Skip to content

Commit 9abc1eb

Browse files
akemnadebebarino
authored andcommitted
clk: twl: add TWL6030 support
The TWL6030 has similar clocks, so add support for it. Take care of the resource grouping handling needed. Signed-off-by: Andreas Kemnade <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Roger Quadros <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 990161e commit 9abc1eb

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

drivers/clk/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ config CLK_TWL
291291
help
292292
Enable support for controlling the clock resources on TWL family
293293
PMICs. These devices have some 32K clock outputs which can be
294-
controlled by software. For now, only the TWL6032 clocks are
294+
controlled by software. For now, the TWL6032 and TWL6030 clocks are
295295
supported.
296296

297297
config CLK_TWL6040

drivers/clk/clk-twl.c

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,29 @@
1111
#include <linux/platform_device.h>
1212
#include <linux/slab.h>
1313

14-
#define VREG_STATE 2
14+
#define VREG_STATE 2
15+
#define VREG_GRP 0
1516
#define TWL6030_CFG_STATE_OFF 0x00
1617
#define TWL6030_CFG_STATE_ON 0x01
1718
#define TWL6030_CFG_STATE_MASK 0x03
19+
#define TWL6030_CFG_STATE_GRP_SHIFT 5
20+
#define TWL6030_CFG_STATE_APP_SHIFT 2
21+
#define TWL6030_CFG_STATE_APP_MASK (0x03 << TWL6030_CFG_STATE_APP_SHIFT)
22+
#define TWL6030_CFG_STATE_APP(v) (((v) & TWL6030_CFG_STATE_APP_MASK) >>\
23+
TWL6030_CFG_STATE_APP_SHIFT)
24+
#define P1_GRP BIT(0) /* processor power group */
25+
#define P2_GRP BIT(1)
26+
#define P3_GRP BIT(2)
27+
#define ALL_GRP (P1_GRP | P2_GRP | P3_GRP)
28+
29+
enum twl_type {
30+
TWL_TYPE_6030,
31+
TWL_TYPE_6032,
32+
};
1833

1934
struct twl_clock_info {
2035
struct device *dev;
36+
enum twl_type type;
2137
u8 base;
2238
struct clk_hw hw;
2339
};
@@ -56,23 +72,36 @@ static unsigned long twl_clks_recalc_rate(struct clk_hw *hw,
5672
static int twl6032_clks_prepare(struct clk_hw *hw)
5773
{
5874
struct twl_clock_info *cinfo = to_twl_clks_info(hw);
59-
int ret;
6075

61-
ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
62-
TWL6030_CFG_STATE_ON);
63-
if (ret < 0)
64-
dev_err(cinfo->dev, "clk prepare failed\n");
76+
if (cinfo->type == TWL_TYPE_6030) {
77+
int grp;
78+
79+
grp = twlclk_read(cinfo, TWL_MODULE_PM_RECEIVER, VREG_GRP);
80+
if (grp < 0)
81+
return grp;
6582

66-
return ret;
83+
return twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
84+
grp << TWL6030_CFG_STATE_GRP_SHIFT |
85+
TWL6030_CFG_STATE_ON);
86+
}
87+
88+
return twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
89+
TWL6030_CFG_STATE_ON);
6790
}
6891

6992
static void twl6032_clks_unprepare(struct clk_hw *hw)
7093
{
7194
struct twl_clock_info *cinfo = to_twl_clks_info(hw);
7295
int ret;
7396

74-
ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
75-
TWL6030_CFG_STATE_OFF);
97+
if (cinfo->type == TWL_TYPE_6030)
98+
ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
99+
ALL_GRP << TWL6030_CFG_STATE_GRP_SHIFT |
100+
TWL6030_CFG_STATE_OFF);
101+
else
102+
ret = twlclk_write(cinfo, TWL_MODULE_PM_RECEIVER, VREG_STATE,
103+
TWL6030_CFG_STATE_OFF);
104+
76105
if (ret < 0)
77106
dev_err(cinfo->dev, "clk unprepare failed\n");
78107
}
@@ -138,6 +167,7 @@ static int twl_clks_probe(struct platform_device *pdev)
138167
for (i = 0; i < count; i++) {
139168
cinfo[i].base = hw_data[i].base;
140169
cinfo[i].dev = &pdev->dev;
170+
cinfo[i].type = platform_get_device_id(pdev)->driver_data;
141171
cinfo[i].hw.init = &hw_data[i].init;
142172
ret = devm_clk_hw_register(&pdev->dev, &cinfo[i].hw);
143173
if (ret) {
@@ -159,7 +189,11 @@ static int twl_clks_probe(struct platform_device *pdev)
159189

160190
static const struct platform_device_id twl_clks_id[] = {
161191
{
192+
.name = "twl6030-clk",
193+
.driver_data = TWL_TYPE_6030,
194+
}, {
162195
.name = "twl6032-clk",
196+
.driver_data = TWL_TYPE_6032,
163197
}, {
164198
/* sentinel */
165199
}

0 commit comments

Comments
 (0)