rt-socket-can "no device" problem with advantech PCM-26D2CA CANboard [CLOSED]
Wolfgang has solved this problem.
This problem occurs, because rt-socket-can driver in xenomai 3.0.2 does not have the Advantech PCM26D2CA device yet. It's device id is 0xC302. Below is the the final patch. I have tested it. It works fine :)
Thanks, Wolfgang.
---
97a98,103
Quoted 6 lines
ADV_PCI_DEVICE(0xc201),ADV_PCI_DEVICE(0xc202),ADV_PCI_DEVICE(0xc204),ADV_PCI_DEVICE(0xc301),ADV_PCI_DEVICE(0xc302),ADV_PCI_DEVICE(0xc304),
117a124,138
Quoted 7 lines
static u8
rtcan_adv_pci_read_reg_shift2(struct rtcan_device *dev, int port){
structrtcan_adv_pci*board = (structrtcan_adv_pci*)dev->board_priv;return
ioread8(board->base_addr + (port << 2));
}
Quoted 8 lines
static void rtcan_adv_pci_write_reg_shift2(struct
rtcan_device*dev, int port,
u8 data)
{
structrtcan_adv_pci*board = (structrtcan_adv_pci*)dev->board_priv;
iowrite8(data, board->base_addr + (port << 2));
}
139a161
Quoted 1 line
unsigned int shift,
164c186
<base_addr = pci_iomap(pdev, bar, ADV_PCI_BASE_SIZE);
---
Quoted 1 line
base_addr=pci_iomap(pdev, bar, ADV_PCI_BASE_SIZE << shift);
170c192
< base_addr = pci_iomap(pdev, bar, ADV_PCI_BASE_SIZE) + offset;
---
Quoted 1 line
base_addr=pci_iomap(pdev, bar,0);
182a205,208
Quoted 4 lines
if (shift == 2) {
chip->read_reg=rtcan_adv_pci_read_reg_shift2;chip->write_reg=rtcan_adv_pci_write_reg_shift2;
} else {
184a211
Quoted 1 line
}
246a274
Quoted 1 line
unsigned int shift = 0;
274a303,312
Quoted 10 lines
case
0xc201:
case0xc202:
case0xc204:
case0xc301:
case0xc302:
case0xc304:nb_ports=pdev->device&0x7;
offset =0x400;
shift = 2;
break;
301c339,340
<ret = rtcan_adv_pci_add_chan(pdev, channel, bar, offset, &master_dev);
---
Quoted 2 lines
ret = rtcan_adv_pci_add_chan(pdev, channel, bar, offset, shift,
&master_dev);
311a351
Quoted 1 line
shift,
---
------------------ Original ------------------
From: "Jack Lee";<[email protected]>; Date: Sep 4, 2016 To: "wg"<[email protected]>; "xenomai"<[email protected]>; Subject: rt-socket-can "no device" problem with advantech PCM-26D2CA CANboard
Quoted 164 lines
Hello,
Am 03.09.2016 um 02:54 schrieb Jack Lee:
...snip...Quoted 16 lines
------------I am back.--------------
I modified the source code and compiled the xeno_can_adv_pci.ko with "make CONFIG_XENO_...=m -C (krnsrc)/drivers/xenomai/can/sja1000 modules". After copied the module to the/lib/... directory and "modprobexeno_can_adv_pci",/proc/rtcan/devicesremain the same. But "dmesg | grep -i can" outputs these:
...[ 239.374873] RT-Socket-CAN 0.90.2 - (C) 2006 RT-Socket-CAN Development Team [ 239.396977] RTCAN SJA1000 driver initialized [ 239.405819] xeno_can_adv_pci: module verification failed: signature and/or required key missing - tainting kernel [ 239.408014] ADV-PCI-CAN 0000:03:00.0: RTCAN Registering card [ 239.408121] ADV-PCI-CAN 0000:03:00.0: PCI->APIC IRQ transform: INT A -> IRQ 18 [ 239.408189] ADV-PCI-CAN 0000:03:00.0: RTCAN detected Advantech PCIQuoted 8 lines
card at slot #0
[ 239.408254] ADV-PCI-CAN: Initializing device 13fe:c302:c302 [ 239.408386] ADV-PCI-CAN: base_addr=ffffc900008fe400 conf_addr= (null) irq=18 ocr=0xfa cdr=0xc0 [ 239.408575] rtcan: registered rtcan0 [ 239.408631] Unregistering SJA1000 device rtcan0 [ 239.408736] RTCAN: unregistered rtcan0 [ 239.408890] ADV-PCI-CAN: probe of 0000:03:00.0 failed with error -5Oops, I forgot to adjust the mapped PCI space. In "
pci_map()" "ADV_PCI_BASE_SIZE<< shift" should be used. Below is v2 of the patch. Hope it works now.Wolfgang.
From
f346a0e7b08a02cc4ef3b06eef88992a6140b957Mon Sep 17 00:00:00 2001
From: Wolfgang Grandegger <Wolfgang Grandegger>
Date: Fri, 2 Sep 2016 10:46:26 +0200
Subject: [PATCH v2] rtcan: add support for new Advantec CAN PCI devices--- ksrc/drivers/can/sja1000/rtcan_adv_pci.c | 52 ++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 6 deletions(-)ksrc/drivers/can/sja1000/rtcan_adv_pci.c +46
-6@@ -95,6 +95,12 @@ static DEFINE_PCI_DEVICE_TABLE(adv_pci_tbl) = {ADV_PCI_DEVICE (0xc101 ),ADV_PCI_DEVICE (0xc102 ),ADV_PCI_DEVICE (0xc104 ), +ADV_PCI_DEVICE (0xc201 ), +ADV_PCI_DEVICE (0xc202 ), +ADV_PCI_DEVICE (0xc204 ), +ADV_PCI_DEVICE (0xc301 ), +ADV_PCI_DEVICE (0xc302 ), + ADV_PCI_DEVICE(0xc304), /* required last entry */ { } };@@ -115,6 +121,21 @@ static void rtcan_adv_pci_write_reg(struct rtcan_device *dev, int port, u8 data)iowrite8 (data, board->base_addr + port); } +static u8 rtcan_adv_pci_read_reg_shift2 (struct rtcan_device *dev,int port) +{ +struct rtcan_adv_pci *board = (struct rtcan_adv_pci *)dev->board_priv; + +return ioread8 (board->base_addr + (port <<2 )); +} + +static void rtcan_adv_pci_write_reg_shift2 (struct rtcan_device *dev,int port, +u8 data) +{ +struct rtcan_adv_pci *board = (struct rtcan_adv_pci *)dev->board_priv; + +iowrite8 (data, board->base_addr + (port <<2 )); +} +static void rtcan_adv_pci_del_chan (struct pci_dev *pdev,struct rtcan_device *dev) {@@ -137,6 +158,7 @@ static int rtcan_adv_pci_add_chan(struct pci_dev *pdev,int channel, unsigned int bar, unsigned int offset, + unsigned int shift, struct rtcan_device **master_dev) { struct rtcan_device *dev;@@ -161,13 +183,15 @@ static int rtcan_adv_pci_add_chan(struct pci_dev *pdev,if (offset) base_addr = master_board->base_addr+offset;else - base_addr =pci_iomap (pdev, bar,ADV_PCI_BASE_SIZE ); + base_addr =pci_iomap (pdev, bar, +ADV_PCI_BASE_SIZE << shift);if (!base_addr) { ret = -EIO ; goto failure; } }else { - base_addr =pci_iomap (pdev, bar,ADV_PCI_BASE_SIZE ) + offset; + base_addr =pci_iomap (pdev, bar, +ADV_PCI_BASE_SIZE << shift) + offset;if (!base_addr) { ret = -EIO ; goto failure;@@ -180,8 +204,13 @@ static int rtcan_adv_pci_add_chan(struct pci_dev *pdev, dev->board_name = adv_pci_board_name; - chip->read_reg = rtcan_adv_pci_read_reg; - chip->write_reg = rtcan_adv_pci_write_reg; +if (shift ==2 ) { + chip->read_reg = rtcan_adv_pci_read_reg_shift2; + chip->write_reg = rtcan_adv_pci_write_reg_shift2; + }else { + chip->read_reg = rtcan_adv_pci_read_reg; + chip->write_reg = rtcan_adv_pci_write_reg; + }/* Clock frequency in Hz */ dev->can_sys_clock =ADV_PCI_CAN_CLOCK ;@@ -244,6 +273,7 @@ static int adv_pci_init_one(struct pci_dev *pdev,unsigned int bar =0 ;unsigned int bar_flag =0 ;unsigned int offset =0 ; +unsigned int shift =0 ;unsigned int ix;struct rtcan_device *master_dev =NULL ;@@ -270,7 +300,16 @@ static int adv_pci_init_one(struct pci_dev *pdev,case 0xc104 : nb_ports = pdev->device &0x7 ; offset =0x100 ; - bar =0 ; +break ; +case 0xc201 : +case 0xc202 : +case 0xc204 : +case 0xc301 : +case 0xc302 : +case 0xc304 : + nb_ports = pdev->device &0x7 ; + offset =0x400 ; + shift =2 ;break ;case 0x1680 :case 0x2052 :@@ -298,7 +337,8 @@ static int adv_pci_init_one(struct pci_dev *pdev, pdev->device, pdev->subsystem_device); - ret =rtcan_adv_pci_add_chan (pdev, channel, bar, offset, &master_dev); + ret =rtcan_adv_pci_add_chan (pdev, channel, bar, offset, shift, + &master_dev);if (ret) goto failure_iounmap;Signature · 1 line
1.9.1
...snip...
Hello Jack,
Am 05.09.2016 um 13:30 schrieb Jack Lee:
Quoted 4 lines
Wolfgang has solved this problem.
This problem occurs, because rt-socket-can driver in xenomai 3.0.2 does not have the Advantech PCM26D2CA device yet. It's device id is0xC302. Below is the the final patch. I have tested it. It works fine :)
Apart from the missing PCI id entry, there are other issues with mapping the PCI address space. I actually wonder how it could work with other cards. I'm going to rework the device mapping for inclusion in the Xenomai repo later this week.
Wolfgang.