Open main menu

DAVE Developer's Wiki β

Changes

Enabling SPI1 on Linux (Diva)

7,839 bytes added, 13:11, 19 January 2018
no edit summary
This article shows how to enable the SPI1 interface (with CS0 and CS1 chip selects) which can be used in a standard Linux application.
 
=== Pin Mux Option ===
 
SPI1 signals are available at different Diva pins. The following configurations can be used:
 
==== Option 1 ====
{|class="wikitable" style="text-align:right"
!| Signal
!Diva Connector Phisical Pin
!CPU Ball
|-
|SPI1_SCLK
|J1.109
|C18
|-
|SPI1_D0
|J1.31
|E18
|-
|SPI1_D1
|J1.29
|E17
|-
|SPI1_CS0
|J1.144
|C12
|-
|SPI1_CS1
|J1.69
|A15
|}
 
==== Option 2 ====
 
{{ImportantMessage|text=This configuration can be implemented on the DivaEVB-Lite using the on-board expansion connectors.}}
 
{|class="wikitable" style="text-align:right"
!| Signal
!Diva Connector Phisical Pin
!CPU Ball
!DivaEVB-Lite signal
|-
|SPI1_SCLK
|J1.150
|A13
|J10.7
|-
|SPI1_D0
|J1.140
|B13
|J9.15
|-
|SPI1_D1
|J1.142
|D12
|J9.17
|-
|SPI1_CS0
|J1.144
|C12
|J9.19
|-
|SPI1_CS1
|J1.69
|A15
|J11.19
|}
 
=== Linux kernel patches ===
 
{{ImportantMessage|text=The patches below applies to DIVELK 1.0.0 Linux source tree.}}
 
==== Option 1 ====
 
The files <code>arch/arm/mach-omap2/board-diva.c</code> and <code>arch/arm/mach-omap2/diva_pinmux_table.h</code> must be modified according to the following patches:
 
<pre>
diff --git a/arch/arm/mach-omap2/board-diva.c b/arch/arm/mach-omap2/board-diva.c
index f6b77fc..a8b3996 100644
--- a/arch/arm/mach-omap2/board-diva.c
+++ b/arch/arm/mach-omap2/board-diva.c
@@ -356,6 +356,30 @@ static void spi0_init(int evm_id, int profile)
ARRAY_SIZE(diva_spi0_slave_info));
}
+/* -------------- SPI 1 Platform Data -----------------------------*/
+struct spi_board_info __initdata diva_spi1_slave_info[] = {
+ {
+ .modalias = "spidev",
+ .max_speed_hz = 2000000, /* max spi clock (SCK) speed in HZ */
+ .bus_num = 2,
+ .chip_select = 0,
+ },
+ {
+ .modalias = "spidev",
+ .max_speed_hz = 2000000, /* max spi clock (SCK) speed in HZ */
+ .bus_num = 2,
+ .chip_select = 1,
+ },
+};
+
+/* setup spi0 */
+
+static void spi1_init(int evm_id, int profile)
+{
+ setup_pin_mux(spi1_pin_mux);
+ spi_register_board_info(diva_spi1_slave_info,
+ ARRAY_SIZE(diva_spi1_slave_info));
+}
/* ----------- NAND Init ---------------------------------------*/
@@ -878,6 +902,7 @@ static struct evm_dev_cfg diva_dev_cfg[] = {
{mmc0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{rmii1_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{spi0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
+ {spi1_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{usb0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{usb1_init, DEV_ON_BASEBOARD, PROFILE_NONE},
</pre>
 
<pre>
diff --git a/arch/arm/mach-omap2/diva_pinmux_table.h b/arch/arm/mach-omap2/diva_pinmux_table.h
index 5a2646a..9509b46 100644
--- a/arch/arm/mach-omap2/diva_pinmux_table.h
+++ b/arch/arm/mach-omap2/diva_pinmux_table.h
@@ -180,6 +180,21 @@ static struct pinmux_config w1_gpio_pin_mux[] = {
{NULL, 0},
};
+/* Module pin mux for SPI fash */
+static struct pinmux_config spi1_pin_mux[] = {
+ {"ecap0_in_pwm0_out.spi1_sclk", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL
+ | AM33XX_INPUT_EN},
+ {"uart0_ctsn.spi1_d0", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_PULL_UP
+ | AM33XX_INPUT_EN},
+ {"uart0_rtsn.spi1_d1", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL
+ | AM33XX_INPUT_EN},
+ {"mcasp0_ahclkr.spi1_cs0", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_PULL_UP
+ | AM33XX_INPUT_EN},
+ {"xdma_event_intr0.spi1_cs1", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL | AM33XX_PULL_UP
+ | AM33XX_INPUT_EN},
+ {NULL, 0},
+};
+
/*
* the following mux configurations are un-tested but are left here for
* reference. They are all comment-out to avoid "defined but not used" warning
</pre>
 
The kernel must be rebuilt to make these modifications effective.
 
 
==== Option 2 ====
 
The files <code>arch/arm/mach-omap2/board-diva.c</code> and <code>arch/arm/mach-omap2/diva_pinmux_table.h</code> must be modified according to the following patches:
 
<pre>
diff --git a/arch/arm/mach-omap2/board-diva.c b/arch/arm/mach-omap2/board-diva.c
index 42898e9..8f7810d 100644
--- a/arch/arm/mach-omap2/board-diva.c
+++ b/arch/arm/mach-omap2/board-diva.c
@@ -356,6 +356,30 @@ static void spi0_init(int evm_id, int profile)
ARRAY_SIZE(diva_spi0_slave_info));
}
+/* -------------- SPI 1 Platform Data -----------------------------*/
+struct spi_board_info __initdata diva_spi1_slave_info[] = {
+ {
+ .modalias = "spidev",
+ .max_speed_hz = 2000000, /* max spi clock (SCK) speed in HZ */
+ .bus_num = 2,
+ .chip_select = 0,
+ },
+ {
+ .modalias = "spidev",
+ .max_speed_hz = 2000000, /* max spi clock (SCK) speed in HZ */
+ .bus_num = 2,
+ .chip_select = 1,
+ },
+};
+
+/* setup spi1 */
+
+static void spi1_init(int evm_id, int profile)
+{
+ setup_pin_mux(spi1_pin_mux);
+ spi_register_board_info(diva_spi1_slave_info,
+ ARRAY_SIZE(diva_spi1_slave_info));
+}
/* ----------- NAND Init ---------------------------------------*/
@@ -872,11 +896,12 @@ static struct evm_dev_cfg diva_dev_cfg[] = {
{mmc0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{rmii1_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{spi0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
+ {spi1_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{usb0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{usb1_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{mfd_tscadc_init, DEV_ON_BASEBOARD, PROFILE_NONE},
- {mcasp0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
+ //{mcasp0_init, DEV_ON_BASEBOARD, PROFILE_NONE},
{w1_init, DEV_ON_BASEBOARD, PROFILE_NONE},
</pre>
 
{{ImportantMessage|text=With this pinmux configuration, the SPI1 signals are shared with the McASP0 signals. Thus, for a proper setup, the MCASP0 interface initialization must be disabled in <code>evm_dev_cfg diva_dev_cfg[]</code> (please see the patch above).}}
 
<pre>
diff --git a/arch/arm/mach-omap2/diva_pinmux_table.h b/arch/arm/mach-omap2/diva_pinmux_table.h
index f6647b0..d2722a3 100644
--- a/arch/arm/mach-omap2/diva_pinmux_table.h
+++ b/arch/arm/mach-omap2/diva_pinmux_table.h
@@ -179,6 +179,19 @@ static struct pinmux_config w1_gpio_pin_mux[] = {
{NULL, 0},
};
+/* Module pin mux for SPI1 */
+
+
+static struct pinmux_config spi1_pin_mux[] = {
+ {"mcasp0_aclkx.spi1_sclk", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL | AM33XX_INPUT_EN}, // clock
+ {"mcasp0_fsx.spi1_d0", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL | AM33XX_PULL_UP | AM33XX_INPUT_EN}, // d0
+ {"mcasp0_axr0.spi1_d1", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL | AM33XX_INPUT_EN}, // d1
+ {"mcasp0_ahclkr.spi1_cs0", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL | AM33XX_PULL_UP | AM33XX_INPUT_EN}, // cs0
+ {"xdma_event_intr0.spi1_cs1", OMAP_MUX_MODE4 | AM33XX_PULL_ENBL | AM33XX_PULL_UP | AM33XX_INPUT_EN}, // cs1
+ {NULL, 0},
+};
+
+
/*
* the following mux configurations are un-tested but are left here for
* reference. They are all comment-out to avoid "defined but not used" warning
@@ -187,7 +200,7 @@ static struct pinmux_config w1_gpio_pin_mux[] = {
#ifdef UNUSED_DIVA_PINMUX
/* Module pin mux for SPI flash */
-static struct pinmux_config spi1_pin_mux[] = {
+/*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
@@ -197,7 +210,7 @@ static struct pinmux_config spi1_pin_mux[] = {
{"mcasp0_ahclkr.spi1_cs0", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
| AM33XX_PULL_UP | AM33XX_INPUT_EN},
{NULL, 0},
-};
+};*/
/* Module pin mux for rgmii1 */
static struct pinmux_config rgmii1_pin_mux[] = {
</pre>
 
The kernel must be rebuilt to make these modifications effective.
 
=== Using the interface ===
 
Users can access the peripherals connected to the SP1 bus through the <code>spidev</code> interface. For further information, please refer to
 
* https://www.kernel.org/doc/Documentation/spi/spidev
* https://www.kernel.org/doc/Documentation/spi/spidev_test.c
 
=== Patch download ===
 
* Option 1: [[File:Divelk-spi1-enable.patch.zip]]
* Option 2: [[File:Divelk-spi1-enable-divaevb-lite.patch.zip]]
8,221
edits