162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright (c) 2011 Broadcom Corporation 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 562306a36Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 662306a36Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 962306a36Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1062306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 1162306a36Sopenharmony_ci * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1262306a36Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 1362306a36Sopenharmony_ci * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 1462306a36Sopenharmony_ci * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#ifndef _BRCM_AIUTILS_H_ 1862306a36Sopenharmony_ci#define _BRCM_AIUTILS_H_ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#include <linux/bcma/bcma.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#include "types.h" 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* 2562306a36Sopenharmony_ci * SOC Interconnect Address Map. 2662306a36Sopenharmony_ci * All regions may not exist on all chips. 2762306a36Sopenharmony_ci */ 2862306a36Sopenharmony_ci/* each core gets 4Kbytes for registers */ 2962306a36Sopenharmony_ci#define SI_CORE_SIZE 0x1000 3062306a36Sopenharmony_ci/* 3162306a36Sopenharmony_ci * Max cores (this is arbitrary, for software 3262306a36Sopenharmony_ci * convenience and could be changed if we 3362306a36Sopenharmony_ci * make any larger chips 3462306a36Sopenharmony_ci */ 3562306a36Sopenharmony_ci#define SI_MAXCORES 16 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci/* Client Mode sb2pcitranslation2 size in bytes */ 3862306a36Sopenharmony_ci#define SI_PCI_DMA_SZ 0x40000000 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), high 32 bits */ 4162306a36Sopenharmony_ci#define SI_PCIE_DMA_H32 0x80000000 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* chipcommon being the first core: */ 4462306a36Sopenharmony_ci#define SI_CC_IDX 0 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/* SOC Interconnect types (aka chip types) */ 4762306a36Sopenharmony_ci#define SOCI_AI 1 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* A register that is common to all cores to 5062306a36Sopenharmony_ci * communicate w/PMU regarding clock control. 5162306a36Sopenharmony_ci */ 5262306a36Sopenharmony_ci#define SI_CLK_CTL_ST 0x1e0 /* clock control and status */ 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci/* clk_ctl_st register */ 5562306a36Sopenharmony_ci#define CCS_FORCEALP 0x00000001 /* force ALP request */ 5662306a36Sopenharmony_ci#define CCS_FORCEHT 0x00000002 /* force HT request */ 5762306a36Sopenharmony_ci#define CCS_FORCEILP 0x00000004 /* force ILP request */ 5862306a36Sopenharmony_ci#define CCS_ALPAREQ 0x00000008 /* ALP Avail Request */ 5962306a36Sopenharmony_ci#define CCS_HTAREQ 0x00000010 /* HT Avail Request */ 6062306a36Sopenharmony_ci#define CCS_FORCEHWREQOFF 0x00000020 /* Force HW Clock Request Off */ 6162306a36Sopenharmony_ci#define CCS_ERSRC_REQ_MASK 0x00000700 /* external resource requests */ 6262306a36Sopenharmony_ci#define CCS_ERSRC_REQ_SHIFT 8 6362306a36Sopenharmony_ci#define CCS_ALPAVAIL 0x00010000 /* ALP is available */ 6462306a36Sopenharmony_ci#define CCS_HTAVAIL 0x00020000 /* HT is available */ 6562306a36Sopenharmony_ci#define CCS_BP_ON_APL 0x00040000 /* RO: running on ALP clock */ 6662306a36Sopenharmony_ci#define CCS_BP_ON_HT 0x00080000 /* RO: running on HT clock */ 6762306a36Sopenharmony_ci#define CCS_ERSRC_STS_MASK 0x07000000 /* external resource status */ 6862306a36Sopenharmony_ci#define CCS_ERSRC_STS_SHIFT 24 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* HT avail in chipc and pcmcia on 4328a0 */ 7162306a36Sopenharmony_ci#define CCS0_HTAVAIL 0x00010000 7262306a36Sopenharmony_ci/* ALP avail in chipc and pcmcia on 4328a0 */ 7362306a36Sopenharmony_ci#define CCS0_ALPAVAIL 0x00020000 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* Not really related to SOC Interconnect, but a couple of software 7662306a36Sopenharmony_ci * conventions for the use the flash space: 7762306a36Sopenharmony_ci */ 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci/* Minumum amount of flash we support */ 8062306a36Sopenharmony_ci#define FLASH_MIN 0x00020000 /* Minimum flash size */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#define CC_SROM_OTP 0x800 /* SROM/OTP address space */ 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* gpiotimerval */ 8562306a36Sopenharmony_ci#define GPIO_ONTIME_SHIFT 16 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* Fields in clkdiv */ 8862306a36Sopenharmony_ci#define CLKD_OTP 0x000f0000 8962306a36Sopenharmony_ci#define CLKD_OTP_SHIFT 16 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci/* dynamic clock control defines */ 9262306a36Sopenharmony_ci#define LPOMINFREQ 25000 /* low power oscillator min */ 9362306a36Sopenharmony_ci#define LPOMAXFREQ 43000 /* low power oscillator max */ 9462306a36Sopenharmony_ci#define XTALMINFREQ 19800000 /* 20 MHz - 1% */ 9562306a36Sopenharmony_ci#define XTALMAXFREQ 20200000 /* 20 MHz + 1% */ 9662306a36Sopenharmony_ci#define PCIMINFREQ 25000000 /* 25 MHz */ 9762306a36Sopenharmony_ci#define PCIMAXFREQ 34000000 /* 33 MHz + fudge */ 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci#define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */ 10062306a36Sopenharmony_ci#define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */ 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci/* clkctl xtal what flags */ 10362306a36Sopenharmony_ci#define XTAL 0x1 /* primary crystal oscillator (2050) */ 10462306a36Sopenharmony_ci#define PLL 0x2 /* main chip pll */ 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci/* GPIO usage priorities */ 10762306a36Sopenharmony_ci#define GPIO_DRV_PRIORITY 0 /* Driver */ 10862306a36Sopenharmony_ci#define GPIO_APP_PRIORITY 1 /* Application */ 10962306a36Sopenharmony_ci#define GPIO_HI_PRIORITY 2 /* Highest priority. Ignore GPIO 11062306a36Sopenharmony_ci * reservation 11162306a36Sopenharmony_ci */ 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci/* GPIO pull up/down */ 11462306a36Sopenharmony_ci#define GPIO_PULLUP 0 11562306a36Sopenharmony_ci#define GPIO_PULLDN 1 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci/* GPIO event regtype */ 11862306a36Sopenharmony_ci#define GPIO_REGEVT 0 /* GPIO register event */ 11962306a36Sopenharmony_ci#define GPIO_REGEVT_INTMSK 1 /* GPIO register event int mask */ 12062306a36Sopenharmony_ci#define GPIO_REGEVT_INTPOL 2 /* GPIO register event int polarity */ 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci/* device path */ 12362306a36Sopenharmony_ci#define SI_DEVPATH_BUFSZ 16 /* min buffer size in bytes */ 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* SI routine enumeration: to be used by update function with multiple hooks */ 12662306a36Sopenharmony_ci#define SI_DOATTACH 1 12762306a36Sopenharmony_ci#define SI_PCIDOWN 2 12862306a36Sopenharmony_ci#define SI_PCIUP 3 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci/* 13162306a36Sopenharmony_ci * Data structure to export all chip specific common variables 13262306a36Sopenharmony_ci * public (read-only) portion of aiutils handle returned by si_attach() 13362306a36Sopenharmony_ci */ 13462306a36Sopenharmony_cistruct si_pub { 13562306a36Sopenharmony_ci int ccrev; /* chip common core rev */ 13662306a36Sopenharmony_ci u32 cccaps; /* chip common capabilities */ 13762306a36Sopenharmony_ci int pmurev; /* pmu core rev */ 13862306a36Sopenharmony_ci u32 pmucaps; /* pmu capabilities */ 13962306a36Sopenharmony_ci uint boardtype; /* board type */ 14062306a36Sopenharmony_ci uint boardvendor; /* board vendor */ 14162306a36Sopenharmony_ci uint chip; /* chip number */ 14262306a36Sopenharmony_ci uint chiprev; /* chip revision */ 14362306a36Sopenharmony_ci uint chippkg; /* chip package option */ 14462306a36Sopenharmony_ci}; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_cistruct pci_dev; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci/* misc si info needed by some of the routines */ 14962306a36Sopenharmony_cistruct si_info { 15062306a36Sopenharmony_ci struct si_pub pub; /* back plane public state (must be first) */ 15162306a36Sopenharmony_ci struct bcma_bus *icbus; /* handle to soc interconnect bus */ 15262306a36Sopenharmony_ci struct pci_dev *pcibus; /* handle to pci bus */ 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci u32 chipst; /* chip status */ 15562306a36Sopenharmony_ci}; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/* 15862306a36Sopenharmony_ci * Many of the routines below take an 'sih' handle as their first arg. 15962306a36Sopenharmony_ci * Allocate this by calling si_attach(). Free it by calling si_detach(). 16062306a36Sopenharmony_ci * At any one time, the sih is logically focused on one particular si core 16162306a36Sopenharmony_ci * (the "current core"). 16262306a36Sopenharmony_ci * Use si_setcore() or si_setcoreidx() to change the association to another core 16362306a36Sopenharmony_ci */ 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci/* AMBA Interconnect exported externs */ 16762306a36Sopenharmony_ciu32 ai_core_cflags(struct bcma_device *core, u32 mask, u32 val); 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci/* === exported functions === */ 17062306a36Sopenharmony_cistruct si_pub *ai_attach(struct bcma_bus *pbus); 17162306a36Sopenharmony_civoid ai_detach(struct si_pub *sih); 17262306a36Sopenharmony_ciuint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val); 17362306a36Sopenharmony_civoid ai_clkctl_init(struct si_pub *sih); 17462306a36Sopenharmony_ciu16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih); 17562306a36Sopenharmony_cibool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode); 17662306a36Sopenharmony_cibool ai_deviceremoved(struct si_pub *sih); 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci/* Enable Ex-PA for 4313 */ 17962306a36Sopenharmony_civoid ai_epa_4313war(struct si_pub *sih); 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_cistatic inline u32 ai_get_cccaps(struct si_pub *sih) 18262306a36Sopenharmony_ci{ 18362306a36Sopenharmony_ci return sih->cccaps; 18462306a36Sopenharmony_ci} 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_cistatic inline int ai_get_pmurev(struct si_pub *sih) 18762306a36Sopenharmony_ci{ 18862306a36Sopenharmony_ci return sih->pmurev; 18962306a36Sopenharmony_ci} 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_cistatic inline u32 ai_get_pmucaps(struct si_pub *sih) 19262306a36Sopenharmony_ci{ 19362306a36Sopenharmony_ci return sih->pmucaps; 19462306a36Sopenharmony_ci} 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_cistatic inline uint ai_get_boardtype(struct si_pub *sih) 19762306a36Sopenharmony_ci{ 19862306a36Sopenharmony_ci return sih->boardtype; 19962306a36Sopenharmony_ci} 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_cistatic inline uint ai_get_boardvendor(struct si_pub *sih) 20262306a36Sopenharmony_ci{ 20362306a36Sopenharmony_ci return sih->boardvendor; 20462306a36Sopenharmony_ci} 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_cistatic inline uint ai_get_chip_id(struct si_pub *sih) 20762306a36Sopenharmony_ci{ 20862306a36Sopenharmony_ci return sih->chip; 20962306a36Sopenharmony_ci} 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_cistatic inline uint ai_get_chiprev(struct si_pub *sih) 21262306a36Sopenharmony_ci{ 21362306a36Sopenharmony_ci return sih->chiprev; 21462306a36Sopenharmony_ci} 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cistatic inline uint ai_get_chippkg(struct si_pub *sih) 21762306a36Sopenharmony_ci{ 21862306a36Sopenharmony_ci return sih->chippkg; 21962306a36Sopenharmony_ci} 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci#endif /* _BRCM_AIUTILS_H_ */ 222