* [RFC PATCH 0/6] IIO in kernel interfaces.
@ 2011-10-18 15:29 Jonathan Cameron
2011-10-18 15:29 ` [PATCH 1/6] IIO: core: add datasheet_name to chan_spec Jonathan Cameron
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 15:29 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: linus.ml.walleij, zdevai, linux, arnd, broonie, gregkh,
Jonathan Cameron
There are obviously some rough corners in here that will need cleaning up.
For now I've just put this out there to see if anyone radically disagrees
on the direction. It sits on top the recent rfc to move first bit of IIO
out of staging with a few buglets fixed. Best bet if anyone wants to
test is to pull from:
https://github.com/jic23/linux-iio/tree/outofstaging
which now also includes these patches.
Intereresting patches are 3 and 4. 5 gives a trivial example of
a driver using this (hwmon driver that only takes first matching channel
and sticks it out as in1_input - breaks all sorts elements of the hwmon
interface spec.)
For now I've gone with Mark Brown's suggestion of a datasheet_name for
finding the channels on the device. Patch 2 hacks this name into the
max1363 driver. I'll probably put a version matching on channel number and
type in at a later date.
Here we just have a pull interface. Push is considerably harder to do
and needs quite a lot more of the IIO infrastructure to be in place
(triggers / buffers etc). Events obviously require IIO event handling
to be there. Hence all of that will have to wait until those elements
have in of themselves been posted for review.
It is pretty clear to me that hwmon interface for starters needs the
ability to say - 'give me all mappings that correspond to me'.
This is what I intend to add next followed by some utility functions
to make it easy to match the hwmon interface.
At that point I'll propose the hwmon driver goes into drivers/hwmon
(subject to the underlying iio stuff merging).
Fun fun fun. Thanks to Linus an Mark for their input on this.
Hope this is roughly what you guys were looking for.
Also on my list to do is to check this very thoroughly for any
possible race conditions around the removal of the underlying
device.
Jonathan
Jonathan Cameron (6):
IIO: core: add datasheet_name to chan_spec
IIO:ADC:max1363 add datasheet_name entries.
IIO:CORE add global list of registered IIO devices.
IIO:Core add in kernel interface mapping and getting IIO channels.
IIO:Temporary example hwmon interface.
stargate2: example of map configuration for iio to hwmon example.
arch/arm/mach-pxa/stargate2.c | 23 ++++++++
drivers/Makefile | 2 +-
drivers/iio/Kconfig | 7 ++
drivers/iio/Makefile | 2 +
drivers/iio/adc/max1363_core.c | 4 +-
drivers/iio/iio.c | 121 ++++++++++++++++++++++++++++++++++++++++
drivers/iio/iio_hwmon.c | 104 ++++++++++++++++++++++++++++++++++
drivers/iio/inkern.c | 21 +++++++
include/linux/iio/iio.h | 9 +++-
include/linux/iio/inkern.h | 63 +++++++++++++++++++++
10 files changed, 353 insertions(+), 3 deletions(-)
create mode 100644 drivers/iio/iio_hwmon.c
create mode 100644 drivers/iio/inkern.c
create mode 100644 include/linux/iio/inkern.h
--
1.7.7
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/6] IIO: core: add datasheet_name to chan_spec
2011-10-18 15:29 [RFC PATCH 0/6] IIO in kernel interfaces Jonathan Cameron
@ 2011-10-18 15:29 ` Jonathan Cameron
2011-10-18 15:29 ` [PATCH 2/6] IIO:ADC:max1363 add datasheet_name entries Jonathan Cameron
` (4 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 15:29 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: linus.ml.walleij, zdevai, linux, arnd, broonie, gregkh,
Jonathan Cameron
This allows for matching against the name given
on a datasheet, however silly/inconsistent it might
be.
Useful for in kernel interfaces.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
include/linux/iio/iio.h | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 8066c8a..beedc5c 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -128,6 +128,7 @@ struct iio_chan_spec {
} scan_type;
long info_mask;
char *extend_name;
+ const char *datasheet_name;
unsigned processed_val:1;
unsigned modified:1;
unsigned indexed:1;
--
1.7.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/6] IIO:ADC:max1363 add datasheet_name entries.
2011-10-18 15:29 [RFC PATCH 0/6] IIO in kernel interfaces Jonathan Cameron
2011-10-18 15:29 ` [PATCH 1/6] IIO: core: add datasheet_name to chan_spec Jonathan Cameron
@ 2011-10-18 15:29 ` Jonathan Cameron
2011-10-18 15:29 ` [PATCH 3/6] IIO:CORE add global list of registered IIO devices Jonathan Cameron
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 15:29 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: linus.ml.walleij, zdevai, linux, arnd, broonie, gregkh,
Jonathan Cameron
Kind of obvious for this device but useful
for testing purposes.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
drivers/iio/adc/max1363_core.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/drivers/iio/adc/max1363_core.c b/drivers/iio/adc/max1363_core.c
index ee06d48..e035df9 100644
--- a/drivers/iio/adc/max1363_core.c
+++ b/drivers/iio/adc/max1363_core.c
@@ -251,7 +251,8 @@ static const enum max1363_modes max1363_mode_list[] = {
.indexed = 1, \
.channel = num, \
.address = addr, \
- .info_mask = MAX1363_INFO_MASK \
+ .info_mask = MAX1363_INFO_MASK, \
+ .datasheet_name = "AIN"#num \
} \
/* bipolar channel */
@@ -264,6 +265,7 @@ static const enum max1363_modes max1363_mode_list[] = {
.channel2 = num2, \
.address = addr, \
.info_mask = MAX1363_INFO_MASK, \
+ .datasheet_name = "AIN"#num"-AIN"#num2 \
}
#define MAX1363_INFO_MASK (1 << IIO_CHAN_INFO_SCALE_SHARED)
--
1.7.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/6] IIO:CORE add global list of registered IIO devices.
2011-10-18 15:29 [RFC PATCH 0/6] IIO in kernel interfaces Jonathan Cameron
2011-10-18 15:29 ` [PATCH 1/6] IIO: core: add datasheet_name to chan_spec Jonathan Cameron
2011-10-18 15:29 ` [PATCH 2/6] IIO:ADC:max1363 add datasheet_name entries Jonathan Cameron
@ 2011-10-18 15:29 ` Jonathan Cameron
2011-10-18 18:25 ` Lars-Peter Clausen
2011-10-18 15:29 ` [PATCH 4/6] IIO:Core add in kernel interface mapping and getting IIO channels Jonathan Cameron
` (2 subsequent siblings)
5 siblings, 1 reply; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 15:29 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: linus.ml.walleij, zdevai, linux, arnd, broonie, gregkh,
Jonathan Cameron
Needed for inkernel interfaces.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
drivers/iio/iio.c | 9 +++++++++
include/linux/iio/iio.h | 1 +
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/drivers/iio/iio.c b/drivers/iio/iio.c
index 9e6acc1..246a093 100644
--- a/drivers/iio/iio.c
+++ b/drivers/iio/iio.c
@@ -15,6 +15,9 @@
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+static DEFINE_MUTEX(iio_device_list_lock);
+static LIST_HEAD(iio_device_list);
+
static DEFINE_IDA(iio_ida);
static struct bus_type iio_bus_type = {
@@ -91,6 +94,9 @@ static void iio_dev_release(struct device *device)
{
struct iio_dev *indio_dev = container_of(device, struct iio_dev, dev);
iio_device_unregister_sysfs(indio_dev);
+ mutex_lock(&iio_device_list_lock);
+ list_del(&indio_dev->dev_list_entry);
+ mutex_unlock(&iio_device_list_lock);
}
static struct device_type iio_dev_type = {
@@ -559,6 +565,9 @@ int iio_device_register(struct iio_dev *indio_dev)
if (ret)
goto error_free_sysfs;
+ mutex_lock(&iio_device_list_lock);
+ list_add(&indio_dev->dev_list_entry, &iio_device_list);
+ mutex_unlock(&iio_device_list_lock);
return 0;
error_free_sysfs:
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index beedc5c..f14e7dc 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -192,6 +192,7 @@ struct iio_info {
* @info: [DRIVER] callbacks and constant info from driver
* @groups: [INTERN] attribute groups
* @groupcounter: [INTERN] index of next attribute group
+ * @dev_list_entry: [INTERN] entry in global list of iio devices
**/
struct iio_dev {
int id;
--
1.7.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/6] IIO:Core add in kernel interface mapping and getting IIO channels.
2011-10-18 15:29 [RFC PATCH 0/6] IIO in kernel interfaces Jonathan Cameron
` (2 preceding siblings ...)
2011-10-18 15:29 ` [PATCH 3/6] IIO:CORE add global list of registered IIO devices Jonathan Cameron
@ 2011-10-18 15:29 ` Jonathan Cameron
2011-10-18 15:29 ` [PATCH 5/6] IIO:Temporary example hwmon interface Jonathan Cameron
2011-10-18 15:29 ` [PATCH 6/6] stargate2: example of map configuration for iio to hwmon example Jonathan Cameron
5 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 15:29 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: linus.ml.walleij, zdevai, linux, arnd, broonie, gregkh,
Jonathan Cameron
Two elements here:
* Map as defined in include/linux/iio/inkern.h
* Matching code to actually get the iio_dev and channel
that we want from the global list of IIO devices.
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
drivers/Makefile | 2 +-
drivers/iio/Makefile | 1 +
drivers/iio/iio.c | 112 ++++++++++++++++++++++++++++++++++++++++++++
drivers/iio/inkern.c | 21 ++++++++
include/linux/iio/iio.h | 7 ++-
include/linux/iio/inkern.h | 63 +++++++++++++++++++++++++
6 files changed, 204 insertions(+), 2 deletions(-)
diff --git a/drivers/Makefile b/drivers/Makefile
index df39628..2b389c5 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -130,5 +130,5 @@ obj-$(CONFIG_VIRT_DRIVERS) += virt/
obj-$(CONFIG_HYPERV) += hv/
-obj-$(CONFIG_IIO) += iio/
+obj-y += iio/
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index db3c426..cfb588a 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -1,6 +1,7 @@
#
# Makefile for the Industrial I/O subsystem
#
+obj-y = inkern.o
obj-$(CONFIG_IIO) += iio.o
industrialio-y := core.o
diff --git a/drivers/iio/iio.c b/drivers/iio/iio.c
index 246a093..ae2daf0 100644
--- a/drivers/iio/iio.c
+++ b/drivers/iio/iio.c
@@ -12,8 +12,10 @@
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/idr.h>
+#include <linux/err.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+#include <linux/iio/inkern.h>
static DEFINE_MUTEX(iio_device_list_lock);
static LIST_HEAD(iio_device_list);
@@ -71,6 +73,116 @@ static const char * const iio_chan_info_postfix[] = {
= "quadrature_correction_raw",
};
+struct iio_channel *iio_channel_get(const struct device *dev,
+ const char *name,
+ const char *channel_name)
+{
+ struct iio_map *c_i = NULL, *c = NULL;
+ struct iio_dev *i_i = NULL, *indio_dev = NULL;
+ const struct iio_chan_spec *chan = NULL;
+
+ int i;
+ struct iio_channel *channel;
+
+ if (dev == NULL && name == NULL && channel_name == NULL)
+ return ERR_PTR(-ENODEV);
+ /* first find matching entry the channel map */
+ list_for_each_entry(c_i, &iio_map_list, l) {
+ if (dev && dev != c_i->consumer_dev)
+ continue;
+ if (name && strcmp(name, c_i->consumer_dev_name) != 0)
+ continue;
+
+ if (channel_name && strcmp(channel_name, c_i->consumer_channel)
+ != 0)
+ continue;
+ c = c_i;
+ break;
+ }
+ if (c == NULL)
+ return ERR_PTR(-ENODEV);
+
+ mutex_lock(&iio_device_list_lock);
+ /* now find the iio device if it has been registered */
+ if (c->adc_dev) {
+ list_for_each_entry(i_i, &iio_device_list,
+ dev_list_entry) {
+ if (i_i->info->get_hardware_id && c->adc_dev ==
+ indio_dev->info->get_hardware_id(indio_dev)) {
+ indio_dev = i_i;
+ break;
+ } else if (indio_dev->dev.parent &&
+ c->adc_dev == indio_dev->dev.parent) {
+ indio_dev = i_i;
+ break;
+ }
+ }
+ } else if (c->adc_dev_name) {
+ list_for_each_entry(i_i, &iio_device_list,
+ dev_list_entry) {
+ if (i_i->info->get_hardware_id) {
+ if (c->adc_dev_name ==
+ dev_name(i_i->info->get_hardware_id(i_i))) {
+ indio_dev = i_i;
+ break;
+ }
+ } else if (i_i->dev.parent) {
+ if (strcmp(c->adc_dev_name,
+ dev_name(i_i->dev.parent)) == 0) {
+ indio_dev = i_i;
+ break;
+ }
+ } else {
+ printk(KERN_ERR "invalid map\n");
+ mutex_unlock(&iio_device_list_lock);
+ return ERR_PTR(-ENODEV);
+ }
+ }
+ }
+ if (indio_dev)
+ get_device(&indio_dev->dev);
+ mutex_unlock(&iio_device_list_lock);
+ if (indio_dev == NULL)
+ return ERR_PTR(-ENODEV);
+
+ /* finally verify the channel exists */
+ if (c->adc_channel_label)
+ for (i = 0; i < indio_dev->num_channels; i++)
+ if (indio_dev->channels[i].datasheet_name &&
+ strcmp(c->adc_channel_label,
+ indio_dev->channels[i].datasheet_name)
+ == 0) {
+ chan = &indio_dev->channels[i];
+ break;
+ }
+ channel = kmalloc(sizeof(*channel), GFP_KERNEL);
+ if (channel == NULL)
+ return ERR_PTR(-ENOMEM);
+ channel->indio_dev = indio_dev;
+ if (chan == NULL)
+ channel->channel = &indio_dev->channels[c->channel_number];
+ else
+ channel->channel = chan;
+ return channel;
+}
+EXPORT_SYMBOL_GPL(iio_channel_get);
+
+void iio_channel_release(struct iio_channel *channel)
+{
+ put_device(&channel->indio_dev->dev);
+ kfree(channel);
+}
+EXPORT_SYMBOL_GPL(iio_channel_release);
+
+
+int iio_read_channel_raw(struct iio_channel *chan, int *val)
+{
+ int val2;
+ return chan->indio_dev->info->read_raw(chan->indio_dev, chan->channel,
+ val, &val2, 0);
+}
+EXPORT_SYMBOL_GPL(iio_read_channel_raw);
+
static void iio_device_free_read_attr(struct iio_dev *indio_dev,
struct iio_dev_attr *p)
{
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
new file mode 100644
index 0000000..e2ba5d6
--- /dev/null
+++ b/drivers/iio/inkern.c
@@ -0,0 +1,21 @@
+/* The industrial I/O core in kernel channel mapping
+ *
+ * Copyright (c) 2011 Jonathan Cameron
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+#include <linux/iio/inkern.h>
+#include <linux/err.h>
+
+LIST_HEAD(iio_map_list);
+EXPORT_SYMBOL_GPL(iio_map_list);
+void iio_map_array_register(struct iio_map *map, int nummaps)
+{
+ int i;
+ for (i = 0; i < nummaps; i++)
+ list_add(&map[i].l, &iio_map_list);
+}
+EXPORT_SYMBOL(iio_map_array_register);
+
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index f14e7dc..34c51b7 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -153,7 +153,10 @@ struct iio_dev;
* @write_raw_get_fmt: callback function to query the expected
* format/precision. If not set by the driver, write_raw
* returns IIO_VAL_INT_PLUS_MICRO.
- **/
+ * @get_hardware_id: obtain device relating to hardware. Typically based on
+ * the parent device (actual hardware). Note that if
+ * not specified then iio_dev.dev->parent is used.
+ */
struct iio_info {
struct module *driver_module;
const struct attribute_group *attrs;
@@ -173,6 +176,7 @@ struct iio_info {
int (*write_raw_get_fmt)(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
long mask);
+ struct device *(*get_hardware_id)(struct iio_dev *indio_dev);
};
/**
@@ -208,6 +212,7 @@ struct iio_dev {
#define IIO_MAX_GROUPS 1
const struct attribute_group *groups[IIO_MAX_GROUPS + 1];
int groupcounter;
+ struct list_head dev_list_entry;
};
/**
diff --git a/include/linux/iio/inkern.h b/include/linux/iio/inkern.h
new file mode 100644
index 0000000..89b43d32
--- /dev/null
+++ b/include/linux/iio/inkern.h
@@ -0,0 +1,63 @@
+#include <linux/device.h>
+#include <linux/list.h>
+
+struct iio_dev;
+struct iio_chan_spec;
+
+struct iio_channel {
+ struct iio_dev *indio_dev;
+ const struct iio_chan_spec *channel;
+};
+
+extern struct list_head iio_map_list;
+
+struct iio_map {
+ /* iio device side */
+ struct device *adc_dev;
+ const char *adc_dev_name;
+ const char *adc_channel_label;
+ int channel_number; /*naughty starting point */
+
+ /* consumer side */
+ struct device *consumer_dev;
+ const char *consumer_dev_name;
+ const char *consumer_channel;
+
+ /* management - probably neater ways of doing this */
+ struct list_head l;
+};
+
+void iio_map_array_register(struct iio_map *map, int nummaps);
+/**
+ * iio_channel_get() - get an opaque reference to a specified device.
+ */
+struct iio_channel *iio_channel_get(const struct device *dev,
+ const char *name,
+ const char *consumer_channel);
+void iio_channel_release(struct iio_channel *chan);
+
+/**
+ * iio_read_channel_raw() - read from a given channel
+ * @channel: the channel being queried.
+ * @val: value read back.
+ *
+ * Note raw reads from iio channels are in adc counts and hence
+ * scale will need to be applied if standard units required.
+ *
+ * Maybe want to pass the type as a sanity check.
+ */
+int iio_read_channel_raw(struct iio_channel *chan,
+ int *val);
+
+/**
+ * iio_read_channel_scale() - read the scale value for a channel
+ * @channel: the channel being queried.
+ * @val: first part of value read back.
+ * @val2: second part of value read back.
+ *
+ * Note returns a description of what is in val and val2, such
+ * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
+ * + val2/1e6
+ */
+int iio_read_channel_scale(struct iio_channel *chan, int *val,
+ int *val2);
--
1.7.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/6] IIO:Temporary example hwmon interface.
2011-10-18 15:29 [RFC PATCH 0/6] IIO in kernel interfaces Jonathan Cameron
` (3 preceding siblings ...)
2011-10-18 15:29 ` [PATCH 4/6] IIO:Core add in kernel interface mapping and getting IIO channels Jonathan Cameron
@ 2011-10-18 15:29 ` Jonathan Cameron
2011-10-18 15:29 ` [PATCH 6/6] stargate2: example of map configuration for iio to hwmon example Jonathan Cameron
5 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 15:29 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: linus.ml.walleij, zdevai, linux, arnd, broonie, gregkh,
Jonathan Cameron
Not to be merged. Breaks all sorts of elements of the hwmon
interface spec and is not flexible enough.
---
drivers/iio/Kconfig | 7 +++
drivers/iio/Makefile | 1 +
drivers/iio/iio_hwmon.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 112 insertions(+), 0 deletions(-)
diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 308bc97..334f633 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -11,6 +11,13 @@ menuconfig IIO
if IIO
+config IIO_HWMON
+ tristate "Temporary dummy driver to test in kern interface"
+ help
+ Dirty test of in kernel framework. Not intended to ever
+ merge in current state.
+
+
source "drivers/iio/adc/Kconfig"
source "drivers/iio/imu/Kconfig"
source "drivers/iio/light/Kconfig"
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index cfb588a..5f9c01a 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -6,6 +6,7 @@ obj-y = inkern.o
obj-$(CONFIG_IIO) += iio.o
industrialio-y := core.o
+obj-$(CONFIG_IIO_HWMON) += iio_hwmon.o
obj-y += adc/
obj-y += imu/
obj-y += light/
diff --git a/drivers/iio/iio_hwmon.c b/drivers/iio/iio_hwmon.c
new file mode 100644
index 0000000..03fc590
--- /dev/null
+++ b/drivers/iio/iio_hwmon.c
@@ -0,0 +1,104 @@
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/iio/inkern.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+
+struct iio_hwmon_state {
+ struct iio_channel *channel;
+ struct device *hwmon_dev;
+};
+
+static ssize_t iio_hwmon_read_val(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ int val, ret;
+ struct iio_hwmon_state *state = dev_get_drvdata(dev);
+
+ ret = iio_read_channel_raw(state->channel, &val);
+ if (ret < 0)
+ return ret;
+ return sprintf(buf, "%d\n", val);
+}
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, iio_hwmon_read_val, NULL, 0);
+
+static struct attribute *iio_hwmon_attrs[] = {
+ &sensor_dev_attr_in1_input.dev_attr.attr,
+ NULL,
+};
+
+static struct attribute_group iio_hwmon_attr_group = {
+ .attrs = iio_hwmon_attrs
+};
+
+static int __devinit iio_hwmon_probe(struct platform_device *pdev)
+{
+ struct iio_hwmon_state *st;
+ int ret;
+
+ st = kzalloc(sizeof(*st), GFP_KERNEL);
+ if (st == NULL) {
+ ret = -ENOMEM;
+ goto error_ret;
+ }
+
+ st->channel = iio_channel_get(&pdev->dev, NULL, "testchan1");
+ if (IS_ERR(st->channel)) {
+ ret = PTR_ERR(st->channel);
+ goto error_free_state;
+ }
+
+ st->hwmon_dev = hwmon_device_register(&pdev->dev);
+
+ ret = sysfs_create_group(&pdev->dev.kobj, &iio_hwmon_attr_group);
+ if (ret < 0)
+ goto error_release_channel;
+
+ platform_set_drvdata(pdev, st);
+ return 0;
+
+error_release_channel:
+ iio_channel_release(st->channel);
+error_free_state:
+ kfree(st);
+error_ret:
+ return ret;
+}
+
+static int __devexit iio_hwmon_remove(struct platform_device *pdev)
+{
+ struct iio_hwmon_state *st = platform_get_drvdata(pdev);
+ sysfs_remove_group(&pdev->dev.kobj, &iio_hwmon_attr_group);
+ hwmon_device_unregister(st->hwmon_dev);
+ iio_channel_release(st->channel);
+ return 0;
+}
+
+static struct platform_driver __refdata iio_hwmon_driver = {
+ .driver = {
+ .name = "iio_hwmon",
+ .owner = THIS_MODULE,
+ },
+ .probe = iio_hwmon_probe,
+ .remove = __devexit_p(iio_hwmon_remove),
+};
+
+static int iio_inkern_init(void)
+{
+ return platform_driver_register(&iio_hwmon_driver);
+}
+module_init(iio_inkern_init);
+
+static void iio_inkern_exit(void)
+{
+ platform_driver_unregister(&iio_hwmon_driver);
+}
+module_exit(iio_inkern_exit);
+
+MODULE_AUTHOR("Jonathan Cameron <jic23@cam.ac.uk>");
+MODULE_DESCRIPTION("IIO to hwmon driver");
+MODULE_LICENSE("GPL v2");
--
1.7.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/6] stargate2: example of map configuration for iio to hwmon example.
2011-10-18 15:29 [RFC PATCH 0/6] IIO in kernel interfaces Jonathan Cameron
` (4 preceding siblings ...)
2011-10-18 15:29 ` [PATCH 5/6] IIO:Temporary example hwmon interface Jonathan Cameron
@ 2011-10-18 15:29 ` Jonathan Cameron
5 siblings, 0 replies; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 15:29 UTC (permalink / raw)
To: linux-kernel, linux-iio
Cc: linus.ml.walleij, zdevai, linux, arnd, broonie, gregkh,
Jonathan Cameron
Do not commit.
---
arch/arm/mach-pxa/stargate2.c | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/arch/arm/mach-pxa/stargate2.c b/arch/arm/mach-pxa/stargate2.c
index 3f8d0af..62dc2a8 100644
--- a/arch/arm/mach-pxa/stargate2.c
+++ b/arch/arm/mach-pxa/stargate2.c
@@ -54,6 +54,8 @@
#include <linux/mfd/da903x.h>
#include <linux/sht15.h>
+#include <linux/iio/inkern.h>
+
#include "devices.h"
#include "generic.h"
@@ -406,6 +408,24 @@ static struct i2c_pxa_platform_data i2c_pdata = {
.fast_mode = 1,
};
+static struct platform_device iio_hwmon_test = {
+ .name = "iio_hwmon",
+};
+
+static struct iio_map adc_map[] = {
+ {
+ .adc_dev_name = "0-0035",
+ .adc_channel_label = "AIN1",
+ .consumer_dev = &iio_hwmon_test.dev,
+ .consumer_channel = "testchan1",
+ }, {
+ .adc_dev_name = "0-0035",
+ .adc_channel_label = "AIN2",
+ .consumer_dev = &iio_hwmon_test.dev,
+ .consumer_channel = "testchan2",
+ },
+};
+
static void __init imote2_stargate2_init(void)
{
@@ -423,6 +443,8 @@ static void __init imote2_stargate2_init(void)
pxa27x_set_i2c_power_info(&i2c_pwr_pdata);
pxa_set_i2c_info(&i2c_pdata);
+
+ iio_map_array_register(adc_map, 1);
}
#ifdef CONFIG_MACH_INTELMOTE2
@@ -971,6 +993,7 @@ static struct platform_device *stargate2_devices[] = {
&stargate2_sram,
&smc91x_device,
&sht15,
+ &iio_hwmon_test,
};
static void __init stargate2_init(void)
--
1.7.7
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] IIO:CORE add global list of registered IIO devices.
2011-10-18 15:29 ` [PATCH 3/6] IIO:CORE add global list of registered IIO devices Jonathan Cameron
@ 2011-10-18 18:25 ` Lars-Peter Clausen
2011-10-18 20:33 ` Jonathan Cameron
0 siblings, 1 reply; 11+ messages in thread
From: Lars-Peter Clausen @ 2011-10-18 18:25 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-kernel, linux-iio, linus.ml.walleij, zdevai, linux, arnd,
broonie, gregkh
On 10/18/2011 05:29 PM, Jonathan Cameron wrote:
> Needed for inkernel interfaces.
>
The bus_type structure keeps a list of all devices registered on that bus, so
you should be able to use bus_for_each_dev and bus_find_device for iterating
over the iio devices.
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
> drivers/iio/iio.c | 9 +++++++++
> include/linux/iio/iio.h | 1 +
> 2 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/iio/iio.c b/drivers/iio/iio.c
> index 9e6acc1..246a093 100644
> --- a/drivers/iio/iio.c
> +++ b/drivers/iio/iio.c
> @@ -15,6 +15,9 @@
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
>
> +static DEFINE_MUTEX(iio_device_list_lock);
> +static LIST_HEAD(iio_device_list);
> +
> static DEFINE_IDA(iio_ida);
>
> static struct bus_type iio_bus_type = {
> @@ -91,6 +94,9 @@ static void iio_dev_release(struct device *device)
> {
> struct iio_dev *indio_dev = container_of(device, struct iio_dev, dev);
> iio_device_unregister_sysfs(indio_dev);
> + mutex_lock(&iio_device_list_lock);
> + list_del(&indio_dev->dev_list_entry);
> + mutex_unlock(&iio_device_list_lock);
> }
>
> static struct device_type iio_dev_type = {
> @@ -559,6 +565,9 @@ int iio_device_register(struct iio_dev *indio_dev)
> if (ret)
> goto error_free_sysfs;
>
> + mutex_lock(&iio_device_list_lock);
> + list_add(&indio_dev->dev_list_entry, &iio_device_list);
> + mutex_unlock(&iio_device_list_lock);
> return 0;
>
> error_free_sysfs:
> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
> index beedc5c..f14e7dc 100644
> --- a/include/linux/iio/iio.h
> +++ b/include/linux/iio/iio.h
> @@ -192,6 +192,7 @@ struct iio_info {
> * @info: [DRIVER] callbacks and constant info from driver
> * @groups: [INTERN] attribute groups
> * @groupcounter: [INTERN] index of next attribute group
> + * @dev_list_entry: [INTERN] entry in global list of iio devices
> **/
> struct iio_dev {
> int id;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] IIO:CORE add global list of registered IIO devices.
2011-10-18 18:25 ` Lars-Peter Clausen
@ 2011-10-18 20:33 ` Jonathan Cameron
2011-10-19 13:46 ` Jonathan Cameron
0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-18 20:33 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: linux-kernel, linux-iio, linus.ml.walleij, zdevai, linux, arnd,
broonie, gregkh
On 10/18/11 19:25, Lars-Peter Clausen wrote:
> On 10/18/2011 05:29 PM, Jonathan Cameron wrote:
>> Needed for inkernel interfaces.
>>
>
> The bus_type structure keeps a list of all devices registered on that bus, so
> you should be able to use bus_for_each_dev and bus_find_device for iterating
> over the iio devices.
I hadn't realised that but don't think it will work anyway. There are several
other things than iio_dev based devices that sit on our bus unfortunately.
None are in these initial merges but they will turn up later.
The most common are iio_triggers but there are also a few weird ones such
as the event generator for the dummy driver and the sysfstrig control device.
We could play some games to allow these to be identified, but it's going
to be a mess. Probably easier to just maintain a second list as we are doing
here. Interesting suggestion though. Thanks and feel free to point out if there
is a simple way around the identification issue.
>
>> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
>> ---
>> drivers/iio/iio.c | 9 +++++++++
>> include/linux/iio/iio.h | 1 +
>> 2 files changed, 10 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/iio/iio.c b/drivers/iio/iio.c
>> index 9e6acc1..246a093 100644
>> --- a/drivers/iio/iio.c
>> +++ b/drivers/iio/iio.c
>> @@ -15,6 +15,9 @@
>> #include <linux/iio/iio.h>
>> #include <linux/iio/sysfs.h>
>>
>> +static DEFINE_MUTEX(iio_device_list_lock);
>> +static LIST_HEAD(iio_device_list);
>> +
>> static DEFINE_IDA(iio_ida);
>>
>> static struct bus_type iio_bus_type = {
>> @@ -91,6 +94,9 @@ static void iio_dev_release(struct device *device)
>> {
>> struct iio_dev *indio_dev = container_of(device, struct iio_dev, dev);
>> iio_device_unregister_sysfs(indio_dev);
>> + mutex_lock(&iio_device_list_lock);
>> + list_del(&indio_dev->dev_list_entry);
>> + mutex_unlock(&iio_device_list_lock);
>> }
>>
>> static struct device_type iio_dev_type = {
>> @@ -559,6 +565,9 @@ int iio_device_register(struct iio_dev *indio_dev)
>> if (ret)
>> goto error_free_sysfs;
>>
>> + mutex_lock(&iio_device_list_lock);
>> + list_add(&indio_dev->dev_list_entry, &iio_device_list);
>> + mutex_unlock(&iio_device_list_lock);
>> return 0;
>>
>> error_free_sysfs:
>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
>> index beedc5c..f14e7dc 100644
>> --- a/include/linux/iio/iio.h
>> +++ b/include/linux/iio/iio.h
>> @@ -192,6 +192,7 @@ struct iio_info {
>> * @info: [DRIVER] callbacks and constant info from driver
>> * @groups: [INTERN] attribute groups
>> * @groupcounter: [INTERN] index of next attribute group
>> + * @dev_list_entry: [INTERN] entry in global list of iio devices
>> **/
>> struct iio_dev {
>> int id;
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] IIO:CORE add global list of registered IIO devices.
2011-10-18 20:33 ` Jonathan Cameron
@ 2011-10-19 13:46 ` Jonathan Cameron
2011-10-19 15:02 ` Lars-Peter Clausen
0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Cameron @ 2011-10-19 13:46 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Lars-Peter Clausen, linux-kernel, linux-iio, linus.ml.walleij,
zdevai, linux, arnd, broonie, gregkh
On 10/18/11 21:33, Jonathan Cameron wrote:
> On 10/18/11 19:25, Lars-Peter Clausen wrote:
>> On 10/18/2011 05:29 PM, Jonathan Cameron wrote:
>>> Needed for inkernel interfaces.
>>>
>>
>> The bus_type structure keeps a list of all devices registered on that bus, so
>> you should be able to use bus_for_each_dev and bus_find_device for iterating
>> over the iio devices.
> I hadn't realised that but don't think it will work anyway. There are several
> other things than iio_dev based devices that sit on our bus unfortunately.
> None are in these initial merges but they will turn up later.
> The most common are iio_triggers but there are also a few weird ones such
> as the event generator for the dummy driver and the sysfstrig control device.
> We could play some games to allow these to be identified, but it's going
> to be a mess. Probably easier to just maintain a second list as we are doing
> here. Interesting suggestion though. Thanks and feel free to point out if there
> is a simple way around the identification issue.
Actually looking into it this morning - this is trivial to do.
We can just check that the device_type is set appropriately before doing anything
else.
Thanks Lars-Peter your suggestion is should clean things up nicely.
New version coming up.
>>
>>> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
>>> ---
>>> drivers/iio/iio.c | 9 +++++++++
>>> include/linux/iio/iio.h | 1 +
>>> 2 files changed, 10 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/drivers/iio/iio.c b/drivers/iio/iio.c
>>> index 9e6acc1..246a093 100644
>>> --- a/drivers/iio/iio.c
>>> +++ b/drivers/iio/iio.c
>>> @@ -15,6 +15,9 @@
>>> #include <linux/iio/iio.h>
>>> #include <linux/iio/sysfs.h>
>>>
>>> +static DEFINE_MUTEX(iio_device_list_lock);
>>> +static LIST_HEAD(iio_device_list);
>>> +
>>> static DEFINE_IDA(iio_ida);
>>>
>>> static struct bus_type iio_bus_type = {
>>> @@ -91,6 +94,9 @@ static void iio_dev_release(struct device *device)
>>> {
>>> struct iio_dev *indio_dev = container_of(device, struct iio_dev, dev);
>>> iio_device_unregister_sysfs(indio_dev);
>>> + mutex_lock(&iio_device_list_lock);
>>> + list_del(&indio_dev->dev_list_entry);
>>> + mutex_unlock(&iio_device_list_lock);
>>> }
>>>
>>> static struct device_type iio_dev_type = {
>>> @@ -559,6 +565,9 @@ int iio_device_register(struct iio_dev *indio_dev)
>>> if (ret)
>>> goto error_free_sysfs;
>>>
>>> + mutex_lock(&iio_device_list_lock);
>>> + list_add(&indio_dev->dev_list_entry, &iio_device_list);
>>> + mutex_unlock(&iio_device_list_lock);
>>> return 0;
>>>
>>> error_free_sysfs:
>>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
>>> index beedc5c..f14e7dc 100644
>>> --- a/include/linux/iio/iio.h
>>> +++ b/include/linux/iio/iio.h
>>> @@ -192,6 +192,7 @@ struct iio_info {
>>> * @info: [DRIVER] callbacks and constant info from driver
>>> * @groups: [INTERN] attribute groups
>>> * @groupcounter: [INTERN] index of next attribute group
>>> + * @dev_list_entry: [INTERN] entry in global list of iio devices
>>> **/
>>> struct iio_dev {
>>> int id;
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] IIO:CORE add global list of registered IIO devices.
2011-10-19 13:46 ` Jonathan Cameron
@ 2011-10-19 15:02 ` Lars-Peter Clausen
0 siblings, 0 replies; 11+ messages in thread
From: Lars-Peter Clausen @ 2011-10-19 15:02 UTC (permalink / raw)
To: Jonathan Cameron
Cc: linux-kernel, linux-iio, linus.ml.walleij, zdevai, linux, arnd,
broonie, gregkh
On 10/19/2011 03:46 PM, Jonathan Cameron wrote:
> On 10/18/11 21:33, Jonathan Cameron wrote:
>> On 10/18/11 19:25, Lars-Peter Clausen wrote:
>>> On 10/18/2011 05:29 PM, Jonathan Cameron wrote:
>>>> Needed for inkernel interfaces.
>>>>
>>>
>>> The bus_type structure keeps a list of all devices registered on that bus, so
>>> you should be able to use bus_for_each_dev and bus_find_device for iterating
>>> over the iio devices.
>> I hadn't realised that but don't think it will work anyway. There are several
>> other things than iio_dev based devices that sit on our bus unfortunately.
>> None are in these initial merges but they will turn up later.
>> The most common are iio_triggers but there are also a few weird ones such
>> as the event generator for the dummy driver and the sysfstrig control device.
>> We could play some games to allow these to be identified, but it's going
>> to be a mess. Probably easier to just maintain a second list as we are doing
>> here. Interesting suggestion though. Thanks and feel free to point out if there
>> is a simple way around the identification issue.
> Actually looking into it this morning - this is trivial to do.
> We can just check that the device_type is set appropriately before doing anything
> else.
>
> Thanks Lars-Peter your suggestion is should clean things up nicely.
>
> New version coming up.
Yes, this should work. The device class iter functions already allow
filtering on the device type, so it might even make sense to add generic
device bus iterator functions which allow this as well, but this is probably
something for later.
>>>
>>>> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
>>>> ---
>>>> drivers/iio/iio.c | 9 +++++++++
>>>> include/linux/iio/iio.h | 1 +
>>>> 2 files changed, 10 insertions(+), 0 deletions(-)
>>>>
>>>> diff --git a/drivers/iio/iio.c b/drivers/iio/iio.c
>>>> index 9e6acc1..246a093 100644
>>>> --- a/drivers/iio/iio.c
>>>> +++ b/drivers/iio/iio.c
>>>> @@ -15,6 +15,9 @@
>>>> #include <linux/iio/iio.h>
>>>> #include <linux/iio/sysfs.h>
>>>>
>>>> +static DEFINE_MUTEX(iio_device_list_lock);
>>>> +static LIST_HEAD(iio_device_list);
>>>> +
>>>> static DEFINE_IDA(iio_ida);
>>>>
>>>> static struct bus_type iio_bus_type = {
>>>> @@ -91,6 +94,9 @@ static void iio_dev_release(struct device *device)
>>>> {
>>>> struct iio_dev *indio_dev = container_of(device, struct iio_dev, dev);
>>>> iio_device_unregister_sysfs(indio_dev);
>>>> + mutex_lock(&iio_device_list_lock);
>>>> + list_del(&indio_dev->dev_list_entry);
>>>> + mutex_unlock(&iio_device_list_lock);
>>>> }
>>>>
>>>> static struct device_type iio_dev_type = {
>>>> @@ -559,6 +565,9 @@ int iio_device_register(struct iio_dev *indio_dev)
>>>> if (ret)
>>>> goto error_free_sysfs;
>>>>
>>>> + mutex_lock(&iio_device_list_lock);
>>>> + list_add(&indio_dev->dev_list_entry, &iio_device_list);
>>>> + mutex_unlock(&iio_device_list_lock);
>>>> return 0;
>>>>
>>>> error_free_sysfs:
>>>> diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
>>>> index beedc5c..f14e7dc 100644
>>>> --- a/include/linux/iio/iio.h
>>>> +++ b/include/linux/iio/iio.h
>>>> @@ -192,6 +192,7 @@ struct iio_info {
>>>> * @info: [DRIVER] callbacks and constant info from driver
>>>> * @groups: [INTERN] attribute groups
>>>> * @groupcounter: [INTERN] index of next attribute group
>>>> + * @dev_list_entry: [INTERN] entry in global list of iio devices
>>>> **/
>>>> struct iio_dev {
>>>> int id;
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-10-19 15:02 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-18 15:29 [RFC PATCH 0/6] IIO in kernel interfaces Jonathan Cameron
2011-10-18 15:29 ` [PATCH 1/6] IIO: core: add datasheet_name to chan_spec Jonathan Cameron
2011-10-18 15:29 ` [PATCH 2/6] IIO:ADC:max1363 add datasheet_name entries Jonathan Cameron
2011-10-18 15:29 ` [PATCH 3/6] IIO:CORE add global list of registered IIO devices Jonathan Cameron
2011-10-18 18:25 ` Lars-Peter Clausen
2011-10-18 20:33 ` Jonathan Cameron
2011-10-19 13:46 ` Jonathan Cameron
2011-10-19 15:02 ` Lars-Peter Clausen
2011-10-18 15:29 ` [PATCH 4/6] IIO:Core add in kernel interface mapping and getting IIO channels Jonathan Cameron
2011-10-18 15:29 ` [PATCH 5/6] IIO:Temporary example hwmon interface Jonathan Cameron
2011-10-18 15:29 ` [PATCH 6/6] stargate2: example of map configuration for iio to hwmon example Jonathan Cameron
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).