From nobody Sun Feb 8 09:25:52 2026 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4C0D1A0BC9 for ; Wed, 8 Jan 2025 01:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736299738; cv=none; b=BHAPIg7XBwtMHxZBVVhUHMlK6EXo9k7vcmfI6JgH0Rv6aLhvceucesWyuZPUt4MLffDYkLv2Zsu/QxhyHMWMPt2/PzpukmyHb/ZHEa7cR2Pdtfpy/nUkKnXQxSaKkjxsiqzTq+gA3JgngnKakRBB9Gnyufd0M5ZGHEEAU2tVRsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736299738; c=relaxed/simple; bh=4tV3lnlihbjKXefUypMNRce6dC18x2ab/02qc1skGvw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nN9emu/EN+2Tqne7lkXnGKVqCCc2XKCAwD/8TcXQLiL3Hccqq5Hc+uUpnhdr6kL6fvJQM4702Fxp1HPp/kVSUhnFXxS8nV5sG59ZXgcmW/mJ6UJ1OvmMfmOWgnVo8md5+0QxVKq1+hABUyCGDPEjcRWDZGKx32OwHTw87oh6CIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=jeUhedi7; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jeUhedi7" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ee46851b5eso19426208a91.1 for ; Tue, 07 Jan 2025 17:28:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1736299735; x=1736904535; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MfN6GTuNKF5VqrxYRWrKUqgkdrEWac7RU0Z/q9vfjN0=; b=jeUhedi7/s9vN6UXJTOMvaZ+0hVG1cW7wzd65GXE0qqjZzy3l3VqrhyVcM4iAujUU7 NPw6De5hcs57pFB1HvmTjRCZyN/7hI8pLTa/QExNL2LIamZfidmgOysJl3yvd4PMI6IT hPA3JDe0j1YBFzxc6VDPrWZNYbLGaR5/bOXo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736299735; x=1736904535; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MfN6GTuNKF5VqrxYRWrKUqgkdrEWac7RU0Z/q9vfjN0=; b=SfI/+83WoRtHHHjPYAHzT5dQ7nKy6MJd0r14uAj+hfK8C+XPUje9yRUcCkmPypDLTH Uj0xrV5p8yIBMAdN1dmPbaRsOy6hxy1nVgtHhDk7mu+hm/ujUoRvkqJSS/4TdngjzMfH +X+8R7t7+JZYRpXMq1nFIDyUq5HQlZMSnWYx4YMr1KgKDQvZYl4rBWGwp3VexeLOeBqq YL9Gx1MbSJsL24R93KnHasTCcpqJ99dAA2kF6X6ud3vMwGmgVNTJs8XDxmAKXZ3pvpmG ydqoIbdjGPrnFd8XruofX+3MJ3W3t6jGqoldJhuoVb2QOmc9duXIfdConGZ9Dh0efejg Mfrg== X-Gm-Message-State: AOJu0YwvHVTtn8kImP1OR0uhuXcVW6el+FMz8q3X1d2xfIl8pAbAm1wu D5eXghJDPTbMJ6AGdM+OjqWa7sghhObf8RR2XyDqLsEzY4sa3oSyJ6Yp5jPr5A== X-Gm-Gg: ASbGncu/VwhNysiTc6998bV6qbgYXV/QW53i4ox07juc8YwZQWiRJjuylRJpUOCTb7c 2JKVumBht/yBb/f4opLxuaEtcn87aFVRaCJy3X2k5ny7ZxB//+FUaTTEKHE66/Bws0WKK3tbFaq GwCayrFWKs4hQG8AtyIbz7RgdCwWsQhSuxc+oS9d+1WAs6YVK0PeQWBWsZZUYN+FEwVX/1QW9/U f2OypLRTv4cYYLgJG93jW5GFFe+zDSEEl3W7CdkUxiTkwI+vnIvL1tw0FDlaDtDp0497WJKv1J+ PSzpbb1T6wppKL7Gsjx6 X-Google-Smtp-Source: AGHT+IH4Y++Unzll3LBTxpHGSJAl9gWr9EZnywMb7/5iKVZRlAs9Kn/eOeYulAHPdNQ/JPBW9ae4bA== X-Received: by 2002:a17:90b:2c84:b0:2f4:47fc:7f18 with SMTP id 98e67ed59e1d1-2f548ebb679mr1630164a91.10.1736299735123; Tue, 07 Jan 2025 17:28:55 -0800 (PST) Received: from localhost (129.135.125.34.bc.googleusercontent.com. [34.125.135.129]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f54a13dcd5sm239559a91.0.2025.01.07.17.28.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jan 2025 17:28:54 -0800 (PST) From: Stephen Boyd To: Bjorn Andersson , Konrad Dybcio Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, devicetree@vger.kernel.org, Dmitry Baryshkov , Krzysztof Kozlowski , Rob Herring , linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Arnd Bergmann , Conor Dooley , Saravana Kannan , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Subject: [RFC PATCH 4/6] of: Extract alloc/add functions from of_platform_device_create_pdata() Date: Tue, 7 Jan 2025 17:28:41 -0800 Message-ID: <20250108012846.3275443-5-swboyd@chromium.org> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog In-Reply-To: <20250108012846.3275443-1-swboyd@chromium.org> References: <20250108012846.3275443-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow drivers to modify the 'struct device' for a device node by splitting of_platform_device_create_pdata() into two functions. The first function, of_platform_device_alloc(), allocates the platform device and the second function, of_platform_device_add(), adds the platform device to the platform bus. SoC power management drivers can use these APIs to allocate a platform device for a node underneath the soc node, attach pmdomains and/or set the device as runtime PM active, and finally add the platform device to the platform bus. Cc: Rob Herring Cc: Saravana Kannan Cc: Cc: Bjorn Andersson Cc: Konrad Dybcio Cc: Signed-off-by: Stephen Boyd --- drivers/of/platform.c | 80 ++++++++++++++++++++++++++++++------- include/linux/of_platform.h | 14 +++++++ 2 files changed, 79 insertions(+), 15 deletions(-) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 63a80c30d515..d8ee2d38a382 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -138,6 +138,66 @@ struct platform_device *of_device_alloc(struct device_= node *np, } EXPORT_SYMBOL(of_device_alloc); =20 +/** + * of_platform_device_alloc - Alloc and initialize an of_device + * @np: pointer to node to create device for + * @bus_id: name to assign device + * @parent: Linux device model parent device. + * + * Return: Pointer to created platform device, or NULL if a device was not + * allocated. Unavailable devices will not get allocated. + */ +struct platform_device * +of_platform_device_alloc(struct device_node *np, const char *bus_id, + struct device *parent) +{ + struct platform_device *ofdev; + + pr_debug("alloc platform device: %pOF\n", np); + + if (!of_device_is_available(np) || + of_node_test_and_set_flag(np, OF_POPULATED)) + return NULL; + + ofdev =3D of_device_alloc(np, bus_id, parent); + if (!ofdev) { + of_node_clear_flag(np, OF_POPULATED); + return ofdev; + } + + ofdev->dev.coherent_dma_mask =3D DMA_BIT_MASK(32); + if (!ofdev->dev.dma_mask) + ofdev->dev.dma_mask =3D &ofdev->dev.coherent_dma_mask; + ofdev->dev.bus =3D &platform_bus_type; + of_msi_configure(&ofdev->dev, ofdev->dev.of_node); + + return ofdev; +} +EXPORT_SYMBOL(of_platform_device_alloc); + +/** + * of_platform_device_add - Add an of_device to the platform bus + * @ofdev: of_device to add + * + * Return: 0 on success, negative errno on failure. + */ +int of_platform_device_add(struct platform_device *ofdev) +{ + struct device_node *np =3D ofdev->dev.of_node; + int ret; + + pr_debug("adding platform device: %pOF\n", np); + + ret =3D of_device_add(ofdev); + if (ret) { + platform_device_put(ofdev); + of_node_clear_flag(np, OF_POPULATED); + } + + return ret; +} +EXPORT_SYMBOL(of_platform_device_add); + /** * of_platform_device_create_pdata - Alloc, initialize and register an of_= device * @np: pointer to node to create device for @@ -154,29 +214,19 @@ static struct platform_device *of_platform_device_cre= ate_pdata( void *platform_data, struct device *parent) { + int ret; struct platform_device *dev; =20 pr_debug("create platform device: %pOF\n", np); =20 - if (!of_device_is_available(np) || - of_node_test_and_set_flag(np, OF_POPULATED)) + dev =3D of_platform_device_alloc(np, bus_id, parent); + if (!dev) return NULL; =20 - dev =3D of_device_alloc(np, bus_id, parent); - if (!dev) - goto err_clear_flag; - - dev->dev.coherent_dma_mask =3D DMA_BIT_MASK(32); - if (!dev->dev.dma_mask) - dev->dev.dma_mask =3D &dev->dev.coherent_dma_mask; - dev->dev.bus =3D &platform_bus_type; dev->dev.platform_data =3D platform_data; - of_msi_configure(&dev->dev, dev->dev.of_node); - - if (of_device_add(dev) !=3D 0) { - platform_device_put(dev); + ret =3D of_platform_device_add(dev); + if (ret) goto err_clear_flag; - } =20 return dev; =20 diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 17471ef8e092..e55c1371b560 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -71,6 +71,10 @@ extern int of_platform_bus_probe(struct device_node *roo= t, =20 #ifdef CONFIG_OF_ADDRESS /* Platform devices and busses creation */ +extern struct platform_device *of_platform_device_alloc(struct device_node= *np, + const char *bus_id, + struct device *parent); +extern int of_platform_device_add(struct platform_device *ofdev); extern struct platform_device *of_platform_device_create(struct device_nod= e *np, const char *bus_id, struct device *parent); @@ -91,6 +95,16 @@ extern int devm_of_platform_populate(struct device *dev); extern void devm_of_platform_depopulate(struct device *dev); #else /* Platform devices and busses creation */ +static inline struct platform_device *of_platform_device_alloc(struct devi= ce_node *np, + const char *bus_id, + struct device *parent) +{ + return NULL; +} +static inline int of_platform_device_add(struct platform_device *ofdev) +{ + return -ENODEV; +} static inline struct platform_device *of_platform_device_create(struct dev= ice_node *np, const char *bus_id, struct device *parent) --=20 https://chromeos.dev