在dev-spi.c中
/* SPI (0) */
static struct resource s3c_spi0_resource[] = {
[0] = {
.start = S3C_PA_SPI0,
.end = S3C_PA_SPI0 + S3C_SZ_SPI0 - 1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = IRQ_SPI0,
.end = IRQ_SPI0,
.flags = IORESOURCE_IRQ,
}
};
static struct s3c_spi_mstr_info sspi0_mstr_info = {
.pdev = NULL,
.clk = NULL,
.prnt_clk = NULL,
.num_slaves = 0,
.spiclck_get = smi_getclcks,
.spiclck_put = smi_putclcks,
.spiclck_en = smi_enclcks,
.spiclck_dis = smi_disclcks,
.spiclck_setrate = smi_setrate,
.spiclck_getrate = smi_getrate,
};
static u64 s3c_device_spi0_dmamask = 0xffffffffUL;
struct platform_device
s3c_device_spi0 = {
.name
= "s3c-spi",
.id
= 0,
.num_resources
= ARRAY_SIZE(s3c_spi0_resource),
.resource
= s3c_spi0_resource,
.dev
= {
.dma_mask = &s3c_device_spi0_dmamask,
.coherent_dma_mask = 0xffffffffUL,
.platform_data = &sspi0_mstr_info,
}
};
EXPORT_SYMBOL(s3c_device_spi0);
/* SPI (1) */
static struct resource s3c_spi1_resource[] = {
[0] = {
.start = S3C_PA_SPI1,
.end = S3C_PA_SPI1 + S3C_SZ_SPI1 - 1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = IRQ_SPI1,
.end = IRQ_SPI1,
.flags = IORESOURCE_IRQ,
}
};
static struct s3c_spi_mstr_info sspi1_mstr_info = {
.pdev = NULL,
.clk = NULL,
.prnt_clk = NULL,
.num_slaves = 0,
.spiclck_get = smi_getclcks,
.spiclck_put = smi_putclcks,
.spiclck_en = smi_enclcks,
.spiclck_dis = smi_disclcks,
.spiclck_setrate = smi_setrate,
.spiclck_getrate = smi_getrate,
};
static u64 s3c_device_spi1_dmamask = 0xffffffffUL;
struct platform_device s3c_device_spi1 = {
.name
= "s3c-spi",
.id
= 1,
.num_resources
= ARRAY_SIZE(s3c_spi1_resource),
.resource
= s3c_spi1_resource,
.dev
= {
.dma_mask = &s3c_device_spi1_dmamask,
.coherent_dma_mask = 0xffffffffUL,
.platform_data = &sspi1_mstr_info,
}
};
EXPORT_SYMBOL(s3c_device_spi1);
/* SPI (2) */
static struct resource s3c_spi2_resource[] = {
[0] = {
.start = S3C_PA_SPI2,
.end = S3C_PA_SPI2 + S3C_SZ_SPI2 - 1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = IRQ_SPI2,
.end = IRQ_SPI2,
.flags = IORESOURCE_IRQ,
}
};
static struct s3c_spi_mstr_info sspi2_mstr_info = {
.pdev = NULL,
.clk = NULL,
.prnt_clk = NULL,
.num_slaves = 0,
.spiclck_get = smi_getclcks,
.spiclck_put = smi_putclcks,
.spiclck_en = smi_enclcks,
.spiclck_dis = smi_disclcks,
.spiclck_setrate = smi_setrate,
.spiclck_getrate = smi_getrate,
};
static u64 s3c_device_spi2_dmamask = 0xffffffffUL;
struct platform_device s3c_device_spi2 = {
.name
= "s3c-spi",
.id
= 2,
.num_resources
= ARRAY_SIZE(s3c_spi2_resource),
.resource
= s3c_spi2_resource,
.dev
= {
.dma_mask = &s3c_device_spi2_dmamask,
.coherent_dma_mask = 0xffffffffUL,
.platform_data = &sspi2_mstr_info,
}
};
EXPORT_SYMBOL(s3c_device_spi2);
void __init s3cspi_set_slaves(unsigned id, int n, struct s3c_spi_pdata const *dat)
{
struct s3c_spi_mstr_info *pinfo;
if(id == 0)
pinfo = (struct s3c_spi_mstr_info *)s3c_device_spi0.dev.platform_data;
else if(id == 1)
pinfo = (struct s3c_spi_mstr_info *)s3c_device_spi1.dev.platform_data;
else if(id == 2)
pinfo = (struct s3c_spi_mstr_info *)s3c_device_spi2.dev.platform_data;
else
return;
pinfo->spd = kmalloc(n * sizeof (*dat), GFP_KERNEL);
if(!pinfo->spd)
return;
memcpy(pinfo->spd, dat, n * sizeof(*dat));
pinfo->num_slaves = n;
}
在板初始化中调用:/mach-smdkv210.c
static void __init smdkv210_machine_init(void)
{
.......
#if defined(CONFIG_SPI_CNTRLR_0)
s3cspi_set_slaves(BUSNUM(0), ARRAY_SIZE(s3c_slv_pdata_0), s3c_slv_pdata_0);
#endif
#if defined(CONFIG_SPI_CNTRLR_1)
s3cspi_set_slaves(BUSNUM(1), ARRAY_SIZE(s3c_slv_pdata_1), s3c_slv_pdata_1);
#endif
spi_register_board_info(s3c_spi_devs, ARRAY_SIZE(s3c_spi_devs));
..........
}
#if defined(CONFIG_SPI_CNTRLR_0)
static struct s3c_spi_pdata s3c_slv_pdata_0[] __initdata = {
[0] = { /* Slave-0 */
.cs_level = CS_FLOAT,
.cs_pin = S5PV210_GPB(1),
.cs_mode = S5PV210_GPB_OUTPUT(1),
.cs_set = s3c_cs_set,
.cs_config = s3c_cs_config,
.cs_suspend = s3c_cs_suspend,
.cs_resume = s3c_cs_resume,
},
};
#endif
#if defined(CONFIG_SPI_CNTRLR_1)
static struct s3c_spi_pdata s3c_slv_pdata_1[] __initdata = {
[0] = { /* Slave-0 */
.cs_level = CS_FLOAT,
.cs_pin = S5PV210_GPB(5),
.cs_mode = S5PV210_GPB_OUTPUT(5),
.cs_set = s3c_cs_set,
.cs_config = s3c_cs_config,
.cs_suspend = s3c_cs_suspend,
.cs_resume = s3c_cs_resume,
},
};
#endif
static struct spi_board_info s3c_spi_devs[] __initdata = {
#if defined(CONFIG_SPI_CNTRLR_0)
[0] = {
.modalias = "spidev", /* Test Interface */
.mode = SPI_MODE_0, /* CPOL=0, CPHA=0 */
.max_speed_hz = 100000,
/* Connected to SPI-0 as 1st Slave */
.bus_num = 0,
.irq = IRQ_SPI0,
.chip_select = 0,
},
#endif
#if defined(CONFIG_SPI_CNTRLR_1)
[1] = {
.modalias = "spidev", /* Test Interface */
.mode = SPI_MODE_0, /* CPOL=0, CPHA=0 */
.max_speed_hz = 100000,
/* Connected to SPI-1 as 1st Slave */
.bus_num = 1,
.irq = IRQ_SPI1,
.chip_select = 0,
},
#endif
};