Lines Matching +full:data +full:- +full:addr

4  * Copyright (c) 2014-2015 Hisilicon Limited.
5 * Copyright (c) 2014-2015 Linaro Limited.
49 #define HI6220_TEMP_BASE (-60000)
54 #define HI3660_TEMP_BASE (-63780)
69 struct hisi_thermal_data *data; member
81 int (*probe)(struct hisi_thermal_data *data);
97 * Temperature base: -60°C
100 * millidegree and begins at -60 000 m°C
108 * steps = (Temp - TempBase) / 785
118 return DIV_ROUND_UP(temp - HI6220_TEMP_BASE, HI6220_TEMP_STEP); in hi6220_thermal_temp_to_step()
124 * Temperature base: -63.780°C
127 * millidegree and begins at -63 780 m°C
136 return DIV_ROUND_UP(temp - HI3660_TEMP_BASE, HI3660_TEMP_STEP); in hi3660_thermal_temp_to_step()
154 * temperature decrease to 65°C - 5°C another interrupt is raised.
170 static inline void hi6220_thermal_set_lag(void __iomem *addr, int value) in hi6220_thermal_set_lag() argument
173 addr + HI6220_TEMP0_LAG); in hi6220_thermal_set_lag()
176 static inline void hi6220_thermal_alarm_clear(void __iomem *addr, int value) in hi6220_thermal_alarm_clear() argument
178 writel(value, addr + HI6220_TEMP0_INT_CLR); in hi6220_thermal_alarm_clear()
181 static inline void hi6220_thermal_alarm_enable(void __iomem *addr, int value) in hi6220_thermal_alarm_enable() argument
183 writel(value, addr + HI6220_TEMP0_INT_EN); in hi6220_thermal_alarm_enable()
186 static inline void hi6220_thermal_alarm_set(void __iomem *addr, int temp) in hi6220_thermal_alarm_set() argument
189 addr + HI6220_TEMP0_TH); in hi6220_thermal_alarm_set()
192 static inline void hi6220_thermal_reset_set(void __iomem *addr, int temp) in hi6220_thermal_reset_set() argument
194 writel(hi6220_thermal_temp_to_step(temp), addr + HI6220_TEMP0_RST_TH); in hi6220_thermal_reset_set()
197 static inline void hi6220_thermal_reset_enable(void __iomem *addr, int value) in hi6220_thermal_reset_enable() argument
199 writel(value, addr + HI6220_TEMP0_RST_MSK); in hi6220_thermal_reset_enable()
202 static inline void hi6220_thermal_enable(void __iomem *addr, int value) in hi6220_thermal_enable() argument
204 writel(value, addr + HI6220_TEMP0_EN); in hi6220_thermal_enable()
207 static inline int hi6220_thermal_get_temperature(void __iomem *addr) in hi6220_thermal_get_temperature() argument
209 return hi6220_thermal_step_to_temp(readl(addr + HI6220_TEMP0_VALUE)); in hi6220_thermal_get_temperature()
221 static inline void hi3660_thermal_set_lag(void __iomem *addr, in hi3660_thermal_set_lag() argument
225 addr + HI3660_LAG(id)); in hi3660_thermal_set_lag()
228 static inline void hi3660_thermal_alarm_clear(void __iomem *addr, in hi3660_thermal_alarm_clear() argument
231 writel(value, addr + HI3660_INT_CLR(id)); in hi3660_thermal_alarm_clear()
234 static inline void hi3660_thermal_alarm_enable(void __iomem *addr, in hi3660_thermal_alarm_enable() argument
237 writel(value, addr + HI3660_INT_EN(id)); in hi3660_thermal_alarm_enable()
240 static inline void hi3660_thermal_alarm_set(void __iomem *addr, in hi3660_thermal_alarm_set() argument
243 writel(value, addr + HI3660_TH(id)); in hi3660_thermal_alarm_set()
246 static inline int hi3660_thermal_get_temperature(void __iomem *addr, int id) in hi3660_thermal_get_temperature() argument
248 return hi3660_thermal_step_to_temp(readl(addr + HI3660_TEMP(id))); in hi3660_thermal_get_temperature()
252 * Temperature configuration register - Sensor selection
261 static inline void hi6220_thermal_sensor_select(void __iomem *addr, int sensor) in hi6220_thermal_sensor_select() argument
263 writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_SS_MSK) | in hi6220_thermal_sensor_select()
264 (sensor << 12), addr + HI6220_TEMP0_CFG); in hi6220_thermal_sensor_select()
268 * Temperature configuration register - Hdak conversion polling interval
277 static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value) in hi6220_thermal_hdak_set() argument
279 writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_HDAK_MSK) | in hi6220_thermal_hdak_set()
280 (value << 4), addr + HI6220_TEMP0_CFG); in hi6220_thermal_hdak_set()
285 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_irq_handler() local
287 hi6220_thermal_alarm_clear(data->regs, 1); in hi6220_thermal_irq_handler()
293 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_irq_handler() local
295 hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); in hi3660_thermal_irq_handler()
301 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_get_temp() local
303 return hi6220_thermal_get_temperature(data->regs); in hi6220_thermal_get_temp()
308 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_get_temp() local
310 return hi3660_thermal_get_temperature(data->regs, sensor->id); in hi3660_thermal_get_temp()
315 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_disable_sensor() local
318 hi6220_thermal_enable(data->regs, 0); in hi6220_thermal_disable_sensor()
319 hi6220_thermal_alarm_enable(data->regs, 0); in hi6220_thermal_disable_sensor()
320 hi6220_thermal_reset_enable(data->regs, 0); in hi6220_thermal_disable_sensor()
322 clk_disable_unprepare(data->clk); in hi6220_thermal_disable_sensor()
329 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_disable_sensor() local
332 hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); in hi3660_thermal_disable_sensor()
338 struct hisi_thermal_data *data = sensor->data; in hi6220_thermal_enable_sensor() local
342 ret = clk_prepare_enable(data->clk); in hi6220_thermal_enable_sensor()
347 hi6220_thermal_reset_enable(data->regs, 0); in hi6220_thermal_enable_sensor()
348 hi6220_thermal_enable(data->regs, 0); in hi6220_thermal_enable_sensor()
351 hi6220_thermal_sensor_select(data->regs, sensor->id); in hi6220_thermal_enable_sensor()
354 hi6220_thermal_hdak_set(data->regs, 0); in hi6220_thermal_enable_sensor()
357 hi6220_thermal_set_lag(data->regs, HI6220_TEMP_LAG); in hi6220_thermal_enable_sensor()
360 hi6220_thermal_alarm_set(data->regs, sensor->thres_temp); in hi6220_thermal_enable_sensor()
362 hi6220_thermal_reset_set(data->regs, HI6220_TEMP_RESET); in hi6220_thermal_enable_sensor()
365 hi6220_thermal_reset_enable(data->regs, 1); in hi6220_thermal_enable_sensor()
366 hi6220_thermal_enable(data->regs, 1); in hi6220_thermal_enable_sensor()
368 hi6220_thermal_alarm_clear(data->regs, 0); in hi6220_thermal_enable_sensor()
369 hi6220_thermal_alarm_enable(data->regs, 1); in hi6220_thermal_enable_sensor()
377 struct hisi_thermal_data *data = sensor->data; in hi3660_thermal_enable_sensor() local
380 hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); in hi3660_thermal_enable_sensor()
383 hi3660_thermal_set_lag(data->regs, sensor->id, HI3660_TEMP_LAG); in hi3660_thermal_enable_sensor()
386 value = hi3660_thermal_temp_to_step(sensor->thres_temp); in hi3660_thermal_enable_sensor()
387 hi3660_thermal_alarm_set(data->regs, sensor->id, value); in hi3660_thermal_enable_sensor()
390 hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); in hi3660_thermal_enable_sensor()
391 hi3660_thermal_alarm_enable(data->regs, sensor->id, 1); in hi3660_thermal_enable_sensor()
396 static int hi6220_thermal_probe(struct hisi_thermal_data *data) in hi6220_thermal_probe() argument
398 struct platform_device *pdev = data->pdev; in hi6220_thermal_probe()
399 struct device *dev = &pdev->dev; in hi6220_thermal_probe()
402 data->clk = devm_clk_get(dev, "thermal_clk"); in hi6220_thermal_probe()
403 if (IS_ERR(data->clk)) { in hi6220_thermal_probe()
404 ret = PTR_ERR(data->clk); in hi6220_thermal_probe()
405 if (ret != -EPROBE_DEFER) in hi6220_thermal_probe()
410 data->sensor = devm_kzalloc(dev, sizeof(*data->sensor), GFP_KERNEL); in hi6220_thermal_probe()
411 if (!data->sensor) in hi6220_thermal_probe()
412 return -ENOMEM; in hi6220_thermal_probe()
414 data->sensor[0].id = HI6220_CLUSTER0_SENSOR; in hi6220_thermal_probe()
415 data->sensor[0].irq_name = "tsensor_intr"; in hi6220_thermal_probe()
416 data->sensor[0].data = data; in hi6220_thermal_probe()
417 data->nr_sensors = 1; in hi6220_thermal_probe()
422 static int hi3660_thermal_probe(struct hisi_thermal_data *data) in hi3660_thermal_probe() argument
424 struct platform_device *pdev = data->pdev; in hi3660_thermal_probe()
425 struct device *dev = &pdev->dev; in hi3660_thermal_probe()
427 data->nr_sensors = 1; in hi3660_thermal_probe()
429 data->sensor = devm_kzalloc(dev, sizeof(*data->sensor) * in hi3660_thermal_probe()
430 data->nr_sensors, GFP_KERNEL); in hi3660_thermal_probe()
431 if (!data->sensor) in hi3660_thermal_probe()
432 return -ENOMEM; in hi3660_thermal_probe()
434 data->sensor[0].id = HI3660_BIG_SENSOR; in hi3660_thermal_probe()
435 data->sensor[0].irq_name = "tsensor_a73"; in hi3660_thermal_probe()
436 data->sensor[0].data = data; in hi3660_thermal_probe()
438 data->sensor[1].id = HI3660_LITTLE_SENSOR; in hi3660_thermal_probe()
439 data->sensor[1].irq_name = "tsensor_a53"; in hi3660_thermal_probe()
440 data->sensor[1].data = data; in hi3660_thermal_probe()
448 struct hisi_thermal_data *data = sensor->data; in hisi_thermal_get_temp() local
450 *temp = data->ops->get_temp(sensor); in hisi_thermal_get_temp()
452 dev_dbg(&data->pdev->dev, "tzd=%p, id=%d, temp=%d, thres=%d\n", in hisi_thermal_get_temp()
453 sensor->tzd, sensor->id, *temp, sensor->thres_temp); in hisi_thermal_get_temp()
465 struct hisi_thermal_data *data = sensor->data; in hisi_thermal_alarm_irq_thread() local
468 data->ops->irq_handler(sensor); in hisi_thermal_alarm_irq_thread()
472 if (temp >= sensor->thres_temp) { in hisi_thermal_alarm_irq_thread()
473 dev_crit(&data->pdev->dev, in hisi_thermal_alarm_irq_thread()
475 sensor->id, temp, sensor->thres_temp); in hisi_thermal_alarm_irq_thread()
477 thermal_zone_device_update(sensor->tzd, in hisi_thermal_alarm_irq_thread()
481 dev_crit(&data->pdev->dev, in hisi_thermal_alarm_irq_thread()
483 sensor->id, temp, sensor->thres_temp); in hisi_thermal_alarm_irq_thread()
495 sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, in hisi_thermal_register_sensor()
496 sensor->id, sensor, in hisi_thermal_register_sensor()
498 if (IS_ERR(sensor->tzd)) { in hisi_thermal_register_sensor()
499 ret = PTR_ERR(sensor->tzd); in hisi_thermal_register_sensor()
500 sensor->tzd = NULL; in hisi_thermal_register_sensor()
501 dev_err(&pdev->dev, "failed to register sensor id %d: %d\n", in hisi_thermal_register_sensor()
502 sensor->id, ret); in hisi_thermal_register_sensor()
506 trip = of_thermal_get_trip_points(sensor->tzd); in hisi_thermal_register_sensor()
508 for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { in hisi_thermal_register_sensor()
510 sensor->thres_temp = trip[i].temperature; in hisi_thermal_register_sensor()
537 .data = &hi6220_ops,
540 .compatible = "hisilicon,hi3660-tsensor",
541 .data = &hi3660_ops,
550 struct thermal_zone_device *tzd = sensor->tzd; in hisi_thermal_toggle_sensor()
560 struct hisi_thermal_data *data; in hisi_thermal_probe() local
561 struct device *dev = &pdev->dev; in hisi_thermal_probe()
565 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in hisi_thermal_probe()
566 if (!data) in hisi_thermal_probe()
567 return -ENOMEM; in hisi_thermal_probe()
569 data->pdev = pdev; in hisi_thermal_probe()
570 platform_set_drvdata(pdev, data); in hisi_thermal_probe()
571 data->ops = of_device_get_match_data(dev); in hisi_thermal_probe()
574 data->regs = devm_ioremap_resource(dev, res); in hisi_thermal_probe()
575 if (IS_ERR(data->regs)) { in hisi_thermal_probe()
577 return PTR_ERR(data->regs); in hisi_thermal_probe()
580 ret = data->ops->probe(data); in hisi_thermal_probe()
584 for (i = 0; i < data->nr_sensors; i++) { in hisi_thermal_probe()
585 struct hisi_thermal_sensor *sensor = &data->sensor[i]; in hisi_thermal_probe()
600 IRQF_ONESHOT, sensor->irq_name, in hisi_thermal_probe()
607 ret = data->ops->enable_sensor(sensor); in hisi_thermal_probe()
621 struct hisi_thermal_data *data = platform_get_drvdata(pdev); in hisi_thermal_remove() local
624 for (i = 0; i < data->nr_sensors; i++) { in hisi_thermal_remove()
625 struct hisi_thermal_sensor *sensor = &data->sensor[i]; in hisi_thermal_remove()
628 data->ops->disable_sensor(sensor); in hisi_thermal_remove()
637 struct hisi_thermal_data *data = dev_get_drvdata(dev); in hisi_thermal_suspend() local
640 for (i = 0; i < data->nr_sensors; i++) in hisi_thermal_suspend()
641 data->ops->disable_sensor(&data->sensor[i]); in hisi_thermal_suspend()
648 struct hisi_thermal_data *data = dev_get_drvdata(dev); in hisi_thermal_resume() local
651 for (i = 0; i < data->nr_sensors; i++) in hisi_thermal_resume()
652 ret |= data->ops->enable_sensor(&data->sensor[i]); in hisi_thermal_resume()