161e115a5SMichael Buesch #ifndef LINUX_SSB_H_ 261e115a5SMichael Buesch #define LINUX_SSB_H_ 361e115a5SMichael Buesch 461e115a5SMichael Buesch #include <linux/device.h> 561e115a5SMichael Buesch #include <linux/list.h> 661e115a5SMichael Buesch #include <linux/types.h> 761e115a5SMichael Buesch #include <linux/spinlock.h> 861e115a5SMichael Buesch #include <linux/pci.h> 961e115a5SMichael Buesch #include <linux/mod_devicetable.h> 109c0c7a42SMichael Buesch #include <linux/dma-mapping.h> 1161e115a5SMichael Buesch 1261e115a5SMichael Buesch #include <linux/ssb/ssb_regs.h> 1361e115a5SMichael Buesch 1461e115a5SMichael Buesch 1561e115a5SMichael Buesch struct pcmcia_device; 1661e115a5SMichael Buesch struct ssb_bus; 1761e115a5SMichael Buesch struct ssb_driver; 1861e115a5SMichael Buesch 1961e115a5SMichael Buesch struct ssb_sprom { 2061e115a5SMichael Buesch u8 revision; 21ac82fab4SLarry Finger u8 il0mac[6]; /* MAC address for 802.11b/g */ 22ac82fab4SLarry Finger u8 et0mac[6]; /* MAC address for Ethernet */ 23ac82fab4SLarry Finger u8 et1mac[6]; /* MAC address for 802.11a */ 24ac82fab4SLarry Finger u8 et0phyaddr; /* MII address for enet0 */ 25ac82fab4SLarry Finger u8 et1phyaddr; /* MII address for enet1 */ 26e861b98dSMichael Buesch u8 et0mdcport; /* MDIO for enet0 */ 27e861b98dSMichael Buesch u8 et1mdcport; /* MDIO for enet1 */ 28e861b98dSMichael Buesch u8 board_rev; /* Board revision number from SPROM. */ 29ac82fab4SLarry Finger u8 country_code; /* Country Code */ 30f679056bSGábor Stefanik u8 ant_available_a; /* 2GHz antenna available bits (up to 4) */ 31f679056bSGábor Stefanik u8 ant_available_bg; /* 5GHz antenna available bits (up to 4) */ 32ac82fab4SLarry Finger u16 pa0b0; 33ac82fab4SLarry Finger u16 pa0b1; 34ac82fab4SLarry Finger u16 pa0b2; 35ac82fab4SLarry Finger u16 pa1b0; 36ac82fab4SLarry Finger u16 pa1b1; 37ac82fab4SLarry Finger u16 pa1b2; 38f679056bSGábor Stefanik u16 pa1lob0; 39f679056bSGábor Stefanik u16 pa1lob1; 40f679056bSGábor Stefanik u16 pa1lob2; 41f679056bSGábor Stefanik u16 pa1hib0; 42f679056bSGábor Stefanik u16 pa1hib1; 43f679056bSGábor Stefanik u16 pa1hib2; 44ac82fab4SLarry Finger u8 gpio0; /* GPIO pin 0 */ 45ac82fab4SLarry Finger u8 gpio1; /* GPIO pin 1 */ 46ac82fab4SLarry Finger u8 gpio2; /* GPIO pin 2 */ 47ac82fab4SLarry Finger u8 gpio3; /* GPIO pin 3 */ 48f679056bSGábor Stefanik u16 maxpwr_bg; /* 2.4GHz Amplifier Max Power (in dBm Q5.2) */ 49f679056bSGábor Stefanik u16 maxpwr_al; /* 5.2GHz Amplifier Max Power (in dBm Q5.2) */ 50f679056bSGábor Stefanik u16 maxpwr_a; /* 5.3GHz Amplifier Max Power (in dBm Q5.2) */ 51f679056bSGábor Stefanik u16 maxpwr_ah; /* 5.8GHz Amplifier Max Power (in dBm Q5.2) */ 52ac82fab4SLarry Finger u8 itssi_a; /* Idle TSSI Target for A-PHY */ 53ac82fab4SLarry Finger u8 itssi_bg; /* Idle TSSI Target for B/G-PHY */ 54f679056bSGábor Stefanik u8 tri2g; /* 2.4GHz TX isolation */ 55f679056bSGábor Stefanik u8 tri5gl; /* 5.2GHz TX isolation */ 56f679056bSGábor Stefanik u8 tri5g; /* 5.3GHz TX isolation */ 57f679056bSGábor Stefanik u8 tri5gh; /* 5.8GHz TX isolation */ 58172c69a4SRafał Miłecki u8 txpid2g[4]; /* 2GHz TX power index */ 59172c69a4SRafał Miłecki u8 txpid5gl[4]; /* 4.9 - 5.1GHz TX power index */ 60172c69a4SRafał Miłecki u8 txpid5g[4]; /* 5.1 - 5.5GHz TX power index */ 61172c69a4SRafał Miłecki u8 txpid5gh[4]; /* 5.5 - ...GHz TX power index */ 62f679056bSGábor Stefanik u8 rxpo2g; /* 2GHz RX power offset */ 63f679056bSGábor Stefanik u8 rxpo5g; /* 5GHz RX power offset */ 64f679056bSGábor Stefanik u8 rssisav2g; /* 2GHz RSSI params */ 65f679056bSGábor Stefanik u8 rssismc2g; 66f679056bSGábor Stefanik u8 rssismf2g; 67f679056bSGábor Stefanik u8 bxa2g; /* 2GHz BX arch */ 68f679056bSGábor Stefanik u8 rssisav5g; /* 5GHz RSSI params */ 69f679056bSGábor Stefanik u8 rssismc5g; 70f679056bSGábor Stefanik u8 rssismf5g; 71f679056bSGábor Stefanik u8 bxa5g; /* 5GHz BX arch */ 72f679056bSGábor Stefanik u16 cck2gpo; /* CCK power offset */ 73f679056bSGábor Stefanik u32 ofdm2gpo; /* 2.4GHz OFDM power offset */ 74f679056bSGábor Stefanik u32 ofdm5glpo; /* 5.2GHz OFDM power offset */ 75f679056bSGábor Stefanik u32 ofdm5gpo; /* 5.3GHz OFDM power offset */ 76f679056bSGábor Stefanik u32 ofdm5ghpo; /* 5.8GHz OFDM power offset */ 77f679056bSGábor Stefanik u16 boardflags_lo; /* Board flags (bits 0-15) */ 78f679056bSGábor Stefanik u16 boardflags_hi; /* Board flags (bits 16-31) */ 79f679056bSGábor Stefanik u16 boardflags2_lo; /* Board flags (bits 32-47) */ 80f679056bSGábor Stefanik u16 boardflags2_hi; /* Board flags (bits 48-63) */ 81f679056bSGábor Stefanik /* TODO store board flags in a single u64 */ 82e861b98dSMichael Buesch 83e861b98dSMichael Buesch /* Antenna gain values for up to 4 antennas 84e861b98dSMichael Buesch * on each band. Values in dBm/4 (Q5.2). Negative gain means the 85e861b98dSMichael Buesch * loss in the connectors is bigger than the gain. */ 86e861b98dSMichael Buesch struct { 87e861b98dSMichael Buesch struct { 88e861b98dSMichael Buesch s8 a0, a1, a2, a3; 89e861b98dSMichael Buesch } ghz24; /* 2.4GHz band */ 90e861b98dSMichael Buesch struct { 91e861b98dSMichael Buesch s8 a0, a1, a2, a3; 92e861b98dSMichael Buesch } ghz5; /* 5GHz band */ 93e861b98dSMichael Buesch } antenna_gain; 94ac82fab4SLarry Finger 95f679056bSGábor Stefanik /* TODO - add any parameters needed from rev 2, 3, 4, 5 or 8 SPROMs */ 9661e115a5SMichael Buesch }; 9761e115a5SMichael Buesch 9861e115a5SMichael Buesch /* Information about the PCB the circuitry is soldered on. */ 9961e115a5SMichael Buesch struct ssb_boardinfo { 10061e115a5SMichael Buesch u16 vendor; 10161e115a5SMichael Buesch u16 type; 10261e115a5SMichael Buesch u16 rev; 10361e115a5SMichael Buesch }; 10461e115a5SMichael Buesch 10561e115a5SMichael Buesch 10661e115a5SMichael Buesch struct ssb_device; 10761e115a5SMichael Buesch /* Lowlevel read/write operations on the device MMIO. 10861e115a5SMichael Buesch * Internal, don't use that outside of ssb. */ 10961e115a5SMichael Buesch struct ssb_bus_ops { 110ffc7689dSMichael Buesch u8 (*read8)(struct ssb_device *dev, u16 offset); 11161e115a5SMichael Buesch u16 (*read16)(struct ssb_device *dev, u16 offset); 11261e115a5SMichael Buesch u32 (*read32)(struct ssb_device *dev, u16 offset); 113ffc7689dSMichael Buesch void (*write8)(struct ssb_device *dev, u16 offset, u8 value); 11461e115a5SMichael Buesch void (*write16)(struct ssb_device *dev, u16 offset, u16 value); 11561e115a5SMichael Buesch void (*write32)(struct ssb_device *dev, u16 offset, u32 value); 116d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO 117d625a29bSMichael Buesch void (*block_read)(struct ssb_device *dev, void *buffer, 118d625a29bSMichael Buesch size_t count, u16 offset, u8 reg_width); 119d625a29bSMichael Buesch void (*block_write)(struct ssb_device *dev, const void *buffer, 120d625a29bSMichael Buesch size_t count, u16 offset, u8 reg_width); 121d625a29bSMichael Buesch #endif 12261e115a5SMichael Buesch }; 12361e115a5SMichael Buesch 12461e115a5SMichael Buesch 12561e115a5SMichael Buesch /* Core-ID values. */ 12661e115a5SMichael Buesch #define SSB_DEV_CHIPCOMMON 0x800 12761e115a5SMichael Buesch #define SSB_DEV_ILINE20 0x801 12861e115a5SMichael Buesch #define SSB_DEV_SDRAM 0x803 12961e115a5SMichael Buesch #define SSB_DEV_PCI 0x804 13061e115a5SMichael Buesch #define SSB_DEV_MIPS 0x805 13161e115a5SMichael Buesch #define SSB_DEV_ETHERNET 0x806 13261e115a5SMichael Buesch #define SSB_DEV_V90 0x807 13361e115a5SMichael Buesch #define SSB_DEV_USB11_HOSTDEV 0x808 13461e115a5SMichael Buesch #define SSB_DEV_ADSL 0x809 13561e115a5SMichael Buesch #define SSB_DEV_ILINE100 0x80A 13661e115a5SMichael Buesch #define SSB_DEV_IPSEC 0x80B 13761e115a5SMichael Buesch #define SSB_DEV_PCMCIA 0x80D 13861e115a5SMichael Buesch #define SSB_DEV_INTERNAL_MEM 0x80E 13961e115a5SMichael Buesch #define SSB_DEV_MEMC_SDRAM 0x80F 14061e115a5SMichael Buesch #define SSB_DEV_EXTIF 0x811 14161e115a5SMichael Buesch #define SSB_DEV_80211 0x812 14261e115a5SMichael Buesch #define SSB_DEV_MIPS_3302 0x816 14361e115a5SMichael Buesch #define SSB_DEV_USB11_HOST 0x817 14461e115a5SMichael Buesch #define SSB_DEV_USB11_DEV 0x818 14561e115a5SMichael Buesch #define SSB_DEV_USB20_HOST 0x819 14661e115a5SMichael Buesch #define SSB_DEV_USB20_DEV 0x81A 14761e115a5SMichael Buesch #define SSB_DEV_SDIO_HOST 0x81B 14861e115a5SMichael Buesch #define SSB_DEV_ROBOSWITCH 0x81C 14961e115a5SMichael Buesch #define SSB_DEV_PARA_ATA 0x81D 15061e115a5SMichael Buesch #define SSB_DEV_SATA_XORDMA 0x81E 15161e115a5SMichael Buesch #define SSB_DEV_ETHERNET_GBIT 0x81F 15261e115a5SMichael Buesch #define SSB_DEV_PCIE 0x820 15361e115a5SMichael Buesch #define SSB_DEV_MIMO_PHY 0x821 15461e115a5SMichael Buesch #define SSB_DEV_SRAM_CTRLR 0x822 15561e115a5SMichael Buesch #define SSB_DEV_MINI_MACPHY 0x823 15661e115a5SMichael Buesch #define SSB_DEV_ARM_1176 0x824 15761e115a5SMichael Buesch #define SSB_DEV_ARM_7TDMI 0x825 15861e115a5SMichael Buesch 15961e115a5SMichael Buesch /* Vendor-ID values */ 16061e115a5SMichael Buesch #define SSB_VENDOR_BROADCOM 0x4243 16161e115a5SMichael Buesch 16261e115a5SMichael Buesch /* Some kernel subsystems poke with dev->drvdata, so we must use the 16361e115a5SMichael Buesch * following ugly workaround to get from struct device to struct ssb_device */ 16461e115a5SMichael Buesch struct __ssb_dev_wrapper { 16561e115a5SMichael Buesch struct device dev; 16661e115a5SMichael Buesch struct ssb_device *sdev; 16761e115a5SMichael Buesch }; 16861e115a5SMichael Buesch 16961e115a5SMichael Buesch struct ssb_device { 17061e115a5SMichael Buesch /* Having a copy of the ops pointer in each dev struct 17161e115a5SMichael Buesch * is an optimization. */ 17261e115a5SMichael Buesch const struct ssb_bus_ops *ops; 17361e115a5SMichael Buesch 17414f92952SFUJITA Tomonori struct device *dev, *dma_dev; 1754ac58469SMichael Buesch 17661e115a5SMichael Buesch struct ssb_bus *bus; 17761e115a5SMichael Buesch struct ssb_device_id id; 17861e115a5SMichael Buesch 17961e115a5SMichael Buesch u8 core_index; 18061e115a5SMichael Buesch unsigned int irq; 18161e115a5SMichael Buesch 18261e115a5SMichael Buesch /* Internal-only stuff follows. */ 18361e115a5SMichael Buesch void *drvdata; /* Per-device data */ 18461e115a5SMichael Buesch void *devtypedata; /* Per-devicetype (eg 802.11) data */ 18561e115a5SMichael Buesch }; 18661e115a5SMichael Buesch 18761e115a5SMichael Buesch /* Go from struct device to struct ssb_device. */ 18861e115a5SMichael Buesch static inline 18961e115a5SMichael Buesch struct ssb_device * dev_to_ssb_dev(struct device *dev) 19061e115a5SMichael Buesch { 19161e115a5SMichael Buesch struct __ssb_dev_wrapper *wrap; 19261e115a5SMichael Buesch wrap = container_of(dev, struct __ssb_dev_wrapper, dev); 19361e115a5SMichael Buesch return wrap->sdev; 19461e115a5SMichael Buesch } 19561e115a5SMichael Buesch 19661e115a5SMichael Buesch /* Device specific user data */ 19761e115a5SMichael Buesch static inline 19861e115a5SMichael Buesch void ssb_set_drvdata(struct ssb_device *dev, void *data) 19961e115a5SMichael Buesch { 20061e115a5SMichael Buesch dev->drvdata = data; 20161e115a5SMichael Buesch } 20261e115a5SMichael Buesch static inline 20361e115a5SMichael Buesch void * ssb_get_drvdata(struct ssb_device *dev) 20461e115a5SMichael Buesch { 20561e115a5SMichael Buesch return dev->drvdata; 20661e115a5SMichael Buesch } 20761e115a5SMichael Buesch 20861e115a5SMichael Buesch /* Devicetype specific user data. This is per device-type (not per device) */ 20961e115a5SMichael Buesch void ssb_set_devtypedata(struct ssb_device *dev, void *data); 21061e115a5SMichael Buesch static inline 21161e115a5SMichael Buesch void * ssb_get_devtypedata(struct ssb_device *dev) 21261e115a5SMichael Buesch { 21361e115a5SMichael Buesch return dev->devtypedata; 21461e115a5SMichael Buesch } 21561e115a5SMichael Buesch 21661e115a5SMichael Buesch 21761e115a5SMichael Buesch struct ssb_driver { 21861e115a5SMichael Buesch const char *name; 21961e115a5SMichael Buesch const struct ssb_device_id *id_table; 22061e115a5SMichael Buesch 22161e115a5SMichael Buesch int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id); 22261e115a5SMichael Buesch void (*remove)(struct ssb_device *dev); 22361e115a5SMichael Buesch int (*suspend)(struct ssb_device *dev, pm_message_t state); 22461e115a5SMichael Buesch int (*resume)(struct ssb_device *dev); 22561e115a5SMichael Buesch void (*shutdown)(struct ssb_device *dev); 22661e115a5SMichael Buesch 22761e115a5SMichael Buesch struct device_driver drv; 22861e115a5SMichael Buesch }; 22961e115a5SMichael Buesch #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv) 23061e115a5SMichael Buesch 23161e115a5SMichael Buesch extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner); 23261e115a5SMichael Buesch static inline int ssb_driver_register(struct ssb_driver *drv) 23361e115a5SMichael Buesch { 23461e115a5SMichael Buesch return __ssb_driver_register(drv, THIS_MODULE); 23561e115a5SMichael Buesch } 23661e115a5SMichael Buesch extern void ssb_driver_unregister(struct ssb_driver *drv); 23761e115a5SMichael Buesch 23861e115a5SMichael Buesch 23961e115a5SMichael Buesch 24061e115a5SMichael Buesch 24161e115a5SMichael Buesch enum ssb_bustype { 24261e115a5SMichael Buesch SSB_BUSTYPE_SSB, /* This SSB bus is the system bus */ 24361e115a5SMichael Buesch SSB_BUSTYPE_PCI, /* SSB is connected to PCI bus */ 24461e115a5SMichael Buesch SSB_BUSTYPE_PCMCIA, /* SSB is connected to PCMCIA bus */ 24524ea602eSAlbert Herranz SSB_BUSTYPE_SDIO, /* SSB is connected to SDIO bus */ 24661e115a5SMichael Buesch }; 24761e115a5SMichael Buesch 24861e115a5SMichael Buesch /* board_vendor */ 24961e115a5SMichael Buesch #define SSB_BOARDVENDOR_BCM 0x14E4 /* Broadcom */ 25061e115a5SMichael Buesch #define SSB_BOARDVENDOR_DELL 0x1028 /* Dell */ 25161e115a5SMichael Buesch #define SSB_BOARDVENDOR_HP 0x0E11 /* HP */ 25261e115a5SMichael Buesch /* board_type */ 25361e115a5SMichael Buesch #define SSB_BOARD_BCM94306MP 0x0418 25461e115a5SMichael Buesch #define SSB_BOARD_BCM4309G 0x0421 25561e115a5SMichael Buesch #define SSB_BOARD_BCM4306CB 0x0417 25661e115a5SMichael Buesch #define SSB_BOARD_BCM4309MP 0x040C 25761e115a5SMichael Buesch #define SSB_BOARD_MP4318 0x044A 25861e115a5SMichael Buesch #define SSB_BOARD_BU4306 0x0416 25961e115a5SMichael Buesch #define SSB_BOARD_BU4309 0x040A 26061e115a5SMichael Buesch /* chip_package */ 26161e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712S 1 /* Small 200pin 4712 */ 26261e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712M 2 /* Medium 225pin 4712 */ 26361e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712L 0 /* Large 340pin 4712 */ 26461e115a5SMichael Buesch 26561e115a5SMichael Buesch #include <linux/ssb/ssb_driver_chipcommon.h> 26661e115a5SMichael Buesch #include <linux/ssb/ssb_driver_mips.h> 26761e115a5SMichael Buesch #include <linux/ssb/ssb_driver_extif.h> 26861e115a5SMichael Buesch #include <linux/ssb/ssb_driver_pci.h> 26961e115a5SMichael Buesch 27061e115a5SMichael Buesch struct ssb_bus { 27161e115a5SMichael Buesch /* The MMIO area. */ 27261e115a5SMichael Buesch void __iomem *mmio; 27361e115a5SMichael Buesch 27461e115a5SMichael Buesch const struct ssb_bus_ops *ops; 27561e115a5SMichael Buesch 2768b45499cSMichael Buesch /* The core currently mapped into the MMIO window. 2778b45499cSMichael Buesch * Not valid on all host-buses. So don't use outside of SSB. */ 27861e115a5SMichael Buesch struct ssb_device *mapped_device; 27924ea602eSAlbert Herranz union { 28061e115a5SMichael Buesch /* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */ 28161e115a5SMichael Buesch u8 mapped_pcmcia_seg; 28224ea602eSAlbert Herranz /* Current SSB base address window for SDIO. */ 28324ea602eSAlbert Herranz u32 sdio_sbaddr; 28424ea602eSAlbert Herranz }; 285993e1c78SMichael Buesch /* Lock for core and segment switching. 286993e1c78SMichael Buesch * On PCMCIA-host busses this is used to protect the whole MMIO access. */ 28761e115a5SMichael Buesch spinlock_t bar_lock; 28861e115a5SMichael Buesch 2898b45499cSMichael Buesch /* The host-bus this backplane is running on. */ 29061e115a5SMichael Buesch enum ssb_bustype bustype; 2918b45499cSMichael Buesch /* Pointers to the host-bus. Check bustype before using any of these pointers. */ 2928b45499cSMichael Buesch union { 29361e115a5SMichael Buesch /* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */ 29461e115a5SMichael Buesch struct pci_dev *host_pci; 29561e115a5SMichael Buesch /* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */ 29661e115a5SMichael Buesch struct pcmcia_device *host_pcmcia; 29724ea602eSAlbert Herranz /* Pointer to the SDIO device (only if bustype == SSB_BUSTYPE_SDIO). */ 29824ea602eSAlbert Herranz struct sdio_func *host_sdio; 2998b45499cSMichael Buesch }; 30024ea602eSAlbert Herranz 30124ea602eSAlbert Herranz /* See enum ssb_quirks */ 30224ea602eSAlbert Herranz unsigned int quirks; 30361e115a5SMichael Buesch 304e7ec2e32SMichael Buesch #ifdef CONFIG_SSB_SPROM 30561e115a5SMichael Buesch /* Mutex to protect the SPROM writing. */ 306e7ec2e32SMichael Buesch struct mutex sprom_mutex; 30761e115a5SMichael Buesch #endif 30861e115a5SMichael Buesch 30961e115a5SMichael Buesch /* ID information about the Chip. */ 31061e115a5SMichael Buesch u16 chip_id; 311ce57d9e6SRafał Miłecki u8 chip_rev; 312ea2db495SRafał Miłecki u16 sprom_offset; 313c272ef44SLarry Finger u16 sprom_size; /* number of words in sprom */ 31461e115a5SMichael Buesch u8 chip_package; 31561e115a5SMichael Buesch 31661e115a5SMichael Buesch /* List of devices (cores) on the backplane. */ 31761e115a5SMichael Buesch struct ssb_device devices[SSB_MAX_NR_CORES]; 31861e115a5SMichael Buesch u8 nr_devices; 31961e115a5SMichael Buesch 32061e115a5SMichael Buesch /* Software ID number for this bus. */ 32161e115a5SMichael Buesch unsigned int busnumber; 32261e115a5SMichael Buesch 32361e115a5SMichael Buesch /* The ChipCommon device (if available). */ 32461e115a5SMichael Buesch struct ssb_chipcommon chipco; 32561e115a5SMichael Buesch /* The PCI-core device (if available). */ 32661e115a5SMichael Buesch struct ssb_pcicore pcicore; 32761e115a5SMichael Buesch /* The MIPS-core device (if available). */ 32861e115a5SMichael Buesch struct ssb_mipscore mipscore; 32961e115a5SMichael Buesch /* The EXTif-core device (if available). */ 33061e115a5SMichael Buesch struct ssb_extif extif; 33161e115a5SMichael Buesch 33261e115a5SMichael Buesch /* The following structure elements are not available in early 33361e115a5SMichael Buesch * SSB initialization. Though, they are available for regular 33461e115a5SMichael Buesch * registered drivers at any stage. So be careful when 33561e115a5SMichael Buesch * using them in the ssb core code. */ 33661e115a5SMichael Buesch 33761e115a5SMichael Buesch /* ID information about the PCB. */ 33861e115a5SMichael Buesch struct ssb_boardinfo boardinfo; 33961e115a5SMichael Buesch /* Contents of the SPROM. */ 34061e115a5SMichael Buesch struct ssb_sprom sprom; 3417cb44615SMichael Buesch /* If the board has a cardbus slot, this is set to true. */ 3427cb44615SMichael Buesch bool has_cardbus_slot; 34361e115a5SMichael Buesch 34453521d8cSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED 34553521d8cSMichael Buesch /* Lock for GPIO register access. */ 34653521d8cSMichael Buesch spinlock_t gpio_lock; 34753521d8cSMichael Buesch #endif /* EMBEDDED */ 34853521d8cSMichael Buesch 34961e115a5SMichael Buesch /* Internal-only stuff follows. Do not touch. */ 35061e115a5SMichael Buesch struct list_head list; 35161e115a5SMichael Buesch #ifdef CONFIG_SSB_DEBUG 35261e115a5SMichael Buesch /* Is the bus already powered up? */ 35361e115a5SMichael Buesch bool powered_up; 35461e115a5SMichael Buesch int power_warn_count; 35561e115a5SMichael Buesch #endif /* DEBUG */ 35661e115a5SMichael Buesch }; 35761e115a5SMichael Buesch 35824ea602eSAlbert Herranz enum ssb_quirks { 35924ea602eSAlbert Herranz /* SDIO connected card requires performing a read after writing a 32-bit value */ 36024ea602eSAlbert Herranz SSB_QUIRK_SDIO_READ_AFTER_WRITE32 = (1 << 0), 36124ea602eSAlbert Herranz }; 36224ea602eSAlbert Herranz 36361e115a5SMichael Buesch /* The initialization-invariants. */ 36461e115a5SMichael Buesch struct ssb_init_invariants { 3657cb44615SMichael Buesch /* Versioning information about the PCB. */ 36661e115a5SMichael Buesch struct ssb_boardinfo boardinfo; 3677cb44615SMichael Buesch /* The SPROM information. That's either stored in an 3687cb44615SMichael Buesch * EEPROM or NVRAM on the board. */ 36961e115a5SMichael Buesch struct ssb_sprom sprom; 3707cb44615SMichael Buesch /* If the board has a cardbus slot, this is set to true. */ 3717cb44615SMichael Buesch bool has_cardbus_slot; 37261e115a5SMichael Buesch }; 37361e115a5SMichael Buesch /* Type of function to fetch the invariants. */ 37461e115a5SMichael Buesch typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus, 37561e115a5SMichael Buesch struct ssb_init_invariants *iv); 37661e115a5SMichael Buesch 37761e115a5SMichael Buesch /* Register a SSB system bus. get_invariants() is called after the 37861e115a5SMichael Buesch * basic system devices are initialized. 37961e115a5SMichael Buesch * The invariants are usually fetched from some NVRAM. 38061e115a5SMichael Buesch * Put the invariants into the struct pointed to by iv. */ 38161e115a5SMichael Buesch extern int ssb_bus_ssbbus_register(struct ssb_bus *bus, 38261e115a5SMichael Buesch unsigned long baseaddr, 38361e115a5SMichael Buesch ssb_invariants_func_t get_invariants); 38461e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST 38561e115a5SMichael Buesch extern int ssb_bus_pcibus_register(struct ssb_bus *bus, 38661e115a5SMichael Buesch struct pci_dev *host_pci); 38761e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */ 38861e115a5SMichael Buesch #ifdef CONFIG_SSB_PCMCIAHOST 38961e115a5SMichael Buesch extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus, 39061e115a5SMichael Buesch struct pcmcia_device *pcmcia_dev, 39161e115a5SMichael Buesch unsigned long baseaddr); 39261e115a5SMichael Buesch #endif /* CONFIG_SSB_PCMCIAHOST */ 39324ea602eSAlbert Herranz #ifdef CONFIG_SSB_SDIOHOST 39424ea602eSAlbert Herranz extern int ssb_bus_sdiobus_register(struct ssb_bus *bus, 39524ea602eSAlbert Herranz struct sdio_func *sdio_func, 39624ea602eSAlbert Herranz unsigned int quirks); 39724ea602eSAlbert Herranz #endif /* CONFIG_SSB_SDIOHOST */ 39824ea602eSAlbert Herranz 39961e115a5SMichael Buesch 40061e115a5SMichael Buesch extern void ssb_bus_unregister(struct ssb_bus *bus); 40161e115a5SMichael Buesch 402d53cdbb9SJohn W. Linville /* Does the device have an SPROM? */ 403d53cdbb9SJohn W. Linville extern bool ssb_is_sprom_available(struct ssb_bus *bus); 404d53cdbb9SJohn W. Linville 405e79c1ba8SMichael Buesch /* Set a fallback SPROM. 406e79c1ba8SMichael Buesch * See kdoc at the function definition for complete documentation. */ 407e79c1ba8SMichael Buesch extern int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom); 408e79c1ba8SMichael Buesch 4098fe2b65aSMichael Buesch /* Suspend a SSB bus. 4108fe2b65aSMichael Buesch * Call this from the parent bus suspend routine. */ 4118fe2b65aSMichael Buesch extern int ssb_bus_suspend(struct ssb_bus *bus); 4128fe2b65aSMichael Buesch /* Resume a SSB bus. 4138fe2b65aSMichael Buesch * Call this from the parent bus resume routine. */ 4148fe2b65aSMichael Buesch extern int ssb_bus_resume(struct ssb_bus *bus); 4158fe2b65aSMichael Buesch 41661e115a5SMichael Buesch extern u32 ssb_clockspeed(struct ssb_bus *bus); 41761e115a5SMichael Buesch 41861e115a5SMichael Buesch /* Is the device enabled in hardware? */ 41961e115a5SMichael Buesch int ssb_device_is_enabled(struct ssb_device *dev); 42061e115a5SMichael Buesch /* Enable a device and pass device-specific SSB_TMSLOW flags. 42161e115a5SMichael Buesch * If no device-specific flags are available, use 0. */ 42261e115a5SMichael Buesch void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags); 42361e115a5SMichael Buesch /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */ 42461e115a5SMichael Buesch void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags); 42561e115a5SMichael Buesch 42661e115a5SMichael Buesch 42761e115a5SMichael Buesch /* Device MMIO register read/write functions. */ 428ffc7689dSMichael Buesch static inline u8 ssb_read8(struct ssb_device *dev, u16 offset) 429ffc7689dSMichael Buesch { 430ffc7689dSMichael Buesch return dev->ops->read8(dev, offset); 431ffc7689dSMichael Buesch } 43261e115a5SMichael Buesch static inline u16 ssb_read16(struct ssb_device *dev, u16 offset) 43361e115a5SMichael Buesch { 43461e115a5SMichael Buesch return dev->ops->read16(dev, offset); 43561e115a5SMichael Buesch } 43661e115a5SMichael Buesch static inline u32 ssb_read32(struct ssb_device *dev, u16 offset) 43761e115a5SMichael Buesch { 43861e115a5SMichael Buesch return dev->ops->read32(dev, offset); 43961e115a5SMichael Buesch } 440ffc7689dSMichael Buesch static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value) 441ffc7689dSMichael Buesch { 442ffc7689dSMichael Buesch dev->ops->write8(dev, offset, value); 443ffc7689dSMichael Buesch } 44461e115a5SMichael Buesch static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value) 44561e115a5SMichael Buesch { 44661e115a5SMichael Buesch dev->ops->write16(dev, offset, value); 44761e115a5SMichael Buesch } 44861e115a5SMichael Buesch static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value) 44961e115a5SMichael Buesch { 45061e115a5SMichael Buesch dev->ops->write32(dev, offset, value); 45161e115a5SMichael Buesch } 452d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO 453d625a29bSMichael Buesch static inline void ssb_block_read(struct ssb_device *dev, void *buffer, 454d625a29bSMichael Buesch size_t count, u16 offset, u8 reg_width) 455d625a29bSMichael Buesch { 456d625a29bSMichael Buesch dev->ops->block_read(dev, buffer, count, offset, reg_width); 457d625a29bSMichael Buesch } 458d625a29bSMichael Buesch 459d625a29bSMichael Buesch static inline void ssb_block_write(struct ssb_device *dev, const void *buffer, 460d625a29bSMichael Buesch size_t count, u16 offset, u8 reg_width) 461d625a29bSMichael Buesch { 462d625a29bSMichael Buesch dev->ops->block_write(dev, buffer, count, offset, reg_width); 463d625a29bSMichael Buesch } 464d625a29bSMichael Buesch #endif /* CONFIG_SSB_BLOCKIO */ 46561e115a5SMichael Buesch 46661e115a5SMichael Buesch 467f225763aSMichael Buesch /* The SSB DMA API. Use this API for any DMA operation on the device. 468f225763aSMichael Buesch * This API basically is a wrapper that calls the correct DMA API for 469f225763aSMichael Buesch * the host device type the SSB device is attached to. */ 470f225763aSMichael Buesch 47161e115a5SMichael Buesch /* Translation (routing) bits that need to be ORed to DMA 47261e115a5SMichael Buesch * addresses before they are given to a device. */ 47361e115a5SMichael Buesch extern u32 ssb_dma_translation(struct ssb_device *dev); 47461e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_MASK 0xC0000000 47561e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_SHIFT 30 47661e115a5SMichael Buesch 477f225763aSMichael Buesch static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev) 478f225763aSMichael Buesch { 479f225763aSMichael Buesch #ifdef CONFIG_SSB_DEBUG 480f225763aSMichael Buesch printk(KERN_ERR "SSB: BUG! Calling DMA API for " 481f225763aSMichael Buesch "unsupported bustype %d\n", dev->bus->bustype); 482f225763aSMichael Buesch #endif /* DEBUG */ 483f225763aSMichael Buesch } 484f225763aSMichael Buesch 48561e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST 48661e115a5SMichael Buesch /* PCI-host wrapper driver */ 48761e115a5SMichael Buesch extern int ssb_pcihost_register(struct pci_driver *driver); 48861e115a5SMichael Buesch static inline void ssb_pcihost_unregister(struct pci_driver *driver) 48961e115a5SMichael Buesch { 49061e115a5SMichael Buesch pci_unregister_driver(driver); 49161e115a5SMichael Buesch } 492961d57c8SMiguel Botón 493961d57c8SMiguel Botón static inline 494961d57c8SMiguel Botón void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state) 495961d57c8SMiguel Botón { 496961d57c8SMiguel Botón if (sdev->bus->bustype == SSB_BUSTYPE_PCI) 497961d57c8SMiguel Botón pci_set_power_state(sdev->bus->host_pci, state); 498961d57c8SMiguel Botón } 499532031d7SAndrew Morton #else 500532031d7SAndrew Morton static inline void ssb_pcihost_unregister(struct pci_driver *driver) 501532031d7SAndrew Morton { 502532031d7SAndrew Morton } 503532031d7SAndrew Morton 504532031d7SAndrew Morton static inline 505532031d7SAndrew Morton void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state) 506532031d7SAndrew Morton { 507532031d7SAndrew Morton } 50861e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */ 50961e115a5SMichael Buesch 51061e115a5SMichael Buesch 51161e115a5SMichael Buesch /* If a driver is shutdown or suspended, call this to signal 51261e115a5SMichael Buesch * that the bus may be completely powered down. SSB will decide, 51361e115a5SMichael Buesch * if it's really time to power down the bus, based on if there 51461e115a5SMichael Buesch * are other devices that want to run. */ 51561e115a5SMichael Buesch extern int ssb_bus_may_powerdown(struct ssb_bus *bus); 51661e115a5SMichael Buesch /* Before initializing and enabling a device, call this to power-up the bus. 51761e115a5SMichael Buesch * If you want to allow use of dynamic-power-control, pass the flag. 51861e115a5SMichael Buesch * Otherwise static always-on powercontrol will be used. */ 51961e115a5SMichael Buesch extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl); 52061e115a5SMichael Buesch 521*8576f815SRafał Miłecki extern void ssb_commit_settings(struct ssb_bus *bus); 52261e115a5SMichael Buesch 52361e115a5SMichael Buesch /* Various helper functions */ 52461e115a5SMichael Buesch extern u32 ssb_admatch_base(u32 adm); 52561e115a5SMichael Buesch extern u32 ssb_admatch_size(u32 adm); 52661e115a5SMichael Buesch 527aab547ceSMichael Buesch /* PCI device mapping and fixup routines. 528aab547ceSMichael Buesch * Called from the architecture pcibios init code. 529aab547ceSMichael Buesch * These are only available on SSB_EMBEDDED configurations. */ 530aab547ceSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED 531aab547ceSMichael Buesch int ssb_pcibios_plat_dev_init(struct pci_dev *dev); 532aab547ceSMichael Buesch int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin); 533aab547ceSMichael Buesch #endif /* CONFIG_SSB_EMBEDDED */ 53461e115a5SMichael Buesch 53561e115a5SMichael Buesch #endif /* LINUX_SSB_H_ */ 536