1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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>
27#include <linux/io.h>
28
29#include <mach/hardware.h>
30#include <asm/irq.h>
31#include <asm/mach/irq.h>
32
33#include <asm/hardware/locomo.h>
34
35
36#define IRQ_LOCOMO_KEY (0)
37#define IRQ_LOCOMO_GPIO (1)
38#define IRQ_LOCOMO_LT (2)
39#define IRQ_LOCOMO_SPI (3)
40
41
42#define M62332_EVR_CH 1
43
44
45#define M62332_SLAVE_ADDR 0x4e
46#define M62332_W_BIT 0x00
47#define M62332_SUB_ADDR 0x00
48#define M62332_A_BIT 0x00
49
50
51#define DAC_BUS_FREE_TIME 5
52#define DAC_START_SETUP_TIME 5
53#define DAC_STOP_SETUP_TIME 4
54#define DAC_START_HOLD_TIME 5
55#define DAC_SCL_LOW_HOLD_TIME 5
56#define DAC_SCL_HIGH_HOLD_TIME 4
57#define DAC_DATA_SETUP_TIME 1
58#define DAC_DATA_HOLD_TIME 1
59#define DAC_LOW_SETUP_TIME 1
60#define DAC_HIGH_SETUP_TIME 1
61
62
63struct locomo {
64 struct device *dev;
65 unsigned long phys;
66 unsigned int irq;
67 int irq_base;
68 spinlock_t lock;
69 void __iomem *base;
70#ifdef CONFIG_PM
71 void *saved_state;
72#endif
73};
74
75struct locomo_dev_info {
76 unsigned long offset;
77 unsigned long length;
78 unsigned int devid;
79 unsigned int irq[1];
80 const char * name;
81};
82
83
84
85
86
87
88static struct locomo_dev_info locomo_devices[] = {
89 {
90 .devid = LOCOMO_DEVID_KEYBOARD,
91 .irq = { IRQ_LOCOMO_KEY },
92 .name = "locomo-keyboard",
93 .offset = LOCOMO_KEYBOARD,
94 .length = 16,
95 },
96 {
97 .devid = LOCOMO_DEVID_FRONTLIGHT,
98 .irq = {},
99 .name = "locomo-frontlight",
100 .offset = LOCOMO_FRONTLIGHT,
101 .length = 8,
102
103 },
104 {
105 .devid = LOCOMO_DEVID_BACKLIGHT,
106 .irq = {},
107 .name = "locomo-backlight",
108 .offset = LOCOMO_BACKLIGHT,
109 .length = 8,
110 },
111 {
112 .devid = LOCOMO_DEVID_AUDIO,
113 .irq = {},
114 .name = "locomo-audio",
115 .offset = LOCOMO_AUDIO,
116 .length = 4,
117 },
118 {
119 .devid = LOCOMO_DEVID_LED,
120 .irq = {},
121 .name = "locomo-led",
122 .offset = LOCOMO_LED,
123 .length = 8,
124 },
125 {
126 .devid = LOCOMO_DEVID_UART,
127 .irq = {},
128 .name = "locomo-uart",
129 .offset = 0,
130 .length = 0,
131 },
132 {
133 .devid = LOCOMO_DEVID_SPI,
134 .irq = {},
135 .name = "locomo-spi",
136 .offset = LOCOMO_SPI,
137 .length = 0x30,
138 },
139};
140
141static void locomo_handler(struct irq_desc *desc)
142{
143 struct locomo *lchip = irq_desc_get_handler_data(desc);
144 int req, i;
145
146
147 desc->irq_data.chip->irq_ack(&desc->irq_data);
148
149
150 req = locomo_readl(lchip->base + LOCOMO_ICR) & 0x0f00;
151
152 if (req) {
153 unsigned int irq;
154
155
156 irq = lchip->irq_base;
157 for (i = 0; i <= 3; i++, irq++) {
158 if (req & (0x0100 << i)) {
159 generic_handle_irq(irq);
160 }
161
162 }
163 }
164}
165
166static void locomo_ack_irq(struct irq_data *d)
167{
168}
169
170static void locomo_mask_irq(struct irq_data *d)
171{
172 struct locomo *lchip = irq_data_get_irq_chip_data(d);
173 unsigned int r;
174 r = locomo_readl(lchip->base + LOCOMO_ICR);
175 r &= ~(0x0010 << (d->irq - lchip->irq_base));
176 locomo_writel(r, lchip->base + LOCOMO_ICR);
177}
178
179static void locomo_unmask_irq(struct irq_data *d)
180{
181 struct locomo *lchip = irq_data_get_irq_chip_data(d);
182 unsigned int r;
183 r = locomo_readl(lchip->base + LOCOMO_ICR);
184 r |= (0x0010 << (d->irq - lchip->irq_base));
185 locomo_writel(r, lchip->base + LOCOMO_ICR);
186}
187
188static struct irq_chip locomo_chip = {
189 .name = "LOCOMO",
190 .irq_ack = locomo_ack_irq,
191 .irq_mask = locomo_mask_irq,
192 .irq_unmask = locomo_unmask_irq,
193};
194
195static void locomo_setup_irq(struct locomo *lchip)
196{
197 int irq = lchip->irq_base;
198
199
200
201
202 irq_set_irq_type(lchip->irq, IRQ_TYPE_EDGE_FALLING);
203 irq_set_chained_handler_and_data(lchip->irq, locomo_handler, lchip);
204
205
206 for ( ; irq <= lchip->irq_base + 3; irq++) {
207 irq_set_chip_and_handler(irq, &locomo_chip, handle_level_irq);
208 irq_set_chip_data(irq, lchip);
209 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
210 }
211}
212
213
214static void locomo_dev_release(struct device *_dev)
215{
216 struct locomo_dev *dev = LOCOMO_DEV(_dev);
217
218 kfree(dev);
219}
220
221static int
222locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
223{
224 struct locomo_dev *dev;
225 int ret;
226
227 dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL);
228 if (!dev) {
229 ret = -ENOMEM;
230 goto out;
231 }
232
233
234
235
236
237 if (lchip->dev->dma_mask) {
238 dev->dma_mask = *lchip->dev->dma_mask;
239 dev->dev.dma_mask = &dev->dma_mask;
240 }
241
242 dev_set_name(&dev->dev, "%s", info->name);
243 dev->devid = info->devid;
244 dev->dev.parent = lchip->dev;
245 dev->dev.bus = &locomo_bus_type;
246 dev->dev.release = locomo_dev_release;
247 dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
248
249 if (info->offset)
250 dev->mapbase = lchip->base + info->offset;
251 else
252 dev->mapbase = 0;
253 dev->length = info->length;
254
255 dev->irq[0] = (lchip->irq_base == NO_IRQ) ?
256 NO_IRQ : lchip->irq_base + info->irq[0];
257
258 ret = device_register(&dev->dev);
259 if (ret) {
260 out:
261 kfree(dev);
262 }
263 return ret;
264}
265
266#ifdef CONFIG_PM
267
268struct locomo_save_data {
269 u16 LCM_GPO;
270 u16 LCM_SPICT;
271 u16 LCM_GPE;
272 u16 LCM_ASD;
273 u16 LCM_SPIMD;
274};
275
276static int locomo_suspend(struct platform_device *dev, pm_message_t state)
277{
278 struct locomo *lchip = platform_get_drvdata(dev);
279 struct locomo_save_data *save;
280 unsigned long flags;
281
282 save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
283 if (!save)
284 return -ENOMEM;
285
286 lchip->saved_state = save;
287
288 spin_lock_irqsave(&lchip->lock, flags);
289
290 save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO);
291 locomo_writel(0x00, lchip->base + LOCOMO_GPO);
292 save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPICT);
293 locomo_writel(0x40, lchip->base + LOCOMO_SPI + LOCOMO_SPICT);
294 save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE);
295 locomo_writel(0x00, lchip->base + LOCOMO_GPE);
296 save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD);
297 locomo_writel(0x00, lchip->base + LOCOMO_ASD);
298 save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPIMD);
299 locomo_writel(0x3C14, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD);
300
301 locomo_writel(0x00, lchip->base + LOCOMO_PAIF);
302 locomo_writel(0x00, lchip->base + LOCOMO_DAC);
303 locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC);
304
305 if ((locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88))
306 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
307 else
308
309 locomo_writel(0xc1, lchip->base + LOCOMO_C32K);
310
311 locomo_writel(0x00, lchip->base + LOCOMO_TADC);
312 locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC);
313 locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
314
315 spin_unlock_irqrestore(&lchip->lock, flags);
316
317 return 0;
318}
319
320static int locomo_resume(struct platform_device *dev)
321{
322 struct locomo *lchip = platform_get_drvdata(dev);
323 struct locomo_save_data *save;
324 unsigned long r;
325 unsigned long flags;
326
327 save = lchip->saved_state;
328 if (!save)
329 return 0;
330
331 spin_lock_irqsave(&lchip->lock, flags);
332
333 locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
334 locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPI + LOCOMO_SPICT);
335 locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
336 locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
337 locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD);
338
339 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
340 locomo_writel(0x90, lchip->base + LOCOMO_TADC);
341
342 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
343 r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
344 r &= 0xFEFF;
345 locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
346 locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
347
348 spin_unlock_irqrestore(&lchip->lock, flags);
349
350 lchip->saved_state = NULL;
351 kfree(save);
352
353 return 0;
354}
355#endif
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370static int
371__locomo_probe(struct device *me, struct resource *mem, int irq)
372{
373 struct locomo_platform_data *pdata = me->platform_data;
374 struct locomo *lchip;
375 unsigned long r;
376 int i, ret = -ENODEV;
377
378 lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL);
379 if (!lchip)
380 return -ENOMEM;
381
382 spin_lock_init(&lchip->lock);
383
384 lchip->dev = me;
385 dev_set_drvdata(lchip->dev, lchip);
386
387 lchip->phys = mem->start;
388 lchip->irq = irq;
389 lchip->irq_base = (pdata) ? pdata->irq_base : NO_IRQ;
390
391
392
393
394
395 lchip->base = ioremap(mem->start, PAGE_SIZE);
396 if (!lchip->base) {
397 ret = -ENOMEM;
398 goto out;
399 }
400
401
402 locomo_writel(0, lchip->base + LOCOMO_ICR);
403
404 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
405
406
407 locomo_writel(0, lchip->base + LOCOMO_GPO);
408 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
409 , lchip->base + LOCOMO_GPE);
410 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
411 , lchip->base + LOCOMO_GPD);
412 locomo_writel(0, lchip->base + LOCOMO_GIE);
413
414
415 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
416 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
417
418
419 locomo_writel(0, lchip->base + LOCOMO_LTINT);
420
421 locomo_writel(0, lchip->base + LOCOMO_SPI + LOCOMO_SPIIE);
422
423 locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
424 r = locomo_readl(lchip->base + LOCOMO_ASD);
425 r |= 0x8000;
426 locomo_writel(r, lchip->base + LOCOMO_ASD);
427
428 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
429 r = locomo_readl(lchip->base + LOCOMO_HSD);
430 r |= 0x8000;
431 locomo_writel(r, lchip->base + LOCOMO_HSD);
432
433 locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
434
435
436 locomo_writel(0x80, lchip->base + LOCOMO_TADC);
437 udelay(1000);
438
439 r = locomo_readl(lchip->base + LOCOMO_TADC);
440 r |= 0x10;
441 locomo_writel(r, lchip->base + LOCOMO_TADC);
442 udelay(100);
443
444
445 r = locomo_readl(lchip->base + LOCOMO_DAC);
446 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
447 locomo_writel(r, lchip->base + LOCOMO_DAC);
448
449 r = locomo_readl(lchip->base + LOCOMO_VER);
450 printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
451
452
453
454
455
456 if (lchip->irq != NO_IRQ && lchip->irq_base != NO_IRQ)
457 locomo_setup_irq(lchip);
458
459 for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
460 locomo_init_one_child(lchip, &locomo_devices[i]);
461 return 0;
462
463 out:
464 kfree(lchip);
465 return ret;
466}
467
468static int locomo_remove_child(struct device *dev, void *data)
469{
470 device_unregister(dev);
471 return 0;
472}
473
474static void __locomo_remove(struct locomo *lchip)
475{
476 device_for_each_child(lchip->dev, NULL, locomo_remove_child);
477
478 if (lchip->irq != NO_IRQ) {
479 irq_set_chained_handler_and_data(lchip->irq, NULL, NULL);
480 }
481
482 iounmap(lchip->base);
483 kfree(lchip);
484}
485
486static int locomo_probe(struct platform_device *dev)
487{
488 struct resource *mem;
489 int irq;
490
491 mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
492 if (!mem)
493 return -EINVAL;
494 irq = platform_get_irq(dev, 0);
495 if (irq < 0)
496 return -ENXIO;
497
498 return __locomo_probe(&dev->dev, mem, irq);
499}
500
501static int locomo_remove(struct platform_device *dev)
502{
503 struct locomo *lchip = platform_get_drvdata(dev);
504
505 if (lchip) {
506 __locomo_remove(lchip);
507 platform_set_drvdata(dev, NULL);
508 }
509
510 return 0;
511}
512
513
514
515
516
517
518
519static struct platform_driver locomo_device_driver = {
520 .probe = locomo_probe,
521 .remove = locomo_remove,
522#ifdef CONFIG_PM
523 .suspend = locomo_suspend,
524 .resume = locomo_resume,
525#endif
526 .driver = {
527 .name = "locomo",
528 },
529};
530
531
532
533
534
535static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
536{
537 return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
538}
539
540void locomo_gpio_set_dir(struct device *dev, unsigned int bits, unsigned int dir)
541{
542 struct locomo *lchip = dev_get_drvdata(dev);
543 unsigned long flags;
544 unsigned int r;
545
546 if (!lchip)
547 return;
548
549 spin_lock_irqsave(&lchip->lock, flags);
550
551 r = locomo_readl(lchip->base + LOCOMO_GPD);
552 if (dir)
553 r |= bits;
554 else
555 r &= ~bits;
556 locomo_writel(r, lchip->base + LOCOMO_GPD);
557
558 r = locomo_readl(lchip->base + LOCOMO_GPE);
559 if (dir)
560 r |= bits;
561 else
562 r &= ~bits;
563 locomo_writel(r, lchip->base + LOCOMO_GPE);
564
565 spin_unlock_irqrestore(&lchip->lock, flags);
566}
567EXPORT_SYMBOL(locomo_gpio_set_dir);
568
569int locomo_gpio_read_level(struct device *dev, unsigned int bits)
570{
571 struct locomo *lchip = dev_get_drvdata(dev);
572 unsigned long flags;
573 unsigned int ret;
574
575 if (!lchip)
576 return -ENODEV;
577
578 spin_lock_irqsave(&lchip->lock, flags);
579 ret = locomo_readl(lchip->base + LOCOMO_GPL);
580 spin_unlock_irqrestore(&lchip->lock, flags);
581
582 ret &= bits;
583 return ret;
584}
585EXPORT_SYMBOL(locomo_gpio_read_level);
586
587int locomo_gpio_read_output(struct device *dev, unsigned int bits)
588{
589 struct locomo *lchip = dev_get_drvdata(dev);
590 unsigned long flags;
591 unsigned int ret;
592
593 if (!lchip)
594 return -ENODEV;
595
596 spin_lock_irqsave(&lchip->lock, flags);
597 ret = locomo_readl(lchip->base + LOCOMO_GPO);
598 spin_unlock_irqrestore(&lchip->lock, flags);
599
600 ret &= bits;
601 return ret;
602}
603EXPORT_SYMBOL(locomo_gpio_read_output);
604
605void locomo_gpio_write(struct device *dev, unsigned int bits, unsigned int set)
606{
607 struct locomo *lchip = dev_get_drvdata(dev);
608 unsigned long flags;
609 unsigned int r;
610
611 if (!lchip)
612 return;
613
614 spin_lock_irqsave(&lchip->lock, flags);
615
616 r = locomo_readl(lchip->base + LOCOMO_GPO);
617 if (set)
618 r |= bits;
619 else
620 r &= ~bits;
621 locomo_writel(r, lchip->base + LOCOMO_GPO);
622
623 spin_unlock_irqrestore(&lchip->lock, flags);
624}
625EXPORT_SYMBOL(locomo_gpio_write);
626
627static void locomo_m62332_sendbit(void *mapbase, int bit)
628{
629 unsigned int r;
630
631 r = locomo_readl(mapbase + LOCOMO_DAC);
632 r &= ~(LOCOMO_DAC_SCLOEB);
633 locomo_writel(r, mapbase + LOCOMO_DAC);
634 udelay(DAC_LOW_SETUP_TIME);
635 udelay(DAC_DATA_HOLD_TIME);
636 r = locomo_readl(mapbase + LOCOMO_DAC);
637 r &= ~(LOCOMO_DAC_SCLOEB);
638 locomo_writel(r, mapbase + LOCOMO_DAC);
639 udelay(DAC_LOW_SETUP_TIME);
640 udelay(DAC_SCL_LOW_HOLD_TIME);
641
642 if (bit & 1) {
643 r = locomo_readl(mapbase + LOCOMO_DAC);
644 r |= LOCOMO_DAC_SDAOEB;
645 locomo_writel(r, mapbase + LOCOMO_DAC);
646 udelay(DAC_HIGH_SETUP_TIME);
647 } else {
648 r = locomo_readl(mapbase + LOCOMO_DAC);
649 r &= ~(LOCOMO_DAC_SDAOEB);
650 locomo_writel(r, mapbase + LOCOMO_DAC);
651 udelay(DAC_LOW_SETUP_TIME);
652 }
653
654 udelay(DAC_DATA_SETUP_TIME);
655 r = locomo_readl(mapbase + LOCOMO_DAC);
656 r |= LOCOMO_DAC_SCLOEB;
657 locomo_writel(r, mapbase + LOCOMO_DAC);
658 udelay(DAC_HIGH_SETUP_TIME);
659 udelay(DAC_SCL_HIGH_HOLD_TIME);
660}
661
662void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
663{
664 struct locomo *lchip = locomo_chip_driver(ldev);
665 int i;
666 unsigned char data;
667 unsigned int r;
668 void *mapbase = lchip->base;
669 unsigned long flags;
670
671 spin_lock_irqsave(&lchip->lock, flags);
672
673
674 udelay(DAC_BUS_FREE_TIME);
675 r = locomo_readl(mapbase + LOCOMO_DAC);
676 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
677 locomo_writel(r, mapbase + LOCOMO_DAC);
678 udelay(DAC_HIGH_SETUP_TIME);
679 udelay(DAC_SCL_HIGH_HOLD_TIME);
680 r = locomo_readl(mapbase + LOCOMO_DAC);
681 r &= ~(LOCOMO_DAC_SDAOEB);
682 locomo_writel(r, mapbase + LOCOMO_DAC);
683 udelay(DAC_START_HOLD_TIME);
684 udelay(DAC_DATA_HOLD_TIME);
685
686
687 data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
688 for (i = 1; i <= 8; i++) {
689 locomo_m62332_sendbit(mapbase, data >> (8 - i));
690 }
691
692
693 r = locomo_readl(mapbase + LOCOMO_DAC);
694 r &= ~(LOCOMO_DAC_SCLOEB);
695 locomo_writel(r, mapbase + LOCOMO_DAC);
696 udelay(DAC_LOW_SETUP_TIME);
697 udelay(DAC_SCL_LOW_HOLD_TIME);
698 r = locomo_readl(mapbase + LOCOMO_DAC);
699 r &= ~(LOCOMO_DAC_SDAOEB);
700 locomo_writel(r, mapbase + LOCOMO_DAC);
701 udelay(DAC_LOW_SETUP_TIME);
702 r = locomo_readl(mapbase + LOCOMO_DAC);
703 r |= LOCOMO_DAC_SCLOEB;
704 locomo_writel(r, mapbase + LOCOMO_DAC);
705 udelay(DAC_HIGH_SETUP_TIME);
706 udelay(DAC_SCL_HIGH_HOLD_TIME);
707 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) {
708 printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
709 goto out;
710 }
711
712
713
714
715 data = M62332_SUB_ADDR + channel;
716 for (i = 1; i <= 8; i++) {
717 locomo_m62332_sendbit(mapbase, data >> (8 - i));
718 }
719
720
721 r = locomo_readl(mapbase + LOCOMO_DAC);
722 r &= ~(LOCOMO_DAC_SCLOEB);
723 locomo_writel(r, mapbase + LOCOMO_DAC);
724 udelay(DAC_LOW_SETUP_TIME);
725 udelay(DAC_SCL_LOW_HOLD_TIME);
726 r = locomo_readl(mapbase + LOCOMO_DAC);
727 r &= ~(LOCOMO_DAC_SDAOEB);
728 locomo_writel(r, mapbase + LOCOMO_DAC);
729 udelay(DAC_LOW_SETUP_TIME);
730 r = locomo_readl(mapbase + LOCOMO_DAC);
731 r |= LOCOMO_DAC_SCLOEB;
732 locomo_writel(r, mapbase + LOCOMO_DAC);
733 udelay(DAC_HIGH_SETUP_TIME);
734 udelay(DAC_SCL_HIGH_HOLD_TIME);
735 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) {
736 printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
737 goto out;
738 }
739
740
741 for (i = 1; i <= 8; i++) {
742 locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
743 }
744
745
746 r = locomo_readl(mapbase + LOCOMO_DAC);
747 r &= ~(LOCOMO_DAC_SCLOEB);
748 locomo_writel(r, mapbase + LOCOMO_DAC);
749 udelay(DAC_LOW_SETUP_TIME);
750 udelay(DAC_SCL_LOW_HOLD_TIME);
751 r = locomo_readl(mapbase + LOCOMO_DAC);
752 r &= ~(LOCOMO_DAC_SDAOEB);
753 locomo_writel(r, mapbase + LOCOMO_DAC);
754 udelay(DAC_LOW_SETUP_TIME);
755 r = locomo_readl(mapbase + LOCOMO_DAC);
756 r |= LOCOMO_DAC_SCLOEB;
757 locomo_writel(r, mapbase + LOCOMO_DAC);
758 udelay(DAC_HIGH_SETUP_TIME);
759 udelay(DAC_SCL_HIGH_HOLD_TIME);
760 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) {
761 printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
762 }
763
764out:
765
766 r = locomo_readl(mapbase + LOCOMO_DAC);
767 r &= ~(LOCOMO_DAC_SCLOEB);
768 locomo_writel(r, mapbase + LOCOMO_DAC);
769 udelay(DAC_LOW_SETUP_TIME);
770 udelay(DAC_SCL_LOW_HOLD_TIME);
771 r = locomo_readl(mapbase + LOCOMO_DAC);
772 r |= LOCOMO_DAC_SCLOEB;
773 locomo_writel(r, mapbase + LOCOMO_DAC);
774 udelay(DAC_HIGH_SETUP_TIME);
775 udelay(DAC_SCL_HIGH_HOLD_TIME);
776 r = locomo_readl(mapbase + LOCOMO_DAC);
777 r |= LOCOMO_DAC_SDAOEB;
778 locomo_writel(r, mapbase + LOCOMO_DAC);
779 udelay(DAC_HIGH_SETUP_TIME);
780 udelay(DAC_SCL_HIGH_HOLD_TIME);
781
782 r = locomo_readl(mapbase + LOCOMO_DAC);
783 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
784 locomo_writel(r, mapbase + LOCOMO_DAC);
785 udelay(DAC_LOW_SETUP_TIME);
786 udelay(DAC_SCL_LOW_HOLD_TIME);
787
788 spin_unlock_irqrestore(&lchip->lock, flags);
789}
790EXPORT_SYMBOL(locomo_m62332_senddata);
791
792
793
794
795
796void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf)
797{
798 unsigned long flags;
799 struct locomo *lchip = locomo_chip_driver(dev);
800
801 if (vr)
802 locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 1);
803 else
804 locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
805
806 spin_lock_irqsave(&lchip->lock, flags);
807 locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
808 udelay(100);
809 locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
810 locomo_writel(bpwf | LOCOMO_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
811 spin_unlock_irqrestore(&lchip->lock, flags);
812}
813EXPORT_SYMBOL(locomo_frontlight_set);
814
815
816
817
818
819
820
821static int locomo_match(struct device *_dev, struct device_driver *_drv)
822{
823 struct locomo_dev *dev = LOCOMO_DEV(_dev);
824 struct locomo_driver *drv = LOCOMO_DRV(_drv);
825
826 return dev->devid == drv->devid;
827}
828
829static int locomo_bus_probe(struct device *dev)
830{
831 struct locomo_dev *ldev = LOCOMO_DEV(dev);
832 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
833 int ret = -ENODEV;
834
835 if (drv->probe)
836 ret = drv->probe(ldev);
837 return ret;
838}
839
840static int locomo_bus_remove(struct device *dev)
841{
842 struct locomo_dev *ldev = LOCOMO_DEV(dev);
843 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
844 int ret = 0;
845
846 if (drv->remove)
847 ret = drv->remove(ldev);
848 return ret;
849}
850
851struct bus_type locomo_bus_type = {
852 .name = "locomo-bus",
853 .match = locomo_match,
854 .probe = locomo_bus_probe,
855 .remove = locomo_bus_remove,
856};
857
858int locomo_driver_register(struct locomo_driver *driver)
859{
860 driver->drv.bus = &locomo_bus_type;
861 return driver_register(&driver->drv);
862}
863EXPORT_SYMBOL(locomo_driver_register);
864
865void locomo_driver_unregister(struct locomo_driver *driver)
866{
867 driver_unregister(&driver->drv);
868}
869EXPORT_SYMBOL(locomo_driver_unregister);
870
871static int __init locomo_init(void)
872{
873 int ret = bus_register(&locomo_bus_type);
874 if (ret == 0)
875 platform_driver_register(&locomo_device_driver);
876 return ret;
877}
878
879static void __exit locomo_exit(void)
880{
881 platform_driver_unregister(&locomo_device_driver);
882 bus_unregister(&locomo_bus_type);
883}
884
885module_init(locomo_init);
886module_exit(locomo_exit);
887
888MODULE_DESCRIPTION("Sharp LoCoMo core driver");
889MODULE_LICENSE("GPL");
890MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
891