Lines Matching +full:tx +full:- +full:clk +full:- +full:tap +full:- +full:delay
1 // SPDX-License-Identifier: GPL-2.0+
9 * Copyright (c) 2010-2013 Micrel, Inc.
29 #include <linux/clk.h>
30 #include <linux/delay.h>
126 * The value is calculated as following: (1/1000000)/((2^-32)/4)
132 * The value is calculated as following: (1/1000000)/((2^-32)/8)
360 /* Delay used to get the second part from the LTC */
525 const struct kszphy_type *type = phydev->drv->driver_data; in kszphy_config_intr()
529 if (type && type->interrupt_level_mask) in kszphy_config_intr()
530 mask = type->interrupt_level_mask; in kszphy_config_intr()
542 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { in kszphy_config_intr()
605 return -EINVAL; in kszphy_setup_led()
625 * unique (non-broadcast) address on a shared bus.
666 struct kszphy_priv *priv = phydev->priv; in kszphy_config_reset()
669 if (priv->rmii_ref_clk_sel) { in kszphy_config_reset()
670 ret = kszphy_rmii_clk_sel(phydev, priv->rmii_ref_clk_sel_val); in kszphy_config_reset()
678 if (priv->type && priv->led_mode >= 0) in kszphy_config_reset()
679 kszphy_setup_led(phydev, priv->type->led_mode_reg, priv->led_mode); in kszphy_config_reset()
686 struct kszphy_priv *priv = phydev->priv; in kszphy_config_init()
692 type = priv->type; in kszphy_config_init()
694 if (type && type->has_broadcast_disable) in kszphy_config_init()
697 if (type && type->has_nand_tree_disable) in kszphy_config_init()
705 struct device_node *of_node = phydev->mdio.dev.of_node; in ksz8041_fiber_mode()
707 return of_property_read_bool(of_node, "micrel,fiber-mode"); in ksz8041_fiber_mode()
716 phydev->dev_flags |= MICREL_PHY_FXEN; in ksz8041_config_init()
720 linkmode_and(phydev->supported, phydev->supported, mask); in ksz8041_config_init()
722 phydev->supported); in ksz8041_config_init()
723 linkmode_and(phydev->advertising, phydev->advertising, mask); in ksz8041_config_init()
725 phydev->advertising); in ksz8041_config_init()
726 phydev->autoneg = AUTONEG_DISABLE; in ksz8041_config_init()
734 /* Skip auto-negotiation in fiber mode */ in ksz8041_config_aneg()
735 if (phydev->dev_flags & MICREL_PHY_FXEN) { in ksz8041_config_aneg()
736 phydev->speed = SPEED_100; in ksz8041_config_aneg()
748 if (!phy_id_compare(phydev->phy_id, PHY_ID_KSZ8051, MICREL_PHY_ID_MASK)) in ksz8051_ksz8795_match_phy_device()
774 /* KSZPHY_OMSO_FACTORY_TEST is set at de-assertion of the reset line in ksz8081_config_init()
776 * pull-down is missing, the factory test mode should be cleared by in ksz8081_config_init()
818 /* The MDI-X configuration is automatically changed by the PHY after in ksz8081_config_aneg()
819 * switching from autoneg off to on. So, take MDI-X configuration under in ksz8081_config_aneg()
822 return ksz8081_config_mdix(phydev, phydev->mdix_ctrl); in ksz8081_config_aneg()
835 phydev->mdix_ctrl = ETH_TP_MDI_X; in ksz8081_mdix_update()
837 phydev->mdix_ctrl = ETH_TP_MDI; in ksz8081_mdix_update()
839 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; in ksz8081_mdix_update()
847 phydev->mdix = ETH_TP_MDI; in ksz8081_mdix_update()
849 phydev->mdix = ETH_TP_MDI_X; in ksz8081_mdix_update()
898 int val1 = -1; in ksz9021_load_values_from_of()
899 int val2 = -2; in ksz9021_load_values_from_of()
900 int val3 = -3; in ksz9021_load_values_from_of()
901 int val4 = -4; in ksz9021_load_values_from_of()
925 if (val1 != -1) in ksz9021_load_values_from_of()
928 if (val2 != -2) in ksz9021_load_values_from_of()
931 if (val3 != -3) in ksz9021_load_values_from_of()
934 if (val4 != -4) in ksz9021_load_values_from_of()
949 dev_walker = &phydev->mdio.dev; in ksz9021_config_init()
951 of_node = dev_walker->of_node; in ksz9021_config_init()
952 dev_walker = dev_walker->parent; in ksz9021_config_init()
959 "txen-skew-ps", "txc-skew-ps", in ksz9021_config_init()
960 "rxdv-skew-ps", "rxc-skew-ps"); in ksz9021_config_init()
963 "rxd0-skew-ps", "rxd1-skew-ps", in ksz9021_config_init()
964 "rxd2-skew-ps", "rxd3-skew-ps"); in ksz9021_config_init()
967 "txd0-skew-ps", "txd1-skew-ps", in ksz9021_config_init()
968 "txd2-skew-ps", "txd3-skew-ps"); in ksz9021_config_init()
1002 * provide different RGMII options we need to configure delay offset
1003 * for each pad relative to build in delay.
1005 /* keep rx as "No delay adjustment" and set rx_clk to +0.60ns to get delays of
1011 /* set rx to +0.30ns and rx_clk to -0.90ns to compensate the
1012 * internal 1.2ns delay.
1017 /* set tx to -0.42ns and tx_clk to +0.96ns to get 1.38ns delay */
1021 /* set tx and tx_clk to "No delay adjustment" to keep 0ns
1037 int val[4] = {-1, -2, -3, -4}; in ksz9031_of_load_skew_values()
1060 if (val[i] != -(i + 1)) { in ksz9031_of_load_skew_values()
1089 /* Enable energy-detect power-down mode */
1103 u16 rx, tx, rx_clk, tx_clk; in ksz9031_config_rgmii_delay() local
1106 switch (phydev->interface) { in ksz9031_config_rgmii_delay()
1108 tx = TX_ND; in ksz9031_config_rgmii_delay()
1114 tx = TX_ID; in ksz9031_config_rgmii_delay()
1120 tx = TX_ND; in ksz9031_config_rgmii_delay()
1126 tx = TX_ID; in ksz9031_config_rgmii_delay()
1137 FIELD_PREP(MII_KSZ9031RN_TX_CTL_M, tx)); in ksz9031_config_rgmii_delay()
1150 FIELD_PREP(MII_KSZ9031RN_TXD3, tx) | in ksz9031_config_rgmii_delay()
1151 FIELD_PREP(MII_KSZ9031RN_TXD2, tx) | in ksz9031_config_rgmii_delay()
1152 FIELD_PREP(MII_KSZ9031RN_TXD1, tx) | in ksz9031_config_rgmii_delay()
1153 FIELD_PREP(MII_KSZ9031RN_TXD0, tx)); in ksz9031_config_rgmii_delay()
1165 static const char *clk_skews[2] = {"rxc-skew-ps", "txc-skew-ps"}; in ksz9031_config_init()
1167 "rxd0-skew-ps", "rxd1-skew-ps", in ksz9031_config_init()
1168 "rxd2-skew-ps", "rxd3-skew-ps" in ksz9031_config_init()
1171 "txd0-skew-ps", "txd1-skew-ps", in ksz9031_config_init()
1172 "txd2-skew-ps", "txd3-skew-ps" in ksz9031_config_init()
1174 static const char *control_skews[2] = {"txen-skew-ps", "rxdv-skew-ps"}; in ksz9031_config_init()
1186 dev_walker = &phydev->mdio.dev; in ksz9031_config_init()
1188 of_node = dev_walker->of_node; in ksz9031_config_init()
1189 dev_walker = dev_walker->parent; in ksz9031_config_init()
1219 "*-skew-ps values should be used only with RGMII PHY modes\n"); in ksz9031_config_init()
1222 * When the device links in the 1000BASE-T slave mode only, in ksz9031_config_init()
1236 if (of_property_read_bool(of_node, "micrel,force-master")) { in ksz9031_config_init()
1266 int val[4] = {-(1 + KSZ9131_OFFSET), -(2 + KSZ9131_OFFSET), in ksz9131_of_load_skew_values()
1267 -(3 + KSZ9131_OFFSET), -(4 + KSZ9131_OFFSET)}; in ksz9131_of_load_skew_values()
1283 if (skewval < -KSZ9131_OFFSET) in ksz9131_of_load_skew_values()
1284 skewval = -KSZ9131_OFFSET; in ksz9131_of_load_skew_values()
1302 if (val[i] != -(i + 1 + KSZ9131_OFFSET)) { in ksz9131_of_load_skew_values()
1320 const struct kszphy_type *type = phydev->drv->driver_data; in ksz9131_config_rgmii_delay()
1324 switch (phydev->interface) { in ksz9131_config_rgmii_delay()
1326 rxcdll_val = type->disable_dll_rx_bit; in ksz9131_config_rgmii_delay()
1327 txcdll_val = type->disable_dll_tx_bit; in ksz9131_config_rgmii_delay()
1335 txcdll_val = type->disable_dll_tx_bit; in ksz9131_config_rgmii_delay()
1338 rxcdll_val = type->disable_dll_rx_bit; in ksz9131_config_rgmii_delay()
1346 KSZ9131RN_RXC_DLL_CTRL, type->disable_dll_mask, in ksz9131_config_rgmii_delay()
1352 KSZ9131RN_TXC_DLL_CTRL, type->disable_dll_mask, in ksz9131_config_rgmii_delay()
1358 * When LEDs are configured in Individual Mode, LED1 is ON in a no-link
1379 char *clk_skews[2] = {"rxc-skew-psec", "txc-skew-psec"}; in ksz9131_config_init()
1381 "rxd0-skew-psec", "rxd1-skew-psec", in ksz9131_config_init()
1382 "rxd2-skew-psec", "rxd3-skew-psec" in ksz9131_config_init()
1385 "txd0-skew-psec", "txd1-skew-psec", in ksz9131_config_init()
1386 "txd2-skew-psec", "txd3-skew-psec" in ksz9131_config_init()
1388 char *control_skews[2] = {"txen-skew-psec", "rxdv-skew-psec"}; in ksz9131_config_init()
1392 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; in ksz9131_config_init()
1394 dev_walker = &phydev->mdio.dev; in ksz9131_config_init()
1396 of_node = dev_walker->of_node; in ksz9131_config_init()
1397 dev_walker = dev_walker->parent; in ksz9131_config_init()
1451 if (phydev->mdix_ctrl != ETH_TP_MDI_AUTO) { in ksz9131_mdix_update()
1452 phydev->mdix = phydev->mdix_ctrl; in ksz9131_mdix_update()
1460 phydev->mdix = ETH_TP_MDI; in ksz9131_mdix_update()
1462 phydev->mdix = ETH_TP_MDI_X; in ksz9131_mdix_update()
1464 phydev->mdix = ETH_TP_MDI_INVALID; in ksz9131_mdix_update()
1510 ret = ksz9131_config_mdix(phydev, phydev->mdix_ctrl); in ksz9131_config_aneg()
1531 linkmode_and(phydev->supported_eee, phydev->supported, in ksz9477_get_features()
1550 phydev->duplex = DUPLEX_HALF; in ksz8873mll_read_status()
1552 phydev->duplex = DUPLEX_FULL; in ksz8873mll_read_status()
1555 phydev->speed = SPEED_10; in ksz8873mll_read_status()
1557 phydev->speed = SPEED_100; in ksz8873mll_read_status()
1559 phydev->link = 1; in ksz8873mll_read_status()
1560 phydev->pause = phydev->asym_pause = 0; in ksz8873mll_read_status()
1575 * link-up may fail after a link-up to link-down transition. in ksz9031_get_features()
1582 linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported); in ksz9031_get_features()
1587 linkmode_set_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported); in ksz9031_get_features()
1607 phydev->link = 0; in ksz9031_read_status()
1608 if (phydev->drv->config_intr && phy_interrupt_is_valid(phydev)) in ksz9031_read_status()
1609 phydev->drv->config_intr(phydev); in ksz9031_read_status()
1618 struct kszphy_priv *priv = phydev->priv; in ksz9x31_cable_test_start()
1621 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic in ksz9x31_cable_test_start()
1622 * Prior to running the cable diagnostics, Auto-negotiation should in ksz9x31_cable_test_start()
1633 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic in ksz9x31_cable_test_start()
1634 * The Master-Slave configuration should be set to Slave by writing in ksz9x31_cable_test_start()
1635 * a value of 0x1000 to the Auto-Negotiation Master Slave Control in ksz9x31_cable_test_start()
1643 priv->vct_ctrl1000 = ret & (CTL1000_ENABLE_MASTER | CTL1000_AS_MASTER); in ksz9x31_cable_test_start()
1688 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic in ksz9x31_cable_test_fault_length()
1690 * distance to fault = (VCT_DATA - 22) * 4 / cable propagation velocity in ksz9x31_cable_test_fault_length()
1693 dt = clamp(dt - 22, 0, 255); in ksz9x31_cable_test_fault_length()
1725 /* KSZ9131RNX, DS00002841B-page 38, 4.14 LinkMD (R) Cable Diagnostic in ksz9x31_cable_test_one_pair()
1746 return -EAGAIN; in ksz9x31_cable_test_one_pair()
1765 struct kszphy_priv *priv = phydev->priv; in ksz9x31_cable_test_get_status()
1773 while (pair_mask && retries--) { in ksz9x31_cable_test_get_status()
1776 if (ret == -EAGAIN) in ksz9x31_cable_test_get_status()
1802 priv->vct_ctrl1000); in ksz9x31_cable_test_get_status()
1824 * counter intuitive, the "-X" in "1 = Force MDI" in the data in ksz886x_config_mdix()
1826 * 1 = Force MDI (sic!) (transmit on RX+/RX- pins) in ksz886x_config_mdix()
1827 * 0 = Normal operation (transmit on TX+/TX- pins) in ksz886x_config_mdix()
1852 if (phydev->autoneg != AUTONEG_ENABLE) { in ksz886x_config_aneg()
1874 /* The MDI-X configuration is automatically changed by the PHY after in ksz886x_config_aneg()
1875 * switching from autoneg off to on. So, take MDI-X configuration under in ksz886x_config_aneg()
1878 return ksz886x_config_mdix(phydev, phydev->mdix_ctrl); in ksz886x_config_aneg()
1891 phydev->mdix_ctrl = ETH_TP_MDI_X; in ksz886x_mdix_update()
1893 phydev->mdix_ctrl = ETH_TP_MDI; in ksz886x_mdix_update()
1895 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; in ksz886x_mdix_update()
1904 phydev->mdix = ETH_TP_MDI_X; in ksz886x_mdix_update()
1906 phydev->mdix = ETH_TP_MDI; in ksz886x_mdix_update()
1938 /* Transmit waveform amplitude can be improved (1000BASE-T, 100BASE-TX, 10BASE-Te) */
1967 * necessary to set the PHY to 100 Mbps speed with auto-negotiation in ksz9477_phy_errata()
1968 * disabled by writing to register 0xN100-0xN101. After writing the in ksz9477_phy_errata()
1970 * register settings, write register 0xN100-0xN101 again to enable in ksz9477_phy_errata()
1971 * and restart auto-negotiation. in ksz9477_phy_errata()
1980 err = phy_write_mmd(phydev, errata->dev_addr, errata->reg_addr, errata->val); in ksz9477_phy_errata()
1997 if ((phydev->phy_id & 0xf) == 1) { in ksz9477_config_init()
2006 if (phydev->dev_flags & MICREL_NO_EEE) in ksz9477_config_init()
2007 linkmode_fill(phydev->eee_broken_modes); in ksz9477_config_init()
2028 struct kszphy_priv *priv = phydev->priv; in kszphy_get_stat()
2036 val = val & ((1 << stat.bits) - 1); in kszphy_get_stat()
2037 priv->stats[i] += val; in kszphy_get_stat()
2038 ret = priv->stats[i]; in kszphy_get_stat()
2057 phydev->interrupts = PHY_INTERRUPT_DISABLED; in kszphy_suspend()
2058 if (phydev->drv->config_intr) in kszphy_suspend()
2059 phydev->drv->config_intr(phydev); in kszphy_suspend()
2067 const struct kszphy_type *type = phydev->drv->driver_data; in kszphy_parse_led_mode()
2068 const struct device_node *np = phydev->mdio.dev.of_node; in kszphy_parse_led_mode()
2069 struct kszphy_priv *priv = phydev->priv; in kszphy_parse_led_mode()
2072 if (type && type->led_mode_reg) { in kszphy_parse_led_mode()
2073 ret = of_property_read_u32(np, "micrel,led-mode", in kszphy_parse_led_mode()
2074 &priv->led_mode); in kszphy_parse_led_mode()
2077 priv->led_mode = -1; in kszphy_parse_led_mode()
2079 if (priv->led_mode > 3) { in kszphy_parse_led_mode()
2081 priv->led_mode); in kszphy_parse_led_mode()
2082 priv->led_mode = -1; in kszphy_parse_led_mode()
2085 priv->led_mode = -1; in kszphy_parse_led_mode()
2095 /* After switching from power-down to normal mode, an internal global in kszphy_resume()
2107 phydev->interrupts = PHY_INTERRUPT_ENABLED; in kszphy_resume()
2108 if (phydev->drv->config_intr) in kszphy_resume()
2109 phydev->drv->config_intr(phydev); in kszphy_resume()
2128 /* After switching from power-down to normal mode, an internal global in ksz9477_resume()
2135 if ((phydev->phy_id & 0xf) == 1) { in ksz9477_resume()
2143 phydev->interrupts = PHY_INTERRUPT_ENABLED; in ksz9477_resume()
2144 if (phydev->drv->config_intr) in ksz9477_resume()
2145 phydev->drv->config_intr(phydev); in ksz9477_resume()
2165 /* Re-program the value after chip is reset. */ in ksz8061_resume()
2172 phydev->interrupts = PHY_INTERRUPT_ENABLED; in ksz8061_resume()
2173 if (phydev->drv->config_intr) in ksz8061_resume()
2174 phydev->drv->config_intr(phydev); in ksz8061_resume()
2182 const struct kszphy_type *type = phydev->drv->driver_data; in kszphy_probe()
2183 const struct device_node *np = phydev->mdio.dev.of_node; in kszphy_probe()
2185 struct clk *clk; in kszphy_probe() local
2187 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); in kszphy_probe()
2189 return -ENOMEM; in kszphy_probe()
2191 phydev->priv = priv; in kszphy_probe()
2193 priv->type = type; in kszphy_probe()
2197 clk = devm_clk_get_optional_enabled(&phydev->mdio.dev, "rmii-ref"); in kszphy_probe()
2198 /* NOTE: clk may be NULL if building without CONFIG_HAVE_CLK */ in kszphy_probe()
2199 if (!IS_ERR_OR_NULL(clk)) { in kszphy_probe()
2200 unsigned long rate = clk_get_rate(clk); in kszphy_probe()
2204 priv->rmii_ref_clk_sel = type->has_rmii_ref_clk_sel; in kszphy_probe()
2206 "micrel,rmii-reference-clock-select-25-mhz"); in kszphy_probe()
2209 priv->rmii_ref_clk_sel_val = rmii_ref_clk_sel_25_mhz; in kszphy_probe()
2211 priv->rmii_ref_clk_sel_val = !rmii_ref_clk_sel_25_mhz; in kszphy_probe()
2215 return -EINVAL; in kszphy_probe()
2217 } else if (!clk) { in kszphy_probe()
2218 /* unnamed clock from the generic ethernet-phy binding */ in kszphy_probe()
2219 clk = devm_clk_get_optional_enabled(&phydev->mdio.dev, NULL); in kszphy_probe()
2220 if (IS_ERR(clk)) in kszphy_probe()
2221 return PTR_ERR(clk); in kszphy_probe()
2225 phydev->port = PORT_FIBRE; in kszphy_probe()
2227 /* Support legacy board-file configuration */ in kszphy_probe()
2228 if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) { in kszphy_probe()
2229 priv->rmii_ref_clk_sel = true; in kszphy_probe()
2230 priv->rmii_ref_clk_sel_val = true; in kszphy_probe()
2240 * confuse the internal state machine - disable auto neg here. in lan8814_cable_test_start()
2249 if (phydev->dev_flags & MICREL_KSZ8_P1_ERRATA) in ksz886x_cable_test_start()
2250 return -EOPNOTSUPP; in ksz886x_cable_test_start()
2254 * confuse the internal state machine - disable auto neg here. in ksz886x_cable_test_start()
2300 * (DELTA_TIME - 22) * 0.8 for lan8814 phy. in ksz886x_cable_test_fault_length()
2305 return ((dt - 22) * 800) / 10; in ksz886x_cable_test_fault_length()
2312 const struct kszphy_type *type = phydev->drv->driver_data; in ksz886x_cable_test_wait_for_completion()
2315 ret = phy_read_poll_timeout(phydev, type->cable_diag_reg, val, in ksz886x_cable_test_wait_for_completion()
2349 return -EAGAIN; in lan8814_cable_test_one_pair()
2377 * We can workaround this limitation by using the MDI-X functionality. in ksz886x_cable_test_one_pair()
2384 switch (phydev->phy_id & MICREL_PHY_ID_MASK) { in ksz886x_cable_test_one_pair()
2392 ret = -ENODEV; in ksz886x_cable_test_one_pair()
2414 return -EAGAIN; in ksz886x_cable_test_one_pair()
2432 const struct kszphy_type *type = phydev->drv->driver_data; in ksz886x_cable_test_get_status()
2433 unsigned long pair_mask = type->pair_mask; in ksz886x_cable_test_get_status()
2441 while (pair_mask && retries--) { in ksz886x_cable_test_get_status()
2443 if (type->cable_diag_reg == LAN8814_CABLE_DIAG) in ksz886x_cable_test_get_status()
2447 if (ret == -EAGAIN) in ksz886x_cable_test_get_status()
2560 struct phy_device *phydev = ptp_priv->phydev; in lan8814_ts_info()
2561 struct lan8814_shared_priv *shared = phydev->shared->priv; in lan8814_ts_info()
2563 info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | in lan8814_ts_info()
2567 info->phc_index = ptp_clock_index(shared->ptp_clock); in lan8814_ts_info()
2569 info->tx_types = in lan8814_ts_info()
2574 info->rx_filters = in lan8814_ts_info()
2607 ptp_priv->hwts_tx_type = config->tx_type; in lan8814_hwtstamp()
2608 ptp_priv->rx_filter = config->rx_filter; in lan8814_hwtstamp()
2610 switch (config->rx_filter) { in lan8814_hwtstamp()
2612 ptp_priv->layer = 0; in lan8814_hwtstamp()
2613 ptp_priv->version = 0; in lan8814_hwtstamp()
2618 ptp_priv->layer = PTP_CLASS_L4; in lan8814_hwtstamp()
2619 ptp_priv->version = PTP_CLASS_V2; in lan8814_hwtstamp()
2624 ptp_priv->layer = PTP_CLASS_L2; in lan8814_hwtstamp()
2625 ptp_priv->version = PTP_CLASS_V2; in lan8814_hwtstamp()
2630 ptp_priv->layer = PTP_CLASS_L4 | PTP_CLASS_L2; in lan8814_hwtstamp()
2631 ptp_priv->version = PTP_CLASS_V2; in lan8814_hwtstamp()
2634 return -ERANGE; in lan8814_hwtstamp()
2637 if (ptp_priv->layer & PTP_CLASS_L2) { in lan8814_hwtstamp()
2640 } else if (ptp_priv->layer & PTP_CLASS_L4) { in lan8814_hwtstamp()
2644 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_RX_PARSE_CONFIG, rxcfg); in lan8814_hwtstamp()
2645 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_PARSE_CONFIG, txcfg); in lan8814_hwtstamp()
2649 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_RX_TIMESTAMP_EN, pkt_ts_enable); in lan8814_hwtstamp()
2650 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_TIMESTAMP_EN, pkt_ts_enable); in lan8814_hwtstamp()
2652 tx_mod = lanphy_read_page_reg(ptp_priv->phydev, 5, PTP_TX_MOD); in lan8814_hwtstamp()
2653 if (ptp_priv->hwts_tx_type == HWTSTAMP_TX_ONESTEP_SYNC) { in lan8814_hwtstamp()
2654 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_MOD, in lan8814_hwtstamp()
2656 } else if (ptp_priv->hwts_tx_type == HWTSTAMP_TX_ON) { in lan8814_hwtstamp()
2657 lanphy_write_page_reg(ptp_priv->phydev, 5, PTP_TX_MOD, in lan8814_hwtstamp()
2661 if (config->rx_filter != HWTSTAMP_FILTER_NONE) in lan8814_hwtstamp()
2662 lan8814_config_ts_intr(ptp_priv->phydev, true); in lan8814_hwtstamp()
2664 lan8814_config_ts_intr(ptp_priv->phydev, false); in lan8814_hwtstamp()
2667 list_for_each_entry_safe(rx_ts, tmp, &ptp_priv->rx_ts_list, list) { in lan8814_hwtstamp()
2668 list_del(&rx_ts->list); in lan8814_hwtstamp()
2671 skb_queue_purge(&ptp_priv->rx_queue); in lan8814_hwtstamp()
2672 skb_queue_purge(&ptp_priv->tx_queue); in lan8814_hwtstamp()
2674 lan8814_flush_fifo(ptp_priv->phydev, false); in lan8814_hwtstamp()
2675 lan8814_flush_fifo(ptp_priv->phydev, true); in lan8814_hwtstamp()
2685 switch (ptp_priv->hwts_tx_type) { in lan8814_txtstamp()
2693 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; in lan8814_txtstamp()
2694 skb_queue_tail(&ptp_priv->tx_queue, skb); in lan8814_txtstamp()
2716 *sig = (__force u16)(ntohs(ptp_header->sequence_id)); in lan8814_get_sig_rx()
2733 spin_lock_irqsave(&ptp_priv->rx_ts_lock, flags); in lan8814_match_rx_skb()
2734 list_for_each_entry_safe(rx_ts, tmp, &ptp_priv->rx_ts_list, list) { in lan8814_match_rx_skb()
2736 if (memcmp(&skb_sig, &rx_ts->seq_id, sizeof(rx_ts->seq_id))) in lan8814_match_rx_skb()
2741 shhwtstamps->hwtstamp = ktime_set(rx_ts->seconds, in lan8814_match_rx_skb()
2742 rx_ts->nsec); in lan8814_match_rx_skb()
2743 list_del(&rx_ts->list); in lan8814_match_rx_skb()
2749 spin_unlock_irqrestore(&ptp_priv->rx_ts_lock, flags); in lan8814_match_rx_skb()
2761 if (ptp_priv->rx_filter == HWTSTAMP_FILTER_NONE || in lan8814_rxtstamp()
2765 if ((type & ptp_priv->version) == 0 || (type & ptp_priv->layer) == 0) in lan8814_rxtstamp()
2772 skb_queue_tail(&ptp_priv->rx_queue, skb); in lan8814_rxtstamp()
2810 struct phy_device *phydev = shared->phydev; in lan8814_ptpci_gettime64()
2814 mutex_lock(&shared->shared_lock); in lan8814_ptpci_gettime64()
2816 mutex_unlock(&shared->shared_lock); in lan8814_ptpci_gettime64()
2817 ts->tv_sec = seconds; in lan8814_ptpci_gettime64()
2818 ts->tv_nsec = nano_seconds; in lan8814_ptpci_gettime64()
2828 struct phy_device *phydev = shared->phydev; in lan8814_ptpci_settime64()
2830 mutex_lock(&shared->shared_lock); in lan8814_ptpci_settime64()
2831 lan8814_ptp_clock_set(phydev, ts->tv_sec, ts->tv_nsec); in lan8814_ptpci_settime64()
2832 mutex_unlock(&shared->shared_lock); in lan8814_ptpci_settime64()
2878 nano_seconds -= 1000000000; in lan8814_ptp_clock_step()
2883 } else if (time_step_ns < -15000000000LL) { in lan8814_ptp_clock_step()
2885 time_step_ns = -time_step_ns; in lan8814_ptp_clock_step()
2888 set_seconds -= div_u64_rem(time_step_ns, 1000000000LL, in lan8814_ptp_clock_step()
2892 set_seconds--; in lan8814_ptp_clock_step()
2895 nano_seconds -= nano_seconds_step; in lan8814_ptp_clock_step()
2908 abs_time_step_ns = (u64)(-time_step_ns); in lan8814_ptp_clock_step()
2909 seconds = -((s32)div_u64_rem(abs_time_step_ns, 1000000000, in lan8814_ptp_clock_step()
2917 seconds--; in lan8814_ptp_clock_step()
2918 nano_seconds = (1000000000 - nano_seconds); in lan8814_ptp_clock_step()
2930 nano_seconds -= 1000000000; in lan8814_ptp_clock_step()
2951 seconds -= ((s32)adjustment_value); in lan8814_ptp_clock_step()
2954 set_seconds -= adjustment_value; in lan8814_ptp_clock_step()
2957 u32 adjustment_value = (u32)(-seconds); in lan8814_ptp_clock_step()
3000 struct phy_device *phydev = shared->phydev; in lan8814_ptpci_adjtime()
3002 mutex_lock(&shared->shared_lock); in lan8814_ptpci_adjtime()
3004 mutex_unlock(&shared->shared_lock); in lan8814_ptpci_adjtime()
3013 struct phy_device *phydev = shared->phydev; in lan8814_ptpci_adjfine()
3019 scaled_ppm = -scaled_ppm; in lan8814_ptpci_adjfine()
3032 mutex_lock(&shared->shared_lock); in lan8814_ptpci_adjfine()
3035 mutex_unlock(&shared->shared_lock); in lan8814_ptpci_adjfine()
3135 struct phy_device *phydev = shared->phydev; in lan8814_ptp_perout()
3142 if (rq->perout.flags & ~PTP_PEROUT_DUTY_CYCLE) in lan8814_ptp_perout()
3143 return -EOPNOTSUPP; in lan8814_ptp_perout()
3145 mutex_lock(&shared->shared_lock); in lan8814_ptp_perout()
3146 event = rq->perout.index; in lan8814_ptp_perout()
3147 pin = ptp_find_pin(shared->ptp_clock, PTP_PF_PEROUT, event); in lan8814_ptp_perout()
3149 mutex_unlock(&shared->shared_lock); in lan8814_ptp_perout()
3150 return -EBUSY; in lan8814_ptp_perout()
3156 mutex_unlock(&shared->shared_lock); in lan8814_ptp_perout()
3160 ts_on.tv_sec = rq->perout.on.sec; in lan8814_ptp_perout()
3161 ts_on.tv_nsec = rq->perout.on.nsec; in lan8814_ptp_perout()
3164 ts_period.tv_sec = rq->perout.period.sec; in lan8814_ptp_perout()
3165 ts_period.tv_nsec = rq->perout.period.nsec; in lan8814_ptp_perout()
3171 mutex_unlock(&shared->shared_lock); in lan8814_ptp_perout()
3172 return -EOPNOTSUPP; in lan8814_ptp_perout()
3178 mutex_unlock(&shared->shared_lock); in lan8814_ptp_perout()
3179 return -EINVAL; in lan8814_ptp_perout()
3234 lan8814_ptp_set_target(phydev, event, rq->perout.start.sec, in lan8814_ptp_perout()
3235 rq->perout.start.nsec); in lan8814_ptp_perout()
3236 lan8814_ptp_set_reload(phydev, event, rq->perout.period.sec, in lan8814_ptp_perout()
3237 rq->perout.period.nsec); in lan8814_ptp_perout()
3239 mutex_unlock(&shared->shared_lock); in lan8814_ptp_perout()
3308 struct phy_device *phydev = shared->phydev; in lan8814_ptp_extts()
3311 if (rq->extts.flags & ~(PTP_ENABLE_FEATURE | in lan8814_ptp_extts()
3314 return -EOPNOTSUPP; in lan8814_ptp_extts()
3316 pin = ptp_find_pin(shared->ptp_clock, PTP_PF_EXTTS, in lan8814_ptp_extts()
3317 rq->extts.index); in lan8814_ptp_extts()
3318 if (pin == -1 || pin != LAN8814_PTP_EXTTS_NUM) in lan8814_ptp_extts()
3319 return -EINVAL; in lan8814_ptp_extts()
3321 mutex_lock(&shared->shared_lock); in lan8814_ptp_extts()
3323 lan8814_ptp_extts_on(phydev, pin, rq->extts.flags); in lan8814_ptp_extts()
3327 mutex_unlock(&shared->shared_lock); in lan8814_ptp_extts()
3335 switch (rq->type) { in lan8814_ptpci_enable()
3341 return -EINVAL; in lan8814_ptpci_enable()
3356 return -1; in lan8814_ptpci_verify()
3360 return -1; in lan8814_ptpci_verify()
3363 return -1; in lan8814_ptpci_verify()
3380 *sig = (__force u16)(ntohs(ptp_header->sequence_id)); in lan8814_get_sig_tx()
3393 spin_lock_irqsave(&ptp_priv->tx_queue.lock, flags); in lan8814_match_tx_skb()
3394 skb_queue_walk_safe(&ptp_priv->tx_queue, skb, skb_tmp) { in lan8814_match_tx_skb()
3401 __skb_unlink(skb, &ptp_priv->tx_queue); in lan8814_match_tx_skb()
3405 spin_unlock_irqrestore(&ptp_priv->tx_queue.lock, flags); in lan8814_match_tx_skb()
3416 struct phy_device *phydev = ptp_priv->phydev; in lan8814_dequeue_tx_skb()
3426 struct phy_device *phydev = ptp_priv->phydev; in lan8814_get_tx_ts()
3448 spin_lock_irqsave(&ptp_priv->rx_queue.lock, flags); in lan8814_match_skb()
3449 skb_queue_walk_safe(&ptp_priv->rx_queue, skb, skb_tmp) { in lan8814_match_skb()
3453 if (memcmp(&skb_sig, &rx_ts->seq_id, sizeof(rx_ts->seq_id))) in lan8814_match_skb()
3456 __skb_unlink(skb, &ptp_priv->rx_queue); in lan8814_match_skb()
3461 spin_unlock_irqrestore(&ptp_priv->rx_queue.lock, flags); in lan8814_match_skb()
3466 shhwtstamps->hwtstamp = ktime_set(rx_ts->seconds, rx_ts->nsec); in lan8814_match_skb()
3482 spin_lock_irqsave(&ptp_priv->rx_ts_lock, flags); in lan8814_match_rx_ts()
3483 list_add(&rx_ts->list, &ptp_priv->rx_ts_list); in lan8814_match_rx_ts()
3484 spin_unlock_irqrestore(&ptp_priv->rx_ts_lock, flags); in lan8814_match_rx_ts()
3492 struct phy_device *phydev = ptp_priv->phydev; in lan8814_get_rx_ts()
3501 lan8814_ptp_rx_ts_get(phydev, &rx_ts->seconds, &rx_ts->nsec, in lan8814_get_rx_ts()
3502 &rx_ts->seq_id); in lan8814_get_rx_ts()
3514 struct kszphy_priv *priv = phydev->priv; in lan8814_handle_ptp_interrupt()
3515 struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv; in lan8814_handle_ptp_interrupt()
3525 skb_queue_purge(&ptp_priv->tx_queue); in lan8814_handle_ptp_interrupt()
3530 skb_queue_purge(&ptp_priv->rx_queue); in lan8814_handle_ptp_interrupt()
3536 struct phy_device *phydev = shared->phydev; in lan8814_gpio_process_cap()
3552 return -1; in lan8814_gpio_process_cap()
3575 ptp_clock_event(shared->ptp_clock, &ptp_event); in lan8814_gpio_process_cap()
3582 struct lan8814_shared_priv *shared = phydev->shared->priv; in lan8814_handle_gpio_interrupt()
3585 mutex_lock(&shared->shared_lock); in lan8814_handle_gpio_interrupt()
3587 mutex_unlock(&shared->shared_lock); in lan8814_handle_gpio_interrupt()
3596 /* MDI-X setting for swap A,B transmit */ in lan8804_config_init()
3643 /* By default interrupt buffer is open-drain in which case the interrupt in lan8804_config_intr()
3645 * push-pull to be able to change interrupt polarity in lan8804_config_intr()
3650 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { in lan8804_config_intr()
3721 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { in lan8814_config_intr()
3740 struct kszphy_priv *priv = phydev->priv; in lan8814_ptp_init()
3741 struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv; in lan8814_ptp_init()
3773 skb_queue_head_init(&ptp_priv->tx_queue); in lan8814_ptp_init()
3774 skb_queue_head_init(&ptp_priv->rx_queue); in lan8814_ptp_init()
3775 INIT_LIST_HEAD(&ptp_priv->rx_ts_list); in lan8814_ptp_init()
3776 spin_lock_init(&ptp_priv->rx_ts_lock); in lan8814_ptp_init()
3778 ptp_priv->phydev = phydev; in lan8814_ptp_init()
3780 ptp_priv->mii_ts.rxtstamp = lan8814_rxtstamp; in lan8814_ptp_init()
3781 ptp_priv->mii_ts.txtstamp = lan8814_txtstamp; in lan8814_ptp_init()
3782 ptp_priv->mii_ts.hwtstamp = lan8814_hwtstamp; in lan8814_ptp_init()
3783 ptp_priv->mii_ts.ts_info = lan8814_ts_info; in lan8814_ptp_init()
3785 phydev->mii_ts = &ptp_priv->mii_ts; in lan8814_ptp_init()
3788 phydev->default_timestamp = true; in lan8814_ptp_init()
3793 struct lan8814_shared_priv *shared = phydev->shared->priv; in lan8814_ptp_probe_once()
3796 mutex_init(&shared->shared_lock); in lan8814_ptp_probe_once()
3798 shared->pin_config = devm_kmalloc_array(&phydev->mdio.dev, in lan8814_ptp_probe_once()
3800 sizeof(*shared->pin_config), in lan8814_ptp_probe_once()
3802 if (!shared->pin_config) in lan8814_ptp_probe_once()
3803 return -ENOMEM; in lan8814_ptp_probe_once()
3806 struct ptp_pin_desc *ptp_pin = &shared->pin_config[i]; in lan8814_ptp_probe_once()
3809 snprintf(ptp_pin->name, in lan8814_ptp_probe_once()
3810 sizeof(ptp_pin->name), "lan8814_ptp_pin_%02d", i); in lan8814_ptp_probe_once()
3811 ptp_pin->index = i; in lan8814_ptp_probe_once()
3812 ptp_pin->func = PTP_PF_NONE; in lan8814_ptp_probe_once()
3815 shared->ptp_clock_info.owner = THIS_MODULE; in lan8814_ptp_probe_once()
3816 snprintf(shared->ptp_clock_info.name, 30, "%s", phydev->drv->name); in lan8814_ptp_probe_once()
3817 shared->ptp_clock_info.max_adj = 31249999; in lan8814_ptp_probe_once()
3818 shared->ptp_clock_info.n_alarm = 0; in lan8814_ptp_probe_once()
3819 shared->ptp_clock_info.n_ext_ts = LAN8814_PTP_EXTTS_NUM; in lan8814_ptp_probe_once()
3820 shared->ptp_clock_info.n_pins = LAN8814_PTP_GPIO_NUM; in lan8814_ptp_probe_once()
3821 shared->ptp_clock_info.pps = 0; in lan8814_ptp_probe_once()
3822 shared->ptp_clock_info.pin_config = shared->pin_config; in lan8814_ptp_probe_once()
3823 shared->ptp_clock_info.n_per_out = LAN8814_PTP_PEROUT_NUM; in lan8814_ptp_probe_once()
3824 shared->ptp_clock_info.adjfine = lan8814_ptpci_adjfine; in lan8814_ptp_probe_once()
3825 shared->ptp_clock_info.adjtime = lan8814_ptpci_adjtime; in lan8814_ptp_probe_once()
3826 shared->ptp_clock_info.gettime64 = lan8814_ptpci_gettime64; in lan8814_ptp_probe_once()
3827 shared->ptp_clock_info.settime64 = lan8814_ptpci_settime64; in lan8814_ptp_probe_once()
3828 shared->ptp_clock_info.getcrosststamp = NULL; in lan8814_ptp_probe_once()
3829 shared->ptp_clock_info.enable = lan8814_ptpci_enable; in lan8814_ptp_probe_once()
3830 shared->ptp_clock_info.verify = lan8814_ptpci_verify; in lan8814_ptp_probe_once()
3832 shared->ptp_clock = ptp_clock_register(&shared->ptp_clock_info, in lan8814_ptp_probe_once()
3833 &phydev->mdio.dev); in lan8814_ptp_probe_once()
3834 if (IS_ERR(shared->ptp_clock)) { in lan8814_ptp_probe_once()
3836 PTR_ERR(shared->ptp_clock)); in lan8814_ptp_probe_once()
3837 return -EINVAL; in lan8814_ptp_probe_once()
3841 if (!shared->ptp_clock) in lan8814_ptp_probe_once()
3846 shared->phydev = phydev; in lan8814_ptp_probe_once()
3877 struct kszphy_priv *lan8814 = phydev->priv; in lan8814_config_init()
3890 /* MDI-X setting for swap A,B transmit */ in lan8814_config_init()
3896 if (lan8814->led_mode >= 0) in lan8814_config_init()
3897 lan8814_setup_led(phydev, lan8814->led_mode); in lan8814_config_init()
3911 gpiod = devm_gpiod_get_optional(&phydev->mdio.dev, "coma-mode", in lan8814_release_coma_mode()
3952 const struct kszphy_type *type = phydev->drv->driver_data; in lan8814_probe()
3957 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); in lan8814_probe()
3959 return -ENOMEM; in lan8814_probe()
3961 phydev->priv = priv; in lan8814_probe()
3963 priv->type = type; in lan8814_probe()
3967 /* Strap-in value for PHY address, below register read gives starting in lan8814_probe()
3971 devm_phy_package_join(&phydev->mdio.dev, phydev, in lan8814_probe()
4079 /* 10M/100M Ethernet Signal Tuning Errata for Shorted-Center Tap in lan8841_config_init()
4125 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { in lan8841_config_intr()
4166 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_get_tx_ts()
4200 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_flush_fifo()
4223 struct phy_device *phydev = ptp_priv->phydev; in lan8841_gpio_process_cap()
4228 pin = ptp_find_pin_unlocked(ptp_priv->ptp_clock, PTP_PF_EXTTS, 0); in lan8841_gpio_process_cap()
4229 if (pin == -1) in lan8841_gpio_process_cap()
4241 mutex_lock(&ptp_priv->ptp_lock); in lan8841_gpio_process_cap()
4259 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_gpio_process_cap()
4267 ptp_clock_event(ptp_priv->ptp_clock, &ptp_event); in lan8841_gpio_process_cap()
4272 struct kszphy_priv *priv = phydev->priv; in lan8841_handle_ptp_interrupt()
4273 struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv; in lan8841_handle_ptp_interrupt()
4287 skb_queue_purge(&ptp_priv->tx_queue); in lan8841_handle_ptp_interrupt()
4328 info->phc_index = ptp_priv->ptp_clock ? in lan8841_ts_info()
4329 ptp_clock_index(ptp_priv->ptp_clock) : -1; in lan8841_ts_info()
4330 if (info->phc_index == -1) in lan8841_ts_info()
4333 info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | in lan8841_ts_info()
4337 info->tx_types = (1 << HWTSTAMP_TX_OFF) | in lan8841_ts_info()
4341 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | in lan8841_ts_info()
4356 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_enable_processing()
4359 /* Enable interrupts on the TX side */ in lan8841_ptp_enable_processing()
4377 ptp_schedule_worker(ptp_priv->ptp_clock, 0); in lan8841_ptp_enable_processing()
4379 /* Disable interrupts on the TX side */ in lan8841_ptp_enable_processing()
4390 ptp_cancel_worker_sync(ptp_priv->ptp_clock); in lan8841_ptp_enable_processing()
4403 struct phy_device *phydev = ptp_priv->phydev; in lan8841_hwtstamp()
4407 ptp_priv->hwts_tx_type = config->tx_type; in lan8841_hwtstamp()
4408 ptp_priv->rx_filter = config->rx_filter; in lan8841_hwtstamp()
4410 switch (config->rx_filter) { in lan8841_hwtstamp()
4412 ptp_priv->layer = 0; in lan8841_hwtstamp()
4413 ptp_priv->version = 0; in lan8841_hwtstamp()
4418 ptp_priv->layer = PTP_CLASS_L4; in lan8841_hwtstamp()
4419 ptp_priv->version = PTP_CLASS_V2; in lan8841_hwtstamp()
4424 ptp_priv->layer = PTP_CLASS_L2; in lan8841_hwtstamp()
4425 ptp_priv->version = PTP_CLASS_V2; in lan8841_hwtstamp()
4430 ptp_priv->layer = PTP_CLASS_L4 | PTP_CLASS_L2; in lan8841_hwtstamp()
4431 ptp_priv->version = PTP_CLASS_V2; in lan8841_hwtstamp()
4434 return -ERANGE; in lan8841_hwtstamp()
4440 if (ptp_priv->layer & PTP_CLASS_L2) { in lan8841_hwtstamp()
4443 } else if (ptp_priv->layer & PTP_CLASS_L4) { in lan8841_hwtstamp()
4456 /* Enable / disable of the TX timestamp in the SYNC frames */ in lan8841_hwtstamp()
4459 ptp_priv->hwts_tx_type == HWTSTAMP_TX_ONESTEP_SYNC ? in lan8841_hwtstamp()
4464 config->rx_filter != HWTSTAMP_FILTER_NONE); in lan8841_hwtstamp()
4466 skb_queue_purge(&ptp_priv->tx_queue); in lan8841_hwtstamp()
4487 if (ptp_priv->rx_filter == HWTSTAMP_FILTER_NONE || in lan8841_rxtstamp()
4491 if ((type & ptp_priv->version) == 0 || (type & ptp_priv->layer) == 0) in lan8841_rxtstamp()
4494 spin_lock_irqsave(&ptp_priv->seconds_lock, flags); in lan8841_rxtstamp()
4495 ts.tv_sec = ptp_priv->seconds; in lan8841_rxtstamp()
4496 spin_unlock_irqrestore(&ptp_priv->seconds_lock, flags); in lan8841_rxtstamp()
4497 ts_header = __be32_to_cpu(header->reserved2); in lan8841_rxtstamp()
4504 ts.tv_sec -= GENMASK(1, 0) + 1; in lan8841_rxtstamp()
4508 shhwtstamps->hwtstamp = in lan8841_rxtstamp()
4511 header->reserved2 = 0; in lan8841_rxtstamp()
4528 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_set_target()
4556 ts->tv_sec + LAN8841_BUFFER_TIME, 0); in lan8841_ptp_update_target()
4567 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_set_reload()
4601 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_settime64()
4606 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_settime64()
4607 phy_write_mmd(phydev, 2, LAN8841_PTP_LTC_SET_SEC_LO, lower_16_bits(ts->tv_sec)); in lan8841_ptp_settime64()
4608 phy_write_mmd(phydev, 2, LAN8841_PTP_LTC_SET_SEC_MID, upper_16_bits(ts->tv_sec)); in lan8841_ptp_settime64()
4609 phy_write_mmd(phydev, 2, LAN8841_PTP_LTC_SET_SEC_HI, upper_32_bits(ts->tv_sec) & 0xffff); in lan8841_ptp_settime64()
4610 phy_write_mmd(phydev, 2, LAN8841_PTP_LTC_SET_NS_LO, lower_16_bits(ts->tv_nsec)); in lan8841_ptp_settime64()
4611 phy_write_mmd(phydev, 2, LAN8841_PTP_LTC_SET_NS_HI, upper_16_bits(ts->tv_nsec) & 0x3fff); in lan8841_ptp_settime64()
4617 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_settime64()
4619 spin_lock_irqsave(&ptp_priv->seconds_lock, flags); in lan8841_ptp_settime64()
4620 ptp_priv->seconds = ts->tv_sec; in lan8841_ptp_settime64()
4621 spin_unlock_irqrestore(&ptp_priv->seconds_lock, flags); in lan8841_ptp_settime64()
4638 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_gettime64()
4642 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_gettime64()
4657 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_gettime64()
4668 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_getseconds()
4671 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_getseconds()
4682 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_getseconds()
4697 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_adjtime()
4710 if (delta > 10000000000LL || delta < -10000000000LL) { in lan8841_ptp_adjtime()
4714 ptp->gettime64(ptp, &ts); in lan8841_ptp_adjtime()
4719 ptp->settime64(ptp, &ts); in lan8841_ptp_adjtime()
4723 sec = div_u64_rem(delta < 0 ? -delta : delta, NSEC_PER_SEC, &nsec); in lan8841_ptp_adjtime()
4729 sec--; in lan8841_ptp_adjtime()
4730 nsec = NSEC_PER_SEC - nsec; in lan8841_ptp_adjtime()
4744 nsec -= NSEC_PER_SEC; in lan8841_ptp_adjtime()
4747 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_adjtime()
4764 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_adjtime()
4767 ptp->gettime64(ptp, &ts); in lan8841_ptp_adjtime()
4768 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_adjtime()
4770 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_adjtime()
4783 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_adjfine()
4791 scaled_ppm = -scaled_ppm; in lan8841_ptp_adjfine()
4798 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_adjfine()
4803 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_adjfine()
4817 return -1; in lan8841_ptp_verify()
4830 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_perout_off()
4846 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_perout_on()
4876 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_remove_event()
4881 * pins 0-4 while GPIO_DATA_SEL2 contains GPIO pins 5-9, therefore in lan8841_ptp_remove_event()
4888 tmp = LAN8841_GPIO_DATA_SEL_GPIO_DATA_SEL_EVENT_MASK << (3 * (pin - 5)); in lan8841_ptp_remove_event()
4907 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_enable_event()
4928 * pins 0-4 while GPIO_DATA_SEL2 contains GPIO pins 5-9, therefore in lan8841_ptp_enable_event()
4941 tmp << (3 * (pin - 5))); in lan8841_ptp_enable_event()
4966 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_perout()
4973 if (rq->perout.flags & ~PTP_PEROUT_DUTY_CYCLE) in lan8841_ptp_perout()
4974 return -EOPNOTSUPP; in lan8841_ptp_perout()
4976 pin = ptp_find_pin(ptp_priv->ptp_clock, PTP_PF_PEROUT, rq->perout.index); in lan8841_ptp_perout()
4977 if (pin == -1 || pin >= LAN8841_PTP_GPIO_NUM) in lan8841_ptp_perout()
4978 return -EINVAL; in lan8841_ptp_perout()
4988 ts_on.tv_sec = rq->perout.on.sec; in lan8841_ptp_perout()
4989 ts_on.tv_nsec = rq->perout.on.nsec; in lan8841_ptp_perout()
4992 ts_period.tv_sec = rq->perout.period.sec; in lan8841_ptp_perout()
4993 ts_period.tv_nsec = rq->perout.period.nsec; in lan8841_ptp_perout()
4999 return -EOPNOTSUPP; in lan8841_ptp_perout()
5005 return -EINVAL; in lan8841_ptp_perout()
5058 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_perout()
5059 ret = lan8841_ptp_set_target(ptp_priv, LAN8841_EVENT_A, rq->perout.start.sec, in lan8841_ptp_perout()
5060 rq->perout.start.nsec); in lan8841_ptp_perout()
5061 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_perout()
5065 ret = lan8841_ptp_set_reload(ptp_priv, LAN8841_EVENT_A, rq->perout.period.sec, in lan8841_ptp_perout()
5066 rq->perout.period.nsec); in lan8841_ptp_perout()
5090 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_extts_on()
5120 struct phy_device *phydev = ptp_priv->phydev; in lan8841_ptp_extts_off()
5155 if (rq->extts.flags & ~(PTP_ENABLE_FEATURE | in lan8841_ptp_extts()
5158 return -EOPNOTSUPP; in lan8841_ptp_extts()
5160 pin = ptp_find_pin(ptp_priv->ptp_clock, PTP_PF_EXTTS, rq->extts.index); in lan8841_ptp_extts()
5161 if (pin == -1 || pin >= LAN8841_PTP_GPIO_NUM) in lan8841_ptp_extts()
5162 return -EINVAL; in lan8841_ptp_extts()
5164 mutex_lock(&ptp_priv->ptp_lock); in lan8841_ptp_extts()
5166 ret = lan8841_ptp_extts_on(ptp_priv, pin, rq->extts.flags); in lan8841_ptp_extts()
5169 mutex_unlock(&ptp_priv->ptp_lock); in lan8841_ptp_extts()
5177 switch (rq->type) { in lan8841_ptp_enable()
5183 return -EOPNOTSUPP; in lan8841_ptp_enable()
5196 lan8841_ptp_getseconds(&ptp_priv->ptp_clock_info, &ts); in lan8841_ptp_do_aux_work()
5198 spin_lock_irqsave(&ptp_priv->seconds_lock, flags); in lan8841_ptp_do_aux_work()
5199 ptp_priv->seconds = ts.tv_sec; in lan8841_ptp_do_aux_work()
5200 spin_unlock_irqrestore(&ptp_priv->seconds_lock, flags); in lan8841_ptp_do_aux_work()
5237 phydev->interface = PHY_INTERFACE_MODE_RGMII_RXID; in lan8841_probe()
5243 priv = phydev->priv; in lan8841_probe()
5244 ptp_priv = &priv->ptp_priv; in lan8841_probe()
5246 ptp_priv->pin_config = devm_kcalloc(&phydev->mdio.dev, in lan8841_probe()
5248 sizeof(*ptp_priv->pin_config), in lan8841_probe()
5250 if (!ptp_priv->pin_config) in lan8841_probe()
5251 return -ENOMEM; in lan8841_probe()
5254 struct ptp_pin_desc *p = &ptp_priv->pin_config[i]; in lan8841_probe()
5256 snprintf(p->name, sizeof(p->name), "pin%d", i); in lan8841_probe()
5257 p->index = i; in lan8841_probe()
5258 p->func = PTP_PF_NONE; in lan8841_probe()
5261 ptp_priv->ptp_clock_info = lan8841_ptp_clock_info; in lan8841_probe()
5262 ptp_priv->ptp_clock_info.pin_config = ptp_priv->pin_config; in lan8841_probe()
5263 ptp_priv->ptp_clock = ptp_clock_register(&ptp_priv->ptp_clock_info, in lan8841_probe()
5264 &phydev->mdio.dev); in lan8841_probe()
5265 if (IS_ERR(ptp_priv->ptp_clock)) { in lan8841_probe()
5267 PTR_ERR(ptp_priv->ptp_clock)); in lan8841_probe()
5268 return -EINVAL; in lan8841_probe()
5271 if (!ptp_priv->ptp_clock) in lan8841_probe()
5275 skb_queue_head_init(&ptp_priv->tx_queue); in lan8841_probe()
5276 ptp_priv->phydev = phydev; in lan8841_probe()
5277 mutex_init(&ptp_priv->ptp_lock); in lan8841_probe()
5278 spin_lock_init(&ptp_priv->seconds_lock); in lan8841_probe()
5280 ptp_priv->mii_ts.rxtstamp = lan8841_rxtstamp; in lan8841_probe()
5281 ptp_priv->mii_ts.txtstamp = lan8814_txtstamp; in lan8841_probe()
5282 ptp_priv->mii_ts.hwtstamp = lan8841_hwtstamp; in lan8841_probe()
5283 ptp_priv->mii_ts.ts_info = lan8841_ts_info; in lan8841_probe()
5285 phydev->mii_ts = &ptp_priv->mii_ts; in lan8841_probe()
5288 phydev->default_timestamp = true; in lan8841_probe()
5295 struct kszphy_priv *priv = phydev->priv; in lan8841_suspend()
5296 struct kszphy_ptp_priv *ptp_priv = &priv->ptp_priv; in lan8841_suspend()
5298 if (ptp_priv->ptp_clock) in lan8841_suspend()
5299 ptp_cancel_worker_sync(ptp_priv->ptp_clock); in lan8841_suspend()