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/compiler.h>
12 #include <linux/init.h>
13 #include <linux/spinlock.h>
14 #include <linux/module.h>
16 #include <asm/arch/gpio.h>
17 #include <asm/arch/processor.h>
18 #include <asm/arch/processor-ns9360.h>
20 #include <asm/types.h>
21 #include <asm/bitops.h>
23 #include "gpio-ns9360.h"
25 #if defined(CONFIG_PROCESSOR_NS9360)
27 #elif defined(CONFIG_PROCESSOR_NS9750)
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())
44 #if defined(CONFIG_PROCESSOR_NS9750)
45 if (processor_is_ns9750())
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;
62 EXPORT_SYMBOL(gpio_request
);
64 void gpio_free(unsigned gpio
)
66 clear_bit(gpio
, gpiores
);
69 EXPORT_SYMBOL(gpio_free
);
71 int gpio_direction_input(unsigned gpio
)
73 if (likely(ns9xxx_valid_gpio(gpio
))) {
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);
85 spin_unlock_irqrestore(&gpio_lock
, flags
);
92 EXPORT_SYMBOL(gpio_direction_input
);
94 int gpio_direction_output(unsigned gpio
, int value
)
96 if (likely(ns9xxx_valid_gpio(gpio
))) {
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);
110 spin_unlock_irqrestore(&gpio_lock
, flags
);
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
);
130 EXPORT_SYMBOL(gpio_get_value
);
132 void gpio_set_value(unsigned gpio
, int value
)
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
);
143 spin_unlock_irqrestore(&gpio_lock
, flags
);
145 EXPORT_SYMBOL(gpio_set_value
);