ssb.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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 in the basic address register window. (PCI bus only) */
  237. struct ssb_device *mapped_device;
  238. union {
  239. /* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */
  240. u8 mapped_pcmcia_seg;
  241. /* Current SSB base address window for SDIO. */
  242. u32 sdio_sbaddr;
  243. };
  244. /* Lock for core and segment switching.
  245. * On PCMCIA-host busses this is used to protect the whole MMIO access. */
  246. spinlock_t bar_lock;
  247. /* The bus this backplane is running on. */
  248. enum ssb_bustype bustype;
  249. /* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */
  250. struct pci_dev *host_pci;
  251. /* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
  252. struct pcmcia_device *host_pcmcia;
  253. /* Pointer to the SDIO device (only if bustype == SSB_BUSTYPE_SDIO). */
  254. struct sdio_func *host_sdio;
  255. /* See enum ssb_quirks */
  256. unsigned int quirks;
  257. #ifdef CONFIG_SSB_SPROM
  258. /* Mutex to protect the SPROM writing. */
  259. struct mutex sprom_mutex;
  260. #endif
  261. /* ID information about the Chip. */
  262. u16 chip_id;
  263. u16 chip_rev;
  264. u16 sprom_size; /* number of words in sprom */
  265. u8 chip_package;
  266. /* List of devices (cores) on the backplane. */
  267. struct ssb_device devices[SSB_MAX_NR_CORES];
  268. u8 nr_devices;
  269. /* Software ID number for this bus. */
  270. unsigned int busnumber;
  271. /* The ChipCommon device (if available). */
  272. struct ssb_chipcommon chipco;
  273. /* The PCI-core device (if available). */
  274. struct ssb_pcicore pcicore;
  275. /* The MIPS-core device (if available). */
  276. struct ssb_mipscore mipscore;
  277. /* The EXTif-core device (if available). */
  278. struct ssb_extif extif;
  279. /* The following structure elements are not available in early
  280. * SSB initialization. Though, they are available for regular
  281. * registered drivers at any stage. So be careful when
  282. * using them in the ssb core code. */
  283. /* ID information about the PCB. */
  284. struct ssb_boardinfo boardinfo;
  285. /* Contents of the SPROM. */
  286. struct ssb_sprom sprom;
  287. /* If the board has a cardbus slot, this is set to true. */
  288. bool has_cardbus_slot;
  289. #ifdef CONFIG_SSB_EMBEDDED
  290. /* Lock for GPIO register access. */
  291. spinlock_t gpio_lock;
  292. #endif /* EMBEDDED */
  293. /* Internal-only stuff follows. Do not touch. */
  294. struct list_head list;
  295. #ifdef CONFIG_SSB_DEBUG
  296. /* Is the bus already powered up? */
  297. bool powered_up;
  298. int power_warn_count;
  299. #endif /* DEBUG */
  300. };
  301. enum ssb_quirks {
  302. /* SDIO connected card requires performing a read after writing a 32-bit value */
  303. SSB_QUIRK_SDIO_READ_AFTER_WRITE32 = (1 << 0),
  304. };
  305. /* The initialization-invariants. */
  306. struct ssb_init_invariants {
  307. /* Versioning information about the PCB. */
  308. struct ssb_boardinfo boardinfo;
  309. /* The SPROM information. That's either stored in an
  310. * EEPROM or NVRAM on the board. */
  311. struct ssb_sprom sprom;
  312. /* If the board has a cardbus slot, this is set to true. */
  313. bool has_cardbus_slot;
  314. };
  315. /* Type of function to fetch the invariants. */
  316. typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
  317. struct ssb_init_invariants *iv);
  318. /* Register a SSB system bus. get_invariants() is called after the
  319. * basic system devices are initialized.
  320. * The invariants are usually fetched from some NVRAM.
  321. * Put the invariants into the struct pointed to by iv. */
  322. extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
  323. unsigned long baseaddr,
  324. ssb_invariants_func_t get_invariants);
  325. #ifdef CONFIG_SSB_PCIHOST
  326. extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
  327. struct pci_dev *host_pci);
  328. #endif /* CONFIG_SSB_PCIHOST */
  329. #ifdef CONFIG_SSB_PCMCIAHOST
  330. extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
  331. struct pcmcia_device *pcmcia_dev,
  332. unsigned long baseaddr);
  333. #endif /* CONFIG_SSB_PCMCIAHOST */
  334. #ifdef CONFIG_SSB_SDIOHOST
  335. extern int ssb_bus_sdiobus_register(struct ssb_bus *bus,
  336. struct sdio_func *sdio_func,
  337. unsigned int quirks);
  338. #endif /* CONFIG_SSB_SDIOHOST */
  339. extern void ssb_bus_unregister(struct ssb_bus *bus);
  340. /* Set a fallback SPROM.
  341. * See kdoc at the function definition for complete documentation. */
  342. extern int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom);
  343. /* Suspend a SSB bus.
  344. * Call this from the parent bus suspend routine. */
  345. extern int ssb_bus_suspend(struct ssb_bus *bus);
  346. /* Resume a SSB bus.
  347. * Call this from the parent bus resume routine. */
  348. extern int ssb_bus_resume(struct ssb_bus *bus);
  349. extern u32 ssb_clockspeed(struct ssb_bus *bus);
  350. /* Is the device enabled in hardware? */
  351. int ssb_device_is_enabled(struct ssb_device *dev);
  352. /* Enable a device and pass device-specific SSB_TMSLOW flags.
  353. * If no device-specific flags are available, use 0. */
  354. void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
  355. /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
  356. void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
  357. /* Device MMIO register read/write functions. */
  358. static inline u8 ssb_read8(struct ssb_device *dev, u16 offset)
  359. {
  360. return dev->ops->read8(dev, offset);
  361. }
  362. static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
  363. {
  364. return dev->ops->read16(dev, offset);
  365. }
  366. static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
  367. {
  368. return dev->ops->read32(dev, offset);
  369. }
  370. static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value)
  371. {
  372. dev->ops->write8(dev, offset, value);
  373. }
  374. static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
  375. {
  376. dev->ops->write16(dev, offset, value);
  377. }
  378. static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
  379. {
  380. dev->ops->write32(dev, offset, value);
  381. }
  382. #ifdef CONFIG_SSB_BLOCKIO
  383. static inline void ssb_block_read(struct ssb_device *dev, void *buffer,
  384. size_t count, u16 offset, u8 reg_width)
  385. {
  386. dev->ops->block_read(dev, buffer, count, offset, reg_width);
  387. }
  388. static inline void ssb_block_write(struct ssb_device *dev, const void *buffer,
  389. size_t count, u16 offset, u8 reg_width)
  390. {
  391. dev->ops->block_write(dev, buffer, count, offset, reg_width);
  392. }
  393. #endif /* CONFIG_SSB_BLOCKIO */
  394. /* The SSB DMA API. Use this API for any DMA operation on the device.
  395. * This API basically is a wrapper that calls the correct DMA API for
  396. * the host device type the SSB device is attached to. */
  397. /* Translation (routing) bits that need to be ORed to DMA
  398. * addresses before they are given to a device. */
  399. extern u32 ssb_dma_translation(struct ssb_device *dev);
  400. #define SSB_DMA_TRANSLATION_MASK 0xC0000000
  401. #define SSB_DMA_TRANSLATION_SHIFT 30
  402. extern int ssb_dma_set_mask(struct ssb_device *dev, u64 mask);
  403. extern void * ssb_dma_alloc_consistent(struct ssb_device *dev, size_t size,
  404. dma_addr_t *dma_handle, gfp_t gfp_flags);
  405. extern void ssb_dma_free_consistent(struct ssb_device *dev, size_t size,
  406. void *vaddr, dma_addr_t dma_handle,
  407. gfp_t gfp_flags);
  408. static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev)
  409. {
  410. #ifdef CONFIG_SSB_DEBUG
  411. printk(KERN_ERR "SSB: BUG! Calling DMA API for "
  412. "unsupported bustype %d\n", dev->bus->bustype);
  413. #endif /* DEBUG */
  414. }
  415. static inline int ssb_dma_mapping_error(struct ssb_device *dev, dma_addr_t addr)
  416. {
  417. switch (dev->bus->bustype) {
  418. case SSB_BUSTYPE_PCI:
  419. #ifdef CONFIG_SSB_PCIHOST
  420. return pci_dma_mapping_error(dev->bus->host_pci, addr);
  421. #endif
  422. break;
  423. case SSB_BUSTYPE_SSB:
  424. return dma_mapping_error(dev->dev, addr);
  425. default:
  426. break;
  427. }
  428. __ssb_dma_not_implemented(dev);
  429. return -ENOSYS;
  430. }
  431. static inline dma_addr_t ssb_dma_map_single(struct ssb_device *dev, void *p,
  432. size_t size, enum dma_data_direction dir)
  433. {
  434. switch (dev->bus->bustype) {
  435. case SSB_BUSTYPE_PCI:
  436. #ifdef CONFIG_SSB_PCIHOST
  437. return pci_map_single(dev->bus->host_pci, p, size, dir);
  438. #endif
  439. break;
  440. case SSB_BUSTYPE_SSB:
  441. return dma_map_single(dev->dev, p, size, dir);
  442. default:
  443. break;
  444. }
  445. __ssb_dma_not_implemented(dev);
  446. return 0;
  447. }
  448. static inline void ssb_dma_unmap_single(struct ssb_device *dev, dma_addr_t dma_addr,
  449. size_t size, enum dma_data_direction dir)
  450. {
  451. switch (dev->bus->bustype) {
  452. case SSB_BUSTYPE_PCI:
  453. #ifdef CONFIG_SSB_PCIHOST
  454. pci_unmap_single(dev->bus->host_pci, dma_addr, size, dir);
  455. return;
  456. #endif
  457. break;
  458. case SSB_BUSTYPE_SSB:
  459. dma_unmap_single(dev->dev, dma_addr, size, dir);
  460. return;
  461. default:
  462. break;
  463. }
  464. __ssb_dma_not_implemented(dev);
  465. }
  466. static inline void ssb_dma_sync_single_for_cpu(struct ssb_device *dev,
  467. dma_addr_t dma_addr,
  468. size_t size,
  469. enum dma_data_direction dir)
  470. {
  471. switch (dev->bus->bustype) {
  472. case SSB_BUSTYPE_PCI:
  473. #ifdef CONFIG_SSB_PCIHOST
  474. pci_dma_sync_single_for_cpu(dev->bus->host_pci, dma_addr,
  475. size, dir);
  476. return;
  477. #endif
  478. break;
  479. case SSB_BUSTYPE_SSB:
  480. dma_sync_single_for_cpu(dev->dev, dma_addr, size, dir);
  481. return;
  482. default:
  483. break;
  484. }
  485. __ssb_dma_not_implemented(dev);
  486. }
  487. static inline void ssb_dma_sync_single_for_device(struct ssb_device *dev,
  488. dma_addr_t dma_addr,
  489. size_t size,
  490. enum dma_data_direction dir)
  491. {
  492. switch (dev->bus->bustype) {
  493. case SSB_BUSTYPE_PCI:
  494. #ifdef CONFIG_SSB_PCIHOST
  495. pci_dma_sync_single_for_device(dev->bus->host_pci, dma_addr,
  496. size, dir);
  497. return;
  498. #endif
  499. break;
  500. case SSB_BUSTYPE_SSB:
  501. dma_sync_single_for_device(dev->dev, dma_addr, size, dir);
  502. return;
  503. default:
  504. break;
  505. }
  506. __ssb_dma_not_implemented(dev);
  507. }
  508. static inline void ssb_dma_sync_single_range_for_cpu(struct ssb_device *dev,
  509. dma_addr_t dma_addr,
  510. unsigned long offset,
  511. size_t size,
  512. enum dma_data_direction dir)
  513. {
  514. switch (dev->bus->bustype) {
  515. case SSB_BUSTYPE_PCI:
  516. #ifdef CONFIG_SSB_PCIHOST
  517. /* Just sync everything. That's all the PCI API can do. */
  518. pci_dma_sync_single_for_cpu(dev->bus->host_pci, dma_addr,
  519. offset + size, dir);
  520. return;
  521. #endif
  522. break;
  523. case SSB_BUSTYPE_SSB:
  524. dma_sync_single_range_for_cpu(dev->dev, dma_addr, offset,
  525. size, dir);
  526. return;
  527. default:
  528. break;
  529. }
  530. __ssb_dma_not_implemented(dev);
  531. }
  532. static inline void ssb_dma_sync_single_range_for_device(struct ssb_device *dev,
  533. dma_addr_t dma_addr,
  534. unsigned long offset,
  535. size_t size,
  536. enum dma_data_direction dir)
  537. {
  538. switch (dev->bus->bustype) {
  539. case SSB_BUSTYPE_PCI:
  540. #ifdef CONFIG_SSB_PCIHOST
  541. /* Just sync everything. That's all the PCI API can do. */
  542. pci_dma_sync_single_for_device(dev->bus->host_pci, dma_addr,
  543. offset + size, dir);
  544. return;
  545. #endif
  546. break;
  547. case SSB_BUSTYPE_SSB:
  548. dma_sync_single_range_for_device(dev->dev, dma_addr, offset,
  549. size, dir);
  550. return;
  551. default:
  552. break;
  553. }
  554. __ssb_dma_not_implemented(dev);
  555. }
  556. #ifdef CONFIG_SSB_PCIHOST
  557. /* PCI-host wrapper driver */
  558. extern int ssb_pcihost_register(struct pci_driver *driver);
  559. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  560. {
  561. pci_unregister_driver(driver);
  562. }
  563. static inline
  564. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  565. {
  566. if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
  567. pci_set_power_state(sdev->bus->host_pci, state);
  568. }
  569. #else
  570. static inline void ssb_pcihost_unregister(struct pci_driver *driver)
  571. {
  572. }
  573. static inline
  574. void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
  575. {
  576. }
  577. #endif /* CONFIG_SSB_PCIHOST */
  578. /* If a driver is shutdown or suspended, call this to signal
  579. * that the bus may be completely powered down. SSB will decide,
  580. * if it's really time to power down the bus, based on if there
  581. * are other devices that want to run. */
  582. extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
  583. /* Before initializing and enabling a device, call this to power-up the bus.
  584. * If you want to allow use of dynamic-power-control, pass the flag.
  585. * Otherwise static always-on powercontrol will be used. */
  586. extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
  587. /* Various helper functions */
  588. extern u32 ssb_admatch_base(u32 adm);
  589. extern u32 ssb_admatch_size(u32 adm);
  590. /* PCI device mapping and fixup routines.
  591. * Called from the architecture pcibios init code.
  592. * These are only available on SSB_EMBEDDED configurations. */
  593. #ifdef CONFIG_SSB_EMBEDDED
  594. int ssb_pcibios_plat_dev_init(struct pci_dev *dev);
  595. int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
  596. #endif /* CONFIG_SSB_EMBEDDED */
  597. #endif /* LINUX_SSB_H_ */