Skip to content

Commit 7e22e11

Browse files
committed
drm/rp1: rp1-dsi: Add support for inverting lane polarities
The D-PHY on RP1 support lane polarity swapping, and there is a standard device tree mechanism for configuring this, so tie the two together. Signed-off-by: Dave Stevenson <[email protected]>
1 parent 34a7487 commit 7e22e11

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

drivers/gpu/drm/rp1/rp1-dsi/rp1_dsi.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,11 @@ static const struct mipi_dsi_host_ops rp1dsi_mipi_dsi_host_ops = {
417417
static int rp1dsi_platform_probe(struct platform_device *pdev)
418418
{
419419
struct device *dev = &pdev->dev;
420+
struct device_node *node = dev->of_node;
421+
struct device_node *endpoint;
420422
struct drm_device *drm;
421423
struct rp1_dsi *dsi;
422-
int i, ret;
424+
int i, nr_lanes, ret;
423425

424426
drm = drm_dev_alloc(&rp1dsi_driver, dev);
425427
if (IS_ERR(drm)) {
@@ -459,6 +461,12 @@ static int rp1dsi_platform_probe(struct platform_device *pdev)
459461
}
460462
}
461463

464+
endpoint = of_graph_get_endpoint_by_regs(node, 0, -1);
465+
nr_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
466+
if (nr_lanes > 0 && nr_lanes <= 4)
467+
of_property_read_u32_array(endpoint, "lane-polarities",
468+
dsi->lane_polarities, nr_lanes + 1);
469+
462470
for (i = 0; i < RP1DSI_NUM_HW_BLOCKS; i++) {
463471
dsi->hw_base[i] =
464472
devm_ioremap_resource(dev,

drivers/gpu/drm/rp1/rp1-dsi/rp1_dsi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ struct rp1_dsi {
4949
/* Clocks. We need DPI clock; the others are frequency references */
5050
struct clk *clocks[RP1DSI_NUM_CLOCKS];
5151

52+
/* Device tree parsed information */
53+
u32 lane_polarities[5];
54+
5255
/* Block (DSI DMA, DSI Host) base addresses, and current state */
5356
void __iomem *hw_base[RP1DSI_NUM_HW_BLOCKS];
5457
u32 cur_fmt;

drivers/gpu/drm/rp1/rp1-dsi/rp1_dsi_dsi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@
143143
#define DPHY_PLL_INPUT_DIV_OFFSET 0x17
144144
#define DPHY_PLL_LOOP_DIV_OFFSET 0x18
145145
#define DPHY_PLL_DIV_CTRL_OFFSET 0x19
146+
#define DPHY_CLK_PN_SWAP 0x35
146147
#define DPHY_HS_RX_CTRL_LANE0_OFFSET 0x44
148+
#define DPHY_D0_PN_SWAP 0x45
149+
#define DPHY_D1_PN_SWAP 0x55
150+
#define DPHY_D2_PN_SWAP 0x85
151+
#define DPHY_D3_PN_SWAP 0x95
147152

148153

149154
#define DSI_WRITE(reg, val) writel((val), dsi->hw_base[RP1DSI_HW_BLOCK_DSI] + (reg))
@@ -354,6 +359,13 @@ static u32 dphy_init(struct rp1_dsi *dsi, u32 ref_freq, u32 vco_freq)
354359
udelay(1);
355360
/* Since we are in DSI (not CSI2) mode here, start the PLL */
356361
actual_vco_freq = dphy_configure_pll(dsi, ref_freq, vco_freq);
362+
363+
dphy_transaction(dsi, DPHY_CLK_PN_SWAP, !!dsi->lane_polarities[0]);
364+
dphy_transaction(dsi, DPHY_D0_PN_SWAP, !!dsi->lane_polarities[1]);
365+
dphy_transaction(dsi, DPHY_D1_PN_SWAP, !!dsi->lane_polarities[2]);
366+
dphy_transaction(dsi, DPHY_D2_PN_SWAP, !!dsi->lane_polarities[3]);
367+
dphy_transaction(dsi, DPHY_D3_PN_SWAP, !!dsi->lane_polarities[4]);
368+
357369
udelay(1);
358370
/* Unreset */
359371
DSI_WRITE(DSI_PHYRSTZ, DSI_PHYRSTZ_SHUTDOWNZ_BITS);

0 commit comments

Comments
 (0)