2 * Support code for the SCOOP interface found on various Sharp PDAs
4 * Copyright (c) 2004 Richard Purdie
6 * Based on code written by Sharp/Lineo for 2.4 kernels
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 #include <linux/device.h>
15 #include <linux/string.h>
16 #include <linux/platform_device.h>
18 #include <asm/hardware/scoop.h>
20 #define SCOOP_REG(d,adr) (*(volatile unsigned short*)(d +(adr)))
24 spinlock_t scoop_lock;
25 unsigned short suspend_clr;
26 unsigned short suspend_set;
30 void reset_scoop(struct device *dev)
32 struct scoop_dev *sdev = dev_get_drvdata(dev);
34 SCOOP_REG(sdev->base,SCOOP_MCR) = 0x0100; // 00
35 SCOOP_REG(sdev->base,SCOOP_CDR) = 0x0000; // 04
36 SCOOP_REG(sdev->base,SCOOP_CPR) = 0x0000; // 0C
37 SCOOP_REG(sdev->base,SCOOP_CCR) = 0x0000; // 10
38 SCOOP_REG(sdev->base,SCOOP_IMR) = 0x0000; // 18
39 SCOOP_REG(sdev->base,SCOOP_IRM) = 0x00FF; // 14
40 SCOOP_REG(sdev->base,SCOOP_ISR) = 0x0000; // 1C
41 SCOOP_REG(sdev->base,SCOOP_IRM) = 0x0000;
44 unsigned short set_scoop_gpio(struct device *dev, unsigned short bit)
46 unsigned short gpio_bit;
48 struct scoop_dev *sdev = dev_get_drvdata(dev);
50 spin_lock_irqsave(&sdev->scoop_lock, flag);
51 gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) | bit;
52 SCOOP_REG(sdev->base, SCOOP_GPWR) = gpio_bit;
53 spin_unlock_irqrestore(&sdev->scoop_lock, flag);
58 unsigned short reset_scoop_gpio(struct device *dev, unsigned short bit)
60 unsigned short gpio_bit;
62 struct scoop_dev *sdev = dev_get_drvdata(dev);
64 spin_lock_irqsave(&sdev->scoop_lock, flag);
65 gpio_bit = SCOOP_REG(sdev->base, SCOOP_GPWR) & ~bit;
66 SCOOP_REG(sdev->base,SCOOP_GPWR) = gpio_bit;
67 spin_unlock_irqrestore(&sdev->scoop_lock, flag);
72 EXPORT_SYMBOL(set_scoop_gpio);
73 EXPORT_SYMBOL(reset_scoop_gpio);
75 unsigned short read_scoop_reg(struct device *dev, unsigned short reg)
77 struct scoop_dev *sdev = dev_get_drvdata(dev);
78 return SCOOP_REG(sdev->base,reg);
81 void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data)
83 struct scoop_dev *sdev = dev_get_drvdata(dev);
84 SCOOP_REG(sdev->base,reg)=data;
87 EXPORT_SYMBOL(reset_scoop);
88 EXPORT_SYMBOL(read_scoop_reg);
89 EXPORT_SYMBOL(write_scoop_reg);
91 static void check_scoop_reg(struct scoop_dev *sdev)
95 mcr = SCOOP_REG(sdev->base, SCOOP_MCR);
96 if ((mcr & 0x100) == 0)
97 SCOOP_REG(sdev->base, SCOOP_MCR) = 0x0101;
101 static int scoop_suspend(struct device *dev, pm_message_t state)
103 struct scoop_dev *sdev = dev_get_drvdata(dev);
105 check_scoop_reg(sdev);
106 sdev->scoop_gpwr = SCOOP_REG(sdev->base, SCOOP_GPWR);
107 SCOOP_REG(sdev->base, SCOOP_GPWR) = (sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set;
112 static int scoop_resume(struct device *dev)
114 struct scoop_dev *sdev = dev_get_drvdata(dev);
116 check_scoop_reg(sdev);
117 SCOOP_REG(sdev->base,SCOOP_GPWR) = sdev->scoop_gpwr;
122 #define scoop_suspend NULL
123 #define scoop_resume NULL
126 int __init scoop_probe(struct device *dev)
128 struct scoop_dev *devptr;
129 struct scoop_config *inf;
130 struct platform_device *pdev = to_platform_device(dev);
131 struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
136 devptr = kmalloc(sizeof(struct scoop_dev), GFP_KERNEL);
141 memset(devptr, 0, sizeof(struct scoop_dev));
142 spin_lock_init(&devptr->scoop_lock);
144 inf = dev->platform_data;
145 devptr->base = ioremap(mem->start, mem->end - mem->start + 1);
152 dev_set_drvdata(dev, devptr);
154 printk("Sharp Scoop Device found at 0x%08x -> 0x%08x\n",(unsigned int)mem->start,(unsigned int)devptr->base);
156 SCOOP_REG(devptr->base, SCOOP_MCR) = 0x0140;
158 SCOOP_REG(devptr->base, SCOOP_GPCR) = inf->io_dir & 0xffff;
159 SCOOP_REG(devptr->base, SCOOP_GPWR) = inf->io_out & 0xffff;
161 devptr->suspend_clr = inf->suspend_clr;
162 devptr->suspend_set = inf->suspend_set;
167 static int scoop_remove(struct device *dev)
169 struct scoop_dev *sdev = dev_get_drvdata(dev);
173 dev_set_drvdata(dev, NULL);
178 static struct device_driver scoop_driver = {
179 .name = "sharp-scoop",
180 .bus = &platform_bus_type,
181 .probe = scoop_probe,
182 .remove = scoop_remove,
183 .suspend = scoop_suspend,
184 .resume = scoop_resume,
187 int __init scoop_init(void)
189 return driver_register(&scoop_driver);
192 subsys_initcall(scoop_init);