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