Received: by 10.223.185.116 with SMTP id b49csp426511wrg; Wed, 14 Feb 2018 01:00:51 -0800 (PST) X-Google-Smtp-Source: AH8x225LvDOw8H0JnyUHvRix89uMwmS9SegutKhJBS9xqpt9qnqOVMAs8XUrb/y4evtsa0vojLKB X-Received: by 10.99.125.74 with SMTP id m10mr3427750pgn.354.1518598851034; Wed, 14 Feb 2018 01:00:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518598850; cv=none; d=google.com; s=arc-20160816; b=VGbpAKgOdbdDJ+lvfLz7EkYSGXfDVqIlVgKy3+pRx37eb7mxEcXguGEbQTavENK3zA +dES0siKWHcATB8sXFKmKaLAZGCXIwZVVOZNMGEAagOTka10eVM0Bi3f8mYSzpRV0x+7 99Jvr97vdEIuYdaHN0njFaRZIFEm2Nueqq2BnaJpzJjwRlzWt5mxCEPrSmg/3l/Xul11 jwONA3HKEDavn6Hax1uDuRUa3Fxd4q4wWKx8yiS3HNdNBmV0ypSkzkueAB6u4qTon35+ ZsAfHiRvgSXC5epWY5OavQUPlpdCd8isJIL2yxEWxA/vbcica/CCbPgfGy3OwwWBmLIg Bmnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=HqyRUL/deJU359JwpgEafRgQNveLZg/2O2Et8F6EMwg=; b=OWXTvMICI4Ea6F1lR5v8cTwZXAXMW5eewJu6BGm3I8emMr8ny4yRWE4lQDUMdxj3rb OFRPXyMB3JTZC1eqYJr3eJg8LHhFkWPPvtvTaW9GsWIPyrzLWdWcimpwo7SWwuvpqaUr qFFiUdwBdEnwFfIkfsK9P3kDLCIyJ4TE3Tx/W9cMH9kehjDbXRTJqugOf0DgqeynqA1P EYJ9rTXJinWX5mwmup6CBVQRraqUzyU8C+nZCmbPUru9GW7HE0vdTZshFTQmyAa+j3xq QY+Xa1QX3LrtKq4o5mA/DMHGfW9ArAT/3jFsjDEDdAiIdHx0A9Dwd5aGaBEewYrzPiU7 yTfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=bWL7Glz5; 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 m6si2827028pff.273.2018.02.14.01.00.36; Wed, 14 Feb 2018 01:00:50 -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=bWL7Glz5; 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 S1754621AbeBNI74 (ORCPT + 99 others); Wed, 14 Feb 2018 03:59:56 -0500 Received: from mail-ot0-f169.google.com ([74.125.82.169]:33994 "EHLO mail-ot0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754332AbeBNI7y (ORCPT ); Wed, 14 Feb 2018 03:59:54 -0500 Received: by mail-ot0-f169.google.com with SMTP id l10so19778699oth.1 for ; Wed, 14 Feb 2018 00:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=HqyRUL/deJU359JwpgEafRgQNveLZg/2O2Et8F6EMwg=; b=bWL7Glz5Wj5xJYa0c7iLPAjXhddqWKJZ5SSWtc+YeA/RRmjNOfzTzDIOoXpufAZHNE PGQz6CreYaW396oQ2eQZMu5DEysxz7qkJP5qLFj2L3BowXJ67s5Ro8dAmcWHe+KrlpB2 74X0dy1IMObbVt13I1OnvvLQyu47n7TV8bBAQIphyQ2v1bjyFowBbXG2fxuYL17dLoTW jhb5KTD9PKgBC5DtmyiaibQo0o3gJr0ZYnhdSXeaV9TU3MIBhAupJSPWyl27xKYCw8kJ 3Al9HvD5mV/PNzU5CVLnJlYJqyvV72omk89MOF2U5tsFxK5BN/aRjQVBpoeOLWM7Hz7Z 5zKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=HqyRUL/deJU359JwpgEafRgQNveLZg/2O2Et8F6EMwg=; b=Uil5eBlTlOawsOMq4pVDqFJ15IkdLNA0VMXVZKM3IvRcHxR47s1lG5kREbhgDCQij7 uOtI3nfqw8PIgbsgocjJzSfrp6clwSObIaDOIejess9se5mGr/hBKAmTurLqF4yw4aTJ STc04kGUCPmmgoQef4mWgrEF+M+1RiIF7JbUHoQLChrs1KxMhN6lh1yLZGNT1cttRXIr lMLi5LTk6ILSu+2vZXeSsrvE5/7wNxyCqA631ElhxX+yabvBOXG/TCtlacouD/rH6CNJ qXE3io3TGQ0sWA96+Do0PtpdgU/S4nWrXu5wj1CV9ACfMjzD90++9D0LYhujA6pserC/ TNjQ== X-Gm-Message-State: APf1xPDb4K88Y2eNKzhAZVjqsMNlmPDcc+Je90oFvn16ediipGWGgvdi 1Ob/KBHj+8hbEwfP7ziGPq1bqFdqW7Xww3wBHU+gzg== X-Received: by 10.157.70.145 with SMTP id z17mr3052270ote.306.1518598794212; Wed, 14 Feb 2018 00:59:54 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.42.71 with HTTP; Wed, 14 Feb 2018 00:59:53 -0800 (PST) In-Reply-To: References: <20180213183946.1662-1-brgl@bgdev.pl> From: Bartosz Golaszewski Date: Wed, 14 Feb 2018 09:59:53 +0100 Message-ID: Subject: Re: [PATCH v2] reset: add support for non-DT systems To: Andy Shevchenko Cc: Philipp Zabel , Linux Kernel Mailing List , Bartosz Golaszewski , Sekhar Nori , Kevin Hilman , David Lechner Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-02-13 20:17 GMT+01:00 Andy Shevchenko : > On Tue, Feb 13, 2018 at 8:39 PM, Bartosz Golaszewski wrote: >> 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. > >> +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; >> + } > > Wouldn't be slightly more readable > > if (id && lookup->id) { > if (strcmp(id, lookup->id)) > continue; > } else if (id || lookup->id) { > continue; > } > > rstc = __reset_control_get_internal(rcdev, index, shared); > break; > You'd get less indentations, yes but I wanted to emphasize the condition on which we want to stop in this line. >> + } >> + } >> + >> + mutex_unlock(&reset_list_mutex); >> + > >> + if (!rstc) >> + return optional ? NULL : ERR_PTR(-ENOENT); > > Isn't simpler > > if (!optional && !rstc) // or other way around, depending which might > be more offten > return ERR_PTR(...); > IMO it's just a matter of taste. Thanks, Bartosz