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.

SPI BASED GPIO EXPANDER

Hi,


Just some suggestions I need for my GPIO Expander Driver.


I have just written a working driver for my GPIO expander in Linux Kernel 2.6.37

The suggestions I need are during my probe function I use the spi write routines to configure IO of the expander.

When I use the subsys_initcall for the driver registration the SPI routines do not work properly but when i use late_initcall all seems to work fine.

The thing I would like to know is that I thought I would register the driver first and then do the init of IO's the last thing in my board file. But what happens is that when i use the gpio_set_value or any other gpio routine it gets executed first thing before my driver is registered in which case the GPIO is invalid. How do I specify in my board file that request some gpio's when my IO expander driver has registered.

Thanks for your help.


Ali

  • Hello Muhammad,

    Could you provide us more information about your SPI IO expander?

    lxr.free-electrons.com/.../gpio-mcp23s08.c

    See a similar thread e2e.ti.com/.../368940

    Best regards,
    Yanko
  • Hi Yanko,

    The thread you have referred to was me when I started writing the driver a while back.

    I am using XRA1405 and Linux Kernel 2.6.37

    I register spi based XRA1405 in by board file using spi_register_board_info. This will call the xra1405_init function and this results in probe function being called.

    The init function is defined as

    static int __init xra1405_init(void)
    {
        return spi_register_driver(&xra1405_driver);
    }
    subsys_initcall(xra1405_init);

    When I replace the subsys_initcall with late_initcall my spi_read and spi_write routines work as I can read back what I write to xra1405 registers.

    But with subsys_initcall they do not as read retunrs zero and write, writes rubbish.

    I want to register the driver using subsys_initcall. What I want to do is use Linux API's of request, direction and set_value to set up pins in my board specific file but when I call this They get called before the spi based drive is registered and at that point they are not valid. How do I call them in my board specific file after the xra1405 (IO Expander 1 & 2 in logs) driver is registered.

    Here is what I have in my log files when using subsys_initcall

    ************************ LOGS ***********************

    [    0.000000] NET: Registered protocol family 16
    [    0.000000] gpiochip_add: gpios 0..31 (gpio) Success to register
    [    0.000000] OMAP GPIO hardware version 2.5
    [    0.000000] gpiochip_add: gpios 32..63 (gpio) Success to register
    [    0.000000] OMAP GPIO hardware version 2.5
    [    0.000000] gpiochip_add: gpios 64..95 (gpio) Success to register
    [    0.000000] OMAP GPIO hardware version 2.5
    [    0.000000] gpiochip_add: gpios 96..127 (gpio) Success to register
    [    0.000000] OMAP GPIO hardware version 2.5
    [    0.000000] gpiochip_add: gpios 128..159 (gpio) Success to register
    [    0.000000] OMAP GPIO hardware version 2.5
    [    0.000000] gpiochip_add: gpios 160..191 (gpio) Success to register
    [    0.000000] OMAP GPIO hardware version 2.5
    [    0.000000] omap_mux_init: Add partition: #1: core, flags: 0
    [    0.000000] GPIO_129 set for Amplifier Enabled
    [    0.000000] GPIO_24 set for USB Reset
    [    0.000000] GPIO_138 set for IO_CS0
    [    0.000000] GPIO_136 set for IO_CS1
    [    0.000000] GPIO_137 set for ETH_RST
    [    0.000000] GPIO_29 set for ETH_IRQ

    XRA1405 Driver not registered at this point and when I say gpio_request(212,NULL) in my board specific file, it returns invalid gpio pin which is correct. I want my gpio_request to be called after the XRA1405 driver (IO Expander 1 & 2) is registered.


    [    0.000000] hw-breakpoint: debug architecture 0x4 unsupported.
    [    0.000000] OMAP DMA hardware revision 5.0
    [    0.023101] bio: create slab <bio-0> at 0
    [    0.024291] regulator: vwl1271: 1800 mV
    [    0.025573] SCSI subsystem initialized
    [    0.025970] omap2_mcspi omap2_mcspi.1: registered master spi1
    [    0.026245] omap2_mcspi omap2_mcspi.2: registered master spi2
    [    0.026306] spi spi2.0: setup mode 0, 8 bits/w, 1500000 Hz max --> 0
    [    0.026519] omap2_mcspi omap2_mcspi.2: registered child spi2.0
    [    0.026550] spi spi2.1: setup mode 0, 8 bits/w, 12000000 Hz max --> 0
    [    0.026550] spi spi2.1: GPIO 138 selected as chip_select
    [    0.026794] IO Expander 1 spi2.1: setup mode 0, 16 bits/w, 12000000 Hz max --> 0
    [    0.026794] IO Expander 1 spi2.1: GPIO 138 selected as chip_select
    [    0.026824] gpiochip_add: gpios 212..227 (IO Expander 1) Success to register
    [    0.027038] omap2_mcspi omap2_mcspi.2: registered child spi2.1
    [    0.027069] spi spi2.2: setup mode 0, 8 bits/w, 12000000 Hz max --> 0
    [    0.027099] spi spi2.2: GPIO 136 selected as chip_select
    [    0.027313] IO Expander 2 spi2.2: setup mode 0, 16 bits/w, 12000000 Hz max --> 0
    [    0.027313] IO Expander 2 spi2.2: GPIO 136 selected as chip_select
    [    0.027343] gpiochip_add: gpios 228..243 (IO Expander 2) Success to register
    [    0.027557] omap2_mcspi omap2_mcspi.2: registered child spi2.2
    [    0.027862] omap2_mcspi omap2_mcspi.3: registered master spi3
    [    0.028106] omap2_mcspi omap2_mcspi.4: registered master spi4

    HERE-----> I want it to be called here after all the spi's are registered.

     Regards

    Ali

  • Hi Ali,

    The problem with unproper work of SPI GPIO expander initialized by subsys_initcall could be due to that this function initializes the driver very early in the boot sequence. This ordering ensures that subsystem and platform drivers are initialized before device drivers try to utilize the former's functionality (e.g. a device driver registers as a subsystem device).
    In other words the system probably is not ready for initialization of your driver in that moment but when using the late_initcall function the system is ready yet.
    I suggest you to try to find some way to delay the usage of gpio_set_value until the SPI GPIO expander initialization complete.

    BR
    Tsvetolin Shulev
  • Hi Tsvetolin

    Can you suggest any method for this?

    Thanks

    Ali