Skip to content

Commit 59128c2

Browse files
Taniya Dasbebarino
authored andcommitted
clk: qcom: clk-alpha-pll: Add support for controlling Lucid PLLs
Add programming sequence support for managing the Lucid PLLs. Signed-off-by: Taniya Das <[email protected]> Signed-off-by: Venkata Narendra Kumar Gutta <[email protected]> Signed-off-by: Vinod Koul <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Reviewed-by: Bryan O'Donoghue <[email protected]> Tested-by: Bryan O'Donoghue <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent ee4adbb commit 59128c2

File tree

2 files changed

+205
-0
lines changed

2 files changed

+205
-0
lines changed

drivers/clk/qcom/clk-alpha-pll.c

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#define PLL_CONFIG_CTL_U1(p) ((p)->offset + (p)->regs[PLL_OFF_CONFIG_CTL_U1])
5353
#define PLL_TEST_CTL(p) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL])
5454
#define PLL_TEST_CTL_U(p) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL_U])
55+
#define PLL_TEST_CTL_U1(p) ((p)->offset + (p)->regs[PLL_OFF_TEST_CTL_U1])
5556
#define PLL_STATUS(p) ((p)->offset + (p)->regs[PLL_OFF_STATUS])
5657
#define PLL_OPMODE(p) ((p)->offset + (p)->regs[PLL_OFF_OPMODE])
5758
#define PLL_FRAC(p) ((p)->offset + (p)->regs[PLL_OFF_FRAC])
@@ -116,6 +117,22 @@ const u8 clk_alpha_pll_regs[][PLL_OFF_MAX_REGS] = {
116117
[PLL_OFF_ALPHA_VAL] = 0x40,
117118
[PLL_OFF_CAL_VAL] = 0x44,
118119
},
120+
[CLK_ALPHA_PLL_TYPE_LUCID] = {
121+
[PLL_OFF_L_VAL] = 0x04,
122+
[PLL_OFF_CAL_L_VAL] = 0x08,
123+
[PLL_OFF_USER_CTL] = 0x0c,
124+
[PLL_OFF_USER_CTL_U] = 0x10,
125+
[PLL_OFF_USER_CTL_U1] = 0x14,
126+
[PLL_OFF_CONFIG_CTL] = 0x18,
127+
[PLL_OFF_CONFIG_CTL_U] = 0x1c,
128+
[PLL_OFF_CONFIG_CTL_U1] = 0x20,
129+
[PLL_OFF_TEST_CTL] = 0x24,
130+
[PLL_OFF_TEST_CTL_U] = 0x28,
131+
[PLL_OFF_TEST_CTL_U1] = 0x2c,
132+
[PLL_OFF_STATUS] = 0x30,
133+
[PLL_OFF_OPMODE] = 0x38,
134+
[PLL_OFF_ALPHA_VAL] = 0x40,
135+
},
119136
};
120137
EXPORT_SYMBOL_GPL(clk_alpha_pll_regs);
121138

@@ -139,6 +156,10 @@ EXPORT_SYMBOL_GPL(clk_alpha_pll_regs);
139156
#define PLL_OUT_MASK 0x7
140157
#define PLL_RATE_MARGIN 500
141158

159+
/* LUCID PLL specific settings and offsets */
160+
#define LUCID_PLL_CAL_VAL 0x44
161+
#define LUCID_PCAL_DONE BIT(26)
162+
142163
#define pll_alpha_width(p) \
143164
((PLL_ALPHA_VAL_U(p) - PLL_ALPHA_VAL(p) == 4) ? \
144165
ALPHA_REG_BITWIDTH : ALPHA_REG_16BIT_WIDTH)
@@ -1370,3 +1391,175 @@ const struct clk_ops clk_alpha_pll_postdiv_fabia_ops = {
13701391
.set_rate = clk_alpha_pll_postdiv_fabia_set_rate,
13711392
};
13721393
EXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_fabia_ops);
1394+
1395+
/**
1396+
* clk_lucid_pll_configure - configure the lucid pll
1397+
*
1398+
* @pll: clk alpha pll
1399+
* @regmap: register map
1400+
* @config: configuration to apply for pll
1401+
*/
1402+
void clk_lucid_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
1403+
const struct alpha_pll_config *config)
1404+
{
1405+
if (config->l)
1406+
regmap_write(regmap, PLL_L_VAL(pll), config->l);
1407+
1408+
regmap_write(regmap, PLL_CAL_L_VAL(pll), LUCID_PLL_CAL_VAL);
1409+
1410+
if (config->alpha)
1411+
regmap_write(regmap, PLL_ALPHA_VAL(pll), config->alpha);
1412+
1413+
if (config->config_ctl_val)
1414+
regmap_write(regmap, PLL_CONFIG_CTL(pll),
1415+
config->config_ctl_val);
1416+
1417+
if (config->config_ctl_hi_val)
1418+
regmap_write(regmap, PLL_CONFIG_CTL_U(pll),
1419+
config->config_ctl_hi_val);
1420+
1421+
if (config->config_ctl_hi1_val)
1422+
regmap_write(regmap, PLL_CONFIG_CTL_U1(pll),
1423+
config->config_ctl_hi1_val);
1424+
1425+
if (config->user_ctl_val)
1426+
regmap_write(regmap, PLL_USER_CTL(pll),
1427+
config->user_ctl_val);
1428+
1429+
if (config->user_ctl_hi_val)
1430+
regmap_write(regmap, PLL_USER_CTL_U(pll),
1431+
config->user_ctl_hi_val);
1432+
1433+
if (config->user_ctl_hi1_val)
1434+
regmap_write(regmap, PLL_USER_CTL_U1(pll),
1435+
config->user_ctl_hi1_val);
1436+
1437+
if (config->test_ctl_val)
1438+
regmap_write(regmap, PLL_TEST_CTL(pll),
1439+
config->test_ctl_val);
1440+
1441+
if (config->test_ctl_hi_val)
1442+
regmap_write(regmap, PLL_TEST_CTL_U(pll),
1443+
config->test_ctl_hi_val);
1444+
1445+
if (config->test_ctl_hi1_val)
1446+
regmap_write(regmap, PLL_TEST_CTL_U1(pll),
1447+
config->test_ctl_hi1_val);
1448+
1449+
regmap_update_bits(regmap, PLL_MODE(pll), PLL_UPDATE_BYPASS,
1450+
PLL_UPDATE_BYPASS);
1451+
1452+
/* Disable PLL output */
1453+
regmap_update_bits(regmap, PLL_MODE(pll), PLL_OUTCTRL, 0);
1454+
1455+
/* Set operation mode to OFF */
1456+
regmap_write(regmap, PLL_OPMODE(pll), PLL_STANDBY);
1457+
1458+
/* Place the PLL in STANDBY mode */
1459+
regmap_update_bits(regmap, PLL_MODE(pll), PLL_RESET_N, PLL_RESET_N);
1460+
}
1461+
EXPORT_SYMBOL_GPL(clk_lucid_pll_configure);
1462+
1463+
/*
1464+
* The Lucid PLL requires a power-on self-calibration which happens when the
1465+
* PLL comes out of reset. Calibrate in case it is not completed.
1466+
*/
1467+
static int alpha_pll_lucid_prepare(struct clk_hw *hw)
1468+
{
1469+
struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
1470+
u32 regval;
1471+
int ret;
1472+
1473+
/* Return early if calibration is not needed. */
1474+
regmap_read(pll->clkr.regmap, PLL_STATUS(pll), &regval);
1475+
if (regval & LUCID_PCAL_DONE)
1476+
return 0;
1477+
1478+
/* On/off to calibrate */
1479+
ret = clk_trion_pll_enable(hw);
1480+
if (!ret)
1481+
clk_trion_pll_disable(hw);
1482+
1483+
return ret;
1484+
}
1485+
1486+
static int alpha_pll_lucid_set_rate(struct clk_hw *hw, unsigned long rate,
1487+
unsigned long prate)
1488+
{
1489+
struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
1490+
unsigned long rrate;
1491+
u32 regval, l, alpha_width = pll_alpha_width(pll);
1492+
u64 a;
1493+
int ret;
1494+
1495+
rrate = alpha_pll_round_rate(rate, prate, &l, &a, alpha_width);
1496+
1497+
/*
1498+
* Due to a limited number of bits for fractional rate programming, the
1499+
* rounded up rate could be marginally higher than the requested rate.
1500+
*/
1501+
if (rrate > (rate + PLL_RATE_MARGIN) || rrate < rate) {
1502+
pr_err("Call set rate on the PLL with rounded rates!\n");
1503+
return -EINVAL;
1504+
}
1505+
1506+
regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l);
1507+
regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), a);
1508+
1509+
/* Latch the PLL input */
1510+
ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
1511+
PLL_UPDATE, PLL_UPDATE);
1512+
if (ret)
1513+
return ret;
1514+
1515+
/* Wait for 2 reference cycles before checking the ACK bit. */
1516+
udelay(1);
1517+
regmap_read(pll->clkr.regmap, PLL_MODE(pll), &regval);
1518+
if (!(regval & ALPHA_PLL_ACK_LATCH)) {
1519+
pr_err("Lucid PLL latch failed. Output may be unstable!\n");
1520+
return -EINVAL;
1521+
}
1522+
1523+
/* Return the latch input to 0 */
1524+
ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll),
1525+
PLL_UPDATE, 0);
1526+
if (ret)
1527+
return ret;
1528+
1529+
if (clk_hw_is_enabled(hw)) {
1530+
ret = wait_for_pll_enable_lock(pll);
1531+
if (ret)
1532+
return ret;
1533+
}
1534+
1535+
/* Wait for PLL output to stabilize */
1536+
udelay(100);
1537+
return 0;
1538+
}
1539+
1540+
const struct clk_ops clk_alpha_pll_lucid_ops = {
1541+
.prepare = alpha_pll_lucid_prepare,
1542+
.enable = clk_trion_pll_enable,
1543+
.disable = clk_trion_pll_disable,
1544+
.is_enabled = clk_trion_pll_is_enabled,
1545+
.recalc_rate = clk_trion_pll_recalc_rate,
1546+
.round_rate = clk_alpha_pll_round_rate,
1547+
.set_rate = alpha_pll_lucid_set_rate,
1548+
};
1549+
EXPORT_SYMBOL_GPL(clk_alpha_pll_lucid_ops);
1550+
1551+
const struct clk_ops clk_alpha_pll_fixed_lucid_ops = {
1552+
.enable = clk_trion_pll_enable,
1553+
.disable = clk_trion_pll_disable,
1554+
.is_enabled = clk_trion_pll_is_enabled,
1555+
.recalc_rate = clk_trion_pll_recalc_rate,
1556+
.round_rate = clk_alpha_pll_round_rate,
1557+
};
1558+
EXPORT_SYMBOL_GPL(clk_alpha_pll_fixed_lucid_ops);
1559+
1560+
const struct clk_ops clk_alpha_pll_postdiv_lucid_ops = {
1561+
.recalc_rate = clk_alpha_pll_postdiv_fabia_recalc_rate,
1562+
.round_rate = clk_alpha_pll_postdiv_fabia_round_rate,
1563+
.set_rate = clk_alpha_pll_postdiv_fabia_set_rate,
1564+
};
1565+
EXPORT_SYMBOL_GPL(clk_alpha_pll_postdiv_lucid_ops);

drivers/clk/qcom/clk-alpha-pll.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum {
1414
CLK_ALPHA_PLL_TYPE_BRAMMO,
1515
CLK_ALPHA_PLL_TYPE_FABIA,
1616
CLK_ALPHA_PLL_TYPE_TRION,
17+
CLK_ALPHA_PLL_TYPE_LUCID,
1718
CLK_ALPHA_PLL_TYPE_MAX,
1819
};
1920

@@ -30,6 +31,7 @@ enum {
3031
PLL_OFF_CONFIG_CTL_U1,
3132
PLL_OFF_TEST_CTL,
3233
PLL_OFF_TEST_CTL_U,
34+
PLL_OFF_TEST_CTL_U1,
3335
PLL_OFF_STATUS,
3436
PLL_OFF_OPMODE,
3537
PLL_OFF_FRAC,
@@ -94,10 +96,13 @@ struct alpha_pll_config {
9496
u32 alpha_hi;
9597
u32 config_ctl_val;
9698
u32 config_ctl_hi_val;
99+
u32 config_ctl_hi1_val;
97100
u32 user_ctl_val;
98101
u32 user_ctl_hi_val;
102+
u32 user_ctl_hi1_val;
99103
u32 test_ctl_val;
100104
u32 test_ctl_hi_val;
105+
u32 test_ctl_hi1_val;
101106
u32 main_output_mask;
102107
u32 aux_output_mask;
103108
u32 aux2_output_mask;
@@ -123,10 +128,17 @@ extern const struct clk_ops clk_alpha_pll_fabia_ops;
123128
extern const struct clk_ops clk_alpha_pll_fixed_fabia_ops;
124129
extern const struct clk_ops clk_alpha_pll_postdiv_fabia_ops;
125130

131+
extern const struct clk_ops clk_alpha_pll_lucid_ops;
132+
extern const struct clk_ops clk_alpha_pll_fixed_lucid_ops;
133+
extern const struct clk_ops clk_alpha_pll_postdiv_lucid_ops;
134+
126135
void clk_alpha_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
127136
const struct alpha_pll_config *config);
128137
void clk_fabia_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
129138
const struct alpha_pll_config *config);
139+
void clk_lucid_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
140+
const struct alpha_pll_config *config);
141+
130142
extern const struct clk_ops clk_trion_fixed_pll_ops;
131143
extern const struct clk_ops clk_trion_pll_postdiv_ops;
132144

0 commit comments

Comments
 (0)