Lines Matching refs:ctx

119 static int ld9040_clear_error(struct ld9040 *ctx)
121 int ret = ctx->error;
123 ctx->error = 0;
127 static int ld9040_spi_write_word(struct ld9040 *ctx, u16 data)
129 struct spi_device *spi = to_spi_device(ctx->dev);
142 static void ld9040_dcs_write(struct ld9040 *ctx, const u8 *data, size_t len)
146 if (ctx->error < 0 || len == 0)
149 dev_dbg(ctx->dev, "writing dcs seq: %*ph\n", (int)len, data);
150 ret = ld9040_spi_write_word(ctx, *data);
154 ret = ld9040_spi_write_word(ctx, *data | 0x100);
158 dev_err(ctx->dev, "error %d writing dcs seq: %*ph\n", ret,
160 ctx->error = ret;
166 #define ld9040_dcs_write_seq_static(ctx, seq...) \
169 ld9040_dcs_write(ctx, d, ARRAY_SIZE(d));\
172 static void ld9040_brightness_set(struct ld9040 *ctx)
174 ld9040_dcs_write(ctx, ld9040_gammas[ctx->brightness],
175 ARRAY_SIZE(ld9040_gammas[ctx->brightness]));
177 ld9040_dcs_write_seq_static(ctx, MCS_GAMMA_CTRL, 0x02, 0x5a);
180 static void ld9040_init(struct ld9040 *ctx)
182 ld9040_dcs_write_seq_static(ctx, MCS_USER_SETTING, 0x5a, 0x5a);
183 ld9040_dcs_write_seq_static(ctx, MCS_PANEL_CONDITION,
187 ld9040_dcs_write_seq_static(ctx, MCS_DISPCTL,
189 ld9040_dcs_write_seq_static(ctx, MCS_MANPWR, 0x04);
190 ld9040_dcs_write_seq_static(ctx, MCS_POWER_CTRL,
192 ld9040_dcs_write_seq_static(ctx, MCS_ELVSS_ON, 0x0f, 0x00, 0x16);
193 ld9040_dcs_write_seq_static(ctx, MCS_GTCON, 0x09, 0x00, 0x00);
194 ld9040_brightness_set(ctx);
195 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_EXIT_SLEEP_MODE);
196 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_ON);
199 static int ld9040_power_on(struct ld9040 *ctx)
203 ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
207 msleep(ctx->power_on_delay);
208 gpiod_set_value(ctx->reset_gpio, 0);
209 msleep(ctx->reset_delay);
210 gpiod_set_value(ctx->reset_gpio, 1);
211 msleep(ctx->reset_delay);
216 static int ld9040_power_off(struct ld9040 *ctx)
218 return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
228 struct ld9040 *ctx = panel_to_ld9040(panel);
231 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_SET_DISPLAY_OFF);
232 ld9040_dcs_write_seq_static(ctx, MIPI_DCS_ENTER_SLEEP_MODE);
235 ld9040_clear_error(ctx);
237 return ld9040_power_off(ctx);
242 struct ld9040 *ctx = panel_to_ld9040(panel);
245 ret = ld9040_power_on(ctx);
249 ld9040_init(ctx);
251 ret = ld9040_clear_error(ctx);
267 struct ld9040 *ctx = panel_to_ld9040(panel);
276 drm_display_mode_from_videomode(&ctx->vm, mode);
277 mode->width_mm = ctx->width_mm;
278 mode->height_mm = ctx->height_mm;
296 static int ld9040_parse_dt(struct ld9040 *ctx)
298 struct device *dev = ctx->dev;
302 ret = of_get_videomode(np, &ctx->vm, 0);
306 of_property_read_u32(np, "power-on-delay", &ctx->power_on_delay);
307 of_property_read_u32(np, "reset-delay", &ctx->reset_delay);
308 of_property_read_u32(np, "panel-width-mm", &ctx->width_mm);
309 of_property_read_u32(np, "panel-height-mm", &ctx->height_mm);
316 struct ld9040 *ctx = bl_get_data(dev);
318 ctx->brightness = backlight_get_brightness(dev);
319 ld9040_brightness_set(ctx);
339 struct ld9040 *ctx;
342 ctx = devm_kzalloc(dev, sizeof(struct ld9040), GFP_KERNEL);
343 if (!ctx)
346 spi_set_drvdata(spi, ctx);
348 ctx->dev = dev;
349 ctx->brightness = ld9040_bl_props.brightness;
351 ret = ld9040_parse_dt(ctx);
355 ctx->supplies[0].supply = "vdd3";
356 ctx->supplies[1].supply = "vci";
357 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
358 ctx->supplies);
362 ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
363 if (IS_ERR(ctx->reset_gpio)) {
365 PTR_ERR(ctx->reset_gpio));
366 return PTR_ERR(ctx->reset_gpio);
376 drm_panel_init(&ctx->panel, dev, &ld9040_drm_funcs,
380 ctx, &ld9040_bl_ops,
385 drm_panel_add(&ctx->panel);
392 struct ld9040 *ctx = spi_get_drvdata(spi);
394 ld9040_power_off(ctx);
395 drm_panel_remove(&ctx->panel);