acpi_amba.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <graeme.gregory@linaro.org>
  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. {"ARMHC500", 0}, /* ARM CoreSight ETM4x */
  21. {"ARMHC501", 0}, /* ARM CoreSight ETR */
  22. {"ARMHC502", 0}, /* ARM CoreSight STM */
  23. {"ARMHC503", 0}, /* ARM CoreSight Debug */
  24. {"ARMHC979", 0}, /* ARM CoreSight TPIU */
  25. {"ARMHC97C", 0}, /* ARM CoreSight SoC-400 TMC, SoC-600 ETF/ETB */
  26. {"ARMHC98D", 0}, /* ARM CoreSight Dynamic Replicator */
  27. {"ARMHC9CA", 0}, /* ARM CoreSight CATU */
  28. {"ARMHC9FF", 0}, /* ARM CoreSight Dynamic Funnel */
  29. {"", 0},
  30. };
  31. static void amba_register_dummy_clk(void)
  32. {
  33. static struct clk *amba_dummy_clk;
  34. /* If clock already registered */
  35. if (amba_dummy_clk)
  36. return;
  37. amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, 0, 0);
  38. clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
  39. }
  40. static int amba_handler_attach(struct acpi_device *adev,
  41. const struct acpi_device_id *id)
  42. {
  43. struct amba_device *dev;
  44. struct resource_entry *rentry;
  45. struct list_head resource_list;
  46. bool address_found = false;
  47. int irq_no = 0;
  48. int ret;
  49. /* If the ACPI node already has a physical device attached, skip it. */
  50. if (adev->physical_node_count)
  51. return 0;
  52. dev = amba_device_alloc(dev_name(&adev->dev), 0, 0);
  53. if (!dev) {
  54. dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n",
  55. __func__);
  56. return -ENOMEM;
  57. }
  58. INIT_LIST_HEAD(&resource_list);
  59. ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
  60. if (ret < 0)
  61. goto err_free;
  62. list_for_each_entry(rentry, &resource_list, node) {
  63. switch (resource_type(rentry->res)) {
  64. case IORESOURCE_MEM:
  65. if (!address_found) {
  66. dev->res = *rentry->res;
  67. dev->res.name = dev_name(&dev->dev);
  68. address_found = true;
  69. }
  70. break;
  71. case IORESOURCE_IRQ:
  72. if (irq_no < AMBA_NR_IRQS)
  73. dev->irq[irq_no++] = rentry->res->start;
  74. break;
  75. default:
  76. dev_warn(&adev->dev, "Invalid resource\n");
  77. break;
  78. }
  79. }
  80. acpi_dev_free_resource_list(&resource_list);
  81. /*
  82. * If the ACPI node has a parent and that parent has a physical device
  83. * attached to it, that physical device should be the parent of
  84. * the amba device we are about to create.
  85. */
  86. if (adev->parent)
  87. dev->dev.parent = acpi_get_first_physical_node(adev->parent);
  88. ACPI_COMPANION_SET(&dev->dev, adev);
  89. ret = amba_device_add(dev, &iomem_resource);
  90. if (ret) {
  91. dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
  92. __func__, ret);
  93. goto err_free;
  94. }
  95. return 1;
  96. err_free:
  97. amba_device_put(dev);
  98. return ret;
  99. }
  100. static struct acpi_scan_handler amba_handler = {
  101. .ids = amba_id_list,
  102. .attach = amba_handler_attach,
  103. };
  104. void __init acpi_amba_init(void)
  105. {
  106. amba_register_dummy_clk();
  107. acpi_scan_add_handler(&amba_handler);
  108. }