Skip to content

Commit 32b0c7a

Browse files
Marek Vasutbebarino
authored andcommitted
clk: fsl-sai: Extract clock setup into fsl_sai_clk_register()
Create helper function fsl_sai_clk_register() to set up and register SAI clock. Rename BCLK specific struct fsl_sai_clk members with bclk_ prefix. Use of_node_full_name(dev->of_node) and clock name to register uniquely named clock. This is done in preparation for the follow up patch, which adds MCLK support. Signed-off-by: Marek Vasut <[email protected]> Reviewed-by: Brian Masney <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent f293f88 commit 32b0c7a

1 file changed

Lines changed: 63 additions & 27 deletions

File tree

drivers/clk/clk-fsl-sai.c

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,71 @@ struct fsl_sai_data {
2626
};
2727

2828
struct fsl_sai_clk {
29-
struct clk_divider div;
30-
struct clk_gate gate;
29+
struct clk_divider bclk_div;
30+
struct clk_gate bclk_gate;
31+
struct clk_hw *bclk_hw;
3132
spinlock_t lock;
3233
};
3334

35+
static struct clk_hw *
36+
fsl_sai_of_clk_get(struct of_phandle_args *clkspec, void *data)
37+
{
38+
struct fsl_sai_clk *sai_clk = data;
39+
40+
return sai_clk->bclk_hw;
41+
}
42+
43+
static int fsl_sai_clk_register(struct device *dev, void __iomem *base,
44+
spinlock_t *lock, struct clk_divider *div,
45+
struct clk_gate *gate, struct clk_hw **hw,
46+
const int gate_bit, const int dir_bit,
47+
const int div_reg, char *name)
48+
{
49+
const struct fsl_sai_data *data = device_get_match_data(dev);
50+
struct clk_parent_data pdata = { .index = 0 };
51+
struct clk_hw *chw;
52+
char *cname;
53+
54+
gate->reg = base + data->offset + I2S_CSR;
55+
gate->bit_idx = gate_bit;
56+
gate->lock = lock;
57+
58+
div->reg = base + div_reg;
59+
div->shift = CR2_DIV_SHIFT;
60+
div->width = CR2_DIV_WIDTH;
61+
div->lock = lock;
62+
63+
cname = devm_kasprintf(dev, GFP_KERNEL, "%s.%s",
64+
of_node_full_name(dev->of_node), name);
65+
if (!cname)
66+
return -ENOMEM;
67+
68+
/* Set clock direction */
69+
writel(dir_bit, base + div_reg);
70+
71+
chw = devm_clk_hw_register_composite_pdata(dev, cname,
72+
&pdata, 1, NULL, NULL,
73+
&div->hw,
74+
&clk_divider_ops,
75+
&gate->hw,
76+
&clk_gate_ops,
77+
CLK_SET_RATE_GATE);
78+
if (IS_ERR(chw))
79+
return PTR_ERR(chw);
80+
81+
*hw = chw;
82+
83+
return 0;
84+
}
85+
3486
static int fsl_sai_clk_probe(struct platform_device *pdev)
3587
{
3688
struct device *dev = &pdev->dev;
3789
const struct fsl_sai_data *data = device_get_match_data(dev);
3890
struct fsl_sai_clk *sai_clk;
39-
struct clk_parent_data pdata = { .index = 0 };
4091
struct clk *clk_bus;
4192
void __iomem *base;
42-
struct clk_hw *hw;
93+
int ret;
4394

4495
sai_clk = devm_kzalloc(dev, sizeof(*sai_clk), GFP_KERNEL);
4596
if (!sai_clk)
@@ -55,29 +106,14 @@ static int fsl_sai_clk_probe(struct platform_device *pdev)
55106

56107
spin_lock_init(&sai_clk->lock);
57108

58-
sai_clk->gate.reg = base + data->offset + I2S_CSR;
59-
sai_clk->gate.bit_idx = CSR_BCE_BIT;
60-
sai_clk->gate.lock = &sai_clk->lock;
61-
62-
sai_clk->div.reg = base + data->offset + I2S_CR2;
63-
sai_clk->div.shift = CR2_DIV_SHIFT;
64-
sai_clk->div.width = CR2_DIV_WIDTH;
65-
sai_clk->div.lock = &sai_clk->lock;
66-
67-
/* set clock direction, we are the BCLK master */
68-
writel(CR2_BCD, base + data->offset + I2S_CR2);
69-
70-
hw = devm_clk_hw_register_composite_pdata(dev, dev->of_node->name,
71-
&pdata, 1, NULL, NULL,
72-
&sai_clk->div.hw,
73-
&clk_divider_ops,
74-
&sai_clk->gate.hw,
75-
&clk_gate_ops,
76-
CLK_SET_RATE_GATE);
77-
if (IS_ERR(hw))
78-
return PTR_ERR(hw);
79-
80-
return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
109+
ret = fsl_sai_clk_register(dev, base, &sai_clk->lock,
110+
&sai_clk->bclk_div, &sai_clk->bclk_gate,
111+
&sai_clk->bclk_hw, CSR_BCE_BIT, CR2_BCD,
112+
data->offset + I2S_CR2, "BCLK");
113+
if (ret)
114+
return ret;
115+
116+
return devm_of_clk_add_hw_provider(dev, fsl_sai_of_clk_get, sai_clk);
81117
}
82118

83119
static const struct fsl_sai_data fsl_sai_vf610_data = {

0 commit comments

Comments
 (0)