1 --- a/drivers/gpio/Kconfig
2 +++ b/drivers/gpio/Kconfig
3 @@ -255,4 +255,12 @@ config GPIO_UCB1400
4 To compile this driver as a module, choose M here: the
5 module will be called ucb1400_gpio.
7 +comment "Other GPIO expanders"
9 +config GPIO_NXP_74HC164
10 + tristate "NXP 74HC164 Output expanders"
12 + Platform driver for NXP 74HC164 8-output Expanders. This
13 + provides a GPIO interface supporting outputs.
16 --- a/drivers/gpio/Makefile
17 +++ b/drivers/gpio/Makefile
18 @@ -11,6 +11,7 @@ obj-$(CONFIG_GPIO_MAX7301) += max7301.o
19 obj-$(CONFIG_GPIO_MAX732X) += max732x.o
20 obj-$(CONFIG_GPIO_MC33880) += mc33880.o
21 obj-$(CONFIG_GPIO_MCP23S08) += mcp23s08.o
22 +obj-$(CONFIG_GPIO_NXP_74HC164) += nxp_74hc164.o
23 obj-$(CONFIG_GPIO_PCA953X) += pca953x.o
24 obj-$(CONFIG_GPIO_PCF857X) += pcf857x.o
25 obj-$(CONFIG_GPIO_PL061) += pl061.o
27 +++ b/drivers/gpio/nxp_74hc164.c
30 + * NXP 74HC164 - output expander GPIO driver
32 + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
33 + * Copyright (C) 2010 Miguel Gaio <miguel.gaio@efixo.com>
35 + * This program is free software; you can redistribute it and/or modify
36 + * it under the terms of the GNU General Public License version 2 as
37 + * published by the Free Software Foundation.
39 + * Copy from nxp_74hc153.c code
42 +#include <linux/module.h>
43 +#include <linux/init.h>
44 +#include <linux/gpio.h>
45 +#include <linux/bitops.h>
46 +#include <linux/platform_device.h>
47 +#include <linux/nxp_74hc164.h>
49 +#define NXP_74HC164_NUM_GPIOS 8
51 +struct nxp_74hc164_chip {
52 + struct device *parent;
53 + struct gpio_chip gpio_chip;
58 +static void nxp_74hc164_set_value(struct gpio_chip *, unsigned, int);
60 +static struct nxp_74hc164_chip *gpio_to_nxp(struct gpio_chip *gc)
62 + return container_of(gc, struct nxp_74hc164_chip, gpio_chip);
65 +static int nxp_74hc164_direction_input(struct gpio_chip *gc, unsigned offset)
71 +static int nxp_74hc164_direction_output(struct gpio_chip *gc,
72 + unsigned offset, int val)
74 + nxp_74hc164_set_value(gc, offset, val);
78 +static int nxp_74hc164_get_value(struct gpio_chip *gc, unsigned offset)
80 + struct nxp_74hc164_chip *nxp = gpio_to_nxp(gc);
83 + mutex_lock(&nxp->lock);
84 + ret = test_bit(offset, &nxp->mask);
85 + mutex_unlock(&nxp->lock);
90 +static void nxp_74hc164_set_value(struct gpio_chip *gc,
91 + unsigned offset, int val)
93 + struct nxp_74hc164_chip *nxp;
94 + struct nxp_74hc164_platform_data *pdata;
99 + nxp = gpio_to_nxp(gc);
100 + pdata = nxp->parent->platform_data;
102 + mutex_lock(&nxp->lock);
104 + refresh = (test_and_set_bit(offset, &nxp->mask) != val);
106 + refresh = (test_and_clear_bit(offset, &nxp->mask) != val);
110 + for (i = 8; i > 0; --i, mask <<= 1) {
111 + gpio_set_value(pdata->gpio_pin_data, mask & 0x80);
112 + gpio_set_value(pdata->gpio_pin_clk, 1);
113 + gpio_set_value(pdata->gpio_pin_clk, 0);
116 + mutex_unlock(&nxp->lock);
119 +static int __devinit nxp_74hc164_probe(struct platform_device *pdev)
121 + struct nxp_74hc164_platform_data *pdata;
122 + struct nxp_74hc164_chip *nxp;
123 + struct gpio_chip *gc;
126 + pdata = pdev->dev.platform_data;
127 + if (pdata == NULL) {
128 + dev_dbg(&pdev->dev, "no platform data specified\n");
132 + nxp = kzalloc(sizeof(struct nxp_74hc164_chip), GFP_KERNEL);
134 + dev_err(&pdev->dev, "no memory for private data\n");
138 + err = gpio_request(pdata->gpio_pin_clk, dev_name(&pdev->dev));
140 + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
141 + pdata->gpio_pin_clk, err);
145 + err = gpio_request(pdata->gpio_pin_data, dev_name(&pdev->dev));
147 + dev_err(&pdev->dev, "unable to claim gpio %u, err=%d\n",
148 + pdata->gpio_pin_data, err);
152 + err = gpio_direction_output(pdata->gpio_pin_clk, 0);
154 + dev_err(&pdev->dev,
155 + "unable to set direction of gpio %u, err=%d\n",
156 + pdata->gpio_pin_clk, err);
157 + goto err_free_data;
160 + err = gpio_direction_output(pdata->gpio_pin_data, 0);
162 + dev_err(&pdev->dev,
163 + "unable to set direction of gpio %u, err=%d\n",
164 + pdata->gpio_pin_data, err);
165 + goto err_free_data;
168 + nxp->parent = &pdev->dev;
169 + mutex_init(&nxp->lock);
171 + gc = &nxp->gpio_chip;
173 + gc->direction_input = nxp_74hc164_direction_input;
174 + gc->direction_output = nxp_74hc164_direction_output;
175 + gc->get = nxp_74hc164_get_value;
176 + gc->set = nxp_74hc164_set_value;
179 + gc->base = pdata->gpio_base;
180 + gc->ngpio = NXP_74HC164_NUM_GPIOS;
181 + gc->label = dev_name(nxp->parent);
182 + gc->dev = nxp->parent;
183 + gc->owner = THIS_MODULE;
185 + err = gpiochip_add(&nxp->gpio_chip);
187 + dev_err(&pdev->dev, "unable to add gpio chip, err=%d\n", err);
188 + goto err_free_data;
191 + platform_set_drvdata(pdev, nxp);
195 + gpio_free(pdata->gpio_pin_data);
197 + gpio_free(pdata->gpio_pin_clk);
203 +static int nxp_74hc164_remove(struct platform_device *pdev)
205 + struct nxp_74hc164_chip *nxp = platform_get_drvdata(pdev);
206 + struct nxp_74hc164_platform_data *pdata = pdev->dev.platform_data;
211 + err = gpiochip_remove(&nxp->gpio_chip);
213 + dev_err(&pdev->dev,
214 + "unable to remove gpio chip, err=%d\n",
219 + gpio_free(pdata->gpio_pin_clk);
220 + gpio_free(pdata->gpio_pin_data);
223 + platform_set_drvdata(pdev, NULL);
229 +static struct platform_driver nxp_74hc164_driver = {
230 + .probe = nxp_74hc164_probe,
231 + .remove = __devexit_p(nxp_74hc164_remove),
233 + .name = NXP_74HC164_DRIVER_NAME,
234 + .owner = THIS_MODULE,
238 +static int __init nxp_74hc164_init(void)
240 + return platform_driver_register(&nxp_74hc164_driver);
242 +subsys_initcall(nxp_74hc164_init);
244 +static void __exit nxp_74hc164_exit(void)
246 + platform_driver_unregister(&nxp_74hc164_driver);
248 +module_exit(nxp_74hc164_exit);
250 +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
251 +MODULE_AUTHOR("Miguel Gaio <miguel.gaio@efixo.com>");
252 +MODULE_DESCRIPTION("GPIO expander driver for NXP 74HC164");
253 +MODULE_LICENSE("GPL v2");
254 +MODULE_ALIAS("platform:" NXP_74HC164_DRIVER_NAME);
256 +++ b/include/linux/nxp_74hc164.h
259 + * NXP 74HC164 - Dual 4-input multiplexer defines
261 + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
263 + * This program is free software; you can redistribute it and/or modify
264 + * it under the terms of the GNU General Public License version 2 as
265 + * published by the Free Software Foundation.
268 +#ifndef _NXP_74HC164_H
269 +#define _NXP_74HC164_H
271 +#define NXP_74HC164_DRIVER_NAME "nxp-74hc164"
273 +struct nxp_74hc164_platform_data {
274 + unsigned gpio_base;
275 + unsigned gpio_pin_data;
276 + unsigned gpio_pin_clk;
279 +#endif /* _NXP_74HC164_H */