diff options
Diffstat (limited to 'drivers/acpi/acpi_platform.c')
-rw-r--r-- | drivers/acpi/acpi_platform.c | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index db129b9f52cb..26fce4b8a632 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c | |||
@@ -13,6 +13,7 @@ | |||
13 | 13 | ||
14 | #include <linux/acpi.h> | 14 | #include <linux/acpi.h> |
15 | #include <linux/device.h> | 15 | #include <linux/device.h> |
16 | #include <linux/err.h> | ||
16 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
18 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
@@ -21,18 +22,59 @@ | |||
21 | 22 | ||
22 | ACPI_MODULE_NAME("platform"); | 23 | ACPI_MODULE_NAME("platform"); |
23 | 24 | ||
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 | |||
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 | |||
24 | /** | 63 | /** |
25 | * acpi_create_platform_device - Create platform device for ACPI device node | 64 | * acpi_create_platform_device - Create platform device for ACPI device node |
26 | * @adev: ACPI device node to create a platform device for. | 65 | * @adev: ACPI device node to create a platform device for. |
66 | * @id: ACPI device ID used to match @adev. | ||
27 | * | 67 | * |
28 | * Check if the given @adev can be represented as a platform device and, if | 68 | * Check if the given @adev can be represented as a platform device and, if |
29 | * that's the case, create and register a platform device, populate its common | 69 | * that's the case, create and register a platform device, populate its common |
30 | * resources and returns a pointer to it. Otherwise, return %NULL. | 70 | * resources and returns a pointer to it. Otherwise, return %NULL. |
31 | * | 71 | * |
32 | * The platform device's name will be taken from the @adev's _HID and _UID. | 72 | * Name of the platform device will be the same as @adev's. |
33 | */ | 73 | */ |
34 | struct platform_device *acpi_create_platform_device(struct acpi_device *adev) | 74 | static int acpi_create_platform_device(struct acpi_device *adev, |
75 | const struct acpi_device_id *id) | ||
35 | { | 76 | { |
77 | unsigned long flags = id->driver_data; | ||
36 | struct platform_device *pdev = NULL; | 78 | struct platform_device *pdev = NULL; |
37 | struct acpi_device *acpi_parent; | 79 | struct acpi_device *acpi_parent; |
38 | struct platform_device_info pdevinfo; | 80 | struct platform_device_info pdevinfo; |
@@ -41,20 +83,28 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) | |||
41 | struct resource *resources; | 83 | struct resource *resources; |
42 | int count; | 84 | int count; |
43 | 85 | ||
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 | } | ||
92 | } | ||
93 | |||
44 | /* If the ACPI node already has a physical device attached, skip it. */ | 94 | /* If the ACPI node already has a physical device attached, skip it. */ |
45 | if (adev->physical_node_count) | 95 | if (adev->physical_node_count) |
46 | return NULL; | 96 | return 0; |
47 | 97 | ||
48 | INIT_LIST_HEAD(&resource_list); | 98 | INIT_LIST_HEAD(&resource_list); |
49 | count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); | 99 | count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); |
50 | if (count <= 0) | 100 | if (count <= 0) |
51 | return NULL; | 101 | return 0; |
52 | 102 | ||
53 | resources = kmalloc(count * sizeof(struct resource), GFP_KERNEL); | 103 | resources = kmalloc(count * sizeof(struct resource), GFP_KERNEL); |
54 | if (!resources) { | 104 | if (!resources) { |
55 | dev_err(&adev->dev, "No memory for resources\n"); | 105 | dev_err(&adev->dev, "No memory for resources\n"); |
56 | acpi_dev_free_resource_list(&resource_list); | 106 | acpi_dev_free_resource_list(&resource_list); |
57 | return NULL; | 107 | return -ENOMEM; |
58 | } | 108 | } |
59 | count = 0; | 109 | count = 0; |
60 | list_for_each_entry(rentry, &resource_list, node) | 110 | list_for_each_entry(rentry, &resource_list, node) |
@@ -100,5 +150,15 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) | |||
100 | } | 150 | } |
101 | 151 | ||
102 | kfree(resources); | 152 | kfree(resources); |
103 | return pdev; | 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); | ||
104 | } | 164 | } |