From: Mark Brown <broonie@kernel.org>
To: Bert Vermeulen <bert@biot.com>
Cc: ralf@linux-mips.org, linux-mips@linux-mips.org,
linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Subject: Re: [PATCH 1/2] spi: Add SPI driver for Mikrotik RB4xx series boards
Date: Fri, 20 Mar 2015 12:51:39 +0000 [thread overview]
Message-ID: <20150320125139.GJ2869@sirena.org.uk> (raw)
In-Reply-To: <1426853793-24454-2-git-send-email-bert@biot.com>
[-- Attachment #1: Type: text/plain, Size: 2847 bytes --]
On Fri, Mar 20, 2015 at 01:16:32PM +0100, Bert Vermeulen wrote:
> +#define DRV_NAME "rb4xx-spi"
> +#define DRV_DESC "Mikrotik RB4xx SPI controller driver"
Both of these are used exactly once, the defines aren't adding anything
except indirection.
> +#define DRV_VERSION "0.1.0"
The kernel is already versioned, don't include versions for individual
drivers - nobody is going to update it anyway.
> +static unsigned spi_clk_low = AR71XX_SPI_IOC_CS1;
No global variables, use driver data.
> +#ifdef RB4XX_SPI_DEBUG
> +static inline void do_spi_delay(void)
> +{
> + ndelay(20000);
> +}
> +#else
> +static inline void do_spi_delay(void) { }
> +#endif
Remove this, if it's useful implement it generically.
> +static inline void do_spi_init(struct spi_device *spi)
> +{
> + unsigned cs = AR71XX_SPI_IOC_CS0 | AR71XX_SPI_IOC_CS1;
> +
> + if (!(spi->mode & SPI_CS_HIGH))
> + cs ^= (spi->chip_select == 2) ? AR71XX_SPI_IOC_CS1 :
> + AR71XX_SPI_IOC_CS0;
Please write this expression in a more legible fashion, I can't really
tell what it's supposed to do.
> +static void do_spi_byte(void __iomem *base, unsigned char byte)
> +{
> + do_spi_clk(base, byte >> 7);
> + do_spi_clk(base, byte >> 6);
> + do_spi_clk(base, byte >> 5);
> + do_spi_clk(base, byte >> 4);
> + do_spi_clk(base, byte >> 3);
> + do_spi_clk(base, byte >> 2);
> + do_spi_clk(base, byte >> 1);
> + do_spi_clk(base, byte);
This looks awfully like it's bitbanging the value out, can we not use
spi-bitbang here?
> + pr_debug("spi_byte sent 0x%02x got 0x%02x\n",
> + (unsigned)byte,
> + (unsigned char)__raw_readl(base + AR71XX_SPI_REG_RDS));
dev_dbg().
> +static inline void do_spi_clk_fast(void __iomem *base, unsigned bit1,
> + unsigned bit2)
Why would we ever want the slow version?
> +static int rb4xx_spi_msg(struct rb4xx_spi *rbspi, struct spi_message *m)
> +{
> + struct spi_transfer *t = NULL;
> + void __iomem *base = rbspi->base;
> +
> + m->status = 0;
> + if (list_empty(&m->transfers))
> + return -1;
> +
> + __raw_writel(AR71XX_SPI_FS_GPIO, base + AR71XX_SPI_REG_FS);
> + __raw_writel(SPI_CTRL_FASTEST, base + AR71XX_SPI_REG_CTRL);
> + do_spi_init(m->spi);
> +
> + list_for_each_entry(t, &m->transfers, transfer_list) {
> + int len;
This is reimplementing the core message queue code, provide a
transfer_one() operation if there's some reason not to use bitbang.
> +static void rb4xx_spi_process_queue_locked(struct rb4xx_spi *rbspi,
> + unsigned long *flags)
Similarly all the queue code is reimplementing core functionality.
> +static int __init rb4xx_spi_init(void)
> +{
> + return platform_driver_register(&rb4xx_spi_drv);
> +}
> +subsys_initcall(rb4xx_spi_init);
> +
> +static void __exit rb4xx_spi_exit(void)
> +{
> + platform_driver_unregister(&rb4xx_spi_drv);
> +}
> +
> +module_exit(rb4xx_spi_exit);
module_platform_driver()
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-03-20 12:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 12:16 [PATCH 0/2] spi: Add driver for Routerboard RB4xx boards Bert Vermeulen
2015-03-20 12:16 ` [PATCH 1/2] spi: Add SPI driver for Mikrotik RB4xx series boards Bert Vermeulen
2015-03-20 12:51 ` Mark Brown [this message]
2015-03-22 11:25 ` Bert Vermeulen
2015-03-22 16:17 ` Mark Brown
2015-03-20 12:56 ` Mark Brown
2015-03-25 21:40 ` Andy Shevchenko
2015-03-20 12:16 ` [PATCH 2/2] spi: Add driver for the CPLD chip on Mikrotik RB4xx boards Bert Vermeulen
2015-03-20 13:28 ` Mark Brown
2015-03-25 21:45 ` Andy Shevchenko
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=20150320125139.GJ2869@sirena.org.uk \
--to=broonie@kernel.org \
--cc=bert@biot.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-spi@vger.kernel.org \
--cc=ralf@linux-mips.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
all inboxes | Powered by JetHome®