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