Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: Fix bit masking in Kontron PLD GPIO driver

This patch fixes the bit masking within the GPIO driver. The masking is
basically done twice which causes the wrong GPIOs to be addressed.

Signed-off-by: Michael Brunner <michael.brunner@kontron.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Brunner Michael and committed by
Linus Walleij
2e7f6122 40a625da

+9 -15
+9 -15
drivers/gpio/gpio-kempld.c
··· 46 46 47 47 status = kempld_read8(pld, reg); 48 48 if (val) 49 - status |= (1 << bit); 49 + status |= KEMPLD_GPIO_MASK(bit); 50 50 else 51 - status &= ~(1 << bit); 51 + status &= ~KEMPLD_GPIO_MASK(bit); 52 52 kempld_write8(pld, reg, status); 53 53 } 54 54 ··· 60 60 status = kempld_read8(pld, reg); 61 61 kempld_release_mutex(pld); 62 62 63 - return !!(status & (1 << bit)); 63 + return !!(status & KEMPLD_GPIO_MASK(bit)); 64 64 } 65 65 66 66 static int kempld_gpio_get(struct gpio_chip *chip, unsigned offset) ··· 69 69 = container_of(chip, struct kempld_gpio_data, chip); 70 70 struct kempld_device_data *pld = gpio->pld; 71 71 72 - return kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), 73 - KEMPLD_GPIO_MASK(offset)); 72 + return kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL_NUM(offset), offset); 74 73 } 75 74 76 75 static void kempld_gpio_set(struct gpio_chip *chip, unsigned offset, int value) ··· 79 80 struct kempld_device_data *pld = gpio->pld; 80 81 81 82 kempld_get_mutex(pld); 82 - kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), 83 - KEMPLD_GPIO_MASK(offset), value); 83 + kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), offset, value); 84 84 kempld_release_mutex(pld); 85 85 } 86 86 ··· 90 92 struct kempld_device_data *pld = gpio->pld; 91 93 92 94 kempld_get_mutex(pld); 93 - kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), 94 - KEMPLD_GPIO_MASK(offset), 0); 95 + kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), offset, 0); 95 96 kempld_release_mutex(pld); 96 97 97 98 return 0; ··· 104 107 struct kempld_device_data *pld = gpio->pld; 105 108 106 109 kempld_get_mutex(pld); 107 - kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), 108 - KEMPLD_GPIO_MASK(offset), value); 109 - kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), 110 - KEMPLD_GPIO_MASK(offset), 1); 110 + kempld_gpio_bitop(pld, KEMPLD_GPIO_LVL_NUM(offset), offset, value); 111 + kempld_gpio_bitop(pld, KEMPLD_GPIO_DIR_NUM(offset), offset, 1); 111 112 kempld_release_mutex(pld); 112 113 113 114 return 0; ··· 117 122 = container_of(chip, struct kempld_gpio_data, chip); 118 123 struct kempld_device_data *pld = gpio->pld; 119 124 120 - return kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), 121 - KEMPLD_GPIO_MASK(offset)); 125 + return kempld_gpio_get_bit(pld, KEMPLD_GPIO_DIR_NUM(offset), offset); 122 126 } 123 127 124 128 static int kempld_gpio_pincount(struct kempld_device_data *pld)