xref: /linux/include/drm/bridge/samsung-dsim.h (revision 58809f614e0e3f4e12b489bddf680bfeb31c0a20)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2022 Amarula Solutions(India)
4  * Author: Jagan Teki <jagan@amarulasolutions.com>
5  */
6 
7 #ifndef __SAMSUNG_DSIM__
8 #define __SAMSUNG_DSIM__
9 
10 #include <linux/gpio/consumer.h>
11 #include <linux/regulator/consumer.h>
12 
13 #include <drm/drm_atomic_helper.h>
14 #include <drm/drm_bridge.h>
15 #include <drm/drm_mipi_dsi.h>
16 #include <drm/drm_of.h>
17 
18 struct platform_device;
19 struct samsung_dsim;
20 
21 #define DSIM_STATE_ENABLED		BIT(0)
22 #define DSIM_STATE_INITIALIZED		BIT(1)
23 #define DSIM_STATE_CMD_LPM		BIT(2)
24 #define DSIM_STATE_VIDOUT_AVAILABLE	BIT(3)
25 
26 enum samsung_dsim_type {
27 	DSIM_TYPE_EXYNOS3250,
28 	DSIM_TYPE_EXYNOS4210,
29 	DSIM_TYPE_EXYNOS5410,
30 	DSIM_TYPE_EXYNOS5422,
31 	DSIM_TYPE_EXYNOS5433,
32 	DSIM_TYPE_EXYNOS7870,
33 	DSIM_TYPE_IMX8MM,
34 	DSIM_TYPE_IMX8MP,
35 	DSIM_TYPE_COUNT,
36 };
37 
38 #define samsung_dsim_hw_is_exynos(hw) \
39 	((hw) >= DSIM_TYPE_EXYNOS3250 && (hw) <= DSIM_TYPE_EXYNOS5433)
40 
41 struct samsung_dsim_transfer {
42 	struct list_head list;
43 	struct completion completed;
44 	int result;
45 	struct mipi_dsi_packet packet;
46 	u16 flags;
47 	u16 tx_done;
48 
49 	u8 *rx_payload;
50 	u16 rx_len;
51 	u16 rx_done;
52 };
53 
54 struct samsung_dsim_driver_data {
55 	const unsigned int *reg_ofs;
56 	unsigned int plltmr_reg;
57 	unsigned int has_legacy_status_reg:1;
58 	unsigned int has_freqband:1;
59 	unsigned int has_clklane_stop:1;
60 	unsigned int has_broken_fifoctrl_emptyhdr:1;
61 	unsigned int has_sfrctrl:1;
62 	struct clk_bulk_data *clk_data;
63 	unsigned int num_clks;
64 	unsigned int min_freq;
65 	unsigned int max_freq;
66 	unsigned int wait_for_hdr_fifo;
67 	unsigned int wait_for_reset;
68 	unsigned int num_bits_resol;
69 	unsigned int video_mode_bit;
70 	unsigned int pll_stable_bit;
71 	unsigned int esc_clken_bit;
72 	unsigned int byte_clken_bit;
73 	unsigned int tx_req_hsclk_bit;
74 	unsigned int lane_esc_clk_bit;
75 	unsigned int lane_esc_data_offset;
76 	unsigned int pll_p_offset;
77 	unsigned int pll_m_offset;
78 	unsigned int pll_s_offset;
79 	unsigned int main_vsa_offset;
80 	const unsigned int *reg_values;
81 	unsigned int pll_fin_min;
82 	unsigned int pll_fin_max;
83 	u16 m_min;
84 	u16 m_max;
85 };
86 
87 struct samsung_dsim_host_ops {
88 	int (*register_host)(struct samsung_dsim *dsim);
89 	void (*unregister_host)(struct samsung_dsim *dsim);
90 	int (*attach)(struct samsung_dsim *dsim, struct mipi_dsi_device *device);
91 	void (*detach)(struct samsung_dsim *dsim, struct mipi_dsi_device *device);
92 	irqreturn_t (*te_irq_handler)(struct samsung_dsim *dsim);
93 };
94 
95 struct samsung_dsim_plat_data {
96 	enum samsung_dsim_type hw_type;
97 	const struct samsung_dsim_host_ops *host_ops;
98 };
99 
100 struct samsung_dsim {
101 	struct mipi_dsi_host dsi_host;
102 	struct drm_bridge bridge;
103 	struct drm_bridge *out_bridge;
104 	struct device *dev;
105 	struct drm_display_mode mode;
106 
107 	void __iomem *reg_base;
108 	struct phy *phy;
109 	struct clk *pll_clk;
110 	struct regulator_bulk_data supplies[2];
111 	int irq;
112 	struct gpio_desc *te_gpio;
113 
114 	u32 pll_clk_rate;
115 	u32 burst_clk_rate;
116 	u32 hs_clock;
117 	u32 esc_clk_rate;
118 	u32 lanes;
119 	u32 mode_flags;
120 	u32 format;
121 
122 	bool swap_dn_dp_clk;
123 	bool swap_dn_dp_data;
124 	int state;
125 	struct drm_property *brightness;
126 	struct completion completed;
127 
128 	spinlock_t transfer_lock; /* protects transfer_list */
129 	struct list_head transfer_list;
130 
131 	const struct samsung_dsim_driver_data *driver_data;
132 	const struct samsung_dsim_plat_data *plat_data;
133 
134 	void *priv;
135 };
136 
137 extern int samsung_dsim_probe(struct platform_device *pdev);
138 extern void samsung_dsim_remove(struct platform_device *pdev);
139 extern const struct dev_pm_ops samsung_dsim_pm_ops;
140 
141 #endif /* __SAMSUNG_DSIM__ */
142