1 // SPDX-License-Identifier: GPL-2.0+
4 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
6 * base on the MPC83xx serdes initialization, which is
8 * Copyright 2007,2011 Freescale Semiconductor, Inc.
9 * Copyright (C) 2008 MontaVista Software, Inc.
17 #include <linux/delay.h>
19 #include "mpc83xx_serdes.h"
22 * struct mpc83xx_serdes_priv - Private structure for MPC83xx serdes
23 * @regs: The device's register map
24 * @rfcks: Variable to keep the serdes reference clock selection set during
25 * initialization in (is or'd to every value written to SRDSCR4)
27 struct mpc83xx_serdes_priv {
28 struct mpc83xx_serdes_regs *regs;
33 * setup_sata() - Configure the SerDes device to SATA mode
34 * @dev: The device to configure
36 static void setup_sata(struct udevice *dev)
38 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
40 /* Set and clear reset bits */
41 setbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_SATA_RESET);
43 clrbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_SATA_RESET);
45 /* Configure SRDSCR0 */
46 clrsetbits_be32(&priv->regs->srdscr0,
47 SRDSCR0_TXEQA_MASK | SRDSCR0_TXEQE_MASK,
48 SRDSCR0_TXEQA_SATA | SRDSCR0_TXEQE_SATA);
50 /* Configure SRDSCR1 */
51 clrbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
53 /* Configure SRDSCR2 */
54 clrsetbits_be32(&priv->regs->srdscr2,
58 /* Configure SRDSCR3 */
59 out_be32(&priv->regs->srdscr3,
60 SRDSCR3_KFR_SATA | SRDSCR3_KPH_SATA |
61 SRDSCR3_SDFM_SATA_PEX | SRDSCR3_SDTXL_SATA);
63 /* Configure SRDSCR4 */
64 out_be32(&priv->regs->srdscr4, priv->rfcks | SRDSCR4_PROT_SATA);
68 * setup_pex() - Configure the SerDes device to PCI Express mode
69 * @dev: The device to configure
70 * @type: The PCI Express type to configure for (x1 or x2)
72 static void setup_pex(struct udevice *dev, enum pex_type type)
74 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
76 /* Configure SRDSCR1 */
77 setbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
79 /* Configure SRDSCR2 */
80 clrsetbits_be32(&priv->regs->srdscr2,
84 /* Configure SRDSCR3 */
85 out_be32(&priv->regs->srdscr3, SRDSCR3_SDFM_SATA_PEX);
87 /* Configure SRDSCR4 */
89 out_be32(&priv->regs->srdscr4,
90 priv->rfcks | SRDSCR4_PROT_PEX | SRDSCR4_PLANE_X2);
92 out_be32(&priv->regs->srdscr4,
93 priv->rfcks | SRDSCR4_PROT_PEX);
97 * setup_sgmii() - Configure the SerDes device to SGMII mode
98 * @dev: The device to configure
100 static void setup_sgmii(struct udevice *dev)
102 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
104 /* Configure SRDSCR1 */
105 clrbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
107 /* Configure SRDSCR2 */
108 clrsetbits_be32(&priv->regs->srdscr2,
112 /* Configure SRDSCR3 */
113 out_be32(&priv->regs->srdscr3, 0);
115 /* Configure SRDSCR4 */
116 out_be32(&priv->regs->srdscr4, priv->rfcks | SRDSCR4_PROT_SGMII);
119 static int mpc83xx_serdes_probe(struct udevice *dev)
121 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
125 priv->regs = map_sysmem(dev_read_addr(dev),
126 sizeof(struct mpc83xx_serdes_regs));
128 switch (dev_read_u32_default(dev, "serdes-clk", -1)) {
130 priv->rfcks = SRDSCR4_RFCKS_100;
133 priv->rfcks = SRDSCR4_RFCKS_125;
136 priv->rfcks = SRDSCR4_RFCKS_150;
139 debug("%s: Could not read serdes clock value\n", dev->name);
143 vdd = dev_read_bool(dev, "vdd");
148 clrbits_be32(&priv->regs->srdscr0, SRDSCR0_DPP_1V2);
151 clrbits_be32(&priv->regs->srdscr0, SRDSCR2_VDD_1V2);
154 proto = dev_read_string(dev, "proto");
156 /* protocol specific configuration */
157 if (!strcmp(proto, "sata")) {
159 } else if (!strcmp(proto, "pex")) {
160 setup_pex(dev, PEX_X1);
161 } else if (!strcmp(proto, "pex-x2")) {
162 setup_pex(dev, PEX_X2);
163 } else if (!strcmp(proto, "sgmii")) {
166 debug("%s: Invalid protocol value %s\n", dev->name, proto);
170 /* Do a software reset */
171 setbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_RST);
176 static const struct udevice_id mpc83xx_serdes_ids[] = {
177 { .compatible = "fsl,mpc83xx-serdes" },
181 U_BOOT_DRIVER(mpc83xx_serdes) = {
182 .name = "mpc83xx_serdes",
184 .of_match = mpc83xx_serdes_ids,
185 .probe = mpc83xx_serdes_probe,
186 .priv_auto_alloc_size = sizeof(struct mpc83xx_serdes_priv),