2005-11-07 09:00:19 +00:00
|
|
|
/*
|
2008-04-18 20:33:38 +00:00
|
|
|
* Freescale MPC85xx/MPC86xx RapidIO support
|
2005-11-07 09:00:19 +00:00
|
|
|
*
|
2010-05-26 21:44:05 +00:00
|
|
|
* Copyright 2009 Sysgo AG
|
|
|
|
* Thomas Moll <thomas.moll@sysgo.com>
|
|
|
|
* - fixed maintenance access routines, check for aligned access
|
|
|
|
*
|
2010-05-26 21:44:00 +00:00
|
|
|
* Copyright 2009 Integrated Device Technology, Inc.
|
|
|
|
* Alex Bounine <alexandre.bounine@idt.com>
|
|
|
|
* - Added Port-Write message handling
|
|
|
|
* - Added Machine Check exception handling
|
|
|
|
*
|
2011-11-12 12:02:28 +00:00
|
|
|
* Copyright (C) 2007, 2008, 2010, 2011 Freescale Semiconductor, Inc.
|
2008-04-18 20:33:41 +00:00
|
|
|
* Zhang Wei <wei.zhang@freescale.com>
|
|
|
|
*
|
2005-11-07 09:00:19 +00:00
|
|
|
* Copyright 2005 MontaVista Software, Inc.
|
|
|
|
* Matt Porter <mporter@kernel.crashing.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
2011-11-11 13:48:28 +00:00
|
|
|
#include <linux/module.h>
|
2005-11-07 09:00:19 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/interrupt.h>
|
2009-04-18 17:48:52 +00:00
|
|
|
#include <linux/device.h>
|
2008-04-18 20:33:41 +00:00
|
|
|
#include <linux/of_platform.h>
|
2008-04-18 20:33:44 +00:00
|
|
|
#include <linux/delay.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2011-11-12 12:02:28 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/uaccess.h>
|
2010-05-26 21:44:00 +00:00
|
|
|
#include <asm/machdep.h>
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2011-11-12 12:02:28 +00:00
|
|
|
#include "fsl_rio.h"
|
2010-05-26 21:44:00 +00:00
|
|
|
|
2011-11-12 12:02:28 +00:00
|
|
|
#undef DEBUG_PW /* Port-Write debugging */
|
2010-11-18 06:57:53 +00:00
|
|
|
|
|
|
|
#define RIO_PORT1_EDCSR 0x0640
|
|
|
|
#define RIO_PORT2_EDCSR 0x0680
|
|
|
|
#define RIO_PORT1_IECSR 0x10130
|
|
|
|
#define RIO_PORT2_IECSR 0x101B0
|
|
|
|
|
2005-11-07 09:00:19 +00:00
|
|
|
#define RIO_ATMU_REGS_OFFSET 0x10c00
|
2010-10-27 22:34:34 +00:00
|
|
|
#define RIO_GCCSR 0x13c
|
2008-04-18 20:33:44 +00:00
|
|
|
#define RIO_ESCSR 0x158
|
2011-11-12 12:02:28 +00:00
|
|
|
#define ESCSR_CLEAR 0x07120204
|
2010-11-18 06:57:53 +00:00
|
|
|
#define RIO_PORT2_ESCSR 0x178
|
2008-04-18 20:33:44 +00:00
|
|
|
#define RIO_CCSR 0x15c
|
2010-11-18 06:57:53 +00:00
|
|
|
#define RIO_LTLEDCSR_IER 0x80000000
|
|
|
|
#define RIO_LTLEDCSR_PRT 0x01000000
|
2011-11-12 12:02:28 +00:00
|
|
|
#define IECSR_CLEAR 0x80000000
|
2008-04-18 20:33:44 +00:00
|
|
|
#define RIO_ISR_AACR 0x10120
|
|
|
|
#define RIO_ISR_AACR_AA 0x1 /* Accept All ID */
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2010-05-26 21:44:00 +00:00
|
|
|
#define __fsl_read_rio_config(x, addr, err, op) \
|
|
|
|
__asm__ __volatile__( \
|
|
|
|
"1: "op" %1,0(%2)\n" \
|
|
|
|
" eieio\n" \
|
|
|
|
"2:\n" \
|
|
|
|
".section .fixup,\"ax\"\n" \
|
|
|
|
"3: li %1,-1\n" \
|
|
|
|
" li %0,%3\n" \
|
|
|
|
" b 2b\n" \
|
|
|
|
".section __ex_table,\"a\"\n" \
|
|
|
|
" .align 2\n" \
|
|
|
|
" .long 1b,3b\n" \
|
|
|
|
".text" \
|
|
|
|
: "=r" (err), "=r" (x) \
|
|
|
|
: "b" (addr), "i" (-EFAULT), "0" (err))
|
|
|
|
|
2011-11-12 12:02:28 +00:00
|
|
|
void __iomem *rio_regs_win;
|
2010-05-26 21:44:00 +00:00
|
|
|
|
2010-06-18 06:24:20 +00:00
|
|
|
#ifdef CONFIG_E500
|
2010-11-18 06:57:32 +00:00
|
|
|
int fsl_rio_mcheck_exception(struct pt_regs *regs)
|
2010-05-26 21:44:00 +00:00
|
|
|
{
|
2011-06-16 19:09:17 +00:00
|
|
|
const struct exception_table_entry *entry;
|
|
|
|
unsigned long reason;
|
2010-05-26 21:44:00 +00:00
|
|
|
|
2011-06-16 19:09:17 +00:00
|
|
|
if (!rio_regs_win)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
reason = in_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR));
|
|
|
|
if (reason & (RIO_LTLEDCSR_IER | RIO_LTLEDCSR_PRT)) {
|
|
|
|
/* Check if we are prepared to handle this fault */
|
|
|
|
entry = search_exception_tables(regs->nip);
|
|
|
|
if (entry) {
|
|
|
|
pr_debug("RIO: %s - MC Exception handled\n",
|
|
|
|
__func__);
|
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR),
|
|
|
|
0);
|
|
|
|
regs->msr |= MSR_RI;
|
|
|
|
regs->nip = entry->fixup;
|
|
|
|
return 1;
|
2010-05-26 21:44:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 06:57:32 +00:00
|
|
|
return 0;
|
2010-05-26 21:44:00 +00:00
|
|
|
}
|
2010-11-18 06:57:32 +00:00
|
|
|
EXPORT_SYMBOL_GPL(fsl_rio_mcheck_exception);
|
2010-06-18 06:24:20 +00:00
|
|
|
#endif
|
2010-05-26 21:44:00 +00:00
|
|
|
|
2005-11-07 09:00:19 +00:00
|
|
|
/**
|
2008-04-18 20:33:38 +00:00
|
|
|
* fsl_local_config_read - Generate a MPC85xx local config space read
|
2008-04-30 23:45:58 +00:00
|
|
|
* @mport: RapidIO master port info
|
2005-11-07 09:00:19 +00:00
|
|
|
* @index: ID of RapdiIO interface
|
|
|
|
* @offset: Offset into configuration space
|
|
|
|
* @len: Length (in bytes) of the maintenance transaction
|
|
|
|
* @data: Value to be read into
|
|
|
|
*
|
|
|
|
* Generates a MPC85xx local configuration space read. Returns %0 on
|
|
|
|
* success or %-EINVAL on failure.
|
|
|
|
*/
|
2008-04-18 20:33:41 +00:00
|
|
|
static int fsl_local_config_read(struct rio_mport *mport,
|
|
|
|
int index, u32 offset, int len, u32 *data)
|
2005-11-07 09:00:19 +00:00
|
|
|
{
|
2008-04-18 20:33:41 +00:00
|
|
|
struct rio_priv *priv = mport->priv;
|
2008-04-18 20:33:38 +00:00
|
|
|
pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index,
|
2011-11-12 12:02:28 +00:00
|
|
|
offset);
|
2008-04-18 20:33:41 +00:00
|
|
|
*data = in_be32(priv->regs_win + offset);
|
2005-11-07 09:00:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-18 20:33:38 +00:00
|
|
|
* fsl_local_config_write - Generate a MPC85xx local config space write
|
2008-04-30 23:45:58 +00:00
|
|
|
* @mport: RapidIO master port info
|
2005-11-07 09:00:19 +00:00
|
|
|
* @index: ID of RapdiIO interface
|
|
|
|
* @offset: Offset into configuration space
|
|
|
|
* @len: Length (in bytes) of the maintenance transaction
|
|
|
|
* @data: Value to be written
|
|
|
|
*
|
|
|
|
* Generates a MPC85xx local configuration space write. Returns %0 on
|
|
|
|
* success or %-EINVAL on failure.
|
|
|
|
*/
|
2008-04-18 20:33:41 +00:00
|
|
|
static int fsl_local_config_write(struct rio_mport *mport,
|
|
|
|
int index, u32 offset, int len, u32 data)
|
2005-11-07 09:00:19 +00:00
|
|
|
{
|
2008-04-18 20:33:41 +00:00
|
|
|
struct rio_priv *priv = mport->priv;
|
2005-11-07 09:00:19 +00:00
|
|
|
pr_debug
|
2011-11-12 12:02:28 +00:00
|
|
|
("fsl_local_config_write: index %d offset %8.8x data %8.8x\n",
|
|
|
|
index, offset, data);
|
2008-04-18 20:33:41 +00:00
|
|
|
out_be32(priv->regs_win + offset, data);
|
2005-11-07 09:00:19 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-18 20:33:38 +00:00
|
|
|
* fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
|
2008-04-30 23:45:58 +00:00
|
|
|
* @mport: RapidIO master port info
|
2005-11-07 09:00:19 +00:00
|
|
|
* @index: ID of RapdiIO interface
|
|
|
|
* @destid: Destination ID of transaction
|
|
|
|
* @hopcount: Number of hops to target device
|
|
|
|
* @offset: Offset into configuration space
|
|
|
|
* @len: Length (in bytes) of the maintenance transaction
|
|
|
|
* @val: Location to be read into
|
|
|
|
*
|
|
|
|
* Generates a MPC85xx read maintenance transaction. Returns %0 on
|
|
|
|
* success or %-EINVAL on failure.
|
|
|
|
*/
|
|
|
|
static int
|
2008-04-18 20:33:41 +00:00
|
|
|
fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid,
|
|
|
|
u8 hopcount, u32 offset, int len, u32 *val)
|
2005-11-07 09:00:19 +00:00
|
|
|
{
|
2008-04-18 20:33:41 +00:00
|
|
|
struct rio_priv *priv = mport->priv;
|
2005-11-07 09:00:19 +00:00
|
|
|
u8 *data;
|
2010-05-26 21:44:00 +00:00
|
|
|
u32 rval, err = 0;
|
2005-11-07 09:00:19 +00:00
|
|
|
|
|
|
|
pr_debug
|
2011-11-12 12:02:28 +00:00
|
|
|
("fsl_rio_config_read:"
|
|
|
|
" index %d destid %d hopcount %d offset %8.8x len %d\n",
|
2005-11-07 09:00:19 +00:00
|
|
|
index, destid, hopcount, offset, len);
|
2010-05-26 21:44:05 +00:00
|
|
|
|
|
|
|
/* 16MB maintenance window possible */
|
|
|
|
/* allow only aligned access to maintenance registers */
|
|
|
|
if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-04-18 20:33:41 +00:00
|
|
|
out_be32(&priv->maint_atmu_regs->rowtar,
|
2010-05-26 21:44:05 +00:00
|
|
|
(destid << 22) | (hopcount << 12) | (offset >> 12));
|
2011-11-12 12:02:28 +00:00
|
|
|
out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2010-05-26 21:44:05 +00:00
|
|
|
data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
|
2005-11-07 09:00:19 +00:00
|
|
|
switch (len) {
|
|
|
|
case 1:
|
2010-05-26 21:44:00 +00:00
|
|
|
__fsl_read_rio_config(rval, data, err, "lbz");
|
2005-11-07 09:00:19 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2010-05-26 21:44:00 +00:00
|
|
|
__fsl_read_rio_config(rval, data, err, "lhz");
|
2005-11-07 09:00:19 +00:00
|
|
|
break;
|
2010-05-26 21:44:05 +00:00
|
|
|
case 4:
|
2010-05-26 21:44:00 +00:00
|
|
|
__fsl_read_rio_config(rval, data, err, "lwz");
|
2005-11-07 09:00:19 +00:00
|
|
|
break;
|
2010-05-26 21:44:05 +00:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2005-11-07 09:00:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-26 21:44:00 +00:00
|
|
|
if (err) {
|
|
|
|
pr_debug("RIO: cfg_read error %d for %x:%x:%x\n",
|
|
|
|
err, destid, hopcount, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
*val = rval;
|
|
|
|
|
|
|
|
return err;
|
2005-11-07 09:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-18 20:33:38 +00:00
|
|
|
* fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
|
2008-04-30 23:45:58 +00:00
|
|
|
* @mport: RapidIO master port info
|
2005-11-07 09:00:19 +00:00
|
|
|
* @index: ID of RapdiIO interface
|
|
|
|
* @destid: Destination ID of transaction
|
|
|
|
* @hopcount: Number of hops to target device
|
|
|
|
* @offset: Offset into configuration space
|
|
|
|
* @len: Length (in bytes) of the maintenance transaction
|
|
|
|
* @val: Value to be written
|
|
|
|
*
|
|
|
|
* Generates an MPC85xx write maintenance transaction. Returns %0 on
|
|
|
|
* success or %-EINVAL on failure.
|
|
|
|
*/
|
|
|
|
static int
|
2008-04-18 20:33:41 +00:00
|
|
|
fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid,
|
|
|
|
u8 hopcount, u32 offset, int len, u32 val)
|
2005-11-07 09:00:19 +00:00
|
|
|
{
|
2008-04-18 20:33:41 +00:00
|
|
|
struct rio_priv *priv = mport->priv;
|
2005-11-07 09:00:19 +00:00
|
|
|
u8 *data;
|
|
|
|
pr_debug
|
2011-11-12 12:02:28 +00:00
|
|
|
("fsl_rio_config_write:"
|
|
|
|
"index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n",
|
2005-11-07 09:00:19 +00:00
|
|
|
index, destid, hopcount, offset, len, val);
|
2010-05-26 21:44:05 +00:00
|
|
|
|
|
|
|
/* 16MB maintenance windows possible */
|
|
|
|
/* allow only aligned access to maintenance registers */
|
|
|
|
if (offset > (0x1000000 - len) || !IS_ALIGNED(offset, len))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-04-18 20:33:41 +00:00
|
|
|
out_be32(&priv->maint_atmu_regs->rowtar,
|
2010-05-26 21:44:05 +00:00
|
|
|
(destid << 22) | (hopcount << 12) | (offset >> 12));
|
2011-11-12 12:02:28 +00:00
|
|
|
out_be32(&priv->maint_atmu_regs->rowtear, (destid >> 10));
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2010-05-26 21:44:05 +00:00
|
|
|
data = (u8 *) priv->maint_win + (offset & (RIO_MAINT_WIN_SIZE - 1));
|
2005-11-07 09:00:19 +00:00
|
|
|
switch (len) {
|
|
|
|
case 1:
|
|
|
|
out_8((u8 *) data, val);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
out_be16((u16 *) data, val);
|
|
|
|
break;
|
2010-05-26 21:44:05 +00:00
|
|
|
case 4:
|
2005-11-07 09:00:19 +00:00
|
|
|
out_be32((u32 *) data, val);
|
|
|
|
break;
|
2010-05-26 21:44:05 +00:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2005-11-07 09:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-12 12:02:28 +00:00
|
|
|
void fsl_rio_port_error_handler(struct rio_mport *port, int offset)
|
2010-11-18 06:57:53 +00:00
|
|
|
{
|
|
|
|
/*XXX: Error recovery is not implemented, we just clear errors */
|
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 0);
|
|
|
|
|
|
|
|
if (offset == 0) {
|
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_PORT1_EDCSR), 0);
|
2011-08-25 22:59:25 +00:00
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_PORT1_IECSR), IECSR_CLEAR);
|
2010-11-18 06:57:53 +00:00
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_ESCSR), ESCSR_CLEAR);
|
|
|
|
} else {
|
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_PORT2_EDCSR), 0);
|
2011-08-25 22:59:25 +00:00
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_PORT2_IECSR), IECSR_CLEAR);
|
2010-11-18 06:57:53 +00:00
|
|
|
out_be32((u32 *)(rio_regs_win + RIO_PORT2_ESCSR), ESCSR_CLEAR);
|
|
|
|
}
|
|
|
|
}
|
2008-04-18 20:33:44 +00:00
|
|
|
static inline void fsl_rio_info(struct device *dev, u32 ccsr)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
if (ccsr & 1) {
|
|
|
|
/* Serial phy */
|
|
|
|
switch (ccsr >> 30) {
|
|
|
|
case 0:
|
|
|
|
str = "1";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
str = "4";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
2009-06-28 06:26:10 +00:00
|
|
|
break;
|
2008-04-18 20:33:44 +00:00
|
|
|
}
|
|
|
|
dev_info(dev, "Hardware port width: %s\n", str);
|
|
|
|
|
|
|
|
switch ((ccsr >> 27) & 7) {
|
|
|
|
case 0:
|
|
|
|
str = "Single-lane 0";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
str = "Single-lane 2";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
str = "Four-lane";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dev_info(dev, "Training connection status: %s\n", str);
|
|
|
|
} else {
|
|
|
|
/* Parallel phy */
|
|
|
|
if (!(ccsr & 0x80000000))
|
|
|
|
dev_info(dev, "Output port operating in 8-bit mode\n");
|
|
|
|
if (!(ccsr & 0x08000000))
|
|
|
|
dev_info(dev, "Input port operating in 8-bit mode\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-07 09:00:19 +00:00
|
|
|
/**
|
2008-04-30 23:45:58 +00:00
|
|
|
* fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
|
2010-08-06 15:25:50 +00:00
|
|
|
* @dev: platform_device pointer
|
2005-11-07 09:00:19 +00:00
|
|
|
*
|
|
|
|
* Initializes MPC85xx RapidIO hardware interface, configures
|
|
|
|
* master port with system-specific info, and registers the
|
|
|
|
* master port with the RapidIO subsystem.
|
|
|
|
*/
|
2010-07-22 21:52:34 +00:00
|
|
|
int fsl_rio_setup(struct platform_device *dev)
|
2005-11-07 09:00:19 +00:00
|
|
|
{
|
|
|
|
struct rio_ops *ops;
|
|
|
|
struct rio_mport *port;
|
2008-04-18 20:33:41 +00:00
|
|
|
struct rio_priv *priv;
|
|
|
|
int rc = 0;
|
|
|
|
const u32 *dt_range, *cell;
|
|
|
|
struct resource regs;
|
|
|
|
int rlen;
|
2008-04-18 20:33:44 +00:00
|
|
|
u32 ccsr;
|
2008-04-18 20:33:41 +00:00
|
|
|
u64 law_start, law_size;
|
|
|
|
int paw, aw, sw;
|
|
|
|
|
2010-04-13 23:12:29 +00:00
|
|
|
if (!dev->dev.of_node) {
|
2008-04-18 20:33:41 +00:00
|
|
|
dev_err(&dev->dev, "Device OF-Node is NULL");
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
2010-04-13 23:12:29 +00:00
|
|
|
rc = of_address_to_resource(dev->dev.of_node, 0, ®s);
|
2008-04-18 20:33:41 +00:00
|
|
|
if (rc) {
|
|
|
|
dev_err(&dev->dev, "Can't get %s property 'reg'\n",
|
2010-04-13 23:12:29 +00:00
|
|
|
dev->dev.of_node->full_name);
|
2008-04-18 20:33:41 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
2011-11-12 12:02:28 +00:00
|
|
|
dev_info(&dev->dev, "Of-device full name %s\n",
|
|
|
|
dev->dev.of_node->full_name);
|
2009-05-13 22:02:24 +00:00
|
|
|
dev_info(&dev->dev, "Regs: %pR\n", ®s);
|
2008-04-18 20:33:41 +00:00
|
|
|
|
2010-04-13 23:12:29 +00:00
|
|
|
dt_range = of_get_property(dev->dev.of_node, "ranges", &rlen);
|
2008-04-18 20:33:41 +00:00
|
|
|
if (!dt_range) {
|
|
|
|
dev_err(&dev->dev, "Can't get %s property 'ranges'\n",
|
2010-04-13 23:12:29 +00:00
|
|
|
dev->dev.of_node->full_name);
|
2008-04-18 20:33:41 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get node address wide */
|
2010-04-13 23:12:29 +00:00
|
|
|
cell = of_get_property(dev->dev.of_node, "#address-cells", NULL);
|
2008-04-18 20:33:41 +00:00
|
|
|
if (cell)
|
|
|
|
aw = *cell;
|
|
|
|
else
|
2010-04-13 23:12:29 +00:00
|
|
|
aw = of_n_addr_cells(dev->dev.of_node);
|
2008-04-18 20:33:41 +00:00
|
|
|
/* Get node size wide */
|
2010-04-13 23:12:29 +00:00
|
|
|
cell = of_get_property(dev->dev.of_node, "#size-cells", NULL);
|
2008-04-18 20:33:41 +00:00
|
|
|
if (cell)
|
|
|
|
sw = *cell;
|
|
|
|
else
|
2010-04-13 23:12:29 +00:00
|
|
|
sw = of_n_size_cells(dev->dev.of_node);
|
2008-04-18 20:33:41 +00:00
|
|
|
/* Get parent address wide wide */
|
2010-04-13 23:12:29 +00:00
|
|
|
paw = of_n_addr_cells(dev->dev.of_node);
|
2008-04-18 20:33:41 +00:00
|
|
|
|
|
|
|
law_start = of_read_number(dt_range + aw, paw);
|
|
|
|
law_size = of_read_number(dt_range + aw + paw, sw);
|
|
|
|
|
|
|
|
dev_info(&dev->dev, "LAW start 0x%016llx, size 0x%016llx.\n",
|
|
|
|
law_start, law_size);
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2010-05-26 21:43:59 +00:00
|
|
|
ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL);
|
2009-08-07 07:00:34 +00:00
|
|
|
if (!ops) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_ops;
|
|
|
|
}
|
2008-04-18 20:33:38 +00:00
|
|
|
ops->lcread = fsl_local_config_read;
|
|
|
|
ops->lcwrite = fsl_local_config_write;
|
|
|
|
ops->cread = fsl_rio_config_read;
|
|
|
|
ops->cwrite = fsl_rio_config_write;
|
2010-05-26 21:44:00 +00:00
|
|
|
ops->pwenable = fsl_rio_pw_enable;
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2008-04-18 20:33:41 +00:00
|
|
|
port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
|
2009-08-07 07:00:34 +00:00
|
|
|
if (!port) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_port;
|
|
|
|
}
|
2005-11-07 09:00:19 +00:00
|
|
|
port->index = 0;
|
2008-04-18 20:33:41 +00:00
|
|
|
|
|
|
|
priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL);
|
|
|
|
if (!priv) {
|
|
|
|
printk(KERN_ERR "Can't alloc memory for 'priv'\n");
|
|
|
|
rc = -ENOMEM;
|
2009-08-07 07:00:34 +00:00
|
|
|
goto err_priv;
|
2008-04-18 20:33:41 +00:00
|
|
|
}
|
|
|
|
|
2005-11-07 09:00:19 +00:00
|
|
|
INIT_LIST_HEAD(&port->dbells);
|
|
|
|
port->iores.start = law_start;
|
2009-05-12 08:35:59 +00:00
|
|
|
port->iores.end = law_start + law_size - 1;
|
2005-11-07 09:00:19 +00:00
|
|
|
port->iores.flags = IORESOURCE_MEM;
|
2009-05-12 08:35:59 +00:00
|
|
|
port->iores.name = "rio_io_win";
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2011-03-23 23:43:06 +00:00
|
|
|
if (request_resource(&iomem_resource, &port->iores) < 0) {
|
|
|
|
dev_err(&dev->dev, "RIO: Error requesting master port region"
|
|
|
|
" 0x%016llx-0x%016llx\n",
|
|
|
|
(u64)port->iores.start, (u64)port->iores.end);
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_res;
|
|
|
|
}
|
|
|
|
|
2011-11-12 12:02:28 +00:00
|
|
|
priv->pwirq = irq_of_parse_and_map(dev->dev.of_node, 0);
|
|
|
|
dev_info(&dev->dev, "pwirq: %d\n", priv->pwirq);
|
2005-11-07 09:00:19 +00:00
|
|
|
strcpy(port->name, "RIO0 mport");
|
|
|
|
|
2009-04-18 17:48:52 +00:00
|
|
|
priv->dev = &dev->dev;
|
|
|
|
|
2005-11-07 09:00:19 +00:00
|
|
|
port->ops = ops;
|
2008-04-18 20:33:41 +00:00
|
|
|
port->priv = priv;
|
2010-10-27 22:34:34 +00:00
|
|
|
port->phys_efptr = 0x100;
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2011-06-09 16:13:32 +00:00
|
|
|
priv->regs_win = ioremap(regs.start, resource_size(®s));
|
2010-05-26 21:44:00 +00:00
|
|
|
rio_regs_win = priv->regs_win;
|
2008-04-18 20:33:42 +00:00
|
|
|
|
2008-04-18 20:33:44 +00:00
|
|
|
/* Probe the master port phy type */
|
|
|
|
ccsr = in_be32(priv->regs_win + RIO_CCSR);
|
|
|
|
port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL;
|
|
|
|
dev_info(&dev->dev, "RapidIO PHY type: %s\n",
|
|
|
|
(port->phy_type == RIO_PHY_PARALLEL) ? "parallel" :
|
|
|
|
((port->phy_type == RIO_PHY_SERIAL) ? "serial" :
|
|
|
|
"unknown"));
|
2008-04-18 20:33:44 +00:00
|
|
|
/* Checking the port training status */
|
|
|
|
if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
|
|
|
|
dev_err(&dev->dev, "Port is not ready. "
|
2011-11-12 12:02:28 +00:00
|
|
|
"Try to restart connection...\n");
|
2008-04-18 20:33:44 +00:00
|
|
|
switch (port->phy_type) {
|
|
|
|
case RIO_PHY_SERIAL:
|
|
|
|
/* Disable ports */
|
|
|
|
out_be32(priv->regs_win + RIO_CCSR, 0);
|
|
|
|
/* Set 1x lane */
|
|
|
|
setbits32(priv->regs_win + RIO_CCSR, 0x02000000);
|
|
|
|
/* Enable ports */
|
|
|
|
setbits32(priv->regs_win + RIO_CCSR, 0x00600000);
|
|
|
|
break;
|
|
|
|
case RIO_PHY_PARALLEL:
|
|
|
|
/* Disable ports */
|
|
|
|
out_be32(priv->regs_win + RIO_CCSR, 0x22000000);
|
|
|
|
/* Enable ports */
|
|
|
|
out_be32(priv->regs_win + RIO_CCSR, 0x44000000);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
msleep(100);
|
|
|
|
if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) {
|
|
|
|
dev_err(&dev->dev, "Port restart failed.\n");
|
|
|
|
rc = -ENOLINK;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
dev_info(&dev->dev, "Port restart success!\n");
|
|
|
|
}
|
|
|
|
fsl_rio_info(&dev->dev, ccsr);
|
2008-04-18 20:33:44 +00:00
|
|
|
|
2008-04-18 20:33:42 +00:00
|
|
|
port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR))
|
|
|
|
& RIO_PEF_CTLS) >> 4;
|
|
|
|
dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n",
|
|
|
|
port->sys_size ? 65536 : 256);
|
|
|
|
|
2011-04-14 22:22:14 +00:00
|
|
|
if (rio_register_mport(port))
|
|
|
|
goto err;
|
|
|
|
|
2010-10-27 22:34:34 +00:00
|
|
|
if (port->host_deviceid >= 0)
|
|
|
|
out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST |
|
|
|
|
RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED);
|
|
|
|
else
|
|
|
|
out_be32(priv->regs_win + RIO_GCCSR, 0x00000000);
|
|
|
|
|
2008-04-18 20:33:41 +00:00
|
|
|
priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win
|
|
|
|
+ RIO_ATMU_REGS_OFFSET);
|
|
|
|
priv->maint_atmu_regs = priv->atmu_regs + 1;
|
2008-04-18 20:33:44 +00:00
|
|
|
|
|
|
|
/* Set to receive any dist ID for serial RapidIO controller. */
|
|
|
|
if (port->phy_type == RIO_PHY_SERIAL)
|
|
|
|
out_be32((priv->regs_win + RIO_ISR_AACR), RIO_ISR_AACR_AA);
|
2005-11-07 09:00:19 +00:00
|
|
|
|
|
|
|
/* Configure maintenance transaction window */
|
2009-05-12 08:35:59 +00:00
|
|
|
out_be32(&priv->maint_atmu_regs->rowbar, law_start >> 12);
|
2010-05-26 21:44:05 +00:00
|
|
|
out_be32(&priv->maint_atmu_regs->rowar,
|
|
|
|
0x80077000 | (ilog2(RIO_MAINT_WIN_SIZE) - 1));
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2008-04-18 20:33:41 +00:00
|
|
|
priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE);
|
2005-11-07 09:00:19 +00:00
|
|
|
|
2011-11-12 12:02:28 +00:00
|
|
|
fsl_rio_setup_rmu(port, dev->dev.of_node);
|
|
|
|
|
2010-05-26 21:44:00 +00:00
|
|
|
fsl_rio_port_write_init(port);
|
2008-04-18 20:33:41 +00:00
|
|
|
|
2008-04-18 20:33:41 +00:00
|
|
|
return 0;
|
2008-04-18 20:33:41 +00:00
|
|
|
err:
|
2009-08-07 07:00:34 +00:00
|
|
|
iounmap(priv->regs_win);
|
2011-11-02 20:39:07 +00:00
|
|
|
release_resource(&port->iores);
|
2011-03-23 23:43:06 +00:00
|
|
|
err_res:
|
2008-04-18 20:33:41 +00:00
|
|
|
kfree(priv);
|
2009-08-07 07:00:34 +00:00
|
|
|
err_priv:
|
2008-04-18 20:33:41 +00:00
|
|
|
kfree(port);
|
2009-08-07 07:00:34 +00:00
|
|
|
err_port:
|
|
|
|
kfree(ops);
|
|
|
|
err_ops:
|
2008-04-18 20:33:41 +00:00
|
|
|
return rc;
|
2005-11-07 09:00:19 +00:00
|
|
|
}
|
2008-04-18 20:33:41 +00:00
|
|
|
|
|
|
|
/* The probe function for RapidIO peer-to-peer network.
|
|
|
|
*/
|
2011-02-23 02:59:54 +00:00
|
|
|
static int __devinit fsl_of_rio_rpn_probe(struct platform_device *dev)
|
2008-04-18 20:33:41 +00:00
|
|
|
{
|
|
|
|
printk(KERN_INFO "Setting up RapidIO peer-to-peer network %s\n",
|
2010-04-13 23:12:29 +00:00
|
|
|
dev->dev.of_node->full_name);
|
2008-04-18 20:33:41 +00:00
|
|
|
|
2011-03-23 23:43:04 +00:00
|
|
|
return fsl_rio_setup(dev);
|
2008-04-18 20:33:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct of_device_id fsl_of_rio_rpn_ids[] = {
|
|
|
|
{
|
|
|
|
.compatible = "fsl,rapidio-delta",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2011-02-23 02:59:54 +00:00
|
|
|
static struct platform_driver fsl_of_rio_rpn_driver = {
|
2010-04-13 23:13:02 +00:00
|
|
|
.driver = {
|
|
|
|
.name = "fsl-of-rio",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = fsl_of_rio_rpn_ids,
|
|
|
|
},
|
2008-04-18 20:33:41 +00:00
|
|
|
.probe = fsl_of_rio_rpn_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static __init int fsl_of_rio_rpn_init(void)
|
|
|
|
{
|
2011-02-23 02:59:54 +00:00
|
|
|
return platform_driver_register(&fsl_of_rio_rpn_driver);
|
2008-04-18 20:33:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(fsl_of_rio_rpn_init);
|