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>
29 #include <mach/hardware.h>
31 #include <asm/mach/irq.h>
33 #include <asm/hardware/locomo.h>
35 /* LoCoMo Interrupts */
36 #define IRQ_LOCOMO_KEY (0)
37 #define IRQ_LOCOMO_GPIO (1)
38 #define IRQ_LOCOMO_LT (2)
39 #define IRQ_LOCOMO_SPI (3)
41 /* M62332 output channel selection */
42 #define M62332_EVR_CH 1 /* M62332 volume channel number */
43 /* 0 : CH.1 , 1 : CH. 2 */
45 #define M62332_SLAVE_ADDR 0x4e /* Slave address */
46 #define M62332_W_BIT 0x00 /* W bit (0 only) */
47 #define M62332_SUB_ADDR 0x00 /* Sub address */
48 #define M62332_A_BIT 0x00 /* A bit (0 only) */
50 /* DAC setup and hold times (expressed in us) */
51 #define DAC_BUS_FREE_TIME 5 /* 4.7 us */
52 #define DAC_START_SETUP_TIME 5 /* 4.7 us */
53 #define DAC_STOP_SETUP_TIME 4 /* 4.0 us */
54 #define DAC_START_HOLD_TIME 5 /* 4.7 us */
55 #define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */
56 #define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */
57 #define DAC_DATA_SETUP_TIME 1 /* 250 ns */
58 #define DAC_DATA_HOLD_TIME 1 /* 300 ns */
59 #define DAC_LOW_SETUP_TIME 1 /* 300 ns */
60 #define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */
62 /* the following is the overall data for the locomo chip */
75 struct locomo_dev_info
{
83 /* All the locomo devices. If offset is non-zero, the mapbase for the
84 * locomo_dev will be set to the chip base plus offset. If offset is
85 * zero, then the mapbase for the locomo_dev will be set to zero. An
86 * offset of zero means the device only uses GPIOs or other helper
87 * functions inside this file */
88 static struct locomo_dev_info locomo_devices
[] = {
90 .devid
= LOCOMO_DEVID_KEYBOARD
,
91 .irq
= { IRQ_LOCOMO_KEY
},
92 .name
= "locomo-keyboard",
93 .offset
= LOCOMO_KEYBOARD
,
97 .devid
= LOCOMO_DEVID_FRONTLIGHT
,
99 .name
= "locomo-frontlight",
100 .offset
= LOCOMO_FRONTLIGHT
,
105 .devid
= LOCOMO_DEVID_BACKLIGHT
,
107 .name
= "locomo-backlight",
108 .offset
= LOCOMO_BACKLIGHT
,
112 .devid
= LOCOMO_DEVID_AUDIO
,
114 .name
= "locomo-audio",
115 .offset
= LOCOMO_AUDIO
,
119 .devid
= LOCOMO_DEVID_LED
,
121 .name
= "locomo-led",
122 .offset
= LOCOMO_LED
,
126 .devid
= LOCOMO_DEVID_UART
,
128 .name
= "locomo-uart",
133 .devid
= LOCOMO_DEVID_SPI
,
135 .name
= "locomo-spi",
136 .offset
= LOCOMO_SPI
,
141 static void locomo_handler(struct irq_desc
*desc
)
143 struct locomo
*lchip
= irq_desc_get_chip_data(desc
);
146 /* Acknowledge the parent IRQ */
147 desc
->irq_data
.chip
->irq_ack(&desc
->irq_data
);
149 /* check why this interrupt was generated */
150 req
= locomo_readl(lchip
->base
+ LOCOMO_ICR
) & 0x0f00;
155 /* generate the next interrupt(s) */
156 irq
= lchip
->irq_base
;
157 for (i
= 0; i
<= 3; i
++, irq
++) {
158 if (req
& (0x0100 << i
)) {
159 generic_handle_irq(irq
);
166 static void locomo_ack_irq(struct irq_data
*d
)
170 static void locomo_mask_irq(struct irq_data
*d
)
172 struct locomo
*lchip
= irq_data_get_irq_chip_data(d
);
174 r
= locomo_readl(lchip
->base
+ LOCOMO_ICR
);
175 r
&= ~(0x0010 << (d
->irq
- lchip
->irq_base
));
176 locomo_writel(r
, lchip
->base
+ LOCOMO_ICR
);
179 static void locomo_unmask_irq(struct irq_data
*d
)
181 struct locomo
*lchip
= irq_data_get_irq_chip_data(d
);
183 r
= locomo_readl(lchip
->base
+ LOCOMO_ICR
);
184 r
|= (0x0010 << (d
->irq
- lchip
->irq_base
));
185 locomo_writel(r
, lchip
->base
+ LOCOMO_ICR
);
188 static struct irq_chip locomo_chip
= {
190 .irq_ack
= locomo_ack_irq
,
191 .irq_mask
= locomo_mask_irq
,
192 .irq_unmask
= locomo_unmask_irq
,
195 static void locomo_setup_irq(struct locomo
*lchip
)
197 int irq
= lchip
->irq_base
;
200 * Install handler for IRQ_LOCOMO_HW.
202 irq_set_irq_type(lchip
->irq
, IRQ_TYPE_EDGE_FALLING
);
203 irq_set_chip_data(lchip
->irq
, lchip
);
204 irq_set_chained_handler(lchip
->irq
, locomo_handler
);
206 /* Install handlers for IRQ_LOCOMO_* */
207 for ( ; irq
<= lchip
->irq_base
+ 3; irq
++) {
208 irq_set_chip_and_handler(irq
, &locomo_chip
, handle_level_irq
);
209 irq_set_chip_data(irq
, lchip
);
210 irq_clear_status_flags(irq
, IRQ_NOREQUEST
| IRQ_NOPROBE
);
215 static void locomo_dev_release(struct device
*_dev
)
217 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
223 locomo_init_one_child(struct locomo
*lchip
, struct locomo_dev_info
*info
)
225 struct locomo_dev
*dev
;
228 dev
= kzalloc(sizeof(struct locomo_dev
), GFP_KERNEL
);
235 * If the parent device has a DMA mask associated with it,
236 * propagate it down to the children.
238 if (lchip
->dev
->dma_mask
) {
239 dev
->dma_mask
= *lchip
->dev
->dma_mask
;
240 dev
->dev
.dma_mask
= &dev
->dma_mask
;
243 dev_set_name(&dev
->dev
, "%s", info
->name
);
244 dev
->devid
= info
->devid
;
245 dev
->dev
.parent
= lchip
->dev
;
246 dev
->dev
.bus
= &locomo_bus_type
;
247 dev
->dev
.release
= locomo_dev_release
;
248 dev
->dev
.coherent_dma_mask
= lchip
->dev
->coherent_dma_mask
;
251 dev
->mapbase
= lchip
->base
+ info
->offset
;
254 dev
->length
= info
->length
;
256 dev
->irq
[0] = (lchip
->irq_base
== NO_IRQ
) ?
257 NO_IRQ
: lchip
->irq_base
+ info
->irq
[0];
259 ret
= device_register(&dev
->dev
);
269 struct locomo_save_data
{
277 static int locomo_suspend(struct platform_device
*dev
, pm_message_t state
)
279 struct locomo
*lchip
= platform_get_drvdata(dev
);
280 struct locomo_save_data
*save
;
283 save
= kmalloc(sizeof(struct locomo_save_data
), GFP_KERNEL
);
287 lchip
->saved_state
= save
;
289 spin_lock_irqsave(&lchip
->lock
, flags
);
291 save
->LCM_GPO
= locomo_readl(lchip
->base
+ LOCOMO_GPO
); /* GPIO */
292 locomo_writel(0x00, lchip
->base
+ LOCOMO_GPO
);
293 save
->LCM_SPICT
= locomo_readl(lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPICT
); /* SPI */
294 locomo_writel(0x40, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPICT
);
295 save
->LCM_GPE
= locomo_readl(lchip
->base
+ LOCOMO_GPE
); /* GPIO */
296 locomo_writel(0x00, lchip
->base
+ LOCOMO_GPE
);
297 save
->LCM_ASD
= locomo_readl(lchip
->base
+ LOCOMO_ASD
); /* ADSTART */
298 locomo_writel(0x00, lchip
->base
+ LOCOMO_ASD
);
299 save
->LCM_SPIMD
= locomo_readl(lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPIMD
); /* SPI */
300 locomo_writel(0x3C14, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPIMD
);
302 locomo_writel(0x00, lchip
->base
+ LOCOMO_PAIF
);
303 locomo_writel(0x00, lchip
->base
+ LOCOMO_DAC
);
304 locomo_writel(0x00, lchip
->base
+ LOCOMO_BACKLIGHT
+ LOCOMO_TC
);
306 if ((locomo_readl(lchip
->base
+ LOCOMO_LED
+ LOCOMO_LPT0
) & 0x88) && (locomo_readl(lchip
->base
+ LOCOMO_LED
+ LOCOMO_LPT1
) & 0x88))
307 locomo_writel(0x00, lchip
->base
+ LOCOMO_C32K
); /* CLK32 off */
309 /* 18MHz already enabled, so no wait */
310 locomo_writel(0xc1, lchip
->base
+ LOCOMO_C32K
); /* CLK32 on */
312 locomo_writel(0x00, lchip
->base
+ LOCOMO_TADC
); /* 18MHz clock off*/
313 locomo_writel(0x00, lchip
->base
+ LOCOMO_AUDIO
+ LOCOMO_ACC
); /* 22MHz/24MHz clock off */
314 locomo_writel(0x00, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
); /* FL */
316 spin_unlock_irqrestore(&lchip
->lock
, flags
);
321 static int locomo_resume(struct platform_device
*dev
)
323 struct locomo
*lchip
= platform_get_drvdata(dev
);
324 struct locomo_save_data
*save
;
328 save
= lchip
->saved_state
;
332 spin_lock_irqsave(&lchip
->lock
, flags
);
334 locomo_writel(save
->LCM_GPO
, lchip
->base
+ LOCOMO_GPO
);
335 locomo_writel(save
->LCM_SPICT
, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPICT
);
336 locomo_writel(save
->LCM_GPE
, lchip
->base
+ LOCOMO_GPE
);
337 locomo_writel(save
->LCM_ASD
, lchip
->base
+ LOCOMO_ASD
);
338 locomo_writel(save
->LCM_SPIMD
, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPIMD
);
340 locomo_writel(0x00, lchip
->base
+ LOCOMO_C32K
);
341 locomo_writel(0x90, lchip
->base
+ LOCOMO_TADC
);
343 locomo_writel(0, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KSC
);
344 r
= locomo_readl(lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
346 locomo_writel(r
, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
347 locomo_writel(0x1, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KCMD
);
349 spin_unlock_irqrestore(&lchip
->lock
, flags
);
351 lchip
->saved_state
= NULL
;
360 * locomo_probe - probe for a single LoCoMo chip.
361 * @phys_addr: physical address of device.
363 * Probe for a LoCoMo chip. This must be called
364 * before any other locomo-specific code.
367 * %-ENODEV device not found.
368 * %-EBUSY physical address already marked in-use.
372 __locomo_probe(struct device
*me
, struct resource
*mem
, int irq
)
374 struct locomo_platform_data
*pdata
= me
->platform_data
;
375 struct locomo
*lchip
;
377 int i
, ret
= -ENODEV
;
379 lchip
= kzalloc(sizeof(struct locomo
), GFP_KERNEL
);
383 spin_lock_init(&lchip
->lock
);
386 dev_set_drvdata(lchip
->dev
, lchip
);
388 lchip
->phys
= mem
->start
;
390 lchip
->irq_base
= (pdata
) ? pdata
->irq_base
: NO_IRQ
;
393 * Map the whole region. This also maps the
394 * registers for our children.
396 lchip
->base
= ioremap(mem
->start
, PAGE_SIZE
);
402 /* locomo initialize */
403 locomo_writel(0, lchip
->base
+ LOCOMO_ICR
);
405 locomo_writel(0, lchip
->base
+ LOCOMO_KEYBOARD
+ LOCOMO_KIC
);
408 locomo_writel(0, lchip
->base
+ LOCOMO_GPO
);
409 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
410 , lchip
->base
+ LOCOMO_GPE
);
411 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
412 , lchip
->base
+ LOCOMO_GPD
);
413 locomo_writel(0, lchip
->base
+ LOCOMO_GIE
);
416 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
417 locomo_writel(0, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALD
);
420 locomo_writel(0, lchip
->base
+ LOCOMO_LTINT
);
422 locomo_writel(0, lchip
->base
+ LOCOMO_SPI
+ LOCOMO_SPIIE
);
424 locomo_writel(6 + 8 + 320 + 30 - 10, lchip
->base
+ LOCOMO_ASD
);
425 r
= locomo_readl(lchip
->base
+ LOCOMO_ASD
);
427 locomo_writel(r
, lchip
->base
+ LOCOMO_ASD
);
429 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip
->base
+ LOCOMO_HSD
);
430 r
= locomo_readl(lchip
->base
+ LOCOMO_HSD
);
432 locomo_writel(r
, lchip
->base
+ LOCOMO_HSD
);
434 locomo_writel(128 / 8, lchip
->base
+ LOCOMO_HSC
);
437 locomo_writel(0x80, lchip
->base
+ LOCOMO_TADC
);
440 r
= locomo_readl(lchip
->base
+ LOCOMO_TADC
);
442 locomo_writel(r
, lchip
->base
+ LOCOMO_TADC
);
446 r
= locomo_readl(lchip
->base
+ LOCOMO_DAC
);
447 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
448 locomo_writel(r
, lchip
->base
+ LOCOMO_DAC
);
450 r
= locomo_readl(lchip
->base
+ LOCOMO_VER
);
451 printk(KERN_INFO
"LoCoMo Chip: %lu%lu\n", (r
>> 8), (r
& 0xff));
454 * The interrupt controller must be initialised before any
455 * other device to ensure that the interrupts are available.
457 if (lchip
->irq
!= NO_IRQ
&& lchip
->irq_base
!= NO_IRQ
)
458 locomo_setup_irq(lchip
);
460 for (i
= 0; i
< ARRAY_SIZE(locomo_devices
); i
++)
461 locomo_init_one_child(lchip
, &locomo_devices
[i
]);
469 static int locomo_remove_child(struct device
*dev
, void *data
)
471 device_unregister(dev
);
475 static void __locomo_remove(struct locomo
*lchip
)
477 device_for_each_child(lchip
->dev
, NULL
, locomo_remove_child
);
479 if (lchip
->irq
!= NO_IRQ
) {
480 irq_set_chained_handler_and_data(lchip
->irq
, NULL
, NULL
);
483 iounmap(lchip
->base
);
487 static int locomo_probe(struct platform_device
*dev
)
489 struct resource
*mem
;
492 mem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
495 irq
= platform_get_irq(dev
, 0);
499 return __locomo_probe(&dev
->dev
, mem
, irq
);
502 static int locomo_remove(struct platform_device
*dev
)
504 struct locomo
*lchip
= platform_get_drvdata(dev
);
507 __locomo_remove(lchip
);
508 platform_set_drvdata(dev
, NULL
);
515 * Not sure if this should be on the system bus or not yet.
516 * We really want some way to register a system device at
517 * the per-machine level, and then have this driver pick
518 * up the registered devices.
520 static struct platform_driver locomo_device_driver
= {
521 .probe
= locomo_probe
,
522 .remove
= locomo_remove
,
524 .suspend
= locomo_suspend
,
525 .resume
= locomo_resume
,
533 * Get the parent device driver (us) structure
534 * from a child function device
536 static inline struct locomo
*locomo_chip_driver(struct locomo_dev
*ldev
)
538 return (struct locomo
*)dev_get_drvdata(ldev
->dev
.parent
);
541 void locomo_gpio_set_dir(struct device
*dev
, unsigned int bits
, unsigned int dir
)
543 struct locomo
*lchip
= dev_get_drvdata(dev
);
550 spin_lock_irqsave(&lchip
->lock
, flags
);
552 r
= locomo_readl(lchip
->base
+ LOCOMO_GPD
);
557 locomo_writel(r
, lchip
->base
+ LOCOMO_GPD
);
559 r
= locomo_readl(lchip
->base
+ LOCOMO_GPE
);
564 locomo_writel(r
, lchip
->base
+ LOCOMO_GPE
);
566 spin_unlock_irqrestore(&lchip
->lock
, flags
);
568 EXPORT_SYMBOL(locomo_gpio_set_dir
);
570 int locomo_gpio_read_level(struct device
*dev
, unsigned int bits
)
572 struct locomo
*lchip
= dev_get_drvdata(dev
);
579 spin_lock_irqsave(&lchip
->lock
, flags
);
580 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPL
);
581 spin_unlock_irqrestore(&lchip
->lock
, flags
);
586 EXPORT_SYMBOL(locomo_gpio_read_level
);
588 int locomo_gpio_read_output(struct device
*dev
, unsigned int bits
)
590 struct locomo
*lchip
= dev_get_drvdata(dev
);
597 spin_lock_irqsave(&lchip
->lock
, flags
);
598 ret
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
599 spin_unlock_irqrestore(&lchip
->lock
, flags
);
604 EXPORT_SYMBOL(locomo_gpio_read_output
);
606 void locomo_gpio_write(struct device
*dev
, unsigned int bits
, unsigned int set
)
608 struct locomo
*lchip
= dev_get_drvdata(dev
);
615 spin_lock_irqsave(&lchip
->lock
, flags
);
617 r
= locomo_readl(lchip
->base
+ LOCOMO_GPO
);
622 locomo_writel(r
, lchip
->base
+ LOCOMO_GPO
);
624 spin_unlock_irqrestore(&lchip
->lock
, flags
);
626 EXPORT_SYMBOL(locomo_gpio_write
);
628 static void locomo_m62332_sendbit(void *mapbase
, int bit
)
632 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
633 r
&= ~(LOCOMO_DAC_SCLOEB
);
634 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
635 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
636 udelay(DAC_DATA_HOLD_TIME
); /* 300 nsec */
637 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
638 r
&= ~(LOCOMO_DAC_SCLOEB
);
639 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
640 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
641 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
644 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
645 r
|= LOCOMO_DAC_SDAOEB
;
646 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
647 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
649 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
650 r
&= ~(LOCOMO_DAC_SDAOEB
);
651 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
652 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
655 udelay(DAC_DATA_SETUP_TIME
); /* 250 nsec */
656 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
657 r
|= LOCOMO_DAC_SCLOEB
;
658 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
659 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
660 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
663 void locomo_m62332_senddata(struct locomo_dev
*ldev
, unsigned int dac_data
, int channel
)
665 struct locomo
*lchip
= locomo_chip_driver(ldev
);
669 void *mapbase
= lchip
->base
;
672 spin_lock_irqsave(&lchip
->lock
, flags
);
675 udelay(DAC_BUS_FREE_TIME
); /* 5.0 usec */
676 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
677 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
678 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
679 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
680 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.0 usec */
681 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
682 r
&= ~(LOCOMO_DAC_SDAOEB
);
683 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
684 udelay(DAC_START_HOLD_TIME
); /* 5.0 usec */
685 udelay(DAC_DATA_HOLD_TIME
); /* 300 nsec */
687 /* Send slave address and W bit (LSB is W bit) */
688 data
= (M62332_SLAVE_ADDR
<< 1) | M62332_W_BIT
;
689 for (i
= 1; i
<= 8; i
++) {
690 locomo_m62332_sendbit(mapbase
, data
>> (8 - i
));
694 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
695 r
&= ~(LOCOMO_DAC_SCLOEB
);
696 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
697 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
698 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
699 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
700 r
&= ~(LOCOMO_DAC_SDAOEB
);
701 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
702 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
703 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
704 r
|= LOCOMO_DAC_SCLOEB
;
705 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
706 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
707 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
708 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
709 printk(KERN_WARNING
"locomo: m62332_senddata Error 1\n");
713 /* Send Sub address (LSB is channel select) */
714 /* channel = 0 : ch1 select */
715 /* = 1 : ch2 select */
716 data
= M62332_SUB_ADDR
+ channel
;
717 for (i
= 1; i
<= 8; i
++) {
718 locomo_m62332_sendbit(mapbase
, data
>> (8 - i
));
722 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
723 r
&= ~(LOCOMO_DAC_SCLOEB
);
724 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
725 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
726 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
727 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
728 r
&= ~(LOCOMO_DAC_SDAOEB
);
729 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
730 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
731 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
732 r
|= LOCOMO_DAC_SCLOEB
;
733 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
734 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
735 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
736 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
737 printk(KERN_WARNING
"locomo: m62332_senddata Error 2\n");
742 for (i
= 1; i
<= 8; i
++) {
743 locomo_m62332_sendbit(mapbase
, dac_data
>> (8 - i
));
747 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
748 r
&= ~(LOCOMO_DAC_SCLOEB
);
749 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
750 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
751 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
752 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
753 r
&= ~(LOCOMO_DAC_SDAOEB
);
754 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
755 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
756 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
757 r
|= LOCOMO_DAC_SCLOEB
;
758 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
759 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
760 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4.7 usec */
761 if (locomo_readl(mapbase
+ LOCOMO_DAC
) & LOCOMO_DAC_SDAOEB
) { /* High is error */
762 printk(KERN_WARNING
"locomo: m62332_senddata Error 3\n");
767 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
768 r
&= ~(LOCOMO_DAC_SCLOEB
);
769 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
770 udelay(DAC_LOW_SETUP_TIME
); /* 300 nsec */
771 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
772 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
773 r
|= LOCOMO_DAC_SCLOEB
;
774 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
775 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
776 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4 usec */
777 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
778 r
|= LOCOMO_DAC_SDAOEB
;
779 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
780 udelay(DAC_HIGH_SETUP_TIME
); /* 1000 nsec */
781 udelay(DAC_SCL_HIGH_HOLD_TIME
); /* 4 usec */
783 r
= locomo_readl(mapbase
+ LOCOMO_DAC
);
784 r
|= LOCOMO_DAC_SCLOEB
| LOCOMO_DAC_SDAOEB
;
785 locomo_writel(r
, mapbase
+ LOCOMO_DAC
);
786 udelay(DAC_LOW_SETUP_TIME
); /* 1000 nsec */
787 udelay(DAC_SCL_LOW_HOLD_TIME
); /* 4.7 usec */
789 spin_unlock_irqrestore(&lchip
->lock
, flags
);
791 EXPORT_SYMBOL(locomo_m62332_senddata
);
797 void locomo_frontlight_set(struct locomo_dev
*dev
, int duty
, int vr
, int bpwf
)
800 struct locomo
*lchip
= locomo_chip_driver(dev
);
803 locomo_gpio_write(dev
->dev
.parent
, LOCOMO_GPIO_FL_VR
, 1);
805 locomo_gpio_write(dev
->dev
.parent
, LOCOMO_GPIO_FL_VR
, 0);
807 spin_lock_irqsave(&lchip
->lock
, flags
);
808 locomo_writel(bpwf
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
810 locomo_writel(duty
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALD
);
811 locomo_writel(bpwf
| LOCOMO_ALC_EN
, lchip
->base
+ LOCOMO_FRONTLIGHT
+ LOCOMO_ALS
);
812 spin_unlock_irqrestore(&lchip
->lock
, flags
);
814 EXPORT_SYMBOL(locomo_frontlight_set
);
817 * LoCoMo "Register Access Bus."
819 * We model this as a regular bus type, and hang devices directly
822 static int locomo_match(struct device
*_dev
, struct device_driver
*_drv
)
824 struct locomo_dev
*dev
= LOCOMO_DEV(_dev
);
825 struct locomo_driver
*drv
= LOCOMO_DRV(_drv
);
827 return dev
->devid
== drv
->devid
;
830 static int locomo_bus_suspend(struct device
*dev
, pm_message_t state
)
832 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
833 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
836 if (drv
&& drv
->suspend
)
837 ret
= drv
->suspend(ldev
, state
);
841 static int locomo_bus_resume(struct device
*dev
)
843 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
844 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
847 if (drv
&& drv
->resume
)
848 ret
= drv
->resume(ldev
);
852 static int locomo_bus_probe(struct device
*dev
)
854 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
855 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
859 ret
= drv
->probe(ldev
);
863 static int locomo_bus_remove(struct device
*dev
)
865 struct locomo_dev
*ldev
= LOCOMO_DEV(dev
);
866 struct locomo_driver
*drv
= LOCOMO_DRV(dev
->driver
);
870 ret
= drv
->remove(ldev
);
874 struct bus_type locomo_bus_type
= {
875 .name
= "locomo-bus",
876 .match
= locomo_match
,
877 .probe
= locomo_bus_probe
,
878 .remove
= locomo_bus_remove
,
879 .suspend
= locomo_bus_suspend
,
880 .resume
= locomo_bus_resume
,
883 int locomo_driver_register(struct locomo_driver
*driver
)
885 driver
->drv
.bus
= &locomo_bus_type
;
886 return driver_register(&driver
->drv
);
888 EXPORT_SYMBOL(locomo_driver_register
);
890 void locomo_driver_unregister(struct locomo_driver
*driver
)
892 driver_unregister(&driver
->drv
);
894 EXPORT_SYMBOL(locomo_driver_unregister
);
896 static int __init
locomo_init(void)
898 int ret
= bus_register(&locomo_bus_type
);
900 platform_driver_register(&locomo_device_driver
);
904 static void __exit
locomo_exit(void)
906 platform_driver_unregister(&locomo_device_driver
);
907 bus_unregister(&locomo_bus_type
);
910 module_init(locomo_init
);
911 module_exit(locomo_exit
);
913 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
914 MODULE_LICENSE("GPL");
915 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");