Skip to content

Commit c03d431

Browse files
author
Rafał Miłecki
committed
kernel: backport Broadcom thermal drivers
This includes driver for Northstar and for Raspberry Pi. Signed-off-by: Rafał Miłecki <[email protected]>
1 parent 8f254e9 commit c03d431

5 files changed

+801
-0
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
From e498b4984db82b4ba3ceea7dba813222a31e9c2e Mon Sep 17 00:00:00 2001
2+
From: Laxman Dewangan <[email protected]>
3+
Date: Wed, 9 Mar 2016 18:40:06 +0530
4+
Subject: [PATCH] thermal: of-thermal: Add devm version of
5+
thermal_zone_of_sensor_register
6+
7+
Add resource managed version of thermal_zone_of_sensor_register() and
8+
thermal_zone_of_sensor_unregister().
9+
10+
This helps in reducing the code size in error path, remove of
11+
driver remove callbacks and making proper sequence for deallocations.
12+
13+
Signed-off-by: Laxman Dewangan <[email protected]>
14+
Signed-off-by: Eduardo Valentin <[email protected]>
15+
---
16+
drivers/thermal/of-thermal.c | 81 ++++++++++++++++++++++++++++++++++++++++++++
17+
include/linux/thermal.h | 18 ++++++++++
18+
2 files changed, 99 insertions(+)
19+
20+
--- a/drivers/thermal/of-thermal.c
21+
+++ b/drivers/thermal/of-thermal.c
22+
@@ -559,6 +559,87 @@ void thermal_zone_of_sensor_unregister(s
23+
}
24+
EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister);
25+
26+
+static void devm_thermal_zone_of_sensor_release(struct device *dev, void *res)
27+
+{
28+
+ thermal_zone_of_sensor_unregister(dev,
29+
+ *(struct thermal_zone_device **)res);
30+
+}
31+
+
32+
+static int devm_thermal_zone_of_sensor_match(struct device *dev, void *res,
33+
+ void *data)
34+
+{
35+
+ struct thermal_zone_device **r = res;
36+
+
37+
+ if (WARN_ON(!r || !*r))
38+
+ return 0;
39+
+
40+
+ return *r == data;
41+
+}
42+
+
43+
+/**
44+
+ * devm_thermal_zone_of_sensor_register - Resource managed version of
45+
+ * thermal_zone_of_sensor_register()
46+
+ * @dev: a valid struct device pointer of a sensor device. Must contain
47+
+ * a valid .of_node, for the sensor node.
48+
+ * @sensor_id: a sensor identifier, in case the sensor IP has more
49+
+ * than one sensors
50+
+ * @data: a private pointer (owned by the caller) that will be passed
51+
+ * back, when a temperature reading is needed.
52+
+ * @ops: struct thermal_zone_of_device_ops *. Must contain at least .get_temp.
53+
+ *
54+
+ * Refer thermal_zone_of_sensor_register() for more details.
55+
+ *
56+
+ * Return: On success returns a valid struct thermal_zone_device,
57+
+ * otherwise, it returns a corresponding ERR_PTR(). Caller must
58+
+ * check the return value with help of IS_ERR() helper.
59+
+ * Registered hermal_zone_device device will automatically be
60+
+ * released when device is unbounded.
61+
+ */
62+
+struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
63+
+ struct device *dev, int sensor_id,
64+
+ void *data, const struct thermal_zone_of_device_ops *ops)
65+
+{
66+
+ struct thermal_zone_device **ptr, *tzd;
67+
+
68+
+ ptr = devres_alloc(devm_thermal_zone_of_sensor_release, sizeof(*ptr),
69+
+ GFP_KERNEL);
70+
+ if (!ptr)
71+
+ return ERR_PTR(-ENOMEM);
72+
+
73+
+ tzd = thermal_zone_of_sensor_register(dev, sensor_id, data, ops);
74+
+ if (IS_ERR(tzd)) {
75+
+ devres_free(ptr);
76+
+ return tzd;
77+
+ }
78+
+
79+
+ *ptr = tzd;
80+
+ devres_add(dev, ptr);
81+
+
82+
+ return tzd;
83+
+}
84+
+EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_register);
85+
+
86+
+/**
87+
+ * devm_thermal_zone_of_sensor_unregister - Resource managed version of
88+
+ * thermal_zone_of_sensor_unregister().
89+
+ * @dev: Device for which which resource was allocated.
90+
+ * @tzd: a pointer to struct thermal_zone_device where the sensor is registered.
91+
+ *
92+
+ * This function removes the sensor callbacks and private data from the
93+
+ * thermal zone device registered with devm_thermal_zone_of_sensor_register()
94+
+ * API. It will also silent the zone by remove the .get_temp() and .get_trend()
95+
+ * thermal zone device callbacks.
96+
+ * Normally this function will not need to be called and the resource
97+
+ * management code will ensure that the resource is freed.
98+
+ */
99+
+void devm_thermal_zone_of_sensor_unregister(struct device *dev,
100+
+ struct thermal_zone_device *tzd)
101+
+{
102+
+ WARN_ON(devres_release(dev, devm_thermal_zone_of_sensor_release,
103+
+ devm_thermal_zone_of_sensor_match, tzd));
104+
+}
105+
+EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister);
106+
+
107+
/*** functions parsing device tree nodes ***/
108+
109+
/**
110+
--- a/include/linux/thermal.h
111+
+++ b/include/linux/thermal.h
112+
@@ -364,6 +364,11 @@ thermal_zone_of_sensor_register(struct d
113+
const struct thermal_zone_of_device_ops *ops);
114+
void thermal_zone_of_sensor_unregister(struct device *dev,
115+
struct thermal_zone_device *tz);
116+
+struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
117+
+ struct device *dev, int id, void *data,
118+
+ const struct thermal_zone_of_device_ops *ops);
119+
+void devm_thermal_zone_of_sensor_unregister(struct device *dev,
120+
+ struct thermal_zone_device *tz);
121+
#else
122+
static inline struct thermal_zone_device *
123+
thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
124+
@@ -378,6 +383,19 @@ void thermal_zone_of_sensor_unregister(s
125+
{
126+
}
127+
128+
+static inline struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
129+
+ struct device *dev, int id, void *data,
130+
+ const struct thermal_zone_of_device_ops *ops)
131+
+{
132+
+ return ERR_PTR(-ENODEV);
133+
+}
134+
+
135+
+static inline
136+
+void devm_thermal_zone_of_sensor_unregister(struct device *dev,
137+
+ struct thermal_zone_device *tz)
138+
+{
139+
+}
140+
+
141+
#endif
142+
143+
#if IS_ENABLED(CONFIG_THERMAL)
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
From 4a7069a32c99a81950de035535b0a064dcceaeba Mon Sep 17 00:00:00 2001
2+
From: Rajendra Nayak <[email protected]>
3+
Date: Thu, 5 May 2016 14:21:42 +0530
4+
Subject: [PATCH] thermal: core: export apis to get slope and offset
5+
6+
Add apis for platform thermal drivers to query for slope and offset
7+
attributes, which might be needed for temperature calculations.
8+
9+
Signed-off-by: Rajendra Nayak <[email protected]>
10+
Signed-off-by: Eduardo Valentin <[email protected]>
11+
Signed-off-by: Zhang Rui <[email protected]>
12+
---
13+
Documentation/thermal/sysfs-api.txt | 12 ++++++++++++
14+
drivers/thermal/thermal_core.c | 30 ++++++++++++++++++++++++++++++
15+
include/linux/thermal.h | 8 ++++++++
16+
3 files changed, 50 insertions(+)
17+
18+
--- a/Documentation/thermal/sysfs-api.txt
19+
+++ b/Documentation/thermal/sysfs-api.txt
20+
@@ -72,6 +72,18 @@ temperature) and throttle appropriate de
21+
It deletes the corresponding entry form /sys/class/thermal folder and
22+
unbind all the thermal cooling devices it uses.
23+
24+
+1.1.7 int thermal_zone_get_slope(struct thermal_zone_device *tz)
25+
+
26+
+ This interface is used to read the slope attribute value
27+
+ for the thermal zone device, which might be useful for platform
28+
+ drivers for temperature calculations.
29+
+
30+
+1.1.8 int thermal_zone_get_offset(struct thermal_zone_device *tz)
31+
+
32+
+ This interface is used to read the offset attribute value
33+
+ for the thermal zone device, which might be useful for platform
34+
+ drivers for temperature calculations.
35+
+
36+
1.2 thermal cooling device interface
37+
1.2.1 struct thermal_cooling_device *thermal_cooling_device_register(char *name,
38+
void *devdata, struct thermal_cooling_device_ops *)
39+
--- a/drivers/thermal/thermal_core.c
40+
+++ b/drivers/thermal/thermal_core.c
41+
@@ -2061,6 +2061,36 @@ exit:
42+
}
43+
EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
44+
45+
+/**
46+
+ * thermal_zone_get_slope - return the slope attribute of the thermal zone
47+
+ * @tz: thermal zone device with the slope attribute
48+
+ *
49+
+ * Return: If the thermal zone device has a slope attribute, return it, else
50+
+ * return 1.
51+
+ */
52+
+int thermal_zone_get_slope(struct thermal_zone_device *tz)
53+
+{
54+
+ if (tz && tz->tzp)
55+
+ return tz->tzp->slope;
56+
+ return 1;
57+
+}
58+
+EXPORT_SYMBOL_GPL(thermal_zone_get_slope);
59+
+
60+
+/**
61+
+ * thermal_zone_get_offset - return the offset attribute of the thermal zone
62+
+ * @tz: thermal zone device with the offset attribute
63+
+ *
64+
+ * Return: If the thermal zone device has a offset attribute, return it, else
65+
+ * return 0.
66+
+ */
67+
+int thermal_zone_get_offset(struct thermal_zone_device *tz)
68+
+{
69+
+ if (tz && tz->tzp)
70+
+ return tz->tzp->offset;
71+
+ return 0;
72+
+}
73+
+EXPORT_SYMBOL_GPL(thermal_zone_get_offset);
74+
+
75+
#ifdef CONFIG_NET
76+
static const struct genl_multicast_group thermal_event_mcgrps[] = {
77+
{ .name = THERMAL_GENL_MCAST_GROUP_NAME, },
78+
--- a/include/linux/thermal.h
79+
+++ b/include/linux/thermal.h
80+
@@ -432,6 +432,8 @@ thermal_of_cooling_device_register(struc
81+
void thermal_cooling_device_unregister(struct thermal_cooling_device *);
82+
struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
83+
int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
84+
+int thermal_zone_get_slope(struct thermal_zone_device *tz);
85+
+int thermal_zone_get_offset(struct thermal_zone_device *tz);
86+
87+
int get_tz_trend(struct thermal_zone_device *, int);
88+
struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
89+
@@ -489,6 +491,12 @@ static inline struct thermal_zone_device
90+
static inline int thermal_zone_get_temp(
91+
struct thermal_zone_device *tz, int *temp)
92+
{ return -ENODEV; }
93+
+static inline int thermal_zone_get_slope(
94+
+ struct thermal_zone_device *tz)
95+
+{ return -ENODEV; }
96+
+static inline int thermal_zone_get_offset(
97+
+ struct thermal_zone_device *tz)
98+
+{ return -ENODEV; }
99+
static inline int get_tz_trend(struct thermal_zone_device *tz, int trip)
100+
{ return -ENODEV; }
101+
static inline struct thermal_instance *

0 commit comments

Comments
 (0)