From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
"Bartosz Golaszewski" <bgolaszewski@baylibre.com>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
linux-pwm@vger.kernel.org,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>
Subject: Re: [PATCH v4] gpio: pca953x: Add Maxim MAX7313 PWM support
Date: Mon, 6 Jan 2020 14:44:37 +0100 [thread overview]
Message-ID: <20200106144437.615698c1@xps13> (raw)
In-Reply-To: <CAHp75VeJNZWz_Cv=dozAwt74OBu8TgyYe5bNU3sHreRMdqxR8A@mail.gmail.com>
Hi Andy,
> > #define PCA_INT BIT(8)
> > #define PCA_PCAL BIT(9)
>
> > +#define MAX_PWM BIT(10)
>
> Use same prefix.
I am not sure it is relevant here, I think showing the specificity of
the MAXIM PWM is okay.
>
> ...
>
> > +#define PWM_MAX_COUNT 16
> > +#define PWM_PER_REG 2
>
> > +#define PWM_BITS_PER_REG (8 / PWM_PER_REG)
>
> Can we simple put 4 here?
>
Fine
> ...
>
> > +#define PWM_INTENSITY_MASK GENMASK(PWM_BITS_PER_REG - 1, 0)
>
> Please use plain numbers for the GENMASK() arguments.
Ok
>
> ...
>
> > +struct max7313_pwm_data {
> > + struct gpio_desc *desc;
> > +};
>
> Are you plan to extend this? Can we directly use struct gpio_desc pointer?
I'm not a fan of this method at all, I think it is better practice to
keep a container in this case, which can be easily extended when needed.
>
> ...
>
> > + if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE &&
> > + chip->driver_data & MAX_PWM) {
>
> Can't we simple check only for a flag for now?
I don't get it. You just want the driver_data & MAX_PWM check?
>
> > + if (reg >= MAX7313_MASTER &&
> > + reg < (MAX7313_INTENSITY + bank_sz))
> > + return true;
> > + }
>
> ...
>
> > + if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE &&
> > + chip->driver_data & MAX_PWM) {
> > + if (reg >= MAX7313_MASTER &&
> > + reg < (MAX7313_INTENSITY + bank_sz))
> > + return true;
> > + }
>
> This is a duplicate from above. Need a helper?
Perhaps!
>
> ...
>
> > +/*
> > + * Max7313 PWM specific methods
> > + *
> > + * Limitations:
> > + * - Does not support a disabled state
> > + * - Period fixed to 31.25ms
> > + * - Only supports normal polarity
> > + * - Some glitches cannot be prevented
> > + */
>
> Can we have below in a separate file and attach it to the gpio-pca953x
> code iff CONFIG_PWM != n?
I'll check, why not.
>
> ...
>
> > + mutex_lock(&pca_chip->i2c_lock);
>
> > + regmap_read(pca_chip->regmap, reg, &val);
>
> No error check?
>
> > + mutex_unlock(&pca_chip->i2c_lock);
>
> ...
>
> > + if (shift)
>
> Redundant.
Ok
>
> > + val >>= shift;
>
> ...
>
> > + mutex_lock(&pca_chip->i2c_lock);
> > + regmap_read(pca_chip->regmap, reg, &output);
> > + mutex_unlock(&pca_chip->i2c_lock);
>
> No error check?
>
> ...
>
> > + mutex_lock(&pca_chip->i2c_lock);
> > + regmap_read(pca_chip->regmap, reg, &output);
> > + mutex_unlock(&pca_chip->i2c_lock);
>
> No error check?
>
> ...
>
> > +static int max7313_pwm_request(struct pwm_chip *chip,
> > + struct pwm_device *pwm)
> > +{
> > + struct max7313_pwm *max_pwm = to_max7313_pwm(chip);
> > + struct pca953x_chip *pca_chip = to_pca953x(max_pwm);
> > + struct max7313_pwm_data *data;
> > + struct gpio_desc *desc;
> > +
> > + desc = gpiochip_request_own_desc(&pca_chip->gpio_chip, pwm->hwpwm,
> > + "max7313-pwm", GPIO_ACTIVE_HIGH, 0);
> > + if (IS_ERR(desc)) {
>
> > + dev_err(&pca_chip->client->dev,
>
> Can't we get to struct device easily?
> If it's possible maybe we could move next line to this one?
I'll try.
>
> > + "pin already in use (probably as GPIO): %ld\n",
> > + PTR_ERR(desc));
> > + return PTR_ERR(desc);
> > + }
>
> > + return 0;
> > +}
>
> ...
>
> > + if (intensity)
> > + set_bit(pwm->hwpwm, max_pwm->active_pwm);
> > + else
> > + clear_bit(pwm->hwpwm, max_pwm->active_pwm);
>
> assign_bit()
Nice!
>
> By the way, do you really need it to be atomic? Perhaps __asign_bit()?
Maybe not, indeed.
>
> ...
>
> > + active = bitmap_weight(max_pwm->active_pwm, PWM_MAX_COUNT);
>
> > + if (!active)
>
> In this case more readable will be active == 0 since you compare this
> to the exact value.
>
"if (!active)" is read "if not active" which is IMHO very descriptive!
I'll correct most of your comments and send a v5.
Thanks,
Miquèl
next prev parent reply other threads:[~2020-01-06 13:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-29 19:10 [PATCH v4] gpio: pca953x: Add Maxim MAX7313 PWM support Miquel Raynal
2019-12-12 15:26 ` Linus Walleij
2019-12-12 21:14 ` Uwe Kleine-König
2019-12-16 8:39 ` Miquel Raynal
2019-12-16 8:54 ` Uwe Kleine-König
2019-12-16 9:14 ` Miquel Raynal
2019-12-16 9:24 ` Uwe Kleine-König
2019-12-16 21:50 ` Andy Shevchenko
2020-01-06 13:44 ` Miquel Raynal [this message]
2020-01-06 21:11 ` Miquel Raynal
2020-01-07 12:31 ` Linus Walleij
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=20200106144437.615698c1@xps13 \
--to=miquel.raynal@bootlin.com \
--cc=andy.shevchenko@gmail.com \
--cc=bgolaszewski@baylibre.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=thierry.reding@gmail.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=u.kleine-koenig@pengutronix.de \
/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).