2 * arch/arm/mach-ns9xxx/gpio.c
4 * Copyright (C) 2006,2007 by Digi International Inc.
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/kernel.h>
12 #include <linux/compiler.h>
13 #include <linux/init.h>
14 #include <linux/spinlock.h>
15 #include <linux/module.h>
16 #include <linux/bitops.h>
18 #include <mach/gpio.h>
19 #include <mach/processor.h>
20 #include <mach/processor-ns9360.h>
22 #include <asm/types.h>
24 #include "gpio-ns9360.h"
26 #if defined(CONFIG_PROCESSOR_NS9360)
28 #elif defined(CONFIG_PROCESSOR_NS9750)
32 /* protects BBU_GCONFx and BBU_GCTRLx */
33 static spinlock_t gpio_lock = __SPIN_LOCK_UNLOCKED(gpio_lock);
35 /* only access gpiores with atomic ops */
36 static DECLARE_BITMAP(gpiores, GPIO_MAX + 1);
38 static inline int ns9xxx_valid_gpio(unsigned gpio)
40 #if defined(CONFIG_PROCESSOR_NS9360)
41 if (processor_is_ns9360())
45 #if defined(CONFIG_PROCESSOR_NS9750)
46 if (processor_is_ns9750())
56 int gpio_request(unsigned gpio, const char *label)
58 if (likely(ns9xxx_valid_gpio(gpio)))
59 return test_and_set_bit(gpio, gpiores) ? -EBUSY : 0;
63 EXPORT_SYMBOL(gpio_request);
65 void gpio_free(unsigned gpio)
68 clear_bit(gpio, gpiores);
71 EXPORT_SYMBOL(gpio_free);
73 int gpio_direction_input(unsigned gpio)
75 if (likely(ns9xxx_valid_gpio(gpio))) {
79 spin_lock_irqsave(&gpio_lock, flags);
80 #if defined(CONFIG_PROCESSOR_NS9360)
81 if (processor_is_ns9360())
82 ret = __ns9360_gpio_configure(gpio, 0, 0, 3);
87 spin_unlock_irqrestore(&gpio_lock, flags);
94 EXPORT_SYMBOL(gpio_direction_input);
96 int gpio_direction_output(unsigned gpio, int value)
98 if (likely(ns9xxx_valid_gpio(gpio))) {
102 gpio_set_value(gpio, value);
104 spin_lock_irqsave(&gpio_lock, flags);
105 #if defined(CONFIG_PROCESSOR_NS9360)
106 if (processor_is_ns9360())
107 ret = __ns9360_gpio_configure(gpio, 1, 0, 3);
112 spin_unlock_irqrestore(&gpio_lock, flags);
118 EXPORT_SYMBOL(gpio_direction_output);
120 int gpio_get_value(unsigned gpio)
122 #if defined(CONFIG_PROCESSOR_NS9360)
123 if (processor_is_ns9360())
124 return ns9360_gpio_get_value(gpio);
132 EXPORT_SYMBOL(gpio_get_value);
134 void gpio_set_value(unsigned gpio, int value)
137 spin_lock_irqsave(&gpio_lock, flags);
138 #if defined(CONFIG_PROCESSOR_NS9360)
139 if (processor_is_ns9360())
140 ns9360_gpio_set_value(gpio, value);
145 spin_unlock_irqrestore(&gpio_lock, flags);
147 EXPORT_SYMBOL(gpio_set_value);