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 | |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 35 | /* LoCoMo Interrupts */ |
| 36 | #define IRQ_LOCOMO_KEY (0) |
| 37 | #define IRQ_LOCOMO_GPIO (1) |
| 38 | #define IRQ_LOCOMO_LT (2) |
| 39 | #define IRQ_LOCOMO_SPI (3) |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* M62332 output channel selection */ |
| 42 | #define M62332_EVR_CH 1 /* M62332 volume channel number */ |
| 43 | /* 0 : CH.1 , 1 : CH. 2 */ |
| 44 | /* DAC send data */ |
| 45 | #define M62332_SLAVE_ADDR 0x4e /* Slave address */ |
| 46 | #define M62332_W_BIT 0x00 /* W bit (0 only) */ |
| 47 | #define M62332_SUB_ADDR 0x00 /* Sub address */ |
| 48 | #define M62332_A_BIT 0x00 /* A bit (0 only) */ |
| 49 | |
| 50 | /* DAC setup and hold times (expressed in us) */ |
| 51 | #define DAC_BUS_FREE_TIME 5 /* 4.7 us */ |
| 52 | #define DAC_START_SETUP_TIME 5 /* 4.7 us */ |
| 53 | #define DAC_STOP_SETUP_TIME 4 /* 4.0 us */ |
| 54 | #define DAC_START_HOLD_TIME 5 /* 4.7 us */ |
| 55 | #define DAC_SCL_LOW_HOLD_TIME 5 /* 4.7 us */ |
| 56 | #define DAC_SCL_HIGH_HOLD_TIME 4 /* 4.0 us */ |
| 57 | #define DAC_DATA_SETUP_TIME 1 /* 250 ns */ |
| 58 | #define DAC_DATA_HOLD_TIME 1 /* 300 ns */ |
| 59 | #define DAC_LOW_SETUP_TIME 1 /* 300 ns */ |
| 60 | #define DAC_HIGH_SETUP_TIME 1 /* 1000 ns */ |
| 61 | |
| 62 | /* the following is the overall data for the locomo chip */ |
| 63 | struct locomo { |
| 64 | struct device *dev; |
| 65 | unsigned long phys; |
| 66 | unsigned int irq; |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 67 | int irq_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | spinlock_t lock; |
Russell King | 5481536 | 2006-03-15 15:43:04 +0000 | [diff] [blame] | 69 | void __iomem *base; |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 70 | #ifdef CONFIG_PM |
| 71 | void *saved_state; |
| 72 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | struct locomo_dev_info { |
| 76 | unsigned long offset; |
| 77 | unsigned long length; |
| 78 | unsigned int devid; |
| 79 | unsigned int irq[1]; |
| 80 | const char * name; |
| 81 | }; |
| 82 | |
| 83 | /* All the locomo devices. If offset is non-zero, the mapbase for the |
| 84 | * locomo_dev will be set to the chip base plus offset. If offset is |
| 85 | * zero, then the mapbase for the locomo_dev will be set to zero. An |
| 86 | * offset of zero means the device only uses GPIOs or other helper |
| 87 | * functions inside this file */ |
| 88 | static struct locomo_dev_info locomo_devices[] = { |
| 89 | { |
| 90 | .devid = LOCOMO_DEVID_KEYBOARD, |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 91 | .irq = { IRQ_LOCOMO_KEY }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | .name = "locomo-keyboard", |
| 93 | .offset = LOCOMO_KEYBOARD, |
| 94 | .length = 16, |
| 95 | }, |
| 96 | { |
| 97 | .devid = LOCOMO_DEVID_FRONTLIGHT, |
| 98 | .irq = {}, |
| 99 | .name = "locomo-frontlight", |
| 100 | .offset = LOCOMO_FRONTLIGHT, |
| 101 | .length = 8, |
| 102 | |
| 103 | }, |
| 104 | { |
| 105 | .devid = LOCOMO_DEVID_BACKLIGHT, |
| 106 | .irq = {}, |
| 107 | .name = "locomo-backlight", |
| 108 | .offset = LOCOMO_BACKLIGHT, |
| 109 | .length = 8, |
| 110 | }, |
| 111 | { |
| 112 | .devid = LOCOMO_DEVID_AUDIO, |
| 113 | .irq = {}, |
| 114 | .name = "locomo-audio", |
| 115 | .offset = LOCOMO_AUDIO, |
| 116 | .length = 4, |
| 117 | }, |
| 118 | { |
| 119 | .devid = LOCOMO_DEVID_LED, |
| 120 | .irq = {}, |
| 121 | .name = "locomo-led", |
| 122 | .offset = LOCOMO_LED, |
| 123 | .length = 8, |
| 124 | }, |
| 125 | { |
| 126 | .devid = LOCOMO_DEVID_UART, |
| 127 | .irq = {}, |
| 128 | .name = "locomo-uart", |
| 129 | .offset = 0, |
| 130 | .length = 0, |
| 131 | }, |
Dirk Opfer | a2025e7 | 2006-09-25 22:41:47 +0100 | [diff] [blame] | 132 | { |
| 133 | .devid = LOCOMO_DEVID_SPI, |
| 134 | .irq = {}, |
| 135 | .name = "locomo-spi", |
| 136 | .offset = LOCOMO_SPI, |
| 137 | .length = 0x30, |
| 138 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 141 | static void locomo_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 143 | struct locomo *lchip = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | int req, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | /* Acknowledge the parent IRQ */ |
| 147 | desc->chip->ack(irq); |
| 148 | |
| 149 | /* check why this interrupt was generated */ |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 150 | req = locomo_readl(lchip->base + LOCOMO_ICR) & 0x0f00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | if (req) { |
| 153 | /* generate the next interrupt(s) */ |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 154 | irq = lchip->irq_base; |
Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame] | 155 | for (i = 0; i <= 3; i++, irq++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | if (req & (0x0100 << i)) { |
Dmitry Baryshkov | d8aa025 | 2008-10-09 13:36:24 +0100 | [diff] [blame] | 157 | generic_handle_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | static void locomo_ack_irq(unsigned int irq) |
| 165 | { |
| 166 | } |
| 167 | |
| 168 | static void locomo_mask_irq(unsigned int irq) |
| 169 | { |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 170 | struct locomo *lchip = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | unsigned int r; |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 172 | r = locomo_readl(lchip->base + LOCOMO_ICR); |
| 173 | r &= ~(0x0010 << (irq - lchip->irq_base)); |
| 174 | locomo_writel(r, lchip->base + LOCOMO_ICR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void locomo_unmask_irq(unsigned int irq) |
| 178 | { |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 179 | struct locomo *lchip = get_irq_chip_data(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | unsigned int r; |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 181 | r = locomo_readl(lchip->base + LOCOMO_ICR); |
| 182 | r |= (0x0010 << (irq - lchip->irq_base)); |
| 183 | locomo_writel(r, lchip->base + LOCOMO_ICR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 186 | static struct irq_chip locomo_chip = { |
| 187 | .name = "LOCOMO", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | .ack = locomo_ack_irq, |
| 189 | .mask = locomo_mask_irq, |
| 190 | .unmask = locomo_unmask_irq, |
| 191 | }; |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | static void locomo_setup_irq(struct locomo *lchip) |
| 194 | { |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 195 | int irq = lchip->irq_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | /* |
| 198 | * Install handler for IRQ_LOCOMO_HW. |
| 199 | */ |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 200 | set_irq_type(lchip->irq, IRQ_TYPE_EDGE_FALLING); |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 201 | set_irq_chip_data(lchip->irq, lchip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | set_irq_chained_handler(lchip->irq, locomo_handler); |
| 203 | |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 204 | /* Install handlers for IRQ_LOCOMO_* */ |
| 205 | for ( ; irq <= lchip->irq_base + 3; irq++) { |
Eric Miao | 00dd802 | 2009-12-25 12:18:33 +0800 | [diff] [blame] | 206 | set_irq_chip(irq, &locomo_chip); |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 207 | set_irq_chip_data(irq, lchip); |
| 208 | set_irq_handler(irq, handle_level_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | |
| 214 | static void locomo_dev_release(struct device *_dev) |
| 215 | { |
| 216 | struct locomo_dev *dev = LOCOMO_DEV(_dev); |
| 217 | |
| 218 | kfree(dev); |
| 219 | } |
| 220 | |
| 221 | static int |
| 222 | locomo_init_one_child(struct locomo *lchip, struct locomo_dev_info *info) |
| 223 | { |
| 224 | struct locomo_dev *dev; |
| 225 | int ret; |
| 226 | |
Russell King | d2a02b9 | 2006-03-20 19:46:41 +0000 | [diff] [blame] | 227 | dev = kzalloc(sizeof(struct locomo_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if (!dev) { |
| 229 | ret = -ENOMEM; |
| 230 | goto out; |
| 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | /* |
| 234 | * If the parent device has a DMA mask associated with it, |
| 235 | * propagate it down to the children. |
| 236 | */ |
| 237 | if (lchip->dev->dma_mask) { |
| 238 | dev->dma_mask = *lchip->dev->dma_mask; |
| 239 | dev->dev.dma_mask = &dev->dma_mask; |
| 240 | } |
| 241 | |
Kay Sievers | 3f97870 | 2008-05-30 17:42:11 +0200 | [diff] [blame] | 242 | dev_set_name(&dev->dev, "%s", info->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | dev->devid = info->devid; |
| 244 | dev->dev.parent = lchip->dev; |
| 245 | dev->dev.bus = &locomo_bus_type; |
| 246 | dev->dev.release = locomo_dev_release; |
| 247 | dev->dev.coherent_dma_mask = lchip->dev->coherent_dma_mask; |
| 248 | |
| 249 | if (info->offset) |
| 250 | dev->mapbase = lchip->base + info->offset; |
| 251 | else |
| 252 | dev->mapbase = 0; |
| 253 | dev->length = info->length; |
| 254 | |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 255 | dev->irq[0] = (lchip->irq_base == NO_IRQ) ? |
| 256 | NO_IRQ : lchip->irq_base + info->irq[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | ret = device_register(&dev->dev); |
| 259 | if (ret) { |
| 260 | out: |
| 261 | kfree(dev); |
| 262 | } |
| 263 | return ret; |
| 264 | } |
| 265 | |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 266 | #ifdef CONFIG_PM |
| 267 | |
| 268 | struct locomo_save_data { |
| 269 | u16 LCM_GPO; |
| 270 | u16 LCM_SPICT; |
| 271 | u16 LCM_GPE; |
| 272 | u16 LCM_ASD; |
| 273 | u16 LCM_SPIMD; |
| 274 | }; |
| 275 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 276 | static int locomo_suspend(struct platform_device *dev, pm_message_t state) |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 277 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 278 | struct locomo *lchip = platform_get_drvdata(dev); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 279 | struct locomo_save_data *save; |
| 280 | unsigned long flags; |
| 281 | |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 282 | save = kmalloc(sizeof(struct locomo_save_data), GFP_KERNEL); |
| 283 | if (!save) |
| 284 | return -ENOMEM; |
| 285 | |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 286 | lchip->saved_state = save; |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 287 | |
| 288 | spin_lock_irqsave(&lchip->lock, flags); |
| 289 | |
| 290 | save->LCM_GPO = locomo_readl(lchip->base + LOCOMO_GPO); /* GPIO */ |
| 291 | locomo_writel(0x00, lchip->base + LOCOMO_GPO); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 292 | save->LCM_SPICT = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPICT); /* SPI */ |
H Hartley Sweeten | 1b0d76c | 2010-03-22 10:33:58 +0800 | [diff] [blame] | 293 | locomo_writel(0x40, lchip->base + LOCOMO_SPI + LOCOMO_SPICT); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 294 | save->LCM_GPE = locomo_readl(lchip->base + LOCOMO_GPE); /* GPIO */ |
| 295 | locomo_writel(0x00, lchip->base + LOCOMO_GPE); |
| 296 | save->LCM_ASD = locomo_readl(lchip->base + LOCOMO_ASD); /* ADSTART */ |
| 297 | locomo_writel(0x00, lchip->base + LOCOMO_ASD); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 298 | save->LCM_SPIMD = locomo_readl(lchip->base + LOCOMO_SPI + LOCOMO_SPIMD); /* SPI */ |
| 299 | locomo_writel(0x3C14, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 300 | |
| 301 | locomo_writel(0x00, lchip->base + LOCOMO_PAIF); |
| 302 | locomo_writel(0x00, lchip->base + LOCOMO_DAC); |
| 303 | locomo_writel(0x00, lchip->base + LOCOMO_BACKLIGHT + LOCOMO_TC); |
| 304 | |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 305 | 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] | 306 | locomo_writel(0x00, lchip->base + LOCOMO_C32K); /* CLK32 off */ |
| 307 | else |
| 308 | /* 18MHz already enabled, so no wait */ |
| 309 | locomo_writel(0xc1, lchip->base + LOCOMO_C32K); /* CLK32 on */ |
| 310 | |
| 311 | locomo_writel(0x00, lchip->base + LOCOMO_TADC); /* 18MHz clock off*/ |
| 312 | locomo_writel(0x00, lchip->base + LOCOMO_AUDIO + LOCOMO_ACC); /* 22MHz/24MHz clock off */ |
| 313 | locomo_writel(0x00, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); /* FL */ |
| 314 | |
| 315 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 320 | static int locomo_resume(struct platform_device *dev) |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 321 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 322 | struct locomo *lchip = platform_get_drvdata(dev); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 323 | struct locomo_save_data *save; |
| 324 | unsigned long r; |
| 325 | unsigned long flags; |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 326 | |
| 327 | save = lchip->saved_state; |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 328 | if (!save) |
| 329 | return 0; |
| 330 | |
| 331 | spin_lock_irqsave(&lchip->lock, flags); |
| 332 | |
| 333 | locomo_writel(save->LCM_GPO, lchip->base + LOCOMO_GPO); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 334 | locomo_writel(save->LCM_SPICT, lchip->base + LOCOMO_SPI + LOCOMO_SPICT); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 335 | locomo_writel(save->LCM_GPE, lchip->base + LOCOMO_GPE); |
| 336 | locomo_writel(save->LCM_ASD, lchip->base + LOCOMO_ASD); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 337 | locomo_writel(save->LCM_SPIMD, lchip->base + LOCOMO_SPI + LOCOMO_SPIMD); |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 338 | |
| 339 | locomo_writel(0x00, lchip->base + LOCOMO_C32K); |
| 340 | locomo_writel(0x90, lchip->base + LOCOMO_TADC); |
| 341 | |
| 342 | locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KSC); |
| 343 | r = locomo_readl(lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 344 | r &= 0xFEFF; |
| 345 | locomo_writel(r, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 346 | locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD); |
| 347 | |
| 348 | spin_unlock_irqrestore(&lchip->lock, flags); |
Rafael J. Wysocki | 93160c6 | 2007-07-09 11:39:19 -0700 | [diff] [blame] | 349 | |
| 350 | lchip->saved_state = NULL; |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 351 | kfree(save); |
| 352 | |
| 353 | return 0; |
| 354 | } |
| 355 | #endif |
| 356 | |
Pavel Machek | 4ebf2d0 | 2006-03-15 16:03:03 +0000 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /** |
| 359 | * locomo_probe - probe for a single LoCoMo chip. |
| 360 | * @phys_addr: physical address of device. |
| 361 | * |
| 362 | * Probe for a LoCoMo chip. This must be called |
| 363 | * before any other locomo-specific code. |
| 364 | * |
| 365 | * Returns: |
| 366 | * %-ENODEV device not found. |
| 367 | * %-EBUSY physical address already marked in-use. |
| 368 | * %0 successful. |
| 369 | */ |
| 370 | static int |
| 371 | __locomo_probe(struct device *me, struct resource *mem, int irq) |
| 372 | { |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 373 | struct locomo_platform_data *pdata = me->platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | struct locomo *lchip; |
| 375 | unsigned long r; |
| 376 | int i, ret = -ENODEV; |
| 377 | |
Russell King | d2a02b9 | 2006-03-20 19:46:41 +0000 | [diff] [blame] | 378 | lchip = kzalloc(sizeof(struct locomo), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | if (!lchip) |
| 380 | return -ENOMEM; |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | spin_lock_init(&lchip->lock); |
| 383 | |
| 384 | lchip->dev = me; |
| 385 | dev_set_drvdata(lchip->dev, lchip); |
| 386 | |
| 387 | lchip->phys = mem->start; |
| 388 | lchip->irq = irq; |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 389 | lchip->irq_base = (pdata) ? pdata->irq_base : NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* |
| 392 | * Map the whole region. This also maps the |
| 393 | * registers for our children. |
| 394 | */ |
| 395 | lchip->base = ioremap(mem->start, PAGE_SIZE); |
| 396 | if (!lchip->base) { |
| 397 | ret = -ENOMEM; |
| 398 | goto out; |
| 399 | } |
| 400 | |
| 401 | /* locomo initialize */ |
| 402 | locomo_writel(0, lchip->base + LOCOMO_ICR); |
| 403 | /* KEYBOARD */ |
| 404 | locomo_writel(0, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KIC); |
| 405 | |
| 406 | /* GPIO */ |
| 407 | locomo_writel(0, lchip->base + LOCOMO_GPO); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 408 | 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] | 409 | , lchip->base + LOCOMO_GPE); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 410 | 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] | 411 | , lchip->base + LOCOMO_GPD); |
| 412 | locomo_writel(0, lchip->base + LOCOMO_GIE); |
| 413 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 414 | /* Frontlight */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); |
| 416 | locomo_writel(0, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD); |
Pavel Machek | 4ebf2d0 | 2006-03-15 16:03:03 +0000 | [diff] [blame] | 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | /* Longtime timer */ |
| 419 | locomo_writel(0, lchip->base + LOCOMO_LTINT); |
| 420 | /* SPI */ |
H Hartley Sweeten | 1b0d76c | 2010-03-22 10:33:58 +0800 | [diff] [blame] | 421 | locomo_writel(0, lchip->base + LOCOMO_SPI + LOCOMO_SPIIE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | locomo_writel(6 + 8 + 320 + 30 - 10, lchip->base + LOCOMO_ASD); |
| 424 | r = locomo_readl(lchip->base + LOCOMO_ASD); |
| 425 | r |= 0x8000; |
| 426 | locomo_writel(r, lchip->base + LOCOMO_ASD); |
| 427 | |
| 428 | locomo_writel(6 + 8 + 320 + 30 - 10 - 128 + 4, lchip->base + LOCOMO_HSD); |
| 429 | r = locomo_readl(lchip->base + LOCOMO_HSD); |
| 430 | r |= 0x8000; |
| 431 | locomo_writel(r, lchip->base + LOCOMO_HSD); |
| 432 | |
| 433 | locomo_writel(128 / 8, lchip->base + LOCOMO_HSC); |
| 434 | |
| 435 | /* XON */ |
| 436 | locomo_writel(0x80, lchip->base + LOCOMO_TADC); |
| 437 | udelay(1000); |
| 438 | /* CLK9MEN */ |
| 439 | r = locomo_readl(lchip->base + LOCOMO_TADC); |
| 440 | r |= 0x10; |
| 441 | locomo_writel(r, lchip->base + LOCOMO_TADC); |
| 442 | udelay(100); |
| 443 | |
| 444 | /* init DAC */ |
| 445 | r = locomo_readl(lchip->base + LOCOMO_DAC); |
| 446 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; |
| 447 | locomo_writel(r, lchip->base + LOCOMO_DAC); |
| 448 | |
| 449 | r = locomo_readl(lchip->base + LOCOMO_VER); |
| 450 | printk(KERN_INFO "LoCoMo Chip: %lu%lu\n", (r >> 8), (r & 0xff)); |
| 451 | |
| 452 | /* |
| 453 | * The interrupt controller must be initialised before any |
| 454 | * other device to ensure that the interrupts are available. |
| 455 | */ |
Eric Miao | ac609d2 | 2010-02-04 18:07:33 -0800 | [diff] [blame] | 456 | if (lchip->irq != NO_IRQ && lchip->irq_base != NO_IRQ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | locomo_setup_irq(lchip); |
| 458 | |
| 459 | for (i = 0; i < ARRAY_SIZE(locomo_devices); i++) |
| 460 | locomo_init_one_child(lchip, &locomo_devices[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | return 0; |
| 462 | |
| 463 | out: |
| 464 | kfree(lchip); |
| 465 | return ret; |
| 466 | } |
| 467 | |
Pavel Machek | e24da5d | 2005-09-04 11:33:12 +0100 | [diff] [blame] | 468 | static int locomo_remove_child(struct device *dev, void *data) |
| 469 | { |
| 470 | device_unregister(dev); |
| 471 | return 0; |
| 472 | } |
| 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | static void __locomo_remove(struct locomo *lchip) |
| 475 | { |
Pavel Machek | e24da5d | 2005-09-04 11:33:12 +0100 | [diff] [blame] | 476 | device_for_each_child(lchip->dev, NULL, locomo_remove_child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
| 478 | if (lchip->irq != NO_IRQ) { |
| 479 | set_irq_chained_handler(lchip->irq, NULL); |
| 480 | set_irq_data(lchip->irq, NULL); |
| 481 | } |
| 482 | |
| 483 | iounmap(lchip->base); |
| 484 | kfree(lchip); |
| 485 | } |
| 486 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 487 | static int locomo_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | struct resource *mem; |
| 490 | int irq; |
| 491 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 492 | mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | if (!mem) |
| 494 | return -EINVAL; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 495 | irq = platform_get_irq(dev, 0); |
David Vrabel | 4894473 | 2006-01-19 17:56:29 +0000 | [diff] [blame] | 496 | if (irq < 0) |
| 497 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 499 | return __locomo_probe(&dev->dev, mem, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 502 | static int locomo_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Pavel Machek | c35bf4a | 2005-11-12 20:25:25 +0000 | [diff] [blame] | 504 | struct locomo *lchip = platform_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 506 | if (lchip) { |
| 507 | __locomo_remove(lchip); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 508 | platform_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | /* |
| 515 | * Not sure if this should be on the system bus or not yet. |
| 516 | * We really want some way to register a system device at |
| 517 | * the per-machine level, and then have this driver pick |
| 518 | * up the registered devices. |
| 519 | */ |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 520 | static struct platform_driver locomo_device_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | .probe = locomo_probe, |
| 522 | .remove = locomo_remove, |
John Lenz | b38d950 | 2005-09-08 14:41:54 +0100 | [diff] [blame] | 523 | #ifdef CONFIG_PM |
| 524 | .suspend = locomo_suspend, |
| 525 | .resume = locomo_resume, |
| 526 | #endif |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 527 | .driver = { |
| 528 | .name = "locomo", |
| 529 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | }; |
| 531 | |
| 532 | /* |
| 533 | * Get the parent device driver (us) structure |
| 534 | * from a child function device |
| 535 | */ |
| 536 | static inline struct locomo *locomo_chip_driver(struct locomo_dev *ldev) |
| 537 | { |
| 538 | return (struct locomo *)dev_get_drvdata(ldev->dev.parent); |
| 539 | } |
| 540 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 541 | 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] | 542 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 543 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | unsigned long flags; |
| 545 | unsigned int r; |
| 546 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 547 | if (!lchip) |
| 548 | return; |
| 549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | spin_lock_irqsave(&lchip->lock, flags); |
| 551 | |
| 552 | r = locomo_readl(lchip->base + LOCOMO_GPD); |
Thomas Kunze | 2a52efb | 2008-04-29 17:44:54 +0100 | [diff] [blame] | 553 | if (dir) |
| 554 | r |= bits; |
| 555 | else |
| 556 | r &= ~bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | locomo_writel(r, lchip->base + LOCOMO_GPD); |
| 558 | |
| 559 | r = locomo_readl(lchip->base + LOCOMO_GPE); |
| 560 | if (dir) |
| 561 | r |= bits; |
| 562 | else |
| 563 | r &= ~bits; |
| 564 | locomo_writel(r, lchip->base + LOCOMO_GPE); |
| 565 | |
| 566 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 567 | } |
Hartley Sweeten | 9c5e8fe | 2009-09-18 20:40:27 +0100 | [diff] [blame] | 568 | EXPORT_SYMBOL(locomo_gpio_set_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 570 | int locomo_gpio_read_level(struct device *dev, unsigned int bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 572 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | unsigned long flags; |
| 574 | unsigned int ret; |
| 575 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 576 | if (!lchip) |
| 577 | return -ENODEV; |
| 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | spin_lock_irqsave(&lchip->lock, flags); |
| 580 | ret = locomo_readl(lchip->base + LOCOMO_GPL); |
| 581 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 582 | |
| 583 | ret &= bits; |
| 584 | return ret; |
| 585 | } |
Hartley Sweeten | 9c5e8fe | 2009-09-18 20:40:27 +0100 | [diff] [blame] | 586 | EXPORT_SYMBOL(locomo_gpio_read_level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 588 | int locomo_gpio_read_output(struct device *dev, unsigned int bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 590 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | unsigned long flags; |
| 592 | unsigned int ret; |
| 593 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 594 | if (!lchip) |
| 595 | return -ENODEV; |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | spin_lock_irqsave(&lchip->lock, flags); |
| 598 | ret = locomo_readl(lchip->base + LOCOMO_GPO); |
| 599 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 600 | |
| 601 | ret &= bits; |
| 602 | return ret; |
| 603 | } |
Hartley Sweeten | 9c5e8fe | 2009-09-18 20:40:27 +0100 | [diff] [blame] | 604 | EXPORT_SYMBOL(locomo_gpio_read_output); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 606 | 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] | 607 | { |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 608 | struct locomo *lchip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | unsigned long flags; |
| 610 | unsigned int r; |
| 611 | |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 612 | if (!lchip) |
| 613 | return; |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | spin_lock_irqsave(&lchip->lock, flags); |
| 616 | |
| 617 | r = locomo_readl(lchip->base + LOCOMO_GPO); |
| 618 | if (set) |
| 619 | r |= bits; |
| 620 | else |
| 621 | r &= ~bits; |
| 622 | locomo_writel(r, lchip->base + LOCOMO_GPO); |
| 623 | |
| 624 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 625 | } |
Hartley Sweeten | 9c5e8fe | 2009-09-18 20:40:27 +0100 | [diff] [blame] | 626 | EXPORT_SYMBOL(locomo_gpio_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | static void locomo_m62332_sendbit(void *mapbase, int bit) |
| 629 | { |
| 630 | unsigned int r; |
| 631 | |
| 632 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 633 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 634 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 635 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 636 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ |
| 637 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 638 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 639 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 640 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 641 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 642 | |
| 643 | if (bit & 1) { |
| 644 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 645 | r |= LOCOMO_DAC_SDAOEB; |
| 646 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 647 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 648 | } else { |
| 649 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 650 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 651 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 652 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 653 | } |
| 654 | |
| 655 | udelay(DAC_DATA_SETUP_TIME); /* 250 nsec */ |
| 656 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 657 | r |= LOCOMO_DAC_SCLOEB; |
| 658 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 659 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 660 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ |
| 661 | } |
| 662 | |
| 663 | void locomo_m62332_senddata(struct locomo_dev *ldev, unsigned int dac_data, int channel) |
| 664 | { |
| 665 | struct locomo *lchip = locomo_chip_driver(ldev); |
| 666 | int i; |
| 667 | unsigned char data; |
| 668 | unsigned int r; |
| 669 | void *mapbase = lchip->base; |
| 670 | unsigned long flags; |
| 671 | |
| 672 | spin_lock_irqsave(&lchip->lock, flags); |
| 673 | |
| 674 | /* Start */ |
| 675 | udelay(DAC_BUS_FREE_TIME); /* 5.0 usec */ |
| 676 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 677 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; |
| 678 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 679 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 680 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.0 usec */ |
| 681 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 682 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 683 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 684 | udelay(DAC_START_HOLD_TIME); /* 5.0 usec */ |
| 685 | udelay(DAC_DATA_HOLD_TIME); /* 300 nsec */ |
| 686 | |
| 687 | /* Send slave address and W bit (LSB is W bit) */ |
| 688 | data = (M62332_SLAVE_ADDR << 1) | M62332_W_BIT; |
| 689 | for (i = 1; i <= 8; i++) { |
| 690 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); |
| 691 | } |
| 692 | |
| 693 | /* Check A bit */ |
| 694 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 695 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 696 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 697 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 698 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 699 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 700 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 701 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 702 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 703 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 704 | r |= LOCOMO_DAC_SCLOEB; |
| 705 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 706 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 707 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ |
| 708 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ |
| 709 | printk(KERN_WARNING "locomo: m62332_senddata Error 1\n"); |
H Hartley Sweeten | c8c3dcb | 2010-03-22 11:09:20 +0800 | [diff] [blame] | 710 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* Send Sub address (LSB is channel select) */ |
| 714 | /* channel = 0 : ch1 select */ |
| 715 | /* = 1 : ch2 select */ |
| 716 | data = M62332_SUB_ADDR + channel; |
| 717 | for (i = 1; i <= 8; i++) { |
| 718 | locomo_m62332_sendbit(mapbase, data >> (8 - i)); |
| 719 | } |
| 720 | |
| 721 | /* Check A bit */ |
| 722 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 723 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 724 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 725 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 726 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 727 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 728 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 729 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 730 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 731 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 732 | r |= LOCOMO_DAC_SCLOEB; |
| 733 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 734 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 735 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ |
| 736 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ |
| 737 | printk(KERN_WARNING "locomo: m62332_senddata Error 2\n"); |
H Hartley Sweeten | c8c3dcb | 2010-03-22 11:09:20 +0800 | [diff] [blame] | 738 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* Send DAC data */ |
| 742 | for (i = 1; i <= 8; i++) { |
| 743 | locomo_m62332_sendbit(mapbase, dac_data >> (8 - i)); |
| 744 | } |
| 745 | |
| 746 | /* Check A bit */ |
| 747 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 748 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 749 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 750 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 751 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 752 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 753 | r &= ~(LOCOMO_DAC_SDAOEB); |
| 754 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 755 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 756 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 757 | r |= LOCOMO_DAC_SCLOEB; |
| 758 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 759 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 760 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4.7 usec */ |
| 761 | if (locomo_readl(mapbase + LOCOMO_DAC) & LOCOMO_DAC_SDAOEB) { /* High is error */ |
| 762 | printk(KERN_WARNING "locomo: m62332_senddata Error 3\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | |
H Hartley Sweeten | c8c3dcb | 2010-03-22 11:09:20 +0800 | [diff] [blame] | 765 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | /* stop */ |
| 767 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 768 | r &= ~(LOCOMO_DAC_SCLOEB); |
| 769 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 770 | udelay(DAC_LOW_SETUP_TIME); /* 300 nsec */ |
| 771 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 772 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 773 | r |= LOCOMO_DAC_SCLOEB; |
| 774 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 775 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 776 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ |
| 777 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 778 | r |= LOCOMO_DAC_SDAOEB; |
| 779 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 780 | udelay(DAC_HIGH_SETUP_TIME); /* 1000 nsec */ |
| 781 | udelay(DAC_SCL_HIGH_HOLD_TIME); /* 4 usec */ |
| 782 | |
| 783 | r = locomo_readl(mapbase + LOCOMO_DAC); |
| 784 | r |= LOCOMO_DAC_SCLOEB | LOCOMO_DAC_SDAOEB; |
| 785 | locomo_writel(r, mapbase + LOCOMO_DAC); |
| 786 | udelay(DAC_LOW_SETUP_TIME); /* 1000 nsec */ |
| 787 | udelay(DAC_SCL_LOW_HOLD_TIME); /* 4.7 usec */ |
| 788 | |
| 789 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 790 | } |
Hartley Sweeten | 9c5e8fe | 2009-09-18 20:40:27 +0100 | [diff] [blame] | 791 | EXPORT_SYMBOL(locomo_m62332_senddata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
| 793 | /* |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 794 | * Frontlight control |
| 795 | */ |
| 796 | |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 797 | void locomo_frontlight_set(struct locomo_dev *dev, int duty, int vr, int bpwf) |
| 798 | { |
| 799 | unsigned long flags; |
| 800 | struct locomo *lchip = locomo_chip_driver(dev); |
| 801 | |
| 802 | if (vr) |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 803 | locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 1); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 804 | else |
Richard Purdie | 8d48427 | 2006-09-25 20:11:48 +0100 | [diff] [blame] | 805 | locomo_gpio_write(dev->dev.parent, LOCOMO_GPIO_FL_VR, 0); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 806 | |
| 807 | spin_lock_irqsave(&lchip->lock, flags); |
| 808 | locomo_writel(bpwf, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); |
| 809 | udelay(100); |
| 810 | locomo_writel(duty, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALD); |
| 811 | locomo_writel(bpwf | LOCOMO_ALC_EN, lchip->base + LOCOMO_FRONTLIGHT + LOCOMO_ALS); |
| 812 | spin_unlock_irqrestore(&lchip->lock, flags); |
| 813 | } |
Eric Miao | 9179825 | 2008-12-01 11:41:19 +0800 | [diff] [blame] | 814 | EXPORT_SYMBOL(locomo_frontlight_set); |
Richard Purdie | e442378 | 2006-06-26 00:26:27 -0700 | [diff] [blame] | 815 | |
| 816 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | * LoCoMo "Register Access Bus." |
| 818 | * |
| 819 | * We model this as a regular bus type, and hang devices directly |
| 820 | * off this. |
| 821 | */ |
| 822 | static int locomo_match(struct device *_dev, struct device_driver *_drv) |
| 823 | { |
| 824 | struct locomo_dev *dev = LOCOMO_DEV(_dev); |
| 825 | struct locomo_driver *drv = LOCOMO_DRV(_drv); |
| 826 | |
| 827 | return dev->devid == drv->devid; |
| 828 | } |
| 829 | |
| 830 | static int locomo_bus_suspend(struct device *dev, pm_message_t state) |
| 831 | { |
| 832 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 833 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 834 | int ret = 0; |
| 835 | |
| 836 | if (drv && drv->suspend) |
| 837 | ret = drv->suspend(ldev, state); |
| 838 | return ret; |
| 839 | } |
| 840 | |
| 841 | static int locomo_bus_resume(struct device *dev) |
| 842 | { |
| 843 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 844 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 845 | int ret = 0; |
| 846 | |
| 847 | if (drv && drv->resume) |
| 848 | ret = drv->resume(ldev); |
| 849 | return ret; |
| 850 | } |
| 851 | |
| 852 | static int locomo_bus_probe(struct device *dev) |
| 853 | { |
| 854 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 855 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 856 | int ret = -ENODEV; |
| 857 | |
| 858 | if (drv->probe) |
| 859 | ret = drv->probe(ldev); |
| 860 | return ret; |
| 861 | } |
| 862 | |
| 863 | static int locomo_bus_remove(struct device *dev) |
| 864 | { |
| 865 | struct locomo_dev *ldev = LOCOMO_DEV(dev); |
| 866 | struct locomo_driver *drv = LOCOMO_DRV(dev->driver); |
| 867 | int ret = 0; |
| 868 | |
| 869 | if (drv->remove) |
| 870 | ret = drv->remove(ldev); |
| 871 | return ret; |
| 872 | } |
| 873 | |
| 874 | struct bus_type locomo_bus_type = { |
| 875 | .name = "locomo-bus", |
| 876 | .match = locomo_match, |
Russell King | 306955b | 2006-01-05 14:33:04 +0000 | [diff] [blame] | 877 | .probe = locomo_bus_probe, |
| 878 | .remove = locomo_bus_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | .suspend = locomo_bus_suspend, |
| 880 | .resume = locomo_bus_resume, |
| 881 | }; |
| 882 | |
| 883 | int locomo_driver_register(struct locomo_driver *driver) |
| 884 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | driver->drv.bus = &locomo_bus_type; |
| 886 | return driver_register(&driver->drv); |
| 887 | } |
Hartley Sweeten | 9c5e8fe | 2009-09-18 20:40:27 +0100 | [diff] [blame] | 888 | EXPORT_SYMBOL(locomo_driver_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
| 890 | void locomo_driver_unregister(struct locomo_driver *driver) |
| 891 | { |
| 892 | driver_unregister(&driver->drv); |
| 893 | } |
Hartley Sweeten | 9c5e8fe | 2009-09-18 20:40:27 +0100 | [diff] [blame] | 894 | EXPORT_SYMBOL(locomo_driver_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | static int __init locomo_init(void) |
| 897 | { |
| 898 | int ret = bus_register(&locomo_bus_type); |
| 899 | if (ret == 0) |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 900 | platform_driver_register(&locomo_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | return ret; |
| 902 | } |
| 903 | |
| 904 | static void __exit locomo_exit(void) |
| 905 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 906 | platform_driver_unregister(&locomo_device_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | bus_unregister(&locomo_bus_type); |
| 908 | } |
| 909 | |
| 910 | module_init(locomo_init); |
| 911 | module_exit(locomo_exit); |
| 912 | |
| 913 | MODULE_DESCRIPTION("Sharp LoCoMo core driver"); |
| 914 | MODULE_LICENSE("GPL"); |
| 915 | MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); |