2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-05-11 13:22:52 +08:00
|
|
|
/*
|
2008-05-15 07:05:29 +08:00
|
|
|
* MPC52xx PSC in SPI mode driver.
|
2007-05-11 13:22:52 +08:00
|
|
|
*
|
|
|
|
* Maintainer: Dragos Carp
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 TOPTICA Photonics AG.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2009-06-18 07:26:05 +08:00
|
|
|
#include <linux/types.h>
|
2007-05-11 13:22:52 +08:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/interrupt.h>
|
2023-02-18 04:45:42 +08:00
|
|
|
#include <linux/platform_device.h>
|
2023-03-07 02:31:14 +08:00
|
|
|
#include <linux/property.h>
|
2007-05-11 13:22:52 +08:00
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/spi/spi.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>
|
2007-05-11 13:22:52 +08:00
|
|
|
|
|
|
|
#include <asm/mpc52xx.h>
|
|
|
|
#include <asm/mpc52xx_psc.h>
|
|
|
|
|
|
|
|
#define MCLK 20000000 /* PSC port MClk in hz */
|
|
|
|
|
|
|
|
struct mpc52xx_psc_spi {
|
|
|
|
/* driver internal data */
|
|
|
|
struct mpc52xx_psc __iomem *psc;
|
2008-03-05 06:28:42 +08:00
|
|
|
struct mpc52xx_psc_fifo __iomem *fifo;
|
2023-08-07 22:49:42 +08:00
|
|
|
int irq;
|
2007-05-11 13:22:52 +08:00
|
|
|
u8 bits_per_word;
|
|
|
|
|
|
|
|
struct completion done;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* controller state */
|
|
|
|
struct mpc52xx_psc_spi_cs {
|
|
|
|
int bits_per_word;
|
|
|
|
int speed_hz;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* set clock freq, clock ramp, bits per work
|
|
|
|
* if t is NULL then reset the values to the default values
|
|
|
|
*/
|
|
|
|
static int mpc52xx_psc_spi_transfer_setup(struct spi_device *spi,
|
|
|
|
struct spi_transfer *t)
|
|
|
|
{
|
|
|
|
struct mpc52xx_psc_spi_cs *cs = spi->controller_state;
|
|
|
|
|
|
|
|
cs->speed_hz = (t && t->speed_hz)
|
|
|
|
? t->speed_hz : spi->max_speed_hz;
|
|
|
|
cs->bits_per_word = (t && t->bits_per_word)
|
|
|
|
? t->bits_per_word : spi->bits_per_word;
|
|
|
|
cs->bits_per_word = ((cs->bits_per_word + 7) / 8) * 8;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct mpc52xx_psc_spi_cs *cs = spi->controller_state;
|
2023-08-23 11:29:50 +08:00
|
|
|
struct mpc52xx_psc_spi *mps = spi_controller_get_devdata(spi->controller);
|
2007-05-11 13:22:52 +08:00
|
|
|
struct mpc52xx_psc __iomem *psc = mps->psc;
|
|
|
|
u32 sicr;
|
|
|
|
u16 ccr;
|
|
|
|
|
|
|
|
sicr = in_be32(&psc->sicr);
|
|
|
|
|
|
|
|
/* Set clock phase and polarity */
|
|
|
|
if (spi->mode & SPI_CPHA)
|
|
|
|
sicr |= 0x00001000;
|
|
|
|
else
|
|
|
|
sicr &= ~0x00001000;
|
|
|
|
if (spi->mode & SPI_CPOL)
|
|
|
|
sicr |= 0x00002000;
|
|
|
|
else
|
|
|
|
sicr &= ~0x00002000;
|
|
|
|
|
|
|
|
if (spi->mode & SPI_LSB_FIRST)
|
|
|
|
sicr |= 0x10000000;
|
|
|
|
else
|
|
|
|
sicr &= ~0x10000000;
|
|
|
|
out_be32(&psc->sicr, sicr);
|
|
|
|
|
|
|
|
/* Set clock frequency and bits per word
|
|
|
|
* Because psc->ccr is defined as 16bit register instead of 32bit
|
|
|
|
* just set the lower byte of BitClkDiv
|
|
|
|
*/
|
2008-10-08 23:02:11 +08:00
|
|
|
ccr = in_be16((u16 __iomem *)&psc->ccr);
|
2007-05-11 13:22:52 +08:00
|
|
|
ccr &= 0xFF00;
|
|
|
|
if (cs->speed_hz)
|
|
|
|
ccr |= (MCLK / cs->speed_hz - 1) & 0xFF;
|
|
|
|
else /* by default SPI Clk 1MHz */
|
|
|
|
ccr |= (MCLK / 1000000 - 1) & 0xFF;
|
2008-10-08 23:02:11 +08:00
|
|
|
out_be16((u16 __iomem *)&psc->ccr, ccr);
|
2007-05-11 13:22:52 +08:00
|
|
|
mps->bits_per_word = cs->bits_per_word;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MPC52xx_PSC_BUFSIZE (MPC52xx_PSC_RFNUM_MASK + 1)
|
|
|
|
/* wake up when 80% fifo full */
|
|
|
|
#define MPC52xx_PSC_RFALARM (MPC52xx_PSC_BUFSIZE * 20 / 100)
|
|
|
|
|
|
|
|
static int mpc52xx_psc_spi_transfer_rxtx(struct spi_device *spi,
|
|
|
|
struct spi_transfer *t)
|
|
|
|
{
|
2023-08-23 11:29:50 +08:00
|
|
|
struct mpc52xx_psc_spi *mps = spi_controller_get_devdata(spi->controller);
|
2007-05-11 13:22:52 +08:00
|
|
|
struct mpc52xx_psc __iomem *psc = mps->psc;
|
2008-03-05 06:28:42 +08:00
|
|
|
struct mpc52xx_psc_fifo __iomem *fifo = mps->fifo;
|
2007-05-11 13:22:52 +08:00
|
|
|
unsigned rb = 0; /* number of bytes receieved */
|
|
|
|
unsigned sb = 0; /* number of bytes sent */
|
|
|
|
unsigned char *rx_buf = (unsigned char *)t->rx_buf;
|
|
|
|
unsigned char *tx_buf = (unsigned char *)t->tx_buf;
|
|
|
|
unsigned rfalarm;
|
|
|
|
unsigned send_at_once = MPC52xx_PSC_BUFSIZE;
|
|
|
|
unsigned recv_at_once;
|
2008-12-02 05:13:53 +08:00
|
|
|
int last_block = 0;
|
2007-05-11 13:22:52 +08:00
|
|
|
|
|
|
|
if (!t->tx_buf && !t->rx_buf && t->len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* enable transmiter/receiver */
|
|
|
|
out_8(&psc->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
|
|
|
|
while (rb < t->len) {
|
|
|
|
if (t->len - rb > MPC52xx_PSC_BUFSIZE) {
|
|
|
|
rfalarm = MPC52xx_PSC_RFALARM;
|
2008-12-02 05:13:53 +08:00
|
|
|
last_block = 0;
|
2007-05-11 13:22:52 +08:00
|
|
|
} else {
|
|
|
|
send_at_once = t->len - sb;
|
|
|
|
rfalarm = MPC52xx_PSC_BUFSIZE - (t->len - rb);
|
2008-12-02 05:13:53 +08:00
|
|
|
last_block = 1;
|
2007-05-11 13:22:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(&spi->dev, "send %d bytes...\n", send_at_once);
|
2008-07-29 06:46:32 +08:00
|
|
|
for (; send_at_once; sb++, send_at_once--) {
|
|
|
|
/* set EOF flag before the last word is sent */
|
2008-12-02 05:13:53 +08:00
|
|
|
if (send_at_once == 1 && last_block)
|
2008-07-29 06:46:32 +08:00
|
|
|
out_8(&psc->ircr2, 0x01);
|
|
|
|
|
|
|
|
if (tx_buf)
|
2007-05-11 13:22:52 +08:00
|
|
|
out_8(&psc->mpc52xx_psc_buffer_8, tx_buf[sb]);
|
2008-07-29 06:46:32 +08:00
|
|
|
else
|
2007-05-11 13:22:52 +08:00
|
|
|
out_8(&psc->mpc52xx_psc_buffer_8, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-20 05:10:43 +08:00
|
|
|
/* enable interrupts and wait for wake up
|
2007-05-11 13:22:52 +08:00
|
|
|
* if just one byte is expected the Rx FIFO genererates no
|
|
|
|
* FFULL interrupt, so activate the RxRDY interrupt
|
|
|
|
*/
|
|
|
|
out_8(&psc->command, MPC52xx_PSC_SEL_MODE_REG_1);
|
|
|
|
if (t->len - rb == 1) {
|
|
|
|
out_8(&psc->mode, 0);
|
|
|
|
} else {
|
|
|
|
out_8(&psc->mode, MPC52xx_PSC_MODE_FFULL);
|
2008-03-05 06:28:42 +08:00
|
|
|
out_be16(&fifo->rfalarm, rfalarm);
|
2007-05-11 13:22:52 +08:00
|
|
|
}
|
|
|
|
out_be16(&psc->mpc52xx_psc_imr, MPC52xx_PSC_IMR_RXRDY);
|
|
|
|
wait_for_completion(&mps->done);
|
2008-03-05 06:28:42 +08:00
|
|
|
recv_at_once = in_be16(&fifo->rfnum);
|
2007-05-11 13:22:52 +08:00
|
|
|
dev_dbg(&spi->dev, "%d bytes received\n", recv_at_once);
|
|
|
|
|
|
|
|
send_at_once = recv_at_once;
|
|
|
|
if (rx_buf) {
|
|
|
|
for (; recv_at_once; rb++, recv_at_once--)
|
|
|
|
rx_buf[rb] = in_8(&psc->mpc52xx_psc_buffer_8);
|
|
|
|
} else {
|
|
|
|
for (; recv_at_once; rb++, recv_at_once--)
|
|
|
|
in_8(&psc->mpc52xx_psc_buffer_8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* disable transmiter/receiver */
|
|
|
|
out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-06 19:29:45 +08:00
|
|
|
static int mpc52xx_psc_spi_transfer_one_message(struct spi_controller *ctlr,
|
|
|
|
struct spi_message *m)
|
2007-05-11 13:22:52 +08:00
|
|
|
{
|
2022-06-13 20:19:46 +08:00
|
|
|
struct spi_device *spi;
|
|
|
|
struct spi_transfer *t = NULL;
|
|
|
|
unsigned cs_change;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
spi = m->spi;
|
|
|
|
cs_change = 1;
|
|
|
|
status = 0;
|
|
|
|
list_for_each_entry (t, &m->transfers, transfer_list) {
|
|
|
|
if (t->bits_per_word || t->speed_hz) {
|
|
|
|
status = mpc52xx_psc_spi_transfer_setup(spi, t);
|
|
|
|
if (status < 0)
|
2007-05-11 13:22:52 +08:00
|
|
|
break;
|
2022-06-13 20:19:46 +08:00
|
|
|
}
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2022-06-13 20:19:46 +08:00
|
|
|
if (cs_change)
|
|
|
|
mpc52xx_psc_spi_activate_cs(spi);
|
|
|
|
cs_change = t->cs_change;
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2022-06-13 20:19:46 +08:00
|
|
|
status = mpc52xx_psc_spi_transfer_rxtx(spi, t);
|
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
m->actual_length += t->len;
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2022-06-13 20:19:46 +08:00
|
|
|
spi_transfer_delay_exec(t);
|
|
|
|
}
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2022-06-13 20:19:46 +08:00
|
|
|
m->status = status;
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2022-06-13 20:19:46 +08:00
|
|
|
mpc52xx_psc_spi_transfer_setup(spi, NULL);
|
|
|
|
|
|
|
|
spi_finalize_current_message(ctlr);
|
|
|
|
|
|
|
|
return 0;
|
2007-05-11 13:22:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc52xx_psc_spi_setup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct mpc52xx_psc_spi_cs *cs = spi->controller_state;
|
|
|
|
|
|
|
|
if (spi->bits_per_word%8)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!cs) {
|
2021-05-18 09:38:19 +08:00
|
|
|
cs = kzalloc(sizeof(*cs), GFP_KERNEL);
|
2007-05-11 13:22:52 +08:00
|
|
|
if (!cs)
|
|
|
|
return -ENOMEM;
|
|
|
|
spi->controller_state = cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
cs->bits_per_word = spi->bits_per_word;
|
|
|
|
cs->speed_hz = spi->max_speed_hz;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mpc52xx_psc_spi_cleanup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
kfree(spi->controller_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
|
|
|
|
{
|
|
|
|
struct mpc52xx_psc __iomem *psc = mps->psc;
|
2008-03-05 06:28:42 +08:00
|
|
|
struct mpc52xx_psc_fifo __iomem *fifo = mps->fifo;
|
2007-05-11 13:22:52 +08:00
|
|
|
u32 mclken_div;
|
2009-11-02 11:53:11 +08:00
|
|
|
int ret;
|
2007-05-11 13:22:52 +08:00
|
|
|
|
|
|
|
/* default sysclk is 512MHz */
|
2023-02-18 04:45:40 +08:00
|
|
|
mclken_div = 512000000 / MCLK;
|
2009-11-02 11:53:11 +08:00
|
|
|
ret = mpc52xx_set_psc_clkdiv(psc_id, mclken_div);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2007-05-11 13:22:52 +08:00
|
|
|
|
|
|
|
/* Reset the PSC into a known state */
|
|
|
|
out_8(&psc->command, MPC52xx_PSC_RST_RX);
|
|
|
|
out_8(&psc->command, MPC52xx_PSC_RST_TX);
|
|
|
|
out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
|
|
|
|
|
|
|
|
/* Disable interrupts, interrupts are based on alarm level */
|
|
|
|
out_be16(&psc->mpc52xx_psc_imr, 0);
|
|
|
|
out_8(&psc->command, MPC52xx_PSC_SEL_MODE_REG_1);
|
2008-03-05 06:28:42 +08:00
|
|
|
out_8(&fifo->rfcntl, 0);
|
2007-05-11 13:22:52 +08:00
|
|
|
out_8(&psc->mode, MPC52xx_PSC_MODE_FFULL);
|
|
|
|
|
2023-08-23 11:29:50 +08:00
|
|
|
/* Configure 8bit codec mode as a SPI host and use EOF flags */
|
2007-05-11 13:22:52 +08:00
|
|
|
/* SICR_SIM_CODEC8|SICR_GENCLK|SICR_SPI|SICR_MSTR|SICR_USEEOF */
|
|
|
|
out_be32(&psc->sicr, 0x0180C800);
|
2008-10-08 23:02:11 +08:00
|
|
|
out_be16((u16 __iomem *)&psc->ccr, 0x070F); /* default SPI Clk 1MHz */
|
2007-05-11 13:22:52 +08:00
|
|
|
|
|
|
|
/* Set 2ms DTL delay */
|
|
|
|
out_8(&psc->ctur, 0x00);
|
|
|
|
out_8(&psc->ctlr, 0x84);
|
|
|
|
|
|
|
|
mps->bits_per_word = 8;
|
|
|
|
|
2009-11-02 11:53:11 +08:00
|
|
|
return 0;
|
2007-05-11 13:22:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t mpc52xx_psc_spi_isr(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct mpc52xx_psc_spi *mps = (struct mpc52xx_psc_spi *)dev_id;
|
|
|
|
struct mpc52xx_psc __iomem *psc = mps->psc;
|
|
|
|
|
|
|
|
/* disable interrupt and wake up the work queue */
|
|
|
|
if (in_be16(&psc->mpc52xx_psc_isr) & MPC52xx_PSC_IMR_RXRDY) {
|
|
|
|
out_be16(&psc->mpc52xx_psc_imr, 0);
|
|
|
|
complete(&mps->done);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2023-02-18 04:45:42 +08:00
|
|
|
static int mpc52xx_psc_spi_of_probe(struct platform_device *pdev)
|
2007-05-11 13:22:52 +08:00
|
|
|
{
|
2023-02-18 04:45:42 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2007-05-11 13:22:52 +08:00
|
|
|
struct mpc52xx_psc_spi *mps;
|
2023-08-23 11:29:50 +08:00
|
|
|
struct spi_controller *host;
|
2023-02-18 04:45:42 +08:00
|
|
|
u32 bus_num;
|
2007-05-11 13:22:52 +08:00
|
|
|
int ret;
|
|
|
|
|
2023-08-23 11:29:50 +08:00
|
|
|
host = devm_spi_alloc_host(dev, sizeof(*mps));
|
|
|
|
if (host == NULL)
|
2007-05-11 13:22:52 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2023-08-23 11:29:50 +08:00
|
|
|
dev_set_drvdata(dev, host);
|
|
|
|
mps = spi_controller_get_devdata(host);
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2009-06-18 07:26:04 +08:00
|
|
|
/* the spi->mode bits understood by this driver: */
|
2023-08-23 11:29:50 +08:00
|
|
|
host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
|
2009-06-18 07:26:04 +08:00
|
|
|
|
2023-03-07 02:31:15 +08:00
|
|
|
ret = device_property_read_u32(dev, "cell-index", &bus_num);
|
2023-02-18 04:45:42 +08:00
|
|
|
if (ret || bus_num > 5)
|
|
|
|
return dev_err_probe(dev, ret ? : -EINVAL, "Invalid cell-index property\n");
|
2023-08-23 11:29:50 +08:00
|
|
|
host->bus_num = bus_num + 1;
|
2023-02-18 04:45:42 +08:00
|
|
|
|
2023-08-23 11:29:50 +08:00
|
|
|
host->num_chipselect = 255;
|
|
|
|
host->setup = mpc52xx_psc_spi_setup;
|
|
|
|
host->transfer_one_message = mpc52xx_psc_spi_transfer_one_message;
|
|
|
|
host->cleanup = mpc52xx_psc_spi_cleanup;
|
2023-03-07 02:31:14 +08:00
|
|
|
|
2023-08-23 11:29:50 +08:00
|
|
|
device_set_node(&host->dev, dev_fwnode(dev));
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2023-02-18 04:45:42 +08:00
|
|
|
mps->psc = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
|
2023-03-07 02:31:11 +08:00
|
|
|
if (IS_ERR(mps->psc))
|
|
|
|
return dev_err_probe(dev, PTR_ERR(mps->psc), "could not ioremap I/O port range\n");
|
|
|
|
|
2008-03-05 06:28:42 +08:00
|
|
|
/* On the 5200, fifo regs are immediately ajacent to the psc regs */
|
|
|
|
mps->fifo = ((void __iomem *)mps->psc) + sizeof(struct mpc52xx_psc);
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2023-02-18 04:45:42 +08:00
|
|
|
mps->irq = platform_get_irq(pdev, 0);
|
2023-03-07 02:31:12 +08:00
|
|
|
if (mps->irq < 0)
|
|
|
|
return mps->irq;
|
|
|
|
|
2023-02-18 04:45:41 +08:00
|
|
|
ret = devm_request_irq(dev, mps->irq, mpc52xx_psc_spi_isr, 0,
|
|
|
|
"mpc52xx-psc-spi", mps);
|
2007-05-11 13:22:52 +08:00
|
|
|
if (ret)
|
2023-02-18 04:45:41 +08:00
|
|
|
return ret;
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2023-08-23 11:29:50 +08:00
|
|
|
ret = mpc52xx_psc_spi_port_config(host->bus_num, mps);
|
2007-05-11 13:22:52 +08:00
|
|
|
if (ret < 0)
|
2023-02-18 04:45:41 +08:00
|
|
|
return dev_err_probe(dev, ret, "can't configure PSC! Is it capable of SPI?\n");
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2023-02-18 04:45:41 +08:00
|
|
|
init_completion(&mps->done);
|
2007-05-11 13:22:52 +08:00
|
|
|
|
2023-08-23 11:29:50 +08:00
|
|
|
return devm_spi_register_controller(dev, host);
|
2007-05-11 13:22:52 +08:00
|
|
|
}
|
|
|
|
|
2010-01-21 04:49:44 +08:00
|
|
|
static const struct of_device_id mpc52xx_psc_spi_of_match[] = {
|
2008-01-25 13:25:31 +08:00
|
|
|
{ .compatible = "fsl,mpc5200-psc-spi", },
|
|
|
|
{ .compatible = "mpc5200-psc-spi", }, /* old */
|
|
|
|
{}
|
2007-05-11 13:22:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(of, mpc52xx_psc_spi_of_match);
|
|
|
|
|
2011-02-23 12:02:43 +08:00
|
|
|
static struct platform_driver mpc52xx_psc_spi_of_driver = {
|
2007-05-11 13:22:52 +08:00
|
|
|
.probe = mpc52xx_psc_spi_of_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "mpc52xx-psc-spi",
|
2010-04-14 07:13:02 +08:00
|
|
|
.of_match_table = mpc52xx_psc_spi_of_match,
|
2007-05-11 13:22:52 +08:00
|
|
|
},
|
|
|
|
};
|
2011-10-06 01:29:49 +08:00
|
|
|
module_platform_driver(mpc52xx_psc_spi_of_driver);
|
2007-05-11 13:22:52 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Dragos Carp");
|
|
|
|
MODULE_DESCRIPTION("MPC52xx PSC SPI Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|