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