tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / sprd_isp / isp2.0 / tshark2 / src / isp_k_isr.c
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #include <linux/uaccess.h>
15 #include <linux/sprd_mm.h>
16 #include <video/sprd_isp.h>
17 #include <linux/delay.h>
18 #include "isp_reg.h"
19 #include "isp_drv.h"
20
21 #define ISP_TIME_OUT_MAX (500)
22
23 int32_t isp_get_int_num(struct isp_node *node)
24 {
25
26         node->irq_val1 = REG_RD(ISP_INT_INT0);
27         node->irq_val2 = REG_RD(ISP_INT_INT1);
28         node->irq_val3 = REG_RD(ISP_INT_INT2);
29
30         if ((0 == node->irq_val1)
31                 && (0 == node->irq_val2)
32                 && (0 == node->irq_val3)) {
33                 printk("isp_get_int_num: int error.\n");
34                 return -1;
35         }
36
37         REG_WR(ISP_INT_CLR0, ISP_IRQ_HW_MASK);
38         REG_WR(ISP_INT_CLR1, ISP_IRQ_HW_MASK);
39         REG_WR(ISP_INT_CLR2, ISP_IRQ_HW_MASK);
40
41         return 0;
42 }
43
44 void isp_clr_int(void)
45 {
46         REG_WR(ISP_INT_CLR0, ISP_IRQ_HW_MASK);
47         REG_WR(ISP_INT_CLR1, ISP_IRQ_HW_MASK);
48         REG_WR(ISP_INT_CLR2, ISP_IRQ_HW_MASK);
49 }
50
51 void isp_en_irq(uint32_t irq_mode)
52 {
53         REG_WR(ISP_INT_CLR0, ISP_IRQ_HW_MASK);
54         REG_WR(ISP_INT_CLR1, ISP_IRQ_HW_MASK);
55         REG_WR(ISP_INT_CLR2, ISP_IRQ_HW_MASK);
56
57         switch(irq_mode) {
58         case ISP_INT_VIDEO_MODE:
59                 REG_WR(ISP_INT_EN0, ISP_INT_DCAMERA_SOF | ISP_INT_AEM_DONE | ISP_INT_AFM_RGB_DONE | ISP_INT_AFL_DONE);
60                 REG_WR(ISP_INT_EN1, 0);
61                 REG_WR(ISP_INT_EN2, 0);
62                 break;
63         case ISP_INT_CAPTURE_MODE:
64                 REG_WR(ISP_INT_EN0, ISP_INT_STORE_DONE);
65                 REG_WR(ISP_INT_EN1, 0);
66                 REG_WR(ISP_INT_EN2, 0);
67                 break;
68         case ISP_INT_CLEAR_MODE:
69                 REG_WR(ISP_INT_EN0, 0);
70                 REG_WR(ISP_INT_EN1, 0);
71                 REG_WR(ISP_INT_EN2, 0);
72                 break;
73         default:
74                 printk("isp_en_irq: irq_mode error.\n");
75                 break;
76         }
77 }
78
79 int32_t isp_axi_bus_waiting(void)
80 {
81         int32_t ret = 0;
82         uint32_t reg_value = 0;
83         uint32_t time_out_cnt = 0;
84
85         REG_OWR(ISP_AXI_ITI2AXIM_CTRL, BIT_18);
86
87         reg_value = REG_RD(ISP_INT_STATUS);
88         while ((0x00 == (reg_value & BIT_3))
89                 && (time_out_cnt < ISP_TIME_OUT_MAX)) {
90                 time_out_cnt++;
91                 udelay(50);
92                 reg_value = REG_RD(ISP_INT_STATUS);
93         }
94
95         if (time_out_cnt >= ISP_TIME_OUT_MAX) {
96                 ret = -1;
97                 printk("isp_axi_bus_waiting: time out.\n");
98         }
99
100         return ret;
101 }