2 * linux/arch/arm/mach-sprd/gpio.c
4 * Generic SPRD GPIO handling
6 * Author: Yingchun Li(yingchun.li@spreadtrum.com)
7 * Created: March 10, 2010
8 * Copyright: Spreadtrum Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <asm/arch/gpio.h>
16 #include <asm/arch/gpio_phy.h>
17 #include <asm/arch/sprd_reg.h>
18 #include <asm/arch/gpio_reg_v0.h>
19 #include <asm/arch/asm_generic_gpio.h>
20 #include <asm/arch/chip_drv_common_io.h>
22 #define KERN_WARNING ""
23 #define WARN(nmu, fmt...) printf(fmt)
25 #define BUG_ON(__cond__) if(__cond__) printf("%s line: %d bug on\n", __FUNCTION__, __LINE__)
26 #define pr_err(fmt...) printf(fmt)
27 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
28 #define pr_debug(fmt...) printf(fmt)
34 #define GPIO_DBG(fmt...) pr_debug(fmt)
36 #define GPIO_DBG(fmt...)
40 #define GPO_TRI 0xFFFF
44 #define GPO_DATA 0xFFFF
49 enum gpio_section_type gpio_type;
60 #define GPIO_INVALID_ID 0xffff
61 #define INVALID_REG (~(u32)0)
63 //static struct gpio_irq_map gpio_irq_table[NR_GPIO_IRQS];
66 static void __get_gpio_base_info (u32 gpio_id, struct gpio_info *info)
70 struct gpio_section *section_table;
72 section_table = gpio_get_section_table (&table_size);
73 BUG_ON((gpio_id >= GPIO_MAX_PIN_NUM) || (table_size <= 0));
76 info->base_addr = __get_base_addr (gpio_id);
77 info->bit_num = __get_bit_num (gpio_id);
78 info->die = __get_gpio_die(gpio_id);
80 for (i = 0; i < table_size; i++) {
81 if (section_table[i].page_base == info->base_addr) {
82 if (section_table[i].page_size > info->bit_num) {
83 info->gpio_type = section_table[i].section_type;
90 info->gpio_type = GPIO_SECTION_INVALID;
97 static void __gpio_set_dir (struct gpio_info * info, int dir)
103 reg_addr = info->base_addr;
105 switch (info->gpio_type) {
106 case GPIO_SECTION_GPI:
108 WARN(1, "cannot set dir output with GPI");
112 case GPIO_SECTION_GPO:
114 WARN(1, "cannot set dir input with GPO");
118 case GPIO_SECTION_GPIO:
119 reg_addr += GPIO_DIR;
121 case GPIO_SECTION_INVALID:
123 WARN(1, " the GPIO_ID is Invalid in this chip");
127 //local_irq_save(flags);
128 value = gpio_reg_get(reg_addr, info->die);
131 value |= 1 << info->bit_num;
133 value &= ~(1 << info->bit_num);
134 gpio_reg_set(reg_addr, info->die, value);
136 //local_irq_restore(flags);
140 get data register's offset
142 static u32 __gpio_get_data_reg_offs (struct gpio_info *info)
146 switch (info->gpio_type) {
147 case GPIO_SECTION_GPI:
148 offset_addr = GPI_DATA;
150 case GPIO_SECTION_GPO:
151 offset_addr = GPO_DATA;
153 case GPIO_SECTION_GPIO:
154 offset_addr = GPIO_DATA;
156 case GPIO_SECTION_INVALID:
158 pr_err("the GPIO_ID is Invalid in this chip");
166 static int __gpio_get_pin_data (struct gpio_info *info)
171 reg_addr = info->base_addr;
173 offset_addr = __gpio_get_data_reg_offs (info);
175 if (offset_addr != INVALID_REG) {
176 reg_addr += offset_addr;
177 return gpio_reg_get(reg_addr, info->die) & (1<<info->bit_num);
182 static u32 __gpio_get_data_mask_reg_offs (struct gpio_info *info)
186 switch (info->gpio_type) {
187 case GPIO_SECTION_GPI:
188 offset_addr = GPI_DMSK;
190 case GPIO_SECTION_GPO:
191 offset_addr = GPO_TRI;
193 case GPIO_SECTION_GPIO:
194 offset_addr = GPIO_DMSK;
196 case GPIO_SECTION_INVALID:
198 pr_err ("the GPIO_ID is Invalid in this chip");
207 if the data register can be access, return ture, else return false;
209 static int __gpio_get_data_mask (struct gpio_info *info)
215 reg_addr = info->base_addr;
217 offset_addr = __gpio_get_data_mask_reg_offs(info);
218 if (offset_addr != INVALID_REG) {
219 reg_addr += offset_addr;
221 GPIO_DBG("gpio_addr %x data mask :%x\r\n", info->base_addr,
222 gpio_reg_get(reg_addr, info->die));
224 value = gpio_reg_get(reg_addr, info->die);
225 return ( value & (1<< info->bit_num)) ? true : false;
231 static int __gpio_get_dir (struct gpio_info *info)
236 reg_addr = info->base_addr;
238 switch (info->gpio_type) {
239 case GPIO_SECTION_GPI:
242 case GPIO_SECTION_GPO:
245 case GPIO_SECTION_GPIO:
246 reg_addr += GPIO_DIR;
249 case GPIO_SECTION_INVALID:
251 pr_warning("[GPIO_DRV]the GPIO_ID is Invalid in this chip");
256 value = gpio_reg_get(reg_addr, info->die) & (1<< info->bit_num);
257 return value ? true: false;
260 static void __gpio_set_pin_data (struct gpio_info *info ,int b_on)
267 reg_addr = info->base_addr;
269 offset_addr = __gpio_get_data_reg_offs (info);
270 if (offset_addr == INVALID_REG)
273 reg_addr += offset_addr;
275 //local_irq_save(flags);
277 value = gpio_reg_get(reg_addr, info->die);
279 value |= 1 << info->bit_num;
281 value &= ~(1 << info->bit_num);
282 gpio_reg_set(reg_addr, info->die, value);
283 //local_irq_restore(flags);
287 set data mask, the gpio data register can be access
289 static void __gpio_set_data_mask (struct gpio_info *info, int b_on)
296 reg_addr = info->base_addr;
297 offset_addr = __gpio_get_data_mask_reg_offs(info);
298 if (offset_addr != INVALID_REG) {
299 reg_addr += offset_addr;
301 //local_irq_save(flags);
302 value = gpio_reg_get(reg_addr, info->die);
304 value |= 1 << info->bit_num;
306 value &= ~(1 << info->bit_num);
307 gpio_reg_set(reg_addr, info->die, value);
308 //local_irq_restore(flags);
310 GPIO_DBG("After setting gpio_addr %x data mask :%x\r\n", reg_addr,
311 gpio_reg_get(reg_addr, info->die));
317 int sprd_gpio_direction_output(struct gpio_chip *chip,
318 unsigned offset, int value)
320 unsigned gpio_id = offset;
321 struct gpio_info gpio_info;
323 __get_gpio_base_info (gpio_id, &gpio_info);
324 __gpio_set_dir(&gpio_info, 1);
325 __gpio_set_pin_data(&gpio_info, value);
329 int sprd_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
331 unsigned gpio_id = offset;
332 struct gpio_info gpio_info;
334 __get_gpio_base_info (gpio_id, &gpio_info);
335 __gpio_set_dir(&gpio_info, 0);
342 int sprd_gpio_get(struct gpio_chip *chip, unsigned offset)
344 unsigned gpio_id = offset;
345 struct gpio_info gpio_info;
347 __get_gpio_base_info (gpio_id, &gpio_info);
349 if (!__gpio_get_data_mask (&gpio_info)) {
350 WARN(1, "GPIO_%d data mask hasn't been opened!\n", gpio_id);
353 if (__gpio_get_dir (&gpio_info))
355 WARN(1, "[GPIO_DRV]GPIO_GetValue: GPIO_%d should be input port!\n", gpio_id);
358 return __gpio_get_pin_data (&gpio_info);
364 * Set output GPIO level
366 void sprd_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
368 struct gpio_info gpio_info;
369 u32 gpio_id = offset;
371 BUG_ON (gpio_id >= GPIO_MAX_PIN_NUM);
373 __get_gpio_base_info (gpio_id, &gpio_info);
376 if (!__gpio_get_data_mask (&gpio_info))
378 WARN(1, "GPIO_%d data mask no opened!", gpio_id);
382 if (!__gpio_get_dir (&gpio_info)) {
383 WARN(1, "GPIO_%d dir wrong!can't set input value", gpio_id);
387 __gpio_set_pin_data (&gpio_info, value);
389 GPIO_DBG("gpio_%d setting :%x \n", gpio_id, value);
392 int sprd_gpio_request(struct gpio_chip *chip, unsigned offset)
394 unsigned gpio_id = offset;
395 struct gpio_info gpio_info;
397 GPIO_DBG("request gpio_%d\r\n", gpio_id);
398 __get_gpio_base_info (gpio_id, &gpio_info);
400 GPIO_DBG("gpio info, pin is :%d, base addr :%x, bit num :%d, type :%d\r\n", gpio_id,
401 gpio_info.base_addr, gpio_info.bit_num, gpio_info.gpio_type);
402 GPIO_DBG("ture is %d, false is %d\n", true, false);
403 __gpio_set_data_mask (&gpio_info, true);
408 static void sprd_gpio_free(struct gpio_chip *chip, unsigned offset)
410 unsigned gpio_id = offset;
411 struct gpio_info gpio_info;
413 if (gpio_id > GPIO_MAX_PIN_NUM) {
414 WARN(1, KERN_WARNING"gpio number is too larger:%d\r\n", gpio_id);
418 __get_gpio_base_info (gpio_id, &gpio_info);
419 __gpio_set_data_mask (&gpio_info, false);
425 static int sprd_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
429 for (i = 0; i < NR_GPIO_IRQS; i++) {
430 if (gpio_irq_table[i].gpio_id == offset)
434 if (i >= NR_GPIO_IRQS)
436 return gpio_irq_table[i].irq_num;
439 int irq_to_gpio(unsigned long irq)
443 for (i = 0; i < NR_GPIO_IRQS; i++) {
444 if (gpio_irq_table[i].irq_num == irq)
448 if (i >= NR_GPIO_IRQS)
450 return gpio_irq_table[i].gpio_id;
452 EXPORT_SYMBOL(irq_to_gpio);
454 static struct gpio_chip sprd_gpio_chip = {
455 .label = "sc8800s-gpio",
456 .direction_input = sprd_gpio_direction_input,
457 .direction_output = sprd_gpio_direction_output,
458 .get = sprd_gpio_get,
459 .set = sprd_gpio_set,
460 .request = sprd_gpio_request,
461 .free = sprd_gpio_free,
462 .to_irq = sprd_gpio_to_irq,
464 .ngpio = GPIO_MAX_PIN_NUM,
467 static u32 __gpio_get_int_mask_addr (struct gpio_info *info)
471 switch (info->gpio_type) {
472 case GPIO_SECTION_GPI:
473 offset_addr = GPI_IE;
475 case GPIO_SECTION_GPO:
476 WARN(1, "this opretion can not belong to GPO");
479 case GPIO_SECTION_GPIO:
480 offset_addr = GPIO_IE;
483 case GPIO_SECTION_INVALID:
485 WARN (1, "the GPIO_ID is Invalid in this chip");
494 static void __gpio_enable_irq (struct gpio_info *info)
501 reg_addr = info->base_addr;
502 offset_addr = __gpio_get_int_mask_addr (info);
503 if (offset_addr != INVALID_REG) {
504 reg_addr += offset_addr;
505 local_irq_save(flags);
506 value = gpio_reg_get(reg_addr, info->die);
507 value |= 1 << info->bit_num;
508 gpio_reg_set(reg_addr, info->die, value);
509 local_irq_restore(flags);
515 static void __gpio_disable_irq (struct gpio_info *info)
522 reg_addr = info->base_addr;
523 offset_addr = __gpio_get_int_mask_addr (info);
525 if (offset_addr != INVALID_REG) {
526 reg_addr += offset_addr;
527 local_irq_save(flags);
528 value = gpio_reg_get(reg_addr, info->die);
529 value &= ~ (1 << info->bit_num);
530 gpio_reg_set(reg_addr, info->die, value);
531 local_irq_restore(flags);
538 static void __gpio_clear_irq_status (struct gpio_info *info)
544 reg_addr = info->base_addr;
546 switch (info->gpio_type) {
547 case GPIO_SECTION_GPI:
550 case GPIO_SECTION_GPO:
551 GPIO_DBG("this opretion can not belong to GPO");
553 case GPIO_SECTION_GPIO:
556 case GPIO_SECTION_INVALID:
558 GPIO_DBG("the GPIO_ID is Invalid in this chip");
563 local_irq_save(flags);
564 value = gpio_reg_get(reg_addr, info->die);
565 value &= ~ (1 << info->bit_num);
566 value |= 1 << info->bit_num;
567 gpio_reg_set(reg_addr, info->die, value);
570 static int __gpio_get_int_status (struct gpio_info *info)
575 reg_addr = info->base_addr;
577 switch (info->gpio_type) {
578 case GPIO_SECTION_GPI:
581 case GPIO_SECTION_GPO:
582 WARN(1, "The corresponding reg of this GPIO_ID is a GPO! No Intr!");
585 case GPIO_SECTION_GPIO:
586 reg_addr += GPIO_MIS;
588 case GPIO_SECTION_INVALID:
590 WARN(1, "the GPIO_ID is Invalid in this chip");
594 value = gpio_reg_get(reg_addr, info->die);
596 return ( value & (1 << info->bit_num)) ? true : false;
599 static void __gpio_set_int_type (struct gpio_info *info, int type)
601 if (info->gpio_type == GPIO_SECTION_GPI) {
603 case IRQ_TYPE_LEVEL_HIGH: // detect high level.
604 gpio_reg_or( (info->base_addr + GPI_IEV), info->die,
605 (0x1 << info->bit_num));
608 case IRQ_TYPE_LEVEL_LOW: // detect low level.
609 gpio_reg_and( (info->base_addr + GPI_IEV), info->die,
610 ~ (0x1 << info->bit_num));
613 case IRQ_TYPE_EDGE_BOTH: // detect the rising edges and falling edges.
614 case IRQ_TYPE_EDGE_RISING: // detect the rising edges.
615 case IRQ_TYPE_EDGE_FALLING:
617 WARN(1, "The Irq type is invalid for GPI. \n");
620 } else if (info->gpio_type == GPIO_SECTION_GPIO) {
622 case IRQ_TYPE_LEVEL_HIGH: // detect high level.
623 gpio_reg_or( (info->base_addr + GPIO_IS), info->die, (0x1 << info->bit_num));
624 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
625 gpio_reg_or( (info->base_addr + GPIO_IEV), info->die, (0x1 << info->bit_num));
628 case IRQ_TYPE_LEVEL_LOW: // detect low level.
629 gpio_reg_or( (info->base_addr + GPIO_IS), info->die, (0x1 << info->bit_num));
630 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
631 gpio_reg_and( (info->base_addr + GPIO_IEV), info->die, ~(0x1 << info->bit_num));
634 case IRQ_TYPE_EDGE_BOTH: // detect the rising edges and falling edges.
635 gpio_reg_and( (info->base_addr + GPIO_IS), info->die, ~(0x1 << info->bit_num));
636 gpio_reg_or(info->base_addr + GPIO_IBE, info->die, (0x1 << info->bit_num));
637 gpio_reg_and( (info->base_addr + GPIO_IEV), info->die, ~(0x1 << info->bit_num));
640 case IRQ_TYPE_EDGE_RISING: // detect the rising edges.
641 gpio_reg_and( (info->base_addr + GPIO_IS), info->die, ~(0x1 << info->bit_num));
642 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
643 gpio_reg_or( (info->base_addr + GPIO_IEV), info->die, (0x1 << info->bit_num));
646 case IRQ_TYPE_EDGE_FALLING:
647 gpio_reg_and( (info->base_addr + GPIO_IS), info->die, ~(0x1 << info->bit_num));
648 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
649 gpio_reg_and( (info->base_addr + GPIO_IEV), info->die, ~(0x1 << info->bit_num));
652 WARN(1, "fault irq type \r\n");
656 WARN(1, "the gpio type is Invalid for irq\r\n");
662 The GPI module can do handware debouce, the max period is 255ms,
664 if your application need debounce time larger than that, please use software
667 void gpio_set_hw_debounce (unsigned int gpio, u8 period)
671 struct gpio_info gpio_info;
674 __get_gpio_base_info (gpio, &gpio_info);
675 if (gpio_info.gpio_type != GPIO_SECTION_GPI) {
676 WARN(1, "GPIO_%d is not in GPI\r\n", gpio);
680 reg_addr = gpio_info.base_addr;
681 reg_addr += (GPI_0CTRL+ (gpio_info.bit_num << 2));
683 local_irq_save(flags);
686 GPIO_REG_OR (reg_addr, GPI_DEBOUNCE_BIT);
687 GPIO_REG_SET (reg_addr, (GPIO_REG32 (reg_addr) & 0xFF00) +debounce_period);
689 gpio_reg_or(reg_addr, gpio_info.die, GPI_DEBOUNCE_BIT);
690 value = (gpio_reg_get(reg_addr, gpio_info.die) & 0xFF00) + period;
691 gpio_reg_set(reg_addr, gpio_info.die, value);
692 } else {// not recommend
693 //GPIO_REG_AND (reg_addr, ~GPI_DEBOUNCE_BIT); //bypass mode
694 gpio_reg_and(reg_addr, gpio_info.die, ~GPI_DEBOUNCE_BIT);
696 local_irq_restore(flags);
699 EXPORT_SYMBOL(gpio_set_hw_debounce);
702 generate the trig_start pulse for GPI interrupt;
704 static void __gpio_trig_detect (struct gpio_info *info)
710 reg_addr = info->base_addr;
712 switch (info->gpio_type) {
713 case GPIO_SECTION_GPI:
714 reg_addr += GPI_TRIG;
717 case GPIO_SECTION_GPO:
718 case GPIO_SECTION_GPIO:
719 GPIO_DBG("[GPIO_DRV]this opretion can not belong to GPO/GPIO");
723 case GPIO_SECTION_INVALID:
725 GPIO_DBG ("[GPIO_DRV]the GPIO_ID is Invalid in this chip");
730 local_irq_save(flags);
732 value = gpio_reg_get(reg_addr, info->die) & ~(1 << info->bit_num);
733 value |= 1 << info->bit_num;
734 gpio_reg_set(reg_addr, info->die, value);
736 local_irq_restore(flags);
737 //GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) | (value<<pGpio_info->bit_num)));
742 void gpio_enable_gpi_interupt (struct gpio_info *info)
745 switch (info->gpio_type) {
746 case GPIO_SECTION_GPI:
747 __gpio_enable_irq (info);
748 __gpio_trig_detect (info);
750 case GPIO_SECTION_GPO:
751 case GPIO_SECTION_GPIO:
760 //EXPORT_SYMBOL(gpio_enable_gpi_interupt);
762 static void sprd_ack_gpio_irq(unsigned int irq)
765 struct gpio_irq_map *map= get_irq_chip_data(irq);
766 struct gpio_info gpio_info;
769 if (gpio >= GPIO_MAX_PIN_NUM ) {
770 pr_warning(" [%s] error gpio %d\n", __FUNCTION__, gpio);
773 GPIO_DBG("ack irq gpio %d irq %d", gpio, irq);
775 __get_gpio_base_info (gpio, &gpio_info);
776 __gpio_clear_irq_status(&gpio_info);
779 static void sprd_mask_gpio_irq(unsigned int irq)
782 struct gpio_irq_map *map= get_irq_chip_data(irq);
783 struct gpio_info gpio_info;
786 if (gpio >= GPIO_MAX_PIN_NUM ) {
787 pr_warning(" [%s] error gpio %d\n", __func__, gpio);
791 GPIO_DBG("mask gpio %d irq %d", gpio, irq);
792 __get_gpio_base_info (gpio, &gpio_info);
793 __gpio_disable_irq (&gpio_info);
797 static void sprd_unmask_gpio_irq(unsigned int irq)
800 struct gpio_info gpio_info;
801 struct gpio_irq_map *map= get_irq_chip_data(irq);
804 if (gpio >= GPIO_MAX_PIN_NUM ) {
805 pr_warning(" [%s] error gpio %d\n", __FUNCTION__, gpio);
809 GPIO_DBG("unmask gpio %d irq %d", gpio, irq);
810 __get_gpio_base_info (gpio, &gpio_info);
811 __gpio_enable_irq (&gpio_info);
813 if(gpio_info.gpio_type == GPIO_SECTION_GPI)
814 __gpio_trig_detect (&gpio_info);
818 static int sprd_gpio_irq_type(unsigned int irq, unsigned int type)
821 struct gpio_irq_map *map= get_irq_chip_data(irq);
822 struct gpio_info gpio_info;
825 if (gpio >= GPIO_MAX_PIN_NUM ) {
826 pr_warning(" [%s] error gpio %d\n", __FUNCTION__, gpio);
830 __get_gpio_base_info (gpio, &gpio_info);
832 __gpio_set_int_type(&gpio_info, type);
834 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
835 __set_irq_handler_unlocked(irq, handle_level_irq);
836 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
837 __set_irq_handler_unlocked(irq, handle_edge_irq);
841 static void sprd_disable_gpio_irq(unsigned int irq)
843 sprd_mask_gpio_irq(irq);
845 static struct irq_chip sprd_muxed_gpio_chip = {
847 .ack = sprd_ack_gpio_irq,
848 .mask = sprd_mask_gpio_irq,
849 .unmask = sprd_unmask_gpio_irq,
850 .set_type = sprd_gpio_irq_type,
851 .disable = sprd_disable_gpio_irq,
854 static int gpio_get_int_status(unsigned int gpio)
856 struct gpio_info gpio_info;
858 __get_gpio_base_info (gpio, &gpio_info);
859 return __gpio_get_int_status (&gpio_info);
864 static void sprd_gpio_demux_handler(unsigned int irq, struct irq_desc *desc)
868 for (i = 0; i < NR_GPIO_IRQS; i++) {
869 if (gpio_irq_table[i].gpio_id == GPIO_INVALID_ID) {
872 if (gpio_get_int_status(gpio_irq_table[i].gpio_id)) {
873 generic_handle_irq(gpio_irq_table[i].irq_num);
877 static void sprd_gpio_irq_init(void)
882 for(i = 0; i < NR_GPIO_IRQS; i++) {
883 gpio_irq_table[i].gpio_id= GPIO_INVALID_ID;
885 for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + NR_GPIO_IRQS); irq++) {
886 set_irq_chip(irq, &sprd_muxed_gpio_chip);
887 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
890 set_irq_chained_handler(IRQ_GPIO_INT, sprd_gpio_demux_handler);
891 set_irq_chained_handler(IRQ_ANA_GPIO_INT, sprd_gpio_demux_handler);
895 allocate an irq for gpio
897 __must_check int sprd_alloc_gpio_irq(unsigned gpio)
901 struct gpio_info gpio_info;
904 __get_gpio_base_info (gpio, &gpio_info);
906 // find a free record
907 for (i = 0; i< NR_GPIO_IRQS; i++) {
908 if (gpio_irq_table[i].gpio_id == gpio) {
909 pr_warning("irq for GPIO_%d has been alloc !\n", gpio);
914 for(i = 0; i < NR_GPIO_IRQS; i++) {
915 if (gpio_irq_table[i].gpio_id == GPIO_INVALID_ID)
919 if (i >= NR_GPIO_IRQS) {
920 // No free item in the table.
923 local_irq_save(flags);
924 irq = GPIO_IRQ_START + i;
925 gpio_irq_table[i].gpio_id = gpio;
926 gpio_irq_table[i].irq_num = irq;
928 set_irq_chip_data(irq, &gpio_irq_table[i]);
929 local_irq_restore(flags);
930 __gpio_clear_irq_status(&gpio_info);
931 if (gpio_info.gpio_type == GPIO_SECTION_GPI)
932 __gpio_trig_detect (&gpio_info);
937 EXPORT_SYMBOL(sprd_alloc_gpio_irq);
939 void sprd_free_gpio_irq(int irq)
944 local_irq_save(flags);
945 for (i = 0; i < NR_GPIO_IRQS; i++) {
946 if (gpio_irq_table[i].irq_num == irq) {
947 set_irq_chip_data(irq, NULL);
948 gpio_irq_table[i].gpio_id = GPIO_INVALID_ID;
952 local_irq_restore(flags);
954 EXPORT_SYMBOL(sprd_free_gpio_irq);
956 __init void sprd_gpio_init(void)
958 //enable gpio bank 0~10, that is, all 176 gpio
959 //__raw_writel(0x7fff, GR_GEN2);
960 //CHIP_REG_OR ( (GR_GEN0), (GEN0_GPIO_EN | GEN0_GPIO_RTC_EN));
961 __raw_bits_or (GEN0_GPIO_EN | GEN0_GPIO_RTC_EN, GR_GEN0);
962 ANA_REG_OR (ANA_AGEN,AGEN_RTC_GPIO_EN);
964 ANA_REG_OR (ANA_AGEN,AGEN_GPIO_EN);
966 gpiochip_add(&sprd_gpio_chip);
968 sprd_gpio_irq_init();
971 void sprd_gpio_init(void)
973 #if defined(CONFIG_SPX15)
974 REG32(REG_AON_APB_APB_EB0) |= BIT_AON_GPIO_EB;
976 REG32(REG_AON_APB_APB_EB0) |= BIT_GPIO_EB;
977 #if !(defined(CONFIG_ADIE_SC2723S)||defined(CONFIG_ADIE_SC2723))
978 ANA_REG_OR(ANA_REG_GLB_ARM_MODULE_EN, BIT_ANA_GPIO_EN);