Linux下的SPI FLASH驱动

Linux 下的SPI flash驱动

JEDEC

只需了解JEDEC是一个定义半导体行业标准的机构即可,大部分的SPI FLASH都遵循其制定的SFDP标准,软件开发是按照标准操作即可。

SPI协议

SPI NOR framework

引入框架的目的:https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/mtd/spi-nor.txt?h=linux-4.9.y
大致意思就是SPI控制器只能发送接收字节,和设备无关,对于一些固定协议的设备来说使用起来比较麻烦,所以引入这一层便于开发。
spi_nor.c有一个spi_nor_ids表,定义了一些其支持的设备列表信息。
在这里插入图片描述

m25p80

m25p80.c基于SPI NOR框架提供了对常用flash的支持。

参考文章

  1. SFDP(Serial Flash Discoverable Parameters)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个Linux下常用的SPI Flash驱动程序demo,供参考: #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/spi/spi.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> #define SPINOR_OP_RDID 0x9f struct spinor_chip { struct spi_device *spi; struct mtd_info *mtd; }; static int spinor_read_id(struct spinor_chip *chip, u8 *id) { struct spi_transfer t = { .tx_buf = &SPINOR_OP_RDID, .rx_buf = id, .len = 3, }; struct spi_message m; spi_message_init(&m); spi_message_add_tail(&t, &m); return spi_sync(chip->spi, &m); } static int spinor_probe(struct spi_device *spi) { struct spinor_chip *chip; int ret; u8 id[3]; chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; chip->spi = spi; ret = spinor_read_id(chip, id); if (ret) return ret; spi_set_drvdata(spi, chip); chip->mtd = mtd_device_parse_register(&spi->dev, NULL, NULL, NULL, 0, NULL); if (IS_ERR(chip->mtd)) { dev_err(&spi->dev, "failed to register MTD device\n"); return PTR_ERR(chip->mtd); } return 0; } static int spinor_remove(struct spi_device *spi) { struct spinor_chip *chip = spi_get_drvdata(spi); mtd_device_unregister(chip->mtd); return 0; } static const struct of_device_id spinor_of_match[] = { { .compatible = "spi-flash" }, { }, }; MODULE_DEVICE_TABLE(of, spinor_of_match); static struct spi_driver spinor_driver = { .driver = { .name = "spinor", .owner = THIS_MODULE, .of_match_table = spinor_of_match, }, .probe = spinor_probe, .remove = spinor_remove, }; module_spi_driver(spinor_driver); MODULE_AUTHOR("Your Name"); MODULE_LICENSE("GPL");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值