From: Ryan Mallon <rmallon@gmail.com>
To: Jenny TC <jenny.tc@intel.com>
Cc: cbouatmailru@gmail.com, anton.vorontsov@linaro.org,
linux-kernel@vger.kernel.org, durgadoss.r@intel.com
Subject: Re: [PATCH] power_supply: Register battery as a thermal zone
Date: Wed, 09 May 2012 16:16:01 +1000 [thread overview]
Message-ID: <4FAA0BA1.5080004@gmail.com> (raw)
In-Reply-To: <1336562318-16096-1-git-send-email-jenny.tc@intel.com>
On 09/05/12 21:18, Jenny TC wrote:
> Battery and charger contribute to Thermals in most of the embedded
> devices. So, it makes sense to identify them as Thermal zones in a
> particular platform.
>
> This patch registers a thermal zone if the power supply is reporting
> a temperature property. The thermal zone will be used by platform's
> thermal management solution.
>
> Signed-off-by: Jenny TC <jenny.tc@intel.com>
> ---
> +#ifdef CONFIG_THERMAL
> +static int power_supply_read_temp(struct thermal_zone_device *tzd,
> + unsigned long *temp)
> +{
> + struct power_supply *psy;
> + union power_supply_propval val;
> + int ret;
> +
> + WARN_ON(tzd == NULL);
> + psy = tzd->devdata;
> + WARN_ON(psy == NULL);
These WARN_ONs seem unnecessary since you will oops if either of them
are NULL anyway.
> + ret = psy->get_property(psy,
> + POWER_SUPPLY_PROP_TEMP, &val);
> + if (!ret)
> + *temp = val.intval * 100;
> + return ret;
> +}
<snip>
> int power_supply_register(struct device *parent, struct power_supply *psy)
> {
> struct device *dev;
> int rc;
> +#ifdef CONFIG_THERMAL
> + int i;
> +#endif
>
> dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> if (!dev)
> @@ -196,7 +223,21 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
> rc = device_add(dev);
> if (rc)
> goto device_add_failed;
> -
> +#ifdef CONFIG_THERMAL
> + /* Register battery zone device psy reports temperature */
> + for (i = 0; i < psy->num_properties; i++) {
> + if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) {
> + psy->tzd = thermal_zone_device_register(
> + (char *)psy->name, 0, psy,
> + &psy_tzd_ops, 0, 0, 0, 0);
> + if (IS_ERR(psy->tzd)) {
> + rc = PTR_ERR(psy->tzd);
> + goto therm_zone_reg_failed;
> + }
> + break;
> + }
> + }
> +#endif
This would be better moved into its own function, so you can minimise
the amount of ifdefs needed. Having extra ifdefs for variable
declarations and exit paths is especially ugly :-/. Ideally you can have
a single #ifdef CONFIG_THERMAL block, and define empty functions for the
!CONFIG_THERMAL case.
~Ryan
next prev parent reply other threads:[~2012-05-09 6:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-09 11:18 [PATCH] power_supply: Register battery as a thermal zone Jenny TC
2012-05-09 6:16 ` Ryan Mallon [this message]
2012-05-09 9:33 ` Tc, Jenny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FAA0BA1.5080004@gmail.com \
--to=rmallon@gmail.com \
--cc=anton.vorontsov@linaro.org \
--cc=cbouatmailru@gmail.com \
--cc=durgadoss.r@intel.com \
--cc=jenny.tc@intel.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox