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