almaz1c Posted February 8, 2018 Posted February 8, 2018 Hello! I am using armbian on orangepi zero. Currently SPI_CS line is LOW in default state and goes HIGH when selecting. Does it possible to invert it's state to be HIGH in default state and to be pulled down during line selection?
chwe Posted February 9, 2018 Posted February 9, 2018 I'm not sure anymore.. Long time ago since I lastly used SPI on legacy kernel... I think defining cs in the fexfile (bin2fex --> fex2bin) [spi0] according to this should work: spi_cs0 = port:PA13<2><1><default><default> But on your own, test it first with a multimeter before complaining about faults..
almaz1c Posted February 12, 2018 Author Posted February 12, 2018 spi0 { pins = "PC0", "PC1", "PC2", "PC3"; function = "spio0"; linux, phandle = <0x20>; phandle = <0x20>; }; spi1 { pins = "PA15", "PA16", "PA14", "PA13"; function = "spi1"; linux, phandle = <0x21>; phandle = <0x21>; }; spi@01c68000 { compatible = "allwinner, sun8i-h3-spi"; reg = <0x1c68000 0x1000>; interrupts = <0x0 0x41 0x4>; clocks = <0x6 0x1e 0x6 0x52>; clock-names = "ahb", "mod"; dmas = <0x1f 0x17 0x1f 0x17>; dma-names = "default"; pinctrl-names = "default"; pinctrl-0 = <0x20>; resets = <0x6 0xf>; status = "disabled"; #address-cells = 0x1; #size-cells = 0x0; linux,phandle = <0x5c>; phandle = <0x5c>; flash@0 { #address-cells = <0x1>; #size-cells = <0x1>; compatible = "mxicy, mx25l1606e", "winbond, w25q1$ reg = <0x0>; spi-max-frequency = <0x2625a00>; }; }; spi@01c69000 { compatible = "allwinner, sun8i-h3-spi"; reg = <0x1c69000 0x1000>; interrupts = <0x0 0x42 0x4>; clocks = <0x6 0x1f 0x6 0x53>; clock-names = "ahb", "mod"; dmas = <0x1f 0x18 0x6 0x53>; dma-names = "rx", "tx"; pinctrl-names = "default"; pinctrl-0 = <0x21>; resets = <0x6 0x10>; status = "disabled"; #address-cells = <0x1>; #size-cells = <0x0>; linux, phandle = <0x5d>; phandle = <0x5d>; }; spi0_pins = "/soc/pinctrl@01c20800/spi0"; spi1_pins = "/soc/pinctrl@01c20800/spi1"; spi0 = "/soc/spi@01c68000"; spi1 = "/soc/spi@01c69000"; I use debian server mainline kernel. So there is dts instead of fex. Here is what I found in dts. What is the magic string that will invert CS default state? 1
zador.blood.stained Posted February 12, 2018 Posted February 12, 2018 Available DT settings for SPI busses and SPI slave devices are listed there: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/Documentation/devicetree/bindings/spi/spi-bus.txt Those properties include a slave device property named "spi-cs-high". Though applying this property may need creating an additional DT overlay (i.e. if it needs to be applied to a spidev slave activated by an overlay). Edit: Though this will work only if SPI drivers respect this flag, which they may not do.
almaz1c Posted February 15, 2018 Author Posted February 15, 2018 On 2/12/2018 at 10:29 PM, zador.blood.stained said: Available DT settings for SPI busses and SPI slave devices are listed there: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/Documentation/devicetree/bindings/spi/spi-bus.txt Those properties include a slave device property named "spi-cs-high". Though applying this property may need creating an additional DT overlay (i.e. if it needs to be applied to a spidev slave activated by an overlay). Edit: Though this will work only if SPI drivers respect this flag, which they may not do. I tried it. Here is armbianEnv.txt file: $ cat /boot/armbianEnv.txt verbosity=1 logo=disabled console=both disp_mode=1920x1080p60 overlay_prefix=sun8i-h3 overlays=usbhost2 usbhost3 spi-spidev spi-add-cs1 rootdev=UUID=39059033-9dc5-4bc4-a4d2-61ef949d5b21 rootfstype=ext4 param_spidev_spi_bus=1 param_spidev_spi_cs=1 usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u dtb to dts converting: $ cd /boot/dtb/overlay al@orangepizero:/boot/dtb/overlay$ cp sun8i-h3-spi-spidev.dtbo /home/al/ al@orangepizero:/boot/dtb/overlay$ cd /home/al/ al@orangepizero:~$ cp sun8i-h3-spi-spidev.dtbo sun8i-h3-spi-spidev.dtbo_def pidev.dtboizero:~$ dtc -I dtb -O dts -o sun8i-h3-spi-spidev.dts ./sun8i-h3-spi-sp Warning (unit_address_vs_reg): Node /fragment@0 has a unit name, but no reg property Warning (unit_address_vs_reg): Node /fragment@1 has a unit name, but no reg property Warning (unit_address_vs_reg): Node /fragment@1/__overlay__/spidev has a reg or ranges property, but no unit name Warning (unit_address_vs_reg): Node /fragment@2 has a unit name, but no reg property Warning (unit_address_vs_reg): Node /fragment@2/__overlay__/spidev has a reg or ranges property, but no unit name dts file editing; $ rm sun8i-h3-spi-spidev.dtbo $ sudo rm /boot/dtb/overlay/sun8i-h3-spi-spidev.dtbo $ ls /boot/dtb/overlay/ | grep spidev $ nano sun8i-h3-spi-spidev.dts /dts-v1/; / { compatible = "allwinner,sun8i-h3"; fragment@0 { target-path = "/aliases"; __overlay__ { spi0 = "/soc/spi@01c68000"; spi1 = "/soc/spi@01c69000"; }; }; fragment@1 { target = <0xffffffff>; __overlay__ { #address-cells = <0x1>; #size-cells = <0x0>; spidev { compatible = "spidev"; status = "disabled"; reg = <0x0>; spi-max-frequency = <0xf4240>; }; }; }; fragment@2 { target = <0xffffffff>; __overlay__ { #address-cells = <0x1>; #size-cells = <0x0>; spidev { compatible = "spidev"; status = "ok"; spi-cs-high; reg = <0x0>; spi-max-frequency = <0xf4240>; }; }; }; __fixups__ { spi0 = "/fragment@1:target:0"; spi1 = "/fragment@2:target:0"; }; }; Converting dts back to dtbo: $ dtc -I dts -O dtb -o sun8i-h3-spi-spidev.dtbo ./sun8i-h3-spi-spidev.dts $ sudo mv sun8i-h3-spi-spidev.dtbo /boot/dtb/overlay/sun8i-h3-spi-spidev.dtbo $ ls /boot/dtb/overlay/ | grep spidev $ sudo reboot Unfortunately, oscilloscope shows me that CS pin still in "1" while CS active but I need it to be in "1" during passive state and pulled down to "0" during CS activating. How to invert it? Used distributive: $ uname -a Linux orangepizero 4.14.19-sunxi #2 SMP Thu Feb 15 20:54:47 MSK 2018 armv7l GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 9.3 (stretch) Release: 9.3 Codename: stretch
Recommended Posts