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 struct irq_chip locomo_gpio_chip
= {
325 .name
= "LOCOMO-gpio",
326 .ack
= locomo_gpio_ack_irq
,
327 .mask
= locomo_gpio_mask_irq
,
328 .unmask
= locomo_gpio_unmask_irq
,
331 static void locomo_lt_handler(unsigned int irq
, struct irq_desc
*desc
)
334 void __iomem
*mapbase
= get_irq_chip_data(irq
);
336 if (locomo_readl(mapbase
+ LOCOMO_LTINT
) & 0x0001) {
337 d
= irq_desc
+ LOCOMO_IRQ_LT_START
;
338 desc_handle_irq(LOCOMO_IRQ_LT_START
, d
);
342 static void locomo_lt_ack_irq(unsigned int irq
)
344 void __iomem
*mapbase
= get_irq_chip_data(irq
);
346 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
347 r
&= ~(0x0100 << (irq
- LOCOMO_IRQ_LT_START
));
348 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
351 static void locomo_lt_mask_irq(unsigned int irq
)
353 void __iomem
*mapbase
= get_irq_chip_data(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 void locomo_lt_unmask_irq(unsigned int irq
)
362 void __iomem
*mapbase
= get_irq_chip_data(irq
);
364 r
= locomo_readl(mapbase
+ LOCOMO_LTINT
);
365 r
|= (0x0010 << (irq
- LOCOMO_IRQ_LT_START
));
366 locomo_writel(r
, mapbase
+ LOCOMO_LTINT
);
369 static struct irq_chip locomo_lt_chip
= {
371 .ack
= locomo_lt_ack_irq
,
372 .mask
= locomo_lt_mask_irq
,
373 .unmask
= locomo_lt_unmask_irq
,
376 static void locomo_spi_handler(unsigned int irq
, struct irq_desc
*desc
)
380 void __iomem
*mapbase
= get_irq_chip_data(irq
);
382 req
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIR
) & 0x000F;
384 irq
= LOCOMO_IRQ_SPI_START
;
387 for (i
= 0; i
<= 3; i
++, irq
++, d
++) {
388 if (req
& (0x0001 << i
)) {
389 desc_handle_irq(irq
, d
);
395 static void locomo_spi_ack_irq(unsigned int irq
)
397 void __iomem
*mapbase
= get_irq_chip_data(irq
);
399 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
400 r
|= (0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
401 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
403 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIS
);
404 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
405 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIS
);
407 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
408 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
409 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIWE
);
412 static void locomo_spi_mask_irq(unsigned int irq
)
414 void __iomem
*mapbase
= get_irq_chip_data(irq
);
416 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
417 r
&= ~(0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
418 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
421 static void locomo_spi_unmask_irq(unsigned int irq
)
423 void __iomem
*mapbase
= get_irq_chip_data(irq
);
425 r
= locomo_readl(mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
426 r
|= (0x0001 << (irq
- LOCOMO_IRQ_SPI_START
));
427 locomo_writel(r
, mapbase
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
430 static struct irq_chip locomo_spi_chip
= {
431 .name
= "LOCOMO-spi",
432 .ack
= locomo_spi_ack_irq
,
433 .mask
= locomo_spi_mask_irq
,
434 .unmask
= locomo_spi_unmask_irq
,
437 static void locomo_setup_irq(struct locomo
*lchip
)
440 void __iomem
*irqbase
= lchip
->base
;
443 * Install handler for IRQ_LOCOMO_HW.
445 set_irq_type(lchip
->irq
, IRQT_FALLING
);
446 set_irq_chip_data(lchip
->irq
, irqbase
);
447 set_irq_chained_handler(lchip
->irq
, locomo_handler
);
449 /* Install handlers for IRQ_LOCOMO_*_BASE */
450 set_irq_chip(IRQ_LOCOMO_KEY_BASE
, &locomo_chip
);
451 set_irq_chip_data(IRQ_LOCOMO_KEY_BASE
, irqbase
);
452 set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE
, locomo_key_handler
);
453 set_irq_flags(IRQ_LOCOMO_KEY_BASE
, IRQF_VALID
| IRQF_PROBE
);
455 set_irq_chip(IRQ_LOCOMO_GPIO_BASE
, &locomo_chip
);
456 set_irq_chip_data(IRQ_LOCOMO_GPIO_BASE
, irqbase
);
457 set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE
, locomo_gpio_handler
);
458 set_irq_flags(IRQ_LOCOMO_GPIO_BASE
, IRQF_VALID
| IRQF_PROBE
);
460 set_irq_chip(IRQ_LOCOMO_LT_BASE
, &locomo_chip
);
461 set_irq_chip_data(IRQ_LOCOMO_LT_BASE
, irqbase
);
462 set_irq_chained_handler(IRQ_LOCOMO_LT_BASE
, locomo_lt_handler
);
463 set_irq_flags(IRQ_LOCOMO_LT_BASE
, IRQF_VALID
| IRQF_PROBE
);
465 set_irq_chip(IRQ_LOCOMO_SPI_BASE
, &locomo_chip
);
466 set_irq_chip_data(IRQ_LOCOMO_SPI_BASE
, irqbase
);
467 set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE
, locomo_spi_handler
);
468 set_irq_flags(IRQ_LOCOMO_SPI_BASE
, IRQF_VALID
| IRQF_PROBE
);
470 /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
471 set_irq_chip(LOCOMO_IRQ_KEY_START
, &locomo_key_chip
);
472 set_irq_chip_data(LOCOMO_IRQ_KEY_START
, irqbase
);
473 set_irq_handler(LOCOMO_IRQ_KEY_START
, handle_edge_irq
);
474 set_irq_flags(LOCOMO_IRQ_KEY_START
, IRQF_VALID
| IRQF_PROBE
);
476 /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
477 for (irq
= LOCOMO_IRQ_GPIO_START
; irq
< LOCOMO_IRQ_GPIO_START
+ 16; irq
++) {
478 set_irq_chip(irq
, &locomo_gpio_chip
);
479 set_irq_chip_data(irq
, irqbase
);
480 set_irq_handler(irq
, handle_edge_irq
);
481 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
484 /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
485 set_irq_chip(LOCOMO_IRQ_LT_START
, &locomo_lt_chip
);
486 set_irq_chip_data(LOCOMO_IRQ_LT_START
, irqbase
);
487 set_irq_handler(LOCOMO_IRQ_LT_START
, handle_edge_irq
);
488 set_irq_flags(LOCOMO_IRQ_LT_START
, IRQF_VALID
| IRQF_PROBE
);
490 /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
491 for (irq
= LOCOMO_IRQ_SPI_START
; irq
< LOCOMO_IRQ_SPI_START
+ 3; irq
++) {
492 set_irq_chip(irq
, &locomo_spi_chip
);
493 set_irq_chip_data(irq
, irqbase
);
494 set_irq_handler(irq
, handle_edge_irq
);
495 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
500 static void locomo_dev_release(struct device
*_dev
)
502 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
508 locomo_init_one_child(struct locomo
*lchip
, struct locomo_dev_info
*info
)
510 struct locomo_dev
*dev
;
513 dev
= kzalloc(sizeof(struct locomo_dev
), GFP_KERNEL
);
519 strncpy(dev
->dev
.bus_id
, info
->name
, sizeof(dev
->dev
.bus_id
));
521 * If the parent device has a DMA mask associated with it,
522 * propagate it down to the children.
524 if (lchip
->dev
->dma_mask
) {
525 dev
->dma_mask
= *lchip
->dev
->dma_mask
;
526 dev
->dev
.dma_mask
= &dev
->dma_mask
;
529 dev
->devid
= info
->devid
;
530 dev
->dev
.parent
= lchip
->dev
;
531 dev
->dev
.bus
= &locomo_bus_type
;
532 dev
->dev
.release
= locomo_dev_release
;
533 dev
->dev
.coherent_dma_mask
= lchip
->dev
->coherent_dma_mask
;
536 dev
->mapbase
= lchip
->base
+ info
->offset
;
539 dev
->length
= info
->length
;
541 memmove(dev
->irq
, info
->irq
, sizeof(dev
->irq
));
543 ret
= device_register(&dev
->dev
);
553 struct locomo_save_data
{
561 static int locomo_suspend(struct platform_device
*dev
, pm_message_t state
)
563 struct locomo
*lchip
= platform_get_drvdata(dev
);
564 struct locomo_save_data
*save
;
567 save
= kmalloc(sizeof(struct locomo_save_data
), GFP_KERNEL
);
571 lchip
->saved_state
= save
;
573 spin_lock_irqsave(&lchip
->lock
, flags
);
575 save
->LCM_GPO
= locomo_readl(lchip
->base
+ LOCOMO_GPO
); /* GPIO */
576 locomo_writel(0x00, lchip
->base
+ LOCOMO_GPO
);
577 save
->LCM_SPICT
= locomo_readl(lchip
->base
+ LOCOMO_SPICT
); /* SPI */
578 locomo_writel(0x40, lchip
->base
+ LOCOMO_SPICT
);
579 save
->LCM_GPE
= locomo_readl(lchip
->base
+ LOCOMO_GPE
); /* GPIO */
580 locomo_writel(0x00, lchip
->base
+ LOCOMO_GPE
);
581 save
->LCM_ASD
= locomo_readl(lchip
->base
+ LOCOMO_ASD
); /* ADSTART */
582 locomo_writel(0x00, lchip
->base
+ LOCOMO_ASD
);
583 save
->LCM_SPIMD
= locomo_readl(lchip
->base
+ LOCOMO_SPIMD
); /* SPI */
584 locomo_writel(0x3C14, lchip
->base
+ LOCOMO_SPIMD
);
586 locomo_writel(0x00, lchip
->base
+ LOCOMO_PAIF
);
587 locomo_writel(0x00, lchip
->base
+ LOCOMO_DAC
);
588 locomo_writel(0x00, lchip
->base
+ LOCOMO_BACKLIGHT
+ LOCOMO_TC
);
590 if ( (locomo_readl(lchip
->base
+ LOCOMO_LED
+ LOCOMO_LPT0
) & 0x88) && (locomo_readl(lchip
->base
+ LOCOMO_LED
+ LOCOMO_LPT1
) & 0x88) )
591 locomo_writel(0x00, lchip
->base
+ LOCOMO_C32K
); /* CLK32 off */
593 /* 18MHz already enabled, so no wait */
594 locomo_writel(0xc1, lchip
->base
+ LOCOMO_C32K
); /* CLK32 on */
596 locomo_writel(0x00, lchip
->base
+ LOCOMO_TADC
); /* 18MHz clock off*/
597 locomo_writel(0x00, lchip
->base
+ LOCOMO_AUDIO
+ LOCOMO_ACC
); /* 22MHz/24MHz clock off */
598 locomo_writel(0x00, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
); /* FL */
600 spin_unlock_irqrestore(&lchip
->lock
, flags
);
605 static int locomo_resume(struct platform_device
*dev
)
607 struct locomo
*lchip
= platform_get_drvdata(dev
);
608 struct locomo_save_data
*save
;
612 save
= lchip
->saved_state
;
616 spin_lock_irqsave(&lchip
->lock
, flags
);
618 locomo_writel(save
->LCM_GPO
, lchip
->base
+ LOCOMO_GPO
);
619 locomo_writel(save
->LCM_SPICT
, lchip
->base
+ LOCOMO_SPICT
);
620 locomo_writel(save
->LCM_GPE
, lchip
->base
+ LOCOMO_GPE
);
621 locomo_writel(save
->LCM_ASD
, lchip
->base
+ LOCOMO_ASD
);
622 locomo_writel(save
->LCM_SPIMD
, lchip
->base
+ LOCOMO_SPIMD
);
624 locomo_writel(0x00, lchip
->base
+ LOCOMO_C32K
);
625 locomo_writel(0x90, lchip
->base
+ LOCOMO_TADC
);
627 locomo_writel(0, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KSC
);
628 r
= locomo_readl(lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
630 locomo_writel(r
, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
631 locomo_writel(0x1, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KCMD
);
633 spin_unlock_irqrestore(&lchip
->lock
, flags
);
635 lchip
->saved_state
= NULL
;
644 * locomo_probe - probe for a single LoCoMo chip.
645 * @phys_addr: physical address of device.
647 * Probe for a LoCoMo chip. This must be called
648 * before any other locomo-specific code.
651 * %-ENODEV device not found.
652 * %-EBUSY physical address already marked in-use.
656 __locomo_probe(struct device
*me
, struct resource
*mem
, int irq
)
658 struct locomo
*lchip
;
660 int i
, ret
= -ENODEV
;
662 lchip
= kzalloc(sizeof(struct locomo
), GFP_KERNEL
);
666 spin_lock_init(&lchip
->lock
);
669 dev_set_drvdata(lchip
->dev
, lchip
);
671 lchip
->phys
= mem
->start
;
675 * Map the whole region. This also maps the
676 * registers for our children.
678 lchip
->base
= ioremap(mem
->start
, PAGE_SIZE
);
684 /* locomo initialize */
685 locomo_writel(0, lchip
->base
+ LOCOMO_ICR
);
687 locomo_writel(0, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
690 locomo_writel(0, lchip
->base
+ LOCOMO_GPO
);
691 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
692 , lchip
->base
+ LOCOMO_GPE
);
693 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
694 , lchip
->base
+ LOCOMO_GPD
);
695 locomo_writel(0, lchip
->base
+ LOCOMO_GIE
);
698 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
699 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALD
);
702 locomo_writel(0, lchip
->base
+ LOCOMO_LTINT
);
704 locomo_writel(0, lchip
->base
+ LOCOMO_SPIIE
);
706 locomo_writel(6 + 8 + 320 + 30 - 10, lchip
->base
+ LOCOMO_ASD
);
707 r
= locomo_readl(lchip
->base
+ LOCOMO_ASD
);
709 locomo_writel(r
, lchip
->base
+ LOCOMO_ASD
);
711 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip
->base
+ LOCOMO_HSD
);
712 r
= locomo_readl(lchip
->base
+ LOCOMO_HSD
);
714 locomo_writel(r
, lchip
->base
+ LOCOMO_HSD
);
716 locomo_writel(128 / 8, lchip
->base
+ LOCOMO_HSC
);
719 locomo_writel(0x80, lchip
->base
+ LOCOMO_TADC
);
722 r
= locomo_readl(lchip
->base
+ LOCOMO_TADC
);
724 locomo_writel(r
, lchip
->base
+ LOCOMO_TADC
);
728 r
= locomo_readl(lchip
->base
+ LOCOMO_DAC
);
729 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
730 locomo_writel(r
, lchip
->base
+ LOCOMO_DAC
);
732 r
= locomo_readl(lchip
->base
+ LOCOMO_VER
);
733 printk(KERN_INFO
"LoCoMo Chip: %lu%lu\n", (r
>> 8), (r
& 0xff));
736 * The interrupt controller must be initialised before any
737 * other device to ensure that the interrupts are available.
739 if (lchip
->irq
!= NO_IRQ
)
740 locomo_setup_irq(lchip
);
742 for (i
= 0; i
< ARRAY_SIZE(locomo_devices
); i
++)
743 locomo_init_one_child(lchip
, &locomo_devices
[i
]);
751 static int locomo_remove_child(struct device
*dev
, void *data
)
753 device_unregister(dev
);
757 static void __locomo_remove(struct locomo
*lchip
)
759 device_for_each_child(lchip
->dev
, NULL
, locomo_remove_child
);
761 if (lchip
->irq
!= NO_IRQ
) {
762 set_irq_chained_handler(lchip
->irq
, NULL
);
763 set_irq_data(lchip
->irq
, NULL
);
766 iounmap(lchip
->base
);
770 static int locomo_probe(struct platform_device
*dev
)
772 struct resource
*mem
;
775 mem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
778 irq
= platform_get_irq(dev
, 0);
782 return __locomo_probe(&dev
->dev
, mem
, irq
);
785 static int locomo_remove(struct platform_device
*dev
)
787 struct locomo
*lchip
= platform_get_drvdata(dev
);
790 __locomo_remove(lchip
);
791 platform_set_drvdata(dev
, NULL
);
798 * Not sure if this should be on the system bus or not yet.
799 * We really want some way to register a system device at
800 * the per-machine level, and then have this driver pick
801 * up the registered devices.
803 static struct platform_driver locomo_device_driver
= {
804 .probe
= locomo_probe
,
805 .remove
= locomo_remove
,
807 .suspend
= locomo_suspend
,
808 .resume
= locomo_resume
,
816 * Get the parent device driver (us) structure
817 * from a child function device
819 static inline struct locomo
*locomo_chip_driver(struct locomo_dev
*ldev
)
821 return (struct locomo
*)dev_get_drvdata(ldev
->dev
.parent
);
824 void locomo_gpio_set_dir(struct device
*dev
, unsigned int bits
, unsigned int dir
)
826 struct locomo
*lchip
= dev_get_drvdata(dev
);
833 spin_lock_irqsave(&lchip
->lock
, flags
);
835 r
= locomo_readl(lchip
->base
+ LOCOMO_GPD
);
837 locomo_writel(r
, lchip
->base
+ LOCOMO_GPD
);
839 r
= locomo_readl(lchip
->base
+ LOCOMO_GPE
);
844 locomo_writel(r
, lchip
->base
+ LOCOMO_GPE
);
846 spin_unlock_irqrestore(&lchip
->lock
, flags
);
849 int locomo_gpio_read_level(struct device
*dev
, unsigned int bits
)
851 struct locomo
*lchip
= dev_get_drvdata(dev
);
858 spin_lock_irqsave(&lchip
->lock
, flags
);
859 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPL
);
860 spin_unlock_irqrestore(&lchip
->lock
, flags
);
866 int locomo_gpio_read_output(struct device
*dev
, unsigned int bits
)
868 struct locomo
*lchip
= dev_get_drvdata(dev
);
875 spin_lock_irqsave(&lchip
->lock
, flags
);
876 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
877 spin_unlock_irqrestore(&lchip
->lock
, flags
);
883 void locomo_gpio_write(struct device
*dev
, unsigned int bits
, unsigned int set
)
885 struct locomo
*lchip
= dev_get_drvdata(dev
);
892 spin_lock_irqsave(&lchip
->lock
, flags
);
894 r
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
899 locomo_writel(r
, lchip
->base
+ LOCOMO_GPO
);
901 spin_unlock_irqrestore(&lchip
->lock
, flags
);
904 static void locomo_m62332_sendbit(void *mapbase
, int bit
)
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_DATA_HOLD_TIME
); /* 300 nsec */
913 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
914 r
&= ~(LOCOMO_DAC_SCLOEB
);
915 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
916 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
917 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
920 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
921 r
|= LOCOMO_DAC_SDAOEB
;
922 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
923 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
925 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
926 r
&= ~(LOCOMO_DAC_SDAOEB
);
927 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
928 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
931 udelay(DAC_DATA_SETUP_TIME
); /* 250 nsec */
932 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
933 r
|= LOCOMO_DAC_SCLOEB
;
934 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
935 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
936 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
939 void locomo_m62332_senddata(struct locomo_dev
*ldev
, unsigned int dac_data
, int channel
)
941 struct locomo
*lchip
= locomo_chip_driver(ldev
);
945 void *mapbase
= lchip
->base
;
948 spin_lock_irqsave(&lchip
->lock
, flags
);
951 udelay(DAC_BUS_FREE_TIME
); /* 5.0 usec */
952 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
953 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
954 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
955 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
956 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
957 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
958 r
&= ~(LOCOMO_DAC_SDAOEB
);
959 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
960 udelay(DAC_START_HOLD_TIME
); /* 5.0 usec */
961 udelay(DAC_DATA_HOLD_TIME
); /* 300 nsec */
963 /* Send slave address and W bit (LSB is W bit) */
964 data
= (M62332_SLAVE_ADDR
<< 1) | M62332_W_BIT
;
965 for (i
= 1; i
<= 8; i
++) {
966 locomo_m62332_sendbit(mapbase
, data
>> (8 - i
));
970 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
971 r
&= ~(LOCOMO_DAC_SCLOEB
);
972 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
973 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
974 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
975 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
976 r
&= ~(LOCOMO_DAC_SDAOEB
);
977 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
978 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
979 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
980 r
|= LOCOMO_DAC_SCLOEB
;
981 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
982 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
983 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
984 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
985 printk(KERN_WARNING
"locomo: m62332_senddata Error 1\n");
989 /* Send Sub address (LSB is channel select) */
990 /* channel = 0 : ch1 select */
991 /* = 1 : ch2 select */
992 data
= M62332_SUB_ADDR
+ channel
;
993 for (i
= 1; i
<= 8; i
++) {
994 locomo_m62332_sendbit(mapbase
, data
>> (8 - i
));
998 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
999 r
&= ~(LOCOMO_DAC_SCLOEB
);
1000 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1001 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1002 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
1003 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1004 r
&= ~(LOCOMO_DAC_SDAOEB
);
1005 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1006 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1007 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1008 r
|= LOCOMO_DAC_SCLOEB
;
1009 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1010 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1011 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
1012 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
1013 printk(KERN_WARNING
"locomo: m62332_senddata Error 2\n");
1018 for (i
= 1; i
<= 8; i
++) {
1019 locomo_m62332_sendbit(mapbase
, dac_data
>> (8 - i
));
1023 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1024 r
&= ~(LOCOMO_DAC_SCLOEB
);
1025 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1026 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1027 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
1028 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1029 r
&= ~(LOCOMO_DAC_SDAOEB
);
1030 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1031 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1032 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1033 r
|= LOCOMO_DAC_SCLOEB
;
1034 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1035 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1036 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
1037 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
1038 printk(KERN_WARNING
"locomo: m62332_senddata Error 3\n");
1043 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1044 r
&= ~(LOCOMO_DAC_SCLOEB
);
1045 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1046 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
1047 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
1048 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1049 r
|= LOCOMO_DAC_SCLOEB
;
1050 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1051 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1052 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4 usec */
1053 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1054 r
|= LOCOMO_DAC_SDAOEB
;
1055 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1056 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
1057 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4 usec */
1059 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
1060 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
1061 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
1062 udelay(DAC_LOW_SETUP_TIME
); /* 1000 nsec */
1063 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
1065 spin_unlock_irqrestore(&lchip
->lock
, flags
);
1069 * Frontlight control
1072 static struct locomo
*locomo_chip_driver(struct locomo_dev
*ldev
);
1074 void locomo_frontlight_set(struct locomo_dev
*dev
, int duty
, int vr
, int bpwf
)
1076 unsigned long flags
;
1077 struct locomo
*lchip
= locomo_chip_driver(dev
);
1080 locomo_gpio_write(dev
->dev
.parent
, LOCOMO_GPIO_FL_VR
, 1);
1082 locomo_gpio_write(dev
->dev
.parent
, LOCOMO_GPIO_FL_VR
, 0);
1084 spin_lock_irqsave(&lchip
->lock
, flags
);
1085 locomo_writel(bpwf
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
1087 locomo_writel(duty
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALD
);
1088 locomo_writel(bpwf
| LOCOMO_ALC_EN
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
1089 spin_unlock_irqrestore(&lchip
->lock
, flags
);
1093 * LoCoMo "Register Access Bus."
1095 * We model this as a regular bus type, and hang devices directly
1098 static int locomo_match(struct device
*_dev
, struct device_driver
*_drv
)
1100 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
1101 struct locomo_driver
*drv
= LOCOMO_DRV(_drv
);
1103 return dev
->devid
== drv
->devid
;
1106 static int locomo_bus_suspend(struct device
*dev
, pm_message_t state
)
1108 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1109 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1112 if (drv
&& drv
->suspend
)
1113 ret
= drv
->suspend(ldev
, state
);
1117 static int locomo_bus_resume(struct device
*dev
)
1119 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1120 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1123 if (drv
&& drv
->resume
)
1124 ret
= drv
->resume(ldev
);
1128 static int locomo_bus_probe(struct device
*dev
)
1130 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1131 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1135 ret
= drv
->probe(ldev
);
1139 static int locomo_bus_remove(struct device
*dev
)
1141 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
1142 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
1146 ret
= drv
->remove(ldev
);
1150 struct bus_type locomo_bus_type
= {
1151 .name
= "locomo-bus",
1152 .match
= locomo_match
,
1153 .probe
= locomo_bus_probe
,
1154 .remove
= locomo_bus_remove
,
1155 .suspend
= locomo_bus_suspend
,
1156 .resume
= locomo_bus_resume
,
1159 int locomo_driver_register(struct locomo_driver
*driver
)
1161 driver
->drv
.bus
= &locomo_bus_type
;
1162 return driver_register(&driver
->drv
);
1165 void locomo_driver_unregister(struct locomo_driver
*driver
)
1167 driver_unregister(&driver
->drv
);
1170 static int __init
locomo_init(void)
1172 int ret
= bus_register(&locomo_bus_type
);
1174 platform_driver_register(&locomo_device_driver
);
1178 static void __exit
locomo_exit(void)
1180 platform_driver_unregister(&locomo_device_driver
);
1181 bus_unregister(&locomo_bus_type
);
1184 module_init(locomo_init
);
1185 module_exit(locomo_exit
);
1187 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1188 MODULE_LICENSE("GPL");
1189 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1191 EXPORT_SYMBOL(locomo_driver_register
);
1192 EXPORT_SYMBOL(locomo_driver_unregister
);
1193 EXPORT_SYMBOL(locomo_gpio_set_dir
);
1194 EXPORT_SYMBOL(locomo_gpio_read_level
);
1195 EXPORT_SYMBOL(locomo_gpio_read_output
);
1196 EXPORT_SYMBOL(locomo_gpio_write
);
1197 EXPORT_SYMBOL(locomo_m62332_senddata
);