ssb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. /* Pointer to the device that has to be used for
  117. * any DMA related operation. */
  118. struct device *dma_dev;
  119. struct ssb_bus *bus;
  120. struct ssb_device_id id;
  121. u8 core_index;
  122. unsigned int irq;
  123. /* Internal-only stuff follows. */
  124. void *drvdata; /* Per-device data */
  125. void *devtypedata; /* Per-devicetype (eg 802.11) data */
  126. };
  127. /* Go from struct device to struct ssb_device. */
  128. static inline
  129. struct ssb_device * dev_to_ssb_dev(struct device *dev)
  130. {
  131. struct __ssb_dev_wrapper *wrap;
  132. wrap = container_of(dev, struct __ssb_dev_wrapper, dev);
  133. return wrap->sdev;
  134. }
  135. /* Device specific user data */
  136. static inline
  137. void ssb_set_drvdata(struct ssb_device *dev, void *data)
  138. {
  139. dev->drvdata = data;
  140. }
  141. static inline
  142. void * ssb_get_drvdata(struct ssb_device *dev)
  143. {
  144. return dev->drvdata;
  145. }
  146. /* Devicetype specific user data. This is per device-type (not per device) */
  147. void ssb_set_devtypedata(struct ssb_device *dev, void *data);
  148. static inline
  149. void * ssb_get_devtypedata(struct ssb_device *dev)
  150. {
  151. return dev->devtypedata;
  152. }
  153. struct ssb_driver {
  154. const char *name;
  155. const struct ssb_device_id *id_table;
  156. int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id);
  157. void (*remove)(struct ssb_device *dev);
  158. int (*suspend)(struct ssb_device *dev, pm_message_t state);
  159. int (*resume)(struct ssb_device *dev);
  160. void (*shutdown)(struct ssb_device *dev);
  161. struct device_driver drv;
  162. };
  163. #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv)
  164. extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
  165. static inline int ssb_driver_register(struct ssb_driver *drv)
  166. {
  167. return __ssb_driver_register(drv, THIS_MODULE);
  168. }
  169. extern void ssb_driver_unregister(struct ssb_driver *drv);
  170. enum ssb_bustype {
  171. SSB_BUSTYPE_SSB, /* This SSB bus is the system bus */
  172. SSB_BUSTYPE_PCI, /* SSB is connected to PCI bus */
  173. SSB_BUSTYPE_PCMCIA, /* SSB is connected to PCMCIA bus */
  174. };
  175. /* board_vendor */
  176. #define SSB_BOARDVENDOR_BCM 0x14E4 /* Broadcom */
  177. #define SSB_BOARDVENDOR_DELL 0x1028 /* Dell */
  178. #define SSB_BOARDVENDOR_HP 0x0E11 /* HP */
  179. /* board_type */
  180. #define SSB_BOARD_BCM94306MP 0x0418
  181. #define SSB_BOARD_BCM4309G 0x0421
  182. #define SSB_BOARD_BCM4306CB 0x0417
  183. #define SSB_BOARD_BCM4309MP 0x040C
  184. #define SSB_BOARD_MP4318 0x044A
  185. #define SSB_BOARD_BU4306 0x0416
  186. #define SSB_BOARD_BU4309 0x040A
  187. /* chip_package */
  188. #define SSB_CHIPPACK_BCM4712S 1 /* Small 200pin 4712 */
  189. #define SSB_CHIPPACK_BCM4712M 2 /* Medium 225pin 4712 */
  190. #define SSB_CHIPPACK_BCM4712L 0 /* Large 340pin 4712 */
  191. #include <linux/ssb/ssb_driver_chipcommon.h>
  192. #include <linux/ssb/ssb_driver_mips.h>
  193. #include <linux/ssb/ssb_driver_extif.h>
  194. #include <linux/ssb/ssb_driver_pci.h>
  195. struct ssb_bus {
  196. /* The MMIO area. */
  197. void __iomem *mmio;
  198. const struct ssb_bus_ops *ops;
  199. /* The core in the basic address register window. (PCI bus only) */
  200. struct ssb_device *mapped_device;
  201. /* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */
  202. u8 mapped_pcmcia_seg;
  203. /* Lock for core and segment switching.
  204. * On PCMCIA-host busses this is used to protect the whole MMIO access. */
  205. spinlock_t bar_lock;
  206. /* The bus this backplane is running on. */
  207. enum ssb_bustype bustype;
  208. /* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */
  209. struct pci_dev *host_pci;
  210. /* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
  211. struct pcmcia_device *host_pcmcia;
  212. #ifdef CONFIG_SSB_PCIHOST
  213. /* Mutex to protect the SPROM writing. */
  214. struct mutex pci_sprom_mutex;
  215. #endif
  216. /* ID information about the Chip. */
  217. u16 chip_id;
  218. u16 chip_rev;
  219. u16 sprom_size; /* number of words in sprom */
  220. u8 chip_package;
  221. /* List of devices (cores) on the backplane. */
  222. struct ssb_device devices[SSB_MAX_NR_CORES];
  223. u8 nr_devices;
  224. /* Reference count. Number of suspended devices. */
  225. u8 suspend_cnt;
  226. /* Software ID number for this bus. */
  227. unsigned int busnumber;
  228. /* The ChipCommon device (if available). */
  229. struct ssb_chipcommon chipco;
  230. /* The PCI-core device (if available). */
  231. struct ssb_pcicore pcicore;
  232. /* The MIPS-core device (if available). */
  233. struct ssb_mipscore mipscore;
  234. /* The EXTif-core device (if available). */
  235. struct ssb_extif extif;
  236. /* The following structure elements are not available in early
  237. * SSB initialization. Though, they are available for regular
  238. * registered drivers at any stage. So be careful when
  239. * using them in the ssb core code. */
  240. /* ID information about the PCB. */
  241. struct ssb_boardinfo boardinfo;
  242. /* Contents of the SPROM. */
  243. struct ssb_sprom sprom;
  244. /* If the board has a cardbus slot, this is set to true. */
  245. bool has_cardbus_slot;
  246. #ifdef CONFIG_SSB_EMBEDDED
  247. /* Lock for GPIO register access. */
  248. spinlock_t gpio_lock;
  249. #endif /* EMBEDDED */
  250. /* Internal-only stuff follows. Do not touch. */
  251. struct list_head list;
  252. #ifdef CONFIG_SSB_DEBUG
  253. /* Is the bus already powered up? */
  254. bool powered_up;
  255. int power_warn_count;
  256. #endif /* DEBUG */
  257. };
  258. /* The initialization-invariants. */
  259. struct ssb_init_invariants {
  260. /* Versioning information about the PCB. */
  261. struct ssb_boardinfo boardinfo;
  262. /* The SPROM information. That's either stored in an
  263. * EEPROM or NVRAM on the board. */
  264. struct ssb_sprom sprom;
  265. /* If the board has a cardbus slot, this is set to true. */
  266. bool has_cardbus_slot;
  267. };
  268. /* Type of function to fetch the invariants. */
  269. typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
  270. struct ssb_init_invariants *iv);
  271. /* Register a SSB system bus. get_invariants() is called after the
  272. * basic system devices are initialized.
  273. * The invariants are usually fetched from some NVRAM.
  274. * Put the invariants into the struct pointed to by iv. */
  275. extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
  276. unsigned long baseaddr,
  277. ssb_invariants_func_t get_invariants);
  278. #ifdef CONFIG_SSB_PCIHOST
  279. extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
  280. struct pci_dev *host_pci);
  281. #endif /* CONFIG_SSB_PCIHOST */
  282. #ifdef CONFIG_SSB_PCMCIAHOST
  283. extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
  284. struct pcmcia_device *pcmcia_dev,
  285. unsigned long baseaddr);
  286. #endif /* CONFIG_SSB_PCMCIAHOST */
  287. extern void ssb_bus_unregister(struct ssb_bus *bus);
  288. extern u32 ssb_clockspeed(struct ssb_bus *bus);
  289. /* Is the device enabled in hardware? */
  290. int ssb_device_is_enabled(struct ssb_device *dev);
  291. /* Enable a device and pass device-specific SSB_TMSLOW flags.
  292. * If no device-specific flags are available, use 0. */
  293. void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
  294. /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
  295. void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
  296. /* Device MMIO register read/write functions. */
  297. static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
  298. {
  299. return dev->ops->read16(dev, offset);
  300. }
  301. static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
  302. {
  303. return dev->ops->read32(dev, offset);
  304. }
  305. static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
  306. {
  307. dev->ops->write16(dev, offset, value);
  308. }
  309. static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
  310. {
  311. dev->ops->write32(dev, offset, value);
  312. }
  313. /* Translation (routing) bits that need to be ORed to DMA
  314. * addresses before they are given to a device. */
  315. extern u32 ssb_dma_translation(struct ssb_device *dev);
  316. #define SSB_DMA_TRANSLATION_MASK 0xC0000000
  317. #define SSB_DMA_TRANSLATION_SHIFT 30
  318. extern int ssb_dma_set_mask(struct ssb_device *ssb_dev, u64 mask);
  319. #ifdef CONFIG_SSB_PCIHOST
  320. /* PCI-host wrapper driver */
  321. extern int ssb_pcihost_register(struct pci_driver *driver);
  322. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  323. {
  324. pci_unregister_driver(driver);
  325. }
  326. static inline
  327. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  328. {
  329. if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
  330. pci_set_power_state(sdev->bus->host_pci, state);
  331. }
  332. #else
  333. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  334. {
  335. }
  336. static inline
  337. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  338. {
  339. }
  340. #endif /* CONFIG_SSB_PCIHOST */
  341. /* If a driver is shutdown or suspended, call this to signal
  342. * that the bus may be completely powered down. SSB will decide,
  343. * if it's really time to power down the bus, based on if there
  344. * are other devices that want to run. */
  345. extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
  346. /* Before initializing and enabling a device, call this to power-up the bus.
  347. * If you want to allow use of dynamic-power-control, pass the flag.
  348. * Otherwise static always-on powercontrol will be used. */
  349. extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
  350. /* Various helper functions */
  351. extern u32 ssb_admatch_base(u32 adm);
  352. extern u32 ssb_admatch_size(u32 adm);
  353. #endif /* LINUX_SSB_H_ */