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 has_broken_fifoctrl_emptyhdr:1;
57 	unsigned int num_clks;
58 	unsigned int min_freq;
59 	unsigned int max_freq;
60 	unsigned int wait_for_reset;
61 	unsigned int num_bits_resol;
62 	unsigned int pll_p_offset;
63 	const unsigned int *reg_values;
64 	u16 m_min;
65 	u16 m_max;
66 };
67 
68 struct samsung_dsim_host_ops {
69 	int (*register_host)(struct samsung_dsim *dsim);
70 	void (*unregister_host)(struct samsung_dsim *dsim);
71 	int (*attach)(struct samsung_dsim *dsim, struct mipi_dsi_device *device);
72 	void (*detach)(struct samsung_dsim *dsim, struct mipi_dsi_device *device);
73 	irqreturn_t (*te_irq_handler)(struct samsung_dsim *dsim);
74 };
75 
76 struct samsung_dsim_plat_data {
77 	enum samsung_dsim_type hw_type;
78 	const struct samsung_dsim_host_ops *host_ops;
79 };
80 
81 struct samsung_dsim {
82 	struct mipi_dsi_host dsi_host;
83 	struct drm_bridge bridge;
84 	struct drm_bridge *out_bridge;
85 	struct device *dev;
86 	struct drm_display_mode mode;
87 
88 	void __iomem *reg_base;
89 	struct phy *phy;
90 	struct clk **clks;
91 	struct regulator_bulk_data supplies[2];
92 	int irq;
93 	struct gpio_desc *te_gpio;
94 
95 	u32 pll_clk_rate;
96 	u32 burst_clk_rate;
97 	u32 hs_clock;
98 	u32 esc_clk_rate;
99 	u32 lanes;
100 	u32 mode_flags;
101 	u32 format;
102 
103 	bool swap_dn_dp_clk;
104 	bool swap_dn_dp_data;
105 	int state;
106 	struct drm_property *brightness;
107 	struct completion completed;
108 
109 	spinlock_t transfer_lock; /* protects transfer_list */
110 	struct list_head transfer_list;
111 
112 	const struct samsung_dsim_driver_data *driver_data;
113 	const struct samsung_dsim_plat_data *plat_data;
114 
115 	void *priv;
116 };
117 
118 extern int samsung_dsim_probe(struct platform_device *pdev);
119 extern int samsung_dsim_remove(struct platform_device *pdev);
120 extern const struct dev_pm_ops samsung_dsim_pm_ops;
121 
122 #endif /* __SAMSUNG_DSIM__ */
123