IIO ADC example code for kernel driver

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

IIO ADC example code for kernel driver

跳至解决方案
1,092 次查看
Tony-FM-Eng
Contributor II

I am trying to set up several IIO ADC input channels through my kernel driver on a S32G2. I was wondering if there might be an example that I could follow?

I am not sure if I need to use the consumer functions under the 'include/linux/iio" directory to request and setup channels for the ADC? Once the channels are set up,
I would like to capture values on a regular bases through either polling or an interrupt and then write the values to my sysfs driver nodes.

Note, I could not find any examples for the S32G in any of the NXP Community forums or in the kernel documentation (kernel version 5.15).

Thanks for any assistance.

0 项奖励
回复
1 解答
963 次查看
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

We apologize for the delay. We have received the following update:

"

I don't see such example in our reference bsp and I think such dts configuration is not required in our design.

Please reference to S32G reference manual on SAR ADC to see that channels mapping to ADCs are fixed which we only need to configure corresponding register to enable/consume the data.

In bsp user manual, from the SAR-ADC chapter, you can also see the operation through sysfs to enable each channel and read through its corresponding ADC buffer. And those ADC_CH_# are not multi-function pins for dts configure either.

Customer can reference to our kernel driver "s32cc_adc.c" to implement their driver (or hook to it) if needed.

"

Please, let us know.

在原帖中查看解决方案

0 项奖励
回复
7 回复数
1,066 次查看
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

Can you let us know which BSP version are you working with?

Also, are you using any NXP reference board? Or is this a custom board?

Please, let us know.

0 项奖励
回复
1,039 次查看
Tony-FM-Eng
Contributor II

I am using BSP 39.0 with a custom board.

Also, looking through some of the documentation, in order to obtain an iio_channel, there needs to be an established iio_map? Is the iio_map already generated in Yocto, or is this something that is required to be setup in the board dts file?

0 项奖励
回复
1,020 次查看
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

Thanks for your feedback. On regards of the specific IIO topic, we understand that the default dts should be good enough.

As for ADC itself, the available examples are provided under the BSP39.0 User Manual for S32G2 platforms [BSP39.0 User Manual for S32G2 platforms]:

DanielAguirre_0-1719932262044.png

Please, let us know.

0 项奖励
回复
1,014 次查看
Tony-FM-Eng
Contributor II

Thanks for the update and the example, but this is from sysfs user space and not for a kernel driver. 

I am looking for an example that utilizes the dts file and references to obtaining data within the kernel driver. 

For reference, this is what I have tried without success:

 

In myboard.dts
 
Using this as a ROOT node?
   
&adc0 {
     #io-channel-cells = <1>;
     status = "okay";
     adc0_capture {status = "okay";
     compatible = "my-adc-driver";
     io-channels = <&adc0 3>;
};
 
Or using the following as a SOC node?
 
iio_map {
           ch0 {
                  nxp,adc-channel-number = <0x0>;
                  nxp,adc-consumer-device = "adc-input.1";
                  nxpi,adc-consumer-channel = "vin1";
            };
 
            ch1 {
                 nxp,adc-channel-number = <0x1>;
                 nxp,adc-consumer-device = "adc-input.2";
                 nxp,adc-consumer-channel = "vin2";
            };
};
 
 
In my_adc_driver.c:
 
// Get the instance of the channel from iio_map?
iio_channel *adc_vin1= iio_channel_get(&pdev->dev, "ch0");
 
// Read ADC value
ret = iio_read_channel_raw(adc_vin1, &value);

 

I'm not sure if I need a ROOT or a SOC node in myboard.dts file, and how to setup either? So, I am looking for an example on either, both for the dts and in the kernel driver file.

Thanks again for any additional assistance.

0 项奖励
回复
997 次查看
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

Thanks for your feedback. Overall, we understand that there are no examples on regards of kernel driver modifications, just the ones available under the BSP39.0 User Manual.

We will confirm with the related team if there is any information we might be missing.

We apologize for any delay from our side.

Please, let us know.

0 项奖励
回复
964 次查看
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

We apologize for the delay. We have received the following update:

"

I don't see such example in our reference bsp and I think such dts configuration is not required in our design.

Please reference to S32G reference manual on SAR ADC to see that channels mapping to ADCs are fixed which we only need to configure corresponding register to enable/consume the data.

In bsp user manual, from the SAR-ADC chapter, you can also see the operation through sysfs to enable each channel and read through its corresponding ADC buffer. And those ADC_CH_# are not multi-function pins for dts configure either.

Customer can reference to our kernel driver "s32cc_adc.c" to implement their driver (or hook to it) if needed.

"

Please, let us know.

0 项奖励
回复
794 次查看
Tony-FM-Eng
Contributor II
As per the suggestion, I decided to implement some of the ADC code from NXP's "s32cc_adc.c" Linux driver into my new driver.
0 项奖励
回复