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.

ADC DTS file

Hi,

am writing my own driver adc for reading all channels data ,

so how to implement my driver with dts file and how i will get interrupts

when i call request_irq in character driver the handler will not call ,

am assign 16 number interrupt ,this way is correct or any other method to interrupt request

please reply me its urgent .

**  begal bone balck ,ti processor,sdk 7

Thanks & Regards,

Naveen

  • You already have opened at least two threads on this topic. Please post on the original threads, so that you can reach people who replied to you. I am closing this thread now.

  • Hi Naveen,

    Are you looking for a ready to use dts node for the ADC?
    If so, you can adopt the adc device tree node from the current dts files: am33xx.dtsi :
    tscadc: tscadc@44e0d000 {
    compatible = "ti,am3359-tscadc";
    reg = <0x44e0d000 0x1000>;
    interrupt-parent = <&intc>;
    interrupts = <16>;
    ti,hwmods = "adc_tsc";
    clocks = <&adc_tsc_fck>;
    clock-names = "fck";
    status = "disabled";

    tsc {
    compatible = "ti,am3359-tsc";
    };
    am335x_adc: adc {
    #io-channel-cells = <1>;
    compatible = "ti,am3359-adc";
    };
    };

    And then in your specific dts file, for beaglebone black that is am335x-boneblack.dts, you should just enable it:
    &tscadc {
    status = "okay";
    tsc {
    ti,wires = <4>;
    ti,x-plate-resistance = <200>;
    ti,coordinate-readouts = <5>;
    ti,wire-config = <0x00 0x11 0x22 0x33>;
    };
    };
    Since you use the the gpio expansion headers, you could remove accordingly the tsc parts from your code.

    Hope this helps.

    Best Regards,
    Yordan
  • Also change the compatible = "ti,am3359-adc"; & compatible = "ti,am3359-tscadc"; parts in the code to point your custom driver, NOT the default TI driver.
    The following wiki may also be of help to you: processors.wiki.ti.com/.../AM335x_ADC_Driver%27s_Guide
    Best Regards,
    Yordan
  • HI Yordan,

    am change my dts file according to your suggestions,
    calling request_irq in my driver ,this function execute without error,
    but interrupt handler not called ,

    cat /proc/interrupts

    16: 0 INTC 0 adcsample

    my interrupt request :
    request_irq(16,adc_irq_handler,0,"adcsample",NULL);

    can u suggest any other method but interrupt count will be 0



    Regards,
    Naven
  • Hi Yodan,

    am change in device tree compatible name ,but mapping will be fail,
    i try to print device name ,irq number, and address but device name will print wrong

    Irq_number = 32
    res->start = 44e0d000
    resource_size(res) = 1000
    pdev->name = 44e0d000.tscadc
    ADC_DRIVER 44e0d000.tscadc: failed to map registers.
    ADC_DRIVER: probe of 44e0d000.tscadc failed with error -12

    the device name will print different way and mapping will be fail,
    so can u suggest me how can i solve this problem.

    Regards,
    Naven
  • Hi Naven,

    The firs error message, reporting fail to map registers:

    p naveen kumar said:
    ADC_DRIVER 44e0d000.tscadc: failed to map registers.

    Indicates that your kernel still uses the drivers/mfd/ti_am335x_tscadc.c driver (default ti touchscreen_adc controller driver) the message comes from the bellow fragment of code:
        tscadc->tscadc_base = devm_ioremap(&pdev->dev,
                res->start, resource_size(res));
        if (!tscadc->tscadc_base) {
            dev_err(&pdev->dev, "failed to map registers.\n");
            return -ENOMEM;
        }

    Can you put some debug printks in your driver to be sure that it is built in the kernel? If not, try adding it to tisdk_am335x-evm_defconfig file.

    Also can you post the modified device tree structures for the ADC?


    Best Regards,

    Yordan

  • Hi Yordan,


      ***********  am33xx.dtsi ********************************

     tscadc: tscadc@44e0d000 {
                compatible = "ti,adcsample";
                 reg = <0x44e0d000 0x1000>;
                 interrupt-parent = <&intc>;
                 interrupts = <16>;
                 ti,hwmods = "adc_tsc";
                 clocks = <&adc_tsc_fck>;
                 clock-names = "fck";
                 status = "disabled";

               am335x_adc: adc {
                       #io-channel-cells = <1>;
                       compatible = "ti,adcsample";
                 };
           };

    **************************   am335x-evm.dts ***************************************

    &tscadc {
        status = "okay";
        tsc {
            ti,wires = <4>;
            ti,x-plate-resistance = <200>;
            ti,coordinate-readouts = <5>;
            ti,wire-config = <0x00 0x11 0x22 0x33>;
        };

        adc {
             ti,adc-channels = <4 5 6 7>;
        };

    };

    ******************** my driver *******************************************

     static const struct of_device_id ti_tscadc_dt_ids[] = {
             { .compatible = "ti,adcsample",  },
                 { }
     };
    *****************************************************************************

    but the problem is not created proper dts file ,

    my quistion is sample character driver enable all adc registers etc ,but how my character driver add with dts file ??

    u told that change in dts file according my driver so same way i change but it not work properly

    may be iam doing any mistake ,please give me sujestion and is the way is correct and any changes need ??

    Thanks & Regards,

    Naven

  • Hi Naven,

    Sorry for the delayed response.

    DTS configuration looks ok. Have you added adcsample.c driver it to the kernel sources, as described here: stackoverflow.com/.../adding-new-driver-code-to-linux-source-code, so that it can be properly compiled within your kernel (as a module or directly built in the kernel image)?

    Best Regards,
    Yordan
  • Hi Yordan,

    Thanks for reply and i solve the interrupt problem ,i hard coded 32 number in request_irq first argument,

    so the handler will call . but the problem is reading data from fifo is not proper values the only channel 7 value will be

    correct but remaining values will get wrong but i did not understand wats problem my register configuration

    i sending my registers  configuration and log file check once .

    Register Configuration :

    clk_div = 0x4;
    iowrite32(clk_div, base_addr + ADC_CLKDIV);

    cntl = ioread32(base_addr + CTRL);
    cntl = cntl | (1 << 1);                       //TSC ADC tags
    cntl = cntl | (1 << 2);                       //disable write protect
    iowrite32(cntl,base_addr + CTRL);

    stpcnfg = stpcnfg |(0x8 << 15);               // SEL_INM pin
    stpcnfg = stpcnfg |(0x6 << 19);               // SEL_INP pins SW configuration
    stpcnfg = stpcnfg |(0x4 << 2);                // average 16 samples
    iowrite32(stpcnfg,base_addr + STEPCONFIG1);   //stepconfig 1

    cntl = cntl | 1;                          // enable TSC_ADC_SS
    iowrite32(cntl,base_addr + CTRL);

    iowrite32(0x2, base_addr + STEPENABLE); //step enable

    printk("FIF_DATA = %d\n",((ioread32(base_addr + 0x100)& 0xFFF)));

    Log File :

    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   61.536156] FIF_DATA = 3390
    val =0 t=:3.459583 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   63.836797] FIF_DATA = 1161
    val =0 t=:3.458542 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   65.466063] FIF_DATA = 337
    val =0 t=:3.372791 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   66.535943] FIF_DATA = 3522
    val =0 t=:3.449333 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   67.805611] FIF_DATA = 1009
    val =0 t=:3.499917 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   69.105865] FIF_DATA = 3890
    val =0 t=:3.445125 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   70.975969] FIF_DATA = 3911
    val =0 t=:3.461083 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   72.246909] FIF_DATA = 404
    val =0 t=:3.389166 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   73.865814] FIF_DATA = 3930
    val =0 t=:3.458708 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   75.016007] FIF_DATA = 675
    val =0 t=:3.363375 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   76.426743] FIF_DATA = 3773
    val =0 t=:3.572292 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   77.895956] FIF_DATA = 64
    val =0 t=:3.273667 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   79.055918] FIF_DATA = 736
    val =0 t=:3.359708 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   80.205874] FIF_DATA = 1591
    val =0 t=:3.455333 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   81.185897] FIF_DATA = 2934
    val =0 t=:3.449542 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   82.605838] FIF_DATA = 2273
    val =0 t=:3.452458 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    [   83.985919] FIF_DATA = 3764

    Thanks & Regards,

    Naven

  • devmem2 read log :

    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# . ./read_reg.sh
    /dev/mem opened.
    Memory mapped at address 0xb6f49000.
    Read at address 0x44E0D010 (0xb6f49010): 0x0000000C
    /dev/mem opened.
    Memory mapped at address 0xb6ff7000.
    Read at address 0x44E0D024 (0xb6ff7024): 0x00000112
    /dev/mem opened.
    Memory mapped at address 0xb6f4f000.
    Read at address 0x44E0D028 (0xb6f4f028): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f25000.
    Read at address 0x44E0D02C (0xb6f2502c): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6fbe000.
    Read at address 0x44E0D030 (0xb6fbe030): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6fbf000.
    Read at address 0x44E0D034 (0xb6fbf034): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6fe9000.
    Read at address 0x44E0D040 (0xb6fe9040): 0x00000007
    /dev/mem opened.
    Memory mapped at address 0xb6fb1000.
    Read at address 0x44E0D044 (0xb6fb1044): 0x00000010
    /dev/mem opened.
    Memory mapped at address 0xb6fea000.
    Read at address 0x44E0D048 (0xb6fea048): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6feb000.
    Read at address 0x44E0D04C (0xb6feb04c): 0x00000004
    /dev/mem opened.
    Memory mapped at address 0xb6f68000.
    Read at address 0x44E0D050 (0xb6f68050): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6fce000.
    Read at address 0x44E0D054 (0xb6fce054): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6fb9000.
    Read at address 0x44E0D058 (0xb6fb9058): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f73000.
    Read at address 0x44E0D064 (0xb6f73064): 0x002C0010
    /dev/mem opened.
    Memory mapped at address 0xb6fc0000.
    Read at address 0x44E0D068 (0xb6fc0068): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f79000.
    Read at address 0x44E0D0E4 (0xb6f790e4): 0x0000007D
    /dev/mem opened.
    Memory mapped at address 0xb6fdb000.
    Read at address 0x44E0D0E8 (0xb6fdb0e8): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f46000.
    Read at address 0x44E0D100 (0xb6f46100): 0x00000C74
  • Hi Naven,

    Thanks for posting the register dump. I will check it and come back with my feedback, if I find something wrong with your settings.

    Best Regards,
    Yordan
  • Hi,

    I checked the register values, and my initial comments are:

    - Read at address 0x44E0D024 (0xb6ff7024): 0x00000112:  Means that you have End_of_Sequence, FIFO0_Underflow & Out_of_Range interrupt events pending. See description of the raw status register (IRQSTATUS_RAW).

    - On the other hand  

     Read at address 0x44E0D028 (0xb6f4f028): 0x00000000  (IRQSTATUS register)

     Read at address 0x44E0D02C (0xb6f2502c): 0x00000000  (IRQENABLE_SET register)

    Show that neither of these interrupt events (indicated in IRQSTATUS_RAW)  are enabled in your setup. Try using IRQENABLE_SET to enable the corresponding interrupt events & see Section 12.3.5 Interrupts in AM335x TRM for description on how to process them.

    - Read at address 0x44E0D040 (0xb6fe9040): 0x00000007

      Try writing 0x00000027 in CTRL register.  This should utilize the AFE (in 4 wire mode).  Note that when setting bits [6:5]AFE_Pen_Ctrl User also needs to make sure the ground path is connected properly for pen interrupt to occur (using the StepConfig registers).

    - Read at address 0x44E0D044 (0xb6fb1044): 0x00000010: indicates that ADCSTAT[4:0]STEP_ID = 0x10 =>  Idle. Again check Section 12.3.5 Interrupts in TRM.  Reading Idle means that you need to restart the ADC.

    - Read at address 0x44E0D04C (0xb6feb04c): 0x00000004 => Try using lower clock, i.e. ADC_CLKDIV[15:0] ADC_ClkDiv is set to 0x7 in TI SDK8.0

    - Read at address 0x44E0D064 (0xb6f73064): 0x002C0010: means that you've set your adc in HW synchronized, one-shot mode.  Try using continuous mode (SW or HW), see Section 12.3.4 One-Shot (Single) or Continuous Mode in AM335x TRM.  

    - Read at address 0x44E0D0E8 (0xb6fdb0e8): 0x00000000: Program some FIFO Threshold. 0x0 means that your adc module will immediately start sending interrupts. Again see  Section 12.3.5 Interrupts for details.

    Hope this helps.

    Best Regards,

    Yordan

  • Hi Sir,

    i change register values as per your suggestion ,The FIFO reading some values
    i change all channels like 3,4,5,6 etc . but reading same values
    but my confusion is all pins are open but how this values reading FIFO,
    any changes need in registers or this values is correct.

    my console data : channel ,3,4,5,6
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =1885 t=:0.013708 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =1885 t=:0.014083 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =1884 t=:0.012833 ms

    channel 7 :
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =2420 t=:0.012875 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =2423 t=:0.013292 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =2421 t=:0.013500 ms

    Register settings :

    clk_div = 0x7;
    iowrite32(clk_div, base_addr + ADC_CLKDIV);

    cntl = cntl | (1 << 1); //TSC ADC tags
    cntl = cntl | (1 << 2); //disable write protect
    iowrite32(cntl,base_addr + CTRL);

    stpcnfg = stpcnfg |(0x8 << 15); // SEL_INM pin
    stpcnfg = stpcnfg |(0x7 << 19); // SEL_INP pins SW configuratio
    stpcnfg = stpcnfg |(0x3 << 2); // average 16 samples
    stpcnfg = stpcnfg |(1 << 0); //Continous mode
    iowrite32(stpcnfg,base_addr + STEPCONFIG1); //stepconfig 1

    iowrite32(0x0, base_addr + 0xE8); //FIFO0_THRESHOLD Register

    iowrite32(0,base_addr + 0x2C);
    irqcnfg = ioread32(base_addr + 0x2C);
    irqcnfg = irqcnfg | (1 << 1); //End_of_sequence
    irqcnfg = irqcnfg | (1 << 2); //FIF_0 Threshold
    iowrite32( irqcnfg,base_addr + 0x2C);

    iowrite32(0x2, base_addr + STEPENABLE);

    int cntl = ioread32(base_addr + CTRL);
    cntl = cntl | 1; // enable TSC_ADC_SS
    cntl = cntl | (1 << 5); //AFE_PEN_Ctrl
    iowrite32(cntl,base_addr + CTRL);

    devmem2 log file :
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# . ./read_reg.sh
    /dev/mem opened.
    Memory mapped at address 0xb6fc8000.
    Read at address 0x44E0D010 (0xb6fc8010): 0x0000000C
    /dev/mem opened.
    Memory mapped at address 0xb6fc5000.
    Read at address 0x44E0D024 (0xb6fc5024): 0x0000001A
    /dev/mem opened.
    Memory mapped at address 0xb6fe7000.
    Read at address 0x44E0D028 (0xb6fe7028): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f1c000.
    Read at address 0x44E0D02C (0xb6f1c02c): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6fd3000.
    Read at address 0x44E0D030 (0xb6fd3030): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f58000.
    Read at address 0x44E0D034 (0xb6f58034): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f47000.
    Read at address 0x44E0D040 (0xb6f47040): 0x00000027
    /dev/mem opened.
    Memory mapped at address 0xb6f44000.
    Read at address 0x44E0D044 (0xb6f44044): 0x00000020
    /dev/mem opened.
    Memory mapped at address 0xb6f45000.
    Read at address 0x44E0D048 (0xb6f45048): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f12000.
    Read at address 0x44E0D04C (0xb6f1204c): 0x00000007
    /dev/mem opened.
    Memory mapped at address 0xb6f71000.
    Read at address 0x44E0D050 (0xb6f71050): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6ff8000.
    Read at address 0x44E0D054 (0xb6ff8054): 0x00000002
    /dev/mem opened.
    Memory mapped at address 0xb6fdb000.
    Read at address 0x44E0D058 (0xb6fdb058): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6ff4000.
    Read at address 0x44E0D064 (0xb6ff4064): 0x0034000D
    /dev/mem opened.
    Memory mapped at address 0xb6f1d000.
    Read at address 0x44E0D068 (0xb6f1d068): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f80000.
    Read at address 0x44E0D0E4 (0xb6f800e4): 0x0000000E
    /dev/mem opened.
    Memory mapped at address 0xb6ff1000.
    Read at address 0x44E0D0E8 (0xb6ff10e8): 0x00000000
    /dev/mem opened.
    Memory mapped at address 0xb6f4c000.
    Read at address 0x44E0D100 (0xb6f4c100): 0x00000761



    Thanks & Regards,
    Naven.
  • Testing channel 6 : input voltage 1.2v

    o/p log :



    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =12 t=:0.013000 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =14 t=:0.013500 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =12 t=:0.013167 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =6 t=:0.011750 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =15 t=:0.012792 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =9 t=:0.012417 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =9 t=:0.012583 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =8 t=:0.011834 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =2404 t=:0.014375 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =4095 t=:0.012750 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =3933 t=:0.011333 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =254 t=:0.012459 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =4095 t=:0.013458 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test
    val =3709 t=:0.012791 ms
    root@am335x-evm:/lib/modules/3.12.10-ti2013.12.01# ./adc_test