Search code examples
clinux-device-driverembedded-linuxopenwrtspi

Issue with sharing SPI hardware for flash and tft LCD


I am using TFT LCD screen (ILI9163c) which is connected with athros AR9331 module with spi pins. Athros AR9331 is running with OpenWRT linux distribution. So, I am driving my LCD with spidev0.1 using my C application code.

Athros AR9331 board is using same SPI pins for driving flash memory on board, which is handled from kernel.

I have separate chip select pin for LCD to give proper data recognizance for LCD by making it low and high from code, but still sometimes LCD screen affected with garbage when some data transferred (using other script or application) on flash while LCD printing is on going from my code.

I have control on LCD chip select from code but not for flash. so in this case what should i do to handle a situation when operation for both flash and LCD is going parallel.

This is my function code for sending data on LCD using SPIdev0.1.

    void spi_transactor(unsigned int wlength,
                        unsigned int rlength,
                        const unsigned char write_data,
                        int mode)
    {
       int ret;
       struct spi_ioc_transfer xfer[4];
       unsigned char init_reg[1];

       init_reg[0] = write_data;

       if (mode)
       {
          gpio_set_value(_rs, 1);  // DATA 
       }
       else
       {
          gpio_set_value(_rs, 0);  // COMMAND
       }

       memset(xfer, 0, sizeof xfer);

       xfer[0].bits_per_word = 8;
       xfer[0].tx_buf = (unsigned long) &init_reg[0];
       xfer[0].rx_buf = 0;                        //( unsigned long ) &buf_rx[0];
       xfer[0].len = wlength + rlength;
       xfer[0].delay_usecs = 0;
       xfer[0].speed_hz = speedx;               
       //xfer[0].speed_hz = 40000000;            // 40MHZ

 gpio_set_value(_CS, 0);          // SET ChipSELECT LOW    
       ret = ioctl(spi_fd, SPI_IOC_MESSAGE(1), &xfer);     
 gpio_set_value(_CS, 1);          // SET ChipSELECT HIGH 

       (void) ret;
       //DEBUG_PRINT("%d\n",ret);
       //if (ret <= 0) ; 
       //DEBUG_PRINT("ERROR: %s\n", strerror(errno));

    }

i think it can be possible if we can configure my gpio as Chipselect in spidev0.1 driver in kernel... But how i can configure gpio as chipselect in kernel ?


Solution

  • i found something similar to this, here...

    openWRT custom chipselect GPIO

    just registered general GPIO-pin as CS1 for LCD from spi driver and finally i solved my issue.

    Thank you @A.K , @user694733