From: Radu Pirea <radu.pirea@microchip.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Mark Brown <broonie@kernel.org>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
<alexandre.belloni@bootlin.com>, Lee Jones <lee.jones@linaro.org>,
Richard Genoud <richard.genoud@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-spi <linux-spi@vger.kernel.org>,
linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
devicetree <devicetree@vger.kernel.org>,
"open list:SERIAL DRIVERS" <linux-serial@vger.kernel.org>
Subject: Re: [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi
Date: Tue, 29 May 2018 17:28:37 +0300 [thread overview]
Message-ID: <110bb353-b131-348c-8e26-9863b074142d@microchip.com> (raw)
In-Reply-To: <CAHp75Vc0e=+2YptoFAUuPSpAyxaCUJJqjQPPY5VZHV=MEMOqHQ@mail.gmail.com>
On 05/28/2018 11:21 AM, Andy Shevchenko wrote:
> On Fri, May 25, 2018 at 8:19 PM, Radu Pirea <radu.pirea@microchip.com> wrote:
>> This is the driver for at91-usart in spi mode. The USART IP can be configured
>> to work in many modes and one of them is SPI.
>>
>> The driver was tested on sama5d3-xplained and sama5d4-xplained boards with
>> enc28j60 ethernet controller as slave.
>
>> +#include <linux/of_gpio.h>
>
> What is the use of it?
I need of_gpio.h for of_gpio_named_count, of_get_named_gpio and
devm_gpio_request_one(found in gpio.h)
>
>> +#define US_INIT (US_MR_SPI_MASTER | US_MR_CHRL | US_MR_CLKO | \
>> + US_MR_WRDBT)
>
> Don't split lines like this, it's hard to read.
>
> #define FOO \
> (BAR1 | BAR2)
I'll fix it.
>
> I think I already told this to someone recently, maybe to you.
>
>> +/* Register access macros */
>> +#define spi_readl(port, reg) \
>> + readl_relaxed((port)->regs + US_##reg)
>> +#define spi_writel(port, reg, value) \
>> + writel_relaxed((value), (port)->regs + US_##reg)
>> +
>> +#define spi_readb(port, reg) \
>> + readb_relaxed((port)->regs + US_##reg)
>> +#define spi_writeb(port, reg, value) \
>> + writeb_relaxed((value), (port)->regs + US_##reg)
>
> Names are too generic. You better to use the same prefix as for the
> rest, i.e. at91_spi_
Good ideea. I will change the names.
>
>> + /*used in interrupt to protect data reading*/
>
> Comment style.
>
> You need to read some existing code, perhaps, to see how it's done.
Ok. I will add the comment.
>
>> +static inline void at91_usart_spi_tx(struct at91_usart_spi *aus)
>> +{
>> + unsigned int len = aus->current_transfer->len;
>> + unsigned int remaining = aus->current_tx_remaining_bytes;
>> + const u8 *tx_buf = aus->current_transfer->tx_buf;
>> +
>
>> + if (remaining)
>> + if (at91_usart_spi_tx_ready(aus)) {
>
> if (x) {
> if (y) {
> ...
> }
> }
>
> is equivalent to if (x && y) {}.
>
> Though, considering your intention here, I would rather go with better
> pattern, i.e.
>
> if (!remaining)
> return;
Thank for suggestion. I will change.
>
>> + spi_writeb(aus, THR, tx_buf[len - remaining]);
>> + aus->current_tx_remaining_bytes--;
>> + }
>> +}
>> +
>> +static inline void at91_usart_spi_rx(struct at91_usart_spi *aus)
>> +{
>
>> + if (remaining) {
>> + rx_buf[len - remaining] = spi_readb(aus, RHR);
>> + aus->current_rx_remaining_bytes--;
>> + }
>
> Ditto.
>
>> +}
>
>
>> +static int at91_usart_gpio_setup(struct platform_device *pdev)
>> +{
>
>> + struct device_node *np = pdev->dev.parent->of_node;
>
> Your driver is not OF specific as far as I can see. Drop all these
> device_node stuff and change API calls respectively.
Ok. What do you suggest to use instead of OF API to get the count of
cs-gpios and to read their values one by one?
>
>> + int i;
>
>> + int ret = 0;
>> + int nb = 0;
>
> What happened to indentation?
>
> Redundnant assignment for both.
>
>> + if (!np)
>> + return -EINVAL;
>> +
>> + nb = of_gpio_named_count(np, "cs-gpios");
>> + for (i = 0; i < nb; i++) {
>> + int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
>> +
>> + if (cs_gpio < 0)
>> + return cs_gpio;
>> +
>> + if (gpio_is_valid(cs_gpio)) {
>> + ret = devm_gpio_request_one(&pdev->dev, cs_gpio,
>> + GPIOF_DIR_OUT,
>> + dev_name(&pdev->dev));
>> + if (ret)
>> + return ret;
>> + }
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static int at91_usart_spi_probe(struct platform_device *pdev)
>> +{
>
>> + regs = platform_get_resource(to_platform_device(pdev->dev.parent),
>> + IORESOURCE_MEM, 0);
>> + if (!regs)
>> + return -EINVAL;
>
> This looks weird. Supply resource to _this_ device in your MFD code.
I know weird, but is the safest way to pass the resource and the of_node.
>
>> + dev_info(&pdev->dev,
>> + "Atmel USART SPI Controller version 0x%x at 0x%08lx (irq %d)\n",
>> + spi_readl(aus, VERSION),
>> + (unsigned long)regs->start, irq);
>
> I think I already told you, don't use explicit casting when print.
> If it wasn't you, do you homework then. But above is no go. >
>> + return 0;
>
>> +static struct platform_driver at91_usart_spi_driver = {
>> + .driver = {
>> + .name = "at91_usart_spi",
>
>> + .of_match_table = of_match_ptr(at91_usart_spi_dt_ids),
>
> Drop of_match_ptr(). It's not needed.
>
>> + },
>> + .probe = at91_usart_spi_probe,
>
>> + .remove = at91_usart_spi_remove, };
>
> Already told ya, split lines correctly.
>
next prev parent reply other threads:[~2018-05-29 14:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-25 17:19 [PATCH v4 0/6] Driver for at91 usart in spi mode Radu Pirea
2018-05-25 17:19 ` [PATCH v4 1/6] MAINTAINERS: add at91 usart mfd driver Radu Pirea
2018-05-25 17:19 ` [PATCH v4 2/6] dt-bindings: add binding for atmel-usart in SPI mode Radu Pirea
2018-05-31 1:00 ` Rob Herring
2018-06-13 6:11 ` Lee Jones
2018-05-25 17:19 ` [PATCH v4 3/6] mfd: at91-usart: added mfd driver for usart Radu Pirea
2018-05-28 8:00 ` Andy Shevchenko
2018-05-29 9:32 ` Alexandre Belloni
2018-05-31 1:02 ` Rob Herring
2018-05-25 17:19 ` [PATCH v4 4/6] MAINTAINERS: add at91 usart spi driver Radu Pirea
2018-05-25 17:19 ` [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi Radu Pirea
2018-05-28 8:21 ` Andy Shevchenko
2018-05-29 14:28 ` Radu Pirea [this message]
2018-05-29 14:34 ` Nicolas Ferre
2018-05-29 14:36 ` Nicolas Ferre
2018-05-25 17:19 ` [PATCH v4 6/6] tty/serial: atmel: changed the driver to work under at91-usart mfd Radu Pirea
2018-05-28 10:08 ` Richard Genoud
2018-05-29 9:15 ` Radu Pirea
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=110bb353-b131-348c-8e26-9863b074142d@microchip.com \
--to=radu.pirea@microchip.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andy.shevchenko@gmail.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=lee.jones@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=nicolas.ferre@microchip.com \
--cc=richard.genoud@gmail.com \
--cc=robh+dt@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