2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-12-13 16:02:11 +08:00
|
|
|
/*
|
|
|
|
* OMAP7xx SPI 100k controller driver
|
|
|
|
* Author: Fabrice Crohas <fcrohas@gmail.com>
|
|
|
|
* from original omap1_mcspi driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005, 2006 Nokia Corporation
|
|
|
|
* Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
|
2021-05-19 16:15:36 +08:00
|
|
|
* Juha Yrjola <juha.yrjola@nokia.com>
|
2009-12-13 16:02:11 +08:00
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/platform_device.h>
|
2014-12-11 02:16:25 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2009-12-13 16:02:11 +08:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/io.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
|
|
|
|
#define OMAP1_SPI100K_MAX_FREQ 48000000
|
|
|
|
|
|
|
|
#define ICR_SPITAS (OMAP7XX_ICR_BASE + 0x12)
|
|
|
|
|
|
|
|
#define SPI_SETUP1 0x00
|
|
|
|
#define SPI_SETUP2 0x02
|
|
|
|
#define SPI_CTRL 0x04
|
|
|
|
#define SPI_STATUS 0x06
|
|
|
|
#define SPI_TX_LSB 0x08
|
|
|
|
#define SPI_TX_MSB 0x0a
|
|
|
|
#define SPI_RX_LSB 0x0c
|
|
|
|
#define SPI_RX_MSB 0x0e
|
|
|
|
|
|
|
|
#define SPI_SETUP1_INT_READ_ENABLE (1UL << 5)
|
|
|
|
#define SPI_SETUP1_INT_WRITE_ENABLE (1UL << 4)
|
|
|
|
#define SPI_SETUP1_CLOCK_DIVISOR(x) ((x) << 1)
|
|
|
|
#define SPI_SETUP1_CLOCK_ENABLE (1UL << 0)
|
|
|
|
|
|
|
|
#define SPI_SETUP2_ACTIVE_EDGE_FALLING (0UL << 0)
|
|
|
|
#define SPI_SETUP2_ACTIVE_EDGE_RISING (1UL << 0)
|
|
|
|
#define SPI_SETUP2_NEGATIVE_LEVEL (0UL << 5)
|
|
|
|
#define SPI_SETUP2_POSITIVE_LEVEL (1UL << 5)
|
|
|
|
#define SPI_SETUP2_LEVEL_TRIGGER (0UL << 10)
|
|
|
|
#define SPI_SETUP2_EDGE_TRIGGER (1UL << 10)
|
|
|
|
|
|
|
|
#define SPI_CTRL_SEN(x) ((x) << 7)
|
|
|
|
#define SPI_CTRL_WORD_SIZE(x) (((x) - 1) << 2)
|
|
|
|
#define SPI_CTRL_WR (1UL << 1)
|
|
|
|
#define SPI_CTRL_RD (1UL << 0)
|
|
|
|
|
|
|
|
#define SPI_STATUS_WE (1UL << 1)
|
|
|
|
#define SPI_STATUS_RD (1UL << 0)
|
|
|
|
|
|
|
|
/* use PIO for small transfers, avoiding DMA setup/teardown overhead and
|
|
|
|
* cache operations; better heuristics consider wordsize and bitrate.
|
|
|
|
*/
|
|
|
|
#define DMA_MIN_BYTES 8
|
|
|
|
|
|
|
|
#define SPI_RUNNING 0
|
|
|
|
#define SPI_SHUTDOWN 1
|
|
|
|
|
|
|
|
struct omap1_spi100k {
|
|
|
|
struct clk *ick;
|
|
|
|
struct clk *fck;
|
|
|
|
|
|
|
|
/* Virtual base address of the controller */
|
|
|
|
void __iomem *base;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct omap1_spi100k_cs {
|
|
|
|
void __iomem *base;
|
|
|
|
int word_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void spi100k_enable_clock(struct spi_master *master)
|
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
/* enable SPI */
|
|
|
|
val = readw(spi100k->base + SPI_SETUP1);
|
|
|
|
val |= SPI_SETUP1_CLOCK_ENABLE;
|
|
|
|
writew(val, spi100k->base + SPI_SETUP1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spi100k_disable_clock(struct spi_master *master)
|
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
/* disable SPI */
|
|
|
|
val = readw(spi100k->base + SPI_SETUP1);
|
|
|
|
val &= ~SPI_SETUP1_CLOCK_ENABLE;
|
|
|
|
writew(val, spi100k->base + SPI_SETUP1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spi100k_write_data(struct spi_master *master, int len, int data)
|
|
|
|
{
|
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
|
2010-05-30 08:12:23 +08:00
|
|
|
/* write 16-bit word, shifting 8-bit data if necessary */
|
|
|
|
if (len <= 8) {
|
|
|
|
data <<= 8;
|
|
|
|
len = 16;
|
|
|
|
}
|
|
|
|
|
2009-12-13 16:02:11 +08:00
|
|
|
spi100k_enable_clock(master);
|
2021-03-24 14:16:35 +08:00
|
|
|
writew(data, spi100k->base + SPI_TX_MSB);
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
writew(SPI_CTRL_SEN(0) |
|
|
|
|
SPI_CTRL_WORD_SIZE(len) |
|
|
|
|
SPI_CTRL_WR,
|
|
|
|
spi100k->base + SPI_CTRL);
|
|
|
|
|
|
|
|
/* Wait for bit ack send change */
|
2014-02-26 09:27:10 +08:00
|
|
|
while ((readw(spi100k->base + SPI_STATUS) & SPI_STATUS_WE) != SPI_STATUS_WE)
|
|
|
|
;
|
2009-12-13 16:02:11 +08:00
|
|
|
udelay(1000);
|
|
|
|
|
|
|
|
spi100k_disable_clock(master);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spi100k_read_data(struct spi_master *master, int len)
|
|
|
|
{
|
2019-10-09 08:37:16 +08:00
|
|
|
int dataL;
|
2009-12-13 16:02:11 +08:00
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
|
2010-05-30 08:12:23 +08:00
|
|
|
/* Always do at least 16 bits */
|
|
|
|
if (len <= 8)
|
|
|
|
len = 16;
|
|
|
|
|
2009-12-13 16:02:11 +08:00
|
|
|
spi100k_enable_clock(master);
|
|
|
|
writew(SPI_CTRL_SEN(0) |
|
|
|
|
SPI_CTRL_WORD_SIZE(len) |
|
|
|
|
SPI_CTRL_RD,
|
|
|
|
spi100k->base + SPI_CTRL);
|
|
|
|
|
2014-02-26 09:27:10 +08:00
|
|
|
while ((readw(spi100k->base + SPI_STATUS) & SPI_STATUS_RD) != SPI_STATUS_RD)
|
|
|
|
;
|
2009-12-13 16:02:11 +08:00
|
|
|
udelay(1000);
|
|
|
|
|
|
|
|
dataL = readw(spi100k->base + SPI_RX_LSB);
|
2019-10-09 08:37:16 +08:00
|
|
|
readw(spi100k->base + SPI_RX_MSB);
|
2009-12-13 16:02:11 +08:00
|
|
|
spi100k_disable_clock(master);
|
|
|
|
|
|
|
|
return dataL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spi100k_open(struct spi_master *master)
|
|
|
|
{
|
|
|
|
/* get control of SPI */
|
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
writew(SPI_SETUP1_INT_READ_ENABLE |
|
|
|
|
SPI_SETUP1_INT_WRITE_ENABLE |
|
|
|
|
SPI_SETUP1_CLOCK_DIVISOR(0), spi100k->base + SPI_SETUP1);
|
|
|
|
|
|
|
|
/* configure clock and interrupts */
|
|
|
|
writew(SPI_SETUP2_ACTIVE_EDGE_FALLING |
|
|
|
|
SPI_SETUP2_NEGATIVE_LEVEL |
|
|
|
|
SPI_SETUP2_LEVEL_TRIGGER, spi100k->base + SPI_SETUP2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap1_spi100k_force_cs(struct omap1_spi100k *spi100k, int enable)
|
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
writew(0x05fc, spi100k->base + SPI_CTRL);
|
|
|
|
else
|
|
|
|
writew(0x05fd, spi100k->base + SPI_CTRL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
omap1_spi100k_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
|
|
|
|
{
|
|
|
|
struct omap1_spi100k_cs *cs = spi->controller_state;
|
|
|
|
unsigned int count, c;
|
|
|
|
int word_len;
|
|
|
|
|
|
|
|
count = xfer->len;
|
|
|
|
c = count;
|
|
|
|
word_len = cs->word_len;
|
|
|
|
|
|
|
|
if (word_len <= 8) {
|
|
|
|
u8 *rx;
|
|
|
|
const u8 *tx;
|
|
|
|
|
|
|
|
rx = xfer->rx_buf;
|
|
|
|
tx = xfer->tx_buf;
|
|
|
|
do {
|
2014-02-26 09:27:10 +08:00
|
|
|
c -= 1;
|
2009-12-13 16:02:11 +08:00
|
|
|
if (xfer->tx_buf != NULL)
|
2010-05-30 08:12:23 +08:00
|
|
|
spi100k_write_data(spi->master, word_len, *tx++);
|
2009-12-13 16:02:11 +08:00
|
|
|
if (xfer->rx_buf != NULL)
|
2010-05-30 08:12:23 +08:00
|
|
|
*rx++ = spi100k_read_data(spi->master, word_len);
|
2014-02-26 09:27:10 +08:00
|
|
|
} while (c);
|
2009-12-13 16:02:11 +08:00
|
|
|
} else if (word_len <= 16) {
|
|
|
|
u16 *rx;
|
|
|
|
const u16 *tx;
|
|
|
|
|
|
|
|
rx = xfer->rx_buf;
|
|
|
|
tx = xfer->tx_buf;
|
|
|
|
do {
|
2014-02-26 09:27:10 +08:00
|
|
|
c -= 2;
|
2009-12-13 16:02:11 +08:00
|
|
|
if (xfer->tx_buf != NULL)
|
2014-02-26 09:27:10 +08:00
|
|
|
spi100k_write_data(spi->master, word_len, *tx++);
|
2009-12-13 16:02:11 +08:00
|
|
|
if (xfer->rx_buf != NULL)
|
2014-02-26 09:27:10 +08:00
|
|
|
*rx++ = spi100k_read_data(spi->master, word_len);
|
|
|
|
} while (c);
|
2009-12-13 16:02:11 +08:00
|
|
|
} else if (word_len <= 32) {
|
|
|
|
u32 *rx;
|
|
|
|
const u32 *tx;
|
|
|
|
|
|
|
|
rx = xfer->rx_buf;
|
|
|
|
tx = xfer->tx_buf;
|
|
|
|
do {
|
2014-02-26 09:27:10 +08:00
|
|
|
c -= 4;
|
2009-12-13 16:02:11 +08:00
|
|
|
if (xfer->tx_buf != NULL)
|
2014-02-26 09:27:10 +08:00
|
|
|
spi100k_write_data(spi->master, word_len, *tx);
|
2009-12-13 16:02:11 +08:00
|
|
|
if (xfer->rx_buf != NULL)
|
2014-02-26 09:27:10 +08:00
|
|
|
*rx = spi100k_read_data(spi->master, word_len);
|
|
|
|
} while (c);
|
2009-12-13 16:02:11 +08:00
|
|
|
}
|
|
|
|
return count - c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called only when no transfer is active to this device */
|
|
|
|
static int omap1_spi100k_setup_transfer(struct spi_device *spi,
|
|
|
|
struct spi_transfer *t)
|
|
|
|
{
|
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(spi->master);
|
|
|
|
struct omap1_spi100k_cs *cs = spi->controller_state;
|
2015-09-15 21:26:21 +08:00
|
|
|
u8 word_len;
|
2009-12-13 16:02:11 +08:00
|
|
|
|
2015-09-15 21:26:21 +08:00
|
|
|
if (t != NULL)
|
2009-12-13 16:02:11 +08:00
|
|
|
word_len = t->bits_per_word;
|
2015-09-15 21:26:21 +08:00
|
|
|
else
|
|
|
|
word_len = spi->bits_per_word;
|
2009-12-13 16:02:11 +08:00
|
|
|
|
2021-04-29 19:20:48 +08:00
|
|
|
if (word_len > 32)
|
2009-12-13 16:02:11 +08:00
|
|
|
return -EINVAL;
|
|
|
|
cs->word_len = word_len;
|
|
|
|
|
|
|
|
/* SPI init before transfer */
|
2021-03-24 14:16:35 +08:00
|
|
|
writew(0x3e, spi100k->base + SPI_SETUP1);
|
|
|
|
writew(0x00, spi100k->base + SPI_STATUS);
|
|
|
|
writew(0x3e, spi100k->base + SPI_CTRL);
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the spi->mode bits understood by this driver: */
|
|
|
|
#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH)
|
|
|
|
|
|
|
|
static int omap1_spi100k_setup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct omap1_spi100k *spi100k;
|
|
|
|
struct omap1_spi100k_cs *cs = spi->controller_state;
|
|
|
|
|
|
|
|
spi100k = spi_master_get_devdata(spi->master);
|
|
|
|
|
|
|
|
if (!cs) {
|
2014-03-29 15:03:37 +08:00
|
|
|
cs = devm_kzalloc(&spi->dev, sizeof(*cs), GFP_KERNEL);
|
2009-12-13 16:02:11 +08:00
|
|
|
if (!cs)
|
|
|
|
return -ENOMEM;
|
|
|
|
cs->base = spi100k->base + spi->chip_select * 0x14;
|
|
|
|
spi->controller_state = cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi100k_open(spi->master);
|
|
|
|
|
2013-07-10 23:09:22 +08:00
|
|
|
clk_prepare_enable(spi100k->ick);
|
|
|
|
clk_prepare_enable(spi100k->fck);
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
ret = omap1_spi100k_setup_transfer(spi, NULL);
|
|
|
|
|
2013-07-10 23:09:22 +08:00
|
|
|
clk_disable_unprepare(spi100k->ick);
|
|
|
|
clk_disable_unprepare(spi100k->fck);
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-10 22:40:19 +08:00
|
|
|
static int omap1_spi100k_transfer_one_message(struct spi_master *master,
|
|
|
|
struct spi_message *m)
|
|
|
|
{
|
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
struct spi_device *spi = m->spi;
|
|
|
|
struct spi_transfer *t = NULL;
|
|
|
|
int cs_active = 0;
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(t, &m->transfers, transfer_list) {
|
|
|
|
if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
|
|
|
|
break;
|
|
|
|
}
|
2015-09-15 21:26:21 +08:00
|
|
|
status = omap1_spi100k_setup_transfer(spi, t);
|
|
|
|
if (status < 0)
|
|
|
|
break;
|
2013-07-10 22:40:19 +08:00
|
|
|
|
|
|
|
if (!cs_active) {
|
|
|
|
omap1_spi100k_force_cs(spi100k, 1);
|
|
|
|
cs_active = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t->len) {
|
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
count = omap1_spi100k_txrx_pio(spi, t);
|
|
|
|
m->actual_length += count;
|
|
|
|
|
|
|
|
if (count != t->len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-26 18:51:37 +08:00
|
|
|
spi_transfer_delay_exec(t);
|
2013-07-10 22:40:19 +08:00
|
|
|
|
|
|
|
/* ignore the "leave it on after last xfer" hint */
|
|
|
|
|
|
|
|
if (t->cs_change) {
|
|
|
|
omap1_spi100k_force_cs(spi100k, 0);
|
|
|
|
cs_active = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 21:26:21 +08:00
|
|
|
status = omap1_spi100k_setup_transfer(spi, NULL);
|
2013-07-10 22:40:19 +08:00
|
|
|
|
|
|
|
if (cs_active)
|
|
|
|
omap1_spi100k_force_cs(spi100k, 0);
|
|
|
|
|
|
|
|
m->status = status;
|
2013-07-10 22:52:11 +08:00
|
|
|
|
|
|
|
spi_finalize_current_message(master);
|
2013-07-10 22:40:19 +08:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-12-08 00:57:14 +08:00
|
|
|
static int omap1_spi100k_probe(struct platform_device *pdev)
|
2009-12-13 16:02:11 +08:00
|
|
|
{
|
|
|
|
struct spi_master *master;
|
|
|
|
struct omap1_spi100k *spi100k;
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
if (!pdev->id)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-02-26 09:27:10 +08:00
|
|
|
master = spi_alloc_master(&pdev->dev, sizeof(*spi100k));
|
2009-12-13 16:02:11 +08:00
|
|
|
if (master == NULL) {
|
|
|
|
dev_dbg(&pdev->dev, "master allocation failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdev->id != -1)
|
2014-02-26 09:27:10 +08:00
|
|
|
master->bus_num = pdev->id;
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
master->setup = omap1_spi100k_setup;
|
2013-07-10 22:52:11 +08:00
|
|
|
master->transfer_one_message = omap1_spi100k_transfer_one_message;
|
2009-12-13 16:02:11 +08:00
|
|
|
master->num_chipselect = 2;
|
|
|
|
master->mode_bits = MODEBITS;
|
2013-05-22 10:36:35 +08:00
|
|
|
master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
|
2013-07-10 22:06:46 +08:00
|
|
|
master->min_speed_hz = OMAP1_SPI100K_MAX_FREQ/(1<<16);
|
|
|
|
master->max_speed_hz = OMAP1_SPI100K_MAX_FREQ;
|
2014-12-11 02:16:25 +08:00
|
|
|
master->auto_runtime_pm = true;
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
spi100k = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The memory region base address is taken as the platform_data.
|
|
|
|
* You should allocate this with ioremap() before initializing
|
|
|
|
* the SPI.
|
|
|
|
*/
|
2013-07-30 15:58:59 +08:00
|
|
|
spi100k->base = (void __iomem *)dev_get_platdata(&pdev->dev);
|
2009-12-13 16:02:11 +08:00
|
|
|
|
2013-07-10 23:07:51 +08:00
|
|
|
spi100k->ick = devm_clk_get(&pdev->dev, "ick");
|
2009-12-13 16:02:11 +08:00
|
|
|
if (IS_ERR(spi100k->ick)) {
|
|
|
|
dev_dbg(&pdev->dev, "can't get spi100k_ick\n");
|
|
|
|
status = PTR_ERR(spi100k->ick);
|
2013-07-10 23:07:51 +08:00
|
|
|
goto err;
|
2009-12-13 16:02:11 +08:00
|
|
|
}
|
|
|
|
|
2013-07-10 23:07:51 +08:00
|
|
|
spi100k->fck = devm_clk_get(&pdev->dev, "fck");
|
2009-12-13 16:02:11 +08:00
|
|
|
if (IS_ERR(spi100k->fck)) {
|
|
|
|
dev_dbg(&pdev->dev, "can't get spi100k_fck\n");
|
|
|
|
status = PTR_ERR(spi100k->fck);
|
2013-07-10 23:07:51 +08:00
|
|
|
goto err;
|
2009-12-13 16:02:11 +08:00
|
|
|
}
|
|
|
|
|
2014-12-11 02:16:25 +08:00
|
|
|
status = clk_prepare_enable(spi100k->ick);
|
|
|
|
if (status != 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to enable ick: %d\n", status);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = clk_prepare_enable(spi100k->fck);
|
|
|
|
if (status != 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to enable fck: %d\n", status);
|
|
|
|
goto err_ick;
|
|
|
|
}
|
|
|
|
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
|
|
|
2013-09-24 12:37:23 +08:00
|
|
|
status = devm_spi_register_master(&pdev->dev, master);
|
2009-12-13 16:02:11 +08:00
|
|
|
if (status < 0)
|
2014-12-11 02:16:25 +08:00
|
|
|
goto err_fck;
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
return status;
|
|
|
|
|
2014-12-11 02:16:25 +08:00
|
|
|
err_fck:
|
|
|
|
clk_disable_unprepare(spi100k->fck);
|
|
|
|
err_ick:
|
|
|
|
clk_disable_unprepare(spi100k->ick);
|
2013-07-10 23:07:51 +08:00
|
|
|
err:
|
2009-12-13 16:02:11 +08:00
|
|
|
spi_master_put(master);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-12-11 02:16:25 +08:00
|
|
|
static int omap1_spi100k_remove(struct platform_device *pdev)
|
|
|
|
{
|
2021-04-09 16:29:54 +08:00
|
|
|
struct spi_master *master = platform_get_drvdata(pdev);
|
2014-12-11 02:16:25 +08:00
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
|
|
|
|
clk_disable_unprepare(spi100k->fck);
|
|
|
|
clk_disable_unprepare(spi100k->ick);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int omap1_spi100k_runtime_suspend(struct device *dev)
|
|
|
|
{
|
2021-04-09 16:29:54 +08:00
|
|
|
struct spi_master *master = dev_get_drvdata(dev);
|
2014-12-11 02:16:25 +08:00
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
|
|
|
|
clk_disable_unprepare(spi100k->ick);
|
|
|
|
clk_disable_unprepare(spi100k->fck);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap1_spi100k_runtime_resume(struct device *dev)
|
|
|
|
{
|
2021-04-09 16:29:54 +08:00
|
|
|
struct spi_master *master = dev_get_drvdata(dev);
|
2014-12-11 02:16:25 +08:00
|
|
|
struct omap1_spi100k *spi100k = spi_master_get_devdata(master);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(spi100k->ick);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(dev, "Failed to enable ick: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(spi100k->fck);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(dev, "Failed to enable fck: %d\n", ret);
|
|
|
|
clk_disable_unprepare(spi100k->ick);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct dev_pm_ops omap1_spi100k_pm = {
|
|
|
|
SET_RUNTIME_PM_OPS(omap1_spi100k_runtime_suspend,
|
|
|
|
omap1_spi100k_runtime_resume, NULL)
|
|
|
|
};
|
|
|
|
|
2009-12-13 16:02:11 +08:00
|
|
|
static struct platform_driver omap1_spi100k_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "omap1_spi100k",
|
2014-12-11 02:16:25 +08:00
|
|
|
.pm = &omap1_spi100k_pm,
|
2009-12-13 16:02:11 +08:00
|
|
|
},
|
2013-07-10 23:10:33 +08:00
|
|
|
.probe = omap1_spi100k_probe,
|
2014-12-11 02:16:25 +08:00
|
|
|
.remove = omap1_spi100k_remove,
|
2009-12-13 16:02:11 +08:00
|
|
|
};
|
|
|
|
|
2013-07-10 23:10:33 +08:00
|
|
|
module_platform_driver(omap1_spi100k_driver);
|
2009-12-13 16:02:11 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("OMAP7xx SPI 100k controller driver");
|
|
|
|
MODULE_AUTHOR("Fabrice Crohas <fcrohas@gmail.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|