Received: by 10.223.185.116 with SMTP id b49csp3688166wrg; Mon, 19 Feb 2018 04:26:49 -0800 (PST) X-Google-Smtp-Source: AH8x224ivJzSwy1NbdOgeqnIzDafPt/vp4s6PFzPA1GSXm8dafUAPqQZ8y7t9akyXR4/eWX9zmqB X-Received: by 10.99.138.74 with SMTP id y71mr12427766pgd.419.1519043209202; Mon, 19 Feb 2018 04:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519043209; cv=none; d=google.com; s=arc-20160816; b=icbmFJD/roxj2G5OUalDFaLIsVHunlOEIs+Kb7yewtLO5Gnm3JKcz788h1DyR8/I5i 4InvWQsbrl7Db25dLiKEZOQEs4DRnT0afdIRhtNTVXU1WwUnT8YJvN6lQ99sW3RFxVYj VA0gujbFNU1AG/YDb52yJTm7QTVc1Zn2JuNgbZF4kE3uIz1bRI6nrDS5utnHA2rzxD2j e3/RctMXUCmMN4kzdSAsRFbtpmB0Nkpbsiq7c8yDnXIfQKZs7blkNB8xHOwbOiiymAcm C7X3iP4T3fM1ZNNAWHZuiQDMYOIRjP3xMPNZE+IvMrGdK0pNC0pl8L23j8qlRpZpFjM1 tPeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=I2mB2V15sErP+FBZ/HWiivePMKct0qN2iW4QHJNJX4o=; b=teAvxzE5uyGJbzcPOPj8A0z/5yRx5qfJFYtlk3KSInk22MEB7FAxb7E1pDMt5XBDYW KKqwgjXkJ3IWF0MEVR5cidfk8VL11Att1NdokIC7S67ejzv+RycsVRzmSKXJsaCeL5WM qLBo3UvFo/DVuwR9re888kjn354H+luMW5mJeyq+U6YCcInThI4u4THHB9nXc4eFamzl 4hXFv10cuQlHQHgdl6uyXVaYk2g7z6DClp3bpELQV2UTJk1d+/TXUItWiZFKINyFUyJe H/OlAcxMjtCsRwLeZv8hdjuaaTkD5J4XEyr11VTXJD0lLHkPN1h13Bri5uqLItWRAehm cmHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si5488476pfb.75.2018.02.19.04.26.34; Mon, 19 Feb 2018 04:26:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752734AbeBSMZz (ORCPT + 99 others); Mon, 19 Feb 2018 07:25:55 -0500 Received: from relay01.alfahosting-server.de ([109.237.142.236]:9602 "EHLO relay01.alfahosting-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752717AbeBSMZx (ORCPT ); Mon, 19 Feb 2018 07:25:53 -0500 X-Greylist: delayed 1462 seconds by postgrey-1.27 at vger.kernel.org; Mon, 19 Feb 2018 07:25:53 EST Received: by relay01.alfahosting-server.de (Postfix, from userid 1001) id 5DC3432C005B; Mon, 19 Feb 2018 13:01:29 +0100 (CET) X-Spam-DCC: : X-Spam-Level: X-Spam-Status: No, score=-1000.0 required=7.0 tests=BAYES_50,D_SENT_WITH_SASL autolearn=disabled version=3.2.5 Received: from alfa3028.alfahosting-server.de (alfa3028.alfahosting-server.de [109.237.138.38]) by relay01.alfahosting-server.de (Postfix) with ESMTPS id 394C232C0449; Mon, 19 Feb 2018 13:01:27 +0100 (CET) Received: from localhost.localdomain (unknown [91.230.2.244]) (Authenticated sender: yes) by alfa3028.alfahosting-server.de (Postfix) with ESMTPA id AAA76430CEF5; Mon, 19 Feb 2018 13:01:25 +0100 (CET) From: Richard Leitner To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, linux@roeck-us.net, mathias.nyman@linux.intel.com, johan@kernel.org, felipe.balbi@linux.intel.com, ekorenevsky@gmail.com, peter.chen@nxp.com, drake@endlessm.com, joe@perches.com, Richard Leitner Subject: [PATCH] usb: core: introduce per-port over-current counters Date: Mon, 19 Feb 2018 13:01:07 +0100 Message-Id: <20180219120107.20434-1-dev@g0hl1n.net> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Leitner For some userspace applications information on the number of over-current conditions at specific USB hub ports is relevant. Therefore introduce a oc_counter in the usb port struct which is exported via sysfs. Signed-off-by: Richard Leitner --- Tested on an i.MX6DL based board. --- drivers/usb/core/hub.c | 4 +++- drivers/usb/core/hub.h | 1 + drivers/usb/core/port.c | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index c5c1f6cf3228..448fba1e1827 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -5104,8 +5104,10 @@ static void port_event(struct usb_hub *hub, int port1) if (portchange & USB_PORT_STAT_C_OVERCURRENT) { u16 status = 0, unused; + port_dev->oc_count++; - dev_dbg(&port_dev->dev, "over-current change\n"); + dev_dbg(&port_dev->dev, "over-current change #%u\n", + port_dev->oc_count); usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_OVER_CURRENT); msleep(100); /* Cool down */ diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 2a700ccc868c..b5cf567bf9e2 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -100,6 +100,7 @@ struct usb_port { unsigned int is_superspeed:1; unsigned int usb3_lpm_u1_permit:1; unsigned int usb3_lpm_u2_permit:1; + unsigned int oc_count; }; #define to_usb_port(_dev) \ diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index 1a01e9ad3804..0bfe410eb8a7 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -41,6 +41,15 @@ static ssize_t connect_type_show(struct device *dev, } static DEVICE_ATTR_RO(connect_type); +static ssize_t oc_count_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct usb_port *port_dev = to_usb_port(dev); + + return sprintf(buf, "%u\n", port_dev->oc_count); +} +static DEVICE_ATTR_RO(oc_count); + static ssize_t usb3_lpm_permit_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -109,6 +118,7 @@ static DEVICE_ATTR_RW(usb3_lpm_permit); static struct attribute *port_dev_attrs[] = { &dev_attr_connect_type.attr, + &dev_attr_oc_count.attr, NULL, }; -- 2.11.0