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, 0, 0);
  32. clk_register_clkdev(amba_dummy_clk, "apb_pclk", NULL);
  33. }
  34. static int amba_handler_attach(struct acpi_device *adev,
  35. const struct acpi_device_id *id)
  36. {
  37. struct amba_device *dev;
  38. struct resource_entry *rentry;
  39. struct list_head resource_list;
  40. bool address_found = false;
  41. int irq_no = 0;
  42. int ret;
  43. /* If the ACPI node already has a physical device attached, skip it. */
  44. if (adev->physical_node_count)
  45. return 0;
  46. dev = amba_device_alloc(dev_name(&adev->dev), 0, 0);
  47. if (!dev) {
  48. dev_err(&adev->dev, "%s(): amba_device_alloc() failed\n",
  49. __func__);
  50. return -ENOMEM;
  51. }
  52. INIT_LIST_HEAD(&resource_list);
  53. ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
  54. if (ret < 0)
  55. goto err_free;
  56. list_for_each_entry(rentry, &resource_list, node) {
  57. switch (resource_type(rentry->res)) {
  58. case IORESOURCE_MEM:
  59. if (!address_found) {
  60. dev->res = *rentry->res;
  61. address_found = true;
  62. }
  63. break;
  64. case IORESOURCE_IRQ:
  65. if (irq_no < AMBA_NR_IRQS)
  66. dev->irq[irq_no++] = rentry->res->start;
  67. break;
  68. default:
  69. dev_warn(&adev->dev, "Invalid resource\n");
  70. break;
  71. }
  72. }
  73. acpi_dev_free_resource_list(&resource_list);
  74. /*
  75. * If the ACPI node has a parent and that parent has a physical device
  76. * attached to it, that physical device should be the parent of
  77. * the amba device we are about to create.
  78. */
  79. if (adev->parent)
  80. dev->dev.parent = acpi_get_first_physical_node(adev->parent);
  81. ACPI_COMPANION_SET(&dev->dev, adev);
  82. ret = amba_device_add(dev, &iomem_resource);
  83. if (ret) {
  84. dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
  85. __func__, ret);
  86. goto err_free;
  87. }
  88. return 1;
  89. err_free:
  90. amba_device_put(dev);
  91. return ret;
  92. }
  93. static struct acpi_scan_handler amba_handler = {
  94. .ids = amba_id_list,
  95. .attach = amba_handler_attach,
  96. };
  97. void __init acpi_amba_init(void)
  98. {
  99. amba_register_dummy_clk();
  100. acpi_scan_add_handler(&amba_handler);
  101. }