ibm_ocp.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * ibm_ocp.h
  3. *
  4. * (c) Benjamin Herrenschmidt (benh@kernel.crashing.org)
  5. * Mipsys - France
  6. *
  7. * Derived from work (c) Armin Kuster akuster@pacbell.net
  8. *
  9. * Additional support and port to 2.6 LDM/sysfs by
  10. * Matt Porter <mporter@kernel.crashing.org>
  11. * Copyright 2003-2004 MontaVista Software, Inc.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. */
  19. #ifdef __KERNEL__
  20. #ifndef __IBM_OCP_H__
  21. #define __IBM_OCP_H__
  22. #include <asm/types.h>
  23. /*
  24. * IBM 4xx OCP system information
  25. */
  26. struct ocp_sys_info_data {
  27. int opb_bus_freq; /* OPB Bus Frequency (Hz) */
  28. int ebc_bus_freq; /* EBC Bus Frequency (Hz) */
  29. };
  30. extern struct ocp_sys_info_data ocp_sys_info;
  31. /*
  32. * EMAC additional data and sysfs support
  33. *
  34. * Note about mdio_idx: When you have a zmii, it's usually
  35. * not necessary, it covers the case of the 405EP which has
  36. * the MDIO lines on EMAC0 only
  37. *
  38. * Note about phy_map: Per EMAC map of PHY ids which should
  39. * be probed by emac_probe. Different EMACs can have
  40. * overlapping maps.
  41. *
  42. * Note, this map uses inverse logic for bits:
  43. * 0 - id should be probed
  44. * 1 - id should be ignored
  45. *
  46. * Default value of 0x00000000 - will result in usual
  47. * auto-detection logic.
  48. *
  49. */
  50. struct ocp_func_emac_data {
  51. int rgmii_idx; /* RGMII device index or -1 */
  52. int rgmii_mux; /* RGMII input of this EMAC */
  53. int zmii_idx; /* ZMII device index or -1 */
  54. int zmii_mux; /* ZMII input of this EMAC */
  55. int mal_idx; /* MAL device index */
  56. int mal_rx_chan; /* MAL rx channel number */
  57. int mal_tx_chan; /* MAL tx channel number */
  58. int wol_irq; /* WOL interrupt */
  59. int mdio_idx; /* EMAC idx of MDIO master or -1 */
  60. int tah_idx; /* TAH device index or -1 */
  61. int phy_mode; /* PHY type or configurable mode */
  62. u8 mac_addr[6]; /* EMAC mac address */
  63. u32 phy_map; /* EMAC phy map */
  64. u32 phy_feat_exc; /* Excluded PHY features */
  65. };
  66. /* Sysfs support */
  67. #define OCP_SYSFS_EMAC_DATA() \
  68. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, rgmii_idx) \
  69. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, rgmii_mux) \
  70. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, zmii_idx) \
  71. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, zmii_mux) \
  72. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, mal_idx) \
  73. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, mal_rx_chan) \
  74. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, mal_tx_chan) \
  75. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, wol_irq) \
  76. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, mdio_idx) \
  77. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, tah_idx) \
  78. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "%d\n", emac, phy_mode) \
  79. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "0x%08x\n", emac, phy_map) \
  80. OCP_SYSFS_ADDTL(struct ocp_func_emac_data, "0x%08x\n", emac, phy_feat_exc)\
  81. \
  82. void ocp_show_emac_data(struct device *dev) \
  83. { \
  84. device_create_file(dev, &dev_attr_emac_rgmii_idx); \
  85. device_create_file(dev, &dev_attr_emac_rgmii_mux); \
  86. device_create_file(dev, &dev_attr_emac_zmii_idx); \
  87. device_create_file(dev, &dev_attr_emac_zmii_mux); \
  88. device_create_file(dev, &dev_attr_emac_mal_idx); \
  89. device_create_file(dev, &dev_attr_emac_mal_rx_chan); \
  90. device_create_file(dev, &dev_attr_emac_mal_tx_chan); \
  91. device_create_file(dev, &dev_attr_emac_wol_irq); \
  92. device_create_file(dev, &dev_attr_emac_mdio_idx); \
  93. device_create_file(dev, &dev_attr_emac_tah_idx); \
  94. device_create_file(dev, &dev_attr_emac_phy_mode); \
  95. device_create_file(dev, &dev_attr_emac_phy_map); \
  96. device_create_file(dev, &dev_attr_emac_phy_feat_exc); \
  97. }
  98. /*
  99. * PHY mode settings (EMAC <-> ZMII/RGMII bridge <-> PHY)
  100. */
  101. #define PHY_MODE_NA 0
  102. #define PHY_MODE_MII 1
  103. #define PHY_MODE_RMII 2
  104. #define PHY_MODE_SMII 3
  105. #define PHY_MODE_RGMII 4
  106. #define PHY_MODE_TBI 5
  107. #define PHY_MODE_GMII 6
  108. #define PHY_MODE_RTBI 7
  109. #define PHY_MODE_SGMII 8
  110. #ifdef CONFIG_40x
  111. /*
  112. * Helper function to copy MAC addresses from the bd_t to OCP EMAC
  113. * additions.
  114. *
  115. * The range of EMAC indices (inclusive) to be copied are the arguments.
  116. */
  117. static inline void ibm_ocp_set_emac(int start, int end)
  118. {
  119. int i;
  120. struct ocp_def *def;
  121. /* Copy MAC addresses to EMAC additions */
  122. for (i=start; i<=end; i++) {
  123. def = ocp_get_one_device(OCP_VENDOR_IBM, OCP_FUNC_EMAC, i);
  124. if (i == 0)
  125. memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
  126. __res.bi_enetaddr, 6);
  127. #if defined(CONFIG_405EP) || defined(CONFIG_44x)
  128. else if (i == 1)
  129. memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
  130. __res.bi_enet1addr, 6);
  131. #endif
  132. #if defined(CONFIG_440GX)
  133. else if (i == 2)
  134. memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
  135. __res.bi_enet2addr, 6);
  136. else if (i == 3)
  137. memcpy(((struct ocp_func_emac_data *)def->additions)->mac_addr,
  138. __res.bi_enet3addr, 6);
  139. #endif
  140. }
  141. }
  142. #endif
  143. /*
  144. * MAL additional data and sysfs support
  145. */
  146. struct ocp_func_mal_data {
  147. int num_tx_chans; /* Number of TX channels */
  148. int num_rx_chans; /* Number of RX channels */
  149. int txeob_irq; /* TX End Of Buffer IRQ */
  150. int rxeob_irq; /* RX End Of Buffer IRQ */
  151. int txde_irq; /* TX Descriptor Error IRQ */
  152. int rxde_irq; /* RX Descriptor Error IRQ */
  153. int serr_irq; /* MAL System Error IRQ */
  154. int dcr_base; /* MALx_CFG DCR number */
  155. };
  156. #define OCP_SYSFS_MAL_DATA() \
  157. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, num_tx_chans) \
  158. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, num_rx_chans) \
  159. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, txeob_irq) \
  160. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, rxeob_irq) \
  161. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, txde_irq) \
  162. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, rxde_irq) \
  163. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, serr_irq) \
  164. OCP_SYSFS_ADDTL(struct ocp_func_mal_data, "%d\n", mal, dcr_base) \
  165. \
  166. void ocp_show_mal_data(struct device *dev) \
  167. { \
  168. device_create_file(dev, &dev_attr_mal_num_tx_chans); \
  169. device_create_file(dev, &dev_attr_mal_num_rx_chans); \
  170. device_create_file(dev, &dev_attr_mal_txeob_irq); \
  171. device_create_file(dev, &dev_attr_mal_rxeob_irq); \
  172. device_create_file(dev, &dev_attr_mal_txde_irq); \
  173. device_create_file(dev, &dev_attr_mal_rxde_irq); \
  174. device_create_file(dev, &dev_attr_mal_serr_irq); \
  175. device_create_file(dev, &dev_attr_mal_dcr_base); \
  176. }
  177. /*
  178. * IIC additional data and sysfs support
  179. */
  180. struct ocp_func_iic_data {
  181. int fast_mode; /* IIC fast mode enabled */
  182. };
  183. #define OCP_SYSFS_IIC_DATA() \
  184. OCP_SYSFS_ADDTL(struct ocp_func_iic_data, "%d\n", iic, fast_mode) \
  185. \
  186. void ocp_show_iic_data(struct device *dev) \
  187. { \
  188. device_create_file(dev, &dev_attr_iic_fast_mode); \
  189. }
  190. #endif /* __IBM_OCP_H__ */
  191. #endif /* __KERNEL__ */