hc
2023-11-22 f743a7adbd6e230d66a6206fa115b59fec2d88eb
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 *************************************************************************
 * Rockchip driver for CIF ISP 1.0
 * (Based on Intel driver for sofiaxxx)
 *
 * Copyright (C) 2015 Intel Mobile Communications GmbH
 * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *************************************************************************
 */
 
#ifndef _CIF_ISP10_PLTFRM_H
#define _CIF_ISP10_PLTFRM_H
 
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/wait.h>
#include <linux/string.h>
#include <linux/platform_data/rk_isp10_platform.h>
 
struct cif_isp10_strm_fmt;
struct cif_isp10_csi_config;
struct cif_isp10_device;
struct cif_isp10_img_src;
struct pltfrm_cam_itf;
enum cif_isp10_pinctrl_state;
enum cif_isp10_inp;
enum cif_isp10_pm_state;
 
#define CIF_ISP10_PLTFRM_DEVICE struct device *
#define CIF_ISP10_PLTFRM_MEM_IO_ADDR void __iomem *
#define CIF_ISP10_PLTFRM_EVENT wait_queue_head_t
 
#ifdef CONFIG_CIF_ISP10_REG_TRACE
int
cif_isp10_pltfrm_rtrace_printf(
   struct device *dev,
   const char *fmt,
   ...);
 
int
cif_isp10_pltfrm_ftrace_printf(
   struct device *dev,
   const char *fmt,
   ...);
 
#else
#define cif_isp10_pltfrm_rtrace_printf(dev, str, ...)
#define cif_isp10_pltfrm_ftrace_printf(dev, str, ...)
#endif
 
#define cif_isp10_pltfrm_pr_dbg(dev, fmt, arg...) \
   do { \
       pr_debug("%s: " fmt, \
           __func__, ## arg); \
       cif_isp10_pltfrm_ftrace_printf(dev, "%s: " fmt, \
           __func__, ## arg); \
   } while (0)
#define cif_isp10_pltfrm_pr_info(dev, fmt, arg...) \
   do { \
       pr_info("%s: " fmt, \
           __func__, ## arg); \
       cif_isp10_pltfrm_ftrace_printf(dev, "%s: " fmt, \
           __func__, ## arg); \
   } while (0)
#define cif_isp10_pltfrm_pr_warn(dev, fmt, arg...) \
   do { \
       pr_warn("%s WARN: " fmt, \
           __func__, ## arg); \
       cif_isp10_pltfrm_ftrace_printf(dev, "%s WARN: " fmt, \
           __func__, ## arg); \
   } while (0)
#define cif_isp10_pltfrm_pr_err(dev, fmt, arg...) \
   do { \
       pr_err("%s(%d) ERR: " fmt, \
           __func__, __LINE__, ## arg); \
       cif_isp10_pltfrm_ftrace_printf(dev, "%s(%d) ERR: " fmt, \
           __func__, __LINE__, ## arg); \
   } while (0)
 
void cif_isp10_pltfrm_write_reg(
   struct device *dev,
   u32 data,
   CIF_ISP10_PLTFRM_MEM_IO_ADDR addr);
 
void cif_isp10_pltfrm_write_reg_OR(
   struct device *dev,
   u32 data,
   CIF_ISP10_PLTFRM_MEM_IO_ADDR addr);
 
void cif_isp10_pltfrm_write_reg_AND(
   struct device *dev,
   u32 data,
   CIF_ISP10_PLTFRM_MEM_IO_ADDR addr);
 
u32 cif_isp10_pltfrm_read_reg(
   struct device *dev,
   CIF_ISP10_PLTFRM_MEM_IO_ADDR addr);
 
#define cif_iowrite32(d, a) \
   cif_isp10_pltfrm_write_reg(NULL, (u32)(d), a)
#define cif_ioread32(a) \
   cif_isp10_pltfrm_read_reg(NULL, a)
#define cif_iowrite32OR(d, a) \
   cif_isp10_pltfrm_write_reg_OR(NULL, (u32)(d), a)
#define cif_iowrite32AND(d, a) \
   cif_isp10_pltfrm_write_reg_AND(NULL, (u32)(d), a)
/* BUG: Register write seems to fail sometimes w/o read before write. */
#define cif_iowrite32_verify(d, a, mask) \
   { \
       unsigned int i = 0; \
       unsigned long flags = 0; \
       spin_lock_irqsave(&dev->iowrite32_verify_lock, flags); \
       do { \
           cif_iowrite32(d, a); \
           udelay(1); \
           if (i++ == 50) { \
               pr_err("Error in writing %x@0x%p, read %x\n", \
                   (d) & (mask), a, ioread32(a)); \
                   WARN_ON(1); \
           } \
       } while ((ioread32(a) & mask) != ((d) & mask)); \
       spin_unlock_irqrestore(&dev->iowrite32_verify_lock, flags);\
   }
#define cif_iowrite32OR_verify(d, a, mask) \
   cif_iowrite32_verify((u32)(d) | cif_ioread32(a), a, mask)
#define cif_iowrite32AND_verify(d, a, mask) \
   cif_iowrite32_verify((u32)(d) & cif_ioread32(a), a, mask)
 
#define cif_isp10_pltfrm_event_init(_dev, _event) \
   init_waitqueue_head(_event)
 
#define cif_isp10_pltfrm_event_clear(_dev, _event)
 
#define cif_isp10_pltfrm_event_signal(_dev, _event) \
   wake_up_interruptible(_event)
 
#define cif_isp10_pltfrm_event_wait_timeout( \
   _dev, _event, _condition, _timeout_us) \
   wait_event_interruptible_timeout( \
       *(_event), _condition, ((_timeout_us) * HZ) / 1000000)
 
void
cif_isp10_pltfrm_debug_register_print_cb(
   struct device *dev,
   void (*print)(void *cntxt, const char *block_name),
   void *cntxt);
 
int cif_isp10_pltfrm_dev_init(
   struct cif_isp10_device *cif_isp_dev,
   struct device **dev,
   void __iomem **reg_base_addr);
 
void cif_isp10_pltfrm_dev_release(
   struct device *dev,
   struct cif_isp10_device *cif_isp10_dev);
 
int cif_isp10_pltfrm_pm_set_state(
   struct device *dev,
   enum cif_isp10_pm_state state);
 
int cif_isp10_pltfrm_write_cif_ana_bandgap_bias(
   struct device *dev,
   u32 val);
 
int cif_isp10_pltfrm_pinctrl_set_state(
   struct device *dev,
   enum cif_isp10_pinctrl_state pinctrl_state);
 
int cif_isp10_pltfrm_get_img_src_device(
   struct device *dev,
   struct cif_isp10_img_src **img_src_array,
   unsigned int array_len);
 
int cif_isp10_pltfrm_g_interface_config(
   struct cif_isp10_img_src *img_src,
   struct pltfrm_cam_itf *cam_itf);
 
int cif_isp10_pltfrm_irq_register_isr(
   struct device *dev,
   unsigned int mis,
   int (*isr)(unsigned int mis, void *cntxt),
   void *cntxt);
 
const char *cif_isp10_pltfrm_get_device_type(
   struct device *dev);
 
const char *cif_isp10_pltfrm_dev_string(
   struct device *dev);
 
int cif_isp10_pltfrm_soc_init(
   struct cif_isp10_device *cif_isp10_dev,
   struct pltfrm_soc_cfg *soc_cfg);
 
int cif_isp10_pltfrm_mipi_dphy_config(
   struct cif_isp10_device *cif_isp10_dev);
 
int cif_isp10_pltfrm_reset(
   struct cif_isp10_device *cif_isp10_dev);
 
#endif