120-phy-move-fixed_phy-MII-register-generation-to-a-libr.patch 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. From 4d5621372f6e7ddbfd5879602f82073987bcc722 Mon Sep 17 00:00:00 2001
  2. From: Russell King <rmk+kernel@arm.linux.org.uk>
  3. Date: Sun, 20 Sep 2015 09:57:10 +0100
  4. Subject: [PATCH 709/744] phy: move fixed_phy MII register generation to a
  5. library
  6. Move the fixed_phy MII register generation to a library to allow other
  7. software phy implementations to use this code.
  8. Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
  9. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
  10. ---
  11. drivers/net/phy/Kconfig | 4 ++
  12. drivers/net/phy/Makefile | 3 +-
  13. drivers/net/phy/fixed_phy.c | 95 ++-------------------------------
  14. drivers/net/phy/swphy.c | 126 ++++++++++++++++++++++++++++++++++++++++++++
  15. drivers/net/phy/swphy.h | 8 +++
  16. 5 files changed, 143 insertions(+), 93 deletions(-)
  17. create mode 100644 drivers/net/phy/swphy.c
  18. create mode 100644 drivers/net/phy/swphy.h
  19. --- a/drivers/net/phy/Kconfig
  20. +++ b/drivers/net/phy/Kconfig
  21. @@ -26,6 +26,9 @@ config SWCONFIG_LEDS
  22. bool "Switch LED trigger support"
  23. depends on (SWCONFIG && LEDS_TRIGGERS)
  24. +config SWPHY
  25. + bool
  26. +
  27. comment "MII PHY device drivers"
  28. config AQUANTIA_PHY
  29. @@ -205,6 +208,7 @@ config RTL8306_PHY
  30. config FIXED_PHY
  31. tristate "Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs"
  32. depends on PHYLIB
  33. + select SWPHY
  34. ---help---
  35. Adds the platform "fixed" MDIO Bus to cover the boards that use
  36. PHYs that are not connected to the real MDIO bus.
  37. --- a/drivers/net/phy/Makefile
  38. +++ b/drivers/net/phy/Makefile
  39. @@ -1,6 +1,7 @@
  40. # Makefile for Linux PHY drivers
  41. -libphy-objs := phy.o phy_device.o mdio_bus.o
  42. +libphy-y := phy.o phy_device.o mdio_bus.o
  43. +libphy-$(CONFIG_SWPHY) += swphy.o
  44. obj-$(CONFIG_MDIO_BOARDINFO) += mdio-boardinfo.o
  45. --- a/drivers/net/phy/fixed_phy.c
  46. +++ b/drivers/net/phy/fixed_phy.c
  47. @@ -24,6 +24,8 @@
  48. #include <linux/of.h>
  49. #include <linux/gpio.h>
  50. +#include "swphy.h"
  51. +
  52. #define MII_REGS_NUM 29
  53. struct fixed_mdio_bus {
  54. @@ -49,101 +51,10 @@ static struct fixed_mdio_bus platform_fm
  55. static int fixed_phy_update_regs(struct fixed_phy *fp)
  56. {
  57. - u16 bmsr = BMSR_ANEGCAPABLE;
  58. - u16 bmcr = 0;
  59. - u16 lpagb = 0;
  60. - u16 lpa = 0;
  61. -
  62. if (gpio_is_valid(fp->link_gpio))
  63. fp->status.link = !!gpio_get_value_cansleep(fp->link_gpio);
  64. - if (fp->status.duplex) {
  65. - switch (fp->status.speed) {
  66. - case 1000:
  67. - bmsr |= BMSR_ESTATEN;
  68. - break;
  69. - case 100:
  70. - bmsr |= BMSR_100FULL;
  71. - break;
  72. - case 10:
  73. - bmsr |= BMSR_10FULL;
  74. - break;
  75. - default:
  76. - break;
  77. - }
  78. - } else {
  79. - switch (fp->status.speed) {
  80. - case 1000:
  81. - bmsr |= BMSR_ESTATEN;
  82. - break;
  83. - case 100:
  84. - bmsr |= BMSR_100HALF;
  85. - break;
  86. - case 10:
  87. - bmsr |= BMSR_10HALF;
  88. - break;
  89. - default:
  90. - break;
  91. - }
  92. - }
  93. -
  94. - if (fp->status.link) {
  95. - bmsr |= BMSR_LSTATUS | BMSR_ANEGCOMPLETE;
  96. -
  97. - if (fp->status.duplex) {
  98. - bmcr |= BMCR_FULLDPLX;
  99. -
  100. - switch (fp->status.speed) {
  101. - case 1000:
  102. - bmcr |= BMCR_SPEED1000;
  103. - lpagb |= LPA_1000FULL;
  104. - break;
  105. - case 100:
  106. - bmcr |= BMCR_SPEED100;
  107. - lpa |= LPA_100FULL;
  108. - break;
  109. - case 10:
  110. - lpa |= LPA_10FULL;
  111. - break;
  112. - default:
  113. - pr_warn("fixed phy: unknown speed\n");
  114. - return -EINVAL;
  115. - }
  116. - } else {
  117. - switch (fp->status.speed) {
  118. - case 1000:
  119. - bmcr |= BMCR_SPEED1000;
  120. - lpagb |= LPA_1000HALF;
  121. - break;
  122. - case 100:
  123. - bmcr |= BMCR_SPEED100;
  124. - lpa |= LPA_100HALF;
  125. - break;
  126. - case 10:
  127. - lpa |= LPA_10HALF;
  128. - break;
  129. - default:
  130. - pr_warn("fixed phy: unknown speed\n");
  131. - return -EINVAL;
  132. - }
  133. - }
  134. -
  135. - if (fp->status.pause)
  136. - lpa |= LPA_PAUSE_CAP;
  137. -
  138. - if (fp->status.asym_pause)
  139. - lpa |= LPA_PAUSE_ASYM;
  140. - }
  141. -
  142. - fp->regs[MII_PHYSID1] = 0;
  143. - fp->regs[MII_PHYSID2] = 0;
  144. -
  145. - fp->regs[MII_BMSR] = bmsr;
  146. - fp->regs[MII_BMCR] = bmcr;
  147. - fp->regs[MII_LPA] = lpa;
  148. - fp->regs[MII_STAT1000] = lpagb;
  149. -
  150. - return 0;
  151. + return swphy_update_regs(fp->regs, &fp->status);
  152. }
  153. static int fixed_mdio_read(struct mii_bus *bus, int phy_addr, int reg_num)
  154. --- /dev/null
  155. +++ b/drivers/net/phy/swphy.c
  156. @@ -0,0 +1,126 @@
  157. +/*
  158. + * Software PHY emulation
  159. + *
  160. + * Code taken from fixed_phy.c by Russell King <rmk+kernel@arm.linux.org.uk>
  161. + *
  162. + * Author: Vitaly Bordug <vbordug@ru.mvista.com>
  163. + * Anton Vorontsov <avorontsov@ru.mvista.com>
  164. + *
  165. + * Copyright (c) 2006-2007 MontaVista Software, Inc.
  166. + *
  167. + * This program is free software; you can redistribute it and/or modify it
  168. + * under the terms of the GNU General Public License as published by the
  169. + * Free Software Foundation; either version 2 of the License, or (at your
  170. + * option) any later version.
  171. + */
  172. +#include <linux/export.h>
  173. +#include <linux/mii.h>
  174. +#include <linux/phy.h>
  175. +#include <linux/phy_fixed.h>
  176. +
  177. +#include "swphy.h"
  178. +
  179. +/**
  180. + * swphy_update_regs - update MII register array with fixed phy state
  181. + * @regs: array of 32 registers to update
  182. + * @state: fixed phy status
  183. + *
  184. + * Update the array of MII registers with the fixed phy link, speed,
  185. + * duplex and pause mode settings.
  186. + */
  187. +int swphy_update_regs(u16 *regs, const struct fixed_phy_status *state)
  188. +{
  189. + u16 bmsr = BMSR_ANEGCAPABLE;
  190. + u16 bmcr = 0;
  191. + u16 lpagb = 0;
  192. + u16 lpa = 0;
  193. +
  194. + if (state->duplex) {
  195. + switch (state->speed) {
  196. + case 1000:
  197. + bmsr |= BMSR_ESTATEN;
  198. + break;
  199. + case 100:
  200. + bmsr |= BMSR_100FULL;
  201. + break;
  202. + case 10:
  203. + bmsr |= BMSR_10FULL;
  204. + break;
  205. + default:
  206. + break;
  207. + }
  208. + } else {
  209. + switch (state->speed) {
  210. + case 1000:
  211. + bmsr |= BMSR_ESTATEN;
  212. + break;
  213. + case 100:
  214. + bmsr |= BMSR_100HALF;
  215. + break;
  216. + case 10:
  217. + bmsr |= BMSR_10HALF;
  218. + break;
  219. + default:
  220. + break;
  221. + }
  222. + }
  223. +
  224. + if (state->link) {
  225. + bmsr |= BMSR_LSTATUS | BMSR_ANEGCOMPLETE;
  226. +
  227. + if (state->duplex) {
  228. + bmcr |= BMCR_FULLDPLX;
  229. +
  230. + switch (state->speed) {
  231. + case 1000:
  232. + bmcr |= BMCR_SPEED1000;
  233. + lpagb |= LPA_1000FULL;
  234. + break;
  235. + case 100:
  236. + bmcr |= BMCR_SPEED100;
  237. + lpa |= LPA_100FULL;
  238. + break;
  239. + case 10:
  240. + lpa |= LPA_10FULL;
  241. + break;
  242. + default:
  243. + pr_warn("swphy: unknown speed\n");
  244. + return -EINVAL;
  245. + }
  246. + } else {
  247. + switch (state->speed) {
  248. + case 1000:
  249. + bmcr |= BMCR_SPEED1000;
  250. + lpagb |= LPA_1000HALF;
  251. + break;
  252. + case 100:
  253. + bmcr |= BMCR_SPEED100;
  254. + lpa |= LPA_100HALF;
  255. + break;
  256. + case 10:
  257. + lpa |= LPA_10HALF;
  258. + break;
  259. + default:
  260. + pr_warn("swphy: unknown speed\n");
  261. + return -EINVAL;
  262. + }
  263. + }
  264. +
  265. + if (state->pause)
  266. + lpa |= LPA_PAUSE_CAP;
  267. +
  268. + if (state->asym_pause)
  269. + lpa |= LPA_PAUSE_ASYM;
  270. + }
  271. +
  272. + regs[MII_PHYSID1] = 0;
  273. + regs[MII_PHYSID2] = 0;
  274. +
  275. + regs[MII_BMSR] = bmsr;
  276. + regs[MII_BMCR] = bmcr;
  277. + regs[MII_LPA] = lpa;
  278. + regs[MII_STAT1000] = lpagb;
  279. +
  280. + return 0;
  281. +}
  282. +EXPORT_SYMBOL_GPL(swphy_update_regs);
  283. --- /dev/null
  284. +++ b/drivers/net/phy/swphy.h
  285. @@ -0,0 +1,8 @@
  286. +#ifndef SWPHY_H
  287. +#define SWPHY_H
  288. +
  289. +struct fixed_phy_status;
  290. +
  291. +int swphy_update_regs(u16 *regs, const struct fixed_phy_status *state);
  292. +
  293. +#endif