Received: by 10.223.185.116 with SMTP id b49csp3696452wrg; Mon, 19 Feb 2018 04:35:34 -0800 (PST) X-Google-Smtp-Source: AH8x227qtH4tpbUWpgIIdV82Cvz8eTbhfDTi83icTzqe8F9eCzFmahgmRqCeCHuveulEo5vXKGri X-Received: by 10.101.81.76 with SMTP id g12mr12575223pgq.24.1519043734255; Mon, 19 Feb 2018 04:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519043734; cv=none; d=google.com; s=arc-20160816; b=nAWd1VLD1VRisZgNkGT6x6rbtPlvqvSvsHkm69dETCez3nXsL6a8QFRx7IKNDWEvGz 41Qw6EO6BUFs+vOMOrMh/idzUMEFfSFtGXJnVJhhprKkhOvCZ/oBk7UfTlzhddd0Ji1T YG2xT/RtbKxvjqlM/HlxFhj0wHINeUs+M7d9Jpary159cWFEYUU4yijF5ysoW+HG5C5C 8tj+cHpdp0HWhppo2KndHLiZay/VJTKabDlDOyT6LU2zJpod+f0BbE0E3ei2NuCuZaMP wkSUmXjIwocCIrdO1QpEEvAVfxriyycHBr0ZS1pDAdQaxgsCqWmXh3HvWrV2ELTvRDpb 2Acw== 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=d6HN+iYhj3DjlNs1cbLONUzxryI5dPtLGn4kblszIV4=; b=wgYR1iZyROQHdTzSBl1D3qGrOwsqhkIlkD0ul8wqSV2hwOznrTk4FZigxdgnsbE4/V KQDBLG/F4tjYLUVnlK8szQdyPBruTdauaLZmrdTQpq2LI366sUihTZs7/VdaTpS72pGe Fi3s+SlNSgdlUi30RbVqeNwz4LnbiU6XLlpG3bF1tWHsNhL5U9jOz/ivF1Ta8M8lxqcK g3SXc4eJ/HvjkWya9lW6oGAQ84PLjcckD0tI4qxEca/74C9TBc7eSi5mkjoOELHYc8gD sGv1K+9u1AlxN8Wx7xo3cpt0G+GtrTEkyoCLNJNKk81EDFsgD773TtC7gWqscTB7ljBF pm/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=VQPIxP7V; 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 g128si5414137pgc.574.2018.02.19.04.35.19; Mon, 19 Feb 2018 04:35:34 -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=VQPIxP7V; 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 S1752692AbeBSMem (ORCPT + 99 others); Mon, 19 Feb 2018 07:34:42 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:41560 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752638AbeBSMel (ORCPT ); Mon, 19 Feb 2018 07:34:41 -0500 Received: by mail-wr0-f195.google.com with SMTP id f14so5023037wre.8 for ; Mon, 19 Feb 2018 04:34:40 -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=d6HN+iYhj3DjlNs1cbLONUzxryI5dPtLGn4kblszIV4=; b=VQPIxP7Vi9Vimf5WHWy3LIIwCNza+ZCFPAoVDf/wCuF/CaVFWno2IcF+U8jhrzbir7 esp6zbhpxj4Xx708B4tdoAqAZm/lSSnAUVzNTil1pvBHm0jqwEz3EnmsPsXSr3pE65LR DuWaim79iaayCEnjS+cDcV2a/ciX81r2I27R2YqPH7070Le4cHvfsF8+wO23Xd0p34vS Frl+lcG6EYLS/q2eMG6OvDTJECdaCuqbjtwLuTJflVgZNEPzSZhT+6XvZNB3R0op+WMi ZkGKedJTWYCmLZ5d/rROoXIHNHeccdjMlngPWtuviHIxNRn4gYU2r3S/0PT6a97LjZT4 tgwQ== 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=d6HN+iYhj3DjlNs1cbLONUzxryI5dPtLGn4kblszIV4=; b=VIuFngiDnWgHizmXp43Iy2JfEXbgMWvMYTDJ9kpMVxMLRrjREfSuD1ckaozZ2uODCh OBzwMObSu2gBVwN5h4AWslfZRQ/b9POu2iVLxh7FJpfQRSJXhOsBjn6tZ7ttB3R+Rgjp Y9e54wCi6K8XYMFbzBDdFlo4wQ7kFhmMpVfDY26nljXXc9nFRsn2HGpXFnjMVhNqGI4l 4jZeWH8B9v1tXpFailwFYSicDyTHg7p+7Hx654MlRl0h1fZ12/MlwDZgBO5avrNI1V+O 4iRPeW+hwO1jOJfAbv18NyrNAjkaYpW32CPeHWMlbZbWoMxQKIBIVysI4gPH03s1PKMm H+zQ== X-Gm-Message-State: APf1xPA6QvCZaVKpD5qLv0ZiXFloxW7cV8B+t6Ad+Cw/U1pZCLeRhAqX z92Bem7UCfvsypf1yM5az/2MLg== X-Received: by 10.223.209.65 with SMTP id b1mr10094814wri.277.1519043679677; Mon, 19 Feb 2018 04:34:39 -0800 (PST) Received: from brgl-bgdev.baylibre.local ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id o12sm12007697wrb.15.2018.02.19.04.34.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Feb 2018 04:34:39 -0800 (PST) From: Bartosz Golaszewski To: Philipp Zabel Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski , Sekhar Nori , Kevin Hilman , David Lechner Subject: [PATCH v3] reset: add support for non-DT systems Date: Mon, 19 Feb 2018 13:34:35 +0100 Message-Id: <20180219123435.12007-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, an additional, optional identifier string and the reset id number. 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[] = { { .dev = "foo", .reset_id = "foo_id", .id = 14 }, { .dev = "bar", .id = NULL, .id = 3 }, { } }; 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 v2 -> v3: - added the reset id number field to the lookup struct so that we don't need to rely on the array index drivers/reset/core.c | 40 +++++++++++++++++++++++++++++++++++++++- include/linux/reset-controller.h | 17 +++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index da4292e9de97..7dceab1012a6 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 *reset_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 ((!reset_id && !lookup->reset_id) || + !strcmp(reset_id, lookup->reset_id)) { + rstc = __reset_control_get_internal(rcdev, + lookup->id, 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..345fd9a760f7 100644 --- a/include/linux/reset-controller.h +++ b/include/linux/reset-controller.h @@ -22,6 +22,20 @@ 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 + * @reset_id: additional reset identifier (if the device uses multiple + * reset lines) + * @id: ID of the reset controller in the reset controller device + */ +struct reset_lookup { + const char *dev; + const char *reset_id; + unsigned long id; +}; + struct module; struct device_node; struct of_phandle_args; @@ -34,6 +48,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 +61,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