S3C2440 SPI驱动框架

时间:2021-09-19 23:34:58

S3C2440 SPI驱动代码详细解读:

https://www.linuxidc.com/Linux/2012-08/68402p4.htm

一、platform device and board_info

/* /arch/arm/plat-s3c24xx*/
static struct resource s3c_spi0_resource[] = {
[
0] = { .start = S3C24XX_PA_SPI, .end = S3C24XX_PA_SPI + 0x1f, .flags = IORESOURCE_MEM, }, [1] = { .start = IRQ_SPI0, .end = IRQ_SPI0, .flags = IORESOURCE_IRQ, } }; static u64 s3c_device_spi0_dmamask = 0xffffffffUL; struct platform_device s3c_device_spi0 = { .name = "s3c2410-spi",      /* 匹配platform_device 的.driver.namen */ .id = 0, .num_resources = ARRAY_SIZE(s3c_spi0_resource), .resource = s3c_spi0_resource, .dev = { .dma_mask = &s3c_device_spi0_dmamask, .coherent_dma_mask = 0xffffffffUL } }; EXPORT_SYMBOL(s3c_device_spi0); /* /arch/arm/mach-s3c2440/mach-tq2440.c */ static struct spi_board_info s3c2440_spi0_board[] = { [0] = { .modalias = "spidev", .bus_num = 0, .chip_select = 0, .irq = IRQ_SPI0, //IRQ_EINT10,/* 修改无效 */ .max_speed_hz = 10*1000*1000, }, }; static struct s3c2410_spi_info s3c2440_spi0_platdata = { .pin_cs = S3C2410_GPG2, .num_cs = 1, .bus_num = 0, }; static struct platform_device *tq2440_devices[] __initdata = {   ......&s3c_device_spi0, /* sunhj add for spi0 */ &s3c_device_spi1, }; static void __init tq2440_machine_init(void) {
  platform_add_devices(tq2440_devices, ARRAY_SIZE(tq2440_devices));
  /* sunhj add for spi */ s3c_device_spi0.dev.platform_data= &s3c2440_spi0_platdata; spi_register_board_info(s3c2440_spi0_board, ARRAY_SIZE(s3c2440_spi0_board)); }

 

二、Platform driver

/* /driver/spi/spi_s3c24xx.c */