2
0

740-v5.13-0006-net-dsa-b53-mmap-Add-device-tree-support.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From a5538a777b73b35750ed1ffff8c1ef539e861624 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <[email protected]>
  3. Date: Wed, 17 Mar 2021 10:23:17 +0100
  4. Subject: [PATCH] net: dsa: b53: mmap: Add device tree support
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Add device tree support to b53_mmap.c while keeping platform devices support.
  9. Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  10. Signed-off-by: David S. Miller <[email protected]>
  11. ---
  12. drivers/net/dsa/b53/b53_mmap.c | 55 ++++++++++++++++++++++++++++++++++
  13. 1 file changed, 55 insertions(+)
  14. --- a/drivers/net/dsa/b53/b53_mmap.c
  15. +++ b/drivers/net/dsa/b53/b53_mmap.c
  16. @@ -16,6 +16,7 @@
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. +#include <linux/bits.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/io.h>
  23. @@ -242,11 +243,65 @@ static const struct b53_io_ops b53_mmap_
  24. .phy_write16 = b53_mmap_phy_write16,
  25. };
  26. +static int b53_mmap_probe_of(struct platform_device *pdev,
  27. + struct b53_platform_data **ppdata)
  28. +{
  29. + struct device_node *np = pdev->dev.of_node;
  30. + struct device_node *of_ports, *of_port;
  31. + struct device *dev = &pdev->dev;
  32. + struct b53_platform_data *pdata;
  33. + void __iomem *mem;
  34. +
  35. + mem = devm_platform_ioremap_resource(pdev, 0);
  36. + if (IS_ERR(mem))
  37. + return PTR_ERR(mem);
  38. +
  39. + pdata = devm_kzalloc(dev, sizeof(struct b53_platform_data),
  40. + GFP_KERNEL);
  41. + if (!pdata)
  42. + return -ENOMEM;
  43. +
  44. + pdata->regs = mem;
  45. + pdata->chip_id = BCM63XX_DEVICE_ID;
  46. + pdata->big_endian = of_property_read_bool(np, "big-endian");
  47. +
  48. + of_ports = of_get_child_by_name(np, "ports");
  49. + if (!of_ports) {
  50. + dev_err(dev, "no ports child node found\n");
  51. + return -EINVAL;
  52. + }
  53. +
  54. + for_each_available_child_of_node(of_ports, of_port) {
  55. + u32 reg;
  56. +
  57. + if (of_property_read_u32(of_port, "reg", &reg))
  58. + continue;
  59. +
  60. + if (reg < B53_CPU_PORT)
  61. + pdata->enabled_ports |= BIT(reg);
  62. + }
  63. +
  64. + of_node_put(of_ports);
  65. + *ppdata = pdata;
  66. +
  67. + return 0;
  68. +}
  69. +
  70. static int b53_mmap_probe(struct platform_device *pdev)
  71. {
  72. + struct device_node *np = pdev->dev.of_node;
  73. struct b53_platform_data *pdata = pdev->dev.platform_data;
  74. struct b53_mmap_priv *priv;
  75. struct b53_device *dev;
  76. + int ret;
  77. +
  78. + if (!pdata && np) {
  79. + ret = b53_mmap_probe_of(pdev, &pdata);
  80. + if (ret) {
  81. + dev_err(&pdev->dev, "OF probe error\n");
  82. + return ret;
  83. + }
  84. + }
  85. if (!pdata)
  86. return -EINVAL;