diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2015-01-30 04:56:05 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2015-02-03 07:35:57 -0500 |
commit | 37fc8a92daf5e775a18790ccd935240ef72ddd83 (patch) | |
tree | 3630ae6ba5244199562e515ffab9ec3962c30ef2 /drivers/gpio | |
parent | 9e089246a53cce0e14f04fb24de0e1bc62ec5400 (diff) |
gpio: max732x: use an inline function for container cast
Cast the struct gpio_chip into a max732x_chip using an inline
macro and move the assignment to the variable declaration
to save lines and simplify things.
Cc: Semen Protsenko <semen.protsenko@globallogic.com>
Acked-by: Mans Rullgard <mans@mansr.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpio-max732x.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c index 745698d977a5..a095b2393fe9 100644 --- a/drivers/gpio/gpio-max732x.c +++ b/drivers/gpio/gpio-max732x.c | |||
@@ -161,6 +161,11 @@ struct max732x_chip { | |||
161 | #endif | 161 | #endif |
162 | }; | 162 | }; |
163 | 163 | ||
164 | static inline struct max732x_chip *to_max732x(struct gpio_chip *gc) | ||
165 | { | ||
166 | return container_of(gc, struct max732x_chip, gpio_chip); | ||
167 | } | ||
168 | |||
164 | static int max732x_writeb(struct max732x_chip *chip, int group_a, uint8_t val) | 169 | static int max732x_writeb(struct max732x_chip *chip, int group_a, uint8_t val) |
165 | { | 170 | { |
166 | struct i2c_client *client; | 171 | struct i2c_client *client; |
@@ -199,12 +204,10 @@ static inline int is_group_a(struct max732x_chip *chip, unsigned off) | |||
199 | 204 | ||
200 | static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off) | 205 | static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off) |
201 | { | 206 | { |
202 | struct max732x_chip *chip; | 207 | struct max732x_chip *chip = to_max732x(gc); |
203 | uint8_t reg_val; | 208 | uint8_t reg_val; |
204 | int ret; | 209 | int ret; |
205 | 210 | ||
206 | chip = container_of(gc, struct max732x_chip, gpio_chip); | ||
207 | |||
208 | ret = max732x_readb(chip, is_group_a(chip, off), ®_val); | 211 | ret = max732x_readb(chip, is_group_a(chip, off), ®_val); |
209 | if (ret < 0) | 212 | if (ret < 0) |
210 | return 0; | 213 | return 0; |
@@ -215,12 +218,10 @@ static int max732x_gpio_get_value(struct gpio_chip *gc, unsigned off) | |||
215 | static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask, | 218 | static void max732x_gpio_set_mask(struct gpio_chip *gc, unsigned off, int mask, |
216 | int val) | 219 | int val) |
217 | { | 220 | { |
218 | struct max732x_chip *chip; | 221 | struct max732x_chip *chip = to_max732x(gc); |
219 | uint8_t reg_out; | 222 | uint8_t reg_out; |
220 | int ret; | 223 | int ret; |
221 | 224 | ||
222 | chip = container_of(gc, struct max732x_chip, gpio_chip); | ||
223 | |||
224 | mutex_lock(&chip->lock); | 225 | mutex_lock(&chip->lock); |
225 | 226 | ||
226 | reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; | 227 | reg_out = (off > 7) ? chip->reg_out[1] : chip->reg_out[0]; |
@@ -261,11 +262,9 @@ static void max732x_gpio_set_multiple(struct gpio_chip *gc, | |||
261 | 262 | ||
262 | static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) | 263 | static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) |
263 | { | 264 | { |
264 | struct max732x_chip *chip; | 265 | struct max732x_chip *chip = to_max732x(gc); |
265 | unsigned int mask = 1u << off; | 266 | unsigned int mask = 1u << off; |
266 | 267 | ||
267 | chip = container_of(gc, struct max732x_chip, gpio_chip); | ||
268 | |||
269 | if ((mask & chip->dir_input) == 0) { | 268 | if ((mask & chip->dir_input) == 0) { |
270 | dev_dbg(&chip->client->dev, "%s port %d is output only\n", | 269 | dev_dbg(&chip->client->dev, "%s port %d is output only\n", |
271 | chip->client->name, off); | 270 | chip->client->name, off); |
@@ -285,11 +284,9 @@ static int max732x_gpio_direction_input(struct gpio_chip *gc, unsigned off) | |||
285 | static int max732x_gpio_direction_output(struct gpio_chip *gc, | 284 | static int max732x_gpio_direction_output(struct gpio_chip *gc, |
286 | unsigned off, int val) | 285 | unsigned off, int val) |
287 | { | 286 | { |
288 | struct max732x_chip *chip; | 287 | struct max732x_chip *chip = to_max732x(gc); |
289 | unsigned int mask = 1u << off; | 288 | unsigned int mask = 1u << off; |
290 | 289 | ||
291 | chip = container_of(gc, struct max732x_chip, gpio_chip); | ||
292 | |||
293 | if ((mask & chip->dir_output) == 0) { | 290 | if ((mask & chip->dir_output) == 0) { |
294 | dev_dbg(&chip->client->dev, "%s port %d is input only\n", | 291 | dev_dbg(&chip->client->dev, "%s port %d is input only\n", |
295 | chip->client->name, off); | 292 | chip->client->name, off); |
@@ -361,9 +358,7 @@ static void max732x_irq_update_mask(struct max732x_chip *chip) | |||
361 | 358 | ||
362 | static int max732x_gpio_to_irq(struct gpio_chip *gc, unsigned off) | 359 | static int max732x_gpio_to_irq(struct gpio_chip *gc, unsigned off) |
363 | { | 360 | { |
364 | struct max732x_chip *chip; | 361 | struct max732x_chip *chip = to_max732x(gc); |
365 | |||
366 | chip = container_of(gc, struct max732x_chip, gpio_chip); | ||
367 | 362 | ||
368 | if (chip->irq_domain) { | 363 | if (chip->irq_domain) { |
369 | return irq_create_mapping(chip->irq_domain, | 364 | return irq_create_mapping(chip->irq_domain, |