~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/common/scoop.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Support code for the SCOOP interface found on various Sharp PDAs
  4  *
  5  * Copyright (c) 2004 Richard Purdie
  6  *
  7  *      Based on code written by Sharp/Lineo for 2.4 kernels
  8  */
  9 
 10 #include <linux/device.h>
 11 #include <linux/gpio/driver.h>
 12 #include <linux/string.h>
 13 #include <linux/slab.h>
 14 #include <linux/platform_device.h>
 15 #include <linux/export.h>
 16 #include <linux/io.h>
 17 #include <asm/hardware/scoop.h>
 18 
 19 /* PCMCIA to Scoop linkage
 20 
 21    There is no easy way to link multiple scoop devices into one
 22    single entity for the pxa2xx_pcmcia device so this structure
 23    is used which is setup by the platform code.
 24 
 25    This file is never modular so this symbol is always
 26    accessile to the board support files.
 27 */
 28 struct scoop_pcmcia_config *platform_scoop_config;
 29 EXPORT_SYMBOL(platform_scoop_config);
 30 
 31 struct  scoop_dev {
 32         void __iomem *base;
 33         struct gpio_chip gpio;
 34         spinlock_t scoop_lock;
 35         unsigned short suspend_clr;
 36         unsigned short suspend_set;
 37         u32 scoop_gpwr;
 38 };
 39 
 40 void reset_scoop(struct device *dev)
 41 {
 42         struct scoop_dev *sdev = dev_get_drvdata(dev);
 43 
 44         iowrite16(0x0100, sdev->base + SCOOP_MCR);  /* 00 */
 45         iowrite16(0x0000, sdev->base + SCOOP_CDR);  /* 04 */
 46         iowrite16(0x0000, sdev->base + SCOOP_CCR);  /* 10 */
 47         iowrite16(0x0000, sdev->base + SCOOP_IMR);  /* 18 */
 48         iowrite16(0x00FF, sdev->base + SCOOP_IRM);  /* 14 */
 49         iowrite16(0x0000, sdev->base + SCOOP_ISR);  /* 1C */
 50         iowrite16(0x0000, sdev->base + SCOOP_IRM);
 51 }
 52 
 53 static void __scoop_gpio_set(struct scoop_dev *sdev,
 54                         unsigned offset, int value)
 55 {
 56         unsigned short gpwr;
 57 
 58         gpwr = ioread16(sdev->base + SCOOP_GPWR);
 59         if (value)
 60                 gpwr |= 1 << (offset + 1);
 61         else
 62                 gpwr &= ~(1 << (offset + 1));
 63         iowrite16(gpwr, sdev->base + SCOOP_GPWR);
 64 }
 65 
 66 static void scoop_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 67 {
 68         struct scoop_dev *sdev = gpiochip_get_data(chip);
 69         unsigned long flags;
 70 
 71         spin_lock_irqsave(&sdev->scoop_lock, flags);
 72 
 73         __scoop_gpio_set(sdev, offset, value);
 74 
 75         spin_unlock_irqrestore(&sdev->scoop_lock, flags);
 76 }
 77 
 78 static int scoop_gpio_get(struct gpio_chip *chip, unsigned offset)
 79 {
 80         struct scoop_dev *sdev = gpiochip_get_data(chip);
 81 
 82         /* XXX: I'm unsure, but it seems so */
 83         return !!(ioread16(sdev->base + SCOOP_GPRR) & (1 << (offset + 1)));
 84 }
 85 
 86 static int scoop_gpio_direction_input(struct gpio_chip *chip,
 87                         unsigned offset)
 88 {
 89         struct scoop_dev *sdev = gpiochip_get_data(chip);
 90         unsigned long flags;
 91         unsigned short gpcr;
 92 
 93         spin_lock_irqsave(&sdev->scoop_lock, flags);
 94 
 95         gpcr = ioread16(sdev->base + SCOOP_GPCR);
 96         gpcr &= ~(1 << (offset + 1));
 97         iowrite16(gpcr, sdev->base + SCOOP_GPCR);
 98 
 99         spin_unlock_irqrestore(&sdev->scoop_lock, flags);
100 
101         return 0;
102 }
103 
104 static int scoop_gpio_direction_output(struct gpio_chip *chip,
105                         unsigned offset, int value)
106 {
107         struct scoop_dev *sdev = gpiochip_get_data(chip);
108         unsigned long flags;
109         unsigned short gpcr;
110 
111         spin_lock_irqsave(&sdev->scoop_lock, flags);
112 
113         __scoop_gpio_set(sdev, offset, value);
114 
115         gpcr = ioread16(sdev->base + SCOOP_GPCR);
116         gpcr |= 1 << (offset + 1);
117         iowrite16(gpcr, sdev->base + SCOOP_GPCR);
118 
119         spin_unlock_irqrestore(&sdev->scoop_lock, flags);
120 
121         return 0;
122 }
123 
124 unsigned short read_scoop_reg(struct device *dev, unsigned short reg)
125 {
126         struct scoop_dev *sdev = dev_get_drvdata(dev);
127         return ioread16(sdev->base + reg);
128 }
129 
130 void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data)
131 {
132         struct scoop_dev *sdev = dev_get_drvdata(dev);
133         iowrite16(data, sdev->base + reg);
134 }
135 
136 EXPORT_SYMBOL(reset_scoop);
137 EXPORT_SYMBOL(read_scoop_reg);
138 EXPORT_SYMBOL(write_scoop_reg);
139 
140 #ifdef CONFIG_PM
141 static void check_scoop_reg(struct scoop_dev *sdev)
142 {
143         unsigned short mcr;
144 
145         mcr = ioread16(sdev->base + SCOOP_MCR);
146         if ((mcr & 0x100) == 0)
147                 iowrite16(0x0101, sdev->base + SCOOP_MCR);
148 }
149 
150 static int scoop_suspend(struct platform_device *dev, pm_message_t state)
151 {
152         struct scoop_dev *sdev = platform_get_drvdata(dev);
153 
154         check_scoop_reg(sdev);
155         sdev->scoop_gpwr = ioread16(sdev->base + SCOOP_GPWR);
156         iowrite16((sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set, sdev->base + SCOOP_GPWR);
157 
158         return 0;
159 }
160 
161 static int scoop_resume(struct platform_device *dev)
162 {
163         struct scoop_dev *sdev = platform_get_drvdata(dev);
164 
165         check_scoop_reg(sdev);
166         iowrite16(sdev->scoop_gpwr, sdev->base + SCOOP_GPWR);
167 
168         return 0;
169 }
170 #else
171 #define scoop_suspend   NULL
172 #define scoop_resume    NULL
173 #endif
174 
175 static int scoop_probe(struct platform_device *pdev)
176 {
177         struct scoop_dev *devptr;
178         struct scoop_config *inf;
179         struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
180         int ret;
181 
182         if (!mem)
183                 return -EINVAL;
184 
185         devptr = kzalloc(sizeof(struct scoop_dev), GFP_KERNEL);
186         if (!devptr)
187                 return -ENOMEM;
188 
189         spin_lock_init(&devptr->scoop_lock);
190 
191         inf = pdev->dev.platform_data;
192         devptr->base = ioremap(mem->start, resource_size(mem));
193 
194         if (!devptr->base) {
195                 ret = -ENOMEM;
196                 goto err_ioremap;
197         }
198 
199         platform_set_drvdata(pdev, devptr);
200 
201         printk("Sharp Scoop Device found at 0x%08x -> 0x%8p\n",(unsigned int)mem->start, devptr->base);
202 
203         iowrite16(0x0140, devptr->base + SCOOP_MCR);
204         reset_scoop(&pdev->dev);
205         iowrite16(0x0000, devptr->base + SCOOP_CPR);
206         iowrite16(inf->io_dir & 0xffff, devptr->base + SCOOP_GPCR);
207         iowrite16(inf->io_out & 0xffff, devptr->base + SCOOP_GPWR);
208 
209         devptr->suspend_clr = inf->suspend_clr;
210         devptr->suspend_set = inf->suspend_set;
211 
212         devptr->gpio.base = -1;
213 
214         if (inf->gpio_base != 0) {
215                 devptr->gpio.label = dev_name(&pdev->dev);
216                 devptr->gpio.base = inf->gpio_base;
217                 devptr->gpio.ngpio = 12; /* PA11 = 0, PA12 = 1, etc. up to PA22 = 11 */
218                 devptr->gpio.set = scoop_gpio_set;
219                 devptr->gpio.get = scoop_gpio_get;
220                 devptr->gpio.direction_input = scoop_gpio_direction_input;
221                 devptr->gpio.direction_output = scoop_gpio_direction_output;
222 
223                 ret = gpiochip_add_data(&devptr->gpio, devptr);
224                 if (ret)
225                         goto err_gpio;
226         }
227 
228         return 0;
229 
230 err_gpio:
231         platform_set_drvdata(pdev, NULL);
232 err_ioremap:
233         iounmap(devptr->base);
234         kfree(devptr);
235 
236         return ret;
237 }
238 
239 static void scoop_remove(struct platform_device *pdev)
240 {
241         struct scoop_dev *sdev = platform_get_drvdata(pdev);
242 
243         if (sdev->gpio.base != -1)
244                 gpiochip_remove(&sdev->gpio);
245 
246         platform_set_drvdata(pdev, NULL);
247         iounmap(sdev->base);
248         kfree(sdev);
249 }
250 
251 static struct platform_driver scoop_driver = {
252         .probe          = scoop_probe,
253         .remove_new     = scoop_remove,
254         .suspend        = scoop_suspend,
255         .resume         = scoop_resume,
256         .driver         = {
257                 .name   = "sharp-scoop",
258         },
259 };
260 
261 static int __init scoop_init(void)
262 {
263         return platform_driver_register(&scoop_driver);
264 }
265 
266 subsys_initcall(scoop_init);
267 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php