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.

I2C board init for TI ADS7828 ADC

Other Parts Discussed in Thread: OMAP-L138, OMAPL138, ADS7828

I am trying to configure the kernel for initialization of the TI-ADS7828 ADC on I2C 0. I am connecting the device to the TI-LCDK running MCDK_1_01_00_02 with linux 3.3-psp03.22.00.06

I used menuconfig to include the TI-ADS7828 device driver.

I am having trouble with board initialization in arch/arm/mach-davinici/board-omapl138-lcdk.c. Is there any documentation on how to setup platform_data and how to register the board on I2C 0?

When I boot the kernel with these changes I do not have i2c-0 rgistered as /dev/i2c-0, /sys/class/i2c-adapter , or /sys/class/i2c-dev

Code that I added:

/* I2C0 PINMUX pins */
static short omapl138_i2c0_pins[] __initdata = {
 DA850_I2C0_SDA, DA850_I2C0_SCL, -1
};

static struct davinci_i2c_platform_data lcdk_i2c0_adc_pdata = {
        .bus_freq       = 100,  /* kHz */
        .bus_delay      = 0,    /* usec */
};

static struct i2c_board_info __initdata omapl138_lcdk_i2c0_devices[] = {
        // MWS added for TI 7823 ADC
        {
                I2C_BOARD_INFO("ads7828", 0x48),
        },
};


static void omapl138_lcdk_i2c_init(void)
{
        int ret;
        ret = davinci_cfg_reg_list(omapl138_i2c0_pins);
        if (ret) {
                pr_warn("omapl138_lcdk_init: i2c0 mux setup failed: %d\n", ret);
                return;
        }

        // Init I2C
        ret = da8xx_register_i2c(0, &lcdk_i2c0_adc_pdata);
        if (ret) {
                pr_warning("omapl138_lcdk_init: i2c0 registration failed: %d\n", ret);
                return;
        }

        i2c_register_board_info(0, omapl138_lcdk_i2c0_devices,
                        ARRAY_SIZE(omapl138_lcdk_i2c0_devices));
}

  • Dear MattS,
    What error you are getting while I2C init from linux boot log ?
    You don't have any other I2C slave devices on I2C bus 0 ?
    Able to detect the 0x48 I2C slave device on bus 0 through "i2cdetect" ?
    Please attach the bootup log.
  • Hello Titus,

    >What error you are getting while I2C init from linux boot log ?

    I do not receive any I2C init errors during boot. I have attached my boot log below for reference.

    >You don't have any other I2C slave devices on I2C bus 0 ?

    No, there are no other devices connected on I2C bus 0. I am using the stock board-omapl138-lcdk.c (with changes identified above for I2C 0 initialization).

    >Able to detect the 0x48 I2C slave device on bus 0 through "i2cdetect" ?

    I can not run i2cdetect because i2c0 is not available. I suspect I am missing something in board-omapl138-lcdk.c to fully initialize i2c0. Shell command ls /dev/i2* results in:

    root@omapl138-lcdk:~# ls /dev/i2*
    /dev/i2c-1

    root@omapl138-lcdk:~# i2cdetect -l
    i2c-1 i2c DaVinci I2C adapter I2C adapter
    root@omapl138-lcdk:~#



    >Please attach the bootup log.
    I have attached my boot log below for reference.






    The system is going down for reboot NOW!k (ttyS2) (Tue Dec 17 03:01:07 2013):
    INIT: Switching to runlevel: 6
    INIT: Sending processes the TERM signal
    INIT: Sending processes thStopping Dropbear SSH server: stopped /usr/sbin/dropbear (pid 670)
    dropbear.
    Stopping telnet daemon.
    Stopping system message bus: Error opening /dev/fb0: No such file or directory
    Stopping syslogd/klogd: stopped syslogd (pid 686)
    stopped klogd (pid 688)
    done
    Stopping thttpd.
    ALSA: Storing mixer settings...
    /usr/sbin/alsactl: save_state:1580: No soundcards found...
    NOT deconfiguring network interfaces: / is an NFS mount
    ***************************************************************
    ***************************************************************
    NOTICE: This file system contains the followin GPLv3 packages:
    gdbserver

    If you do not wish to distribute GPLv3 components please remove
    the above packages prior to distribution. This can be done using
    the opkg remove command. i.e.:
    opkg remove <package>
    Where <package> is the name printed in the list above

    NOTE: If the package is a dependency of another package you
    will be notified of the dependent packages. You should
    use the --force-removal-of-dependent-packages option to
    also remove the dependent packages as well
    ***************************************************************
    ***************************************************************
    Sending all processes the TERM signal...
    Sending all processes the KILL signal...
    Unmounting remote filesystems...
    Deactivating swap...
    Unmounting local filesystems...
    Rebooting... Restarting system.
    NAND: 512 MiB
    MMC: davinci: 0
    Bad block table found at page 262080, version 0x01
    Bad block table found at page 262016, version 0x01
    nand_bbt: ECC error while reading bad block table
    nand_read_bbt: Bad block at 0x000012980000
    In: serial
    Out: serial
    Err: serial
    Net: DaVinci-EMAC
    Hit any key to stop autoboot: 0
    BOOTP broadcast 1
    DHCP client bound to address 192.168.5.152
    Using DaVinci-EMAC device
    TFTP from server 192.168.2.65; our IP address is 192.168.5.152
    Filename 'uImage-omapl138-lcdk.bin'.
    Load address: 0xc0700000
    Loading: #################################################################
    #################################################################
    #################################################################
    #################################################################
    #################################################################
    #################################################################
    ##############
    done
    Bytes transferred = 2064080 (1f7ed0 hex)
    ## Booting kernel from Legacy Image at c0700000 ...
    Image Name: Linux-3.3.0
    Image Type: ARM Linux Kernel Image (uncompressed)
    Data Size: 2064016 Bytes = 2 MiB
    Load Address: c0008000
    Entry Point: c0008000
    Verifying Checksum ... OK
    Loading Kernel Image ... OK
    OK

    Starting kernel ...

    Uncompressing Linux... done, booting the kernel.
    Booting Linux on physical CPU 0
    Linux version 3.3.0 (tilcdk@matt-XPS-8700) (gcc version 4.5.3 20110311 (prerelease) (GCC) ) #124 PREEMPT Fri Dec 4 16:01:34 EST 2015
    CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
    CPU: VIVT data cache, VIVT instruction cache
    Machine: AM18x/OMAP-L138 lcdk board
    Memory policy: ECC disabled, Data cache writeback
    BUG: mapping for 0x80000000 at 0xfffe0000 out of vmalloc space
    DaVinci da850/omap-l138/am18x variant 0x1
    Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
    Kernel command line: console=ttyS2,115200n8 rw noinitrd root=/dev/nfs nfsroot=192.168.2.65:/home/tilcdk/ti/mcsdk_1_01_00_02/targetNFS,nolock,rsize=1024,w
    size=1024 ip=dhcp
    PID hash table entries: 512 (order: -1, 2048 bytes)
    Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
    Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
    Memory: 128MB = 128MB total
    Memory: 125556k/125556k available, 5516k reserved, 0K highmem
    Virtual kernel memory layout:
    vector : 0xffff0000 - 0xffff1000 ( 4 kB)
    fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
    vmalloc : 0xc8800000 - 0xff000000 ( 872 MB)
    lowmem : 0xc0000000 - 0xc8000000 ( 128 MB)
    modules : 0xbf000000 - 0xc0000000 ( 16 MB)
    .text : 0xc0008000 - 0xc03d7000 (3900 kB)
    .init : 0xc03d7000 - 0xc03fc000 ( 148 kB)
    .data : 0xc03fc000 - 0xc0424f40 ( 164 kB)
    .bss : 0xc0424f64 - 0xc043e9a4 ( 103 kB)
    SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
    NR_IRQS:245
    Console: colour dummy device 80x30
    Calibrating delay loop... 148.88 BogoMIPS (lpj=744448)
    pid_max: default: 32768 minimum: 301
    Mount-cache hash table entries: 512
    CPU: Testing write buffer coherency: ok
    Setting up static identity map for 0xc02ee910 - 0xc02ee968
    gpiochip_add: registered GPIOs 0 to 31 on device: DaVinci
    gpiochip_add: registered GPIOs 32 to 63 on device: DaVinci
    gpiochip_add: registered GPIOs 64 to 95 on device: DaVinci
    gpiochip_add: registered GPIOs 96 to 127 on device: DaVinci
    gpiochip_add: registered GPIOs 128 to 143 on device: DaVinci
    DaVinci: 144 gpio irqs
    print_constraints: dummy:
    NET: Registered protocol family 16
    EMAC: MII PHY configured
    bio: create slab <bio-0> at 0
    SCSI subsystem initialized
    Switching to clocksource timer0_1
    NET: Registered protocol family 2
    IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
    TCP established hash table entries: 4096 (order: 3, 32768 bytes)
    TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
    TCP: Hash tables configured (established 4096 bind 4096)
    TCP reno registered
    UDP hash table entries: 256 (order: 0, 4096 bytes)
    UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
    NET: Registered protocol family 1
    RPC: Registered named UNIX socket transport module.
    RPC: Registered udp transport module.
    RPC: Registered tcp transport module.
    RPC: Registered tcp NFSv4.1 backchannel transport module.
    JFFS2 version 2.2. (NAND) ▒© 2001-2006 Red Hat, Inc.
    msgmni has been set to 245
    io scheduler noop registered (default)
    Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
    serial8250.0: ttyS0 at MMIO 0x1c42000 (irq = 25) is a AR7
    serial8250.0: ttyS1 at MMIO 0x1d0c000 (irq = 53) is a AR7
    serial8250.0: ttyS2 at MMIO 0x1d0d000 (irq = 61) is a AR7
    console [ttyS2] enabled
    brd: module loaded
    NAND device: Manufacturer ID: 0x2c, Chip ID: 0xcc (Micron NAND 512MiB 3,3V 16-bit)
    Bad block table found at page 262080, version 0x01
    Bad block table found at page 262016, version 0x01
    nand_read_bbt: bad block at 0x000012980000
    Creating 4 MTD partitions on "davinci_nand.1":
    0x000000000000-0x000000020000 : "u-boot env"
    0x000000020000-0x0000000a0000 : "u-boot"
    0x0000000a0000-0x0000002a0000 : "kernel"
    0x0000002a0000-0x000020000000 : "filesystem"
    davinci_nand davinci_nand.1: controller rev. 2.5
    davinci_mdio davinci_mdio.0: davinci mdio revision 1.5
    davinci_mdio davinci_mdio.0: detected phy mask ffffff7f
    davinci_mdio.0: probed
    davinci_mdio davinci_mdio.0: phy[7]: device davinci_mdio-0:07, driver SMSC LAN8710/LAN8720
    input: gpio-keys-polled as /devices/platform/gpio-keys-polled.0/input/input0
    omap_rtc omap_rtc: rtc core: registered omap_rtc as rtc0
    omap_rtc: RTC power up reset detected
    omap_rtc: already running
    i2c /dev entries driver
    watchdog watchdog: heartbeat 60 sec
    cpuidle: using governor ladder
    cpuidle: using governor menu
    davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode
    nf_conntrack version 0.5.0 (1961 buckets, 7844 max)
    TCP cubic registered
    NET: Registered protocol family 17
    console [netcon0] enabled
    netconsole: network logging started
    davinci_emac davinci_emac.1: using random MAC addr: 26:cc:7a:45:32:a2
    omap_rtc omap_rtc: setting system clock to 2013-12-17 03:01:38 UTC (1387249298)
    davinci_mdio davinci_mdio.0: resetting idled controller
    net eth0: attached PHY driver [SMSC LAN8710/LAN8720] (mii_bus:phy_addr=davinci_mdio-0:07, id=7c0f1)
    PHY: davinci_mdio-0:07 - Link is Up - 100/Full
    Sending DHCP requests ., OK
    IP-Config: Got DHCP answer from 0.0.0.0, my address is 192.168.5.141
    IP-Config: Complete:
    device=eth0, addr=192.168.5.141, mask=255.255.240.0, gw=192.168.2.1,
    host=192.168.5.141, domain=, nis-domain=(none),
    bootserver=0.0.0.0, rootserver=192.168.2.65, rootpath=
    VFS: Mounted root (nfs filesystem) on device 0:13.
    Freeing init memory: 148K
    INIT: version 2.88 booting
    Error opening /dev/fb0: No such device or address
    Starting udev
    ip_tables: (C) 2000-2006 Netfilter Core Team
    Starting Bootlog daemon: bootlogd.
    ALSA: Restoring mixer settings...
    NOT configuring network interfaces: / is an NFS mount
    /usr/sbin/alsactl: load_state:1686: No soundcards found...
    INIT: Entering runlevel: 5
    Starting system message bus: dbus.
    Starting Dropbear SSH server: NET: Registered protocol family 10
    dropbear.
    Starting telnet daemon.
    Starting syslogd/klogd: done
    Starting thttpd.
    ***************************************************************
    ***************************************************************
    NOTICE: This file system contains the followin GPLv3 packages:
    gdbserver

    If you do not wish to distribute GPLv3 components please remove
    the above packages prior to distribution. This can be done using
    the opkg remove command. i.e.:
    opkg remove <package>
    Where <package> is the name printed in the list above

    NOTE: If the package is a dependency of another package you
    will be notified of the dependent packages. You should
    use the --force-removal-of-dependent-packages option to
    also remove the dependent packages as well
    ***************************************************************
    ***************************************************************
    Stopping Bootlog daemon: bootlogd.

    _____ _____ _ _
    | _ |___ ___ ___ ___ | _ |___ ___ |_|___ ___| |_
    | | _| .'| . | . | | __| _| . | | | -_| _| _|
    |__|__|_| |__,|_ |___| |__| |_| |___|_| |___|___|_|
    |___| |___|

    Arago Project http://arago-project.org omapl138-lcdk ttyS2

    Arago 2013.05 omapl138-lcdk ttyS2

  • I removed my "custom code" above to configure I2C-0 leaving the GPIO based I2C configuration in board-omapl138-lcdk.c. This configures GPIO1[4] as SDA pin and GPIO1[5] as SCL pin. These pins are registered as I2C-1. Using this interface on I2C-1 I am able to probe the bus to see the TI-7823 and TI-7828 on the bus. My next step is to connect an analog input on one of the channels to make sure I can properly interact with the ADC device over I2C.


    root@omapl138-lcdk:~# i2cdetect -r 1
    WARNING! This program can confuse your I2C bus, cause data loss and worse!
    I will probe file /dev/i2c-1 using read byte commands.
    I will probe address range 0x03-0x77.
    Continue? [Y/n] y
    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- 48 -- -- UU -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- 5d -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --
    root@omapl138-lcdk:~#

    572 static struct i2c_board_info __initdata omapl138_lcdk_i2c_devices[] = {
    573         {
    574                 I2C_BOARD_INFO("tlv320aic3x", 0x18),
    575         },
    576 };
    577
    578 static struct i2c_gpio_platform_data da850_gpio_i2c_pdata = {
    579         .sda_pin        = GPIO_TO_PIN(1, 4),
    580         .scl_pin        = GPIO_TO_PIN(1, 5),
    581         .udelay         = 2,                    /* 250 KHz */
    582 };
    583
    584 static struct platform_device da850_gpio_i2c = {
    585         .name           = "i2c-gpio",
    586         .id             = 1,
    587         .dev            = {
    588                 .platform_data  = &da850_gpio_i2c_pdata,
    589         },
    590 };
    591
    592 static void omapl138_lcdk_i2c_init(void)
    593 {
    594         int ret;
    595         ret = davinci_cfg_reg_list(da850_i2c0_pins);
    596         if (ret)
    597                 pr_warn("omapl138_lcdk_init: i2c0 mux setup failed: %d\n",
    598                                 ret);
    599
    600         platform_device_register(&da850_gpio_i2c);
    601
    602         if (ret)
    603                 pr_warn("omapl138_lcdk_init: i2c0 registration failed: %d\n",
    604                                 ret);
    605         i2c_register_board_info(1, omapl138_lcdk_i2c_devices,
    606                         ARRAY_SIZE(omapl138_lcdk_i2c_devices));
    607 }
    

  • Dear MattS,
    Sorry for the delayed response on this.

    We did I2C GPIO bitbang (GPIO lines as I2C lines) in LCDK board file.

    Yes, i2c0 will detect as i2c1 in user space.

    You can just change the code like below.

    static struct i2c_board_info __initdata omapl138_lcdk_i2c_devices[] = {
    {
    I2C_BOARD_INFO("tlv320aic3x", 0x18),
    I2C_BOARD_INFO("ads7828", 0x48),
    },
    };


    If you want i2c ID as 0, then do the following and check.

    584 static struct platform_device da850_gpio_i2c = {
    585 .name = "i2c-gpio",
    586 .id = 0, //1
    587 .dev = {
    588 .platform_data = &da850_gpio_i2c_pdata,
    589 },
    590 };

    Please let me know if any help.