aboutsummaryrefslogtreecommitdiff
path: root/drivers/media/platform/hisi/isp/isp.h
blob: 2803e23e4d1e7f929589093ef419ab184025c83f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2018 Linaro Ltd.
 */

#ifndef HISI_ISP_H
#define HISI_ISP_H

#include <linux/regulator/consumer.h>

#include "isp-csiphy.h"
#include "isp-sr.h"
#include "isp-cvdr.h"

#define MASK0(name)  ((1<<(name##_LEN))-1)
#define MASK1(name)  (((1<<(name##_LEN))-1) << (name##_OFFSET))

/* operation on the field of a variable */
#define isp_readl_field(reg, name) \
	(((reg) >> (name##_OFFSET)) & MASK0(name))

#define isp_writel_field(reg, name, val) \
	(reg = ((reg) & ~MASK1(name)) | \
		(((val) & MASK0(name)) << (name##_OFFSET)))

#define ISP_NUM_CLKS 2

enum IRQ_MERGER_TYPE {
	IRQ_MERGER_DEBUG_0  = 0x0,
	IRQ_MERGER_DEBUG_1  = 0x20,
	IRQ_MERGER_DEBUG_2  = 0x40,
	IRQ_MERGER_DEBUG_3  = 0x60,
	IRQ_MERGER_DEBUG_4  = 0x80,
	IRQ_MERGER_ERROR_0  = 0xA0,
	IRQ_MERGER_ERROR_1  = 0xC0,
	IRQ_MERGER_FRPROC_0 = 0xE0,
	IRQ_MERGER_FRPROC_1 = 0x100,
	IRQ_MERGER_FRPROC_2 = 0x120,
	IRQ_MERGER_COMBINED = 0x140,
	IRQ_MERGER_IRQ_MAX  = 0xFF,
};

enum IRQ_MERGER_FUNC_TYPE {
	IRQ_MERGER_FUNC_IMS  = 0x0,
	IRQ_MERGER_FUNC_RIS  = 0x4,
	IRQ_MERGER_FUNC_MIS  = 0x8,
	IRQ_MERGER_FUNC_ICR  = 0xC,
	IRQ_MERGER_FUNC_ISR  = 0x10,
	IRQ_MERGER_FUNC_NO   = 0x1F,
};

#define IRQ_MERGER_IMSC_DEBUG0 \
	(IRQ_MERGER_DEBUG_0)
#define IRQ_MERGER_IMSC_DEBUG1 \
	(IRQ_MERGER_DEBUG_1)
#define IRQ_MERGER_IMSC_DEBUG2 \
	(IRQ_MERGER_DEBUG_2)
#define IRQ_MERGER_IMSC_DEBUG3 \
	(IRQ_MERGER_DEBUG_3)
#define IRQ_MERGER_IMSC_ERROR0 \
	(IRQ_MERGER_ERROR_0)
#define IRQ_MERGER_IMSC_ERROR1 \
	(IRQ_MERGER_ERROR_1)
#define IRQ_MERGER_IMSC_FRPROC0 \
	(IRQ_MERGER_FRPROC_0)
#define IRQ_MERGER_IMSC_FRPROC1 \
	(IRQ_MERGER_FRPROC_1)
#define IRQ_MERGER_IMSC_FRPROC2 \
	(IRQ_MERGER_FRPROC_2)

#define IRQ_MERGER_ICR_DEBUG0 \
	(IRQ_MERGER_DEBUG_0 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_DEBUG1 \
	(IRQ_MERGER_DEBUG_1 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_DEBUG2 \
	(IRQ_MERGER_DEBUG_2 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_DEBUG3 \
	(IRQ_MERGER_DEBUG_3 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_ERROR0 \
	(IRQ_MERGER_ERROR_0 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_ERROR1 \
	(IRQ_MERGER_ERROR_1 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_FRPROC0 \
	(IRQ_MERGER_FRPROC_0 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_FRPROC1 \
	(IRQ_MERGER_FRPROC_1 + IRQ_MERGER_FUNC_ICR)
#define IRQ_MERGER_ICR_FRPROC2 \
	(IRQ_MERGER_FRPROC_2 + IRQ_MERGER_FUNC_ICR)

#define IRQ_MERGER_SR_4_CVDR_RT_SOF_VPWR_23_OFFSET     17
#define IRQ_MERGER_SR_4_CVDR_RT_EOF_VPWR_23_OFFSET     21

#define	YUV_DT_420_8BITS 0x18
#define	YUV_DT_420_10BITS 0x19
#define	YUV_DT_LEGACY_420_8BITS 0x1A
#define	YUV_DT_420_8BITS_C 0x1C
#define	YUV_DT_420_10BITS_C 0x1D
#define	YUV_DT_422_8BITS 0x1E
#define	YUV_DT_422_10BITS 0x1F

#define	RAW_DT_RAW6 0x28
#define	RAW_DT_RAW7 0x29
#define	RAW_DT_RAW8 0x2A
#define	RAW_DT_RAW10 0x2B
#define	RAW_DT_RAW12 0x2C
#define	RAW_DT_RAW14 0x2D

struct resources {
	char *reg;
};

struct isp_clock {
	struct clk *clk;
	const char *name;
	u32 freq;
};

struct isp {
	void __iomem *ispss_ctrl;
	void __iomem *smmu_ctrl;
	void __iomem *irq_merger2;
	struct v4l2_device v4l2_dev;
	struct v4l2_async_notifier notifier;
	struct media_device media_dev;
	struct device *dev;
	struct csiphy_device *csiphy;
	struct sr_device *sr;
	struct cvdr_device *cvdr;
	struct isp_clock clks[ISP_NUM_CLKS];
	void *virt_addr;
	dma_addr_t hw_addr;
	int csiphy_num;
	u8 csiphy_id;
	unsigned int pool_size;
	unsigned int frame_size;
	unsigned int frame_count;
	unsigned int frame_num;
};

struct isp_camera_interface {
	struct csiphy_config cfg;
};

struct isp_async_subdev {
	struct v4l2_async_subdev asd; /* must be first */
	struct isp_camera_interface interface;
};

void isp_writel(void __iomem *base , u32 reg, u32 value);
u32 isp_readl(void __iomem *base , u32 reg);
int isp_enable_clocks(struct isp_clock *clks, struct device *dev);
void isp_disable_clocks(struct isp_clock *clks);
void isp_ispss_clear_irq_state(struct isp *isp);
void isp_ispss_enable_irq(struct isp *isp);
u32 isp_clear_irq(struct isp *isp, enum IRQ_MERGER_TYPE irq);
int frame_num2Offset(struct isp *isp, int frame_num);
void isp_config_smmu_bypass(struct isp *isp);

#endif /* HISI_ISP_H */