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 "mpc83xx_serdes.h"
20 * struct mpc83xx_serdes_priv - Private structure for MPC83xx serdes
21 * @regs: The device's register map
22 * @rfcks: Variable to keep the serdes reference clock selection set during
23 * initialization in (is or'd to every value written to SRDSCR4)
25 struct mpc83xx_serdes_priv {
26 struct mpc83xx_serdes_regs *regs;
31 * setup_sata() - Configure the SerDes device to SATA mode
32 * @dev: The device to configure
34 static void setup_sata(struct udevice *dev)
36 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
38 /* Set and clear reset bits */
39 setbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_SATA_RESET);
41 clrbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_SATA_RESET);
43 /* Configure SRDSCR0 */
44 clrsetbits_be32(&priv->regs->srdscr0,
45 SRDSCR0_TXEQA_MASK | SRDSCR0_TXEQE_MASK,
46 SRDSCR0_TXEQA_SATA | SRDSCR0_TXEQE_SATA);
48 /* Configure SRDSCR1 */
49 clrbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
51 /* Configure SRDSCR2 */
52 clrsetbits_be32(&priv->regs->srdscr2,
56 /* Configure SRDSCR3 */
57 out_be32(&priv->regs->srdscr3,
58 SRDSCR3_KFR_SATA | SRDSCR3_KPH_SATA |
59 SRDSCR3_SDFM_SATA_PEX | SRDSCR3_SDTXL_SATA);
61 /* Configure SRDSCR4 */
62 out_be32(&priv->regs->srdscr4, priv->rfcks | SRDSCR4_PROT_SATA);
66 * setup_pex() - Configure the SerDes device to PCI Express mode
67 * @dev: The device to configure
68 * @type: The PCI Express type to configure for (x1 or x2)
70 static void setup_pex(struct udevice *dev, enum pex_type type)
72 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
74 /* Configure SRDSCR1 */
75 setbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
77 /* Configure SRDSCR2 */
78 clrsetbits_be32(&priv->regs->srdscr2,
82 /* Configure SRDSCR3 */
83 out_be32(&priv->regs->srdscr3, SRDSCR3_SDFM_SATA_PEX);
85 /* Configure SRDSCR4 */
87 out_be32(&priv->regs->srdscr4,
88 priv->rfcks | SRDSCR4_PROT_PEX | SRDSCR4_PLANE_X2);
90 out_be32(&priv->regs->srdscr4,
91 priv->rfcks | SRDSCR4_PROT_PEX);
95 * setup_sgmii() - Configure the SerDes device to SGMII mode
96 * @dev: The device to configure
98 static void setup_sgmii(struct udevice *dev)
100 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
102 /* Configure SRDSCR1 */
103 clrbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
105 /* Configure SRDSCR2 */
106 clrsetbits_be32(&priv->regs->srdscr2,
110 /* Configure SRDSCR3 */
111 out_be32(&priv->regs->srdscr3, 0);
113 /* Configure SRDSCR4 */
114 out_be32(&priv->regs->srdscr4, priv->rfcks | SRDSCR4_PROT_SGMII);
117 static int mpc83xx_serdes_probe(struct udevice *dev)
119 struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
123 priv->regs = map_sysmem(dev_read_addr(dev),
124 sizeof(struct mpc83xx_serdes_regs));
126 switch (dev_read_u32_default(dev, "serdes-clk", -1)) {
128 priv->rfcks = SRDSCR4_RFCKS_100;
131 priv->rfcks = SRDSCR4_RFCKS_125;
134 priv->rfcks = SRDSCR4_RFCKS_150;
137 debug("%s: Could not read serdes clock value\n", dev->name);
141 vdd = dev_read_bool(dev, "vdd");
146 clrbits_be32(&priv->regs->srdscr0, SRDSCR0_DPP_1V2);
149 clrbits_be32(&priv->regs->srdscr0, SRDSCR2_VDD_1V2);
152 proto = dev_read_string(dev, "proto");
154 /* protocol specific configuration */
155 if (!strcmp(proto, "sata")) {
157 } else if (!strcmp(proto, "pex")) {
158 setup_pex(dev, PEX_X1);
159 } else if (!strcmp(proto, "pex-x2")) {
160 setup_pex(dev, PEX_X2);
161 } else if (!strcmp(proto, "sgmii")) {
164 debug("%s: Invalid protocol value %s\n", dev->name, proto);
168 /* Do a software reset */
169 setbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_RST);
174 static const struct udevice_id mpc83xx_serdes_ids[] = {
175 { .compatible = "fsl,mpc83xx-serdes" },
179 U_BOOT_DRIVER(mpc83xx_serdes) = {
180 .name = "mpc83xx_serdes",
182 .of_match = mpc83xx_serdes_ids,
183 .probe = mpc83xx_serdes_probe,
184 .priv_auto_alloc_size = sizeof(struct mpc83xx_serdes_priv),