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