Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sebastian Reichel and committed by
Lee Jones
2dc51ca8 ac9a7868

+16 -18
+16 -18
drivers/clk/clk-rk808.c
··· 12 12 #include <linux/slab.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/mfd/rk808.h> 15 - #include <linux/i2c.h> 16 15 17 16 struct rk808_clkout { 18 - struct rk808 *rk808; 17 + struct regmap *regmap; 19 18 struct clk_hw clkout1_hw; 20 19 struct clk_hw clkout2_hw; 21 20 }; ··· 30 31 struct rk808_clkout *rk808_clkout = container_of(hw, 31 32 struct rk808_clkout, 32 33 clkout2_hw); 33 - struct rk808 *rk808 = rk808_clkout->rk808; 34 34 35 - return regmap_update_bits(rk808->regmap, RK808_CLK32OUT_REG, 35 + return regmap_update_bits(rk808_clkout->regmap, RK808_CLK32OUT_REG, 36 36 CLK32KOUT2_EN, enable ? CLK32KOUT2_EN : 0); 37 37 } 38 38 ··· 50 52 struct rk808_clkout *rk808_clkout = container_of(hw, 51 53 struct rk808_clkout, 52 54 clkout2_hw); 53 - struct rk808 *rk808 = rk808_clkout->rk808; 54 55 uint32_t val; 55 56 56 - int ret = regmap_read(rk808->regmap, RK808_CLK32OUT_REG, &val); 57 + int ret = regmap_read(rk808_clkout->regmap, RK808_CLK32OUT_REG, &val); 57 58 58 59 if (ret < 0) 59 60 return ret; ··· 90 93 struct rk808_clkout *rk808_clkout = container_of(hw, 91 94 struct rk808_clkout, 92 95 clkout2_hw); 93 - struct rk808 *rk808 = rk808_clkout->rk808; 94 96 95 - return regmap_update_bits(rk808->regmap, RK817_SYS_CFG(1), 97 + return regmap_update_bits(rk808_clkout->regmap, RK817_SYS_CFG(1), 96 98 RK817_CLK32KOUT2_EN, 97 99 enable ? RK817_CLK32KOUT2_EN : 0); 98 100 } ··· 111 115 struct rk808_clkout *rk808_clkout = container_of(hw, 112 116 struct rk808_clkout, 113 117 clkout2_hw); 114 - struct rk808 *rk808 = rk808_clkout->rk808; 115 118 unsigned int val; 116 119 117 - int ret = regmap_read(rk808->regmap, RK817_SYS_CFG(1), &val); 120 + int ret = regmap_read(rk808_clkout->regmap, RK817_SYS_CFG(1), &val); 118 121 119 122 if (ret < 0) 120 123 return 0; ··· 148 153 static int rk808_clkout_probe(struct platform_device *pdev) 149 154 { 150 155 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); 151 - struct i2c_client *client = rk808->i2c; 152 - struct device_node *node = client->dev.of_node; 156 + struct device *dev = &pdev->dev; 153 157 struct clk_init_data init = {}; 154 158 struct rk808_clkout *rk808_clkout; 155 159 int ret; 156 160 157 - rk808_clkout = devm_kzalloc(&client->dev, 161 + dev->of_node = pdev->dev.parent->of_node; 162 + 163 + rk808_clkout = devm_kzalloc(dev, 158 164 sizeof(*rk808_clkout), GFP_KERNEL); 159 165 if (!rk808_clkout) 160 166 return -ENOMEM; 161 167 162 - rk808_clkout->rk808 = rk808; 168 + rk808_clkout->regmap = dev_get_regmap(pdev->dev.parent, NULL); 169 + if (!rk808_clkout->regmap) 170 + return -ENODEV; 163 171 164 172 init.parent_names = NULL; 165 173 init.num_parents = 0; ··· 171 173 rk808_clkout->clkout1_hw.init = &init; 172 174 173 175 /* optional override of the clockname */ 174 - of_property_read_string_index(node, "clock-output-names", 176 + of_property_read_string_index(dev->of_node, "clock-output-names", 175 177 0, &init.name); 176 178 177 - ret = devm_clk_hw_register(&client->dev, &rk808_clkout->clkout1_hw); 179 + ret = devm_clk_hw_register(dev, &rk808_clkout->clkout1_hw); 178 180 if (ret) 179 181 return ret; 180 182 ··· 183 185 rk808_clkout->clkout2_hw.init = &init; 184 186 185 187 /* optional override of the clockname */ 186 - of_property_read_string_index(node, "clock-output-names", 188 + of_property_read_string_index(dev->of_node, "clock-output-names", 187 189 1, &init.name); 188 190 189 - ret = devm_clk_hw_register(&client->dev, &rk808_clkout->clkout2_hw); 191 + ret = devm_clk_hw_register(dev, &rk808_clkout->clkout2_hw); 190 192 if (ret) 191 193 return ret; 192 194