From patchwork Fri Jun 22 08:09:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "(Exiting) Baolin Wang" X-Patchwork-Id: 10481473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A561860380 for ; Fri, 22 Jun 2018 08:10:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9778728E69 for ; Fri, 22 Jun 2018 08:10:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BB5828E74; Fri, 22 Jun 2018 08:10:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1827328E69 for ; Fri, 22 Jun 2018 08:10:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754184AbeFVIKC (ORCPT ); Fri, 22 Jun 2018 04:10:02 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:41105 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754172AbeFVIJ7 (ORCPT ); Fri, 22 Jun 2018 04:09:59 -0400 Received: by mail-pf0-f194.google.com with SMTP id a11-v6so2838346pff.8 for ; Fri, 22 Jun 2018 01:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=0Tzpf9ziKr+g+hROmT1grV3fdzAFs7fX02E9A7Xg4ZM=; b=HEnnXQGlLutVmWD43oi6ceJzSCpIhb3RZy3tm9zT+XhTUKcW+b3PQpiLGunqUzvgsn 3a/PQUSpkZJ/kprN/hGLvCZ3YeRop1ex0U7IdA2DCMU+AvpHCa7Og4VSZW+DUOSm3Tmj gL5s/eWARXTGSnix3CB7n7a0kvAnNCPeMelZU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=0Tzpf9ziKr+g+hROmT1grV3fdzAFs7fX02E9A7Xg4ZM=; b=rtMh9KSiNB7tI7Mdb0rQu1w5lAMOcIntGrCDEN2QAQp8e87CCp8+B7f8anAhJGNDT/ Y+OuzqYXiBL35xYIgAX9K9HlDC0KfP9M6DLjOJ9wCauxv0Guo5le99SwOpW8tyb+kt2b MPTkNHcT/FvlIV6Sh3g/EfESRnJPT9urFB8bN7WFuxNRXRCmNZLph5DD2WvpHnIR3Pd2 RbirND0uzBh892hvrKInq50a/N/3R2eaW7MgaiV0lSFt5iB2O4mvqrBEvzd/IBpEQtmD uFDoZhK7tdNN95chz4dKoG4oi5DnSbZGhwuthlSkhwx7e0upQXlQgoDVSXJAiVrw3lZZ dDPw== X-Gm-Message-State: APt69E3ndpBA3RU/nRFwS2fLI3Stgd2ddN30YvUQEDQzgwjZbEHA8OHG cZRc1CntcfUr5wHdz3lv2w7Wtw== X-Google-Smtp-Source: ADUXVKL14cdsrF5x7Q6I2Kdillry/zFcZWsgptjgAVzNiOvfBwlYW9sWkyiaJW+rL/TieYzqH2CIwQ== X-Received: by 2002:a63:78c6:: with SMTP id t189-v6mr482034pgc.239.1529654998951; Fri, 22 Jun 2018 01:09:58 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id i65-v6sm22656131pfd.17.2018.06.22.01.09.56 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jun 2018 01:09:58 -0700 (PDT) From: Baolin Wang To: ohad@wizery.com, bjorn.andersson@linaro.org, broonie@kernel.org Cc: baolin.wang@linaro.org, linux-spi@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] hwspinlock: Add devm_xxx() APIs to register/unregister one hwlock controller Date: Fri, 22 Jun 2018 16:09:00 +0800 Message-Id: <52f3abc65549f6b412587a2c5938ee1347bccde7.1529654288.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces devm_hwspin_lock_register() and devm_hwspin_lock_unregister() interfaces to help to register or unregister one hardware spinlock controller, that will help to simplify the cleanup code for hwspinlock drivers. Signed-off-by: Baolin Wang --- drivers/hwspinlock/hwspinlock_core.c | 82 ++++++++++++++++++++++++++++++++++ include/linux/hwspinlock.h | 6 +++ 2 files changed, 88 insertions(+) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index d542b6f..ba27465 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -529,6 +529,88 @@ int hwspin_lock_unregister(struct hwspinlock_device *bank) } EXPORT_SYMBOL_GPL(hwspin_lock_unregister); +static void devm_hwspin_lock_unreg(struct device *dev, void *res) +{ + hwspin_lock_unregister(*(struct hwspinlock_device **)res); +} + +static int devm_hwspin_lock_device_match(struct device *dev, void *res, + void *data) +{ + struct hwspinlock_device **bank = res; + + if (WARN_ON(!bank || !*bank)) + return 0; + + return *bank == data; +} + +/** + * devm_hwspin_lock_unregister() - unregister an hw spinlock device for + * a managed device + * @dev: the backing device + * @bank: the hwspinlock device, which usually provides numerous hw locks + * + * This function should be called from the underlying platform-specific + * implementation, to unregister an existing (and unused) hwspinlock. + * + * Should be called from a process context (might sleep) + * + * Returns 0 on success, or an appropriate error code on failure + */ +int devm_hwspin_lock_unregister(struct device *dev, + struct hwspinlock_device *bank) +{ + int ret; + + ret = devres_release(dev, devm_hwspin_lock_unreg, + devm_hwspin_lock_device_match, bank); + WARN_ON(ret); + + return ret; +} +EXPORT_SYMBOL_GPL(devm_hwspin_lock_unregister); + +/** + * devm_hwspin_lock_register() - register a new hw spinlock device for + * a managed device + * @dev: the backing device + * @bank: the hwspinlock device, which usually provides numerous hw locks + * @ops: hwspinlock handlers for this device + * @base_id: id of the first hardware spinlock in this bank + * @num_locks: number of hwspinlocks provided by this device + * + * This function should be called from the underlying platform-specific + * implementation, to register a new hwspinlock device instance. + * + * Should be called from a process context (might sleep) + * + * Returns 0 on success, or an appropriate error code on failure + */ +int devm_hwspin_lock_register(struct device *dev, + struct hwspinlock_device *bank, + const struct hwspinlock_ops *ops, + int base_id, int num_locks) +{ + struct hwspinlock_device **ptr; + int ret; + + ptr = devres_alloc(devm_hwspin_lock_unreg, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = hwspin_lock_register(bank, dev, ops, base_id, num_locks); + if (!ret) { + *ptr = bank; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return ret; +} +EXPORT_SYMBOL_GPL(devm_hwspin_lock_register); + /** * __hwspin_lock_request() - tag an hwspinlock as used and power it up * diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index dfd0593..94064cc 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -71,6 +71,12 @@ int __hwspin_lock_timeout(struct hwspinlock *, unsigned int, int, struct hwspinlock *devm_hwspin_lock_request(struct device *dev); struct hwspinlock *devm_hwspin_lock_request_specific(struct device *dev, unsigned int id); +int devm_hwspin_lock_unregister(struct device *dev, + struct hwspinlock_device *bank); +int devm_hwspin_lock_register(struct device *dev, + struct hwspinlock_device *bank, + const struct hwspinlock_ops *ops, + int base_id, int num_locks); #else /* !CONFIG_HWSPINLOCK */