[U-Boot] [PATCH v2 2/3] spi: sh_spi: full DM conversion

v1->v2 New in v2 add cs_info method remove fixed regs address add missing platform struct missing member moved priv struct into sh_spi.c remove unnecessary space and comments
Signed-off-by: Akash Gajjar akash@openedev.com --- drivers/spi/sh_spi.c | 44 +++++++++++++++++++++++++++++++-------- drivers/spi/sh_spi.h | 4 ---- include/dm/platform_data/spi_sh.h | 5 ----- 3 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/drivers/spi/sh_spi.c b/drivers/spi/sh_spi.c index b308ec8..db14031 100644 --- a/drivers/spi/sh_spi.c +++ b/drivers/spi/sh_spi.c @@ -2,7 +2,7 @@ * SH SPI driver * * Support for device model: - * Copyright (C) 2018 Akash Gajjar akash@openedev.com + * Copyright (C) 2018 Akash Gajjar akash@openedev.com * Harshit Shah shahharshitr@gmail.com * * Copyright (C) 2011-2012 Renesas Solutions Corp. @@ -19,6 +19,11 @@ #include <dm/platform_data/spi_sh.h> #include "sh_spi.h"
+struct sh_spi_priv { + struct sh_spi_regs *regs; + u32 cs; +}; + static void sh_spi_write(unsigned long data, unsigned long *reg) { writel(data, reg); @@ -86,10 +91,11 @@ static void sh_spi_set_cs(struct sh_spi_regs *regs, unsigned int cs) sh_spi_set_bit(val, ®s->cr4); }
-static void __spi_setup(struct sh_spi_regs *regs, uint cs) +static void spi_setup(struct sh_spi_priv *priv) { - /* initialize spi */ - regs = (struct sh_spi_regs *)CONFIG_SH_SPI_BASE; + struct sh_spi_regs *regs = priv->regs; + u32 cs = priv->cs; + /* SPI sycle stop */ sh_spi_write(0xfe, ®s->cr1); /* CR1 init */ @@ -106,7 +112,7 @@ static void __spi_setup(struct sh_spi_regs *regs, uint cs) }
static int sh_spi_send(struct sh_spi_regs *regs, const unsigned char *tx_data, - unsigned int len, unsigned long flags) + unsigned int len, unsigned long flags) { int i, cur_len, ret = 0; int remain = (int)len; @@ -151,7 +157,7 @@ static int sh_spi_send(struct sh_spi_regs *regs, const unsigned char *tx_data, }
static int sh_spi_receive(struct sh_spi_regs *regs, unsigned char *rx_data, - unsigned int len, unsigned long flags) + unsigned int len, unsigned long flags) { int i;
@@ -227,12 +233,29 @@ static int sh_spi_xfer(struct udevice *dev, unsigned int bitlen, return ret; }
+static int sh_spi_cs_info(struct udevice *bus, uint cs, + struct spi_cs_info *info) +{ + struct sh_spi_priv *priv = dev_get_priv(bus); + + if (cs >= priv->cs) { + printf("no cs %u\n", cs); + return -ENODEV; + } + + return 0; +} + static int sh_spi_probe(struct udevice *bus) { + struct sh_spi_platdata *plat = bus->platdata; struct sh_spi_priv *priv = dev_get_priv(bus); struct sh_spi_regs *regs = priv->regs;
- __spi_setup(regs, priv->cs); + priv->regs = plat->regs; + priv->cs = plat->cs; + + spi_setup(priv);
return 0; } @@ -248,8 +271,9 @@ static int sh_spi_ofdata_to_platadata(struct udevice *bus) if (addr == FDT_ADDR_T_NONE) return -EINVAL;
+ plat->regs = (struct sh_spi_regs *regs)addr; plat->cs = fdtdec_get_int(gd->fdt_blob, dev_of_offset(bus), - "num-cs", 4); + "num-cs", 4);
return 0; } @@ -259,10 +283,12 @@ static const struct dm_spi_ops mvebu_spi_ops = { .xfer = sh_spi_xfer, .set_speed = sh_spi_set_speed, .set_mode = sh_spi_set_mode, + .cs_info = sh_spi_cs_info, };
+/* TODO: update compatible device tree */ static const struct udevice_id sh_spi_ids[] = { - { .compatible = "sh,sh_spi" }, + { .compatible = " " }, }; #endif
diff --git a/drivers/spi/sh_spi.h b/drivers/spi/sh_spi.h index 87a253f..f945744 100644 --- a/drivers/spi/sh_spi.h +++ b/drivers/spi/sh_spi.h @@ -55,10 +55,6 @@ struct sh_spi_regs { #define SH_SPI_FIFO_SIZE 32 #define SH_SPI_NUM_CS 4
-struct sh_spi_priv { - struct sh_spi_regs *regs; -}; - static inline struct sh_spi *to_sh_spi(struct spi_slave *slave) { return container_of(slave, struct sh_spi, slave); diff --git a/include/dm/platform_data/spi_sh.h b/include/dm/platform_data/spi_sh.h index b4d63dc..c6d0ac5 100644 --- a/include/dm/platform_data/spi_sh.h +++ b/include/dm/platform_data/spi_sh.h @@ -2,16 +2,11 @@ * Copyright (C) 2018 Akash Gajjar akash@openedev.com * * SPDX-License-Identifier: GPL-2.0+ - * */
#ifndef __spi_sh_h #define __spi_sh_h
-/* - * struct sh_spi_platdata - information about a sh spi module - * - */ struct sh_spi_platdata { struct sh_spi_regs *regs; u8 cs;
participants (1)
-
Akash Gajjar