blob: ca2b6310f8f709d3b19877b3349628d70553a47c [file] [log] [blame]
Magnus Damm119f5e42013-03-13 20:32:13 +09001/*
2 * Renesas R-Car GPIO Support
3 *
Hisashi Nakamura1fd2b492014-11-07 20:54:08 +09004 * Copyright (C) 2014 Renesas Electronics Corporation
Magnus Damm119f5e42013-03-13 20:32:13 +09005 * Copyright (C) 2013 Magnus Damm
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/err.h>
18#include <linux/gpio.h>
19#include <linux/init.h>
20#include <linux/interrupt.h>
21#include <linux/io.h>
22#include <linux/ioport.h>
23#include <linux/irq.h>
24#include <linux/irqdomain.h>
25#include <linux/module.h>
Sachin Kamatbd0bf462013-10-16 15:35:02 +053026#include <linux/of.h>
Laurent Pinchartdc3465a2013-03-10 03:27:00 +010027#include <linux/pinctrl/consumer.h>
Magnus Damm119f5e42013-03-13 20:32:13 +090028#include <linux/platform_data/gpio-rcar.h>
29#include <linux/platform_device.h>
Geert Uytterhoevendf0c6c82014-04-14 20:33:13 +020030#include <linux/pm_runtime.h>
Magnus Damm119f5e42013-03-13 20:32:13 +090031#include <linux/spinlock.h>
32#include <linux/slab.h>
33
34struct gpio_rcar_priv {
35 void __iomem *base;
36 spinlock_t lock;
37 struct gpio_rcar_config config;
38 struct platform_device *pdev;
39 struct gpio_chip gpio_chip;
40 struct irq_chip irq_chip;
41 struct irq_domain *irq_domain;
42};
43
44#define IOINTSEL 0x00
45#define INOUTSEL 0x04
46#define OUTDT 0x08
47#define INDT 0x0c
48#define INTDT 0x10
49#define INTCLR 0x14
50#define INTMSK 0x18
51#define MSKCLR 0x1c
52#define POSNEG 0x20
53#define EDGLEVEL 0x24
54#define FILONOFF 0x28
Simon Horman7e1092b2013-05-24 18:47:24 +090055#define BOTHEDGE 0x4c
Magnus Damm119f5e42013-03-13 20:32:13 +090056
Laurent Pinchart159f8a02013-05-21 13:40:06 +020057#define RCAR_MAX_GPIO_PER_BANK 32
58
Magnus Damm119f5e42013-03-13 20:32:13 +090059static inline u32 gpio_rcar_read(struct gpio_rcar_priv *p, int offs)
60{
61 return ioread32(p->base + offs);
62}
63
64static inline void gpio_rcar_write(struct gpio_rcar_priv *p, int offs,
65 u32 value)
66{
67 iowrite32(value, p->base + offs);
68}
69
70static void gpio_rcar_modify_bit(struct gpio_rcar_priv *p, int offs,
71 int bit, bool value)
72{
73 u32 tmp = gpio_rcar_read(p, offs);
74
75 if (value)
76 tmp |= BIT(bit);
77 else
78 tmp &= ~BIT(bit);
79
80 gpio_rcar_write(p, offs, tmp);
81}
82
83static void gpio_rcar_irq_disable(struct irq_data *d)
84{
85 struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d);
86
87 gpio_rcar_write(p, INTMSK, ~BIT(irqd_to_hwirq(d)));
88}
89
90static void gpio_rcar_irq_enable(struct irq_data *d)
91{
92 struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d);
93
94 gpio_rcar_write(p, MSKCLR, BIT(irqd_to_hwirq(d)));
95}
96
97static void gpio_rcar_config_interrupt_input_mode(struct gpio_rcar_priv *p,
98 unsigned int hwirq,
99 bool active_high_rising_edge,
Simon Horman7e1092b2013-05-24 18:47:24 +0900100 bool level_trigger,
101 bool both)
Magnus Damm119f5e42013-03-13 20:32:13 +0900102{
103 unsigned long flags;
104
105 /* follow steps in the GPIO documentation for
106 * "Setting Edge-Sensitive Interrupt Input Mode" and
107 * "Setting Level-Sensitive Interrupt Input Mode"
108 */
109
110 spin_lock_irqsave(&p->lock, flags);
111
112 /* Configure postive or negative logic in POSNEG */
113 gpio_rcar_modify_bit(p, POSNEG, hwirq, !active_high_rising_edge);
114
115 /* Configure edge or level trigger in EDGLEVEL */
116 gpio_rcar_modify_bit(p, EDGLEVEL, hwirq, !level_trigger);
117
Simon Horman7e1092b2013-05-24 18:47:24 +0900118 /* Select one edge or both edges in BOTHEDGE */
119 if (p->config.has_both_edge_trigger)
120 gpio_rcar_modify_bit(p, BOTHEDGE, hwirq, both);
121
Magnus Damm119f5e42013-03-13 20:32:13 +0900122 /* Select "Interrupt Input Mode" in IOINTSEL */
123 gpio_rcar_modify_bit(p, IOINTSEL, hwirq, true);
124
125 /* Write INTCLR in case of edge trigger */
126 if (!level_trigger)
127 gpio_rcar_write(p, INTCLR, BIT(hwirq));
128
129 spin_unlock_irqrestore(&p->lock, flags);
130}
131
132static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
133{
134 struct gpio_rcar_priv *p = irq_data_get_irq_chip_data(d);
135 unsigned int hwirq = irqd_to_hwirq(d);
136
137 dev_dbg(&p->pdev->dev, "sense irq = %d, type = %d\n", hwirq, type);
138
139 switch (type & IRQ_TYPE_SENSE_MASK) {
140 case IRQ_TYPE_LEVEL_HIGH:
Simon Horman7e1092b2013-05-24 18:47:24 +0900141 gpio_rcar_config_interrupt_input_mode(p, hwirq, true, true,
142 false);
Magnus Damm119f5e42013-03-13 20:32:13 +0900143 break;
144 case IRQ_TYPE_LEVEL_LOW:
Simon Horman7e1092b2013-05-24 18:47:24 +0900145 gpio_rcar_config_interrupt_input_mode(p, hwirq, false, true,
146 false);
Magnus Damm119f5e42013-03-13 20:32:13 +0900147 break;
148 case IRQ_TYPE_EDGE_RISING:
Simon Horman7e1092b2013-05-24 18:47:24 +0900149 gpio_rcar_config_interrupt_input_mode(p, hwirq, true, false,
150 false);
Magnus Damm119f5e42013-03-13 20:32:13 +0900151 break;
152 case IRQ_TYPE_EDGE_FALLING:
Simon Horman7e1092b2013-05-24 18:47:24 +0900153 gpio_rcar_config_interrupt_input_mode(p, hwirq, false, false,
154 false);
155 break;
156 case IRQ_TYPE_EDGE_BOTH:
157 if (!p->config.has_both_edge_trigger)
158 return -EINVAL;
159 gpio_rcar_config_interrupt_input_mode(p, hwirq, true, false,
160 true);
Magnus Damm119f5e42013-03-13 20:32:13 +0900161 break;
162 default:
163 return -EINVAL;
164 }
165 return 0;
166}
167
168static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id)
169{
170 struct gpio_rcar_priv *p = dev_id;
171 u32 pending;
172 unsigned int offset, irqs_handled = 0;
173
Valentine Barshak8808b642013-11-29 22:04:09 +0400174 while ((pending = gpio_rcar_read(p, INTDT) &
175 gpio_rcar_read(p, INTMSK))) {
Magnus Damm119f5e42013-03-13 20:32:13 +0900176 offset = __ffs(pending);
177 gpio_rcar_write(p, INTCLR, BIT(offset));
178 generic_handle_irq(irq_find_mapping(p->irq_domain, offset));
179 irqs_handled++;
180 }
181
182 return irqs_handled ? IRQ_HANDLED : IRQ_NONE;
183}
184
185static inline struct gpio_rcar_priv *gpio_to_priv(struct gpio_chip *chip)
186{
187 return container_of(chip, struct gpio_rcar_priv, gpio_chip);
188}
189
190static void gpio_rcar_config_general_input_output_mode(struct gpio_chip *chip,
191 unsigned int gpio,
192 bool output)
193{
194 struct gpio_rcar_priv *p = gpio_to_priv(chip);
195 unsigned long flags;
196
197 /* follow steps in the GPIO documentation for
198 * "Setting General Output Mode" and
199 * "Setting General Input Mode"
200 */
201
202 spin_lock_irqsave(&p->lock, flags);
203
204 /* Configure postive logic in POSNEG */
205 gpio_rcar_modify_bit(p, POSNEG, gpio, false);
206
207 /* Select "General Input/Output Mode" in IOINTSEL */
208 gpio_rcar_modify_bit(p, IOINTSEL, gpio, false);
209
210 /* Select Input Mode or Output Mode in INOUTSEL */
211 gpio_rcar_modify_bit(p, INOUTSEL, gpio, output);
212
213 spin_unlock_irqrestore(&p->lock, flags);
214}
215
Laurent Pinchartdc3465a2013-03-10 03:27:00 +0100216static int gpio_rcar_request(struct gpio_chip *chip, unsigned offset)
217{
218 return pinctrl_request_gpio(chip->base + offset);
219}
220
221static void gpio_rcar_free(struct gpio_chip *chip, unsigned offset)
222{
223 pinctrl_free_gpio(chip->base + offset);
224
225 /* Set the GPIO as an input to ensure that the next GPIO request won't
226 * drive the GPIO pin as an output.
227 */
228 gpio_rcar_config_general_input_output_mode(chip, offset, false);
229}
230
Magnus Damm119f5e42013-03-13 20:32:13 +0900231static int gpio_rcar_direction_input(struct gpio_chip *chip, unsigned offset)
232{
233 gpio_rcar_config_general_input_output_mode(chip, offset, false);
234 return 0;
235}
236
237static int gpio_rcar_get(struct gpio_chip *chip, unsigned offset)
238{
Magnus Dammae9550f2013-06-17 08:41:52 +0900239 u32 bit = BIT(offset);
240
241 /* testing on r8a7790 shows that INDT does not show correct pin state
242 * when configured as output, so use OUTDT in case of output pins */
243 if (gpio_rcar_read(gpio_to_priv(chip), INOUTSEL) & bit)
Jürg Billeter7cb54092014-06-24 04:19:50 +0200244 return !!(gpio_rcar_read(gpio_to_priv(chip), OUTDT) & bit);
Magnus Dammae9550f2013-06-17 08:41:52 +0900245 else
Jürg Billeter7cb54092014-06-24 04:19:50 +0200246 return !!(gpio_rcar_read(gpio_to_priv(chip), INDT) & bit);
Magnus Damm119f5e42013-03-13 20:32:13 +0900247}
248
249static void gpio_rcar_set(struct gpio_chip *chip, unsigned offset, int value)
250{
251 struct gpio_rcar_priv *p = gpio_to_priv(chip);
252 unsigned long flags;
253
254 spin_lock_irqsave(&p->lock, flags);
255 gpio_rcar_modify_bit(p, OUTDT, offset, value);
256 spin_unlock_irqrestore(&p->lock, flags);
257}
258
259static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset,
260 int value)
261{
262 /* write GPIO value to output before selecting output mode of pin */
263 gpio_rcar_set(chip, offset, value);
264 gpio_rcar_config_general_input_output_mode(chip, offset, true);
265 return 0;
266}
267
268static int gpio_rcar_to_irq(struct gpio_chip *chip, unsigned offset)
269{
270 return irq_create_mapping(gpio_to_priv(chip)->irq_domain, offset);
271}
272
Linus Walleijc0d6c1a2013-10-11 19:43:39 +0200273static int gpio_rcar_irq_domain_map(struct irq_domain *h, unsigned int irq,
274 irq_hw_number_t hwirq)
Magnus Damm119f5e42013-03-13 20:32:13 +0900275{
276 struct gpio_rcar_priv *p = h->host_data;
277
Linus Walleijc0d6c1a2013-10-11 19:43:39 +0200278 dev_dbg(&p->pdev->dev, "map hw irq = %d, irq = %d\n", (int)hwirq, irq);
Magnus Damm119f5e42013-03-13 20:32:13 +0900279
Linus Walleijc0d6c1a2013-10-11 19:43:39 +0200280 irq_set_chip_data(irq, h->host_data);
281 irq_set_chip_and_handler(irq, &p->irq_chip, handle_level_irq);
282 set_irq_flags(irq, IRQF_VALID); /* kill me now */
Magnus Damm119f5e42013-03-13 20:32:13 +0900283 return 0;
284}
285
286static struct irq_domain_ops gpio_rcar_irq_domain_ops = {
287 .map = gpio_rcar_irq_domain_map,
Laurent Pinchartfe132642014-07-08 12:46:46 +0200288 .xlate = irq_domain_xlate_twocell,
Magnus Damm119f5e42013-03-13 20:32:13 +0900289};
290
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100291struct gpio_rcar_info {
292 bool has_both_edge_trigger;
293};
294
Hisashi Nakamura1fd2b492014-11-07 20:54:08 +0900295static const struct gpio_rcar_info gpio_rcar_info_gen1 = {
296 .has_both_edge_trigger = false,
297};
298
299static const struct gpio_rcar_info gpio_rcar_info_gen2 = {
300 .has_both_edge_trigger = true,
301};
302
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100303static const struct of_device_id gpio_rcar_of_table[] = {
304 {
305 .compatible = "renesas,gpio-r8a7790",
Hisashi Nakamura1fd2b492014-11-07 20:54:08 +0900306 .data = &gpio_rcar_info_gen2,
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100307 }, {
308 .compatible = "renesas,gpio-r8a7791",
Hisashi Nakamura1fd2b492014-11-07 20:54:08 +0900309 .data = &gpio_rcar_info_gen2,
310 }, {
311 .compatible = "renesas,gpio-r8a7793",
312 .data = &gpio_rcar_info_gen2,
313 }, {
314 .compatible = "renesas,gpio-r8a7794",
315 .data = &gpio_rcar_info_gen2,
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100316 }, {
317 .compatible = "renesas,gpio-rcar",
Hisashi Nakamura1fd2b492014-11-07 20:54:08 +0900318 .data = &gpio_rcar_info_gen1,
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100319 }, {
320 /* Terminator */
321 },
322};
323
324MODULE_DEVICE_TABLE(of, gpio_rcar_of_table);
325
326static int gpio_rcar_parse_pdata(struct gpio_rcar_priv *p)
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200327{
Jingoo Hane56aee12013-07-30 17:08:05 +0900328 struct gpio_rcar_config *pdata = dev_get_platdata(&p->pdev->dev);
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200329 struct device_node *np = p->pdev->dev.of_node;
330 struct of_phandle_args args;
331 int ret;
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200332
Laurent Pincharte3050622013-06-18 12:29:49 +0200333 if (pdata) {
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200334 p->config = *pdata;
Laurent Pincharte3050622013-06-18 12:29:49 +0200335 } else if (IS_ENABLED(CONFIG_OF) && np) {
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100336 const struct of_device_id *match;
337 const struct gpio_rcar_info *info;
338
339 match = of_match_node(gpio_rcar_of_table, np);
340 if (!match)
341 return -EINVAL;
342
343 info = match->data;
344
Laurent Pinchart01eb2d12013-09-11 15:51:01 +0200345 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0,
346 &args);
347 p->config.number_of_pins = ret == 0 ? args.args[2]
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200348 : RCAR_MAX_GPIO_PER_BANK;
349 p->config.gpio_base = -1;
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100350 p->config.has_both_edge_trigger = info->has_both_edge_trigger;
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200351 }
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200352
353 if (p->config.number_of_pins == 0 ||
354 p->config.number_of_pins > RCAR_MAX_GPIO_PER_BANK) {
355 dev_warn(&p->pdev->dev,
356 "Invalid number of gpio lines %u, using %u\n",
357 p->config.number_of_pins, RCAR_MAX_GPIO_PER_BANK);
358 p->config.number_of_pins = RCAR_MAX_GPIO_PER_BANK;
359 }
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100360
361 return 0;
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200362}
363
Magnus Damm119f5e42013-03-13 20:32:13 +0900364static int gpio_rcar_probe(struct platform_device *pdev)
365{
Magnus Damm119f5e42013-03-13 20:32:13 +0900366 struct gpio_rcar_priv *p;
367 struct resource *io, *irq;
368 struct gpio_chip *gpio_chip;
369 struct irq_chip *irq_chip;
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100370 struct device *dev = &pdev->dev;
371 const char *name = dev_name(dev);
Magnus Damm119f5e42013-03-13 20:32:13 +0900372 int ret;
373
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100374 p = devm_kzalloc(dev, sizeof(*p), GFP_KERNEL);
Geert Uytterhoeven7d82bf32015-01-12 11:07:58 +0100375 if (!p)
376 return -ENOMEM;
Magnus Damm119f5e42013-03-13 20:32:13 +0900377
Magnus Damm119f5e42013-03-13 20:32:13 +0900378 p->pdev = pdev;
Magnus Damm119f5e42013-03-13 20:32:13 +0900379 spin_lock_init(&p->lock);
380
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200381 /* Get device configuration from DT node or platform data. */
Laurent Pinchart850dfe12013-11-29 14:48:00 +0100382 ret = gpio_rcar_parse_pdata(p);
383 if (ret < 0)
384 return ret;
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200385
386 platform_set_drvdata(pdev, p);
387
Geert Uytterhoevendf0c6c82014-04-14 20:33:13 +0200388 pm_runtime_enable(dev);
389 pm_runtime_get_sync(dev);
390
Magnus Damm119f5e42013-03-13 20:32:13 +0900391 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
392 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
393
394 if (!io || !irq) {
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100395 dev_err(dev, "missing IRQ or IOMEM\n");
Magnus Damm119f5e42013-03-13 20:32:13 +0900396 ret = -EINVAL;
397 goto err0;
398 }
399
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100400 p->base = devm_ioremap_nocache(dev, io->start, resource_size(io));
Magnus Damm119f5e42013-03-13 20:32:13 +0900401 if (!p->base) {
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100402 dev_err(dev, "failed to remap I/O memory\n");
Magnus Damm119f5e42013-03-13 20:32:13 +0900403 ret = -ENXIO;
404 goto err0;
405 }
406
407 gpio_chip = &p->gpio_chip;
Laurent Pinchartdc3465a2013-03-10 03:27:00 +0100408 gpio_chip->request = gpio_rcar_request;
409 gpio_chip->free = gpio_rcar_free;
Magnus Damm119f5e42013-03-13 20:32:13 +0900410 gpio_chip->direction_input = gpio_rcar_direction_input;
411 gpio_chip->get = gpio_rcar_get;
412 gpio_chip->direction_output = gpio_rcar_direction_output;
413 gpio_chip->set = gpio_rcar_set;
414 gpio_chip->to_irq = gpio_rcar_to_irq;
415 gpio_chip->label = name;
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100416 gpio_chip->dev = dev;
Magnus Damm119f5e42013-03-13 20:32:13 +0900417 gpio_chip->owner = THIS_MODULE;
418 gpio_chip->base = p->config.gpio_base;
419 gpio_chip->ngpio = p->config.number_of_pins;
420
421 irq_chip = &p->irq_chip;
422 irq_chip->name = name;
423 irq_chip->irq_mask = gpio_rcar_irq_disable;
424 irq_chip->irq_unmask = gpio_rcar_irq_enable;
Magnus Damm119f5e42013-03-13 20:32:13 +0900425 irq_chip->irq_set_type = gpio_rcar_irq_set_type;
Magnus Damm40396112013-11-20 09:23:17 +0900426 irq_chip->flags = IRQCHIP_SKIP_SET_WAKE | IRQCHIP_SET_TYPE_MASKED
427 | IRQCHIP_MASK_ON_SUSPEND;
Magnus Damm119f5e42013-03-13 20:32:13 +0900428
429 p->irq_domain = irq_domain_add_simple(pdev->dev.of_node,
430 p->config.number_of_pins,
431 p->config.irq_base,
432 &gpio_rcar_irq_domain_ops, p);
433 if (!p->irq_domain) {
434 ret = -ENXIO;
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100435 dev_err(dev, "cannot initialize irq domain\n");
Dan Carpenter0c8aab82013-11-07 10:56:51 +0300436 goto err0;
Magnus Damm119f5e42013-03-13 20:32:13 +0900437 }
438
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100439 if (devm_request_irq(dev, irq->start, gpio_rcar_irq_handler,
440 IRQF_SHARED, name, p)) {
441 dev_err(dev, "failed to request IRQ\n");
Magnus Damm119f5e42013-03-13 20:32:13 +0900442 ret = -ENOENT;
443 goto err1;
444 }
445
446 ret = gpiochip_add(gpio_chip);
447 if (ret) {
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100448 dev_err(dev, "failed to add GPIO controller\n");
Magnus Damm119f5e42013-03-13 20:32:13 +0900449 goto err1;
450 }
451
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100452 dev_info(dev, "driving %d GPIOs\n", p->config.number_of_pins);
Magnus Damm119f5e42013-03-13 20:32:13 +0900453
454 /* warn in case of mismatch if irq base is specified */
455 if (p->config.irq_base) {
456 ret = irq_find_mapping(p->irq_domain, 0);
457 if (p->config.irq_base != ret)
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100458 dev_warn(dev, "irq base mismatch (%u/%u)\n",
Magnus Damm119f5e42013-03-13 20:32:13 +0900459 p->config.irq_base, ret);
460 }
461
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200462 if (p->config.pctl_name) {
463 ret = gpiochip_add_pin_range(gpio_chip, p->config.pctl_name, 0,
464 gpio_chip->base, gpio_chip->ngpio);
465 if (ret < 0)
Geert Uytterhoevenb22978f2014-03-27 21:47:36 +0100466 dev_warn(dev, "failed to add pin range\n");
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200467 }
Laurent Pinchartdc3465a2013-03-10 03:27:00 +0100468
Magnus Damm119f5e42013-03-13 20:32:13 +0900469 return 0;
470
471err1:
472 irq_domain_remove(p->irq_domain);
473err0:
Geert Uytterhoevendf0c6c82014-04-14 20:33:13 +0200474 pm_runtime_put(dev);
475 pm_runtime_disable(dev);
Magnus Damm119f5e42013-03-13 20:32:13 +0900476 return ret;
477}
478
479static int gpio_rcar_remove(struct platform_device *pdev)
480{
481 struct gpio_rcar_priv *p = platform_get_drvdata(pdev);
Magnus Damm119f5e42013-03-13 20:32:13 +0900482
abdoulaye berthe9f5132a2014-07-12 22:30:12 +0200483 gpiochip_remove(&p->gpio_chip);
Magnus Damm119f5e42013-03-13 20:32:13 +0900484
485 irq_domain_remove(p->irq_domain);
Geert Uytterhoevendf0c6c82014-04-14 20:33:13 +0200486 pm_runtime_put(&pdev->dev);
487 pm_runtime_disable(&pdev->dev);
Magnus Damm119f5e42013-03-13 20:32:13 +0900488 return 0;
489}
490
491static struct platform_driver gpio_rcar_device_driver = {
492 .probe = gpio_rcar_probe,
493 .remove = gpio_rcar_remove,
494 .driver = {
495 .name = "gpio_rcar",
Laurent Pinchart159f8a02013-05-21 13:40:06 +0200496 .of_match_table = of_match_ptr(gpio_rcar_of_table),
Magnus Damm119f5e42013-03-13 20:32:13 +0900497 }
498};
499
500module_platform_driver(gpio_rcar_device_driver);
501
502MODULE_AUTHOR("Magnus Damm");
503MODULE_DESCRIPTION("Renesas R-Car GPIO Driver");
504MODULE_LICENSE("GPL v2");