Lines Matching +full:sensor +full:- +full:id
1 /*-
52 #include <dt-bindings/thermal/tegra124-soctherm.h>
55 /* Per sensors registers - base is 0x0c0*/
131 #define WR4(_sc, _r, _v) bus_write_4((_sc)->mem_res, (_r), (_v))
132 #define RD4(_sc, _r) bus_read_4((_sc)->mem_res, (_r))
155 int id; member
204 .id = TEGRA124_SOCTHERM_SENSOR_CPU,
208 .fuse_corr_beta = -6266900,
212 .id = -1,
216 .fuse_corr_beta = -5700700,
220 .id = -1,
224 .fuse_corr_beta = -6768200,
228 .id = -1,
232 .fuse_corr_beta = -6232000,
236 .id = TEGRA124_SOCTHERM_SENSOR_MEM,
240 .fuse_corr_beta = -5936400,
244 .id = -1,
248 .fuse_corr_beta = -7124600,
252 .id = TEGRA124_SOCTHERM_SENSOR_GPU,
256 .fuse_corr_beta = -6000500,
260 .id = TEGRA124_SOCTHERM_SENSOR_PLLX,
264 .fuse_corr_beta = -6729300,
293 .id = TEGRA124_SOCTHERM_SENSOR_CPU,
301 .id = -1,
305 .fuse_corr_beta = -67500,
309 .id = -1,
317 .id = -1,
325 .id = TEGRA124_SOCTHERM_SENSOR_MEM,
333 .id = -1,
337 .fuse_corr_beta = -6263600,
341 .id = TEGRA124_SOCTHERM_SENSOR_GPU,
349 .id = TEGRA124_SOCTHERM_SENSOR_PLLX,
369 {"nvidia,tegra124-soctherm", (uintptr_t)&tegra124_soc},
370 {"nvidia,tegra210-soctherm", (uintptr_t)&tegra210_soc},
381 mask = (1 << bits) - 1; in extract_signed()
382 val = ((reg >> shift) & mask) << (32 - bits); in extract_signed()
383 val >>= 32 - bits; in extract_signed()
404 cal = &sc->shared_cal; in tegra124_shared_cal()
406 cal->base_cp = TEGRA124_FUSE_COMMON_CP_TS_BASE(val); in tegra124_shared_cal()
407 cal->base_ft = TEGRA124_FUSE_COMMON_FT_TS_BASE(val); in tegra124_shared_cal()
418 cal->actual_temp_cp = 2 * TEGRA124_NOMINAL_CALIB_CP + calib_cp; in tegra124_shared_cal()
419 cal->actual_temp_ft = 2 * TEGRA124_NOMINAL_CALIB_FT + calib_ft; in tegra124_shared_cal()
423 __func__, cal->base_cp, cal->base_ft, in tegra124_shared_cal()
424 cal->actual_temp_cp, cal->actual_temp_ft); in tegra124_shared_cal()
435 cal = &sc->shared_cal; in tegra210_shared_cal()
438 cal->base_cp = TEGRA210_FUSE_COMMON_CP_TS_BASE(val); in tegra210_shared_cal()
439 cal->base_ft = TEGRA210_FUSE_COMMON_FT_TS_BASE(val); in tegra210_shared_cal()
448 cal->actual_temp_cp = 2 * TEGRA210_NOMINAL_CALIB_CP + calib_cp; in tegra210_shared_cal()
449 cal->actual_temp_ft = 2 * TEGRA210_NOMINAL_CALIB_FT + calib_ft; in tegra210_shared_cal()
453 __func__, cal->base_cp, cal->base_ft, in tegra210_shared_cal()
454 cal->actual_temp_cp, cal->actual_temp_ft); in tegra210_shared_cal()
459 tsensor_calibration(struct soctherm_softc *sc, struct tsensor *sensor) in tsensor_calibration() argument
469 cfg = sc->soc->tsensor_cfg; in tsensor_calibration()
470 cal = &sc->shared_cal; in tsensor_calibration()
472 val = tegra_fuse_read_4(sensor->calib_fuse); in tsensor_calibration()
476 actual_tsensor_cp = cal->base_cp * 64 + calib_cp; in tsensor_calibration()
481 actual_tsensor_ft = cal->base_ft * 32 + calib_ft; in tsensor_calibration()
483 delta_sens = actual_tsensor_ft - actual_tsensor_cp; in tsensor_calibration()
484 delta_temp = cal->actual_temp_ft - cal->actual_temp_cp; in tsensor_calibration()
485 mult = cfg->pdiv * cfg->tsample_ate; in tsensor_calibration()
486 div = cfg->tsample * cfg->pdiv_ate; in tsensor_calibration()
491 tmp = (int64_t)actual_tsensor_ft * cal->actual_temp_cp - in tsensor_calibration()
492 (int64_t)actual_tsensor_cp * cal->actual_temp_ft; in tsensor_calibration()
495 temp_a = div64_s64_precise((int64_t)temp_a * sensor->fuse_corr_alpha, in tsensor_calibration()
497 temp_b = div64_s64_precise((int64_t)temp_b * sensor->fuse_corr_alpha + in tsensor_calibration()
498 sensor->fuse_corr_beta, 1000000); in tsensor_calibration()
499 sensor->therm_a = (int16_t)temp_a; in tsensor_calibration()
500 sensor->therm_b = (int16_t)temp_b; in tsensor_calibration()
502 printf("%s: sensor %s fuse: 0x%08X (0x%04X, 0x%04X)" in tsensor_calibration()
504 __func__, sensor->name, val, val & 0x1FFF, (val >> 13) & 0x1FFF, in tsensor_calibration()
507 (uint16_t)sensor->therm_a, sensor->therm_a, in tsensor_calibration()
508 (uint16_t)sensor->therm_b, sensor->therm_b); in tsensor_calibration()
513 soctherm_init_tsensor(struct soctherm_softc *sc, struct tsensor *sensor) in soctherm_init_tsensor() argument
518 cfg = sc->soc->tsensor_cfg; in soctherm_init_tsensor()
519 tsensor_calibration(sc, sensor); in soctherm_init_tsensor()
521 val = RD4(sc, sensor->sensor_base + TSENSOR_CONFIG0); in soctherm_init_tsensor()
524 WR4(sc, sensor->sensor_base + TSENSOR_CONFIG0, val); in soctherm_init_tsensor()
526 val = TSENSOR_CONFIG0_TALL(cfg->tall); in soctherm_init_tsensor()
528 WR4(sc, sensor->sensor_base + TSENSOR_CONFIG0, val); in soctherm_init_tsensor()
530 val = TSENSOR_CONFIG1_TSAMPLE(cfg->tsample - 1); in soctherm_init_tsensor()
531 val |= TSENSOR_CONFIG1_TIDDQ_EN(cfg->tiddq_en); in soctherm_init_tsensor()
532 val |= TSENSOR_CONFIG1_TEN_COUNT(cfg->ten_count); in soctherm_init_tsensor()
534 WR4(sc, sensor->sensor_base + TSENSOR_CONFIG1, val); in soctherm_init_tsensor()
536 val = TSENSOR_CONFIG2_THERMA((uint16_t)sensor->therm_a) | in soctherm_init_tsensor()
537 TSENSOR_CONFIG2_THERMB((uint16_t)sensor->therm_b); in soctherm_init_tsensor()
538 WR4(sc, sensor->sensor_base + TSENSOR_CONFIG2, val); in soctherm_init_tsensor()
540 val = RD4(sc, sensor->sensor_base + TSENSOR_CONFIG0); in soctherm_init_tsensor()
542 WR4(sc, sensor->sensor_base + TSENSOR_CONFIG0, val); in soctherm_init_tsensor()
544 printf(" Sensor: %s cfg:0x%08X, 0x%08X, 0x%08X," in soctherm_init_tsensor()
545 " sts:0x%08X, 0x%08X, 0x%08X\n", sensor->name, in soctherm_init_tsensor()
546 RD4(sc, sensor->sensor_base + TSENSOR_CONFIG0), in soctherm_init_tsensor()
547 RD4(sc, sensor->sensor_base + TSENSOR_CONFIG1), in soctherm_init_tsensor()
548 RD4(sc, sensor->sensor_base + TSENSOR_CONFIG2), in soctherm_init_tsensor()
549 RD4(sc, sensor->sensor_base + TSENSOR_STATUS0), in soctherm_init_tsensor()
550 RD4(sc, sensor->sensor_base + TSENSOR_STATUS1), in soctherm_init_tsensor()
551 RD4(sc, sensor->sensor_base + TSENSOR_STATUS2) in soctherm_init_tsensor()
565 t *= -1; in soctherm_convert_raw()
571 soctherm_read_temp(struct soctherm_softc *sc, struct tsensor *sensor, int *temp) in soctherm_read_temp() argument
577 for (timeout = 100; timeout > 0; timeout--) { in soctherm_read_temp()
578 val = RD4(sc, sensor->sensor_base + TSENSOR_STATUS1); in soctherm_read_temp()
584 device_printf(sc->dev, "Sensor %s timeouted\n", sensor->name); in soctherm_read_temp()
588 printf(" Sensor: %s cfg:0x%08X, 0x%08X, 0x%08X," in soctherm_read_temp()
589 " sts:0x%08X, 0x%08X, 0x%08X\n", sensor->name, in soctherm_read_temp()
590 RD4(sc, sensor->sensor_base + TSENSOR_CONFIG0), in soctherm_read_temp()
591 RD4(sc, sensor->sensor_base + TSENSOR_CONFIG1), in soctherm_read_temp()
592 RD4(sc, sensor->sensor_base + TSENSOR_CONFIG2), in soctherm_read_temp()
593 RD4(sc, sensor->sensor_base + TSENSOR_STATUS0), in soctherm_read_temp()
594 RD4(sc, sensor->sensor_base + TSENSOR_STATUS1), in soctherm_read_temp()
595 RD4(sc, sensor->sensor_base + TSENSOR_STATUS2) in soctherm_read_temp()
602 soctherm_get_temp(device_t dev, device_t cdev, uintptr_t id, int *val) in soctherm_get_temp() argument
608 /* The direct sensor map starts at 0x100 */ in soctherm_get_temp()
609 if (id >= 0x100) { in soctherm_get_temp()
610 id -= 0x100; in soctherm_get_temp()
611 if (id >= sc->soc->ntsensors) in soctherm_get_temp()
613 return(soctherm_read_temp(sc, sc->soc->tsensors + id, val)); in soctherm_get_temp()
616 for (i = 0; i < sc->soc->ntsensors; i++) { in soctherm_get_temp()
617 if (sc->soc->tsensors->id == id) { in soctherm_get_temp()
618 return(soctherm_read_temp(sc, sc->soc->tsensors + id, in soctherm_get_temp()
631 int id; in soctherm_sysctl_temperature() local
634 if (req->newptr != NULL) in soctherm_sysctl_temperature()
638 id = arg2; in soctherm_sysctl_temperature()
640 if (id >= sc->soc->ntsensors) in soctherm_sysctl_temperature()
642 rv = soctherm_read_temp(sc, sc->soc->tsensors + id, &val); in soctherm_sysctl_temperature()
667 for (i = sc->soc->ntsensors - 1; i >= 0; i--) { in soctherm_init_sysctl()
669 SYSCTL_CHILDREN(oid), OID_AUTO, sc->soc->tsensors[i].name, in soctherm_init_sysctl()
686 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) in soctherm_probe()
701 sc->dev = dev; in soctherm_attach()
702 sc->soc = (struct soctherm_soc *)ofw_bus_search_compatible(dev, in soctherm_attach()
703 compat_data)->ocd_data; in soctherm_attach()
704 node = ofw_bus_get_node(sc->dev); in soctherm_attach()
707 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in soctherm_attach()
709 if (sc->mem_res == NULL) { in soctherm_attach()
715 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); in soctherm_attach()
716 if (sc->irq_res == NULL) { in soctherm_attach()
722 if ((bus_setup_intr(dev, sc->irq_res, INTR_TYPE_MISC, in soctherm_attach()
723 soctherm_intr, NULL, sc, &sc->irq_ih))) { in soctherm_attach()
731 rv = hwreset_get_by_ofw_name(dev, 0, "soctherm", &sc->reset); in soctherm_attach()
736 rv = clk_get_by_ofw_name(dev, 0, "tsensor", &sc->tsensor_clk); in soctherm_attach()
741 rv = clk_get_by_ofw_name(dev, 0, "soctherm", &sc->soctherm_clk); in soctherm_attach()
747 rv = hwreset_assert(sc->reset); in soctherm_attach()
752 rv = clk_enable(sc->tsensor_clk); in soctherm_attach()
757 rv = clk_enable(sc->soctherm_clk); in soctherm_attach()
762 rv = hwreset_deassert(sc->reset); in soctherm_attach()
768 sc->soc->shared_cal(sc); in soctherm_attach()
770 WR4(sc, TSENSOR_PDIV, sc->soc->tsensor_pdiv); in soctherm_attach()
771 WR4(sc, TSENSOR_HOTSPOT_OFF, sc->soc->tsensor_hotspot_off); in soctherm_attach()
773 for (i = 0; i < sc->soc->ntsensors; i++) in soctherm_attach()
774 soctherm_init_tsensor(sc, sc->soc->tsensors + i); in soctherm_attach()
778 device_printf(sc->dev, "Cannot initialize sysctls\n"); in soctherm_attach()
787 if (sc->irq_ih != NULL) in soctherm_attach()
788 bus_teardown_intr(dev, sc->irq_res, sc->irq_ih); in soctherm_attach()
790 if (sc->tsensor_clk != NULL) in soctherm_attach()
791 clk_release(sc->tsensor_clk); in soctherm_attach()
792 if (sc->soctherm_clk != NULL) in soctherm_attach()
793 clk_release(sc->soctherm_clk); in soctherm_attach()
794 if (sc->reset != NULL) in soctherm_attach()
795 hwreset_release(sc->reset); in soctherm_attach()
796 if (sc->irq_res != NULL) in soctherm_attach()
797 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res); in soctherm_attach()
798 if (sc->mem_res != NULL) in soctherm_attach()
799 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); in soctherm_attach()
810 if (sc->irq_ih != NULL) in soctherm_detach()
811 bus_teardown_intr(dev, sc->irq_res, sc->irq_ih); in soctherm_detach()
813 if (sc->tsensor_clk != NULL) in soctherm_detach()
814 clk_release(sc->tsensor_clk); in soctherm_detach()
815 if (sc->soctherm_clk != NULL) in soctherm_detach()
816 clk_release(sc->soctherm_clk); in soctherm_detach()
817 if (sc->reset != NULL) in soctherm_detach()
818 hwreset_release(sc->reset); in soctherm_detach()
819 if (sc->irq_res != NULL) in soctherm_detach()
820 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq_res); in soctherm_detach()
821 if (sc->mem_res != NULL) in soctherm_detach()
822 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); in soctherm_detach()