Lines Matching +full:adc +full:- +full:sleep +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-or-later
28 /* period unit calculated in BUS clock * 256 scaling-up */
66 * - Fire BIT(1) when lower than EN7581_COLD_THRE
67 * - Fire BIT(0) and BIT(5) when higher than EN7581_HOT2NORMAL_THRE or
105 * - Fire BIT(1) when lower than EN7581_COLD_THRE
106 * - Fire BIT(0) and BIT(5) when higher than EN7581_HOT2NORMAL_THRE or
144 * the same addr is used for ADC volt and valid reading.
156 * - 1 sample
157 * - 2 sample and make average of them
158 * - 4,6,10,16 sample, drop max and min and make average of them
184 /* Convert temp to raw value as read from ADC ((((temp / 100) - init) * slope) / 1000) + offset */
185 #define TEMP_TO_RAW(priv, temp) ((((((temp) / 100) - (priv)->init_temp) * \
186 (priv)->default_slope) / 1000) + \
187 (priv)->default_offset)
189 /* Convert raw to temp ((((temp - offset) * 1000) / slope + init) * 100) */
190 #define RAW_TO_TEMP(priv, raw) (((((raw) - (priv)->default_offset) * 1000) / \
191 (priv)->default_slope + \
192 (priv)->init_temp) * 100)
211 regmap_read(priv->chip_scu, EN7581_DOUT_TADC, &val); in airoha_get_thermal_ADC()
220 regmap_read(priv->chip_scu, EN7581_PLLRG_PROTECT, &pllrg); in airoha_init_thermal_ADC_mode()
223 regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, EN7581_SCU_THERMAL_PROTECT_KEY); in airoha_init_thermal_ADC_mode()
225 regmap_write(priv->chip_scu, EN7581_PWD_TADC, adc_mux); in airoha_init_thermal_ADC_mode()
228 regmap_write(priv->chip_scu, EN7581_PLLRG_PROTECT, pllrg); in airoha_init_thermal_ADC_mode()
249 avg_value -= (min_value + max_value); in airoha_thermal_get_temp()
250 avg_value /= AIROHA_MAX_SAMPLES - 2; in airoha_thermal_get_temp()
269 priv->base + EN7581_TEMPOFFSETH); in airoha_thermal_set_trips()
274 if (low != -INT_MAX) { in airoha_thermal_set_trips()
281 priv->base + EN7581_TEMPOFFSETL); in airoha_thermal_set_trips()
288 writel(EN7581_SENSE0_EN, priv->base + EN7581_TEMPMONCTL0); in airoha_thermal_set_trips()
305 status = readl(priv->base + EN7581_TEMPMONINTSTS); in airoha_thermal_irq()
321 writel(status, priv->base + EN7581_TEMPMONINTSTS); in airoha_thermal_irq()
324 thermal_zone_device_update(priv->tz, event); in airoha_thermal_irq()
334 /* Setup thermal sensor to ADC mode and setup the mux to DIODE1 */ in airoha_thermal_setup_adc_val()
336 /* sleep 10 ms for ADC to enable */ in airoha_thermal_setup_adc_val()
339 efuse_calib_info = readl(priv->base + EN7581_EFUSE_TEMP_OFFSET_REG); in airoha_thermal_setup_adc_val()
341 priv->default_offset = FIELD_GET(EN7581_EFUSE_TEMP_OFFSET, efuse_calib_info); in airoha_thermal_setup_adc_val()
343 cpu_sensor = readl(priv->base + EN7581_EFUSE_TEMP_CPU_SENSOR_REG); in airoha_thermal_setup_adc_val()
345 priv->default_slope = EN7581_SLOPE_X100_DIO_DEFAULT; in airoha_thermal_setup_adc_val()
346 priv->init_temp = EN7581_INIT_TEMP_FTK_X10; in airoha_thermal_setup_adc_val()
348 priv->default_slope = EN7581_SLOPE_X100_DIO_AVS; in airoha_thermal_setup_adc_val()
349 priv->init_temp = EN7581_INIT_TEMP_CPK_X10; in airoha_thermal_setup_adc_val()
352 priv->default_offset = airoha_get_thermal_ADC(priv); in airoha_thermal_setup_adc_val()
353 priv->default_slope = EN7581_SLOPE_X100_DIO_DEFAULT; in airoha_thermal_setup_adc_val()
354 priv->init_temp = EN7581_INIT_TEMP_NONK_X10; in airoha_thermal_setup_adc_val()
361 /* Set measure mode */ in airoha_thermal_setup_monitor()
363 priv->base + EN7581_TEMPMSRCTL0); in airoha_thermal_setup_monitor()
366 * Configure ADC valid reading addr in airoha_thermal_setup_monitor()
369 * addresses to configure how to access and setup an ADC for the in airoha_thermal_setup_monitor()
372 * up to 4 different sensors from the same ADC that can be in airoha_thermal_setup_monitor()
373 * switched by tuning the ADC mux or writing address. in airoha_thermal_setup_monitor()
378 writel(priv->scu_adc_res.start + EN7581_DOUT_TADC, in airoha_thermal_setup_monitor()
379 priv->base + EN7581_TEMPADCVALIDADDR); in airoha_thermal_setup_monitor()
382 * Configure valid bit on a fake value of bit 16. The ADC outputs in airoha_thermal_setup_monitor()
386 priv->base + EN7581_TEMPADCVALIDMASK); in airoha_thermal_setup_monitor()
389 * AHB supports max 12 bytes for ADC voltage. Shift the read in airoha_thermal_setup_monitor()
395 priv->base + EN7581_TEMPADCVOLTAGESHIFT); in airoha_thermal_setup_monitor()
399 priv->base + EN7581_TEMPMONCTL1); in airoha_thermal_setup_monitor()
407 priv->base + EN7581_TEMPMONCTL2); in airoha_thermal_setup_monitor()
411 priv->base + EN7581_TEMPAHBPOLL); in airoha_thermal_setup_monitor()
418 struct device *dev = &pdev->dev; in airoha_thermal_probe()
423 return -ENOMEM; in airoha_thermal_probe()
425 priv->base = devm_platform_ioremap_resource(pdev, 0); in airoha_thermal_probe()
426 if (IS_ERR(priv->base)) in airoha_thermal_probe()
427 return PTR_ERR(priv->base); in airoha_thermal_probe()
429 chip_scu_np = of_parse_phandle(dev->of_node, "airoha,chip-scu", 0); in airoha_thermal_probe()
431 return -EINVAL; in airoha_thermal_probe()
433 priv->chip_scu = syscon_node_to_regmap(chip_scu_np); in airoha_thermal_probe()
434 if (IS_ERR(priv->chip_scu)) in airoha_thermal_probe()
435 return PTR_ERR(priv->chip_scu); in airoha_thermal_probe()
437 of_address_to_resource(chip_scu_np, 0, &priv->scu_adc_res); in airoha_thermal_probe()
444 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in airoha_thermal_probe()
446 pdev->name, priv); in airoha_thermal_probe()
456 priv->tz = devm_thermal_of_zone_register(dev, 0, priv, &thdev_ops); in airoha_thermal_probe()
457 if (IS_ERR(priv->tz)) { in airoha_thermal_probe()
459 return PTR_ERR(priv->tz); in airoha_thermal_probe()
466 priv->base + EN7581_TEMPMONINT); in airoha_thermal_probe()
472 { .compatible = "airoha,en7581-thermal" },
479 .name = "airoha-thermal",