linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] spi: davinci: Improve prescaler limit support
@ 2015-07-14 19:45 Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 1/4] spi: davinci: Set prescale value based on register value Franklin S Cooper Jr
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Franklin S Cooper Jr @ 2015-07-14 19:45 UTC (permalink / raw)
  To: linux-spi
  Cc: linux-arm-kernel, linux-kernel, devicetree, Franklin S Cooper Jr

Currently the prescale limit is treated as a one size fits all value even
though their are differences depending on the SOC. This patchset insures
that the proper prescale limit is used for each platform/SOC.

Franklin S Cooper Jr (4):
  spi: davinci: Set prescale value based on register value
  spi: davinci: Choose correct pre-scaler limit based on SOC
  ARM: davinci: Set proper SPI prescale limit value
  ARM: dts: keystone: Add ti,keystone-spi for SPI

 .../devicetree/bindings/spi/spi-davinci.txt        |  2 +
 arch/arm/boot/dts/keystone.dtsi                    |  6 +--
 arch/arm/mach-davinci/devices-da8xx.c              |  2 +
 arch/arm/mach-davinci/dm355.c                      |  1 +
 arch/arm/mach-davinci/dm365.c                      |  1 +
 drivers/spi/spi-davinci.c                          | 50 +++++++++++++++++-----
 include/linux/platform_data/spi-davinci.h          |  1 +
 7 files changed, 50 insertions(+), 13 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] spi: davinci: Set prescale value based on register value
  2015-07-14 19:45 [PATCH 0/4] spi: davinci: Improve prescaler limit support Franklin S Cooper Jr
@ 2015-07-14 19:45 ` Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 2/4] spi: davinci: Choose correct pre-scaler limit based on SOC Franklin S Cooper Jr
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Franklin S Cooper Jr @ 2015-07-14 19:45 UTC (permalink / raw)
  To: linux-spi
  Cc: linux-arm-kernel, linux-kernel, devicetree, Franklin S Cooper Jr

Within davinci_spi_get_prescale() the prescale has two meanings. First one
being the calculated prescale value and then at the end translates it to the
prescale value that will be written to the SPI register.

At first glance this can be confusing especially when comparing the minimum
prescale value against what is seen in the TRM.

To simplify things make it clear that the calculated prescale value will always
be based on the value that will be written into the SPI register.

Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
---
 drivers/spi/spi-davinci.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index 987afeb..b4605c4 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -255,7 +255,7 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value)
  * This function calculates the prescale value that generates a clock rate
  * less than or equal to the specified maximum.
  *
- * Returns: calculated prescale - 1 for easy programming into SPI registers
+ * Returns: calculated prescale value for easy programming into SPI registers
  * or negative error number if valid prescalar cannot be updated.
  */
 static inline int davinci_spi_get_prescale(struct davinci_spi *dspi,
@@ -263,12 +263,13 @@ static inline int davinci_spi_get_prescale(struct davinci_spi *dspi,
 {
 	int ret;
 
-	ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz);
+	/* Subtract 1 to match what will be programmed into SPI register. */
+	ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz) - 1;
 
-	if (ret < 1 || ret > 256)
+	if (ret < 0 || ret > 255)
 		return -EINVAL;
 
-	return ret - 1;
+	return ret;
 }
 
 /**
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] spi: davinci: Choose correct pre-scaler limit based on SOC
  2015-07-14 19:45 [PATCH 0/4] spi: davinci: Improve prescaler limit support Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 1/4] spi: davinci: Set prescale value based on register value Franklin S Cooper Jr
@ 2015-07-14 19:45 ` Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI Franklin S Cooper Jr
  3 siblings, 0 replies; 5+ messages in thread
From: Franklin S Cooper Jr @ 2015-07-14 19:45 UTC (permalink / raw)
  To: linux-spi
  Cc: linux-arm-kernel, linux-kernel, devicetree, Franklin S Cooper Jr

Currently the pre-scaler limit is incorrect. The value differs slightly
for various devices so a single value can't be used. Using the compatible
field select the correct pre-scaler limit.

Add new compatible field value for Keystone devices to support their
unique pre-scaler limit value.

Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
---
 .../devicetree/bindings/spi/spi-davinci.txt        |  2 +
 drivers/spi/spi-davinci.c                          | 43 ++++++++++++++++++----
 include/linux/platform_data/spi-davinci.h          |  1 +
 3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/Documentation/devicetree/bindings/spi/spi-davinci.txt b/Documentation/devicetree/bindings/spi/spi-davinci.txt
index 12ecfe9..d1e914a 100644
--- a/Documentation/devicetree/bindings/spi/spi-davinci.txt
+++ b/Documentation/devicetree/bindings/spi/spi-davinci.txt
@@ -12,6 +12,8 @@ Required properties:
 - compatible:
 	- "ti,dm6441-spi" for SPI used similar to that on DM644x SoC family
 	- "ti,da830-spi" for SPI used similar to that on DA8xx SoC family
+	- "ti,keystone-spi" for SPI used similar to that on Keystone2 SoC
+		family
 - reg: Offset and length of SPI controller register space
 - num-cs: Number of chip selects. This includes internal as well as
 	GPIO chip selects.
diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
index b4605c4..3cf9faa 100644
--- a/drivers/spi/spi-davinci.c
+++ b/drivers/spi/spi-davinci.c
@@ -139,6 +139,8 @@ struct davinci_spi {
 	u32			(*get_tx)(struct davinci_spi *);
 
 	u8			*bytes_per_word;
+
+	u8			prescaler_limit;
 };
 
 static struct davinci_spi_config davinci_spi_default_cfg;
@@ -266,7 +268,7 @@ static inline int davinci_spi_get_prescale(struct davinci_spi *dspi,
 	/* Subtract 1 to match what will be programmed into SPI register. */
 	ret = DIV_ROUND_UP(clk_get_rate(dspi->clk), max_speed_hz) - 1;
 
-	if (ret < 0 || ret > 255)
+	if (ret < dspi->prescaler_limit || ret > 255)
 		return -EINVAL;
 
 	return ret;
@@ -833,13 +835,40 @@ rx_dma_failed:
 }
 
 #if defined(CONFIG_OF)
+
+/* OF SPI data structure */
+struct davinci_spi_of_data {
+	u8	version;
+	u8	prescaler_limit;
+};
+
+static const struct davinci_spi_of_data dm6441_spi_data = {
+	.version = SPI_VERSION_1,
+	.prescaler_limit = 2,
+};
+
+static const struct davinci_spi_of_data da830_spi_data = {
+	.version = SPI_VERSION_2,
+	.prescaler_limit = 2,
+};
+
+static const struct davinci_spi_of_data keystone_spi_data = {
+	.version = SPI_VERSION_1,
+	.prescaler_limit = 0,
+};
+
 static const struct of_device_id davinci_spi_of_match[] = {
 	{
 		.compatible = "ti,dm6441-spi",
+		.data = &dm6441_spi_data,
 	},
 	{
 		.compatible = "ti,da830-spi",
-		.data = (void *)SPI_VERSION_2,
+		.data = &da830_spi_data,
+	},
+	{
+		.compatible = "ti,keystone-spi",
+		.data = &keystone_spi_data,
 	},
 	{ },
 };
@@ -858,21 +887,21 @@ static int spi_davinci_get_pdata(struct platform_device *pdev,
 			struct davinci_spi *dspi)
 {
 	struct device_node *node = pdev->dev.of_node;
+	struct davinci_spi_of_data *spi_data;
 	struct davinci_spi_platform_data *pdata;
 	unsigned int num_cs, intr_line = 0;
 	const struct of_device_id *match;
 
 	pdata = &dspi->pdata;
 
-	pdata->version = SPI_VERSION_1;
 	match = of_match_device(davinci_spi_of_match, &pdev->dev);
 	if (!match)
 		return -ENODEV;
 
-	/* match data has the SPI version number for SPI_VERSION_2 */
-	if (match->data == (void *)SPI_VERSION_2)
-		pdata->version = SPI_VERSION_2;
+	spi_data = (struct davinci_spi_of_data *)match->data;
 
+	pdata->version = spi_data->version;
+	pdata->prescaler_limit = spi_data->prescaler_limit;
 	/*
 	 * default num_cs is 1 and all chipsel are internal to the chip
 	 * indicated by chip_sel being NULL or cs_gpios being NULL or
@@ -992,7 +1021,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
 
 	dspi->bitbang.chipselect = davinci_spi_chipselect;
 	dspi->bitbang.setup_transfer = davinci_spi_setup_transfer;
-
+	dspi->prescaler_limit = pdata->prescaler_limit;
 	dspi->version = pdata->version;
 
 	dspi->bitbang.flags = SPI_NO_CS | SPI_LSB_FIRST | SPI_LOOP;
diff --git a/include/linux/platform_data/spi-davinci.h b/include/linux/platform_data/spi-davinci.h
index 8dc2fa47..f4edcb0 100644
--- a/include/linux/platform_data/spi-davinci.h
+++ b/include/linux/platform_data/spi-davinci.h
@@ -49,6 +49,7 @@ struct davinci_spi_platform_data {
 	u8			num_chipselect;
 	u8			intr_line;
 	u8			*chip_sel;
+	u8			prescaler_limit;
 	bool			cshold_bug;
 	enum dma_event_q	dma_event_q;
 };
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value
  2015-07-14 19:45 [PATCH 0/4] spi: davinci: Improve prescaler limit support Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 1/4] spi: davinci: Set prescale value based on register value Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 2/4] spi: davinci: Choose correct pre-scaler limit based on SOC Franklin S Cooper Jr
@ 2015-07-14 19:45 ` Franklin S Cooper Jr
  2015-07-14 19:45 ` [PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI Franklin S Cooper Jr
  3 siblings, 0 replies; 5+ messages in thread
From: Franklin S Cooper Jr @ 2015-07-14 19:45 UTC (permalink / raw)
  To: linux-spi
  Cc: linux-arm-kernel, linux-kernel, devicetree, Franklin S Cooper Jr

SPI Davinci driver has been updated to allow SOCs to specify their minimum
prescale value. Update the various SOCs board files that use this driver with
their proper prescaler limit.

Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
---
 arch/arm/mach-davinci/devices-da8xx.c | 2 ++
 arch/arm/mach-davinci/dm355.c         | 1 +
 arch/arm/mach-davinci/dm365.c         | 1 +
 3 files changed, 4 insertions(+)

diff --git a/arch/arm/mach-davinci/devices-da8xx.c b/arch/arm/mach-davinci/devices-da8xx.c
index ddfdd82..29e08aa 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -1010,11 +1010,13 @@ static struct davinci_spi_platform_data da8xx_spi_pdata[] = {
 		.version	= SPI_VERSION_2,
 		.intr_line	= 1,
 		.dma_event_q	= EVENTQ_0,
+		.prescaler_limit = 2,
 	},
 	[1] = {
 		.version	= SPI_VERSION_2,
 		.intr_line	= 1,
 		.dma_event_q	= EVENTQ_0,
+		.prescaler_limit = 2,
 	},
 };
 
diff --git a/arch/arm/mach-davinci/dm355.c b/arch/arm/mach-davinci/dm355.c
index 9cbeda7..567dc56 100644
--- a/arch/arm/mach-davinci/dm355.c
+++ b/arch/arm/mach-davinci/dm355.c
@@ -411,6 +411,7 @@ static struct davinci_spi_platform_data dm355_spi0_pdata = {
 	.num_chipselect = 2,
 	.cshold_bug	= true,
 	.dma_event_q	= EVENTQ_1,
+	.prescaler_limit = 1,
 };
 static struct platform_device dm355_spi0_device = {
 	.name = "spi_davinci",
diff --git a/arch/arm/mach-davinci/dm365.c b/arch/arm/mach-davinci/dm365.c
index e3a3c54..6a890a8 100644
--- a/arch/arm/mach-davinci/dm365.c
+++ b/arch/arm/mach-davinci/dm365.c
@@ -646,6 +646,7 @@ static struct davinci_spi_platform_data dm365_spi0_pdata = {
 	.version 	= SPI_VERSION_1,
 	.num_chipselect = 2,
 	.dma_event_q	= EVENTQ_3,
+	.prescaler_limit = 1,
 };
 
 static struct resource dm365_spi0_resources[] = {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI
  2015-07-14 19:45 [PATCH 0/4] spi: davinci: Improve prescaler limit support Franklin S Cooper Jr
                   ` (2 preceding siblings ...)
  2015-07-14 19:45 ` [PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value Franklin S Cooper Jr
@ 2015-07-14 19:45 ` Franklin S Cooper Jr
  3 siblings, 0 replies; 5+ messages in thread
From: Franklin S Cooper Jr @ 2015-07-14 19:45 UTC (permalink / raw)
  To: linux-spi
  Cc: linux-arm-kernel, linux-kernel, devicetree, Franklin S Cooper Jr

Add ti,keystone-spi to the compatible field for the SPI node. This new
entry insures that the proper prescaler limit is used for keystone devices

Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
---
 arch/arm/boot/dts/keystone.dtsi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/keystone.dtsi b/arch/arm/boot/dts/keystone.dtsi
index c06542b..ea2e1cd 100644
--- a/arch/arm/boot/dts/keystone.dtsi
+++ b/arch/arm/boot/dts/keystone.dtsi
@@ -136,7 +136,7 @@
 		};
 
 		spi0: spi@21000400 {
-			compatible = "ti,dm6441-spi";
+			compatible = "ti,keystone-spi", "ti,dm6441-spi";
 			reg = <0x21000400 0x200>;
 			num-cs = <4>;
 			ti,davinci-spi-intr-line = <0>;
@@ -147,7 +147,7 @@
 		};
 
 		spi1: spi@21000600 {
-			compatible = "ti,dm6441-spi";
+			compatible = "ti,keystone-spi", "ti,dm6441-spi";
 			reg = <0x21000600 0x200>;
 			num-cs = <4>;
 			ti,davinci-spi-intr-line = <0>;
@@ -158,7 +158,7 @@
 		};
 
 		spi2: spi@21000800 {
-			compatible = "ti,dm6441-spi";
+			compatible = "ti,keystone-spi", "ti,dm6441-spi";
 			reg = <0x21000800 0x200>;
 			num-cs = <4>;
 			ti,davinci-spi-intr-line = <0>;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-14 19:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-14 19:45 [PATCH 0/4] spi: davinci: Improve prescaler limit support Franklin S Cooper Jr
2015-07-14 19:45 ` [PATCH 1/4] spi: davinci: Set prescale value based on register value Franklin S Cooper Jr
2015-07-14 19:45 ` [PATCH 2/4] spi: davinci: Choose correct pre-scaler limit based on SOC Franklin S Cooper Jr
2015-07-14 19:45 ` [PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value Franklin S Cooper Jr
2015-07-14 19:45 ` [PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI Franklin S Cooper Jr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).