aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin/kernel/bfin_gpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/blackfin/kernel/bfin_gpio.c')
-rw-r--r--arch/blackfin/kernel/bfin_gpio.c111
1 files changed, 58 insertions, 53 deletions
diff --git a/arch/blackfin/kernel/bfin_gpio.c b/arch/blackfin/kernel/bfin_gpio.c
index 42833ee2b308..dc07ed08b37f 100644
--- a/arch/blackfin/kernel/bfin_gpio.c
+++ b/arch/blackfin/kernel/bfin_gpio.c
@@ -108,11 +108,7 @@ static unsigned short * const port_fer[] = {
108}; 108};
109#endif 109#endif
110 110
111static unsigned short reserved_gpio_map[GPIO_BANK_NUM]; 111#define RESOURCE_LABEL_SIZE 16
112static unsigned short reserved_peri_map[gpio_bank(MAX_RESOURCES)];
113static unsigned short reserved_gpio_irq_map[GPIO_BANK_NUM];
114
115#define RESOURCE_LABEL_SIZE 16
116 112
117static struct str_ident { 113static struct str_ident {
118 char name[RESOURCE_LABEL_SIZE]; 114 char name[RESOURCE_LABEL_SIZE];
@@ -122,19 +118,6 @@ static struct str_ident {
122static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM]; 118static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM];
123#endif 119#endif
124 120
125inline int check_gpio(unsigned gpio)
126{
127#if defined(CONFIG_BF54x)
128 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
129 || gpio == GPIO_PH14 || gpio == GPIO_PH15
130 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
131 return -EINVAL;
132#endif
133 if (gpio >= MAX_BLACKFIN_GPIOS)
134 return -EINVAL;
135 return 0;
136}
137
138static void gpio_error(unsigned gpio) 121static void gpio_error(unsigned gpio)
139{ 122{
140 printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio); 123 printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio);
@@ -167,6 +150,29 @@ static int cmp_label(unsigned short ident, const char *label)
167 return -EINVAL; 150 return -EINVAL;
168} 151}
169 152
153#define map_entry(m, i) reserved_##m##_map[gpio_bank(i)]
154#define is_reserved(m, i, e) (map_entry(m, i) & gpio_bit(i))
155#define reserve(m, i) (map_entry(m, i) |= gpio_bit(i))
156#define unreserve(m, i) (map_entry(m, i) &= ~gpio_bit(i))
157#define DECLARE_RESERVED_MAP(m, c) static unsigned short reserved_##m##_map[c]
158
159DECLARE_RESERVED_MAP(gpio, GPIO_BANK_NUM);
160DECLARE_RESERVED_MAP(peri, DIV_ROUND_UP(MAX_RESOURCES, GPIO_BANKSIZE));
161DECLARE_RESERVED_MAP(gpio_irq, GPIO_BANK_NUM);
162
163inline int check_gpio(unsigned gpio)
164{
165#if defined(CONFIG_BF54x)
166 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
167 || gpio == GPIO_PH14 || gpio == GPIO_PH15
168 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
169 return -EINVAL;
170#endif
171 if (gpio >= MAX_BLACKFIN_GPIOS)
172 return -EINVAL;
173 return 0;
174}
175
170static void port_setup(unsigned gpio, unsigned short usage) 176static void port_setup(unsigned gpio, unsigned short usage)
171{ 177{
172#if defined(BF538_FAMILY) 178#if defined(BF538_FAMILY)
@@ -475,7 +481,7 @@ GET_GPIO_P(maskb)
475 481
476 482
477#ifdef CONFIG_PM 483#ifdef CONFIG_PM
478static unsigned short wakeup_map[GPIO_BANK_NUM]; 484DECLARE_RESERVED_MAP(wakeup, GPIO_BANK_NUM);
479 485
480static const unsigned int sic_iwr_irqs[] = { 486static const unsigned int sic_iwr_irqs[] = {
481#if defined(BF533_FAMILY) 487#if defined(BF533_FAMILY)
@@ -521,9 +527,9 @@ int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl)
521 527
522 local_irq_save_hw(flags); 528 local_irq_save_hw(flags);
523 if (ctrl) 529 if (ctrl)
524 wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio); 530 reserve(wakeup, gpio);
525 else 531 else
526 wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); 532 unreserve(wakeup, gpio);
527 533
528 set_gpio_maskb(gpio, ctrl); 534 set_gpio_maskb(gpio, ctrl);
529 local_irq_restore_hw(flags); 535 local_irq_restore_hw(flags);
@@ -536,7 +542,7 @@ int bfin_pm_standby_ctrl(unsigned ctrl)
536 u16 bank, mask, i; 542 u16 bank, mask, i;
537 543
538 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { 544 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
539 mask = wakeup_map[gpio_bank(i)]; 545 mask = map_entry(wakeup, i);
540 bank = gpio_bank(i); 546 bank = gpio_bank(i);
541 547
542 if (mask) 548 if (mask)
@@ -653,7 +659,7 @@ EXPORT_SYMBOL(get_gpio_dir);
653 659
654/*********************************************************** 660/***********************************************************
655* 661*
656* FUNCTIONS: Blackfin Peripheral Resource Allocation 662* FUNCTIONS: Blackfin Peripheral Resource Allocation
657* and PortMux Setup 663* and PortMux Setup
658* 664*
659* INPUTS/OUTPUTS: 665* INPUTS/OUTPUTS:
@@ -689,8 +695,7 @@ int peripheral_request(unsigned short per, const char *label)
689 /* If a pin can be muxed as either GPIO or peripheral, make 695 /* If a pin can be muxed as either GPIO or peripheral, make
690 * sure it is not already a GPIO pin when we request it. 696 * sure it is not already a GPIO pin when we request it.
691 */ 697 */
692 if (unlikely(!check_gpio(ident) && 698 if (unlikely(!check_gpio(ident) && is_reserved(gpio, ident, 1))) {
693 reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
694 if (system_state == SYSTEM_BOOTING) 699 if (system_state == SYSTEM_BOOTING)
695 dump_stack(); 700 dump_stack();
696 printk(KERN_ERR 701 printk(KERN_ERR
@@ -700,7 +705,7 @@ int peripheral_request(unsigned short per, const char *label)
700 return -EBUSY; 705 return -EBUSY;
701 } 706 }
702 707
703 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) { 708 if (unlikely(is_reserved(peri, ident, 1))) {
704 709
705 /* 710 /*
706 * Pin functions like AMC address strobes my 711 * Pin functions like AMC address strobes my
@@ -731,7 +736,7 @@ int peripheral_request(unsigned short per, const char *label)
731 } 736 }
732 737
733 anyway: 738 anyway:
734 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident); 739 reserve(peri, ident);
735 740
736 portmux_setup(per); 741 portmux_setup(per);
737 port_setup(ident, PERIPHERAL_USAGE); 742 port_setup(ident, PERIPHERAL_USAGE);
@@ -777,7 +782,7 @@ void peripheral_free(unsigned short per)
777 782
778 local_irq_save_hw(flags); 783 local_irq_save_hw(flags);
779 784
780 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) { 785 if (unlikely(!is_reserved(peri, ident, 0))) {
781 local_irq_restore_hw(flags); 786 local_irq_restore_hw(flags);
782 return; 787 return;
783 } 788 }
@@ -785,7 +790,7 @@ void peripheral_free(unsigned short per)
785 if (!(per & P_MAYSHARE)) 790 if (!(per & P_MAYSHARE))
786 port_setup(ident, GPIO_USAGE); 791 port_setup(ident, GPIO_USAGE);
787 792
788 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident); 793 unreserve(peri, ident);
789 794
790 set_label(ident, "free"); 795 set_label(ident, "free");
791 796
@@ -836,7 +841,7 @@ int bfin_gpio_request(unsigned gpio, const char *label)
836 return 0; 841 return 0;
837 } 842 }
838 843
839 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 844 if (unlikely(is_reserved(gpio, gpio, 1))) {
840 if (system_state == SYSTEM_BOOTING) 845 if (system_state == SYSTEM_BOOTING)
841 dump_stack(); 846 dump_stack();
842 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n", 847 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
@@ -844,7 +849,7 @@ int bfin_gpio_request(unsigned gpio, const char *label)
844 local_irq_restore_hw(flags); 849 local_irq_restore_hw(flags);
845 return -EBUSY; 850 return -EBUSY;
846 } 851 }
847 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 852 if (unlikely(is_reserved(peri, gpio, 1))) {
848 if (system_state == SYSTEM_BOOTING) 853 if (system_state == SYSTEM_BOOTING)
849 dump_stack(); 854 dump_stack();
850 printk(KERN_ERR 855 printk(KERN_ERR
@@ -853,7 +858,7 @@ int bfin_gpio_request(unsigned gpio, const char *label)
853 local_irq_restore_hw(flags); 858 local_irq_restore_hw(flags);
854 return -EBUSY; 859 return -EBUSY;
855 } 860 }
856 if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 861 if (unlikely(is_reserved(gpio_irq, gpio, 1))) {
857 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!" 862 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!"
858 " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio); 863 " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio);
859 } 864 }
@@ -863,7 +868,7 @@ int bfin_gpio_request(unsigned gpio, const char *label)
863 } 868 }
864#endif 869#endif
865 870
866 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); 871 reserve(gpio, gpio);
867 set_label(gpio, label); 872 set_label(gpio, label);
868 873
869 local_irq_restore_hw(flags); 874 local_irq_restore_hw(flags);
@@ -885,7 +890,7 @@ void bfin_gpio_free(unsigned gpio)
885 890
886 local_irq_save_hw(flags); 891 local_irq_save_hw(flags);
887 892
888 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { 893 if (unlikely(!is_reserved(gpio, gpio, 0))) {
889 if (system_state == SYSTEM_BOOTING) 894 if (system_state == SYSTEM_BOOTING)
890 dump_stack(); 895 dump_stack();
891 gpio_error(gpio); 896 gpio_error(gpio);
@@ -893,7 +898,7 @@ void bfin_gpio_free(unsigned gpio)
893 return; 898 return;
894 } 899 }
895 900
896 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); 901 unreserve(gpio, gpio);
897 902
898 set_label(gpio, "free"); 903 set_label(gpio, "free");
899 904
@@ -902,7 +907,7 @@ void bfin_gpio_free(unsigned gpio)
902EXPORT_SYMBOL(bfin_gpio_free); 907EXPORT_SYMBOL(bfin_gpio_free);
903 908
904#ifdef BFIN_SPECIAL_GPIO_BANKS 909#ifdef BFIN_SPECIAL_GPIO_BANKS
905static unsigned short reserved_special_gpio_map[gpio_bank(MAX_RESOURCES)]; 910DECLARE_RESERVED_MAP(special_gpio, gpio_bank(MAX_RESOURCES));
906 911
907int bfin_special_gpio_request(unsigned gpio, const char *label) 912int bfin_special_gpio_request(unsigned gpio, const char *label)
908{ 913{
@@ -921,14 +926,14 @@ int bfin_special_gpio_request(unsigned gpio, const char *label)
921 return 0; 926 return 0;
922 } 927 }
923 928
924 if (unlikely(reserved_special_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 929 if (unlikely(is_reserved(special_gpio, gpio, 1))) {
925 local_irq_restore_hw(flags); 930 local_irq_restore_hw(flags);
926 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n", 931 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
927 gpio, get_label(gpio)); 932 gpio, get_label(gpio));
928 933
929 return -EBUSY; 934 return -EBUSY;
930 } 935 }
931 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 936 if (unlikely(is_reserved(peri, gpio, 1))) {
932 local_irq_restore_hw(flags); 937 local_irq_restore_hw(flags);
933 printk(KERN_ERR 938 printk(KERN_ERR
934 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n", 939 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
@@ -937,8 +942,8 @@ int bfin_special_gpio_request(unsigned gpio, const char *label)
937 return -EBUSY; 942 return -EBUSY;
938 } 943 }
939 944
940 reserved_special_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); 945 reserve(special_gpio, gpio);
941 reserved_peri_map[gpio_bank(gpio)] |= gpio_bit(gpio); 946 reserve(peri, gpio);
942 947
943 set_label(gpio, label); 948 set_label(gpio, label);
944 local_irq_restore_hw(flags); 949 local_irq_restore_hw(flags);
@@ -956,14 +961,14 @@ void bfin_special_gpio_free(unsigned gpio)
956 961
957 local_irq_save_hw(flags); 962 local_irq_save_hw(flags);
958 963
959 if (unlikely(!(reserved_special_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { 964 if (unlikely(!is_reserved(special_gpio, gpio, 0))) {
960 gpio_error(gpio); 965 gpio_error(gpio);
961 local_irq_restore_hw(flags); 966 local_irq_restore_hw(flags);
962 return; 967 return;
963 } 968 }
964 969
965 reserved_special_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); 970 unreserve(special_gpio, gpio);
966 reserved_peri_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); 971 unreserve(peri, gpio);
967 set_label(gpio, "free"); 972 set_label(gpio, "free");
968 local_irq_restore_hw(flags); 973 local_irq_restore_hw(flags);
969} 974}
@@ -980,7 +985,7 @@ int bfin_gpio_irq_request(unsigned gpio, const char *label)
980 985
981 local_irq_save_hw(flags); 986 local_irq_save_hw(flags);
982 987
983 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 988 if (unlikely(is_reserved(peri, gpio, 1))) {
984 if (system_state == SYSTEM_BOOTING) 989 if (system_state == SYSTEM_BOOTING)
985 dump_stack(); 990 dump_stack();
986 printk(KERN_ERR 991 printk(KERN_ERR
@@ -989,12 +994,12 @@ int bfin_gpio_irq_request(unsigned gpio, const char *label)
989 local_irq_restore_hw(flags); 994 local_irq_restore_hw(flags);
990 return -EBUSY; 995 return -EBUSY;
991 } 996 }
992 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) 997 if (unlikely(is_reserved(gpio, gpio, 1)))
993 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved by %s! " 998 printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved by %s! "
994 "(Documentation/blackfin/bfin-gpio-notes.txt)\n", 999 "(Documentation/blackfin/bfin-gpio-notes.txt)\n",
995 gpio, get_label(gpio)); 1000 gpio, get_label(gpio));
996 1001
997 reserved_gpio_irq_map[gpio_bank(gpio)] |= gpio_bit(gpio); 1002 reserve(gpio_irq, gpio);
998 set_label(gpio, label); 1003 set_label(gpio, label);
999 1004
1000 local_irq_restore_hw(flags); 1005 local_irq_restore_hw(flags);
@@ -1013,7 +1018,7 @@ void bfin_gpio_irq_free(unsigned gpio)
1013 1018
1014 local_irq_save_hw(flags); 1019 local_irq_save_hw(flags);
1015 1020
1016 if (unlikely(!(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { 1021 if (unlikely(!is_reserved(gpio_irq, gpio, 0))) {
1017 if (system_state == SYSTEM_BOOTING) 1022 if (system_state == SYSTEM_BOOTING)
1018 dump_stack(); 1023 dump_stack();
1019 gpio_error(gpio); 1024 gpio_error(gpio);
@@ -1021,7 +1026,7 @@ void bfin_gpio_irq_free(unsigned gpio)
1021 return; 1026 return;
1022 } 1027 }
1023 1028
1024 reserved_gpio_irq_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); 1029 unreserve(gpio_irq, gpio);
1025 1030
1026 set_label(gpio, "free"); 1031 set_label(gpio, "free");
1027 1032
@@ -1042,7 +1047,7 @@ int bfin_gpio_direction_input(unsigned gpio)
1042{ 1047{
1043 unsigned long flags; 1048 unsigned long flags;
1044 1049
1045 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 1050 if (unlikely(!is_reserved(gpio, gpio, 0))) {
1046 gpio_error(gpio); 1051 gpio_error(gpio);
1047 return -EINVAL; 1052 return -EINVAL;
1048 } 1053 }
@@ -1084,7 +1089,7 @@ int bfin_gpio_direction_output(unsigned gpio, int value)
1084{ 1089{
1085 unsigned long flags; 1090 unsigned long flags;
1086 1091
1087 if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 1092 if (unlikely(!is_reserved(gpio, gpio, 0))) {
1088 gpio_error(gpio); 1093 gpio_error(gpio);
1089 return -EINVAL; 1094 return -EINVAL;
1090 } 1095 }
@@ -1153,13 +1158,13 @@ static int gpio_proc_read(char *buf, char **start, off_t offset,
1153 int c, irq, gpio, outlen = 0; 1158 int c, irq, gpio, outlen = 0;
1154 1159
1155 for (c = 0; c < MAX_RESOURCES; c++) { 1160 for (c = 0; c < MAX_RESOURCES; c++) {
1156 irq = reserved_gpio_irq_map[gpio_bank(c)] & gpio_bit(c); 1161 irq = is_reserved(gpio_irq, c, 1);
1157 gpio = reserved_gpio_map[gpio_bank(c)] & gpio_bit(c); 1162 gpio = is_reserved(gpio, c, 1);
1158 if (!check_gpio(c) && (gpio || irq)) 1163 if (!check_gpio(c) && (gpio || irq))
1159 len = sprintf(buf, "GPIO_%d: \t%s%s \t\tGPIO %s\n", c, 1164 len = sprintf(buf, "GPIO_%d: \t%s%s \t\tGPIO %s\n", c,
1160 get_label(c), (gpio && irq) ? " *" : "", 1165 get_label(c), (gpio && irq) ? " *" : "",
1161 get_gpio_dir(c) ? "OUTPUT" : "INPUT"); 1166 get_gpio_dir(c) ? "OUTPUT" : "INPUT");
1162 else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c)) 1167 else if (is_reserved(peri, c, 1))
1163 len = sprintf(buf, "GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c)); 1168 len = sprintf(buf, "GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c));
1164 else 1169 else
1165 continue; 1170 continue;