From: Jonathan Cameron <jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
To: samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org
Cc: alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org,
achew-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org,
ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
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-xJW1crHCIS+8kqYwC468Frtp2NbXvJi8gfoxzgwHRXE@public.gmane.org>
On 09/03/10 06:18, samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org wrote:
>
>
>> -----Original Message-----
>> From: linux-iio-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org [mailto:linux-iio-
>> owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org] On Behalf Of ext Alan Cox
>> Sent: 03 September, 2010 01:20
>> To: achew-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
>> Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-
>> i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org; khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org;
>> ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
>> 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
next prev parent reply other threads:[~2010-09-03 7:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-02 21:35 [PATCH 1/1] iio: ak8975: Add Ak8975 magnetometer sensor achew-DDmLM1+adcrQT0dZR+AlfA
[not found] ` <1283463351-15816-1-git-send-email-achew-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2010-09-02 22:19 ` Alan Cox
[not found] ` <20100902231942.21375cc0-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-09-02 22:16 ` Andrew Chew
2010-09-02 22:41 ` Alan Cox
2010-09-02 23:15 ` Jonathan Cameron
2010-09-03 5:18 ` samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w
[not found] ` <62697B07E9803846BC582181BD6FB6B82B9C057FFC-xJW1crHCIS+8kqYwC468Frtp2NbXvJi8gfoxzgwHRXE@public.gmane.org>
2010-09-03 7:23 ` Jonathan Cameron [this message]
[not found] ` <4C80A26F.6020408-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
2010-09-03 7:20 ` samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w
-- strict thread matches above, loose matches on Subject: below --
2010-09-02 23:40 achew-DDmLM1+adcrQT0dZR+AlfA
[not found] ` <1283470837-18210-1-git-send-email-achew-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2010-09-03 23:16 ` Andrew Morton
2010-09-04 16:38 ` Jonathan Cameron
2010-09-06 8:17 ` Datta, Shubhrajyoti
[not found] ` <0680EC522D0CC943BC586913CF3768C003C2018464-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2010-09-07 23:07 ` Andrew Chew
[not found] ` <643E69AA4436674C8F39DCC2C05F763816B85AD0A9-lR+7xdUAJVNDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
2010-09-08 10:05 ` Datta, Shubhrajyoti
[not found] ` <0680EC522D0CC943BC586913CF3768C003C2018BD4-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
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-kwpb1pkirijaa/9udqfwiw@public.gmane.org \
--cc=achew-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org \
--cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
--cc=ldewangan-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=samu.p.onkalo-xNZwKgViW5gAvxtiuMwx3w@public.gmane.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