Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1251815ybz; Thu, 16 Apr 2020 05:57:26 -0700 (PDT) X-Google-Smtp-Source: APiQypISZUvB68QulpjQq6bOEzdrHL7EGFSeourQIJb0FUGJIFOmE2PO4lwPpfSZ5fu/+15PCxYD X-Received: by 2002:a17:906:3289:: with SMTP id 9mr9501957ejw.130.1587041846064; Thu, 16 Apr 2020 05:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587041846; cv=none; d=google.com; s=arc-20160816; b=qycgD3yEtol4zQr2VXYwpJM0cJj5+7+57H/SyX7WgllE1MqCEstRAM2/6bS6ZI3ROH VTMqAhRTOBWU8c+v8QUQiz4Tk6k8FD0A2ddCHZBGMqWRzVC0T2L4aQMRmhl4Y2t2C6jC mK+f60Yeg8RVL+sA8v9ZxDCJYjJaTwHjzAlOLgt/7caTpOIXmM3lMdocXgMlct0cVvb4 01+Ge3y9V+VXkiT+iqb2FNvKPiKuNm1tbE9FCVaH5sbK1eSQtx27Prr400l9Cv8ThKYT tJlQ9w66YIQw8QYsqo2ZE7kXr8prGWkCufHDfYezBKYiY2FI6/zy/xS6OBW7qqxRylOC mnHw== 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 :in-reply-to:references:mime-version; bh=c/ihTYCTD3epNk5Gu+lgAZE4OJm8QPNObknlT0RXmos=; b=mvq5hvyphi3tUGZNevZbbb65UbnLh58ZDKYcOrDJb51M1u5cmD9Wl/UnvrQdUgP62f XwMNV6MGwK5PfFdoNDLszg6NZ8vXz8LWQMbAjSBkFLSl70EfGfbLP/5M3WxywsbqDs/r +cHn8izlep/hw7UoaxWrfEi3nNG17ptaXmsB5mhv69I7RHa1DglCzGTKnJixel3Yg0NO ANZDXfPxI04sCqoOPBmZno/iuDaNDNe5l/3ZJZZSfd/MEmaEuel7k05CqVsfKzxD5HrJ M3ANNOb1PwqD9/H+6JnA9tB67LjugGeTZuDGJ/uBggj9iRsn9Vu0HNLoyHQv4VrzYpnb d48Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 30si14761557edr.255.2020.04.16.05.57.02; Thu, 16 Apr 2020 05:57:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2894561AbgDPMzM (ORCPT + 99 others); Thu, 16 Apr 2020 08:55:12 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:53131 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2894377AbgDPMzE (ORCPT ); Thu, 16 Apr 2020 08:55:04 -0400 Received: from mail-lj1-f169.google.com ([209.85.208.169]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPSA (Nemesis) id 1MqK2d-1ivFKg0nSd-00nRFg for ; Thu, 16 Apr 2020 14:55:01 +0200 Received: by mail-lj1-f169.google.com with SMTP id u6so6077799ljl.6 for ; Thu, 16 Apr 2020 05:55:01 -0700 (PDT) X-Gm-Message-State: AGi0PuYoJbYh1+QdfJCPWxDTAhhqPNs93z4IaxRpe9WXRyonkHQK9ewN X6CkUoiXnPl0lYe/ipetl9dvHA30wodPvzEu+qE= X-Received: by 2002:a2e:b888:: with SMTP id r8mr6519458ljp.128.1587041700605; Thu, 16 Apr 2020 05:55:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Arnd Bergmann Date: Thu, 16 Apr 2020 14:54:43 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH v2 3/3] soc: sprd: Add Spreadtrum special bits updating support To: Baolin Wang Cc: Lee Jones , Mark Brown , Orson Zhai , Lyra Zhang , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:S1VtNc0DQCU/+cVc+TCwgsKYeCbevWEURuBZxK0Tlt+mt15qaJK OlW0YRgu2fpv8CW8HZNdBUYd+uBop5DXtFN7k0oViy4kC0KnLWqcgAIDNSFNfeSzRmivhyZ JLp8AnMb/6B6p6MFe5Ye1BvKsMcZ+8uXEQTwdGFOIZfGt1YpAQPnvdnykuNG5CnN9WA1u7a S41eDD+175zL1BMMp6V5A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:UMFHcJWeNR8=:JaI9i+eoUrTXfKTENVCInm msVbcGqfmgtx62y1+holZCui7i0rJUywhVO1LIkV5QIYSfmPc9kkeMmiVKRBKKIwSmvFDBTbL IcHw7f+cQYYIaxko1Sad/JkJ8kCsTZDOvm9KQ78W4nN3uqb0CemKEeLLsozD7BuLXIsibS0L2 nycrdoePaGfxT8ZNIpG42dXSpoBsMGCmgp9spDCxS2sc1OASJqcW+buvntUtuWfZvoEno6mvT doBghwBmjBd6VfNhaOEqBra/Pbl0+30tuNf+RdNjYz4UQtxrqtV7K1r3ePt+Wswo1dTMHJljL X12RSSsKaMjao6fmsv8UV1hJ4xlsSCbDBr3G1ATD0Oc/qlhmYOtDEWumfCKD+iOhvj+OPkpXv 5qBghSv0A+0lVWXwqsuCewuyvvDk6FM87aGPw9vNchJ6yET4wUNphDqmLx1FCpvSz2LO0I2vY 6h9WXRdnxqKJRS5FEkfcR5ne4qtkE/SnNBucx8qTXVL5zCw3TOKCzjlXQ94ZreQm6v4FRz9yU 7r22brBcwnEgM/qEj4O8nBFgnn6BWtuIzN9ouRYY16AeN6J5odtzPJQLPoW7u7kl6iXIPfWCd TPnE4vopJv+4MwTKvsQwgBIZpwHjroM2fINgC5P25nTJoMKmF/WYY20PWTHngK7v0WhX3AHtw RzKlg4jFeSZq63rEikytz5PYH1NnaQfJJfu1hlZC9bNr2nbTd6NSawVMyrclbnC031Sm3/bSA /btYP+mk2YoPYWs8fdmxQK7LVAsouO3oMdBYWKzx9SGNeLtV8vYrNBEt2BNBMtKCUwz/CRgM1 KbzqlOTeIJ/jmqjgaowB5uURWeZ6xKYM3zjYeSbaxA/ZnhWnAk= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 16, 2020 at 5:49 AM Baolin Wang wrote: > > On Wed, Apr 15, 2020 at 11:36 PM Arnd Bergmann wrote: > > > > On Mon, Apr 13, 2020 at 8:14 AM Baolin Wang wrote: > > > > > > The spreadtrum platform uses a special set/clear method to update > > > registers' bits, which can remove the race of updating the global > > > registers between the multiple subsystems. Thus we can register > > > a physical regmap bus into syscon core to support this. > > > > > > Signed-off-by: Baolin Wang > > > > I'd hope to avoid complicating the syscon driver further for this. > > Have you tried to use something other than syscon here to > > provide the regmap? > > I did not figure out other better solutions, since we still want to > use the common syscon driver with related APIs and node properties. > > Otherwise, I am afraid I should copy the common syscon driver into the > Spreadtrum SoC syscon driver with providing a new regmap bus, and > invent other similar APIs for users, but I think this is not good. We > still want to use the standard syscon APIs to keep consistent. Right, that is certainly a problem. One option would be modifying the syscon driver itself, making it support the spreadtrum specific update_bits function natively when a matching syscon node is used and CONFIG_ARCH_SPRD is enabled. We do support endianess properties and hwspinlocksin syscon, so adding another variant of regmap there isn't too much of a stretch. > > > + void __iomem *base = context; > > > + unsigned int set, clr; > > > + > > > + set = val & mask; > > > + clr = ~set & mask; > > > + > > > + if (set) > > > + writel(set, base + reg + SPRD_REG_SET_OFFSET); > > > + > > > + if (clr) > > > + writel(clr, base + reg + SPRD_REG_CLR_OFFSET); > > > + > > > + return 0; > > > +} > > > > Regarding the implementation: Doesn't this introduce a new race > > between setting and clearing bits if you do both at the same time? > > > > This may not be a problem if you never do. > > I think this is not a issue, we just make sure the set bits updating > and clear bits updating both are atomic operation, which is safe to > update bits, right? > If user want to protect a series of bits updating operation between > the multiple subsystems, ( such as including several bits setting and > bit clearing operations), you still need use hwlocks. But that's > another topic, which is not set/clr method can solve. One thing that breaks is setting a multi-bit field atomically. We have other drivers doing for instance static void cdce925_clk_set_pdiv(struct clk_cdce925_output *data, u16 pdiv) { switch (data->index) { case 0: regmap_update_bits(data->chip->regmap, CDCE925_REG_Y1SPIPDIVH, 0x03, (pdiv >> 8) & 0x03); regmap_write(data->chip->regmap, 0x03, pdiv & 0xFF); break; case 1: regmap_update_bits(data->chip->regmap, 0x16, 0x7F, pdiv); break; case 2: regmap_update_bits(data->chip->regmap, 0x17, 0x7F, pdiv); break; case 3: regmap_update_bits(data->chip->regmap, 0x26, 0x7F, pdiv); break; ... } This works with the read-modify-write method under a lock, but it would risk setting a dangerous (i.e. crashing the system or damaging the hardware) clock divider value if we first enable some bits and then disable some others. Hardware registers only have bits you set or clear independently it is not a problem. > > > +static int sprd_syscon_init(void) > > > +{ > > > + syscon_register_phys_regmap_bus(&sprd_syscon_regmap); > > > + > > > + return 0; > > > +} > > > +core_initcall_sync(sprd_syscon_init); > > > > I don't think this part can be done at all: If you load the module on a > > generic kernel running on a random other platform, it will break as > > there is no check at all to ensure the platform is compatible. > > > > The same thing happens on a platform that may have multiple > > syscon nodes, when not all of them use the same register layout. > > > > The only sane way that I can see would be to do it based on > > properties of the syscon node itself. > > OK, so what about adding a new property for the syscon node? and we > can check if need to register a new physical regmap bus from the > syscon node. > > if (of_property_read_bool(np, "physical-regmap-bus") && syscon_phy_regmap_bus) > regmap = regmap_init(NULL, syscon_phy_regmap_bus, base, &syscon_config); > else > regmap = regmap_init_mmio(NULL, base, &syscon_config); The property also needs to encode which implementation is used, either describing the way that spreadtrum does the bit set/clear, or just naming it something with spreadtrum. This could be either in the compatible string as a more specific identifier, or it could be a separate property. Arnd