Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'dpaa2-mac-protocol-change'

Ioana Ciornei says:

====================
dpaa2-mac: add support for changing the protocol at runtime

This patch set adds support for changing the Ethernet protocol at
runtime on Layerscape SoCs which have the Lynx 28G SerDes block.

The first two patches add a new generic PHY driver for the Lynx 28G and
the bindings file associated. The driver reads the PLL configuration at
probe time (the frequency provided to the lanes) and determines what
protocols can be supported.
Based on this the driver can deny or approve a request from the
dpaa2-mac to setup a new protocol.

The next 2 patches add some MC APIs for inquiring what is the running
version of firmware and setting up a new protocol on the MAC.

Moving along, we extract the code for setting up the supported
interfaces on a MAC on a different function since in the next patches
will update the logic.

In the next patch, the dpaa2-mac is updated so that it retrieves the
SerDes PHY based on the OF node and in case of a major reconfig, call
the PHY driver to set up the new protocol on the associated lane and the
MC firmware to reconfigure the MAC side of things.

Finally, the LX2160A dtsi is annotated with the SerDes PHY nodes for the
1st SerDes block. Beside this, the LX2160A Clearfog dtsi is annotated
with the 'phys' property for the exposed SFP cages.

Changes in v2:
- 1/8: add MODULE_LICENSE
Changes in v3:
- 2/8: fix 'make dt_binding_check' errors
- 7/8: reverse order of dpaa2_mac_start() and phylink_start()
- 7/8: treat all RGMII variants in dpmac_eth_if_mode
- 7/8: remove the .mac_prepare callback
- 7/8: ignore PHY_INTERFACE_MODE_NA in validate
Changes in v4:
- 1/8: remove the DT nodes parsing
- 1/8: add an xlate function
- 2/8: remove the children phy nodes for each lane
- 7/8: rework the of_phy_get if statement
- 8/8: remove the DT nodes for each lane and the lane id in the
phys phandle
Changes in v5:
- 2/8: use phy as the name of the DT node in the example
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+919 -21
+40
Documentation/devicetree/bindings/phy/fsl,lynx-28g.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/phy/fsl,lynx-28g.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Freescale Lynx 28G SerDes PHY binding 8 + 9 + maintainers: 10 + - Ioana Ciornei <ioana.ciornei@nxp.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - fsl,lynx-28g 16 + 17 + reg: 18 + maxItems: 1 19 + 20 + "#phy-cells": 21 + const: 1 22 + 23 + required: 24 + - compatible 25 + - reg 26 + - "#phy-cells" 27 + 28 + additionalProperties: false 29 + 30 + examples: 31 + - | 32 + soc { 33 + #address-cells = <2>; 34 + #size-cells = <2>; 35 + serdes_1: phy@1ea0000 { 36 + compatible = "fsl,lynx-28g"; 37 + reg = <0x0 0x1ea0000 0x0 0x1e30>; 38 + #phy-cells = <1>; 39 + }; 40 + };
+7
MAINTAINERS
··· 11333 11333 W: http://linux-test-project.github.io/ 11334 11334 T: git git://github.com/linux-test-project/ltp.git 11335 11335 11336 + LYNX 28G SERDES PHY DRIVER 11337 + M: Ioana Ciornei <ioana.ciornei@nxp.com> 11338 + L: netdev@vger.kernel.org 11339 + S: Supported 11340 + F: Documentation/devicetree/bindings/phy/fsl,lynx-28g.yaml 11341 + F: drivers/phy/freescale/phy-fsl-lynx-28g.c 11342 + 11336 11343 LYNX PCS MODULE 11337 11344 M: Ioana Ciornei <ioana.ciornei@nxp.com> 11338 11345 L: netdev@vger.kernel.org
+4
arch/arm64/boot/dts/freescale/fsl-lx2160a-clearfog-itx.dtsi
··· 63 63 &dpmac7 { 64 64 sfp = <&sfp0>; 65 65 managed = "in-band-status"; 66 + phys = <&serdes_1 3>; 66 67 }; 67 68 68 69 &dpmac8 { 69 70 sfp = <&sfp1>; 70 71 managed = "in-band-status"; 72 + phys = <&serdes_1 2>; 71 73 }; 72 74 73 75 &dpmac9 { 74 76 sfp = <&sfp2>; 75 77 managed = "in-band-status"; 78 + phys = <&serdes_1 1>; 76 79 }; 77 80 78 81 &dpmac10 { 79 82 sfp = <&sfp3>; 80 83 managed = "in-band-status"; 84 + phys = <&serdes_1 0>; 81 85 }; 82 86 83 87 &emdio2 {
+6
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi
··· 612 612 ranges; 613 613 dma-ranges = <0x0 0x0 0x0 0x0 0x10000 0x00000000>; 614 614 615 + serdes_1: phy@1ea0000 { 616 + compatible = "fsl,lynx-28g"; 617 + reg = <0x0 0x1ea0000 0x0 0x1e30>; 618 + #phy-cells = <1>; 619 + }; 620 + 615 621 crypto: crypto@8000000 { 616 622 compatible = "fsl,sec-v5.0", "fsl,sec-v4.0"; 617 623 fsl,sec-era = <10>;
+4 -1
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
··· 2077 2077 goto enable_err; 2078 2078 } 2079 2079 2080 - if (dpaa2_eth_is_type_phy(priv)) 2080 + if (dpaa2_eth_is_type_phy(priv)) { 2081 + dpaa2_mac_start(priv->mac); 2081 2082 phylink_start(priv->mac->phylink); 2083 + } 2082 2084 2083 2085 return 0; 2084 2086 ··· 2155 2153 2156 2154 if (dpaa2_eth_is_type_phy(priv)) { 2157 2155 phylink_stop(priv->mac->phylink); 2156 + dpaa2_mac_stop(priv->mac); 2158 2157 } else { 2159 2158 netif_tx_stop_all_queues(net_dev); 2160 2159 netif_carrier_off(net_dev);
+140 -19
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c
··· 3 3 4 4 #include <linux/acpi.h> 5 5 #include <linux/pcs-lynx.h> 6 + #include <linux/phy/phy.h> 6 7 #include <linux/property.h> 7 8 8 9 #include "dpaa2-eth.h" ··· 11 10 12 11 #define phylink_to_dpaa2_mac(config) \ 13 12 container_of((config), struct dpaa2_mac, phylink_config) 13 + 14 + #define DPMAC_PROTOCOL_CHANGE_VER_MAJOR 4 15 + #define DPMAC_PROTOCOL_CHANGE_VER_MINOR 8 16 + 17 + #define DPAA2_MAC_FEATURE_PROTOCOL_CHANGE BIT(0) 18 + 19 + static int dpaa2_mac_cmp_ver(struct dpaa2_mac *mac, 20 + u16 ver_major, u16 ver_minor) 21 + { 22 + if (mac->ver_major == ver_major) 23 + return mac->ver_minor - ver_minor; 24 + return mac->ver_major - ver_major; 25 + } 26 + 27 + static void dpaa2_mac_detect_features(struct dpaa2_mac *mac) 28 + { 29 + mac->features = 0; 30 + 31 + if (dpaa2_mac_cmp_ver(mac, DPMAC_PROTOCOL_CHANGE_VER_MAJOR, 32 + DPMAC_PROTOCOL_CHANGE_VER_MINOR) >= 0) 33 + mac->features |= DPAA2_MAC_FEATURE_PROTOCOL_CHANGE; 34 + } 14 35 15 36 static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode) 16 37 { ··· 59 36 } 60 37 61 38 return 0; 39 + } 40 + 41 + static enum dpmac_eth_if dpmac_eth_if_mode(phy_interface_t if_mode) 42 + { 43 + switch (if_mode) { 44 + case PHY_INTERFACE_MODE_RGMII: 45 + case PHY_INTERFACE_MODE_RGMII_ID: 46 + case PHY_INTERFACE_MODE_RGMII_RXID: 47 + case PHY_INTERFACE_MODE_RGMII_TXID: 48 + return DPMAC_ETH_IF_RGMII; 49 + case PHY_INTERFACE_MODE_USXGMII: 50 + return DPMAC_ETH_IF_USXGMII; 51 + case PHY_INTERFACE_MODE_QSGMII: 52 + return DPMAC_ETH_IF_QSGMII; 53 + case PHY_INTERFACE_MODE_SGMII: 54 + return DPMAC_ETH_IF_SGMII; 55 + case PHY_INTERFACE_MODE_10GBASER: 56 + return DPMAC_ETH_IF_XFI; 57 + case PHY_INTERFACE_MODE_1000BASEX: 58 + return DPMAC_ETH_IF_1000BASEX; 59 + default: 60 + return DPMAC_ETH_IF_MII; 61 + } 62 62 } 63 63 64 64 static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev, ··· 171 125 if (err) 172 126 netdev_err(mac->net_dev, "%s: dpmac_set_link_state() = %d\n", 173 127 __func__, err); 128 + 129 + if (!mac->serdes_phy) 130 + return; 131 + 132 + /* This happens only if we support changing of protocol at runtime */ 133 + err = dpmac_set_protocol(mac->mc_io, 0, mac->mc_dev->mc_handle, 134 + dpmac_eth_if_mode(state->interface)); 135 + if (err) 136 + netdev_err(mac->net_dev, "dpmac_set_protocol() = %d\n", err); 137 + 138 + err = phy_set_mode_ext(mac->serdes_phy, PHY_MODE_ETHERNET, state->interface); 139 + if (err) 140 + netdev_err(mac->net_dev, "phy_set_mode_ext() = %d\n", err); 174 141 } 175 142 176 143 static void dpaa2_mac_link_up(struct phylink_config *config, ··· 294 235 } 295 236 } 296 237 238 + static void dpaa2_mac_set_supported_interfaces(struct dpaa2_mac *mac) 239 + { 240 + int intf, err; 241 + 242 + /* We support the current interface mode, and if we have a PCS 243 + * similar interface modes that do not require the SerDes lane to be 244 + * reconfigured. 245 + */ 246 + __set_bit(mac->if_mode, mac->phylink_config.supported_interfaces); 247 + if (mac->pcs) { 248 + switch (mac->if_mode) { 249 + case PHY_INTERFACE_MODE_1000BASEX: 250 + case PHY_INTERFACE_MODE_SGMII: 251 + __set_bit(PHY_INTERFACE_MODE_1000BASEX, 252 + mac->phylink_config.supported_interfaces); 253 + __set_bit(PHY_INTERFACE_MODE_SGMII, 254 + mac->phylink_config.supported_interfaces); 255 + break; 256 + 257 + default: 258 + break; 259 + } 260 + } 261 + 262 + if (!mac->serdes_phy) 263 + return; 264 + 265 + /* In case we have access to the SerDes phy/lane, then ask the SerDes 266 + * driver what interfaces are supported based on the current PLL 267 + * configuration. 268 + */ 269 + for (intf = 0; intf < PHY_INTERFACE_MODE_MAX; intf++) { 270 + if (intf == PHY_INTERFACE_MODE_NA) 271 + continue; 272 + 273 + err = phy_validate(mac->serdes_phy, PHY_MODE_ETHERNET, intf, NULL); 274 + if (err) 275 + continue; 276 + 277 + __set_bit(intf, mac->phylink_config.supported_interfaces); 278 + } 279 + } 280 + 281 + void dpaa2_mac_start(struct dpaa2_mac *mac) 282 + { 283 + if (mac->serdes_phy) 284 + phy_power_on(mac->serdes_phy); 285 + } 286 + 287 + void dpaa2_mac_stop(struct dpaa2_mac *mac) 288 + { 289 + if (mac->serdes_phy) 290 + phy_power_off(mac->serdes_phy); 291 + } 292 + 297 293 int dpaa2_mac_connect(struct dpaa2_mac *mac) 298 294 { 299 295 struct net_device *net_dev = mac->net_dev; 300 296 struct fwnode_handle *dpmac_node; 297 + struct phy *serdes_phy = NULL; 301 298 struct phylink *phylink; 302 299 int err; 303 300 ··· 369 254 if (err < 0) 370 255 return -EINVAL; 371 256 mac->if_mode = err; 257 + 258 + if (mac->features & DPAA2_MAC_FEATURE_PROTOCOL_CHANGE && 259 + !phy_interface_mode_is_rgmii(mac->if_mode) && 260 + is_of_node(dpmac_node)) { 261 + serdes_phy = of_phy_get(to_of_node(dpmac_node), NULL); 262 + 263 + if (serdes_phy == ERR_PTR(-ENODEV)) 264 + serdes_phy = NULL; 265 + else if (IS_ERR(serdes_phy)) 266 + return PTR_ERR(serdes_phy); 267 + else 268 + phy_init(serdes_phy); 269 + } 270 + mac->serdes_phy = serdes_phy; 372 271 373 272 /* The MAC does not have the capability to add RGMII delays so 374 273 * error out if the interface mode requests them and there is no PHY ··· 412 283 MAC_10FD | MAC_100FD | MAC_1000FD | MAC_2500FD | MAC_5000FD | 413 284 MAC_10000FD; 414 285 415 - /* We support the current interface mode, and if we have a PCS 416 - * similar interface modes that do not require the PLLs to be 417 - * reconfigured. 418 - */ 419 - __set_bit(mac->if_mode, mac->phylink_config.supported_interfaces); 420 - if (mac->pcs) { 421 - switch (mac->if_mode) { 422 - case PHY_INTERFACE_MODE_1000BASEX: 423 - case PHY_INTERFACE_MODE_SGMII: 424 - __set_bit(PHY_INTERFACE_MODE_1000BASEX, 425 - mac->phylink_config.supported_interfaces); 426 - __set_bit(PHY_INTERFACE_MODE_SGMII, 427 - mac->phylink_config.supported_interfaces); 428 - break; 429 - 430 - default: 431 - break; 432 - } 433 - } 286 + dpaa2_mac_set_supported_interfaces(mac); 434 287 435 288 phylink = phylink_create(&mac->phylink_config, 436 289 dpmac_node, mac->if_mode, ··· 447 336 phylink_disconnect_phy(mac->phylink); 448 337 phylink_destroy(mac->phylink); 449 338 dpaa2_pcs_destroy(mac); 339 + of_phy_put(mac->serdes_phy); 340 + mac->serdes_phy = NULL; 450 341 } 451 342 452 343 int dpaa2_mac_open(struct dpaa2_mac *mac) ··· 471 358 netdev_err(net_dev, "dpmac_get_attributes() = %d\n", err); 472 359 goto err_close_dpmac; 473 360 } 361 + 362 + err = dpmac_get_api_version(mac->mc_io, 0, &mac->ver_major, &mac->ver_minor); 363 + if (err) { 364 + netdev_err(net_dev, "dpmac_get_api_version() = %d\n", err); 365 + goto err_close_dpmac; 366 + } 367 + 368 + dpaa2_mac_detect_features(mac); 474 369 475 370 /* Find the device node representing the MAC device and link the device 476 371 * behind the associated netdev to it.
+8
drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h
··· 17 17 struct net_device *net_dev; 18 18 struct fsl_mc_io *mc_io; 19 19 struct dpmac_attr attr; 20 + u16 ver_major, ver_minor; 21 + unsigned long features; 20 22 21 23 struct phylink_config phylink_config; 22 24 struct phylink *phylink; ··· 26 24 enum dpmac_link_type if_link_type; 27 25 struct phylink_pcs *pcs; 28 26 struct fwnode_handle *fw_node; 27 + 28 + struct phy *serdes_phy; 29 29 }; 30 30 31 31 bool dpaa2_mac_is_type_fixed(struct fsl_mc_device *dpmac_dev, ··· 46 42 void dpaa2_mac_get_strings(u8 *data); 47 43 48 44 void dpaa2_mac_get_ethtool_stats(struct dpaa2_mac *mac, u64 *data); 45 + 46 + void dpaa2_mac_start(struct dpaa2_mac *mac); 47 + 48 + void dpaa2_mac_stop(struct dpaa2_mac *mac); 49 49 50 50 #endif /* DPAA2_MAC_H */
+4 -1
drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c
··· 703 703 704 704 dpaa2_switch_enable_ctrl_if_napi(ethsw); 705 705 706 - if (dpaa2_switch_port_is_type_phy(port_priv)) 706 + if (dpaa2_switch_port_is_type_phy(port_priv)) { 707 + dpaa2_mac_start(port_priv->mac); 707 708 phylink_start(port_priv->mac->phylink); 709 + } 708 710 709 711 return 0; 710 712 } ··· 719 717 720 718 if (dpaa2_switch_port_is_type_phy(port_priv)) { 721 719 phylink_stop(port_priv->mac->phylink); 720 + dpaa2_mac_stop(port_priv->mac); 722 721 } else { 723 722 netif_tx_stop_all_queues(netdev); 724 723 netif_carrier_off(netdev);
+12
drivers/net/ethernet/freescale/dpaa2/dpmac-cmd.h
··· 19 19 #define DPMAC_CMDID_CLOSE DPMAC_CMD(0x800) 20 20 #define DPMAC_CMDID_OPEN DPMAC_CMD(0x80c) 21 21 22 + #define DPMAC_CMDID_GET_API_VERSION DPMAC_CMD(0xa0c) 23 + 22 24 #define DPMAC_CMDID_GET_ATTR DPMAC_CMD(0x004) 23 25 #define DPMAC_CMDID_SET_LINK_STATE DPMAC_CMD_V2(0x0c3) 24 26 25 27 #define DPMAC_CMDID_GET_COUNTER DPMAC_CMD(0x0c4) 28 + 29 + #define DPMAC_CMDID_SET_PROTOCOL DPMAC_CMD(0x0c7) 26 30 27 31 /* Macros for accessing command fields smaller than 1byte */ 28 32 #define DPMAC_MASK(field) \ ··· 74 70 __le64 counter; 75 71 }; 76 72 73 + struct dpmac_rsp_get_api_version { 74 + __le16 major; 75 + __le16 minor; 76 + }; 77 + 78 + struct dpmac_cmd_set_protocol { 79 + u8 eth_if; 80 + }; 77 81 #endif /* _FSL_DPMAC_CMD_H */
+54
drivers/net/ethernet/freescale/dpaa2/dpmac.c
··· 181 181 182 182 return 0; 183 183 } 184 + 185 + /** 186 + * dpmac_get_api_version() - Get Data Path MAC version 187 + * @mc_io: Pointer to MC portal's I/O object 188 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 189 + * @major_ver: Major version of data path mac API 190 + * @minor_ver: Minor version of data path mac API 191 + * 192 + * Return: '0' on Success; Error code otherwise. 193 + */ 194 + int dpmac_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags, 195 + u16 *major_ver, u16 *minor_ver) 196 + { 197 + struct dpmac_rsp_get_api_version *rsp_params; 198 + struct fsl_mc_command cmd = { 0 }; 199 + int err; 200 + 201 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_API_VERSION, 202 + cmd_flags, 203 + 0); 204 + 205 + err = mc_send_command(mc_io, &cmd); 206 + if (err) 207 + return err; 208 + 209 + rsp_params = (struct dpmac_rsp_get_api_version *)cmd.params; 210 + *major_ver = le16_to_cpu(rsp_params->major); 211 + *minor_ver = le16_to_cpu(rsp_params->minor); 212 + 213 + return 0; 214 + } 215 + 216 + /** 217 + * dpmac_set_protocol() - Reconfigure the DPMAC protocol 218 + * @mc_io: Pointer to opaque I/O object 219 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 220 + * @token: Token of DPMAC object 221 + * @protocol: New protocol for the DPMAC to be reconfigured in. 222 + * 223 + * Return: '0' on Success; Error code otherwise. 224 + */ 225 + int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, 226 + enum dpmac_eth_if protocol) 227 + { 228 + struct dpmac_cmd_set_protocol *cmd_params; 229 + struct fsl_mc_command cmd = { 0 }; 230 + 231 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_PROTOCOL, 232 + cmd_flags, token); 233 + cmd_params = (struct dpmac_cmd_set_protocol *)cmd.params; 234 + cmd_params->eth_if = protocol; 235 + 236 + return mc_send_command(mc_io, &cmd); 237 + }
+5
drivers/net/ethernet/freescale/dpaa2/dpmac.h
··· 205 205 int dpmac_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, 206 206 enum dpmac_counter_id id, u64 *value); 207 207 208 + int dpmac_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags, 209 + u16 *major_ver, u16 *minor_ver); 210 + 211 + int dpmac_set_protocol(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, 212 + enum dpmac_eth_if protocol); 208 213 #endif /* __FSL_DPMAC_H */
+10
drivers/phy/freescale/Kconfig
··· 22 22 help 23 23 Enable this to add support for the PCIE PHY as found on 24 24 i.MX8M family of SOCs. 25 + 26 + config PHY_FSL_LYNX_28G 27 + tristate "Freescale Layerscape Lynx 28G SerDes PHY support" 28 + depends on OF 29 + select GENERIC_PHY 30 + help 31 + Enable this to add support for the Lynx SerDes 28G PHY as 32 + found on NXP's Layerscape platforms such as LX2160A. 33 + Used to change the protocol running on SerDes lanes at runtime. 34 + Only useful for a restricted set of Ethernet protocols.
+1
drivers/phy/freescale/Makefile
··· 2 2 obj-$(CONFIG_PHY_FSL_IMX8MQ_USB) += phy-fsl-imx8mq-usb.o 3 3 obj-$(CONFIG_PHY_MIXEL_MIPI_DPHY) += phy-fsl-imx8-mipi-dphy.o 4 4 obj-$(CONFIG_PHY_FSL_IMX8M_PCIE) += phy-fsl-imx8m-pcie.o 5 + obj-$(CONFIG_PHY_FSL_LYNX_28G) += phy-fsl-lynx-28g.o
+624
drivers/phy/freescale/phy-fsl-lynx-28g.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* Copyright (c) 2021-2022 NXP. */ 3 + 4 + #include <linux/module.h> 5 + #include <linux/phy.h> 6 + #include <linux/phy/phy.h> 7 + #include <linux/platform_device.h> 8 + #include <linux/workqueue.h> 9 + #include <linux/workqueue.h> 10 + 11 + #define LYNX_28G_NUM_LANE 8 12 + #define LYNX_28G_NUM_PLL 2 13 + 14 + /* General registers per SerDes block */ 15 + #define LYNX_28G_PCC8 0x10a0 16 + #define LYNX_28G_PCC8_SGMII 0x1 17 + #define LYNX_28G_PCC8_SGMII_DIS 0x0 18 + 19 + #define LYNX_28G_PCCC 0x10b0 20 + #define LYNX_28G_PCCC_10GBASER 0x9 21 + #define LYNX_28G_PCCC_USXGMII 0x1 22 + #define LYNX_28G_PCCC_SXGMII_DIS 0x0 23 + 24 + #define LYNX_28G_LNa_PCC_OFFSET(lane) (4 * (LYNX_28G_NUM_LANE - (lane->id) - 1)) 25 + 26 + /* Per PLL registers */ 27 + #define LYNX_28G_PLLnRSTCTL(pll) (0x400 + (pll) * 0x100 + 0x0) 28 + #define LYNX_28G_PLLnRSTCTL_DIS(rstctl) (((rstctl) & BIT(24)) >> 24) 29 + #define LYNX_28G_PLLnRSTCTL_LOCK(rstctl) (((rstctl) & BIT(23)) >> 23) 30 + 31 + #define LYNX_28G_PLLnCR0(pll) (0x400 + (pll) * 0x100 + 0x4) 32 + #define LYNX_28G_PLLnCR0_REFCLK_SEL(cr0) (((cr0) & GENMASK(20, 16))) 33 + #define LYNX_28G_PLLnCR0_REFCLK_SEL_100MHZ 0x0 34 + #define LYNX_28G_PLLnCR0_REFCLK_SEL_125MHZ 0x10000 35 + #define LYNX_28G_PLLnCR0_REFCLK_SEL_156MHZ 0x20000 36 + #define LYNX_28G_PLLnCR0_REFCLK_SEL_150MHZ 0x30000 37 + #define LYNX_28G_PLLnCR0_REFCLK_SEL_161MHZ 0x40000 38 + 39 + #define LYNX_28G_PLLnCR1(pll) (0x400 + (pll) * 0x100 + 0x8) 40 + #define LYNX_28G_PLLnCR1_FRATE_SEL(cr1) (((cr1) & GENMASK(28, 24))) 41 + #define LYNX_28G_PLLnCR1_FRATE_5G_10GVCO 0x0 42 + #define LYNX_28G_PLLnCR1_FRATE_5G_25GVCO 0x10000000 43 + #define LYNX_28G_PLLnCR1_FRATE_10G_20GVCO 0x6000000 44 + 45 + /* Per SerDes lane registers */ 46 + /* Lane a General Control Register */ 47 + #define LYNX_28G_LNaGCR0(lane) (0x800 + (lane) * 0x100 + 0x0) 48 + #define LYNX_28G_LNaGCR0_PROTO_SEL_MSK GENMASK(7, 3) 49 + #define LYNX_28G_LNaGCR0_PROTO_SEL_SGMII 0x8 50 + #define LYNX_28G_LNaGCR0_PROTO_SEL_XFI 0x50 51 + #define LYNX_28G_LNaGCR0_IF_WIDTH_MSK GENMASK(2, 0) 52 + #define LYNX_28G_LNaGCR0_IF_WIDTH_10_BIT 0x0 53 + #define LYNX_28G_LNaGCR0_IF_WIDTH_20_BIT 0x2 54 + 55 + /* Lane a Tx Reset Control Register */ 56 + #define LYNX_28G_LNaTRSTCTL(lane) (0x800 + (lane) * 0x100 + 0x20) 57 + #define LYNX_28G_LNaTRSTCTL_HLT_REQ BIT(27) 58 + #define LYNX_28G_LNaTRSTCTL_RST_DONE BIT(30) 59 + #define LYNX_28G_LNaTRSTCTL_RST_REQ BIT(31) 60 + 61 + /* Lane a Tx General Control Register */ 62 + #define LYNX_28G_LNaTGCR0(lane) (0x800 + (lane) * 0x100 + 0x24) 63 + #define LYNX_28G_LNaTGCR0_USE_PLLF 0x0 64 + #define LYNX_28G_LNaTGCR0_USE_PLLS BIT(28) 65 + #define LYNX_28G_LNaTGCR0_USE_PLL_MSK BIT(28) 66 + #define LYNX_28G_LNaTGCR0_N_RATE_FULL 0x0 67 + #define LYNX_28G_LNaTGCR0_N_RATE_HALF 0x1000000 68 + #define LYNX_28G_LNaTGCR0_N_RATE_QUARTER 0x2000000 69 + #define LYNX_28G_LNaTGCR0_N_RATE_MSK GENMASK(26, 24) 70 + 71 + #define LYNX_28G_LNaTECR0(lane) (0x800 + (lane) * 0x100 + 0x30) 72 + 73 + /* Lane a Rx Reset Control Register */ 74 + #define LYNX_28G_LNaRRSTCTL(lane) (0x800 + (lane) * 0x100 + 0x40) 75 + #define LYNX_28G_LNaRRSTCTL_HLT_REQ BIT(27) 76 + #define LYNX_28G_LNaRRSTCTL_RST_DONE BIT(30) 77 + #define LYNX_28G_LNaRRSTCTL_RST_REQ BIT(31) 78 + #define LYNX_28G_LNaRRSTCTL_CDR_LOCK BIT(12) 79 + 80 + /* Lane a Rx General Control Register */ 81 + #define LYNX_28G_LNaRGCR0(lane) (0x800 + (lane) * 0x100 + 0x44) 82 + #define LYNX_28G_LNaRGCR0_USE_PLLF 0x0 83 + #define LYNX_28G_LNaRGCR0_USE_PLLS BIT(28) 84 + #define LYNX_28G_LNaRGCR0_USE_PLL_MSK BIT(28) 85 + #define LYNX_28G_LNaRGCR0_N_RATE_MSK GENMASK(26, 24) 86 + #define LYNX_28G_LNaRGCR0_N_RATE_FULL 0x0 87 + #define LYNX_28G_LNaRGCR0_N_RATE_HALF 0x1000000 88 + #define LYNX_28G_LNaRGCR0_N_RATE_QUARTER 0x2000000 89 + #define LYNX_28G_LNaRGCR0_N_RATE_MSK GENMASK(26, 24) 90 + 91 + #define LYNX_28G_LNaRGCR1(lane) (0x800 + (lane) * 0x100 + 0x48) 92 + 93 + #define LYNX_28G_LNaRECR0(lane) (0x800 + (lane) * 0x100 + 0x50) 94 + #define LYNX_28G_LNaRECR1(lane) (0x800 + (lane) * 0x100 + 0x54) 95 + #define LYNX_28G_LNaRECR2(lane) (0x800 + (lane) * 0x100 + 0x58) 96 + 97 + #define LYNX_28G_LNaRSCCR0(lane) (0x800 + (lane) * 0x100 + 0x74) 98 + 99 + #define LYNX_28G_LNaPSS(lane) (0x1000 + (lane) * 0x4) 100 + #define LYNX_28G_LNaPSS_TYPE(pss) (((pss) & GENMASK(30, 24)) >> 24) 101 + #define LYNX_28G_LNaPSS_TYPE_SGMII 0x4 102 + #define LYNX_28G_LNaPSS_TYPE_XFI 0x28 103 + 104 + #define LYNX_28G_SGMIIaCR1(lane) (0x1804 + (lane) * 0x10) 105 + #define LYNX_28G_SGMIIaCR1_SGPCS_EN BIT(11) 106 + #define LYNX_28G_SGMIIaCR1_SGPCS_DIS 0x0 107 + #define LYNX_28G_SGMIIaCR1_SGPCS_MSK BIT(11) 108 + 109 + struct lynx_28g_priv; 110 + 111 + struct lynx_28g_pll { 112 + struct lynx_28g_priv *priv; 113 + u32 rstctl, cr0, cr1; 114 + int id; 115 + DECLARE_PHY_INTERFACE_MASK(supported); 116 + }; 117 + 118 + struct lynx_28g_lane { 119 + struct lynx_28g_priv *priv; 120 + struct phy *phy; 121 + bool powered_up; 122 + bool init; 123 + unsigned int id; 124 + phy_interface_t interface; 125 + }; 126 + 127 + struct lynx_28g_priv { 128 + void __iomem *base; 129 + struct device *dev; 130 + struct lynx_28g_pll pll[LYNX_28G_NUM_PLL]; 131 + struct lynx_28g_lane lane[LYNX_28G_NUM_LANE]; 132 + 133 + struct delayed_work cdr_check; 134 + }; 135 + 136 + static void lynx_28g_rmw(struct lynx_28g_priv *priv, unsigned long off, 137 + u32 val, u32 mask) 138 + { 139 + void __iomem *reg = priv->base + off; 140 + u32 orig, tmp; 141 + 142 + orig = ioread32(reg); 143 + tmp = orig & ~mask; 144 + tmp |= val; 145 + iowrite32(tmp, reg); 146 + } 147 + 148 + #define lynx_28g_lane_rmw(lane, reg, val, mask) \ 149 + lynx_28g_rmw((lane)->priv, LYNX_28G_##reg(lane->id), \ 150 + LYNX_28G_##reg##_##val, LYNX_28G_##reg##_##mask) 151 + #define lynx_28g_lane_read(lane, reg) \ 152 + ioread32((lane)->priv->base + LYNX_28G_##reg((lane)->id)) 153 + #define lynx_28g_pll_read(pll, reg) \ 154 + ioread32((pll)->priv->base + LYNX_28G_##reg((pll)->id)) 155 + 156 + static bool lynx_28g_supports_interface(struct lynx_28g_priv *priv, int intf) 157 + { 158 + int i; 159 + 160 + for (i = 0; i < LYNX_28G_NUM_PLL; i++) { 161 + if (LYNX_28G_PLLnRSTCTL_DIS(priv->pll[i].rstctl)) 162 + continue; 163 + 164 + if (test_bit(intf, priv->pll[i].supported)) 165 + return true; 166 + } 167 + 168 + return false; 169 + } 170 + 171 + static struct lynx_28g_pll *lynx_28g_pll_get(struct lynx_28g_priv *priv, 172 + phy_interface_t intf) 173 + { 174 + struct lynx_28g_pll *pll; 175 + int i; 176 + 177 + for (i = 0; i < LYNX_28G_NUM_PLL; i++) { 178 + pll = &priv->pll[i]; 179 + 180 + if (LYNX_28G_PLLnRSTCTL_DIS(pll->rstctl)) 181 + continue; 182 + 183 + if (test_bit(intf, pll->supported)) 184 + return pll; 185 + } 186 + 187 + return NULL; 188 + } 189 + 190 + static void lynx_28g_lane_set_nrate(struct lynx_28g_lane *lane, 191 + struct lynx_28g_pll *pll, 192 + phy_interface_t intf) 193 + { 194 + switch (LYNX_28G_PLLnCR1_FRATE_SEL(pll->cr1)) { 195 + case LYNX_28G_PLLnCR1_FRATE_5G_10GVCO: 196 + case LYNX_28G_PLLnCR1_FRATE_5G_25GVCO: 197 + switch (intf) { 198 + case PHY_INTERFACE_MODE_SGMII: 199 + case PHY_INTERFACE_MODE_1000BASEX: 200 + lynx_28g_lane_rmw(lane, LNaTGCR0, N_RATE_QUARTER, N_RATE_MSK); 201 + lynx_28g_lane_rmw(lane, LNaRGCR0, N_RATE_QUARTER, N_RATE_MSK); 202 + break; 203 + default: 204 + break; 205 + } 206 + break; 207 + case LYNX_28G_PLLnCR1_FRATE_10G_20GVCO: 208 + switch (intf) { 209 + case PHY_INTERFACE_MODE_10GBASER: 210 + case PHY_INTERFACE_MODE_USXGMII: 211 + lynx_28g_lane_rmw(lane, LNaTGCR0, N_RATE_FULL, N_RATE_MSK); 212 + lynx_28g_lane_rmw(lane, LNaRGCR0, N_RATE_FULL, N_RATE_MSK); 213 + break; 214 + default: 215 + break; 216 + } 217 + break; 218 + default: 219 + break; 220 + } 221 + } 222 + 223 + static void lynx_28g_lane_set_pll(struct lynx_28g_lane *lane, 224 + struct lynx_28g_pll *pll) 225 + { 226 + if (pll->id == 0) { 227 + lynx_28g_lane_rmw(lane, LNaTGCR0, USE_PLLF, USE_PLL_MSK); 228 + lynx_28g_lane_rmw(lane, LNaRGCR0, USE_PLLF, USE_PLL_MSK); 229 + } else { 230 + lynx_28g_lane_rmw(lane, LNaTGCR0, USE_PLLS, USE_PLL_MSK); 231 + lynx_28g_lane_rmw(lane, LNaRGCR0, USE_PLLS, USE_PLL_MSK); 232 + } 233 + } 234 + 235 + static void lynx_28g_cleanup_lane(struct lynx_28g_lane *lane) 236 + { 237 + u32 lane_offset = LYNX_28G_LNa_PCC_OFFSET(lane); 238 + struct lynx_28g_priv *priv = lane->priv; 239 + 240 + /* Cleanup the protocol configuration registers of the current protocol */ 241 + switch (lane->interface) { 242 + case PHY_INTERFACE_MODE_10GBASER: 243 + lynx_28g_rmw(priv, LYNX_28G_PCCC, 244 + LYNX_28G_PCCC_SXGMII_DIS << lane_offset, 245 + GENMASK(3, 0) << lane_offset); 246 + break; 247 + case PHY_INTERFACE_MODE_SGMII: 248 + case PHY_INTERFACE_MODE_1000BASEX: 249 + lynx_28g_rmw(priv, LYNX_28G_PCC8, 250 + LYNX_28G_PCC8_SGMII_DIS << lane_offset, 251 + GENMASK(3, 0) << lane_offset); 252 + break; 253 + default: 254 + break; 255 + } 256 + } 257 + 258 + static void lynx_28g_lane_set_sgmii(struct lynx_28g_lane *lane) 259 + { 260 + u32 lane_offset = LYNX_28G_LNa_PCC_OFFSET(lane); 261 + struct lynx_28g_priv *priv = lane->priv; 262 + struct lynx_28g_pll *pll; 263 + 264 + lynx_28g_cleanup_lane(lane); 265 + 266 + /* Setup the lane to run in SGMII */ 267 + lynx_28g_rmw(priv, LYNX_28G_PCC8, 268 + LYNX_28G_PCC8_SGMII << lane_offset, 269 + GENMASK(3, 0) << lane_offset); 270 + 271 + /* Setup the protocol select and SerDes parallel interface width */ 272 + lynx_28g_lane_rmw(lane, LNaGCR0, PROTO_SEL_SGMII, PROTO_SEL_MSK); 273 + lynx_28g_lane_rmw(lane, LNaGCR0, IF_WIDTH_10_BIT, IF_WIDTH_MSK); 274 + 275 + /* Switch to the PLL that works with this interface type */ 276 + pll = lynx_28g_pll_get(priv, PHY_INTERFACE_MODE_SGMII); 277 + lynx_28g_lane_set_pll(lane, pll); 278 + 279 + /* Choose the portion of clock net to be used on this lane */ 280 + lynx_28g_lane_set_nrate(lane, pll, PHY_INTERFACE_MODE_SGMII); 281 + 282 + /* Enable the SGMII PCS */ 283 + lynx_28g_lane_rmw(lane, SGMIIaCR1, SGPCS_EN, SGPCS_MSK); 284 + 285 + /* Configure the appropriate equalization parameters for the protocol */ 286 + iowrite32(0x00808006, priv->base + LYNX_28G_LNaTECR0(lane->id)); 287 + iowrite32(0x04310000, priv->base + LYNX_28G_LNaRGCR1(lane->id)); 288 + iowrite32(0x9f800000, priv->base + LYNX_28G_LNaRECR0(lane->id)); 289 + iowrite32(0x001f0000, priv->base + LYNX_28G_LNaRECR1(lane->id)); 290 + iowrite32(0x00000000, priv->base + LYNX_28G_LNaRECR2(lane->id)); 291 + iowrite32(0x00000000, priv->base + LYNX_28G_LNaRSCCR0(lane->id)); 292 + } 293 + 294 + static void lynx_28g_lane_set_10gbaser(struct lynx_28g_lane *lane) 295 + { 296 + u32 lane_offset = LYNX_28G_LNa_PCC_OFFSET(lane); 297 + struct lynx_28g_priv *priv = lane->priv; 298 + struct lynx_28g_pll *pll; 299 + 300 + lynx_28g_cleanup_lane(lane); 301 + 302 + /* Enable the SXGMII lane */ 303 + lynx_28g_rmw(priv, LYNX_28G_PCCC, 304 + LYNX_28G_PCCC_10GBASER << lane_offset, 305 + GENMASK(3, 0) << lane_offset); 306 + 307 + /* Setup the protocol select and SerDes parallel interface width */ 308 + lynx_28g_lane_rmw(lane, LNaGCR0, PROTO_SEL_XFI, PROTO_SEL_MSK); 309 + lynx_28g_lane_rmw(lane, LNaGCR0, IF_WIDTH_20_BIT, IF_WIDTH_MSK); 310 + 311 + /* Switch to the PLL that works with this interface type */ 312 + pll = lynx_28g_pll_get(priv, PHY_INTERFACE_MODE_10GBASER); 313 + lynx_28g_lane_set_pll(lane, pll); 314 + 315 + /* Choose the portion of clock net to be used on this lane */ 316 + lynx_28g_lane_set_nrate(lane, pll, PHY_INTERFACE_MODE_10GBASER); 317 + 318 + /* Disable the SGMII PCS */ 319 + lynx_28g_lane_rmw(lane, SGMIIaCR1, SGPCS_DIS, SGPCS_MSK); 320 + 321 + /* Configure the appropriate equalization parameters for the protocol */ 322 + iowrite32(0x10808307, priv->base + LYNX_28G_LNaTECR0(lane->id)); 323 + iowrite32(0x10000000, priv->base + LYNX_28G_LNaRGCR1(lane->id)); 324 + iowrite32(0x00000000, priv->base + LYNX_28G_LNaRECR0(lane->id)); 325 + iowrite32(0x001f0000, priv->base + LYNX_28G_LNaRECR1(lane->id)); 326 + iowrite32(0x81000020, priv->base + LYNX_28G_LNaRECR2(lane->id)); 327 + iowrite32(0x00002000, priv->base + LYNX_28G_LNaRSCCR0(lane->id)); 328 + } 329 + 330 + static int lynx_28g_power_off(struct phy *phy) 331 + { 332 + struct lynx_28g_lane *lane = phy_get_drvdata(phy); 333 + u32 trstctl, rrstctl; 334 + 335 + if (!lane->powered_up) 336 + return 0; 337 + 338 + /* Issue a halt request */ 339 + lynx_28g_lane_rmw(lane, LNaTRSTCTL, HLT_REQ, HLT_REQ); 340 + lynx_28g_lane_rmw(lane, LNaRRSTCTL, HLT_REQ, HLT_REQ); 341 + 342 + /* Wait until the halting process is complete */ 343 + do { 344 + trstctl = lynx_28g_lane_read(lane, LNaTRSTCTL); 345 + rrstctl = lynx_28g_lane_read(lane, LNaRRSTCTL); 346 + } while ((trstctl & LYNX_28G_LNaTRSTCTL_HLT_REQ) || 347 + (rrstctl & LYNX_28G_LNaRRSTCTL_HLT_REQ)); 348 + 349 + lane->powered_up = false; 350 + 351 + return 0; 352 + } 353 + 354 + static int lynx_28g_power_on(struct phy *phy) 355 + { 356 + struct lynx_28g_lane *lane = phy_get_drvdata(phy); 357 + u32 trstctl, rrstctl; 358 + 359 + if (lane->powered_up) 360 + return 0; 361 + 362 + /* Issue a reset request on the lane */ 363 + lynx_28g_lane_rmw(lane, LNaTRSTCTL, RST_REQ, RST_REQ); 364 + lynx_28g_lane_rmw(lane, LNaRRSTCTL, RST_REQ, RST_REQ); 365 + 366 + /* Wait until the reset sequence is completed */ 367 + do { 368 + trstctl = lynx_28g_lane_read(lane, LNaTRSTCTL); 369 + rrstctl = lynx_28g_lane_read(lane, LNaRRSTCTL); 370 + } while (!(trstctl & LYNX_28G_LNaTRSTCTL_RST_DONE) || 371 + !(rrstctl & LYNX_28G_LNaRRSTCTL_RST_DONE)); 372 + 373 + lane->powered_up = true; 374 + 375 + return 0; 376 + } 377 + 378 + static int lynx_28g_set_mode(struct phy *phy, enum phy_mode mode, int submode) 379 + { 380 + struct lynx_28g_lane *lane = phy_get_drvdata(phy); 381 + struct lynx_28g_priv *priv = lane->priv; 382 + int powered_up = lane->powered_up; 383 + int err = 0; 384 + 385 + if (mode != PHY_MODE_ETHERNET) 386 + return -EOPNOTSUPP; 387 + 388 + if (lane->interface == PHY_INTERFACE_MODE_NA) 389 + return -EOPNOTSUPP; 390 + 391 + if (!lynx_28g_supports_interface(priv, submode)) 392 + return -EOPNOTSUPP; 393 + 394 + /* If the lane is powered up, put the lane into the halt state while 395 + * the reconfiguration is being done. 396 + */ 397 + if (powered_up) 398 + lynx_28g_power_off(phy); 399 + 400 + switch (submode) { 401 + case PHY_INTERFACE_MODE_SGMII: 402 + case PHY_INTERFACE_MODE_1000BASEX: 403 + lynx_28g_lane_set_sgmii(lane); 404 + break; 405 + case PHY_INTERFACE_MODE_10GBASER: 406 + lynx_28g_lane_set_10gbaser(lane); 407 + break; 408 + default: 409 + err = -EOPNOTSUPP; 410 + goto out; 411 + } 412 + 413 + lane->interface = submode; 414 + 415 + out: 416 + /* Power up the lane if necessary */ 417 + if (powered_up) 418 + lynx_28g_power_on(phy); 419 + 420 + return err; 421 + } 422 + 423 + static int lynx_28g_validate(struct phy *phy, enum phy_mode mode, int submode, 424 + union phy_configure_opts *opts __always_unused) 425 + { 426 + struct lynx_28g_lane *lane = phy_get_drvdata(phy); 427 + struct lynx_28g_priv *priv = lane->priv; 428 + 429 + if (mode != PHY_MODE_ETHERNET) 430 + return -EOPNOTSUPP; 431 + 432 + if (!lynx_28g_supports_interface(priv, submode)) 433 + return -EOPNOTSUPP; 434 + 435 + return 0; 436 + } 437 + 438 + static int lynx_28g_init(struct phy *phy) 439 + { 440 + struct lynx_28g_lane *lane = phy_get_drvdata(phy); 441 + 442 + /* Mark the fact that the lane was init */ 443 + lane->init = true; 444 + 445 + /* SerDes lanes are powered on at boot time. Any lane that is managed 446 + * by this driver will get powered down at init time aka at dpaa2-eth 447 + * probe time. 448 + */ 449 + lane->powered_up = true; 450 + lynx_28g_power_off(phy); 451 + 452 + return 0; 453 + } 454 + 455 + static const struct phy_ops lynx_28g_ops = { 456 + .init = lynx_28g_init, 457 + .power_on = lynx_28g_power_on, 458 + .power_off = lynx_28g_power_off, 459 + .set_mode = lynx_28g_set_mode, 460 + .validate = lynx_28g_validate, 461 + .owner = THIS_MODULE, 462 + }; 463 + 464 + static void lynx_28g_pll_read_configuration(struct lynx_28g_priv *priv) 465 + { 466 + struct lynx_28g_pll *pll; 467 + int i; 468 + 469 + for (i = 0; i < LYNX_28G_NUM_PLL; i++) { 470 + pll = &priv->pll[i]; 471 + pll->priv = priv; 472 + pll->id = i; 473 + 474 + pll->rstctl = lynx_28g_pll_read(pll, PLLnRSTCTL); 475 + pll->cr0 = lynx_28g_pll_read(pll, PLLnCR0); 476 + pll->cr1 = lynx_28g_pll_read(pll, PLLnCR1); 477 + 478 + if (LYNX_28G_PLLnRSTCTL_DIS(pll->rstctl)) 479 + continue; 480 + 481 + switch (LYNX_28G_PLLnCR1_FRATE_SEL(pll->cr1)) { 482 + case LYNX_28G_PLLnCR1_FRATE_5G_10GVCO: 483 + case LYNX_28G_PLLnCR1_FRATE_5G_25GVCO: 484 + /* 5GHz clock net */ 485 + __set_bit(PHY_INTERFACE_MODE_1000BASEX, pll->supported); 486 + __set_bit(PHY_INTERFACE_MODE_SGMII, pll->supported); 487 + break; 488 + case LYNX_28G_PLLnCR1_FRATE_10G_20GVCO: 489 + /* 10.3125GHz clock net */ 490 + __set_bit(PHY_INTERFACE_MODE_10GBASER, pll->supported); 491 + break; 492 + default: 493 + /* 6GHz, 12.890625GHz, 8GHz */ 494 + break; 495 + } 496 + } 497 + } 498 + 499 + #define work_to_lynx(w) container_of((w), struct lynx_28g_priv, cdr_check.work) 500 + 501 + static void lynx_28g_cdr_lock_check(struct work_struct *work) 502 + { 503 + struct lynx_28g_priv *priv = work_to_lynx(work); 504 + struct lynx_28g_lane *lane; 505 + u32 rrstctl; 506 + int i; 507 + 508 + for (i = 0; i < LYNX_28G_NUM_LANE; i++) { 509 + lane = &priv->lane[i]; 510 + 511 + if (!lane->init) 512 + continue; 513 + 514 + if (!lane->powered_up) 515 + continue; 516 + 517 + rrstctl = lynx_28g_lane_read(lane, LNaRRSTCTL); 518 + if (!(rrstctl & LYNX_28G_LNaRRSTCTL_CDR_LOCK)) { 519 + lynx_28g_lane_rmw(lane, LNaRRSTCTL, RST_REQ, RST_REQ); 520 + do { 521 + rrstctl = lynx_28g_lane_read(lane, LNaRRSTCTL); 522 + } while (!(rrstctl & LYNX_28G_LNaRRSTCTL_RST_DONE)); 523 + } 524 + } 525 + queue_delayed_work(system_power_efficient_wq, &priv->cdr_check, 526 + msecs_to_jiffies(1000)); 527 + } 528 + 529 + static void lynx_28g_lane_read_configuration(struct lynx_28g_lane *lane) 530 + { 531 + u32 pss, protocol; 532 + 533 + pss = lynx_28g_lane_read(lane, LNaPSS); 534 + protocol = LYNX_28G_LNaPSS_TYPE(pss); 535 + switch (protocol) { 536 + case LYNX_28G_LNaPSS_TYPE_SGMII: 537 + lane->interface = PHY_INTERFACE_MODE_SGMII; 538 + break; 539 + case LYNX_28G_LNaPSS_TYPE_XFI: 540 + lane->interface = PHY_INTERFACE_MODE_10GBASER; 541 + break; 542 + default: 543 + lane->interface = PHY_INTERFACE_MODE_NA; 544 + } 545 + } 546 + 547 + static struct phy *lynx_28g_xlate(struct device *dev, 548 + struct of_phandle_args *args) 549 + { 550 + struct lynx_28g_priv *priv = dev_get_drvdata(dev); 551 + int idx = args->args[0]; 552 + 553 + if (WARN_ON(idx >= LYNX_28G_NUM_LANE)) 554 + return ERR_PTR(-EINVAL); 555 + 556 + return priv->lane[idx].phy; 557 + } 558 + 559 + static int lynx_28g_probe(struct platform_device *pdev) 560 + { 561 + struct device *dev = &pdev->dev; 562 + struct phy_provider *provider; 563 + struct lynx_28g_priv *priv; 564 + int i; 565 + 566 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 567 + if (!priv) 568 + return -ENOMEM; 569 + priv->dev = &pdev->dev; 570 + 571 + priv->base = devm_platform_ioremap_resource(pdev, 0); 572 + if (IS_ERR(priv->base)) 573 + return PTR_ERR(priv->base); 574 + 575 + lynx_28g_pll_read_configuration(priv); 576 + 577 + for (i = 0; i < LYNX_28G_NUM_LANE; i++) { 578 + struct lynx_28g_lane *lane = &priv->lane[i]; 579 + struct phy *phy; 580 + 581 + memset(lane, 0, sizeof(*lane)); 582 + 583 + phy = devm_phy_create(&pdev->dev, NULL, &lynx_28g_ops); 584 + if (IS_ERR(phy)) 585 + return PTR_ERR(phy); 586 + 587 + lane->priv = priv; 588 + lane->phy = phy; 589 + lane->id = i; 590 + phy_set_drvdata(phy, lane); 591 + lynx_28g_lane_read_configuration(lane); 592 + } 593 + 594 + dev_set_drvdata(dev, priv); 595 + 596 + INIT_DELAYED_WORK(&priv->cdr_check, lynx_28g_cdr_lock_check); 597 + 598 + queue_delayed_work(system_power_efficient_wq, &priv->cdr_check, 599 + msecs_to_jiffies(1000)); 600 + 601 + dev_set_drvdata(&pdev->dev, priv); 602 + provider = devm_of_phy_provider_register(&pdev->dev, lynx_28g_xlate); 603 + 604 + return PTR_ERR_OR_ZERO(provider); 605 + } 606 + 607 + static const struct of_device_id lynx_28g_of_match_table[] = { 608 + { .compatible = "fsl,lynx-28g" }, 609 + { }, 610 + }; 611 + MODULE_DEVICE_TABLE(of, lynx_28g_of_match_table); 612 + 613 + static struct platform_driver lynx_28g_driver = { 614 + .probe = lynx_28g_probe, 615 + .driver = { 616 + .name = "lynx-28g", 617 + .of_match_table = lynx_28g_of_match_table, 618 + }, 619 + }; 620 + module_platform_driver(lynx_28g_driver); 621 + 622 + MODULE_AUTHOR("Ioana Ciornei <ioana.ciornei@nxp.com>"); 623 + MODULE_DESCRIPTION("Lynx 28G SerDes PHY driver for Layerscape SoCs"); 624 + MODULE_LICENSE("GPL v2");