/* sometimes a short mid-message deselect of the chip
* may be needed to terminate a mode or command
*/
/* [cgw]: 释放spi */
ndelay(nsecs);
bitbang->chipselect(spi, BITBANG_CS_INACTIVE);
ndelay(nsecs);
}
m->status = status;
m->complete(m->context);
/* restore speed and wordsize */
/* [cgw]: 速度和位数恢复默认 */
if (setup_transfer)
setup_transfer(spi, NULL);
/* normally deactivate chipselect ... unless no error and
* cs_change has hinted that the next message will probably
* be for this chip too.
*/
if (!(status == 0 && cs_change)) {
ndelay(nsecs);
bitbang->chipselect(spi, BITBANG_CS_INACTIVE);
ndelay(nsecs);
}
spin_lock_irqsave(&bitbang->lock, flags);
}
bitbang->busy = 0;
/* [cgw]: 退出临界区 */
spin_unlock_irqrestore(&bitbang->lock, flags);
}
代码:
spi_platform_dev.c
#include <asm/arch/spi-gpio.h>
static struct spi_board_info board_info[1] = {
{
.modalias = "spi_ssd1306", /* [cgw]: spi设备名,和设备驱动名对应 */
.bus_num = 0, /* [cgw]: spi总线号,即spi0 */
.chip_select = 2, /* [cgw]: spi总线上的设备号,即spi0.2 */
.max_speed_hz = 50000, /* [cgw]: spi时钟 */
.mode = SPI_MODE_3, /* [cgw]: spi数据模式 */
},
};
static void ssd1306_chip_select(struct s3c2410_spigpio_info *spi, int cs)
{
/* [cgw]: 选中设备号为2的spi设备 */
if (spi->board_info->chip_select == 2) {
s3c2410_gpio_cfgpin(S3C2410_GPG2, S3C2410_GPIO_OUTPUT);
/* [cgw]: 选中设备 */
if (BITBANG_CS_ACTIVE == cs) {
s3c2410_gpio_setpin(S3C2410_GPG2, 0);
/* [cgw]: 释放设备 */
} else if (BITBANG_CS_INACTIVE == cs) {
s3c2410_gpio_setpin(S3C2410_GPG2, 1);
}
}
}
/* [cgw]: */
static struct s3c2410_spigpio_info spi_dev = {
.pin_clk = S3C2410_GPG7,
.pin_mosi = S3C2410_GPG5,
.pin_miso = S3C2410_GPG6,
.board_size = 1, /* [cgw]: 设置板上spi接口数量为1 */
.board_info = &board_info[0],
.chip_select = ssd1306_chip_select
};
static void spi_dev_release(struct device * dev)
{
printk("spi_dev_release! \n");
}
/* [cgw]: 分配一个平台设备 */
static struct platform_device spi_platform_dev = {
.name = "s3c24xx-spi-gpio", /* [cgw]: 设置平台设备名,和平台驱动名对应 */
.id = -1,
.dev = {
.release = spi_dev_release,
.platform_data = (void *)&spi_dev, /* [cgw]: 通过platform_data传递spi_dev给平台驱动
* 平台驱动可以访问spi_dev
*/
},
};
static int spi_dev_init(void)
{
/* [cgw]: 注册spi_platform_dev平台设备 */
platform_device_register(&spi_platform_dev);
return 0;
}
static void spi_dev_exit(void)
{
/* [cgw]: 注销spi_platform_dev平台设备 */
platform_device_unregister(&spi_platform_dev);
}
module_init(spi_dev_init);
module_exit(spi_dev_exit);
MODULE_LICENSE("GPL");
spi_ssd1306_drv.c