Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1350244 > unrolled thread
| Started by | Laxman Dewangan <ldewangan@nvidia.com> |
|---|---|
| First post | 2016-03-04 15:00 +0100 |
| Last post | 2016-03-09 13:30 +0100 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 0/3] thermal: add devm_ version of thermal_zone register and driver for max77620 Laxman Dewangan <ldewangan@nvidia.com> - 2016-03-04 15:00 +0100
[PATCH 1/3] thermal: of-thermal: Add devm version of thermal_zone_of_sensor_register Laxman Dewangan <ldewangan@nvidia.com> - 2016-03-04 15:00 +0100
Re: [PATCH 1/3] thermal: of-thermal: Add devm version of thermal_zone_of_sensor_register Eduardo Valentin <edubezval@gmail.com> - 2016-03-08 22:40 +0100
Re: [PATCH 1/3] thermal: of-thermal: Add devm version of thermal_zone_of_sensor_register Laxman Dewangan <ldewangan@nvidia.com> - 2016-03-09 13:30 +0100
| From | Laxman Dewangan <ldewangan@nvidia.com> |
|---|---|
| Date | 2016-03-04 15:00 +0100 |
| Subject | [PATCH 0/3] thermal: add devm_ version of thermal_zone register and driver for max77620 |
| Message-ID | <r8YqS-7AF-5@gated-at.bofh.it> |
The series add the devm_ version of thermal_zone_of_sensor_register/unregister
and use this in new thermal driver for max77620.
The header file for max77620 is part of MFD patch
https://lkml.org/lkml/2016/2/11/186
Laxman Dewangan (3):
thermal: of-thermal: Add devm version of
thermal_zone_of_sensor_register
thermal: Add devm_thermal_zone_of_sensor_register() in managed devices
list
thermal: max77620: Add thermal driver for reporting junction temp
Documentation/driver-model/devres.txt | 4 +
drivers/thermal/Kconfig | 9 ++
drivers/thermal/Makefile | 1 +
drivers/thermal/of-thermal.c | 81 ++++++++++++++++++
drivers/thermal/thermal-max77620.c | 151 ++++++++++++++++++++++++++++++++++
include/linux/thermal.h | 18 ++++
6 files changed, 264 insertions(+)
create mode 100644 drivers/thermal/thermal-max77620.c
--
2.1.4
[toc] | [next] | [standalone]
| From | Laxman Dewangan <ldewangan@nvidia.com> |
|---|---|
| Date | 2016-03-04 15:00 +0100 |
| Subject | [PATCH 1/3] thermal: of-thermal: Add devm version of thermal_zone_of_sensor_register |
| Message-ID | <r8YqT-7AF-19@gated-at.bofh.it> |
| In reply to | #1350244 |
Add resource managed version of thermal_zone_of_sensor_register() and
thermal_zone_of_sensor_unregister().
This helps in reducing the code size in error path, remove of
driver remove callbacks and making proper sequence for deallocations.
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
---
drivers/thermal/of-thermal.c | 81 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/thermal.h | 18 ++++++++++
2 files changed, 99 insertions(+)
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 9043f8f..1d9f8dc 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -555,6 +555,87 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
}
EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister);
+static void devm_thermal_zone_of_sensor_release(struct device *dev, void *res)
+{
+ thermal_zone_of_sensor_unregister(dev,
+ *(struct thermal_zone_device **)res);
+}
+
+static int devm_thermal_zone_of_sensor_match(struct device *dev, void *res,
+ void *data)
+{
+ struct thermal_zone_device **r = res;
+
+ if (WARN_ON(!r || !*r))
+ return 0;
+
+ return *r == data;
+}
+
+/**
+ * devm_thermal_zone_of_sensor_register - Resource managed version of
+ * thermal_zone_of_sensor_register()
+ * @dev: a valid struct device pointer of a sensor device. Must contain
+ * a valid .of_node, for the sensor node.
+ * @sensor_id: a sensor identifier, in case the sensor IP has more
+ * than one sensors
+ * @data: a private pointer (owned by the caller) that will be passed
+ * back, when a temperature reading is needed.
+ * @ops: struct thermal_zone_of_device_ops *. Must contain at least .get_temp.
+ *
+ * Refer thermal_zone_of_sensor_register() for more details.
+ *
+ * Return: On success returns a valid struct thermal_zone_device,
+ * otherwise, it returns a corresponding ERR_PTR(). Caller must
+ * check the return value with help of IS_ERR() helper.
+ * Registered hermal_zone_device device will automatically be
+ * released when device is unbounded.
+ */
+struct thermal_zone_device *
+devm_thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
+ void *data, const struct thermal_zone_of_device_ops *ops)
+{
+ struct thermal_zone_device **ptr, *tzd;
+
+ ptr = devres_alloc(devm_thermal_zone_of_sensor_release, sizeof(*ptr),
+ GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ tzd = thermal_zone_of_sensor_register(dev, sensor_id, data, ops);
+ if (IS_ERR(tzd)) {
+ devres_free(ptr);
+ return tzd;
+ }
+
+ *ptr = tzd;
+ devres_add(dev, ptr);
+
+ return tzd;
+}
+EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_register);
+
+/**
+ * devm_thermal_zone_of_sensor_unregister - Resource managed version of
+ * thermal_zone_of_sensor_unregister().
+ * @dev: Device for which which resource was allocated.
+ * @tzd: a pointer to struct thermal_zone_device where the sensor is registered.
+ *
+ * This function removes the sensor callbacks and private data from the
+ * thermal zone device registered with devm_thermal_zone_of_sensor_register()
+ * API. It will also silent the zone by remove the .get_temp() and .get_trend()
+ * thermal zone device callbacks.
+ * Normally this function will not need to be called and the resource
+ * management code will ensure that the resource is freed.
+ */
+void devm_thermal_zone_of_sensor_unregister(struct device *dev,
+ struct thermal_zone_device *tzd)
+{
+ WARN_ON(devres_release(dev, devm_thermal_zone_of_sensor_release,
+ devm_thermal_zone_of_sensor_match, tzd));
+}
+EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister);
+
/*** functions parsing device tree nodes ***/
/**
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index e13a1ac..4c43b21 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -362,6 +362,11 @@ thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
const struct thermal_zone_of_device_ops *ops);
void thermal_zone_of_sensor_unregister(struct device *dev,
struct thermal_zone_device *tz);
+struct thermal_zone_device *
+devm_thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
+ const struct thermal_zone_of_device_ops *ops);
+void devm_thermal_zone_of_sensor_unregister(struct device *dev,
+ struct thermal_zone_device *tz);
#else
static inline struct thermal_zone_device *
thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
@@ -376,6 +381,19 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
{
}
+static inline struct thermal_zone_device *
+devm_thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
+ const struct thermal_zone_of_device_ops *ops)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline
+void devm_thermal_zone_of_sensor_unregister(struct device *dev,
+ struct thermal_zone_device *tz)
+{
+}
+
#endif
#if IS_ENABLED(CONFIG_THERMAL)
--
2.1.4
[toc] | [prev] | [next] | [standalone]
| From | Eduardo Valentin <edubezval@gmail.com> |
|---|---|
| Date | 2016-03-08 22:40 +0100 |
| Subject | Re: [PATCH 1/3] thermal: of-thermal: Add devm version of thermal_zone_of_sensor_register |
| Message-ID | <raxwd-6Ct-5@gated-at.bofh.it> |
| In reply to | #1350247 |
Hello Laxman,
Minor as follows.
Can you please run ./scripts/checkpatch.pl --strict on this and remove
the warnings, errors, checks?
On Fri, Mar 04, 2016 at 07:10:08PM +0530, Laxman Dewangan wrote:
> Add resource managed version of thermal_zone_of_sensor_register() and
> thermal_zone_of_sensor_unregister().
>
> This helps in reducing the code size in error path, remove of
> driver remove callbacks and making proper sequence for deallocations.
>
> Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
> ---
> drivers/thermal/of-thermal.c | 81 ++++++++++++++++++++++++++++++++++++++++++++
> include/linux/thermal.h | 18 ++++++++++
Could you also please document these under
Documentation/thermal/sysfs-api.txt?
> 2 files changed, 99 insertions(+)
>
> diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
> index 9043f8f..1d9f8dc 100644
> --- a/drivers/thermal/of-thermal.c
> +++ b/drivers/thermal/of-thermal.c
> @@ -555,6 +555,87 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
> }
> EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister);
>
> +static void devm_thermal_zone_of_sensor_release(struct device *dev, void *res)
> +{
> + thermal_zone_of_sensor_unregister(dev,
> + *(struct thermal_zone_device **)res);
> +}
> +
> +static int devm_thermal_zone_of_sensor_match(struct device *dev, void *res,
> + void *data)
> +{
> + struct thermal_zone_device **r = res;
> +
> + if (WARN_ON(!r || !*r))
> + return 0;
> +
> + return *r == data;
> +}
> +
> +/**
> + * devm_thermal_zone_of_sensor_register - Resource managed version of
> + * thermal_zone_of_sensor_register()
> + * @dev: a valid struct device pointer of a sensor device. Must contain
> + * a valid .of_node, for the sensor node.
> + * @sensor_id: a sensor identifier, in case the sensor IP has more
> + * than one sensors
> + * @data: a private pointer (owned by the caller) that will be passed
> + * back, when a temperature reading is needed.
> + * @ops: struct thermal_zone_of_device_ops *. Must contain at least .get_temp.
> + *
> + * Refer thermal_zone_of_sensor_register() for more details.
> + *
> + * Return: On success returns a valid struct thermal_zone_device,
> + * otherwise, it returns a corresponding ERR_PTR(). Caller must
> + * check the return value with help of IS_ERR() helper.
> + * Registered hermal_zone_device device will automatically be
> + * released when device is unbounded.
> + */
> +struct thermal_zone_device *
> +devm_thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
> + void *data, const struct thermal_zone_of_device_ops *ops)
> +{
> + struct thermal_zone_device **ptr, *tzd;
> +
> + ptr = devres_alloc(devm_thermal_zone_of_sensor_release, sizeof(*ptr),
> + GFP_KERNEL);
> + if (!ptr)
> + return ERR_PTR(-ENOMEM);
> +
> + tzd = thermal_zone_of_sensor_register(dev, sensor_id, data, ops);
> + if (IS_ERR(tzd)) {
> + devres_free(ptr);
> + return tzd;
> + }
> +
> + *ptr = tzd;
> + devres_add(dev, ptr);
> +
> + return tzd;
> +}
> +EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_register);
> +
> +/**
> + * devm_thermal_zone_of_sensor_unregister - Resource managed version of
> + * thermal_zone_of_sensor_unregister().
> + * @dev: Device for which which resource was allocated.
> + * @tzd: a pointer to struct thermal_zone_device where the sensor is registered.
> + *
> + * This function removes the sensor callbacks and private data from the
> + * thermal zone device registered with devm_thermal_zone_of_sensor_register()
> + * API. It will also silent the zone by remove the .get_temp() and .get_trend()
> + * thermal zone device callbacks.
> + * Normally this function will not need to be called and the resource
> + * management code will ensure that the resource is freed.
> + */
> +void devm_thermal_zone_of_sensor_unregister(struct device *dev,
> + struct thermal_zone_device *tzd)
> +{
> + WARN_ON(devres_release(dev, devm_thermal_zone_of_sensor_release,
> + devm_thermal_zone_of_sensor_match, tzd));
> +}
> +EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister);
> +
> /*** functions parsing device tree nodes ***/
>
> /**
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index e13a1ac..4c43b21 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -362,6 +362,11 @@ thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
> const struct thermal_zone_of_device_ops *ops);
> void thermal_zone_of_sensor_unregister(struct device *dev,
> struct thermal_zone_device *tz);
> +struct thermal_zone_device *
> +devm_thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
> + const struct thermal_zone_of_device_ops *ops);
> +void devm_thermal_zone_of_sensor_unregister(struct device *dev,
> + struct thermal_zone_device *tz);
> #else
> static inline struct thermal_zone_device *
> thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
> @@ -376,6 +381,19 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
> {
> }
>
> +static inline struct thermal_zone_device *
> +devm_thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
> + const struct thermal_zone_of_device_ops *ops)
> +{
> + return ERR_PTR(-ENODEV);
> +}
> +
> +static inline
> +void devm_thermal_zone_of_sensor_unregister(struct device *dev,
> + struct thermal_zone_device *tz)
> +{
> +}
> +
> #endif
>
> #if IS_ENABLED(CONFIG_THERMAL)
> --
> 2.1.4
>
[toc] | [prev] | [next] | [standalone]
| From | Laxman Dewangan <ldewangan@nvidia.com> |
|---|---|
| Date | 2016-03-09 13:30 +0100 |
| Subject | Re: [PATCH 1/3] thermal: of-thermal: Add devm version of thermal_zone_of_sensor_register |
| Message-ID | <raLpw-7PW-23@gated-at.bofh.it> |
| In reply to | #1353426 |
Hi Edurado, Thanks for review. On Wednesday 09 March 2016 02:59 AM, Eduardo Valentin wrote: > Hello Laxman, > > > Minor as follows. > > Can you please run ./scripts/checkpatch.pl --strict on this and remove > the warnings, errors, checks? Taken from existing function and so borrowed the error. Will fix in next revision. > > On Fri, Mar 04, 2016 at 07:10:08PM +0530, Laxman Dewangan wrote: >> Add resource managed version of thermal_zone_of_sensor_register() and >> thermal_zone_of_sensor_unregister(). >> >> This helps in reducing the code size in error path, remove of >> driver remove callbacks and making proper sequence for deallocations. >> >> Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> >> --- >> drivers/thermal/of-thermal.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/thermal.h | 18 ++++++++++ > Could you also please document these under > Documentation/thermal/sysfs-api.txt? > > Sure, I saw that thermal_zone_of_sensor_register/unregister is also not documented. So I will add the details for this first and then add for newly added interfaces. Will take care in next series.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web