2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* linux/drivers/pcmcia/sa1111_generic.c
|
|
|
|
*
|
|
|
|
* We implement the generic parts of a SA1111 PCMCIA driver. This
|
|
|
|
* basically means we handle everything except controlling the
|
|
|
|
* power. Power is machine specific...
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
2009-03-25 10:21:35 +00:00
|
|
|
#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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <pcmcia/ss.h>
|
|
|
|
|
2008-08-05 15:14:15 +00:00
|
|
|
#include <mach/hardware.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/hardware/sa1111.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
#include "sa1111_generic.h"
|
|
|
|
|
2012-01-16 11:32:09 +00:00
|
|
|
/*
|
|
|
|
* These are offsets from the above base.
|
|
|
|
*/
|
|
|
|
#define PCCR 0x0000
|
|
|
|
#define PCSSR 0x0004
|
|
|
|
#define PCSR 0x0008
|
|
|
|
|
|
|
|
#define PCSR_S0_READY (1<<0)
|
|
|
|
#define PCSR_S1_READY (1<<1)
|
|
|
|
#define PCSR_S0_DETECT (1<<2)
|
|
|
|
#define PCSR_S1_DETECT (1<<3)
|
|
|
|
#define PCSR_S0_VS1 (1<<4)
|
|
|
|
#define PCSR_S0_VS2 (1<<5)
|
|
|
|
#define PCSR_S1_VS1 (1<<6)
|
|
|
|
#define PCSR_S1_VS2 (1<<7)
|
|
|
|
#define PCSR_S0_WP (1<<8)
|
|
|
|
#define PCSR_S1_WP (1<<9)
|
|
|
|
#define PCSR_S0_BVD1 (1<<10)
|
|
|
|
#define PCSR_S0_BVD2 (1<<11)
|
|
|
|
#define PCSR_S1_BVD1 (1<<12)
|
|
|
|
#define PCSR_S1_BVD2 (1<<13)
|
|
|
|
|
|
|
|
#define PCCR_S0_RST (1<<0)
|
|
|
|
#define PCCR_S1_RST (1<<1)
|
|
|
|
#define PCCR_S0_FLT (1<<2)
|
|
|
|
#define PCCR_S1_FLT (1<<3)
|
|
|
|
#define PCCR_S0_PWAITEN (1<<4)
|
|
|
|
#define PCCR_S1_PWAITEN (1<<5)
|
|
|
|
#define PCCR_S0_PSE (1<<6)
|
|
|
|
#define PCCR_S1_PSE (1<<7)
|
|
|
|
|
|
|
|
#define PCSSR_S0_SLEEP (1<<0)
|
|
|
|
#define PCSSR_S1_SLEEP (1<<1)
|
|
|
|
|
2009-12-26 04:32:38 +00:00
|
|
|
#define IDX_IRQ_S0_READY_NINT (0)
|
|
|
|
#define IDX_IRQ_S0_CD_VALID (1)
|
|
|
|
#define IDX_IRQ_S0_BVD1_STSCHG (2)
|
|
|
|
#define IDX_IRQ_S1_READY_NINT (3)
|
|
|
|
#define IDX_IRQ_S1_CD_VALID (4)
|
|
|
|
#define IDX_IRQ_S1_BVD1_STSCHG (5)
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
|
|
|
|
{
|
2009-03-29 18:42:44 +00:00
|
|
|
struct sa1111_pcmcia_socket *s = to_skt(skt);
|
2012-01-16 11:32:09 +00:00
|
|
|
unsigned long status = sa1111_readl(s->dev->mapbase + PCSR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (skt->nr) {
|
|
|
|
case 0:
|
|
|
|
state->detect = status & PCSR_S0_DETECT ? 0 : 1;
|
|
|
|
state->ready = status & PCSR_S0_READY ? 1 : 0;
|
|
|
|
state->bvd1 = status & PCSR_S0_BVD1 ? 1 : 0;
|
|
|
|
state->bvd2 = status & PCSR_S0_BVD2 ? 1 : 0;
|
|
|
|
state->wrprot = status & PCSR_S0_WP ? 1 : 0;
|
|
|
|
state->vs_3v = status & PCSR_S0_VS1 ? 0 : 1;
|
|
|
|
state->vs_Xv = status & PCSR_S0_VS2 ? 0 : 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
state->detect = status & PCSR_S1_DETECT ? 0 : 1;
|
|
|
|
state->ready = status & PCSR_S1_READY ? 1 : 0;
|
|
|
|
state->bvd1 = status & PCSR_S1_BVD1 ? 1 : 0;
|
|
|
|
state->bvd2 = status & PCSR_S1_BVD2 ? 1 : 0;
|
|
|
|
state->wrprot = status & PCSR_S1_WP ? 1 : 0;
|
|
|
|
state->vs_3v = status & PCSR_S1_VS1 ? 0 : 1;
|
|
|
|
state->vs_Xv = status & PCSR_S1_VS2 ? 0 : 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
|
|
|
|
{
|
2009-03-29 18:42:44 +00:00
|
|
|
struct sa1111_pcmcia_socket *s = to_skt(skt);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int pccr_skt_mask, pccr_set_mask, val;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
switch (skt->nr) {
|
|
|
|
case 0:
|
|
|
|
pccr_skt_mask = PCCR_S0_RST|PCCR_S0_FLT|PCCR_S0_PWAITEN|PCCR_S0_PSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
pccr_skt_mask = PCCR_S1_RST|PCCR_S1_FLT|PCCR_S1_PWAITEN|PCCR_S1_PSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pccr_set_mask = 0;
|
|
|
|
|
|
|
|
if (state->Vcc != 0)
|
|
|
|
pccr_set_mask |= PCCR_S0_PWAITEN|PCCR_S1_PWAITEN;
|
|
|
|
if (state->Vcc == 50)
|
|
|
|
pccr_set_mask |= PCCR_S0_PSE|PCCR_S1_PSE;
|
|
|
|
if (state->flags & SS_RESET)
|
|
|
|
pccr_set_mask |= PCCR_S0_RST|PCCR_S1_RST;
|
|
|
|
if (state->flags & SS_OUTPUT_ENA)
|
|
|
|
pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
2012-01-16 11:32:09 +00:00
|
|
|
val = sa1111_readl(s->dev->mapbase + PCCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
val &= ~pccr_skt_mask;
|
|
|
|
val |= pccr_set_mask & pccr_skt_mask;
|
2012-01-16 11:32:09 +00:00
|
|
|
sa1111_writel(val, s->dev->mapbase + PCCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-29 18:42:44 +00:00
|
|
|
int sa1111_pcmcia_add(struct sa1111_dev *dev, struct pcmcia_low_level *ops,
|
|
|
|
int (*add)(struct soc_pcmcia_socket *))
|
|
|
|
{
|
|
|
|
struct sa1111_pcmcia_socket *s;
|
|
|
|
int i, ret = 0;
|
|
|
|
|
2009-03-29 21:35:11 +00:00
|
|
|
ops->socket_state = sa1111_pcmcia_socket_state;
|
|
|
|
|
2009-03-29 18:42:44 +00:00
|
|
|
for (i = 0; i < ops->nr; i++) {
|
|
|
|
s = kzalloc(sizeof(*s), GFP_KERNEL);
|
|
|
|
if (!s)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
s->soc.nr = ops->first + i;
|
2011-12-19 14:07:31 +00:00
|
|
|
soc_pcmcia_init_one(&s->soc, ops, &dev->dev);
|
2009-03-29 18:42:44 +00:00
|
|
|
s->dev = dev;
|
2011-12-19 23:04:22 +00:00
|
|
|
if (s->soc.nr) {
|
|
|
|
s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S1_READY_NINT];
|
|
|
|
s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S1_CD_VALID];
|
|
|
|
s->soc.stat[SOC_STAT_CD].name = "SA1111 CF card detect";
|
|
|
|
s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S1_BVD1_STSCHG];
|
|
|
|
s->soc.stat[SOC_STAT_BVD1].name = "SA1111 CF BVD1";
|
|
|
|
} else {
|
|
|
|
s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S0_READY_NINT];
|
|
|
|
s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S0_CD_VALID];
|
|
|
|
s->soc.stat[SOC_STAT_CD].name = "SA1111 PCMCIA card detect";
|
|
|
|
s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S0_BVD1_STSCHG];
|
|
|
|
s->soc.stat[SOC_STAT_BVD1].name = "SA1111 PCMCIA BVD1";
|
|
|
|
}
|
2009-03-29 18:42:44 +00:00
|
|
|
|
|
|
|
ret = add(&s->soc);
|
|
|
|
if (ret == 0) {
|
|
|
|
s->next = dev_get_drvdata(&dev->dev);
|
|
|
|
dev_set_drvdata(&dev->dev, s);
|
|
|
|
} else
|
|
|
|
kfree(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
static int pcmcia_probe(struct sa1111_dev *dev)
|
|
|
|
{
|
2005-10-28 13:29:43 +00:00
|
|
|
void __iomem *base;
|
2012-01-26 13:25:47 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sa1111_enable_device(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-29 18:42:44 +00:00
|
|
|
dev_set_drvdata(&dev->dev, NULL);
|
|
|
|
|
2012-01-26 13:25:47 +00:00
|
|
|
if (!request_mem_region(dev->res.start, 512, SA1111_DRIVER_NAME(dev))) {
|
|
|
|
sa1111_disable_device(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
2012-01-26 13:25:47 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
base = dev->mapbase;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the suspend state.
|
|
|
|
*/
|
2012-01-16 11:32:09 +00:00
|
|
|
sa1111_writel(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + PCSSR);
|
|
|
|
sa1111_writel(PCCR_S0_FLT | PCCR_S1_FLT, base + PCCR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SA1100_BADGE4
|
|
|
|
pcmcia_badge4_init(&dev->dev);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SA1100_JORNADA720
|
|
|
|
pcmcia_jornada720_init(&dev->dev);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ARCH_LUBBOCK
|
|
|
|
pcmcia_lubbock_init(dev);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_ASSABET_NEPONSET
|
|
|
|
pcmcia_neponset_init(dev);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit pcmcia_remove(struct sa1111_dev *dev)
|
|
|
|
{
|
2009-03-29 18:42:44 +00:00
|
|
|
struct sa1111_pcmcia_socket *next, *s = dev_get_drvdata(&dev->dev);
|
2009-03-26 22:21:18 +00:00
|
|
|
|
|
|
|
dev_set_drvdata(&dev->dev, NULL);
|
|
|
|
|
2012-01-24 21:33:26 +00:00
|
|
|
for (; s; s = next) {
|
|
|
|
next = s->next;
|
2009-03-29 18:42:44 +00:00
|
|
|
soc_pcmcia_remove_one(&s->soc);
|
|
|
|
kfree(s);
|
|
|
|
}
|
2009-03-26 22:21:18 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
release_mem_region(dev->res.start, 512);
|
2012-01-26 13:25:47 +00:00
|
|
|
sa1111_disable_device(dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sa1111_driver pcmcia_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "sa1111-pcmcia",
|
|
|
|
},
|
|
|
|
.devid = SA1111_DEVID_PCMCIA,
|
|
|
|
.probe = pcmcia_probe,
|
2012-11-19 18:20:38 +00:00
|
|
|
.remove = pcmcia_remove,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init sa1111_drv_pcmcia_init(void)
|
|
|
|
{
|
|
|
|
return sa1111_driver_register(&pcmcia_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sa1111_drv_pcmcia_exit(void)
|
|
|
|
{
|
|
|
|
sa1111_driver_unregister(&pcmcia_driver);
|
|
|
|
}
|
|
|
|
|
2005-09-03 18:39:25 +00:00
|
|
|
fs_initcall(sa1111_drv_pcmcia_init);
|
2005-04-16 22:20:36 +00:00
|
|
|
module_exit(sa1111_drv_pcmcia_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver");
|
|
|
|
MODULE_LICENSE("GPL");
|