Lines Matching +full:thermal +full:- +full:calibration
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ST Thermal Sensor Driver core routines
6 * Copyright (C) 2003-2014 STMicroelectronics (R&D) Limited
16 /* The Thermal Framework expects millidegrees */
25 struct device *dev = sensor->dev; in st_thermal_alloc_regfields()
26 struct regmap *regmap = sensor->regmap; in st_thermal_alloc_regfields()
27 const struct reg_field *reg_fields = sensor->cdata->reg_fields; in st_thermal_alloc_regfields()
29 sensor->dcorrect = devm_regmap_field_alloc(dev, regmap, in st_thermal_alloc_regfields()
32 sensor->overflow = devm_regmap_field_alloc(dev, regmap, in st_thermal_alloc_regfields()
35 sensor->temp_data = devm_regmap_field_alloc(dev, regmap, in st_thermal_alloc_regfields()
38 if (IS_ERR(sensor->dcorrect) || in st_thermal_alloc_regfields()
39 IS_ERR(sensor->overflow) || in st_thermal_alloc_regfields()
40 IS_ERR(sensor->temp_data)) { in st_thermal_alloc_regfields()
42 return -EINVAL; in st_thermal_alloc_regfields()
45 return sensor->ops->alloc_regfields(sensor); in st_thermal_alloc_regfields()
51 struct device *dev = sensor->dev; in st_thermal_sensor_on()
53 ret = clk_prepare_enable(sensor->clk); in st_thermal_sensor_on()
59 ret = sensor->ops->power_ctrl(sensor, POWER_ON); in st_thermal_sensor_on()
62 clk_disable_unprepare(sensor->clk); in st_thermal_sensor_on()
72 ret = sensor->ops->power_ctrl(sensor, POWER_OFF); in st_thermal_sensor_off()
76 clk_disable_unprepare(sensor->clk); in st_thermal_sensor_off()
85 struct device *dev = sensor->dev; in st_thermal_calibration()
87 /* Check if sensor calibration data is already written */ in st_thermal_calibration()
88 ret = regmap_field_read(sensor->dcorrect, &val); in st_thermal_calibration()
90 dev_err(dev, "failed to read calibration data\n"); in st_thermal_calibration()
96 * Sensor calibration value not set by bootloader, in st_thermal_calibration()
97 * default calibration data to be used in st_thermal_calibration()
99 ret = regmap_field_write(sensor->dcorrect, in st_thermal_calibration()
100 sensor->cdata->calibration_val); in st_thermal_calibration()
102 dev_err(dev, "failed to set calibration data\n"); in st_thermal_calibration()
111 struct st_thermal_sensor *sensor = th->devdata; in st_thermal_get_temp()
112 struct device *dev = sensor->dev; in st_thermal_get_temp()
117 ret = regmap_field_read(sensor->overflow, &overflow); in st_thermal_get_temp()
121 return -EIO; in st_thermal_get_temp()
123 ret = regmap_field_read(sensor->temp_data, &temp); in st_thermal_get_temp()
127 temp += sensor->cdata->temp_adjust_val; in st_thermal_get_temp()
140 struct st_thermal_sensor *sensor = th->devdata; in st_thermal_get_trip_type()
141 struct device *dev = sensor->dev; in st_thermal_get_trip_type()
149 return -EINVAL; in st_thermal_get_trip_type()
158 struct st_thermal_sensor *sensor = th->devdata; in st_thermal_get_trip_temp()
159 struct device *dev = sensor->dev; in st_thermal_get_trip_temp()
163 *temp = mcelsius(sensor->cdata->crit_temp); in st_thermal_get_trip_temp()
167 return -EINVAL; in st_thermal_get_trip_temp()
183 struct device *dev = &pdev->dev; in st_thermal_register()
184 struct device_node *np = dev->of_node; in st_thermal_register()
192 return -EINVAL; in st_thermal_register()
197 return -ENOMEM; in st_thermal_register()
199 sensor->dev = dev; in st_thermal_register()
202 if (!(match && match->data)) in st_thermal_register()
203 return -EINVAL; in st_thermal_register()
205 sensor->cdata = match->data; in st_thermal_register()
206 if (!sensor->cdata->ops) in st_thermal_register()
207 return -EINVAL; in st_thermal_register()
209 sensor->ops = sensor->cdata->ops; in st_thermal_register()
211 ret = (sensor->ops->regmap_init)(sensor); in st_thermal_register()
219 sensor->clk = devm_clk_get(dev, "thermal"); in st_thermal_register()
220 if (IS_ERR(sensor->clk)) { in st_thermal_register()
222 return PTR_ERR(sensor->clk); in st_thermal_register()
225 if (sensor->ops->register_enable_irq) { in st_thermal_register()
226 ret = sensor->ops->register_enable_irq(sensor); in st_thermal_register()
239 polling_delay = sensor->ops->register_enable_irq ? 0 : 1000; in st_thermal_register()
241 sensor->thermal_dev = in st_thermal_register()
244 if (IS_ERR(sensor->thermal_dev)) { in st_thermal_register()
245 dev_err(dev, "failed to register thermal zone device\n"); in st_thermal_register()
246 ret = PTR_ERR(sensor->thermal_dev); in st_thermal_register()
249 ret = thermal_zone_device_enable(sensor->thermal_dev); in st_thermal_register()
258 thermal_zone_device_unregister(sensor->thermal_dev); in st_thermal_register()
271 thermal_zone_device_unregister(sensor->thermal_dev); in st_thermal_unregister()
298 if (sensor->ops->enable_irq) { in st_thermal_resume()
299 ret = sensor->ops->enable_irq(sensor); in st_thermal_resume()
312 MODULE_DESCRIPTION("STMicroelectronics STi SoC Thermal Sensor Driver");