blob: 42833ee2b308ba546b323823a6bc2d37e94481ba [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * GPIO Abstraction Layer
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Copyright 2006-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07005 *
Robin Getz96f10502009-09-24 14:11:24 +00006 * Licensed under the GPL-2 or later
Bryan Wu1394f032007-05-06 14:50:22 -07007 */
8
Mike Frysinger168f1212007-10-11 00:22:35 +08009#include <linux/delay.h>
Bryan Wu1394f032007-05-06 14:50:22 -070010#include <linux/module.h>
11#include <linux/err.h>
Mike Frysinger1545a112007-12-24 16:54:48 +080012#include <linux/proc_fs.h>
Bryan Wu1394f032007-05-06 14:50:22 -070013#include <asm/blackfin.h>
14#include <asm/gpio.h>
Michael Hennerichc58c2142007-10-04 00:35:05 +080015#include <asm/portmux.h>
Bryan Wu1394f032007-05-06 14:50:22 -070016#include <linux/irq.h>
17
Michael Hennerich2b393312007-10-10 16:58:49 +080018#if ANOMALY_05000311 || ANOMALY_05000323
19enum {
20 AWA_data = SYSCR,
21 AWA_data_clear = SYSCR,
22 AWA_data_set = SYSCR,
23 AWA_toggle = SYSCR,
Graf Yang6ed83942008-04-24 04:43:14 +080024 AWA_maska = BFIN_UART_SCR,
25 AWA_maska_clear = BFIN_UART_SCR,
26 AWA_maska_set = BFIN_UART_SCR,
27 AWA_maska_toggle = BFIN_UART_SCR,
28 AWA_maskb = BFIN_UART_GCTL,
29 AWA_maskb_clear = BFIN_UART_GCTL,
30 AWA_maskb_set = BFIN_UART_GCTL,
31 AWA_maskb_toggle = BFIN_UART_GCTL,
Michael Hennerich2b393312007-10-10 16:58:49 +080032 AWA_dir = SPORT1_STAT,
33 AWA_polar = SPORT1_STAT,
34 AWA_edge = SPORT1_STAT,
35 AWA_both = SPORT1_STAT,
36#if ANOMALY_05000311
37 AWA_inen = TIMER_ENABLE,
38#elif ANOMALY_05000323
39 AWA_inen = DMA1_1_CONFIG,
40#endif
41};
42 /* Anomaly Workaround */
43#define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
44#else
45#define AWA_DUMMY_READ(...) do { } while (0)
46#endif
47
Mike Frysingerf5563092009-02-04 16:49:45 +080048static struct gpio_port_t * const gpio_array[] = {
Michael Hennerichdc26aec2008-11-18 17:48:22 +080049#if defined(BF533_FAMILY) || defined(BF538_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -070050 (struct gpio_port_t *) FIO_FLAG_D,
Mike Frysinger269647d2009-03-28 20:32:57 +080051#elif defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Bryan Wu1394f032007-05-06 14:50:22 -070052 (struct gpio_port_t *) PORTFIO,
53 (struct gpio_port_t *) PORTGIO,
54 (struct gpio_port_t *) PORTHIO,
Mike Frysingerf5563092009-02-04 16:49:45 +080055#elif defined(BF561_FAMILY)
56 (struct gpio_port_t *) FIO0_FLAG_D,
57 (struct gpio_port_t *) FIO1_FLAG_D,
58 (struct gpio_port_t *) FIO2_FLAG_D,
Mike Frysinger269647d2009-03-28 20:32:57 +080059#elif defined(CONFIG_BF54x)
Mike Frysingerf5563092009-02-04 16:49:45 +080060 (struct gpio_port_t *)PORTA_FER,
61 (struct gpio_port_t *)PORTB_FER,
62 (struct gpio_port_t *)PORTC_FER,
63 (struct gpio_port_t *)PORTD_FER,
64 (struct gpio_port_t *)PORTE_FER,
65 (struct gpio_port_t *)PORTF_FER,
66 (struct gpio_port_t *)PORTG_FER,
67 (struct gpio_port_t *)PORTH_FER,
68 (struct gpio_port_t *)PORTI_FER,
69 (struct gpio_port_t *)PORTJ_FER,
70#else
71# error no gpio arrays defined
72#endif
Bryan Wu1394f032007-05-06 14:50:22 -070073};
74
Mike Frysinger269647d2009-03-28 20:32:57 +080075#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +080076static unsigned short * const port_fer[] = {
Bryan Wu1394f032007-05-06 14:50:22 -070077 (unsigned short *) PORTF_FER,
78 (unsigned short *) PORTG_FER,
79 (unsigned short *) PORTH_FER,
80};
Bryan Wu1394f032007-05-06 14:50:22 -070081
Mike Frysingerf5563092009-02-04 16:49:45 +080082# if !defined(BF537_FAMILY)
83static unsigned short * const port_mux[] = {
Michael Hennerich59003142007-10-21 16:54:27 +080084 (unsigned short *) PORTF_MUX,
85 (unsigned short *) PORTG_MUX,
86 (unsigned short *) PORTH_MUX,
87};
88
89static const
Graf Yang0ce5eaf2009-02-04 16:49:45 +080090u8 pmux_offset[][16] = {
Mike Frysinger269647d2009-03-28 20:32:57 +080091# if defined(CONFIG_BF52x)
Graf Yang0ce5eaf2009-02-04 16:49:45 +080092 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */
93 { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */
94 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */
Mike Frysinger269647d2009-03-28 20:32:57 +080095# elif defined(CONFIG_BF51x)
Graf Yang0ce5eaf2009-02-04 16:49:45 +080096 { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 }, /* PORTF */
97 { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 }, /* PORTG */
98 { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 }, /* PORTH */
99# endif
100};
Mike Frysingerf5563092009-02-04 16:49:45 +0800101# endif
Graf Yang0ce5eaf2009-02-04 16:49:45 +0800102
Michael Hennerich621dd242009-09-28 12:23:41 +0000103#elif defined(BF538_FAMILY)
104static unsigned short * const port_fer[] = {
105 (unsigned short *) PORTCIO_FER,
106 (unsigned short *) PORTDIO_FER,
107 (unsigned short *) PORTEIO_FER,
108};
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800109#endif
110
Bryan Wu397861c2008-11-18 17:48:22 +0800111static unsigned short reserved_gpio_map[GPIO_BANK_NUM];
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800112static unsigned short reserved_peri_map[gpio_bank(MAX_RESOURCES)];
Graf Yang9570ff42009-01-07 23:14:38 +0800113static unsigned short reserved_gpio_irq_map[GPIO_BANK_NUM];
Michael Hennerichc58c2142007-10-04 00:35:05 +0800114
Michael Hennerich8c613622007-08-03 17:48:09 +0800115#define RESOURCE_LABEL_SIZE 16
116
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800117static struct str_ident {
Michael Hennerich8c613622007-08-03 17:48:09 +0800118 char name[RESOURCE_LABEL_SIZE];
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800119} str_ident[MAX_RESOURCES];
Bryan Wu1394f032007-05-06 14:50:22 -0700120
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800121#if defined(CONFIG_PM)
Bryan Wu397861c2008-11-18 17:48:22 +0800122static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM];
Bryan Wu1394f032007-05-06 14:50:22 -0700123#endif
124
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800125inline int check_gpio(unsigned gpio)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800126{
Mike Frysinger269647d2009-03-28 20:32:57 +0800127#if defined(CONFIG_BF54x)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800128 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
129 || gpio == GPIO_PH14 || gpio == GPIO_PH15
Mike Frysinger27228b22008-10-28 15:45:42 +0800130 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800131 return -EINVAL;
Mike Frysinger27228b22008-10-28 15:45:42 +0800132#endif
Michael Henneriche7613aa2007-06-11 16:37:57 +0800133 if (gpio >= MAX_BLACKFIN_GPIOS)
Bryan Wu1394f032007-05-06 14:50:22 -0700134 return -EINVAL;
135 return 0;
136}
137
Mike Frysinger74c04502008-10-08 16:13:17 +0800138static void gpio_error(unsigned gpio)
Michael Hennerichacbcd262008-01-22 18:36:20 +0800139{
140 printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio);
141}
142
Michael Hennerichc58c2142007-10-04 00:35:05 +0800143static void set_label(unsigned short ident, const char *label)
144{
Michael Henneriche9fae182008-10-13 11:35:22 +0800145 if (label) {
Michael Hennerich8c613622007-08-03 17:48:09 +0800146 strncpy(str_ident[ident].name, label,
Michael Hennerichc58c2142007-10-04 00:35:05 +0800147 RESOURCE_LABEL_SIZE);
Michael Hennerich8c613622007-08-03 17:48:09 +0800148 str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800149 }
150}
151
152static char *get_label(unsigned short ident)
153{
Michael Hennerich8c613622007-08-03 17:48:09 +0800154 return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN");
Michael Hennerichc58c2142007-10-04 00:35:05 +0800155}
156
157static int cmp_label(unsigned short ident, const char *label)
158{
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800159 if (label == NULL) {
160 dump_stack();
161 printk(KERN_ERR "Please provide none-null label\n");
162 }
163
Michael Henneriche9fae182008-10-13 11:35:22 +0800164 if (label)
Mike Frysinger1f7d3732008-10-28 15:47:11 +0800165 return strcmp(str_ident[ident].name, label);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800166 else
167 return -EINVAL;
168}
169
Mike Frysingera2d03a12008-10-28 15:53:37 +0800170static void port_setup(unsigned gpio, unsigned short usage)
171{
Michael Hennerich621dd242009-09-28 12:23:41 +0000172#if defined(BF538_FAMILY)
173 /*
174 * BF538/9 Port C,D and E are special.
175 * Inverted PORT_FER polarity on CDE and no PORF_FER on F
176 * Regular PORT F GPIOs are handled here, CDE are exclusively
177 * managed by GPIOLIB
178 */
179
180 if (gpio < MAX_BLACKFIN_GPIOS || gpio >= MAX_RESOURCES)
181 return;
182
183 gpio -= MAX_BLACKFIN_GPIOS;
184
185 if (usage == GPIO_USAGE)
186 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
187 else
188 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
189 SSYNC();
190 return;
191#endif
192
Mike Frysingera2d03a12008-10-28 15:53:37 +0800193 if (check_gpio(gpio))
194 return;
195
Mike Frysinger269647d2009-03-28 20:32:57 +0800196#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Mike Frysingera2d03a12008-10-28 15:53:37 +0800197 if (usage == GPIO_USAGE)
198 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
199 else
200 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
201 SSYNC();
Mike Frysinger269647d2009-03-28 20:32:57 +0800202#elif defined(CONFIG_BF54x)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800203 if (usage == GPIO_USAGE)
204 gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
205 else
206 gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
207 SSYNC();
Bryan Wu1394f032007-05-06 14:50:22 -0700208#endif
Mike Frysingera2d03a12008-10-28 15:53:37 +0800209}
Bryan Wu1394f032007-05-06 14:50:22 -0700210
Michael Hennerichc58c2142007-10-04 00:35:05 +0800211#ifdef BF537_FAMILY
Michael Hennerich8c613622007-08-03 17:48:09 +0800212static struct {
213 unsigned short res;
214 unsigned short offset;
215} port_mux_lut[] = {
216 {.res = P_PPI0_D13, .offset = 11},
217 {.res = P_PPI0_D14, .offset = 11},
218 {.res = P_PPI0_D15, .offset = 11},
219 {.res = P_SPORT1_TFS, .offset = 11},
220 {.res = P_SPORT1_TSCLK, .offset = 11},
221 {.res = P_SPORT1_DTPRI, .offset = 11},
222 {.res = P_PPI0_D10, .offset = 10},
223 {.res = P_PPI0_D11, .offset = 10},
224 {.res = P_PPI0_D12, .offset = 10},
225 {.res = P_SPORT1_RSCLK, .offset = 10},
226 {.res = P_SPORT1_RFS, .offset = 10},
227 {.res = P_SPORT1_DRPRI, .offset = 10},
228 {.res = P_PPI0_D8, .offset = 9},
229 {.res = P_PPI0_D9, .offset = 9},
230 {.res = P_SPORT1_DRSEC, .offset = 9},
231 {.res = P_SPORT1_DTSEC, .offset = 9},
232 {.res = P_TMR2, .offset = 8},
233 {.res = P_PPI0_FS3, .offset = 8},
234 {.res = P_TMR3, .offset = 7},
235 {.res = P_SPI0_SSEL4, .offset = 7},
236 {.res = P_TMR4, .offset = 6},
237 {.res = P_SPI0_SSEL5, .offset = 6},
238 {.res = P_TMR5, .offset = 5},
239 {.res = P_SPI0_SSEL6, .offset = 5},
240 {.res = P_UART1_RX, .offset = 4},
241 {.res = P_UART1_TX, .offset = 4},
242 {.res = P_TMR6, .offset = 4},
243 {.res = P_TMR7, .offset = 4},
244 {.res = P_UART0_RX, .offset = 3},
245 {.res = P_UART0_TX, .offset = 3},
246 {.res = P_DMAR0, .offset = 3},
247 {.res = P_DMAR1, .offset = 3},
248 {.res = P_SPORT0_DTSEC, .offset = 1},
249 {.res = P_SPORT0_DRSEC, .offset = 1},
250 {.res = P_CAN0_RX, .offset = 1},
251 {.res = P_CAN0_TX, .offset = 1},
252 {.res = P_SPI0_SSEL7, .offset = 1},
253 {.res = P_SPORT0_TFS, .offset = 0},
254 {.res = P_SPORT0_DTPRI, .offset = 0},
255 {.res = P_SPI0_SSEL2, .offset = 0},
256 {.res = P_SPI0_SSEL3, .offset = 0},
Michael Hennerichc58c2142007-10-04 00:35:05 +0800257};
258
Mike Frysingerf5563092009-02-04 16:49:45 +0800259static void portmux_setup(unsigned short per)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800260{
Michael Hennerich8c613622007-08-03 17:48:09 +0800261 u16 y, offset, muxreg;
Mike Frysingerf5563092009-02-04 16:49:45 +0800262 u16 function = P_FUNCT2MUX(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800263
Michael Hennerich8c613622007-08-03 17:48:09 +0800264 for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
265 if (port_mux_lut[y].res == per) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800266
267 /* SET PORTMUX REG */
268
Michael Hennerich8c613622007-08-03 17:48:09 +0800269 offset = port_mux_lut[y].offset;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800270 muxreg = bfin_read_PORT_MUX();
271
Mike Frysingerd171c232008-03-26 08:35:46 +0800272 if (offset != 1)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800273 muxreg &= ~(1 << offset);
Mike Frysingerd171c232008-03-26 08:35:46 +0800274 else
Michael Hennerichc58c2142007-10-04 00:35:05 +0800275 muxreg &= ~(3 << 1);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800276
277 muxreg |= (function << offset);
278 bfin_write_PORT_MUX(muxreg);
279 }
280 }
281}
Mike Frysinger269647d2009-03-28 20:32:57 +0800282#elif defined(CONFIG_BF54x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800283inline void portmux_setup(unsigned short per)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800284{
285 u32 pmux;
Mike Frysingerf5563092009-02-04 16:49:45 +0800286 u16 ident = P_IDENT(per);
287 u16 function = P_FUNCT2MUX(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800288
Mike Frysingerf5563092009-02-04 16:49:45 +0800289 pmux = gpio_array[gpio_bank(ident)]->port_mux;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800290
Mike Frysingerf5563092009-02-04 16:49:45 +0800291 pmux &= ~(0x3 << (2 * gpio_sub_n(ident)));
292 pmux |= (function & 0x3) << (2 * gpio_sub_n(ident));
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800293
Mike Frysingerf5563092009-02-04 16:49:45 +0800294 gpio_array[gpio_bank(ident)]->port_mux = pmux;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800295}
296
Mike Frysingerf5563092009-02-04 16:49:45 +0800297inline u16 get_portmux(unsigned short per)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800298{
299 u32 pmux;
Mike Frysingerf5563092009-02-04 16:49:45 +0800300 u16 ident = P_IDENT(per);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800301
Mike Frysingerf5563092009-02-04 16:49:45 +0800302 pmux = gpio_array[gpio_bank(ident)]->port_mux;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800303
Mike Frysingerf5563092009-02-04 16:49:45 +0800304 return (pmux >> (2 * gpio_sub_n(ident)) & 0x3);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800305}
Mike Frysinger269647d2009-03-28 20:32:57 +0800306#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800307inline void portmux_setup(unsigned short per)
Michael Hennerich59003142007-10-21 16:54:27 +0800308{
Mike Frysingerf5563092009-02-04 16:49:45 +0800309 u16 pmux, ident = P_IDENT(per), function = P_FUNCT2MUX(per);
Michael Hennerich59003142007-10-21 16:54:27 +0800310 u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)];
311
312 pmux = *port_mux[gpio_bank(ident)];
313 pmux &= ~(3 << offset);
314 pmux |= (function & 3) << offset;
315 *port_mux[gpio_bank(ident)] = pmux;
316 SSYNC();
317}
Michael Hennerichc58c2142007-10-04 00:35:05 +0800318#else
319# define portmux_setup(...) do { } while (0)
320#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700321
Mike Frysinger269647d2009-03-28 20:32:57 +0800322#ifndef CONFIG_BF54x
Bryan Wu1394f032007-05-06 14:50:22 -0700323/***********************************************************
324*
325* FUNCTIONS: Blackfin General Purpose Ports Access Functions
326*
327* INPUTS/OUTPUTS:
328* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
329*
330*
331* DESCRIPTION: These functions abstract direct register access
332* to Blackfin processor General Purpose
333* Ports Regsiters
334*
335* CAUTION: These functions do not belong to the GPIO Driver API
336*************************************************************
337* MODIFICATION HISTORY :
338**************************************************************/
339
340/* Set a specific bit */
341
342#define SET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800343void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700344{ \
345 unsigned long flags; \
Yi Li6a01f232009-01-07 23:14:39 +0800346 local_irq_save_hw(flags); \
Bryan Wu1394f032007-05-06 14:50:22 -0700347 if (arg) \
Mike Frysingerf5563092009-02-04 16:49:45 +0800348 gpio_array[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
Bryan Wu1394f032007-05-06 14:50:22 -0700349 else \
Mike Frysingerf5563092009-02-04 16:49:45 +0800350 gpio_array[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800351 AWA_DUMMY_READ(name); \
Yi Li6a01f232009-01-07 23:14:39 +0800352 local_irq_restore_hw(flags); \
Bryan Wu1394f032007-05-06 14:50:22 -0700353} \
354EXPORT_SYMBOL(set_gpio_ ## name);
355
Mike Frysingerf5563092009-02-04 16:49:45 +0800356SET_GPIO(dir) /* set_gpio_dir() */
357SET_GPIO(inen) /* set_gpio_inen() */
358SET_GPIO(polar) /* set_gpio_polar() */
359SET_GPIO(edge) /* set_gpio_edge() */
360SET_GPIO(both) /* set_gpio_both() */
Bryan Wu1394f032007-05-06 14:50:22 -0700361
362
Michael Hennerich2b393312007-10-10 16:58:49 +0800363#define SET_GPIO_SC(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800364void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800365{ \
366 unsigned long flags; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800367 if (ANOMALY_05000311 || ANOMALY_05000323) \
368 local_irq_save_hw(flags); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800369 if (arg) \
Mike Frysingerf5563092009-02-04 16:49:45 +0800370 gpio_array[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800371 else \
Mike Frysingerf5563092009-02-04 16:49:45 +0800372 gpio_array[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
373 if (ANOMALY_05000311 || ANOMALY_05000323) { \
374 AWA_DUMMY_READ(name); \
375 local_irq_restore_hw(flags); \
376 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800377} \
378EXPORT_SYMBOL(set_gpio_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700379
380SET_GPIO_SC(maska)
381SET_GPIO_SC(maskb)
Bryan Wu1394f032007-05-06 14:50:22 -0700382SET_GPIO_SC(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700383
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800384void set_gpio_toggle(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700385{
386 unsigned long flags;
Mike Frysingerf5563092009-02-04 16:49:45 +0800387 if (ANOMALY_05000311 || ANOMALY_05000323)
388 local_irq_save_hw(flags);
389 gpio_array[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
390 if (ANOMALY_05000311 || ANOMALY_05000323) {
391 AWA_DUMMY_READ(toggle);
392 local_irq_restore_hw(flags);
393 }
Bryan Wu1394f032007-05-06 14:50:22 -0700394}
Bryan Wu1394f032007-05-06 14:50:22 -0700395EXPORT_SYMBOL(set_gpio_toggle);
396
397
398/*Set current PORT date (16-bit word)*/
399
Michael Hennerich2b393312007-10-10 16:58:49 +0800400#define SET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800401void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800402{ \
403 unsigned long flags; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800404 if (ANOMALY_05000311 || ANOMALY_05000323) \
405 local_irq_save_hw(flags); \
406 gpio_array[gpio_bank(gpio)]->name = arg; \
407 if (ANOMALY_05000311 || ANOMALY_05000323) { \
408 AWA_DUMMY_READ(name); \
409 local_irq_restore_hw(flags); \
410 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800411} \
412EXPORT_SYMBOL(set_gpiop_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700413
Michael Hennerich2b393312007-10-10 16:58:49 +0800414SET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700415SET_GPIO_P(dir)
416SET_GPIO_P(inen)
417SET_GPIO_P(polar)
418SET_GPIO_P(edge)
419SET_GPIO_P(both)
420SET_GPIO_P(maska)
421SET_GPIO_P(maskb)
422
Bryan Wu1394f032007-05-06 14:50:22 -0700423/* Get a specific bit */
Michael Hennerich2b393312007-10-10 16:58:49 +0800424#define GET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800425unsigned short get_gpio_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800426{ \
427 unsigned long flags; \
428 unsigned short ret; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800429 if (ANOMALY_05000311 || ANOMALY_05000323) \
430 local_irq_save_hw(flags); \
431 ret = 0x01 & (gpio_array[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
432 if (ANOMALY_05000311 || ANOMALY_05000323) { \
433 AWA_DUMMY_READ(name); \
434 local_irq_restore_hw(flags); \
435 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800436 return ret; \
437} \
438EXPORT_SYMBOL(get_gpio_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700439
Michael Hennerich2b393312007-10-10 16:58:49 +0800440GET_GPIO(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700441GET_GPIO(dir)
442GET_GPIO(inen)
443GET_GPIO(polar)
444GET_GPIO(edge)
445GET_GPIO(both)
446GET_GPIO(maska)
447GET_GPIO(maskb)
448
Bryan Wu1394f032007-05-06 14:50:22 -0700449/*Get current PORT date (16-bit word)*/
450
Michael Hennerich2b393312007-10-10 16:58:49 +0800451#define GET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800452unsigned short get_gpiop_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800453{ \
454 unsigned long flags; \
455 unsigned short ret; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800456 if (ANOMALY_05000311 || ANOMALY_05000323) \
457 local_irq_save_hw(flags); \
458 ret = (gpio_array[gpio_bank(gpio)]->name); \
459 if (ANOMALY_05000311 || ANOMALY_05000323) { \
460 AWA_DUMMY_READ(name); \
461 local_irq_restore_hw(flags); \
462 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800463 return ret; \
464} \
465EXPORT_SYMBOL(get_gpiop_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700466
Michael Hennerich2b393312007-10-10 16:58:49 +0800467GET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700468GET_GPIO_P(dir)
469GET_GPIO_P(inen)
470GET_GPIO_P(polar)
471GET_GPIO_P(edge)
472GET_GPIO_P(both)
473GET_GPIO_P(maska)
474GET_GPIO_P(maskb)
475
Bryan Wu1394f032007-05-06 14:50:22 -0700476
477#ifdef CONFIG_PM
Mike Frysingerf5563092009-02-04 16:49:45 +0800478static unsigned short wakeup_map[GPIO_BANK_NUM];
Mike Frysingerf5563092009-02-04 16:49:45 +0800479
480static const unsigned int sic_iwr_irqs[] = {
481#if defined(BF533_FAMILY)
482 IRQ_PROG_INTB
483#elif defined(BF537_FAMILY)
484 IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX
485#elif defined(BF538_FAMILY)
486 IRQ_PORTF_INTB
Mike Frysinger269647d2009-03-28 20:32:57 +0800487#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800488 IRQ_PORTF_INTB, IRQ_PORTG_INTB, IRQ_PORTH_INTB
489#elif defined(BF561_FAMILY)
490 IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB
491#else
492# error no SIC_IWR defined
493#endif
494};
495
Bryan Wu1394f032007-05-06 14:50:22 -0700496/***********************************************************
497*
498* FUNCTIONS: Blackfin PM Setup API
499*
500* INPUTS/OUTPUTS:
501* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
502* type -
503* PM_WAKE_RISING
504* PM_WAKE_FALLING
505* PM_WAKE_HIGH
506* PM_WAKE_LOW
507* PM_WAKE_BOTH_EDGES
508*
509* DESCRIPTION: Blackfin PM Driver API
510*
511* CAUTION:
512*************************************************************
513* MODIFICATION HISTORY :
514**************************************************************/
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000515int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl)
Bryan Wu1394f032007-05-06 14:50:22 -0700516{
517 unsigned long flags;
518
519 if (check_gpio(gpio) < 0)
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000520 return -EINVAL;
Bryan Wu1394f032007-05-06 14:50:22 -0700521
Yi Li6a01f232009-01-07 23:14:39 +0800522 local_irq_save_hw(flags);
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000523 if (ctrl)
524 wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio);
525 else
526 wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -0700527
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000528 set_gpio_maskb(gpio, ctrl);
Yi Li6a01f232009-01-07 23:14:39 +0800529 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700530
531 return 0;
532}
533
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000534int bfin_pm_standby_ctrl(unsigned ctrl)
Bryan Wu1394f032007-05-06 14:50:22 -0700535{
536 u16 bank, mask, i;
537
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800538 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Bryan Wu1394f032007-05-06 14:50:22 -0700539 mask = wakeup_map[gpio_bank(i)];
540 bank = gpio_bank(i);
541
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000542 if (mask)
543 bfin_internal_set_wake(sic_iwr_irqs[bank], ctrl);
Bryan Wu1394f032007-05-06 14:50:22 -0700544 }
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000545 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700546}
547
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800548void bfin_gpio_pm_hibernate_suspend(void)
549{
550 int i, bank;
551
552 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
553 bank = gpio_bank(i);
554
Mike Frysinger269647d2009-03-28 20:32:57 +0800555#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800556 gpio_bank_saved[bank].fer = *port_fer[bank];
Mike Frysinger269647d2009-03-28 20:32:57 +0800557#if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800558 gpio_bank_saved[bank].mux = *port_mux[bank];
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800559#else
Mike Frysingerf5563092009-02-04 16:49:45 +0800560 if (bank == 0)
561 gpio_bank_saved[bank].mux = bfin_read_PORT_MUX();
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800562#endif
563#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800564 gpio_bank_saved[bank].data = gpio_array[bank]->data;
565 gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
566 gpio_bank_saved[bank].polar = gpio_array[bank]->polar;
567 gpio_bank_saved[bank].dir = gpio_array[bank]->dir;
568 gpio_bank_saved[bank].edge = gpio_array[bank]->edge;
569 gpio_bank_saved[bank].both = gpio_array[bank]->both;
570 gpio_bank_saved[bank].maska = gpio_array[bank]->maska;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800571 }
572
573 AWA_DUMMY_READ(maska);
574}
575
576void bfin_gpio_pm_hibernate_restore(void)
577{
578 int i, bank;
579
580 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Mike Frysingerf5563092009-02-04 16:49:45 +0800581 bank = gpio_bank(i);
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800582
Mike Frysinger269647d2009-03-28 20:32:57 +0800583#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
584#if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800585 *port_mux[bank] = gpio_bank_saved[bank].mux;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800586#else
Mike Frysingerf5563092009-02-04 16:49:45 +0800587 if (bank == 0)
588 bfin_write_PORT_MUX(gpio_bank_saved[bank].mux);
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800589#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800590 *port_fer[bank] = gpio_bank_saved[bank].fer;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800591#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800592 gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
Michael Hennerichc03c2a82009-07-08 12:04:43 +0000593 gpio_array[bank]->data_set = gpio_bank_saved[bank].data
594 & gpio_bank_saved[bank].dir;
Mike Frysingerf5563092009-02-04 16:49:45 +0800595 gpio_array[bank]->dir = gpio_bank_saved[bank].dir;
596 gpio_array[bank]->polar = gpio_bank_saved[bank].polar;
597 gpio_array[bank]->edge = gpio_bank_saved[bank].edge;
598 gpio_array[bank]->both = gpio_bank_saved[bank].both;
Mike Frysingerf5563092009-02-04 16:49:45 +0800599 gpio_array[bank]->maska = gpio_bank_saved[bank].maska;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800600 }
601 AWA_DUMMY_READ(maska);
602}
603
604
Bryan Wu1394f032007-05-06 14:50:22 -0700605#endif
Mike Frysinger269647d2009-03-28 20:32:57 +0800606#else /* CONFIG_BF54x */
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800607#ifdef CONFIG_PM
608
Michael Hennerichbb84dbf2010-03-10 14:26:06 +0000609int bfin_pm_standby_ctrl(unsigned ctrl)
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800610{
611 return 0;
612}
613
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800614void bfin_gpio_pm_hibernate_suspend(void)
615{
616 int i, bank;
617
618 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
619 bank = gpio_bank(i);
620
Mike Frysingerf5563092009-02-04 16:49:45 +0800621 gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer;
622 gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux;
623 gpio_bank_saved[bank].data = gpio_array[bank]->data;
Mike Frysingerf5563092009-02-04 16:49:45 +0800624 gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
625 gpio_bank_saved[bank].dir = gpio_array[bank]->dir_set;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800626 }
627}
628
629void bfin_gpio_pm_hibernate_restore(void)
630{
631 int i, bank;
632
633 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Mike Frysingerf5563092009-02-04 16:49:45 +0800634 bank = gpio_bank(i);
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800635
Mike Frysingerf5563092009-02-04 16:49:45 +0800636 gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux;
637 gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer;
638 gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
639 gpio_array[bank]->dir_set = gpio_bank_saved[bank].dir;
640 gpio_array[bank]->data_set = gpio_bank_saved[bank].data
641 | gpio_bank_saved[bank].dir;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800642 }
643}
644#endif
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800645
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800646unsigned short get_gpio_dir(unsigned gpio)
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800647{
Mike Frysingerf5563092009-02-04 16:49:45 +0800648 return (0x01 & (gpio_array[gpio_bank(gpio)]->dir_clear >> gpio_sub_n(gpio)));
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800649}
650EXPORT_SYMBOL(get_gpio_dir);
651
Mike Frysinger269647d2009-03-28 20:32:57 +0800652#endif /* CONFIG_BF54x */
Bryan Wu1394f032007-05-06 14:50:22 -0700653
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800654/***********************************************************
655*
656* FUNCTIONS: Blackfin Peripheral Resource Allocation
657* and PortMux Setup
658*
659* INPUTS/OUTPUTS:
660* per Peripheral Identifier
661* label String
662*
663* DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API
664*
665* CAUTION:
666*************************************************************
667* MODIFICATION HISTORY :
668**************************************************************/
Michael Hennerichc58c2142007-10-04 00:35:05 +0800669
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800670int peripheral_request(unsigned short per, const char *label)
671{
672 unsigned long flags;
673 unsigned short ident = P_IDENT(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800674
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800675 /*
676 * Don't cares are pins with only one dedicated function
677 */
678
679 if (per & P_DONTCARE)
680 return 0;
681
682 if (!(per & P_DEFINED))
683 return -ENODEV;
684
Barry Song89e84ee2009-09-16 04:36:29 +0000685 BUG_ON(ident >= MAX_RESOURCES);
686
Yi Li6a01f232009-01-07 23:14:39 +0800687 local_irq_save_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800688
Mike Frysinger6a87d292008-10-28 16:16:29 +0800689 /* If a pin can be muxed as either GPIO or peripheral, make
690 * sure it is not already a GPIO pin when we request it.
691 */
692 if (unlikely(!check_gpio(ident) &&
693 reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800694 if (system_state == SYSTEM_BOOTING)
695 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800696 printk(KERN_ERR
Mike Frysinger6c7ec0e2008-10-28 15:49:59 +0800697 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800698 __func__, ident, get_label(ident));
Yi Li6a01f232009-01-07 23:14:39 +0800699 local_irq_restore_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800700 return -EBUSY;
701 }
702
703 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
704
Mike Frysingerd171c232008-03-26 08:35:46 +0800705 /*
706 * Pin functions like AMC address strobes my
707 * be requested and used by several drivers
708 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800709
Mike Frysinger269647d2009-03-28 20:32:57 +0800710#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +0800711 if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) {
Mike Frysinger6c7ec0e2008-10-28 15:49:59 +0800712#else
713 if (!(per & P_MAYSHARE)) {
714#endif
Mike Frysingerd171c232008-03-26 08:35:46 +0800715 /*
716 * Allow that the identical pin function can
717 * be requested from the same driver twice
718 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800719
Mike Frysingerd171c232008-03-26 08:35:46 +0800720 if (cmp_label(ident, label) == 0)
721 goto anyway;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800722
Robin Getzd6879c52009-03-29 01:10:30 +0800723 if (system_state == SYSTEM_BOOTING)
724 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800725 printk(KERN_ERR
726 "%s: Peripheral %d function %d is already reserved by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800727 __func__, ident, P_FUNCT2MUX(per), get_label(ident));
Yi Li6a01f232009-01-07 23:14:39 +0800728 local_irq_restore_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800729 return -EBUSY;
730 }
731 }
732
Mike Frysingerd171c232008-03-26 08:35:46 +0800733 anyway:
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800734 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
735
Mike Frysingerf5563092009-02-04 16:49:45 +0800736 portmux_setup(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800737 port_setup(ident, PERIPHERAL_USAGE);
738
Yi Li6a01f232009-01-07 23:14:39 +0800739 local_irq_restore_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800740 set_label(ident, label);
741
742 return 0;
743}
744EXPORT_SYMBOL(peripheral_request);
745
Mike Frysinger68179372008-04-24 05:04:24 +0800746int peripheral_request_list(const unsigned short per[], const char *label)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800747{
748 u16 cnt;
749 int ret;
750
751 for (cnt = 0; per[cnt] != 0; cnt++) {
Michael Hennerich314c98d2007-07-24 18:03:45 +0800752
Michael Hennerichc58c2142007-10-04 00:35:05 +0800753 ret = peripheral_request(per[cnt], label);
Michael Hennerich314c98d2007-07-24 18:03:45 +0800754
755 if (ret < 0) {
Mike Frysingerd171c232008-03-26 08:35:46 +0800756 for ( ; cnt > 0; cnt--)
Michael Hennerich314c98d2007-07-24 18:03:45 +0800757 peripheral_free(per[cnt - 1]);
Mike Frysingerd171c232008-03-26 08:35:46 +0800758
759 return ret;
Michael Hennerich314c98d2007-07-24 18:03:45 +0800760 }
Michael Hennerichc58c2142007-10-04 00:35:05 +0800761 }
762
763 return 0;
764}
765EXPORT_SYMBOL(peripheral_request_list);
766
767void peripheral_free(unsigned short per)
768{
769 unsigned long flags;
770 unsigned short ident = P_IDENT(per);
771
772 if (per & P_DONTCARE)
773 return;
774
775 if (!(per & P_DEFINED))
776 return;
777
Yi Li6a01f232009-01-07 23:14:39 +0800778 local_irq_save_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800779
Mike Frysingerd171c232008-03-26 08:35:46 +0800780 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
Yi Li6a01f232009-01-07 23:14:39 +0800781 local_irq_restore_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800782 return;
783 }
784
Mike Frysingerd171c232008-03-26 08:35:46 +0800785 if (!(per & P_MAYSHARE))
Michael Hennerichc58c2142007-10-04 00:35:05 +0800786 port_setup(ident, GPIO_USAGE);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800787
788 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
789
Michael Hennerich2acde902007-10-11 00:24:40 +0800790 set_label(ident, "free");
791
Yi Li6a01f232009-01-07 23:14:39 +0800792 local_irq_restore_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800793}
794EXPORT_SYMBOL(peripheral_free);
795
Mike Frysinger68179372008-04-24 05:04:24 +0800796void peripheral_free_list(const unsigned short per[])
Michael Hennerichc58c2142007-10-04 00:35:05 +0800797{
798 u16 cnt;
Mike Frysingerd171c232008-03-26 08:35:46 +0800799 for (cnt = 0; per[cnt] != 0; cnt++)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800800 peripheral_free(per[cnt]);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800801}
802EXPORT_SYMBOL(peripheral_free_list);
803
Bryan Wu1394f032007-05-06 14:50:22 -0700804/***********************************************************
805*
806* FUNCTIONS: Blackfin GPIO Driver
807*
808* INPUTS/OUTPUTS:
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800809* gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
810* label String
Bryan Wu1394f032007-05-06 14:50:22 -0700811*
812* DESCRIPTION: Blackfin GPIO Driver API
813*
814* CAUTION:
815*************************************************************
816* MODIFICATION HISTORY :
817**************************************************************/
818
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800819int bfin_gpio_request(unsigned gpio, const char *label)
Bryan Wu1394f032007-05-06 14:50:22 -0700820{
821 unsigned long flags;
822
823 if (check_gpio(gpio) < 0)
824 return -EINVAL;
825
Yi Li6a01f232009-01-07 23:14:39 +0800826 local_irq_save_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700827
Michael Hennerich2acde902007-10-11 00:24:40 +0800828 /*
829 * Allow that the identical GPIO can
830 * be requested from the same driver twice
831 * Do nothing and return -
832 */
833
834 if (cmp_label(gpio, label) == 0) {
Yi Li6a01f232009-01-07 23:14:39 +0800835 local_irq_restore_hw(flags);
Michael Hennerich2acde902007-10-11 00:24:40 +0800836 return 0;
837 }
838
Michael Hennerichc58c2142007-10-04 00:35:05 +0800839 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800840 if (system_state == SYSTEM_BOOTING)
841 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800842 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
Graf Yang9570ff42009-01-07 23:14:38 +0800843 gpio, get_label(gpio));
Yi Li6a01f232009-01-07 23:14:39 +0800844 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700845 return -EBUSY;
846 }
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800847 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800848 if (system_state == SYSTEM_BOOTING)
849 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800850 printk(KERN_ERR
851 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
852 gpio, get_label(gpio));
Yi Li6a01f232009-01-07 23:14:39 +0800853 local_irq_restore_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800854 return -EBUSY;
855 }
Michael Hennericha2be3932009-02-04 16:49:45 +0800856 if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Graf Yang9570ff42009-01-07 23:14:38 +0800857 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!"
858 " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio);
Michael Hennericha2be3932009-02-04 16:49:45 +0800859 }
Mike Frysinger269647d2009-03-28 20:32:57 +0800860#ifndef CONFIG_BF54x
Michael Hennericha2be3932009-02-04 16:49:45 +0800861 else { /* Reset POLAR setting when acquiring a gpio for the first time */
862 set_gpio_polar(gpio, 0);
863 }
864#endif
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800865
Michael Hennerichc58c2142007-10-04 00:35:05 +0800866 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
Graf Yang9570ff42009-01-07 23:14:38 +0800867 set_label(gpio, label);
Bryan Wu1394f032007-05-06 14:50:22 -0700868
Yi Li6a01f232009-01-07 23:14:39 +0800869 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700870
871 port_setup(gpio, GPIO_USAGE);
872
873 return 0;
874}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800875EXPORT_SYMBOL(bfin_gpio_request);
Bryan Wu1394f032007-05-06 14:50:22 -0700876
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800877void bfin_gpio_free(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700878{
879 unsigned long flags;
880
881 if (check_gpio(gpio) < 0)
882 return;
883
Uwe Kleine-Koenig45c4f2a2009-02-04 17:02:30 +0800884 might_sleep();
885
Yi Li6a01f232009-01-07 23:14:39 +0800886 local_irq_save_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700887
Michael Hennerichc58c2142007-10-04 00:35:05 +0800888 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800889 if (system_state == SYSTEM_BOOTING)
890 dump_stack();
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800891 gpio_error(gpio);
Yi Li6a01f232009-01-07 23:14:39 +0800892 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700893 return;
894 }
895
Michael Hennerichc58c2142007-10-04 00:35:05 +0800896 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -0700897
Michael Hennerich2acde902007-10-11 00:24:40 +0800898 set_label(gpio, "free");
899
Yi Li6a01f232009-01-07 23:14:39 +0800900 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700901}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800902EXPORT_SYMBOL(bfin_gpio_free);
Bryan Wu1394f032007-05-06 14:50:22 -0700903
Michael Hennerich621dd242009-09-28 12:23:41 +0000904#ifdef BFIN_SPECIAL_GPIO_BANKS
905static unsigned short reserved_special_gpio_map[gpio_bank(MAX_RESOURCES)];
906
907int bfin_special_gpio_request(unsigned gpio, const char *label)
908{
909 unsigned long flags;
910
911 local_irq_save_hw(flags);
912
913 /*
914 * Allow that the identical GPIO can
915 * be requested from the same driver twice
916 * Do nothing and return -
917 */
918
919 if (cmp_label(gpio, label) == 0) {
920 local_irq_restore_hw(flags);
921 return 0;
922 }
923
924 if (unlikely(reserved_special_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
925 local_irq_restore_hw(flags);
926 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
927 gpio, get_label(gpio));
928
929 return -EBUSY;
930 }
931 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
932 local_irq_restore_hw(flags);
933 printk(KERN_ERR
934 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
935 gpio, get_label(gpio));
936
937 return -EBUSY;
938 }
939
940 reserved_special_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
941 reserved_peri_map[gpio_bank(gpio)] |= gpio_bit(gpio);
942
943 set_label(gpio, label);
944 local_irq_restore_hw(flags);
945 port_setup(gpio, GPIO_USAGE);
946
947 return 0;
948}
949EXPORT_SYMBOL(bfin_special_gpio_request);
950
951void bfin_special_gpio_free(unsigned gpio)
952{
953 unsigned long flags;
954
955 might_sleep();
956
957 local_irq_save_hw(flags);
958
959 if (unlikely(!(reserved_special_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
960 gpio_error(gpio);
961 local_irq_restore_hw(flags);
962 return;
963 }
964
965 reserved_special_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
966 reserved_peri_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
967 set_label(gpio, "free");
968 local_irq_restore_hw(flags);
969}
970EXPORT_SYMBOL(bfin_special_gpio_free);
971#endif
972
973
Graf Yang9570ff42009-01-07 23:14:38 +0800974int bfin_gpio_irq_request(unsigned gpio, const char *label)
975{
976 unsigned long flags;
977
978 if (check_gpio(gpio) < 0)
979 return -EINVAL;
980
Yi Li6a01f232009-01-07 23:14:39 +0800981 local_irq_save_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +0800982
Graf Yang9570ff42009-01-07 23:14:38 +0800983 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800984 if (system_state == SYSTEM_BOOTING)
985 dump_stack();
Graf Yang9570ff42009-01-07 23:14:38 +0800986 printk(KERN_ERR
987 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
988 gpio, get_label(gpio));
Yi Li6a01f232009-01-07 23:14:39 +0800989 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +0800990 return -EBUSY;
991 }
992 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))
993 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved by %s! "
994 "(Documentation/blackfin/bfin-gpio-notes.txt)\n",
995 gpio, get_label(gpio));
996
997 reserved_gpio_irq_map[gpio_bank(gpio)] |= gpio_bit(gpio);
998 set_label(gpio, label);
999
Yi Li6a01f232009-01-07 23:14:39 +08001000 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001001
1002 port_setup(gpio, GPIO_USAGE);
1003
1004 return 0;
1005}
1006
1007void bfin_gpio_irq_free(unsigned gpio)
1008{
1009 unsigned long flags;
1010
1011 if (check_gpio(gpio) < 0)
1012 return;
1013
Yi Li6a01f232009-01-07 23:14:39 +08001014 local_irq_save_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001015
1016 if (unlikely(!(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
Robin Getzd6879c52009-03-29 01:10:30 +08001017 if (system_state == SYSTEM_BOOTING)
1018 dump_stack();
Graf Yang9570ff42009-01-07 23:14:38 +08001019 gpio_error(gpio);
Yi Li6a01f232009-01-07 23:14:39 +08001020 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001021 return;
1022 }
1023
1024 reserved_gpio_irq_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
1025
1026 set_label(gpio, "free");
1027
Yi Li6a01f232009-01-07 23:14:39 +08001028 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001029}
1030
Mike Frysingerf5563092009-02-04 16:49:45 +08001031static inline void __bfin_gpio_direction_input(unsigned gpio)
1032{
Mike Frysinger269647d2009-03-28 20:32:57 +08001033#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001034 gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001035#else
Mike Frysingerf5563092009-02-04 16:49:45 +08001036 gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
1037#endif
1038 gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
Michael Hennerich803a8d22008-05-17 16:01:51 +08001039}
Michael Hennerich803a8d22008-05-17 16:01:51 +08001040
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001041int bfin_gpio_direction_input(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -07001042{
1043 unsigned long flags;
1044
Michael Hennerichacbcd262008-01-22 18:36:20 +08001045 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1046 gpio_error(gpio);
1047 return -EINVAL;
1048 }
Bryan Wu1394f032007-05-06 14:50:22 -07001049
Yi Li6a01f232009-01-07 23:14:39 +08001050 local_irq_save_hw(flags);
Mike Frysingerf5563092009-02-04 16:49:45 +08001051 __bfin_gpio_direction_input(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +08001052 AWA_DUMMY_READ(inen);
Yi Li6a01f232009-01-07 23:14:39 +08001053 local_irq_restore_hw(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001054
1055 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001056}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001057EXPORT_SYMBOL(bfin_gpio_direction_input);
Bryan Wu1394f032007-05-06 14:50:22 -07001058
Mike Frysingerf5563092009-02-04 16:49:45 +08001059void bfin_gpio_irq_prepare(unsigned gpio)
1060{
Mike Frysinger269647d2009-03-28 20:32:57 +08001061#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001062 unsigned long flags;
1063#endif
1064
1065 port_setup(gpio, GPIO_USAGE);
1066
Mike Frysinger269647d2009-03-28 20:32:57 +08001067#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001068 local_irq_save_hw(flags);
1069 __bfin_gpio_direction_input(gpio);
1070 local_irq_restore_hw(flags);
1071#endif
1072}
1073
1074void bfin_gpio_set_value(unsigned gpio, int arg)
1075{
1076 if (arg)
1077 gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
1078 else
1079 gpio_array[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
1080}
1081EXPORT_SYMBOL(bfin_gpio_set_value);
1082
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001083int bfin_gpio_direction_output(unsigned gpio, int value)
Bryan Wu1394f032007-05-06 14:50:22 -07001084{
1085 unsigned long flags;
1086
Michael Hennerichacbcd262008-01-22 18:36:20 +08001087 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1088 gpio_error(gpio);
1089 return -EINVAL;
1090 }
Bryan Wu1394f032007-05-06 14:50:22 -07001091
Yi Li6a01f232009-01-07 23:14:39 +08001092 local_irq_save_hw(flags);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001093
Mike Frysingerf5563092009-02-04 16:49:45 +08001094 gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
1095 gpio_set_value(gpio, value);
Mike Frysinger269647d2009-03-28 20:32:57 +08001096#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001097 gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio);
1098#else
1099 gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
1100#endif
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001101
Michael Hennerich2b393312007-10-10 16:58:49 +08001102 AWA_DUMMY_READ(dir);
Yi Li6a01f232009-01-07 23:14:39 +08001103 local_irq_restore_hw(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001104
1105 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001106}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001107EXPORT_SYMBOL(bfin_gpio_direction_output);
Mike Frysinger168f1212007-10-11 00:22:35 +08001108
Mike Frysingerf5563092009-02-04 16:49:45 +08001109int bfin_gpio_get_value(unsigned gpio)
1110{
Mike Frysinger269647d2009-03-28 20:32:57 +08001111#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001112 return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio)));
1113#else
1114 unsigned long flags;
1115
1116 if (unlikely(get_gpio_edge(gpio))) {
1117 int ret;
1118 local_irq_save_hw(flags);
1119 set_gpio_edge(gpio, 0);
1120 ret = get_gpio_data(gpio);
1121 set_gpio_edge(gpio, 1);
1122 local_irq_restore_hw(flags);
1123 return ret;
1124 } else
1125 return get_gpio_data(gpio);
1126#endif
1127}
1128EXPORT_SYMBOL(bfin_gpio_get_value);
1129
Mike Frysinger168f1212007-10-11 00:22:35 +08001130/* If we are booting from SPI and our board lacks a strong enough pull up,
1131 * the core can reset and execute the bootrom faster than the resistor can
1132 * pull the signal logically high. To work around this (common) error in
1133 * board design, we explicitly set the pin back to GPIO mode, force /CS
1134 * high, and wait for the electrons to do their thing.
1135 *
1136 * This function only makes sense to be called from reset code, but it
1137 * lives here as we need to force all the GPIO states w/out going through
1138 * BUG() checks and such.
1139 */
Sonic Zhangb52dae32009-02-04 16:49:45 +08001140void bfin_reset_boot_spi_cs(unsigned short pin)
Mike Frysinger168f1212007-10-11 00:22:35 +08001141{
Sonic Zhangb52dae32009-02-04 16:49:45 +08001142 unsigned short gpio = P_IDENT(pin);
Michael Hennerich4d5f4ed2007-08-27 16:46:17 +08001143 port_setup(gpio, GPIO_USAGE);
Mike Frysingerf5563092009-02-04 16:49:45 +08001144 gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001145 AWA_DUMMY_READ(data_set);
Mike Frysinger168f1212007-10-11 00:22:35 +08001146 udelay(1);
1147}
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001148
Mike Frysinger1545a112007-12-24 16:54:48 +08001149#if defined(CONFIG_PROC_FS)
1150static int gpio_proc_read(char *buf, char **start, off_t offset,
1151 int len, int *unused_i, void *unused_v)
1152{
Graf Yang9570ff42009-01-07 23:14:38 +08001153 int c, irq, gpio, outlen = 0;
Mike Frysinger1545a112007-12-24 16:54:48 +08001154
1155 for (c = 0; c < MAX_RESOURCES; c++) {
Graf Yang9570ff42009-01-07 23:14:38 +08001156 irq = reserved_gpio_irq_map[gpio_bank(c)] & gpio_bit(c);
1157 gpio = reserved_gpio_map[gpio_bank(c)] & gpio_bit(c);
1158 if (!check_gpio(c) && (gpio || irq))
1159 len = sprintf(buf, "GPIO_%d: \t%s%s \t\tGPIO %s\n", c,
1160 get_label(c), (gpio && irq) ? " *" : "",
1161 get_gpio_dir(c) ? "OUTPUT" : "INPUT");
Mike Frysinger1545a112007-12-24 16:54:48 +08001162 else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c))
Graf Yang8eb3e3b2008-11-18 17:48:22 +08001163 len = sprintf(buf, "GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c));
Mike Frysinger1545a112007-12-24 16:54:48 +08001164 else
1165 continue;
1166 buf += len;
1167 outlen += len;
1168 }
1169 return outlen;
1170}
1171
1172static __init int gpio_register_proc(void)
1173{
1174 struct proc_dir_entry *proc_gpio;
1175
1176 proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
1177 if (proc_gpio)
1178 proc_gpio->read_proc = gpio_proc_read;
1179 return proc_gpio != NULL;
1180}
Mike Frysinger1545a112007-12-24 16:54:48 +08001181__initcall(gpio_register_proc);
1182#endif
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001183
1184#ifdef CONFIG_GPIOLIB
Joachim Eastwoodf9c29e82010-02-11 12:41:11 +01001185static int bfin_gpiolib_direction_input(struct gpio_chip *chip, unsigned gpio)
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001186{
1187 return bfin_gpio_direction_input(gpio);
1188}
1189
Joachim Eastwoodf9c29e82010-02-11 12:41:11 +01001190static int bfin_gpiolib_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001191{
1192 return bfin_gpio_direction_output(gpio, level);
1193}
1194
Joachim Eastwoodf9c29e82010-02-11 12:41:11 +01001195static int bfin_gpiolib_get_value(struct gpio_chip *chip, unsigned gpio)
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001196{
1197 return bfin_gpio_get_value(gpio);
1198}
1199
Joachim Eastwoodf9c29e82010-02-11 12:41:11 +01001200static void bfin_gpiolib_set_value(struct gpio_chip *chip, unsigned gpio, int value)
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001201{
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001202 return bfin_gpio_set_value(gpio, value);
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001203}
1204
Joachim Eastwoodf9c29e82010-02-11 12:41:11 +01001205static int bfin_gpiolib_gpio_request(struct gpio_chip *chip, unsigned gpio)
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001206{
1207 return bfin_gpio_request(gpio, chip->label);
1208}
1209
Joachim Eastwoodf9c29e82010-02-11 12:41:11 +01001210static void bfin_gpiolib_gpio_free(struct gpio_chip *chip, unsigned gpio)
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001211{
1212 return bfin_gpio_free(gpio);
1213}
1214
Joachim Eastwoodf9c29e82010-02-11 12:41:11 +01001215static int bfin_gpiolib_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
Joachim Eastwood7f4f69f2010-02-10 12:31:41 +01001216{
1217 return gpio + GPIO_IRQ_BASE;
1218}
1219
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001220static struct gpio_chip bfin_chip = {
Michael Hennerichedd07992009-12-16 08:45:17 +00001221 .label = "BFIN-GPIO",
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001222 .direction_input = bfin_gpiolib_direction_input,
1223 .get = bfin_gpiolib_get_value,
1224 .direction_output = bfin_gpiolib_direction_output,
1225 .set = bfin_gpiolib_set_value,
1226 .request = bfin_gpiolib_gpio_request,
1227 .free = bfin_gpiolib_gpio_free,
Joachim Eastwood7f4f69f2010-02-10 12:31:41 +01001228 .to_irq = bfin_gpiolib_gpio_to_irq,
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001229 .base = 0,
1230 .ngpio = MAX_BLACKFIN_GPIOS,
1231};
1232
1233static int __init bfin_gpiolib_setup(void)
1234{
1235 return gpiochip_add(&bfin_chip);
1236}
1237arch_initcall(bfin_gpiolib_setup);
1238#endif