This patch adds support for the ICPDAS PISO-CAN200/400 and
PCM-CAN100/200/400 series CAN boards of ICPDAS (http://www.icpdas.com).
The driver is based on the EMS pci driver with adjustments of PCI ids
and board detection and is developed by Golden Wang <[email protected]>
and Wayne Lin <[email protected]>.
Acknowledgements:
Felix Obenhuber <[email protected]>
Wayne
diff -ruN trunk/FILES-2.6-ALL trunk-1199-icpdas-patch/FILES-2.6-ALL
--- trunk/FILES-2.6-ALL 2010-11-01 14:58:25.000000000 +0800
+++ trunk-1199-icpdas-patch/FILES-2.6-ALL 2010-10-29 14:40:19.000000000
+0800
@@ -50,6 +50,7 @@
kernel/2.6/drivers/net/can/mscan/Makefile
kernel/2.6/drivers/net/can/mscan/mscan.h
kernel/2.6/drivers/net/can/mscan/Kconfig
+kernel/2.6/drivers/net/can/sja1000/icpdas_pci.c
kernel/2.6/drivers/net/can/sja1000/ixxat_pci.c
kernel/2.6/drivers/net/can/sja1000/peak_pci.c
kernel/2.6/drivers/net/can/sja1000/esd_pci.c
diff -ruN trunk/kernel/2.6/drivers/net/can/sja1000/icpdas_pci.c
trunk-1199-icpdas-patch/kernel/2.6/drivers/net/can/sja1000/icpdas_pci.c
--- trunk/kernel/2.6/drivers/net/can/sja1000/icpdas_pci.c 1970-01-01
08:00:00.000000000 +0800
+++ trunk-1199-icpdas-patch/kernel/2.6/drivers/net/can/sja1000/icpdas_pci.c
2010-11-01 14:36:45.000000000 +0800
@@ -0,0 +1,346 @@
+/*
+ * Copyright (C) 2010 Golden Wang <[email protected]>
+ *
+ * Derived from the ems_pci.c driver:
+ * Copyright (C) 2007 Wolfgang Grandegger <[email protected]>
+ * Copyright (C) 2008 Markus Plessing <[email protected]>
+ * Copyright (C) 2008 Sebastian Haas <[email protected]>
+ *
+ * ICPDAS PISO-CAN200/400 and PCM-CAN100/200 series device driver.
+ * http://www.icpdas.com/products/Remote_IO/can_bus/can_intro.htm
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the version 2 of the GNU General Public License
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/netdevice.h>
+#include <linux/delay.h>
+#include <linux/pci.h>
+#include <linux/can.h>
+#include <linux/can/dev.h>
+#include <linux/io.h>
+#include <linux/string.h>
+#include "sja1000.h"
+
+#define DRV_NAME "icpdas-pci"
+
+MODULE_AUTHOR("Golden <[email protected]>");
+MODULE_DESCRIPTION("SocketCAN driver for ICPDAS PCI/104 Series");
+MODULE_SUPPORTED_DEVICE("ICPDAS PISO-CAN200/400 PCM-CAN 100/200 cards");
+MODULE_LICENSE("GPL v2");
+
+#define ICPDAS_PCI_MAX_CHAN 4
+
+struct icpdas_pci_card {
+ int version;
+ int board;
+ int channels;
+
+ struct pci_dev *pci_dev;
+ struct net_device *net_dev[ICPDAS_PCI_MAX_CHAN];
+
+ void __iomem *conf_addr;
+ void __iomem *base_addr;
+};
+
+#define ICPDAS_PCI_CAN_CLOCK (16000000 / 2)
+
+/*
+ * Register definitions for the PLX 9030
+ */
+#define PLX_ICSR 0x4c /* Interrupt Control/Status register */
+#define PLX_ICSR_LINTI1_ENA 0x0001 /* LINTi1 Enable */
+#define PLX_ICSR_PCIINT_ENA 0x0040 /* PCI Interrupt Enable */
+#define PLX_ICSR_LINTI1_CLR 0x0400 /* Local Edge Triggerable Interrupt Clear */
+#define PLX_ICSR_ENA_CLR (PLX_ICSR_LINTI1_ENA | PLX_ICSR_PCIINT_ENA )
+
+/*
+ * The board configuration is probably following:
+ * RX1 is connected to ground.
+ * TX1 is not connected.
+ * CLKO is not connected.
+ * Setting the OCR register to 0xDA is a good idea.
+ * This means normal output mode, push-pull and the correct polarity.
+ */
+#define ICPDAS_PCI_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL)
+
+/*
+ * In the CDR register, you should set CBP to 1.
+ * You will probably also want to set the clock divider value to 7
+ * (meaning direct oscillator output) because the second SJA1000 chip
+ * is driven by the first one CLKOUT output.
+ */
+#define ICPDAS_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK)
+
+#define ICPDAS_VENDOR_ID1 0x10b5
+
+#define ICPDAS_DEVICE_ID1 0x9030
+#define ICPDAS_DEVICE_ID2 0x9050
+
+#define ICPDAS_SUBVENDOR_ID1 0x2129
+
+#define ICPDAS_SUBDEVICE_PISO_CAN200 0xc200
+#define ICPDAS_SUBDEVICE_PISO_CAN400 0xc400
+#define ICPDAS_SUBDEVICE_PISO_CAN200U 0xc210
+#define ICPDAS_SUBDEVICE_PISO_CAN400U 0xc410
+#define ICPDAS_SUBDEVICE_PISO_CAN200E 0xc280
+#define ICPDAS_SUBDEVICE_PISO_CAN400E 0xc480
+#define ICPDAS_SUBDEVICE_PCM_CAN100 0xc150
+#define ICPDAS_SUBDEVICE_PCM_CAN200 0xc250
+
+static unsigned int board_num = 1;
+static struct pci_device_id icpdas_pci_tbl[] = {
+ /* PISO" means "Pci" interface and "ISOlation"*/
+ /* PISO-CAN200, 2-CAN Port*/
+ {ICPDAS_VENDOR_ID1, ICPDAS_DEVICE_ID2, ICPDAS_SUBVENDOR_ID1,
ICPDAS_SUBDEVICE_PISO_CAN200,},
+
+ /* PISO-CAN400, 4-CAN Port */
+ {ICPDAS_VENDOR_ID1, ICPDAS_DEVICE_ID2, ICPDAS_SUBVENDOR_ID1,
ICPDAS_SUBDEVICE_PISO_CAN400,},
+
+ /* PISO-CAN200U, 2-CAN Port, Universal PCI */
+ {ICPDAS_VENDOR_ID1, ICPDAS_DEVICE_ID1, ICPDAS_SUBVENDOR_ID1,
ICPDAS_SUBDEVICE_PISO_CAN200U,},
+
+ /* PISO-CAN400U, 4-CAN Port, Universal PCI */
+ {ICPDAS_VENDOR_ID1, ICPDAS_DEVICE_ID1, ICPDAS_SUBVENDOR_ID1,
ICPDAS_SUBDEVICE_PISO_CAN400U,},
+
+ /* PISO-CAN200E, 2-CAN Port, PCI Express interface*/
+ {ICPDAS_VENDOR_ID1, ICPDAS_DEVICE_ID2, ICPDAS_SUBVENDOR_ID1,
ICPDAS_SUBDEVICE_PISO_CAN200E,},
+
+ /* PCM-CAN100, 1-CAN Port, PC104/PC104+ compliant */
+ {ICPDAS_VENDOR_ID1, ICPDAS_DEVICE_ID1, ICPDAS_SUBVENDOR_ID1,
ICPDAS_SUBDEVICE_PCM_CAN100,},
+
+ /* PCM-CAN200, 2-CAN Port, PC104/PC104+ compliant */
+ {ICPDAS_VENDOR_ID1, ICPDAS_DEVICE_ID1, ICPDAS_SUBVENDOR_ID1,
ICPDAS_SUBDEVICE_PCM_CAN200,},
+
+ { 0,}
+};
+
+MODULE_DEVICE_TABLE(pci, icpdas_pci_tbl);
+
+/*
+ * Helper to read internal registers from card logic (not CAN)
+ */
+static u8 icpdas_pci_read_reg(const struct sja1000_priv *priv, int port)
+{
+ return ioread8(priv->reg_base + port);
+}
+
+static void icpdas_pci_write_reg(const struct sja1000_priv *priv,
+ int port, u8 val)
+{
+ iowrite8(val, priv->reg_base + port);
+}
+
+/*
+ * Check if a CAN controller is present at the specified location
+ * by trying to set 'em into the PeliCAN mode
+ */
+static inline int icpdas_pci_check_chan(const struct sja1000_priv *priv)
+{
+ unsigned char res;
+
+ /* Make sure SJA1000 is in reset mode */
+ priv->write_reg(priv, REG_MOD, 1);
+
+ priv->write_reg(priv, REG_CDR, CDR_PELICAN);
+
+ /* read reset-values */
+ res = priv->read_reg(priv, REG_CDR);
+
+ if (res == CDR_PELICAN)
+ return 1;
+
+ return 0;
+}
+
+static void icpdas_pci_del_card(struct pci_dev *pdev)
+{
+ struct icpdas_pci_card *card = pci_get_drvdata(pdev);
+ struct sja1000_priv *priv;
+ struct net_device *dev;
+ int i = 0;
+
+ for (i = 0; i < card->channels; i++)
+ {
+ dev = card->net_dev[i];
+
+ if (!dev)
+ continue;
+
+ priv = netdev_priv(dev);
+ dev_info(&pdev->dev, "Removing %s.\n", dev->name);
+
+ if(priv->reg_base != NULL)
+ pci_iounmap(card->pci_dev, priv->reg_base);
+
+ unregister_sja1000dev(dev);
+ free_sja1000dev(dev);
+ }
+
+ if (card->base_addr != NULL)
+ pci_iounmap(card->pci_dev, card->base_addr);
+
+ if (card->conf_addr != NULL)
+ pci_iounmap(card->pci_dev, card->conf_addr);
+
+ kfree(card);
+
+ pci_disable_device(pdev);
+ pci_set_drvdata(pdev, NULL);
+}
+
+static void icpdas_pci_card_reset(struct icpdas_pci_card *card)
+{
+ /* Request board reset */
+ writeb(0, card->base_addr);
+}
+
+/*
+ * Probe PCI device and register each available CAN channel to SJA1000
Socket-CAN subsystem.
+ */
+static int __devinit icpdas_pci_add_card(struct pci_dev *pdev,const struct
pci_device_id *ent)
+{
+ struct sja1000_priv *priv;
+ struct net_device *dev;
+ struct icpdas_pci_card *card;
+ int err, i;
+
+ /* Enabling PCI device */
+ if (pci_enable_device(pdev) < 0)
+ {
+ dev_err(&pdev->dev, "Enabling PCI device failed\n");
+ return -ENODEV;
+ }
+
+ /* Allocating card structures to hold addresses, ... */
+ card = kzalloc(sizeof(struct icpdas_pci_card), GFP_KERNEL);
+ if (card == NULL)
+ {
+ dev_err(&pdev->dev, "Unable to allocate memory\n");
+ pci_disable_device(pdev);
+ return -ENOMEM;
+ }
+
+ pci_set_drvdata(pdev, card);
+
+ card->pci_dev = pdev;
+ card->version = 0;
+ card->board = board_num;
+ card->channels = ((pdev->subsystem_device >> 8)&0x0f);
+
+ /* Remap configuration space and controller memory area */
+ card->conf_addr = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
+
+ if (card->conf_addr == NULL)
+ {
+ err = -ENOMEM;
+ goto failure_cleanup;
+ }
+
+ card->base_addr = pci_iomap(pdev, 2, pci_resource_len(pdev, 2));
+
+ if (card->base_addr == NULL)
+ {
+ err = -ENOMEM;
+ goto failure_cleanup;
+ }
+
+ icpdas_pci_card_reset(card);
+
+ /* Detect available channels */
+ for (i = 0; i < card->channels; i++)
+ {
+ dev = alloc_sja1000dev(sizeof(struct icpdas_pci_card));
+ if (dev == NULL)
+ {
+ err = -ENOMEM;
+ goto failure_cleanup;
+ }
+
+ card->net_dev[i] = dev;
+ priv = netdev_priv(dev);
+ priv->priv = card;
+ priv->irq_flags = IRQF_SHARED;
+
+ dev->irq = pdev->irq;
+ //Bar 0 (PLX), Bar 2 (port 1), Bar 3 ~ 5 (port 2 ~ 4)
+ priv->reg_base = pci_iomap(pdev, (i+2), pci_resource_len(pdev,
(i+2)));
+
+ priv->read_reg = icpdas_pci_read_reg;
+ priv->write_reg = icpdas_pci_write_reg;
+
+ /* Check if channel is present */
+ if (icpdas_pci_check_chan(priv))
+ {
+ priv->can.clock.freq = ICPDAS_PCI_CAN_CLOCK;
+ priv->ocr = ICPDAS_PCI_OCR;
+ priv->cdr = ICPDAS_PCI_CDR;
+
+ SET_NETDEV_DEV(dev, &pdev->dev);
+
+ /* Register SJA1000 device */
+ err = register_sja1000dev(dev);
+ if (err)
+ {
+ dev_err(&pdev->dev, "Registering device failed "
+ "(err=%d)\n", err);
+ free_sja1000dev(dev);
+ goto failure_cleanup;
+ }
+
+ dev_info(&pdev->dev, "Board #%d : Channel #%d at 0x%p,
irq %d\n", card->board, i + 1, priv->reg_base, dev->irq);
+ }
+ else
+ {
+ free_sja1000dev(dev);
+ }
+ }
+
+ iowrite32(PLX_ICSR_ENA_CLR, card->conf_addr + PLX_ICSR);
+
+ board_num++;
+
+ return 0;
+
+failure_cleanup:
+ dev_err(&pdev->dev, "Error: %d. Cleaning Up.\n", err);
+
+ icpdas_pci_del_card(pdev);
+
+ return err;
+}
+
+static struct pci_driver icpdas_pci_driver = {
+ .name = DRV_NAME,
+ .id_table = icpdas_pci_tbl,
+ .probe = icpdas_pci_add_card,
+ .remove = icpdas_pci_del_card,
+};
+
+static int __init icpdas_pci_init(void)
+{
+ return pci_register_driver(&icpdas_pci_driver);
+}
+
+static void __exit icpdas_pci_exit(void)
+{
+ pci_unregister_driver(&icpdas_pci_driver);
+}
+
+module_init(icpdas_pci_init);
+module_exit(icpdas_pci_exit);
+
diff -ruN trunk/kernel/2.6/drivers/net/can/sja1000/Kconfig
trunk-1199-icpdas-patch/kernel/2.6/drivers/net/can/sja1000/Kconfig
--- trunk/kernel/2.6/drivers/net/can/sja1000/Kconfig 2010-11-01
14:58:24.000000000 +0800
+++ trunk-1199-icpdas-patch/kernel/2.6/drivers/net/can/sja1000/Kconfig
2010-10-29 14:39:35.000000000 +0800
@@ -100,4 +100,12 @@
This driver adds support for the PIPCAN module used on some SBC
boards from MPL AG (http://www.mpl.ch).
+config CAN_ICPDAS_PCI
+ tristate "ICPDAS PCI Card"
+ depends on PCI && CAN_SJA1000
+ ---help---
+ This driver is for the ICPDAS PCI/104 card (1,2 or 4 channel)
+ PISO-CAN 200/400/200U/400U/200E and PCM-CAN 100/200
+ from ICP DAS (http://www.icpdas.com).
+
endif
diff -ruN trunk/kernel/2.6/drivers/net/can/sja1000/Makefile
trunk-1199-icpdas-patch/kernel/2.6/drivers/net/can/sja1000/Makefile
--- trunk/kernel/2.6/drivers/net/can/sja1000/Makefile 2010-11-01
14:58:24.000000000 +0800
+++ trunk-1199-icpdas-patch/kernel/2.6/drivers/net/can/sja1000/Makefile
2010-10-29 14:37:47.000000000 +0800
@@ -28,6 +28,7 @@
obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o
obj-$(CONFIG_CAN_PIPCAN) += pipcan.o
obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o
+obj-$(CONFIG_CAN_ICPDAS_PCI) += icpdas_pci.o
ifeq ($(CONFIG_CAN_DEBUG_DEVICES),y)
EXTRA_CFLAGS += -DDEBUG
diff -ruN trunk/kernel/2.6/Makefile trunk-1199-icpdas-patch/kernel/2.6/Makefile
--- trunk/kernel/2.6/Makefile 2010-11-01 14:58:24.000000000 +0800
+++ trunk-1199-icpdas-patch/kernel/2.6/Makefile 2010-10-29 14:40:58.000000000
+0800
@@ -29,6 +29,7 @@
export CONFIG_CAN_SOFTING=m
export CONFIG_CAN_SOFTING_CS=m
export CONFIG_CAN_MCP251X=m
+export CONFIG_CAN_ICPDAS_PCI=m
export CONFIG_CAN=m
export CONFIG_CAN_RAW=m
_______________________________________________
Socketcan-core mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-core