diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-12-08 13:50:17 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-12-08 13:50:17 -0500 |
commit | d3eaf5875e36b37f1386a4e3e7562c5a6c35abd2 (patch) | |
tree | 13f5b6c391ad74a072a4f77f74e958a6ac287032 | |
parent | b2776bf7149bddd1f4161f14f79520f17fc1d71d (diff) | |
parent | 29470ea8d828e4dec74e94f7f17b7479ff5ef276 (diff) |
Merge branch 'device-properties'
* device-properties:
leds: leds-gpio: Fix multiple instances registration without 'label' property
leds: leds-gpio: Fix legacy GPIO number case
ACPI / property: Drop size_prop from acpi_dev_get_property_reference()
leds: leds-gpio: Convert gpio_blink_set() to use GPIO descriptors
ACPI / GPIO: Document ACPI GPIO mappings API
net: rfkill: gpio: Add default GPIO driver mappings for ACPI
ACPI / GPIO: Driver GPIO mappings for ACPI GPIOs
input: gpio_keys_polled: Make use of device property API
leds: leds-gpio: Make use of device property API
gpio: Support for unified device properties interface
Driver core: Unified interface for firmware node properties
input: gpio_keys_polled: Add support for GPIO descriptors
leds: leds-gpio: Add support for GPIO descriptors
gpio: sch: Consolidate core and resume banks
gpio / ACPI: Add support for _DSD device properties
misc: at25: Make use of device property API
ACPI: Allow drivers to match using Device Tree compatible property
Driver core: Unified device properties interface for platform firmware
ACPI: Add support for device specific properties
31 files changed, 2105 insertions, 386 deletions
diff --git a/Documentation/acpi/gpio-properties.txt b/Documentation/acpi/gpio-properties.txt new file mode 100644 index 000000000000..ae36fcf86dc7 --- /dev/null +++ b/Documentation/acpi/gpio-properties.txt | |||
@@ -0,0 +1,96 @@ | |||
1 | _DSD Device Properties Related to GPIO | ||
2 | -------------------------------------- | ||
3 | |||
4 | With the release of ACPI 5.1 and the _DSD configuration objecte names | ||
5 | can finally be given to GPIOs (and other things as well) returned by | ||
6 | _CRS. Previously, we were only able to use an integer index to find | ||
7 | the corresponding GPIO, which is pretty error prone (it depends on | ||
8 | the _CRS output ordering, for example). | ||
9 | |||
10 | With _DSD we can now query GPIOs using a name instead of an integer | ||
11 | index, like the ASL example below shows: | ||
12 | |||
13 | // Bluetooth device with reset and shutdown GPIOs | ||
14 | Device (BTH) | ||
15 | { | ||
16 | Name (_HID, ...) | ||
17 | |||
18 | Name (_CRS, ResourceTemplate () | ||
19 | { | ||
20 | GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly, | ||
21 | "\\_SB.GPO0", 0, ResourceConsumer) {15} | ||
22 | GpioIo (Exclusive, PullUp, 0, 0, IoRestrictionInputOnly, | ||
23 | "\\_SB.GPO0", 0, ResourceConsumer) {27, 31} | ||
24 | }) | ||
25 | |||
26 | Name (_DSD, Package () | ||
27 | { | ||
28 | ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), | ||
29 | Package () | ||
30 | { | ||
31 | Package () {"reset-gpio", Package() {^BTH, 1, 1, 0 }}, | ||
32 | Package () {"shutdown-gpio", Package() {^BTH, 0, 0, 0 }}, | ||
33 | } | ||
34 | }) | ||
35 | } | ||
36 | |||
37 | The format of the supported GPIO property is: | ||
38 | |||
39 | Package () { "name", Package () { ref, index, pin, active_low }} | ||
40 | |||
41 | ref - The device that has _CRS containing GpioIo()/GpioInt() resources, | ||
42 | typically this is the device itself (BTH in our case). | ||
43 | index - Index of the GpioIo()/GpioInt() resource in _CRS starting from zero. | ||
44 | pin - Pin in the GpioIo()/GpioInt() resource. Typically this is zero. | ||
45 | active_low - If 1 the GPIO is marked as active_low. | ||
46 | |||
47 | Since ACPI GpioIo() resource does not have a field saying whether it is | ||
48 | active low or high, the "active_low" argument can be used here. Setting | ||
49 | it to 1 marks the GPIO as active low. | ||
50 | |||
51 | In our Bluetooth example the "reset-gpio" refers to the second GpioIo() | ||
52 | resource, second pin in that resource with the GPIO number of 31. | ||
53 | |||
54 | ACPI GPIO Mappings Provided by Drivers | ||
55 | -------------------------------------- | ||
56 | |||
57 | There are systems in which the ACPI tables do not contain _DSD but provide _CRS | ||
58 | with GpioIo()/GpioInt() resources and device drivers still need to work with | ||
59 | them. | ||
60 | |||
61 | In those cases ACPI device identification objects, _HID, _CID, _CLS, _SUB, _HRV, | ||
62 | available to the driver can be used to identify the device and that is supposed | ||
63 | to be sufficient to determine the meaning and purpose of all of the GPIO lines | ||
64 | listed by the GpioIo()/GpioInt() resources returned by _CRS. In other words, | ||
65 | the driver is supposed to know what to use the GpioIo()/GpioInt() resources for | ||
66 | once it has identified the device. Having done that, it can simply assign names | ||
67 | to the GPIO lines it is going to use and provide the GPIO subsystem with a | ||
68 | mapping between those names and the ACPI GPIO resources corresponding to them. | ||
69 | |||
70 | To do that, the driver needs to define a mapping table as a NULL-terminated | ||
71 | array of struct acpi_gpio_mapping objects that each contain a name, a pointer | ||
72 | to an array of line data (struct acpi_gpio_params) objects and the size of that | ||
73 | array. Each struct acpi_gpio_params object consists of three fields, | ||
74 | crs_entry_index, line_index, active_low, representing the index of the target | ||
75 | GpioIo()/GpioInt() resource in _CRS starting from zero, the index of the target | ||
76 | line in that resource starting from zero, and the active-low flag for that line, | ||
77 | respectively, in analogy with the _DSD GPIO property format specified above. | ||
78 | |||
79 | For the example Bluetooth device discussed previously the data structures in | ||
80 | question would look like this: | ||
81 | |||
82 | static const struct acpi_gpio_params reset_gpio = { 1, 1, false }; | ||
83 | static const struct acpi_gpio_params shutdown_gpio = { 0, 0, false }; | ||
84 | |||
85 | static const struct acpi_gpio_mapping bluetooth_acpi_gpios[] = { | ||
86 | { "reset-gpio", &reset_gpio, 1 }, | ||
87 | { "shutdown-gpio", &shutdown_gpio, 1 }, | ||
88 | { }, | ||
89 | }; | ||
90 | |||
91 | Next, the mapping table needs to be passed as the second argument to | ||
92 | acpi_dev_add_driver_gpios() that will register it with the ACPI device object | ||
93 | pointed to by its first argument. That should be done in the driver's .probe() | ||
94 | routine. On removal, the driver should unregister its GPIO mapping table by | ||
95 | calling acpi_dev_remove_driver_gpios() on the ACPI device object where that | ||
96 | table was previously registered. | ||
diff --git a/Documentation/gpio/consumer.txt b/Documentation/gpio/consumer.txt index 6ce544191ca6..859918db36b8 100644 --- a/Documentation/gpio/consumer.txt +++ b/Documentation/gpio/consumer.txt | |||
@@ -219,6 +219,24 @@ part of the IRQ interface, e.g. IRQF_TRIGGER_FALLING, as are system wakeup | |||
219 | capabilities. | 219 | capabilities. |
220 | 220 | ||
221 | 221 | ||
222 | GPIOs and ACPI | ||
223 | ============== | ||
224 | |||
225 | On ACPI systems, GPIOs are described by GpioIo()/GpioInt() resources listed by | ||
226 | the _CRS configuration objects of devices. Those resources do not provide | ||
227 | connection IDs (names) for GPIOs, so it is necessary to use an additional | ||
228 | mechanism for this purpose. | ||
229 | |||
230 | Systems compliant with ACPI 5.1 or newer may provide a _DSD configuration object | ||
231 | which, among other things, may be used to provide connection IDs for specific | ||
232 | GPIOs described by the GpioIo()/GpioInt() resources in _CRS. If that is the | ||
233 | case, it will be handled by the GPIO subsystem automatically. However, if the | ||
234 | _DSD is not present, the mappings between GpioIo()/GpioInt() resources and GPIO | ||
235 | connection IDs need to be provided by device drivers. | ||
236 | |||
237 | For details refer to Documentation/acpi/gpio-properties.txt | ||
238 | |||
239 | |||
222 | Interacting With the Legacy GPIO Subsystem | 240 | Interacting With the Legacy GPIO Subsystem |
223 | ========================================== | 241 | ========================================== |
224 | Many kernel subsystems still handle GPIOs using the legacy integer-based | 242 | Many kernel subsystems still handle GPIOs using the legacy integer-based |
diff --git a/arch/arm/mach-s3c24xx/h1940-bluetooth.c b/arch/arm/mach-s3c24xx/h1940-bluetooth.c index b4d14b864367..9c8b1279a4ba 100644 --- a/arch/arm/mach-s3c24xx/h1940-bluetooth.c +++ b/arch/arm/mach-s3c24xx/h1940-bluetooth.c | |||
@@ -41,7 +41,7 @@ static void h1940bt_enable(int on) | |||
41 | mdelay(10); | 41 | mdelay(10); |
42 | gpio_set_value(S3C2410_GPH(1), 0); | 42 | gpio_set_value(S3C2410_GPH(1), 0); |
43 | 43 | ||
44 | h1940_led_blink_set(-EINVAL, GPIO_LED_BLINK, NULL, NULL); | 44 | h1940_led_blink_set(NULL, GPIO_LED_BLINK, NULL, NULL); |
45 | } | 45 | } |
46 | else { | 46 | else { |
47 | gpio_set_value(S3C2410_GPH(1), 1); | 47 | gpio_set_value(S3C2410_GPH(1), 1); |
@@ -50,7 +50,7 @@ static void h1940bt_enable(int on) | |||
50 | mdelay(10); | 50 | mdelay(10); |
51 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0); | 51 | gpio_set_value(H1940_LATCH_BLUETOOTH_POWER, 0); |
52 | 52 | ||
53 | h1940_led_blink_set(-EINVAL, GPIO_LED_NO_BLINK_LOW, NULL, NULL); | 53 | h1940_led_blink_set(NULL, GPIO_LED_NO_BLINK_LOW, NULL, NULL); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
diff --git a/arch/arm/mach-s3c24xx/h1940.h b/arch/arm/mach-s3c24xx/h1940.h index 2950cc466840..596d9f64c5b6 100644 --- a/arch/arm/mach-s3c24xx/h1940.h +++ b/arch/arm/mach-s3c24xx/h1940.h | |||
@@ -19,8 +19,10 @@ | |||
19 | #define H1940_SUSPEND_RESUMEAT (0x30081000) | 19 | #define H1940_SUSPEND_RESUMEAT (0x30081000) |
20 | #define H1940_SUSPEND_CHECK (0x30080000) | 20 | #define H1940_SUSPEND_CHECK (0x30080000) |
21 | 21 | ||
22 | struct gpio_desc; | ||
23 | |||
22 | extern void h1940_pm_return(void); | 24 | extern void h1940_pm_return(void); |
23 | extern int h1940_led_blink_set(unsigned gpio, int state, | 25 | extern int h1940_led_blink_set(struct gpio_desc *desc, int state, |
24 | unsigned long *delay_on, | 26 | unsigned long *delay_on, |
25 | unsigned long *delay_off); | 27 | unsigned long *delay_off); |
26 | 28 | ||
diff --git a/arch/arm/mach-s3c24xx/mach-h1940.c b/arch/arm/mach-s3c24xx/mach-h1940.c index d35ddc1d9991..d40d4f5244c6 100644 --- a/arch/arm/mach-s3c24xx/mach-h1940.c +++ b/arch/arm/mach-s3c24xx/mach-h1940.c | |||
@@ -359,10 +359,11 @@ static struct platform_device h1940_battery = { | |||
359 | 359 | ||
360 | static DEFINE_SPINLOCK(h1940_blink_spin); | 360 | static DEFINE_SPINLOCK(h1940_blink_spin); |
361 | 361 | ||
362 | int h1940_led_blink_set(unsigned gpio, int state, | 362 | int h1940_led_blink_set(struct gpio_desc *desc, int state, |
363 | unsigned long *delay_on, unsigned long *delay_off) | 363 | unsigned long *delay_on, unsigned long *delay_off) |
364 | { | 364 | { |
365 | int blink_gpio, check_gpio1, check_gpio2; | 365 | int blink_gpio, check_gpio1, check_gpio2; |
366 | int gpio = desc ? desc_to_gpio(desc) : -EINVAL; | ||
366 | 367 | ||
367 | switch (gpio) { | 368 | switch (gpio) { |
368 | case H1940_LATCH_LED_GREEN: | 369 | case H1940_LATCH_LED_GREEN: |
diff --git a/arch/arm/mach-s3c24xx/mach-rx1950.c b/arch/arm/mach-s3c24xx/mach-rx1950.c index c3f2682d0c62..1d35ff375a01 100644 --- a/arch/arm/mach-s3c24xx/mach-rx1950.c +++ b/arch/arm/mach-s3c24xx/mach-rx1950.c | |||
@@ -250,9 +250,10 @@ static void rx1950_disable_charger(void) | |||
250 | 250 | ||
251 | static DEFINE_SPINLOCK(rx1950_blink_spin); | 251 | static DEFINE_SPINLOCK(rx1950_blink_spin); |
252 | 252 | ||
253 | static int rx1950_led_blink_set(unsigned gpio, int state, | 253 | static int rx1950_led_blink_set(struct gpio_desc *desc, int state, |
254 | unsigned long *delay_on, unsigned long *delay_off) | 254 | unsigned long *delay_on, unsigned long *delay_off) |
255 | { | 255 | { |
256 | int gpio = desc_to_gpio(desc); | ||
256 | int blink_gpio, check_gpio; | 257 | int blink_gpio, check_gpio; |
257 | 258 | ||
258 | switch (gpio) { | 259 | switch (gpio) { |
diff --git a/arch/arm/plat-orion/gpio.c b/arch/arm/plat-orion/gpio.c index e048f6198d68..e53fc8df7e4e 100644 --- a/arch/arm/plat-orion/gpio.c +++ b/arch/arm/plat-orion/gpio.c | |||
@@ -306,9 +306,10 @@ EXPORT_SYMBOL(orion_gpio_set_blink); | |||
306 | 306 | ||
307 | #define ORION_BLINK_HALF_PERIOD 100 /* ms */ | 307 | #define ORION_BLINK_HALF_PERIOD 100 /* ms */ |
308 | 308 | ||
309 | int orion_gpio_led_blink_set(unsigned gpio, int state, | 309 | int orion_gpio_led_blink_set(struct gpio_desc *desc, int state, |
310 | unsigned long *delay_on, unsigned long *delay_off) | 310 | unsigned long *delay_on, unsigned long *delay_off) |
311 | { | 311 | { |
312 | unsigned gpio = desc_to_gpio(desc); | ||
312 | 313 | ||
313 | if (delay_on && delay_off && !*delay_on && !*delay_off) | 314 | if (delay_on && delay_off && !*delay_on && !*delay_off) |
314 | *delay_on = *delay_off = ORION_BLINK_HALF_PERIOD; | 315 | *delay_on = *delay_off = ORION_BLINK_HALF_PERIOD; |
diff --git a/arch/arm/plat-orion/include/plat/orion-gpio.h b/arch/arm/plat-orion/include/plat/orion-gpio.h index e763988b04b9..e856b073a9c8 100644 --- a/arch/arm/plat-orion/include/plat/orion-gpio.h +++ b/arch/arm/plat-orion/include/plat/orion-gpio.h | |||
@@ -14,12 +14,15 @@ | |||
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/types.h> | 15 | #include <linux/types.h> |
16 | #include <linux/irqdomain.h> | 16 | #include <linux/irqdomain.h> |
17 | |||
18 | struct gpio_desc; | ||
19 | |||
17 | /* | 20 | /* |
18 | * Orion-specific GPIO API extensions. | 21 | * Orion-specific GPIO API extensions. |
19 | */ | 22 | */ |
20 | void orion_gpio_set_unused(unsigned pin); | 23 | void orion_gpio_set_unused(unsigned pin); |
21 | void orion_gpio_set_blink(unsigned pin, int blink); | 24 | void orion_gpio_set_blink(unsigned pin, int blink); |
22 | int orion_gpio_led_blink_set(unsigned gpio, int state, | 25 | int orion_gpio_led_blink_set(struct gpio_desc *desc, int state, |
23 | unsigned long *delay_on, unsigned long *delay_off); | 26 | unsigned long *delay_on, unsigned long *delay_off); |
24 | 27 | ||
25 | #define GPIO_INPUT_OK (1 << 0) | 28 | #define GPIO_INPUT_OK (1 << 0) |
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index c3b2fcb729f3..6d11522f0e48 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
@@ -47,6 +47,7 @@ acpi-y += int340x_thermal.o | |||
47 | acpi-y += power.o | 47 | acpi-y += power.o |
48 | acpi-y += event.o | 48 | acpi-y += event.o |
49 | acpi-y += sysfs.o | 49 | acpi-y += sysfs.o |
50 | acpi-y += property.o | ||
50 | acpi-$(CONFIG_X86) += acpi_cmos_rtc.o | 51 | acpi-$(CONFIG_X86) += acpi_cmos_rtc.o |
51 | acpi-$(CONFIG_DEBUG_FS) += debugfs.o | 52 | acpi-$(CONFIG_DEBUG_FS) += debugfs.o |
52 | acpi-$(CONFIG_ACPI_NUMA) += numa.o | 53 | acpi-$(CONFIG_ACPI_NUMA) += numa.o |
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 447f6d679b29..163e82f536fa 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h | |||
@@ -173,4 +173,10 @@ static inline void suspend_nvs_restore(void) {} | |||
173 | bool acpi_osi_is_win8(void); | 173 | bool acpi_osi_is_win8(void); |
174 | #endif | 174 | #endif |
175 | 175 | ||
176 | /*-------------------------------------------------------------------------- | ||
177 | Device properties | ||
178 | -------------------------------------------------------------------------- */ | ||
179 | void acpi_init_properties(struct acpi_device *adev); | ||
180 | void acpi_free_properties(struct acpi_device *adev); | ||
181 | |||
176 | #endif /* _ACPI_INTERNAL_H_ */ | 182 | #endif /* _ACPI_INTERNAL_H_ */ |
diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c new file mode 100644 index 000000000000..0d083736e25b --- /dev/null +++ b/drivers/acpi/property.c | |||
@@ -0,0 +1,551 @@ | |||
1 | /* | ||
2 | * ACPI device specific properties support. | ||
3 | * | ||
4 | * Copyright (C) 2014, Intel Corporation | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Authors: Mika Westerberg <mika.westerberg@linux.intel.com> | ||
8 | * Darren Hart <dvhart@linux.intel.com> | ||
9 | * Rafael J. Wysocki <rafael.j.wysocki@intel.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #include <linux/acpi.h> | ||
17 | #include <linux/device.h> | ||
18 | #include <linux/export.h> | ||
19 | |||
20 | #include "internal.h" | ||
21 | |||
22 | /* ACPI _DSD device properties UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */ | ||
23 | static const u8 prp_uuid[16] = { | ||
24 | 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d, | ||
25 | 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01 | ||
26 | }; | ||
27 | |||
28 | static bool acpi_property_value_ok(const union acpi_object *value) | ||
29 | { | ||
30 | int j; | ||
31 | |||
32 | /* | ||
33 | * The value must be an integer, a string, a reference, or a package | ||
34 | * whose every element must be an integer, a string, or a reference. | ||
35 | */ | ||
36 | switch (value->type) { | ||
37 | case ACPI_TYPE_INTEGER: | ||
38 | case ACPI_TYPE_STRING: | ||
39 | case ACPI_TYPE_LOCAL_REFERENCE: | ||
40 | return true; | ||
41 | |||
42 | case ACPI_TYPE_PACKAGE: | ||
43 | for (j = 0; j < value->package.count; j++) | ||
44 | switch (value->package.elements[j].type) { | ||
45 | case ACPI_TYPE_INTEGER: | ||
46 | case ACPI_TYPE_STRING: | ||
47 | case ACPI_TYPE_LOCAL_REFERENCE: | ||
48 | continue; | ||
49 | |||
50 | default: | ||
51 | return false; | ||
52 | } | ||
53 | |||
54 | return true; | ||
55 | } | ||
56 | return false; | ||
57 | } | ||
58 | |||
59 | static bool acpi_properties_format_valid(const union acpi_object *properties) | ||
60 | { | ||
61 | int i; | ||
62 | |||
63 | for (i = 0; i < properties->package.count; i++) { | ||
64 | const union acpi_object *property; | ||
65 | |||
66 | property = &properties->package.elements[i]; | ||
67 | /* | ||
68 | * Only two elements allowed, the first one must be a string and | ||
69 | * the second one has to satisfy certain conditions. | ||
70 | */ | ||
71 | if (property->package.count != 2 | ||
72 | || property->package.elements[0].type != ACPI_TYPE_STRING | ||
73 | || !acpi_property_value_ok(&property->package.elements[1])) | ||
74 | return false; | ||
75 | } | ||
76 | return true; | ||
77 | } | ||
78 | |||
79 | static void acpi_init_of_compatible(struct acpi_device *adev) | ||
80 | { | ||
81 | const union acpi_object *of_compatible; | ||
82 | struct acpi_hardware_id *hwid; | ||
83 | bool acpi_of = false; | ||
84 | int ret; | ||
85 | |||
86 | /* | ||
87 | * Check if the special PRP0001 ACPI ID is present and in that | ||
88 | * case we fill in Device Tree compatible properties for this | ||
89 | * device. | ||
90 | */ | ||
91 | list_for_each_entry(hwid, &adev->pnp.ids, list) { | ||
92 | if (!strcmp(hwid->id, "PRP0001")) { | ||
93 | acpi_of = true; | ||
94 | break; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | if (!acpi_of) | ||
99 | return; | ||
100 | |||
101 | ret = acpi_dev_get_property_array(adev, "compatible", ACPI_TYPE_STRING, | ||
102 | &of_compatible); | ||
103 | if (ret) { | ||
104 | ret = acpi_dev_get_property(adev, "compatible", | ||
105 | ACPI_TYPE_STRING, &of_compatible); | ||
106 | if (ret) { | ||
107 | acpi_handle_warn(adev->handle, | ||
108 | "PRP0001 requires compatible property\n"); | ||
109 | return; | ||
110 | } | ||
111 | } | ||
112 | adev->data.of_compatible = of_compatible; | ||
113 | } | ||
114 | |||
115 | void acpi_init_properties(struct acpi_device *adev) | ||
116 | { | ||
117 | struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER }; | ||
118 | const union acpi_object *desc; | ||
119 | acpi_status status; | ||
120 | int i; | ||
121 | |||
122 | status = acpi_evaluate_object_typed(adev->handle, "_DSD", NULL, &buf, | ||
123 | ACPI_TYPE_PACKAGE); | ||
124 | if (ACPI_FAILURE(status)) | ||
125 | return; | ||
126 | |||
127 | desc = buf.pointer; | ||
128 | if (desc->package.count % 2) | ||
129 | goto fail; | ||
130 | |||
131 | /* Look for the device properties UUID. */ | ||
132 | for (i = 0; i < desc->package.count; i += 2) { | ||
133 | const union acpi_object *uuid, *properties; | ||
134 | |||
135 | uuid = &desc->package.elements[i]; | ||
136 | properties = &desc->package.elements[i + 1]; | ||
137 | |||
138 | /* | ||
139 | * The first element must be a UUID and the second one must be | ||
140 | * a package. | ||
141 | */ | ||
142 | if (uuid->type != ACPI_TYPE_BUFFER || uuid->buffer.length != 16 | ||
143 | || properties->type != ACPI_TYPE_PACKAGE) | ||
144 | break; | ||
145 | |||
146 | if (memcmp(uuid->buffer.pointer, prp_uuid, sizeof(prp_uuid))) | ||
147 | continue; | ||
148 | |||
149 | /* | ||
150 | * We found the matching UUID. Now validate the format of the | ||
151 | * package immediately following it. | ||
152 | */ | ||
153 | if (!acpi_properties_format_valid(properties)) | ||
154 | break; | ||
155 | |||
156 | adev->data.pointer = buf.pointer; | ||
157 | adev->data.properties = properties; | ||
158 | |||
159 | acpi_init_of_compatible(adev); | ||
160 | return; | ||
161 | } | ||
162 | |||
163 | fail: | ||
164 | dev_warn(&adev->dev, "Returned _DSD data is not valid, skipping\n"); | ||
165 | ACPI_FREE(buf.pointer); | ||
166 | } | ||
167 | |||
168 | void acpi_free_properties(struct acpi_device *adev) | ||
169 | { | ||
170 | ACPI_FREE((void *)adev->data.pointer); | ||
171 | adev->data.of_compatible = NULL; | ||
172 | adev->data.pointer = NULL; | ||
173 | adev->data.properties = NULL; | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * acpi_dev_get_property - return an ACPI property with given name | ||
178 | * @adev: ACPI device to get property | ||
179 | * @name: Name of the property | ||
180 | * @type: Expected property type | ||
181 | * @obj: Location to store the property value (if not %NULL) | ||
182 | * | ||
183 | * Look up a property with @name and store a pointer to the resulting ACPI | ||
184 | * object at the location pointed to by @obj if found. | ||
185 | * | ||
186 | * Callers must not attempt to free the returned objects. These objects will be | ||
187 | * freed by the ACPI core automatically during the removal of @adev. | ||
188 | * | ||
189 | * Return: %0 if property with @name has been found (success), | ||
190 | * %-EINVAL if the arguments are invalid, | ||
191 | * %-ENODATA if the property doesn't exist, | ||
192 | * %-EPROTO if the property value type doesn't match @type. | ||
193 | */ | ||
194 | int acpi_dev_get_property(struct acpi_device *adev, const char *name, | ||
195 | acpi_object_type type, const union acpi_object **obj) | ||
196 | { | ||
197 | const union acpi_object *properties; | ||
198 | int i; | ||
199 | |||
200 | if (!adev || !name) | ||
201 | return -EINVAL; | ||
202 | |||
203 | if (!adev->data.pointer || !adev->data.properties) | ||
204 | return -ENODATA; | ||
205 | |||
206 | properties = adev->data.properties; | ||
207 | for (i = 0; i < properties->package.count; i++) { | ||
208 | const union acpi_object *propname, *propvalue; | ||
209 | const union acpi_object *property; | ||
210 | |||
211 | property = &properties->package.elements[i]; | ||
212 | |||
213 | propname = &property->package.elements[0]; | ||
214 | propvalue = &property->package.elements[1]; | ||
215 | |||
216 | if (!strcmp(name, propname->string.pointer)) { | ||
217 | if (type != ACPI_TYPE_ANY && propvalue->type != type) | ||
218 | return -EPROTO; | ||
219 | else if (obj) | ||
220 | *obj = propvalue; | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | } | ||
225 | return -ENODATA; | ||
226 | } | ||
227 | EXPORT_SYMBOL_GPL(acpi_dev_get_property); | ||
228 | |||
229 | /** | ||
230 | * acpi_dev_get_property_array - return an ACPI array property with given name | ||
231 | * @adev: ACPI device to get property | ||
232 | * @name: Name of the property | ||
233 | * @type: Expected type of array elements | ||
234 | * @obj: Location to store a pointer to the property value (if not NULL) | ||
235 | * | ||
236 | * Look up an array property with @name and store a pointer to the resulting | ||
237 | * ACPI object at the location pointed to by @obj if found. | ||
238 | * | ||
239 | * Callers must not attempt to free the returned objects. Those objects will be | ||
240 | * freed by the ACPI core automatically during the removal of @adev. | ||
241 | * | ||
242 | * Return: %0 if array property (package) with @name has been found (success), | ||
243 | * %-EINVAL if the arguments are invalid, | ||
244 | * %-ENODATA if the property doesn't exist, | ||
245 | * %-EPROTO if the property is not a package or the type of its elements | ||
246 | * doesn't match @type. | ||
247 | */ | ||
248 | int acpi_dev_get_property_array(struct acpi_device *adev, const char *name, | ||
249 | acpi_object_type type, | ||
250 | const union acpi_object **obj) | ||
251 | { | ||
252 | const union acpi_object *prop; | ||
253 | int ret, i; | ||
254 | |||
255 | ret = acpi_dev_get_property(adev, name, ACPI_TYPE_PACKAGE, &prop); | ||
256 | if (ret) | ||
257 | return ret; | ||
258 | |||
259 | if (type != ACPI_TYPE_ANY) { | ||
260 | /* Check that all elements are of correct type. */ | ||
261 | for (i = 0; i < prop->package.count; i++) | ||
262 | if (prop->package.elements[i].type != type) | ||
263 | return -EPROTO; | ||
264 | } | ||
265 | if (obj) | ||
266 | *obj = prop; | ||
267 | |||
268 | return 0; | ||
269 | } | ||
270 | EXPORT_SYMBOL_GPL(acpi_dev_get_property_array); | ||
271 | |||
272 | /** | ||
273 | * acpi_dev_get_property_reference - returns handle to the referenced object | ||
274 | * @adev: ACPI device to get property | ||
275 | * @name: Name of the property | ||
276 | * @index: Index of the reference to return | ||
277 | * @args: Location to store the returned reference with optional arguments | ||
278 | * | ||
279 | * Find property with @name, verifify that it is a package containing at least | ||
280 | * one object reference and if so, store the ACPI device object pointer to the | ||
281 | * target object in @args->adev. If the reference includes arguments, store | ||
282 | * them in the @args->args[] array. | ||
283 | * | ||
284 | * If there's more than one reference in the property value package, @index is | ||
285 | * used to select the one to return. | ||
286 | * | ||
287 | * Return: %0 on success, negative error code on failure. | ||
288 | */ | ||
289 | int acpi_dev_get_property_reference(struct acpi_device *adev, | ||
290 | const char *name, size_t index, | ||
291 | struct acpi_reference_args *args) | ||
292 | { | ||
293 | const union acpi_object *element, *end; | ||
294 | const union acpi_object *obj; | ||
295 | struct acpi_device *device; | ||
296 | int ret, idx = 0; | ||
297 | |||
298 | ret = acpi_dev_get_property(adev, name, ACPI_TYPE_ANY, &obj); | ||
299 | if (ret) | ||
300 | return ret; | ||
301 | |||
302 | /* | ||
303 | * The simplest case is when the value is a single reference. Just | ||
304 | * return that reference then. | ||
305 | */ | ||
306 | if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) { | ||
307 | if (index) | ||
308 | return -EINVAL; | ||
309 | |||
310 | ret = acpi_bus_get_device(obj->reference.handle, &device); | ||
311 | if (ret) | ||
312 | return ret; | ||
313 | |||
314 | args->adev = device; | ||
315 | args->nargs = 0; | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | /* | ||
320 | * If it is not a single reference, then it is a package of | ||
321 | * references followed by number of ints as follows: | ||
322 | * | ||
323 | * Package () { REF, INT, REF, INT, INT } | ||
324 | * | ||
325 | * The index argument is then used to determine which reference | ||
326 | * the caller wants (along with the arguments). | ||
327 | */ | ||
328 | if (obj->type != ACPI_TYPE_PACKAGE || index >= obj->package.count) | ||
329 | return -EPROTO; | ||
330 | |||
331 | element = obj->package.elements; | ||
332 | end = element + obj->package.count; | ||
333 | |||
334 | while (element < end) { | ||
335 | u32 nargs, i; | ||
336 | |||
337 | if (element->type != ACPI_TYPE_LOCAL_REFERENCE) | ||
338 | return -EPROTO; | ||
339 | |||
340 | ret = acpi_bus_get_device(element->reference.handle, &device); | ||
341 | if (ret) | ||
342 | return -ENODEV; | ||
343 | |||
344 | element++; | ||
345 | nargs = 0; | ||
346 | |||
347 | /* assume following integer elements are all args */ | ||
348 | for (i = 0; element + i < end; i++) { | ||
349 | int type = element[i].type; | ||
350 | |||
351 | if (type == ACPI_TYPE_INTEGER) | ||
352 | nargs++; | ||
353 | else if (type == ACPI_TYPE_LOCAL_REFERENCE) | ||
354 | break; | ||
355 | else | ||
356 | return -EPROTO; | ||
357 | } | ||
358 | |||
359 | if (idx++ == index) { | ||
360 | args->adev = device; | ||
361 | args->nargs = nargs; | ||
362 | for (i = 0; i < nargs; i++) | ||
363 | args->args[i] = element[i].integer.value; | ||
364 | |||
365 | return 0; | ||
366 | } | ||
367 | |||
368 | element += nargs; | ||
369 | } | ||
370 | |||
371 | return -EPROTO; | ||
372 | } | ||
373 | EXPORT_SYMBOL_GPL(acpi_dev_get_property_reference); | ||
374 | |||
375 | int acpi_dev_prop_get(struct acpi_device *adev, const char *propname, | ||
376 | void **valptr) | ||
377 | { | ||
378 | return acpi_dev_get_property(adev, propname, ACPI_TYPE_ANY, | ||
379 | (const union acpi_object **)valptr); | ||
380 | } | ||
381 | |||
382 | int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname, | ||
383 | enum dev_prop_type proptype, void *val) | ||
384 | { | ||
385 | const union acpi_object *obj; | ||
386 | int ret; | ||
387 | |||
388 | if (!val) | ||
389 | return -EINVAL; | ||
390 | |||
391 | if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) { | ||
392 | ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_INTEGER, &obj); | ||
393 | if (ret) | ||
394 | return ret; | ||
395 | |||
396 | switch (proptype) { | ||
397 | case DEV_PROP_U8: | ||
398 | if (obj->integer.value > U8_MAX) | ||
399 | return -EOVERFLOW; | ||
400 | *(u8 *)val = obj->integer.value; | ||
401 | break; | ||
402 | case DEV_PROP_U16: | ||
403 | if (obj->integer.value > U16_MAX) | ||
404 | return -EOVERFLOW; | ||
405 | *(u16 *)val = obj->integer.value; | ||
406 | break; | ||
407 | case DEV_PROP_U32: | ||
408 | if (obj->integer.value > U32_MAX) | ||
409 | return -EOVERFLOW; | ||
410 | *(u32 *)val = obj->integer.value; | ||
411 | break; | ||
412 | default: | ||
413 | *(u64 *)val = obj->integer.value; | ||
414 | break; | ||
415 | } | ||
416 | } else if (proptype == DEV_PROP_STRING) { | ||
417 | ret = acpi_dev_get_property(adev, propname, ACPI_TYPE_STRING, &obj); | ||
418 | if (ret) | ||
419 | return ret; | ||
420 | |||
421 | *(char **)val = obj->string.pointer; | ||
422 | } else { | ||
423 | ret = -EINVAL; | ||
424 | } | ||
425 | return ret; | ||
426 | } | ||
427 | |||
428 | static int acpi_copy_property_array_u8(const union acpi_object *items, u8 *val, | ||
429 | size_t nval) | ||
430 | { | ||
431 | int i; | ||
432 | |||
433 | for (i = 0; i < nval; i++) { | ||
434 | if (items[i].type != ACPI_TYPE_INTEGER) | ||
435 | return -EPROTO; | ||
436 | if (items[i].integer.value > U8_MAX) | ||
437 | return -EOVERFLOW; | ||
438 | |||
439 | val[i] = items[i].integer.value; | ||
440 | } | ||
441 | return 0; | ||
442 | } | ||
443 | |||
444 | static int acpi_copy_property_array_u16(const union acpi_object *items, | ||
445 | u16 *val, size_t nval) | ||
446 | { | ||
447 | int i; | ||
448 | |||
449 | for (i = 0; i < nval; i++) { | ||
450 | if (items[i].type != ACPI_TYPE_INTEGER) | ||
451 | return -EPROTO; | ||
452 | if (items[i].integer.value > U16_MAX) | ||
453 | return -EOVERFLOW; | ||
454 | |||
455 | val[i] = items[i].integer.value; | ||
456 | } | ||
457 | return 0; | ||
458 | } | ||
459 | |||
460 | static int acpi_copy_property_array_u32(const union acpi_object *items, | ||
461 | u32 *val, size_t nval) | ||
462 | { | ||
463 | int i; | ||
464 | |||
465 | for (i = 0; i < nval; i++) { | ||
466 | if (items[i].type != ACPI_TYPE_INTEGER) | ||
467 | return -EPROTO; | ||
468 | if (items[i].integer.value > U32_MAX) | ||
469 | return -EOVERFLOW; | ||
470 | |||
471 | val[i] = items[i].integer.value; | ||
472 | } | ||
473 | return 0; | ||
474 | } | ||
475 | |||
476 | static int acpi_copy_property_array_u64(const union acpi_object *items, | ||
477 | u64 *val, size_t nval) | ||
478 | { | ||
479 | int i; | ||
480 | |||
481 | for (i = 0; i < nval; i++) { | ||
482 | if (items[i].type != ACPI_TYPE_INTEGER) | ||
483 | return -EPROTO; | ||
484 | |||
485 | val[i] = items[i].integer.value; | ||
486 | } | ||
487 | return 0; | ||
488 | } | ||
489 | |||
490 | static int acpi_copy_property_array_string(const union acpi_object *items, | ||
491 | char **val, size_t nval) | ||
492 | { | ||
493 | int i; | ||
494 | |||
495 | for (i = 0; i < nval; i++) { | ||
496 | if (items[i].type != ACPI_TYPE_STRING) | ||
497 | return -EPROTO; | ||
498 | |||
499 | val[i] = items[i].string.pointer; | ||
500 | } | ||
501 | return 0; | ||
502 | } | ||
503 | |||
504 | int acpi_dev_prop_read(struct acpi_device *adev, const char *propname, | ||
505 | enum dev_prop_type proptype, void *val, size_t nval) | ||
506 | { | ||
507 | const union acpi_object *obj; | ||
508 | const union acpi_object *items; | ||
509 | int ret; | ||
510 | |||
511 | if (val && nval == 1) { | ||
512 | ret = acpi_dev_prop_read_single(adev, propname, proptype, val); | ||
513 | if (!ret) | ||
514 | return ret; | ||
515 | } | ||
516 | |||
517 | ret = acpi_dev_get_property_array(adev, propname, ACPI_TYPE_ANY, &obj); | ||
518 | if (ret) | ||
519 | return ret; | ||
520 | |||
521 | if (!val) | ||
522 | return obj->package.count; | ||
523 | else if (nval <= 0) | ||
524 | return -EINVAL; | ||
525 | |||
526 | if (nval > obj->package.count) | ||
527 | return -EOVERFLOW; | ||
528 | |||
529 | items = obj->package.elements; | ||
530 | switch (proptype) { | ||
531 | case DEV_PROP_U8: | ||
532 | ret = acpi_copy_property_array_u8(items, (u8 *)val, nval); | ||
533 | break; | ||
534 | case DEV_PROP_U16: | ||
535 | ret = acpi_copy_property_array_u16(items, (u16 *)val, nval); | ||
536 | break; | ||
537 | case DEV_PROP_U32: | ||
538 | ret = acpi_copy_property_array_u32(items, (u32 *)val, nval); | ||
539 | break; | ||
540 | case DEV_PROP_U64: | ||
541 | ret = acpi_copy_property_array_u64(items, (u64 *)val, nval); | ||
542 | break; | ||
543 | case DEV_PROP_STRING: | ||
544 | ret = acpi_copy_property_array_string(items, (char **)val, nval); | ||
545 | break; | ||
546 | default: | ||
547 | ret = -EINVAL; | ||
548 | break; | ||
549 | } | ||
550 | return ret; | ||
551 | } | ||
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 0476e90b2091..9cb5cca3cfe3 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -124,17 +124,56 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias, | |||
124 | if (list_empty(&acpi_dev->pnp.ids)) | 124 | if (list_empty(&acpi_dev->pnp.ids)) |
125 | return 0; | 125 | return 0; |
126 | 126 | ||
127 | len = snprintf(modalias, size, "acpi:"); | 127 | /* |
128 | size -= len; | 128 | * If the device has PRP0001 we expose DT compatible modalias |
129 | 129 | * instead in form of of:NnameTCcompatible. | |
130 | list_for_each_entry(id, &acpi_dev->pnp.ids, list) { | 130 | */ |
131 | count = snprintf(&modalias[len], size, "%s:", id->id); | 131 | if (acpi_dev->data.of_compatible) { |
132 | if (count < 0) | 132 | struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER }; |
133 | return -EINVAL; | 133 | const union acpi_object *of_compatible, *obj; |
134 | if (count >= size) | 134 | int i, nval; |
135 | return -ENOMEM; | 135 | char *c; |
136 | len += count; | 136 | |
137 | size -= count; | 137 | acpi_get_name(acpi_dev->handle, ACPI_SINGLE_NAME, &buf); |
138 | /* DT strings are all in lower case */ | ||
139 | for (c = buf.pointer; *c != '\0'; c++) | ||
140 | *c = tolower(*c); | ||
141 | |||
142 | len = snprintf(modalias, size, "of:N%sT", (char *)buf.pointer); | ||
143 | ACPI_FREE(buf.pointer); | ||
144 | |||
145 | of_compatible = acpi_dev->data.of_compatible; | ||
146 | if (of_compatible->type == ACPI_TYPE_PACKAGE) { | ||
147 | nval = of_compatible->package.count; | ||
148 | obj = of_compatible->package.elements; | ||
149 | } else { /* Must be ACPI_TYPE_STRING. */ | ||
150 | nval = 1; | ||
151 | obj = of_compatible; | ||
152 | } | ||
153 | for (i = 0; i < nval; i++, obj++) { | ||
154 | count = snprintf(&modalias[len], size, "C%s", | ||
155 | obj->string.pointer); | ||
156 | if (count < 0) | ||
157 | return -EINVAL; | ||
158 | if (count >= size) | ||
159 | return -ENOMEM; | ||
160 | |||
161 | len += count; | ||
162 | size -= count; | ||
163 | } | ||
164 | } else { | ||
165 | len = snprintf(modalias, size, "acpi:"); | ||
166 | size -= len; | ||
167 | |||
168 | list_for_each_entry(id, &acpi_dev->pnp.ids, list) { | ||
169 | count = snprintf(&modalias[len], size, "%s:", id->id); | ||
170 | if (count < 0) | ||
171 | return -EINVAL; | ||
172 | if (count >= size) | ||
173 | return -ENOMEM; | ||
174 | len += count; | ||
175 | size -= count; | ||
176 | } | ||
138 | } | 177 | } |
139 | 178 | ||
140 | modalias[len] = '\0'; | 179 | modalias[len] = '\0'; |
@@ -902,6 +941,51 @@ int acpi_match_device_ids(struct acpi_device *device, | |||
902 | } | 941 | } |
903 | EXPORT_SYMBOL(acpi_match_device_ids); | 942 | EXPORT_SYMBOL(acpi_match_device_ids); |
904 | 943 | ||
944 | /* Performs match against special "PRP0001" shoehorn ACPI ID */ | ||
945 | static bool acpi_of_driver_match_device(struct device *dev, | ||
946 | const struct device_driver *drv) | ||
947 | { | ||
948 | const union acpi_object *of_compatible, *obj; | ||
949 | struct acpi_device *adev; | ||
950 | int i, nval; | ||
951 | |||
952 | adev = ACPI_COMPANION(dev); | ||
953 | if (!adev) | ||
954 | return false; | ||
955 | |||
956 | of_compatible = adev->data.of_compatible; | ||
957 | if (!drv->of_match_table || !of_compatible) | ||
958 | return false; | ||
959 | |||
960 | if (of_compatible->type == ACPI_TYPE_PACKAGE) { | ||
961 | nval = of_compatible->package.count; | ||
962 | obj = of_compatible->package.elements; | ||
963 | } else { /* Must be ACPI_TYPE_STRING. */ | ||
964 | nval = 1; | ||
965 | obj = of_compatible; | ||
966 | } | ||
967 | /* Now we can look for the driver DT compatible strings */ | ||
968 | for (i = 0; i < nval; i++, obj++) { | ||
969 | const struct of_device_id *id; | ||
970 | |||
971 | for (id = drv->of_match_table; id->compatible[0]; id++) | ||
972 | if (!strcasecmp(obj->string.pointer, id->compatible)) | ||
973 | return true; | ||
974 | } | ||
975 | |||
976 | return false; | ||
977 | } | ||
978 | |||
979 | bool acpi_driver_match_device(struct device *dev, | ||
980 | const struct device_driver *drv) | ||
981 | { | ||
982 | if (!drv->acpi_match_table) | ||
983 | return acpi_of_driver_match_device(dev, drv); | ||
984 | |||
985 | return !!acpi_match_device(drv->acpi_match_table, dev); | ||
986 | } | ||
987 | EXPORT_SYMBOL_GPL(acpi_driver_match_device); | ||
988 | |||
905 | static void acpi_free_power_resources_lists(struct acpi_device *device) | 989 | static void acpi_free_power_resources_lists(struct acpi_device *device) |
906 | { | 990 | { |
907 | int i; | 991 | int i; |
@@ -922,6 +1006,7 @@ static void acpi_device_release(struct device *dev) | |||
922 | { | 1006 | { |
923 | struct acpi_device *acpi_dev = to_acpi_device(dev); | 1007 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
924 | 1008 | ||
1009 | acpi_free_properties(acpi_dev); | ||
925 | acpi_free_pnp_ids(&acpi_dev->pnp); | 1010 | acpi_free_pnp_ids(&acpi_dev->pnp); |
926 | acpi_free_power_resources_lists(acpi_dev); | 1011 | acpi_free_power_resources_lists(acpi_dev); |
927 | kfree(acpi_dev); | 1012 | kfree(acpi_dev); |
@@ -1304,6 +1389,26 @@ int acpi_device_add(struct acpi_device *device, | |||
1304 | return result; | 1389 | return result; |
1305 | } | 1390 | } |
1306 | 1391 | ||
1392 | struct acpi_device *acpi_get_next_child(struct device *dev, | ||
1393 | struct acpi_device *child) | ||
1394 | { | ||
1395 | struct acpi_device *adev = ACPI_COMPANION(dev); | ||
1396 | struct list_head *head, *next; | ||
1397 | |||
1398 | if (!adev) | ||
1399 | return NULL; | ||
1400 | |||
1401 | head = &adev->children; | ||
1402 | if (list_empty(head)) | ||
1403 | return NULL; | ||
1404 | |||
1405 | if (!child) | ||
1406 | return list_first_entry(head, struct acpi_device, node); | ||
1407 | |||
1408 | next = child->node.next; | ||
1409 | return next == head ? NULL : list_entry(next, struct acpi_device, node); | ||
1410 | } | ||
1411 | |||
1307 | /* -------------------------------------------------------------------------- | 1412 | /* -------------------------------------------------------------------------- |
1308 | Driver Management | 1413 | Driver Management |
1309 | -------------------------------------------------------------------------- */ | 1414 | -------------------------------------------------------------------------- */ |
@@ -1923,9 +2028,11 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, | |||
1923 | device->device_type = type; | 2028 | device->device_type = type; |
1924 | device->handle = handle; | 2029 | device->handle = handle; |
1925 | device->parent = acpi_bus_get_parent(handle); | 2030 | device->parent = acpi_bus_get_parent(handle); |
2031 | device->fwnode.type = FWNODE_ACPI; | ||
1926 | acpi_set_device_status(device, sta); | 2032 | acpi_set_device_status(device, sta); |
1927 | acpi_device_get_busid(device); | 2033 | acpi_device_get_busid(device); |
1928 | acpi_set_pnp_ids(handle, &device->pnp, type); | 2034 | acpi_set_pnp_ids(handle, &device->pnp, type); |
2035 | acpi_init_properties(device); | ||
1929 | acpi_bus_get_flags(device); | 2036 | acpi_bus_get_flags(device); |
1930 | device->flags.match_driver = false; | 2037 | device->flags.match_driver = false; |
1931 | device->flags.initialized = true; | 2038 | device->flags.initialized = true; |
diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 6922cd6850a2..53c3fe1aeb29 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile | |||
@@ -4,7 +4,7 @@ obj-y := component.o core.o bus.o dd.o syscore.o \ | |||
4 | driver.o class.o platform.o \ | 4 | driver.o class.o platform.o \ |
5 | cpu.o firmware.o init.o map.o devres.o \ | 5 | cpu.o firmware.o init.o map.o devres.o \ |
6 | attribute_container.o transport_class.o \ | 6 | attribute_container.o transport_class.o \ |
7 | topology.o container.o | 7 | topology.o container.o property.o |
8 | obj-$(CONFIG_DEVTMPFS) += devtmpfs.o | 8 | obj-$(CONFIG_DEVTMPFS) += devtmpfs.o |
9 | obj-$(CONFIG_DMA_CMA) += dma-contiguous.o | 9 | obj-$(CONFIG_DMA_CMA) += dma-contiguous.o |
10 | obj-y += power/ | 10 | obj-y += power/ |
diff --git a/drivers/base/property.c b/drivers/base/property.c new file mode 100644 index 000000000000..c45845874d4f --- /dev/null +++ b/drivers/base/property.c | |||
@@ -0,0 +1,431 @@ | |||
1 | /* | ||
2 | * property.c - Unified device property interface. | ||
3 | * | ||
4 | * Copyright (C) 2014, Intel Corporation | ||
5 | * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | ||
6 | * Mika Westerberg <mika.westerberg@linux.intel.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/property.h> | ||
14 | #include <linux/export.h> | ||
15 | #include <linux/acpi.h> | ||
16 | #include <linux/of.h> | ||
17 | |||
18 | /** | ||
19 | * device_property_present - check if a property of a device is present | ||
20 | * @dev: Device whose property is being checked | ||
21 | * @propname: Name of the property | ||
22 | * | ||
23 | * Check if property @propname is present in the device firmware description. | ||
24 | */ | ||
25 | bool device_property_present(struct device *dev, const char *propname) | ||
26 | { | ||
27 | if (IS_ENABLED(CONFIG_OF) && dev->of_node) | ||
28 | return of_property_read_bool(dev->of_node, propname); | ||
29 | |||
30 | return !acpi_dev_prop_get(ACPI_COMPANION(dev), propname, NULL); | ||
31 | } | ||
32 | EXPORT_SYMBOL_GPL(device_property_present); | ||
33 | |||
34 | /** | ||
35 | * fwnode_property_present - check if a property of a firmware node is present | ||
36 | * @fwnode: Firmware node whose property to check | ||
37 | * @propname: Name of the property | ||
38 | */ | ||
39 | bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname) | ||
40 | { | ||
41 | if (is_of_node(fwnode)) | ||
42 | return of_property_read_bool(of_node(fwnode), propname); | ||
43 | else if (is_acpi_node(fwnode)) | ||
44 | return !acpi_dev_prop_get(acpi_node(fwnode), propname, NULL); | ||
45 | |||
46 | return false; | ||
47 | } | ||
48 | EXPORT_SYMBOL_GPL(fwnode_property_present); | ||
49 | |||
50 | #define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \ | ||
51 | (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \ | ||
52 | : of_property_count_elems_of_size((node), (propname), sizeof(type)) | ||
53 | |||
54 | #define DEV_PROP_READ_ARRAY(_dev_, _propname_, _type_, _proptype_, _val_, _nval_) \ | ||
55 | IS_ENABLED(CONFIG_OF) && _dev_->of_node ? \ | ||
56 | (OF_DEV_PROP_READ_ARRAY(_dev_->of_node, _propname_, _type_, \ | ||
57 | _val_, _nval_)) : \ | ||
58 | acpi_dev_prop_read(ACPI_COMPANION(_dev_), _propname_, \ | ||
59 | _proptype_, _val_, _nval_) | ||
60 | |||
61 | /** | ||
62 | * device_property_read_u8_array - return a u8 array property of a device | ||
63 | * @dev: Device to get the property of | ||
64 | * @propname: Name of the property | ||
65 | * @val: The values are stored here | ||
66 | * @nval: Size of the @val array | ||
67 | * | ||
68 | * Function reads an array of u8 properties with @propname from the device | ||
69 | * firmware description and stores them to @val if found. | ||
70 | * | ||
71 | * Return: %0 if the property was found (success), | ||
72 | * %-EINVAL if given arguments are not valid, | ||
73 | * %-ENODATA if the property does not have a value, | ||
74 | * %-EPROTO if the property is not an array of numbers, | ||
75 | * %-EOVERFLOW if the size of the property is not as expected. | ||
76 | */ | ||
77 | int device_property_read_u8_array(struct device *dev, const char *propname, | ||
78 | u8 *val, size_t nval) | ||
79 | { | ||
80 | return DEV_PROP_READ_ARRAY(dev, propname, u8, DEV_PROP_U8, val, nval); | ||
81 | } | ||
82 | EXPORT_SYMBOL_GPL(device_property_read_u8_array); | ||
83 | |||
84 | /** | ||
85 | * device_property_read_u16_array - return a u16 array property of a device | ||
86 | * @dev: Device to get the property of | ||
87 | * @propname: Name of the property | ||
88 | * @val: The values are stored here | ||
89 | * @nval: Size of the @val array | ||
90 | * | ||
91 | * Function reads an array of u16 properties with @propname from the device | ||
92 | * firmware description and stores them to @val if found. | ||
93 | * | ||
94 | * Return: %0 if the property was found (success), | ||
95 | * %-EINVAL if given arguments are not valid, | ||
96 | * %-ENODATA if the property does not have a value, | ||
97 | * %-EPROTO if the property is not an array of numbers, | ||
98 | * %-EOVERFLOW if the size of the property is not as expected. | ||
99 | */ | ||
100 | int device_property_read_u16_array(struct device *dev, const char *propname, | ||
101 | u16 *val, size_t nval) | ||
102 | { | ||
103 | return DEV_PROP_READ_ARRAY(dev, propname, u16, DEV_PROP_U16, val, nval); | ||
104 | } | ||
105 | EXPORT_SYMBOL_GPL(device_property_read_u16_array); | ||
106 | |||
107 | /** | ||
108 | * device_property_read_u32_array - return a u32 array property of a device | ||
109 | * @dev: Device to get the property of | ||
110 | * @propname: Name of the property | ||
111 | * @val: The values are stored here | ||
112 | * @nval: Size of the @val array | ||
113 | * | ||
114 | * Function reads an array of u32 properties with @propname from the device | ||
115 | * firmware description and stores them to @val if found. | ||
116 | * | ||
117 | * Return: %0 if the property was found (success), | ||
118 | * %-EINVAL if given arguments are not valid, | ||
119 | * %-ENODATA if the property does not have a value, | ||
120 | * %-EPROTO if the property is not an array of numbers, | ||
121 | * %-EOVERFLOW if the size of the property is not as expected. | ||
122 | */ | ||
123 | int device_property_read_u32_array(struct device *dev, const char *propname, | ||
124 | u32 *val, size_t nval) | ||
125 | { | ||
126 | return DEV_PROP_READ_ARRAY(dev, propname, u32, DEV_PROP_U32, val, nval); | ||
127 | } | ||
128 | EXPORT_SYMBOL_GPL(device_property_read_u32_array); | ||
129 | |||
130 | /** | ||
131 | * device_property_read_u64_array - return a u64 array property of a device | ||
132 | * @dev: Device to get the property of | ||
133 | * @propname: Name of the property | ||
134 | * @val: The values are stored here | ||
135 | * @nval: Size of the @val array | ||
136 | * | ||
137 | * Function reads an array of u64 properties with @propname from the device | ||
138 | * firmware description and stores them to @val if found. | ||
139 | * | ||
140 | * Return: %0 if the property was found (success), | ||
141 | * %-EINVAL if given arguments are not valid, | ||
142 | * %-ENODATA if the property does not have a value, | ||
143 | * %-EPROTO if the property is not an array of numbers, | ||
144 | * %-EOVERFLOW if the size of the property is not as expected. | ||
145 | */ | ||
146 | int device_property_read_u64_array(struct device *dev, const char *propname, | ||
147 | u64 *val, size_t nval) | ||
148 | { | ||
149 | return DEV_PROP_READ_ARRAY(dev, propname, u64, DEV_PROP_U64, val, nval); | ||
150 | } | ||
151 | EXPORT_SYMBOL_GPL(device_property_read_u64_array); | ||
152 | |||
153 | /** | ||
154 | * device_property_read_string_array - return a string array property of device | ||
155 | * @dev: Device to get the property of | ||
156 | * @propname: Name of the property | ||
157 | * @val: The values are stored here | ||
158 | * @nval: Size of the @val array | ||
159 | * | ||
160 | * Function reads an array of string properties with @propname from the device | ||
161 | * firmware description and stores them to @val if found. | ||
162 | * | ||
163 | * Return: %0 if the property was found (success), | ||
164 | * %-EINVAL if given arguments are not valid, | ||
165 | * %-ENODATA if the property does not have a value, | ||
166 | * %-EPROTO or %-EILSEQ if the property is not an array of strings, | ||
167 | * %-EOVERFLOW if the size of the property is not as expected. | ||
168 | */ | ||
169 | int device_property_read_string_array(struct device *dev, const char *propname, | ||
170 | const char **val, size_t nval) | ||
171 | { | ||
172 | return IS_ENABLED(CONFIG_OF) && dev->of_node ? | ||
173 | of_property_read_string_array(dev->of_node, propname, val, nval) : | ||
174 | acpi_dev_prop_read(ACPI_COMPANION(dev), propname, | ||
175 | DEV_PROP_STRING, val, nval); | ||
176 | } | ||
177 | EXPORT_SYMBOL_GPL(device_property_read_string_array); | ||
178 | |||
179 | /** | ||
180 | * device_property_read_string - return a string property of a device | ||
181 | * @dev: Device to get the property of | ||
182 | * @propname: Name of the property | ||
183 | * @val: The value is stored here | ||
184 | * | ||
185 | * Function reads property @propname from the device firmware description and | ||
186 | * stores the value into @val if found. The value is checked to be a string. | ||
187 | * | ||
188 | * Return: %0 if the property was found (success), | ||
189 | * %-EINVAL if given arguments are not valid, | ||
190 | * %-ENODATA if the property does not have a value, | ||
191 | * %-EPROTO or %-EILSEQ if the property type is not a string. | ||
192 | */ | ||
193 | int device_property_read_string(struct device *dev, const char *propname, | ||
194 | const char **val) | ||
195 | { | ||
196 | return IS_ENABLED(CONFIG_OF) && dev->of_node ? | ||
197 | of_property_read_string(dev->of_node, propname, val) : | ||
198 | acpi_dev_prop_read(ACPI_COMPANION(dev), propname, | ||
199 | DEV_PROP_STRING, val, 1); | ||
200 | } | ||
201 | EXPORT_SYMBOL_GPL(device_property_read_string); | ||
202 | |||
203 | #define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_) \ | ||
204 | ({ \ | ||
205 | int _ret_; \ | ||
206 | if (is_of_node(_fwnode_)) \ | ||
207 | _ret_ = OF_DEV_PROP_READ_ARRAY(of_node(_fwnode_), _propname_, \ | ||
208 | _type_, _val_, _nval_); \ | ||
209 | else if (is_acpi_node(_fwnode_)) \ | ||
210 | _ret_ = acpi_dev_prop_read(acpi_node(_fwnode_), _propname_, \ | ||
211 | _proptype_, _val_, _nval_); \ | ||
212 | else \ | ||
213 | _ret_ = -ENXIO; \ | ||
214 | _ret_; \ | ||
215 | }) | ||
216 | |||
217 | /** | ||
218 | * fwnode_property_read_u8_array - return a u8 array property of firmware node | ||
219 | * @fwnode: Firmware node to get the property of | ||
220 | * @propname: Name of the property | ||
221 | * @val: The values are stored here | ||
222 | * @nval: Size of the @val array | ||
223 | * | ||
224 | * Read an array of u8 properties with @propname from @fwnode and stores them to | ||
225 | * @val if found. | ||
226 | * | ||
227 | * Return: %0 if the property was found (success), | ||
228 | * %-EINVAL if given arguments are not valid, | ||
229 | * %-ENODATA if the property does not have a value, | ||
230 | * %-EPROTO if the property is not an array of numbers, | ||
231 | * %-EOVERFLOW if the size of the property is not as expected, | ||
232 | * %-ENXIO if no suitable firmware interface is present. | ||
233 | */ | ||
234 | int fwnode_property_read_u8_array(struct fwnode_handle *fwnode, | ||
235 | const char *propname, u8 *val, size_t nval) | ||
236 | { | ||
237 | return FWNODE_PROP_READ_ARRAY(fwnode, propname, u8, DEV_PROP_U8, | ||
238 | val, nval); | ||
239 | } | ||
240 | EXPORT_SYMBOL_GPL(fwnode_property_read_u8_array); | ||
241 | |||
242 | /** | ||
243 | * fwnode_property_read_u16_array - return a u16 array property of firmware node | ||
244 | * @fwnode: Firmware node to get the property of | ||
245 | * @propname: Name of the property | ||
246 | * @val: The values are stored here | ||
247 | * @nval: Size of the @val array | ||
248 | * | ||
249 | * Read an array of u16 properties with @propname from @fwnode and store them to | ||
250 | * @val if found. | ||
251 | * | ||
252 | * Return: %0 if the property was found (success), | ||
253 | * %-EINVAL if given arguments are not valid, | ||
254 | * %-ENODATA if the property does not have a value, | ||
255 | * %-EPROTO if the property is not an array of numbers, | ||
256 | * %-EOVERFLOW if the size of the property is not as expected, | ||
257 | * %-ENXIO if no suitable firmware interface is present. | ||
258 | */ | ||
259 | int fwnode_property_read_u16_array(struct fwnode_handle *fwnode, | ||
260 | const char *propname, u16 *val, size_t nval) | ||
261 | { | ||
262 | return FWNODE_PROP_READ_ARRAY(fwnode, propname, u16, DEV_PROP_U16, | ||
263 | val, nval); | ||
264 | } | ||
265 | EXPORT_SYMBOL_GPL(fwnode_property_read_u16_array); | ||
266 | |||
267 | /** | ||
268 | * fwnode_property_read_u32_array - return a u32 array property of firmware node | ||
269 | * @fwnode: Firmware node to get the property of | ||
270 | * @propname: Name of the property | ||
271 | * @val: The values are stored here | ||
272 | * @nval: Size of the @val array | ||
273 | * | ||
274 | * Read an array of u32 properties with @propname from @fwnode store them to | ||
275 | * @val if found. | ||
276 | * | ||
277 | * Return: %0 if the property was found (success), | ||
278 | * %-EINVAL if given arguments are not valid, | ||
279 | * %-ENODATA if the property does not have a value, | ||
280 | * %-EPROTO if the property is not an array of numbers, | ||
281 | * %-EOVERFLOW if the size of the property is not as expected, | ||
282 | * %-ENXIO if no suitable firmware interface is present. | ||
283 | */ | ||
284 | int fwnode_property_read_u32_array(struct fwnode_handle *fwnode, | ||
285 | const char *propname, u32 *val, size_t nval) | ||
286 | { | ||
287 | return FWNODE_PROP_READ_ARRAY(fwnode, propname, u32, DEV_PROP_U32, | ||
288 | val, nval); | ||
289 | } | ||
290 | EXPORT_SYMBOL_GPL(fwnode_property_read_u32_array); | ||
291 | |||
292 | /** | ||
293 | * fwnode_property_read_u64_array - return a u64 array property firmware node | ||
294 | * @fwnode: Firmware node to get the property of | ||
295 | * @propname: Name of the property | ||
296 | * @val: The values are stored here | ||
297 | * @nval: Size of the @val array | ||
298 | * | ||
299 | * Read an array of u64 properties with @propname from @fwnode and store them to | ||
300 | * @val if found. | ||
301 | * | ||
302 | * Return: %0 if the property was found (success), | ||
303 | * %-EINVAL if given arguments are not valid, | ||
304 | * %-ENODATA if the property does not have a value, | ||
305 | * %-EPROTO if the property is not an array of numbers, | ||
306 | * %-EOVERFLOW if the size of the property is not as expected, | ||
307 | * %-ENXIO if no suitable firmware interface is present. | ||
308 | */ | ||
309 | int fwnode_property_read_u64_array(struct fwnode_handle *fwnode, | ||
310 | const char *propname, u64 *val, size_t nval) | ||
311 | { | ||
312 | return FWNODE_PROP_READ_ARRAY(fwnode, propname, u64, DEV_PROP_U64, | ||
313 | val, nval); | ||
314 | } | ||
315 | EXPORT_SYMBOL_GPL(fwnode_property_read_u64_array); | ||
316 | |||
317 | /** | ||
318 | * fwnode_property_read_string_array - return string array property of a node | ||
319 | * @fwnode: Firmware node to get the property of | ||
320 | * @propname: Name of the property | ||
321 | * @val: The values are stored here | ||
322 | * @nval: Size of the @val array | ||
323 | * | ||
324 | * Read an string list property @propname from the given firmware node and store | ||
325 | * them to @val if found. | ||
326 | * | ||
327 | * Return: %0 if the property was found (success), | ||
328 | * %-EINVAL if given arguments are not valid, | ||
329 | * %-ENODATA if the property does not have a value, | ||
330 | * %-EPROTO if the property is not an array of strings, | ||
331 | * %-EOVERFLOW if the size of the property is not as expected, | ||
332 | * %-ENXIO if no suitable firmware interface is present. | ||
333 | */ | ||
334 | int fwnode_property_read_string_array(struct fwnode_handle *fwnode, | ||
335 | const char *propname, const char **val, | ||
336 | size_t nval) | ||
337 | { | ||
338 | if (is_of_node(fwnode)) | ||
339 | return of_property_read_string_array(of_node(fwnode), propname, | ||
340 | val, nval); | ||
341 | else if (is_acpi_node(fwnode)) | ||
342 | return acpi_dev_prop_read(acpi_node(fwnode), propname, | ||
343 | DEV_PROP_STRING, val, nval); | ||
344 | |||
345 | return -ENXIO; | ||
346 | } | ||
347 | EXPORT_SYMBOL_GPL(fwnode_property_read_string_array); | ||
348 | |||
349 | /** | ||
350 | * fwnode_property_read_string - return a string property of a firmware node | ||
351 | * @fwnode: Firmware node to get the property of | ||
352 | * @propname: Name of the property | ||
353 | * @val: The value is stored here | ||
354 | * | ||
355 | * Read property @propname from the given firmware node and store the value into | ||
356 | * @val if found. The value is checked to be a string. | ||
357 | * | ||
358 | * Return: %0 if the property was found (success), | ||
359 | * %-EINVAL if given arguments are not valid, | ||
360 | * %-ENODATA if the property does not have a value, | ||
361 | * %-EPROTO or %-EILSEQ if the property is not a string, | ||
362 | * %-ENXIO if no suitable firmware interface is present. | ||
363 | */ | ||
364 | int fwnode_property_read_string(struct fwnode_handle *fwnode, | ||
365 | const char *propname, const char **val) | ||
366 | { | ||
367 | if (is_of_node(fwnode)) | ||
368 | return of_property_read_string(of_node(fwnode),propname, val); | ||
369 | else if (is_acpi_node(fwnode)) | ||
370 | return acpi_dev_prop_read(acpi_node(fwnode), propname, | ||
371 | DEV_PROP_STRING, val, 1); | ||
372 | |||
373 | return -ENXIO; | ||
374 | } | ||
375 | EXPORT_SYMBOL_GPL(fwnode_property_read_string); | ||
376 | |||
377 | /** | ||
378 | * device_get_next_child_node - Return the next child node handle for a device | ||
379 | * @dev: Device to find the next child node for. | ||
380 | * @child: Handle to one of the device's child nodes or a null handle. | ||
381 | */ | ||
382 | struct fwnode_handle *device_get_next_child_node(struct device *dev, | ||
383 | struct fwnode_handle *child) | ||
384 | { | ||
385 | if (IS_ENABLED(CONFIG_OF) && dev->of_node) { | ||
386 | struct device_node *node; | ||
387 | |||
388 | node = of_get_next_available_child(dev->of_node, of_node(child)); | ||
389 | if (node) | ||
390 | return &node->fwnode; | ||
391 | } else if (IS_ENABLED(CONFIG_ACPI)) { | ||
392 | struct acpi_device *node; | ||
393 | |||
394 | node = acpi_get_next_child(dev, acpi_node(child)); | ||
395 | if (node) | ||
396 | return acpi_fwnode_handle(node); | ||
397 | } | ||
398 | return NULL; | ||
399 | } | ||
400 | EXPORT_SYMBOL_GPL(device_get_next_child_node); | ||
401 | |||
402 | /** | ||
403 | * fwnode_handle_put - Drop reference to a device node | ||
404 | * @fwnode: Pointer to the device node to drop the reference to. | ||
405 | * | ||
406 | * This has to be used when terminating device_for_each_child_node() iteration | ||
407 | * with break or return to prevent stale device node references from being left | ||
408 | * behind. | ||
409 | */ | ||
410 | void fwnode_handle_put(struct fwnode_handle *fwnode) | ||
411 | { | ||
412 | if (is_of_node(fwnode)) | ||
413 | of_node_put(of_node(fwnode)); | ||
414 | } | ||
415 | EXPORT_SYMBOL_GPL(fwnode_handle_put); | ||
416 | |||
417 | /** | ||
418 | * device_get_child_node_count - return the number of child nodes for device | ||
419 | * @dev: Device to cound the child nodes for | ||
420 | */ | ||
421 | unsigned int device_get_child_node_count(struct device *dev) | ||
422 | { | ||
423 | struct fwnode_handle *child; | ||
424 | unsigned int count = 0; | ||
425 | |||
426 | device_for_each_child_node(dev, child) | ||
427 | count++; | ||
428 | |||
429 | return count; | ||
430 | } | ||
431 | EXPORT_SYMBOL_GPL(device_get_child_node_count); | ||
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c index 954b9f6b0ef8..13dbd3dfc33a 100644 --- a/drivers/gpio/devres.c +++ b/drivers/gpio/devres.c | |||
@@ -109,6 +109,38 @@ struct gpio_desc *__must_check __devm_gpiod_get_index(struct device *dev, | |||
109 | EXPORT_SYMBOL(__devm_gpiod_get_index); | 109 | EXPORT_SYMBOL(__devm_gpiod_get_index); |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * devm_get_gpiod_from_child - get a GPIO descriptor from a device's child node | ||
113 | * @dev: GPIO consumer | ||
114 | * @child: firmware node (child of @dev) | ||
115 | * | ||
116 | * GPIO descriptors returned from this function are automatically disposed on | ||
117 | * driver detach. | ||
118 | */ | ||
119 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, | ||
120 | struct fwnode_handle *child) | ||
121 | { | ||
122 | struct gpio_desc **dr; | ||
123 | struct gpio_desc *desc; | ||
124 | |||
125 | dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), | ||
126 | GFP_KERNEL); | ||
127 | if (!dr) | ||
128 | return ERR_PTR(-ENOMEM); | ||
129 | |||
130 | desc = fwnode_get_named_gpiod(child, "gpios"); | ||
131 | if (IS_ERR(desc)) { | ||
132 | devres_free(dr); | ||
133 | return desc; | ||
134 | } | ||
135 | |||
136 | *dr = desc; | ||
137 | devres_add(dev, dr); | ||
138 | |||
139 | return desc; | ||
140 | } | ||
141 | EXPORT_SYMBOL(devm_get_gpiod_from_child); | ||
142 | |||
143 | /** | ||
112 | * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() | 144 | * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() |
113 | * @dev: GPIO consumer | 145 | * @dev: GPIO consumer |
114 | * @con_id: function within the GPIO consumer | 146 | * @con_id: function within the GPIO consumer |
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c index 41e91d70301e..99720c8bc8ed 100644 --- a/drivers/gpio/gpio-sch.c +++ b/drivers/gpio/gpio-sch.c | |||
@@ -29,290 +29,221 @@ | |||
29 | 29 | ||
30 | #include <linux/gpio.h> | 30 | #include <linux/gpio.h> |
31 | 31 | ||
32 | static DEFINE_SPINLOCK(gpio_lock); | 32 | #define GEN 0x00 |
33 | 33 | #define GIO 0x04 | |
34 | #define CGEN (0x00) | 34 | #define GLV 0x08 |
35 | #define CGIO (0x04) | 35 | |
36 | #define CGLV (0x08) | 36 | struct sch_gpio { |
37 | 37 | struct gpio_chip chip; | |
38 | #define RGEN (0x20) | 38 | spinlock_t lock; |
39 | #define RGIO (0x24) | 39 | unsigned short iobase; |
40 | #define RGLV (0x28) | 40 | unsigned short core_base; |
41 | 41 | unsigned short resume_base; | |
42 | static unsigned short gpio_ba; | 42 | }; |
43 | |||
44 | static int sch_gpio_core_direction_in(struct gpio_chip *gc, unsigned gpio_num) | ||
45 | { | ||
46 | u8 curr_dirs; | ||
47 | unsigned short offset, bit; | ||
48 | |||
49 | spin_lock(&gpio_lock); | ||
50 | |||
51 | offset = CGIO + gpio_num / 8; | ||
52 | bit = gpio_num % 8; | ||
53 | |||
54 | curr_dirs = inb(gpio_ba + offset); | ||
55 | |||
56 | if (!(curr_dirs & (1 << bit))) | ||
57 | outb(curr_dirs | (1 << bit), gpio_ba + offset); | ||
58 | 43 | ||
59 | spin_unlock(&gpio_lock); | 44 | #define to_sch_gpio(c) container_of(c, struct sch_gpio, chip) |
60 | return 0; | ||
61 | } | ||
62 | 45 | ||
63 | static int sch_gpio_core_get(struct gpio_chip *gc, unsigned gpio_num) | 46 | static unsigned sch_gpio_offset(struct sch_gpio *sch, unsigned gpio, |
47 | unsigned reg) | ||
64 | { | 48 | { |
65 | int res; | 49 | unsigned base = 0; |
66 | unsigned short offset, bit; | ||
67 | 50 | ||
68 | offset = CGLV + gpio_num / 8; | 51 | if (gpio >= sch->resume_base) { |
69 | bit = gpio_num % 8; | 52 | gpio -= sch->resume_base; |
53 | base += 0x20; | ||
54 | } | ||
70 | 55 | ||
71 | res = !!(inb(gpio_ba + offset) & (1 << bit)); | 56 | return base + reg + gpio / 8; |
72 | return res; | ||
73 | } | 57 | } |
74 | 58 | ||
75 | static void sch_gpio_core_set(struct gpio_chip *gc, unsigned gpio_num, int val) | 59 | static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio) |
76 | { | 60 | { |
77 | u8 curr_vals; | 61 | if (gpio >= sch->resume_base) |
78 | unsigned short offset, bit; | 62 | gpio -= sch->resume_base; |
79 | 63 | return gpio % 8; | |
80 | spin_lock(&gpio_lock); | ||
81 | |||
82 | offset = CGLV + gpio_num / 8; | ||
83 | bit = gpio_num % 8; | ||
84 | |||
85 | curr_vals = inb(gpio_ba + offset); | ||
86 | |||
87 | if (val) | ||
88 | outb(curr_vals | (1 << bit), gpio_ba + offset); | ||
89 | else | ||
90 | outb((curr_vals & ~(1 << bit)), gpio_ba + offset); | ||
91 | spin_unlock(&gpio_lock); | ||
92 | } | 64 | } |
93 | 65 | ||
94 | static int sch_gpio_core_direction_out(struct gpio_chip *gc, | 66 | static void sch_gpio_enable(struct sch_gpio *sch, unsigned gpio) |
95 | unsigned gpio_num, int val) | ||
96 | { | 67 | { |
97 | u8 curr_dirs; | ||
98 | unsigned short offset, bit; | 68 | unsigned short offset, bit; |
69 | u8 enable; | ||
99 | 70 | ||
100 | spin_lock(&gpio_lock); | 71 | spin_lock(&sch->lock); |
101 | 72 | ||
102 | offset = CGIO + gpio_num / 8; | 73 | offset = sch_gpio_offset(sch, gpio, GEN); |
103 | bit = gpio_num % 8; | 74 | bit = sch_gpio_bit(sch, gpio); |
104 | |||
105 | curr_dirs = inb(gpio_ba + offset); | ||
106 | if (curr_dirs & (1 << bit)) | ||
107 | outb(curr_dirs & ~(1 << bit), gpio_ba + offset); | ||
108 | 75 | ||
109 | spin_unlock(&gpio_lock); | 76 | enable = inb(sch->iobase + offset); |
77 | if (!(enable & (1 << bit))) | ||
78 | outb(enable | (1 << bit), sch->iobase + offset); | ||
110 | 79 | ||
111 | /* | 80 | spin_unlock(&sch->lock); |
112 | * according to the datasheet, writing to the level register has no | ||
113 | * effect when GPIO is programmed as input. | ||
114 | * Actually the the level register is read-only when configured as input. | ||
115 | * Thus presetting the output level before switching to output is _NOT_ possible. | ||
116 | * Hence we set the level after configuring the GPIO as output. | ||
117 | * But we cannot prevent a short low pulse if direction is set to high | ||
118 | * and an external pull-up is connected. | ||
119 | */ | ||
120 | sch_gpio_core_set(gc, gpio_num, val); | ||
121 | return 0; | ||
122 | } | 81 | } |
123 | 82 | ||
124 | static struct gpio_chip sch_gpio_core = { | 83 | static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num) |
125 | .label = "sch_gpio_core", | ||
126 | .owner = THIS_MODULE, | ||
127 | .direction_input = sch_gpio_core_direction_in, | ||
128 | .get = sch_gpio_core_get, | ||
129 | .direction_output = sch_gpio_core_direction_out, | ||
130 | .set = sch_gpio_core_set, | ||
131 | }; | ||
132 | |||
133 | static int sch_gpio_resume_direction_in(struct gpio_chip *gc, | ||
134 | unsigned gpio_num) | ||
135 | { | 84 | { |
85 | struct sch_gpio *sch = to_sch_gpio(gc); | ||
136 | u8 curr_dirs; | 86 | u8 curr_dirs; |
137 | unsigned short offset, bit; | 87 | unsigned short offset, bit; |
138 | 88 | ||
139 | spin_lock(&gpio_lock); | 89 | spin_lock(&sch->lock); |
140 | 90 | ||
141 | offset = RGIO + gpio_num / 8; | 91 | offset = sch_gpio_offset(sch, gpio_num, GIO); |
142 | bit = gpio_num % 8; | 92 | bit = sch_gpio_bit(sch, gpio_num); |
143 | 93 | ||
144 | curr_dirs = inb(gpio_ba + offset); | 94 | curr_dirs = inb(sch->iobase + offset); |
145 | 95 | ||
146 | if (!(curr_dirs & (1 << bit))) | 96 | if (!(curr_dirs & (1 << bit))) |
147 | outb(curr_dirs | (1 << bit), gpio_ba + offset); | 97 | outb(curr_dirs | (1 << bit), sch->iobase + offset); |
148 | 98 | ||
149 | spin_unlock(&gpio_lock); | 99 | spin_unlock(&sch->lock); |
150 | return 0; | 100 | return 0; |
151 | } | 101 | } |
152 | 102 | ||
153 | static int sch_gpio_resume_get(struct gpio_chip *gc, unsigned gpio_num) | 103 | static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num) |
154 | { | 104 | { |
105 | struct sch_gpio *sch = to_sch_gpio(gc); | ||
106 | int res; | ||
155 | unsigned short offset, bit; | 107 | unsigned short offset, bit; |
156 | 108 | ||
157 | offset = RGLV + gpio_num / 8; | 109 | offset = sch_gpio_offset(sch, gpio_num, GLV); |
158 | bit = gpio_num % 8; | 110 | bit = sch_gpio_bit(sch, gpio_num); |
111 | |||
112 | res = !!(inb(sch->iobase + offset) & (1 << bit)); | ||
159 | 113 | ||
160 | return !!(inb(gpio_ba + offset) & (1 << bit)); | 114 | return res; |
161 | } | 115 | } |
162 | 116 | ||
163 | static void sch_gpio_resume_set(struct gpio_chip *gc, | 117 | static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val) |
164 | unsigned gpio_num, int val) | ||
165 | { | 118 | { |
119 | struct sch_gpio *sch = to_sch_gpio(gc); | ||
166 | u8 curr_vals; | 120 | u8 curr_vals; |
167 | unsigned short offset, bit; | 121 | unsigned short offset, bit; |
168 | 122 | ||
169 | spin_lock(&gpio_lock); | 123 | spin_lock(&sch->lock); |
170 | 124 | ||
171 | offset = RGLV + gpio_num / 8; | 125 | offset = sch_gpio_offset(sch, gpio_num, GLV); |
172 | bit = gpio_num % 8; | 126 | bit = sch_gpio_bit(sch, gpio_num); |
173 | 127 | ||
174 | curr_vals = inb(gpio_ba + offset); | 128 | curr_vals = inb(sch->iobase + offset); |
175 | 129 | ||
176 | if (val) | 130 | if (val) |
177 | outb(curr_vals | (1 << bit), gpio_ba + offset); | 131 | outb(curr_vals | (1 << bit), sch->iobase + offset); |
178 | else | 132 | else |
179 | outb((curr_vals & ~(1 << bit)), gpio_ba + offset); | 133 | outb((curr_vals & ~(1 << bit)), sch->iobase + offset); |
180 | 134 | ||
181 | spin_unlock(&gpio_lock); | 135 | spin_unlock(&sch->lock); |
182 | } | 136 | } |
183 | 137 | ||
184 | static int sch_gpio_resume_direction_out(struct gpio_chip *gc, | 138 | static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num, |
185 | unsigned gpio_num, int val) | 139 | int val) |
186 | { | 140 | { |
141 | struct sch_gpio *sch = to_sch_gpio(gc); | ||
187 | u8 curr_dirs; | 142 | u8 curr_dirs; |
188 | unsigned short offset, bit; | 143 | unsigned short offset, bit; |
189 | 144 | ||
190 | offset = RGIO + gpio_num / 8; | 145 | spin_lock(&sch->lock); |
191 | bit = gpio_num % 8; | ||
192 | 146 | ||
193 | spin_lock(&gpio_lock); | 147 | offset = sch_gpio_offset(sch, gpio_num, GIO); |
148 | bit = sch_gpio_bit(sch, gpio_num); | ||
194 | 149 | ||
195 | curr_dirs = inb(gpio_ba + offset); | 150 | curr_dirs = inb(sch->iobase + offset); |
196 | if (curr_dirs & (1 << bit)) | 151 | if (curr_dirs & (1 << bit)) |
197 | outb(curr_dirs & ~(1 << bit), gpio_ba + offset); | 152 | outb(curr_dirs & ~(1 << bit), sch->iobase + offset); |
198 | 153 | ||
199 | spin_unlock(&gpio_lock); | 154 | spin_unlock(&sch->lock); |
200 | 155 | ||
201 | /* | 156 | /* |
202 | * according to the datasheet, writing to the level register has no | 157 | * according to the datasheet, writing to the level register has no |
203 | * effect when GPIO is programmed as input. | 158 | * effect when GPIO is programmed as input. |
204 | * Actually the the level register is read-only when configured as input. | 159 | * Actually the the level register is read-only when configured as input. |
205 | * Thus presetting the output level before switching to output is _NOT_ possible. | 160 | * Thus presetting the output level before switching to output is _NOT_ possible. |
206 | * Hence we set the level after configuring the GPIO as output. | 161 | * Hence we set the level after configuring the GPIO as output. |
207 | * But we cannot prevent a short low pulse if direction is set to high | 162 | * But we cannot prevent a short low pulse if direction is set to high |
208 | * and an external pull-up is connected. | 163 | * and an external pull-up is connected. |
209 | */ | 164 | */ |
210 | sch_gpio_resume_set(gc, gpio_num, val); | 165 | sch_gpio_set(gc, gpio_num, val); |
211 | return 0; | 166 | return 0; |
212 | } | 167 | } |
213 | 168 | ||
214 | static struct gpio_chip sch_gpio_resume = { | 169 | static struct gpio_chip sch_gpio_chip = { |
215 | .label = "sch_gpio_resume", | 170 | .label = "sch_gpio", |
216 | .owner = THIS_MODULE, | 171 | .owner = THIS_MODULE, |
217 | .direction_input = sch_gpio_resume_direction_in, | 172 | .direction_input = sch_gpio_direction_in, |
218 | .get = sch_gpio_resume_get, | 173 | .get = sch_gpio_get, |
219 | .direction_output = sch_gpio_resume_direction_out, | 174 | .direction_output = sch_gpio_direction_out, |
220 | .set = sch_gpio_resume_set, | 175 | .set = sch_gpio_set, |
221 | }; | 176 | }; |
222 | 177 | ||
223 | static int sch_gpio_probe(struct platform_device *pdev) | 178 | static int sch_gpio_probe(struct platform_device *pdev) |
224 | { | 179 | { |
180 | struct sch_gpio *sch; | ||
225 | struct resource *res; | 181 | struct resource *res; |
226 | int err, id; | ||
227 | 182 | ||
228 | id = pdev->id; | 183 | sch = devm_kzalloc(&pdev->dev, sizeof(*sch), GFP_KERNEL); |
229 | if (!id) | 184 | if (!sch) |
230 | return -ENODEV; | 185 | return -ENOMEM; |
231 | 186 | ||
232 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 187 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
233 | if (!res) | 188 | if (!res) |
234 | return -EBUSY; | 189 | return -EBUSY; |
235 | 190 | ||
236 | if (!request_region(res->start, resource_size(res), pdev->name)) | 191 | if (!devm_request_region(&pdev->dev, res->start, resource_size(res), |
192 | pdev->name)) | ||
237 | return -EBUSY; | 193 | return -EBUSY; |
238 | 194 | ||
239 | gpio_ba = res->start; | 195 | spin_lock_init(&sch->lock); |
196 | sch->iobase = res->start; | ||
197 | sch->chip = sch_gpio_chip; | ||
198 | sch->chip.label = dev_name(&pdev->dev); | ||
199 | sch->chip.dev = &pdev->dev; | ||
240 | 200 | ||
241 | switch (id) { | 201 | switch (pdev->id) { |
242 | case PCI_DEVICE_ID_INTEL_SCH_LPC: | 202 | case PCI_DEVICE_ID_INTEL_SCH_LPC: |
243 | sch_gpio_core.base = 0; | 203 | sch->core_base = 0; |
244 | sch_gpio_core.ngpio = 10; | 204 | sch->resume_base = 10; |
245 | sch_gpio_resume.base = 10; | 205 | sch->chip.ngpio = 14; |
246 | sch_gpio_resume.ngpio = 4; | 206 | |
247 | /* | 207 | /* |
248 | * GPIO[6:0] enabled by default | 208 | * GPIO[6:0] enabled by default |
249 | * GPIO7 is configured by the CMC as SLPIOVR | 209 | * GPIO7 is configured by the CMC as SLPIOVR |
250 | * Enable GPIO[9:8] core powered gpios explicitly | 210 | * Enable GPIO[9:8] core powered gpios explicitly |
251 | */ | 211 | */ |
252 | outb(0x3, gpio_ba + CGEN + 1); | 212 | sch_gpio_enable(sch, 8); |
213 | sch_gpio_enable(sch, 9); | ||
253 | /* | 214 | /* |
254 | * SUS_GPIO[2:0] enabled by default | 215 | * SUS_GPIO[2:0] enabled by default |
255 | * Enable SUS_GPIO3 resume powered gpio explicitly | 216 | * Enable SUS_GPIO3 resume powered gpio explicitly |
256 | */ | 217 | */ |
257 | outb(0x8, gpio_ba + RGEN); | 218 | sch_gpio_enable(sch, 13); |
258 | break; | 219 | break; |
259 | 220 | ||
260 | case PCI_DEVICE_ID_INTEL_ITC_LPC: | 221 | case PCI_DEVICE_ID_INTEL_ITC_LPC: |
261 | sch_gpio_core.base = 0; | 222 | sch->core_base = 0; |
262 | sch_gpio_core.ngpio = 5; | 223 | sch->resume_base = 5; |
263 | sch_gpio_resume.base = 5; | 224 | sch->chip.ngpio = 14; |
264 | sch_gpio_resume.ngpio = 9; | ||
265 | break; | 225 | break; |
266 | 226 | ||
267 | case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: | 227 | case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: |
268 | sch_gpio_core.base = 0; | 228 | sch->core_base = 0; |
269 | sch_gpio_core.ngpio = 21; | 229 | sch->resume_base = 21; |
270 | sch_gpio_resume.base = 21; | 230 | sch->chip.ngpio = 30; |
271 | sch_gpio_resume.ngpio = 9; | ||
272 | break; | 231 | break; |
273 | 232 | ||
274 | default: | 233 | default: |
275 | err = -ENODEV; | 234 | return -ENODEV; |
276 | goto err_sch_gpio_core; | ||
277 | } | 235 | } |
278 | 236 | ||
279 | sch_gpio_core.dev = &pdev->dev; | 237 | platform_set_drvdata(pdev, sch); |
280 | sch_gpio_resume.dev = &pdev->dev; | ||
281 | |||
282 | err = gpiochip_add(&sch_gpio_core); | ||
283 | if (err < 0) | ||
284 | goto err_sch_gpio_core; | ||
285 | 238 | ||
286 | err = gpiochip_add(&sch_gpio_resume); | 239 | return gpiochip_add(&sch->chip); |
287 | if (err < 0) | ||
288 | goto err_sch_gpio_resume; | ||
289 | |||
290 | return 0; | ||
291 | |||
292 | err_sch_gpio_resume: | ||
293 | gpiochip_remove(&sch_gpio_core); | ||
294 | |||
295 | err_sch_gpio_core: | ||
296 | release_region(res->start, resource_size(res)); | ||
297 | gpio_ba = 0; | ||
298 | |||
299 | return err; | ||
300 | } | 240 | } |
301 | 241 | ||
302 | static int sch_gpio_remove(struct platform_device *pdev) | 242 | static int sch_gpio_remove(struct platform_device *pdev) |
303 | { | 243 | { |
304 | struct resource *res; | 244 | struct sch_gpio *sch = platform_get_drvdata(pdev); |
305 | if (gpio_ba) { | ||
306 | |||
307 | gpiochip_remove(&sch_gpio_core); | ||
308 | gpiochip_remove(&sch_gpio_resume); | ||
309 | |||
310 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
311 | |||
312 | release_region(res->start, resource_size(res)); | ||
313 | gpio_ba = 0; | ||
314 | } | ||
315 | 245 | ||
246 | gpiochip_remove(&sch->chip); | ||
316 | return 0; | 247 | return 0; |
317 | } | 248 | } |
318 | 249 | ||
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 05c6275da224..ba98bb59a58f 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c | |||
@@ -287,9 +287,45 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) | |||
287 | } | 287 | } |
288 | } | 288 | } |
289 | 289 | ||
290 | int acpi_dev_add_driver_gpios(struct acpi_device *adev, | ||
291 | const struct acpi_gpio_mapping *gpios) | ||
292 | { | ||
293 | if (adev && gpios) { | ||
294 | adev->driver_gpios = gpios; | ||
295 | return 0; | ||
296 | } | ||
297 | return -EINVAL; | ||
298 | } | ||
299 | EXPORT_SYMBOL_GPL(acpi_dev_add_driver_gpios); | ||
300 | |||
301 | static bool acpi_get_driver_gpio_data(struct acpi_device *adev, | ||
302 | const char *name, int index, | ||
303 | struct acpi_reference_args *args) | ||
304 | { | ||
305 | const struct acpi_gpio_mapping *gm; | ||
306 | |||
307 | if (!adev->driver_gpios) | ||
308 | return false; | ||
309 | |||
310 | for (gm = adev->driver_gpios; gm->name; gm++) | ||
311 | if (!strcmp(name, gm->name) && gm->data && index < gm->size) { | ||
312 | const struct acpi_gpio_params *par = gm->data + index; | ||
313 | |||
314 | args->adev = adev; | ||
315 | args->args[0] = par->crs_entry_index; | ||
316 | args->args[1] = par->line_index; | ||
317 | args->args[2] = par->active_low; | ||
318 | args->nargs = 3; | ||
319 | return true; | ||
320 | } | ||
321 | |||
322 | return false; | ||
323 | } | ||
324 | |||
290 | struct acpi_gpio_lookup { | 325 | struct acpi_gpio_lookup { |
291 | struct acpi_gpio_info info; | 326 | struct acpi_gpio_info info; |
292 | int index; | 327 | int index; |
328 | int pin_index; | ||
293 | struct gpio_desc *desc; | 329 | struct gpio_desc *desc; |
294 | int n; | 330 | int n; |
295 | }; | 331 | }; |
@@ -303,13 +339,24 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data) | |||
303 | 339 | ||
304 | if (lookup->n++ == lookup->index && !lookup->desc) { | 340 | if (lookup->n++ == lookup->index && !lookup->desc) { |
305 | const struct acpi_resource_gpio *agpio = &ares->data.gpio; | 341 | const struct acpi_resource_gpio *agpio = &ares->data.gpio; |
342 | int pin_index = lookup->pin_index; | ||
343 | |||
344 | if (pin_index >= agpio->pin_table_length) | ||
345 | return 1; | ||
306 | 346 | ||
307 | lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, | 347 | lookup->desc = acpi_get_gpiod(agpio->resource_source.string_ptr, |
308 | agpio->pin_table[0]); | 348 | agpio->pin_table[pin_index]); |
309 | lookup->info.gpioint = | 349 | lookup->info.gpioint = |
310 | agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; | 350 | agpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT; |
311 | lookup->info.active_low = | 351 | |
312 | agpio->polarity == ACPI_ACTIVE_LOW; | 352 | /* |
353 | * ActiveLow is only specified for GpioInt resource. If | ||
354 | * GpioIo is used then the only way to set the flag is | ||
355 | * to use _DSD "gpios" property. | ||
356 | */ | ||
357 | if (lookup->info.gpioint) | ||
358 | lookup->info.active_low = | ||
359 | agpio->polarity == ACPI_ACTIVE_LOW; | ||
313 | } | 360 | } |
314 | 361 | ||
315 | return 1; | 362 | return 1; |
@@ -317,40 +364,79 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data) | |||
317 | 364 | ||
318 | /** | 365 | /** |
319 | * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources | 366 | * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources |
320 | * @dev: pointer to a device to get GPIO from | 367 | * @adev: pointer to a ACPI device to get GPIO from |
368 | * @propname: Property name of the GPIO (optional) | ||
321 | * @index: index of GpioIo/GpioInt resource (starting from %0) | 369 | * @index: index of GpioIo/GpioInt resource (starting from %0) |
322 | * @info: info pointer to fill in (optional) | 370 | * @info: info pointer to fill in (optional) |
323 | * | 371 | * |
324 | * Function goes through ACPI resources for @dev and based on @index looks | 372 | * Function goes through ACPI resources for @adev and based on @index looks |
325 | * up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor, | 373 | * up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor, |
326 | * and returns it. @index matches GpioIo/GpioInt resources only so if there | 374 | * and returns it. @index matches GpioIo/GpioInt resources only so if there |
327 | * are total %3 GPIO resources, the index goes from %0 to %2. | 375 | * are total %3 GPIO resources, the index goes from %0 to %2. |
328 | * | 376 | * |
377 | * If @propname is specified the GPIO is looked using device property. In | ||
378 | * that case @index is used to select the GPIO entry in the property value | ||
379 | * (in case of multiple). | ||
380 | * | ||
329 | * If the GPIO cannot be translated or there is an error an ERR_PTR is | 381 | * If the GPIO cannot be translated or there is an error an ERR_PTR is |
330 | * returned. | 382 | * returned. |
331 | * | 383 | * |
332 | * Note: if the GPIO resource has multiple entries in the pin list, this | 384 | * Note: if the GPIO resource has multiple entries in the pin list, this |
333 | * function only returns the first. | 385 | * function only returns the first. |
334 | */ | 386 | */ |
335 | struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, | 387 | struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev, |
388 | const char *propname, int index, | ||
336 | struct acpi_gpio_info *info) | 389 | struct acpi_gpio_info *info) |
337 | { | 390 | { |
338 | struct acpi_gpio_lookup lookup; | 391 | struct acpi_gpio_lookup lookup; |
339 | struct list_head resource_list; | 392 | struct list_head resource_list; |
340 | struct acpi_device *adev; | 393 | bool active_low = false; |
341 | acpi_handle handle; | ||
342 | int ret; | 394 | int ret; |
343 | 395 | ||
344 | if (!dev) | 396 | if (!adev) |
345 | return ERR_PTR(-EINVAL); | ||
346 | |||
347 | handle = ACPI_HANDLE(dev); | ||
348 | if (!handle || acpi_bus_get_device(handle, &adev)) | ||
349 | return ERR_PTR(-ENODEV); | 397 | return ERR_PTR(-ENODEV); |
350 | 398 | ||
351 | memset(&lookup, 0, sizeof(lookup)); | 399 | memset(&lookup, 0, sizeof(lookup)); |
352 | lookup.index = index; | 400 | lookup.index = index; |
353 | 401 | ||
402 | if (propname) { | ||
403 | struct acpi_reference_args args; | ||
404 | |||
405 | dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname); | ||
406 | |||
407 | memset(&args, 0, sizeof(args)); | ||
408 | ret = acpi_dev_get_property_reference(adev, propname, | ||
409 | index, &args); | ||
410 | if (ret) { | ||
411 | bool found = acpi_get_driver_gpio_data(adev, propname, | ||
412 | index, &args); | ||
413 | if (!found) | ||
414 | return ERR_PTR(ret); | ||
415 | } | ||
416 | |||
417 | /* | ||
418 | * The property was found and resolved so need to | ||
419 | * lookup the GPIO based on returned args instead. | ||
420 | */ | ||
421 | adev = args.adev; | ||
422 | if (args.nargs >= 2) { | ||
423 | lookup.index = args.args[0]; | ||
424 | lookup.pin_index = args.args[1]; | ||
425 | /* | ||
426 | * 3rd argument, if present is used to | ||
427 | * specify active_low. | ||
428 | */ | ||
429 | if (args.nargs >= 3) | ||
430 | active_low = !!args.args[2]; | ||
431 | } | ||
432 | |||
433 | dev_dbg(&adev->dev, "GPIO: _DSD returned %s %zd %llu %llu %llu\n", | ||
434 | dev_name(&adev->dev), args.nargs, | ||
435 | args.args[0], args.args[1], args.args[2]); | ||
436 | } else { | ||
437 | dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index); | ||
438 | } | ||
439 | |||
354 | INIT_LIST_HEAD(&resource_list); | 440 | INIT_LIST_HEAD(&resource_list); |
355 | ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, | 441 | ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, |
356 | &lookup); | 442 | &lookup); |
@@ -359,8 +445,11 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, | |||
359 | 445 | ||
360 | acpi_dev_free_resource_list(&resource_list); | 446 | acpi_dev_free_resource_list(&resource_list); |
361 | 447 | ||
362 | if (lookup.desc && info) | 448 | if (lookup.desc && info) { |
363 | *info = lookup.info; | 449 | *info = lookup.info; |
450 | if (active_low) | ||
451 | info->active_low = active_low; | ||
452 | } | ||
364 | 453 | ||
365 | return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT); | 454 | return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT); |
366 | } | 455 | } |
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e8e98ca25ec7..58659dbe702a 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -1505,14 +1505,36 @@ static struct gpio_desc *acpi_find_gpio(struct device *dev, const char *con_id, | |||
1505 | unsigned int idx, | 1505 | unsigned int idx, |
1506 | enum gpio_lookup_flags *flags) | 1506 | enum gpio_lookup_flags *flags) |
1507 | { | 1507 | { |
1508 | static const char * const suffixes[] = { "gpios", "gpio" }; | ||
1509 | struct acpi_device *adev = ACPI_COMPANION(dev); | ||
1508 | struct acpi_gpio_info info; | 1510 | struct acpi_gpio_info info; |
1509 | struct gpio_desc *desc; | 1511 | struct gpio_desc *desc; |
1512 | char propname[32]; | ||
1513 | int i; | ||
1510 | 1514 | ||
1511 | desc = acpi_get_gpiod_by_index(dev, idx, &info); | 1515 | /* Try first from _DSD */ |
1512 | if (IS_ERR(desc)) | 1516 | for (i = 0; i < ARRAY_SIZE(suffixes); i++) { |
1513 | return desc; | 1517 | if (con_id && strcmp(con_id, "gpios")) { |
1518 | snprintf(propname, sizeof(propname), "%s-%s", | ||
1519 | con_id, suffixes[i]); | ||
1520 | } else { | ||
1521 | snprintf(propname, sizeof(propname), "%s", | ||
1522 | suffixes[i]); | ||
1523 | } | ||
1524 | |||
1525 | desc = acpi_get_gpiod_by_index(adev, propname, idx, &info); | ||
1526 | if (!IS_ERR(desc) || (PTR_ERR(desc) == -EPROBE_DEFER)) | ||
1527 | break; | ||
1528 | } | ||
1514 | 1529 | ||
1515 | if (info.gpioint && info.active_low) | 1530 | /* Then from plain _CRS GPIOs */ |
1531 | if (IS_ERR(desc)) { | ||
1532 | desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info); | ||
1533 | if (IS_ERR(desc)) | ||
1534 | return desc; | ||
1535 | } | ||
1536 | |||
1537 | if (info.active_low) | ||
1516 | *flags |= GPIO_ACTIVE_LOW; | 1538 | *flags |= GPIO_ACTIVE_LOW; |
1517 | 1539 | ||
1518 | return desc; | 1540 | return desc; |
@@ -1713,6 +1735,61 @@ struct gpio_desc *__must_check __gpiod_get_index(struct device *dev, | |||
1713 | EXPORT_SYMBOL_GPL(__gpiod_get_index); | 1735 | EXPORT_SYMBOL_GPL(__gpiod_get_index); |
1714 | 1736 | ||
1715 | /** | 1737 | /** |
1738 | * fwnode_get_named_gpiod - obtain a GPIO from firmware node | ||
1739 | * @fwnode: handle of the firmware node | ||
1740 | * @propname: name of the firmware property representing the GPIO | ||
1741 | * | ||
1742 | * This function can be used for drivers that get their configuration | ||
1743 | * from firmware. | ||
1744 | * | ||
1745 | * Function properly finds the corresponding GPIO using whatever is the | ||
1746 | * underlying firmware interface and then makes sure that the GPIO | ||
1747 | * descriptor is requested before it is returned to the caller. | ||
1748 | * | ||
1749 | * In case of error an ERR_PTR() is returned. | ||
1750 | */ | ||
1751 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | ||
1752 | const char *propname) | ||
1753 | { | ||
1754 | struct gpio_desc *desc = ERR_PTR(-ENODEV); | ||
1755 | bool active_low = false; | ||
1756 | int ret; | ||
1757 | |||
1758 | if (!fwnode) | ||
1759 | return ERR_PTR(-EINVAL); | ||
1760 | |||
1761 | if (is_of_node(fwnode)) { | ||
1762 | enum of_gpio_flags flags; | ||
1763 | |||
1764 | desc = of_get_named_gpiod_flags(of_node(fwnode), propname, 0, | ||
1765 | &flags); | ||
1766 | if (!IS_ERR(desc)) | ||
1767 | active_low = flags & OF_GPIO_ACTIVE_LOW; | ||
1768 | } else if (is_acpi_node(fwnode)) { | ||
1769 | struct acpi_gpio_info info; | ||
1770 | |||
1771 | desc = acpi_get_gpiod_by_index(acpi_node(fwnode), propname, 0, | ||
1772 | &info); | ||
1773 | if (!IS_ERR(desc)) | ||
1774 | active_low = info.active_low; | ||
1775 | } | ||
1776 | |||
1777 | if (IS_ERR(desc)) | ||
1778 | return desc; | ||
1779 | |||
1780 | ret = gpiod_request(desc, NULL); | ||
1781 | if (ret) | ||
1782 | return ERR_PTR(ret); | ||
1783 | |||
1784 | /* Only value flag can be set from both DT and ACPI is active_low */ | ||
1785 | if (active_low) | ||
1786 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); | ||
1787 | |||
1788 | return desc; | ||
1789 | } | ||
1790 | EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod); | ||
1791 | |||
1792 | /** | ||
1716 | * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO | 1793 | * gpiod_get_index_optional - obtain an optional GPIO from a multi-index GPIO |
1717 | * function | 1794 | * function |
1718 | * @dev: GPIO consumer, can be NULL for system-global GPIOs | 1795 | * @dev: GPIO consumer, can be NULL for system-global GPIOs |
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 9db2b6a71c5d..e3a52113a541 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h | |||
@@ -34,7 +34,8 @@ void acpi_gpiochip_remove(struct gpio_chip *chip); | |||
34 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); | 34 | void acpi_gpiochip_request_interrupts(struct gpio_chip *chip); |
35 | void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); | 35 | void acpi_gpiochip_free_interrupts(struct gpio_chip *chip); |
36 | 36 | ||
37 | struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index, | 37 | struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev, |
38 | const char *propname, int index, | ||
38 | struct acpi_gpio_info *info); | 39 | struct acpi_gpio_info *info); |
39 | #else | 40 | #else |
40 | static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } | 41 | static inline void acpi_gpiochip_add(struct gpio_chip *chip) { } |
@@ -47,8 +48,8 @@ static inline void | |||
47 | acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } | 48 | acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { } |
48 | 49 | ||
49 | static inline struct gpio_desc * | 50 | static inline struct gpio_desc * |
50 | acpi_get_gpiod_by_index(struct device *dev, int index, | 51 | acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname, |
51 | struct acpi_gpio_info *info) | 52 | int index, struct acpi_gpio_info *info) |
52 | { | 53 | { |
53 | return ERR_PTR(-ENOSYS); | 54 | return ERR_PTR(-ENOSYS); |
54 | } | 55 | } |
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 432d36395f35..c9c1c8ca7267 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c | |||
@@ -23,10 +23,9 @@ | |||
23 | #include <linux/ioport.h> | 23 | #include <linux/ioport.h> |
24 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
26 | #include <linux/gpio/consumer.h> | ||
26 | #include <linux/gpio_keys.h> | 27 | #include <linux/gpio_keys.h> |
27 | #include <linux/of.h> | 28 | #include <linux/property.h> |
28 | #include <linux/of_platform.h> | ||
29 | #include <linux/of_gpio.h> | ||
30 | 29 | ||
31 | #define DRV_NAME "gpio-keys-polled" | 30 | #define DRV_NAME "gpio-keys-polled" |
32 | 31 | ||
@@ -51,15 +50,14 @@ static void gpio_keys_polled_check_state(struct input_dev *input, | |||
51 | int state; | 50 | int state; |
52 | 51 | ||
53 | if (bdata->can_sleep) | 52 | if (bdata->can_sleep) |
54 | state = !!gpio_get_value_cansleep(button->gpio); | 53 | state = !!gpiod_get_value_cansleep(button->gpiod); |
55 | else | 54 | else |
56 | state = !!gpio_get_value(button->gpio); | 55 | state = !!gpiod_get_value(button->gpiod); |
57 | 56 | ||
58 | if (state != bdata->last_state) { | 57 | if (state != bdata->last_state) { |
59 | unsigned int type = button->type ?: EV_KEY; | 58 | unsigned int type = button->type ?: EV_KEY; |
60 | 59 | ||
61 | input_event(input, type, button->code, | 60 | input_event(input, type, button->code, state); |
62 | !!(state ^ button->active_low)); | ||
63 | input_sync(input); | 61 | input_sync(input); |
64 | bdata->count = 0; | 62 | bdata->count = 0; |
65 | bdata->last_state = state; | 63 | bdata->last_state = state; |
@@ -102,21 +100,15 @@ static void gpio_keys_polled_close(struct input_polled_dev *dev) | |||
102 | pdata->disable(bdev->dev); | 100 | pdata->disable(bdev->dev); |
103 | } | 101 | } |
104 | 102 | ||
105 | #ifdef CONFIG_OF | ||
106 | static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev) | 103 | static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct device *dev) |
107 | { | 104 | { |
108 | struct device_node *node, *pp; | ||
109 | struct gpio_keys_platform_data *pdata; | 105 | struct gpio_keys_platform_data *pdata; |
110 | struct gpio_keys_button *button; | 106 | struct gpio_keys_button *button; |
107 | struct fwnode_handle *child; | ||
111 | int error; | 108 | int error; |
112 | int nbuttons; | 109 | int nbuttons; |
113 | int i; | ||
114 | |||
115 | node = dev->of_node; | ||
116 | if (!node) | ||
117 | return NULL; | ||
118 | 110 | ||
119 | nbuttons = of_get_child_count(node); | 111 | nbuttons = device_get_child_node_count(dev); |
120 | if (nbuttons == 0) | 112 | if (nbuttons == 0) |
121 | return NULL; | 113 | return NULL; |
122 | 114 | ||
@@ -126,52 +118,44 @@ static struct gpio_keys_platform_data *gpio_keys_polled_get_devtree_pdata(struct | |||
126 | return ERR_PTR(-ENOMEM); | 118 | return ERR_PTR(-ENOMEM); |
127 | 119 | ||
128 | pdata->buttons = (struct gpio_keys_button *)(pdata + 1); | 120 | pdata->buttons = (struct gpio_keys_button *)(pdata + 1); |
129 | pdata->nbuttons = nbuttons; | ||
130 | 121 | ||
131 | pdata->rep = !!of_get_property(node, "autorepeat", NULL); | 122 | pdata->rep = device_property_present(dev, "autorepeat"); |
132 | of_property_read_u32(node, "poll-interval", &pdata->poll_interval); | 123 | device_property_read_u32(dev, "poll-interval", &pdata->poll_interval); |
133 | 124 | ||
134 | i = 0; | 125 | device_for_each_child_node(dev, child) { |
135 | for_each_child_of_node(node, pp) { | 126 | struct gpio_desc *desc; |
136 | int gpio; | ||
137 | enum of_gpio_flags flags; | ||
138 | 127 | ||
139 | if (!of_find_property(pp, "gpios", NULL)) { | 128 | desc = devm_get_gpiod_from_child(dev, child); |
140 | pdata->nbuttons--; | 129 | if (IS_ERR(desc)) { |
141 | dev_warn(dev, "Found button without gpios\n"); | 130 | error = PTR_ERR(desc); |
142 | continue; | ||
143 | } | ||
144 | |||
145 | gpio = of_get_gpio_flags(pp, 0, &flags); | ||
146 | if (gpio < 0) { | ||
147 | error = gpio; | ||
148 | if (error != -EPROBE_DEFER) | 131 | if (error != -EPROBE_DEFER) |
149 | dev_err(dev, | 132 | dev_err(dev, |
150 | "Failed to get gpio flags, error: %d\n", | 133 | "Failed to get gpio flags, error: %d\n", |
151 | error); | 134 | error); |
135 | fwnode_handle_put(child); | ||
152 | return ERR_PTR(error); | 136 | return ERR_PTR(error); |
153 | } | 137 | } |
154 | 138 | ||
155 | button = &pdata->buttons[i++]; | 139 | button = &pdata->buttons[pdata->nbuttons++]; |
156 | 140 | button->gpiod = desc; | |
157 | button->gpio = gpio; | ||
158 | button->active_low = flags & OF_GPIO_ACTIVE_LOW; | ||
159 | 141 | ||
160 | if (of_property_read_u32(pp, "linux,code", &button->code)) { | 142 | if (fwnode_property_read_u32(child, "linux,code", &button->code)) { |
161 | dev_err(dev, "Button without keycode: 0x%x\n", | 143 | dev_err(dev, "Button without keycode: %d\n", |
162 | button->gpio); | 144 | pdata->nbuttons - 1); |
145 | fwnode_handle_put(child); | ||
163 | return ERR_PTR(-EINVAL); | 146 | return ERR_PTR(-EINVAL); |
164 | } | 147 | } |
165 | 148 | ||
166 | button->desc = of_get_property(pp, "label", NULL); | 149 | fwnode_property_read_string(child, "label", &button->desc); |
167 | 150 | ||
168 | if (of_property_read_u32(pp, "linux,input-type", &button->type)) | 151 | if (fwnode_property_read_u32(child, "linux,input-type", |
152 | &button->type)) | ||
169 | button->type = EV_KEY; | 153 | button->type = EV_KEY; |
170 | 154 | ||
171 | button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL); | 155 | button->wakeup = fwnode_property_present(child, "gpio-key,wakeup"); |
172 | 156 | ||
173 | if (of_property_read_u32(pp, "debounce-interval", | 157 | if (fwnode_property_read_u32(child, "debounce-interval", |
174 | &button->debounce_interval)) | 158 | &button->debounce_interval)) |
175 | button->debounce_interval = 5; | 159 | button->debounce_interval = 5; |
176 | } | 160 | } |
177 | 161 | ||
@@ -187,15 +171,6 @@ static const struct of_device_id gpio_keys_polled_of_match[] = { | |||
187 | }; | 171 | }; |
188 | MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); | 172 | MODULE_DEVICE_TABLE(of, gpio_keys_polled_of_match); |
189 | 173 | ||
190 | #else | ||
191 | |||
192 | static inline struct gpio_keys_platform_data * | ||
193 | gpio_keys_polled_get_devtree_pdata(struct device *dev) | ||
194 | { | ||
195 | return NULL; | ||
196 | } | ||
197 | #endif | ||
198 | |||
199 | static int gpio_keys_polled_probe(struct platform_device *pdev) | 174 | static int gpio_keys_polled_probe(struct platform_device *pdev) |
200 | { | 175 | { |
201 | struct device *dev = &pdev->dev; | 176 | struct device *dev = &pdev->dev; |
@@ -259,7 +234,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) | |||
259 | for (i = 0; i < pdata->nbuttons; i++) { | 234 | for (i = 0; i < pdata->nbuttons; i++) { |
260 | struct gpio_keys_button *button = &pdata->buttons[i]; | 235 | struct gpio_keys_button *button = &pdata->buttons[i]; |
261 | struct gpio_keys_button_data *bdata = &bdev->data[i]; | 236 | struct gpio_keys_button_data *bdata = &bdev->data[i]; |
262 | unsigned int gpio = button->gpio; | ||
263 | unsigned int type = button->type ?: EV_KEY; | 237 | unsigned int type = button->type ?: EV_KEY; |
264 | 238 | ||
265 | if (button->wakeup) { | 239 | if (button->wakeup) { |
@@ -267,15 +241,31 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) | |||
267 | return -EINVAL; | 241 | return -EINVAL; |
268 | } | 242 | } |
269 | 243 | ||
270 | error = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_IN, | 244 | /* |
271 | button->desc ? : DRV_NAME); | 245 | * Legacy GPIO number so request the GPIO here and |
272 | if (error) { | 246 | * convert it to descriptor. |
273 | dev_err(dev, "unable to claim gpio %u, err=%d\n", | 247 | */ |
274 | gpio, error); | 248 | if (!button->gpiod && gpio_is_valid(button->gpio)) { |
275 | return error; | 249 | unsigned flags = 0; |
250 | |||
251 | if (button->active_low) | ||
252 | flags |= GPIOF_ACTIVE_LOW; | ||
253 | |||
254 | error = devm_gpio_request_one(&pdev->dev, button->gpio, | ||
255 | flags, button->desc ? : DRV_NAME); | ||
256 | if (error) { | ||
257 | dev_err(dev, "unable to claim gpio %u, err=%d\n", | ||
258 | button->gpio, error); | ||
259 | return error; | ||
260 | } | ||
261 | |||
262 | button->gpiod = gpio_to_desc(button->gpio); | ||
276 | } | 263 | } |
277 | 264 | ||
278 | bdata->can_sleep = gpio_cansleep(gpio); | 265 | if (IS_ERR(button->gpiod)) |
266 | return PTR_ERR(button->gpiod); | ||
267 | |||
268 | bdata->can_sleep = gpiod_cansleep(button->gpiod); | ||
279 | bdata->last_state = -1; | 269 | bdata->last_state = -1; |
280 | bdata->threshold = DIV_ROUND_UP(button->debounce_interval, | 270 | bdata->threshold = DIV_ROUND_UP(button->debounce_interval, |
281 | pdata->poll_interval); | 271 | pdata->poll_interval); |
@@ -308,7 +298,7 @@ static struct platform_driver gpio_keys_polled_driver = { | |||
308 | .driver = { | 298 | .driver = { |
309 | .name = DRV_NAME, | 299 | .name = DRV_NAME, |
310 | .owner = THIS_MODULE, | 300 | .owner = THIS_MODULE, |
311 | .of_match_table = of_match_ptr(gpio_keys_polled_of_match), | 301 | .of_match_table = gpio_keys_polled_of_match, |
312 | }, | 302 | }, |
313 | }; | 303 | }; |
314 | module_platform_driver(gpio_keys_polled_driver); | 304 | module_platform_driver(gpio_keys_polled_driver); |
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c index b4518c8751c8..868e6fc17cba 100644 --- a/drivers/leds/leds-gpio.c +++ b/drivers/leds/leds-gpio.c | |||
@@ -12,25 +12,23 @@ | |||
12 | */ | 12 | */ |
13 | #include <linux/err.h> | 13 | #include <linux/err.h> |
14 | #include <linux/gpio.h> | 14 | #include <linux/gpio.h> |
15 | #include <linux/gpio/consumer.h> | ||
15 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
16 | #include <linux/leds.h> | 17 | #include <linux/leds.h> |
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
18 | #include <linux/of.h> | ||
19 | #include <linux/of_gpio.h> | ||
20 | #include <linux/of_platform.h> | ||
21 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
20 | #include <linux/property.h> | ||
22 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
23 | #include <linux/workqueue.h> | 22 | #include <linux/workqueue.h> |
24 | 23 | ||
25 | struct gpio_led_data { | 24 | struct gpio_led_data { |
26 | struct led_classdev cdev; | 25 | struct led_classdev cdev; |
27 | unsigned gpio; | 26 | struct gpio_desc *gpiod; |
28 | struct work_struct work; | 27 | struct work_struct work; |
29 | u8 new_level; | 28 | u8 new_level; |
30 | u8 can_sleep; | 29 | u8 can_sleep; |
31 | u8 active_low; | ||
32 | u8 blinking; | 30 | u8 blinking; |
33 | int (*platform_gpio_blink_set)(unsigned gpio, int state, | 31 | int (*platform_gpio_blink_set)(struct gpio_desc *desc, int state, |
34 | unsigned long *delay_on, unsigned long *delay_off); | 32 | unsigned long *delay_on, unsigned long *delay_off); |
35 | }; | 33 | }; |
36 | 34 | ||
@@ -40,12 +38,11 @@ static void gpio_led_work(struct work_struct *work) | |||
40 | container_of(work, struct gpio_led_data, work); | 38 | container_of(work, struct gpio_led_data, work); |
41 | 39 | ||
42 | if (led_dat->blinking) { | 40 | if (led_dat->blinking) { |
43 | led_dat->platform_gpio_blink_set(led_dat->gpio, | 41 | led_dat->platform_gpio_blink_set(led_dat->gpiod, |
44 | led_dat->new_level, | 42 | led_dat->new_level, NULL, NULL); |
45 | NULL, NULL); | ||
46 | led_dat->blinking = 0; | 43 | led_dat->blinking = 0; |
47 | } else | 44 | } else |
48 | gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level); | 45 | gpiod_set_value_cansleep(led_dat->gpiod, led_dat->new_level); |
49 | } | 46 | } |
50 | 47 | ||
51 | static void gpio_led_set(struct led_classdev *led_cdev, | 48 | static void gpio_led_set(struct led_classdev *led_cdev, |
@@ -60,9 +57,6 @@ static void gpio_led_set(struct led_classdev *led_cdev, | |||
60 | else | 57 | else |
61 | level = 1; | 58 | level = 1; |
62 | 59 | ||
63 | if (led_dat->active_low) | ||
64 | level = !level; | ||
65 | |||
66 | /* Setting GPIOs with I2C/etc requires a task context, and we don't | 60 | /* Setting GPIOs with I2C/etc requires a task context, and we don't |
67 | * seem to have a reliable way to know if we're already in one; so | 61 | * seem to have a reliable way to know if we're already in one; so |
68 | * let's just assume the worst. | 62 | * let's just assume the worst. |
@@ -72,11 +66,11 @@ static void gpio_led_set(struct led_classdev *led_cdev, | |||
72 | schedule_work(&led_dat->work); | 66 | schedule_work(&led_dat->work); |
73 | } else { | 67 | } else { |
74 | if (led_dat->blinking) { | 68 | if (led_dat->blinking) { |
75 | led_dat->platform_gpio_blink_set(led_dat->gpio, level, | 69 | led_dat->platform_gpio_blink_set(led_dat->gpiod, level, |
76 | NULL, NULL); | 70 | NULL, NULL); |
77 | led_dat->blinking = 0; | 71 | led_dat->blinking = 0; |
78 | } else | 72 | } else |
79 | gpio_set_value(led_dat->gpio, level); | 73 | gpiod_set_value(led_dat->gpiod, level); |
80 | } | 74 | } |
81 | } | 75 | } |
82 | 76 | ||
@@ -87,34 +81,49 @@ static int gpio_blink_set(struct led_classdev *led_cdev, | |||
87 | container_of(led_cdev, struct gpio_led_data, cdev); | 81 | container_of(led_cdev, struct gpio_led_data, cdev); |
88 | 82 | ||
89 | led_dat->blinking = 1; | 83 | led_dat->blinking = 1; |
90 | return led_dat->platform_gpio_blink_set(led_dat->gpio, GPIO_LED_BLINK, | 84 | return led_dat->platform_gpio_blink_set(led_dat->gpiod, GPIO_LED_BLINK, |
91 | delay_on, delay_off); | 85 | delay_on, delay_off); |
92 | } | 86 | } |
93 | 87 | ||
94 | static int create_gpio_led(const struct gpio_led *template, | 88 | static int create_gpio_led(const struct gpio_led *template, |
95 | struct gpio_led_data *led_dat, struct device *parent, | 89 | struct gpio_led_data *led_dat, struct device *parent, |
96 | int (*blink_set)(unsigned, int, unsigned long *, unsigned long *)) | 90 | int (*blink_set)(struct gpio_desc *, int, unsigned long *, |
91 | unsigned long *)) | ||
97 | { | 92 | { |
98 | int ret, state; | 93 | int ret, state; |
99 | 94 | ||
100 | led_dat->gpio = -1; | 95 | led_dat->gpiod = template->gpiod; |
96 | if (!led_dat->gpiod) { | ||
97 | /* | ||
98 | * This is the legacy code path for platform code that | ||
99 | * still uses GPIO numbers. Ultimately we would like to get | ||
100 | * rid of this block completely. | ||
101 | */ | ||
102 | unsigned long flags = 0; | ||
103 | |||
104 | /* skip leds that aren't available */ | ||
105 | if (!gpio_is_valid(template->gpio)) { | ||
106 | dev_info(parent, "Skipping unavailable LED gpio %d (%s)\n", | ||
107 | template->gpio, template->name); | ||
108 | return 0; | ||
109 | } | ||
101 | 110 | ||
102 | /* skip leds that aren't available */ | 111 | if (template->active_low) |
103 | if (!gpio_is_valid(template->gpio)) { | 112 | flags |= GPIOF_ACTIVE_LOW; |
104 | dev_info(parent, "Skipping unavailable LED gpio %d (%s)\n", | ||
105 | template->gpio, template->name); | ||
106 | return 0; | ||
107 | } | ||
108 | 113 | ||
109 | ret = devm_gpio_request(parent, template->gpio, template->name); | 114 | ret = devm_gpio_request_one(parent, template->gpio, flags, |
110 | if (ret < 0) | 115 | template->name); |
111 | return ret; | 116 | if (ret < 0) |
117 | return ret; | ||
118 | |||
119 | led_dat->gpiod = gpio_to_desc(template->gpio); | ||
120 | if (IS_ERR(led_dat->gpiod)) | ||
121 | return PTR_ERR(led_dat->gpiod); | ||
122 | } | ||
112 | 123 | ||
113 | led_dat->cdev.name = template->name; | 124 | led_dat->cdev.name = template->name; |
114 | led_dat->cdev.default_trigger = template->default_trigger; | 125 | led_dat->cdev.default_trigger = template->default_trigger; |
115 | led_dat->gpio = template->gpio; | 126 | led_dat->can_sleep = gpiod_cansleep(led_dat->gpiod); |
116 | led_dat->can_sleep = gpio_cansleep(template->gpio); | ||
117 | led_dat->active_low = template->active_low; | ||
118 | led_dat->blinking = 0; | 127 | led_dat->blinking = 0; |
119 | if (blink_set) { | 128 | if (blink_set) { |
120 | led_dat->platform_gpio_blink_set = blink_set; | 129 | led_dat->platform_gpio_blink_set = blink_set; |
@@ -122,30 +131,24 @@ static int create_gpio_led(const struct gpio_led *template, | |||
122 | } | 131 | } |
123 | led_dat->cdev.brightness_set = gpio_led_set; | 132 | led_dat->cdev.brightness_set = gpio_led_set; |
124 | if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) | 133 | if (template->default_state == LEDS_GPIO_DEFSTATE_KEEP) |
125 | state = !!gpio_get_value_cansleep(led_dat->gpio) ^ led_dat->active_low; | 134 | state = !!gpiod_get_value_cansleep(led_dat->gpiod); |
126 | else | 135 | else |
127 | state = (template->default_state == LEDS_GPIO_DEFSTATE_ON); | 136 | state = (template->default_state == LEDS_GPIO_DEFSTATE_ON); |
128 | led_dat->cdev.brightness = state ? LED_FULL : LED_OFF; | 137 | led_dat->cdev.brightness = state ? LED_FULL : LED_OFF; |
129 | if (!template->retain_state_suspended) | 138 | if (!template->retain_state_suspended) |
130 | led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; | 139 | led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; |
131 | 140 | ||
132 | ret = gpio_direction_output(led_dat->gpio, led_dat->active_low ^ state); | 141 | ret = gpiod_direction_output(led_dat->gpiod, state); |
133 | if (ret < 0) | 142 | if (ret < 0) |
134 | return ret; | 143 | return ret; |
135 | 144 | ||
136 | INIT_WORK(&led_dat->work, gpio_led_work); | 145 | INIT_WORK(&led_dat->work, gpio_led_work); |
137 | 146 | ||
138 | ret = led_classdev_register(parent, &led_dat->cdev); | 147 | return led_classdev_register(parent, &led_dat->cdev); |
139 | if (ret < 0) | ||
140 | return ret; | ||
141 | |||
142 | return 0; | ||
143 | } | 148 | } |
144 | 149 | ||
145 | static void delete_gpio_led(struct gpio_led_data *led) | 150 | static void delete_gpio_led(struct gpio_led_data *led) |
146 | { | 151 | { |
147 | if (!gpio_is_valid(led->gpio)) | ||
148 | return; | ||
149 | led_classdev_unregister(&led->cdev); | 152 | led_classdev_unregister(&led->cdev); |
150 | cancel_work_sync(&led->work); | 153 | cancel_work_sync(&led->work); |
151 | } | 154 | } |
@@ -161,40 +164,47 @@ static inline int sizeof_gpio_leds_priv(int num_leds) | |||
161 | (sizeof(struct gpio_led_data) * num_leds); | 164 | (sizeof(struct gpio_led_data) * num_leds); |
162 | } | 165 | } |
163 | 166 | ||
164 | /* Code to create from OpenFirmware platform devices */ | 167 | static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) |
165 | #ifdef CONFIG_OF_GPIO | ||
166 | static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) | ||
167 | { | 168 | { |
168 | struct device_node *np = pdev->dev.of_node, *child; | 169 | struct device *dev = &pdev->dev; |
170 | struct fwnode_handle *child; | ||
169 | struct gpio_leds_priv *priv; | 171 | struct gpio_leds_priv *priv; |
170 | int count, ret; | 172 | int count, ret; |
173 | struct device_node *np; | ||
171 | 174 | ||
172 | /* count LEDs in this device, so we know how much to allocate */ | 175 | count = device_get_child_node_count(dev); |
173 | count = of_get_available_child_count(np); | ||
174 | if (!count) | 176 | if (!count) |
175 | return ERR_PTR(-ENODEV); | 177 | return ERR_PTR(-ENODEV); |
176 | 178 | ||
177 | for_each_available_child_of_node(np, child) | 179 | priv = devm_kzalloc(dev, sizeof_gpio_leds_priv(count), GFP_KERNEL); |
178 | if (of_get_gpio(child, 0) == -EPROBE_DEFER) | ||
179 | return ERR_PTR(-EPROBE_DEFER); | ||
180 | |||
181 | priv = devm_kzalloc(&pdev->dev, sizeof_gpio_leds_priv(count), | ||
182 | GFP_KERNEL); | ||
183 | if (!priv) | 180 | if (!priv) |
184 | return ERR_PTR(-ENOMEM); | 181 | return ERR_PTR(-ENOMEM); |
185 | 182 | ||
186 | for_each_available_child_of_node(np, child) { | 183 | device_for_each_child_node(dev, child) { |
187 | struct gpio_led led = {}; | 184 | struct gpio_led led = {}; |
188 | enum of_gpio_flags flags; | 185 | const char *state = NULL; |
189 | const char *state; | 186 | |
190 | 187 | led.gpiod = devm_get_gpiod_from_child(dev, child); | |
191 | led.gpio = of_get_gpio_flags(child, 0, &flags); | 188 | if (IS_ERR(led.gpiod)) { |
192 | led.active_low = flags & OF_GPIO_ACTIVE_LOW; | 189 | fwnode_handle_put(child); |
193 | led.name = of_get_property(child, "label", NULL) ? : child->name; | 190 | goto err; |
194 | led.default_trigger = | 191 | } |
195 | of_get_property(child, "linux,default-trigger", NULL); | 192 | |
196 | state = of_get_property(child, "default-state", NULL); | 193 | np = of_node(child); |
197 | if (state) { | 194 | |
195 | if (fwnode_property_present(child, "label")) { | ||
196 | fwnode_property_read_string(child, "label", &led.name); | ||
197 | } else { | ||
198 | if (IS_ENABLED(CONFIG_OF) && !led.name && np) | ||
199 | led.name = np->name; | ||
200 | if (!led.name) | ||
201 | return ERR_PTR(-EINVAL); | ||
202 | } | ||
203 | fwnode_property_read_string(child, "linux,default-trigger", | ||
204 | &led.default_trigger); | ||
205 | |||
206 | if (!fwnode_property_read_string(child, "linux,default_state", | ||
207 | &state)) { | ||
198 | if (!strcmp(state, "keep")) | 208 | if (!strcmp(state, "keep")) |
199 | led.default_state = LEDS_GPIO_DEFSTATE_KEEP; | 209 | led.default_state = LEDS_GPIO_DEFSTATE_KEEP; |
200 | else if (!strcmp(state, "on")) | 210 | else if (!strcmp(state, "on")) |
@@ -203,13 +213,13 @@ static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) | |||
203 | led.default_state = LEDS_GPIO_DEFSTATE_OFF; | 213 | led.default_state = LEDS_GPIO_DEFSTATE_OFF; |
204 | } | 214 | } |
205 | 215 | ||
206 | if (of_get_property(child, "retain-state-suspended", NULL)) | 216 | if (fwnode_property_present(child, "retain-state-suspended")) |
207 | led.retain_state_suspended = 1; | 217 | led.retain_state_suspended = 1; |
208 | 218 | ||
209 | ret = create_gpio_led(&led, &priv->leds[priv->num_leds++], | 219 | ret = create_gpio_led(&led, &priv->leds[priv->num_leds++], |
210 | &pdev->dev, NULL); | 220 | dev, NULL); |
211 | if (ret < 0) { | 221 | if (ret < 0) { |
212 | of_node_put(child); | 222 | fwnode_handle_put(child); |
213 | goto err; | 223 | goto err; |
214 | } | 224 | } |
215 | } | 225 | } |
@@ -228,12 +238,6 @@ static const struct of_device_id of_gpio_leds_match[] = { | |||
228 | }; | 238 | }; |
229 | 239 | ||
230 | MODULE_DEVICE_TABLE(of, of_gpio_leds_match); | 240 | MODULE_DEVICE_TABLE(of, of_gpio_leds_match); |
231 | #else /* CONFIG_OF_GPIO */ | ||
232 | static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) | ||
233 | { | ||
234 | return ERR_PTR(-ENODEV); | ||
235 | } | ||
236 | #endif /* CONFIG_OF_GPIO */ | ||
237 | 241 | ||
238 | static int gpio_led_probe(struct platform_device *pdev) | 242 | static int gpio_led_probe(struct platform_device *pdev) |
239 | { | 243 | { |
@@ -261,7 +265,7 @@ static int gpio_led_probe(struct platform_device *pdev) | |||
261 | } | 265 | } |
262 | } | 266 | } |
263 | } else { | 267 | } else { |
264 | priv = gpio_leds_create_of(pdev); | 268 | priv = gpio_leds_create(pdev); |
265 | if (IS_ERR(priv)) | 269 | if (IS_ERR(priv)) |
266 | return PTR_ERR(priv); | 270 | return PTR_ERR(priv); |
267 | } | 271 | } |
@@ -288,7 +292,7 @@ static struct platform_driver gpio_led_driver = { | |||
288 | .driver = { | 292 | .driver = { |
289 | .name = "leds-gpio", | 293 | .name = "leds-gpio", |
290 | .owner = THIS_MODULE, | 294 | .owner = THIS_MODULE, |
291 | .of_match_table = of_match_ptr(of_gpio_leds_match), | 295 | .of_match_table = of_gpio_leds_match, |
292 | }, | 296 | }, |
293 | }; | 297 | }; |
294 | 298 | ||
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 634f72929e12..0a1af93ec638 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include <linux/spi/spi.h> | 19 | #include <linux/spi/spi.h> |
20 | #include <linux/spi/eeprom.h> | 20 | #include <linux/spi/eeprom.h> |
21 | #include <linux/of.h> | 21 | #include <linux/property.h> |
22 | 22 | ||
23 | /* | 23 | /* |
24 | * NOTE: this is an *EEPROM* driver. The vagaries of product naming | 24 | * NOTE: this is an *EEPROM* driver. The vagaries of product naming |
@@ -301,35 +301,33 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf, | |||
301 | 301 | ||
302 | /*-------------------------------------------------------------------------*/ | 302 | /*-------------------------------------------------------------------------*/ |
303 | 303 | ||
304 | static int at25_np_to_chip(struct device *dev, | 304 | static int at25_fw_to_chip(struct device *dev, struct spi_eeprom *chip) |
305 | struct device_node *np, | ||
306 | struct spi_eeprom *chip) | ||
307 | { | 305 | { |
308 | u32 val; | 306 | u32 val; |
309 | 307 | ||
310 | memset(chip, 0, sizeof(*chip)); | 308 | memset(chip, 0, sizeof(*chip)); |
311 | strncpy(chip->name, np->name, sizeof(chip->name)); | 309 | strncpy(chip->name, "at25", sizeof(chip->name)); |
312 | 310 | ||
313 | if (of_property_read_u32(np, "size", &val) == 0 || | 311 | if (device_property_read_u32(dev, "size", &val) == 0 || |
314 | of_property_read_u32(np, "at25,byte-len", &val) == 0) { | 312 | device_property_read_u32(dev, "at25,byte-len", &val) == 0) { |
315 | chip->byte_len = val; | 313 | chip->byte_len = val; |
316 | } else { | 314 | } else { |
317 | dev_err(dev, "Error: missing \"size\" property\n"); | 315 | dev_err(dev, "Error: missing \"size\" property\n"); |
318 | return -ENODEV; | 316 | return -ENODEV; |
319 | } | 317 | } |
320 | 318 | ||
321 | if (of_property_read_u32(np, "pagesize", &val) == 0 || | 319 | if (device_property_read_u32(dev, "pagesize", &val) == 0 || |
322 | of_property_read_u32(np, "at25,page-size", &val) == 0) { | 320 | device_property_read_u32(dev, "at25,page-size", &val) == 0) { |
323 | chip->page_size = (u16)val; | 321 | chip->page_size = (u16)val; |
324 | } else { | 322 | } else { |
325 | dev_err(dev, "Error: missing \"pagesize\" property\n"); | 323 | dev_err(dev, "Error: missing \"pagesize\" property\n"); |
326 | return -ENODEV; | 324 | return -ENODEV; |
327 | } | 325 | } |
328 | 326 | ||
329 | if (of_property_read_u32(np, "at25,addr-mode", &val) == 0) { | 327 | if (device_property_read_u32(dev, "at25,addr-mode", &val) == 0) { |
330 | chip->flags = (u16)val; | 328 | chip->flags = (u16)val; |
331 | } else { | 329 | } else { |
332 | if (of_property_read_u32(np, "address-width", &val)) { | 330 | if (device_property_read_u32(dev, "address-width", &val)) { |
333 | dev_err(dev, | 331 | dev_err(dev, |
334 | "Error: missing \"address-width\" property\n"); | 332 | "Error: missing \"address-width\" property\n"); |
335 | return -ENODEV; | 333 | return -ENODEV; |
@@ -350,7 +348,7 @@ static int at25_np_to_chip(struct device *dev, | |||
350 | val); | 348 | val); |
351 | return -ENODEV; | 349 | return -ENODEV; |
352 | } | 350 | } |
353 | if (of_find_property(np, "read-only", NULL)) | 351 | if (device_property_present(dev, "read-only")) |
354 | chip->flags |= EE_READONLY; | 352 | chip->flags |= EE_READONLY; |
355 | } | 353 | } |
356 | return 0; | 354 | return 0; |
@@ -360,21 +358,15 @@ static int at25_probe(struct spi_device *spi) | |||
360 | { | 358 | { |
361 | struct at25_data *at25 = NULL; | 359 | struct at25_data *at25 = NULL; |
362 | struct spi_eeprom chip; | 360 | struct spi_eeprom chip; |
363 | struct device_node *np = spi->dev.of_node; | ||
364 | int err; | 361 | int err; |
365 | int sr; | 362 | int sr; |
366 | int addrlen; | 363 | int addrlen; |
367 | 364 | ||
368 | /* Chip description */ | 365 | /* Chip description */ |
369 | if (!spi->dev.platform_data) { | 366 | if (!spi->dev.platform_data) { |
370 | if (np) { | 367 | err = at25_fw_to_chip(&spi->dev, &chip); |
371 | err = at25_np_to_chip(&spi->dev, np, &chip); | 368 | if (err) |
372 | if (err) | 369 | return err; |
373 | return err; | ||
374 | } else { | ||
375 | dev_err(&spi->dev, "Error: no chip description\n"); | ||
376 | return -ENODEV; | ||
377 | } | ||
378 | } else | 370 | } else |
379 | chip = *(struct spi_eeprom *)spi->dev.platform_data; | 371 | chip = *(struct spi_eeprom *)spi->dev.platform_data; |
380 | 372 | ||
diff --git a/drivers/of/base.c b/drivers/of/base.c index 3823edf2d012..4c2ccde42427 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -1250,6 +1250,39 @@ int of_property_read_u64(const struct device_node *np, const char *propname, | |||
1250 | EXPORT_SYMBOL_GPL(of_property_read_u64); | 1250 | EXPORT_SYMBOL_GPL(of_property_read_u64); |
1251 | 1251 | ||
1252 | /** | 1252 | /** |
1253 | * of_property_read_u64_array - Find and read an array of 64 bit integers | ||
1254 | * from a property. | ||
1255 | * | ||
1256 | * @np: device node from which the property value is to be read. | ||
1257 | * @propname: name of the property to be searched. | ||
1258 | * @out_values: pointer to return value, modified only if return value is 0. | ||
1259 | * @sz: number of array elements to read | ||
1260 | * | ||
1261 | * Search for a property in a device node and read 64-bit value(s) from | ||
1262 | * it. Returns 0 on success, -EINVAL if the property does not exist, | ||
1263 | * -ENODATA if property does not have a value, and -EOVERFLOW if the | ||
1264 | * property data isn't large enough. | ||
1265 | * | ||
1266 | * The out_values is modified only if a valid u64 value can be decoded. | ||
1267 | */ | ||
1268 | int of_property_read_u64_array(const struct device_node *np, | ||
1269 | const char *propname, u64 *out_values, | ||
1270 | size_t sz) | ||
1271 | { | ||
1272 | const __be32 *val = of_find_property_value_of_size(np, propname, | ||
1273 | (sz * sizeof(*out_values))); | ||
1274 | |||
1275 | if (IS_ERR(val)) | ||
1276 | return PTR_ERR(val); | ||
1277 | |||
1278 | while (sz--) { | ||
1279 | *out_values++ = of_read_number(val, 2); | ||
1280 | val += 2; | ||
1281 | } | ||
1282 | return 0; | ||
1283 | } | ||
1284 | |||
1285 | /** | ||
1253 | * of_property_read_string - Find and read a string from a property | 1286 | * of_property_read_string - Find and read a string from a property |
1254 | * @np: device node from which the property value is to be read. | 1287 | * @np: device node from which the property value is to be read. |
1255 | * @propname: name of the property to be searched. | 1288 | * @propname: name of the property to be searched. |
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index f34a0835aa4f..7d1ce40e201e 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h | |||
@@ -27,6 +27,7 @@ | |||
27 | #define __ACPI_BUS_H__ | 27 | #define __ACPI_BUS_H__ |
28 | 28 | ||
29 | #include <linux/device.h> | 29 | #include <linux/device.h> |
30 | #include <linux/property.h> | ||
30 | 31 | ||
31 | /* TBD: Make dynamic */ | 32 | /* TBD: Make dynamic */ |
32 | #define ACPI_MAX_HANDLES 10 | 33 | #define ACPI_MAX_HANDLES 10 |
@@ -337,10 +338,20 @@ struct acpi_device_physical_node { | |||
337 | bool put_online:1; | 338 | bool put_online:1; |
338 | }; | 339 | }; |
339 | 340 | ||
341 | /* ACPI Device Specific Data (_DSD) */ | ||
342 | struct acpi_device_data { | ||
343 | const union acpi_object *pointer; | ||
344 | const union acpi_object *properties; | ||
345 | const union acpi_object *of_compatible; | ||
346 | }; | ||
347 | |||
348 | struct acpi_gpio_mapping; | ||
349 | |||
340 | /* Device */ | 350 | /* Device */ |
341 | struct acpi_device { | 351 | struct acpi_device { |
342 | int device_type; | 352 | int device_type; |
343 | acpi_handle handle; /* no handle for fixed hardware */ | 353 | acpi_handle handle; /* no handle for fixed hardware */ |
354 | struct fwnode_handle fwnode; | ||
344 | struct acpi_device *parent; | 355 | struct acpi_device *parent; |
345 | struct list_head children; | 356 | struct list_head children; |
346 | struct list_head node; | 357 | struct list_head node; |
@@ -353,9 +364,11 @@ struct acpi_device { | |||
353 | struct acpi_device_wakeup wakeup; | 364 | struct acpi_device_wakeup wakeup; |
354 | struct acpi_device_perf performance; | 365 | struct acpi_device_perf performance; |
355 | struct acpi_device_dir dir; | 366 | struct acpi_device_dir dir; |
367 | struct acpi_device_data data; | ||
356 | struct acpi_scan_handler *handler; | 368 | struct acpi_scan_handler *handler; |
357 | struct acpi_hotplug_context *hp; | 369 | struct acpi_hotplug_context *hp; |
358 | struct acpi_driver *driver; | 370 | struct acpi_driver *driver; |
371 | const struct acpi_gpio_mapping *driver_gpios; | ||
359 | void *driver_data; | 372 | void *driver_data; |
360 | struct device dev; | 373 | struct device dev; |
361 | unsigned int physical_node_count; | 374 | unsigned int physical_node_count; |
@@ -364,6 +377,21 @@ struct acpi_device { | |||
364 | void (*remove)(struct acpi_device *); | 377 | void (*remove)(struct acpi_device *); |
365 | }; | 378 | }; |
366 | 379 | ||
380 | static inline bool is_acpi_node(struct fwnode_handle *fwnode) | ||
381 | { | ||
382 | return fwnode && fwnode->type == FWNODE_ACPI; | ||
383 | } | ||
384 | |||
385 | static inline struct acpi_device *acpi_node(struct fwnode_handle *fwnode) | ||
386 | { | ||
387 | return fwnode ? container_of(fwnode, struct acpi_device, fwnode) : NULL; | ||
388 | } | ||
389 | |||
390 | static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev) | ||
391 | { | ||
392 | return &adev->fwnode; | ||
393 | } | ||
394 | |||
367 | static inline void *acpi_driver_data(struct acpi_device *d) | 395 | static inline void *acpi_driver_data(struct acpi_device *d) |
368 | { | 396 | { |
369 | return d->driver_data; | 397 | return d->driver_data; |
diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 407a12f663eb..10f2ed95645c 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/errno.h> | 28 | #include <linux/errno.h> |
29 | #include <linux/ioport.h> /* for struct resource */ | 29 | #include <linux/ioport.h> /* for struct resource */ |
30 | #include <linux/device.h> | 30 | #include <linux/device.h> |
31 | #include <linux/property.h> | ||
31 | 32 | ||
32 | #ifndef _LINUX | 33 | #ifndef _LINUX |
33 | #define _LINUX | 34 | #define _LINUX |
@@ -423,12 +424,8 @@ extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *), | |||
423 | const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, | 424 | const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids, |
424 | const struct device *dev); | 425 | const struct device *dev); |
425 | 426 | ||
426 | static inline bool acpi_driver_match_device(struct device *dev, | 427 | extern bool acpi_driver_match_device(struct device *dev, |
427 | const struct device_driver *drv) | 428 | const struct device_driver *drv); |
428 | { | ||
429 | return !!acpi_match_device(drv->acpi_match_table, dev); | ||
430 | } | ||
431 | |||
432 | int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *); | 429 | int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *); |
433 | int acpi_device_modalias(struct device *, char *, int); | 430 | int acpi_device_modalias(struct device *, char *, int); |
434 | 431 | ||
@@ -443,6 +440,23 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *); | |||
443 | #define ACPI_COMPANION_SET(dev, adev) do { } while (0) | 440 | #define ACPI_COMPANION_SET(dev, adev) do { } while (0) |
444 | #define ACPI_HANDLE(dev) (NULL) | 441 | #define ACPI_HANDLE(dev) (NULL) |
445 | 442 | ||
443 | struct fwnode_handle; | ||
444 | |||
445 | static inline bool is_acpi_node(struct fwnode_handle *fwnode) | ||
446 | { | ||
447 | return false; | ||
448 | } | ||
449 | |||
450 | static inline struct acpi_device *acpi_node(struct fwnode_handle *fwnode) | ||
451 | { | ||
452 | return NULL; | ||
453 | } | ||
454 | |||
455 | static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev) | ||
456 | { | ||
457 | return NULL; | ||
458 | } | ||
459 | |||
446 | static inline const char *acpi_dev_name(struct acpi_device *adev) | 460 | static inline const char *acpi_dev_name(struct acpi_device *adev) |
447 | { | 461 | { |
448 | return NULL; | 462 | return NULL; |
@@ -659,4 +673,114 @@ do { \ | |||
659 | #endif | 673 | #endif |
660 | #endif | 674 | #endif |
661 | 675 | ||
676 | struct acpi_gpio_params { | ||
677 | unsigned int crs_entry_index; | ||
678 | unsigned int line_index; | ||
679 | bool active_low; | ||
680 | }; | ||
681 | |||
682 | struct acpi_gpio_mapping { | ||
683 | const char *name; | ||
684 | const struct acpi_gpio_params *data; | ||
685 | unsigned int size; | ||
686 | }; | ||
687 | |||
688 | #if defined(CONFIG_ACPI) && defined(CONFIG_GPIOLIB) | ||
689 | int acpi_dev_add_driver_gpios(struct acpi_device *adev, | ||
690 | const struct acpi_gpio_mapping *gpios); | ||
691 | |||
692 | static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) | ||
693 | { | ||
694 | if (adev) | ||
695 | adev->driver_gpios = NULL; | ||
696 | } | ||
697 | #else | ||
698 | static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev, | ||
699 | const struct acpi_gpio_mapping *gpios) | ||
700 | { | ||
701 | return -ENXIO; | ||
702 | } | ||
703 | static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {} | ||
704 | #endif | ||
705 | |||
706 | /* Device properties */ | ||
707 | |||
708 | #define MAX_ACPI_REFERENCE_ARGS 8 | ||
709 | struct acpi_reference_args { | ||
710 | struct acpi_device *adev; | ||
711 | size_t nargs; | ||
712 | u64 args[MAX_ACPI_REFERENCE_ARGS]; | ||
713 | }; | ||
714 | |||
715 | #ifdef CONFIG_ACPI | ||
716 | int acpi_dev_get_property(struct acpi_device *adev, const char *name, | ||
717 | acpi_object_type type, const union acpi_object **obj); | ||
718 | int acpi_dev_get_property_array(struct acpi_device *adev, const char *name, | ||
719 | acpi_object_type type, | ||
720 | const union acpi_object **obj); | ||
721 | int acpi_dev_get_property_reference(struct acpi_device *adev, | ||
722 | const char *name, size_t index, | ||
723 | struct acpi_reference_args *args); | ||
724 | |||
725 | int acpi_dev_prop_get(struct acpi_device *adev, const char *propname, | ||
726 | void **valptr); | ||
727 | int acpi_dev_prop_read_single(struct acpi_device *adev, const char *propname, | ||
728 | enum dev_prop_type proptype, void *val); | ||
729 | int acpi_dev_prop_read(struct acpi_device *adev, const char *propname, | ||
730 | enum dev_prop_type proptype, void *val, size_t nval); | ||
731 | |||
732 | struct acpi_device *acpi_get_next_child(struct device *dev, | ||
733 | struct acpi_device *child); | ||
734 | #else | ||
735 | static inline int acpi_dev_get_property(struct acpi_device *adev, | ||
736 | const char *name, acpi_object_type type, | ||
737 | const union acpi_object **obj) | ||
738 | { | ||
739 | return -ENXIO; | ||
740 | } | ||
741 | static inline int acpi_dev_get_property_array(struct acpi_device *adev, | ||
742 | const char *name, | ||
743 | acpi_object_type type, | ||
744 | const union acpi_object **obj) | ||
745 | { | ||
746 | return -ENXIO; | ||
747 | } | ||
748 | static inline int acpi_dev_get_property_reference(struct acpi_device *adev, | ||
749 | const char *name, const char *cells_name, | ||
750 | size_t index, struct acpi_reference_args *args) | ||
751 | { | ||
752 | return -ENXIO; | ||
753 | } | ||
754 | |||
755 | static inline int acpi_dev_prop_get(struct acpi_device *adev, | ||
756 | const char *propname, | ||
757 | void **valptr) | ||
758 | { | ||
759 | return -ENXIO; | ||
760 | } | ||
761 | |||
762 | static inline int acpi_dev_prop_read_single(struct acpi_device *adev, | ||
763 | const char *propname, | ||
764 | enum dev_prop_type proptype, | ||
765 | void *val) | ||
766 | { | ||
767 | return -ENXIO; | ||
768 | } | ||
769 | |||
770 | static inline int acpi_dev_prop_read(struct acpi_device *adev, | ||
771 | const char *propname, | ||
772 | enum dev_prop_type proptype, | ||
773 | void *val, size_t nval) | ||
774 | { | ||
775 | return -ENXIO; | ||
776 | } | ||
777 | |||
778 | static inline struct acpi_device *acpi_get_next_child(struct device *dev, | ||
779 | struct acpi_device *child) | ||
780 | { | ||
781 | return NULL; | ||
782 | } | ||
783 | |||
784 | #endif | ||
785 | |||
662 | #endif /*_LINUX_ACPI_H*/ | 786 | #endif /*_LINUX_ACPI_H*/ |
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 12f146fa6604..00b1b70d68ba 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
@@ -94,6 +94,13 @@ int gpiod_to_irq(const struct gpio_desc *desc); | |||
94 | struct gpio_desc *gpio_to_desc(unsigned gpio); | 94 | struct gpio_desc *gpio_to_desc(unsigned gpio); |
95 | int desc_to_gpio(const struct gpio_desc *desc); | 95 | int desc_to_gpio(const struct gpio_desc *desc); |
96 | 96 | ||
97 | /* Child properties interface */ | ||
98 | struct fwnode_handle; | ||
99 | |||
100 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | ||
101 | const char *propname); | ||
102 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, | ||
103 | struct fwnode_handle *child); | ||
97 | #else /* CONFIG_GPIOLIB */ | 104 | #else /* CONFIG_GPIOLIB */ |
98 | 105 | ||
99 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, | 106 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index 8b622468952c..ee2d8c6f9130 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define _GPIO_KEYS_H | 2 | #define _GPIO_KEYS_H |
3 | 3 | ||
4 | struct device; | 4 | struct device; |
5 | struct gpio_desc; | ||
5 | 6 | ||
6 | /** | 7 | /** |
7 | * struct gpio_keys_button - configuration parameters | 8 | * struct gpio_keys_button - configuration parameters |
@@ -17,6 +18,7 @@ struct device; | |||
17 | * disable button via sysfs | 18 | * disable button via sysfs |
18 | * @value: axis value for %EV_ABS | 19 | * @value: axis value for %EV_ABS |
19 | * @irq: Irq number in case of interrupt keys | 20 | * @irq: Irq number in case of interrupt keys |
21 | * @gpiod: GPIO descriptor | ||
20 | */ | 22 | */ |
21 | struct gpio_keys_button { | 23 | struct gpio_keys_button { |
22 | unsigned int code; | 24 | unsigned int code; |
@@ -29,6 +31,7 @@ struct gpio_keys_button { | |||
29 | bool can_disable; | 31 | bool can_disable; |
30 | int value; | 32 | int value; |
31 | unsigned int irq; | 33 | unsigned int irq; |
34 | struct gpio_desc *gpiod; | ||
32 | }; | 35 | }; |
33 | 36 | ||
34 | /** | 37 | /** |
diff --git a/include/linux/leds.h b/include/linux/leds.h index a57611d0c94e..361101fef270 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h | |||
@@ -261,6 +261,7 @@ struct gpio_led { | |||
261 | unsigned retain_state_suspended : 1; | 261 | unsigned retain_state_suspended : 1; |
262 | unsigned default_state : 2; | 262 | unsigned default_state : 2; |
263 | /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */ | 263 | /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */ |
264 | struct gpio_desc *gpiod; | ||
264 | }; | 265 | }; |
265 | #define LEDS_GPIO_DEFSTATE_OFF 0 | 266 | #define LEDS_GPIO_DEFSTATE_OFF 0 |
266 | #define LEDS_GPIO_DEFSTATE_ON 1 | 267 | #define LEDS_GPIO_DEFSTATE_ON 1 |
@@ -273,7 +274,7 @@ struct gpio_led_platform_data { | |||
273 | #define GPIO_LED_NO_BLINK_LOW 0 /* No blink GPIO state low */ | 274 | #define GPIO_LED_NO_BLINK_LOW 0 /* No blink GPIO state low */ |
274 | #define GPIO_LED_NO_BLINK_HIGH 1 /* No blink GPIO state high */ | 275 | #define GPIO_LED_NO_BLINK_HIGH 1 /* No blink GPIO state high */ |
275 | #define GPIO_LED_BLINK 2 /* Please, blink */ | 276 | #define GPIO_LED_BLINK 2 /* Please, blink */ |
276 | int (*gpio_blink_set)(unsigned gpio, int state, | 277 | int (*gpio_blink_set)(struct gpio_desc *desc, int state, |
277 | unsigned long *delay_on, | 278 | unsigned long *delay_on, |
278 | unsigned long *delay_off); | 279 | unsigned long *delay_off); |
279 | }; | 280 | }; |
diff --git a/include/linux/of.h b/include/linux/of.h index 29f0adc5f3e4..cf79be1441d2 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/spinlock.h> | 23 | #include <linux/spinlock.h> |
24 | #include <linux/topology.h> | 24 | #include <linux/topology.h> |
25 | #include <linux/notifier.h> | 25 | #include <linux/notifier.h> |
26 | #include <linux/property.h> | ||
26 | 27 | ||
27 | #include <asm/byteorder.h> | 28 | #include <asm/byteorder.h> |
28 | #include <asm/errno.h> | 29 | #include <asm/errno.h> |
@@ -49,6 +50,7 @@ struct device_node { | |||
49 | const char *type; | 50 | const char *type; |
50 | phandle phandle; | 51 | phandle phandle; |
51 | const char *full_name; | 52 | const char *full_name; |
53 | struct fwnode_handle fwnode; | ||
52 | 54 | ||
53 | struct property *properties; | 55 | struct property *properties; |
54 | struct property *deadprops; /* removed properties */ | 56 | struct property *deadprops; /* removed properties */ |
@@ -79,6 +81,7 @@ extern struct kobj_type of_node_ktype; | |||
79 | static inline void of_node_init(struct device_node *node) | 81 | static inline void of_node_init(struct device_node *node) |
80 | { | 82 | { |
81 | kobject_init(&node->kobj, &of_node_ktype); | 83 | kobject_init(&node->kobj, &of_node_ktype); |
84 | node->fwnode.type = FWNODE_OF; | ||
82 | } | 85 | } |
83 | 86 | ||
84 | /* true when node is initialized */ | 87 | /* true when node is initialized */ |
@@ -114,6 +117,16 @@ extern struct device_node *of_aliases; | |||
114 | extern struct device_node *of_stdout; | 117 | extern struct device_node *of_stdout; |
115 | extern raw_spinlock_t devtree_lock; | 118 | extern raw_spinlock_t devtree_lock; |
116 | 119 | ||
120 | static inline bool is_of_node(struct fwnode_handle *fwnode) | ||
121 | { | ||
122 | return fwnode && fwnode->type == FWNODE_OF; | ||
123 | } | ||
124 | |||
125 | static inline struct device_node *of_node(struct fwnode_handle *fwnode) | ||
126 | { | ||
127 | return fwnode ? container_of(fwnode, struct device_node, fwnode) : NULL; | ||
128 | } | ||
129 | |||
117 | static inline bool of_have_populated_dt(void) | 130 | static inline bool of_have_populated_dt(void) |
118 | { | 131 | { |
119 | return of_allnodes != NULL; | 132 | return of_allnodes != NULL; |
@@ -263,6 +276,10 @@ extern int of_property_read_u32_array(const struct device_node *np, | |||
263 | size_t sz); | 276 | size_t sz); |
264 | extern int of_property_read_u64(const struct device_node *np, | 277 | extern int of_property_read_u64(const struct device_node *np, |
265 | const char *propname, u64 *out_value); | 278 | const char *propname, u64 *out_value); |
279 | extern int of_property_read_u64_array(const struct device_node *np, | ||
280 | const char *propname, | ||
281 | u64 *out_values, | ||
282 | size_t sz); | ||
266 | 283 | ||
267 | extern int of_property_read_string(struct device_node *np, | 284 | extern int of_property_read_string(struct device_node *np, |
268 | const char *propname, | 285 | const char *propname, |
@@ -355,6 +372,16 @@ bool of_console_check(struct device_node *dn, char *name, int index); | |||
355 | 372 | ||
356 | #else /* CONFIG_OF */ | 373 | #else /* CONFIG_OF */ |
357 | 374 | ||
375 | static inline bool is_of_node(struct fwnode_handle *fwnode) | ||
376 | { | ||
377 | return false; | ||
378 | } | ||
379 | |||
380 | static inline struct device_node *of_node(struct fwnode_handle *fwnode) | ||
381 | { | ||
382 | return NULL; | ||
383 | } | ||
384 | |||
358 | static inline const char* of_node_full_name(const struct device_node *np) | 385 | static inline const char* of_node_full_name(const struct device_node *np) |
359 | { | 386 | { |
360 | return "<no-node>"; | 387 | return "<no-node>"; |
@@ -477,6 +504,13 @@ static inline int of_property_read_u32_array(const struct device_node *np, | |||
477 | return -ENOSYS; | 504 | return -ENOSYS; |
478 | } | 505 | } |
479 | 506 | ||
507 | static inline int of_property_read_u64_array(const struct device_node *np, | ||
508 | const char *propname, | ||
509 | u64 *out_values, size_t sz) | ||
510 | { | ||
511 | return -ENOSYS; | ||
512 | } | ||
513 | |||
480 | static inline int of_property_read_string(struct device_node *np, | 514 | static inline int of_property_read_string(struct device_node *np, |
481 | const char *propname, | 515 | const char *propname, |
482 | const char **out_string) | 516 | const char **out_string) |
diff --git a/include/linux/property.h b/include/linux/property.h new file mode 100644 index 000000000000..a6a3d98bd7e9 --- /dev/null +++ b/include/linux/property.h | |||
@@ -0,0 +1,143 @@ | |||
1 | /* | ||
2 | * property.h - Unified device property interface. | ||
3 | * | ||
4 | * Copyright (C) 2014, Intel Corporation | ||
5 | * Authors: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | ||
6 | * Mika Westerberg <mika.westerberg@linux.intel.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 | #ifndef _LINUX_PROPERTY_H_ | ||
14 | #define _LINUX_PROPERTY_H_ | ||
15 | |||
16 | #include <linux/types.h> | ||
17 | |||
18 | struct device; | ||
19 | |||
20 | enum dev_prop_type { | ||
21 | DEV_PROP_U8, | ||
22 | DEV_PROP_U16, | ||
23 | DEV_PROP_U32, | ||
24 | DEV_PROP_U64, | ||
25 | DEV_PROP_STRING, | ||
26 | DEV_PROP_MAX, | ||
27 | }; | ||
28 | |||
29 | bool device_property_present(struct device *dev, const char *propname); | ||
30 | int device_property_read_u8_array(struct device *dev, const char *propname, | ||
31 | u8 *val, size_t nval); | ||
32 | int device_property_read_u16_array(struct device *dev, const char *propname, | ||
33 | u16 *val, size_t nval); | ||
34 | int device_property_read_u32_array(struct device *dev, const char *propname, | ||
35 | u32 *val, size_t nval); | ||
36 | int device_property_read_u64_array(struct device *dev, const char *propname, | ||
37 | u64 *val, size_t nval); | ||
38 | int device_property_read_string_array(struct device *dev, const char *propname, | ||
39 | const char **val, size_t nval); | ||
40 | int device_property_read_string(struct device *dev, const char *propname, | ||
41 | const char **val); | ||
42 | |||
43 | enum fwnode_type { | ||
44 | FWNODE_INVALID = 0, | ||
45 | FWNODE_OF, | ||
46 | FWNODE_ACPI, | ||
47 | }; | ||
48 | |||
49 | struct fwnode_handle { | ||
50 | enum fwnode_type type; | ||
51 | }; | ||
52 | |||
53 | bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname); | ||
54 | int fwnode_property_read_u8_array(struct fwnode_handle *fwnode, | ||
55 | const char *propname, u8 *val, | ||
56 | size_t nval); | ||
57 | int fwnode_property_read_u16_array(struct fwnode_handle *fwnode, | ||
58 | const char *propname, u16 *val, | ||
59 | size_t nval); | ||
60 | int fwnode_property_read_u32_array(struct fwnode_handle *fwnode, | ||
61 | const char *propname, u32 *val, | ||
62 | size_t nval); | ||
63 | int fwnode_property_read_u64_array(struct fwnode_handle *fwnode, | ||
64 | const char *propname, u64 *val, | ||
65 | size_t nval); | ||
66 | int fwnode_property_read_string_array(struct fwnode_handle *fwnode, | ||
67 | const char *propname, const char **val, | ||
68 | size_t nval); | ||
69 | int fwnode_property_read_string(struct fwnode_handle *fwnode, | ||
70 | const char *propname, const char **val); | ||
71 | |||
72 | struct fwnode_handle *device_get_next_child_node(struct device *dev, | ||
73 | struct fwnode_handle *child); | ||
74 | |||
75 | #define device_for_each_child_node(dev, child) \ | ||
76 | for (child = device_get_next_child_node(dev, NULL); child; \ | ||
77 | child = device_get_next_child_node(dev, child)) | ||
78 | |||
79 | void fwnode_handle_put(struct fwnode_handle *fwnode); | ||
80 | |||
81 | unsigned int device_get_child_node_count(struct device *dev); | ||
82 | |||
83 | static inline bool device_property_read_bool(struct device *dev, | ||
84 | const char *propname) | ||
85 | { | ||
86 | return device_property_present(dev, propname); | ||
87 | } | ||
88 | |||
89 | static inline int device_property_read_u8(struct device *dev, | ||
90 | const char *propname, u8 *val) | ||
91 | { | ||
92 | return device_property_read_u8_array(dev, propname, val, 1); | ||
93 | } | ||
94 | |||
95 | static inline int device_property_read_u16(struct device *dev, | ||
96 | const char *propname, u16 *val) | ||
97 | { | ||
98 | return device_property_read_u16_array(dev, propname, val, 1); | ||
99 | } | ||
100 | |||
101 | static inline int device_property_read_u32(struct device *dev, | ||
102 | const char *propname, u32 *val) | ||
103 | { | ||
104 | return device_property_read_u32_array(dev, propname, val, 1); | ||
105 | } | ||
106 | |||
107 | static inline int device_property_read_u64(struct device *dev, | ||
108 | const char *propname, u64 *val) | ||
109 | { | ||
110 | return device_property_read_u64_array(dev, propname, val, 1); | ||
111 | } | ||
112 | |||
113 | static inline bool fwnode_property_read_bool(struct fwnode_handle *fwnode, | ||
114 | const char *propname) | ||
115 | { | ||
116 | return fwnode_property_present(fwnode, propname); | ||
117 | } | ||
118 | |||
119 | static inline int fwnode_property_read_u8(struct fwnode_handle *fwnode, | ||
120 | const char *propname, u8 *val) | ||
121 | { | ||
122 | return fwnode_property_read_u8_array(fwnode, propname, val, 1); | ||
123 | } | ||
124 | |||
125 | static inline int fwnode_property_read_u16(struct fwnode_handle *fwnode, | ||
126 | const char *propname, u16 *val) | ||
127 | { | ||
128 | return fwnode_property_read_u16_array(fwnode, propname, val, 1); | ||
129 | } | ||
130 | |||
131 | static inline int fwnode_property_read_u32(struct fwnode_handle *fwnode, | ||
132 | const char *propname, u32 *val) | ||
133 | { | ||
134 | return fwnode_property_read_u32_array(fwnode, propname, val, 1); | ||
135 | } | ||
136 | |||
137 | static inline int fwnode_property_read_u64(struct fwnode_handle *fwnode, | ||
138 | const char *propname, u64 *val) | ||
139 | { | ||
140 | return fwnode_property_read_u64_array(fwnode, propname, val, 1); | ||
141 | } | ||
142 | |||
143 | #endif /* _LINUX_PROPERTY_H_ */ | ||
diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c index 0f62326c0f5e..2a4717967502 100644 --- a/net/rfkill/rfkill-gpio.c +++ b/net/rfkill/rfkill-gpio.c | |||
@@ -63,6 +63,15 @@ static const struct rfkill_ops rfkill_gpio_ops = { | |||
63 | .set_block = rfkill_gpio_set_power, | 63 | .set_block = rfkill_gpio_set_power, |
64 | }; | 64 | }; |
65 | 65 | ||
66 | static const struct acpi_gpio_params reset_gpios = { 0, 0, false }; | ||
67 | static const struct acpi_gpio_params shutdown_gpios = { 1, 0, false }; | ||
68 | |||
69 | static const struct acpi_gpio_mapping acpi_rfkill_default_gpios[] = { | ||
70 | { "reset-gpios", &reset_gpios, 1 }, | ||
71 | { "shutdown-gpios", &shutdown_gpios, 1 }, | ||
72 | { }, | ||
73 | }; | ||
74 | |||
66 | static int rfkill_gpio_acpi_probe(struct device *dev, | 75 | static int rfkill_gpio_acpi_probe(struct device *dev, |
67 | struct rfkill_gpio_data *rfkill) | 76 | struct rfkill_gpio_data *rfkill) |
68 | { | 77 | { |
@@ -75,7 +84,8 @@ static int rfkill_gpio_acpi_probe(struct device *dev, | |||
75 | rfkill->name = dev_name(dev); | 84 | rfkill->name = dev_name(dev); |
76 | rfkill->type = (unsigned)id->driver_data; | 85 | rfkill->type = (unsigned)id->driver_data; |
77 | 86 | ||
78 | return 0; | 87 | return acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), |
88 | acpi_rfkill_default_gpios); | ||
79 | } | 89 | } |
80 | 90 | ||
81 | static int rfkill_gpio_probe(struct platform_device *pdev) | 91 | static int rfkill_gpio_probe(struct platform_device *pdev) |
@@ -102,7 +112,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev) | |||
102 | 112 | ||
103 | rfkill->clk = devm_clk_get(&pdev->dev, NULL); | 113 | rfkill->clk = devm_clk_get(&pdev->dev, NULL); |
104 | 114 | ||
105 | gpio = devm_gpiod_get_index(&pdev->dev, "reset", 0); | 115 | gpio = devm_gpiod_get(&pdev->dev, "reset"); |
106 | if (!IS_ERR(gpio)) { | 116 | if (!IS_ERR(gpio)) { |
107 | ret = gpiod_direction_output(gpio, 0); | 117 | ret = gpiod_direction_output(gpio, 0); |
108 | if (ret) | 118 | if (ret) |
@@ -110,7 +120,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev) | |||
110 | rfkill->reset_gpio = gpio; | 120 | rfkill->reset_gpio = gpio; |
111 | } | 121 | } |
112 | 122 | ||
113 | gpio = devm_gpiod_get_index(&pdev->dev, "shutdown", 1); | 123 | gpio = devm_gpiod_get(&pdev->dev, "shutdown"); |
114 | if (!IS_ERR(gpio)) { | 124 | if (!IS_ERR(gpio)) { |
115 | ret = gpiod_direction_output(gpio, 0); | 125 | ret = gpiod_direction_output(gpio, 0); |
116 | if (ret) | 126 | if (ret) |
@@ -150,6 +160,8 @@ static int rfkill_gpio_remove(struct platform_device *pdev) | |||
150 | rfkill_unregister(rfkill->rfkill_dev); | 160 | rfkill_unregister(rfkill->rfkill_dev); |
151 | rfkill_destroy(rfkill->rfkill_dev); | 161 | rfkill_destroy(rfkill->rfkill_dev); |
152 | 162 | ||
163 | acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pdev->dev)); | ||
164 | |||
153 | return 0; | 165 | return 0; |
154 | } | 166 | } |
155 | 167 | ||