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