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#include <linux/delay.h> 188c2ecf20Sopenharmony_ci#include <linux/io.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#include <brcm_hw_ids.h> 218c2ecf20Sopenharmony_ci#include <chipcommon.h> 228c2ecf20Sopenharmony_ci#include <brcmu_utils.h> 238c2ecf20Sopenharmony_ci#include "pub.h" 248c2ecf20Sopenharmony_ci#include "aiutils.h" 258c2ecf20Sopenharmony_ci#include "pmu.h" 268c2ecf20Sopenharmony_ci#include "soc.h" 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * external LPO crystal frequency 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci#define EXT_ILP_HZ 32768 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* 348c2ecf20Sopenharmony_ci * Duration for ILP clock frequency measurment in milliseconds 358c2ecf20Sopenharmony_ci * 368c2ecf20Sopenharmony_ci * remark: 1000 must be an integer multiple of this duration 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci#define ILP_CALC_DUR 10 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* Fields in pmucontrol */ 418c2ecf20Sopenharmony_ci#define PCTL_ILP_DIV_MASK 0xffff0000 428c2ecf20Sopenharmony_ci#define PCTL_ILP_DIV_SHIFT 16 438c2ecf20Sopenharmony_ci#define PCTL_PLL_PLLCTL_UPD 0x00000400 /* rev 2 */ 448c2ecf20Sopenharmony_ci#define PCTL_NOILP_ON_WAIT 0x00000200 /* rev 1 */ 458c2ecf20Sopenharmony_ci#define PCTL_HT_REQ_EN 0x00000100 468c2ecf20Sopenharmony_ci#define PCTL_ALP_REQ_EN 0x00000080 478c2ecf20Sopenharmony_ci#define PCTL_XTALFREQ_MASK 0x0000007c 488c2ecf20Sopenharmony_ci#define PCTL_XTALFREQ_SHIFT 2 498c2ecf20Sopenharmony_ci#define PCTL_ILP_DIV_EN 0x00000002 508c2ecf20Sopenharmony_ci#define PCTL_LPO_SEL 0x00000001 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* ILP clock */ 538c2ecf20Sopenharmony_ci#define ILP_CLOCK 32000 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* ALP clock on pre-PMU chips */ 568c2ecf20Sopenharmony_ci#define ALP_CLOCK 20000000 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* pmustatus */ 598c2ecf20Sopenharmony_ci#define PST_EXTLPOAVAIL 0x0100 608c2ecf20Sopenharmony_ci#define PST_WDRESET 0x0080 618c2ecf20Sopenharmony_ci#define PST_INTPEND 0x0040 628c2ecf20Sopenharmony_ci#define PST_SBCLKST 0x0030 638c2ecf20Sopenharmony_ci#define PST_SBCLKST_ILP 0x0010 648c2ecf20Sopenharmony_ci#define PST_SBCLKST_ALP 0x0020 658c2ecf20Sopenharmony_ci#define PST_SBCLKST_HT 0x0030 668c2ecf20Sopenharmony_ci#define PST_ALPAVAIL 0x0008 678c2ecf20Sopenharmony_ci#define PST_HTAVAIL 0x0004 688c2ecf20Sopenharmony_ci#define PST_RESINIT 0x0003 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* PMU resource bit position */ 718c2ecf20Sopenharmony_ci#define PMURES_BIT(bit) (1 << (bit)) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* PMU corerev and chip specific PLL controls. 748c2ecf20Sopenharmony_ci * PMU<rev>_PLL<num>_XX where <rev> is PMU corerev and <num> is an arbitrary 758c2ecf20Sopenharmony_ci * number to differentiate different PLLs controlled by the same PMU rev. 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* pmu XtalFreqRatio */ 798c2ecf20Sopenharmony_ci#define PMU_XTALFREQ_REG_ILPCTR_MASK 0x00001FFF 808c2ecf20Sopenharmony_ci#define PMU_XTALFREQ_REG_MEASURE_MASK 0x80000000 818c2ecf20Sopenharmony_ci#define PMU_XTALFREQ_REG_MEASURE_SHIFT 31 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* 4313 resources */ 848c2ecf20Sopenharmony_ci#define RES4313_BB_PU_RSRC 0 858c2ecf20Sopenharmony_ci#define RES4313_ILP_REQ_RSRC 1 868c2ecf20Sopenharmony_ci#define RES4313_XTAL_PU_RSRC 2 878c2ecf20Sopenharmony_ci#define RES4313_ALP_AVAIL_RSRC 3 888c2ecf20Sopenharmony_ci#define RES4313_RADIO_PU_RSRC 4 898c2ecf20Sopenharmony_ci#define RES4313_BG_PU_RSRC 5 908c2ecf20Sopenharmony_ci#define RES4313_VREG1P4_PU_RSRC 6 918c2ecf20Sopenharmony_ci#define RES4313_AFE_PWRSW_RSRC 7 928c2ecf20Sopenharmony_ci#define RES4313_RX_PWRSW_RSRC 8 938c2ecf20Sopenharmony_ci#define RES4313_TX_PWRSW_RSRC 9 948c2ecf20Sopenharmony_ci#define RES4313_BB_PWRSW_RSRC 10 958c2ecf20Sopenharmony_ci#define RES4313_SYNTH_PWRSW_RSRC 11 968c2ecf20Sopenharmony_ci#define RES4313_MISC_PWRSW_RSRC 12 978c2ecf20Sopenharmony_ci#define RES4313_BB_PLL_PWRSW_RSRC 13 988c2ecf20Sopenharmony_ci#define RES4313_HT_AVAIL_RSRC 14 998c2ecf20Sopenharmony_ci#define RES4313_MACPHY_CLK_AVAIL_RSRC 15 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciu16 si_pmu_fast_pwrup_delay(struct si_pub *sih) 1028c2ecf20Sopenharmony_ci{ 1038c2ecf20Sopenharmony_ci uint delay = PMU_MAX_TRANSITION_DLY; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci switch (ai_get_chip_id(sih)) { 1068c2ecf20Sopenharmony_ci case BCMA_CHIP_ID_BCM43224: 1078c2ecf20Sopenharmony_ci case BCMA_CHIP_ID_BCM43225: 1088c2ecf20Sopenharmony_ci case BCMA_CHIP_ID_BCM4313: 1098c2ecf20Sopenharmony_ci delay = 3700; 1108c2ecf20Sopenharmony_ci break; 1118c2ecf20Sopenharmony_ci default: 1128c2ecf20Sopenharmony_ci break; 1138c2ecf20Sopenharmony_ci } 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci return (u16) delay; 1168c2ecf20Sopenharmony_ci} 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ciu32 si_pmu_measure_alpclk(struct si_pub *sih) 1198c2ecf20Sopenharmony_ci{ 1208c2ecf20Sopenharmony_ci struct si_info *sii = container_of(sih, struct si_info, pub); 1218c2ecf20Sopenharmony_ci struct bcma_device *core; 1228c2ecf20Sopenharmony_ci u32 alp_khz; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci if (ai_get_pmurev(sih) < 10) 1258c2ecf20Sopenharmony_ci return 0; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci /* Remember original core before switch to chipc */ 1288c2ecf20Sopenharmony_ci core = sii->icbus->drv_cc.core; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci if (bcma_read32(core, CHIPCREGOFFS(pmustatus)) & PST_EXTLPOAVAIL) { 1318c2ecf20Sopenharmony_ci u32 ilp_ctr, alp_hz; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* 1348c2ecf20Sopenharmony_ci * Enable the reg to measure the freq, 1358c2ecf20Sopenharmony_ci * in case it was disabled before 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ci bcma_write32(core, CHIPCREGOFFS(pmu_xtalfreq), 1388c2ecf20Sopenharmony_ci 1U << PMU_XTALFREQ_REG_MEASURE_SHIFT); 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci /* Delay for well over 4 ILP clocks */ 1418c2ecf20Sopenharmony_ci udelay(1000); 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci /* Read the latched number of ALP ticks per 4 ILP ticks */ 1448c2ecf20Sopenharmony_ci ilp_ctr = bcma_read32(core, CHIPCREGOFFS(pmu_xtalfreq)) & 1458c2ecf20Sopenharmony_ci PMU_XTALFREQ_REG_ILPCTR_MASK; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci /* 1488c2ecf20Sopenharmony_ci * Turn off the PMU_XTALFREQ_REG_MEASURE_SHIFT 1498c2ecf20Sopenharmony_ci * bit to save power 1508c2ecf20Sopenharmony_ci */ 1518c2ecf20Sopenharmony_ci bcma_write32(core, CHIPCREGOFFS(pmu_xtalfreq), 0); 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /* Calculate ALP frequency */ 1548c2ecf20Sopenharmony_ci alp_hz = (ilp_ctr * EXT_ILP_HZ) / 4; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci /* 1578c2ecf20Sopenharmony_ci * Round to nearest 100KHz, and at 1588c2ecf20Sopenharmony_ci * the same time convert to KHz 1598c2ecf20Sopenharmony_ci */ 1608c2ecf20Sopenharmony_ci alp_khz = (alp_hz + 50000) / 100000 * 100; 1618c2ecf20Sopenharmony_ci } else 1628c2ecf20Sopenharmony_ci alp_khz = 0; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci return alp_khz; 1658c2ecf20Sopenharmony_ci} 166