From: Jason Wang <jason77.wang@gmail.com>
To: s.hauer@pengutronix.de, u.kleine-koenig@pengutronix.de,
amit.kucheria@canonical.com, grant.likely@secretlab.ca
Cc: spi-devel-general@lists.sourceforge.net,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/6] spi-imx: add CSPI and eCSPI support for i.MX51 MCU
Date: Thu, 2 Sep 2010 15:51:59 +0800 [thread overview]
Message-ID: <1283413924-14210-2-git-send-email-jason77.wang@gmail.com> (raw)
In-Reply-To: <1283413924-14210-1-git-send-email-jason77.wang@gmail.com>
There are 3 SPI controllers on i.MX51, one is called CSPI and is
100% compatible with the one on i.MX35, the other two are called
eCSPI and are not compatible with existing controllers on other
i.MX platforms, here we add support of these three controllers in
the imx spi driver.
Signed-off-by: Jason Wang <jason77.wang@gmail.com>
---
drivers/spi/spi_imx.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 131 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 7972e90..8d9c9da 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -155,6 +155,120 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
return 7;
}
+/* MX51 eCSPI post divider */
+static unsigned int spi_imx_clkdiv_3(unsigned int fin,
+ unsigned int fspi)
+{
+ int i, div = 1;
+
+ for (i = 0; i < 15; i++) {
+ if (fspi * div >= fin)
+ return i;
+ div <<= 1;
+ }
+
+ return 15;
+}
+
+#define MX51_INTREG_TEEN (1 << 0)
+#define MX51_INTREG_RREN (1 << 3)
+
+#define MX51_CSPICTRL_ENABLE (1 << 0)
+#define MX51_CSPICTRL_XCH (1 << 2)
+
+#define MX51_CSPICTRL_BL_SHIFT 20
+#define MX51_CSPICTRL_CS_SHIFT 18
+#define MX51_CSPICTRL_DR_SHIFT 8
+#define MX51_CSPICTRL_MODE_SHIFT 4
+#define MX51_CSPICONF_PHA_SHIFT 0
+#define MX51_CSPICONF_POL_SHIFT 4
+#define MX51_CSPICONF_SSPOL_SHIFT 12
+#define MX51_CSPICONF_SSCTL_SHIFT 8
+
+#define MX51_CSPICTRL_CSMASK 0x3
+#define MX51_CSPIINT 0x10
+#define MX51_CSPICONF 0xC
+#define MX51_CSPISTATUS 0x18
+#define MX51_STATUS_RR (1 << 3)
+
+#define MAX_CHIPSELECT_NUM 4
+
+static int get_chipselect(struct spi_imx_data *spi_imx,
+ struct spi_imx_config *config)
+{
+ int i;
+
+ for (i = 0; i < MAX_CHIPSELECT_NUM; i++) {
+ if (config->cs == spi_imx->chipselect[i])
+ return i;
+ }
+
+ return -EINVAL;
+}
+static void mx51_intctrl(struct spi_imx_data *spi_imx, int enable)
+{
+ unsigned int val = 0;
+
+ if (enable & MXC_INT_TE)
+ val |= MX51_INTREG_TEEN;
+ if (enable & MXC_INT_RR)
+ val |= MX51_INTREG_RREN;
+
+ writel(val, spi_imx->base + MX51_CSPIINT);
+}
+
+static void mx51_trigger(struct spi_imx_data *spi_imx)
+{
+ unsigned int reg;
+
+ reg = readl(spi_imx->base + MXC_CSPICTRL);
+ reg |= MX51_CSPICTRL_XCH;
+ writel(reg, spi_imx->base + MXC_CSPICTRL);
+}
+
+static int mx51_config(struct spi_imx_data *spi_imx,
+ struct spi_imx_config *config)
+{
+ unsigned int config_reg = 0;
+ unsigned int ctrl_reg = MX51_CSPICTRL_ENABLE;
+ int chan;
+
+ chan = get_chipselect(spi_imx, config);
+ if (chan < 0)
+ return chan;
+ ctrl_reg |= (chan & MX51_CSPICTRL_CSMASK) << MX51_CSPICTRL_CS_SHIFT;
+ ctrl_reg |= (1 << (chan & MX51_CSPICTRL_CSMASK)) <<
+ MX51_CSPICTRL_MODE_SHIFT;
+ ctrl_reg |= spi_imx_clkdiv_3(spi_imx->spi_clk, config->speed_hz) <<
+ MX51_CSPICTRL_DR_SHIFT;
+
+ ctrl_reg |= (config->bpw - 1) << MX51_CSPICTRL_BL_SHIFT;
+
+
+ if (config->mode & SPI_CPHA)
+ config_reg |= (1 << (chan & MX51_CSPICTRL_CSMASK)) <<
+ MX51_CSPICONF_PHA_SHIFT;
+ if (config->mode & SPI_CPOL)
+ config_reg |= (1 << (chan & MX51_CSPICTRL_CSMASK)) <<
+ MX51_CSPICONF_POL_SHIFT;
+ if (config->mode & SPI_CS_HIGH)
+ config_reg |= (1 << (chan & MX51_CSPICTRL_CSMASK)) <<
+ MX51_CSPICONF_SSPOL_SHIFT;
+
+ config_reg |= (1 << (chan & MX51_CSPICTRL_CSMASK)) <<
+ MX51_CSPICONF_SSCTL_SHIFT;
+
+ writel(ctrl_reg, spi_imx->base + MXC_CSPICTRL);
+ writel(config_reg, spi_imx->base + MX51_CSPICONF);
+
+ return 0;
+}
+
+static int mx51_rx_available(struct spi_imx_data *spi_imx)
+{
+ return readl(spi_imx->base + MX51_CSPISTATUS) & MX51_STATUS_RR;
+}
+
#define MX31_INTREG_TEEN (1 << 0)
#define MX31_INTREG_RREN (1 << 3)
@@ -209,7 +323,7 @@ static int mx31_config(struct spi_imx_data *spi_imx,
if (cpu_is_mx31())
reg |= (config->bpw - 1) << MX31_CSPICTRL_BC_SHIFT;
- else if (cpu_is_mx25() || cpu_is_mx35()) {
+ else if (cpu_is_mx25() || cpu_is_mx35() || cpu_is_mx51()) {
reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT;
reg |= MX31_CSPICTRL_SSCTL;
}
@@ -223,7 +337,7 @@ static int mx31_config(struct spi_imx_data *spi_imx,
if (config->cs < 0) {
if (cpu_is_mx31())
reg |= (config->cs + 32) << MX31_CSPICTRL_CS_SHIFT;
- else if (cpu_is_mx25() || cpu_is_mx35())
+ else if (cpu_is_mx25() || cpu_is_mx35() || cpu_is_mx51())
reg |= (config->cs + 32) << MX35_CSPICTRL_CS_SHIFT;
}
@@ -567,7 +681,14 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
goto out_iounmap;
}
- if (cpu_is_mx25() || cpu_is_mx31() || cpu_is_mx35()) {
+ /* i.MX51 has two eCSPI and one CSPI controllers, eCSPI controllers are
+ * not compatible with existing SPI controllers on other i.MX platforms,
+ * while CSPI controller is 100% compatible with the one on the i.MX35.
+ * We set the platform device id to 2 for this CSPI at i.MX51 board init
+ * level to distinguish it from two eCSPI controllers.
+ */
+ if (cpu_is_mx25() || cpu_is_mx31() || cpu_is_mx35() ||
+ (cpu_is_mx51() && (pdev->id == 2))) {
spi_imx->intctrl = mx31_intctrl;
spi_imx->config = mx31_config;
spi_imx->trigger = mx31_trigger;
@@ -582,6 +703,11 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
spi_imx->config = mx1_config;
spi_imx->trigger = mx1_trigger;
spi_imx->rx_available = mx1_rx_available;
+ } else if (cpu_is_mx51()) {
+ spi_imx->intctrl = mx51_intctrl;
+ spi_imx->config = mx51_config;
+ spi_imx->trigger = mx51_trigger;
+ spi_imx->rx_available = mx51_rx_available;
} else
BUG();
@@ -599,7 +725,8 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
writel(1, spi_imx->base + MXC_RESET);
/* drain receive buffer */
- if (cpu_is_mx25() || cpu_is_mx31() || cpu_is_mx35())
+ if (cpu_is_mx25() || cpu_is_mx31() || cpu_is_mx35() ||
+ (cpu_is_mx51() && (pdev->id == 2)))
while (readl(spi_imx->base + MX3_CSPISTAT) & MX3_CSPISTAT_RR)
readl(spi_imx->base + MXC_CSPIRXDATA);
--
1.5.6.5
next prev parent reply other threads:[~2010-09-02 7:51 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 ` Jason Wang [this message]
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
[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 ` [PATCH 05/16] spi/imx: add support for imx51's eCSPI and CSPI Uwe Kleine-König
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 03/16] spi/imx: get rid of more ifs depending on the used cpu 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=1283413924-14210-2-git-send-email-jason77.wang@gmail.com \
--to=jason77.wang@gmail.com \
--cc=amit.kucheria@canonical.com \
--cc=grant.likely@secretlab.ca \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
--cc=spi-devel-general@lists.sourceforge.net \
--cc=u.kleine-koenig@pengutronix.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;
as well as URLs for NNTP newsgroup(s).