1 From 1de1b5c2860d889a9422f187ad90d8e38b2431fd Mon Sep 17 00:00:00 2001
2 From: Thomas Kunze <thommycheck@gmx.de>
3 Date: Tue, 10 Feb 2009 14:50:56 +0100
4 Subject: [PATCH 16/23] add gpiolib support to ucb1x00
6 The old access methods to the gpios will be removed when
7 all users has been converted. (mainly ucb1x00-ts)
9 arch/arm/mach-sa1100/include/mach/mcp.h | 1 +
10 drivers/mfd/mcp-sa11x0.c | 1 +
11 drivers/mfd/ucb1x00-core.c | 87 ++++++++++++++++++++++++++++++-
12 include/linux/mfd/mcp.h | 1 +
13 include/linux/mfd/ucb1x00.h | 3 +
14 5 files changed, 91 insertions(+), 2 deletions(-)
16 diff --git a/arch/arm/mach-sa1100/include/mach/mcp.h b/arch/arm/mach-sa1100/include/mach/mcp.h
17 index fb8b09a..ed1a331 100644
18 --- a/arch/arm/mach-sa1100/include/mach/mcp.h
19 +++ b/arch/arm/mach-sa1100/include/mach/mcp.h
20 @@ -16,6 +16,7 @@ struct mcp_plat_data {
23 unsigned int sclk_rate;
28 diff --git a/drivers/mfd/mcp-sa11x0.c b/drivers/mfd/mcp-sa11x0.c
29 index 88c81cf..dfa59eb 100644
30 --- a/drivers/mfd/mcp-sa11x0.c
31 +++ b/drivers/mfd/mcp-sa11x0.c
32 @@ -163,6 +163,7 @@ static int mcp_sa11x0_probe(struct platform_device *pdev)
33 mcp->dma_audio_wr = DMA_Ser4MCP0Wr;
34 mcp->dma_telco_rd = DMA_Ser4MCP1Rd;
35 mcp->dma_telco_wr = DMA_Ser4MCP1Wr;
36 + mcp->gpio_base = data->gpio_base;
38 platform_set_drvdata(pdev, mcp);
40 diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
41 index bc2c1ba..b9c3f3d 100644
42 --- a/drivers/mfd/ucb1x00-core.c
43 +++ b/drivers/mfd/ucb1x00-core.c
45 #include <linux/device.h>
46 #include <linux/mutex.h>
47 #include <linux/mfd/ucb1x00.h>
48 +#include <linux/gpio.h>
51 #include <mach/hardware.h>
54 static DEFINE_MUTEX(ucb1x00_mutex);
55 static LIST_HEAD(ucb1x00_drivers);
56 static LIST_HEAD(ucb1x00_devices);
57 @@ -107,6 +107,60 @@ unsigned int ucb1x00_io_read(struct ucb1x00 *ucb)
58 return ucb1x00_reg_read(ucb, UCB_IO_DATA);
61 +static void ucb1x00_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
63 + struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio);
64 + unsigned long flags;
66 + spin_lock_irqsave(&ucb->io_lock, flags);
68 + ucb->io_out |= 1 << offset;
70 + ucb->io_out &= ~(1 << offset);
72 + ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out);
73 + spin_unlock_irqrestore(&ucb->io_lock, flags);
76 +static int ucb1x00_gpio_get(struct gpio_chip *chip, unsigned offset)
78 + struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio);
79 + return ucb1x00_reg_read(ucb, UCB_IO_DATA) & (1 << offset);
82 +static int ucb1x00_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
84 + struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio);
85 + unsigned long flags;
87 + spin_lock_irqsave(&ucb->io_lock, flags);
88 + ucb->io_dir &= ~(1 << offset);
89 + ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir);
90 + spin_unlock_irqrestore(&ucb->io_lock, flags);
95 +static int ucb1x00_gpio_direction_output(struct gpio_chip *chip, unsigned offset
98 + struct ucb1x00 *ucb = container_of(chip, struct ucb1x00, gpio);
99 + unsigned long flags;
101 + spin_lock_irqsave(&ucb->io_lock, flags);
102 + ucb->io_dir |= (1 << offset);
103 + ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir);
106 + ucb->io_out |= 1 << offset;
108 + ucb->io_out &= ~(1 << offset);
109 + ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out);
110 + spin_unlock_irqrestore(&ucb->io_lock, flags);
116 * UCB1300 data sheet says we must:
117 * 1. enable ADC => 5us (including reference startup time)
118 @@ -475,6 +529,7 @@ static int ucb1x00_probe(struct mcp *mcp)
119 struct ucb1x00_driver *drv;
125 id = mcp_reg_read(mcp, UCB_ID);
126 @@ -507,12 +562,27 @@ static int ucb1x00_probe(struct mcp *mcp)
130 + ucb->gpio.base = -1;
131 + if (mcp->gpio_base != 0) {
132 + ucb->gpio.label = dev_name(&ucb->dev);
133 + ucb->gpio.base = mcp->gpio_base;
134 + ucb->gpio.ngpio = 10;
135 + ucb->gpio.set = ucb1x00_gpio_set;
136 + ucb->gpio.get = ucb1x00_gpio_get;
137 + ucb->gpio.direction_input = ucb1x00_gpio_direction_input;
138 + ucb->gpio.direction_output = ucb1x00_gpio_direction_output;
139 + ret = gpiochip_add(&ucb->gpio);
143 + dev_info(&ucb->dev, "gpio_base not set so no gpiolib support");
145 ret = request_irq(ucb->irq, ucb1x00_irq, IRQF_TRIGGER_RISING,
148 printk(KERN_ERR "ucb1x00: unable to grab irq%d: %d\n",
154 mcp_set_drvdata(mcp, ucb);
155 @@ -521,6 +591,7 @@ static int ucb1x00_probe(struct mcp *mcp)
160 INIT_LIST_HEAD(&ucb->devs);
161 mutex_lock(&ucb1x00_mutex);
162 list_add(&ucb->node, &ucb1x00_devices);
163 @@ -528,10 +599,14 @@ static int ucb1x00_probe(struct mcp *mcp)
164 ucb1x00_add_dev(ucb, drv);
166 mutex_unlock(&ucb1x00_mutex);
171 free_irq(ucb->irq, ucb);
173 + if (ucb->gpio.base != -1)
174 + temp = gpiochip_remove(&ucb->gpio);
178 @@ -544,6 +619,7 @@ static void ucb1x00_remove(struct mcp *mcp)
180 struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
181 struct list_head *l, *n;
184 mutex_lock(&ucb1x00_mutex);
185 list_del(&ucb->node);
186 @@ -553,6 +629,12 @@ static void ucb1x00_remove(struct mcp *mcp)
188 mutex_unlock(&ucb1x00_mutex);
190 + if (ucb->gpio.base != -1) {
191 + ret = gpiochip_remove(&ucb->gpio);
193 + dev_err(&ucb->dev, "Can't remove gpio chip: %d\n", ret);
196 free_irq(ucb->irq, ucb);
197 device_unregister(&ucb->dev);
199 @@ -603,6 +685,7 @@ static int ucb1x00_resume(struct mcp *mcp)
200 struct ucb1x00 *ucb = mcp_get_drvdata(mcp);
201 struct ucb1x00_dev *dev;
203 + ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir);
204 mutex_lock(&ucb1x00_mutex);
205 list_for_each_entry(dev, &ucb->devs, dev_node) {
206 if (dev->drv->resume)
207 diff --git a/include/linux/mfd/mcp.h b/include/linux/mfd/mcp.h
208 index be95e09..ee49670 100644
209 --- a/include/linux/mfd/mcp.h
210 +++ b/include/linux/mfd/mcp.h
211 @@ -26,6 +26,7 @@ struct mcp {
212 dma_device_t dma_telco_rd;
213 dma_device_t dma_telco_wr;
214 struct device attached_device;
219 diff --git a/include/linux/mfd/ucb1x00.h b/include/linux/mfd/ucb1x00.h
220 index 70eb763..b13171e 100644
221 --- a/include/linux/mfd/ucb1x00.h
222 +++ b/include/linux/mfd/ucb1x00.h
226 #include <linux/mfd/mcp.h>
227 +#include <linux/gpio.h>
229 #define UCB_IO_DATA 0x00
230 #define UCB_IO_DIR 0x01
232 @@ -126,6 +128,7 @@ struct ucb1x00 {
234 struct list_head node;
235 struct list_head devs;
236 + struct gpio_chip gpio;
239 struct ucb1x00_driver;