Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 1 | #ifndef LINUX_SSB_H_ |
| 2 | #define LINUX_SSB_H_ |
| 3 | |
| 4 | #include <linux/device.h> |
| 5 | #include <linux/list.h> |
| 6 | #include <linux/types.h> |
| 7 | #include <linux/spinlock.h> |
| 8 | #include <linux/pci.h> |
| 9 | #include <linux/mod_devicetable.h> |
| 10 | |
| 11 | #include <linux/ssb/ssb_regs.h> |
| 12 | |
| 13 | |
| 14 | struct pcmcia_device; |
| 15 | struct ssb_bus; |
| 16 | struct ssb_driver; |
| 17 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 18 | struct ssb_sprom { |
| 19 | u8 revision; |
Larry Finger | ac82fab | 2007-11-09 16:54:45 -0600 | [diff] [blame] | 20 | u8 il0mac[6]; /* MAC address for 802.11b/g */ |
| 21 | u8 et0mac[6]; /* MAC address for Ethernet */ |
| 22 | u8 et1mac[6]; /* MAC address for 802.11a */ |
| 23 | u8 et0phyaddr; /* MII address for enet0 */ |
| 24 | u8 et1phyaddr; /* MII address for enet1 */ |
Michael Buesch | e861b98 | 2007-12-22 21:51:30 +0100 | [diff] [blame] | 25 | u8 et0mdcport; /* MDIO for enet0 */ |
| 26 | u8 et1mdcport; /* MDIO for enet1 */ |
| 27 | u8 board_rev; /* Board revision number from SPROM. */ |
Larry Finger | ac82fab | 2007-11-09 16:54:45 -0600 | [diff] [blame] | 28 | u8 country_code; /* Country Code */ |
Michael Buesch | e861b98 | 2007-12-22 21:51:30 +0100 | [diff] [blame] | 29 | u8 ant_available_a; /* A-PHY antenna available bits (up to 4) */ |
| 30 | u8 ant_available_bg; /* B/G-PHY antenna available bits (up to 4) */ |
Larry Finger | ac82fab | 2007-11-09 16:54:45 -0600 | [diff] [blame] | 31 | u16 pa0b0; |
| 32 | u16 pa0b1; |
| 33 | u16 pa0b2; |
| 34 | u16 pa1b0; |
| 35 | u16 pa1b1; |
| 36 | u16 pa1b2; |
| 37 | u8 gpio0; /* GPIO pin 0 */ |
| 38 | u8 gpio1; /* GPIO pin 1 */ |
| 39 | u8 gpio2; /* GPIO pin 2 */ |
| 40 | u8 gpio3; /* GPIO pin 3 */ |
| 41 | u16 maxpwr_a; /* A-PHY Amplifier Max Power (in dBm Q5.2) */ |
| 42 | u16 maxpwr_bg; /* B/G-PHY Amplifier Max Power (in dBm Q5.2) */ |
| 43 | u8 itssi_a; /* Idle TSSI Target for A-PHY */ |
| 44 | u8 itssi_bg; /* Idle TSSI Target for B/G-PHY */ |
| 45 | u16 boardflags_lo; /* Boardflags (low 16 bits) */ |
Michael Buesch | af4b7450 | 2008-01-13 21:08:24 +0100 | [diff] [blame] | 46 | u16 boardflags_hi; /* Boardflags (high 16 bits) */ |
Michael Buesch | e861b98 | 2007-12-22 21:51:30 +0100 | [diff] [blame] | 47 | |
| 48 | /* Antenna gain values for up to 4 antennas |
| 49 | * on each band. Values in dBm/4 (Q5.2). Negative gain means the |
| 50 | * loss in the connectors is bigger than the gain. */ |
| 51 | struct { |
| 52 | struct { |
| 53 | s8 a0, a1, a2, a3; |
| 54 | } ghz24; /* 2.4GHz band */ |
| 55 | struct { |
| 56 | s8 a0, a1, a2, a3; |
| 57 | } ghz5; /* 5GHz band */ |
| 58 | } antenna_gain; |
Larry Finger | ac82fab | 2007-11-09 16:54:45 -0600 | [diff] [blame] | 59 | |
| 60 | /* TODO - add any parameters needed from rev 2, 3, or 4 SPROMs */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /* Information about the PCB the circuitry is soldered on. */ |
| 64 | struct ssb_boardinfo { |
| 65 | u16 vendor; |
| 66 | u16 type; |
| 67 | u16 rev; |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | struct ssb_device; |
| 72 | /* Lowlevel read/write operations on the device MMIO. |
| 73 | * Internal, don't use that outside of ssb. */ |
| 74 | struct ssb_bus_ops { |
| 75 | u16 (*read16)(struct ssb_device *dev, u16 offset); |
| 76 | u32 (*read32)(struct ssb_device *dev, u16 offset); |
| 77 | void (*write16)(struct ssb_device *dev, u16 offset, u16 value); |
| 78 | void (*write32)(struct ssb_device *dev, u16 offset, u32 value); |
| 79 | }; |
| 80 | |
| 81 | |
| 82 | /* Core-ID values. */ |
| 83 | #define SSB_DEV_CHIPCOMMON 0x800 |
| 84 | #define SSB_DEV_ILINE20 0x801 |
| 85 | #define SSB_DEV_SDRAM 0x803 |
| 86 | #define SSB_DEV_PCI 0x804 |
| 87 | #define SSB_DEV_MIPS 0x805 |
| 88 | #define SSB_DEV_ETHERNET 0x806 |
| 89 | #define SSB_DEV_V90 0x807 |
| 90 | #define SSB_DEV_USB11_HOSTDEV 0x808 |
| 91 | #define SSB_DEV_ADSL 0x809 |
| 92 | #define SSB_DEV_ILINE100 0x80A |
| 93 | #define SSB_DEV_IPSEC 0x80B |
| 94 | #define SSB_DEV_PCMCIA 0x80D |
| 95 | #define SSB_DEV_INTERNAL_MEM 0x80E |
| 96 | #define SSB_DEV_MEMC_SDRAM 0x80F |
| 97 | #define SSB_DEV_EXTIF 0x811 |
| 98 | #define SSB_DEV_80211 0x812 |
| 99 | #define SSB_DEV_MIPS_3302 0x816 |
| 100 | #define SSB_DEV_USB11_HOST 0x817 |
| 101 | #define SSB_DEV_USB11_DEV 0x818 |
| 102 | #define SSB_DEV_USB20_HOST 0x819 |
| 103 | #define SSB_DEV_USB20_DEV 0x81A |
| 104 | #define SSB_DEV_SDIO_HOST 0x81B |
| 105 | #define SSB_DEV_ROBOSWITCH 0x81C |
| 106 | #define SSB_DEV_PARA_ATA 0x81D |
| 107 | #define SSB_DEV_SATA_XORDMA 0x81E |
| 108 | #define SSB_DEV_ETHERNET_GBIT 0x81F |
| 109 | #define SSB_DEV_PCIE 0x820 |
| 110 | #define SSB_DEV_MIMO_PHY 0x821 |
| 111 | #define SSB_DEV_SRAM_CTRLR 0x822 |
| 112 | #define SSB_DEV_MINI_MACPHY 0x823 |
| 113 | #define SSB_DEV_ARM_1176 0x824 |
| 114 | #define SSB_DEV_ARM_7TDMI 0x825 |
| 115 | |
| 116 | /* Vendor-ID values */ |
| 117 | #define SSB_VENDOR_BROADCOM 0x4243 |
| 118 | |
| 119 | /* Some kernel subsystems poke with dev->drvdata, so we must use the |
| 120 | * following ugly workaround to get from struct device to struct ssb_device */ |
| 121 | struct __ssb_dev_wrapper { |
| 122 | struct device dev; |
| 123 | struct ssb_device *sdev; |
| 124 | }; |
| 125 | |
| 126 | struct ssb_device { |
| 127 | /* Having a copy of the ops pointer in each dev struct |
| 128 | * is an optimization. */ |
| 129 | const struct ssb_bus_ops *ops; |
| 130 | |
| 131 | struct device *dev; |
| 132 | struct ssb_bus *bus; |
| 133 | struct ssb_device_id id; |
| 134 | |
| 135 | u8 core_index; |
| 136 | unsigned int irq; |
| 137 | |
| 138 | /* Internal-only stuff follows. */ |
| 139 | void *drvdata; /* Per-device data */ |
| 140 | void *devtypedata; /* Per-devicetype (eg 802.11) data */ |
| 141 | }; |
| 142 | |
| 143 | /* Go from struct device to struct ssb_device. */ |
| 144 | static inline |
| 145 | struct ssb_device * dev_to_ssb_dev(struct device *dev) |
| 146 | { |
| 147 | struct __ssb_dev_wrapper *wrap; |
| 148 | wrap = container_of(dev, struct __ssb_dev_wrapper, dev); |
| 149 | return wrap->sdev; |
| 150 | } |
| 151 | |
| 152 | /* Device specific user data */ |
| 153 | static inline |
| 154 | void ssb_set_drvdata(struct ssb_device *dev, void *data) |
| 155 | { |
| 156 | dev->drvdata = data; |
| 157 | } |
| 158 | static inline |
| 159 | void * ssb_get_drvdata(struct ssb_device *dev) |
| 160 | { |
| 161 | return dev->drvdata; |
| 162 | } |
| 163 | |
| 164 | /* Devicetype specific user data. This is per device-type (not per device) */ |
| 165 | void ssb_set_devtypedata(struct ssb_device *dev, void *data); |
| 166 | static inline |
| 167 | void * ssb_get_devtypedata(struct ssb_device *dev) |
| 168 | { |
| 169 | return dev->devtypedata; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | struct ssb_driver { |
| 174 | const char *name; |
| 175 | const struct ssb_device_id *id_table; |
| 176 | |
| 177 | int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id); |
| 178 | void (*remove)(struct ssb_device *dev); |
| 179 | int (*suspend)(struct ssb_device *dev, pm_message_t state); |
| 180 | int (*resume)(struct ssb_device *dev); |
| 181 | void (*shutdown)(struct ssb_device *dev); |
| 182 | |
| 183 | struct device_driver drv; |
| 184 | }; |
| 185 | #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv) |
| 186 | |
| 187 | extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner); |
| 188 | static inline int ssb_driver_register(struct ssb_driver *drv) |
| 189 | { |
| 190 | return __ssb_driver_register(drv, THIS_MODULE); |
| 191 | } |
| 192 | extern void ssb_driver_unregister(struct ssb_driver *drv); |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | enum ssb_bustype { |
| 198 | SSB_BUSTYPE_SSB, /* This SSB bus is the system bus */ |
| 199 | SSB_BUSTYPE_PCI, /* SSB is connected to PCI bus */ |
| 200 | SSB_BUSTYPE_PCMCIA, /* SSB is connected to PCMCIA bus */ |
| 201 | }; |
| 202 | |
| 203 | /* board_vendor */ |
| 204 | #define SSB_BOARDVENDOR_BCM 0x14E4 /* Broadcom */ |
| 205 | #define SSB_BOARDVENDOR_DELL 0x1028 /* Dell */ |
| 206 | #define SSB_BOARDVENDOR_HP 0x0E11 /* HP */ |
| 207 | /* board_type */ |
| 208 | #define SSB_BOARD_BCM94306MP 0x0418 |
| 209 | #define SSB_BOARD_BCM4309G 0x0421 |
| 210 | #define SSB_BOARD_BCM4306CB 0x0417 |
| 211 | #define SSB_BOARD_BCM4309MP 0x040C |
| 212 | #define SSB_BOARD_MP4318 0x044A |
| 213 | #define SSB_BOARD_BU4306 0x0416 |
| 214 | #define SSB_BOARD_BU4309 0x040A |
| 215 | /* chip_package */ |
| 216 | #define SSB_CHIPPACK_BCM4712S 1 /* Small 200pin 4712 */ |
| 217 | #define SSB_CHIPPACK_BCM4712M 2 /* Medium 225pin 4712 */ |
| 218 | #define SSB_CHIPPACK_BCM4712L 0 /* Large 340pin 4712 */ |
| 219 | |
| 220 | #include <linux/ssb/ssb_driver_chipcommon.h> |
| 221 | #include <linux/ssb/ssb_driver_mips.h> |
| 222 | #include <linux/ssb/ssb_driver_extif.h> |
| 223 | #include <linux/ssb/ssb_driver_pci.h> |
| 224 | |
| 225 | struct ssb_bus { |
| 226 | /* The MMIO area. */ |
| 227 | void __iomem *mmio; |
| 228 | |
| 229 | const struct ssb_bus_ops *ops; |
| 230 | |
| 231 | /* The core in the basic address register window. (PCI bus only) */ |
| 232 | struct ssb_device *mapped_device; |
| 233 | /* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */ |
| 234 | u8 mapped_pcmcia_seg; |
Michael Buesch | 993e1c7 | 2007-12-22 22:01:36 +0100 | [diff] [blame] | 235 | /* Lock for core and segment switching. |
| 236 | * On PCMCIA-host busses this is used to protect the whole MMIO access. */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 237 | spinlock_t bar_lock; |
| 238 | |
| 239 | /* The bus this backplane is running on. */ |
| 240 | enum ssb_bustype bustype; |
| 241 | /* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */ |
| 242 | struct pci_dev *host_pci; |
| 243 | /* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */ |
| 244 | struct pcmcia_device *host_pcmcia; |
| 245 | |
| 246 | #ifdef CONFIG_SSB_PCIHOST |
| 247 | /* Mutex to protect the SPROM writing. */ |
| 248 | struct mutex pci_sprom_mutex; |
| 249 | #endif |
| 250 | |
| 251 | /* ID information about the Chip. */ |
| 252 | u16 chip_id; |
| 253 | u16 chip_rev; |
Larry Finger | c272ef4 | 2007-11-09 16:56:25 -0600 | [diff] [blame] | 254 | u16 sprom_size; /* number of words in sprom */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 255 | u8 chip_package; |
| 256 | |
| 257 | /* List of devices (cores) on the backplane. */ |
| 258 | struct ssb_device devices[SSB_MAX_NR_CORES]; |
| 259 | u8 nr_devices; |
| 260 | |
| 261 | /* Reference count. Number of suspended devices. */ |
| 262 | u8 suspend_cnt; |
| 263 | |
| 264 | /* Software ID number for this bus. */ |
| 265 | unsigned int busnumber; |
| 266 | |
| 267 | /* The ChipCommon device (if available). */ |
| 268 | struct ssb_chipcommon chipco; |
| 269 | /* The PCI-core device (if available). */ |
| 270 | struct ssb_pcicore pcicore; |
| 271 | /* The MIPS-core device (if available). */ |
| 272 | struct ssb_mipscore mipscore; |
| 273 | /* The EXTif-core device (if available). */ |
| 274 | struct ssb_extif extif; |
| 275 | |
| 276 | /* The following structure elements are not available in early |
| 277 | * SSB initialization. Though, they are available for regular |
| 278 | * registered drivers at any stage. So be careful when |
| 279 | * using them in the ssb core code. */ |
| 280 | |
| 281 | /* ID information about the PCB. */ |
| 282 | struct ssb_boardinfo boardinfo; |
| 283 | /* Contents of the SPROM. */ |
| 284 | struct ssb_sprom sprom; |
Michael Buesch | 7cb4461 | 2008-02-19 17:46:48 +0100 | [diff] [blame] | 285 | /* If the board has a cardbus slot, this is set to true. */ |
| 286 | bool has_cardbus_slot; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 287 | |
Michael Buesch | 53521d8 | 2008-02-19 16:22:50 +0100 | [diff] [blame] | 288 | #ifdef CONFIG_SSB_EMBEDDED |
| 289 | /* Lock for GPIO register access. */ |
| 290 | spinlock_t gpio_lock; |
| 291 | #endif /* EMBEDDED */ |
| 292 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 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 | |
| 302 | /* The initialization-invariants. */ |
| 303 | struct ssb_init_invariants { |
Michael Buesch | 7cb4461 | 2008-02-19 17:46:48 +0100 | [diff] [blame] | 304 | /* Versioning information about the PCB. */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 305 | struct ssb_boardinfo boardinfo; |
Michael Buesch | 7cb4461 | 2008-02-19 17:46:48 +0100 | [diff] [blame] | 306 | /* The SPROM information. That's either stored in an |
| 307 | * EEPROM or NVRAM on the board. */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 308 | struct ssb_sprom sprom; |
Michael Buesch | 7cb4461 | 2008-02-19 17:46:48 +0100 | [diff] [blame] | 309 | /* If the board has a cardbus slot, this is set to true. */ |
| 310 | bool has_cardbus_slot; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 311 | }; |
| 312 | /* Type of function to fetch the invariants. */ |
| 313 | typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus, |
| 314 | struct ssb_init_invariants *iv); |
| 315 | |
| 316 | /* Register a SSB system bus. get_invariants() is called after the |
| 317 | * basic system devices are initialized. |
| 318 | * The invariants are usually fetched from some NVRAM. |
| 319 | * Put the invariants into the struct pointed to by iv. */ |
| 320 | extern int ssb_bus_ssbbus_register(struct ssb_bus *bus, |
| 321 | unsigned long baseaddr, |
| 322 | ssb_invariants_func_t get_invariants); |
| 323 | #ifdef CONFIG_SSB_PCIHOST |
| 324 | extern int ssb_bus_pcibus_register(struct ssb_bus *bus, |
| 325 | struct pci_dev *host_pci); |
| 326 | #endif /* CONFIG_SSB_PCIHOST */ |
| 327 | #ifdef CONFIG_SSB_PCMCIAHOST |
| 328 | extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus, |
| 329 | struct pcmcia_device *pcmcia_dev, |
| 330 | unsigned long baseaddr); |
| 331 | #endif /* CONFIG_SSB_PCMCIAHOST */ |
| 332 | |
| 333 | extern void ssb_bus_unregister(struct ssb_bus *bus); |
| 334 | |
| 335 | extern u32 ssb_clockspeed(struct ssb_bus *bus); |
| 336 | |
| 337 | /* Is the device enabled in hardware? */ |
| 338 | int ssb_device_is_enabled(struct ssb_device *dev); |
| 339 | /* Enable a device and pass device-specific SSB_TMSLOW flags. |
| 340 | * If no device-specific flags are available, use 0. */ |
| 341 | void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags); |
| 342 | /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */ |
| 343 | void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags); |
| 344 | |
| 345 | |
| 346 | /* Device MMIO register read/write functions. */ |
| 347 | static inline u16 ssb_read16(struct ssb_device *dev, u16 offset) |
| 348 | { |
| 349 | return dev->ops->read16(dev, offset); |
| 350 | } |
| 351 | static inline u32 ssb_read32(struct ssb_device *dev, u16 offset) |
| 352 | { |
| 353 | return dev->ops->read32(dev, offset); |
| 354 | } |
| 355 | static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value) |
| 356 | { |
| 357 | dev->ops->write16(dev, offset, value); |
| 358 | } |
| 359 | static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value) |
| 360 | { |
| 361 | dev->ops->write32(dev, offset, value); |
| 362 | } |
| 363 | |
| 364 | |
| 365 | /* Translation (routing) bits that need to be ORed to DMA |
| 366 | * addresses before they are given to a device. */ |
| 367 | extern u32 ssb_dma_translation(struct ssb_device *dev); |
| 368 | #define SSB_DMA_TRANSLATION_MASK 0xC0000000 |
| 369 | #define SSB_DMA_TRANSLATION_SHIFT 30 |
| 370 | |
| 371 | extern int ssb_dma_set_mask(struct ssb_device *ssb_dev, u64 mask); |
| 372 | |
| 373 | |
| 374 | #ifdef CONFIG_SSB_PCIHOST |
| 375 | /* PCI-host wrapper driver */ |
| 376 | extern int ssb_pcihost_register(struct pci_driver *driver); |
| 377 | static inline void ssb_pcihost_unregister(struct pci_driver *driver) |
| 378 | { |
| 379 | pci_unregister_driver(driver); |
| 380 | } |
Miguel Botón | 961d57c | 2008-01-01 01:16:46 +0100 | [diff] [blame] | 381 | |
| 382 | static inline |
| 383 | void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state) |
| 384 | { |
| 385 | if (sdev->bus->bustype == SSB_BUSTYPE_PCI) |
| 386 | pci_set_power_state(sdev->bus->host_pci, state); |
| 387 | } |
Andrew Morton | 532031d | 2008-02-04 23:58:42 -0800 | [diff] [blame] | 388 | #else |
| 389 | static inline void ssb_pcihost_unregister(struct pci_driver *driver) |
| 390 | { |
| 391 | } |
| 392 | |
| 393 | static inline |
| 394 | void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state) |
| 395 | { |
| 396 | } |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 397 | #endif /* CONFIG_SSB_PCIHOST */ |
| 398 | |
| 399 | |
| 400 | /* If a driver is shutdown or suspended, call this to signal |
| 401 | * that the bus may be completely powered down. SSB will decide, |
| 402 | * if it's really time to power down the bus, based on if there |
| 403 | * are other devices that want to run. */ |
| 404 | extern int ssb_bus_may_powerdown(struct ssb_bus *bus); |
| 405 | /* Before initializing and enabling a device, call this to power-up the bus. |
| 406 | * If you want to allow use of dynamic-power-control, pass the flag. |
| 407 | * Otherwise static always-on powercontrol will be used. */ |
| 408 | extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl); |
| 409 | |
| 410 | |
| 411 | /* Various helper functions */ |
| 412 | extern u32 ssb_admatch_base(u32 adm); |
| 413 | extern u32 ssb_admatch_size(u32 adm); |
| 414 | |
| 415 | |
| 416 | #endif /* LINUX_SSB_H_ */ |