From patchwork Mon Oct 19 18:03:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vabhav Sharma (OSS)" X-Patchwork-Id: 1384474 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oss.nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-NXP1-onmicrosoft-com header.b=RYigx7hF; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CFQl70C43z9sT6 for ; Tue, 20 Oct 2020 05:48:50 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C29BA823E5; Mon, 19 Oct 2020 20:48:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="RYigx7hF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ECE43822CD; Mon, 19 Oct 2020 20:10:23 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER,SPF_HELO_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0621.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::621]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D047B81F7C for ; Mon, 19 Oct 2020 20:10:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=oss.nxp.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vabhav.sharma@oss.nxp.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mhO9O0o8H6gJW2h6M/3QC7H8UzSHNijca9fJX0JOtA1tzdKoxnAZtLnAwccIxs0XkFi17Z1MMebhDY3weE1xgtOvTrlyG0CX6nigijZl96iNqLNMgzs0EH0lbIihyH1rCybqkowr2efAliFm5/C8wiAS+3Qqi+tYeQFpJn2NEyKbyr6fvlLtX1N/61E0NTjWNJNdFF+d9U8MCAvO6ILFFbCZPeeh6mcjDI9cyBosj3MW0f8MWJddchPwzjLLSWaYSVhEE48I2wURpxaxXFvQPqivPg68aNUBtAFjMfVtr1UTnM8Y7FFSyaaATAv2WXbD5HhA3TUEK55JSEpePI5Ejw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sqJSOntixKrfB1m1BrI4F/8BLGXOJ8OjVVUpiUKF6hw=; b=LkxNHm5XSAabjC94429fsjb/+PK+BQRueH2RgtGA30Gvz9B2z/ctekaCQHukP7Dq92V9I1fV6YnXLYF58E2Ka7LxWqx1lpSGZMH69fhfIo89eomTWCiNg5eAFvGIumjL2NUoR+4PSFeWpVv6XoC2CIuTUBHRO+vmZZoXLOaeGTUyt9j4IHCJFjesRN+hNcg/q+d2U/tOkyRETewn5pm0hNsOyptadGA1HruxfbqEDj+huFJ5P4ObKXlGZ1fN7hm1/ZUI+c4fg5yKwFwBccRYiAyqzFkUV7Z7FkdXkAMKo5GrggJ4egjdOyl0Ef4UXV4J6rGT0tW09WSR+c1jSGPZWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sqJSOntixKrfB1m1BrI4F/8BLGXOJ8OjVVUpiUKF6hw=; b=RYigx7hF+iDariCHlhv9KJzn5VwvVPfT+sUCtMYSh00HJUtiVqIDPaCQDf8eg2kGDxu3Wd7hT0C8C3KnNh3UZ/gHwnaC+iQhQv7bX3Gu2bjb1R5K597w89OcCzAUXe+6fFrOrXcdUh+88jLSdaQyb0hvc4YR773qSD95/DxzVp8= Authentication-Results: chromium.org; dkim=none (message not signed) header.d=none;chromium.org; dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB4800.eurprd04.prod.outlook.com (2603:10a6:803:5a::12) by VI1PR0402MB3373.eurprd04.prod.outlook.com (2603:10a6:803:a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.28; Mon, 19 Oct 2020 18:10:19 +0000 Received: from VI1PR04MB4800.eurprd04.prod.outlook.com ([fe80::c83f:7144:6c80:e73e]) by VI1PR04MB4800.eurprd04.prod.outlook.com ([fe80::c83f:7144:6c80:e73e%4]) with mapi id 15.20.3477.028; Mon, 19 Oct 2020 18:10:19 +0000 From: Vabhav Sharma To: sjg@chromium.org, sr@denx.de Cc: u-boot@lists.denx.de, V.Sethi@nxp.com, andre.przywara@arm.com, Vabhav Sharma Subject: [PATCH v3 1/2] dm: core: add function uclass_probe_all() to probe all devices Date: Mon, 19 Oct 2020 23:33:07 +0530 Message-Id: <1603130588-10500-2-git-send-email-vabhav.sharma@oss.nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1603130588-10500-1-git-send-email-vabhav.sharma@oss.nxp.com> References: <1603130588-10500-1-git-send-email-vabhav.sharma@oss.nxp.com> X-Originating-IP: [92.120.0.71] X-ClientProxiedBy: SG2PR06CA0242.apcprd06.prod.outlook.com (2603:1096:4:ac::26) To VI1PR04MB4800.eurprd04.prod.outlook.com (2603:10a6:803:5a::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from uefi-OptiPlex-790.ap.freescale.net (92.120.0.71) by SG2PR06CA0242.apcprd06.prod.outlook.com (2603:1096:4:ac::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3477.22 via Frontend Transport; Mon, 19 Oct 2020 18:10:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d0796b82-3f37-442a-1f01-08d8745a3cfa X-MS-TrafficTypeDiagnostic: VI1PR0402MB3373: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bepnc+x2OStgQrVn3J/f60l94de7PKyidqJWyw72l2n+R2RNML0VOoyXnSu1Pvm1EoPEQNWMrpgfChG3pNL1ePoZgwnZFn3gFE+5XtAHnIApJDTJ142EsXYPuXZ+gLgPnMD/wpodoKGJcrM6MJrXY6K+ML5mKni9ynIAh1rq/kPwUxCoNp0Nqzt6jXpbwTfqt8Dbtw9jQ5udua3o/F70tyr1AvTmOXmFUyzt8CGzgnEgoEKKPNzl2SYgxPdGhr7l03vZfNyADVANKYEkIYUswbXJvgPm0CQjRIOUeMZhmPrwHtXee5oO1QgrUbDHyLpHDZe6Gxs8cHn0ltfQLnSSr+tWAIZ5yz3Q2pvlPfgSbBEfrvGAjGg6rCpcYjJer4ZAlSSMtbawfaMuu8aHqpVFjA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB4800.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(366004)(396003)(39860400002)(376002)(346002)(4326008)(6666004)(6512007)(44832011)(956004)(2616005)(6486002)(16526019)(186003)(26005)(52116002)(66556008)(66476007)(86362001)(8936002)(478600001)(8676002)(5660300002)(316002)(966005)(6506007)(2906002)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 6W+iPsOAdBZPhHBLRx05stnKOGmNC8XidNGJjKpNv9BnTQIzoN1yEYmbToSg2KSIdLfIdo0z5Exio0oJDdeyrnCLL9sdPdlYwO+TdoT1yCXhjXTQo98La2+JXpr2xbtYCYNb/OB7ZL6O8d4zfgfCaw2K6ZaE9gJr1/LSUxborJauXnI5R0rXiMC3t92ekq1mDv6zXVJ0MbZp+WzC/QnEqEdRQNtlVL6xvZ2HguNRqLFdHCKqvSs4dUAdQ7t9kEN7E4qZLdGd03qIYN5sEusUI8vjtma7+mUdZ6kARCgIs/0rJ/16tzmIVytl66Bt/2ce5OX9Ky6qvFCCsUMwhfss86J6BFTTWOZi0xh1L4Isq43YfvrnHVvv8HOAbEsn450C5GQmcrdOWgzXt1E6Nj7vITlNLufe128/rivuyaYCaJ6Ir/LUOS/HR/OK5fWlrCFhShCdiug7fqfPjced1PRfmbFqXP2yA/lpA5zEwOj6LKitYDAy16Et+R3OIQnk+CoEMZ1YjzGgtCTGLlL5J1mN4hBf2UoQmf7Dn72ukuPZHwPbUDxnt+AIFruFf1almPyCX4B6dTPIIvPkIOAc4C1QYYeYdkuU/N/Q4tK/M7V1w1dX5eIuW4FeBSHMR7Rf9PRxQ+E4W+/QtKyxPXpPP+mnhg== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0796b82-3f37-442a-1f01-08d8745a3cfa X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB4800.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2020 18:10:19.5046 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0Urd1dZ8jwFJyDctJd1vK0BCfTzL2yAmLjR/Phi3L0YDgpeqeZGSU/hHq+RU2VX01a2+BNUnAD01kRwGBQhmcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3373 X-Mailman-Approved-At: Mon, 19 Oct 2020 20:48:19 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Vabhav Sharma Support a common method to probe all devices associated with uclass. This includes data structures and code for finding the first device and looping for remaining devices associated with uclasses (groups of devices with the same purpose, e.g. all SERIAL ports will be in the same uclass). An example is SBSA compliant PL011 UART IP, where firmware does the serial port initialization and prepare uart device to let the kernel use it for sending and reveiving the characters.SERIAL uclass will use this function to initialize PL011 UART ports. The feature is enabled with CONFIG_DM. Signed-off-by: Vabhav Sharma Reviewed-by: Stefan Roese Reviewed-by: Simon Glass --- v3: Incorporated review comments of Stephan,Simon Related discussion https://patchwork.ozlabs.org/project/uboot/patch/1601400 385-11854-1-git-send-email-vabhav.sharma@oss.nxp.com/ --- drivers/core/uclass.c | 17 +++++++++++++++++ include/dm/uclass.h | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index c3f1b73..0725e8e 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev) } #endif +int uclass_probe_all(enum uclass_id id) +{ + struct udevice *dev; + int ret; + + ret = uclass_first_device(id, &dev); + if (ret || !dev) + return ret; + if (dev) { + /* Scanning uclass to probe all devices */ + for (; dev; uclass_next_device(&dev)) + ; + } + + return 0; +} + UCLASS_DRIVER(nop) = { .id = UCLASS_NOP, .name = "nop", diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 67ff746..0fce83f 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data, int uclass_resolve_seq(struct udevice *dev); /** + * uclass_probe_all() - Probe all devices based on an uclass ID + * + * Every uclass is identified by an ID, a number from 0 to n-1 where n is + * the number of uclasses. This function probe all devices asocciated with + * a uclass by looking its ID. + * + * @id: uclass ID to look up + * @return 0 if OK, other -ve on error + */ +int uclass_probe_all(enum uclass_id id); + +/** * uclass_id_foreach_dev() - Helper function to iteration through devices * * This creates a for() loop which works through the available devices in