ssb.h 13 KB

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