]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - arch/arm/common/locomo.c
Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[mirror_ubuntu-hirsute-kernel.git] / arch / arm / common / locomo.c
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/arm/common/locomo.c
3 *
4 * Sharp LoCoMo support
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This file contains all generic LoCoMo support.
11 *
12 * All initialization functions provided here are intended to be called
13 * from machine specific code with proper arguments when required.
14 *
15 * Based on sa1111.c
16 */
17
1da177e4
LT
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/delay.h>
22#include <linux/errno.h>
23#include <linux/ioport.h>
d052d1be 24#include <linux/platform_device.h>
1da177e4
LT
25#include <linux/slab.h>
26#include <linux/spinlock.h>
27
28#include <asm/hardware.h>
1da177e4
LT
29#include <asm/io.h>
30#include <asm/irq.h>
31#include <asm/mach/irq.h>
32
33#include <asm/hardware/locomo.h>
34
35/* M62332 output channel selection */
36#define M62332_EVR_CH 1 /* M62332 volume channel number */
37 /* 0 : CH.1 , 1 : CH. 2 */
38/* DAC send data */
39#define M62332_SLAVE_ADDR 0x4e /* Slave address */
40#define M62332_W_BIT 0x00 /* W bit (0 only) */
41#define M62332_SUB_ADDR 0x00 /* Sub address */
42#define M62332_A_BIT 0x00 /* A bit (0 only) */
43
44/* DAC setup and hold times (expressed in us) */
45#define DAC_BUS_FREE_TIME 5 /* 4.7 us */
46#define DAC_START_SETUP_TIME 5 /* 4.7 us */
47#define DAC_STOP_SETUP_TIME 4 /* 4.0 us */
48#define DAC_START_HOLD_TIME 5 /* 4.7 us */
49#define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */
50#define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */
51#define DAC_DATA_SETUP_TIME 1 /* 250 ns */
52#define DAC_DATA_HOLD_TIME 1 /* 300 ns */
53#define DAC_LOW_SETUP_TIME 1 /* 300 ns */
54#define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */
55
56/* the following is the overall data for the locomo chip */
57struct locomo {
58 struct device *dev;
59 unsigned long phys;
60 unsigned int irq;
61 spinlock_t lock;
54815366 62 void __iomem *base;
1da177e4
LT
63};
64
65struct locomo_dev_info {
66 unsigned long offset;
67 unsigned long length;
68 unsigned int devid;
69 unsigned int irq[1];
70 const char * name;
71};
72
73/* All the locomo devices. If offset is non-zero, the mapbase for the
74 * locomo_dev will be set to the chip base plus offset. If offset is
75 * zero, then the mapbase for the locomo_dev will be set to zero. An
76 * offset of zero means the device only uses GPIOs or other helper
77 * functions inside this file */
78static struct locomo_dev_info locomo_devices[] = {
79 {
80 .devid = LOCOMO_DEVID_KEYBOARD,
81 .irq = {
82 IRQ_LOCOMO_KEY,
83 },
84 .name = "locomo-keyboard",
85 .offset = LOCOMO_KEYBOARD,
86 .length = 16,
87 },
88 {
89 .devid = LOCOMO_DEVID_FRONTLIGHT,
90 .irq = {},
91 .name = "locomo-frontlight",
92 .offset = LOCOMO_FRONTLIGHT,
93 .length = 8,
94
95 },
96 {
97 .devid = LOCOMO_DEVID_BACKLIGHT,
98 .irq = {},
99 .name = "locomo-backlight",
100 .offset = LOCOMO_BACKLIGHT,
101 .length = 8,
102 },
103 {
104 .devid = LOCOMO_DEVID_AUDIO,
105 .irq = {},
106 .name = "locomo-audio",
107 .offset = LOCOMO_AUDIO,
108 .length = 4,
109 },
110 {
111 .devid = LOCOMO_DEVID_LED,
112 .irq = {},
113 .name = "locomo-led",
114 .offset = LOCOMO_LED,
115 .length = 8,
116 },
117 {
118 .devid = LOCOMO_DEVID_UART,
119 .irq = {},
120 .name = "locomo-uart",
121 .offset = 0,
122 .length = 0,
123 },
124};
125
126
127/** LoCoMo interrupt handling stuff.
128 * NOTE: LoCoMo has a 1 to many mapping on all of its IRQs.
129 * that is, there is only one real hardware interrupt
130 * we determine which interrupt it is by reading some IO memory.
131 * We have two levels of expansion, first in the handler for the
132 * hardware interrupt we generate an interrupt
133 * IRQ_LOCOMO_*_BASE and those handlers generate more interrupts
134 *
135 * hardware irq reads LOCOMO_ICR & 0x0f00
136 * IRQ_LOCOMO_KEY_BASE
137 * IRQ_LOCOMO_GPIO_BASE
138 * IRQ_LOCOMO_LT_BASE
139 * IRQ_LOCOMO_SPI_BASE
140 * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
141 * IRQ_LOCOMO_KEY
142 * IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff
143 * IRQ_LOCOMO_GPIO[0-15]
144 * IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001
145 * IRQ_LOCOMO_LT
146 * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
147 * IRQ_LOCOMO_SPI_RFR
148 * IRQ_LOCOMO_SPI_RFW
149 * IRQ_LOCOMO_SPI_OVRN
150 * IRQ_LOCOMO_SPI_TEND
151 */
152
153#define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE)
154#define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY)
155#define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0)
156#define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT)
157#define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR)
158
159static void locomo_handler(unsigned int irq, struct irqdesc *desc,
160 struct pt_regs *regs)
161{
162 int req, i;
163 struct irqdesc *d;
54815366 164 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
165
166 /* Acknowledge the parent IRQ */
167 desc->chip->ack(irq);
168
169 /* check why this interrupt was generated */
170 req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00;
171
172 if (req) {
173 /* generate the next interrupt(s) */
174 irq = LOCOMO_IRQ_START;
175 d = irq_desc + irq;
176 for (i = 0; i <= 3; i++, d++, irq++) {
177 if (req & (0x0100 << i)) {
664399e1 178 desc_handle_irq(irq, d, regs);
1da177e4
LT
179 }
180
181 }
182 }
183}
184
185static void locomo_ack_irq(unsigned int irq)
186{
187}
188
189static void locomo_mask_irq(unsigned int irq)
190{
54815366 191 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
192 unsigned int r;
193 r = locomo_readl(mapbase + LOCOMO_ICR);
194 r &= ~(0x0010 << (irq - LOCOMO_IRQ_START));
195 locomo_writel(r, mapbase + LOCOMO_ICR);
196}
197
198static void locomo_unmask_irq(unsigned int irq)
199{
54815366 200 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
201 unsigned int r;
202 r = locomo_readl(mapbase + LOCOMO_ICR);
203 r |= (0x0010 << (irq - LOCOMO_IRQ_START));
204 locomo_writel(r, mapbase + LOCOMO_ICR);
205}
206
207static struct irqchip locomo_chip = {
208 .ack = locomo_ack_irq,
209 .mask = locomo_mask_irq,
210 .unmask = locomo_unmask_irq,
211};
212
213static void locomo_key_handler(unsigned int irq, struct irqdesc *desc,
214 struct pt_regs *regs)
215{
216 struct irqdesc *d;
54815366 217 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
218
219 if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) {
220 d = irq_desc + LOCOMO_IRQ_KEY_START;
664399e1 221 desc_handle_irq(LOCOMO_IRQ_KEY_START, d, regs);
1da177e4
LT
222 }
223}
224
225static void locomo_key_ack_irq(unsigned int irq)
226{
54815366 227 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
228 unsigned int r;
229 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
230 r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START));
231 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
232}
233
234static void locomo_key_mask_irq(unsigned int irq)
235{
54815366 236 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
237 unsigned int r;
238 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
239 r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START));
240 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
241}
242
243static void locomo_key_unmask_irq(unsigned int irq)
244{
54815366 245 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
246 unsigned int r;
247 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
248 r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START));
249 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
250}
251
252static struct irqchip locomo_key_chip = {
253 .ack = locomo_key_ack_irq,
254 .mask = locomo_key_mask_irq,
255 .unmask = locomo_key_unmask_irq,
256};
257
258static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc,
259 struct pt_regs *regs)
260{
261 int req, i;
262 struct irqdesc *d;
54815366 263 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
264
265 req = locomo_readl(mapbase + LOCOMO_GIR) &
266 locomo_readl(mapbase + LOCOMO_GPD) &
267 0xffff;
268
269 if (req) {
270 irq = LOCOMO_IRQ_GPIO_START;
271 d = irq_desc + LOCOMO_IRQ_GPIO_START;
272 for (i = 0; i <= 15; i++, irq++, d++) {
273 if (req & (0x0001 << i)) {
664399e1 274 desc_handle_irq(irq, d, regs);
1da177e4
LT
275 }
276 }
277 }
278}
279
280static void locomo_gpio_ack_irq(unsigned int irq)
281{
54815366 282 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
283 unsigned int r;
284 r = locomo_readl(mapbase + LOCOMO_GWE);
285 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
286 locomo_writel(r, mapbase + LOCOMO_GWE);
287
288 r = locomo_readl(mapbase + LOCOMO_GIS);
289 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
290 locomo_writel(r, mapbase + LOCOMO_GIS);
291
292 r = locomo_readl(mapbase + LOCOMO_GWE);
293 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
294 locomo_writel(r, mapbase + LOCOMO_GWE);
295}
296
297static void locomo_gpio_mask_irq(unsigned int irq)
298{
54815366 299 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
300 unsigned int r;
301 r = locomo_readl(mapbase + LOCOMO_GIE);
302 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
303 locomo_writel(r, mapbase + LOCOMO_GIE);
304}
305
306static void locomo_gpio_unmask_irq(unsigned int irq)
307{
54815366 308 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
309 unsigned int r;
310 r = locomo_readl(mapbase + LOCOMO_GIE);
311 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
312 locomo_writel(r, mapbase + LOCOMO_GIE);
313}
314
315static struct irqchip locomo_gpio_chip = {
316 .ack = locomo_gpio_ack_irq,
317 .mask = locomo_gpio_mask_irq,
318 .unmask = locomo_gpio_unmask_irq,
319};
320
321static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc,
322 struct pt_regs *regs)
323{
324 struct irqdesc *d;
54815366 325 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
326
327 if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) {
328 d = irq_desc + LOCOMO_IRQ_LT_START;
664399e1 329 desc_handle_irq(LOCOMO_IRQ_LT_START, d, regs);
1da177e4
LT
330 }
331}
332
333static void locomo_lt_ack_irq(unsigned int irq)
334{
54815366 335 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
336 unsigned int r;
337 r = locomo_readl(mapbase + LOCOMO_LTINT);
338 r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START));
339 locomo_writel(r, mapbase + LOCOMO_LTINT);
340}
341
342static void locomo_lt_mask_irq(unsigned int irq)
343{
54815366 344 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
345 unsigned int r;
346 r = locomo_readl(mapbase + LOCOMO_LTINT);
347 r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START));
348 locomo_writel(r, mapbase + LOCOMO_LTINT);
349}
350
351static void locomo_lt_unmask_irq(unsigned int irq)
352{
54815366 353 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
354 unsigned int r;
355 r = locomo_readl(mapbase + LOCOMO_LTINT);
356 r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START));
357 locomo_writel(r, mapbase + LOCOMO_LTINT);
358}
359
360static struct irqchip locomo_lt_chip = {
361 .ack = locomo_lt_ack_irq,
362 .mask = locomo_lt_mask_irq,
363 .unmask = locomo_lt_unmask_irq,
364};
365
366static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc,
367 struct pt_regs *regs)
368{
369 int req, i;
370 struct irqdesc *d;
54815366 371 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
372
373 req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F;
374 if (req) {
375 irq = LOCOMO_IRQ_SPI_START;
376 d = irq_desc + irq;
377
378 for (i = 0; i <= 3; i++, irq++, d++) {
379 if (req & (0x0001 << i)) {
664399e1 380 desc_handle_irq(irq, d, regs);
1da177e4
LT
381 }
382 }
383 }
384}
385
386static void locomo_spi_ack_irq(unsigned int irq)
387{
54815366 388 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
389 unsigned int r;
390 r = locomo_readl(mapbase + LOCOMO_SPIWE);
391 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
392 locomo_writel(r, mapbase + LOCOMO_SPIWE);
393
394 r = locomo_readl(mapbase + LOCOMO_SPIIS);
395 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
396 locomo_writel(r, mapbase + LOCOMO_SPIIS);
397
398 r = locomo_readl(mapbase + LOCOMO_SPIWE);
399 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
400 locomo_writel(r, mapbase + LOCOMO_SPIWE);
401}
402
403static void locomo_spi_mask_irq(unsigned int irq)
404{
54815366 405 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
406 unsigned int r;
407 r = locomo_readl(mapbase + LOCOMO_SPIIE);
408 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
409 locomo_writel(r, mapbase + LOCOMO_SPIIE);
410}
411
412static void locomo_spi_unmask_irq(unsigned int irq)
413{
54815366 414 void __iomem *mapbase = get_irq_chipdata(irq);
1da177e4
LT
415 unsigned int r;
416 r = locomo_readl(mapbase + LOCOMO_SPIIE);
417 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
418 locomo_writel(r, mapbase + LOCOMO_SPIIE);
419}
420
421static struct irqchip locomo_spi_chip = {
422 .ack = locomo_spi_ack_irq,
423 .mask = locomo_spi_mask_irq,
424 .unmask = locomo_spi_unmask_irq,
425};
426
427static void locomo_setup_irq(struct locomo *lchip)
428{
429 int irq;
54815366 430 void __iomem *irqbase = lchip->base;
1da177e4
LT
431
432 /*
433 * Install handler for IRQ_LOCOMO_HW.
434 */
435 set_irq_type(lchip->irq, IRQT_FALLING);
436 set_irq_chipdata(lchip->irq, irqbase);
437 set_irq_chained_handler(lchip->irq, locomo_handler);
438
439 /* Install handlers for IRQ_LOCOMO_*_BASE */
440 set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip);
441 set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase);
442 set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler);
443 set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE);
444
445 set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip);
446 set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase);
447 set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler);
448 set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE);
449
450 set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip);
451 set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase);
452 set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler);
453 set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE);
454
455 set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip);
456 set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase);
457 set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler);
458 set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE);
459
460 /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
461 set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip);
462 set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase);
463 set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ);
464 set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE);
465
466 /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
467 for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) {
468 set_irq_chip(irq, &locomo_gpio_chip);
469 set_irq_chipdata(irq, irqbase);
470 set_irq_handler(irq, do_edge_IRQ);
471 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
472 }
473
474 /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
475 set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip);
476 set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase);
477 set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ);
478 set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE);
479
480 /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
481 for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) {
482 set_irq_chip(irq, &locomo_spi_chip);
483 set_irq_chipdata(irq, irqbase);
484 set_irq_handler(irq, do_edge_IRQ);
485 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
486 }
487}
488
489
490static void locomo_dev_release(struct device *_dev)
491{
492 struct locomo_dev *dev = LOCOMO_DEV(_dev);
493
494 kfree(dev);
495}
496
497static int
498locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
499{
500 struct locomo_dev *dev;
501 int ret;
502
d2a02b93 503 dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL);
1da177e4
LT
504 if (!dev) {
505 ret = -ENOMEM;
506 goto out;
507 }
1da177e4 508
7a2c3029 509 strncpy(dev->dev.bus_id, info->name, sizeof(dev->dev.bus_id));
1da177e4
LT
510 /*
511 * If the parent device has a DMA mask associated with it,
512 * propagate it down to the children.
513 */
514 if (lchip->dev->dma_mask) {
515 dev->dma_mask = *lchip->dev->dma_mask;
516 dev->dev.dma_mask = &dev->dma_mask;
517 }
518
519 dev->devid = info->devid;
520 dev->dev.parent = lchip->dev;
521 dev->dev.bus = &locomo_bus_type;
522 dev->dev.release = locomo_dev_release;
523 dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
524
525 if (info->offset)
526 dev->mapbase = lchip->base + info->offset;
527 else
528 dev->mapbase = 0;
529 dev->length = info->length;
530
531 memmove(dev->irq, info->irq, sizeof(dev->irq));
532
533 ret = device_register(&dev->dev);
534 if (ret) {
535 out:
536 kfree(dev);
537 }
538 return ret;
539}
540
b38d950d
JL
541#ifdef CONFIG_PM
542
543struct locomo_save_data {
544 u16 LCM_GPO;
545 u16 LCM_SPICT;
546 u16 LCM_GPE;
547 u16 LCM_ASD;
548 u16 LCM_SPIMD;
549};
550
3ae5eaec 551static int locomo_suspend(struct platform_device *dev, pm_message_t state)
b38d950d 552{
3ae5eaec 553 struct locomo *lchip = platform_get_drvdata(dev);
b38d950d
JL
554 struct locomo_save_data *save;
555 unsigned long flags;
556
b38d950d
JL
557 save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
558 if (!save)
559 return -ENOMEM;
560
3ae5eaec 561 dev->dev.power.saved_state = (void *) save;
b38d950d
JL
562
563 spin_lock_irqsave(&lchip->lock, flags);
564
565 save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */
566 locomo_writel(0x00, lchip->base + LOCOMO_GPO);
567 save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPICT); /* SPI */
568 locomo_writel(0x40, lchip->base + LOCOMO_SPICT);
569 save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */
570 locomo_writel(0x00, lchip->base + LOCOMO_GPE);
571 save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */
572 locomo_writel(0x00, lchip->base + LOCOMO_ASD);
573 save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPIMD); /* SPI */
574 locomo_writel(0x3C14, lchip->base + LOCOMO_SPIMD);
575
576 locomo_writel(0x00, lchip->base + LOCOMO_PAIF);
577 locomo_writel(0x00, lchip->base + LOCOMO_DAC);
578 locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC);
579
580 if ( (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88) )
581 locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */
582 else
583 /* 18MHz already enabled, so no wait */
584 locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */
585
586 locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/
587 locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */
588 locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */
589
590 spin_unlock_irqrestore(&lchip->lock, flags);
591
592 return 0;
593}
594
3ae5eaec 595static int locomo_resume(struct platform_device *dev)
b38d950d 596{
3ae5eaec 597 struct locomo *lchip = platform_get_drvdata(dev);
b38d950d
JL
598 struct locomo_save_data *save;
599 unsigned long r;
600 unsigned long flags;
601
3ae5eaec 602 save = (struct locomo_save_data *) dev->dev.power.saved_state;
b38d950d
JL
603 if (!save)
604 return 0;
605
606 spin_lock_irqsave(&lchip->lock, flags);
607
608 locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
609 locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPICT);
610 locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
611 locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
612 locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPIMD);
613
614 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
615 locomo_writel(0x90, lchip->base + LOCOMO_TADC);
616
617 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
618 r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
619 r &= 0xFEFF;
620 locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
621 locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
622
623 spin_unlock_irqrestore(&lchip->lock, flags);
b38d950d
JL
624 kfree(save);
625
626 return 0;
627}
628#endif
629
4ebf2d00 630
1da177e4
LT
631/**
632 * locomo_probe - probe for a single LoCoMo chip.
633 * @phys_addr: physical address of device.
634 *
635 * Probe for a LoCoMo chip. This must be called
636 * before any other locomo-specific code.
637 *
638 * Returns:
639 * %-ENODEV device not found.
640 * %-EBUSY physical address already marked in-use.
641 * %0 successful.
642 */
643static int
644__locomo_probe(struct device *me, struct resource *mem, int irq)
645{
646 struct locomo *lchip;
647 unsigned long r;
648 int i, ret = -ENODEV;
649
d2a02b93 650 lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL);
1da177e4
LT
651 if (!lchip)
652 return -ENOMEM;
653
1da177e4
LT
654 spin_lock_init(&lchip->lock);
655
656 lchip->dev = me;
657 dev_set_drvdata(lchip->dev, lchip);
658
659 lchip->phys = mem->start;
660 lchip->irq = irq;
661
662 /*
663 * Map the whole region. This also maps the
664 * registers for our children.
665 */
666 lchip->base = ioremap(mem->start, PAGE_SIZE);
667 if (!lchip->base) {
668 ret = -ENOMEM;
669 goto out;
670 }
671
672 /* locomo initialize */
673 locomo_writel(0, lchip->base + LOCOMO_ICR);
674 /* KEYBOARD */
675 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
676
677 /* GPIO */
678 locomo_writel(0, lchip->base + LOCOMO_GPO);
679 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
680 , lchip->base + LOCOMO_GPE);
681 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
682 , lchip->base + LOCOMO_GPD);
683 locomo_writel(0, lchip->base + LOCOMO_GIE);
684
e4423781 685 /* Frontlight */
1da177e4
LT
686 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
687 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
4ebf2d00 688
1da177e4
LT
689 /* Longtime timer */
690 locomo_writel(0, lchip->base + LOCOMO_LTINT);
691 /* SPI */
692 locomo_writel(0, lchip->base + LOCOMO_SPIIE);
693
694 locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
695 r = locomo_readl(lchip->base + LOCOMO_ASD);
696 r |= 0x8000;
697 locomo_writel(r, lchip->base + LOCOMO_ASD);
698
699 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
700 r = locomo_readl(lchip->base + LOCOMO_HSD);
701 r |= 0x8000;
702 locomo_writel(r, lchip->base + LOCOMO_HSD);
703
704 locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
705
706 /* XON */
707 locomo_writel(0x80, lchip->base + LOCOMO_TADC);
708 udelay(1000);
709 /* CLK9MEN */
710 r = locomo_readl(lchip->base + LOCOMO_TADC);
711 r |= 0x10;
712 locomo_writel(r, lchip->base + LOCOMO_TADC);
713 udelay(100);
714
715 /* init DAC */
716 r = locomo_readl(lchip->base + LOCOMO_DAC);
717 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
718 locomo_writel(r, lchip->base + LOCOMO_DAC);
719
720 r = locomo_readl(lchip->base + LOCOMO_VER);
721 printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
722
723 /*
724 * The interrupt controller must be initialised before any
725 * other device to ensure that the interrupts are available.
726 */
727 if (lchip->irq != NO_IRQ)
728 locomo_setup_irq(lchip);
729
730 for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
731 locomo_init_one_child(lchip, &locomo_devices[i]);
1da177e4
LT
732 return 0;
733
734 out:
735 kfree(lchip);
736 return ret;
737}
738
e24da5d3 739static int locomo_remove_child(struct device *dev, void *data)
1da177e4 740{
e24da5d3
PM
741 device_unregister(dev);
742 return 0;
743}
1da177e4 744
e24da5d3
PM
745static void __locomo_remove(struct locomo *lchip)
746{
747 device_for_each_child(lchip->dev, NULL, locomo_remove_child);
1da177e4
LT
748
749 if (lchip->irq != NO_IRQ) {
750 set_irq_chained_handler(lchip->irq, NULL);
751 set_irq_data(lchip->irq, NULL);
752 }
753
754 iounmap(lchip->base);
755 kfree(lchip);
756}
757
3ae5eaec 758static int locomo_probe(struct platform_device *dev)
1da177e4 759{
1da177e4
LT
760 struct resource *mem;
761 int irq;
762
3ae5eaec 763 mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
1da177e4
LT
764 if (!mem)
765 return -EINVAL;
3ae5eaec 766 irq = platform_get_irq(dev, 0);
48944738
DV
767 if (irq < 0)
768 return -ENXIO;
1da177e4 769
3ae5eaec 770 return __locomo_probe(&dev->dev, mem, irq);
1da177e4
LT
771}
772
3ae5eaec 773static int locomo_remove(struct platform_device *dev)
1da177e4 774{
c35bf4a5 775 struct locomo *lchip = platform_get_drvdata(dev);
1da177e4
LT
776
777 if (lchip) {
778 __locomo_remove(lchip);
3ae5eaec 779 platform_set_drvdata(dev, NULL);
1da177e4
LT
780 }
781
782 return 0;
783}
784
785/*
786 * Not sure if this should be on the system bus or not yet.
787 * We really want some way to register a system device at
788 * the per-machine level, and then have this driver pick
789 * up the registered devices.
790 */
3ae5eaec 791static struct platform_driver locomo_device_driver = {
1da177e4
LT
792 .probe = locomo_probe,
793 .remove = locomo_remove,
b38d950d
JL
794#ifdef CONFIG_PM
795 .suspend = locomo_suspend,
796 .resume = locomo_resume,
797#endif
3ae5eaec
RK
798 .driver = {
799 .name = "locomo",
800 },
1da177e4
LT
801};
802
803/*
804 * Get the parent device driver (us) structure
805 * from a child function device
806 */
807static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
808{
809 return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
810}
811
812void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir)
813{
814 struct locomo *lchip = locomo_chip_driver(ldev);
815 unsigned long flags;
816 unsigned int r;
817
818 spin_lock_irqsave(&lchip->lock, flags);
819
820 r = locomo_readl(lchip->base + LOCOMO_GPD);
821 r &= ~bits;
822 locomo_writel(r, lchip->base + LOCOMO_GPD);
823
824 r = locomo_readl(lchip->base + LOCOMO_GPE);
825 if (dir)
826 r |= bits;
827 else
828 r &= ~bits;
829 locomo_writel(r, lchip->base + LOCOMO_GPE);
830
831 spin_unlock_irqrestore(&lchip->lock, flags);
832}
833
834unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits)
835{
836 struct locomo *lchip = locomo_chip_driver(ldev);
837 unsigned long flags;
838 unsigned int ret;
839
840 spin_lock_irqsave(&lchip->lock, flags);
841 ret = locomo_readl(lchip->base + LOCOMO_GPL);
842 spin_unlock_irqrestore(&lchip->lock, flags);
843
844 ret &= bits;
845 return ret;
846}
847
848unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits)
849{
850 struct locomo *lchip = locomo_chip_driver(ldev);
851 unsigned long flags;
852 unsigned int ret;
853
854 spin_lock_irqsave(&lchip->lock, flags);
855 ret = locomo_readl(lchip->base + LOCOMO_GPO);
856 spin_unlock_irqrestore(&lchip->lock, flags);
857
858 ret &= bits;
859 return ret;
860}
861
862void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set)
863{
864 struct locomo *lchip = locomo_chip_driver(ldev);
865 unsigned long flags;
866 unsigned int r;
867
868 spin_lock_irqsave(&lchip->lock, flags);
869
870 r = locomo_readl(lchip->base + LOCOMO_GPO);
871 if (set)
872 r |= bits;
873 else
874 r &= ~bits;
875 locomo_writel(r, lchip->base + LOCOMO_GPO);
876
877 spin_unlock_irqrestore(&lchip->lock, flags);
878}
879
880static void locomo_m62332_sendbit(void *mapbase, int bit)
881{
882 unsigned int r;
883
884 r = locomo_readl(mapbase + LOCOMO_DAC);
885 r &= ~(LOCOMO_DAC_SCLOEB);
886 locomo_writel(r, mapbase + LOCOMO_DAC);
887 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
888 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
889 r = locomo_readl(mapbase + LOCOMO_DAC);
890 r &= ~(LOCOMO_DAC_SCLOEB);
891 locomo_writel(r, mapbase + LOCOMO_DAC);
892 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
893 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
894
895 if (bit & 1) {
896 r = locomo_readl(mapbase + LOCOMO_DAC);
897 r |= LOCOMO_DAC_SDAOEB;
898 locomo_writel(r, mapbase + LOCOMO_DAC);
899 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
900 } else {
901 r = locomo_readl(mapbase + LOCOMO_DAC);
902 r &= ~(LOCOMO_DAC_SDAOEB);
903 locomo_writel(r, mapbase + LOCOMO_DAC);
904 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
905 }
906
907 udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */
908 r = locomo_readl(mapbase + LOCOMO_DAC);
909 r |= LOCOMO_DAC_SCLOEB;
910 locomo_writel(r, mapbase + LOCOMO_DAC);
911 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
912 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
913}
914
915void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
916{
917 struct locomo *lchip = locomo_chip_driver(ldev);
918 int i;
919 unsigned char data;
920 unsigned int r;
921 void *mapbase = lchip->base;
922 unsigned long flags;
923
924 spin_lock_irqsave(&lchip->lock, flags);
925
926 /* Start */
927 udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */
928 r = locomo_readl(mapbase + LOCOMO_DAC);
929 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
930 locomo_writel(r, mapbase + LOCOMO_DAC);
931 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
932 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
933 r = locomo_readl(mapbase + LOCOMO_DAC);
934 r &= ~(LOCOMO_DAC_SDAOEB);
935 locomo_writel(r, mapbase + LOCOMO_DAC);
936 udelay(DAC_START_HOLD_TIME); /* 5.0 usec */
937 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
938
939 /* Send slave address and W bit (LSB is W bit) */
940 data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
941 for (i = 1; i <= 8; i++) {
942 locomo_m62332_sendbit(mapbase, data >> (8 - i));
943 }
944
945 /* Check A bit */
946 r = locomo_readl(mapbase + LOCOMO_DAC);
947 r &= ~(LOCOMO_DAC_SCLOEB);
948 locomo_writel(r, mapbase + LOCOMO_DAC);
949 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
950 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
951 r = locomo_readl(mapbase + LOCOMO_DAC);
952 r &= ~(LOCOMO_DAC_SDAOEB);
953 locomo_writel(r, mapbase + LOCOMO_DAC);
954 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
955 r = locomo_readl(mapbase + LOCOMO_DAC);
956 r |= LOCOMO_DAC_SCLOEB;
957 locomo_writel(r, mapbase + LOCOMO_DAC);
958 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
959 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
960 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
961 printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
962 return;
963 }
964
965 /* Send Sub address (LSB is channel select) */
966 /* channel = 0 : ch1 select */
967 /* = 1 : ch2 select */
968 data = M62332_SUB_ADDR + channel;
969 for (i = 1; i <= 8; i++) {
970 locomo_m62332_sendbit(mapbase, data >> (8 - i));
971 }
972
973 /* Check A bit */
974 r = locomo_readl(mapbase + LOCOMO_DAC);
975 r &= ~(LOCOMO_DAC_SCLOEB);
976 locomo_writel(r, mapbase + LOCOMO_DAC);
977 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
978 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
979 r = locomo_readl(mapbase + LOCOMO_DAC);
980 r &= ~(LOCOMO_DAC_SDAOEB);
981 locomo_writel(r, mapbase + LOCOMO_DAC);
982 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
983 r = locomo_readl(mapbase + LOCOMO_DAC);
984 r |= LOCOMO_DAC_SCLOEB;
985 locomo_writel(r, mapbase + LOCOMO_DAC);
986 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
987 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
988 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
989 printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
990 return;
991 }
992
993 /* Send DAC data */
994 for (i = 1; i <= 8; i++) {
995 locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
996 }
997
998 /* Check A bit */
999 r = locomo_readl(mapbase + LOCOMO_DAC);
1000 r &= ~(LOCOMO_DAC_SCLOEB);
1001 locomo_writel(r, mapbase + LOCOMO_DAC);
1002 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1003 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1004 r = locomo_readl(mapbase + LOCOMO_DAC);
1005 r &= ~(LOCOMO_DAC_SDAOEB);
1006 locomo_writel(r, mapbase + LOCOMO_DAC);
1007 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1008 r = locomo_readl(mapbase + LOCOMO_DAC);
1009 r |= LOCOMO_DAC_SCLOEB;
1010 locomo_writel(r, mapbase + LOCOMO_DAC);
1011 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1012 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
1013 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
1014 printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
1015 return;
1016 }
1017
1018 /* stop */
1019 r = locomo_readl(mapbase + LOCOMO_DAC);
1020 r &= ~(LOCOMO_DAC_SCLOEB);
1021 locomo_writel(r, mapbase + LOCOMO_DAC);
1022 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1023 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1024 r = locomo_readl(mapbase + LOCOMO_DAC);
1025 r |= LOCOMO_DAC_SCLOEB;
1026 locomo_writel(r, mapbase + LOCOMO_DAC);
1027 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1028 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
1029 r = locomo_readl(mapbase + LOCOMO_DAC);
1030 r |= LOCOMO_DAC_SDAOEB;
1031 locomo_writel(r, mapbase + LOCOMO_DAC);
1032 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1033 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
1034
1035 r = locomo_readl(mapbase + LOCOMO_DAC);
1036 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
1037 locomo_writel(r, mapbase + LOCOMO_DAC);
1038 udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */
1039 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1040
1041 spin_unlock_irqrestore(&lchip->lock, flags);
1042}
1043
e4423781
RP
1044/*
1045 * Frontlight control
1046 */
1047
1048static struct locomo *locomo_chip_driver(struct locomo_dev *ldev);
1049
1050void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf)
1051{
1052 unsigned long flags;
1053 struct locomo *lchip = locomo_chip_driver(dev);
1054
1055 if (vr)
1056 locomo_gpio_write(dev, LOCOMO_GPIO_FL_VR, 1);
1057 else
1058 locomo_gpio_write(dev, LOCOMO_GPIO_FL_VR, 0);
1059
1060 spin_lock_irqsave(&lchip->lock, flags);
1061 locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
1062 udelay(100);
1063 locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
1064 locomo_writel(bpwf | LOCOMO_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
1065 spin_unlock_irqrestore(&lchip->lock, flags);
1066}
1067
1da177e4
LT
1068/*
1069 * LoCoMo "Register Access Bus."
1070 *
1071 * We model this as a regular bus type, and hang devices directly
1072 * off this.
1073 */
1074static int locomo_match(struct device *_dev, struct device_driver *_drv)
1075{
1076 struct locomo_dev *dev = LOCOMO_DEV(_dev);
1077 struct locomo_driver *drv = LOCOMO_DRV(_drv);
1078
1079 return dev->devid == drv->devid;
1080}
1081
1082static int locomo_bus_suspend(struct device *dev, pm_message_t state)
1083{
1084 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1085 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1086 int ret = 0;
1087
1088 if (drv && drv->suspend)
1089 ret = drv->suspend(ldev, state);
1090 return ret;
1091}
1092
1093static int locomo_bus_resume(struct device *dev)
1094{
1095 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1096 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1097 int ret = 0;
1098
1099 if (drv && drv->resume)
1100 ret = drv->resume(ldev);
1101 return ret;
1102}
1103
1104static int locomo_bus_probe(struct device *dev)
1105{
1106 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1107 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1108 int ret = -ENODEV;
1109
1110 if (drv->probe)
1111 ret = drv->probe(ldev);
1112 return ret;
1113}
1114
1115static int locomo_bus_remove(struct device *dev)
1116{
1117 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1118 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1119 int ret = 0;
1120
1121 if (drv->remove)
1122 ret = drv->remove(ldev);
1123 return ret;
1124}
1125
1126struct bus_type locomo_bus_type = {
1127 .name = "locomo-bus",
1128 .match = locomo_match,
306955be
RK
1129 .probe = locomo_bus_probe,
1130 .remove = locomo_bus_remove,
1da177e4
LT
1131 .suspend = locomo_bus_suspend,
1132 .resume = locomo_bus_resume,
1133};
1134
1135int locomo_driver_register(struct locomo_driver *driver)
1136{
1da177e4
LT
1137 driver->drv.bus = &locomo_bus_type;
1138 return driver_register(&driver->drv);
1139}
1140
1141void locomo_driver_unregister(struct locomo_driver *driver)
1142{
1143 driver_unregister(&driver->drv);
1144}
1145
1146static int __init locomo_init(void)
1147{
1148 int ret = bus_register(&locomo_bus_type);
1149 if (ret == 0)
3ae5eaec 1150 platform_driver_register(&locomo_device_driver);
1da177e4
LT
1151 return ret;
1152}
1153
1154static void __exit locomo_exit(void)
1155{
3ae5eaec 1156 platform_driver_unregister(&locomo_device_driver);
1da177e4
LT
1157 bus_unregister(&locomo_bus_type);
1158}
1159
1160module_init(locomo_init);
1161module_exit(locomo_exit);
1162
1163MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1164MODULE_LICENSE("GPL");
1165MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1166
1167EXPORT_SYMBOL(locomo_driver_register);
1168EXPORT_SYMBOL(locomo_driver_unregister);
1169EXPORT_SYMBOL(locomo_gpio_set_dir);
1170EXPORT_SYMBOL(locomo_gpio_read_level);
1171EXPORT_SYMBOL(locomo_gpio_read_output);
1172EXPORT_SYMBOL(locomo_gpio_write);
1173EXPORT_SYMBOL(locomo_m62332_senddata);