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/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>
24 #include <linux/platform_device.h>
25 #include <linux/slab.h>
26 #include <linux/spinlock.h>
28 #include <asm/hardware.h>
31 #include <asm/mach/irq.h>
33 #include <asm/hardware/locomo.h>
35 /* M62332 output channel selection */
36 #define M62332_EVR_CH 1 /* M62332 volume channel number */
37 /* 0 : CH.1 , 1 : CH. 2 */
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) */
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 */
56 /* the following is the overall data for the locomo chip */
65 struct locomo_dev_info {
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 */
78 static struct locomo_dev_info locomo_devices[] = {
80 .devid = LOCOMO_DEVID_KEYBOARD,
84 .name = "locomo-keyboard",
85 .offset = LOCOMO_KEYBOARD,
89 .devid = LOCOMO_DEVID_FRONTLIGHT,
91 .name = "locomo-frontlight",
92 .offset = LOCOMO_FRONTLIGHT,
97 .devid = LOCOMO_DEVID_BACKLIGHT,
99 .name = "locomo-backlight",
100 .offset = LOCOMO_BACKLIGHT,
104 .devid = LOCOMO_DEVID_AUDIO,
106 .name = "locomo-audio",
107 .offset = LOCOMO_AUDIO,
111 .devid = LOCOMO_DEVID_LED,
113 .name = "locomo-led",
114 .offset = LOCOMO_LED,
118 .devid = LOCOMO_DEVID_UART,
120 .name = "locomo-uart",
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
135 * hardware irq reads LOCOMO_ICR & 0x0f00
136 * IRQ_LOCOMO_KEY_BASE
137 * IRQ_LOCOMO_GPIO_BASE
139 * IRQ_LOCOMO_SPI_BASE
140 * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
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
146 * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
149 * IRQ_LOCOMO_SPI_OVRN
150 * IRQ_LOCOMO_SPI_TEND
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)
159 static void locomo_handler(unsigned int irq, struct irqdesc *desc,
160 struct pt_regs *regs)
164 void __iomem *mapbase = get_irq_chipdata(irq);
166 /* Acknowledge the parent IRQ */
167 desc->chip->ack(irq);
169 /* check why this interrupt was generated */
170 req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00;
173 /* generate the next interrupt(s) */
174 irq = LOCOMO_IRQ_START;
176 for (i = 0; i <= 3; i++, d++, irq++) {
177 if (req & (0x0100 << i)) {
178 desc_handle_irq(irq, d, regs);
185 static void locomo_ack_irq(unsigned int irq)
189 static void locomo_mask_irq(unsigned int irq)
191 void __iomem *mapbase = get_irq_chipdata(irq);
193 r = locomo_readl(mapbase + LOCOMO_ICR);
194 r &= ~(0x0010 << (irq - LOCOMO_IRQ_START));
195 locomo_writel(r, mapbase + LOCOMO_ICR);
198 static void locomo_unmask_irq(unsigned int irq)
200 void __iomem *mapbase = get_irq_chipdata(irq);
202 r = locomo_readl(mapbase + LOCOMO_ICR);
203 r |= (0x0010 << (irq - LOCOMO_IRQ_START));
204 locomo_writel(r, mapbase + LOCOMO_ICR);
207 static struct irq_chip 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 __iomem *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 __iomem *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 __iomem *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 __iomem *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 irq_chip locomo_key_chip = {
254 .name = "LOCOMO-key",
255 .ack = locomo_key_ack_irq,
256 .mask = locomo_key_mask_irq,
257 .unmask = locomo_key_unmask_irq,
260 static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc,
261 struct pt_regs *regs)
265 void __iomem *mapbase = get_irq_chipdata(irq);
267 req = locomo_readl(mapbase + LOCOMO_GIR) &
268 locomo_readl(mapbase + LOCOMO_GPD) &
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)) {
276 desc_handle_irq(irq, d, regs);
282 static void locomo_gpio_ack_irq(unsigned int irq)
284 void __iomem *mapbase = get_irq_chipdata(irq);
286 r = locomo_readl(mapbase + LOCOMO_GWE);
287 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
288 locomo_writel(r, mapbase + LOCOMO_GWE);
290 r = locomo_readl(mapbase + LOCOMO_GIS);
291 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
292 locomo_writel(r, mapbase + LOCOMO_GIS);
294 r = locomo_readl(mapbase + LOCOMO_GWE);
295 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
296 locomo_writel(r, mapbase + LOCOMO_GWE);
299 static void locomo_gpio_mask_irq(unsigned int irq)
301 void __iomem *mapbase = get_irq_chipdata(irq);
303 r = locomo_readl(mapbase + LOCOMO_GIE);
304 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
305 locomo_writel(r, mapbase + LOCOMO_GIE);
308 static void locomo_gpio_unmask_irq(unsigned int irq)
310 void __iomem *mapbase = get_irq_chipdata(irq);
312 r = locomo_readl(mapbase + LOCOMO_GIE);
313 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
314 locomo_writel(r, mapbase + LOCOMO_GIE);
317 static struct irq_chip locomo_gpio_chip = {
318 .name = "LOCOMO-gpio",
319 .ack = locomo_gpio_ack_irq,
320 .mask = locomo_gpio_mask_irq,
321 .unmask = locomo_gpio_unmask_irq,
324 static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc,
325 struct pt_regs *regs)
328 void __iomem *mapbase = get_irq_chipdata(irq);
330 if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) {
331 d = irq_desc + LOCOMO_IRQ_LT_START;
332 desc_handle_irq(LOCOMO_IRQ_LT_START, d, regs);
336 static void locomo_lt_ack_irq(unsigned int irq)
338 void __iomem *mapbase = get_irq_chipdata(irq);
340 r = locomo_readl(mapbase + LOCOMO_LTINT);
341 r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START));
342 locomo_writel(r, mapbase + LOCOMO_LTINT);
345 static void locomo_lt_mask_irq(unsigned int irq)
347 void __iomem *mapbase = get_irq_chipdata(irq);
349 r = locomo_readl(mapbase + LOCOMO_LTINT);
350 r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START));
351 locomo_writel(r, mapbase + LOCOMO_LTINT);
354 static void locomo_lt_unmask_irq(unsigned int irq)
356 void __iomem *mapbase = get_irq_chipdata(irq);
358 r = locomo_readl(mapbase + LOCOMO_LTINT);
359 r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START));
360 locomo_writel(r, mapbase + LOCOMO_LTINT);
363 static struct irq_chip locomo_lt_chip = {
365 .ack = locomo_lt_ack_irq,
366 .mask = locomo_lt_mask_irq,
367 .unmask = locomo_lt_unmask_irq,
370 static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc,
371 struct pt_regs *regs)
375 void __iomem *mapbase = get_irq_chipdata(irq);
377 req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F;
379 irq = LOCOMO_IRQ_SPI_START;
382 for (i = 0; i <= 3; i++, irq++, d++) {
383 if (req & (0x0001 << i)) {
384 desc_handle_irq(irq, d, regs);
390 static void locomo_spi_ack_irq(unsigned int irq)
392 void __iomem *mapbase = get_irq_chipdata(irq);
394 r = locomo_readl(mapbase + LOCOMO_SPIWE);
395 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
396 locomo_writel(r, mapbase + LOCOMO_SPIWE);
398 r = locomo_readl(mapbase + LOCOMO_SPIIS);
399 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
400 locomo_writel(r, mapbase + LOCOMO_SPIIS);
402 r = locomo_readl(mapbase + LOCOMO_SPIWE);
403 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
404 locomo_writel(r, mapbase + LOCOMO_SPIWE);
407 static void locomo_spi_mask_irq(unsigned int irq)
409 void __iomem *mapbase = get_irq_chipdata(irq);
411 r = locomo_readl(mapbase + LOCOMO_SPIIE);
412 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
413 locomo_writel(r, mapbase + LOCOMO_SPIIE);
416 static void locomo_spi_unmask_irq(unsigned int irq)
418 void __iomem *mapbase = get_irq_chipdata(irq);
420 r = locomo_readl(mapbase + LOCOMO_SPIIE);
421 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
422 locomo_writel(r, mapbase + LOCOMO_SPIIE);
425 static struct irq_chip locomo_spi_chip = {
426 .name = "LOCOMO-spi",
427 .ack = locomo_spi_ack_irq,
428 .mask = locomo_spi_mask_irq,
429 .unmask = locomo_spi_unmask_irq,
432 static void locomo_setup_irq(struct locomo *lchip)
435 void __iomem *irqbase = lchip->base;
438 * Install handler for IRQ_LOCOMO_HW.
440 set_irq_type(lchip->irq, IRQT_FALLING);
441 set_irq_chipdata(lchip->irq, irqbase);
442 set_irq_chained_handler(lchip->irq, locomo_handler);
444 /* Install handlers for IRQ_LOCOMO_*_BASE */
445 set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip);
446 set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase);
447 set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler);
448 set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE);
450 set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip);
451 set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase);
452 set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler);
453 set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE);
455 set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip);
456 set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase);
457 set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler);
458 set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE);
460 set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip);
461 set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase);
462 set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler);
463 set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE);
465 /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
466 set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip);
467 set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase);
468 set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ);
469 set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE);
471 /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
472 for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) {
473 set_irq_chip(irq, &locomo_gpio_chip);
474 set_irq_chipdata(irq, irqbase);
475 set_irq_handler(irq, do_edge_IRQ);
476 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
479 /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
480 set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip);
481 set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase);
482 set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ);
483 set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE);
485 /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
486 for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) {
487 set_irq_chip(irq, &locomo_spi_chip);
488 set_irq_chipdata(irq, irqbase);
489 set_irq_handler(irq, do_edge_IRQ);
490 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
495 static void locomo_dev_release(struct device *_dev)
497 struct locomo_dev *dev = LOCOMO_DEV(_dev);
503 locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
505 struct locomo_dev *dev;
508 dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL);
514 strncpy(dev->dev.bus_id, info->name, sizeof(dev->dev.bus_id));
516 * If the parent device has a DMA mask associated with it,
517 * propagate it down to the children.
519 if (lchip->dev->dma_mask) {
520 dev->dma_mask = *lchip->dev->dma_mask;
521 dev->dev.dma_mask = &dev->dma_mask;
524 dev->devid = info->devid;
525 dev->dev.parent = lchip->dev;
526 dev->dev.bus = &locomo_bus_type;
527 dev->dev.release = locomo_dev_release;
528 dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
531 dev->mapbase = lchip->base + info->offset;
534 dev->length = info->length;
536 memmove(dev->irq, info->irq, sizeof(dev->irq));
538 ret = device_register(&dev->dev);
548 struct locomo_save_data {
556 static int locomo_suspend(struct platform_device *dev, pm_message_t state)
558 struct locomo *lchip = platform_get_drvdata(dev);
559 struct locomo_save_data *save;
562 save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
566 dev->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 platform_device *dev)
602 struct locomo *lchip = platform_get_drvdata(dev);
603 struct locomo_save_data *save;
607 save = (struct locomo_save_data *) dev->dev.power.saved_state;
611 spin_lock_irqsave(&lchip->lock, flags);
613 locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
614 locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPICT);
615 locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
616 locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
617 locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPIMD);
619 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
620 locomo_writel(0x90, lchip->base + LOCOMO_TADC);
622 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
623 r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
625 locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
626 locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
628 spin_unlock_irqrestore(&lchip->lock, flags);
637 * locomo_probe - probe for a single LoCoMo chip.
638 * @phys_addr: physical address of device.
640 * Probe for a LoCoMo chip. This must be called
641 * before any other locomo-specific code.
644 * %-ENODEV device not found.
645 * %-EBUSY physical address already marked in-use.
649 __locomo_probe(struct device *me, struct resource *mem, int irq)
651 struct locomo *lchip;
653 int i, ret = -ENODEV;
655 lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL);
659 spin_lock_init(&lchip->lock);
662 dev_set_drvdata(lchip->dev, lchip);
664 lchip->phys = mem->start;
668 * Map the whole region. This also maps the
669 * registers for our children.
671 lchip->base = ioremap(mem->start, PAGE_SIZE);
677 /* locomo initialize */
678 locomo_writel(0, lchip->base + LOCOMO_ICR);
680 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
683 locomo_writel(0, lchip->base + LOCOMO_GPO);
684 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
685 , lchip->base + LOCOMO_GPE);
686 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
687 , lchip->base + LOCOMO_GPD);
688 locomo_writel(0, lchip->base + LOCOMO_GIE);
691 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
692 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
695 locomo_writel(0, lchip->base + LOCOMO_LTINT);
697 locomo_writel(0, lchip->base + LOCOMO_SPIIE);
699 locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
700 r = locomo_readl(lchip->base + LOCOMO_ASD);
702 locomo_writel(r, lchip->base + LOCOMO_ASD);
704 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
705 r = locomo_readl(lchip->base + LOCOMO_HSD);
707 locomo_writel(r, lchip->base + LOCOMO_HSD);
709 locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
712 locomo_writel(0x80, lchip->base + LOCOMO_TADC);
715 r = locomo_readl(lchip->base + LOCOMO_TADC);
717 locomo_writel(r, lchip->base + LOCOMO_TADC);
721 r = locomo_readl(lchip->base + LOCOMO_DAC);
722 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
723 locomo_writel(r, lchip->base + LOCOMO_DAC);
725 r = locomo_readl(lchip->base + LOCOMO_VER);
726 printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
729 * The interrupt controller must be initialised before any
730 * other device to ensure that the interrupts are available.
732 if (lchip->irq != NO_IRQ)
733 locomo_setup_irq(lchip);
735 for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
736 locomo_init_one_child(lchip, &locomo_devices[i]);
744 static int locomo_remove_child(struct device *dev, void *data)
746 device_unregister(dev);
750 static void __locomo_remove(struct locomo *lchip)
752 device_for_each_child(lchip->dev, NULL, locomo_remove_child);
754 if (lchip->irq != NO_IRQ) {
755 set_irq_chained_handler(lchip->irq, NULL);
756 set_irq_data(lchip->irq, NULL);
759 iounmap(lchip->base);
763 static int locomo_probe(struct platform_device *dev)
765 struct resource *mem;
768 mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
771 irq = platform_get_irq(dev, 0);
775 return __locomo_probe(&dev->dev, mem, irq);
778 static int locomo_remove(struct platform_device *dev)
780 struct locomo *lchip = platform_get_drvdata(dev);
783 __locomo_remove(lchip);
784 platform_set_drvdata(dev, NULL);
791 * Not sure if this should be on the system bus or not yet.
792 * We really want some way to register a system device at
793 * the per-machine level, and then have this driver pick
794 * up the registered devices.
796 static struct platform_driver locomo_device_driver = {
797 .probe = locomo_probe,
798 .remove = locomo_remove,
800 .suspend = locomo_suspend,
801 .resume = locomo_resume,
809 * Get the parent device driver (us) structure
810 * from a child function device
812 static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
814 return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
817 void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir)
819 struct locomo *lchip = locomo_chip_driver(ldev);
823 spin_lock_irqsave(&lchip->lock, flags);
825 r = locomo_readl(lchip->base + LOCOMO_GPD);
827 locomo_writel(r, lchip->base + LOCOMO_GPD);
829 r = locomo_readl(lchip->base + LOCOMO_GPE);
834 locomo_writel(r, lchip->base + LOCOMO_GPE);
836 spin_unlock_irqrestore(&lchip->lock, flags);
839 unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits)
841 struct locomo *lchip = locomo_chip_driver(ldev);
845 spin_lock_irqsave(&lchip->lock, flags);
846 ret = locomo_readl(lchip->base + LOCOMO_GPL);
847 spin_unlock_irqrestore(&lchip->lock, flags);
853 unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits)
855 struct locomo *lchip = locomo_chip_driver(ldev);
859 spin_lock_irqsave(&lchip->lock, flags);
860 ret = locomo_readl(lchip->base + LOCOMO_GPO);
861 spin_unlock_irqrestore(&lchip->lock, flags);
867 void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set)
869 struct locomo *lchip = locomo_chip_driver(ldev);
873 spin_lock_irqsave(&lchip->lock, flags);
875 r = locomo_readl(lchip->base + LOCOMO_GPO);
880 locomo_writel(r, lchip->base + LOCOMO_GPO);
882 spin_unlock_irqrestore(&lchip->lock, flags);
885 static void locomo_m62332_sendbit(void *mapbase, int bit)
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_DATA_HOLD_TIME); /* 300 nsec */
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_SCL_LOW_HOLD_TIME); /* 4.7 usec */
901 r = locomo_readl(mapbase + LOCOMO_DAC);
902 r |= LOCOMO_DAC_SDAOEB;
903 locomo_writel(r, mapbase + LOCOMO_DAC);
904 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
906 r = locomo_readl(mapbase + LOCOMO_DAC);
907 r &= ~(LOCOMO_DAC_SDAOEB);
908 locomo_writel(r, mapbase + LOCOMO_DAC);
909 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
912 udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */
913 r = locomo_readl(mapbase + LOCOMO_DAC);
914 r |= LOCOMO_DAC_SCLOEB;
915 locomo_writel(r, mapbase + LOCOMO_DAC);
916 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
917 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
920 void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
922 struct locomo *lchip = locomo_chip_driver(ldev);
926 void *mapbase = lchip->base;
929 spin_lock_irqsave(&lchip->lock, flags);
932 udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */
933 r = locomo_readl(mapbase + LOCOMO_DAC);
934 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
935 locomo_writel(r, mapbase + LOCOMO_DAC);
936 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
937 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
938 r = locomo_readl(mapbase + LOCOMO_DAC);
939 r &= ~(LOCOMO_DAC_SDAOEB);
940 locomo_writel(r, mapbase + LOCOMO_DAC);
941 udelay(DAC_START_HOLD_TIME); /* 5.0 usec */
942 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
944 /* Send slave address and W bit (LSB is W bit) */
945 data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
946 for (i = 1; i <= 8; i++) {
947 locomo_m62332_sendbit(mapbase, data >> (8 - i));
951 r = locomo_readl(mapbase + LOCOMO_DAC);
952 r &= ~(LOCOMO_DAC_SCLOEB);
953 locomo_writel(r, mapbase + LOCOMO_DAC);
954 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
955 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
956 r = locomo_readl(mapbase + LOCOMO_DAC);
957 r &= ~(LOCOMO_DAC_SDAOEB);
958 locomo_writel(r, mapbase + LOCOMO_DAC);
959 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
960 r = locomo_readl(mapbase + LOCOMO_DAC);
961 r |= LOCOMO_DAC_SCLOEB;
962 locomo_writel(r, mapbase + LOCOMO_DAC);
963 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
964 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
965 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
966 printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
970 /* Send Sub address (LSB is channel select) */
971 /* channel = 0 : ch1 select */
972 /* = 1 : ch2 select */
973 data = M62332_SUB_ADDR + channel;
974 for (i = 1; i <= 8; i++) {
975 locomo_m62332_sendbit(mapbase, data >> (8 - i));
979 r = locomo_readl(mapbase + LOCOMO_DAC);
980 r &= ~(LOCOMO_DAC_SCLOEB);
981 locomo_writel(r, mapbase + LOCOMO_DAC);
982 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
983 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
984 r = locomo_readl(mapbase + LOCOMO_DAC);
985 r &= ~(LOCOMO_DAC_SDAOEB);
986 locomo_writel(r, mapbase + LOCOMO_DAC);
987 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
988 r = locomo_readl(mapbase + LOCOMO_DAC);
989 r |= LOCOMO_DAC_SCLOEB;
990 locomo_writel(r, mapbase + LOCOMO_DAC);
991 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
992 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
993 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
994 printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
999 for (i = 1; i <= 8; i++) {
1000 locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
1004 r = locomo_readl(mapbase + LOCOMO_DAC);
1005 r &= ~(LOCOMO_DAC_SCLOEB);
1006 locomo_writel(r, mapbase + LOCOMO_DAC);
1007 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1008 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1009 r = locomo_readl(mapbase + LOCOMO_DAC);
1010 r &= ~(LOCOMO_DAC_SDAOEB);
1011 locomo_writel(r, mapbase + LOCOMO_DAC);
1012 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1013 r = locomo_readl(mapbase + LOCOMO_DAC);
1014 r |= LOCOMO_DAC_SCLOEB;
1015 locomo_writel(r, mapbase + LOCOMO_DAC);
1016 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1017 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
1018 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
1019 printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
1024 r = locomo_readl(mapbase + LOCOMO_DAC);
1025 r &= ~(LOCOMO_DAC_SCLOEB);
1026 locomo_writel(r, mapbase + LOCOMO_DAC);
1027 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1028 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1029 r = locomo_readl(mapbase + LOCOMO_DAC);
1030 r |= LOCOMO_DAC_SCLOEB;
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 r = locomo_readl(mapbase + LOCOMO_DAC);
1035 r |= LOCOMO_DAC_SDAOEB;
1036 locomo_writel(r, mapbase + LOCOMO_DAC);
1037 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1038 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
1040 r = locomo_readl(mapbase + LOCOMO_DAC);
1041 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
1042 locomo_writel(r, mapbase + LOCOMO_DAC);
1043 udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */
1044 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1046 spin_unlock_irqrestore(&lchip->lock, flags);
1050 * Frontlight control
1053 static struct locomo *locomo_chip_driver(struct locomo_dev *ldev);
1055 void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf)
1057 unsigned long flags;
1058 struct locomo *lchip = locomo_chip_driver(dev);
1061 locomo_gpio_write(dev, LOCOMO_GPIO_FL_VR, 1);
1063 locomo_gpio_write(dev, LOCOMO_GPIO_FL_VR, 0);
1065 spin_lock_irqsave(&lchip->lock, flags);
1066 locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
1068 locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
1069 locomo_writel(bpwf | LOCOMO_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
1070 spin_unlock_irqrestore(&lchip->lock, flags);
1074 * LoCoMo "Register Access Bus."
1076 * We model this as a regular bus type, and hang devices directly
1079 static int locomo_match(struct device *_dev, struct device_driver *_drv)
1081 struct locomo_dev *dev = LOCOMO_DEV(_dev);
1082 struct locomo_driver *drv = LOCOMO_DRV(_drv);
1084 return dev->devid == drv->devid;
1087 static int locomo_bus_suspend(struct device *dev, pm_message_t state)
1089 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1090 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1093 if (drv && drv->suspend)
1094 ret = drv->suspend(ldev, state);
1098 static int locomo_bus_resume(struct device *dev)
1100 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1101 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1104 if (drv && drv->resume)
1105 ret = drv->resume(ldev);
1109 static int locomo_bus_probe(struct device *dev)
1111 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1112 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1116 ret = drv->probe(ldev);
1120 static int locomo_bus_remove(struct device *dev)
1122 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1123 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1127 ret = drv->remove(ldev);
1131 struct bus_type locomo_bus_type = {
1132 .name = "locomo-bus",
1133 .match = locomo_match,
1134 .probe = locomo_bus_probe,
1135 .remove = locomo_bus_remove,
1136 .suspend = locomo_bus_suspend,
1137 .resume = locomo_bus_resume,
1140 int locomo_driver_register(struct locomo_driver *driver)
1142 driver->drv.bus = &locomo_bus_type;
1143 return driver_register(&driver->drv);
1146 void locomo_driver_unregister(struct locomo_driver *driver)
1148 driver_unregister(&driver->drv);
1151 static int __init locomo_init(void)
1153 int ret = bus_register(&locomo_bus_type);
1155 platform_driver_register(&locomo_device_driver);
1159 static void __exit locomo_exit(void)
1161 platform_driver_unregister(&locomo_device_driver);
1162 bus_unregister(&locomo_bus_type);
1165 module_init(locomo_init);
1166 module_exit(locomo_exit);
1168 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1169 MODULE_LICENSE("GPL");
1170 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1172 EXPORT_SYMBOL(locomo_driver_register);
1173 EXPORT_SYMBOL(locomo_driver_unregister);
1174 EXPORT_SYMBOL(locomo_gpio_set_dir);
1175 EXPORT_SYMBOL(locomo_gpio_read_level);
1176 EXPORT_SYMBOL(locomo_gpio_read_output);
1177 EXPORT_SYMBOL(locomo_gpio_write);
1178 EXPORT_SYMBOL(locomo_m62332_senddata);