aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amdfalconx86/recipes-kernel/linux/files/0005-yocto-amd-i2c-driver_support_ACPI2Platform-1.0.patch
blob: 992a54f86c049e15c45a3ab96cc5c03c455389ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
From a29dd45173a7e20e5e3f29fb8d71222b80fb0c12 Mon Sep 17 00:00:00 2001
From: Ken Xue <Ken.Xue@amd.com>
Date: Thu, 6 Nov 2014 08:21:37 +0800
Subject: [PATCH 1/6] [CZ][FCH]support ACPI2Platform device for x86 system.

This new feature is to interpret AMD specific ACPI device to platform device
such as I2C, UART found on AMD CZ and later chipsets. It is based on example
INTEL LPSS. Now, it just supports AMD I2C.

Signed-off-by: Ken Xue <Ken.Xue@amd.com>
Signed-off-by: Jeff Wu <Jeff.Wu@amd.com>
Signed-off-by: Awais Belal <awais_belal@mentor.com>
---
 arch/x86/Kconfig        |  11 +++
 drivers/acpi/Makefile   |   1 +
 drivers/acpi/acpi_apd.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/acpi/internal.h |   6 ++
 drivers/acpi/scan.c     |   1 +
 5 files changed, 253 insertions(+)
 create mode 100644 drivers/acpi/acpi_apd.c
diff -Naur a/arch/x86/Kconfig b/arch/x86/Kconfig
--- a/arch/x86/Kconfig	2015-03-25 14:39:54.676737984 +0530
+++ b/arch/x86/Kconfig	2015-03-25 14:51:42.084751856 +0530
@@ -474,6 +474,17 @@
 	  things like clock tree (common clock framework) and pincontrol
 	  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+       bool "AMD ACPI2Platform devices support"
+       depends on ACPI
+       select COMMON_CLK
+       select PINCTRL
+       ---help---
+         Select to interpret AMD specific ACPI device to platform device
+         such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
+         this option enables things like clock tree (common clock framework)
+         and pincontrol.
+
 config X86_RDC321X
 	bool "RDC R-321x SoC"
 	depends on X86_32
diff -Naur a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
--- a/drivers/acpi/acpi_apd.c	1970-01-01 05:30:00.000000000 +0530
+++ b/drivers/acpi/acpi_apd.c	2015-03-25 14:51:42.084751856 +0530
@@ -0,0 +1,234 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue <Ken.Xue@amd.com>
+ *	Peng, Carl <Carl.Peng@amd.com>
+ *	Wu, Jeff <Jeff.Wu@amd.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/acpi.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/clk-provider.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+
+#include "internal.h"
+
+ACPI_MODULE_NAME("acpi_apd");
+struct apd_private_data;
+
+struct apd_device_desc {
+	bool clk_required;
+	bool fix_rate_root_clock;
+	const char *clk_name;
+	unsigned long	rate;
+	size_t prv_size_override;
+	void (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+	void __iomem *mmio_base;
+	resource_size_t mmio_size;
+	struct clk *clk;
+	const struct apd_device_desc *dev_desc;
+};
+
+static struct apd_device_desc amd_i2c_desc = {
+	.clk_required = true,
+	.fix_rate_root_clock = true,
+	.clk_name = "i2c_clk",
+	.rate = 136192000, /*(133 * 1024 * 1000)*/
+};
+
+static const struct acpi_device_id acpi_apd_device_ids[] = {
+	/* Generic apd devices */
+	{ "AMD0010", (unsigned long)&amd_i2c_desc },
+	/*{ "UART0000, (unsigned long)&amur_uart_dev_desc },*/
+	/*{"AMD0030", (unsigned long)&amur_gpio_dev_desc },*/
+	{ }
+};
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+	struct resource r;
+
+	return !acpi_dev_resource_memory(res, &r);
+}
+
+static int register_device_clock(struct acpi_device *adev,
+				 struct apd_private_data *pdata)
+{
+	const struct apd_device_desc *dev_desc = pdata->dev_desc;
+	struct clk *clk = ERR_PTR(-ENODEV);
+
+	clk = pdata->clk;
+	if (!clk && dev_desc->fix_rate_root_clock) {
+		clk = clk_register_fixed_rate(&adev->dev, dev_name(&adev->dev),
+				      NULL, CLK_IS_ROOT, dev_desc->rate);
+		pdata->clk = clk;
+		clk_register_clkdev(clk, NULL, dev_name(&adev->dev));
+	}
+
+	return 0;
+}
+
+static int acpi_apd_create_device(struct acpi_device *adev,
+				   const struct acpi_device_id *id)
+{
+	struct apd_device_desc *dev_desc;
+	struct apd_private_data *pdata;
+	struct resource_list_entry *rentry;
+	struct list_head resource_list;
+	int ret;
+
+	dev_desc = (struct apd_device_desc *)id->driver_data;
+	if (!dev_desc)
+		return acpi_create_platform_device(adev, id);
+
+	pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return -ENOMEM;
+
+	INIT_LIST_HEAD(&resource_list);
+	ret = acpi_dev_get_resources(adev, &resource_list, is_memory, NULL);
+	if (ret < 0)
+		goto err_out;
+
+	list_for_each_entry(rentry, &resource_list, node)
+		if (resource_type(&rentry->res) == IORESOURCE_MEM) {
+			if (dev_desc->prv_size_override)
+				pdata->mmio_size = dev_desc->prv_size_override;
+			else
+				pdata->mmio_size = resource_size(&rentry->res);
+			pdata->mmio_base = ioremap(rentry->res.start,
+						   pdata->mmio_size);
+			break;
+		}
+
+	acpi_dev_free_resource_list(&resource_list);
+
+	pdata->dev_desc = dev_desc;
+
+	if (dev_desc->clk_required) {
+		ret = register_device_clock(adev, pdata);
+		if (ret) {
+			/* Skip the device, but continue the namespace scan. */
+			ret = 0;
+			goto err_out;
+		}
+	}
+
+	/*
+	 * This works around a known issue in ACPI tables where apd devices
+	 * have _PS0 and _PS3 without _PSC (and no power resources), so
+	 * acpi_bus_init_power() will assume that the BIOS has put them into D0.
+	 */
+	ret = acpi_device_fix_up_power(adev);
+	if (ret) {
+		/* Skip the device, but continue the namespace scan. */
+		ret = 0;
+		goto err_out;
+	}
+
+	if (dev_desc->setup)
+		dev_desc->setup(pdata);
+
+	adev->driver_data = pdata;
+	ret = acpi_create_platform_device(adev, id);
+	if (ret > 0)
+		return ret;
+
+	adev->driver_data = NULL;
+
+ err_out:
+	kfree(pdata);
+	return ret;
+}
+
+static ssize_t apd_device_desc_show(struct device *dev,
+				struct device_attribute *attr, char *buf)
+{
+	int ret;
+	struct acpi_device *adev;
+	struct apd_private_data *pdata;
+
+	ret = acpi_bus_get_device(ACPI_HANDLE(dev), &adev);
+	if (WARN_ON(ret))
+		return ret;
+
+	pdata = acpi_driver_data(adev);
+	if (WARN_ON(!pdata || !pdata->dev_desc))
+		return -ENODEV;
+
+	if (pdata->dev_desc->clk_required)
+		return sprintf(buf, "Required clk: %s %s %ld\n",
+		pdata->dev_desc->clk_name,
+		pdata->dev_desc->fix_rate_root_clock ?
+		"fix rate" : "no fix rate",
+		pdata->dev_desc->rate);
+	else
+		return sprintf(buf, "No need clk\n");
+}
+
+static DEVICE_ATTR(device_desc, S_IRUSR, apd_device_desc_show, NULL);
+
+static struct attribute *apd_attrs[] = {
+	&dev_attr_device_desc.attr,
+	NULL,
+};
+
+static struct attribute_group apd_attr_group = {
+	.attrs = apd_attrs,
+	.name = "apd_ltr",
+};
+
+static int acpi_apd_platform_notify(struct notifier_block *nb,
+				     unsigned long action, void *data)
+{
+	struct platform_device *pdev = to_platform_device(data);
+	struct apd_private_data *pdata;
+	struct acpi_device *adev;
+	const struct acpi_device_id *id;
+	int ret = 0;
+
+	id = acpi_match_device(acpi_apd_device_ids, &pdev->dev);
+	if (!id || !id->driver_data)
+		return 0;
+
+	if (acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev))
+		return 0;
+
+	pdata = acpi_driver_data(adev);
+	if (!pdata || !pdata->mmio_base)
+		return 0;
+
+	if (action == BUS_NOTIFY_ADD_DEVICE)
+		ret = sysfs_create_group(&pdev->dev.kobj, &apd_attr_group);
+	else if (action == BUS_NOTIFY_DEL_DEVICE)
+		sysfs_remove_group(&pdev->dev.kobj, &apd_attr_group);
+
+	return ret;
+}
+
+static struct notifier_block acpi_apd_nb = {
+	.notifier_call = acpi_apd_platform_notify,
+};
+
+static struct acpi_scan_handler apd_handler = {
+	.ids = acpi_apd_device_ids,
+	.attach = acpi_apd_create_device,
+};
+
+void __init acpi_apd_init(void)
+{
+	bus_register_notifier(&platform_bus_type, &acpi_apd_nb);
+	acpi_scan_add_handler(&apd_handler);
+}
diff -Naur a/drivers/acpi/internal.h b/drivers/acpi/internal.h
--- a/drivers/acpi/internal.h	2015-03-25 14:39:54.684737985 +0530
+++ b/drivers/acpi/internal.h	2015-03-25 14:51:42.084751856 +0530
@@ -72,6 +72,12 @@
 static inline void acpi_lpss_init(void) {}
 #endif
 
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+void acpi_apd_init(void);
+#else
+static inline void acpi_apd_init(void) {}
+#endif
+
 bool acpi_queue_hotplug_work(struct work_struct *work);
 bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent);
 
diff -Naur a/drivers/acpi/Makefile b/drivers/acpi/Makefile
--- a/drivers/acpi/Makefile	2015-03-25 14:39:54.684737985 +0530
+++ b/drivers/acpi/Makefile	2015-03-25 14:51:42.084751856 +0530
@@ -40,6 +40,7 @@
 acpi-$(CONFIG_ACPI_DOCK)	+= dock.o
 acpi-y				+= pci_root.o pci_link.o pci_irq.o
 acpi-$(CONFIG_X86_INTEL_LPSS)	+= acpi_lpss.o
+acpi-$(CONFIG_X86_AMD_PLATFORM_DEVICE) += acpi_apd.o
 acpi-y				+= acpi_platform.o
 acpi-y				+= power.o
 acpi-y				+= event.o
diff -Naur a/drivers/acpi/scan.c b/drivers/acpi/scan.c
--- a/drivers/acpi/scan.c	2015-03-25 14:39:54.688737985 +0530
+++ b/drivers/acpi/scan.c	2015-03-25 14:51:42.084751856 +0530
@@ -2191,6 +2191,7 @@
 	acpi_processor_init();
 	acpi_platform_init();
 	acpi_lpss_init();
+	acpi_apd_init();
 	acpi_cmos_rtc_init();
 	acpi_container_init();
 	acpi_memory_hotplug_init();