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