Closed caio-porto closed 3 years ago
I am using the CP21230 driver with the MCP2515 CAN controller. The above channel configuration looks fine. Are you sure you have wired the IRQ pin of MCP2515 to GPIO#2 of the CP2130 or do you use an explicit IRQ pin, than you shoud not set the IRQ pin in the channel_config at all. If you use the CP2130 GPIOs for IRQ you should also lower the irq_poll_interval, I use 100 there with the MCP2515. The MCP2515 driver also needs a patch such that you can set the IRQ pin with platform_data and then you need to write the binary platform data to channel_pdata. I can provide you with the patches and some program to generate the binary platform data if needed.
Thank you very much for the quick response. I'm going to do some tests on my side changing IRQ pins and making sure that they are connected to the right pins. Also going to lower the irq_poll_interval if I decide to connect them directly. At this moment I don't have the IRQ connected to the CP2130. I'm using the MCP2515 kernel module [https://github.com/mangOH/mangOH/blob/master/linux_kernel_modules/can_common/can_iot.c] instead of the platform_data. I will try to use the platform_data as well to make sure the issue is just on the driver. Could you send me the patches and the programs you may have?
Thank you very much for the prompt support with this!
The program that I use to generate the binary platform data is in the repository, create_pdata.c, and the patch for the mcp2515 is needed for making the platform data work.
--- a/drivers/net/can/spi/mcp251x.c
+++ b/drivers/net/can/spi/mcp251x.c
@@ -1034,7 +1034,7 @@ static int mcp251x_can_probe(struct spi_device *spi)
int freq, ret;
clk = devm_clk_get(&spi->dev, NULL);
- if (IS_ERR(clk)) {
+ if (!clk || IS_ERR(clk)) {
if (pdata)
freq = pdata->oscillator_frequency;
else
--
I finally got time to work on this again and this was my progress. When I try to initialize the can0 interface I'm getting the following error logged:
[ 434.037242] spi32766.2 supply vdd not found, using dummy regulator [ 434.037336] spi32766.2 supply xceiver not found, using dummy regulator [ 467.034220] gpio_sync_ri: RI owner is Modem [ 467.034245] gpiod_export: sierra--find GPIO,chipdev = -828217840,chipngpio = 80,chipbase = 0 [ 467.036069] sps:BAM 0x07884000 (va:0xd09c0000) enabled: ver:0x18, number of pipes:24 [ 467.036578] spi1.0 supply vdd not found, using dummy regulator [ 467.036660] spi1.0 supply xceiver not found, using dummy regulator [ 467.047547] can_spi_init: mcp2515 (gpio:9 irq:61). [ 504.152050] mcp251x spi32766.2: failed to acquire irq -930657552 [ 522.002345] mcp251x spi32766.2: failed to acquire irq -930657552
I'm trying to use the module that was already developed for the mangOH board. It already implements the platform_data configuration. I set the IRQ pin to 9. The interrupt is not connected to the cp2130, it's connect directly to one of the processors GPIOs, that's why I'm using -1 for the IRQ. I'm using CS2 for this mcp2515 chip. I'm trying to understand what's the "cs_mode" configuration. I see it as an enable, so I set it to 1, but I see that it accepts the value 2 as well.
echo -n 2,1,-1,0,0,0,1,0,0,0,0,mcp2515 > $(find /sys -name 'channel_config')
Thank you, Caio Porto
Hi @jh-hsd,
After studying more about the driver I could finish developing the modules and loading them. However I still cannot receive any CAN message. I followed your instructions, but I just won't work.
Here is the adapted CAN module: can1_spi.c (3.5 KB)
I also wrote a script that loads the modules and bring the CAN interface up. You will notice that I’m creating and loading the pdata as suggested, but still not working. start_can.sh (425 Bytes)
This is the output from dmesg
[ 90.686833] spi_master spi32766: can_spi_init(): find SPI device(‘spi32766.1’) [ 90.686861] spi_master spi32766: can_spi_init(): dev(‘mcp2515’) mode(0) max speed(12000000) CS(1) bits/word(8) [ 90.686898] gpio_sync_ri: RI owner is Modem [ 90.686912] gpiod_export: sierra–find GPIO,chipdev = -828217840,chipngpio = 80,chipbase = 0 [ 90.687244] spi spi32766.1: can_spi_init(): mcp2515 (gpio:9 irq:61). [ 90.687257] spi spi32766.1: can_spi_init(): ‘mcp2515’ initialized [ 90.736726] spi32766.1 supply vdd not found, using dummy regulator [ 90.736827] spi32766.1 supply xceiver not found, using dummy regulator [ 96.663519] mcp251x spi32766.1: modalias:mcp2515 , irq:61 , Max Speed:6000000 , chip:1
Output from lsmod
root@swi-mdm9x28-wp:~# lsmod Tainted: G mcp251x 9728 0 - Live 0xbf024000 (O) can1_spi 1190 0 - Live 0xbf020000 (O) mt7697serial 8094 0 - Live 0xbf01a000 (O) mt7697q 19703 0 - Live 0xbf010000 (O) cp2130 20454 2 can1_spi,mt7697q, Live 0xbf000000 (O)
_channelconfig content:
root@swi-mdm9x28-wp:~# cat $(find /sys -name ‘channel_config’) channel cs_mode irq_pin clock_phase polarity cs_pin_mode clock_freq delay_mask inter_byte_delay pre_delay post_delay mod_alias 0 2 -1 0 0 1 12 MHz 0 0 0 0 ‘mt7697’ 1 2 -1 0 0 0 6 MHz 0 0 0 0 ‘mcp2515’ 2 0 0 0 0 1 6 MHz 0 0 0 0 ‘(null)’ 3 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 4 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 5 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 6 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 7 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 8 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 9 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 10 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
Please, advise what should I test next. I have tested this MCP2515 with a Raspberry Pi and it works perfectly. The interface with CP2130 makes everything very hard.
I'm looking for someone that can solve this issue for me. Maybe a part time contractor.
Thank you very much, Caio Porto
Hi @jh-hsd,
After studying more about the driver I could finish developing the modules and loading them. However I still cannot receive any CAN message. I followed your instructions, but I just won't work.
Here is the adapted CAN module: can1_spi.c (3.5 KB)
I also wrote a script that loads the modules and bring the CAN interface up. You will notice that I’m creating and loading the pdata as suggested, but still not working. start_can.sh (425 Bytes)
This is the output from dmesg
[ 90.686833] spi_master spi32766: can_spi_init(): find SPI device(‘spi32766.1’) [ 90.686861] spi_master spi32766: can_spi_init(): dev(‘mcp2515’) mode(0) max speed(12000000) CS(1) bits/word(8) [ 90.686898] gpio_sync_ri: RI owner is Modem [ 90.686912] gpiod_export: sierra–find GPIO,chipdev = -828217840,chipngpio = 80,chipbase = 0 [ 90.687244] spi spi32766.1: can_spi_init(): mcp2515 (gpio:9 irq:61). [ 90.687257] spi spi32766.1: can_spi_init(): ‘mcp2515’ initialized [ 90.736726] spi32766.1 supply vdd not found, using dummy regulator [ 90.736827] spi32766.1 supply xceiver not found, using dummy regulator [ 96.663519] mcp251x spi32766.1: modalias:mcp2515 , irq:61 , Max Speed:6000000 , chip:1
Output from lsmod
root@swi-mdm9x28-wp:~# lsmod Tainted: G mcp251x 9728 0 - Live 0xbf024000 (O) can1_spi 1190 0 - Live 0xbf020000 (O) mt7697serial 8094 0 - Live 0xbf01a000 (O) mt7697q 19703 0 - Live 0xbf010000 (O) cp2130 20454 2 can1_spi,mt7697q, Live 0xbf000000 (O)
_channelconfig content:
root@swi-mdm9x28-wp:~# cat $(find /sys -name ‘channel_config’) channel cs_mode irq_pin clock_phase polarity cs_pin_mode clock_freq delay_mask inter_byte_delay pre_delay post_delay mod_alias 0 2 -1 0 0 1 12 MHz 0 0 0 0 ‘mt7697’ 1 2 -1 0 0 0 6 MHz 0 0 0 0 ‘mcp2515’ 2 0 0 0 0 1 6 MHz 0 0 0 0 ‘(null)’ 3 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 4 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 5 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 6 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 7 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 8 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 9 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’ 10 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
Please, advise what should I test next. I have tested this MCP2515 with a Raspberry Pi and it works perfectly. The interface with CP2130 makes everything very hard.
I have the CAN chip working in an embedded device with CP2130 - so it should be fine. Could you please enable debug output on CP2130 with '#define DEBUG' at the top of the driver file. And also enable debug output for the CAN chip module. Please providde me the full output. Is reading the issue or do you also fail to write? Did you check with an oscilloscope if everything is fine hardware wise.
I'm looking for someone that can solve this issue for me. Maybe a part time contractor.
I could do that for you, that is exactly the area where I am working in. And I am pretty sure that it is not a big issue that is left to be solved. Just let me know if you are interested.
Thank you very much, Caio Porto
I don't know if you have any experience with it, but I just can't get the mcp2515 to work with the Mangoh Red over the Rpi SPI port. I tried to assign multiples IRQ, but it won't work at all.
echo -n 0,2,1,0,0,0,1,0,0,0,0,mcp2515 > /sys/devices/7c00000.hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config
echo -n 0,2,0,0,0,0,1,0,0,0,0,mcp2515 > /sys/devices/7c00000.hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config
Please, let me know if you have any suggestion.
Thank you!