public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Akash Gajjar <gajjar04akash@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/3] spi: sh_spi: full DM conversion
Date: Wed,  9 May 2018 12:27:34 +0530	[thread overview]
Message-ID: <1525849054-24335-1-git-send-email-akash@openedev.com> (raw)
In-Reply-To: <akash@openedev.com>

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, &regs->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, &regs->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;
-- 
2.7.4

  parent reply	other threads:[~2018-05-09  6:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <akash@openedev.com>
2018-04-26 16:46 ` [U-Boot] [PATCH v1 1/3] spi: sh_qspi: DM conversion Akash Gajjar
2018-04-27  6:06   ` Jagan Teki
2018-04-26 16:48 ` [U-Boot] [PATCH v1 2/3] spi: sh_spi: " Akash Gajjar
2018-04-27  6:22   ` Jagan Teki
2018-04-26 16:50 ` [U-Boot] [PATCH v1 3/3] spi: mxs_spi: " Akash Gajjar
2018-04-27  6:40   ` Jagan Teki
2018-05-09  6:36 ` [U-Boot] [PATCH v2 1/3] spi: sh_qspi: full " Akash Gajjar
2018-05-09 11:21   ` Jagan Teki
2018-05-09  6:57 ` Akash Gajjar [this message]
2018-05-09  7:04 ` [U-Boot] [PATCH v2 3/3] spi: mxs_spi: full dm conversion Akash Gajjar
2018-05-09  7:07 ` [U-Boot] [PATCH v1 1/1] spi: lpc32xx_ssp: DM conversion Akash Gajjar
2018-09-04  6:33   ` Jagan Teki
2018-09-19 11:32     ` Vladimir Zapolskiy
2018-11-05 10:09       ` Jagan Teki
2018-05-10 14:13 ` [U-Boot] [PATCH v3 1/3] spi: sh_qspi: " Akash Gajjar
2018-05-10 14:15 ` [U-Boot] [PATCH v3 2/3] spi: sh_spi: " Akash Gajjar
2018-05-10 14:17 ` [U-Boot] [PATCH v3 3/3] spi: mxs_spi: " Akash Gajjar
2018-05-10 14:30   ` Marek Vasut
2018-05-11 10:08     ` Gajjar Akash
2018-05-11 10:39       ` Marek Vasut
2018-05-11 11:09         ` Akash Gajjar
2018-05-11 11:31           ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1525849054-24335-1-git-send-email-akash@openedev.com \
    --to=gajjar04akash@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox