Message ID | 4E692080.9020801@grandegger.com |
---|---|
State | Superseded, archived |
Delegated to: | David Miller |
Headers | show |
Hello Wolfgang, many thanks for providing this patch! On 09/08/11 22:07, Wolfgang Grandegger wrote: > This patch adds the "peak_pci" driver for the PCAN PCI/PCIe cards (1, 2, 3 > or 4 channels) from PEAK Systems (http://www.peak-system.com). Yes - that fits, but ... > +#define PEAK_PCI_VENDOR_ID 0x001C /* The PCI device and vendor IDs */ > +#define PEAK_PCI_DEVICE_ID 0x0001 /* for PCI / PCIe slot cards */ > +#define PEAK_PCIE_DEVICE_ID 0x0002 /* for PCIExpress cards */ > + > +static const u16 peak_pci_icr_masks[] = {0x02, 0x01, 0x40, 0x80}; > + > +static DEFINE_PCI_DEVICE_TABLE(peak_pci_tbl) = { > + {PEAK_PCI_VENDOR_ID, PEAK_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, > + {PEAK_PCI_VENDOR_ID, PEAK_PCIE_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, > + {0,} > +}; The problem is the support of the PCAN ExpressCard (device ID 0x0002) here. This commit https://lists.berlios.de/pipermail/socketcan-commit/2010-June/000814.html should be reverted, as you can use the PCAN-ExpressCard (IPEH-00300[12]) only with a hardware patch, as we need some I2C initialisations to enable the CAN transceiver (and the funky status LEDs). See at: http://anonscm.debian.org/gitweb/?p=collab-maint/peak-linux-driver.git;a=blob;f=driver/src/pcan_pciec.c;h=87ce0bda41aa0a6dda8284d48237b1ef7c678e11;hb=HEAD#l36 I'll also test your driver on Monday. Tnx & best regards, Oliver -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Oliver, On 09/09/2011 04:42 PM, Oliver Hartkopp wrote: > Hello Wolfgang, > > many thanks for providing this patch! > > On 09/08/11 22:07, Wolfgang Grandegger wrote: > >> This patch adds the "peak_pci" driver for the PCAN PCI/PCIe cards (1, 2, 3 >> or 4 channels) from PEAK Systems (http://www.peak-system.com). > > > Yes - that fits, but ... > > >> +#define PEAK_PCI_VENDOR_ID 0x001C /* The PCI device and vendor IDs */ >> +#define PEAK_PCI_DEVICE_ID 0x0001 /* for PCI / PCIe slot cards */ >> +#define PEAK_PCIE_DEVICE_ID 0x0002 /* for PCIExpress cards */ >> + >> +static const u16 peak_pci_icr_masks[] = {0x02, 0x01, 0x40, 0x80}; >> + >> +static DEFINE_PCI_DEVICE_TABLE(peak_pci_tbl) = { >> + {PEAK_PCI_VENDOR_ID, PEAK_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, >> + {PEAK_PCI_VENDOR_ID, PEAK_PCIE_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, >> + {0,} >> +}; > > > The problem is the support of the PCAN ExpressCard (device ID 0x0002) here. > > This commit > > https://lists.berlios.de/pipermail/socketcan-commit/2010-June/000814.html > > should be reverted, as you can use the PCAN-ExpressCard (IPEH-00300[12]) only > with a hardware patch, as we need some I2C initialisations to enable the CAN > transceiver (and the funky status LEDs). See at: > > http://anonscm.debian.org/gitweb/?p=collab-maint/peak-linux-driver.git;a=blob;f=driver/src/pcan_pciec.c;h=87ce0bda41aa0a6dda8284d48237b1ef7c678e11;hb=HEAD#l36 OK, I see, I will revert then. I already realized the I2C stuff for the PCAN-ExpressCard. Obviously Thomas does not use that card but a PCIe slot cards > I'll also test your driver on Monday. Thanks, Wolfgang. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 09/09/11 17:20, Wolfgang Grandegger wrote: > >> I'll also test your driver on Monday. > > Thanks, Hi Wolfgang, even if i only had my hardware-patched PEAK PCI ExpressCard hardware here (which is to be removed in the supported PCI device list due to the missing I2C initialization), i successfully tested your driver. Tested-by: Oliver Hartkopp <socketcan@hartkopp.net> So let's wait for some feedback from Thomas, when he's back to the office ;-) Tnx & best regards, Oliver -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Oliver, On 09/12/2011 05:49 PM, Oliver Hartkopp wrote: > On 09/09/11 17:20, Wolfgang Grandegger wrote: > > >> >>> I'll also test your driver on Monday. >> >> Thanks, > > > Hi Wolfgang, > > even if i only had my hardware-patched PEAK PCI ExpressCard hardware here > (which is to be removed in the supported PCI device list due to the missing > I2C initialization), i successfully tested your driver. > > Tested-by: Oliver Hartkopp <socketcan@hartkopp.net> Thanks, I have just sent v2. > So let's wait for some feedback from Thomas, when he's back to the office ;-) Yep, some testing on a 4 channel card would be nice. Wolfgang. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi together, i'll test the patch as soon as the system is available again, which is not before next week. Thomas Wolfgang Grandegger <wg@grandegger.com> schrieb am 13.09.2011 09:38:57: > Hi Oliver, > > On 09/12/2011 05:49 PM, Oliver Hartkopp wrote: > > On 09/09/11 17:20, Wolfgang Grandegger wrote: > > > > > >> > >>> I'll also test your driver on Monday. > >> > >> Thanks, > > > > > > Hi Wolfgang, > > > > even if i only had my hardware-patched PEAK PCI ExpressCard hardware here > > (which is to be removed in the supported PCI device list due to the missing > > I2C initialization), i successfully tested your driver. > > > > Tested-by: Oliver Hartkopp <socketcan@hartkopp.net> > > Thanks, I have just sent v2. > > > So let's wait for some feedback from Thomas, when he's back to the office ;-) > > Yep, some testing on a 4 channel card would be nice. > > Wolfgang. > -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
I got access to another system with a 4 channel card and tested your patch (v1) within the Berlios socket-can SVN tree: it worked :) Thanks! Thomas Wolfgang Grandegger <wg@grandegger.com> schrieb am 13.09.2011 09:38:57: > Hi Oliver, > > On 09/12/2011 05:49 PM, Oliver Hartkopp wrote: > > On 09/09/11 17:20, Wolfgang Grandegger wrote: > > > > > >> > >>> I'll also test your driver on Monday. > >> > >> Thanks, > > > > > > Hi Wolfgang, > > > > even if i only had my hardware-patched PEAK PCI ExpressCard hardware here > > (which is to be removed in the supported PCI device list due to the missing > > I2C initialization), i successfully tested your driver. > > > > Tested-by: Oliver Hartkopp <socketcan@hartkopp.net> > > Thanks, I have just sent v2. > > > So let's wait for some feedback from Thomas, when he's back to the office ;-) > > Yep, some testing on a 4 channel card would be nice. > > Wolfgang. > -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Thomas, On 09/29/2011 11:21 AM, Thomas Wiedemann wrote: > I got access to another system with a 4 channel card and tested your patch > (v1) within the Berlios socket-can SVN tree: it worked :) Hm, did the patch apply to the SVN tree? Any chance to test with David Miller's net-next-2.6 tree. Anyway, I'm quite sure now that the patch works fine on 4-channel cards as well. Thanks for your effort. Wolfgang. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Wolfgang, i just replaced peak_pci.c. The net-next-2.6 branch? Is that the one in the latest linux kernels? I'll try to find some time to test a new kernel. Thomas Wolfgang Grandegger <wg@grandegger.com> schrieb am 29.09.2011 12:39:55: > Hi Thomas, > > On 09/29/2011 11:21 AM, Thomas Wiedemann wrote: > > I got access to another system with a 4 channel card and tested your patch > > (v1) within the Berlios socket-can SVN tree: it worked :) > > Hm, did the patch apply to the SVN tree? Any chance to test with David > Miller's net-next-2.6 tree. Anyway, I'm quite sure now that the patch > works fine on 4-channel cards as well. > > Thanks for your effort. > > Wolfgang. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Thomas, On 09/29/2011 01:46 PM, Thomas Wiedemann wrote: > Hi Wolfgang, > i just replaced peak_pci.c. > The net-next-2.6 branch? Is that the one in the latest linux kernels? I'll > try to find some time to test a new kernel. Temporarily (kernel.org is still down) you can get the "net-next-2.6" as shown below: $ git clone git://github.com/davem330/net-next.git The tree is maintained by David Miller and will show up mainline with the next kernel release. Thanks, Wolfgang. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/net/can/sja1000/Kconfig b/drivers/net/can/sja1000/Kconfig index 6fdc031..72b637d 100644 --- a/drivers/net/can/sja1000/Kconfig +++ b/drivers/net/can/sja1000/Kconfig @@ -37,6 +37,13 @@ config CAN_EMS_PCI CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). +config CAN_PEAK_PCI + tristate "PEAK PCAN PCI/PCIe Cards" + depends on PCI + ---help--- + This driver is for the PCAN PCI/PCIe cards (1, 2, 3 or 4 channels) + from PEAK Systems (http://www.peak-system.com). + config CAN_KVASER_PCI tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards" depends on PCI diff --git a/drivers/net/can/sja1000/Makefile b/drivers/net/can/sja1000/Makefile index 2c591eb..428f5cf 100644 --- a/drivers/net/can/sja1000/Makefile +++ b/drivers/net/can/sja1000/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_CAN_SJA1000_PLATFORM) += sja1000_platform.o obj-$(CONFIG_CAN_SJA1000_OF_PLATFORM) += sja1000_of_platform.o obj-$(CONFIG_CAN_EMS_PCI) += ems_pci.o obj-$(CONFIG_CAN_KVASER_PCI) += kvaser_pci.o +obj-$(CONFIG_CAN_PEAK_PCI) += peak_pci.o obj-$(CONFIG_CAN_PLX_PCI) += plx_pci.o obj-$(CONFIG_CAN_TSCAN1) += tscan1.o diff --git a/drivers/net/can/sja1000/peak_pci.c b/drivers/net/can/sja1000/peak_pci.c new file mode 100644 index 0000000..23d865d --- /dev/null +++ b/drivers/net/can/sja1000/peak_pci.c @@ -0,0 +1,293 @@ +/* + * Copyright (C) 2007, 2011 Wolfgang Grandegger <wg@grandegger.com> + * + * Derived from the PCAN project file driver/src/pcan_pci.c: + * + * Copyright (C) 2001-2006 PEAK System-Technik GmbH + * + * 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/io.h> +#include <linux/can.h> +#include <linux/can/dev.h> + +#include "sja1000.h" + +MODULE_AUTHOR("Wolfgang Grandegger <wg@grandegger.com>"); +MODULE_DESCRIPTION("Socket-CAN driver for PEAK PCAN PCI/PCIe cards"); +MODULE_SUPPORTED_DEVICE("PEAK PCAN PCI/PCIe CAN card"); +MODULE_LICENSE("GPL v2"); + +#define DRV_NAME "peak_pci" + +struct peak_pci_chan { + void __iomem *cfg_base; /* Common for all channels */ + struct net_device *next_dev; /* Chain of network devices */ + u16 icr_mask; /* Interrupt mask for fast ack */ +}; + +#define PEAK_PCI_CAN_CLOCK (16000000 / 2) + +#define PEAK_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK) +#define PEAK_PCI_OCR OCR_TX0_PUSHPULL + +/* + * Important PITA registers + */ +#define PITA_ICR 0x00 /* Interrupt control register */ +#define PITA_GPIOICR 0x18 /* GPIO interface control register */ +#define PITA_MISC 0x1C /* Miscellaneous register */ + +#define PEAK_PCI_CFG_SIZE 0x1000 /* Size of the config PCI bar */ +#define PEAK_PCI_CHAN_SIZE 0x0400 /* Size used by the channel */ + +#define PEAK_PCI_VENDOR_ID 0x001C /* The PCI device and vendor IDs */ +#define PEAK_PCI_DEVICE_ID 0x0001 /* for PCI / PCIe slot cards */ +#define PEAK_PCIE_DEVICE_ID 0x0002 /* for PCIExpress cards */ + +static const u16 peak_pci_icr_masks[] = {0x02, 0x01, 0x40, 0x80}; + +static DEFINE_PCI_DEVICE_TABLE(peak_pci_tbl) = { + {PEAK_PCI_VENDOR_ID, PEAK_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, + {PEAK_PCI_VENDOR_ID, PEAK_PCIE_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID,}, + {0,} +}; + +MODULE_DEVICE_TABLE(pci, peak_pci_tbl); + +static u8 peak_pci_read_reg(const struct sja1000_priv *priv, int port) +{ + return readb(priv->reg_base + (port << 2)); +} + +static void peak_pci_write_reg(const struct sja1000_priv *priv, + int port, u8 val) +{ + writeb(val, priv->reg_base + (port << 2)); +} + +static void peak_pci_post_irq(const struct sja1000_priv *priv) +{ + struct peak_pci_chan *chan = priv->priv; + u16 icr; + + /* Select and clear in PITA stored interrupt */ + icr = readw(chan->cfg_base + PITA_ICR); + if (icr & chan->icr_mask) + writew(chan->icr_mask, chan->cfg_base + PITA_ICR); +} + +static int __devinit peak_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *ent) +{ + struct sja1000_priv *priv; + struct peak_pci_chan *chan; + struct net_device *dev, *dev0 = NULL; + void __iomem *cfg_base, *reg_base; + u16 sub_sys_id, icr; + int i, err, channels; + + err = pci_enable_device(pdev); + if (err) + return err; + + err = pci_request_regions(pdev, DRV_NAME); + if (err) + goto failure_disable_pci; + + err = pci_read_config_word(pdev, 0x2e, &sub_sys_id); + if (err) + goto failure_release_regions; + + dev_dbg(&pdev->dev, "probing device %04x:%04x:%04x\n", + pdev->vendor, pdev->device, sub_sys_id); + + err = pci_write_config_word(pdev, 0x44, 0); + if (err) + goto failure_release_regions; + + if (sub_sys_id >= 12) + channels = 4; + else if (sub_sys_id >= 10) + channels = 3; + else if (sub_sys_id >= 4) + channels = 2; + else + channels = 1; + + cfg_base = pci_iomap(pdev, 0, PEAK_PCI_CFG_SIZE); + if (!cfg_base) { + dev_err(&pdev->dev, "failed to map PCI resource #0\n"); + goto failure_release_regions; + } + + reg_base = pci_iomap(pdev, 1, PEAK_PCI_CHAN_SIZE * channels); + if (!reg_base) { + dev_err(&pdev->dev, "failed to map PCI resource #1\n"); + goto failure_unmap_cfg_base; + } + + /* Set GPIO control register */ + writew(0x0005, cfg_base + PITA_GPIOICR + 2); + /* Enable all channels of this card */ + writeb(0x00, cfg_base + PITA_GPIOICR); + /* Toggle reset */ + writeb(0x05, cfg_base + PITA_MISC + 3); + mdelay(5); + /* Leave parport mux mode */ + writeb(0x04, cfg_base + PITA_MISC + 3); + + icr = readw(cfg_base + PITA_ICR + 2); + + for (i = 0; i < channels; i++) { + dev = alloc_sja1000dev(sizeof(struct peak_pci_chan)); + if (!dev) { + err = -ENOMEM; + goto failure_remove_channels; + } + + priv = netdev_priv(dev); + chan = priv->priv; + + chan->cfg_base = cfg_base; + priv->reg_base = reg_base + i * PEAK_PCI_CHAN_SIZE; + + priv->read_reg = peak_pci_read_reg; + priv->write_reg = peak_pci_write_reg; + priv->post_irq = peak_pci_post_irq; + + priv->can.clock.freq = PEAK_PCI_CAN_CLOCK; + priv->ocr = PEAK_PCI_OCR; + priv->cdr = PEAK_PCI_CDR; + /* Neither a slave nor a single device distributes the clock */ + if (channels == 1 || i > 0) + priv->cdr |= CDR_CLK_OFF; + + /* Setup interrupt handling */ + priv->irq_flags = IRQF_SHARED; + dev->irq = pdev->irq; + + chan->icr_mask = peak_pci_icr_masks[i]; + icr |= chan->icr_mask; + + SET_NETDEV_DEV(dev, &pdev->dev); + + err = register_sja1000dev(dev); + if (err) { + dev_err(&pdev->dev, "failed to register device\n"); + free_sja1000dev(dev); + goto failure_remove_channels; + } + + /* Create chain of SJA1000 devices */ + if (i == 0) + dev0 = dev; + else + chan->next_dev = dev; + + dev_info(&pdev->dev, + "%s at reg_base=0x%p cfg_base=0x%p irq=%d\n", + dev->name, priv->reg_base, chan->cfg_base, dev->irq); + } + + pci_set_drvdata(pdev, dev0); + + /* Enable interrupts */ + writew(icr, cfg_base + PITA_ICR + 2); + + return 0; + +failure_remove_channels: + /* Disable interrupts */ + writew(0x0, cfg_base + PITA_ICR + 2); + + for (dev = dev0; dev; dev = chan->next_dev) { + unregister_sja1000dev(dev); + free_sja1000dev(dev); + priv = netdev_priv(dev); + chan = priv->priv; + dev = chan->next_dev; + } + + pci_iounmap(pdev, reg_base); + +failure_unmap_cfg_base: + pci_iounmap(pdev, cfg_base); + +failure_release_regions: + pci_release_regions(pdev); + +failure_disable_pci: + pci_disable_device(pdev); + + return err; +} + +static void __devexit peak_pci_remove(struct pci_dev *pdev) +{ + struct net_device *dev = pci_get_drvdata(pdev); /* First device */ + struct sja1000_priv *priv = netdev_priv(dev); + struct peak_pci_chan *chan = priv->priv; + void __iomem *cfg_base = chan->cfg_base; + void __iomem *reg_base = priv->reg_base; + + /* Disable interrupts */ + writew(0x0, cfg_base + PITA_ICR + 2); + + /* Loop over all registered devices */ + while (1) { + dev_info(&pdev->dev, "removing device %s\n", dev->name); + unregister_sja1000dev(dev); + free_sja1000dev(dev); + dev = chan->next_dev; + if (!dev) + break; + priv = netdev_priv(dev); + chan = priv->priv; + } + + pci_iounmap(pdev, reg_base); + pci_iounmap(pdev, cfg_base); + pci_release_regions(pdev); + pci_disable_device(pdev); + + pci_set_drvdata(pdev, NULL); +} + +static struct pci_driver peak_pci_driver = { + .name = DRV_NAME, + .id_table = peak_pci_tbl, + .probe = peak_pci_probe, + .remove = __devexit_p(peak_pci_remove), +}; + +static int __init peak_pci_init(void) +{ + return pci_register_driver(&peak_pci_driver); +} +module_init(peak_pci_init); + +static void __exit peak_pci_exit(void) +{ + pci_unregister_driver(&peak_pci_driver); +} +module_exit(peak_pci_exit);
This patch adds the "peak_pci" driver for the PCAN PCI/PCIe cards (1, 2, 3 or 4 channels) from PEAK Systems (http://www.peak-system.com). Signed-off-by: Wolfgang Grandegger <wg@grandegger.com> --- I have tested this patch on my 2 channel PEAK PCI card. Thomas, or somebody else with a PEAK PCAN PCI/PCIe card at hand, it would be nice if you could test it on your 4 channel card and add your "Tested-by". Thanks, Wolfgang. drivers/net/can/sja1000/Kconfig | 7 + drivers/net/can/sja1000/Makefile | 1 + drivers/net/can/sja1000/peak_pci.c | 293 ++++++++++++++++++++++++++++++++++++ 3 files changed, 301 insertions(+), 0 deletions(-) create mode 100644 drivers/net/can/sja1000/peak_pci.c