public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Samuel Ortiz <sameo@linux.intel.com>
To: Jin Park <jinyoungp@nvidia.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] aat2870: Adding backlight, regulator and mfd driver
Date: Mon, 20 Jun 2011 12:29:34 +0200	[thread overview]
Message-ID: <20110620102934.GE22420@sortiz-mobl> (raw)
In-Reply-To: <1306743452-26386-2-git-send-email-jinyoungp@nvidia.com>

Hi Jin,

On Mon, May 30, 2011 at 05:17:32PM +0900, Jin Park wrote:
> Adding backlight, regulator and mfd driver for AnalogicTech AAT2870.
Before reviewing this patch, could you please do the following:

1) Split it into 3 actual patches: the MFD one, the regulator one and the
backlight one.
2) Add the relevant maintainers (See MAINTAINERS) if you want to get a proper
regulator and backlight driver review.

Now, some MFD specific comments:

> +static int aat2870_read(struct aat2870_data *aat2870, u8 addr, u8 *val)
> +{
> +	struct i2c_client *client = aat2870->client;
> +	int ret = 0;
> +
> +	if (addr >= AAT2870_REG_NUM) {
> +		dev_err(aat2870->dev, "Invalid address, 0x%02x\n", addr);
> +		return -EINVAL;
> +	}
> +
> +	mutex_lock(&aat2870->io_lock);
> +
> +	if (!aat2870->reg_cache[addr].readable) {
> +		*val = aat2870->reg_cache[addr].value;
> +		goto out_unlock;
> +	}
> +
> +	ret = i2c_master_send(client, &addr, 1);
> +	if (ret < 0)
> +		goto out_unlock;
> +	if (ret != 1) {
> +		ret = -EIO;
> +		goto out_unlock;
> +	}
> +
> +	ret = i2c_master_recv(client, val, 1);
> +	if (ret < 0)
> +		goto out_unlock;
> +	if (ret != 1) {
> +		ret = -EIO;
> +		goto out_unlock;
> +	}
> +
> +	ret = 0;
> +
> +out_unlock:
> +	mutex_unlock(&aat2870->io_lock);
> +	dev_dbg(&client->dev, "read: addr=0x%02x, val=0x%02x\n", addr, *val);
> +
> +	return ret;
> +}
> +
> +static int aat2870_write(struct aat2870_data *aat2870, u8 addr, u8 val)
> +{
> +	struct i2c_client *client = aat2870->client;
> +	u8 msg[2];
> +	int ret = 0;
> +
> +	if (addr >= AAT2870_REG_NUM) {
> +		dev_err(aat2870->dev, "Invalid address, 0x%02x\n", addr);
> +		return -EINVAL;
> +	}
> +
> +	if (!aat2870->reg_cache[addr].writeable) {
> +		dev_err(aat2870->dev, "Address 0x%02x is not writeable\n",
> +			addr);
> +		return -EINVAL;
> +	}
> +
> +	mutex_lock(&aat2870->io_lock);
> +
> +	msg[0] = addr;
> +	msg[1] = val;
> +	ret = i2c_master_send(client, msg, 2);
> +	if (ret < 0)
> +		goto out_unlock;
> +	if (ret != 2) {
> +		ret = -EIO;
> +		goto out_unlock;
> +	}
> +
> +	aat2870->reg_cache[addr].value = val;
> +	ret = 0;
> +
> +out_unlock:
> +	mutex_unlock(&aat2870->io_lock);
> +	dev_dbg(&client->dev, "write: addr=0x%02x, val=0x%02x\n", addr, val);
> +
> +	return ret;
> +}
> +
> +static int aat2870_update_bits(struct aat2870_data *aat2870, u8 addr,
> +			       u8 mask, u8 val)
> +{
> +	int change;
> +	u8 old_val, new_val;
> +	int ret;
> +
> +	ret = aat2870->read(aat2870, addr, &old_val);
> +	if (ret)
> +		return ret;
> +
> +	new_val = (old_val & ~mask) | val;
> +	change = old_val != new_val;
> +	if (change)
> +		ret = aat2870->write(aat2870, addr, new_val);
> +
> +	dev_dbg(&aat2870->client->dev,
> +		"update_bits: change=%d, addr=0x%02x, old=0x%02x, new=0x%02x\n",
> +		change, addr, old_val, new_val);
> +
> +	return ret;
> +}
You also need to take the io_lock mutex here, to prevent someone else to write
a different value to your register between your read and write.
So what you typically want is an unlocked version of aat2870_[read|write]
(let's say we call it __aat2870_[read|write]). Then your aat2870_[read|write]
become wrappers around the __aat2870_[read|write] with the lock taken. And
your update_bits routine can use __aat2870_[read|write] with the lock taken
from the beginning.

The rest looks pretty fine to me.

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/

  parent reply	other threads:[~2011-06-20 10:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-30  8:17 [PATCH 0/1] Submitting aat2870 driver Jin Park
2011-05-30  8:17 ` [PATCH 1/1] aat2870: Adding backlight, regulator and mfd driver Jin Park
2011-05-30  9:09   ` Joe Perches
2011-06-20 10:29   ` Samuel Ortiz [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-05-31  4:26 Jin Park
2011-05-31  6:30 ` Joe Perches
2011-05-31  6:46 Jin Park

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=20110620102934.GE22420@sortiz-mobl \
    --to=sameo@linux.intel.com \
    --cc=jinyoungp@nvidia.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