Path: blob/main/sys/contrib/dev/broadcom/brcm80211/brcmsmac/aiutils.c
178665 views
/*1* Copyright (c) 2010 Broadcom Corporation2*3* Permission to use, copy, modify, and/or distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES8* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF9* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY10* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES11* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION12* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN13* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.14*15* File contents: support functions for PCI/PCIe16*/1718#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1920#include <linux/delay.h>2122#include <defs.h>23#include <chipcommon.h>24#include <brcmu_utils.h>25#include <brcm_hw_ids.h>26#include <soc.h>27#include "types.h"28#include "pub.h"29#include "pmu.h"30#include "aiutils.h"3132/* slow_clk_ctl */33/* slow clock source mask */34#define SCC_SS_MASK 0x0000000735/* source of slow clock is LPO */36#define SCC_SS_LPO 0x0000000037/* source of slow clock is crystal */38#define SCC_SS_XTAL 0x0000000139/* source of slow clock is PCI */40#define SCC_SS_PCI 0x0000000241/* LPOFreqSel, 1: 160Khz, 0: 32KHz */42#define SCC_LF 0x0000020043/* LPOPowerDown, 1: LPO is disabled, 0: LPO is enabled */44#define SCC_LP 0x0000040045/* ForceSlowClk, 1: sb/cores running on slow clock, 0: power logic control */46#define SCC_FS 0x0000080047/* IgnorePllOffReq, 1/0:48* power logic ignores/honors PLL clock disable requests from core49*/50#define SCC_IP 0x0000100051/* XtalControlEn, 1/0:52* power logic does/doesn't disable crystal when appropriate53*/54#define SCC_XC 0x0000200055/* XtalPU (RO), 1/0: crystal running/disabled */56#define SCC_XP 0x0000400057/* ClockDivider (SlowClk = 1/(4+divisor)) */58#define SCC_CD_MASK 0xffff000059#define SCC_CD_SHIFT 166061/* system_clk_ctl */62/* ILPen: Enable Idle Low Power */63#define SYCC_IE 0x0000000164/* ALPen: Enable Active Low Power */65#define SYCC_AE 0x0000000266/* ForcePLLOn */67#define SYCC_FP 0x0000000468/* Force ALP (or HT if ALPen is not set */69#define SYCC_AR 0x0000000870/* Force HT */71#define SYCC_HR 0x0000001072/* ClkDiv (ILP = 1/(4 * (divisor + 1)) */73#define SYCC_CD_MASK 0xffff000074#define SYCC_CD_SHIFT 167576#define CST4329_SPROM_OTP_SEL_MASK 0x0000000377/* OTP is powered up, use def. CIS, no SPROM */78#define CST4329_DEFCIS_SEL 079/* OTP is powered up, SPROM is present */80#define CST4329_SPROM_SEL 181/* OTP is powered up, no SPROM */82#define CST4329_OTP_SEL 283/* OTP is powered down, SPROM is present */84#define CST4329_OTP_PWRDN 38586#define CST4329_SPI_SDIO_MODE_MASK 0x0000000487#define CST4329_SPI_SDIO_MODE_SHIFT 28889/* 43224 chip-specific ChipControl register bits */90#define CCTRL43224_GPIO_TOGGLE 0x800091/* 12 mA drive strength */92#define CCTRL_43224A0_12MA_LED_DRIVE 0x00F000F093/* 12 mA drive strength for later 43224s */94#define CCTRL_43224B0_12MA_LED_DRIVE 0xF09596/* 43236 Chip specific ChipStatus register bits */97#define CST43236_SFLASH_MASK 0x0000004098#define CST43236_OTP_MASK 0x0000008099#define CST43236_HSIC_MASK 0x00000100 /* USB/HSIC */100#define CST43236_BP_CLK 0x00000200 /* 120/96Mbps */101#define CST43236_BOOT_MASK 0x00001800102#define CST43236_BOOT_SHIFT 11103#define CST43236_BOOT_FROM_SRAM 0 /* boot from SRAM, ARM in reset */104#define CST43236_BOOT_FROM_ROM 1 /* boot from ROM */105#define CST43236_BOOT_FROM_FLASH 2 /* boot from FLASH */106#define CST43236_BOOT_FROM_INVALID 3107108/* 4331 chip-specific ChipControl register bits */109/* 0 disable */110#define CCTRL4331_BT_COEXIST (1<<0)111/* 0 SECI is disabled (JTAG functional) */112#define CCTRL4331_SECI (1<<1)113/* 0 disable */114#define CCTRL4331_EXT_LNA (1<<2)115/* sprom/gpio13-15 mux */116#define CCTRL4331_SPROM_GPIO13_15 (1<<3)117/* 0 ext pa disable, 1 ext pa enabled */118#define CCTRL4331_EXTPA_EN (1<<4)119/* set drive out GPIO_CLK on sprom_cs pin */120#define CCTRL4331_GPIOCLK_ON_SPROMCS (1<<5)121/* use sprom_cs pin as PCIE mdio interface */122#define CCTRL4331_PCIE_MDIO_ON_SPROMCS (1<<6)123/* aband extpa will be at gpio2/5 and sprom_dout */124#define CCTRL4331_EXTPA_ON_GPIO2_5 (1<<7)125/* override core control on pipe_AuxClkEnable */126#define CCTRL4331_OVR_PIPEAUXCLKEN (1<<8)127/* override core control on pipe_AuxPowerDown */128#define CCTRL4331_OVR_PIPEAUXPWRDOWN (1<<9)129/* pcie_auxclkenable */130#define CCTRL4331_PCIE_AUXCLKEN (1<<10)131/* pcie_pipe_pllpowerdown */132#define CCTRL4331_PCIE_PIPE_PLLDOWN (1<<11)133/* enable bt_shd0 at gpio4 */134#define CCTRL4331_BT_SHD0_ON_GPIO4 (1<<16)135/* enable bt_shd1 at gpio5 */136#define CCTRL4331_BT_SHD1_ON_GPIO5 (1<<17)137138/* 4331 Chip specific ChipStatus register bits */139/* crystal frequency 20/40Mhz */140#define CST4331_XTAL_FREQ 0x00000001141#define CST4331_SPROM_PRESENT 0x00000002142#define CST4331_OTP_PRESENT 0x00000004143#define CST4331_LDO_RF 0x00000008144#define CST4331_LDO_PAR 0x00000010145146/* 4319 chip-specific ChipStatus register bits */147#define CST4319_SPI_CPULESSUSB 0x00000001148#define CST4319_SPI_CLK_POL 0x00000002149#define CST4319_SPI_CLK_PH 0x00000008150/* gpio [7:6], SDIO CIS selection */151#define CST4319_SPROM_OTP_SEL_MASK 0x000000c0152#define CST4319_SPROM_OTP_SEL_SHIFT 6153/* use default CIS, OTP is powered up */154#define CST4319_DEFCIS_SEL 0x00000000155/* use SPROM, OTP is powered up */156#define CST4319_SPROM_SEL 0x00000040157/* use OTP, OTP is powered up */158#define CST4319_OTP_SEL 0x00000080159/* use SPROM, OTP is powered down */160#define CST4319_OTP_PWRDN 0x000000c0161/* gpio [8], sdio/usb mode */162#define CST4319_SDIO_USB_MODE 0x00000100163#define CST4319_REMAP_SEL_MASK 0x00000600164#define CST4319_ILPDIV_EN 0x00000800165#define CST4319_XTAL_PD_POL 0x00001000166#define CST4319_LPO_SEL 0x00002000167#define CST4319_RES_INIT_MODE 0x0000c000168/* PALDO is configured with external PNP */169#define CST4319_PALDO_EXTPNP 0x00010000170#define CST4319_CBUCK_MODE_MASK 0x00060000171#define CST4319_CBUCK_MODE_BURST 0x00020000172#define CST4319_CBUCK_MODE_LPBURST 0x00060000173#define CST4319_RCAL_VALID 0x01000000174#define CST4319_RCAL_VALUE_MASK 0x3e000000175#define CST4319_RCAL_VALUE_SHIFT 25176177/* 4336 chip-specific ChipStatus register bits */178#define CST4336_SPI_MODE_MASK 0x00000001179#define CST4336_SPROM_PRESENT 0x00000002180#define CST4336_OTP_PRESENT 0x00000004181#define CST4336_ARMREMAP_0 0x00000008182#define CST4336_ILPDIV_EN_MASK 0x00000010183#define CST4336_ILPDIV_EN_SHIFT 4184#define CST4336_XTAL_PD_POL_MASK 0x00000020185#define CST4336_XTAL_PD_POL_SHIFT 5186#define CST4336_LPO_SEL_MASK 0x00000040187#define CST4336_LPO_SEL_SHIFT 6188#define CST4336_RES_INIT_MODE_MASK 0x00000180189#define CST4336_RES_INIT_MODE_SHIFT 7190#define CST4336_CBUCK_MODE_MASK 0x00000600191#define CST4336_CBUCK_MODE_SHIFT 9192193/* 4313 chip-specific ChipStatus register bits */194#define CST4313_SPROM_PRESENT 1195#define CST4313_OTP_PRESENT 2196#define CST4313_SPROM_OTP_SEL_MASK 0x00000002197#define CST4313_SPROM_OTP_SEL_SHIFT 0198199/* 4313 Chip specific ChipControl register bits */200/* 12 mA drive strength for later 4313 */201#define CCTRL_4313_12MA_LED_DRIVE 0x00000007202203/* Manufacturer Ids */204#define MFGID_ARM 0x43b205#define MFGID_BRCM 0x4bf206#define MFGID_MIPS 0x4a7207208/* Enumeration ROM registers */209#define ER_EROMENTRY 0x000210#define ER_REMAPCONTROL 0xe00211#define ER_REMAPSELECT 0xe04212#define ER_MASTERSELECT 0xe10213#define ER_ITCR 0xf00214#define ER_ITIP 0xf04215216/* Erom entries */217#define ER_TAG 0xe218#define ER_TAG1 0x6219#define ER_VALID 1220#define ER_CI 0221#define ER_MP 2222#define ER_ADD 4223#define ER_END 0xe224#define ER_BAD 0xffffffff225226/* EROM CompIdentA */227#define CIA_MFG_MASK 0xfff00000228#define CIA_MFG_SHIFT 20229#define CIA_CID_MASK 0x000fff00230#define CIA_CID_SHIFT 8231#define CIA_CCL_MASK 0x000000f0232#define CIA_CCL_SHIFT 4233234/* EROM CompIdentB */235#define CIB_REV_MASK 0xff000000236#define CIB_REV_SHIFT 24237#define CIB_NSW_MASK 0x00f80000238#define CIB_NSW_SHIFT 19239#define CIB_NMW_MASK 0x0007c000240#define CIB_NMW_SHIFT 14241#define CIB_NSP_MASK 0x00003e00242#define CIB_NSP_SHIFT 9243#define CIB_NMP_MASK 0x000001f0244#define CIB_NMP_SHIFT 4245246/* EROM AddrDesc */247#define AD_ADDR_MASK 0xfffff000248#define AD_SP_MASK 0x00000f00249#define AD_SP_SHIFT 8250#define AD_ST_MASK 0x000000c0251#define AD_ST_SHIFT 6252#define AD_ST_SLAVE 0x00000000253#define AD_ST_BRIDGE 0x00000040254#define AD_ST_SWRAP 0x00000080255#define AD_ST_MWRAP 0x000000c0256#define AD_SZ_MASK 0x00000030257#define AD_SZ_SHIFT 4258#define AD_SZ_4K 0x00000000259#define AD_SZ_8K 0x00000010260#define AD_SZ_16K 0x00000020261#define AD_SZ_SZD 0x00000030262#define AD_AG32 0x00000008263#define AD_ADDR_ALIGN 0x00000fff264#define AD_SZ_BASE 0x00001000 /* 4KB */265266/* EROM SizeDesc */267#define SD_SZ_MASK 0xfffff000268#define SD_SG32 0x00000008269#define SD_SZ_ALIGN 0x00000fff270271/* PCI config space bit 4 for 4306c0 slow clock source */272#define PCI_CFG_GPIO_SCS 0x10273/* PCI config space GPIO 14 for Xtal power-up */274#define PCI_CFG_GPIO_XTAL 0x40275/* PCI config space GPIO 15 for PLL power-down */276#define PCI_CFG_GPIO_PLL 0x80277278/* power control defines */279#define PLL_DELAY 150 /* us pll on delay */280#define FREF_DELAY 200 /* us fref change delay */281#define XTAL_ON_DELAY 1000 /* us crystal power-on delay */282283/* resetctrl */284#define AIRC_RESET 1285286#define NOREV -1 /* Invalid rev */287288/* GPIO Based LED powersave defines */289#define DEFAULT_GPIO_ONTIME 10 /* Default: 10% on */290#define DEFAULT_GPIO_OFFTIME 90 /* Default: 10% on */291292/* When Srom support present, fields in sromcontrol */293#define SRC_START 0x80000000294#define SRC_BUSY 0x80000000295#define SRC_OPCODE 0x60000000296#define SRC_OP_READ 0x00000000297#define SRC_OP_WRITE 0x20000000298#define SRC_OP_WRDIS 0x40000000299#define SRC_OP_WREN 0x60000000300#define SRC_OTPSEL 0x00000010301#define SRC_LOCK 0x00000008302#define SRC_SIZE_MASK 0x00000006303#define SRC_SIZE_1K 0x00000000304#define SRC_SIZE_4K 0x00000002305#define SRC_SIZE_16K 0x00000004306#define SRC_SIZE_SHIFT 1307#define SRC_PRESENT 0x00000001308309/* External PA enable mask */310#define GPIO_CTRL_EPA_EN_MASK 0x40311312#define DEFAULT_GPIOTIMERVAL \313((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)314315#define BADIDX (SI_MAXCORES + 1)316317#define IS_SIM(chippkg) \318((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))319320#define GOODCOREADDR(x, b) \321(((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \322IS_ALIGNED((x), SI_CORE_SIZE))323324struct aidmp {325u32 oobselina30; /* 0x000 */326u32 oobselina74; /* 0x004 */327u32 PAD[6];328u32 oobselinb30; /* 0x020 */329u32 oobselinb74; /* 0x024 */330u32 PAD[6];331u32 oobselinc30; /* 0x040 */332u32 oobselinc74; /* 0x044 */333u32 PAD[6];334u32 oobselind30; /* 0x060 */335u32 oobselind74; /* 0x064 */336u32 PAD[38];337u32 oobselouta30; /* 0x100 */338u32 oobselouta74; /* 0x104 */339u32 PAD[6];340u32 oobseloutb30; /* 0x120 */341u32 oobseloutb74; /* 0x124 */342u32 PAD[6];343u32 oobseloutc30; /* 0x140 */344u32 oobseloutc74; /* 0x144 */345u32 PAD[6];346u32 oobseloutd30; /* 0x160 */347u32 oobseloutd74; /* 0x164 */348u32 PAD[38];349u32 oobsynca; /* 0x200 */350u32 oobseloutaen; /* 0x204 */351u32 PAD[6];352u32 oobsyncb; /* 0x220 */353u32 oobseloutben; /* 0x224 */354u32 PAD[6];355u32 oobsyncc; /* 0x240 */356u32 oobseloutcen; /* 0x244 */357u32 PAD[6];358u32 oobsyncd; /* 0x260 */359u32 oobseloutden; /* 0x264 */360u32 PAD[38];361u32 oobaextwidth; /* 0x300 */362u32 oobainwidth; /* 0x304 */363u32 oobaoutwidth; /* 0x308 */364u32 PAD[5];365u32 oobbextwidth; /* 0x320 */366u32 oobbinwidth; /* 0x324 */367u32 oobboutwidth; /* 0x328 */368u32 PAD[5];369u32 oobcextwidth; /* 0x340 */370u32 oobcinwidth; /* 0x344 */371u32 oobcoutwidth; /* 0x348 */372u32 PAD[5];373u32 oobdextwidth; /* 0x360 */374u32 oobdinwidth; /* 0x364 */375u32 oobdoutwidth; /* 0x368 */376u32 PAD[37];377u32 ioctrlset; /* 0x400 */378u32 ioctrlclear; /* 0x404 */379u32 ioctrl; /* 0x408 */380u32 PAD[61];381u32 iostatus; /* 0x500 */382u32 PAD[127];383u32 ioctrlwidth; /* 0x700 */384u32 iostatuswidth; /* 0x704 */385u32 PAD[62];386u32 resetctrl; /* 0x800 */387u32 resetstatus; /* 0x804 */388u32 resetreadid; /* 0x808 */389u32 resetwriteid; /* 0x80c */390u32 PAD[60];391u32 errlogctrl; /* 0x900 */392u32 errlogdone; /* 0x904 */393u32 errlogstatus; /* 0x908 */394u32 errlogaddrlo; /* 0x90c */395u32 errlogaddrhi; /* 0x910 */396u32 errlogid; /* 0x914 */397u32 errloguser; /* 0x918 */398u32 errlogflags; /* 0x91c */399u32 PAD[56];400u32 intstatus; /* 0xa00 */401u32 PAD[127];402u32 config; /* 0xe00 */403u32 PAD[63];404u32 itcr; /* 0xf00 */405u32 PAD[3];406u32 itipooba; /* 0xf10 */407u32 itipoobb; /* 0xf14 */408u32 itipoobc; /* 0xf18 */409u32 itipoobd; /* 0xf1c */410u32 PAD[4];411u32 itipoobaout; /* 0xf30 */412u32 itipoobbout; /* 0xf34 */413u32 itipoobcout; /* 0xf38 */414u32 itipoobdout; /* 0xf3c */415u32 PAD[4];416u32 itopooba; /* 0xf50 */417u32 itopoobb; /* 0xf54 */418u32 itopoobc; /* 0xf58 */419u32 itopoobd; /* 0xf5c */420u32 PAD[4];421u32 itopoobain; /* 0xf70 */422u32 itopoobbin; /* 0xf74 */423u32 itopoobcin; /* 0xf78 */424u32 itopoobdin; /* 0xf7c */425u32 PAD[4];426u32 itopreset; /* 0xf90 */427u32 PAD[15];428u32 peripherialid4; /* 0xfd0 */429u32 peripherialid5; /* 0xfd4 */430u32 peripherialid6; /* 0xfd8 */431u32 peripherialid7; /* 0xfdc */432u32 peripherialid0; /* 0xfe0 */433u32 peripherialid1; /* 0xfe4 */434u32 peripherialid2; /* 0xfe8 */435u32 peripherialid3; /* 0xfec */436u32 componentid0; /* 0xff0 */437u32 componentid1; /* 0xff4 */438u32 componentid2; /* 0xff8 */439u32 componentid3; /* 0xffc */440};441442static bool443ai_buscore_setup(struct si_info *sii, struct bcma_device *cc)444{445/* no cores found, bail out */446if (cc->bus->nr_cores == 0)447return false;448449/* get chipcommon rev */450sii->pub.ccrev = cc->id.rev;451452/* get chipcommon chipstatus */453sii->chipst = bcma_read32(cc, CHIPCREGOFFS(chipstatus));454455/* get chipcommon capabilities */456sii->pub.cccaps = bcma_read32(cc, CHIPCREGOFFS(capabilities));457458/* get pmu rev and caps */459if (ai_get_cccaps(&sii->pub) & CC_CAP_PMU) {460sii->pub.pmucaps = bcma_read32(cc,461CHIPCREGOFFS(pmucapabilities));462sii->pub.pmurev = sii->pub.pmucaps & PCAP_REV_MASK;463}464465return true;466}467468static struct si_info *ai_doattach(struct si_info *sii,469struct bcma_bus *pbus)470{471struct si_pub *sih = &sii->pub;472struct bcma_device *cc;473474sii->icbus = pbus;475sii->pcibus = pbus->host_pci;476477/* switch to Chipcommon core */478cc = pbus->drv_cc.core;479480sih->chip = pbus->chipinfo.id;481sih->chiprev = pbus->chipinfo.rev;482sih->chippkg = pbus->chipinfo.pkg;483sih->boardvendor = pbus->boardinfo.vendor;484sih->boardtype = pbus->boardinfo.type;485486if (!ai_buscore_setup(sii, cc))487goto exit;488489/* === NVRAM, clock is ready === */490bcma_write32(cc, CHIPCREGOFFS(gpiopullup), 0);491bcma_write32(cc, CHIPCREGOFFS(gpiopulldown), 0);492493/* PMU specific initializations */494if (ai_get_cccaps(sih) & CC_CAP_PMU) {495(void)si_pmu_measure_alpclk(sih);496}497498return sii;499500exit:501502return NULL;503}504505/*506* Allocate a si handle and do the attach.507*/508struct si_pub *509ai_attach(struct bcma_bus *pbus)510{511struct si_info *sii;512513/* alloc struct si_info */514sii = kzalloc(sizeof(*sii), GFP_ATOMIC);515if (sii == NULL)516return NULL;517518if (ai_doattach(sii, pbus) == NULL) {519kfree(sii);520return NULL;521}522523return (struct si_pub *) sii;524}525526/* may be called with core in reset */527void ai_detach(struct si_pub *sih)528{529struct si_info *sii;530531sii = container_of(sih, struct si_info, pub);532533kfree(sii);534}535536/*537* read/modify chipcommon core register.538*/539uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val)540{541struct bcma_device *cc;542u32 w;543struct si_info *sii;544545sii = container_of(sih, struct si_info, pub);546cc = sii->icbus->drv_cc.core;547548/* mask and set */549if (mask || val)550bcma_maskset32(cc, regoff, ~mask, val);551552/* readback */553w = bcma_read32(cc, regoff);554555return w;556}557558/* return the slow clock source - LPO, XTAL, or PCI */559static uint ai_slowclk_src(struct si_pub *sih, struct bcma_device *cc)560{561return SCC_SS_XTAL;562}563564/*565* return the ILP (slowclock) min or max frequency566* precondition: we've established the chip has dynamic clk control567*/568static uint ai_slowclk_freq(struct si_pub *sih, bool max_freq,569struct bcma_device *cc)570{571uint div;572573/* Chipc rev 10 is InstaClock */574div = bcma_read32(cc, CHIPCREGOFFS(system_clk_ctl));575div = 4 * ((div >> SYCC_CD_SHIFT) + 1);576return max_freq ? XTALMAXFREQ : (XTALMINFREQ / div);577}578579static void580ai_clkctl_setdelay(struct si_pub *sih, struct bcma_device *cc)581{582uint slowmaxfreq, pll_delay, slowclk;583uint pll_on_delay, fref_sel_delay;584585pll_delay = PLL_DELAY;586587/*588* If the slow clock is not sourced by the xtal then589* add the xtal_on_delay since the xtal will also be590* powered down by dynamic clk control logic.591*/592593slowclk = ai_slowclk_src(sih, cc);594if (slowclk != SCC_SS_XTAL)595pll_delay += XTAL_ON_DELAY;596597/* Starting with 4318 it is ILP that is used for the delays */598slowmaxfreq =599ai_slowclk_freq(sih, false, cc);600601pll_on_delay = ((slowmaxfreq * pll_delay) + 999999) / 1000000;602fref_sel_delay = ((slowmaxfreq * FREF_DELAY) + 999999) / 1000000;603604bcma_write32(cc, CHIPCREGOFFS(pll_on_delay), pll_on_delay);605bcma_write32(cc, CHIPCREGOFFS(fref_sel_delay), fref_sel_delay);606}607608/* initialize power control delay registers */609void ai_clkctl_init(struct si_pub *sih)610{611struct si_info *sii = container_of(sih, struct si_info, pub);612struct bcma_device *cc;613614if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))615return;616617cc = sii->icbus->drv_cc.core;618if (cc == NULL)619return;620621/* set all Instaclk chip ILP to 1 MHz */622bcma_maskset32(cc, CHIPCREGOFFS(system_clk_ctl), SYCC_CD_MASK,623(ILP_DIV_1MHZ << SYCC_CD_SHIFT));624625ai_clkctl_setdelay(sih, cc);626}627628/*629* return the value suitable for writing to the630* dot11 core FAST_PWRUP_DELAY register631*/632u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih)633{634struct si_info *sii;635struct bcma_device *cc;636uint slowminfreq;637u16 fpdelay;638639sii = container_of(sih, struct si_info, pub);640if (ai_get_cccaps(sih) & CC_CAP_PMU) {641fpdelay = si_pmu_fast_pwrup_delay(sih);642return fpdelay;643}644645if (!(ai_get_cccaps(sih) & CC_CAP_PWR_CTL))646return 0;647648fpdelay = 0;649cc = sii->icbus->drv_cc.core;650if (cc) {651slowminfreq = ai_slowclk_freq(sih, false, cc);652fpdelay = (((bcma_read32(cc, CHIPCREGOFFS(pll_on_delay)) + 2)653* 1000000) + (slowminfreq - 1)) / slowminfreq;654}655return fpdelay;656}657658/*659* clock control policy function through chipcommon660*661* set dynamic clk control mode (forceslow, forcefast, dynamic)662* returns true if we are forcing fast clock663* this is a wrapper over the next internal function664* to allow flexible policy settings for outside caller665*/666bool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode)667{668struct si_info *sii;669struct bcma_device *cc;670671sii = container_of(sih, struct si_info, pub);672673cc = sii->icbus->drv_cc.core;674bcma_core_set_clockmode(cc, mode);675return mode == BCMA_CLKMODE_FAST;676}677678/* Enable BT-COEX & Ex-PA for 4313 */679void ai_epa_4313war(struct si_pub *sih)680{681struct si_info *sii = container_of(sih, struct si_info, pub);682struct bcma_device *cc;683684cc = sii->icbus->drv_cc.core;685686/* EPA Fix */687bcma_set32(cc, CHIPCREGOFFS(gpiocontrol), GPIO_CTRL_EPA_EN_MASK);688}689690/* check if the device is removed */691bool ai_deviceremoved(struct si_pub *sih)692{693u32 w = 0;694struct si_info *sii;695696sii = container_of(sih, struct si_info, pub);697698if (sii->icbus->hosttype != BCMA_HOSTTYPE_PCI)699return false;700701pci_read_config_dword(sii->pcibus, PCI_VENDOR_ID, &w);702if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM)703return true;704705return false;706}707708709