Commit 7ad4e463 authored by Lin Huang's avatar Lin Huang Committed by Thierry Reding

drm/panel: p079zca: Refactor panel driver to support multiple panels

Refactor Innolux P079ZCA panel driver, let it support multi panels from
Innolux that share similar power sequences.

Panels may require different power supplies so use regulator bulk
interfaces and define per panel supply-names.

Changes in v2:
- Change regulator property name to meet the panel datasheet
Changes in v3:
- this patch only refactor P079ZCA panel to support multi panel,
  support P097PFG panel in another patch
Changes in v4:
- Modify the patch which suggest by Thierry
Changes in v5:
- use regulator_bulk to handle different supply number
Signed-off-by: default avatarLin Huang <hl@rock-chips.com>
Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180702102721.3546-2-heiko@sntech.de
parent 3d5664f9
...@@ -20,12 +20,29 @@ ...@@ -20,12 +20,29 @@
#include <video/mipi_display.h> #include <video/mipi_display.h>
struct panel_desc {
const struct drm_display_mode *mode;
unsigned int bpc;
struct {
unsigned int width;
unsigned int height;
} size;
unsigned long flags;
enum mipi_dsi_pixel_format format;
unsigned int lanes;
const char * const *supply_names;
unsigned int num_supplies;
};
struct innolux_panel { struct innolux_panel {
struct drm_panel base; struct drm_panel base;
struct mipi_dsi_device *link; struct mipi_dsi_device *link;
const struct panel_desc *desc;
struct backlight_device *backlight; struct backlight_device *backlight;
struct regulator *supply; struct regulator_bulk_data *supplies;
unsigned int num_supplies;
struct gpio_desc *enable_gpio; struct gpio_desc *enable_gpio;
bool prepared; bool prepared;
...@@ -77,7 +94,8 @@ static int innolux_panel_unprepare(struct drm_panel *panel) ...@@ -77,7 +94,8 @@ static int innolux_panel_unprepare(struct drm_panel *panel)
/* T8: 80ms - 1000ms */ /* T8: 80ms - 1000ms */
msleep(80); msleep(80);
err = regulator_disable(innolux->supply); err = regulator_bulk_disable(innolux->desc->num_supplies,
innolux->supplies);
if (err < 0) if (err < 0)
return err; return err;
...@@ -89,14 +107,15 @@ static int innolux_panel_unprepare(struct drm_panel *panel) ...@@ -89,14 +107,15 @@ static int innolux_panel_unprepare(struct drm_panel *panel)
static int innolux_panel_prepare(struct drm_panel *panel) static int innolux_panel_prepare(struct drm_panel *panel)
{ {
struct innolux_panel *innolux = to_innolux_panel(panel); struct innolux_panel *innolux = to_innolux_panel(panel);
int err, regulator_err; int err;
if (innolux->prepared) if (innolux->prepared)
return 0; return 0;
gpiod_set_value_cansleep(innolux->enable_gpio, 0); gpiod_set_value_cansleep(innolux->enable_gpio, 0);
err = regulator_enable(innolux->supply); err = regulator_bulk_enable(innolux->desc->num_supplies,
innolux->supplies);
if (err < 0) if (err < 0)
return err; return err;
...@@ -133,12 +152,9 @@ static int innolux_panel_prepare(struct drm_panel *panel) ...@@ -133,12 +152,9 @@ static int innolux_panel_prepare(struct drm_panel *panel)
return 0; return 0;
poweroff: poweroff:
regulator_err = regulator_disable(innolux->supply);
if (regulator_err)
DRM_DEV_ERROR(panel->dev, "failed to disable regulator: %d\n",
regulator_err);
gpiod_set_value_cansleep(innolux->enable_gpio, 0); gpiod_set_value_cansleep(innolux->enable_gpio, 0);
regulator_bulk_disable(innolux->desc->num_supplies, innolux->supplies);
return err; return err;
} }
...@@ -162,7 +178,11 @@ static int innolux_panel_enable(struct drm_panel *panel) ...@@ -162,7 +178,11 @@ static int innolux_panel_enable(struct drm_panel *panel)
return 0; return 0;
} }
static const struct drm_display_mode default_mode = { static const char * const innolux_p079zca_supply_names[] = {
"power",
};
static const struct drm_display_mode innolux_p079zca_mode = {
.clock = 56900, .clock = 56900,
.hdisplay = 768, .hdisplay = 768,
.hsync_start = 768 + 40, .hsync_start = 768 + 40,
...@@ -175,15 +195,31 @@ static const struct drm_display_mode default_mode = { ...@@ -175,15 +195,31 @@ static const struct drm_display_mode default_mode = {
.vrefresh = 60, .vrefresh = 60,
}; };
static const struct panel_desc innolux_p079zca_panel_desc = {
.mode = &innolux_p079zca_mode,
.bpc = 8,
.size = {
.width = 120,
.height = 160,
},
.flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
MIPI_DSI_MODE_LPM,
.format = MIPI_DSI_FMT_RGB888,
.lanes = 4,
.supply_names = innolux_p079zca_supply_names,
.num_supplies = ARRAY_SIZE(innolux_p079zca_supply_names),
};
static int innolux_panel_get_modes(struct drm_panel *panel) static int innolux_panel_get_modes(struct drm_panel *panel)
{ {
struct innolux_panel *innolux = to_innolux_panel(panel);
const struct drm_display_mode *m = innolux->desc->mode;
struct drm_display_mode *mode; struct drm_display_mode *mode;
mode = drm_mode_duplicate(panel->drm, &default_mode); mode = drm_mode_duplicate(panel->drm, m);
if (!mode) { if (!mode) {
DRM_DEV_ERROR(panel->drm->dev, "failed to add mode %ux%ux@%u\n", DRM_DEV_ERROR(panel->drm->dev, "failed to add mode %ux%ux@%u\n",
default_mode.hdisplay, default_mode.vdisplay, m->hdisplay, m->vdisplay, m->vrefresh);
default_mode.vrefresh);
return -ENOMEM; return -ENOMEM;
} }
...@@ -191,9 +227,11 @@ static int innolux_panel_get_modes(struct drm_panel *panel) ...@@ -191,9 +227,11 @@ static int innolux_panel_get_modes(struct drm_panel *panel)
drm_mode_probed_add(panel->connector, mode); drm_mode_probed_add(panel->connector, mode);
panel->connector->display_info.width_mm = 120; panel->connector->display_info.width_mm =
panel->connector->display_info.height_mm = 160; innolux->desc->size.width;
panel->connector->display_info.bpc = 8; panel->connector->display_info.height_mm =
innolux->desc->size.height;
panel->connector->display_info.bpc = innolux->desc->bpc;
return 1; return 1;
} }
...@@ -207,19 +245,39 @@ static const struct drm_panel_funcs innolux_panel_funcs = { ...@@ -207,19 +245,39 @@ static const struct drm_panel_funcs innolux_panel_funcs = {
}; };
static const struct of_device_id innolux_of_match[] = { static const struct of_device_id innolux_of_match[] = {
{ .compatible = "innolux,p079zca", }, { .compatible = "innolux,p079zca",
.data = &innolux_p079zca_panel_desc
},
{ } { }
}; };
MODULE_DEVICE_TABLE(of, innolux_of_match); MODULE_DEVICE_TABLE(of, innolux_of_match);
static int innolux_panel_add(struct innolux_panel *innolux) static int innolux_panel_add(struct mipi_dsi_device *dsi,
const struct panel_desc *desc)
{ {
struct device *dev = &innolux->link->dev; struct innolux_panel *innolux;
int err; struct device *dev = &dsi->dev;
int err, i;
innolux = devm_kzalloc(dev, sizeof(*innolux), GFP_KERNEL);
if (!innolux)
return -ENOMEM;
innolux->desc = desc;
innolux->supplies = devm_kcalloc(dev, desc->num_supplies,
sizeof(*innolux->supplies),
GFP_KERNEL);
if (!innolux->supplies)
return -ENOMEM;
innolux->supply = devm_regulator_get(dev, "power"); for (i = 0; i < desc->num_supplies; i++)
if (IS_ERR(innolux->supply)) innolux->supplies[i].supply = desc->supply_names[i];
return PTR_ERR(innolux->supply);
err = devm_regulator_bulk_get(dev, desc->num_supplies,
innolux->supplies);
if (err < 0)
return err;
innolux->enable_gpio = devm_gpiod_get_optional(dev, "enable", innolux->enable_gpio = devm_gpiod_get_optional(dev, "enable",
GPIOD_OUT_HIGH); GPIOD_OUT_HIGH);
...@@ -230,15 +288,21 @@ static int innolux_panel_add(struct innolux_panel *innolux) ...@@ -230,15 +288,21 @@ static int innolux_panel_add(struct innolux_panel *innolux)
} }
innolux->backlight = devm_of_find_backlight(dev); innolux->backlight = devm_of_find_backlight(dev);
if (IS_ERR(innolux->backlight)) if (IS_ERR(innolux->backlight))
return PTR_ERR(innolux->backlight); return PTR_ERR(innolux->backlight);
drm_panel_init(&innolux->base); drm_panel_init(&innolux->base);
innolux->base.funcs = &innolux_panel_funcs; innolux->base.funcs = &innolux_panel_funcs;
innolux->base.dev = &innolux->link->dev; innolux->base.dev = dev;
err = drm_panel_add(&innolux->base);
if (err < 0)
return err;
mipi_dsi_set_drvdata(dsi, innolux);
innolux->link = dsi;
return drm_panel_add(&innolux->base); return 0;
} }
static void innolux_panel_del(struct innolux_panel *innolux) static void innolux_panel_del(struct innolux_panel *innolux)
...@@ -249,28 +313,24 @@ static void innolux_panel_del(struct innolux_panel *innolux) ...@@ -249,28 +313,24 @@ static void innolux_panel_del(struct innolux_panel *innolux)
static int innolux_panel_probe(struct mipi_dsi_device *dsi) static int innolux_panel_probe(struct mipi_dsi_device *dsi)
{ {
struct innolux_panel *innolux; const struct panel_desc *desc;
const struct of_device_id *id;
int err; int err;
dsi->lanes = 4; id = of_match_node(innolux_of_match, dsi->dev.of_node);
dsi->format = MIPI_DSI_FMT_RGB888; if (!id)
dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | return -ENODEV;
MIPI_DSI_MODE_LPM;
innolux = devm_kzalloc(&dsi->dev, sizeof(*innolux), GFP_KERNEL); desc = id->data;
if (!innolux) dsi->mode_flags = desc->flags;
return -ENOMEM; dsi->format = desc->format;
dsi->lanes = desc->lanes;
mipi_dsi_set_drvdata(dsi, innolux); err = innolux_panel_add(dsi, desc);
innolux->link = dsi;
err = innolux_panel_add(innolux);
if (err < 0) if (err < 0)
return err; return err;
err = mipi_dsi_attach(dsi); return mipi_dsi_attach(dsi);
return err;
} }
static int innolux_panel_remove(struct mipi_dsi_device *dsi) static int innolux_panel_remove(struct mipi_dsi_device *dsi)
...@@ -317,5 +377,6 @@ static struct mipi_dsi_driver innolux_panel_driver = { ...@@ -317,5 +377,6 @@ static struct mipi_dsi_driver innolux_panel_driver = {
module_mipi_dsi_driver(innolux_panel_driver); module_mipi_dsi_driver(innolux_panel_driver);
MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
MODULE_AUTHOR("Lin Huang <hl@rock-chips.com>");
MODULE_DESCRIPTION("Innolux P079ZCA panel driver"); MODULE_DESCRIPTION("Innolux P079ZCA panel driver");
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment