Re: [Xenomai-core] RTCAN (MSCAN) doesn't compile on latest Denx 2.6.23

2007-09-26 Thread Daniel Schnell
Wolfgang Grandegger wrote:

 
 I have a patch already since a while but forgot to post it. Could you
 please give the attached patch a try? 
 

I have given the patch a try and it doesn't quite work out of the box,
as there is an index off-by-one error concerning the configured CAN
ports. The result is that probing the CAN controller starts with the
second entry in the device tree and a random address will be probed for
the second CAN controller where ioremap gladly bumps out with an error
which results in a RT-CAN shutdown.

The applied patch solves the issue for me. I don't know if it works in
case of (! #defined CONFIG_PPC_MERGE)


Best regards,

Daniel.


mscan_fix_ot_index.patch
Description: mscan_fix_ot_index.patch
___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] RTCAN (MSCAN) doesn't compile on latest Denx 2.6.23

2007-09-26 Thread Wolfgang Grandegger
Daniel Schnell wrote:
 Wolfgang Grandegger wrote:
 
 I have a patch already since a while but forgot to post it. Could you
 please give the attached patch a try? 

 
 I have given the patch a try and it doesn't quite work out of the box,
 as there is an index off-by-one error concerning the configured CAN
 ports. The result is that probing the CAN controller starts with the
 second entry in the device tree and a random address will be probed for
 the second CAN controller where ioremap gladly bumps out with an error
 which results in a RT-CAN shutdown.
 
 The applied patch solves the issue for me. I don't know if it works in
 case of (! #defined CONFIG_PPC_MERGE)

I'm going to check that. Thanks for reporting.

Wolfgang.


___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core


Re: [Xenomai-core] RTCAN (MSCAN) doesn't compile on latest Denx 2.6.23

2007-09-24 Thread Wolfgang Grandegger

Hi Daniel,

Daniel Schnell wrote:

Hi,

I have cross compiled Xenomai latest trunk (Adeos-1.7) for the Denx
2.6.23 tree for a PowerPC5200 arch, and the only annoyance I can see is
that MSCAN driver for Xenomai is not compiling because of missing
defines/enums in asm-powerpc/mpc52xx.h in comparision to
asm-ppc/mpc52xx.h.


It's a bit more tricky as it has to deal with flat device tree based 
resource management.



Looking at the included socket-can mscan driver, things seem to have
changed quite a bit since the socketcan has been ported to
RTCAN/Xenomai.

Wolfgang, Jan, is the MSCAN RT driver just needing the appropriate
defines inside asm-powerpc/mpc52xx.h or or does the driver itself need
changes ? How does the socketcan MSCAN driver come along without these ?


I have a patch already since a while but forgot to post it. Could you 
please give the attached patch a try?


Wolfgang.

Index: ksrc/drivers/can/mscan/rtcan_mscan.c
===
--- ksrc/drivers/can/mscan/rtcan_mscan.c	(revision 3008)
+++ ksrc/drivers/can/mscan/rtcan_mscan.c	(working copy)
@@ -88,7 +88,9 @@ char *mscan_pins = NULL;
 module_param(mscan_pins, charp, 0444);
 MODULE_PARM_DESC(mscan_pins, Routing to GPIO pins (PSC2 or I2C1/TMR01));
  
-struct rtcan_device *rtcan_mscan_devs[RTCAN_MSCAN_DEVS];
+static struct rtcan_device *rtcan_mscan_devs[RTCAN_MSCAN_DEVS];
+static int rtcan_mscan_count;
+
 
 /**
  *  Reception Interrupt handler
@@ -733,26 +735,45 @@ static inline void __init mscan_gpio_con
 }
 }
 
-int __init rtcan_mscan_init_one(int idx)
+static inline int mscan_get_config(unsigned long *addr,
+   unsigned int *irq)
+{
+#ifdef CONFIG_PPC_MERGE
+/* Use Open Firmware device tree */
+struct device_node *np = NULL;
+unsigned int i;
+int ret;
+
+for (i = 0; i  RTCAN_MSCAN_DEVS; i++) {
+	struct resource r[2] = {};
+
+	np = of_find_compatible_node(np, mscan, mpc5200-mscan);
+	if (np == NULL)
+	break;
+	ret = of_address_to_resource(np, 0, r[0]);
+	if (ret)
+	return ret;
+	of_irq_to_resource(np, 0, r[1]);
+	addr[i] = r[0].start;
+	irq[i] = r[1].start;
+	rtcan_mscan_count++;
+}
+#else
+addr[0] = MSCAN_CAN1_ADDR;
+irq[0] = MSCAN_CAN1_IRQ;
+addr[1] = MSCAN_CAN2_ADDR;
+irq[1] = MSCAN_CAN2_IRQ;
+rtcan_mscan_count = 2;
+#endif
+return 0;
+}
+
+int __init rtcan_mscan_init_one(int idx, unsigned long addr, int irq)
 {
-int ret, irq;
-unsigned long addr;
+int ret;
 struct rtcan_device *dev;
 struct mscan_regs *regs;
 
-switch (port[idx]) {
-case 1:
-	addr = MSCAN_CAN1_ADDR;
-	irq = MSCAN_CAN1_IRQ;
-	break;
-case 2:
-	addr = MSCAN_CAN2_ADDR;
-	irq = MSCAN_CAN2_IRQ;
-	break;
-default:
-	return 0;
-}
-
 if ((dev = rtcan_dev_alloc(0, 0)) == NULL) {
 return -ENOMEM;
 }
@@ -762,7 +783,13 @@ int __init rtcan_mscan_init_one(int idx)
 
 dev-can_sys_clock = mscan_clock;
 
-dev-base_addr = addr;
+dev-base_addr = (unsigned long)ioremap(addr, MSCAN_SIZE);
+if (dev-base_addr == 0) {
+	ret = -ENOMEM;
+	printk(ERROR! ioremap of %#lx failed\n, addr);
+	goto out_dev_free;
+}
+
 regs = (struct mscan_regs *)dev-base_addr;
 
 /* Enable MSCAN module. */
@@ -790,7 +817,7 @@ int __init rtcan_mscan_init_one(int idx)
 			   0, RTCAN_DRV_NAME, (void *)dev);
 if (ret) {
 	printk(ERROR! rtdm_irq_request for IRQ %d failed\n, irq);
-	goto out_dev_free;
+	goto out_iounmap;
 }
 
 mscan_chip_config(regs);
@@ -812,12 +839,15 @@ int __init rtcan_mscan_init_one(int idx)
 
 return 0;
 
- out_irq_free:
+out_irq_free:
 rtdm_irq_free(dev-irq_handle);
 
- out_dev_free:
+out_iounmap:
 /* Disable MSCAN module. */
 regs-canctl1 = ~MSCAN_CANE;
+iounmap((void *)dev-base_addr);
+
+out_dev_free:
 rtcan_dev_free(dev);
 
 return ret;
@@ -829,17 +859,18 @@ static void __exit rtcan_mscan_exit(void
 int i;
 struct rtcan_device *dev;
 
-for (i = 0; i  RTCAN_MSCAN_DEVS; i++) {
+for (i = 0; i  rtcan_mscan_count; i++) {
 
 	if ((dev = rtcan_mscan_devs[i]) == NULL)
 	continue;
-	
+
 	printk(Unloading %s device %s\n, RTCAN_DRV_NAME, dev-name);
 
 rtcan_mscan_mode_stop(dev, NULL);
 	rtdm_irq_free(dev-irq_handle);
 	rtcan_mscan_remove_proc(dev);
 	rtcan_dev_unregister(dev);
+	iounmap((void *)dev-base_addr);
 rtcan_dev_free(dev);
 }
 
@@ -847,15 +878,21 @@ static void __exit rtcan_mscan_exit(void
 
 static int __init rtcan_mscan_init(void)
 {
-int i, err;
+int i, idx, err;
+int unsigned long addr[RTCAN_MSCAN_DEVS];
+int irq[RTCAN_MSCAN_DEVS];
 
+if ((err = mscan_get_config(addr, irq)))
+	return err;
 mscan_gpio_config();
 
-for (i = 0; i  RTCAN_MSCAN_DEVS; i++) {
-	if (port[i]  1 || port[i]  RTCAN_MSCAN_DEVS)
+for (i = 0; i  rtcan_mscan_count; i++) {
+	idx = port[i];
+	if (idx  1 || idx  rtcan_mscan_count)
 	continue;
 
-	if ((err = rtcan_mscan_init_one(i) != 0)) {
+	err = rtcan_mscan_init_one(idx, 

Re: [Xenomai-core] RTCAN (MSCAN) doesn't compile on latest Denx 2.6.23

2007-09-24 Thread Daniel Schnell
Wolfgang Grandegger wrote:

 
 It's a bit more tricky as it has to deal with flat device tree based
 resource management. 
 

Yes this makes sense.


 I have a patch already since a while but forgot to post it. Could you
 please give the attached patch a try? 
 

Patch applies and compiles cleanly. I will give it a try as soon as I
added the support for our board. I have already support for a 2.6.20
Kernel, so this should be no big deal.

Slightly OT:
Do you know the status of the mpc5200 support of the Denx-2.6 kernel
concerning ATA and FEC ? Are the latest patches from Sylvain Munaut and
Grant Likely already inside ?

What I find nice about the Denx kernel Repo is, that together with
Xenomai there are now two options for opening the MSCAN device.


Best regards,

Daniel Schnell.

___
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core