mpc83xx_serdes.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2018
  4. * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
  5. *
  6. * base on the MPC83xx serdes initialization, which is
  7. *
  8. * Copyright 2007,2011 Freescale Semiconductor, Inc.
  9. * Copyright (C) 2008 MontaVista Software, Inc.
  10. */
  11. #include <common.h>
  12. #include <dm.h>
  13. #include <mapmem.h>
  14. #include <misc.h>
  15. #include "mpc83xx_serdes.h"
  16. /**
  17. * struct mpc83xx_serdes_priv - Private structure for MPC83xx serdes
  18. * @regs: The device's register map
  19. * @rfcks: Variable to keep the serdes reference clock selection set during
  20. * initialization in (is or'd to every value written to SRDSCR4)
  21. */
  22. struct mpc83xx_serdes_priv {
  23. struct mpc83xx_serdes_regs *regs;
  24. u32 rfcks;
  25. };
  26. /**
  27. * setup_sata() - Configure the SerDes device to SATA mode
  28. * @dev: The device to configure
  29. */
  30. static void setup_sata(struct udevice *dev)
  31. {
  32. struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
  33. /* Set and clear reset bits */
  34. setbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_SATA_RESET);
  35. udelay(1000);
  36. clrbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_SATA_RESET);
  37. /* Configure SRDSCR0 */
  38. clrsetbits_be32(&priv->regs->srdscr0,
  39. SRDSCR0_TXEQA_MASK | SRDSCR0_TXEQE_MASK,
  40. SRDSCR0_TXEQA_SATA | SRDSCR0_TXEQE_SATA);
  41. /* Configure SRDSCR1 */
  42. clrbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
  43. /* Configure SRDSCR2 */
  44. clrsetbits_be32(&priv->regs->srdscr2,
  45. SRDSCR2_SEIC_MASK,
  46. SRDSCR2_SEIC_SATA);
  47. /* Configure SRDSCR3 */
  48. out_be32(&priv->regs->srdscr3,
  49. SRDSCR3_KFR_SATA | SRDSCR3_KPH_SATA |
  50. SRDSCR3_SDFM_SATA_PEX | SRDSCR3_SDTXL_SATA);
  51. /* Configure SRDSCR4 */
  52. out_be32(&priv->regs->srdscr4, priv->rfcks | SRDSCR4_PROT_SATA);
  53. }
  54. /**
  55. * setup_pex() - Configure the SerDes device to PCI Express mode
  56. * @dev: The device to configure
  57. * @type: The PCI Express type to configure for (x1 or x2)
  58. */
  59. static void setup_pex(struct udevice *dev, enum pex_type type)
  60. {
  61. struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
  62. /* Configure SRDSCR1 */
  63. setbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
  64. /* Configure SRDSCR2 */
  65. clrsetbits_be32(&priv->regs->srdscr2,
  66. SRDSCR2_SEIC_MASK,
  67. SRDSCR2_SEIC_PEX);
  68. /* Configure SRDSCR3 */
  69. out_be32(&priv->regs->srdscr3, SRDSCR3_SDFM_SATA_PEX);
  70. /* Configure SRDSCR4 */
  71. if (type == PEX_X2)
  72. out_be32(&priv->regs->srdscr4,
  73. priv->rfcks | SRDSCR4_PROT_PEX | SRDSCR4_PLANE_X2);
  74. else
  75. out_be32(&priv->regs->srdscr4,
  76. priv->rfcks | SRDSCR4_PROT_PEX);
  77. }
  78. /**
  79. * setup_sgmii() - Configure the SerDes device to SGMII mode
  80. * @dev: The device to configure
  81. */
  82. static void setup_sgmii(struct udevice *dev)
  83. {
  84. struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
  85. /* Configure SRDSCR1 */
  86. clrbits_be32(&priv->regs->srdscr1, SRDSCR1_PLLBW);
  87. /* Configure SRDSCR2 */
  88. clrsetbits_be32(&priv->regs->srdscr2,
  89. SRDSCR2_SEIC_MASK,
  90. SRDSCR2_SEIC_SGMII);
  91. /* Configure SRDSCR3 */
  92. out_be32(&priv->regs->srdscr3, 0);
  93. /* Configure SRDSCR4 */
  94. out_be32(&priv->regs->srdscr4, priv->rfcks | SRDSCR4_PROT_SGMII);
  95. }
  96. static int mpc83xx_serdes_probe(struct udevice *dev)
  97. {
  98. struct mpc83xx_serdes_priv *priv = dev_get_priv(dev);
  99. bool vdd;
  100. const char *proto;
  101. priv->regs = map_sysmem(dev_read_addr(dev),
  102. sizeof(struct mpc83xx_serdes_regs));
  103. switch (dev_read_u32_default(dev, "serdes-clk", -1)) {
  104. case 100:
  105. priv->rfcks = SRDSCR4_RFCKS_100;
  106. break;
  107. case 125:
  108. priv->rfcks = SRDSCR4_RFCKS_125;
  109. break;
  110. case 150:
  111. priv->rfcks = SRDSCR4_RFCKS_150;
  112. break;
  113. default:
  114. debug("%s: Could not read serdes clock value\n", dev->name);
  115. return -EINVAL;
  116. }
  117. vdd = dev_read_bool(dev, "vdd");
  118. /* 1.0V corevdd */
  119. if (vdd) {
  120. /* DPPE/DPPA = 0 */
  121. clrbits_be32(&priv->regs->srdscr0, SRDSCR0_DPP_1V2);
  122. /* VDD = 0 */
  123. clrbits_be32(&priv->regs->srdscr0, SRDSCR2_VDD_1V2);
  124. }
  125. proto = dev_read_string(dev, "proto");
  126. /* protocol specific configuration */
  127. if (!strcmp(proto, "sata")) {
  128. setup_sata(dev);
  129. } else if (!strcmp(proto, "pex")) {
  130. setup_pex(dev, PEX_X1);
  131. } else if (!strcmp(proto, "pex-x2")) {
  132. setup_pex(dev, PEX_X2);
  133. } else if (!strcmp(proto, "sgmii")) {
  134. setup_sgmii(dev);
  135. } else {
  136. debug("%s: Invalid protocol value %s\n", dev->name, proto);
  137. return -EINVAL;
  138. }
  139. /* Do a software reset */
  140. setbits_be32(&priv->regs->srdsrstctl, SRDSRSTCTL_RST);
  141. return 0;
  142. }
  143. static const struct udevice_id mpc83xx_serdes_ids[] = {
  144. { .compatible = "fsl,mpc83xx-serdes" },
  145. { }
  146. };
  147. U_BOOT_DRIVER(mpc83xx_serdes) = {
  148. .name = "mpc83xx_serdes",
  149. .id = UCLASS_MISC,
  150. .of_match = mpc83xx_serdes_ids,
  151. .probe = mpc83xx_serdes_probe,
  152. .priv_auto_alloc_size = sizeof(struct mpc83xx_serdes_priv),
  153. };