20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/netdevice.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
32 #define DRV_NAME "ems_pci"
39 #define EMS_PCI_V1_MAX_CHAN 2
40 #define EMS_PCI_V2_MAX_CHAN 4
41 #define EMS_PCI_MAX_CHAN EMS_PCI_V2_MAX_CHAN
54 #define EMS_PCI_CAN_CLOCK (16000000 / 2)
61 #define PITA2_ICR 0x00
62 #define PITA2_ICR_INT0 0x00000002
63 #define PITA2_ICR_INT0_EN 0x00020000
65 #define PITA2_MISC 0x1c
66 #define PITA2_MISC_CONFIG 0x04000000
72 #define PLX_ICSR_LINTI1_ENA 0x0001
73 #define PLX_ICSR_PCIINT_ENA 0x0040
74 #define PLX_ICSR_LINTI1_CLR 0x0400
75 #define PLX_ICSR_ENA_CLR (PLX_ICSR_LINTI1_ENA | PLX_ICSR_PCIINT_ENA | \
86 #define EMS_PCI_OCR (OCR_TX0_PUSHPULL | OCR_TX1_PUSHPULL)
94 #define EMS_PCI_CDR (CDR_CBP | CDR_CLKOUT_MASK)
96 #define EMS_PCI_V1_BASE_BAR 1
97 #define EMS_PCI_V1_CONF_SIZE 4096
98 #define EMS_PCI_V2_BASE_BAR 2
99 #define EMS_PCI_V2_CONF_SIZE 128
100 #define EMS_PCI_CAN_BASE_OFFSET 0x400
101 #define EMS_PCI_CAN_CTRL_SIZE 0x200
103 #define EMS_PCI_BASE_SIZE 4096
149 static void ems_pci_v2_write_reg(
const struct sja1000_priv *priv,
155 static void ems_pci_v2_post_irq(
const struct sja1000_priv *priv)
166 static inline int ems_pci_check_chan(
const struct sja1000_priv *priv)
184 static void ems_pci_del_card(
struct pci_dev *pdev)
190 for (i = 0; i < card->
channels; i++) {
210 pci_set_drvdata(pdev,
NULL);
213 static void ems_pci_card_reset(
struct ems_pci_card *card)
229 int max_chan, conf_size, base_bar;
234 dev_err(&pdev->
dev,
"Enabling PCI device failed\n");
241 dev_err(&pdev->
dev,
"Unable to allocate memory\n");
246 pci_set_drvdata(pdev, card);
265 card->
conf_addr = pci_iomap(pdev, 0, conf_size);
268 goto failure_cleanup;
274 goto failure_cleanup;
282 if (ems_pci_v1_readb(card, 0) != 0x55 ||
283 ems_pci_v1_readb(card, 1) != 0xAA ||
284 ems_pci_v1_readb(card, 2) != 0x01 ||
285 ems_pci_v1_readb(card, 3) != 0xCB ||
286 ems_pci_v1_readb(card, 4) != 0x11) {
288 "Not EMS Dr. Thomas Wuensche interface\n");
290 goto failure_cleanup;
294 ems_pci_card_reset(card);
297 for (i = 0; i < max_chan; i++) {
301 goto failure_cleanup;
305 priv = netdev_priv(dev);
313 priv->
read_reg = ems_pci_v1_read_reg;
315 priv->
post_irq = ems_pci_v1_post_irq;
317 priv->
read_reg = ems_pci_v2_read_reg;
319 priv->
post_irq = ems_pci_v2_post_irq;
323 if (ems_pci_check_chan(priv)) {
342 dev_err(&pdev->
dev,
"Registering device failed "
345 goto failure_cleanup;
350 dev_info(&pdev->
dev,
"Channel #%d at 0x%p, irq %d\n",
360 dev_err(&pdev->
dev,
"Error: %d. Cleaning Up.\n", err);
362 ems_pci_del_card(pdev);
369 .id_table = ems_pci_tbl,
370 .probe = ems_pci_add_card,
371 .remove = ems_pci_del_card,