Lines Matching +full:rk3328 +full:- +full:grf +full:- +full:gpio

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
38 #include <sys/gpio.h>
93 /* V7 GRF register */
100 #define WR4(_sc, _r, _v) bus_write_4((_sc)->mem_res, (_r), (_v))
101 #define RD4(_sc, _r) bus_read_4((_sc)->mem_res, (_r))
141 struct syscon *grf; member
153 {3800, -40000},
154 {3792, -35000},
155 {3783, -30000},
156 {3774, -25000},
157 {3765, -20000},
158 {3756, -15000},
159 {3747, -10000},
160 {3737, -5000},
199 .shutdown_mode = 1, /* GPIO */
210 {296, -40000},
211 {304, -35000},
212 {313, -30000},
213 {331, -20000},
214 {340, -15000},
215 {349, -10000},
216 {359, -5000},
264 {402, -40000},
265 {410, -35000},
266 {419, -30000},
267 {427, -25000},
268 {436, -20000},
269 {444, -15000},
270 {453, -10000},
271 {461, -5000},
309 .shutdown_mode = 1, /* GPIO */
320 {0, -40000},
321 {1584, -40000},
322 {1620, -35000},
323 {1652, -30000},
324 {1688, -25000},
325 {1720, -20000},
326 {1756, -15000},
327 {1788, -10000},
328 {1824, -5000},
366 .shutdown_mode = 1, /* GPIO */
377 {"rockchip,rk3288-tsadc", (uintptr_t)&rk3288_tsadc_conf},
378 {"rockchip,rk3328-tsadc", (uintptr_t)&rk3328_tsadc_conf},
379 {"rockchip,rk3399-tsadc", (uintptr_t)&rk3399_tsadc_conf},
380 {"rockchip,rk3568-tsadc", (uintptr_t)&rk3568_tsadc_conf},
390 tbl = sc->conf->calib_info.table; in tsadc_temp_to_raw()
391 ntbl = sc->conf->calib_info.nentries; in tsadc_temp_to_raw()
396 if (temp >= tbl[ntbl - 1].temp) in tsadc_temp_to_raw()
397 return (tbl[ntbl - 1].raw); in tsadc_temp_to_raw()
399 for (i = 1; i < (ntbl - 1); i++) { in tsadc_temp_to_raw()
408 * Translated value is between i and i - 1 table entries. in tsadc_temp_to_raw()
411 raw = (int)tbl[i - 1].raw - (int)tbl[i].raw; in tsadc_temp_to_raw()
412 raw *= temp - tbl[i - 1].temp; in tsadc_temp_to_raw()
413 denom = tbl[i - 1].temp - tbl[i].temp; in tsadc_temp_to_raw()
414 raw = tbl[i - 1].raw + raw / denom; in tsadc_temp_to_raw()
425 tbl = sc->conf->calib_info.table; in tsadc_raw_to_temp()
426 ntbl = sc->conf->calib_info.nentries; in tsadc_raw_to_temp()
433 if (raw <= tbl[ntbl - 1].raw) in tsadc_raw_to_temp()
434 return (tbl[ntbl - 1].temp); in tsadc_raw_to_temp()
436 for (i = ntbl - 2; i > 0; i--) { in tsadc_raw_to_temp()
447 if (raw >= tbl[ntbl - 1].raw) in tsadc_raw_to_temp()
448 return (tbl[ntbl - 1].temp); in tsadc_raw_to_temp()
449 for (i = 1; i < (ntbl - 1); i++) { in tsadc_raw_to_temp()
459 * Translated value is between i and i - 1 table entries. in tsadc_raw_to_temp()
462 temp = (int)tbl[i - 1].temp - (int)tbl[i].temp; in tsadc_raw_to_temp()
463 temp *= raw - tbl[i - 1].raw; in tsadc_raw_to_temp()
464 denom = tbl[i - 1].raw - tbl[i].raw; in tsadc_raw_to_temp()
465 temp = tbl[i - 1].temp + temp / denom; in tsadc_raw_to_temp()
476 if (sc->shutdown_mode != 0) { in tsadc_init_tsensor()
477 /* Signal shutdown of GPIO pin */ in tsadc_init_tsensor()
478 val &= ~TSADC_INT_EN_2CRU_EN_SRC(sensor->channel); in tsadc_init_tsensor()
479 val |= TSADC_INT_EN_2GPIO_EN_SRC(sensor->channel); in tsadc_init_tsensor()
481 val |= TSADC_INT_EN_2CRU_EN_SRC(sensor->channel); in tsadc_init_tsensor()
482 val &= ~TSADC_INT_EN_2GPIO_EN_SRC(sensor->channel); in tsadc_init_tsensor()
487 val = tsadc_raw_to_temp(sc, sc->shutdown_temp); in tsadc_init_tsensor()
488 WR4(sc, TSADC_COMP_SHUT(sensor->channel), val); in tsadc_init_tsensor()
490 val |= TSADC_AUTO_SRC_EN(sensor->channel); in tsadc_init_tsensor()
494 val = tsadc_temp_to_raw(sc, sc->alarm_temp); in tsadc_init_tsensor()
495 WR4(sc, TSADC_COMP_INT(sensor->channel), val); in tsadc_init_tsensor()
497 val |= TSADC_COMP_INT_SRC_EN(sensor->channel); in tsadc_init_tsensor()
508 if (sc->shutdown_pol != 0) in tsadc_init()
512 if (sc->conf->q_sel_ntc) in tsadc_init()
516 switch (sc->conf->version) { in tsadc_init()
526 if (sc->grf == NULL) { in tsadc_init()
530 SYSCON_WRITE_4(sc->grf, GRF_TSADC_TESTBIT_L, in tsadc_init()
532 SYSCON_WRITE_4(sc->grf, GRF_TSADC_TESTBIT_H, in tsadc_init()
536 SYSCON_WRITE_4(sc->grf, GRF_SARADC_TESTBIT, in tsadc_init()
538 SYSCON_WRITE_4(sc->grf, GRF_TSADC_TESTBIT_H, in tsadc_init()
554 if (sc->grf) { in tsadc_init()
555 SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON, GRF_TSADC_TSEN); in tsadc_init()
557 SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON, in tsadc_init()
559 SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON, in tsadc_init()
561 SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON, in tsadc_init()
574 val = RD4(sc, TSADC_DATA(sensor->channel)); in tsadc_read_temp()
578 device_printf(sc->dev, "%s: Sensor(id: %d, ch: %d), val: %d temp: %d\n", in tsadc_read_temp()
579 __func__, sensor->id, sensor->channel, val, *temp); in tsadc_read_temp()
580 device_printf(sc->dev, "%s: user_con=0x%08x auto_con=0x%08x " in tsadc_read_temp()
583 RD4(sc, TSADC_COMP_INT(sensor->channel)), in tsadc_read_temp()
584 RD4(sc, TSADC_COMP_SHUT(sensor->channel))); in tsadc_read_temp()
597 if (id >= sc->conf->ntsensors) in tsadc_get_temp()
600 for (i = 0; i < sc->conf->ntsensors; i++) { in tsadc_get_temp()
601 if (sc->conf->tsensors->id == id) { in tsadc_get_temp()
602 rv =tsadc_read_temp(sc, sc->conf->tsensors + id, val); in tsadc_get_temp()
618 if (req->newptr != NULL) in tsadc_sysctl_temperature()
624 if (id >= sc->conf->ntsensors) in tsadc_sysctl_temperature()
626 rv = tsadc_read_temp(sc, sc->conf->tsensors + id, &val); in tsadc_sysctl_temperature()
651 for (i = sc->conf->ntsensors - 1; i >= 0; i--) { in tsadc_init_sysctl()
653 SYSCTL_CHILDREN(oid), OID_AUTO, sc->conf->tsensors[i].name, in tsadc_init_sysctl()
676 device_printf(sc->dev, "Alarm: device temperature " in tsadc_intr()
679 device_printf(sc->dev, "Alarm: device temperature " in tsadc_intr()
692 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) in tsadc_probe()
708 sc->dev = dev; in tsadc_attach()
709 node = ofw_bus_get_node(sc->dev); in tsadc_attach()
710 sc->conf = (struct tsadc_conf *) in tsadc_attach()
711 ofw_bus_search_compatible(dev, compat_data)->ocd_data; in tsadc_attach()
712 sc->alarm_temp = 90000; in tsadc_attach()
715 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in tsadc_attach()
717 if (sc->mem_res == NULL) { in tsadc_attach()
723 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); in tsadc_attach()
724 if (sc->irq_res == NULL) { in tsadc_attach()
729 if ((bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC | INTR_MPSAFE, in tsadc_attach()
730 tsadc_intr, NULL, sc, &sc->irq_ih))) { in tsadc_attach()
737 rv = hwreset_array_get_ofw(dev, 0, &sc->hwreset); in tsadc_attach()
742 rv = clk_get_by_ofw_name(dev, 0, "tsadc", &sc->tsadc_clk); in tsadc_attach()
747 rv = clk_get_by_ofw_name(dev, 0, "apb_pclk", &sc->apb_pclk_clk); in tsadc_attach()
753 /* grf is optional */ in tsadc_attach()
754 rv = syscon_get_by_ofw_property(dev, node, "rockchip,grf", &sc->grf); in tsadc_attach()
756 device_printf(dev, "Cannot get 'grf' syscon: %d\n", rv); in tsadc_attach()
760 rv = OF_getencprop(node, "rockchip,hw-tshut-temp", in tsadc_attach()
761 &sc->shutdown_temp, sizeof(sc->shutdown_temp)); in tsadc_attach()
763 sc->shutdown_temp = sc->conf->shutdown_temp; in tsadc_attach()
765 rv = OF_getencprop(node, "rockchip,hw-tshut-mode", in tsadc_attach()
766 &sc->shutdown_mode, sizeof(sc->shutdown_mode)); in tsadc_attach()
768 sc->shutdown_mode = sc->conf->shutdown_mode; in tsadc_attach()
770 rv = OF_getencprop(node, "rockchip,hw-tshut-polarity", in tsadc_attach()
771 &sc->shutdown_pol, sizeof(sc->shutdown_pol)); in tsadc_attach()
773 sc->shutdown_pol = sc->conf->shutdown_pol; in tsadc_attach()
776 rv = hwreset_array_assert(sc->hwreset); in tsadc_attach()
783 rv = clk_set_assigned(sc->dev, node); in tsadc_attach()
789 rv = clk_enable(sc->tsadc_clk); in tsadc_attach()
794 rv = clk_enable(sc->apb_pclk_clk); in tsadc_attach()
799 rv = hwreset_array_deassert(sc->hwreset); in tsadc_attach()
806 for (i = 0; i < sc->conf->ntsensors; i++) in tsadc_attach()
807 tsadc_init_tsensor(sc, sc->conf->tsensors + i); in tsadc_attach()
816 device_printf(sc->dev, "Cannot initialize sysctls\n"); in tsadc_attach()
827 if (sc->irq_ih != NULL) in tsadc_attach()
828 bus_teardown_intr(dev, sc->irq_res, sc->irq_ih); in tsadc_attach()
829 if (sc->tsadc_clk != NULL) in tsadc_attach()
830 clk_release(sc->tsadc_clk); in tsadc_attach()
831 if (sc->apb_pclk_clk != NULL) in tsadc_attach()
832 clk_release(sc->apb_pclk_clk); in tsadc_attach()
833 if (sc->hwreset != NULL) in tsadc_attach()
834 hwreset_array_release(sc->hwreset); in tsadc_attach()
835 if (sc->irq_res != NULL) in tsadc_attach()
836 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res); in tsadc_attach()
837 if (sc->mem_res != NULL) in tsadc_attach()
838 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); in tsadc_attach()
849 if (sc->irq_ih != NULL) in tsadc_detach()
850 bus_teardown_intr(dev, sc->irq_res, sc->irq_ih); in tsadc_detach()
852 if (sc->tsadc_clk != NULL) in tsadc_detach()
853 clk_release(sc->tsadc_clk); in tsadc_detach()
854 if (sc->apb_pclk_clk != NULL) in tsadc_detach()
855 clk_release(sc->apb_pclk_clk); in tsadc_detach()
856 if (sc->hwreset != NULL) in tsadc_detach()
857 hwreset_array_release(sc->hwreset); in tsadc_detach()
858 if (sc->irq_res != NULL) in tsadc_detach()
859 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res); in tsadc_detach()
860 if (sc->mem_res != NULL) in tsadc_detach()
861 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); in tsadc_detach()