]>
Commit | Line | Data |
---|---|---|
72edd84a LB |
1 | /* |
2 | * arch/arm/plat-iop/gpio.c | |
3 | * GPIO handling for Intel IOP3xx processors. | |
4 | * | |
5 | * Copyright (C) 2006 Lennert Buytenhek <[email protected]> | |
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, or (at | |
10 | * your option) any later version. | |
11 | */ | |
12 | ||
13 | #include <linux/device.h> | |
63f385cd AP |
14 | #include <linux/init.h> |
15 | #include <linux/types.h> | |
16 | #include <linux/errno.h> | |
17 | #include <linux/gpio.h> | |
dc28094b | 18 | #include <linux/export.h> |
7b85b867 | 19 | #include <linux/platform_device.h> |
e3f94b38 LW |
20 | #include <linux/bitops.h> |
21 | #include <linux/io.h> | |
f6ffa5ee LW |
22 | |
23 | #define IOP3XX_N_GPIOS 8 | |
72edd84a | 24 | |
7b85b867 LW |
25 | #define GPIO_IN 0 |
26 | #define GPIO_OUT 1 | |
27 | #define GPIO_LOW 0 | |
28 | #define GPIO_HIGH 1 | |
29 | ||
30 | /* Memory base offset */ | |
31 | static void __iomem *base; | |
32 | ||
33 | #define IOP3XX_GPIO_REG(reg) (base + (reg)) | |
e3f94b38 LW |
34 | #define IOP3XX_GPOE IOP3XX_GPIO_REG(0x0000) |
35 | #define IOP3XX_GPID IOP3XX_GPIO_REG(0x0004) | |
36 | #define IOP3XX_GPOD IOP3XX_GPIO_REG(0x0008) | |
7b85b867 | 37 | |
51a97d82 | 38 | static void gpio_line_config(int line, int direction) |
72edd84a LB |
39 | { |
40 | unsigned long flags; | |
e3f94b38 | 41 | u32 val; |
72edd84a LB |
42 | |
43 | local_irq_save(flags); | |
e3f94b38 | 44 | val = readl(IOP3XX_GPOE); |
72edd84a | 45 | if (direction == GPIO_IN) { |
e3f94b38 | 46 | val |= BIT(line); |
72edd84a | 47 | } else if (direction == GPIO_OUT) { |
e3f94b38 | 48 | val &= ~BIT(line); |
72edd84a | 49 | } |
e3f94b38 | 50 | writel(val, IOP3XX_GPOE); |
72edd84a LB |
51 | local_irq_restore(flags); |
52 | } | |
72edd84a | 53 | |
51a97d82 | 54 | static int gpio_line_get(int line) |
72edd84a | 55 | { |
e3f94b38 | 56 | return !!(readl(IOP3XX_GPID) & BIT(line)); |
72edd84a | 57 | } |
72edd84a | 58 | |
51a97d82 | 59 | static void gpio_line_set(int line, int value) |
72edd84a LB |
60 | { |
61 | unsigned long flags; | |
e3f94b38 | 62 | u32 val; |
72edd84a LB |
63 | |
64 | local_irq_save(flags); | |
e3f94b38 | 65 | val = readl(IOP3XX_GPOD); |
72edd84a | 66 | if (value == GPIO_LOW) { |
e3f94b38 | 67 | val &= ~BIT(line); |
72edd84a | 68 | } else if (value == GPIO_HIGH) { |
e3f94b38 | 69 | val |= BIT(line); |
72edd84a | 70 | } |
e3f94b38 | 71 | writel(val, IOP3XX_GPOD); |
72edd84a LB |
72 | local_irq_restore(flags); |
73 | } | |
63f385cd AP |
74 | |
75 | static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) | |
76 | { | |
77 | gpio_line_config(gpio, GPIO_IN); | |
78 | return 0; | |
79 | } | |
80 | ||
81 | static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level) | |
82 | { | |
83 | gpio_line_set(gpio, level); | |
84 | gpio_line_config(gpio, GPIO_OUT); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio) | |
89 | { | |
90 | return gpio_line_get(gpio); | |
91 | } | |
92 | ||
93 | static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value) | |
94 | { | |
95 | gpio_line_set(gpio, value); | |
96 | } | |
97 | ||
98 | static struct gpio_chip iop3xx_chip = { | |
99 | .label = "iop3xx", | |
100 | .direction_input = iop3xx_gpio_direction_input, | |
101 | .get = iop3xx_gpio_get_value, | |
102 | .direction_output = iop3xx_gpio_direction_output, | |
103 | .set = iop3xx_gpio_set_value, | |
104 | .base = 0, | |
105 | .ngpio = IOP3XX_N_GPIOS, | |
106 | }; | |
107 | ||
7b85b867 | 108 | static int iop3xx_gpio_probe(struct platform_device *pdev) |
63f385cd | 109 | { |
7b85b867 LW |
110 | struct resource *res; |
111 | ||
112 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
e34ca9de | 113 | base = devm_ioremap_resource(&pdev->dev, res); |
138d876e BZ |
114 | if (IS_ERR(base)) |
115 | return PTR_ERR(base); | |
7b85b867 | 116 | |
0c638759 | 117 | return devm_gpiochip_add_data(&pdev->dev, &iop3xx_chip, NULL); |
63f385cd | 118 | } |
7b85b867 LW |
119 | |
120 | static struct platform_driver iop3xx_gpio_driver = { | |
121 | .driver = { | |
122 | .name = "gpio-iop", | |
7b85b867 LW |
123 | }, |
124 | .probe = iop3xx_gpio_probe, | |
125 | }; | |
126 | ||
127 | static int __init iop3xx_gpio_init(void) | |
128 | { | |
129 | return platform_driver_register(&iop3xx_gpio_driver); | |
130 | } | |
131 | arch_initcall(iop3xx_gpio_init); |