All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: f.fainelli@gmail.com, linux-kernel@vger.kernel.org,
	linux-pwm@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	wahrenst@gmx.net, linux-input@vger.kernel.org,
	dmitry.torokhov@gmail.com, gregkh@linuxfoundation.org,
	devel@driverdev.osuosl.org, p.zabel@pengutronix.de,
	linux-gpio@vger.kernel.org, linus.walleij@linaro.org,
	linux-clk@vger.kernel.org, sboyd@kernel.org,
	linux-rpi-kernel@lists.infradead.org, bgolaszewski@baylibre.com,
	andy.shevchenko@gmail.com
Subject: Re: [PATCH v7 11/11] pwm: Add Raspberry Pi Firmware based PWM bus
Date: Wed, 10 Mar 2021 12:50:41 +0100	[thread overview]
Message-ID: <20210310115041.s7tzvgdpksws6yss@pengutronix.de> (raw)
In-Reply-To: <20210118123244.13669-12-nsaenzjulienne@suse.de>

[-- Attachment #1: Type: text/plain, Size: 2838 bytes --]

Hello Nicolas,

On Mon, Jan 18, 2021 at 01:32:44PM +0100, Nicolas Saenz Julienne wrote:
> diff --git a/drivers/pwm/pwm-raspberrypi-poe.c b/drivers/pwm/pwm-raspberrypi-poe.c
> new file mode 100644
> index 000000000000..ca845e8fabe6
> --- /dev/null
> +++ b/drivers/pwm/pwm-raspberrypi-poe.c
> @@ -0,0 +1,220 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> + * For more information on Raspberry Pi's PoE hat see:
> + * https://www.raspberrypi.org/products/poe-hat/
> + *
> + * Limitations:
> + *  - No disable bit, so a disabled PWM is simulated by duty_cycle 0
> + *  - Only normal polarity
> + *  - Fixed 12.5 kHz period
> + *
> + * The current period is completed when HW is reconfigured.

nice.

> + */
> +
> [...]
> +static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> +				 const struct pwm_state *state)
> +{
> +	struct raspberrypi_pwm *rpipwm = raspberrypi_pwm_from_chip(chip);
> +	unsigned int duty_cycle;
> +	int ret;
> +
> +	if (state->period < RPI_PWM_PERIOD_NS ||
> +	    state->polarity != PWM_POLARITY_NORMAL)
> +		return -EINVAL;
> +
> +	if (!state->enabled)
> +		duty_cycle = 0;
> +	else if (state->duty_cycle < RPI_PWM_PERIOD_NS)
> +		duty_cycle = DIV_ROUND_DOWN_ULL(state->duty_cycle * RPI_PWM_MAX_DUTY,
> +						RPI_PWM_PERIOD_NS);
> +	else
> +		duty_cycle = RPI_PWM_MAX_DUTY;
> +
> +	if (duty_cycle == rpipwm->duty_cycle)
> +		return 0;
> +
> +	ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG,
> +					   duty_cycle);
> +	if (ret) {
> +		dev_err(chip->dev, "Failed to set duty cycle: %pe\n",
> +			ERR_PTR(ret));
> +		return ret;
> +	}
> +
> +	/*
> +	 * This sets the default duty cycle after resetting the board, we
> +	 * updated it every time to mimic Raspberry Pi's downstream's driver
> +	 * behaviour.
> +	 */
> +	ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_DEF_DUTY_REG,
> +					   duty_cycle);
> +	if (ret) {
> +		dev_err(chip->dev, "Failed to set default duty cycle: %pe\n",
> +			ERR_PTR(ret));
> +		return ret;

This only has an effect for the next reboot, right? If so I wonder if it
is a good idea in general. (Think: The current PWM setting enables a
motor that makes a self-driving car move at 100 km/h. Consider the rpi
crashes, do I want to car to pick up driving 100 km/h at power up even
before Linux is up again?) And if we agree it's a good idea: Should
raspberrypi_pwm_apply return 0 if setting the duty cycle succeeded and
only setting the default didn't?

Other than that the patch looks fine.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: devel@driverdev.osuosl.org, linux-pwm@vger.kernel.org,
	f.fainelli@gmail.com, devicetree@vger.kernel.org,
	sboyd@kernel.org, gregkh@linuxfoundation.org,
	linus.walleij@linaro.org, dmitry.torokhov@gmail.com,
	linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
	andy.shevchenko@gmail.com, bcm-kernel-feedback-list@broadcom.com,
	wahrenst@gmx.net, p.zabel@pengutronix.de,
	linux-input@vger.kernel.org, bgolaszewski@baylibre.com,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rpi-kernel@lists.infradead.org
Subject: Re: [PATCH v7 11/11] pwm: Add Raspberry Pi Firmware based PWM bus
Date: Wed, 10 Mar 2021 12:50:41 +0100	[thread overview]
Message-ID: <20210310115041.s7tzvgdpksws6yss@pengutronix.de> (raw)
In-Reply-To: <20210118123244.13669-12-nsaenzjulienne@suse.de>


[-- Attachment #1.1: Type: text/plain, Size: 2838 bytes --]

Hello Nicolas,

On Mon, Jan 18, 2021 at 01:32:44PM +0100, Nicolas Saenz Julienne wrote:
> diff --git a/drivers/pwm/pwm-raspberrypi-poe.c b/drivers/pwm/pwm-raspberrypi-poe.c
> new file mode 100644
> index 000000000000..ca845e8fabe6
> --- /dev/null
> +++ b/drivers/pwm/pwm-raspberrypi-poe.c
> @@ -0,0 +1,220 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> + * For more information on Raspberry Pi's PoE hat see:
> + * https://www.raspberrypi.org/products/poe-hat/
> + *
> + * Limitations:
> + *  - No disable bit, so a disabled PWM is simulated by duty_cycle 0
> + *  - Only normal polarity
> + *  - Fixed 12.5 kHz period
> + *
> + * The current period is completed when HW is reconfigured.

nice.

> + */
> +
> [...]
> +static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> +				 const struct pwm_state *state)
> +{
> +	struct raspberrypi_pwm *rpipwm = raspberrypi_pwm_from_chip(chip);
> +	unsigned int duty_cycle;
> +	int ret;
> +
> +	if (state->period < RPI_PWM_PERIOD_NS ||
> +	    state->polarity != PWM_POLARITY_NORMAL)
> +		return -EINVAL;
> +
> +	if (!state->enabled)
> +		duty_cycle = 0;
> +	else if (state->duty_cycle < RPI_PWM_PERIOD_NS)
> +		duty_cycle = DIV_ROUND_DOWN_ULL(state->duty_cycle * RPI_PWM_MAX_DUTY,
> +						RPI_PWM_PERIOD_NS);
> +	else
> +		duty_cycle = RPI_PWM_MAX_DUTY;
> +
> +	if (duty_cycle == rpipwm->duty_cycle)
> +		return 0;
> +
> +	ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG,
> +					   duty_cycle);
> +	if (ret) {
> +		dev_err(chip->dev, "Failed to set duty cycle: %pe\n",
> +			ERR_PTR(ret));
> +		return ret;
> +	}
> +
> +	/*
> +	 * This sets the default duty cycle after resetting the board, we
> +	 * updated it every time to mimic Raspberry Pi's downstream's driver
> +	 * behaviour.
> +	 */
> +	ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_DEF_DUTY_REG,
> +					   duty_cycle);
> +	if (ret) {
> +		dev_err(chip->dev, "Failed to set default duty cycle: %pe\n",
> +			ERR_PTR(ret));
> +		return ret;

This only has an effect for the next reboot, right? If so I wonder if it
is a good idea in general. (Think: The current PWM setting enables a
motor that makes a self-driving car move at 100 km/h. Consider the rpi
crashes, do I want to car to pick up driving 100 km/h at power up even
before Linux is up again?) And if we agree it's a good idea: Should
raspberrypi_pwm_apply return 0 if setting the duty cycle succeeded and
only setting the default didn't?

Other than that the patch looks fine.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 169 bytes --]

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

WARNING: multiple messages have this Message-ID (diff)
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: f.fainelli@gmail.com, linux-kernel@vger.kernel.org,
	linux-pwm@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	wahrenst@gmx.net, linux-input@vger.kernel.org,
	dmitry.torokhov@gmail.com, gregkh@linuxfoundation.org,
	devel@driverdev.osuosl.org, p.zabel@pengutronix.de,
	linux-gpio@vger.kernel.org, linus.walleij@linaro.org,
	linux-clk@vger.kernel.org, sboyd@kernel.org,
	linux-rpi-kernel@lists.infradead.org, bgolaszewski@baylibre.com,
	andy.shevchenko@gmail.com
Subject: Re: [PATCH v7 11/11] pwm: Add Raspberry Pi Firmware based PWM bus
Date: Wed, 10 Mar 2021 12:50:41 +0100	[thread overview]
Message-ID: <20210310115041.s7tzvgdpksws6yss@pengutronix.de> (raw)
In-Reply-To: <20210118123244.13669-12-nsaenzjulienne@suse.de>


[-- Attachment #1.1: Type: text/plain, Size: 2838 bytes --]

Hello Nicolas,

On Mon, Jan 18, 2021 at 01:32:44PM +0100, Nicolas Saenz Julienne wrote:
> diff --git a/drivers/pwm/pwm-raspberrypi-poe.c b/drivers/pwm/pwm-raspberrypi-poe.c
> new file mode 100644
> index 000000000000..ca845e8fabe6
> --- /dev/null
> +++ b/drivers/pwm/pwm-raspberrypi-poe.c
> @@ -0,0 +1,220 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> + * For more information on Raspberry Pi's PoE hat see:
> + * https://www.raspberrypi.org/products/poe-hat/
> + *
> + * Limitations:
> + *  - No disable bit, so a disabled PWM is simulated by duty_cycle 0
> + *  - Only normal polarity
> + *  - Fixed 12.5 kHz period
> + *
> + * The current period is completed when HW is reconfigured.

nice.

> + */
> +
> [...]
> +static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> +				 const struct pwm_state *state)
> +{
> +	struct raspberrypi_pwm *rpipwm = raspberrypi_pwm_from_chip(chip);
> +	unsigned int duty_cycle;
> +	int ret;
> +
> +	if (state->period < RPI_PWM_PERIOD_NS ||
> +	    state->polarity != PWM_POLARITY_NORMAL)
> +		return -EINVAL;
> +
> +	if (!state->enabled)
> +		duty_cycle = 0;
> +	else if (state->duty_cycle < RPI_PWM_PERIOD_NS)
> +		duty_cycle = DIV_ROUND_DOWN_ULL(state->duty_cycle * RPI_PWM_MAX_DUTY,
> +						RPI_PWM_PERIOD_NS);
> +	else
> +		duty_cycle = RPI_PWM_MAX_DUTY;
> +
> +	if (duty_cycle == rpipwm->duty_cycle)
> +		return 0;
> +
> +	ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG,
> +					   duty_cycle);
> +	if (ret) {
> +		dev_err(chip->dev, "Failed to set duty cycle: %pe\n",
> +			ERR_PTR(ret));
> +		return ret;
> +	}
> +
> +	/*
> +	 * This sets the default duty cycle after resetting the board, we
> +	 * updated it every time to mimic Raspberry Pi's downstream's driver
> +	 * behaviour.
> +	 */
> +	ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_DEF_DUTY_REG,
> +					   duty_cycle);
> +	if (ret) {
> +		dev_err(chip->dev, "Failed to set default duty cycle: %pe\n",
> +			ERR_PTR(ret));
> +		return ret;

This only has an effect for the next reboot, right? If so I wonder if it
is a good idea in general. (Think: The current PWM setting enables a
motor that makes a self-driving car move at 100 km/h. Consider the rpi
crashes, do I want to car to pick up driving 100 km/h at power up even
before Linux is up again?) And if we agree it's a good idea: Should
raspberrypi_pwm_apply return 0 if setting the duty cycle succeeded and
only setting the default didn't?

Other than that the patch looks fine.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2021-03-10 11:51 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-18 12:32 [PATCH v7 00/11] Raspberry Pi PoE HAT fan support Nicolas Saenz Julienne
2021-01-18 12:32 ` Nicolas Saenz Julienne
2021-01-18 12:32 ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 01/11] firmware: raspberrypi: Keep count of all consumers Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 02/11] firmware: raspberrypi: Introduce devm_rpi_firmware_get() Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 03/11] clk: bcm: rpi: Release firmware handle on unbind Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 04/11] gpio: raspberrypi-exp: " Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 05/11] reset: raspberrypi: " Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 06/11] soc: bcm: raspberrypi-power: " Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 07/11] staging: vchiq: " Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-26 17:47   ` Greg KH
2021-01-26 17:47     ` Greg KH
2021-01-26 17:47     ` Greg KH
2021-01-18 12:32 ` [PATCH v7 08/11] input: raspberrypi-ts: Release firmware handle when not needed Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 09/11] dt-bindings: pwm: Add binding for RPi firmware PWM bus Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 10/11] DO NOT MERGE: ARM: dts: Add RPi's official PoE hat support Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32 ` [PATCH v7 11/11] pwm: Add Raspberry Pi Firmware based PWM bus Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-01-18 12:32   ` Nicolas Saenz Julienne
2021-02-08 20:53   ` Nicolas Saenz Julienne
2021-02-08 20:53     ` Nicolas Saenz Julienne
2021-02-08 20:53     ` Nicolas Saenz Julienne
2021-03-09  9:59   ` Nicolas Saenz Julienne
2021-03-09  9:59     ` Nicolas Saenz Julienne
2021-03-09  9:59     ` Nicolas Saenz Julienne
2021-03-10 11:50   ` Uwe Kleine-König [this message]
2021-03-10 11:50     ` Uwe Kleine-König
2021-03-10 11:50     ` Uwe Kleine-König
2021-03-11 13:01     ` Nicolas Saenz Julienne
2021-03-11 13:01       ` Nicolas Saenz Julienne
2021-03-11 13:01       ` Nicolas Saenz Julienne
2021-03-11 13:18       ` Uwe Kleine-König
2021-03-11 13:18         ` Uwe Kleine-König
2021-03-11 13:18         ` Uwe Kleine-König
2021-03-11 13:41         ` Nicolas Saenz Julienne
2021-03-11 13:41           ` Nicolas Saenz Julienne
2021-03-11 13:41           ` Nicolas Saenz Julienne

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=20210310115041.s7tzvgdpksws6yss@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=andy.shevchenko@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=f.fainelli@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=nsaenzjulienne@suse.de \
    --cc=p.zabel@pengutronix.de \
    --cc=sboyd@kernel.org \
    --cc=wahrenst@gmx.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.