ssb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. #ifndef LINUX_SSB_H_
  2. #define LINUX_SSB_H_
  3. #include <linux/device.h>
  4. #include <linux/list.h>
  5. #include <linux/types.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/pci.h>
  8. #include <linux/mod_devicetable.h>
  9. #include <linux/ssb/ssb_regs.h>
  10. struct pcmcia_device;
  11. struct ssb_bus;
  12. struct ssb_driver;
  13. struct ssb_sprom {
  14. u8 revision;
  15. u8 il0mac[6]; /* MAC address for 802.11b/g */
  16. u8 et0mac[6]; /* MAC address for Ethernet */
  17. u8 et1mac[6]; /* MAC address for 802.11a */
  18. u8 et0phyaddr; /* MII address for enet0 */
  19. u8 et1phyaddr; /* MII address for enet1 */
  20. u8 et0mdcport; /* MDIO for enet0 */
  21. u8 et1mdcport; /* MDIO for enet1 */
  22. u8 board_rev; /* Board revision number from SPROM. */
  23. u8 country_code; /* Country Code */
  24. u8 ant_available_a; /* A-PHY antenna available bits (up to 4) */
  25. u8 ant_available_bg; /* B/G-PHY antenna available bits (up to 4) */
  26. u16 pa0b0;
  27. u16 pa0b1;
  28. u16 pa0b2;
  29. u16 pa1b0;
  30. u16 pa1b1;
  31. u16 pa1b2;
  32. u8 gpio0; /* GPIO pin 0 */
  33. u8 gpio1; /* GPIO pin 1 */
  34. u8 gpio2; /* GPIO pin 2 */
  35. u8 gpio3; /* GPIO pin 3 */
  36. u16 maxpwr_a; /* A-PHY Amplifier Max Power (in dBm Q5.2) */
  37. u16 maxpwr_bg; /* B/G-PHY Amplifier Max Power (in dBm Q5.2) */
  38. u8 itssi_a; /* Idle TSSI Target for A-PHY */
  39. u8 itssi_bg; /* Idle TSSI Target for B/G-PHY */
  40. u16 boardflags_lo; /* Boardflags (low 16 bits) */
  41. u16 boardflags_hi; /* Boardflags (high 16 bits) */
  42. /* Antenna gain values for up to 4 antennas
  43. * on each band. Values in dBm/4 (Q5.2). Negative gain means the
  44. * loss in the connectors is bigger than the gain. */
  45. struct {
  46. struct {
  47. s8 a0, a1, a2, a3;
  48. } ghz24; /* 2.4GHz band */
  49. struct {
  50. s8 a0, a1, a2, a3;
  51. } ghz5; /* 5GHz band */
  52. } antenna_gain;
  53. /* TODO - add any parameters needed from rev 2, 3, or 4 SPROMs */
  54. };
  55. /* Information about the PCB the circuitry is soldered on. */
  56. struct ssb_boardinfo {
  57. u16 vendor;
  58. u16 type;
  59. u16 rev;
  60. };
  61. struct ssb_device;
  62. /* Lowlevel read/write operations on the device MMIO.
  63. * Internal, don't use that outside of ssb. */
  64. struct ssb_bus_ops {
  65. u16 (*read16)(struct ssb_device *dev, u16 offset);
  66. u32 (*read32)(struct ssb_device *dev, u16 offset);
  67. void (*write16)(struct ssb_device *dev, u16 offset, u16 value);
  68. void (*write32)(struct ssb_device *dev, u16 offset, u32 value);
  69. };
  70. /* Core-ID values. */
  71. #define SSB_DEV_CHIPCOMMON 0x800
  72. #define SSB_DEV_ILINE20 0x801
  73. #define SSB_DEV_SDRAM 0x803
  74. #define SSB_DEV_PCI 0x804
  75. #define SSB_DEV_MIPS 0x805
  76. #define SSB_DEV_ETHERNET 0x806
  77. #define SSB_DEV_V90 0x807
  78. #define SSB_DEV_USB11_HOSTDEV 0x808
  79. #define SSB_DEV_ADSL 0x809
  80. #define SSB_DEV_ILINE100 0x80A
  81. #define SSB_DEV_IPSEC 0x80B
  82. #define SSB_DEV_PCMCIA 0x80D
  83. #define SSB_DEV_INTERNAL_MEM 0x80E
  84. #define SSB_DEV_MEMC_SDRAM 0x80F
  85. #define SSB_DEV_EXTIF 0x811
  86. #define SSB_DEV_80211 0x812
  87. #define SSB_DEV_MIPS_3302 0x816
  88. #define SSB_DEV_USB11_HOST 0x817
  89. #define SSB_DEV_USB11_DEV 0x818
  90. #define SSB_DEV_USB20_HOST 0x819
  91. #define SSB_DEV_USB20_DEV 0x81A
  92. #define SSB_DEV_SDIO_HOST 0x81B
  93. #define SSB_DEV_ROBOSWITCH 0x81C
  94. #define SSB_DEV_PARA_ATA 0x81D
  95. #define SSB_DEV_SATA_XORDMA 0x81E
  96. #define SSB_DEV_ETHERNET_GBIT 0x81F
  97. #define SSB_DEV_PCIE 0x820
  98. #define SSB_DEV_MIMO_PHY 0x821
  99. #define SSB_DEV_SRAM_CTRLR 0x822
  100. #define SSB_DEV_MINI_MACPHY 0x823
  101. #define SSB_DEV_ARM_1176 0x824
  102. #define SSB_DEV_ARM_7TDMI 0x825
  103. /* Vendor-ID values */
  104. #define SSB_VENDOR_BROADCOM 0x4243
  105. /* Some kernel subsystems poke with dev->drvdata, so we must use the
  106. * following ugly workaround to get from struct device to struct ssb_device */
  107. struct __ssb_dev_wrapper {
  108. struct device dev;
  109. struct ssb_device *sdev;
  110. };
  111. struct ssb_device {
  112. /* Having a copy of the ops pointer in each dev struct
  113. * is an optimization. */
  114. const struct ssb_bus_ops *ops;
  115. struct device *dev;
  116. struct ssb_bus *bus;
  117. struct ssb_device_id id;
  118. u8 core_index;
  119. unsigned int irq;
  120. /* Internal-only stuff follows. */
  121. void *drvdata; /* Per-device data */
  122. void *devtypedata; /* Per-devicetype (eg 802.11) data */
  123. };
  124. /* Go from struct device to struct ssb_device. */
  125. static inline
  126. struct ssb_device * dev_to_ssb_dev(struct device *dev)
  127. {
  128. struct __ssb_dev_wrapper *wrap;
  129. wrap = container_of(dev, struct __ssb_dev_wrapper, dev);
  130. return wrap->sdev;
  131. }
  132. /* Device specific user data */
  133. static inline
  134. void ssb_set_drvdata(struct ssb_device *dev, void *data)
  135. {
  136. dev->drvdata = data;
  137. }
  138. static inline
  139. void * ssb_get_drvdata(struct ssb_device *dev)
  140. {
  141. return dev->drvdata;
  142. }
  143. /* Devicetype specific user data. This is per device-type (not per device) */
  144. void ssb_set_devtypedata(struct ssb_device *dev, void *data);
  145. static inline
  146. void * ssb_get_devtypedata(struct ssb_device *dev)
  147. {
  148. return dev->devtypedata;
  149. }
  150. struct ssb_driver {
  151. const char *name;
  152. const struct ssb_device_id *id_table;
  153. int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id);
  154. void (*remove)(struct ssb_device *dev);
  155. int (*suspend)(struct ssb_device *dev, pm_message_t state);
  156. int (*resume)(struct ssb_device *dev);
  157. void (*shutdown)(struct ssb_device *dev);
  158. struct device_driver drv;
  159. };
  160. #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv)
  161. extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
  162. static inline int ssb_driver_register(struct ssb_driver *drv)
  163. {
  164. return __ssb_driver_register(drv, THIS_MODULE);
  165. }
  166. extern void ssb_driver_unregister(struct ssb_driver *drv);
  167. enum ssb_bustype {
  168. SSB_BUSTYPE_SSB, /* This SSB bus is the system bus */
  169. SSB_BUSTYPE_PCI, /* SSB is connected to PCI bus */
  170. SSB_BUSTYPE_PCMCIA, /* SSB is connected to PCMCIA bus */
  171. };
  172. /* board_vendor */
  173. #define SSB_BOARDVENDOR_BCM 0x14E4 /* Broadcom */
  174. #define SSB_BOARDVENDOR_DELL 0x1028 /* Dell */
  175. #define SSB_BOARDVENDOR_HP 0x0E11 /* HP */
  176. /* board_type */
  177. #define SSB_BOARD_BCM94306MP 0x0418
  178. #define SSB_BOARD_BCM4309G 0x0421
  179. #define SSB_BOARD_BCM4306CB 0x0417
  180. #define SSB_BOARD_BCM4309MP 0x040C
  181. #define SSB_BOARD_MP4318 0x044A
  182. #define SSB_BOARD_BU4306 0x0416
  183. #define SSB_BOARD_BU4309 0x040A
  184. /* chip_package */
  185. #define SSB_CHIPPACK_BCM4712S 1 /* Small 200pin 4712 */
  186. #define SSB_CHIPPACK_BCM4712M 2 /* Medium 225pin 4712 */
  187. #define SSB_CHIPPACK_BCM4712L 0 /* Large 340pin 4712 */
  188. #include <linux/ssb/ssb_driver_chipcommon.h>
  189. #include <linux/ssb/ssb_driver_mips.h>
  190. #include <linux/ssb/ssb_driver_extif.h>
  191. #include <linux/ssb/ssb_driver_pci.h>
  192. struct ssb_bus {
  193. /* The MMIO area. */
  194. void __iomem *mmio;
  195. const struct ssb_bus_ops *ops;
  196. /* The core in the basic address register window. (PCI bus only) */
  197. struct ssb_device *mapped_device;
  198. /* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */
  199. u8 mapped_pcmcia_seg;
  200. /* Lock for core and segment switching.
  201. * On PCMCIA-host busses this is used to protect the whole MMIO access. */
  202. spinlock_t bar_lock;
  203. /* The bus this backplane is running on. */
  204. enum ssb_bustype bustype;
  205. /* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */
  206. struct pci_dev *host_pci;
  207. /* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
  208. struct pcmcia_device *host_pcmcia;
  209. #ifdef CONFIG_SSB_PCIHOST
  210. /* Mutex to protect the SPROM writing. */
  211. struct mutex pci_sprom_mutex;
  212. #endif
  213. /* ID information about the Chip. */
  214. u16 chip_id;
  215. u16 chip_rev;
  216. u16 sprom_size; /* number of words in sprom */
  217. u8 chip_package;
  218. /* List of devices (cores) on the backplane. */
  219. struct ssb_device devices[SSB_MAX_NR_CORES];
  220. u8 nr_devices;
  221. /* Reference count. Number of suspended devices. */
  222. u8 suspend_cnt;
  223. /* Software ID number for this bus. */
  224. unsigned int busnumber;
  225. /* The ChipCommon device (if available). */
  226. struct ssb_chipcommon chipco;
  227. /* The PCI-core device (if available). */
  228. struct ssb_pcicore pcicore;
  229. /* The MIPS-core device (if available). */
  230. struct ssb_mipscore mipscore;
  231. /* The EXTif-core device (if available). */
  232. struct ssb_extif extif;
  233. /* The following structure elements are not available in early
  234. * SSB initialization. Though, they are available for regular
  235. * registered drivers at any stage. So be careful when
  236. * using them in the ssb core code. */
  237. /* ID information about the PCB. */
  238. struct ssb_boardinfo boardinfo;
  239. /* Contents of the SPROM. */
  240. struct ssb_sprom sprom;
  241. /* Internal-only stuff follows. Do not touch. */
  242. struct list_head list;
  243. #ifdef CONFIG_SSB_DEBUG
  244. /* Is the bus already powered up? */
  245. bool powered_up;
  246. int power_warn_count;
  247. #endif /* DEBUG */
  248. };
  249. /* The initialization-invariants. */
  250. struct ssb_init_invariants {
  251. struct ssb_boardinfo boardinfo;
  252. struct ssb_sprom sprom;
  253. };
  254. /* Type of function to fetch the invariants. */
  255. typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
  256. struct ssb_init_invariants *iv);
  257. /* Register a SSB system bus. get_invariants() is called after the
  258. * basic system devices are initialized.
  259. * The invariants are usually fetched from some NVRAM.
  260. * Put the invariants into the struct pointed to by iv. */
  261. extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
  262. unsigned long baseaddr,
  263. ssb_invariants_func_t get_invariants);
  264. #ifdef CONFIG_SSB_PCIHOST
  265. extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
  266. struct pci_dev *host_pci);
  267. #endif /* CONFIG_SSB_PCIHOST */
  268. #ifdef CONFIG_SSB_PCMCIAHOST
  269. extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
  270. struct pcmcia_device *pcmcia_dev,
  271. unsigned long baseaddr);
  272. #endif /* CONFIG_SSB_PCMCIAHOST */
  273. extern void ssb_bus_unregister(struct ssb_bus *bus);
  274. extern u32 ssb_clockspeed(struct ssb_bus *bus);
  275. /* Is the device enabled in hardware? */
  276. int ssb_device_is_enabled(struct ssb_device *dev);
  277. /* Enable a device and pass device-specific SSB_TMSLOW flags.
  278. * If no device-specific flags are available, use 0. */
  279. void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
  280. /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
  281. void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
  282. /* Device MMIO register read/write functions. */
  283. static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
  284. {
  285. return dev->ops->read16(dev, offset);
  286. }
  287. static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
  288. {
  289. return dev->ops->read32(dev, offset);
  290. }
  291. static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
  292. {
  293. dev->ops->write16(dev, offset, value);
  294. }
  295. static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
  296. {
  297. dev->ops->write32(dev, offset, value);
  298. }
  299. /* Translation (routing) bits that need to be ORed to DMA
  300. * addresses before they are given to a device. */
  301. extern u32 ssb_dma_translation(struct ssb_device *dev);
  302. #define SSB_DMA_TRANSLATION_MASK 0xC0000000
  303. #define SSB_DMA_TRANSLATION_SHIFT 30
  304. extern int ssb_dma_set_mask(struct ssb_device *ssb_dev, u64 mask);
  305. #ifdef CONFIG_SSB_PCIHOST
  306. /* PCI-host wrapper driver */
  307. extern int ssb_pcihost_register(struct pci_driver *driver);
  308. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  309. {
  310. pci_unregister_driver(driver);
  311. }
  312. static inline
  313. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  314. {
  315. if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
  316. pci_set_power_state(sdev->bus->host_pci, state);
  317. }
  318. #else
  319. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  320. {
  321. }
  322. static inline
  323. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  324. {
  325. }
  326. #endif /* CONFIG_SSB_PCIHOST */
  327. /* If a driver is shutdown or suspended, call this to signal
  328. * that the bus may be completely powered down. SSB will decide,
  329. * if it's really time to power down the bus, based on if there
  330. * are other devices that want to run. */
  331. extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
  332. /* Before initializing and enabling a device, call this to power-up the bus.
  333. * If you want to allow use of dynamic-power-control, pass the flag.
  334. * Otherwise static always-on powercontrol will be used. */
  335. extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
  336. /* Various helper functions */
  337. extern u32 ssb_admatch_base(u32 adm);
  338. extern u32 ssb_admatch_size(u32 adm);
  339. #endif /* LINUX_SSB_H_ */