Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3813346rwb; Sun, 20 Nov 2022 22:59:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf731mgCFfgksx5iEqdD7ZOkaAkZomaY0UygIH5OM+cn6vhB49UMpE+MsvGx4VeSIHH7mdzz X-Received: by 2002:aa7:c30c:0:b0:469:80b7:a16a with SMTP id l12-20020aa7c30c000000b0046980b7a16amr1931433edq.306.1669013956911; Sun, 20 Nov 2022 22:59:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669013956; cv=none; d=google.com; s=arc-20160816; b=mxmGtt7q00DMk/x7d/3JwAjvS51ZXsLHKj/RxPKz13ug4RMc8wJg4gL7cAhsuBCmeK FQt3liidR6Tf+0hR/Z+xiyIrcgb/IEqOAZwTuamZbZhkSDRcyihDTo1/KDdpNy44GuDa vdi1Xk2DFNdSR/cd3o5gqwkLH3pH/3mtMtiJFY+lT+fi4x7D34piiEIUuqdIocPk05ih EloLDB7XngOsqUJnvSAHUPo8gOai5BmYLLDq+iwJ7Y9POeRkmV18jmwrnzRCXRpV2TZM jqmW5upeweeHgQOLgUbX5IvE9S00Ul9BPeOvplu428CWugSVblDj0+N6vZOZYA3fqP0U 3T5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=L7+eqek/E/WnqdTO067PuTCEyXCliseIp9lN/F5T2O4=; b=d2cQkPJA2QVREjvXl68EFykfaXKOeaYBS4Fitkwez7K0V4tMYC/IKTdoMyRn4icjak ICvB/TipscWMRrQ9vREmwnpvEZCj/bxLj50QV4kpkbgP/Mx8j7W6ES2vL3MUSEvn8iMm ficIGeNNyBOOA9xp8jEc/V2gNXEfo/4pA+zf5aJt7a3pZZ8TLHR3jcbVpi/j1MW/spgr fHki0fmAj4HkzLdmgUxMPyZl0ygbEyKYs0tZJ95a0h96QCzezTRhap+G47+311BYIsOr YlO5YIVzqdzKGcmekScqH/SIwxkYXynMtn0mHphySxNzZl1SfuY0UCB5ie1cRtu+im7U Pxdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZKk0Stmp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a170906974a00b0078d49f0df9csi8994805ejy.453.2022.11.20.22.58.54; Sun, 20 Nov 2022 22:59:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZKk0Stmp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229558AbiKUGVQ (ORCPT + 91 others); Mon, 21 Nov 2022 01:21:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiKUGVP (ORCPT ); Mon, 21 Nov 2022 01:21:15 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CBAE2C673 for ; Sun, 20 Nov 2022 22:21:14 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso9887399pjt.0 for ; Sun, 20 Nov 2022 22:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=L7+eqek/E/WnqdTO067PuTCEyXCliseIp9lN/F5T2O4=; b=ZKk0StmpbeGK016qCI8yukcq0kjSwsVRgEDhsd3qv/+fSh5pCk+JobvB0b3YXjtCVl awhHREbDL+19v+bGncU+okf+vipgkMWoxkFaMAH8xgRpXQ2XDk3fo0AAFZI9WEsOS6ZO rOIMdMWmO7sYarTeLF7+IhqjMe3EMj4H4bzuA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=L7+eqek/E/WnqdTO067PuTCEyXCliseIp9lN/F5T2O4=; b=SRjXMF0uGCp+aRdySY0OhvYXoTLBmxdoncTojLT3MdxODQxNJHXHT9VDWPI07TXMYg symalP41blT6W+R2ZlIoEotV9zVS/WEJ0F/Vn+ayrkx3OWCTgwCjl5v8ERviB+SCaCGl CxRhxmXzsa3iI0rCgUUInNjkZWIJvcEvEP8ba+w0aguOVB6qhjSujfCSHJKxm4oicH18 3LQEQZW3xQUSfLAIk7su4b4tJ2HCjl7KVSrYcx1SNOoj+RRcXAeaMoTDQIWAc3H5qFPS MuNlMClXmBY5nrmyq9dND/swcWplYTZN8oQ2y8e904cCkMwbJN2QlAurqFxdr+viLYwM o+QQ== X-Gm-Message-State: ANoB5pl4/GWa5GvxmG55NnOSXxdWgdvETHF8tqCrbbKD1IgDRfAfLPnE sNq1oDmhc7E9XkGxYWxveUff8c6wikrhBg== X-Received: by 2002:a17:90a:7004:b0:218:8757:8f2b with SMTP id f4-20020a17090a700400b0021887578f2bmr13906217pjk.221.1669011673897; Sun, 20 Nov 2022 22:21:13 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id p188-20020a625bc5000000b0056e32a2b88esm7672980pfb.219.2022.11.20.22.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Nov 2022 22:21:13 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: Prashant Malani , Heikki Krogerus , Benson Leung , Greg Kroah-Hartman Subject: [PATCH] usb: typec: pd: Add symlink to linked device Date: Mon, 21 Nov 2022 06:20:39 +0000 Message-Id: <20221121062106.2569297-1-pmalani@chromium.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There exists a symlink from a device to its USB Power Delivery object, but not the other way around. Add a symlink from the USB PD object to the device which it's associated with, and call it "device". This is helpful to identify said device (a Type-C peripheral for example) during uevents, since during USB PD object creation/destruction, a uevent is generated for the PD object, but not the device linked to it. Cc: Heikki Krogerus Cc: Benson Leung Signed-off-by: Prashant Malani --- .../ABI/testing/sysfs-class-usb_power_delivery | 6 ++++++ drivers/usb/typec/pd.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-usb_power_delivery b/Documentation/ABI/testing/sysfs-class-usb_power_delivery index ce2b1b563cb3..e7d19193875f 100644 --- a/Documentation/ABI/testing/sysfs-class-usb_power_delivery +++ b/Documentation/ABI/testing/sysfs-class-usb_power_delivery @@ -4,6 +4,12 @@ Contact: Heikki Krogerus Description: Directory for USB Power Delivery devices. +What: /sys/class/usb_power_delivery/.../device +Date: November 2022 +Contact: Prashant Malani +Description: + Symbolic link to the directory of the device to which the USB PD object is linked. + What: /sys/class/usb_power_delivery/.../revision Date: May 2022 Contact: Heikki Krogerus diff --git a/drivers/usb/typec/pd.c b/drivers/usb/typec/pd.c index dc72005d68db..ed073d922655 100644 --- a/drivers/usb/typec/pd.c +++ b/drivers/usb/typec/pd.c @@ -656,7 +656,8 @@ EXPORT_SYMBOL_GPL(usb_power_delivery_unregister); * @dev: The device. * * This function can be used to create a symlink named "usb_power_delivery" for - * @dev that points to @pd. + * @dev that points to @pd. It also creates another symlink named "device" which + * points from @pd to @dev. */ int usb_power_delivery_link_device(struct usb_power_delivery *pd, struct device *dev) { @@ -669,6 +670,12 @@ int usb_power_delivery_link_device(struct usb_power_delivery *pd, struct device if (ret) return ret; + ret = sysfs_create_link(&pd->dev.kobj, &dev->kobj, "device"); + if (ret) { + sysfs_remove_link(&dev->kobj, "usb_power_delivery"); + return ret; + } + get_device(&pd->dev); get_device(dev); @@ -681,13 +688,14 @@ EXPORT_SYMBOL_GPL(usb_power_delivery_link_device); * @pd: The USB PD instance. * @dev: The device. * - * Remove the symlink that was previously created with pd_link_device(). + * Remove the symlinks that were previously created with pd_link_device(). */ void usb_power_delivery_unlink_device(struct usb_power_delivery *pd, struct device *dev) { if (IS_ERR_OR_NULL(pd) || !dev) return; + sysfs_remove_link(&pd->dev.kobj, "device"); sysfs_remove_link(&dev->kobj, "usb_power_delivery"); put_device(&pd->dev); put_device(dev); -- 2.38.1.584.g0f3c55d4c2-goog