全部博文(776)
分类: LINUX
2015-09-04 07:08:06
ADM5120_GPIO_P3L1 GPIO17 -> MISO ADM5120_GPIO_P3L0 GPIO18 -> MOSI ADM5120_GPIO_P4L1 GPIO20 -> SCK ADM5120_GPIO_P4L0 GPIO21 -> CS RESET Button GPIO2 -> INTAnother part is the board defintion: #include <linux/spi/spi_gpio.h> #include <inux/can/platform/mcp251x.h> ... static struct mcp251x_platform_data mcp251x_info = { .oscillator_frequency = 16E6, .board_specific_setup = NULL, .power_enable = NULL, .transceiver_enable = NULL, }; static struct spi_gpio_platform_data br61xx_gpio_spi = { .sck = 20, .mosi = 18, .miso = 17, .num_chipselect = 1, /* number of chip selects for spi gpio master */ }; static struct platform_device spi_gpio_device = { .name = "spi_gpio", .id = 1, /* Bus number */ .dev.platform_data = &br61xx_gpio_spi, }; static struct spi_board_info mcp2515_spi_gpio_board_info [] = { { .modalias = "mcp2515", .max_speed_hz = 10000000, .bus_num = 1, .chip_select = 0, .platform_data = &mcp251x_info, .mode = SPI_MODE_0, .controller_data = (void *) 21, }, }; static struct platform_device *br61xx_devices[] __initdata = { &spi_gpio_device, }; void __init br61xx_generic_setup(void) { ... spi_register_board_info(mcp2515_spi_gpio_board_info,ARRAY_SIZE(mcp2515_spi_gpio_board_info)); adm5120_add_device_gpio_buttons(ARRAY_SIZE(br61xx_gpio_buttons), br61xx_gpio_buttons);
root@OpenWrt:~# cat /sys/kernel/debug/gpio GPIOs 0-3, adm5120 gpio0: gpio-0 (power ) out hi gpio-2 (MCP251x /INT ) in hi GPIOs 8-22, adm5120 gpio1: gpio-8 (wan_lnkact ) out hi gpio-9 (wan_speed ) out hi gpio-11 (lan1_lnkact ) out hi gpio-12 (lan1_speed ) out hi gpio-14 (lan2_lnkact ) out hi gpio-15 (lan2_speed ) out hi gpio-17 (spi_gpio.1 ) in lo gpio-18 (spi_gpio.1 ) out lo gpio-20 (spi_gpio.1 ) out lo gpio-21 (spi1.0 ) out hidmesg should show something like this:
[ 17.648000] can: controller area network core (rev 20090105 abi 8) [ 17.656000] NET: Registered protocol family 29 [ 17.704000] CAN device driver interface [ 17.748000] can: raw protocol (rev 20090105) [ 17.956000] mcp251x spi1.0: CANSTAT 0x80 CANCTRL 0x07 [ 17.956000] mcp251x spi1.0: probedAfter starting the controller:
/usr/sbin/ip link set can0 type can bitrate 250000 /sbin/ifconfig can0 updmesg should show:
[ 39.108000] mcp251x spi1.0: INTC_REG_IRQ_ENABLE was = 0x212 [ 39.108000] mcp251x spi1.0: INTC_REG_IRQ_ENABLE now = 0x212 [ 39.120000] mcp251x spi1.0: GPIO2 IRQ initialized: IRQ 12 [ 39.160000] mcp251x spi1.0: CNF: 0x01 0xb5 0x01You also should see the corresponding interrupts:
root@OpenWrt:~# cat /proc/interrupts CPU0 2: 0 MIPS cascade [INTC] 7: 113752 MIPS timer 9: 35 INTC uart-pl010 12: 0 INTC mcp251x 17: 18955 INTC eth0, eth1 ERR: 0BTW: The number of interrupts is always even for the mcp251x because of the workaround.
root@OpenWrt:/# ip -s -d link show can0 8: can0: mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10 link/can can state ERROR-ACTIVE restart-ms 0 bitrate 250000 sample-point 0.875 tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1 mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1 clock 8000000 re-started bus-errors arbit-lost error-warn error-pass bus-off 0 0 0 0 0 0 RX: bytes packets errors dropped overrun mcast 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 0 0 0 0