Skip to content

Commit 21f010b

Browse files
Dragan Cveticgregkh
authored andcommitted
misc: xilinx_sdfec: Add CCF support
Add the support for Linux Clock Control Framework (CCF). Registers and enables clocks with the Clock Control Framework (CCF), to prevent shared clocks from been disabled. Tested-by: Dragan Cvetic <dragan.cvetic@xilinx.com> Signed-off-by: Derek Kiernan <derek.kiernan@xilinx.com> Signed-off-by: Dragan Cvetic <dragan.cvetic@xilinx.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 76d83e1 commit 21f010b

1 file changed

Lines changed: 188 additions & 5 deletions

File tree

‎drivers/misc/xilinx_sdfec.c‎

Lines changed: 188 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,35 @@
2525
static struct idr dev_idr;
2626
static struct mutex dev_idr_lock;
2727

28+
/**
29+
* struct xsdfec_clks - For managing SD-FEC clocks
30+
* @core_clk: Main processing clock for core
31+
* @axi_clk: AXI4-Lite memory-mapped clock
32+
* @din_words_clk: DIN Words AXI4-Stream Slave clock
33+
* @din_clk: DIN AXI4-Stream Slave clock
34+
* @dout_clk: DOUT Words AXI4-Stream Slave clock
35+
* @dout_words_clk: DOUT AXI4-Stream Slave clock
36+
* @ctrl_clk: Control AXI4-Stream Slave clock
37+
* @status_clk: Status AXI4-Stream Slave clock
38+
*/
39+
struct xsdfec_clks {
40+
struct clk *core_clk;
41+
struct clk *axi_clk;
42+
struct clk *din_words_clk;
43+
struct clk *din_clk;
44+
struct clk *dout_clk;
45+
struct clk *dout_words_clk;
46+
struct clk *ctrl_clk;
47+
struct clk *status_clk;
48+
};
49+
2850
/**
2951
* struct xsdfec_dev - Driver data for SDFEC
3052
* @regs: device physical base address
3153
* @dev: pointer to device struct
3254
* @miscdev: Misc device handle
3355
* @error_data_lock: Error counter and states spinlock
56+
* @clks: Clocks managed by the SDFEC driver
3457
* @dev_name: Device name
3558
* @dev_id: Device ID
3659
*
@@ -42,6 +65,7 @@ struct xsdfec_dev {
4265
struct miscdevice miscdev;
4366
/* Spinlock to protect state_updated and stats_updated */
4467
spinlock_t error_data_lock;
68+
struct xsdfec_clks clks;
4569
char dev_name[DEV_NAME_LEN];
4670
int dev_id;
4771
};
@@ -50,6 +74,159 @@ static const struct file_operations xsdfec_fops = {
5074
.owner = THIS_MODULE,
5175
};
5276

77+
static int xsdfec_clk_init(struct platform_device *pdev,
78+
struct xsdfec_clks *clks)
79+
{
80+
int err;
81+
82+
clks->core_clk = devm_clk_get(&pdev->dev, "core_clk");
83+
if (IS_ERR(clks->core_clk)) {
84+
dev_err(&pdev->dev, "failed to get core_clk");
85+
return PTR_ERR(clks->core_clk);
86+
}
87+
88+
clks->axi_clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
89+
if (IS_ERR(clks->axi_clk)) {
90+
dev_err(&pdev->dev, "failed to get axi_clk");
91+
return PTR_ERR(clks->axi_clk);
92+
}
93+
94+
clks->din_words_clk = devm_clk_get(&pdev->dev, "s_axis_din_words_aclk");
95+
if (IS_ERR(clks->din_words_clk)) {
96+
if (PTR_ERR(clks->din_words_clk) != -ENOENT) {
97+
err = PTR_ERR(clks->din_words_clk);
98+
return err;
99+
}
100+
clks->din_words_clk = NULL;
101+
}
102+
103+
clks->din_clk = devm_clk_get(&pdev->dev, "s_axis_din_aclk");
104+
if (IS_ERR(clks->din_clk)) {
105+
if (PTR_ERR(clks->din_clk) != -ENOENT) {
106+
err = PTR_ERR(clks->din_clk);
107+
return err;
108+
}
109+
clks->din_clk = NULL;
110+
}
111+
112+
clks->dout_clk = devm_clk_get(&pdev->dev, "m_axis_dout_aclk");
113+
if (IS_ERR(clks->dout_clk)) {
114+
if (PTR_ERR(clks->dout_clk) != -ENOENT) {
115+
err = PTR_ERR(clks->dout_clk);
116+
return err;
117+
}
118+
clks->dout_clk = NULL;
119+
}
120+
121+
clks->dout_words_clk =
122+
devm_clk_get(&pdev->dev, "s_axis_dout_words_aclk");
123+
if (IS_ERR(clks->dout_words_clk)) {
124+
if (PTR_ERR(clks->dout_words_clk) != -ENOENT) {
125+
err = PTR_ERR(clks->dout_words_clk);
126+
return err;
127+
}
128+
clks->dout_words_clk = NULL;
129+
}
130+
131+
clks->ctrl_clk = devm_clk_get(&pdev->dev, "s_axis_ctrl_aclk");
132+
if (IS_ERR(clks->ctrl_clk)) {
133+
if (PTR_ERR(clks->ctrl_clk) != -ENOENT) {
134+
err = PTR_ERR(clks->ctrl_clk);
135+
return err;
136+
}
137+
clks->ctrl_clk = NULL;
138+
}
139+
140+
clks->status_clk = devm_clk_get(&pdev->dev, "m_axis_status_aclk");
141+
if (IS_ERR(clks->status_clk)) {
142+
if (PTR_ERR(clks->status_clk) != -ENOENT) {
143+
err = PTR_ERR(clks->status_clk);
144+
return err;
145+
}
146+
clks->status_clk = NULL;
147+
}
148+
149+
err = clk_prepare_enable(clks->core_clk);
150+
if (err) {
151+
dev_err(&pdev->dev, "failed to enable core_clk (%d)", err);
152+
return err;
153+
}
154+
155+
err = clk_prepare_enable(clks->axi_clk);
156+
if (err) {
157+
dev_err(&pdev->dev, "failed to enable axi_clk (%d)", err);
158+
goto err_disable_core_clk;
159+
}
160+
161+
err = clk_prepare_enable(clks->din_clk);
162+
if (err) {
163+
dev_err(&pdev->dev, "failed to enable din_clk (%d)", err);
164+
goto err_disable_axi_clk;
165+
}
166+
167+
err = clk_prepare_enable(clks->din_words_clk);
168+
if (err) {
169+
dev_err(&pdev->dev, "failed to enable din_words_clk (%d)", err);
170+
goto err_disable_din_clk;
171+
}
172+
173+
err = clk_prepare_enable(clks->dout_clk);
174+
if (err) {
175+
dev_err(&pdev->dev, "failed to enable dout_clk (%d)", err);
176+
goto err_disable_din_words_clk;
177+
}
178+
179+
err = clk_prepare_enable(clks->dout_words_clk);
180+
if (err) {
181+
dev_err(&pdev->dev, "failed to enable dout_words_clk (%d)",
182+
err);
183+
goto err_disable_dout_clk;
184+
}
185+
186+
err = clk_prepare_enable(clks->ctrl_clk);
187+
if (err) {
188+
dev_err(&pdev->dev, "failed to enable ctrl_clk (%d)", err);
189+
goto err_disable_dout_words_clk;
190+
}
191+
192+
err = clk_prepare_enable(clks->status_clk);
193+
if (err) {
194+
dev_err(&pdev->dev, "failed to enable status_clk (%d)\n", err);
195+
goto err_disable_ctrl_clk;
196+
}
197+
198+
return err;
199+
200+
err_disable_ctrl_clk:
201+
clk_disable_unprepare(clks->ctrl_clk);
202+
err_disable_dout_words_clk:
203+
clk_disable_unprepare(clks->dout_words_clk);
204+
err_disable_dout_clk:
205+
clk_disable_unprepare(clks->dout_clk);
206+
err_disable_din_words_clk:
207+
clk_disable_unprepare(clks->din_words_clk);
208+
err_disable_din_clk:
209+
clk_disable_unprepare(clks->din_clk);
210+
err_disable_axi_clk:
211+
clk_disable_unprepare(clks->axi_clk);
212+
err_disable_core_clk:
213+
clk_disable_unprepare(clks->core_clk);
214+
215+
return err;
216+
}
217+
218+
static void xsdfec_disable_all_clks(struct xsdfec_clks *clks)
219+
{
220+
clk_disable_unprepare(clks->status_clk);
221+
clk_disable_unprepare(clks->ctrl_clk);
222+
clk_disable_unprepare(clks->dout_words_clk);
223+
clk_disable_unprepare(clks->dout_clk);
224+
clk_disable_unprepare(clks->din_words_clk);
225+
clk_disable_unprepare(clks->din_clk);
226+
clk_disable_unprepare(clks->core_clk);
227+
clk_disable_unprepare(clks->axi_clk);
228+
}
229+
53230
static void xsdfec_idr_remove(struct xsdfec_dev *xsdfec)
54231
{
55232
mutex_lock(&dev_idr_lock);
@@ -71,12 +248,16 @@ static int xsdfec_probe(struct platform_device *pdev)
71248
xsdfec->dev = &pdev->dev;
72249
spin_lock_init(&xsdfec->error_data_lock);
73250

251+
err = xsdfec_clk_init(pdev, &xsdfec->clks);
252+
if (err)
253+
return err;
254+
74255
dev = xsdfec->dev;
75256
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
76257
xsdfec->regs = devm_ioremap_resource(dev, res);
77258
if (IS_ERR(xsdfec->regs)) {
78259
err = PTR_ERR(xsdfec->regs);
79-
return err;
260+
goto err_xsdfec_dev;
80261
}
81262

82263
/* Save driver private data */
@@ -86,7 +267,7 @@ static int xsdfec_probe(struct platform_device *pdev)
86267
err = idr_alloc(&dev_idr, xsdfec->dev_name, 0, 0, GFP_KERNEL);
87268
mutex_unlock(&dev_idr_lock);
88269
if (err < 0)
89-
goto err_xsddev_idr;
270+
goto err_xsdfec_dev;
90271
xsdfec->dev_id = err;
91272

92273
snprintf(xsdfec->dev_name, DEV_NAME_LEN, "xsdfec%d", xsdfec->dev_id);
@@ -97,13 +278,14 @@ static int xsdfec_probe(struct platform_device *pdev)
97278
err = misc_register(&xsdfec->miscdev);
98279
if (err) {
99280
dev_err(dev, "error:%d. Unable to register device", err);
100-
return err;
281+
goto err_xsdfec_idr;
101282
}
102283
return 0;
103284

104-
err_xsddev_idr:
285+
err_xsdfec_idr:
105286
xsdfec_idr_remove(xsdfec);
106-
287+
err_xsdfec_dev:
288+
xsdfec_disable_all_clks(&xsdfec->clks);
107289
return err;
108290
}
109291

@@ -114,6 +296,7 @@ static int xsdfec_remove(struct platform_device *pdev)
114296
xsdfec = platform_get_drvdata(pdev);
115297
misc_deregister(&xsdfec->miscdev);
116298
xsdfec_idr_remove(xsdfec);
299+
xsdfec_disable_all_clks(&xsdfec->clks);
117300
return 0;
118301
}
119302

0 commit comments

Comments
 (0)