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.
14 //#include <linux/init.h>
15 //#include <linux/irq.h>
16 //#include <linux/bug.h>
17 //#include <linux/module.h>
18 //#include <linux/delay.h>
21 //#include <asm/gpio.h>
22 #include <asm/arch/gpio.h>
24 //#include <mach/regs_global.h>
25 //#include <mach/regs_gpio.h>
26 //#include <mach/regs_ana.h>
27 #include <asm/arch/sc8800g_reg_global.h>
28 #include <asm/arch/sc8800g_reg_base.h>
29 #include <asm/arch/gpio_reg_v0.h>
30 #include <asm/arch/gpio_phy.h>
31 #include <asm/arch/asm_generic_gpio.h>
32 #include <asm/arch/regs_ana.h>
33 #include <asm/arch/regs_global.h>
35 #define KERN_WARNING ""
36 #define WARN(nmu, fmt...) printf(fmt)
38 #define BUG_ON(__cond__) if(__cond__) printf("%s line: %d bug on\n", __FUNCTION__, __LINE__)
39 #define pr_err(fmt...) printf(fmt)
40 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
41 #define pr_debug(fmt...) printf(fmt)
42 #define pr_warning(fmt...) printf(fmt)
47 #define GPIO_DBG(fmt...) pr_debug(fmt)
49 #define GPIO_DBG(fmt...)
53 #define GPO_TRI 0xFFFF
57 #define GPO_DATA 0xFFFF
62 enum gpio_section_type gpio_type;
73 #define GPIO_INVALID_ID 0xffff
74 #define INVALID_REG (~(u32)0)
76 //static struct gpio_irq_map gpio_irq_table[NR_GPIO_IRQS];
79 static void __get_gpio_base_info (u32 gpio_id, struct gpio_info *info)
83 struct gpio_section *section_table;
85 section_table = gpio_get_section_table (&table_size);
86 BUG_ON((gpio_id >= GPIO_MAX_PIN_NUM) || (table_size <= 0));
89 info->base_addr = __get_base_addr (gpio_id);
90 info->bit_num = __get_bit_num (gpio_id);
91 info->die = __get_gpio_die(gpio_id);
93 for (i = 0; i < table_size; i++) {
94 if (section_table[i].page_base == info->base_addr) {
95 if (section_table[i].page_size > info->bit_num) {
96 info->gpio_type = section_table[i].section_type;
103 info->gpio_type = GPIO_SECTION_INVALID;
110 static int __gpio_set_dir (struct gpio_info * info, int dir)
116 reg_addr = info->base_addr;
118 switch (info->gpio_type) {
119 case GPIO_SECTION_GPI:
121 WARN(1, "cannot set dir output with GPI");
126 case GPIO_SECTION_GPO:
128 WARN(1, "cannot set dir input with GPO");
133 case GPIO_SECTION_GPIO:
134 reg_addr += GPIO_DIR;
136 case GPIO_SECTION_INVALID:
138 WARN(1, " the GPIO_ID is Invalid in this chip");
142 local_irq_save(flags);
143 value = gpio_reg_get(reg_addr, info->die);
146 value |= 1 << info->bit_num;
148 value &= ~(1 << info->bit_num);
149 gpio_reg_set(reg_addr, info->die, value);
151 local_irq_restore(flags);
157 get data register's offset
159 static u32 __gpio_get_data_reg_offs (struct gpio_info *info)
163 switch (info->gpio_type) {
164 case GPIO_SECTION_GPI:
165 offset_addr = GPI_DATA;
167 case GPIO_SECTION_GPO:
168 offset_addr = GPO_DATA;
170 case GPIO_SECTION_GPIO:
171 offset_addr = GPIO_DATA;
173 case GPIO_SECTION_INVALID:
175 pr_err("the GPIO_ID is Invalid in this chip");
183 static int __gpio_get_pin_data (struct gpio_info *info)
188 reg_addr = info->base_addr;
190 offset_addr = __gpio_get_data_reg_offs (info);
192 if (offset_addr != INVALID_REG) {
193 reg_addr += offset_addr;
194 return gpio_reg_get(reg_addr, info->die) & (1<<info->bit_num);
199 static u32 __gpio_get_data_mask_reg_offs (struct gpio_info *info)
203 switch (info->gpio_type) {
204 case GPIO_SECTION_GPI:
205 offset_addr = GPI_DMSK;
207 case GPIO_SECTION_GPO:
208 offset_addr = GPO_TRI;
210 case GPIO_SECTION_GPIO:
211 offset_addr = GPIO_DMSK;
213 case GPIO_SECTION_INVALID:
215 pr_err ("the GPIO_ID is Invalid in this chip");
224 if the data register can be access, return ture, else return false;
226 static int __gpio_get_data_mask (struct gpio_info *info)
232 reg_addr = info->base_addr;
234 offset_addr = __gpio_get_data_mask_reg_offs(info);
235 if (offset_addr != INVALID_REG) {
236 reg_addr += offset_addr;
238 GPIO_DBG("gpio_addr %x data mask :%x\r\n", info->base_addr,
239 gpio_reg_get(reg_addr, info->die));
241 value = gpio_reg_get(reg_addr, info->die);
242 return ( value & (1<< info->bit_num)) ? true : false;
248 static int __gpio_get_dir (struct gpio_info *info)
253 reg_addr = info->base_addr;
255 switch (info->gpio_type) {
256 case GPIO_SECTION_GPI:
259 case GPIO_SECTION_GPO:
262 case GPIO_SECTION_GPIO:
263 reg_addr += GPIO_DIR;
266 case GPIO_SECTION_INVALID:
268 pr_warning("[GPIO_DRV]the GPIO_ID is Invalid in this chip");
273 value = gpio_reg_get(reg_addr, info->die) & (1<< info->bit_num);
274 return value ? true: false;
277 static void __gpio_set_pin_data (struct gpio_info *info ,int b_on)
284 reg_addr = info->base_addr;
286 offset_addr = __gpio_get_data_reg_offs (info);
287 if (offset_addr == INVALID_REG)
290 reg_addr += offset_addr;
292 local_irq_save(flags);
294 value = gpio_reg_get(reg_addr, info->die);
296 value |= 1 << info->bit_num;
298 value &= ~(1 << info->bit_num);
299 gpio_reg_set(reg_addr, info->die, value);
300 local_irq_restore(flags);
304 set data mask, the gpio data register can be access
306 static void __gpio_set_data_mask (struct gpio_info *info, int b_on)
313 reg_addr = info->base_addr;
314 offset_addr = __gpio_get_data_mask_reg_offs(info);
315 if (offset_addr != INVALID_REG) {
316 reg_addr += offset_addr;
318 local_irq_save(flags);
319 value = gpio_reg_get(reg_addr, info->die);
321 value |= 1 << info->bit_num;
323 value &= ~(1 << info->bit_num);
324 gpio_reg_set(reg_addr, info->die, value);
325 local_irq_restore(flags);
327 GPIO_DBG("After setting gpio_addr %x data mask :%x\r\n", reg_addr,
328 gpio_reg_get(reg_addr, info->die));
334 int sprd_gpio_direction_output(struct gpio_chip *chip,
335 unsigned offset, int value)
337 unsigned gpio_id = offset;
338 struct gpio_info gpio_info;
341 __get_gpio_base_info (gpio_id, &gpio_info);
342 res = __gpio_set_dir(&gpio_info, 1);
344 pr_warning("GPIO: cannot set direction for %d\n", gpio_id);
347 __gpio_set_pin_data(&gpio_info, value);
351 int sprd_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
353 unsigned gpio_id = offset;
354 struct gpio_info gpio_info;
357 __get_gpio_base_info (gpio_id, &gpio_info);
358 res = __gpio_set_dir(&gpio_info, 0);
360 pr_warning("GPIO: cannot set direction for %d\n", gpio_id);
369 int sprd_gpio_get(struct gpio_chip *chip, unsigned offset)
371 unsigned gpio_id = offset;
372 struct gpio_info gpio_info;
374 __get_gpio_base_info (gpio_id, &gpio_info);
376 if (!__gpio_get_data_mask (&gpio_info)) {
377 WARN(1, "GPIO_%d data mask hasn't been opened!\n", gpio_id);
380 if (__gpio_get_dir (&gpio_info))
382 WARN(1, "[GPIO_DRV]GPIO_GetValue: GPIO_%d should be input port!\n", gpio_id);
385 return __gpio_get_pin_data (&gpio_info);
391 * Set output GPIO level
393 static void sprd_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
395 struct gpio_info gpio_info;
396 u32 gpio_id = offset;
398 BUG_ON (gpio_id >= GPIO_MAX_PIN_NUM);
400 __get_gpio_base_info (gpio_id, &gpio_info);
403 if (!__gpio_get_data_mask (&gpio_info))
405 WARN(1, "GPIO_%d data mask no opened!", gpio_id);
409 if (!__gpio_get_dir (&gpio_info)) {
410 WARN(1, "GPIO_%d dir wrong!can't set input value", gpio_id);
414 __gpio_set_pin_data (&gpio_info, value);
416 GPIO_DBG("gpio_%d setting :%x \n", gpio_id, value);
419 int sprd_gpio_request(struct gpio_chip *chip, unsigned offset)
421 unsigned gpio_id = offset;
422 struct gpio_info gpio_info;
424 GPIO_DBG("request gpio_%d\r\n", gpio_id);
425 __get_gpio_base_info (gpio_id, &gpio_info);
427 GPIO_DBG("gpio info, pin is :%d, base addr :%x, bit num :%d, type :%d\r\n", gpio_id,
428 gpio_info.base_addr, gpio_info.bit_num, gpio_info.gpio_type);
429 GPIO_DBG("ture is %d, false is %d\n", true, false);
430 __gpio_set_data_mask (&gpio_info, true);
435 static void sprd_gpio_free(struct gpio_chip *chip, unsigned offset)
437 unsigned gpio_id = offset;
438 struct gpio_info gpio_info;
440 if (gpio_id > GPIO_MAX_PIN_NUM) {
441 WARN(1, KERN_WARNING"gpio number is too larger:%d\r\n", gpio_id);
445 __get_gpio_base_info (gpio_id, &gpio_info);
446 __gpio_set_data_mask (&gpio_info, false);
452 static int sprd_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
456 for (i = 0; i < NR_GPIO_IRQS; i++) {
457 if (gpio_irq_table[i].gpio_id == offset)
461 if (i >= NR_GPIO_IRQS)
463 return gpio_irq_table[i].irq_num;
466 int irq_to_gpio(unsigned long irq)
470 for (i = 0; i < NR_GPIO_IRQS; i++) {
471 if (gpio_irq_table[i].irq_num == irq)
475 if (i >= NR_GPIO_IRQS)
477 return gpio_irq_table[i].gpio_id;
479 EXPORT_SYMBOL(irq_to_gpio);
481 static struct gpio_chip sprd_gpio_chip = {
482 .label = "sc8800s-gpio",
483 .direction_input = sprd_gpio_direction_input,
484 .direction_output = sprd_gpio_direction_output,
485 .get = sprd_gpio_get,
486 .set = sprd_gpio_set,
487 .request = sprd_gpio_request,
488 .free = sprd_gpio_free,
489 .to_irq = sprd_gpio_to_irq,
491 .ngpio = GPIO_MAX_PIN_NUM,
494 static u32 __gpio_get_int_mask_addr (struct gpio_info *info)
498 switch (info->gpio_type) {
499 case GPIO_SECTION_GPI:
500 offset_addr = GPI_IE;
502 case GPIO_SECTION_GPO:
503 WARN(1, "this opretion can not belong to GPO");
506 case GPIO_SECTION_GPIO:
507 offset_addr = GPIO_IE;
510 case GPIO_SECTION_INVALID:
512 WARN (1, "the GPIO_ID is Invalid in this chip");
521 static void __gpio_enable_irq (struct gpio_info *info)
528 reg_addr = info->base_addr;
529 offset_addr = __gpio_get_int_mask_addr (info);
530 if (offset_addr != INVALID_REG) {
531 reg_addr += offset_addr;
532 local_irq_save(flags);
533 value = gpio_reg_get(reg_addr, info->die);
534 value |= 1 << info->bit_num;
535 gpio_reg_set(reg_addr, info->die, value);
536 local_irq_restore(flags);
542 static void __gpio_disable_irq (struct gpio_info *info)
549 reg_addr = info->base_addr;
550 offset_addr = __gpio_get_int_mask_addr (info);
552 if (offset_addr != INVALID_REG) {
553 reg_addr += offset_addr;
554 local_irq_save(flags);
555 value = gpio_reg_get(reg_addr, info->die);
556 value &= ~ (1 << info->bit_num);
557 gpio_reg_set(reg_addr, info->die, value);
558 local_irq_restore(flags);
565 static void __gpio_clear_irq_status (struct gpio_info *info)
571 reg_addr = info->base_addr;
573 switch (info->gpio_type) {
574 case GPIO_SECTION_GPI:
577 case GPIO_SECTION_GPO:
578 GPIO_DBG("this opretion can not belong to GPO");
580 case GPIO_SECTION_GPIO:
583 case GPIO_SECTION_INVALID:
585 GPIO_DBG("the GPIO_ID is Invalid in this chip");
590 local_irq_save(flags);
591 value = gpio_reg_get(reg_addr, info->die);
592 value &= ~ (1 << info->bit_num);
593 value |= 1 << info->bit_num;
594 gpio_reg_set(reg_addr, info->die, value);
595 local_irq_restore(flags);
598 static int __gpio_get_int_status (struct gpio_info *info)
603 reg_addr = info->base_addr;
605 switch (info->gpio_type) {
606 case GPIO_SECTION_GPI:
609 case GPIO_SECTION_GPO:
610 WARN(1, "The corresponding reg of this GPIO_ID is a GPO! No Intr!");
613 case GPIO_SECTION_GPIO:
614 reg_addr += GPIO_MIS;
616 case GPIO_SECTION_INVALID:
618 WARN(1, "the GPIO_ID is Invalid in this chip");
622 value = gpio_reg_get(reg_addr, info->die);
624 return ( value & (1 << info->bit_num)) ? true : false;
627 static void __gpio_set_int_type (struct gpio_info *info, int type)
629 if (info->gpio_type == GPIO_SECTION_GPI) {
631 case IRQ_TYPE_LEVEL_HIGH: // detect high level.
632 gpio_reg_or( (info->base_addr + GPI_IEV), info->die,
633 (0x1 << info->bit_num));
636 case IRQ_TYPE_LEVEL_LOW: // detect low level.
637 gpio_reg_and( (info->base_addr + GPI_IEV), info->die,
638 ~ (0x1 << info->bit_num));
641 case IRQ_TYPE_EDGE_BOTH: // detect the rising edges and falling edges.
642 case IRQ_TYPE_EDGE_RISING: // detect the rising edges.
643 case IRQ_TYPE_EDGE_FALLING:
645 WARN(1, "The Irq type is invalid for GPI. \n");
648 } else if (info->gpio_type == GPIO_SECTION_GPIO) {
650 case IRQ_TYPE_LEVEL_HIGH: // detect high level.
651 gpio_reg_or( (info->base_addr + GPIO_IS), info->die, (0x1 << info->bit_num));
652 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
653 gpio_reg_or( (info->base_addr + GPIO_IEV), info->die, (0x1 << info->bit_num));
656 case IRQ_TYPE_LEVEL_LOW: // detect low level.
657 gpio_reg_or( (info->base_addr + GPIO_IS), info->die, (0x1 << info->bit_num));
658 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
659 gpio_reg_and( (info->base_addr + GPIO_IEV), info->die, ~(0x1 << info->bit_num));
662 case IRQ_TYPE_EDGE_BOTH: // detect the rising edges and falling edges.
663 gpio_reg_and( (info->base_addr + GPIO_IS), info->die, ~(0x1 << info->bit_num));
664 gpio_reg_or(info->base_addr + GPIO_IBE, info->die, (0x1 << info->bit_num));
665 gpio_reg_and( (info->base_addr + GPIO_IEV), info->die, ~(0x1 << info->bit_num));
668 case IRQ_TYPE_EDGE_RISING: // detect the rising edges.
669 gpio_reg_and( (info->base_addr + GPIO_IS), info->die, ~(0x1 << info->bit_num));
670 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
671 gpio_reg_or( (info->base_addr + GPIO_IEV), info->die, (0x1 << info->bit_num));
674 case IRQ_TYPE_EDGE_FALLING:
675 gpio_reg_and( (info->base_addr + GPIO_IS), info->die, ~(0x1 << info->bit_num));
676 gpio_reg_and(info->base_addr + GPIO_IBE, info->die, ~ (0x1 << info->bit_num));
677 gpio_reg_and( (info->base_addr + GPIO_IEV), info->die, ~(0x1 << info->bit_num));
680 WARN(1, "fault irq type \r\n");
684 WARN(1, "the gpio type is Invalid for irq\r\n");
690 The GPI module can do handware debouce, the max period is 255ms,
692 if your application need debounce time larger than that, please use software
695 void gpio_set_hw_debounce (unsigned int gpio, u8 period)
699 struct gpio_info gpio_info;
702 __get_gpio_base_info (gpio, &gpio_info);
703 if (gpio_info.gpio_type != GPIO_SECTION_GPI) {
704 WARN(1, "GPIO_%d is not in GPI\r\n", gpio);
708 reg_addr = gpio_info.base_addr;
709 reg_addr += (GPI_0CTRL+ (gpio_info.bit_num << 2));
711 local_irq_save(flags);
714 GPIO_REG_OR (reg_addr, GPI_DEBOUNCE_BIT);
715 GPIO_REG_SET (reg_addr, (GPIO_REG32 (reg_addr) & 0xFF00) +debounce_period);
717 gpio_reg_or(reg_addr, gpio_info.die, GPI_DEBOUNCE_BIT);
718 value = (gpio_reg_get(reg_addr, gpio_info.die) & 0xFF00) + period;
719 gpio_reg_set(reg_addr, gpio_info.die, value);
720 } else {// not recommend
721 //GPIO_REG_AND (reg_addr, ~GPI_DEBOUNCE_BIT); //bypass mode
722 gpio_reg_and(reg_addr, gpio_info.die, ~GPI_DEBOUNCE_BIT);
724 local_irq_restore(flags);
727 EXPORT_SYMBOL(gpio_set_hw_debounce);
730 generate the trig_start pulse for GPI interrupt;
732 static void __gpio_trig_detect (struct gpio_info *info)
738 reg_addr = info->base_addr;
740 switch (info->gpio_type) {
741 case GPIO_SECTION_GPI:
742 reg_addr += GPI_TRIG;
745 case GPIO_SECTION_GPO:
746 case GPIO_SECTION_GPIO:
747 GPIO_DBG("[GPIO_DRV]this opretion can not belong to GPO/GPIO");
751 case GPIO_SECTION_INVALID:
753 GPIO_DBG ("[GPIO_DRV]the GPIO_ID is Invalid in this chip");
758 local_irq_save(flags);
760 value = gpio_reg_get(reg_addr, info->die) & ~(1 << info->bit_num);
761 value |= 1 << info->bit_num;
762 gpio_reg_set(reg_addr, info->die, value);
764 local_irq_restore(flags);
765 //GPIO_REG_SET (reg_addr, ( (GPIO_REG32 (reg_addr) & ~ (1<<pGpio_info->bit_num)) | (value<<pGpio_info->bit_num)));
770 void gpio_enable_gpi_interupt (struct gpio_info *info)
773 switch (info->gpio_type) {
774 case GPIO_SECTION_GPI:
775 __gpio_enable_irq (info);
776 __gpio_trig_detect (info);
778 case GPIO_SECTION_GPO:
779 case GPIO_SECTION_GPIO:
788 //EXPORT_SYMBOL(gpio_enable_gpi_interupt);
790 static void sprd_ack_gpio_irq(unsigned int irq)
793 struct gpio_irq_map *map= get_irq_chip_data(irq);
794 struct gpio_info gpio_info;
797 if (gpio >= GPIO_MAX_PIN_NUM ) {
798 pr_warning(" [%s] error gpio %d\n", __FUNCTION__, gpio);
801 GPIO_DBG("ack irq gpio %d irq %d", gpio, irq);
803 __get_gpio_base_info (gpio, &gpio_info);
804 __gpio_clear_irq_status(&gpio_info);
807 static void sprd_mask_gpio_irq(unsigned int irq)
810 struct gpio_irq_map *map= get_irq_chip_data(irq);
811 struct gpio_info gpio_info;
814 if (gpio >= GPIO_MAX_PIN_NUM ) {
815 pr_warning(" [%s] error gpio %d\n", __func__, gpio);
819 GPIO_DBG("mask gpio %d irq %d", gpio, irq);
820 __get_gpio_base_info (gpio, &gpio_info);
821 __gpio_disable_irq (&gpio_info);
825 static void sprd_unmask_gpio_irq(unsigned int irq)
828 struct gpio_info gpio_info;
829 struct gpio_irq_map *map= get_irq_chip_data(irq);
832 if (gpio >= GPIO_MAX_PIN_NUM ) {
833 pr_warning(" [%s] error gpio %d\n", __FUNCTION__, gpio);
837 GPIO_DBG("unmask gpio %d irq %d", gpio, irq);
838 __get_gpio_base_info (gpio, &gpio_info);
839 __gpio_enable_irq (&gpio_info);
841 if(gpio_info.gpio_type == GPIO_SECTION_GPI)
842 __gpio_trig_detect (&gpio_info);
846 static int sprd_gpio_irq_type(unsigned int irq, unsigned int type)
849 struct gpio_irq_map *map= get_irq_chip_data(irq);
850 struct gpio_info gpio_info;
853 if (gpio >= GPIO_MAX_PIN_NUM ) {
854 pr_warning(" [%s] error gpio %d\n", __FUNCTION__, gpio);
858 __get_gpio_base_info (gpio, &gpio_info);
860 __gpio_set_int_type(&gpio_info, type);
862 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
863 __set_irq_handler_unlocked(irq, handle_level_irq);
864 else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
865 __set_irq_handler_unlocked(irq, handle_edge_irq);
869 static void sprd_disable_gpio_irq(unsigned int irq)
871 sprd_mask_gpio_irq(irq);
873 static struct irq_chip sprd_muxed_gpio_chip = {
875 .ack = sprd_ack_gpio_irq,
876 .mask = sprd_mask_gpio_irq,
877 .unmask = sprd_unmask_gpio_irq,
878 .set_type = sprd_gpio_irq_type,
879 .disable = sprd_disable_gpio_irq,
882 static int gpio_get_int_status(unsigned int gpio)
884 struct gpio_info gpio_info;
886 __get_gpio_base_info (gpio, &gpio_info);
887 return __gpio_get_int_status (&gpio_info);
892 static void sprd_gpio_demux_handler(unsigned int irq, struct irq_desc *desc)
896 for (i = 0; i < NR_GPIO_IRQS; i++) {
897 if (gpio_irq_table[i].gpio_id == GPIO_INVALID_ID) {
900 if (gpio_get_int_status(gpio_irq_table[i].gpio_id)) {
901 generic_handle_irq(gpio_irq_table[i].irq_num);
904 desc->chip->unmask(irq);
906 static void sprd_gpio_irq_init(void)
911 for(i = 0; i < NR_GPIO_IRQS; i++) {
912 gpio_irq_table[i].gpio_id= GPIO_INVALID_ID;
914 for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + NR_GPIO_IRQS); irq++) {
915 set_irq_chip(irq, &sprd_muxed_gpio_chip);
916 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
919 set_irq_chained_handler(IRQ_GPIO_INT, sprd_gpio_demux_handler);
920 set_irq_chained_handler(IRQ_ANA_GPIO_INT, sprd_gpio_demux_handler);
924 allocate an irq for gpio
926 __must_check int sprd_alloc_gpio_irq(unsigned gpio)
930 struct gpio_info gpio_info;
933 __get_gpio_base_info (gpio, &gpio_info);
935 // find a free record
936 for (i = 0; i< NR_GPIO_IRQS; i++) {
937 if (gpio_irq_table[i].gpio_id == gpio) {
938 pr_warning("irq for GPIO_%d has been alloc !\n", gpio);
943 for(i = 0; i < NR_GPIO_IRQS; i++) {
944 if (gpio_irq_table[i].gpio_id == GPIO_INVALID_ID)
948 if (i >= NR_GPIO_IRQS) {
949 // No free item in the table.
952 local_irq_save(flags);
953 irq = GPIO_IRQ_START + i;
954 gpio_irq_table[i].gpio_id = gpio;
955 gpio_irq_table[i].irq_num = irq;
957 set_irq_chip_data(irq, &gpio_irq_table[i]);
958 local_irq_restore(flags);
959 __gpio_clear_irq_status(&gpio_info);
960 if (gpio_info.gpio_type == GPIO_SECTION_GPI)
961 __gpio_trig_detect (&gpio_info);
966 EXPORT_SYMBOL(sprd_alloc_gpio_irq);
968 void sprd_free_gpio_irq(int irq)
973 local_irq_save(flags);
974 for (i = 0; i < NR_GPIO_IRQS; i++) {
975 if (gpio_irq_table[i].irq_num == irq) {
976 set_irq_chip_data(irq, NULL);
977 gpio_irq_table[i].gpio_id = GPIO_INVALID_ID;
981 local_irq_restore(flags);
983 EXPORT_SYMBOL(sprd_free_gpio_irq);
985 __init void sprd_gpio_init(void)
987 //enable gpio bank 0~10, that is, all 176 gpio
988 //__raw_writel(0x7fff, GR_GEN2);
989 //CHIP_REG_OR ( (GR_GEN0), (GEN0_GPIO_EN | GEN0_GPIO_RTC_EN));
990 __raw_bits_or (GEN0_GPIO_EN | GEN0_GPIO_RTC_EN, GR_GEN0);
991 ANA_REG_OR (ANA_AGEN,AGEN_RTC_GPIO_EN);
993 ANA_REG_OR (ANA_AGEN,AGEN_GPIO_EN);
995 gpiochip_add(&sprd_gpio_chip);
997 sprd_gpio_irq_init();
1000 void sprd_gpio_init(void)
1002 //enable gpio bank 0~10, that is, all 176 gpio
1003 //__raw_writel(0x7fff, GR_GEN2);
1004 //CHIP_REG_OR ( (GR_GEN0), (GEN0_GPIO_EN | GEN0_GPIO_RTC_EN));
1005 // __raw_bits_or (GEN0_GPIO_EN | GEN0_GPIO_RTC_EN, GR_GEN0);
1007 temp = readl(GR_GEN0);
1008 temp |= (GEN0_GPIO_EN | GEN0_GPIO_RTC_EN);
1009 writel(temp, GR_GEN0);
1010 ANA_REG_OR (ANA_AGEN,AGEN_RTC_GPIO_EN);
1012 volatile i = 0x2fff;
1014 ANA_REG_OR (ANA_AGEN,AGEN_GPIO_EN);
1016 //gpiochip_add(&sprd_gpio_chip);
1018 // sprd_gpio_irq_init();