Lines Matching +full:cpsw +full:- +full:mdio

4  * (C) Copyright 2012-2014
7 * SPDX-License-Identifier: GPL-2.0+
21 #include <asm/ti-common/keystone_nav.h>
22 #include <asm/ti-common/keystone_net.h>
23 #include <asm/ti-common/keystone_serdes.h>
80 /* CPSW Switch slave registers */
91 /* CPSW Switch slave registers */
119 /* MDIO */
124 struct mdio_regs *adap_mdio = bus->priv; in keystone2_mdio_reset()
126 clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1; in keystone2_mdio_reset()
130 &adap_mdio->control); in keystone2_mdio_reset()
132 while (readl(&adap_mdio->control) & MDIO_CONTROL_IDLE) in keystone2_mdio_reset()
139 * keystone2_mdio_read - read a PHY register via MDIO interface.
146 struct mdio_regs *adap_mdio = bus->priv; in keystone2_mdio_read()
148 while (readl(&adap_mdio->useraccess0) & MDIO_USERACCESS0_GO) in keystone2_mdio_read()
153 &adap_mdio->useraccess0); in keystone2_mdio_read()
156 while ((tmp = readl(&adap_mdio->useraccess0)) & MDIO_USERACCESS0_GO) in keystone2_mdio_read()
162 return -1; in keystone2_mdio_read()
166 * keystone2_mdio_write - write to a PHY register via MDIO interface.
172 struct mdio_regs *adap_mdio = bus->priv; in keystone2_mdio_write()
174 while (readl(&adap_mdio->useraccess0) & MDIO_USERACCESS0_GO) in keystone2_mdio_write()
179 (val & 0xffff), &adap_mdio->useraccess0); in keystone2_mdio_write()
182 while (readl(&adap_mdio->useraccess0) & MDIO_USERACCESS0_GO) in keystone2_mdio_write()
193 struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv; in keystone2_eth_gigabit_enable()
196 data = keystone2_mdio_read(mdio_bus, eth_priv->phy_addr, in keystone2_eth_gigabit_enable()
204 * Check if link detected is giga-bit in keystone2_eth_gigabit_enable()
207 writel(readl(DEVICE_EMACSL_BASE(eth_priv->slave_port - 1) + in keystone2_eth_gigabit_enable()
210 DEVICE_EMACSL_BASE(eth_priv->slave_port - 1) + CPGMACSL_REG_CTL); in keystone2_eth_gigabit_enable()
219 if (priv->has_mdio) { in keystone2_eth_gigabit_enable()
220 data = keystone2_mdio_read(priv->mdio_bus, priv->phy_addr, in keystone2_eth_gigabit_enable()
228 * Check if link detected is giga-bit in keystone2_eth_gigabit_enable()
231 writel(readl(DEVICE_EMACSL_BASE(priv->slave_port - 1) + in keystone2_eth_gigabit_enable()
234 DEVICE_EMACSL_BASE(priv->slave_port - 1) + CPGMACSL_REG_CTL); in keystone2_eth_gigabit_enable()
247 phy_dev->link = 0; in keystone_rgmii_config()
253 phy_dev->link = 0; in keystone_rgmii_config()
254 return -EINTR; in keystone_rgmii_config()
335 phy_dev->dev->name); in keystone_sgmii_config()
342 phy_dev->link = 0; in keystone_sgmii_config()
348 phy_dev->link = 0; in keystone_sgmii_config()
349 return -EINTR; in keystone_sgmii_config()
395 if (cfg->max_rx_len > CPGMAC_REG_MAXLEN_LEN) { in mac_sl_config()
396 cfg->max_rx_len = CPGMAC_REG_MAXLEN_LEN; in mac_sl_config()
411 writel(cfg->max_rx_len, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_MAXLEN); in mac_sl_config()
412 writel(cfg->ctl, DEVICE_EMACSL_BASE(port) + CPGMACSL_REG_CTL); in mac_sl_config()
509 eth_priv = (struct eth_priv_t *)dev->priv; in keystone2_eth_read_mac_addr()
511 /* Read the e-fuse mac address */ in keystone2_eth_read_mac_addr()
512 if (eth_priv->slave_port == 1) { in keystone2_eth_read_mac_addr()
517 dev->enetaddr[0] = (macb >> 8) & 0xff; in keystone2_eth_read_mac_addr()
518 dev->enetaddr[1] = (macb >> 0) & 0xff; in keystone2_eth_read_mac_addr()
519 dev->enetaddr[2] = (maca >> 24) & 0xff; in keystone2_eth_read_mac_addr()
520 dev->enetaddr[3] = (maca >> 16) & 0xff; in keystone2_eth_read_mac_addr()
521 dev->enetaddr[4] = (maca >> 8) & 0xff; in keystone2_eth_read_mac_addr()
522 dev->enetaddr[5] = (maca >> 0) & 0xff; in keystone2_eth_read_mac_addr()
539 struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv; in keystone2_eth_open()
540 struct phy_device *phy_dev = eth_priv->phy_dev; in keystone2_eth_open()
544 net_rx_buffs.rx_flow = eth_priv->rx_flow; in keystone2_eth_open()
547 (eth_priv->sgmii_link_type == SGMII_LINK_MAC_PHY) ? 1 : 0; in keystone2_eth_open()
555 keystone_sgmii_config(phy_dev, eth_priv->slave_port - 1, in keystone2_eth_open()
556 eth_priv->sgmii_link_type); in keystone2_eth_open()
567 return -1; in keystone2_eth_open()
572 return -1; in keystone2_eth_open()
586 if (phy_dev->link == 0) { in keystone2_eth_open()
589 return -1; in keystone2_eth_open()
597 debug("- emac_open\n"); in keystone2_eth_open()
607 struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv; in keystone2_eth_close()
608 struct phy_device *phy_dev = eth_priv->phy_dev; in keystone2_eth_close()
623 debug("- emac_close\n"); in keystone2_eth_close()
633 int ret_status = -1; in keystone2_eth_send_packet()
634 struct eth_priv_t *eth_priv = (struct eth_priv_t *)dev->priv; in keystone2_eth_send_packet()
635 struct phy_device *phy_dev = eth_priv->phy_dev; in keystone2_eth_send_packet()
638 if (phy_dev->link == 0) in keystone2_eth_send_packet()
639 return -1; in keystone2_eth_send_packet()
641 if (cpmac_drv_send((u32 *)packet, length, eth_priv->slave_port) != 0) in keystone2_eth_send_packet()
686 return -1; in keystone2_emac_initialize()
690 strcpy(dev->name, eth_priv->int_name); in keystone2_emac_initialize()
691 dev->priv = eth_priv; in keystone2_emac_initialize()
695 dev->iobase = 0; in keystone2_emac_initialize()
696 dev->init = keystone2_eth_open; in keystone2_emac_initialize()
697 dev->halt = keystone2_eth_close; in keystone2_emac_initialize()
698 dev->send = keystone2_eth_send_packet; in keystone2_emac_initialize()
699 dev->recv = keystone2_eth_rcv_packet; in keystone2_emac_initialize()
701 dev->mcast = keystone2_eth_bcast_addr; in keystone2_emac_initialize()
706 /* Register MDIO bus if it's not registered yet */ in keystone2_emac_initialize()
709 mdio_bus->read = keystone2_mdio_read; in keystone2_emac_initialize()
710 mdio_bus->write = keystone2_mdio_write; in keystone2_emac_initialize()
711 mdio_bus->reset = keystone2_mdio_reset; in keystone2_emac_initialize()
712 mdio_bus->priv = (void *)EMAC_MDIO_BASE_ADDR; in keystone2_emac_initialize()
713 strcpy(mdio_bus->name, "ethernet-mdio"); in keystone2_emac_initialize()
726 phy_dev = phy_connect(mdio_bus, eth_priv->phy_addr, in keystone2_emac_initialize()
727 dev, eth_priv->phy_if); in keystone2_emac_initialize()
730 phy_dev = phy_find_by_mask(mdio_bus, 1 << eth_priv->phy_addr, in keystone2_emac_initialize()
731 eth_priv->phy_if); in keystone2_emac_initialize()
732 phy_dev->dev = dev; in keystone2_emac_initialize()
734 eth_priv->phy_dev = phy_dev; in keystone2_emac_initialize()
746 keystone_rgmii_config(priv->phydev); in ks2_eth_start()
748 keystone_sgmii_config(priv->phydev, priv->slave_port - 1, in ks2_eth_start()
749 priv->sgmii_link_type); in ks2_eth_start()
759 if (ksnav_init(priv->netcp_pktdma, &priv->net_rx_buffs)) { in ks2_eth_start()
771 if (priv->has_mdio) { in ks2_eth_start()
772 keystone2_mdio_reset(priv->mdio_bus); in ks2_eth_start()
774 phy_startup(priv->phydev); in ks2_eth_start()
775 if (priv->phydev->link == 0) { in ks2_eth_start()
785 priv->emac_open = true; in ks2_eth_start()
790 ksnav_close(priv->netcp_pktdma); in ks2_eth_start()
794 return -EFAULT; in ks2_eth_start()
801 genphy_update_link(priv->phydev); in ks2_eth_send()
802 if (priv->phydev->link == 0) in ks2_eth_send()
803 return -1; in ks2_eth_send()
808 return ksnav_send(priv->netcp_pktdma, (u32 *)packet, in ks2_eth_send()
809 length, (priv->slave_port) << 16); in ks2_eth_send()
818 priv->hd = ksnav_recv(priv->netcp_pktdma, &pkt, &pkt_size); in ks2_eth_recv()
819 if (priv->hd == NULL) in ks2_eth_recv()
820 return -EAGAIN; in ks2_eth_recv()
832 ksnav_release_rxhd(priv->netcp_pktdma, priv->hd); in ks2_eth_free_pkt()
841 if (!priv->emac_open) in ks2_eth_stop()
845 ksnav_close(priv->netcp_pktdma); in ks2_eth_stop()
847 phy_shutdown(priv->phydev); in ks2_eth_stop()
848 priv->emac_open = false; in ks2_eth_stop()
858 /* Read the e-fuse mac address */ in ks2_eth_read_rom_hwaddr()
859 if (priv->slave_port == 1) { in ks2_eth_read_rom_hwaddr()
864 pdata->enetaddr[0] = (macb >> 8) & 0xff; in ks2_eth_read_rom_hwaddr()
865 pdata->enetaddr[1] = (macb >> 0) & 0xff; in ks2_eth_read_rom_hwaddr()
866 pdata->enetaddr[2] = (maca >> 24) & 0xff; in ks2_eth_read_rom_hwaddr()
867 pdata->enetaddr[3] = (maca >> 16) & 0xff; in ks2_eth_read_rom_hwaddr()
868 pdata->enetaddr[4] = (maca >> 8) & 0xff; in ks2_eth_read_rom_hwaddr()
869 pdata->enetaddr[5] = (maca >> 0) & 0xff; in ks2_eth_read_rom_hwaddr()
879 writel(mac_hi(pdata->enetaddr), in ks2_eth_write_hwaddr()
880 DEVICE_EMACSW_BASE(pdata->iobase, priv->slave_port - 1) + in ks2_eth_write_hwaddr()
882 writel(mac_lo(pdata->enetaddr), in ks2_eth_write_hwaddr()
883 DEVICE_EMACSW_BASE(pdata->iobase, priv->slave_port - 1) + in ks2_eth_write_hwaddr()
895 priv->dev = dev; in ks2_eth_probe()
904 return -EACCES; in ks2_eth_probe()
907 return -EACCES; in ks2_eth_probe()
909 return -EACCES; in ks2_eth_probe()
915 priv->net_rx_buffs.buff_ptr = rx_buffs; in ks2_eth_probe()
916 priv->net_rx_buffs.num_buffs = RX_BUFF_NUMS; in ks2_eth_probe()
917 priv->net_rx_buffs.buff_len = RX_BUFF_LEN; in ks2_eth_probe()
919 if (priv->slave_port == 1) { in ks2_eth_probe()
921 * Register MDIO bus for slave 0 only, other slave have in ks2_eth_probe()
922 * to re-use the same in ks2_eth_probe()
926 pr_err("MDIO alloc failed\n"); in ks2_eth_probe()
927 return -ENOMEM; in ks2_eth_probe()
929 priv->mdio_bus = mdio_bus; in ks2_eth_probe()
930 mdio_bus->read = keystone2_mdio_read; in ks2_eth_probe()
931 mdio_bus->write = keystone2_mdio_write; in ks2_eth_probe()
932 mdio_bus->reset = keystone2_mdio_reset; in ks2_eth_probe()
933 mdio_bus->priv = priv->mdio_base; in ks2_eth_probe()
934 sprintf(mdio_bus->name, "ethernet-mdio"); in ks2_eth_probe()
938 pr_err("MDIO bus register failed\n"); in ks2_eth_probe()
942 /* Get the MDIO bus from slave 0 device */ in ks2_eth_probe()
945 parent_priv = dev_get_priv(dev->parent); in ks2_eth_probe()
946 priv->mdio_bus = parent_priv->mdio_bus; in ks2_eth_probe()
953 priv->netcp_pktdma = &netcp_pktdma; in ks2_eth_probe()
955 if (priv->has_mdio) { in ks2_eth_probe()
956 priv->phydev = phy_connect(priv->mdio_bus, priv->phy_addr, in ks2_eth_probe()
957 dev, priv->phy_if); in ks2_eth_probe()
958 phy_config(priv->phydev); in ks2_eth_probe()
968 free(priv->phydev); in ks2_eth_remove()
969 mdio_unregister(priv->mdio_bus); in ks2_eth_remove()
970 mdio_free(priv->mdio_bus); in ks2_eth_remove()
987 const void *fdt = gd->fdt_blob; in ks2_eth_bind_slaves()
999 slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); in ks2_eth_bind_slaves()
1000 if (slave_no == -ENOENT) in ks2_eth_bind_slaves()
1009 snprintf(slave_name, 20, "netcp@slave-%d", slave_no); in ks2_eth_bind_slaves()
1014 pr_err("ks2_net - not able to bind slave interfaces\n"); in ks2_eth_bind_slaves()
1020 sec_slave = fdt_subnode_offset(fdt, gbe, "secondary-slave-ports"); in ks2_eth_bind_slaves()
1024 slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); in ks2_eth_bind_slaves()
1025 if (slave_no == -ENOENT) in ks2_eth_bind_slaves()
1030 snprintf(slave_name, 20, "netcp@slave-%d", slave_no); in ks2_eth_bind_slaves()
1034 pr_err("ks2_net - not able to bind slave interfaces\n"); in ks2_eth_bind_slaves()
1046 const void *fdt = gd->fdt_blob; in ks2_eth_parse_slave_interface()
1047 int mdio; in ks2_eth_parse_slave_interface() local
1052 priv->slave_port = fdtdec_get_int(fdt, slave, "slave-port", -1); in ks2_eth_parse_slave_interface()
1053 priv->net_rx_buffs.rx_flow = priv->slave_port * 8; in ks2_eth_parse_slave_interface()
1055 /* U-Boot slave port number starts with 1 instead of 0 */ in ks2_eth_parse_slave_interface()
1056 priv->slave_port += 1; in ks2_eth_parse_slave_interface()
1059 "ti,navigator-dmas", in ks2_eth_parse_slave_interface()
1062 if (dma_count > (2 * priv->slave_port)) { in ks2_eth_parse_slave_interface()
1065 dma_idx = priv->slave_port * 2 - 1; in ks2_eth_parse_slave_interface()
1066 priv->net_rx_buffs.rx_flow = dma_channel[dma_idx]; in ks2_eth_parse_slave_interface()
1069 priv->link_type = fdtdec_get_int(fdt, slave, "link-interface", -1); in ks2_eth_parse_slave_interface()
1071 phy = fdtdec_lookup_phandle(fdt, slave, "phy-handle"); in ks2_eth_parse_slave_interface()
1073 priv->phy_addr = fdtdec_get_int(fdt, phy, "reg", -1); in ks2_eth_parse_slave_interface()
1075 mdio = fdt_parent_offset(fdt, phy); in ks2_eth_parse_slave_interface()
1076 if (mdio < 0) { in ks2_eth_parse_slave_interface()
1077 pr_err("mdio dt not found\n"); in ks2_eth_parse_slave_interface()
1078 return -ENODEV; in ks2_eth_parse_slave_interface()
1080 priv->mdio_base = (void *)fdtdec_get_addr(fdt, mdio, "reg"); in ks2_eth_parse_slave_interface()
1083 if (priv->link_type == LINK_TYPE_SGMII_MAC_TO_PHY_MODE) { in ks2_eth_parse_slave_interface()
1084 priv->phy_if = PHY_INTERFACE_MODE_SGMII; in ks2_eth_parse_slave_interface()
1085 pdata->phy_interface = priv->phy_if; in ks2_eth_parse_slave_interface()
1086 priv->sgmii_link_type = SGMII_LINK_MAC_PHY; in ks2_eth_parse_slave_interface()
1087 priv->has_mdio = true; in ks2_eth_parse_slave_interface()
1088 } else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) { in ks2_eth_parse_slave_interface()
1089 priv->phy_if = PHY_INTERFACE_MODE_RGMII; in ks2_eth_parse_slave_interface()
1090 pdata->phy_interface = priv->phy_if; in ks2_eth_parse_slave_interface()
1091 priv->has_mdio = true; in ks2_eth_parse_slave_interface()
1101 const void *fdt = gd->fdt_blob; in ks2_sl_eth_ofdata_to_platdata()
1115 pdata->iobase = fdtdec_get_addr(fdt, netcp, "reg"); in ks2_sl_eth_ofdata_to_platdata()
1124 const void *fdt = gd->fdt_blob; in ks2_eth_ofdata_to_platdata()
1125 int gbe_0 = -ENODEV; in ks2_eth_ofdata_to_platdata()
1130 "netcp-devices"); in ks2_eth_ofdata_to_platdata()
1137 pdata->iobase = devfdt_get_addr(dev); in ks2_eth_ofdata_to_platdata()
1143 { .compatible = "ti,netcp-1.0" },