GNU Linux-libre 4.14.251-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / sh_css_hrt.c
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 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 "platform_support.h"
16
17 #include "sh_css_hrt.h"
18 #include "ia_css_debug.h"
19
20 #include "device_access.h"
21
22 #define __INLINE_EVENT__
23 #include "event_fifo.h"
24 #define __INLINE_SP__
25 #include "sp.h"
26 #define __INLINE_ISP__
27 #include "isp.h"
28 #define __INLINE_IRQ__
29 #include "irq.h"
30 #define __INLINE_FIFO_MONITOR__
31 #include "fifo_monitor.h"
32
33 /* System independent */
34 #include "sh_css_internal.h"
35
36 bool sh_css_hrt_system_is_idle(void)
37 {
38         bool not_idle = false, idle;
39         fifo_channel_t ch;
40
41         idle = sp_ctrl_getbit(SP0_ID, SP_SC_REG, SP_IDLE_BIT);
42         not_idle |= !idle;
43         if (!idle)
44                 IA_CSS_WARNING("SP not idle");
45
46         idle = isp_ctrl_getbit(ISP0_ID, ISP_SC_REG, ISP_IDLE_BIT);
47         not_idle |= !idle;
48         if (!idle)
49                 IA_CSS_WARNING("ISP not idle");
50
51         for (ch=0; ch<N_FIFO_CHANNEL; ch++) {
52                 fifo_channel_state_t state;
53                 fifo_channel_get_state(FIFO_MONITOR0_ID, ch, &state);
54                 if (state.fifo_valid) {
55                         IA_CSS_WARNING("FIFO channel %d is not empty", ch);
56                         not_idle = true;
57                 }
58         }
59
60         return !not_idle;
61 }
62
63 enum ia_css_err sh_css_hrt_sp_wait(void)
64 {
65 #if defined(HAS_IRQ_MAP_VERSION_2)
66         irq_sw_channel_id_t     irq_id = IRQ_SW_CHANNEL0_ID;
67 #else
68         irq_sw_channel_id_t     irq_id = IRQ_SW_CHANNEL2_ID;
69 #endif
70         /*
71          * Wait till SP is idle or till there is a SW2 interrupt
72          * The SW2 interrupt will be used when frameloop runs on SP
73          * and signals an event with similar meaning as SP idle
74          * (e.g. frame_done)
75          */
76         while (!sp_ctrl_getbit(SP0_ID, SP_SC_REG, SP_IDLE_BIT) &&
77                 ((irq_reg_load(IRQ0_ID,
78                         _HRT_IRQ_CONTROLLER_STATUS_REG_IDX) &
79                         (1U<<(irq_id + IRQ_SW_CHANNEL_OFFSET))) == 0)) {
80                 hrt_sleep();
81         }
82
83 return IA_CSS_SUCCESS;
84 }