Initializing both CS on SPI1 causes data corruption

Using two MCP23S17 I/O expanders via SPI1 with CS0 P9.28 and CS1 P9.42.
I am initializing each chip separately and doing a read immediately after, which produces the expected data. However, if I go back to read the first chip after initializing the second chip, the data is skewed and doesn’t read the first chip correctly. This happens even if I swap the order that the chips are initialized – whichever one was initialized first ends up with skewed data.

Software or kernel issue?

Here is my code and the output:
https://pastebin.com/L6qJGwPZ

Try again using the MCP23S17 bindings and the pinctrl-mcp23s08 driver:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt

Regards,

Sure, that name would be fine, but I would first start with this example:

https://github.com/beagleboard/bb.org-overlays/blob/master/src/arm/BB-SPI0-MCP23S08-00A0.dts

Then change it to SPI1 and tweak the node to match the mcp23s17..

Regards,

Robert,

This caused my spidev1.0 and spidev1.1 to disappear.

Yes, that's good.. you can use the gpiolib/etc instead of hacking thru spidev..

Here's what I compiled:
/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

/dts-v1/;
/plugin/;

#include <dt-bindings/board/am335x-bbw-bbb-base.h>
#include <dt-bindings/pinctrl/am33xx.h>

/ {
        compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";

        /* identification */
        part-number = "BB-SPI1-MCP23S17";
        version = "00A0";

        /* state the resources this cape uses */
        exclusive-use =
                /* the pin header uses */
                "P9.31", /* spi1_sclk, SPI1_SCLK */
                "P9.29", /* spi1_d0, SPI1_MISO */
                "P9.30", /* spi1_d1, SPI1_MOSI */
                "P9.28", /* spi1_cs0, CS0 */
                "P9.42", /* spi1_cs1, CS1 */
                /* the hardware ip uses */
                "spi1";

        /*
         * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
         */
        fragment@0 {
                target-path="/";
                __overlay__ {

                        chosen {
                                overlays {
                                        BB-SPI1-MCP23S17-00A0 = __TIMESTAMP__;
                                };
                        };
                };
        };

        /*
         * Free up the pins used by the cape from the pinmux helpers.
         */
        fragment@1 {
                target = <&ocp>;
                __overlay__ {
                        P9_28_pinmux { status = "disabled"; }; /* spi1_cs0 */
                        P9_30_pinmux { status = "disabled"; }; /* spi1_d1 */
                        P9_29_pinmux { status = "disabled"; }; /* spi1_d0 */
                        P9_31_pinmux { status = "disabled"; }; /* spi1_sclk */
                        P9_42_pinmux { status = "disabled"; }; /* spi1_cs1 */
                };
        };

        fragment@2 {
                target = <&am33xx_pinmux>;
                __overlay__ {
                        bb_spi0_pins: pinmux_bb_spi0_pins {

This label name doesn't match below... (aka: bb_spi1) replace ^ spi0
with spi1...

                                pinctrl-single,pins = <
                                        BONE_P9_31 (PIN_INPUT_PULLUP | MUX_MODE3) /* spi1_sclk.spi1_sclk */
                                        BONE_P9_29 (PIN_INPUT_PULLUP | MUX_MODE3) /* spi1_d0.spi1_d0 */
                                        BONE_P9_30 (PIN_OUTPUT_PULLUP | MUX_MODE3) /* spi1_d1.spi1_d1 */
                                        BONE_P9_28 (PIN_OUTPUT_PULLUP | MUX_MODE3) /* spi1_cs0.spi1_cs0 */
                                        BONE_P9_42 (PIN_OUTPUT_PULLUP | MUX_MODE2) /* spi1_cs1.spi1_cs1 */
                                >;
                        };
                };
        };

        fragment@3 {
                target = <&spi1>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;

                        status = "okay";
                        pinctrl-names = "default";
                        pinctrl-0 = <&bb_spi1_pins>;

                        gpiom1: gpio@0 {
                                compatible = "microchip,mcp23s17";
                                gpio-controller;
                                #gpio-cells = <2>;
                                microchip,spi-present-mask = <0x01>;
                                mcp,spi-present-mask = <0x01>;
                                spi-present-mask = <0x01>;
                                reg = <0>;
                                spi-max-frequency = <1000000>;
                        };

                        gpiom2: gpio@1 {
                                compatible = "microchip,mcp23s17";
                                gpio-conroller;

spelling: gpio-controller

                                #gpio-cells = <2>;
                                microchip,spi-present-mask = <0x01>;
                                mcp,spi-present-mask = <0x01>;
                                spi-present-mask = <0x01>;
                                reg = <1>;
                                spi-max-frequency = <1000000>;
                        };
                };
        };
};

Regards,