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
17 /* The Thermal Framework expects millidegrees */
26 struct device *dev = sensor->dev; in st_thermal_alloc_regfields()
27 struct regmap *regmap = sensor->regmap; in st_thermal_alloc_regfields()
28 const struct reg_field *reg_fields = sensor->cdata->reg_fields; in st_thermal_alloc_regfields()
30 sensor->dcorrect = devm_regmap_field_alloc(dev, regmap, in st_thermal_alloc_regfields()
33 sensor->overflow = devm_regmap_field_alloc(dev, regmap, in st_thermal_alloc_regfields()
36 sensor->temp_data = devm_regmap_field_alloc(dev, regmap, in st_thermal_alloc_regfields()
39 if (IS_ERR(sensor->dcorrect) || in st_thermal_alloc_regfields()
40 IS_ERR(sensor->overflow) || in st_thermal_alloc_regfields()
41 IS_ERR(sensor->temp_data)) { in st_thermal_alloc_regfields()
43 return -EINVAL; in st_thermal_alloc_regfields()
46 return sensor->ops->alloc_regfields(sensor); in st_thermal_alloc_regfields()
52 struct device *dev = sensor->dev; in st_thermal_sensor_on()
54 ret = clk_prepare_enable(sensor->clk); in st_thermal_sensor_on()
60 ret = sensor->ops->power_ctrl(sensor, POWER_ON); in st_thermal_sensor_on()
63 clk_disable_unprepare(sensor->clk); in st_thermal_sensor_on()
73 ret = sensor->ops->power_ctrl(sensor, POWER_OFF); in st_thermal_sensor_off()
77 clk_disable_unprepare(sensor->clk); in st_thermal_sensor_off()
86 struct device *dev = sensor->dev; in st_thermal_calibration()
88 /* Check if sensor calibration data is already written */ in st_thermal_calibration()
89 ret = regmap_field_read(sensor->dcorrect, &val); in st_thermal_calibration()
91 dev_err(dev, "failed to read calibration data\n"); in st_thermal_calibration()
97 * Sensor calibration value not set by bootloader, in st_thermal_calibration()
98 * default calibration data to be used in st_thermal_calibration()
100 ret = regmap_field_write(sensor->dcorrect, in st_thermal_calibration()
101 sensor->cdata->calibration_val); in st_thermal_calibration()
103 dev_err(dev, "failed to set calibration data\n"); in st_thermal_calibration()
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()
143 struct device *dev = &pdev->dev; in st_thermal_register()
144 struct device_node *np = dev->of_node; in st_thermal_register()
151 return -EINVAL; in st_thermal_register()
156 return -ENOMEM; in st_thermal_register()
158 sensor->dev = dev; in st_thermal_register()
161 if (!(match && match->data)) in st_thermal_register()
162 return -EINVAL; in st_thermal_register()
164 sensor->cdata = match->data; in st_thermal_register()
165 if (!sensor->cdata->ops) in st_thermal_register()
166 return -EINVAL; in st_thermal_register()
168 sensor->ops = sensor->cdata->ops; in st_thermal_register()
170 ret = (sensor->ops->regmap_init)(sensor); in st_thermal_register()
178 sensor->clk = devm_clk_get(dev, "thermal"); in st_thermal_register()
179 if (IS_ERR(sensor->clk)) { in st_thermal_register()
181 return PTR_ERR(sensor->clk); in st_thermal_register()
184 if (sensor->ops->register_enable_irq) { in st_thermal_register()
185 ret = sensor->ops->register_enable_irq(sensor); in st_thermal_register()
198 sensor->thermal_dev = in st_thermal_register()
200 if (IS_ERR(sensor->thermal_dev)) { in st_thermal_register()
201 dev_err(dev, "failed to register thermal of zone\n"); in st_thermal_register()
202 ret = PTR_ERR(sensor->thermal_dev); in st_thermal_register()
212 devm_thermal_add_hwmon_sysfs(dev, sensor->thermal_dev); in st_thermal_register()
228 thermal_remove_hwmon_sysfs(sensor->thermal_dev); in st_thermal_unregister()
229 devm_thermal_of_zone_unregister(sensor->dev, sensor->thermal_dev); in st_thermal_unregister()
253 if (sensor->ops->enable_irq) { in st_thermal_resume()
254 ret = sensor->ops->enable_irq(sensor); in st_thermal_resume()
266 MODULE_DESCRIPTION("STMicroelectronics STi SoC Thermal Sensor Driver");