From patchwork Fri Feb 7 20:23:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 3607611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E39459F2D6 for ; Fri, 7 Feb 2014 20:30:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD3F920131 for ; Fri, 7 Feb 2014 20:29:59 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 91E562012F for ; Fri, 7 Feb 2014 20:29:58 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBs3R-0003vL-K5; Fri, 07 Feb 2014 20:29:41 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBryZ-0006PZ-SW; Fri, 07 Feb 2014 20:24:39 +0000 Received: from pandora.arm.linux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WBryV-0006OK-8I for linux-arm-kernel@lists.infradead.org; Fri, 07 Feb 2014 20:24:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=kIONjOFt4O/rDdDhzOa4+IzsTKjVinkoYOm93oUQB9s=; b=gwvAWrsB6oRhDKEkT+PFx1MB5HYi27DWAClmCCLWPozHw3r0tY9DYXAibZCmtmADHGjyf0fktgpHEjis9+fMfiUam7+Wv9lIhAZ7b/P5mNjkAIEtHYEZPLo+G08vGEk30G+kkDPHCksmqrZU7ucQdCWR9iyeMwxUnBfE9L4nM+g=; Received: from n2100.arm.linux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:4f86]:58443) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1WBrxp-0002MF-O3; Fri, 07 Feb 2014 20:23:53 +0000 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1WBrxn-0004fu-Nl; Fri, 07 Feb 2014 20:23:51 +0000 Date: Fri, 7 Feb 2014 20:23:51 +0000 From: Russell King - ARM Linux To: Jean-Francois Moine Subject: Re: [PATCH RFC 0/2] drivers/base: simplify simple DT-based components Message-ID: <20140207202351.GH26684@n2100.arm.linux.org.uk> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140207_152435_774095_245A3AB5 X-CRM114-Status: GOOD ( 26.25 ) X-Spam-Score: -2.5 (--) Cc: devel@driverdev.osuosl.org, alsa-devel@alsa-project.org, Daniel Vetter , Takashi Iwai , Greg Kroah-Hartman , dri-devel@lists.freedesktop.org, Sascha Hauer , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, Feb 07, 2014 at 06:11:08PM +0100, Jean-Francois Moine wrote: > This patch series tries to simplify the code of simple devices in case > they are part of componentised subsystems, are declared in a DT, and > are not using the component bin/unbind functions. Here's my changes to the TDA998x driver to add support for the component helper. The TDA998x driver retains support for the old way so that drivers can be transitioned. For any one DRM "card" the transition to using the component layer must be all-in or all-out - partial transitions are not permitted with the simple locking implementation currently in the component helper due to the possibility of deadlock. (Master binds, holding the component lock, master declares i2c device, i2c device is bound to tda998x, which tries to register with the component layer, trying to take the held lock.) http://ftp.arm.linux.org.uk/cgit/linux-cubox.git/log/?h=unstable/tda998x-devel It's marked unstable because the two "drivers/base" commits in there are _not_ the upstream commits. You'll notice that I just sent one of those to Gregkh in patch form. Now, the bits which aren't in that branch but which update the Armada driver is the below, which needs some clean up and removal of some local differences I have in my cubox tree, but nicely illustrates why /your/ patches to the component stuff is the wrong approach. Not only does the patch below add support for using the componentised TDA998x driver in the above link, but it allows that componentised support to be specified not only via platform data but also via DT. The DT stuff is untested, but it works exactly the same way as imx-drm does which has been tested. And yes, I'm thinking that maybe moving compare_of() into the component support so that drivers can share this generic function may be a good idea. So... as I've been saying, no changes to component.c are required here. diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c index 6f6554bac93f..1f2b7c60bff9 100644 --- a/drivers/gpu/drm/armada/armada_drv.c +++ b/drivers/gpu/drm/armada/armada_drv.c @@ -6,7 +6,9 @@ * published by the Free Software Foundation. */ #include +#include #include +#include #include #include #include "armada_crtc.h" @@ -53,6 +55,11 @@ static const struct armada_drm_slave_config tda19988_config = { }; #endif +static bool is_componentized(struct device *dev) +{ + return dev->of_node || dev->platform_data; +} + static void armada_drm_unref_work(struct work_struct *work) { struct armada_private *priv = @@ -171,16 +178,22 @@ static int armada_drm_load(struct drm_device *dev, unsigned long flags) goto err_kms; } + if (is_componentized(dev->dev)) { + ret = component_bind_all(dev->dev, dev); + if (ret) + goto err_kms; + } else { #ifdef CONFIG_DRM_ARMADA_TDA1998X - ret = armada_drm_connector_slave_create(dev, &tda19988_config); - if (ret) - goto err_kms; + ret = armada_drm_connector_slave_create(dev, &tda19988_config); + if (ret) + goto err_kms; #endif #ifdef CONFIG_DRM_ARMADA_TDA1998X_NXP - ret = armada_drm_tda19988_nxp_create(dev); - if (ret) - goto err_kms; + ret = armada_drm_tda19988_nxp_create(dev); + if (ret) + goto err_kms; #endif + } ret = drm_vblank_init(dev, n); if (ret) @@ -204,6 +217,10 @@ static int armada_drm_load(struct drm_device *dev, unsigned long flags) drm_irq_uninstall(dev); err_kms: drm_mode_config_cleanup(dev); + + if (is_componentized(dev->dev)) + component_unbind_all(dev->dev, dev); + drm_mm_takedown(&priv->linear); flush_work(&priv->fb_unref_work); @@ -218,6 +235,10 @@ static int armada_drm_unload(struct drm_device *dev) armada_fbdev_fini(dev); drm_irq_uninstall(dev); drm_mode_config_cleanup(dev); + + if (is_componentized(dev->dev)) + component_unbind_all(dev->dev, dev); + drm_mm_takedown(&priv->linear); flush_work(&priv->fb_unref_work); dev->dev_private = NULL; @@ -380,14 +401,82 @@ static struct drm_driver armada_drm_driver = { .fops = &armada_drm_fops, }; +static int armada_drm_bind(struct device *dev) +{ + return drm_platform_init(&armada_drm_driver, to_platform_device(dev)); +} + +static void armada_drm_unbind(struct device *dev) +{ + drm_platform_exit(&armada_drm_driver, to_platform_device(dev)); +} + +static int compare_of(struct device *dev, void *data) +{ + return dev->of_node == data; +} + +static int armada_drm_compare_name(struct device *dev, void *data) +{ + const char *name = data; + return !strcmp(dev_name(dev), name); +} + +static int armada_drm_add_components(struct device *dev, struct master *master) +{ + int i, ret = -ENXIO; + + if (dev->of_node) { + struct device_node *np = dev->of_node; + + for (i = 0; ; i++) { + struct device_node *node; + + node = of_parse_phandle(np, "connectors", i); + if (!node) + break; + + ret = component_master_add_child(master, compare_of, + node); + of_node_put(node); + if (ret) + break; + } + } else if (dev->platform_data) { + struct armada_drm_platform_data *data = dev->platform_data; + + for (i = 0; i < data->num_devices; i++) { + ret = component_master_add_child(master, + armada_drm_compare_name, + (void *)data->devices[i]); + if (ret) + break; + } + } + + return ret; +} + +static const struct component_master_ops armada_master_ops = { + .add_components = armada_drm_add_components, + .bind = armada_drm_bind, + .unbind = armada_drm_unbind, +}; + static int armada_drm_probe(struct platform_device *pdev) { - return drm_platform_init(&armada_drm_driver, pdev); + if (is_componentized(&pdev->dev)) + return component_master_add(&pdev->dev, &armada_master_ops); + else + return drm_platform_init(&armada_drm_driver, pdev); } static int armada_drm_remove(struct platform_device *pdev) { - drm_platform_exit(&armada_drm_driver, pdev); + if (is_componentized(&pdev->dev)) + component_master_del(&pdev->dev, &armada_master_ops); + else + drm_platform_exit(&armada_drm_driver, pdev); return 0; }