linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Jason Wang <jason77.wang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
	amit.kucheria-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: [PATCH 05/16] spi/imx: add support for imx51's eCSPI and CSPI
Date: Fri, 17 Sep 2010 11:54:23 +0200	[thread overview]
Message-ID: <1284717274-12850-5-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20100917095247.GB30441-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

i.MX51 comes with two eCSPI interfaces (that are quite different from
what was known before---the tried and tested Freescale way) and a CSPI
interface that is identical to the devices found on i.MX25 and i.MX35.

This patch is a merge of two very similar patches (by Jason Wang and Sascha
Hauer resp.) plus a (now hopefully correct) reimplementation of the
clock calculation.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/spi/Kconfig   |    5 ++-
 drivers/spi/spi_imx.c |  140 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 143 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 4e9d77b..7e631fa 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -153,7 +153,10 @@ config SPI_IMX_VER_0_4
 	def_bool y if ARCH_MX31
 
 config SPI_IMX_VER_0_7
-	def_bool y if ARCH_MX25 || ARCH_MX35
+	def_bool y if ARCH_MX25 || ARCH_MX35 || ARCH_MX51
+
+config SPI_IMX_VER_2_3
+	def_bool y if ARCH_MX51
 
 config SPI_IMX
 	tristate "Freescale i.MX SPI controllers"
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 23db984..6bab2cf 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -65,6 +65,7 @@ enum spi_imx_devtype {
 	SPI_IMX_VER_0_4,
 	SPI_IMX_VER_0_5,
 	SPI_IMX_VER_0_7,
+	SPI_IMX_VER_2_3,
 	SPI_IMX_VER_AUTODETECT,
 };
 
@@ -155,7 +156,7 @@ static unsigned int spi_imx_clkdiv_1(unsigned int fin,
 	return max;
 }
 
-/* MX1, MX31, MX35 */
+/* MX1, MX31, MX35, MX51 CSPI */
 static unsigned int spi_imx_clkdiv_2(unsigned int fin,
 		unsigned int fspi)
 {
@@ -170,6 +171,128 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
 	return 7;
 }
 
+#define SPI_IMX2_3_CTRL		0x08
+#define SPI_IMX2_3_CTRL_ENABLE		(1 <<  0)
+#define SPI_IMX2_3_CTRL_XCH		(1 <<  2)
+#define SPI_IMX2_3_CTRL_MODE(cs)	(1 << ((cs) +  4))
+#define SPI_IMX2_3_CTRL_POSTDIV_OFFSET	8
+#define SPI_IMX2_3_CTRL_PREDIV_OFFSET	12
+#define SPI_IMX2_3_CTRL_CS(cs)		((cs) << 18)
+#define SPI_IMX2_3_CTRL_BL_OFFSET	20
+
+#define SPI_IMX2_3_CONFIG	0x0c
+#define SPI_IMX2_3_CONFIG_SCLKPHA(cs)	(1 << ((cs) +  0))
+#define SPI_IMX2_3_CONFIG_SCLKPOL(cs)	(1 << ((cs) +  4))
+#define SPI_IMX2_3_CONFIG_SBBCTRL(cs)	(1 << ((cs) +  8))
+#define SPI_IMX2_3_CONFIG_SSBPOL(cs)	(1 << ((cs) + 12))
+
+#define SPI_IMX2_3_INT		0x10
+#define SPI_IMX2_3_INT_TEEN		(1 <<  0)
+#define SPI_IMX2_3_INT_RREN		(1 <<  3)
+
+#define SPI_IMX2_3_STAT		0x18
+#define SPI_IMX2_3_STAT_RR		(1 <<  3)
+
+/* MX51 eCSPI */
+static unsigned int spi_imx2_3_clkdiv(unsigned int fin, unsigned int fspi)
+{
+	/*
+	 * there are two 4-bit dividers, the pre-divider divides by
+	 * $pre, the post-divider by 2^$post
+	 */
+	unsigned int pre, post;
+
+	if (unlikely(fspi > fin))
+		return 0;
+
+	post = fls(fin) - fls(fspi);
+	if (fin > fspi << post)
+		post++;
+
+	/* now we have: (fin <= fspi << post) with post being minimal */
+
+	post = max(4U, post) - 4;
+	if (unlikely(post > 0xf)) {
+		pr_err("%s: cannot set clock freq: %u (base freq: %u)\n",
+				__func__, fspi, fin);
+		return 0xff;
+	}
+
+	pre = DIV_ROUND_UP(fin, fspi << post) - 1;
+
+	pr_debug("%s: fin: %u, fspi: %u, post: %u, pre: %u\n",
+			__func__, fin, fspi, post, pre);
+	return (pre << SPI_IMX2_3_CTRL_PREDIV_OFFSET) |
+		(post << SPI_IMX2_3_CTRL_POSTDIV_OFFSET);
+}
+
+static void __maybe_unused spi_imx2_3_intctrl(struct spi_imx_data *spi_imx, int enable)
+{
+	unsigned val = 0;
+
+	if (enable & MXC_INT_TE)
+		val |= SPI_IMX2_3_INT_TEEN;
+
+	if (enable & MXC_INT_RR)
+		val |= SPI_IMX2_3_INT_RREN;
+
+	writel(val, spi_imx->base + SPI_IMX2_3_INT);
+}
+
+static void __maybe_unused spi_imx2_3_trigger(struct spi_imx_data *spi_imx)
+{
+	u32 reg;
+
+	reg = readl(spi_imx->base + SPI_IMX2_3_CTRL);
+	reg |= SPI_IMX2_3_CTRL_XCH;
+	writel(reg, spi_imx->base + SPI_IMX2_3_CTRL);
+}
+
+static int __maybe_unused spi_imx2_3_config(struct spi_imx_data *spi_imx,
+		struct spi_imx_config *config)
+{
+	u32 ctrl = SPI_IMX2_3_CTRL_ENABLE, cfg = 0;
+
+	/* set master mode */
+	ctrl |= SPI_IMX2_3_CTRL_MODE(config->cs);
+
+	/* set clock speed */
+	ctrl |= spi_imx2_3_clkdiv(spi_imx->spi_clk, config->speed_hz);
+
+	/* set chip select to use */
+	ctrl |= SPI_IMX2_3_CTRL_CS(config->cs);
+
+	ctrl |= (config->bpw - 1) << SPI_IMX2_3_CTRL_BL_OFFSET;
+
+	cfg |= SPI_IMX2_3_CONFIG_SBBCTRL(config->cs);
+
+	if (config->mode & SPI_CPHA)
+		cfg |= SPI_IMX2_3_CONFIG_SCLKPHA(config->cs);
+
+	if (config->mode & SPI_CPOL)
+		cfg |= SPI_IMX2_3_CONFIG_SCLKPOL(config->cs);
+
+	if (config->mode & SPI_CS_HIGH)
+		cfg |= SPI_IMX2_3_CONFIG_SSBPOL(config->cs);
+
+	writel(ctrl, spi_imx->base + SPI_IMX2_3_CTRL);
+	writel(cfg, spi_imx->base + SPI_IMX2_3_CONFIG);
+
+	return 0;
+}
+
+static int __maybe_unused spi_imx2_3_rx_available(struct spi_imx_data *spi_imx)
+{
+	return readl(spi_imx->base + SPI_IMX2_3_STAT) & SPI_IMX2_3_STAT_RR;
+}
+
+static void __maybe_unused spi_imx2_3_reset(struct spi_imx_data *spi_imx)
+{
+	/* drain receive buffer */
+	while (spi_imx2_3_rx_available(spi_imx))
+		readl(spi_imx->base + MXC_CSPIRXDATA);
+}
+
 #define MX31_INTREG_TEEN	(1 << 0)
 #define MX31_INTREG_RREN	(1 << 3)
 
@@ -447,6 +570,15 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] __devinitdata = {
 		.reset = spi_imx0_4_reset,
 	},
 #endif
+#ifdef CONFIG_SPI_IMX_VER_2_3
+	[SPI_IMX_VER_2_3] = {
+		.intctrl = spi_imx2_3_intctrl,
+		.config = spi_imx2_3_config,
+		.trigger = spi_imx2_3_trigger,
+		.rx_available = spi_imx2_3_rx_available,
+		.reset = spi_imx2_3_reset,
+	},
+#endif
 };
 
 static void spi_imx_chipselect(struct spi_device *spi, int is_active)
@@ -603,6 +735,12 @@ static struct platform_device_id spi_imx_devtype[] = {
 		.name = "imx35-cspi",
 		.driver_data = SPI_IMX_VER_0_7,
 	}, {
+		.name = "imx51-cspi",
+		.driver_data = SPI_IMX_VER_0_7,
+	}, {
+		.name = "imx51-ecspi",
+		.driver_data = SPI_IMX_VER_2_3,
+	}, {
 		/* sentinel */
 	}
 };
-- 
1.7.2.3


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
spi-devel-general mailing list
spi-devel-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spi-devel-general

  parent reply	other threads:[~2010-09-17  9:54 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-02  7:51 [PATCH 0/6] add spi support for i.MX51 in the existing spi_imx driver Jason Wang
2010-09-02  7:51 ` [PATCH 1/6] spi-imx: add CSPI and eCSPI support for i.MX51 MCU Jason Wang
2010-09-02  7:52   ` [PATCH 2/6] i.MX5/clock: add eCSPI and CSPI clock definitions Jason Wang
2010-09-02  7:52     ` [PATCH 3/6] mx5: add support to dynamically register spi_imx devices (imx51 3ds) Jason Wang
2010-09-02  7:52       ` [PATCH 4/6] mx5/iomux: add iomux definitions for eCSPI2 on the imx51_3ds board Jason Wang
2010-09-02  7:52         ` [PATCH 5/6] mx51_3ds: add eCSPI2 support " Jason Wang
2010-09-02  7:52           ` [PATCH 6/6] mx51_3ds: add SPI NOR flash in the board init stage Jason Wang
2010-09-02 15:05           ` [PATCH 5/6] mx51_3ds: add eCSPI2 support on the imx51_3ds board Uwe Kleine-König
2010-09-03  6:24             ` Jason Wang
2010-09-02 15:02       ` [PATCH 3/6] mx5: add support to dynamically register spi_imx devices (imx51 3ds) Uwe Kleine-König
2010-09-03  6:22         ` Jason Wang
2010-09-02 15:01     ` [PATCH 2/6] i.MX5/clock: add eCSPI and CSPI clock definitions Uwe Kleine-König
2010-09-03  6:22       ` Jason Wang
2010-09-10  9:47         ` Uwe Kleine-König
     [not found]           ` <20100910094714.GF30558-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-09-10 10:04             ` Lothar Waßmann
2010-09-13  3:31           ` Jason Wang
2010-09-02 14:53   ` [PATCH 1/6] spi-imx: add CSPI and eCSPI support for i.MX51 MCU Uwe Kleine-König
2010-09-02 15:11     ` Lothar Waßmann
2010-09-02 17:29       ` Baruch Siach
2010-09-02 17:57         ` Uwe Kleine-König
2010-09-03  8:49         ` Lothar Waßmann
2010-09-03  6:16     ` Jason Wang
2010-09-03  7:54       ` Uwe Kleine-König
2010-09-02  8:27 ` [PATCH 0/6] add spi support for i.MX51 in the existing spi_imx driver Uwe Kleine-König
2010-09-02 10:07   ` Jason Wang
2010-09-02 14:39     ` Uwe Kleine-König
2010-09-02 14:41       ` [PATCH 1/6] ARM: mx51: clean up mx51 header Uwe Kleine-König
2010-09-02 14:41       ` [PATCH 2/6] ARM: mx51: fix naming of spi related defines Uwe Kleine-König
2010-09-02 14:42       ` [PATCH 3/6] ARM: imx: change the way spi-imx devices are registered Uwe Kleine-König
2010-09-02 14:42       ` [PATCH 4/6] ARM: mx51: Add spi clock and spi_imx device registration Uwe Kleine-König
     [not found]         ` <1283438523-19697-4-git-send-email-u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-09-03  5:46           ` Jason Wang
2010-09-02 14:42       ` [PATCH 5/6] spi-imx: Add i.MX51 support Uwe Kleine-König
2010-09-09  5:33         ` Grant Likely
2010-09-09  7:27           ` Uwe Kleine-König
2010-09-02 14:42       ` [PATCH 6/6] ARM: mx5/mx51_babbage: Add spi support Uwe Kleine-König
2010-09-03  3:18       ` [PATCH 0/6] add spi support for i.MX51 in the existing spi_imx driver Jason Wang
2010-09-03  6:41         ` Amit Kucheria
2010-09-03  9:34           ` Robert Schwebel
2010-09-17  9:52       ` Uwe Kleine-König
2010-09-17  9:54         ` [PATCH 01/16] spi/imx: default to m on platforms that have such devices Uwe Kleine-König
2010-09-17  9:54         ` [PATCH 03/16] spi/imx: get rid of more ifs depending on the used cpu Uwe Kleine-König
     [not found]         ` <20100917095247.GB30441-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-09-17  9:54           ` [PATCH 02/16] spi/imx: convert driver to use platform ids Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 04/16] spi/imx: save the spi chip select in config struct, not the gpio to use Uwe Kleine-König
     [not found]             ` <1284717274-12850-4-git-send-email-u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-09-17 11:11               ` Lothar Waßmann
2010-09-17 11:20                 ` Russell King - ARM Linux
2010-09-19  8:47                   ` Jason Wang
2010-09-17  9:54           ` Uwe Kleine-König [this message]
2010-09-17  9:54           ` [PATCH 06/16] ARM: imx: change the way spi-imx devices are registered Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 07/16] ARM: imx: use platform ids for spi_imx devices Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 08/16] ARM: mx51: clean up mx51 header Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 09/16] ARM: mx51: fix naming of spi related defines Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 10/16] ARM: mx5: add spi_imx device registration Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 11/16] ARM: mx5/clock-mx51: refactor ccgr callbacks to use common code Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 13/16] ARM: mx5/clock-mx51: add spi clocks Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 14/16] ARM: mx5/iomux-mx51: add iomux definitions for eCSPI2 on the imx51_3ds board Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 15/16] ARM: mx5/mx51_3ds: add eCSPI2 support " Uwe Kleine-König
2010-09-17  9:54           ` [PATCH 16/16] ARM: mx5/mx51_3ds: add SPI NOR flash in the board init stage Uwe Kleine-König
2010-09-17  9:54         ` [PATCH 12/16] ARM: mx5/clock-mx51: new macro that defines a clk with all members Uwe Kleine-König
2010-09-19  8:53         ` [PATCH 0/6] add spi support for i.MX51 in the existing spi_imx driver Jason Wang
2010-09-20 15:33           ` Uwe Kleine-König
2010-09-21  1:39             ` Jason Wang
2010-09-24  7:00         ` Grant Likely
2010-09-24  9:11           ` Uwe Kleine-König
2010-09-24 16:12             ` Grant Likely
2010-09-24 18:18               ` Uwe Kleine-König
     [not found]       ` <20100902143908.GK14214-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-10-08  9:24         ` [PATCH 7/6] spi/imx: Support different fifo sizes Uwe Kleine-König
     [not found]           ` <1286529841-20800-1-git-send-email-u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-10-08 16:39             ` Grant Likely

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=1284717274-12850-5-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig-bicnvbalz9megne8c9+irq@public.gmane.org \
    --cc=amit.kucheria-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org \
    --cc=jason77.wang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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;
as well as URLs for NNTP newsgroup(s).