This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Device Tree and Device Driver as IIO Consumer - Kernel (3.14)



Folks,

I'm trying to develop a device driver in which is going to read an AD channel from am335x.

I've tried to use the DT configuration as shown here:
lxr.free-electrons.com/.../iio-bindings.txt

But when I use "iio_channel_get" function no channel is returned.

I supposed that ti_am335x_adc.c driver is not mapping the iio channels.

Is there another way to parse from DT and read an adc channel from the device driver?

  • Sorry, but it does not helps.

    This is for reading the ADC from userspace.

    I need to read ADC values from a device driver.
  • Hi Diego,

    I am also attempting to read the ADC from within the Kernel. I eventually was able to read the ADC via the IIO Consumer driver.

    I added the following to my device tree.

    /* Enable all the ADC Channels */
    &tscadc {
    	status = "okay";	
    	adc {
    		ti,adc-channels = < 0 1 2 3 4 5 6 >;
    	};	
    };
    .
    .
    .
    iio_adc_consumer{
    		compatible ="iio_adc_consumer_test";
    		io-channels = <&am335x_adc 0>, <&am335x_adc 1>, <&am335x_adc 2>, <&am335x_adc 3>, <&am335x_adc 4>, <&am335x_adc 5>, <&am335x_adc 6>;
    		io-channel-names = "AIN0", "AIN1", "AIN2", "AIN3", "AIN4", "AIN5", "AIN6";
    };

    Then in my kernel device driver the following code.

    static int iio_consumer_probe(struct platform_device *pdev)
    {
    	struct iio_channel *adc_channel = NULL;
    	int ret, val;
    
    	adc_channel = iio_channel_get(&pdev->dev, "AIN0");
    	ret = iio_read_channel_raw(adc_channel, &val);
    	printk(KERN_INFO "ret = %d val = %d \n", ret, val);
    	iio_channel_release(adc_channel);
    
    	adc_channel = iio_channel_get(&pdev->dev, "AIN1");
    	ret = iio_read_channel_raw(adc_channel, &val);
    	printk(KERN_INFO "ret = %d val = %d \n", ret, val);
    	
    	adc_channel = iio_channel_get(&pdev->dev, "AIN2");
    	ret = iio_read_channel_raw(adc_channel, &val);
    	printk(KERN_INFO "ret = %d val = %d \n", ret, val);int 
    
    	adc_channel = iio_channel_get(&pdev->dev, "AIN3");
    	ret = iio_read_channel_raw(adc_channel, &val);
    	printk(KERN_INFO "ret = %d val = %d \n", ret, val);
    
    	return 0;
    }