am335x gpio 模拟 spi 驱动添加

  • kernel 内 make menuconfig

    //  make menuconfig 
    Device Drivers  --->
        [*] SPI support  --->
              <*>   GPIO-based bitbanging SPI Master   // 这个是gpio-spi 的驱动
              <*>   User mode SPI device driver support   // 这个是生成 /dev/spidev*.*的驱动
  • 在板级文件里面添加:

    //  vim arch/arm/mach-omap2/board-aplex_ECM_5416.c
    #define GPIO1_12 GPIO_TO_PIN(1, 12)                                         
    #define GPIO1_13 GPIO_TO_PIN(1, 13)                                         
    #define GPIO1_14 GPIO_TO_PIN(1, 14)                                         
    #define GPIO1_15 GPIO_TO_PIN(1, 15)                                         
    #define SPI_GPIO_BUS_NUM 3       // 设置spi 总线编号 
                                              
    static struct spi_gpio_platform_data ecm_5410_gpio_spi_data = {             
        .sck = GPIO1_12,            // 指定clk 的gpio     
        .mosi = GPIO1_13,         // 指定slave input                    
        .miso = GPIO1_14,          // 指定 slave output                  
        .num_chipselect = 1,      // 指定一共有几个cs           
    };                                                                          
                                                                                
    static struct platform_device ecm_5410_gpio_spi_device = {                  
        .name = "spi_gpio",       // 匹配 spi-gpio.c 里面的驱动名字                                              
        .id = SPI_GPIO_BUS_NUM,        // 配置 spi 总线编号                                         
        .dev = {                                                                
            .platform_data = &ecm_5410_gpio_spi_data,    // 指定配置数据                       
        },                                                                      
    };                                                                          
    // 配置 pin_mux                                                                            
    static struct pinmux_config ecm_5410_gpio_spi_pin_mux[] = {                 
        {"gpmc_ad12.gpio1_12", OMAP_MUX_MODE7 | AM33XX_PULL_ENBL | AM33XX_INPUT_EN},
        {"gpmc_ad13.gpio1_13", OMAP_MUX_MODE7 | AM33XX_PULL_ENBL | AM33XX_PULL_UP | AM33XX_INPUT_EN},
        {"gpmc_ad14.gpio1_14", OMAP_MUX_MODE7 | AM33XX_PULL_ENBL | AM33XX_INPUT_EN},
        {"gpmc_ad15.gpio1_15", OMAP_MUX_MODE7 | AM33XX_PULL_ENBL | AM33XX_INPUT_EN},
    };                                                                          
                                                                                
    static struct spi_board_info  am335x_spi2_slave_info[] = {     
        {                                                                       
            .modalias = "spidev",                                               
            .max_speed_hz = 10000000,                                           
            .bus_num = SPI_GPIO_BUS_NUM,                                        
            .controller_data = (void *)GPIO1_15,       // 设置 cs 总线                         
            .chip_select   = 0,                                                    
            .mode = SPI_MODE_0,                                                    
        },                                                                         
    };                                                                             

    static void ecm_5410_gpio_spi_init(int evm_id, int profile)                 
    {                                                                           
        setup_pin_mux(ecm_5410_gpio_spi_pin_mux);                               
        // 总线设备注册,先配置到spi-gpio 的总线驱动                                                                        
        platform_device_register(&ecm_5410_gpio_spi_device);                    
         // spi 板级信息注册,生成 /dev/spidev3.0                                                                       
        spi_register_board_info(am335x_spi2_slave_info,                         
                    ARRAY_SIZE(am335x_spi2_slave_info));                        
    };                                                                          
                                                                               
    static struct evm_dev_cfg ECM_5412_dev_cfg[] = {                            
        // ... ... 加入板级初始化                                                              
        {ecm_5410_gpio_spi_init,   DEV_ON_BASEBOARD, PROFILE_ALL},              
        {NULL, 0, 0},                                                           
    };                                                                          
posted @ 2017-10-23 13:54  陈富林  阅读(1526)  评论(0编辑  收藏  举报