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>
30 #include <asm/mach-types.h>
33 #include <asm/mach/irq.h>
35 #include <asm/hardware/locomo.h>
37 /* M62332 output channel selection */
38 #define M62332_EVR_CH 1 /* M62332 volume channel number */
39 /* 0 : CH.1 , 1 : CH. 2 */
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) */
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 */
58 /* the following is the overall data for the locomo chip */
67 struct locomo_dev_info
{
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 */
80 static struct locomo_dev_info locomo_devices
[] = {
82 .devid
= LOCOMO_DEVID_KEYBOARD
,
86 .name
= "locomo-keyboard",
87 .offset
= LOCOMO_KEYBOARD
,
91 .devid
= LOCOMO_DEVID_FRONTLIGHT
,
93 .name
= "locomo-frontlight",
94 .offset
= LOCOMO_FRONTLIGHT
,
99 .devid
= LOCOMO_DEVID_BACKLIGHT
,
101 .name
= "locomo-backlight",
102 .offset
= LOCOMO_BACKLIGHT
,
106 .devid
= LOCOMO_DEVID_AUDIO
,
108 .name
= "locomo-audio",
109 .offset
= LOCOMO_AUDIO
,
113 .devid
= LOCOMO_DEVID_LED
,
115 .name
= "locomo-led",
116 .offset
= LOCOMO_LED
,
120 .devid
= LOCOMO_DEVID_UART
,
122 .name
= "locomo-uart",
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
137 * hardware irq reads LOCOMO_ICR & 0x0f00
138 * IRQ_LOCOMO_KEY_BASE
139 * IRQ_LOCOMO_GPIO_BASE
141 * IRQ_LOCOMO_SPI_BASE
142 * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
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
148 * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
151 * IRQ_LOCOMO_SPI_OVRN
152 * IRQ_LOCOMO_SPI_TEND
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)
161 static void locomo_handler(unsigned int irq
, struct irqdesc
*desc
,
162 struct pt_regs
*regs
)
166 void *mapbase
= get_irq_chipdata(irq
);
168 /* Acknowledge the parent IRQ */
169 desc
->chip
->ack(irq
);
171 /* check why this interrupt was generated */
172 req
= locomo_readl(mapbase
+ LOCOMO_ICR
) & 0x0f00;
175 /* generate the next interrupt(s) */
176 irq
= LOCOMO_IRQ_START
;
178 for (i
= 0; i
<= 3; i
++, d
++, irq
++) {
179 if (req
& (0x0100 << i
)) {
180 d
->handle(irq
, d
, regs
);
187 static void locomo_ack_irq(unsigned int irq
)
191 static void locomo_mask_irq(unsigned int irq
)
193 void *mapbase
= get_irq_chipdata(irq
);
195 r
= locomo_readl(mapbase
+ LOCOMO_ICR
);
196 r
&= ~(0x0010 << (irq
- LOCOMO_IRQ_START
));
197 locomo_writel(r
, mapbase
+ LOCOMO_ICR
);
200 static void locomo_unmask_irq(unsigned int irq
)
202 void *mapbase
= get_irq_chipdata(irq
);
204 r
= locomo_readl(mapbase
+ LOCOMO_ICR
);
205 r
|= (0x0010 << (irq
- LOCOMO_IRQ_START
));
206 locomo_writel(r
, mapbase
+ LOCOMO_ICR
);
209 static struct irqchip locomo_chip
= {
210 .ack
= locomo_ack_irq
,
211 .mask
= locomo_mask_irq
,
212 .unmask
= locomo_unmask_irq
,
215 static void locomo_key_handler(unsigned int irq
, struct irqdesc
*desc
,
216 struct pt_regs
*regs
)
219 void *mapbase
= get_irq_chipdata(irq
);
221 if (locomo_readl(mapbase
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
) & 0x0001) {
222 d
= irq_desc
+ LOCOMO_IRQ_KEY_START
;
223 d
->handle(LOCOMO_IRQ_KEY_START
, d
, regs
);
227 static void locomo_key_ack_irq(unsigned int irq
)
229 void *mapbase
= get_irq_chipdata(irq
);
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
);
236 static void locomo_key_mask_irq(unsigned int irq
)
238 void *mapbase
= get_irq_chipdata(irq
);
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
);
245 static void locomo_key_unmask_irq(unsigned int irq
)
247 void *mapbase
= get_irq_chipdata(irq
);
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
);
254 static struct irqchip locomo_key_chip
= {
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 *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 d
->handle(irq
, d
, regs
);
282 static void locomo_gpio_ack_irq(unsigned int irq
)
284 void *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 *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 *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 irqchip locomo_gpio_chip
= {
318 .ack
= locomo_gpio_ack_irq
,
319 .mask
= locomo_gpio_mask_irq
,
320 .unmask
= locomo_gpio_unmask_irq
,
323 static void locomo_lt_handler(unsigned int irq
, struct irqdesc
*desc
,
324 struct pt_regs
*regs
)
327 void *mapbase
= get_irq_chipdata(irq
);
329 if (locomo_readl(mapbase
+ LOCOMO_LTINT
) & 0x0001) {
330 d
= irq_desc
+ LOCOMO_IRQ_LT_START
;
331 d
->handle(LOCOMO_IRQ_LT_START
, d
, regs
);
335 static void locomo_lt_ack_irq(unsigned int irq
)
337 void *mapbase
= get_irq_chipdata(irq
);
339 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
340 r
&= ~(0x0100 << (irq
- LOCOMO_IRQ_LT_START
));
341 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
344 static void locomo_lt_mask_irq(unsigned int irq
)
346 void *mapbase
= get_irq_chipdata(irq
);
348 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
349 r
&= ~(0x0010 << (irq
- LOCOMO_IRQ_LT_START
));
350 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
353 static void locomo_lt_unmask_irq(unsigned int irq
)
355 void *mapbase
= get_irq_chipdata(irq
);
357 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
358 r
|= (0x0010 << (irq
- LOCOMO_IRQ_LT_START
));
359 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
362 static struct irqchip locomo_lt_chip
= {
363 .ack
= locomo_lt_ack_irq
,
364 .mask
= locomo_lt_mask_irq
,
365 .unmask
= locomo_lt_unmask_irq
,
368 static void locomo_spi_handler(unsigned int irq
, struct irqdesc
*desc
,
369 struct pt_regs
*regs
)
373 void *mapbase
= get_irq_chipdata(irq
);
375 req
= locomo_readl(mapbase
+ LOCOMO_SPIIR
) & 0x000F;
377 irq
= LOCOMO_IRQ_SPI_START
;
380 for (i
= 0; i
<= 3; i
++, irq
++, d
++) {
381 if (req
& (0x0001 << i
)) {
382 d
->handle(irq
, d
, regs
);
388 static void locomo_spi_ack_irq(unsigned int irq
)
390 void *mapbase
= get_irq_chipdata(irq
);
392 r
= locomo_readl(mapbase
+ LOCOMO_SPIWE
);
393 r
|= (0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
394 locomo_writel(r
, mapbase
+ LOCOMO_SPIWE
);
396 r
= locomo_readl(mapbase
+ LOCOMO_SPIIS
);
397 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
398 locomo_writel(r
, mapbase
+ LOCOMO_SPIIS
);
400 r
= locomo_readl(mapbase
+ LOCOMO_SPIWE
);
401 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
402 locomo_writel(r
, mapbase
+ LOCOMO_SPIWE
);
405 static void locomo_spi_mask_irq(unsigned int irq
)
407 void *mapbase
= get_irq_chipdata(irq
);
409 r
= locomo_readl(mapbase
+ LOCOMO_SPIIE
);
410 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
411 locomo_writel(r
, mapbase
+ LOCOMO_SPIIE
);
414 static void locomo_spi_unmask_irq(unsigned int irq
)
416 void *mapbase
= get_irq_chipdata(irq
);
418 r
= locomo_readl(mapbase
+ LOCOMO_SPIIE
);
419 r
|= (0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
420 locomo_writel(r
, mapbase
+ LOCOMO_SPIIE
);
423 static struct irqchip locomo_spi_chip
= {
424 .ack
= locomo_spi_ack_irq
,
425 .mask
= locomo_spi_mask_irq
,
426 .unmask
= locomo_spi_unmask_irq
,
429 static void locomo_setup_irq(struct locomo
*lchip
)
432 void *irqbase
= lchip
->base
;
435 * Install handler for IRQ_LOCOMO_HW.
437 set_irq_type(lchip
->irq
, IRQT_FALLING
);
438 set_irq_chipdata(lchip
->irq
, irqbase
);
439 set_irq_chained_handler(lchip
->irq
, locomo_handler
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
492 static void locomo_dev_release(struct device
*_dev
)
494 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
500 locomo_init_one_child(struct locomo
*lchip
, struct locomo_dev_info
*info
)
502 struct locomo_dev
*dev
;
505 dev
= kmalloc(sizeof(struct locomo_dev
), GFP_KERNEL
);
510 memset(dev
, 0, sizeof(struct locomo_dev
));
512 strncpy(dev
->dev
.bus_id
,info
->name
,sizeof(dev
->dev
.bus_id
));
514 * If the parent device has a DMA mask associated with it,
515 * propagate it down to the children.
517 if (lchip
->dev
->dma_mask
) {
518 dev
->dma_mask
= *lchip
->dev
->dma_mask
;
519 dev
->dev
.dma_mask
= &dev
->dma_mask
;
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
;
529 dev
->mapbase
= lchip
->base
+ info
->offset
;
532 dev
->length
= info
->length
;
534 memmove(dev
->irq
, info
->irq
, sizeof(dev
->irq
));
536 ret
= device_register(&dev
->dev
);
545 * locomo_probe - probe for a single LoCoMo chip.
546 * @phys_addr: physical address of device.
548 * Probe for a LoCoMo chip. This must be called
549 * before any other locomo-specific code.
552 * %-ENODEV device not found.
553 * %-EBUSY physical address already marked in-use.
557 __locomo_probe(struct device
*me
, struct resource
*mem
, int irq
)
559 struct locomo
*lchip
;
561 int i
, ret
= -ENODEV
;
563 lchip
= kmalloc(sizeof(struct locomo
), GFP_KERNEL
);
567 memset(lchip
, 0, sizeof(struct locomo
));
569 spin_lock_init(&lchip
->lock
);
572 dev_set_drvdata(lchip
->dev
, lchip
);
574 lchip
->phys
= mem
->start
;
578 * Map the whole region. This also maps the
579 * registers for our children.
581 lchip
->base
= ioremap(mem
->start
, PAGE_SIZE
);
587 /* locomo initialize */
588 locomo_writel(0, lchip
->base
+ LOCOMO_ICR
);
590 locomo_writel(0, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
593 locomo_writel(0, lchip
->base
+ LOCOMO_GPO
);
594 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
595 , lchip
->base
+ LOCOMO_GPE
);
596 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
597 , lchip
->base
+ LOCOMO_GPD
);
598 locomo_writel(0, lchip
->base
+ LOCOMO_GIE
);
601 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
602 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALD
);
604 locomo_writel(0, lchip
->base
+ LOCOMO_LTINT
);
606 locomo_writel(0, lchip
->base
+ LOCOMO_SPIIE
);
608 locomo_writel(6 + 8 + 320 + 30 - 10, lchip
->base
+ LOCOMO_ASD
);
609 r
= locomo_readl(lchip
->base
+ LOCOMO_ASD
);
611 locomo_writel(r
, lchip
->base
+ LOCOMO_ASD
);
613 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip
->base
+ LOCOMO_HSD
);
614 r
= locomo_readl(lchip
->base
+ LOCOMO_HSD
);
616 locomo_writel(r
, lchip
->base
+ LOCOMO_HSD
);
618 locomo_writel(128 / 8, lchip
->base
+ LOCOMO_HSC
);
621 locomo_writel(0x80, lchip
->base
+ LOCOMO_TADC
);
624 r
= locomo_readl(lchip
->base
+ LOCOMO_TADC
);
626 locomo_writel(r
, lchip
->base
+ LOCOMO_TADC
);
630 r
= locomo_readl(lchip
->base
+ LOCOMO_DAC
);
631 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
632 locomo_writel(r
, lchip
->base
+ LOCOMO_DAC
);
634 r
= locomo_readl(lchip
->base
+ LOCOMO_VER
);
635 printk(KERN_INFO
"LoCoMo Chip: %lu%lu\n", (r
>> 8), (r
& 0xff));
638 * The interrupt controller must be initialised before any
639 * other device to ensure that the interrupts are available.
641 if (lchip
->irq
!= NO_IRQ
)
642 locomo_setup_irq(lchip
);
644 for (i
= 0; i
< ARRAY_SIZE(locomo_devices
); i
++)
645 locomo_init_one_child(lchip
, &locomo_devices
[i
]);
654 static void __locomo_remove(struct locomo
*lchip
)
656 struct list_head
*l
, *n
;
658 list_for_each_safe(l
, n
, &lchip
->dev
->children
) {
659 struct device
*d
= list_to_dev(l
);
661 device_unregister(d
);
664 if (lchip
->irq
!= NO_IRQ
) {
665 set_irq_chained_handler(lchip
->irq
, NULL
);
666 set_irq_data(lchip
->irq
, NULL
);
669 iounmap(lchip
->base
);
673 static int locomo_probe(struct device
*dev
)
675 struct platform_device
*pdev
= to_platform_device(dev
);
676 struct resource
*mem
;
679 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
682 irq
= platform_get_irq(pdev
, 0);
684 return __locomo_probe(dev
, mem
, irq
);
687 static int locomo_remove(struct device
*dev
)
689 struct locomo
*lchip
= dev_get_drvdata(dev
);
692 __locomo_remove(lchip
);
693 dev_set_drvdata(dev
, NULL
);
700 * Not sure if this should be on the system bus or not yet.
701 * We really want some way to register a system device at
702 * the per-machine level, and then have this driver pick
703 * up the registered devices.
705 static struct device_driver locomo_device_driver
= {
707 .bus
= &platform_bus_type
,
708 .probe
= locomo_probe
,
709 .remove
= locomo_remove
,
713 * Get the parent device driver (us) structure
714 * from a child function device
716 static inline struct locomo
*locomo_chip_driver(struct locomo_dev
*ldev
)
718 return (struct locomo
*)dev_get_drvdata(ldev
->dev
.parent
);
721 void locomo_gpio_set_dir(struct locomo_dev
*ldev
, unsigned int bits
, unsigned int dir
)
723 struct locomo
*lchip
= locomo_chip_driver(ldev
);
727 spin_lock_irqsave(&lchip
->lock
, flags
);
729 r
= locomo_readl(lchip
->base
+ LOCOMO_GPD
);
731 locomo_writel(r
, lchip
->base
+ LOCOMO_GPD
);
733 r
= locomo_readl(lchip
->base
+ LOCOMO_GPE
);
738 locomo_writel(r
, lchip
->base
+ LOCOMO_GPE
);
740 spin_unlock_irqrestore(&lchip
->lock
, flags
);
743 unsigned int locomo_gpio_read_level(struct locomo_dev
*ldev
, unsigned int bits
)
745 struct locomo
*lchip
= locomo_chip_driver(ldev
);
749 spin_lock_irqsave(&lchip
->lock
, flags
);
750 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPL
);
751 spin_unlock_irqrestore(&lchip
->lock
, flags
);
757 unsigned int locomo_gpio_read_output(struct locomo_dev
*ldev
, unsigned int bits
)
759 struct locomo
*lchip
= locomo_chip_driver(ldev
);
763 spin_lock_irqsave(&lchip
->lock
, flags
);
764 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
765 spin_unlock_irqrestore(&lchip
->lock
, flags
);
771 void locomo_gpio_write(struct locomo_dev
*ldev
, unsigned int bits
, unsigned int set
)
773 struct locomo
*lchip
= locomo_chip_driver(ldev
);
777 spin_lock_irqsave(&lchip
->lock
, flags
);
779 r
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
784 locomo_writel(r
, lchip
->base
+ LOCOMO_GPO
);
786 spin_unlock_irqrestore(&lchip
->lock
, flags
);
789 static void locomo_m62332_sendbit(void *mapbase
, int bit
)
793 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
794 r
&= ~(LOCOMO_DAC_SCLOEB
);
795 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
796 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
797 udelay(DAC_DATA_HOLD_TIME
); /* 300 nsec */
798 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
799 r
&= ~(LOCOMO_DAC_SCLOEB
);
800 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
801 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
802 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
805 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
806 r
|= LOCOMO_DAC_SDAOEB
;
807 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
808 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
810 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
811 r
&= ~(LOCOMO_DAC_SDAOEB
);
812 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
813 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
816 udelay(DAC_DATA_SETUP_TIME
); /* 250 nsec */
817 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
818 r
|= LOCOMO_DAC_SCLOEB
;
819 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
820 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
821 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
824 void locomo_m62332_senddata(struct locomo_dev
*ldev
, unsigned int dac_data
, int channel
)
826 struct locomo
*lchip
= locomo_chip_driver(ldev
);
830 void *mapbase
= lchip
->base
;
833 spin_lock_irqsave(&lchip
->lock
, flags
);
836 udelay(DAC_BUS_FREE_TIME
); /* 5.0 usec */
837 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
838 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
839 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
840 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
841 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
842 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
843 r
&= ~(LOCOMO_DAC_SDAOEB
);
844 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
845 udelay(DAC_START_HOLD_TIME
); /* 5.0 usec */
846 udelay(DAC_DATA_HOLD_TIME
); /* 300 nsec */
848 /* Send slave address and W bit (LSB is W bit) */
849 data
= (M62332_SLAVE_ADDR
<< 1) | M62332_W_BIT
;
850 for (i
= 1; i
<= 8; i
++) {
851 locomo_m62332_sendbit(mapbase
, data
>> (8 - i
));
855 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
856 r
&= ~(LOCOMO_DAC_SCLOEB
);
857 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
858 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
859 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
860 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
861 r
&= ~(LOCOMO_DAC_SDAOEB
);
862 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
863 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
864 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
865 r
|= LOCOMO_DAC_SCLOEB
;
866 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
867 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
868 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
869 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
870 printk(KERN_WARNING
"locomo: m62332_senddata Error 1\n");
874 /* Send Sub address (LSB is channel select) */
875 /* channel = 0 : ch1 select */
876 /* = 1 : ch2 select */
877 data
= M62332_SUB_ADDR
+ channel
;
878 for (i
= 1; i
<= 8; i
++) {
879 locomo_m62332_sendbit(mapbase
, data
>> (8 - i
));
883 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
884 r
&= ~(LOCOMO_DAC_SCLOEB
);
885 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
886 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
887 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
888 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
889 r
&= ~(LOCOMO_DAC_SDAOEB
);
890 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
891 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
892 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
893 r
|= LOCOMO_DAC_SCLOEB
;
894 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
895 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
896 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
897 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
898 printk(KERN_WARNING
"locomo: m62332_senddata Error 2\n");
903 for (i
= 1; i
<= 8; i
++) {
904 locomo_m62332_sendbit(mapbase
, dac_data
>> (8 - i
));
908 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
909 r
&= ~(LOCOMO_DAC_SCLOEB
);
910 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
911 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
912 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
913 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
914 r
&= ~(LOCOMO_DAC_SDAOEB
);
915 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
916 udelay(DAC_LOW_SETUP_TIME
); /* 300 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.7 usec */
922 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
923 printk(KERN_WARNING
"locomo: m62332_senddata Error 3\n");
928 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
929 r
&= ~(LOCOMO_DAC_SCLOEB
);
930 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
931 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
932 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
933 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
934 r
|= LOCOMO_DAC_SCLOEB
;
935 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
936 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
937 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4 usec */
938 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
939 r
|= 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 usec */
944 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
945 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
946 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
947 udelay(DAC_LOW_SETUP_TIME
); /* 1000 nsec */
948 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
950 spin_unlock_irqrestore(&lchip
->lock
, flags
);
954 * LoCoMo "Register Access Bus."
956 * We model this as a regular bus type, and hang devices directly
959 static int locomo_match(struct device
*_dev
, struct device_driver
*_drv
)
961 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
962 struct locomo_driver
*drv
= LOCOMO_DRV(_drv
);
964 return dev
->devid
== drv
->devid
;
967 static int locomo_bus_suspend(struct device
*dev
, pm_message_t state
)
969 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
970 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
973 if (drv
&& drv
->suspend
)
974 ret
= drv
->suspend(ldev
, state
);
978 static int locomo_bus_resume(struct device
*dev
)
980 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
981 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
984 if (drv
&& drv
->resume
)
985 ret
= drv
->resume(ldev
);
989 static int locomo_bus_probe(struct device
*dev
)
991 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
992 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
996 ret
= drv
->probe(ldev
);
1000 static int locomo_bus_remove(struct device
*dev
)
1002 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1003 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1007 ret
= drv
->remove(ldev
);
1011 struct bus_type locomo_bus_type
= {
1012 .name
= "locomo-bus",
1013 .match
= locomo_match
,
1014 .suspend
= locomo_bus_suspend
,
1015 .resume
= locomo_bus_resume
,
1018 int locomo_driver_register(struct locomo_driver
*driver
)
1020 driver
->drv
.probe
= locomo_bus_probe
;
1021 driver
->drv
.remove
= locomo_bus_remove
;
1022 driver
->drv
.bus
= &locomo_bus_type
;
1023 return driver_register(&driver
->drv
);
1026 void locomo_driver_unregister(struct locomo_driver
*driver
)
1028 driver_unregister(&driver
->drv
);
1031 static int __init
locomo_init(void)
1033 int ret
= bus_register(&locomo_bus_type
);
1035 driver_register(&locomo_device_driver
);
1039 static void __exit
locomo_exit(void)
1041 driver_unregister(&locomo_device_driver
);
1042 bus_unregister(&locomo_bus_type
);
1045 module_init(locomo_init
);
1046 module_exit(locomo_exit
);
1048 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1049 MODULE_LICENSE("GPL");
1050 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1052 EXPORT_SYMBOL(locomo_driver_register
);
1053 EXPORT_SYMBOL(locomo_driver_unregister
);
1054 EXPORT_SYMBOL(locomo_gpio_set_dir
);
1055 EXPORT_SYMBOL(locomo_gpio_read_level
);
1056 EXPORT_SYMBOL(locomo_gpio_read_output
);
1057 EXPORT_SYMBOL(locomo_gpio_write
);
1058 EXPORT_SYMBOL(locomo_m62332_senddata
);