oLinuxino MAXI mcp2515

Started by marker5a, June 22, 2016, 11:39:34 PM

Previous topic - Next topic

marker5a

Hello All

I've been playing around with the olinuxino maxi board and have been trying for a few days now to get the mcp2515 to play nice with my board.  I learned about the device tree as I am a bit new at modifying device/board level kernel paramters..  I understand the concept but still seem to be missing some key low level paramters.

Anyways, here goes...

I have the following electrical connections:
1) CS tied to UEXT_CS
2) SCK tied to SSP2_SCK
3) SI tied to SSP2_MOSI
4) SO tied to PIN9/LCD_D08/SSP2_MISO
5) INT tied to AUART1_TXD

I addded the following into the imx23-olinuxino.dts file, compiled it and uploaded to /boot/dtbs/ and rebooted:

ssp1: ssp@80034000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "fsl,imx23-spi";
pinctrl-names = "default";
pinctrl-0 = <&spi2_pins_a>;
status = "okay";

can0: can@0 {
compatible = "microchip,mcp2515";
reg = <0>;
oscillator-frequency = <16000000>;
interrupt-parent = <&gpio0>;
interrupts = <16 0x2>;
spi-max-frequency = <1000000>;
};
};


After reboot, I have been getting the following in dmesg:

Quotemcp251x: probe of spi1.1 failed with error -2

I am guessing that I have the wrong gpio setting or something like that, or maybe I do not have a complete dts definition for the mcp2515 part to work... any guidance would be greatly appreciated!

Thanks!
Chris

swahren

Hi Chris,

it's better to attach the complete dts file instead of a single part. The "oscillator-frequency" property is wrong according to devicetree binding. You will need to define a clock node which specify the oscillator-frequency and add reference in your can0 node:


mcp_xtal:mcp_xtal{
compatible = "fixed-clock";
clock-frequency = <16000000>;
#clock-cells = <0>;
};


Btw you didn't say nothing about how about the power is connected to the mcp2515 or a kernel version.

Stefan

marker5a

Hi Stefan

First off, thanks for taking the time to help me through this...

Sorry for not including the other relevant info.. I am running ArchLinux as that is what I am accustomed to on my other machines, kernel 4.6.2.  Power is provided to the MCP2515 from the 3.3V rail which is confirmed to be clean... not thinking it is a ps issue in case you were wondering.  Also, the clkout pin on the mcp2515 is giving a solid 2mhz clock out, so the mcp is running and not in sleep mode.

Anyways, I made a few modifications: changed the irq pin to bank0.24 on the imx chip (SSP2_CLK) and added in the clock mode as you described... it seems to be better, but still problematic... now instead of error -2, i get the following:
Quote
[   94.010000] mcp251x spi1.0: spi transfer failed: ret = -22
[   94.010000] mcp251x: probe of spi1.0 failed with error -22

The motive for changing the IRQ to the clock was based on other things i had seen online... moving interrupt to the clock is obviously less desirable because the cpu will be triggering lots of interrupts, but I wanted to eliminate the possibility of the other irq line not triggering interrupts for some reason and thus not allowing the mcp to initialize properly.  Other people have used the clock by accident as itnerrupt, and while throughput did go down, the part would at least still initialize.

The dts file I am using is based off of the imx23-olinuxino.dts file included with the source... below is my modified version with the additions you mentioned:

/*
* Copyright 2012 Freescale Semiconductor, Inc.
*
* Author: Fabio Estevam <fabio.estevam@freescale.com>
*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/

/dts-v1/;
#include <dt-bindings/gpio/gpio.h>
#include "imx23.dtsi"

/ {
model = "i.MX23 Olinuxino Low Cost Board";
compatible = "olimex,imx23-olinuxino", "fsl,imx23";

memory {
reg = <0x40000000 0x04000000>;
};

clocks {
mcp_clk: mcp_clk{
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <16000000>;
};
};

apb@80000000 {
apbh@80000000 {
ssp0: ssp@80010000 {
compatible = "fsl,imx23-mmc";
pinctrl-names = "default";
pinctrl-0 = <&mmc0_4bit_pins_a &mmc0_pins_fixup>;
bus-width = <4>;
broken-cd;
status = "okay";
};

pinctrl@80018000 {
pinctrl-names = "default";
pinctrl-0 = <&hog_pins_a>;

hog_pins_a: hog@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_GPMI_ALE__GPIO_0_17
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

led_pin_gpio2_1: led_gpio2_1@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_SSP1_DETECT__GPIO_2_1
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};
};

ssp1: ssp@80034000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "fsl,imx23-spi";
pinctrl-names = "default";
pinctrl-0 = <&spi2_pins_a>;
clock-frequency = <1000000>;
status = "okay";

can0: can@0 {
compatible = "microchip,mcp2515";
reg = <0>;
clocks = <&mcp_clk>;
interrupt-parent = <&gpio0>;
interrupts = <24 0x0>;
spi-max-frequency = <1000000>;
};
};
};

apbx@80040000 {
lradc@80050000 {
status = "okay";
};

i2c: i2c@80058000 {
pinctrl-names = "default";
pinctrl-0 = <&i2c_pins_b>;
status = "okay";
};

duart: serial@80070000 {
pinctrl-names = "default";
pinctrl-0 = <&duart_pins_a>;
status = "okay";
};

auart0: serial@8006c000 {
pinctrl-names = "default";
pinctrl-0 = <&auart0_2pins_a>;
status = "okay";
};

usbphy0: usbphy@8007c000 {
status = "okay";
};
};
};

ahb@80080000 {
usb0: usb@80080000 {
dr_mode = "host";
vbus-supply = <&reg_usb0_vbus>;
status = "okay";
};
};

regulators {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <0>;

reg_usb0_vbus: regulator@0 {
compatible = "regulator-fixed";
reg = <0>;
regulator-name = "usb0_vbus";
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
enable-active-high;
startup-delay-us = <300>; /* LAN9215 requires a POR of 200us minimum */
gpio = <&gpio0 17 0>;
};
};

leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&led_pin_gpio2_1>;

user {
label = "green";
gpios = <&gpio2 1 GPIO_ACTIVE_HIGH>;
};
};
};


imx23.dtsi file

/*
* Copyright 2012 Freescale Semiconductor, Inc.
*
* The code contained herein is licensed under the GNU General Public
* License. You may obtain a copy of the GNU General Public License
* Version 2 or later at the following locations:
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/

#include "skeleton.dtsi"
#include "imx23-pinfunc.h"

/ {
interrupt-parent = <&icoll>;

aliases {
gpio0 = &gpio0;
gpio1 = &gpio1;
gpio2 = &gpio2;
serial0 = &auart0;
serial1 = &auart1;
spi0 = &ssp0;
spi1 = &ssp1;
usbphy0 = &usbphy0;
};

cpus {
#address-cells = <0>;
#size-cells = <0>;

cpu {
compatible = "arm,arm926ej-s";
device_type = "cpu";
};
};

apb@80000000 {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x80000000 0x80000>;
ranges;

apbh@80000000 {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x80000000 0x40000>;
ranges;

icoll: interrupt-controller@80000000 {
compatible = "fsl,imx23-icoll", "fsl,icoll";
interrupt-controller;
#interrupt-cells = <1>;
reg = <0x80000000 0x2000>;
};

dma_apbh: dma-apbh@80004000 {
compatible = "fsl,imx23-dma-apbh";
reg = <0x80004000 0x2000>;
interrupts = <0 14 20 0
      13 13 13 13>;
interrupt-names = "empty", "ssp0", "ssp1", "empty",
  "gpmi0", "gpmi1", "gpmi2", "gpmi3";
#dma-cells = <1>;
dma-channels = <8>;
clocks = <&clks 15>;
};

ecc@80008000 {
reg = <0x80008000 0x2000>;
status = "disabled";
};

gpmi-nand@8000c000 {
compatible = "fsl,imx23-gpmi-nand";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x8000c000 0x2000>, <0x8000a000 0x2000>;
reg-names = "gpmi-nand", "bch";
interrupts = <56>;
interrupt-names = "bch";
clocks = <&clks 34>;
clock-names = "gpmi_io";
dmas = <&dma_apbh 4>;
dma-names = "rx-tx";
status = "disabled";
};

ssp0: ssp@80010000 {
reg = <0x80010000 0x2000>;
interrupts = <15>;
clocks = <&clks 33>;
dmas = <&dma_apbh 1>;
dma-names = "rx-tx";
status = "disabled";
};

etm@80014000 {
reg = <0x80014000 0x2000>;
status = "disabled";
};

pinctrl@80018000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "fsl,imx23-pinctrl", "simple-bus";
reg = <0x80018000 0x2000>;

gpio0: gpio@0 {
compatible = "fsl,imx23-gpio", "fsl,mxs-gpio";
interrupts = <16>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
};

gpio1: gpio@1 {
compatible = "fsl,imx23-gpio", "fsl,mxs-gpio";
interrupts = <17>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
};

gpio2: gpio@2 {
compatible = "fsl,imx23-gpio", "fsl,mxs-gpio";
interrupts = <18>;
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
};

duart_pins_a: duart@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_PWM0__DUART_RX
MX23_PAD_PWM1__DUART_TX
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

auart0_pins_a: auart0@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_AUART1_RX__AUART1_RX
MX23_PAD_AUART1_TX__AUART1_TX
MX23_PAD_AUART1_CTS__AUART1_CTS
MX23_PAD_AUART1_RTS__AUART1_RTS
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

auart0_2pins_a: auart0-2pins@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_I2C_SCL__AUART1_TX
MX23_PAD_I2C_SDA__AUART1_RX
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

gpmi_pins_a: gpmi-nand@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_GPMI_D00__GPMI_D00
MX23_PAD_GPMI_D01__GPMI_D01
MX23_PAD_GPMI_D02__GPMI_D02
MX23_PAD_GPMI_D03__GPMI_D03
MX23_PAD_GPMI_D04__GPMI_D04
MX23_PAD_GPMI_D05__GPMI_D05
MX23_PAD_GPMI_D06__GPMI_D06
MX23_PAD_GPMI_D07__GPMI_D07
MX23_PAD_GPMI_CLE__GPMI_CLE
MX23_PAD_GPMI_ALE__GPMI_ALE
MX23_PAD_GPMI_RDY0__GPMI_RDY0
MX23_PAD_GPMI_RDY1__GPMI_RDY1
MX23_PAD_GPMI_WPN__GPMI_WPN
MX23_PAD_GPMI_WRN__GPMI_WRN
MX23_PAD_GPMI_RDN__GPMI_RDN
MX23_PAD_GPMI_CE1N__GPMI_CE1N
MX23_PAD_GPMI_CE0N__GPMI_CE0N
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

gpmi_pins_fixup: gpmi-pins-fixup {
fsl,pinmux-ids = <
MX23_PAD_GPMI_WPN__GPMI_WPN
MX23_PAD_GPMI_WRN__GPMI_WRN
MX23_PAD_GPMI_RDN__GPMI_RDN
>;
fsl,drive-strength = <MXS_DRIVE_12mA>;
};

mmc0_4bit_pins_a: mmc0-4bit@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_SSP1_DATA0__SSP1_DATA0
MX23_PAD_SSP1_DATA1__SSP1_DATA1
MX23_PAD_SSP1_DATA2__SSP1_DATA2
MX23_PAD_SSP1_DATA3__SSP1_DATA3
MX23_PAD_SSP1_CMD__SSP1_CMD
MX23_PAD_SSP1_SCK__SSP1_SCK
>;
fsl,drive-strength = <MXS_DRIVE_8mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_ENABLE>;
};

mmc0_8bit_pins_a: mmc0-8bit@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_SSP1_DATA0__SSP1_DATA0
MX23_PAD_SSP1_DATA1__SSP1_DATA1
MX23_PAD_SSP1_DATA2__SSP1_DATA2
MX23_PAD_SSP1_DATA3__SSP1_DATA3
MX23_PAD_GPMI_D08__SSP1_DATA4
MX23_PAD_GPMI_D09__SSP1_DATA5
MX23_PAD_GPMI_D10__SSP1_DATA6
MX23_PAD_GPMI_D11__SSP1_DATA7
MX23_PAD_SSP1_CMD__SSP1_CMD
MX23_PAD_SSP1_DETECT__SSP1_DETECT
MX23_PAD_SSP1_SCK__SSP1_SCK
>;
fsl,drive-strength = <MXS_DRIVE_8mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_ENABLE>;
};

mmc0_pins_fixup: mmc0-pins-fixup {
fsl,pinmux-ids = <
MX23_PAD_SSP1_DETECT__SSP1_DETECT
MX23_PAD_SSP1_SCK__SSP1_SCK
>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

pwm2_pins_a: pwm2@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_PWM2__PWM2
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

lcdif_24bit_pins_a: lcdif-24bit@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_LCD_D00__LCD_D00
MX23_PAD_LCD_D01__LCD_D01
MX23_PAD_LCD_D02__LCD_D02
MX23_PAD_LCD_D03__LCD_D03
MX23_PAD_LCD_D04__LCD_D04
MX23_PAD_LCD_D05__LCD_D05
MX23_PAD_LCD_D06__LCD_D06
MX23_PAD_LCD_D07__LCD_D07
MX23_PAD_LCD_D08__LCD_D08
MX23_PAD_LCD_D09__LCD_D09
MX23_PAD_LCD_D10__LCD_D10
MX23_PAD_LCD_D11__LCD_D11
MX23_PAD_LCD_D12__LCD_D12
MX23_PAD_LCD_D13__LCD_D13
MX23_PAD_LCD_D14__LCD_D14
MX23_PAD_LCD_D15__LCD_D15
MX23_PAD_LCD_D16__LCD_D16
MX23_PAD_LCD_D17__LCD_D17
MX23_PAD_GPMI_D08__LCD_D18
MX23_PAD_GPMI_D09__LCD_D19
MX23_PAD_GPMI_D10__LCD_D20
MX23_PAD_GPMI_D11__LCD_D21
MX23_PAD_GPMI_D12__LCD_D22
MX23_PAD_GPMI_D13__LCD_D23
MX23_PAD_LCD_DOTCK__LCD_DOTCK
MX23_PAD_LCD_ENABLE__LCD_ENABLE
MX23_PAD_LCD_HSYNC__LCD_HSYNC
MX23_PAD_LCD_VSYNC__LCD_VSYNC
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

spi2_pins_a: spi2@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_GPMI_WRN__SSP2_SCK
MX23_PAD_GPMI_RDY1__SSP2_CMD
MX23_PAD_GPMI_D00__SSP2_DATA0
MX23_PAD_GPMI_D03__SSP2_DATA3
>;
fsl,drive-strength = <MXS_DRIVE_8mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_ENABLE>;
};

i2c_pins_a: i2c@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_I2C_SCL__I2C_SCL
MX23_PAD_I2C_SDA__I2C_SDA
>;
fsl,drive-strength = <MXS_DRIVE_8mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_ENABLE>;
};

i2c_pins_b: i2c@1 {
reg = <1>;
fsl,pinmux-ids = <
MX23_PAD_LCD_ENABLE__I2C_SCL
MX23_PAD_LCD_HSYNC__I2C_SDA
>;
fsl,drive-strength = <MXS_DRIVE_8mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_ENABLE>;
};

i2c_pins_c: i2c@2 {
reg = <2>;
fsl,pinmux-ids = <
MX23_PAD_SSP1_DATA1__I2C_SCL
MX23_PAD_SSP1_DATA2__I2C_SDA
>;
fsl,drive-strength = <MXS_DRIVE_8mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_ENABLE>;
};
};

digctl@8001c000 {
compatible = "fsl,imx23-digctl";
reg = <0x8001c000 2000>;
status = "disabled";
};

emi@80020000 {
reg = <0x80020000 0x2000>;
status = "disabled";
};

dma_apbx: dma-apbx@80024000 {
compatible = "fsl,imx23-dma-apbx";
reg = <0x80024000 0x2000>;
interrupts = <7 5 9 26
      19 0 25 23
      60 58 9 0
      0 0 0 0>;
interrupt-names = "audio-adc", "audio-dac", "spdif-tx", "i2c",
  "saif0", "empty", "auart0-rx", "auart0-tx",
  "auart1-rx", "auart1-tx", "saif1", "empty",
  "empty", "empty", "empty", "empty";
#dma-cells = <1>;
dma-channels = <16>;
clocks = <&clks 16>;
};

dcp@80028000 {
compatible = "fsl,imx23-dcp";
reg = <0x80028000 0x2000>;
interrupts = <53 54>;
status = "okay";
};

pxp@8002a000 {
reg = <0x8002a000 0x2000>;
status = "disabled";
};

ocotp@8002c000 {
compatible = "fsl,imx23-ocotp", "fsl,ocotp";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x8002c000 0x2000>;
clocks = <&clks 15>;
};

axi-ahb@8002e000 {
reg = <0x8002e000 0x2000>;
status = "disabled";
};

lcdif@80030000 {
compatible = "fsl,imx23-lcdif";
reg = <0x80030000 2000>;
interrupts = <46 45>;
clocks = <&clks 38>;
status = "disabled";
};

ssp1: ssp@80034000 {
reg = <0x80034000 0x2000>;
interrupts = <2>;
clocks = <&clks 33>;
dmas = <&dma_apbh 2>;
dma-names = "rx-tx";
status = "disabled";
};

tvenc@80038000 {
reg = <0x80038000 0x2000>;
status = "disabled";
};
                };

apbx@80040000 {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x80040000 0x40000>;
ranges;

clks: clkctrl@80040000 {
compatible = "fsl,imx23-clkctrl", "fsl,clkctrl";
reg = <0x80040000 0x2000>;
#clock-cells = <1>;
};

saif0: saif@80042000 {
reg = <0x80042000 0x2000>;
dmas = <&dma_apbx 4>;
dma-names = "rx-tx";
status = "disabled";
};

power@80044000 {
reg = <0x80044000 0x2000>;
status = "disabled";
};

saif1: saif@80046000 {
reg = <0x80046000 0x2000>;
dmas = <&dma_apbx 10>;
dma-names = "rx-tx";
status = "disabled";
};

audio-out@80048000 {
reg = <0x80048000 0x2000>;
dmas = <&dma_apbx 1>;
dma-names = "tx";
status = "disabled";
};

audio-in@8004c000 {
reg = <0x8004c000 0x2000>;
dmas = <&dma_apbx 0>;
dma-names = "rx";
status = "disabled";
};

lradc: lradc@80050000 {
compatible = "fsl,imx23-lradc";
reg = <0x80050000 0x2000>;
interrupts = <36 37 38 39 40 41 42 43 44>;
status = "disabled";
clocks = <&clks 26>;
#io-channel-cells = <1>;
};

spdif@80054000 {
reg = <0x80054000 2000>;
dmas = <&dma_apbx 2>;
dma-names = "tx";
status = "disabled";
};

i2c: i2c@80058000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "fsl,imx23-i2c";
reg = <0x80058000 0x2000>;
interrupts = <27>;
clock-frequency = <100000>;
dmas = <&dma_apbx 3>;
dma-names = "rx-tx";
status = "disabled";
};

rtc@8005c000 {
compatible = "fsl,imx23-rtc", "fsl,stmp3xxx-rtc";
reg = <0x8005c000 0x2000>;
interrupts = <22>;
};

pwm: pwm@80064000 {
compatible = "fsl,imx23-pwm";
reg = <0x80064000 0x2000>;
clocks = <&clks 30>;
#pwm-cells = <2>;
fsl,pwm-number = <5>;
status = "disabled";
};

timrot@80068000 {
compatible = "fsl,imx23-timrot", "fsl,timrot";
reg = <0x80068000 0x2000>;
interrupts = <28 29 30 31>;
clocks = <&clks 28>;
};

auart0: serial@8006c000 {
compatible = "fsl,imx23-auart";
reg = <0x8006c000 0x2000>;
interrupts = <24>;
clocks = <&clks 32>;
dmas = <&dma_apbx 6>, <&dma_apbx 7>;
dma-names = "rx", "tx";
status = "disabled";
};

auart1: serial@8006e000 {
compatible = "fsl,imx23-auart";
reg = <0x8006e000 0x2000>;
interrupts = <59>;
clocks = <&clks 32>;
dmas = <&dma_apbx 8>, <&dma_apbx 9>;
dma-names = "rx", "tx";
status = "disabled";
};

duart: serial@80070000 {
compatible = "arm,pl011", "arm,primecell";
reg = <0x80070000 0x2000>;
interrupts = <0>;
clocks = <&clks 32>, <&clks 16>;
clock-names = "uart", "apb_pclk";
status = "disabled";
};

usbphy0: usbphy@8007c000 {
compatible = "fsl,imx23-usbphy";
reg = <0x8007c000 0x2000>;
clocks = <&clks 41>;
status = "disabled";
};
};
};

ahb@80080000 {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
reg = <0x80080000 0x80000>;
ranges;

usb0: usb@80080000 {
compatible = "fsl,imx23-usb", "fsl,imx27-usb";
reg = <0x80080000 0x40000>;
interrupts = <11>;
fsl,usbphy = <&usbphy0>;
clocks = <&clks 40>;
status = "disabled";
};
};

iio-hwmon {
compatible = "iio-hwmon";
io-channels = <&lradc 8>;
};
};



swahren

Hi Chris,

this return value (22 = EINVAL) says that propably a parameter is wrong. Unfortunately there are many reasons for this so you need to add some debug messages ( pr_info ) into spi_sync ( drivers/spi/spi.c ) to figure out what's wrong.

Maybe you should remove clock-frequency from the spi master node or change the irq pin back to bank0.16.

marker5a

Hey Stefan

Thanks for pointing me in the right direction... I went through and started polluting debug messages anywhere I could, and it appears that the following happens:

1.) spi_driver callback for probe calls the mcp251x_can_probe routine
2.) mcp251x_can_probe calls mcp251x_hw_probe
3.) mcp251x_hw_probe calls mcp251x_hw_reset
4.) mcp251x_hw_probe attemps to send the reset instruction through the mcp251x_spi_trans routine
5.) spi_sync gets called and throws EINVAL during

list_for_each_entry(xfer, &message->transfers, transfer_list) {
if (xfer->rx_buf && xfer->tx_buf)
return -EINVAL;


Going to do some more digging on that, but if you have any further info/hints that may be pertinent, I'd greatly appreciate it! 

Also, regardless of whether or not I can get this thing to work, I owe you a beer if you ever roll through central florida  :D :D

Thanks!
Chris

JohnS

Is there not a Maintainer for it?  Try sending an email to him/her.

And/or try the linux-sunxi ML.

Oh, or armbian site?

John

swahren

#6
Hi Chris,

congratulations i think you've found a missing check in mcp251x driver.

Is this the place in __spi_validate where the issue occure?


/* Half-duplex links include original MicroWire, and ones with
* only one data pin like SPI_3WIRE (switches direction) or where
* either MOSI or MISO is missing.  They can also be caused by
* software limitations.
*/
if ((master->flags & SPI_MASTER_HALF_DUPLEX)
|| (spi->mode & SPI_3WIRE)) {
unsigned flags = master->flags;
list_for_each_entry(xfer, &message->transfers, transfer_list) {
if (xfer->rx_buf && xfer->tx_buf)
return -EINVAL;
if ((flags & SPI_MASTER_NO_TX) && xfer->tx_buf)
return -EINVAL;
if ((flags & SPI_MASTER_NO_RX) && xfer->rx_buf)
return -EINVAL;
}
}


Sorry, the SPI of the MX23 is only half duplex but it looks that the mcp251x driver assumes a full duplex SPI connection.

Edit: Thanks for the offer ;-)

marker5a

Stefan

Indeed, that was the spot where the error was being thrown... just to see if that what was causing it, I commented it out and recompiled, and now it seems to pretend to initialize successfully, (no errors now in dmesg).  The only consequence of said action is that the mcp251x still isn't showing up, but as you said, that seems to be a half-duplex issue vs what the spi driver expects...

So, it seems at this point, Id either have to code/find an update to the mcp251x.c file to force it into half duplex mode... or... the easier thing to do might be to just write the mcp2515 interface in userspace and handle it that way instead.  Either way, I have some coding to do I suppose..

Again, seriosuly appreciate your patience and help on this one Stefan... Also, John, thanks for chiming in on that as well, I'll see if any of those avenues yield anything and report back if they do

Thanks again for your help guys!

Chris

marker5a

For anyone interested in a workaround (maybe nobody cares  ;D ), I did find a temporary solution based on http://www.sciencegizmo.com.au/?p=105.  The user provided a solution to bitbang an interface to a SPI RTC... the nice thing is that bitbang module handles the lack of HW full-duplex transparently.  Eventually, I'd like to modify the mcp driver, but for the time being, this works for me.

The solution ended up being to leave the mcp251x driver as is, and just using the spi-bitbang module.  The modified DTS is shown below for imx233 maxi using the following hw connections:

CS - Pin 10 on UEXT
MISO - Pin 7 on UEXT
MOSI - Pin 8 on UEXT
SCK - Pin 9 on UEXT
INT - Pin 6 on UEXT


/dts-v1/;
#include <dt-bindings/gpio/gpio.h>
#include "imx23.dtsi"

/ {
model = "i.MX23 Olinuxino Low Cost Board";
compatible = "olimex,imx23-olinuxino", "fsl,imx23";

memory {
reg = <0x40000000 0x04000000>;
};
clocks {
mcp_clk: mcp_clk{
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <16000000>;
};
};

spi {
compatible = "spi-gpio";
#address-cells = <0x1>;
#size-cells = <0>;

gpio-mosi = <&gpio0 20 0>;
gpio-miso = <&gpio0 0 0>;
gpio-sck = <&gpio0 24 0>;
cs-gpios = <&gpio0 3 1>;
num-chipselects = <1>;
status = "okay";
   
can0: can@0 {
compatible = "microchip,mcp2515";
reg = <0>;
clocks = <&mcp_clk>;
interrupt-parent = <&gpio1>;
interrupts = <24 0x2>;
spi-max-frequency = <1000000>;
};
};

apb@80000000 {
apbh@80000000 {
ssp0: ssp@80010000 {
compatible = "fsl,imx23-mmc";
pinctrl-names = "default";
pinctrl-0 = <&mmc0_4bit_pins_a &mmc0_pins_fixup>;
bus-width = <4>;
broken-cd;
status = "okay";
};

pinctrl@80018000 {
pinctrl-names = "default";
pinctrl-0 = <&hog_pins_a>;

hog_pins_a: hog@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_GPMI_ALE__GPIO_0_17
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};

led_pin_gpio2_1: led_gpio2_1@0 {
reg = <0>;
fsl,pinmux-ids = <
MX23_PAD_SSP1_DETECT__GPIO_2_1
>;
fsl,drive-strength = <MXS_DRIVE_4mA>;
fsl,voltage = <MXS_VOLTAGE_HIGH>;
fsl,pull-up = <MXS_PULL_DISABLE>;
};
};
};

apbx@80040000 {
lradc@80050000 {
status = "okay";
};

i2c: i2c@80058000 {
pinctrl-names = "default";
pinctrl-0 = <&i2c_pins_b>;
status = "okay";
};

duart: serial@80070000 {
pinctrl-names = "default";
pinctrl-0 = <&duart_pins_a>;
status = "okay";
};

auart0: serial@8006c000 {
pinctrl-names = "default";
pinctrl-0 = <&auart0_2pins_a>;
status = "okay";
};

usbphy0: usbphy@8007c000 {
status = "okay";
};
};
};

ahb@80080000 {
usb0: usb@80080000 {
dr_mode = "host";
vbus-supply = <&reg_usb0_vbus>;
status = "okay";
};
};

regulators {
compatible = "simple-bus";
#address-cells = <1>;
#size-cells = <0>;

reg_usb0_vbus: regulator@0 {
compatible = "regulator-fixed";
reg = <0>;
regulator-name = "usb0_vbus";
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
enable-active-high;
startup-delay-us = <300>; /* LAN9215 requires a POR of 200us minimum */
gpio = <&gpio0 17 0>;
};
};

leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&led_pin_gpio2_1>;

user {
label = "green";
gpios = <&gpio2 1 GPIO_ACTIVE_HIGH>;
};
};
};


I am away from the HW at the moment, but I was able to verify that everything worked properly in loopback mode and was able to send/receive packets..  Going to wire up a can device next on the bus and verify, but this does look promising for anyone that can get away with a bitbang approach.

Anyways, thanks again for your help Stefan!!!

JohnS

I don't know that I'll use it but I'm interested :)

John

marker5a

Hehe, yea, probably will get the same reaction from most people... but, if there is one helpless soul out there like me that can get some use out of this post, then I can feel like I paid it forward  ;D... having you and Stefan chiming in to help newbies like me make me appreciate the OS community more and more every day and is the reason why I will always stick with it.

Anyways, enough of my ranting about things that most of you already know about...  take care and hope to talk to you guys soon again!  (Hopefully I will be on next time with a better solution  ;D )