ssb.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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/dma-mapping.h>
  10. #include <linux/ssb/ssb_regs.h>
  11. struct pcmcia_device;
  12. struct ssb_bus;
  13. struct ssb_driver;
  14. struct ssb_sprom {
  15. u8 revision;
  16. u8 il0mac[6]; /* MAC address for 802.11b/g */
  17. u8 et0mac[6]; /* MAC address for Ethernet */
  18. u8 et1mac[6]; /* MAC address for 802.11a */
  19. u8 et0phyaddr; /* MII address for enet0 */
  20. u8 et1phyaddr; /* MII address for enet1 */
  21. u8 et0mdcport; /* MDIO for enet0 */
  22. u8 et1mdcport; /* MDIO for enet1 */
  23. u8 board_rev; /* Board revision number from SPROM. */
  24. u8 country_code; /* Country Code */
  25. u8 ant_available_a; /* 2GHz antenna available bits (up to 4) */
  26. u8 ant_available_bg; /* 5GHz antenna available bits (up to 4) */
  27. u16 pa0b0;
  28. u16 pa0b1;
  29. u16 pa0b2;
  30. u16 pa1b0;
  31. u16 pa1b1;
  32. u16 pa1b2;
  33. u16 pa1lob0;
  34. u16 pa1lob1;
  35. u16 pa1lob2;
  36. u16 pa1hib0;
  37. u16 pa1hib1;
  38. u16 pa1hib2;
  39. u8 gpio0; /* GPIO pin 0 */
  40. u8 gpio1; /* GPIO pin 1 */
  41. u8 gpio2; /* GPIO pin 2 */
  42. u8 gpio3; /* GPIO pin 3 */
  43. u16 maxpwr_bg; /* 2.4GHz Amplifier Max Power (in dBm Q5.2) */
  44. u16 maxpwr_al; /* 5.2GHz Amplifier Max Power (in dBm Q5.2) */
  45. u16 maxpwr_a; /* 5.3GHz Amplifier Max Power (in dBm Q5.2) */
  46. u16 maxpwr_ah; /* 5.8GHz Amplifier Max Power (in dBm Q5.2) */
  47. u8 itssi_a; /* Idle TSSI Target for A-PHY */
  48. u8 itssi_bg; /* Idle TSSI Target for B/G-PHY */
  49. u8 tri2g; /* 2.4GHz TX isolation */
  50. u8 tri5gl; /* 5.2GHz TX isolation */
  51. u8 tri5g; /* 5.3GHz TX isolation */
  52. u8 tri5gh; /* 5.8GHz TX isolation */
  53. u8 rxpo2g; /* 2GHz RX power offset */
  54. u8 rxpo5g; /* 5GHz RX power offset */
  55. u8 rssisav2g; /* 2GHz RSSI params */
  56. u8 rssismc2g;
  57. u8 rssismf2g;
  58. u8 bxa2g; /* 2GHz BX arch */
  59. u8 rssisav5g; /* 5GHz RSSI params */
  60. u8 rssismc5g;
  61. u8 rssismf5g;
  62. u8 bxa5g; /* 5GHz BX arch */
  63. u16 cck2gpo; /* CCK power offset */
  64. u32 ofdm2gpo; /* 2.4GHz OFDM power offset */
  65. u32 ofdm5glpo; /* 5.2GHz OFDM power offset */
  66. u32 ofdm5gpo; /* 5.3GHz OFDM power offset */
  67. u32 ofdm5ghpo; /* 5.8GHz OFDM power offset */
  68. u16 boardflags_lo; /* Board flags (bits 0-15) */
  69. u16 boardflags_hi; /* Board flags (bits 16-31) */
  70. u16 boardflags2_lo; /* Board flags (bits 32-47) */
  71. u16 boardflags2_hi; /* Board flags (bits 48-63) */
  72. /* TODO store board flags in a single u64 */
  73. /* Antenna gain values for up to 4 antennas
  74. * on each band. Values in dBm/4 (Q5.2). Negative gain means the
  75. * loss in the connectors is bigger than the gain. */
  76. struct {
  77. struct {
  78. s8 a0, a1, a2, a3;
  79. } ghz24; /* 2.4GHz band */
  80. struct {
  81. s8 a0, a1, a2, a3;
  82. } ghz5; /* 5GHz band */
  83. } antenna_gain;
  84. /* TODO - add any parameters needed from rev 2, 3, 4, 5 or 8 SPROMs */
  85. };
  86. /* Information about the PCB the circuitry is soldered on. */
  87. struct ssb_boardinfo {
  88. u16 vendor;
  89. u16 type;
  90. u16 rev;
  91. };
  92. struct ssb_device;
  93. /* Lowlevel read/write operations on the device MMIO.
  94. * Internal, don't use that outside of ssb. */
  95. struct ssb_bus_ops {
  96. u8 (*read8)(struct ssb_device *dev, u16 offset);
  97. u16 (*read16)(struct ssb_device *dev, u16 offset);
  98. u32 (*read32)(struct ssb_device *dev, u16 offset);
  99. void (*write8)(struct ssb_device *dev, u16 offset, u8 value);
  100. void (*write16)(struct ssb_device *dev, u16 offset, u16 value);
  101. void (*write32)(struct ssb_device *dev, u16 offset, u32 value);
  102. #ifdef CONFIG_SSB_BLOCKIO
  103. void (*block_read)(struct ssb_device *dev, void *buffer,
  104. size_t count, u16 offset, u8 reg_width);
  105. void (*block_write)(struct ssb_device *dev, const void *buffer,
  106. size_t count, u16 offset, u8 reg_width);
  107. #endif
  108. };
  109. /* Core-ID values. */
  110. #define SSB_DEV_CHIPCOMMON 0x800
  111. #define SSB_DEV_ILINE20 0x801
  112. #define SSB_DEV_SDRAM 0x803
  113. #define SSB_DEV_PCI 0x804
  114. #define SSB_DEV_MIPS 0x805
  115. #define SSB_DEV_ETHERNET 0x806
  116. #define SSB_DEV_V90 0x807
  117. #define SSB_DEV_USB11_HOSTDEV 0x808
  118. #define SSB_DEV_ADSL 0x809
  119. #define SSB_DEV_ILINE100 0x80A
  120. #define SSB_DEV_IPSEC 0x80B
  121. #define SSB_DEV_PCMCIA 0x80D
  122. #define SSB_DEV_INTERNAL_MEM 0x80E
  123. #define SSB_DEV_MEMC_SDRAM 0x80F
  124. #define SSB_DEV_EXTIF 0x811
  125. #define SSB_DEV_80211 0x812
  126. #define SSB_DEV_MIPS_3302 0x816
  127. #define SSB_DEV_USB11_HOST 0x817
  128. #define SSB_DEV_USB11_DEV 0x818
  129. #define SSB_DEV_USB20_HOST 0x819
  130. #define SSB_DEV_USB20_DEV 0x81A
  131. #define SSB_DEV_SDIO_HOST 0x81B
  132. #define SSB_DEV_ROBOSWITCH 0x81C
  133. #define SSB_DEV_PARA_ATA 0x81D
  134. #define SSB_DEV_SATA_XORDMA 0x81E
  135. #define SSB_DEV_ETHERNET_GBIT 0x81F
  136. #define SSB_DEV_PCIE 0x820
  137. #define SSB_DEV_MIMO_PHY 0x821
  138. #define SSB_DEV_SRAM_CTRLR 0x822
  139. #define SSB_DEV_MINI_MACPHY 0x823
  140. #define SSB_DEV_ARM_1176 0x824
  141. #define SSB_DEV_ARM_7TDMI 0x825
  142. /* Vendor-ID values */
  143. #define SSB_VENDOR_BROADCOM 0x4243
  144. /* Some kernel subsystems poke with dev->drvdata, so we must use the
  145. * following ugly workaround to get from struct device to struct ssb_device */
  146. struct __ssb_dev_wrapper {
  147. struct device dev;
  148. struct ssb_device *sdev;
  149. };
  150. struct ssb_device {
  151. /* Having a copy of the ops pointer in each dev struct
  152. * is an optimization. */
  153. const struct ssb_bus_ops *ops;
  154. struct device *dev;
  155. struct ssb_bus *bus;
  156. struct ssb_device_id id;
  157. u8 core_index;
  158. unsigned int irq;
  159. /* Internal-only stuff follows. */
  160. void *drvdata; /* Per-device data */
  161. void *devtypedata; /* Per-devicetype (eg 802.11) data */
  162. };
  163. /* Go from struct device to struct ssb_device. */
  164. static inline
  165. struct ssb_device * dev_to_ssb_dev(struct device *dev)
  166. {
  167. struct __ssb_dev_wrapper *wrap;
  168. wrap = container_of(dev, struct __ssb_dev_wrapper, dev);
  169. return wrap->sdev;
  170. }
  171. /* Device specific user data */
  172. static inline
  173. void ssb_set_drvdata(struct ssb_device *dev, void *data)
  174. {
  175. dev->drvdata = data;
  176. }
  177. static inline
  178. void * ssb_get_drvdata(struct ssb_device *dev)
  179. {
  180. return dev->drvdata;
  181. }
  182. /* Devicetype specific user data. This is per device-type (not per device) */
  183. void ssb_set_devtypedata(struct ssb_device *dev, void *data);
  184. static inline
  185. void * ssb_get_devtypedata(struct ssb_device *dev)
  186. {
  187. return dev->devtypedata;
  188. }
  189. struct ssb_driver {
  190. const char *name;
  191. const struct ssb_device_id *id_table;
  192. int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id);
  193. void (*remove)(struct ssb_device *dev);
  194. int (*suspend)(struct ssb_device *dev, pm_message_t state);
  195. int (*resume)(struct ssb_device *dev);
  196. void (*shutdown)(struct ssb_device *dev);
  197. struct device_driver drv;
  198. };
  199. #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv)
  200. extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
  201. static inline int ssb_driver_register(struct ssb_driver *drv)
  202. {
  203. return __ssb_driver_register(drv, THIS_MODULE);
  204. }
  205. extern void ssb_driver_unregister(struct ssb_driver *drv);
  206. enum ssb_bustype {
  207. SSB_BUSTYPE_SSB, /* This SSB bus is the system bus */
  208. SSB_BUSTYPE_PCI, /* SSB is connected to PCI bus */
  209. SSB_BUSTYPE_PCMCIA, /* SSB is connected to PCMCIA bus */
  210. SSB_BUSTYPE_SDIO, /* SSB is connected to SDIO bus */
  211. };
  212. /* board_vendor */
  213. #define SSB_BOARDVENDOR_BCM 0x14E4 /* Broadcom */
  214. #define SSB_BOARDVENDOR_DELL 0x1028 /* Dell */
  215. #define SSB_BOARDVENDOR_HP 0x0E11 /* HP */
  216. /* board_type */
  217. #define SSB_BOARD_BCM94306MP 0x0418
  218. #define SSB_BOARD_BCM4309G 0x0421
  219. #define SSB_BOARD_BCM4306CB 0x0417
  220. #define SSB_BOARD_BCM4309MP 0x040C
  221. #define SSB_BOARD_MP4318 0x044A
  222. #define SSB_BOARD_BU4306 0x0416
  223. #define SSB_BOARD_BU4309 0x040A
  224. /* chip_package */
  225. #define SSB_CHIPPACK_BCM4712S 1 /* Small 200pin 4712 */
  226. #define SSB_CHIPPACK_BCM4712M 2 /* Medium 225pin 4712 */
  227. #define SSB_CHIPPACK_BCM4712L 0 /* Large 340pin 4712 */
  228. #include <linux/ssb/ssb_driver_chipcommon.h>
  229. #include <linux/ssb/ssb_driver_mips.h>
  230. #include <linux/ssb/ssb_driver_extif.h>
  231. #include <linux/ssb/ssb_driver_pci.h>
  232. struct ssb_bus {
  233. /* The MMIO area. */
  234. void __iomem *mmio;
  235. const struct ssb_bus_ops *ops;
  236. /* The core currently mapped into the MMIO window.
  237. * Not valid on all host-buses. So don't use outside of SSB. */
  238. struct ssb_device *mapped_device;
  239. union {
  240. /* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */
  241. u8 mapped_pcmcia_seg;
  242. /* Current SSB base address window for SDIO. */
  243. u32 sdio_sbaddr;
  244. };
  245. /* Lock for core and segment switching.
  246. * On PCMCIA-host busses this is used to protect the whole MMIO access. */
  247. spinlock_t bar_lock;
  248. /* The host-bus this backplane is running on. */
  249. enum ssb_bustype bustype;
  250. /* Pointers to the host-bus. Check bustype before using any of these pointers. */
  251. union {
  252. /* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */
  253. struct pci_dev *host_pci;
  254. /* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
  255. struct pcmcia_device *host_pcmcia;
  256. /* Pointer to the SDIO device (only if bustype == SSB_BUSTYPE_SDIO). */
  257. struct sdio_func *host_sdio;
  258. };
  259. /* See enum ssb_quirks */
  260. unsigned int quirks;
  261. #ifdef CONFIG_SSB_SPROM
  262. /* Mutex to protect the SPROM writing. */
  263. struct mutex sprom_mutex;
  264. #endif
  265. /* ID information about the Chip. */
  266. u16 chip_id;
  267. u16 chip_rev;
  268. u16 sprom_size; /* number of words in sprom */
  269. u8 chip_package;
  270. /* List of devices (cores) on the backplane. */
  271. struct ssb_device devices[SSB_MAX_NR_CORES];
  272. u8 nr_devices;
  273. /* Software ID number for this bus. */
  274. unsigned int busnumber;
  275. /* The ChipCommon device (if available). */
  276. struct ssb_chipcommon chipco;
  277. /* The PCI-core device (if available). */
  278. struct ssb_pcicore pcicore;
  279. /* The MIPS-core device (if available). */
  280. struct ssb_mipscore mipscore;
  281. /* The EXTif-core device (if available). */
  282. struct ssb_extif extif;
  283. /* The following structure elements are not available in early
  284. * SSB initialization. Though, they are available for regular
  285. * registered drivers at any stage. So be careful when
  286. * using them in the ssb core code. */
  287. /* ID information about the PCB. */
  288. struct ssb_boardinfo boardinfo;
  289. /* Contents of the SPROM. */
  290. struct ssb_sprom sprom;
  291. /* If the board has a cardbus slot, this is set to true. */
  292. bool has_cardbus_slot;
  293. #ifdef CONFIG_SSB_EMBEDDED
  294. /* Lock for GPIO register access. */
  295. spinlock_t gpio_lock;
  296. #endif /* EMBEDDED */
  297. /* Internal-only stuff follows. Do not touch. */
  298. struct list_head list;
  299. #ifdef CONFIG_SSB_DEBUG
  300. /* Is the bus already powered up? */
  301. bool powered_up;
  302. int power_warn_count;
  303. #endif /* DEBUG */
  304. };
  305. enum ssb_quirks {
  306. /* SDIO connected card requires performing a read after writing a 32-bit value */
  307. SSB_QUIRK_SDIO_READ_AFTER_WRITE32 = (1 << 0),
  308. };
  309. /* The initialization-invariants. */
  310. struct ssb_init_invariants {
  311. /* Versioning information about the PCB. */
  312. struct ssb_boardinfo boardinfo;
  313. /* The SPROM information. That's either stored in an
  314. * EEPROM or NVRAM on the board. */
  315. struct ssb_sprom sprom;
  316. /* If the board has a cardbus slot, this is set to true. */
  317. bool has_cardbus_slot;
  318. };
  319. /* Type of function to fetch the invariants. */
  320. typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
  321. struct ssb_init_invariants *iv);
  322. /* Register a SSB system bus. get_invariants() is called after the
  323. * basic system devices are initialized.
  324. * The invariants are usually fetched from some NVRAM.
  325. * Put the invariants into the struct pointed to by iv. */
  326. extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
  327. unsigned long baseaddr,
  328. ssb_invariants_func_t get_invariants);
  329. #ifdef CONFIG_SSB_PCIHOST
  330. extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
  331. struct pci_dev *host_pci);
  332. #endif /* CONFIG_SSB_PCIHOST */
  333. #ifdef CONFIG_SSB_PCMCIAHOST
  334. extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
  335. struct pcmcia_device *pcmcia_dev,
  336. unsigned long baseaddr);
  337. #endif /* CONFIG_SSB_PCMCIAHOST */
  338. #ifdef CONFIG_SSB_SDIOHOST
  339. extern int ssb_bus_sdiobus_register(struct ssb_bus *bus,
  340. struct sdio_func *sdio_func,
  341. unsigned int quirks);
  342. #endif /* CONFIG_SSB_SDIOHOST */
  343. extern void ssb_bus_unregister(struct ssb_bus *bus);
  344. /* Does the device have an SPROM? */
  345. extern bool ssb_is_sprom_available(struct ssb_bus *bus);
  346. /* Set a fallback SPROM.
  347. * See kdoc at the function definition for complete documentation. */
  348. extern int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom);
  349. /* Suspend a SSB bus.
  350. * Call this from the parent bus suspend routine. */
  351. extern int ssb_bus_suspend(struct ssb_bus *bus);
  352. /* Resume a SSB bus.
  353. * Call this from the parent bus resume routine. */
  354. extern int ssb_bus_resume(struct ssb_bus *bus);
  355. extern u32 ssb_clockspeed(struct ssb_bus *bus);
  356. /* Is the device enabled in hardware? */
  357. int ssb_device_is_enabled(struct ssb_device *dev);
  358. /* Enable a device and pass device-specific SSB_TMSLOW flags.
  359. * If no device-specific flags are available, use 0. */
  360. void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
  361. /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
  362. void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
  363. /* Device MMIO register read/write functions. */
  364. static inline u8 ssb_read8(struct ssb_device *dev, u16 offset)
  365. {
  366. return dev->ops->read8(dev, offset);
  367. }
  368. static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
  369. {
  370. return dev->ops->read16(dev, offset);
  371. }
  372. static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
  373. {
  374. return dev->ops->read32(dev, offset);
  375. }
  376. static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value)
  377. {
  378. dev->ops->write8(dev, offset, value);
  379. }
  380. static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
  381. {
  382. dev->ops->write16(dev, offset, value);
  383. }
  384. static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
  385. {
  386. dev->ops->write32(dev, offset, value);
  387. }
  388. #ifdef CONFIG_SSB_BLOCKIO
  389. static inline void ssb_block_read(struct ssb_device *dev, void *buffer,
  390. size_t count, u16 offset, u8 reg_width)
  391. {
  392. dev->ops->block_read(dev, buffer, count, offset, reg_width);
  393. }
  394. static inline void ssb_block_write(struct ssb_device *dev, const void *buffer,
  395. size_t count, u16 offset, u8 reg_width)
  396. {
  397. dev->ops->block_write(dev, buffer, count, offset, reg_width);
  398. }
  399. #endif /* CONFIG_SSB_BLOCKIO */
  400. /* The SSB DMA API. Use this API for any DMA operation on the device.
  401. * This API basically is a wrapper that calls the correct DMA API for
  402. * the host device type the SSB device is attached to. */
  403. /* Translation (routing) bits that need to be ORed to DMA
  404. * addresses before they are given to a device. */
  405. extern u32 ssb_dma_translation(struct ssb_device *dev);
  406. #define SSB_DMA_TRANSLATION_MASK 0xC0000000
  407. #define SSB_DMA_TRANSLATION_SHIFT 30
  408. extern int ssb_dma_set_mask(struct ssb_device *dev, u64 mask);
  409. extern void * ssb_dma_alloc_consistent(struct ssb_device *dev, size_t size,
  410. dma_addr_t *dma_handle, gfp_t gfp_flags);
  411. extern void ssb_dma_free_consistent(struct ssb_device *dev, size_t size,
  412. void *vaddr, dma_addr_t dma_handle,
  413. gfp_t gfp_flags);
  414. static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev)
  415. {
  416. #ifdef CONFIG_SSB_DEBUG
  417. printk(KERN_ERR "SSB: BUG! Calling DMA API for "
  418. "unsupported bustype %d\n", dev->bus->bustype);
  419. #endif /* DEBUG */
  420. }
  421. static inline int ssb_dma_mapping_error(struct ssb_device *dev, dma_addr_t addr)
  422. {
  423. switch (dev->bus->bustype) {
  424. case SSB_BUSTYPE_PCI:
  425. #ifdef CONFIG_SSB_PCIHOST
  426. return pci_dma_mapping_error(dev->bus->host_pci, addr);
  427. #endif
  428. break;
  429. case SSB_BUSTYPE_SSB:
  430. return dma_mapping_error(dev->dev, addr);
  431. default:
  432. break;
  433. }
  434. __ssb_dma_not_implemented(dev);
  435. return -ENOSYS;
  436. }
  437. static inline dma_addr_t ssb_dma_map_single(struct ssb_device *dev, void *p,
  438. size_t size, enum dma_data_direction dir)
  439. {
  440. switch (dev->bus->bustype) {
  441. case SSB_BUSTYPE_PCI:
  442. #ifdef CONFIG_SSB_PCIHOST
  443. return pci_map_single(dev->bus->host_pci, p, size, dir);
  444. #endif
  445. break;
  446. case SSB_BUSTYPE_SSB:
  447. return dma_map_single(dev->dev, p, size, dir);
  448. default:
  449. break;
  450. }
  451. __ssb_dma_not_implemented(dev);
  452. return 0;
  453. }
  454. static inline void ssb_dma_unmap_single(struct ssb_device *dev, dma_addr_t dma_addr,
  455. size_t size, enum dma_data_direction dir)
  456. {
  457. switch (dev->bus->bustype) {
  458. case SSB_BUSTYPE_PCI:
  459. #ifdef CONFIG_SSB_PCIHOST
  460. pci_unmap_single(dev->bus->host_pci, dma_addr, size, dir);
  461. return;
  462. #endif
  463. break;
  464. case SSB_BUSTYPE_SSB:
  465. dma_unmap_single(dev->dev, dma_addr, size, dir);
  466. return;
  467. default:
  468. break;
  469. }
  470. __ssb_dma_not_implemented(dev);
  471. }
  472. static inline void ssb_dma_sync_single_for_cpu(struct ssb_device *dev,
  473. dma_addr_t dma_addr,
  474. size_t size,
  475. enum dma_data_direction dir)
  476. {
  477. switch (dev->bus->bustype) {
  478. case SSB_BUSTYPE_PCI:
  479. #ifdef CONFIG_SSB_PCIHOST
  480. pci_dma_sync_single_for_cpu(dev->bus->host_pci, dma_addr,
  481. size, dir);
  482. return;
  483. #endif
  484. break;
  485. case SSB_BUSTYPE_SSB:
  486. dma_sync_single_for_cpu(dev->dev, dma_addr, size, dir);
  487. return;
  488. default:
  489. break;
  490. }
  491. __ssb_dma_not_implemented(dev);
  492. }
  493. static inline void ssb_dma_sync_single_for_device(struct ssb_device *dev,
  494. dma_addr_t dma_addr,
  495. size_t size,
  496. enum dma_data_direction dir)
  497. {
  498. switch (dev->bus->bustype) {
  499. case SSB_BUSTYPE_PCI:
  500. #ifdef CONFIG_SSB_PCIHOST
  501. pci_dma_sync_single_for_device(dev->bus->host_pci, dma_addr,
  502. size, dir);
  503. return;
  504. #endif
  505. break;
  506. case SSB_BUSTYPE_SSB:
  507. dma_sync_single_for_device(dev->dev, dma_addr, size, dir);
  508. return;
  509. default:
  510. break;
  511. }
  512. __ssb_dma_not_implemented(dev);
  513. }
  514. static inline void ssb_dma_sync_single_range_for_cpu(struct ssb_device *dev,
  515. dma_addr_t dma_addr,
  516. unsigned long offset,
  517. size_t size,
  518. enum dma_data_direction dir)
  519. {
  520. switch (dev->bus->bustype) {
  521. case SSB_BUSTYPE_PCI:
  522. #ifdef CONFIG_SSB_PCIHOST
  523. /* Just sync everything. That's all the PCI API can do. */
  524. pci_dma_sync_single_for_cpu(dev->bus->host_pci, dma_addr,
  525. offset + size, dir);
  526. return;
  527. #endif
  528. break;
  529. case SSB_BUSTYPE_SSB:
  530. dma_sync_single_range_for_cpu(dev->dev, dma_addr, offset,
  531. size, dir);
  532. return;
  533. default:
  534. break;
  535. }
  536. __ssb_dma_not_implemented(dev);
  537. }
  538. static inline void ssb_dma_sync_single_range_for_device(struct ssb_device *dev,
  539. dma_addr_t dma_addr,
  540. unsigned long offset,
  541. size_t size,
  542. enum dma_data_direction dir)
  543. {
  544. switch (dev->bus->bustype) {
  545. case SSB_BUSTYPE_PCI:
  546. #ifdef CONFIG_SSB_PCIHOST
  547. /* Just sync everything. That's all the PCI API can do. */
  548. pci_dma_sync_single_for_device(dev->bus->host_pci, dma_addr,
  549. offset + size, dir);
  550. return;
  551. #endif
  552. break;
  553. case SSB_BUSTYPE_SSB:
  554. dma_sync_single_range_for_device(dev->dev, dma_addr, offset,
  555. size, dir);
  556. return;
  557. default:
  558. break;
  559. }
  560. __ssb_dma_not_implemented(dev);
  561. }
  562. #ifdef CONFIG_SSB_PCIHOST
  563. /* PCI-host wrapper driver */
  564. extern int ssb_pcihost_register(struct pci_driver *driver);
  565. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  566. {
  567. pci_unregister_driver(driver);
  568. }
  569. static inline
  570. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  571. {
  572. if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
  573. pci_set_power_state(sdev->bus->host_pci, state);
  574. }
  575. #else
  576. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  577. {
  578. }
  579. static inline
  580. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  581. {
  582. }
  583. #endif /* CONFIG_SSB_PCIHOST */
  584. /* If a driver is shutdown or suspended, call this to signal
  585. * that the bus may be completely powered down. SSB will decide,
  586. * if it's really time to power down the bus, based on if there
  587. * are other devices that want to run. */
  588. extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
  589. /* Before initializing and enabling a device, call this to power-up the bus.
  590. * If you want to allow use of dynamic-power-control, pass the flag.
  591. * Otherwise static always-on powercontrol will be used. */
  592. extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
  593. /* Various helper functions */
  594. extern u32 ssb_admatch_base(u32 adm);
  595. extern u32 ssb_admatch_size(u32 adm);
  596. /* PCI device mapping and fixup routines.
  597. * Called from the architecture pcibios init code.
  598. * These are only available on SSB_EMBEDDED configurations. */
  599. #ifdef CONFIG_SSB_EMBEDDED
  600. int ssb_pcibios_plat_dev_init(struct pci_dev *dev);
  601. int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
  602. #endif /* CONFIG_SSB_EMBEDDED */
  603. #endif /* LINUX_SSB_H_ */