acpi_amba.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * ACPI support for platform bus type.
  3. *
  4. * Copyright (C) 2015, Linaro Ltd
  5. * Author: Graeme Gregory <graeme.gregory@linaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/acpi.h>
  12. #include <linux/amba/bus.h>
  13. #include <linux/clkdev.h>
  14. #include <linux/clk-provider.h>
  15. #include <linux/device.h>
  16. #include <linux/err.h>
  17. #include <linux/ioport.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include "internal.h"
  21. static const struct acpi_device_id amba_id_list[] = {
  22. {"ARMH0061", 0}, /* PL061 GPIO Device */
  23. {"", 0},
  24. };
  25. static void amba_register_dummy_clk(void)
  26. {
  27. static struct clk *amba_dummy_clk;
  28. /* If clock already registered */
  29. if (amba_dummy_clk)
  30. return;
  31. amba_dummy_clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL,
  32. CLK_IS_ROOT, 0);
  33. clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
  34. }
  35. static int amba_handler_attach(struct acpi_device *adev,
  36. const struct acpi_device_id *id)
  37. {
  38. struct amba_device *dev;
  39. struct resource_entry *rentry;
  40. struct list_head resource_list;
  41. bool address_found = false;
  42. int irq_no = 0;
  43. int ret;
  44. /* If the ACPI node already has a physical device attached, skip it. */
  45. if (adev->physical_node_count)
  46. return 0;
  47. dev = amba_device_alloc(dev_name(&adev->dev), 0, 0);
  48. if (!dev) {
  49. dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n",
  50. __func__);
  51. return -ENOMEM;
  52. }
  53. INIT_LIST_HEAD(&resource_list);
  54. ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
  55. if (ret < 0)
  56. goto err_free;
  57. list_for_each_entry(rentry, &resource_list, node) {
  58. switch (resource_type(rentry->res)) {
  59. case IORESOURCE_MEM:
  60. if (!address_found) {
  61. dev->res = *rentry->res;
  62. address_found = true;
  63. }
  64. break;
  65. case IORESOURCE_IRQ:
  66. if (irq_no < AMBA_NR_IRQS)
  67. dev->irq[irq_no++] = rentry->res->start;
  68. break;
  69. default:
  70. dev_warn(&adev->dev, "Invalid resource\n");
  71. break;
  72. }
  73. }
  74. acpi_dev_free_resource_list(&resource_list);
  75. /*
  76. * If the ACPI node has a parent and that parent has a physical device
  77. * attached to it, that physical device should be the parent of
  78. * the amba device we are about to create.
  79. */
  80. if (adev->parent)
  81. dev->dev.parent = acpi_get_first_physical_node(adev->parent);
  82. ACPI_COMPANION_SET(&dev->dev, adev);
  83. ret = amba_device_add(dev, &iomem_resource);
  84. if (ret) {
  85. dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
  86. __func__, ret);
  87. goto err_free;
  88. }
  89. return 1;
  90. err_free:
  91. amba_device_put(dev);
  92. return ret;
  93. }
  94. static struct acpi_scan_handler amba_handler = {
  95. .ids = amba_id_list,
  96. .attach = amba_handler_attach,
  97. };
  98. void __init acpi_amba_init(void)
  99. {
  100. amba_register_dummy_clk();
  101. acpi_scan_add_handler(&amba_handler);
  102. }