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

Configure Feed

Select the types of activity you want to include in your feed.

clk: microchip: mpfs: convert cfg_clk to clk_divider

The cfg_clk struct is now just a redefinition of the clk_divider struct
with custom implentations of the ops, that implement an extra level of
redirection. Remove the custom struct and replace it with clk_divider.

Reviewed-by: Daire McNamara <daire.mcnamara@microchip.com>
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/20220909123123.2699583-13-conor.dooley@microchip.com

authored by

Conor Dooley and committed by
Claudiu Beznea
4da2404b e7df7ba0

+8 -68
+8 -68
drivers/clk/microchip/clk-mpfs.c
··· 49 49 50 50 #define to_mpfs_msspll_clk(_hw) container_of(_hw, struct mpfs_msspll_hw_clock, hw) 51 51 52 - struct mpfs_cfg_clock { 53 - void __iomem *reg; 54 - const struct clk_div_table *table; 55 - u8 shift; 56 - u8 width; 57 - u8 flags; 58 - }; 59 - 60 52 struct mpfs_cfg_hw_clock { 61 - struct mpfs_cfg_clock cfg; 62 - struct clk_hw hw; 53 + struct clk_divider cfg; 63 54 struct clk_init_data init; 64 55 unsigned int id; 65 56 u32 reg_offset; 66 57 }; 67 - 68 - #define to_mpfs_cfg_clk(_hw) container_of(_hw, struct mpfs_cfg_hw_clock, hw) 69 58 70 59 struct mpfs_periph_clock { 71 60 void __iomem *reg; ··· 215 226 * "CFG" clocks 216 227 */ 217 228 218 - static unsigned long mpfs_cfg_clk_recalc_rate(struct clk_hw *hw, unsigned long prate) 219 - { 220 - struct mpfs_cfg_hw_clock *cfg_hw = to_mpfs_cfg_clk(hw); 221 - struct mpfs_cfg_clock *cfg = &cfg_hw->cfg; 222 - u32 val; 223 - 224 - val = readl_relaxed(cfg->reg) >> cfg->shift; 225 - val &= clk_div_mask(cfg->width); 226 - 227 - return divider_recalc_rate(hw, prate, val, cfg->table, cfg->flags, cfg->width); 228 - } 229 - 230 - static long mpfs_cfg_clk_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) 231 - { 232 - struct mpfs_cfg_hw_clock *cfg_hw = to_mpfs_cfg_clk(hw); 233 - struct mpfs_cfg_clock *cfg = &cfg_hw->cfg; 234 - 235 - return divider_round_rate(hw, rate, prate, cfg->table, cfg->width, 0); 236 - } 237 - 238 - static int mpfs_cfg_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long prate) 239 - { 240 - struct mpfs_cfg_hw_clock *cfg_hw = to_mpfs_cfg_clk(hw); 241 - struct mpfs_cfg_clock *cfg = &cfg_hw->cfg; 242 - unsigned long flags; 243 - u32 val; 244 - int divider_setting; 245 - 246 - divider_setting = divider_get_val(rate, prate, cfg->table, cfg->width, 0); 247 - 248 - if (divider_setting < 0) 249 - return divider_setting; 250 - 251 - spin_lock_irqsave(&mpfs_clk_lock, flags); 252 - val = readl_relaxed(cfg->reg); 253 - val &= ~(clk_div_mask(cfg->width) << cfg_hw->cfg.shift); 254 - val |= divider_setting << cfg->shift; 255 - writel_relaxed(val, cfg->reg); 256 - 257 - spin_unlock_irqrestore(&mpfs_clk_lock, flags); 258 - 259 - return 0; 260 - } 261 - 262 - static const struct clk_ops mpfs_clk_cfg_ops = { 263 - .recalc_rate = mpfs_cfg_clk_recalc_rate, 264 - .round_rate = mpfs_cfg_clk_round_rate, 265 - .set_rate = mpfs_cfg_clk_set_rate, 266 - }; 267 - 268 229 #define CLK_CFG(_id, _name, _parent, _shift, _width, _table, _flags, _offset) { \ 269 230 .id = _id, \ 270 231 .cfg.shift = _shift, \ ··· 222 283 .cfg.table = _table, \ 223 284 .reg_offset = _offset, \ 224 285 .cfg.flags = _flags, \ 225 - .hw.init = CLK_HW_INIT(_name, _parent, &mpfs_clk_cfg_ops, 0), \ 286 + .cfg.hw.init = CLK_HW_INIT(_name, _parent, &clk_divider_ops, 0), \ 287 + .cfg.lock = &mpfs_clk_lock, \ 226 288 } 227 289 228 290 #define CLK_CPU_OFFSET 0u ··· 245 305 .cfg.table = mpfs_div_rtcref_table, 246 306 .reg_offset = REG_RTC_CLOCK_CR, 247 307 .cfg.flags = CLK_DIVIDER_ONE_BASED, 248 - .hw.init = 249 - CLK_HW_INIT_PARENTS_DATA("clk_rtcref", mpfs_ext_ref, &mpfs_clk_cfg_ops, 0), 308 + .cfg.hw.init = 309 + CLK_HW_INIT_PARENTS_DATA("clk_rtcref", mpfs_ext_ref, &clk_divider_ops, 0), 250 310 } 251 311 }; 252 312 ··· 260 320 struct mpfs_cfg_hw_clock *cfg_hw = &cfg_hws[i]; 261 321 262 322 cfg_hw->cfg.reg = data->base + cfg_hw->reg_offset; 263 - ret = devm_clk_hw_register(dev, &cfg_hw->hw); 323 + ret = devm_clk_hw_register(dev, &cfg_hw->cfg.hw); 264 324 if (ret) 265 325 return dev_err_probe(dev, ret, "failed to register clock id: %d\n", 266 326 cfg_hw->id); 267 327 268 328 id = cfg_hw->id; 269 - data->hw_data.hws[id] = &cfg_hw->hw; 329 + data->hw_data.hws[id] = &cfg_hw->cfg.hw; 270 330 } 271 331 272 332 return 0; ··· 336 396 _flags), \ 337 397 } 338 398 339 - #define PARENT_CLK(PARENT) (&mpfs_cfg_clks[CLK_##PARENT##_OFFSET].hw) 399 + #define PARENT_CLK(PARENT) (&mpfs_cfg_clks[CLK_##PARENT##_OFFSET].cfg.hw) 340 400 341 401 /* 342 402 * Critical clocks: