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

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 #define mcelsius(temp) ((temp) * 1000) argument
23 static int st_thermal_alloc_regfields(struct st_thermal_sensor *sensor) in st_thermal_alloc_regfields() argument
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()
48 static int st_thermal_sensor_on(struct st_thermal_sensor *sensor) in st_thermal_sensor_on() argument
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()
61 dev_err(dev, "failed to power on sensor\n"); in st_thermal_sensor_on()
62 clk_disable_unprepare(sensor->clk); in st_thermal_sensor_on()
68 static int st_thermal_sensor_off(struct st_thermal_sensor *sensor) in st_thermal_sensor_off() argument
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()
81 static int st_thermal_calibration(struct st_thermal_sensor *sensor) in st_thermal_calibration() argument
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()
96 * Sensor calibration value not set by bootloader, in st_thermal_calibration()
99 ret = regmap_field_write(sensor->dcorrect, in st_thermal_calibration()
100 sensor->cdata->calibration_val); in st_thermal_calibration()
111 struct st_thermal_sensor *sensor = thermal_zone_device_priv(th); in st_thermal_get_temp() local
112 unsigned int temp; in st_thermal_get_temp() local
116 ret = regmap_field_read(sensor->overflow, &overflow); in st_thermal_get_temp()
120 return -EIO; in st_thermal_get_temp()
122 ret = regmap_field_read(sensor->temp_data, &temp); in st_thermal_get_temp()
126 temp += sensor->cdata->temp_adjust_val; in st_thermal_get_temp()
127 temp = mcelsius(temp); in st_thermal_get_temp()
129 *temperature = temp; in st_thermal_get_temp()
143 struct st_thermal_sensor *sensor; in st_thermal_register() local
144 struct device *dev = &pdev->dev; in st_thermal_register()
145 struct device_node *np = dev->of_node; in st_thermal_register()
153 return -EINVAL; in st_thermal_register()
156 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); in st_thermal_register()
157 if (!sensor) in st_thermal_register()
158 return -ENOMEM; in st_thermal_register()
160 sensor->dev = dev; in st_thermal_register()
163 if (!(match && match->data)) in st_thermal_register()
164 return -EINVAL; in st_thermal_register()
166 sensor->cdata = match->data; in st_thermal_register()
167 if (!sensor->cdata->ops) in st_thermal_register()
168 return -EINVAL; in st_thermal_register()
170 sensor->ops = sensor->cdata->ops; in st_thermal_register()
172 ret = (sensor->ops->regmap_init)(sensor); in st_thermal_register()
176 ret = st_thermal_alloc_regfields(sensor); in st_thermal_register()
180 sensor->clk = devm_clk_get(dev, "thermal"); in st_thermal_register()
181 if (IS_ERR(sensor->clk)) { in st_thermal_register()
183 return PTR_ERR(sensor->clk); in st_thermal_register()
186 if (sensor->ops->register_enable_irq) { in st_thermal_register()
187 ret = sensor->ops->register_enable_irq(sensor); in st_thermal_register()
192 ret = st_thermal_sensor_on(sensor); in st_thermal_register()
196 ret = st_thermal_calibration(sensor); in st_thermal_register()
200 polling_delay = sensor->ops->register_enable_irq ? 0 : 1000; in st_thermal_register()
202 trip.temperature = sensor->cdata->crit_temp; in st_thermal_register()
205 sensor->thermal_dev = in st_thermal_register()
206 thermal_zone_device_register_with_trips(dev_name(dev), &trip, 1, 0, sensor, in st_thermal_register()
208 if (IS_ERR(sensor->thermal_dev)) { in st_thermal_register()
210 ret = PTR_ERR(sensor->thermal_dev); in st_thermal_register()
213 ret = thermal_zone_device_enable(sensor->thermal_dev); in st_thermal_register()
217 platform_set_drvdata(pdev, sensor); in st_thermal_register()
222 thermal_zone_device_unregister(sensor->thermal_dev); in st_thermal_register()
224 st_thermal_sensor_off(sensor); in st_thermal_register()
232 struct st_thermal_sensor *sensor = platform_get_drvdata(pdev); in st_thermal_unregister() local
234 st_thermal_sensor_off(sensor); in st_thermal_unregister()
235 thermal_zone_device_unregister(sensor->thermal_dev); in st_thermal_unregister()
242 struct st_thermal_sensor *sensor = dev_get_drvdata(dev); in st_thermal_suspend() local
244 return st_thermal_sensor_off(sensor); in st_thermal_suspend()
250 struct st_thermal_sensor *sensor = dev_get_drvdata(dev); in st_thermal_resume() local
252 ret = st_thermal_sensor_on(sensor); in st_thermal_resume()
256 ret = st_thermal_calibration(sensor); in st_thermal_resume()
260 if (sensor->ops->enable_irq) { in st_thermal_resume()
261 ret = sensor->ops->enable_irq(sensor); in st_thermal_resume()
274 MODULE_DESCRIPTION("STMicroelectronics STi SoC Thermal Sensor Driver");