USB: ftdi_usb: Eliminate ioctl and BKL ioctl use
[linux-2.6/libata-dev.git] / arch / arm / mach-ns9xxx / gpio.c
blobb3c963b0c8f5414bb9713d6897a8040da3736703
1 /*
2 * arch/arm/mach-ns9xxx/gpio.c
4 * Copyright (C) 2006,2007 by Digi International Inc.
5 * All rights reserved.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 #include <linux/compiler.h>
12 #include <linux/init.h>
13 #include <linux/spinlock.h>
14 #include <linux/module.h>
16 #include <asm/arch-ns9xxx/gpio.h>
17 #include <asm/arch-ns9xxx/processor.h>
18 #include <asm/arch-ns9xxx/processor-ns9360.h>
19 #include <asm/bug.h>
20 #include <asm/types.h>
21 #include <asm/bitops.h>
23 #include "gpio-ns9360.h"
25 #if defined(CONFIG_PROCESSOR_NS9360)
26 #define GPIO_MAX 72
27 #elif defined(CONFIG_PROCESSOR_NS9750)
28 #define GPIO_MAX 49
29 #endif
31 /* protects BBU_GCONFx and BBU_GCTRLx */
32 static spinlock_t gpio_lock = __SPIN_LOCK_UNLOCKED(gpio_lock);
34 /* only access gpiores with atomic ops */
35 static DECLARE_BITMAP(gpiores, GPIO_MAX + 1);
37 static inline int ns9xxx_valid_gpio(unsigned gpio)
39 #if defined(CONFIG_PROCESSOR_NS9360)
40 if (processor_is_ns9360())
41 return gpio <= 72;
42 else
43 #endif
44 #if defined(CONFIG_PROCESSOR_NS9750)
45 if (processor_is_ns9750())
46 return gpio <= 49;
47 else
48 #endif
50 BUG();
51 return 0;
55 int gpio_request(unsigned gpio, const char *label)
57 if (likely(ns9xxx_valid_gpio(gpio)))
58 return test_and_set_bit(gpio, gpiores) ? -EBUSY : 0;
59 else
60 return -EINVAL;
62 EXPORT_SYMBOL(gpio_request);
64 void gpio_free(unsigned gpio)
66 clear_bit(gpio, gpiores);
67 return;
69 EXPORT_SYMBOL(gpio_free);
71 int gpio_direction_input(unsigned gpio)
73 if (likely(ns9xxx_valid_gpio(gpio))) {
74 int ret = -EINVAL;
75 unsigned long flags;
77 spin_lock_irqsave(&gpio_lock, flags);
78 #if defined(CONFIG_PROCESSOR_NS9360)
79 if (processor_is_ns9360())
80 ret = __ns9360_gpio_configure(gpio, 0, 0, 3);
81 else
82 #endif
83 BUG();
85 spin_unlock_irqrestore(&gpio_lock, flags);
87 return ret;
89 } else
90 return -EINVAL;
92 EXPORT_SYMBOL(gpio_direction_input);
94 int gpio_direction_output(unsigned gpio, int value)
96 if (likely(ns9xxx_valid_gpio(gpio))) {
97 int ret = -EINVAL;
98 unsigned long flags;
100 gpio_set_value(gpio, value);
102 spin_lock_irqsave(&gpio_lock, flags);
103 #if defined(CONFIG_PROCESSOR_NS9360)
104 if (processor_is_ns9360())
105 ret = __ns9360_gpio_configure(gpio, 1, 0, 3);
106 else
107 #endif
108 BUG();
110 spin_unlock_irqrestore(&gpio_lock, flags);
112 return ret;
113 } else
114 return -EINVAL;
116 EXPORT_SYMBOL(gpio_direction_output);
118 int gpio_get_value(unsigned gpio)
120 #if defined(CONFIG_PROCESSOR_NS9360)
121 if (processor_is_ns9360())
122 return ns9360_gpio_get_value(gpio);
123 else
124 #endif
126 BUG();
127 return -EINVAL;
130 EXPORT_SYMBOL(gpio_get_value);
132 void gpio_set_value(unsigned gpio, int value)
134 unsigned long flags;
135 spin_lock_irqsave(&gpio_lock, flags);
136 #if defined(CONFIG_PROCESSOR_NS9360)
137 if (processor_is_ns9360())
138 ns9360_gpio_set_value(gpio, value);
139 else
140 #endif
141 BUG();
143 spin_unlock_irqrestore(&gpio_lock, flags);
145 EXPORT_SYMBOL(gpio_set_value);