Hi Christian and thanks for you help.
I have attached your patch to SVN rev 1064, below is the errors that I
get when activating the interface:
r...@overo:~# ip link set can0 type can bitrate 250000
r...@overo:~# ip link set can0 up
r...@overo:~# ------------[ cut here ]------------
WARNING: at
/home/overo-oe/tmp/work/overo-angstrom-linux-gnueabi/socketcan-modules-0.0+svnr1064-r46/trunk/kernel/2.6/drivers/net/can/mcp251x.c:796
mcp251x_irq_work_handler+0x244/0x5c0 [mcp251x]()
Modules linked in: mcp251x can_dev
[<c00f45d4>] (unwind_backtrace+0x0/0xdc) from [<c0116278>]
(warn_slowpath_common+0x4c/0x80)
[<c0116278>] (warn_slowpath_common+0x4c/0x80) from [<bf008ef8>]
(mcp251x_irq_work_handler+0x244/0x5c0 [mcp251x])
[<bf008ef8>] (mcp251x_irq_work_handler+0x244/0x5c0 [mcp251x]) from
[<c0126d1c>] (worker_thread+0x19c/0x218)
[<c0126d1c>] (worker_thread+0x19c/0x218) from [<c012a6b0>] (kthread+0x78/0x80)
[<c012a6b0>] (kthread+0x78/0x80) from [<c00f0800>] (kernel_thread_exit+0x0/0x8)
---[ end trace 39731716fb7a3d35 ]---
------------[ cut here ]------------
WARNING: at
/home/overo-oe/tmp/work/overo-angstrom-linux-gnueabi/socketcan-modules-0.0+svnr1064-r46/trunk/kernel/2.6/drivers/net/can/mcp251x.c:796
mcp251x_irq_work_handler+0x244/0x5c0 [mcp251x]()
Modules linked in: mcp251x can_dev
[<c00f45d4>] (unwind_backtrace+0x0/0xdc) from [<c0116278>]
(warn_slowpath_common+0x4c/0x80)
[<c0116278>] (warn_slowpath_common+0x4c/0x80) from [<bf008ef8>]
(mcp251x_irq_work_handler+0x244/0x5c0 [mcp251x])
[<bf008ef8>] (mcp251x_irq_work_handler+0x244/0x5c0 [mcp251x]) from
[<c0126d1c>] (worker_thread+0x19c/0x218)
[<c0126d1c>] (worker_thread+0x19c/0x218) from [<c012a6b0>] (kthread+0x78/0x80)
[<c012a6b0>] (kthread+0x78/0x80) from [<c00f0800>] (kernel_thread_exit+0x0/0x8)
---[ end trace 39731716fb7a3d36 ]---
What I should mention is that I do not have a reset pin to the mcp251x
so I try to reset it with the SPI message, see my patch to the
linux-omap3-2.6.31:
---
diff -Nurd a/arch/arm/mach-omap2/board-overo.c
b/arch/arm/mach-omap2/board-overo.
c
--- a/arch/arm/mach-omap2/board-overo.c 2009-09-26 13:06:18.000000000 +0200
+++ b/arch/arm/mach-omap2/board-overo.c 2009-09-30 16:43:57.000000000 +0200
@@ -56,6 +56,7 @@
#define OVERO_GPIO_BT_XGATE 15
#define OVERO_GPIO_W2W_NRESET 16
#define OVERO_GPIO_PENDOWN 114
+#define OVERO_GPIO_CAN_INT 114
#define OVERO_GPIO_BT_NRESET 164
#define OVERO_GPIO_USBH_CPEN 168
#define OVERO_GPIO_USBH_NRESET 183
@@ -95,7 +96,7 @@
};
static void __init overo_ads7846_init(void)
-{
+{/*
if ((gpio_request(OVERO_GPIO_PENDOWN, "ADS7846_PENDOWN") == 0) &&
(gpio_direction_input(OVERO_GPIO_PENDOWN) == 0)) {
gpio_export(OVERO_GPIO_PENDOWN, 0);
@@ -103,12 +104,72 @@
printk(KERN_ERR "could not obtain gpio for ADS7846_PENDOWN\n");
return;
}
-}
+*/}
#else
static inline void __init overo_ads7846_init(void) { return; }
#endif
+/* CAN mcp251x SPI driver
+ Added by Erik Calissendorff 2009-09-06 */
+
+#include <linux/spi/mcp251x.h>
+
+static struct omap2_mcspi_device_config mcp251x_mcspi_config = {
+ .turbo_mode = 0,
+ .single_channel = 1, /* 0: slave, 1: master */
+};
+
+#define MCP251X_INSTRUCTION_RESET 0xC0
+/* MPC251x registers */
+#define MCP251X_CANSTAT 0x0e
+#define MCP251X_CANCTRL 0x0f
+
+static int mcp251x_setup(struct spi_device *spi)
+{
+ u8 spi_tx = MCP251X_INSTRUCTION_RESET;
+ int ret;
+
+ printk(KERN_INFO "Running: mcp251x_setup");
+ gpio_set_value(174, 1);
+ msleep(5);
+ gpio_set_value(174, 0);
+ msleep(5);
+
+ ret=spi_write(spi, &spi_tx, 1);
+
+ msleep(5);
+ gpio_set_value(174, 1);
+
+ msleep(5);
+ gpio_set_value(174, 0);
+
+ return 0;
+}
+
+static struct mcp251x_platform_data mcp251x_config = {
+ .oscillator_frequency = 20000000,
+ .board_specific_setup = &mcp251x_setup,
+ .model = CAN_MCP251X_MCP2515,
+ .power_enable = NULL,
+ .transceiver_enable = NULL,
+};
+
+static void __init overo_mcp251x_init(void)
+{
+printk(KERN_INFO "Running: overo_mcp251x_init\n");
+ if ((gpio_request(OVERO_GPIO_CAN_INT, "MCP251X_INTERRUPT") == 0) &&
+ (gpio_direction_input(OVERO_GPIO_CAN_INT) == 0)) {
+ gpio_export(OVERO_GPIO_CAN_INT, 0);
+ } else {
+ printk(KERN_ERR "could not obtain gpio for
MCP251X_INTERRUPT\n");
+ return;
+ }
+}
+
+/* End of CAN mcp251x SPI driver */
+
+
#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
#include <linux/smsc911x.h>
@@ -510,6 +571,7 @@
}
static struct spi_board_info overo_spi_board_info[] __initdata = {
+/*
#if defined(CONFIG_TOUCHSCREEN_ADS7846) || \
defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
{
@@ -533,11 +595,25 @@
.mode = SPI_MODE_3, },
#endif
+*/
+ {
+ .modalias = "mcp251x",
+ .bus_num = 1,
+ .chip_select = 0,
+ // this can be increased to 10MHz with 15 part
+ // SPI clock is divided down 13MHz, so granularity is
not too goo
d
+ // 13MHz, 6.5MHz, 4.33MHz, 3.25MHz, 2.6MHz, 2.1666MHz etc.
+ .max_speed_hz = 6500000,
+ .controller_data = &mcp251x_mcspi_config,
+ .irq = OMAP_GPIO_IRQ(OVERO_GPIO_CAN_INT),
+ .platform_data = &mcp251x_config,
+ },
};
static int __init overo_spi_init(void)
{
- overo_ads7846_init();
+// overo_ads7846_init();
+ overo_mcp251x_init();
spi_register_board_info(overo_spi_board_info,
ARRAY_SIZE(overo_spi_board_info));
return 0;
diff -Nurd a/include/linux/spi/mcp251x.h b/include/linux/spi/mcp251x.h
--- a/include/linux/spi/mcp251x.h 1970-01-01 01:00:00.000000000 +0100
+++ b/include/linux/spi/mcp251x.h 2009-09-26 13:41:00.000000000 +0200
@@ -0,0 +1,34 @@
+#ifndef __CAN_PLATFORM_MCP251X_H__
+#define __CAN_PLATFORM_MCP251X_H__
+
+/*
+ *
+ * CAN bus driver for Microchip 251x CAN Controller with SPI Interface
+ *
+ */
+
+/**
+ * struct mcp251x_platform_data - MCP251X SPI CAN controller platform data
+ * @oscillator_frequency: - oscillator frequency in Hz
+ * @model: - actual type of chip
+ * @board_specific_setup: - called before probing the chip (power,reset)
+ * @transceiver_enable: - called to power on/off the transceiver
+ * @power_enable: - called to power on/off the mcp *and* the
+ * transceiver
+ *
+ * Please note that you should define power_enable or transceiver_enable or
+ * none of them. Defining both of them is no use.
+ *
+ */
+
+struct mcp251x_platform_data {
+ unsigned long oscillator_frequency;
+ int model;
+#define CAN_MCP251X_MCP2510 0
+#define CAN_MCP251X_MCP2515 1
+ int (*board_specific_setup)(struct spi_device *spi);
+ int (*transceiver_enable)(int enable);
+ int (*power_enable) (int enable);
+};
+
+#endif /* __CAN_PLATFORM_MCP251X_H__ */
---
I have also tried to patch the u-boot-omap3 but unsure if the change
is needed or correct:
---
diff -Nurd a/board/overo/overo.h b/board/overo/overo.h
--- a/board/overo/overo.h 2009-09-30 19:08:36.000000000 +0200
+++ b/board/overo/overo.h 2009-09-30 19:17:57.000000000 +0200
@@ -268,7 +268,7 @@
MUX_VAL(CP(MCSPI1_CLK), (IEN | PTD | DIS | M0)) /*McSPI1_CLK*/\
MUX_VAL(CP(MCSPI1_SIMO), (IEN | PTD | DIS | M0))
/*McSPI1_SIMO */\
MUX_VAL(CP(MCSPI1_SOMI), (IEN | PTD | DIS | M0))
/*McSPI1_SOMI */\
- MUX_VAL(CP(MCSPI1_CS0), (IEN | PTD | EN | M0)) /*McSPI1_CS0*/\
+ MUX_VAL(CP(MCSPI1_CS0), (IDIS | PTD | EN | M0)) /*McSPI1_CS0*/\
MUX_VAL(CP(MCSPI1_CS1), (IDIS | PTD | EN | M0)) /*McSPI1_CS1*/\
MUX_VAL(CP(MCSPI1_CS2), (IEN | PTU | DIS | M4)) /*GPIO_176 */\
/* -
LAN_INTR */\
---
>From what I can see the problem seems to be that the chip isn't
entering configuration mode and therefor isn't setting the right
bitrate etc. When looking at the CAN data on a oscilloscope it appears
to be at 1Mbit instead of 250kbit as requested and as the other units.
Hope the extra info can bring some more light into my problems and
further assist me in finding the solution.
Kindest regards,
//Erik
On Wed, Sep 30, 2009 at 10:09 AM, christian pellegrin
<[email protected]> wrote:
> On Sat, Sep 26, 2009 at 10:00 PM, Erik Calissendorff
> <[email protected]> wrote:
>> Hi I have tried to get the mcp251x driver to work with the Overo
>> Gumstix for sometime now.
>
> Hi,
>
>> ------------[ cut here ]------------
>> WARNING: at
>> /home/plejd/overo-oe/tmp/work/overo-angstrom-linux-gnueabi/socketcan-modules-0.0+svnr1064-r45/trunk/kernel/2.6/drivers/net/can/mcp251x.c:840
>> mcp251x_irq_work_handler+0x24c/0x5d0 [mcp251x]()
>
> huh you added debugging lines so I don't know to which line in SVN
> does 840 refer. Anyway the WARN_ON in that function can be triggered
> only if the read from registers is not meaningful (for example tx done
> when there is not tx pending). Or the cause may be a bug in the driver
> of course.
>
> BTW if you need to have entry and exit function information you should
> definitely check ftrace.
>
> Can you please just use SVN version with just the following patch:
>
> Index: drivers/net/can/mcp251x.c
> ===================================================================
> --- drivers/net/can/mcp251x.c (revision 1064)
> +++ drivers/net/can/mcp251x.c (working copy)
> @@ -243,6 +243,19 @@
> ret = spi_sync(spi, &m);
> if (ret < 0)
> dev_err(&spi->dev, "%s: failed: ret = %d\n", __func__, ret);
> +#if 1
> + {
> + int i;
> +
> + printk("tx:");
> + for(i = 0; i < len; i++)
> + printk(" %02x", priv->spi_tx_buf[i]);
> + printk("rx:");
> + for(i = 0; i < len; i++)
> + printk(" %02x", priv->spi_rx_buf[i]);
> + printk("\n");
> + }
> +#endif
> return ret;
> }
>
> so I could be able to quickly tell you if SPI communications looks meaningful?
>
>
> --
> Christian Pellegrin, see http://www.evolware.org/chri/
> "Real Programmers don't play tennis, or any other sport which requires
> you to change clothes. Mountain climbing is OK, and Real Programmers
> wear their climbing boots to work in case a mountain should suddenly
> spring up in the middle of the computer room."
>
--
Erik Calissendorff
Cell: +33 (0)647 175 822 (France)
Cell: +46 (0)703 972 779 (Sweden)
E-mail: [email protected]
Homepage: http://www.tansaki.com
--
CONFIDENTIALITY NOTICE
This e-mail or the documents accompanying this e-mail contain information which
may be confidential or privileged and exempt from disclosure under
applicable law.
If you have received this e-mail in error, please notify immediately
and delete this message.
_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users