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 <linux/delay.h>
17
18#include <system_global.h>
19#include "isp.h"
20
21#ifndef __INLINE_ISP__
22#include "isp_private.h"
23#endif /* __INLINE_ISP__ */
24
25#include "assert_support.h"
26
27void cnd_isp_irq_enable(
28    const isp_ID_t		ID,
29    const bool		cnd)
30{
31	if (cnd) {
32		isp_ctrl_setbit(ID, ISP_IRQ_READY_REG, ISP_IRQ_READY_BIT);
33		/* Enabling the IRQ immediately triggers an interrupt, clear it */
34		isp_ctrl_setbit(ID, ISP_IRQ_CLEAR_REG, ISP_IRQ_CLEAR_BIT);
35	} else {
36		isp_ctrl_clearbit(ID, ISP_IRQ_READY_REG,
37				  ISP_IRQ_READY_BIT);
38	}
39	return;
40}
41
42/* ISP functions to control the ISP state from the host, even in crun. */
43
44/* Inspect readiness of an ISP indexed by ID */
45unsigned int isp_is_ready(isp_ID_t ID)
46{
47	assert(ID < N_ISP_ID);
48	return isp_ctrl_getbit(ID, ISP_SC_REG, ISP_IDLE_BIT);
49}
50
51/* Inspect sleeping of an ISP indexed by ID */
52unsigned int isp_is_sleeping(isp_ID_t ID)
53{
54	assert(ID < N_ISP_ID);
55	return isp_ctrl_getbit(ID, ISP_SC_REG, ISP_SLEEPING_BIT);
56}
57
58/* To be called by the host immediately before starting ISP ID. */
59void isp_start(isp_ID_t ID)
60{
61	assert(ID < N_ISP_ID);
62}
63
64/* Wake up ISP ID. */
65void isp_wake(isp_ID_t ID)
66{
67	assert(ID < N_ISP_ID);
68	isp_ctrl_setbit(ID, ISP_SC_REG, ISP_START_BIT);
69	udelay(1);
70}
71