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_of.h>
15 #include <drm/drm_mipi_dsi.h>
16 
17 struct samsung_dsim;
18 
19 #define DSIM_STATE_ENABLED		BIT(0)
20 #define DSIM_STATE_INITIALIZED		BIT(1)
21 #define DSIM_STATE_CMD_LPM		BIT(2)
22 #define DSIM_STATE_VIDOUT_AVAILABLE	BIT(3)
23 
24 enum samsung_dsim_type {
25 	DSIM_TYPE_EXYNOS3250,
26 	DSIM_TYPE_EXYNOS4210,
27 	DSIM_TYPE_EXYNOS5410,
28 	DSIM_TYPE_EXYNOS5422,
29 	DSIM_TYPE_EXYNOS5433,
30 	DSIM_TYPE_IMX8MM,
31 	DSIM_TYPE_IMX8MP,
32 	DSIM_TYPE_COUNT,
33 };
34 
35 #define samsung_dsim_hw_is_exynos(hw) \
36 	((hw) >= DSIM_TYPE_EXYNOS3250 && (hw) <= DSIM_TYPE_EXYNOS5433)
37 
38 struct samsung_dsim_transfer {
39 	struct list_head list;
40 	struct completion completed;
41 	int result;
42 	struct mipi_dsi_packet packet;
43 	u16 flags;
44 	u16 tx_done;
45 
46 	u8 *rx_payload;
47 	u16 rx_len;
48 	u16 rx_done;
49 };
50 
51 struct samsung_dsim_driver_data {
52 	const unsigned int *reg_ofs;
53 	unsigned int plltmr_reg;
54 	unsigned int has_freqband:1;
55 	unsigned int has_clklane_stop:1;
56 	unsigned int num_clks;
57 	unsigned int min_freq;
58 	unsigned int max_freq;
59 	unsigned int wait_for_reset;
60 	unsigned int num_bits_resol;
61 	unsigned int pll_p_offset;
62 	const unsigned int *reg_values;
63 	u16 m_min;
64 	u16 m_max;
65 };
66 
67 struct samsung_dsim_host_ops {
68 	int (*register_host)(struct samsung_dsim *dsim);
69 	void (*unregister_host)(struct samsung_dsim *dsim);
70 	int (*attach)(struct samsung_dsim *dsim, struct mipi_dsi_device *device);
71 	void (*detach)(struct samsung_dsim *dsim, struct mipi_dsi_device *device);
72 	irqreturn_t (*te_irq_handler)(struct samsung_dsim *dsim);
73 };
74 
75 struct samsung_dsim_plat_data {
76 	enum samsung_dsim_type hw_type;
77 	const struct samsung_dsim_host_ops *host_ops;
78 };
79 
80 struct samsung_dsim {
81 	struct mipi_dsi_host dsi_host;
82 	struct drm_bridge bridge;
83 	struct drm_bridge *out_bridge;
84 	struct device *dev;
85 	struct drm_display_mode mode;
86 
87 	void __iomem *reg_base;
88 	struct phy *phy;
89 	struct clk **clks;
90 	struct regulator_bulk_data supplies[2];
91 	int irq;
92 	struct gpio_desc *te_gpio;
93 
94 	u32 pll_clk_rate;
95 	u32 burst_clk_rate;
96 	u32 hs_clock;
97 	u32 esc_clk_rate;
98 	u32 lanes;
99 	u32 mode_flags;
100 	u32 format;
101 
102 	bool swap_dn_dp_clk;
103 	bool swap_dn_dp_data;
104 	int state;
105 	struct drm_property *brightness;
106 	struct completion completed;
107 
108 	spinlock_t transfer_lock; /* protects transfer_list */
109 	struct list_head transfer_list;
110 
111 	const struct samsung_dsim_driver_data *driver_data;
112 	const struct samsung_dsim_plat_data *plat_data;
113 
114 	void *priv;
115 };
116 
117 extern int samsung_dsim_probe(struct platform_device *pdev);
118 extern int samsung_dsim_remove(struct platform_device *pdev);
119 extern const struct dev_pm_ops samsung_dsim_pm_ops;
120 
121 #endif /* __SAMSUNG_DSIM__ */
122