public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Lars Poeschel <larsi@wh2.tu-dresden.de>
Cc: sameo@linux.intel.com, linux-kernel@vger.kernel.org,
	jic23@cam.ac.uk, khali@linux-fr.org, ben-linux@fluff.org,
	w.sang@pengutronix.de, grant.likely@secretlab.ca,
	linus.walleij@linaro.org, Lars Poeschel <poeschel@lemonage.de>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>
Subject: Re: [PATCH v2 4/4] iio: adc: add viperboard adc driver
Date: Mon, 15 Oct 2012 16:26:36 +0200	[thread overview]
Message-ID: <507C1D1C.2030607@metafoo.de> (raw)
In-Reply-To: <1350052469-27802-4-git-send-email-larsi@wh2.tu-dresden.de>

Added linux-iio@vger.kernel.org to Cc.

On 10/12/2012 04:34 PM, Lars Poeschel wrote:
> From: Lars Poeschel <poeschel@lemonage.de>
> 
> This adds the mfd cell to use the adc part of the Nano River Technologies
> viperboard.
> 
> Signed-off-by: Lars Poeschel <poeschel@lemonage.de>

Looks good in general, just some minor code style issues.

> ---
>  drivers/iio/adc/Kconfig          |    7 ++
>  drivers/iio/adc/Makefile         |    1 +
>  drivers/iio/adc/viperboard_adc.c |  185 ++++++++++++++++++++++++++++++++++++++
>  drivers/mfd/viperboard.c         |    3 +
>  4 files changed, 196 insertions(+)
>  create mode 100644 drivers/iio/adc/viperboard_adc.c
> 
[...]
> diff --git a/drivers/iio/adc/viperboard_adc.c b/drivers/iio/adc/viperboard_adc.c
> new file mode 100644
> index 0000000..8ae6634
> --- /dev/null
> +++ b/drivers/iio/adc/viperboard_adc.c
> @@ -0,0 +1,185 @@
> +/*
> + *  Nano River Technologies viperboard iio ADC driver
> + *
> + *  (C) 2012 by Lemonage GmbH
> + *  Author: Lars Poeschel <poeschel@lemonage.de>
> + *  All rights reserved.
> + *
> + *  This program is free software; you can redistribute  it and/or modify it
> + *  under  the terms of  the GNU General  Public License as published by the
> + *  Free Software Foundation;  either version 2 of the	License, or (at your
> + *  option) any later version.
> + *
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/types.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +
> +#include <linux/usb.h>
> +#include <linux/iio/iio.h>
> +
> +#include <linux/mfd/viperboard.h>
> +
> +#define VPRBRD_ADC_CMD_GET		0x00
> +
> +struct __packed vprbrd_adc_msg {
> +	u8 cmd;
> +	u8 chan;
> +	u8 val;
> +};

put the __packed between } and ;

> +
> +struct vprbrd_adc {
> +	struct vprbrd *vb;
> +};
> +
> +#define VPRBRD_ADC_CHANNEL(_index) {			\
> +	.type = IIO_VOLTAGE,				\
> +	.indexed = 1,					\
> +	.channel = _index,				\
> +	.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT,	\

It would be good if you could also report the channel scale.

> +	.scan_index = _index,				\
> +	.scan_type.sign = 'u',				\
> +	.scan_type.realbits = 8,			\
> +	.scan_type.storagebits = 8,			\

Usually this is written as
	.scan_type = {
		.sign = 'u',
		....
	},

> +}
> +
> +static struct iio_chan_spec vprbrd_adc_iio_channels[] = {
const

> +	VPRBRD_ADC_CHANNEL(0),
> +	VPRBRD_ADC_CHANNEL(1),
> +	VPRBRD_ADC_CHANNEL(2),
> +	VPRBRD_ADC_CHANNEL(3),
> +};
> +
> +static int vprbrd_iio_read_raw(struct iio_dev *iio_dev,
> +				struct iio_chan_spec const *chan,
> +				int *val,
> +				int *val2,
> +				long mask)

'mask' used to be a mask and that's why it is still called 'mask' in older
drivers. For new drivers we should use 'info'.

> +{
> +	int ret, error = 0;
> +	struct vprbrd_adc *adc = iio_priv(iio_dev);
> +	struct vprbrd *vb = adc->vb;
> +	struct vprbrd_adc_msg *admsg = (struct vprbrd_adc_msg *)vb->buf;
> +
> +	if (mask == IIO_CHAN_INFO_RAW) {
> +

Use switch instead of if. Otherwise you'd end up with if(mask == ...) else
if(mask == ...) else if (mask == ...) if you add support for more channel
attributes.

> +		mutex_lock(&vb->lock);
> +
> +		admsg->cmd = VPRBRD_ADC_CMD_GET;
> +		admsg->chan = chan->scan_index;
> +		admsg->val = 0x00;
> +
> +		ret = usb_control_msg(vb->usb_dev,
> +			usb_sndctrlpipe(vb->usb_dev, 0), 0xec, 0x40,
> +			0x0000, 0x0000, admsg,
> +			sizeof(struct vprbrd_adc_msg), 100);
> +		if (ret != sizeof(struct vprbrd_adc_msg)) {
> +			dev_err(&iio_dev->dev, "usb send error on adc read\n");
> +			error = -EREMOTEIO;
> +		}

Does it make sense to send out the second msg if the first one failed?

> +
> +		ret = usb_control_msg(vb->usb_dev,
> +			usb_rcvctrlpipe(vb->usb_dev, 0), 0xec, 0xc0,
> +			0x0000, 0x0000, admsg,
> +			sizeof(struct vprbrd_adc_msg), 100);
> +

It would be good to have some defines for the magic constants used for
request and request_type.

> +		*val = admsg->val;
> +
> +		mutex_unlock(&vb->lock);
> +
> +		if (ret != sizeof(struct vprbrd_adc_msg)) {
> +			dev_err(&iio_dev->dev, "usb recv error on adc read\n");
> +			error = -EREMOTEIO;
> +		}
> +
> +		if (error)
> +			goto error;
> +
> +		return IIO_VAL_INT;
> +	}
> +	error =  -EINVAL;
> +error:
> +	return error;
> +}
> +
> +static const struct iio_info vprbrd_adc_iio_info = {
> +	.read_raw = &vprbrd_iio_read_raw,
> +	.driver_module = THIS_MODULE,
> +};
> +
> +static int __devinit vprbrd_adc_probe(struct platform_device *pdev)
> +{
> +	struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent);
> +	struct vprbrd_adc *adc;
> +	struct iio_dev *iodev;

Usually this is called indio_dev, would be good for consistency if you'd do
this as well.

> +	int ret;
> +
> +	/* registering iio */
> +	iodev = iio_device_alloc(sizeof(struct vprbrd_adc));
> +	if (!iodev) {
> +		dev_err(&pdev->dev, "failed allocating iio device\n");
> +		return -ENOMEM;
> +	}
> +
> +	adc = iio_priv(iodev);
> +	adc->vb = vb;
> +	iodev->name = "viperboard adc";
> +	iodev->dev.parent = &pdev->dev;
> +	iodev->info = &vprbrd_adc_iio_info;
> +	iodev->modes = INDIO_DIRECT_MODE;
> +	iodev->channels = vprbrd_adc_iio_channels;
> +	iodev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
> +
> +	ret = iio_device_register(iodev);
> +	if (ret) {
> +		dev_err(&pdev->dev, "could not register iio (adc)");
> +		goto error;
> +	}
> +
> +	platform_set_drvdata(pdev, iodev);
> +
> +	return 0;
> +
> +error:
> +	iio_device_free(iodev);
> +	return ret;
> +}
> +
> +static int __devexit vprbrd_adc_remove(struct platform_device *pdev)
> +{
> +	struct iio_dev *iodev = platform_get_drvdata(pdev);
> +
> +	iio_device_unregister(iodev);
> +	iio_device_free(iodev);
> +
> +	return 0;
> +}
> +
> +static struct platform_driver vprbrd_adc_driver = {
> +	.driver.name	= "viperboard-adc",
> +	.driver.owner	= THIS_MODULE,

Same as with scan_type, usually this is written as

.driver = {
	.name = ...
	....
},

> +	.probe		= vprbrd_adc_probe,
> +	.remove		= __devexit_p(vprbrd_adc_remove),
> +};
> +
> +static int __init vprbrd_adc_init(void)
> +{
> +	return platform_driver_register(&vprbrd_adc_driver);
> +}
> +subsys_initcall(vprbrd_adc_init);
> +
> +static void __exit vprbrd_adc_exit(void)
> +{
> +	platform_driver_unregister(&vprbrd_adc_driver);
> +}
> +module_exit(vprbrd_adc_exit);

module_platform_driver(vprbrd_adc_driver);

> +
> +MODULE_AUTHOR("Lars Poeschel <poeschel@lemonage.de>");
> +MODULE_DESCRIPTION("IIO ADC driver for Nano River Techs Viperboard");
> +MODULE_LICENSE("GPL");
> +MODULE_ALIAS("platform:viperboard-adc");
> diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
> index a25e07e..eb1cf89 100644
> --- a/drivers/mfd/viperboard.c
> +++ b/drivers/mfd/viperboard.c
> @@ -55,6 +55,9 @@ static struct mfd_cell vprbrd_devs[] = {
>  	{
>  		.name = "viperboard-i2c",
>  	},
> +	{
> +		.name = "viperboard-adc",
> +	},
>  };
>  
>  static int vprbrd_probe(struct usb_interface *interface,


  reply	other threads:[~2012-10-15 14:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-27 13:08 [PATCH] mfd: viperboard driver added larsi
2012-09-19 15:29 ` Samuel Ortiz
2012-09-24 16:46   ` Lars Poeschel
2012-09-25  8:55     ` Samuel Ortiz
2012-09-28 13:59       ` Lars Poeschel
2012-10-12 14:34       ` [PATCH v2 1/4] mfd: add viperboard driver Lars Poeschel
2012-10-12 14:34         ` [PATCH v2 2/4] gpio: add viperboard gpio driver Lars Poeschel
2012-10-15 13:00           ` Linus Walleij
2012-10-16  6:51             ` Lars Poeschel
2012-10-16 10:00               ` Linus Walleij
2012-10-16 13:38                 ` Lars Poeschel
2012-10-16 17:11                   ` Linus Walleij
2012-10-23 15:24                     ` Lars Poeschel
2012-10-24  7:53                       ` Linus Walleij
2012-10-24 16:31                         ` Mark Brown
2012-10-25 10:02                           ` Lars Poeschel
2012-10-25 14:00                             ` Mark Brown
2012-10-25 16:02                               ` Lars Poeschel
2012-10-25 16:06                                 ` Mark Brown
2012-10-26  9:16                                   ` Lars Poeschel
2012-10-27 16:14                                     ` Linus Walleij
2012-10-27 21:35                                       ` Mark Brown
2012-10-12 14:34         ` [PATCH v2 3/4] i2c: add viperboard i2c master driver Lars Poeschel
2012-10-12 14:34         ` [PATCH v2 4/4] iio: adc: add viperboard adc driver Lars Poeschel
2012-10-15 14:26           ` Lars-Peter Clausen [this message]
2012-10-16  7:11             ` Lars Poeschel
2012-10-15 17:09         ` [PATCH v2 1/4] mfd: add viperboard driver Peter Meerwald
2012-10-16  7:15           ` Lars Poeschel
2012-10-16  8:40         ` Lars-Peter Clausen
2012-10-16  9:43           ` Lars Poeschel
2012-10-16 10:58             ` Lars-Peter Clausen
2012-10-18  7:29               ` Lars Poeschel
2012-10-18 14:13                 ` Lars-Peter Clausen

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=507C1D1C.2030607@metafoo.de \
    --to=lars@metafoo.de \
    --cc=ben-linux@fluff.org \
    --cc=grant.likely@secretlab.ca \
    --cc=jic23@cam.ac.uk \
    --cc=khali@linux-fr.org \
    --cc=larsi@wh2.tu-dresden.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=poeschel@lemonage.de \
    --cc=sameo@linux.intel.com \
    --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