Linux 5.7.7
[linux/fpc-iii.git] / arch / arm / common / locomo.c
blob62f241b09fe33008581d98d148363b9b870b6810
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/common/locomo.c
5 * Sharp LoCoMo support
7 * This file contains all generic LoCoMo support.
9 * All initialization functions provided here are intended to be called
10 * from machine specific code with proper arguments when required.
12 * Based on sa1111.c
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/delay.h>
19 #include <linux/errno.h>
20 #include <linux/ioport.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
23 #include <linux/spinlock.h>
24 #include <linux/io.h>
26 #include <mach/hardware.h>
27 #include <asm/irq.h>
28 #include <asm/mach/irq.h>
30 #include <asm/hardware/locomo.h>
32 /* LoCoMo Interrupts */
33 #define IRQ_LOCOMO_KEY (0)
34 #define IRQ_LOCOMO_GPIO (1)
35 #define IRQ_LOCOMO_LT (2)
36 #define IRQ_LOCOMO_SPI (3)
38 /* M62332 output channel selection */
39 #define M62332_EVR_CH 1 /* M62332 volume channel number */
40 /* 0 : CH.1 , 1 : CH. 2 */
41 /* DAC send data */
42 #define M62332_SLAVE_ADDR 0x4e /* Slave address */
43 #define M62332_W_BIT 0x00 /* W bit (0 only) */
44 #define M62332_SUB_ADDR 0x00 /* Sub address */
45 #define M62332_A_BIT 0x00 /* A bit (0 only) */
47 /* DAC setup and hold times (expressed in us) */
48 #define DAC_BUS_FREE_TIME 5 /* 4.7 us */
49 #define DAC_START_SETUP_TIME 5 /* 4.7 us */
50 #define DAC_STOP_SETUP_TIME 4 /* 4.0 us */
51 #define DAC_START_HOLD_TIME 5 /* 4.7 us */
52 #define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */
53 #define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */
54 #define DAC_DATA_SETUP_TIME 1 /* 250 ns */
55 #define DAC_DATA_HOLD_TIME 1 /* 300 ns */
56 #define DAC_LOW_SETUP_TIME 1 /* 300 ns */
57 #define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */
59 /* the following is the overall data for the locomo chip */
60 struct locomo {
61 struct device *dev;
62 unsigned long phys;
63 unsigned int irq;
64 int irq_base;
65 spinlock_t lock;
66 void __iomem *base;
67 #ifdef CONFIG_PM
68 void *saved_state;
69 #endif
72 struct locomo_dev_info {
73 unsigned long offset;
74 unsigned long length;
75 unsigned int devid;
76 unsigned int irq[1];
77 const char * name;
80 /* All the locomo devices. If offset is non-zero, the mapbase for the
81 * locomo_dev will be set to the chip base plus offset. If offset is
82 * zero, then the mapbase for the locomo_dev will be set to zero. An
83 * offset of zero means the device only uses GPIOs or other helper
84 * functions inside this file */
85 static struct locomo_dev_info locomo_devices[] = {
87 .devid = LOCOMO_DEVID_KEYBOARD,
88 .irq = { IRQ_LOCOMO_KEY },
89 .name = "locomo-keyboard",
90 .offset = LOCOMO_KEYBOARD,
91 .length = 16,
94 .devid = LOCOMO_DEVID_FRONTLIGHT,
95 .irq = {},
96 .name = "locomo-frontlight",
97 .offset = LOCOMO_FRONTLIGHT,
98 .length = 8,
102 .devid = LOCOMO_DEVID_BACKLIGHT,
103 .irq = {},
104 .name = "locomo-backlight",
105 .offset = LOCOMO_BACKLIGHT,
106 .length = 8,
109 .devid = LOCOMO_DEVID_AUDIO,
110 .irq = {},
111 .name = "locomo-audio",
112 .offset = LOCOMO_AUDIO,
113 .length = 4,
116 .devid = LOCOMO_DEVID_LED,
117 .irq = {},
118 .name = "locomo-led",
119 .offset = LOCOMO_LED,
120 .length = 8,
123 .devid = LOCOMO_DEVID_UART,
124 .irq = {},
125 .name = "locomo-uart",
126 .offset = 0,
127 .length = 0,
130 .devid = LOCOMO_DEVID_SPI,
131 .irq = {},
132 .name = "locomo-spi",
133 .offset = LOCOMO_SPI,
134 .length = 0x30,
138 static void locomo_handler(struct irq_desc *desc)
140 struct locomo *lchip = irq_desc_get_handler_data(desc);
141 int req, i;
143 /* Acknowledge the parent IRQ */
144 desc->irq_data.chip->irq_ack(&desc->irq_data);
146 /* check why this interrupt was generated */
147 req = locomo_readl(lchip->base + LOCOMO_ICR) & 0x0f00;
149 if (req) {
150 unsigned int irq;
152 /* generate the next interrupt(s) */
153 irq = lchip->irq_base;
154 for (i = 0; i <= 3; i++, irq++) {
155 if (req & (0x0100 << i)) {
156 generic_handle_irq(irq);
163 static void locomo_ack_irq(struct irq_data *d)
167 static void locomo_mask_irq(struct irq_data *d)
169 struct locomo *lchip = irq_data_get_irq_chip_data(d);
170 unsigned int r;
171 r = locomo_readl(lchip->base + LOCOMO_ICR);
172 r &= ~(0x0010 << (d->irq - lchip->irq_base));
173 locomo_writel(r, lchip->base + LOCOMO_ICR);
176 static void locomo_unmask_irq(struct irq_data *d)
178 struct locomo *lchip = irq_data_get_irq_chip_data(d);
179 unsigned int r;
180 r = locomo_readl(lchip->base + LOCOMO_ICR);
181 r |= (0x0010 << (d->irq - lchip->irq_base));
182 locomo_writel(r, lchip->base + LOCOMO_ICR);
185 static struct irq_chip locomo_chip = {
186 .name = "LOCOMO",
187 .irq_ack = locomo_ack_irq,
188 .irq_mask = locomo_mask_irq,
189 .irq_unmask = locomo_unmask_irq,
192 static void locomo_setup_irq(struct locomo *lchip)
194 int irq = lchip->irq_base;
197 * Install handler for IRQ_LOCOMO_HW.
199 irq_set_irq_type(lchip->irq, IRQ_TYPE_EDGE_FALLING);
200 irq_set_chained_handler_and_data(lchip->irq, locomo_handler, lchip);
202 /* Install handlers for IRQ_LOCOMO_* */
203 for ( ; irq <= lchip->irq_base + 3; irq++) {
204 irq_set_chip_and_handler(irq, &locomo_chip, handle_level_irq);
205 irq_set_chip_data(irq, lchip);
206 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
211 static void locomo_dev_release(struct device *_dev)
213 struct locomo_dev *dev = LOCOMO_DEV(_dev);
215 kfree(dev);
218 static int
219 locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
221 struct locomo_dev *dev;
222 int ret;
224 dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL);
225 if (!dev) {
226 ret = -ENOMEM;
227 goto out;
231 * If the parent device has a DMA mask associated with it,
232 * propagate it down to the children.
234 if (lchip->dev->dma_mask) {
235 dev->dma_mask = *lchip->dev->dma_mask;
236 dev->dev.dma_mask = &dev->dma_mask;
239 dev_set_name(&dev->dev, "%s", info->name);
240 dev->devid = info->devid;
241 dev->dev.parent = lchip->dev;
242 dev->dev.bus = &locomo_bus_type;
243 dev->dev.release = locomo_dev_release;
244 dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
246 if (info->offset)
247 dev->mapbase = lchip->base + info->offset;
248 else
249 dev->mapbase = 0;
250 dev->length = info->length;
252 dev->irq[0] = (lchip->irq_base == NO_IRQ) ?
253 NO_IRQ : lchip->irq_base + info->irq[0];
255 ret = device_register(&dev->dev);
256 if (ret) {
257 out:
258 kfree(dev);
260 return ret;
263 #ifdef CONFIG_PM
265 struct locomo_save_data {
266 u16 LCM_GPO;
267 u16 LCM_SPICT;
268 u16 LCM_GPE;
269 u16 LCM_ASD;
270 u16 LCM_SPIMD;
273 static int locomo_suspend(struct platform_device *dev, pm_message_t state)
275 struct locomo *lchip = platform_get_drvdata(dev);
276 struct locomo_save_data *save;
277 unsigned long flags;
279 save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
280 if (!save)
281 return -ENOMEM;
283 lchip->saved_state = save;
285 spin_lock_irqsave(&lchip->lock, flags);
287 save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */
288 locomo_writel(0x00, lchip->base + LOCOMO_GPO);
289 save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPICT); /* SPI */
290 locomo_writel(0x40, lchip->base + LOCOMO_SPI + LOCOMO_SPICT);
291 save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */
292 locomo_writel(0x00, lchip->base + LOCOMO_GPE);
293 save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */
294 locomo_writel(0x00, lchip->base + LOCOMO_ASD);
295 save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPIMD); /* SPI */
296 locomo_writel(0x3C14, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD);
298 locomo_writel(0x00, lchip->base + LOCOMO_PAIF);
299 locomo_writel(0x00, lchip->base + LOCOMO_DAC);
300 locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC);
302 if ((locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88))
303 locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */
304 else
305 /* 18MHz already enabled, so no wait */
306 locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */
308 locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/
309 locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */
310 locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */
312 spin_unlock_irqrestore(&lchip->lock, flags);
314 return 0;
317 static int locomo_resume(struct platform_device *dev)
319 struct locomo *lchip = platform_get_drvdata(dev);
320 struct locomo_save_data *save;
321 unsigned long r;
322 unsigned long flags;
324 save = lchip->saved_state;
325 if (!save)
326 return 0;
328 spin_lock_irqsave(&lchip->lock, flags);
330 locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
331 locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPI + LOCOMO_SPICT);
332 locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
333 locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
334 locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD);
336 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
337 locomo_writel(0x90, lchip->base + LOCOMO_TADC);
339 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
340 r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
341 r &= 0xFEFF;
342 locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
343 locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
345 spin_unlock_irqrestore(&lchip->lock, flags);
347 lchip->saved_state = NULL;
348 kfree(save);
350 return 0;
352 #endif
356 * locomo_probe - probe for a single LoCoMo chip.
357 * @phys_addr: physical address of device.
359 * Probe for a LoCoMo chip. This must be called
360 * before any other locomo-specific code.
362 * Returns:
363 * %-ENODEV device not found.
364 * %-EBUSY physical address already marked in-use.
365 * %0 successful.
367 static int
368 __locomo_probe(struct device *me, struct resource *mem, int irq)
370 struct locomo_platform_data *pdata = me->platform_data;
371 struct locomo *lchip;
372 unsigned long r;
373 int i, ret = -ENODEV;
375 lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL);
376 if (!lchip)
377 return -ENOMEM;
379 spin_lock_init(&lchip->lock);
381 lchip->dev = me;
382 dev_set_drvdata(lchip->dev, lchip);
384 lchip->phys = mem->start;
385 lchip->irq = irq;
386 lchip->irq_base = (pdata) ? pdata->irq_base : NO_IRQ;
389 * Map the whole region. This also maps the
390 * registers for our children.
392 lchip->base = ioremap(mem->start, PAGE_SIZE);
393 if (!lchip->base) {
394 ret = -ENOMEM;
395 goto out;
398 /* locomo initialize */
399 locomo_writel(0, lchip->base + LOCOMO_ICR);
400 /* KEYBOARD */
401 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
403 /* GPIO */
404 locomo_writel(0, lchip->base + LOCOMO_GPO);
405 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
406 , lchip->base + LOCOMO_GPE);
407 locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
408 , lchip->base + LOCOMO_GPD);
409 locomo_writel(0, lchip->base + LOCOMO_GIE);
411 /* Frontlight */
412 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
413 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
415 /* Longtime timer */
416 locomo_writel(0, lchip->base + LOCOMO_LTINT);
417 /* SPI */
418 locomo_writel(0, lchip->base + LOCOMO_SPI + LOCOMO_SPIIE);
420 locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
421 r = locomo_readl(lchip->base + LOCOMO_ASD);
422 r |= 0x8000;
423 locomo_writel(r, lchip->base + LOCOMO_ASD);
425 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
426 r = locomo_readl(lchip->base + LOCOMO_HSD);
427 r |= 0x8000;
428 locomo_writel(r, lchip->base + LOCOMO_HSD);
430 locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
432 /* XON */
433 locomo_writel(0x80, lchip->base + LOCOMO_TADC);
434 udelay(1000);
435 /* CLK9MEN */
436 r = locomo_readl(lchip->base + LOCOMO_TADC);
437 r |= 0x10;
438 locomo_writel(r, lchip->base + LOCOMO_TADC);
439 udelay(100);
441 /* init DAC */
442 r = locomo_readl(lchip->base + LOCOMO_DAC);
443 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
444 locomo_writel(r, lchip->base + LOCOMO_DAC);
446 r = locomo_readl(lchip->base + LOCOMO_VER);
447 printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
450 * The interrupt controller must be initialised before any
451 * other device to ensure that the interrupts are available.
453 if (lchip->irq != NO_IRQ && lchip->irq_base != NO_IRQ)
454 locomo_setup_irq(lchip);
456 for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
457 locomo_init_one_child(lchip, &locomo_devices[i]);
458 return 0;
460 out:
461 kfree(lchip);
462 return ret;
465 static int locomo_remove_child(struct device *dev, void *data)
467 device_unregister(dev);
468 return 0;
471 static void __locomo_remove(struct locomo *lchip)
473 device_for_each_child(lchip->dev, NULL, locomo_remove_child);
475 if (lchip->irq != NO_IRQ) {
476 irq_set_chained_handler_and_data(lchip->irq, NULL, NULL);
479 iounmap(lchip->base);
480 kfree(lchip);
483 static int locomo_probe(struct platform_device *dev)
485 struct resource *mem;
486 int irq;
488 mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
489 if (!mem)
490 return -EINVAL;
491 irq = platform_get_irq(dev, 0);
492 if (irq < 0)
493 return -ENXIO;
495 return __locomo_probe(&dev->dev, mem, irq);
498 static int locomo_remove(struct platform_device *dev)
500 struct locomo *lchip = platform_get_drvdata(dev);
502 if (lchip) {
503 __locomo_remove(lchip);
504 platform_set_drvdata(dev, NULL);
507 return 0;
511 * Not sure if this should be on the system bus or not yet.
512 * We really want some way to register a system device at
513 * the per-machine level, and then have this driver pick
514 * up the registered devices.
516 static struct platform_driver locomo_device_driver = {
517 .probe = locomo_probe,
518 .remove = locomo_remove,
519 #ifdef CONFIG_PM
520 .suspend = locomo_suspend,
521 .resume = locomo_resume,
522 #endif
523 .driver = {
524 .name = "locomo",
529 * Get the parent device driver (us) structure
530 * from a child function device
532 static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
534 return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
537 void locomo_gpio_set_dir(struct device *dev, unsigned int bits, unsigned int dir)
539 struct locomo *lchip = dev_get_drvdata(dev);
540 unsigned long flags;
541 unsigned int r;
543 if (!lchip)
544 return;
546 spin_lock_irqsave(&lchip->lock, flags);
548 r = locomo_readl(lchip->base + LOCOMO_GPD);
549 if (dir)
550 r |= bits;
551 else
552 r &= ~bits;
553 locomo_writel(r, lchip->base + LOCOMO_GPD);
555 r = locomo_readl(lchip->base + LOCOMO_GPE);
556 if (dir)
557 r |= bits;
558 else
559 r &= ~bits;
560 locomo_writel(r, lchip->base + LOCOMO_GPE);
562 spin_unlock_irqrestore(&lchip->lock, flags);
564 EXPORT_SYMBOL(locomo_gpio_set_dir);
566 int locomo_gpio_read_level(struct device *dev, unsigned int bits)
568 struct locomo *lchip = dev_get_drvdata(dev);
569 unsigned long flags;
570 unsigned int ret;
572 if (!lchip)
573 return -ENODEV;
575 spin_lock_irqsave(&lchip->lock, flags);
576 ret = locomo_readl(lchip->base + LOCOMO_GPL);
577 spin_unlock_irqrestore(&lchip->lock, flags);
579 ret &= bits;
580 return ret;
582 EXPORT_SYMBOL(locomo_gpio_read_level);
584 int locomo_gpio_read_output(struct device *dev, unsigned int bits)
586 struct locomo *lchip = dev_get_drvdata(dev);
587 unsigned long flags;
588 unsigned int ret;
590 if (!lchip)
591 return -ENODEV;
593 spin_lock_irqsave(&lchip->lock, flags);
594 ret = locomo_readl(lchip->base + LOCOMO_GPO);
595 spin_unlock_irqrestore(&lchip->lock, flags);
597 ret &= bits;
598 return ret;
600 EXPORT_SYMBOL(locomo_gpio_read_output);
602 void locomo_gpio_write(struct device *dev, unsigned int bits, unsigned int set)
604 struct locomo *lchip = dev_get_drvdata(dev);
605 unsigned long flags;
606 unsigned int r;
608 if (!lchip)
609 return;
611 spin_lock_irqsave(&lchip->lock, flags);
613 r = locomo_readl(lchip->base + LOCOMO_GPO);
614 if (set)
615 r |= bits;
616 else
617 r &= ~bits;
618 locomo_writel(r, lchip->base + LOCOMO_GPO);
620 spin_unlock_irqrestore(&lchip->lock, flags);
622 EXPORT_SYMBOL(locomo_gpio_write);
624 static void locomo_m62332_sendbit(void *mapbase, int bit)
626 unsigned int r;
628 r = locomo_readl(mapbase + LOCOMO_DAC);
629 r &= ~(LOCOMO_DAC_SCLOEB);
630 locomo_writel(r, mapbase + LOCOMO_DAC);
631 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
632 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
633 r = locomo_readl(mapbase + LOCOMO_DAC);
634 r &= ~(LOCOMO_DAC_SCLOEB);
635 locomo_writel(r, mapbase + LOCOMO_DAC);
636 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
637 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
639 if (bit & 1) {
640 r = locomo_readl(mapbase + LOCOMO_DAC);
641 r |= LOCOMO_DAC_SDAOEB;
642 locomo_writel(r, mapbase + LOCOMO_DAC);
643 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
644 } else {
645 r = locomo_readl(mapbase + LOCOMO_DAC);
646 r &= ~(LOCOMO_DAC_SDAOEB);
647 locomo_writel(r, mapbase + LOCOMO_DAC);
648 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
651 udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */
652 r = locomo_readl(mapbase + LOCOMO_DAC);
653 r |= LOCOMO_DAC_SCLOEB;
654 locomo_writel(r, mapbase + LOCOMO_DAC);
655 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
656 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
659 void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
661 struct locomo *lchip = locomo_chip_driver(ldev);
662 int i;
663 unsigned char data;
664 unsigned int r;
665 void *mapbase = lchip->base;
666 unsigned long flags;
668 spin_lock_irqsave(&lchip->lock, flags);
670 /* Start */
671 udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */
672 r = locomo_readl(mapbase + LOCOMO_DAC);
673 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
674 locomo_writel(r, mapbase + LOCOMO_DAC);
675 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
676 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */
677 r = locomo_readl(mapbase + LOCOMO_DAC);
678 r &= ~(LOCOMO_DAC_SDAOEB);
679 locomo_writel(r, mapbase + LOCOMO_DAC);
680 udelay(DAC_START_HOLD_TIME); /* 5.0 usec */
681 udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */
683 /* Send slave address and W bit (LSB is W bit) */
684 data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT;
685 for (i = 1; i <= 8; i++) {
686 locomo_m62332_sendbit(mapbase, data >> (8 - i));
689 /* Check A bit */
690 r = locomo_readl(mapbase + LOCOMO_DAC);
691 r &= ~(LOCOMO_DAC_SCLOEB);
692 locomo_writel(r, mapbase + LOCOMO_DAC);
693 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
694 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
695 r = locomo_readl(mapbase + LOCOMO_DAC);
696 r &= ~(LOCOMO_DAC_SDAOEB);
697 locomo_writel(r, mapbase + LOCOMO_DAC);
698 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
699 r = locomo_readl(mapbase + LOCOMO_DAC);
700 r |= LOCOMO_DAC_SCLOEB;
701 locomo_writel(r, mapbase + LOCOMO_DAC);
702 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
703 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
704 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
705 printk(KERN_WARNING "locomo: m62332_senddata Error 1\n");
706 goto out;
709 /* Send Sub address (LSB is channel select) */
710 /* channel = 0 : ch1 select */
711 /* = 1 : ch2 select */
712 data = M62332_SUB_ADDR + channel;
713 for (i = 1; i <= 8; i++) {
714 locomo_m62332_sendbit(mapbase, data >> (8 - i));
717 /* Check A bit */
718 r = locomo_readl(mapbase + LOCOMO_DAC);
719 r &= ~(LOCOMO_DAC_SCLOEB);
720 locomo_writel(r, mapbase + LOCOMO_DAC);
721 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
722 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
723 r = locomo_readl(mapbase + LOCOMO_DAC);
724 r &= ~(LOCOMO_DAC_SDAOEB);
725 locomo_writel(r, mapbase + LOCOMO_DAC);
726 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
727 r = locomo_readl(mapbase + LOCOMO_DAC);
728 r |= LOCOMO_DAC_SCLOEB;
729 locomo_writel(r, mapbase + LOCOMO_DAC);
730 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
731 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
732 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
733 printk(KERN_WARNING "locomo: m62332_senddata Error 2\n");
734 goto out;
737 /* Send DAC data */
738 for (i = 1; i <= 8; i++) {
739 locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
742 /* Check A bit */
743 r = locomo_readl(mapbase + LOCOMO_DAC);
744 r &= ~(LOCOMO_DAC_SCLOEB);
745 locomo_writel(r, mapbase + LOCOMO_DAC);
746 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
747 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
748 r = locomo_readl(mapbase + LOCOMO_DAC);
749 r &= ~(LOCOMO_DAC_SDAOEB);
750 locomo_writel(r, mapbase + LOCOMO_DAC);
751 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
752 r = locomo_readl(mapbase + LOCOMO_DAC);
753 r |= LOCOMO_DAC_SCLOEB;
754 locomo_writel(r, mapbase + LOCOMO_DAC);
755 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
756 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */
757 if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */
758 printk(KERN_WARNING "locomo: m62332_senddata Error 3\n");
761 out:
762 /* stop */
763 r = locomo_readl(mapbase + LOCOMO_DAC);
764 r &= ~(LOCOMO_DAC_SCLOEB);
765 locomo_writel(r, mapbase + LOCOMO_DAC);
766 udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */
767 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
768 r = locomo_readl(mapbase + LOCOMO_DAC);
769 r |= LOCOMO_DAC_SCLOEB;
770 locomo_writel(r, mapbase + LOCOMO_DAC);
771 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
772 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
773 r = locomo_readl(mapbase + LOCOMO_DAC);
774 r |= LOCOMO_DAC_SDAOEB;
775 locomo_writel(r, mapbase + LOCOMO_DAC);
776 udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */
777 udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */
779 r = locomo_readl(mapbase + LOCOMO_DAC);
780 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
781 locomo_writel(r, mapbase + LOCOMO_DAC);
782 udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */
783 udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */
785 spin_unlock_irqrestore(&lchip->lock, flags);
787 EXPORT_SYMBOL(locomo_m62332_senddata);
790 * Frontlight control
793 void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf)
795 unsigned long flags;
796 struct locomo *lchip = locomo_chip_driver(dev);
798 if (vr)
799 locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 1);
800 else
801 locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
803 spin_lock_irqsave(&lchip->lock, flags);
804 locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
805 udelay(100);
806 locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
807 locomo_writel(bpwf | LOCOMO_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
808 spin_unlock_irqrestore(&lchip->lock, flags);
810 EXPORT_SYMBOL(locomo_frontlight_set);
813 * LoCoMo "Register Access Bus."
815 * We model this as a regular bus type, and hang devices directly
816 * off this.
818 static int locomo_match(struct device *_dev, struct device_driver *_drv)
820 struct locomo_dev *dev = LOCOMO_DEV(_dev);
821 struct locomo_driver *drv = LOCOMO_DRV(_drv);
823 return dev->devid == drv->devid;
826 static int locomo_bus_probe(struct device *dev)
828 struct locomo_dev *ldev = LOCOMO_DEV(dev);
829 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
830 int ret = -ENODEV;
832 if (drv->probe)
833 ret = drv->probe(ldev);
834 return ret;
837 static int locomo_bus_remove(struct device *dev)
839 struct locomo_dev *ldev = LOCOMO_DEV(dev);
840 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
841 int ret = 0;
843 if (drv->remove)
844 ret = drv->remove(ldev);
845 return ret;
848 struct bus_type locomo_bus_type = {
849 .name = "locomo-bus",
850 .match = locomo_match,
851 .probe = locomo_bus_probe,
852 .remove = locomo_bus_remove,
855 int locomo_driver_register(struct locomo_driver *driver)
857 driver->drv.bus = &locomo_bus_type;
858 return driver_register(&driver->drv);
860 EXPORT_SYMBOL(locomo_driver_register);
862 void locomo_driver_unregister(struct locomo_driver *driver)
864 driver_unregister(&driver->drv);
866 EXPORT_SYMBOL(locomo_driver_unregister);
868 static int __init locomo_init(void)
870 int ret = bus_register(&locomo_bus_type);
871 if (ret == 0)
872 platform_driver_register(&locomo_device_driver);
873 return ret;
876 static void __exit locomo_exit(void)
878 platform_driver_unregister(&locomo_device_driver);
879 bus_unregister(&locomo_bus_type);
882 module_init(locomo_init);
883 module_exit(locomo_exit);
885 MODULE_DESCRIPTION("Sharp LoCoMo core driver");
886 MODULE_LICENSE("GPL");
887 MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");