Difference between revisions of "SPI"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
Line 19: Line 19:
 
compatible = "mxicy,mx25l12805d";
 
compatible = "mxicy,mx25l12805d";
 
reg = <0>;
 
reg = <0>;
status = "disabled";
+
status = "disabled";       // disabled表示禁用该驱动
  
 
spi-max-frequency = <50000000>;
 
spi-max-frequency = <50000000>;
Line 42: Line 42:
 
spi-flash| SPI0 flash(X)
 
spi-flash| SPI0 flash(X)
 
</syntaxhighlight>
 
</syntaxhighlight>
设置完毕后需要重启系统。<br>
+
设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。<br>
 
{{Linux-SPIFlash/zh}}  
 
{{Linux-SPIFlash/zh}}  
  
Line 58: Line 58:
 
compatible = "mxicy,mx25l12805d";
 
compatible = "mxicy,mx25l12805d";
 
reg = <0>;
 
reg = <0>;
status = "disabled";
+
status = "disabled";       // disabled表示禁用该驱动
  
 
spi-max-frequency = <50000000>;
 
spi-max-frequency = <50000000>;
Line 81: Line 81:
 
spi-flash| SPI0 flash(X)
 
spi-flash| SPI0 flash(X)
 
</syntaxhighlight>
 
</syntaxhighlight>
设置完毕后需要重启系统。<br>
+
设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。<br>
 
{{Linux-SPIFlash/zh}}
 
{{Linux-SPIFlash/zh}}

Revision as of 04:39, 15 January 2019

查看中文

1 S5P4418

1.1 Q: S5P4418的/dev目录下只有一个spidev0.0这个设备节点, 怎么添加spidev1.0

对于3.4内核来说,4418 需要修改 arch/arm/plat-s5p4418/nanopi2/device.c;
想要增加一路的话,可先搜索 CONFIG_SPI_SPIDEV , 然后参考已有代码增加另一路的支持;
另外,arch/arm/plat-s5p4418/asb/device.c 有 spi2 的支持,修改时可参考;

2 H5

2.1 SPI Flash

FriendlyElec H5的Linux-4.14内核集成了"mxicy,mx25l12805d"的SPI Flash驱动,使用的是SPI0,但是默认并没有使能,相关的dts配置如下:

$ cat linux/arch/arm64/boot/dts/allwinner/sun50i-h5-nanopi.dtsi
&spi0 {
	...
	spiflash: spiflash@0 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "mxicy,mx25l12805d";
		reg = <0>;
		status = "disabled";        // disabled表示禁用该驱动
 
		spi-max-frequency = <50000000>;
		mode = <0>;
 
		partition@0 {
			reg = <0x0 0x1000000>;
			label = "spi-flash";
		};
	};
    ...

可以在npi-config里将其使能,如下:

$ npi-config
	6 Advanced Options| Configure advanced setting
		A5 SPI| Enable/Disable SPI
			spi0 Enable/Disable spi0[enabled]
				spidev0.0| SPI0 char device
				spi-2.8'tft| Matrix-2'8_SPI_Key_TFT
				spi-flash| SPI0 flash(X)

设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。
启动Linux系统时,看到类似下面的启动信息则说明SPI Flash被成功检测到了:

m25p80 spi0.0: mx25l12805d (16384 Kbytes)
1 ofpart partitions found on MTD device spi0.0
Creating 1 MTD partitions on "spi0.0":
0x000000000000-0x000001000000 : "spi-flash"

SPI Flash在Linux系统下的使用方法如下:

$ cat /sys/class/mtd/mtd0/size          # 以byte为单位
$ cat /sys/class/block/mtdblock0/size   # 以sector(512 byte)为单位
$ apt-get install mtd-utils 
$ flash_eraseall -j /dev/mtd0           # 格式成jffs2的格式
$ mount -t jffs2 /dev/mtdblock0 /mnt    
$ mkfs.ext4 /dev/mtdblock0              # 也格式化为ext4
$ mount -t ext4 /dev/mtdblock0 /mnt


3 H3/H2+

3.1 SPI Flash

FriendlyElec H3/H2+的Linux-4.14内核集成了"mxicy,mx25l12805d"的SPI Flash驱动,使用的是SPI0,但是默认并没有使能,相关的dts配置如下:

$ cat linux/arch/arm/boot/dts/sun8i-h3-nanopi.dtsi
&spi0 {
	...
	spiflash: spiflash@0 {
		#address-cells = <1>;
		#size-cells = <1>;
		compatible = "mxicy,mx25l12805d";
		reg = <0>;
		status = "disabled";        // disabled表示禁用该驱动
 
		spi-max-frequency = <50000000>;
		mode = <0>;
 
		partition@0 {
			reg = <0x0 0x1000000>;
			label = "spi-flash";
		};
	};
    ...

可以在npi-config里将其使能,如下:

$ npi-config
	6 Advanced Options| Configure advanced setting
		A5 SPI| Enable/Disable SPI
			spi0 Enable/Disable spi0[enabled]
				spidev0.0| SPI0 char device
				spi-2.8'tft| Matrix-2'8_SPI_Key_TFT
				spi-flash| SPI0 flash(X)

设置完毕后,dtb里spi flash的status = "okay",需要重启系统才能生效。
启动Linux系统时,看到类似下面的启动信息则说明SPI Flash被成功检测到了:

m25p80 spi0.0: mx25l12805d (16384 Kbytes)
1 ofpart partitions found on MTD device spi0.0
Creating 1 MTD partitions on "spi0.0":
0x000000000000-0x000001000000 : "spi-flash"

SPI Flash在Linux系统下的使用方法如下:

$ cat /sys/class/mtd/mtd0/size          # 以byte为单位
$ cat /sys/class/block/mtdblock0/size   # 以sector(512 byte)为单位
$ apt-get install mtd-utils 
$ flash_eraseall -j /dev/mtd0           # 格式成jffs2的格式
$ mount -t jffs2 /dev/mtdblock0 /mnt    
$ mkfs.ext4 /dev/mtdblock0              # 也格式化为ext4
$ mount -t ext4 /dev/mtdblock0 /mnt