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

gpio: pcf857x: Add OF support

Add DT bindings for the pcf857x-compatible chips and parse the device
tree node in the driver.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Laurent Pinchart and committed by
Linus Walleij
63f57cd4 e5304db8

+107 -8
+71
Documentation/devicetree/bindings/gpio/gpio-pcf857x.txt
··· 1 + * PCF857x-compatible I/O expanders 2 + 3 + The PCF857x-compatible chips have "quasi-bidirectional" I/O lines that can be 4 + driven high by a pull-up current source or driven low to ground. This combines 5 + the direction and output level into a single bit per line, which can't be read 6 + back. We can't actually know at initialization time whether a line is configured 7 + (a) as output and driving the signal low/high, or (b) as input and reporting a 8 + low/high value, without knowing the last value written since the chip came out 9 + of reset (if any). The only reliable solution for setting up line direction is 10 + thus to do it explicitly. 11 + 12 + Required Properties: 13 + 14 + - compatible: should be one of the following. 15 + - "maxim,max7328": For the Maxim MAX7378 16 + - "maxim,max7329": For the Maxim MAX7329 17 + - "nxp,pca8574": For the NXP PCA8574 18 + - "nxp,pca8575": For the NXP PCA8575 19 + - "nxp,pca9670": For the NXP PCA9670 20 + - "nxp,pca9671": For the NXP PCA9671 21 + - "nxp,pca9672": For the NXP PCA9672 22 + - "nxp,pca9673": For the NXP PCA9673 23 + - "nxp,pca9674": For the NXP PCA9674 24 + - "nxp,pca9675": For the NXP PCA9675 25 + - "nxp,pcf8574": For the NXP PCF8574 26 + - "nxp,pcf8574a": For the NXP PCF8574A 27 + - "nxp,pcf8575": For the NXP PCF8575 28 + - "ti,tca9554": For the TI TCA9554 29 + 30 + - reg: I2C slave address. 31 + 32 + - gpio-controller: Marks the device node as a gpio controller. 33 + - #gpio-cells: Should be 2. The first cell is the GPIO number and the second 34 + cell specifies GPIO flags, as defined in <dt-bindings/gpio/gpio.h>. Only the 35 + GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW flags are supported. 36 + 37 + Optional Properties: 38 + 39 + - lines-initial-states: Bitmask that specifies the initial state of each 40 + line. When a bit is set to zero, the corresponding line will be initialized to 41 + the input (pulled-up) state. When the bit is set to one, the line will be 42 + initialized the the low-level output state. If the property is not specified 43 + all lines will be initialized to the input state. 44 + 45 + The I/O expander can detect input state changes, and thus optionally act as 46 + an interrupt controller. When the expander interrupt line is connected all the 47 + following properties must be set. For more information please see the 48 + interrupt controller device tree bindings documentation available at 49 + Documentation/devicetree/bindings/interrupt-controller/interrupts.txt. 50 + 51 + - interrupt-controller: Identifies the node as an interrupt controller. 52 + - #interrupt-cells: Number of cells to encode an interrupt source, shall be 2. 53 + - interrupt-parent: phandle of the parent interrupt controller. 54 + - interrupts: Interrupt specifier for the controllers interrupt. 55 + 56 + 57 + Please refer to gpio.txt in this directory for details of the common GPIO 58 + bindings used by client devices. 59 + 60 + Example: PCF8575 I/O expander node 61 + 62 + pcf8575: gpio@20 { 63 + compatible = "nxp,pcf8575"; 64 + reg = <0x20>; 65 + interrupt-parent = <&irqpin2>; 66 + interrupts = <3 0>; 67 + gpio-controller; 68 + #gpio-cells = <2>; 69 + interrupt-controller; 70 + #interrupt-cells = <2>; 71 + };
+36 -8
drivers/gpio/gpio-pcf857x.c
··· 26 26 #include <linux/irqdomain.h> 27 27 #include <linux/kernel.h> 28 28 #include <linux/module.h> 29 + #include <linux/of.h> 30 + #include <linux/of_device.h> 29 31 #include <linux/slab.h> 30 32 #include <linux/spinlock.h> 31 33 ··· 50 48 { } 51 49 }; 52 50 MODULE_DEVICE_TABLE(i2c, pcf857x_id); 51 + 52 + #ifdef CONFIG_OF 53 + static const struct of_device_id pcf857x_of_table[] = { 54 + { .compatible = "nxp,pcf8574" }, 55 + { .compatible = "nxp,pcf8574a" }, 56 + { .compatible = "nxp,pca8574" }, 57 + { .compatible = "nxp,pca9670" }, 58 + { .compatible = "nxp,pca9672" }, 59 + { .compatible = "nxp,pca9674" }, 60 + { .compatible = "nxp,pcf8575" }, 61 + { .compatible = "nxp,pca8575" }, 62 + { .compatible = "nxp,pca9671" }, 63 + { .compatible = "nxp,pca9673" }, 64 + { .compatible = "nxp,pca9675" }, 65 + { .compatible = "maxim,max7328" }, 66 + { .compatible = "maxim,max7329" }, 67 + { .compatible = "ti,tca9554" }, 68 + { } 69 + }; 70 + MODULE_DEVICE_TABLE(of, pcf857x_of_table); 71 + #endif 53 72 54 73 /* 55 74 * The pcf857x, pca857x, and pca967x chips only expose one read and one ··· 283 260 static int pcf857x_probe(struct i2c_client *client, 284 261 const struct i2c_device_id *id) 285 262 { 286 - struct pcf857x_platform_data *pdata; 263 + struct pcf857x_platform_data *pdata = dev_get_platdata(&client->dev); 264 + struct device_node *np = client->dev.of_node; 287 265 struct pcf857x *gpio; 266 + unsigned int n_latch = 0; 288 267 int status; 289 268 290 - pdata = dev_get_platdata(&client->dev); 291 - if (!pdata) { 269 + if (IS_ENABLED(CONFIG_OF) && np) 270 + of_property_read_u32(np, "lines-initial-states", &n_latch); 271 + else if (pdata) 272 + n_latch = pdata->n_latch; 273 + else 292 274 dev_dbg(&client->dev, "no platform data\n"); 293 - } 294 275 295 276 /* Allocate, initialize, and register this gpio_chip. */ 296 277 gpio = devm_kzalloc(&client->dev, sizeof(*gpio), GFP_KERNEL); ··· 387 360 * may cause transient glitching since it can't know the last value 388 361 * written (some pins may need to be driven low). 389 362 * 390 - * Using pdata->n_latch avoids that trouble. When left initialized 391 - * to zero, our software copy of the "latch" then matches the chip's 392 - * all-ones reset state. Otherwise it flags pins to be driven low. 363 + * Using n_latch avoids that trouble. When left initialized to zero, 364 + * our software copy of the "latch" then matches the chip's all-ones 365 + * reset state. Otherwise it flags pins to be driven low. 393 366 */ 394 - gpio->out = pdata ? ~pdata->n_latch : ~0; 367 + gpio->out = ~n_latch; 395 368 gpio->status = gpio->out; 396 369 397 370 status = gpiochip_add(&gpio->chip); ··· 453 426 .driver = { 454 427 .name = "pcf857x", 455 428 .owner = THIS_MODULE, 429 + .of_match_table = of_match_ptr(pcf857x_of_table), 456 430 }, 457 431 .probe = pcf857x_probe, 458 432 .remove = pcf857x_remove,