Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2923247ybz; Mon, 27 Apr 2020 07:03:03 -0700 (PDT) X-Google-Smtp-Source: APiQypJcdLZJt3/RiUy9d5Hugpae8uga3khSVbvXDp/X02H5+St+YBrpoXYslNUZFX9wBpVJ2R7Y X-Received: by 2002:a17:906:1387:: with SMTP id f7mr19152621ejc.333.1587996183568; Mon, 27 Apr 2020 07:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587996183; cv=none; d=google.com; s=arc-20160816; b=p3XkjIIBKG3yNpA3qop1nhBI5rfE37gkyd8HtiFzmw50qmiGfX9Jguj0ELd9PyGs/8 MCQ+dlINhLV4IscN5w2tWxM697jZZL5GY7TwWR1C63NAEaNuB7VdTeS53wedVfyAMXGp JSD5/BUPuhHGfyUfs78ILjb6uXV8XFzkfUwPHYN4wHyI5FCzC+w9mfg8bZjmBwk5/6wz b/dU61kM4Ekog7ARwOI2Q/lHfM0wy9sqTROpKtiLbygicEtxcXxgkh6Jhiqt27n+Hw8P MSxZ3AyomXzUh0iGWzAy7BUAnxsLIChgrDhpxjoNRlPBF10EW0vqkEKHjY6O+QnRvnZB AY+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=mAejBM0UQ+JAKH+J4ue/w3q0hFHD/gp49Td2iDPYEB8=; b=H7zOeW6ljCWFfCQBc7ieZxnxA8/bwm5PeIQdR/b4WU4J5gbXyXIktu3PLrIJB5rXWu fsF37ZXlfP6Bu9lYSLbrUqN2NPiXlYQFK8d0VJSdZ5QETAgEr016vew71aF5hyTim5fZ Aw0EAczi8tEgCa7vRTWp0O1u5VQW/BFR53BwrbcCHABjjRj5svmhZJqL61dBFk6l25DZ b78xlU1lHQSG3LDiSXAGscPVOFF0yPOnXHmkq78w7IZnOLeRlQt9246ExjXWne5Bz7vo cSwto7zXN7OPZt/wiwpAdRae4ob66LNDPxxbkaxk+WzqImY5Phgeb3Mp/PNBIWwxHEun 5zdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=QV8TO4a2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l22si8976677ejg.362.2020.04.27.07.02.37; Mon, 27 Apr 2020 07:03:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@synopsys.com header.s=mail header.b=QV8TO4a2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=synopsys.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727946AbgD0OA4 (ORCPT + 99 others); Mon, 27 Apr 2020 10:00:56 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:46536 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727814AbgD0OAt (ORCPT ); Mon, 27 Apr 2020 10:00:49 -0400 Received: from mailhost.synopsys.com (mdc-mailhost2.synopsys.com [10.225.0.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 7F010C0341; Mon, 27 Apr 2020 14:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1587996048; bh=UCMLWfN5C9w1mGSx3E4j3bVLT7LwXe2DGiVPSwkAs/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=QV8TO4a2U2ao0BqiDYqgQTdTuFU4iNU5kNWrUgOptD6OLmmAohE0MZ2OVkdj9Uwss NdAN5fwUUyGDw9nh8cqyrRmqJ+ZK3XFdwsZtKS2zvtYgIWcJc+0zGKyXsrYQ3NjfE4 6zLg2ljAJmkt62DrQVT15SMG70AbEEXVPnvV7u5RSVGVmsQCsEwO+AMKt5gtHmsSGf wPm3oMNOvtOTWV45uz8jEcVFmve7aNBpfxt5WeNvKOkOaZxrX/Cy1YD5Wa/OqIGqwV 40pkIfW+d5UtrO1qXgjgm5TFE6BHtRLgw244JuMqcCuL3K+EOvfy3vB5WDUwH6jX8M j7IuK9e8aEywg== Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by mailhost.synopsys.com (Postfix) with ESMTP id E9D2FA0063; Mon, 27 Apr 2020 14:00:44 +0000 (UTC) From: Angelo Ribeiro To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Angelo Ribeiro , Maarten Lankhorst , Maxime Ripard , David Airlie , Daniel Vetter , Sam Ravnborg , Gustavo Pimentel , Joao Pinto Subject: [PATCH v3 2/4] drm: ipk: Add DRM driver for DesignWare IPK DSI Date: Mon, 27 Apr 2020 16:00:34 +0200 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for Synopsys DesignWare VPG (Video Pattern Generator) and DRM driver for Synopsys DesignWare DSI Host IPK solution. This patch has to be applied on top of Daniel Vetter's implementation - devm_drm_dev_alloc https://patchwork.freedesktop.org/patch/359897/ . Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: David Airlie Cc: Daniel Vetter Cc: Sam Ravnborg Cc: Gustavo Pimentel Cc: Joao Pinto Signed-off-by: Angelo Ribeiro --- Changes since v3: - Changed Makefile to use '+=' instead of '\'. - Rearranged headers. - Replaced drm_mode_config_init by drmm_mode_config_init. - Droped DRM legacy functions. - Replaced DRM_xxx by drm_xxx. - Changed load function to devm_drm_dev_alloc. - Implemented pipeline as a drm_simple_display_pipe. --- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/ipk/Kconfig | 13 ++ drivers/gpu/drm/ipk/Makefile | 4 + drivers/gpu/drm/ipk/dw-drv.c | 169 ++++++++++++++++++ drivers/gpu/drm/ipk/dw-ipk.h | 26 +++ drivers/gpu/drm/ipk/dw-vpg.c | 412 +++++++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/ipk/dw-vpg.h | 48 +++++ 8 files changed, 675 insertions(+) create mode 100644 drivers/gpu/drm/ipk/Kconfig create mode 100644 drivers/gpu/drm/ipk/Makefile create mode 100644 drivers/gpu/drm/ipk/dw-drv.c create mode 100644 drivers/gpu/drm/ipk/dw-ipk.h create mode 100644 drivers/gpu/drm/ipk/dw-vpg.c create mode 100644 drivers/gpu/drm/ipk/dw-vpg.h diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 4359497..29ea1d1 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -388,6 +388,8 @@ source "drivers/gpu/drm/mcde/Kconfig" source "drivers/gpu/drm/tidss/Kconfig" +source "drivers/gpu/drm/ipk/Kconfig" + # Keep legacy drivers last menuconfig DRM_LEGACY diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index f34d08c..b15f2ea 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -124,3 +124,4 @@ obj-$(CONFIG_DRM_PANFROST) += panfrost/ obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/ obj-$(CONFIG_DRM_MCDE) += mcde/ obj-$(CONFIG_DRM_TIDSS) += tidss/ +obj-$(CONFIG_DRM_IPK) += ipk/ diff --git a/drivers/gpu/drm/ipk/Kconfig b/drivers/gpu/drm/ipk/Kconfig new file mode 100644 index 0000000..1f87444 --- /dev/null +++ b/drivers/gpu/drm/ipk/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +config DRM_IPK + tristate "DRM Support for Synopsys DesignWare IPK DSI" + depends on DRM + select DRM_KMS_HELPER + select DRM_GEM_CMA_HELPER + select DRM_KMS_CMA_HELPER + select DRM_PANEL_BRIDGE + select VIDEOMODE_HELPERS + help + Enable support for the Synopsys DesignWare DRM DSI. + To compile this driver as a module, choose M here: the module + will be called ipk-drm. diff --git a/drivers/gpu/drm/ipk/Makefile b/drivers/gpu/drm/ipk/Makefile new file mode 100644 index 0000000..6a1a911 --- /dev/null +++ b/drivers/gpu/drm/ipk/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +ipk-drm-y := dw-drv.o dw-vpg.o + +obj-$(CONFIG_DRM_IPK) += ipk-drm.o diff --git a/drivers/gpu/drm/ipk/dw-drv.c b/drivers/gpu/drm/ipk/dw-drv.c new file mode 100644 index 0000000..5ff6cbf --- /dev/null +++ b/drivers/gpu/drm/ipk/dw-drv.c @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019-2020 Synopsys, Inc. and/or its affiliates. + * Synopsys DesignWare MIPI DSI DRM driver + * + * Author: Angelo Ribeiro + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "dw-ipk.h" +#include "dw-vpg.h" + +static const struct drm_mode_config_funcs dw_ipk_drm_modecfg_funcs = { + .fb_create = drm_gem_fb_create_with_dirty, + .atomic_check = drm_atomic_helper_check, + .atomic_commit = drm_atomic_helper_commit, +}; + +static int dw_ipk_load(struct drm_device *drm) +{ + int ret; + + ret = drmm_mode_config_init(drm); + if (ret) + return ret; + + drm->mode_config.min_width = 0; + drm->mode_config.min_height = 0; + + /* To handle orientation */ + drm->mode_config.max_width = 2048; + drm->mode_config.max_height = 2048; + + drm->mode_config.funcs = &dw_ipk_drm_modecfg_funcs; + + /* TODO + * Optional framebuffer memory resources allocation + */ + + ret = vpg_load(drm); + if (ret) + return ret; + + /* Calls all the crtc's, encoder's and connector's reset */ + drm_mode_config_reset(drm); + + return ret; +} + +static void dw_ipk_unload(struct drm_device *drm) +{ + drm_dbg(drm, "\n"); + vpg_unload(drm); +} + +DEFINE_DRM_GEM_CMA_FOPS(ipk_drm_driver_fops); + +static int dw_ipk_gem_cma_dumb_create(struct drm_file *file, + struct drm_device *dev, + struct drm_mode_create_dumb *args) +{ + unsigned int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); + int err; + + /* + * In order to optimize data transfer, pitch is aligned on + * 128 bytes, height is aligned on 4 bytes + */ + args->pitch = roundup(min_pitch, 128); + args->height = roundup(args->height, 4); + + err = drm_gem_cma_dumb_create_internal(file, dev, args); + if (err) + drm_err(dev, "dumb_create failed %d\n", err); + + return err; +} + +static struct drm_driver dw_ipk_drm_driver = { + .gem_create_object = drm_cma_gem_create_object_default_funcs, + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, + .dumb_create = dw_ipk_gem_cma_dumb_create, + + .major = 1, + .minor = 0, + .patchlevel = 0, + .name = "dw_ipk", + .desc = "DW IPK DSI Host Controller", + .date = "20190725", + + .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET, + + .fops = &ipk_drm_driver_fops, +}; + +static int dw_ipk_drm_platform_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct drm_device *drm; + struct ipk_device *ipk; + int ret; + + ipk = devm_drm_dev_alloc(dev, &dw_ipk_drm_driver, + struct ipk_device, drm); + if (IS_ERR(ipk)) + return PTR_ERR(ipk); + + ipk->platform = pdev; + drm = &ipk->drm; + + platform_set_drvdata(pdev, drm); + + ret = dw_ipk_load(drm); + if (ret) + return ret; + + ret = drm_dev_register(drm, 0); + if (ret) + return ret; + + drm_fbdev_generic_setup(drm, 24); + + return ret; +} + +static int dw_ipk_drm_platform_remove(struct platform_device *pdev) +{ + struct drm_device *drm = platform_get_drvdata(pdev); + + drm_dev_unregister(drm); + dw_ipk_unload(drm); + + return 0; +} + +static const struct of_device_id dw_ipk_dt_ids[] = { + {.compatible = "snps,dw-ipk-vpg"}, + { /* sentinel */ } +}; + +MODULE_DEVICE_TABLE(of, dw_ipk_dt_ids); + +static struct platform_driver dw_ipk_drm_platform_driver = { + .probe = dw_ipk_drm_platform_probe, + .remove = dw_ipk_drm_platform_remove, + .driver = { + .name = "dw-ipk-drm", + .of_match_table = dw_ipk_dt_ids, + }, +}; + +module_platform_driver(dw_ipk_drm_platform_driver); + +MODULE_DESCRIPTION("Synopsys DesignWare IPK DRM driver"); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Angelo Ribeiro "); diff --git a/drivers/gpu/drm/ipk/dw-ipk.h b/drivers/gpu/drm/ipk/dw-ipk.h new file mode 100644 index 0000000..8d3fd12 --- /dev/null +++ b/drivers/gpu/drm/ipk/dw-ipk.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2019-2020 Synopsys, Inc. and/or its affiliates. + * Synopsys DesignWare IPK MIPI DSI DRM Driver + */ + +#ifndef _DW_IPK_H +#define _DW_IPK_H + +#include + +struct vpg_device; + +struct ipk_device { + struct drm_device drm; + struct platform_device *platform; + struct drm_simple_display_pipe pipe; + struct vpg_device *vpg; +}; + +#define drm_dev_to_ipk_dev(target) \ + container_of(target, struct ipk_device, drm) +#define display_pipe_to_ipk_dev(target) \ + container_of(target, struct ipk_device, pipe) + +#endif /* _DW_IPK_H */ diff --git a/drivers/gpu/drm/ipk/dw-vpg.c b/drivers/gpu/drm/ipk/dw-vpg.c new file mode 100644 index 0000000..b7575fa --- /dev/null +++ b/drivers/gpu/drm/ipk/dw-vpg.c @@ -0,0 +1,412 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019-2020 Synopsys, Inc. and/or its affiliates. + * Synopsys DesignWare MIPI DSI controller + * + * Author: Angelo Ribeiro + * Author: Luis Oliveira + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include