Skip to content

Commit ff55787

Browse files
committed
drm/bridge: tc358768: Separate indirect register writes
Some registers can only be written indirectly, using DSI_CONFW register. We don't have many uses for those registers (in fact, only DSI_CONTROL is currently written), but the code to do those writes inline is a bit confusing. Add a new function, tc358768_confw_update_bits() which can be used to write the bits indirectly. Only DSI_CONTROL is currently supported. Tested-by: João Paulo Gonçalves <joao.goncalves@toradex.com> # Toradex Verdin AM62 Reviewed-by: Francesco Dolcini <francesco.dolcini@toradex.com> Link: https://patch.msgid.link/20260311-tc358768-v2-3-e75a99131bd5@ideasonboard.com Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
1 parent 6b2bb54 commit ff55787

1 file changed

Lines changed: 39 additions & 13 deletions

File tree

drivers/gpu/drm/bridge/tc358768.c

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
/* TC358768_DSI_CONFW (0x0500) register */
124124
#define TC358768_DSI_CONFW_MODE_SET (5 << 29)
125125
#define TC358768_DSI_CONFW_MODE_CLR (6 << 29)
126-
#define TC358768_DSI_CONFW_ADDR_DSI_CONTROL (0x3 << 24)
126+
#define TC358768_DSI_CONFW_ADDR(x) ((x) << 24)
127127

128128
/* TC358768_DSICMD_TX (0x0600) register */
129129
#define TC358768_DSI_CMDTX_DC_START BIT(0)
@@ -232,6 +232,36 @@ static void tc358768_update_bits(struct tc358768_priv *priv, u32 reg, u32 mask,
232232
tc358768_write(priv, reg, tmp);
233233
}
234234

235+
static void tc358768_confw_update_bits(struct tc358768_priv *priv, u16 reg,
236+
u16 mask, u16 val)
237+
{
238+
u8 confw_addr;
239+
u32 confw_val;
240+
241+
switch (reg) {
242+
case TC358768_DSI_CONTROL:
243+
confw_addr = 0x3;
244+
break;
245+
default:
246+
priv->error = -EINVAL;
247+
return;
248+
}
249+
250+
if (mask != val) {
251+
confw_val = TC358768_DSI_CONFW_MODE_CLR |
252+
TC358768_DSI_CONFW_ADDR(confw_addr) |
253+
mask;
254+
tc358768_write(priv, TC358768_DSI_CONFW, confw_val);
255+
}
256+
257+
if (val & mask) {
258+
confw_val = TC358768_DSI_CONFW_MODE_SET |
259+
TC358768_DSI_CONFW_ADDR(confw_addr) |
260+
(val & mask);
261+
tc358768_write(priv, TC358768_DSI_CONFW, confw_val);
262+
}
263+
}
264+
235265
static void tc358768_dsicmd_tx(struct tc358768_priv *priv)
236266
{
237267
u32 val;
@@ -693,7 +723,7 @@ static void tc358768_bridge_atomic_pre_enable(struct drm_bridge *bridge,
693723
struct tc358768_priv *priv = bridge_to_tc358768(bridge);
694724
struct mipi_dsi_device *dsi_dev = priv->output.dev;
695725
unsigned long mode_flags = dsi_dev->mode_flags;
696-
u32 val, val2, lptxcnt, hact, data_type;
726+
u32 val, mask, val2, lptxcnt, hact, data_type;
697727
s32 raw_val;
698728
struct drm_crtc_state *crtc_state;
699729
struct drm_connector_state *conn_state;
@@ -1065,13 +1095,7 @@ static void tc358768_bridge_atomic_pre_enable(struct drm_bridge *bridge,
10651095
tc358768_write(priv, TC358768_DSI_START, 0x1);
10661096

10671097
/* Configure DSI_Control register */
1068-
val = TC358768_DSI_CONFW_MODE_CLR | TC358768_DSI_CONFW_ADDR_DSI_CONTROL;
1069-
val |= TC358768_DSI_CONTROL_TXMD | TC358768_DSI_CONTROL_HSCKMD |
1070-
0x3 << 1 | TC358768_DSI_CONTROL_EOTDIS;
1071-
tc358768_write(priv, TC358768_DSI_CONFW, val);
1072-
1073-
val = TC358768_DSI_CONFW_MODE_SET | TC358768_DSI_CONFW_ADDR_DSI_CONTROL;
1074-
val |= (dsi_dev->lanes - 1) << 1;
1098+
val = (dsi_dev->lanes - 1) << 1;
10751099

10761100
val |= TC358768_DSI_CONTROL_TXMD;
10771101

@@ -1081,11 +1105,13 @@ static void tc358768_bridge_atomic_pre_enable(struct drm_bridge *bridge,
10811105
if (dsi_dev->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET)
10821106
val |= TC358768_DSI_CONTROL_EOTDIS;
10831107

1084-
tc358768_write(priv, TC358768_DSI_CONFW, val);
1108+
mask = TC358768_DSI_CONTROL_TXMD | TC358768_DSI_CONTROL_HSCKMD |
1109+
0x3 << 1 | TC358768_DSI_CONTROL_EOTDIS;
1110+
1111+
tc358768_confw_update_bits(priv, TC358768_DSI_CONTROL, mask, val);
10851112

1086-
val = TC358768_DSI_CONFW_MODE_CLR | TC358768_DSI_CONFW_ADDR_DSI_CONTROL;
1087-
val |= TC358768_DSI_CONTROL_DSI_MODE;
1088-
tc358768_write(priv, TC358768_DSI_CONFW, val);
1113+
tc358768_confw_update_bits(priv, TC358768_DSI_CONTROL,
1114+
TC358768_DSI_CONTROL_DSI_MODE, 0);
10891115

10901116
ret = tc358768_clear_error(priv);
10911117
if (ret)

0 commit comments

Comments
 (0)