spi: atcspi200: Full dm conversion
PATCH 1/1 spi: atcspi200: Full dm conversion
From: Rick Chen <[email protected]>
atcspi200_spi now support dt along with platform data.
--- 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
drivers/spi/atcspi200_spi.c +27 -107
@@ -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
include/dm/platform_data/spi_atcspi200.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* Copyright (C) 2018 Rick Chen <[email protected]> +* +* 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 */
Signature · 1 line
1.7.1
PATCH 1/1 spi: atcspi200: Full dm conversion
Quoted 10 lines · Andes
From: Rick Chen <[email protected]>
atcspi200_spinow support dt along with platform data.Signed-off-by Rick Chen <[email protected]>Signed-off-by Rick Chen <[email protected]>Signed-off-by Greentime Hu <[email protected]>--- 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.
PATCH 1/1 spi: atcspi200: Full dm conversion
2018-03-07 15:20 GMT+08:00 Jagan Teki <[email protected]>:
Quoted 12 lines · Andes
Quoted 10 lines
From: Rick Chen <[email protected]>
atcspi200_spinow support dt along with platform data.Signed-off-by Rick Chen <[email protected]>Signed-off-by Rick Chen <[email protected]>Signed-off-by Greentime Hu <[email protected]>--- drivers/spi/atcspi200_spi.c | 134 ++++++------------------------ include/dm/platform_data/spi_atcspi200.h | 15 ++++
Quoted 5 lines
I have seen only two boards using this driver (adp-ae3xx_defconfig, nx25-ae250_defconfig) and both are enabled
DM_SPIwithOF_CONTROLwhy we need to have platdata for this? here [1] is non-dm code drop.
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
A message that is not in the archive (sent off-list or not yet received): CAD6G_RS=Bze+dnsHQ-JxoLV4vjDquOs3hVDP+oiEDTgE0rbxzQ@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): CAD6G_RTOO-WZ7KJA1=3-3_gpKY3OEewsO9-BFRPZFM-oyMQQpw@mail.gmail.com
PATCH 1/1 spi: atcspi200: Full dm conversion
On 07-Mar-2018 1:12 PM, "陳建志" <[email protected]> wrote:
2018-03-07 15:20 GMT+08:00 Jagan Teki <[email protected]>:
Quoted 10 lines · Andes
Quoted 9 lines
From: Rick Chen <[email protected]>
atcspi200_spinow support dt along with platform data.Signed-off-by Rick Chen <[email protected]>Signed-off-by Rick Chen <[email protected]>Signed-off-by Greentime Hu <[email protected]>--- drivers/spi/atcspi200_spi.c | 134
++++++------------------------
Quoted 7 lines
Quoted 1 line
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_SPIwithOF_CONTROLwhy we need to have platdata for this? here [1] is non-dm code drop.
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?
PATCH 1/1 spi: atcspi200: Full dm conversion
2018-03-07 19:02 GMT+08:00 Jagan Teki <[email protected]>:
Quoted 30 lines · 陳建志
2018-03-07 15:20 GMT+08:00 Jagan Teki <[email protected]>:
Quoted 13 lines · Andes
Quoted 11 lines
From: Rick Chen <[email protected]>
atcspi200_spinow support dt along with platform data.Signed-off-by Rick Chen <[email protected]>Signed-off-by Rick Chen <[email protected]>Signed-off-by Greentime Hu <[email protected]>--- drivers/spi/atcspi200_spi.c | 134 ++++++------------------------ include/dm/platform_data/spi_atcspi200.h | 15 ++++Quoted 5 lines
I have seen only two boards using this driver (adp-ae3xx_defconfig, nx25-ae250_defconfig) and both are enabled
DM_SPIwithOF_CONTROLwhy we need to have platdata for this? here [1] is non-dm code drop.Hi Tagan Teki
I just refer to [PATCH][Boards Need to Switch DM] spi: davinci: Full dm conversion
And have this modification.
Quoted 7 lines
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_SPLwith dr. With this reason it is not require to add pdata here?
Thanks for your explanations.
Rick