2 * linux/arch/arm/common/locomo.c
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.
10 * This file contains all generic LoCoMo support.
12 * All initialization functions provided here are intended to be called
13 * from machine specific code with proper arguments when required.
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>
29 #include <asm/hardware.h>
32 #include <asm/mach/irq.h>
34 #include <asm/hardware/locomo.h>
36 /* M62332 output channel selection */
37 #define M62332_EVR_CH 1 /* M62332 volume channel number */
38 /* 0 : CH.1 , 1 : CH. 2 */
40 #define M62332_SLAVE_ADDR 0x4e /* Slave address */
41 #define M62332_W_BIT 0x00 /* W bit (0 only) */
42 #define M62332_SUB_ADDR 0x00 /* Sub address */
43 #define M62332_A_BIT 0x00 /* A bit (0 only) */
45 /* DAC setup and hold times (expressed in us) */
46 #define DAC_BUS_FREE_TIME 5 /* 4.7 us */
47 #define DAC_START_SETUP_TIME 5 /* 4.7 us */
48 #define DAC_STOP_SETUP_TIME 4 /* 4.0 us */
49 #define DAC_START_HOLD_TIME 5 /* 4.7 us */
50 #define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */
51 #define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */
52 #define DAC_DATA_SETUP_TIME 1 /* 250 ns */
53 #define DAC_DATA_HOLD_TIME 1 /* 300 ns */
54 #define DAC_LOW_SETUP_TIME 1 /* 300 ns */
55 #define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */
57 /* the following is the overall data for the locomo chip */
66 struct locomo_dev_info {
74 /* All the locomo devices. If offset is non-zero, the mapbase for the
75 * locomo_dev will be set to the chip base plus offset. If offset is
76 * zero, then the mapbase for the locomo_dev will be set to zero. An
77 * offset of zero means the device only uses GPIOs or other helper
78 * functions inside this file */
79 static struct locomo_dev_info locomo_devices[] = {
81 .devid = LOCOMO_DEVID_KEYBOARD,
85 .name = "locomo-keyboard",
86 .offset = LOCOMO_KEYBOARD,
90 .devid = LOCOMO_DEVID_FRONTLIGHT,
92 .name = "locomo-frontlight",
93 .offset = LOCOMO_FRONTLIGHT,
98 .devid = LOCOMO_DEVID_BACKLIGHT,
100 .name = "locomo-backlight",
101 .offset = LOCOMO_BACKLIGHT,
105 .devid = LOCOMO_DEVID_AUDIO,
107 .name = "locomo-audio",
108 .offset = LOCOMO_AUDIO,
112 .devid = LOCOMO_DEVID_LED,
114 .name = "locomo-led",
115 .offset = LOCOMO_LED,
119 .devid = LOCOMO_DEVID_UART,
121 .name = "locomo-uart",
128 /** LoCoMo interrupt handling stuff.
129 * NOTE: LoCoMo has a 1 to many mapping on all of its IRQs.
130 * that is, there is only one real hardware interrupt
131 * we determine which interrupt it is by reading some IO memory.
132 * We have two levels of expansion, first in the handler for the
133 * hardware interrupt we generate an interrupt
134 * IRQ_LOCOMO_*_BASE and those handlers generate more interrupts
136 * hardware irq reads LOCOMO_ICR & 0x0f00
137 * IRQ_LOCOMO_KEY_BASE
138 * IRQ_LOCOMO_GPIO_BASE
140 * IRQ_LOCOMO_SPI_BASE
141 * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
143 * IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff
144 * IRQ_LOCOMO_GPIO[0-15]
145 * IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001
147 * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
150 * IRQ_LOCOMO_SPI_OVRN
151 * IRQ_LOCOMO_SPI_TEND
154 #define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE)
155 #define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY)
156 #define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0)
157 #define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT)
158 #define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR)
160 static void locomo_handler(unsigned int irq, struct irqdesc *desc,
161 struct pt_regs *regs)
165 void *mapbase = get_irq_chipdata(irq);
167 /* Acknowledge the parent IRQ */
168 desc->chip->ack(irq);
170 /* check why this interrupt was generated */
171 req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00;
174 /* generate the next interrupt(s) */
175 irq = LOCOMO_IRQ_START;
177 for (i = 0; i <= 3; i++, d++, irq++) {
178 if (req & (0x0100 << i)) {
179 desc_handle_irq(irq, d, regs);
186 static void locomo_ack_irq(unsigned int irq)
190 static void locomo_mask_irq(unsigned int irq)
192 void *mapbase = get_irq_chipdata(irq);
194 r = locomo_readl(mapbase + LOCOMO_ICR);
195 r &= ~(0x0010 << (irq - LOCOMO_IRQ_START));
196 locomo_writel(r, mapbase + LOCOMO_ICR);
199 static void locomo_unmask_irq(unsigned int irq)
201 void *mapbase = get_irq_chipdata(irq);
203 r = locomo_readl(mapbase + LOCOMO_ICR);
204 r |= (0x0010 << (irq - LOCOMO_IRQ_START));
205 locomo_writel(r, mapbase + LOCOMO_ICR);
208 static struct irqchip locomo_chip = {
209 .ack = locomo_ack_irq,
210 .mask = locomo_mask_irq,
211 .unmask = locomo_unmask_irq,
214 static void locomo_key_handler(unsigned int irq, struct irqdesc *desc,
215 struct pt_regs *regs)
218 void *mapbase = get_irq_chipdata(irq);
220 if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) {
221 d = irq_desc + LOCOMO_IRQ_KEY_START;
222 desc_handle_irq(LOCOMO_IRQ_KEY_START, d, regs);
226 static void locomo_key_ack_irq(unsigned int irq)
228 void *mapbase = get_irq_chipdata(irq);
230 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
231 r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START));
232 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
235 static void locomo_key_mask_irq(unsigned int irq)
237 void *mapbase = get_irq_chipdata(irq);
239 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
240 r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START));
241 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
244 static void locomo_key_unmask_irq(unsigned int irq)
246 void *mapbase = get_irq_chipdata(irq);
248 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
249 r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START));
250 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
253 static struct irqchip locomo_key_chip = {
254 .ack = locomo_key_ack_irq,
255 .mask = locomo_key_mask_irq,
256 .unmask = locomo_key_unmask_irq,
259 static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc,
260 struct pt_regs *regs)
264 void *mapbase = get_irq_chipdata(irq);
266 req = locomo_readl(mapbase + LOCOMO_GIR) &
267 locomo_readl(mapbase + LOCOMO_GPD) &
271 irq = LOCOMO_IRQ_GPIO_START;
272 d = irq_desc + LOCOMO_IRQ_GPIO_START;
273 for (i = 0; i <= 15; i++, irq++, d++) {
274 if (req & (0x0001 << i)) {
275 desc_handle_irq(irq, d, regs);
281 static void locomo_gpio_ack_irq(unsigned int irq)
283 void *mapbase = get_irq_chipdata(irq);
285 r = locomo_readl(mapbase + LOCOMO_GWE);
286 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
287 locomo_writel(r, mapbase + LOCOMO_GWE);
289 r = locomo_readl(mapbase + LOCOMO_GIS);
290 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
291 locomo_writel(r, mapbase + LOCOMO_GIS);
293 r = locomo_readl(mapbase + LOCOMO_GWE);
294 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
295 locomo_writel(r, mapbase + LOCOMO_GWE);
298 static void locomo_gpio_mask_irq(unsigned int irq)
300 void *mapbase = get_irq_chipdata(irq);
302 r = locomo_readl(mapbase + LOCOMO_GIE);
303 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
304 locomo_writel(r, mapbase + LOCOMO_GIE);
307 static void locomo_gpio_unmask_irq(unsigned int irq)
309 void *mapbase = get_irq_chipdata(irq);
311 r = locomo_readl(mapbase + LOCOMO_GIE);
312 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
313 locomo_writel(r, mapbase + LOCOMO_GIE);
316 static struct irqchip locomo_gpio_chip = {
317 .ack = locomo_gpio_ack_irq,
318 .mask = locomo_gpio_mask_irq,
319 .unmask = locomo_gpio_unmask_irq,
322 static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc,
323 struct pt_regs *regs)
326 void *mapbase = get_irq_chipdata(irq);
328 if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) {
329 d = irq_desc + LOCOMO_IRQ_LT_START;
330 desc_handle_irq(LOCOMO_IRQ_LT_START, d, regs);
334 static void locomo_lt_ack_irq(unsigned int irq)
336 void *mapbase = get_irq_chipdata(irq);
338 r = locomo_readl(mapbase + LOCOMO_LTINT);
339 r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START));
340 locomo_writel(r, mapbase + LOCOMO_LTINT);
343 static void locomo_lt_mask_irq(unsigned int irq)
345 void *mapbase = get_irq_chipdata(irq);
347 r = locomo_readl(mapbase + LOCOMO_LTINT);
348 r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START));
349 locomo_writel(r, mapbase + LOCOMO_LTINT);
352 static void locomo_lt_unmask_irq(unsigned int irq)
354 void *mapbase = get_irq_chipdata(irq);
356 r = locomo_readl(mapbase + LOCOMO_LTINT);
357 r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START));
358 locomo_writel(r, mapbase + LOCOMO_LTINT);
361 static struct irqchip locomo_lt_chip = {
362 .ack = locomo_lt_ack_irq,
363 .mask = locomo_lt_mask_irq,
364 .unmask = locomo_lt_unmask_irq,
367 static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc,
368 struct pt_regs *regs)
372 void *mapbase = get_irq_chipdata(irq);
374 req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F;
376 irq = LOCOMO_IRQ_SPI_START;
379 for (i = 0; i <= 3; i++, irq++, d++) {
380 if (req & (0x0001 << i)) {
381 desc_handle_irq(irq, d, regs);
387 static void locomo_spi_ack_irq(unsigned int irq)
389 void *mapbase = get_irq_chipdata(irq);
391 r = locomo_readl(mapbase + LOCOMO_SPIWE);
392 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
393 locomo_writel(r, mapbase + LOCOMO_SPIWE);
395 r = locomo_readl(mapbase + LOCOMO_SPIIS);
396 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
397 locomo_writel(r, mapbase + LOCOMO_SPIIS);
399 r = locomo_readl(mapbase + LOCOMO_SPIWE);
400 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
401 locomo_writel(r, mapbase + LOCOMO_SPIWE);
404 static void locomo_spi_mask_irq(unsigned int irq)
406 void *mapbase = get_irq_chipdata(irq);
408 r = locomo_readl(mapbase + LOCOMO_SPIIE);
409 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
410 locomo_writel(r, mapbase + LOCOMO_SPIIE);
413 static void locomo_spi_unmask_irq(unsigned int irq)
415 void *mapbase = get_irq_chipdata(irq);
417 r = locomo_readl(mapbase + LOCOMO_SPIIE);
418 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
419 locomo_writel(r, mapbase + LOCOMO_SPIIE);
422 static struct irqchip locomo_spi_chip = {
423 .ack = locomo_spi_ack_irq,
424 .mask = locomo_spi_mask_irq,
425 .unmask = locomo_spi_unmask_irq,
428 static void locomo_setup_irq(struct locomo *lchip)
431 void *irqbase = lchip->base;
434 * Install handler for IRQ_LOCOMO_HW.
436 set_irq_type(lchip->irq, IRQT_FALLING);
437 set_irq_chipdata(lchip->irq, irqbase);
438 set_irq_chained_handler(lchip->irq, locomo_handler);
440 /* Install handlers for IRQ_LOCOMO_*_BASE */
441 set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip);
442 set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase);
443 set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler);
444 set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE);
446 set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip);
447 set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase);
448 set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler);
449 set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE);
451 set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip);
452 set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase);
453 set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler);
454 set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE);
456 set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip);
457 set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase);
458 set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler);
459 set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE);
461 /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
462 set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip);
463 set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase);
464 set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ);
465 set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE);
467 /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
468 for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) {
469 set_irq_chip(irq, &locomo_gpio_chip);
470 set_irq_chipdata(irq, irqbase);
471 set_irq_handler(irq, do_edge_IRQ);
472 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
475 /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
476 set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip);
477 set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase);
478 set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ);
479 set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE);
481 /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
482 for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) {
483 set_irq_chip(irq, &locomo_spi_chip);
484 set_irq_chipdata(irq, irqbase);
485 set_irq_handler(irq, do_edge_IRQ);
486 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
491 static void locomo_dev_release(struct device *_dev)
493 struct locomo_dev *dev = LOCOMO_DEV(_dev);
499 locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
501 struct locomo_dev *dev;
504 dev = kmalloc(sizeof(struct locomo_dev), GFP_KERNEL);
509 memset(dev, 0, sizeof(struct locomo_dev));
511 strncpy(dev->dev.bus_id,info->name,sizeof(dev->dev.bus_id));
513 * If the parent device has a DMA mask associated with it,
514 * propagate it down to the children.
516 if (lchip->dev->dma_mask) {
517 dev->dma_mask = *lchip->dev->dma_mask;
518 dev->dev.dma_mask = &dev->dma_mask;
521 dev->devid = info->devid;
522 dev->dev.parent = lchip->dev;
523 dev->dev.bus = &locomo_bus_type;
524 dev->dev.release = locomo_dev_release;
525 dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
528 dev->mapbase = lchip->base + info->offset;
531 dev->length = info->length;
533 memmove(dev->irq, info->irq, sizeof(dev->irq));
535 ret = device_register(&dev->dev);
545 struct locomo_save_data {
553 static int locomo_suspend(struct device *dev, pm_message_t state, u32 level)
555 struct locomo *lchip = dev_get_drvdata(dev);
556 struct locomo_save_data *save;
559 if (level != SUSPEND_DISABLE)
562 save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
566 dev->power.saved_state = (void *) save;
568 spin_lock_irqsave(&lchip->lock, flags);
570 save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */
571 locomo_writel(0x00, lchip->base + LOCOMO_GPO);
572 save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPICT); /* SPI */
573 locomo_writel(0x40, lchip->base + LOCOMO_SPICT);
574 save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */
575 locomo_writel(0x00, lchip->base + LOCOMO_GPE);
576 save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */
577 locomo_writel(0x00, lchip->base + LOCOMO_ASD);
578 save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPIMD); /* SPI */
579 locomo_writel(0x3C14, lchip->base + LOCOMO_SPIMD);
581 locomo_writel(0x00, lchip->base + LOCOMO_PAIF);
582 locomo_writel(0x00, lchip->base + LOCOMO_DAC);
583 locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC);
585 if ( (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88) )
586 locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */
588 /* 18MHz already enabled, so no wait */
589 locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */
591 locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/
592 locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */
593 locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */
595 spin_unlock_irqrestore(&lchip->lock, flags);
600 static int locomo_resume(struct device *dev, u32 level)
602 struct locomo *lchip = dev_get_drvdata(dev);
603 struct locomo_save_data *save;
607 if (level != RESUME_ENABLE)
610 save = (struct locomo_save_data *) dev->power.saved_state;
614 spin_lock_irqsave(&lchip->lock, flags);
616 locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
617 locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPICT);
618 locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
619 locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
620 locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPIMD);
622 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
623 locomo_writel(0x90, lchip->base + LOCOMO_TADC);
625 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
626 r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
628 locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
629 locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
631 spin_unlock_irqrestore(&lchip->lock, flags);
633 dev->power.saved_state = NULL;
641 * locomo_probe - probe for a single LoCoMo chip.
642 * @phys_addr: physical address of device.
644 * Probe for a LoCoMo chip. This must be called
645 * before any other locomo-specific code.
648 * %-ENODEV device not found.
649 * %-EBUSY physical address already marked in-use.
653 __locomo_probe(struct device *me, struct resource *mem, int irq)
655 struct locomo *lchip;
657 int i, ret = -ENODEV;
659 lchip = kmalloc(sizeof(struct locomo), GFP_KERNEL);
663 memset(lchip, 0, sizeof(struct locomo));
665 spin_lock_init(&lchip->lock);
668 dev_set_drvdata(lchip->dev, lchip);
670 lchip->phys = mem->start;
674 * Map the whole region. This also maps the
675 * registers for our children.
677 lchip->base = ioremap(mem->start, PAGE_SIZE);
683 /* locomo initialize */
684 locomo_writel(0, lchip->base + LOCOMO_ICR);
686 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
689 locomo_writel(0, lchip->base + LOCOMO_GPO);
690 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
691 , lchip->base + LOCOMO_GPE);
692 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
693 , lchip->base + LOCOMO_GPD);
694 locomo_writel(0, lchip->base + LOCOMO_GIE);
697 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
698 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
700 locomo_writel(0, lchip->base + LOCOMO_LTINT);
702 locomo_writel(0, lchip->base + LOCOMO_SPIIE);
704 locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
705 r = locomo_readl(lchip->base + LOCOMO_ASD);
707 locomo_writel(r, lchip->base + LOCOMO_ASD);
709 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
710 r = locomo_readl(lchip->base + LOCOMO_HSD);
712 locomo_writel(r, lchip->base + LOCOMO_HSD);
714 locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
717 locomo_writel(0x80, lchip->base + LOCOMO_TADC);
720 r = locomo_readl(lchip->base + LOCOMO_TADC);
722 locomo_writel(r, lchip->base + LOCOMO_TADC);
726 r = locomo_readl(lchip->base + LOCOMO_DAC);
727 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
728 locomo_writel(r, lchip->base + LOCOMO_DAC);
730 r = locomo_readl(lchip->base + LOCOMO_VER);
731 printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
734 * The interrupt controller must be initialised before any
735 * other device to ensure that the interrupts are available.
737 if (lchip->irq != NO_IRQ)
738 locomo_setup_irq(lchip);
740 for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
741 locomo_init_one_child(lchip, &locomo_devices[i]);
750 static int locomo_remove_child(struct device *dev, void *data)
752 device_unregister(dev);
756 static void __locomo_remove(struct locomo *lchip)
758 device_for_each_child(lchip->dev, NULL, locomo_remove_child);
760 if (lchip->irq != NO_IRQ) {
761 set_irq_chained_handler(lchip->irq, NULL);
762 set_irq_data(lchip->irq, NULL);
765 iounmap(lchip->base);
769 static int locomo_probe(struct device *dev)
771 struct platform_device *pdev = to_platform_device(dev);
772 struct resource *mem;
775 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
778 irq = platform_get_irq(pdev, 0);
780 return __locomo_probe(dev, mem, irq);
783 static int locomo_remove(struct device *dev)
785 struct locomo *lchip = dev_get_drvdata(dev);
788 __locomo_remove(lchip);
789 dev_set_drvdata(dev, NULL);
796 * Not sure if this should be on the system bus or not yet.
797 * We really want some way to register a system device at
798 * the per-machine level, and then have this driver pick
799 * up the registered devices.
801 static struct device_driver locomo_device_driver = {
803 .bus = &platform_bus_type,
804 .probe = locomo_probe,
805 .remove = locomo_remove,
807 .suspend = locomo_suspend,
808 .resume = locomo_resume,
813 * Get the parent device driver (us) structure
814 * from a child function device
816 static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
818 return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
821 void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir)
823 struct locomo *lchip = locomo_chip_driver(ldev);
827 spin_lock_irqsave(&lchip->lock, flags);
829 r = locomo_readl(lchip->base + LOCOMO_GPD);
831 locomo_writel(r, lchip->base + LOCOMO_GPD);
833 r = locomo_readl(lchip->base + LOCOMO_GPE);
838 locomo_writel(r, lchip->base + LOCOMO_GPE);
840 spin_unlock_irqrestore(&lchip->lock, flags);
843 unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits)
845 struct locomo *lchip = locomo_chip_driver(ldev);
849 spin_lock_irqsave(&lchip->lock, flags);
850 ret = locomo_readl(lchip->base + LOCOMO_GPL);
851 spin_unlock_irqrestore(&lchip->lock, flags);
857 unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits)
859 struct locomo *lchip = locomo_chip_driver(ldev);
863 spin_lock_irqsave(&lchip->lock, flags);
864 ret = locomo_readl(lchip->base + LOCOMO_GPO);
865 spin_unlock_irqrestore(&lchip->lock, flags);
871 void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set)
873 struct locomo *lchip = locomo_chip_driver(ldev);
877 spin_lock_irqsave(&lchip->lock, flags);
879 r = locomo_readl(lchip->base + LOCOMO_GPO);
884 locomo_writel(r, lchip->base + LOCOMO_GPO);
886 spin_unlock_irqrestore(&lchip->lock, flags);
889 static void locomo_m62332_sendbit(void *mapbase, int bit)
893 r = locomo_readl(mapbase + LOCOMO_DAC);
894 r &= ~(LOCOMO_DAC_SCLOEB);
895 locomo_writel(r, mapbase + LOCOMO_DAC);
896 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
897 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
898 r = locomo_readl(mapbase + LOCOMO_DAC);
899 r &= ~(LOCOMO_DAC_SCLOEB);
900 locomo_writel(r, mapbase + LOCOMO_DAC);
901 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
902 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
905 r = locomo_readl(mapbase + LOCOMO_DAC);
906 r |= LOCOMO_DAC_SDAOEB;
907 locomo_writel(r, mapbase + LOCOMO_DAC);
908 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
910 r = locomo_readl(mapbase + LOCOMO_DAC);
911 r &= ~(LOCOMO_DAC_SDAOEB);
912 locomo_writel(r, mapbase + LOCOMO_DAC);
913 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
916 udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */
917 r = locomo_readl(mapbase + LOCOMO_DAC);
918 r |= LOCOMO_DAC_SCLOEB;
919 locomo_writel(r, mapbase + LOCOMO_DAC);
920 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
921 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
924 void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
926 struct locomo *lchip = locomo_chip_driver(ldev);
930 void *mapbase = lchip->base;
933 spin_lock_irqsave(&lchip->lock, flags);
936 udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */
937 r = locomo_readl(mapbase + LOCOMO_DAC);
938 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
939 locomo_writel(r, mapbase + LOCOMO_DAC);
940 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
941 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
942 r = locomo_readl(mapbase + LOCOMO_DAC);
943 r &= ~(LOCOMO_DAC_SDAOEB);
944 locomo_writel(r, mapbase + LOCOMO_DAC);
945 udelay(DAC_START_HOLD_TIME); /* 5.0 usec */
946 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
948 /* Send slave address and W bit (LSB is W bit) */
949 data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
950 for (i = 1; i <= 8; i++) {
951 locomo_m62332_sendbit(mapbase, data >> (8 - i));
955 r = locomo_readl(mapbase + LOCOMO_DAC);
956 r &= ~(LOCOMO_DAC_SCLOEB);
957 locomo_writel(r, mapbase + LOCOMO_DAC);
958 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
959 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
960 r = locomo_readl(mapbase + LOCOMO_DAC);
961 r &= ~(LOCOMO_DAC_SDAOEB);
962 locomo_writel(r, mapbase + LOCOMO_DAC);
963 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
964 r = locomo_readl(mapbase + LOCOMO_DAC);
965 r |= LOCOMO_DAC_SCLOEB;
966 locomo_writel(r, mapbase + LOCOMO_DAC);
967 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
968 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
969 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
970 printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
974 /* Send Sub address (LSB is channel select) */
975 /* channel = 0 : ch1 select */
976 /* = 1 : ch2 select */
977 data = M62332_SUB_ADDR + channel;
978 for (i = 1; i <= 8; i++) {
979 locomo_m62332_sendbit(mapbase, data >> (8 - i));
983 r = locomo_readl(mapbase + LOCOMO_DAC);
984 r &= ~(LOCOMO_DAC_SCLOEB);
985 locomo_writel(r, mapbase + LOCOMO_DAC);
986 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
987 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
988 r = locomo_readl(mapbase + LOCOMO_DAC);
989 r &= ~(LOCOMO_DAC_SDAOEB);
990 locomo_writel(r, mapbase + LOCOMO_DAC);
991 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
992 r = locomo_readl(mapbase + LOCOMO_DAC);
993 r |= LOCOMO_DAC_SCLOEB;
994 locomo_writel(r, mapbase + LOCOMO_DAC);
995 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
996 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
997 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
998 printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
1003 for (i = 1; i <= 8; i++) {
1004 locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
1008 r = locomo_readl(mapbase + LOCOMO_DAC);
1009 r &= ~(LOCOMO_DAC_SCLOEB);
1010 locomo_writel(r, mapbase + LOCOMO_DAC);
1011 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1012 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1013 r = locomo_readl(mapbase + LOCOMO_DAC);
1014 r &= ~(LOCOMO_DAC_SDAOEB);
1015 locomo_writel(r, mapbase + LOCOMO_DAC);
1016 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1017 r = locomo_readl(mapbase + LOCOMO_DAC);
1018 r |= LOCOMO_DAC_SCLOEB;
1019 locomo_writel(r, mapbase + LOCOMO_DAC);
1020 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1021 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
1022 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
1023 printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
1028 r = locomo_readl(mapbase + LOCOMO_DAC);
1029 r &= ~(LOCOMO_DAC_SCLOEB);
1030 locomo_writel(r, mapbase + LOCOMO_DAC);
1031 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1032 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1033 r = locomo_readl(mapbase + LOCOMO_DAC);
1034 r |= LOCOMO_DAC_SCLOEB;
1035 locomo_writel(r, mapbase + LOCOMO_DAC);
1036 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1037 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
1038 r = locomo_readl(mapbase + LOCOMO_DAC);
1039 r |= LOCOMO_DAC_SDAOEB;
1040 locomo_writel(r, mapbase + LOCOMO_DAC);
1041 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1042 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
1044 r = locomo_readl(mapbase + LOCOMO_DAC);
1045 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
1046 locomo_writel(r, mapbase + LOCOMO_DAC);
1047 udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */
1048 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1050 spin_unlock_irqrestore(&lchip->lock, flags);
1054 * LoCoMo "Register Access Bus."
1056 * We model this as a regular bus type, and hang devices directly
1059 static int locomo_match(struct device *_dev, struct device_driver *_drv)
1061 struct locomo_dev *dev = LOCOMO_DEV(_dev);
1062 struct locomo_driver *drv = LOCOMO_DRV(_drv);
1064 return dev->devid == drv->devid;
1067 static int locomo_bus_suspend(struct device *dev, pm_message_t state)
1069 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1070 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1073 if (drv && drv->suspend)
1074 ret = drv->suspend(ldev, state);
1078 static int locomo_bus_resume(struct device *dev)
1080 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1081 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1084 if (drv && drv->resume)
1085 ret = drv->resume(ldev);
1089 static int locomo_bus_probe(struct device *dev)
1091 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1092 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1096 ret = drv->probe(ldev);
1100 static int locomo_bus_remove(struct device *dev)
1102 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1103 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1107 ret = drv->remove(ldev);
1111 struct bus_type locomo_bus_type = {
1112 .name = "locomo-bus",
1113 .match = locomo_match,
1114 .suspend = locomo_bus_suspend,
1115 .resume = locomo_bus_resume,
1118 int locomo_driver_register(struct locomo_driver *driver)
1120 driver->drv.probe = locomo_bus_probe;
1121 driver->drv.remove = locomo_bus_remove;
1122 driver->drv.bus = &locomo_bus_type;
1123 return driver_register(&driver->drv);
1126 void locomo_driver_unregister(struct locomo_driver *driver)
1128 driver_unregister(&driver->drv);
1131 static int __init locomo_init(void)
1133 int ret = bus_register(&locomo_bus_type);
1135 driver_register(&locomo_device_driver);
1139 static void __exit locomo_exit(void)
1141 driver_unregister(&locomo_device_driver);
1142 bus_unregister(&locomo_bus_type);
1145 module_init(locomo_init);
1146 module_exit(locomo_exit);
1148 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1149 MODULE_LICENSE("GPL");
1150 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1152 EXPORT_SYMBOL(locomo_driver_register);
1153 EXPORT_SYMBOL(locomo_driver_unregister);
1154 EXPORT_SYMBOL(locomo_gpio_set_dir);
1155 EXPORT_SYMBOL(locomo_gpio_read_level);
1156 EXPORT_SYMBOL(locomo_gpio_read_output);
1157 EXPORT_SYMBOL(locomo_gpio_write);
1158 EXPORT_SYMBOL(locomo_m62332_senddata);