2007-02-12 11:52:37 +03:00
|
|
|
/*
|
2011-06-06 11:16:30 +04:00
|
|
|
* MicroWire interface driver for OMAP
|
2007-02-12 11:52:37 +03:00
|
|
|
*
|
|
|
|
* Copyright 2003 MontaVista Software Inc. <source@mvista.com>
|
|
|
|
*
|
|
|
|
* Ported to 2.6 OMAP uwire interface.
|
|
|
|
* Copyright (C) 2004 Texas Instruments.
|
|
|
|
*
|
|
|
|
* Generalization patches by Juha Yrjola <juha.yrjola@nokia.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 David Brownell (ported to 2.6 SPI interface)
|
|
|
|
* Copyright (C) 2006 Nokia
|
|
|
|
*
|
|
|
|
* Many updates by Imre Deak <imre.deak@nokia.com>
|
|
|
|
*
|
|
|
|
* 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 SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/clk.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2014-06-24 15:52:46 +04:00
|
|
|
#include <linux/device.h>
|
2007-02-12 11:52:37 +03:00
|
|
|
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/spi/spi_bitbang.h>
|
2011-07-03 23:44:29 +04:00
|
|
|
#include <linux/module.h>
|
2014-06-24 10:18:19 +04:00
|
|
|
#include <linux/io.h>
|
2007-02-12 11:52:37 +03:00
|
|
|
|
2008-08-05 19:14:15 +04:00
|
|
|
#include <mach/hardware.h>
|
2007-02-12 11:52:37 +03:00
|
|
|
#include <asm/mach-types.h>
|
|
|
|
|
2012-09-19 21:46:56 +04:00
|
|
|
#include <mach/mux.h>
|
2012-09-01 04:04:35 +04:00
|
|
|
|
|
|
|
#include <mach/omap7xx.h> /* OMAP7XX_IO_CONF registers */
|
2007-02-12 11:52:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* FIXME address is now a platform device resource,
|
|
|
|
* and irqs should show there too...
|
|
|
|
*/
|
|
|
|
#define UWIRE_BASE_PHYS 0xFFFB3000
|
|
|
|
|
|
|
|
/* uWire Registers: */
|
|
|
|
#define UWIRE_IO_SIZE 0x20
|
|
|
|
#define UWIRE_TDR 0x00
|
|
|
|
#define UWIRE_RDR 0x00
|
|
|
|
#define UWIRE_CSR 0x01
|
|
|
|
#define UWIRE_SR1 0x02
|
|
|
|
#define UWIRE_SR2 0x03
|
|
|
|
#define UWIRE_SR3 0x04
|
|
|
|
#define UWIRE_SR4 0x05
|
|
|
|
#define UWIRE_SR5 0x06
|
|
|
|
|
|
|
|
/* CSR bits */
|
|
|
|
#define RDRB (1 << 15)
|
|
|
|
#define CSRB (1 << 14)
|
|
|
|
#define START (1 << 13)
|
|
|
|
#define CS_CMD (1 << 12)
|
|
|
|
|
|
|
|
/* SR1 or SR2 bits */
|
|
|
|
#define UWIRE_READ_FALLING_EDGE 0x0001
|
|
|
|
#define UWIRE_READ_RISING_EDGE 0x0000
|
|
|
|
#define UWIRE_WRITE_FALLING_EDGE 0x0000
|
|
|
|
#define UWIRE_WRITE_RISING_EDGE 0x0002
|
|
|
|
#define UWIRE_CS_ACTIVE_LOW 0x0000
|
|
|
|
#define UWIRE_CS_ACTIVE_HIGH 0x0004
|
|
|
|
#define UWIRE_FREQ_DIV_2 0x0000
|
|
|
|
#define UWIRE_FREQ_DIV_4 0x0008
|
|
|
|
#define UWIRE_FREQ_DIV_8 0x0010
|
|
|
|
#define UWIRE_CHK_READY 0x0020
|
|
|
|
#define UWIRE_CLK_INVERTED 0x0040
|
|
|
|
|
|
|
|
|
|
|
|
struct uwire_spi {
|
|
|
|
struct spi_bitbang bitbang;
|
|
|
|
struct clk *ck;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uwire_state {
|
|
|
|
unsigned div1_idx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* REVISIT compile time constant for idx_shift? */
|
2008-09-04 17:07:22 +04:00
|
|
|
/*
|
|
|
|
* Or, put it in a structure which is used throughout the driver;
|
|
|
|
* that avoids having to issue two loads for each bit of static data.
|
|
|
|
*/
|
2007-02-12 11:52:37 +03:00
|
|
|
static unsigned int uwire_idx_shift;
|
2008-09-04 17:07:22 +04:00
|
|
|
static void __iomem *uwire_base;
|
2007-02-12 11:52:37 +03:00
|
|
|
|
|
|
|
static inline void uwire_write_reg(int idx, u16 val)
|
|
|
|
{
|
2008-09-04 17:07:22 +04:00
|
|
|
__raw_writew(val, uwire_base + (idx << uwire_idx_shift));
|
2007-02-12 11:52:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline u16 uwire_read_reg(int idx)
|
|
|
|
{
|
2008-09-04 17:07:22 +04:00
|
|
|
return __raw_readw(uwire_base + (idx << uwire_idx_shift));
|
2007-02-12 11:52:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void omap_uwire_configure_mode(u8 cs, unsigned long flags)
|
|
|
|
{
|
|
|
|
u16 w, val = 0;
|
|
|
|
int shift, reg;
|
|
|
|
|
|
|
|
if (flags & UWIRE_CLK_INVERTED)
|
|
|
|
val ^= 0x03;
|
|
|
|
val = flags & 0x3f;
|
|
|
|
if (cs & 1)
|
|
|
|
shift = 6;
|
|
|
|
else
|
|
|
|
shift = 0;
|
|
|
|
if (cs <= 1)
|
|
|
|
reg = UWIRE_SR1;
|
|
|
|
else
|
|
|
|
reg = UWIRE_SR2;
|
|
|
|
|
|
|
|
w = uwire_read_reg(reg);
|
|
|
|
w &= ~(0x3f << shift);
|
|
|
|
w |= val << shift;
|
|
|
|
uwire_write_reg(reg, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wait_uwire_csr_flag(u16 mask, u16 val, int might_not_catch)
|
|
|
|
{
|
|
|
|
u16 w;
|
|
|
|
int c = 0;
|
|
|
|
unsigned long max_jiffies = jiffies + HZ;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
w = uwire_read_reg(UWIRE_CSR);
|
|
|
|
if ((w & mask) == val)
|
|
|
|
break;
|
|
|
|
if (time_after(jiffies, max_jiffies)) {
|
|
|
|
printk(KERN_ERR "%s: timeout. reg=%#06x "
|
|
|
|
"mask=%#06x val=%#06x\n",
|
2008-04-28 13:14:19 +04:00
|
|
|
__func__, w, mask, val);
|
2007-02-12 11:52:37 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
c++;
|
|
|
|
if (might_not_catch && c > 64)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uwire_set_clk1_div(int div1_idx)
|
|
|
|
{
|
|
|
|
u16 w;
|
|
|
|
|
|
|
|
w = uwire_read_reg(UWIRE_SR3);
|
|
|
|
w &= ~(0x03 << 1);
|
|
|
|
w |= div1_idx << 1;
|
|
|
|
uwire_write_reg(UWIRE_SR3, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uwire_chipselect(struct spi_device *spi, int value)
|
|
|
|
{
|
|
|
|
struct uwire_state *ust = spi->controller_state;
|
|
|
|
u16 w;
|
|
|
|
int old_cs;
|
|
|
|
|
|
|
|
|
|
|
|
BUG_ON(wait_uwire_csr_flag(CSRB, 0, 0));
|
|
|
|
|
|
|
|
w = uwire_read_reg(UWIRE_CSR);
|
|
|
|
old_cs = (w >> 10) & 0x03;
|
|
|
|
if (value == BITBANG_CS_INACTIVE || old_cs != spi->chip_select) {
|
|
|
|
/* Deselect this CS, or the previous CS */
|
|
|
|
w &= ~CS_CMD;
|
|
|
|
uwire_write_reg(UWIRE_CSR, w);
|
|
|
|
}
|
|
|
|
/* activate specfied chipselect */
|
|
|
|
if (value == BITBANG_CS_ACTIVE) {
|
|
|
|
uwire_set_clk1_div(ust->div1_idx);
|
|
|
|
/* invert clock? */
|
|
|
|
if (spi->mode & SPI_CPOL)
|
|
|
|
uwire_write_reg(UWIRE_SR4, 1);
|
|
|
|
else
|
|
|
|
uwire_write_reg(UWIRE_SR4, 0);
|
|
|
|
|
|
|
|
w = spi->chip_select << 10;
|
|
|
|
w |= CS_CMD;
|
|
|
|
uwire_write_reg(UWIRE_CSR, w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uwire_txrx(struct spi_device *spi, struct spi_transfer *t)
|
|
|
|
{
|
|
|
|
unsigned len = t->len;
|
2015-09-15 16:26:20 +03:00
|
|
|
unsigned bits = t->bits_per_word;
|
2007-02-12 11:52:37 +03:00
|
|
|
unsigned bytes;
|
|
|
|
u16 val, w;
|
2009-08-18 22:18:35 +04:00
|
|
|
int status = 0;
|
2007-02-12 11:52:37 +03:00
|
|
|
|
|
|
|
if (!t->tx_buf && !t->rx_buf)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
w = spi->chip_select << 10;
|
|
|
|
w |= CS_CMD;
|
|
|
|
|
|
|
|
if (t->tx_buf) {
|
|
|
|
const u8 *buf = t->tx_buf;
|
|
|
|
|
|
|
|
/* NOTE: DMA could be used for TX transfers */
|
|
|
|
|
|
|
|
/* write one or two bytes at a time */
|
|
|
|
while (len >= 1) {
|
|
|
|
/* tx bit 15 is first sent; we byteswap multibyte words
|
|
|
|
* (msb-first) on the way out from memory.
|
|
|
|
*/
|
|
|
|
val = *buf++;
|
|
|
|
if (bits > 8) {
|
|
|
|
bytes = 2;
|
|
|
|
val |= *buf++ << 8;
|
|
|
|
} else
|
|
|
|
bytes = 1;
|
|
|
|
val <<= 16 - bits;
|
|
|
|
|
|
|
|
#ifdef VERBOSE
|
|
|
|
pr_debug("%s: write-%d =%04x\n",
|
2009-03-25 02:38:21 +03:00
|
|
|
dev_name(&spi->dev), bits, val);
|
2007-02-12 11:52:37 +03:00
|
|
|
#endif
|
|
|
|
if (wait_uwire_csr_flag(CSRB, 0, 0))
|
|
|
|
goto eio;
|
|
|
|
|
|
|
|
uwire_write_reg(UWIRE_TDR, val);
|
|
|
|
|
|
|
|
/* start write */
|
|
|
|
val = START | w | (bits << 5);
|
|
|
|
|
|
|
|
uwire_write_reg(UWIRE_CSR, val);
|
|
|
|
len -= bytes;
|
|
|
|
|
|
|
|
/* Wait till write actually starts.
|
|
|
|
* This is needed with MPU clock 60+ MHz.
|
|
|
|
* REVISIT: we may not have time to catch it...
|
|
|
|
*/
|
|
|
|
if (wait_uwire_csr_flag(CSRB, CSRB, 1))
|
|
|
|
goto eio;
|
|
|
|
|
|
|
|
status += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* REVISIT: save this for later to get more i/o overlap */
|
|
|
|
if (wait_uwire_csr_flag(CSRB, 0, 0))
|
|
|
|
goto eio;
|
|
|
|
|
|
|
|
} else if (t->rx_buf) {
|
|
|
|
u8 *buf = t->rx_buf;
|
|
|
|
|
|
|
|
/* read one or two bytes at a time */
|
|
|
|
while (len) {
|
|
|
|
if (bits > 8) {
|
|
|
|
bytes = 2;
|
|
|
|
} else
|
|
|
|
bytes = 1;
|
|
|
|
|
|
|
|
/* start read */
|
|
|
|
val = START | w | (bits << 0);
|
|
|
|
uwire_write_reg(UWIRE_CSR, val);
|
|
|
|
len -= bytes;
|
|
|
|
|
|
|
|
/* Wait till read actually starts */
|
|
|
|
(void) wait_uwire_csr_flag(CSRB, CSRB, 1);
|
|
|
|
|
|
|
|
if (wait_uwire_csr_flag(RDRB | CSRB,
|
|
|
|
RDRB, 0))
|
|
|
|
goto eio;
|
|
|
|
|
|
|
|
/* rx bit 0 is last received; multibyte words will
|
|
|
|
* be properly byteswapped on the way to memory.
|
|
|
|
*/
|
|
|
|
val = uwire_read_reg(UWIRE_RDR);
|
|
|
|
val &= (1 << bits) - 1;
|
|
|
|
*buf++ = (u8) val;
|
|
|
|
if (bytes == 2)
|
|
|
|
*buf++ = val >> 8;
|
|
|
|
status += bytes;
|
|
|
|
#ifdef VERBOSE
|
|
|
|
pr_debug("%s: read-%d =%04x\n",
|
2009-03-25 02:38:21 +03:00
|
|
|
dev_name(&spi->dev), bits, val);
|
2007-02-12 11:52:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
eio:
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
|
|
|
|
{
|
|
|
|
struct uwire_state *ust = spi->controller_state;
|
|
|
|
struct uwire_spi *uwire;
|
|
|
|
unsigned flags = 0;
|
|
|
|
unsigned hz;
|
|
|
|
unsigned long rate;
|
|
|
|
int div1_idx;
|
|
|
|
int div1;
|
|
|
|
int div2;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
uwire = spi_master_get_devdata(spi->master);
|
|
|
|
|
|
|
|
/* mode 0..3, clock inverted separately;
|
|
|
|
* standard nCS signaling;
|
|
|
|
* don't treat DI=high as "not ready"
|
|
|
|
*/
|
|
|
|
if (spi->mode & SPI_CS_HIGH)
|
|
|
|
flags |= UWIRE_CS_ACTIVE_HIGH;
|
|
|
|
|
|
|
|
if (spi->mode & SPI_CPOL)
|
|
|
|
flags |= UWIRE_CLK_INVERTED;
|
|
|
|
|
|
|
|
switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {
|
|
|
|
case SPI_MODE_0:
|
|
|
|
case SPI_MODE_3:
|
2007-05-24 00:58:20 +04:00
|
|
|
flags |= UWIRE_WRITE_FALLING_EDGE | UWIRE_READ_RISING_EDGE;
|
2007-02-12 11:52:37 +03:00
|
|
|
break;
|
|
|
|
case SPI_MODE_1:
|
|
|
|
case SPI_MODE_2:
|
2007-05-24 00:58:20 +04:00
|
|
|
flags |= UWIRE_WRITE_RISING_EDGE | UWIRE_READ_FALLING_EDGE;
|
2007-02-12 11:52:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assume it's already enabled */
|
|
|
|
rate = clk_get_rate(uwire->ck);
|
|
|
|
|
2015-09-15 16:26:20 +03:00
|
|
|
if (t != NULL)
|
2007-02-12 11:52:37 +03:00
|
|
|
hz = t->speed_hz;
|
2015-09-15 16:26:20 +03:00
|
|
|
else
|
|
|
|
hz = spi->max_speed_hz;
|
2007-02-12 11:52:37 +03:00
|
|
|
|
|
|
|
if (!hz) {
|
2009-03-25 02:38:21 +03:00
|
|
|
pr_debug("%s: zero speed?\n", dev_name(&spi->dev));
|
2007-02-12 11:52:37 +03:00
|
|
|
status = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* F_INT = mpu_xor_clk / DIV1 */
|
|
|
|
for (div1_idx = 0; div1_idx < 4; div1_idx++) {
|
|
|
|
switch (div1_idx) {
|
|
|
|
case 0:
|
|
|
|
div1 = 2;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
div1 = 4;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
div1 = 7;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 3:
|
|
|
|
div1 = 10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
div2 = (rate / div1 + hz - 1) / hz;
|
|
|
|
if (div2 <= 8)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (div1_idx == 4) {
|
|
|
|
pr_debug("%s: lowest clock %ld, need %d\n",
|
2009-03-25 02:38:21 +03:00
|
|
|
dev_name(&spi->dev), rate / 10 / 8, hz);
|
2007-02-12 11:52:37 +03:00
|
|
|
status = -EDOM;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have to cache this and reset in uwire_chipselect as this is a
|
|
|
|
* global parameter and another uwire device can change it under
|
|
|
|
* us */
|
|
|
|
ust->div1_idx = div1_idx;
|
|
|
|
uwire_set_clk1_div(div1_idx);
|
|
|
|
|
|
|
|
rate /= div1;
|
|
|
|
|
|
|
|
switch (div2) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
flags |= UWIRE_FREQ_DIV_2;
|
|
|
|
rate /= 2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
flags |= UWIRE_FREQ_DIV_4;
|
|
|
|
rate /= 4;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
flags |= UWIRE_FREQ_DIV_8;
|
|
|
|
rate /= 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
omap_uwire_configure_mode(spi->chip_select, flags);
|
|
|
|
pr_debug("%s: uwire flags %02x, armxor %lu KHz, SCK %lu KHz\n",
|
2008-04-28 13:14:19 +04:00
|
|
|
__func__, flags,
|
2007-02-12 11:52:37 +03:00
|
|
|
clk_get_rate(uwire->ck) / 1000,
|
|
|
|
rate / 1000);
|
|
|
|
status = 0;
|
|
|
|
done:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int uwire_setup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct uwire_state *ust = spi->controller_state;
|
|
|
|
|
|
|
|
if (ust == NULL) {
|
|
|
|
ust = kzalloc(sizeof(*ust), GFP_KERNEL);
|
|
|
|
if (ust == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
spi->controller_state = ust;
|
|
|
|
}
|
|
|
|
|
|
|
|
return uwire_setup_transfer(spi, NULL);
|
|
|
|
}
|
|
|
|
|
2007-02-21 00:58:19 +03:00
|
|
|
static void uwire_cleanup(struct spi_device *spi)
|
2007-02-12 11:52:37 +03:00
|
|
|
{
|
|
|
|
kfree(spi->controller_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uwire_off(struct uwire_spi *uwire)
|
|
|
|
{
|
|
|
|
uwire_write_reg(UWIRE_SR3, 0);
|
2020-07-15 08:26:46 +03:00
|
|
|
clk_disable_unprepare(uwire->ck);
|
2007-02-12 11:52:37 +03:00
|
|
|
spi_master_put(uwire->bitbang.master);
|
|
|
|
}
|
|
|
|
|
2013-02-05 17:27:35 +04:00
|
|
|
static int uwire_probe(struct platform_device *pdev)
|
2007-02-12 11:52:37 +03:00
|
|
|
{
|
|
|
|
struct spi_master *master;
|
|
|
|
struct uwire_spi *uwire;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
master = spi_alloc_master(&pdev->dev, sizeof *uwire);
|
|
|
|
if (!master)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
uwire = spi_master_get_devdata(master);
|
2008-09-04 17:07:22 +04:00
|
|
|
|
2014-06-21 00:38:58 +04:00
|
|
|
uwire_base = devm_ioremap(&pdev->dev, UWIRE_BASE_PHYS, UWIRE_IO_SIZE);
|
2008-09-04 17:07:22 +04:00
|
|
|
if (!uwire_base) {
|
|
|
|
dev_dbg(&pdev->dev, "can't ioremap UWIRE\n");
|
|
|
|
spi_master_put(master);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2013-05-23 14:20:40 +04:00
|
|
|
platform_set_drvdata(pdev, uwire);
|
2007-02-12 11:52:37 +03:00
|
|
|
|
2014-06-21 00:38:58 +04:00
|
|
|
uwire->ck = devm_clk_get(&pdev->dev, "fck");
|
2009-01-22 22:41:20 +03:00
|
|
|
if (IS_ERR(uwire->ck)) {
|
|
|
|
status = PTR_ERR(uwire->ck);
|
|
|
|
dev_dbg(&pdev->dev, "no functional clock?\n");
|
2007-02-12 11:52:37 +03:00
|
|
|
spi_master_put(master);
|
2009-01-22 22:41:20 +03:00
|
|
|
return status;
|
2007-02-12 11:52:37 +03:00
|
|
|
}
|
2020-07-15 08:26:46 +03:00
|
|
|
clk_prepare_enable(uwire->ck);
|
2007-02-12 11:52:37 +03:00
|
|
|
|
2009-09-22 13:04:51 +04:00
|
|
|
if (cpu_is_omap7xx())
|
2007-02-12 11:52:37 +03:00
|
|
|
uwire_idx_shift = 1;
|
|
|
|
else
|
|
|
|
uwire_idx_shift = 2;
|
|
|
|
|
|
|
|
uwire_write_reg(UWIRE_SR3, 1);
|
|
|
|
|
2009-06-18 03:26:04 +04:00
|
|
|
/* the spi->mode bits understood by this driver: */
|
|
|
|
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
|
2014-02-15 10:26:21 +04:00
|
|
|
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 16);
|
2009-06-30 22:41:27 +04:00
|
|
|
master->flags = SPI_MASTER_HALF_DUPLEX;
|
|
|
|
|
2007-02-12 11:52:37 +03:00
|
|
|
master->bus_num = 2; /* "official" */
|
|
|
|
master->num_chipselect = 4;
|
|
|
|
master->setup = uwire_setup;
|
|
|
|
master->cleanup = uwire_cleanup;
|
|
|
|
|
|
|
|
uwire->bitbang.master = master;
|
|
|
|
uwire->bitbang.chipselect = uwire_chipselect;
|
|
|
|
uwire->bitbang.setup_transfer = uwire_setup_transfer;
|
|
|
|
uwire->bitbang.txrx_bufs = uwire_txrx;
|
|
|
|
|
|
|
|
status = spi_bitbang_start(&uwire->bitbang);
|
2008-09-04 17:07:22 +04:00
|
|
|
if (status < 0) {
|
2007-02-12 11:52:37 +03:00
|
|
|
uwire_off(uwire);
|
2008-09-04 17:07:22 +04:00
|
|
|
}
|
2007-02-12 11:52:37 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-02-05 17:27:35 +04:00
|
|
|
static int uwire_remove(struct platform_device *pdev)
|
2007-02-12 11:52:37 +03:00
|
|
|
{
|
2013-05-23 14:20:40 +04:00
|
|
|
struct uwire_spi *uwire = platform_get_drvdata(pdev);
|
2007-02-12 11:52:37 +03:00
|
|
|
|
|
|
|
// FIXME remove all child devices, somewhere ...
|
|
|
|
|
2014-03-29 14:50:12 +04:00
|
|
|
spi_bitbang_stop(&uwire->bitbang);
|
2007-02-12 11:52:37 +03:00
|
|
|
uwire_off(uwire);
|
2014-03-29 14:50:12 +04:00
|
|
|
return 0;
|
2007-02-12 11:52:37 +03:00
|
|
|
}
|
|
|
|
|
2008-04-11 08:29:20 +04:00
|
|
|
/* work with hotplug and coldplug */
|
|
|
|
MODULE_ALIAS("platform:omap_uwire");
|
|
|
|
|
2007-02-12 11:52:37 +03:00
|
|
|
static struct platform_driver uwire_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "omap_uwire",
|
|
|
|
},
|
2013-10-09 00:35:39 +04:00
|
|
|
.probe = uwire_probe,
|
|
|
|
.remove = uwire_remove,
|
2007-02-12 11:52:37 +03:00
|
|
|
// suspend ... unuse ck
|
|
|
|
// resume ... use ck
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init omap_uwire_init(void)
|
|
|
|
{
|
|
|
|
/* FIXME move these into the relevant board init code. also, include
|
|
|
|
* H3 support; it uses tsc2101 like H2 (on a different chipselect).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (machine_is_omap_h2()) {
|
|
|
|
/* defaults: W21 SDO, U18 SDI, V19 SCL */
|
|
|
|
omap_cfg_reg(N14_1610_UWIRE_CS0);
|
|
|
|
omap_cfg_reg(N15_1610_UWIRE_CS1);
|
|
|
|
}
|
|
|
|
if (machine_is_omap_perseus2()) {
|
|
|
|
/* configure pins: MPU_UW_nSCS1, MPU_UW_SDO, MPU_UW_SCLK */
|
2009-09-22 13:04:51 +04:00
|
|
|
int val = omap_readl(OMAP7XX_IO_CONF_9) & ~0x00EEE000;
|
|
|
|
omap_writel(val | 0x00AAA000, OMAP7XX_IO_CONF_9);
|
2007-02-12 11:52:37 +03:00
|
|
|
}
|
|
|
|
|
2013-10-09 00:35:39 +04:00
|
|
|
return platform_driver_register(&uwire_driver);
|
2007-02-12 11:52:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit omap_uwire_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&uwire_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(omap_uwire_init);
|
|
|
|
module_exit(omap_uwire_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|