Linux SOC development
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Andy Shevchenko <andy@kernel.org>
Cc: Gregory CLEMENT <gregory.clement@bootlin.com>,
	Arnd Bergmann <arnd@arndb.de>,
	soc@kernel.org, arm@kernel.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH v2 3/7] platform: cznic: turris-omnia-mcu: Add support for MCU connected GPIOs
Date: Wed, 20 Sep 2023 19:08:18 +0200	[thread overview]
Message-ID: <20230920190818.50b2018b@dellmb> (raw)
In-Reply-To: <ZQmbd211FzPjA97r@smile.fi.intel.com>

Hi Andy,

I'm sending reply to some of your comments. For those to which I do not
reply I will simply incorporate your suggestions.

On Tue, 19 Sep 2023 16:00:39 +0300
Andy Shevchenko <andy@kernel.org> wrote:

> On Tue, Sep 19, 2023 at 12:38:11PM +0200, Marek Behún wrote:
> > - front button pin
> > - enable pins for USB regulators
> > - MiniPCIe / mSATA card presence pins in MiniPCIe port 0
> > - LED output pins from WAN ethernet PHY, LAN switch and MiniPCIe ports
> > - on board revisions 32+ also various peripheral resets and another
> >   voltage regulator enable pin  
> 
> Can the main driver provide a regmap and all other use it?

It can't. These are not registers accessible via I2C at specific
addresses, but commands with different-length arguments. This was
already discussed 4 years ago with Jacek, see
  https://www.spinics.net/lists/linux-leds/msg11587.html
There, Jacek suggested writing regmap API for the leds-turris-omnia
driver (the MCU is also a LED controller and has same command
interface, only at different I2C address).

> > +	if (gpio->ctl_cmd)
> > +		return -EOPNOTSUPP;  
> 
> I believe internally we use ENOTSUPP.
> Ditto for all cases like this.

checkpatch warns: 
  ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP

> > +	mutex_lock(&mcu->lock);
> > +
> > +	if (ctl_mask)
> > +		err = omnia_ctl_cmd_unlocked(mcu,
> >   CMD_GENERAL_CONTROL, ctl,
> > +					     ctl_mask);  
> 
> > +	if (!err && ext_ctl_mask)
> > +		err = omnia_ctl_cmd_unlocked(mcu, CMD_EXT_CONTROL,
> >   ext_ctl,
> > +					     ext_ctl_mask);  
> 
> Can it be
> 
> 	if (err)
> 		goto out_unlock;
> 
> 	if (_mask)
> 		...

Linus suggested using guards, so I will refactor this away.

> > +	mutex_unlock(&mcu->lock);  
> 
> > +	if (err)
> > +		dev_err(&mcu->client->dev, "Cannot set GPIOs:
> >   %d\n", err);  
> 
> How is useful this one?

The function does not return, this way we will know something has gone
wrong. I am used to do this from the networking subsystem, where people
at least from mv88e6xxx wanted such behavior. Do you want me to drop
this?

> > +static int omnia_gpio_init_valid_mask(struct gpio_chip *gc,
> > +				      unsigned long *valid_mask,
> > +				      unsigned int ngpios)
> > +{
> > +	struct omnia_mcu *mcu = gpiochip_get_data(gc);  
> 
> > +	bitmap_zero(valid_mask, ngpios);  
> 
> No need.
> 
> Also do you have bitops.h included?

bitmap.h actually for this

> > +	rising = reply[0] | (reply[2] << 8) | (reply[4] << 16) |
> > +		 (reply[6] << 24);
> > +	falling = reply[1] | (reply[3] << 8) | (reply[5] << 16) |
> > +		  (reply[7] << 24);  
> 
> With a help of two masks, you can access to the both edges as to
>   64-bit value and simplify the code.

Huh? As in
  rising = reply & 0x00ff00ff00ff00ff;
  falling = reply & 0xff00ff00ff00ff00;
?
But then I can't or the rising bit with the corresponding falling bit
to get pending...
Or I guess i can with:
  pending = rising & (pending >> 8);

Am I understanding you correctly?

But then I would need to store the mask in driver data as a 64-bit
value with half the data not used. Also the CPU is 32-bit.

> > +static struct attribute *omnia_mcu_gpio_attrs[] = {
> > +	&dev_attr_front_button_mode.attr,
> > +	NULL,
> > +};
> > +
> > +static const struct attribute_group omnia_mcu_gpio_group = {
> > +	.attrs = omnia_mcu_gpio_attrs,
> > +};  
> 
> ATTRIBUTE_GROUPS() ?

I only want to create ane attribute_group. (I am using
devm_device_add_group(), not devm_device_add_groups()).

> > +	err = devm_device_add_group(dev, &omnia_mcu_gpio_group);  
> 
> No way, no-one should use the API scheduled for removal.
> What's wrong with .dev_groups ?

Can I add them conditionally? GPIO chip is always created, but the
patch 4/7 only adds the attributes conditionally. Is it possible via
.dev_groups?

> 
> ...
> 
> > +void omnia_mcu_unregister_gpiochip(struct omnia_mcu *mcu)
> > +{
> > +	if (!(mcu->features & FEAT_NEW_INT_API))
> > +
> >   cancel_delayed_work_sync(&mcu->button_release_emul_work); +
> > +	mutex_destroy(&mcu->lock);  
> 
> Wrong order?

No, the mutex may be used in the work. Can't destroy it first. Or am I
misunderstanding something?


> >  struct omnia_mcu {
> >  	struct i2c_client *client;
> >  	const char *type;
> >  	u16 features;
> > +
> > +	/* GPIO chip */
> > +	struct gpio_chip gc;  
> 
> Making this a first member may lead to the better code. Check with
>   bloat-o-meter.

kabel@dellmb ~/linux $ ./scripts/bloat-o-meter \
  turris-omnia-mcu.o turris-omnia-mcu-gpiochip-first.o
add/remove: 0/0 grow/shrink: 9/0 up/down: 52/0 (52)
Function                                     old     new   delta
omnia_mcu_register_gpiochip                  840     852     +12
omnia_mcu_probe                              696     708     +12
omnia_mcu_unregister_gpiochip                 20      24      +4
omnia_irq_bus_sync_unlock                    256     260      +4
omnia_irq_bus_lock                            36      40      +4
omnia_gpio_get_multiple                      872     876      +4
omnia_gpio_get                               372     376      +4
fw_features_show                              28      32      +4
front_button_mode_show                       260     264      +4
Total: Before=10468, After=10520, chg +0.50%

Seems the code grew when I swapped it.


Marek

  reply	other threads:[~2023-09-20 17:08 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-19 10:38 [PATCH v2 0/7] Turris Omnia MCU driver Marek Behún
2023-09-19 10:38 ` [PATCH v2 1/7] dt-bindings: arm: add cznic,turris-omnia-mcu binding Marek Behún
2023-09-20 12:37   ` Krzysztof Kozlowski
2023-09-19 10:38 ` [PATCH v2 2/7] platform: cznic: Add preliminary support for Turris Omnia MCU Marek Behún
2023-09-19 12:29   ` Andy Shevchenko
2023-09-19 15:16     ` Marek Behún
2023-09-19 18:27       ` Andy Shevchenko
2023-09-20 14:19         ` Marek Behún
2023-09-20 14:47           ` Andy Shevchenko
2023-09-19 10:38 ` [PATCH v2 3/7] platform: cznic: turris-omnia-mcu: Add support for MCU connected GPIOs Marek Behún
2023-09-19 13:00   ` Andy Shevchenko
2023-09-20 17:08     ` Marek Behún [this message]
2023-09-21  9:55       ` Andy Shevchenko
2023-09-21 20:25         ` Marek Behún
2023-09-22 14:18           ` Andy Shevchenko
2023-09-25 10:03             ` Marek Behún
2023-09-25 10:29               ` Andy Shevchenko
2023-09-21 18:42     ` Marek Behún
2023-09-22 14:14       ` Andy Shevchenko
2023-09-20 11:58   ` Linus Walleij
2023-09-20 13:36     ` Andy Shevchenko
2023-09-21 19:45     ` Marek Behún
2023-09-21 20:14       ` Marek Behún
2023-09-22 14:21         ` Andy Shevchenko
2023-09-19 10:38 ` [PATCH v2 4/7] platform: cznic: turris-omnia-mcu: Add support for poweroff and wakeup Marek Behún
2023-09-19 10:38 ` [PATCH v2 5/7] platform: cznic: turris-omnia-mcu: Add support for MCU watchdog Marek Behún
2023-09-19 13:50   ` Guenter Roeck
2023-09-22 11:46     ` Marek Behún
2023-09-19 10:38 ` [PATCH v2 6/7] ARM: dts: turris-omnia: Add MCU system-controller node Marek Behún
2023-09-19 10:38 ` [PATCH v2 7/7] ARM: dts: turris-omnia: Add GPIO key node for front button Marek Behún

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=20230920190818.50b2018b@dellmb \
    --to=kabel@kernel.org \
    --cc=andy@kernel.org \
    --cc=arm@kernel.org \
    --cc=arnd@arndb.de \
    --cc=brgl@bgdev.pl \
    --cc=gregory.clement@bootlin.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=soc@kernel.org \
    /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