Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => iMX233 => Topic started by: wwarczak on October 24, 2012, 04:28:58 PM

Title: SPI Examples
Post by: wwarczak on October 24, 2012, 04:28:58 PM
Hello.

I need to use my device with SPI interface in the module connector UEXT OLINUXINO-MAXi.

My device operates in SPI slave mode and SPI requires transmission
256 bytes at a frequency of 25MHz SCK.

I'm looking for examples of the software side of IMX233 using the hardware SPI interface.
Is the software must be implemented at the kernel level, or it can be an application
user. Are there any examples of hardware modules support SPI on which I could learn from?
Title: Re: SPI Examples
Post by: olimex on October 24, 2012, 04:45:11 PM
to the best of my knowledge iMX233 SPI Linux driver is broken and works only in the ancient LTIB kernel
Fadil who is on this forum is working to push SPI support in 3.x kernel but I'm not sure at what stage it is now
Title: Re: SPI Examples
Post by: jlumme on October 25, 2012, 02:11:35 AM
I'm also interested in SPI examples for imx.. My hope is to use spi flash, but we're still working on the flashing mechanisms...
The broken driver doesnt sound too good ;/
Title: Re: SPI Examples
Post by: Fabio Estevam on October 25, 2012, 05:33:21 AM
I added support for spi flash on mx28evk. Take a look at arch/arm/boot/dts/imx28-evk.dts.

The spi driver works fine and the driver is shared between mx23 and mx28. You just need to add support for imx23-olinuxino.dts.

Fadil will post his patches soon.

Regards,

Fabio Estevam
Title: Re: SPI Examples
Post by: jlumme on October 25, 2012, 06:50:20 AM
Fabio, very interesting - thank you! I will definitely take a look at your example..
Title: Re: SPI Examples
Post by: wigyori on October 29, 2012, 03:45:31 PM
Hi Fabio / Fadil,

Is there a tree that's publicly available with your updates and if we can take patches from it?

Thanks,
-w-
Title: Re: SPI Examples
Post by: Fadil Berisha on October 29, 2012, 04:56:41 PM
Quote from: wigyori on October 29, 2012, 03:45:31 PM
Hi Fabio / Fadil,

Is there a tree that's publicly available with your updates and if we can take patches from it?

Thanks,
-w-

I just uploaded patch at following link:
https://www.dropbox.com/s/0v5morn5a4a0mlv/0001-ARM-imx23-olinuxino-Add-spi-support.patch

I will posts also some test results and small guide how to use.

Regards
Fadil Berisha
Title: Re: SPI Examples
Post by: wigyori on October 29, 2012, 06:26:46 PM
Hi Fadil,

Great stuff, thanks for this. Do you have a repository of the rest of your patches that we can download? I'm referring to the likes of your I2C patch and IIRC there was a USB patchset. Also, it'd be good to know what version or git branch can these apply to.

Thanks a lot,
-w-
Title: Re: SPI Examples
Post by: wwarczak on October 29, 2012, 07:09:27 PM
I made the first attempt with old LTIB kernel and got the following results:

mxs-spi mxs-spi.0: at 0x80034000 mapped to 0xF0034000, irq=20, bus 1, DMA
at 0x80034000 mapped to 0xF0034000, irq=20, bus 1, DMA

I started to test the example mxc_spi_test1.c (LTIB)

I need to get SPI_CLK at 20Mhz or more, whether it is possible for imx233?
I will try kernel 3.x with Fadil patches.
Title: Re: SPI Examples
Post by: Fadil Berisha on October 30, 2012, 04:55:05 AM
Hi wigyori

Quote from: wigyori on October 29, 2012, 06:26:46 PM
Hi Fadil,

Great stuff, thanks for this. Do you have a repository of the rest of your patches that we can download? I'm referring to the likes of your I2C patch and IIRC there was a USB patchset. Also, it'd be good to know what version or git branch can these apply to.

Thanks a lot,
-w-

I posted new SPI Example on this forum (GPIO expander mcp23s08). Right now doing final i2c testing. All patches, including i2c support will move on https://github.com/koliqi/imx23-olinuxino/ and rewrite guide for kernel compilation to match 3.7 with spi/i2c support. Patches apply to linux-next 3.7-rc2. You can apply patches also on 3.7-rc2 from kernel.org. 

Regards
Fadil Berisha
Title: Re: SPI Examples
Post by: wwarczak on November 02, 2012, 03:58:12 PM
I still have problems with the SPI:

1) On the old LTIB 2.6.31-626-g602af1c_OLinuXino kernel driver is available but does not work properly:

Configuration: noinitrd console=ttyAM0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2

dmesg:

mxs-spi mxs-spi.0: Max possible speed 96000 = 96000000/2 kHz
mxs-spi mxs-spi.0: at 0x80034000 mapped to 0xF0034000, irq=20, bus 1, DMA

device:

0 crw-rw----    1 root     root     153,   0 Jan  1 00:00 /dev/spidev1.0

When sending data to the device function write hang.

echo "test" > /dev/spidev1.0 hangs until CTR-C

SCK and MOSI lines are working properly, but no Slave Select signal is generated


2) On the new linux-3.7-rc3 kernel from kernel.org:

* NOT applied patches 0001-usb_led.patch  (merged in kernel 3.7)
* applied patch: 0001-ARM-imx23-olinuxino-Add-spi-support.patch
* default config witch: make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- mxs_defconfig 

in configuration set options:

CONFIG_SPI=y
CONFIG_SPI_BITBANG=m
CONFIG_SPI_GPIO=m
CONFIG_SPI_MXS=y
CONFIG_SPI_SPIDEV=y

kernel compiled and installed without errors

Dmesg: no spi info:

Linux version 3.7.0-rc3 (root@imx233develDebian)
Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2

Sys filesystem:

/sys/bus/spi
/sys/bus/spi/devices
/sys/bus/spi/drivers
/sys/bus/spi/drivers/spidev
/sys/bus/spi/drivers/spidev/bind
/sys/bus/spi/drivers/spidev/uevent
/sys/bus/spi/drivers/spidev/unbind
/sys/bus/spi/drivers/mtd_dataflash
/sys/bus/spi/drivers/mtd_dataflash/bind
/sys/bus/spi/drivers/mtd_dataflash/uevent
/sys/bus/spi/drivers/mtd_dataflash/unbind
/sys/bus/spi/uevent
/sys/bus/spi/drivers_probe
/sys/bus/spi/drivers_autoprobe
/sys/bus/platform/drivers/mxs-spi
/sys/bus/platform/drivers/mxs-spi/bind
/sys/bus/platform/drivers/mxs-spi/uevent
/sys/bus/platform/drivers/mxs-spi/unbind
/sys/class/spi_master
/sys/class/spidev
/sys/module/spidev
/sys/module/spidev/parameters
/sys/module/spidev/parameters/bufsiz
/sys/module/spidev/uevent

My application uses API described in Documentation/spi/spidev. I need some more help witch kernel configuration.
Title: Re: SPI Examples
Post by: wwarczak on November 02, 2012, 11:19:40 PM
Hello.
After manually applying patches from: https://www.olimex.com/forum/index.php?topic=232.0
there is some progress:

dmesg | grep spi

[    0.000000] Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2
[    0.120000] bus: 'spi': registered
[    0.120000] device class 'spi_master': registering
[    0.920000] bus: 'spi': add driver mtd_dataflash
[    0.930000] device class 'spidev': registering
[    0.930000] bus: 'spi': add driver spidev
[    0.930000] bus: 'platform': add driver mxs-spi
[    0.930000] bus: 'platform': driver_probe_device: matched device 80034000.ssp with driver mxs-spi
[    0.930000] bus: 'platform': really_probe: probing driver mxs-spi with device 80034000.ssp
[    0.930000] device: 'spi32766': device_add
[    0.930000] PM: Adding info for No Bus:spi32766
[    0.930000] mxs-spi 80034000.ssp: registered master spi32766 (dynamic)
[    0.930000] spi spi32766.0: setup mode 0, 8 bits/w, 40000000 Hz max --> 0
[    0.930000] device: 'spi32766.0': device_add
[    0.940000] bus: 'spi': add device spi32766.0
[    0.940000] PM: Adding info for spi:spi32766.0
[    0.940000] mxs-spi 80034000.ssp: registered child spi32766.0
[    0.940000] driver: '80034000.ssp': driver_bound: bound to device 'mxs-spi'
[    0.940000] bus: 'platform': really_probe: bound device 80034000.ssp to driver mxs-spi

[root@imx233 dev]# find /sys/ | grep spi
/sys/bus/spi
/sys/bus/spi/devices
/sys/bus/spi/devices/spi32766.0
/sys/bus/spi/drivers
/sys/bus/spi/drivers/spidev
/sys/bus/spi/drivers/spidev/bind
/sys/bus/spi/drivers/spidev/uevent
/sys/bus/spi/drivers/spidev/unbind
/sys/bus/spi/drivers/mtd_dataflash
/sys/bus/spi/drivers/mtd_dataflash/bind
/sys/bus/spi/drivers/mtd_dataflash/uevent
/sys/bus/spi/drivers/mtd_dataflash/unbind
/sys/bus/spi/uevent
/sys/bus/spi/drivers_probe
/sys/bus/spi/drivers_autoprobe
/sys/bus/platform/drivers/mxs-spi
/sys/bus/platform/drivers/mxs-spi/bind
/sys/bus/platform/drivers/mxs-spi/80034000.ssp
/sys/bus/platform/drivers/mxs-spi/uevent
/sys/bus/platform/drivers/mxs-spi/unbind
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/power
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/device
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/subsystem
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/uevent
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/power
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/modalias
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/subsystem
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0/uevent
/sys/class/spi_master
/sys/class/spi_master/spi32766
/sys/class/spidev
/sys/module/spidev
/sys/module/spidev/parameters
/sys/module/spidev/parameters/bufsiz
/sys/module/spidev/uevent

but still no spi device in /dev (udev installed)


Title: Re: SPI Examples
Post by: Fadil Berisha on November 03, 2012, 02:39:48 AM
Quote from: wwarczak on November 02, 2012, 11:19:40 PM


but still no spi device in /dev (udev installed)

What device you have atached on spi interface?
For each device you need activate driver with kernel menuconfig and  create node on file imx23-olinuxino.dts as shown on https://www.olimex.com/forum/index.php?topic=232.msg912#msg912 and this template:

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

See examples for:

1) spi flash sst25vf016b, and

2) spi GPIO expander mcp23s08

Fadil Berisha
Title: Re: SPI Examples
Post by: benowski on November 04, 2012, 03:42:30 PM
Did anyone knows what to write in node spi device for mcp2515 CAN Controller?

I think it should be combined somehow with declaration in file ..\linux-mainline/include/linux/can/platform\mcp251x.h

/**
* struct mcp251x_platform_data - MCP251X SPI CAN controller platform data
* @oscillator_frequency:       - oscillator frequency in Hz
* @irq_flags:                  - IRQF configuration flags
* @board_specific_setup:       - called before probing the chip (power,reset)
* @transceiver_enable:         - called to power on/off the transceiver
* @power_enable:               - called to power on/off the mcp *and* the
*                                transceiver
*
* Please note that you should define power_enable or transceiver_enable or
* none of them. Defining both of them is no use.
*
*/

struct mcp251x_platform_data {
   unsigned long oscillator_frequency;
   unsigned long irq_flags;
   int (*board_specific_setup)(struct spi_device *spi);
   int (*transceiver_enable)(int enable);
   int (*power_enable) (int enable);
};
Title: Re: SPI Examples
Post by: Fadil Berisha on November 04, 2012, 07:28:02 PM
Quote from: benowski on November 04, 2012, 03:42:30 PM
Did anyone knows what to write in node spi device for mcp2515 CAN Controller?


SPI slave device mcp2515 would be presented on imx23-olinuxino.dts DT file with node like this (fill value for oscilator-frequency & irq-flag):

can0: mcp2515@0 {
compatible = "microchip,mcp2515";
reg = <0>;
spi-max-frequency = <16000000>;
                                        oscillator-frequency = <      >;
                                        irq-flag = < >;
};

Since mcp2515 driver is not device tree compatible, you need to modify driver in order to accept platform data from DT file. If needed, you can pass also other board_specific_setup data.
How to modify driver,  example I wrote is here https://www.olimex.com/forum/index.php?topic=232.msg912#msg912

Fadil Berisha
Title: Re: SPI Examples
Post by: benowski on November 05, 2012, 12:41:01 PM
Thanks for fast respond! If I deal with mcp251x, I will write about results.
I am doing it with tutorial barebox on olinuxino.md.
I have already compiled kernel. Now I try to compile barebox.
And I got into trouble.

Fadil, do you know what could be a problem?

  CHK     include/generated/utsrelease.h
  SYMLINK include/config.h -> arch/arm/boards/imx233-olinuxino//config.h
  CC      scripts/bareboxenv-target
In file included from /home/andrzej/olinuxino/gcc-arm-none-eabi-4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/include/dirent.h:6:0,
                 from scripts/bareboxenv.c:28:
/home/andrzej/olinuxino/gcc-arm-none-eabi-4_6-2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/include/sys/dirent.h:10:2: error: #error "<dirent.h> not supported"
In file included from scripts/bareboxenv.c:34:0:
scripts/compiler.h:27:22: fatal error: sys/mman.h: No such file or directory
compilation terminated.
make[1]: *** [scripts/bareboxenv-target] Błąd 1
make: *** [scripts] Błąd 2
Title: Re: SPI Examples
Post by: Fadil Berisha on November 05, 2012, 04:47:28 PM
Quote from: benowski on November 05, 2012, 12:41:01 PM

I am doing it with tutorial barebox on olinuxino.md.
I have already compiled kernel. Now I try to compile barebox.


To compile barebox use arm-linux-gnueabi. Now, olinuxino is in barebox mainline and  no need to apply any olinuxino patches on barebox. If still getting problem, please start new topic about compiling barebox and continue here discussion about SPI Examples.

Fadil Berisha
   
Title: Re: SPI Examples
Post by: benowski on November 12, 2012, 01:31:19 PM
Hi. I have compiled kernel with dts:

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

             can0: mcp2515@0 {
               compatible = "microchip,mcp2515";
               reg = <0>;
               spi-max-frequency = <16000000>;
                                        oscillator-frequency = <12000000>;
                                        irq-flag = <&gpio0 17 0>;//MX23_INT_GPIO0=16
            };

root@debian:~# dmesg | grep spi
[    0.900000] mxs-spi 80034000.ssp: registered master spi32766 (dynamic)
[    0.910000] spi spi32766.0: setup mode 0, 8 bits/w, 16000000 Hz max --> 0
[    0.910000] mxs-spi 80034000.ssp: registered child spi32766.0
[    0.920000] mcp251x spi32766.0: Andrzej tu byl. Probing..1
[    0.920000] mcp251x spi32766.0: setup mode 0, 8 bits/w, 16000000 Hz max --> 0
[    0.930000] mcp251x spi32766.0: spi transfer failed: ret = -22
[    0.940000] mcp251x spi32766.0: spi transfer failed: m = -1014833736
[    0.950000] mcp251x spi32766.0: spi transfer failed: ret = -22
[    0.950000] mcp251x spi32766.0: spi transfer failed: m = -1014833632
[    0.960000] mcp251x spi32766.0: spi transfer failed: ret = -22
[    0.970000] mcp251x spi32766.0: spi transfer failed: m = -1014833632
[    0.970000] mcp251x spi32766.0: CANSTAT 0x8a CANCTRL 0x13
[    0.970000] mcp251x spi32766.0: Probe failed adi mcp251x_hw_probe
[    0.980000] mcp251x spi32766.0: probe failed adi pdata->power_enable
root@debian:~# dmesg | grep can
[    0.910000] vcan: Virtual CAN interface driver
[    1.140000] of_get_named_gpio_flags: can't parse gpios property
[    1.250000] can: controller area network core (rev 20120528 abi 9)
[    1.270000] can: raw protocol (rev 20120528)
[    1.270000] can: broadcast manager protocol (rev 20120528 t)


I think spi is not working, because i watch pins(9,10,11) on CON2 with oscyloscope and nothing appeard.
Fadil, do you know what to do enable or test spi?
Title: Re: SPI Examples
Post by: Fadil Berisha on November 12, 2012, 07:22:51 PM
Quote from: benowski on November 12, 2012, 01:31:19 PM

I think spi is not working, because i watch pins(9,10,11) on CON2 with oscyloscope and nothing appeard.
Fadil, do you know what to do enable or test spi?

You do not have any activity because your driver in use - fail to probe. See this error:

[    0.970000] mcp251x spi32766.0: Probe failed adi mcp251x_hw_probe

I see you passing variables oscillator-frequency and irq-flag, but question is:
did you adapt driver mcp2515 to accept variables from device tree DT file?

Fadil Berisha
Title: Re: SPI Examples
Post by: benowski on November 12, 2012, 07:58:28 PM
"did you adapt driver mcp2515 to accept variables from device tree DT file?"

Yes. here is a diff(path) to driver
https://www.dropbox.com/s/kybyp66nkwjblml/mcp251x_path

i try also your port expander(and your path dts to it) and it was working. I saw on osciloscope clk, MOSI etc

or maybe there is a problem with
"
#ifdef CONFIG_OF
static const struct of_device_id mcp251x_dt_ids[] = {
   { .compatible = "microchip,mcp2515", },
   { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, mcp251x_dt_ids);
#else
#define mcp251x_dt_ids NULL
#endif
"
Title: Re: SPI Examples
Post by: Fadil Berisha on November 12, 2012, 08:29:02 PM
Quote from: benowski on November 12, 2012, 07:58:28 PM
"did you adapt driver mcp2515 to accept variables from device tree DT file?"

Yes. here is a diff(path) to driver
https://www.dropbox.com/s/kybyp66nkwjblml/mcp251x_path

i try also your port expander(and your path dts to it) and it was working. I saw on osciloscope clk, MOSI etc

or maybe there is a problem with
"
#ifdef CONFIG_OF
static const struct of_device_id mcp251x_dt_ids[] = {
   { .compatible = "microchip,mcp2515", },
   { /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, mcp251x_dt_ids);
#else
#define mcp251x_dt_ids NULL
#endif
"
Your patch looks good to me, but because of this info:

[    0.980000] mcp251x spi32766.0: probe failed adi pdata->power_enable

I think you need to check definitions about power enable. How power_anable is handled in your board? Is schemtic of your module available?

EDIT Message: Second comment - In DT you have

irq-flag = <&gpio0 17 0>;//MX23_INT_GPIO0=16

With this you passing GPIO pin 17 as interrupt input.
Check documentation of your board. My understanding is that you need to pass irq FLAG not interrupt pin.

If your documentation show that you need to handle interrupts, in that case irq-flag = <&gpio0 17 0> is OK but in driver you need to declare gpio pin 17 as input pin and point to interrupt handler.

Fadil Berisha
Title: Re: SPI Examples
Post by: benowski on November 12, 2012, 09:36:59 PM
"I think you need to check definitions about power enable. How power_anable is handled in your board? Is schemtic of your module available? "

I didn't plug Can controller to the olinuxino board yet. Firstly I wanted to check if port spi is working. But unfortunately nothing appeared on osciloscope.
You can find example schematic here : http://cor-net.org/2009/09/can-interface-for-the-mini2440-dev-board/

"How power_anable is handled in your board?" I think one pin of gpio  should be connected with CS pin in mcp251x.

I wrote <&gpio0 17 0> in dts, because I do not know what exactly to insert there,it was just to compile dts file with succes
But for sure, in mcp251x datasheet, state that it is Interrupt output pin, so my master device(olinuxino) should have configured this as input. Am i right?
Title: Re: SPI Examples
Post by: Fadil Berisha on November 12, 2012, 10:57:40 PM
Quote from: benowski on November 12, 2012, 09:36:59 PM

But for sure, in mcp251x datasheet, state that it is Interrupt output pin, so my master device(olinuxino) should have configured this as input. Am i right?
Yes, schematics show that you need to define GPIO pin as input and connect on nINT. In that case. need also section in driver with gpio definition as input and definition for interrupt handler.

You can expect activity on SPI interface only after driver is load with no error. Before connecting on olinuxino check also voltage levels.

Fadil Berisha

Title: Re: SPI Examples
Post by: jlumme on December 11, 2012, 01:11:40 PM
I'm having some issues adding SPI device to the kernel. I'm trying to add my SPI flash chip.

I have followed Fadil's suggestions as in: https://www.olimex.com/forum/index.php?topic=232.0

My imx23-olinuxino.dts looks like this:

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

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

//Flash chip
flash: sst25vf64c@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "sst,sst25vf64c";
spi-max-frequency = <40000000>;
reg = <0>;
};
};

pinctrl@80018000 {
....


I can see that my dtb is compiled, and if I look at the binary, I can see that "sst25vf64c" looks like it has been added to the blob.

In kernel I have following SPI flags:

CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y


But still during boot, I get nothing:

# dmesg |grep -i spi
[    0.000000] Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2
#


Any ideas what might be the problem here ?
I'm positive that I clean and recreate kernel and also bootlets, but still nothing.. (?)
Title: Re: SPI Examples
Post by: Fadil Berisha on December 11, 2012, 07:53:40 PM
Quote from: jlumme on December 11, 2012, 01:11:40 PM
I can see that my dtb is compiled, and if I look at the binary, I can see that "sst25vf64c" looks like it has been added to the blob.

In kernel I have following SPI flags:

CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y


But still during boot, I get nothing:
Is driver for sst25vf64c in .config? Also, make sure to append DT blob on kernel.

Fadil Berisha
Title: Re: SPI Examples
Post by: jlumme on December 12, 2012, 03:28:41 AM
Quote from: Fadil Berisha on December 11, 2012, 07:53:40 PM

Is driver for sst25vf64c in .config? Also, make sure to append DT blob on kernel.

Fadil Berisha
Hi Fadil,

I was trying this one step at the time, and thought I would first see what happens in kernel if I add the device, would it try to load a driver or not.. Yes, I'm sure I was appending also the dtb to kernel.

Now that you mentioned this, I did a bit of searching, and it seems that sst25vf chips are supported by same driver as in your example (m25p80.c), but it's missing support for 64Mbit chip (largest I see is for 32bits). But adding a new one with proper JEDEC ID is not a big thing (if it works ;) ).

I will modify the dts once I get back home, and make sure CONFIG_MTD_M25P80 is also set in config.. Thanks for your help!
Title: Re: SPI Examples
Post by: jlumme on December 12, 2012, 01:27:25 PM
Still no luck :o

I have pasted my dtsi and dts files here:

imx23.dtsi: http://paste.ubuntu.com/1427335/
imx23-olinuxino.dts: http://paste.ubuntu.com/1427336/

I can clearly see that my modified DTB is added, you can see my change of model name to DTS (model = "i.MX23 Olinuxino Low Cost Board TEST" ) and in kernel boot I can see:
[    0.000000] Booting Linux on physical CPU 0                                                                                                                 
[    0.000000] Linux version 3.6.0_test_alpha1-09647-gddee6b1-dirty (jlumme@simppa) (gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-1ubuntu1) ) #8 Wed Dec 12 20:16:042
[    0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177                                                                                   
[    0.000000] CPU: VIVT data cache, VIVT instruction cache                                                                                                     
[    0.000000] Machine: Freescale i.MX23 (Device Tree), model: i.MX23 Olinuxino Low Cost Board TEST               


My kernel config contains now these flags:
CONFIG_SPI=y
CONFIG_SPI_DEBUG=y
CONFIG_SPI_MASTER=y
CONFIG_SPI_BITBANG=y
CONFIG_SPI_GPIO=y
&
CONFIG_MTD_M25P80=y


In the driver I have added the proper JEDEC for my 64bit chip:
kernel/drivers/mtd/devices/m25p80.c:
{ "sst25vf064b", INFO(0xbf254b, 0, 64 * 1024,128, SECT_4K) }, //jlumme


And still dmesg shows zero messages for SPI  :-\
# dmesg | grep spi                                                                                                                                             
[    0.000000] Kernel command line: noinitrd console=ttyAMA0,115200 root=/dev/mmcblk0p2 rw rootwait ssp1=mmc ssp2=spi2                                         


Any hints ?
Title: Re: SPI Examples
Post by: Fadil Berisha on December 12, 2012, 05:32:46 PM
Hi jlumme,

Your kernel is Linux version 3.6.0_test_alpha1-09647-gddee6b1-dirty. Check is there SPI support for imx23 SoC. If not, use latest version 3.7 (there is also olinuxino SPI support).

Fadil Berisha

Title: Re: SPI Examples
Post by: jlumme on December 13, 2012, 08:01:09 AM
Fadil, thanks your for your reply.
Indeed it seems that there is CONFIG_MXS_SPI flag now available in new (3.7) kernels..
I seem to have an issue getting the kernel to boot now, though. I will start another thread, as this might be something others will bump into as well if they try to compile a kernel from kernel.org
Title: Re: SPI Examples
Post by: jlumme on December 15, 2012, 05:21:19 AM
After successfully compiling latest kernel, and applying the additions I mentioned before, my flash chip is now recognized as expected.

Now, if I only I knew how to use it on Linux side... ;)

Thanks Fadil for your advice on the newer kernel, that was the trick!
Title: Re: SPI Examples
Post by: jlumme on January 01, 2013, 09:36:46 AM
Has anyone successfully used spidev to communicate over SPI from user land ? I would like to talk to micro controller over the bus.
I've seem to have got a new device added to the bus with this dtsi for SSP2:


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

    flash: m25p80@0 {
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "sst,sst25vf064b";
        spi-max-frequency = <10000000>;
         reg = <0>;
    };
    ucontroller: spidev@1 {
        compatible = "linux,spidev";
        spi-max-frequency = <1000000>;
        reg = <1>;
    };



I've also added CS1 for SSP2:

//Added for chip select in SPI2
spi2_pin_cs1: spi2@1 {
    reg = <0>;
    fsl,pinmux-ids = <
    0x0042 /* MX23_PAD_GPMI_D03__SSP2_DATA4 */
    >;
    fsl,drive-strength = <1>;
    fsl,voltage = <1>;
    fsl,pull-up = <1>;
};


Now, after boot when I mount devtmpfs, spidev is shown under /dev.
The whole system has this SPI stuff:

# find / -name "spi*"
/sys/bus/spi
/sys/bus/spi/devices/spi32766.0
/sys/bus/spi/devices/spi32766.1
/sys/bus/spi/drivers/spidev
/sys/bus/spi/drivers/spidev/spi32766.1
/sys/bus/platform/drivers/spi_gpio
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.0
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.1
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.1/spidev
/sys/devices/80000000.apb/80000000.apbh/80034000.ssp/spi_master/spi32766/spi32766.1/spidev/spidev32766.1
/sys/class/spi_master
/sys/class/spi_master/spi32766
/sys/class/spidev
/sys/class/spidev/spidev32766.1
/sys/module/spidev
/home/default/spitest
/dev/spidev32766.1


But, when trying to run the spidev_test.c code from Documentation/spi, I seem to get strange "Invalid argument" (I don't specify anything).
The file descriptor for spidev is correct (/dev/spidev32766.1), and when I launch the test program, I see some activity in both, spidev driver, and also spi-mxs.c when main function sets up the spi details (bits, speed and spi mode).
But for some reason, I always just get -22 when trying to access the spi bus through spidev..

Title: Re: SPI Examples
Post by: jlumme on January 02, 2013, 06:17:10 AM
Mmkay, after some digging, it turns out spi.c was causing my problems.
I didn't check who was forcing (spi-mxs.c?) half-duplex transfers, but it looks correct accorging to mx23 datasheet ch. 21.5.1.

Anyhow, the problem was that spidev_test.c code was assingning rx and tx buffers, and spi.c was having none of that here:
static int __spi_async(struct spi_device *spi, struct spi_message *message)
{
   ....
   if ((master->flags & SPI_MASTER_HALF_DUPLEX)
|| (spi->mode & SPI_3WIRE)) {
      ....
      if (xfer->rx_buf && xfer->tx_buf) {
return -EINVAL;
      }


After zeroing rx buffer from my transfer data packet, it looks to work as expected.
As usual, user error  8)