ssb.h 12 KB

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