Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: samu.p.onkalo@nokia.com
Cc: alan@lxorguk.ukuu.org.uk, achew@nvidia.com,
	linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	linux-i2c@vger.kernel.org, akpm@linux-foundation.org,
	khali@linux-fr.org, ldewangan@nvidia.com
Subject: Re: [PATCH 1/1] iio: ak8975: Add Ak8975 magnetometer sensor
Date: Fri, 03 Sep 2010 08:23:27 +0100	[thread overview]
Message-ID: <4C80A26F.6020408@cam.ac.uk> (raw)
In-Reply-To: <62697B07E9803846BC582181BD6FB6B82B9C057FFC@NOK-EUMSG-02.mgdnok.nokia.com>

On 09/03/10 06:18, samu.p.onkalo@nokia.com wrote:
> 
> 
>> -----Original Message-----
>> From: linux-iio-owner@vger.kernel.org [mailto:linux-iio-
>> owner@vger.kernel.org] On Behalf Of ext Alan Cox
>> Sent: 03 September, 2010 01:20
>> To: achew@nvidia.com
>> Cc: linux-kernel@vger.kernel.org; linux-iio@vger.kernel.org; linux-
>> i2c@vger.kernel.org; akpm@linux-foundation.org; khali@linux-fr.org;
>> ldewangan@nvidia.com
>> Subject: Re: [PATCH 1/1] iio: ak8975: Add Ak8975 magnetometer sensor
>>
>>> +/*
>>> + * Shows the device's mode.  0 = off, 1 = on.
>>> + */
>>
>> Should this not be handled by runtime pm nowdays ?
>>
>>> +	if ((oval < 0) || (oval > 1)) {
>>> +		dev_err(dev, "mode value is not supported\n");
>>> +		return -EINVAL;
>>> +	}
>>
>> ulong cannot be < 0 and doesn't need all the brackets
>>
>>
>>> +	/* Wait for the conversion to complete. */
>>> +	while (timeout_ms) {
>>> +		msleep(AK8975_CONVERSION_DONE_POLL_TIME);
>>> +		state = (gpio_get_value(data->eoc_gpio) ? 1 : 0);
>>> +		if (state)
>>> +			break;
>>> +		timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
>>> +	}
>>
>> This makes some fairly specific wiring assumptions about how the ak8975
>> is configured. I'm looking at the ak8974 driver in our tree and also
>> wondering if they can be combined sanely.
> 
> With ak8974 chip, it is possible to have similar functionality without interrupt
> pin. This is most probably true also for ak8975 chip. It is not good to assume
> that everyone uses interrupt pin if the same functionally can be achieved
> another way. I mean polling via I2C instead of checking GPIO state after the
> sleep. 
Of course this can be done, but it's up to Andrew to decide whether he wants to.
I think the usual principal of writing only what people currently need applies
here.  Perhaps a comment in the code to point out this could be done is a sensible
compromise?  
> 
> Based on the this driver it seems that ak8974 and ak8975 are quite similar, but
> also there are many differences like different register map. Maybe combining
> these two makes implementation just messy.
> 
> 
>>
>>> +	status = ak8975_read_data(client, AK8975_REG_ST1, 1,
>> &read_status);
>>> +	if (!status) {
>>> +		dev_err(&client->dev, "Error in reading ST1\n");
>>> +		return false;
>>
>> I would have expected these to return a meaningful error code not 0 ?
>>
>>> +static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, show_mode,
>> store_mode, 0);
>>> +static IIO_DEVICE_ATTR(magn_x_calibscale, S_IRUGO, show_calibscale,
>> NULL, 0);
>>> +static IIO_DEVICE_ATTR(magn_y_calibscale, S_IRUGO, show_calibscale,
>> NULL, 1);
>>> +static IIO_DEVICE_ATTR(magn_z_calibscale, S_IRUGO, show_calibscale,
>> NULL, 2);
>>> +static IIO_DEV_ATTR_MAGN_X(show_raw, AK8975_REG_HXL);
>>> +static IIO_DEV_ATTR_MAGN_Y(show_raw, AK8975_REG_HYL);
>>> +static IIO_DEV_ATTR_MAGN_Z(show_raw, AK8975_REG_HZL);
>>
>> This seems odd as an interface as it's raw when the maths to provide
>> non-raw (and thus abstract and easy for user space) data is trivial
>> enough to do in kernel
>>
>> (but then I still suspect it should jusst be an input device of course)
>>
>>> +static int ak8975_probe(struct i2c_client *client,
>>> +			const struct i2c_device_id *id)
>>> +{
>>> +	struct ak8975_data *data;
>>> +	int err;
>>> +
>>> +	/* Allocate our device context. */
>>> +	data = kzalloc(sizeof(struct ak8975_data), GFP_KERNEL);
>>> +	if (!data) {
>>> +		dev_err(&client->dev, "Memory allocation fails\n");
>>> +		err = -ENOMEM;
>>> +		goto exit;
>>> +	}
>>> +
>>> +	i2c_set_clientdata(client, data);
>>> +	data->client = client;
>>> +
>>> +	mutex_init(&data->lock);
>>> +
>>> +	/* Grab and set up the supplied GPIO. */
>>> +	data->eoc_irq = client->irq;
>>> +	data->eoc_gpio = irq_to_gpio(client->irq);
>>
>> It may not be via a GPIO. Better to do the GPIO handling in platform
>> abstraction or accept passing IRQ and no GPIO value to mean "just use
>> the
>> IRQ". Ie do all the gpio foo if (data->eoc_gpio) { ... }
>>
>>
>>> +
>>> +	err = gpio_request(data->eoc_gpio, "ak_8975");
>>> +	if (err < 0) {
>>> +		dev_err(&client->dev, "failed to request GPIO %d, error
>> %d\n",
>>> +			data->eoc_gpio, err);
>>> +		goto exit_free;
>>> +	}
>>> +
>>> +	err = gpio_direction_input(data->eoc_gpio);
>>> +	if (err < 0) {
>>> +		dev_err(&client->dev, "Failed to configure input direction
>> for"
>>> +			" GPIO %d, error %d\n", data->eoc_gpio, err);
>>> +		gpio_free(data->eoc_gpio);
>>
>> This frees the GPIO twice ?
>>
>> Looks basically sound to me.
>>
>> Alan

  reply	other threads:[~2010-09-03  7:18 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-02 21:35 [PATCH 1/1] iio: ak8975: Add Ak8975 magnetometer sensor achew
2010-09-02 22:19 ` Alan Cox
2010-09-02 22:16   ` Andrew Chew
2010-09-02 22:41     ` Alan Cox
2010-09-02 23:15       ` Jonathan Cameron
2010-09-02 23:57         ` Andrew Chew
2010-09-03  7:19           ` Jonathan Cameron
2010-09-03 20:03             ` Andrew Chew
2010-09-04 16:07               ` Jonathan Cameron
2010-09-03  5:18   ` samu.p.onkalo
2010-09-03  7:23     ` Jonathan Cameron [this message]
2010-09-03  7:20       ` samu.p.onkalo
  -- strict thread matches above, loose matches on Subject: below --
2010-09-02 23:40 achew
2010-09-03 23:16 ` Andrew Morton
2010-09-04 16:38 ` Jonathan Cameron
2010-09-06  8:17 ` Datta, Shubhrajyoti
2010-09-07 23:07   ` Andrew Chew
2010-09-08 10:05     ` Datta, Shubhrajyoti
2010-09-08 15:34       ` Murphy, Dan

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=4C80A26F.6020408@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --cc=achew@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=khali@linux-fr.org \
    --cc=ldewangan@nvidia.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samu.p.onkalo@nokia.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