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 "input_system.h"
17
18#include "ia_css_isys.h"
19#include "platform_support.h"
20
21#ifdef ISP2401
22#include "isys_dma_public.h"	/* isys2401_dma_set_max_burst_size() */
23#include "isys_irq.h"
24#endif
25
26#if !defined(ISP2401)
27input_system_err_t ia_css_isys_init(void)
28{
29	backend_channel_cfg_t backend_ch0;
30	backend_channel_cfg_t backend_ch1;
31	target_cfg2400_t targetB;
32	target_cfg2400_t targetC;
33	u32 acq_mem_region_size = 24;
34	u32 acq_nof_mem_regions = 2;
35	input_system_err_t error = INPUT_SYSTEM_ERR_NO_ERROR;
36
37	memset(&backend_ch0, 0, sizeof(backend_channel_cfg_t));
38	memset(&backend_ch1, 0, sizeof(backend_channel_cfg_t));
39	memset(&targetB, 0, sizeof(targetB));
40	memset(&targetC, 0, sizeof(targetC));
41
42	error = input_system_configuration_reset();
43	if (error != INPUT_SYSTEM_ERR_NO_ERROR)
44		return error;
45
46	error = input_system_csi_xmem_channel_cfg(
47		    0,			/*ch_id                 */
48		    INPUT_SYSTEM_PORT_A,	/*port                  */
49		    backend_ch0,		/*backend_ch            */
50		    32,			/*mem_region_size       */
51		    6,			/*nof_mem_regions       */
52		    acq_mem_region_size,	/*acq_mem_region_size   */
53		    acq_nof_mem_regions,	/*acq_nof_mem_regions   */
54		    targetB,		/*target                */
55		    3);			/*nof_xmem_buffers      */
56	if (error != INPUT_SYSTEM_ERR_NO_ERROR)
57		return error;
58
59	error = input_system_csi_xmem_channel_cfg(
60		    1,			/*ch_id                 */
61		    INPUT_SYSTEM_PORT_B,	/*port                  */
62		    backend_ch0,		/*backend_ch            */
63		    16,			/*mem_region_size       */
64		    3,			/*nof_mem_regions       */
65		    acq_mem_region_size,	/*acq_mem_region_size   */
66		    acq_nof_mem_regions,	/*acq_nof_mem_regions   */
67		    targetB,		/*target                */
68		    3);			/*nof_xmem_buffers      */
69	if (error != INPUT_SYSTEM_ERR_NO_ERROR)
70		return error;
71
72	error = input_system_csi_xmem_channel_cfg(
73		    2,			/*ch_id                 */
74		    INPUT_SYSTEM_PORT_C,	/*port                  */
75		    backend_ch1,		/*backend_ch            */
76		    32,			/*mem_region_size       */
77		    3,			/*nof_mem_regions       */
78		    acq_mem_region_size,	/*acq_mem_region_size   */
79		    acq_nof_mem_regions,	/*acq_nof_mem_regions   */
80		    targetC,		/*target                */
81		    2);			/*nof_xmem_buffers      */
82	if (error != INPUT_SYSTEM_ERR_NO_ERROR)
83		return error;
84
85	error = input_system_configuration_commit();
86
87	return error;
88}
89#elif defined(ISP2401)
90input_system_err_t ia_css_isys_init(void)
91{
92	ia_css_isys_csi_rx_lut_rmgr_init();
93	ia_css_isys_ibuf_rmgr_init();
94	ia_css_isys_dma_channel_rmgr_init();
95	ia_css_isys_stream2mmio_sid_rmgr_init();
96
97	isys2401_dma_set_max_burst_size(ISYS2401_DMA0_ID,
98					1 /* Non Burst DMA transactions */);
99
100	/* Enable 2401 input system IRQ status for driver to retrieve */
101	isys_irqc_status_enable(ISYS_IRQ0_ID);
102	isys_irqc_status_enable(ISYS_IRQ1_ID);
103	isys_irqc_status_enable(ISYS_IRQ2_ID);
104
105	return INPUT_SYSTEM_ERR_NO_ERROR;
106}
107#endif
108
109#if !defined(ISP2401)
110void ia_css_isys_uninit(void)
111{
112}
113#elif defined(ISP2401)
114void ia_css_isys_uninit(void)
115{
116	ia_css_isys_csi_rx_lut_rmgr_uninit();
117	ia_css_isys_ibuf_rmgr_uninit();
118	ia_css_isys_dma_channel_rmgr_uninit();
119	ia_css_isys_stream2mmio_sid_rmgr_uninit();
120}
121#endif
122
123