In this howto I describe how to add a generic kernel mode SPI driver to the BeagleBone kernel source. Of course the methods are nearly the same for different target platforms. I won’t go into the details of writing a kernel mode SPI driver for now.

Let’s start with adding our driver source file (myspidriver.c) to the kernel source tree. Create the file in the drivers/misc directory. Add this to the end of drivers/misc/Makefile:

1
obj-$(CONFIG_MYSPIDRIVER) += myspidriver.o

Add this near the end of drivers/misc/Kconfig:

1
2
3
4
5
config MYSPIDRIVER
    tristate "My SPI driver"
    depends on SPI && SYSFS
    help
        This is my SPI driver.

Add this to your kernel .config to have the driver compiled as a module:

1
CONFIG_MYSPIDRIVER=m

Go to arch/arm/mach-omap2 and edit board-am335xevm.c. Insert this under the other spi_board_info structs:

1
2
3
4
5
6
7
8
9
10
static struct spi_board_info bone_myspidriver_info[] = {
       {
               .modalias      = "myspidriver",
               .irq           = -1,
               .max_speed_hz  = 6500000,
               .bus_num       = 2,
               .chip_select   = 0,
               .mode          = SPI_MODE_0,
       },
};

Configure the SPI bus setting variables as you need. Search for “BeagleBone cape: exporting SPI pins as spidev” and replace those lines with these:

1
2
3
pr_info("BeagleBone cape: initializing myspidriver cape\n");
setup_pin_mux(spi1_pin_mux);
spi_register_board_info(bone_myspidriver_info, ARRAY_SIZE(bone_myspidriver_info));

Initializing GPIO pins

If you want to use some GPIO pins, add this to the end of the am335x_evm_init() function:

1
setup_pin_mux(myspidriver_pin_mux);

Add this after the static struct pinmux_config tt3201_pin_mux[] block:

1
2
3
4
5
static struct pinmux_config myspidriver_pin_mux[] = {
    {"mcasp0_fsr.gpio3_19", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT_PULLUP },
    {"mcasp0_ahclkx.gpio3_21", OMAP_MUX_MODE7 | AM33XX_PIN_INPUT_PULLUP },
    {NULL, 0},
};

This will initialize the gpio3_19 and gpio3_21 pins as GPIO pullup pins. To find out where these pins exactly are on the board, look at the SRM.

Finally

After all of this, recompile your kernel and modules. In the boot message logs, you should see the “BeagleBone cape: initializing myspidriver cape” line.

[…]  http://dp.nonoo.hu/beaglebone-spi-driver/ […]

 

[…]  http://dp.nonoo.hu/beaglebone-spi-driver/ […]

 
sumik 2015-07-23 10:01:15

i am unable to add the spi_board_info into my arch/arm/mach-ompa2/board-am3517evm.c

sumik 2015-07-23 11:26:31

and i am using linux-3.8.13-bone70

 
 
Name (required)
E-mail (required - never shown publicly)
Webpage URL
Comment:
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> in your comment.

About me

Nonoo
I'm Nonoo. This is my blog about music, sounds, filmmaking, amateur radio, computers, programming, electronics and other things I'm obsessed with. ... »

Twitter

Listening now

My favorite artists