All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Genoud <richard.genoud@gmail.com>
To: Claudiu.Beznea@microchip.com, gregkh@linuxfoundation.org,
	jirislaby@kernel.org, Nicolas.Ferre@microchip.com,
	alexandre.belloni@bootlin.com, patrice.chotard@foss.st.com
Cc: linux-serial@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] tty: serial: atmel: improve clock management
Date: Fri, 10 Jun 2022 15:43:15 +0200	[thread overview]
Message-ID: <a46eec81-aa2c-74c0-210d-4d28ba46e815@gmail.com> (raw)
In-Reply-To: <4a189186-9871-09ab-d7e1-9346f7af0bfe@microchip.com>

Hi,
Le 08/06/2022 à 10:18, Claudiu.Beznea@microchip.com a écrit :
> Hi,
> 
> On 02.06.2022 12:29, Richard Genoud wrote:
>>
>> Hi,
>>
>> Le 25/05/2022 à 15:37, Claudiu Beznea a écrit :
>>> atmel_port->clk was requested in atmel_init_port() (which is called only
>>> on probe path) only if atmel_port->clk was NULL. But atmel_port->clk is
>>> NULL on probing path. Thus don't check this. Along with this the clock is
>>> now requested with devm_clk_get() and the clock request has been moved in
>>> atmel_serial_probe() function to avoid disabling/re-enabling it on probe
>>> path for multiple times. All the checks of atmel_port->clk were removed
>>> along with clk_put() and atmel_port->clk = NULL. Now, on probing time the
>>> clock is enabled at the beginning and disabled at the end of probe. As
>>> atmel_console_setup() is called in the middle of probe and clock is
>>> already enabled at that time the clk_prepare_enable() in
>>> atmel_console_setup() has also been removed.
>> Could you split this patch into smaller steps ?
>> I think it will be easier to read and review.
> 
> I kept it as a single patch as it is all related to clock management.
> 
> Having the clock enabled only at the beginning of probe and disabled at the
> end of probe lead to removing the code in atmel_init_port(), also removing
> the code under CONFIG_SERIAL_ATMEL_CONSOLE in probe. Same for the rest of
> the removed code.
> 
> With this, would you still want to split it in multiple patches?

I think that, at least, the switch from clk_get() to devm_clk_get() can 
be in a separate patch.
But in general, I prefer when patches are self-explaining rather than a 
bigger patch with a longer explanation of what it does in the commit 
message.

Regards,
Richard

> 
> Thank you,
> Claudiu Beznea
>>>
>>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>>> ---
>>>    drivers/tty/serial/atmel_serial.c | 65 +++++++------------------------
>>>    1 file changed, 15 insertions(+), 50 deletions(-)
>>>
>>> diff --git a/drivers/tty/serial/atmel_serial.c
>>> b/drivers/tty/serial/atmel_serial.c
>>> index 5c793a23dc54..2955b1012014 100644
>>> --- a/drivers/tty/serial/atmel_serial.c
>>> +++ b/drivers/tty/serial/atmel_serial.c
>>> @@ -2501,24 +2501,7 @@ static int atmel_init_port(struct atmel_uart_port
>>> *atmel_port,
>>>        if (ret)
>>>                return ret;
>>>
>>> -     /* for console, the clock could already be configured */
>>> -     if (!atmel_port->clk) {
>>> -             atmel_port->clk = clk_get(&mpdev->dev, "usart");
>>> -             if (IS_ERR(atmel_port->clk)) {
>>> -                     ret = PTR_ERR(atmel_port->clk);
>>> -                     atmel_port->clk = NULL;
>>> -                     return ret;
>>> -             }
>>> -             ret = clk_prepare_enable(atmel_port->clk);
>>> -             if (ret) {
>>> -                     clk_put(atmel_port->clk);
>>> -                     atmel_port->clk = NULL;
>>> -                     return ret;
>>> -             }
>>> -             port->uartclk = clk_get_rate(atmel_port->clk);
>>> -             clk_disable_unprepare(atmel_port->clk);
>>> -             /* only enable clock when USART is in use */
>>> -     }
>>> +     port->uartclk = clk_get_rate(atmel_port->clk);
>>>
>>>        /*
>>>         * Use TXEMPTY for interrupt when rs485 or ISO7816 else TXRDY or
>>> @@ -2640,10 +2623,6 @@ static int __init atmel_console_setup(struct
>>> console *co, char *options)
>>>                return -ENODEV;
>>>        }
>>>
>>> -     ret = clk_prepare_enable(atmel_ports[co->index].clk);
>>> -     if (ret)
>>> -             return ret;
>>> -
>> Now, "int ret;" is unused, you can remove it.
>>
>>>        atmel_uart_writel(port, ATMEL_US_IDR, -1);
>>>        atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA |
>>> ATMEL_US_RSTRX);
>>>        atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN);
>>> @@ -2889,14 +2868,23 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>        atomic_set(&atmel_port->tasklet_shutdown, 0);
>>>        spin_lock_init(&atmel_port->lock_suspended);
>>>
>>> +     atmel_port->clk = devm_clk_get(&pdev->dev, "usart");
>>> +     if (IS_ERR(atmel_port->clk)) {
>>> +             ret = PTR_ERR(atmel_port->clk);
>>> +             goto err;
>>> +     }
>>> +     ret = clk_prepare_enable(atmel_port->clk);
>>> +     if (ret)
>>> +             goto err;
>>> +
>>>        ret = atmel_init_port(atmel_port, pdev);
>>>        if (ret)
>>> -             goto err_clear_bit;
>>> +             goto err_clk_disable_unprepare;
>>>
>>>        atmel_port->gpios = mctrl_gpio_init(&atmel_port->uart, 0);
>>>        if (IS_ERR(atmel_port->gpios)) {
>>>                ret = PTR_ERR(atmel_port->gpios);
>>> -             goto err_clear_bit;
>>> +             goto err_clk_disable_unprepare;
>>>        }
>>>
>>>        if (!atmel_use_pdc_rx(&atmel_port->uart)) {
>>> @@ -2905,7 +2893,7 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>                                     sizeof(struct atmel_uart_char),
>>>                                     GFP_KERNEL);
>>>                if (!data)
>>> -                     goto err_alloc_ring;
>>> +                     goto err_clk_disable_unprepare;
>>>                atmel_port->rx_ring.buf = data;
>>>        }
>>>
>>> @@ -2915,26 +2903,9 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>        if (ret)
>>>                goto err_add_port;
>>>
>>> -#ifdef CONFIG_SERIAL_ATMEL_CONSOLE
>>> -     if (uart_console(&atmel_port->uart)
>>> -                     && ATMEL_CONSOLE_DEVICE->flags & CON_ENABLED) {
>>> -             /*
>>> -              * The serial core enabled the clock for us, so undo
>>> -              * the clk_prepare_enable() in atmel_console_setup()
>>> -              */
>>> -             clk_disable_unprepare(atmel_port->clk);
>>> -     }
>>> -#endif
>>> -
>>>        device_init_wakeup(&pdev->dev, 1);
>>>        platform_set_drvdata(pdev, atmel_port);
>>>
>>> -     /*
>>> -      * The peripheral clock has been disabled by atmel_init_port():
>>> -      * enable it before accessing I/O registers
>>> -      */
>>> -     clk_prepare_enable(atmel_port->clk);
>>> -
>>>        if (rs485_enabled) {
>>>                atmel_uart_writel(&atmel_port->uart, ATMEL_US_MR,
>>>                                  ATMEL_US_USMODE_NORMAL);
>>> @@ -2958,12 +2929,8 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>    err_add_port:
>>>        kfree(atmel_port->rx_ring.buf);
>>>        atmel_port->rx_ring.buf = NULL;
>>> -err_alloc_ring:
>>> -     if (!uart_console(&atmel_port->uart)) {
>>> -             clk_put(atmel_port->clk);
>>> -             atmel_port->clk = NULL;
>>> -     }
>>> -err_clear_bit:
>>> +err_clk_disable_unprepare:
>>> +     clk_disable_unprepare(atmel_port->clk);
>>>        clear_bit(atmel_port->uart.line, atmel_ports_in_use);
>>>    err:
>>>        return ret;
>>> @@ -2997,8 +2964,6 @@ static int atmel_serial_remove(struct
>>> platform_device *pdev)
>>>
>>>        clear_bit(port->line, atmel_ports_in_use);
>>>
>>> -     clk_put(atmel_port->clk);
>>> -     atmel_port->clk = NULL;
>>>        pdev->dev.of_node = NULL;
>>>
>>>        return ret;
>> Thanks !
>>
>> Regards,
>> Richard
> 

WARNING: multiple messages have this Message-ID (diff)
From: Richard Genoud <richard.genoud@gmail.com>
To: Claudiu.Beznea@microchip.com, gregkh@linuxfoundation.org,
	jirislaby@kernel.org, Nicolas.Ferre@microchip.com,
	alexandre.belloni@bootlin.com, patrice.chotard@foss.st.com
Cc: linux-serial@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] tty: serial: atmel: improve clock management
Date: Fri, 10 Jun 2022 15:43:15 +0200	[thread overview]
Message-ID: <a46eec81-aa2c-74c0-210d-4d28ba46e815@gmail.com> (raw)
In-Reply-To: <4a189186-9871-09ab-d7e1-9346f7af0bfe@microchip.com>

Hi,
Le 08/06/2022 à 10:18, Claudiu.Beznea@microchip.com a écrit :
> Hi,
> 
> On 02.06.2022 12:29, Richard Genoud wrote:
>>
>> Hi,
>>
>> Le 25/05/2022 à 15:37, Claudiu Beznea a écrit :
>>> atmel_port->clk was requested in atmel_init_port() (which is called only
>>> on probe path) only if atmel_port->clk was NULL. But atmel_port->clk is
>>> NULL on probing path. Thus don't check this. Along with this the clock is
>>> now requested with devm_clk_get() and the clock request has been moved in
>>> atmel_serial_probe() function to avoid disabling/re-enabling it on probe
>>> path for multiple times. All the checks of atmel_port->clk were removed
>>> along with clk_put() and atmel_port->clk = NULL. Now, on probing time the
>>> clock is enabled at the beginning and disabled at the end of probe. As
>>> atmel_console_setup() is called in the middle of probe and clock is
>>> already enabled at that time the clk_prepare_enable() in
>>> atmel_console_setup() has also been removed.
>> Could you split this patch into smaller steps ?
>> I think it will be easier to read and review.
> 
> I kept it as a single patch as it is all related to clock management.
> 
> Having the clock enabled only at the beginning of probe and disabled at the
> end of probe lead to removing the code in atmel_init_port(), also removing
> the code under CONFIG_SERIAL_ATMEL_CONSOLE in probe. Same for the rest of
> the removed code.
> 
> With this, would you still want to split it in multiple patches?

I think that, at least, the switch from clk_get() to devm_clk_get() can 
be in a separate patch.
But in general, I prefer when patches are self-explaining rather than a 
bigger patch with a longer explanation of what it does in the commit 
message.

Regards,
Richard

> 
> Thank you,
> Claudiu Beznea
>>>
>>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>>> ---
>>>    drivers/tty/serial/atmel_serial.c | 65 +++++++------------------------
>>>    1 file changed, 15 insertions(+), 50 deletions(-)
>>>
>>> diff --git a/drivers/tty/serial/atmel_serial.c
>>> b/drivers/tty/serial/atmel_serial.c
>>> index 5c793a23dc54..2955b1012014 100644
>>> --- a/drivers/tty/serial/atmel_serial.c
>>> +++ b/drivers/tty/serial/atmel_serial.c
>>> @@ -2501,24 +2501,7 @@ static int atmel_init_port(struct atmel_uart_port
>>> *atmel_port,
>>>        if (ret)
>>>                return ret;
>>>
>>> -     /* for console, the clock could already be configured */
>>> -     if (!atmel_port->clk) {
>>> -             atmel_port->clk = clk_get(&mpdev->dev, "usart");
>>> -             if (IS_ERR(atmel_port->clk)) {
>>> -                     ret = PTR_ERR(atmel_port->clk);
>>> -                     atmel_port->clk = NULL;
>>> -                     return ret;
>>> -             }
>>> -             ret = clk_prepare_enable(atmel_port->clk);
>>> -             if (ret) {
>>> -                     clk_put(atmel_port->clk);
>>> -                     atmel_port->clk = NULL;
>>> -                     return ret;
>>> -             }
>>> -             port->uartclk = clk_get_rate(atmel_port->clk);
>>> -             clk_disable_unprepare(atmel_port->clk);
>>> -             /* only enable clock when USART is in use */
>>> -     }
>>> +     port->uartclk = clk_get_rate(atmel_port->clk);
>>>
>>>        /*
>>>         * Use TXEMPTY for interrupt when rs485 or ISO7816 else TXRDY or
>>> @@ -2640,10 +2623,6 @@ static int __init atmel_console_setup(struct
>>> console *co, char *options)
>>>                return -ENODEV;
>>>        }
>>>
>>> -     ret = clk_prepare_enable(atmel_ports[co->index].clk);
>>> -     if (ret)
>>> -             return ret;
>>> -
>> Now, "int ret;" is unused, you can remove it.
>>
>>>        atmel_uart_writel(port, ATMEL_US_IDR, -1);
>>>        atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_RSTSTA |
>>> ATMEL_US_RSTRX);
>>>        atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN | ATMEL_US_RXEN);
>>> @@ -2889,14 +2868,23 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>        atomic_set(&atmel_port->tasklet_shutdown, 0);
>>>        spin_lock_init(&atmel_port->lock_suspended);
>>>
>>> +     atmel_port->clk = devm_clk_get(&pdev->dev, "usart");
>>> +     if (IS_ERR(atmel_port->clk)) {
>>> +             ret = PTR_ERR(atmel_port->clk);
>>> +             goto err;
>>> +     }
>>> +     ret = clk_prepare_enable(atmel_port->clk);
>>> +     if (ret)
>>> +             goto err;
>>> +
>>>        ret = atmel_init_port(atmel_port, pdev);
>>>        if (ret)
>>> -             goto err_clear_bit;
>>> +             goto err_clk_disable_unprepare;
>>>
>>>        atmel_port->gpios = mctrl_gpio_init(&atmel_port->uart, 0);
>>>        if (IS_ERR(atmel_port->gpios)) {
>>>                ret = PTR_ERR(atmel_port->gpios);
>>> -             goto err_clear_bit;
>>> +             goto err_clk_disable_unprepare;
>>>        }
>>>
>>>        if (!atmel_use_pdc_rx(&atmel_port->uart)) {
>>> @@ -2905,7 +2893,7 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>                                     sizeof(struct atmel_uart_char),
>>>                                     GFP_KERNEL);
>>>                if (!data)
>>> -                     goto err_alloc_ring;
>>> +                     goto err_clk_disable_unprepare;
>>>                atmel_port->rx_ring.buf = data;
>>>        }
>>>
>>> @@ -2915,26 +2903,9 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>        if (ret)
>>>                goto err_add_port;
>>>
>>> -#ifdef CONFIG_SERIAL_ATMEL_CONSOLE
>>> -     if (uart_console(&atmel_port->uart)
>>> -                     && ATMEL_CONSOLE_DEVICE->flags & CON_ENABLED) {
>>> -             /*
>>> -              * The serial core enabled the clock for us, so undo
>>> -              * the clk_prepare_enable() in atmel_console_setup()
>>> -              */
>>> -             clk_disable_unprepare(atmel_port->clk);
>>> -     }
>>> -#endif
>>> -
>>>        device_init_wakeup(&pdev->dev, 1);
>>>        platform_set_drvdata(pdev, atmel_port);
>>>
>>> -     /*
>>> -      * The peripheral clock has been disabled by atmel_init_port():
>>> -      * enable it before accessing I/O registers
>>> -      */
>>> -     clk_prepare_enable(atmel_port->clk);
>>> -
>>>        if (rs485_enabled) {
>>>                atmel_uart_writel(&atmel_port->uart, ATMEL_US_MR,
>>>                                  ATMEL_US_USMODE_NORMAL);
>>> @@ -2958,12 +2929,8 @@ static int atmel_serial_probe(struct
>>> platform_device *pdev)
>>>    err_add_port:
>>>        kfree(atmel_port->rx_ring.buf);
>>>        atmel_port->rx_ring.buf = NULL;
>>> -err_alloc_ring:
>>> -     if (!uart_console(&atmel_port->uart)) {
>>> -             clk_put(atmel_port->clk);
>>> -             atmel_port->clk = NULL;
>>> -     }
>>> -err_clear_bit:
>>> +err_clk_disable_unprepare:
>>> +     clk_disable_unprepare(atmel_port->clk);
>>>        clear_bit(atmel_port->uart.line, atmel_ports_in_use);
>>>    err:
>>>        return ret;
>>> @@ -2997,8 +2964,6 @@ static int atmel_serial_remove(struct
>>> platform_device *pdev)
>>>
>>>        clear_bit(port->line, atmel_ports_in_use);
>>>
>>> -     clk_put(atmel_port->clk);
>>> -     atmel_port->clk = NULL;
>>>        pdev->dev.of_node = NULL;
>>>
>>>        return ret;
>> Thanks !
>>
>> Regards,
>> Richard
> 

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

  reply	other threads:[~2022-06-10 13:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25 13:37 [PATCH 0/3] serial: atmel: cleanup code Claudiu Beznea
2022-05-25 13:37 ` Claudiu Beznea
2022-05-25 13:37 ` [PATCH 1/3] tty: serial: atmel: stop using legacy pm ops Claudiu Beznea
2022-05-25 13:37   ` Claudiu Beznea
2022-06-02  9:14   ` Richard Genoud
2022-06-02  9:14     ` Richard Genoud
2022-05-25 13:37 ` [PATCH 2/3] tty: serial: atmel: improve clock management Claudiu Beznea
2022-05-25 13:37   ` Claudiu Beznea
2022-06-02  9:29   ` Richard Genoud
2022-06-02  9:29     ` Richard Genoud
2022-06-08  8:18     ` Claudiu.Beznea
2022-06-08  8:18       ` Claudiu.Beznea
2022-06-10 13:43       ` Richard Genoud [this message]
2022-06-10 13:43         ` Richard Genoud
2022-05-25 13:37 ` [PATCH 3/3] serial: st-asc: remove include of pm_runtime.h Claudiu Beznea
2022-05-25 13:37   ` Claudiu Beznea
2022-05-30  7:47   ` Patrice CHOTARD
2022-05-30  7:47     ` Patrice CHOTARD

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=a46eec81-aa2c-74c0-210d-4d28ba46e815@gmail.com \
    --to=richard.genoud@gmail.com \
    --cc=Claudiu.Beznea@microchip.com \
    --cc=Nicolas.Ferre@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=patrice.chotard@foss.st.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 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.