2011-05-09 16:56:46 +00:00
|
|
|
/*
|
|
|
|
* Broadcom specific AMBA
|
|
|
|
* ChipCommon Power Management Unit driver
|
|
|
|
*
|
2011-07-04 18:50:05 +00:00
|
|
|
* Copyright 2009, Michael Buesch <m@bues.ch>
|
2011-05-09 16:56:46 +00:00
|
|
|
* Copyright 2007, Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the GNU/GPL. See COPYING for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bcma_private.h"
|
2011-07-28 01:21:04 +00:00
|
|
|
#include <linux/export.h>
|
2011-05-09 16:56:46 +00:00
|
|
|
#include <linux/bcma/bcma.h>
|
|
|
|
|
2011-07-22 23:20:11 +00:00
|
|
|
static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
|
|
|
|
{
|
|
|
|
bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
|
|
|
|
bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
|
|
|
|
return bcma_cc_read32(cc, BCMA_CC_PLLCTL_DATA);
|
|
|
|
}
|
|
|
|
|
2011-09-16 10:33:58 +00:00
|
|
|
void bcma_chipco_pll_write(struct bcma_drv_cc *cc, u32 offset, u32 value)
|
2011-05-09 16:56:46 +00:00
|
|
|
{
|
2011-09-16 10:33:58 +00:00
|
|
|
bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
|
|
|
|
bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
|
|
|
|
bcma_cc_write32(cc, BCMA_CC_PLLCTL_DATA, value);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bcma_chipco_pll_write);
|
2011-05-09 16:56:46 +00:00
|
|
|
|
2011-09-16 10:33:58 +00:00
|
|
|
void bcma_chipco_pll_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
|
|
|
|
u32 set)
|
|
|
|
{
|
|
|
|
bcma_cc_write32(cc, BCMA_CC_PLLCTL_ADDR, offset);
|
|
|
|
bcma_cc_read32(cc, BCMA_CC_PLLCTL_ADDR);
|
|
|
|
bcma_cc_maskset32(cc, BCMA_CC_PLLCTL_DATA, mask, set);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bcma_chipco_pll_maskset);
|
|
|
|
|
|
|
|
void bcma_chipco_chipctl_maskset(struct bcma_drv_cc *cc,
|
|
|
|
u32 offset, u32 mask, u32 set)
|
|
|
|
{
|
2011-05-09 16:56:46 +00:00
|
|
|
bcma_cc_write32(cc, BCMA_CC_CHIPCTL_ADDR, offset);
|
|
|
|
bcma_cc_read32(cc, BCMA_CC_CHIPCTL_ADDR);
|
2011-09-16 10:33:58 +00:00
|
|
|
bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL_DATA, mask, set);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(bcma_chipco_chipctl_maskset);
|
|
|
|
|
|
|
|
void bcma_chipco_regctl_maskset(struct bcma_drv_cc *cc, u32 offset, u32 mask,
|
|
|
|
u32 set)
|
|
|
|
{
|
|
|
|
bcma_cc_write32(cc, BCMA_CC_REGCTL_ADDR, offset);
|
|
|
|
bcma_cc_read32(cc, BCMA_CC_REGCTL_ADDR);
|
|
|
|
bcma_cc_maskset32(cc, BCMA_CC_REGCTL_DATA, mask, set);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
2011-09-16 10:33:58 +00:00
|
|
|
EXPORT_SYMBOL_GPL(bcma_chipco_regctl_maskset);
|
2011-05-09 16:56:46 +00:00
|
|
|
|
|
|
|
static void bcma_pmu_resources_init(struct bcma_drv_cc *cc)
|
|
|
|
{
|
|
|
|
struct bcma_bus *bus = cc->core->bus;
|
|
|
|
u32 min_msk = 0, max_msk = 0;
|
|
|
|
|
|
|
|
switch (bus->chipinfo.id) {
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM4313:
|
2011-05-09 16:56:46 +00:00
|
|
|
min_msk = 0x200D;
|
|
|
|
max_msk = 0xFFFF;
|
|
|
|
break;
|
|
|
|
default:
|
2012-06-29 23:44:43 +00:00
|
|
|
pr_debug("PMU resource config unknown or not needed for device 0x%04X\n",
|
|
|
|
bus->chipinfo.id);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the resource masks. */
|
|
|
|
if (min_msk)
|
|
|
|
bcma_cc_write32(cc, BCMA_CC_PMU_MINRES_MSK, min_msk);
|
|
|
|
if (max_msk)
|
|
|
|
bcma_cc_write32(cc, BCMA_CC_PMU_MAXRES_MSK, max_msk);
|
|
|
|
}
|
|
|
|
|
2011-08-11 21:46:44 +00:00
|
|
|
/* Disable to allow reading SPROM. Don't know the adventages of enabling it. */
|
|
|
|
void bcma_chipco_bcm4331_ext_pa_lines_ctl(struct bcma_drv_cc *cc, bool enable)
|
|
|
|
{
|
|
|
|
struct bcma_bus *bus = cc->core->bus;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = bcma_cc_read32(cc, BCMA_CC_CHIPCTL);
|
|
|
|
if (enable) {
|
|
|
|
val |= BCMA_CHIPCTL_4331_EXTPA_EN;
|
|
|
|
if (bus->chipinfo.pkg == 9 || bus->chipinfo.pkg == 11)
|
|
|
|
val |= BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
|
2012-06-29 23:44:37 +00:00
|
|
|
else if (bus->chipinfo.rev > 0)
|
|
|
|
val |= BCMA_CHIPCTL_4331_EXTPA_EN2;
|
2011-08-11 21:46:44 +00:00
|
|
|
} else {
|
|
|
|
val &= ~BCMA_CHIPCTL_4331_EXTPA_EN;
|
2012-06-29 23:44:37 +00:00
|
|
|
val &= ~BCMA_CHIPCTL_4331_EXTPA_EN2;
|
2011-08-11 21:46:44 +00:00
|
|
|
val &= ~BCMA_CHIPCTL_4331_EXTPA_ON_GPIO2_5;
|
|
|
|
}
|
|
|
|
bcma_cc_write32(cc, BCMA_CC_CHIPCTL, val);
|
|
|
|
}
|
|
|
|
|
2011-05-09 16:56:46 +00:00
|
|
|
void bcma_pmu_workarounds(struct bcma_drv_cc *cc)
|
|
|
|
{
|
|
|
|
struct bcma_bus *bus = cc->core->bus;
|
|
|
|
|
|
|
|
switch (bus->chipinfo.id) {
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM4313:
|
2012-06-29 23:44:41 +00:00
|
|
|
/* enable 12 mA drive strenth for 4313 and set chipControl
|
|
|
|
register bit 1 */
|
|
|
|
bcma_chipco_chipctl_maskset(cc, 0,
|
|
|
|
BCMA_CCTRL_4313_12MA_LED_DRIVE,
|
|
|
|
BCMA_CCTRL_4313_12MA_LED_DRIVE);
|
2011-05-09 16:56:46 +00:00
|
|
|
break;
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM4331:
|
|
|
|
case BCMA_CHIP_ID_BCM43431:
|
2012-06-01 14:13:17 +00:00
|
|
|
/* Ext PA lines must be enabled for tx on BCM4331 */
|
|
|
|
bcma_chipco_bcm4331_ext_pa_lines_ctl(cc, true);
|
2011-05-09 16:56:46 +00:00
|
|
|
break;
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM43224:
|
2012-06-29 23:44:41 +00:00
|
|
|
case BCMA_CHIP_ID_BCM43421:
|
|
|
|
/* enable 12 mA drive strenth for 43224 and set chipControl
|
|
|
|
register bit 15 */
|
2011-05-09 16:56:46 +00:00
|
|
|
if (bus->chipinfo.rev == 0) {
|
2012-06-29 23:44:41 +00:00
|
|
|
bcma_cc_maskset32(cc, BCMA_CC_CHIPCTL,
|
|
|
|
BCMA_CCTRL_43224_GPIO_TOGGLE,
|
|
|
|
BCMA_CCTRL_43224_GPIO_TOGGLE);
|
|
|
|
bcma_chipco_chipctl_maskset(cc, 0,
|
|
|
|
BCMA_CCTRL_43224A0_12MA_LED_DRIVE,
|
|
|
|
BCMA_CCTRL_43224A0_12MA_LED_DRIVE);
|
2011-05-09 16:56:46 +00:00
|
|
|
} else {
|
2012-06-29 23:44:41 +00:00
|
|
|
bcma_chipco_chipctl_maskset(cc, 0,
|
|
|
|
BCMA_CCTRL_43224B0_12MA_LED_DRIVE,
|
|
|
|
BCMA_CCTRL_43224B0_12MA_LED_DRIVE);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-06-29 23:44:43 +00:00
|
|
|
pr_debug("Workarounds unknown or not needed for device 0x%04X\n",
|
|
|
|
bus->chipinfo.id);
|
2011-05-09 16:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bcma_pmu_init(struct bcma_drv_cc *cc)
|
|
|
|
{
|
|
|
|
u32 pmucap;
|
|
|
|
|
|
|
|
pmucap = bcma_cc_read32(cc, BCMA_CC_PMU_CAP);
|
|
|
|
cc->pmu.rev = (pmucap & BCMA_CC_PMU_CAP_REVISION);
|
|
|
|
|
|
|
|
pr_debug("Found rev %u PMU (capabilities 0x%08X)\n", cc->pmu.rev,
|
|
|
|
pmucap);
|
|
|
|
|
|
|
|
if (cc->pmu.rev == 1)
|
|
|
|
bcma_cc_mask32(cc, BCMA_CC_PMU_CTL,
|
|
|
|
~BCMA_CC_PMU_CTL_NOILPONW);
|
|
|
|
else
|
|
|
|
bcma_cc_set32(cc, BCMA_CC_PMU_CTL,
|
|
|
|
BCMA_CC_PMU_CTL_NOILPONW);
|
|
|
|
|
|
|
|
bcma_pmu_resources_init(cc);
|
|
|
|
bcma_pmu_workarounds(cc);
|
|
|
|
}
|
2011-07-22 23:20:10 +00:00
|
|
|
|
|
|
|
u32 bcma_pmu_alp_clock(struct bcma_drv_cc *cc)
|
|
|
|
{
|
|
|
|
struct bcma_bus *bus = cc->core->bus;
|
|
|
|
|
|
|
|
switch (bus->chipinfo.id) {
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM4716:
|
|
|
|
case BCMA_CHIP_ID_BCM4748:
|
|
|
|
case BCMA_CHIP_ID_BCM47162:
|
|
|
|
case BCMA_CHIP_ID_BCM4313:
|
|
|
|
case BCMA_CHIP_ID_BCM5357:
|
|
|
|
case BCMA_CHIP_ID_BCM4749:
|
|
|
|
case BCMA_CHIP_ID_BCM53572:
|
2011-07-22 23:20:10 +00:00
|
|
|
/* always 20Mhz */
|
|
|
|
return 20000 * 1000;
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM5356:
|
|
|
|
case BCMA_CHIP_ID_BCM4706:
|
2011-07-22 23:20:10 +00:00
|
|
|
/* always 25Mhz */
|
|
|
|
return 25000 * 1000;
|
|
|
|
default:
|
|
|
|
pr_warn("No ALP clock specified for %04X device, "
|
|
|
|
"pmu rev. %d, using default %d Hz\n",
|
|
|
|
bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_ALP_CLOCK);
|
|
|
|
}
|
|
|
|
return BCMA_CC_PMU_ALP_CLOCK;
|
|
|
|
}
|
2011-07-22 23:20:11 +00:00
|
|
|
|
|
|
|
/* Find the output of the "m" pll divider given pll controls that start with
|
|
|
|
* pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
|
|
|
|
*/
|
|
|
|
static u32 bcma_pmu_clock(struct bcma_drv_cc *cc, u32 pll0, u32 m)
|
|
|
|
{
|
|
|
|
u32 tmp, div, ndiv, p1, p2, fc;
|
|
|
|
struct bcma_bus *bus = cc->core->bus;
|
|
|
|
|
|
|
|
BUG_ON((pll0 & 3) || (pll0 > BCMA_CC_PMU4716_MAINPLL_PLL0));
|
|
|
|
|
|
|
|
BUG_ON(!m || m > 4);
|
|
|
|
|
2012-06-29 23:44:38 +00:00
|
|
|
if (bus->chipinfo.id == BCMA_CHIP_ID_BCM5357 ||
|
|
|
|
bus->chipinfo.id == BCMA_CHIP_ID_BCM4749) {
|
2011-07-22 23:20:11 +00:00
|
|
|
/* Detect failure in clock setting */
|
|
|
|
tmp = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
|
|
|
|
if (tmp & 0x40000)
|
|
|
|
return 133 * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_P1P2_OFF);
|
|
|
|
p1 = (tmp & BCMA_CC_PPL_P1_MASK) >> BCMA_CC_PPL_P1_SHIFT;
|
|
|
|
p2 = (tmp & BCMA_CC_PPL_P2_MASK) >> BCMA_CC_PPL_P2_SHIFT;
|
|
|
|
|
|
|
|
tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_M14_OFF);
|
|
|
|
div = (tmp >> ((m - 1) * BCMA_CC_PPL_MDIV_WIDTH)) &
|
|
|
|
BCMA_CC_PPL_MDIV_MASK;
|
|
|
|
|
|
|
|
tmp = bcma_chipco_pll_read(cc, pll0 + BCMA_CC_PPL_NM5_OFF);
|
|
|
|
ndiv = (tmp & BCMA_CC_PPL_NDIV_MASK) >> BCMA_CC_PPL_NDIV_SHIFT;
|
|
|
|
|
|
|
|
/* Do calculation in Mhz */
|
|
|
|
fc = bcma_pmu_alp_clock(cc) / 1000000;
|
|
|
|
fc = (p1 * ndiv * fc) / p2;
|
|
|
|
|
|
|
|
/* Return clock in Hertz */
|
|
|
|
return (fc / div) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* query bus clock frequency for PMU-enabled chipcommon */
|
|
|
|
u32 bcma_pmu_get_clockcontrol(struct bcma_drv_cc *cc)
|
|
|
|
{
|
|
|
|
struct bcma_bus *bus = cc->core->bus;
|
|
|
|
|
|
|
|
switch (bus->chipinfo.id) {
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM4716:
|
|
|
|
case BCMA_CHIP_ID_BCM4748:
|
|
|
|
case BCMA_CHIP_ID_BCM47162:
|
2011-07-22 23:20:11 +00:00
|
|
|
return bcma_pmu_clock(cc, BCMA_CC_PMU4716_MAINPLL_PLL0,
|
|
|
|
BCMA_CC_PMU5_MAINPLL_SSB);
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM5356:
|
2011-07-22 23:20:11 +00:00
|
|
|
return bcma_pmu_clock(cc, BCMA_CC_PMU5356_MAINPLL_PLL0,
|
|
|
|
BCMA_CC_PMU5_MAINPLL_SSB);
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM5357:
|
|
|
|
case BCMA_CHIP_ID_BCM4749:
|
2011-07-22 23:20:11 +00:00
|
|
|
return bcma_pmu_clock(cc, BCMA_CC_PMU5357_MAINPLL_PLL0,
|
|
|
|
BCMA_CC_PMU5_MAINPLL_SSB);
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM4706:
|
2011-07-22 23:20:11 +00:00
|
|
|
return bcma_pmu_clock(cc, BCMA_CC_PMU4706_MAINPLL_PLL0,
|
|
|
|
BCMA_CC_PMU5_MAINPLL_SSB);
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM53572:
|
2011-07-22 23:20:11 +00:00
|
|
|
return 75000000;
|
|
|
|
default:
|
|
|
|
pr_warn("No backplane clock specified for %04X device, "
|
|
|
|
"pmu rev. %d, using default %d Hz\n",
|
|
|
|
bus->chipinfo.id, cc->pmu.rev, BCMA_CC_PMU_HT_CLOCK);
|
|
|
|
}
|
|
|
|
return BCMA_CC_PMU_HT_CLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* query cpu clock frequency for PMU-enabled chipcommon */
|
|
|
|
u32 bcma_pmu_get_clockcpu(struct bcma_drv_cc *cc)
|
|
|
|
{
|
|
|
|
struct bcma_bus *bus = cc->core->bus;
|
|
|
|
|
2012-06-29 23:44:38 +00:00
|
|
|
if (bus->chipinfo.id == BCMA_CHIP_ID_BCM53572)
|
2011-07-22 23:20:11 +00:00
|
|
|
return 300000000;
|
|
|
|
|
|
|
|
if (cc->pmu.rev >= 5) {
|
|
|
|
u32 pll;
|
|
|
|
switch (bus->chipinfo.id) {
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM5356:
|
2011-07-22 23:20:11 +00:00
|
|
|
pll = BCMA_CC_PMU5356_MAINPLL_PLL0;
|
|
|
|
break;
|
2012-06-29 23:44:38 +00:00
|
|
|
case BCMA_CHIP_ID_BCM5357:
|
|
|
|
case BCMA_CHIP_ID_BCM4749:
|
2011-07-22 23:20:11 +00:00
|
|
|
pll = BCMA_CC_PMU5357_MAINPLL_PLL0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pll = BCMA_CC_PMU4716_MAINPLL_PLL0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-06-29 23:44:38 +00:00
|
|
|
/* TODO: if (bus->chipinfo.id == BCMA_CHIP_ID_BCM4706)
|
2011-07-22 23:20:11 +00:00
|
|
|
return si_4706_pmu_clock(sih, osh, cc, PMU4706_MAINPLL_PLL0, PMU5_MAINPLL_CPU); */
|
|
|
|
return bcma_pmu_clock(cc, pll, BCMA_CC_PMU5_MAINPLL_CPU);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bcma_pmu_get_clockcontrol(cc);
|
|
|
|
}
|