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