Hello,
I find an "adc" device by the following code:
struct device dev;
static int custom_match_dev(struct device *dev, const void *data)
{
// this function implements the comaparison logic. Return not zero if found.
const char *name = data;
int result = 0;
if (dev == NULL)
return result;
if (dev->of_node == NULL)
return result;
if (dev->of_node->name == NULL)
return result;
result = sysfs_streq(name, dev->of_node->name);
return result;
}
static struct device *find_dev(const char *name)
{
struct device *dev = NULL;
dev = bus_find_device(&platform_bus_type, NULL, name, custom_match_dev);
return dev;
}
and there is an "adc" here:
~# cat /sys/bus/platform/devices/TI-am335x-adc.2.auto/of_node/name
adc
~# ls /sys/bus/platform/devices/TI-am335x-adc.2.auto/of_node/
#io-channel-cells compatible name ti,adc-channels
~# ls /sys/bus/platform/devices/TI-am335x-adc.2.auto
driver iio:device0 of_node subsystem
driver_override modalias power uevent
~# ls /sys/bus/iio/devices/iio\:device0/
buffer/ in_voltage2_raw in_voltage6_raw power/
dev in_voltage3_raw in_voltage7_raw scan_elements/
in_voltage0_raw in_voltage4_raw name subsystem/
in_voltage1_raw in_voltage5_raw of_node/ uevent
When I try to get the iio channels with devm_IIo_channel_get or
devm_IIo_channel_get_all.
I always get -19 answer (no such device). I also tried the iio_channel_get and iio_channel_get_all and the result is same.
struct iio_channel *channels;
channels = iio_channel_get(dev, "iio:device0");
if (IS_ERR(channels))
{
printk(KERN_ERR "channels: %d\n", (int)channels);
//return 0;
return PTR_ERR(channels);
}
At the iio_channel_get second parameter I tried various stings like channel number and other strings I found under /sys/bus/iio.... and path above.
What is wrong with this code?
Please give me any advice how I read adc channels in kernel space.
Thank you in advance.
Roland Dobak