Lines Matching +full:data +full:- +full:addr
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2014-2015 HiSilicon Limited.
6 * Copyright (c) 2014-2015 Linaro Limited.
40 #define HI6220_TEMP_BASE (-60000)
45 #define HI3660_TEMP_BASE (-63780)
60 struct hisi_thermal_data *data; member
72 int (*probe)(struct hisi_thermal_data *data);
88 * Temperature base: -60°C
91 * millidegree and begins at -60 000 m°C
99 * steps = (Temp - TempBase) / 785
109 return DIV_ROUND_UP(temp - HI6220_TEMP_BASE, HI6220_TEMP_STEP); in hi6220_thermal_temp_to_step()
115 * Temperature base: -63.780°C
118 * millidegree and begins at -63 780 m°C
127 return DIV_ROUND_UP(temp - HI3660_TEMP_BASE, HI3660_TEMP_STEP); in hi3660_thermal_temp_to_step()
145 * temperature decrease to 65°C - 5°C another interrupt is raised.
161 static inline void hi6220_thermal_set_lag(void __iomem *addr, int value) in hi6220_thermal_set_lag() argument
164 addr + HI6220_TEMP0_LAG); in hi6220_thermal_set_lag()
167 static inline void hi6220_thermal_alarm_clear(void __iomem *addr, int value) in hi6220_thermal_alarm_clear() argument
169 writel(value, addr + HI6220_TEMP0_INT_CLR); in hi6220_thermal_alarm_clear()
172 static inline void hi6220_thermal_alarm_enable(void __iomem *addr, int value) in hi6220_thermal_alarm_enable() argument
174 writel(value, addr + HI6220_TEMP0_INT_EN); in hi6220_thermal_alarm_enable()
177 static inline void hi6220_thermal_alarm_set(void __iomem *addr, int temp) in hi6220_thermal_alarm_set() argument
180 addr + HI6220_TEMP0_TH); in hi6220_thermal_alarm_set()
183 static inline void hi6220_thermal_reset_set(void __iomem *addr, int temp) in hi6220_thermal_reset_set() argument
185 writel(hi6220_thermal_temp_to_step(temp), addr + HI6220_TEMP0_RST_TH); in hi6220_thermal_reset_set()
188 static inline void hi6220_thermal_reset_enable(void __iomem *addr, int value) in hi6220_thermal_reset_enable() argument
190 writel(value, addr + HI6220_TEMP0_RST_MSK); in hi6220_thermal_reset_enable()
193 static inline void hi6220_thermal_enable(void __iomem *addr, int value) in hi6220_thermal_enable() argument
195 writel(value, addr + HI6220_TEMP0_EN); in hi6220_thermal_enable()
198 static inline int hi6220_thermal_get_temperature(void __iomem *addr) in hi6220_thermal_get_temperature() argument
200 return hi6220_thermal_step_to_temp(readl(addr + HI6220_TEMP0_VALUE)); in hi6220_thermal_get_temperature()
212 static inline void hi3660_thermal_set_lag(void __iomem *addr, in hi3660_thermal_set_lag() argument
216 addr + HI3660_LAG(id)); in hi3660_thermal_set_lag()
219 static inline void hi3660_thermal_alarm_clear(void __iomem *addr, in hi3660_thermal_alarm_clear() argument
222 writel(value, addr + HI3660_INT_CLR(id)); in hi3660_thermal_alarm_clear()
225 static inline void hi3660_thermal_alarm_enable(void __iomem *addr, in hi3660_thermal_alarm_enable() argument
228 writel(value, addr + HI3660_INT_EN(id)); in hi3660_thermal_alarm_enable()
231 static inline void hi3660_thermal_alarm_set(void __iomem *addr, in hi3660_thermal_alarm_set() argument
234 writel(value, addr + HI3660_TH(id)); in hi3660_thermal_alarm_set()
237 static inline int hi3660_thermal_get_temperature(void __iomem *addr, int id) in hi3660_thermal_get_temperature() argument
239 return hi3660_thermal_step_to_temp(readl(addr + HI3660_TEMP(id))); in hi3660_thermal_get_temperature()
243 * Temperature configuration register - Sensor selection
252 static inline void hi6220_thermal_sensor_select(void __iomem *addr, int sensor) in hi6220_thermal_sensor_select() argument
254 writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_SS_MSK) | in hi6220_thermal_sensor_select()
255 (sensor << 12), addr + HI6220_TEMP0_CFG); in hi6220_thermal_sensor_select()
259 * Temperature configuration register - Hdak conversion polling interval
268 static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value) in hi6220_thermal_hdak_set() argument
270 writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_HDAK_MSK) | in hi6220_thermal_hdak_set()
271 (value << 4), addr + HI6220_TEMP0_CFG); in hi6220_thermal_hdak_set()
276 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_irq_handler() local
278 hi6220_thermal_alarm_clear(data->regs, 1); in hi6220_thermal_irq_handler()
284 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_irq_handler() local
286 hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); in hi3660_thermal_irq_handler()
292 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_get_temp() local
294 return hi6220_thermal_get_temperature(data->regs); in hi6220_thermal_get_temp()
299 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_get_temp() local
301 return hi3660_thermal_get_temperature(data->regs, sensor->id); in hi3660_thermal_get_temp()
306 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_disable_sensor() local
309 hi6220_thermal_enable(data->regs, 0); in hi6220_thermal_disable_sensor()
310 hi6220_thermal_alarm_enable(data->regs, 0); in hi6220_thermal_disable_sensor()
311 hi6220_thermal_reset_enable(data->regs, 0); in hi6220_thermal_disable_sensor()
313 clk_disable_unprepare(data->clk); in hi6220_thermal_disable_sensor()
320 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_disable_sensor() local
323 hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); in hi3660_thermal_disable_sensor()
329 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_enable_sensor() local
333 ret = clk_prepare_enable(data->clk); in hi6220_thermal_enable_sensor()
338 hi6220_thermal_reset_enable(data->regs, 0); in hi6220_thermal_enable_sensor()
339 hi6220_thermal_enable(data->regs, 0); in hi6220_thermal_enable_sensor()
342 hi6220_thermal_sensor_select(data->regs, sensor->id); in hi6220_thermal_enable_sensor()
345 hi6220_thermal_hdak_set(data->regs, 0); in hi6220_thermal_enable_sensor()
348 hi6220_thermal_set_lag(data->regs, HI6220_TEMP_LAG); in hi6220_thermal_enable_sensor()
351 hi6220_thermal_alarm_set(data->regs, sensor->thres_temp); in hi6220_thermal_enable_sensor()
353 hi6220_thermal_reset_set(data->regs, HI6220_TEMP_RESET); in hi6220_thermal_enable_sensor()
356 hi6220_thermal_reset_enable(data->regs, 1); in hi6220_thermal_enable_sensor()
357 hi6220_thermal_enable(data->regs, 1); in hi6220_thermal_enable_sensor()
359 hi6220_thermal_alarm_clear(data->regs, 0); in hi6220_thermal_enable_sensor()
360 hi6220_thermal_alarm_enable(data->regs, 1); in hi6220_thermal_enable_sensor()
368 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_enable_sensor() local
371 hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); in hi3660_thermal_enable_sensor()
374 hi3660_thermal_set_lag(data->regs, sensor->id, HI3660_TEMP_LAG); in hi3660_thermal_enable_sensor()
377 value = hi3660_thermal_temp_to_step(sensor->thres_temp); in hi3660_thermal_enable_sensor()
378 hi3660_thermal_alarm_set(data->regs, sensor->id, value); in hi3660_thermal_enable_sensor()
381 hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); in hi3660_thermal_enable_sensor()
382 hi3660_thermal_alarm_enable(data->regs, sensor->id, 1); in hi3660_thermal_enable_sensor()
387 static int hi6220_thermal_probe(struct hisi_thermal_data *data) in hi6220_thermal_probe() argument
389 struct platform_device *pdev = data->pdev; in hi6220_thermal_probe()
390 struct device *dev = &pdev->dev; in hi6220_thermal_probe()
393 data->clk = devm_clk_get(dev, "thermal_clk"); in hi6220_thermal_probe()
394 if (IS_ERR(data->clk)) { in hi6220_thermal_probe()
395 ret = PTR_ERR(data->clk); in hi6220_thermal_probe()
396 if (ret != -EPROBE_DEFER) in hi6220_thermal_probe()
401 data->sensor = devm_kzalloc(dev, sizeof(*data->sensor), GFP_KERNEL); in hi6220_thermal_probe()
402 if (!data->sensor) in hi6220_thermal_probe()
403 return -ENOMEM; in hi6220_thermal_probe()
405 data->sensor[0].id = HI6220_CLUSTER0_SENSOR; in hi6220_thermal_probe()
406 data->sensor[0].irq_name = "tsensor_intr"; in hi6220_thermal_probe()
407 data->sensor[0].data = data; in hi6220_thermal_probe()
408 data->nr_sensors = 1; in hi6220_thermal_probe()
413 static int hi3660_thermal_probe(struct hisi_thermal_data *data) in hi3660_thermal_probe() argument
415 struct platform_device *pdev = data->pdev; in hi3660_thermal_probe()
416 struct device *dev = &pdev->dev; in hi3660_thermal_probe()
418 data->nr_sensors = 1; in hi3660_thermal_probe()
420 data->sensor = devm_kzalloc(dev, sizeof(*data->sensor) * in hi3660_thermal_probe()
421 data->nr_sensors, GFP_KERNEL); in hi3660_thermal_probe()
422 if (!data->sensor) in hi3660_thermal_probe()
423 return -ENOMEM; in hi3660_thermal_probe()
425 data->sensor[0].id = HI3660_BIG_SENSOR; in hi3660_thermal_probe()
426 data->sensor[0].irq_name = "tsensor_a73"; in hi3660_thermal_probe()
427 data->sensor[0].data = data; in hi3660_thermal_probe()
435 struct hisi_thermal_data *data = sensor->data; in hisi_thermal_get_temp() local
437 *temp = data->ops->get_temp(sensor); in hisi_thermal_get_temp()
449 struct hisi_thermal_data *data = sensor->data; in hisi_thermal_alarm_irq_thread() local
452 data->ops->irq_handler(sensor); in hisi_thermal_alarm_irq_thread()
454 temp = data->ops->get_temp(sensor); in hisi_thermal_alarm_irq_thread()
456 if (temp >= sensor->thres_temp) { in hisi_thermal_alarm_irq_thread()
457 dev_crit(&data->pdev->dev, in hisi_thermal_alarm_irq_thread()
459 sensor->id, temp, sensor->thres_temp); in hisi_thermal_alarm_irq_thread()
461 thermal_zone_device_update(sensor->tzd, in hisi_thermal_alarm_irq_thread()
465 dev_crit(&data->pdev->dev, in hisi_thermal_alarm_irq_thread()
467 sensor->id, temp, sensor->thres_temp); in hisi_thermal_alarm_irq_thread()
479 sensor->tzd = devm_thermal_of_zone_register(&pdev->dev, in hisi_thermal_register_sensor()
480 sensor->id, sensor, in hisi_thermal_register_sensor()
482 if (IS_ERR(sensor->tzd)) { in hisi_thermal_register_sensor()
483 ret = PTR_ERR(sensor->tzd); in hisi_thermal_register_sensor()
484 sensor->tzd = NULL; in hisi_thermal_register_sensor()
485 dev_err(&pdev->dev, "failed to register sensor id %d: %d\n", in hisi_thermal_register_sensor()
486 sensor->id, ret); in hisi_thermal_register_sensor()
490 for (i = 0; i < thermal_zone_get_num_trips(sensor->tzd); i++) { in hisi_thermal_register_sensor()
492 thermal_zone_get_trip(sensor->tzd, i, &trip); in hisi_thermal_register_sensor()
495 sensor->thres_temp = trip.temperature; in hisi_thermal_register_sensor()
522 .data = &hi6220_ops,
525 .compatible = "hisilicon,hi3660-tsensor",
526 .data = &hi3660_ops,
535 struct thermal_zone_device *tzd = sensor->tzd; in hisi_thermal_toggle_sensor()
545 struct hisi_thermal_data *data; in hisi_thermal_probe() local
546 struct device *dev = &pdev->dev; in hisi_thermal_probe()
549 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in hisi_thermal_probe()
550 if (!data) in hisi_thermal_probe()
551 return -ENOMEM; in hisi_thermal_probe()
553 data->pdev = pdev; in hisi_thermal_probe()
554 platform_set_drvdata(pdev, data); in hisi_thermal_probe()
555 data->ops = of_device_get_match_data(dev); in hisi_thermal_probe()
557 data->regs = devm_platform_ioremap_resource(pdev, 0); in hisi_thermal_probe()
558 if (IS_ERR(data->regs)) in hisi_thermal_probe()
559 return PTR_ERR(data->regs); in hisi_thermal_probe()
561 ret = data->ops->probe(data); in hisi_thermal_probe()
565 for (i = 0; i < data->nr_sensors; i++) { in hisi_thermal_probe()
566 struct hisi_thermal_sensor *sensor = &data->sensor[i]; in hisi_thermal_probe()
581 IRQF_ONESHOT, sensor->irq_name, in hisi_thermal_probe()
588 ret = data->ops->enable_sensor(sensor); in hisi_thermal_probe()
602 struct hisi_thermal_data *data = platform_get_drvdata(pdev); in hisi_thermal_remove() local
605 for (i = 0; i < data->nr_sensors; i++) { in hisi_thermal_remove()
606 struct hisi_thermal_sensor *sensor = &data->sensor[i]; in hisi_thermal_remove()
609 data->ops->disable_sensor(sensor); in hisi_thermal_remove()
615 struct hisi_thermal_data *data = dev_get_drvdata(dev); in hisi_thermal_suspend() local
618 for (i = 0; i < data->nr_sensors; i++) in hisi_thermal_suspend()
619 data->ops->disable_sensor(&data->sensor[i]); in hisi_thermal_suspend()
626 struct hisi_thermal_data *data = dev_get_drvdata(dev); in hisi_thermal_resume() local
629 for (i = 0; i < data->nr_sensors; i++) in hisi_thermal_resume()
630 ret |= data->ops->enable_sensor(&data->sensor[i]); in hisi_thermal_resume()