]>
Commit | Line | Data |
---|---|---|
91e56878 MW |
1 | /* |
2 | * ACPI support for platform bus type. | |
3 | * | |
4 | * Copyright (C) 2012, Intel Corporation | |
5 | * Authors: Mika Westerberg <[email protected]> | |
6 | * Mathias Nyman <[email protected]> | |
7 | * Rafael J. Wysocki <[email protected]> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | */ | |
13 | ||
14 | #include <linux/acpi.h> | |
15 | #include <linux/device.h> | |
e375325c | 16 | #include <linux/err.h> |
91e56878 MW |
17 | #include <linux/kernel.h> |
18 | #include <linux/module.h> | |
19 | #include <linux/platform_device.h> | |
20 | ||
5923f986 AS |
21 | #include "internal.h" |
22 | ||
91e56878 MW |
23 | ACPI_MODULE_NAME("platform"); |
24 | ||
141a297b RW |
25 | /* Flags for acpi_create_platform_device */ |
26 | #define ACPI_PLATFORM_CLK BIT(0) | |
27 | ||
28 | /* | |
29 | * The following ACPI IDs are known to be suitable for representing as | |
30 | * platform devices. | |
31 | */ | |
32 | static const struct acpi_device_id acpi_platform_device_ids[] = { | |
33 | ||
34 | { "PNP0D40" }, | |
35 | ||
36 | /* Haswell LPSS devices */ | |
37 | { "INT33C0", ACPI_PLATFORM_CLK }, | |
38 | { "INT33C1", ACPI_PLATFORM_CLK }, | |
39 | { "INT33C2", ACPI_PLATFORM_CLK }, | |
40 | { "INT33C3", ACPI_PLATFORM_CLK }, | |
41 | { "INT33C4", ACPI_PLATFORM_CLK }, | |
42 | { "INT33C5", ACPI_PLATFORM_CLK }, | |
43 | { "INT33C6", ACPI_PLATFORM_CLK }, | |
44 | { "INT33C7", ACPI_PLATFORM_CLK }, | |
45 | ||
46 | { } | |
47 | }; | |
48 | ||
e375325c MW |
49 | static int acpi_create_platform_clks(struct acpi_device *adev) |
50 | { | |
51 | static struct platform_device *pdev; | |
52 | ||
53 | /* Create Lynxpoint LPSS clocks */ | |
54 | if (!pdev && !strncmp(acpi_device_hid(adev), "INT33C", 6)) { | |
55 | pdev = platform_device_register_simple("clk-lpt", -1, NULL, 0); | |
56 | if (IS_ERR(pdev)) | |
57 | return PTR_ERR(pdev); | |
58 | } | |
59 | ||
60 | return 0; | |
61 | } | |
62 | ||
91e56878 MW |
63 | /** |
64 | * acpi_create_platform_device - Create platform device for ACPI device node | |
65 | * @adev: ACPI device node to create a platform device for. | |
141a297b | 66 | * @id: ACPI device ID used to match @adev. |
91e56878 MW |
67 | * |
68 | * Check if the given @adev can be represented as a platform device and, if | |
69 | * that's the case, create and register a platform device, populate its common | |
70 | * resources and returns a pointer to it. Otherwise, return %NULL. | |
71 | * | |
7eaa2800 | 72 | * Name of the platform device will be the same as @adev's. |
91e56878 | 73 | */ |
141a297b RW |
74 | static int acpi_create_platform_device(struct acpi_device *adev, |
75 | const struct acpi_device_id *id) | |
91e56878 | 76 | { |
141a297b | 77 | unsigned long flags = id->driver_data; |
91e56878 MW |
78 | struct platform_device *pdev = NULL; |
79 | struct acpi_device *acpi_parent; | |
863f9f30 | 80 | struct platform_device_info pdevinfo; |
8e345c99 RW |
81 | struct resource_list_entry *rentry; |
82 | struct list_head resource_list; | |
83 | struct resource *resources; | |
84 | int count; | |
91e56878 | 85 | |
141a297b RW |
86 | if (flags & ACPI_PLATFORM_CLK) { |
87 | int ret = acpi_create_platform_clks(adev); | |
88 | if (ret) { | |
89 | dev_err(&adev->dev, "failed to create clocks\n"); | |
90 | return ret; | |
91 | } | |
e375325c MW |
92 | } |
93 | ||
91e56878 MW |
94 | /* If the ACPI node already has a physical device attached, skip it. */ |
95 | if (adev->physical_node_count) | |
141a297b | 96 | return 0; |
91e56878 | 97 | |
8e345c99 RW |
98 | INIT_LIST_HEAD(&resource_list); |
99 | count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); | |
100 | if (count <= 0) | |
141a297b | 101 | return 0; |
91e56878 | 102 | |
8e345c99 RW |
103 | resources = kmalloc(count * sizeof(struct resource), GFP_KERNEL); |
104 | if (!resources) { | |
105 | dev_err(&adev->dev, "No memory for resources\n"); | |
106 | acpi_dev_free_resource_list(&resource_list); | |
141a297b | 107 | return -ENOMEM; |
91e56878 | 108 | } |
8e345c99 RW |
109 | count = 0; |
110 | list_for_each_entry(rentry, &resource_list, node) | |
111 | resources[count++] = rentry->res; | |
91e56878 | 112 | |
8e345c99 | 113 | acpi_dev_free_resource_list(&resource_list); |
91e56878 | 114 | |
863f9f30 | 115 | memset(&pdevinfo, 0, sizeof(pdevinfo)); |
91e56878 MW |
116 | /* |
117 | * If the ACPI node has a parent and that parent has a physical device | |
118 | * attached to it, that physical device should be the parent of the | |
119 | * platform device we are about to create. | |
120 | */ | |
863f9f30 | 121 | pdevinfo.parent = NULL; |
91e56878 MW |
122 | acpi_parent = adev->parent; |
123 | if (acpi_parent) { | |
124 | struct acpi_device_physical_node *entry; | |
125 | struct list_head *list; | |
126 | ||
127 | mutex_lock(&acpi_parent->physical_node_lock); | |
128 | list = &acpi_parent->physical_node_list; | |
129 | if (!list_empty(list)) { | |
130 | entry = list_first_entry(list, | |
131 | struct acpi_device_physical_node, | |
132 | node); | |
863f9f30 | 133 | pdevinfo.parent = entry->dev; |
91e56878 MW |
134 | } |
135 | mutex_unlock(&acpi_parent->physical_node_lock); | |
136 | } | |
863f9f30 RW |
137 | pdevinfo.name = dev_name(&adev->dev); |
138 | pdevinfo.id = -1; | |
139 | pdevinfo.res = resources; | |
140 | pdevinfo.num_res = count; | |
141 | pdevinfo.acpi_node.handle = adev->handle; | |
142 | pdev = platform_device_register_full(&pdevinfo); | |
91e56878 MW |
143 | if (IS_ERR(pdev)) { |
144 | dev_err(&adev->dev, "platform device creation failed: %ld\n", | |
145 | PTR_ERR(pdev)); | |
146 | pdev = NULL; | |
147 | } else { | |
148 | dev_dbg(&adev->dev, "created platform device %s\n", | |
149 | dev_name(&pdev->dev)); | |
150 | } | |
151 | ||
8e345c99 | 152 | kfree(resources); |
141a297b RW |
153 | return 1; |
154 | } | |
155 | ||
156 | static struct acpi_scan_handler platform_handler = { | |
157 | .ids = acpi_platform_device_ids, | |
158 | .attach = acpi_create_platform_device, | |
159 | }; | |
160 | ||
161 | void __init acpi_platform_init(void) | |
162 | { | |
163 | acpi_scan_add_handler(&platform_handler); | |
91e56878 | 164 | } |