SPI Nor FLASH
参考内核 dervices/mtd/devices/m25p80.c
M25P64 datasheet
由于M25P64属于SPI Nor Flash linux内核对于Flash采用Mtd驱动进行管理。
分析m25p80.c 省略了MTD Nor Flash Jedec与CFI 分析 这块分析可以参考韦东山老师Nor flash驱动的讲解 ,对于SPI falsh 驱动已经支持的很好了,只需要去添加以下设备注册
驱动硬件接口属于SPI设备驱动
static struct spi_driver m25p80_driver = {
.driver = {
.name = "m25p80",
.bus = &spi_bus_type,
.owner = THIS_MODULE,
},
.probe = m25p_probe,
.remove = __devexit_p(m25p_remove),
};
static int m25p80_init(void)
{
return spi_register_driver(&m25p80_driver);
}
static void m25p80_exit(void)
{
spi_unregister_driver(&m25p80_driver);
}
module_init(m25p80_init);
module_exit(m25p80_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mike Lavender");
MODULE_DESCRIPTION("MTD SPI driver for ST M25Pxx flash chips");
对于MTD Nor Flash设备驱动核心在于分配,设置mtd_info,注册。 MTD设备读写均使用MTD注册字符设备进行读写,最终调用mtd_info中注册的底层设备读写方法。
struct m25p {
struct spi_device *spi;
struct semaphore lock;
struct mtd_info mtd;
unsigned partitioned;
u8 command[4];
};
/*
* board specific setup should have ensured the SPI clock used here
* matches what the READ command supports, at least until this driver
* understands FAST_READ (for clocks over 25 MHz).
*/
static int __devinit m25p_probe(struct spi_device *spi)
{