GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / hive_isp_css_common / host / isp_private.h
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 #ifndef __ISP_PRIVATE_H_INCLUDED__
16 #define __ISP_PRIVATE_H_INCLUDED__
17
18 #ifdef HRT_MEMORY_ACCESS
19 #include <hrt/api.h>
20 #endif
21
22 #include "isp_public.h"
23
24 #include "device_access.h"
25
26 #include "assert_support.h"
27 #include "type_support.h"
28
29 STORAGE_CLASS_ISP_C void isp_ctrl_store(
30         const isp_ID_t          ID,
31         const unsigned int      reg,
32         const hrt_data          value)
33 {
34         assert(ID < N_ISP_ID);
35         assert(ISP_CTRL_BASE[ID] != (hrt_address)-1);
36 #if !defined(HRT_MEMORY_ACCESS)
37         ia_css_device_store_uint32(ISP_CTRL_BASE[ID] + reg*sizeof(hrt_data), value);
38 #else
39         hrt_master_port_store_32(ISP_CTRL_BASE[ID] + reg*sizeof(hrt_data), value);
40 #endif
41         return;
42 }
43
44 STORAGE_CLASS_ISP_C hrt_data isp_ctrl_load(
45         const isp_ID_t          ID,
46         const unsigned int      reg)
47 {
48         assert(ID < N_ISP_ID);
49         assert(ISP_CTRL_BASE[ID] != (hrt_address)-1);
50 #if !defined(HRT_MEMORY_ACCESS)
51         return ia_css_device_load_uint32(ISP_CTRL_BASE[ID] + reg*sizeof(hrt_data));
52 #else
53         return hrt_master_port_uload_32(ISP_CTRL_BASE[ID] + reg*sizeof(hrt_data));
54 #endif
55 }
56
57 STORAGE_CLASS_ISP_C bool isp_ctrl_getbit(
58         const isp_ID_t          ID,
59         const unsigned int      reg,
60         const unsigned int      bit)
61 {
62         hrt_data val = isp_ctrl_load(ID, reg);
63         return (val & (1UL << bit)) != 0;
64 }
65
66 STORAGE_CLASS_ISP_C void isp_ctrl_setbit(
67         const isp_ID_t          ID,
68         const unsigned int      reg,
69         const unsigned int      bit)
70 {
71         hrt_data        data = isp_ctrl_load(ID, reg);
72         isp_ctrl_store(ID, reg, (data | (1UL << bit)));
73         return;
74 }
75
76 STORAGE_CLASS_ISP_C void isp_ctrl_clearbit(
77         const isp_ID_t          ID,
78         const unsigned int      reg,
79         const unsigned int      bit)
80 {
81         hrt_data        data = isp_ctrl_load(ID, reg);
82         isp_ctrl_store(ID, reg, (data & ~(1UL << bit)));
83         return;
84 }
85
86 STORAGE_CLASS_ISP_C void isp_dmem_store(
87         const isp_ID_t          ID,
88         unsigned int            addr,
89         const void              *data,
90         const size_t            size)
91 {
92         assert(ID < N_ISP_ID);
93         assert(ISP_DMEM_BASE[ID] != (hrt_address)-1);
94 #if !defined(HRT_MEMORY_ACCESS)
95         ia_css_device_store(ISP_DMEM_BASE[ID] + addr, data, size);
96 #else
97         hrt_master_port_store(ISP_DMEM_BASE[ID] + addr, data, size);
98 #endif
99         return;
100 }
101
102 STORAGE_CLASS_ISP_C void isp_dmem_load(
103         const isp_ID_t          ID,
104         const unsigned int      addr,
105         void                    *data,
106         const size_t            size)
107 {
108         assert(ID < N_ISP_ID);
109         assert(ISP_DMEM_BASE[ID] != (hrt_address)-1);
110 #if !defined(HRT_MEMORY_ACCESS)
111         ia_css_device_load(ISP_DMEM_BASE[ID] + addr, data, size);
112 #else
113         hrt_master_port_load(ISP_DMEM_BASE[ID] + addr, data, size);
114 #endif
115         return;
116 }
117
118 STORAGE_CLASS_ISP_C void isp_dmem_store_uint32(
119         const isp_ID_t          ID,
120         unsigned int            addr,
121         const uint32_t          data)
122 {
123         assert(ID < N_ISP_ID);
124         assert(ISP_DMEM_BASE[ID] != (hrt_address)-1);
125         (void)ID;
126 #if !defined(HRT_MEMORY_ACCESS)
127         ia_css_device_store_uint32(ISP_DMEM_BASE[ID] + addr, data);
128 #else
129         hrt_master_port_store_32(ISP_DMEM_BASE[ID] + addr, data);
130 #endif
131         return;
132 }
133
134 STORAGE_CLASS_ISP_C uint32_t isp_dmem_load_uint32(
135         const isp_ID_t          ID,
136         const unsigned int      addr)
137 {
138         assert(ID < N_ISP_ID);
139         assert(ISP_DMEM_BASE[ID] != (hrt_address)-1);
140         (void)ID;
141 #if !defined(HRT_MEMORY_ACCESS)
142         return ia_css_device_load_uint32(ISP_DMEM_BASE[ID] + addr);
143 #else
144         return hrt_master_port_uload_32(ISP_DMEM_BASE[ID] + addr);
145 #endif
146 }
147
148 STORAGE_CLASS_ISP_C uint32_t isp_2w_cat_1w(
149         const uint16_t          x0,
150         const uint16_t          x1)
151 {
152         uint32_t out = ((uint32_t)(x1 & HIVE_ISP_VMEM_MASK) << ISP_VMEM_ELEMBITS)
153                 | (x0 & HIVE_ISP_VMEM_MASK);
154         return out;
155 }
156
157 #endif /* __ISP_PRIVATE_H_INCLUDED__ */