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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C3CCC4332F for ; Thu, 9 Nov 2023 17:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=72rGA+/MSpTmg7FmZimRCetolBEPJ3p5SDMy8+Gepx8=; b=r3VRGbCEWNqinf atAjpQWgHZsWQWDtr+amU0+LHbk+EFddUH01AVyhnF/0iEBbL/eC0TqAcF36HmBeWxc6XisHvZflX UntbOA2vncan0TFcH3jQ8+7qkcA1FESQFVXv//zNGjBegz1g9reO9u5xC6+fEDPG9jhqe83Mb5MF/ KpDGuwUiLpuef13o8PxKegZAstKWTcLw0HQKQos3rKrS+Kpcv6zUBr7JwyyLzoL8ZkI1ks+j5y3tq COaT5uXE5mh644UwAYdIni5STs7pZXwBcFJ2daR1hglytfvmeffhLpDrU7Oe5uBFZO/7vSXgIqq7D Rf2CFOD54hdgWR6RT8aA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r19Ev-006z1a-19; Thu, 09 Nov 2023 17:54:49 +0000 Received: from mgamail.intel.com ([192.55.52.115]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r19Es-006z0b-2a; Thu, 09 Nov 2023 17:54:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699552486; x=1731088486; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=W+SHpRUTX0bjysEqjA1XdgPiJiwC/4AQT1Ukvj3HDhQ=; b=OBf/xbhNOrMabnOgs1AUu0iC93PNuefAFkJDFySg5EKGxXXD8ghNS0Q9 FNgk/0pK6kC0yvcEBHOtJKAlhsvubfOAMFVjVKv5x48Nm1HxR9XVIJMTy LN8JA52Mx93JciDc3OTcUwIMz3Jl6PhtgKik2hQ/CmzBxZLxuAQrwI8VG AXrnERlY5gwUMMi+D0UVRIDcm6G1e9CGAxXF+x2O+ExBXJbphKpv/0l8W QHgqruFFaNL9L+l6lKR5OnREm6ZXUHlXN8pTpUsFWHFb51jo/39dkHfeQ r2gDKN+XO7itKmublBHb66oJPSIoVUJkP4xTmVqh4OhVLd7+XZoc1RN9R g==; X-IronPort-AV: E=McAfee;i="6600,9927,10889"; a="389845725" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="389845725" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 09:54:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10889"; a="854147773" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="854147773" Received: from smile.fi.intel.com ([10.237.72.54]) by FMSMGA003.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 09:54:37 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97-RC3) (envelope-from ) id 1r19Ef-0000000Cekh-33M3; Thu, 09 Nov 2023 19:54:33 +0200 Date: Thu, 9 Nov 2023 19:54:33 +0200 From: Andy Shevchenko To: Chen-Yu Tsai Cc: Rob Herring , Frank Rowand , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , AngeloGioacchino Del Regno , Hsin-Yi Wang , Dmitry Torokhov , Jiri Kosina , linus.walleij@linaro.org, broonie@kernel.org, gregkh@linuxfoundation.org, hdegoede@redhat.com, james.clark@arm.com, james@equiv.tech, keescook@chromium.org, petr.tesarik.ext@huawei.com, rafael@kernel.org, tglx@linutronix.de, Jeff LaBundy , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold Subject: Re: [RFC PATCH v2 2/7] of: Introduce hardware prober driver Message-ID: References: <20231109100606.1245545-1-wenst@chromium.org> <20231109100606.1245545-3-wenst@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231109100606.1245545-3-wenst@chromium.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231109_095446_907180_38C16186 X-CRM114-Status: GOOD ( 39.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Nov 09, 2023 at 06:05:59PM +0800, Chen-Yu Tsai wrote: > Some devices are designed and manufactured with some components having > multiple drop-in replacement options. These components are often > connected to the mainboard via ribbon cables, having the same signals > and pin assignments across all options. These may include the display > panel and touchscreen on laptops and tablets, and the trackpad on > laptops. Sometimes which component option is used in a particular device > can be detected by some firmware provided identifier, other times that > information is not available, and the kernel has to try to probe each > device. > > This change attempts to make the "probe each device" case cleaner. The > current approach is to have all options added and enabled in the device > tree. The kernel would then bind each device and run each driver's probe > function. This works, but has been broken before due to the introduction > of asynchronous probing, causing multiple instances requesting "shared" > resources, such as pinmuxes, GPIO pins, interrupt lines, at the same > time, with only one instance succeeding. Work arounds for these include > moving the pinmux to the parent I2C controller, using GPIO hogs or > pinmux settings to keep the GPIO pins in some fixed configuration, and > requesting the interrupt line very late. Such configurations can be seen > on the MT8183 Krane Chromebook tablets, and the Qualcomm sc8280xp-based > Lenovo Thinkpad 13S. > > Instead of this delicate dance between drivers and device tree quirks, > this change introduces a simple I2C component prober. For any given > class of devices on the same I2C bus, it will go through all of them, > doing a simple I2C read transfer and see which one of them responds. > It will then enable the device that responds. > > This requires some minor modifications in the existing device tree. > The status for all the device nodes for the component options must be > set to "failed-needs-probe-xxx". This makes it clear that some mechanism > is needed to enable one of them, and also prevents the prober and device > drivers running at the same time. ... > +config HW_PROBER config OF_HW_PROBER // or anything with explicit OF Don't give a false impression that this is something that may works without OF support. ... > + bool "Hardware Prober driver" Ditto. ... > +/* > + * hw_prober.c - Hardware prober driver Do not include filename into the file itself. > + * > + * Copyright (c) 2023 Google LLC > + */ ... > + node = of_find_node_by_name(NULL, node_name); > + if (!node) > + return dev_err_probe(&pdev->dev, -ENODEV, "Could not find %s device node\n", > + node_name); With struct device *dev = &pdev->dev; this and other lines can be made neater. ... For better maintenance it's good to have ret assignment be placed here ret = 0; > + for_each_child_of_node(i2c_node, node) { > + struct property *prop; > + union i2c_smbus_data data; > + u32 addr; > + > + if (!of_node_name_prefix(node, node_name)) > + continue; > + if (of_property_read_u32(node, "reg", &addr)) > + continue; > + if (i2c_smbus_xfer(i2c, addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data) < 0) > + continue; > + > + dev_info(&pdev->dev, "Enabling %pOF\n", node); > + > + prop = kzalloc(sizeof(*prop), GFP_KERNEL); > + if (!prop) { > + ret = -ENOMEM; > + of_node_put(node); > + break; > + } > + > + prop->name = "status"; > + prop->length = 5; > + prop->value = "okay"; > + > + /* Found a device that is responding */ > + ret = of_update_property(node, prop); > + if (ret) > + kfree(prop); > + > + of_node_put(node); > + break; > + } ... > +static const struct hw_prober_entry hw_prober_platforms[] = { > + { .compatible = "google,hana", .prober = i2c_component_prober, .data = "touchscreen" }, > + { .compatible = "google,hana", .prober = i2c_component_prober, .data = "trackpad" }, > +}; Why can't OF ID table be used for this? ... > + for (int i = 0; i < ARRAY_SIZE(hw_prober_platforms); i++) unsigned? > + if (of_machine_is_compatible(hw_prober_platforms[i].compatible)) { > + int ret; > + > + ret = hw_prober_platforms[i].prober(pdev, hw_prober_platforms[i].data); > + if (ret) > + return ret; > + } ... > + pdev = platform_device_register_simple(DRV_NAME, -1, NULL, 0); -1 is defined in the header, use that definition. > + if (!IS_ERR(pdev)) > + return 0; > + > + platform_driver_unregister(&hw_prober_driver); > + > + return PTR_ERR(pdev); Can you use standard pattern, i.e. checking for the _error_ condition? -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel