b53_priv.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * B53 common definitions
  3. *
  4. * Copyright (C) 2011-2013 Jonas Gorski <[email protected]>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef __B53_PRIV_H
  19. #define __B53_PRIV_H
  20. #include <linux/kernel.h>
  21. #include <linux/mutex.h>
  22. #include <linux/switch.h>
  23. struct b53_device;
  24. struct b53_io_ops {
  25. int (*read8)(struct b53_device *dev, u8 page, u8 reg, u8 *value);
  26. int (*read16)(struct b53_device *dev, u8 page, u8 reg, u16 *value);
  27. int (*read32)(struct b53_device *dev, u8 page, u8 reg, u32 *value);
  28. int (*read48)(struct b53_device *dev, u8 page, u8 reg, u64 *value);
  29. int (*read64)(struct b53_device *dev, u8 page, u8 reg, u64 *value);
  30. int (*write8)(struct b53_device *dev, u8 page, u8 reg, u8 value);
  31. int (*write16)(struct b53_device *dev, u8 page, u8 reg, u16 value);
  32. int (*write32)(struct b53_device *dev, u8 page, u8 reg, u32 value);
  33. int (*write48)(struct b53_device *dev, u8 page, u8 reg, u64 value);
  34. int (*write64)(struct b53_device *dev, u8 page, u8 reg, u64 value);
  35. int (*phy_read16)(struct b53_device *dev, int addr, u8 reg, u16 *value);
  36. int (*phy_write16)(struct b53_device *dev, int addr, u8 reg, u16 value);
  37. };
  38. enum {
  39. BCM5325_DEVICE_ID = 0x25,
  40. BCM5365_DEVICE_ID = 0x65,
  41. BCM5395_DEVICE_ID = 0x95,
  42. BCM5397_DEVICE_ID = 0x97,
  43. BCM5398_DEVICE_ID = 0x98,
  44. BCM53115_DEVICE_ID = 0x53115,
  45. BCM53125_DEVICE_ID = 0x53125,
  46. BCM53128_DEVICE_ID = 0x53128,
  47. BCM63XX_DEVICE_ID = 0x6300,
  48. BCM53010_DEVICE_ID = 0x53010,
  49. BCM53011_DEVICE_ID = 0x53011,
  50. BCM53012_DEVICE_ID = 0x53012,
  51. BCM53018_DEVICE_ID = 0x53018,
  52. BCM53019_DEVICE_ID = 0x53019,
  53. };
  54. #define B53_N_PORTS 9
  55. #define B53_N_PORTS_25 6
  56. struct b53_vlan {
  57. unsigned int members:B53_N_PORTS;
  58. unsigned int untag:B53_N_PORTS;
  59. };
  60. struct b53_port {
  61. unsigned int pvid:12;
  62. };
  63. struct b53_device {
  64. struct switch_dev sw_dev;
  65. struct b53_platform_data *pdata;
  66. struct mutex reg_mutex;
  67. const struct b53_io_ops *ops;
  68. /* chip specific data */
  69. u32 chip_id;
  70. u8 core_rev;
  71. u8 vta_regs[3];
  72. u8 duplex_reg;
  73. u8 jumbo_pm_reg;
  74. u8 jumbo_size_reg;
  75. int reset_gpio;
  76. /* used ports mask */
  77. u16 enabled_ports;
  78. /* connect specific data */
  79. u8 current_page;
  80. struct device *dev;
  81. void *priv;
  82. /* run time configuration */
  83. unsigned enable_vlan:1;
  84. unsigned enable_jumbo:1;
  85. unsigned allow_vid_4095:1;
  86. struct b53_port *ports;
  87. struct b53_vlan *vlans;
  88. char *buf;
  89. };
  90. #define b53_for_each_port(dev, i) \
  91. for (i = 0; i < B53_N_PORTS; i++) \
  92. if (dev->enabled_ports & BIT(i))
  93. static inline int is5325(struct b53_device *dev)
  94. {
  95. return dev->chip_id == BCM5325_DEVICE_ID;
  96. }
  97. static inline int is5365(struct b53_device *dev)
  98. {
  99. #ifdef CONFIG_BCM47XX
  100. return dev->chip_id == BCM5365_DEVICE_ID;
  101. #else
  102. return 0;
  103. #endif
  104. }
  105. static inline int is5397_98(struct b53_device *dev)
  106. {
  107. return dev->chip_id == BCM5397_DEVICE_ID ||
  108. dev->chip_id == BCM5398_DEVICE_ID;
  109. }
  110. static inline int is539x(struct b53_device *dev)
  111. {
  112. return dev->chip_id == BCM5395_DEVICE_ID ||
  113. dev->chip_id == BCM5397_DEVICE_ID ||
  114. dev->chip_id == BCM5398_DEVICE_ID;
  115. }
  116. static inline int is531x5(struct b53_device *dev)
  117. {
  118. return dev->chip_id == BCM53115_DEVICE_ID ||
  119. dev->chip_id == BCM53125_DEVICE_ID ||
  120. dev->chip_id == BCM53128_DEVICE_ID;
  121. }
  122. static inline int is63xx(struct b53_device *dev)
  123. {
  124. #ifdef CONFIG_BCM63XX
  125. return dev->chip_id == BCM63XX_DEVICE_ID;
  126. #else
  127. return 0;
  128. #endif
  129. }
  130. static inline int is5301x(struct b53_device *dev)
  131. {
  132. return dev->chip_id == BCM53010_DEVICE_ID ||
  133. dev->chip_id == BCM53011_DEVICE_ID ||
  134. dev->chip_id == BCM53012_DEVICE_ID ||
  135. dev->chip_id == BCM53018_DEVICE_ID ||
  136. dev->chip_id == BCM53019_DEVICE_ID;
  137. }
  138. #define B53_CPU_PORT_25 5
  139. #define B53_CPU_PORT 8
  140. static inline int is_cpu_port(struct b53_device *dev, int port)
  141. {
  142. return dev->sw_dev.cpu_port == port;
  143. }
  144. static inline int is_imp_port(struct b53_device *dev, int port)
  145. {
  146. if (is5325(dev) || is5365(dev))
  147. return port == B53_CPU_PORT_25;
  148. else
  149. return port == B53_CPU_PORT;
  150. }
  151. static inline struct b53_device *sw_to_b53(struct switch_dev *sw)
  152. {
  153. return container_of(sw, struct b53_device, sw_dev);
  154. }
  155. struct b53_device *b53_swconfig_switch_alloc(struct device *base, struct b53_io_ops *ops,
  156. void *priv);
  157. int b53_swconfig_switch_detect(struct b53_device *dev);
  158. int b53_swconfig_switch_register(struct b53_device *dev);
  159. static inline void b53_switch_remove(struct b53_device *dev)
  160. {
  161. unregister_switch(&dev->sw_dev);
  162. }
  163. static inline int b53_read8(struct b53_device *dev, u8 page, u8 reg, u8 *val)
  164. {
  165. int ret;
  166. mutex_lock(&dev->reg_mutex);
  167. ret = dev->ops->read8(dev, page, reg, val);
  168. mutex_unlock(&dev->reg_mutex);
  169. return ret;
  170. }
  171. static inline int b53_read16(struct b53_device *dev, u8 page, u8 reg, u16 *val)
  172. {
  173. int ret;
  174. mutex_lock(&dev->reg_mutex);
  175. ret = dev->ops->read16(dev, page, reg, val);
  176. mutex_unlock(&dev->reg_mutex);
  177. return ret;
  178. }
  179. static inline int b53_read32(struct b53_device *dev, u8 page, u8 reg, u32 *val)
  180. {
  181. int ret;
  182. mutex_lock(&dev->reg_mutex);
  183. ret = dev->ops->read32(dev, page, reg, val);
  184. mutex_unlock(&dev->reg_mutex);
  185. return ret;
  186. }
  187. static inline int b53_read48(struct b53_device *dev, u8 page, u8 reg, u64 *val)
  188. {
  189. int ret;
  190. mutex_lock(&dev->reg_mutex);
  191. ret = dev->ops->read48(dev, page, reg, val);
  192. mutex_unlock(&dev->reg_mutex);
  193. return ret;
  194. }
  195. static inline int b53_read64(struct b53_device *dev, u8 page, u8 reg, u64 *val)
  196. {
  197. int ret;
  198. mutex_lock(&dev->reg_mutex);
  199. ret = dev->ops->read64(dev, page, reg, val);
  200. mutex_unlock(&dev->reg_mutex);
  201. return ret;
  202. }
  203. static inline int b53_write8(struct b53_device *dev, u8 page, u8 reg, u8 value)
  204. {
  205. int ret;
  206. mutex_lock(&dev->reg_mutex);
  207. ret = dev->ops->write8(dev, page, reg, value);
  208. mutex_unlock(&dev->reg_mutex);
  209. return ret;
  210. }
  211. static inline int b53_write16(struct b53_device *dev, u8 page, u8 reg,
  212. u16 value)
  213. {
  214. int ret;
  215. mutex_lock(&dev->reg_mutex);
  216. ret = dev->ops->write16(dev, page, reg, value);
  217. mutex_unlock(&dev->reg_mutex);
  218. return ret;
  219. }
  220. static inline int b53_write32(struct b53_device *dev, u8 page, u8 reg,
  221. u32 value)
  222. {
  223. int ret;
  224. mutex_lock(&dev->reg_mutex);
  225. ret = dev->ops->write32(dev, page, reg, value);
  226. mutex_unlock(&dev->reg_mutex);
  227. return ret;
  228. }
  229. static inline int b53_write48(struct b53_device *dev, u8 page, u8 reg,
  230. u64 value)
  231. {
  232. int ret;
  233. mutex_lock(&dev->reg_mutex);
  234. ret = dev->ops->write48(dev, page, reg, value);
  235. mutex_unlock(&dev->reg_mutex);
  236. return ret;
  237. }
  238. static inline int b53_write64(struct b53_device *dev, u8 page, u8 reg,
  239. u64 value)
  240. {
  241. int ret;
  242. mutex_lock(&dev->reg_mutex);
  243. ret = dev->ops->write64(dev, page, reg, value);
  244. mutex_unlock(&dev->reg_mutex);
  245. return ret;
  246. }
  247. #ifdef CONFIG_BCM47XX
  248. #include <bcm47xx_board.h>
  249. #endif
  250. #include <linux/version.h>
  251. #include <linux/bcm47xx_nvram.h>
  252. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  253. {
  254. #ifdef CONFIG_BCM47XX
  255. enum bcm47xx_board board = bcm47xx_board_get();
  256. switch (board) {
  257. case BCM47XX_BOARD_LINKSYS_WRT300NV11:
  258. case BCM47XX_BOARD_LINKSYS_WRT310NV1:
  259. return 8;
  260. default:
  261. break;
  262. }
  263. #endif
  264. return bcm47xx_nvram_gpio_pin("robo_reset");
  265. }
  266. #endif