Commit 4a22b8a4ad5561436b16f5278d2f9e406ffb8705

Authored by Marc Kleine-Budde
Committed by Linus Torvalds
1 parent 22e3d63147

gpio: max730x: make pullups configurable via platformdata

The gpios on the max730x chips have support for internal pullups while in
input mode.

This patch adds support for configuring these pullups via platform data.
A new member ("input_pullup_active") to the platform data struct is
introduced.  A set bit in this variable activates the pullups while the
respective port is in input mode.  This is a compatible enhancement since
unset bits lead to disables pullups which was the default in the original
driver.

_Note_: the 4 lowest bits in "input_pullup_active" are unused because the
first 4 ports of the controller are not used, too.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Reviewed-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 23 additions and 7 deletions Side-by-side Diff

drivers/gpio/max730x.c
... ... @@ -54,7 +54,7 @@
54 54 {
55 55 struct max7301 *ts = container_of(chip, struct max7301, chip);
56 56 u8 *config;
57   - u8 offset_bits;
  57 + u8 offset_bits, pin_config;
58 58 int ret;
59 59  
60 60 /* First 4 pins are unused in the controller */
61 61  
62 62  
... ... @@ -63,12 +63,15 @@
63 63  
64 64 config = &ts->port_config[offset >> 2];
65 65  
  66 + if (ts->input_pullup_active & BIT(offset))
  67 + pin_config = PIN_CONFIG_IN_PULLUP;
  68 + else
  69 + pin_config = PIN_CONFIG_IN_WO_PULLUP;
  70 +
66 71 mutex_lock(&ts->lock);
67 72  
68   - /* Standard GPIO API doesn't support pull-ups, has to be extended.
69   - * Hard-coding no pollup for now. */
70 73 *config = (*config & ~(PIN_CONFIG_MASK << offset_bits))
71   - | (PIN_CONFIG_IN_WO_PULLUP << offset_bits);
  74 + | (pin_config << offset_bits);
72 75  
73 76 ret = ts->write(ts->dev, 0x08 + (offset >> 2), *config);
74 77  
... ... @@ -177,6 +180,7 @@
177 180 /* Power up the chip and disable IRQ output */
178 181 ts->write(dev, 0x04, 0x01);
179 182  
  183 + ts->input_pullup_active = pdata->input_pullup_active;
180 184 ts->chip.label = dev->driver->name;
181 185  
182 186 ts->chip.direction_input = max7301_direction_input;
183 187  
... ... @@ -191,13 +195,17 @@
191 195 ts->chip.owner = THIS_MODULE;
192 196  
193 197 /*
194   - * tristate all pins in hardware and cache the
  198 + * initialize pullups according to platform data and cache the
195 199 * register values for later use.
196 200 */
197 201 for (i = 1; i < 8; i++) {
198 202 int j;
199   - /* 0xAA means input with internal pullup disabled */
200   - ts->write(dev, 0x08 + i, 0xAA);
  203 + /*
  204 + * initialize port_config with "0xAA", which means
  205 + * input with internal pullup disabled. This is needed
  206 + * to avoid writing zeros (in the inner for loop),
  207 + * which is not allowed according to the datasheet.
  208 + */
201 209 ts->port_config[i] = 0xAA;
202 210 for (j = 0; j < 4; j++) {
203 211 int offset = (i - 1) * 4 + j;
include/linux/spi/max7301.h
... ... @@ -11,6 +11,7 @@
11 11 struct mutex lock;
12 12 u8 port_config[8]; /* field 0 is unused */
13 13 u32 out_level; /* cached output levels */
  14 + u32 input_pullup_active;
14 15 struct gpio_chip chip;
15 16 struct device *dev;
16 17 int (*write)(struct device *dev, unsigned int reg, unsigned int val);
... ... @@ -20,6 +21,13 @@
20 21 struct max7301_platform_data {
21 22 /* number assigned to the first GPIO */
22 23 unsigned base;
  24 + /*
  25 + * bitmask controlling the pullup configuration,
  26 + *
  27 + * _note_ the 4 lowest bits are unused, because the first 4
  28 + * ports of the controller are not used, too.
  29 + */
  30 + u32 input_pullup_active;
23 31 };
24 32  
25 33 extern int __max730x_remove(struct device *dev);