Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/ioport.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/slab.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame^] | 28 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/io.h> |
| 30 | #include <asm/irq.h> |
| 31 | #include <asm/mach/irq.h> |
| 32 | |
| 33 | #include <asm/hardware/locomo.h> |
| 34 | |
| 35 | /* M62332 output channel selection */ |
| 36 | #define M62332_EVR_CH 1 /* M62332 volume channel number */ |
| 37 | /* 0 : CH.1 , 1 : CH. 2 */ |
| 38 | /* DAC send data */ |
| 39 | #define M62332_SLAVE_ADDR 0x4e /* Slave address */ |
| 40 | #define M62332_W_BIT 0x00 /* W bit (0 only) */ |
| 41 | #define M62332_SUB_ADDR 0x00 /* Sub address */ |
| 42 | #define M62332_A_BIT 0x00 /* A bit (0 only) */ |
| 43 | |
| 44 | /* DAC setup and hold times (expressed in us) */ |
| 45 | #define DAC_BUS_FREE_TIME 5 /* 4.7 us */ |
| 46 | #define DAC_START_SETUP_TIME 5 /* 4.7 us */ |
| 47 | #define DAC_STOP_SETUP_TIME 4 /* 4.0 us */ |
| 48 | #define DAC_START_HOLD_TIME 5 /* 4.7 us */ |
| 49 | #define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */ |
| 50 | #define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */ |
| 51 | #define DAC_DATA_SETUP_TIME 1 /* 250 ns */ |
| 52 | #define DAC_DATA_HOLD_TIME 1 /* 300 ns */ |
| 53 | #define DAC_LOW_SETUP_TIME 1 /* 300 ns */ |
| 54 | #define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */ |
| 55 | |
| 56 | /* the following is the overall data for the locomo chip */ |
| 57 | struct locomo { |
| 58 | struct device *dev; |
| 59 | unsigned long phys; |
| 60 | unsigned int irq; |
| 61 | spinlock_t lock; |
Russell King | 5481536 | 2006-03-15 15:43:04 +0000 | [diff] [blame] | 62 | void __iomem *base; |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 63 | #ifdef CONFIG_PM |
| 64 | void *saved_state; |
| 65 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | struct locomo_dev_info { |
| 69 | unsigned long offset; |
| 70 | unsigned long length; |
| 71 | unsigned int devid; |
| 72 | unsigned int irq[1]; |
| 73 | const char * name; |
| 74 | }; |
| 75 | |
| 76 | /* All the locomo devices. If offset is non-zero, the mapbase for the |
| 77 | * locomo_dev will be set to the chip base plus offset. If offset is |
| 78 | * zero, then the mapbase for the locomo_dev will be set to zero. An |
| 79 | * offset of zero means the device only uses GPIOs or other helper |
| 80 | * functions inside this file */ |
| 81 | static struct locomo_dev_info locomo_devices[] = { |
| 82 | { |
| 83 | .devid = LOCOMO_DEVID_KEYBOARD, |
| 84 | .irq = { |
| 85 | IRQ_LOCOMO_KEY, |
| 86 | }, |
| 87 | .name = "locomo-keyboard", |
| 88 | .offset = LOCOMO_KEYBOARD, |
| 89 | .length = 16, |
| 90 | }, |
| 91 | { |
| 92 | .devid = LOCOMO_DEVID_FRONTLIGHT, |
| 93 | .irq = {}, |
| 94 | .name = "locomo-frontlight", |
| 95 | .offset = LOCOMO_FRONTLIGHT, |
| 96 | .length = 8, |
| 97 | |
| 98 | }, |
| 99 | { |
| 100 | .devid = LOCOMO_DEVID_BACKLIGHT, |
| 101 | .irq = {}, |
| 102 | .name = "locomo-backlight", |
| 103 | .offset = LOCOMO_BACKLIGHT, |
| 104 | .length = 8, |
| 105 | }, |
| 106 | { |
| 107 | .devid = LOCOMO_DEVID_AUDIO, |
| 108 | .irq = {}, |
| 109 | .name = "locomo-audio", |
| 110 | .offset = LOCOMO_AUDIO, |
| 111 | .length = 4, |
| 112 | }, |
| 113 | { |
| 114 | .devid = LOCOMO_DEVID_LED, |
| 115 | .irq = {}, |
| 116 | .name = "locomo-led", |
| 117 | .offset = LOCOMO_LED, |
| 118 | .length = 8, |
| 119 | }, |
| 120 | { |
| 121 | .devid = LOCOMO_DEVID_UART, |
| 122 | .irq = {}, |
| 123 | .name = "locomo-uart", |
| 124 | .offset = 0, |
| 125 | .length = 0, |
| 126 | }, |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 127 | { |
| 128 | .devid = LOCOMO_DEVID_SPI, |
| 129 | .irq = {}, |
| 130 | .name = "locomo-spi", |
| 131 | .offset = LOCOMO_SPI, |
| 132 | .length = 0x30, |
| 133 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | |
| 137 | /** LoCoMo interrupt handling stuff. |
| 138 | * NOTE: LoCoMo has a 1 to many mapping on all of its IRQs. |
| 139 | * that is, there is only one real hardware interrupt |
| 140 | * we determine which interrupt it is by reading some IO memory. |
| 141 | * We have two levels of expansion, first in the handler for the |
| 142 | * hardware interrupt we generate an interrupt |
| 143 | * IRQ_LOCOMO_*_BASE and those handlers generate more interrupts |
| 144 | * |
| 145 | * hardware irq reads LOCOMO_ICR & 0x0f00 |
| 146 | * IRQ_LOCOMO_KEY_BASE |
| 147 | * IRQ_LOCOMO_GPIO_BASE |
| 148 | * IRQ_LOCOMO_LT_BASE |
| 149 | * IRQ_LOCOMO_SPI_BASE |
| 150 | * IRQ_LOCOMO_KEY_BASE reads LOCOMO_KIC & 0x0001 |
| 151 | * IRQ_LOCOMO_KEY |
| 152 | * IRQ_LOCOMO_GPIO_BASE reads LOCOMO_GIR & LOCOMO_GPD & 0xffff |
| 153 | * IRQ_LOCOMO_GPIO[0-15] |
| 154 | * IRQ_LOCOMO_LT_BASE reads LOCOMO_LTINT & 0x0001 |
| 155 | * IRQ_LOCOMO_LT |
| 156 | * IRQ_LOCOMO_SPI_BASE reads LOCOMO_SPIIR & 0x000F |
| 157 | * IRQ_LOCOMO_SPI_RFR |
| 158 | * IRQ_LOCOMO_SPI_RFW |
| 159 | * IRQ_LOCOMO_SPI_OVRN |
| 160 | * IRQ_LOCOMO_SPI_TEND |
| 161 | */ |
| 162 | |
| 163 | #define LOCOMO_IRQ_START (IRQ_LOCOMO_KEY_BASE) |
| 164 | #define LOCOMO_IRQ_KEY_START (IRQ_LOCOMO_KEY) |
| 165 | #define LOCOMO_IRQ_GPIO_START (IRQ_LOCOMO_GPIO0) |
| 166 | #define LOCOMO_IRQ_LT_START (IRQ_LOCOMO_LT) |
| 167 | #define LOCOMO_IRQ_SPI_START (IRQ_LOCOMO_SPI_RFR) |
| 168 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 169 | static void locomo_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | int req, i; |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 172 | struct irq_desc *d; |
| 173 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | /* Acknowledge the parent IRQ */ |
| 176 | desc->chip->ack(irq); |
| 177 | |
| 178 | /* check why this interrupt was generated */ |
| 179 | req = locomo_readl(mapbase + LOCOMO_ICR) & 0x0f00; |
| 180 | |
| 181 | if (req) { |
| 182 | /* generate the next interrupt(s) */ |
| 183 | irq = LOCOMO_IRQ_START; |
| 184 | d = irq_desc + irq; |
| 185 | for (i = 0; i <= 3; i++, d++, irq++) { |
| 186 | if (req & (0x0100 << i)) { |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 187 | desc_handle_irq(irq, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | static void locomo_ack_irq(unsigned int irq) |
| 195 | { |
| 196 | } |
| 197 | |
| 198 | static void locomo_mask_irq(unsigned int irq) |
| 199 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 200 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | unsigned int r; |
| 202 | r = locomo_readl(mapbase + LOCOMO_ICR); |
| 203 | r &= ~(0x0010 << (irq - LOCOMO_IRQ_START)); |
| 204 | locomo_writel(r, mapbase + LOCOMO_ICR); |
| 205 | } |
| 206 | |
| 207 | static void locomo_unmask_irq(unsigned int irq) |
| 208 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 209 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | unsigned int r; |
| 211 | r = locomo_readl(mapbase + LOCOMO_ICR); |
| 212 | r |= (0x0010 << (irq - LOCOMO_IRQ_START)); |
| 213 | locomo_writel(r, mapbase + LOCOMO_ICR); |
| 214 | } |
| 215 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 216 | static struct irq_chip locomo_chip = { |
| 217 | .name = "LOCOMO", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | .ack = locomo_ack_irq, |
| 219 | .mask = locomo_mask_irq, |
| 220 | .unmask = locomo_unmask_irq, |
| 221 | }; |
| 222 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 223 | static void locomo_key_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 225 | struct irq_desc *d; |
| 226 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | if (locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC) & 0x0001) { |
| 229 | d = irq_desc + LOCOMO_IRQ_KEY_START; |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 230 | desc_handle_irq(LOCOMO_IRQ_KEY_START, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
| 234 | static void locomo_key_ack_irq(unsigned int irq) |
| 235 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 236 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | unsigned int r; |
| 238 | r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 239 | r &= ~(0x0100 << (irq - LOCOMO_IRQ_KEY_START)); |
| 240 | locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 241 | } |
| 242 | |
| 243 | static void locomo_key_mask_irq(unsigned int irq) |
| 244 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 245 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | unsigned int r; |
| 247 | r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 248 | r &= ~(0x0010 << (irq - LOCOMO_IRQ_KEY_START)); |
| 249 | locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 250 | } |
| 251 | |
| 252 | static void locomo_key_unmask_irq(unsigned int irq) |
| 253 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 254 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | unsigned int r; |
| 256 | r = locomo_readl(mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 257 | r |= (0x0010 << (irq - LOCOMO_IRQ_KEY_START)); |
| 258 | locomo_writel(r, mapbase + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 259 | } |
| 260 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 261 | static struct irq_chip locomo_key_chip = { |
| 262 | .name = "LOCOMO-key", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | .ack = locomo_key_ack_irq, |
| 264 | .mask = locomo_key_mask_irq, |
| 265 | .unmask = locomo_key_unmask_irq, |
| 266 | }; |
| 267 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 268 | static void locomo_gpio_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
| 270 | int req, i; |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 271 | struct irq_desc *d; |
| 272 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | req = locomo_readl(mapbase + LOCOMO_GIR) & |
| 275 | locomo_readl(mapbase + LOCOMO_GPD) & |
| 276 | 0xffff; |
| 277 | |
| 278 | if (req) { |
| 279 | irq = LOCOMO_IRQ_GPIO_START; |
| 280 | d = irq_desc + LOCOMO_IRQ_GPIO_START; |
| 281 | for (i = 0; i <= 15; i++, irq++, d++) { |
| 282 | if (req & (0x0001 << i)) { |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 283 | desc_handle_irq(irq, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | static void locomo_gpio_ack_irq(unsigned int irq) |
| 290 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 291 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | unsigned int r; |
| 293 | r = locomo_readl(mapbase + LOCOMO_GWE); |
| 294 | r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); |
| 295 | locomo_writel(r, mapbase + LOCOMO_GWE); |
| 296 | |
| 297 | r = locomo_readl(mapbase + LOCOMO_GIS); |
| 298 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); |
| 299 | locomo_writel(r, mapbase + LOCOMO_GIS); |
| 300 | |
| 301 | r = locomo_readl(mapbase + LOCOMO_GWE); |
| 302 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); |
| 303 | locomo_writel(r, mapbase + LOCOMO_GWE); |
| 304 | } |
| 305 | |
| 306 | static void locomo_gpio_mask_irq(unsigned int irq) |
| 307 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 308 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | unsigned int r; |
| 310 | r = locomo_readl(mapbase + LOCOMO_GIE); |
| 311 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); |
| 312 | locomo_writel(r, mapbase + LOCOMO_GIE); |
| 313 | } |
| 314 | |
| 315 | static void locomo_gpio_unmask_irq(unsigned int irq) |
| 316 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 317 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | unsigned int r; |
| 319 | r = locomo_readl(mapbase + LOCOMO_GIE); |
| 320 | r |= (0x0001 << (irq - LOCOMO_IRQ_GPIO_START)); |
| 321 | locomo_writel(r, mapbase + LOCOMO_GIE); |
| 322 | } |
| 323 | |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 324 | static int GPIO_IRQ_rising_edge; |
| 325 | static int GPIO_IRQ_falling_edge; |
| 326 | |
| 327 | static int locomo_gpio_type(unsigned int irq, unsigned int type) |
| 328 | { |
| 329 | unsigned int mask; |
| 330 | void __iomem *mapbase = get_irq_chip_data(irq); |
| 331 | |
| 332 | mask = 1 << (irq - LOCOMO_IRQ_GPIO_START); |
| 333 | |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 334 | if (type == IRQ_TYPE_PROBE) { |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 335 | if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask) |
| 336 | return 0; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 337 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 338 | } |
| 339 | |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 340 | if (type & IRQ_TYPE_EDGE_RISING) |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 341 | GPIO_IRQ_rising_edge |= mask; |
| 342 | else |
| 343 | GPIO_IRQ_rising_edge &= ~mask; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 344 | if (type & IRQ_TYPE_EDGE_FALLING) |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 345 | GPIO_IRQ_falling_edge |= mask; |
| 346 | else |
| 347 | GPIO_IRQ_falling_edge &= ~mask; |
| 348 | locomo_writel(GPIO_IRQ_rising_edge, mapbase + LOCOMO_GRIE); |
| 349 | locomo_writel(GPIO_IRQ_falling_edge, mapbase + LOCOMO_GFIE); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 354 | static struct irq_chip locomo_gpio_chip = { |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 355 | .name = "LOCOMO-gpio", |
| 356 | .ack = locomo_gpio_ack_irq, |
| 357 | .mask = locomo_gpio_mask_irq, |
| 358 | .unmask = locomo_gpio_unmask_irq, |
| 359 | .set_type = locomo_gpio_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | }; |
| 361 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 362 | static void locomo_lt_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 364 | struct irq_desc *d; |
| 365 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | if (locomo_readl(mapbase + LOCOMO_LTINT) & 0x0001) { |
| 368 | d = irq_desc + LOCOMO_IRQ_LT_START; |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 369 | desc_handle_irq(LOCOMO_IRQ_LT_START, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | |
| 373 | static void locomo_lt_ack_irq(unsigned int irq) |
| 374 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 375 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | unsigned int r; |
| 377 | r = locomo_readl(mapbase + LOCOMO_LTINT); |
| 378 | r &= ~(0x0100 << (irq - LOCOMO_IRQ_LT_START)); |
| 379 | locomo_writel(r, mapbase + LOCOMO_LTINT); |
| 380 | } |
| 381 | |
| 382 | static void locomo_lt_mask_irq(unsigned int irq) |
| 383 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 384 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | unsigned int r; |
| 386 | r = locomo_readl(mapbase + LOCOMO_LTINT); |
| 387 | r &= ~(0x0010 << (irq - LOCOMO_IRQ_LT_START)); |
| 388 | locomo_writel(r, mapbase + LOCOMO_LTINT); |
| 389 | } |
| 390 | |
| 391 | static void locomo_lt_unmask_irq(unsigned int irq) |
| 392 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 393 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | unsigned int r; |
| 395 | r = locomo_readl(mapbase + LOCOMO_LTINT); |
| 396 | r |= (0x0010 << (irq - LOCOMO_IRQ_LT_START)); |
| 397 | locomo_writel(r, mapbase + LOCOMO_LTINT); |
| 398 | } |
| 399 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 400 | static struct irq_chip locomo_lt_chip = { |
| 401 | .name = "LOCOMO-lt", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | .ack = locomo_lt_ack_irq, |
| 403 | .mask = locomo_lt_mask_irq, |
| 404 | .unmask = locomo_lt_unmask_irq, |
| 405 | }; |
| 406 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 407 | static void locomo_spi_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
| 409 | int req, i; |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 410 | struct irq_desc *d; |
| 411 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 413 | req = locomo_readl(mapbase + LOCOMO_SPI + LOCOMO_SPIIR) & 0x000F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | if (req) { |
| 415 | irq = LOCOMO_IRQ_SPI_START; |
| 416 | d = irq_desc + irq; |
| 417 | |
| 418 | for (i = 0; i <= 3; i++, irq++, d++) { |
| 419 | if (req & (0x0001 << i)) { |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 420 | desc_handle_irq(irq, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | static void locomo_spi_ack_irq(unsigned int irq) |
| 427 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 428 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | unsigned int r; |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 430 | r = locomo_readl(mapbase + LOCOMO_SPI + LOCOMO_SPIWE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START)); |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 432 | locomo_writel(r, mapbase + LOCOMO_SPI + LOCOMO_SPIWE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 434 | r = locomo_readl(mapbase + LOCOMO_SPI + LOCOMO_SPIIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START)); |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 436 | locomo_writel(r, mapbase + LOCOMO_SPI + LOCOMO_SPIIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 438 | r = locomo_readl(mapbase + LOCOMO_SPI + LOCOMO_SPIWE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START)); |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 440 | locomo_writel(r, mapbase + LOCOMO_SPI + LOCOMO_SPIWE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static void locomo_spi_mask_irq(unsigned int irq) |
| 444 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 445 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | unsigned int r; |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 447 | r = locomo_readl(mapbase + LOCOMO_SPI + LOCOMO_SPIIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | r &= ~(0x0001 << (irq - LOCOMO_IRQ_SPI_START)); |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 449 | locomo_writel(r, mapbase + LOCOMO_SPI + LOCOMO_SPIIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void locomo_spi_unmask_irq(unsigned int irq) |
| 453 | { |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 454 | void __iomem *mapbase = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | unsigned int r; |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 456 | r = locomo_readl(mapbase + LOCOMO_SPI + LOCOMO_SPIIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | r |= (0x0001 << (irq - LOCOMO_IRQ_SPI_START)); |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 458 | locomo_writel(r, mapbase + LOCOMO_SPI + LOCOMO_SPIIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 461 | static struct irq_chip locomo_spi_chip = { |
| 462 | .name = "LOCOMO-spi", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | .ack = locomo_spi_ack_irq, |
| 464 | .mask = locomo_spi_mask_irq, |
| 465 | .unmask = locomo_spi_unmask_irq, |
| 466 | }; |
| 467 | |
| 468 | static void locomo_setup_irq(struct locomo *lchip) |
| 469 | { |
| 470 | int irq; |
Russell King | 5481536 | 2006-03-15 15:43:04 +0000 | [diff] [blame] | 471 | void __iomem *irqbase = lchip->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * Install handler for IRQ_LOCOMO_HW. |
| 475 | */ |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 476 | set_irq_type(lchip->irq, IRQ_TYPE_EDGE_FALLING); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 477 | set_irq_chip_data(lchip->irq, irqbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | set_irq_chained_handler(lchip->irq, locomo_handler); |
| 479 | |
| 480 | /* Install handlers for IRQ_LOCOMO_*_BASE */ |
| 481 | set_irq_chip(IRQ_LOCOMO_KEY_BASE, &locomo_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 482 | set_irq_chip_data(IRQ_LOCOMO_KEY_BASE, irqbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | set_irq_chained_handler(IRQ_LOCOMO_KEY_BASE, locomo_key_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | set_irq_chip(IRQ_LOCOMO_GPIO_BASE, &locomo_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 486 | set_irq_chip_data(IRQ_LOCOMO_GPIO_BASE, irqbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | set_irq_chained_handler(IRQ_LOCOMO_GPIO_BASE, locomo_gpio_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | set_irq_chip(IRQ_LOCOMO_LT_BASE, &locomo_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 490 | set_irq_chip_data(IRQ_LOCOMO_LT_BASE, irqbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | set_irq_chained_handler(IRQ_LOCOMO_LT_BASE, locomo_lt_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | set_irq_chip(IRQ_LOCOMO_SPI_BASE, &locomo_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 494 | set_irq_chip_data(IRQ_LOCOMO_SPI_BASE, irqbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | set_irq_chained_handler(IRQ_LOCOMO_SPI_BASE, locomo_spi_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | /* install handlers for IRQ_LOCOMO_KEY_BASE generated interrupts */ |
| 498 | set_irq_chip(LOCOMO_IRQ_KEY_START, &locomo_key_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 499 | set_irq_chip_data(LOCOMO_IRQ_KEY_START, irqbase); |
| 500 | set_irq_handler(LOCOMO_IRQ_KEY_START, handle_edge_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | set_irq_flags(LOCOMO_IRQ_KEY_START, IRQF_VALID | IRQF_PROBE); |
| 502 | |
| 503 | /* install handlers for IRQ_LOCOMO_GPIO_BASE generated interrupts */ |
| 504 | for (irq = LOCOMO_IRQ_GPIO_START; irq < LOCOMO_IRQ_GPIO_START + 16; irq++) { |
| 505 | set_irq_chip(irq, &locomo_gpio_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 506 | set_irq_chip_data(irq, irqbase); |
| 507 | set_irq_handler(irq, handle_edge_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 509 | } |
| 510 | |
| 511 | /* install handlers for IRQ_LOCOMO_LT_BASE generated interrupts */ |
| 512 | set_irq_chip(LOCOMO_IRQ_LT_START, &locomo_lt_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 513 | set_irq_chip_data(LOCOMO_IRQ_LT_START, irqbase); |
| 514 | set_irq_handler(LOCOMO_IRQ_LT_START, handle_edge_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | set_irq_flags(LOCOMO_IRQ_LT_START, IRQF_VALID | IRQF_PROBE); |
| 516 | |
| 517 | /* install handlers for IRQ_LOCOMO_SPI_BASE generated interrupts */ |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 518 | for (irq = LOCOMO_IRQ_SPI_START; irq < LOCOMO_IRQ_SPI_START + 4; irq++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | set_irq_chip(irq, &locomo_spi_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 520 | set_irq_chip_data(irq, irqbase); |
| 521 | set_irq_handler(irq, handle_edge_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | |
| 527 | static void locomo_dev_release(struct device *_dev) |
| 528 | { |
| 529 | struct locomo_dev *dev = LOCOMO_DEV(_dev); |
| 530 | |
| 531 | kfree(dev); |
| 532 | } |
| 533 | |
| 534 | static int |
| 535 | locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info) |
| 536 | { |
| 537 | struct locomo_dev *dev; |
| 538 | int ret; |
| 539 | |
Russell King | d2a02b9 | 2006-03-20 19:46:41 +0000 | [diff] [blame] | 540 | dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | if (!dev) { |
| 542 | ret = -ENOMEM; |
| 543 | goto out; |
| 544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | /* |
| 547 | * If the parent device has a DMA mask associated with it, |
| 548 | * propagate it down to the children. |
| 549 | */ |
| 550 | if (lchip->dev->dma_mask) { |
| 551 | dev->dma_mask = *lchip->dev->dma_mask; |
| 552 | dev->dev.dma_mask = &dev->dma_mask; |
| 553 | } |
| 554 | |
Kay Sievers | 3f97870 | 2008-05-30 17:42:11 +0200 | [diff] [blame] | 555 | dev_set_name(&dev->dev, "%s", info->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | dev->devid = info->devid; |
| 557 | dev->dev.parent = lchip->dev; |
| 558 | dev->dev.bus = &locomo_bus_type; |
| 559 | dev->dev.release = locomo_dev_release; |
| 560 | dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask; |
| 561 | |
| 562 | if (info->offset) |
| 563 | dev->mapbase = lchip->base + info->offset; |
| 564 | else |
| 565 | dev->mapbase = 0; |
| 566 | dev->length = info->length; |
| 567 | |
| 568 | memmove(dev->irq, info->irq, sizeof(dev->irq)); |
| 569 | |
| 570 | ret = device_register(&dev->dev); |
| 571 | if (ret) { |
| 572 | out: |
| 573 | kfree(dev); |
| 574 | } |
| 575 | return ret; |
| 576 | } |
| 577 | |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 578 | #ifdef CONFIG_PM |
| 579 | |
| 580 | struct locomo_save_data { |
| 581 | u16 LCM_GPO; |
| 582 | u16 LCM_SPICT; |
| 583 | u16 LCM_GPE; |
| 584 | u16 LCM_ASD; |
| 585 | u16 LCM_SPIMD; |
| 586 | }; |
| 587 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 588 | static int locomo_suspend(struct platform_device *dev, pm_message_t state) |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 589 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 590 | struct locomo *lchip = platform_get_drvdata(dev); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 591 | struct locomo_save_data *save; |
| 592 | unsigned long flags; |
| 593 | |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 594 | save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL); |
| 595 | if (!save) |
| 596 | return -ENOMEM; |
| 597 | |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 598 | lchip->saved_state = save; |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 599 | |
| 600 | spin_lock_irqsave(&lchip->lock, flags); |
| 601 | |
| 602 | save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */ |
| 603 | locomo_writel(0x00, lchip->base + LOCOMO_GPO); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 604 | save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPICT); /* SPI */ |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 605 | locomo_writel(0x40, lchip->base + LOCOMO_SPICT); |
| 606 | save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */ |
| 607 | locomo_writel(0x00, lchip->base + LOCOMO_GPE); |
| 608 | save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */ |
| 609 | locomo_writel(0x00, lchip->base + LOCOMO_ASD); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 610 | save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPIMD); /* SPI */ |
| 611 | locomo_writel(0x3C14, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 612 | |
| 613 | locomo_writel(0x00, lchip->base + LOCOMO_PAIF); |
| 614 | locomo_writel(0x00, lchip->base + LOCOMO_DAC); |
| 615 | locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC); |
| 616 | |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 617 | if ((locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT0) & 0x88) && (locomo_readl(lchip->base + LOCOMO_LED + LOCOMO_LPT1) & 0x88)) |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 618 | locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */ |
| 619 | else |
| 620 | /* 18MHz already enabled, so no wait */ |
| 621 | locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */ |
| 622 | |
| 623 | locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/ |
| 624 | locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */ |
| 625 | locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */ |
| 626 | |
| 627 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 632 | static int locomo_resume(struct platform_device *dev) |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 633 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 634 | struct locomo *lchip = platform_get_drvdata(dev); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 635 | struct locomo_save_data *save; |
| 636 | unsigned long r; |
| 637 | unsigned long flags; |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 638 | |
| 639 | save = lchip->saved_state; |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 640 | if (!save) |
| 641 | return 0; |
| 642 | |
| 643 | spin_lock_irqsave(&lchip->lock, flags); |
| 644 | |
| 645 | locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 646 | locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPI + LOCOMO_SPICT); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 647 | locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE); |
| 648 | locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 649 | locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 650 | |
| 651 | locomo_writel(0x00, lchip->base + LOCOMO_C32K); |
| 652 | locomo_writel(0x90, lchip->base + LOCOMO_TADC); |
| 653 | |
| 654 | locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC); |
| 655 | r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 656 | r &= 0xFEFF; |
| 657 | locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 658 | locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD); |
| 659 | |
| 660 | spin_unlock_irqrestore(&lchip->lock, flags); |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 661 | |
| 662 | lchip->saved_state = NULL; |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 663 | kfree(save); |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | #endif |
| 668 | |
Pavel Machek | 4ebf2d0 | 2006-03-15 16:03:03 +0000 | [diff] [blame] | 669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /** |
| 671 | * locomo_probe - probe for a single LoCoMo chip. |
| 672 | * @phys_addr: physical address of device. |
| 673 | * |
| 674 | * Probe for a LoCoMo chip. This must be called |
| 675 | * before any other locomo-specific code. |
| 676 | * |
| 677 | * Returns: |
| 678 | * %-ENODEV device not found. |
| 679 | * %-EBUSY physical address already marked in-use. |
| 680 | * %0 successful. |
| 681 | */ |
| 682 | static int |
| 683 | __locomo_probe(struct device *me, struct resource *mem, int irq) |
| 684 | { |
| 685 | struct locomo *lchip; |
| 686 | unsigned long r; |
| 687 | int i, ret = -ENODEV; |
| 688 | |
Russell King | d2a02b9 | 2006-03-20 19:46:41 +0000 | [diff] [blame] | 689 | lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | if (!lchip) |
| 691 | return -ENOMEM; |
| 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | spin_lock_init(&lchip->lock); |
| 694 | |
| 695 | lchip->dev = me; |
| 696 | dev_set_drvdata(lchip->dev, lchip); |
| 697 | |
| 698 | lchip->phys = mem->start; |
| 699 | lchip->irq = irq; |
| 700 | |
| 701 | /* |
| 702 | * Map the whole region. This also maps the |
| 703 | * registers for our children. |
| 704 | */ |
| 705 | lchip->base = ioremap(mem->start, PAGE_SIZE); |
| 706 | if (!lchip->base) { |
| 707 | ret = -ENOMEM; |
| 708 | goto out; |
| 709 | } |
| 710 | |
| 711 | /* locomo initialize */ |
| 712 | locomo_writel(0, lchip->base + LOCOMO_ICR); |
| 713 | /* KEYBOARD */ |
| 714 | locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 715 | |
| 716 | /* GPIO */ |
| 717 | locomo_writel(0, lchip->base + LOCOMO_GPO); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 718 | locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | , lchip->base + LOCOMO_GPE); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 720 | locomo_writel((LOCOMO_GPIO(1) | LOCOMO_GPIO(2) | LOCOMO_GPIO(13) | LOCOMO_GPIO(14)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | , lchip->base + LOCOMO_GPD); |
| 722 | locomo_writel(0, lchip->base + LOCOMO_GIE); |
| 723 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 724 | /* Frontlight */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); |
| 726 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD); |
Pavel Machek | 4ebf2d0 | 2006-03-15 16:03:03 +0000 | [diff] [blame] | 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | /* Longtime timer */ |
| 729 | locomo_writel(0, lchip->base + LOCOMO_LTINT); |
| 730 | /* SPI */ |
| 731 | locomo_writel(0, lchip->base + LOCOMO_SPIIE); |
| 732 | |
| 733 | locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD); |
| 734 | r = locomo_readl(lchip->base + LOCOMO_ASD); |
| 735 | r |= 0x8000; |
| 736 | locomo_writel(r, lchip->base + LOCOMO_ASD); |
| 737 | |
| 738 | locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD); |
| 739 | r = locomo_readl(lchip->base + LOCOMO_HSD); |
| 740 | r |= 0x8000; |
| 741 | locomo_writel(r, lchip->base + LOCOMO_HSD); |
| 742 | |
| 743 | locomo_writel(128 / 8, lchip->base + LOCOMO_HSC); |
| 744 | |
| 745 | /* XON */ |
| 746 | locomo_writel(0x80, lchip->base + LOCOMO_TADC); |
| 747 | udelay(1000); |
| 748 | /* CLK9MEN */ |
| 749 | r = locomo_readl(lchip->base + LOCOMO_TADC); |
| 750 | r |= 0x10; |
| 751 | locomo_writel(r, lchip->base + LOCOMO_TADC); |
| 752 | udelay(100); |
| 753 | |
| 754 | /* init DAC */ |
| 755 | r = locomo_readl(lchip->base + LOCOMO_DAC); |
| 756 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; |
| 757 | locomo_writel(r, lchip->base + LOCOMO_DAC); |
| 758 | |
| 759 | r = locomo_readl(lchip->base + LOCOMO_VER); |
| 760 | printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff)); |
| 761 | |
| 762 | /* |
| 763 | * The interrupt controller must be initialised before any |
| 764 | * other device to ensure that the interrupts are available. |
| 765 | */ |
| 766 | if (lchip->irq != NO_IRQ) |
| 767 | locomo_setup_irq(lchip); |
| 768 | |
| 769 | for (i = 0; i < ARRAY_SIZE(locomo_devices); i++) |
| 770 | locomo_init_one_child(lchip, &locomo_devices[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | return 0; |
| 772 | |
| 773 | out: |
| 774 | kfree(lchip); |
| 775 | return ret; |
| 776 | } |
| 777 | |
Pavel Machek | e24da5d | 2005-09-04 11:33:12 +0100 | [diff] [blame] | 778 | static int locomo_remove_child(struct device *dev, void *data) |
| 779 | { |
| 780 | device_unregister(dev); |
| 781 | return 0; |
| 782 | } |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | static void __locomo_remove(struct locomo *lchip) |
| 785 | { |
Pavel Machek | e24da5d | 2005-09-04 11:33:12 +0100 | [diff] [blame] | 786 | device_for_each_child(lchip->dev, NULL, locomo_remove_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | if (lchip->irq != NO_IRQ) { |
| 789 | set_irq_chained_handler(lchip->irq, NULL); |
| 790 | set_irq_data(lchip->irq, NULL); |
| 791 | } |
| 792 | |
| 793 | iounmap(lchip->base); |
| 794 | kfree(lchip); |
| 795 | } |
| 796 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 797 | static int locomo_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | struct resource *mem; |
| 800 | int irq; |
| 801 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 802 | mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | if (!mem) |
| 804 | return -EINVAL; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 805 | irq = platform_get_irq(dev, 0); |
David Vrabel | 4894473 | 2006-01-19 17:56:29 +0000 | [diff] [blame] | 806 | if (irq < 0) |
| 807 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 809 | return __locomo_probe(&dev->dev, mem, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 812 | static int locomo_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | { |
Pavel Machek | c35bf4a | 2005-11-12 20:25:25 +0000 | [diff] [blame] | 814 | struct locomo *lchip = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | |
| 816 | if (lchip) { |
| 817 | __locomo_remove(lchip); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 818 | platform_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * Not sure if this should be on the system bus or not yet. |
| 826 | * We really want some way to register a system device at |
| 827 | * the per-machine level, and then have this driver pick |
| 828 | * up the registered devices. |
| 829 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 830 | static struct platform_driver locomo_device_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | .probe = locomo_probe, |
| 832 | .remove = locomo_remove, |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 833 | #ifdef CONFIG_PM |
| 834 | .suspend = locomo_suspend, |
| 835 | .resume = locomo_resume, |
| 836 | #endif |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 837 | .driver = { |
| 838 | .name = "locomo", |
| 839 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | }; |
| 841 | |
| 842 | /* |
| 843 | * Get the parent device driver (us) structure |
| 844 | * from a child function device |
| 845 | */ |
| 846 | static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev) |
| 847 | { |
| 848 | return (struct locomo *)dev_get_drvdata(ldev->dev.parent); |
| 849 | } |
| 850 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 851 | void locomo_gpio_set_dir(struct device *dev, unsigned int bits, unsigned int dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 853 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | unsigned long flags; |
| 855 | unsigned int r; |
| 856 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 857 | if (!lchip) |
| 858 | return; |
| 859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | spin_lock_irqsave(&lchip->lock, flags); |
| 861 | |
| 862 | r = locomo_readl(lchip->base + LOCOMO_GPD); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 863 | if (dir) |
| 864 | r |= bits; |
| 865 | else |
| 866 | r &= ~bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | locomo_writel(r, lchip->base + LOCOMO_GPD); |
| 868 | |
| 869 | r = locomo_readl(lchip->base + LOCOMO_GPE); |
| 870 | if (dir) |
| 871 | r |= bits; |
| 872 | else |
| 873 | r &= ~bits; |
| 874 | locomo_writel(r, lchip->base + LOCOMO_GPE); |
| 875 | |
| 876 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 877 | } |
| 878 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 879 | int locomo_gpio_read_level(struct device *dev, unsigned int bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 881 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | unsigned long flags; |
| 883 | unsigned int ret; |
| 884 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 885 | if (!lchip) |
| 886 | return -ENODEV; |
| 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | spin_lock_irqsave(&lchip->lock, flags); |
| 889 | ret = locomo_readl(lchip->base + LOCOMO_GPL); |
| 890 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 891 | |
| 892 | ret &= bits; |
| 893 | return ret; |
| 894 | } |
| 895 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 896 | int locomo_gpio_read_output(struct device *dev, unsigned int bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 898 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | unsigned long flags; |
| 900 | unsigned int ret; |
| 901 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 902 | if (!lchip) |
| 903 | return -ENODEV; |
| 904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | spin_lock_irqsave(&lchip->lock, flags); |
| 906 | ret = locomo_readl(lchip->base + LOCOMO_GPO); |
| 907 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 908 | |
| 909 | ret &= bits; |
| 910 | return ret; |
| 911 | } |
| 912 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 913 | void locomo_gpio_write(struct device *dev, unsigned int bits, unsigned int set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 915 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | unsigned long flags; |
| 917 | unsigned int r; |
| 918 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 919 | if (!lchip) |
| 920 | return; |
| 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | spin_lock_irqsave(&lchip->lock, flags); |
| 923 | |
| 924 | r = locomo_readl(lchip->base + LOCOMO_GPO); |
| 925 | if (set) |
| 926 | r |= bits; |
| 927 | else |
| 928 | r &= ~bits; |
| 929 | locomo_writel(r, lchip->base + LOCOMO_GPO); |
| 930 | |
| 931 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 932 | } |
| 933 | |
| 934 | static void locomo_m62332_sendbit(void *mapbase, int bit) |
| 935 | { |
| 936 | unsigned int r; |
| 937 | |
| 938 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 939 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 940 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 941 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 942 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ |
| 943 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 944 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 945 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 946 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 947 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 948 | |
| 949 | if (bit & 1) { |
| 950 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 951 | r |= LOCOMO_DAC_SDAOEB; |
| 952 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 953 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 954 | } else { |
| 955 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 956 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 957 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 958 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 959 | } |
| 960 | |
| 961 | udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */ |
| 962 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 963 | r |= LOCOMO_DAC_SCLOEB; |
| 964 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 965 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 966 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ |
| 967 | } |
| 968 | |
| 969 | void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel) |
| 970 | { |
| 971 | struct locomo *lchip = locomo_chip_driver(ldev); |
| 972 | int i; |
| 973 | unsigned char data; |
| 974 | unsigned int r; |
| 975 | void *mapbase = lchip->base; |
| 976 | unsigned long flags; |
| 977 | |
| 978 | spin_lock_irqsave(&lchip->lock, flags); |
| 979 | |
| 980 | /* Start */ |
| 981 | udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */ |
| 982 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 983 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; |
| 984 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 985 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 986 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ |
| 987 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 988 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 989 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 990 | udelay(DAC_START_HOLD_TIME); /* 5.0 usec */ |
| 991 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ |
| 992 | |
| 993 | /* Send slave address and W bit (LSB is W bit) */ |
| 994 | data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT; |
| 995 | for (i = 1; i <= 8; i++) { |
| 996 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); |
| 997 | } |
| 998 | |
| 999 | /* Check A bit */ |
| 1000 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1001 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 1002 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1003 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 1004 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 1005 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1006 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 1007 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1008 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 1009 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1010 | r |= LOCOMO_DAC_SCLOEB; |
| 1011 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1012 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 1013 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ |
| 1014 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ |
| 1015 | printk(KERN_WARNING "locomo: m62332_senddata Error 1\n"); |
| 1016 | return; |
| 1017 | } |
| 1018 | |
| 1019 | /* Send Sub address (LSB is channel select) */ |
| 1020 | /* channel = 0 : ch1 select */ |
| 1021 | /* = 1 : ch2 select */ |
| 1022 | data = M62332_SUB_ADDR + channel; |
| 1023 | for (i = 1; i <= 8; i++) { |
| 1024 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); |
| 1025 | } |
| 1026 | |
| 1027 | /* Check A bit */ |
| 1028 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1029 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 1030 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1031 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 1032 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 1033 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1034 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 1035 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1036 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 1037 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1038 | r |= LOCOMO_DAC_SCLOEB; |
| 1039 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1040 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 1041 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ |
| 1042 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ |
| 1043 | printk(KERN_WARNING "locomo: m62332_senddata Error 2\n"); |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | /* Send DAC data */ |
| 1048 | for (i = 1; i <= 8; i++) { |
| 1049 | locomo_m62332_sendbit(mapbase, dac_data >> (8 - i)); |
| 1050 | } |
| 1051 | |
| 1052 | /* Check A bit */ |
| 1053 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1054 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 1055 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1056 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 1057 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 1058 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1059 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 1060 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1061 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 1062 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1063 | r |= LOCOMO_DAC_SCLOEB; |
| 1064 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1065 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 1066 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ |
| 1067 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ |
| 1068 | printk(KERN_WARNING "locomo: m62332_senddata Error 3\n"); |
| 1069 | return; |
| 1070 | } |
| 1071 | |
| 1072 | /* stop */ |
| 1073 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1074 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 1075 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1076 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 1077 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 1078 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1079 | r |= LOCOMO_DAC_SCLOEB; |
| 1080 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1081 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 1082 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ |
| 1083 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1084 | r |= LOCOMO_DAC_SDAOEB; |
| 1085 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1086 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 1087 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ |
| 1088 | |
| 1089 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 1090 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; |
| 1091 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 1092 | udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */ |
| 1093 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 1094 | |
| 1095 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 1096 | } |
| 1097 | |
| 1098 | /* |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 1099 | * Frontlight control |
| 1100 | */ |
| 1101 | |
| 1102 | static struct locomo *locomo_chip_driver(struct locomo_dev *ldev); |
| 1103 | |
| 1104 | void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf) |
| 1105 | { |
| 1106 | unsigned long flags; |
| 1107 | struct locomo *lchip = locomo_chip_driver(dev); |
| 1108 | |
| 1109 | if (vr) |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 1110 | locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 1); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 1111 | else |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 1112 | locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 0); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 1113 | |
| 1114 | spin_lock_irqsave(&lchip->lock, flags); |
| 1115 | locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); |
| 1116 | udelay(100); |
| 1117 | locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD); |
| 1118 | locomo_writel(bpwf | LOCOMO_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); |
| 1119 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 1120 | } |
| 1121 | |
| 1122 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | * LoCoMo "Register Access Bus." |
| 1124 | * |
| 1125 | * We model this as a regular bus type, and hang devices directly |
| 1126 | * off this. |
| 1127 | */ |
| 1128 | static int locomo_match(struct device *_dev, struct device_driver *_drv) |
| 1129 | { |
| 1130 | struct locomo_dev *dev = LOCOMO_DEV(_dev); |
| 1131 | struct locomo_driver *drv = LOCOMO_DRV(_drv); |
| 1132 | |
| 1133 | return dev->devid == drv->devid; |
| 1134 | } |
| 1135 | |
| 1136 | static int locomo_bus_suspend(struct device *dev, pm_message_t state) |
| 1137 | { |
| 1138 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 1139 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 1140 | int ret = 0; |
| 1141 | |
| 1142 | if (drv && drv->suspend) |
| 1143 | ret = drv->suspend(ldev, state); |
| 1144 | return ret; |
| 1145 | } |
| 1146 | |
| 1147 | static int locomo_bus_resume(struct device *dev) |
| 1148 | { |
| 1149 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 1150 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 1151 | int ret = 0; |
| 1152 | |
| 1153 | if (drv && drv->resume) |
| 1154 | ret = drv->resume(ldev); |
| 1155 | return ret; |
| 1156 | } |
| 1157 | |
| 1158 | static int locomo_bus_probe(struct device *dev) |
| 1159 | { |
| 1160 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 1161 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 1162 | int ret = -ENODEV; |
| 1163 | |
| 1164 | if (drv->probe) |
| 1165 | ret = drv->probe(ldev); |
| 1166 | return ret; |
| 1167 | } |
| 1168 | |
| 1169 | static int locomo_bus_remove(struct device *dev) |
| 1170 | { |
| 1171 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 1172 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 1173 | int ret = 0; |
| 1174 | |
| 1175 | if (drv->remove) |
| 1176 | ret = drv->remove(ldev); |
| 1177 | return ret; |
| 1178 | } |
| 1179 | |
| 1180 | struct bus_type locomo_bus_type = { |
| 1181 | .name = "locomo-bus", |
| 1182 | .match = locomo_match, |
Russell King | 306955b | 2006-01-05 14:33:04 +0000 | [diff] [blame] | 1183 | .probe = locomo_bus_probe, |
| 1184 | .remove = locomo_bus_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | .suspend = locomo_bus_suspend, |
| 1186 | .resume = locomo_bus_resume, |
| 1187 | }; |
| 1188 | |
| 1189 | int locomo_driver_register(struct locomo_driver *driver) |
| 1190 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | driver->drv.bus = &locomo_bus_type; |
| 1192 | return driver_register(&driver->drv); |
| 1193 | } |
| 1194 | |
| 1195 | void locomo_driver_unregister(struct locomo_driver *driver) |
| 1196 | { |
| 1197 | driver_unregister(&driver->drv); |
| 1198 | } |
| 1199 | |
| 1200 | static int __init locomo_init(void) |
| 1201 | { |
| 1202 | int ret = bus_register(&locomo_bus_type); |
| 1203 | if (ret == 0) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1204 | platform_driver_register(&locomo_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | return ret; |
| 1206 | } |
| 1207 | |
| 1208 | static void __exit locomo_exit(void) |
| 1209 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1210 | platform_driver_unregister(&locomo_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | bus_unregister(&locomo_bus_type); |
| 1212 | } |
| 1213 | |
| 1214 | module_init(locomo_init); |
| 1215 | module_exit(locomo_exit); |
| 1216 | |
| 1217 | MODULE_DESCRIPTION("Sharp LoCoMo core driver"); |
| 1218 | MODULE_LICENSE("GPL"); |
| 1219 | MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); |
| 1220 | |
| 1221 | EXPORT_SYMBOL(locomo_driver_register); |
| 1222 | EXPORT_SYMBOL(locomo_driver_unregister); |
| 1223 | EXPORT_SYMBOL(locomo_gpio_set_dir); |
| 1224 | EXPORT_SYMBOL(locomo_gpio_read_level); |
| 1225 | EXPORT_SYMBOL(locomo_gpio_read_output); |
| 1226 | EXPORT_SYMBOL(locomo_gpio_write); |
| 1227 | EXPORT_SYMBOL(locomo_m62332_senddata); |