From patchwork Thu Apr 19 17:56:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Panda X-Patchwork-Id: 10351951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 53E4D60365 for ; Fri, 20 Apr 2018 07:33:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4110A2823D for ; Fri, 20 Apr 2018 07:33:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35EC92869A; Fri, 20 Apr 2018 07:33:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A6282823D for ; Fri, 20 Apr 2018 07:33:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 939056E22F; Fri, 20 Apr 2018 07:32:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by gabe.freedesktop.org (Postfix) with ESMTPS id 90F1F6E65E; Thu, 19 Apr 2018 17:56:49 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6907C60C55; Thu, 19 Apr 2018 17:56:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524160609; bh=f88WSYFzm0WvfPnDC8lRjUzWaiGPHgIM0+0wYItv0bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FAiigTeDM2u2ODGsKHhwofk5RtQ2Pmkuzx6N86rqxQgElG/w8RFoDPIlIly4lrruO sJxcN/AnF87pN3a1seLVP1TKztrWUrFPYmMC6H7FoAsUJqBeJhspbSbpge+ezN/6Oj fzJOkz/1riq9ojzV84/sPMu3EoK4KuaTfdet47Zo= Received: from spanda-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: spanda@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2061360D81; Thu, 19 Apr 2018 17:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1524160608; bh=f88WSYFzm0WvfPnDC8lRjUzWaiGPHgIM0+0wYItv0bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dv6l26SCc0BC18AfPJkvFkqSKWA7BtBEB1F0G3CVYU61x5tCxCsp5DmrDBc5oLJlf ZAJmprTVvqdgiThXfuQtu5J2A5raswEXPASB81bOhsk43Wv68nkMlqL7SgBEP0wlzu CI5PSFuV3ibHRqvCu/ZWbmDiek3VISAUU30jARg4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2061360D81 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=spanda@codeaurora.org From: Sandeep Panda To: dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, devicetree@vger.kernel.org Subject: [[RFC]DPU PATCH 3/4] drm/panel: add Innolux TV123WAM eDP panel driver Date: Thu, 19 Apr 2018 23:26:07 +0530 Message-Id: <1524160568-27583-4-git-send-email-spanda@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524160568-27583-1-git-send-email-spanda@codeaurora.org> References: <1524160568-27583-1-git-send-email-spanda@codeaurora.org> X-Mailman-Approved-At: Fri, 20 Apr 2018 07:31:50 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ryadav@codeaurora.org, Sandeep Panda , abhinavk@codeaurora.org, hoegsberg@chromium.org, chandanu@codeaurora.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add support for Innolux TV123WAM 12.3" panel which is an eDP panel. Signed-off-by: Sandeep Panda --- 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 +#include +#include +#include +#include + +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");