Enable spi2.1 on BeagleBone

spi2.1Well, the SPI 2.0 is enabled in user space and has been for a while now. However, the Replicape uses both SPI 2.0 (CS0) and SPI 2.1 (CS1). So how can that be enabled as well? Newer versions of the Linux kernel enables automatic pin-muxing by reading the contents of the EEPROM, but you still need to recompile the kernel to enable a second channel for the SPI.

This post builds on my previous post about compiling a new kernel for BeagleBone.

To get stuff into your EEPROM so the kernel will mux the pins right, have a look at this page. The guy has a couple of methods, my personal favourite is the bone-script.

Where is the file?
There is really only one file to worry about when configuring the features of the kernel for BeagleBone. The file of interest for adding a new cape is “board-am335xevm.c” located in:

build/tmp-angstrom_v2012_05-eglibc/work/beaglebone-angstrom-linux-gnueabi/linux-ti33x-psp-3.2.34-r18a+gitr720e07b4c1f687b61b147b31c698cb6816d72f01/git/arch/arm/mach-omap2

Make a copy of it, so you can make patch with the diff later.

The function of interest is the “beaglebone_cape_setup” that handles all cape specific setups. That is where the pin-muxing goes.
At the bottom of that function is where the default setup occurs under the goto-label “out2:”

if(beaglebone_spi1_free == 1) {
			beaglebone_spi1_free = 0;
			pr_info("BeagleBone cape: exporting SPI pins as spidev\n");
			setup_pin_mux(spi1_pin_mux);					
			spi_register_board_info(bone_spidev2_info, ARRAY_SIZE(bone_spidev2_info));				
		}

This only happens if none of the capes have claimed the SPI1 (which appears as SPI2.0 in the Linux file system). It might be a good idea to change the text in the “pr_info” function so you know on startup that the chnages you have made really did occur.

So to enable spi2.1, the “spi_register_board_info” function must be changed. Initially it looks like this:

static struct spi_board_info bone_spidev2_info[] = {
	{
		.modalias      = "spidev",
		.irq           = -1,
		.max_speed_hz  = 12000000,
		.bus_num       = 2,
		.chip_select   = 0,
	},
};

Change it to this:

static struct spi_board_info bone_spidev2_info[] = {
	{
		.modalias      = "spidev",
		.irq           = -1,
		.max_speed_hz  = 12000000,
		.bus_num       = 2,
		.chip_select   = 0,
	},
	{
		.modalias      = "spidev",
		.irq           = -1,
		.max_speed_hz  = 12000000,
		.bus_num       = 2,
		.chip_select   = 1,
	},
};

You see what I did there? The second structure is identical, only it has .chip_slect = 1.

Enable the pin-muxing – the wrong way
If you only want SPI2.1 enabled without having to make a cape just to pin-mux right, you can simply change the “spi1_pin_mux” structure. I added the last entry for the spi1_cs1-pin.

/* Module pin mux for SPI flash */
static struct pinmux_config spi1_pin_mux[] = {
	{"mcasp0_aclkx.spi1_sclk", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
		| AM33XX_INPUT_EN},
	{"mcasp0_fsx.spi1_d0", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
		| AM33XX_PULL_UP | AM33XX_INPUT_EN},
	{"mcasp0_axr0.spi1_d1", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
		| AM33XX_INPUT_EN},
	{"mcasp0_ahclkr.spi1_cs0", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
		| AM33XX_PULL_UP | AM33XX_INPUT_EN},
	{"ecap0_in_pwm0_out.spi1_cs1", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
		| AM33XX_PULL_UP | AM33XX_INPUT_EN},
	{NULL, 0},
};

Pin-muxing based on EEPROM – the right way
On the Replicape, the pins are defined in the EEPROM, so I simply add the :

	if (!strncmp( "Replicape", cape_config.name, 9)) {
		pr_info( "BeagleBone cape: initializing Replicape 3D printer cape\n");
		bone_io_config_from_cape_eeprom();
		return; 
	}

This function should be placed somewhere in the “beaglebone_cape_setup” function. There are several others there, so a place should be easy to find..

Now the “pin-muxing the wrong way” is just a hack so it is not necessary to send a patch up stream, but for capes you are planning on selling, it would be great with support for it right out of the box. Look in the comments on the compiling a kernel for BeagleBone for info on that.

3 thoughts on “Enable spi2.1 on BeagleBone

  1. Pingback: How to Enable SPI2.1 on a BeagleBone « adafruit industries blog

  2. {“ecap0_in_pwm0_out.spi1_cs1″, OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
    | AM33XX_PULL_UP | AM33XX_INPUT_EN},

    I believe it should be OMAP_MUX_MODE2 from the Beaglebone schematic.

    -Sriram

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>