3.8 and SPI

OK, I finally got the 3.8 kernel installed and running. I'll post
tomorrow on the procedure I used. Meanwhile has anyone figured out how
to use SPI with this version? There is a group of SPI files in /sys but
none seem to do anything.

John

You need to enable them in DeviceTree.

Here is a quick example of how to enable them using an appended devicetree.

&spi1 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi0_pins_s0>;

};

&spi0 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi1_pins_s0>;

};

If you want spidev support then from memory something like this could work:

&spi1 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi0_pins_s0>;
   compatible = "linux,spidev";
};

&spi0 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi1_pins_s0>;
   compatible = "linux,spidev";
};

The internet and google will help with specifics. This is all just devicetree generics that you need to read about.

OK, I finally got the 3.8 kernel installed and running. I'll post
tomorrow on the procedure I used. Meanwhile has anyone figured out how
to use SPI with this version? There is a group of SPI files in /sys but
none seem to do anything.

John

You need to enable them in DeviceTree.

Here is a quick example of how to enable them using an appended devicetree.

&spi1 {
  status = "okay";
  pinctrl-names = "default";
  pinctrl-0 = <&spi0_pins_s0>;

};

&spi0 {
  status = "okay";
  pinctrl-names = "default";
  pinctrl-0 = <&spi1_pins_s0>;

};

If you want spidev support then from memory something like this could work:

&spi1 {
  status = "okay";
  pinctrl-names = "default";
  pinctrl-0 = <&spi0_pins_s0>;
  compatible = "linux,spidev";
};

&spi0 {
  status = "okay";
  pinctrl-names = "default";
  pinctrl-0 = <&spi1_pins_s0>;
  compatible = "linux,spidev";
};

The internet and google will help with specifics. This is all just devicetree generics that you need to read about.

Apologies, this is more specific, again from the top of my head so will need some more research:

Look at the other devicetree appends in arch/arm/boot/dts for inspiration and examples.

&am33xx_pinmux {
   spi0_pins_s0: spi0_pins_s0 {
     pinctrl-single,pins = <
       0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
       0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */
       0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */
       0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
     >;
   };
};

&spi1 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi0_pins_s0>;

   spidev@0 {
     spi-max-frequency = <24000000>;
     reg = <0>;
     compatible = "linux,spidev";
   };

   spidev@1 {
     spi-max-frequency = <24000000>;
     reg = <1>;
     compatible = "linux,spidev";
   };

};

&spi0 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi1_pins_s0>;

   spidev@0 {
     spi-max-frequency = <24000000>;
     reg = <0>;
     compatible = "linux,spidev";
   };

};

Apologies, this is more specific, again from the top of my head so will
need some more research:

Thanks. I've googled my fingers to the bone today and I'm still as
confused as ever. Is there a user manual or reference manual or
something for DT?

I entered the below text in am33xx.dtsi after the end of the other text.
I think that's what an append is, correct?

I figured out that "okay" should be "ok"

When I run the compiler I get two error messages:

ERROR (phandle_references): Reference to non-existent node or label
"userleds_pins"

ERROR (phandle_references): Reference to non-existent node or label
"spi1_pins_s0"

userleds_pins is in am335x-bone-common.dtsi which I did not touch.

I haven't the faintest idea where to go from here.

Help! Please!

John

Apologies, this is more specific, again from the top of my head so will
need some more research:

Thanks. I've googled my fingers to the bone today and I'm still as
confused as ever. Is there a user manual or reference manual or
something for DT?

https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/Documentation/devicetree?id=refs/tags/next-20130312

http://www.devicetree.org/Device_Tree_Usage

I entered the below text in am33xx.dtsi after the end of the other text.
  I think that's what an append is, correct?

I figured out that "okay" should be "ok"

No, okay should be okay.

When I run the compiler I get two error messages:

ERROR (phandle_references): Reference to non-existent node or label
"userleds_pins"

ERROR (phandle_references): Reference to non-existent node or label
"spi1_pins_s0"

This is because spi1 pins were removed from the bone config recently and I had not realised. I have put them back in with the example below.

userleds_pins is in am335x-bone-common.dtsi which I did not touch.

I haven't the faintest idea where to go from here.

Help! Please!

Look at am33xx.dtsi

Then look at am335x-bone-common.dtsi which includes am33xx.dtsi

Then either add to am335x-bone-common.dtsi, or, make a new file which includes am335x-bone-common.dtsi and make your changes to that.

In my setup I have:

am335x-custom.dtb:

/dts-v1/;

/include/ "am335x-bone-custom.dtsi"

am335x-bone-custom.dtsi:

/include/ "am33xx.dtsi"

/include/ "am335x-bone-common.dtsi"

&am33xx_pinmux {

   spi0_pins_s0: spi0_pins_s0 {
     pinctrl-single,pins = <
       0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
       0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */
       0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */
       0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
     >;
   };

   spi1_pins_s0: spi1_pins_s0 {
     pinctrl-single,pins = <
       0x190 0x33 /* mcasp0_aclkx.spi1_sclk, INPUT_PULLUP | MODE3 */
       0x194 0x33 /* mcasp0_fsx.spi1_d0, INPUT_PULLUP | MODE3 */
       0x198 0x13 /* mcasp0_axr0.spi1_d1, OUTPUT_PULLUP | MODE3 */
       0x19c 0x13 /* mcasp0_ahclkr.spi1_cs0, OUTPU T_PULLUP | MODE3 */
     >;
   };

&spi1 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi0_pins_s0>;

   spidev@0 {
     spi-max-frequency = <24000000>;
     reg = <0>;
     compatible = "linux,spidev";
   };

};

&spi0 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi1_pins_s0>;

   spidev@0 {
     spi-max-frequency = <24000000>;
     reg = <0>;
     compatible = "linux,spidev";
   };

};

I *don't* use spidev so the above spidev@0 parts are an assumption, they may need tweaking to be fully correct.

You then add am335x-custom.dtb to the Makefile, under the entry am335x-bone.dtb then build the kernel. Change your uEnv to point to am335x-custom.dtb and copy that dtb over to your sd card.

This is almost _exact_steps_ and you should be able to get going from here. Anything more and the consultancy quotes might have to start coming out :wink:

Thanks so much Chris. That looks very good.

John

Hi Jack

Were you able to get /dev/spidevxx working from userspace on 3.8 kernel?

Could you share the patch you have done if its in some working form,
instead of inlining in email?

I tried to port your changes, and i dont get the SPI to work from
userspace program.
Could you check if following can be an issue?

@@ -367,7 +368,7 @@
                };

                spi0: spi@48030000 {
- compatible = "ti,omap4-mcspi";
+ compatible = "ti,omap2-mcspi";
                        #address-cells = <1>;
                        #size-cells = <0>;
                        reg = <0x48030000 0x400>;
@@ -383,7 +384,7 @@
                };

                spi1: spi@481a0000 {
- compatible = "ti,omap4-mcspi";
+ compatible = "ti,omap2-mcspi";
                        #address-cells = <1>;
                        #size-cells = <0>;
                        reg = <0x481a0000 0x400>;

Hi Randy,

Yes I was able to get spidev working on the 3.8 kernel. The steps are still pretty much exactly the same as listed below.

Create a custom dtsi with the code snippet below, create a custom dts which includes your custom dtsi, then add your dts to the Makefile. You don't really want to be altering the beaglebone dts as it will interfere with future updates.

This exact dtsi with all the vanilla beaglebone devicetree files that come with the 3.8 kernel will get you up and running with spidev on spi0.1

/include/ "am33xx.dtsi"

/include/ "am335x-bone-common.dtsi"

&am33xx_pinmux {

   spi0_pins_s0: spi0_pins_s0 {
     pinctrl-single,pins = <
       0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
       0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */
       0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */
       0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */

     >;
   };
};

&spi0 {
   status = "okay";
   pinctrl-names = "default";
   pinctrl-0 = <&spi0_pins_s0>;

   spidev@0 {
     spi-max-frequency = <24000000>;
     reg = <0>;
     compatible = "linux,spidev";
   };

};

If you need any more help than this then I'm available for consulting work :slight_smile:

Thanks Jack for the pointer. This is working now.
It was really helpful.

I’m also trying to get SPI working with the 3.8 kernel. I created the dts/dtsi files in setup-scripts/build/tmp-angstrom_v2012_12-eglibc/work/beaglebone-angstrom-linux/gnueabi/linux-mainline-3.8.6-r22b/git/arch/arm/boot/dts, edited the Makefile in that directory and ended up with a file called am335x-bone-spi.dtb after running bitbake. I copied this into the /boot directory on the SD card but can’t figure out how to modify uEnv.txt in order to load it. Any hints? The 3.8 device trees are incredibly confusing to me.

Thanks!

Check your uEnv.txt file for variable: dtb_file=xxxx
that is what gets loaded by default by bootloader as the dtb file. If
you dont change to your new file, it will continue to load the old
one.

Pre DTS/DTB days for arm kernel were much better - but you can see the
advantage now.
You dont have to recompile kernel and you can get new functionality
just by adding a new dtb file. That is the _EXACT_ intent to introduce
dts/dtb infrastructure.
I dont like it, but that's the way forward and if stable and working,
is really good.

Check your uEnv.txt file for variable: dtb_file=xxxx
that is what gets loaded by default by bootloader as the dtb file. If
you dont change to your new file, it will continue to load the old
one.

Pre DTS/DTB days for arm kernel were much better - but you can see the
advantage now.
You dont have to recompile kernel and you can get new functionality
just by adding a new dtb file. That is the _EXACT_ intent to introduce
dts/dtb infrastructure.
I dont like it, but that's the way forward and if stable and working,
is really good.

> I'm also trying to get SPI working with the 3.8 kernel. I created the
> dts/dtsi files in
>
setup-scripts/build/tmp-angstrom_v2012_12-eglibc/work/beaglebone-angstrom-linux/gnueabi/linux-mainline-3.8.6-r22b/git/arch/arm/boot/dts,
> edited the Makefile in that directory and ended up with a file called
> am335x-bone-spi.dtb after running bitbake. I copied this into the /boot
> directory on the SD card but can't figure out how to modify uEnv.txt in
> order to load it. Any hints? The 3.8 device trees are incredibly
confusing
> to me.

Instead of modifying uEnv.txt, you could write your DT files as overlays to
the existing DT, rather than modifying them statically.

I've started trying to make an attempt at documenting this:

I imagine we can have a fairly complete set of overlays included in the
default image for things like spidev and pwm_test drivers.

Thanks, but the only entry in my uEnv.txt file was the following:

optargs=run_hardware_tests quiet

I tried adding this line:

dtb_file=/boot/am335x-bone-spi.dtb

That didn’t work, and neither did:

dtb_file=am335x-bone-spi.dtb

It’s not at all clear to me how you are supposed to debug these sorts of problems. There’s nothing in the boot text or dmesg that gives me a clue as to what’s wrong.

Thanks, but the only entry in my uEnv.txt file was the following:

optargs=run_hardware_tests quiet

Break the auto boot of uboot by pressing enter key.

printenv should give you info on the bootcmd being executed.

At runtime the env file will be read and so will the dtb.

Check if u find this helpful,else later can send u the exact boot args etc once I am at my desk.

Thanks Randy - based upon your suggestion I discovered that the relevant variable was fdtfile, not dtb_file. That said, I still was unable to get my new dtb file to load at boot, even if I copied over the entire contents of the default boot environment into the uEnv.txt file and made the appropriate edits. I ended up overwriting /boot/am335x-bone.dtb with my custom am335x-bone-spi.dtb file and now SPI is up and running.

Jason - the overlays sound interesting, and I’ll definitely follow your progress there. In any case, I’m going to move on now that SPI is working for me. So far the 3.8 kernel seems like a big improvement.