blob: 6b94462713710b612f3fb82e351b92d5e5bdb46a [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/kernel/bfin_gpio.c
3 * Based on:
4 * Author: Michael Hennerich (hennerich@blackfin.uclinux.org)
5 *
6 * Created:
7 * Description: GPIO Abstraction Layer
8 *
9 * Modified:
Michael Hennericha2c8cfe2008-01-22 17:20:10 +080010 * Copyright 2008 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -070011 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
Mike Frysinger168f1212007-10-11 00:22:35 +080030#include <linux/delay.h>
Bryan Wu1394f032007-05-06 14:50:22 -070031#include <linux/module.h>
32#include <linux/err.h>
Mike Frysinger1545a112007-12-24 16:54:48 +080033#include <linux/proc_fs.h>
Bryan Wu1394f032007-05-06 14:50:22 -070034#include <asm/blackfin.h>
35#include <asm/gpio.h>
Michael Hennerichc58c2142007-10-04 00:35:05 +080036#include <asm/portmux.h>
Bryan Wu1394f032007-05-06 14:50:22 -070037#include <linux/irq.h>
38
Michael Hennerich2b393312007-10-10 16:58:49 +080039#if ANOMALY_05000311 || ANOMALY_05000323
40enum {
41 AWA_data = SYSCR,
42 AWA_data_clear = SYSCR,
43 AWA_data_set = SYSCR,
44 AWA_toggle = SYSCR,
Graf Yang6ed83942008-04-24 04:43:14 +080045 AWA_maska = BFIN_UART_SCR,
46 AWA_maska_clear = BFIN_UART_SCR,
47 AWA_maska_set = BFIN_UART_SCR,
48 AWA_maska_toggle = BFIN_UART_SCR,
49 AWA_maskb = BFIN_UART_GCTL,
50 AWA_maskb_clear = BFIN_UART_GCTL,
51 AWA_maskb_set = BFIN_UART_GCTL,
52 AWA_maskb_toggle = BFIN_UART_GCTL,
Michael Hennerich2b393312007-10-10 16:58:49 +080053 AWA_dir = SPORT1_STAT,
54 AWA_polar = SPORT1_STAT,
55 AWA_edge = SPORT1_STAT,
56 AWA_both = SPORT1_STAT,
57#if ANOMALY_05000311
58 AWA_inen = TIMER_ENABLE,
59#elif ANOMALY_05000323
60 AWA_inen = DMA1_1_CONFIG,
61#endif
62};
63 /* Anomaly Workaround */
64#define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
65#else
66#define AWA_DUMMY_READ(...) do { } while (0)
67#endif
68
Mike Frysingerf5563092009-02-04 16:49:45 +080069static struct gpio_port_t * const gpio_array[] = {
Michael Hennerichdc26aec2008-11-18 17:48:22 +080070#if defined(BF533_FAMILY) || defined(BF538_FAMILY)
Bryan Wu1394f032007-05-06 14:50:22 -070071 (struct gpio_port_t *) FIO_FLAG_D,
Mike Frysinger269647d2009-03-28 20:32:57 +080072#elif defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Bryan Wu1394f032007-05-06 14:50:22 -070073 (struct gpio_port_t *) PORTFIO,
74 (struct gpio_port_t *) PORTGIO,
75 (struct gpio_port_t *) PORTHIO,
Mike Frysingerf5563092009-02-04 16:49:45 +080076#elif defined(BF561_FAMILY)
77 (struct gpio_port_t *) FIO0_FLAG_D,
78 (struct gpio_port_t *) FIO1_FLAG_D,
79 (struct gpio_port_t *) FIO2_FLAG_D,
Mike Frysinger269647d2009-03-28 20:32:57 +080080#elif defined(CONFIG_BF54x)
Mike Frysingerf5563092009-02-04 16:49:45 +080081 (struct gpio_port_t *)PORTA_FER,
82 (struct gpio_port_t *)PORTB_FER,
83 (struct gpio_port_t *)PORTC_FER,
84 (struct gpio_port_t *)PORTD_FER,
85 (struct gpio_port_t *)PORTE_FER,
86 (struct gpio_port_t *)PORTF_FER,
87 (struct gpio_port_t *)PORTG_FER,
88 (struct gpio_port_t *)PORTH_FER,
89 (struct gpio_port_t *)PORTI_FER,
90 (struct gpio_port_t *)PORTJ_FER,
91#else
92# error no gpio arrays defined
93#endif
Bryan Wu1394f032007-05-06 14:50:22 -070094};
95
Mike Frysinger269647d2009-03-28 20:32:57 +080096#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +080097static unsigned short * const port_fer[] = {
Bryan Wu1394f032007-05-06 14:50:22 -070098 (unsigned short *) PORTF_FER,
99 (unsigned short *) PORTG_FER,
100 (unsigned short *) PORTH_FER,
101};
Bryan Wu1394f032007-05-06 14:50:22 -0700102
Mike Frysingerf5563092009-02-04 16:49:45 +0800103# if !defined(BF537_FAMILY)
104static unsigned short * const port_mux[] = {
Michael Hennerich59003142007-10-21 16:54:27 +0800105 (unsigned short *) PORTF_MUX,
106 (unsigned short *) PORTG_MUX,
107 (unsigned short *) PORTH_MUX,
108};
109
110static const
Graf Yang0ce5eaf2009-02-04 16:49:45 +0800111u8 pmux_offset[][16] = {
Mike Frysinger269647d2009-03-28 20:32:57 +0800112# if defined(CONFIG_BF52x)
Graf Yang0ce5eaf2009-02-04 16:49:45 +0800113 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */
114 { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */
115 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */
Mike Frysinger269647d2009-03-28 20:32:57 +0800116# elif defined(CONFIG_BF51x)
Graf Yang0ce5eaf2009-02-04 16:49:45 +0800117 { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 }, /* PORTF */
118 { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 }, /* PORTG */
119 { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 }, /* PORTH */
120# endif
121};
Mike Frysingerf5563092009-02-04 16:49:45 +0800122# endif
Graf Yang0ce5eaf2009-02-04 16:49:45 +0800123
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800124#endif
125
Bryan Wu397861c2008-11-18 17:48:22 +0800126static unsigned short reserved_gpio_map[GPIO_BANK_NUM];
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800127static unsigned short reserved_peri_map[gpio_bank(MAX_RESOURCES)];
Graf Yang9570ff42009-01-07 23:14:38 +0800128static unsigned short reserved_gpio_irq_map[GPIO_BANK_NUM];
Michael Hennerichc58c2142007-10-04 00:35:05 +0800129
Michael Hennerich8c613622007-08-03 17:48:09 +0800130#define RESOURCE_LABEL_SIZE 16
131
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800132static struct str_ident {
Michael Hennerich8c613622007-08-03 17:48:09 +0800133 char name[RESOURCE_LABEL_SIZE];
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800134} str_ident[MAX_RESOURCES];
Bryan Wu1394f032007-05-06 14:50:22 -0700135
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800136#if defined(CONFIG_PM)
Bryan Wu397861c2008-11-18 17:48:22 +0800137static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM];
Bryan Wu1394f032007-05-06 14:50:22 -0700138#endif
139
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800140inline int check_gpio(unsigned gpio)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800141{
Mike Frysinger269647d2009-03-28 20:32:57 +0800142#if defined(CONFIG_BF54x)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800143 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
144 || gpio == GPIO_PH14 || gpio == GPIO_PH15
Mike Frysinger27228b22008-10-28 15:45:42 +0800145 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800146 return -EINVAL;
Mike Frysinger27228b22008-10-28 15:45:42 +0800147#endif
Michael Henneriche7613aa2007-06-11 16:37:57 +0800148 if (gpio >= MAX_BLACKFIN_GPIOS)
Bryan Wu1394f032007-05-06 14:50:22 -0700149 return -EINVAL;
150 return 0;
151}
152
Mike Frysinger74c04502008-10-08 16:13:17 +0800153static void gpio_error(unsigned gpio)
Michael Hennerichacbcd262008-01-22 18:36:20 +0800154{
155 printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio);
156}
157
Michael Hennerichc58c2142007-10-04 00:35:05 +0800158static void set_label(unsigned short ident, const char *label)
159{
Michael Henneriche9fae182008-10-13 11:35:22 +0800160 if (label) {
Michael Hennerich8c613622007-08-03 17:48:09 +0800161 strncpy(str_ident[ident].name, label,
Michael Hennerichc58c2142007-10-04 00:35:05 +0800162 RESOURCE_LABEL_SIZE);
Michael Hennerich8c613622007-08-03 17:48:09 +0800163 str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800164 }
165}
166
167static char *get_label(unsigned short ident)
168{
Michael Hennerich8c613622007-08-03 17:48:09 +0800169 return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN");
Michael Hennerichc58c2142007-10-04 00:35:05 +0800170}
171
172static int cmp_label(unsigned short ident, const char *label)
173{
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800174 if (label == NULL) {
175 dump_stack();
176 printk(KERN_ERR "Please provide none-null label\n");
177 }
178
Michael Henneriche9fae182008-10-13 11:35:22 +0800179 if (label)
Mike Frysinger1f7d3732008-10-28 15:47:11 +0800180 return strcmp(str_ident[ident].name, label);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800181 else
182 return -EINVAL;
183}
184
Mike Frysingera2d03a12008-10-28 15:53:37 +0800185static void port_setup(unsigned gpio, unsigned short usage)
186{
187 if (check_gpio(gpio))
188 return;
189
Mike Frysinger269647d2009-03-28 20:32:57 +0800190#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Mike Frysingera2d03a12008-10-28 15:53:37 +0800191 if (usage == GPIO_USAGE)
192 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
193 else
194 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
195 SSYNC();
Mike Frysinger269647d2009-03-28 20:32:57 +0800196#elif defined(CONFIG_BF54x)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800197 if (usage == GPIO_USAGE)
198 gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
199 else
200 gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
201 SSYNC();
Bryan Wu1394f032007-05-06 14:50:22 -0700202#endif
Mike Frysingera2d03a12008-10-28 15:53:37 +0800203}
Bryan Wu1394f032007-05-06 14:50:22 -0700204
Michael Hennerichc58c2142007-10-04 00:35:05 +0800205#ifdef BF537_FAMILY
Michael Hennerich8c613622007-08-03 17:48:09 +0800206static struct {
207 unsigned short res;
208 unsigned short offset;
209} port_mux_lut[] = {
210 {.res = P_PPI0_D13, .offset = 11},
211 {.res = P_PPI0_D14, .offset = 11},
212 {.res = P_PPI0_D15, .offset = 11},
213 {.res = P_SPORT1_TFS, .offset = 11},
214 {.res = P_SPORT1_TSCLK, .offset = 11},
215 {.res = P_SPORT1_DTPRI, .offset = 11},
216 {.res = P_PPI0_D10, .offset = 10},
217 {.res = P_PPI0_D11, .offset = 10},
218 {.res = P_PPI0_D12, .offset = 10},
219 {.res = P_SPORT1_RSCLK, .offset = 10},
220 {.res = P_SPORT1_RFS, .offset = 10},
221 {.res = P_SPORT1_DRPRI, .offset = 10},
222 {.res = P_PPI0_D8, .offset = 9},
223 {.res = P_PPI0_D9, .offset = 9},
224 {.res = P_SPORT1_DRSEC, .offset = 9},
225 {.res = P_SPORT1_DTSEC, .offset = 9},
226 {.res = P_TMR2, .offset = 8},
227 {.res = P_PPI0_FS3, .offset = 8},
228 {.res = P_TMR3, .offset = 7},
229 {.res = P_SPI0_SSEL4, .offset = 7},
230 {.res = P_TMR4, .offset = 6},
231 {.res = P_SPI0_SSEL5, .offset = 6},
232 {.res = P_TMR5, .offset = 5},
233 {.res = P_SPI0_SSEL6, .offset = 5},
234 {.res = P_UART1_RX, .offset = 4},
235 {.res = P_UART1_TX, .offset = 4},
236 {.res = P_TMR6, .offset = 4},
237 {.res = P_TMR7, .offset = 4},
238 {.res = P_UART0_RX, .offset = 3},
239 {.res = P_UART0_TX, .offset = 3},
240 {.res = P_DMAR0, .offset = 3},
241 {.res = P_DMAR1, .offset = 3},
242 {.res = P_SPORT0_DTSEC, .offset = 1},
243 {.res = P_SPORT0_DRSEC, .offset = 1},
244 {.res = P_CAN0_RX, .offset = 1},
245 {.res = P_CAN0_TX, .offset = 1},
246 {.res = P_SPI0_SSEL7, .offset = 1},
247 {.res = P_SPORT0_TFS, .offset = 0},
248 {.res = P_SPORT0_DTPRI, .offset = 0},
249 {.res = P_SPI0_SSEL2, .offset = 0},
250 {.res = P_SPI0_SSEL3, .offset = 0},
Michael Hennerichc58c2142007-10-04 00:35:05 +0800251};
252
Mike Frysingerf5563092009-02-04 16:49:45 +0800253static void portmux_setup(unsigned short per)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800254{
Michael Hennerich8c613622007-08-03 17:48:09 +0800255 u16 y, offset, muxreg;
Mike Frysingerf5563092009-02-04 16:49:45 +0800256 u16 function = P_FUNCT2MUX(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800257
Michael Hennerich8c613622007-08-03 17:48:09 +0800258 for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
259 if (port_mux_lut[y].res == per) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800260
261 /* SET PORTMUX REG */
262
Michael Hennerich8c613622007-08-03 17:48:09 +0800263 offset = port_mux_lut[y].offset;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800264 muxreg = bfin_read_PORT_MUX();
265
Mike Frysingerd171c232008-03-26 08:35:46 +0800266 if (offset != 1)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800267 muxreg &= ~(1 << offset);
Mike Frysingerd171c232008-03-26 08:35:46 +0800268 else
Michael Hennerichc58c2142007-10-04 00:35:05 +0800269 muxreg &= ~(3 << 1);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800270
271 muxreg |= (function << offset);
272 bfin_write_PORT_MUX(muxreg);
273 }
274 }
275}
Mike Frysinger269647d2009-03-28 20:32:57 +0800276#elif defined(CONFIG_BF54x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800277inline void portmux_setup(unsigned short per)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800278{
279 u32 pmux;
Mike Frysingerf5563092009-02-04 16:49:45 +0800280 u16 ident = P_IDENT(per);
281 u16 function = P_FUNCT2MUX(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800282
Mike Frysingerf5563092009-02-04 16:49:45 +0800283 pmux = gpio_array[gpio_bank(ident)]->port_mux;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800284
Mike Frysingerf5563092009-02-04 16:49:45 +0800285 pmux &= ~(0x3 << (2 * gpio_sub_n(ident)));
286 pmux |= (function & 0x3) << (2 * gpio_sub_n(ident));
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800287
Mike Frysingerf5563092009-02-04 16:49:45 +0800288 gpio_array[gpio_bank(ident)]->port_mux = pmux;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800289}
290
Mike Frysingerf5563092009-02-04 16:49:45 +0800291inline u16 get_portmux(unsigned short per)
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800292{
293 u32 pmux;
Mike Frysingerf5563092009-02-04 16:49:45 +0800294 u16 ident = P_IDENT(per);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800295
Mike Frysingerf5563092009-02-04 16:49:45 +0800296 pmux = gpio_array[gpio_bank(ident)]->port_mux;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800297
Mike Frysingerf5563092009-02-04 16:49:45 +0800298 return (pmux >> (2 * gpio_sub_n(ident)) & 0x3);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800299}
Mike Frysinger269647d2009-03-28 20:32:57 +0800300#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800301inline void portmux_setup(unsigned short per)
Michael Hennerich59003142007-10-21 16:54:27 +0800302{
Mike Frysingerf5563092009-02-04 16:49:45 +0800303 u16 pmux, ident = P_IDENT(per), function = P_FUNCT2MUX(per);
Michael Hennerich59003142007-10-21 16:54:27 +0800304 u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)];
305
306 pmux = *port_mux[gpio_bank(ident)];
307 pmux &= ~(3 << offset);
308 pmux |= (function & 3) << offset;
309 *port_mux[gpio_bank(ident)] = pmux;
310 SSYNC();
311}
Michael Hennerichc58c2142007-10-04 00:35:05 +0800312#else
313# define portmux_setup(...) do { } while (0)
314#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700315
Mike Frysinger269647d2009-03-28 20:32:57 +0800316#ifndef CONFIG_BF54x
Bryan Wu1394f032007-05-06 14:50:22 -0700317/***********************************************************
318*
319* FUNCTIONS: Blackfin General Purpose Ports Access Functions
320*
321* INPUTS/OUTPUTS:
322* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
323*
324*
325* DESCRIPTION: These functions abstract direct register access
326* to Blackfin processor General Purpose
327* Ports Regsiters
328*
329* CAUTION: These functions do not belong to the GPIO Driver API
330*************************************************************
331* MODIFICATION HISTORY :
332**************************************************************/
333
334/* Set a specific bit */
335
336#define SET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800337void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Bryan Wu1394f032007-05-06 14:50:22 -0700338{ \
339 unsigned long flags; \
Yi Li6a01f232009-01-07 23:14:39 +0800340 local_irq_save_hw(flags); \
Bryan Wu1394f032007-05-06 14:50:22 -0700341 if (arg) \
Mike Frysingerf5563092009-02-04 16:49:45 +0800342 gpio_array[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
Bryan Wu1394f032007-05-06 14:50:22 -0700343 else \
Mike Frysingerf5563092009-02-04 16:49:45 +0800344 gpio_array[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800345 AWA_DUMMY_READ(name); \
Yi Li6a01f232009-01-07 23:14:39 +0800346 local_irq_restore_hw(flags); \
Bryan Wu1394f032007-05-06 14:50:22 -0700347} \
348EXPORT_SYMBOL(set_gpio_ ## name);
349
Mike Frysingerf5563092009-02-04 16:49:45 +0800350SET_GPIO(dir) /* set_gpio_dir() */
351SET_GPIO(inen) /* set_gpio_inen() */
352SET_GPIO(polar) /* set_gpio_polar() */
353SET_GPIO(edge) /* set_gpio_edge() */
354SET_GPIO(both) /* set_gpio_both() */
Bryan Wu1394f032007-05-06 14:50:22 -0700355
356
Michael Hennerich2b393312007-10-10 16:58:49 +0800357#define SET_GPIO_SC(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800358void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800359{ \
360 unsigned long flags; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800361 if (ANOMALY_05000311 || ANOMALY_05000323) \
362 local_irq_save_hw(flags); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800363 if (arg) \
Mike Frysingerf5563092009-02-04 16:49:45 +0800364 gpio_array[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
Michael Hennerich2b393312007-10-10 16:58:49 +0800365 else \
Mike Frysingerf5563092009-02-04 16:49:45 +0800366 gpio_array[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
367 if (ANOMALY_05000311 || ANOMALY_05000323) { \
368 AWA_DUMMY_READ(name); \
369 local_irq_restore_hw(flags); \
370 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800371} \
372EXPORT_SYMBOL(set_gpio_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700373
374SET_GPIO_SC(maska)
375SET_GPIO_SC(maskb)
Bryan Wu1394f032007-05-06 14:50:22 -0700376SET_GPIO_SC(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700377
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800378void set_gpio_toggle(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700379{
380 unsigned long flags;
Mike Frysingerf5563092009-02-04 16:49:45 +0800381 if (ANOMALY_05000311 || ANOMALY_05000323)
382 local_irq_save_hw(flags);
383 gpio_array[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
384 if (ANOMALY_05000311 || ANOMALY_05000323) {
385 AWA_DUMMY_READ(toggle);
386 local_irq_restore_hw(flags);
387 }
Bryan Wu1394f032007-05-06 14:50:22 -0700388}
Bryan Wu1394f032007-05-06 14:50:22 -0700389EXPORT_SYMBOL(set_gpio_toggle);
390
391
392/*Set current PORT date (16-bit word)*/
393
Michael Hennerich2b393312007-10-10 16:58:49 +0800394#define SET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800395void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800396{ \
397 unsigned long flags; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800398 if (ANOMALY_05000311 || ANOMALY_05000323) \
399 local_irq_save_hw(flags); \
400 gpio_array[gpio_bank(gpio)]->name = arg; \
401 if (ANOMALY_05000311 || ANOMALY_05000323) { \
402 AWA_DUMMY_READ(name); \
403 local_irq_restore_hw(flags); \
404 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800405} \
406EXPORT_SYMBOL(set_gpiop_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700407
Michael Hennerich2b393312007-10-10 16:58:49 +0800408SET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700409SET_GPIO_P(dir)
410SET_GPIO_P(inen)
411SET_GPIO_P(polar)
412SET_GPIO_P(edge)
413SET_GPIO_P(both)
414SET_GPIO_P(maska)
415SET_GPIO_P(maskb)
416
Bryan Wu1394f032007-05-06 14:50:22 -0700417/* Get a specific bit */
Michael Hennerich2b393312007-10-10 16:58:49 +0800418#define GET_GPIO(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800419unsigned short get_gpio_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800420{ \
421 unsigned long flags; \
422 unsigned short ret; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800423 if (ANOMALY_05000311 || ANOMALY_05000323) \
424 local_irq_save_hw(flags); \
425 ret = 0x01 & (gpio_array[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
426 if (ANOMALY_05000311 || ANOMALY_05000323) { \
427 AWA_DUMMY_READ(name); \
428 local_irq_restore_hw(flags); \
429 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800430 return ret; \
431} \
432EXPORT_SYMBOL(get_gpio_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700433
Michael Hennerich2b393312007-10-10 16:58:49 +0800434GET_GPIO(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700435GET_GPIO(dir)
436GET_GPIO(inen)
437GET_GPIO(polar)
438GET_GPIO(edge)
439GET_GPIO(both)
440GET_GPIO(maska)
441GET_GPIO(maskb)
442
Bryan Wu1394f032007-05-06 14:50:22 -0700443/*Get current PORT date (16-bit word)*/
444
Michael Hennerich2b393312007-10-10 16:58:49 +0800445#define GET_GPIO_P(name) \
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800446unsigned short get_gpiop_ ## name(unsigned gpio) \
Michael Hennerich2b393312007-10-10 16:58:49 +0800447{ \
448 unsigned long flags; \
449 unsigned short ret; \
Mike Frysingerf5563092009-02-04 16:49:45 +0800450 if (ANOMALY_05000311 || ANOMALY_05000323) \
451 local_irq_save_hw(flags); \
452 ret = (gpio_array[gpio_bank(gpio)]->name); \
453 if (ANOMALY_05000311 || ANOMALY_05000323) { \
454 AWA_DUMMY_READ(name); \
455 local_irq_restore_hw(flags); \
456 } \
Michael Hennerich2b393312007-10-10 16:58:49 +0800457 return ret; \
458} \
459EXPORT_SYMBOL(get_gpiop_ ## name);
Bryan Wu1394f032007-05-06 14:50:22 -0700460
Michael Hennerich2b393312007-10-10 16:58:49 +0800461GET_GPIO_P(data)
Bryan Wu1394f032007-05-06 14:50:22 -0700462GET_GPIO_P(dir)
463GET_GPIO_P(inen)
464GET_GPIO_P(polar)
465GET_GPIO_P(edge)
466GET_GPIO_P(both)
467GET_GPIO_P(maska)
468GET_GPIO_P(maskb)
469
Bryan Wu1394f032007-05-06 14:50:22 -0700470
471#ifdef CONFIG_PM
Mike Frysingerf5563092009-02-04 16:49:45 +0800472
473static unsigned short wakeup_map[GPIO_BANK_NUM];
474static unsigned char wakeup_flags_map[MAX_BLACKFIN_GPIOS];
475
476static const unsigned int sic_iwr_irqs[] = {
477#if defined(BF533_FAMILY)
478 IRQ_PROG_INTB
479#elif defined(BF537_FAMILY)
480 IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX
481#elif defined(BF538_FAMILY)
482 IRQ_PORTF_INTB
Mike Frysinger269647d2009-03-28 20:32:57 +0800483#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800484 IRQ_PORTF_INTB, IRQ_PORTG_INTB, IRQ_PORTH_INTB
485#elif defined(BF561_FAMILY)
486 IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB
487#else
488# error no SIC_IWR defined
489#endif
490};
491
Bryan Wu1394f032007-05-06 14:50:22 -0700492/***********************************************************
493*
494* FUNCTIONS: Blackfin PM Setup API
495*
496* INPUTS/OUTPUTS:
497* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
498* type -
499* PM_WAKE_RISING
500* PM_WAKE_FALLING
501* PM_WAKE_HIGH
502* PM_WAKE_LOW
503* PM_WAKE_BOTH_EDGES
504*
505* DESCRIPTION: Blackfin PM Driver API
506*
507* CAUTION:
508*************************************************************
509* MODIFICATION HISTORY :
510**************************************************************/
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800511int gpio_pm_wakeup_request(unsigned gpio, unsigned char type)
Bryan Wu1394f032007-05-06 14:50:22 -0700512{
513 unsigned long flags;
514
515 if ((check_gpio(gpio) < 0) || !type)
516 return -EINVAL;
517
Yi Li6a01f232009-01-07 23:14:39 +0800518 local_irq_save_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700519 wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio);
520 wakeup_flags_map[gpio] = type;
Yi Li6a01f232009-01-07 23:14:39 +0800521 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700522
523 return 0;
524}
525EXPORT_SYMBOL(gpio_pm_wakeup_request);
526
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800527void gpio_pm_wakeup_free(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700528{
529 unsigned long flags;
530
531 if (check_gpio(gpio) < 0)
532 return;
533
Yi Li6a01f232009-01-07 23:14:39 +0800534 local_irq_save_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700535
536 wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
537
Yi Li6a01f232009-01-07 23:14:39 +0800538 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700539}
540EXPORT_SYMBOL(gpio_pm_wakeup_free);
541
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800542static int bfin_gpio_wakeup_type(unsigned gpio, unsigned char type)
Bryan Wu1394f032007-05-06 14:50:22 -0700543{
544 port_setup(gpio, GPIO_USAGE);
545 set_gpio_dir(gpio, 0);
546 set_gpio_inen(gpio, 1);
547
548 if (type & (PM_WAKE_RISING | PM_WAKE_FALLING))
549 set_gpio_edge(gpio, 1);
550 else
551 set_gpio_edge(gpio, 0);
552
553 if ((type & (PM_WAKE_BOTH_EDGES)) == (PM_WAKE_BOTH_EDGES))
554 set_gpio_both(gpio, 1);
555 else
556 set_gpio_both(gpio, 0);
557
558 if ((type & (PM_WAKE_FALLING | PM_WAKE_LOW)))
559 set_gpio_polar(gpio, 1);
560 else
561 set_gpio_polar(gpio, 0);
562
563 SSYNC();
564
565 return 0;
566}
567
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800568u32 bfin_pm_standby_setup(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700569{
Bryan Wu1394f032007-05-06 14:50:22 -0700570 u16 bank, mask, i, gpio;
571
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800572 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Bryan Wu1394f032007-05-06 14:50:22 -0700573 mask = wakeup_map[gpio_bank(i)];
574 bank = gpio_bank(i);
575
Mike Frysingerf5563092009-02-04 16:49:45 +0800576 gpio_bank_saved[bank].maskb = gpio_array[bank]->maskb;
577 gpio_array[bank]->maskb = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700578
579 if (mask) {
Mike Frysinger269647d2009-03-28 20:32:57 +0800580#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Bryan Wu1394f032007-05-06 14:50:22 -0700581 gpio_bank_saved[bank].fer = *port_fer[bank];
582#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800583 gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
584 gpio_bank_saved[bank].polar = gpio_array[bank]->polar;
585 gpio_bank_saved[bank].dir = gpio_array[bank]->dir;
586 gpio_bank_saved[bank].edge = gpio_array[bank]->edge;
587 gpio_bank_saved[bank].both = gpio_array[bank]->both;
Michael Hennerichc58c2142007-10-04 00:35:05 +0800588 gpio_bank_saved[bank].reserved =
589 reserved_gpio_map[bank];
Bryan Wu1394f032007-05-06 14:50:22 -0700590
591 gpio = i;
592
593 while (mask) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800594 if ((mask & 1) && (wakeup_flags_map[gpio] !=
595 PM_WAKE_IGNORE)) {
Michael Hennerichc58c2142007-10-04 00:35:05 +0800596 reserved_gpio_map[gpio_bank(gpio)] |=
Michael Hennerich581d62a2007-06-14 13:30:23 +0800597 gpio_bit(gpio);
598 bfin_gpio_wakeup_type(gpio,
599 wakeup_flags_map[gpio]);
Bryan Wu1394f032007-05-06 14:50:22 -0700600 set_gpio_data(gpio, 0); /*Clear*/
601 }
602 gpio++;
603 mask >>= 1;
604 }
605
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800606 bfin_internal_set_wake(sic_iwr_irqs[bank], 1);
Mike Frysingerf5563092009-02-04 16:49:45 +0800607 gpio_array[bank]->maskb_set = wakeup_map[gpio_bank(i)];
Bryan Wu1394f032007-05-06 14:50:22 -0700608 }
609 }
610
Michael Hennerich2b393312007-10-10 16:58:49 +0800611 AWA_DUMMY_READ(maskb_set);
612
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800613 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700614}
615
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800616void bfin_pm_standby_restore(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700617{
618 u16 bank, mask, i;
619
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800620 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Bryan Wu1394f032007-05-06 14:50:22 -0700621 mask = wakeup_map[gpio_bank(i)];
622 bank = gpio_bank(i);
623
624 if (mask) {
Mike Frysinger269647d2009-03-28 20:32:57 +0800625#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Bryan Wu1394f032007-05-06 14:50:22 -0700626 *port_fer[bank] = gpio_bank_saved[bank].fer;
627#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800628 gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
629 gpio_array[bank]->dir = gpio_bank_saved[bank].dir;
630 gpio_array[bank]->polar = gpio_bank_saved[bank].polar;
631 gpio_array[bank]->edge = gpio_bank_saved[bank].edge;
632 gpio_array[bank]->both = gpio_bank_saved[bank].both;
Michael Hennerich581d62a2007-06-14 13:30:23 +0800633
Michael Hennerichc58c2142007-10-04 00:35:05 +0800634 reserved_gpio_map[bank] =
635 gpio_bank_saved[bank].reserved;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800636 bfin_internal_set_wake(sic_iwr_irqs[bank], 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700637 }
638
Mike Frysingerf5563092009-02-04 16:49:45 +0800639 gpio_array[bank]->maskb = gpio_bank_saved[bank].maskb;
Bryan Wu1394f032007-05-06 14:50:22 -0700640 }
Michael Hennerich2b393312007-10-10 16:58:49 +0800641 AWA_DUMMY_READ(maskb);
Bryan Wu1394f032007-05-06 14:50:22 -0700642}
643
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800644void bfin_gpio_pm_hibernate_suspend(void)
645{
646 int i, bank;
647
648 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
649 bank = gpio_bank(i);
650
Mike Frysinger269647d2009-03-28 20:32:57 +0800651#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800652 gpio_bank_saved[bank].fer = *port_fer[bank];
Mike Frysinger269647d2009-03-28 20:32:57 +0800653#if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800654 gpio_bank_saved[bank].mux = *port_mux[bank];
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800655#else
Mike Frysingerf5563092009-02-04 16:49:45 +0800656 if (bank == 0)
657 gpio_bank_saved[bank].mux = bfin_read_PORT_MUX();
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800658#endif
659#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800660 gpio_bank_saved[bank].data = gpio_array[bank]->data;
661 gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
662 gpio_bank_saved[bank].polar = gpio_array[bank]->polar;
663 gpio_bank_saved[bank].dir = gpio_array[bank]->dir;
664 gpio_bank_saved[bank].edge = gpio_array[bank]->edge;
665 gpio_bank_saved[bank].both = gpio_array[bank]->both;
666 gpio_bank_saved[bank].maska = gpio_array[bank]->maska;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800667 }
668
669 AWA_DUMMY_READ(maska);
670}
671
672void bfin_gpio_pm_hibernate_restore(void)
673{
674 int i, bank;
675
676 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Mike Frysingerf5563092009-02-04 16:49:45 +0800677 bank = gpio_bank(i);
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800678
Mike Frysinger269647d2009-03-28 20:32:57 +0800679#if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
680#if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Mike Frysingerf5563092009-02-04 16:49:45 +0800681 *port_mux[bank] = gpio_bank_saved[bank].mux;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800682#else
Mike Frysingerf5563092009-02-04 16:49:45 +0800683 if (bank == 0)
684 bfin_write_PORT_MUX(gpio_bank_saved[bank].mux);
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800685#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800686 *port_fer[bank] = gpio_bank_saved[bank].fer;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800687#endif
Mike Frysingerf5563092009-02-04 16:49:45 +0800688 gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
Michael Hennerichc03c2a82009-07-08 12:04:43 +0000689 gpio_array[bank]->data_set = gpio_bank_saved[bank].data
690 & gpio_bank_saved[bank].dir;
Mike Frysingerf5563092009-02-04 16:49:45 +0800691 gpio_array[bank]->dir = gpio_bank_saved[bank].dir;
692 gpio_array[bank]->polar = gpio_bank_saved[bank].polar;
693 gpio_array[bank]->edge = gpio_bank_saved[bank].edge;
694 gpio_array[bank]->both = gpio_bank_saved[bank].both;
Mike Frysingerf5563092009-02-04 16:49:45 +0800695 gpio_array[bank]->maska = gpio_bank_saved[bank].maska;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800696 }
697 AWA_DUMMY_READ(maska);
698}
699
700
Bryan Wu1394f032007-05-06 14:50:22 -0700701#endif
Mike Frysinger269647d2009-03-28 20:32:57 +0800702#else /* CONFIG_BF54x */
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800703#ifdef CONFIG_PM
704
705u32 bfin_pm_standby_setup(void)
706{
707 return 0;
708}
709
710void bfin_pm_standby_restore(void)
711{
712
713}
714
715void bfin_gpio_pm_hibernate_suspend(void)
716{
717 int i, bank;
718
719 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
720 bank = gpio_bank(i);
721
Mike Frysingerf5563092009-02-04 16:49:45 +0800722 gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer;
723 gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux;
724 gpio_bank_saved[bank].data = gpio_array[bank]->data;
725 gpio_bank_saved[bank].data = gpio_array[bank]->data;
726 gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
727 gpio_bank_saved[bank].dir = gpio_array[bank]->dir_set;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800728 }
729}
730
731void bfin_gpio_pm_hibernate_restore(void)
732{
733 int i, bank;
734
735 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Mike Frysingerf5563092009-02-04 16:49:45 +0800736 bank = gpio_bank(i);
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800737
Mike Frysingerf5563092009-02-04 16:49:45 +0800738 gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux;
739 gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer;
740 gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
741 gpio_array[bank]->dir_set = gpio_bank_saved[bank].dir;
742 gpio_array[bank]->data_set = gpio_bank_saved[bank].data
743 | gpio_bank_saved[bank].dir;
Michael Hennerich1efc80b2008-07-19 16:57:32 +0800744 }
745}
746#endif
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800747
Michael Hennericha2c8cfe2008-01-22 17:20:10 +0800748unsigned short get_gpio_dir(unsigned gpio)
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800749{
Mike Frysingerf5563092009-02-04 16:49:45 +0800750 return (0x01 & (gpio_array[gpio_bank(gpio)]->dir_clear >> gpio_sub_n(gpio)));
Michael Hennerichfac3cf42007-12-24 20:07:03 +0800751}
752EXPORT_SYMBOL(get_gpio_dir);
753
Mike Frysinger269647d2009-03-28 20:32:57 +0800754#endif /* CONFIG_BF54x */
Bryan Wu1394f032007-05-06 14:50:22 -0700755
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800756/***********************************************************
757*
758* FUNCTIONS: Blackfin Peripheral Resource Allocation
759* and PortMux Setup
760*
761* INPUTS/OUTPUTS:
762* per Peripheral Identifier
763* label String
764*
765* DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API
766*
767* CAUTION:
768*************************************************************
769* MODIFICATION HISTORY :
770**************************************************************/
Michael Hennerichc58c2142007-10-04 00:35:05 +0800771
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800772int peripheral_request(unsigned short per, const char *label)
773{
774 unsigned long flags;
775 unsigned short ident = P_IDENT(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800776
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800777 /*
778 * Don't cares are pins with only one dedicated function
779 */
780
781 if (per & P_DONTCARE)
782 return 0;
783
784 if (!(per & P_DEFINED))
785 return -ENODEV;
786
Yi Li6a01f232009-01-07 23:14:39 +0800787 local_irq_save_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800788
Mike Frysinger6a87d292008-10-28 16:16:29 +0800789 /* If a pin can be muxed as either GPIO or peripheral, make
790 * sure it is not already a GPIO pin when we request it.
791 */
792 if (unlikely(!check_gpio(ident) &&
793 reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800794 if (system_state == SYSTEM_BOOTING)
795 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800796 printk(KERN_ERR
Mike Frysinger6c7ec0e2008-10-28 15:49:59 +0800797 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800798 __func__, ident, get_label(ident));
Yi Li6a01f232009-01-07 23:14:39 +0800799 local_irq_restore_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800800 return -EBUSY;
801 }
802
803 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
804
Mike Frysingerd171c232008-03-26 08:35:46 +0800805 /*
806 * Pin functions like AMC address strobes my
807 * be requested and used by several drivers
808 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800809
Mike Frysinger269647d2009-03-28 20:32:57 +0800810#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +0800811 if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) {
Mike Frysinger6c7ec0e2008-10-28 15:49:59 +0800812#else
813 if (!(per & P_MAYSHARE)) {
814#endif
Mike Frysingerd171c232008-03-26 08:35:46 +0800815 /*
816 * Allow that the identical pin function can
817 * be requested from the same driver twice
818 */
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800819
Mike Frysingerd171c232008-03-26 08:35:46 +0800820 if (cmp_label(ident, label) == 0)
821 goto anyway;
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800822
Robin Getzd6879c52009-03-29 01:10:30 +0800823 if (system_state == SYSTEM_BOOTING)
824 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800825 printk(KERN_ERR
826 "%s: Peripheral %d function %d is already reserved by %s !\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800827 __func__, ident, P_FUNCT2MUX(per), get_label(ident));
Yi Li6a01f232009-01-07 23:14:39 +0800828 local_irq_restore_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800829 return -EBUSY;
830 }
831 }
832
Mike Frysingerd171c232008-03-26 08:35:46 +0800833 anyway:
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800834 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
835
Mike Frysingerf5563092009-02-04 16:49:45 +0800836 portmux_setup(per);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800837 port_setup(ident, PERIPHERAL_USAGE);
838
Yi Li6a01f232009-01-07 23:14:39 +0800839 local_irq_restore_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800840 set_label(ident, label);
841
842 return 0;
843}
844EXPORT_SYMBOL(peripheral_request);
845
Mike Frysinger68179372008-04-24 05:04:24 +0800846int peripheral_request_list(const unsigned short per[], const char *label)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800847{
848 u16 cnt;
849 int ret;
850
851 for (cnt = 0; per[cnt] != 0; cnt++) {
Michael Hennerich314c98d2007-07-24 18:03:45 +0800852
Michael Hennerichc58c2142007-10-04 00:35:05 +0800853 ret = peripheral_request(per[cnt], label);
Michael Hennerich314c98d2007-07-24 18:03:45 +0800854
855 if (ret < 0) {
Mike Frysingerd171c232008-03-26 08:35:46 +0800856 for ( ; cnt > 0; cnt--)
Michael Hennerich314c98d2007-07-24 18:03:45 +0800857 peripheral_free(per[cnt - 1]);
Mike Frysingerd171c232008-03-26 08:35:46 +0800858
859 return ret;
Michael Hennerich314c98d2007-07-24 18:03:45 +0800860 }
Michael Hennerichc58c2142007-10-04 00:35:05 +0800861 }
862
863 return 0;
864}
865EXPORT_SYMBOL(peripheral_request_list);
866
867void peripheral_free(unsigned short per)
868{
869 unsigned long flags;
870 unsigned short ident = P_IDENT(per);
871
872 if (per & P_DONTCARE)
873 return;
874
875 if (!(per & P_DEFINED))
876 return;
877
Yi Li6a01f232009-01-07 23:14:39 +0800878 local_irq_save_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800879
Mike Frysingerd171c232008-03-26 08:35:46 +0800880 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
Yi Li6a01f232009-01-07 23:14:39 +0800881 local_irq_restore_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800882 return;
883 }
884
Mike Frysingerd171c232008-03-26 08:35:46 +0800885 if (!(per & P_MAYSHARE))
Michael Hennerichc58c2142007-10-04 00:35:05 +0800886 port_setup(ident, GPIO_USAGE);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800887
888 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
889
Michael Hennerich2acde902007-10-11 00:24:40 +0800890 set_label(ident, "free");
891
Yi Li6a01f232009-01-07 23:14:39 +0800892 local_irq_restore_hw(flags);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800893}
894EXPORT_SYMBOL(peripheral_free);
895
Mike Frysinger68179372008-04-24 05:04:24 +0800896void peripheral_free_list(const unsigned short per[])
Michael Hennerichc58c2142007-10-04 00:35:05 +0800897{
898 u16 cnt;
Mike Frysingerd171c232008-03-26 08:35:46 +0800899 for (cnt = 0; per[cnt] != 0; cnt++)
Michael Hennerichc58c2142007-10-04 00:35:05 +0800900 peripheral_free(per[cnt]);
Michael Hennerichc58c2142007-10-04 00:35:05 +0800901}
902EXPORT_SYMBOL(peripheral_free_list);
903
Bryan Wu1394f032007-05-06 14:50:22 -0700904/***********************************************************
905*
906* FUNCTIONS: Blackfin GPIO Driver
907*
908* INPUTS/OUTPUTS:
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800909* gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
910* label String
Bryan Wu1394f032007-05-06 14:50:22 -0700911*
912* DESCRIPTION: Blackfin GPIO Driver API
913*
914* CAUTION:
915*************************************************************
916* MODIFICATION HISTORY :
917**************************************************************/
918
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800919int bfin_gpio_request(unsigned gpio, const char *label)
Bryan Wu1394f032007-05-06 14:50:22 -0700920{
921 unsigned long flags;
922
923 if (check_gpio(gpio) < 0)
924 return -EINVAL;
925
Yi Li6a01f232009-01-07 23:14:39 +0800926 local_irq_save_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700927
Michael Hennerich2acde902007-10-11 00:24:40 +0800928 /*
929 * Allow that the identical GPIO can
930 * be requested from the same driver twice
931 * Do nothing and return -
932 */
933
934 if (cmp_label(gpio, label) == 0) {
Yi Li6a01f232009-01-07 23:14:39 +0800935 local_irq_restore_hw(flags);
Michael Hennerich2acde902007-10-11 00:24:40 +0800936 return 0;
937 }
938
Michael Hennerichc58c2142007-10-04 00:35:05 +0800939 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800940 if (system_state == SYSTEM_BOOTING)
941 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800942 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
Graf Yang9570ff42009-01-07 23:14:38 +0800943 gpio, get_label(gpio));
Yi Li6a01f232009-01-07 23:14:39 +0800944 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700945 return -EBUSY;
946 }
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800947 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800948 if (system_state == SYSTEM_BOOTING)
949 dump_stack();
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800950 printk(KERN_ERR
951 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
952 gpio, get_label(gpio));
Yi Li6a01f232009-01-07 23:14:39 +0800953 local_irq_restore_hw(flags);
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800954 return -EBUSY;
955 }
Michael Hennericha2be3932009-02-04 16:49:45 +0800956 if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Graf Yang9570ff42009-01-07 23:14:38 +0800957 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!"
958 " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio);
Michael Hennericha2be3932009-02-04 16:49:45 +0800959 }
Mike Frysinger269647d2009-03-28 20:32:57 +0800960#ifndef CONFIG_BF54x
Michael Hennericha2be3932009-02-04 16:49:45 +0800961 else { /* Reset POLAR setting when acquiring a gpio for the first time */
962 set_gpio_polar(gpio, 0);
963 }
964#endif
Michael Hennerichd2b11a42007-08-28 16:47:46 +0800965
Michael Hennerichc58c2142007-10-04 00:35:05 +0800966 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
Graf Yang9570ff42009-01-07 23:14:38 +0800967 set_label(gpio, label);
Bryan Wu1394f032007-05-06 14:50:22 -0700968
Yi Li6a01f232009-01-07 23:14:39 +0800969 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700970
971 port_setup(gpio, GPIO_USAGE);
972
973 return 0;
974}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800975EXPORT_SYMBOL(bfin_gpio_request);
Bryan Wu1394f032007-05-06 14:50:22 -0700976
Michael Hennericha4f0b32c2008-11-18 17:48:22 +0800977void bfin_gpio_free(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -0700978{
979 unsigned long flags;
980
981 if (check_gpio(gpio) < 0)
982 return;
983
Uwe Kleine-Koenig45c4f2a2009-02-04 17:02:30 +0800984 might_sleep();
985
Yi Li6a01f232009-01-07 23:14:39 +0800986 local_irq_save_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700987
Michael Hennerichc58c2142007-10-04 00:35:05 +0800988 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
Robin Getzd6879c52009-03-29 01:10:30 +0800989 if (system_state == SYSTEM_BOOTING)
990 dump_stack();
Mike Frysingerf85c4ab2008-03-26 08:34:23 +0800991 gpio_error(gpio);
Yi Li6a01f232009-01-07 23:14:39 +0800992 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700993 return;
994 }
995
Michael Hennerichc58c2142007-10-04 00:35:05 +0800996 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
Bryan Wu1394f032007-05-06 14:50:22 -0700997
Michael Hennerich2acde902007-10-11 00:24:40 +0800998 set_label(gpio, "free");
999
Yi Li6a01f232009-01-07 23:14:39 +08001000 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -07001001}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001002EXPORT_SYMBOL(bfin_gpio_free);
Bryan Wu1394f032007-05-06 14:50:22 -07001003
Graf Yang9570ff42009-01-07 23:14:38 +08001004int bfin_gpio_irq_request(unsigned gpio, const char *label)
1005{
1006 unsigned long flags;
1007
1008 if (check_gpio(gpio) < 0)
1009 return -EINVAL;
1010
Yi Li6a01f232009-01-07 23:14:39 +08001011 local_irq_save_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001012
Graf Yang9570ff42009-01-07 23:14:38 +08001013 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
Robin Getzd6879c52009-03-29 01:10:30 +08001014 if (system_state == SYSTEM_BOOTING)
1015 dump_stack();
Graf Yang9570ff42009-01-07 23:14:38 +08001016 printk(KERN_ERR
1017 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
1018 gpio, get_label(gpio));
Yi Li6a01f232009-01-07 23:14:39 +08001019 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001020 return -EBUSY;
1021 }
1022 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))
1023 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved by %s! "
1024 "(Documentation/blackfin/bfin-gpio-notes.txt)\n",
1025 gpio, get_label(gpio));
1026
1027 reserved_gpio_irq_map[gpio_bank(gpio)] |= gpio_bit(gpio);
1028 set_label(gpio, label);
1029
Yi Li6a01f232009-01-07 23:14:39 +08001030 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001031
1032 port_setup(gpio, GPIO_USAGE);
1033
1034 return 0;
1035}
1036
1037void bfin_gpio_irq_free(unsigned gpio)
1038{
1039 unsigned long flags;
1040
1041 if (check_gpio(gpio) < 0)
1042 return;
1043
Yi Li6a01f232009-01-07 23:14:39 +08001044 local_irq_save_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001045
1046 if (unlikely(!(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
Robin Getzd6879c52009-03-29 01:10:30 +08001047 if (system_state == SYSTEM_BOOTING)
1048 dump_stack();
Graf Yang9570ff42009-01-07 23:14:38 +08001049 gpio_error(gpio);
Yi Li6a01f232009-01-07 23:14:39 +08001050 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001051 return;
1052 }
1053
1054 reserved_gpio_irq_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
1055
1056 set_label(gpio, "free");
1057
Yi Li6a01f232009-01-07 23:14:39 +08001058 local_irq_restore_hw(flags);
Graf Yang9570ff42009-01-07 23:14:38 +08001059}
1060
Mike Frysingerf5563092009-02-04 16:49:45 +08001061static inline void __bfin_gpio_direction_input(unsigned gpio)
1062{
Mike Frysinger269647d2009-03-28 20:32:57 +08001063#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001064 gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio);
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001065#else
Mike Frysingerf5563092009-02-04 16:49:45 +08001066 gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
1067#endif
1068 gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
Michael Hennerich803a8d22008-05-17 16:01:51 +08001069}
Michael Hennerich803a8d22008-05-17 16:01:51 +08001070
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001071int bfin_gpio_direction_input(unsigned gpio)
Bryan Wu1394f032007-05-06 14:50:22 -07001072{
1073 unsigned long flags;
1074
Michael Hennerichacbcd262008-01-22 18:36:20 +08001075 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1076 gpio_error(gpio);
1077 return -EINVAL;
1078 }
Bryan Wu1394f032007-05-06 14:50:22 -07001079
Yi Li6a01f232009-01-07 23:14:39 +08001080 local_irq_save_hw(flags);
Mike Frysingerf5563092009-02-04 16:49:45 +08001081 __bfin_gpio_direction_input(gpio);
Michael Hennerich2b393312007-10-10 16:58:49 +08001082 AWA_DUMMY_READ(inen);
Yi Li6a01f232009-01-07 23:14:39 +08001083 local_irq_restore_hw(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001084
1085 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001086}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001087EXPORT_SYMBOL(bfin_gpio_direction_input);
Bryan Wu1394f032007-05-06 14:50:22 -07001088
Mike Frysingerf5563092009-02-04 16:49:45 +08001089void bfin_gpio_irq_prepare(unsigned gpio)
1090{
Mike Frysinger269647d2009-03-28 20:32:57 +08001091#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001092 unsigned long flags;
1093#endif
1094
1095 port_setup(gpio, GPIO_USAGE);
1096
Mike Frysinger269647d2009-03-28 20:32:57 +08001097#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001098 local_irq_save_hw(flags);
1099 __bfin_gpio_direction_input(gpio);
1100 local_irq_restore_hw(flags);
1101#endif
1102}
1103
1104void bfin_gpio_set_value(unsigned gpio, int arg)
1105{
1106 if (arg)
1107 gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
1108 else
1109 gpio_array[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
1110}
1111EXPORT_SYMBOL(bfin_gpio_set_value);
1112
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001113int bfin_gpio_direction_output(unsigned gpio, int value)
Bryan Wu1394f032007-05-06 14:50:22 -07001114{
1115 unsigned long flags;
1116
Michael Hennerichacbcd262008-01-22 18:36:20 +08001117 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1118 gpio_error(gpio);
1119 return -EINVAL;
1120 }
Bryan Wu1394f032007-05-06 14:50:22 -07001121
Yi Li6a01f232009-01-07 23:14:39 +08001122 local_irq_save_hw(flags);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001123
Mike Frysingerf5563092009-02-04 16:49:45 +08001124 gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
1125 gpio_set_value(gpio, value);
Mike Frysinger269647d2009-03-28 20:32:57 +08001126#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001127 gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio);
1128#else
1129 gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
1130#endif
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001131
Michael Hennerich2b393312007-10-10 16:58:49 +08001132 AWA_DUMMY_READ(dir);
Yi Li6a01f232009-01-07 23:14:39 +08001133 local_irq_restore_hw(flags);
Michael Hennerichacbcd262008-01-22 18:36:20 +08001134
1135 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -07001136}
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001137EXPORT_SYMBOL(bfin_gpio_direction_output);
Mike Frysinger168f1212007-10-11 00:22:35 +08001138
Mike Frysingerf5563092009-02-04 16:49:45 +08001139int bfin_gpio_get_value(unsigned gpio)
1140{
Mike Frysinger269647d2009-03-28 20:32:57 +08001141#ifdef CONFIG_BF54x
Mike Frysingerf5563092009-02-04 16:49:45 +08001142 return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio)));
1143#else
1144 unsigned long flags;
1145
1146 if (unlikely(get_gpio_edge(gpio))) {
1147 int ret;
1148 local_irq_save_hw(flags);
1149 set_gpio_edge(gpio, 0);
1150 ret = get_gpio_data(gpio);
1151 set_gpio_edge(gpio, 1);
1152 local_irq_restore_hw(flags);
1153 return ret;
1154 } else
1155 return get_gpio_data(gpio);
1156#endif
1157}
1158EXPORT_SYMBOL(bfin_gpio_get_value);
1159
Mike Frysinger168f1212007-10-11 00:22:35 +08001160/* If we are booting from SPI and our board lacks a strong enough pull up,
1161 * the core can reset and execute the bootrom faster than the resistor can
1162 * pull the signal logically high. To work around this (common) error in
1163 * board design, we explicitly set the pin back to GPIO mode, force /CS
1164 * high, and wait for the electrons to do their thing.
1165 *
1166 * This function only makes sense to be called from reset code, but it
1167 * lives here as we need to force all the GPIO states w/out going through
1168 * BUG() checks and such.
1169 */
Sonic Zhangb52dae32009-02-04 16:49:45 +08001170void bfin_reset_boot_spi_cs(unsigned short pin)
Mike Frysinger168f1212007-10-11 00:22:35 +08001171{
Sonic Zhangb52dae32009-02-04 16:49:45 +08001172 unsigned short gpio = P_IDENT(pin);
Michael Hennerich4d5f4ed2007-08-27 16:46:17 +08001173 port_setup(gpio, GPIO_USAGE);
Mike Frysingerf5563092009-02-04 16:49:45 +08001174 gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
Michael Hennericha2c8cfe2008-01-22 17:20:10 +08001175 AWA_DUMMY_READ(data_set);
Mike Frysinger168f1212007-10-11 00:22:35 +08001176 udelay(1);
1177}
Michael Hennerichd2b11a42007-08-28 16:47:46 +08001178
Mike Frysinger1545a112007-12-24 16:54:48 +08001179#if defined(CONFIG_PROC_FS)
1180static int gpio_proc_read(char *buf, char **start, off_t offset,
1181 int len, int *unused_i, void *unused_v)
1182{
Graf Yang9570ff42009-01-07 23:14:38 +08001183 int c, irq, gpio, outlen = 0;
Mike Frysinger1545a112007-12-24 16:54:48 +08001184
1185 for (c = 0; c < MAX_RESOURCES; c++) {
Graf Yang9570ff42009-01-07 23:14:38 +08001186 irq = reserved_gpio_irq_map[gpio_bank(c)] & gpio_bit(c);
1187 gpio = reserved_gpio_map[gpio_bank(c)] & gpio_bit(c);
1188 if (!check_gpio(c) && (gpio || irq))
1189 len = sprintf(buf, "GPIO_%d: \t%s%s \t\tGPIO %s\n", c,
1190 get_label(c), (gpio && irq) ? " *" : "",
1191 get_gpio_dir(c) ? "OUTPUT" : "INPUT");
Mike Frysinger1545a112007-12-24 16:54:48 +08001192 else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c))
Graf Yang8eb3e3b2008-11-18 17:48:22 +08001193 len = sprintf(buf, "GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c));
Mike Frysinger1545a112007-12-24 16:54:48 +08001194 else
1195 continue;
1196 buf += len;
1197 outlen += len;
1198 }
1199 return outlen;
1200}
1201
1202static __init int gpio_register_proc(void)
1203{
1204 struct proc_dir_entry *proc_gpio;
1205
1206 proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
1207 if (proc_gpio)
1208 proc_gpio->read_proc = gpio_proc_read;
1209 return proc_gpio != NULL;
1210}
Mike Frysinger1545a112007-12-24 16:54:48 +08001211__initcall(gpio_register_proc);
1212#endif
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001213
1214#ifdef CONFIG_GPIOLIB
1215int bfin_gpiolib_direction_input(struct gpio_chip *chip, unsigned gpio)
1216{
1217 return bfin_gpio_direction_input(gpio);
1218}
1219
1220int bfin_gpiolib_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
1221{
1222 return bfin_gpio_direction_output(gpio, level);
1223}
1224
1225int bfin_gpiolib_get_value(struct gpio_chip *chip, unsigned gpio)
1226{
1227 return bfin_gpio_get_value(gpio);
1228}
1229
1230void bfin_gpiolib_set_value(struct gpio_chip *chip, unsigned gpio, int value)
1231{
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001232 return bfin_gpio_set_value(gpio, value);
Michael Hennericha4f0b32c2008-11-18 17:48:22 +08001233}
1234
1235int bfin_gpiolib_gpio_request(struct gpio_chip *chip, unsigned gpio)
1236{
1237 return bfin_gpio_request(gpio, chip->label);
1238}
1239
1240void bfin_gpiolib_gpio_free(struct gpio_chip *chip, unsigned gpio)
1241{
1242 return bfin_gpio_free(gpio);
1243}
1244
1245static struct gpio_chip bfin_chip = {
1246 .label = "Blackfin-GPIOlib",
1247 .direction_input = bfin_gpiolib_direction_input,
1248 .get = bfin_gpiolib_get_value,
1249 .direction_output = bfin_gpiolib_direction_output,
1250 .set = bfin_gpiolib_set_value,
1251 .request = bfin_gpiolib_gpio_request,
1252 .free = bfin_gpiolib_gpio_free,
1253 .base = 0,
1254 .ngpio = MAX_BLACKFIN_GPIOS,
1255};
1256
1257static int __init bfin_gpiolib_setup(void)
1258{
1259 return gpiochip_add(&bfin_chip);
1260}
1261arch_initcall(bfin_gpiolib_setup);
1262#endif