ssb: Convert to use of the new SPROM structure
[safe/jmp/linux-2.6] / include / linux / ssb / ssb.h
1 #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
14 struct pcmcia_device;
15 struct ssb_bus;
16 struct ssb_driver;
17
18
19 struct 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
54 struct 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
68 struct 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
81 struct ssb_sprom {
82         u8 revision;
83         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 */
109         /* 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                 };
118         };
119 };
120
121 /* Information about the PCB the circuitry is soldered on. */
122 struct ssb_boardinfo {
123         u16 vendor;
124         u16 type;
125         u16 rev;
126 };
127
128
129 struct ssb_device;
130 /* Lowlevel read/write operations on the device MMIO.
131  * Internal, don't use that outside of ssb. */
132 struct 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 */
179 struct __ssb_dev_wrapper {
180         struct device dev;
181         struct ssb_device *sdev;
182 };
183
184 struct 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. */
202 static inline
203 struct 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 */
211 static inline
212 void ssb_set_drvdata(struct ssb_device *dev, void *data)
213 {
214         dev->drvdata = data;
215 }
216 static inline
217 void * 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) */
223 void ssb_set_devtypedata(struct ssb_device *dev, void *data);
224 static inline
225 void * ssb_get_devtypedata(struct ssb_device *dev)
226 {
227         return dev->devtypedata;
228 }
229
230
231 struct 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
245 extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
246 static inline int ssb_driver_register(struct ssb_driver *drv)
247 {
248         return __ssb_driver_register(drv, THIS_MODULE);
249 }
250 extern void ssb_driver_unregister(struct ssb_driver *drv);
251
252
253
254
255 enum 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
283 struct 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         u16 sprom_size;         /* number of words in sprom */
312         u8 chip_package;
313
314         /* List of devices (cores) on the backplane. */
315         struct ssb_device devices[SSB_MAX_NR_CORES];
316         u8 nr_devices;
317
318         /* Reference count. Number of suspended devices. */
319         u8 suspend_cnt;
320
321         /* Software ID number for this bus. */
322         unsigned int busnumber;
323
324         /* The ChipCommon device (if available). */
325         struct ssb_chipcommon chipco;
326         /* The PCI-core device (if available). */
327         struct ssb_pcicore pcicore;
328         /* The MIPS-core device (if available). */
329         struct ssb_mipscore mipscore;
330         /* The EXTif-core device (if available). */
331         struct ssb_extif extif;
332
333         /* The following structure elements are not available in early
334          * SSB initialization. Though, they are available for regular
335          * registered drivers at any stage. So be careful when
336          * using them in the ssb core code. */
337
338         /* ID information about the PCB. */
339         struct ssb_boardinfo boardinfo;
340         /* Contents of the SPROM. */
341         struct ssb_sprom sprom;
342
343         /* Internal-only stuff follows. Do not touch. */
344         struct list_head list;
345 #ifdef CONFIG_SSB_DEBUG
346         /* Is the bus already powered up? */
347         bool powered_up;
348         int power_warn_count;
349 #endif /* DEBUG */
350 };
351
352 /* The initialization-invariants. */
353 struct ssb_init_invariants {
354         struct ssb_boardinfo boardinfo;
355         struct ssb_sprom sprom;
356 };
357 /* Type of function to fetch the invariants. */
358 typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
359                                      struct ssb_init_invariants *iv);
360
361 /* Register a SSB system bus. get_invariants() is called after the
362  * basic system devices are initialized.
363  * The invariants are usually fetched from some NVRAM.
364  * Put the invariants into the struct pointed to by iv. */
365 extern int ssb_bus_ssbbus_register(struct ssb_bus *bus,
366                                    unsigned long baseaddr,
367                                    ssb_invariants_func_t get_invariants);
368 #ifdef CONFIG_SSB_PCIHOST
369 extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
370                                    struct pci_dev *host_pci);
371 #endif /* CONFIG_SSB_PCIHOST */
372 #ifdef CONFIG_SSB_PCMCIAHOST
373 extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
374                                       struct pcmcia_device *pcmcia_dev,
375                                       unsigned long baseaddr);
376 #endif /* CONFIG_SSB_PCMCIAHOST */
377
378 extern void ssb_bus_unregister(struct ssb_bus *bus);
379
380 extern u32 ssb_clockspeed(struct ssb_bus *bus);
381
382 /* Is the device enabled in hardware? */
383 int ssb_device_is_enabled(struct ssb_device *dev);
384 /* Enable a device and pass device-specific SSB_TMSLOW flags.
385  * If no device-specific flags are available, use 0. */
386 void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
387 /* Disable a device in hardware and pass SSB_TMSLOW flags (if any). */
388 void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
389
390
391 /* Device MMIO register read/write functions. */
392 static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
393 {
394         return dev->ops->read16(dev, offset);
395 }
396 static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
397 {
398         return dev->ops->read32(dev, offset);
399 }
400 static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
401 {
402         dev->ops->write16(dev, offset, value);
403 }
404 static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
405 {
406         dev->ops->write32(dev, offset, value);
407 }
408
409
410 /* Translation (routing) bits that need to be ORed to DMA
411  * addresses before they are given to a device. */
412 extern u32 ssb_dma_translation(struct ssb_device *dev);
413 #define SSB_DMA_TRANSLATION_MASK        0xC0000000
414 #define SSB_DMA_TRANSLATION_SHIFT       30
415
416 extern int ssb_dma_set_mask(struct ssb_device *ssb_dev, u64 mask);
417
418
419 #ifdef CONFIG_SSB_PCIHOST
420 /* PCI-host wrapper driver */
421 extern int ssb_pcihost_register(struct pci_driver *driver);
422 static inline void ssb_pcihost_unregister(struct pci_driver *driver)
423 {
424         pci_unregister_driver(driver);
425 }
426 #endif /* CONFIG_SSB_PCIHOST */
427
428
429 /* If a driver is shutdown or suspended, call this to signal
430  * that the bus may be completely powered down. SSB will decide,
431  * if it's really time to power down the bus, based on if there
432  * are other devices that want to run. */
433 extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
434 /* Before initializing and enabling a device, call this to power-up the bus.
435  * If you want to allow use of dynamic-power-control, pass the flag.
436  * Otherwise static always-on powercontrol will be used. */
437 extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
438
439
440 /* Various helper functions */
441 extern u32 ssb_admatch_base(u32 adm);
442 extern u32 ssb_admatch_size(u32 adm);
443
444
445 #endif /* LINUX_SSB_H_ */