2006-03-08 14:53:24 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
|
2013-01-22 17:26:32 +07:00
|
|
|
* Copyright (C) 2013, Intel Corporation
|
2006-03-08 14:53:24 +07:00
|
|
|
*
|
|
|
|
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/errno.h>
|
2013-04-08 17:19:33 +07:00
|
|
|
#include <linux/err.h>
|
2006-03-08 14:53:24 +07:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
2010-11-23 08:12:15 +07:00
|
|
|
#include <linux/spi/pxa2xx_spi.h>
|
2006-03-08 14:53:24 +07:00
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/delay.h>
|
2009-04-07 09:00:54 +07:00
|
|
|
#include <linux/gpio.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2013-01-22 17:26:27 +07:00
|
|
|
#include <linux/clk.h>
|
2013-01-22 17:26:30 +07:00
|
|
|
#include <linux/pm_runtime.h>
|
2013-01-22 17:26:33 +07:00
|
|
|
#include <linux/acpi.h>
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/delay.h>
|
|
|
|
|
2013-01-22 17:26:28 +07:00
|
|
|
#include "spi-pxa2xx.h"
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Stephen Street");
|
2007-12-11 06:49:25 +07:00
|
|
|
MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
|
2006-03-08 14:53:24 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-11 11:29:20 +07:00
|
|
|
MODULE_ALIAS("platform:pxa2xx-spi");
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
#define MAX_BUSES 3
|
|
|
|
|
2008-10-16 12:02:43 +07:00
|
|
|
#define TIMOUT_DFLT 1000
|
|
|
|
|
2008-02-24 06:23:40 +07:00
|
|
|
/*
|
|
|
|
* for testing SSCR1 changes that require SSP restart, basically
|
|
|
|
* everything except the service and interrupt enables, the pxa270 developer
|
|
|
|
* manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this
|
|
|
|
* list, but the PXA255 dev man says all bits without really meaning the
|
|
|
|
* service and interrupt enables
|
|
|
|
*/
|
|
|
|
#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
|
2006-12-10 17:18:54 +07:00
|
|
|
| SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
|
2008-02-24 06:23:40 +07:00
|
|
|
| SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
|
|
|
|
| SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
|
|
|
|
| SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
|
|
|
|
| SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
|
2006-12-10 17:18:54 +07:00
|
|
|
|
2013-01-22 17:26:32 +07:00
|
|
|
#define LPSS_RX_THRESH_DFLT 64
|
|
|
|
#define LPSS_TX_LOTHRESH_DFLT 160
|
|
|
|
#define LPSS_TX_HITHRESH_DFLT 224
|
|
|
|
|
|
|
|
/* Offset from drv_data->lpss_base */
|
2013-03-05 17:05:17 +07:00
|
|
|
#define SSP_REG 0x0c
|
2013-01-22 17:26:32 +07:00
|
|
|
#define SPI_CS_CONTROL 0x18
|
|
|
|
#define SPI_CS_CONTROL_SW_MODE BIT(0)
|
|
|
|
#define SPI_CS_CONTROL_CS_HIGH BIT(1)
|
|
|
|
|
|
|
|
static bool is_lpss_ssp(const struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
return drv_data->ssp_type == LPSS_SSP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read and write LPSS SSP private registers. Caller must first check that
|
|
|
|
* is_lpss_ssp() returns true before these can be called.
|
|
|
|
*/
|
|
|
|
static u32 __lpss_ssp_read_priv(struct driver_data *drv_data, unsigned offset)
|
|
|
|
{
|
|
|
|
WARN_ON(!drv_data->lpss_base);
|
|
|
|
return readl(drv_data->lpss_base + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __lpss_ssp_write_priv(struct driver_data *drv_data,
|
|
|
|
unsigned offset, u32 value)
|
|
|
|
{
|
|
|
|
WARN_ON(!drv_data->lpss_base);
|
|
|
|
writel(value, drv_data->lpss_base + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lpss_ssp_setup - perform LPSS SSP specific setup
|
|
|
|
* @drv_data: pointer to the driver private data
|
|
|
|
*
|
|
|
|
* Perform LPSS SSP specific setup. This function must be called first if
|
|
|
|
* one is going to use LPSS SSP private registers.
|
|
|
|
*/
|
|
|
|
static void lpss_ssp_setup(struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
unsigned offset = 0x400;
|
|
|
|
u32 value, orig;
|
|
|
|
|
|
|
|
if (!is_lpss_ssp(drv_data))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform auto-detection of the LPSS SSP private registers. They
|
|
|
|
* can be either at 1k or 2k offset from the base address.
|
|
|
|
*/
|
|
|
|
orig = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL);
|
|
|
|
|
|
|
|
value = orig | SPI_CS_CONTROL_SW_MODE;
|
|
|
|
writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL);
|
|
|
|
value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL);
|
|
|
|
if (value != (orig | SPI_CS_CONTROL_SW_MODE)) {
|
|
|
|
offset = 0x800;
|
|
|
|
goto detection_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
value &= ~SPI_CS_CONTROL_SW_MODE;
|
|
|
|
writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL);
|
|
|
|
value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL);
|
|
|
|
if (value != orig) {
|
|
|
|
offset = 0x800;
|
|
|
|
goto detection_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
detection_done:
|
|
|
|
/* Now set the LPSS base */
|
|
|
|
drv_data->lpss_base = drv_data->ioaddr + offset;
|
|
|
|
|
|
|
|
/* Enable software chip select control */
|
|
|
|
value = SPI_CS_CONTROL_SW_MODE | SPI_CS_CONTROL_CS_HIGH;
|
|
|
|
__lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value);
|
2013-03-05 17:05:17 +07:00
|
|
|
|
|
|
|
/* Enable multiblock DMA transfers */
|
|
|
|
if (drv_data->master_info->enable_dma)
|
|
|
|
__lpss_ssp_write_priv(drv_data, SSP_REG, 1);
|
2013-01-22 17:26:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable)
|
|
|
|
{
|
|
|
|
u32 value;
|
|
|
|
|
|
|
|
if (!is_lpss_ssp(drv_data))
|
|
|
|
return;
|
|
|
|
|
|
|
|
value = __lpss_ssp_read_priv(drv_data, SPI_CS_CONTROL);
|
|
|
|
if (enable)
|
|
|
|
value &= ~SPI_CS_CONTROL_CS_HIGH;
|
|
|
|
else
|
|
|
|
value |= SPI_CS_CONTROL_CS_HIGH;
|
|
|
|
__lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value);
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:00:54 +07:00
|
|
|
static void cs_assert(struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
struct chip_data *chip = drv_data->cur_chip;
|
|
|
|
|
2010-11-23 08:12:17 +07:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP) {
|
|
|
|
write_SSSR(drv_data->cur_chip->frm, drv_data->ioaddr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:00:54 +07:00
|
|
|
if (chip->cs_control) {
|
|
|
|
chip->cs_control(PXA2XX_CS_ASSERT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:32 +07:00
|
|
|
if (gpio_is_valid(chip->gpio_cs)) {
|
2009-04-07 09:00:54 +07:00
|
|
|
gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted);
|
2013-01-22 17:26:32 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpss_ssp_cs_control(drv_data, true);
|
2009-04-07 09:00:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cs_deassert(struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
struct chip_data *chip = drv_data->cur_chip;
|
|
|
|
|
2010-11-23 08:12:17 +07:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP)
|
|
|
|
return;
|
|
|
|
|
2009-04-07 09:00:54 +07:00
|
|
|
if (chip->cs_control) {
|
2009-04-09 08:48:03 +07:00
|
|
|
chip->cs_control(PXA2XX_CS_DEASSERT);
|
2009-04-07 09:00:54 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:32 +07:00
|
|
|
if (gpio_is_valid(chip->gpio_cs)) {
|
2009-04-07 09:00:54 +07:00
|
|
|
gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted);
|
2013-01-22 17:26:32 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpss_ssp_cs_control(drv_data, false);
|
2009-04-07 09:00:54 +07:00
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:28 +07:00
|
|
|
int pxa2xx_spi_flush(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
|
|
|
unsigned long limit = loops_per_jiffy << 1;
|
|
|
|
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
do {
|
|
|
|
while (read_SSSR(reg) & SSSR_RNE) {
|
|
|
|
read_SSDR(reg);
|
|
|
|
}
|
2009-04-22 02:24:46 +07:00
|
|
|
} while ((read_SSSR(reg) & SSSR_BSY) && --limit);
|
2010-11-23 08:12:17 +07:00
|
|
|
write_SSSR_CS(drv_data, SSSR_ROR);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static int null_writer(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-29 05:05:23 +07:00
|
|
|
u8 n_bytes = drv_data->n_bytes;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2010-11-23 08:12:15 +07:00
|
|
|
if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
|
2006-12-10 17:18:54 +07:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
write_SSDR(0, reg);
|
|
|
|
drv_data->tx += n_bytes;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static int null_reader(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-29 05:05:23 +07:00
|
|
|
u8 n_bytes = drv_data->n_bytes;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
while ((read_SSSR(reg) & SSSR_RNE)
|
2006-12-10 17:18:54 +07:00
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
2006-03-08 14:53:24 +07:00
|
|
|
read_SSDR(reg);
|
|
|
|
drv_data->rx += n_bytes;
|
|
|
|
}
|
2006-12-10 17:18:54 +07:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static int u8_writer(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2010-11-23 08:12:15 +07:00
|
|
|
if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
|
2006-12-10 17:18:54 +07:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
write_SSDR(*(u8 *)(drv_data->tx), reg);
|
|
|
|
++drv_data->tx;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static int u8_reader(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
while ((read_SSSR(reg) & SSSR_RNE)
|
2006-12-10 17:18:54 +07:00
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
2006-03-08 14:53:24 +07:00
|
|
|
*(u8 *)(drv_data->rx) = read_SSDR(reg);
|
|
|
|
++drv_data->rx;
|
|
|
|
}
|
2006-12-10 17:18:54 +07:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static int u16_writer(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2010-11-23 08:12:15 +07:00
|
|
|
if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
|
2006-12-10 17:18:54 +07:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
write_SSDR(*(u16 *)(drv_data->tx), reg);
|
|
|
|
drv_data->tx += 2;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static int u16_reader(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
while ((read_SSSR(reg) & SSSR_RNE)
|
2006-12-10 17:18:54 +07:00
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
2006-03-08 14:53:24 +07:00
|
|
|
*(u16 *)(drv_data->rx) = read_SSDR(reg);
|
|
|
|
drv_data->rx += 2;
|
|
|
|
}
|
2006-12-10 17:18:54 +07:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
2006-12-10 17:18:54 +07:00
|
|
|
|
|
|
|
static int u32_writer(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2010-11-23 08:12:15 +07:00
|
|
|
if (((read_SSSR(reg) & SSSR_TFL_MASK) == SSSR_TFL_MASK)
|
2006-12-10 17:18:54 +07:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
write_SSDR(*(u32 *)(drv_data->tx), reg);
|
|
|
|
drv_data->tx += 4;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static int u32_reader(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
while ((read_SSSR(reg) & SSSR_RNE)
|
2006-12-10 17:18:54 +07:00
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
2006-03-08 14:53:24 +07:00
|
|
|
*(u32 *)(drv_data->rx) = read_SSDR(reg);
|
|
|
|
drv_data->rx += 4;
|
|
|
|
}
|
2006-12-10 17:18:54 +07:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:28 +07:00
|
|
|
void *pxa2xx_spi_next_transfer(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
|
|
|
struct spi_message *msg = drv_data->cur_msg;
|
|
|
|
struct spi_transfer *trans = drv_data->cur_transfer;
|
|
|
|
|
|
|
|
/* Move to next transfer */
|
|
|
|
if (trans->transfer_list.next != &msg->transfers) {
|
|
|
|
drv_data->cur_transfer =
|
|
|
|
list_entry(trans->transfer_list.next,
|
|
|
|
struct spi_transfer,
|
|
|
|
transfer_list);
|
|
|
|
return RUNNING_STATE;
|
|
|
|
} else
|
|
|
|
return DONE_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* caller already set message->status; dma and pio irqs are blocked */
|
2006-05-21 05:00:19 +07:00
|
|
|
static void giveback(struct driver_data *drv_data)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
|
|
|
struct spi_transfer* last_transfer;
|
2006-05-21 05:00:19 +07:00
|
|
|
struct spi_message *msg;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-05-21 05:00:19 +07:00
|
|
|
msg = drv_data->cur_msg;
|
|
|
|
drv_data->cur_msg = NULL;
|
|
|
|
drv_data->cur_transfer = NULL;
|
|
|
|
|
|
|
|
last_transfer = list_entry(msg->transfers.prev,
|
2006-03-08 14:53:24 +07:00
|
|
|
struct spi_transfer,
|
|
|
|
transfer_list);
|
|
|
|
|
2008-09-13 16:33:17 +07:00
|
|
|
/* Delay if requested before any change in chip select */
|
|
|
|
if (last_transfer->delay_usecs)
|
|
|
|
udelay(last_transfer->delay_usecs);
|
|
|
|
|
|
|
|
/* Drop chip select UNLESS cs_change is true or we are returning
|
|
|
|
* a message with an error, or next message is for another chip
|
|
|
|
*/
|
2006-03-08 14:53:24 +07:00
|
|
|
if (!last_transfer->cs_change)
|
2009-04-07 09:00:54 +07:00
|
|
|
cs_deassert(drv_data);
|
2008-09-13 16:33:17 +07:00
|
|
|
else {
|
|
|
|
struct spi_message *next_msg;
|
|
|
|
|
|
|
|
/* Holding of cs was hinted, but we need to make sure
|
|
|
|
* the next message is for the same chip. Don't waste
|
|
|
|
* time with the following tests unless this was hinted.
|
|
|
|
*
|
|
|
|
* We cannot postpone this until pump_messages, because
|
|
|
|
* after calling msg->complete (below) the driver that
|
|
|
|
* sent the current message could be unloaded, which
|
|
|
|
* could invalidate the cs_control() callback...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get a pointer to the next message, if any */
|
2013-01-22 17:26:26 +07:00
|
|
|
next_msg = spi_get_next_queued_message(drv_data->master);
|
2008-09-13 16:33:17 +07:00
|
|
|
|
|
|
|
/* see if the next and current messages point
|
|
|
|
* to the same chip
|
|
|
|
*/
|
|
|
|
if (next_msg && next_msg->spi != msg->spi)
|
|
|
|
next_msg = NULL;
|
|
|
|
if (!next_msg || msg->state == ERROR_STATE)
|
2009-04-07 09:00:54 +07:00
|
|
|
cs_deassert(drv_data);
|
2008-09-13 16:33:17 +07:00
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2013-01-22 17:26:26 +07:00
|
|
|
spi_finalize_current_message(drv_data->master);
|
2009-04-07 09:00:54 +07:00
|
|
|
drv_data->cur_chip = NULL;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2010-11-23 08:12:17 +07:00
|
|
|
static void reset_sccr1(struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
|
|
|
struct chip_data *chip = drv_data->cur_chip;
|
|
|
|
u32 sccr1_reg;
|
|
|
|
|
|
|
|
sccr1_reg = read_SSCR1(reg) & ~drv_data->int_cr1;
|
|
|
|
sccr1_reg &= ~SSCR1_RFT;
|
|
|
|
sccr1_reg |= chip->threshold;
|
|
|
|
write_SSCR1(sccr1_reg, reg);
|
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static void int_error_stop(struct driver_data *drv_data, const char* msg)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Stop and reset SSP */
|
2010-11-23 08:12:17 +07:00
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
2010-11-23 08:12:17 +07:00
|
|
|
reset_sccr1(drv_data);
|
2010-11-23 08:12:17 +07:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2006-12-10 17:18:54 +07:00
|
|
|
write_SSTO(0, reg);
|
2013-01-22 17:26:28 +07:00
|
|
|
pxa2xx_spi_flush(drv_data);
|
2006-12-10 17:18:54 +07:00
|
|
|
write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
dev_err(&drv_data->pdev->dev, "%s\n", msg);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
drv_data->cur_msg->state = ERROR_STATE;
|
|
|
|
tasklet_schedule(&drv_data->pump_transfers);
|
|
|
|
}
|
2006-05-21 05:00:19 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static void int_transfer_complete(struct driver_data *drv_data)
|
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Stop SSP */
|
2010-11-23 08:12:17 +07:00
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
2010-11-23 08:12:17 +07:00
|
|
|
reset_sccr1(drv_data);
|
2010-11-23 08:12:17 +07:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2006-12-10 17:18:54 +07:00
|
|
|
write_SSTO(0, reg);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2011-03-31 08:57:33 +07:00
|
|
|
/* Update total byte transferred return count actual bytes read */
|
2006-12-10 17:18:54 +07:00
|
|
|
drv_data->cur_msg->actual_length += drv_data->len -
|
|
|
|
(drv_data->rx_end - drv_data->rx);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2008-09-13 16:33:17 +07:00
|
|
|
/* Transfer delays and chip select release are
|
|
|
|
* handled in pump_transfers or giveback
|
|
|
|
*/
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Move to next transfer */
|
2013-01-22 17:26:28 +07:00
|
|
|
drv_data->cur_msg->state = pxa2xx_spi_next_transfer(drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Schedule transfer tasklet */
|
|
|
|
tasklet_schedule(&drv_data->pump_transfers);
|
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
|
|
|
|
{
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ?
|
|
|
|
drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
u32 irq_status = read_SSSR(reg) & irq_mask;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
if (irq_status & SSSR_ROR) {
|
|
|
|
int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
if (irq_status & SSSR_TINT) {
|
|
|
|
write_SSSR(SSSR_TINT, reg);
|
|
|
|
if (drv_data->read(drv_data)) {
|
|
|
|
int_transfer_complete(drv_data);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Drain rx fifo, Fill tx fifo and prevent overruns */
|
|
|
|
do {
|
|
|
|
if (drv_data->read(drv_data)) {
|
|
|
|
int_transfer_complete(drv_data);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
} while (drv_data->write(drv_data));
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
if (drv_data->read(drv_data)) {
|
|
|
|
int_transfer_complete(drv_data);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
if (drv_data->tx == drv_data->tx_end) {
|
2010-11-23 08:12:17 +07:00
|
|
|
u32 bytes_left;
|
|
|
|
u32 sccr1_reg;
|
|
|
|
|
|
|
|
sccr1_reg = read_SSCR1(reg);
|
|
|
|
sccr1_reg &= ~SSCR1_TIE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PXA25x_SSP has no timeout, set up rx threshould for the
|
2011-03-31 08:57:33 +07:00
|
|
|
* remaining RX bytes.
|
2010-11-23 08:12:17 +07:00
|
|
|
*/
|
2010-11-23 08:12:17 +07:00
|
|
|
if (pxa25x_ssp_comp(drv_data)) {
|
2010-11-23 08:12:17 +07:00
|
|
|
|
|
|
|
sccr1_reg &= ~SSCR1_RFT;
|
|
|
|
|
|
|
|
bytes_left = drv_data->rx_end - drv_data->rx;
|
|
|
|
switch (drv_data->n_bytes) {
|
|
|
|
case 4:
|
|
|
|
bytes_left >>= 1;
|
|
|
|
case 2:
|
|
|
|
bytes_left >>= 1;
|
2006-12-10 17:18:54 +07:00
|
|
|
}
|
2010-11-23 08:12:17 +07:00
|
|
|
|
|
|
|
if (bytes_left > RX_THRESH_DFLT)
|
|
|
|
bytes_left = RX_THRESH_DFLT;
|
|
|
|
|
|
|
|
sccr1_reg |= SSCR1_RxTresh(bytes_left);
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
2010-11-23 08:12:17 +07:00
|
|
|
write_SSCR1(sccr1_reg, reg);
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-05-21 05:00:19 +07:00
|
|
|
/* We did something */
|
|
|
|
return IRQ_HANDLED;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
static irqreturn_t ssp_int(int irq, void *dev_id)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2006-10-07 02:00:58 +07:00
|
|
|
struct driver_data *drv_data = dev_id;
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2013-01-22 17:26:30 +07:00
|
|
|
u32 sccr1_reg;
|
2010-11-23 08:12:14 +07:00
|
|
|
u32 mask = drv_data->mask_sr;
|
|
|
|
u32 status;
|
|
|
|
|
2013-01-22 17:26:30 +07:00
|
|
|
/*
|
|
|
|
* The IRQ might be shared with other peripherals so we must first
|
|
|
|
* check that are we RPM suspended or not. If we are we assume that
|
|
|
|
* the IRQ was not for us (we shouldn't be RPM suspended when the
|
|
|
|
* interrupt is enabled).
|
|
|
|
*/
|
|
|
|
if (pm_runtime_suspended(&drv_data->pdev->dev))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
sccr1_reg = read_SSCR1(reg);
|
2010-11-23 08:12:14 +07:00
|
|
|
status = read_SSSR(reg);
|
|
|
|
|
|
|
|
/* Ignore possible writes if we don't need to write */
|
|
|
|
if (!(sccr1_reg & SSCR1_TIE))
|
|
|
|
mask &= ~SSSR_TFS;
|
|
|
|
|
|
|
|
if (!(status & mask))
|
|
|
|
return IRQ_NONE;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
if (!drv_data->cur_msg) {
|
2006-05-21 05:00:19 +07:00
|
|
|
|
|
|
|
write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
|
|
|
|
write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
|
2010-11-23 08:12:17 +07:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2006-05-21 05:00:19 +07:00
|
|
|
write_SSTO(0, reg);
|
2010-11-23 08:12:17 +07:00
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
2006-05-21 05:00:19 +07:00
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
dev_err(&drv_data->pdev->dev, "bad message state "
|
2006-12-10 17:18:54 +07:00
|
|
|
"in interrupt handler\n");
|
2006-05-21 05:00:19 +07:00
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
/* Never fail */
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return drv_data->transfer_handler(drv_data);
|
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:27 +07:00
|
|
|
static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
|
2007-11-21 17:50:53 +07:00
|
|
|
{
|
2013-01-22 17:26:27 +07:00
|
|
|
unsigned long ssp_clk = drv_data->max_clk_rate;
|
|
|
|
const struct ssp_device *ssp = drv_data->ssp;
|
|
|
|
|
|
|
|
rate = min_t(int, ssp_clk, rate);
|
2007-11-21 17:50:53 +07:00
|
|
|
|
2010-11-23 08:12:17 +07:00
|
|
|
if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
|
2007-11-21 17:50:53 +07:00
|
|
|
return ((ssp_clk / (2 * rate) - 1) & 0xff) << 8;
|
|
|
|
else
|
|
|
|
return ((ssp_clk / rate - 1) & 0xfff) << 8;
|
|
|
|
}
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
static void pump_transfers(unsigned long data)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = (struct driver_data *)data;
|
|
|
|
struct spi_message *message = NULL;
|
|
|
|
struct spi_transfer *transfer = NULL;
|
|
|
|
struct spi_transfer *previous = NULL;
|
|
|
|
struct chip_data *chip = NULL;
|
2008-04-28 16:14:17 +07:00
|
|
|
void __iomem *reg = drv_data->ioaddr;
|
2006-03-29 05:05:23 +07:00
|
|
|
u32 clk_div = 0;
|
|
|
|
u8 bits = 0;
|
|
|
|
u32 speed = 0;
|
|
|
|
u32 cr0;
|
2006-12-10 17:18:54 +07:00
|
|
|
u32 cr1;
|
|
|
|
u32 dma_thresh = drv_data->cur_chip->dma_threshold;
|
|
|
|
u32 dma_burst = drv_data->cur_chip->dma_burst_size;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
/* Get current state information */
|
|
|
|
message = drv_data->cur_msg;
|
|
|
|
transfer = drv_data->cur_transfer;
|
|
|
|
chip = drv_data->cur_chip;
|
|
|
|
|
|
|
|
/* Handle for abort */
|
|
|
|
if (message->state == ERROR_STATE) {
|
|
|
|
message->status = -EIO;
|
2006-05-21 05:00:19 +07:00
|
|
|
giveback(drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle end of message */
|
|
|
|
if (message->state == DONE_STATE) {
|
|
|
|
message->status = 0;
|
2006-05-21 05:00:19 +07:00
|
|
|
giveback(drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-13 16:33:17 +07:00
|
|
|
/* Delay if requested at end of transfer before CS change */
|
2006-03-08 14:53:24 +07:00
|
|
|
if (message->state == RUNNING_STATE) {
|
|
|
|
previous = list_entry(transfer->transfer_list.prev,
|
|
|
|
struct spi_transfer,
|
|
|
|
transfer_list);
|
|
|
|
if (previous->delay_usecs)
|
|
|
|
udelay(previous->delay_usecs);
|
2008-09-13 16:33:17 +07:00
|
|
|
|
|
|
|
/* Drop chip select only if cs_change is requested */
|
|
|
|
if (previous->cs_change)
|
2009-04-07 09:00:54 +07:00
|
|
|
cs_deassert(drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:28 +07:00
|
|
|
/* Check if we can DMA this transfer */
|
|
|
|
if (!pxa2xx_spi_dma_is_possible(transfer->len) && chip->enable_dma) {
|
2008-09-13 16:33:18 +07:00
|
|
|
|
|
|
|
/* reject already-mapped transfers; PIO won't always work */
|
|
|
|
if (message->is_dma_mapped
|
|
|
|
|| transfer->rx_dma || transfer->tx_dma) {
|
|
|
|
dev_err(&drv_data->pdev->dev,
|
|
|
|
"pump_transfers: mapped transfer length "
|
2008-10-02 00:39:24 +07:00
|
|
|
"of %u is greater than %d\n",
|
2008-09-13 16:33:18 +07:00
|
|
|
transfer->len, MAX_DMA_LEN);
|
|
|
|
message->status = -EINVAL;
|
|
|
|
giveback(drv_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* warn ... we force this to PIO mode */
|
|
|
|
if (printk_ratelimit())
|
|
|
|
dev_warn(&message->spi->dev, "pump_transfers: "
|
|
|
|
"DMA disabled for transfer length %ld "
|
|
|
|
"greater than %d\n",
|
|
|
|
(long)drv_data->len, MAX_DMA_LEN);
|
2006-12-10 17:18:54 +07:00
|
|
|
}
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
/* Setup the transfer state based on the type of transfer */
|
2013-01-22 17:26:28 +07:00
|
|
|
if (pxa2xx_spi_flush(drv_data) == 0) {
|
2006-03-08 14:53:24 +07:00
|
|
|
dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
|
|
|
|
message->status = -EIO;
|
2006-05-21 05:00:19 +07:00
|
|
|
giveback(drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
return;
|
|
|
|
}
|
2006-03-29 05:05:23 +07:00
|
|
|
drv_data->n_bytes = chip->n_bytes;
|
2006-03-08 14:53:24 +07:00
|
|
|
drv_data->tx = (void *)transfer->tx_buf;
|
|
|
|
drv_data->tx_end = drv_data->tx + transfer->len;
|
|
|
|
drv_data->rx = transfer->rx_buf;
|
|
|
|
drv_data->rx_end = drv_data->rx + transfer->len;
|
|
|
|
drv_data->rx_dma = transfer->rx_dma;
|
|
|
|
drv_data->tx_dma = transfer->tx_dma;
|
2013-01-22 17:26:28 +07:00
|
|
|
drv_data->len = transfer->len;
|
2006-03-08 14:53:24 +07:00
|
|
|
drv_data->write = drv_data->tx ? chip->write : null_writer;
|
|
|
|
drv_data->read = drv_data->rx ? chip->read : null_reader;
|
2006-03-29 05:05:23 +07:00
|
|
|
|
|
|
|
/* Change speed and bit per word on a per transfer */
|
2006-12-10 17:18:54 +07:00
|
|
|
cr0 = chip->cr0;
|
2006-03-29 05:05:23 +07:00
|
|
|
if (transfer->speed_hz || transfer->bits_per_word) {
|
|
|
|
|
|
|
|
bits = chip->bits_per_word;
|
|
|
|
speed = chip->speed_hz;
|
|
|
|
|
|
|
|
if (transfer->speed_hz)
|
|
|
|
speed = transfer->speed_hz;
|
|
|
|
|
|
|
|
if (transfer->bits_per_word)
|
|
|
|
bits = transfer->bits_per_word;
|
|
|
|
|
2013-01-22 17:26:27 +07:00
|
|
|
clk_div = ssp_get_clk_div(drv_data, speed);
|
2006-03-29 05:05:23 +07:00
|
|
|
|
|
|
|
if (bits <= 8) {
|
|
|
|
drv_data->n_bytes = 1;
|
|
|
|
drv_data->read = drv_data->read != null_reader ?
|
|
|
|
u8_reader : null_reader;
|
|
|
|
drv_data->write = drv_data->write != null_writer ?
|
|
|
|
u8_writer : null_writer;
|
|
|
|
} else if (bits <= 16) {
|
|
|
|
drv_data->n_bytes = 2;
|
|
|
|
drv_data->read = drv_data->read != null_reader ?
|
|
|
|
u16_reader : null_reader;
|
|
|
|
drv_data->write = drv_data->write != null_writer ?
|
|
|
|
u16_writer : null_writer;
|
|
|
|
} else if (bits <= 32) {
|
|
|
|
drv_data->n_bytes = 4;
|
|
|
|
drv_data->read = drv_data->read != null_reader ?
|
|
|
|
u32_reader : null_reader;
|
|
|
|
drv_data->write = drv_data->write != null_writer ?
|
|
|
|
u32_writer : null_writer;
|
|
|
|
}
|
2006-12-10 17:18:54 +07:00
|
|
|
/* if bits/word is changed in dma mode, then must check the
|
|
|
|
* thresholds and burst also */
|
|
|
|
if (chip->enable_dma) {
|
2013-01-22 17:26:28 +07:00
|
|
|
if (pxa2xx_spi_set_dma_burst_and_threshold(chip,
|
|
|
|
message->spi,
|
2006-12-10 17:18:54 +07:00
|
|
|
bits, &dma_burst,
|
|
|
|
&dma_thresh))
|
|
|
|
if (printk_ratelimit())
|
|
|
|
dev_warn(&message->spi->dev,
|
2008-09-13 16:33:18 +07:00
|
|
|
"pump_transfers: "
|
2006-12-10 17:18:54 +07:00
|
|
|
"DMA burst size reduced to "
|
|
|
|
"match bits_per_word\n");
|
|
|
|
}
|
2006-03-29 05:05:23 +07:00
|
|
|
|
|
|
|
cr0 = clk_div
|
|
|
|
| SSCR0_Motorola
|
2006-05-21 05:00:19 +07:00
|
|
|
| SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
|
2006-03-29 05:05:23 +07:00
|
|
|
| SSCR0_SSE
|
|
|
|
| (bits > 16 ? SSCR0_EDSS : 0);
|
|
|
|
}
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
message->state = RUNNING_STATE;
|
|
|
|
|
2008-09-13 16:33:18 +07:00
|
|
|
drv_data->dma_mapped = 0;
|
2013-01-22 17:26:28 +07:00
|
|
|
if (pxa2xx_spi_dma_is_possible(drv_data->len))
|
|
|
|
drv_data->dma_mapped = pxa2xx_spi_map_dma_buffers(drv_data);
|
2008-09-13 16:33:18 +07:00
|
|
|
if (drv_data->dma_mapped) {
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
/* Ensure we have the correct interrupt handler */
|
2013-01-22 17:26:28 +07:00
|
|
|
drv_data->transfer_handler = pxa2xx_spi_dma_transfer;
|
|
|
|
|
|
|
|
pxa2xx_spi_dma_prepare(drv_data, dma_burst);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Clear status and start DMA engine */
|
|
|
|
cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
|
2006-03-08 14:53:24 +07:00
|
|
|
write_SSSR(drv_data->clear_sr, reg);
|
2013-01-22 17:26:28 +07:00
|
|
|
|
|
|
|
pxa2xx_spi_dma_start(drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
} else {
|
|
|
|
/* Ensure we have the correct interrupt handler */
|
|
|
|
drv_data->transfer_handler = interrupt_transfer;
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Clear status */
|
|
|
|
cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
|
2010-11-23 08:12:17 +07:00
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
2006-12-10 17:18:54 +07:00
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:32 +07:00
|
|
|
if (is_lpss_ssp(drv_data)) {
|
|
|
|
if ((read_SSIRF(reg) & 0xff) != chip->lpss_rx_threshold)
|
|
|
|
write_SSIRF(chip->lpss_rx_threshold, reg);
|
|
|
|
if ((read_SSITF(reg) & 0xffff) != chip->lpss_tx_threshold)
|
|
|
|
write_SSITF(chip->lpss_tx_threshold, reg);
|
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* see if we need to reload the config registers */
|
|
|
|
if ((read_SSCR0(reg) != cr0)
|
|
|
|
|| (read_SSCR1(reg) & SSCR1_CHANGE_MASK) !=
|
|
|
|
(cr1 & SSCR1_CHANGE_MASK)) {
|
|
|
|
|
2008-02-24 06:23:40 +07:00
|
|
|
/* stop the SSP, and update the other bits */
|
2006-12-10 17:18:54 +07:00
|
|
|
write_SSCR0(cr0 & ~SSCR0_SSE, reg);
|
2010-11-23 08:12:17 +07:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2006-03-08 14:53:24 +07:00
|
|
|
write_SSTO(chip->timeout, reg);
|
2008-02-24 06:23:40 +07:00
|
|
|
/* first set CR1 without interrupt and service enables */
|
|
|
|
write_SSCR1(cr1 & SSCR1_CHANGE_MASK, reg);
|
|
|
|
/* restart the SSP */
|
2006-12-10 17:18:54 +07:00
|
|
|
write_SSCR0(cr0, reg);
|
2008-02-24 06:23:40 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
} else {
|
2010-11-23 08:12:17 +07:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2006-12-10 17:18:54 +07:00
|
|
|
write_SSTO(chip->timeout, reg);
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
2008-02-24 06:23:40 +07:00
|
|
|
|
2009-04-07 09:00:54 +07:00
|
|
|
cs_assert(drv_data);
|
2008-02-24 06:23:40 +07:00
|
|
|
|
|
|
|
/* after chip select, release the data by enabling service
|
|
|
|
* requests and interrupts, without changing any mode bits */
|
|
|
|
write_SSCR1(cr1, reg);
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:26 +07:00
|
|
|
static int pxa2xx_spi_transfer_one_message(struct spi_master *master,
|
|
|
|
struct spi_message *msg)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2013-01-22 17:26:26 +07:00
|
|
|
struct driver_data *drv_data = spi_master_get_devdata(master);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2013-01-22 17:26:26 +07:00
|
|
|
drv_data->cur_msg = msg;
|
2006-03-08 14:53:24 +07:00
|
|
|
/* Initial message state*/
|
|
|
|
drv_data->cur_msg->state = START_STATE;
|
|
|
|
drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
|
|
|
|
struct spi_transfer,
|
|
|
|
transfer_list);
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* prepare to setup the SSP, in pump_transfers, using the per
|
|
|
|
* chip configuration */
|
2006-03-08 14:53:24 +07:00
|
|
|
drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
|
|
|
|
|
|
|
|
/* Mark as busy and launch transfers */
|
|
|
|
tasklet_schedule(&drv_data->pump_transfers);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:30 +07:00
|
|
|
static int pxa2xx_spi_prepare_transfer(struct spi_master *master)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
pm_runtime_get_sync(&drv_data->pdev->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa2xx_spi_unprepare_transfer(struct spi_master *master)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
/* Disable the SSP now */
|
|
|
|
write_SSCR0(read_SSCR0(drv_data->ioaddr) & ~SSCR0_SSE,
|
|
|
|
drv_data->ioaddr);
|
|
|
|
|
|
|
|
pm_runtime_mark_last_busy(&drv_data->pdev->dev);
|
|
|
|
pm_runtime_put_autosuspend(&drv_data->pdev->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:00:54 +07:00
|
|
|
static int setup_cs(struct spi_device *spi, struct chip_data *chip,
|
|
|
|
struct pxa2xx_spi_chip *chip_info)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (chip == NULL || chip_info == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* NOTE: setup() can be called multiple times, possibly with
|
|
|
|
* different chip_info, release previously requested GPIO
|
|
|
|
*/
|
|
|
|
if (gpio_is_valid(chip->gpio_cs))
|
|
|
|
gpio_free(chip->gpio_cs);
|
|
|
|
|
|
|
|
/* If (*cs_control) is provided, ignore GPIO chip select */
|
|
|
|
if (chip_info->cs_control) {
|
|
|
|
chip->cs_control = chip_info->cs_control;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpio_is_valid(chip_info->gpio_cs)) {
|
|
|
|
err = gpio_request(chip_info->gpio_cs, "SPI_CS");
|
|
|
|
if (err) {
|
|
|
|
dev_err(&spi->dev, "failed to request chip select "
|
|
|
|
"GPIO%d\n", chip_info->gpio_cs);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->gpio_cs = chip_info->gpio_cs;
|
|
|
|
chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
|
|
|
|
|
|
|
|
err = gpio_direction_output(chip->gpio_cs,
|
|
|
|
!chip->gpio_cs_inverted);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
static int setup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct pxa2xx_spi_chip *chip_info = NULL;
|
|
|
|
struct chip_data *chip;
|
|
|
|
struct driver_data *drv_data = spi_master_get_devdata(spi->master);
|
|
|
|
unsigned int clk_div;
|
2013-01-22 17:26:32 +07:00
|
|
|
uint tx_thres, tx_hi_thres, rx_thres;
|
|
|
|
|
|
|
|
if (is_lpss_ssp(drv_data)) {
|
|
|
|
tx_thres = LPSS_TX_LOTHRESH_DFLT;
|
|
|
|
tx_hi_thres = LPSS_TX_HITHRESH_DFLT;
|
|
|
|
rx_thres = LPSS_RX_THRESH_DFLT;
|
|
|
|
} else {
|
|
|
|
tx_thres = TX_THRESH_DFLT;
|
|
|
|
tx_hi_thres = 0;
|
|
|
|
rx_thres = RX_THRESH_DFLT;
|
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* Only alloc on first setup */
|
2006-03-08 14:53:24 +07:00
|
|
|
chip = spi_get_ctldata(spi);
|
2006-12-10 17:18:54 +07:00
|
|
|
if (!chip) {
|
2006-03-08 14:53:24 +07:00
|
|
|
chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
|
2006-12-10 17:18:54 +07:00
|
|
|
if (!chip) {
|
|
|
|
dev_err(&spi->dev,
|
|
|
|
"failed setup: can't allocate chip data\n");
|
2006-03-08 14:53:24 +07:00
|
|
|
return -ENOMEM;
|
2006-12-10 17:18:54 +07:00
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2010-11-23 08:12:17 +07:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP) {
|
|
|
|
if (spi->chip_select > 4) {
|
|
|
|
dev_err(&spi->dev, "failed setup: "
|
|
|
|
"cs number must not be > 4.\n");
|
|
|
|
kfree(chip);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->frm = spi->chip_select;
|
|
|
|
} else
|
|
|
|
chip->gpio_cs = -1;
|
2006-03-08 14:53:24 +07:00
|
|
|
chip->enable_dma = 0;
|
2008-10-16 12:02:43 +07:00
|
|
|
chip->timeout = TIMOUT_DFLT;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* protocol drivers may change the chip settings, so...
|
|
|
|
* if chip_info exists, use it */
|
|
|
|
chip_info = spi->controller_data;
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
/* chip_info isn't always needed */
|
2006-12-10 17:18:54 +07:00
|
|
|
chip->cr1 = 0;
|
2006-03-08 14:53:24 +07:00
|
|
|
if (chip_info) {
|
2008-10-16 12:02:43 +07:00
|
|
|
if (chip_info->timeout)
|
|
|
|
chip->timeout = chip_info->timeout;
|
|
|
|
if (chip_info->tx_threshold)
|
|
|
|
tx_thres = chip_info->tx_threshold;
|
2013-01-22 17:26:32 +07:00
|
|
|
if (chip_info->tx_hi_threshold)
|
|
|
|
tx_hi_thres = chip_info->tx_hi_threshold;
|
2008-10-16 12:02:43 +07:00
|
|
|
if (chip_info->rx_threshold)
|
|
|
|
rx_thres = chip_info->rx_threshold;
|
|
|
|
chip->enable_dma = drv_data->master_info->enable_dma;
|
2006-03-08 14:53:24 +07:00
|
|
|
chip->dma_threshold = 0;
|
|
|
|
if (chip_info->enable_loopback)
|
|
|
|
chip->cr1 = SSCR1_LBM;
|
2013-01-22 17:26:33 +07:00
|
|
|
} else if (ACPI_HANDLE(&spi->dev)) {
|
|
|
|
/*
|
|
|
|
* Slave devices enumerated from ACPI namespace don't
|
|
|
|
* usually have chip_info but we still might want to use
|
|
|
|
* DMA with them.
|
|
|
|
*/
|
|
|
|
chip->enable_dma = drv_data->master_info->enable_dma;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2008-10-16 12:02:43 +07:00
|
|
|
chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
|
|
|
|
(SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
|
|
|
|
|
2013-01-22 17:26:32 +07:00
|
|
|
chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
|
|
|
|
chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
|
|
|
|
| SSITF_TxHiThresh(tx_hi_thres);
|
|
|
|
|
2006-12-10 17:18:54 +07:00
|
|
|
/* set dma burst and threshold outside of chip_info path so that if
|
|
|
|
* chip_info goes away after setting chip->enable_dma, the
|
|
|
|
* burst and threshold can still respond to changes in bits_per_word */
|
|
|
|
if (chip->enable_dma) {
|
|
|
|
/* set up legal burst and threshold for dma */
|
2013-01-22 17:26:28 +07:00
|
|
|
if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,
|
|
|
|
spi->bits_per_word,
|
2006-12-10 17:18:54 +07:00
|
|
|
&chip->dma_burst_size,
|
|
|
|
&chip->dma_threshold)) {
|
|
|
|
dev_warn(&spi->dev, "in setup: DMA burst size reduced "
|
|
|
|
"to match bits_per_word\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:27 +07:00
|
|
|
clk_div = ssp_get_clk_div(drv_data, spi->max_speed_hz);
|
2006-03-29 05:05:23 +07:00
|
|
|
chip->speed_hz = spi->max_speed_hz;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
chip->cr0 = clk_div
|
|
|
|
| SSCR0_Motorola
|
2006-05-21 05:00:19 +07:00
|
|
|
| SSCR0_DataSize(spi->bits_per_word > 16 ?
|
|
|
|
spi->bits_per_word - 16 : spi->bits_per_word)
|
2006-03-08 14:53:24 +07:00
|
|
|
| SSCR0_SSE
|
|
|
|
| (spi->bits_per_word > 16 ? SSCR0_EDSS : 0);
|
2007-01-26 15:56:44 +07:00
|
|
|
chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
|
|
|
|
chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
|
|
|
|
| (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2013-01-22 17:26:31 +07:00
|
|
|
if (spi->mode & SPI_LOOP)
|
|
|
|
chip->cr1 |= SSCR1_LBM;
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
/* NOTE: PXA25x_SSP _could_ use external clocking ... */
|
2010-11-23 08:12:17 +07:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2009-06-18 06:26:03 +07:00
|
|
|
dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
|
2013-01-22 17:26:27 +07:00
|
|
|
drv_data->max_clk_rate
|
2010-03-16 15:48:01 +07:00
|
|
|
/ (1 + ((chip->cr0 & SSCR0_SCR(0xfff)) >> 8)),
|
|
|
|
chip->enable_dma ? "DMA" : "PIO");
|
2006-03-08 14:53:24 +07:00
|
|
|
else
|
2009-06-18 06:26:03 +07:00
|
|
|
dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
|
2013-01-22 17:26:27 +07:00
|
|
|
drv_data->max_clk_rate / 2
|
2010-03-16 15:48:01 +07:00
|
|
|
/ (1 + ((chip->cr0 & SSCR0_SCR(0x0ff)) >> 8)),
|
|
|
|
chip->enable_dma ? "DMA" : "PIO");
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
if (spi->bits_per_word <= 8) {
|
|
|
|
chip->n_bytes = 1;
|
|
|
|
chip->read = u8_reader;
|
|
|
|
chip->write = u8_writer;
|
|
|
|
} else if (spi->bits_per_word <= 16) {
|
|
|
|
chip->n_bytes = 2;
|
|
|
|
chip->read = u16_reader;
|
|
|
|
chip->write = u16_writer;
|
|
|
|
} else if (spi->bits_per_word <= 32) {
|
|
|
|
chip->cr0 |= SSCR0_EDSS;
|
|
|
|
chip->n_bytes = 4;
|
|
|
|
chip->read = u32_reader;
|
|
|
|
chip->write = u32_writer;
|
|
|
|
}
|
2006-03-29 05:05:23 +07:00
|
|
|
chip->bits_per_word = spi->bits_per_word;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
spi_set_ctldata(spi, chip);
|
|
|
|
|
2010-11-23 08:12:17 +07:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP)
|
|
|
|
return 0;
|
|
|
|
|
2009-04-07 09:00:54 +07:00
|
|
|
return setup_cs(spi, chip, chip_info);
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2007-02-12 15:52:45 +07:00
|
|
|
static void cleanup(struct spi_device *spi)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2007-02-12 15:52:45 +07:00
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
2010-11-23 08:12:17 +07:00
|
|
|
struct driver_data *drv_data = spi_master_get_devdata(spi->master);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2009-05-13 03:19:36 +07:00
|
|
|
if (!chip)
|
|
|
|
return;
|
|
|
|
|
2010-11-23 08:12:17 +07:00
|
|
|
if (drv_data->ssp_type != CE4100_SSP && gpio_is_valid(chip->gpio_cs))
|
2009-04-07 09:00:54 +07:00
|
|
|
gpio_free(chip->gpio_cs);
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
kfree(chip);
|
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:33 +07:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
static struct pxa2xx_spi_master *
|
|
|
|
pxa2xx_spi_acpi_get_pdata(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct pxa2xx_spi_master *pdata;
|
|
|
|
struct acpi_device *adev;
|
|
|
|
struct ssp_device *ssp;
|
|
|
|
struct resource *res;
|
|
|
|
int devid;
|
|
|
|
|
|
|
|
if (!ACPI_HANDLE(&pdev->dev) ||
|
|
|
|
acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev))
|
|
|
|
return NULL;
|
|
|
|
|
2013-06-20 21:44:22 +07:00
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
2013-01-22 17:26:33 +07:00
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"failed to allocate memory for platform data\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ssp = &pdata->ssp;
|
|
|
|
|
|
|
|
ssp->phys_base = res->start;
|
2013-04-08 17:19:33 +07:00
|
|
|
ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(ssp->mmio_base))
|
2013-05-13 17:45:09 +07:00
|
|
|
return NULL;
|
2013-01-22 17:26:33 +07:00
|
|
|
|
|
|
|
ssp->clk = devm_clk_get(&pdev->dev, NULL);
|
|
|
|
ssp->irq = platform_get_irq(pdev, 0);
|
|
|
|
ssp->type = LPSS_SSP;
|
|
|
|
ssp->pdev = pdev;
|
|
|
|
|
|
|
|
ssp->port_id = -1;
|
|
|
|
if (adev->pnp.unique_id && !kstrtoint(adev->pnp.unique_id, 0, &devid))
|
|
|
|
ssp->port_id = devid;
|
|
|
|
|
|
|
|
pdata->num_chipselect = 1;
|
2013-05-13 17:45:10 +07:00
|
|
|
pdata->enable_dma = true;
|
2013-01-22 17:26:33 +07:00
|
|
|
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct acpi_device_id pxa2xx_spi_acpi_match[] = {
|
|
|
|
{ "INT33C0", 0 },
|
|
|
|
{ "INT33C1", 0 },
|
2013-05-13 17:45:11 +07:00
|
|
|
{ "80860F0E", 0 },
|
2013-01-22 17:26:33 +07:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match);
|
|
|
|
#else
|
|
|
|
static inline struct pxa2xx_spi_master *
|
|
|
|
pxa2xx_spi_acpi_get_pdata(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-07 23:57:14 +07:00
|
|
|
static int pxa2xx_spi_probe(struct platform_device *pdev)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct pxa2xx_spi_master *platform_info;
|
|
|
|
struct spi_master *master;
|
2008-10-16 12:02:42 +07:00
|
|
|
struct driver_data *drv_data;
|
2007-11-21 17:50:53 +07:00
|
|
|
struct ssp_device *ssp;
|
2008-10-16 12:02:42 +07:00
|
|
|
int status;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2013-01-07 17:44:33 +07:00
|
|
|
platform_info = dev_get_platdata(dev);
|
|
|
|
if (!platform_info) {
|
2013-01-22 17:26:33 +07:00
|
|
|
platform_info = pxa2xx_spi_acpi_get_pdata(pdev);
|
|
|
|
if (!platform_info) {
|
|
|
|
dev_err(&pdev->dev, "missing platform data\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2013-01-07 17:44:33 +07:00
|
|
|
}
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2010-05-05 21:11:15 +07:00
|
|
|
ssp = pxa_ssp_request(pdev->id, pdev->name);
|
2013-01-07 17:44:33 +07:00
|
|
|
if (!ssp)
|
|
|
|
ssp = &platform_info->ssp;
|
|
|
|
|
|
|
|
if (!ssp->mmio_base) {
|
|
|
|
dev_err(&pdev->dev, "failed to get ssp\n");
|
2006-03-08 14:53:24 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate master with space for drv_data and null dma buffer */
|
|
|
|
master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
|
|
|
|
if (!master) {
|
2008-10-16 12:02:42 +07:00
|
|
|
dev_err(&pdev->dev, "cannot alloc spi_master\n");
|
2010-05-05 21:11:15 +07:00
|
|
|
pxa_ssp_free(ssp);
|
2006-03-08 14:53:24 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
drv_data = spi_master_get_devdata(master);
|
|
|
|
drv_data->master = master;
|
|
|
|
drv_data->master_info = platform_info;
|
|
|
|
drv_data->pdev = pdev;
|
2007-11-21 17:50:53 +07:00
|
|
|
drv_data->ssp = ssp;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2010-10-08 23:11:19 +07:00
|
|
|
master->dev.parent = &pdev->dev;
|
|
|
|
master->dev.of_node = pdev->dev.of_node;
|
2009-06-18 06:26:04 +07:00
|
|
|
/* the spi->mode bits understood by this driver: */
|
2013-01-22 17:26:31 +07:00
|
|
|
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
|
2009-06-18 06:26:04 +07:00
|
|
|
|
2013-01-07 17:44:33 +07:00
|
|
|
master->bus_num = ssp->port_id;
|
2006-03-08 14:53:24 +07:00
|
|
|
master->num_chipselect = platform_info->num_chipselect;
|
2009-04-07 09:00:57 +07:00
|
|
|
master->dma_alignment = DMA_ALIGNMENT;
|
2006-03-08 14:53:24 +07:00
|
|
|
master->cleanup = cleanup;
|
|
|
|
master->setup = setup;
|
2013-01-22 17:26:26 +07:00
|
|
|
master->transfer_one_message = pxa2xx_spi_transfer_one_message;
|
2013-01-22 17:26:30 +07:00
|
|
|
master->prepare_transfer_hardware = pxa2xx_spi_prepare_transfer;
|
|
|
|
master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2007-11-21 17:50:53 +07:00
|
|
|
drv_data->ssp_type = ssp->type;
|
2013-01-22 17:26:25 +07:00
|
|
|
drv_data->null_dma_buf = (u32 *)PTR_ALIGN(&drv_data[1], DMA_ALIGNMENT);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2007-11-21 17:50:53 +07:00
|
|
|
drv_data->ioaddr = ssp->mmio_base;
|
|
|
|
drv_data->ssdr_physical = ssp->phys_base + SSDR;
|
2010-11-23 08:12:17 +07:00
|
|
|
if (pxa25x_ssp_comp(drv_data)) {
|
2013-05-22 09:36:35 +07:00
|
|
|
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
|
2006-03-08 14:53:24 +07:00
|
|
|
drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
|
|
|
|
drv_data->dma_cr1 = 0;
|
|
|
|
drv_data->clear_sr = SSSR_ROR;
|
|
|
|
drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
|
|
|
|
} else {
|
2013-05-22 09:36:35 +07:00
|
|
|
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
|
2006-03-08 14:53:24 +07:00
|
|
|
drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
|
2013-01-22 17:26:29 +07:00
|
|
|
drv_data->dma_cr1 = DEFAULT_DMA_CR1;
|
2006-03-08 14:53:24 +07:00
|
|
|
drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
|
|
|
|
drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
|
|
|
|
}
|
|
|
|
|
2010-11-23 08:12:14 +07:00
|
|
|
status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
|
|
|
|
drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
if (status < 0) {
|
2008-10-16 12:02:42 +07:00
|
|
|
dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
|
2006-03-08 14:53:24 +07:00
|
|
|
goto out_error_master_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup DMA if requested */
|
|
|
|
drv_data->tx_channel = -1;
|
|
|
|
drv_data->rx_channel = -1;
|
|
|
|
if (platform_info->enable_dma) {
|
2013-01-22 17:26:28 +07:00
|
|
|
status = pxa2xx_spi_dma_setup(drv_data);
|
|
|
|
if (status) {
|
2013-05-13 17:45:10 +07:00
|
|
|
dev_dbg(dev, "no DMA channels available, using PIO\n");
|
2013-01-22 17:26:28 +07:00
|
|
|
platform_info->enable_dma = false;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable SOC clock */
|
2013-01-22 17:26:27 +07:00
|
|
|
clk_prepare_enable(ssp->clk);
|
|
|
|
|
|
|
|
drv_data->max_clk_rate = clk_get_rate(ssp->clk);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
/* Load default SSP configuration */
|
|
|
|
write_SSCR0(0, drv_data->ioaddr);
|
2008-10-16 12:02:43 +07:00
|
|
|
write_SSCR1(SSCR1_RxTresh(RX_THRESH_DFLT) |
|
|
|
|
SSCR1_TxTresh(TX_THRESH_DFLT),
|
|
|
|
drv_data->ioaddr);
|
2010-03-16 15:48:01 +07:00
|
|
|
write_SSCR0(SSCR0_SCR(2)
|
2006-03-08 14:53:24 +07:00
|
|
|
| SSCR0_Motorola
|
|
|
|
| SSCR0_DataSize(8),
|
|
|
|
drv_data->ioaddr);
|
2010-11-23 08:12:17 +07:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2006-03-08 14:53:24 +07:00
|
|
|
write_SSTO(0, drv_data->ioaddr);
|
|
|
|
write_SSPSP(0, drv_data->ioaddr);
|
|
|
|
|
2013-01-22 17:26:32 +07:00
|
|
|
lpss_ssp_setup(drv_data);
|
|
|
|
|
2013-01-22 17:26:26 +07:00
|
|
|
tasklet_init(&drv_data->pump_transfers, pump_transfers,
|
|
|
|
(unsigned long)drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
/* Register with the SPI framework */
|
|
|
|
platform_set_drvdata(pdev, drv_data);
|
|
|
|
status = spi_register_master(master);
|
|
|
|
if (status != 0) {
|
|
|
|
dev_err(&pdev->dev, "problem registering spi master\n");
|
2013-01-22 17:26:26 +07:00
|
|
|
goto out_error_clock_enabled;
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
|
|
|
|
2013-01-22 17:26:30 +07:00
|
|
|
pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
|
|
|
|
pm_runtime_use_autosuspend(&pdev->dev);
|
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
return status;
|
|
|
|
|
|
|
|
out_error_clock_enabled:
|
2013-01-22 17:26:27 +07:00
|
|
|
clk_disable_unprepare(ssp->clk);
|
2013-01-22 17:26:28 +07:00
|
|
|
pxa2xx_spi_dma_release(drv_data);
|
2007-11-21 17:50:53 +07:00
|
|
|
free_irq(ssp->irq, drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
out_error_master_alloc:
|
|
|
|
spi_master_put(master);
|
2010-05-05 21:11:15 +07:00
|
|
|
pxa_ssp_free(ssp);
|
2006-03-08 14:53:24 +07:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa2xx_spi_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = platform_get_drvdata(pdev);
|
2009-01-07 05:41:45 +07:00
|
|
|
struct ssp_device *ssp;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
if (!drv_data)
|
|
|
|
return 0;
|
2009-01-07 05:41:45 +07:00
|
|
|
ssp = drv_data->ssp;
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2013-01-22 17:26:30 +07:00
|
|
|
pm_runtime_get_sync(&pdev->dev);
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
/* Disable the SSP at the peripheral and SOC level */
|
|
|
|
write_SSCR0(0, drv_data->ioaddr);
|
2013-01-22 17:26:27 +07:00
|
|
|
clk_disable_unprepare(ssp->clk);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
/* Release DMA */
|
2013-01-22 17:26:28 +07:00
|
|
|
if (drv_data->master_info->enable_dma)
|
|
|
|
pxa2xx_spi_dma_release(drv_data);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
2013-01-22 17:26:30 +07:00
|
|
|
pm_runtime_put_noidle(&pdev->dev);
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
/* Release IRQ */
|
2007-11-21 17:50:53 +07:00
|
|
|
free_irq(ssp->irq, drv_data);
|
|
|
|
|
|
|
|
/* Release SSP */
|
2010-05-05 21:11:15 +07:00
|
|
|
pxa_ssp_free(ssp);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
/* Disconnect from the SPI framework */
|
|
|
|
spi_unregister_master(drv_data->master);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_spi_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
if ((status = pxa2xx_spi_remove(pdev)) != 0)
|
|
|
|
dev_err(&pdev->dev, "shutdown failed with %d\n", status);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2009-07-21 21:50:16 +07:00
|
|
|
static int pxa2xx_spi_suspend(struct device *dev)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2009-07-21 21:50:16 +07:00
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
2007-11-21 17:50:53 +07:00
|
|
|
struct ssp_device *ssp = drv_data->ssp;
|
2006-03-08 14:53:24 +07:00
|
|
|
int status = 0;
|
|
|
|
|
2013-01-22 17:26:26 +07:00
|
|
|
status = spi_master_suspend(drv_data->master);
|
2006-03-08 14:53:24 +07:00
|
|
|
if (status != 0)
|
|
|
|
return status;
|
|
|
|
write_SSCR0(0, drv_data->ioaddr);
|
2013-01-22 17:26:27 +07:00
|
|
|
clk_disable_unprepare(ssp->clk);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-21 21:50:16 +07:00
|
|
|
static int pxa2xx_spi_resume(struct device *dev)
|
2006-03-08 14:53:24 +07:00
|
|
|
{
|
2009-07-21 21:50:16 +07:00
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
2007-11-21 17:50:53 +07:00
|
|
|
struct ssp_device *ssp = drv_data->ssp;
|
2006-03-08 14:53:24 +07:00
|
|
|
int status = 0;
|
|
|
|
|
2013-01-22 17:26:28 +07:00
|
|
|
pxa2xx_spi_dma_resume(drv_data);
|
2009-04-22 02:24:43 +07:00
|
|
|
|
2006-03-08 14:53:24 +07:00
|
|
|
/* Enable the SSP clock */
|
2013-01-22 17:26:27 +07:00
|
|
|
clk_prepare_enable(ssp->clk);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
/* Start the queue running */
|
2013-01-22 17:26:26 +07:00
|
|
|
status = spi_master_resume(drv_data->master);
|
2006-03-08 14:53:24 +07:00
|
|
|
if (status != 0) {
|
2009-07-21 21:50:16 +07:00
|
|
|
dev_err(dev, "problem starting queue (%d)\n", status);
|
2006-03-08 14:53:24 +07:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-01-22 17:26:30 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_RUNTIME
|
|
|
|
static int pxa2xx_spi_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_disable_unprepare(drv_data->ssp->clk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa2xx_spi_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_prepare_enable(drv_data->ssp->clk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2009-07-21 21:50:16 +07:00
|
|
|
|
2009-12-15 09:00:08 +07:00
|
|
|
static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
|
2013-01-22 17:26:30 +07:00
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume)
|
|
|
|
SET_RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend,
|
|
|
|
pxa2xx_spi_runtime_resume, NULL)
|
2009-07-21 21:50:16 +07:00
|
|
|
};
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
static struct platform_driver driver = {
|
|
|
|
.driver = {
|
2009-07-21 21:50:16 +07:00
|
|
|
.name = "pxa2xx-spi",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.pm = &pxa2xx_spi_pm_ops,
|
2013-01-22 17:26:33 +07:00
|
|
|
.acpi_match_table = ACPI_PTR(pxa2xx_spi_acpi_match),
|
2006-03-08 14:53:24 +07:00
|
|
|
},
|
2010-11-20 00:00:11 +07:00
|
|
|
.probe = pxa2xx_spi_probe,
|
2007-10-16 15:27:46 +07:00
|
|
|
.remove = pxa2xx_spi_remove,
|
2006-03-08 14:53:24 +07:00
|
|
|
.shutdown = pxa2xx_spi_shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pxa2xx_spi_init(void)
|
|
|
|
{
|
2010-11-20 00:00:11 +07:00
|
|
|
return platform_driver_register(&driver);
|
2006-03-08 14:53:24 +07:00
|
|
|
}
|
2009-09-23 06:46:10 +07:00
|
|
|
subsys_initcall(pxa2xx_spi_init);
|
2006-03-08 14:53:24 +07:00
|
|
|
|
|
|
|
static void __exit pxa2xx_spi_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&driver);
|
|
|
|
}
|
|
|
|
module_exit(pxa2xx_spi_exit);
|