2015-07-22 12:34:46

by Franklin S Cooper Jr

[permalink] [raw]
Subject: [RESEND][PATCH 0/4] spi: davinci: Improve prescaler limit support

Currently the prescale limit is treated as one size fits all value even
though there 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


2015-07-22 12:34:47

by Franklin S Cooper Jr

[permalink] [raw]
Subject: [RESEND][PATCH 1/4] spi: davinci: Set prescale value based on register value

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 <[email protected]>
---
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

2015-07-22 12:34:56

by Franklin S Cooper Jr

[permalink] [raw]
Subject: [RESEND][PATCH 2/4] spi: davinci: Choose correct pre-scaler limit based on SOC

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 <[email protected]>
---
.../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

2015-07-22 12:34:57

by Franklin S Cooper Jr

[permalink] [raw]
Subject: [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value

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 <[email protected]>
---
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

2015-07-22 12:35:09

by Franklin S Cooper Jr

[permalink] [raw]
Subject: [RESEND][PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI

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 <[email protected]>
---
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

2015-07-22 16:19:37

by Santosh Shilimkar

[permalink] [raw]
Subject: Re: [RESEND][PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI

On 7/22/2015 5:32 AM, Franklin S Cooper Jr wrote:
> 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 <[email protected]>
> ---
Once the binding and driver makes it, I can pick this up.
Keep me posted. Thanks !!

Regards,
Santosh

2015-07-24 11:50:15

by Sekhar Nori

[permalink] [raw]
Subject: Re: [RESEND][PATCH 2/4] spi: davinci: Choose correct pre-scaler limit based on SOC

On Wednesday 22 July 2015 06:02 PM, Franklin S Cooper Jr wrote:
> 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 <[email protected]>

Reviewed-by: Sekhar Nori <[email protected]>

Thanks,
Sekhar

2015-07-24 11:51:24

by Sekhar Nori

[permalink] [raw]
Subject: Re: [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value

On Wednesday 22 July 2015 06:02 PM, Franklin S Cooper Jr wrote:
> 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 <[email protected]>

Acked-by: Sekhar Nori <[email protected]>

in case Mark is okay to take it through his tree. It does not clash with
anything else I have for mach-davinci.

Thanks,
Sekhar

2015-08-10 23:48:21

by Franklin S Cooper Jr

[permalink] [raw]
Subject: Re: [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value



On 07/24/2015 06:50 AM, Sekhar Nori wrote:
> On Wednesday 22 July 2015 06:02 PM, Franklin S Cooper Jr wrote:
>> 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 <[email protected]>
> Acked-by: Sekhar Nori <[email protected]>
>
> in case Mark is okay to take it through his tree. It does not clash with
> anything else I have for mach-davinci.
>
> Thanks,
> Sekhar
>
ping. Patches 1 and 2 have already been pulled into Mark's spi tree and are currently in in linux-next.

2015-08-11 06:59:13

by Sekhar Nori

[permalink] [raw]
Subject: Re: [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value

On Tuesday 11 August 2015 05:17 AM, Franklin S Cooper Jr. wrote:
>
>
> On 07/24/2015 06:50 AM, Sekhar Nori wrote:
>> On Wednesday 22 July 2015 06:02 PM, Franklin S Cooper Jr wrote:
>>> 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 <[email protected]>
>> Acked-by: Sekhar Nori <[email protected]>
>>
>> in case Mark is okay to take it through his tree. It does not clash with
>> anything else I have for mach-davinci.
>>
>> Thanks,
>> Sekhar
>>
> ping. Patches 1 and 2 have already been pulled into Mark's spi tree and are currently in in linux-next.

Mark, can you apply this patch to your tree as well? Thats the preferred
route for me.

If thats not an option for you, can you confirm that the topic/davinci
branch of your spi tree is an immutable commit I can base my pull
request to ARM-SoC on?

Thanks,
Sekhar

2015-08-11 09:04:06

by Mark Brown

[permalink] [raw]
Subject: Re: [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value

On Tue, Aug 11, 2015 at 12:28:21PM +0530, Sekhar Nori wrote:
> On Tuesday 11 August 2015 05:17 AM, Franklin S Cooper Jr. wrote:

> > ping. Patches 1 and 2 have already been pulled into Mark's spi tree and are currently in in linux-next.

> Mark, can you apply this patch to your tree as well? Thats the preferred
> route for me.

> If thats not an option for you, can you confirm that the topic/davinci
> branch of your spi tree is an immutable commit I can base my pull
> request to ARM-SoC on?

Why would there be any interdependency between the the two trees, that
would be very unusual? Adding a new value to DT doesn't need the kernel
to understand it and the driver should be compatible with existing DTs.
If there *is* some dependency that suggests the driver update has
problems...

In any case I don't have a copy of the patch any more.


Attachments:
(No filename) (847.00 B)
signature.asc (473.00 B)
Digital signature
Download all attachments

2015-08-11 09:25:29

by Sekhar Nori

[permalink] [raw]
Subject: Re: [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value

On Tuesday 11 August 2015 02:33 PM, Mark Brown wrote:
> On Tue, Aug 11, 2015 at 12:28:21PM +0530, Sekhar Nori wrote:
>> On Tuesday 11 August 2015 05:17 AM, Franklin S Cooper Jr. wrote:
>
>>> ping. Patches 1 and 2 have already been pulled into Mark's spi tree and are currently in in linux-next.
>
>> Mark, can you apply this patch to your tree as well? Thats the preferred
>> route for me.
>
>> If thats not an option for you, can you confirm that the topic/davinci
>> branch of your spi tree is an immutable commit I can base my pull
>> request to ARM-SoC on?
>
> Why would there be any interdependency between the the two trees, that
> would be very unusual? Adding a new value to DT doesn't need the kernel
> to understand it and the driver should be compatible with existing DTs.
> If there *is* some dependency that suggests the driver update has
> problems...

The dependency is because of platform data. Patch 2/4 adds a new
platform data member 'prescaler_limit' which this patch populates for
DaVinci devices using legacy booting.

> In any case I don't have a copy of the patch any more.

I can resend this patch to you with my ack included.

Thanks,
Sekhar

2015-08-11 09:28:34

by Mark Brown

[permalink] [raw]
Subject: Re: [RESEND][PATCH 3/4] ARM: davinci: Set proper SPI prescale limit value

On Tue, Aug 11, 2015 at 02:54:33PM +0530, Sekhar Nori wrote:
> On Tuesday 11 August 2015 02:33 PM, Mark Brown wrote:

> > Why would there be any interdependency between the the two trees, that
> > would be very unusual? Adding a new value to DT doesn't need the kernel
> > to understand it and the driver should be compatible with existing DTs.
> > If there *is* some dependency that suggests the driver update has
> > problems...

> The dependency is because of platform data. Patch 2/4 adds a new
> platform data member 'prescaler_limit' which this patch populates for
> DaVinci devices using legacy booting.

Ugh, you still have legacy platforms :(

> > In any case I don't have a copy of the patch any more.

> I can resend this patch to you with my ack included.

I guess.


Attachments:
(No filename) (779.00 B)
signature.asc (473.00 B)
Digital signature
Download all attachments

2015-08-24 13:36:59

by Franklin S Cooper Jr

[permalink] [raw]
Subject: Re: [RESEND][PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI

Hi Santosh,

All the patches except this one are in linux-next.

On 07/22/2015 11:17 AM, santosh shilimkar wrote:
> On 7/22/2015 5:32 AM, Franklin S Cooper Jr wrote:
>> 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 <[email protected]>
>> ---
> Once the binding and driver makes it, I can pick this up.
> Keep me posted. Thanks !!
>
> Regards,
> Santosh
>

2015-08-24 16:16:12

by Santosh Shilimkar

[permalink] [raw]
Subject: Re: [RESEND][PATCH 4/4] ARM: dts: keystone: Add ti,keystone-spi for SPI

On 8/24/2015 6:36 AM, Franklin S Cooper Jr. wrote:
> Hi Santosh,
>
> All the patches except this one are in linux-next.
>
Yes I noticed it. I will queue this up for next merge window.
Thanks for reminder.

Regards,
Santosh