Lines Matching +full:temp +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/nvmem-consumer.h>
23 #define TRITSR 0x20 /* TMU immediate temp */
72 #define VER2_TEMP_LOW_LIMIT -40000
81 int (*get_temp)(void *data, int *temp);
97 static int imx8mm_tmu_get_temp(void *data, int *temp) in imx8mm_tmu_get_temp() argument
99 struct tmu_sensor *sensor = data; in imx8mm_tmu_get_temp() local
100 struct imx8mm_tmu *tmu = sensor->priv; in imx8mm_tmu_get_temp()
103 val = readl_relaxed(tmu->base + TRITSR) & TRITSR_TEMP0_VAL_MASK; in imx8mm_tmu_get_temp()
110 *temp = val * 1000; in imx8mm_tmu_get_temp()
111 if (*temp < VER1_TEMP_LOW_LIMIT || *temp > VER2_TEMP_HIGH_LIMIT) in imx8mm_tmu_get_temp()
112 return -EAGAIN; in imx8mm_tmu_get_temp()
117 static int imx8mp_tmu_get_temp(void *data, int *temp) in imx8mp_tmu_get_temp() argument
119 struct tmu_sensor *sensor = data; in imx8mp_tmu_get_temp() local
120 struct imx8mm_tmu *tmu = sensor->priv; in imx8mp_tmu_get_temp()
124 val = readl_relaxed(tmu->base + TRITSR); in imx8mp_tmu_get_temp()
125 ready = test_bit(probe_status_offset(sensor->hw_id), &val); in imx8mp_tmu_get_temp()
127 return -EAGAIN; in imx8mp_tmu_get_temp()
129 val = sensor->hw_id ? FIELD_GET(TRITSR_TEMP1_VAL_MASK, val) : in imx8mp_tmu_get_temp()
134 *temp = val * 1000; in imx8mp_tmu_get_temp()
135 if (*temp < VER2_TEMP_LOW_LIMIT || *temp > VER2_TEMP_HIGH_LIMIT) in imx8mp_tmu_get_temp()
136 return -EAGAIN; in imx8mp_tmu_get_temp()
141 static int tmu_get_temp(struct thermal_zone_device *tz, int *temp) in tmu_get_temp() argument
143 struct tmu_sensor *sensor = thermal_zone_device_priv(tz); in tmu_get_temp() local
144 struct imx8mm_tmu *tmu = sensor->priv; in tmu_get_temp()
146 return tmu->socdata->get_temp(sensor, temp); in tmu_get_temp()
157 val = readl_relaxed(tmu->base + TER); in imx8mm_tmu_enable()
159 if (tmu->socdata->version == TMU_VER2) in imx8mm_tmu_enable()
161 writel_relaxed(val, tmu->base + TER); in imx8mm_tmu_enable()
168 val = readl_relaxed(tmu->base + TPS); in imx8mm_tmu_probe_sel_all()
170 writel_relaxed(val, tmu->base + TPS); in imx8mm_tmu_probe_sel_all()
176 struct device *dev = &pdev->dev; in imx8mm_tmu_probe_set_calib_v1()
180 ret = nvmem_cell_read_u32(&pdev->dev, "calib", &ana0); in imx8mm_tmu_probe_set_calib_v1()
188 tmu->base + TASR); in imx8mm_tmu_probe_set_calib_v1()
193 tmu->base + TCALIV(0)); in imx8mm_tmu_probe_set_calib_v1()
201 struct device *dev = &pdev->dev; in imx8mm_tmu_probe_set_calib_v2()
223 return -EINVAL; in imx8mm_tmu_probe_set_calib_v2()
230 tmu->base + TCALIV(0)); in imx8mm_tmu_probe_set_calib_v2()
232 tmu->base + TCALIV(1)); in imx8mm_tmu_probe_set_calib_v2()
240 tmu->base + TASR); in imx8mm_tmu_probe_set_calib_v2()
247 tmu->base + TRIM); in imx8mm_tmu_probe_set_calib_v2()
254 tmu->base + TCALIV(0)); in imx8mm_tmu_probe_set_calib_v2()
260 tmu->base + TCALIV(1)); in imx8mm_tmu_probe_set_calib_v2()
266 tmu->base + TCALIV(2)); in imx8mm_tmu_probe_set_calib_v2()
274 struct device *dev = &pdev->dev; in imx8mm_tmu_probe_set_calib()
282 if (!of_property_present(pdev->dev.of_node, "nvmem-cells")) { in imx8mm_tmu_probe_set_calib()
284 … "No OCOTP nvmem reference found, SoC-specific calibration not loaded. Please update your DT.\n"); in imx8mm_tmu_probe_set_calib()
288 if (tmu->socdata->version == TMU_VER1) in imx8mm_tmu_probe_set_calib()
301 data = of_device_get_match_data(&pdev->dev); in imx8mm_tmu_probe()
303 tmu = devm_kzalloc(&pdev->dev, struct_size(tmu, sensors, in imx8mm_tmu_probe()
304 data->num_sensors), GFP_KERNEL); in imx8mm_tmu_probe()
306 return -ENOMEM; in imx8mm_tmu_probe()
308 tmu->socdata = data; in imx8mm_tmu_probe()
310 tmu->base = devm_platform_ioremap_resource(pdev, 0); in imx8mm_tmu_probe()
311 if (IS_ERR(tmu->base)) in imx8mm_tmu_probe()
312 return PTR_ERR(tmu->base); in imx8mm_tmu_probe()
314 tmu->clk = devm_clk_get(&pdev->dev, NULL); in imx8mm_tmu_probe()
315 if (IS_ERR(tmu->clk)) in imx8mm_tmu_probe()
316 return dev_err_probe(&pdev->dev, PTR_ERR(tmu->clk), in imx8mm_tmu_probe()
319 ret = clk_prepare_enable(tmu->clk); in imx8mm_tmu_probe()
321 dev_err(&pdev->dev, "failed to enable tmu clock: %d\n", ret); in imx8mm_tmu_probe()
328 for (i = 0; i < data->num_sensors; i++) { in imx8mm_tmu_probe()
329 tmu->sensors[i].priv = tmu; in imx8mm_tmu_probe()
330 tmu->sensors[i].tzd = in imx8mm_tmu_probe()
331 devm_thermal_of_zone_register(&pdev->dev, i, in imx8mm_tmu_probe()
332 &tmu->sensors[i], in imx8mm_tmu_probe()
334 if (IS_ERR(tmu->sensors[i].tzd)) { in imx8mm_tmu_probe()
335 ret = PTR_ERR(tmu->sensors[i].tzd); in imx8mm_tmu_probe()
336 dev_err(&pdev->dev, in imx8mm_tmu_probe()
337 "failed to register thermal zone sensor[%d]: %d\n", in imx8mm_tmu_probe()
341 tmu->sensors[i].hw_id = i; in imx8mm_tmu_probe()
343 devm_thermal_add_hwmon_sysfs(&pdev->dev, tmu->sensors[i].tzd); in imx8mm_tmu_probe()
353 if (tmu->socdata->version == TMU_VER2) in imx8mm_tmu_probe()
362 clk_disable_unprepare(tmu->clk); in imx8mm_tmu_probe()
373 clk_disable_unprepare(tmu->clk); in imx8mm_tmu_remove()
390 { .compatible = "fsl,imx8mm-tmu", .data = &imx8mm_tmu_data, },
391 { .compatible = "fsl,imx8mp-tmu", .data = &imx8mp_tmu_data, },