xref: /aosp_15_r20/external/coreboot/src/vendorcode/cavium/bdk/libbdk-hal/if/bdk-if-phy-marvell.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /***********************license start***********************************
2 * Copyright (c) 2003-2016  Cavium Inc. ([email protected]). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
13 *   * Redistributions in binary form must reproduce the above
14 *     copyright notice, this list of conditions and the following
15 *     disclaimer in the documentation and/or other materials provided
16 *     with the distribution.
17 *
18 *   * Neither the name of Cavium Inc. nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22 *
23 * This Software, including technical data, may be subject to U.S. export
24 * control laws, including the U.S. Export Administration Act and its
25 * associated regulations, and may be subject to export or import
26 * regulations in other countries.
27 *
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
31 * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
32 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
33 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
34 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
35 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
36 * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK
37 * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39 #include <bdk.h>
40 #include <libbdk-hal/bdk-mdio.h>
41 #include <libbdk-hal/bdk-qlm.h>
42 #include <libbdk-hal/if/bdk-if.h>
43 
44 /**
45  * Setup marvell PHYs
46  * This function sets up one port in a marvell 88E1512 in SGMII mode
47  */
setup_marvell_phy(bdk_node_t node,int mdio_bus,int mdio_addr)48 static void setup_marvell_phy(bdk_node_t node, int mdio_bus, int mdio_addr)
49 {
50       int phy_status = 0;
51 
52            BDK_TRACE(PHY, "%s In SGMII mode for Marvell PHY 88E1512\n", __func__);
53           /* Switch to Page 18 */
54             phy_status = bdk_mdio_write(node, mdio_bus, mdio_addr, 22, 18);
55           if (phy_status < 0)
56                        return;
57 
58           phy_status = bdk_mdio_read(node, mdio_bus, mdio_addr, 22);
59           if (phy_status < 0)
60                        return;
61 
62           /* Change the Phy System mode from RGMII(default hw reset mode) to SGMII */
63           phy_status = bdk_mdio_write(node, mdio_bus, mdio_addr, 20, 1);
64           if (phy_status < 0)
65                 return;
66 
67           /* Requires a Software reset */
68           phy_status = bdk_mdio_write(node, mdio_bus, mdio_addr, 20, 0x8001);
69           if (phy_status < 0)
70                 return;
71 
72           phy_status = bdk_mdio_read(node, mdio_bus, mdio_addr, 20);
73           if (phy_status < 0)
74                        return;
75 
76           /* Change the Page back to 0 */
77             phy_status = bdk_mdio_write(node, mdio_bus, mdio_addr, 22, 0);
78           if (phy_status < 0)
79                        return;
80 
81           phy_status = bdk_mdio_read(node, mdio_bus, mdio_addr, 22);
82           if (phy_status < 0)
83                        return;
84 
85       phy_status = bdk_mdio_read(node, mdio_bus, mdio_addr, 17);
86       if (phy_status < 0)
87            return;
88 }
89 
bdk_if_phy_marvell_setup(bdk_node_t node,int qlm,int mdio_bus,int phy_addr)90 int bdk_if_phy_marvell_setup(bdk_node_t node, int qlm, int mdio_bus, int phy_addr)
91 {
92     BDK_TRACE(PHY,"In %s\n",__func__);
93 
94     /* Check if the PHY is marvell PHY we expect */
95     int phy_status = bdk_mdio_read(node, mdio_bus, phy_addr, BDK_MDIO_PHY_REG_ID1);
96     if (phy_status != 0x0141)
97         return 0;
98 
99     /* Check that the GSER mode is SGMII */
100     /* Switch the marvell PHY to the correct mode */
101     bdk_qlm_modes_t qlm_mode = bdk_qlm_get_mode(node, qlm);
102 
103     BDK_TRACE(PHY,"%s: QLM:%d QLM_MODE:%d\n",__func__, qlm, qlm_mode);
104 
105     if ((qlm_mode != BDK_QLM_MODE_SGMII_1X1) &&
106         (qlm_mode != BDK_QLM_MODE_SGMII_2X1))
107         return 0;
108 
109     BDK_TRACE(PHY,"%s: Detected Marvell Phy in SGMII mode\n", __func__);
110     for (int port = 0; port < 2; port++)
111     {
112         setup_marvell_phy(node, mdio_bus, phy_addr + port);
113     }
114     return 0;
115 }
116