From patchwork Mon Jul 29 19:55:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 11064453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 110B91823 for ; Mon, 29 Jul 2019 19:56:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01AFF209CE for ; Mon, 29 Jul 2019 19:56:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9DA527FC0; Mon, 29 Jul 2019 19:56:02 +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.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 5B01F27FB0 for ; Mon, 29 Jul 2019 19:56:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED8826E1E2; Mon, 29 Jul 2019 19:55:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id DAC286E1D6 for ; Mon, 29 Jul 2019 19:55:48 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:57528 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1hsBkI-0003F7-Sq; Mon, 29 Jul 2019 21:55:46 +0200 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [RFC 2/4] drm/panel/ili9341: Rebase and some more Date: Mon, 29 Jul 2019 21:55:24 +0200 Message-Id: <20190729195526.13337-3-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190729195526.13337-1-noralf@tronnes.org> References: <20190729195526.13337-1-noralf@tronnes.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Rgiy6CkOvO1Tq7ifyR6f7FdQkuWs89+QMc4LPY4uXxg=; b=RJKfNbRpo0QDSS5dUTCWfQpQY4GeRoSVLQqXSsgXBysFrYJUfExXPUoNY9OnpHNR3mUMNHIKMp7kmS5Ps6unYe0ITX04tX0onJQwX16RxcrTkp6GGMZuUReLnJVYPGo9PzjHH3N90pYLZxJOdAtpZTnefJSKFGgrKZAMdyW+vRdw+F7mpbDaA0snrGzeQF0+NfwRzN4vzhVpQLKbZ9hwytlNk+YNbaQ0w1xIXBjHPHPTgKWWcPaKUwqJsBOoRpxaWzn93v/x6QrVXhQVCF1cKAjtyinFfoQCEnVP/hRG3+Tx23D/QDRFzuyFg8lkqp0wZRHhqhqUXAC4nZimsEaGng==; 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: daniel.vetter@ffwll.ch, josef@lusticky.cz, thierry.reding@gmail.com, laurent.pinchart@ideasonboard.com, sam@ravnborg.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Embed mipi_dbi in struct ili9341. Rebase on moved mipi-dbi, rename variable name. Add backlight_device to panel struct. mipi_dbi_hw_reset() already has a NULL check on the reset gpio. Prepare for more panels by reworking ili9341_config. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/panel/panel-ilitek-ili9341.c | 104 +++++++++---------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-ilitek-ili9341.c b/drivers/gpu/drm/panel/panel-ilitek-ili9341.c index 0c700b171025..a755f3e60111 100644 --- a/drivers/gpu/drm/panel/panel-ilitek-ili9341.c +++ b/drivers/gpu/drm/panel/panel-ilitek-ili9341.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include /* ILI9341 extended register set (Vendor Command Set) */ #define ILI9341_IFMODE 0xB0 // clock polarity @@ -42,17 +42,18 @@ /** * struct ili9341_config - the display specific configuration - * @width_mm: physical panel width [mm] - * @height_mm: physical panel height [mm] + * @funcs: Panel functions + * @mode: Display mode */ struct ili9341_config { - u32 width_mm; - u32 height_mm; + const struct drm_panel_funcs *funcs; + const struct drm_display_mode *mode; }; struct ili9341 { struct drm_panel panel; - struct mipi_dbi *mipi; + struct mipi_dbi dbi; + struct backlight_device *backlight; const struct ili9341_config *conf; }; @@ -63,47 +64,50 @@ static inline struct ili9341 *panel_to_ili9341(struct drm_panel *panel) static int ili9341_deinit(struct drm_panel *panel, struct ili9341 *ili) { - mipi_dbi_command(ili->mipi, MIPI_DCS_SET_DISPLAY_OFF); - mipi_dbi_command(ili->mipi, MIPI_DCS_ENTER_SLEEP_MODE); + struct mipi_dbi *dbi = &ili->dbi; + + mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_OFF); + mipi_dbi_command(dbi, MIPI_DCS_ENTER_SLEEP_MODE); msleep(5); return 0; } -static int ili9341_init(struct drm_panel *panel, struct ili9341 *ili) +static int dt024ctft_init(struct drm_panel *panel, struct ili9341 *ili) { - /* HW / SW Reset display and wait */ - if (ili->mipi->reset) - mipi_dbi_hw_reset(ili->mipi); + struct mipi_dbi *dbi = &ili->dbi; - mipi_dbi_command(ili->mipi, MIPI_DCS_SOFT_RESET); + /* HW / SW Reset display and wait */ + mipi_dbi_hw_reset(dbi); + + mipi_dbi_command(dbi, MIPI_DCS_SOFT_RESET); msleep(120); /* Polarity */ - mipi_dbi_command(ili->mipi, ILI9341_IFMODE, 0xC0); + mipi_dbi_command(dbi, ILI9341_IFMODE, 0xC0); /* Interface control */ - mipi_dbi_command(ili->mipi, ILI9341_IFCTL, 0x09, 0x01, 0x26); + mipi_dbi_command(dbi, ILI9341_IFCTL, 0x09, 0x01, 0x26); /* Pixel format */ - mipi_dbi_command(ili->mipi, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_18BIT << 4); + mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_18BIT << 4); /* Gamma */ - mipi_dbi_command(ili->mipi, MIPI_DCS_SET_GAMMA_CURVE, 0x01); - mipi_dbi_command(ili->mipi, ILI9341_PGAMCTRL, + mipi_dbi_command(dbi, MIPI_DCS_SET_GAMMA_CURVE, 0x01); + mipi_dbi_command(dbi, ILI9341_PGAMCTRL, 0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, 0xf1, 0x37, 0x07, 0x10, 0x03, 0x0e, 0x09, 0x00); - mipi_dbi_command(ili->mipi, ILI9341_NGAMCTRL, + mipi_dbi_command(dbi, ILI9341_NGAMCTRL, 0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, 0xc1, 0x48, 0x08, 0x0f, 0x0c, 0x31, 0x36, 0x0f); /* Rotation */ - mipi_dbi_command(ili->mipi, MIPI_DCS_SET_ADDRESS_MODE, ILI9341_MADCTL_MX); + mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, ILI9341_MADCTL_MX); /* Exit sleep mode */ - mipi_dbi_command(ili->mipi, MIPI_DCS_EXIT_SLEEP_MODE); + mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE); msleep(120); - mipi_dbi_command(ili->mipi, MIPI_DCS_SET_DISPLAY_ON); + mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON); return 0; } @@ -115,12 +119,12 @@ static int ili9341_unprepare(struct drm_panel *panel) return ili9341_deinit(panel, ili); } -static int ili9341_prepare(struct drm_panel *panel) +static int dt024ctft_prepare(struct drm_panel *panel) { struct ili9341 *ili = panel_to_ili9341(panel); int ret; - ret = ili9341_init(panel, ili); + ret = dt024ctft_init(panel, ili); if (ret < 0) ili9341_unprepare(panel); return ret; @@ -130,14 +134,14 @@ static int ili9341_enable(struct drm_panel *panel) { struct ili9341 *ili = panel_to_ili9341(panel); - return backlight_enable(ili->mipi->backlight); + return backlight_enable(ili->backlight); } static int ili9341_disable(struct drm_panel *panel) { struct ili9341 *ili = panel_to_ili9341(panel); - return backlight_disable(ili->mipi->backlight); + return backlight_disable(ili->backlight); } static const struct drm_display_mode prgb_240x320_mode = { @@ -154,7 +158,10 @@ static const struct drm_display_mode prgb_240x320_mode = { .vtotal = 320 + 4 + 2 + 2, .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC, - .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED + .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, + + .width_mm = 37, + .height_mm = 49, }; static int ili9341_get_modes(struct drm_panel *panel) @@ -163,7 +170,7 @@ static int ili9341_get_modes(struct drm_panel *panel) struct ili9341 *ili = panel_to_ili9341(panel); struct drm_display_mode *mode; - mode = drm_mode_duplicate(panel->drm, &prgb_240x320_mode); + mode = drm_mode_duplicate(panel->drm, ili->conf->mode); if (!mode) { DRM_DEV_ERROR(panel->drm->dev, "bad mode or failed to add mode\n"); return -ENOMEM; @@ -171,9 +178,6 @@ static int ili9341_get_modes(struct drm_panel *panel) drm_mode_set_name(mode); - mode->width_mm = ili->conf->width_mm; - mode->height_mm = ili->conf->height_mm; - connector->display_info.width_mm = mode->width_mm; connector->display_info.height_mm = mode->height_mm; connector->display_info.bus_flags |= DRM_BUS_FLAG_DE_HIGH | @@ -184,31 +188,32 @@ static int ili9341_get_modes(struct drm_panel *panel) return 1; /* Number of modes */ } -static const struct drm_panel_funcs ili9341_drm_funcs = { +static const struct drm_panel_funcs dt024ctft_drm_funcs = { .disable = ili9341_disable, .unprepare = ili9341_unprepare, - .prepare = ili9341_prepare, + .prepare = dt024ctft_prepare, .enable = ili9341_enable, .get_modes = ili9341_get_modes, }; +static const struct ili9341_config dt024ctft_data = { + .funcs = &dt024ctft_drm_funcs, + .mode = &prgb_240x320_mode, +}; + static int ili9341_probe(struct spi_device *spi) { struct device *dev = &spi->dev; struct ili9341 *ili; - struct mipi_dbi *mipi; + struct mipi_dbi *dbi; struct gpio_desc *dc_gpio; int ret; - mipi = devm_kzalloc(dev, sizeof(*mipi), GFP_KERNEL); - if (!mipi) - return -ENOMEM; - ili = devm_kzalloc(dev, sizeof(*ili), GFP_KERNEL); if (!ili) return -ENOMEM; - ili->mipi = mipi; + dbi = &ili->dbi; spi_set_drvdata(spi, ili); @@ -222,16 +227,16 @@ static int ili9341_probe(struct spi_device *spi) return -ENODEV; } - ili->mipi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(ili->mipi->reset)) { + dbi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(dbi->reset)) { DRM_DEV_ERROR(dev, "failed to get gpio 'reset'\n"); - return PTR_ERR(ili->mipi->reset); + return PTR_ERR(dbi->reset); } - ili->mipi->backlight = devm_of_find_backlight(dev); - if (IS_ERR(ili->mipi->backlight)) { + ili->backlight = devm_of_find_backlight(dev); + if (IS_ERR(ili->backlight)) { DRM_DEV_ERROR(dev, "failed to get backlight\n"); - return PTR_ERR(ili->mipi->backlight); + return PTR_ERR(ili->backlight); } dc_gpio = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW); @@ -240,7 +245,7 @@ static int ili9341_probe(struct spi_device *spi) return PTR_ERR(dc_gpio); } - ret = mipi_dbi_spi_init(spi, ili->mipi, dc_gpio); + ret = mipi_dbi_spi_init(spi, dbi, dc_gpio); if (ret) { DRM_DEV_ERROR(dev, "MIPI-DBI SPI setup failed\n"); return ret; @@ -248,7 +253,7 @@ static int ili9341_probe(struct spi_device *spi) drm_panel_init(&ili->panel); ili->panel.dev = dev; - ili->panel.funcs = &ili9341_drm_funcs; + ili->panel.funcs = ili->conf->funcs; return drm_panel_add(&ili->panel); } @@ -265,11 +270,6 @@ static int ili9341_remove(struct spi_device *spi) return 0; } -static const struct ili9341_config dt024ctft_data = { - .width_mm = 37, - .height_mm = 49, -}; - static const struct of_device_id ili9341_of_match[] = { { .compatible = "displaytech,dt024ctft", .data = &dt024ctft_data }, { /* sentinel */ }