1 Index: linux-3.14.25/drivers/gpio/Kconfig
2 ===================================================================
3 --- linux-3.14.25.orig/drivers/gpio/Kconfig 2014-11-30 15:25:59.554663011 +0100
4 +++ linux-3.14.25/drivers/gpio/Kconfig 2014-11-30 15:26:36.399907220 +0100
6 Support for the RDC R321x SoC GPIOs over southbridge
7 PCI configuration space.
9 +config GPIO_GW_I2C_PLD
10 + tristate "Gateworks I2C PLD GPIO Expander"
13 + Say yes here to provide access to the Gateworks I2C PLD GPIO
14 + Expander. This is used at least on the GW2358-4.
17 comment "SPI GPIO expanders:"
20 Index: linux-3.14.25/drivers/gpio/Makefile
21 ===================================================================
22 --- linux-3.14.25.orig/drivers/gpio/Makefile 2014-11-30 15:25:59.554663011 +0100
23 +++ linux-3.14.25/drivers/gpio/Makefile 2014-11-30 15:26:36.399907220 +0100
25 obj-$(CONFIG_GPIO_WM8994) += gpio-wm8994.o
26 obj-$(CONFIG_GPIO_XILINX) += gpio-xilinx.o
27 obj-$(CONFIG_GPIO_XTENSA) += gpio-xtensa.o
28 +obj-$(CONFIG_GPIO_GW_I2C_PLD) += gw_i2c_pld.o
29 Index: linux-3.14.25/drivers/gpio/gw_i2c_pld.c
30 ===================================================================
31 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
32 +++ linux-3.14.25/drivers/gpio/gw_i2c_pld.c 2014-12-01 07:15:30.030979315 +0100
35 + * Gateworks I2C PLD GPIO expander
37 + * Copyright (C) 2009 Gateworks Corporation
39 + * This program is free software; you can redistribute it and/or modify
40 + * it under the terms of the GNU General Public License as published by
41 + * the Free Software Foundation; either version 2 of the License, or
42 + * (at your option) any later version.
44 + * This program is distributed in the hope that it will be useful,
45 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 + * GNU General Public License for more details.
49 + * You should have received a copy of the GNU General Public License
50 + * along with this program; if not, write to the Free Software
51 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
54 +#include <linux/kernel.h>
55 +#include <linux/slab.h>
56 +#include <linux/hardirq.h>
57 +#include <linux/i2c.h>
58 +#include <linux/i2c/gw_i2c_pld.h>
59 +#include <linux/module.h>
60 +#include <linux/export.h>
61 +#include <asm/gpio.h>
62 +#include <mach/hardware.h>
64 +static const struct i2c_device_id gw_i2c_pld_id[] = {
65 + { "gw_i2c_pld", 8 },
68 +MODULE_DEVICE_TABLE(i2c, gw_i2c_pld_id);
71 + * The Gateworks I2C PLD chip only expose one read and one
72 + * write register. Writing a "one" bit (to match the reset state) lets
73 + * that pin be used as an input. It is an open-drain model.
77 + struct gpio_chip chip;
78 + struct i2c_client *client;
79 + unsigned out; /* software latch */
82 +/*-------------------------------------------------------------------------*/
85 + * The Gateworks I2C PLD chip does not properly send the acknowledge bit
86 + * thus we cannot use standard i2c_smbus functions. We have recreated
87 + * our own here, but we still use the rt_mutex_lock to lock the i2c_bus
88 + * as the device still exists on the I2C bus.
91 +#define PLD_SCL_GPIO 6
92 +#define PLD_SDA_GPIO 7
94 +#define SCL_LO() gpio_line_set(PLD_SCL_GPIO, IXP4XX_GPIO_LOW)
95 +#define SCL_HI() gpio_line_set(PLD_SCL_GPIO, IXP4XX_GPIO_HIGH)
96 +#define SCL_EN() gpio_line_config(PLD_SCL_GPIO, IXP4XX_GPIO_OUT)
97 +#define SDA_LO() gpio_line_set(PLD_SDA_GPIO, IXP4XX_GPIO_LOW)
98 +#define SDA_HI() gpio_line_set(PLD_SDA_GPIO, IXP4XX_GPIO_HIGH)
99 +#define SDA_EN() gpio_line_config(PLD_SDA_GPIO, IXP4XX_GPIO_OUT)
100 +#define SDA_DIS() gpio_line_config(PLD_SDA_GPIO, IXP4XX_GPIO_IN)
101 +#define SDA_IN(x) gpio_line_get(PLD_SDA_GPIO, &x);
103 +static int i2c_pld_write_byte(int address, int byte)
107 + address = (address << 1) & ~0x1;
116 + for (i = 7; i >= 0; i--)
118 + if (address & (1 << i))
133 + for (i = 7; i >= 0; i--)
135 + if (byte & (1 << i))
160 +static unsigned int i2c_pld_read_byte(int address)
162 + int i = 0, byte = 0;
165 + address = (address << 1) | 0x1;
174 + for (i = 7; i >= 0; i--)
176 + if (address & (1 << i))
192 + for (i = 7; i >= 0; i--)
210 +static int gw_i2c_pld_input8(struct gpio_chip *chip, unsigned offset)
213 + struct gw_i2c_pld *gpio = container_of(chip, struct gw_i2c_pld, chip);
214 + struct i2c_adapter *adap = gpio->client->adapter;
216 + if (in_atomic() || irqs_disabled()) {
217 + ret = rt_mutex_trylock(&adap->bus_lock);
219 + /* I2C activity is ongoing. */
222 + rt_mutex_lock(&adap->bus_lock);
225 + gpio->out |= (1 << offset);
227 + ret = i2c_pld_write_byte(gpio->client->addr, gpio->out);
229 + rt_mutex_unlock(&adap->bus_lock);
234 +static int gw_i2c_pld_get8(struct gpio_chip *chip, unsigned offset)
238 + struct gw_i2c_pld *gpio = container_of(chip, struct gw_i2c_pld, chip);
239 + struct i2c_adapter *adap = gpio->client->adapter;
241 + if (in_atomic() || irqs_disabled()) {
242 + ret = rt_mutex_trylock(&adap->bus_lock);
244 + /* I2C activity is ongoing. */
247 + rt_mutex_lock(&adap->bus_lock);
250 + value = i2c_pld_read_byte(gpio->client->addr);
252 + rt_mutex_unlock(&adap->bus_lock);
254 + return (value < 0) ? 0 : (value & (1 << offset));
257 +static int gw_i2c_pld_output8(struct gpio_chip *chip, unsigned offset, int value)
261 + struct gw_i2c_pld *gpio = container_of(chip, struct gw_i2c_pld, chip);
262 + struct i2c_adapter *adap = gpio->client->adapter;
264 + unsigned bit = 1 << offset;
266 + if (in_atomic() || irqs_disabled()) {
267 + ret = rt_mutex_trylock(&adap->bus_lock);
269 + /* I2C activity is ongoing. */
272 + rt_mutex_lock(&adap->bus_lock);
281 + ret = i2c_pld_write_byte(gpio->client->addr, gpio->out);
283 + rt_mutex_unlock(&adap->bus_lock);
288 +static void gw_i2c_pld_set8(struct gpio_chip *chip, unsigned offset, int value)
290 + gw_i2c_pld_output8(chip, offset, value);
293 +/*-------------------------------------------------------------------------*/
295 +static int gw_i2c_pld_probe(struct i2c_client *client,
296 + const struct i2c_device_id *id)
298 + struct gw_i2c_pld_platform_data *pdata;
299 + struct gw_i2c_pld *gpio;
302 + pdata = client->dev.platform_data;
306 + /* Allocate, initialize, and register this gpio_chip. */
307 + gpio = kzalloc(sizeof *gpio, GFP_KERNEL);
311 + gpio->chip.base = pdata->gpio_base;
312 + gpio->chip.can_sleep = 1;
313 + gpio->chip.dev = &client->dev;
314 + gpio->chip.owner = THIS_MODULE;
316 + gpio->chip.ngpio = pdata->nr_gpio;
317 + gpio->chip.direction_input = gw_i2c_pld_input8;
318 + gpio->chip.get = gw_i2c_pld_get8;
319 + gpio->chip.direction_output = gw_i2c_pld_output8;
320 + gpio->chip.set = gw_i2c_pld_set8;
322 + gpio->chip.label = client->name;
324 + gpio->client = client;
325 + i2c_set_clientdata(client, gpio);
329 + status = gpiochip_add(&gpio->chip);
333 + dev_info(&client->dev, "gpios %d..%d on a %s%s\n",
335 + gpio->chip.base + gpio->chip.ngpio - 1,
337 + client->irq ? " (irq ignored)" : "");
339 + /* Let platform code set up the GPIOs and their users.
340 + * Now is the first time anyone could use them.
342 + if (pdata->setup) {
343 + status = pdata->setup(client,
344 + gpio->chip.base, gpio->chip.ngpio,
347 + dev_warn(&client->dev, "setup --> %d\n", status);
353 + dev_dbg(&client->dev, "probe error %d for '%s'\n",
354 + status, client->name);
359 +static int gw_i2c_pld_remove(struct i2c_client *client)
361 + struct gw_i2c_pld_platform_data *pdata = client->dev.platform_data;
362 + struct gw_i2c_pld *gpio = i2c_get_clientdata(client);
365 + if (pdata->teardown) {
366 + status = pdata->teardown(client,
367 + gpio->chip.base, gpio->chip.ngpio,
370 + dev_err(&client->dev, "%s --> %d\n",
371 + "teardown", status);
376 + status = gpiochip_remove(&gpio->chip);
380 + dev_err(&client->dev, "%s --> %d\n", "remove", status);
384 +static struct i2c_driver gw_i2c_pld_driver = {
386 + .name = "gw_i2c_pld",
387 + .owner = THIS_MODULE,
389 + .probe = gw_i2c_pld_probe,
390 + .remove = gw_i2c_pld_remove,
391 + .id_table = gw_i2c_pld_id,
394 +static int __init gw_i2c_pld_init(void)
396 + return i2c_add_driver(&gw_i2c_pld_driver);
398 +module_init(gw_i2c_pld_init);
400 +static void __exit gw_i2c_pld_exit(void)
402 + i2c_del_driver(&gw_i2c_pld_driver);
404 +module_exit(gw_i2c_pld_exit);
406 +MODULE_LICENSE("GPL");
407 +MODULE_AUTHOR("Chris Lang");
408 Index: linux-3.14.25/include/linux/i2c/gw_i2c_pld.h
409 ===================================================================
410 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
411 +++ linux-3.14.25/include/linux/i2c/gw_i2c_pld.h 2014-11-30 15:26:36.403907355 +0100
413 +#ifndef __LINUX_GW_I2C_PLD_H
414 +#define __LINUX_GW_I2C_PLD_H
417 + * The Gateworks I2C PLD Implements an additional 8 bits of GPIO through the PLD
420 +struct gw_i2c_pld_platform_data {
421 + unsigned gpio_base;
423 + int (*setup)(struct i2c_client *client,
424 + int gpio, unsigned ngpio,
426 + int (*teardown)(struct i2c_client *client,
427 + int gpio, unsigned ngpio,
432 +#endif /* __LINUX_GW_I2C_PLD_H */