Lines Matching +full:ent +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2012 Stephane Grosjean <s.grosjean@peak-system.com>
8 * Copyright (C) 2001-2006 PEAK System-Technik GmbH
19 #include <linux/i2c-algo-bit.h>
25 MODULE_AUTHOR("Stephane Grosjean <s.grosjean@peak-system.com>");
26 MODULE_DESCRIPTION("Socket-CAN driver for PEAK PCAN PCI family cards");
62 #define PEAK_PC_104P_DEVICE_ID 0x0006 /* PCAN-PC/104+ cards */
63 #define PEAK_PCI_104E_DEVICE_ID 0x0007 /* PCAN-PCI/104 Express cards */
65 #define PEAK_PCIE_OEM_ID 0x0009 /* PCAN-PCI Express OEM */
66 #define PEAK_PCIEC34_DEVICE_ID 0x000A /* PCAN-PCI Express 34 (one channel) */
77 .driver_data = (kernel_ulong_t)"PCAN-PCI",
80 .driver_data = (kernel_ulong_t)"PCAN-PCI Express",
83 .driver_data = (kernel_ulong_t)"PCAN-miniPCI",
86 .driver_data = (kernel_ulong_t)"PCAN-miniPCIe",
89 .driver_data = (kernel_ulong_t)"PCAN-PC/104-Plus Quad",
92 .driver_data = (kernel_ulong_t)"PCAN-PCI/104-Express",
95 .driver_data = (kernel_ulong_t)"PCAN-cPCI",
98 .driver_data = (kernel_ulong_t)"PCAN-Chip PCIe",
103 .driver_data = (kernel_ulong_t)"PCAN-ExpressCard",
106 .driver_data = (kernel_ulong_t)"PCAN-ExpressCard 34",
115 /* PCAN-ExpressCard needs I2C bit-banging configuration option. */
180 u8 gp_outen = readb(card->cfg_base + PITA_GPOEN) & ~PITA_GPIN_SCL; in pita_set_scl_highz()
182 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_set_scl_highz()
187 u8 gp_outen = readb(card->cfg_base + PITA_GPOEN) & ~PITA_GPIN_SDA; in pita_set_sda_highz()
189 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_set_sda_highz()
194 /* raise SCL & SDA GPIOs to high-Z */ in peak_pciec_init_pita_gpio()
205 gp_out = readb(card->cfg_base + PITA_GPOUT) & ~PITA_GPIN_SDA; in pita_setsda()
206 writeb(gp_out, card->cfg_base + PITA_GPOUT); in pita_setsda()
209 gp_outen = readb(card->cfg_base + PITA_GPOEN); in pita_setsda()
215 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_setsda()
224 gp_out = readb(card->cfg_base + PITA_GPOUT) & ~PITA_GPIN_SCL; in pita_setscl()
225 writeb(gp_out, card->cfg_base + PITA_GPOUT); in pita_setscl()
228 gp_outen = readb(card->cfg_base + PITA_GPOEN); in pita_setscl()
234 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_setscl()
244 return (readb(card->cfg_base + PITA_GPIN) & PITA_GPIN_SDA) ? 1 : 0; in pita_getsda()
254 return (readb(card->cfg_base + PITA_GPIN) & PITA_GPIN_SCL) ? 1 : 0; in pita_getscl()
257 /* write commands to the LED chip though the I2C-bus of the PCAN-PCIeC */
273 if (offset == 5 && data == card->led_cache) in peak_pciec_write_pca9553()
276 ret = i2c_transfer(&card->led_chip, &msg, 1); in peak_pciec_write_pca9553()
281 card->led_cache = data; in peak_pciec_write_pca9553()
292 u8 new_led = card->led_cache; in peak_pciec_led_work()
296 for (i = 0; i < card->chan_count; i++) { in peak_pciec_led_work()
301 netdev = card->channel[i].netdev; in peak_pciec_led_work()
302 if (!netdev || !(netdev->flags & IFF_UP)) in peak_pciec_led_work()
312 if (netdev->stats.rx_bytes != card->channel[i].prev_rx_bytes) { in peak_pciec_led_work()
313 card->channel[i].prev_rx_bytes = netdev->stats.rx_bytes; in peak_pciec_led_work()
317 if (netdev->stats.tx_bytes != card->channel[i].prev_tx_bytes) { in peak_pciec_led_work()
318 card->channel[i].prev_tx_bytes = netdev->stats.tx_bytes; in peak_pciec_led_work()
329 schedule_delayed_work(&card->led_work, HZ); in peak_pciec_led_work()
335 u8 new_led = card->led_cache; in peak_pciec_set_leds()
339 for (i = 0; i < card->chan_count; i++) in peak_pciec_set_leds()
352 schedule_delayed_work(&card->led_work, HZ); in peak_pciec_start_led_work()
358 cancel_delayed_work_sync(&card->led_work); in peak_pciec_stop_led_work()
361 /* initialize the PCA9553 4-bit I2C-bus LED chip */
403 struct peak_pci_chan *chan = priv->priv; in peak_pciec_write_reg()
404 struct peak_pciec_card *card = chan->pciec_card; in peak_pciec_write_reg()
405 int c = (priv->reg_base - card->reg_base) / PEAK_PCI_CHAN_SIZE; in peak_pciec_write_reg()
439 struct peak_pci_chan *chan = priv->priv; in peak_pciec_probe()
444 if (chan->prev_dev) { in peak_pciec_probe()
445 struct sja1000_priv *prev_priv = netdev_priv(chan->prev_dev); in peak_pciec_probe()
446 struct peak_pci_chan *prev_chan = prev_priv->priv; in peak_pciec_probe()
448 card = prev_chan->pciec_card; in peak_pciec_probe()
450 return -ENODEV; in peak_pciec_probe()
457 return -ENOMEM; in peak_pciec_probe()
459 card->cfg_base = chan->cfg_base; in peak_pciec_probe()
460 card->reg_base = priv->reg_base; in peak_pciec_probe()
462 card->led_chip.owner = THIS_MODULE; in peak_pciec_probe()
463 card->led_chip.dev.parent = &pdev->dev; in peak_pciec_probe()
464 card->led_chip.algo_data = &card->i2c_bit; in peak_pciec_probe()
465 strscpy(card->led_chip.name, "peak_i2c", in peak_pciec_probe()
466 sizeof(card->led_chip.name)); in peak_pciec_probe()
468 card->i2c_bit = peak_pciec_i2c_bit_ops; in peak_pciec_probe()
469 card->i2c_bit.udelay = 10; in peak_pciec_probe()
470 card->i2c_bit.timeout = HZ; in peak_pciec_probe()
471 card->i2c_bit.data = card; in peak_pciec_probe()
475 err = i2c_bit_add_bus(&card->led_chip); in peak_pciec_probe()
477 dev_err(&pdev->dev, "i2c init failed\n"); in peak_pciec_probe()
483 dev_err(&pdev->dev, "leds hardware init failed\n"); in peak_pciec_probe()
487 INIT_DELAYED_WORK(&card->led_work, peak_pciec_led_work); in peak_pciec_probe()
488 /* PCAN-ExpressCard needs its own callback for leds */ in peak_pciec_probe()
489 priv->write_reg = peak_pciec_write_reg; in peak_pciec_probe()
492 chan->pciec_card = card; in peak_pciec_probe()
493 card->channel[card->chan_count++].netdev = dev; in peak_pciec_probe()
498 i2c_del_adapter(&card->led_chip); in peak_pciec_probe()
511 i2c_del_adapter(&card->led_chip); in peak_pciec_remove()
518 /* Placebo functions when PCAN-ExpressCard support is not selected */
521 return -ENODEV; in peak_pciec_probe()
531 return readb(priv->reg_base + (port << 2)); in peak_pci_read_reg()
537 writeb(val, priv->reg_base + (port << 2)); in peak_pci_write_reg()
542 struct peak_pci_chan *chan = priv->priv; in peak_pci_post_irq()
546 icr = readw(chan->cfg_base + PITA_ICR); in peak_pci_post_irq()
547 if (icr & chan->icr_mask) in peak_pci_post_irq()
548 writew(chan->icr_mask, chan->cfg_base + PITA_ICR); in peak_pci_post_irq()
551 static int peak_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) in peak_pci_probe() argument
573 dev_dbg(&pdev->dev, "probing device %04x:%04x:%04x\n", in peak_pci_probe()
574 pdev->vendor, pdev->device, sub_sys_id); in peak_pci_probe()
591 dev_err(&pdev->dev, "failed to map PCI resource #0\n"); in peak_pci_probe()
592 err = -ENOMEM; in peak_pci_probe()
598 dev_err(&pdev->dev, "failed to map PCI resource #1\n"); in peak_pci_probe()
599 err = -ENOMEM; in peak_pci_probe()
625 dev_info(&pdev->dev, "%ux CAN %s%s\n", in peak_pci_probe()
626 channels, (const char *)ent->driver_data, fw_str); in peak_pci_probe()
633 err = -ENOMEM; in peak_pci_probe()
638 chan = priv->priv; in peak_pci_probe()
640 chan->cfg_base = cfg_base; in peak_pci_probe()
641 priv->reg_base = reg_base + i * PEAK_PCI_CHAN_SIZE; in peak_pci_probe()
643 priv->read_reg = peak_pci_read_reg; in peak_pci_probe()
644 priv->write_reg = peak_pci_write_reg; in peak_pci_probe()
645 priv->post_irq = peak_pci_post_irq; in peak_pci_probe()
647 priv->can.clock.freq = PEAK_PCI_CAN_CLOCK; in peak_pci_probe()
648 priv->ocr = PEAK_PCI_OCR; in peak_pci_probe()
649 priv->cdr = PEAK_PCI_CDR; in peak_pci_probe()
652 priv->cdr |= CDR_CLK_OFF; in peak_pci_probe()
655 priv->irq_flags = IRQF_SHARED; in peak_pci_probe()
656 dev->irq = pdev->irq; in peak_pci_probe()
658 chan->icr_mask = peak_pci_icr_masks[i]; in peak_pci_probe()
659 icr |= chan->icr_mask; in peak_pci_probe()
661 SET_NETDEV_DEV(dev, &pdev->dev); in peak_pci_probe()
662 dev->dev_id = i; in peak_pci_probe()
665 chan->prev_dev = pci_get_drvdata(pdev); in peak_pci_probe()
668 /* PCAN-ExpressCard needs some additional i2c init. in peak_pci_probe()
672 if (pdev->device == PEAK_PCIEC_DEVICE_ID || in peak_pci_probe()
673 pdev->device == PEAK_PCIEC34_DEVICE_ID) { in peak_pci_probe()
676 dev_err(&pdev->dev, in peak_pci_probe()
685 dev_err(&pdev->dev, "failed to register device\n"); in peak_pci_probe()
689 dev_info(&pdev->dev, in peak_pci_probe()
691 dev->name, priv->reg_base, chan->cfg_base, dev->irq); in peak_pci_probe()
700 pci_set_drvdata(pdev, chan->prev_dev); in peak_pci_probe()
710 chan = priv->priv; in peak_pci_probe()
711 prev_dev = chan->prev_dev; in peak_pci_probe()
718 if (chan && chan->pciec_card) in peak_pci_probe()
719 peak_pciec_remove(chan->pciec_card); in peak_pci_probe()
743 struct peak_pci_chan *chan = priv->priv; in peak_pci_remove()
744 void __iomem *cfg_base = chan->cfg_base; in peak_pci_remove()
745 void __iomem *reg_base = priv->reg_base; in peak_pci_remove()
752 struct net_device *prev_dev = chan->prev_dev; in peak_pci_remove()
754 dev_info(&pdev->dev, "removing device %s\n", dev->name); in peak_pci_remove()
756 if (!prev_dev && chan->pciec_card) in peak_pci_remove()
757 peak_pciec_remove(chan->pciec_card); in peak_pci_remove()
765 chan = priv->priv; in peak_pci_remove()