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