Add support for Innolux TV123WAM 12.3" panel which
is an eDP panel.

Signed-off-by: Sandeep Panda <spa...@codeaurora.org>
---
 drivers/gpu/drm/panel/panel-innolux-tv123wam.c | 293 +++++++++++++++++++++++++
 1 file changed, 293 insertions(+)
 create mode 100644 drivers/gpu/drm/panel/panel-innolux-tv123wam.c

diff --git a/drivers/gpu/drm/panel/panel-innolux-tv123wam.c 
b/drivers/gpu/drm/panel/panel-innolux-tv123wam.c
new file mode 100644
index 0000000..5632b02
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-innolux-tv123wam.c
@@ -0,0 +1,293 @@
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <drm/drmP.h>
+#include <drm/drm_panel.h>
+#include <linux/gpio/consumer.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+
+struct innolux_edp_2k_panel_desc {
+       const struct drm_display_mode *modes;
+       unsigned int num_modes;
+       u32 bpc;
+       u32 bus_flags;
+};
+
+struct innolux_edp_2k_panel {
+       struct drm_panel base;
+       bool enabled;
+       bool prepared;
+       const struct innolux_edp_2k_panel_desc *desc;
+       struct regulator *supply;
+       struct gpio_desc *enable_gpio;
+       struct backlight_device *backlight;
+};
+
+static const struct drm_display_mode innolux_edp_2k_mode = {
+       .clock = 206016,
+       .hdisplay = 2160,
+       .hsync_start = 2160 + 48,
+       .hsync_end = 2160 + 48 + 32,
+       .htotal = 2160 + 48 + 32 + 80,
+       .vdisplay = 1440,
+       .vsync_start = 1440 + 3,
+       .vsync_end = 1440 + 3 + 10,
+       .vtotal = 1440 + 3 + 10 + 27,
+       .vrefresh = 60,
+       .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
+};
+
+static const struct innolux_edp_2k_panel_desc innolux_edp_2k = {
+       .modes = &innolux_edp_2k_mode,
+       .num_modes = 1,
+       .bpc = 8,
+       .bus_flags = DRM_BUS_FLAG_PIXDATA_POSEDGE,
+};
+
+static const struct of_device_id platform_of_match[] = {
+       {
+               .compatible = "innolux, edp_2k_panel",
+               .data = &innolux_edp_2k,
+       },
+};
+
+static inline struct innolux_edp_2k_panel *
+to_innolux_edp_2k_panel(struct drm_panel *panel)
+{
+       return container_of(panel, struct innolux_edp_2k_panel, base);
+}
+
+static int innolux_edp_2k_panel_disable(struct drm_panel *panel)
+{
+       struct innolux_edp_2k_panel *pdata = to_innolux_edp_2k_panel(panel);
+
+       if (!pdata->enabled)
+               return 0;
+
+       if (pdata->backlight) {
+               pdata->backlight->props.power = FB_BLANK_POWERDOWN;
+               pdata->backlight->props.state |= BL_CORE_FBBLANK;
+               backlight_update_status(pdata->backlight);
+       }
+
+       pdata->enabled = false;
+
+       return 0;
+}
+
+static int innolux_edp_2k_panel_unprepare(struct drm_panel *panel)
+{
+       struct innolux_edp_2k_panel *pdata = to_innolux_edp_2k_panel(panel);
+
+       if (!pdata->prepared)
+               return 0;
+
+       if (pdata->enable_gpio)
+               gpiod_set_value_cansleep(pdata->enable_gpio, 0);
+
+       regulator_disable(pdata->supply);
+
+       pdata->prepared = false;
+
+       return 0;
+}
+
+static int innolux_edp_2k_panel_prepare(struct drm_panel *panel)
+{
+       struct innolux_edp_2k_panel *pdata = to_innolux_edp_2k_panel(panel);
+       int ret;
+
+       if (pdata->prepared)
+               return 0;
+
+       ret = regulator_enable(pdata->supply);
+       if (ret < 0) {
+               dev_err(panel->dev, "failed to enable supply: %d\n", ret);
+               return ret;
+       }
+
+       if (pdata->enable_gpio)
+               gpiod_set_value_cansleep(pdata->enable_gpio, 1);
+
+       pdata->prepared = true;
+
+       return 0;
+}
+
+static int innolux_edp_2k_panel_enable(struct drm_panel *panel)
+{
+       struct innolux_edp_2k_panel *pdata = to_innolux_edp_2k_panel(panel);
+
+       if (pdata->enabled)
+               return 0;
+
+       if (pdata->backlight) {
+               pdata->backlight->props.state &= ~BL_CORE_FBBLANK;
+               pdata->backlight->props.power = FB_BLANK_UNBLANK;
+               backlight_update_status(pdata->backlight);
+       }
+
+       pdata->enabled = true;
+
+       return 0;
+}
+
+static int innolux_edp_2k_panel_get_modes(struct drm_panel *panel)
+{
+       struct innolux_edp_2k_panel *pdata = to_innolux_edp_2k_panel(panel);
+       struct drm_connector *connector = pdata->base.connector;
+       struct drm_device *drm = pdata->base.drm;
+       struct drm_display_mode *mode;
+       unsigned int i, num = 0;
+
+       if (!pdata->desc || !connector || !drm)
+               return 0;
+
+       for (i = 0; i < pdata->desc->num_modes; i++) {
+               const struct drm_display_mode *m = &pdata->desc->modes[i];
+
+               mode = drm_mode_duplicate(drm, m);
+               if (!mode) {
+                       dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
+                               m->hdisplay, m->vdisplay, m->vrefresh);
+                       continue;
+               }
+
+               mode->type |= DRM_MODE_TYPE_DRIVER;
+
+               if (pdata->desc->num_modes == 1)
+                       mode->type |= DRM_MODE_TYPE_PREFERRED;
+
+               drm_mode_set_name(mode);
+
+               drm_mode_probed_add(connector, mode);
+               num++;
+       }
+
+       connector->display_info.bpc = pdata->desc->bpc;
+       connector->display_info.bus_flags = pdata->desc->bus_flags;
+
+       return num;
+}
+
+static const struct drm_panel_funcs innolux_edp_2k_panel_funcs = {
+       .disable = innolux_edp_2k_panel_disable,
+       .unprepare = innolux_edp_2k_panel_unprepare,
+       .prepare = innolux_edp_2k_panel_prepare,
+       .enable = innolux_edp_2k_panel_enable,
+       .get_modes = innolux_edp_2k_panel_get_modes,
+};
+
+static int innolux_edp_2k_panel_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       const struct of_device_id *id;
+       struct device_node *backlight;
+       struct innolux_edp_2k_panel *pdata;
+       int ret;
+
+       id = of_match_node(platform_of_match, pdev->dev.of_node);
+       if (!id)
+               return -ENODEV;
+
+       pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata)
+               return -ENOMEM;
+
+       pdata->enabled = false;
+       pdata->prepared = false;
+       pdata->desc = id->data;
+
+       pdata->supply = devm_regulator_get(dev, "power");
+       if (IS_ERR(pdata->supply))
+               return PTR_ERR(pdata->supply);
+
+       pdata->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
+       if (IS_ERR(pdata->enable_gpio))
+               return PTR_ERR(pdata->enable_gpio);
+
+       backlight = of_parse_phandle(dev->of_node, "backlight", 0);
+       if (backlight) {
+               pdata->backlight = of_find_backlight_by_node(backlight);
+               of_node_put(backlight);
+
+               if (!pdata->backlight)
+                       return -EPROBE_DEFER;
+       }
+
+       drm_panel_init(&pdata->base);
+       pdata->base.dev = dev;
+       pdata->base.funcs = &innolux_edp_2k_panel_funcs;
+
+       ret = drm_panel_add(&pdata->base);
+       if (ret < 0)
+               goto free_backlight;
+
+       dev_set_drvdata(dev, pdata);
+
+       return 0;
+
+free_backlight:
+       if (pdata->backlight)
+               put_device(&pdata->backlight->dev);
+
+       return ret;
+}
+
+static int innolux_edp_2k_panel_remove(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct innolux_edp_2k_panel *pdata = dev_get_drvdata(dev);
+
+       drm_panel_detach(&pdata->base);
+       drm_panel_remove(&pdata->base);
+
+       innolux_edp_2k_panel_disable(&pdata->base);
+       innolux_edp_2k_panel_unprepare(&pdata->base);
+
+       if (pdata->backlight)
+               put_device(&pdata->backlight->dev);
+
+       return 0;
+}
+
+static struct platform_driver innolux_edp_2k_panel_driver = {
+       .driver = {
+               .name = "innolux-2k-edp-panel",
+               .of_match_table = platform_of_match,
+       },
+       .probe = innolux_edp_2k_panel_probe,
+       .remove = innolux_edp_2k_panel_remove,
+};
+
+static int __init innolux_edp_2k_panel_init(void)
+{
+       int ret;
+
+       ret = platform_driver_register(&innolux_edp_2k_panel_driver);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+module_init(innolux_edp_2k_panel_init);
+
+static void __exit innolux_edp_2k_panel_exit(void)
+{
+       platform_driver_unregister(&innolux_edp_2k_panel_driver);
+}
+module_exit(innolux_edp_2k_panel_exit);
+
+MODULE_DESCRIPTION("Innolux 2k eDP panel driver");
+MODULE_LICENSE("GPL");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

_______________________________________________
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno

Reply via email to