hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
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
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Rockchip MIPI CSI2 DPHY driver
 *
 * Copyright (C) 2020 Rockchip Electronics Co., Ltd.
 */
 
#ifndef _PHY_ROCKCHIP_CSI2_DPHY_COMMON_H_
#define _PHY_ROCKCHIP_CSI2_DPHY_COMMON_H_
 
/* add new chip id in tail by time order */
enum csi2_dphy_chip_id {
   CHIP_ID_RK3568 = 0x0,
};
 
enum csi2_dphy_rx_pads {
   CSI2_DPHY_RX_PAD_SINK = 0,
   CSI2_DPHY_RX_PAD_SOURCE,
   CSI2_DPHY_RX_PADS_NUM,
};
 
enum csi2_dphy_lane_mode {
   LANE_MODE_UNDEF = 0x0,
   LANE_MODE_FULL,
   LANE_MODE_SPLIT,
};
 
struct grf_reg {
   u32 offset;
   u32 mask;
   u32 shift;
};
 
struct csi2dphy_reg {
   u32 offset;
};
 
#define MAX_DPHY_SENSORS    (2)
#define MAX_NUM_CSI2_DPHY    (0x2)
 
struct csi2_sensor {
   struct v4l2_subdev *sd;
   struct v4l2_mbus_config mbus;
   struct v4l2_mbus_framefmt format;
   int lanes;
};
 
struct csi2_dphy_hw;
 
struct csi2_dphy {
   struct device *dev;
   struct list_head list;
   struct csi2_dphy_hw *dphy_hw;
   struct v4l2_async_notifier notifier;
   struct v4l2_subdev sd;
   struct mutex mutex; /* lock for updating protection */
   struct media_pad pads[CSI2_DPHY_RX_PADS_NUM];
   struct csi2_sensor sensors[MAX_DPHY_SENSORS];
   u64 data_rate_mbps;
   int num_sensors;
   int phy_index;
   bool is_streaming;
   enum csi2_dphy_lane_mode lane_mode;
};
 
struct dphy_hw_drv_data {
   const struct    clk_bulk_data *clks;
   int num_clks;
   const struct hsfreq_range *hsfreq_ranges;
   int num_hsfreq_ranges;
   const struct grf_reg *grf_regs;
   const struct txrx_reg *txrx_regs;
   const struct csi2dphy_reg *csi2dphy_regs;
   void (*individual_init)(struct csi2_dphy_hw *hw);
   enum csi2_dphy_chip_id chip_id;
};
 
struct csi2_dphy_hw {
   struct device *dev;
   struct regmap *regmap_grf;
   const struct grf_reg *grf_regs;
   const struct txrx_reg *txrx_regs;
   const struct csi2dphy_reg *csi2dphy_regs;
   const struct dphy_hw_drv_data *drv_data;
   void __iomem *hw_base_addr;
   struct clk_bulk_data    *clks;
   struct csi2_dphy *dphy_dev[MAX_NUM_CSI2_DPHY];
   struct v4l2_subdev sd;
   struct mutex mutex; /* lock for updating protection */
   atomic_t stream_cnt;
   int num_clks;
   int num_sensors;
   int dphy_dev_num;
   enum csi2_dphy_lane_mode lane_mode;
 
   int (*stream_on)(struct csi2_dphy *dphy, struct v4l2_subdev *sd);
   int (*stream_off)(struct csi2_dphy *dphy, struct v4l2_subdev *sd);
};
 
extern struct platform_driver rockchip_csi2_dphy_driver;
 
#endif