acpi_lpss.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * ACPI support for Intel Lynxpoint LPSS.
  3. *
  4. * Copyright (C) 2013, Intel Corporation
  5. * Authors: Mika Westerberg <mika.westerberg@linux.intel.com>
  6. * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/acpi.h>
  13. #include <linux/clk.h>
  14. #include <linux/clkdev.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/platform_data/clk-lpss.h>
  20. #include "internal.h"
  21. ACPI_MODULE_NAME("acpi_lpss");
  22. #define LPSS_CLK_OFFSET 0x800
  23. #define LPSS_CLK_SIZE 0x04
  24. struct lpss_device_desc {
  25. bool clk_required;
  26. const char *clk_parent;
  27. };
  28. struct lpss_private_data {
  29. void __iomem *mmio_base;
  30. resource_size_t mmio_size;
  31. struct clk *clk;
  32. const struct lpss_device_desc *dev_desc;
  33. };
  34. static struct lpss_device_desc lpt_dev_desc = {
  35. .clk_required = true,
  36. .clk_parent = "lpss_clk",
  37. };
  38. static const struct acpi_device_id acpi_lpss_device_ids[] = {
  39. /* Lynxpoint LPSS devices */
  40. { "INT33C0", (unsigned long)&lpt_dev_desc },
  41. { "INT33C1", (unsigned long)&lpt_dev_desc },
  42. { "INT33C2", (unsigned long)&lpt_dev_desc },
  43. { "INT33C3", (unsigned long)&lpt_dev_desc },
  44. { "INT33C4", (unsigned long)&lpt_dev_desc },
  45. { "INT33C5", (unsigned long)&lpt_dev_desc },
  46. { "INT33C6", },
  47. { "INT33C7", },
  48. { }
  49. };
  50. static int is_memory(struct acpi_resource *res, void *not_used)
  51. {
  52. struct resource r;
  53. return !acpi_dev_resource_memory(res, &r);
  54. }
  55. /* LPSS main clock device. */
  56. static struct platform_device *lpss_clk_dev;
  57. static inline void lpt_register_clock_device(void)
  58. {
  59. lpss_clk_dev = platform_device_register_simple("clk-lpt", -1, NULL, 0);
  60. }
  61. static int register_device_clock(struct acpi_device *adev,
  62. struct lpss_private_data *pdata)
  63. {
  64. const struct lpss_device_desc *dev_desc = pdata->dev_desc;
  65. if (!lpss_clk_dev)
  66. lpt_register_clock_device();
  67. if (!dev_desc->clk_parent || !pdata->mmio_base
  68. || pdata->mmio_size < LPSS_CLK_OFFSET + LPSS_CLK_SIZE)
  69. return -ENODATA;
  70. pdata->clk = clk_register_gate(NULL, dev_name(&adev->dev),
  71. dev_desc->clk_parent, 0,
  72. pdata->mmio_base + LPSS_CLK_OFFSET,
  73. 0, 0, NULL);
  74. if (IS_ERR(pdata->clk))
  75. return PTR_ERR(pdata->clk);
  76. clk_register_clkdev(pdata->clk, NULL, dev_name(&adev->dev));
  77. return 0;
  78. }
  79. static int acpi_lpss_create_device(struct acpi_device *adev,
  80. const struct acpi_device_id *id)
  81. {
  82. struct lpss_device_desc *dev_desc;
  83. struct lpss_private_data *pdata;
  84. struct resource_list_entry *rentry;
  85. struct list_head resource_list;
  86. int ret;
  87. dev_desc = (struct lpss_device_desc *)id->driver_data;
  88. if (!dev_desc)
  89. return acpi_create_platform_device(adev, id);
  90. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  91. if (!pdata)
  92. return -ENOMEM;
  93. INIT_LIST_HEAD(&resource_list);
  94. ret = acpi_dev_get_resources(adev, &resource_list, is_memory, NULL);
  95. if (ret < 0)
  96. goto err_out;
  97. list_for_each_entry(rentry, &resource_list, node)
  98. if (resource_type(&rentry->res) == IORESOURCE_MEM) {
  99. pdata->mmio_size = resource_size(&rentry->res);
  100. pdata->mmio_base = ioremap(rentry->res.start,
  101. pdata->mmio_size);
  102. pdata->dev_desc = dev_desc;
  103. break;
  104. }
  105. acpi_dev_free_resource_list(&resource_list);
  106. if (dev_desc->clk_required) {
  107. ret = register_device_clock(adev, pdata);
  108. if (ret) {
  109. /*
  110. * Skip the device, but don't terminate the namespace
  111. * scan.
  112. */
  113. ret = 0;
  114. goto err_out;
  115. }
  116. }
  117. adev->driver_data = pdata;
  118. ret = acpi_create_platform_device(adev, id);
  119. if (ret > 0)
  120. return ret;
  121. adev->driver_data = NULL;
  122. err_out:
  123. kfree(pdata);
  124. return ret;
  125. }
  126. static struct acpi_scan_handler lpss_handler = {
  127. .ids = acpi_lpss_device_ids,
  128. .attach = acpi_lpss_create_device,
  129. };
  130. void __init acpi_lpss_init(void)
  131. {
  132. if (!lpt_clk_init())
  133. acpi_scan_add_handler(&lpss_handler);
  134. }