Skip to content

Commit 574d5c4

Browse files
committed
Use new MIPI DSI _multi() calls for better error handling
Not all of the functions exist upstream yet, e.g. - mipi_dsi_dcs_set_tear_off_multi() - mipi_dsi_shutdown_peripheral_multi() are currently missing. These will need to be added upstream.
1 parent 3dd64f9 commit 574d5c4

File tree

2 files changed

+44
-51
lines changed

2 files changed

+44
-51
lines changed

driver.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ def msleep(m: int) -> str:
103103
return f"usleep_range({u}, {u + 1000})"
104104

105105

106+
# msleep(< 20) will possibly sleep up to 20ms
107+
# In this case, usleep_range should be used
108+
def dsi_msleep(m: int) -> str:
109+
if m >= 20:
110+
return f"mipi_dsi_msleep(&dsi_ctx, {m})"
111+
else:
112+
# It's hard to say what a good range would be...
113+
# Downstream uses usleep_range(m * 1000, m * 1000) but that doesn't quite sound great
114+
# Sleep for up to 1ms longer for now
115+
u = m * 1000
116+
return f"mipi_dsi_usleep_range(&dsi_ctx, {u}, {u + 1000})"
117+
118+
106119
def generate_reset(p: Panel, options: Options) -> str:
107120
if not p.reset_seq:
108121
return ''
@@ -126,21 +139,14 @@ def generate_commands(p: Panel, options: Options, cmd_name: str) -> str:
126139
s = f'''\
127140
static int {p.short_id}_{cmd_name}(struct {p.short_id} *ctx)
128141
{{
142+
struct mipi_dsi_multi_context dsi_ctx = {{ .dsi = ctx->dsi }};
129143
'''
130-
variables = ['struct mipi_dsi_device *dsi = ctx->dsi']
131-
if '(dev, ' in cmd.generated:
132-
variables.append('struct device *dev = &dsi->dev')
133-
if 'ret = ' in cmd.generated:
134-
variables.append('int ret')
135-
136-
for v in variables:
137-
s += f'\t{v};\n'
138144

139145
if p.cmds['on'].state != p.cmds['off'].state:
140146
if cmd.state == CommandSequence.State.LP_MODE:
141-
s += '\n\tdsi->mode_flags |= MIPI_DSI_MODE_LPM;\n'
147+
s += '\n\tctx->dsi->mode_flags |= MIPI_DSI_MODE_LPM;\n'
142148
elif cmd.state == CommandSequence.State.HS_MODE:
143-
s += '\n\tdsi->mode_flags &= ~MIPI_DSI_MODE_LPM;\n'
149+
s += '\n\tctx->dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;\n'
144150

145151
block = True
146152
for c in cmd.seq:
@@ -150,10 +156,10 @@ def generate_commands(p: Panel, options: Options, cmd_name: str) -> str:
150156

151157
s += c.generated + '\n'
152158
if c.wait and c.wait > options.ignore_wait:
153-
s += f'\t{msleep(c.wait)};\n'
159+
s += f'\t{dsi_msleep(c.wait)};\n'
154160

155161
s += '''
156-
return 0;
162+
return dsi_ctx.accum_err;
157163
}
158164
'''
159165
return s

mipi.py

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def get_params(b: bytes) -> List[str]:
6262
# MIPI DCS commands
6363
@unique
6464
class DCSCommand(Enum):
65-
NOP = 0x00, 0, 'mipi_dsi_dcs_nop'
66-
SOFT_RESET = 0x01, 0, 'mipi_dsi_dcs_soft_reset'
65+
NOP = 0x00, 0, 'mipi_dsi_dcs_nop_multi'
66+
SOFT_RESET = 0x01, 0, 'mipi_dsi_dcs_soft_reset_multi'
6767
# GET_COMPRESSION_MODE = 0x03,
6868
# GET_DISPLAY_ID = 0x04,
6969
# GET_ERROR_COUNT_ON_DSI = 0x05,
@@ -77,40 +77,40 @@ class DCSCommand(Enum):
7777
# GET_DISPLAY_MODE = 0x0D,
7878
# GET_SIGNAL_MODE = 0x0E,
7979
# GET_DIAGNOSTIC_RESULT = 0x0F,
80-
ENTER_SLEEP_MODE = 0x10, 0, 'mipi_dsi_dcs_enter_sleep_mode'
81-
EXIT_SLEEP_MODE = 0x11, 0, 'mipi_dsi_dcs_exit_sleep_mode'
80+
ENTER_SLEEP_MODE = 0x10, 0, 'mipi_dsi_dcs_enter_sleep_mode_multi'
81+
EXIT_SLEEP_MODE = 0x11, 0, 'mipi_dsi_dcs_exit_sleep_mode_multi'
8282
ENTER_PARTIAL_MODE = 0x12, 0,
8383
ENTER_NORMAL_MODE = 0x13, 0,
8484
# GET_IMAGE_CHECKSUM_RGB = 0x14,
8585
# GET_IMAGE_CHECKSUM_CT = 0x15,
8686
EXIT_INVERT_MODE = 0x20, 0,
8787
ENTER_INVERT_MODE = 0x21, 0,
8888
SET_GAMMA_CURVE = 0x26, 1,
89-
SET_DISPLAY_OFF = 0x28, 0, 'mipi_dsi_dcs_set_display_off'
90-
SET_DISPLAY_ON = 0x29, 0, 'mipi_dsi_dcs_set_display_on'
91-
SET_COLUMN_ADDRESS = 0x2A, 4, 'mipi_dsi_dcs_set_column_address', _get_params_int(2, 'big')
92-
SET_PAGE_ADDRESS = 0x2B, 4, 'mipi_dsi_dcs_set_page_address', _get_params_int(2, 'big')
89+
SET_DISPLAY_OFF = 0x28, 0, 'mipi_dsi_dcs_set_display_off_multi'
90+
SET_DISPLAY_ON = 0x29, 0, 'mipi_dsi_dcs_set_display_on_multi'
91+
SET_COLUMN_ADDRESS = 0x2A, 4, 'mipi_dsi_dcs_set_column_address_multi', _get_params_int(2, 'big')
92+
SET_PAGE_ADDRESS = 0x2B, 4, 'mipi_dsi_dcs_set_page_address_multi', _get_params_int(2, 'big')
9393
WRITE_MEMORY_START = 0x2C,
9494
WRITE_LUT = 0x2D,
9595
READ_MEMORY_START = 0x2E,
9696
SET_PARTIAL_ROWS = 0x30,
9797
SET_PARTIAL_COLUMNS = 0x31,
9898
SET_SCROLL_AREA = 0x33, 6,
99-
SET_TEAR_OFF = 0x34, 0, 'mipi_dsi_dcs_set_tear_off'
100-
SET_TEAR_ON = 0x35, 1, 'mipi_dsi_dcs_set_tear_on', TearMode.get_params
99+
SET_TEAR_OFF = 0x34, 0, 'mipi_dsi_dcs_set_tear_off_multi'
100+
SET_TEAR_ON = 0x35, 1, 'mipi_dsi_dcs_set_tear_on_multi', TearMode.get_params
101101
SET_ADDRESS_MODE = 0x36, 1,
102102
SET_SCROLL_START = 0x37, 2,
103103
EXIT_IDLE_MODE = 0x38, 0,
104104
ENTER_IDLE_MODE = 0x39, 0,
105-
SET_PIXEL_FORMAT = 0x3A, 1, 'mipi_dsi_dcs_set_pixel_format'
105+
SET_PIXEL_FORMAT = 0x3A, 1, 'mipi_dsi_dcs_set_pixel_format_multi'
106106
WRITE_MEMORY_CONTINUE = 0x3C,
107107
SET_3D_CONTROL = 0x3D,
108108
READ_MEMORY_CONTINUE = 0x3E,
109109
# GET_3D_CONTROL = 0x3F,
110110
SET_VSYNC_TIMING = 0x40
111-
SET_TEAR_SCANLINE = 0x44, 2, 'mipi_dsi_dcs_set_tear_scanline', _get_params_int(2, 'big')
111+
SET_TEAR_SCANLINE = 0x44, 2, 'mipi_dsi_dcs_set_tear_scanline_multi', _get_params_int(2, 'big')
112112
GET_SCANLINE = 0x45,
113-
SET_DISPLAY_BRIGHTNESS = 0x51, (1, 2), 'mipi_dsi_dcs_set_display_brightness', _get_params_int(2, 'little')
113+
SET_DISPLAY_BRIGHTNESS = 0x51, (1, 2), 'mipi_dsi_dcs_set_display_brightness_multi', _get_params_int(2, 'little')
114114
# GET_DISPLAY_BRIGHTNESS = 0x52,
115115
WRITE_CONTROL_DISPLAY = 0x53, 1,
116116
# GET_CONTROL_DISPLAY = 0x54,
@@ -136,13 +136,9 @@ def __new__(cls, value: int, nargs: Union[int, Tuple[int]] = (), method: str = N
136136
def identifier(self):
137137
return 'MIPI_DCS_' + self.name
138138

139-
@property
140-
def description(self):
141-
return self.name.lower().replace('_', ' ')
142-
143139
def get_params(self, b: bytes):
144140
params = self._get_params(b)
145-
params.insert(0, 'dsi')
141+
params.insert(0, '&dsi_ctx')
146142
return params
147143

148144
@staticmethod
@@ -178,50 +174,45 @@ def find(payload: bytes, dumb: bool) -> Optional[DCSCommand]:
178174
DCSCommand.SET_DISPLAY_ON, DCSCommand.SET_DISPLAY_OFF]
179175

180176

181-
def _generate_checked_call(method: str, args: List[str], description: str) -> str:
182-
return f'''\
183-
{wrap.join(f' ret = {method}(', ',', ');', args)}
184-
if (ret < 0) {{
185-
dev_err(dev, "Failed to {description}: %d\\n", ret);
186-
return ret;
187-
}}\
188-
'''
177+
def _generate_call(method: str, args: List[str]) -> str:
178+
return wrap.join(f'\t{method}(', ',', ');', args)
189179

190180

191181
def _generate_generic_write(t: Transaction, payload: bytes, options: Options) -> str:
192182
# TODO: Warn when downstream uses LONG_WRITE but mainline would use SHORT
193183
params = _get_params_hex(payload)
194-
params.insert(0, 'dsi')
195-
return wrap.join('\tmipi_dsi_generic_write_seq(', ',', ');', params, force=2)
184+
params.insert(0, '&dsi_ctx')
185+
return wrap.join('\tmipi_dsi_generic_write_seq_multi(', ',', ');', params, force=2)
196186

197187

198188
def _generate_dcs_write(t: Transaction, payload: bytes, options: Options) -> str:
199189
# TODO: Warn when downstream uses LONG_WRITE but mainline would use SHORT
200190

201191
dcs = DCSCommand.find(payload, options.dumb_dcs)
202192
if dcs and dcs.method:
203-
return _generate_checked_call(dcs.method, dcs.get_params(payload[1:]), dcs.description)
193+
return _generate_call(dcs.method, dcs.get_params(payload[1:]))
204194

205195
params = _get_params_hex(payload)
206196
if dcs:
207197
params[0] = dcs.identifier
208-
params.insert(0, 'dsi')
198+
params.insert(0, '&dsi_ctx')
209199

210-
return wrap.join('\tmipi_dsi_dcs_write_seq(', ',', ');', params, force=2)
200+
return wrap.join('\tmipi_dsi_dcs_write_seq_multi(', ',', ');', params, force=2)
211201

212202

213203
def _generate_peripheral(t: Transaction, payload: bytes, options: Options) -> str:
214204
if t == Transaction.TURN_ON_PERIPHERAL:
215-
return _generate_checked_call('mipi_dsi_turn_on_peripheral', ['dsi'], t.description)
205+
return _generate_call('mipi_dsi_turn_on_peripheral_multi', ['&dsi_ctx'])
216206
elif t == Transaction.SHUTDOWN_PERIPHERAL:
217-
return _generate_checked_call('mipi_dsi_shutdown_peripheral', ['dsi'], t.description)
207+
return _generate_call('mipi_dsi_shutdown_peripheral_multi', ['&dsi_ctx'])
218208
else:
219209
raise ValueError(t)
220210

221211

222212
def _generate_compression_mode(t: Transaction, payload: bytes, options: Options) -> str:
223-
return _generate_checked_call('mipi_dsi_compression_mode', ['dsi', str(bool(payload[0])).lower()],
224-
'set compression mode')
213+
return _generate_call('mipi_dsi_compression_mode_ext_multi',
214+
['&dsi_ctx', str(bool(payload[0])).lower(),
215+
'MIPI_DSI_COMPRESSION_DSC', '0']) # TODO: Do we need something != 0?
225216

226217

227218
def _generate_ignore(t: Transaction, payload: bytes, options: Options) -> str:
@@ -297,10 +288,6 @@ def __new__(cls, value: int, max_args: int = -1, generate=_generate_fallback) ->
297288
def identifier(self):
298289
return 'MIPI_DSI_' + self.name
299290

300-
@property
301-
def description(self):
302-
return self.name.lower().replace('_', ' ')
303-
304291
@property
305292
def is_long(self):
306293
# From mipi_dsi_packet_format_is_long()

0 commit comments

Comments
 (0)