10 #include <linux/module.h>
20 #if ANOMALY_05000311 || ANOMALY_05000323
23 AWA_data_clear =
SYSCR,
40 #elif ANOMALY_05000323
45 #define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
47 #define AWA_DUMMY_READ(...) do { } while (0)
51 #if defined(BF533_FAMILY) || defined(BF538_FAMILY)
53 #elif defined(CONFIG_BF52x) || defined(
BF537_FAMILY) || defined(CONFIG_BF51x)
61 #elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
69 #
if defined(CONFIG_BF54x)
79 #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
80 static unsigned short *
const port_fer[] = {
86 # if !defined(BF537_FAMILY)
87 static unsigned short *
const port_mux[] = {
94 u8 pmux_offset[][16] = {
95 # if defined(CONFIG_BF52x)
96 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 },
97 { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 },
98 { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 },
99 # elif defined(CONFIG_BF51x)
100 { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 },
101 { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 },
102 { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 },
107 #elif defined(BF538_FAMILY)
108 static unsigned short *
const port_fer[] = {
115 #define RESOURCE_LABEL_SIZE 16
117 static struct str_ident {
121 #if defined(CONFIG_PM)
124 static unsigned short port_fer_saved[3];
128 static void gpio_error(
unsigned gpio)
133 static void set_label(
unsigned short ident,
const char *
label)
142 static char *get_label(
unsigned short ident)
144 return (*str_ident[ident].
name ? str_ident[ident].
name :
"UNKNOWN");
147 static int cmp_label(
unsigned short ident,
const char *label)
160 #define map_entry(m, i) reserved_##m##_map[gpio_bank(i)]
161 #define is_reserved(m, i, e) (map_entry(m, i) & gpio_bit(i))
162 #define reserve(m, i) (map_entry(m, i) |= gpio_bit(i))
163 #define unreserve(m, i) (map_entry(m, i) &= ~gpio_bit(i))
164 #define DECLARE_RESERVED_MAP(m, c) static unsigned short reserved_##m##_map[c]
172 #if defined(CONFIG_BF54x)
183 static void port_setup(
unsigned gpio,
unsigned short usage)
185 #if defined(BF538_FAMILY)
209 #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
215 #elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
225 static const s8 port_mux[] = {
253 static int portmux_group_check(
unsigned short per)
267 if (port_mux[m] != offset)
273 pfunc = (pmux >>
offset) & 3;
275 pfunc = (pmux >>
offset) & 1;
276 if (pfunc !=
function) {
277 pr_err(
"pin group conflict! request pin %d func %d conflict with pin %d func %d\n",
278 ident,
function, m, pfunc);
301 pmux |= (
function <<
offset);
304 #elif defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
314 pmux |= (
function & 0x3) << (2 *
gpio_sub_n(ident));
319 inline u16 get_portmux(
unsigned short per)
323 return (pmux >> (2 *
gpio_sub_n(ident)) & 0x3);
325 static int portmux_group_check(
unsigned short per)
329 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
330 static int portmux_group_check(
unsigned short per)
338 if (offset != pmux_offset[
gpio_bank(ident)][pin])
342 if (gpiopin == ident)
348 pfunc = (pfunc >>
offset) & 3;
349 if (pfunc !=
function) {
350 pr_err(
"pin group conflict! request pin %d func %d conflict with pin %d func %d\n",
351 ident,
function, gpiopin, pfunc);
367 if (((pmux >> offset) & 3) ==
function)
370 pmux |= (
function & 3) << offset;
375 # define portmux_setup(...) do { } while (0)
376 static int portmux_group_check(
unsigned short per)
382 #if !(defined(CONFIG_BF54x) || defined(CONFIG_BF60x))
402 #define SET_GPIO(name) \
403 void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
405 unsigned long flags; \
406 flags = hard_local_irq_save(); \
408 gpio_array[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
410 gpio_array[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
411 AWA_DUMMY_READ(name); \
412 hard_local_irq_restore(flags); \
414 EXPORT_SYMBOL(set_gpio_ ## name);
423 #define SET_GPIO_SC(name) \
424 void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
426 unsigned long flags; \
427 if (ANOMALY_05000311 || ANOMALY_05000323) \
428 flags = hard_local_irq_save(); \
430 gpio_array[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
432 gpio_array[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
433 if (ANOMALY_05000311 || ANOMALY_05000323) { \
434 AWA_DUMMY_READ(name); \
435 hard_local_irq_restore(flags); \
438 EXPORT_SYMBOL(set_gpio_ ## name);
460 #define SET_GPIO_P(name) \
461 void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
463 unsigned long flags; \
464 if (ANOMALY_05000311 || ANOMALY_05000323) \
465 flags = hard_local_irq_save(); \
466 gpio_array[gpio_bank(gpio)]->name = arg; \
467 if (ANOMALY_05000311 || ANOMALY_05000323) { \
468 AWA_DUMMY_READ(name); \
469 hard_local_irq_restore(flags); \
472 EXPORT_SYMBOL(set_gpiop_ ## name);
484 #define GET_GPIO(name) \
485 unsigned short get_gpio_ ## name(unsigned gpio) \
487 unsigned long flags; \
488 unsigned short ret; \
489 if (ANOMALY_05000311 || ANOMALY_05000323) \
490 flags = hard_local_irq_save(); \
491 ret = 0x01 & (gpio_array[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
492 if (ANOMALY_05000311 || ANOMALY_05000323) { \
493 AWA_DUMMY_READ(name); \
494 hard_local_irq_restore(flags); \
498 EXPORT_SYMBOL(get_gpio_ ## name);
511 #define GET_GPIO_P(name) \
512 unsigned short get_gpiop_ ## name(unsigned gpio) \
514 unsigned long flags; \
515 unsigned short ret; \
516 if (ANOMALY_05000311 || ANOMALY_05000323) \
517 flags = hard_local_irq_save(); \
518 ret = (gpio_array[gpio_bank(gpio)]->name); \
519 if (ANOMALY_05000311 || ANOMALY_05000323) { \
520 AWA_DUMMY_READ(name); \
521 hard_local_irq_restore(flags); \
525 EXPORT_SYMBOL(get_gpiop_ ## name);
540 static const unsigned int sic_iwr_irqs[] = {
541 #if defined(BF533_FAMILY)
543 #elif defined(BF537_FAMILY)
545 #elif defined(BF538_FAMILY)
547 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
549 #elif defined(BF561_FAMILY)
552 # error no SIC_IWR defined
575 int gpio_pm_wakeup_ctrl(
unsigned gpio,
unsigned ctrl)
594 int bfin_pm_standby_ctrl(
unsigned ctrl)
608 void bfin_gpio_pm_hibernate_suspend(
void)
614 port_fer_saved[i] = *port_fer[i];
620 #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
621 gpio_bank_saved[bank].fer = *port_fer[bank];
622 #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
623 gpio_bank_saved[bank].mux = *port_mux[bank];
629 gpio_bank_saved[bank].data = gpio_array[bank]->
data;
630 gpio_bank_saved[bank].inen = gpio_array[bank]->
inen;
631 gpio_bank_saved[bank].polar = gpio_array[bank]->
polar;
632 gpio_bank_saved[bank].dir = gpio_array[bank]->
dir;
633 gpio_bank_saved[bank].edge = gpio_array[bank]->
edge;
634 gpio_bank_saved[bank].both = gpio_array[bank]->
both;
635 gpio_bank_saved[bank].maska = gpio_array[bank]->
maska;
638 #ifdef BFIN_SPECIAL_GPIO_BANKS
639 bfin_special_gpio_pm_hibernate_suspend();
645 void bfin_gpio_pm_hibernate_restore(
void)
651 *port_fer[i] = port_fer_saved[i];
657 #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
658 #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
659 *port_mux[bank] = gpio_bank_saved[bank].mux;
664 *port_fer[bank] = gpio_bank_saved[bank].fer;
666 gpio_array[bank]->
inen = gpio_bank_saved[bank].inen;
667 gpio_array[bank]->
data_set = gpio_bank_saved[bank].data
668 & gpio_bank_saved[bank].dir;
669 gpio_array[bank]->
dir = gpio_bank_saved[bank].dir;
670 gpio_array[bank]->
polar = gpio_bank_saved[bank].polar;
671 gpio_array[bank]->
edge = gpio_bank_saved[bank].edge;
672 gpio_array[bank]->
both = gpio_bank_saved[bank].both;
673 gpio_array[bank]->
maska = gpio_bank_saved[bank].maska;
676 #ifdef BFIN_SPECIAL_GPIO_BANKS
677 bfin_special_gpio_pm_hibernate_restore();
688 int bfin_pm_standby_ctrl(
unsigned ctrl)
693 void bfin_gpio_pm_hibernate_suspend(
void)
700 gpio_bank_saved[bank].fer = gpio_array[bank]->
port_fer;
701 gpio_bank_saved[bank].mux = gpio_array[bank]->
port_mux;
702 gpio_bank_saved[bank].data = gpio_array[bank]->
data;
703 gpio_bank_saved[bank].inen = gpio_array[bank]->
inen;
704 gpio_bank_saved[bank].dir = gpio_array[bank]->
dir_set;
708 void bfin_gpio_pm_hibernate_restore(
void)
715 gpio_array[bank]->
port_mux = gpio_bank_saved[bank].mux;
716 gpio_array[bank]->
port_fer = gpio_bank_saved[bank].fer;
717 gpio_array[bank]->
inen = gpio_bank_saved[bank].inen;
718 gpio_array[bank]->
data_set = gpio_bank_saved[bank].data
719 & gpio_bank_saved[bank].dir;
720 gpio_array[bank]->
dir_set = gpio_bank_saved[bank].dir;
752 unsigned short ident =
P_IDENT(per);
775 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
776 __func__, ident, get_label(ident));
788 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
791 if (!(per & P_MAYSHARE)) {
798 if (cmp_label(ident, label) == 0)
804 "%s: Peripheral %d function %d is already reserved by %s !\n",
805 __func__, ident,
P_FUNCT2MUX(per), get_label(ident));
811 if (
unlikely(portmux_group_check(per))) {
822 set_label(ident, label);
833 for (cnt = 0; per[
cnt] != 0; cnt++) {
838 for ( ; cnt > 0; cnt--)
852 unsigned short ident =
P_IDENT(per);
854 if (per & P_DONTCARE)
857 if (!(per & P_DEFINED))
872 set_label(ident,
"free");
881 for (cnt = 0; per[
cnt] != 0; cnt++)
916 if (cmp_label(gpio, label) == 0) {
924 printk(
KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
925 gpio, get_label(gpio));
933 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
934 gpio, get_label(gpio));
940 " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio);
942 #if !(defined(CONFIG_BF54x) || defined(CONFIG_BF60x))
949 set_label(gpio, label);
980 set_label(gpio,
"free");
986 #ifdef BFIN_SPECIAL_GPIO_BANKS
989 int bfin_special_gpio_request(
unsigned gpio,
const char *label)
1001 if (cmp_label(gpio, label) == 0) {
1008 printk(
KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
1009 gpio, get_label(gpio));
1016 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
1017 gpio, get_label(gpio));
1025 set_label(gpio, label);
1033 void bfin_special_gpio_free(
unsigned gpio)
1035 unsigned long flags;
1049 set_label(gpio,
"free");
1058 unsigned long flags;
1069 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
1070 gpio, get_label(gpio));
1076 "(Documentation/blackfin/bfin-gpio-notes.txt)\n",
1077 gpio, get_label(gpio));
1080 set_label(gpio, label);
1091 unsigned long flags;
1108 set_label(gpio,
"free");
1113 static inline void __bfin_gpio_direction_input(
unsigned gpio)
1115 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
1125 unsigned long flags;
1133 __bfin_gpio_direction_input(gpio);
1143 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
1144 unsigned long flags;
1149 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
1151 __bfin_gpio_direction_input(gpio);
1167 unsigned long flags;
1178 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
1193 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
1196 unsigned long flags;
1224 unsigned short gpio =
P_IDENT(pin);
1231 #if defined(CONFIG_PROC_FS)
1232 static int gpio_proc_show(
struct seq_file *m,
void *
v)
1240 seq_printf(m,
"GPIO_%d: \t%s%s \t\tGPIO %s\n", c,
1241 get_label(c), (gpio && irq) ?
" *" :
"",
1244 seq_printf(m,
"GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c));
1258 .
open = gpio_proc_open,
1264 static __init int gpio_register_proc(
void)
1268 proc_gpio = proc_create(
"gpio", 0,
NULL, &gpio_proc_ops);
1269 return proc_gpio ==
NULL;
1274 #ifdef CONFIG_GPIOLIB
1275 static int bfin_gpiolib_direction_input(
struct gpio_chip *
chip,
unsigned gpio)
1280 static int bfin_gpiolib_direction_output(
struct gpio_chip *
chip,
unsigned gpio,
int level)
1285 static int bfin_gpiolib_get_value(
struct gpio_chip *
chip,
unsigned gpio)
1290 static void bfin_gpiolib_set_value(
struct gpio_chip *
chip,
unsigned gpio,
int value)
1295 static int bfin_gpiolib_gpio_request(
struct gpio_chip *
chip,
unsigned gpio)
1300 static void bfin_gpiolib_gpio_free(
struct gpio_chip *
chip,
unsigned gpio)
1305 static int bfin_gpiolib_gpio_to_irq(
struct gpio_chip *
chip,
unsigned gpio)
1310 static struct gpio_chip bfin_chip = {
1311 .label =
"BFIN-GPIO",
1312 .direction_input = bfin_gpiolib_direction_input,
1313 .get = bfin_gpiolib_get_value,
1314 .direction_output = bfin_gpiolib_direction_output,
1315 .set = bfin_gpiolib_set_value,
1316 .request = bfin_gpiolib_gpio_request,
1317 .free = bfin_gpiolib_gpio_free,
1318 .to_irq = bfin_gpiolib_gpio_to_irq,
1323 static int __init bfin_gpiolib_setup(
void)