Skip to content

Commit 2dc51ca

Browse files
srelag-linaro
authored andcommitted
clk: RK808: Reduce 'struct rk808' usage
Reduce usage of 'struct rk808' (driver data of the parent MFD), so that only the chip variant field is still being accessed directly. This allows restructuring the MFD driver to support SPI based PMICs. Acked-by: Stephen Boyd <sboyd@kernel.org> Tested-by: Diederik de Haas <didi.debian@cknow.org> # Rock64, Quartz64 Model A + B Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # Pine64 QuartzPro64 Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20230504173618.142075-2-sebastian.reichel@collabora.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent ac9a786 commit 2dc51ca

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

drivers/clk/clk-rk808.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
#include <linux/slab.h>
1313
#include <linux/platform_device.h>
1414
#include <linux/mfd/rk808.h>
15-
#include <linux/i2c.h>
1615

1716
struct rk808_clkout {
18-
struct rk808 *rk808;
17+
struct regmap *regmap;
1918
struct clk_hw clkout1_hw;
2019
struct clk_hw clkout2_hw;
2120
};
@@ -31,9 +30,8 @@ static int rk808_clkout2_enable(struct clk_hw *hw, bool enable)
3130
struct rk808_clkout *rk808_clkout = container_of(hw,
3231
struct rk808_clkout,
3332
clkout2_hw);
34-
struct rk808 *rk808 = rk808_clkout->rk808;
3533

36-
return regmap_update_bits(rk808->regmap, RK808_CLK32OUT_REG,
34+
return regmap_update_bits(rk808_clkout->regmap, RK808_CLK32OUT_REG,
3735
CLK32KOUT2_EN, enable ? CLK32KOUT2_EN : 0);
3836
}
3937

@@ -52,10 +50,9 @@ static int rk808_clkout2_is_prepared(struct clk_hw *hw)
5250
struct rk808_clkout *rk808_clkout = container_of(hw,
5351
struct rk808_clkout,
5452
clkout2_hw);
55-
struct rk808 *rk808 = rk808_clkout->rk808;
5653
uint32_t val;
5754

58-
int ret = regmap_read(rk808->regmap, RK808_CLK32OUT_REG, &val);
55+
int ret = regmap_read(rk808_clkout->regmap, RK808_CLK32OUT_REG, &val);
5956

6057
if (ret < 0)
6158
return ret;
@@ -93,9 +90,8 @@ static int rk817_clkout2_enable(struct clk_hw *hw, bool enable)
9390
struct rk808_clkout *rk808_clkout = container_of(hw,
9491
struct rk808_clkout,
9592
clkout2_hw);
96-
struct rk808 *rk808 = rk808_clkout->rk808;
9793

98-
return regmap_update_bits(rk808->regmap, RK817_SYS_CFG(1),
94+
return regmap_update_bits(rk808_clkout->regmap, RK817_SYS_CFG(1),
9995
RK817_CLK32KOUT2_EN,
10096
enable ? RK817_CLK32KOUT2_EN : 0);
10197
}
@@ -115,10 +111,9 @@ static int rk817_clkout2_is_prepared(struct clk_hw *hw)
115111
struct rk808_clkout *rk808_clkout = container_of(hw,
116112
struct rk808_clkout,
117113
clkout2_hw);
118-
struct rk808 *rk808 = rk808_clkout->rk808;
119114
unsigned int val;
120115

121-
int ret = regmap_read(rk808->regmap, RK817_SYS_CFG(1), &val);
116+
int ret = regmap_read(rk808_clkout->regmap, RK817_SYS_CFG(1), &val);
122117

123118
if (ret < 0)
124119
return 0;
@@ -153,18 +148,21 @@ static const struct clk_ops *rkpmic_get_ops(long variant)
153148
static int rk808_clkout_probe(struct platform_device *pdev)
154149
{
155150
struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
156-
struct i2c_client *client = rk808->i2c;
157-
struct device_node *node = client->dev.of_node;
151+
struct device *dev = &pdev->dev;
158152
struct clk_init_data init = {};
159153
struct rk808_clkout *rk808_clkout;
160154
int ret;
161155

162-
rk808_clkout = devm_kzalloc(&client->dev,
156+
dev->of_node = pdev->dev.parent->of_node;
157+
158+
rk808_clkout = devm_kzalloc(dev,
163159
sizeof(*rk808_clkout), GFP_KERNEL);
164160
if (!rk808_clkout)
165161
return -ENOMEM;
166162

167-
rk808_clkout->rk808 = rk808;
163+
rk808_clkout->regmap = dev_get_regmap(pdev->dev.parent, NULL);
164+
if (!rk808_clkout->regmap)
165+
return -ENODEV;
168166

169167
init.parent_names = NULL;
170168
init.num_parents = 0;
@@ -173,10 +171,10 @@ static int rk808_clkout_probe(struct platform_device *pdev)
173171
rk808_clkout->clkout1_hw.init = &init;
174172

175173
/* optional override of the clockname */
176-
of_property_read_string_index(node, "clock-output-names",
174+
of_property_read_string_index(dev->of_node, "clock-output-names",
177175
0, &init.name);
178176

179-
ret = devm_clk_hw_register(&client->dev, &rk808_clkout->clkout1_hw);
177+
ret = devm_clk_hw_register(dev, &rk808_clkout->clkout1_hw);
180178
if (ret)
181179
return ret;
182180

@@ -185,10 +183,10 @@ static int rk808_clkout_probe(struct platform_device *pdev)
185183
rk808_clkout->clkout2_hw.init = &init;
186184

187185
/* optional override of the clockname */
188-
of_property_read_string_index(node, "clock-output-names",
186+
of_property_read_string_index(dev->of_node, "clock-output-names",
189187
1, &init.name);
190188

191-
ret = devm_clk_hw_register(&client->dev, &rk808_clkout->clkout2_hw);
189+
ret = devm_clk_hw_register(dev, &rk808_clkout->clkout2_hw);
192190
if (ret)
193191
return ret;
194192

0 commit comments

Comments
 (0)