Received: by 10.223.185.116 with SMTP id b49csp3977919wrg; Tue, 13 Feb 2018 10:40:53 -0800 (PST) X-Google-Smtp-Source: AH8x224uH584zARIj6hoQUDdddpbGT1chzeD/jhsFAX2mq1pfJw1Skmit0eL+H7U8jpJ0FTogTeA X-Received: by 10.101.71.129 with SMTP id e1mr1727255pgs.430.1518547253512; Tue, 13 Feb 2018 10:40:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518547253; cv=none; d=google.com; s=arc-20160816; b=X+nT8TMoaUJwILwQgxERX/ADSefJzJprCXIqcpZOrhtFBXHfVUD2xCaoj7lcL0RenG G4MKuFJwa7zD73Lt+OICgYu7xIYzVlAjmOXI1Goc2lWFdpLuzRDda/nv0z5bFdddnqvN pGORR9z1ep7FRQcYF97NoN6YQMPTjCq6qV6HHHG0Lcev1lGiERuyndSMDMdoq5H1FAK/ JQ9T3PH8JGUZFnMm8M3sL1htgG9d6txVlcuBw1OfQujOqPtIMD4u0Y4dNzFeM7KpFRhf 2BwMLV9M6UnCCAyh5mjq8szsVyLp4HFZJ6Zog8RjGwbh+tacJe8G/bTR8eHQnu1CULq6 faKA== 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 :dkim-signature:arc-authentication-results; bh=7o06hqOUxMTgWpoACXFyk60D16vt/4SB1ebQftwoet0=; b=boBB8y8gFVgZZiw/wRfhkzvZrOAJy48PnQCJqMjgfMdpFS+Zas8Hw/ocToOLuwLXTb 7Hfmist6cYSmfogQJ6tucSkrHaAgU+3xEGXfjj7ZIhPM/huWsmFVTETn7qlgXQviZo5B whphOGvCgNU0aS4txuwz1C+j/TWQ/wxpuPvbrsY9maFKQezxoaGmeEK9oLw6yRID8QE2 xYayGlWfqH9TYcqMM170v7vfhnC1OMVU2/WQePpHQ3BnGXegvM8NZPNgbWk+ctW23xHO fInnhka/hShp0r2vWJU2VENCocN0ytfzvDoMdmlfG/DzRPRNSSZhc+UB7lsi8uHiliZt nwcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=VSdQn1tx; 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 y6si6818371pgc.112.2018.02.13.10.40.37; Tue, 13 Feb 2018 10:40: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; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=VSdQn1tx; 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 S965490AbeBMSjx (ORCPT + 99 others); Tue, 13 Feb 2018 13:39:53 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39031 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965344AbeBMSjv (ORCPT ); Tue, 13 Feb 2018 13:39:51 -0500 Received: by mail-wm0-f67.google.com with SMTP id b21so17766548wme.4 for ; Tue, 13 Feb 2018 10:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=7o06hqOUxMTgWpoACXFyk60D16vt/4SB1ebQftwoet0=; b=VSdQn1txpAgJuJEzeBR5CTzsx4s/9Y/w/dqYIxnTvolEmcfAHzIDhdpoyFQtsSUgl8 +KaPSrJWUEFMvhHvs/+p6O7CIdv/dKetZE1blnOSjIxkodkQrupk16bxJ4GsS+qYw2mc RcghqfmT/O2tpS+Reipp6PN4l2rJO8sPzEkn986wVtvgzLLkQSKp7qtVlHdFfk+qM4M7 nXrmTyWFUBXijlb+oYEAhEBlocOBjE2li9qFBrJXTu8VBx39LFwqUpqA2/AT7t6jCnLn miWQVQXDntjtyDLNYPstEq09S9uX1jmw+yvd106YsExDtZ7jDAyQ2TsPVaxVcVBoqZE+ J6CQ== 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; bh=7o06hqOUxMTgWpoACXFyk60D16vt/4SB1ebQftwoet0=; b=eHRknzH3iVQhwblvNt5qqy+6TjWWG17GNMJmYWZj7wd2o52fmlwEF6GQUkKVUpOuJ6 uClYpI/6dpo9o1lsFcdanGdBN2wKZDMB/SRQoEE/l9Xg3uyeK0MoqFLuzQy4jmHJQ8v/ zBMp6nWXg08hA9BE+xel+cQyDDEGANr297ffYf7no7gJu8tZzTpO91adMvYS6xt/QK/H OGzSkeCiA2jOt2UYQwjen4Y392Qn7ytJbQUPHM88VdK2ZAmrH92SeWJQQixU5fzBMQeg WEkW3Wd4VkxWmpTlZ8NQ2ufvUdWKNTnhM0D78Vad9SiHDbqZMsTcM549EqWspuB54qU1 SP3A== X-Gm-Message-State: APf1xPBWjJX5KbAXy+IUX94pFPoSTbXWFFQ0jBydORINfyOAXIpgmFRr YT8HWeegIxKFr1Se6UiCL/LpAN4s1/w= X-Received: by 10.28.24.193 with SMTP id 184mr2004732wmy.144.1518547189651; Tue, 13 Feb 2018 10:39:49 -0800 (PST) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id v9sm11598072wre.8.2018.02.13.10.39.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 10:39:48 -0800 (PST) From: Bartosz Golaszewski To: Philipp Zabel Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski , Sekhar Nori , Kevin Hilman , David Lechner Subject: [PATCH v2] reset: add support for non-DT systems Date: Tue, 13 Feb 2018 19:39:46 +0100 Message-Id: <20180213183946.1662-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.16.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski The reset framework only supports device-tree. There are some platforms however, which need to use it even in legacy, board-file based mode. An example of such architecture is the DaVinci family of SoCs which supports both device tree and legacy boot modes and we don't want to introduce any regressions. We're currently working on converting the platform from its hand-crafted clock API to using the common clock framework. Part of the overhaul will be representing the chip's power sleep controller's reset lines using the reset framework. This changeset extends the core reset code with a new field in the reset controller struct which contains an array of lookup entries. Each entry contains the device name and an additional, optional identifier string. Drivers can register a set of reset lines using this lookup table and concerned devices can access them using the regular reset_control API. This new function is only called as a fallback in case the of_node field is NULL and doesn't change anything for current users. Tested with a dummy reset driver with several lookup entries. An example lookup table can look like this: static const struct reset_lookup foobar_reset_lookup[] = { [FOO_RESET] = { .dev = "foo", .id = "foo_id" }, [BAR_RESET] = { .dev = "bar", .id = NULL }, { } }; where FOO_RESET and BAR_RESET will correspond with the id parameters of reset callbacks. Cc: Sekhar Nori Cc: Kevin Hilman Cc: David Lechner Signed-off-by: Bartosz Golaszewski --- v1 -> v2: - renamed the new function to __reset_control_get_from_lookup() - added a missing break; when a matching entry is found - rearranged the code in __reset_control_get() - we can no longer get to the return at the bottom, so remove it and return from __reset_control_get_from_lookup() if __of_reset_control_get() fails - return -ENOENT from reset_contol_get() if we can't find a matching entry, prevously returned -EINVAL referred to the fact that we passed a device without the of_node which is no longer an error condition - add a comment about needing a sentinel in the lookup table drivers/reset/core.c | 40 +++++++++++++++++++++++++++++++++++++++- include/linux/reset-controller.h | 14 ++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index da4292e9de97..b104a0c5c511 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -493,6 +493,44 @@ struct reset_control *__of_reset_control_get(struct device_node *node, } EXPORT_SYMBOL_GPL(__of_reset_control_get); +static struct reset_control * +__reset_control_get_from_lookup(struct device *dev, const char *id, + bool shared, bool optional) +{ + struct reset_controller_dev *rcdev; + const char *dev_id = dev_name(dev); + struct reset_control *rstc = NULL; + const struct reset_lookup *lookup; + int index; + + mutex_lock(&reset_list_mutex); + + list_for_each_entry(rcdev, &reset_controller_list, list) { + if (!rcdev->lookup) + continue; + + lookup = rcdev->lookup; + for (index = 0; lookup->dev; index++, lookup++) { + if (strcmp(dev_id, lookup->dev)) + continue; + + if ((!id && !lookup->id) || + (id && lookup->id && !strcmp(id, lookup->id))) { + rstc = __reset_control_get_internal(rcdev, + index, shared); + break; + } + } + } + + mutex_unlock(&reset_list_mutex); + + if (!rstc) + return optional ? NULL : ERR_PTR(-ENOENT); + + return rstc; +} + struct reset_control *__reset_control_get(struct device *dev, const char *id, int index, bool shared, bool optional) { @@ -500,7 +538,7 @@ struct reset_control *__reset_control_get(struct device *dev, const char *id, return __of_reset_control_get(dev->of_node, id, index, shared, optional); - return optional ? NULL : ERR_PTR(-EINVAL); + return __reset_control_get_from_lookup(dev, id, shared, optional); } EXPORT_SYMBOL_GPL(__reset_control_get); diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h index adb88f8cefbc..4cc52b4a4d27 100644 --- a/include/linux/reset-controller.h +++ b/include/linux/reset-controller.h @@ -22,6 +22,17 @@ struct reset_control_ops { int (*status)(struct reset_controller_dev *rcdev, unsigned long id); }; +/** + * struct reset_lookup - a single entry in a reset lookup table + * + * @dev: name of the device associated with this reset + * @id: additional reset identifier (if the device uses multiple reset lines) + */ +struct reset_lookup { + const char *dev; + const char *id; +}; + struct module; struct device_node; struct of_phandle_args; @@ -34,6 +45,8 @@ struct of_phandle_args; * @list: internal list of reset controller devices * @reset_control_head: head of internal list of requested reset controls * @of_node: corresponding device tree node as phandle target + * @lookup: array of lookup entries associated with this request controller, + * must end with a zeroed sentinel entry * @of_reset_n_cells: number of cells in reset line specifiers * @of_xlate: translation function to translate from specifier as found in the * device tree to id as given to the reset control ops @@ -45,6 +58,7 @@ struct reset_controller_dev { struct list_head list; struct list_head reset_control_head; struct device_node *of_node; + const struct reset_lookup *lookup; int of_reset_n_cells; int (*of_xlate)(struct reset_controller_dev *rcdev, const struct of_phandle_args *reset_spec); -- 2.16.1