2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Support code for the SCOOP interface found on various Sharp PDAs
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Richard Purdie
|
|
|
|
*
|
|
|
|
* Based on code written by Sharp/Lineo for 2.4 kernels
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
2005-10-30 16:03:48 -07:00
|
|
|
#include <linux/string.h>
|
2006-01-08 02:02:05 -07:00
|
|
|
#include <linux/slab.h>
|
2005-10-29 12:07:23 -06:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/hardware/scoop.h>
|
|
|
|
|
2006-04-18 16:18:53 -06:00
|
|
|
/* PCMCIA to Scoop linkage
|
|
|
|
|
|
|
|
There is no easy way to link multiple scoop devices into one
|
|
|
|
single entity for the pxa2xx_pcmcia device so this structure
|
|
|
|
is used which is setup by the platform code.
|
|
|
|
|
|
|
|
This file is never modular so this symbol is always
|
|
|
|
accessile to the board support files.
|
|
|
|
*/
|
|
|
|
struct scoop_pcmcia_config *platform_scoop_config;
|
|
|
|
EXPORT_SYMBOL(platform_scoop_config);
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
struct scoop_dev {
|
2008-04-09 15:43:37 -06:00
|
|
|
void __iomem *base;
|
2005-04-16 16:20:36 -06:00
|
|
|
spinlock_t scoop_lock;
|
2005-10-10 03:20:06 -06:00
|
|
|
unsigned short suspend_clr;
|
|
|
|
unsigned short suspend_set;
|
2005-04-16 16:20:36 -06:00
|
|
|
u32 scoop_gpwr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void reset_scoop(struct device *dev)
|
|
|
|
{
|
|
|
|
struct scoop_dev *sdev = dev_get_drvdata(dev);
|
|
|
|
|
2008-04-09 16:05:09 -06:00
|
|
|
iowrite16(0x0100, sdev->base + SCOOP_MCR); // 00
|
|
|
|
iowrite16(0x0000, sdev->base + SCOOP_CDR); // 04
|
|
|
|
iowrite16(0x0000, sdev->base + SCOOP_CCR); // 10
|
|
|
|
iowrite16(0x0000, sdev->base + SCOOP_IMR); // 18
|
|
|
|
iowrite16(0x00FF, sdev->base + SCOOP_IRM); // 14
|
|
|
|
iowrite16(0x0000, sdev->base + SCOOP_ISR); // 1C
|
|
|
|
iowrite16(0x0000, sdev->base + SCOOP_IRM);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short set_scoop_gpio(struct device *dev, unsigned short bit)
|
|
|
|
{
|
|
|
|
unsigned short gpio_bit;
|
|
|
|
unsigned long flag;
|
|
|
|
struct scoop_dev *sdev = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sdev->scoop_lock, flag);
|
2008-04-09 16:05:09 -06:00
|
|
|
gpio_bit = ioread16(sdev->base + SCOOP_GPWR) | bit;
|
|
|
|
iowrite16(gpio_bit, sdev->base + SCOOP_GPWR);
|
2005-04-16 16:20:36 -06:00
|
|
|
spin_unlock_irqrestore(&sdev->scoop_lock, flag);
|
|
|
|
|
|
|
|
return gpio_bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short reset_scoop_gpio(struct device *dev, unsigned short bit)
|
|
|
|
{
|
|
|
|
unsigned short gpio_bit;
|
|
|
|
unsigned long flag;
|
|
|
|
struct scoop_dev *sdev = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sdev->scoop_lock, flag);
|
2008-04-09 16:05:09 -06:00
|
|
|
gpio_bit = ioread16(sdev->base + SCOOP_GPWR) & ~bit;
|
|
|
|
iowrite16(gpio_bit, sdev->base + SCOOP_GPWR);
|
2005-04-16 16:20:36 -06:00
|
|
|
spin_unlock_irqrestore(&sdev->scoop_lock, flag);
|
|
|
|
|
|
|
|
return gpio_bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(set_scoop_gpio);
|
|
|
|
EXPORT_SYMBOL(reset_scoop_gpio);
|
|
|
|
|
|
|
|
unsigned short read_scoop_reg(struct device *dev, unsigned short reg)
|
|
|
|
{
|
|
|
|
struct scoop_dev *sdev = dev_get_drvdata(dev);
|
2008-04-09 16:05:09 -06:00
|
|
|
return ioread16(sdev->base + reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data)
|
|
|
|
{
|
|
|
|
struct scoop_dev *sdev = dev_get_drvdata(dev);
|
2008-04-09 16:05:09 -06:00
|
|
|
iowrite16(data, sdev->base + reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(reset_scoop);
|
|
|
|
EXPORT_SYMBOL(read_scoop_reg);
|
|
|
|
EXPORT_SYMBOL(write_scoop_reg);
|
|
|
|
|
2005-10-10 03:20:06 -06:00
|
|
|
static void check_scoop_reg(struct scoop_dev *sdev)
|
|
|
|
{
|
|
|
|
unsigned short mcr;
|
|
|
|
|
2008-04-09 16:05:09 -06:00
|
|
|
mcr = ioread16(sdev->base + SCOOP_MCR);
|
2005-10-10 03:20:06 -06:00
|
|
|
if ((mcr & 0x100) == 0)
|
2008-04-09 16:05:09 -06:00
|
|
|
iowrite16(0x0101, sdev->base + SCOOP_MCR);
|
2005-10-10 03:20:06 -06:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef CONFIG_PM
|
2005-11-09 15:32:44 -07:00
|
|
|
static int scoop_suspend(struct platform_device *dev, pm_message_t state)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-09 15:32:44 -07:00
|
|
|
struct scoop_dev *sdev = platform_get_drvdata(dev);
|
2005-10-28 10:52:56 -06:00
|
|
|
|
|
|
|
check_scoop_reg(sdev);
|
2008-04-09 16:05:09 -06:00
|
|
|
sdev->scoop_gpwr = ioread16(sdev->base + SCOOP_GPWR);
|
|
|
|
iowrite16((sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set, sdev->base + SCOOP_GPWR);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
static int scoop_resume(struct platform_device *dev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-09 15:32:44 -07:00
|
|
|
struct scoop_dev *sdev = platform_get_drvdata(dev);
|
2005-10-28 10:52:56 -06:00
|
|
|
|
|
|
|
check_scoop_reg(sdev);
|
2008-04-09 16:05:09 -06:00
|
|
|
iowrite16(sdev->scoop_gpwr, sdev->base + SCOOP_GPWR);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define scoop_suspend NULL
|
|
|
|
#define scoop_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2008-04-09 15:43:37 -06:00
|
|
|
static int __devinit scoop_probe(struct platform_device *pdev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct scoop_dev *devptr;
|
|
|
|
struct scoop_config *inf;
|
|
|
|
struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
|
|
|
|
if (!mem)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2006-03-20 12:46:41 -07:00
|
|
|
devptr = kzalloc(sizeof(struct scoop_dev), GFP_KERNEL);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!devptr)
|
2006-03-20 12:46:41 -07:00
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
spin_lock_init(&devptr->scoop_lock);
|
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
inf = pdev->dev.platform_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
devptr->base = ioremap(mem->start, mem->end - mem->start + 1);
|
|
|
|
|
|
|
|
if (!devptr->base) {
|
|
|
|
kfree(devptr);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
platform_set_drvdata(pdev, devptr);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-09 15:43:37 -06:00
|
|
|
printk("Sharp Scoop Device found at 0x%08x -> 0x%8p\n",(unsigned int)mem->start, devptr->base);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-09 16:05:09 -06:00
|
|
|
iowrite16(0x0140, devptr->base + SCOOP_MCR);
|
2005-11-12 13:25:25 -07:00
|
|
|
reset_scoop(&pdev->dev);
|
2008-04-09 16:05:09 -06:00
|
|
|
iowrite16(0x0000, devptr->base + SCOOP_CPR);
|
|
|
|
iowrite16(inf->io_dir & 0xffff, devptr->base + SCOOP_GPCR);
|
|
|
|
iowrite16(inf->io_out & 0xffff, devptr->base + SCOOP_GPWR);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-10-10 03:20:06 -06:00
|
|
|
devptr->suspend_clr = inf->suspend_clr;
|
|
|
|
devptr->suspend_set = inf->suspend_set;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-09 15:43:37 -06:00
|
|
|
static int __devexit scoop_remove(struct platform_device *pdev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-09 15:32:44 -07:00
|
|
|
struct scoop_dev *sdev = platform_get_drvdata(pdev);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (sdev) {
|
|
|
|
iounmap(sdev->base);
|
|
|
|
kfree(sdev);
|
2005-11-09 15:32:44 -07:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
static struct platform_driver scoop_driver = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.probe = scoop_probe,
|
2008-04-09 15:43:37 -06:00
|
|
|
.remove = __devexit_p(scoop_remove),
|
2005-04-16 16:20:36 -06:00
|
|
|
.suspend = scoop_suspend,
|
|
|
|
.resume = scoop_resume,
|
2005-11-09 15:32:44 -07:00
|
|
|
.driver = {
|
|
|
|
.name = "sharp-scoop",
|
|
|
|
},
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2008-04-09 15:43:37 -06:00
|
|
|
static int __init scoop_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-09 15:32:44 -07:00
|
|
|
return platform_driver_register(&scoop_driver);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(scoop_init);
|