0010-net-switchlib-add-driver-for-Lantiq-PSB697X-switch-f.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. From e2c59cedebf72e4a002134a2932f722b508a5448 Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  3. Date: Wed, 29 Aug 2012 22:08:15 +0200
  4. Subject: net: switchlib: add driver for Lantiq PSB697X switch family
  5. Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  6. --- a/drivers/net/switch/Makefile
  7. +++ b/drivers/net/switch/Makefile
  8. @@ -10,6 +10,7 @@ include $(TOPDIR)/config.mk
  9. LIB := $(obj)libswitch.o
  10. COBJS-$(CONFIG_SWITCH_MULTI) += switch.o
  11. +COBJS-$(CONFIG_SWITCH_PSB697X) += psb697x.o
  12. COBJS := $(COBJS-y)
  13. SRCS := $(COBJS:.o=.c)
  14. --- /dev/null
  15. +++ b/drivers/net/switch/psb697x.c
  16. @@ -0,0 +1,118 @@
  17. +/*
  18. + * Copyright (C) 2011-2013 Daniel Schwierzeck, daniel.schwierzeck@gmail.com
  19. + *
  20. + * SPDX-License-Identifier: GPL-2.0+
  21. + */
  22. +
  23. +#include <common.h>
  24. +#include <malloc.h>
  25. +#include <switch.h>
  26. +#include <miiphy.h>
  27. +
  28. +#define PSB697X_CHIPID1 0x2599
  29. +#define PSB697X_PORT_COUNT 7
  30. +
  31. +#define PSB697X_PORT_BASE(p) (p * 0x20)
  32. +#define PSB697X_REG_PS(p) (PSB697X_PORT_BASE(p) + 0x00)
  33. +#define PSB697X_REG_PBC(p) (PSB697X_PORT_BASE(p) + 0x01)
  34. +#define PSB697X_REG_PEC(p) (PSB697X_PORT_BASE(p) + 0x02)
  35. +
  36. +#define PSB697X_REG_SGC1 0x0E0 /* Switch Global Control Register 1 */
  37. +#define PSB697X_REG_SGC2 0x0E1 /* Switch Global Control Register 2 */
  38. +#define PSB697X_REG_CMH 0x0E2 /* CPU Port & Mirror Control */
  39. +#define PSB697X_REG_MIICR 0x0F5 /* MII Port Control */
  40. +#define PSB697X_REG_CI0 0x100 /* Chip Identifier 0 */
  41. +#define PSB697X_REG_CI1 0x101 /* Chip Identifier 1 */
  42. +#define PSB697X_REG_MIIAC 0x120 /* MII Indirect Access Control */
  43. +#define PSB697X_REG_MIIWD 0x121 /* MII Indirect Write Data */
  44. +#define PSB697X_REG_MIIRD 0x122 /* MII Indirect Read Data */
  45. +
  46. +#define PSB697X_REG_PORT_FLP (1 << 2) /* Force link up */
  47. +#define PSB697X_REG_PORT_FLD (1 << 1) /* Force link down */
  48. +
  49. +#define PSB697X_REG_SGC2_SE (1 << 15) /* Switch enable */
  50. +
  51. +#define PSB697X_REG_CMH_CPN_MASK 0x7
  52. +#define PSB697X_REG_CMH_CPN_SHIFT 5
  53. +
  54. +
  55. +static inline int psb697x_mii_read(struct mii_dev *bus, u16 reg)
  56. +{
  57. + int ret;
  58. +
  59. + ret = bus->read(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE, reg & 0x1f);
  60. +
  61. + return ret;
  62. +}
  63. +
  64. +static inline int psb697x_mii_write(struct mii_dev *bus, u16 reg, u16 val)
  65. +{
  66. + int ret;
  67. +
  68. + ret = bus->write(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE,
  69. + reg & 0x1f, val);
  70. +
  71. + return ret;
  72. +}
  73. +
  74. +static int psb697x_probe(struct switch_device *dev)
  75. +{
  76. + struct mii_dev *bus = dev->bus;
  77. + int ci1;
  78. +
  79. + ci1 = psb697x_mii_read(bus, PSB697X_REG_CI1);
  80. +
  81. + if (ci1 == PSB697X_CHIPID1)
  82. + return 0;
  83. +
  84. + return 1;
  85. +}
  86. +
  87. +static void psb697x_setup(struct switch_device *dev)
  88. +{
  89. + struct mii_dev *bus = dev->bus;
  90. + int i, state;
  91. +
  92. + /* Enable switch */
  93. + psb697x_mii_write(bus, PSB697X_REG_SGC2, PSB697X_REG_SGC2_SE);
  94. +
  95. + /*
  96. + * Force 100 Mbps as default value for CPU ports 5 and 6 to get
  97. + * full speed.
  98. + */
  99. + psb697x_mii_write(bus, PSB697X_REG_MIICR, 0x0773);
  100. +
  101. + for (i = 0; i < PSB697X_PORT_COUNT; i++) {
  102. + state = dev->port_mask & (1 << i);
  103. +
  104. + /*
  105. + * Software workaround from Errata Sheet:
  106. + * Force link down and reset internal PHY, keep that state
  107. + * for all unconnected ports and disable force link down
  108. + * for all connected ports
  109. + */
  110. + psb697x_mii_write(bus, PSB697X_REG_PBC(i),
  111. + PSB697X_REG_PORT_FLD);
  112. +
  113. + if (i == dev->cpu_port)
  114. + /* Force link up for CPU port */
  115. + psb697x_mii_write(bus, PSB697X_REG_PBC(i),
  116. + PSB697X_REG_PORT_FLP);
  117. + else if (state)
  118. + /* Disable force link down for active LAN ports */
  119. + psb697x_mii_write(bus, PSB697X_REG_PBC(i), 0);
  120. + }
  121. +}
  122. +
  123. +static struct switch_driver psb697x_drv = {
  124. + .name = "psb697x",
  125. +};
  126. +
  127. +void switch_psb697x_init(void)
  128. +{
  129. + /* For archs with manual relocation */
  130. + psb697x_drv.probe = psb697x_probe;
  131. + psb697x_drv.setup = psb697x_setup;
  132. +
  133. + switch_driver_register(&psb697x_drv);
  134. +}
  135. --- a/drivers/net/switch/switch.c
  136. +++ b/drivers/net/switch/switch.c
  137. @@ -17,6 +17,10 @@ void switch_init(void)
  138. INIT_LIST_HEAD(&switch_drivers);
  139. INIT_LIST_HEAD(&switch_devices);
  140. +#if defined(CONFIG_SWITCH_PSB697X)
  141. + switch_psb697x_init();
  142. +#endif
  143. +
  144. board_switch_init();
  145. }
  146. --- a/include/switch.h
  147. +++ b/include/switch.h
  148. @@ -97,6 +97,7 @@ static inline void switch_setup(struct s
  149. }
  150. /* Init functions for supported Switch drivers */
  151. +extern void switch_psb697x_init(void);
  152. #endif /* __SWITCH_H */