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