blob: 787e0d027f04741d5ba6ccc9858253fa45f194b2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/common/locomo.c
3 *
4 * Sharp LoCoMo support
5 *
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.
9 *
10 * This file contains all generic LoCoMo support.
11 *
12 * All initialization functions provided here are intended to be called
13 * from machine specific code with proper arguments when required.
14 *
15 * Based on sa1111.c
16 */
17
18#include <linux/config.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/delay.h>
23#include <linux/errno.h>
24#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010025#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/slab.h>
27#include <linux/spinlock.h>
28
29#include <asm/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/io.h>
31#include <asm/irq.h>
32#include <asm/mach/irq.h>
33
34#include <asm/hardware/locomo.h>
35
36/* M62332 output channel selection */
37#define M62332_EVR_CH 1 /* M62332 volume channel number */
38 /* 0 : CH.1 , 1 : CH. 2 */
39/* DAC send data */
40#define M62332_SLAVE_ADDR 0x4e /* Slave address */
41#define M62332_W_BIT 0x00 /* W bit (0 only) */
42#define M62332_SUB_ADDR 0x00 /* Sub address */
43#define M62332_A_BIT 0x00 /* A bit (0 only) */
44
45/* DAC setup and hold times (expressed in us) */
46#define DAC_BUS_FREE_TIME 5 /* 4.7 us */
47#define DAC_START_SETUP_TIME 5 /* 4.7 us */
48#define DAC_STOP_SETUP_TIME 4 /* 4.0 us */
49#define DAC_START_HOLD_TIME 5 /* 4.7 us */
50#define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */
51#define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */
52#define DAC_DATA_SETUP_TIME 1 /* 250 ns */
53#define DAC_DATA_HOLD_TIME 1 /* 300 ns */
54#define DAC_LOW_SETUP_TIME 1 /* 300 ns */
55#define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */
56
57/* the following is the overall data for the locomo chip */
58struct locomo {
59 struct device *dev;
60 unsigned long phys;
61 unsigned int irq;
62 spinlock_t lock;
Russell King54815362006-03-15 15:43:04 +000063 void __iomem *base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
66struct locomo_dev_info {
67 unsigned long offset;
68 unsigned long length;
69 unsigned int devid;
70 unsigned int irq[1];
71 const char * name;
72};
73
74/* All the locomo devices. If offset is non-zero, the mapbase for the
75 * locomo_dev will be set to the chip base plus offset. If offset is
76 * zero, then the mapbase for the locomo_dev will be set to zero. An
77 * offset of zero means the device only uses GPIOs or other helper
78 * functions inside this file */
79static struct locomo_dev_info locomo_devices[] = {
80 {
81 .devid = LOCOMO_DEVID_KEYBOARD,
82 .irq = {
83 IRQ_LOCOMO_KEY,
84 },
85 .name = "locomo-keyboard",
86 .offset = LOCOMO_KEYBOARD,
87 .length = 16,
88 },
89 {
90 .devid = LOCOMO_DEVID_FRONTLIGHT,
91 .irq = {},
92 .name = "locomo-frontlight",
93 .offset = LOCOMO_FRONTLIGHT,
94 .length = 8,
95
96 },
97 {
98 .devid = LOCOMO_DEVID_BACKLIGHT,
99 .irq = {},
100 .name = "locomo-backlight",
101 .offset = LOCOMO_BACKLIGHT,
102 .length = 8,
103 },
104 {
105 .devid = LOCOMO_DEVID_AUDIO,
106 .irq = {},
107 .name = "locomo-audio",
108 .offset = LOCOMO_AUDIO,
109 .length = 4,
110 },
111 {
112 .devid = LOCOMO_DEVID_LED,
113 .irq = {},
114 .name = "locomo-led",
115 .offset = LOCOMO_LED,
116 .length = 8,
117 },
118 {
119 .devid = LOCOMO_DEVID_UART,
120 .irq = {},
121 .name = "locomo-uart",
122 .offset = 0,
123 .length = 0,
124 },
125};
126
127
128/** LoCoMo interrupt handling stuff.
129 * NOTE: LoCoMo has a 1 to many mapping on all of its IRQs.
130 * that is, there is only one real hardware interrupt
131 * we determine which interrupt it is by reading some IO memory.
132 * We have two levels of expansion, first in the handler for the
133 * hardware interrupt we generate an interrupt
134 * IRQ_LOCOMO_*_BASE and those handlers generate more interrupts
135 *
136 * hardware irq reads LOCOMO_ICR & 0x0f00
137 * IRQ_LOCOMO_KEY_BASE
138 * IRQ_LOCOMO_GPIO_BASE
139 * IRQ_LOCOMO_LT_BASE
140 * IRQ_LOCOMO_SPI_BASE
141 * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001
142 * IRQ_LOCOMO_KEY
143 * IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff
144 * IRQ_LOCOMO_GPIO[0-15]
145 * IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001
146 * IRQ_LOCOMO_LT
147 * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F
148 * IRQ_LOCOMO_SPI_RFR
149 * IRQ_LOCOMO_SPI_RFW
150 * IRQ_LOCOMO_SPI_OVRN
151 * IRQ_LOCOMO_SPI_TEND
152 */
153
154#define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE)
155#define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY)
156#define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0)
157#define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT)
158#define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR)
159
160static void locomo_handler(unsigned int irq, struct irqdesc *desc,
161 struct pt_regs *regs)
162{
163 int req, i;
164 struct irqdesc *d;
Russell King54815362006-03-15 15:43:04 +0000165 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 /* Acknowledge the parent IRQ */
168 desc->chip->ack(irq);
169
170 /* check why this interrupt was generated */
171 req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00;
172
173 if (req) {
174 /* generate the next interrupt(s) */
175 irq = LOCOMO_IRQ_START;
176 d = irq_desc + irq;
177 for (i = 0; i <= 3; i++, d++, irq++) {
178 if (req & (0x0100 << i)) {
Russell King664399e2005-09-04 19:45:00 +0100179 desc_handle_irq(irq, d, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
181
182 }
183 }
184}
185
186static void locomo_ack_irq(unsigned int irq)
187{
188}
189
190static void locomo_mask_irq(unsigned int irq)
191{
Russell King54815362006-03-15 15:43:04 +0000192 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 unsigned int r;
194 r = locomo_readl(mapbase + LOCOMO_ICR);
195 r &= ~(0x0010 << (irq - LOCOMO_IRQ_START));
196 locomo_writel(r, mapbase + LOCOMO_ICR);
197}
198
199static void locomo_unmask_irq(unsigned int irq)
200{
Russell King54815362006-03-15 15:43:04 +0000201 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 unsigned int r;
203 r = locomo_readl(mapbase + LOCOMO_ICR);
204 r |= (0x0010 << (irq - LOCOMO_IRQ_START));
205 locomo_writel(r, mapbase + LOCOMO_ICR);
206}
207
208static struct irqchip locomo_chip = {
209 .ack = locomo_ack_irq,
210 .mask = locomo_mask_irq,
211 .unmask = locomo_unmask_irq,
212};
213
214static void locomo_key_handler(unsigned int irq, struct irqdesc *desc,
215 struct pt_regs *regs)
216{
217 struct irqdesc *d;
Russell King54815362006-03-15 15:43:04 +0000218 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) {
221 d = irq_desc + LOCOMO_IRQ_KEY_START;
Russell King664399e2005-09-04 19:45:00 +0100222 desc_handle_irq(LOCOMO_IRQ_KEY_START, d, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224}
225
226static void locomo_key_ack_irq(unsigned int irq)
227{
Russell King54815362006-03-15 15:43:04 +0000228 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 unsigned int r;
230 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
231 r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START));
232 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
233}
234
235static void locomo_key_mask_irq(unsigned int irq)
236{
Russell King54815362006-03-15 15:43:04 +0000237 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 unsigned int r;
239 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
240 r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START));
241 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
242}
243
244static void locomo_key_unmask_irq(unsigned int irq)
245{
Russell King54815362006-03-15 15:43:04 +0000246 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 unsigned int r;
248 r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
249 r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START));
250 locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC);
251}
252
253static struct irqchip locomo_key_chip = {
254 .ack = locomo_key_ack_irq,
255 .mask = locomo_key_mask_irq,
256 .unmask = locomo_key_unmask_irq,
257};
258
259static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc,
260 struct pt_regs *regs)
261{
262 int req, i;
263 struct irqdesc *d;
Russell King54815362006-03-15 15:43:04 +0000264 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266 req = locomo_readl(mapbase + LOCOMO_GIR) &
267 locomo_readl(mapbase + LOCOMO_GPD) &
268 0xffff;
269
270 if (req) {
271 irq = LOCOMO_IRQ_GPIO_START;
272 d = irq_desc + LOCOMO_IRQ_GPIO_START;
273 for (i = 0; i <= 15; i++, irq++, d++) {
274 if (req & (0x0001 << i)) {
Russell King664399e2005-09-04 19:45:00 +0100275 desc_handle_irq(irq, d, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277 }
278 }
279}
280
281static void locomo_gpio_ack_irq(unsigned int irq)
282{
Russell King54815362006-03-15 15:43:04 +0000283 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 unsigned int r;
285 r = locomo_readl(mapbase + LOCOMO_GWE);
286 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
287 locomo_writel(r, mapbase + LOCOMO_GWE);
288
289 r = locomo_readl(mapbase + LOCOMO_GIS);
290 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
291 locomo_writel(r, mapbase + LOCOMO_GIS);
292
293 r = locomo_readl(mapbase + LOCOMO_GWE);
294 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
295 locomo_writel(r, mapbase + LOCOMO_GWE);
296}
297
298static void locomo_gpio_mask_irq(unsigned int irq)
299{
Russell King54815362006-03-15 15:43:04 +0000300 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 unsigned int r;
302 r = locomo_readl(mapbase + LOCOMO_GIE);
303 r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
304 locomo_writel(r, mapbase + LOCOMO_GIE);
305}
306
307static void locomo_gpio_unmask_irq(unsigned int irq)
308{
Russell King54815362006-03-15 15:43:04 +0000309 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 unsigned int r;
311 r = locomo_readl(mapbase + LOCOMO_GIE);
312 r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START));
313 locomo_writel(r, mapbase + LOCOMO_GIE);
314}
315
316static struct irqchip locomo_gpio_chip = {
317 .ack = locomo_gpio_ack_irq,
318 .mask = locomo_gpio_mask_irq,
319 .unmask = locomo_gpio_unmask_irq,
320};
321
322static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc,
323 struct pt_regs *regs)
324{
325 struct irqdesc *d;
Russell King54815362006-03-15 15:43:04 +0000326 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) {
329 d = irq_desc + LOCOMO_IRQ_LT_START;
Russell King664399e2005-09-04 19:45:00 +0100330 desc_handle_irq(LOCOMO_IRQ_LT_START, d, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
332}
333
334static void locomo_lt_ack_irq(unsigned int irq)
335{
Russell King54815362006-03-15 15:43:04 +0000336 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 unsigned int r;
338 r = locomo_readl(mapbase + LOCOMO_LTINT);
339 r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START));
340 locomo_writel(r, mapbase + LOCOMO_LTINT);
341}
342
343static void locomo_lt_mask_irq(unsigned int irq)
344{
Russell King54815362006-03-15 15:43:04 +0000345 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 unsigned int r;
347 r = locomo_readl(mapbase + LOCOMO_LTINT);
348 r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START));
349 locomo_writel(r, mapbase + LOCOMO_LTINT);
350}
351
352static void locomo_lt_unmask_irq(unsigned int irq)
353{
Russell King54815362006-03-15 15:43:04 +0000354 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 unsigned int r;
356 r = locomo_readl(mapbase + LOCOMO_LTINT);
357 r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START));
358 locomo_writel(r, mapbase + LOCOMO_LTINT);
359}
360
361static struct irqchip locomo_lt_chip = {
362 .ack = locomo_lt_ack_irq,
363 .mask = locomo_lt_mask_irq,
364 .unmask = locomo_lt_unmask_irq,
365};
366
367static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc,
368 struct pt_regs *regs)
369{
370 int req, i;
371 struct irqdesc *d;
Russell King54815362006-03-15 15:43:04 +0000372 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 req = locomo_readl(mapbase + LOCOMO_SPIIR) & 0x000F;
375 if (req) {
376 irq = LOCOMO_IRQ_SPI_START;
377 d = irq_desc + irq;
378
379 for (i = 0; i <= 3; i++, irq++, d++) {
380 if (req & (0x0001 << i)) {
Russell King664399e2005-09-04 19:45:00 +0100381 desc_handle_irq(irq, d, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 }
383 }
384 }
385}
386
387static void locomo_spi_ack_irq(unsigned int irq)
388{
Russell King54815362006-03-15 15:43:04 +0000389 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 unsigned int r;
391 r = locomo_readl(mapbase + LOCOMO_SPIWE);
392 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
393 locomo_writel(r, mapbase + LOCOMO_SPIWE);
394
395 r = locomo_readl(mapbase + LOCOMO_SPIIS);
396 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
397 locomo_writel(r, mapbase + LOCOMO_SPIIS);
398
399 r = locomo_readl(mapbase + LOCOMO_SPIWE);
400 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
401 locomo_writel(r, mapbase + LOCOMO_SPIWE);
402}
403
404static void locomo_spi_mask_irq(unsigned int irq)
405{
Russell King54815362006-03-15 15:43:04 +0000406 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 unsigned int r;
408 r = locomo_readl(mapbase + LOCOMO_SPIIE);
409 r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START));
410 locomo_writel(r, mapbase + LOCOMO_SPIIE);
411}
412
413static void locomo_spi_unmask_irq(unsigned int irq)
414{
Russell King54815362006-03-15 15:43:04 +0000415 void __iomem *mapbase = get_irq_chipdata(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 unsigned int r;
417 r = locomo_readl(mapbase + LOCOMO_SPIIE);
418 r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START));
419 locomo_writel(r, mapbase + LOCOMO_SPIIE);
420}
421
422static struct irqchip locomo_spi_chip = {
423 .ack = locomo_spi_ack_irq,
424 .mask = locomo_spi_mask_irq,
425 .unmask = locomo_spi_unmask_irq,
426};
427
428static void locomo_setup_irq(struct locomo *lchip)
429{
430 int irq;
Russell King54815362006-03-15 15:43:04 +0000431 void __iomem *irqbase = lchip->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /*
434 * Install handler for IRQ_LOCOMO_HW.
435 */
436 set_irq_type(lchip->irq, IRQT_FALLING);
437 set_irq_chipdata(lchip->irq, irqbase);
438 set_irq_chained_handler(lchip->irq, locomo_handler);
439
440 /* Install handlers for IRQ_LOCOMO_*_BASE */
441 set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip);
442 set_irq_chipdata(IRQ_LOCOMO_KEY_BASE, irqbase);
443 set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler);
444 set_irq_flags(IRQ_LOCOMO_KEY_BASE, IRQF_VALID | IRQF_PROBE);
445
446 set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip);
447 set_irq_chipdata(IRQ_LOCOMO_GPIO_BASE, irqbase);
448 set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler);
449 set_irq_flags(IRQ_LOCOMO_GPIO_BASE, IRQF_VALID | IRQF_PROBE);
450
451 set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip);
452 set_irq_chipdata(IRQ_LOCOMO_LT_BASE, irqbase);
453 set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler);
454 set_irq_flags(IRQ_LOCOMO_LT_BASE, IRQF_VALID | IRQF_PROBE);
455
456 set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip);
457 set_irq_chipdata(IRQ_LOCOMO_SPI_BASE, irqbase);
458 set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler);
459 set_irq_flags(IRQ_LOCOMO_SPI_BASE, IRQF_VALID | IRQF_PROBE);
460
461 /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */
462 set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip);
463 set_irq_chipdata(LOCOMO_IRQ_KEY_START, irqbase);
464 set_irq_handler(LOCOMO_IRQ_KEY_START, do_edge_IRQ);
465 set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE);
466
467 /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */
468 for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) {
469 set_irq_chip(irq, &locomo_gpio_chip);
470 set_irq_chipdata(irq, irqbase);
471 set_irq_handler(irq, do_edge_IRQ);
472 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
473 }
474
475 /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */
476 set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip);
477 set_irq_chipdata(LOCOMO_IRQ_LT_START, irqbase);
478 set_irq_handler(LOCOMO_IRQ_LT_START, do_edge_IRQ);
479 set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE);
480
481 /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */
482 for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 3; irq++) {
483 set_irq_chip(irq, &locomo_spi_chip);
484 set_irq_chipdata(irq, irqbase);
485 set_irq_handler(irq, do_edge_IRQ);
486 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
487 }
488}
489
490
491static void locomo_dev_release(struct device *_dev)
492{
493 struct locomo_dev *dev = LOCOMO_DEV(_dev);
494
495 kfree(dev);
496}
497
498static int
499locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info)
500{
501 struct locomo_dev *dev;
502 int ret;
503
504 dev = kmalloc(sizeof(struct locomo_dev), GFP_KERNEL);
505 if (!dev) {
506 ret = -ENOMEM;
507 goto out;
508 }
509 memset(dev, 0, sizeof(struct locomo_dev));
510
511 strncpy(dev->dev.bus_id,info->name,sizeof(dev->dev.bus_id));
512 /*
513 * If the parent device has a DMA mask associated with it,
514 * propagate it down to the children.
515 */
516 if (lchip->dev->dma_mask) {
517 dev->dma_mask = *lchip->dev->dma_mask;
518 dev->dev.dma_mask = &dev->dma_mask;
519 }
520
521 dev->devid = info->devid;
522 dev->dev.parent = lchip->dev;
523 dev->dev.bus = &locomo_bus_type;
524 dev->dev.release = locomo_dev_release;
525 dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask;
526
527 if (info->offset)
528 dev->mapbase = lchip->base + info->offset;
529 else
530 dev->mapbase = 0;
531 dev->length = info->length;
532
533 memmove(dev->irq, info->irq, sizeof(dev->irq));
534
535 ret = device_register(&dev->dev);
536 if (ret) {
537 out:
538 kfree(dev);
539 }
540 return ret;
541}
542
John Lenzb38d9502005-09-08 14:41:54 +0100543#ifdef CONFIG_PM
544
545struct locomo_save_data {
546 u16 LCM_GPO;
547 u16 LCM_SPICT;
548 u16 LCM_GPE;
549 u16 LCM_ASD;
550 u16 LCM_SPIMD;
551};
552
Russell King3ae5eae2005-11-09 22:32:44 +0000553static int locomo_suspend(struct platform_device *dev, pm_message_t state)
John Lenzb38d9502005-09-08 14:41:54 +0100554{
Russell King3ae5eae2005-11-09 22:32:44 +0000555 struct locomo *lchip = platform_get_drvdata(dev);
John Lenzb38d9502005-09-08 14:41:54 +0100556 struct locomo_save_data *save;
557 unsigned long flags;
558
John Lenzb38d9502005-09-08 14:41:54 +0100559 save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL);
560 if (!save)
561 return -ENOMEM;
562
Russell King3ae5eae2005-11-09 22:32:44 +0000563 dev->dev.power.saved_state = (void *) save;
John Lenzb38d9502005-09-08 14:41:54 +0100564
565 spin_lock_irqsave(&lchip->lock, flags);
566
567 save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */
568 locomo_writel(0x00, lchip->base + LOCOMO_GPO);
569 save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPICT); /* SPI */
570 locomo_writel(0x40, lchip->base + LOCOMO_SPICT);
571 save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */
572 locomo_writel(0x00, lchip->base + LOCOMO_GPE);
573 save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */
574 locomo_writel(0x00, lchip->base + LOCOMO_ASD);
575 save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPIMD); /* SPI */
576 locomo_writel(0x3C14, lchip->base + LOCOMO_SPIMD);
577
578 locomo_writel(0x00, lchip->base + LOCOMO_PAIF);
579 locomo_writel(0x00, lchip->base + LOCOMO_DAC);
580 locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC);
581
582 if ( (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88) )
583 locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */
584 else
585 /* 18MHz already enabled, so no wait */
586 locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */
587
588 locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/
589 locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */
590 locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */
591
592 spin_unlock_irqrestore(&lchip->lock, flags);
593
594 return 0;
595}
596
Russell King3ae5eae2005-11-09 22:32:44 +0000597static int locomo_resume(struct platform_device *dev)
John Lenzb38d9502005-09-08 14:41:54 +0100598{
Russell King3ae5eae2005-11-09 22:32:44 +0000599 struct locomo *lchip = platform_get_drvdata(dev);
John Lenzb38d9502005-09-08 14:41:54 +0100600 struct locomo_save_data *save;
601 unsigned long r;
602 unsigned long flags;
603
Russell King3ae5eae2005-11-09 22:32:44 +0000604 save = (struct locomo_save_data *) dev->dev.power.saved_state;
John Lenzb38d9502005-09-08 14:41:54 +0100605 if (!save)
606 return 0;
607
608 spin_lock_irqsave(&lchip->lock, flags);
609
610 locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO);
611 locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPICT);
612 locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE);
613 locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD);
614 locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPIMD);
615
616 locomo_writel(0x00, lchip->base + LOCOMO_C32K);
617 locomo_writel(0x90, lchip->base + LOCOMO_TADC);
618
619 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC);
620 r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
621 r &= 0xFEFF;
622 locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
623 locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);
624
625 spin_unlock_irqrestore(&lchip->lock, flags);
John Lenzb38d9502005-09-08 14:41:54 +0100626 kfree(save);
627
628 return 0;
629}
630#endif
631
Pavel Machek4ebf2d02006-03-15 16:03:03 +0000632
633#define LCM_ALC_EN 0x8000
634
635void frontlight_set(struct locomo *lchip, int duty, int vr, int bpwf)
636{
637 unsigned long flags;
638
639 spin_lock_irqsave(&lchip->lock, flags);
640 locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
641 udelay(100);
642 locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
643 locomo_writel(bpwf | LCM_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
644 spin_unlock_irqrestore(&lchip->lock, flags);
645}
646
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648/**
649 * locomo_probe - probe for a single LoCoMo chip.
650 * @phys_addr: physical address of device.
651 *
652 * Probe for a LoCoMo chip. This must be called
653 * before any other locomo-specific code.
654 *
655 * Returns:
656 * %-ENODEV device not found.
657 * %-EBUSY physical address already marked in-use.
658 * %0 successful.
659 */
660static int
661__locomo_probe(struct device *me, struct resource *mem, int irq)
662{
663 struct locomo *lchip;
664 unsigned long r;
665 int i, ret = -ENODEV;
666
667 lchip = kmalloc(sizeof(struct locomo), GFP_KERNEL);
668 if (!lchip)
669 return -ENOMEM;
670
671 memset(lchip, 0, sizeof(struct locomo));
672
673 spin_lock_init(&lchip->lock);
674
675 lchip->dev = me;
676 dev_set_drvdata(lchip->dev, lchip);
677
678 lchip->phys = mem->start;
679 lchip->irq = irq;
680
681 /*
682 * Map the whole region. This also maps the
683 * registers for our children.
684 */
685 lchip->base = ioremap(mem->start, PAGE_SIZE);
686 if (!lchip->base) {
687 ret = -ENOMEM;
688 goto out;
689 }
690
691 /* locomo initialize */
692 locomo_writel(0, lchip->base + LOCOMO_ICR);
693 /* KEYBOARD */
694 locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC);
695
696 /* GPIO */
697 locomo_writel(0, lchip->base + LOCOMO_GPO);
698 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
699 , lchip->base + LOCOMO_GPE);
700 locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14))
701 , lchip->base + LOCOMO_GPD);
702 locomo_writel(0, lchip->base + LOCOMO_GIE);
703
704 /* FrontLight */
705 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS);
706 locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD);
Pavel Machek4ebf2d02006-03-15 16:03:03 +0000707
708 /* Same constants can be used for collie and poodle
709 (depending on CONFIG options in original sharp code)? */
710 frontlight_set(lchip, 163, 0, 148);
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /* Longtime timer */
713 locomo_writel(0, lchip->base + LOCOMO_LTINT);
714 /* SPI */
715 locomo_writel(0, lchip->base + LOCOMO_SPIIE);
716
717 locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD);
718 r = locomo_readl(lchip->base + LOCOMO_ASD);
719 r |= 0x8000;
720 locomo_writel(r, lchip->base + LOCOMO_ASD);
721
722 locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD);
723 r = locomo_readl(lchip->base + LOCOMO_HSD);
724 r |= 0x8000;
725 locomo_writel(r, lchip->base + LOCOMO_HSD);
726
727 locomo_writel(128 / 8, lchip->base + LOCOMO_HSC);
728
729 /* XON */
730 locomo_writel(0x80, lchip->base + LOCOMO_TADC);
731 udelay(1000);
732 /* CLK9MEN */
733 r = locomo_readl(lchip->base + LOCOMO_TADC);
734 r |= 0x10;
735 locomo_writel(r, lchip->base + LOCOMO_TADC);
736 udelay(100);
737
738 /* init DAC */
739 r = locomo_readl(lchip->base + LOCOMO_DAC);
740 r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB;
741 locomo_writel(r, lchip->base + LOCOMO_DAC);
742
743 r = locomo_readl(lchip->base + LOCOMO_VER);
744 printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff));
745
746 /*
747 * The interrupt controller must be initialised before any
748 * other device to ensure that the interrupts are available.
749 */
750 if (lchip->irq != NO_IRQ)
751 locomo_setup_irq(lchip);
752
753 for (i = 0; i < ARRAY_SIZE(locomo_devices); i++)
754 locomo_init_one_child(lchip, &locomo_devices[i]);
755
756 return 0;
757
758 out:
759 kfree(lchip);
760 return ret;
761}
762
Pavel Macheke24da5d2005-09-04 11:33:12 +0100763static int locomo_remove_child(struct device *dev, void *data)
764{
765 device_unregister(dev);
766 return 0;
767}
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769static void __locomo_remove(struct locomo *lchip)
770{
Pavel Macheke24da5d2005-09-04 11:33:12 +0100771 device_for_each_child(lchip->dev, NULL, locomo_remove_child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 if (lchip->irq != NO_IRQ) {
774 set_irq_chained_handler(lchip->irq, NULL);
775 set_irq_data(lchip->irq, NULL);
776 }
777
778 iounmap(lchip->base);
779 kfree(lchip);
780}
781
Russell King3ae5eae2005-11-09 22:32:44 +0000782static int locomo_probe(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 struct resource *mem;
785 int irq;
786
Russell King3ae5eae2005-11-09 22:32:44 +0000787 mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 if (!mem)
789 return -EINVAL;
Russell King3ae5eae2005-11-09 22:32:44 +0000790 irq = platform_get_irq(dev, 0);
David Vrabel48944732006-01-19 17:56:29 +0000791 if (irq < 0)
792 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Russell King3ae5eae2005-11-09 22:32:44 +0000794 return __locomo_probe(&dev->dev, mem, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795}
796
Russell King3ae5eae2005-11-09 22:32:44 +0000797static int locomo_remove(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Pavel Machekc35bf4a2005-11-12 20:25:25 +0000799 struct locomo *lchip = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 if (lchip) {
802 __locomo_remove(lchip);
Russell King3ae5eae2005-11-09 22:32:44 +0000803 platform_set_drvdata(dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
805
806 return 0;
807}
808
809/*
810 * Not sure if this should be on the system bus or not yet.
811 * We really want some way to register a system device at
812 * the per-machine level, and then have this driver pick
813 * up the registered devices.
814 */
Russell King3ae5eae2005-11-09 22:32:44 +0000815static struct platform_driver locomo_device_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .probe = locomo_probe,
817 .remove = locomo_remove,
John Lenzb38d9502005-09-08 14:41:54 +0100818#ifdef CONFIG_PM
819 .suspend = locomo_suspend,
820 .resume = locomo_resume,
821#endif
Russell King3ae5eae2005-11-09 22:32:44 +0000822 .driver = {
823 .name = "locomo",
824 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825};
826
827/*
828 * Get the parent device driver (us) structure
829 * from a child function device
830 */
831static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev)
832{
833 return (struct locomo *)dev_get_drvdata(ldev->dev.parent);
834}
835
836void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir)
837{
838 struct locomo *lchip = locomo_chip_driver(ldev);
839 unsigned long flags;
840 unsigned int r;
841
842 spin_lock_irqsave(&lchip->lock, flags);
843
844 r = locomo_readl(lchip->base + LOCOMO_GPD);
845 r &= ~bits;
846 locomo_writel(r, lchip->base + LOCOMO_GPD);
847
848 r = locomo_readl(lchip->base + LOCOMO_GPE);
849 if (dir)
850 r |= bits;
851 else
852 r &= ~bits;
853 locomo_writel(r, lchip->base + LOCOMO_GPE);
854
855 spin_unlock_irqrestore(&lchip->lock, flags);
856}
857
858unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits)
859{
860 struct locomo *lchip = locomo_chip_driver(ldev);
861 unsigned long flags;
862 unsigned int ret;
863
864 spin_lock_irqsave(&lchip->lock, flags);
865 ret = locomo_readl(lchip->base + LOCOMO_GPL);
866 spin_unlock_irqrestore(&lchip->lock, flags);
867
868 ret &= bits;
869 return ret;
870}
871
872unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits)
873{
874 struct locomo *lchip = locomo_chip_driver(ldev);
875 unsigned long flags;
876 unsigned int ret;
877
878 spin_lock_irqsave(&lchip->lock, flags);
879 ret = locomo_readl(lchip->base + LOCOMO_GPO);
880 spin_unlock_irqrestore(&lchip->lock, flags);
881
882 ret &= bits;
883 return ret;
884}
885
886void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set)
887{
888 struct locomo *lchip = locomo_chip_driver(ldev);
889 unsigned long flags;
890 unsigned int r;
891
892 spin_lock_irqsave(&lchip->lock, flags);
893
894 r = locomo_readl(lchip->base + LOCOMO_GPO);
895 if (set)
896 r |= bits;
897 else
898 r &= ~bits;
899 locomo_writel(r, lchip->base + LOCOMO_GPO);
900
901 spin_unlock_irqrestore(&lchip->lock, flags);
902}
903
904static void locomo_m62332_sendbit(void *mapbase, int bit)
905{
906 unsigned int r;
907
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 */
918
919 if (bit & 1) {
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 */
924 } else {
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 */
929 }
930
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 */
937}
938
939void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel)
940{
941 struct locomo *lchip = locomo_chip_driver(ldev);
942 int i;
943 unsigned char data;
944 unsigned int r;
945 void *mapbase = lchip->base;
946 unsigned long flags;
947
948 spin_lock_irqsave(&lchip->lock, flags);
949
950 /* Start */
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 */
962
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));
967 }
968
969 /* Check A bit */
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");
986 return;
987 }
988
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));
995 }
996
997 /* Check A bit */
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");
1014 return;
1015 }
1016
1017 /* Send DAC data */
1018 for (i = 1; i <= 8; i++) {
1019 locomo_m62332_sendbit(mapbase, dac_data >> (8 - i));
1020 }
1021
1022 /* Check A bit */
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");
1039 return;
1040 }
1041
1042 /* stop */
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 */
1058
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 */
1064
1065 spin_unlock_irqrestore(&lchip->lock, flags);
1066}
1067
1068/*
1069 * LoCoMo "Register Access Bus."
1070 *
1071 * We model this as a regular bus type, and hang devices directly
1072 * off this.
1073 */
1074static int locomo_match(struct device *_dev, struct device_driver *_drv)
1075{
1076 struct locomo_dev *dev = LOCOMO_DEV(_dev);
1077 struct locomo_driver *drv = LOCOMO_DRV(_drv);
1078
1079 return dev->devid == drv->devid;
1080}
1081
1082static int locomo_bus_suspend(struct device *dev, pm_message_t state)
1083{
1084 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1085 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1086 int ret = 0;
1087
1088 if (drv && drv->suspend)
1089 ret = drv->suspend(ldev, state);
1090 return ret;
1091}
1092
1093static int locomo_bus_resume(struct device *dev)
1094{
1095 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1096 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1097 int ret = 0;
1098
1099 if (drv && drv->resume)
1100 ret = drv->resume(ldev);
1101 return ret;
1102}
1103
1104static int locomo_bus_probe(struct device *dev)
1105{
1106 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1107 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1108 int ret = -ENODEV;
1109
1110 if (drv->probe)
1111 ret = drv->probe(ldev);
1112 return ret;
1113}
1114
1115static int locomo_bus_remove(struct device *dev)
1116{
1117 struct locomo_dev *ldev = LOCOMO_DEV(dev);
1118 struct locomo_driver *drv = LOCOMO_DRV(dev->driver);
1119 int ret = 0;
1120
1121 if (drv->remove)
1122 ret = drv->remove(ldev);
1123 return ret;
1124}
1125
1126struct bus_type locomo_bus_type = {
1127 .name = "locomo-bus",
1128 .match = locomo_match,
Russell King306955b2006-01-05 14:33:04 +00001129 .probe = locomo_bus_probe,
1130 .remove = locomo_bus_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 .suspend = locomo_bus_suspend,
1132 .resume = locomo_bus_resume,
1133};
1134
1135int locomo_driver_register(struct locomo_driver *driver)
1136{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 driver->drv.bus = &locomo_bus_type;
1138 return driver_register(&driver->drv);
1139}
1140
1141void locomo_driver_unregister(struct locomo_driver *driver)
1142{
1143 driver_unregister(&driver->drv);
1144}
1145
1146static int __init locomo_init(void)
1147{
1148 int ret = bus_register(&locomo_bus_type);
1149 if (ret == 0)
Russell King3ae5eae2005-11-09 22:32:44 +00001150 platform_driver_register(&locomo_device_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 return ret;
1152}
1153
1154static void __exit locomo_exit(void)
1155{
Russell King3ae5eae2005-11-09 22:32:44 +00001156 platform_driver_unregister(&locomo_device_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 bus_unregister(&locomo_bus_type);
1158}
1159
1160module_init(locomo_init);
1161module_exit(locomo_exit);
1162
1163MODULE_DESCRIPTION("Sharp LoCoMo core driver");
1164MODULE_LICENSE("GPL");
1165MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
1166
1167EXPORT_SYMBOL(locomo_driver_register);
1168EXPORT_SYMBOL(locomo_driver_unregister);
1169EXPORT_SYMBOL(locomo_gpio_set_dir);
1170EXPORT_SYMBOL(locomo_gpio_read_level);
1171EXPORT_SYMBOL(locomo_gpio_read_output);
1172EXPORT_SYMBOL(locomo_gpio_write);
1173EXPORT_SYMBOL(locomo_m62332_senddata);