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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 7FDDCFCA191 for ; Mon, 9 Mar 2026 23:03:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C0C610E5F6; Mon, 9 Mar 2026 23:03:49 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="gMjHQH/+"; dkim-atps=neutral Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11011004.outbound.protection.outlook.com [52.101.65.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id C9F0A10E5C7; Mon, 9 Mar 2026 19:09:35 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dMBWjDUMOg0DP8mJcVGPJnmVYKrAzI3jfcH5Zi15QynSY2x0/fO7M4qUT/8AC47TxaG4Ef0eKcH2EY96tUMRXcNm8mk/o6Z+e0lV/Wa1/+pNdy4Ztghm/Q4+keGCrcwvmDfDgVYCtaDV1V+nH31oiUH2RHpTbB27DJ0N81XPoYd7cBAw5URCOh/KAjMCF2BNDI4cB8T7dloxxf/pAShntGM4lscFv6RH+eIIQEggD/Xv6aDLKxTO4h/dhsuVlDRIiuqLGHpvxsSfTUEKqPf6go4FcRXbq61RIndqR9oxLjGttwJkzO1WTpSev5RCAWFnhTHnmrN3ULiGI/ptPOBmNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=36cKg4kTCAAhKk0XjVLIKcWJs9eC51sG5z3DOE1qP1o=; b=wNfkz38rhvaApTVKeHhlUOMeoyn/X0dM9MTNISmpr9N4Dn2F0QU+klya+5/amNy7IRg0DjYIdVOxJ2Bw9KxcOCq3PiD82HDx/pl1obHLabghmb+8LnH+r0a3xewwdbmNOQuttsA3PEotd1JnOd2m3hIKQ0wbz7EO0mZJGM49YetEh4sY7UypbxfNC8dKeYqfBcZvjcESBHAIkYDjlOtC0/CD00ijskb9DQRWdPBHOvr0oYyfJsFdW/GJe1N4xxSBE3Oc5qy4jAWerHWm06tEkjd/oR3O6kgBJpypUE/GY1lP6yY5d/q1z6l3YgM/wcae9gxesgkKAu11RzFgPoYVhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=36cKg4kTCAAhKk0XjVLIKcWJs9eC51sG5z3DOE1qP1o=; b=gMjHQH/+QYsLj2gLn3UqvPEqMImJF0y5BuZqqIgNEGgTAXhg2TiOJe9AiLZxF3xBZk+ujv91yt9gYygbamr1O+qtt9zhd71E/RKVxFLRdWa9v/IY+kJCwYkKDWZlVbsnj/tqfEWIBMbJhU8IE6XncB6ZX4iEtPVshJtf5huBawuTkV3AO6+TBQzrBQ/wGSWdZg9Wkrtj4QmJjB1U9RGDzcz8vYsNkINeCLt4GF5wumYbk4K5QFVHWiFgUNAqHYS4dbSMYrk1Jl2aagHjf22wsti0hai1uH3+C9InX+x6pshIr8YQAIAnARN4tckV6tjXD3J1vXut4mZZpp280enozQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) by AM9PR04MB7540.eurprd04.prod.outlook.com (2603:10a6:20b:283::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9678.25; Mon, 9 Mar 2026 19:09:33 +0000 Received: from AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4]) by AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4%4]) with mapi id 15.20.9678.023; Mon, 9 Mar 2026 19:09:33 +0000 From: Vladimir Oltean To: linux-phy@lists.infradead.org Cc: Vinod Koul , Neil Armstrong , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-can@vger.kernel.org, linux-gpio@vger.kernel.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org, spacemit@lists.linux.dev, UNGLinuxDriver@microchip.com, Dmitry Baryshkov Subject: [PATCH v3 phy-next 12/24] phy: move provider API out of public Date: Mon, 9 Mar 2026 21:08:30 +0200 Message-ID: <20260309190842.927634-13-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260309190842.927634-1-vladimir.oltean@nxp.com> References: <20260309190842.927634-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: VI1PR06CA0095.eurprd06.prod.outlook.com (2603:10a6:803:8c::24) To AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8585:EE_|AM9PR04MB7540:EE_ X-MS-Office365-Filtering-Correlation-Id: fa2ccf06-42e0-4a42-16e1-08de7e0f65ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|19092799006|1800799024|366016|10070799003|7416014|376014|13003099007|18082099003; X-Microsoft-Antispam-Message-Info: FkLvQG+cIjyzI8f5iLqCN9BYOavnr6o6mJvbE0JYDnSUxMcGPPMFKOVTMeWQNbw4FEgHcck40/bI1NCgWGBrtL0M6YC4dGb/wI4+aMcNutDyjVg3viwdqxWXg8sbFfPL9UP2C9JVIerSNhZi06eTbg1tWH0HKJeHdaYE+XFTl3RkQZE/wTBW9UTuCqs8c7FakmJ+dFm6X56iRDsNPs/ZobmBYt+/4l8ukJNBCXm6GnWrV5xgPRFNVSE8TDR1y4gWUPRt4pV7gjV2hmdg8M8hojrdeGLJV8/KJDdca/br6Zvf+PrWhZJkhLdqJsKSx+wiLwjZL5lJTiiVnDgNdXg/T91DddpNRp//2OcQbeOMmvvUDv8Kek72tVh+Wf8lxnSq1g5p6buyPhLbr6eAUCVkEpS9nRj3EnNsBvmoYQ0B+oEHDzpkmZbhtGuxtdaLZO4fGQ2tzRiOu9xz0aXy5EP61CM8lnNzG8bdu3aHzUpu3hZI5K8/qT1KFU5zmOum4Xs2vciKHB9YuUYlg3xy+7mZBXi1wLYSYJLoBJlfJc7s1l/DQfMwR+pF1zmwgmYgoVcJHDgZU/K72CX3Xxpv/3xLwhL4TcnhAixBvZp6MT6h5XElkDI7tUduozsjzhOJZPL5uJmwoe9x+txFCyedhHBBiV82/NcorjUYu32eZlBBO+WyL6Mb9hQkT3lDLyTirur6 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8585.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(19092799006)(1800799024)(366016)(10070799003)(7416014)(376014)(13003099007)(18082099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?4K7uYgCvF1iJVq52bhA37yxh3RzZUD1pXlJb4J1D1RLysN7vmz/v45V4oQKy?= =?us-ascii?Q?++AvMHrQfLKLat18TOH8XwRYZNr5wHpjTTRMWnUNaIjfjo11DEMPSPyVw/3a?= =?us-ascii?Q?744JzD9YSyqpTcF1lVyGc1tUbyJprbaZR1nx4QBwcYBz8CrVjD410K5iQLBK?= =?us-ascii?Q?2rvAZVCv7AY9T4KdX/OYzk4IieUP8S+jmw0+VmPlosIkwUPiTtpgzK7BQf8z?= =?us-ascii?Q?orxvSzbcJak5jbJrH2v/xzQM4Kfjz9Jl1Ksldqzfuc52kV29AZR9b9uG3vJH?= =?us-ascii?Q?IjWtBZ1qYKdnyUDLZKL4dvrTL40NNHkd865kU7TnlX5JEvgtMZU5iJcu62UK?= =?us-ascii?Q?1ZB77F7DHiqI4q45qjIBh3zahjR4lwiw2ALv2qwl3yNtdrKud0iYu2xb+5Xc?= =?us-ascii?Q?897PDHoCuPrT8OkkgMi0NPOynQtVojRhE6A4mgZLylLeFaU03+DOI+CQoKEs?= =?us-ascii?Q?fm0KY+1S21q+8eo4yym6MvvhVQ6/KfgP1cSkmRs56eYcUYPYWi8XYI3gEeJp?= =?us-ascii?Q?Wd6ugkN6S9kaUHqwJzb/NOimQ5epm+xI5Fuk3Oo63V1OJlnk3BNNFj/OM8fS?= =?us-ascii?Q?n0gSa4REW9Gv7r3UVzWFTgX22SpM5PlgKaxiYtl/mrpLTXge4U6irPqDyLZO?= =?us-ascii?Q?HEd1QhHsD2rI/jPD6+W2kcO2eihSXoEEG/MYBvKscqdWorFoYVtghmBUM4Cq?= =?us-ascii?Q?8c4kiNfI9um0kNgv0enOSya2OKNhZXgPfP/jXFeBy1dGvfRYihrNTepS0Vrg?= =?us-ascii?Q?UVkLuKhjODoZuINkCM3ckzBQMssHkB4I+8l7B6ZKHacUqhYPhw2xAyYCFAE8?= =?us-ascii?Q?N+4euYql6z1vgmoXEWJLHNh1IcTGQF0bw8GPsg9chjx/PGO7T/MqkOB8ujXa?= =?us-ascii?Q?j4nV7+dP7rfVDEW7Peyi7NvOIkHHuH1FQAcEgctA0o5QWGfu78i32Ffu5HQC?= =?us-ascii?Q?EjLiT4sPFHHPcbWmyDu+iDownWF5t4dbzkqBCpReMqpzrj15kn8ahmOMwTZ4?= =?us-ascii?Q?JFzzEfHlQ+PW4xCNchbfdf+mehop/qB4Lbk5JbTbBQA0PKNO2sCDLtDxWP+Y?= =?us-ascii?Q?bHGDwK7OQNZ+YDdyN3IcMWI6LtRTgOw+z5nahcAfDASs3hIjPeoAEw7HWfus?= =?us-ascii?Q?BVQI4VGc4Mq4n4Ml48pEv0HsTCc+epKxT4vOK5tK/LWnukeRR4dvpgvqao5Y?= =?us-ascii?Q?b5lSRILllwkIBarjUcXsGqaJsSYDqLcUELMYCsm8MiQ30eu0qLGTKqTA350c?= =?us-ascii?Q?VdArRFNncLo8XS63bKzEkSchebvKdm1KZOVy5M+3Mphf6RO9jdjWWd6y37f4?= =?us-ascii?Q?R+LuUPmncqkOmJrhLzA103U11c2qGd9YQZa+EvFosMDQT/PY8xFzFgS0tCXE?= =?us-ascii?Q?0o+18CxnHmq/ucYSJqNHC+DHLAji670tkZ7ZBExi5dTLdNlclCmx9l/pR0EA?= =?us-ascii?Q?ohane1xgD3rmfFlV6WbxglEM7dOc64e0g3/wM3r5EsnhPAZsX9pO+7FJ1rnN?= =?us-ascii?Q?hxAbHRFSBYe2zW6/ONU0I1PVk3rb4na87YzBtR1DBbS1qIkl/ha5YrF/LzkJ?= =?us-ascii?Q?6ciK4XUgXYqzg07TDydaApBq+woIchkvcZo7lyvfEJKf/yp0fQBaIbtPWBq0?= =?us-ascii?Q?hBmk7mwg9+3afZ6KeRSKG4GPYaXNNgdzm8DjQ+tJuvzCHmppqlG3u80gVeh0?= =?us-ascii?Q?Xm+8AOfN3m3cBTX3H49+d/c4L5Ljo79pk29+/2YVWIMjFSd5X1KNGm4LraI8?= =?us-ascii?Q?Nh8FSWZIEtxZAhFflgDAmwIfKWD9ssDK67zH8/i+aCtkpLUNwlN63TaSuYeu?= X-MS-Exchange-AntiSpam-MessageData-1: UAxshQK1iF4tKA94zfQPEf8M7vk3hljsH9M= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa2ccf06-42e0-4a42-16e1-08de7e0f65ca X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8585.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Mar 2026 19:09:33.3229 (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: C7OKKmtIfX0TTIYctZ3U0I7z/pCfUJjSS93nSDy7or2jTju2ZuxAJYS7Hf5DgyUYtetPp4qfoZq9X2ruUq/AfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7540 X-Mailman-Approved-At: Mon, 09 Mar 2026 23:03:19 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The major goal is to hide the contents of struct phy from consumer drivers. The idea with "phy-props.h" is that both consumers and providers make use of some data types. So both headers include "phy-props.h". Some slight points of contention. 1. phy_set_bus_width(): Vinod explains that despite the current caller situation (9 providers, 1 consumer), it is a consumer API function. The use case is that the controller (for example UFS) may have limitations and should set the expected lanes to be used and width on those lanes. A number of Generic PHYs can support multiple lanes and multiple width so this is way for controller telling I am using this configuration. 2. phy-provider.h should go to include/linux/phy/ or to drivers/phy/? We do have 3 PHY providers outside of drivers/phy/: drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_dphy.c drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c drivers/pinctrl/tegra/pinctrl-tegra-xusb.c but the practice is not encouraged, and with time, these should be moved to the subsystem. This is not something that I can do now. 3. We can no longer tolerate static inline helpers. Allowing these would make it impossible to hide the struct phy definition from consumers. I've made phy_get_mode(), phy_get_bus_width(), phy_set_bus_width() exported symbols in drivers/phy/phy-core.c. 4. This is not a change without side effects. In the transition we are no longer providing at all, and to PHY consumer drivers. However, the in-tree dependencies should all have been resolved. Also, the movement of phy-provider.h to drivers/phy/ is at least "interesting" for out of tree PHY provider drivers (this header is not deployed by make headers_install). However, it seems to be what Vinod is looking to see. For temporary compatibility, keep including the provider header. This will be removed when abuses are all gotten rid of. Signed-off-by: Vladimir Oltean Reviewed-by: Dmitry Baryshkov --- v2->v3: none v1->v2: - collect tag - fix path to phy-provider.h - update commit message with the 4th point of contention --- drivers/phy/phy-core.c | 34 +++ drivers/phy/phy-provider.h | 256 +++++++++++++++++ include/linux/phy/phy-props.h | 75 +++++ include/linux/phy/phy.h | 497 +++++++--------------------------- 4 files changed, 456 insertions(+), 406 deletions(-) create mode 100644 drivers/phy/phy-provider.h create mode 100644 include/linux/phy/phy-props.h diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 21aaf2f76e53..a1aff00fba7c 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -20,6 +20,22 @@ #include #include +#define to_phy(a) (container_of((a), struct phy, dev)) + +/** + * struct phy_lookup - PHY association in list of phys managed by the phy driver + * @node: list node + * @dev_id: the device of the association + * @con_id: connection ID string on device + * @phy: the phy of the association + */ +struct phy_lookup { + struct list_head node; + const char *dev_id; + const char *con_id; + struct phy *phy; +}; + static void phy_release(struct device *dev); static const struct class phy_class = { .name = "phy", @@ -606,6 +622,24 @@ int phy_validate(struct phy *phy, enum phy_mode mode, int submode, } EXPORT_SYMBOL_GPL(phy_validate); +enum phy_mode phy_get_mode(struct phy *phy) +{ + return phy->attrs.mode; +} +EXPORT_SYMBOL_GPL(phy_get_mode); + +int phy_get_bus_width(struct phy *phy) +{ + return phy->attrs.bus_width; +} +EXPORT_SYMBOL_GPL(phy_get_bus_width); + +void phy_set_bus_width(struct phy *phy, int bus_width) +{ + phy->attrs.bus_width = bus_width; +} +EXPORT_SYMBOL_GPL(phy_set_bus_width); + /** * _of_phy_get() - lookup and obtain a reference to a phy by phandle * @np: device_node for which to get the phy diff --git a/drivers/phy/phy-provider.h b/drivers/phy/phy-provider.h new file mode 100644 index 000000000000..0637278a2d8d --- /dev/null +++ b/drivers/phy/phy-provider.h @@ -0,0 +1,256 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * phy-provider.h -- Generic PHY provider API + * + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com + * + * Author: Kishon Vijay Abraham I + */ +#ifndef __PHY_PROVIDER_H +#define __PHY_PROVIDER_H + +#include +#include +#include +#include +#include + +struct phy; + +/** + * struct phy_ops - set of function pointers for performing phy operations + * @init: operation to be performed for initializing phy + * @exit: operation to be performed while exiting + * @power_on: powering on the phy + * @power_off: powering off the phy + * @set_mode: set the mode of the phy + * @set_media: set the media type of the phy (optional) + * @set_speed: set the speed of the phy (optional) + * @reset: resetting the phy + * @calibrate: calibrate the phy + * @notify_phystate: notify and configure the phy for a particular state + * @release: ops to be performed while the consumer relinquishes the PHY + * @owner: the module owner containing the ops + */ +struct phy_ops { + int (*init)(struct phy *phy); + int (*exit)(struct phy *phy); + int (*power_on)(struct phy *phy); + int (*power_off)(struct phy *phy); + int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode); + int (*set_media)(struct phy *phy, enum phy_media media); + int (*set_speed)(struct phy *phy, int speed); + + /** + * @configure: + * + * Optional. + * + * Used to change the PHY parameters. phy_init() must have + * been called on the phy. + * + * Returns: 0 if successful, an negative error code otherwise + */ + int (*configure)(struct phy *phy, union phy_configure_opts *opts); + + /** + * @validate: + * + * Optional. + * + * Used to check that the current set of parameters can be + * handled by the phy. Implementations are free to tune the + * parameters passed as arguments if needed by some + * implementation detail or constraints. It must not change + * any actual configuration of the PHY, so calling it as many + * times as deemed fit by the consumer must have no side + * effect. + * + * Returns: 0 if the configuration can be applied, an negative + * error code otherwise + */ + int (*validate)(struct phy *phy, enum phy_mode mode, int submode, + union phy_configure_opts *opts); + int (*reset)(struct phy *phy); + int (*calibrate)(struct phy *phy); + + /* notify phy connect status change */ + int (*connect)(struct phy *phy, int port); + int (*disconnect)(struct phy *phy, int port); + + int (*notify_phystate)(struct phy *phy, union phy_notify state); + void (*release)(struct phy *phy); + struct module *owner; +}; + +/** + * struct phy_attrs - represents phy attributes + * @bus_width: Data path width implemented by PHY + * @max_link_rate: Maximum link rate supported by PHY (units to be decided by producer and consumer) + * @mode: PHY mode + */ +struct phy_attrs { + u32 bus_width; + u32 max_link_rate; + enum phy_mode mode; +}; + +/** + * struct phy - represents the phy device + * @dev: phy device + * @id: id of the phy device + * @ops: function pointers for performing phy operations + * @mutex: mutex to protect phy_ops + * @lockdep_key: lockdep information for this mutex + * @init_count: used to protect when the PHY is used by multiple consumers + * @power_count: used to protect when the PHY is used by multiple consumers + * @attrs: used to specify PHY specific attributes + * @pwr: power regulator associated with the phy + * @debugfs: debugfs directory + */ +struct phy { + struct device dev; + int id; + const struct phy_ops *ops; + struct mutex mutex; + struct lock_class_key lockdep_key; + int init_count; + int power_count; + struct phy_attrs attrs; + struct regulator *pwr; + struct dentry *debugfs; +}; + +/** + * struct phy_provider - represents the phy provider + * @dev: phy provider device + * @children: can be used to override the default (dev->of_node) child node + * @owner: the module owner having of_xlate + * @list: to maintain a linked list of PHY providers + * @of_xlate: function pointer to obtain phy instance from phy pointer + */ +struct phy_provider { + struct device *dev; + struct device_node *children; + struct module *owner; + struct list_head list; + struct phy *(*of_xlate)(struct device *dev, + const struct of_phandle_args *args); +}; + +#define of_phy_provider_register(dev, xlate) \ + __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) + +#define devm_of_phy_provider_register(dev, xlate) \ + __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) + +#define of_phy_provider_register_full(dev, children, xlate) \ + __of_phy_provider_register(dev, children, THIS_MODULE, xlate) + +#define devm_of_phy_provider_register_full(dev, children, xlate) \ + __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate) + +static inline void phy_set_drvdata(struct phy *phy, void *data) +{ + dev_set_drvdata(&phy->dev, data); +} + +static inline void *phy_get_drvdata(struct phy *phy) +{ + return dev_get_drvdata(&phy->dev); +} + +#if IS_ENABLED(CONFIG_GENERIC_PHY) +struct phy *phy_create(struct device *dev, struct device_node *node, + const struct phy_ops *ops); +struct phy *devm_phy_create(struct device *dev, struct device_node *node, + const struct phy_ops *ops); +void phy_destroy(struct phy *phy); +void devm_phy_destroy(struct device *dev, struct phy *phy); + +struct phy_provider * +__of_phy_provider_register(struct device *dev, struct device_node *children, + struct module *owner, + struct phy *(*of_xlate)(struct device *dev, + const struct of_phandle_args *args)); +struct phy_provider * +__devm_of_phy_provider_register(struct device *dev, struct device_node *children, + struct module *owner, + struct phy *(*of_xlate)(struct device *dev, + const struct of_phandle_args *args)); +void of_phy_provider_unregister(struct phy_provider *phy_provider); +void devm_of_phy_provider_unregister(struct device *dev, + struct phy_provider *phy_provider); +int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id); +void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id); +struct phy *of_phy_simple_xlate(struct device *dev, + const struct of_phandle_args *args); +#else +static inline struct phy *phy_create(struct device *dev, + struct device_node *node, + const struct phy_ops *ops) +{ + return ERR_PTR(-ENOSYS); +} + +static inline struct phy *devm_phy_create(struct device *dev, + struct device_node *node, + const struct phy_ops *ops) +{ + return ERR_PTR(-ENOSYS); +} + +static inline void phy_destroy(struct phy *phy) +{ +} + +static inline void devm_phy_destroy(struct device *dev, struct phy *phy) +{ +} + +static inline struct phy_provider * +__of_phy_provider_register(struct device *dev, struct device_node *children, + struct module *owner, + struct phy *(*of_xlate)(struct device *dev, + const struct of_phandle_args *args)) +{ + return ERR_PTR(-ENOSYS); +} + +static inline struct phy_provider * +__devm_of_phy_provider_register(struct device *dev, struct device_node *children, + struct module *owner, + struct phy *(*of_xlate)(struct device *dev, + const struct of_phandle_args *args)) +{ + return ERR_PTR(-ENOSYS); +} + +static inline void of_phy_provider_unregister(struct phy_provider *phy_provider) +{ +} + +static inline void devm_of_phy_provider_unregister(struct device *dev, + struct phy_provider *phy_provider) +{ +} + +static inline int phy_create_lookup(struct phy *phy, const char *con_id, + const char *dev_id) +{ + return 0; +} + +static inline void phy_remove_lookup(struct phy *phy, const char *con_id, + const char *dev_id) +{ +} + +static inline struct phy *of_phy_simple_xlate(struct device *dev, + const struct of_phandle_args *args) +{ + return ERR_PTR(-ENOSYS); +} +#endif /* IS_ENABLED(CONFIG_GENERIC_PHY) */ + +#endif /* __PHY_PROVIDER_H */ diff --git a/include/linux/phy/phy-props.h b/include/linux/phy/phy-props.h new file mode 100644 index 000000000000..11f36738165f --- /dev/null +++ b/include/linux/phy/phy-props.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * phy-provider.h -- Generic PHY properties + * + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com + * + * Author: Kishon Vijay Abraham I + */ +#ifndef __PHY_PROPS_H +#define __PHY_PROPS_H + +#include +#include +#include +#include + +enum phy_mode { + PHY_MODE_INVALID, + PHY_MODE_USB_HOST, + PHY_MODE_USB_HOST_LS, + PHY_MODE_USB_HOST_FS, + PHY_MODE_USB_HOST_HS, + PHY_MODE_USB_HOST_SS, + PHY_MODE_USB_DEVICE, + PHY_MODE_USB_DEVICE_LS, + PHY_MODE_USB_DEVICE_FS, + PHY_MODE_USB_DEVICE_HS, + PHY_MODE_USB_DEVICE_SS, + PHY_MODE_USB_OTG, + PHY_MODE_UFS_HS_A, + PHY_MODE_UFS_HS_B, + PHY_MODE_PCIE, + PHY_MODE_ETHERNET, + PHY_MODE_MIPI_DPHY, + PHY_MODE_SATA, + PHY_MODE_LVDS, + PHY_MODE_DP, + PHY_MODE_HDMI, +}; + +enum phy_media { + PHY_MEDIA_DEFAULT, + PHY_MEDIA_SR, + PHY_MEDIA_DAC, +}; + +enum phy_ufs_state { + PHY_UFS_HIBERN8_ENTER, + PHY_UFS_HIBERN8_EXIT, +}; + +union phy_notify { + enum phy_ufs_state ufs_state; +}; + +/** + * union phy_configure_opts - Opaque generic phy configuration + * + * @mipi_dphy: Configuration set applicable for phys supporting + * the MIPI_DPHY phy mode. + * @dp: Configuration set applicable for phys supporting + * the DisplayPort protocol. + * @lvds: Configuration set applicable for phys supporting + * the LVDS phy mode. + * @hdmi: Configuration set applicable for phys supporting + * the HDMI phy mode. + */ +union phy_configure_opts { + struct phy_configure_opts_mipi_dphy mipi_dphy; + struct phy_configure_opts_dp dp; + struct phy_configure_opts_lvds lvds; + struct phy_configure_opts_hdmi hdmi; +}; + +#endif /* __PHY_PROPS_H */ diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index ea47975e288a..f208edd25afe 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -1,246 +1,38 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /* - * phy.h -- generic phy header file + * phy.h -- Generic PHY consumer API * * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com * * Author: Kishon Vijay Abraham I */ -#ifndef __DRIVERS_PHY_H -#define __DRIVERS_PHY_H +#ifndef __PHY_CONSUMER_H +#define __PHY_CONSUMER_H -#include -#include -#include -#include -#include +#include -#include -#include -#include -#include +#include "../../../drivers/phy/phy-provider.h" +struct device; +struct device_node; struct phy; -enum phy_mode { - PHY_MODE_INVALID, - PHY_MODE_USB_HOST, - PHY_MODE_USB_HOST_LS, - PHY_MODE_USB_HOST_FS, - PHY_MODE_USB_HOST_HS, - PHY_MODE_USB_HOST_SS, - PHY_MODE_USB_DEVICE, - PHY_MODE_USB_DEVICE_LS, - PHY_MODE_USB_DEVICE_FS, - PHY_MODE_USB_DEVICE_HS, - PHY_MODE_USB_DEVICE_SS, - PHY_MODE_USB_OTG, - PHY_MODE_UFS_HS_A, - PHY_MODE_UFS_HS_B, - PHY_MODE_PCIE, - PHY_MODE_ETHERNET, - PHY_MODE_MIPI_DPHY, - PHY_MODE_SATA, - PHY_MODE_LVDS, - PHY_MODE_DP, - PHY_MODE_HDMI, -}; - -enum phy_media { - PHY_MEDIA_DEFAULT, - PHY_MEDIA_SR, - PHY_MEDIA_DAC, -}; - -enum phy_ufs_state { - PHY_UFS_HIBERN8_ENTER, - PHY_UFS_HIBERN8_EXIT, -}; - -union phy_notify { - enum phy_ufs_state ufs_state; -}; - -/** - * union phy_configure_opts - Opaque generic phy configuration - * - * @mipi_dphy: Configuration set applicable for phys supporting - * the MIPI_DPHY phy mode. - * @dp: Configuration set applicable for phys supporting - * the DisplayPort protocol. - * @lvds: Configuration set applicable for phys supporting - * the LVDS phy mode. - * @hdmi: Configuration set applicable for phys supporting - * the HDMI phy mode. - */ -union phy_configure_opts { - struct phy_configure_opts_mipi_dphy mipi_dphy; - struct phy_configure_opts_dp dp; - struct phy_configure_opts_lvds lvds; - struct phy_configure_opts_hdmi hdmi; -}; - -/** - * struct phy_ops - set of function pointers for performing phy operations - * @init: operation to be performed for initializing phy - * @exit: operation to be performed while exiting - * @power_on: powering on the phy - * @power_off: powering off the phy - * @set_mode: set the mode of the phy - * @set_media: set the media type of the phy (optional) - * @set_speed: set the speed of the phy (optional) - * @reset: resetting the phy - * @calibrate: calibrate the phy - * @notify_phystate: notify and configure the phy for a particular state - * @release: ops to be performed while the consumer relinquishes the PHY - * @owner: the module owner containing the ops - */ -struct phy_ops { - int (*init)(struct phy *phy); - int (*exit)(struct phy *phy); - int (*power_on)(struct phy *phy); - int (*power_off)(struct phy *phy); - int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode); - int (*set_media)(struct phy *phy, enum phy_media media); - int (*set_speed)(struct phy *phy, int speed); - - /** - * @configure: - * - * Optional. - * - * Used to change the PHY parameters. phy_init() must have - * been called on the phy. - * - * Returns: 0 if successful, an negative error code otherwise - */ - int (*configure)(struct phy *phy, union phy_configure_opts *opts); - - /** - * @validate: - * - * Optional. - * - * Used to check that the current set of parameters can be - * handled by the phy. Implementations are free to tune the - * parameters passed as arguments if needed by some - * implementation detail or constraints. It must not change - * any actual configuration of the PHY, so calling it as many - * times as deemed fit by the consumer must have no side - * effect. - * - * Returns: 0 if the configuration can be applied, an negative - * error code otherwise - */ - int (*validate)(struct phy *phy, enum phy_mode mode, int submode, - union phy_configure_opts *opts); - int (*reset)(struct phy *phy); - int (*calibrate)(struct phy *phy); - - /* notify phy connect status change */ - int (*connect)(struct phy *phy, int port); - int (*disconnect)(struct phy *phy, int port); - - int (*notify_phystate)(struct phy *phy, union phy_notify state); - void (*release)(struct phy *phy); - struct module *owner; -}; - -/** - * struct phy_attrs - represents phy attributes - * @bus_width: Data path width implemented by PHY - * @max_link_rate: Maximum link rate supported by PHY (units to be decided by producer and consumer) - * @mode: PHY mode - */ -struct phy_attrs { - u32 bus_width; - u32 max_link_rate; - enum phy_mode mode; -}; - -/** - * struct phy - represents the phy device - * @dev: phy device - * @id: id of the phy device - * @ops: function pointers for performing phy operations - * @mutex: mutex to protect phy_ops - * @lockdep_key: lockdep information for this mutex - * @init_count: used to protect when the PHY is used by multiple consumers - * @power_count: used to protect when the PHY is used by multiple consumers - * @attrs: used to specify PHY specific attributes - * @pwr: power regulator associated with the phy - * @debugfs: debugfs directory - */ -struct phy { - struct device dev; - int id; - const struct phy_ops *ops; - struct mutex mutex; - struct lock_class_key lockdep_key; - int init_count; - int power_count; - struct phy_attrs attrs; - struct regulator *pwr; - struct dentry *debugfs; -}; - -/** - * struct phy_provider - represents the phy provider - * @dev: phy provider device - * @children: can be used to override the default (dev->of_node) child node - * @owner: the module owner having of_xlate - * @list: to maintain a linked list of PHY providers - * @of_xlate: function pointer to obtain phy instance from phy pointer - */ -struct phy_provider { - struct device *dev; - struct device_node *children; - struct module *owner; - struct list_head list; - struct phy * (*of_xlate)(struct device *dev, - const struct of_phandle_args *args); -}; - -/** - * struct phy_lookup - PHY association in list of phys managed by the phy driver - * @node: list node - * @dev_id: the device of the association - * @con_id: connection ID string on device - * @phy: the phy of the association - */ -struct phy_lookup { - struct list_head node; - const char *dev_id; - const char *con_id; - struct phy *phy; -}; - -#define to_phy(a) (container_of((a), struct phy, dev)) - -#define of_phy_provider_register(dev, xlate) \ - __of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) - -#define devm_of_phy_provider_register(dev, xlate) \ - __devm_of_phy_provider_register((dev), NULL, THIS_MODULE, (xlate)) - -#define of_phy_provider_register_full(dev, children, xlate) \ - __of_phy_provider_register(dev, children, THIS_MODULE, xlate) - -#define devm_of_phy_provider_register_full(dev, children, xlate) \ - __devm_of_phy_provider_register(dev, children, THIS_MODULE, xlate) - -static inline void phy_set_drvdata(struct phy *phy, void *data) -{ - dev_set_drvdata(&phy->dev, data); -} - -static inline void *phy_get_drvdata(struct phy *phy) -{ - return dev_get_drvdata(&phy->dev); -} - #if IS_ENABLED(CONFIG_GENERIC_PHY) +struct phy *phy_get(struct device *dev, const char *string); +struct phy *devm_phy_get(struct device *dev, const char *string); +struct phy *devm_phy_optional_get(struct device *dev, const char *string); +struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, + const char *con_id); +struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np, + const char *con_id); +struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, + int index); +void of_phy_put(struct phy *phy); +void phy_put(struct device *dev, struct phy *phy); +void devm_phy_put(struct device *dev, struct phy *phy); +struct phy *of_phy_get(struct device_node *np, const char *con_id); + int phy_pm_runtime_get(struct phy *phy); int phy_pm_runtime_get_sync(struct phy *phy); void phy_pm_runtime_put(struct phy *phy); @@ -257,59 +49,69 @@ int phy_set_speed(struct phy *phy, int speed); int phy_configure(struct phy *phy, union phy_configure_opts *opts); int phy_validate(struct phy *phy, enum phy_mode mode, int submode, union phy_configure_opts *opts); - -static inline enum phy_mode phy_get_mode(struct phy *phy) -{ - return phy->attrs.mode; -} +enum phy_mode phy_get_mode(struct phy *phy); int phy_reset(struct phy *phy); int phy_calibrate(struct phy *phy); int phy_notify_connect(struct phy *phy, int port); int phy_notify_disconnect(struct phy *phy, int port); int phy_notify_state(struct phy *phy, union phy_notify state); -static inline int phy_get_bus_width(struct phy *phy) +int phy_get_bus_width(struct phy *phy); +void phy_set_bus_width(struct phy *phy, int bus_width); +#else +static inline struct phy *phy_get(struct device *dev, const char *string) { - return phy->attrs.bus_width; + return ERR_PTR(-ENOSYS); } -static inline void phy_set_bus_width(struct phy *phy, int bus_width) + +static inline struct phy *devm_phy_get(struct device *dev, const char *string) { - phy->attrs.bus_width = bus_width; + return ERR_PTR(-ENOSYS); } -struct phy *phy_get(struct device *dev, const char *string); -struct phy *devm_phy_get(struct device *dev, const char *string); -struct phy *devm_phy_optional_get(struct device *dev, const char *string); -struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, - const char *con_id); -struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np, - const char *con_id); -struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, - int index); -void of_phy_put(struct phy *phy); -void phy_put(struct device *dev, struct phy *phy); -void devm_phy_put(struct device *dev, struct phy *phy); -struct phy *of_phy_get(struct device_node *np, const char *con_id); -struct phy *of_phy_simple_xlate(struct device *dev, - const struct of_phandle_args *args); -struct phy *phy_create(struct device *dev, struct device_node *node, - const struct phy_ops *ops); -struct phy *devm_phy_create(struct device *dev, struct device_node *node, - const struct phy_ops *ops); -void phy_destroy(struct phy *phy); -void devm_phy_destroy(struct device *dev, struct phy *phy); -struct phy_provider *__of_phy_provider_register(struct device *dev, - struct device_node *children, struct module *owner, - struct phy * (*of_xlate)(struct device *dev, - const struct of_phandle_args *args)); -struct phy_provider *__devm_of_phy_provider_register(struct device *dev, - struct device_node *children, struct module *owner, - struct phy * (*of_xlate)(struct device *dev, - const struct of_phandle_args *args)); -void of_phy_provider_unregister(struct phy_provider *phy_provider); -void devm_of_phy_provider_unregister(struct device *dev, - struct phy_provider *phy_provider); -int phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id); -void phy_remove_lookup(struct phy *phy, const char *con_id, const char *dev_id); -#else + +static inline struct phy *devm_phy_optional_get(struct device *dev, + const char *string) +{ + return NULL; +} + +static inline struct phy *devm_of_phy_get(struct device *dev, + struct device_node *np, + const char *con_id) +{ + return ERR_PTR(-ENOSYS); +} + +static inline struct phy *devm_of_phy_optional_get(struct device *dev, + struct device_node *np, + const char *con_id) +{ + return NULL; +} + +static inline struct phy *devm_of_phy_get_by_index(struct device *dev, + struct device_node *np, + int index) +{ + return ERR_PTR(-ENOSYS); +} + +static inline void of_phy_put(struct phy *phy) +{ +} + +static inline void phy_put(struct device *dev, struct phy *phy) +{ +} + +static inline void devm_phy_put(struct device *dev, struct phy *phy) +{ +} + +static inline struct phy *of_phy_get(struct device_node *np, const char *con_id) +{ + return ERR_PTR(-ENOSYS); +} + static inline int phy_pm_runtime_get(struct phy *phy) { if (!phy) @@ -388,61 +190,59 @@ static inline int phy_set_speed(struct phy *phy, int speed) return -ENODEV; } -static inline enum phy_mode phy_get_mode(struct phy *phy) -{ - return PHY_MODE_INVALID; -} - -static inline int phy_reset(struct phy *phy) +static inline int phy_configure(struct phy *phy, + union phy_configure_opts *opts) { if (!phy) return 0; return -ENOSYS; } -static inline int phy_calibrate(struct phy *phy) +static inline int phy_validate(struct phy *phy, enum phy_mode mode, int submode, + union phy_configure_opts *opts) { if (!phy) return 0; return -ENOSYS; } -static inline int phy_notify_connect(struct phy *phy, int index) +static inline enum phy_mode phy_get_mode(struct phy *phy) +{ + return PHY_MODE_INVALID; +} + +static inline int phy_reset(struct phy *phy) { if (!phy) return 0; return -ENOSYS; } -static inline int phy_notify_disconnect(struct phy *phy, int index) +static inline int phy_calibrate(struct phy *phy) { if (!phy) return 0; return -ENOSYS; } -static inline int phy_notify_state(struct phy *phy, union phy_notify state) +static inline int phy_notify_connect(struct phy *phy, int index) { if (!phy) return 0; return -ENOSYS; } -static inline int phy_configure(struct phy *phy, - union phy_configure_opts *opts) +static inline int phy_notify_disconnect(struct phy *phy, int index) { if (!phy) return 0; - return -ENOSYS; } -static inline int phy_validate(struct phy *phy, enum phy_mode mode, int submode, - union phy_configure_opts *opts) +static inline int phy_notify_state(struct phy *phy, union phy_notify state) { if (!phy) return 0; - return -ENOSYS; } @@ -453,122 +253,7 @@ static inline int phy_get_bus_width(struct phy *phy) static inline void phy_set_bus_width(struct phy *phy, int bus_width) { - return; -} - -static inline struct phy *phy_get(struct device *dev, const char *string) -{ - return ERR_PTR(-ENOSYS); -} - -static inline struct phy *devm_phy_get(struct device *dev, const char *string) -{ - return ERR_PTR(-ENOSYS); -} - -static inline struct phy *devm_phy_optional_get(struct device *dev, - const char *string) -{ - return NULL; -} - -static inline struct phy *devm_of_phy_get(struct device *dev, - struct device_node *np, - const char *con_id) -{ - return ERR_PTR(-ENOSYS); -} - -static inline struct phy *devm_of_phy_optional_get(struct device *dev, - struct device_node *np, - const char *con_id) -{ - return NULL; -} - -static inline struct phy *devm_of_phy_get_by_index(struct device *dev, - struct device_node *np, - int index) -{ - return ERR_PTR(-ENOSYS); -} - -static inline void of_phy_put(struct phy *phy) -{ -} - -static inline void phy_put(struct device *dev, struct phy *phy) -{ -} - -static inline void devm_phy_put(struct device *dev, struct phy *phy) -{ -} - -static inline struct phy *of_phy_get(struct device_node *np, const char *con_id) -{ - return ERR_PTR(-ENOSYS); -} - -static inline struct phy *of_phy_simple_xlate(struct device *dev, - const struct of_phandle_args *args) -{ - return ERR_PTR(-ENOSYS); -} - -static inline struct phy *phy_create(struct device *dev, - struct device_node *node, - const struct phy_ops *ops) -{ - return ERR_PTR(-ENOSYS); -} - -static inline struct phy *devm_phy_create(struct device *dev, - struct device_node *node, - const struct phy_ops *ops) -{ - return ERR_PTR(-ENOSYS); -} - -static inline void phy_destroy(struct phy *phy) -{ -} - -static inline void devm_phy_destroy(struct device *dev, struct phy *phy) -{ -} - -static inline struct phy_provider *__of_phy_provider_register( - struct device *dev, struct device_node *children, struct module *owner, - struct phy * (*of_xlate)(struct device *dev, - const struct of_phandle_args *args)) -{ - return ERR_PTR(-ENOSYS); -} - -static inline struct phy_provider *__devm_of_phy_provider_register(struct device - *dev, struct device_node *children, struct module *owner, - struct phy * (*of_xlate)(struct device *dev, - const struct of_phandle_args *args)) -{ - return ERR_PTR(-ENOSYS); -} - -static inline void of_phy_provider_unregister(struct phy_provider *phy_provider) -{ -} - -static inline void devm_of_phy_provider_unregister(struct device *dev, - struct phy_provider *phy_provider) -{ -} -static inline int -phy_create_lookup(struct phy *phy, const char *con_id, const char *dev_id) -{ - return 0; } -static inline void phy_remove_lookup(struct phy *phy, const char *con_id, - const char *dev_id) { } -#endif +#endif /* IS_ENABLED(CONFIG_GENERIC_PHY) */ -#endif /* __DRIVERS_PHY_H */ +#endif /* __PHY_CONSUMER_H */ -- 2.43.0