xref: /linux/include/linux/ssb/ssb.h (revision 3b64e6f9050ff87a746c8e07dc04d97c7f26c5e2)
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;
22*3b64e6f9SHauke Mehrtens 	u16 pa_2g[4], pa_5gl[4], pa_5g[4], pa_5gh[4];
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 */
36edd8d90bSHauke Mehrtens 	u8 leddc_on_time;	/* LED Powersave Duty Cycle On Count */
37edd8d90bSHauke 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 */
56edd8d90bSHauke Mehrtens 	u8 maxpwr_bg;		/* 2.4GHz Amplifier Max Power (in dBm Q5.2) */
57edd8d90bSHauke Mehrtens 	u8 maxpwr_al;		/* 5.2GHz Amplifier Max Power (in dBm Q5.2) */
58edd8d90bSHauke Mehrtens 	u8 maxpwr_a;		/* 5.3GHz Amplifier Max Power (in dBm Q5.2) */
59edd8d90bSHauke 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 */
70edd8d90bSHauke Mehrtens 	s8 rxpo2g;		/* 2GHz RX power offset */
71edd8d90bSHauke 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 		s8 a0, a1, a2, a3;
98e861b98dSMichael Buesch 	} antenna_gain;
99ac82fab4SLarry Finger 
1008a5ac6ecSRafał Miłecki 	struct {
1018a5ac6ecSRafał Miłecki 		struct {
1028a5ac6ecSRafał Miłecki 			u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
1038a5ac6ecSRafał Miłecki 		} ghz2;
1048a5ac6ecSRafał Miłecki 		struct {
1058a5ac6ecSRafał Miłecki 			u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
1068a5ac6ecSRafał Miłecki 		} ghz5;
1078a5ac6ecSRafał Miłecki 	} fem;
1088a5ac6ecSRafał Miłecki 
109f679056bSGábor Stefanik 	/* TODO - add any parameters needed from rev 2, 3, 4, 5 or 8 SPROMs */
11061e115a5SMichael Buesch };
11161e115a5SMichael Buesch 
11261e115a5SMichael Buesch /* Information about the PCB the circuitry is soldered on. */
11361e115a5SMichael Buesch struct ssb_boardinfo {
11461e115a5SMichael Buesch 	u16 vendor;
11561e115a5SMichael Buesch 	u16 type;
116304e21bbSSergei Shtylyov 	u8  rev;
11761e115a5SMichael Buesch };
11861e115a5SMichael Buesch 
11961e115a5SMichael Buesch 
12061e115a5SMichael Buesch struct ssb_device;
12161e115a5SMichael Buesch /* Lowlevel read/write operations on the device MMIO.
12261e115a5SMichael Buesch  * Internal, don't use that outside of ssb. */
12361e115a5SMichael Buesch struct ssb_bus_ops {
124ffc7689dSMichael Buesch 	u8 (*read8)(struct ssb_device *dev, u16 offset);
12561e115a5SMichael Buesch 	u16 (*read16)(struct ssb_device *dev, u16 offset);
12661e115a5SMichael Buesch 	u32 (*read32)(struct ssb_device *dev, u16 offset);
127ffc7689dSMichael Buesch 	void (*write8)(struct ssb_device *dev, u16 offset, u8 value);
12861e115a5SMichael Buesch 	void (*write16)(struct ssb_device *dev, u16 offset, u16 value);
12961e115a5SMichael Buesch 	void (*write32)(struct ssb_device *dev, u16 offset, u32 value);
130d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO
131d625a29bSMichael Buesch 	void (*block_read)(struct ssb_device *dev, void *buffer,
132d625a29bSMichael Buesch 			   size_t count, u16 offset, u8 reg_width);
133d625a29bSMichael Buesch 	void (*block_write)(struct ssb_device *dev, const void *buffer,
134d625a29bSMichael Buesch 			    size_t count, u16 offset, u8 reg_width);
135d625a29bSMichael Buesch #endif
13661e115a5SMichael Buesch };
13761e115a5SMichael Buesch 
13861e115a5SMichael Buesch 
13961e115a5SMichael Buesch /* Core-ID values. */
14061e115a5SMichael Buesch #define SSB_DEV_CHIPCOMMON	0x800
14161e115a5SMichael Buesch #define SSB_DEV_ILINE20		0x801
14261e115a5SMichael Buesch #define SSB_DEV_SDRAM		0x803
14361e115a5SMichael Buesch #define SSB_DEV_PCI		0x804
14461e115a5SMichael Buesch #define SSB_DEV_MIPS		0x805
14561e115a5SMichael Buesch #define SSB_DEV_ETHERNET	0x806
14661e115a5SMichael Buesch #define SSB_DEV_V90		0x807
14761e115a5SMichael Buesch #define SSB_DEV_USB11_HOSTDEV	0x808
14861e115a5SMichael Buesch #define SSB_DEV_ADSL		0x809
14961e115a5SMichael Buesch #define SSB_DEV_ILINE100	0x80A
15061e115a5SMichael Buesch #define SSB_DEV_IPSEC		0x80B
15161e115a5SMichael Buesch #define SSB_DEV_PCMCIA		0x80D
15261e115a5SMichael Buesch #define SSB_DEV_INTERNAL_MEM	0x80E
15361e115a5SMichael Buesch #define SSB_DEV_MEMC_SDRAM	0x80F
15461e115a5SMichael Buesch #define SSB_DEV_EXTIF		0x811
15561e115a5SMichael Buesch #define SSB_DEV_80211		0x812
15661e115a5SMichael Buesch #define SSB_DEV_MIPS_3302	0x816
15761e115a5SMichael Buesch #define SSB_DEV_USB11_HOST	0x817
15861e115a5SMichael Buesch #define SSB_DEV_USB11_DEV	0x818
15961e115a5SMichael Buesch #define SSB_DEV_USB20_HOST	0x819
16061e115a5SMichael Buesch #define SSB_DEV_USB20_DEV	0x81A
16161e115a5SMichael Buesch #define SSB_DEV_SDIO_HOST	0x81B
16261e115a5SMichael Buesch #define SSB_DEV_ROBOSWITCH	0x81C
16361e115a5SMichael Buesch #define SSB_DEV_PARA_ATA	0x81D
16461e115a5SMichael Buesch #define SSB_DEV_SATA_XORDMA	0x81E
16561e115a5SMichael Buesch #define SSB_DEV_ETHERNET_GBIT	0x81F
16661e115a5SMichael Buesch #define SSB_DEV_PCIE		0x820
16761e115a5SMichael Buesch #define SSB_DEV_MIMO_PHY	0x821
16861e115a5SMichael Buesch #define SSB_DEV_SRAM_CTRLR	0x822
16961e115a5SMichael Buesch #define SSB_DEV_MINI_MACPHY	0x823
17061e115a5SMichael Buesch #define SSB_DEV_ARM_1176	0x824
17161e115a5SMichael Buesch #define SSB_DEV_ARM_7TDMI	0x825
17261e115a5SMichael Buesch 
17361e115a5SMichael Buesch /* Vendor-ID values */
17461e115a5SMichael Buesch #define SSB_VENDOR_BROADCOM	0x4243
17561e115a5SMichael Buesch 
17661e115a5SMichael Buesch /* Some kernel subsystems poke with dev->drvdata, so we must use the
17761e115a5SMichael Buesch  * following ugly workaround to get from struct device to struct ssb_device */
17861e115a5SMichael Buesch struct __ssb_dev_wrapper {
17961e115a5SMichael Buesch 	struct device dev;
18061e115a5SMichael Buesch 	struct ssb_device *sdev;
18161e115a5SMichael Buesch };
18261e115a5SMichael Buesch 
18361e115a5SMichael Buesch struct ssb_device {
18461e115a5SMichael Buesch 	/* Having a copy of the ops pointer in each dev struct
18561e115a5SMichael Buesch 	 * is an optimization. */
18661e115a5SMichael Buesch 	const struct ssb_bus_ops *ops;
18761e115a5SMichael Buesch 
18814f92952SFUJITA Tomonori 	struct device *dev, *dma_dev;
1894ac58469SMichael Buesch 
19061e115a5SMichael Buesch 	struct ssb_bus *bus;
19161e115a5SMichael Buesch 	struct ssb_device_id id;
19261e115a5SMichael Buesch 
19361e115a5SMichael Buesch 	u8 core_index;
19461e115a5SMichael Buesch 	unsigned int irq;
19561e115a5SMichael Buesch 
19661e115a5SMichael Buesch 	/* Internal-only stuff follows. */
19761e115a5SMichael Buesch 	void *drvdata;		/* Per-device data */
19861e115a5SMichael Buesch 	void *devtypedata;	/* Per-devicetype (eg 802.11) data */
19961e115a5SMichael Buesch };
20061e115a5SMichael Buesch 
20161e115a5SMichael Buesch /* Go from struct device to struct ssb_device. */
20261e115a5SMichael Buesch static inline
20361e115a5SMichael Buesch struct ssb_device * dev_to_ssb_dev(struct device *dev)
20461e115a5SMichael Buesch {
20561e115a5SMichael Buesch 	struct __ssb_dev_wrapper *wrap;
20661e115a5SMichael Buesch 	wrap = container_of(dev, struct __ssb_dev_wrapper, dev);
20761e115a5SMichael Buesch 	return wrap->sdev;
20861e115a5SMichael Buesch }
20961e115a5SMichael Buesch 
21061e115a5SMichael Buesch /* Device specific user data */
21161e115a5SMichael Buesch static inline
21261e115a5SMichael Buesch void ssb_set_drvdata(struct ssb_device *dev, void *data)
21361e115a5SMichael Buesch {
21461e115a5SMichael Buesch 	dev->drvdata = data;
21561e115a5SMichael Buesch }
21661e115a5SMichael Buesch static inline
21761e115a5SMichael Buesch void * ssb_get_drvdata(struct ssb_device *dev)
21861e115a5SMichael Buesch {
21961e115a5SMichael Buesch 	return dev->drvdata;
22061e115a5SMichael Buesch }
22161e115a5SMichael Buesch 
22261e115a5SMichael Buesch /* Devicetype specific user data. This is per device-type (not per device) */
22361e115a5SMichael Buesch void ssb_set_devtypedata(struct ssb_device *dev, void *data);
22461e115a5SMichael Buesch static inline
22561e115a5SMichael Buesch void * ssb_get_devtypedata(struct ssb_device *dev)
22661e115a5SMichael Buesch {
22761e115a5SMichael Buesch 	return dev->devtypedata;
22861e115a5SMichael Buesch }
22961e115a5SMichael Buesch 
23061e115a5SMichael Buesch 
23161e115a5SMichael Buesch struct ssb_driver {
23261e115a5SMichael Buesch 	const char *name;
23361e115a5SMichael Buesch 	const struct ssb_device_id *id_table;
23461e115a5SMichael Buesch 
23561e115a5SMichael Buesch 	int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id);
23661e115a5SMichael Buesch 	void (*remove)(struct ssb_device *dev);
23761e115a5SMichael Buesch 	int (*suspend)(struct ssb_device *dev, pm_message_t state);
23861e115a5SMichael Buesch 	int (*resume)(struct ssb_device *dev);
23961e115a5SMichael Buesch 	void (*shutdown)(struct ssb_device *dev);
24061e115a5SMichael Buesch 
24161e115a5SMichael Buesch 	struct device_driver drv;
24261e115a5SMichael Buesch };
24361e115a5SMichael Buesch #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv)
24461e115a5SMichael Buesch 
24561e115a5SMichael Buesch extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
246eb5589a8SPaul Gortmaker #define ssb_driver_register(drv) \
247eb5589a8SPaul Gortmaker 	__ssb_driver_register(drv, THIS_MODULE)
248eb5589a8SPaul Gortmaker 
24961e115a5SMichael Buesch extern void ssb_driver_unregister(struct ssb_driver *drv);
25061e115a5SMichael Buesch 
25161e115a5SMichael Buesch 
25261e115a5SMichael Buesch 
25361e115a5SMichael Buesch 
25461e115a5SMichael Buesch enum ssb_bustype {
25561e115a5SMichael Buesch 	SSB_BUSTYPE_SSB,	/* This SSB bus is the system bus */
25661e115a5SMichael Buesch 	SSB_BUSTYPE_PCI,	/* SSB is connected to PCI bus */
25761e115a5SMichael Buesch 	SSB_BUSTYPE_PCMCIA,	/* SSB is connected to PCMCIA bus */
25824ea602eSAlbert Herranz 	SSB_BUSTYPE_SDIO,	/* SSB is connected to SDIO bus */
25961e115a5SMichael Buesch };
26061e115a5SMichael Buesch 
26161e115a5SMichael Buesch /* board_vendor */
26261e115a5SMichael Buesch #define SSB_BOARDVENDOR_BCM	0x14E4	/* Broadcom */
26361e115a5SMichael Buesch #define SSB_BOARDVENDOR_DELL	0x1028	/* Dell */
26461e115a5SMichael Buesch #define SSB_BOARDVENDOR_HP	0x0E11	/* HP */
26561e115a5SMichael Buesch /* board_type */
26661e115a5SMichael Buesch #define SSB_BOARD_BCM94306MP	0x0418
26761e115a5SMichael Buesch #define SSB_BOARD_BCM4309G	0x0421
26861e115a5SMichael Buesch #define SSB_BOARD_BCM4306CB	0x0417
26961e115a5SMichael Buesch #define SSB_BOARD_BCM4309MP	0x040C
27061e115a5SMichael Buesch #define SSB_BOARD_MP4318	0x044A
27161e115a5SMichael Buesch #define SSB_BOARD_BU4306	0x0416
27261e115a5SMichael Buesch #define SSB_BOARD_BU4309	0x040A
27361e115a5SMichael Buesch /* chip_package */
27461e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712S	1	/* Small 200pin 4712 */
27561e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712M	2	/* Medium 225pin 4712 */
27661e115a5SMichael Buesch #define SSB_CHIPPACK_BCM4712L	0	/* Large 340pin 4712 */
27761e115a5SMichael Buesch 
27861e115a5SMichael Buesch #include <linux/ssb/ssb_driver_chipcommon.h>
27961e115a5SMichael Buesch #include <linux/ssb/ssb_driver_mips.h>
28061e115a5SMichael Buesch #include <linux/ssb/ssb_driver_extif.h>
28161e115a5SMichael Buesch #include <linux/ssb/ssb_driver_pci.h>
28261e115a5SMichael Buesch 
28361e115a5SMichael Buesch struct ssb_bus {
28461e115a5SMichael Buesch 	/* The MMIO area. */
28561e115a5SMichael Buesch 	void __iomem *mmio;
28661e115a5SMichael Buesch 
28761e115a5SMichael Buesch 	const struct ssb_bus_ops *ops;
28861e115a5SMichael Buesch 
2898b45499cSMichael Buesch 	/* The core currently mapped into the MMIO window.
2908b45499cSMichael Buesch 	 * Not valid on all host-buses. So don't use outside of SSB. */
29161e115a5SMichael Buesch 	struct ssb_device *mapped_device;
29224ea602eSAlbert Herranz 	union {
29361e115a5SMichael Buesch 		/* Currently mapped PCMCIA segment. (bustype == SSB_BUSTYPE_PCMCIA only) */
29461e115a5SMichael Buesch 		u8 mapped_pcmcia_seg;
29524ea602eSAlbert Herranz 		/* Current SSB base address window for SDIO. */
29624ea602eSAlbert Herranz 		u32 sdio_sbaddr;
29724ea602eSAlbert Herranz 	};
298993e1c78SMichael Buesch 	/* Lock for core and segment switching.
299993e1c78SMichael Buesch 	 * On PCMCIA-host busses this is used to protect the whole MMIO access. */
30061e115a5SMichael Buesch 	spinlock_t bar_lock;
30161e115a5SMichael Buesch 
3028b45499cSMichael Buesch 	/* The host-bus this backplane is running on. */
30361e115a5SMichael Buesch 	enum ssb_bustype bustype;
3048b45499cSMichael Buesch 	/* Pointers to the host-bus. Check bustype before using any of these pointers. */
3058b45499cSMichael Buesch 	union {
30661e115a5SMichael Buesch 		/* Pointer to the PCI bus (only valid if bustype == SSB_BUSTYPE_PCI). */
30761e115a5SMichael Buesch 		struct pci_dev *host_pci;
30861e115a5SMichael Buesch 		/* Pointer to the PCMCIA device (only if bustype == SSB_BUSTYPE_PCMCIA). */
30961e115a5SMichael Buesch 		struct pcmcia_device *host_pcmcia;
31024ea602eSAlbert Herranz 		/* Pointer to the SDIO device (only if bustype == SSB_BUSTYPE_SDIO). */
31124ea602eSAlbert Herranz 		struct sdio_func *host_sdio;
3128b45499cSMichael Buesch 	};
31324ea602eSAlbert Herranz 
31424ea602eSAlbert Herranz 	/* See enum ssb_quirks */
31524ea602eSAlbert Herranz 	unsigned int quirks;
31661e115a5SMichael Buesch 
317e7ec2e32SMichael Buesch #ifdef CONFIG_SSB_SPROM
31861e115a5SMichael Buesch 	/* Mutex to protect the SPROM writing. */
319e7ec2e32SMichael Buesch 	struct mutex sprom_mutex;
32061e115a5SMichael Buesch #endif
32161e115a5SMichael Buesch 
32261e115a5SMichael Buesch 	/* ID information about the Chip. */
32361e115a5SMichael Buesch 	u16 chip_id;
324ce57d9e6SRafał Miłecki 	u8 chip_rev;
325ea2db495SRafał Miłecki 	u16 sprom_offset;
326c272ef44SLarry Finger 	u16 sprom_size;		/* number of words in sprom */
32761e115a5SMichael Buesch 	u8 chip_package;
32861e115a5SMichael Buesch 
32961e115a5SMichael Buesch 	/* List of devices (cores) on the backplane. */
33061e115a5SMichael Buesch 	struct ssb_device devices[SSB_MAX_NR_CORES];
33161e115a5SMichael Buesch 	u8 nr_devices;
33261e115a5SMichael Buesch 
33361e115a5SMichael Buesch 	/* Software ID number for this bus. */
33461e115a5SMichael Buesch 	unsigned int busnumber;
33561e115a5SMichael Buesch 
33661e115a5SMichael Buesch 	/* The ChipCommon device (if available). */
33761e115a5SMichael Buesch 	struct ssb_chipcommon chipco;
33861e115a5SMichael Buesch 	/* The PCI-core device (if available). */
33961e115a5SMichael Buesch 	struct ssb_pcicore pcicore;
34061e115a5SMichael Buesch 	/* The MIPS-core device (if available). */
34161e115a5SMichael Buesch 	struct ssb_mipscore mipscore;
34261e115a5SMichael Buesch 	/* The EXTif-core device (if available). */
34361e115a5SMichael Buesch 	struct ssb_extif extif;
34461e115a5SMichael Buesch 
34561e115a5SMichael Buesch 	/* The following structure elements are not available in early
34661e115a5SMichael Buesch 	 * SSB initialization. Though, they are available for regular
34761e115a5SMichael Buesch 	 * registered drivers at any stage. So be careful when
34861e115a5SMichael Buesch 	 * using them in the ssb core code. */
34961e115a5SMichael Buesch 
35061e115a5SMichael Buesch 	/* ID information about the PCB. */
35161e115a5SMichael Buesch 	struct ssb_boardinfo boardinfo;
35261e115a5SMichael Buesch 	/* Contents of the SPROM. */
35361e115a5SMichael Buesch 	struct ssb_sprom sprom;
3547cb44615SMichael Buesch 	/* If the board has a cardbus slot, this is set to true. */
3557cb44615SMichael Buesch 	bool has_cardbus_slot;
35661e115a5SMichael Buesch 
35753521d8cSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED
35853521d8cSMichael Buesch 	/* Lock for GPIO register access. */
35953521d8cSMichael Buesch 	spinlock_t gpio_lock;
36053521d8cSMichael Buesch #endif /* EMBEDDED */
36153521d8cSMichael Buesch 
36261e115a5SMichael Buesch 	/* Internal-only stuff follows. Do not touch. */
36361e115a5SMichael Buesch 	struct list_head list;
36461e115a5SMichael Buesch #ifdef CONFIG_SSB_DEBUG
36561e115a5SMichael Buesch 	/* Is the bus already powered up? */
36661e115a5SMichael Buesch 	bool powered_up;
36761e115a5SMichael Buesch 	int power_warn_count;
36861e115a5SMichael Buesch #endif /* DEBUG */
36961e115a5SMichael Buesch };
37061e115a5SMichael Buesch 
37124ea602eSAlbert Herranz enum ssb_quirks {
37224ea602eSAlbert Herranz 	/* SDIO connected card requires performing a read after writing a 32-bit value */
37324ea602eSAlbert Herranz 	SSB_QUIRK_SDIO_READ_AFTER_WRITE32	= (1 << 0),
37424ea602eSAlbert Herranz };
37524ea602eSAlbert Herranz 
37661e115a5SMichael Buesch /* The initialization-invariants. */
37761e115a5SMichael Buesch struct ssb_init_invariants {
3787cb44615SMichael Buesch 	/* Versioning information about the PCB. */
37961e115a5SMichael Buesch 	struct ssb_boardinfo boardinfo;
3807cb44615SMichael Buesch 	/* The SPROM information. That's either stored in an
3817cb44615SMichael Buesch 	 * EEPROM or NVRAM on the board. */
38261e115a5SMichael Buesch 	struct ssb_sprom sprom;
3837cb44615SMichael Buesch 	/* If the board has a cardbus slot, this is set to true. */
3847cb44615SMichael Buesch 	bool has_cardbus_slot;
38561e115a5SMichael Buesch };
38661e115a5SMichael Buesch /* Type of function to fetch the invariants. */
38761e115a5SMichael Buesch typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
38861e115a5SMichael Buesch 				     struct ssb_init_invariants *iv);
38961e115a5SMichael Buesch 
39061e115a5SMichael Buesch /* Register a SSB system bus. get_invariants() is called after the
39161e115a5SMichael Buesch  * basic system devices are initialized.
39261e115a5SMichael Buesch  * The invariants are usually fetched from some NVRAM.
39361e115a5SMichael Buesch  * Put the invariants into the struct pointed to by iv. */
39461e115a5SMichael Buesch extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
39561e115a5SMichael Buesch 				   unsigned long baseaddr,
39661e115a5SMichael Buesch 				   ssb_invariants_func_t get_invariants);
39761e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST
39861e115a5SMichael Buesch extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
39961e115a5SMichael Buesch 				   struct pci_dev *host_pci);
40061e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */
40161e115a5SMichael Buesch #ifdef CONFIG_SSB_PCMCIAHOST
40261e115a5SMichael Buesch extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
40361e115a5SMichael Buesch 				      struct pcmcia_device *pcmcia_dev,
40461e115a5SMichael Buesch 				      unsigned long baseaddr);
40561e115a5SMichael Buesch #endif /* CONFIG_SSB_PCMCIAHOST */
40624ea602eSAlbert Herranz #ifdef CONFIG_SSB_SDIOHOST
40724ea602eSAlbert Herranz extern int ssb_bus_sdiobus_register(struct ssb_bus *bus,
40824ea602eSAlbert Herranz 				    struct sdio_func *sdio_func,
40924ea602eSAlbert Herranz 				    unsigned int quirks);
41024ea602eSAlbert Herranz #endif /* CONFIG_SSB_SDIOHOST */
41124ea602eSAlbert Herranz 
41261e115a5SMichael Buesch 
41361e115a5SMichael Buesch extern void ssb_bus_unregister(struct ssb_bus *bus);
41461e115a5SMichael Buesch 
415d53cdbb9SJohn W. Linville /* Does the device have an SPROM? */
416d53cdbb9SJohn W. Linville extern bool ssb_is_sprom_available(struct ssb_bus *bus);
417d53cdbb9SJohn W. Linville 
418e79c1ba8SMichael Buesch /* Set a fallback SPROM.
419e79c1ba8SMichael Buesch  * See kdoc at the function definition for complete documentation. */
420b3ae52b6SHauke Mehrtens extern int ssb_arch_register_fallback_sprom(
421b3ae52b6SHauke Mehrtens 		int (*sprom_callback)(struct ssb_bus *bus,
422b3ae52b6SHauke Mehrtens 		struct ssb_sprom *out));
423e79c1ba8SMichael Buesch 
4248fe2b65aSMichael Buesch /* Suspend a SSB bus.
4258fe2b65aSMichael Buesch  * Call this from the parent bus suspend routine. */
4268fe2b65aSMichael Buesch extern int ssb_bus_suspend(struct ssb_bus *bus);
4278fe2b65aSMichael Buesch /* Resume a SSB bus.
4288fe2b65aSMichael Buesch  * Call this from the parent bus resume routine. */
4298fe2b65aSMichael Buesch extern int ssb_bus_resume(struct ssb_bus *bus);
4308fe2b65aSMichael Buesch 
43161e115a5SMichael Buesch extern u32 ssb_clockspeed(struct ssb_bus *bus);
43261e115a5SMichael Buesch 
43361e115a5SMichael Buesch /* Is the device enabled in hardware? */
43461e115a5SMichael Buesch int ssb_device_is_enabled(struct ssb_device *dev);
43561e115a5SMichael Buesch /* Enable a device and pass device-specific SSB_TMSLOW flags.
43661e115a5SMichael Buesch  * If no device-specific flags are available, use 0. */
43761e115a5SMichael Buesch void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
43861e115a5SMichael Buesch /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
43961e115a5SMichael Buesch void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
44061e115a5SMichael Buesch 
44161e115a5SMichael Buesch 
44261e115a5SMichael Buesch /* Device MMIO register read/write functions. */
443ffc7689dSMichael Buesch static inline u8 ssb_read8(struct ssb_device *dev, u16 offset)
444ffc7689dSMichael Buesch {
445ffc7689dSMichael Buesch 	return dev->ops->read8(dev, offset);
446ffc7689dSMichael Buesch }
44761e115a5SMichael Buesch static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
44861e115a5SMichael Buesch {
44961e115a5SMichael Buesch 	return dev->ops->read16(dev, offset);
45061e115a5SMichael Buesch }
45161e115a5SMichael Buesch static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
45261e115a5SMichael Buesch {
45361e115a5SMichael Buesch 	return dev->ops->read32(dev, offset);
45461e115a5SMichael Buesch }
455ffc7689dSMichael Buesch static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value)
456ffc7689dSMichael Buesch {
457ffc7689dSMichael Buesch 	dev->ops->write8(dev, offset, value);
458ffc7689dSMichael Buesch }
45961e115a5SMichael Buesch static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
46061e115a5SMichael Buesch {
46161e115a5SMichael Buesch 	dev->ops->write16(dev, offset, value);
46261e115a5SMichael Buesch }
46361e115a5SMichael Buesch static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
46461e115a5SMichael Buesch {
46561e115a5SMichael Buesch 	dev->ops->write32(dev, offset, value);
46661e115a5SMichael Buesch }
467d625a29bSMichael Buesch #ifdef CONFIG_SSB_BLOCKIO
468d625a29bSMichael Buesch static inline void ssb_block_read(struct ssb_device *dev, void *buffer,
469d625a29bSMichael Buesch 				  size_t count, u16 offset, u8 reg_width)
470d625a29bSMichael Buesch {
471d625a29bSMichael Buesch 	dev->ops->block_read(dev, buffer, count, offset, reg_width);
472d625a29bSMichael Buesch }
473d625a29bSMichael Buesch 
474d625a29bSMichael Buesch static inline void ssb_block_write(struct ssb_device *dev, const void *buffer,
475d625a29bSMichael Buesch 				   size_t count, u16 offset, u8 reg_width)
476d625a29bSMichael Buesch {
477d625a29bSMichael Buesch 	dev->ops->block_write(dev, buffer, count, offset, reg_width);
478d625a29bSMichael Buesch }
479d625a29bSMichael Buesch #endif /* CONFIG_SSB_BLOCKIO */
48061e115a5SMichael Buesch 
48161e115a5SMichael Buesch 
482f225763aSMichael Buesch /* The SSB DMA API. Use this API for any DMA operation on the device.
483f225763aSMichael Buesch  * This API basically is a wrapper that calls the correct DMA API for
484f225763aSMichael Buesch  * the host device type the SSB device is attached to. */
485f225763aSMichael Buesch 
48661e115a5SMichael Buesch /* Translation (routing) bits that need to be ORed to DMA
48761e115a5SMichael Buesch  * addresses before they are given to a device. */
48861e115a5SMichael Buesch extern u32 ssb_dma_translation(struct ssb_device *dev);
48961e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_MASK	0xC0000000
49061e115a5SMichael Buesch #define SSB_DMA_TRANSLATION_SHIFT	30
49161e115a5SMichael Buesch 
492f225763aSMichael Buesch static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev)
493f225763aSMichael Buesch {
494f225763aSMichael Buesch #ifdef CONFIG_SSB_DEBUG
495f225763aSMichael Buesch 	printk(KERN_ERR "SSB: BUG! Calling DMA API for "
496f225763aSMichael Buesch 	       "unsupported bustype %d\n", dev->bus->bustype);
497f225763aSMichael Buesch #endif /* DEBUG */
498f225763aSMichael Buesch }
499f225763aSMichael Buesch 
50061e115a5SMichael Buesch #ifdef CONFIG_SSB_PCIHOST
50161e115a5SMichael Buesch /* PCI-host wrapper driver */
50261e115a5SMichael Buesch extern int ssb_pcihost_register(struct pci_driver *driver);
50361e115a5SMichael Buesch static inline void ssb_pcihost_unregister(struct pci_driver *driver)
50461e115a5SMichael Buesch {
50561e115a5SMichael Buesch 	pci_unregister_driver(driver);
50661e115a5SMichael Buesch }
507961d57c8SMiguel Botón 
508961d57c8SMiguel Botón static inline
509961d57c8SMiguel Botón void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
510961d57c8SMiguel Botón {
511961d57c8SMiguel Botón 	if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
512961d57c8SMiguel Botón 		pci_set_power_state(sdev->bus->host_pci, state);
513961d57c8SMiguel Botón }
514532031d7SAndrew Morton #else
515532031d7SAndrew Morton static inline void ssb_pcihost_unregister(struct pci_driver *driver)
516532031d7SAndrew Morton {
517532031d7SAndrew Morton }
518532031d7SAndrew Morton 
519532031d7SAndrew Morton static inline
520532031d7SAndrew Morton void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
521532031d7SAndrew Morton {
522532031d7SAndrew Morton }
52361e115a5SMichael Buesch #endif /* CONFIG_SSB_PCIHOST */
52461e115a5SMichael Buesch 
52561e115a5SMichael Buesch 
52661e115a5SMichael Buesch /* If a driver is shutdown or suspended, call this to signal
52761e115a5SMichael Buesch  * that the bus may be completely powered down. SSB will decide,
52861e115a5SMichael Buesch  * if it's really time to power down the bus, based on if there
52961e115a5SMichael Buesch  * are other devices that want to run. */
53061e115a5SMichael Buesch extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
53161e115a5SMichael Buesch /* Before initializing and enabling a device, call this to power-up the bus.
53261e115a5SMichael Buesch  * If you want to allow use of dynamic-power-control, pass the flag.
53361e115a5SMichael Buesch  * Otherwise static always-on powercontrol will be used. */
53461e115a5SMichael Buesch extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
53561e115a5SMichael Buesch 
5368576f815SRafał Miłecki extern void ssb_commit_settings(struct ssb_bus *bus);
53761e115a5SMichael Buesch 
53861e115a5SMichael Buesch /* Various helper functions */
53961e115a5SMichael Buesch extern u32 ssb_admatch_base(u32 adm);
54061e115a5SMichael Buesch extern u32 ssb_admatch_size(u32 adm);
54161e115a5SMichael Buesch 
542aab547ceSMichael Buesch /* PCI device mapping and fixup routines.
543aab547ceSMichael Buesch  * Called from the architecture pcibios init code.
544aab547ceSMichael Buesch  * These are only available on SSB_EMBEDDED configurations. */
545aab547ceSMichael Buesch #ifdef CONFIG_SSB_EMBEDDED
546aab547ceSMichael Buesch int ssb_pcibios_plat_dev_init(struct pci_dev *dev);
547aab547ceSMichael Buesch int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
548aab547ceSMichael Buesch #endif /* CONFIG_SSB_EMBEDDED */
54961e115a5SMichael Buesch 
55061e115a5SMichael Buesch #endif /* LINUX_SSB_H_ */
551