Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5317003imu; Tue, 13 Nov 2018 04:49:53 -0800 (PST) X-Google-Smtp-Source: AJdET5e7I6WheT4sjs5XYMLCEw0sQzZuS3qi7sWIHH6AhpQ3/oepOvLbm4aJEpfjLsD9vCDHvlbm X-Received: by 2002:a17:902:9a94:: with SMTP id w20-v6mr1324958plp.115.1542113393144; Tue, 13 Nov 2018 04:49:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542113393; cv=none; d=google.com; s=arc-20160816; b=d1xwANeovVAgS/pX2Vf2NHD3XFhc7AjHEKZcndfnqdmZXVAJ73uaZaR9bt7jclT5Hz LCYHTqVz1OvAAidfwP5PaJy1kC7cDR0yTw9q0Zbzuy85WHUKrvxcsxzu2hGp4QOMANoF /vi8tOJpiCeqHZ3sA5ACP/4FKX1VmFP7iTSRxuo5tilv8iLNxfSLgWrU54XQx4a5lYYM FcTuNMCLF6RnxqXXYYXR0g/A3uBImrcARwlkHh5QgA/Zq0sGWL0rVYF9yVQz2o0y1dnz OiKwIi/si53X90L6vCAgPiM3xZsUbhcTE0bnV9CslUmw0V2EVR6SweUf1EV2akzR+xN+ QzQw== 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; bh=CHFb3AwzJ0hSO9JX1+gMFJ8qrG59hUtkezH+VOwAyTs=; b=BUYczS2QiNZXF3ed8AfBcnBdtPNOP8hGW4ToxbFMDs5S6h44AvZBJYXOTnK9xMU03f 0MIT/DVIx+zHRjgFzmPreO6YOH1cklpU6mayPgBxKwceMKpMHDbAMiDGAXTmjlI6DPRl LD32laQqeRYcsrS/QDp6Qe4aBdkDuhCvK0nnNkf4qB+le78Kb4dyd+mVlJmxf/Yp76j9 HAzMdTZ9Gq3ECVLSmRwklMHQxfDPp19Oqh6WP5gA4gAA0rn8Fq9S2KRxczzbXPH01M7C kAB7gIeyBDqVnyZ2tVI2b/IaKS33smfozQRI01rij7cYJ7ODCcnoRfP1qGd59CsTW8G7 d9Vw== 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 f35si18125320pgf.449.2018.11.13.04.49.34; Tue, 13 Nov 2018 04:49:53 -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 S1733039AbeKMWps (ORCPT + 99 others); Tue, 13 Nov 2018 17:45:48 -0500 Received: from laurent.telenet-ops.be ([195.130.137.89]:48296 "EHLO laurent.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732884AbeKMWps (ORCPT ); Tue, 13 Nov 2018 17:45:48 -0500 Received: from ramsan.of.borg ([84.194.111.163]) by laurent.telenet-ops.be with bizsmtp id zQnm1y0013XaVaC01QnmF2; Tue, 13 Nov 2018 13:47:46 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1gMY6c-0005r9-0w; Tue, 13 Nov 2018 13:47:46 +0100 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1gMY6b-000222-VV; Tue, 13 Nov 2018 13:47:45 +0100 From: Geert Uytterhoeven To: Philipp Zabel Cc: Eric Auger , Alex Williamson , kvm@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] reset: Add reset_control_get_count() Date: Tue, 13 Nov 2018 13:47:44 +0100 Message-Id: <20181113124744.7769-1-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently the reset core has internal support for counting the number of resets for a device described in DT. Generalize this to devices using lookup resets, and export it for public use. This will be used by generic drivers that need to be sure a device is controlled by a single, dedicated reset line (e.g. vfio-platform). Signed-off-by: Geert Uytterhoeven --- See https://lore.kernel.org/lkml/1539003437.11512.20.camel@pengutronix.de/ for the rationale to ensure a single, dedicated reset line. drivers/reset/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/reset.h | 7 +++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 654e20ff2d5da9d4..c32b755ec373c338 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -859,3 +859,44 @@ devm_reset_control_array_get(struct device *dev, bool shared, bool optional) return rstc; } EXPORT_SYMBOL_GPL(devm_reset_control_array_get); + +static int reset_control_get_count_from_lookup(struct device *dev) +{ + const struct reset_control_lookup *lookup; + const char *dev_id = dev_name(dev); + int count = 0; + + if (!dev) + return -EINVAL; + + mutex_lock(&reset_lookup_mutex); + + list_for_each_entry(lookup, &reset_lookup_list, list) { + if (!strcmp(lookup->dev_id, dev_id)) + count++; + } + + mutex_unlock(&reset_lookup_mutex); + + if (count == 0) + count = -ENOENT; + + return count; +} + +/** + * of_reset_control_get_count - Count number of resets available with a device + * + * @dev: device for which to return the number of resets + * + * Returns positive reset count on success, or error number on failure and + * on count being zero. + */ +int reset_control_get_count(struct device *dev) +{ + if (dev->of_node) + return of_reset_control_get_count(dev->of_node); + + return reset_control_get_count_from_lookup(dev); +} +EXPORT_SYMBOL_GPL(reset_control_get_count); diff --git a/include/linux/reset.h b/include/linux/reset.h index f0b094130686bf32..2698b36bd1eb3e0c 100644 --- a/include/linux/reset.h +++ b/include/linux/reset.h @@ -32,6 +32,8 @@ struct reset_control *devm_reset_control_array_get(struct device *dev, struct reset_control *of_reset_control_array_get(struct device_node *np, bool shared, bool optional); +int reset_control_get_count(struct device *dev); + #else static inline int reset_control_reset(struct reset_control *rstc) @@ -97,6 +99,11 @@ of_reset_control_array_get(struct device_node *np, bool shared, bool optional) return optional ? NULL : ERR_PTR(-ENOTSUPP); } +static inline int reset_control_get_count(struct device *dev) +{ + return -ENOENT; +} + #endif /* CONFIG_RESET_CONTROLLER */ static inline int __must_check device_reset(struct device *dev) -- 2.17.1