Lines Matching full:dsi
3 * i.MX8 NWL MIPI DSI host driver
33 #include "nwl-dsi.h"
35 #define DRV_NAME "nwl-dsi"
83 * The DSI host controller needs this reset sequence according to NWL:
84 * 1. Deassert pclk reset to get access to DSI regs
85 * 2. Configure DSI Host and DPHY and enable DPHY
87 * 4. Send DSI cmds to configure peripheral (handled by panel drv)
89 * DSI data
91 * TODO: Since panel_bridges do their DSI setup in enable we
100 /* DSI clocks */
111 /* dsi lanes */
134 static int nwl_dsi_clear_error(struct nwl_dsi *dsi) in nwl_dsi_clear_error() argument
136 int ret = dsi->error; in nwl_dsi_clear_error()
138 dsi->error = 0; in nwl_dsi_clear_error()
142 static void nwl_dsi_write(struct nwl_dsi *dsi, unsigned int reg, u32 val) in nwl_dsi_write() argument
146 if (dsi->error) in nwl_dsi_write()
149 ret = regmap_write(dsi->regmap, reg, val); in nwl_dsi_write()
151 DRM_DEV_ERROR(dsi->dev, in nwl_dsi_write()
152 "Failed to write NWL DSI reg 0x%x: %d\n", reg, in nwl_dsi_write()
154 dsi->error = ret; in nwl_dsi_write()
158 static u32 nwl_dsi_read(struct nwl_dsi *dsi, u32 reg) in nwl_dsi_read() argument
163 if (dsi->error) in nwl_dsi_read()
166 ret = regmap_read(dsi->regmap, reg, &val); in nwl_dsi_read()
168 DRM_DEV_ERROR(dsi->dev, "Failed to read NWL DSI reg 0x%x: %d\n", in nwl_dsi_read()
170 dsi->error = ret; in nwl_dsi_read()
194 static u32 ps2bc(struct nwl_dsi *dsi, unsigned long long ps) in ps2bc() argument
196 u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); in ps2bc()
198 return DIV64_U64_ROUND_UP(ps * dsi->mode.clock * bpp, in ps2bc()
199 dsi->lanes * 8ULL * NSEC_PER_SEC); in ps2bc()
205 static u32 ui2bc(struct nwl_dsi *dsi, unsigned long long ui) in ui2bc() argument
207 u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); in ui2bc()
209 return DIV64_U64_ROUND_UP(ui * dsi->lanes, in ui2bc()
210 dsi->mode.clock * 1000 * bpp); in ui2bc()
221 static int nwl_dsi_config_host(struct nwl_dsi *dsi) in nwl_dsi_config_host() argument
224 struct phy_configure_opts_mipi_dphy *cfg = &dsi->phy_cfg.mipi_dphy; in nwl_dsi_config_host()
226 if (dsi->lanes < 1 || dsi->lanes > 4) in nwl_dsi_config_host()
229 DRM_DEV_DEBUG_DRIVER(dsi->dev, "DSI Lanes %d\n", dsi->lanes); in nwl_dsi_config_host()
230 nwl_dsi_write(dsi, NWL_DSI_CFG_NUM_LANES, dsi->lanes - 1); in nwl_dsi_config_host()
232 if (dsi->dsi_mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) { in nwl_dsi_config_host()
233 nwl_dsi_write(dsi, NWL_DSI_CFG_NONCONTINUOUS_CLK, 0x01); in nwl_dsi_config_host()
234 nwl_dsi_write(dsi, NWL_DSI_CFG_AUTOINSERT_EOTP, 0x01); in nwl_dsi_config_host()
236 nwl_dsi_write(dsi, NWL_DSI_CFG_NONCONTINUOUS_CLK, 0x00); in nwl_dsi_config_host()
237 nwl_dsi_write(dsi, NWL_DSI_CFG_AUTOINSERT_EOTP, 0x00); in nwl_dsi_config_host()
241 cycles = ui2bc(dsi, cfg->clk_pre); in nwl_dsi_config_host()
242 DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_t_pre: 0x%x\n", cycles); in nwl_dsi_config_host()
243 nwl_dsi_write(dsi, NWL_DSI_CFG_T_PRE, cycles); in nwl_dsi_config_host()
244 cycles = ps2bc(dsi, cfg->lpx + cfg->clk_prepare + cfg->clk_zero); in nwl_dsi_config_host()
245 DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_tx_gap (pre): 0x%x\n", cycles); in nwl_dsi_config_host()
246 cycles += ui2bc(dsi, cfg->clk_pre); in nwl_dsi_config_host()
247 DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_t_post: 0x%x\n", cycles); in nwl_dsi_config_host()
248 nwl_dsi_write(dsi, NWL_DSI_CFG_T_POST, cycles); in nwl_dsi_config_host()
249 cycles = ps2bc(dsi, cfg->hs_exit); in nwl_dsi_config_host()
250 DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_tx_gap: 0x%x\n", cycles); in nwl_dsi_config_host()
251 nwl_dsi_write(dsi, NWL_DSI_CFG_TX_GAP, cycles); in nwl_dsi_config_host()
253 nwl_dsi_write(dsi, NWL_DSI_CFG_EXTRA_CMDS_AFTER_EOTP, 0x01); in nwl_dsi_config_host()
254 nwl_dsi_write(dsi, NWL_DSI_CFG_HTX_TO_COUNT, 0x00); in nwl_dsi_config_host()
255 nwl_dsi_write(dsi, NWL_DSI_CFG_LRX_H_TO_COUNT, 0x00); in nwl_dsi_config_host()
256 nwl_dsi_write(dsi, NWL_DSI_CFG_BTA_H_TO_COUNT, 0x00); in nwl_dsi_config_host()
259 DRM_DEV_DEBUG_DRIVER(dsi->dev, "cfg_twakeup: 0x%x\n", cycles); in nwl_dsi_config_host()
260 nwl_dsi_write(dsi, NWL_DSI_CFG_TWAKEUP, cycles); in nwl_dsi_config_host()
262 return nwl_dsi_clear_error(dsi); in nwl_dsi_config_host()
265 static int nwl_dsi_config_dpi(struct nwl_dsi *dsi) in nwl_dsi_config_dpi() argument
273 hfront_porch = dsi->mode.hsync_start - dsi->mode.hdisplay; in nwl_dsi_config_dpi()
274 hsync_len = dsi->mode.hsync_end - dsi->mode.hsync_start; in nwl_dsi_config_dpi()
275 hback_porch = dsi->mode.htotal - dsi->mode.hsync_end; in nwl_dsi_config_dpi()
277 vfront_porch = dsi->mode.vsync_start - dsi->mode.vdisplay; in nwl_dsi_config_dpi()
278 vsync_len = dsi->mode.vsync_end - dsi->mode.vsync_start; in nwl_dsi_config_dpi()
279 vback_porch = dsi->mode.vtotal - dsi->mode.vsync_end; in nwl_dsi_config_dpi()
281 DRM_DEV_DEBUG_DRIVER(dsi->dev, "hfront_porch = %d\n", hfront_porch); in nwl_dsi_config_dpi()
282 DRM_DEV_DEBUG_DRIVER(dsi->dev, "hback_porch = %d\n", hback_porch); in nwl_dsi_config_dpi()
283 DRM_DEV_DEBUG_DRIVER(dsi->dev, "hsync_len = %d\n", hsync_len); in nwl_dsi_config_dpi()
284 DRM_DEV_DEBUG_DRIVER(dsi->dev, "hdisplay = %d\n", dsi->mode.hdisplay); in nwl_dsi_config_dpi()
285 DRM_DEV_DEBUG_DRIVER(dsi->dev, "vfront_porch = %d\n", vfront_porch); in nwl_dsi_config_dpi()
286 DRM_DEV_DEBUG_DRIVER(dsi->dev, "vback_porch = %d\n", vback_porch); in nwl_dsi_config_dpi()
287 DRM_DEV_DEBUG_DRIVER(dsi->dev, "vsync_len = %d\n", vsync_len); in nwl_dsi_config_dpi()
288 DRM_DEV_DEBUG_DRIVER(dsi->dev, "vactive = %d\n", dsi->mode.vdisplay); in nwl_dsi_config_dpi()
289 DRM_DEV_DEBUG_DRIVER(dsi->dev, "clock = %d kHz\n", dsi->mode.clock); in nwl_dsi_config_dpi()
291 color_format = nwl_dsi_get_dpi_pixel_format(dsi->format); in nwl_dsi_config_dpi()
293 DRM_DEV_ERROR(dsi->dev, "Invalid color format 0x%x\n", in nwl_dsi_config_dpi()
294 dsi->format); in nwl_dsi_config_dpi()
297 DRM_DEV_DEBUG_DRIVER(dsi->dev, "pixel fmt = %d\n", dsi->format); in nwl_dsi_config_dpi()
299 nwl_dsi_write(dsi, NWL_DSI_INTERFACE_COLOR_CODING, NWL_DSI_DPI_24_BIT); in nwl_dsi_config_dpi()
300 nwl_dsi_write(dsi, NWL_DSI_PIXEL_FORMAT, color_format); in nwl_dsi_config_dpi()
305 nwl_dsi_write(dsi, NWL_DSI_VSYNC_POLARITY, in nwl_dsi_config_dpi()
307 nwl_dsi_write(dsi, NWL_DSI_HSYNC_POLARITY, in nwl_dsi_config_dpi()
310 burst_mode = (dsi->dsi_mode_flags & MIPI_DSI_MODE_VIDEO_BURST) && in nwl_dsi_config_dpi()
311 !(dsi->dsi_mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE); in nwl_dsi_config_dpi()
314 nwl_dsi_write(dsi, NWL_DSI_VIDEO_MODE, NWL_DSI_VM_BURST_MODE); in nwl_dsi_config_dpi()
315 nwl_dsi_write(dsi, NWL_DSI_PIXEL_FIFO_SEND_LEVEL, 256); in nwl_dsi_config_dpi()
317 mode = ((dsi->dsi_mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) ? in nwl_dsi_config_dpi()
320 nwl_dsi_write(dsi, NWL_DSI_VIDEO_MODE, mode); in nwl_dsi_config_dpi()
321 nwl_dsi_write(dsi, NWL_DSI_PIXEL_FIFO_SEND_LEVEL, in nwl_dsi_config_dpi()
322 dsi->mode.hdisplay); in nwl_dsi_config_dpi()
325 nwl_dsi_write(dsi, NWL_DSI_HFP, hfront_porch); in nwl_dsi_config_dpi()
326 nwl_dsi_write(dsi, NWL_DSI_HBP, hback_porch); in nwl_dsi_config_dpi()
327 nwl_dsi_write(dsi, NWL_DSI_HSA, hsync_len); in nwl_dsi_config_dpi()
329 nwl_dsi_write(dsi, NWL_DSI_ENABLE_MULT_PKTS, 0x0); in nwl_dsi_config_dpi()
330 nwl_dsi_write(dsi, NWL_DSI_BLLP_MODE, 0x1); in nwl_dsi_config_dpi()
331 nwl_dsi_write(dsi, NWL_DSI_USE_NULL_PKT_BLLP, 0x0); in nwl_dsi_config_dpi()
332 nwl_dsi_write(dsi, NWL_DSI_VC, 0x0); in nwl_dsi_config_dpi()
334 nwl_dsi_write(dsi, NWL_DSI_PIXEL_PAYLOAD_SIZE, dsi->mode.hdisplay); in nwl_dsi_config_dpi()
335 nwl_dsi_write(dsi, NWL_DSI_VACTIVE, dsi->mode.vdisplay - 1); in nwl_dsi_config_dpi()
336 nwl_dsi_write(dsi, NWL_DSI_VBP, vback_porch); in nwl_dsi_config_dpi()
337 nwl_dsi_write(dsi, NWL_DSI_VFP, vfront_porch); in nwl_dsi_config_dpi()
339 return nwl_dsi_clear_error(dsi); in nwl_dsi_config_dpi()
342 static int nwl_dsi_init_interrupts(struct nwl_dsi *dsi) in nwl_dsi_init_interrupts() argument
346 nwl_dsi_write(dsi, NWL_DSI_IRQ_MASK, 0xffffffff); in nwl_dsi_init_interrupts()
347 nwl_dsi_write(dsi, NWL_DSI_IRQ_MASK2, 0x7); in nwl_dsi_init_interrupts()
354 nwl_dsi_write(dsi, NWL_DSI_IRQ_MASK, irq_enable); in nwl_dsi_init_interrupts()
356 return nwl_dsi_clear_error(dsi); in nwl_dsi_init_interrupts()
362 struct nwl_dsi *dsi = container_of(dsi_host, struct nwl_dsi, dsi_host); in nwl_dsi_host_attach() local
363 struct device *dev = dsi->dev; in nwl_dsi_host_attach()
371 dsi->lanes = device->lanes; in nwl_dsi_host_attach()
372 dsi->format = device->format; in nwl_dsi_host_attach()
373 dsi->dsi_mode_flags = device->mode_flags; in nwl_dsi_host_attach()
378 static bool nwl_dsi_read_packet(struct nwl_dsi *dsi, u32 status) in nwl_dsi_read_packet() argument
380 struct device *dev = dsi->dev; in nwl_dsi_read_packet()
381 struct nwl_dsi_transfer *xfer = dsi->xfer; in nwl_dsi_read_packet()
395 val = nwl_dsi_read(dsi, NWL_DSI_RX_PKT_HEADER); in nwl_dsi_read_packet()
396 err = nwl_dsi_clear_error(dsi); in nwl_dsi_read_packet()
431 DRM_DEV_ERROR(dev, "[%02X] DSI error report: 0x%02x\n", in nwl_dsi_read_packet()
457 val = nwl_dsi_read(dsi, NWL_DSI_RX_PAYLOAD); in nwl_dsi_read_packet()
468 val = nwl_dsi_read(dsi, NWL_DSI_RX_PAYLOAD); in nwl_dsi_read_packet()
486 err = nwl_dsi_clear_error(dsi); in nwl_dsi_read_packet()
493 static void nwl_dsi_finish_transmission(struct nwl_dsi *dsi, u32 status) in nwl_dsi_finish_transmission() argument
495 struct nwl_dsi_transfer *xfer = dsi->xfer; in nwl_dsi_finish_transmission()
508 end_packet = nwl_dsi_read_packet(dsi, status); in nwl_dsi_finish_transmission()
515 static void nwl_dsi_begin_transmission(struct nwl_dsi *dsi) in nwl_dsi_begin_transmission() argument
517 struct nwl_dsi_transfer *xfer = dsi->xfer; in nwl_dsi_begin_transmission()
533 nwl_dsi_write(dsi, NWL_DSI_TX_PAYLOAD, val); in nwl_dsi_begin_transmission()
549 nwl_dsi_write(dsi, NWL_DSI_TX_PAYLOAD, val); in nwl_dsi_begin_transmission()
561 if (hs_workaround && (dsi->quirks & E11418_HS_MODE_QUIRK)) { in nwl_dsi_begin_transmission()
562 DRM_DEV_DEBUG_DRIVER(dsi->dev, in nwl_dsi_begin_transmission()
572 nwl_dsi_write(dsi, NWL_DSI_PKT_CONTROL, val); in nwl_dsi_begin_transmission()
575 nwl_dsi_write(dsi, NWL_DSI_SEND_PACKET, 0x1); in nwl_dsi_begin_transmission()
581 struct nwl_dsi *dsi = container_of(dsi_host, struct nwl_dsi, dsi_host); in nwl_dsi_host_transfer() local
586 dsi->xfer = &xfer; in nwl_dsi_host_transfer()
589 dsi->xfer = NULL; in nwl_dsi_host_transfer()
613 ret = clk_prepare_enable(dsi->rx_esc_clk); in nwl_dsi_host_transfer()
615 DRM_DEV_ERROR(dsi->dev, "Failed to enable rx_esc clk: %zd\n", in nwl_dsi_host_transfer()
619 DRM_DEV_DEBUG_DRIVER(dsi->dev, "Enabled rx_esc clk @%lu Hz\n", in nwl_dsi_host_transfer()
620 clk_get_rate(dsi->rx_esc_clk)); in nwl_dsi_host_transfer()
622 /* Initiate the DSI packet transmision */ in nwl_dsi_host_transfer()
623 nwl_dsi_begin_transmission(dsi); in nwl_dsi_host_transfer()
627 DRM_DEV_ERROR(dsi_host->dev, "[%02X] DSI transfer timed out\n", in nwl_dsi_host_transfer()
634 clk_disable_unprepare(dsi->rx_esc_clk); in nwl_dsi_host_transfer()
647 struct nwl_dsi *dsi = data; in nwl_dsi_irq_handler() local
649 irq_status = nwl_dsi_read(dsi, NWL_DSI_IRQ_STATUS); in nwl_dsi_irq_handler()
652 DRM_DEV_ERROR_RATELIMITED(dsi->dev, "tx fifo overflow\n"); in nwl_dsi_irq_handler()
655 DRM_DEV_ERROR_RATELIMITED(dsi->dev, "HS tx timeout\n"); in nwl_dsi_irq_handler()
660 nwl_dsi_finish_transmission(dsi, irq_status); in nwl_dsi_irq_handler()
665 static int nwl_dsi_enable(struct nwl_dsi *dsi) in nwl_dsi_enable() argument
667 struct device *dev = dsi->dev; in nwl_dsi_enable()
668 union phy_configure_opts *phy_cfg = &dsi->phy_cfg; in nwl_dsi_enable()
671 if (!dsi->lanes) { in nwl_dsi_enable()
672 DRM_DEV_ERROR(dev, "Need DSI lanes: %d\n", dsi->lanes); in nwl_dsi_enable()
676 ret = phy_init(dsi->phy); in nwl_dsi_enable()
678 DRM_DEV_ERROR(dev, "Failed to init DSI phy: %d\n", ret); in nwl_dsi_enable()
682 ret = phy_configure(dsi->phy, phy_cfg); in nwl_dsi_enable()
684 DRM_DEV_ERROR(dev, "Failed to configure DSI phy: %d\n", ret); in nwl_dsi_enable()
688 ret = clk_prepare_enable(dsi->tx_esc_clk); in nwl_dsi_enable()
690 DRM_DEV_ERROR(dsi->dev, "Failed to enable tx_esc clk: %d\n", in nwl_dsi_enable()
694 DRM_DEV_DEBUG_DRIVER(dsi->dev, "Enabled tx_esc clk @%lu Hz\n", in nwl_dsi_enable()
695 clk_get_rate(dsi->tx_esc_clk)); in nwl_dsi_enable()
697 ret = nwl_dsi_config_host(dsi); in nwl_dsi_enable()
699 DRM_DEV_ERROR(dev, "Failed to set up DSI: %d", ret); in nwl_dsi_enable()
703 ret = nwl_dsi_config_dpi(dsi); in nwl_dsi_enable()
709 ret = phy_power_on(dsi->phy); in nwl_dsi_enable()
715 ret = nwl_dsi_init_interrupts(dsi); in nwl_dsi_enable()
722 phy_power_off(dsi->phy); in nwl_dsi_enable()
724 clk_disable_unprepare(dsi->tx_esc_clk); in nwl_dsi_enable()
726 phy_exit(dsi->phy); in nwl_dsi_enable()
731 static int nwl_dsi_disable(struct nwl_dsi *dsi) in nwl_dsi_disable() argument
733 struct device *dev = dsi->dev; in nwl_dsi_disable()
737 phy_power_off(dsi->phy); in nwl_dsi_disable()
738 phy_exit(dsi->phy); in nwl_dsi_disable()
740 /* Disabling the clock before the phy breaks enabling dsi again */ in nwl_dsi_disable()
741 clk_disable_unprepare(dsi->tx_esc_clk); in nwl_dsi_disable()
750 struct nwl_dsi *dsi = bridge_to_dsi(bridge); in nwl_dsi_bridge_atomic_disable() local
753 nwl_dsi_disable(dsi); in nwl_dsi_bridge_atomic_disable()
755 ret = reset_control_assert(dsi->rst_dpi); in nwl_dsi_bridge_atomic_disable()
757 DRM_DEV_ERROR(dsi->dev, "Failed to assert DPI: %d\n", ret); in nwl_dsi_bridge_atomic_disable()
760 ret = reset_control_assert(dsi->rst_byte); in nwl_dsi_bridge_atomic_disable()
762 DRM_DEV_ERROR(dsi->dev, "Failed to assert ESC: %d\n", ret); in nwl_dsi_bridge_atomic_disable()
765 ret = reset_control_assert(dsi->rst_esc); in nwl_dsi_bridge_atomic_disable()
767 DRM_DEV_ERROR(dsi->dev, "Failed to assert BYTE: %d\n", ret); in nwl_dsi_bridge_atomic_disable()
770 ret = reset_control_assert(dsi->rst_pclk); in nwl_dsi_bridge_atomic_disable()
772 DRM_DEV_ERROR(dsi->dev, "Failed to assert PCLK: %d\n", ret); in nwl_dsi_bridge_atomic_disable()
776 clk_disable_unprepare(dsi->core_clk); in nwl_dsi_bridge_atomic_disable()
777 clk_disable_unprepare(dsi->lcdif_clk); in nwl_dsi_bridge_atomic_disable()
779 pm_runtime_put(dsi->dev); in nwl_dsi_bridge_atomic_disable()
782 static int nwl_dsi_get_dphy_params(struct nwl_dsi *dsi, in nwl_dsi_get_dphy_params() argument
789 if (dsi->lanes < 1 || dsi->lanes > 4) in nwl_dsi_get_dphy_params()
794 * dphy and nwl dsi host in nwl_dsi_get_dphy_params()
797 mipi_dsi_pixel_format_to_bpp(dsi->format), dsi->lanes, in nwl_dsi_get_dphy_params()
802 rate = clk_get_rate(dsi->tx_esc_clk); in nwl_dsi_get_dphy_params()
803 DRM_DEV_DEBUG_DRIVER(dsi->dev, "LP clk is @%lu Hz\n", rate); in nwl_dsi_get_dphy_params()
814 struct nwl_dsi *dsi = bridge_to_dsi(bridge); in nwl_dsi_bridge_mode_valid() local
815 int bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); in nwl_dsi_bridge_mode_valid()
817 if (mode->clock * bpp > 15000000 * dsi->lanes) in nwl_dsi_bridge_mode_valid()
820 if (mode->clock * bpp < 80000 * dsi->lanes) in nwl_dsi_bridge_mode_valid()
849 struct nwl_dsi *dsi = bridge_to_dsi(bridge); in nwl_dsi_bridge_mode_set() local
850 struct device *dev = dsi->dev; in nwl_dsi_bridge_mode_set()
855 ret = nwl_dsi_get_dphy_params(dsi, adjusted_mode, &new_cfg); in nwl_dsi_bridge_mode_set()
863 if (new_cfg.mipi_dphy.hs_clk_rate == dsi->phy_cfg.mipi_dphy.hs_clk_rate) in nwl_dsi_bridge_mode_set()
866 phy_ref_rate = clk_get_rate(dsi->phy_ref_clk); in nwl_dsi_bridge_mode_set()
869 memcpy(&dsi->phy_cfg, &new_cfg, sizeof(new_cfg)); in nwl_dsi_bridge_mode_set()
871 memcpy(&dsi->mode, adjusted_mode, sizeof(dsi->mode)); in nwl_dsi_bridge_mode_set()
879 struct nwl_dsi *dsi = bridge_to_dsi(bridge); in nwl_dsi_bridge_atomic_pre_enable() local
882 pm_runtime_get_sync(dsi->dev); in nwl_dsi_bridge_atomic_pre_enable()
884 if (clk_prepare_enable(dsi->lcdif_clk) < 0) in nwl_dsi_bridge_atomic_pre_enable()
886 if (clk_prepare_enable(dsi->core_clk) < 0) in nwl_dsi_bridge_atomic_pre_enable()
889 /* Step 1 from DSI reset-out instructions */ in nwl_dsi_bridge_atomic_pre_enable()
890 ret = reset_control_deassert(dsi->rst_pclk); in nwl_dsi_bridge_atomic_pre_enable()
892 DRM_DEV_ERROR(dsi->dev, "Failed to deassert PCLK: %d\n", ret); in nwl_dsi_bridge_atomic_pre_enable()
896 /* Step 2 from DSI reset-out instructions */ in nwl_dsi_bridge_atomic_pre_enable()
897 nwl_dsi_enable(dsi); in nwl_dsi_bridge_atomic_pre_enable()
899 /* Step 3 from DSI reset-out instructions */ in nwl_dsi_bridge_atomic_pre_enable()
900 ret = reset_control_deassert(dsi->rst_esc); in nwl_dsi_bridge_atomic_pre_enable()
902 DRM_DEV_ERROR(dsi->dev, "Failed to deassert ESC: %d\n", ret); in nwl_dsi_bridge_atomic_pre_enable()
905 ret = reset_control_deassert(dsi->rst_byte); in nwl_dsi_bridge_atomic_pre_enable()
907 DRM_DEV_ERROR(dsi->dev, "Failed to deassert BYTE: %d\n", ret); in nwl_dsi_bridge_atomic_pre_enable()
916 struct nwl_dsi *dsi = bridge_to_dsi(bridge); in nwl_dsi_bridge_atomic_enable() local
919 /* Step 5 from DSI reset-out instructions */ in nwl_dsi_bridge_atomic_enable()
920 ret = reset_control_deassert(dsi->rst_dpi); in nwl_dsi_bridge_atomic_enable()
922 DRM_DEV_ERROR(dsi->dev, "Failed to deassert DPI: %d\n", ret); in nwl_dsi_bridge_atomic_enable()
928 struct nwl_dsi *dsi = bridge_to_dsi(bridge); in nwl_dsi_bridge_attach() local
933 ret = drm_of_find_panel_or_bridge(dsi->dev->of_node, 1, 0, &panel, in nwl_dsi_bridge_attach()
943 dsi->panel_bridge = panel_bridge; in nwl_dsi_bridge_attach()
945 if (!dsi->panel_bridge) in nwl_dsi_bridge_attach()
948 return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge, in nwl_dsi_bridge_attach()
953 { struct nwl_dsi *dsi = bridge_to_dsi(bridge); in nwl_dsi_bridge_detach() local
955 drm_of_panel_bridge_remove(dsi->dev->of_node, 1, 0); in nwl_dsi_bridge_detach()
972 static int nwl_dsi_parse_dt(struct nwl_dsi *dsi) in nwl_dsi_parse_dt() argument
974 struct platform_device *pdev = to_platform_device(dsi->dev); in nwl_dsi_parse_dt()
979 dsi->phy = devm_phy_get(dsi->dev, "dphy"); in nwl_dsi_parse_dt()
980 if (IS_ERR(dsi->phy)) { in nwl_dsi_parse_dt()
981 ret = PTR_ERR(dsi->phy); in nwl_dsi_parse_dt()
983 DRM_DEV_ERROR(dsi->dev, "Could not get PHY: %d\n", ret); in nwl_dsi_parse_dt()
987 clk = devm_clk_get(dsi->dev, "lcdif"); in nwl_dsi_parse_dt()
990 DRM_DEV_ERROR(dsi->dev, "Failed to get lcdif clock: %d\n", in nwl_dsi_parse_dt()
994 dsi->lcdif_clk = clk; in nwl_dsi_parse_dt()
996 clk = devm_clk_get(dsi->dev, "core"); in nwl_dsi_parse_dt()
999 DRM_DEV_ERROR(dsi->dev, "Failed to get core clock: %d\n", in nwl_dsi_parse_dt()
1003 dsi->core_clk = clk; in nwl_dsi_parse_dt()
1005 clk = devm_clk_get(dsi->dev, "phy_ref"); in nwl_dsi_parse_dt()
1008 DRM_DEV_ERROR(dsi->dev, "Failed to get phy_ref clock: %d\n", in nwl_dsi_parse_dt()
1012 dsi->phy_ref_clk = clk; in nwl_dsi_parse_dt()
1014 clk = devm_clk_get(dsi->dev, "rx_esc"); in nwl_dsi_parse_dt()
1017 DRM_DEV_ERROR(dsi->dev, "Failed to get rx_esc clock: %d\n", in nwl_dsi_parse_dt()
1021 dsi->rx_esc_clk = clk; in nwl_dsi_parse_dt()
1023 clk = devm_clk_get(dsi->dev, "tx_esc"); in nwl_dsi_parse_dt()
1026 DRM_DEV_ERROR(dsi->dev, "Failed to get tx_esc clock: %d\n", in nwl_dsi_parse_dt()
1030 dsi->tx_esc_clk = clk; in nwl_dsi_parse_dt()
1032 dsi->mux = devm_mux_control_get(dsi->dev, NULL); in nwl_dsi_parse_dt()
1033 if (IS_ERR(dsi->mux)) { in nwl_dsi_parse_dt()
1034 ret = PTR_ERR(dsi->mux); in nwl_dsi_parse_dt()
1036 DRM_DEV_ERROR(dsi->dev, "Failed to get mux: %d\n", ret); in nwl_dsi_parse_dt()
1044 dsi->regmap = in nwl_dsi_parse_dt()
1045 devm_regmap_init_mmio(dsi->dev, base, &nwl_dsi_regmap_config); in nwl_dsi_parse_dt()
1046 if (IS_ERR(dsi->regmap)) { in nwl_dsi_parse_dt()
1047 ret = PTR_ERR(dsi->regmap); in nwl_dsi_parse_dt()
1048 DRM_DEV_ERROR(dsi->dev, "Failed to create NWL DSI regmap: %d\n", in nwl_dsi_parse_dt()
1053 dsi->irq = platform_get_irq(pdev, 0); in nwl_dsi_parse_dt()
1054 if (dsi->irq < 0) { in nwl_dsi_parse_dt()
1055 DRM_DEV_ERROR(dsi->dev, "Failed to get device IRQ: %d\n", in nwl_dsi_parse_dt()
1056 dsi->irq); in nwl_dsi_parse_dt()
1057 return dsi->irq; in nwl_dsi_parse_dt()
1060 dsi->rst_pclk = devm_reset_control_get_exclusive(dsi->dev, "pclk"); in nwl_dsi_parse_dt()
1061 if (IS_ERR(dsi->rst_pclk)) { in nwl_dsi_parse_dt()
1062 DRM_DEV_ERROR(dsi->dev, "Failed to get pclk reset: %ld\n", in nwl_dsi_parse_dt()
1063 PTR_ERR(dsi->rst_pclk)); in nwl_dsi_parse_dt()
1064 return PTR_ERR(dsi->rst_pclk); in nwl_dsi_parse_dt()
1066 dsi->rst_byte = devm_reset_control_get_exclusive(dsi->dev, "byte"); in nwl_dsi_parse_dt()
1067 if (IS_ERR(dsi->rst_byte)) { in nwl_dsi_parse_dt()
1068 DRM_DEV_ERROR(dsi->dev, "Failed to get byte reset: %ld\n", in nwl_dsi_parse_dt()
1069 PTR_ERR(dsi->rst_byte)); in nwl_dsi_parse_dt()
1070 return PTR_ERR(dsi->rst_byte); in nwl_dsi_parse_dt()
1072 dsi->rst_esc = devm_reset_control_get_exclusive(dsi->dev, "esc"); in nwl_dsi_parse_dt()
1073 if (IS_ERR(dsi->rst_esc)) { in nwl_dsi_parse_dt()
1074 DRM_DEV_ERROR(dsi->dev, "Failed to get esc reset: %ld\n", in nwl_dsi_parse_dt()
1075 PTR_ERR(dsi->rst_esc)); in nwl_dsi_parse_dt()
1076 return PTR_ERR(dsi->rst_esc); in nwl_dsi_parse_dt()
1078 dsi->rst_dpi = devm_reset_control_get_exclusive(dsi->dev, "dpi"); in nwl_dsi_parse_dt()
1079 if (IS_ERR(dsi->rst_dpi)) { in nwl_dsi_parse_dt()
1080 DRM_DEV_ERROR(dsi->dev, "Failed to get dpi reset: %ld\n", in nwl_dsi_parse_dt()
1081 PTR_ERR(dsi->rst_dpi)); in nwl_dsi_parse_dt()
1082 return PTR_ERR(dsi->rst_dpi); in nwl_dsi_parse_dt()
1087 static int nwl_dsi_select_input(struct nwl_dsi *dsi) in nwl_dsi_select_input() argument
1093 remote = of_graph_get_remote_node(dsi->dev->of_node, 0, in nwl_dsi_select_input()
1098 remote = of_graph_get_remote_node(dsi->dev->of_node, 0, in nwl_dsi_select_input()
1101 DRM_DEV_ERROR(dsi->dev, in nwl_dsi_select_input()
1107 DRM_DEV_INFO(dsi->dev, "Using %s as input source\n", in nwl_dsi_select_input()
1109 ret = mux_control_try_select(dsi->mux, use_dcss); in nwl_dsi_select_input()
1111 DRM_DEV_ERROR(dsi->dev, "Failed to select input: %d\n", ret); in nwl_dsi_select_input()
1117 static int nwl_dsi_deselect_input(struct nwl_dsi *dsi) in nwl_dsi_deselect_input() argument
1121 ret = mux_control_deselect(dsi->mux); in nwl_dsi_deselect_input()
1123 DRM_DEV_ERROR(dsi->dev, "Failed to deselect input: %d\n", ret); in nwl_dsi_deselect_input()
1133 { .compatible = "fsl,imx8mq-nwl-dsi", },
1148 struct nwl_dsi *dsi; in nwl_dsi_probe() local
1151 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); in nwl_dsi_probe()
1152 if (!dsi) in nwl_dsi_probe()
1155 dsi->dev = dev; in nwl_dsi_probe()
1157 ret = nwl_dsi_parse_dt(dsi); in nwl_dsi_probe()
1161 ret = devm_request_irq(dev, dsi->irq, nwl_dsi_irq_handler, 0, in nwl_dsi_probe()
1162 dev_name(dev), dsi); in nwl_dsi_probe()
1164 DRM_DEV_ERROR(dev, "Failed to request IRQ %d: %d\n", dsi->irq, in nwl_dsi_probe()
1169 dsi->dsi_host.ops = &nwl_dsi_host_ops; in nwl_dsi_probe()
1170 dsi->dsi_host.dev = dev; in nwl_dsi_probe()
1171 ret = mipi_dsi_host_register(&dsi->dsi_host); in nwl_dsi_probe()
1179 dsi->quirks = (uintptr_t)attr->data; in nwl_dsi_probe()
1181 dsi->bridge.driver_private = dsi; in nwl_dsi_probe()
1182 dsi->bridge.funcs = &nwl_dsi_bridge_funcs; in nwl_dsi_probe()
1183 dsi->bridge.of_node = dev->of_node; in nwl_dsi_probe()
1184 dsi->bridge.timings = &nwl_dsi_timings; in nwl_dsi_probe()
1186 dev_set_drvdata(dev, dsi); in nwl_dsi_probe()
1189 ret = nwl_dsi_select_input(dsi); in nwl_dsi_probe()
1192 mipi_dsi_host_unregister(&dsi->dsi_host); in nwl_dsi_probe()
1196 drm_bridge_add(&dsi->bridge); in nwl_dsi_probe()
1202 struct nwl_dsi *dsi = platform_get_drvdata(pdev); in nwl_dsi_remove() local
1204 nwl_dsi_deselect_input(dsi); in nwl_dsi_remove()
1205 mipi_dsi_host_unregister(&dsi->dsi_host); in nwl_dsi_remove()
1206 drm_bridge_remove(&dsi->bridge); in nwl_dsi_remove()
1224 MODULE_DESCRIPTION("Northwest Logic MIPI-DSI driver");