Skip to content

Commit afef38b

Browse files
committed
Add --dumb-dcs parameter to stop interpretation of DCS commands
1 parent a970854 commit afef38b

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def generate_driver(p: Panel, options: Options) -> None:
433433
# Generate command sequences early
434434
for cmd in p.cmds.values():
435435
for c in cmd.seq:
436-
c.generated = c.type.generate(c.payload)
436+
c.generated = c.type.generate(c.payload, options)
437437
cmd.generated += c.generated
438438

439439
options.gpios = []

generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ class Options:
1212
backlight: bool
1313
backlight_gpio: bool
1414
ignore_wait: int
15+
dumb_dcs: bool

lmdpdg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def generate(p: Panel, options: generator.Options) -> None:
4242
Some device trees add a useless 1ms wait after each command, making the driver
4343
unnecessarily verbose.
4444
""")
45+
parser.add_argument('--dumb-dcs', dest='dumb_dcs', action='store_true', help="""
46+
Do not attempt to interpret DCS commands. Some panels use arbitrary DCS commands
47+
to write to registers, which conflict with commands specified in the MIPI DCS
48+
specification. This option stops interpretation of DCS commands, except for
49+
enter/exit_sleep_mode and set_display_on/off (which should be supported by
50+
any panel ideally).
51+
""")
4552
args = parser.parse_args(namespace=generator.Options())
4653

4754
for f in args.dtb:

mipi.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from enum import IntEnum, unique, Enum
1616
from typing import List, Optional, Union, Tuple
1717

18+
from generator import Options
19+
1820
import wrap
1921

2022

@@ -128,13 +130,16 @@ def get_params(self, b: bytes):
128130
return params
129131

130132
@staticmethod
131-
def find(payload: bytes) -> Optional[DCSCommand]:
133+
def find(payload: bytes, dumb: bool) -> Optional[DCSCommand]:
132134
try:
133135
dcs = DCSCommand(payload[0])
134136
except ValueError:
135137
# Not a specified DCS command
136138
return None
137139

140+
if dumb and dcs not in DCSCommand._DUMB_ALLOWED:
141+
return None
142+
138143
if dcs.nargs and len(payload) - 1 not in dcs.nargs:
139144
# Argument count does not match. Weird.
140145
expected_args = " or ".join(str(i) for i in dcs.nargs)
@@ -153,6 +158,10 @@ def find(payload: bytes) -> Optional[DCSCommand]:
153158
return dcs
154159

155160

161+
DCSCommand._DUMB_ALLOWED = [DCSCommand.ENTER_SLEEP_MODE, DCSCommand.EXIT_SLEEP_MODE,
162+
DCSCommand.SET_DISPLAY_ON, DCSCommand.SET_DISPLAY_OFF]
163+
164+
156165
def _generate_checked_call(method: str, args: List[str], description: str) -> str:
157166
return f'''\
158167
{wrap.join(f' ret = {method}(', ',', ');', args)}
@@ -169,17 +178,17 @@ def _generate_checked_call(method: str, args: List[str], description: str) -> st
169178
}
170179

171180

172-
def _generate_generic_write(t: Transaction, payload: bytes) -> str:
181+
def _generate_generic_write(t: Transaction, payload: bytes, options: Options) -> str:
173182
# TODO: Warn when downstream uses LONG_WRITE but mainline would use SHORT
174183
params = _get_params_hex(payload)
175184
params.insert(0, 'dsi')
176185
return wrap.join('\tdsi_generic_write_seq(', ',', ');', params, force=2)
177186

178187

179-
def _generate_dcs_write(t: Transaction, payload: bytes) -> str:
188+
def _generate_dcs_write(t: Transaction, payload: bytes, options: Options) -> str:
180189
# TODO: Warn when downstream uses LONG_WRITE but mainline would use SHORT
181190

182-
dcs = DCSCommand.find(payload)
191+
dcs = DCSCommand.find(payload, options.dumb_dcs)
183192
if dcs and dcs.method:
184193
return _generate_checked_call(dcs.method, dcs.get_params(payload[1:]), dcs.description)
185194

@@ -191,7 +200,7 @@ def _generate_dcs_write(t: Transaction, payload: bytes) -> str:
191200
return wrap.join('\tdsi_dcs_write_seq(', ',', ');', params, force=2)
192201

193202

194-
def _generate_peripheral(t: Transaction, payload: bytes) -> str:
203+
def _generate_peripheral(t: Transaction, payload: bytes, options: Options) -> str:
195204
if t == Transaction.TURN_ON_PERIPHERAL:
196205
return _generate_checked_call('mipi_dsi_turn_on_peripheral', ['dsi'], t.description)
197206
elif t == Transaction.SHUTDOWN_PERIPHERAL:
@@ -200,7 +209,7 @@ def _generate_peripheral(t: Transaction, payload: bytes) -> str:
200209
raise ValueError(t)
201210

202211

203-
def _generate_fallback(t: Transaction, payload: bytes) -> str:
212+
def _generate_fallback(t: Transaction, payload: bytes, options: Options) -> str:
204213
raise ValueError(t.name + ' is not supported')
205214

206215

@@ -270,5 +279,5 @@ def identifier(self):
270279
def description(self):
271280
return self.name.lower().replace('_', ' ')
272281

273-
def generate(self, payload: bytes) -> str:
274-
return self._generate(self, payload)
282+
def generate(self, payload: bytes, options: Options) -> str:
283+
return self._generate(self, payload, options)

0 commit comments

Comments
 (0)