Lines Matching full:sensor

3  * ST Thermal Sensor Driver core routines
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()
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 = th->devdata; in st_thermal_get_temp() local
112 struct device *dev = sensor->dev; in st_thermal_get_temp()
117 ret = regmap_field_read(sensor->overflow, &overflow); 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() local
141 struct device *dev = sensor->dev; in st_thermal_get_trip_type()
158 struct st_thermal_sensor *sensor = th->devdata; in st_thermal_get_trip_temp() local
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()
182 struct st_thermal_sensor *sensor; in st_thermal_register() local
195 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); in st_thermal_register()
196 if (!sensor) in st_thermal_register()
199 sensor->dev = dev; in st_thermal_register()
205 sensor->cdata = match->data; in st_thermal_register()
206 if (!sensor->cdata->ops) 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()
215 ret = st_thermal_alloc_regfields(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()
231 ret = st_thermal_sensor_on(sensor); in st_thermal_register()
235 ret = st_thermal_calibration(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()
242 thermal_zone_device_register(dev_name(dev), 1, 0, sensor, in st_thermal_register()
244 if (IS_ERR(sensor->thermal_dev)) { 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()
253 platform_set_drvdata(pdev, sensor); in st_thermal_register()
258 thermal_zone_device_unregister(sensor->thermal_dev); in st_thermal_register()
260 st_thermal_sensor_off(sensor); in st_thermal_register()
268 struct st_thermal_sensor *sensor = platform_get_drvdata(pdev); in st_thermal_unregister() local
270 st_thermal_sensor_off(sensor); in st_thermal_unregister()
271 thermal_zone_device_unregister(sensor->thermal_dev); in st_thermal_unregister()
280 struct st_thermal_sensor *sensor = dev_get_drvdata(dev); in st_thermal_suspend() local
282 return st_thermal_sensor_off(sensor); in st_thermal_suspend()
288 struct st_thermal_sensor *sensor = dev_get_drvdata(dev); in st_thermal_resume() local
290 ret = st_thermal_sensor_on(sensor); in st_thermal_resume()
294 ret = st_thermal_calibration(sensor); in st_thermal_resume()
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");