Lines Matching +full:regulator +full:- +full:soft +full:- +full:start

1 // SPDX-License-Identifier: GPL-2.0-only
22 #include <linux/regulator/consumer.h>
31 * ks8851_lock - register access lock
39 ks->lock(ks, flags); in ks8851_lock()
43 * ks8851_unlock - register access unlock
51 ks->unlock(ks, flags); in ks8851_unlock()
55 * ks8851_wrreg16 - write 16bit register value to chip
65 ks->wrreg16(ks, reg, val); in ks8851_wrreg16()
69 * ks8851_rdreg16 - read 16 bit register from device
78 return ks->rdreg16(ks, reg); in ks8851_rdreg16()
82 * ks8851_soft_reset - issue one of the soft reset to the device
86 * Issue the relevant soft-reset command to the device's GRR register
103 * ks8851_set_powermode - set power mode of the device
113 netif_dbg(ks, hw, ks->netdev, "setting power mode %d\n", pwrmode); in ks8851_set_powermode()
123 * ks8851_write_mac_addr - write mac address to device registers
147 val = (dev->dev_addr[i] << 8) | dev->dev_addr[i + 1]; in ks8851_write_mac_addr()
160 * ks8851_read_mac_addr - read mac address from device registers
176 dev->dev_addr[i] = reg >> 8; in ks8851_read_mac_addr()
177 dev->dev_addr[i + 1] = reg & 0xff; in ks8851_read_mac_addr()
184 * ks8851_init_mac - initialise the mac address
196 struct net_device *dev = ks->netdev; in ks8851_init_mac()
201 ether_addr_copy(dev->dev_addr, mac_addr); in ks8851_init_mac()
206 if (ks->rc_ccr & CCR_EEPROM) { in ks8851_init_mac()
208 if (is_valid_ether_addr(dev->dev_addr)) in ks8851_init_mac()
211 netdev_err(ks->netdev, "invalid mac address read %pM\n", in ks8851_init_mac()
212 dev->dev_addr); in ks8851_init_mac()
220 * ks8851_dbg_dumpkkt - dump initial packet contents to debug
228 netdev_dbg(ks->netdev, in ks8851_dbg_dumpkkt()
236 * ks8851_rx_skb - receive skbuff
242 ks->rx_skb(ks, skb); in ks8851_rx_skb()
246 * ks8851_rx_pkts - receive packets from the host
263 netif_dbg(ks, rx_status, ks->netdev, in ks8851_rx_pkts()
276 for (; rxfc != 0; rxfc--) { in ks8851_rx_pkts()
280 netif_dbg(ks, rx_status, ks->netdev, in ks8851_rx_pkts()
288 /* start DMA access */ in ks8851_rx_pkts()
289 ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr | RXQCR_SDA); in ks8851_rx_pkts()
294 rxlen -= 4; in ks8851_rx_pkts()
296 skb = netdev_alloc_skb_ip_align(ks->netdev, rxalign); in ks8851_rx_pkts()
305 rxpkt = skb_put(skb, rxlen) - 8; in ks8851_rx_pkts()
307 ks->rdfifo(ks, rxpkt, rxalign + 8); in ks8851_rx_pkts()
312 skb->protocol = eth_type_trans(skb, ks->netdev); in ks8851_rx_pkts()
315 ks->netdev->stats.rx_packets++; in ks8851_rx_pkts()
316 ks->netdev->stats.rx_bytes += rxlen; in ks8851_rx_pkts()
321 ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr | RXQCR_RRXEF); in ks8851_rx_pkts()
326 * ks8851_irq - IRQ handler for dealing with interrupt requests
348 netif_dbg(ks, intr, ks->netdev, in ks8851_irq()
372 ks->tx_space = ks8851_rdreg16(ks, KS_TXMIR); in ks8851_irq()
374 netif_dbg(ks, intr, ks->netdev, in ks8851_irq()
375 "%s: txspace %d\n", __func__, ks->tx_space); in ks8851_irq()
382 netdev_err(ks->netdev, "%s: spi bus error\n", __func__); in ks8851_irq()
390 * packet read-out, however we're masking the interrupt in ks8851_irq()
401 struct ks8851_rxctrl *rxc = &ks->rxctrl; in ks8851_irq()
404 ks8851_wrreg16(ks, KS_MAHTR0, rxc->mchash[0]); in ks8851_irq()
405 ks8851_wrreg16(ks, KS_MAHTR1, rxc->mchash[1]); in ks8851_irq()
406 ks8851_wrreg16(ks, KS_MAHTR2, rxc->mchash[2]); in ks8851_irq()
407 ks8851_wrreg16(ks, KS_MAHTR3, rxc->mchash[3]); in ks8851_irq()
409 ks8851_wrreg16(ks, KS_RXCR2, rxc->rxcr2); in ks8851_irq()
410 ks8851_wrreg16(ks, KS_RXCR1, rxc->rxcr1); in ks8851_irq()
416 mii_check_link(&ks->mii); in ks8851_irq()
419 netif_wake_queue(ks->netdev); in ks8851_irq()
425 * ks8851_flush_tx_work - flush outstanding TX work
430 if (ks->flush_tx_work) in ks8851_flush_tx_work()
431 ks->flush_tx_work(ks); in ks8851_flush_tx_work()
435 * ks8851_net_open - open network device
447 ret = request_threaded_irq(dev->irq, NULL, ks8851_irq, in ks8851_net_open()
449 dev->name, ks); in ks8851_net_open()
459 netif_dbg(ks, ifup, ks->netdev, "opening\n"); in ks8851_net_open()
464 /* issue a soft reset to the RX/TX QMU to put it into a known in ks8851_net_open()
475 /* auto-increment tx data, reset tx pointer */ in ks8851_net_open()
494 ks->rc_rxqcr = (RXQCR_RXFCTE | /* IRQ on frame count exceeded */ in ks8851_net_open()
498 ks8851_wrreg16(ks, KS_RXQCR, ks->rc_rxqcr); in ks8851_net_open()
501 ks8851_wrreg16(ks, KS_ISR, ks->rc_ier); in ks8851_net_open()
502 ks8851_wrreg16(ks, KS_IER, ks->rc_ier); in ks8851_net_open()
504 netif_start_queue(ks->netdev); in ks8851_net_open()
506 netif_dbg(ks, ifup, ks->netdev, "network device up\n"); in ks8851_net_open()
509 mii_check_link(&ks->mii); in ks8851_net_open()
514 * ks8851_net_stop - close network device
538 flush_work(&ks->rxctrl_work); in ks8851_net_stop()
547 /* set powermode to soft power down to save power */ in ks8851_net_stop()
552 while (!skb_queue_empty(&ks->txq)) { in ks8851_net_stop()
553 struct sk_buff *txb = skb_dequeue(&ks->txq); in ks8851_net_stop()
555 netif_dbg(ks, ifdown, ks->netdev, in ks8851_net_stop()
561 free_irq(dev->irq, ks); in ks8851_net_stop()
567 * ks8851_start_xmit - transmit packet
584 return ks->start_xmit(skb, dev); in ks8851_start_xmit()
588 * ks8851_rxctrl_work - work handler to change rx mode
620 if (dev->flags & IFF_PROMISC) { in ks8851_set_rx_mode()
624 } else if (dev->flags & IFF_ALLMULTI) { in ks8851_set_rx_mode()
629 } else if (dev->flags & IFF_MULTICAST && !netdev_mc_empty(dev)) { in ks8851_set_rx_mode()
636 crc = ether_crc(ETH_ALEN, ha->addr); in ks8851_set_rx_mode()
637 crc >>= (32 - 6); /* get top six bits */ in ks8851_set_rx_mode()
657 spin_lock(&ks->statelock); in ks8851_set_rx_mode()
659 if (memcmp(&rxctrl, &ks->rxctrl, sizeof(rxctrl)) != 0) { in ks8851_set_rx_mode()
660 memcpy(&ks->rxctrl, &rxctrl, sizeof(ks->rxctrl)); in ks8851_set_rx_mode()
661 schedule_work(&ks->rxctrl_work); in ks8851_set_rx_mode()
664 spin_unlock(&ks->statelock); in ks8851_set_rx_mode()
672 return -EBUSY; in ks8851_set_mac_address()
674 if (!is_valid_ether_addr(sa->sa_data)) in ks8851_set_mac_address()
675 return -EADDRNOTAVAIL; in ks8851_set_mac_address()
677 memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN); in ks8851_set_mac_address()
686 return -EINVAL; in ks8851_net_ioctl()
688 return generic_mii_ioctl(&ks->mii, if_mii(req), cmd, NULL); in ks8851_net_ioctl()
706 strlcpy(di->driver, "KS8851", sizeof(di->driver)); in ks8851_get_drvinfo()
707 strlcpy(di->version, "1.00", sizeof(di->version)); in ks8851_get_drvinfo()
708 strlcpy(di->bus_info, dev_name(dev->dev.parent), sizeof(di->bus_info)); in ks8851_get_drvinfo()
714 return ks->msg_enable; in ks8851_get_msglevel()
720 ks->msg_enable = to; in ks8851_set_msglevel()
728 mii_ethtool_get_link_ksettings(&ks->mii, cmd); in ks8851_get_link_ksettings()
737 return mii_ethtool_set_link_ksettings(&ks->mii, cmd); in ks8851_set_link_ksettings()
743 return mii_link_ok(&ks->mii); in ks8851_get_link()
749 return mii_nway_restart(&ks->mii); in ks8851_nway_reset()
756 struct ks8851_net *ks = ee->data; in ks8851_eeprom_regread()
761 ee->reg_data_out = (val & EEPCR_EESB) ? 1 : 0; in ks8851_eeprom_regread()
762 ee->reg_data_clock = (val & EEPCR_EESCK) ? 1 : 0; in ks8851_eeprom_regread()
763 ee->reg_chip_select = (val & EEPCR_EECS) ? 1 : 0; in ks8851_eeprom_regread()
768 struct ks8851_net *ks = ee->data; in ks8851_eeprom_regwrite()
769 unsigned val = EEPCR_EESA; /* default - eeprom access on */ in ks8851_eeprom_regwrite()
771 if (ee->drive_data) in ks8851_eeprom_regwrite()
773 if (ee->reg_data_in) in ks8851_eeprom_regwrite()
775 if (ee->reg_data_clock) in ks8851_eeprom_regwrite()
777 if (ee->reg_chip_select) in ks8851_eeprom_regwrite()
784 * ks8851_eeprom_claim - claim device EEPROM and activate the interface
792 /* start with clock low, cs high */ in ks8851_eeprom_claim()
798 * ks8851_eeprom_release - release the EEPROM interface
816 int offset = ee->offset; in ks8851_set_eeprom()
818 int len = ee->len; in ks8851_set_eeprom()
823 return -EINVAL; in ks8851_set_eeprom()
825 if (ee->magic != KS_EEPROM_MAGIC) in ks8851_set_eeprom()
826 return -EINVAL; in ks8851_set_eeprom()
828 if (!(ks->rc_ccr & CCR_EEPROM)) in ks8851_set_eeprom()
829 return -ENOENT; in ks8851_set_eeprom()
835 eeprom_93cx6_wren(&ks->eeprom, true); in ks8851_set_eeprom()
840 eeprom_93cx6_read(&ks->eeprom, offset/2, &tmp); in ks8851_set_eeprom()
850 eeprom_93cx6_write(&ks->eeprom, offset/2, tmp); in ks8851_set_eeprom()
851 eeprom_93cx6_wren(&ks->eeprom, false); in ks8851_set_eeprom()
863 int offset = ee->offset; in ks8851_get_eeprom()
865 int len = ee->len; in ks8851_get_eeprom()
869 return -EINVAL; in ks8851_get_eeprom()
871 if (!(ks->rc_ccr & CCR_EEPROM)) in ks8851_get_eeprom()
872 return -ENOENT; in ks8851_get_eeprom()
878 ee->magic = KS_EEPROM_MAGIC; in ks8851_get_eeprom()
880 eeprom_93cx6_multiread(&ks->eeprom, offset/2, (__le16 *)data, len/2); in ks8851_get_eeprom()
892 return ks->rc_ccr & CCR_EEPROM ? 128 : 0; in ks8851_get_eeprom_len()
911 * ks8851_phy_reg - convert MII register into a KS8851 register
939 * ks8851_phy_read - MII interface PHY register read.
945 * device does not support all the MII registers, the non-existent values
950 * caller. The mii-tool that the driver was tested with takes any -ve error
987 * ks8851_read_selftest - read the selftest memory info.
1001 netdev_warn(ks->netdev, "Memory selftest not finished\n"); in ks8851_read_selftest()
1006 netdev_err(ks->netdev, "TX memory selftest fail\n"); in ks8851_read_selftest()
1011 netdev_err(ks->netdev, "RX memory selftest fail\n"); in ks8851_read_selftest()
1025 struct net_device *netdev = ks->netdev; in ks8851_suspend()
1038 struct net_device *netdev = ks->netdev; in ks8851_resume()
1057 ks->netdev = netdev; in ks8851_probe_common()
1058 ks->tx_space = 6144; in ks8851_probe_common()
1060 gpio = of_get_named_gpio_flags(dev->of_node, "reset-gpios", 0, NULL); in ks8851_probe_common()
1061 if (gpio == -EPROBE_DEFER) in ks8851_probe_common()
1064 ks->gpio = gpio; in ks8851_probe_common()
1074 ks->vdd_io = devm_regulator_get(dev, "vdd-io"); in ks8851_probe_common()
1075 if (IS_ERR(ks->vdd_io)) { in ks8851_probe_common()
1076 ret = PTR_ERR(ks->vdd_io); in ks8851_probe_common()
1080 ret = regulator_enable(ks->vdd_io); in ks8851_probe_common()
1082 dev_err(dev, "regulator vdd_io enable fail: %d\n", ret); in ks8851_probe_common()
1086 ks->vdd_reg = devm_regulator_get(dev, "vdd"); in ks8851_probe_common()
1087 if (IS_ERR(ks->vdd_reg)) { in ks8851_probe_common()
1088 ret = PTR_ERR(ks->vdd_reg); in ks8851_probe_common()
1092 ret = regulator_enable(ks->vdd_reg); in ks8851_probe_common()
1094 dev_err(dev, "regulator vdd enable fail: %d\n", ret); in ks8851_probe_common()
1103 spin_lock_init(&ks->statelock); in ks8851_probe_common()
1105 INIT_WORK(&ks->rxctrl_work, ks8851_rxctrl_work); in ks8851_probe_common()
1108 ks->eeprom.data = ks; in ks8851_probe_common()
1109 ks->eeprom.width = PCI_EEPROM_WIDTH_93C46; in ks8851_probe_common()
1110 ks->eeprom.register_read = ks8851_eeprom_regread; in ks8851_probe_common()
1111 ks->eeprom.register_write = ks8851_eeprom_regwrite; in ks8851_probe_common()
1114 ks->mii.dev = netdev; in ks8851_probe_common()
1115 ks->mii.phy_id = 1, in ks8851_probe_common()
1116 ks->mii.phy_id_mask = 1; in ks8851_probe_common()
1117 ks->mii.reg_num_mask = 0xf; in ks8851_probe_common()
1118 ks->mii.mdio_read = ks8851_phy_read; in ks8851_probe_common()
1119 ks->mii.mdio_write = ks8851_phy_write; in ks8851_probe_common()
1124 ks->msg_enable = netif_msg_init(msg_en, NETIF_MSG_DRV | in ks8851_probe_common()
1128 skb_queue_head_init(&ks->txq); in ks8851_probe_common()
1130 netdev->ethtool_ops = &ks8851_ethtool_ops; in ks8851_probe_common()
1135 netif_carrier_off(ks->netdev); in ks8851_probe_common()
1136 netdev->if_port = IF_PORT_100BASET; in ks8851_probe_common()
1137 netdev->netdev_ops = &ks8851_netdev_ops; in ks8851_probe_common()
1139 /* issue a global soft reset to reset the device. */ in ks8851_probe_common()
1146 ret = -ENODEV; in ks8851_probe_common()
1151 ks->rc_ccr = ks8851_rdreg16(ks, KS_CCR); in ks8851_probe_common()
1154 ks8851_init_mac(ks, dev->of_node); in ks8851_probe_common()
1163 CIDER_REV_GET(cider), netdev->dev_addr, netdev->irq, in ks8851_probe_common()
1164 ks->rc_ccr & CCR_EEPROM ? "has" : "no"); in ks8851_probe_common()
1172 regulator_disable(ks->vdd_reg); in ks8851_probe_common()
1174 regulator_disable(ks->vdd_io); in ks8851_probe_common()
1186 unregister_netdev(priv->netdev); in ks8851_remove_common()
1187 if (gpio_is_valid(priv->gpio)) in ks8851_remove_common()
1188 gpio_set_value(priv->gpio, 0); in ks8851_remove_common()
1189 regulator_disable(priv->vdd_reg); in ks8851_remove_common()
1190 regulator_disable(priv->vdd_io); in ks8851_remove_common()