Lines Matching refs:ctx
118 static int ld9040_clear_error(struct ld9040 *ctx)
120 int ret = ctx->error;
122 ctx->error = 0;
126 static int ld9040_spi_write_word(struct ld9040 *ctx, u16 data)
128 struct spi_device *spi = to_spi_device(ctx->dev);
141 static void ld9040_dcs_write(struct ld9040 *ctx, const u8 *data, size_t len)
145 if (ctx->error < 0 || len == 0)
148 dev_dbg(ctx->dev, "writing dcs seq: %*ph\n", (int)len, data);
149 ret = ld9040_spi_write_word(ctx, *data);
153 ret = ld9040_spi_write_word(ctx, *data | 0x100);
157 dev_err(ctx->dev, "error %d writing dcs seq: %*ph\n", ret,
159 ctx->error = ret;
165 #define ld9040_dcs_write_seq_static(ctx, seq...) \
168 ld9040_dcs_write(ctx, d, ARRAY_SIZE(d));\
171 static void ld9040_brightness_set(struct ld9040 *ctx)
173 ld9040_dcs_write(ctx, ld9040_gammas[ctx->brightness],
174 ARRAY_SIZE(ld9040_gammas[ctx->brightness]));
176 ld9040_dcs_write_seq_static(ctx, MCS_GAMMA_CTRL, 0x02, 0x5a);
179 static void ld9040_init(struct ld9040 *ctx)
181 ld9040_dcs_write_seq_static(ctx, MCS_USER_SETTING, 0x5a, 0x5a);
182 ld9040_dcs_write_seq_static(ctx, MCS_PANEL_CONDITION,
186 ld9040_dcs_write_seq_static(ctx, MCS_DISPCTL,
188 ld9040_dcs_write_seq_static(ctx, MCS_MANPWR, 0x04);
189 ld9040_dcs_write_seq_static(ctx, MCS_POWER_CTRL,
191 ld9040_dcs_write_seq_static(ctx, MCS_ELVSS_ON, 0x0d, 0x00, 0x16);
192 ld9040_dcs_write_seq_static(ctx, MCS_GTCON, 0x09, 0x00, 0x00);
193 ld9040_brightness_set(ctx);
194 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_EXIT_SLEEP_MODE);
195 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_ON);
198 static int ld9040_power_on(struct ld9040 *ctx)
202 ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
206 msleep(ctx->power_on_delay);
207 gpiod_set_value(ctx->reset_gpio, 0);
208 msleep(ctx->reset_delay);
209 gpiod_set_value(ctx->reset_gpio, 1);
210 msleep(ctx->reset_delay);
215 static int ld9040_power_off(struct ld9040 *ctx)
217 return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
227 struct ld9040 *ctx = panel_to_ld9040(panel);
230 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_OFF);
231 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_ENTER_SLEEP_MODE);
234 ld9040_clear_error(ctx);
236 return ld9040_power_off(ctx);
241 struct ld9040 *ctx = panel_to_ld9040(panel);
244 ret = ld9040_power_on(ctx);
248 ld9040_init(ctx);
250 ret = ld9040_clear_error(ctx);
266 struct ld9040 *ctx = panel_to_ld9040(panel);
275 drm_display_mode_from_videomode(&ctx->vm, mode);
276 mode->width_mm = ctx->width_mm;
277 mode->height_mm = ctx->height_mm;
295 static int ld9040_parse_dt(struct ld9040 *ctx)
297 struct device *dev = ctx->dev;
301 ret = of_get_videomode(np, &ctx->vm, 0);
305 of_property_read_u32(np, "power-on-delay", &ctx->power_on_delay);
306 of_property_read_u32(np, "reset-delay", &ctx->reset_delay);
307 of_property_read_u32(np, "panel-width-mm", &ctx->width_mm);
308 of_property_read_u32(np, "panel-height-mm", &ctx->height_mm);
316 struct ld9040 *ctx;
319 ctx = devm_kzalloc(dev, sizeof(struct ld9040), GFP_KERNEL);
320 if (!ctx)
323 spi_set_drvdata(spi, ctx);
325 ctx->dev = dev;
326 ctx->brightness = ARRAY_SIZE(ld9040_gammas) - 1;
328 ret = ld9040_parse_dt(ctx);
332 ctx->supplies[0].supply = "vdd3";
333 ctx->supplies[1].supply = "vci";
334 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
335 ctx->supplies);
339 ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
340 if (IS_ERR(ctx->reset_gpio)) {
342 PTR_ERR(ctx->reset_gpio));
343 return PTR_ERR(ctx->reset_gpio);
353 drm_panel_init(&ctx->panel, dev, &ld9040_drm_funcs,
356 drm_panel_add(&ctx->panel);
363 struct ld9040 *ctx = spi_get_drvdata(spi);
365 ld9040_power_off(ctx);
366 drm_panel_remove(&ctx->panel);