Skip to content

Commit 076403a

Browse files
meltqsuperna9999
authored andcommitted
drm/panel: novatek-nt35950: transition to mipi_dsi wrapped functions
Changes the novatek-nt35950 panel to use multi style functions for improved error handling. Reviewed-by: Neil Armstrong <[email protected]> Signed-off-by: Tejas Vipin <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Neil Armstrong <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent e0cb0c7 commit 076403a

File tree

1 file changed

+66
-145
lines changed

1 file changed

+66
-145
lines changed

drivers/gpu/drm/panel/panel-novatek-nt35950.c

Lines changed: 66 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -100,106 +100,87 @@ static void nt35950_reset(struct nt35950 *nt)
100100

101101
/*
102102
* nt35950_set_cmd2_page - Select manufacturer control (CMD2) page
103+
* @dsi_ctx: context for mipi_dsi functions
103104
* @nt: Main driver structure
104105
* @page: Page number (0-7)
105-
*
106-
* Return: Number of transferred bytes or negative number on error
107106
*/
108-
static int nt35950_set_cmd2_page(struct nt35950 *nt, u8 page)
107+
static void nt35950_set_cmd2_page(struct mipi_dsi_multi_context *dsi_ctx,
108+
struct nt35950 *nt, u8 page)
109109
{
110110
const u8 mauc_cmd2_page[] = { MCS_CMD_MAUCCTR, 0x55, 0xaa, 0x52,
111111
0x08, page };
112-
int ret;
113112

114-
ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], mauc_cmd2_page,
113+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, mauc_cmd2_page,
115114
ARRAY_SIZE(mauc_cmd2_page));
116-
if (ret < 0)
117-
return ret;
118-
119-
nt->last_page = page;
120-
return 0;
115+
if (!dsi_ctx->accum_err)
116+
nt->last_page = page;
121117
}
122118

123119
/*
124120
* nt35950_set_data_compression - Set data compression mode
121+
* @dsi_ctx: context for mipi_dsi functions
125122
* @nt: Main driver structure
126123
* @comp_mode: Compression mode
127-
*
128-
* Return: Number of transferred bytes or negative number on error
129124
*/
130-
static int nt35950_set_data_compression(struct nt35950 *nt, u8 comp_mode)
125+
static void nt35950_set_data_compression(struct mipi_dsi_multi_context *dsi_ctx,
126+
struct nt35950 *nt, u8 comp_mode)
131127
{
132128
u8 cmd_data_compression[] = { MCS_PARAM_DATA_COMPRESSION, comp_mode };
133129
u8 cmd_vesa_dsc_on[] = { MCS_PARAM_VESA_DSC_ON, !!comp_mode };
134130
u8 cmd_vesa_dsc_setting[] = { MCS_PARAM_VESA_DSC_SETTING, 0x03 };
135131
u8 last_page = nt->last_page;
136-
int ret;
137132

138133
/* Set CMD2 Page 0 if we're not there yet */
139-
if (last_page != 0) {
140-
ret = nt35950_set_cmd2_page(nt, 0);
141-
if (ret < 0)
142-
return ret;
143-
}
134+
if (last_page != 0)
135+
nt35950_set_cmd2_page(dsi_ctx, nt, 0);
144136

145-
ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_data_compression,
137+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_data_compression,
146138
ARRAY_SIZE(cmd_data_compression));
147-
if (ret < 0)
148-
return ret;
149-
150-
ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_vesa_dsc_on,
139+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_vesa_dsc_on,
151140
ARRAY_SIZE(cmd_vesa_dsc_on));
152-
if (ret < 0)
153-
return ret;
154141

155142
/* Set the vesa dsc setting on Page 4 */
156-
ret = nt35950_set_cmd2_page(nt, 4);
157-
if (ret < 0)
158-
return ret;
143+
nt35950_set_cmd2_page(dsi_ctx, nt, 4);
159144

160145
/* Display Stream Compression setting, always 0x03 */
161-
ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_vesa_dsc_setting,
146+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_vesa_dsc_setting,
162147
ARRAY_SIZE(cmd_vesa_dsc_setting));
163-
if (ret < 0)
164-
return ret;
165148

166149
/* Get back to the previously set page */
167-
return nt35950_set_cmd2_page(nt, last_page);
150+
nt35950_set_cmd2_page(dsi_ctx, nt, last_page);
168151
}
169152

170153
/*
171154
* nt35950_set_scaler - Enable/disable resolution upscaling
172-
* @nt: Main driver structure
155+
* @dsi_ctx: context for mipi_dsi functions
173156
* @scale_up: Scale up function control
174-
*
175-
* Return: Number of transferred bytes or negative number on error
176157
*/
177-
static int nt35950_set_scaler(struct nt35950 *nt, u8 scale_up)
158+
static void nt35950_set_scaler(struct mipi_dsi_multi_context *dsi_ctx,
159+
u8 scale_up)
178160
{
179161
u8 cmd_scaler[] = { MCS_PARAM_SCALER_FUNCTION, scale_up };
180162

181-
return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_scaler,
182-
ARRAY_SIZE(cmd_scaler));
163+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_scaler,
164+
ARRAY_SIZE(cmd_scaler));
183165
}
184166

185167
/*
186168
* nt35950_set_scale_mode - Resolution upscaling mode
187-
* @nt: Main driver structure
169+
* @dsi_ctx: context for mipi_dsi functions
188170
* @mode: Scaler mode (MCS_DATA_COMPRESSION_*)
189-
*
190-
* Return: Number of transferred bytes or negative number on error
191171
*/
192-
static int nt35950_set_scale_mode(struct nt35950 *nt, u8 mode)
172+
static void nt35950_set_scale_mode(struct mipi_dsi_multi_context *dsi_ctx,
173+
u8 mode)
193174
{
194175
u8 cmd_scaler[] = { MCS_PARAM_SCALEUP_MODE, mode };
195176

196-
return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_scaler,
197-
ARRAY_SIZE(cmd_scaler));
177+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_scaler,
178+
ARRAY_SIZE(cmd_scaler));
198179
}
199180

200181
/*
201182
* nt35950_inject_black_image - Display a completely black image
202-
* @nt: Main driver structure
183+
* @dsi_ctx: context for mipi_dsi functions
203184
*
204185
* After IC setup, the attached panel may show random data
205186
* due to driveric behavior changes (resolution, compression,
@@ -208,43 +189,34 @@ static int nt35950_set_scale_mode(struct nt35950 *nt, u8 mode)
208189
* the display.
209190
* It makes sense to push a black image before sending the sleep-out
210191
* and display-on commands.
211-
*
212-
* Return: Number of transferred bytes or negative number on error
213192
*/
214-
static int nt35950_inject_black_image(struct nt35950 *nt)
193+
static void nt35950_inject_black_image(struct mipi_dsi_multi_context *dsi_ctx)
215194
{
216195
const u8 cmd0_black_img[] = { 0x6f, 0x01 };
217196
const u8 cmd1_black_img[] = { 0xf3, 0x10 };
218197
u8 cmd_test[] = { 0xff, 0xaa, 0x55, 0xa5, 0x80 };
219-
int ret;
220198

221199
/* Enable test command */
222-
ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_test, ARRAY_SIZE(cmd_test));
223-
if (ret < 0)
224-
return ret;
200+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_test, ARRAY_SIZE(cmd_test));
225201

226202
/* Send a black image */
227-
ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd0_black_img,
203+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd0_black_img,
228204
ARRAY_SIZE(cmd0_black_img));
229-
if (ret < 0)
230-
return ret;
231-
ret = mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd1_black_img,
205+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd1_black_img,
232206
ARRAY_SIZE(cmd1_black_img));
233-
if (ret < 0)
234-
return ret;
235207

236208
/* Disable test command */
237209
cmd_test[ARRAY_SIZE(cmd_test) - 1] = 0x00;
238-
return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_test, ARRAY_SIZE(cmd_test));
210+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_test, ARRAY_SIZE(cmd_test));
239211
}
240212

241213
/*
242214
* nt35950_set_dispout - Set Display Output register parameters
243215
* @nt: Main driver structure
244-
*
245-
* Return: Number of transferred bytes or negative number on error
216+
* @dsi_ctx: context for mipi_dsi functions
246217
*/
247-
static int nt35950_set_dispout(struct nt35950 *nt)
218+
static void nt35950_set_dispout(struct mipi_dsi_multi_context *dsi_ctx,
219+
struct nt35950 *nt)
248220
{
249221
u8 cmd_dispout[] = { MCS_PARAM_DISP_OUTPUT_CTRL, 0x00 };
250222
const struct nt35950_panel_mode *mode_data = nt->desc->mode_data;
@@ -254,8 +226,8 @@ static int nt35950_set_dispout(struct nt35950 *nt)
254226
if (mode_data[nt->cur_mode].enable_sram)
255227
cmd_dispout[1] |= MCS_DISP_OUT_SRAM_EN;
256228

257-
return mipi_dsi_dcs_write_buffer(nt->dsi[0], cmd_dispout,
258-
ARRAY_SIZE(cmd_dispout));
229+
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, cmd_dispout,
230+
ARRAY_SIZE(cmd_dispout));
259231
}
260232

261233
static int nt35950_get_current_mode(struct nt35950 *nt)
@@ -284,109 +256,67 @@ static int nt35950_on(struct nt35950 *nt)
284256
{
285257
const struct nt35950_panel_mode *mode_data = nt->desc->mode_data;
286258
struct mipi_dsi_device *dsi = nt->dsi[0];
287-
struct device *dev = &dsi->dev;
288-
int ret;
259+
struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
289260

290261
nt->cur_mode = nt35950_get_current_mode(nt);
291262
nt->dsi[0]->mode_flags |= MIPI_DSI_MODE_LPM;
292263
nt->dsi[1]->mode_flags |= MIPI_DSI_MODE_LPM;
293264

294-
ret = nt35950_set_cmd2_page(nt, 0);
295-
if (ret < 0)
296-
return ret;
265+
nt35950_set_cmd2_page(&dsi_ctx, nt, 0);
266+
nt35950_set_data_compression(&dsi_ctx, nt, mode_data[nt->cur_mode].compression);
267+
nt35950_set_scale_mode(&dsi_ctx, mode_data[nt->cur_mode].scaler_mode);
268+
nt35950_set_scaler(&dsi_ctx, mode_data[nt->cur_mode].scaler_on);
269+
nt35950_set_dispout(&dsi_ctx, nt);
297270

298-
ret = nt35950_set_data_compression(nt, mode_data[nt->cur_mode].compression);
299-
if (ret < 0)
300-
return ret;
301-
302-
ret = nt35950_set_scale_mode(nt, mode_data[nt->cur_mode].scaler_mode);
303-
if (ret < 0)
304-
return ret;
305-
306-
ret = nt35950_set_scaler(nt, mode_data[nt->cur_mode].scaler_on);
307-
if (ret < 0)
308-
return ret;
309-
310-
ret = nt35950_set_dispout(nt);
311-
if (ret < 0)
312-
return ret;
313-
314-
ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
315-
if (ret < 0) {
316-
dev_err(dev, "Failed to set tear on: %d\n", ret);
317-
return ret;
318-
}
319-
320-
ret = mipi_dsi_dcs_set_tear_scanline(dsi, 0);
321-
if (ret < 0) {
322-
dev_err(dev, "Failed to set tear scanline: %d\n", ret);
323-
return ret;
324-
}
271+
mipi_dsi_dcs_set_tear_on_multi(&dsi_ctx, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
272+
mipi_dsi_dcs_set_tear_scanline_multi(&dsi_ctx, 0);
325273

326274
/* CMD2 Page 1 */
327-
ret = nt35950_set_cmd2_page(nt, 1);
328-
if (ret < 0)
329-
return ret;
275+
nt35950_set_cmd2_page(&dsi_ctx, nt, 1);
330276

331277
/* Unknown command */
332-
mipi_dsi_dcs_write_seq(dsi, 0xd4, 0x88, 0x88);
278+
mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xd4, 0x88, 0x88);
333279

334280
/* CMD2 Page 7 */
335-
ret = nt35950_set_cmd2_page(nt, 7);
336-
if (ret < 0)
337-
return ret;
281+
nt35950_set_cmd2_page(&dsi_ctx, nt, 7);
338282

339283
/* Enable SubPixel Rendering */
340-
mipi_dsi_dcs_write_seq(dsi, MCS_PARAM_SPR_EN, 0x01);
284+
mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MCS_PARAM_SPR_EN, 0x01);
341285

342286
/* SPR Mode: YYG Rainbow-RGB */
343-
mipi_dsi_dcs_write_seq(dsi, MCS_PARAM_SPR_MODE, MCS_SPR_MODE_YYG_RAINBOW_RGB);
287+
mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MCS_PARAM_SPR_MODE,
288+
MCS_SPR_MODE_YYG_RAINBOW_RGB);
344289

345290
/* CMD3 */
346-
ret = nt35950_inject_black_image(nt);
347-
if (ret < 0)
348-
return ret;
291+
nt35950_inject_black_image(&dsi_ctx);
292+
mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
293+
mipi_dsi_msleep(&dsi_ctx, 120);
349294

350-
ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
351-
if (ret < 0)
352-
return ret;
353-
msleep(120);
295+
mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
296+
mipi_dsi_msleep(&dsi_ctx, 120);
354297

355-
ret = mipi_dsi_dcs_set_display_on(dsi);
356-
if (ret < 0)
357-
return ret;
358-
msleep(120);
298+
if (dsi_ctx.accum_err)
299+
return dsi_ctx.accum_err;
359300

360301
nt->dsi[0]->mode_flags &= ~MIPI_DSI_MODE_LPM;
361302
nt->dsi[1]->mode_flags &= ~MIPI_DSI_MODE_LPM;
362303

363304
return 0;
364305
}
365306

366-
static int nt35950_off(struct nt35950 *nt)
307+
static void nt35950_off(struct nt35950 *nt)
367308
{
368-
struct device *dev = &nt->dsi[0]->dev;
369-
int ret;
309+
struct mipi_dsi_device *dsi = nt->dsi[0];
310+
struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
370311

371-
ret = mipi_dsi_dcs_set_display_off(nt->dsi[0]);
372-
if (ret < 0) {
373-
dev_err(dev, "Failed to set display off: %d\n", ret);
374-
goto set_lpm;
375-
}
376-
usleep_range(10000, 11000);
312+
mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
313+
mipi_dsi_usleep_range(&dsi_ctx, 10000, 11000);
377314

378-
ret = mipi_dsi_dcs_enter_sleep_mode(nt->dsi[0]);
379-
if (ret < 0) {
380-
dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
381-
goto set_lpm;
382-
}
383-
msleep(150);
315+
mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
316+
mipi_dsi_msleep(&dsi_ctx, 150);
384317

385-
set_lpm:
386318
nt->dsi[0]->mode_flags |= MIPI_DSI_MODE_LPM;
387319
nt->dsi[1]->mode_flags |= MIPI_DSI_MODE_LPM;
388-
389-
return 0;
390320
}
391321

392322
static int nt35950_sharp_init_vregs(struct nt35950 *nt, struct device *dev)
@@ -427,7 +357,6 @@ static int nt35950_sharp_init_vregs(struct nt35950 *nt, struct device *dev)
427357
static int nt35950_prepare(struct drm_panel *panel)
428358
{
429359
struct nt35950 *nt = to_nt35950(panel);
430-
struct device *dev = &nt->dsi[0]->dev;
431360
int ret;
432361

433362
ret = regulator_enable(nt->vregs[0].consumer);
@@ -452,10 +381,6 @@ static int nt35950_prepare(struct drm_panel *panel)
452381
nt35950_reset(nt);
453382

454383
ret = nt35950_on(nt);
455-
if (ret < 0) {
456-
dev_err(dev, "Failed to initialize panel: %d\n", ret);
457-
goto end;
458-
}
459384

460385
end:
461386
if (ret < 0) {
@@ -469,12 +394,8 @@ static int nt35950_prepare(struct drm_panel *panel)
469394
static int nt35950_unprepare(struct drm_panel *panel)
470395
{
471396
struct nt35950 *nt = to_nt35950(panel);
472-
struct device *dev = &nt->dsi[0]->dev;
473-
int ret;
474397

475-
ret = nt35950_off(nt);
476-
if (ret < 0)
477-
dev_err(dev, "Failed to deinitialize panel: %d\n", ret);
398+
nt35950_off(nt);
478399

479400
gpiod_set_value_cansleep(nt->reset_gpio, 0);
480401
regulator_bulk_disable(ARRAY_SIZE(nt->vregs), nt->vregs);

0 commit comments

Comments
 (0)