18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2011 Broadcom Corporation 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 118c2ecf20Sopenharmony_ci * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 138c2ecf20Sopenharmony_ci * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 148c2ecf20Sopenharmony_ci * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#ifndef _BRCM_AIUTILS_H_ 188c2ecf20Sopenharmony_ci#define _BRCM_AIUTILS_H_ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include <linux/bcma/bcma.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#include "types.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* 258c2ecf20Sopenharmony_ci * SOC Interconnect Address Map. 268c2ecf20Sopenharmony_ci * All regions may not exist on all chips. 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci/* each core gets 4Kbytes for registers */ 298c2ecf20Sopenharmony_ci#define SI_CORE_SIZE 0x1000 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * Max cores (this is arbitrary, for software 328c2ecf20Sopenharmony_ci * convenience and could be changed if we 338c2ecf20Sopenharmony_ci * make any larger chips 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_ci#define SI_MAXCORES 16 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* Client Mode sb2pcitranslation2 size in bytes */ 388c2ecf20Sopenharmony_ci#define SI_PCI_DMA_SZ 0x40000000 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* PCIE Client Mode sb2pcitranslation2 (2 ZettaBytes), high 32 bits */ 418c2ecf20Sopenharmony_ci#define SI_PCIE_DMA_H32 0x80000000 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* chipcommon being the first core: */ 448c2ecf20Sopenharmony_ci#define SI_CC_IDX 0 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* SOC Interconnect types (aka chip types) */ 478c2ecf20Sopenharmony_ci#define SOCI_AI 1 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* A register that is common to all cores to 508c2ecf20Sopenharmony_ci * communicate w/PMU regarding clock control. 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci#define SI_CLK_CTL_ST 0x1e0 /* clock control and status */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci/* clk_ctl_st register */ 558c2ecf20Sopenharmony_ci#define CCS_FORCEALP 0x00000001 /* force ALP request */ 568c2ecf20Sopenharmony_ci#define CCS_FORCEHT 0x00000002 /* force HT request */ 578c2ecf20Sopenharmony_ci#define CCS_FORCEILP 0x00000004 /* force ILP request */ 588c2ecf20Sopenharmony_ci#define CCS_ALPAREQ 0x00000008 /* ALP Avail Request */ 598c2ecf20Sopenharmony_ci#define CCS_HTAREQ 0x00000010 /* HT Avail Request */ 608c2ecf20Sopenharmony_ci#define CCS_FORCEHWREQOFF 0x00000020 /* Force HW Clock Request Off */ 618c2ecf20Sopenharmony_ci#define CCS_ERSRC_REQ_MASK 0x00000700 /* external resource requests */ 628c2ecf20Sopenharmony_ci#define CCS_ERSRC_REQ_SHIFT 8 638c2ecf20Sopenharmony_ci#define CCS_ALPAVAIL 0x00010000 /* ALP is available */ 648c2ecf20Sopenharmony_ci#define CCS_HTAVAIL 0x00020000 /* HT is available */ 658c2ecf20Sopenharmony_ci#define CCS_BP_ON_APL 0x00040000 /* RO: running on ALP clock */ 668c2ecf20Sopenharmony_ci#define CCS_BP_ON_HT 0x00080000 /* RO: running on HT clock */ 678c2ecf20Sopenharmony_ci#define CCS_ERSRC_STS_MASK 0x07000000 /* external resource status */ 688c2ecf20Sopenharmony_ci#define CCS_ERSRC_STS_SHIFT 24 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* HT avail in chipc and pcmcia on 4328a0 */ 718c2ecf20Sopenharmony_ci#define CCS0_HTAVAIL 0x00010000 728c2ecf20Sopenharmony_ci/* ALP avail in chipc and pcmcia on 4328a0 */ 738c2ecf20Sopenharmony_ci#define CCS0_ALPAVAIL 0x00020000 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* Not really related to SOC Interconnect, but a couple of software 768c2ecf20Sopenharmony_ci * conventions for the use the flash space: 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/* Minumum amount of flash we support */ 808c2ecf20Sopenharmony_ci#define FLASH_MIN 0x00020000 /* Minimum flash size */ 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define CC_SROM_OTP 0x800 /* SROM/OTP address space */ 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* gpiotimerval */ 858c2ecf20Sopenharmony_ci#define GPIO_ONTIME_SHIFT 16 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci/* Fields in clkdiv */ 888c2ecf20Sopenharmony_ci#define CLKD_OTP 0x000f0000 898c2ecf20Sopenharmony_ci#define CLKD_OTP_SHIFT 16 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/* dynamic clock control defines */ 928c2ecf20Sopenharmony_ci#define LPOMINFREQ 25000 /* low power oscillator min */ 938c2ecf20Sopenharmony_ci#define LPOMAXFREQ 43000 /* low power oscillator max */ 948c2ecf20Sopenharmony_ci#define XTALMINFREQ 19800000 /* 20 MHz - 1% */ 958c2ecf20Sopenharmony_ci#define XTALMAXFREQ 20200000 /* 20 MHz + 1% */ 968c2ecf20Sopenharmony_ci#define PCIMINFREQ 25000000 /* 25 MHz */ 978c2ecf20Sopenharmony_ci#define PCIMAXFREQ 34000000 /* 33 MHz + fudge */ 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */ 1008c2ecf20Sopenharmony_ci#define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */ 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* clkctl xtal what flags */ 1038c2ecf20Sopenharmony_ci#define XTAL 0x1 /* primary crystal oscillator (2050) */ 1048c2ecf20Sopenharmony_ci#define PLL 0x2 /* main chip pll */ 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* GPIO usage priorities */ 1078c2ecf20Sopenharmony_ci#define GPIO_DRV_PRIORITY 0 /* Driver */ 1088c2ecf20Sopenharmony_ci#define GPIO_APP_PRIORITY 1 /* Application */ 1098c2ecf20Sopenharmony_ci#define GPIO_HI_PRIORITY 2 /* Highest priority. Ignore GPIO 1108c2ecf20Sopenharmony_ci * reservation 1118c2ecf20Sopenharmony_ci */ 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* GPIO pull up/down */ 1148c2ecf20Sopenharmony_ci#define GPIO_PULLUP 0 1158c2ecf20Sopenharmony_ci#define GPIO_PULLDN 1 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci/* GPIO event regtype */ 1188c2ecf20Sopenharmony_ci#define GPIO_REGEVT 0 /* GPIO register event */ 1198c2ecf20Sopenharmony_ci#define GPIO_REGEVT_INTMSK 1 /* GPIO register event int mask */ 1208c2ecf20Sopenharmony_ci#define GPIO_REGEVT_INTPOL 2 /* GPIO register event int polarity */ 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* device path */ 1238c2ecf20Sopenharmony_ci#define SI_DEVPATH_BUFSZ 16 /* min buffer size in bytes */ 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* SI routine enumeration: to be used by update function with multiple hooks */ 1268c2ecf20Sopenharmony_ci#define SI_DOATTACH 1 1278c2ecf20Sopenharmony_ci#define SI_PCIDOWN 2 1288c2ecf20Sopenharmony_ci#define SI_PCIUP 3 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/* 1318c2ecf20Sopenharmony_ci * Data structure to export all chip specific common variables 1328c2ecf20Sopenharmony_ci * public (read-only) portion of aiutils handle returned by si_attach() 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_cistruct si_pub { 1358c2ecf20Sopenharmony_ci int ccrev; /* chip common core rev */ 1368c2ecf20Sopenharmony_ci u32 cccaps; /* chip common capabilities */ 1378c2ecf20Sopenharmony_ci int pmurev; /* pmu core rev */ 1388c2ecf20Sopenharmony_ci u32 pmucaps; /* pmu capabilities */ 1398c2ecf20Sopenharmony_ci uint boardtype; /* board type */ 1408c2ecf20Sopenharmony_ci uint boardvendor; /* board vendor */ 1418c2ecf20Sopenharmony_ci uint chip; /* chip number */ 1428c2ecf20Sopenharmony_ci uint chiprev; /* chip revision */ 1438c2ecf20Sopenharmony_ci uint chippkg; /* chip package option */ 1448c2ecf20Sopenharmony_ci}; 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistruct pci_dev; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_cistruct gpioh_item { 1498c2ecf20Sopenharmony_ci void *arg; 1508c2ecf20Sopenharmony_ci bool level; 1518c2ecf20Sopenharmony_ci void (*handler) (u32 stat, void *arg); 1528c2ecf20Sopenharmony_ci u32 event; 1538c2ecf20Sopenharmony_ci struct gpioh_item *next; 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci/* misc si info needed by some of the routines */ 1578c2ecf20Sopenharmony_cistruct si_info { 1588c2ecf20Sopenharmony_ci struct si_pub pub; /* back plane public state (must be first) */ 1598c2ecf20Sopenharmony_ci struct bcma_bus *icbus; /* handle to soc interconnect bus */ 1608c2ecf20Sopenharmony_ci struct pci_dev *pcibus; /* handle to pci bus */ 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci u32 chipst; /* chip status */ 1638c2ecf20Sopenharmony_ci}; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci/* 1668c2ecf20Sopenharmony_ci * Many of the routines below take an 'sih' handle as their first arg. 1678c2ecf20Sopenharmony_ci * Allocate this by calling si_attach(). Free it by calling si_detach(). 1688c2ecf20Sopenharmony_ci * At any one time, the sih is logically focused on one particular si core 1698c2ecf20Sopenharmony_ci * (the "current core"). 1708c2ecf20Sopenharmony_ci * Use si_setcore() or si_setcoreidx() to change the association to another core 1718c2ecf20Sopenharmony_ci */ 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci/* AMBA Interconnect exported externs */ 1758c2ecf20Sopenharmony_ciu32 ai_core_cflags(struct bcma_device *core, u32 mask, u32 val); 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci/* === exported functions === */ 1788c2ecf20Sopenharmony_cistruct si_pub *ai_attach(struct bcma_bus *pbus); 1798c2ecf20Sopenharmony_civoid ai_detach(struct si_pub *sih); 1808c2ecf20Sopenharmony_ciuint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val); 1818c2ecf20Sopenharmony_civoid ai_clkctl_init(struct si_pub *sih); 1828c2ecf20Sopenharmony_ciu16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih); 1838c2ecf20Sopenharmony_cibool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode); 1848c2ecf20Sopenharmony_cibool ai_deviceremoved(struct si_pub *sih); 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/* Enable Ex-PA for 4313 */ 1878c2ecf20Sopenharmony_civoid ai_epa_4313war(struct si_pub *sih); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_cistatic inline u32 ai_get_cccaps(struct si_pub *sih) 1908c2ecf20Sopenharmony_ci{ 1918c2ecf20Sopenharmony_ci return sih->cccaps; 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistatic inline int ai_get_pmurev(struct si_pub *sih) 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci return sih->pmurev; 1978c2ecf20Sopenharmony_ci} 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_cistatic inline u32 ai_get_pmucaps(struct si_pub *sih) 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci return sih->pmucaps; 2028c2ecf20Sopenharmony_ci} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistatic inline uint ai_get_boardtype(struct si_pub *sih) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci return sih->boardtype; 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic inline uint ai_get_boardvendor(struct si_pub *sih) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci return sih->boardvendor; 2128c2ecf20Sopenharmony_ci} 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_cistatic inline uint ai_get_chip_id(struct si_pub *sih) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci return sih->chip; 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic inline uint ai_get_chiprev(struct si_pub *sih) 2208c2ecf20Sopenharmony_ci{ 2218c2ecf20Sopenharmony_ci return sih->chiprev; 2228c2ecf20Sopenharmony_ci} 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cistatic inline uint ai_get_chippkg(struct si_pub *sih) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci return sih->chippkg; 2278c2ecf20Sopenharmony_ci} 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci#endif /* _BRCM_AIUTILS_H_ */ 230