目录
这个就和具体设备相关了,这里贴一个demo。
1. dts
uspi0: usi3spi@f0d89000 {
compatible = "tsm,tsm-spi";
status = "disabled";
interrupt-parent = <&gic>;
interrupts = <0 29 4>;
reg = <0x0 0xf0d89000 0x0 0x1000>;
#address-cells = <1>;
#size-cells = <0>;
clock-names = "usi_clk";
reg-shift = <2>;
pinctrl-name = "default";
pinctrl-0 = <&PA20_pinctrl>;
uspics-gpios = <&porta 20 GPIO_ACTIVE_LOW>;
};
&uspi0 {
status = "okay";
//max-freq = <48000000>;
w25q64@00 {
status = "okay";
#address-cells = <0x1>;
#size-cells = <0x0>;
compatible = "w25q64";
reg = <0>;
spi-max-frequency = <10000000>;
};
};
2. 驱动
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/spi/spi.h>
#include <linux/spi/flash.h>
#include <linux/mtd/spi-nor.h>
static int w25q64_probe(struct spi_device *spi)
{
printk("w25q64_probe 666666\n");
return 0;
}
static int w25q64_remove(struct spi_device *spi)
{
return 0;
}
static const struct of_device_id w25q64_of_table[] = {
{ .compatible = "w25q64" },
{}
};
MODULE_DEVICE_TABLE(of, w25q64_of_table);
static struct spi_driver w25q64_driver = {
.driver = {
.name = "w25q64",
.of_match_table = w25q64_of_table,
},
.probe = w25q64_probe,
.remove = w25q64_remove,
};
module_spi_driver(w25q64_driver);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mike Lavender");
MODULE_DESCRIPTION("MTD SPI driver for ST M25Pxx flash chips");