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