From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 19/20] spi: atmel_spi: Use VERSION register instead of CPU type
Date: Wed, 8 Mar 2017 14:09:08 -0800 [thread overview]
Message-ID: <20170308220909.4560-20-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20170308220909.4560-1-andrew.smirnov@gmail.com>
Use VERSION register instead of CPU type to determine IP block's version
and capabilities. This what corresponding Linux kernel driver does.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
drivers/spi/atmel_spi.c | 35 +++++++++++++++++++++++++++++------
drivers/spi/atmel_spi.h | 1 +
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 67028e6..ef57867 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -40,11 +40,16 @@
#include "atmel_spi.h"
+struct atmel_spi_caps {
+ bool is_spi2;
+};
+
struct atmel_spi {
struct spi_master master;
void __iomem *regs;
struct clk *clk;
int *cs_pins;
+ struct atmel_spi_caps caps;
};
#define to_atmel_spi(p) container_of(p, struct atmel_spi, master)
@@ -62,9 +67,9 @@ struct atmel_spi {
* register, but I haven't checked that it exists on all chips, and
* this is cheaper anyway.
*/
-static inline bool atmel_spi_is_v2(void)
+static inline bool atmel_spi_is_v2(struct atmel_spi *as)
{
- return !cpu_is_at91rm9200();
+ return as->caps.is_spi2;
}
/*
@@ -104,7 +109,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
csr = (u32)spi->controller_data;
- if (atmel_spi_is_v2()) {
+ if (atmel_spi_is_v2(as)) {
/*
* Always use CSR0. This ensures that the clock
* switches to the correct idle polarity before we
@@ -163,8 +168,9 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
npcs_pin, active ? " (low)" : "",
mr);
- if (atmel_spi_is_v2() || npcs_pin != AT91_PIN_PA3)
+ if (atmel_spi_is_v2(as) || npcs_pin != AT91_PIN_PA3) {
gpio_set_value(npcs_pin, !active);
+ }
}
static int atmel_spi_setup(struct spi_device *spi)
@@ -199,7 +205,7 @@ static int atmel_spi_setup(struct spi_device *spi)
spi->max_speed_hz);
bus_hz = clk_get_rate(as->clk);
- if (!atmel_spi_is_v2())
+ if (!atmel_spi_is_v2(as))
bus_hz /= 2;
if (spi->max_speed_hz) {
@@ -248,7 +254,7 @@ static int atmel_spi_setup(struct spi_device *spi)
cs_deactivate(as, spi);
- if (!atmel_spi_is_v2())
+ if (!atmel_spi_is_v2(as))
spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
return 0;
@@ -373,6 +379,21 @@ err:
return ret;
}
+static inline unsigned int atmel_get_version(struct atmel_spi *as)
+{
+ return spi_readl(as, VERSION) & 0x00000fff;
+}
+
+static void atmel_get_caps(struct atmel_spi *as)
+{
+ unsigned int version;
+
+ version = atmel_get_version(as);
+ dev_info(as->master.dev, "version: 0x%x\n", version);
+
+ as->caps.is_spi2 = version > 0x121;
+}
+
static int atmel_spi_probe(struct device_d *dev)
{
struct resource *iores;
@@ -409,6 +430,8 @@ static int atmel_spi_probe(struct device_d *dev)
return PTR_ERR(iores);
as->regs = IOMEM(iores->start);
+ atmel_get_caps(as);
+
for (i = 0; i < master->num_chipselect; i++) {
ret = gpio_request(as->cs_pins[i], dev_name(dev));
if (ret)
diff --git a/drivers/spi/atmel_spi.h b/drivers/spi/atmel_spi.h
index 38ce119..3f4d7ba 100644
--- a/drivers/spi/atmel_spi.h
+++ b/drivers/spi/atmel_spi.h
@@ -23,6 +23,7 @@
#define SPI_CSR1 0x0034
#define SPI_CSR2 0x0038
#define SPI_CSR3 0x003c
+#define SPI_VERSION 0x00fc
#define SPI_RPR 0x0100
#define SPI_RCR 0x0104
#define SPI_TPR 0x0108
--
2.9.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-03-08 22:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 22:08 [PATCH 00/20] AT91, at91sam9x5ek updates (part I/III) Andrey Smirnov
2017-03-08 22:08 ` [PATCH 01/20] at91: Fix bug/typo in debug_ll.h Andrey Smirnov
2017-03-08 22:08 ` [PATCH 02/20] regmap: Implement syscon_node_to_regmap() Andrey Smirnov
2017-03-08 22:08 ` [PATCH 03/20] pinctrl: at91: Fix a bug in at91_pinctrl_set_conf() Andrey Smirnov
2017-03-08 22:08 ` [PATCH 04/20] pinctrl: at91: Fix a bug in at91_pinctrl_set_state() Andrey Smirnov
2017-03-08 22:08 ` [PATCH 05/20] pinctrl: at91: Implement .get_direction hook Andrey Smirnov
2017-03-08 22:08 ` [PATCH 06/20] clk: Port two helper functions from Linux Andrey Smirnov
2017-03-08 22:08 ` [PATCH 07/20] clk: Make COMMON_CLK_OF_PROVIDER depend on OFTREE Andrey Smirnov
2017-03-08 22:08 ` [PATCH 08/20] clk: No-op CLK_OF_DECLARE if not enabled Andrey Smirnov
2017-03-09 10:54 ` Sascha Hauer
2017-03-08 22:08 ` [PATCH 09/20] of: base: Use scoring in DT device matching Andrey Smirnov
2017-03-08 22:08 ` [PATCH 10/20] serial: atmel: Check result of clk_get() Andrey Smirnov
2017-03-08 22:09 ` [PATCH 11/20] usb: ohci-at91: " Andrey Smirnov
2017-03-08 22:09 ` [PATCH 12/20] usb: ohci-at91: Convert global variables to private data Andrey Smirnov
2017-03-08 22:09 ` [PATCH 13/20] usb: ohci-at91: Check result of clk_enable() Andrey Smirnov
2017-03-08 22:09 ` [PATCH 14/20] usb: ehci-atmel: " Andrey Smirnov
2017-03-08 22:09 ` [PATCH 15/20] usb: echi-atmel: Convert global variables to private data Andrey Smirnov
2017-03-08 22:09 ` [PATCH 16/20] usb: ehci-atmel: Zero ehci_data before using it Andrey Smirnov
2017-03-08 22:09 ` [PATCH 17/20] usb: echi-atmel: Check result of ehci_register() Andrey Smirnov
2017-03-08 22:09 ` [PATCH 18/20] spi: atmel_spi: Configure CS GPIO as output Andrey Smirnov
2017-03-08 22:09 ` Andrey Smirnov [this message]
2017-03-08 22:09 ` [PATCH 20/20] clocksource: at91: Move to 'drivers/clocksource' Andrey Smirnov
2017-03-09 7:19 ` [PATCH 00/20] AT91, at91sam9x5ek updates (part I/III) Sascha Hauer
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=20170308220909.4560-20-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.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