summaryrefslogtreecommitdiff
path: root/drivers/spi/imx_spi_cpld.c
diff options
context:
space:
mode:
authorSammy He <r62914@freescale.com>2009-11-16 11:59:54 +0800
committerSammy He <r62914@freescale.com>2009-11-20 17:14:44 +0800
commit1701c3caa7ed7d183a57301f6513c1f5fb4102cd (patch)
tree6146e2b73d560b8b5225047cc922b6ce6fd2037d /drivers/spi/imx_spi_cpld.c
parentcbee64d544a2bd8b5e2ae17bcfdfe79480690292 (diff)
downloadu-boot-imx-1701c3caa7ed7d183a57301f6513c1f5fb4102cd.zip
u-boot-imx-1701c3caa7ed7d183a57301f6513c1f5fb4102cd.tar.gz
u-boot-imx-1701c3caa7ed7d183a57301f6513c1f5fb4102cd.tar.bz2
ENGR00118576 MX25: Support Smc911x ethernet
1. Add imx cspi support for cpld access. 2. Add smc911x ethernet support from cpld. Signed-off-by: Sammy He <r62914@freescale.com>
Diffstat (limited to 'drivers/spi/imx_spi_cpld.c')
-rw-r--r--drivers/spi/imx_spi_cpld.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/drivers/spi/imx_spi_cpld.c b/drivers/spi/imx_spi_cpld.c
new file mode 100644
index 0000000..2e20b9c
--- /dev/null
+++ b/drivers/spi/imx_spi_cpld.c
@@ -0,0 +1,90 @@
+/*
+ * (C) Copyright 2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <config.h>
+#include <common.h>
+#include <spi.h>
+#include <asm/errno.h>
+#include <linux/types.h>
+
+#include <imx_spi.h>
+
+static struct spi_slave *cpld_slave;
+
+/*!
+ * To read/write to a CPLD register.
+ *
+ * @param reg register number inside the CPLD
+ * @param val data to be written to the register; don't care for read
+ * @param read 0 for write; 1 for read
+ *
+ * @return the actual data in the CPLD register
+ */
+unsigned int cpld_reg_xfer(unsigned int reg, unsigned int val,
+ unsigned int read)
+{
+ unsigned int local_val1, local_val2;
+ unsigned int g_tx_buf[2], g_rx_buf[2];
+
+ reg >>= 1;
+
+ local_val1 = (read << 13) | ((reg & 0x0001FFFF) >> 5) | 0x00001000;
+ if (read)
+ local_val2 = (((reg & 0x0000001F) << 27) | 0x0200001f);
+ else
+ local_val2 =
+ (((reg & 0x0000001F) << 27) | ((val & 0x0000FFFF) << 6) |
+ 0x03C00027);
+
+ *g_tx_buf = local_val1;
+ *(g_tx_buf + 1) = local_val2;
+
+ if (read) {
+ if (spi_xfer(cpld_slave, 46, (u8 *) g_tx_buf, (u8 *) g_rx_buf,
+ SPI_XFER_BEGIN | SPI_XFER_END)) {
+ return -1;
+ }
+ } else {
+ if (spi_xfer(cpld_slave, 46, (u8 *) g_tx_buf, (u8 *) g_rx_buf,
+ SPI_XFER_BEGIN)) {
+ return -1;
+ }
+ }
+ return ((*(g_rx_buf + 1)) >> 6) & 0xffff;
+}
+
+struct spi_slave *spi_cpld_probe()
+{
+ cpld_slave = spi_setup_slave(0, 0, 25000000, 0);
+ return cpld_slave;
+}
+
+void mxc_cpld_spi_init(void)
+{
+ spi_cpld_probe();
+}
+
+void spi_cpld_free(struct spi_slave *slave)
+{
+ if (slave)
+ spi_free_slave(slave);
+}