0011-net-switchlib-add-driver-for-Lantiq-ADM6996I-switch-.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. From c291443dc97dadcf0c6afd04688a7d9f79a221b5 Mon Sep 17 00:00:00 2001
  2. From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
  3. Date: Wed, 29 Aug 2012 22:08:16 +0200
  4. Subject: net: switchlib: add driver for Lantiq ADM6996I 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. @@ -11,6 +11,7 @@ LIB := $(obj)libswitch.o
  9. COBJS-$(CONFIG_SWITCH_MULTI) += switch.o
  10. COBJS-$(CONFIG_SWITCH_PSB697X) += psb697x.o
  11. +COBJS-$(CONFIG_SWITCH_ADM6996I) += adm6996i.o
  12. COBJS := $(COBJS-y)
  13. SRCS := $(COBJS:.o=.c)
  14. --- /dev/null
  15. +++ b/drivers/net/switch/adm6996i.c
  16. @@ -0,0 +1,115 @@
  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 ADM6996I_CHIPID0 0x1020
  29. +#define ADM6996I_CHIPID1 0x0007
  30. +#define ADM6996I_PORT_COUNT 6
  31. +
  32. +#define ADM6996I_REG_P0BC 0x001 /* P0 Basic Control */
  33. +#define ADM6996I_REG_P1BC 0x003 /* P1 Basic Control */
  34. +#define ADM6996I_REG_P2BC 0x005 /* P2 Basic Control */
  35. +#define ADM6996I_REG_P3BC 0x007 /* P3 Basic Control */
  36. +#define ADM6996I_REG_P4BC 0x008 /* P4 Basic Control */
  37. +#define ADM6996I_REG_P5BC 0x009 /* P5 Basic Control */
  38. +
  39. +#define ADM6996I_REG_P0EC 0x002 /* P0 Extended Control */
  40. +#define ADM6996I_REG_P1EC 0x002 /* P1 Extended Control */
  41. +#define ADM6996I_REG_P2EC 0x004 /* P2 Extended Control */
  42. +#define ADM6996I_REG_P3EC 0x004 /* P3 Extended Control */
  43. +#define ADM6996I_REG_P4EC 0x006 /* P4 Extended Control */
  44. +#define ADM6996I_REG_P5EC 0x006 /* P5 Extended Control */
  45. +
  46. +#define ADM6996I_REG_SC4 0x012 /* System Control 4 */
  47. +
  48. +#define ADM6996I_REG_CI0 0xA0 /* Chip Identifier 0 */
  49. +#define ADM6996I_REG_CI1 0xA1 /* Chip Identifier 1 */
  50. +
  51. +#define ADM6996I_REG_PXBC_DEFAULT 0x040F
  52. +#define ADM6996I_REG_PXBC_CROSS_EE (1 << 15)
  53. +#define ADM6996I_REG_PXBC_PD (1 << 5)
  54. +
  55. +#define ADM6996I_REG_SC4_DEFAULT 0x3600
  56. +#define ADM6996I_REG_SC4_LED_ENABLE (1 << 1)
  57. +
  58. +#define ADM6996I_REG_CI0_PC_MASK 0xFFF0
  59. +#define ADM6996I_REG_CI0_VN_MASK 0xF
  60. +#define ADM6996I_REG_CI1_PC_MASK 0xF
  61. +
  62. +
  63. +static inline int adm6996i_mii_read(struct mii_dev *bus, u16 reg)
  64. +{
  65. + int ret;
  66. +
  67. + ret = bus->read(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE, reg & 0x1f);
  68. +
  69. + return ret;
  70. +}
  71. +
  72. +static inline int adm6996i_mii_write(struct mii_dev *bus, u16 reg, u16 val)
  73. +{
  74. + int ret;
  75. +
  76. + ret = bus->write(bus, (reg >> 5) & 0x1f, MDIO_DEVAD_NONE,
  77. + reg & 0x1f, val);
  78. +
  79. + return ret;
  80. +}
  81. +
  82. +static int adm6996i_probe(struct switch_device *dev)
  83. +{
  84. + struct mii_dev *bus = dev->bus;
  85. + u16 ci0, ci1;
  86. +
  87. + ci0 = adm6996i_mii_read(bus, ADM6996I_REG_CI0);
  88. + ci1 = adm6996i_mii_read(bus, ADM6996I_REG_CI1);
  89. +
  90. + ci0 &= ADM6996I_REG_CI0_PC_MASK;
  91. + ci1 &= ADM6996I_REG_CI1_PC_MASK;
  92. +
  93. + if (ci0 == ADM6996I_CHIPID0 && ci1 == ADM6996I_CHIPID1)
  94. + return 0;
  95. +
  96. + return 1;
  97. +}
  98. +
  99. +static void adm6996i_setup(struct switch_device *dev)
  100. +{
  101. + struct mii_dev *bus = dev->bus;
  102. + u16 val;
  103. +
  104. + /*
  105. + * Write default values (Port enable, 100 Mbps, Full Duplex,
  106. + * Auto negotiation, Flow control) and enable crossover auto-detect
  107. + */
  108. + val = ADM6996I_REG_PXBC_DEFAULT | ADM6996I_REG_PXBC_CROSS_EE;
  109. + adm6996i_mii_write(bus, ADM6996I_REG_P0BC, val);
  110. + adm6996i_mii_write(bus, ADM6996I_REG_P1BC, val);
  111. + adm6996i_mii_write(bus, ADM6996I_REG_P2BC, val);
  112. + adm6996i_mii_write(bus, ADM6996I_REG_P3BC, val);
  113. + adm6996i_mii_write(bus, ADM6996I_REG_P4BC, val);
  114. + adm6996i_mii_write(bus, ADM6996I_REG_P5BC, val);
  115. +
  116. + val = ADM6996I_REG_SC4_DEFAULT | ADM6996I_REG_SC4_LED_ENABLE;
  117. + adm6996i_mii_write(bus, ADM6996I_REG_SC4, val);
  118. +}
  119. +
  120. +static struct switch_driver adm6996i_drv = {
  121. + .name = "adm6996i",
  122. +};
  123. +
  124. +void switch_adm6996i_init(void)
  125. +{
  126. + /* For archs with manual relocation */
  127. + adm6996i_drv.probe = adm6996i_probe;
  128. + adm6996i_drv.setup = adm6996i_setup;
  129. +
  130. + switch_driver_register(&adm6996i_drv);
  131. +}
  132. --- a/drivers/net/switch/switch.c
  133. +++ b/drivers/net/switch/switch.c
  134. @@ -20,6 +20,9 @@ void switch_init(void)
  135. #if defined(CONFIG_SWITCH_PSB697X)
  136. switch_psb697x_init();
  137. #endif
  138. +#if defined(CONFIG_SWITCH_ADM6996I)
  139. + switch_adm6996i_init();
  140. +#endif
  141. board_switch_init();
  142. }
  143. --- a/include/switch.h
  144. +++ b/include/switch.h
  145. @@ -98,6 +98,7 @@ static inline void switch_setup(struct s
  146. /* Init functions for supported Switch drivers */
  147. extern void switch_psb697x_init(void);
  148. +extern void switch_adm6996i_init(void);
  149. #endif /* __SWITCH_H */