From: Johan Hovold <jhovold@gmail.com>
To: Geon Si Jeong <gshark.jeong@gmail.com>
Cc: Richard Purdie <rpurdie@rpsys.net>,
Daniel Jeong <daniel.jeong@ti.com>,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Wolfram Sang <w.sang@pengutronix.de>
Subject: Re: [PATCH 1/1 v1] leds: Add LED driver for lm3556 chip
Date: Tue, 15 May 2012 20:43:30 +0200 [thread overview]
Message-ID: <20120515184330.GB5654@localhost> (raw)
In-Reply-To: <1333936855-8807-2-git-send-email-gshark.jeong@gmail.com>
On Mon, Apr 09, 2012 at 11:00:55AM +0900, Geon Si Jeong wrote:
> It is a simple driver for LM3556 Chip(Texas Instruments)
> LM3556 :
> The LM3556 is a 4 MHz fixed-frequency synchronous boost
> converter plus 1.5A constant current driver for a high-current white LED.
> Datasheet: www.national.com/ds/LM/LM3556.pdf
>
> Tested on OMAP4430
>
> Signed-off-by: Geon Si Jeong <gshark.jeong@gmail.com>
[...]
> +/* i2c access*/
> +static int lm3556_read_reg(struct i2c_client *client, u8 reg, u8 * val)
> +{
> + int ret;
> +
> + ret = i2c_smbus_read_byte_data(client, reg);
> + if (ret < 0) {
> + dev_err(&client->dev, "i2c reading fail at 0x%02x error %d\n",
> + reg, ret);
> + return ret;
> + }
> + *val = ret & 0xff;
> + return ret;
> +}
> +
> +static int lm3556_write_reg(struct i2c_client *client, u8 reg, u8 val)
> +{
> + int ret = 0;
> +
> + ret = i2c_smbus_write_byte_data(client, reg, val);
> +
> + if (ret < 0)
> + dev_err(&client->dev, "i2c writting fail at 0x%02x\n", reg);
> + return ret;
> +}
> +
> +static int lm3556_write_bits(struct i2c_client *client,
> + u8 reg, u8 val, u8 mask, u8 shift)
> +{
> + int ret;
> + u8 reg_val;
> + struct lm3556_chip_data *chip = i2c_get_clientdata(client);
> +
> + mutex_lock(&chip->lock);
> + ret = lm3556_read_reg(client, reg, ®_val);
> + if (ret < 0)
> + goto out;
> + reg_val &= (~(mask << shift));
> + reg_val |= ((val & mask) << shift);
> + ret = lm3556_write_reg(client, reg, reg_val);
> +out:
> + mutex_unlock(&chip->lock);
> + return ret;
> +}
The register io-locking above is broken. You need to protect both
write_reg and write_bits using the mutex (but you must restructure
your code because write_bits currently calls write_reg). This is
required to avoid register corruption due to concurrent write_reg and
write_bits.
As has been suggested elsewhere, you could consider using regmap.
Thanks,
Johan
next prev parent reply other threads:[~2012-05-15 18:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-09 2:00 [PATCH 0/1 v1] leds: Add LED driver for lm3556 chip Geon Si Jeong
2012-04-09 2:00 ` [PATCH 1/1 " Geon Si Jeong
2012-05-15 18:43 ` Johan Hovold [this message]
2012-05-22 10:48 ` Johan Hovold
2012-05-22 10:58 ` Jeong, Daniel
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=20120515184330.GB5654@localhost \
--to=jhovold@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=daniel.jeong@ti.com \
--cc=gshark.jeong@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rpurdie@rpsys.net \
--cc=w.sang@pengutronix.de \
/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