All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] spi: atcspi200: Full dm conversion
@ 2018-03-07  7:04 Andes
  2018-03-07  7:20 ` Jagan Teki
  0 siblings, 1 reply; 5+ messages in thread
From: Andes @ 2018-03-07  7:04 UTC (permalink / raw)
  To: u-boot

From: Rick Chen <rick@andestech.com>

atcspi200_spi now support dt along with platform data.

Signed-off-by: Rick Chen <rick@andestech.com>
Signed-off-by: Rick Chen <rickchen36@gmail.com>
Signed-off-by: Greentime Hu <green.hu@gmail.com>
---
 drivers/spi/atcspi200_spi.c              |  134 ++++++------------------------
 include/dm/platform_data/spi_atcspi200.h |   15 ++++
 2 files changed, 42 insertions(+), 107 deletions(-)
 create mode 100644 include/dm/platform_data/spi_atcspi200.h

diff --git a/drivers/spi/atcspi200_spi.c b/drivers/spi/atcspi200_spi.c
index 5b2e9d6..0c39c80 100644
--- a/drivers/spi/atcspi200_spi.c
+++ b/drivers/spi/atcspi200_spi.c
@@ -13,6 +13,7 @@
 #include <spi.h>
 #include <asm/io.h>
 #include <dm.h>
+#include <dm/platform_data/spi_atcspi200.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -75,9 +76,6 @@ struct atcspi200_spi_regs {
 };
 
 struct nds_spi_slave {
-#ifndef CONFIG_DM_SPI
-	struct spi_slave slave;
-#endif
 	volatile struct atcspi200_spi_regs *regs;
 	int		to;
 	unsigned int	freq;
@@ -286,89 +284,6 @@ static int __atcspi200_spi_xfer(struct nds_spi_slave *ns,
 		return ret;
 }
 
-#ifndef CONFIG_DM_SPI
-#define to_nds_spi_slave(s) container_of(s, struct nds_spi_slave, slave)
-struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
-		unsigned int max_hz, unsigned int mode)
-{
-	struct nds_spi_slave *ns;
-
-	if (!spi_cs_is_valid(bus, cs))
-		return NULL;
-
-	ns = spi_alloc_slave(struct nds_spi_slave, bus, cs);
-	if (!ns)
-		return NULL;
-
-	switch (bus) {
-	case SPI0_BUS:
-			ns->regs = (struct atcspi200_spi_regs *)SPI0_BASE;
-			break;
-
-		case SPI1_BUS:
-			ns->regs = (struct atcspi200_spi_regs *)SPI1_BASE;
-			break;
-
-		default:
-			return NULL;
-	}
-
-	ns->freq= max_hz;
-	ns->mode = mode;
-	ns->to = SPI_TIMEOUT;
-	ns->max_transfer_length = MAX_TRANSFER_LEN;
-	ns->slave.max_write_size = MAX_TRANSFER_LEN;
-
-	return &ns->slave;
-}
-
-void spi_free_slave(struct spi_slave *slave)
-{
-	struct nds_spi_slave *ns = to_nds_spi_slave(slave);
-	free(ns);
-}
-
-void spi_init(void)
-{
-	/* do nothing */
-}
-
-int spi_claim_bus(struct spi_slave *slave)
-{
-	struct nds_spi_slave *ns = to_nds_spi_slave(slave);
-	return __atcspi200_spi_claim_bus(ns);
-}
-
-void spi_release_bus(struct spi_slave *slave)
-{
-	struct nds_spi_slave *ns = to_nds_spi_slave(slave);
-	__atcspi200_spi_release_bus(ns);
-}
-
-int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out,
-		void *data_in, unsigned long flags)
-{
-	struct nds_spi_slave *ns = to_nds_spi_slave(slave);
-	return __atcspi200_spi_xfer(ns, bitlen, data_out, data_in, flags);
-}
-
-int spi_cs_is_valid(unsigned int bus, unsigned int cs)
-{
-	return bus == 0 && cs < NSPI_MAX_CS_NUM;
-}
-
-void spi_cs_activate(struct spi_slave *slave)
-{
-	struct nds_spi_slave *ns = to_nds_spi_slave(slave);
-	__atcspi200_spi_start(ns);
-}
-
-void spi_cs_deactivate(struct spi_slave *slave)
-{
-	struct nds_spi_slave *ns = to_nds_spi_slave(slave);
-	__atcspi200_spi_stop(ns);
-}
-#else
 static int atcspi200_spi_set_speed(struct udevice *bus, uint max_hz)
 {
 	struct nds_spi_slave *ns = dev_get_priv(bus);
@@ -447,7 +362,10 @@ static int atcspi200_spi_get_clk(struct udevice *bus)
 static int atcspi200_spi_probe(struct udevice *bus)
 {
 	struct nds_spi_slave *ns = dev_get_priv(bus);
+	struct atcspi200_spi_platdata *plat = bus->platdata;
 
+	ns->regs = plat->regs;
+	ns->num_cs = plat->num_cs;
 	ns->to = SPI_TIMEOUT;
 	ns->max_transfer_length = MAX_TRANSFER_LEN;
 	ns->mtiming = ns->regs->timing;
@@ -456,24 +374,6 @@ static int atcspi200_spi_probe(struct udevice *bus)
 	return 0;
 }
 
-static int atcspi200_ofdata_to_platadata(struct udevice *bus)
-{
-	struct nds_spi_slave *ns = dev_get_priv(bus);
-	const void *blob = gd->fdt_blob;
-	int node = dev_of_offset(bus);
-
-	ns->regs = map_physmem(devfdt_get_addr(bus),
-				 sizeof(struct atcspi200_spi_regs),
-				 MAP_NOCACHE);
-	if (!ns->regs) {
-		printf("%s: could not map device address\n", __func__);
-		return -EINVAL;
-	}
-	ns->num_cs = fdtdec_get_int(blob, node, "num-cs", 4);
-
-	return 0;
-}
-
 static const struct dm_spi_ops atcspi200_spi_ops = {
 	.claim_bus	= atcspi200_spi_claim_bus,
 	.release_bus	= atcspi200_spi_release_bus,
@@ -482,18 +382,38 @@ static const struct dm_spi_ops atcspi200_spi_ops = {
 	.set_mode	= atcspi200_spi_set_mode,
 };
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+static int atcspi200_ofdata_to_platadata(struct udevice *bus)
+{
+	struct atcspi200_spi_platdata *plat = bus->platdata;
+	fdt_addr_t addr;
+
+	addr = devfdt_get_addr(bus);
+
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	plat->regs = (struct atcspi200_spi_regs *)addr;
+	plat->num_cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), "num-cs", 4);
+
+	return 0;
+}
+
 static const struct udevice_id atcspi200_spi_ids[] = {
 	{ .compatible = "andestech,atcspi200" },
 	{ }
 };
+#endif
 
 U_BOOT_DRIVER(atcspi200_spi) = {
 	.name = "atcspi200_spi",
 	.id = UCLASS_SPI,
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 	.of_match = atcspi200_spi_ids,
-	.ops = &atcspi200_spi_ops,
 	.ofdata_to_platdata = atcspi200_ofdata_to_platadata,
-	.priv_auto_alloc_size = sizeof(struct nds_spi_slave),
+	.platdata_auto_alloc_size = sizeof(struct atcspi200_spi_platdata),
+#endif
 	.probe = atcspi200_spi_probe,
+	.ops = &atcspi200_spi_ops,
+	.priv_auto_alloc_size = sizeof(struct nds_spi_slave),
 };
-#endif
diff --git a/include/dm/platform_data/spi_atcspi200.h b/include/dm/platform_data/spi_atcspi200.h
new file mode 100644
index 0000000..d09e74b
--- /dev/null
+++ b/include/dm/platform_data/spi_atcspi200.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2018 Rick Chen <rick@andestech.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __spi_atcspi200_h
+#define __spi_atcspi200_h
+
+struct atcspi200_spi_platdata {
+	struct atcspi200_spi_regs *regs;
+	u8 num_cs;
+};
+
+#endif /* __spi_atcspi200_h */
-- 
1.7.1

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

* [U-Boot] [PATCH] spi: atcspi200: Full dm conversion
  2018-03-07  7:04 [U-Boot] [PATCH] spi: atcspi200: Full dm conversion Andes
@ 2018-03-07  7:20 ` Jagan Teki
  2018-03-07  7:42   ` 陳建志
  0 siblings, 1 reply; 5+ messages in thread
From: Jagan Teki @ 2018-03-07  7:20 UTC (permalink / raw)
  To: u-boot

On Wed, Mar 7, 2018 at 12:34 PM, Andes <uboot@andestech.com> wrote:
> From: Rick Chen <rick@andestech.com>
>
> atcspi200_spi now support dt along with platform data.
>
> Signed-off-by: Rick Chen <rick@andestech.com>
> Signed-off-by: Rick Chen <rickchen36@gmail.com>
> Signed-off-by: Greentime Hu <green.hu@gmail.com>
> ---
>  drivers/spi/atcspi200_spi.c              |  134 ++++++------------------------
>  include/dm/platform_data/spi_atcspi200.h |   15 ++++

I have seen only two boards using this driver (adp-ae3xx_defconfig,
nx25-ae250_defconfig) and both are enabled DM_SPI with OF_CONTROL why
we need to have platdata for this? here [1] is non-dm code drop.

[1] https://patchwork.ozlabs.org/patch/882404/

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

* [U-Boot] [PATCH] spi: atcspi200: Full dm conversion
  2018-03-07  7:20 ` Jagan Teki
@ 2018-03-07  7:42   ` 陳建志
       [not found]     ` <CAD6G_RS=Bze+dnsHQ-JxoLV4vjDquOs3hVDP+oiEDTgE0rbxzQ@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: 陳建志 @ 2018-03-07  7:42 UTC (permalink / raw)
  To: u-boot

2018-03-07 15:20 GMT+08:00 Jagan Teki <jagannadh.teki@gmail.com>:
> On Wed, Mar 7, 2018 at 12:34 PM, Andes <uboot@andestech.com> wrote:
>> From: Rick Chen <rick@andestech.com>
>>
>> atcspi200_spi now support dt along with platform data.
>>
>> Signed-off-by: Rick Chen <rick@andestech.com>
>> Signed-off-by: Rick Chen <rickchen36@gmail.com>
>> Signed-off-by: Greentime Hu <green.hu@gmail.com>
>> ---
>>  drivers/spi/atcspi200_spi.c              |  134 ++++++------------------------
>>  include/dm/platform_data/spi_atcspi200.h |   15 ++++
>
> I have seen only two boards using this driver (adp-ae3xx_defconfig,
> nx25-ae250_defconfig) and both are enabled DM_SPI with OF_CONTROL why
> we need to have platdata for this? here [1] is non-dm code drop.
>
> [1] https://patchwork.ozlabs.org/patch/882404/

Hi Tagan Teki

I just refer to [PATCH][Boards Need to Switch DM] spi: davinci: Full
dm conversion
And have this modification.

So it is not necessary to add platdata for atcspi200_spi, just drop
non-dm code, right ?

Thank you

Rick

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

* [U-Boot] [PATCH] spi: atcspi200: Full dm conversion
       [not found]       ` <CAD6G_RTOO-WZ7KJA1=3-3_gpKY3OEewsO9-BFRPZFM-oyMQQpw@mail.gmail.com>
@ 2018-03-07 11:02         ` Jagan Teki
  2018-03-08  1:59           ` 陳建志
  0 siblings, 1 reply; 5+ messages in thread
From: Jagan Teki @ 2018-03-07 11:02 UTC (permalink / raw)
  To: u-boot

On 07-Mar-2018 1:12 PM, "陳建志" <rickchen36@gmail.com> wrote:

2018-03-07 15:20 GMT+08:00 Jagan Teki <jagannadh.teki@gmail.com>:
> On Wed, Mar 7, 2018 at 12:34 PM, Andes <uboot@andestech.com> wrote:
>> From: Rick Chen <rick@andestech.com>
>>
>> atcspi200_spi now support dt along with platform data.
>>
>> Signed-off-by: Rick Chen <rick@andestech.com>
>> Signed-off-by: Rick Chen <rickchen36@gmail.com>
>> Signed-off-by: Greentime Hu <green.hu@gmail.com>
>> ---
>>  drivers/spi/atcspi200_spi.c              |  134
++++++------------------------
>>  include/dm/platform_data/spi_atcspi200.h |   15 ++++
>
> I have seen only two boards using this driver (adp-ae3xx_defconfig,
> nx25-ae250_defconfig) and both are enabled DM_SPI with OF_CONTROL why
> we need to have platdata for this? here [1] is non-dm code drop.
>
> [1] https://patchwork.ozlabs.org/patch/882404/

Hi Tagan Teki

I just refer to [PATCH][Boards Need to Switch DM] spi: davinci: Full
dm conversion
And have this modification.

So it is not necessary to add platdata for atcspi200_spi, just drop
non-dm code, right ?


There are two boards using this driver adp-ae3xx_defconfig and
nx25-ae250_defconfig,
both of them use DM_SPL with dr. With this reason it is not require to add
pdata here?

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

* [U-Boot] [PATCH] spi: atcspi200: Full dm conversion
  2018-03-07 11:02         ` Jagan Teki
@ 2018-03-08  1:59           ` 陳建志
  0 siblings, 0 replies; 5+ messages in thread
From: 陳建志 @ 2018-03-08  1:59 UTC (permalink / raw)
  To: u-boot

2018-03-07 19:02 GMT+08:00 Jagan Teki <jagannadh.teki@gmail.com>:
>
>
> On 07-Mar-2018 1:12 PM, "陳建志" <rickchen36@gmail.com> wrote:
>
> 2018-03-07 15:20 GMT+08:00 Jagan Teki <jagannadh.teki@gmail.com>:
>> On Wed, Mar 7, 2018 at 12:34 PM, Andes <uboot@andestech.com> wrote:
>>> From: Rick Chen <rick@andestech.com>
>>>
>>> atcspi200_spi now support dt along with platform data.
>>>
>>> Signed-off-by: Rick Chen <rick@andestech.com>
>>> Signed-off-by: Rick Chen <rickchen36@gmail.com>
>>> Signed-off-by: Greentime Hu <green.hu@gmail.com>
>>> ---
>>>  drivers/spi/atcspi200_spi.c              |  134
>>> ++++++------------------------
>>>  include/dm/platform_data/spi_atcspi200.h |   15 ++++
>>
>> I have seen only two boards using this driver (adp-ae3xx_defconfig,
>> nx25-ae250_defconfig) and both are enabled DM_SPI with OF_CONTROL why
>> we need to have platdata for this? here [1] is non-dm code drop.
>>
>> [1] https://patchwork.ozlabs.org/patch/882404/
>
> Hi Tagan Teki
>
> I just refer to [PATCH][Boards Need to Switch DM] spi: davinci: Full
> dm conversion
> And have this modification.
>
> So it is not necessary to add platdata for atcspi200_spi, just drop
> non-dm code, right ?
>
>
> There are two boards using this driver adp-ae3xx_defconfig and
> nx25-ae250_defconfig, both of them use DM_SPL with dr. With this reason it
> is not require to add pdata here?

Thanks for your explanations.

Rick

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

end of thread, other threads:[~2018-03-08  1:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07  7:04 [U-Boot] [PATCH] spi: atcspi200: Full dm conversion Andes
2018-03-07  7:20 ` Jagan Teki
2018-03-07  7:42   ` 陳建志
     [not found]     ` <CAD6G_RS=Bze+dnsHQ-JxoLV4vjDquOs3hVDP+oiEDTgE0rbxzQ@mail.gmail.com>
     [not found]       ` <CAD6G_RTOO-WZ7KJA1=3-3_gpKY3OEewsO9-BFRPZFM-oyMQQpw@mail.gmail.com>
2018-03-07 11:02         ` Jagan Teki
2018-03-08  1:59           ` 陳建志

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.