From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24F80C2BABC for ; Tue, 7 Apr 2020 08:13:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7BF4206F7 for ; Tue, 7 Apr 2020 08:13:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="bPdUHv7k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727913AbgDGINl (ORCPT ); Tue, 7 Apr 2020 04:13:41 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41976 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbgDGINk (ORCPT ); Tue, 7 Apr 2020 04:13:40 -0400 Received: by mail-wr1-f67.google.com with SMTP id h9so2755083wrc.8 for ; Tue, 07 Apr 2020 01:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=lTD+Kxr2WH+cMgNO+SQVk8Ij1l3A9jp2tfNGUa6DEpY=; b=bPdUHv7kGns8lqmZ80zgWGwrRHX7qgtF4NOPF+/WlQLbbHcpjxR7ibaYZ9fIqPAq7F I39rBP/8gw6Uwz2BewUua69OCjkNJloIIuNjSfg9gwHv4m1Mb35bHjyvVqe/bbTp+w1L aWB5RfTdlD/GDODKiqTQL8P4VZ1/SKAQseD+A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=lTD+Kxr2WH+cMgNO+SQVk8Ij1l3A9jp2tfNGUa6DEpY=; b=I88ddp4CP8USu71Sb8DA/xa4ioW1RD4RpvJ6ArlTzC9WXfVOg2OUbJzDYB1gRktFqK OI8Z5rryXIS20yilAvzEw6s/jfpYuhq0ELzE6aw+yWX42hjuJYJi0j08JSz3Gw2uC3Uh eAvYGO+yvK53zmx2oc+KtG9EWnZoNM7obSGzotmy3IlIfUtouM9lrbjG3uG70++ytyCu kBB2Y2yfhseH3INdxpiohf9MFeK8TwszLO9iW3lYgEyKkk6hxwFeH3O06lDVa4K77ht+ lWBHVFMOebHgqgS2AHQmM8ax62C5bHz+ZNzXVCFlLXbrwffcNmZ7Y0C3dkbfBc/ACIzN 5QAQ== X-Gm-Message-State: AGi0PuYBVUsfIoJJ1D3s+6ZtT76pesnmXdUjf/GnfLtSDxH5HIuUP/o4 AixDenhsl9uvqOG74f2di20ZQA== X-Google-Smtp-Source: APiQypKpitM+MM3GLTtmdMd3xZxki53IgkT27bnYk5xYDOhXFSHgDQbmufa+khzMZR7HkRNE2ANN9A== X-Received: by 2002:adf:f310:: with SMTP id i16mr1410099wro.100.1586247216418; Tue, 07 Apr 2020 01:13:36 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id g2sm29346879wrs.42.2020.04.07.01.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 01:13:35 -0700 (PDT) Date: Tue, 7 Apr 2020 10:13:33 +0200 From: Daniel Vetter To: Angelo Ribeiro Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@linux.ie, daniel@ffwll.ch, Gustavo.Pimentel@synopsys.com, Joao.Pinto@synopsys.com Subject: Re: [PATCH v2 2/4] drm: ipk: Add DRM driver for DesignWare IPK DSI Message-ID: <20200407081333.GI3456981@phenom.ffwll.local> Mail-Followup-To: Angelo Ribeiro , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@linux.ie, Gustavo.Pimentel@synopsys.com, Joao.Pinto@synopsys.com References: <488ff0f31581967517607e6860ab520839e29635.1586174459.git.angelo.ribeiro@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <488ff0f31581967517607e6860ab520839e29635.1586174459.git.angelo.ribeiro@synopsys.com> X-Operating-System: Linux phenom 5.3.0-3-amd64 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 06, 2020 at 03:24:12PM +0200, Angelo Ribeiro wrote: > Add support for Synopsys DesignWare VPG (Video Pattern Generator) and > DRM driver for Synopsys DesignWare DSI Host IPK solution. > > Cc: Maarten Lankhorst > Cc: Maxime Ripard > Cc: David Airlie > Cc: Daniel Vetter > Cc: Gustavo Pimentel > Cc: Joao Pinto > Signed-off-by: Angelo Ribeiro > --- > drivers/gpu/drm/Kconfig | 2 + > drivers/gpu/drm/Makefile | 1 + > drivers/gpu/drm/ipk/Kconfig | 13 + > drivers/gpu/drm/ipk/Makefile | 6 + > drivers/gpu/drm/ipk/dw-drv.c | 189 +++++++++++++++ > drivers/gpu/drm/ipk/dw-ipk.h | 30 +++ > drivers/gpu/drm/ipk/dw-vpg.c | 559 +++++++++++++++++++++++++++++++++++++++++++ > drivers/gpu/drm/ipk/dw-vpg.h | 55 +++++ > 8 files changed, 855 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 183c600..5bcc1c1 100644 > --- a/drivers/gpu/drm/Makefile > +++ b/drivers/gpu/drm/Makefile > @@ -125,3 +125,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..51d2774 > --- /dev/null > +++ b/drivers/gpu/drm/ipk/Makefile > @@ -0,0 +1,6 @@ > +# 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..6205f1c > --- /dev/null > +++ b/drivers/gpu/drm/ipk/dw-drv.c > @@ -0,0 +1,189 @@ > +// 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 > +#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; > + > + drm_mode_config_init(drm); > + > + 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); > + > + /* Initialize and enable output polling */ > + drm_kms_helper_poll_init(drm); > + > + return ret; > +} > + > +static void dw_ipk_unload(struct drm_device *drm) > +{ > + DRM_DEBUG_DRIVER("\n"); > + > + drm_kms_helper_poll_fini(drm); > + vpg_unload(drm); > +} > + > +DEFINE_DRM_GEM_CMA_FOPS(ipk_drm_driver_fops); > + > +static int 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 < 0) > + drm_err(dev, "dumb_create failed %d\n", err); > + > + return err; > +} > + > +static struct drm_driver dw_ipk_drm_driver = { > + .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC, > + .name = "dw_ipk", > + .desc = "DW IPK DSI Host Controller", > + .date = "20190725", > + .major = 1, > + .minor = 0, > + .patchlevel = 0, > + .fops = &ipk_drm_driver_fops, > + .dumb_create = ipk_gem_cma_dumb_create, > + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, > + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, > + .gem_free_object_unlocked = drm_gem_cma_free_object, > + .gem_vm_ops = &drm_gem_cma_vm_ops, > + .gem_prime_export = drm_gem_prime_export, > + .gem_prime_import = drm_gem_prime_import, > + .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, > + .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, > + .gem_prime_vmap = drm_gem_cma_prime_vmap, > + .gem_prime_vunmap = drm_gem_cma_prime_vunmap, > + .gem_prime_mmap = drm_gem_cma_prime_mmap, > +}; > + > +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; > + > + DRM_DEBUG_DRIVER("\n"); > + > + ipk = kzalloc(sizeof(*ipk), GFP_KERNEL); > + if (!ipk) > + return -ENOMEM; > + > + ipk->platform = pdev; > + drm = &ipk->drm; > + > + ret = drm_dev_init(&ipk->drm, &dw_ipk_drm_driver, dev); > + if (ret) { > + kfree(ipk); > + return ret; > + } I'm reworking this right now, you're missing a call to drmm_add_final_kfree here. But I think even better would be to rebase on top of my patch here: https://patchwork.freedesktop.org/patch/359897/ Which would allow you to drop a bunch of code from your load/unload code. See that patch series for a lot of example conversions. I plan to land that patch pretty soon in drm-misc-next so shouldn't hold up merging your driver. -Daniel > + > + platform_set_drvdata(pdev, drm); > + > + ret = dw_ipk_load(drm); > + if (ret) > + goto err_put; > + > + ret = drm_dev_register(drm, 0); > + if (ret) > + goto err_put; > + > + drm_fbdev_generic_setup(drm, 24); > + > + return ret; > + > +err_put: > + drm_dev_put(drm); > + 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); > + drm_dev_put(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..4abb6dd > --- /dev/null > +++ b/drivers/gpu/drm/ipk/dw-ipk.h > @@ -0,0 +1,30 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (c) 2019-2020 Synopsys, Inc. and/or its affiliates. > + * Synopsys DesignWare MIPI DSI Controller > + */ > + > +#ifndef _DW_IPK_H > +#define _DW_IPK_H > + > +#include "drm/drm_device.h" > +#include > + > +struct ipk_pipeline { > + struct drm_framebuffer *fb; > + struct drm_crtc crtc; > + struct drm_plane *plane; > + struct drm_bridge *bridge; > +}; > + > +struct ipk_device { > + struct drm_device drm; > + struct platform_device *platform; > + struct ipk_pipeline pipeline; > + struct vpg_device *vpg; > +}; > + > +#define drm_device_to_ipk_device(target) \ > + container_of(target, struct ipk_device, drm) > + > +#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..feb3e90 > --- /dev/null > +++ b/drivers/gpu/drm/ipk/dw-vpg.c > @@ -0,0 +1,559 @@ > +// 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 > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include