Re: [PATCH] staging:iio:proof of concept in kernel interface.

From: Linus Walleij
Date: Sun Oct 16 2011 - 14:45:15 EST


2011/10/14 Jonathan Cameron <jic23@xxxxxxxxx>:

> I'm trying to work out what our equivalent of the clk finding api is.

Judging from the ideal use of our in-tree driver
drivers/mfd/ab8500-gpadc.c a map like this would be
great

struct adc_map {
struct device *adc_dev;
const char *adc_dev_name;
const char *channel;
struct device *dev;
const char *dev_name;
};

{ adc_dev, adc_dev_name } are alternative-compulsory identifiers for
the ADC

channel: string identifying the channel on the ADC, strings have
been shown to be good for identifying things.

{ dev, dev_name } are alternative-compulsory identifiers for the
ADC client.

struct device * pointers take precedence, fallback to names if device
pointers are unavailable.

adc_dev_name is the name of the ADC and then I mean what is returned
from it's struct device *dev when you do dev_name() on it. dev_name is
well dev_name(dev);

Then this API feels comfortable:

struct adc *adc_get(struct device *dev, const char *channel);
void adc_put(struct adc *adc);
int adc_read_raw(struct adc *adc, int *val);

We can then add adc_read_voltage(), adc_read_temperature(), adc_read_foo() ...

Usage in say a hwmon driver or whatever:

struct adc *mr_adc = adc_get(dev, NULL);
/*
* Optional channel parameter used only when a single
* device use more than one channel, as with clock names
* or regulator names, so pass in NULL for the one channel
* tied to this device.
*/
ret = adc_read_raw(mr_adc, &val);
(...)
adc_put(mr_adc);

But this is just what looks useful to us.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/