From: Mark Rutland <mark.rutland@arm.com>
To: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
Cc: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"rob.herring@calxeda.com" <rob.herring@calxeda.com>,
Pawel Moll <Pawel.Moll@arm.com>,
"swarren@wwwdotorg.org" <swarren@wwwdotorg.org>,
"ian.campbell@citrix.com" <ian.campbell@citrix.com>,
"rob@landley.net" <rob@landley.net>,
"jic23@cam.ac.uk" <jic23@cam.ac.uk>,
"denis.ciocca@st.com" <denis.ciocca@st.com>,
"srinivas.pandruvada@linux.intel.com"
<srinivas.pandruvada@linux.intel.com>,
"lars@metafoo.de" <lars@metafoo.de>
Subject: Re: [PATCH v2] iio: add Bosch BMA180 acceleration sensor driver
Date: Tue, 13 Aug 2013 14:47:45 +0100 [thread overview]
Message-ID: <20130813134745.GP27165@e106331-lin.cambridge.arm.com> (raw)
In-Reply-To: <1376384956-16720-1-git-send-email-o.v.kravchenko@globallogic.com>
On Tue, Aug 13, 2013 at 10:09:16AM +0100, Oleksandr Kravchenko wrote:
> This patch adds IIO driver for Bosch BMA180 triaxial
> acceleration sensor.
> http://omapworld.com/BMA180_111_1002839.pdf
>
> Signed-off-by: Oleksandr Kravchenko <o.v.kravchenko@globallogic.com>
> ---
> .../devicetree/bindings/iio/accel/bma180.txt | 35 ++
> drivers/iio/accel/Kconfig | 12 +
> drivers/iio/accel/Makefile | 2 +
> drivers/iio/accel/bma180.c | 635 ++++++++++++++++++++
> 4 files changed, 684 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/iio/accel/bma180.txt
> create mode 100644 drivers/iio/accel/bma180.c
>
> diff --git a/Documentation/devicetree/bindings/iio/accel/bma180.txt b/Documentation/devicetree/bindings/iio/accel/bma180.txt
> new file mode 100644
> index 0000000..e08780b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/accel/bma180.txt
> @@ -0,0 +1,35 @@
> +* Bosch BMA180 triaxial acceleration sensor
> +
> +http://omapworld.com/BMA180_111_1002839.pdf
> +
> +Required properties:
> +
> + - compatible : should be "bosch,bma180"
> + - reg : the I2C address of the sensor
> +
> +Optional properties:
> +
> + - interrupt-parent : should be the phandle for the interrupt controller
> +
> + - interrupts : interrupt mapping for GPIO IRQ, it should by configured with
> + flags IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING
> +
> + - bosch,resolution : ADC resolution. Must be 130, 190, 250, 380, 500,
> + 990 or 1980 mcg/LSB only
> +
> + - bosch,bandwidth : select bandwidth frequency. Must be 10, 20, 40, 75,
> + 150 or 300 Hz only
> +
> + - bosch,mode : 0 - select low noise mode, 1 - select low power mode
>From the looks of the code, those last three properties seem to get
programmed into the device, have default values, and look far more like
configuration rather than hardware description.
I don't think these need to be in the dt -- you can set sane defaults
and then have something under sysfs to change them dynamically later if
necessary.
> +
> +Example:
> +
> +bma180@40 {
> + compatible = "bosch,bma180";
> + reg = <0x40>;
> + interrupt-parent = <&gpio6>;
> + interrupts = <18 (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_EDGE_RISING)>;
> + bosch,bandwidth = <300>;
> + bosch,resolution = <250>;
> + bosch,mode = <0>;
> +};
[...]
> +static int bma180_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct bma180_data *data;
> + struct iio_dev *indio_dev;
> + struct iio_trigger *trig;
> + struct device_node *np = client->dev.of_node;
> + int ret;
> +
> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + data = iio_priv(indio_dev);
> + i2c_set_clientdata(client, indio_dev);
> + data->client = client;
> +
> + if (of_property_read_u32(np, "bosch,bandwidth", &data->bw))
> + data->bw = BMA180_DEF_BW;
> + if (of_property_read_u32(np, "bosch,resolution", &data->scale))
> + data->scale = BMA180_DEF_SCALE;
> + of_property_read_u32(np, "bosch,mode", &data->mode);
What if bosch,mode isn't decribed? It looks like it'll have an
uninitialised value.
> +
> + ret = bma180_chip_init(data);
> + if (ret < 0)
> + goto err_1;
> +
> + mutex_init(&data->mutex);
> +
> + indio_dev->dev.parent = &client->dev;
> + indio_dev->channels = bma180_channels;
> + indio_dev->num_channels = ARRAY_SIZE(bma180_channels);
> + indio_dev->name = BMA180_DRV_NAME;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->info = &bma180_info;
> +
> + trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, indio_dev->id);
> + if (!trig) {
> + ret = -ENOMEM;
> + goto err_1;
> + }
> +
> + ret = devm_request_irq(&client->dev, client->irq,
> + iio_trigger_generic_data_rdy_poll,
> + IRQF_TRIGGER_RISING, BMA180_IRQ_NAME, trig);
> + if (ret) {
> + dev_err(&client->dev, "unable to request IRQ\n");
> + goto err_2;
> + }
> +
> + trig->dev.parent = &client->dev;
> + trig->ops = &bma180_trigger_ops;
> + iio_trigger_set_drvdata(trig, indio_dev);
> + data->trig = trig;
> + indio_dev->trig = trig;
> +
> + ret = iio_trigger_register(trig);
> + if (ret)
> + goto err_2;
> +
> + ret = iio_triggered_buffer_setup(indio_dev, NULL,
> + bma180_trigger_handler, NULL);
> + if (ret < 0) {
> + dev_err(&client->dev, "unable to setup iio triggered buffer\n");
> + goto err_3;
> + }
> +
> + ret = iio_device_register(indio_dev);
> + if (ret < 0) {
> + dev_err(&client->dev, "unable to register iio device\n");
> + goto err_4;
> + }
> +
> + return 0;
> +
> +err_4:
> + iio_triggered_buffer_cleanup(indio_dev);
> +err_3:
> + iio_trigger_unregister(trig);
> +err_2:
> + iio_trigger_free(trig);
> +err_1:
> + bma180_chip_disable(data);
It would be nice to have (slightly) clearer labels here, e.g.
err_chip, err_trigger.
Thanks,
Mark.
prev parent reply other threads:[~2013-08-13 13:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-13 9:09 [PATCH v2] iio: add Bosch BMA180 acceleration sensor driver Oleksandr Kravchenko
2013-08-13 13:47 ` Mark Rutland [this message]
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=20130813134745.GP27165@e106331-lin.cambridge.arm.com \
--to=mark.rutland@arm.com \
--cc=Pawel.Moll@arm.com \
--cc=denis.ciocca@st.com \
--cc=devicetree@vger.kernel.org \
--cc=ian.campbell@citrix.com \
--cc=jic23@cam.ac.uk \
--cc=lars@metafoo.de \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=o.v.kravchenko@globallogic.com \
--cc=rob.herring@calxeda.com \
--cc=rob@landley.net \
--cc=srinivas.pandruvada@linux.intel.com \
--cc=swarren@wwwdotorg.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;
as well as URLs for NNTP newsgroup(s).