Skip to contentSkip to conversation

mfd: set device type of mfd platform devices to a mfd type

PATCH In review Lars Poeschel 7 participants 12 messages Nov 5, 2012 – Nov 20, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/5 mfd: set device type of mfd platform devices to a mfd type

From: Lars Poeschel <[email protected]>

This sets the type of the platform devices that are added to the mfd core to some mfd-cell type. This enables us to add mfd cells to platform devices, that are in use by other cores (e.g. the usb core).
Otherwise by removing the mfd cell from a platform device that already has some "childs" would remove all childs, not only the mfd ones.
Thanks to Lars-Peter Clausen for proposing this.

---
 drivers/mfd/mfd-core.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/mfd/mfd-core.c +13 -2
index f8b7771..d317b50 100644
@@ -21,6 +21,10 @@
 #include <linux/irqdomain.h>
 #include <linux/of.h>
 
+static struct device_type const mfd_device_type = {
+	.name = "mfd-cell",
+};
+
 int mfd_cell_enable(struct platform_device *pdev)
 {
 	const struct mfd_cell *cell = mfd_get_cell(pdev);
@@ -91,6 +95,7 @@ static int mfd_add_device(struct device *parent, int id,
 		goto fail_device;
 
 	pdev->dev.parent = parent;
+	pdev->dev.type = &mfd_device_type;
 
 	if (parent->of_node && cell->of_compatible) {
 		for_each_child_of_node(parent->of_node, np) {
@@ -204,10 +209,16 @@ EXPORT_SYMBOL(mfd_add_devices);
 
 static int mfd_remove_devices_fn(struct device *dev, void *c)
 {
-	struct platform_device *pdev = to_platform_device(dev);
-	const struct mfd_cell *cell = mfd_get_cell(pdev);
+	struct platform_device *pdev;
+	const struct mfd_cell *cell;
 	atomic_t **usage_count = c;
 
+	if (dev->type != &mfd_device_type)
+		return 0;
+
+	pdev = to_platform_device(dev);
+	cell = mfd_get_cell(pdev);
+
 	/* find the base address of usage_count pointers (for freeing) */
 	if (!*usage_count || (cell->usage_count < *usage_count))
 		*usage_count = cell->usage_count;
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 2/5 mfd: add viperboard driver

From: Lars Poeschel <[email protected]>

Add mfd driver for Nano River Technologies viperboard.

---
 drivers/mfd/Kconfig            |   14 +++++
 drivers/mfd/Makefile           |    1 +
 drivers/mfd/viperboard.c       |  130 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/viperboard.h |  105 ++++++++++++++++++++++++++++++++
 4 files changed, 250 insertions(+)
 create mode 100644 drivers/mfd/viperboard.c
 create mode 100644 include/linux/mfd/viperboard.h
drivers/mfd/Kconfig +14 -0
index acab3ef..0c2e6bb 100644
@@ -1044,6 +1044,20 @@ config MFD_PALMAS
 	  If you say yes here you get support for the Palmas
 	  series of PMIC chips from Texas Instruments.
 
+config MFD_VIPERBOARD
+        tristate "Support for Nano River Technologies Viperboard"
+	select MFD_CORE
+	depends on USB
+	default n
+	help
+	  Say yes here if you want support for Nano River Technologies
+	  Viperboard.
+	  There are mfd cell drivers available for i2c master, adc and
+	  both gpios found on the board. The spi part does not yet
+	  have a driver.
+	  You need to select the mfd cell drivers separately.
+	  The drivers do not support all features the board exposes.
+
 endmenu
 endif
 
drivers/mfd/Makefile +1 -0
index d8ccb63..eb85ab2 100644
@@ -134,6 +134,7 @@ obj-$(CONFIG_MFD_TPS65090)	+= tps65090.o
 obj-$(CONFIG_MFD_AAT2870_CORE)	+= aat2870-core.o
 obj-$(CONFIG_MFD_INTEL_MSIC)	+= intel_msic.o
 obj-$(CONFIG_MFD_PALMAS)	+= palmas.o
+obj-$(CONFIG_MFD_VIPERBOARD)    += viperboard.o
 obj-$(CONFIG_MFD_RC5T583)	+= rc5t583.o rc5t583-irq.o
 obj-$(CONFIG_MFD_SEC_CORE)	+= sec-core.o sec-irq.o
 obj-$(CONFIG_MFD_SYSCON)	+= syscon.o
drivers/mfd/viperboard.c new file +130 -0

130 lines not on this page · raw message

include/linux/mfd/viperboard.h new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH v3 2/5] mfd: add viperboard driver

Hi Lars,

Quoted 5 lines · Lars Poeschel

From: Lars Poeschel <[email protected]>

Add mfd driver for Nano River Technologies viperboard.

Quoted 8 lines
---
 drivers/mfd/Kconfig            |   14 +++++
 drivers/mfd/Makefile           |    1 +
 drivers/mfd/viperboard.c       |  130 ++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/viperboard.h |  105 ++++++++++++++++++++++++++++++++
 4 files changed, 250 insertions(+)
 create mode 100644 drivers/mfd/viperboard.c
 create mode 100644 include/linux/mfd/viperboard.h

This looks way better than your initial submission.
Patches 2,3,4 and 5 all applied. I would really appreciate to get an ACK from the i2c folks for patch #4.
I received a similar patch from Charles Keepax for patch 1, and I applied the above 4 patches on top of it.

Cheers,
Samuel.

Signature · 2 lines
Intel Open Source Technology Centre
http://oss.intel.com/
#3 lore raw

Re: [PATCH v3 2/5] mfd: add viperboard driver

Quoted 3 lines

Patches 2,3,4 and 5 all applied. I would really appreciate to get an ACK from the i2c folks for patch #4.

I'll try to have a look this week. It fell a bit off because linux-i2c was not in CC. I do wonder about the naming, though. VIPERBOARD is probably the board name, but not the IP core/SoC name?

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#4 lore raw

Re: [PATCH v3 2/5] mfd: add viperboard driver

Quoted 3 lines · Wolfram Sang

I'll try to have a look this week. It fell a bit off because linux-i2c was not in CC. I do wonder about the naming, though. VIPERBOARD is probably the board name, but not the IP core/SoC name?

I am sorry, that I forgot the CC.
You are right it is the board name but not a IP/SoC name. It seems this device is weird to kernel developers - you are not the first one asking. You don't have to see the term board as in kernel sense where it describes a specific SoC and the components connected to it. It is a circuit board, that connects to usb on one side and GPIO, I²C and so on on the other side. You can have a look at it here:
http://nanorivertech.com/viperboard-specs.html

#5 lore raw

PATCH v3 3/5 gpio: add viperboard gpio driver

In reply to Lars Poeschel

From: Lars Poeschel <[email protected]>

This adds the mfd cell to use the gpio a and gpio b part of the Nano River Technologies viperboard.

---
 drivers/gpio/Kconfig           |   13 +
 drivers/gpio/Makefile          |    1 +
 drivers/gpio/gpio-viperboard.c |  517 ++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/viperboard.c       |    3 +
 include/linux/mfd/viperboard.h |    2 +
 5 files changed, 536 insertions(+)
 create mode 100644 drivers/gpio/gpio-viperboard.c
drivers/gpio/Kconfig +13 -0
index d055cee..c3bbd08 100644
@@ -649,4 +649,17 @@ config GPIO_MSIC
 	  Enable support for GPIO on intel MSIC controllers found in
 	  intel MID devices
 
+comment "USB GPIO expanders:"
+
+config GPIO_VIPERBOARD
+	tristate "Viperboard GPIO a & b support"
+	depends on MFD_VIPERBOARD && USB
+	help
+	  Say yes here to access the GPIO signals of Nano River
+	  Technologies Viperboard. There are two GPIO chips on the
+	  board: gpioa and gpiob.
+          See viperboard API specification and Nano
+          River Tech's viperboard.h for detailed meaning
+          of the module parameters.
+
 endif
drivers/gpio/Makefile +1 -0
index 9aeed67..16a1385 100644
@@ -71,6 +71,7 @@ obj-$(CONFIG_GPIO_TPS65912)	+= gpio-tps65912.o
 obj-$(CONFIG_GPIO_TWL4030)	+= gpio-twl4030.o
 obj-$(CONFIG_GPIO_TWL6040)	+= gpio-twl6040.o
 obj-$(CONFIG_GPIO_UCB1400)	+= gpio-ucb1400.o
+obj-$(CONFIG_GPIO_VIPERBOARD)	+= gpio-viperboard.o
 obj-$(CONFIG_GPIO_VR41XX)	+= gpio-vr41xx.o
 obj-$(CONFIG_GPIO_VT8500)	+= gpio-vt8500.o
 obj-$(CONFIG_GPIO_VX855)	+= gpio-vx855.o
drivers/gpio/gpio-viperboard.c new file +517 -0

517 lines not on this page · raw message

drivers/mfd/viperboard.c +3 -0
index 34bc372..4b2ffbf 100644
@@ -38,6 +38,9 @@ static const struct usb_device_id vprbrd_table[] = {
 MODULE_DEVICE_TABLE(usb, vprbrd_table);
 
 static struct mfd_cell vprbrd_devs[] = {
+	{
+		.name = "viperboard-gpio",
+	},
 };
 
 static int vprbrd_probe(struct usb_interface *interface,
include/linux/mfd/viperboard.h +2 -0
index 0d13424..42d339f 100644
@@ -44,6 +44,8 @@
 #define VPRBRD_USB_TIMEOUT_MS       100
 #define VPRBRD_USB_REQUEST_MAJOR    0xea
 #define VPRBRD_USB_REQUEST_MINOR    0xeb
+#define VPRBRD_USB_REQUEST_GPIOA    0xed
+#define VPRBRD_USB_REQUEST_GPIOB    0xdd
 
 struct vprbrd_i2c_write_hdr {
 	u8 cmd;
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH v3 4/5 i2c: add viperboard i2c master driver

In reply to Lars Poeschel

From: Lars Poeschel <[email protected]>

This adds the mfd cell to use the i2c part of the Nano River Technologies viperboard as i2c master.

---
 drivers/i2c/busses/Kconfig          |   10 +
 drivers/i2c/busses/Makefile         |    1 +
 drivers/i2c/busses/i2c-viperboard.c |  476 +++++++++++++++++++++++++++++++++++
 drivers/mfd/viperboard.c            |    3 +
 include/linux/mfd/viperboard.h      |    2 +
 5 files changed, 492 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-viperboard.c
drivers/i2c/busses/Kconfig +10 -0
index 65dd599..405a0fb 100644
@@ -819,6 +819,16 @@ config I2C_TINY_USB
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-tiny-usb.
 
+config I2C_VIPERBOARD
+	tristate "Viperboard I2C master support"
+	depends on MFD_VIPERBOARD && USB
+	help
+	  Say yes here to access the I2C part of the Nano River
+	  Technologies Viperboard as I2C master.
+          See viperboard API specification and Nano
+          River Tech's viperboard.h for detailed meaning
+          of the module parameters.
+
 comment "Other I2C/SMBus bus drivers"
 
 config I2C_ACORN
drivers/i2c/busses/Makefile +1 -0
index 2d33d62..7e8befd 100644
@@ -79,6 +79,7 @@ obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
 obj-$(CONFIG_I2C_PARPORT_LIGHT)	+= i2c-parport-light.o
 obj-$(CONFIG_I2C_TAOS_EVM)	+= i2c-taos-evm.o
 obj-$(CONFIG_I2C_TINY_USB)	+= i2c-tiny-usb.o
+obj-$(CONFIG_I2C_VIPERBOARD)	+= i2c-viperboard.o
 
 # Other I2C/SMBus bus drivers
 obj-$(CONFIG_I2C_ACORN)		+= i2c-acorn.o
drivers/i2c/busses/i2c-viperboard.c new file +476 -0

476 lines not on this page · raw message

drivers/mfd/viperboard.c +3 -0
index 4b2ffbf..a7b5b34 100644
@@ -41,6 +41,9 @@ static struct mfd_cell vprbrd_devs[] = {
 	{
 		.name = "viperboard-gpio",
 	},
+	{
+		.name = "viperboard-i2c",
+	},
 };
 
 static int vprbrd_probe(struct usb_interface *interface,
include/linux/mfd/viperboard.h +2 -0
index 42d339f..ef78514 100644
@@ -42,6 +42,8 @@
 #define VPRBRD_USB_TYPE_OUT	    0x40
 #define VPRBRD_USB_TYPE_IN	    0xc0
 #define VPRBRD_USB_TIMEOUT_MS       100
+#define VPRBRD_USB_REQUEST_I2C_FREQ 0xe6
+#define VPRBRD_USB_REQUEST_I2C      0xe9
 #define VPRBRD_USB_REQUEST_MAJOR    0xea
 #define VPRBRD_USB_REQUEST_MINOR    0xeb
 #define VPRBRD_USB_REQUEST_GPIOA    0xed
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH v4 4/5 i2c: add viperboard i2c master driver

As I got no feedback on the previous patch yet, I answer myself upcounting the patch version. I had to change the setting of the bus frequency as there was no usb capable memory used in patch v3
-- >8 --

Quoted 1 line

From 7a0759ee25a19f7f623543f491be5dee83f195a7 Mon Sep 17 00:00:00 2001

From: Lars Poeschel <[email protected]>
Date: Fri, 12 Oct 2012 14:12:23 +0200
Subject: [PATCH v4 4/5] i2c: add viperboard i2c master driver

This adds the mfd cell to use the i2c part of the Nano River Technologies viperboard as i2c master.

---
 drivers/i2c/busses/Kconfig          |   10 +
 drivers/i2c/busses/Makefile         |    1 +
 drivers/i2c/busses/i2c-viperboard.c |  480 +++++++++++++++++++++++++++++++++++
 drivers/mfd/viperboard.c            |    3 +
 include/linux/mfd/viperboard.h      |    2 +
 5 files changed, 496 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-viperboard.c
drivers/i2c/busses/Kconfig +10 -0
index 65dd599..405a0fb 100644
@@ -819,6 +819,16 @@ config I2C_TINY_USB
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-tiny-usb.
 
+config I2C_VIPERBOARD
+	tristate "Viperboard I2C master support"
+	depends on MFD_VIPERBOARD && USB
+	help
+	  Say yes here to access the I2C part of the Nano River
+	  Technologies Viperboard as I2C master.
+          See viperboard API specification and Nano
+          River Tech's viperboard.h for detailed meaning
+          of the module parameters.
+
 comment "Other I2C/SMBus bus drivers"
 
 config I2C_ACORN
drivers/i2c/busses/Makefile +1 -0
index 2d33d62..7e8befd 100644
@@ -79,6 +79,7 @@ obj-$(CONFIG_I2C_PARPORT)	+= i2c-parport.o
 obj-$(CONFIG_I2C_PARPORT_LIGHT)	+= i2c-parport-light.o
 obj-$(CONFIG_I2C_TAOS_EVM)	+= i2c-taos-evm.o
 obj-$(CONFIG_I2C_TINY_USB)	+= i2c-tiny-usb.o
+obj-$(CONFIG_I2C_VIPERBOARD)	+= i2c-viperboard.o
 
 # Other I2C/SMBus bus drivers
 obj-$(CONFIG_I2C_ACORN)		+= i2c-acorn.o
drivers/i2c/busses/i2c-viperboard.c new file +480 -0

480 lines not on this page · raw message

drivers/mfd/viperboard.c +3 -0
index 4b2ffbf..a7b5b34 100644
@@ -41,6 +41,9 @@ static struct mfd_cell vprbrd_devs[] = {
 	{
 		.name = "viperboard-gpio",
 	},
+	{
+		.name = "viperboard-i2c",
+	},
 };
 
 static int vprbrd_probe(struct usb_interface *interface,
include/linux/mfd/viperboard.h +2 -0
index 42d339f..ef78514 100644
@@ -42,6 +42,8 @@
 #define VPRBRD_USB_TYPE_OUT	    0x40
 #define VPRBRD_USB_TYPE_IN	    0xc0
 #define VPRBRD_USB_TIMEOUT_MS       100
+#define VPRBRD_USB_REQUEST_I2C_FREQ 0xe6
+#define VPRBRD_USB_REQUEST_I2C      0xe9
 #define VPRBRD_USB_REQUEST_MAJOR    0xea
 #define VPRBRD_USB_REQUEST_MINOR    0xeb
 #define VPRBRD_USB_REQUEST_GPIOA    0xed
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH v3 5/5 iio: adc: add viperboard adc driver

In reply to Lars Poeschel

From: Lars Poeschel <[email protected]>

This adds the mfd cell to use the adc part of the Nano River Technologies viperboard.

---
 drivers/iio/adc/Kconfig          |    7 ++
 drivers/iio/adc/Makefile         |    1 +
 drivers/iio/adc/viperboard_adc.c |  181 ++++++++++++++++++++++++++++++++++++++
 drivers/mfd/viperboard.c         |    3 +
 include/linux/mfd/viperboard.h   |    1 +
 5 files changed, 193 insertions(+)
 create mode 100644 drivers/iio/adc/viperboard_adc.c
drivers/iio/adc/Kconfig +7 -0
index 4927581..35ad77d 100644
@@ -60,4 +60,11 @@ config LP8788_ADC
 	help
 	  Say yes here to build support for TI LP8788 ADC.
 
+config VIPERBOARD_ADC
+	tristate "Viperboard ADC support"
+	depends on MFD_VIPERBOARD && USB
+	help
+	  Say yes here to access the ADC part of the Nano River
+	  Technologies Viperboard.
+
 endmenu
drivers/iio/adc/Makefile +1 -0
index 900995d..4852c2e 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7791) += ad7791.o
 obj-$(CONFIG_AT91_ADC) += at91_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
+obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
drivers/iio/adc/viperboard_adc.c new file +181 -0

181 lines not on this page · raw message

drivers/mfd/viperboard.c +3 -0
index a7b5b34..dacb3b7 100644
@@ -44,6 +44,9 @@ static struct mfd_cell vprbrd_devs[] = {
 	{
 		.name = "viperboard-i2c",
 	},
+	{
+		.name = "viperboard-adc",
+	},
 };
 
 static int vprbrd_probe(struct usb_interface *interface,
include/linux/mfd/viperboard.h +1 -0
index ef78514..1934528 100644
@@ -46,6 +46,7 @@
 #define VPRBRD_USB_REQUEST_I2C      0xe9
 #define VPRBRD_USB_REQUEST_MAJOR    0xea
 #define VPRBRD_USB_REQUEST_MINOR    0xeb
+#define VPRBRD_USB_REQUEST_ADC      0xec
 #define VPRBRD_USB_REQUEST_GPIOA    0xed
 #define VPRBRD_USB_REQUEST_GPIOB    0xdd
 
Signature · 1 line
1.7.10.4
Reviewed-by on v3 5/5
#10 lore raw

Re: [PATCH v3 5/5] iio: adc: add viperboard adc driver

Quoted 6 lines · Lars Poeschel

From: Lars Poeschel <[email protected]>

This adds the mfd cell to use the adc part of the Nano River Technologies viperboard.

Looks good to me.

If you happen to resend the series there is one tiny bit that could be changed, but no need to resend the series just for this.

Quoted 10 lines
---
 drivers/iio/adc/Kconfig          |    7 ++
 drivers/iio/adc/Makefile         |    1 +
 drivers/iio/adc/viperboard_adc.c |  181 ++++++++++++++++++++++++++++++++++++++
 drivers/mfd/viperboard.c         |    3 +
 include/linux/mfd/viperboard.h   |    1 +
 5 files changed, 193 insertions(+)
 create mode 100644 drivers/iio/adc/viperboard_adc.c

drivers/iio/adc/viperboard_adc.c line 127

Quoted 10 lines
drivers/iio/adc/viperboard_adc.c new file +10 -0
+
+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 *indio_dev;
+	int ret;
+
+	/* registering iio */
+	indio_dev = iio_device_alloc(sizeof(struct vprbrd_adc));

sizeof(*adc)

Quoted 4 lines
drivers/iio/adc/viperboard_adc.c new file +4 -0
+	if (!indio_dev) {
+		dev_err(&pdev->dev, "failed allocating iio device\n");
+		return -ENOMEM;
+	}
maintainer Acked-by on v3 5/5
#11 lore raw

Re: [PATCH v3 5/5] iio: adc: add viperboard adc driver

In reply to Lars Poeschel
Quoted 5 lines · Lars Poeschel

From: Lars Poeschel <[email protected]>

This adds the mfd cell to use the adc part of the Nano River Technologies viperboard.

One utter nitpick inline (nice to clean up but totally trivial)

Quoted 1 line

As there is a clear dependence on the mfd elements here this should probably go though Samuel's tree once people are happy with the other elements.

Quoted 40 lines
---
 drivers/iio/adc/Kconfig          |    7 ++
 drivers/iio/adc/Makefile         |    1 +
 drivers/iio/adc/viperboard_adc.c |  181 ++++++++++++++++++++++++++++++++++++++
 drivers/mfd/viperboard.c         |    3 +
 include/linux/mfd/viperboard.h   |    1 +
 5 files changed, 193 insertions(+)
 create mode 100644 drivers/iio/adc/viperboard_adc.c
drivers/iio/adc/Kconfig +7 -0
index 4927581..35ad77d 100644
@@ -60,4 +60,11 @@ config LP8788_ADC
 	help
 	  Say yes here to build support for TI LP8788 ADC.
 
+config VIPERBOARD_ADC
+	tristate "Viperboard ADC support"
+	depends on MFD_VIPERBOARD && USB
+	help
+	  Say yes here to access the ADC part of the Nano River
+	  Technologies Viperboard.
+
 endmenu
drivers/iio/adc/Makefile +1 -0
index 900995d..4852c2e 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_AD7476) += ad7476.o
 obj-$(CONFIG_AD7791) += ad7791.o
 obj-$(CONFIG_AT91_ADC) += at91_adc.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
+obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o
drivers/iio/adc/viperboard_adc.c new file +0 -0
new file mode 100644
index 0000000..58345c7

drivers/iio/adc/viperboard_adc.c line 2

Quoted 2 lines
drivers/iio/adc/viperboard_adc.c new file +2 -0
@@ -0,0 +1,181 @@
+/*
+ *  Nano River Technologies viperboard iio ADC driver

IIO (told you it was a nitpick).

Quoted 206 lines
drivers/iio/adc/viperboard_adc.c new file +179 -0
+ *
+ *  (C) 2012 by Lemonage GmbH
+ *  Author: Lars Poeschel <[email protected]>
+ *  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 vprbrd_adc_msg {
+	u8 cmd;
+	u8 chan;
+	u8 val;
+} __packed;
+
+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,	\
+	.scan_index = _index,				\
+	.scan_type = {					\
+		.sign = 'u',				\
+		.realbits = 8,				\
+		.storagebits = 8,			\
+	},						\
+}
+
+static struct iio_chan_spec const vprbrd_adc_iio_channels[] = {
+	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 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;
+
+	switch (info) {
+	case IIO_CHAN_INFO_RAW:
+		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), VPRBRD_USB_REQUEST_ADC,
+			VPRBRD_USB_TYPE_OUT, 0x0000, 0x0000, admsg,
+			sizeof(struct vprbrd_adc_msg), VPRBRD_USB_TIMEOUT_MS);
+		if (ret != sizeof(struct vprbrd_adc_msg)) {
+			dev_err(&iio_dev->dev, "usb send error on adc read\n");
+			error = -EREMOTEIO;
+		}
+
+		ret = usb_control_msg(vb->usb_dev,
+			usb_rcvctrlpipe(vb->usb_dev, 0), VPRBRD_USB_REQUEST_ADC,
+			VPRBRD_USB_TYPE_IN, 0x0000, 0x0000, admsg,
+			sizeof(struct vprbrd_adc_msg), VPRBRD_USB_TIMEOUT_MS);
+
+		*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;
+	default:
+		error = -EINVAL;
+		break;
+	}
+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 *indio_dev;
+	int ret;
+
+	/* registering iio */
+	indio_dev = iio_device_alloc(sizeof(struct vprbrd_adc));
+	if (!indio_dev) {
+		dev_err(&pdev->dev, "failed allocating iio device\n");
+		return -ENOMEM;
+	}
+
+	adc = iio_priv(indio_dev);
+	adc->vb = vb;
+	indio_dev->name = "viperboard adc";
+	indio_dev->dev.parent = &pdev->dev;
+	indio_dev->info = &vprbrd_adc_iio_info;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+	indio_dev->channels = vprbrd_adc_iio_channels;
+	indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(&pdev->dev, "could not register iio (adc)");
+		goto error;
+	}
+
+	platform_set_drvdata(pdev, indio_dev);
+
+	return 0;
+
+error:
+	iio_device_free(indio_dev);
+	return ret;
+}
+
+static int __devexit vprbrd_adc_remove(struct platform_device *pdev)
+{
+	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+
+	iio_device_unregister(indio_dev);
+	iio_device_free(indio_dev);
+
+	return 0;
+}
+
+static struct platform_driver vprbrd_adc_driver = {
+	.driver = {
+		.name	= "viperboard-adc",
+		.owner	= THIS_MODULE,
+	},
+	.probe		= vprbrd_adc_probe,
+	.remove		= __devexit_p(vprbrd_adc_remove),
+};
+
+module_platform_driver(vprbrd_adc_driver);
+
+MODULE_AUTHOR("Lars Poeschel <[email protected]>");
+MODULE_DESCRIPTION("IIO ADC driver for Nano River Techs Viperboard");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:viperboard-adc");
drivers/mfd/viperboard.c +3 -0
index a7b5b34..dacb3b7 100644
@@ -44,6 +44,9 @@ static struct mfd_cell vprbrd_devs[] = {
 	{
 		.name = "viperboard-i2c",
 	},
+	{
+		.name = "viperboard-adc",
+	},
 };
 
 static int vprbrd_probe(struct usb_interface *interface,
include/linux/mfd/viperboard.h +1 -0
index ef78514..1934528 100644
@@ -46,6 +46,7 @@
 #define VPRBRD_USB_REQUEST_I2C      0xe9
 #define VPRBRD_USB_REQUEST_MAJOR    0xea
 #define VPRBRD_USB_REQUEST_MINOR    0xeb
+#define VPRBRD_USB_REQUEST_ADC      0xec
 #define VPRBRD_USB_REQUEST_GPIOA    0xed
 #define VPRBRD_USB_REQUEST_GPIOB    0xdd