Lines Matching +full:tx +full:- +full:clk +full:- +full:1000 +full:- +full:inverted
1 // SPDX-License-Identifier: GPL-2.0-only
15 #include <linux/clk.h>
18 #include <linux/media-bus-format.h>
25 #include <drm/bridge/samsung-dsim.h>
112 #define DSIM_MAIN_VRESOL(x, num_bits) (((x) & ((1 << (num_bits)) - 1)) << 16)
113 #define DSIM_MAIN_HRESOL(x, num_bits) (((x) & ((1 << (num_bits)) - 1)) << 0)
409 .max_freq = 1000,
428 .max_freq = 1000,
445 .max_freq = 1000,
501 * downstream driver - drivers/gpu/drm/bridge/sec-dsim.c
536 writel(val, dsi->reg_base + dsi->driver_data->reg_ofs[idx]); in samsung_dsim_write()
541 return readl(dsi->reg_base + dsi->driver_data->reg_ofs[idx]); in samsung_dsim_read()
546 if (wait_for_completion_timeout(&dsi->completed, msecs_to_jiffies(300))) in samsung_dsim_wait_for_reset()
549 dev_err(dsi->dev, "timeout waiting for reset\n"); in samsung_dsim_wait_for_reset()
554 u32 reset_val = dsi->driver_data->reg_values[RESET_TYPE]; in samsung_dsim_reset()
556 reinit_completion(&dsi->completed); in samsung_dsim_reset()
561 #define MHZ (1000 * 1000)
569 const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; in samsung_dsim_pll_find_pms()
577 p_min = DIV_ROUND_UP(fin, (driver_data->pll_fin_max * MHZ)); in samsung_dsim_pll_find_pms()
578 p_max = fin / (driver_data->pll_fin_min * MHZ); in samsung_dsim_pll_find_pms()
588 if (_m < driver_data->m_min || _m > driver_data->m_max) in samsung_dsim_pll_find_pms()
593 if (tmp < driver_data->min_freq * MHZ || in samsung_dsim_pll_find_pms()
594 tmp > driver_data->max_freq * MHZ) in samsung_dsim_pll_find_pms()
600 delta = abs(fout - tmp); in samsung_dsim_pll_find_pms()
623 const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; in samsung_dsim_set_pll()
630 if (dsi->pll_clk) { in samsung_dsim_set_pll()
636 fin = clk_get_rate(clk_get_parent(dsi->pll_clk)); in samsung_dsim_set_pll()
637 while (fin > driver_data->pll_fin_max * MHZ) in samsung_dsim_set_pll()
639 clk_set_rate(dsi->pll_clk, fin); in samsung_dsim_set_pll()
641 fin = clk_get_rate(dsi->pll_clk); in samsung_dsim_set_pll()
643 fin = dsi->pll_clk_rate; in samsung_dsim_set_pll()
645 dev_dbg(dsi->dev, "PLL ref clock freq %lu\n", fin); in samsung_dsim_set_pll()
649 dev_err(dsi->dev, in samsung_dsim_set_pll()
653 dev_dbg(dsi->dev, "PLL freq %lu, (p %d, m %d, s %d)\n", fout, p, m, s); in samsung_dsim_set_pll()
655 writel(driver_data->reg_values[PLL_TIMER], in samsung_dsim_set_pll()
656 dsi->reg_base + driver_data->plltmr_reg); in samsung_dsim_set_pll()
658 reg = DSIM_PLL_EN | DSIM_PLL_P(p, driver_data->pll_p_offset) | in samsung_dsim_set_pll()
661 if (driver_data->has_freqband) { in samsung_dsim_set_pll()
674 dev_dbg(dsi->dev, "band %d\n", band); in samsung_dsim_set_pll()
679 if (dsi->swap_dn_dp_clk) in samsung_dsim_set_pll()
681 if (dsi->swap_dn_dp_data) in samsung_dsim_set_pll()
686 timeout = 1000; in samsung_dsim_set_pll()
688 if (timeout-- == 0) { in samsung_dsim_set_pll()
689 dev_err(dsi->dev, "PLL failed to stabilize\n"); in samsung_dsim_set_pll()
695 dsi->hs_clock = fout; in samsung_dsim_set_pll()
705 struct drm_display_mode *m = &dsi->mode; in samsung_dsim_enable_clock()
706 int bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); in samsung_dsim_enable_clock()
708 /* m->clock is in KHz */ in samsung_dsim_enable_clock()
709 pix_clk = m->clock * 1000; in samsung_dsim_enable_clock()
712 if (dsi->burst_clk_rate) in samsung_dsim_enable_clock()
713 hs_clk = samsung_dsim_set_pll(dsi, dsi->burst_clk_rate); in samsung_dsim_enable_clock()
715 hs_clk = samsung_dsim_set_pll(dsi, DIV_ROUND_UP(pix_clk * bpp, dsi->lanes)); in samsung_dsim_enable_clock()
718 dev_err(dsi->dev, "failed to configure DSI PLL\n"); in samsung_dsim_enable_clock()
719 return -EFAULT; in samsung_dsim_enable_clock()
723 esc_div = DIV_ROUND_UP(byte_clk, dsi->esc_clk_rate); in samsung_dsim_enable_clock()
731 dev_dbg(dsi->dev, "hs_clk = %lu, byte_clk = %lu, esc_clk = %lu\n", in samsung_dsim_enable_clock()
741 | DSIM_LANE_ESC_CLK_EN_DATA(BIT(dsi->lanes) - 1) in samsung_dsim_enable_clock()
751 const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; in samsung_dsim_set_phy_ctrl()
752 const unsigned int *reg_values = driver_data->reg_values; in samsung_dsim_set_phy_ctrl()
757 unsigned long long byte_clock = dsi->hs_clock / 8; in samsung_dsim_set_phy_ctrl()
759 if (driver_data->has_freqband) in samsung_dsim_set_phy_ctrl()
762 phy_mipi_dphy_get_default_config_for_hsclk(dsi->hs_clock, in samsung_dsim_set_phy_ctrl()
763 dsi->lanes, &cfg); in samsung_dsim_set_phy_ctrl()
791 /* B D-PHY: D-PHY Master & Slave Analog Block control */ in samsung_dsim_set_phy_ctrl()
798 * T LPX: Transmitted length of any Low-Power state period in samsung_dsim_set_phy_ctrl()
799 * T HS-EXIT: Time that the transmitter drives LP-11 following a HS in samsung_dsim_set_phy_ctrl()
808 * T CLK-PREPARE: Time that the transmitter drives the Clock Lane LP-00 in samsung_dsim_set_phy_ctrl()
809 * Line state immediately before the HS-0 Line state starting the in samsung_dsim_set_phy_ctrl()
811 * T CLK-ZERO: Time that the transmitter drives the HS-0 state prior to in samsung_dsim_set_phy_ctrl()
815 * Interval is defined as the period from the end of T HS-TRAIL to in samsung_dsim_set_phy_ctrl()
816 * the beginning of T CLK-TRAIL in samsung_dsim_set_phy_ctrl()
817 * T CLK-TRAIL: Time that the transmitter drives the HS-0 state after in samsung_dsim_set_phy_ctrl()
829 * T HS-PREPARE: Time that the transmitter drives the Data Lane LP-00 in samsung_dsim_set_phy_ctrl()
830 * Line state immediately before the HS-0 Line state starting the in samsung_dsim_set_phy_ctrl()
832 * T HS-ZERO: Time that the transmitter drives the HS-0 state prior to in samsung_dsim_set_phy_ctrl()
834 * T HS-TRAIL: Time that the transmitter drives the flipped differential in samsung_dsim_set_phy_ctrl()
863 reg |= (DSIM_NUM_OF_DATA_LANE(dsi->lanes - 1) | DSIM_LANE_EN_CLK | in samsung_dsim_enable_lane()
870 const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; in samsung_dsim_init_link()
894 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) { in samsung_dsim_init_link()
901 if (!(dsi->mode_flags & MIPI_DSI_MODE_VSYNC_FLUSH)) in samsung_dsim_init_link()
903 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) in samsung_dsim_init_link()
905 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) in samsung_dsim_init_link()
907 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_AUTO_VERT) in samsung_dsim_init_link()
909 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE) in samsung_dsim_init_link()
911 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_NO_HFP) in samsung_dsim_init_link()
913 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_NO_HBP) in samsung_dsim_init_link()
915 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_NO_HSA) in samsung_dsim_init_link()
919 if (dsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET) in samsung_dsim_init_link()
922 switch (dsi->format) { in samsung_dsim_init_link()
936 dev_err(dsi->dev, "invalid pixel format\n"); in samsung_dsim_init_link()
937 return -EINVAL; in samsung_dsim_init_link()
941 * Use non-continuous clock mode if the periparal wants and in samsung_dsim_init_link()
944 * In non-continous clock mode, host controller will turn off in samsung_dsim_init_link()
945 * the HS clock between high-speed transmissions to reduce in samsung_dsim_init_link()
948 if (driver_data->has_clklane_stop && in samsung_dsim_init_link()
949 dsi->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) { in samsung_dsim_init_link()
950 if (!samsung_dsim_hw_is_exynos(dsi->plat_data->hw_type)) in samsung_dsim_init_link()
957 lanes_mask = BIT(dsi->lanes) - 1; in samsung_dsim_init_link()
963 if (timeout-- == 0) { in samsung_dsim_init_link()
964 dev_err(dsi->dev, "waiting for bus lanes timed out\n"); in samsung_dsim_init_link()
965 return -EFAULT; in samsung_dsim_init_link()
976 reg |= DSIM_STOP_STATE_CNT(driver_data->reg_values[STOP_STATE_CNT]); in samsung_dsim_init_link()
987 struct drm_display_mode *m = &dsi->mode; in samsung_dsim_set_display_mode()
988 unsigned int num_bits_resol = dsi->driver_data->num_bits_resol; in samsung_dsim_set_display_mode()
991 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) { in samsung_dsim_set_display_mode()
992 u64 byte_clk = dsi->hs_clock / 8; in samsung_dsim_set_display_mode()
993 u64 pix_clk = m->clock * 1000; in samsung_dsim_set_display_mode()
995 int hfp = DIV64_U64_ROUND_UP((m->hsync_start - m->hdisplay) * byte_clk, pix_clk); in samsung_dsim_set_display_mode()
996 int hbp = DIV64_U64_ROUND_UP((m->htotal - m->hsync_end) * byte_clk, pix_clk); in samsung_dsim_set_display_mode()
997 int hsa = DIV64_U64_ROUND_UP((m->hsync_end - m->hsync_start) * byte_clk, pix_clk); in samsung_dsim_set_display_mode()
1000 hfp = max(hfp - 6, 0); in samsung_dsim_set_display_mode()
1001 hbp = max(hbp - 6, 0); in samsung_dsim_set_display_mode()
1002 hsa = max(hsa - 6, 0); in samsung_dsim_set_display_mode()
1004 dev_dbg(dsi->dev, "calculated hfp: %u, hbp: %u, hsa: %u", in samsung_dsim_set_display_mode()
1008 | DSIM_STABLE_VFP(m->vsync_start - m->vdisplay) in samsung_dsim_set_display_mode()
1009 | DSIM_MAIN_VBP(m->vtotal - m->vsync_end); in samsung_dsim_set_display_mode()
1015 reg = DSIM_MAIN_VSA(m->vsync_end - m->vsync_start) in samsung_dsim_set_display_mode()
1019 reg = DSIM_MAIN_HRESOL(m->hdisplay, num_bits_resol) | in samsung_dsim_set_display_mode()
1020 DSIM_MAIN_VRESOL(m->vdisplay, num_bits_resol); in samsung_dsim_set_display_mode()
1024 dev_dbg(dsi->dev, "LCD size = %dx%d\n", m->hdisplay, m->vdisplay); in samsung_dsim_set_display_mode()
1046 if (!dsi->driver_data->has_broken_fifoctrl_emptyhdr) { in samsung_dsim_wait_for_hdr_fifo()
1063 } while (--timeout); in samsung_dsim_wait_for_hdr_fifo()
1065 return -ETIMEDOUT; in samsung_dsim_wait_for_hdr_fifo()
1091 struct device *dev = dsi->dev; in samsung_dsim_send_to_fifo()
1092 struct mipi_dsi_packet *pkt = &xfer->packet; in samsung_dsim_send_to_fifo()
1093 const u8 *payload = pkt->payload + xfer->tx_done; in samsung_dsim_send_to_fifo()
1094 u16 length = pkt->payload_length - xfer->tx_done; in samsung_dsim_send_to_fifo()
1095 bool first = !xfer->tx_done; in samsung_dsim_send_to_fifo()
1098 dev_dbg(dev, "< xfer %pK: tx len %u, done %u, rx len %u, done %u\n", in samsung_dsim_send_to_fifo()
1099 xfer, length, xfer->tx_done, xfer->rx_len, xfer->rx_done); in samsung_dsim_send_to_fifo()
1104 xfer->tx_done += length; in samsung_dsim_send_to_fifo()
1111 length -= 4; in samsung_dsim_send_to_fifo()
1132 reg = get_unaligned_le32(pkt->header); in samsung_dsim_send_to_fifo()
1138 if (NEQV(xfer->flags & MIPI_DSI_MSG_USE_LPM, in samsung_dsim_send_to_fifo()
1139 dsi->state & DSIM_STATE_CMD_LPM)) { in samsung_dsim_send_to_fifo()
1140 samsung_dsim_set_cmd_lpm(dsi, xfer->flags & MIPI_DSI_MSG_USE_LPM); in samsung_dsim_send_to_fifo()
1141 dsi->state ^= DSIM_STATE_CMD_LPM; in samsung_dsim_send_to_fifo()
1146 if (xfer->flags & MIPI_DSI_MSG_REQ_ACK) in samsung_dsim_send_to_fifo()
1153 u8 *payload = xfer->rx_payload + xfer->rx_done; in samsung_dsim_read_from_fifo()
1154 bool first = !xfer->rx_done; in samsung_dsim_read_from_fifo()
1155 struct device *dev = dsi->dev; in samsung_dsim_read_from_fifo()
1165 if (xfer->rx_len >= 2) { in samsung_dsim_read_from_fifo()
1167 ++xfer->rx_done; in samsung_dsim_read_from_fifo()
1173 ++xfer->rx_done; in samsung_dsim_read_from_fifo()
1174 xfer->rx_len = xfer->rx_done; in samsung_dsim_read_from_fifo()
1175 xfer->result = 0; in samsung_dsim_read_from_fifo()
1179 xfer->result = 0; in samsung_dsim_read_from_fifo()
1184 if (length > xfer->rx_len) { in samsung_dsim_read_from_fifo()
1187 xfer->rx_len, length); in samsung_dsim_read_from_fifo()
1188 length = xfer->rx_len; in samsung_dsim_read_from_fifo()
1189 } else if (length < xfer->rx_len) { in samsung_dsim_read_from_fifo()
1190 xfer->rx_len = length; in samsung_dsim_read_from_fifo()
1194 length = xfer->rx_len - xfer->rx_done; in samsung_dsim_read_from_fifo()
1195 xfer->rx_done += length; in samsung_dsim_read_from_fifo()
1205 length -= 4; in samsung_dsim_read_from_fifo()
1222 if (xfer->rx_done == xfer->rx_len) in samsung_dsim_read_from_fifo()
1223 xfer->result = 0; in samsung_dsim_read_from_fifo()
1231 } while (--length); in samsung_dsim_read_from_fifo()
1241 spin_lock_irqsave(&dsi->transfer_lock, flags); in samsung_dsim_transfer_start()
1243 if (list_empty(&dsi->transfer_list)) { in samsung_dsim_transfer_start()
1244 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_transfer_start()
1248 xfer = list_first_entry(&dsi->transfer_list, in samsung_dsim_transfer_start()
1251 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_transfer_start()
1253 if (xfer->packet.payload_length && in samsung_dsim_transfer_start()
1254 xfer->tx_done == xfer->packet.payload_length) in samsung_dsim_transfer_start()
1260 if (xfer->packet.payload_length || xfer->rx_len) in samsung_dsim_transfer_start()
1263 xfer->result = 0; in samsung_dsim_transfer_start()
1264 complete(&xfer->completed); in samsung_dsim_transfer_start()
1266 spin_lock_irqsave(&dsi->transfer_lock, flags); in samsung_dsim_transfer_start()
1268 list_del_init(&xfer->list); in samsung_dsim_transfer_start()
1269 start = !list_empty(&dsi->transfer_list); in samsung_dsim_transfer_start()
1271 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_transfer_start()
1283 spin_lock_irqsave(&dsi->transfer_lock, flags); in samsung_dsim_transfer_finish()
1285 if (list_empty(&dsi->transfer_list)) { in samsung_dsim_transfer_finish()
1286 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_transfer_finish()
1290 xfer = list_first_entry(&dsi->transfer_list, in samsung_dsim_transfer_finish()
1293 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_transfer_finish()
1295 dev_dbg(dsi->dev, in samsung_dsim_transfer_finish()
1297 xfer, xfer->packet.payload_length, xfer->tx_done, xfer->rx_len, in samsung_dsim_transfer_finish()
1298 xfer->rx_done); in samsung_dsim_transfer_finish()
1300 if (xfer->tx_done != xfer->packet.payload_length) in samsung_dsim_transfer_finish()
1303 if (xfer->rx_done != xfer->rx_len) in samsung_dsim_transfer_finish()
1306 if (xfer->rx_done != xfer->rx_len) in samsung_dsim_transfer_finish()
1309 spin_lock_irqsave(&dsi->transfer_lock, flags); in samsung_dsim_transfer_finish()
1311 list_del_init(&xfer->list); in samsung_dsim_transfer_finish()
1312 start = !list_empty(&dsi->transfer_list); in samsung_dsim_transfer_finish()
1314 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_transfer_finish()
1316 if (!xfer->rx_len) in samsung_dsim_transfer_finish()
1317 xfer->result = 0; in samsung_dsim_transfer_finish()
1318 complete(&xfer->completed); in samsung_dsim_transfer_finish()
1329 spin_lock_irqsave(&dsi->transfer_lock, flags); in samsung_dsim_remove_transfer()
1331 if (!list_empty(&dsi->transfer_list) && in samsung_dsim_remove_transfer()
1332 xfer == list_first_entry(&dsi->transfer_list, in samsung_dsim_remove_transfer()
1334 list_del_init(&xfer->list); in samsung_dsim_remove_transfer()
1335 start = !list_empty(&dsi->transfer_list); in samsung_dsim_remove_transfer()
1336 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_remove_transfer()
1342 list_del_init(&xfer->list); in samsung_dsim_remove_transfer()
1344 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_remove_transfer()
1353 xfer->tx_done = 0; in samsung_dsim_transfer()
1354 xfer->rx_done = 0; in samsung_dsim_transfer()
1355 xfer->result = -ETIMEDOUT; in samsung_dsim_transfer()
1356 init_completion(&xfer->completed); in samsung_dsim_transfer()
1358 spin_lock_irqsave(&dsi->transfer_lock, flags); in samsung_dsim_transfer()
1360 stopped = list_empty(&dsi->transfer_list); in samsung_dsim_transfer()
1361 list_add_tail(&xfer->list, &dsi->transfer_list); in samsung_dsim_transfer()
1363 spin_unlock_irqrestore(&dsi->transfer_lock, flags); in samsung_dsim_transfer()
1368 wait_for_completion_timeout(&xfer->completed, in samsung_dsim_transfer()
1370 if (xfer->result == -ETIMEDOUT) { in samsung_dsim_transfer()
1371 struct mipi_dsi_packet *pkt = &xfer->packet; in samsung_dsim_transfer()
1374 dev_err(dsi->dev, "xfer timed out: %*ph %*ph\n", 4, pkt->header, in samsung_dsim_transfer()
1375 (int)pkt->payload_length, pkt->payload); in samsung_dsim_transfer()
1376 return -ETIMEDOUT; in samsung_dsim_transfer()
1380 return xfer->result; in samsung_dsim_transfer()
1393 dev_warn(dsi->dev, "spurious interrupt\n"); in samsung_dsim_irq()
1405 complete(&dsi->completed); in samsung_dsim_irq()
1421 enable_irq(dsi->irq); in samsung_dsim_enable_irq()
1423 if (dsi->te_gpio) in samsung_dsim_enable_irq()
1424 enable_irq(gpiod_to_irq(dsi->te_gpio)); in samsung_dsim_enable_irq()
1429 if (dsi->te_gpio) in samsung_dsim_disable_irq()
1430 disable_irq(gpiod_to_irq(dsi->te_gpio)); in samsung_dsim_disable_irq()
1432 disable_irq(dsi->irq); in samsung_dsim_disable_irq()
1437 const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; in samsung_dsim_init()
1439 if (dsi->state & DSIM_STATE_INITIALIZED) in samsung_dsim_init()
1445 if (driver_data->reg_values[RESET_TYPE] == DSIM_FUNCRST) in samsung_dsim_init()
1446 samsung_dsim_enable_lane(dsi, BIT(dsi->lanes) - 1); in samsung_dsim_init()
1449 if (driver_data->wait_for_reset) in samsung_dsim_init()
1454 dsi->state |= DSIM_STATE_INITIALIZED; in samsung_dsim_init()
1465 if (dsi->state & DSIM_STATE_ENABLED) in samsung_dsim_atomic_pre_enable()
1468 ret = pm_runtime_resume_and_get(dsi->dev); in samsung_dsim_atomic_pre_enable()
1470 dev_err(dsi->dev, "failed to enable DSI device.\n"); in samsung_dsim_atomic_pre_enable()
1474 dsi->state |= DSIM_STATE_ENABLED; in samsung_dsim_atomic_pre_enable()
1477 * For Exynos-DSIM the downstream bridge, or panel are expecting in samsung_dsim_atomic_pre_enable()
1480 if (!samsung_dsim_hw_is_exynos(dsi->plat_data->hw_type)) { in samsung_dsim_atomic_pre_enable()
1495 dsi->state |= DSIM_STATE_VIDOUT_AVAILABLE; in samsung_dsim_atomic_enable()
1503 if (!(dsi->state & DSIM_STATE_ENABLED)) in samsung_dsim_atomic_disable()
1507 dsi->state &= ~DSIM_STATE_VIDOUT_AVAILABLE; in samsung_dsim_atomic_disable()
1515 dsi->state &= ~DSIM_STATE_ENABLED; in samsung_dsim_atomic_post_disable()
1516 pm_runtime_put_sync(dsi->dev); in samsung_dsim_atomic_post_disable()
1521 * AN13573 i.MX 8/RT MIPI DSI/CSI-2, Rev. 0, 21 March 2022
1585 struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; in samsung_dsim_atomic_check()
1595 * LCDIF must generate inverted HS/VS/DE signals, i.e. active LOW. in samsung_dsim_atomic_check()
1601 if (dsi->plat_data->hw_type == DSIM_TYPE_IMX8MM) { in samsung_dsim_atomic_check()
1602 adjusted_mode->flags |= (DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC); in samsung_dsim_atomic_check()
1603 adjusted_mode->flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC); in samsung_dsim_atomic_check()
1604 } else if (dsi->plat_data->hw_type == DSIM_TYPE_IMX8MP) { in samsung_dsim_atomic_check()
1605 adjusted_mode->flags &= ~(DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC); in samsung_dsim_atomic_check()
1606 adjusted_mode->flags |= (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC); in samsung_dsim_atomic_check()
1619 if (dsi->lanes > 1) { in samsung_dsim_atomic_check()
1620 int hfp = adjusted_mode->hsync_start - adjusted_mode->hdisplay; in samsung_dsim_atomic_check()
1621 int remainder = hfp % dsi->lanes; in samsung_dsim_atomic_check()
1624 adjusted_mode->hsync_start += remainder; in samsung_dsim_atomic_check()
1625 adjusted_mode->hsync_end += remainder; in samsung_dsim_atomic_check()
1626 adjusted_mode->htotal += remainder; in samsung_dsim_atomic_check()
1639 drm_mode_copy(&dsi->mode, adjusted_mode); in samsung_dsim_mode_set()
1647 return drm_bridge_attach(bridge->encoder, dsi->out_bridge, bridge, in samsung_dsim_attach()
1668 const struct samsung_dsim_plat_data *pdata = dsi->plat_data; in samsung_dsim_te_irq_handler()
1670 if (pdata->host_ops && pdata->host_ops->te_irq_handler) in samsung_dsim_te_irq_handler()
1671 return pdata->host_ops->te_irq_handler(dsi); in samsung_dsim_te_irq_handler()
1681 dsi->te_gpio = devm_gpiod_get_optional(dev, "te", GPIOD_IN); in samsung_dsim_register_te_irq()
1682 if (!dsi->te_gpio) in samsung_dsim_register_te_irq()
1684 else if (IS_ERR(dsi->te_gpio)) in samsung_dsim_register_te_irq()
1685 return dev_err_probe(dev, PTR_ERR(dsi->te_gpio), "failed to get te GPIO\n"); in samsung_dsim_register_te_irq()
1687 te_gpio_irq = gpiod_to_irq(dsi->te_gpio); in samsung_dsim_register_te_irq()
1692 dev_err(dsi->dev, "request interrupt failed with %d\n", ret); in samsung_dsim_register_te_irq()
1693 gpiod_put(dsi->te_gpio); in samsung_dsim_register_te_irq()
1704 const struct samsung_dsim_plat_data *pdata = dsi->plat_data; in samsung_dsim_host_attach()
1705 struct device *dev = dsi->dev; in samsung_dsim_host_attach()
1706 struct device_node *np = dev->of_node; in samsung_dsim_host_attach()
1713 * through the upstream device (ie, MIPI-DCS for a MIPI-DSI device). in samsung_dsim_host_attach()
1730 * device-tree node. in samsung_dsim_host_attach()
1733 return -ENODEV; in samsung_dsim_host_attach()
1739 return -ENODEV; in samsung_dsim_host_attach()
1743 dsi->out_bridge = devm_drm_panel_bridge_add(dev, panel); in samsung_dsim_host_attach()
1745 dsi->out_bridge = of_drm_find_bridge(remote); in samsung_dsim_host_attach()
1746 if (!dsi->out_bridge) in samsung_dsim_host_attach()
1747 dsi->out_bridge = ERR_PTR(-EINVAL); in samsung_dsim_host_attach()
1752 if (IS_ERR(dsi->out_bridge)) { in samsung_dsim_host_attach()
1753 ret = PTR_ERR(dsi->out_bridge); in samsung_dsim_host_attach()
1758 DRM_DEV_INFO(dev, "Attached %s device (lanes:%d bpp:%d mode-flags:0x%lx)\n", in samsung_dsim_host_attach()
1759 device->name, device->lanes, in samsung_dsim_host_attach()
1760 mipi_dsi_pixel_format_to_bpp(device->format), in samsung_dsim_host_attach()
1761 device->mode_flags); in samsung_dsim_host_attach()
1763 drm_bridge_add(&dsi->bridge); in samsung_dsim_host_attach()
1771 if (!(device->mode_flags & MIPI_DSI_MODE_VIDEO)) { in samsung_dsim_host_attach()
1772 ret = samsung_dsim_register_te_irq(dsi, &device->dev); in samsung_dsim_host_attach()
1777 if (pdata->host_ops && pdata->host_ops->attach) { in samsung_dsim_host_attach()
1778 ret = pdata->host_ops->attach(dsi, device); in samsung_dsim_host_attach()
1783 dsi->lanes = device->lanes; in samsung_dsim_host_attach()
1784 dsi->format = device->format; in samsung_dsim_host_attach()
1785 dsi->mode_flags = device->mode_flags; in samsung_dsim_host_attach()
1792 if (dsi->te_gpio) { in samsung_dsim_unregister_te_irq()
1793 free_irq(gpiod_to_irq(dsi->te_gpio), dsi); in samsung_dsim_unregister_te_irq()
1794 gpiod_put(dsi->te_gpio); in samsung_dsim_unregister_te_irq()
1802 const struct samsung_dsim_plat_data *pdata = dsi->plat_data; in samsung_dsim_host_detach()
1804 dsi->out_bridge = NULL; in samsung_dsim_host_detach()
1806 if (pdata->host_ops && pdata->host_ops->detach) in samsung_dsim_host_detach()
1807 pdata->host_ops->detach(dsi, device); in samsung_dsim_host_detach()
1811 drm_bridge_remove(&dsi->bridge); in samsung_dsim_host_detach()
1823 if (!(dsi->state & DSIM_STATE_ENABLED)) in samsung_dsim_host_transfer()
1824 return -EINVAL; in samsung_dsim_host_transfer()
1834 xfer.rx_len = msg->rx_len; in samsung_dsim_host_transfer()
1835 xfer.rx_payload = msg->rx_buf; in samsung_dsim_host_transfer()
1836 xfer.flags = msg->flags; in samsung_dsim_host_transfer()
1861 struct device *dev = dsi->dev; in samsung_dsim_parse_dt()
1862 struct device_node *node = dev->of_node; in samsung_dsim_parse_dt()
1867 ret = samsung_dsim_of_read_u32(node, "samsung,pll-clock-frequency", in samsung_dsim_parse_dt()
1868 &dsi->pll_clk_rate, 1); in samsung_dsim_parse_dt()
1872 dsi->pll_clk = devm_clk_get(dev, "sclk_mipi"); in samsung_dsim_parse_dt()
1873 if (IS_ERR(dsi->pll_clk)) in samsung_dsim_parse_dt()
1874 return PTR_ERR(dsi->pll_clk); in samsung_dsim_parse_dt()
1878 ret = samsung_dsim_of_read_u32(node, "samsung,burst-clock-frequency", in samsung_dsim_parse_dt()
1879 &dsi->burst_clk_rate, 1); in samsung_dsim_parse_dt()
1882 dsi->burst_clk_rate = 0; in samsung_dsim_parse_dt()
1885 ret = samsung_dsim_of_read_u32(node, "samsung,esc-clock-frequency", in samsung_dsim_parse_dt()
1886 &dsi->esc_clk_rate, 0); in samsung_dsim_parse_dt()
1890 endpoint = of_graph_get_endpoint_by_regs(node, 1, -1); in samsung_dsim_parse_dt()
1891 nr_lanes = of_property_count_u32_elems(endpoint, "data-lanes"); in samsung_dsim_parse_dt()
1894 of_property_read_u32_array(endpoint, "lane-polarities", in samsung_dsim_parse_dt()
1898 DRM_DEV_ERROR(dsi->dev, "Data lanes polarities do not match"); in samsung_dsim_parse_dt()
1901 dsi->swap_dn_dp_clk = true; in samsung_dsim_parse_dt()
1903 dsi->swap_dn_dp_data = true; in samsung_dsim_parse_dt()
1911 return mipi_dsi_host_register(&dsi->dsi_host); in generic_dsim_register_host()
1916 mipi_dsi_host_unregister(&dsi->dsi_host); in generic_dsim_unregister_host()
1934 struct device *dev = &pdev->dev; in samsung_dsim_probe()
1940 return -ENOMEM; in samsung_dsim_probe()
1942 init_completion(&dsi->completed); in samsung_dsim_probe()
1943 spin_lock_init(&dsi->transfer_lock); in samsung_dsim_probe()
1944 INIT_LIST_HEAD(&dsi->transfer_list); in samsung_dsim_probe()
1946 dsi->dsi_host.ops = &samsung_dsim_ops; in samsung_dsim_probe()
1947 dsi->dsi_host.dev = dev; in samsung_dsim_probe()
1949 dsi->dev = dev; in samsung_dsim_probe()
1950 dsi->plat_data = of_device_get_match_data(dev); in samsung_dsim_probe()
1951 dsi->driver_data = samsung_dsim_types[dsi->plat_data->hw_type]; in samsung_dsim_probe()
1953 dsi->supplies[0].supply = "vddcore"; in samsung_dsim_probe()
1954 dsi->supplies[1].supply = "vddio"; in samsung_dsim_probe()
1955 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(dsi->supplies), in samsung_dsim_probe()
1956 dsi->supplies); in samsung_dsim_probe()
1960 dsi->clks = devm_kcalloc(dev, dsi->driver_data->num_clks, in samsung_dsim_probe()
1961 sizeof(*dsi->clks), GFP_KERNEL); in samsung_dsim_probe()
1962 if (!dsi->clks) in samsung_dsim_probe()
1963 return -ENOMEM; in samsung_dsim_probe()
1965 for (i = 0; i < dsi->driver_data->num_clks; i++) { in samsung_dsim_probe()
1966 dsi->clks[i] = devm_clk_get(dev, clk_names[i]); in samsung_dsim_probe()
1967 if (IS_ERR(dsi->clks[i])) { in samsung_dsim_probe()
1969 dsi->clks[i] = devm_clk_get(dev, OLD_SCLK_MIPI_CLK_NAME); in samsung_dsim_probe()
1970 if (!IS_ERR(dsi->clks[i])) in samsung_dsim_probe()
1975 return PTR_ERR(dsi->clks[i]); in samsung_dsim_probe()
1979 dsi->reg_base = devm_platform_ioremap_resource(pdev, 0); in samsung_dsim_probe()
1980 if (IS_ERR(dsi->reg_base)) in samsung_dsim_probe()
1981 return PTR_ERR(dsi->reg_base); in samsung_dsim_probe()
1983 dsi->phy = devm_phy_optional_get(dev, "dsim"); in samsung_dsim_probe()
1984 if (IS_ERR(dsi->phy)) { in samsung_dsim_probe()
1986 return PTR_ERR(dsi->phy); in samsung_dsim_probe()
1989 dsi->irq = platform_get_irq(pdev, 0); in samsung_dsim_probe()
1990 if (dsi->irq < 0) in samsung_dsim_probe()
1991 return dsi->irq; in samsung_dsim_probe()
1993 ret = devm_request_threaded_irq(dev, dsi->irq, NULL, in samsung_dsim_probe()
2010 dsi->bridge.funcs = &samsung_dsim_bridge_funcs; in samsung_dsim_probe()
2011 dsi->bridge.of_node = dev->of_node; in samsung_dsim_probe()
2012 dsi->bridge.type = DRM_MODE_CONNECTOR_DSI; in samsung_dsim_probe()
2014 /* DE_LOW: i.MX8M Mini/Nano LCDIF-DSIM glue logic inverts HS/VS/DE */ in samsung_dsim_probe()
2015 if (dsi->plat_data->hw_type == DSIM_TYPE_IMX8MM) in samsung_dsim_probe()
2016 dsi->bridge.timings = &samsung_dsim_bridge_timings_de_low; in samsung_dsim_probe()
2018 dsi->bridge.timings = &samsung_dsim_bridge_timings_de_high; in samsung_dsim_probe()
2020 if (dsi->plat_data->host_ops && dsi->plat_data->host_ops->register_host) { in samsung_dsim_probe()
2021 ret = dsi->plat_data->host_ops->register_host(dsi); in samsung_dsim_probe()
2039 pm_runtime_disable(&pdev->dev); in samsung_dsim_remove()
2041 if (dsi->plat_data->host_ops && dsi->plat_data->host_ops->unregister_host) in samsung_dsim_remove()
2042 dsi->plat_data->host_ops->unregister_host(dsi); in samsung_dsim_remove()
2049 const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; in samsung_dsim_suspend()
2054 if (dsi->state & DSIM_STATE_INITIALIZED) { in samsung_dsim_suspend()
2055 dsi->state &= ~DSIM_STATE_INITIALIZED; in samsung_dsim_suspend()
2062 dsi->state &= ~DSIM_STATE_CMD_LPM; in samsung_dsim_suspend()
2064 phy_power_off(dsi->phy); in samsung_dsim_suspend()
2066 for (i = driver_data->num_clks - 1; i > -1; i--) in samsung_dsim_suspend()
2067 clk_disable_unprepare(dsi->clks[i]); in samsung_dsim_suspend()
2069 ret = regulator_bulk_disable(ARRAY_SIZE(dsi->supplies), dsi->supplies); in samsung_dsim_suspend()
2071 dev_err(dsi->dev, "cannot disable regulators %d\n", ret); in samsung_dsim_suspend()
2079 const struct samsung_dsim_driver_data *driver_data = dsi->driver_data; in samsung_dsim_resume()
2082 ret = regulator_bulk_enable(ARRAY_SIZE(dsi->supplies), dsi->supplies); in samsung_dsim_resume()
2084 dev_err(dsi->dev, "cannot enable regulators %d\n", ret); in samsung_dsim_resume()
2088 for (i = 0; i < driver_data->num_clks; i++) { in samsung_dsim_resume()
2089 ret = clk_prepare_enable(dsi->clks[i]); in samsung_dsim_resume()
2094 ret = phy_power_on(dsi->phy); in samsung_dsim_resume()
2096 dev_err(dsi->dev, "cannot enable phy %d\n", ret); in samsung_dsim_resume()
2103 while (--i > -1) in samsung_dsim_resume()
2104 clk_disable_unprepare(dsi->clks[i]); in samsung_dsim_resume()
2105 regulator_bulk_disable(ARRAY_SIZE(dsi->supplies), dsi->supplies); in samsung_dsim_resume()
2129 .compatible = "fsl,imx8mm-mipi-dsim",
2133 .compatible = "fsl,imx8mp-mipi-dsim",
2144 .name = "samsung-dsim",