acpi_amba.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * ACPI support for platform bus type.
  4. *
  5. * Copyright (C) 2015, Linaro Ltd
  6. * Author: Graeme Gregory <[email protected]>
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/amba/bus.h>
  10. #include <linux/clkdev.h>
  11. #include <linux/clk-provider.h>
  12. #include <linux/device.h>
  13. #include <linux/err.h>
  14. #include <linux/ioport.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include "internal.h"
  18. static const struct acpi_device_id amba_id_list[] = {
  19. {"ARMH0061", 0}, /* PL061 GPIO Device */
  20. {"ARMH0330", 0}, /* ARM DMA Controller DMA-330 */
  21. {"ARMHC500", 0}, /* ARM CoreSight ETM4x */
  22. {"ARMHC501", 0}, /* ARM CoreSight ETR */
  23. {"ARMHC502", 0}, /* ARM CoreSight STM */
  24. {"ARMHC503", 0}, /* ARM CoreSight Debug */
  25. {"ARMHC979", 0}, /* ARM CoreSight TPIU */
  26. {"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
  27. {"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */
  28. {"ARMHC9CA", 0}, /* ARM CoreSight CATU */
  29. {"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */
  30. {"", 0},
  31. };
  32. static void amba_register_dummy_clk(void)
  33. {
  34. static struct clk *amba_dummy_clk;
  35. /* If clock already registered */
  36. if (amba_dummy_clk)
  37. return;
  38. amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 0);
  39. clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
  40. }
  41. static int amba_handler_attach(struct acpi_device *adev,
  42. const struct acpi_device_id *id)
  43. {
  44. struct acpi_device *parent = acpi_dev_parent(adev);
  45. struct amba_device *dev;
  46. struct resource_entry *rentry;
  47. struct list_head resource_list;
  48. bool address_found = false;
  49. int irq_no = 0;
  50. int ret;
  51. /* If the ACPI node already has a physical device attached, skip it. */
  52. if (adev->physical_node_count)
  53. return 0;
  54. dev = amba_device_alloc(dev_name(&adev->dev), 0, 0);
  55. if (!dev) {
  56. dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n",
  57. __func__);
  58. return -ENOMEM;
  59. }
  60. INIT_LIST_HEAD(&resource_list);
  61. ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
  62. if (ret < 0)
  63. goto err_free;
  64. list_for_each_entry(rentry, &resource_list, node) {
  65. switch (resource_type(rentry->res)) {
  66. case IORESOURCE_MEM:
  67. if (!address_found) {
  68. dev->res = *rentry->res;
  69. dev->res.name = dev_name(&dev->dev);
  70. address_found = true;
  71. }
  72. break;
  73. case IORESOURCE_IRQ:
  74. if (irq_no < AMBA_NR_IRQS)
  75. dev->irq[irq_no++] = rentry->res->start;
  76. break;
  77. default:
  78. dev_warn(&adev->dev, "Invalid resource\n");
  79. break;
  80. }
  81. }
  82. acpi_dev_free_resource_list(&resource_list);
  83. /*
  84. * If the ACPI node has a parent and that parent has a physical device
  85. * attached to it, that physical device should be the parent of
  86. * the amba device we are about to create.
  87. */
  88. if (parent)
  89. dev->dev.parent = acpi_get_first_physical_node(parent);
  90. ACPI_COMPANION_SET(&dev->dev, adev);
  91. ret = amba_device_add(dev, &iomem_resource);
  92. if (ret) {
  93. dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
  94. __func__, ret);
  95. goto err_free;
  96. }
  97. return 1;
  98. err_free:
  99. amba_device_put(dev);
  100. return ret;
  101. }
  102. static struct acpi_scan_handler amba_handler = {
  103. .ids = amba_id_list,
  104. .attach = amba_handler_attach,
  105. };
  106. void __init acpi_amba_init(void)
  107. {
  108. amba_register_dummy_clk();
  109. acpi_scan_add_handler(&amba_handler);
  110. }