@vinaysimha
@architt
attached panel driver code
struct hx8363a {
struct device *dev;
struct drm_panel panel;
struct gpio_desc *reset_gpio;
bool prepared;
bool enabled;
};
static const struct drm_display_mode default_mode = {
.clock = 26400,
.hdisplay = 480,
.hsync_start = 480 + 12,
.hsync_end = 480 + 12 + 12,
.htotal = 480 + 12 + 12 + 12,
.vdisplay = 800,
.vsync_start = 800 + 4,
.vsync_end = 800 + 4 + 4,
.vtotal = 800 + 4 + 4 + 4,
.vrefresh = 50,
.flags = 0,
.width_mm = 56,
.height_mm = 93,
};
static inline struct hx8363a *panel_to_hx8363a(struct drm_panel *panel)
{
return container_of(panel, struct hx8363a, panel);
}
static void hx8363a_dcs_write_buf(struct hx8363a *ctx, const void *data,
size_t len)
{
struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
int err;
err = mipi_dsi_dcs_write_buffer(dsi, data, len);
if (err < 0)
DRM_ERROR_RATELIMITED("MIPI DSI DCS write buffer failed: %d\n",
err);
}
#define dcs_write_seq(ctx, seq…)
({
static const u8 d[] = { seq };
hx8363a_dcs_write_buf(ctx, d, ARRAY_SIZE(d));
})
static void hx8363a_init_sequence(struct hx8363a *ctx)
{
printk(“hx8363a: %s\n”,func);
dcs_write_seq(ctx, SETEXTC, 0xff, 0x83, 0x63); //0xb9
dcs_write_seq(ctx, SETPOWER, 0x81, 0x30, 0x08, 0x36, 0x01,
0x13, 0x10, 0x10, 0x35, 0x3D, 0x1A, 0x1A);
//0xb1
dcs_write_seq(ctx, SETCYC, 0x01, 0x12, 0x72, 0x12, 0x06,
0x03, 0x54, 0x03, 0x4E); //0xb4
dcs_write_seq(ctx, SETVCOM, 0x56);
dcs_write_seq(ctx, SETPANEL, 0x02); //0xcc
dcs_write_seq(ctx, SETGAMMA, 0x01, 0x07, 0x4c, 0xb0, 0x36,
0x3F, 0x06, 0x49, 0x51, 0x96, 0x18, 0xd8,
0x18, 0x50, 0x13, 0x01, 0x07, 0x4c, 0xb0,
0x36, 0x3f,0x06, 0x49, 0x51, 0x96, 0x18,
0xd8, 0x18, 0x50, 0x13); //0xe0
dcs_write_seq(ctx, SETMIPI, 0x00, 0xa0, 0xc6, 0x00, 0x0a,
0x00, 0x10, 0x30, 0x6f, 0x02, 0x11, 0x18,
0x40); //0xba
dcs_write_seq(ctx, 0x3A, 0x77);
}
static int hx8363a_disable(struct drm_panel *panel)
{
struct hx8363a *ctx = panel_to_hx8363a(panel);
printk(“hx8363a: %s\n”,func);
if (!ctx->enabled)
return 0;
ctx->enabled = false;
return 0;
}
static int hx8363a_unprepare(struct drm_panel *panel)
{
struct hx8363a *ctx = panel_to_hx8363a(panel);
struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
int ret;
printk(“hx8363a: %s\n”,func);
if (!ctx->prepared)
return 0;
ret = mipi_dsi_dcs_set_display_off(dsi);
if (ret)
DRM_WARN("failed to set display off: %d\n", ret);
ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
if (ret)
DRM_WARN("failed to enter sleep mode: %d\n", ret);
msleep(120);
if (ctx->reset_gpio) {
gpiod_set_value_cansleep(ctx->reset_gpio, 1);
msleep(20);
}
ctx->prepared = false;
return 0;
}
static int hx8363a_prepare(struct drm_panel *panel)
{
struct hx8363a *ctx = panel_to_hx8363a(panel);
struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
int ret;
printk(“hx8363a: %s\n”,func);
if (ctx->prepared)
return 0;
if (ctx->reset_gpio) {
gpiod_set_value_cansleep(ctx->reset_gpio, 1);
msleep(20);
gpiod_set_value_cansleep(ctx->reset_gpio, 0);
msleep(100);
}
ret = mipi_dsi_set_maximum_return_packet_size(dsi, 4);
if (ret < 0)
printk("error %d setting maximum return packet\n",
ret);
hx8363a_init_sequence(ctx);
ret = mipi_dsi_dcs_set_column_address(dsi, 0, 479);
if (ret < 0)
printk("%s failed: %d\n", __func__, ret);
ret = mipi_dsi_dcs_set_page_address(dsi, 0, 799);
if (ret < 0)
printk("%s failed: %d\n", __func__, ret);
dcs_write_seq(ctx, WRCABC, 0x03);
dcs_write_seq(ctx, WRCTRLD, 0xff);
ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
if (ret)
return ret;
msleep(125);
ret = mipi_dsi_dcs_set_display_on(dsi);
if (ret)
return ret;
msleep(20);
ctx->prepared = true;
return 0;
}
static int hx8363a_enable(struct drm_panel *panel)
{
struct hx8363a *ctx = panel_to_hx8363a(panel);
printk(“hx8363a: %s\n”,func);
if (ctx->enabled)
return 0;
ctx->enabled = true;
return 0;
}
static int hx8363a_get_modes(struct drm_panel *panel)
{
struct drm_display_mode *mode;
printk(“hx8363a: %s\n”,func);
mode = drm_mode_duplicate(panel->drm, &default_mode);
if (!mode) {
DRM_ERROR("failed to add mode %ux%ux@%u\n",
default_mode.hdisplay, default_mode.vdisplay,
default_mode.vrefresh);
return -ENOMEM;
}
drm_mode_set_name(mode);
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
drm_mode_probed_add(panel->connector, mode);
panel->connector->display_info.width_mm = mode->width_mm;
panel->connector->display_info.height_mm = mode->height_mm;
return 1;
}
static const struct drm_panel_funcs hx8363a_drm_funcs = {
.disable = hx8363a_disable,
.unprepare = hx8363a_unprepare,
.prepare = hx8363a_prepare,
.enable = hx8363a_enable,
.get_modes = hx8363a_get_modes,
};
static int hx8363a_probe(struct mipi_dsi_device *dsi)
{
struct device *dev = &dsi->dev;
struct hx8363a *ctx;
int ret;
printk(“hx8363a: %s\n”,func);
ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
ctx->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(ctx->reset_gpio)) {
ret = PTR_ERR(ctx->reset_gpio);
dev_err(dev, "cannot get reset GPIO: %d\n", ret);
return ret;
}
mipi_dsi_set_drvdata(dsi, ctx);
ctx->dev = dev;
dsi->lanes = 2;
dsi->format = MIPI_DSI_FMT_RGB888;
dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
MIPI_DSI_MODE_LPM;
drm_panel_init(&ctx->panel);
ctx->panel.dev = dev;
ctx->panel.funcs = &hx8363a_drm_funcs;
drm_panel_add(&ctx->panel);
ret = mipi_dsi_attach(dsi);
if (ret < 0) {
dev_err(dev, "mipi_dsi_attach() failed: %d\n", ret);
drm_panel_remove(&ctx->panel);
return ret;
}
return 0;
}
static int hx8363a_remove(struct mipi_dsi_device *dsi)
{
struct hx8363a *ctx = mipi_dsi_get_drvdata(dsi);
printk(“hx8363a: %s\n”,func);
mipi_dsi_detach(dsi);
drm_panel_remove(&ctx->panel);
return 0;
}
static const struct of_device_id himax_hx8363a_of_match[] = {
{ .compatible = “himax,hx8363a” },
{ }
};
MODULE_DEVICE_TABLE(of, himax_hx8363a_of_match);
static struct mipi_dsi_driver himax_hx8363a_driver = {
.probe = hx8363a_probe,
.remove = hx8363a_remove,
.driver = {
.name = “panel-himax-hx8363a”,
.of_match_table = himax_hx8363a_of_match,
},
};
module_mipi_dsi_driver(himax_hx8363a_driver);
please let me know if anything wrong in the code