diff options
author | Wu Hao <hao.wu@intel.com> | 2019-08-11 22:49:58 -0400 |
---|---|---|
committer | Moritz Fischer <mdf@kernel.org> | 2019-09-03 22:35:41 -0400 |
commit | a80a4b82e7d8cf71bf495bda92072d1397b790a1 (patch) | |
tree | 05e00b0021564f246e3dc0195d00bc98e7a15a1a /drivers/fpga | |
parent | 084c3ff1b1d29300e5117f145ec6104ed2fd6b46 (diff) |
fpga: dfl: afu: convert platform_driver to use dev_groups
This patch takes advantage of driver core which helps to create
and remove sysfs attribute files, so there is no need to register
sysfs entries manually in dfl-afu platform river code.
Signed-off-by: Wu Hao <hao.wu@intel.com>
Acked-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
Diffstat (limited to 'drivers/fpga')
-rw-r--r-- | drivers/fpga/dfl-afu-main.c | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c index e50c45ed40ac..e955149722bd 100644 --- a/drivers/fpga/dfl-afu-main.c +++ b/drivers/fpga/dfl-afu-main.c | |||
@@ -282,24 +282,17 @@ static struct attribute *port_hdr_attrs[] = { | |||
282 | &dev_attr_power_state.attr, | 282 | &dev_attr_power_state.attr, |
283 | NULL, | 283 | NULL, |
284 | }; | 284 | }; |
285 | ATTRIBUTE_GROUPS(port_hdr); | 285 | |
286 | static const struct attribute_group port_hdr_group = { | ||
287 | .attrs = port_hdr_attrs, | ||
288 | }; | ||
286 | 289 | ||
287 | static int port_hdr_init(struct platform_device *pdev, | 290 | static int port_hdr_init(struct platform_device *pdev, |
288 | struct dfl_feature *feature) | 291 | struct dfl_feature *feature) |
289 | { | 292 | { |
290 | dev_dbg(&pdev->dev, "PORT HDR Init.\n"); | ||
291 | |||
292 | port_reset(pdev); | 293 | port_reset(pdev); |
293 | 294 | ||
294 | return device_add_groups(&pdev->dev, port_hdr_groups); | 295 | return 0; |
295 | } | ||
296 | |||
297 | static void port_hdr_uinit(struct platform_device *pdev, | ||
298 | struct dfl_feature *feature) | ||
299 | { | ||
300 | dev_dbg(&pdev->dev, "PORT HDR UInit.\n"); | ||
301 | |||
302 | device_remove_groups(&pdev->dev, port_hdr_groups); | ||
303 | } | 296 | } |
304 | 297 | ||
305 | static long | 298 | static long |
@@ -330,7 +323,6 @@ static const struct dfl_feature_id port_hdr_id_table[] = { | |||
330 | 323 | ||
331 | static const struct dfl_feature_ops port_hdr_ops = { | 324 | static const struct dfl_feature_ops port_hdr_ops = { |
332 | .init = port_hdr_init, | 325 | .init = port_hdr_init, |
333 | .uinit = port_hdr_uinit, | ||
334 | .ioctl = port_hdr_ioctl, | 326 | .ioctl = port_hdr_ioctl, |
335 | }; | 327 | }; |
336 | 328 | ||
@@ -361,32 +353,37 @@ static struct attribute *port_afu_attrs[] = { | |||
361 | &dev_attr_afu_id.attr, | 353 | &dev_attr_afu_id.attr, |
362 | NULL | 354 | NULL |
363 | }; | 355 | }; |
364 | ATTRIBUTE_GROUPS(port_afu); | ||
365 | 356 | ||
366 | static int port_afu_init(struct platform_device *pdev, | 357 | static umode_t port_afu_attrs_visible(struct kobject *kobj, |
367 | struct dfl_feature *feature) | 358 | struct attribute *attr, int n) |
368 | { | 359 | { |
369 | struct resource *res = &pdev->resource[feature->resource_index]; | 360 | struct device *dev = kobj_to_dev(kobj); |
370 | int ret; | ||
371 | |||
372 | dev_dbg(&pdev->dev, "PORT AFU Init.\n"); | ||
373 | 361 | ||
374 | ret = afu_mmio_region_add(dev_get_platdata(&pdev->dev), | 362 | /* |
375 | DFL_PORT_REGION_INDEX_AFU, resource_size(res), | 363 | * sysfs entries are visible only if related private feature is |
376 | res->start, DFL_PORT_REGION_READ | | 364 | * enumerated. |
377 | DFL_PORT_REGION_WRITE | DFL_PORT_REGION_MMAP); | 365 | */ |
378 | if (ret) | 366 | if (!dfl_get_feature_by_id(dev, PORT_FEATURE_ID_AFU)) |
379 | return ret; | 367 | return 0; |
380 | 368 | ||
381 | return device_add_groups(&pdev->dev, port_afu_groups); | 369 | return attr->mode; |
382 | } | 370 | } |
383 | 371 | ||
384 | static void port_afu_uinit(struct platform_device *pdev, | 372 | static const struct attribute_group port_afu_group = { |
385 | struct dfl_feature *feature) | 373 | .attrs = port_afu_attrs, |
374 | .is_visible = port_afu_attrs_visible, | ||
375 | }; | ||
376 | |||
377 | static int port_afu_init(struct platform_device *pdev, | ||
378 | struct dfl_feature *feature) | ||
386 | { | 379 | { |
387 | dev_dbg(&pdev->dev, "PORT AFU UInit.\n"); | 380 | struct resource *res = &pdev->resource[feature->resource_index]; |
388 | 381 | ||
389 | device_remove_groups(&pdev->dev, port_afu_groups); | 382 | return afu_mmio_region_add(dev_get_platdata(&pdev->dev), |
383 | DFL_PORT_REGION_INDEX_AFU, | ||
384 | resource_size(res), res->start, | ||
385 | DFL_PORT_REGION_MMAP | DFL_PORT_REGION_READ | | ||
386 | DFL_PORT_REGION_WRITE); | ||
390 | } | 387 | } |
391 | 388 | ||
392 | static const struct dfl_feature_id port_afu_id_table[] = { | 389 | static const struct dfl_feature_id port_afu_id_table[] = { |
@@ -396,7 +393,6 @@ static const struct dfl_feature_id port_afu_id_table[] = { | |||
396 | 393 | ||
397 | static const struct dfl_feature_ops port_afu_ops = { | 394 | static const struct dfl_feature_ops port_afu_ops = { |
398 | .init = port_afu_init, | 395 | .init = port_afu_init, |
399 | .uinit = port_afu_uinit, | ||
400 | }; | 396 | }; |
401 | 397 | ||
402 | static struct dfl_feature_driver port_feature_drvs[] = { | 398 | static struct dfl_feature_driver port_feature_drvs[] = { |
@@ -748,9 +744,16 @@ static int afu_remove(struct platform_device *pdev) | |||
748 | return 0; | 744 | return 0; |
749 | } | 745 | } |
750 | 746 | ||
747 | static const struct attribute_group *afu_dev_groups[] = { | ||
748 | &port_hdr_group, | ||
749 | &port_afu_group, | ||
750 | NULL | ||
751 | }; | ||
752 | |||
751 | static struct platform_driver afu_driver = { | 753 | static struct platform_driver afu_driver = { |
752 | .driver = { | 754 | .driver = { |
753 | .name = DFL_FPGA_FEATURE_DEV_PORT, | 755 | .name = DFL_FPGA_FEATURE_DEV_PORT, |
756 | .dev_groups = afu_dev_groups, | ||
754 | }, | 757 | }, |
755 | .probe = afu_probe, | 758 | .probe = afu_probe, |
756 | .remove = afu_remove, | 759 | .remove = afu_remove, |