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 irqchip locomo_chip = {
208 .ack = locomo_ack_irq,
209 .mask = locomo_mask_irq,
210 .unmask = locomo_unmask_irq,
213 static void locomo_key_handler(unsigned int irq, struct irqdesc *desc,
214 struct pt_regs *regs)
217 void __iomem *mapbase = get_irq_chipdata(irq);
219 if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) {
220 d = irq_desc + LOCOMO_IRQ_KEY_START;
221 desc_handle_irq(LOCOMO_IRQ_KEY_START, d, regs);
225 static void locomo_key_ack_irq(unsigned int irq)
227 void __iomem *mapbase = get_irq_chipdata(irq);
229 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
230 r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START));
231 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
234 static void locomo_key_mask_irq(unsigned int irq)
236 void __iomem *mapbase = get_irq_chipdata(irq);
238 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
239 r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START));
240 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
243 static void locomo_key_unmask_irq(unsigned int irq)
245 void __iomem *mapbase = get_irq_chipdata(irq);
247 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
248 r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START));
249 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
252 static struct irqchip locomo_key_chip = {
253 .ack = locomo_key_ack_irq,
254 .mask = locomo_key_mask_irq,
255 .unmask = locomo_key_unmask_irq,
258 static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc,
259 struct pt_regs *regs)
263 void __iomem *mapbase = get_irq_chipdata(irq);
265 req = locomo_readl(mapbase + LOCOMO_GIR) &
266 locomo_readl(mapbase + LOCOMO_GPD) &
270 irq = LOCOMO_IRQ_GPIO_START;
271 d = irq_desc + LOCOMO_IRQ_GPIO_START;
272 for (i = 0; i <= 15; i++, irq++, d++) {
273 if (req & (0x0001 << i)) {
274 desc_handle_irq(irq, d, regs);
280 static void locomo_gpio_ack_irq(unsigned int irq)
282 void __iomem *mapbase = get_irq_chipdata(irq);
284 r = locomo_readl(mapbase + LOCOMO_GWE);
285 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
286 locomo_writel(r, mapbase + LOCOMO_GWE);
288 r = locomo_readl(mapbase + LOCOMO_GIS);
289 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
290 locomo_writel(r, mapbase + LOCOMO_GIS);
292 r = locomo_readl(mapbase + LOCOMO_GWE);
293 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
294 locomo_writel(r, mapbase + LOCOMO_GWE);
297 static void locomo_gpio_mask_irq(unsigned int irq)
299 void __iomem *mapbase = get_irq_chipdata(irq);
301 r = locomo_readl(mapbase + LOCOMO_GIE);
302 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
303 locomo_writel(r, mapbase + LOCOMO_GIE);
306 static void locomo_gpio_unmask_irq(unsigned int irq)
308 void __iomem *mapbase = get_irq_chipdata(irq);
310 r = locomo_readl(mapbase + LOCOMO_GIE);
311 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
312 locomo_writel(r, mapbase + LOCOMO_GIE);
315 static struct irqchip locomo_gpio_chip = {
316 .ack = locomo_gpio_ack_irq,
317 .mask = locomo_gpio_mask_irq,
318 .unmask = locomo_gpio_unmask_irq,
321 static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc,
322 struct pt_regs *regs)
325 void __iomem *mapbase = get_irq_chipdata(irq);
327 if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) {
328 d = irq_desc + LOCOMO_IRQ_LT_START;
329 desc_handle_irq(LOCOMO_IRQ_LT_START, d, regs);
333 static void locomo_lt_ack_irq(unsigned int irq)
335 void __iomem *mapbase = get_irq_chipdata(irq);
337 r = locomo_readl(mapbase + LOCOMO_LTINT);
338 r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START));
339 locomo_writel(r, mapbase + LOCOMO_LTINT);
342 static void locomo_lt_mask_irq(unsigned int irq)
344 void __iomem *mapbase = get_irq_chipdata(irq);
346 r = locomo_readl(mapbase + LOCOMO_LTINT);
347 r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START));
348 locomo_writel(r, mapbase + LOCOMO_LTINT);
351 static void locomo_lt_unmask_irq(unsigned int irq)
353 void __iomem *mapbase = get_irq_chipdata(irq);
355 r = locomo_readl(mapbase + LOCOMO_LTINT);
356 r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START));
357 locomo_writel(r, mapbase + LOCOMO_LTINT);
360 static struct irqchip locomo_lt_chip = {
361 .ack = locomo_lt_ack_irq,
362 .mask = locomo_lt_mask_irq,
363 .unmask = locomo_lt_unmask_irq,
366 static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc,
367 struct pt_regs *regs)
371 void __iomem *mapbase = get_irq_chipdata(irq);
373 req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F;
375 irq = LOCOMO_IRQ_SPI_START;
378 for (i = 0; i <= 3; i++, irq++, d++) {
379 if (req & (0x0001 << i)) {
380 desc_handle_irq(irq, d, regs);
386 static void locomo_spi_ack_irq(unsigned int irq)
388 void __iomem *mapbase = get_irq_chipdata(irq);
390 r = locomo_readl(mapbase + LOCOMO_SPIWE);
391 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
392 locomo_writel(r, mapbase + LOCOMO_SPIWE);
394 r = locomo_readl(mapbase + LOCOMO_SPIIS);
395 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
396 locomo_writel(r, mapbase + LOCOMO_SPIIS);
398 r = locomo_readl(mapbase + LOCOMO_SPIWE);
399 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
400 locomo_writel(r, mapbase + LOCOMO_SPIWE);
403 static void locomo_spi_mask_irq(unsigned int irq)
405 void __iomem *mapbase = get_irq_chipdata(irq);
407 r = locomo_readl(mapbase + LOCOMO_SPIIE);
408 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
409 locomo_writel(r, mapbase + LOCOMO_SPIIE);
412 static void locomo_spi_unmask_irq(unsigned int irq)
414 void __iomem *mapbase = get_irq_chipdata(irq);
416 r = locomo_readl(mapbase + LOCOMO_SPIIE);
417 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
418 locomo_writel(r, mapbase + LOCOMO_SPIIE);
421 static struct irqchip locomo_spi_chip = {
422 .ack = locomo_spi_ack_irq,
423 .mask = locomo_spi_mask_irq,
424 .unmask = locomo_spi_unmask_irq,
427 static void locomo_setup_irq(struct locomo *lchip)
430 void __iomem *irqbase = lchip->base;
433 * Install handler for IRQ_LOCOMO_HW.
435 set_irq_type(lchip->irq, IRQT_FALLING);
436 set_irq_chipdata(lchip->irq, irqbase);
437 set_irq_chained_handler(lchip->irq, locomo_handler);
439 /* Install handlers for IRQ_LOCOMO_*_BASE */
440 set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip);
441 set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase);
442 set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler);
443 set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE);
445 set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip);
446 set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase);
447 set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler);
448 set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE);
450 set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip);
451 set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase);
452 set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler);
453 set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE);
455 set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip);
456 set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase);
457 set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler);
458 set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE);
460 /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
461 set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip);
462 set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase);
463 set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ);
464 set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE);
466 /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
467 for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) {
468 set_irq_chip(irq, &locomo_gpio_chip);
469 set_irq_chipdata(irq, irqbase);
470 set_irq_handler(irq, do_edge_IRQ);
471 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
474 /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
475 set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip);
476 set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase);
477 set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ);
478 set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE);
480 /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
481 for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) {
482 set_irq_chip(irq, &locomo_spi_chip);
483 set_irq_chipdata(irq, irqbase);
484 set_irq_handler(irq, do_edge_IRQ);
485 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
490 static void locomo_dev_release(struct device *_dev)
492 struct locomo_dev *dev = LOCOMO_DEV(_dev);
498 locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
500 struct locomo_dev *dev;
503 dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL);
509 strncpy(dev->dev.bus_id,info->name,sizeof(dev->dev.bus_id));
511 * If the parent device has a DMA mask associated with it,
512 * propagate it down to the children.
514 if (lchip->dev->dma_mask) {
515 dev->dma_mask = *lchip->dev->dma_mask;
516 dev->dev.dma_mask = &dev->dma_mask;
519 dev->devid = info->devid;
520 dev->dev.parent = lchip->dev;
521 dev->dev.bus = &locomo_bus_type;
522 dev->dev.release = locomo_dev_release;
523 dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
526 dev->mapbase = lchip->base + info->offset;
529 dev->length = info->length;
531 memmove(dev->irq, info->irq, sizeof(dev->irq));
533 ret = device_register(&dev->dev);
543 struct locomo_save_data {
551 static int locomo_suspend(struct platform_device *dev, pm_message_t state)
553 struct locomo *lchip = platform_get_drvdata(dev);
554 struct locomo_save_data *save;
557 save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
561 dev->dev.power.saved_state = (void *) save;
563 spin_lock_irqsave(&lchip->lock, flags);
565 save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */
566 locomo_writel(0x00, lchip->base + LOCOMO_GPO);
567 save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPICT); /* SPI */
568 locomo_writel(0x40, lchip->base + LOCOMO_SPICT);
569 save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */
570 locomo_writel(0x00, lchip->base + LOCOMO_GPE);
571 save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */
572 locomo_writel(0x00, lchip->base + LOCOMO_ASD);
573 save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPIMD); /* SPI */
574 locomo_writel(0x3C14, lchip->base + LOCOMO_SPIMD);
576 locomo_writel(0x00, lchip->base + LOCOMO_PAIF);
577 locomo_writel(0x00, lchip->base + LOCOMO_DAC);
578 locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC);
580 if ( (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88) )
581 locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */
583 /* 18MHz already enabled, so no wait */
584 locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */
586 locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/
587 locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */
588 locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */
590 spin_unlock_irqrestore(&lchip->lock, flags);
595 static int locomo_resume(struct platform_device *dev)
597 struct locomo *lchip = platform_get_drvdata(dev);
598 struct locomo_save_data *save;
602 save = (struct locomo_save_data *) dev->dev.power.saved_state;
606 spin_lock_irqsave(&lchip->lock, flags);
608 locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
609 locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPICT);
610 locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
611 locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
612 locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPIMD);
614 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
615 locomo_writel(0x90, lchip->base + LOCOMO_TADC);
617 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
618 r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
620 locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
621 locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
623 spin_unlock_irqrestore(&lchip->lock, flags);
632 * locomo_probe - probe for a single LoCoMo chip.
633 * @phys_addr: physical address of device.
635 * Probe for a LoCoMo chip. This must be called
636 * before any other locomo-specific code.
639 * %-ENODEV device not found.
640 * %-EBUSY physical address already marked in-use.
644 __locomo_probe(struct device *me, struct resource *mem, int irq)
646 struct locomo *lchip;
648 int i, ret = -ENODEV;
650 lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL);
654 spin_lock_init(&lchip->lock);
657 dev_set_drvdata(lchip->dev, lchip);
659 lchip->phys = mem->start;
663 * Map the whole region. This also maps the
664 * registers for our children.
666 lchip->base = ioremap(mem->start, PAGE_SIZE);
672 /* locomo initialize */
673 locomo_writel(0, lchip->base + LOCOMO_ICR);
675 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
678 locomo_writel(0, lchip->base + LOCOMO_GPO);
679 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
680 , lchip->base + LOCOMO_GPE);
681 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
682 , lchip->base + LOCOMO_GPD);
683 locomo_writel(0, lchip->base + LOCOMO_GIE);
686 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
687 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
690 locomo_writel(0, lchip->base + LOCOMO_LTINT);
692 locomo_writel(0, lchip->base + LOCOMO_SPIIE);
694 locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
695 r = locomo_readl(lchip->base + LOCOMO_ASD);
697 locomo_writel(r, lchip->base + LOCOMO_ASD);
699 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
700 r = locomo_readl(lchip->base + LOCOMO_HSD);
702 locomo_writel(r, lchip->base + LOCOMO_HSD);
704 locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
707 locomo_writel(0x80, lchip->base + LOCOMO_TADC);
710 r = locomo_readl(lchip->base + LOCOMO_TADC);
712 locomo_writel(r, lchip->base + LOCOMO_TADC);
716 r = locomo_readl(lchip->base + LOCOMO_DAC);
717 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
718 locomo_writel(r, lchip->base + LOCOMO_DAC);
720 r = locomo_readl(lchip->base + LOCOMO_VER);
721 printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
724 * The interrupt controller must be initialised before any
725 * other device to ensure that the interrupts are available.
727 if (lchip->irq != NO_IRQ)
728 locomo_setup_irq(lchip);
730 for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
731 locomo_init_one_child(lchip, &locomo_devices[i]);
740 static int locomo_remove_child(struct device *dev, void *data)
742 device_unregister(dev);
746 static void __locomo_remove(struct locomo *lchip)
748 device_for_each_child(lchip->dev, NULL, locomo_remove_child);
750 if (lchip->irq != NO_IRQ) {
751 set_irq_chained_handler(lchip->irq, NULL);
752 set_irq_data(lchip->irq, NULL);
755 iounmap(lchip->base);
759 static int locomo_probe(struct platform_device *dev)
761 struct resource *mem;
764 mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
767 irq = platform_get_irq(dev, 0);
771 return __locomo_probe(&dev->dev, mem, irq);
774 static int locomo_remove(struct platform_device *dev)
776 struct locomo *lchip = platform_get_drvdata(dev);
779 __locomo_remove(lchip);
780 platform_set_drvdata(dev, NULL);
787 * Not sure if this should be on the system bus or not yet.
788 * We really want some way to register a system device at
789 * the per-machine level, and then have this driver pick
790 * up the registered devices.
792 static struct platform_driver locomo_device_driver = {
793 .probe = locomo_probe,
794 .remove = locomo_remove,
796 .suspend = locomo_suspend,
797 .resume = locomo_resume,
805 * Get the parent device driver (us) structure
806 * from a child function device
808 static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
810 return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
813 void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir)
815 struct locomo *lchip = locomo_chip_driver(ldev);
819 spin_lock_irqsave(&lchip->lock, flags);
821 r = locomo_readl(lchip->base + LOCOMO_GPD);
823 locomo_writel(r, lchip->base + LOCOMO_GPD);
825 r = locomo_readl(lchip->base + LOCOMO_GPE);
830 locomo_writel(r, lchip->base + LOCOMO_GPE);
832 spin_unlock_irqrestore(&lchip->lock, flags);
835 unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits)
837 struct locomo *lchip = locomo_chip_driver(ldev);
841 spin_lock_irqsave(&lchip->lock, flags);
842 ret = locomo_readl(lchip->base + LOCOMO_GPL);
843 spin_unlock_irqrestore(&lchip->lock, flags);
849 unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits)
851 struct locomo *lchip = locomo_chip_driver(ldev);
855 spin_lock_irqsave(&lchip->lock, flags);
856 ret = locomo_readl(lchip->base + LOCOMO_GPO);
857 spin_unlock_irqrestore(&lchip->lock, flags);
863 void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set)
865 struct locomo *lchip = locomo_chip_driver(ldev);
869 spin_lock_irqsave(&lchip->lock, flags);
871 r = locomo_readl(lchip->base + LOCOMO_GPO);
876 locomo_writel(r, lchip->base + LOCOMO_GPO);
878 spin_unlock_irqrestore(&lchip->lock, flags);
881 static void locomo_m62332_sendbit(void *mapbase, int bit)
885 r = locomo_readl(mapbase + LOCOMO_DAC);
886 r &= ~(LOCOMO_DAC_SCLOEB);
887 locomo_writel(r, mapbase + LOCOMO_DAC);
888 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
889 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
890 r = locomo_readl(mapbase + LOCOMO_DAC);
891 r &= ~(LOCOMO_DAC_SCLOEB);
892 locomo_writel(r, mapbase + LOCOMO_DAC);
893 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
894 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
897 r = locomo_readl(mapbase + LOCOMO_DAC);
898 r |= LOCOMO_DAC_SDAOEB;
899 locomo_writel(r, mapbase + LOCOMO_DAC);
900 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
902 r = locomo_readl(mapbase + LOCOMO_DAC);
903 r &= ~(LOCOMO_DAC_SDAOEB);
904 locomo_writel(r, mapbase + LOCOMO_DAC);
905 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
908 udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */
909 r = locomo_readl(mapbase + LOCOMO_DAC);
910 r |= LOCOMO_DAC_SCLOEB;
911 locomo_writel(r, mapbase + LOCOMO_DAC);
912 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
913 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
916 void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
918 struct locomo *lchip = locomo_chip_driver(ldev);
922 void *mapbase = lchip->base;
925 spin_lock_irqsave(&lchip->lock, flags);
928 udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */
929 r = locomo_readl(mapbase + LOCOMO_DAC);
930 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
931 locomo_writel(r, mapbase + LOCOMO_DAC);
932 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
933 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
934 r = locomo_readl(mapbase + LOCOMO_DAC);
935 r &= ~(LOCOMO_DAC_SDAOEB);
936 locomo_writel(r, mapbase + LOCOMO_DAC);
937 udelay(DAC_START_HOLD_TIME); /* 5.0 usec */
938 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
940 /* Send slave address and W bit (LSB is W bit) */
941 data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
942 for (i = 1; i <= 8; i++) {
943 locomo_m62332_sendbit(mapbase, data >> (8 - i));
947 r = locomo_readl(mapbase + LOCOMO_DAC);
948 r &= ~(LOCOMO_DAC_SCLOEB);
949 locomo_writel(r, mapbase + LOCOMO_DAC);
950 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
951 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
952 r = locomo_readl(mapbase + LOCOMO_DAC);
953 r &= ~(LOCOMO_DAC_SDAOEB);
954 locomo_writel(r, mapbase + LOCOMO_DAC);
955 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
956 r = locomo_readl(mapbase + LOCOMO_DAC);
957 r |= LOCOMO_DAC_SCLOEB;
958 locomo_writel(r, mapbase + LOCOMO_DAC);
959 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
960 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
961 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
962 printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
966 /* Send Sub address (LSB is channel select) */
967 /* channel = 0 : ch1 select */
968 /* = 1 : ch2 select */
969 data = M62332_SUB_ADDR + channel;
970 for (i = 1; i <= 8; i++) {
971 locomo_m62332_sendbit(mapbase, data >> (8 - i));
975 r = locomo_readl(mapbase + LOCOMO_DAC);
976 r &= ~(LOCOMO_DAC_SCLOEB);
977 locomo_writel(r, mapbase + LOCOMO_DAC);
978 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
979 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
980 r = locomo_readl(mapbase + LOCOMO_DAC);
981 r &= ~(LOCOMO_DAC_SDAOEB);
982 locomo_writel(r, mapbase + LOCOMO_DAC);
983 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
984 r = locomo_readl(mapbase + LOCOMO_DAC);
985 r |= LOCOMO_DAC_SCLOEB;
986 locomo_writel(r, mapbase + LOCOMO_DAC);
987 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
988 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
989 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
990 printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
995 for (i = 1; i <= 8; i++) {
996 locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
1000 r = locomo_readl(mapbase + LOCOMO_DAC);
1001 r &= ~(LOCOMO_DAC_SCLOEB);
1002 locomo_writel(r, mapbase + LOCOMO_DAC);
1003 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1004 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1005 r = locomo_readl(mapbase + LOCOMO_DAC);
1006 r &= ~(LOCOMO_DAC_SDAOEB);
1007 locomo_writel(r, mapbase + LOCOMO_DAC);
1008 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1009 r = locomo_readl(mapbase + LOCOMO_DAC);
1010 r |= LOCOMO_DAC_SCLOEB;
1011 locomo_writel(r, mapbase + LOCOMO_DAC);
1012 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1013 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
1014 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
1015 printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
1020 r = locomo_readl(mapbase + LOCOMO_DAC);
1021 r &= ~(LOCOMO_DAC_SCLOEB);
1022 locomo_writel(r, mapbase + LOCOMO_DAC);
1023 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
1024 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1025 r = locomo_readl(mapbase + LOCOMO_DAC);
1026 r |= LOCOMO_DAC_SCLOEB;
1027 locomo_writel(r, mapbase + LOCOMO_DAC);
1028 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1029 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
1030 r = locomo_readl(mapbase + LOCOMO_DAC);
1031 r |= LOCOMO_DAC_SDAOEB;
1032 locomo_writel(r, mapbase + LOCOMO_DAC);
1033 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
1034 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
1036 r = locomo_readl(mapbase + LOCOMO_DAC);
1037 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
1038 locomo_writel(r, mapbase + LOCOMO_DAC);
1039 udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */
1040 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
1042 spin_unlock_irqrestore(&lchip->lock, flags);
1046 * Frontlight control
1049 static struct locomo *locomo_chip_driver(struct locomo_dev *ldev);
1051 void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf)
1053 unsigned long flags;
1054 struct locomo *lchip = locomo_chip_driver(dev);
1057 locomo_gpio_write(dev, LOCOMO_GPIO_FL_VR, 1);
1059 locomo_gpio_write(dev, LOCOMO_GPIO_FL_VR, 0);
1061 spin_lock_irqsave(&lchip->lock, flags);
1062 locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
1064 locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
1065 locomo_writel(bpwf | LOCOMO_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
1066 spin_unlock_irqrestore(&lchip->lock, flags);
1070 * LoCoMo "Register Access Bus."
1072 * We model this as a regular bus type, and hang devices directly
1075 static int locomo_match(struct device *_dev, struct device_driver *_drv)
1077 struct locomo_dev *dev = LOCOMO_DEV(_dev);
1078 struct locomo_driver *drv = LOCOMO_DRV(_drv);
1080 return dev->devid == drv->devid;
1083 static int locomo_bus_suspend(struct device *dev, pm_message_t state)
1085 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1086 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1089 if (drv && drv->suspend)
1090 ret = drv->suspend(ldev, state);
1094 static int locomo_bus_resume(struct device *dev)
1096 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1097 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1100 if (drv && drv->resume)
1101 ret = drv->resume(ldev);
1105 static int locomo_bus_probe(struct device *dev)
1107 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1108 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1112 ret = drv->probe(ldev);
1116 static int locomo_bus_remove(struct device *dev)
1118 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1119 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1123 ret = drv->remove(ldev);
1127 struct bus_type locomo_bus_type = {
1128 .name = "locomo-bus",
1129 .match = locomo_match,
1130 .probe = locomo_bus_probe,
1131 .remove = locomo_bus_remove,
1132 .suspend = locomo_bus_suspend,
1133 .resume = locomo_bus_resume,
1136 int locomo_driver_register(struct locomo_driver *driver)
1138 driver->drv.bus = &locomo_bus_type;
1139 return driver_register(&driver->drv);
1142 void locomo_driver_unregister(struct locomo_driver *driver)
1144 driver_unregister(&driver->drv);
1147 static int __init locomo_init(void)
1149 int ret = bus_register(&locomo_bus_type);
1151 platform_driver_register(&locomo_device_driver);
1155 static void __exit locomo_exit(void)
1157 platform_driver_unregister(&locomo_device_driver);
1158 bus_unregister(&locomo_bus_type);
1161 module_init(locomo_init);
1162 module_exit(locomo_exit);
1164 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1165 MODULE_LICENSE("GPL");
1166 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1168 EXPORT_SYMBOL(locomo_driver_register);
1169 EXPORT_SYMBOL(locomo_driver_unregister);
1170 EXPORT_SYMBOL(locomo_gpio_set_dir);
1171 EXPORT_SYMBOL(locomo_gpio_read_level);
1172 EXPORT_SYMBOL(locomo_gpio_read_output);
1173 EXPORT_SYMBOL(locomo_gpio_write);
1174 EXPORT_SYMBOL(locomo_m62332_senddata);