diff options
Diffstat (limited to 'drivers/fpga/fpga-mgr.c')
-rw-r--r-- | drivers/fpga/fpga-mgr.c | 76 |
1 files changed, 54 insertions, 22 deletions
diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c index 953dc9195937..b690e65d55fe 100644 --- a/drivers/fpga/fpga-mgr.c +++ b/drivers/fpga/fpga-mgr.c | |||
@@ -39,7 +39,8 @@ static struct class *fpga_mgr_class; | |||
39 | * Step the low level fpga manager through the device-specific steps of getting | 39 | * Step the low level fpga manager through the device-specific steps of getting |
40 | * an FPGA ready to be configured, writing the image to it, then doing whatever | 40 | * an FPGA ready to be configured, writing the image to it, then doing whatever |
41 | * post-configuration steps necessary. This code assumes the caller got the | 41 | * post-configuration steps necessary. This code assumes the caller got the |
42 | * mgr pointer from of_fpga_mgr_get() and checked that it is not an error code. | 42 | * mgr pointer from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is |
43 | * not an error code. | ||
43 | * | 44 | * |
44 | * Return: 0 on success, negative error code otherwise. | 45 | * Return: 0 on success, negative error code otherwise. |
45 | */ | 46 | */ |
@@ -99,7 +100,8 @@ EXPORT_SYMBOL_GPL(fpga_mgr_buf_load); | |||
99 | * Request an FPGA image using the firmware class, then write out to the FPGA. | 100 | * Request an FPGA image using the firmware class, then write out to the FPGA. |
100 | * Update the state before each step to provide info on what step failed if | 101 | * Update the state before each step to provide info on what step failed if |
101 | * there is a failure. This code assumes the caller got the mgr pointer | 102 | * there is a failure. This code assumes the caller got the mgr pointer |
102 | * from of_fpga_mgr_get() and checked that it is not an error code. | 103 | * from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is not an error |
104 | * code. | ||
103 | * | 105 | * |
104 | * Return: 0 on success, negative error code otherwise. | 106 | * Return: 0 on success, negative error code otherwise. |
105 | */ | 107 | */ |
@@ -181,30 +183,11 @@ static struct attribute *fpga_mgr_attrs[] = { | |||
181 | }; | 183 | }; |
182 | ATTRIBUTE_GROUPS(fpga_mgr); | 184 | ATTRIBUTE_GROUPS(fpga_mgr); |
183 | 185 | ||
184 | static int fpga_mgr_of_node_match(struct device *dev, const void *data) | 186 | struct fpga_manager *__fpga_mgr_get(struct device *dev) |
185 | { | ||
186 | return dev->of_node == data; | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * of_fpga_mgr_get - get an exclusive reference to a fpga mgr | ||
191 | * @node: device node | ||
192 | * | ||
193 | * Given a device node, get an exclusive reference to a fpga mgr. | ||
194 | * | ||
195 | * Return: fpga manager struct or IS_ERR() condition containing error code. | ||
196 | */ | ||
197 | struct fpga_manager *of_fpga_mgr_get(struct device_node *node) | ||
198 | { | 187 | { |
199 | struct fpga_manager *mgr; | 188 | struct fpga_manager *mgr; |
200 | struct device *dev; | ||
201 | int ret = -ENODEV; | 189 | int ret = -ENODEV; |
202 | 190 | ||
203 | dev = class_find_device(fpga_mgr_class, NULL, node, | ||
204 | fpga_mgr_of_node_match); | ||
205 | if (!dev) | ||
206 | return ERR_PTR(-ENODEV); | ||
207 | |||
208 | mgr = to_fpga_manager(dev); | 191 | mgr = to_fpga_manager(dev); |
209 | if (!mgr) | 192 | if (!mgr) |
210 | goto err_dev; | 193 | goto err_dev; |
@@ -226,6 +209,55 @@ err_dev: | |||
226 | put_device(dev); | 209 | put_device(dev); |
227 | return ERR_PTR(ret); | 210 | return ERR_PTR(ret); |
228 | } | 211 | } |
212 | |||
213 | static int fpga_mgr_dev_match(struct device *dev, const void *data) | ||
214 | { | ||
215 | return dev->parent == data; | ||
216 | } | ||
217 | |||
218 | /** | ||
219 | * fpga_mgr_get - get an exclusive reference to a fpga mgr | ||
220 | * @dev: parent device that fpga mgr was registered with | ||
221 | * | ||
222 | * Given a device, get an exclusive reference to a fpga mgr. | ||
223 | * | ||
224 | * Return: fpga manager struct or IS_ERR() condition containing error code. | ||
225 | */ | ||
226 | struct fpga_manager *fpga_mgr_get(struct device *dev) | ||
227 | { | ||
228 | struct device *mgr_dev = class_find_device(fpga_mgr_class, NULL, dev, | ||
229 | fpga_mgr_dev_match); | ||
230 | if (!mgr_dev) | ||
231 | return ERR_PTR(-ENODEV); | ||
232 | |||
233 | return __fpga_mgr_get(mgr_dev); | ||
234 | } | ||
235 | EXPORT_SYMBOL_GPL(fpga_mgr_get); | ||
236 | |||
237 | static int fpga_mgr_of_node_match(struct device *dev, const void *data) | ||
238 | { | ||
239 | return dev->of_node == data; | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * of_fpga_mgr_get - get an exclusive reference to a fpga mgr | ||
244 | * @node: device node | ||
245 | * | ||
246 | * Given a device node, get an exclusive reference to a fpga mgr. | ||
247 | * | ||
248 | * Return: fpga manager struct or IS_ERR() condition containing error code. | ||
249 | */ | ||
250 | struct fpga_manager *of_fpga_mgr_get(struct device_node *node) | ||
251 | { | ||
252 | struct device *dev; | ||
253 | |||
254 | dev = class_find_device(fpga_mgr_class, NULL, node, | ||
255 | fpga_mgr_of_node_match); | ||
256 | if (!dev) | ||
257 | return ERR_PTR(-ENODEV); | ||
258 | |||
259 | return __fpga_mgr_get(dev); | ||
260 | } | ||
229 | EXPORT_SYMBOL_GPL(of_fpga_mgr_get); | 261 | EXPORT_SYMBOL_GPL(of_fpga_mgr_get); |
230 | 262 | ||
231 | /** | 263 | /** |