0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0020
0021 #include <linux/delay.h>
0022
0023 #include <defs.h>
0024 #include <chipcommon.h>
0025 #include <brcmu_utils.h>
0026 #include <brcm_hw_ids.h>
0027 #include <soc.h>
0028 #include "types.h"
0029 #include "pub.h"
0030 #include "pmu.h"
0031 #include "aiutils.h"
0032
0033
0034
0035 #define SCC_SS_MASK 0x00000007
0036
0037 #define SCC_SS_LPO 0x00000000
0038
0039 #define SCC_SS_XTAL 0x00000001
0040
0041 #define SCC_SS_PCI 0x00000002
0042
0043 #define SCC_LF 0x00000200
0044
0045 #define SCC_LP 0x00000400
0046
0047 #define SCC_FS 0x00000800
0048
0049
0050
0051 #define SCC_IP 0x00001000
0052
0053
0054
0055 #define SCC_XC 0x00002000
0056
0057 #define SCC_XP 0x00004000
0058
0059 #define SCC_CD_MASK 0xffff0000
0060 #define SCC_CD_SHIFT 16
0061
0062
0063
0064 #define SYCC_IE 0x00000001
0065
0066 #define SYCC_AE 0x00000002
0067
0068 #define SYCC_FP 0x00000004
0069
0070 #define SYCC_AR 0x00000008
0071
0072 #define SYCC_HR 0x00000010
0073
0074 #define SYCC_CD_MASK 0xffff0000
0075 #define SYCC_CD_SHIFT 16
0076
0077 #define CST4329_SPROM_OTP_SEL_MASK 0x00000003
0078
0079 #define CST4329_DEFCIS_SEL 0
0080
0081 #define CST4329_SPROM_SEL 1
0082
0083 #define CST4329_OTP_SEL 2
0084
0085 #define CST4329_OTP_PWRDN 3
0086
0087 #define CST4329_SPI_SDIO_MODE_MASK 0x00000004
0088 #define CST4329_SPI_SDIO_MODE_SHIFT 2
0089
0090
0091 #define CCTRL43224_GPIO_TOGGLE 0x8000
0092
0093 #define CCTRL_43224A0_12MA_LED_DRIVE 0x00F000F0
0094
0095 #define CCTRL_43224B0_12MA_LED_DRIVE 0xF0
0096
0097
0098 #define CST43236_SFLASH_MASK 0x00000040
0099 #define CST43236_OTP_MASK 0x00000080
0100 #define CST43236_HSIC_MASK 0x00000100
0101 #define CST43236_BP_CLK 0x00000200
0102 #define CST43236_BOOT_MASK 0x00001800
0103 #define CST43236_BOOT_SHIFT 11
0104 #define CST43236_BOOT_FROM_SRAM 0
0105 #define CST43236_BOOT_FROM_ROM 1
0106 #define CST43236_BOOT_FROM_FLASH 2
0107 #define CST43236_BOOT_FROM_INVALID 3
0108
0109
0110
0111 #define CCTRL4331_BT_COEXIST (1<<0)
0112
0113 #define CCTRL4331_SECI (1<<1)
0114
0115 #define CCTRL4331_EXT_LNA (1<<2)
0116
0117 #define CCTRL4331_SPROM_GPIO13_15 (1<<3)
0118
0119 #define CCTRL4331_EXTPA_EN (1<<4)
0120
0121 #define CCTRL4331_GPIOCLK_ON_SPROMCS (1<<5)
0122
0123 #define CCTRL4331_PCIE_MDIO_ON_SPROMCS (1<<6)
0124
0125 #define CCTRL4331_EXTPA_ON_GPIO2_5 (1<<7)
0126
0127 #define CCTRL4331_OVR_PIPEAUXCLKEN (1<<8)
0128
0129 #define CCTRL4331_OVR_PIPEAUXPWRDOWN (1<<9)
0130
0131 #define CCTRL4331_PCIE_AUXCLKEN (1<<10)
0132
0133 #define CCTRL4331_PCIE_PIPE_PLLDOWN (1<<11)
0134
0135 #define CCTRL4331_BT_SHD0_ON_GPIO4 (1<<16)
0136
0137 #define CCTRL4331_BT_SHD1_ON_GPIO5 (1<<17)
0138
0139
0140
0141 #define CST4331_XTAL_FREQ 0x00000001
0142 #define CST4331_SPROM_PRESENT 0x00000002
0143 #define CST4331_OTP_PRESENT 0x00000004
0144 #define CST4331_LDO_RF 0x00000008
0145 #define CST4331_LDO_PAR 0x00000010
0146
0147
0148 #define CST4319_SPI_CPULESSUSB 0x00000001
0149 #define CST4319_SPI_CLK_POL 0x00000002
0150 #define CST4319_SPI_CLK_PH 0x00000008
0151
0152 #define CST4319_SPROM_OTP_SEL_MASK 0x000000c0
0153 #define CST4319_SPROM_OTP_SEL_SHIFT 6
0154
0155 #define CST4319_DEFCIS_SEL 0x00000000
0156
0157 #define CST4319_SPROM_SEL 0x00000040
0158
0159 #define CST4319_OTP_SEL 0x00000080
0160
0161 #define CST4319_OTP_PWRDN 0x000000c0
0162
0163 #define CST4319_SDIO_USB_MODE 0x00000100
0164 #define CST4319_REMAP_SEL_MASK 0x00000600
0165 #define CST4319_ILPDIV_EN 0x00000800
0166 #define CST4319_XTAL_PD_POL 0x00001000
0167 #define CST4319_LPO_SEL 0x00002000
0168 #define CST4319_RES_INIT_MODE 0x0000c000
0169
0170 #define CST4319_PALDO_EXTPNP 0x00010000
0171 #define CST4319_CBUCK_MODE_MASK 0x00060000
0172 #define CST4319_CBUCK_MODE_BURST 0x00020000
0173 #define CST4319_CBUCK_MODE_LPBURST 0x00060000
0174 #define CST4319_RCAL_VALID 0x01000000
0175 #define CST4319_RCAL_VALUE_MASK 0x3e000000
0176 #define CST4319_RCAL_VALUE_SHIFT 25
0177
0178
0179 #define CST4336_SPI_MODE_MASK 0x00000001
0180 #define CST4336_SPROM_PRESENT 0x00000002
0181 #define CST4336_OTP_PRESENT 0x00000004
0182 #define CST4336_ARMREMAP_0 0x00000008
0183 #define CST4336_ILPDIV_EN_MASK 0x00000010
0184 #define CST4336_ILPDIV_EN_SHIFT 4
0185 #define CST4336_XTAL_PD_POL_MASK 0x00000020
0186 #define CST4336_XTAL_PD_POL_SHIFT 5
0187 #define CST4336_LPO_SEL_MASK 0x00000040
0188 #define CST4336_LPO_SEL_SHIFT 6
0189 #define CST4336_RES_INIT_MODE_MASK 0x00000180
0190 #define CST4336_RES_INIT_MODE_SHIFT 7
0191 #define CST4336_CBUCK_MODE_MASK 0x00000600
0192 #define CST4336_CBUCK_MODE_SHIFT 9
0193
0194
0195 #define CST4313_SPROM_PRESENT 1
0196 #define CST4313_OTP_PRESENT 2
0197 #define CST4313_SPROM_OTP_SEL_MASK 0x00000002
0198 #define CST4313_SPROM_OTP_SEL_SHIFT 0
0199
0200
0201
0202 #define CCTRL_4313_12MA_LED_DRIVE 0x00000007
0203
0204
0205 #define MFGID_ARM 0x43b
0206 #define MFGID_BRCM 0x4bf
0207 #define MFGID_MIPS 0x4a7
0208
0209
0210 #define ER_EROMENTRY 0x000
0211 #define ER_REMAPCONTROL 0xe00
0212 #define ER_REMAPSELECT 0xe04
0213 #define ER_MASTERSELECT 0xe10
0214 #define ER_ITCR 0xf00
0215 #define ER_ITIP 0xf04
0216
0217
0218 #define ER_TAG 0xe
0219 #define ER_TAG1 0x6
0220 #define ER_VALID 1
0221 #define ER_CI 0
0222 #define ER_MP 2
0223 #define ER_ADD 4
0224 #define ER_END 0xe
0225 #define ER_BAD 0xffffffff
0226
0227
0228 #define CIA_MFG_MASK 0xfff00000
0229 #define CIA_MFG_SHIFT 20
0230 #define CIA_CID_MASK 0x000fff00
0231 #define CIA_CID_SHIFT 8
0232 #define CIA_CCL_MASK 0x000000f0
0233 #define CIA_CCL_SHIFT 4
0234
0235
0236 #define CIB_REV_MASK 0xff000000
0237 #define CIB_REV_SHIFT 24
0238 #define CIB_NSW_MASK 0x00f80000
0239 #define CIB_NSW_SHIFT 19
0240 #define CIB_NMW_MASK 0x0007c000
0241 #define CIB_NMW_SHIFT 14
0242 #define CIB_NSP_MASK 0x00003e00
0243 #define CIB_NSP_SHIFT 9
0244 #define CIB_NMP_MASK 0x000001f0
0245 #define CIB_NMP_SHIFT 4
0246
0247
0248 #define AD_ADDR_MASK 0xfffff000
0249 #define AD_SP_MASK 0x00000f00
0250 #define AD_SP_SHIFT 8
0251 #define AD_ST_MASK 0x000000c0
0252 #define AD_ST_SHIFT 6
0253 #define AD_ST_SLAVE 0x00000000
0254 #define AD_ST_BRIDGE 0x00000040
0255 #define AD_ST_SWRAP 0x00000080
0256 #define AD_ST_MWRAP 0x000000c0
0257 #define AD_SZ_MASK 0x00000030
0258 #define AD_SZ_SHIFT 4
0259 #define AD_SZ_4K 0x00000000
0260 #define AD_SZ_8K 0x00000010
0261 #define AD_SZ_16K 0x00000020
0262 #define AD_SZ_SZD 0x00000030
0263 #define AD_AG32 0x00000008
0264 #define AD_ADDR_ALIGN 0x00000fff
0265 #define AD_SZ_BASE 0x00001000
0266
0267
0268 #define SD_SZ_MASK 0xfffff000
0269 #define SD_SG32 0x00000008
0270 #define SD_SZ_ALIGN 0x00000fff
0271
0272
0273 #define PCI_CFG_GPIO_SCS 0x10
0274
0275 #define PCI_CFG_GPIO_XTAL 0x40
0276
0277 #define PCI_CFG_GPIO_PLL 0x80
0278
0279
0280 #define PLL_DELAY 150
0281 #define FREF_DELAY 200
0282 #define XTAL_ON_DELAY 1000
0283
0284
0285 #define AIRC_RESET 1
0286
0287 #define NOREV -1
0288
0289
0290 #define DEFAULT_GPIO_ONTIME 10
0291 #define DEFAULT_GPIO_OFFTIME 90
0292
0293
0294 #define SRC_START 0x80000000
0295 #define SRC_BUSY 0x80000000
0296 #define SRC_OPCODE 0x60000000
0297 #define SRC_OP_READ 0x00000000
0298 #define SRC_OP_WRITE 0x20000000
0299 #define SRC_OP_WRDIS 0x40000000
0300 #define SRC_OP_WREN 0x60000000
0301 #define SRC_OTPSEL 0x00000010
0302 #define SRC_LOCK 0x00000008
0303 #define SRC_SIZE_MASK 0x00000006
0304 #define SRC_SIZE_1K 0x00000000
0305 #define SRC_SIZE_4K 0x00000002
0306 #define SRC_SIZE_16K 0x00000004
0307 #define SRC_SIZE_SHIFT 1
0308 #define SRC_PRESENT 0x00000001
0309
0310
0311 #define GPIO_CTRL_EPA_EN_MASK 0x40
0312
0313 #define DEFAULT_GPIOTIMERVAL \
0314 ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
0315
0316 #define BADIDX (SI_MAXCORES + 1)
0317
0318 #define IS_SIM(chippkg) \
0319 ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
0320
0321 #define GOODCOREADDR(x, b) \
0322 (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
0323 IS_ALIGNED((x), SI_CORE_SIZE))
0324
0325 struct aidmp {
0326 u32 oobselina30;
0327 u32 oobselina74;
0328 u32 PAD[6];
0329 u32 oobselinb30;
0330 u32 oobselinb74;
0331 u32 PAD[6];
0332 u32 oobselinc30;
0333 u32 oobselinc74;
0334 u32 PAD[6];
0335 u32 oobselind30;
0336 u32 oobselind74;
0337 u32 PAD[38];
0338 u32 oobselouta30;
0339 u32 oobselouta74;
0340 u32 PAD[6];
0341 u32 oobseloutb30;
0342 u32 oobseloutb74;
0343 u32 PAD[6];
0344 u32 oobseloutc30;
0345 u32 oobseloutc74;
0346 u32 PAD[6];
0347 u32 oobseloutd30;
0348 u32 oobseloutd74;
0349 u32 PAD[38];
0350 u32 oobsynca;
0351 u32 oobseloutaen;
0352 u32 PAD[6];
0353 u32 oobsyncb;
0354 u32 oobseloutben;
0355 u32 PAD[6];
0356 u32 oobsyncc;
0357 u32 oobseloutcen;
0358 u32 PAD[6];
0359 u32 oobsyncd;
0360 u32 oobseloutden;
0361 u32 PAD[38];
0362 u32 oobaextwidth;
0363 u32 oobainwidth;
0364 u32 oobaoutwidth;
0365 u32 PAD[5];
0366 u32 oobbextwidth;
0367 u32 oobbinwidth;
0368 u32 oobboutwidth;
0369 u32 PAD[5];
0370 u32 oobcextwidth;
0371 u32 oobcinwidth;
0372 u32 oobcoutwidth;
0373 u32 PAD[5];
0374 u32 oobdextwidth;
0375 u32 oobdinwidth;
0376 u32 oobdoutwidth;
0377 u32 PAD[37];
0378 u32 ioctrlset;
0379 u32 ioctrlclear;
0380 u32 ioctrl;
0381 u32 PAD[61];
0382 u32 iostatus;
0383 u32 PAD[127];
0384 u32 ioctrlwidth;
0385 u32 iostatuswidth;
0386 u32 PAD[62];
0387 u32 resetctrl;
0388 u32 resetstatus;
0389 u32 resetreadid;
0390 u32 resetwriteid;
0391 u32 PAD[60];
0392 u32 errlogctrl;
0393 u32 errlogdone;
0394 u32 errlogstatus;
0395 u32 errlogaddrlo;
0396 u32 errlogaddrhi;
0397 u32 errlogid;
0398 u32 errloguser;
0399 u32 errlogflags;
0400 u32 PAD[56];
0401 u32 intstatus;
0402 u32 PAD[127];
0403 u32 config;
0404 u32 PAD[63];
0405 u32 itcr;
0406 u32 PAD[3];
0407 u32 itipooba;
0408 u32 itipoobb;
0409 u32 itipoobc;
0410 u32 itipoobd;
0411 u32 PAD[4];
0412 u32 itipoobaout;
0413 u32 itipoobbout;
0414 u32 itipoobcout;
0415 u32 itipoobdout;
0416 u32 PAD[4];
0417 u32 itopooba;
0418 u32 itopoobb;
0419 u32 itopoobc;
0420 u32 itopoobd;
0421 u32 PAD[4];
0422 u32 itopoobain;
0423 u32 itopoobbin;
0424 u32 itopoobcin;
0425 u32 itopoobdin;
0426 u32 PAD[4];
0427 u32 itopreset;
0428 u32 PAD[15];
0429 u32 peripherialid4;
0430 u32 peripherialid5;
0431 u32 peripherialid6;
0432 u32 peripherialid7;
0433 u32 peripherialid0;
0434 u32 peripherialid1;
0435 u32 peripherialid2;
0436 u32 peripherialid3;
0437 u32 componentid0;
0438 u32 componentid1;
0439 u32 componentid2;
0440 u32 componentid3;
0441 };
0442
0443 static bool
0444 ai_buscore_setup(struct si_info *sii, struct bcma_device *cc)
0445 {
0446
0447 if (cc->bus->nr_cores == 0)
0448 return false;
0449
0450
0451 sii->pub.ccrev = cc->id.rev;
0452
0453
0454 sii->chipst = bcma_read32(cc, CHIPCREGOFFS(chipstatus));
0455
0456
0457 sii->pub.cccaps = bcma_read32(cc, CHIPCREGOFFS(capabilities));
0458
0459
0460 if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {
0461 sii->pub.pmucaps = bcma_read32(cc,
0462 CHIPCREGOFFS(pmucapabilities));
0463 sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;
0464 }
0465
0466 return true;
0467 }
0468
0469 static struct si_info *ai_doattach(struct si_info *sii,
0470 struct bcma_bus *pbus)
0471 {
0472 struct si_pub *sih = &sii->pub;
0473 struct bcma_device *cc;
0474
0475 sii->icbus = pbus;
0476 sii->pcibus = pbus->host_pci;
0477
0478
0479 cc = pbus->drv_cc.core;
0480
0481 sih->chip = pbus->chipinfo.id;
0482 sih->chiprev = pbus->chipinfo.rev;
0483 sih->chippkg = pbus->chipinfo.pkg;
0484 sih->boardvendor = pbus->boardinfo.vendor;
0485 sih->boardtype = pbus->boardinfo.type;
0486
0487 if (!ai_buscore_setup(sii, cc))
0488 goto exit;
0489
0490
0491 bcma_write32(cc, CHIPCREGOFFS(gpiopullup), 0);
0492 bcma_write32(cc, CHIPCREGOFFS(gpiopulldown), 0);
0493
0494
0495 if (ai_get_cccaps(sih) & CC_CAP_PMU) {
0496 (void)si_pmu_measure_alpclk(sih);
0497 }
0498
0499 return sii;
0500
0501 exit:
0502
0503 return NULL;
0504 }
0505
0506
0507
0508
0509 struct si_pub *
0510 ai_attach(struct bcma_bus *pbus)
0511 {
0512 struct si_info *sii;
0513
0514
0515 sii = kzalloc(sizeof(struct si_info), GFP_ATOMIC);
0516 if (sii == NULL)
0517 return NULL;
0518
0519 if (ai_doattach(sii, pbus) == NULL) {
0520 kfree(sii);
0521 return NULL;
0522 }
0523
0524 return (struct si_pub *) sii;
0525 }
0526
0527
0528 void ai_detach(struct si_pub *sih)
0529 {
0530 struct si_info *sii;
0531
0532 sii = container_of(sih, struct si_info, pub);
0533
0534 kfree(sii);
0535 }
0536
0537
0538
0539
0540 uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val)
0541 {
0542 struct bcma_device *cc;
0543 u32 w;
0544 struct si_info *sii;
0545
0546 sii = container_of(sih, struct si_info, pub);
0547 cc = sii->icbus->drv_cc.core;
0548
0549
0550 if (mask || val)
0551 bcma_maskset32(cc, regoff, ~mask, val);
0552
0553
0554 w = bcma_read32(cc, regoff);
0555
0556 return w;
0557 }
0558
0559
0560 static uint ai_slowclk_src(struct si_pub *sih, struct bcma_device *cc)
0561 {
0562 return SCC_SS_XTAL;
0563 }
0564
0565
0566
0567
0568
0569 static uint ai_slowclk_freq(struct si_pub *sih, bool max_freq,
0570 struct bcma_device *cc)
0571 {
0572 uint div;
0573
0574
0575 div = bcma_read32(cc, CHIPCREGOFFS(system_clk_ctl));
0576 div = 4 * ((div >> SYCC_CD_SHIFT) + 1);
0577 return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);
0578 }
0579
0580 static void
0581 ai_clkctl_setdelay(struct si_pub *sih, struct bcma_device *cc)
0582 {
0583 uint slowmaxfreq, pll_delay, slowclk;
0584 uint pll_on_delay, fref_sel_delay;
0585
0586 pll_delay = PLL_DELAY;
0587
0588
0589
0590
0591
0592
0593
0594 slowclk = ai_slowclk_src(sih, cc);
0595 if (slowclk != SCC_SS_XTAL)
0596 pll_delay += XTAL_ON_DELAY;
0597
0598
0599 slowmaxfreq =
0600 ai_slowclk_freq(sih, false, cc);
0601
0602 pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;
0603 fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;
0604
0605 bcma_write32(cc, CHIPCREGOFFS(pll_on_delay), pll_on_delay);
0606 bcma_write32(cc, CHIPCREGOFFS(fref_sel_delay), fref_sel_delay);
0607 }
0608
0609
0610 void ai_clkctl_init(struct si_pub *sih)
0611 {
0612 struct si_info *sii = container_of(sih, struct si_info, pub);
0613 struct bcma_device *cc;
0614
0615 if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
0616 return;
0617
0618 cc = sii->icbus->drv_cc.core;
0619 if (cc == NULL)
0620 return;
0621
0622
0623 bcma_maskset32(cc, CHIPCREGOFFS(system_clk_ctl), SYCC_CD_MASK,
0624 (ILP_DIV_1MHZ << SYCC_CD_SHIFT));
0625
0626 ai_clkctl_setdelay(sih, cc);
0627 }
0628
0629
0630
0631
0632
0633 u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)
0634 {
0635 struct si_info *sii;
0636 struct bcma_device *cc;
0637 uint slowminfreq;
0638 u16 fpdelay;
0639
0640 sii = container_of(sih, struct si_info, pub);
0641 if (ai_get_cccaps(sih) & CC_CAP_PMU) {
0642 fpdelay = si_pmu_fast_pwrup_delay(sih);
0643 return fpdelay;
0644 }
0645
0646 if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))
0647 return 0;
0648
0649 fpdelay = 0;
0650 cc = sii->icbus->drv_cc.core;
0651 if (cc) {
0652 slowminfreq = ai_slowclk_freq(sih, false, cc);
0653 fpdelay = (((bcma_read32(cc, CHIPCREGOFFS(pll_on_delay)) + 2)
0654 * 1000000) + (slowminfreq - 1)) / slowminfreq;
0655 }
0656 return fpdelay;
0657 }
0658
0659
0660
0661
0662
0663
0664
0665
0666
0667 bool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode)
0668 {
0669 struct si_info *sii;
0670 struct bcma_device *cc;
0671
0672 sii = container_of(sih, struct si_info, pub);
0673
0674 cc = sii->icbus->drv_cc.core;
0675 bcma_core_set_clockmode(cc, mode);
0676 return mode == BCMA_CLKMODE_FAST;
0677 }
0678
0679
0680 void ai_epa_4313war(struct si_pub *sih)
0681 {
0682 struct si_info *sii = container_of(sih, struct si_info, pub);
0683 struct bcma_device *cc;
0684
0685 cc = sii->icbus->drv_cc.core;
0686
0687
0688 bcma_set32(cc, CHIPCREGOFFS(gpiocontrol), GPIO_CTRL_EPA_EN_MASK);
0689 }
0690
0691
0692 bool ai_deviceremoved(struct si_pub *sih)
0693 {
0694 u32 w = 0;
0695 struct si_info *sii;
0696
0697 sii = container_of(sih, struct si_info, pub);
0698
0699 if (sii->icbus->hosttype != BCMA_HOSTTYPE_PCI)
0700 return false;
0701
0702 pci_read_config_dword(sii->pcibus, PCI_VENDOR_ID, &w);
0703 if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)
0704 return true;
0705
0706 return false;
0707 }