How to use GPIO as spi chipselect.

I am working on a board that is derived from a Pocket Beagle.

It has two max81355 SPI Thermocouples on SPI0.

The first uses spi0_cs0 as a chip select.

spi0_cs1 is used for mmc.cd so that can not be used for the second.

The hardware designer used spio_d1(MOSI) set as a GPIO for the 2nd chip select.

I have no clue how to set the device tree entry for that.

This is what I have - which I do not think can work.

fragment@1 {
target = <&am33xx_pinmux>;
overlay {
pb_spi0_pins: pinmux_pb_spi0_pins {
pinctrl-single,pins = <
/* SPI0_SCLK STATUS:WORKS ??? /
AM33XX_IOPAD(0x0950, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE0 ) /
A13 P1.08 SPI0_SCLK 0x150 GPIO2 GPIO0_2 SCLK /
/
SPI0_DO STATUS:WORKS ??? /
AM33XX_IOPAD(0x0954, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE0 ) /
B13 P1.10 SPI0_D0 0x154 GPIO3 GPIO0_3 MISO /
/
SPI0_D1 STATUS:UNKNOWN /
AM33XX_IOPAD(0x0958, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE7 ) /
B14 P1.12 SPI0_D1 0x158 GPIO4 GPIO0_4 TC1 /
/
SPI0_CS0 STATUS:WORKS ??? /
AM33XX_IOPAD(0x095c, PIN_OUTPUT_PULLUP | INPUT_EN | MUX_MODE0 ) /
A14 P1.06 SPI0_CS 0x15c GPIO5 GPIO0_5 TC0 */

;
};
};
};

fragment@2 {
target = <&spi0>;
overlay {
#address-cells = <1>;
#size-cells = <0>;

status = “okay”;
pinctrl-names = “default”;
pinctrl-0 = <&pb_spi0_pins>;
ti,pio-mode; /* disable dma when used as an overlay, dma gets stuck at 160 bits… */

channel@0 {
#address-cells = <1>;
#size-cells = <0>;
compatible = “spidev”;
reg = <0>;
spi-max-frequency = <4300000>;
spi-cpha;
};

channel@1 {
#address-cells = <1>;
#size-cells = <0>;
compatible = “spidev”;
reg = <1>;
spi-max-frequency = <4300000>;
};
};
};

You can not have the SPI hardware manage one of the SPI chip select lines, and you bit-bang the other.
Either you let the SPI hardware manage both of them, which you can not do in this case, because of assignment conflict, or you must bit-bang both of the CS lines.
So, set it up as a single generic SPI driver, and pick any two GPIO pins for chip-select lines.
One of them could be the same pin as CS0, just configured as a GPIO pin.
You will need to write a little wrapper for the SPI call, that drops the appropriate CS line, before you write to the SPI hardware.
You will need to raise the appropriate CS line when the SPI hardware is done sending.
DO NOT send your last data to the SPI hardware and immediately raise the CS line.
The SPI hardware is a parallel to serial device, and will still be sending data for some time after the data is written to it to send.
— Graham

Thank you;

I should have thought of that.

I probably did not because other systems I work with have linux drivers that allow configuring any GPIO as a chip select.

I did think of bit-banging the SPI, This use is not especially high speed. Frankly I do not know why the device is SPI.