<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Feb 22, 2020 at 5:36 AM Sam Ravnborg <<a href="mailto:sam@ravnborg.org">sam@ravnborg.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Kevin.<br>
<br>
On Fri, Feb 21, 2020 at 03:48:52PM +0800, Kevin Tang wrote:<br>
> From: Kevin Tang <<a href="mailto:kevin.tang@unisoc.com" target="_blank">kevin.tang@unisoc.com</a>><br>
> <br>
> Adds drm support for the Unisoc's display subsystem.<br>
<br>
Thanks for the updated driver patch.<br>
Good split of patches.<br>
A few comments in the following.<br>
Please filter in the comments as some may not apply to this driver.<br>
<br>
Sam<br>
<br>
> <br>
> This is drm device and gem driver. This driver provides support for the<br>
> Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.<br>
Hmm, hopefully we can use this without XFree86?<br>
Looks like the above was copied from something outdated.<br></blockquote><div>Yes, copy from drm/Kconfig, but we have tested ok on android hwcomposer.</div><div>It is indeed copied from outdated content, need to fix it?<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
> +++ b/drivers/gpu/drm/sprd/Kconfig<br>
> @@ -0,0 +1,14 @@<br>
> +config DRM_SPRD<br>
> + tristate "DRM Support for Unisoc SoCs Platform"<br>
> + depends on ARCH_SPRD<br>
> + depends on DRM && OF<br>
> + select DRM_KMS_HELPER<br>
> + select DRM_GEM_CMA_HELPER<br>
> + select DRM_KMS_CMA_HELPER<br>
> + select DRM_MIPI_DSI<br>
> + select DRM_PANEL<br>
> + select VIDEOMODE_HELPERS<br>
> + select BACKLIGHT_CLASS_DEVICE<br>
> + help<br>
> + Choose this option if you have a Unisoc chipsets.<br>
> + If M is selected the module will be called sprd-drm.<br>
<br>
Please check that VIDEOMODE_HELPERS is really needed.<br>
Please add COMPILE_TEST - so we will build this driver with<br>
allmodconfig/allyesconfig.<br>
This is how we ofthe verify refactoring work.<br></blockquote><div>Ok, i will fix it. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
> \ No newline at end of file<br>
Please fix.<br>
<br>
<br>
> diff --git a/drivers/gpu/drm/sprd/Makefile b/drivers/gpu/drm/sprd/Makefile<br>
> new file mode 100644<br>
> index 0000000..63b8751<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/Makefile<br>
> @@ -0,0 +1,7 @@<br>
> +# SPDX-License-Identifier: GPL-2.0<br>
> +<br>
> +ccflags-y += -Iinclude/drm<br>
Not required - delete.<br></blockquote><div>Ok, this can be delete, thanks for reminding. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> +subdir-ccflags-y += -I$(src)<br>
Not required - delete.<br></blockquote><div>This maybe can't, because our dpu subdir need it to found parent dir header file. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +<br>
> +obj-y := sprd_drm.o<br>
<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_drm.c b/drivers/gpu/drm/sprd/sprd_drm.c<br>
> new file mode 100644<br>
> index 0000000..7cac098<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_drm.c<br>
> @@ -0,0 +1,292 @@<br>
> +// SPDX-License-Identifier: GPL-2.0<br>
> +/*<br>
> + * Copyright (C) 2019 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#include <linux/component.h><br>
> +#include <linux/dma-mapping.h><br>
> +#include <linux/module.h><br>
> +#include <linux/mutex.h><br>
> +#include <linux/of_graph.h><br>
> +#include <linux/of_platform.h><br>
> +<br>
> +#include <drm/drm_atomic_helper.h><br>
> +#include <drm/drm_crtc_helper.h><br>
> +#include <drm/drm_drv.h><br>
> +#include <drm/drm_gem_cma_helper.h><br>
> +#include <drm/drm_gem_framebuffer_helper.h><br>
> +#include <drm/drm_probe_helper.h><br>
> +#include <drm/drm_vblank.h><br>
> +<br>
> +#include "sprd_drm.h"<br>
> +<br>
> +#define DRIVER_NAME "sprd"<br>
> +#define DRIVER_DESC "Spreadtrum SoCs' DRM Driver"<br>
> +#define DRIVER_DATE "20191101"<br>
We are in 2020 now..<br>
<br>
> +#define DRIVER_MAJOR 1<br>
> +#define DRIVER_MINOR 0<br>
> +<br>
> +static const struct drm_mode_config_helper_funcs sprd_drm_mode_config_helper = {<br>
> + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,<br>
> +};<br>
> +<br>
> +static const struct drm_mode_config_funcs sprd_drm_mode_config_funcs = {<br>
> + .fb_create = drm_gem_fb_create,<br>
> + .atomic_check = drm_atomic_helper_check,<br>
> + .atomic_commit = drm_atomic_helper_commit,<br>
> +};<br>
> +<br>
> +static void sprd_drm_mode_config_init(struct drm_device *drm)<br>
> +{<br>
> + drm_mode_config_init(drm);<br>
> +<br>
> + drm->mode_config.min_width = 0;<br>
> + drm->mode_config.min_height = 0;<br>
> + drm->mode_config.max_width = 8192;<br>
> + drm->mode_config.max_height = 8192;<br>
> + drm->mode_config.allow_fb_modifiers = true;<br>
> +<br>
> + drm->mode_config.funcs = &sprd_drm_mode_config_funcs;<br>
> + drm->mode_config.helper_private = &sprd_drm_mode_config_helper;<br>
> +}<br>
> +<br>
> +DEFINE_DRM_GEM_CMA_FOPS(sprd_drm_fops);<br>
> +<br>
> +static struct drm_driver sprd_drm_drv = {<br>
> + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,<br>
> + .fops = &sprd_drm_fops,<br>
> +<br>
> + /* GEM Operations */<br>
> + DRM_GEM_CMA_VMAP_DRIVER_OPS,<br>
> +<br>
> + .name = DRIVER_NAME,<br>
> + .desc = DRIVER_DESC,<br>
> + .date = DRIVER_DATE,<br>
> + .major = DRIVER_MAJOR,<br>
> + .minor = DRIVER_MINOR,<br>
> +};<br>
> +<br>
> +static int sprd_drm_bind(struct device *dev)<br>
> +{<br>
> + struct drm_device *drm;<br>
> + struct sprd_drm *sprd;<br>
> + int err;<br>
> +<br>
> + drm = drm_dev_alloc(&sprd_drm_drv, dev);<br>
> + if (IS_ERR(drm))<br>
> + return PTR_ERR(drm);<br>
You should embed drm_device in struct sprd_drm.<br>
See example code in drm/drm_drv.c<br>
<br>
This is what modern drm drivers do.<br>
<br>
I *think* you can drop the component framework if you do this.<br></blockquote><div>I have read it(drm/drm_drv.c) carefully, if drop the component framework,</div><div>the whole our drm driver maybe need to redesign, so i still want to keep current design.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> + dev_set_drvdata(dev, drm);<br>
> +<br>
> + sprd = devm_kzalloc(drm->dev, sizeof(*sprd), GFP_KERNEL);<br>
> + if (!sprd) {<br>
> + err = -ENOMEM;<br>
> + goto err_free_drm;<br>
> + }<br>
> + drm->dev_private = sprd;<br>
> +<br>
> + sprd_drm_mode_config_init(drm);<br>
> +<br>
> + /* bind and init sub drivers */<br>
> + err = component_bind_all(drm->dev, drm);<br>
> + if (err) {<br>
> + DRM_ERROR("failed to bind all component.\n");<br>
> + goto err_dc_cleanup;<br>
> + }<br>
When you have a drm_device - which you do here.<br>
Then please use drm_err() and friends for error messages.<br>
Please verify all uses of DRM_XXX<br></blockquote><div>
modern drm drivers need drm_xxx to replace DRM_XXX?</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> + /* vblank init */<br>
> + err = drm_vblank_init(drm, drm->mode_config.num_crtc);<br>
> + if (err) {<br>
> + DRM_ERROR("failed to initialize vblank.\n");<br>
> + goto err_unbind_all;<br>
> + }<br>
<br>
<br>
> + /* with irq_enabled = true, we can use the vblank feature. */<br>
> + drm->irq_enabled = true;<br>
I cannot see any irq being installed. This looks wrong.<br></blockquote><div>Our display controller isr is been register on crtc driver(sprd_dpu.c), not here. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> + /* reset all the states of crtc/plane/encoder/connector */<br>
> + drm_mode_config_reset(drm);<br>
> +<br>
> + /* init kms poll for handling hpd */<br>
> + drm_kms_helper_poll_init(drm);<br>
> +<br>
> + err = drm_dev_register(drm, 0);<br>
> + if (err < 0)<br>
> + goto err_kms_helper_poll_fini;<br>
> +<br>
> + return 0;<br>
> +<br>
> +err_kms_helper_poll_fini:<br>
> + drm_kms_helper_poll_fini(drm);<br>
> +err_unbind_all:<br>
> + component_unbind_all(drm->dev, drm);<br>
> +err_dc_cleanup:<br>
> + drm_mode_config_cleanup(drm);<br>
> +err_free_drm:<br>
> + drm_dev_put(drm);<br>
> + return err;<br>
Please see the example in drm/drm_drv.c - following the example<br>
will simpligy error handling a bit.<br>
Ad you will learn not to use drm_dev_put().<br></blockquote><div>Ok, i will fix it </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +}<br>
> +<br>
> +static void sprd_drm_unbind(struct device *dev)<br>
> +{<br>
> + drm_put_dev(dev_get_drvdata(dev));<br>
> +}<br>
> +<br>
> +static const struct component_master_ops drm_component_ops = {<br>
> + .bind = sprd_drm_bind,<br>
> + .unbind = sprd_drm_unbind,<br>
> +};<br>
> +<br>
> +static int compare_of(struct device *dev, void *data)<br>
> +{<br>
> + struct device_node *np = data;<br>
> +<br>
> + DRM_DEBUG("compare %s\n", np->full_name);<br>
Leftover debugging that can be dropped?<br></blockquote><div>Ok, i will drop useless debug log. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> + return dev->of_node == np;<br>
> +}<br>
> +<br>
> +static int sprd_drm_component_probe(struct device *dev,<br>
> + const struct component_master_ops *m_ops)<br>
> +{<br>
> + struct device_node *ep, *port, *remote;<br>
> + struct component_match *match = NULL;<br>
> + int i;<br>
> +<br>
> + if (!dev->of_node)<br>
> + return -EINVAL;<br>
> +<br>
> + /*<br>
> + * Bind the crtc's ports first, so that drm_of_find_possible_crtcs()<br>
> + * called from encoder's .bind callbacks works as expected<br>
> + */<br>
> + for (i = 0; ; i++) {<br>
> + port = of_parse_phandle(dev->of_node, "ports", i);<br>
> + if (!port)<br>
> + break;<br>
> +<br>
> + if (!of_device_is_available(port->parent)) {<br>
> + of_node_put(port);<br>
> + continue;<br>
> + }<br>
> +<br>
> + component_match_add(dev, &match, compare_of, port->parent);<br>
> + of_node_put(port);<br>
> + }<br>
> +<br>
> + if (i == 0) {<br>
> + dev_err(dev, "missing 'ports' property\n");<br>
> + return -ENODEV;<br>
> + }<br>
> +<br>
> + if (!match) {<br>
> + dev_err(dev, "no available port\n");<br>
> + return -ENODEV;<br>
> + }<br>
> +<br>
> + /*<br>
> + * For bound crtcs, bind the encoders attached to their remote endpoint<br>
> + */<br>
> + for (i = 0; ; i++) {<br>
> + port = of_parse_phandle(dev->of_node, "ports", i);<br>
> + if (!port)<br>
> + break;<br>
> +<br>
> + if (!of_device_is_available(port->parent)) {<br>
> + of_node_put(port);<br>
> + continue;<br>
> + }<br>
> +<br>
> + for_each_child_of_node(port, ep) {<br>
> + remote = of_graph_get_remote_port_parent(ep);<br>
> + if (!remote || !of_device_is_available(remote)) {<br>
> + of_node_put(remote);<br>
> + continue;<br>
> + } else if (!of_device_is_available(remote->parent)) {<br>
> + dev_warn(dev, "parent device of %s is not available\n",<br>
> + remote->full_name);<br>
> + of_node_put(remote);<br>
> + continue;<br>
> + }<br>
> +<br>
> + component_match_add(dev, &match, compare_of, remote);<br>
> + of_node_put(remote);<br>
> + }<br>
> + of_node_put(port);<br>
> + }<br>
> +<br>
> + return component_master_add_with_match(dev, m_ops, match);<br>
> +}<br>
> +<br>
> +static int sprd_drm_probe(struct platform_device *pdev)<br>
> +{<br>
> + int ret;<br>
> +<br>
> + ret = dma_set_mask_and_coherent(&pdev->dev, ~0);<br>
I do not thing ~0 is always the right mask.<br>
Please verify.<br></blockquote><div>It's right mask for us.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> + if (ret) {<br>
> + DRM_ERROR("dma_set_mask_and_coherent failed (%d)\n", ret);<br>
> + return ret;<br>
> + }<br>
> +<br>
> + return sprd_drm_component_probe(&pdev->dev, &drm_component_ops);<br>
> +}<br>
> +<br>
> +static int sprd_drm_remove(struct platform_device *pdev)<br>
> +{<br>
> + component_master_del(&pdev->dev, &drm_component_ops);<br>
> + return 0;<br>
> +}<br>
> +<br>
> +static void sprd_drm_shutdown(struct platform_device *pdev)<br>
> +{<br>
> + struct drm_device *drm = platform_get_drvdata(pdev);<br>
> +<br>
> + if (!drm) {<br>
> + DRM_WARN("drm device is not available, no shutdown\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + drm_atomic_helper_shutdown(drm);<br>
> +}<br>
> +<br>
> +static const struct of_device_id drm_match_table[] = {<br>
> + { .compatible = "sprd,display-subsystem", },<br>
> + {},<br>
<br>
Sometimes we use { /* sentinel */ },<br>
here.<br></blockquote><div>Ok, i will fix it </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +};<br>
> +MODULE_DEVICE_TABLE(of, drm_match_table);<br>
> +<br>
> +static struct platform_driver sprd_drm_driver = {<br>
> + .probe = sprd_drm_probe,<br>
> + .remove = sprd_drm_remove,<br>
> + .shutdown = sprd_drm_shutdown,<br>
> + .driver = {<br>
> + .name = "sprd-drm-drv",<br>
> + .of_match_table = drm_match_table,<br>
> + },<br>
> +};<br>
> +<br>
> +static struct platform_driver *sprd_drm_drivers[] = {<br>
> + &sprd_drm_driver,<br>
> +};<br>
> +<br>
> +static int __init sprd_drm_init(void)<br>
> +{<br>
> + int ret;<br>
> +<br>
> + ret = platform_register_drivers(sprd_drm_drivers,<br>
> + ARRAY_SIZE(sprd_drm_drivers));<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static void __exit sprd_drm_exit(void)<br>
> +{<br>
> + platform_unregister_drivers(sprd_drm_drivers,<br>
> + ARRAY_SIZE(sprd_drm_drivers));<br>
> +}<br>
> +<br>
> +module_init(sprd_drm_init);<br>
> +module_exit(sprd_drm_exit);<br>
> +<br>
> +MODULE_AUTHOR("Leon He <<a href="mailto:leon.he@unisoc.com" target="_blank">leon.he@unisoc.com</a>>");<br>
> +MODULE_AUTHOR("Kevin Tang <<a href="mailto:kevin.tang@unisoc.com" target="_blank">kevin.tang@unisoc.com</a>>");<br>
> +MODULE_DESCRIPTION("Unisoc DRM KMS Master Driver");<br>
> +MODULE_LICENSE("GPL v2");<br>
> diff --git a/drivers/gpu/drm/sprd/sprd_drm.h b/drivers/gpu/drm/sprd/sprd_drm.h<br>
> new file mode 100644<br>
> index 0000000..137cb27<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/sprd/sprd_drm.h<br>
> @@ -0,0 +1,16 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0 */<br>
> +/*<br>
> + * Copyright (C) 2019 Unisoc Inc.<br>
> + */<br>
> +<br>
> +#ifndef _SPRD_DRM_H_<br>
> +#define _SPRD_DRM_H_<br>
> +<br>
> +#include <drm/drm_atomic.h><br>
> +#include <drm/drm_print.h><br>
> +<br>
> +struct sprd_drm {<br>
> + struct drm_device *drm;<br>
> +};<br>
> +<br>
> +#endif /* _SPRD_DRM_H_ */<br>
> -- <br>
> 2.7.4<br>
> <br>
> _______________________________________________<br>
> dri-devel mailing list<br>
> <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</blockquote></div></div>