Skip to content

Commit f079f27

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 <dave.stevenson@raspberrypi.com>
1 parent 58f43fc commit f079f27

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,18 @@
145145
#define DSI_PHYRSTZ_FORCEPLL_LSB 3
146146
#define DSI_PHYRSTZ_FORCEPLL_BITS BIT(DSI_PHYRSTZ_FORCEPLL_LSB)
147147

148+
#define DPHY_CLK_PN_SWAP 0x35
149+
148150
#define DPHY_HS_RX_CTRL_LANE0_OFFSET 0x44
149151
#define DPHY_PLL_INPUT_DIV_OFFSET 0x17
150152
#define DPHY_PLL_LOOP_DIV_OFFSET 0x18
151153
#define DPHY_PLL_DIV_CTRL_OFFSET 0x19
152154

155+
#define DPHY_D0_PN_SWAP 0x45
156+
#define DPHY_D1_PN_SWAP 0x55
157+
#define DPHY_D2_PN_SWAP 0x85
158+
#define DPHY_D3_PN_SWAP 0x95
159+
153160
#define DPHY_PLL_BIAS_OFFSET 0x10
154161
#define DPHY_PLL_BIAS_VCO_RANGE_LSB 3
155162
#define DPHY_PLL_BIAS_USE_PROGRAMMED_VCO_RANGE BIT(7)
@@ -1290,6 +1297,13 @@ static u32 dphy_init(struct rp1_dsi *dsi, u32 ref_freq, u32 vco_freq)
12901297
udelay(1);
12911298
/* Since we are in DSI (not CSI2) mode here, start the PLL */
12921299
actual_vco_freq = dphy_configure_pll(dsi, ref_freq, vco_freq);
1300+
1301+
dphy_transaction(dsi, DPHY_CLK_PN_SWAP, !!dsi->lane_polarities[0]);
1302+
dphy_transaction(dsi, DPHY_D0_PN_SWAP, !!dsi->lane_polarities[1]);
1303+
dphy_transaction(dsi, DPHY_D1_PN_SWAP, !!dsi->lane_polarities[2]);
1304+
dphy_transaction(dsi, DPHY_D2_PN_SWAP, !!dsi->lane_polarities[3]);
1305+
dphy_transaction(dsi, DPHY_D3_PN_SWAP, !!dsi->lane_polarities[4]);
1306+
12931307
udelay(1);
12941308
/* Unreset */
12951309
DSI_WRITE(DSI_PHYRSTZ, DSI_PHYRSTZ_SHUTDOWNZ_BITS);

0 commit comments

Comments
 (0)