Received: by 10.223.185.116 with SMTP id b49csp3766602wrg; Tue, 13 Feb 2018 07:27:35 -0800 (PST) X-Google-Smtp-Source: AH8x227mbNuruI/a9eQRMEXYs3TIKUooaOzVyA2NsKBzG9CTD6uTopxpd0BVnz2EavaCYU6hbO3Q X-Received: by 10.98.78.148 with SMTP id c142mr1573671pfb.153.1518535655545; Tue, 13 Feb 2018 07:27:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518535655; cv=none; d=google.com; s=arc-20160816; b=kxjfghJhl+MMkQ0FgWuKUk6zrjYNaNm4+1PWHR+May6a0pk+upoVGVqykwQRebTwb0 wY8tTcRaDfjrecS0m39WaQjYtNpGqfHs7Z0f8nRxJVcRBPYIVOWqEUoPzXVZK/phmrTG /R2rr9ozQcLOuhnR2zMCy6o6QV3QcmK1ygjV2+JPBJBcNM0PTp9MvUqiV2tAFnUaflY1 XDCADqXb5DFICVLRBSPyywFu/VR2Xu7n3oBAr34ZYUNsj8lBwFctbHiW5tlG30R0DDJf HglfLEvn5D0A1ZN3OO/4lIpKYqQK4GScktvNRWHPCbF8UfhMIDroAD/nNIkP+1Hg2hkv oA1w== 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=8hKB9nTPKmIDteV4dUz5IcPGh9PAPzaOeNOg7GB68FU=; b=JTl3ziKf92+5cjwCluCm6bnZ7H+TCZCRqdZ3qGWO8gdZ0OpOQb324zle4XFm9TqkU+ zHIM60nvoxXI8Nu2YK0Us4/8aCokmnm3jFOMdPJDKlccWmjcD6TDh7O0QajFRlOXHTHD Vf80s5PjKpPQNE9dG4Nxrk+SDoUcLbHN6BNV6ASKoX/+fYfU5erAmkTHc73birrJKXmJ jdRDek6yr21BKSxdHaOMnnxIhW479oovkJwssCr6w7duagnvxsC+/8Iq/okDVx8W7yno bZPYe0I6LGjAHyZMMa+Y9ja9eiPo1Q99vQYjQWdxK8ojOoRi1lFOibn7pgXNHJQKh1nE c+Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=krHs+lxK; 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 72-v6si5717574ple.299.2018.02.13.07.27.21; Tue, 13 Feb 2018 07:27:35 -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=krHs+lxK; 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 S965064AbeBMPZc (ORCPT + 99 others); Tue, 13 Feb 2018 10:25:32 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39010 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753635AbeBMPZa (ORCPT ); Tue, 13 Feb 2018 10:25:30 -0500 Received: by mail-wr0-f194.google.com with SMTP id w77so4507068wrc.6 for ; Tue, 13 Feb 2018 07:25:30 -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=8hKB9nTPKmIDteV4dUz5IcPGh9PAPzaOeNOg7GB68FU=; b=krHs+lxKtKu5cMSIro3RJATNyejr2pkZmHkWLo4G82fo5XPweRw0xIvK2Kuzx9UKJx k8cDMUS/70iCxOxxM5kKXBISPr8mSvNqACgN4WQYeL96uC1NObKQ4lSa0PsLzEWmOomM sTrgsSKR3q2dUEMugftxMlpddZT2Gqg5wJP6qpNlhMYf7fmmfQSi6co8nh7hLf8cP+mS t6tGdXTD/10jP0l1MR696CGNQhfUT3sVXE4aJ9bFu4edEhFNkYgrbNi+3h6VTWSpBgBz FIriFFjaQvb3y02a18hdaZVEYFxTZvjOhohA3Y1b0nfiy0OHj8DQCzPme5VMTi6t3+3S DtKQ== 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=8hKB9nTPKmIDteV4dUz5IcPGh9PAPzaOeNOg7GB68FU=; b=Ey+LuoTk0vFxR9VbxTbtGPQgrOLMWZtcUflxhqvfaf9b/MsN60unZOADzt880Tj3BU hwmLuT2laZ+Kgy+POmlPCf4mz+UH6ZyvRIP02vw/Sbo1v1vQoD9L7bC8Zyyged1lgig5 uSuhdoot4u80n2qgxg6A5sVa3tCkyT/IfNATCvkCgXxpW25BQ/wBfyPECmCgrYgJDwLq c+8AK42llrfORLGvdWwbq+qmY0qVjFLm+9YBqHnAGLLiMl8/TzxKamo8Dysp+06GknkQ fJKdItLcxt5V5L53X7UjyEqHk9FWCbXfseo0DzVZH4jOwjwSek+XBVGNK7F4I0PljBzq LXlw== X-Gm-Message-State: APf1xPA6u8S2kbnuuED+srYKzQ4rgfiGcO637B5Z9f3LVgfF7RbwimXR d6brRqLcqopgLyZcBiitwMdilQ== X-Received: by 10.223.134.132 with SMTP id 4mr1648937wrx.10.1518535529550; Tue, 13 Feb 2018 07:25:29 -0800 (PST) Received: from brgl-bgdev.lan (LFbn-NIC-1-55-252.w2-15.abo.wanadoo.fr. [2.15.147.252]) by smtp.gmail.com with ESMTPSA id k37sm17159039wrf.92.2018.02.13.07.25.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 07:25:28 -0800 (PST) From: Bartosz Golaszewski To: Philipp Zabel Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski , Sekhar Nori , Kevin Hilman , David Lechner Subject: [PATCH] reset: add support for non-DT systems Date: Tue, 13 Feb 2018 16:25:24 +0100 Message-Id: <20180213152524.16620-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 --- drivers/reset/core.c | 43 ++++++++++++++++++++++++++++++++++++++-- include/linux/reset-controller.h | 13 ++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index da4292e9de97..ba7011c6e06f 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -493,12 +493,51 @@ 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_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); + } + } + } + + 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) { if (dev->of_node) - return __of_reset_control_get(dev->of_node, id, index, shared, - optional); + return __of_reset_control_get(dev->of_node, id, + index, shared, optional); + else + return __reset_control_get_lookup(dev, id, shared, optional); return optional ? NULL : ERR_PTR(-EINVAL); } diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h index adb88f8cefbc..0c081336e08b 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,7 @@ 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 * @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 +57,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