302ed32020b6243504afb132b0c483aaf476db99
[sfrench/cifs-2.6.git] / drivers / staging / media / atomisp / pci / hive_isp_css_common / host / isp.c
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 <system_global.h>
17 #include "isp.h"
18
19 #ifndef __INLINE_ISP__
20 #include "isp_private.h"
21 #endif /* __INLINE_ISP__ */
22
23 #include "assert_support.h"
24 #include "platform_support.h"                   /* hrt_sleep() */
25
26 void cnd_isp_irq_enable(
27     const isp_ID_t              ID,
28     const bool          cnd)
29 {
30         if (cnd) {
31                 isp_ctrl_setbit(ID, ISP_IRQ_READY_REG, ISP_IRQ_READY_BIT);
32                 /* Enabling the IRQ immediately triggers an interrupt, clear it */
33                 isp_ctrl_setbit(ID, ISP_IRQ_CLEAR_REG, ISP_IRQ_CLEAR_BIT);
34         } else {
35                 isp_ctrl_clearbit(ID, ISP_IRQ_READY_REG,
36                                   ISP_IRQ_READY_BIT);
37         }
38         return;
39 }
40
41 void isp_get_state(
42     const isp_ID_t              ID,
43     isp_state_t                 *state,
44     isp_stall_t                 *stall)
45 {
46         hrt_data sc = isp_ctrl_load(ID, ISP_SC_REG);
47
48         assert(state);
49         assert(stall);
50
51 #if defined(_hrt_sysmem_ident_address)
52         /* Patch to avoid compiler unused symbol warning in C_RUN build */
53         (void)__hrt_sysmem_ident_address;
54         (void)_hrt_sysmem_map_var;
55 #endif
56
57         state->pc = isp_ctrl_load(ID, ISP_PC_REG);
58         state->status_register = sc;
59         state->is_broken = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_BROKEN_BIT);
60         state->is_idle = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_IDLE_BIT);
61         state->is_sleeping = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_SLEEPING_BIT);
62         state->is_stalling = isp_ctrl_getbit(ID, ISP_SC_REG, ISP_STALLING_BIT);
63         stall->stat_ctrl =
64             !isp_ctrl_getbit(ID, ISP_CTRL_SINK_REG, ISP_CTRL_SINK_BIT);
65         stall->pmem =
66             !isp_ctrl_getbit(ID, ISP_PMEM_SINK_REG, ISP_PMEM_SINK_BIT);
67         stall->dmem =
68             !isp_ctrl_getbit(ID, ISP_DMEM_SINK_REG, ISP_DMEM_SINK_BIT);
69         stall->vmem =
70             !isp_ctrl_getbit(ID, ISP_VMEM_SINK_REG, ISP_VMEM_SINK_BIT);
71         stall->fifo0 =
72             !isp_ctrl_getbit(ID, ISP_FIFO0_SINK_REG, ISP_FIFO0_SINK_BIT);
73         stall->fifo1 =
74             !isp_ctrl_getbit(ID, ISP_FIFO1_SINK_REG, ISP_FIFO1_SINK_BIT);
75         stall->fifo2 =
76             !isp_ctrl_getbit(ID, ISP_FIFO2_SINK_REG, ISP_FIFO2_SINK_BIT);
77         stall->fifo3 =
78             !isp_ctrl_getbit(ID, ISP_FIFO3_SINK_REG, ISP_FIFO3_SINK_BIT);
79         stall->fifo4 =
80             !isp_ctrl_getbit(ID, ISP_FIFO4_SINK_REG, ISP_FIFO4_SINK_BIT);
81         stall->fifo5 =
82             !isp_ctrl_getbit(ID, ISP_FIFO5_SINK_REG, ISP_FIFO5_SINK_BIT);
83         stall->fifo6 =
84             !isp_ctrl_getbit(ID, ISP_FIFO6_SINK_REG, ISP_FIFO6_SINK_BIT);
85         stall->vamem1 =
86             !isp_ctrl_getbit(ID, ISP_VAMEM1_SINK_REG, ISP_VAMEM1_SINK_BIT);
87         stall->vamem2 =
88             !isp_ctrl_getbit(ID, ISP_VAMEM2_SINK_REG, ISP_VAMEM2_SINK_BIT);
89         stall->vamem3 =
90             !isp_ctrl_getbit(ID, ISP_VAMEM3_SINK_REG, ISP_VAMEM3_SINK_BIT);
91         stall->hmem =
92             !isp_ctrl_getbit(ID, ISP_HMEM_SINK_REG, ISP_HMEM_SINK_BIT);
93         /*
94                 stall->icache_master =
95                         !isp_ctrl_getbit(ID, ISP_ICACHE_MT_SINK_REG,
96                                 ISP_ICACHE_MT_SINK_BIT);
97          */
98         return;
99 }
100
101 /* ISP functions to control the ISP state from the host, even in crun. */
102
103 /* Inspect readiness of an ISP indexed by ID */
104 unsigned int isp_is_ready(isp_ID_t ID)
105 {
106         assert(ID < N_ISP_ID);
107         return isp_ctrl_getbit(ID, ISP_SC_REG, ISP_IDLE_BIT);
108 }
109
110 /* Inspect sleeping of an ISP indexed by ID */
111 unsigned int isp_is_sleeping(isp_ID_t ID)
112 {
113         assert(ID < N_ISP_ID);
114         return isp_ctrl_getbit(ID, ISP_SC_REG, ISP_SLEEPING_BIT);
115 }
116
117 /* To be called by the host immediately before starting ISP ID. */
118 void isp_start(isp_ID_t ID)
119 {
120         assert(ID < N_ISP_ID);
121 }
122
123 /* Wake up ISP ID. */
124 void isp_wake(isp_ID_t ID)
125 {
126         assert(ID < N_ISP_ID);
127         isp_ctrl_setbit(ID, ISP_SC_REG, ISP_START_BIT);
128         hrt_sleep();
129 }