xref: /linux/include/linux/ssb/ssb.h (revision 8a5ac6ecd56756ee72588627aa23ab6cf9b790db)
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 */
28e2d646ceSRafał Miłecki 	u16 board_rev;		/* Board revision number from SPROM. */
29ac82fab4SLarry Finger 	u8 country_code;	/* Country Code */
3009779adeSRafał Miłecki 	u16 leddc_on_time;	/* LED Powersave Duty Cycle On Count */
3109779adeSRafał Miłecki 	u16 leddc_off_time;	/* LED Powersave Duty Cycle Off Count */
32f679056bSGábor Stefanik 	u8 ant_available_a;	/* 2GHz antenna available bits (up to 4) */
33f679056bSGábor Stefanik 	u8 ant_available_bg;	/* 5GHz antenna available bits (up to 4) */
34ac82fab4SLarry Finger 	u16 pa0b0;
35ac82fab4SLarry Finger 	u16 pa0b1;
36ac82fab4SLarry Finger 	u16 pa0b2;
37ac82fab4SLarry Finger 	u16 pa1b0;
38ac82fab4SLarry Finger 	u16 pa1b1;
39ac82fab4SLarry Finger 	u16 pa1b2;
40f679056bSGábor Stefanik 	u16 pa1lob0;
41f679056bSGábor Stefanik 	u16 pa1lob1;
42f679056bSGábor Stefanik 	u16 pa1lob2;
43f679056bSGábor Stefanik 	u16 pa1hib0;
44f679056bSGábor Stefanik 	u16 pa1hib1;
45f679056bSGábor Stefanik 	u16 pa1hib2;
46ac82fab4SLarry Finger 	u8 gpio0;		/* GPIO pin 0 */
47ac82fab4SLarry Finger 	u8 gpio1;		/* GPIO pin 1 */
48ac82fab4SLarry Finger 	u8 gpio2;		/* GPIO pin 2 */
49ac82fab4SLarry Finger 	u8 gpio3;		/* GPIO pin 3 */
50f679056bSGábor Stefanik 	u16 maxpwr_bg;		/* 2.4GHz Amplifier Max Power (in dBm Q5.2) */
51f679056bSGábor Stefanik 	u16 maxpwr_al;		/* 5.2GHz Amplifier Max Power (in dBm Q5.2) */
52f679056bSGábor Stefanik 	u16 maxpwr_a;		/* 5.3GHz Amplifier Max Power (in dBm Q5.2) */
53f679056bSGábor Stefanik 	u16 maxpwr_ah;		/* 5.8GHz Amplifier Max Power (in dBm Q5.2) */
54ac82fab4SLarry Finger 	u8 itssi_a;		/* Idle TSSI Target for A-PHY */
55ac82fab4SLarry Finger 	u8 itssi_bg;		/* Idle TSSI Target for B/G-PHY */
56f679056bSGábor Stefanik 	u8 tri2g;		/* 2.4GHz TX isolation */
57f679056bSGábor Stefanik 	u8 tri5gl;		/* 5.2GHz TX isolation */
58f679056bSGábor Stefanik 	u8 tri5g;		/* 5.3GHz TX isolation */
59f679056bSGábor Stefanik 	u8 tri5gh;		/* 5.8GHz TX isolation */
60172c69a4SRafał Miłecki 	u8 txpid2g[4];		/* 2GHz TX power index */
61172c69a4SRafał Miłecki 	u8 txpid5gl[4];		/* 4.9 - 5.1GHz TX power index */
62172c69a4SRafał Miłecki 	u8 txpid5g[4];		/* 5.1 - 5.5GHz TX power index */
63172c69a4SRafał Miłecki 	u8 txpid5gh[4];		/* 5.5 - ...GHz TX power index */
64f679056bSGábor Stefanik 	u8 rxpo2g;		/* 2GHz RX power offset */
65f679056bSGábor Stefanik 	u8 rxpo5g;		/* 5GHz RX power offset */
66f679056bSGábor Stefanik 	u8 rssisav2g;		/* 2GHz RSSI params */
67f679056bSGábor Stefanik 	u8 rssismc2g;
68f679056bSGábor Stefanik 	u8 rssismf2g;
69f679056bSGábor Stefanik 	u8 bxa2g;		/* 2GHz BX arch */
70f679056bSGábor Stefanik 	u8 rssisav5g;		/* 5GHz RSSI params */
71f679056bSGábor Stefanik 	u8 rssismc5g;
72f679056bSGábor Stefanik 	u8 rssismf5g;
73f679056bSGábor Stefanik 	u8 bxa5g;		/* 5GHz BX arch */
74f679056bSGábor Stefanik 	u16 cck2gpo;		/* CCK power offset */
75f679056bSGábor Stefanik 	u32 ofdm2gpo;		/* 2.4GHz OFDM power offset */
76f679056bSGábor Stefanik 	u32 ofdm5glpo;		/* 5.2GHz OFDM power offset */
77f679056bSGábor Stefanik 	u32 ofdm5gpo;		/* 5.3GHz OFDM power offset */
78f679056bSGábor Stefanik 	u32 ofdm5ghpo;		/* 5.8GHz OFDM power offset */
79f679056bSGábor Stefanik 	u16 boardflags_lo;	/* Board flags (bits 0-15) */
80f679056bSGábor Stefanik 	u16 boardflags_hi;	/* Board flags (bits 16-31) */
81f679056bSGábor Stefanik 	u16 boardflags2_lo;	/* Board flags (bits 32-47) */
82f679056bSGábor Stefanik 	u16 boardflags2_hi;	/* Board flags (bits 48-63) */
83f679056bSGábor Stefanik 	/* TODO store board flags in a single u64 */
84e861b98dSMichael Buesch 
85e861b98dSMichael Buesch 	/* Antenna gain values for up to 4 antennas
86e861b98dSMichael Buesch 	 * on each band. Values in dBm/4 (Q5.2). Negative gain means the
87e861b98dSMichael Buesch 	 * loss in the connectors is bigger than the gain. */
88e861b98dSMichael Buesch 	struct {
89e861b98dSMichael Buesch 		struct {
90e861b98dSMichael Buesch 			s8 a0, a1, a2, a3;
91e861b98dSMichael Buesch 		} ghz24;	/* 2.4GHz band */
92e861b98dSMichael Buesch 		struct {
93e861b98dSMichael Buesch 			s8 a0, a1, a2, a3;
94e861b98dSMichael Buesch 		} ghz5;		/* 5GHz band */
95e861b98dSMichael Buesch 	} antenna_gain;
96ac82fab4SLarry Finger 
97*8a5ac6ecSRafał Miłecki 	struct {
98*8a5ac6ecSRafał Miłecki 		struct {
99*8a5ac6ecSRafał Miłecki 			u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
100*8a5ac6ecSRafał Miłecki 		} ghz2;
101*8a5ac6ecSRafał Miłecki 		struct {
102*8a5ac6ecSRafał Miłecki 			u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
103*8a5ac6ecSRafał Miłecki 		} ghz5;
104*8a5ac6ecSRafał Miłecki 	} fem;
105*8a5ac6ecSRafał Miłecki 
106f679056bSGábor Stefanik 	/* TODO - add any parameters needed from rev 2, 3, 4, 5 or 8 SPROMs */
10761e115a5SMichael Buesch };
10861e115a5SMichael Buesch 
10961e115a5SMichael Buesch /* Information about the PCB the circuitry is soldered on. */
11061e115a5SMichael Buesch struct ssb_boardinfo {
11161e115a5SMichael Buesch 	u16 vendor;
11261e115a5SMichael Buesch 	u16 type;
113304e21bbSSergei Shtylyov 	u8  rev;
11461e115a5SMichael Buesch };
11561e115a5SMichael Buesch 
11661e115a5SMichael Buesch 
11761e115a5SMichael Buesch struct ssb_device;
11861e115a5SMichael Buesch /* Lowlevel read/write operations on the device MMIO.
11961e115a5SMichael Buesch  * Internal, don't use that outside of ssb. */
12061e115a5SMichael Buesch struct ssb_bus_ops {
121ffc7689dSMichael Buesch 	u8 (*read8)(struct ssb_device *dev, u16 offset);
12261e115a5SMichael Buesch 	u16 (*read16)(struct ssb_device *dev, u16 offset);
12361e115a5SMichael Buesch 	u32 (*read32)(struct ssb_device *dev, u16 offset);
124ffc7689dSMichael Buesch 	void (*write8)(struct ssb_device *dev, u16 offset, u8 value);
12561e115a5SMichael Buesch 	void (*write16)(struct ssb_device *dev, u16 offset, u16 value);
12661e115a5SMichael Buesch 	void (*write32)(struct ssb_device *dev, u16 offset, u32 value);
127d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO
128d625a29bSMichael Buesch 	void (*block_read)(struct ssb_device *dev, void *buffer,
129d625a29bSMichael Buesch 			   size_t count, u16 offset, u8 reg_width);
130d625a29bSMichael Buesch 	void (*block_write)(struct ssb_device *dev, const void *buffer,
131d625a29bSMichael Buesch 			    size_t count, u16 offset, u8 reg_width);
132d625a29bSMichael Buesch #endif
13361e115a5SMichael Buesch };
13461e115a5SMichael Buesch 
13561e115a5SMichael Buesch 
13661e115a5SMichael Buesch /* Core-ID values. */
13761e115a5SMichael Buesch #define SSB_DEV_CHIPCOMMON	0x800
13861e115a5SMichael Buesch #define SSB_DEV_ILINE20		0x801
13961e115a5SMichael Buesch #define SSB_DEV_SDRAM		0x803
14061e115a5SMichael Buesch #define SSB_DEV_PCI		0x804
14161e115a5SMichael Buesch #define SSB_DEV_MIPS		0x805
14261e115a5SMichael Buesch #define SSB_DEV_ETHERNET	0x806
14361e115a5SMichael Buesch #define SSB_DEV_V90		0x807
14461e115a5SMichael Buesch #define SSB_DEV_USB11_HOSTDEV	0x808
14561e115a5SMichael Buesch #define SSB_DEV_ADSL		0x809
14661e115a5SMichael Buesch #define SSB_DEV_ILINE100	0x80A
14761e115a5SMichael Buesch #define SSB_DEV_IPSEC		0x80B
14861e115a5SMichael Buesch #define SSB_DEV_PCMCIA		0x80D
14961e115a5SMichael Buesch #define SSB_DEV_INTERNAL_MEM	0x80E
15061e115a5SMichael Buesch #define SSB_DEV_MEMC_SDRAM	0x80F
15161e115a5SMichael Buesch #define SSB_DEV_EXTIF		0x811
15261e115a5SMichael Buesch #define SSB_DEV_80211		0x812
15361e115a5SMichael Buesch #define SSB_DEV_MIPS_3302	0x816
15461e115a5SMichael Buesch #define SSB_DEV_USB11_HOST	0x817
15561e115a5SMichael Buesch #define SSB_DEV_USB11_DEV	0x818
15661e115a5SMichael Buesch #define SSB_DEV_USB20_HOST	0x819
15761e115a5SMichael Buesch #define SSB_DEV_USB20_DEV	0x81A
15861e115a5SMichael Buesch #define SSB_DEV_SDIO_HOST	0x81B
15961e115a5SMichael Buesch #define SSB_DEV_ROBOSWITCH	0x81C
16061e115a5SMichael Buesch #define SSB_DEV_PARA_ATA	0x81D
16161e115a5SMichael Buesch #define SSB_DEV_SATA_XORDMA	0x81E
16261e115a5SMichael Buesch #define SSB_DEV_ETHERNET_GBIT	0x81F
16361e115a5SMichael Buesch #define SSB_DEV_PCIE		0x820
16461e115a5SMichael Buesch #define SSB_DEV_MIMO_PHY	0x821
16561e115a5SMichael Buesch #define SSB_DEV_SRAM_CTRLR	0x822
16661e115a5SMichael Buesch #define SSB_DEV_MINI_MACPHY	0x823
16761e115a5SMichael Buesch #define SSB_DEV_ARM_1176	0x824
16861e115a5SMichael Buesch #define SSB_DEV_ARM_7TDMI	0x825
16961e115a5SMichael Buesch 
17061e115a5SMichael Buesch /* Vendor-ID values */
17161e115a5SMichael Buesch #define SSB_VENDOR_BROADCOM	0x4243
17261e115a5SMichael Buesch 
17361e115a5SMichael Buesch /* Some kernel subsystems poke with dev->drvdata, so we must use the
17461e115a5SMichael Buesch  * following ugly workaround to get from struct device to struct ssb_device */
17561e115a5SMichael Buesch struct __ssb_dev_wrapper {
17661e115a5SMichael Buesch 	struct device dev;
17761e115a5SMichael Buesch 	struct ssb_device *sdev;
17861e115a5SMichael Buesch };
17961e115a5SMichael Buesch 
18061e115a5SMichael Buesch struct ssb_device {
18161e115a5SMichael Buesch 	/* Having a copy of the ops pointer in each dev struct
18261e115a5SMichael Buesch 	 * is an optimization. */
18361e115a5SMichael Buesch 	const struct ssb_bus_ops *ops;
18461e115a5SMichael Buesch 
18514f92952SFUJITA Tomonori 	struct device *dev, *dma_dev;
1864ac58469SMichael Buesch 
18761e115a5SMichael Buesch 	struct ssb_bus *bus;
18861e115a5SMichael Buesch 	struct ssb_device_id id;
18961e115a5SMichael Buesch 
19061e115a5SMichael Buesch 	u8 core_index;
19161e115a5SMichael Buesch 	unsigned int irq;
19261e115a5SMichael Buesch 
19361e115a5SMichael Buesch 	/* Internal-only stuff follows. */
19461e115a5SMichael Buesch 	void *drvdata;		/* Per-device data */
19561e115a5SMichael Buesch 	void *devtypedata;	/* Per-devicetype (eg 802.11) data */
19661e115a5SMichael Buesch };
19761e115a5SMichael Buesch 
19861e115a5SMichael Buesch /* Go from struct device to struct ssb_device. */
19961e115a5SMichael Buesch static inline
20061e115a5SMichael Buesch struct ssb_device * dev_to_ssb_dev(struct device *dev)
20161e115a5SMichael Buesch {
20261e115a5SMichael Buesch 	struct __ssb_dev_wrapper *wrap;
20361e115a5SMichael Buesch 	wrap = container_of(dev, struct __ssb_dev_wrapper, dev);
20461e115a5SMichael Buesch 	return wrap->sdev;
20561e115a5SMichael Buesch }
20661e115a5SMichael Buesch 
20761e115a5SMichael Buesch /* Device specific user data */
20861e115a5SMichael Buesch static inline
20961e115a5SMichael Buesch void ssb_set_drvdata(struct ssb_device *dev, void *data)
21061e115a5SMichael Buesch {
21161e115a5SMichael Buesch 	dev->drvdata = data;
21261e115a5SMichael Buesch }
21361e115a5SMichael Buesch static inline
21461e115a5SMichael Buesch void * ssb_get_drvdata(struct ssb_device *dev)
21561e115a5SMichael Buesch {
21661e115a5SMichael Buesch 	return dev->drvdata;
21761e115a5SMichael Buesch }
21861e115a5SMichael Buesch 
21961e115a5SMichael Buesch /* Devicetype specific user data. This is per device-type (not per device) */
22061e115a5SMichael Buesch void ssb_set_devtypedata(struct ssb_device *dev, void *data);
22161e115a5SMichael Buesch static inline
22261e115a5SMichael Buesch void * ssb_get_devtypedata(struct ssb_device *dev)
22361e115a5SMichael Buesch {
22461e115a5SMichael Buesch 	return dev->devtypedata;
22561e115a5SMichael Buesch }
22661e115a5SMichael Buesch 
22761e115a5SMichael Buesch 
22861e115a5SMichael Buesch struct ssb_driver {
22961e115a5SMichael Buesch 	const char *name;
23061e115a5SMichael Buesch 	const struct ssb_device_id *id_table;
23161e115a5SMichael Buesch 
23261e115a5SMichael Buesch 	int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id);
23361e115a5SMichael Buesch 	void (*remove)(struct ssb_device *dev);
23461e115a5SMichael Buesch 	int (*suspend)(struct ssb_device *dev, pm_message_t state);
23561e115a5SMichael Buesch 	int (*resume)(struct ssb_device *dev);
23661e115a5SMichael Buesch 	void (*shutdown)(struct ssb_device *dev);
23761e115a5SMichael Buesch 
23861e115a5SMichael Buesch 	struct device_driver drv;
23961e115a5SMichael Buesch };
24061e115a5SMichael Buesch #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv)
24161e115a5SMichael Buesch 
24261e115a5SMichael Buesch extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
243eb5589a8SPaul Gortmaker #define ssb_driver_register(drv) \
244eb5589a8SPaul Gortmaker 	__ssb_driver_register(drv, THIS_MODULE)
245eb5589a8SPaul Gortmaker 
24661e115a5SMichael Buesch extern void ssb_driver_unregister(struct ssb_driver *drv);
24761e115a5SMichael Buesch 
24861e115a5SMichael Buesch 
24961e115a5SMichael Buesch 
25061e115a5SMichael Buesch 
25161e115a5SMichael Buesch enum ssb_bustype {
25261e115a5SMichael Buesch 	SSB_BUSTYPE_SSB,	/* This SSB bus is the system bus */
25361e115a5SMichael Buesch 	SSB_BUSTYPE_PCI,	/* SSB is connected to PCI bus */
25461e115a5SMichael Buesch 	SSB_BUSTYPE_PCMCIA,	/* SSB is connected to PCMCIA bus */
25524ea602eSAlbert Herranz 	SSB_BUSTYPE_SDIO,	/* SSB is connected to SDIO bus */
25661e115a5SMichael Buesch };
25761e115a5SMichael Buesch 
25861e115a5SMichael Buesch /* board_vendor */
25961e115a5SMichael Buesch #define SSB_BOARDVENDOR_BCM	0x14E4	/* Broadcom */
26061e115a5SMichael Buesch #define SSB_BOARDVENDOR_DELL	0x1028	/* Dell */
26161e115a5SMichael Buesch #define SSB_BOARDVENDOR_HP	0x0E11	/* HP */
26261e115a5SMichael Buesch /* board_type */
26361e115a5SMichael Buesch #define SSB_BOARD_BCM94306MP	0x0418
26461e115a5SMichael Buesch #define SSB_BOARD_BCM4309G	0x0421
26561e115a5SMichael Buesch #define SSB_BOARD_BCM4306CB	0x0417
26661e115a5SMichael Buesch #define SSB_BOARD_BCM4309MP	0x040C
26761e115a5SMichael Buesch #define SSB_BOARD_MP4318	0x044A
26861e115a5SMichael Buesch #define SSB_BOARD_BU4306	0x0416
26961e115a5SMichael Buesch #define SSB_BOARD_BU4309	0x040A
27061e115a5SMichael Buesch /* chip_package */
27161e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712S	1	/* Small 200pin 4712 */
27261e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712M	2	/* Medium 225pin 4712 */
27361e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712L	0	/* Large 340pin 4712 */
27461e115a5SMichael Buesch 
27561e115a5SMichael Buesch #include <linux/ssb/ssb_driver_chipcommon.h>
27661e115a5SMichael Buesch #include <linux/ssb/ssb_driver_mips.h>
27761e115a5SMichael Buesch #include <linux/ssb/ssb_driver_extif.h>
27861e115a5SMichael Buesch #include <linux/ssb/ssb_driver_pci.h>
27961e115a5SMichael Buesch 
28061e115a5SMichael Buesch struct ssb_bus {
28161e115a5SMichael Buesch 	/* The MMIO area. */
28261e115a5SMichael Buesch 	void __iomem *mmio;
28361e115a5SMichael Buesch 
28461e115a5SMichael Buesch 	const struct ssb_bus_ops *ops;
28561e115a5SMichael Buesch 
2868b45499cSMichael Buesch 	/* The core currently mapped into the MMIO window.
2878b45499cSMichael Buesch 	 * Not valid on all host-buses. So don't use outside of SSB. */
28861e115a5SMichael Buesch 	struct ssb_device *mapped_device;
28924ea602eSAlbert Herranz 	union {
29061e115a5SMichael Buesch 		/* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */
29161e115a5SMichael Buesch 		u8 mapped_pcmcia_seg;
29224ea602eSAlbert Herranz 		/* Current SSB base address window for SDIO. */
29324ea602eSAlbert Herranz 		u32 sdio_sbaddr;
29424ea602eSAlbert Herranz 	};
295993e1c78SMichael Buesch 	/* Lock for core and segment switching.
296993e1c78SMichael Buesch 	 * On PCMCIA-host busses this is used to protect the whole MMIO access. */
29761e115a5SMichael Buesch 	spinlock_t bar_lock;
29861e115a5SMichael Buesch 
2998b45499cSMichael Buesch 	/* The host-bus this backplane is running on. */
30061e115a5SMichael Buesch 	enum ssb_bustype bustype;
3018b45499cSMichael Buesch 	/* Pointers to the host-bus. Check bustype before using any of these pointers. */
3028b45499cSMichael Buesch 	union {
30361e115a5SMichael Buesch 		/* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */
30461e115a5SMichael Buesch 		struct pci_dev *host_pci;
30561e115a5SMichael Buesch 		/* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
30661e115a5SMichael Buesch 		struct pcmcia_device *host_pcmcia;
30724ea602eSAlbert Herranz 		/* Pointer to the SDIO device (only if bustype == SSB_BUSTYPE_SDIO). */
30824ea602eSAlbert Herranz 		struct sdio_func *host_sdio;
3098b45499cSMichael Buesch 	};
31024ea602eSAlbert Herranz 
31124ea602eSAlbert Herranz 	/* See enum ssb_quirks */
31224ea602eSAlbert Herranz 	unsigned int quirks;
31361e115a5SMichael Buesch 
314e7ec2e32SMichael Buesch #ifdef CONFIG_SSB_SPROM
31561e115a5SMichael Buesch 	/* Mutex to protect the SPROM writing. */
316e7ec2e32SMichael Buesch 	struct mutex sprom_mutex;
31761e115a5SMichael Buesch #endif
31861e115a5SMichael Buesch 
31961e115a5SMichael Buesch 	/* ID information about the Chip. */
32061e115a5SMichael Buesch 	u16 chip_id;
321ce57d9e6SRafał Miłecki 	u8 chip_rev;
322ea2db495SRafał Miłecki 	u16 sprom_offset;
323c272ef44SLarry Finger 	u16 sprom_size;		/* number of words in sprom */
32461e115a5SMichael Buesch 	u8 chip_package;
32561e115a5SMichael Buesch 
32661e115a5SMichael Buesch 	/* List of devices (cores) on the backplane. */
32761e115a5SMichael Buesch 	struct ssb_device devices[SSB_MAX_NR_CORES];
32861e115a5SMichael Buesch 	u8 nr_devices;
32961e115a5SMichael Buesch 
33061e115a5SMichael Buesch 	/* Software ID number for this bus. */
33161e115a5SMichael Buesch 	unsigned int busnumber;
33261e115a5SMichael Buesch 
33361e115a5SMichael Buesch 	/* The ChipCommon device (if available). */
33461e115a5SMichael Buesch 	struct ssb_chipcommon chipco;
33561e115a5SMichael Buesch 	/* The PCI-core device (if available). */
33661e115a5SMichael Buesch 	struct ssb_pcicore pcicore;
33761e115a5SMichael Buesch 	/* The MIPS-core device (if available). */
33861e115a5SMichael Buesch 	struct ssb_mipscore mipscore;
33961e115a5SMichael Buesch 	/* The EXTif-core device (if available). */
34061e115a5SMichael Buesch 	struct ssb_extif extif;
34161e115a5SMichael Buesch 
34261e115a5SMichael Buesch 	/* The following structure elements are not available in early
34361e115a5SMichael Buesch 	 * SSB initialization. Though, they are available for regular
34461e115a5SMichael Buesch 	 * registered drivers at any stage. So be careful when
34561e115a5SMichael Buesch 	 * using them in the ssb core code. */
34661e115a5SMichael Buesch 
34761e115a5SMichael Buesch 	/* ID information about the PCB. */
34861e115a5SMichael Buesch 	struct ssb_boardinfo boardinfo;
34961e115a5SMichael Buesch 	/* Contents of the SPROM. */
35061e115a5SMichael Buesch 	struct ssb_sprom sprom;
3517cb44615SMichael Buesch 	/* If the board has a cardbus slot, this is set to true. */
3527cb44615SMichael Buesch 	bool has_cardbus_slot;
35361e115a5SMichael Buesch 
35453521d8cSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED
35553521d8cSMichael Buesch 	/* Lock for GPIO register access. */
35653521d8cSMichael Buesch 	spinlock_t gpio_lock;
35753521d8cSMichael Buesch #endif /* EMBEDDED */
35853521d8cSMichael Buesch 
35961e115a5SMichael Buesch 	/* Internal-only stuff follows. Do not touch. */
36061e115a5SMichael Buesch 	struct list_head list;
36161e115a5SMichael Buesch #ifdef CONFIG_SSB_DEBUG
36261e115a5SMichael Buesch 	/* Is the bus already powered up? */
36361e115a5SMichael Buesch 	bool powered_up;
36461e115a5SMichael Buesch 	int power_warn_count;
36561e115a5SMichael Buesch #endif /* DEBUG */
36661e115a5SMichael Buesch };
36761e115a5SMichael Buesch 
36824ea602eSAlbert Herranz enum ssb_quirks {
36924ea602eSAlbert Herranz 	/* SDIO connected card requires performing a read after writing a 32-bit value */
37024ea602eSAlbert Herranz 	SSB_QUIRK_SDIO_READ_AFTER_WRITE32	= (1 << 0),
37124ea602eSAlbert Herranz };
37224ea602eSAlbert Herranz 
37361e115a5SMichael Buesch /* The initialization-invariants. */
37461e115a5SMichael Buesch struct ssb_init_invariants {
3757cb44615SMichael Buesch 	/* Versioning information about the PCB. */
37661e115a5SMichael Buesch 	struct ssb_boardinfo boardinfo;
3777cb44615SMichael Buesch 	/* The SPROM information. That's either stored in an
3787cb44615SMichael Buesch 	 * EEPROM or NVRAM on the board. */
37961e115a5SMichael Buesch 	struct ssb_sprom sprom;
3807cb44615SMichael Buesch 	/* If the board has a cardbus slot, this is set to true. */
3817cb44615SMichael Buesch 	bool has_cardbus_slot;
38261e115a5SMichael Buesch };
38361e115a5SMichael Buesch /* Type of function to fetch the invariants. */
38461e115a5SMichael Buesch typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
38561e115a5SMichael Buesch 				     struct ssb_init_invariants *iv);
38661e115a5SMichael Buesch 
38761e115a5SMichael Buesch /* Register a SSB system bus. get_invariants() is called after the
38861e115a5SMichael Buesch  * basic system devices are initialized.
38961e115a5SMichael Buesch  * The invariants are usually fetched from some NVRAM.
39061e115a5SMichael Buesch  * Put the invariants into the struct pointed to by iv. */
39161e115a5SMichael Buesch extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
39261e115a5SMichael Buesch 				   unsigned long baseaddr,
39361e115a5SMichael Buesch 				   ssb_invariants_func_t get_invariants);
39461e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST
39561e115a5SMichael Buesch extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
39661e115a5SMichael Buesch 				   struct pci_dev *host_pci);
39761e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */
39861e115a5SMichael Buesch #ifdef CONFIG_SSB_PCMCIAHOST
39961e115a5SMichael Buesch extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
40061e115a5SMichael Buesch 				      struct pcmcia_device *pcmcia_dev,
40161e115a5SMichael Buesch 				      unsigned long baseaddr);
40261e115a5SMichael Buesch #endif /* CONFIG_SSB_PCMCIAHOST */
40324ea602eSAlbert Herranz #ifdef CONFIG_SSB_SDIOHOST
40424ea602eSAlbert Herranz extern int ssb_bus_sdiobus_register(struct ssb_bus *bus,
40524ea602eSAlbert Herranz 				    struct sdio_func *sdio_func,
40624ea602eSAlbert Herranz 				    unsigned int quirks);
40724ea602eSAlbert Herranz #endif /* CONFIG_SSB_SDIOHOST */
40824ea602eSAlbert Herranz 
40961e115a5SMichael Buesch 
41061e115a5SMichael Buesch extern void ssb_bus_unregister(struct ssb_bus *bus);
41161e115a5SMichael Buesch 
412d53cdbb9SJohn W. Linville /* Does the device have an SPROM? */
413d53cdbb9SJohn W. Linville extern bool ssb_is_sprom_available(struct ssb_bus *bus);
414d53cdbb9SJohn W. Linville 
415e79c1ba8SMichael Buesch /* Set a fallback SPROM.
416e79c1ba8SMichael Buesch  * See kdoc at the function definition for complete documentation. */
417b3ae52b6SHauke Mehrtens extern int ssb_arch_register_fallback_sprom(
418b3ae52b6SHauke Mehrtens 		int (*sprom_callback)(struct ssb_bus *bus,
419b3ae52b6SHauke Mehrtens 		struct ssb_sprom *out));
420e79c1ba8SMichael Buesch 
4218fe2b65aSMichael Buesch /* Suspend a SSB bus.
4228fe2b65aSMichael Buesch  * Call this from the parent bus suspend routine. */
4238fe2b65aSMichael Buesch extern int ssb_bus_suspend(struct ssb_bus *bus);
4248fe2b65aSMichael Buesch /* Resume a SSB bus.
4258fe2b65aSMichael Buesch  * Call this from the parent bus resume routine. */
4268fe2b65aSMichael Buesch extern int ssb_bus_resume(struct ssb_bus *bus);
4278fe2b65aSMichael Buesch 
42861e115a5SMichael Buesch extern u32 ssb_clockspeed(struct ssb_bus *bus);
42961e115a5SMichael Buesch 
43061e115a5SMichael Buesch /* Is the device enabled in hardware? */
43161e115a5SMichael Buesch int ssb_device_is_enabled(struct ssb_device *dev);
43261e115a5SMichael Buesch /* Enable a device and pass device-specific SSB_TMSLOW flags.
43361e115a5SMichael Buesch  * If no device-specific flags are available, use 0. */
43461e115a5SMichael Buesch void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
43561e115a5SMichael Buesch /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
43661e115a5SMichael Buesch void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
43761e115a5SMichael Buesch 
43861e115a5SMichael Buesch 
43961e115a5SMichael Buesch /* Device MMIO register read/write functions. */
440ffc7689dSMichael Buesch static inline u8 ssb_read8(struct ssb_device *dev, u16 offset)
441ffc7689dSMichael Buesch {
442ffc7689dSMichael Buesch 	return dev->ops->read8(dev, offset);
443ffc7689dSMichael Buesch }
44461e115a5SMichael Buesch static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
44561e115a5SMichael Buesch {
44661e115a5SMichael Buesch 	return dev->ops->read16(dev, offset);
44761e115a5SMichael Buesch }
44861e115a5SMichael Buesch static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
44961e115a5SMichael Buesch {
45061e115a5SMichael Buesch 	return dev->ops->read32(dev, offset);
45161e115a5SMichael Buesch }
452ffc7689dSMichael Buesch static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value)
453ffc7689dSMichael Buesch {
454ffc7689dSMichael Buesch 	dev->ops->write8(dev, offset, value);
455ffc7689dSMichael Buesch }
45661e115a5SMichael Buesch static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
45761e115a5SMichael Buesch {
45861e115a5SMichael Buesch 	dev->ops->write16(dev, offset, value);
45961e115a5SMichael Buesch }
46061e115a5SMichael Buesch static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
46161e115a5SMichael Buesch {
46261e115a5SMichael Buesch 	dev->ops->write32(dev, offset, value);
46361e115a5SMichael Buesch }
464d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO
465d625a29bSMichael Buesch static inline void ssb_block_read(struct ssb_device *dev, void *buffer,
466d625a29bSMichael Buesch 				  size_t count, u16 offset, u8 reg_width)
467d625a29bSMichael Buesch {
468d625a29bSMichael Buesch 	dev->ops->block_read(dev, buffer, count, offset, reg_width);
469d625a29bSMichael Buesch }
470d625a29bSMichael Buesch 
471d625a29bSMichael Buesch static inline void ssb_block_write(struct ssb_device *dev, const void *buffer,
472d625a29bSMichael Buesch 				   size_t count, u16 offset, u8 reg_width)
473d625a29bSMichael Buesch {
474d625a29bSMichael Buesch 	dev->ops->block_write(dev, buffer, count, offset, reg_width);
475d625a29bSMichael Buesch }
476d625a29bSMichael Buesch #endif /* CONFIG_SSB_BLOCKIO */
47761e115a5SMichael Buesch 
47861e115a5SMichael Buesch 
479f225763aSMichael Buesch /* The SSB DMA API. Use this API for any DMA operation on the device.
480f225763aSMichael Buesch  * This API basically is a wrapper that calls the correct DMA API for
481f225763aSMichael Buesch  * the host device type the SSB device is attached to. */
482f225763aSMichael Buesch 
48361e115a5SMichael Buesch /* Translation (routing) bits that need to be ORed to DMA
48461e115a5SMichael Buesch  * addresses before they are given to a device. */
48561e115a5SMichael Buesch extern u32 ssb_dma_translation(struct ssb_device *dev);
48661e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_MASK	0xC0000000
48761e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_SHIFT	30
48861e115a5SMichael Buesch 
489f225763aSMichael Buesch static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev)
490f225763aSMichael Buesch {
491f225763aSMichael Buesch #ifdef CONFIG_SSB_DEBUG
492f225763aSMichael Buesch 	printk(KERN_ERR "SSB: BUG! Calling DMA API for "
493f225763aSMichael Buesch 	       "unsupported bustype %d\n", dev->bus->bustype);
494f225763aSMichael Buesch #endif /* DEBUG */
495f225763aSMichael Buesch }
496f225763aSMichael Buesch 
49761e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST
49861e115a5SMichael Buesch /* PCI-host wrapper driver */
49961e115a5SMichael Buesch extern int ssb_pcihost_register(struct pci_driver *driver);
50061e115a5SMichael Buesch static inline void ssb_pcihost_unregister(struct pci_driver *driver)
50161e115a5SMichael Buesch {
50261e115a5SMichael Buesch 	pci_unregister_driver(driver);
50361e115a5SMichael Buesch }
504961d57c8SMiguel Botón 
505961d57c8SMiguel Botón static inline
506961d57c8SMiguel Botón void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
507961d57c8SMiguel Botón {
508961d57c8SMiguel Botón 	if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
509961d57c8SMiguel Botón 		pci_set_power_state(sdev->bus->host_pci, state);
510961d57c8SMiguel Botón }
511532031d7SAndrew Morton #else
512532031d7SAndrew Morton static inline void ssb_pcihost_unregister(struct pci_driver *driver)
513532031d7SAndrew Morton {
514532031d7SAndrew Morton }
515532031d7SAndrew Morton 
516532031d7SAndrew Morton static inline
517532031d7SAndrew Morton void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
518532031d7SAndrew Morton {
519532031d7SAndrew Morton }
52061e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */
52161e115a5SMichael Buesch 
52261e115a5SMichael Buesch 
52361e115a5SMichael Buesch /* If a driver is shutdown or suspended, call this to signal
52461e115a5SMichael Buesch  * that the bus may be completely powered down. SSB will decide,
52561e115a5SMichael Buesch  * if it's really time to power down the bus, based on if there
52661e115a5SMichael Buesch  * are other devices that want to run. */
52761e115a5SMichael Buesch extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
52861e115a5SMichael Buesch /* Before initializing and enabling a device, call this to power-up the bus.
52961e115a5SMichael Buesch  * If you want to allow use of dynamic-power-control, pass the flag.
53061e115a5SMichael Buesch  * Otherwise static always-on powercontrol will be used. */
53161e115a5SMichael Buesch extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
53261e115a5SMichael Buesch 
5338576f815SRafał Miłecki extern void ssb_commit_settings(struct ssb_bus *bus);
53461e115a5SMichael Buesch 
53561e115a5SMichael Buesch /* Various helper functions */
53661e115a5SMichael Buesch extern u32 ssb_admatch_base(u32 adm);
53761e115a5SMichael Buesch extern u32 ssb_admatch_size(u32 adm);
53861e115a5SMichael Buesch 
539aab547ceSMichael Buesch /* PCI device mapping and fixup routines.
540aab547ceSMichael Buesch  * Called from the architecture pcibios init code.
541aab547ceSMichael Buesch  * These are only available on SSB_EMBEDDED configurations. */
542aab547ceSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED
543aab547ceSMichael Buesch int ssb_pcibios_plat_dev_init(struct pci_dev *dev);
544aab547ceSMichael Buesch int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
545aab547ceSMichael Buesch #endif /* CONFIG_SSB_EMBEDDED */
54661e115a5SMichael Buesch 
54761e115a5SMichael Buesch #endif /* LINUX_SSB_H_ */
548