From: Todd Poynor <toddpoynor@google.com>
To: Keerthy <j-keerthy@ti.com>
Cc: linux-omap@vger.kernel.org, tony@atomide.com
Subject: Re: [RFC PATCH 5/6 V2] OMAP4: Temperature sensor device support
Date: Thu, 18 Aug 2011 22:47:05 -0700 [thread overview]
Message-ID: <20110819054705.GB2901@google.com> (raw)
In-Reply-To: <1313664735-8917-6-git-send-email-j-keerthy@ti.com>
On Thu, Aug 18, 2011 at 04:22:14PM +0530, Keerthy wrote:
...
> +int omap_temp_sensor_device_idle(struct omap_device *od)
> +{
> + struct omap_temp_sensor_registers *registers;
> + struct resource *mem;
> + void __iomem *phy_base;
> + unsigned long timeout;
> + u32 ret = 0, temp;
> +
> + mem = platform_get_resource(&od->pdev, IORESOURCE_MEM, 0);
> + if (!mem) {
> + dev_err(&od->pdev.dev, "no mem resource\n");
> + ret = -EINVAL;
> + goto plat_res_err;
> + }
> +
> + phy_base = ioremap(mem->start, resource_size(mem));
Check NULL return.
> +
> + if (!strcmp(od->hwmods[0]->dev_attr, "mpu"))
> + registers = &omap_mpu_temp_sensor_registers;
> +
> + temp = __raw_readl(phy_base + registers->temp_sensor_ctrl);
Compile warning on possible use of uninitialized value?
Suggest return error if string comparison (ugh) does not match.
> + temp |= registers->bgap_tempsoff_mask;
> +
> + /* BGAP_TEMPSOFF should be set to 1 before gating clock */
> + __raw_writel(temp, phy_base + registers->temp_sensor_ctrl);
> + temp = __raw_readl(phy_base + registers->bgap_status);
> + timeout = jiffies + msecs_to_jiffies(5);
> +
> + /* wait till the clean stop bit is set or till the timeout expires */
> + while (!(temp | registers->status_clean_stop_mask) &&
> + !(time_after(jiffies, timeout))) {
> + temp = __raw_readl(phy_base + registers->bgap_status);
> + usleep_range(500, 2000);
> + }
> +
> + if (time_after(jiffies, timeout))
> + dev_err(&od->pdev.dev, "Clean stop bit not set\n");
> +
> + ret = omap_device_idle_hwmods(od);
> +
> +plat_res_err:
> + return ret;
phy_base not saved anywhere, VM leak. Need iounmap(phy_base).
> +}
> +
> +int omap_temp_sensor_device_activate(struct omap_device *od)
> +{
> + struct omap_temp_sensor_registers *registers;
> + struct resource *mem;
> + void __iomem *phy_base;
> + u32 ret = 0, temp;
> +
> + ret = omap_device_enable_hwmods(od);
> + if (ret < 0)
> + return ret;
> + mem = platform_get_resource(&od->pdev, IORESOURCE_MEM, 0);
> + if (!mem) {
> + dev_err(&od->pdev.dev, "no mem resource\n");
> + return -EINVAL;
> + }
> +
> + phy_base = ioremap(mem->start, resource_size(mem));
Check NULL return.
> +
> + if (!strcmp(od->hwmods[0]->dev_attr, "mpu"))
> + registers = &omap_mpu_temp_sensor_registers;
> +
> + temp = __raw_readl(phy_base + registers->temp_sensor_ctrl);
Error out if not "mpu".
> + temp &= ~(registers->bgap_tempsoff_mask);
> + /* BGAP_TEMPSOFF should be reset to 0 */
> + __raw_writel(temp,
> + phy_base + registers->temp_sensor_ctrl);
> +
> + return 0;
iounmap(phy_base)
> +}
> +
> +static struct omap_device_pm_latency omap_temp_sensor_latency[] = {
> + {
> + .deactivate_func = omap_temp_sensor_device_idle,
> + .activate_func = omap_temp_sensor_device_activate,
> + .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
> + }
> +};
> +
> +static DEFINE_IDR(temp_sensor_device_idr);
> +
> +static int temp_sensor_dev_init(struct omap_hwmod *oh, void *user)
> +{
> + struct omap_temp_sensor_pdata *temp_sensor_pdata;
> + struct omap_device *od;
> + struct omap_temp_sensor_dev_attr *temp_sensor_dev_attr;
> + int ret = 0;
> + int num;
> + struct mutex sensor_mutex; /* sensor mutex */
> +
> + mutex_init(&sensor_mutex);
> +
> + temp_sensor_pdata =
> + kzalloc(sizeof(*temp_sensor_pdata), GFP_KERNEL);
> + if (!temp_sensor_pdata) {
> + dev_err(&oh->od->pdev.dev,
> + "Unable to allocate memory for temp sensor pdata\n");
> + return -ENOMEM;
> + }
> +
> + mutex_lock(&sensor_mutex);
Mutex just init'ed above, this code can't run concurrent with any
other accessors.
> + ret = idr_pre_get(&temp_sensor_device_idr, GFP_KERNEL);
> + if (ret < 0) {
> + mutex_unlock(&sensor_mutex);
> + goto fail_id;
> + }
> + ret = idr_get_new(&temp_sensor_device_idr, temp_sensor_pdata, &num);
> + if (ret < 0) {
> + mutex_unlock(&sensor_mutex);
> + goto fail_id;
> + }
> + mutex_unlock(&sensor_mutex);
> +
> + temp_sensor_dev_attr = oh->dev_attr;
> + if (!strcmp(temp_sensor_dev_attr->name, "mpu"))
> + temp_sensor_pdata->registers = &omap_mpu_temp_sensor_registers;
> +
> + od = omap_device_build("omap_temp_sensor", num,
> + oh, temp_sensor_pdata, sizeof(*temp_sensor_pdata),
> + omap_temp_sensor_latency,
> + ARRAY_SIZE(omap_temp_sensor_latency), 0);
Inconsistent tabbing.
> + if (IS_ERR(od)) {
> + dev_warn(&oh->od->pdev.dev,
> + "Could not build omap_device for %s\n", oh->name);
> + ret = PTR_ERR(od);
> + }
> +
> +fail_id:
> + kfree(temp_sensor_pdata);
> +
> + return ret;
> +}
Todd
next prev parent reply other threads:[~2011-08-19 5:47 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-18 10:52 [RFC PATCH 0/6 V2] OMAP4: Temperature sensor driver Keerthy
2011-08-18 10:52 ` [RFC PATCH 1/6 V2] OMAP4: Clock: Associate clocks for OMAP temperature sensor Keerthy
2011-08-29 21:47 ` Kevin Hilman
2011-08-18 10:52 ` [RFC PATCH 2/6 V2] OMAP4: Adding the temperature sensor register set bit fields Keerthy
2011-08-29 21:52 ` Kevin Hilman
2011-08-18 10:52 ` [RFC PATCH 3/6 V2] OMAP4460: Temperature sensor data Keerthy
2011-08-18 11:32 ` Felipe Balbi
2011-08-18 10:52 ` [RFC PATCH 4/6 V2] OMAP4: Hwmod: OMAP temperature sensor Keerthy
2011-08-18 10:52 ` [RFC PATCH 5/6 V2] OMAP4: Temperature sensor device support Keerthy
2011-08-19 5:47 ` Todd Poynor [this message]
2011-08-18 10:52 ` [RFC PATCH 6/6 V2] hwmon: OMAP4: On die temperature sensor driver Keerthy
2011-08-18 11:37 ` Felipe Balbi
2011-08-22 4:29 ` J, KEERTHY
2011-08-22 9:24 ` Felipe Balbi
2011-08-19 2:13 ` Guenter Roeck
2011-08-19 6:04 ` J, KEERTHY
2011-08-19 6:17 ` Guenter Roeck
2011-08-19 13:01 ` J, KEERTHY
2011-08-19 13:48 ` Guenter Roeck
2011-08-19 9:04 ` J, KEERTHY
2011-08-19 12:53 ` J, KEERTHY
2011-08-19 5:34 ` Todd Poynor
2011-08-22 4:40 ` J, KEERTHY
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=20110819054705.GB2901@google.com \
--to=toddpoynor@google.com \
--cc=j-keerthy@ti.com \
--cc=linux-omap@vger.kernel.org \
--cc=tony@atomide.com \
/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;
as well as URLs for NNTP newsgroup(s).