As we know, we frequently utilize SPI devices on the embedded boards, however, many development boards have no SPI devices, as a result, there is no registration information of SPI devices in it's kernel, you may have no ideas for adding SPI devices if you are not familiar with the kernel.
Don't worry, here, we take MYD-AM335X development board as an example to indicate the way to add SPI flash on the board.
1. First, we need spidev, and we need to add it to the kernel, running it under the root catalog of Linux kernel original code.
1
make
ARCH=arm menuconfig
Choose it in sequence:
Attention: above should all be choosed.
2. Add pin configuration of SPI on arch/arm/mach-omap2/board-am335xevm.c file.
2
3
4
5
6
7
8
/* Module pin for SPI, JBO */
static struct pinmux_config spi_pin_mux[] = {
static
struct
pinmux_config spi_pin_mux[] = {
{"mcasp0_aclkx.spi1_sclk", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL | AM33XX_INPUT_EN },
{
"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_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_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},
"mcasp0_ahclkr.spi1_cs0"
{NULL, 0},
};
3. Add SPI devices and registration function
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
/* Spi slave device, JBO */
static struct spi_board_info am335x_spi1_slave_info[] = {
spi_board_info am335x_spi1_slave_info[] = {
.modalias = "spidev", // to match spidev drive
.modalias =
"spidev"
,
// to match spidev drive
.max_speed_hz = 1000000, // maximal speed
.max_speed_hz = 1000000,
// maximal speed
.bus_num = 2, // indicate the device is on spi1
.bus_num = 2,
// indicate the device is on spi1
.chip_select = 0, //indicate it uses spi1_cs0
.chip_select = 0,
//indicate it uses spi1_cs0
},
/* Setup SPI, JBO */
static void spi_init(int evm_id, int profile)
void
spi_init(
int
evm_id,
profile)
/* Configure SPI */
setup_pin_mux(spi_pin_mux);
spi_register_board_info(am335x_spi1_slave_info,
ARRAY_SIZE(am335x_spi1_slave_info));
return;
return
;
}
4. Add the function call on device initialization list, comment out the MCASP function, as follow
evm_dev_cfg myd_am335x_dev_cfg[] = {
// ..............
//{mcasp0_init, DEV_ON_BASEBOARD, PROFILE_ALL},
{spi_init, DEV_ON_BASEBOARD, PROFILE_ALL},
{NULL, 0, 0},
5. recompile the kernel, you could find spidev 2.0 device node under the /dev/ catalog after you start up the board by this kernel.