xref: /linux/include/linux/ssb/ssb.h (revision edd8d90b624e97105d26615d1655da22a3605fff)
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 
19b0f70292SRafał Miłecki struct ssb_sprom_core_pwr_info {
20b0f70292SRafał Miłecki 	u8 itssi_2g, itssi_5g;
21b0f70292SRafał Miłecki 	u8 maxpwr_2g, maxpwr_5gl, maxpwr_5g, maxpwr_5gh;
22b0f70292SRafał Miłecki 	u16 pa_2g[3], pa_5gl[3], pa_5g[3], pa_5gh[3];
23b0f70292SRafał Miłecki };
24b0f70292SRafał Miłecki 
2561e115a5SMichael Buesch struct ssb_sprom {
2661e115a5SMichael Buesch 	u8 revision;
27ac82fab4SLarry Finger 	u8 il0mac[6];		/* MAC address for 802.11b/g */
28ac82fab4SLarry Finger 	u8 et0mac[6];		/* MAC address for Ethernet */
29ac82fab4SLarry Finger 	u8 et1mac[6];		/* MAC address for 802.11a */
30ac82fab4SLarry Finger 	u8 et0phyaddr;		/* MII address for enet0 */
31ac82fab4SLarry Finger 	u8 et1phyaddr;		/* MII address for enet1 */
32e861b98dSMichael Buesch 	u8 et0mdcport;		/* MDIO for enet0 */
33e861b98dSMichael Buesch 	u8 et1mdcport;		/* MDIO for enet1 */
34e2d646ceSRafał Miłecki 	u16 board_rev;		/* Board revision number from SPROM. */
35ac82fab4SLarry Finger 	u8 country_code;	/* Country Code */
36*edd8d90bSHauke Mehrtens 	u8 leddc_on_time;	/* LED Powersave Duty Cycle On Count */
37*edd8d90bSHauke Mehrtens 	u8 leddc_off_time;	/* LED Powersave Duty Cycle Off Count */
38f679056bSGábor Stefanik 	u8 ant_available_a;	/* 2GHz antenna available bits (up to 4) */
39f679056bSGábor Stefanik 	u8 ant_available_bg;	/* 5GHz antenna available bits (up to 4) */
40ac82fab4SLarry Finger 	u16 pa0b0;
41ac82fab4SLarry Finger 	u16 pa0b1;
42ac82fab4SLarry Finger 	u16 pa0b2;
43ac82fab4SLarry Finger 	u16 pa1b0;
44ac82fab4SLarry Finger 	u16 pa1b1;
45ac82fab4SLarry Finger 	u16 pa1b2;
46f679056bSGábor Stefanik 	u16 pa1lob0;
47f679056bSGábor Stefanik 	u16 pa1lob1;
48f679056bSGábor Stefanik 	u16 pa1lob2;
49f679056bSGábor Stefanik 	u16 pa1hib0;
50f679056bSGábor Stefanik 	u16 pa1hib1;
51f679056bSGábor Stefanik 	u16 pa1hib2;
52ac82fab4SLarry Finger 	u8 gpio0;		/* GPIO pin 0 */
53ac82fab4SLarry Finger 	u8 gpio1;		/* GPIO pin 1 */
54ac82fab4SLarry Finger 	u8 gpio2;		/* GPIO pin 2 */
55ac82fab4SLarry Finger 	u8 gpio3;		/* GPIO pin 3 */
56*edd8d90bSHauke Mehrtens 	u8 maxpwr_bg;		/* 2.4GHz Amplifier Max Power (in dBm Q5.2) */
57*edd8d90bSHauke Mehrtens 	u8 maxpwr_al;		/* 5.2GHz Amplifier Max Power (in dBm Q5.2) */
58*edd8d90bSHauke Mehrtens 	u8 maxpwr_a;		/* 5.3GHz Amplifier Max Power (in dBm Q5.2) */
59*edd8d90bSHauke Mehrtens 	u8 maxpwr_ah;		/* 5.8GHz Amplifier Max Power (in dBm Q5.2) */
60ac82fab4SLarry Finger 	u8 itssi_a;		/* Idle TSSI Target for A-PHY */
61ac82fab4SLarry Finger 	u8 itssi_bg;		/* Idle TSSI Target for B/G-PHY */
62f679056bSGábor Stefanik 	u8 tri2g;		/* 2.4GHz TX isolation */
63f679056bSGábor Stefanik 	u8 tri5gl;		/* 5.2GHz TX isolation */
64f679056bSGábor Stefanik 	u8 tri5g;		/* 5.3GHz TX isolation */
65f679056bSGábor Stefanik 	u8 tri5gh;		/* 5.8GHz TX isolation */
66172c69a4SRafał Miłecki 	u8 txpid2g[4];		/* 2GHz TX power index */
67172c69a4SRafał Miłecki 	u8 txpid5gl[4];		/* 4.9 - 5.1GHz TX power index */
68172c69a4SRafał Miłecki 	u8 txpid5g[4];		/* 5.1 - 5.5GHz TX power index */
69172c69a4SRafał Miłecki 	u8 txpid5gh[4];		/* 5.5 - ...GHz TX power index */
70*edd8d90bSHauke Mehrtens 	s8 rxpo2g;		/* 2GHz RX power offset */
71*edd8d90bSHauke Mehrtens 	s8 rxpo5g;		/* 5GHz RX power offset */
72f679056bSGábor Stefanik 	u8 rssisav2g;		/* 2GHz RSSI params */
73f679056bSGábor Stefanik 	u8 rssismc2g;
74f679056bSGábor Stefanik 	u8 rssismf2g;
75f679056bSGábor Stefanik 	u8 bxa2g;		/* 2GHz BX arch */
76f679056bSGábor Stefanik 	u8 rssisav5g;		/* 5GHz RSSI params */
77f679056bSGábor Stefanik 	u8 rssismc5g;
78f679056bSGábor Stefanik 	u8 rssismf5g;
79f679056bSGábor Stefanik 	u8 bxa5g;		/* 5GHz BX arch */
80f679056bSGábor Stefanik 	u16 cck2gpo;		/* CCK power offset */
81f679056bSGábor Stefanik 	u32 ofdm2gpo;		/* 2.4GHz OFDM power offset */
82f679056bSGábor Stefanik 	u32 ofdm5glpo;		/* 5.2GHz OFDM power offset */
83f679056bSGábor Stefanik 	u32 ofdm5gpo;		/* 5.3GHz OFDM power offset */
84f679056bSGábor Stefanik 	u32 ofdm5ghpo;		/* 5.8GHz OFDM power offset */
85f679056bSGábor Stefanik 	u16 boardflags_lo;	/* Board flags (bits 0-15) */
86f679056bSGábor Stefanik 	u16 boardflags_hi;	/* Board flags (bits 16-31) */
87f679056bSGábor Stefanik 	u16 boardflags2_lo;	/* Board flags (bits 32-47) */
88f679056bSGábor Stefanik 	u16 boardflags2_hi;	/* Board flags (bits 48-63) */
89f679056bSGábor Stefanik 	/* TODO store board flags in a single u64 */
90e861b98dSMichael Buesch 
91b0f70292SRafał Miłecki 	struct ssb_sprom_core_pwr_info core_pwr_info[4];
92b0f70292SRafał Miłecki 
93e861b98dSMichael Buesch 	/* Antenna gain values for up to 4 antennas
94e861b98dSMichael Buesch 	 * on each band. Values in dBm/4 (Q5.2). Negative gain means the
95e861b98dSMichael Buesch 	 * loss in the connectors is bigger than the gain. */
96e861b98dSMichael Buesch 	struct {
97e861b98dSMichael Buesch 		struct {
98e861b98dSMichael Buesch 			s8 a0, a1, a2, a3;
99e861b98dSMichael Buesch 		} ghz24;	/* 2.4GHz band */
100e861b98dSMichael Buesch 		struct {
101e861b98dSMichael Buesch 			s8 a0, a1, a2, a3;
102e861b98dSMichael Buesch 		} ghz5;		/* 5GHz band */
103e861b98dSMichael Buesch 	} antenna_gain;
104ac82fab4SLarry Finger 
1058a5ac6ecSRafał Miłecki 	struct {
1068a5ac6ecSRafał Miłecki 		struct {
1078a5ac6ecSRafał Miłecki 			u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
1088a5ac6ecSRafał Miłecki 		} ghz2;
1098a5ac6ecSRafał Miłecki 		struct {
1108a5ac6ecSRafał Miłecki 			u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
1118a5ac6ecSRafał Miłecki 		} ghz5;
1128a5ac6ecSRafał Miłecki 	} fem;
1138a5ac6ecSRafał Miłecki 
114f679056bSGábor Stefanik 	/* TODO - add any parameters needed from rev 2, 3, 4, 5 or 8 SPROMs */
11561e115a5SMichael Buesch };
11661e115a5SMichael Buesch 
11761e115a5SMichael Buesch /* Information about the PCB the circuitry is soldered on. */
11861e115a5SMichael Buesch struct ssb_boardinfo {
11961e115a5SMichael Buesch 	u16 vendor;
12061e115a5SMichael Buesch 	u16 type;
121304e21bbSSergei Shtylyov 	u8  rev;
12261e115a5SMichael Buesch };
12361e115a5SMichael Buesch 
12461e115a5SMichael Buesch 
12561e115a5SMichael Buesch struct ssb_device;
12661e115a5SMichael Buesch /* Lowlevel read/write operations on the device MMIO.
12761e115a5SMichael Buesch  * Internal, don't use that outside of ssb. */
12861e115a5SMichael Buesch struct ssb_bus_ops {
129ffc7689dSMichael Buesch 	u8 (*read8)(struct ssb_device *dev, u16 offset);
13061e115a5SMichael Buesch 	u16 (*read16)(struct ssb_device *dev, u16 offset);
13161e115a5SMichael Buesch 	u32 (*read32)(struct ssb_device *dev, u16 offset);
132ffc7689dSMichael Buesch 	void (*write8)(struct ssb_device *dev, u16 offset, u8 value);
13361e115a5SMichael Buesch 	void (*write16)(struct ssb_device *dev, u16 offset, u16 value);
13461e115a5SMichael Buesch 	void (*write32)(struct ssb_device *dev, u16 offset, u32 value);
135d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO
136d625a29bSMichael Buesch 	void (*block_read)(struct ssb_device *dev, void *buffer,
137d625a29bSMichael Buesch 			   size_t count, u16 offset, u8 reg_width);
138d625a29bSMichael Buesch 	void (*block_write)(struct ssb_device *dev, const void *buffer,
139d625a29bSMichael Buesch 			    size_t count, u16 offset, u8 reg_width);
140d625a29bSMichael Buesch #endif
14161e115a5SMichael Buesch };
14261e115a5SMichael Buesch 
14361e115a5SMichael Buesch 
14461e115a5SMichael Buesch /* Core-ID values. */
14561e115a5SMichael Buesch #define SSB_DEV_CHIPCOMMON	0x800
14661e115a5SMichael Buesch #define SSB_DEV_ILINE20		0x801
14761e115a5SMichael Buesch #define SSB_DEV_SDRAM		0x803
14861e115a5SMichael Buesch #define SSB_DEV_PCI		0x804
14961e115a5SMichael Buesch #define SSB_DEV_MIPS		0x805
15061e115a5SMichael Buesch #define SSB_DEV_ETHERNET	0x806
15161e115a5SMichael Buesch #define SSB_DEV_V90		0x807
15261e115a5SMichael Buesch #define SSB_DEV_USB11_HOSTDEV	0x808
15361e115a5SMichael Buesch #define SSB_DEV_ADSL		0x809
15461e115a5SMichael Buesch #define SSB_DEV_ILINE100	0x80A
15561e115a5SMichael Buesch #define SSB_DEV_IPSEC		0x80B
15661e115a5SMichael Buesch #define SSB_DEV_PCMCIA		0x80D
15761e115a5SMichael Buesch #define SSB_DEV_INTERNAL_MEM	0x80E
15861e115a5SMichael Buesch #define SSB_DEV_MEMC_SDRAM	0x80F
15961e115a5SMichael Buesch #define SSB_DEV_EXTIF		0x811
16061e115a5SMichael Buesch #define SSB_DEV_80211		0x812
16161e115a5SMichael Buesch #define SSB_DEV_MIPS_3302	0x816
16261e115a5SMichael Buesch #define SSB_DEV_USB11_HOST	0x817
16361e115a5SMichael Buesch #define SSB_DEV_USB11_DEV	0x818
16461e115a5SMichael Buesch #define SSB_DEV_USB20_HOST	0x819
16561e115a5SMichael Buesch #define SSB_DEV_USB20_DEV	0x81A
16661e115a5SMichael Buesch #define SSB_DEV_SDIO_HOST	0x81B
16761e115a5SMichael Buesch #define SSB_DEV_ROBOSWITCH	0x81C
16861e115a5SMichael Buesch #define SSB_DEV_PARA_ATA	0x81D
16961e115a5SMichael Buesch #define SSB_DEV_SATA_XORDMA	0x81E
17061e115a5SMichael Buesch #define SSB_DEV_ETHERNET_GBIT	0x81F
17161e115a5SMichael Buesch #define SSB_DEV_PCIE		0x820
17261e115a5SMichael Buesch #define SSB_DEV_MIMO_PHY	0x821
17361e115a5SMichael Buesch #define SSB_DEV_SRAM_CTRLR	0x822
17461e115a5SMichael Buesch #define SSB_DEV_MINI_MACPHY	0x823
17561e115a5SMichael Buesch #define SSB_DEV_ARM_1176	0x824
17661e115a5SMichael Buesch #define SSB_DEV_ARM_7TDMI	0x825
17761e115a5SMichael Buesch 
17861e115a5SMichael Buesch /* Vendor-ID values */
17961e115a5SMichael Buesch #define SSB_VENDOR_BROADCOM	0x4243
18061e115a5SMichael Buesch 
18161e115a5SMichael Buesch /* Some kernel subsystems poke with dev->drvdata, so we must use the
18261e115a5SMichael Buesch  * following ugly workaround to get from struct device to struct ssb_device */
18361e115a5SMichael Buesch struct __ssb_dev_wrapper {
18461e115a5SMichael Buesch 	struct device dev;
18561e115a5SMichael Buesch 	struct ssb_device *sdev;
18661e115a5SMichael Buesch };
18761e115a5SMichael Buesch 
18861e115a5SMichael Buesch struct ssb_device {
18961e115a5SMichael Buesch 	/* Having a copy of the ops pointer in each dev struct
19061e115a5SMichael Buesch 	 * is an optimization. */
19161e115a5SMichael Buesch 	const struct ssb_bus_ops *ops;
19261e115a5SMichael Buesch 
19314f92952SFUJITA Tomonori 	struct device *dev, *dma_dev;
1944ac58469SMichael Buesch 
19561e115a5SMichael Buesch 	struct ssb_bus *bus;
19661e115a5SMichael Buesch 	struct ssb_device_id id;
19761e115a5SMichael Buesch 
19861e115a5SMichael Buesch 	u8 core_index;
19961e115a5SMichael Buesch 	unsigned int irq;
20061e115a5SMichael Buesch 
20161e115a5SMichael Buesch 	/* Internal-only stuff follows. */
20261e115a5SMichael Buesch 	void *drvdata;		/* Per-device data */
20361e115a5SMichael Buesch 	void *devtypedata;	/* Per-devicetype (eg 802.11) data */
20461e115a5SMichael Buesch };
20561e115a5SMichael Buesch 
20661e115a5SMichael Buesch /* Go from struct device to struct ssb_device. */
20761e115a5SMichael Buesch static inline
20861e115a5SMichael Buesch struct ssb_device * dev_to_ssb_dev(struct device *dev)
20961e115a5SMichael Buesch {
21061e115a5SMichael Buesch 	struct __ssb_dev_wrapper *wrap;
21161e115a5SMichael Buesch 	wrap = container_of(dev, struct __ssb_dev_wrapper, dev);
21261e115a5SMichael Buesch 	return wrap->sdev;
21361e115a5SMichael Buesch }
21461e115a5SMichael Buesch 
21561e115a5SMichael Buesch /* Device specific user data */
21661e115a5SMichael Buesch static inline
21761e115a5SMichael Buesch void ssb_set_drvdata(struct ssb_device *dev, void *data)
21861e115a5SMichael Buesch {
21961e115a5SMichael Buesch 	dev->drvdata = data;
22061e115a5SMichael Buesch }
22161e115a5SMichael Buesch static inline
22261e115a5SMichael Buesch void * ssb_get_drvdata(struct ssb_device *dev)
22361e115a5SMichael Buesch {
22461e115a5SMichael Buesch 	return dev->drvdata;
22561e115a5SMichael Buesch }
22661e115a5SMichael Buesch 
22761e115a5SMichael Buesch /* Devicetype specific user data. This is per device-type (not per device) */
22861e115a5SMichael Buesch void ssb_set_devtypedata(struct ssb_device *dev, void *data);
22961e115a5SMichael Buesch static inline
23061e115a5SMichael Buesch void * ssb_get_devtypedata(struct ssb_device *dev)
23161e115a5SMichael Buesch {
23261e115a5SMichael Buesch 	return dev->devtypedata;
23361e115a5SMichael Buesch }
23461e115a5SMichael Buesch 
23561e115a5SMichael Buesch 
23661e115a5SMichael Buesch struct ssb_driver {
23761e115a5SMichael Buesch 	const char *name;
23861e115a5SMichael Buesch 	const struct ssb_device_id *id_table;
23961e115a5SMichael Buesch 
24061e115a5SMichael Buesch 	int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id);
24161e115a5SMichael Buesch 	void (*remove)(struct ssb_device *dev);
24261e115a5SMichael Buesch 	int (*suspend)(struct ssb_device *dev, pm_message_t state);
24361e115a5SMichael Buesch 	int (*resume)(struct ssb_device *dev);
24461e115a5SMichael Buesch 	void (*shutdown)(struct ssb_device *dev);
24561e115a5SMichael Buesch 
24661e115a5SMichael Buesch 	struct device_driver drv;
24761e115a5SMichael Buesch };
24861e115a5SMichael Buesch #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv)
24961e115a5SMichael Buesch 
25061e115a5SMichael Buesch extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
251eb5589a8SPaul Gortmaker #define ssb_driver_register(drv) \
252eb5589a8SPaul Gortmaker 	__ssb_driver_register(drv, THIS_MODULE)
253eb5589a8SPaul Gortmaker 
25461e115a5SMichael Buesch extern void ssb_driver_unregister(struct ssb_driver *drv);
25561e115a5SMichael Buesch 
25661e115a5SMichael Buesch 
25761e115a5SMichael Buesch 
25861e115a5SMichael Buesch 
25961e115a5SMichael Buesch enum ssb_bustype {
26061e115a5SMichael Buesch 	SSB_BUSTYPE_SSB,	/* This SSB bus is the system bus */
26161e115a5SMichael Buesch 	SSB_BUSTYPE_PCI,	/* SSB is connected to PCI bus */
26261e115a5SMichael Buesch 	SSB_BUSTYPE_PCMCIA,	/* SSB is connected to PCMCIA bus */
26324ea602eSAlbert Herranz 	SSB_BUSTYPE_SDIO,	/* SSB is connected to SDIO bus */
26461e115a5SMichael Buesch };
26561e115a5SMichael Buesch 
26661e115a5SMichael Buesch /* board_vendor */
26761e115a5SMichael Buesch #define SSB_BOARDVENDOR_BCM	0x14E4	/* Broadcom */
26861e115a5SMichael Buesch #define SSB_BOARDVENDOR_DELL	0x1028	/* Dell */
26961e115a5SMichael Buesch #define SSB_BOARDVENDOR_HP	0x0E11	/* HP */
27061e115a5SMichael Buesch /* board_type */
27161e115a5SMichael Buesch #define SSB_BOARD_BCM94306MP	0x0418
27261e115a5SMichael Buesch #define SSB_BOARD_BCM4309G	0x0421
27361e115a5SMichael Buesch #define SSB_BOARD_BCM4306CB	0x0417
27461e115a5SMichael Buesch #define SSB_BOARD_BCM4309MP	0x040C
27561e115a5SMichael Buesch #define SSB_BOARD_MP4318	0x044A
27661e115a5SMichael Buesch #define SSB_BOARD_BU4306	0x0416
27761e115a5SMichael Buesch #define SSB_BOARD_BU4309	0x040A
27861e115a5SMichael Buesch /* chip_package */
27961e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712S	1	/* Small 200pin 4712 */
28061e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712M	2	/* Medium 225pin 4712 */
28161e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712L	0	/* Large 340pin 4712 */
28261e115a5SMichael Buesch 
28361e115a5SMichael Buesch #include <linux/ssb/ssb_driver_chipcommon.h>
28461e115a5SMichael Buesch #include <linux/ssb/ssb_driver_mips.h>
28561e115a5SMichael Buesch #include <linux/ssb/ssb_driver_extif.h>
28661e115a5SMichael Buesch #include <linux/ssb/ssb_driver_pci.h>
28761e115a5SMichael Buesch 
28861e115a5SMichael Buesch struct ssb_bus {
28961e115a5SMichael Buesch 	/* The MMIO area. */
29061e115a5SMichael Buesch 	void __iomem *mmio;
29161e115a5SMichael Buesch 
29261e115a5SMichael Buesch 	const struct ssb_bus_ops *ops;
29361e115a5SMichael Buesch 
2948b45499cSMichael Buesch 	/* The core currently mapped into the MMIO window.
2958b45499cSMichael Buesch 	 * Not valid on all host-buses. So don't use outside of SSB. */
29661e115a5SMichael Buesch 	struct ssb_device *mapped_device;
29724ea602eSAlbert Herranz 	union {
29861e115a5SMichael Buesch 		/* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */
29961e115a5SMichael Buesch 		u8 mapped_pcmcia_seg;
30024ea602eSAlbert Herranz 		/* Current SSB base address window for SDIO. */
30124ea602eSAlbert Herranz 		u32 sdio_sbaddr;
30224ea602eSAlbert Herranz 	};
303993e1c78SMichael Buesch 	/* Lock for core and segment switching.
304993e1c78SMichael Buesch 	 * On PCMCIA-host busses this is used to protect the whole MMIO access. */
30561e115a5SMichael Buesch 	spinlock_t bar_lock;
30661e115a5SMichael Buesch 
3078b45499cSMichael Buesch 	/* The host-bus this backplane is running on. */
30861e115a5SMichael Buesch 	enum ssb_bustype bustype;
3098b45499cSMichael Buesch 	/* Pointers to the host-bus. Check bustype before using any of these pointers. */
3108b45499cSMichael Buesch 	union {
31161e115a5SMichael Buesch 		/* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */
31261e115a5SMichael Buesch 		struct pci_dev *host_pci;
31361e115a5SMichael Buesch 		/* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
31461e115a5SMichael Buesch 		struct pcmcia_device *host_pcmcia;
31524ea602eSAlbert Herranz 		/* Pointer to the SDIO device (only if bustype == SSB_BUSTYPE_SDIO). */
31624ea602eSAlbert Herranz 		struct sdio_func *host_sdio;
3178b45499cSMichael Buesch 	};
31824ea602eSAlbert Herranz 
31924ea602eSAlbert Herranz 	/* See enum ssb_quirks */
32024ea602eSAlbert Herranz 	unsigned int quirks;
32161e115a5SMichael Buesch 
322e7ec2e32SMichael Buesch #ifdef CONFIG_SSB_SPROM
32361e115a5SMichael Buesch 	/* Mutex to protect the SPROM writing. */
324e7ec2e32SMichael Buesch 	struct mutex sprom_mutex;
32561e115a5SMichael Buesch #endif
32661e115a5SMichael Buesch 
32761e115a5SMichael Buesch 	/* ID information about the Chip. */
32861e115a5SMichael Buesch 	u16 chip_id;
329ce57d9e6SRafał Miłecki 	u8 chip_rev;
330ea2db495SRafał Miłecki 	u16 sprom_offset;
331c272ef44SLarry Finger 	u16 sprom_size;		/* number of words in sprom */
33261e115a5SMichael Buesch 	u8 chip_package;
33361e115a5SMichael Buesch 
33461e115a5SMichael Buesch 	/* List of devices (cores) on the backplane. */
33561e115a5SMichael Buesch 	struct ssb_device devices[SSB_MAX_NR_CORES];
33661e115a5SMichael Buesch 	u8 nr_devices;
33761e115a5SMichael Buesch 
33861e115a5SMichael Buesch 	/* Software ID number for this bus. */
33961e115a5SMichael Buesch 	unsigned int busnumber;
34061e115a5SMichael Buesch 
34161e115a5SMichael Buesch 	/* The ChipCommon device (if available). */
34261e115a5SMichael Buesch 	struct ssb_chipcommon chipco;
34361e115a5SMichael Buesch 	/* The PCI-core device (if available). */
34461e115a5SMichael Buesch 	struct ssb_pcicore pcicore;
34561e115a5SMichael Buesch 	/* The MIPS-core device (if available). */
34661e115a5SMichael Buesch 	struct ssb_mipscore mipscore;
34761e115a5SMichael Buesch 	/* The EXTif-core device (if available). */
34861e115a5SMichael Buesch 	struct ssb_extif extif;
34961e115a5SMichael Buesch 
35061e115a5SMichael Buesch 	/* The following structure elements are not available in early
35161e115a5SMichael Buesch 	 * SSB initialization. Though, they are available for regular
35261e115a5SMichael Buesch 	 * registered drivers at any stage. So be careful when
35361e115a5SMichael Buesch 	 * using them in the ssb core code. */
35461e115a5SMichael Buesch 
35561e115a5SMichael Buesch 	/* ID information about the PCB. */
35661e115a5SMichael Buesch 	struct ssb_boardinfo boardinfo;
35761e115a5SMichael Buesch 	/* Contents of the SPROM. */
35861e115a5SMichael Buesch 	struct ssb_sprom sprom;
3597cb44615SMichael Buesch 	/* If the board has a cardbus slot, this is set to true. */
3607cb44615SMichael Buesch 	bool has_cardbus_slot;
36161e115a5SMichael Buesch 
36253521d8cSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED
36353521d8cSMichael Buesch 	/* Lock for GPIO register access. */
36453521d8cSMichael Buesch 	spinlock_t gpio_lock;
36553521d8cSMichael Buesch #endif /* EMBEDDED */
36653521d8cSMichael Buesch 
36761e115a5SMichael Buesch 	/* Internal-only stuff follows. Do not touch. */
36861e115a5SMichael Buesch 	struct list_head list;
36961e115a5SMichael Buesch #ifdef CONFIG_SSB_DEBUG
37061e115a5SMichael Buesch 	/* Is the bus already powered up? */
37161e115a5SMichael Buesch 	bool powered_up;
37261e115a5SMichael Buesch 	int power_warn_count;
37361e115a5SMichael Buesch #endif /* DEBUG */
37461e115a5SMichael Buesch };
37561e115a5SMichael Buesch 
37624ea602eSAlbert Herranz enum ssb_quirks {
37724ea602eSAlbert Herranz 	/* SDIO connected card requires performing a read after writing a 32-bit value */
37824ea602eSAlbert Herranz 	SSB_QUIRK_SDIO_READ_AFTER_WRITE32	= (1 << 0),
37924ea602eSAlbert Herranz };
38024ea602eSAlbert Herranz 
38161e115a5SMichael Buesch /* The initialization-invariants. */
38261e115a5SMichael Buesch struct ssb_init_invariants {
3837cb44615SMichael Buesch 	/* Versioning information about the PCB. */
38461e115a5SMichael Buesch 	struct ssb_boardinfo boardinfo;
3857cb44615SMichael Buesch 	/* The SPROM information. That's either stored in an
3867cb44615SMichael Buesch 	 * EEPROM or NVRAM on the board. */
38761e115a5SMichael Buesch 	struct ssb_sprom sprom;
3887cb44615SMichael Buesch 	/* If the board has a cardbus slot, this is set to true. */
3897cb44615SMichael Buesch 	bool has_cardbus_slot;
39061e115a5SMichael Buesch };
39161e115a5SMichael Buesch /* Type of function to fetch the invariants. */
39261e115a5SMichael Buesch typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
39361e115a5SMichael Buesch 				     struct ssb_init_invariants *iv);
39461e115a5SMichael Buesch 
39561e115a5SMichael Buesch /* Register a SSB system bus. get_invariants() is called after the
39661e115a5SMichael Buesch  * basic system devices are initialized.
39761e115a5SMichael Buesch  * The invariants are usually fetched from some NVRAM.
39861e115a5SMichael Buesch  * Put the invariants into the struct pointed to by iv. */
39961e115a5SMichael Buesch extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
40061e115a5SMichael Buesch 				   unsigned long baseaddr,
40161e115a5SMichael Buesch 				   ssb_invariants_func_t get_invariants);
40261e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST
40361e115a5SMichael Buesch extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
40461e115a5SMichael Buesch 				   struct pci_dev *host_pci);
40561e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */
40661e115a5SMichael Buesch #ifdef CONFIG_SSB_PCMCIAHOST
40761e115a5SMichael Buesch extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
40861e115a5SMichael Buesch 				      struct pcmcia_device *pcmcia_dev,
40961e115a5SMichael Buesch 				      unsigned long baseaddr);
41061e115a5SMichael Buesch #endif /* CONFIG_SSB_PCMCIAHOST */
41124ea602eSAlbert Herranz #ifdef CONFIG_SSB_SDIOHOST
41224ea602eSAlbert Herranz extern int ssb_bus_sdiobus_register(struct ssb_bus *bus,
41324ea602eSAlbert Herranz 				    struct sdio_func *sdio_func,
41424ea602eSAlbert Herranz 				    unsigned int quirks);
41524ea602eSAlbert Herranz #endif /* CONFIG_SSB_SDIOHOST */
41624ea602eSAlbert Herranz 
41761e115a5SMichael Buesch 
41861e115a5SMichael Buesch extern void ssb_bus_unregister(struct ssb_bus *bus);
41961e115a5SMichael Buesch 
420d53cdbb9SJohn W. Linville /* Does the device have an SPROM? */
421d53cdbb9SJohn W. Linville extern bool ssb_is_sprom_available(struct ssb_bus *bus);
422d53cdbb9SJohn W. Linville 
423e79c1ba8SMichael Buesch /* Set a fallback SPROM.
424e79c1ba8SMichael Buesch  * See kdoc at the function definition for complete documentation. */
425b3ae52b6SHauke Mehrtens extern int ssb_arch_register_fallback_sprom(
426b3ae52b6SHauke Mehrtens 		int (*sprom_callback)(struct ssb_bus *bus,
427b3ae52b6SHauke Mehrtens 		struct ssb_sprom *out));
428e79c1ba8SMichael Buesch 
4298fe2b65aSMichael Buesch /* Suspend a SSB bus.
4308fe2b65aSMichael Buesch  * Call this from the parent bus suspend routine. */
4318fe2b65aSMichael Buesch extern int ssb_bus_suspend(struct ssb_bus *bus);
4328fe2b65aSMichael Buesch /* Resume a SSB bus.
4338fe2b65aSMichael Buesch  * Call this from the parent bus resume routine. */
4348fe2b65aSMichael Buesch extern int ssb_bus_resume(struct ssb_bus *bus);
4358fe2b65aSMichael Buesch 
43661e115a5SMichael Buesch extern u32 ssb_clockspeed(struct ssb_bus *bus);
43761e115a5SMichael Buesch 
43861e115a5SMichael Buesch /* Is the device enabled in hardware? */
43961e115a5SMichael Buesch int ssb_device_is_enabled(struct ssb_device *dev);
44061e115a5SMichael Buesch /* Enable a device and pass device-specific SSB_TMSLOW flags.
44161e115a5SMichael Buesch  * If no device-specific flags are available, use 0. */
44261e115a5SMichael Buesch void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
44361e115a5SMichael Buesch /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
44461e115a5SMichael Buesch void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
44561e115a5SMichael Buesch 
44661e115a5SMichael Buesch 
44761e115a5SMichael Buesch /* Device MMIO register read/write functions. */
448ffc7689dSMichael Buesch static inline u8 ssb_read8(struct ssb_device *dev, u16 offset)
449ffc7689dSMichael Buesch {
450ffc7689dSMichael Buesch 	return dev->ops->read8(dev, offset);
451ffc7689dSMichael Buesch }
45261e115a5SMichael Buesch static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
45361e115a5SMichael Buesch {
45461e115a5SMichael Buesch 	return dev->ops->read16(dev, offset);
45561e115a5SMichael Buesch }
45661e115a5SMichael Buesch static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
45761e115a5SMichael Buesch {
45861e115a5SMichael Buesch 	return dev->ops->read32(dev, offset);
45961e115a5SMichael Buesch }
460ffc7689dSMichael Buesch static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value)
461ffc7689dSMichael Buesch {
462ffc7689dSMichael Buesch 	dev->ops->write8(dev, offset, value);
463ffc7689dSMichael Buesch }
46461e115a5SMichael Buesch static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
46561e115a5SMichael Buesch {
46661e115a5SMichael Buesch 	dev->ops->write16(dev, offset, value);
46761e115a5SMichael Buesch }
46861e115a5SMichael Buesch static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
46961e115a5SMichael Buesch {
47061e115a5SMichael Buesch 	dev->ops->write32(dev, offset, value);
47161e115a5SMichael Buesch }
472d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO
473d625a29bSMichael Buesch static inline void ssb_block_read(struct ssb_device *dev, void *buffer,
474d625a29bSMichael Buesch 				  size_t count, u16 offset, u8 reg_width)
475d625a29bSMichael Buesch {
476d625a29bSMichael Buesch 	dev->ops->block_read(dev, buffer, count, offset, reg_width);
477d625a29bSMichael Buesch }
478d625a29bSMichael Buesch 
479d625a29bSMichael Buesch static inline void ssb_block_write(struct ssb_device *dev, const void *buffer,
480d625a29bSMichael Buesch 				   size_t count, u16 offset, u8 reg_width)
481d625a29bSMichael Buesch {
482d625a29bSMichael Buesch 	dev->ops->block_write(dev, buffer, count, offset, reg_width);
483d625a29bSMichael Buesch }
484d625a29bSMichael Buesch #endif /* CONFIG_SSB_BLOCKIO */
48561e115a5SMichael Buesch 
48661e115a5SMichael Buesch 
487f225763aSMichael Buesch /* The SSB DMA API. Use this API for any DMA operation on the device.
488f225763aSMichael Buesch  * This API basically is a wrapper that calls the correct DMA API for
489f225763aSMichael Buesch  * the host device type the SSB device is attached to. */
490f225763aSMichael Buesch 
49161e115a5SMichael Buesch /* Translation (routing) bits that need to be ORed to DMA
49261e115a5SMichael Buesch  * addresses before they are given to a device. */
49361e115a5SMichael Buesch extern u32 ssb_dma_translation(struct ssb_device *dev);
49461e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_MASK	0xC0000000
49561e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_SHIFT	30
49661e115a5SMichael Buesch 
497f225763aSMichael Buesch static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev)
498f225763aSMichael Buesch {
499f225763aSMichael Buesch #ifdef CONFIG_SSB_DEBUG
500f225763aSMichael Buesch 	printk(KERN_ERR "SSB: BUG! Calling DMA API for "
501f225763aSMichael Buesch 	       "unsupported bustype %d\n", dev->bus->bustype);
502f225763aSMichael Buesch #endif /* DEBUG */
503f225763aSMichael Buesch }
504f225763aSMichael Buesch 
50561e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST
50661e115a5SMichael Buesch /* PCI-host wrapper driver */
50761e115a5SMichael Buesch extern int ssb_pcihost_register(struct pci_driver *driver);
50861e115a5SMichael Buesch static inline void ssb_pcihost_unregister(struct pci_driver *driver)
50961e115a5SMichael Buesch {
51061e115a5SMichael Buesch 	pci_unregister_driver(driver);
51161e115a5SMichael Buesch }
512961d57c8SMiguel Botón 
513961d57c8SMiguel Botón static inline
514961d57c8SMiguel Botón void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
515961d57c8SMiguel Botón {
516961d57c8SMiguel Botón 	if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
517961d57c8SMiguel Botón 		pci_set_power_state(sdev->bus->host_pci, state);
518961d57c8SMiguel Botón }
519532031d7SAndrew Morton #else
520532031d7SAndrew Morton static inline void ssb_pcihost_unregister(struct pci_driver *driver)
521532031d7SAndrew Morton {
522532031d7SAndrew Morton }
523532031d7SAndrew Morton 
524532031d7SAndrew Morton static inline
525532031d7SAndrew Morton void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
526532031d7SAndrew Morton {
527532031d7SAndrew Morton }
52861e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */
52961e115a5SMichael Buesch 
53061e115a5SMichael Buesch 
53161e115a5SMichael Buesch /* If a driver is shutdown or suspended, call this to signal
53261e115a5SMichael Buesch  * that the bus may be completely powered down. SSB will decide,
53361e115a5SMichael Buesch  * if it's really time to power down the bus, based on if there
53461e115a5SMichael Buesch  * are other devices that want to run. */
53561e115a5SMichael Buesch extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
53661e115a5SMichael Buesch /* Before initializing and enabling a device, call this to power-up the bus.
53761e115a5SMichael Buesch  * If you want to allow use of dynamic-power-control, pass the flag.
53861e115a5SMichael Buesch  * Otherwise static always-on powercontrol will be used. */
53961e115a5SMichael Buesch extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
54061e115a5SMichael Buesch 
5418576f815SRafał Miłecki extern void ssb_commit_settings(struct ssb_bus *bus);
54261e115a5SMichael Buesch 
54361e115a5SMichael Buesch /* Various helper functions */
54461e115a5SMichael Buesch extern u32 ssb_admatch_base(u32 adm);
54561e115a5SMichael Buesch extern u32 ssb_admatch_size(u32 adm);
54661e115a5SMichael Buesch 
547aab547ceSMichael Buesch /* PCI device mapping and fixup routines.
548aab547ceSMichael Buesch  * Called from the architecture pcibios init code.
549aab547ceSMichael Buesch  * These are only available on SSB_EMBEDDED configurations. */
550aab547ceSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED
551aab547ceSMichael Buesch int ssb_pcibios_plat_dev_init(struct pci_dev *dev);
552aab547ceSMichael Buesch int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
553aab547ceSMichael Buesch #endif /* CONFIG_SSB_EMBEDDED */
55461e115a5SMichael Buesch 
55561e115a5SMichael Buesch #endif /* LINUX_SSB_H_ */
556