0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/acpi.h>
0011 #include <linux/clkdev.h>
0012 #include <linux/clk-provider.h>
0013 #include <linux/err.h>
0014 #include <linux/io.h>
0015 #include <linux/platform_data/clk-fch.h>
0016 #include <linux/platform_device.h>
0017
0018 #include "internal.h"
0019
0020 struct apd_private_data;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 struct apd_device_desc {
0032 unsigned int fixed_clk_rate;
0033 struct property_entry *properties;
0034 int (*setup)(struct apd_private_data *pdata);
0035 };
0036
0037 struct apd_private_data {
0038 struct clk *clk;
0039 struct acpi_device *adev;
0040 const struct apd_device_desc *dev_desc;
0041 };
0042
0043 #if defined(CONFIG_X86_AMD_PLATFORM_DEVICE) || defined(CONFIG_ARM64)
0044 #define APD_ADDR(desc) ((unsigned long)&desc)
0045
0046 static int acpi_apd_setup(struct apd_private_data *pdata)
0047 {
0048 const struct apd_device_desc *dev_desc = pdata->dev_desc;
0049 struct clk *clk;
0050
0051 if (dev_desc->fixed_clk_rate) {
0052 clk = clk_register_fixed_rate(&pdata->adev->dev,
0053 dev_name(&pdata->adev->dev),
0054 NULL, 0, dev_desc->fixed_clk_rate);
0055 clk_register_clkdev(clk, NULL, dev_name(&pdata->adev->dev));
0056 pdata->clk = clk;
0057 }
0058
0059 return 0;
0060 }
0061
0062 #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
0063 static int misc_check_res(struct acpi_resource *ares, void *data)
0064 {
0065 struct resource res;
0066
0067 return !acpi_dev_resource_memory(ares, &res);
0068 }
0069
0070 static int fch_misc_setup(struct apd_private_data *pdata)
0071 {
0072 struct acpi_device *adev = pdata->adev;
0073 const union acpi_object *obj;
0074 struct platform_device *clkdev;
0075 struct fch_clk_data *clk_data;
0076 struct resource_entry *rentry;
0077 struct list_head resource_list;
0078 int ret;
0079
0080 clk_data = devm_kzalloc(&adev->dev, sizeof(*clk_data), GFP_KERNEL);
0081 if (!clk_data)
0082 return -ENOMEM;
0083
0084 INIT_LIST_HEAD(&resource_list);
0085 ret = acpi_dev_get_resources(adev, &resource_list, misc_check_res,
0086 NULL);
0087 if (ret < 0)
0088 return -ENOENT;
0089
0090 if (!acpi_dev_get_property(adev, "clk-name", ACPI_TYPE_STRING, &obj)) {
0091 clk_data->name = devm_kzalloc(&adev->dev, obj->string.length,
0092 GFP_KERNEL);
0093
0094 strcpy(clk_data->name, obj->string.pointer);
0095 } else {
0096
0097 clk_data->name = "mclk";
0098 }
0099
0100 list_for_each_entry(rentry, &resource_list, node) {
0101 clk_data->base = devm_ioremap(&adev->dev, rentry->res->start,
0102 resource_size(rentry->res));
0103 break;
0104 }
0105 if (!clk_data->base)
0106 return -ENOMEM;
0107
0108 acpi_dev_free_resource_list(&resource_list);
0109
0110 clkdev = platform_device_register_data(&adev->dev, "clk-fch",
0111 PLATFORM_DEVID_NONE, clk_data,
0112 sizeof(*clk_data));
0113 return PTR_ERR_OR_ZERO(clkdev);
0114 }
0115
0116 static const struct apd_device_desc cz_i2c_desc = {
0117 .setup = acpi_apd_setup,
0118 .fixed_clk_rate = 133000000,
0119 };
0120
0121 static const struct apd_device_desc wt_i2c_desc = {
0122 .setup = acpi_apd_setup,
0123 .fixed_clk_rate = 150000000,
0124 };
0125
0126 static struct property_entry uart_properties[] = {
0127 PROPERTY_ENTRY_U32("reg-io-width", 4),
0128 PROPERTY_ENTRY_U32("reg-shift", 2),
0129 PROPERTY_ENTRY_BOOL("snps,uart-16550-compatible"),
0130 { },
0131 };
0132
0133 static const struct apd_device_desc cz_uart_desc = {
0134 .setup = acpi_apd_setup,
0135 .fixed_clk_rate = 48000000,
0136 .properties = uart_properties,
0137 };
0138
0139 static const struct apd_device_desc fch_misc_desc = {
0140 .setup = fch_misc_setup,
0141 };
0142 #endif
0143
0144 #ifdef CONFIG_ARM64
0145 static const struct apd_device_desc xgene_i2c_desc = {
0146 .setup = acpi_apd_setup,
0147 .fixed_clk_rate = 100000000,
0148 };
0149
0150 static const struct apd_device_desc vulcan_spi_desc = {
0151 .setup = acpi_apd_setup,
0152 .fixed_clk_rate = 133000000,
0153 };
0154
0155 static const struct apd_device_desc hip07_i2c_desc = {
0156 .setup = acpi_apd_setup,
0157 .fixed_clk_rate = 200000000,
0158 };
0159
0160 static const struct apd_device_desc hip08_i2c_desc = {
0161 .setup = acpi_apd_setup,
0162 .fixed_clk_rate = 250000000,
0163 };
0164
0165 static const struct apd_device_desc hip08_lite_i2c_desc = {
0166 .setup = acpi_apd_setup,
0167 .fixed_clk_rate = 125000000,
0168 };
0169
0170 static const struct apd_device_desc thunderx2_i2c_desc = {
0171 .setup = acpi_apd_setup,
0172 .fixed_clk_rate = 125000000,
0173 };
0174
0175 static const struct apd_device_desc nxp_i2c_desc = {
0176 .setup = acpi_apd_setup,
0177 .fixed_clk_rate = 350000000,
0178 };
0179
0180 static const struct apd_device_desc hip08_spi_desc = {
0181 .setup = acpi_apd_setup,
0182 .fixed_clk_rate = 250000000,
0183 };
0184 #endif
0185
0186 #endif
0187
0188
0189
0190
0191
0192 static int acpi_apd_create_device(struct acpi_device *adev,
0193 const struct acpi_device_id *id)
0194 {
0195 const struct apd_device_desc *dev_desc = (void *)id->driver_data;
0196 struct apd_private_data *pdata;
0197 struct platform_device *pdev;
0198 int ret;
0199
0200 if (!dev_desc) {
0201 pdev = acpi_create_platform_device(adev, NULL);
0202 return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
0203 }
0204
0205 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
0206 if (!pdata)
0207 return -ENOMEM;
0208
0209 pdata->adev = adev;
0210 pdata->dev_desc = dev_desc;
0211
0212 if (dev_desc->setup) {
0213 ret = dev_desc->setup(pdata);
0214 if (ret)
0215 goto err_out;
0216 }
0217
0218 adev->driver_data = pdata;
0219 pdev = acpi_create_platform_device(adev, dev_desc->properties);
0220 if (!IS_ERR_OR_NULL(pdev))
0221 return 1;
0222
0223 ret = PTR_ERR(pdev);
0224 adev->driver_data = NULL;
0225
0226 err_out:
0227 kfree(pdata);
0228 return ret;
0229 }
0230
0231 static const struct acpi_device_id acpi_apd_device_ids[] = {
0232
0233 #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
0234 { "AMD0010", APD_ADDR(cz_i2c_desc) },
0235 { "AMD0020", APD_ADDR(cz_uart_desc) },
0236 { "AMD0030", },
0237 { "AMD0040", APD_ADDR(fch_misc_desc)},
0238 { "AMDI0010", APD_ADDR(wt_i2c_desc) },
0239 { "AMDI0019", APD_ADDR(wt_i2c_desc) },
0240 { "AMDI0020", APD_ADDR(cz_uart_desc) },
0241 { "AMDI0022", APD_ADDR(cz_uart_desc) },
0242 { "HYGO0010", APD_ADDR(wt_i2c_desc) },
0243 #endif
0244 #ifdef CONFIG_ARM64
0245 { "APMC0D0F", APD_ADDR(xgene_i2c_desc) },
0246 { "BRCM900D", APD_ADDR(vulcan_spi_desc) },
0247 { "CAV900D", APD_ADDR(vulcan_spi_desc) },
0248 { "CAV9007", APD_ADDR(thunderx2_i2c_desc) },
0249 { "HISI02A1", APD_ADDR(hip07_i2c_desc) },
0250 { "HISI02A2", APD_ADDR(hip08_i2c_desc) },
0251 { "HISI02A3", APD_ADDR(hip08_lite_i2c_desc) },
0252 { "HISI0173", APD_ADDR(hip08_spi_desc) },
0253 { "NXP0001", APD_ADDR(nxp_i2c_desc) },
0254 #endif
0255 { }
0256 };
0257
0258 static struct acpi_scan_handler apd_handler = {
0259 .ids = acpi_apd_device_ids,
0260 .attach = acpi_apd_create_device,
0261 };
0262
0263 void __init acpi_apd_init(void)
0264 {
0265 acpi_scan_add_handler(&apd_handler);
0266 }