aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-11-25 04:48:40 -0500
committerLinus Walleij <linus.walleij@linaro.org>2016-12-07 09:22:49 -0500
commit2796325ffadda1ef149c0f51d29d2c7d4d72d556 (patch)
treea5fb0efd0968468e36ec4a9a894fc72ac73f997a /drivers/gpio
parent538f76c566eb37f41d4406ed4c6e7ea387b7032f (diff)
gpio: pl061: rename variable from chip to pl061
Rename the local variable "chip" referring to the struct pl061 state container to "pl061": we already have gpio_chip and irq_chip in the driver, we are needlessly adding yet another "chip" to the confusion. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-pl061.c186
1 files changed, 93 insertions, 93 deletions
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c
index b944aaefb59f..47f397236417 100644
--- a/drivers/gpio/gpio-pl061.c
+++ b/drivers/gpio/gpio-pl061.c
@@ -64,22 +64,22 @@ struct pl061 {
64 64
65static int pl061_get_direction(struct gpio_chip *gc, unsigned offset) 65static int pl061_get_direction(struct gpio_chip *gc, unsigned offset)
66{ 66{
67 struct pl061 *chip = gpiochip_get_data(gc); 67 struct pl061 *pl061 = gpiochip_get_data(gc);
68 68
69 return !(readb(chip->base + GPIODIR) & BIT(offset)); 69 return !(readb(pl061->base + GPIODIR) & BIT(offset));
70} 70}
71 71
72static int pl061_direction_input(struct gpio_chip *gc, unsigned offset) 72static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
73{ 73{
74 struct pl061 *chip = gpiochip_get_data(gc); 74 struct pl061 *pl061 = gpiochip_get_data(gc);
75 unsigned long flags; 75 unsigned long flags;
76 unsigned char gpiodir; 76 unsigned char gpiodir;
77 77
78 spin_lock_irqsave(&chip->lock, flags); 78 spin_lock_irqsave(&pl061->lock, flags);
79 gpiodir = readb(chip->base + GPIODIR); 79 gpiodir = readb(pl061->base + GPIODIR);
80 gpiodir &= ~(BIT(offset)); 80 gpiodir &= ~(BIT(offset));
81 writeb(gpiodir, chip->base + GPIODIR); 81 writeb(gpiodir, pl061->base + GPIODIR);
82 spin_unlock_irqrestore(&chip->lock, flags); 82 spin_unlock_irqrestore(&pl061->lock, flags);
83 83
84 return 0; 84 return 0;
85} 85}
@@ -87,44 +87,44 @@ static int pl061_direction_input(struct gpio_chip *gc, unsigned offset)
87static int pl061_direction_output(struct gpio_chip *gc, unsigned offset, 87static int pl061_direction_output(struct gpio_chip *gc, unsigned offset,
88 int value) 88 int value)
89{ 89{
90 struct pl061 *chip = gpiochip_get_data(gc); 90 struct pl061 *pl061 = gpiochip_get_data(gc);
91 unsigned long flags; 91 unsigned long flags;
92 unsigned char gpiodir; 92 unsigned char gpiodir;
93 93
94 spin_lock_irqsave(&chip->lock, flags); 94 spin_lock_irqsave(&pl061->lock, flags);
95 writeb(!!value << offset, chip->base + (BIT(offset + 2))); 95 writeb(!!value << offset, pl061->base + (BIT(offset + 2)));
96 gpiodir = readb(chip->base + GPIODIR); 96 gpiodir = readb(pl061->base + GPIODIR);
97 gpiodir |= BIT(offset); 97 gpiodir |= BIT(offset);
98 writeb(gpiodir, chip->base + GPIODIR); 98 writeb(gpiodir, pl061->base + GPIODIR);
99 99
100 /* 100 /*
101 * gpio value is set again, because pl061 doesn't allow to set value of 101 * gpio value is set again, because pl061 doesn't allow to set value of
102 * a gpio pin before configuring it in OUT mode. 102 * a gpio pin before configuring it in OUT mode.
103 */ 103 */
104 writeb(!!value << offset, chip->base + (BIT(offset + 2))); 104 writeb(!!value << offset, pl061->base + (BIT(offset + 2)));
105 spin_unlock_irqrestore(&chip->lock, flags); 105 spin_unlock_irqrestore(&pl061->lock, flags);
106 106
107 return 0; 107 return 0;
108} 108}
109 109
110static int pl061_get_value(struct gpio_chip *gc, unsigned offset) 110static int pl061_get_value(struct gpio_chip *gc, unsigned offset)
111{ 111{
112 struct pl061 *chip = gpiochip_get_data(gc); 112 struct pl061 *pl061 = gpiochip_get_data(gc);
113 113
114 return !!readb(chip->base + (BIT(offset + 2))); 114 return !!readb(pl061->base + (BIT(offset + 2)));
115} 115}
116 116
117static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value) 117static void pl061_set_value(struct gpio_chip *gc, unsigned offset, int value)
118{ 118{
119 struct pl061 *chip = gpiochip_get_data(gc); 119 struct pl061 *pl061 = gpiochip_get_data(gc);
120 120
121 writeb(!!value << offset, chip->base + (BIT(offset + 2))); 121 writeb(!!value << offset, pl061->base + (BIT(offset + 2)));
122} 122}
123 123
124static int pl061_irq_type(struct irq_data *d, unsigned trigger) 124static int pl061_irq_type(struct irq_data *d, unsigned trigger)
125{ 125{
126 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 126 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
127 struct pl061 *chip = gpiochip_get_data(gc); 127 struct pl061 *pl061 = gpiochip_get_data(gc);
128 int offset = irqd_to_hwirq(d); 128 int offset = irqd_to_hwirq(d);
129 unsigned long flags; 129 unsigned long flags;
130 u8 gpiois, gpioibe, gpioiev; 130 u8 gpiois, gpioibe, gpioiev;
@@ -144,11 +144,11 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)
144 } 144 }
145 145
146 146
147 spin_lock_irqsave(&chip->lock, flags); 147 spin_lock_irqsave(&pl061->lock, flags);
148 148
149 gpioiev = readb(chip->base + GPIOIEV); 149 gpioiev = readb(pl061->base + GPIOIEV);
150 gpiois = readb(chip->base + GPIOIS); 150 gpiois = readb(pl061->base + GPIOIS);
151 gpioibe = readb(chip->base + GPIOIBE); 151 gpioibe = readb(pl061->base + GPIOIBE);
152 152
153 if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 153 if (trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
154 bool polarity = trigger & IRQ_TYPE_LEVEL_HIGH; 154 bool polarity = trigger & IRQ_TYPE_LEVEL_HIGH;
@@ -200,11 +200,11 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)
200 offset); 200 offset);
201 } 201 }
202 202
203 writeb(gpiois, chip->base + GPIOIS); 203 writeb(gpiois, pl061->base + GPIOIS);
204 writeb(gpioibe, chip->base + GPIOIBE); 204 writeb(gpioibe, pl061->base + GPIOIBE);
205 writeb(gpioiev, chip->base + GPIOIEV); 205 writeb(gpioiev, pl061->base + GPIOIEV);
206 206
207 spin_unlock_irqrestore(&chip->lock, flags); 207 spin_unlock_irqrestore(&pl061->lock, flags);
208 208
209 return 0; 209 return 0;
210} 210}
@@ -214,12 +214,12 @@ static void pl061_irq_handler(struct irq_desc *desc)
214 unsigned long pending; 214 unsigned long pending;
215 int offset; 215 int offset;
216 struct gpio_chip *gc = irq_desc_get_handler_data(desc); 216 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
217 struct pl061 *chip = gpiochip_get_data(gc); 217 struct pl061 *pl061 = gpiochip_get_data(gc);
218 struct irq_chip *irqchip = irq_desc_get_chip(desc); 218 struct irq_chip *irqchip = irq_desc_get_chip(desc);
219 219
220 chained_irq_enter(irqchip, desc); 220 chained_irq_enter(irqchip, desc);
221 221
222 pending = readb(chip->base + GPIOMIS); 222 pending = readb(pl061->base + GPIOMIS);
223 if (pending) { 223 if (pending) {
224 for_each_set_bit(offset, &pending, PL061_GPIO_NR) 224 for_each_set_bit(offset, &pending, PL061_GPIO_NR)
225 generic_handle_irq(irq_find_mapping(gc->irqdomain, 225 generic_handle_irq(irq_find_mapping(gc->irqdomain,
@@ -232,27 +232,27 @@ static void pl061_irq_handler(struct irq_desc *desc)
232static void pl061_irq_mask(struct irq_data *d) 232static void pl061_irq_mask(struct irq_data *d)
233{ 233{
234 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 234 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
235 struct pl061 *chip = gpiochip_get_data(gc); 235 struct pl061 *pl061 = gpiochip_get_data(gc);
236 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 236 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
237 u8 gpioie; 237 u8 gpioie;
238 238
239 spin_lock(&chip->lock); 239 spin_lock(&pl061->lock);
240 gpioie = readb(chip->base + GPIOIE) & ~mask; 240 gpioie = readb(pl061->base + GPIOIE) & ~mask;
241 writeb(gpioie, chip->base + GPIOIE); 241 writeb(gpioie, pl061->base + GPIOIE);
242 spin_unlock(&chip->lock); 242 spin_unlock(&pl061->lock);
243} 243}
244 244
245static void pl061_irq_unmask(struct irq_data *d) 245static void pl061_irq_unmask(struct irq_data *d)
246{ 246{
247 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 247 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
248 struct pl061 *chip = gpiochip_get_data(gc); 248 struct pl061 *pl061 = gpiochip_get_data(gc);
249 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 249 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
250 u8 gpioie; 250 u8 gpioie;
251 251
252 spin_lock(&chip->lock); 252 spin_lock(&pl061->lock);
253 gpioie = readb(chip->base + GPIOIE) | mask; 253 gpioie = readb(pl061->base + GPIOIE) | mask;
254 writeb(gpioie, chip->base + GPIOIE); 254 writeb(gpioie, pl061->base + GPIOIE);
255 spin_unlock(&chip->lock); 255 spin_unlock(&pl061->lock);
256} 256}
257 257
258/** 258/**
@@ -266,20 +266,20 @@ static void pl061_irq_unmask(struct irq_data *d)
266static void pl061_irq_ack(struct irq_data *d) 266static void pl061_irq_ack(struct irq_data *d)
267{ 267{
268 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 268 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
269 struct pl061 *chip = gpiochip_get_data(gc); 269 struct pl061 *pl061 = gpiochip_get_data(gc);
270 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR); 270 u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
271 271
272 spin_lock(&chip->lock); 272 spin_lock(&pl061->lock);
273 writeb(mask, chip->base + GPIOIC); 273 writeb(mask, pl061->base + GPIOIC);
274 spin_unlock(&chip->lock); 274 spin_unlock(&pl061->lock);
275} 275}
276 276
277static int pl061_irq_set_wake(struct irq_data *d, unsigned int state) 277static int pl061_irq_set_wake(struct irq_data *d, unsigned int state)
278{ 278{
279 struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 279 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
280 struct pl061 *chip = gpiochip_get_data(gc); 280 struct pl061 *pl061 = gpiochip_get_data(gc);
281 281
282 return irq_set_irq_wake(chip->parent_irq, state); 282 return irq_set_irq_wake(pl061->parent_irq, state);
283} 283}
284 284
285static struct irq_chip pl061_irqchip = { 285static struct irq_chip pl061_irqchip = {
@@ -295,81 +295,81 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
295{ 295{
296 struct device *dev = &adev->dev; 296 struct device *dev = &adev->dev;
297 struct pl061_platform_data *pdata = dev_get_platdata(dev); 297 struct pl061_platform_data *pdata = dev_get_platdata(dev);
298 struct pl061 *chip; 298 struct pl061 *pl061;
299 int ret, irq, i, irq_base; 299 int ret, irq, i, irq_base;
300 300
301 chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); 301 pl061 = devm_kzalloc(dev, sizeof(*pl061), GFP_KERNEL);
302 if (chip == NULL) 302 if (pl061 == NULL)
303 return -ENOMEM; 303 return -ENOMEM;
304 304
305 if (pdata) { 305 if (pdata) {
306 chip->gc.base = pdata->gpio_base; 306 pl061->gc.base = pdata->gpio_base;
307 irq_base = pdata->irq_base; 307 irq_base = pdata->irq_base;
308 if (irq_base <= 0) { 308 if (irq_base <= 0) {
309 dev_err(&adev->dev, "invalid IRQ base in pdata\n"); 309 dev_err(&adev->dev, "invalid IRQ base in pdata\n");
310 return -ENODEV; 310 return -ENODEV;
311 } 311 }
312 } else { 312 } else {
313 chip->gc.base = -1; 313 pl061->gc.base = -1;
314 irq_base = 0; 314 irq_base = 0;
315 } 315 }
316 316
317 chip->base = devm_ioremap_resource(dev, &adev->res); 317 pl061->base = devm_ioremap_resource(dev, &adev->res);
318 if (IS_ERR(chip->base)) 318 if (IS_ERR(pl061->base))
319 return PTR_ERR(chip->base); 319 return PTR_ERR(pl061->base);
320 320
321 spin_lock_init(&chip->lock); 321 spin_lock_init(&pl061->lock);
322 if (of_property_read_bool(dev->of_node, "gpio-ranges")) { 322 if (of_property_read_bool(dev->of_node, "gpio-ranges")) {
323 chip->gc.request = gpiochip_generic_request; 323 pl061->gc.request = gpiochip_generic_request;
324 chip->gc.free = gpiochip_generic_free; 324 pl061->gc.free = gpiochip_generic_free;
325 } 325 }
326 326
327 chip->gc.get_direction = pl061_get_direction; 327 pl061->gc.get_direction = pl061_get_direction;
328 chip->gc.direction_input = pl061_direction_input; 328 pl061->gc.direction_input = pl061_direction_input;
329 chip->gc.direction_output = pl061_direction_output; 329 pl061->gc.direction_output = pl061_direction_output;
330 chip->gc.get = pl061_get_value; 330 pl061->gc.get = pl061_get_value;
331 chip->gc.set = pl061_set_value; 331 pl061->gc.set = pl061_set_value;
332 chip->gc.ngpio = PL061_GPIO_NR; 332 pl061->gc.ngpio = PL061_GPIO_NR;
333 chip->gc.label = dev_name(dev); 333 pl061->gc.label = dev_name(dev);
334 chip->gc.parent = dev; 334 pl061->gc.parent = dev;
335 chip->gc.owner = THIS_MODULE; 335 pl061->gc.owner = THIS_MODULE;
336 336
337 ret = gpiochip_add_data(&chip->gc, chip); 337 ret = gpiochip_add_data(&pl061->gc, pl061);
338 if (ret) 338 if (ret)
339 return ret; 339 return ret;
340 340
341 /* 341 /*
342 * irq_chip support 342 * irq_chip support
343 */ 343 */
344 writeb(0, chip->base + GPIOIE); /* disable irqs */ 344 writeb(0, pl061->base + GPIOIE); /* disable irqs */
345 irq = adev->irq[0]; 345 irq = adev->irq[0];
346 if (irq < 0) { 346 if (irq < 0) {
347 dev_err(&adev->dev, "invalid IRQ\n"); 347 dev_err(&adev->dev, "invalid IRQ\n");
348 return -ENODEV; 348 return -ENODEV;
349 } 349 }
350 chip->parent_irq = irq; 350 pl061->parent_irq = irq;
351 351
352 ret = gpiochip_irqchip_add(&chip->gc, &pl061_irqchip, 352 ret = gpiochip_irqchip_add(&pl061->gc, &pl061_irqchip,
353 irq_base, handle_bad_irq, 353 irq_base, handle_bad_irq,
354 IRQ_TYPE_NONE); 354 IRQ_TYPE_NONE);
355 if (ret) { 355 if (ret) {
356 dev_info(&adev->dev, "could not add irqchip\n"); 356 dev_info(&adev->dev, "could not add irqchip\n");
357 return ret; 357 return ret;
358 } 358 }
359 gpiochip_set_chained_irqchip(&chip->gc, &pl061_irqchip, 359 gpiochip_set_chained_irqchip(&pl061->gc, &pl061_irqchip,
360 irq, pl061_irq_handler); 360 irq, pl061_irq_handler);
361 361
362 for (i = 0; i < PL061_GPIO_NR; i++) { 362 for (i = 0; i < PL061_GPIO_NR; i++) {
363 if (pdata) { 363 if (pdata) {
364 if (pdata->directions & (BIT(i))) 364 if (pdata->directions & (BIT(i)))
365 pl061_direction_output(&chip->gc, i, 365 pl061_direction_output(&pl061->gc, i,
366 pdata->values & (BIT(i))); 366 pdata->values & (BIT(i)));
367 else 367 else
368 pl061_direction_input(&chip->gc, i); 368 pl061_direction_input(&pl061->gc, i);
369 } 369 }
370 } 370 }
371 371
372 amba_set_drvdata(adev, chip); 372 amba_set_drvdata(adev, pl061);
373 dev_info(&adev->dev, "PL061 GPIO chip @%pa registered\n", 373 dev_info(&adev->dev, "PL061 GPIO chip @%pa registered\n",
374 &adev->res.start); 374 &adev->res.start);
375 375
@@ -379,20 +379,20 @@ static int pl061_probe(struct amba_device *adev, const struct amba_id *id)
379#ifdef CONFIG_PM 379#ifdef CONFIG_PM
380static int pl061_suspend(struct device *dev) 380static int pl061_suspend(struct device *dev)
381{ 381{
382 struct pl061 *chip = dev_get_drvdata(dev); 382 struct pl061 *pl061 = dev_get_drvdata(dev);
383 int offset; 383 int offset;
384 384
385 chip->csave_regs.gpio_data = 0; 385 pl061->csave_regs.gpio_data = 0;
386 chip->csave_regs.gpio_dir = readb(chip->base + GPIODIR); 386 pl061->csave_regs.gpio_dir = readb(pl061->base + GPIODIR);
387 chip->csave_regs.gpio_is = readb(chip->base + GPIOIS); 387 pl061->csave_regs.gpio_is = readb(pl061->base + GPIOIS);
388 chip->csave_regs.gpio_ibe = readb(chip->base + GPIOIBE); 388 pl061->csave_regs.gpio_ibe = readb(pl061->base + GPIOIBE);
389 chip->csave_regs.gpio_iev = readb(chip->base + GPIOIEV); 389 pl061->csave_regs.gpio_iev = readb(pl061->base + GPIOIEV);
390 chip->csave_regs.gpio_ie = readb(chip->base + GPIOIE); 390 pl061->csave_regs.gpio_ie = readb(pl061->base + GPIOIE);
391 391
392 for (offset = 0; offset < PL061_GPIO_NR; offset++) { 392 for (offset = 0; offset < PL061_GPIO_NR; offset++) {
393 if (chip->csave_regs.gpio_dir & (BIT(offset))) 393 if (pl061->csave_regs.gpio_dir & (BIT(offset)))
394 chip->csave_regs.gpio_data |= 394 pl061->csave_regs.gpio_data |=
395 pl061_get_value(&chip->gc, offset) << offset; 395 pl061_get_value(&pl061->gc, offset) << offset;
396 } 396 }
397 397
398 return 0; 398 return 0;
@@ -400,22 +400,22 @@ static int pl061_suspend(struct device *dev)
400 400
401static int pl061_resume(struct device *dev) 401static int pl061_resume(struct device *dev)
402{ 402{
403 struct pl061 *chip = dev_get_drvdata(dev); 403 struct pl061 *pl061 = dev_get_drvdata(dev);
404 int offset; 404 int offset;
405 405
406 for (offset = 0; offset < PL061_GPIO_NR; offset++) { 406 for (offset = 0; offset < PL061_GPIO_NR; offset++) {
407 if (chip->csave_regs.gpio_dir & (BIT(offset))) 407 if (pl061->csave_regs.gpio_dir & (BIT(offset)))
408 pl061_direction_output(&chip->gc, offset, 408 pl061_direction_output(&pl061->gc, offset,
409 chip->csave_regs.gpio_data & 409 pl061->csave_regs.gpio_data &
410 (BIT(offset))); 410 (BIT(offset)));
411 else 411 else
412 pl061_direction_input(&chip->gc, offset); 412 pl061_direction_input(&pl061->gc, offset);
413 } 413 }
414 414
415 writeb(chip->csave_regs.gpio_is, chip->base + GPIOIS); 415 writeb(pl061->csave_regs.gpio_is, pl061->base + GPIOIS);
416 writeb(chip->csave_regs.gpio_ibe, chip->base + GPIOIBE); 416 writeb(pl061->csave_regs.gpio_ibe, pl061->base + GPIOIBE);
417 writeb(chip->csave_regs.gpio_iev, chip->base + GPIOIEV); 417 writeb(pl061->csave_regs.gpio_iev, pl061->base + GPIOIEV);
418 writeb(chip->csave_regs.gpio_ie, chip->base + GPIOIE); 418 writeb(pl061->csave_regs.gpio_ie, pl061->base + GPIOIE);
419 419
420 return 0; 420 return 0;
421} 421}