acpi_apd.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * AMD ACPI support for ACPI2platform device.
  3. *
  4. * Copyright (c) 2014,2015 AMD Corporation.
  5. * Authors: Ken Xue <Ken.Xue@amd.com>
  6. * Wu, Jeff <Jeff.Wu@amd.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/clk-provider.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/pm_domain.h>
  15. #include <linux/clkdev.h>
  16. #include <linux/acpi.h>
  17. #include <linux/err.h>
  18. #include <linux/pm.h>
  19. #include "internal.h"
  20. ACPI_MODULE_NAME("acpi_apd");
  21. struct apd_private_data;
  22. /**
  23. * ACPI_APD_SYSFS : add device attributes in sysfs
  24. * ACPI_APD_PM : attach power domain to device
  25. */
  26. #define ACPI_APD_SYSFS BIT(0)
  27. #define ACPI_APD_PM BIT(1)
  28. /**
  29. * struct apd_device_desc - a descriptor for apd device
  30. * @flags: device flags like %ACPI_APD_SYSFS, %ACPI_APD_PM
  31. * @fixed_clk_rate: fixed rate input clock source for acpi device;
  32. * 0 means no fixed rate input clock source
  33. * @setup: a hook routine to set device resource during create platform device
  34. *
  35. * Device description defined as acpi_device_id.driver_data
  36. */
  37. struct apd_device_desc {
  38. unsigned int flags;
  39. unsigned int fixed_clk_rate;
  40. struct property_entry *properties;
  41. int (*setup)(struct apd_private_data *pdata);
  42. };
  43. struct apd_private_data {
  44. struct clk *clk;
  45. struct acpi_device *adev;
  46. const struct apd_device_desc *dev_desc;
  47. };
  48. #if defined(CONFIG_X86_AMD_PLATFORM_DEVICE) || defined(CONFIG_ARM64)
  49. #define APD_ADDR(desc) ((unsigned long)&desc)
  50. static int acpi_apd_setup(struct apd_private_data *pdata)
  51. {
  52. const struct apd_device_desc *dev_desc = pdata->dev_desc;
  53. struct clk *clk = ERR_PTR(-ENODEV);
  54. if (dev_desc->fixed_clk_rate) {
  55. clk = clk_register_fixed_rate(&pdata->adev->dev,
  56. dev_name(&pdata->adev->dev),
  57. NULL, 0, dev_desc->fixed_clk_rate);
  58. clk_register_clkdev(clk, NULL, dev_name(&pdata->adev->dev));
  59. pdata->clk = clk;
  60. }
  61. return 0;
  62. }
  63. #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
  64. static const struct apd_device_desc cz_i2c_desc = {
  65. .setup = acpi_apd_setup,
  66. .fixed_clk_rate = 133000000,
  67. };
  68. static const struct apd_device_desc wt_i2c_desc = {
  69. .setup = acpi_apd_setup,
  70. .fixed_clk_rate = 150000000,
  71. };
  72. static struct property_entry uart_properties[] = {
  73. PROPERTY_ENTRY_U32("reg-io-width", 4),
  74. PROPERTY_ENTRY_U32("reg-shift", 2),
  75. PROPERTY_ENTRY_BOOL("snps,uart-16550-compatible"),
  76. { },
  77. };
  78. static const struct apd_device_desc cz_uart_desc = {
  79. .setup = acpi_apd_setup,
  80. .fixed_clk_rate = 48000000,
  81. .properties = uart_properties,
  82. };
  83. #endif
  84. #ifdef CONFIG_ARM64
  85. static const struct apd_device_desc xgene_i2c_desc = {
  86. .setup = acpi_apd_setup,
  87. .fixed_clk_rate = 100000000,
  88. };
  89. static const struct apd_device_desc vulcan_spi_desc = {
  90. .setup = acpi_apd_setup,
  91. .fixed_clk_rate = 133000000,
  92. };
  93. #endif
  94. #else
  95. #define APD_ADDR(desc) (0UL)
  96. #endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
  97. /**
  98. * Create platform device during acpi scan attach handle.
  99. * Return value > 0 on success of creating device.
  100. */
  101. static int acpi_apd_create_device(struct acpi_device *adev,
  102. const struct acpi_device_id *id)
  103. {
  104. const struct apd_device_desc *dev_desc = (void *)id->driver_data;
  105. struct apd_private_data *pdata;
  106. struct platform_device *pdev;
  107. int ret;
  108. if (!dev_desc) {
  109. pdev = acpi_create_platform_device(adev, NULL);
  110. return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
  111. }
  112. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  113. if (!pdata)
  114. return -ENOMEM;
  115. pdata->adev = adev;
  116. pdata->dev_desc = dev_desc;
  117. if (dev_desc->setup) {
  118. ret = dev_desc->setup(pdata);
  119. if (ret)
  120. goto err_out;
  121. }
  122. adev->driver_data = pdata;
  123. pdev = acpi_create_platform_device(adev, dev_desc->properties);
  124. if (!IS_ERR_OR_NULL(pdev))
  125. return 1;
  126. ret = PTR_ERR(pdev);
  127. adev->driver_data = NULL;
  128. err_out:
  129. kfree(pdata);
  130. return ret;
  131. }
  132. static const struct acpi_device_id acpi_apd_device_ids[] = {
  133. /* Generic apd devices */
  134. #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
  135. { "AMD0010", APD_ADDR(cz_i2c_desc) },
  136. { "AMDI0010", APD_ADDR(wt_i2c_desc) },
  137. { "AMD0020", APD_ADDR(cz_uart_desc) },
  138. { "AMDI0020", APD_ADDR(cz_uart_desc) },
  139. { "AMD0030", },
  140. #endif
  141. #ifdef CONFIG_ARM64
  142. { "APMC0D0F", APD_ADDR(xgene_i2c_desc) },
  143. { "BRCM900D", APD_ADDR(vulcan_spi_desc) },
  144. #endif
  145. { }
  146. };
  147. static struct acpi_scan_handler apd_handler = {
  148. .ids = acpi_apd_device_ids,
  149. .attach = acpi_apd_create_device,
  150. };
  151. void __init acpi_apd_init(void)
  152. {
  153. acpi_scan_add_handler(&apd_handler);
  154. }