Lines Matching +full:bit +full:- +full:banging

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) */
94 * PCAN-ExpressCard needs I2C bit-banging configuration option.
160 u8 gp_outen = readb(card->cfg_base + PITA_GPOEN) & ~PITA_GPIN_SCL; in pita_set_scl_highz()
161 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_set_scl_highz()
166 u8 gp_outen = readb(card->cfg_base + PITA_GPOEN) & ~PITA_GPIN_SDA; in pita_set_sda_highz()
167 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_set_sda_highz()
172 /* raise SCL & SDA GPIOs to high-Z */ in peak_pciec_init_pita_gpio()
183 gp_out = readb(card->cfg_base + PITA_GPOUT) & ~PITA_GPIN_SDA; in pita_setsda()
184 writeb(gp_out, card->cfg_base + PITA_GPOUT); in pita_setsda()
187 gp_outen = readb(card->cfg_base + PITA_GPOEN); in pita_setsda()
193 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_setsda()
202 gp_out = readb(card->cfg_base + PITA_GPOUT) & ~PITA_GPIN_SCL; in pita_setscl()
203 writeb(gp_out, card->cfg_base + PITA_GPOUT); in pita_setscl()
206 gp_outen = readb(card->cfg_base + PITA_GPOEN); in pita_setscl()
212 writeb(gp_outen, card->cfg_base + PITA_GPOEN); in pita_setscl()
222 return (readb(card->cfg_base + PITA_GPIN) & PITA_GPIN_SDA) ? 1 : 0; in pita_getsda()
232 return (readb(card->cfg_base + PITA_GPIN) & PITA_GPIN_SCL) ? 1 : 0; in pita_getscl()
236 * write commands to the LED chip though the I2C-bus of the PCAN-PCIeC
253 if ((offset == 5) && (data == card->led_cache)) in peak_pciec_write_pca9553()
256 ret = i2c_transfer(&card->led_chip, &msg, 1); in peak_pciec_write_pca9553()
261 card->led_cache = data; in peak_pciec_write_pca9553()
274 u8 new_led = card->led_cache; in peak_pciec_led_work()
278 for (i = 0; i < card->chan_count; i++) { in peak_pciec_led_work()
283 netdev = card->channel[i].netdev; in peak_pciec_led_work()
284 if (!netdev || !(netdev->flags & IFF_UP)) in peak_pciec_led_work()
294 if (netdev->stats.rx_bytes != card->channel[i].prev_rx_bytes) { in peak_pciec_led_work()
295 card->channel[i].prev_rx_bytes = netdev->stats.rx_bytes; in peak_pciec_led_work()
299 if (netdev->stats.tx_bytes != card->channel[i].prev_tx_bytes) { in peak_pciec_led_work()
300 card->channel[i].prev_tx_bytes = netdev->stats.tx_bytes; in peak_pciec_led_work()
311 schedule_delayed_work(&card->led_work, HZ); in peak_pciec_led_work()
319 u8 new_led = card->led_cache; in peak_pciec_set_leds()
323 for (i = 0; i < card->chan_count; i++) in peak_pciec_set_leds()
338 schedule_delayed_work(&card->led_work, HZ); in peak_pciec_start_led_work()
346 cancel_delayed_work_sync(&card->led_work); in peak_pciec_stop_led_work()
350 * initialize the PCA9553 4-bit I2C-bus LED chip
396 struct peak_pci_chan *chan = priv->priv; in peak_pciec_write_reg()
397 struct peak_pciec_card *card = chan->pciec_card; in peak_pciec_write_reg()
398 int c = (priv->reg_base - card->reg_base) / PEAK_PCI_CHAN_SIZE; in peak_pciec_write_reg()
432 struct peak_pci_chan *chan = priv->priv; in peak_pciec_probe()
437 if (chan->prev_dev) { in peak_pciec_probe()
438 struct sja1000_priv *prev_priv = netdev_priv(chan->prev_dev); in peak_pciec_probe()
439 struct peak_pci_chan *prev_chan = prev_priv->priv; in peak_pciec_probe()
441 card = prev_chan->pciec_card; in peak_pciec_probe()
443 return -ENODEV; in peak_pciec_probe()
447 /* create the bit banging I2C adapter structure */ in peak_pciec_probe()
450 return -ENOMEM; in peak_pciec_probe()
452 card->cfg_base = chan->cfg_base; in peak_pciec_probe()
453 card->reg_base = priv->reg_base; in peak_pciec_probe()
455 card->led_chip.owner = THIS_MODULE; in peak_pciec_probe()
456 card->led_chip.dev.parent = &pdev->dev; in peak_pciec_probe()
457 card->led_chip.algo_data = &card->i2c_bit; in peak_pciec_probe()
458 strncpy(card->led_chip.name, "peak_i2c", in peak_pciec_probe()
459 sizeof(card->led_chip.name)); in peak_pciec_probe()
461 card->i2c_bit = peak_pciec_i2c_bit_ops; in peak_pciec_probe()
462 card->i2c_bit.udelay = 10; in peak_pciec_probe()
463 card->i2c_bit.timeout = HZ; in peak_pciec_probe()
464 card->i2c_bit.data = card; in peak_pciec_probe()
468 err = i2c_bit_add_bus(&card->led_chip); in peak_pciec_probe()
470 dev_err(&pdev->dev, "i2c init failed\n"); in peak_pciec_probe()
476 dev_err(&pdev->dev, "leds hardware init failed\n"); in peak_pciec_probe()
480 INIT_DELAYED_WORK(&card->led_work, peak_pciec_led_work); in peak_pciec_probe()
481 /* PCAN-ExpressCard needs its own callback for leds */ in peak_pciec_probe()
482 priv->write_reg = peak_pciec_write_reg; in peak_pciec_probe()
485 chan->pciec_card = card; in peak_pciec_probe()
486 card->channel[card->chan_count++].netdev = dev; in peak_pciec_probe()
491 i2c_del_adapter(&card->led_chip); in peak_pciec_probe()
504 i2c_del_adapter(&card->led_chip); in peak_pciec_remove()
512 * Placebo functions when PCAN-ExpressCard support is not selected
516 return -ENODEV; in peak_pciec_probe()
526 return readb(priv->reg_base + (port << 2)); in peak_pci_read_reg()
532 writeb(val, priv->reg_base + (port << 2)); in peak_pci_write_reg()
537 struct peak_pci_chan *chan = priv->priv; in peak_pci_post_irq()
541 icr = readw(chan->cfg_base + PITA_ICR); in peak_pci_post_irq()
542 if (icr & chan->icr_mask) in peak_pci_post_irq()
543 writew(chan->icr_mask, chan->cfg_base + PITA_ICR); in peak_pci_post_irq()
567 dev_dbg(&pdev->dev, "probing device %04x:%04x:%04x\n", in peak_pci_probe()
568 pdev->vendor, pdev->device, sub_sys_id); in peak_pci_probe()
585 dev_err(&pdev->dev, "failed to map PCI resource #0\n"); in peak_pci_probe()
586 err = -ENOMEM; in peak_pci_probe()
592 dev_err(&pdev->dev, "failed to map PCI resource #1\n"); in peak_pci_probe()
593 err = -ENOMEM; in peak_pci_probe()
612 err = -ENOMEM; in peak_pci_probe()
617 chan = priv->priv; in peak_pci_probe()
619 chan->cfg_base = cfg_base; in peak_pci_probe()
620 priv->reg_base = reg_base + i * PEAK_PCI_CHAN_SIZE; in peak_pci_probe()
622 priv->read_reg = peak_pci_read_reg; in peak_pci_probe()
623 priv->write_reg = peak_pci_write_reg; in peak_pci_probe()
624 priv->post_irq = peak_pci_post_irq; in peak_pci_probe()
626 priv->can.clock.freq = PEAK_PCI_CAN_CLOCK; in peak_pci_probe()
627 priv->ocr = PEAK_PCI_OCR; in peak_pci_probe()
628 priv->cdr = PEAK_PCI_CDR; in peak_pci_probe()
631 priv->cdr |= CDR_CLK_OFF; in peak_pci_probe()
634 priv->irq_flags = IRQF_SHARED; in peak_pci_probe()
635 dev->irq = pdev->irq; in peak_pci_probe()
637 chan->icr_mask = peak_pci_icr_masks[i]; in peak_pci_probe()
638 icr |= chan->icr_mask; in peak_pci_probe()
640 SET_NETDEV_DEV(dev, &pdev->dev); in peak_pci_probe()
641 dev->dev_id = i; in peak_pci_probe()
644 chan->prev_dev = pci_get_drvdata(pdev); in peak_pci_probe()
648 * PCAN-ExpressCard needs some additional i2c init. in peak_pci_probe()
652 if (pdev->device == PEAK_PCIEC_DEVICE_ID || in peak_pci_probe()
653 pdev->device == PEAK_PCIEC34_DEVICE_ID) { in peak_pci_probe()
656 dev_err(&pdev->dev, in peak_pci_probe()
665 dev_err(&pdev->dev, "failed to register device\n"); in peak_pci_probe()
669 dev_info(&pdev->dev, in peak_pci_probe()
671 dev->name, priv->reg_base, chan->cfg_base, dev->irq); in peak_pci_probe()
680 pci_set_drvdata(pdev, chan->prev_dev); in peak_pci_probe()
690 chan = priv->priv; in peak_pci_probe()
691 prev_dev = chan->prev_dev; in peak_pci_probe()
698 if (chan && chan->pciec_card) in peak_pci_probe()
699 peak_pciec_remove(chan->pciec_card); in peak_pci_probe()
722 struct peak_pci_chan *chan = priv->priv; in peak_pci_remove()
723 void __iomem *cfg_base = chan->cfg_base; in peak_pci_remove()
724 void __iomem *reg_base = priv->reg_base; in peak_pci_remove()
731 struct net_device *prev_dev = chan->prev_dev; in peak_pci_remove()
733 dev_info(&pdev->dev, "removing device %s\n", dev->name); in peak_pci_remove()
740 if (chan->pciec_card) in peak_pci_remove()
741 peak_pciec_remove(chan->pciec_card); in peak_pci_remove()
745 chan = priv->priv; in peak_pci_remove()