Commit 9fd1d0c7 authored by John Lenz's avatar John Lenz Committed by Russell King

[ARM PATCH] 1937/1: LoCoMo common device

Patch from John Lenz

Cleanup and forward port of patch 1849.
This patch provides support for the SHARP LoCoMo device, 
a companion chip similar to the sa1111 device.  It is present
in many of the SHARP Zaurus line of PDAs.
parent afb7238d
......@@ -222,6 +222,11 @@ config SA1111
depends on ASSABET_NEPONSET || SA1100_ADSBITSY || SA1100_BADGE4 || SA1100_CONSUS || SA1100_GRAPHICSMASTER || SA1100_JORNADA720 || ARCH_LUBBOCK || SA1100_PFS168 || SA1100_PT_SYSTEM3 || SA1100_XP860
default y
config SHARP_LOCOMO
bool
depends on SA1100_COLLIE
default y
config FORCE_MAX_ZONEORDER
int
depends on SA1111
......
......@@ -8,3 +8,4 @@ obj-$(CONFIG_SA1111) += sa1111.o
obj-$(CONFIG_PCI_HOST_VIA82C505) += via82c505.o
obj-$(CONFIG_DMABOUNCE) += dmabounce.o
obj-$(CONFIG_TIMER_ACORN) += time-acorn.o
obj-$(CONFIG_SHARP_LOCOMO) += locomo.o
/*
* linux/arch/arm/common/locomo.c
*
* Sharp LoCoMo support
*
* 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.
*
* This file contains all generic LoCoMo support.
*
* All initialization functions provided here are intended to be called
* from machine specific code with proper arguments when required.
*
* Based on sa1111.c
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/ioport.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <asm/hardware.h>
#include <asm/mach-types.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/mach/irq.h>
#include <asm/hardware/locomo.h>
/* the following is the overall data for the locomo chip */
struct locomo {
struct device *dev;
unsigned long phys;
unsigned int irq;
void *base;
};
struct locomo_dev_info {
unsigned long offset;
unsigned long length;
unsigned int devid;
unsigned int irq[1];
const char * name;
};
static struct locomo_dev_info locomo_devices[] = {
};
/** LoCoMo interrupt handling stuff.
* NOTE: LoCoMo has a 1 to many mapping on all of its IRQs.
* that is, there is only one real hardware interrupt
* we determine which interrupt it is by reading some IO memory.
* We have two levels of expansion, first in the handler for the
* hardware interrupt we generate an interrupt
* IRQ_LOCOMO_*_BASE and those handlers generate more interrupts
*
* hardware irq reads LOCOMO_ICR & 0x0f00
* IRQ_LOCOMO_KEY_BASE
* IRQ_LOCOMO_GPIO_BASE
* IRQ_LOCOMO_LT_BASE
* IRQ_LOCOMO_SPI_BASE
* IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
* IRQ_LOCOMO_KEY
* IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff
* IRQ_LOCOMO_GPIO[0-15]
* IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001
* IRQ_LOCOMO_LT
* IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
* IRQ_LOCOMO_SPI_RFR
* IRQ_LOCOMO_SPI_RFW
* IRQ_LOCOMO_SPI_OVRN
* IRQ_LOCOMO_SPI_TEND
*/
#define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE)
#define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY)
#define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0)
#define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT)
#define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR)
static void locomo_handler(unsigned int irq, struct irqdesc *desc,
struct pt_regs *regs)
{
int req, i;
struct irqdesc *d;
void *mapbase = get_irq_chipdata(irq);
/* Acknowledge the parent IRQ */
desc->chip->ack(irq);
/* check why this interrupt was generated */
req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00;
if (req) {
/* generate the next interrupt(s) */
irq = LOCOMO_IRQ_START;
d = irq_desc + irq;
for (i = 0; i <= 3; i++, d++, irq++) {
if (req & (0x0100 << i)) {
d->handle(irq, d, regs);
}
}
}
}
static void locomo_ack_irq(unsigned int irq)
{
}
static void locomo_mask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_ICR);
r &= ~(0x0010 << (irq - LOCOMO_IRQ_START));
locomo_writel(r, mapbase + LOCOMO_ICR);
}
static void locomo_unmask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_ICR);
r |= (0x0010 << (irq - LOCOMO_IRQ_START));
locomo_writel(r, mapbase + LOCOMO_ICR);
}
static struct irqchip locomo_chip = {
.ack = locomo_ack_irq,
.mask = locomo_mask_irq,
.unmask = locomo_unmask_irq,
};
static void locomo_key_handler(unsigned int irq, struct irqdesc *desc,
struct pt_regs *regs)
{
struct irqdesc *d;
void *mapbase = get_irq_chipdata(irq);
if (locomo_readl(mapbase + LOCOMO_KIC) & 0x0001) {
d = irq_desc + LOCOMO_IRQ_KEY_START;
d->handle(LOCOMO_IRQ_KEY_START, d, regs);
}
}
static void locomo_key_ack_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_KIC);
r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START));
locomo_writel(r, mapbase + LOCOMO_KIC);
}
static void locomo_key_mask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_KIC);
r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START));
locomo_writel(r, mapbase + LOCOMO_KIC);
}
static void locomo_key_unmask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_KIC);
r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START));
locomo_writel(r, mapbase + LOCOMO_KIC);
}
static struct irqchip locomo_key_chip = {
.ack = locomo_key_ack_irq,
.mask = locomo_key_mask_irq,
.unmask = locomo_key_unmask_irq,
};
static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc,
struct pt_regs *regs)
{
int req, i;
struct irqdesc *d;
void *mapbase = get_irq_chipdata(irq);
req = locomo_readl(mapbase + LOCOMO_GIR) &
locomo_readl(mapbase + LOCOMO_GPD) &
0xffff;
if (req) {
irq = LOCOMO_IRQ_GPIO_START;
d = irq_desc + LOCOMO_IRQ_GPIO_START;
for (i = 0; i <= 15; i++, irq++, d++) {
if (req & (0x0001 << i)) {
d->handle(irq, d, regs);
}
}
}
}
static void locomo_gpio_ack_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_GWE);
r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
locomo_writel(r, mapbase + LOCOMO_GWE);
r = locomo_readl(mapbase + LOCOMO_GIS);
r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
locomo_writel(r, mapbase + LOCOMO_GIS);
r = locomo_readl(mapbase + LOCOMO_GWE);
r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
locomo_writel(r, mapbase + LOCOMO_GWE);
}
static void locomo_gpio_mask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_GIE);
r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
locomo_writel(r, mapbase + LOCOMO_GIE);
}
static void locomo_gpio_unmask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_GIE);
r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
locomo_writel(r, mapbase + LOCOMO_GIE);
}
static struct irqchip locomo_gpio_chip = {
.ack = locomo_gpio_ack_irq,
.mask = locomo_gpio_mask_irq,
.unmask = locomo_gpio_unmask_irq,
};
static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc,
struct pt_regs *regs)
{
struct irqdesc *d;
void *mapbase = get_irq_chipdata(irq);
if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) {
d = irq_desc + LOCOMO_IRQ_LT_START;
d->handle(LOCOMO_IRQ_LT_START, d, regs);
}
}
static void locomo_lt_ack_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_LTINT);
r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START));
locomo_writel(r, mapbase + LOCOMO_LTINT);
}
static void locomo_lt_mask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_LTINT);
r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START));
locomo_writel(r, mapbase + LOCOMO_LTINT);
}
static void locomo_lt_unmask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_LTINT);
r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START));
locomo_writel(r, mapbase + LOCOMO_LTINT);
}
static struct irqchip locomo_lt_chip = {
.ack = locomo_lt_ack_irq,
.mask = locomo_lt_mask_irq,
.unmask = locomo_lt_unmask_irq,
};
static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc,
struct pt_regs *regs)
{
int req, i;
struct irqdesc *d;
void *mapbase = get_irq_chipdata(irq);
req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F;
if (req) {
irq = LOCOMO_IRQ_SPI_START;
d = irq_desc + irq;
for (i = 0; i <= 3; i++, irq++, d++) {
if (req & (0x0001 << i)) {
d->handle(irq, d, regs);
}
}
}
}
static void locomo_spi_ack_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_SPIWE);
r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
locomo_writel(r, mapbase + LOCOMO_SPIWE);
r = locomo_readl(mapbase + LOCOMO_SPIIS);
r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
locomo_writel(r, mapbase + LOCOMO_SPIIS);
r = locomo_readl(mapbase + LOCOMO_SPIWE);
r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
locomo_writel(r, mapbase + LOCOMO_SPIWE);
}
static void locomo_spi_mask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_SPIIE);
r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
locomo_writel(r, mapbase + LOCOMO_SPIIE);
}
static void locomo_spi_unmask_irq(unsigned int irq)
{
void *mapbase = get_irq_chipdata(irq);
unsigned int r;
r = locomo_readl(mapbase + LOCOMO_SPIIE);
r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
locomo_writel(r, mapbase + LOCOMO_SPIIE);
}
static struct irqchip locomo_spi_chip = {
.ack = locomo_spi_ack_irq,
.mask = locomo_spi_mask_irq,
.unmask = locomo_spi_unmask_irq,
};
static void locomo_setup_irq(struct locomo *lchip)
{
int irq;
void *irqbase = lchip->base;
/*
* Install handler for IRQ_LOCOMO_HW.
*/
set_irq_type(lchip->irq, IRQT_FALLING);
set_irq_chipdata(lchip->irq, irqbase);
set_irq_chained_handler(lchip->irq, locomo_handler);
/* Install handlers for IRQ_LOCOMO_*_BASE */
set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip);
set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase);
set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler);
set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE);
set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip);
set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase);
set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler);
set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE);
set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip);
set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase);
set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler);
set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE);
set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip);
set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase);
set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler);
set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE);
/* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip);
set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase);
set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ);
set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE);
/* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) {
set_irq_chip(irq, &locomo_gpio_chip);
set_irq_chipdata(irq, irqbase);
set_irq_handler(irq, do_edge_IRQ);
set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
}
/* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip);
set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase);
set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ);
set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE);
/* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) {
set_irq_chip(irq, &locomo_spi_chip);
set_irq_chipdata(irq, irqbase);
set_irq_handler(irq, do_edge_IRQ);
set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
}
}
static void locomo_dev_release(struct device *_dev)
{
struct locomo_dev *dev = LOCOMO_DEV(_dev);
release_resource(&dev->res);
kfree(dev);
}
static int
locomo_init_one_child(struct locomo *lchip, struct resource *parent,
struct locomo_dev_info *info)
{
struct locomo_dev *dev;
int ret;
dev = kmalloc(sizeof(struct locomo_dev), GFP_KERNEL);
if (!dev) {
ret = -ENOMEM;
goto out;
}
memset(dev, 0, sizeof(struct locomo_dev));
strncpy(dev->dev.bus_id,info->name,sizeof(dev->dev.bus_id));
/*
* If the parent device has a DMA mask associated with it,
* propagate it down to the children.
*/
if (lchip->dev->dma_mask) {
dev->dma_mask = *lchip->dev->dma_mask;
dev->dev.dma_mask = &dev->dma_mask;
}
dev->devid = info->devid;
dev->dev.parent = lchip->dev;
dev->dev.bus = &locomo_bus_type;
dev->dev.release = locomo_dev_release;
dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
dev->res.start = lchip->phys + info->offset;
dev->res.end = dev->res.start + info->length;
dev->res.name = dev->dev.bus_id;
dev->res.flags = IORESOURCE_MEM;
dev->mapbase = lchip->base + info->offset;
memmove(dev->irq, info->irq, sizeof(dev->irq));
if (info->length) {
ret = request_resource(parent, &dev->res);
if (ret) {
printk("LoCoMo: failed to allocate resource for %s\n",
dev->res.name);
goto out;
}
}
ret = device_register(&dev->dev);
if (ret) {
release_resource(&dev->res);
out:
kfree(dev);
}
return ret;
}
/**
* locomo_probe - probe for a single LoCoMo chip.
* @phys_addr: physical address of device.
*
* Probe for a LoCoMo chip. This must be called
* before any other locomo-specific code.
*
* Returns:
* %-ENODEV device not found.
* %-EBUSY physical address already marked in-use.
* %0 successful.
*/
static int
__locomo_probe(struct device *me, struct resource *mem, int irq)
{
struct locomo *lchip;
unsigned long r;
int i, ret = -ENODEV;
lchip = kmalloc(sizeof(struct locomo), GFP_KERNEL);
if (!lchip)
return -ENOMEM;
memset(lchip, 0, sizeof(struct locomo));
lchip->dev = me;
dev_set_drvdata(lchip->dev, lchip);
lchip->phys = mem->start;
lchip->irq = irq;
/*
* Map the whole region. This also maps the
* registers for our children.
*/
lchip->base = ioremap(mem->start, PAGE_SIZE);
if (!lchip->base) {
ret = -ENOMEM;
goto out;
}
/* locomo initialize */
locomo_writel(0, lchip->base + LOCOMO_ICR);
/* KEYBOARD */
locomo_writel(0, lchip->base + LOCOMO_KIC);
/* GPIO */
locomo_writel(0, lchip->base + LOCOMO_GPO);
locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
, lchip->base + LOCOMO_GPE);
locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
, lchip->base + LOCOMO_GPD);
locomo_writel(0, lchip->base + LOCOMO_GIE);
/* FrontLight */
locomo_writel(0, lchip->base + LOCOMO_ALS);
locomo_writel(0, lchip->base + LOCOMO_ALD);
/* Longtime timer */
locomo_writel(0, lchip->base + LOCOMO_LTINT);
/* SPI */
locomo_writel(0, lchip->base + LOCOMO_SPIIE);
locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
r = locomo_readl(lchip->base + LOCOMO_ASD);
r |= 0x8000;
locomo_writel(r, lchip->base + LOCOMO_ASD);
locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
r = locomo_readl(lchip->base + LOCOMO_HSD);
r |= 0x8000;
locomo_writel(r, lchip->base + LOCOMO_HSD);
locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
/* XON */
locomo_writel(0x80, lchip->base + LOCOMO_TADC);
udelay(1000);
/* CLK9MEN */
r = locomo_readl(lchip->base + LOCOMO_TADC);
r |= 0x10;
locomo_writel(r, lchip->base + LOCOMO_TADC);
udelay(100);
/* init DAC */
r = locomo_readl(lchip->base + LOCOMO_DAC);
r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
locomo_writel(r, lchip->base + LOCOMO_DAC);
r = locomo_readl(lchip->base + LOCOMO_VER);
printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
/*
* The interrupt controller must be initialised before any
* other device to ensure that the interrupts are available.
*/
if (lchip->irq != NO_IRQ)
locomo_setup_irq(lchip);
for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
locomo_init_one_child(lchip, mem, &locomo_devices[i]);
return 0;
out:
kfree(lchip);
return ret;
}
static void __locomo_remove(struct locomo *lchip)
{
struct list_head *l, *n;
list_for_each_safe(l, n, &lchip->dev->children) {
struct device *d = list_to_dev(l);
device_unregister(d);
}
if (lchip->irq != NO_IRQ) {
set_irq_chained_handler(lchip->irq, NULL);
set_irq_data(lchip->irq, NULL);
}
iounmap(lchip->base);
kfree(lchip);
}
static int locomo_probe(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct resource *mem = NULL, *irq = NULL;
int i;
for (i = 0; i < pdev->num_resources; i++) {
if (pdev->resource[i].flags & IORESOURCE_MEM)
mem = &pdev->resource[i];
if (pdev->resource[i].flags & IORESOURCE_IRQ)
irq = &pdev->resource[i];
}
return __locomo_probe(dev, mem, irq ? irq->start : NO_IRQ);
}
static int locomo_remove(struct device *dev)
{
struct locomo *lchip = dev_get_drvdata(dev);
if (lchip) {
__locomo_remove(lchip);
dev_set_drvdata(dev, NULL);
kfree(dev->saved_state);
dev->saved_state = NULL;
}
return 0;
}
/*
* Not sure if this should be on the system bus or not yet.
* We really want some way to register a system device at
* the per-machine level, and then have this driver pick
* up the registered devices.
*/
static struct device_driver locomo_device_driver = {
.name = "locomo",
.bus = &platform_bus_type,
.probe = locomo_probe,
.remove = locomo_remove,
};
/*
* Get the parent device driver (us) structure
* from a child function device
*/
static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
{
return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
}
/*
* LoCoMo "Register Access Bus."
*
* We model this as a regular bus type, and hang devices directly
* off this.
*/
static int locomo_match(struct device *_dev, struct device_driver *_drv)
{
struct locomo_dev *dev = LOCOMO_DEV(_dev);
struct locomo_driver *drv = LOCOMO_DRV(_drv);
return dev->devid == drv->devid;
}
static int locomo_bus_suspend(struct device *dev, u32 state)
{
struct locomo_dev *ldev = LOCOMO_DEV(dev);
struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
int ret = 0;
if (drv && drv->suspend)
ret = drv->suspend(ldev, state);
return ret;
}
static int locomo_bus_resume(struct device *dev)
{
struct locomo_dev *ldev = LOCOMO_DEV(dev);
struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
int ret = 0;
if (drv && drv->resume)
ret = drv->resume(ldev);
return ret;
}
static int locomo_bus_probe(struct device *dev)
{
struct locomo_dev *ldev = LOCOMO_DEV(dev);
struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
int ret = -ENODEV;
if (drv->probe)
ret = drv->probe(ldev);
return ret;
}
static int locomo_bus_remove(struct device *dev)
{
struct locomo_dev *ldev = LOCOMO_DEV(dev);
struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
int ret = 0;
if (drv->remove)
ret = drv->remove(ldev);
return ret;
}
struct bus_type locomo_bus_type = {
.name = "locomo-bus",
.match = locomo_match,
.suspend = locomo_bus_suspend,
.resume = locomo_bus_resume,
};
int locomo_driver_register(struct locomo_driver *driver)
{
driver->drv.probe = locomo_bus_probe;
driver->drv.remove = locomo_bus_remove;
driver->drv.bus = &locomo_bus_type;
return driver_register(&driver->drv);
}
void locomo_driver_unregister(struct locomo_driver *driver)
{
driver_unregister(&driver->drv);
}
static int __init locomo_init(void)
{
int ret = bus_register(&locomo_bus_type);
if (ret == 0)
driver_register(&locomo_device_driver);
return ret;
}
static void __exit locomo_exit(void)
{
driver_unregister(&locomo_device_driver);
bus_unregister(&locomo_bus_type);
}
module_init(locomo_init);
module_exit(locomo_exit);
MODULE_DESCRIPTION("Sharp LoCoMo core driver");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("John Lenz <jelenz@students.wisc.edu>");
EXPORT_SYMBOL(locomo_driver_register);
EXPORT_SYMBOL(locomo_driver_unregister);
......@@ -121,10 +121,35 @@
#define IRQ_S0_BVD1_STSCHG (IRQ_BOARD_END + 53)
#define IRQ_S1_BVD1_STSCHG (IRQ_BOARD_END + 54)
#define IRQ_LOCOMO_START (IRQ_BOARD_END)
#define IRQ_LOCOMO_KEY (IRQ_BOARD_END + 0)
#define IRQ_LOCOMO_GPIO0 (IRQ_BOARD_END + 1)
#define IRQ_LOCOMO_GPIO1 (IRQ_BOARD_END + 2)
#define IRQ_LOCOMO_GPIO2 (IRQ_BOARD_END + 3)
#define IRQ_LOCOMO_GPIO3 (IRQ_BOARD_END + 4)
#define IRQ_LOCOMO_GPIO4 (IRQ_BOARD_END + 5)
#define IRQ_LOCOMO_GPIO5 (IRQ_BOARD_END + 6)
#define IRQ_LOCOMO_GPIO6 (IRQ_BOARD_END + 7)
#define IRQ_LOCOMO_GPIO7 (IRQ_BOARD_END + 8)
#define IRQ_LOCOMO_GPIO8 (IRQ_BOARD_END + 9)
#define IRQ_LOCOMO_GPIO9 (IRQ_BOARD_END + 10)
#define IRQ_LOCOMO_GPIO10 (IRQ_BOARD_END + 11)
#define IRQ_LOCOMO_GPIO11 (IRQ_BOARD_END + 12)
#define IRQ_LOCOMO_GPIO12 (IRQ_BOARD_END + 13)
#define IRQ_LOCOMO_GPIO13 (IRQ_BOARD_END + 14)
#define IRQ_LOCOMO_GPIO14 (IRQ_BOARD_END + 15)
#define IRQ_LOCOMO_GPIO15 (IRQ_BOARD_END + 16)
#define IRQ_LOCOMO_LT (IRQ_BOARD_END + 17)
#define IRQ_LOCOMO_SPI_RFR (IRQ_BOARD_END + 18)
#define IRQ_LOCOMO_SPI_RFW (IRQ_BOARD_END + 19)
#define IRQ_LOCOMO_SPI_OVRN (IRQ_BOARD_END + 20)
#define IRQ_LOCOMO_SPI_TEND (IRQ_BOARD_END + 21)
/*
* Figure out the MAX IRQ number.
*
* If we have an SA1111, the max IRQ is S1_BVD1_STSCHG+1.
* If we have an LoCoMo, the max IRQ is IRQ_LOCOMO_SPI_TEND+1
* If graphicsclient or graphicsmaster, we don't have a SA1111.
* Otherwise, we have the standard IRQs only.
*/
......@@ -134,6 +159,8 @@
defined(CONFIG_SA1100_GRAPHICSMASTER) || \
defined(CONFIG_SA1100_H3800)
#define NR_IRQS (IRQ_BOARD_END)
#elif defined(CONFIG_SHARP_LOCOMO)
#define NR_IRQS (IRQ_LOCOMO_SPI_TEND + 1)
#else
#define NR_IRQS (IRQ_BOARD_START)
#endif
......@@ -150,6 +177,12 @@
#define IRQ_SYSTEM3_SA1111 (IRQ_BOARD_START + 0)
#define IRQ_SYSTEM3_SMC9196 (IRQ_BOARD_START + 1)
/* LoCoMo Interrupts (CONFIG_SHARP_LOCOMO) */
#define IRQ_LOCOMO_KEY_BASE (IRQ_BOARD_START + 0)
#define IRQ_LOCOMO_GPIO_BASE (IRQ_BOARD_START + 1)
#define IRQ_LOCOMO_LT_BASE (IRQ_BOARD_START + 2)
#define IRQ_LOCOMO_SPI_BASE (IRQ_BOARD_START + 3)
/* H3800-specific IRQs (CONFIG_SA1100_H3800) */
#define H3800_KPIO_IRQ_START (IRQ_BOARD_START)
#define IRQ_H3800_KEY (IRQ_BOARD_START + 0)
......
/*
* linux/include/asm-arm/hardware/locomo.h
*
* This file contains the definitions for the LoCoMo G/A Chip
*
* (C) Copyright 2004 John Lenz
*
* May be copied or modified under the terms of the GNU General Public
* License. See linux/COPYING for more information.
*
* Based on sa1111.h
*/
#ifndef _ASM_ARCH_LOCOMO
#define _ASM_ARCH_LOCOMO
#define locomo_writel(val,addr) ({ *(volatile u16 *)(addr) = (val); })
#define locomo_readl(addr) (*(volatile u16 *)(addr))
/* LOCOMO version */
#define LOCOMO_VER 0x00
/* Pin status */
#define LOCOMO_ST 0x04
/* Pin status */
#define LOCOMO_C32K 0x08
/* Interrupt controller */
#define LOCOMO_ICR 0x0C
/* MCS decoder for boot selecting */
#define LOCOMO_MCSX0 0x10
#define LOCOMO_MCSX1 0x14
#define LOCOMO_MCSX2 0x18
#define LOCOMO_MCSX3 0x1c
/* Touch panel controller */
#define LOCOMO_ASD 0x20 /* AD start delay */
#define LOCOMO_HSD 0x28 /* HSYS delay */
#define LOCOMO_HSC 0x2c /* HSYS period */
#define LOCOMO_TADC 0x30 /* tablet ADC clock */
/* TFT signal */
#define LOCOMO_TC 0x38 /* TFT control signal */
#define LOCOMO_CPSD 0x3c /* CPS delay */
/* Key controller */
#define LOCOMO_KIB 0x40 /* KIB level */
#define LOCOMO_KSC 0x44 /* KSTRB control */
#define LOCOMO_KCMD 0x48 /* KSTRB command */
#define LOCOMO_KIC 0x4c /* Key interrupt */
/* Audio clock */
#define LOCOMO_ACC 0x54
/* SPI interface */
#define LOCOMO_SPIMD 0x60 /* SPI mode setting */
#define LOCOMO_SPICT 0x64 /* SPI mode control */
#define LOCOMO_SPIST 0x68 /* SPI status */
#define LOCOMO_SPIIS 0x70 /* SPI interrupt status */
#define LOCOMO_SPIWE 0x74 /* SPI interrupt status write enable */
#define LOCOMO_SPIIE 0x78 /* SPI interrupt enable */
#define LOCOMO_SPIIR 0x7c /* SPI interrupt request */
#define LOCOMO_SPITD 0x80 /* SPI transfer data write */
#define LOCOMO_SPIRD 0x84 /* SPI receive data read */
#define LOCOMO_SPITS 0x88 /* SPI transfer data shift */
#define LOCOMO_SPIRS 0x8C /* SPI receive data shift */
#define LOCOMO_SPI_TEND (1 << 3) /* Transfer end bit */
#define LOCOMO_SPI_OVRN (1 << 2) /* Over Run bit */
#define LOCOMO_SPI_RFW (1 << 1) /* write buffer bit */
#define LOCOMO_SPI_RFR (1) /* read buffer bit */
/* GPIO */
#define LOCOMO_GPD 0x90 /* GPIO direction */
#define LOCOMO_GPE 0x94 /* GPIO input enable */
#define LOCOMO_GPL 0x98 /* GPIO level */
#define LOCOMO_GPO 0x9c /* GPIO out data setteing */
#define LOCOMO_GRIE 0xa0 /* GPIO rise detection */
#define LOCOMO_GFIE 0xa4 /* GPIO fall detection */
#define LOCOMO_GIS 0xa8 /* GPIO edge detection status */
#define LOCOMO_GWE 0xac /* GPIO status write enable */
#define LOCOMO_GIE 0xb0 /* GPIO interrupt enable */
#define LOCOMO_GIR 0xb4 /* GPIO interrupt request */
#define LOCOMO_GPIO0 (1<<0)
#define LOCOMO_GPIO1 (1<<1)
#define LOCOMO_GPIO2 (1<<2)
#define LOCOMO_GPIO3 (1<<3)
#define LOCOMO_GPIO4 (1<<4)
#define LOCOMO_GPIO5 (1<<5)
#define LOCOMO_GPIO6 (1<<6)
#define LOCOMO_GPIO7 (1<<7)
#define LOCOMO_GPIO8 (1<<8)
#define LOCOMO_GPIO9 (1<<9)
#define LOCOMO_GPIO10 (1<<10)
#define LOCOMO_GPIO11 (1<<11)
#define LOCOMO_GPIO12 (1<<12)
#define LOCOMO_GPIO13 (1<<13)
#define LOCOMO_GPIO14 (1<<14)
#define LOCOMO_GPIO15 (1<<15)
/* Front light adjustment controller */
#define LOCOMO_ALS 0xc8 /* Adjust light cycle */
#define LOCOMO_ALD 0xcc /* Adjust light duty */
/* PCM audio interface */
#define LOCOMO_PAIF 0xd0
/* Long time timer */
#define LOCOMO_LTC 0xd8 /* LTC interrupt setting */
#define LOCOMO_LTINT 0xdc /* LTC interrupt */
/* DAC control signal for LCD (COMADJ ) */
#define LOCOMO_DAC 0xe0
/* DAC control */
#define LOCOMO_DAC_SCLOEB 0x08 /* SCL pin output data */
#define LOCOMO_DAC_TEST 0x04 /* Test bit */
#define LOCOMO_DAC_SDA 0x02 /* SDA pin level (read-only) */
#define LOCOMO_DAC_SDAOEB 0x01 /* SDA pin output data */
/* LED controller */
#define LOCOMO_LPT0 0xe8 /* LEDPWM0 timer */
#define LOCOMO_LPT1 0xec /* LEDPWM1 timer */
#define LOCOMO_LPT_TOFH 0x80 /* */
#define LOCOMO_LPT_TOFL 0x08 /* */
#define LOCOMO_LPT_TOH(TOH) ((TOH & 0x7) << 4) /* */
#define LOCOMO_LPT_TOL(TOL) ((TOL & 0x7)) /* */
/* Audio clock */
#define LOCOMO_ACC_XON 0x80 /* */
#define LOCOMO_ACC_XEN 0x40 /* */
#define LOCOMO_ACC_XSEL0 0x00 /* */
#define LOCOMO_ACC_XSEL1 0x20 /* */
#define LOCOMO_ACC_MCLKEN 0x10 /* */
#define LOCOMO_ACC_64FSEN 0x08 /* */
#define LOCOMO_ACC_CLKSEL000 0x00 /* mclk 2 */
#define LOCOMO_ACC_CLKSEL001 0x01 /* mclk 3 */
#define LOCOMO_ACC_CLKSEL010 0x02 /* mclk 4 */
#define LOCOMO_ACC_CLKSEL011 0x03 /* mclk 6 */
#define LOCOMO_ACC_CLKSEL100 0x04 /* mclk 8 */
#define LOCOMO_ACC_CLKSEL101 0x05 /* mclk 12 */
/* PCM audio interface */
#define LOCOMO_PAIF_SCINV 0x20 /* */
#define LOCOMO_PAIF_SCEN 0x10 /* */
#define LOCOMO_PAIF_LRCRST 0x08 /* */
#define LOCOMO_PAIF_LRCEVE 0x04 /* */
#define LOCOMO_PAIF_LRCINV 0x02 /* */
#define LOCOMO_PAIF_LRCEN 0x01 /* */
/* GPIO */
#define LOCOMO_GPIO(Nb) (0x01 << (Nb)) /* LoCoMo GPIO [0...15] */
#define LOCOMO_GPIO_RTS LOCOMO_GPIO(0) /* LoCoMo GPIO [0] */
#define LOCOMO_GPIO_CTS LOCOMO_GPIO(1) /* LoCoMo GPIO [1] */
#define LOCOMO_GPIO_DSR LOCOMO_GPIO(2) /* LoCoMo GPIO [2] */
#define LOCOMO_GPIO_DTR LOCOMO_GPIO(3) /* LoCoMo GPIO [3] */
#define LOCOMO_GPIO_LCD_VSHA_ON LOCOMO_GPIO(4) /* LoCoMo GPIO [4] */
#define LOCOMO_GPIO_LCD_VSHD_ON LOCOMO_GPIO(5) /* LoCoMo GPIO [5] */
#define LOCOMO_GPIO_LCD_VEE_ON LOCOMO_GPIO(6) /* LoCoMo GPIO [6] */
#define LOCOMO_GPIO_LCD_MOD LOCOMO_GPIO(7) /* LoCoMo GPIO [7] */
#define LOCOMO_GPIO_DAC_ON LOCOMO_GPIO(8) /* LoCoMo GPIO [8] */
#define LOCOMO_GPIO_FL_VR LOCOMO_GPIO(9) /* LoCoMo GPIO [9] */
#define LOCOMO_GPIO_DAC_SDATA LOCOMO_GPIO(10) /* LoCoMo GPIO [10] */
#define LOCOMO_GPIO_DAC_SCK LOCOMO_GPIO(11) /* LoCoMo GPIO [11] */
#define LOCOMO_GPIO_DAC_SLOAD LOCOMO_GPIO(12) /* LoCoMo GPIO [12] */
extern struct bus_type locomo_bus_type;
struct locomo_dev {
struct device dev;
unsigned int devid;
struct resource res;
void *mapbase;
unsigned int irq[1];
u64 dma_mask;
};
#define LOCOMO_DEV(_d) container_of((_d), struct locomo_dev, dev)
#define locomo_get_drvdata(d) dev_get_drvdata(&(d)->dev)
#define locomo_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, p)
struct locomo_driver {
struct device_driver drv;
unsigned int devid;
int (*probe)(struct locomo_dev *);
int (*remove)(struct locomo_dev *);
int (*suspend)(struct locomo_dev *, u32);
int (*resume)(struct locomo_dev *);
};
#define LOCOMO_DRV(_d) container_of((_d), struct locomo_driver, drv)
#define LOCOMO_DRIVER_NAME(_ldev) ((_ldev)->dev.driver->name)
void locomo_lcd_power(struct locomo_dev *, int, unsigned int);
int locomo_driver_register(struct locomo_driver *);
void locomo_driver_unregister(struct locomo_driver *);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment