aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-07-08 11:57:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-07-08 11:57:03 -0400
commit18b16676c36ae6e438ddb543bbb45accbbc4f901 (patch)
treeb2be8d281fb9580f291cfe6607e6659c03814a65
parent1d110cf5d307bd52e826a2ceaa7daab83be61b7a (diff)
parent92c74bceb0dd4b74a6c0b56c2f9a5c93a0860808 (diff)
Merge tag 'gpio-v4.7-5' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "I don't like to toss in last minute patches, but these are all for things that are broken, and have bitten people for real. Two of them go into stable. Maybe all of them if the compile test problem is a pain in the ass also for stable folks. Final (hopefully) GPIO fixes for v4.7: - Fix an oops on the Asus Eee PC 1201 - Revert a patch trying to split GPIO parsing and GPIO configuration - Revert a too liberal compile testing thing" * tag 'gpio-v4.7-5' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: Revert "gpio: gpiolib-of: Allow compile testing" Revert "gpiolib: Split GPIO flags parsing and GPIO configuration" gpio: sch: Fix Oops on module load on Asus Eee PC 1201
-rw-r--r--drivers/gpio/Kconfig2
-rw-r--r--drivers/gpio/gpio-sch.c21
-rw-r--r--drivers/gpio/gpiolib-legacy.c8
-rw-r--r--drivers/gpio/gpiolib.c52
4 files changed, 31 insertions, 52 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index cebcb405812e..536112fd2466 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -49,7 +49,7 @@ config GPIO_DEVRES
49 49
50config OF_GPIO 50config OF_GPIO
51 def_bool y 51 def_bool y
52 depends on OF || COMPILE_TEST 52 depends on OF
53 53
54config GPIO_ACPI 54config GPIO_ACPI
55 def_bool y 55 def_bool y
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index e85e7539cf5d..eb43ae4835c1 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -61,9 +61,8 @@ static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio)
61 return gpio % 8; 61 return gpio % 8;
62} 62}
63 63
64static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg) 64static int sch_gpio_reg_get(struct sch_gpio *sch, unsigned gpio, unsigned reg)
65{ 65{
66 struct sch_gpio *sch = gpiochip_get_data(gc);
67 unsigned short offset, bit; 66 unsigned short offset, bit;
68 u8 reg_val; 67 u8 reg_val;
69 68
@@ -75,10 +74,9 @@ static int sch_gpio_reg_get(struct gpio_chip *gc, unsigned gpio, unsigned reg)
75 return reg_val; 74 return reg_val;
76} 75}
77 76
78static void sch_gpio_reg_set(struct gpio_chip *gc, unsigned gpio, unsigned reg, 77static void sch_gpio_reg_set(struct sch_gpio *sch, unsigned gpio, unsigned reg,
79 int val) 78 int val)
80{ 79{
81 struct sch_gpio *sch = gpiochip_get_data(gc);
82 unsigned short offset, bit; 80 unsigned short offset, bit;
83 u8 reg_val; 81 u8 reg_val;
84 82
@@ -98,14 +96,15 @@ static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
98 struct sch_gpio *sch = gpiochip_get_data(gc); 96 struct sch_gpio *sch = gpiochip_get_data(gc);
99 97
100 spin_lock(&sch->lock); 98 spin_lock(&sch->lock);
101 sch_gpio_reg_set(gc, gpio_num, GIO, 1); 99 sch_gpio_reg_set(sch, gpio_num, GIO, 1);
102 spin_unlock(&sch->lock); 100 spin_unlock(&sch->lock);
103 return 0; 101 return 0;
104} 102}
105 103
106static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num) 104static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
107{ 105{
108 return sch_gpio_reg_get(gc, gpio_num, GLV); 106 struct sch_gpio *sch = gpiochip_get_data(gc);
107 return sch_gpio_reg_get(sch, gpio_num, GLV);
109} 108}
110 109
111static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val) 110static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
@@ -113,7 +112,7 @@ static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
113 struct sch_gpio *sch = gpiochip_get_data(gc); 112 struct sch_gpio *sch = gpiochip_get_data(gc);
114 113
115 spin_lock(&sch->lock); 114 spin_lock(&sch->lock);
116 sch_gpio_reg_set(gc, gpio_num, GLV, val); 115 sch_gpio_reg_set(sch, gpio_num, GLV, val);
117 spin_unlock(&sch->lock); 116 spin_unlock(&sch->lock);
118} 117}
119 118
@@ -123,7 +122,7 @@ static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num,
123 struct sch_gpio *sch = gpiochip_get_data(gc); 122 struct sch_gpio *sch = gpiochip_get_data(gc);
124 123
125 spin_lock(&sch->lock); 124 spin_lock(&sch->lock);
126 sch_gpio_reg_set(gc, gpio_num, GIO, 0); 125 sch_gpio_reg_set(sch, gpio_num, GIO, 0);
127 spin_unlock(&sch->lock); 126 spin_unlock(&sch->lock);
128 127
129 /* 128 /*
@@ -182,13 +181,13 @@ static int sch_gpio_probe(struct platform_device *pdev)
182 * GPIO7 is configured by the CMC as SLPIOVR 181 * GPIO7 is configured by the CMC as SLPIOVR
183 * Enable GPIO[9:8] core powered gpios explicitly 182 * Enable GPIO[9:8] core powered gpios explicitly
184 */ 183 */
185 sch_gpio_reg_set(&sch->chip, 8, GEN, 1); 184 sch_gpio_reg_set(sch, 8, GEN, 1);
186 sch_gpio_reg_set(&sch->chip, 9, GEN, 1); 185 sch_gpio_reg_set(sch, 9, GEN, 1);
187 /* 186 /*
188 * SUS_GPIO[2:0] enabled by default 187 * SUS_GPIO[2:0] enabled by default
189 * Enable SUS_GPIO3 resume powered gpio explicitly 188 * Enable SUS_GPIO3 resume powered gpio explicitly
190 */ 189 */
191 sch_gpio_reg_set(&sch->chip, 13, GEN, 1); 190 sch_gpio_reg_set(sch, 13, GEN, 1);
192 break; 191 break;
193 192
194 case PCI_DEVICE_ID_INTEL_ITC_LPC: 193 case PCI_DEVICE_ID_INTEL_ITC_LPC:
diff --git a/drivers/gpio/gpiolib-legacy.c b/drivers/gpio/gpiolib-legacy.c
index 3a5c7011ad3b..8b830996fe02 100644
--- a/drivers/gpio/gpiolib-legacy.c
+++ b/drivers/gpio/gpiolib-legacy.c
@@ -28,6 +28,10 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
28 if (!desc && gpio_is_valid(gpio)) 28 if (!desc && gpio_is_valid(gpio))
29 return -EPROBE_DEFER; 29 return -EPROBE_DEFER;
30 30
31 err = gpiod_request(desc, label);
32 if (err)
33 return err;
34
31 if (flags & GPIOF_OPEN_DRAIN) 35 if (flags & GPIOF_OPEN_DRAIN)
32 set_bit(FLAG_OPEN_DRAIN, &desc->flags); 36 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
33 37
@@ -37,10 +41,6 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
37 if (flags & GPIOF_ACTIVE_LOW) 41 if (flags & GPIOF_ACTIVE_LOW)
38 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 42 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
39 43
40 err = gpiod_request(desc, label);
41 if (err)
42 return err;
43
44 if (flags & GPIOF_DIR_IN) 44 if (flags & GPIOF_DIR_IN)
45 err = gpiod_direction_input(desc); 45 err = gpiod_direction_input(desc);
46 else 46 else
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 570771ed19e6..be74bd370f1f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1352,14 +1352,6 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
1352 spin_lock_irqsave(&gpio_lock, flags); 1352 spin_lock_irqsave(&gpio_lock, flags);
1353 } 1353 }
1354done: 1354done:
1355 if (status < 0) {
1356 /* Clear flags that might have been set by the caller before
1357 * requesting the GPIO.
1358 */
1359 clear_bit(FLAG_ACTIVE_LOW, &desc->flags);
1360 clear_bit(FLAG_OPEN_DRAIN, &desc->flags);
1361 clear_bit(FLAG_OPEN_SOURCE, &desc->flags);
1362 }
1363 spin_unlock_irqrestore(&gpio_lock, flags); 1355 spin_unlock_irqrestore(&gpio_lock, flags);
1364 return status; 1356 return status;
1365} 1357}
@@ -2587,28 +2579,13 @@ struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
2587} 2579}
2588EXPORT_SYMBOL_GPL(gpiod_get_optional); 2580EXPORT_SYMBOL_GPL(gpiod_get_optional);
2589 2581
2590/**
2591 * gpiod_parse_flags - helper function to parse GPIO lookup flags
2592 * @desc: gpio to be setup
2593 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
2594 * of_get_gpio_hog()
2595 *
2596 * Set the GPIO descriptor flags based on the given GPIO lookup flags.
2597 */
2598static void gpiod_parse_flags(struct gpio_desc *desc, unsigned long lflags)
2599{
2600 if (lflags & GPIO_ACTIVE_LOW)
2601 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
2602 if (lflags & GPIO_OPEN_DRAIN)
2603 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
2604 if (lflags & GPIO_OPEN_SOURCE)
2605 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
2606}
2607 2582
2608/** 2583/**
2609 * gpiod_configure_flags - helper function to configure a given GPIO 2584 * gpiod_configure_flags - helper function to configure a given GPIO
2610 * @desc: gpio whose value will be assigned 2585 * @desc: gpio whose value will be assigned
2611 * @con_id: function within the GPIO consumer 2586 * @con_id: function within the GPIO consumer
2587 * @lflags: gpio_lookup_flags - returned from of_find_gpio() or
2588 * of_get_gpio_hog()
2612 * @dflags: gpiod_flags - optional GPIO initialization flags 2589 * @dflags: gpiod_flags - optional GPIO initialization flags
2613 * 2590 *
2614 * Return 0 on success, -ENOENT if no GPIO has been assigned to the 2591 * Return 0 on success, -ENOENT if no GPIO has been assigned to the
@@ -2616,10 +2593,17 @@ static void gpiod_parse_flags(struct gpio_desc *desc, unsigned long lflags)
2616 * occurred while trying to acquire the GPIO. 2593 * occurred while trying to acquire the GPIO.
2617 */ 2594 */
2618static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, 2595static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
2619 enum gpiod_flags dflags) 2596 unsigned long lflags, enum gpiod_flags dflags)
2620{ 2597{
2621 int status; 2598 int status;
2622 2599
2600 if (lflags & GPIO_ACTIVE_LOW)
2601 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
2602 if (lflags & GPIO_OPEN_DRAIN)
2603 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
2604 if (lflags & GPIO_OPEN_SOURCE)
2605 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
2606
2623 /* No particular flag request, return here... */ 2607 /* No particular flag request, return here... */
2624 if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) { 2608 if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) {
2625 pr_debug("no flags found for %s\n", con_id); 2609 pr_debug("no flags found for %s\n", con_id);
@@ -2686,13 +2670,11 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2686 return desc; 2670 return desc;
2687 } 2671 }
2688 2672
2689 gpiod_parse_flags(desc, lookupflags);
2690
2691 status = gpiod_request(desc, con_id); 2673 status = gpiod_request(desc, con_id);
2692 if (status < 0) 2674 if (status < 0)
2693 return ERR_PTR(status); 2675 return ERR_PTR(status);
2694 2676
2695 status = gpiod_configure_flags(desc, con_id, flags); 2677 status = gpiod_configure_flags(desc, con_id, lookupflags, flags);
2696 if (status < 0) { 2678 if (status < 0) {
2697 dev_dbg(dev, "setup of GPIO %s failed\n", con_id); 2679 dev_dbg(dev, "setup of GPIO %s failed\n", con_id);
2698 gpiod_put(desc); 2680 gpiod_put(desc);
@@ -2748,6 +2730,10 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
2748 if (IS_ERR(desc)) 2730 if (IS_ERR(desc))
2749 return desc; 2731 return desc;
2750 2732
2733 ret = gpiod_request(desc, NULL);
2734 if (ret)
2735 return ERR_PTR(ret);
2736
2751 if (active_low) 2737 if (active_low)
2752 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 2738 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
2753 2739
@@ -2758,10 +2744,6 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
2758 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 2744 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
2759 } 2745 }
2760 2746
2761 ret = gpiod_request(desc, NULL);
2762 if (ret)
2763 return ERR_PTR(ret);
2764
2765 return desc; 2747 return desc;
2766} 2748}
2767EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod); 2749EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod);
@@ -2814,8 +2796,6 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
2814 chip = gpiod_to_chip(desc); 2796 chip = gpiod_to_chip(desc);
2815 hwnum = gpio_chip_hwgpio(desc); 2797 hwnum = gpio_chip_hwgpio(desc);
2816 2798
2817 gpiod_parse_flags(desc, lflags);
2818
2819 local_desc = gpiochip_request_own_desc(chip, hwnum, name); 2799 local_desc = gpiochip_request_own_desc(chip, hwnum, name);
2820 if (IS_ERR(local_desc)) { 2800 if (IS_ERR(local_desc)) {
2821 status = PTR_ERR(local_desc); 2801 status = PTR_ERR(local_desc);
@@ -2824,7 +2804,7 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
2824 return status; 2804 return status;
2825 } 2805 }
2826 2806
2827 status = gpiod_configure_flags(desc, name, dflags); 2807 status = gpiod_configure_flags(desc, name, lflags, dflags);
2828 if (status < 0) { 2808 if (status < 0) {
2829 pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n", 2809 pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n",
2830 name, chip->label, hwnum, status); 2810 name, chip->label, hwnum, status);