嵌入式爱好者

335xs-2把spi修改成can口方法

2016-11-1 10:15| 发布者: 技术学习| 查看: 1533| 评论: 0

类目: AM335x系列产品  >  Linux     文档编号: 73

spi接口是可以修改成can使用的,具体的方法是在内核中修改,具体方法见下:
--- a/arch/arm/configs/ok335xs2_evm_linux_defconfig
+++ b/arch/arm/configs/ok335xs2_evm_linux_defconfig
@@ -725,7 +725,7 @@ CONFIG_CAN_BCM=y
 CONFIG_CAN_DEV=y
 CONFIG_CAN_CALC_BITTIMING=y
 # CONFIG_CAN_TI_HECC is not set
-# CONFIG_CAN_MCP251X is not set
+CONFIG_CAN_MCP251X=y
 # CONFIG_CAN_SJA1000 is not set
 # CONFIG_CAN_C_CAN is not set
 CONFIG_CAN_D_CAN=y

--- a/arch/arm/configs/ok335xs2_evm_linux_sdio_defconfig
+++ b/arch/arm/configs/ok335xs2_evm_linux_sdio_defconfig
@@ -725,7 +725,7 @@ CONFIG_CAN_BCM=y
 CONFIG_CAN_DEV=y
 CONFIG_CAN_CALC_BITTIMING=y
 # CONFIG_CAN_TI_HECC is not set
-# CONFIG_CAN_MCP251X is not set
+CONFIG_CAN_MCP251X=y
 # CONFIG_CAN_SJA1000 is not set
 # CONFIG_CAN_C_CAN is not set
 CONFIG_CAN_D_CAN=y

--- a/arch/arm/configs/ok335xs2_evm_linux_usb_defconfig
+++ b/arch/arm/configs/ok335xs2_evm_linux_usb_defconfig
@@ -725,7 +725,7 @@ CONFIG_CAN_BCM=y
 CONFIG_CAN_DEV=y
 CONFIG_CAN_CALC_BITTIMING=y
 # CONFIG_CAN_TI_HECC is not set
-# CONFIG_CAN_MCP251X is not set
+CONFIG_CAN_MCP251X=y
 # CONFIG_CAN_SJA1000 is not set
 # CONFIG_CAN_C_CAN is not set
 CONFIG_CAN_D_CAN=y

--- a/arch/arm/mach-omap2/board-am335xevm.c
+++ b/arch/arm/mach-omap2/board-am335xevm.c
@@ -81,6 +81,9 @@
 #include "control.h"
 #include <linux/proc_fs.h>
 
+#ifdef CONFIG_CAN_MCP251X
+#include <linux/can/platform/mcp251x.h>
+#endif
 
 /* Convert GPIO signal to GPIO pin number */
 #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
@@ -753,6 +756,10 @@ static struct pinmux_config spi0_pin_mux[] = {
 
 /* Module pin mux for SPI flash */
 static struct pinmux_config spi1_pin_mux[] = {
+#if defined(CONFIG_CAN_MCP251X)&&defined(CONFIG_OK335XS2)
+ {"xdma_event_intr1.gpio0_20",OMAP_MUX_MODE7 | AM33XX_PIN_INPUT | AM33XX_PULL_ENBL| AM33XX_PULL_UP},
+ {"xdma_event_intr0.spi1_cs1", OMAP_MUX_MODE4 | AM33XX_PULL_ENBL| AM33XX_PULL_UP | AM33XX_INPUT_EN},
+#endif
  {"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},
@@ -2164,7 +2171,28 @@ static struct spi_board_info am335x_spi0_slave_info[] = {
  },
 };
 
+#ifdef CONFIG_CAN_MCP251X
+#define AM335XEVM_MCP2515_IRQ_GPIO GPIO_TO_PIN(0, 20)
+
+static struct mcp251x_platform_data mcp251x_info={
+    .oscillator_frequency = 8000000,
+ .transceiver_enable = NULL,
+ .power_enable = NULL,
+};
+#endif
+
 static struct spi_board_info am335x_spi1_slave_info[] = {
+#ifdef CONFIG_CAN_MCP251X
+ {
+ .modalias      = "mcp2515", /* device node name */
+ .platform_data=&mcp251x_info,
+ .max_speed_hz    = 10000000,
+ .bus_num         = 2,
+ .chip_select     = 1,
+ .mode            = SPI_MODE_0,  /* CPOL=0, CPHA=0 */
+ .irq = OMAP_GPIO_IRQ(AM335XEVM_MCP2515_IRQ_GPIO),
+ }
+#else
         {
                 .modalias      = "spidev",
                 .max_speed_hz  = 48000000,//48Mbps
@@ -2172,6 +2200,7 @@ static struct spi_board_info am335x_spi1_slave_info[] = {
                 .chip_select   = 0,
                 .mode = SPI_MODE_1,
         },
+#endif
 };
 
 static struct gpmc_timings am335x_nand_timings = {
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index 94c438d..6db474d 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -241,6 +241,12 @@ static void omap2_mcspi_set_master_mode(struct spi_master *master)
  /* setup when switching from (reset default) slave mode
  * to single-channel master mode
  */
+ /****/
+ l = mcspi_read_reg(master,OMAP2_MCSPI_SYST);
+ l |= (1 << 9);
+ l &=  ~(1 << 8);
+ mcspi_write_reg(master,OMAP2_MCSPI_SYST,l);
+ /***/
  l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL);
  MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_STEST, 0);
  MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_MS, 0);
@@ -680,8 +686,10 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi,
  /* standard 4-wire master mode:  SCK, MOSI/out, MISO/in, nCS
  * REVISIT: this controller could support SPI_3WIRE mode.
  */
- l &= ~(OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1);
- l |= OMAP2_MCSPI_CHCONF_DPE0;
+// l &= ~(OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1);
+// l |= OMAP2_MCSPI_CHCONF_DPE0;
+ l |= (OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1);
+ l &= ~OMAP2_MCSPI_CHCONF_DPE0;
 
  /* wordlength */
  l &= ~OMAP2_MCSPI_CHCONF_WL_MASK;
diff --git a/version b/version
new file mode 100644
index 0000000..542723a
--- /dev/null
+++ b/version
@@ -0,0 +1,2 @@
+2014-12-29
+Merge kernel patch to fix ubifs bug

--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -241,6 +241,12 @@ static void omap2_mcspi_set_master_mode(struct spi_master *master)
  /* setup when switching from (reset default) slave mode
  * to single-channel master mode
  */
+ /****/
+ l = mcspi_read_reg(master,OMAP2_MCSPI_SYST);
+ l |= (1 << 9);
+ l &=  ~(1 << 8);
+ mcspi_write_reg(master,OMAP2_MCSPI_SYST,l);
+ /***/
  l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL);
  MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_STEST, 0);
  MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_MS, 0);
@@ -680,8 +686,10 @@ static int omap2_mcspi_setup_transfer(struct spi_device *spi,
  /* standard 4-wire master mode:  SCK, MOSI/out, MISO/in, nCS
  * REVISIT: this controller could support SPI_3WIRE mode.
  */
- l &= ~(OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1);
- l |= OMAP2_MCSPI_CHCONF_DPE0;
+// l &= ~(OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1);
+// l |= OMAP2_MCSPI_CHCONF_DPE0;
+ l |= (OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1);
+ l &= ~OMAP2_MCSPI_CHCONF_DPE0;
 
  /* wordlength */
  l &= ~OMAP2_MCSPI_CHCONF_WL_MASK;




已解决

未解决

只是看看

最新评论

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2024-12-23 11:44

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部