summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2018-04-01 19:18:23 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2018-04-01 19:18:23 +0000
commite939f54538fd086f4b496be4e96b130132d1d231 (patch)
tree2bb1b34bc49575f0bdcd422c09ac6d1d1309eaa9 /sys/arch
parent8cb279cc42237d0fb39a85ddb0b97a224aa4ac91 (diff)
Stop using a global softc variable in most functions that are called
from the clock framework, and instead always pass the driver's softc as function parameter.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/armv7/imx/imxccm.c115
1 files changed, 49 insertions, 66 deletions
diff --git a/sys/arch/armv7/imx/imxccm.c b/sys/arch/armv7/imx/imxccm.c
index 5e27a6b1490..4bd436544f6 100644
--- a/sys/arch/armv7/imx/imxccm.c
+++ b/sys/arch/armv7/imx/imxccm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imxccm.c,v 1.13 2018/04/01 19:07:31 patrick Exp $ */
+/* $OpenBSD: imxccm.c,v 1.14 2018/04/01 19:18:22 patrick Exp $ */
/*
* Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se>
*
@@ -226,17 +226,17 @@ struct cfdriver imxccm_cd = {
NULL, "imxccm", DV_DULL
};
-uint32_t imxccm_decode_pll(enum clocks, uint32_t);
-uint32_t imxccm_get_pll2_pfd(unsigned int);
-uint32_t imxccm_get_pll3_pfd(unsigned int);
-uint32_t imxccm_get_armclk(void);
-void imxccm_armclk_set_parent(enum clocks);
-uint32_t imxccm_get_usdhx(int x);
-uint32_t imxccm_get_periphclk(void);
-uint32_t imxccm_get_ahbclk(void);
-uint32_t imxccm_get_ipgclk(void);
-uint32_t imxccm_get_ipg_perclk(void);
-uint32_t imxccm_get_uartclk(void);
+uint32_t imxccm_decode_pll(struct imxccm_softc *, enum clocks, uint32_t);
+uint32_t imxccm_get_pll2_pfd(struct imxccm_softc *, unsigned int);
+uint32_t imxccm_get_pll3_pfd(struct imxccm_softc *, unsigned int);
+uint32_t imxccm_get_armclk(struct imxccm_softc *);
+void imxccm_armclk_set_parent(struct imxccm_softc *, enum clocks);
+uint32_t imxccm_get_usdhx(struct imxccm_softc *, int x);
+uint32_t imxccm_get_periphclk(struct imxccm_softc *);
+uint32_t imxccm_get_ahbclk(struct imxccm_softc *);
+uint32_t imxccm_get_ipgclk(struct imxccm_softc *);
+uint32_t imxccm_get_ipg_perclk(struct imxccm_softc *);
+uint32_t imxccm_get_uartclk(struct imxccm_softc *);
void imxccm_enable(void *, uint32_t *, int);
uint32_t imxccm_get_frequency(void *, uint32_t *);
void imxccm_disable_usb1_chrg_detect(void);
@@ -283,7 +283,7 @@ imxccm_attach(struct device *parent, struct device *self, void *aux)
printf(": imx6 rev 1.%d CPU freq: %d MHz",
HREAD4(sc, CCM_ANALOG_DIGPROG) & CCM_ANALOG_DIGPROG_MINOR_MASK,
- imxccm_get_armclk() / 1000000);
+ imxccm_get_armclk(sc) / 1000000);
printf("\n");
@@ -295,9 +295,8 @@ imxccm_attach(struct device *parent, struct device *self, void *aux)
}
uint32_t
-imxccm_decode_pll(enum clocks pll, uint32_t freq)
+imxccm_decode_pll(struct imxccm_softc *sc, enum clocks pll, uint32_t freq)
{
- struct imxccm_softc *sc = imxccm_sc;
uint32_t div;
switch (pll) {
@@ -322,43 +321,35 @@ imxccm_decode_pll(enum clocks pll, uint32_t freq)
}
uint32_t
-imxccm_get_pll2_pfd(unsigned int pfd)
+imxccm_get_pll2_pfd(struct imxccm_softc *sc, unsigned int pfd)
{
- struct imxccm_softc *sc = imxccm_sc;
-
- return imxccm_decode_pll(SYS_PLL2, HCLK_FREQ) * 18ULL
+ return imxccm_decode_pll(sc, SYS_PLL2, HCLK_FREQ) * 18ULL
/ CCM_ANALOG_PFD_528_PFDx_FRAC(HREAD4(sc, CCM_ANALOG_PFD_528), pfd);
}
uint32_t
-imxccm_get_pll3_pfd(unsigned int pfd)
+imxccm_get_pll3_pfd(struct imxccm_softc *sc, unsigned int pfd)
{
- struct imxccm_softc *sc = imxccm_sc;
-
- return imxccm_decode_pll(USB1_PLL3, HCLK_FREQ) * 18ULL
+ return imxccm_decode_pll(sc, USB1_PLL3, HCLK_FREQ) * 18ULL
/ CCM_ANALOG_PFD_480_PFDx_FRAC(HREAD4(sc, CCM_ANALOG_PFD_480), pfd);
}
uint32_t
-imxccm_get_armclk(void)
+imxccm_get_armclk(struct imxccm_softc *sc)
{
- struct imxccm_softc *sc = imxccm_sc;
-
uint32_t ccsr = HREAD4(sc, CCM_CCSR);
if (!(ccsr & CCM_CCSR_PLL1_SW_CLK_SEL))
- return imxccm_decode_pll(ARM_PLL1, HCLK_FREQ);
+ return imxccm_decode_pll(sc, ARM_PLL1, HCLK_FREQ);
else if (ccsr & CCM_CCSR_STEP_SEL)
- return imxccm_get_pll2_pfd(2);
+ return imxccm_get_pll2_pfd(sc, 2);
else
return HCLK_FREQ;
}
void
-imxccm_armclk_set_parent(enum clocks clock)
+imxccm_armclk_set_parent(struct imxccm_softc *sc, enum clocks clock)
{
- struct imxccm_softc *sc = imxccm_sc;
-
switch (clock)
{
case ARM_PLL1:
@@ -385,9 +376,8 @@ imxccm_armclk_set_parent(enum clocks clock)
}
unsigned int
-imxccm_get_usdhx(int x)
+imxccm_get_usdhx(struct imxccm_softc *sc, int x)
{
- struct imxccm_softc *sc = imxccm_sc;
uint32_t cscmr1 = HREAD4(sc, CCM_CSCMR1);
uint32_t cscdr1 = HREAD4(sc, CCM_CSCDR1);
uint32_t podf, clkroot;
@@ -399,18 +389,16 @@ imxccm_get_usdhx(int x)
podf = ((cscdr1 >> (10 + 3*x)) & CCM_CSCDR1_USDHCx_PODF_MASK);
if (cscmr1 & (1 << CCM_CSCDR1_USDHCx_CLK_SEL_SHIFT(x)))
- clkroot = imxccm_get_pll2_pfd(0); // 352 MHz
+ clkroot = imxccm_get_pll2_pfd(sc, 0); // 352 MHz
else
- clkroot = imxccm_get_pll2_pfd(2); // 396 MHz
+ clkroot = imxccm_get_pll2_pfd(sc, 2); // 396 MHz
return clkroot / (podf + 1);
}
uint32_t
-imxccm_get_uartclk(void)
+imxccm_get_uartclk(struct imxccm_softc *sc)
{
- struct imxccm_softc *sc = imxccm_sc;
-
uint32_t clkroot = PLL3_80M;
uint32_t podf = HREAD4(sc, CCM_CSCDR1) & CCM_CSCDR1_UART_PODF_MASK;
@@ -418,16 +406,14 @@ imxccm_get_uartclk(void)
}
uint32_t
-imxccm_get_periphclk(void)
+imxccm_get_periphclk(struct imxccm_softc *sc)
{
- struct imxccm_softc *sc = imxccm_sc;
-
if ((HREAD4(sc, CCM_CBCDR) >> CCM_CBCDR_PERIPH_CLK_SEL_SHIFT)
& CCM_CBCDR_PERIPH_CLK_SEL_MASK) {
switch((HREAD4(sc, CCM_CBCMR)
>> CCM_CBCMR_PERIPH_CLK2_SEL_SHIFT) & CCM_CBCMR_PERIPH_CLK2_SEL_MASK) {
case 0:
- return imxccm_decode_pll(USB1_PLL3, HCLK_FREQ);
+ return imxccm_decode_pll(sc, USB1_PLL3, HCLK_FREQ);
case 1:
case 2:
return HCLK_FREQ;
@@ -440,43 +426,40 @@ imxccm_get_periphclk(void)
>> CCM_CBCMR_PRE_PERIPH_CLK_SEL_SHIFT) & CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK) {
default:
case 0:
- return imxccm_decode_pll(SYS_PLL2, HCLK_FREQ);
+ return imxccm_decode_pll(sc, SYS_PLL2, HCLK_FREQ);
case 1:
- return imxccm_get_pll2_pfd(2); // 396 MHz
+ return imxccm_get_pll2_pfd(sc, 2); // 396 MHz
case 2:
- return imxccm_get_pll2_pfd(0); // 352 MHz
+ return imxccm_get_pll2_pfd(sc, 0); // 352 MHz
case 3:
- return imxccm_get_pll2_pfd(2) / 2; // 198 MHz
+ return imxccm_get_pll2_pfd(sc, 2) / 2; // 198 MHz
}
}
}
uint32_t
-imxccm_get_ahbclk(void)
+imxccm_get_ahbclk(struct imxccm_softc *sc)
{
- struct imxccm_softc *sc = imxccm_sc;
uint32_t ahb_podf;
ahb_podf = (HREAD4(sc, CCM_CBCDR) >> CCM_CBCDR_AHB_PODF_SHIFT)
& CCM_CBCDR_AHB_PODF_MASK;
- return imxccm_get_periphclk() / (ahb_podf + 1);
+ return imxccm_get_periphclk(sc) / (ahb_podf + 1);
}
uint32_t
-imxccm_get_ipgclk(void)
+imxccm_get_ipgclk(struct imxccm_softc *sc)
{
- struct imxccm_softc *sc = imxccm_sc;
uint32_t ipg_podf;
ipg_podf = (HREAD4(sc, CCM_CBCDR) >> CCM_CBCDR_IPG_PODF_SHIFT)
& CCM_CBCDR_IPG_PODF_MASK;
- return imxccm_get_ahbclk() / (ipg_podf + 1);
+ return imxccm_get_ahbclk(sc) / (ipg_podf + 1);
}
uint32_t
-imxccm_get_ipg_perclk(void)
+imxccm_get_ipg_perclk(struct imxccm_softc *sc)
{
- struct imxccm_softc *sc = imxccm_sc;
uint32_t cscmr1 = HREAD4(sc, CCM_CSCMR1);
uint32_t freq, ipg_podf;
@@ -484,7 +467,7 @@ imxccm_get_ipg_perclk(void)
cscmr1 & CCM_CSCMR1_PERCLK_CLK_SEL_MASK)
freq = HCLK_FREQ;
else
- freq = imxccm_get_ipgclk();
+ freq = imxccm_get_ipgclk(sc);
ipg_podf = cscmr1 & CCM_CSCMR1_PERCLK_CLK_PODF_MASK;
@@ -535,34 +518,34 @@ imxccm_get_frequency(void *cookie, uint32_t *cells)
if (sc->sc_gates == imx6ul_gates) {
switch (idx) {
case IMX6UL_CLK_ARM:
- return imxccm_get_armclk();
+ return imxccm_get_armclk(sc);
case IMX6UL_CLK_IPG:
- return imxccm_get_ipgclk();
+ return imxccm_get_ipgclk(sc);
case IMX6UL_CLK_PERCLK:
- return imxccm_get_ipg_perclk();
+ return imxccm_get_ipg_perclk(sc);
case IMX6UL_CLK_UART1_SERIAL:
- return imxccm_get_uartclk();
+ return imxccm_get_uartclk(sc);
case IMX6UL_CLK_USDHC1:
case IMX6UL_CLK_USDHC2:
- return imxccm_get_usdhx(idx - IMX6UL_CLK_USDHC1 + 1);
+ return imxccm_get_usdhx(sc, idx - IMX6UL_CLK_USDHC1 + 1);
}
} else {
switch (idx) {
case IMX6_CLK_AHB:
- return imxccm_get_ahbclk();
+ return imxccm_get_ahbclk(sc);
case IMX6_CLK_ARM:
- return imxccm_get_armclk();
+ return imxccm_get_armclk(sc);
case IMX6_CLK_IPG:
- return imxccm_get_ipgclk();
+ return imxccm_get_ipgclk(sc);
case IMX6_CLK_IPG_PER:
- return imxccm_get_ipg_perclk();
+ return imxccm_get_ipg_perclk(sc);
case IMX6_CLK_UART_SERIAL:
- return imxccm_get_uartclk();
+ return imxccm_get_uartclk(sc);
case IMX6_CLK_USDHC1:
case IMX6_CLK_USDHC2:
case IMX6_CLK_USDHC3:
case IMX6_CLK_USDHC4:
- return imxccm_get_usdhx(idx - IMX6_CLK_USDHC1 + 1);
+ return imxccm_get_usdhx(sc, idx - IMX6_CLK_USDHC1 + 1);
}
}