Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp253386ybt; Fri, 19 Jun 2020 00:48:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9tE9UTrqhL29JFm75cN/30BBcyEBghzZ/oFDMdEtj9ejbmEGcSPT+05En8HlSIl9usiAI X-Received: by 2002:a17:906:1f4f:: with SMTP id d15mr2417829ejk.206.1592552906406; Fri, 19 Jun 2020 00:48:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592552906; cv=none; d=google.com; s=arc-20160816; b=laa3OR6Ed9NZQA/GDxtnbzy5FohAJI2bI34fDALNvOWdsSM3PAn4SPbkJWHcBiilCo m258QrJ7vaUpZPEr1EPF7n+AhwoCThyE7RfiVWZpftebnhliOZ7Vcn8xwlCFBIn4D8r4 Fx4GwpckP9b0lW9wZE3mV5bCHGdfoudpuSE0uEP7afnHYMNB20Qqw060jKSZyciVD1Lk 8iL8UlzNvt4B5X0Z0NyosOUipyuO9Q0AYnKtAYhLSNo6eLUfJBY8U5UOJwBcd6BkGxDQ N3YVp77RswWKnNILY4FjjCGOy4T/kzSD+NWPaCXOlsNXVUURpGWyK+ldVpt1eynUdYmT P7mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ne0Ss8D5GdDPVa9xXnIP6no7dgDH/Uswpkf0SDXeXYc=; b=GfR+KECgpW/Q4UuHwfkw/kzo6w16pDhb8kp/tXSyNsaYw0oO2Ua4Dy/VWKZIm5rdm2 ifrfHEbSSF4a8U0KWln1eXY6eSONbBRJdnpxmSVF/KswlC+/vwzcMTIKw2JFUw+2AXGV 7FbWPu4Jl8t2Zr8qXa5ifF330/zOuWY4OQlLoNeHgocCvDBV95crlTHzzpTWoJlxeWjt t3zMD5zpF5Kcdt4PVEJ8fyy3b5kauAO50uJvXl300AyX6a8NeBGoaXQF3E6xaJrgrVga XRV8271iUnhTPdnqUMmIlp0ExeqU9Iw/S5uqtkPHAzVNst3GeIF9Ue9UYO9FT7h8W0gM D6cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x4gR7Siv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm27si3260531edb.308.2020.06.19.00.48.02; Fri, 19 Jun 2020 00:48: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; dkim=pass header.i=@kernel.org header.s=default header.b=x4gR7Siv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731064AbgFSHoQ (ORCPT + 99 others); Fri, 19 Jun 2020 03:44:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:60422 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731047AbgFSHoN (ORCPT ); Fri, 19 Jun 2020 03:44:13 -0400 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6CD72208DB; Fri, 19 Jun 2020 07:44:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592552652; bh=UdDU2Ya8vvambIemCpJSHDyYc3tTlgjpyYV4GqGjg7c=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=x4gR7SivjA0NaN3zVriYZxI06Of4cPLXFhY7saGIN+j0SGoA/uS6U3hEhXvrCvQGp zvUIrIwCWpKO52kedNkvexEt8/110ih9j03LnJ82GqFUI3WyIfgyg9BFs6RYiu+0c3 NzvyYl/NLT94Yf3vnqKVdKMx6hcFWXpI2vUq3E2w= Received: by mail-lj1-f170.google.com with SMTP id z9so10341469ljh.13; Fri, 19 Jun 2020 00:44:12 -0700 (PDT) X-Gm-Message-State: AOAM533FH2WCH5W0SAZ4EAr8JjCyVDANlPPPoe2eN/413yaAbPptkzI8 KtwrpYGg6xFD2qrKrB0HTlU5BhEIGWmuYzIPc6A= X-Received: by 2002:a2e:8896:: with SMTP id k22mr1087416lji.331.1592552650603; Fri, 19 Jun 2020 00:44:10 -0700 (PDT) MIME-Version: 1.0 References: <20200618080223.951737-1-lee.jones@linaro.org> <20200618100704.GC954398@dell> <20200619064141.GK954398@dell> In-Reply-To: <20200619064141.GK954398@dell> From: Chen-Yu Tsai Date: Fri, 19 Jun 2020 15:43:57 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 1/1] mfd: Add I2C based System Configuaration (SYSCON) access To: Lee Jones Cc: Chen-Yu Tsai , Arnd Bergmann , DTML , gregkh , Mark Brown , "linux-kernel@vger.kernel.org" , Bartosz Golaszewski , michael@walle.cc, Rob Herring , Andy Shevchenko , Linus Walleij , Linux ARM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 19, 2020 at 2:41 PM Lee Jones wrote: > > On Fri, 19 Jun 2020, Chen-Yu Tsai wrote: > > > On Thu, Jun 18, 2020 at 6:07 PM Lee Jones wrote: > > > > > > On Thu, 18 Jun 2020, Arnd Bergmann wrote: > > > > > > > On Thu, Jun 18, 2020 at 10:03 AM Lee Jones w= rote: > > > > > > > > > > The existing SYSCON implementation only supports MMIO (memory map= ped) > > > > > accesses, facilitated by Regmap. This extends support for regist= ers > > > > > held behind I2C busses. > > > > > > > > > > Signed-off-by: Lee Jones > > > > > > > > The implementation looks fine to me, but can you explain how this i= s going to > > > > be used, and what the advantage is over open-coding the devm_regmap= _init_i2c() > > > > in each driver that would use this? > > > > > > Does Regmap let you register/initialise an I2C address more than once= ? > > > > > > When I attempt it, I get: > > > > > > [ 0.522988] i2c i2c-0: Failed to register i2c client tmp105 at 0x3= 2 (-16) > > > [ 0.523341] i2c i2c-0: of_i2c: Failure registering /bus@4000000/mo= therboard/iofpga@7,00000000/i2c@16000/temp@32 > > > [ 0.523691] i2c i2c-0: Failed to create I2C device for /bus@400000= 0/motherboard/iofpga@7,00000000/i2c@16000/temp@32 > > > > > > > Is this about using proper locking through the regmap framework for > > > > shared i2c clients, or to reduce memory consumption when lots of dr= ivers > > > > access the same regmap? > > > > > > All of those things are valid. > > > > > > My use-case is regarding MFDs sharing an I2C interfaced address space > > > with their children. > > > > Is that an issue with the standard mfd + regmap pattern? > > There is no relationship between MFD and Regmap. It is not more > closely related to Regmap than it is any other public API provided > within the kernel. *Some* parent drivers initialise one large, > encompassing Regmap address space and pass it to their children, but > this isn't suitable in all cases. > > > For the AXP20x PMICs, we register the regmap in the parent mfd driver [= 1], > > and store that in dev_data for child drivers to fetch [2]. You could > > easily just fetch the regmap with dev_get_regmap() and a pointer to the > > parent device. > > Remember, not all use-cases are the same. Just because your H/W fits > well within the current framework, doesn't mean all will. > > Initialising in the parent is no problem if the driver is meaningful > in other ways, but what if that's all the parent driver does? In > these cases Syscon can be used instead, rendering the driver > superfluous. Meaning it can (and *should*) then be omitted. I'm guessing in your use case there isn't a need for a parent driver, and you are looking for something like "simple-mfd", but for listing sub-devices within an I2C slave device? In that case I understand. > > > > My impression of the existing syscon code is that the main value-ad= d over > > > > other ways of doing the same is the syscon_regmap_lookup_by_phandle= () > > > > interface that gives other drivers a much simpler way of getting th= e > > > > regmap just based on the DT node. Are you planning to add something > > > > like that here as well? An ideal driver interface might allow > > > > syscon_regmap_lookup_by_phandle() to work for both mmio and i2c > > > > based syscons, or additional ones as well, but implementing this wo= uld > > > > be rather tricky when the i2c core is a loadable module. > > > > The current MMIO syscon is decoupled from the DM, and there is no way > > for drivers to export or register a syscon, meaning I have to open code > > syscon_regmap_lookup_by_phandle() [3] if I want to only expose certain > > registers and not the full address range, or if I want to share the > > regmap with the existing driver (for locking purposes), or both [4]. > > Not sure I understand the problem. > > Could you explain why the current implementation doesn't work for you? > > Open coding your own implementation of Syscon is non-optimal. For the DWMAC Ethernet controllers, the platform glue almost always has a register for tuning the delays of the TX and RX clocks. In almost all later Allwinner chips, this is in a separate area, which we use a syscon for. However in one hybrid chip, this is located in the clock controller. We deemed it risky to also have the whole clock controller address range mapped as a syscon, and so we export a custom regmap. The Ethernet driver has to deal with both cases. Looking at it again, since syscon still has a platform driver, maybe I should just use the dev_get_regmap() route for both cases. > > Maybe there's room for improvement here? The same applies to the new > > I2C case, and likely any other future syscon variants. > > > > IMHO people are getting it wrong if they have both a syscon and a drive= r > > for the same device. > > Syscon is just a means to obtain a group of registers either a) > without a dedicated driver OR b) to share amongst more than 1, > potentially unrelated, user. So in the case of a) which appears to > sit well with-in your use-case and expectations, you are correct. > Whereas in the case of b) you are not. > > I hope that helps clarity the situation somewhat. The concern was mostly due to the commit message of bdb0066df96e mfd: syscon: Decouple syscon interface from platform devic= es which mentions there is a need to have a dedicated driver for such system controller but also share registers with other drivers. The latter is where the syscon interface is helpful. But does not provide any sort of coordination between the dedicated driver and the syscon. I suppose the intention might have been that the driver would get a syscon using its own device node. We avoided that but I wonder if the extra code is worth it or not. Other platforms seem to do ok. Thank you for helping me clear things up. Regards ChenYu > > > I expect the API would be expanded to cover other use-cases. This is > > > a bare bones implementation which has been kept as atomic as possible > > > for ease of review. > > > > Regards > > ChenYu > > > > [1] https://elixir.bootlin.com/linux/latest/source/drivers/mfd/axp20x-i= 2c.c#L43 > > [2] https://elixir.bootlin.com/linux/latest/source/drivers/pinctrl/pinc= trl-axp209.c#L433 > > [3] https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet= /stmicro/stmmac/dwmac-sun8i.c#L1093 > > [4] https://elixir.bootlin.com/linux/latest/source/drivers/clk/sunxi-ng= /ccu-sun8i-r40.c#L1333 > > -- > Lee Jones [=E6=9D=8E=E7=90=BC=E6=96=AF] > Senior Technical Lead - Developer Services > Linaro.org =E2=94=82 Open source software for Arm SoCs > Follow Linaro: Facebook | Twitter | Blog