This source file includes following definitions.
- ingenic_ecc_calculate
- ingenic_ecc_correct
- ingenic_ecc_get
- of_ingenic_ecc_get
- ingenic_ecc_release
- ingenic_ecc_probe
1
2
3
4
5
6
7
8
9 #include <linux/clk.h>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/of_platform.h>
13 #include <linux/platform_device.h>
14
15 #include "ingenic_ecc.h"
16
17
18
19
20
21
22
23
24
25
26
27 int ingenic_ecc_calculate(struct ingenic_ecc *ecc,
28 struct ingenic_ecc_params *params,
29 const u8 *buf, u8 *ecc_code)
30 {
31 return ecc->ops->calculate(ecc, params, buf, ecc_code);
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 int ingenic_ecc_correct(struct ingenic_ecc *ecc,
48 struct ingenic_ecc_params *params,
49 u8 *buf, u8 *ecc_code)
50 {
51 return ecc->ops->correct(ecc, params, buf, ecc_code);
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65 static struct ingenic_ecc *ingenic_ecc_get(struct device_node *np)
66 {
67 struct platform_device *pdev;
68 struct ingenic_ecc *ecc;
69
70 pdev = of_find_device_by_node(np);
71 if (!pdev || !platform_get_drvdata(pdev))
72 return ERR_PTR(-EPROBE_DEFER);
73
74 get_device(&pdev->dev);
75
76 ecc = platform_get_drvdata(pdev);
77 clk_prepare_enable(ecc->clk);
78
79 return ecc;
80 }
81
82
83
84
85
86
87
88
89
90
91
92 struct ingenic_ecc *of_ingenic_ecc_get(struct device_node *of_node)
93 {
94 struct ingenic_ecc *ecc = NULL;
95 struct device_node *np;
96
97 np = of_parse_phandle(of_node, "ecc-engine", 0);
98
99
100
101
102
103 if (!np)
104 np = of_parse_phandle(of_node, "ingenic,bch-controller", 0);
105
106 if (np) {
107 ecc = ingenic_ecc_get(np);
108 of_node_put(np);
109 }
110 return ecc;
111 }
112
113
114
115
116
117 void ingenic_ecc_release(struct ingenic_ecc *ecc)
118 {
119 clk_disable_unprepare(ecc->clk);
120 put_device(ecc->dev);
121 }
122
123 int ingenic_ecc_probe(struct platform_device *pdev)
124 {
125 struct device *dev = &pdev->dev;
126 struct ingenic_ecc *ecc;
127 struct resource *res;
128
129 ecc = devm_kzalloc(dev, sizeof(*ecc), GFP_KERNEL);
130 if (!ecc)
131 return -ENOMEM;
132
133 ecc->ops = device_get_match_data(dev);
134 if (!ecc->ops)
135 return -EINVAL;
136
137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
138 ecc->base = devm_ioremap_resource(dev, res);
139 if (IS_ERR(ecc->base))
140 return PTR_ERR(ecc->base);
141
142 ecc->ops->disable(ecc);
143
144 ecc->clk = devm_clk_get(dev, NULL);
145 if (IS_ERR(ecc->clk)) {
146 dev_err(dev, "failed to get clock: %ld\n", PTR_ERR(ecc->clk));
147 return PTR_ERR(ecc->clk);
148 }
149
150 mutex_init(&ecc->lock);
151
152 ecc->dev = dev;
153 platform_set_drvdata(pdev, ecc);
154
155 return 0;
156 }
157 EXPORT_SYMBOL(ingenic_ecc_probe);