GNU Linux-libre 4.14.257-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / hive_isp_css_common / host / isp.c
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2010-2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #include <system_global.h>
16 #include "isp.h"
17
18 #ifndef __INLINE_ISP__
19 #include "isp_private.h"
20 #endif /* __INLINE_ISP__ */
21
22 #include "assert_support.h"
23 #include "platform_support.h"                   /* hrt_sleep() */
24
25 void cnd_isp_irq_enable(
26         const isp_ID_t          ID,
27         const bool              cnd)
28 {
29         if (cnd) {
30                 isp_ctrl_setbit(ID, ISP_IRQ_READY_REG, ISP_IRQ_READY_BIT);
31 /* Enabling the IRQ immediately triggers an interrupt, clear it */
32                 isp_ctrl_setbit(ID, ISP_IRQ_CLEAR_REG, ISP_IRQ_CLEAR_BIT);
33         } else {
34                 isp_ctrl_clearbit(ID, ISP_IRQ_READY_REG,
35                         ISP_IRQ_READY_BIT);
36         }
37 return;
38 }
39
40 void isp_get_state(
41         const isp_ID_t          ID,
42         isp_state_t                     *state,
43         isp_stall_t                     *stall)
44 {
45         hrt_data sc = isp_ctrl_load(ID, ISP_SC_REG);
46
47         assert(state != NULL);
48         assert(stall != NULL);
49
50 #if defined(_hrt_sysmem_ident_address)
51         /* Patch to avoid compiler unused symbol warning in C_RUN build */
52         (void)__hrt_sysmem_ident_address;
53         (void)_hrt_sysmem_map_var;
54 #endif
55
56         state->pc = isp_ctrl_load(ID, ISP_PC_REG);
57         state->status_register = sc;
58         state->is_broken = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_BROKEN_BIT);
59         state->is_idle = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_IDLE_BIT);
60         state->is_sleeping = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_SLEEPING_BIT);
61         state->is_stalling = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_STALLING_BIT);
62         stall->stat_ctrl =
63                 !isp_ctrl_getbit(ID, ISP_CTRL_SINK_REG, ISP_CTRL_SINK_BIT);
64         stall->pmem =
65                 !isp_ctrl_getbit(ID, ISP_PMEM_SINK_REG, ISP_PMEM_SINK_BIT);
66         stall->dmem =
67                 !isp_ctrl_getbit(ID, ISP_DMEM_SINK_REG, ISP_DMEM_SINK_BIT);
68         stall->vmem =
69                 !isp_ctrl_getbit(ID, ISP_VMEM_SINK_REG, ISP_VMEM_SINK_BIT);
70         stall->fifo0 =
71                 !isp_ctrl_getbit(ID, ISP_FIFO0_SINK_REG, ISP_FIFO0_SINK_BIT);
72         stall->fifo1 =
73                 !isp_ctrl_getbit(ID, ISP_FIFO1_SINK_REG, ISP_FIFO1_SINK_BIT);
74         stall->fifo2 =
75                 !isp_ctrl_getbit(ID, ISP_FIFO2_SINK_REG, ISP_FIFO2_SINK_BIT);
76         stall->fifo3 =
77                 !isp_ctrl_getbit(ID, ISP_FIFO3_SINK_REG, ISP_FIFO3_SINK_BIT);
78         stall->fifo4 =
79                 !isp_ctrl_getbit(ID, ISP_FIFO4_SINK_REG, ISP_FIFO4_SINK_BIT);
80         stall->fifo5 =
81                 !isp_ctrl_getbit(ID, ISP_FIFO5_SINK_REG, ISP_FIFO5_SINK_BIT);
82         stall->fifo6 =
83                 !isp_ctrl_getbit(ID, ISP_FIFO6_SINK_REG, ISP_FIFO6_SINK_BIT);
84         stall->vamem1 =
85                 !isp_ctrl_getbit(ID, ISP_VAMEM1_SINK_REG, ISP_VAMEM1_SINK_BIT);
86         stall->vamem2 =
87                 !isp_ctrl_getbit(ID, ISP_VAMEM2_SINK_REG, ISP_VAMEM2_SINK_BIT);
88         stall->vamem3 =
89                 !isp_ctrl_getbit(ID, ISP_VAMEM3_SINK_REG, ISP_VAMEM3_SINK_BIT);
90         stall->hmem =
91                 !isp_ctrl_getbit(ID, ISP_HMEM_SINK_REG, ISP_HMEM_SINK_BIT);
92 /*
93         stall->icache_master =
94                 !isp_ctrl_getbit(ID, ISP_ICACHE_MT_SINK_REG,
95                         ISP_ICACHE_MT_SINK_BIT);
96  */
97 return;
98 }
99
100 /* ISP functions to control the ISP state from the host, even in crun. */
101
102 /* Inspect readiness of an ISP indexed by ID */
103 unsigned isp_is_ready(isp_ID_t ID)
104 {
105         assert (ID < N_ISP_ID);
106         return isp_ctrl_getbit(ID, ISP_SC_REG, ISP_IDLE_BIT);
107 }
108
109 /* Inspect sleeping of an ISP indexed by ID */
110 unsigned isp_is_sleeping(isp_ID_t ID)
111 {
112         assert (ID < N_ISP_ID);
113         return isp_ctrl_getbit(ID, ISP_SC_REG, ISP_SLEEPING_BIT);
114 }
115
116 /* To be called by the host immediately before starting ISP ID. */
117 void isp_start(isp_ID_t ID)
118 {
119         assert (ID < N_ISP_ID);
120 }
121
122 /* Wake up ISP ID. */
123 void isp_wake(isp_ID_t ID)
124 {
125         assert (ID < N_ISP_ID);
126         isp_ctrl_setbit(ID, ISP_SC_REG, ISP_START_BIT);
127         hrt_sleep();
128 }
129