Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 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 | |
| 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> |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 19 | #include <linux/pm.h> |
| 20 | |
| 21 | #include "internal.h" |
| 22 | |
| 23 | ACPI_MODULE_NAME("acpi_apd"); |
| 24 | struct apd_private_data; |
| 25 | |
| 26 | /** |
| 27 | * ACPI_APD_SYSFS : add device attributes in sysfs |
| 28 | * ACPI_APD_PM : attach power domain to device |
| 29 | */ |
| 30 | #define ACPI_APD_SYSFS BIT(0) |
| 31 | #define ACPI_APD_PM BIT(1) |
| 32 | |
| 33 | /** |
| 34 | * struct apd_device_desc - a descriptor for apd device |
| 35 | * @flags: device flags like %ACPI_APD_SYSFS, %ACPI_APD_PM |
| 36 | * @fixed_clk_rate: fixed rate input clock source for acpi device; |
| 37 | * 0 means no fixed rate input clock source |
| 38 | * @setup: a hook routine to set device resource during create platform device |
| 39 | * |
| 40 | * Device description defined as acpi_device_id.driver_data |
| 41 | */ |
| 42 | struct apd_device_desc { |
| 43 | unsigned int flags; |
| 44 | unsigned int fixed_clk_rate; |
| 45 | int (*setup)(struct apd_private_data *pdata); |
| 46 | }; |
| 47 | |
| 48 | struct apd_private_data { |
| 49 | struct clk *clk; |
| 50 | struct acpi_device *adev; |
| 51 | const struct apd_device_desc *dev_desc; |
| 52 | }; |
| 53 | |
Loc Ho | b790eb2 | 2015-12-10 14:19:16 -0700 | [diff] [blame] | 54 | #if defined(CONFIG_X86_AMD_PLATFORM_DEVICE) || defined(CONFIG_ARM64) |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 55 | #define APD_ADDR(desc) ((unsigned long)&desc) |
| 56 | |
| 57 | static int acpi_apd_setup(struct apd_private_data *pdata) |
| 58 | { |
| 59 | const struct apd_device_desc *dev_desc = pdata->dev_desc; |
| 60 | struct clk *clk = ERR_PTR(-ENODEV); |
| 61 | |
| 62 | if (dev_desc->fixed_clk_rate) { |
| 63 | clk = clk_register_fixed_rate(&pdata->adev->dev, |
| 64 | dev_name(&pdata->adev->dev), |
Stephen Boyd | cdd9a6b | 2016-04-19 18:27:46 -0700 | [diff] [blame] | 65 | NULL, 0, dev_desc->fixed_clk_rate); |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 66 | clk_register_clkdev(clk, NULL, dev_name(&pdata->adev->dev)); |
| 67 | pdata->clk = clk; |
| 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Loc Ho | b790eb2 | 2015-12-10 14:19:16 -0700 | [diff] [blame] | 73 | #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 74 | static struct apd_device_desc cz_i2c_desc = { |
| 75 | .setup = acpi_apd_setup, |
| 76 | .fixed_clk_rate = 133000000, |
| 77 | }; |
| 78 | |
| 79 | static struct apd_device_desc cz_uart_desc = { |
| 80 | .setup = acpi_apd_setup, |
| 81 | .fixed_clk_rate = 48000000, |
| 82 | }; |
Loc Ho | b790eb2 | 2015-12-10 14:19:16 -0700 | [diff] [blame] | 83 | #endif |
| 84 | |
| 85 | #ifdef CONFIG_ARM64 |
| 86 | static struct apd_device_desc xgene_i2c_desc = { |
| 87 | .setup = acpi_apd_setup, |
| 88 | .fixed_clk_rate = 100000000, |
| 89 | }; |
Kamlakant Patel | bd2058d | 2016-08-09 19:35:21 +0530 | [diff] [blame^] | 90 | |
| 91 | static struct apd_device_desc vulcan_spi_desc = { |
| 92 | .setup = acpi_apd_setup, |
| 93 | .fixed_clk_rate = 133000000, |
| 94 | }; |
Loc Ho | b790eb2 | 2015-12-10 14:19:16 -0700 | [diff] [blame] | 95 | #endif |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 96 | |
| 97 | #else |
| 98 | |
| 99 | #define APD_ADDR(desc) (0UL) |
| 100 | |
| 101 | #endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */ |
| 102 | |
| 103 | /** |
| 104 | * Create platform device during acpi scan attach handle. |
| 105 | * Return value > 0 on success of creating device. |
| 106 | */ |
| 107 | static int acpi_apd_create_device(struct acpi_device *adev, |
| 108 | const struct acpi_device_id *id) |
| 109 | { |
| 110 | const struct apd_device_desc *dev_desc = (void *)id->driver_data; |
| 111 | struct apd_private_data *pdata; |
| 112 | struct platform_device *pdev; |
| 113 | int ret; |
| 114 | |
| 115 | if (!dev_desc) { |
| 116 | pdev = acpi_create_platform_device(adev); |
| 117 | return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1; |
| 118 | } |
| 119 | |
| 120 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); |
| 121 | if (!pdata) |
| 122 | return -ENOMEM; |
| 123 | |
| 124 | pdata->adev = adev; |
| 125 | pdata->dev_desc = dev_desc; |
| 126 | |
| 127 | if (dev_desc->setup) { |
| 128 | ret = dev_desc->setup(pdata); |
| 129 | if (ret) |
| 130 | goto err_out; |
| 131 | } |
| 132 | |
| 133 | adev->driver_data = pdata; |
| 134 | pdev = acpi_create_platform_device(adev); |
| 135 | if (!IS_ERR_OR_NULL(pdev)) |
| 136 | return 1; |
| 137 | |
| 138 | ret = PTR_ERR(pdev); |
| 139 | adev->driver_data = NULL; |
| 140 | |
| 141 | err_out: |
| 142 | kfree(pdata); |
| 143 | return ret; |
| 144 | } |
| 145 | |
| 146 | static const struct acpi_device_id acpi_apd_device_ids[] = { |
| 147 | /* Generic apd devices */ |
Loc Ho | b790eb2 | 2015-12-10 14:19:16 -0700 | [diff] [blame] | 148 | #ifdef CONFIG_X86_AMD_PLATFORM_DEVICE |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 149 | { "AMD0010", APD_ADDR(cz_i2c_desc) }, |
Xiangliang Yu | e4e666b | 2016-03-10 19:34:52 +0800 | [diff] [blame] | 150 | { "AMDI0010", APD_ADDR(cz_i2c_desc) }, |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 151 | { "AMD0020", APD_ADDR(cz_uart_desc) }, |
Wang Hongcheng | f5eda99 | 2016-03-11 17:28:23 +0800 | [diff] [blame] | 152 | { "AMDI0020", APD_ADDR(cz_uart_desc) }, |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 153 | { "AMD0030", }, |
Loc Ho | b790eb2 | 2015-12-10 14:19:16 -0700 | [diff] [blame] | 154 | #endif |
| 155 | #ifdef CONFIG_ARM64 |
| 156 | { "APMC0D0F", APD_ADDR(xgene_i2c_desc) }, |
Kamlakant Patel | bd2058d | 2016-08-09 19:35:21 +0530 | [diff] [blame^] | 157 | { "BRCM900D", APD_ADDR(vulcan_spi_desc) }, |
Loc Ho | b790eb2 | 2015-12-10 14:19:16 -0700 | [diff] [blame] | 158 | #endif |
Ken Xue | 92082a8 | 2015-02-06 08:27:51 +0800 | [diff] [blame] | 159 | { } |
| 160 | }; |
| 161 | |
| 162 | static struct acpi_scan_handler apd_handler = { |
| 163 | .ids = acpi_apd_device_ids, |
| 164 | .attach = acpi_apd_create_device, |
| 165 | }; |
| 166 | |
| 167 | void __init acpi_apd_init(void) |
| 168 | { |
| 169 | acpi_scan_add_handler(&apd_handler); |
| 170 | } |