0518-net-mediatek-get-rt3050-ethernet-ports-to-be-disable.patch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. From: Vittorio Gambaletta <openwrt@vittgam.net>
  2. Date: Fri, 01 Jan 2016 00:00:02 +0100
  3. Subject: [PATCH 3/3] net: mediatek: Get rt3050 ethernet ports to be disabled from the device tree.
  4. This patch allows configuring ports to be disabled in the device tree; this
  5. saves power, since disabling ports here actually disables power to ethernet
  6. PHYs.
  7. Line 444 enables all ethernet ports, so line 487 is getting zero ports to be
  8. disabled, except for port 5 in SoCs where this is not implemented as it will
  9. be sticky disabled in register POC0. Because of this, the code will still read
  10. the switch configuration and OR it to the device tree setting.
  11. Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>
  12. ---
  13. --- a/drivers/net/ethernet/mediatek/esw_rt3050.c
  14. +++ b/drivers/net/ethernet/mediatek/esw_rt3050.c
  15. @@ -10,6 +10,7 @@
  16. * Copyright (C) 2009-2015 John Crispin <blogic@openwrt.org>
  17. * Copyright (C) 2009-2015 Felix Fietkau <nbd@nbd.name>
  18. * Copyright (C) 2013-2015 Michael Lee <igvtee@gmail.com>
  19. + * Copyright (C) 2016 Vittorio Gambaletta <openwrt@vittgam.net>
  20. */
  21. #include <linux/module.h>
  22. @@ -219,6 +220,7 @@ struct rt305x_esw {
  23. spinlock_t reg_rw_lock;
  24. unsigned char port_map;
  25. + unsigned char port_disable;
  26. unsigned int reg_led_polarity;
  27. struct switch_dev swdev;
  28. @@ -483,8 +485,14 @@ static void esw_hw_init(struct rt305x_es
  29. esw_w32(esw, 0x00000005, RT305X_ESW_REG_P3LED);
  30. esw_w32(esw, 0x00000005, RT305X_ESW_REG_P4LED);
  31. - /* Copy disabled port configuration from bootloader setup */
  32. - port_disable = esw_get_port_disable(esw);
  33. + /* Copy disabled port configuration from device tree setup */
  34. + port_disable = esw->port_disable;
  35. +
  36. + /* Disable nonexistent ports by reading the switch config
  37. + * after having enabled all possible ports above
  38. + */
  39. + port_disable |= esw_get_port_disable(esw);
  40. +
  41. for (i = 0; i < 6; i++)
  42. esw->ports[i].disable = (port_disable & (1 << i)) != 0;
  43. @@ -1330,7 +1338,7 @@ static int esw_probe(struct platform_dev
  44. {
  45. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  46. struct device_node *np = pdev->dev.of_node;
  47. - const __be32 *port_map, *reg_init;
  48. + const __be32 *port_map, *port_disable, *reg_init;
  49. struct switch_dev *swdev;
  50. struct rt305x_esw *esw;
  51. int ret;
  52. @@ -1349,6 +1357,10 @@ static int esw_probe(struct platform_dev
  53. if (port_map)
  54. esw->port_map = be32_to_cpu(*port_map);
  55. + port_disable = of_get_property(np, "mediatek,portdisable", NULL);
  56. + if (port_disable)
  57. + esw->port_disable = be32_to_cpu(*port_disable);
  58. +
  59. reg_init = of_get_property(np, "mediatek,led_polarity", NULL);
  60. if (reg_init)
  61. esw->reg_led_polarity = be32_to_cpu(*reg_init);
  62. --- a/Documentation/devicetree/bindings/net/ralink,rt3050-esw.txt
  63. +++ b/Documentation/devicetree/bindings/net/ralink,rt3050-esw.txt
  64. @@ -16,6 +16,7 @@ Required properties:
  65. Optional properties:
  66. - mediatek,portmap: can be used to choose if the default switch setup is
  67. llllw or wllll
  68. +- mediatek,portdisable: disable unused ethernet PHYs to save power
  69. - mediatek,led_polarity: override the active high/low settings of the leds
  70. Example: