0001
0002 #ifndef LINUX_SSB_H_
0003 #define LINUX_SSB_H_
0004
0005 #include <linux/device.h>
0006 #include <linux/list.h>
0007 #include <linux/types.h>
0008 #include <linux/spinlock.h>
0009 #include <linux/pci.h>
0010 #include <linux/gpio/driver.h>
0011 #include <linux/mod_devicetable.h>
0012 #include <linux/dma-mapping.h>
0013 #include <linux/platform_device.h>
0014
0015 #include <linux/ssb/ssb_regs.h>
0016
0017
0018 struct pcmcia_device;
0019 struct ssb_bus;
0020 struct ssb_driver;
0021
0022 struct ssb_sprom_core_pwr_info {
0023 u8 itssi_2g, itssi_5g;
0024 u8 maxpwr_2g, maxpwr_5gl, maxpwr_5g, maxpwr_5gh;
0025 u16 pa_2g[4], pa_5gl[4], pa_5g[4], pa_5gh[4];
0026 };
0027
0028 struct ssb_sprom {
0029 u8 revision;
0030 u8 il0mac[6] __aligned(sizeof(u16));
0031 u8 et0mac[6] __aligned(sizeof(u16));
0032 u8 et1mac[6] __aligned(sizeof(u16));
0033 u8 et2mac[6] __aligned(sizeof(u16));
0034 u8 et0phyaddr;
0035 u8 et1phyaddr;
0036 u8 et2phyaddr;
0037 u8 et0mdcport;
0038 u8 et1mdcport;
0039 u8 et2mdcport;
0040 u16 dev_id;
0041 u16 board_rev;
0042 u16 board_num;
0043 u16 board_type;
0044 u8 country_code;
0045 char alpha2[2];
0046 u8 leddc_on_time;
0047 u8 leddc_off_time;
0048 u8 ant_available_a;
0049 u8 ant_available_bg;
0050 u16 pa0b0;
0051 u16 pa0b1;
0052 u16 pa0b2;
0053 u16 pa1b0;
0054 u16 pa1b1;
0055 u16 pa1b2;
0056 u16 pa1lob0;
0057 u16 pa1lob1;
0058 u16 pa1lob2;
0059 u16 pa1hib0;
0060 u16 pa1hib1;
0061 u16 pa1hib2;
0062 u8 gpio0;
0063 u8 gpio1;
0064 u8 gpio2;
0065 u8 gpio3;
0066 u8 maxpwr_bg;
0067 u8 maxpwr_al;
0068 u8 maxpwr_a;
0069 u8 maxpwr_ah;
0070 u8 itssi_a;
0071 u8 itssi_bg;
0072 u8 tri2g;
0073 u8 tri5gl;
0074 u8 tri5g;
0075 u8 tri5gh;
0076 u8 txpid2g[4];
0077 u8 txpid5gl[4];
0078 u8 txpid5g[4];
0079 u8 txpid5gh[4];
0080 s8 rxpo2g;
0081 s8 rxpo5g;
0082 u8 rssisav2g;
0083 u8 rssismc2g;
0084 u8 rssismf2g;
0085 u8 bxa2g;
0086 u8 rssisav5g;
0087 u8 rssismc5g;
0088 u8 rssismf5g;
0089 u8 bxa5g;
0090 u16 cck2gpo;
0091 u32 ofdm2gpo;
0092 u32 ofdm5glpo;
0093 u32 ofdm5gpo;
0094 u32 ofdm5ghpo;
0095 u32 boardflags;
0096 u32 boardflags2;
0097 u32 boardflags3;
0098
0099 u16 boardflags_lo;
0100 u16 boardflags_hi;
0101 u16 boardflags2_lo;
0102 u16 boardflags2_hi;
0103
0104 struct ssb_sprom_core_pwr_info core_pwr_info[4];
0105
0106
0107
0108
0109 struct {
0110 s8 a0, a1, a2, a3;
0111 } antenna_gain;
0112
0113 struct {
0114 struct {
0115 u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
0116 } ghz2;
0117 struct {
0118 u8 tssipos, extpa_gain, pdet_range, tr_iso, antswlut;
0119 } ghz5;
0120 } fem;
0121
0122 u16 mcs2gpo[8];
0123 u16 mcs5gpo[8];
0124 u16 mcs5glpo[8];
0125 u16 mcs5ghpo[8];
0126 u8 opo;
0127
0128 u8 rxgainerr2ga[3];
0129 u8 rxgainerr5gla[3];
0130 u8 rxgainerr5gma[3];
0131 u8 rxgainerr5gha[3];
0132 u8 rxgainerr5gua[3];
0133
0134 u8 noiselvl2ga[3];
0135 u8 noiselvl5gla[3];
0136 u8 noiselvl5gma[3];
0137 u8 noiselvl5gha[3];
0138 u8 noiselvl5gua[3];
0139
0140 u8 regrev;
0141 u8 txchain;
0142 u8 rxchain;
0143 u8 antswitch;
0144 u16 cddpo;
0145 u16 stbcpo;
0146 u16 bw40po;
0147 u16 bwduppo;
0148
0149 u8 tempthresh;
0150 u8 tempoffset;
0151 u16 rawtempsense;
0152 u8 measpower;
0153 u8 tempsense_slope;
0154 u8 tempcorrx;
0155 u8 tempsense_option;
0156 u8 freqoffset_corr;
0157 u8 iqcal_swp_dis;
0158 u8 hw_iqcal_en;
0159 u8 elna2g;
0160 u8 elna5g;
0161 u8 phycal_tempdelta;
0162 u8 temps_period;
0163 u8 temps_hysteresis;
0164 u8 measpower1;
0165 u8 measpower2;
0166 u8 pcieingress_war;
0167
0168
0169 u16 cckbw202gpo;
0170 u16 cckbw20ul2gpo;
0171 u32 legofdmbw202gpo;
0172 u32 legofdmbw20ul2gpo;
0173 u32 legofdmbw205glpo;
0174 u32 legofdmbw20ul5glpo;
0175 u32 legofdmbw205gmpo;
0176 u32 legofdmbw20ul5gmpo;
0177 u32 legofdmbw205ghpo;
0178 u32 legofdmbw20ul5ghpo;
0179 u32 mcsbw202gpo;
0180 u32 mcsbw20ul2gpo;
0181 u32 mcsbw402gpo;
0182 u32 mcsbw205glpo;
0183 u32 mcsbw20ul5glpo;
0184 u32 mcsbw405glpo;
0185 u32 mcsbw205gmpo;
0186 u32 mcsbw20ul5gmpo;
0187 u32 mcsbw405gmpo;
0188 u32 mcsbw205ghpo;
0189 u32 mcsbw20ul5ghpo;
0190 u32 mcsbw405ghpo;
0191 u16 mcs32po;
0192 u16 legofdm40duppo;
0193 u8 sar2g;
0194 u8 sar5g;
0195 };
0196
0197
0198 struct ssb_boardinfo {
0199 u16 vendor;
0200 u16 type;
0201 };
0202
0203
0204 struct ssb_device;
0205
0206
0207 struct ssb_bus_ops {
0208 u8 (*read8)(struct ssb_device *dev, u16 offset);
0209 u16 (*read16)(struct ssb_device *dev, u16 offset);
0210 u32 (*read32)(struct ssb_device *dev, u16 offset);
0211 void (*write8)(struct ssb_device *dev, u16 offset, u8 value);
0212 void (*write16)(struct ssb_device *dev, u16 offset, u16 value);
0213 void (*write32)(struct ssb_device *dev, u16 offset, u32 value);
0214 #ifdef CONFIG_SSB_BLOCKIO
0215 void (*block_read)(struct ssb_device *dev, void *buffer,
0216 size_t count, u16 offset, u8 reg_width);
0217 void (*block_write)(struct ssb_device *dev, const void *buffer,
0218 size_t count, u16 offset, u8 reg_width);
0219 #endif
0220 };
0221
0222
0223
0224 #define SSB_DEV_CHIPCOMMON 0x800
0225 #define SSB_DEV_ILINE20 0x801
0226 #define SSB_DEV_SDRAM 0x803
0227 #define SSB_DEV_PCI 0x804
0228 #define SSB_DEV_MIPS 0x805
0229 #define SSB_DEV_ETHERNET 0x806
0230 #define SSB_DEV_V90 0x807
0231 #define SSB_DEV_USB11_HOSTDEV 0x808
0232 #define SSB_DEV_ADSL 0x809
0233 #define SSB_DEV_ILINE100 0x80A
0234 #define SSB_DEV_IPSEC 0x80B
0235 #define SSB_DEV_PCMCIA 0x80D
0236 #define SSB_DEV_INTERNAL_MEM 0x80E
0237 #define SSB_DEV_MEMC_SDRAM 0x80F
0238 #define SSB_DEV_EXTIF 0x811
0239 #define SSB_DEV_80211 0x812
0240 #define SSB_DEV_MIPS_3302 0x816
0241 #define SSB_DEV_USB11_HOST 0x817
0242 #define SSB_DEV_USB11_DEV 0x818
0243 #define SSB_DEV_USB20_HOST 0x819
0244 #define SSB_DEV_USB20_DEV 0x81A
0245 #define SSB_DEV_SDIO_HOST 0x81B
0246 #define SSB_DEV_ROBOSWITCH 0x81C
0247 #define SSB_DEV_PARA_ATA 0x81D
0248 #define SSB_DEV_SATA_XORDMA 0x81E
0249 #define SSB_DEV_ETHERNET_GBIT 0x81F
0250 #define SSB_DEV_PCIE 0x820
0251 #define SSB_DEV_MIMO_PHY 0x821
0252 #define SSB_DEV_SRAM_CTRLR 0x822
0253 #define SSB_DEV_MINI_MACPHY 0x823
0254 #define SSB_DEV_ARM_1176 0x824
0255 #define SSB_DEV_ARM_7TDMI 0x825
0256 #define SSB_DEV_ARM_CM3 0x82A
0257
0258
0259 #define SSB_VENDOR_BROADCOM 0x4243
0260
0261
0262
0263 struct __ssb_dev_wrapper {
0264 struct device dev;
0265 struct ssb_device *sdev;
0266 };
0267
0268 struct ssb_device {
0269
0270
0271 const struct ssb_bus_ops *ops;
0272
0273 struct device *dev, *dma_dev;
0274
0275 struct ssb_bus *bus;
0276 struct ssb_device_id id;
0277
0278 u8 core_index;
0279 unsigned int irq;
0280
0281
0282 void *drvdata;
0283 void *devtypedata;
0284 };
0285
0286
0287 static inline
0288 struct ssb_device * dev_to_ssb_dev(struct device *dev)
0289 {
0290 struct __ssb_dev_wrapper *wrap;
0291 wrap = container_of(dev, struct __ssb_dev_wrapper, dev);
0292 return wrap->sdev;
0293 }
0294
0295
0296 static inline
0297 void ssb_set_drvdata(struct ssb_device *dev, void *data)
0298 {
0299 dev->drvdata = data;
0300 }
0301 static inline
0302 void * ssb_get_drvdata(struct ssb_device *dev)
0303 {
0304 return dev->drvdata;
0305 }
0306
0307
0308 void ssb_set_devtypedata(struct ssb_device *dev, void *data);
0309 static inline
0310 void * ssb_get_devtypedata(struct ssb_device *dev)
0311 {
0312 return dev->devtypedata;
0313 }
0314
0315
0316 struct ssb_driver {
0317 const char *name;
0318 const struct ssb_device_id *id_table;
0319
0320 int (*probe)(struct ssb_device *dev, const struct ssb_device_id *id);
0321 void (*remove)(struct ssb_device *dev);
0322 int (*suspend)(struct ssb_device *dev, pm_message_t state);
0323 int (*resume)(struct ssb_device *dev);
0324 void (*shutdown)(struct ssb_device *dev);
0325
0326 struct device_driver drv;
0327 };
0328 #define drv_to_ssb_drv(_drv) container_of(_drv, struct ssb_driver, drv)
0329
0330 extern int __ssb_driver_register(struct ssb_driver *drv, struct module *owner);
0331 #define ssb_driver_register(drv) \
0332 __ssb_driver_register(drv, THIS_MODULE)
0333
0334 extern void ssb_driver_unregister(struct ssb_driver *drv);
0335
0336
0337
0338
0339 enum ssb_bustype {
0340 SSB_BUSTYPE_SSB,
0341 SSB_BUSTYPE_PCI,
0342 SSB_BUSTYPE_PCMCIA,
0343 SSB_BUSTYPE_SDIO,
0344 };
0345
0346
0347 #define SSB_BOARDVENDOR_BCM 0x14E4
0348 #define SSB_BOARDVENDOR_DELL 0x1028
0349 #define SSB_BOARDVENDOR_HP 0x0E11
0350
0351 #define SSB_BOARD_BCM94301CB 0x0406
0352 #define SSB_BOARD_BCM94301MP 0x0407
0353 #define SSB_BOARD_BU4309 0x040A
0354 #define SSB_BOARD_BCM94309CB 0x040B
0355 #define SSB_BOARD_BCM4309MP 0x040C
0356 #define SSB_BOARD_BU4306 0x0416
0357 #define SSB_BOARD_BCM94306MP 0x0418
0358 #define SSB_BOARD_BCM4309G 0x0421
0359 #define SSB_BOARD_BCM4306CB 0x0417
0360 #define SSB_BOARD_BCM94306PC 0x0425
0361 #define SSB_BOARD_BCM94306CBSG 0x042B
0362 #define SSB_BOARD_PCSG94306 0x042D
0363 #define SSB_BOARD_BU4704SD 0x042E
0364 #define SSB_BOARD_BCM94704AGR 0x042F
0365 #define SSB_BOARD_BCM94308MP 0x0430
0366 #define SSB_BOARD_BU4318 0x0447
0367 #define SSB_BOARD_CB4318 0x0448
0368 #define SSB_BOARD_MPG4318 0x0449
0369 #define SSB_BOARD_MP4318 0x044A
0370 #define SSB_BOARD_SD4318 0x044B
0371 #define SSB_BOARD_BCM94306P 0x044C
0372 #define SSB_BOARD_BCM94303MP 0x044E
0373 #define SSB_BOARD_BCM94306MPM 0x0450
0374 #define SSB_BOARD_BCM94306MPL 0x0453
0375 #define SSB_BOARD_PC4303 0x0454
0376 #define SSB_BOARD_BCM94306MPLNA 0x0457
0377 #define SSB_BOARD_BCM94306MPH 0x045B
0378 #define SSB_BOARD_BCM94306PCIV 0x045C
0379 #define SSB_BOARD_BCM94318MPGH 0x0463
0380 #define SSB_BOARD_BU4311 0x0464
0381 #define SSB_BOARD_BCM94311MC 0x0465
0382 #define SSB_BOARD_BCM94311MCAG 0x0466
0383
0384 #define SSB_BOARD_BU4321 0x046B
0385 #define SSB_BOARD_BU4321E 0x047C
0386 #define SSB_BOARD_MP4321 0x046C
0387 #define SSB_BOARD_CB2_4321 0x046D
0388 #define SSB_BOARD_CB2_4321_AG 0x0066
0389 #define SSB_BOARD_MC4321 0x046E
0390
0391 #define SSB_BOARD_BCM94325DEVBU 0x0490
0392 #define SSB_BOARD_BCM94325BGABU 0x0491
0393 #define SSB_BOARD_BCM94325SDGWB 0x0492
0394 #define SSB_BOARD_BCM94325SDGMDL 0x04AA
0395 #define SSB_BOARD_BCM94325SDGMDL2 0x04C6
0396 #define SSB_BOARD_BCM94325SDGMDL3 0x04C9
0397 #define SSB_BOARD_BCM94325SDABGWBA 0x04E1
0398
0399 #define SSB_BOARD_BCM94322MC 0x04A4
0400 #define SSB_BOARD_BCM94322USB 0x04A8
0401 #define SSB_BOARD_BCM94322HM 0x04B0
0402 #define SSB_BOARD_BCM94322USB2D 0x04Bf
0403
0404 #define SSB_BOARD_BU4312 0x048A
0405 #define SSB_BOARD_BCM4312MCGSG 0x04B5
0406
0407 #define SSB_CHIPPACK_BCM4712S 1
0408 #define SSB_CHIPPACK_BCM4712M 2
0409 #define SSB_CHIPPACK_BCM4712L 0
0410
0411 #include <linux/ssb/ssb_driver_chipcommon.h>
0412 #include <linux/ssb/ssb_driver_mips.h>
0413 #include <linux/ssb/ssb_driver_extif.h>
0414 #include <linux/ssb/ssb_driver_pci.h>
0415
0416 struct ssb_bus {
0417
0418 void __iomem *mmio;
0419
0420 const struct ssb_bus_ops *ops;
0421
0422
0423
0424 struct ssb_device *mapped_device;
0425 union {
0426
0427 u8 mapped_pcmcia_seg;
0428
0429 u32 sdio_sbaddr;
0430 };
0431
0432
0433 spinlock_t bar_lock;
0434
0435
0436 enum ssb_bustype bustype;
0437
0438 union {
0439
0440 struct pci_dev *host_pci;
0441
0442 struct pcmcia_device *host_pcmcia;
0443
0444 struct sdio_func *host_sdio;
0445 };
0446
0447
0448 unsigned int quirks;
0449
0450 #ifdef CONFIG_SSB_SPROM
0451
0452 struct mutex sprom_mutex;
0453 #endif
0454
0455
0456 u16 chip_id;
0457 u8 chip_rev;
0458 u16 sprom_offset;
0459 u16 sprom_size;
0460 u8 chip_package;
0461
0462
0463 struct ssb_device devices[SSB_MAX_NR_CORES];
0464 u8 nr_devices;
0465
0466
0467 unsigned int busnumber;
0468
0469
0470 struct ssb_chipcommon chipco;
0471
0472 struct ssb_pcicore pcicore;
0473
0474 struct ssb_mipscore mipscore;
0475
0476 struct ssb_extif extif;
0477
0478
0479
0480
0481
0482
0483
0484 struct ssb_boardinfo boardinfo;
0485
0486 struct ssb_sprom sprom;
0487
0488 bool has_cardbus_slot;
0489
0490 #ifdef CONFIG_SSB_EMBEDDED
0491
0492 spinlock_t gpio_lock;
0493 struct platform_device *watchdog;
0494 #endif
0495 #ifdef CONFIG_SSB_DRIVER_GPIO
0496 struct gpio_chip gpio;
0497 struct irq_domain *irq_domain;
0498 #endif
0499
0500
0501 struct list_head list;
0502
0503 bool powered_up;
0504 int power_warn_count;
0505 };
0506
0507 enum ssb_quirks {
0508
0509 SSB_QUIRK_SDIO_READ_AFTER_WRITE32 = (1 << 0),
0510 };
0511
0512
0513 struct ssb_init_invariants {
0514
0515 struct ssb_boardinfo boardinfo;
0516
0517
0518 struct ssb_sprom sprom;
0519
0520 bool has_cardbus_slot;
0521 };
0522
0523 typedef int (*ssb_invariants_func_t)(struct ssb_bus *bus,
0524 struct ssb_init_invariants *iv);
0525
0526
0527 extern int ssb_bus_host_soc_register(struct ssb_bus *bus,
0528 unsigned long baseaddr);
0529 #ifdef CONFIG_SSB_PCIHOST
0530 extern int ssb_bus_pcibus_register(struct ssb_bus *bus,
0531 struct pci_dev *host_pci);
0532 #endif
0533 #ifdef CONFIG_SSB_PCMCIAHOST
0534 extern int ssb_bus_pcmciabus_register(struct ssb_bus *bus,
0535 struct pcmcia_device *pcmcia_dev,
0536 unsigned long baseaddr);
0537 #endif
0538 #ifdef CONFIG_SSB_SDIOHOST
0539 extern int ssb_bus_sdiobus_register(struct ssb_bus *bus,
0540 struct sdio_func *sdio_func,
0541 unsigned int quirks);
0542 #endif
0543
0544
0545 extern void ssb_bus_unregister(struct ssb_bus *bus);
0546
0547
0548 extern bool ssb_is_sprom_available(struct ssb_bus *bus);
0549
0550
0551
0552 extern int ssb_arch_register_fallback_sprom(
0553 int (*sprom_callback)(struct ssb_bus *bus,
0554 struct ssb_sprom *out));
0555
0556
0557
0558 extern int ssb_bus_suspend(struct ssb_bus *bus);
0559
0560
0561 extern int ssb_bus_resume(struct ssb_bus *bus);
0562
0563 extern u32 ssb_clockspeed(struct ssb_bus *bus);
0564
0565
0566 int ssb_device_is_enabled(struct ssb_device *dev);
0567
0568
0569 void ssb_device_enable(struct ssb_device *dev, u32 core_specific_flags);
0570
0571 void ssb_device_disable(struct ssb_device *dev, u32 core_specific_flags);
0572
0573
0574
0575 static inline u8 ssb_read8(struct ssb_device *dev, u16 offset)
0576 {
0577 return dev->ops->read8(dev, offset);
0578 }
0579 static inline u16 ssb_read16(struct ssb_device *dev, u16 offset)
0580 {
0581 return dev->ops->read16(dev, offset);
0582 }
0583 static inline u32 ssb_read32(struct ssb_device *dev, u16 offset)
0584 {
0585 return dev->ops->read32(dev, offset);
0586 }
0587 static inline void ssb_write8(struct ssb_device *dev, u16 offset, u8 value)
0588 {
0589 dev->ops->write8(dev, offset, value);
0590 }
0591 static inline void ssb_write16(struct ssb_device *dev, u16 offset, u16 value)
0592 {
0593 dev->ops->write16(dev, offset, value);
0594 }
0595 static inline void ssb_write32(struct ssb_device *dev, u16 offset, u32 value)
0596 {
0597 dev->ops->write32(dev, offset, value);
0598 }
0599 #ifdef CONFIG_SSB_BLOCKIO
0600 static inline void ssb_block_read(struct ssb_device *dev, void *buffer,
0601 size_t count, u16 offset, u8 reg_width)
0602 {
0603 dev->ops->block_read(dev, buffer, count, offset, reg_width);
0604 }
0605
0606 static inline void ssb_block_write(struct ssb_device *dev, const void *buffer,
0607 size_t count, u16 offset, u8 reg_width)
0608 {
0609 dev->ops->block_write(dev, buffer, count, offset, reg_width);
0610 }
0611 #endif
0612
0613
0614
0615
0616
0617
0618
0619
0620 extern u32 ssb_dma_translation(struct ssb_device *dev);
0621 #define SSB_DMA_TRANSLATION_MASK 0xC0000000
0622 #define SSB_DMA_TRANSLATION_SHIFT 30
0623
0624 static inline void __cold __ssb_dma_not_implemented(struct ssb_device *dev)
0625 {
0626 #ifdef CONFIG_SSB_DEBUG
0627 printk(KERN_ERR "SSB: BUG! Calling DMA API for "
0628 "unsupported bustype %d\n", dev->bus->bustype);
0629 #endif
0630 }
0631
0632 #ifdef CONFIG_SSB_PCIHOST
0633
0634 extern int ssb_pcihost_register(struct pci_driver *driver);
0635 static inline void ssb_pcihost_unregister(struct pci_driver *driver)
0636 {
0637 pci_unregister_driver(driver);
0638 }
0639
0640 static inline
0641 void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
0642 {
0643 if (sdev->bus->bustype == SSB_BUSTYPE_PCI)
0644 pci_set_power_state(sdev->bus->host_pci, state);
0645 }
0646 #else
0647 static inline void ssb_pcihost_unregister(struct pci_driver *driver)
0648 {
0649 }
0650
0651 static inline
0652 void ssb_pcihost_set_power_state(struct ssb_device *sdev, pci_power_t state)
0653 {
0654 }
0655 #endif
0656
0657
0658
0659
0660
0661
0662 extern int ssb_bus_may_powerdown(struct ssb_bus *bus);
0663
0664
0665
0666 extern int ssb_bus_powerup(struct ssb_bus *bus, bool dynamic_pctl);
0667
0668 extern void ssb_commit_settings(struct ssb_bus *bus);
0669
0670
0671 extern u32 ssb_admatch_base(u32 adm);
0672 extern u32 ssb_admatch_size(u32 adm);
0673
0674
0675
0676
0677 #ifdef CONFIG_SSB_EMBEDDED
0678 int ssb_pcibios_plat_dev_init(struct pci_dev *dev);
0679 int ssb_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin);
0680 #endif
0681
0682 #endif