devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: "Arnd Bergmann" <arnd@arndb.de>
Cc: "Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Simon Horman" <horms@kernel.org>, "Lee Jones" <lee@kernel.org>,
	"derek.kiernan@amd.com" <derek.kiernan@amd.com>,
	"dragan.cvetic@amd.com" <dragan.cvetic@amd.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Lars Povlsen" <lars.povlsen@microchip.com>,
	"Steen Hegelund" <Steen.Hegelund@microchip.com>,
	"Daniel Machon" <daniel.machon@microchip.com>,
	UNGLinuxDriver@microchip.com, "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Saravana Kannan" <saravanak@google.com>,
	"David S . Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Horatiu Vultur" <horatiu.vultur@microchip.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Netdev <netdev@vger.kernel.org>,
	linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	"Allan Nielsen" <allan.nielsen@microchip.com>,
	"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v6 2/7] reset: mchp: sparx5: Use the second reg item when cpu-syscon is not present
Date: Tue, 1 Oct 2024 18:30:38 +0200	[thread overview]
Message-ID: <20241001183038.1cc77490@bootlin.com> (raw)
In-Reply-To: <20240930162616.2241e46f@bootlin.com>

Hi Arnd,

On Mon, 30 Sep 2024 16:26:16 +0200
Herve Codina <herve.codina@bootlin.com> wrote:

> On Mon, 30 Sep 2024 13:57:01 +0000
> "Arnd Bergmann" <arnd@arndb.de> wrote:
> 
> > On Mon, Sep 30, 2024, at 12:15, Herve Codina wrote:  
> > > In the LAN966x PCI device use case, syscon cannot be used as syscon
> > > devices do not support removal [1]. A syscon device is a core "system"
> > > device and not a device available in some addon boards and so, it is not
> > > supposed to be removed.
> > >
> > > In order to remove the syscon usage, use a local mapping of a reg
> > > address range when cpu-syscon is not present.
> > >
> > > Link: https://lore.kernel.org/all/20240923100741.11277439@bootlin.com/ [1]
> > > Signed-off-by: Herve Codina <herve.codina@bootlin.com>
> > > ---    
> >   
> > >>  	err = mchp_sparx5_map_syscon(pdev, "cpu-syscon", &ctx->cpu_ctrl);    
> > > -	if (err)
> > > +	switch (err) {
> > > +	case 0:
> > > +		break;
> > > +	case -ENODEV:    
> > 
> > I was expecting a patch that would read the phandle and map the
> > syscon node to keep the behavior unchanged, but I guess this one
> > works as well.
> > 
> > The downside of your approach is that it requires an different
> > DT binding, which only works as long as there are no other
> > users of the syscon registers.  
> 
> Yes, I knwow but keeping the binding with the syscon device (i.e. compatible
> = "...", "syscon";) leads to confusion.
> Indeed, the syscon API cannot be used because using this API leads issues
> when the syscon device is removed.
> That means the you have a "syscon" node (compatible = "syscon") but we cannot
> use the syscon API (include/linux/mfd/syscon.h) with this node.
> 
> Also, in order to share resources between several consumers of the "syscon"
> registers, we need exactly what is done in syscon. I mean we need to map
> resources only once, provide this resource throught a regmap an share this
> regmap between the consumers. Indeed a lock needs to be shared in order to
> protect against registers RMW accesses done by several consumers.
> In other word, we need to copy/paste syscon code with support for removal
> implemented (feature needed in the LAN966x PCI device use case).
> 
> So, I found really simpler and less confusing to fully discard the syscon node
> and handle registers directly in the only one consumer.
> 
> With all of these, do you thing my approach can be acceptable ?
> 

Well, the related binding has been rejected.

In the next iteration, I will keep the syscon node and implement what you
suggested (i.e. read the phandle and map the syscon node).

This will look like this:
--- 8< ---
static const struct regmap_config mchp_lan966x_syscon_regmap_config = {
       .reg_bits = 32,
       .val_bits = 32,
       .reg_stride = 4,
};

static struct regmap *mchp_lan966x_syscon_to_regmap(struct device *dev,
       	                                           struct device_node *syscon_np)
{
       struct regmap_config regmap_config = mchp_lan966x_syscon_regmap_config;
       resource_size_t size;
       void __iomem *base;

       base = devm_of_iomap(dev, syscon_np, 0, &size);
       if (IS_ERR(base))
               return ERR_CAST(base);

       regmap_config.max_register = size - 4;

       return devm_regmap_init_mmio(dev, base, &regmap_config);
}
--- 8< ---

In mchp_sparx5_map_syscon(), I will call the syscon API or the local
function based on the device compatible string:
	--- 8< ---
	if (of_device_is_compatible(pdev->dev.of_node, "microchip,lan966x-switch-reset"))
		regmap = mchp_lan966x_syscon_to_regmap(&pdev->dev, syscon_np);
	else
		regmap = syscon_node_to_regmap(syscon_np);
	--- 8< ---

Is this kind of solution you were expecting?
If you have thought about something different, can you give me some pointers?

Best regards,
Hervé


  reply	other threads:[~2024-10-01 16:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30 12:15 [PATCH v6 0/7] Add support for the LAN966x PCI device using a DT overlay Herve Codina
2024-09-30 12:15 ` [PATCH v6 1/7] dt-bindings: reset: microchip,rst: Allow to replace cpu-syscon by an additional reg item Herve Codina
2024-10-01  6:43   ` Krzysztof Kozlowski
2024-10-01 16:06     ` Herve Codina
2024-09-30 12:15 ` [PATCH v6 2/7] reset: mchp: sparx5: Use the second reg item when cpu-syscon is not present Herve Codina
2024-09-30 13:03   ` Steen Hegelund
2024-09-30 13:23   ` Geert Uytterhoeven
2024-09-30 13:57   ` Arnd Bergmann
2024-09-30 14:26     ` Herve Codina
2024-10-01 16:30       ` Herve Codina [this message]
2024-10-02  9:29         ` Arnd Bergmann
2024-10-02 10:19           ` Herve Codina
2024-10-02 10:58             ` Arnd Bergmann
2024-09-30 12:15 ` [PATCH v6 3/7] misc: Add support for LAN966x PCI device Herve Codina
2024-10-02 11:08   ` Arnd Bergmann
2024-10-02 12:41     ` Herve Codina
2024-10-02 14:31       ` Arnd Bergmann
2024-10-02 16:02         ` Herve Codina
2024-09-30 12:15 ` [PATCH v6 4/7] MAINTAINERS: Add the Microchip LAN966x PCI driver entry Herve Codina
2024-09-30 12:15 ` [PATCH v6 5/7] reset: mchp: sparx5: Add MCHP_LAN966X_PCI dependency Herve Codina
2024-09-30 12:15 ` [PATCH v6 6/7] reset: mchp: sparx5: Allow building as a module Herve Codina
2024-09-30 12:15 ` [PATCH v6 7/7] reset: mchp: sparx5: set the dev member of the reset controller Herve Codina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241001183038.1cc77490@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=Steen.Hegelund@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=allan.nielsen@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=andy.shevchenko@gmail.com \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.machon@microchip.com \
    --cc=davem@davemloft.net \
    --cc=derek.kiernan@amd.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dragan.cvetic@amd.com \
    --cc=edumazet@google.com \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=horatiu.vultur@microchip.com \
    --cc=horms@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=lars.povlsen@microchip.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=saravanak@google.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).