Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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> | |
d052d1be | 25 | #include <linux/platform_device.h> |
1da177e4 LT |
26 | #include <linux/slab.h> |
27 | #include <linux/spinlock.h> | |
28 | ||
29 | #include <asm/hardware.h> | |
1da177e4 LT |
30 | #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 */ | |
58 | struct locomo { | |
59 | struct device *dev; | |
60 | unsigned long phys; | |
61 | unsigned int irq; | |
62 | spinlock_t lock; | |
54815366 | 63 | void __iomem *base; |
1da177e4 LT |
64 | }; |
65 | ||
66 | struct 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 */ | |
79 | static 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 | ||
160 | static void locomo_handler(unsigned int irq, struct irqdesc *desc, | |
161 | struct pt_regs *regs) | |
162 | { | |
163 | int req, i; | |
164 | struct irqdesc *d; | |
54815366 | 165 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
166 | |
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)) { | |
664399e1 | 179 | desc_handle_irq(irq, d, regs); |
1da177e4 LT |
180 | } |
181 | ||
182 | } | |
183 | } | |
184 | } | |
185 | ||
186 | static void locomo_ack_irq(unsigned int irq) | |
187 | { | |
188 | } | |
189 | ||
190 | static void locomo_mask_irq(unsigned int irq) | |
191 | { | |
54815366 | 192 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
193 | 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 | ||
199 | static void locomo_unmask_irq(unsigned int irq) | |
200 | { | |
54815366 | 201 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
202 | 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 | ||
208 | static struct irqchip locomo_chip = { | |
209 | .ack = locomo_ack_irq, | |
210 | .mask = locomo_mask_irq, | |
211 | .unmask = locomo_unmask_irq, | |
212 | }; | |
213 | ||
214 | static void locomo_key_handler(unsigned int irq, struct irqdesc *desc, | |
215 | struct pt_regs *regs) | |
216 | { | |
217 | struct irqdesc *d; | |
54815366 | 218 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
219 | |
220 | if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) { | |
221 | d = irq_desc + LOCOMO_IRQ_KEY_START; | |
664399e1 | 222 | desc_handle_irq(LOCOMO_IRQ_KEY_START, d, regs); |
1da177e4 LT |
223 | } |
224 | } | |
225 | ||
226 | static void locomo_key_ack_irq(unsigned int irq) | |
227 | { | |
54815366 | 228 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
229 | 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 | ||
235 | static void locomo_key_mask_irq(unsigned int irq) | |
236 | { | |
54815366 | 237 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
238 | 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 | ||
244 | static void locomo_key_unmask_irq(unsigned int irq) | |
245 | { | |
54815366 | 246 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
247 | 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 | ||
253 | static 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 | ||
259 | static void locomo_gpio_handler(unsigned int irq, struct irqdesc *desc, | |
260 | struct pt_regs *regs) | |
261 | { | |
262 | int req, i; | |
263 | struct irqdesc *d; | |
54815366 | 264 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
265 | |
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)) { | |
664399e1 | 275 | desc_handle_irq(irq, d, regs); |
1da177e4 LT |
276 | } |
277 | } | |
278 | } | |
279 | } | |
280 | ||
281 | static void locomo_gpio_ack_irq(unsigned int irq) | |
282 | { | |
54815366 | 283 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
284 | 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 | ||
298 | static void locomo_gpio_mask_irq(unsigned int irq) | |
299 | { | |
54815366 | 300 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
301 | 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 | ||
307 | static void locomo_gpio_unmask_irq(unsigned int irq) | |
308 | { | |
54815366 | 309 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
310 | 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 | ||
316 | static 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 | ||
322 | static void locomo_lt_handler(unsigned int irq, struct irqdesc *desc, | |
323 | struct pt_regs *regs) | |
324 | { | |
325 | struct irqdesc *d; | |
54815366 | 326 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
327 | |
328 | if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) { | |
329 | d = irq_desc + LOCOMO_IRQ_LT_START; | |
664399e1 | 330 | desc_handle_irq(LOCOMO_IRQ_LT_START, d, regs); |
1da177e4 LT |
331 | } |
332 | } | |
333 | ||
334 | static void locomo_lt_ack_irq(unsigned int irq) | |
335 | { | |
54815366 | 336 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
337 | 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 | ||
343 | static void locomo_lt_mask_irq(unsigned int irq) | |
344 | { | |
54815366 | 345 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
346 | 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 | ||
352 | static void locomo_lt_unmask_irq(unsigned int irq) | |
353 | { | |
54815366 | 354 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
355 | 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 | ||
361 | static 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 | ||
367 | static void locomo_spi_handler(unsigned int irq, struct irqdesc *desc, | |
368 | struct pt_regs *regs) | |
369 | { | |
370 | int req, i; | |
371 | struct irqdesc *d; | |
54815366 | 372 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
373 | |
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)) { | |
664399e1 | 381 | desc_handle_irq(irq, d, regs); |
1da177e4 LT |
382 | } |
383 | } | |
384 | } | |
385 | } | |
386 | ||
387 | static void locomo_spi_ack_irq(unsigned int irq) | |
388 | { | |
54815366 | 389 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
390 | 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 | ||
404 | static void locomo_spi_mask_irq(unsigned int irq) | |
405 | { | |
54815366 | 406 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
407 | 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 | ||
413 | static void locomo_spi_unmask_irq(unsigned int irq) | |
414 | { | |
54815366 | 415 | void __iomem *mapbase = get_irq_chipdata(irq); |
1da177e4 LT |
416 | 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 | ||
422 | static 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 | ||
428 | static void locomo_setup_irq(struct locomo *lchip) | |
429 | { | |
430 | int irq; | |
54815366 | 431 | void __iomem *irqbase = lchip->base; |
1da177e4 LT |
432 | |
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 | ||
491 | static void locomo_dev_release(struct device *_dev) | |
492 | { | |
493 | struct locomo_dev *dev = LOCOMO_DEV(_dev); | |
494 | ||
495 | kfree(dev); | |
496 | } | |
497 | ||
498 | static int | |
499 | locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info) | |
500 | { | |
501 | struct locomo_dev *dev; | |
502 | int ret; | |
503 | ||
d2a02b93 | 504 | dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL); |
1da177e4 LT |
505 | if (!dev) { |
506 | ret = -ENOMEM; | |
507 | goto out; | |
508 | } | |
1da177e4 LT |
509 | |
510 | strncpy(dev->dev.bus_id,info->name,sizeof(dev->dev.bus_id)); | |
511 | /* | |
512 | * If the parent device has a DMA mask associated with it, | |
513 | * propagate it down to the children. | |
514 | */ | |
515 | if (lchip->dev->dma_mask) { | |
516 | dev->dma_mask = *lchip->dev->dma_mask; | |
517 | dev->dev.dma_mask = &dev->dma_mask; | |
518 | } | |
519 | ||
520 | dev->devid = info->devid; | |
521 | dev->dev.parent = lchip->dev; | |
522 | dev->dev.bus = &locomo_bus_type; | |
523 | dev->dev.release = locomo_dev_release; | |
524 | dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask; | |
525 | ||
526 | if (info->offset) | |
527 | dev->mapbase = lchip->base + info->offset; | |
528 | else | |
529 | dev->mapbase = 0; | |
530 | dev->length = info->length; | |
531 | ||
532 | memmove(dev->irq, info->irq, sizeof(dev->irq)); | |
533 | ||
534 | ret = device_register(&dev->dev); | |
535 | if (ret) { | |
536 | out: | |
537 | kfree(dev); | |
538 | } | |
539 | return ret; | |
540 | } | |
541 | ||
b38d950d JL |
542 | #ifdef CONFIG_PM |
543 | ||
544 | struct locomo_save_data { | |
545 | u16 LCM_GPO; | |
546 | u16 LCM_SPICT; | |
547 | u16 LCM_GPE; | |
548 | u16 LCM_ASD; | |
549 | u16 LCM_SPIMD; | |
550 | }; | |
551 | ||
3ae5eaec | 552 | static int locomo_suspend(struct platform_device *dev, pm_message_t state) |
b38d950d | 553 | { |
3ae5eaec | 554 | struct locomo *lchip = platform_get_drvdata(dev); |
b38d950d JL |
555 | struct locomo_save_data *save; |
556 | unsigned long flags; | |
557 | ||
b38d950d JL |
558 | save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL); |
559 | if (!save) | |
560 | return -ENOMEM; | |
561 | ||
3ae5eaec | 562 | dev->dev.power.saved_state = (void *) save; |
b38d950d JL |
563 | |
564 | spin_lock_irqsave(&lchip->lock, flags); | |
565 | ||
566 | save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */ | |
567 | locomo_writel(0x00, lchip->base + LOCOMO_GPO); | |
568 | save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPICT); /* SPI */ | |
569 | locomo_writel(0x40, lchip->base + LOCOMO_SPICT); | |
570 | save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */ | |
571 | locomo_writel(0x00, lchip->base + LOCOMO_GPE); | |
572 | save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */ | |
573 | locomo_writel(0x00, lchip->base + LOCOMO_ASD); | |
574 | save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPIMD); /* SPI */ | |
575 | locomo_writel(0x3C14, lchip->base + LOCOMO_SPIMD); | |
576 | ||
577 | locomo_writel(0x00, lchip->base + LOCOMO_PAIF); | |
578 | locomo_writel(0x00, lchip->base + LOCOMO_DAC); | |
579 | locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC); | |
580 | ||
581 | if ( (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88) ) | |
582 | locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */ | |
583 | else | |
584 | /* 18MHz already enabled, so no wait */ | |
585 | locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */ | |
586 | ||
587 | locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/ | |
588 | locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */ | |
589 | locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */ | |
590 | ||
591 | spin_unlock_irqrestore(&lchip->lock, flags); | |
592 | ||
593 | return 0; | |
594 | } | |
595 | ||
3ae5eaec | 596 | static int locomo_resume(struct platform_device *dev) |
b38d950d | 597 | { |
3ae5eaec | 598 | struct locomo *lchip = platform_get_drvdata(dev); |
b38d950d JL |
599 | struct locomo_save_data *save; |
600 | unsigned long r; | |
601 | unsigned long flags; | |
602 | ||
3ae5eaec | 603 | save = (struct locomo_save_data *) dev->dev.power.saved_state; |
b38d950d JL |
604 | if (!save) |
605 | return 0; | |
606 | ||
607 | spin_lock_irqsave(&lchip->lock, flags); | |
608 | ||
609 | locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO); | |
610 | locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPICT); | |
611 | locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE); | |
612 | locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD); | |
613 | locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPIMD); | |
614 | ||
615 | locomo_writel(0x00, lchip->base + LOCOMO_C32K); | |
616 | locomo_writel(0x90, lchip->base + LOCOMO_TADC); | |
617 | ||
618 | locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC); | |
619 | r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); | |
620 | r &= 0xFEFF; | |
621 | locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); | |
622 | locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD); | |
623 | ||
624 | spin_unlock_irqrestore(&lchip->lock, flags); | |
b38d950d JL |
625 | kfree(save); |
626 | ||
627 | return 0; | |
628 | } | |
629 | #endif | |
630 | ||
4ebf2d00 PM |
631 | |
632 | #define LCM_ALC_EN 0x8000 | |
633 | ||
634 | void frontlight_set(struct locomo *lchip, int duty, int vr, int bpwf) | |
635 | { | |
636 | unsigned long flags; | |
637 | ||
638 | spin_lock_irqsave(&lchip->lock, flags); | |
639 | locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); | |
640 | udelay(100); | |
641 | locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD); | |
642 | locomo_writel(bpwf | LCM_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); | |
643 | spin_unlock_irqrestore(&lchip->lock, flags); | |
644 | } | |
645 | ||
646 | ||
1da177e4 LT |
647 | /** |
648 | * locomo_probe - probe for a single LoCoMo chip. | |
649 | * @phys_addr: physical address of device. | |
650 | * | |
651 | * Probe for a LoCoMo chip. This must be called | |
652 | * before any other locomo-specific code. | |
653 | * | |
654 | * Returns: | |
655 | * %-ENODEV device not found. | |
656 | * %-EBUSY physical address already marked in-use. | |
657 | * %0 successful. | |
658 | */ | |
659 | static int | |
660 | __locomo_probe(struct device *me, struct resource *mem, int irq) | |
661 | { | |
662 | struct locomo *lchip; | |
663 | unsigned long r; | |
664 | int i, ret = -ENODEV; | |
665 | ||
d2a02b93 | 666 | lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL); |
1da177e4 LT |
667 | if (!lchip) |
668 | return -ENOMEM; | |
669 | ||
1da177e4 LT |
670 | spin_lock_init(&lchip->lock); |
671 | ||
672 | lchip->dev = me; | |
673 | dev_set_drvdata(lchip->dev, lchip); | |
674 | ||
675 | lchip->phys = mem->start; | |
676 | lchip->irq = irq; | |
677 | ||
678 | /* | |
679 | * Map the whole region. This also maps the | |
680 | * registers for our children. | |
681 | */ | |
682 | lchip->base = ioremap(mem->start, PAGE_SIZE); | |
683 | if (!lchip->base) { | |
684 | ret = -ENOMEM; | |
685 | goto out; | |
686 | } | |
687 | ||
688 | /* locomo initialize */ | |
689 | locomo_writel(0, lchip->base + LOCOMO_ICR); | |
690 | /* KEYBOARD */ | |
691 | locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); | |
692 | ||
693 | /* GPIO */ | |
694 | locomo_writel(0, lchip->base + LOCOMO_GPO); | |
695 | locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14)) | |
696 | , lchip->base + LOCOMO_GPE); | |
697 | locomo_writel( (LOCOMO_GPIO(2) | LOCOMO_GPIO(3) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14)) | |
698 | , lchip->base + LOCOMO_GPD); | |
699 | locomo_writel(0, lchip->base + LOCOMO_GIE); | |
700 | ||
701 | /* FrontLight */ | |
702 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); | |
703 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD); | |
4ebf2d00 PM |
704 | |
705 | /* Same constants can be used for collie and poodle | |
706 | (depending on CONFIG options in original sharp code)? */ | |
707 | frontlight_set(lchip, 163, 0, 148); | |
708 | ||
1da177e4 LT |
709 | /* Longtime timer */ |
710 | locomo_writel(0, lchip->base + LOCOMO_LTINT); | |
711 | /* SPI */ | |
712 | locomo_writel(0, lchip->base + LOCOMO_SPIIE); | |
713 | ||
714 | locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD); | |
715 | r = locomo_readl(lchip->base + LOCOMO_ASD); | |
716 | r |= 0x8000; | |
717 | locomo_writel(r, lchip->base + LOCOMO_ASD); | |
718 | ||
719 | locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD); | |
720 | r = locomo_readl(lchip->base + LOCOMO_HSD); | |
721 | r |= 0x8000; | |
722 | locomo_writel(r, lchip->base + LOCOMO_HSD); | |
723 | ||
724 | locomo_writel(128 / 8, lchip->base + LOCOMO_HSC); | |
725 | ||
726 | /* XON */ | |
727 | locomo_writel(0x80, lchip->base + LOCOMO_TADC); | |
728 | udelay(1000); | |
729 | /* CLK9MEN */ | |
730 | r = locomo_readl(lchip->base + LOCOMO_TADC); | |
731 | r |= 0x10; | |
732 | locomo_writel(r, lchip->base + LOCOMO_TADC); | |
733 | udelay(100); | |
734 | ||
735 | /* init DAC */ | |
736 | r = locomo_readl(lchip->base + LOCOMO_DAC); | |
737 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; | |
738 | locomo_writel(r, lchip->base + LOCOMO_DAC); | |
739 | ||
740 | r = locomo_readl(lchip->base + LOCOMO_VER); | |
741 | printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff)); | |
742 | ||
743 | /* | |
744 | * The interrupt controller must be initialised before any | |
745 | * other device to ensure that the interrupts are available. | |
746 | */ | |
747 | if (lchip->irq != NO_IRQ) | |
748 | locomo_setup_irq(lchip); | |
749 | ||
750 | for (i = 0; i < ARRAY_SIZE(locomo_devices); i++) | |
751 | locomo_init_one_child(lchip, &locomo_devices[i]); | |
752 | ||
753 | return 0; | |
754 | ||
755 | out: | |
756 | kfree(lchip); | |
757 | return ret; | |
758 | } | |
759 | ||
e24da5d3 | 760 | static int locomo_remove_child(struct device *dev, void *data) |
1da177e4 | 761 | { |
e24da5d3 PM |
762 | device_unregister(dev); |
763 | return 0; | |
764 | } | |
1da177e4 | 765 | |
e24da5d3 PM |
766 | static void __locomo_remove(struct locomo *lchip) |
767 | { | |
768 | device_for_each_child(lchip->dev, NULL, locomo_remove_child); | |
1da177e4 LT |
769 | |
770 | if (lchip->irq != NO_IRQ) { | |
771 | set_irq_chained_handler(lchip->irq, NULL); | |
772 | set_irq_data(lchip->irq, NULL); | |
773 | } | |
774 | ||
775 | iounmap(lchip->base); | |
776 | kfree(lchip); | |
777 | } | |
778 | ||
3ae5eaec | 779 | static int locomo_probe(struct platform_device *dev) |
1da177e4 | 780 | { |
1da177e4 LT |
781 | struct resource *mem; |
782 | int irq; | |
783 | ||
3ae5eaec | 784 | mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
1da177e4 LT |
785 | if (!mem) |
786 | return -EINVAL; | |
3ae5eaec | 787 | irq = platform_get_irq(dev, 0); |
48944738 DV |
788 | if (irq < 0) |
789 | return -ENXIO; | |
1da177e4 | 790 | |
3ae5eaec | 791 | return __locomo_probe(&dev->dev, mem, irq); |
1da177e4 LT |
792 | } |
793 | ||
3ae5eaec | 794 | static int locomo_remove(struct platform_device *dev) |
1da177e4 | 795 | { |
c35bf4a5 | 796 | struct locomo *lchip = platform_get_drvdata(dev); |
1da177e4 LT |
797 | |
798 | if (lchip) { | |
799 | __locomo_remove(lchip); | |
3ae5eaec | 800 | platform_set_drvdata(dev, NULL); |
1da177e4 LT |
801 | } |
802 | ||
803 | return 0; | |
804 | } | |
805 | ||
806 | /* | |
807 | * Not sure if this should be on the system bus or not yet. | |
808 | * We really want some way to register a system device at | |
809 | * the per-machine level, and then have this driver pick | |
810 | * up the registered devices. | |
811 | */ | |
3ae5eaec | 812 | static struct platform_driver locomo_device_driver = { |
1da177e4 LT |
813 | .probe = locomo_probe, |
814 | .remove = locomo_remove, | |
b38d950d JL |
815 | #ifdef CONFIG_PM |
816 | .suspend = locomo_suspend, | |
817 | .resume = locomo_resume, | |
818 | #endif | |
3ae5eaec RK |
819 | .driver = { |
820 | .name = "locomo", | |
821 | }, | |
1da177e4 LT |
822 | }; |
823 | ||
824 | /* | |
825 | * Get the parent device driver (us) structure | |
826 | * from a child function device | |
827 | */ | |
828 | static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev) | |
829 | { | |
830 | return (struct locomo *)dev_get_drvdata(ldev->dev.parent); | |
831 | } | |
832 | ||
833 | void locomo_gpio_set_dir(struct locomo_dev *ldev, unsigned int bits, unsigned int dir) | |
834 | { | |
835 | struct locomo *lchip = locomo_chip_driver(ldev); | |
836 | unsigned long flags; | |
837 | unsigned int r; | |
838 | ||
839 | spin_lock_irqsave(&lchip->lock, flags); | |
840 | ||
841 | r = locomo_readl(lchip->base + LOCOMO_GPD); | |
842 | r &= ~bits; | |
843 | locomo_writel(r, lchip->base + LOCOMO_GPD); | |
844 | ||
845 | r = locomo_readl(lchip->base + LOCOMO_GPE); | |
846 | if (dir) | |
847 | r |= bits; | |
848 | else | |
849 | r &= ~bits; | |
850 | locomo_writel(r, lchip->base + LOCOMO_GPE); | |
851 | ||
852 | spin_unlock_irqrestore(&lchip->lock, flags); | |
853 | } | |
854 | ||
855 | unsigned int locomo_gpio_read_level(struct locomo_dev *ldev, unsigned int bits) | |
856 | { | |
857 | struct locomo *lchip = locomo_chip_driver(ldev); | |
858 | unsigned long flags; | |
859 | unsigned int ret; | |
860 | ||
861 | spin_lock_irqsave(&lchip->lock, flags); | |
862 | ret = locomo_readl(lchip->base + LOCOMO_GPL); | |
863 | spin_unlock_irqrestore(&lchip->lock, flags); | |
864 | ||
865 | ret &= bits; | |
866 | return ret; | |
867 | } | |
868 | ||
869 | unsigned int locomo_gpio_read_output(struct locomo_dev *ldev, unsigned int bits) | |
870 | { | |
871 | struct locomo *lchip = locomo_chip_driver(ldev); | |
872 | unsigned long flags; | |
873 | unsigned int ret; | |
874 | ||
875 | spin_lock_irqsave(&lchip->lock, flags); | |
876 | ret = locomo_readl(lchip->base + LOCOMO_GPO); | |
877 | spin_unlock_irqrestore(&lchip->lock, flags); | |
878 | ||
879 | ret &= bits; | |
880 | return ret; | |
881 | } | |
882 | ||
883 | void locomo_gpio_write(struct locomo_dev *ldev, unsigned int bits, unsigned int set) | |
884 | { | |
885 | struct locomo *lchip = locomo_chip_driver(ldev); | |
886 | unsigned long flags; | |
887 | unsigned int r; | |
888 | ||
889 | spin_lock_irqsave(&lchip->lock, flags); | |
890 | ||
891 | r = locomo_readl(lchip->base + LOCOMO_GPO); | |
892 | if (set) | |
893 | r |= bits; | |
894 | else | |
895 | r &= ~bits; | |
896 | locomo_writel(r, lchip->base + LOCOMO_GPO); | |
897 | ||
898 | spin_unlock_irqrestore(&lchip->lock, flags); | |
899 | } | |
900 | ||
901 | static void locomo_m62332_sendbit(void *mapbase, int bit) | |
902 | { | |
903 | unsigned int r; | |
904 | ||
905 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
906 | r &= ~(LOCOMO_DAC_SCLOEB); | |
907 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
908 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
909 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ | |
910 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
911 | r &= ~(LOCOMO_DAC_SCLOEB); | |
912 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
913 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
914 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | |
915 | ||
916 | if (bit & 1) { | |
917 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
918 | r |= LOCOMO_DAC_SDAOEB; | |
919 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
920 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
921 | } else { | |
922 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
923 | r &= ~(LOCOMO_DAC_SDAOEB); | |
924 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
925 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
926 | } | |
927 | ||
928 | udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */ | |
929 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
930 | r |= LOCOMO_DAC_SCLOEB; | |
931 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
932 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
933 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ | |
934 | } | |
935 | ||
936 | void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel) | |
937 | { | |
938 | struct locomo *lchip = locomo_chip_driver(ldev); | |
939 | int i; | |
940 | unsigned char data; | |
941 | unsigned int r; | |
942 | void *mapbase = lchip->base; | |
943 | unsigned long flags; | |
944 | ||
945 | spin_lock_irqsave(&lchip->lock, flags); | |
946 | ||
947 | /* Start */ | |
948 | udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */ | |
949 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
950 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; | |
951 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
952 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
953 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ | |
954 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
955 | r &= ~(LOCOMO_DAC_SDAOEB); | |
956 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
957 | udelay(DAC_START_HOLD_TIME); /* 5.0 usec */ | |
958 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ | |
959 | ||
960 | /* Send slave address and W bit (LSB is W bit) */ | |
961 | data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT; | |
962 | for (i = 1; i <= 8; i++) { | |
963 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); | |
964 | } | |
965 | ||
966 | /* Check A bit */ | |
967 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
968 | r &= ~(LOCOMO_DAC_SCLOEB); | |
969 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
970 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
971 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | |
972 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
973 | r &= ~(LOCOMO_DAC_SDAOEB); | |
974 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
975 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
976 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
977 | r |= LOCOMO_DAC_SCLOEB; | |
978 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
979 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
980 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ | |
981 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ | |
982 | printk(KERN_WARNING "locomo: m62332_senddata Error 1\n"); | |
983 | return; | |
984 | } | |
985 | ||
986 | /* Send Sub address (LSB is channel select) */ | |
987 | /* channel = 0 : ch1 select */ | |
988 | /* = 1 : ch2 select */ | |
989 | data = M62332_SUB_ADDR + channel; | |
990 | for (i = 1; i <= 8; i++) { | |
991 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); | |
992 | } | |
993 | ||
994 | /* Check A bit */ | |
995 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
996 | r &= ~(LOCOMO_DAC_SCLOEB); | |
997 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
998 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
999 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | |
1000 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1001 | r &= ~(LOCOMO_DAC_SDAOEB); | |
1002 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1003 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
1004 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1005 | r |= LOCOMO_DAC_SCLOEB; | |
1006 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1007 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
1008 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ | |
1009 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ | |
1010 | printk(KERN_WARNING "locomo: m62332_senddata Error 2\n"); | |
1011 | return; | |
1012 | } | |
1013 | ||
1014 | /* Send DAC data */ | |
1015 | for (i = 1; i <= 8; i++) { | |
1016 | locomo_m62332_sendbit(mapbase, dac_data >> (8 - i)); | |
1017 | } | |
1018 | ||
1019 | /* Check A bit */ | |
1020 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1021 | r &= ~(LOCOMO_DAC_SCLOEB); | |
1022 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1023 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
1024 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | |
1025 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1026 | r &= ~(LOCOMO_DAC_SDAOEB); | |
1027 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1028 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
1029 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1030 | r |= LOCOMO_DAC_SCLOEB; | |
1031 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1032 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
1033 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ | |
1034 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ | |
1035 | printk(KERN_WARNING "locomo: m62332_senddata Error 3\n"); | |
1036 | return; | |
1037 | } | |
1038 | ||
1039 | /* stop */ | |
1040 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1041 | r &= ~(LOCOMO_DAC_SCLOEB); | |
1042 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1043 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ | |
1044 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | |
1045 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1046 | r |= LOCOMO_DAC_SCLOEB; | |
1047 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1048 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
1049 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ | |
1050 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1051 | r |= LOCOMO_DAC_SDAOEB; | |
1052 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1053 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ | |
1054 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ | |
1055 | ||
1056 | r = locomo_readl(mapbase + LOCOMO_DAC); | |
1057 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; | |
1058 | locomo_writel(r, mapbase + LOCOMO_DAC); | |
1059 | udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */ | |
1060 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ | |
1061 | ||
1062 | spin_unlock_irqrestore(&lchip->lock, flags); | |
1063 | } | |
1064 | ||
1065 | /* | |
1066 | * LoCoMo "Register Access Bus." | |
1067 | * | |
1068 | * We model this as a regular bus type, and hang devices directly | |
1069 | * off this. | |
1070 | */ | |
1071 | static int locomo_match(struct device *_dev, struct device_driver *_drv) | |
1072 | { | |
1073 | struct locomo_dev *dev = LOCOMO_DEV(_dev); | |
1074 | struct locomo_driver *drv = LOCOMO_DRV(_drv); | |
1075 | ||
1076 | return dev->devid == drv->devid; | |
1077 | } | |
1078 | ||
1079 | static int locomo_bus_suspend(struct device *dev, pm_message_t state) | |
1080 | { | |
1081 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | |
1082 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | |
1083 | int ret = 0; | |
1084 | ||
1085 | if (drv && drv->suspend) | |
1086 | ret = drv->suspend(ldev, state); | |
1087 | return ret; | |
1088 | } | |
1089 | ||
1090 | static int locomo_bus_resume(struct device *dev) | |
1091 | { | |
1092 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | |
1093 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | |
1094 | int ret = 0; | |
1095 | ||
1096 | if (drv && drv->resume) | |
1097 | ret = drv->resume(ldev); | |
1098 | return ret; | |
1099 | } | |
1100 | ||
1101 | static int locomo_bus_probe(struct device *dev) | |
1102 | { | |
1103 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | |
1104 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | |
1105 | int ret = -ENODEV; | |
1106 | ||
1107 | if (drv->probe) | |
1108 | ret = drv->probe(ldev); | |
1109 | return ret; | |
1110 | } | |
1111 | ||
1112 | static int locomo_bus_remove(struct device *dev) | |
1113 | { | |
1114 | struct locomo_dev *ldev = LOCOMO_DEV(dev); | |
1115 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); | |
1116 | int ret = 0; | |
1117 | ||
1118 | if (drv->remove) | |
1119 | ret = drv->remove(ldev); | |
1120 | return ret; | |
1121 | } | |
1122 | ||
1123 | struct bus_type locomo_bus_type = { | |
1124 | .name = "locomo-bus", | |
1125 | .match = locomo_match, | |
306955be RK |
1126 | .probe = locomo_bus_probe, |
1127 | .remove = locomo_bus_remove, | |
1da177e4 LT |
1128 | .suspend = locomo_bus_suspend, |
1129 | .resume = locomo_bus_resume, | |
1130 | }; | |
1131 | ||
1132 | int locomo_driver_register(struct locomo_driver *driver) | |
1133 | { | |
1da177e4 LT |
1134 | driver->drv.bus = &locomo_bus_type; |
1135 | return driver_register(&driver->drv); | |
1136 | } | |
1137 | ||
1138 | void locomo_driver_unregister(struct locomo_driver *driver) | |
1139 | { | |
1140 | driver_unregister(&driver->drv); | |
1141 | } | |
1142 | ||
1143 | static int __init locomo_init(void) | |
1144 | { | |
1145 | int ret = bus_register(&locomo_bus_type); | |
1146 | if (ret == 0) | |
3ae5eaec | 1147 | platform_driver_register(&locomo_device_driver); |
1da177e4 LT |
1148 | return ret; |
1149 | } | |
1150 | ||
1151 | static void __exit locomo_exit(void) | |
1152 | { | |
3ae5eaec | 1153 | platform_driver_unregister(&locomo_device_driver); |
1da177e4 LT |
1154 | bus_unregister(&locomo_bus_type); |
1155 | } | |
1156 | ||
1157 | module_init(locomo_init); | |
1158 | module_exit(locomo_exit); | |
1159 | ||
1160 | MODULE_DESCRIPTION("Sharp LoCoMo core driver"); | |
1161 | MODULE_LICENSE("GPL"); | |
1162 | MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); | |
1163 | ||
1164 | EXPORT_SYMBOL(locomo_driver_register); | |
1165 | EXPORT_SYMBOL(locomo_driver_unregister); | |
1166 | EXPORT_SYMBOL(locomo_gpio_set_dir); | |
1167 | EXPORT_SYMBOL(locomo_gpio_read_level); | |
1168 | EXPORT_SYMBOL(locomo_gpio_read_output); | |
1169 | EXPORT_SYMBOL(locomo_gpio_write); | |
1170 | EXPORT_SYMBOL(locomo_m62332_senddata); |