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 */
68 struct locomo_dev_info
{
76 /* All the locomo devices. If offset is non-zero, the mapbase for the
77 * locomo_dev will be set to the chip base plus offset. If offset is
78 * zero, then the mapbase for the locomo_dev will be set to zero. An
79 * offset of zero means the device only uses GPIOs or other helper
80 * functions inside this file */
81 static struct locomo_dev_info locomo_devices
[] = {
83 .devid
= LOCOMO_DEVID_KEYBOARD
,
87 .name
= "locomo-keyboard",
88 .offset
= LOCOMO_KEYBOARD
,
92 .devid
= LOCOMO_DEVID_FRONTLIGHT
,
94 .name
= "locomo-frontlight",
95 .offset
= LOCOMO_FRONTLIGHT
,
100 .devid
= LOCOMO_DEVID_BACKLIGHT
,
102 .name
= "locomo-backlight",
103 .offset
= LOCOMO_BACKLIGHT
,
107 .devid
= LOCOMO_DEVID_AUDIO
,
109 .name
= "locomo-audio",
110 .offset
= LOCOMO_AUDIO
,
114 .devid
= LOCOMO_DEVID_LED
,
116 .name
= "locomo-led",
117 .offset
= LOCOMO_LED
,
121 .devid
= LOCOMO_DEVID_UART
,
123 .name
= "locomo-uart",
128 .devid
= LOCOMO_DEVID_SPI
,
130 .name
= "locomo-spi",
131 .offset
= LOCOMO_SPI
,
137 /** LoCoMo interrupt handling stuff.
138 * NOTE: LoCoMo has a 1 to many mapping on all of its IRQs.
139 * that is, there is only one real hardware interrupt
140 * we determine which interrupt it is by reading some IO memory.
141 * We have two levels of expansion, first in the handler for the
142 * hardware interrupt we generate an interrupt
143 * IRQ_LOCOMO_*_BASE and those handlers generate more interrupts
145 * hardware irq reads LOCOMO_ICR & 0x0f00
146 * IRQ_LOCOMO_KEY_BASE
147 * IRQ_LOCOMO_GPIO_BASE
149 * IRQ_LOCOMO_SPI_BASE
150 * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
152 * IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff
153 * IRQ_LOCOMO_GPIO[0-15]
154 * IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001
156 * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
159 * IRQ_LOCOMO_SPI_OVRN
160 * IRQ_LOCOMO_SPI_TEND
163 #define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE)
164 #define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY)
165 #define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0)
166 #define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT)
167 #define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR)
169 static void locomo_handler(unsigned int irq
, struct irq_desc
*desc
)
173 void __iomem
*mapbase
= get_irq_chip_data(irq
);
175 /* Acknowledge the parent IRQ */
176 desc
->chip
->ack(irq
);
178 /* check why this interrupt was generated */
179 req
= locomo_readl(mapbase
+ LOCOMO_ICR
) & 0x0f00;
182 /* generate the next interrupt(s) */
183 irq
= LOCOMO_IRQ_START
;
185 for (i
= 0; i
<= 3; i
++, d
++, irq
++) {
186 if (req
& (0x0100 << i
)) {
187 desc_handle_irq(irq
, d
);
194 static void locomo_ack_irq(unsigned int irq
)
198 static void locomo_mask_irq(unsigned int irq
)
200 void __iomem
*mapbase
= get_irq_chip_data(irq
);
202 r
= locomo_readl(mapbase
+ LOCOMO_ICR
);
203 r
&= ~(0x0010 << (irq
- LOCOMO_IRQ_START
));
204 locomo_writel(r
, mapbase
+ LOCOMO_ICR
);
207 static void locomo_unmask_irq(unsigned int irq
)
209 void __iomem
*mapbase
= get_irq_chip_data(irq
);
211 r
= locomo_readl(mapbase
+ LOCOMO_ICR
);
212 r
|= (0x0010 << (irq
- LOCOMO_IRQ_START
));
213 locomo_writel(r
, mapbase
+ LOCOMO_ICR
);
216 static struct irq_chip locomo_chip
= {
218 .ack
= locomo_ack_irq
,
219 .mask
= locomo_mask_irq
,
220 .unmask
= locomo_unmask_irq
,
223 static void locomo_key_handler(unsigned int irq
, struct irq_desc
*desc
)
226 void __iomem
*mapbase
= get_irq_chip_data(irq
);
228 if (locomo_readl(mapbase
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
) & 0x0001) {
229 d
= irq_desc
+ LOCOMO_IRQ_KEY_START
;
230 desc_handle_irq(LOCOMO_IRQ_KEY_START
, d
);
234 static void locomo_key_ack_irq(unsigned int irq
)
236 void __iomem
*mapbase
= get_irq_chip_data(irq
);
238 r
= locomo_readl(mapbase
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
239 r
&= ~(0x0100 << (irq
- LOCOMO_IRQ_KEY_START
));
240 locomo_writel(r
, mapbase
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
243 static void locomo_key_mask_irq(unsigned int irq
)
245 void __iomem
*mapbase
= get_irq_chip_data(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 void locomo_key_unmask_irq(unsigned int irq
)
254 void __iomem
*mapbase
= get_irq_chip_data(irq
);
256 r
= locomo_readl(mapbase
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
257 r
|= (0x0010 << (irq
- LOCOMO_IRQ_KEY_START
));
258 locomo_writel(r
, mapbase
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
261 static struct irq_chip locomo_key_chip
= {
262 .name
= "LOCOMO-key",
263 .ack
= locomo_key_ack_irq
,
264 .mask
= locomo_key_mask_irq
,
265 .unmask
= locomo_key_unmask_irq
,
268 static void locomo_gpio_handler(unsigned int irq
, struct irq_desc
*desc
)
272 void __iomem
*mapbase
= get_irq_chip_data(irq
);
274 req
= locomo_readl(mapbase
+ LOCOMO_GIR
) &
275 locomo_readl(mapbase
+ LOCOMO_GPD
) &
279 irq
= LOCOMO_IRQ_GPIO_START
;
280 d
= irq_desc
+ LOCOMO_IRQ_GPIO_START
;
281 for (i
= 0; i
<= 15; i
++, irq
++, d
++) {
282 if (req
& (0x0001 << i
)) {
283 desc_handle_irq(irq
, d
);
289 static void locomo_gpio_ack_irq(unsigned int irq
)
291 void __iomem
*mapbase
= get_irq_chip_data(irq
);
293 r
= locomo_readl(mapbase
+ LOCOMO_GWE
);
294 r
|= (0x0001 << (irq
- LOCOMO_IRQ_GPIO_START
));
295 locomo_writel(r
, mapbase
+ LOCOMO_GWE
);
297 r
= locomo_readl(mapbase
+ LOCOMO_GIS
);
298 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_GPIO_START
));
299 locomo_writel(r
, mapbase
+ LOCOMO_GIS
);
301 r
= locomo_readl(mapbase
+ LOCOMO_GWE
);
302 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_GPIO_START
));
303 locomo_writel(r
, mapbase
+ LOCOMO_GWE
);
306 static void locomo_gpio_mask_irq(unsigned int irq
)
308 void __iomem
*mapbase
= get_irq_chip_data(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 void locomo_gpio_unmask_irq(unsigned int irq
)
317 void __iomem
*mapbase
= get_irq_chip_data(irq
);
319 r
= locomo_readl(mapbase
+ LOCOMO_GIE
);
320 r
|= (0x0001 << (irq
- LOCOMO_IRQ_GPIO_START
));
321 locomo_writel(r
, mapbase
+ LOCOMO_GIE
);
324 static int GPIO_IRQ_rising_edge
;
325 static int GPIO_IRQ_falling_edge
;
327 static int locomo_gpio_type(unsigned int irq
, unsigned int type
)
330 void __iomem
*mapbase
= get_irq_chip_data(irq
);
332 mask
= 1 << (irq
- LOCOMO_IRQ_GPIO_START
);
334 if (type
== IRQT_PROBE
) {
335 if ((GPIO_IRQ_rising_edge
| GPIO_IRQ_falling_edge
) & mask
)
337 type
= __IRQT_RISEDGE
| __IRQT_FALEDGE
;
340 if (type
& __IRQT_RISEDGE
)
341 GPIO_IRQ_rising_edge
|= mask
;
343 GPIO_IRQ_rising_edge
&= ~mask
;
344 if (type
& __IRQT_FALEDGE
)
345 GPIO_IRQ_falling_edge
|= mask
;
347 GPIO_IRQ_falling_edge
&= ~mask
;
348 locomo_writel(GPIO_IRQ_rising_edge
, mapbase
+ LOCOMO_GRIE
);
349 locomo_writel(GPIO_IRQ_falling_edge
, mapbase
+ LOCOMO_GFIE
);
354 static struct irq_chip locomo_gpio_chip
= {
355 .name
= "LOCOMO-gpio",
356 .ack
= locomo_gpio_ack_irq
,
357 .mask
= locomo_gpio_mask_irq
,
358 .unmask
= locomo_gpio_unmask_irq
,
359 .set_type
= locomo_gpio_type
,
362 static void locomo_lt_handler(unsigned int irq
, struct irq_desc
*desc
)
365 void __iomem
*mapbase
= get_irq_chip_data(irq
);
367 if (locomo_readl(mapbase
+ LOCOMO_LTINT
) & 0x0001) {
368 d
= irq_desc
+ LOCOMO_IRQ_LT_START
;
369 desc_handle_irq(LOCOMO_IRQ_LT_START
, d
);
373 static void locomo_lt_ack_irq(unsigned int irq
)
375 void __iomem
*mapbase
= get_irq_chip_data(irq
);
377 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
378 r
&= ~(0x0100 << (irq
- LOCOMO_IRQ_LT_START
));
379 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
382 static void locomo_lt_mask_irq(unsigned int irq
)
384 void __iomem
*mapbase
= get_irq_chip_data(irq
);
386 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
387 r
&= ~(0x0010 << (irq
- LOCOMO_IRQ_LT_START
));
388 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
391 static void locomo_lt_unmask_irq(unsigned int irq
)
393 void __iomem
*mapbase
= get_irq_chip_data(irq
);
395 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
396 r
|= (0x0010 << (irq
- LOCOMO_IRQ_LT_START
));
397 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
400 static struct irq_chip locomo_lt_chip
= {
402 .ack
= locomo_lt_ack_irq
,
403 .mask
= locomo_lt_mask_irq
,
404 .unmask
= locomo_lt_unmask_irq
,
407 static void locomo_spi_handler(unsigned int irq
, struct irq_desc
*desc
)
411 void __iomem
*mapbase
= get_irq_chip_data(irq
);
413 req
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIR
) & 0x000F;
415 irq
= LOCOMO_IRQ_SPI_START
;
418 for (i
= 0; i
<= 3; i
++, irq
++, d
++) {
419 if (req
& (0x0001 << i
)) {
420 desc_handle_irq(irq
, d
);
426 static void locomo_spi_ack_irq(unsigned int irq
)
428 void __iomem
*mapbase
= get_irq_chip_data(irq
);
430 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
431 r
|= (0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
432 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
434 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIS
);
435 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
436 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIS
);
438 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
439 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
440 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
443 static void locomo_spi_mask_irq(unsigned int irq
)
445 void __iomem
*mapbase
= get_irq_chip_data(irq
);
447 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
448 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
449 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
452 static void locomo_spi_unmask_irq(unsigned int irq
)
454 void __iomem
*mapbase
= get_irq_chip_data(irq
);
456 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
457 r
|= (0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
458 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
461 static struct irq_chip locomo_spi_chip
= {
462 .name
= "LOCOMO-spi",
463 .ack
= locomo_spi_ack_irq
,
464 .mask
= locomo_spi_mask_irq
,
465 .unmask
= locomo_spi_unmask_irq
,
468 static void locomo_setup_irq(struct locomo
*lchip
)
471 void __iomem
*irqbase
= lchip
->base
;
474 * Install handler for IRQ_LOCOMO_HW.
476 set_irq_type(lchip
->irq
, IRQT_FALLING
);
477 set_irq_chip_data(lchip
->irq
, irqbase
);
478 set_irq_chained_handler(lchip
->irq
, locomo_handler
);
480 /* Install handlers for IRQ_LOCOMO_*_BASE */
481 set_irq_chip(IRQ_LOCOMO_KEY_BASE
, &locomo_chip
);
482 set_irq_chip_data(IRQ_LOCOMO_KEY_BASE
, irqbase
);
483 set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE
, locomo_key_handler
);
485 set_irq_chip(IRQ_LOCOMO_GPIO_BASE
, &locomo_chip
);
486 set_irq_chip_data(IRQ_LOCOMO_GPIO_BASE
, irqbase
);
487 set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE
, locomo_gpio_handler
);
489 set_irq_chip(IRQ_LOCOMO_LT_BASE
, &locomo_chip
);
490 set_irq_chip_data(IRQ_LOCOMO_LT_BASE
, irqbase
);
491 set_irq_chained_handler(IRQ_LOCOMO_LT_BASE
, locomo_lt_handler
);
493 set_irq_chip(IRQ_LOCOMO_SPI_BASE
, &locomo_chip
);
494 set_irq_chip_data(IRQ_LOCOMO_SPI_BASE
, irqbase
);
495 set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE
, locomo_spi_handler
);
497 /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
498 set_irq_chip(LOCOMO_IRQ_KEY_START
, &locomo_key_chip
);
499 set_irq_chip_data(LOCOMO_IRQ_KEY_START
, irqbase
);
500 set_irq_handler(LOCOMO_IRQ_KEY_START
, handle_edge_irq
);
501 set_irq_flags(LOCOMO_IRQ_KEY_START
, IRQF_VALID
| IRQF_PROBE
);
503 /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
504 for (irq
= LOCOMO_IRQ_GPIO_START
; irq
< LOCOMO_IRQ_GPIO_START
+ 16; irq
++) {
505 set_irq_chip(irq
, &locomo_gpio_chip
);
506 set_irq_chip_data(irq
, irqbase
);
507 set_irq_handler(irq
, handle_edge_irq
);
508 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
511 /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
512 set_irq_chip(LOCOMO_IRQ_LT_START
, &locomo_lt_chip
);
513 set_irq_chip_data(LOCOMO_IRQ_LT_START
, irqbase
);
514 set_irq_handler(LOCOMO_IRQ_LT_START
, handle_edge_irq
);
515 set_irq_flags(LOCOMO_IRQ_LT_START
, IRQF_VALID
| IRQF_PROBE
);
517 /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
518 for (irq
= LOCOMO_IRQ_SPI_START
; irq
< LOCOMO_IRQ_SPI_START
+ 4; irq
++) {
519 set_irq_chip(irq
, &locomo_spi_chip
);
520 set_irq_chip_data(irq
, irqbase
);
521 set_irq_handler(irq
, handle_edge_irq
);
522 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
527 static void locomo_dev_release(struct device
*_dev
)
529 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
535 locomo_init_one_child(struct locomo
*lchip
, struct locomo_dev_info
*info
)
537 struct locomo_dev
*dev
;
540 dev
= kzalloc(sizeof(struct locomo_dev
), GFP_KERNEL
);
546 strncpy(dev
->dev
.bus_id
, info
->name
, sizeof(dev
->dev
.bus_id
));
548 * If the parent device has a DMA mask associated with it,
549 * propagate it down to the children.
551 if (lchip
->dev
->dma_mask
) {
552 dev
->dma_mask
= *lchip
->dev
->dma_mask
;
553 dev
->dev
.dma_mask
= &dev
->dma_mask
;
556 dev
->devid
= info
->devid
;
557 dev
->dev
.parent
= lchip
->dev
;
558 dev
->dev
.bus
= &locomo_bus_type
;
559 dev
->dev
.release
= locomo_dev_release
;
560 dev
->dev
.coherent_dma_mask
= lchip
->dev
->coherent_dma_mask
;
563 dev
->mapbase
= lchip
->base
+ info
->offset
;
566 dev
->length
= info
->length
;
568 memmove(dev
->irq
, info
->irq
, sizeof(dev
->irq
));
570 ret
= device_register(&dev
->dev
);
580 struct locomo_save_data
{
588 static int locomo_suspend(struct platform_device
*dev
, pm_message_t state
)
590 struct locomo
*lchip
= platform_get_drvdata(dev
);
591 struct locomo_save_data
*save
;
594 save
= kmalloc(sizeof(struct locomo_save_data
), GFP_KERNEL
);
598 lchip
->saved_state
= save
;
600 spin_lock_irqsave(&lchip
->lock
, flags
);
602 save
->LCM_GPO
= locomo_readl(lchip
->base
+ LOCOMO_GPO
); /* GPIO */
603 locomo_writel(0x00, lchip
->base
+ LOCOMO_GPO
);
604 save
->LCM_SPICT
= locomo_readl(lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPICT
); /* SPI */
605 locomo_writel(0x40, lchip
->base
+ LOCOMO_SPICT
);
606 save
->LCM_GPE
= locomo_readl(lchip
->base
+ LOCOMO_GPE
); /* GPIO */
607 locomo_writel(0x00, lchip
->base
+ LOCOMO_GPE
);
608 save
->LCM_ASD
= locomo_readl(lchip
->base
+ LOCOMO_ASD
); /* ADSTART */
609 locomo_writel(0x00, lchip
->base
+ LOCOMO_ASD
);
610 save
->LCM_SPIMD
= locomo_readl(lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPIMD
); /* SPI */
611 locomo_writel(0x3C14, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPIMD
);
613 locomo_writel(0x00, lchip
->base
+ LOCOMO_PAIF
);
614 locomo_writel(0x00, lchip
->base
+ LOCOMO_DAC
);
615 locomo_writel(0x00, lchip
->base
+ LOCOMO_BACKLIGHT
+ LOCOMO_TC
);
617 if ((locomo_readl(lchip
->base
+ LOCOMO_LED
+ LOCOMO_LPT0
) & 0x88) && (locomo_readl(lchip
->base
+ LOCOMO_LED
+ LOCOMO_LPT1
) & 0x88))
618 locomo_writel(0x00, lchip
->base
+ LOCOMO_C32K
); /* CLK32 off */
620 /* 18MHz already enabled, so no wait */
621 locomo_writel(0xc1, lchip
->base
+ LOCOMO_C32K
); /* CLK32 on */
623 locomo_writel(0x00, lchip
->base
+ LOCOMO_TADC
); /* 18MHz clock off*/
624 locomo_writel(0x00, lchip
->base
+ LOCOMO_AUDIO
+ LOCOMO_ACC
); /* 22MHz/24MHz clock off */
625 locomo_writel(0x00, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
); /* FL */
627 spin_unlock_irqrestore(&lchip
->lock
, flags
);
632 static int locomo_resume(struct platform_device
*dev
)
634 struct locomo
*lchip
= platform_get_drvdata(dev
);
635 struct locomo_save_data
*save
;
639 save
= lchip
->saved_state
;
643 spin_lock_irqsave(&lchip
->lock
, flags
);
645 locomo_writel(save
->LCM_GPO
, lchip
->base
+ LOCOMO_GPO
);
646 locomo_writel(save
->LCM_SPICT
, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPICT
);
647 locomo_writel(save
->LCM_GPE
, lchip
->base
+ LOCOMO_GPE
);
648 locomo_writel(save
->LCM_ASD
, lchip
->base
+ LOCOMO_ASD
);
649 locomo_writel(save
->LCM_SPIMD
, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPIMD
);
651 locomo_writel(0x00, lchip
->base
+ LOCOMO_C32K
);
652 locomo_writel(0x90, lchip
->base
+ LOCOMO_TADC
);
654 locomo_writel(0, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KSC
);
655 r
= locomo_readl(lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
657 locomo_writel(r
, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
658 locomo_writel(0x1, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KCMD
);
660 spin_unlock_irqrestore(&lchip
->lock
, flags
);
662 lchip
->saved_state
= NULL
;
671 * locomo_probe - probe for a single LoCoMo chip.
672 * @phys_addr: physical address of device.
674 * Probe for a LoCoMo chip. This must be called
675 * before any other locomo-specific code.
678 * %-ENODEV device not found.
679 * %-EBUSY physical address already marked in-use.
683 __locomo_probe(struct device
*me
, struct resource
*mem
, int irq
)
685 struct locomo
*lchip
;
687 int i
, ret
= -ENODEV
;
689 lchip
= kzalloc(sizeof(struct locomo
), GFP_KERNEL
);
693 spin_lock_init(&lchip
->lock
);
696 dev_set_drvdata(lchip
->dev
, lchip
);
698 lchip
->phys
= mem
->start
;
702 * Map the whole region. This also maps the
703 * registers for our children.
705 lchip
->base
= ioremap(mem
->start
, PAGE_SIZE
);
711 /* locomo initialize */
712 locomo_writel(0, lchip
->base
+ LOCOMO_ICR
);
714 locomo_writel(0, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
717 locomo_writel(0, lchip
->base
+ LOCOMO_GPO
);
718 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
719 , lchip
->base
+ LOCOMO_GPE
);
720 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
721 , lchip
->base
+ LOCOMO_GPD
);
722 locomo_writel(0, lchip
->base
+ LOCOMO_GIE
);
725 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
726 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALD
);
729 locomo_writel(0, lchip
->base
+ LOCOMO_LTINT
);
731 locomo_writel(0, lchip
->base
+ LOCOMO_SPIIE
);
733 locomo_writel(6 + 8 + 320 + 30 - 10, lchip
->base
+ LOCOMO_ASD
);
734 r
= locomo_readl(lchip
->base
+ LOCOMO_ASD
);
736 locomo_writel(r
, lchip
->base
+ LOCOMO_ASD
);
738 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip
->base
+ LOCOMO_HSD
);
739 r
= locomo_readl(lchip
->base
+ LOCOMO_HSD
);
741 locomo_writel(r
, lchip
->base
+ LOCOMO_HSD
);
743 locomo_writel(128 / 8, lchip
->base
+ LOCOMO_HSC
);
746 locomo_writel(0x80, lchip
->base
+ LOCOMO_TADC
);
749 r
= locomo_readl(lchip
->base
+ LOCOMO_TADC
);
751 locomo_writel(r
, lchip
->base
+ LOCOMO_TADC
);
755 r
= locomo_readl(lchip
->base
+ LOCOMO_DAC
);
756 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
757 locomo_writel(r
, lchip
->base
+ LOCOMO_DAC
);
759 r
= locomo_readl(lchip
->base
+ LOCOMO_VER
);
760 printk(KERN_INFO
"LoCoMo Chip: %lu%lu\n", (r
>> 8), (r
& 0xff));
763 * The interrupt controller must be initialised before any
764 * other device to ensure that the interrupts are available.
766 if (lchip
->irq
!= NO_IRQ
)
767 locomo_setup_irq(lchip
);
769 for (i
= 0; i
< ARRAY_SIZE(locomo_devices
); i
++)
770 locomo_init_one_child(lchip
, &locomo_devices
[i
]);
778 static int locomo_remove_child(struct device
*dev
, void *data
)
780 device_unregister(dev
);
784 static void __locomo_remove(struct locomo
*lchip
)
786 device_for_each_child(lchip
->dev
, NULL
, locomo_remove_child
);
788 if (lchip
->irq
!= NO_IRQ
) {
789 set_irq_chained_handler(lchip
->irq
, NULL
);
790 set_irq_data(lchip
->irq
, NULL
);
793 iounmap(lchip
->base
);
797 static int locomo_probe(struct platform_device
*dev
)
799 struct resource
*mem
;
802 mem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
805 irq
= platform_get_irq(dev
, 0);
809 return __locomo_probe(&dev
->dev
, mem
, irq
);
812 static int locomo_remove(struct platform_device
*dev
)
814 struct locomo
*lchip
= platform_get_drvdata(dev
);
817 __locomo_remove(lchip
);
818 platform_set_drvdata(dev
, NULL
);
825 * Not sure if this should be on the system bus or not yet.
826 * We really want some way to register a system device at
827 * the per-machine level, and then have this driver pick
828 * up the registered devices.
830 static struct platform_driver locomo_device_driver
= {
831 .probe
= locomo_probe
,
832 .remove
= locomo_remove
,
834 .suspend
= locomo_suspend
,
835 .resume
= locomo_resume
,
843 * Get the parent device driver (us) structure
844 * from a child function device
846 static inline struct locomo
*locomo_chip_driver(struct locomo_dev
*ldev
)
848 return (struct locomo
*)dev_get_drvdata(ldev
->dev
.parent
);
851 void locomo_gpio_set_dir(struct device
*dev
, unsigned int bits
, unsigned int dir
)
853 struct locomo
*lchip
= dev_get_drvdata(dev
);
860 spin_lock_irqsave(&lchip
->lock
, flags
);
862 r
= locomo_readl(lchip
->base
+ LOCOMO_GPD
);
867 locomo_writel(r
, lchip
->base
+ LOCOMO_GPD
);
869 r
= locomo_readl(lchip
->base
+ LOCOMO_GPE
);
874 locomo_writel(r
, lchip
->base
+ LOCOMO_GPE
);
876 spin_unlock_irqrestore(&lchip
->lock
, flags
);
879 int locomo_gpio_read_level(struct device
*dev
, unsigned int bits
)
881 struct locomo
*lchip
= dev_get_drvdata(dev
);
888 spin_lock_irqsave(&lchip
->lock
, flags
);
889 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPL
);
890 spin_unlock_irqrestore(&lchip
->lock
, flags
);
896 int locomo_gpio_read_output(struct device
*dev
, unsigned int bits
)
898 struct locomo
*lchip
= dev_get_drvdata(dev
);
905 spin_lock_irqsave(&lchip
->lock
, flags
);
906 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
907 spin_unlock_irqrestore(&lchip
->lock
, flags
);
913 void locomo_gpio_write(struct device
*dev
, unsigned int bits
, unsigned int set
)
915 struct locomo
*lchip
= dev_get_drvdata(dev
);
922 spin_lock_irqsave(&lchip
->lock
, flags
);
924 r
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
929 locomo_writel(r
, lchip
->base
+ LOCOMO_GPO
);
931 spin_unlock_irqrestore(&lchip
->lock
, flags
);
934 static void locomo_m62332_sendbit(void *mapbase
, int bit
)
938 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
939 r
&= ~(LOCOMO_DAC_SCLOEB
);
940 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
941 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
942 udelay(DAC_DATA_HOLD_TIME
); /* 300 nsec */
943 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
944 r
&= ~(LOCOMO_DAC_SCLOEB
);
945 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
946 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
947 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
950 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
951 r
|= LOCOMO_DAC_SDAOEB
;
952 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
953 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
955 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
956 r
&= ~(LOCOMO_DAC_SDAOEB
);
957 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
958 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
961 udelay(DAC_DATA_SETUP_TIME
); /* 250 nsec */
962 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
963 r
|= LOCOMO_DAC_SCLOEB
;
964 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
965 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
966 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
969 void locomo_m62332_senddata(struct locomo_dev
*ldev
, unsigned int dac_data
, int channel
)
971 struct locomo
*lchip
= locomo_chip_driver(ldev
);
975 void *mapbase
= lchip
->base
;
978 spin_lock_irqsave(&lchip
->lock
, flags
);
981 udelay(DAC_BUS_FREE_TIME
); /* 5.0 usec */
982 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
983 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
984 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
985 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
986 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
987 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
988 r
&= ~(LOCOMO_DAC_SDAOEB
);
989 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
990 udelay(DAC_START_HOLD_TIME
); /* 5.0 usec */
991 udelay(DAC_DATA_HOLD_TIME
); /* 300 nsec */
993 /* Send slave address and W bit (LSB is W bit) */
994 data
= (M62332_SLAVE_ADDR
<< 1) | M62332_W_BIT
;
995 for (i
= 1; i
<= 8; i
++) {
996 locomo_m62332_sendbit(mapbase
, 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 1\n");
1019 /* Send Sub address (LSB is channel select) */
1020 /* channel = 0 : ch1 select */
1021 /* = 1 : ch2 select */
1022 data
= M62332_SUB_ADDR
+ channel
;
1023 for (i
= 1; i
<= 8; i
++) {
1024 locomo_m62332_sendbit(mapbase
, data
>> (8 - i
));
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_SDAOEB
);
1035 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1036 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1037 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1038 r
|= LOCOMO_DAC_SCLOEB
;
1039 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1040 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1041 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
1042 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
1043 printk(KERN_WARNING
"locomo: m62332_senddata Error 2\n");
1048 for (i
= 1; i
<= 8; i
++) {
1049 locomo_m62332_sendbit(mapbase
, dac_data
>> (8 - i
));
1053 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1054 r
&= ~(LOCOMO_DAC_SCLOEB
);
1055 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1056 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1057 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
1058 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1059 r
&= ~(LOCOMO_DAC_SDAOEB
);
1060 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1061 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1062 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1063 r
|= LOCOMO_DAC_SCLOEB
;
1064 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1065 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1066 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
1067 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
1068 printk(KERN_WARNING
"locomo: m62332_senddata Error 3\n");
1073 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1074 r
&= ~(LOCOMO_DAC_SCLOEB
);
1075 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1076 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1077 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
1078 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1079 r
|= LOCOMO_DAC_SCLOEB
;
1080 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1081 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1082 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4 usec */
1083 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1084 r
|= LOCOMO_DAC_SDAOEB
;
1085 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1086 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1087 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4 usec */
1089 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1090 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
1091 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1092 udelay(DAC_LOW_SETUP_TIME
); /* 1000 nsec */
1093 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
1095 spin_unlock_irqrestore(&lchip
->lock
, flags
);
1099 * Frontlight control
1102 static struct locomo
*locomo_chip_driver(struct locomo_dev
*ldev
);
1104 void locomo_frontlight_set(struct locomo_dev
*dev
, int duty
, int vr
, int bpwf
)
1106 unsigned long flags
;
1107 struct locomo
*lchip
= locomo_chip_driver(dev
);
1110 locomo_gpio_write(dev
->dev
.parent
, LOCOMO_GPIO_FL_VR
, 1);
1112 locomo_gpio_write(dev
->dev
.parent
, LOCOMO_GPIO_FL_VR
, 0);
1114 spin_lock_irqsave(&lchip
->lock
, flags
);
1115 locomo_writel(bpwf
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
1117 locomo_writel(duty
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALD
);
1118 locomo_writel(bpwf
| LOCOMO_ALC_EN
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
1119 spin_unlock_irqrestore(&lchip
->lock
, flags
);
1123 * LoCoMo "Register Access Bus."
1125 * We model this as a regular bus type, and hang devices directly
1128 static int locomo_match(struct device
*_dev
, struct device_driver
*_drv
)
1130 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
1131 struct locomo_driver
*drv
= LOCOMO_DRV(_drv
);
1133 return dev
->devid
== drv
->devid
;
1136 static int locomo_bus_suspend(struct device
*dev
, pm_message_t state
)
1138 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1139 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1142 if (drv
&& drv
->suspend
)
1143 ret
= drv
->suspend(ldev
, state
);
1147 static int locomo_bus_resume(struct device
*dev
)
1149 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1150 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1153 if (drv
&& drv
->resume
)
1154 ret
= drv
->resume(ldev
);
1158 static int locomo_bus_probe(struct device
*dev
)
1160 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1161 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1165 ret
= drv
->probe(ldev
);
1169 static int locomo_bus_remove(struct device
*dev
)
1171 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1172 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1176 ret
= drv
->remove(ldev
);
1180 struct bus_type locomo_bus_type
= {
1181 .name
= "locomo-bus",
1182 .match
= locomo_match
,
1183 .probe
= locomo_bus_probe
,
1184 .remove
= locomo_bus_remove
,
1185 .suspend
= locomo_bus_suspend
,
1186 .resume
= locomo_bus_resume
,
1189 int locomo_driver_register(struct locomo_driver
*driver
)
1191 driver
->drv
.bus
= &locomo_bus_type
;
1192 return driver_register(&driver
->drv
);
1195 void locomo_driver_unregister(struct locomo_driver
*driver
)
1197 driver_unregister(&driver
->drv
);
1200 static int __init
locomo_init(void)
1202 int ret
= bus_register(&locomo_bus_type
);
1204 platform_driver_register(&locomo_device_driver
);
1208 static void __exit
locomo_exit(void)
1210 platform_driver_unregister(&locomo_device_driver
);
1211 bus_unregister(&locomo_bus_type
);
1214 module_init(locomo_init
);
1215 module_exit(locomo_exit
);
1217 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1218 MODULE_LICENSE("GPL");
1219 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1221 EXPORT_SYMBOL(locomo_driver_register
);
1222 EXPORT_SYMBOL(locomo_driver_unregister
);
1223 EXPORT_SYMBOL(locomo_gpio_set_dir
);
1224 EXPORT_SYMBOL(locomo_gpio_read_level
);
1225 EXPORT_SYMBOL(locomo_gpio_read_output
);
1226 EXPORT_SYMBOL(locomo_gpio_write
);
1227 EXPORT_SYMBOL(locomo_m62332_senddata
);