Merge branch 'next' of git://git.infradead.org/users/vkoul/slave-dma
[linux/fpc-iii.git] / drivers / acpi / acpi_apd.c
blob3984ea96e5f762de82fe5e4fb140999d9b434f48
1 /*
2 * AMD ACPI support for ACPI2platform device.
4 * Copyright (c) 2014,2015 AMD Corporation.
5 * Authors: Ken Xue <Ken.Xue@amd.com>
6 * Wu, Jeff <Jeff.Wu@amd.com>
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.
13 #include <linux/clk-provider.h>
14 #include <linux/platform_device.h>
15 #include <linux/pm_domain.h>
16 #include <linux/clkdev.h>
17 #include <linux/acpi.h>
18 #include <linux/err.h>
19 #include <linux/clk.h>
20 #include <linux/pm.h>
22 #include "internal.h"
24 ACPI_MODULE_NAME("acpi_apd");
25 struct apd_private_data;
27 /**
28 * ACPI_APD_SYSFS : add device attributes in sysfs
29 * ACPI_APD_PM : attach power domain to device
31 #define ACPI_APD_SYSFS BIT(0)
32 #define ACPI_APD_PM BIT(1)
34 /**
35 * struct apd_device_desc - a descriptor for apd device
36 * @flags: device flags like %ACPI_APD_SYSFS, %ACPI_APD_PM
37 * @fixed_clk_rate: fixed rate input clock source for acpi device;
38 * 0 means no fixed rate input clock source
39 * @setup: a hook routine to set device resource during create platform device
41 * Device description defined as acpi_device_id.driver_data
43 struct apd_device_desc {
44 unsigned int flags;
45 unsigned int fixed_clk_rate;
46 int (*setup)(struct apd_private_data *pdata);
49 struct apd_private_data {
50 struct clk *clk;
51 struct acpi_device *adev;
52 const struct apd_device_desc *dev_desc;
55 #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
56 #define APD_ADDR(desc) ((unsigned long)&desc)
58 static int acpi_apd_setup(struct apd_private_data *pdata)
60 const struct apd_device_desc *dev_desc = pdata->dev_desc;
61 struct clk *clk = ERR_PTR(-ENODEV);
63 if (dev_desc->fixed_clk_rate) {
64 clk = clk_register_fixed_rate(&pdata->adev->dev,
65 dev_name(&pdata->adev->dev),
66 NULL, CLK_IS_ROOT,
67 dev_desc->fixed_clk_rate);
68 clk_register_clkdev(clk, NULL, dev_name(&pdata->adev->dev));
69 pdata->clk = clk;
72 return 0;
75 static struct apd_device_desc cz_i2c_desc = {
76 .setup = acpi_apd_setup,
77 .fixed_clk_rate = 133000000,
80 static struct apd_device_desc cz_uart_desc = {
81 .setup = acpi_apd_setup,
82 .fixed_clk_rate = 48000000,
85 #else
87 #define APD_ADDR(desc) (0UL)
89 #endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
91 /**
92 * Create platform device during acpi scan attach handle.
93 * Return value > 0 on success of creating device.
95 static int acpi_apd_create_device(struct acpi_device *adev,
96 const struct acpi_device_id *id)
98 const struct apd_device_desc *dev_desc = (void *)id->driver_data;
99 struct apd_private_data *pdata;
100 struct platform_device *pdev;
101 int ret;
103 if (!dev_desc) {
104 pdev = acpi_create_platform_device(adev);
105 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
108 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
109 if (!pdata)
110 return -ENOMEM;
112 pdata->adev = adev;
113 pdata->dev_desc = dev_desc;
115 if (dev_desc->setup) {
116 ret = dev_desc->setup(pdata);
117 if (ret)
118 goto err_out;
121 adev->driver_data = pdata;
122 pdev = acpi_create_platform_device(adev);
123 if (!IS_ERR_OR_NULL(pdev))
124 return 1;
126 ret = PTR_ERR(pdev);
127 adev->driver_data = NULL;
129 err_out:
130 kfree(pdata);
131 return ret;
134 static const struct acpi_device_id acpi_apd_device_ids[] = {
135 /* Generic apd devices */
136 { "AMD0010", APD_ADDR(cz_i2c_desc) },
137 { "AMD0020", APD_ADDR(cz_uart_desc) },
138 { "AMD0030", },
142 static struct acpi_scan_handler apd_handler = {
143 .ids = acpi_apd_device_ids,
144 .attach = acpi_apd_create_device,
147 void __init acpi_apd_init(void)
149 acpi_scan_add_handler(&apd_handler);