看了论坛中大佬的说法,5.x内核是ok的,但是我加上之后一直提示cs被already use,所以仔细查看了内核,原来是reg属性搞的鬼
贴修改
硬件连接:
SPI--》PC0", "PC1", "PC3"
CS0 -->"PC2"
CS1 --> "PB4"
注意IO占用问题。
sun8i0v3s.dtsi中
spi0_pins: spi0-pins {
pins = "PC0", "PC1", "PC2","PC3";//CLK MOSI MISO CS WP
function = "spi0";
};
spi0: spi@1c68000 {
compatible = "allwinner,sun8i-h3-spi";
reg = <0x01c68000 0x1000>;
interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&ccu CLK_BUS_SPI0>, <&ccu CLK_SPI0>;
clock-names = "ahb", "mod";
num-cs = <2>;
/* pinctrl-names = "default";*/
/* pinctrl-0 = <&spi0_pins spi0_pin_lcd>;*/
resets = <&ccu RST_BUS_SPI0>;
status = "disabled";
#address-cells = <1>;
#size-cells = <0>;
};
//以上基本无改动
&pio {
spi0_cs_pins: spi0_cs_pins {
pins = "PC2", "PB4";
function = "gpio_out";
};
};
&spi0 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
cs-gpios = <&pio 2 2 GPIO_ACTIVE_HIGH>, <&pio 1 4 GPIO_ACTIVE_HIGH>;
flash: W25M02GV@0 {
spi-max-frequency = <50000000>;
#address-cells = <1>;
#size-cells = <1>;
compatible = "spi-nand";
reg = <0>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "u-boot";
reg = <0x000000 0x100000>;
read-only;
};
partition@100000 {
label = "dtb";
reg = <0x100000 0x10000>;
read-only;
};
partition@110000 {
label = "kernel";
reg = <0x110000 0x400000>;
read-only;
};
partition@510000 {
label = "rootfs";
reg = <0x510000 0xAF0000>;
};
};
};
st7789v: st7789v@1{
compatible = "sitronix,st7789v";
spi-max-frequency = <50000000>;
reg = <1>;
spi-cpol;
spi-cpha;
dc-gpios = <&pio 1 5 GPIO_ACTIVE_LOW>;
//backlight
rotate = <270>;
fps = <60>;
buswidth = <8>;
};
};
以上改动后,内核配置上ST7789V驱动即可ok
战术撤退
离线
@varzhou
Linux SPI只有一个设备的话,CS会始终有效,如何才能做到SPI发完数据,CS自动失效,再次传输数据时CS自动有效,就是说CS不用的时候自动失效,用的时候自动有效
你说的无效和有效是说CS用的时候是CS,不用时候是其他功能IO的意思吗?
离线
@varzhou
是说有数据的时候CS拉低没数据的时候CS拉高,因为有些设备的SPI接口要检测到CS的上升沿才会把数据读进去,CS拉高无效期间,不会做GPIO用途,只是让选择失效而已
加上spi-cs-high属性就好了
离线
@varzhou
是说有数据的时候CS拉低没数据的时候CS拉高,因为有些设备的SPI接口要检测到CS的上升沿才会把数据读进去,CS拉高无效期间,不会做GPIO用途,只是让选择失效而已
具体code中表现为:
if (of_find_property(nc, "spi-cs-high", NULL))
spi->mode |= SPI_CS_HIGH;
离线
@varzhou
这是设备树指定CS极性,并不会在SPI数据传输完后,拉到相反电平,试过不行,用的IMX8芯片
验证是可以的,但是在构造spi的xfer时候,需要设计.cs_change = 1,才能生效
if (xfer->cs_change) {
if (list_is_last(&xfer->transfer_list,
&msg->transfers)) {
keep_cs = true;
} else {
spi_set_cs(msg->spi, false);
udelay(10);
spi_set_cs(msg->spi, true);
}
}
离线