Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2010 |
| 3 | * |
| 4 | * License Terms: GNU General Public License, version 2 |
| 5 | * Author: Hanumath Prasad <hanumath.prasad@stericsson.com> for ST-Ericsson |
| 6 | * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/irq.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/i2c.h> |
| 14 | #include <linux/mfd/core.h> |
Sundar Iyer | c6eda6c | 2010-12-13 09:33:12 +0530 | [diff] [blame] | 15 | #include <linux/mfd/tc3589x.h> |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 16 | |
Sundar Iyer | 593e9d7 | 2010-12-13 09:33:18 +0530 | [diff] [blame^] | 17 | #define TC3589x_CLKMODE_MODCTL_SLEEP 0x0 |
| 18 | #define TC3589x_CLKMODE_MODCTL_OPERATION (1 << 0) |
| 19 | |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 20 | /** |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 21 | * tc3589x_reg_read() - read a single TC3589x register |
| 22 | * @tc3589x: Device to read from |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 23 | * @reg: Register to read |
| 24 | */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 25 | int tc3589x_reg_read(struct tc3589x *tc3589x, u8 reg) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 26 | { |
| 27 | int ret; |
| 28 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 29 | ret = i2c_smbus_read_byte_data(tc3589x->i2c, reg); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 30 | if (ret < 0) |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 31 | dev_err(tc3589x->dev, "failed to read reg %#x: %d\n", |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 32 | reg, ret); |
| 33 | |
| 34 | return ret; |
| 35 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 36 | EXPORT_SYMBOL_GPL(tc3589x_reg_read); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 37 | |
| 38 | /** |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 39 | * tc3589x_reg_read() - write a single TC3589x register |
| 40 | * @tc3589x: Device to write to |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 41 | * @reg: Register to read |
| 42 | * @data: Value to write |
| 43 | */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 44 | int tc3589x_reg_write(struct tc3589x *tc3589x, u8 reg, u8 data) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 45 | { |
| 46 | int ret; |
| 47 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 48 | ret = i2c_smbus_write_byte_data(tc3589x->i2c, reg, data); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 49 | if (ret < 0) |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 50 | dev_err(tc3589x->dev, "failed to write reg %#x: %d\n", |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 51 | reg, ret); |
| 52 | |
| 53 | return ret; |
| 54 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 55 | EXPORT_SYMBOL_GPL(tc3589x_reg_write); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 56 | |
| 57 | /** |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 58 | * tc3589x_block_read() - read multiple TC3589x registers |
| 59 | * @tc3589x: Device to read from |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 60 | * @reg: First register |
| 61 | * @length: Number of registers |
| 62 | * @values: Buffer to write to |
| 63 | */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 64 | int tc3589x_block_read(struct tc3589x *tc3589x, u8 reg, u8 length, u8 *values) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 65 | { |
| 66 | int ret; |
| 67 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 68 | ret = i2c_smbus_read_i2c_block_data(tc3589x->i2c, reg, length, values); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 69 | if (ret < 0) |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 70 | dev_err(tc3589x->dev, "failed to read regs %#x: %d\n", |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 71 | reg, ret); |
| 72 | |
| 73 | return ret; |
| 74 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 75 | EXPORT_SYMBOL_GPL(tc3589x_block_read); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 76 | |
| 77 | /** |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 78 | * tc3589x_block_write() - write multiple TC3589x registers |
| 79 | * @tc3589x: Device to write to |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 80 | * @reg: First register |
| 81 | * @length: Number of registers |
| 82 | * @values: Values to write |
| 83 | */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 84 | int tc3589x_block_write(struct tc3589x *tc3589x, u8 reg, u8 length, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 85 | const u8 *values) |
| 86 | { |
| 87 | int ret; |
| 88 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 89 | ret = i2c_smbus_write_i2c_block_data(tc3589x->i2c, reg, length, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 90 | values); |
| 91 | if (ret < 0) |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 92 | dev_err(tc3589x->dev, "failed to write regs %#x: %d\n", |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 93 | reg, ret); |
| 94 | |
| 95 | return ret; |
| 96 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 97 | EXPORT_SYMBOL_GPL(tc3589x_block_write); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 98 | |
| 99 | /** |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 100 | * tc3589x_set_bits() - set the value of a bitfield in a TC3589x register |
| 101 | * @tc3589x: Device to write to |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 102 | * @reg: Register to write |
| 103 | * @mask: Mask of bits to set |
| 104 | * @values: Value to set |
| 105 | */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 106 | int tc3589x_set_bits(struct tc3589x *tc3589x, u8 reg, u8 mask, u8 val) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 107 | { |
| 108 | int ret; |
| 109 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 110 | mutex_lock(&tc3589x->lock); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 111 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 112 | ret = tc3589x_reg_read(tc3589x, reg); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 113 | if (ret < 0) |
| 114 | goto out; |
| 115 | |
| 116 | ret &= ~mask; |
| 117 | ret |= val; |
| 118 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 119 | ret = tc3589x_reg_write(tc3589x, reg, ret); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 120 | |
| 121 | out: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 122 | mutex_unlock(&tc3589x->lock); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 123 | return ret; |
| 124 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 125 | EXPORT_SYMBOL_GPL(tc3589x_set_bits); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 126 | |
| 127 | static struct resource gpio_resources[] = { |
| 128 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 129 | .start = TC3589x_INT_GPIIRQ, |
| 130 | .end = TC3589x_INT_GPIIRQ, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 131 | .flags = IORESOURCE_IRQ, |
| 132 | }, |
| 133 | }; |
| 134 | |
Sundar Iyer | 611b759 | 2010-12-13 09:33:15 +0530 | [diff] [blame] | 135 | static struct mfd_cell tc3589x_dev_gpio[] = { |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 136 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 137 | .name = "tc3589x-gpio", |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 138 | .num_resources = ARRAY_SIZE(gpio_resources), |
| 139 | .resources = &gpio_resources[0], |
| 140 | }, |
| 141 | }; |
| 142 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 143 | static irqreturn_t tc3589x_irq(int irq, void *data) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 144 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 145 | struct tc3589x *tc3589x = data; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 146 | int status; |
| 147 | |
Sundar Iyer | bd77efd | 2010-12-13 09:33:16 +0530 | [diff] [blame] | 148 | again: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 149 | status = tc3589x_reg_read(tc3589x, TC3589x_IRQST); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 150 | if (status < 0) |
| 151 | return IRQ_NONE; |
| 152 | |
| 153 | while (status) { |
| 154 | int bit = __ffs(status); |
| 155 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 156 | handle_nested_irq(tc3589x->irq_base + bit); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 157 | status &= ~(1 << bit); |
| 158 | } |
| 159 | |
| 160 | /* |
| 161 | * A dummy read or write (to any register) appears to be necessary to |
| 162 | * have the last interrupt clear (for example, GPIO IC write) take |
Sundar Iyer | bd77efd | 2010-12-13 09:33:16 +0530 | [diff] [blame] | 163 | * effect. In such a case, recheck for any interrupt which is still |
| 164 | * pending. |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 165 | */ |
Sundar Iyer | bd77efd | 2010-12-13 09:33:16 +0530 | [diff] [blame] | 166 | status = tc3589x_reg_read(tc3589x, TC3589x_IRQST); |
| 167 | if (status) |
| 168 | goto again; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 169 | |
| 170 | return IRQ_HANDLED; |
| 171 | } |
| 172 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 173 | static void tc3589x_irq_dummy(unsigned int irq) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 174 | { |
| 175 | /* No mask/unmask at this level */ |
| 176 | } |
| 177 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 178 | static struct irq_chip tc3589x_irq_chip = { |
| 179 | .name = "tc3589x", |
| 180 | .mask = tc3589x_irq_dummy, |
| 181 | .unmask = tc3589x_irq_dummy, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 182 | }; |
| 183 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 184 | static int tc3589x_irq_init(struct tc3589x *tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 185 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 186 | int base = tc3589x->irq_base; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 187 | int irq; |
| 188 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 189 | for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) { |
| 190 | set_irq_chip_data(irq, tc3589x); |
| 191 | set_irq_chip_and_handler(irq, &tc3589x_irq_chip, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 192 | handle_edge_irq); |
| 193 | set_irq_nested_thread(irq, 1); |
| 194 | #ifdef CONFIG_ARM |
| 195 | set_irq_flags(irq, IRQF_VALID); |
| 196 | #else |
| 197 | set_irq_noprobe(irq); |
| 198 | #endif |
| 199 | } |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 204 | static void tc3589x_irq_remove(struct tc3589x *tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 205 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 206 | int base = tc3589x->irq_base; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 207 | int irq; |
| 208 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 209 | for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) { |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 210 | #ifdef CONFIG_ARM |
| 211 | set_irq_flags(irq, 0); |
| 212 | #endif |
| 213 | set_irq_chip_and_handler(irq, NULL, NULL); |
| 214 | set_irq_chip_data(irq, NULL); |
| 215 | } |
| 216 | } |
| 217 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 218 | static int tc3589x_chip_init(struct tc3589x *tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 219 | { |
| 220 | int manf, ver, ret; |
| 221 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 222 | manf = tc3589x_reg_read(tc3589x, TC3589x_MANFCODE); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 223 | if (manf < 0) |
| 224 | return manf; |
| 225 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 226 | ver = tc3589x_reg_read(tc3589x, TC3589x_VERSION); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 227 | if (ver < 0) |
| 228 | return ver; |
| 229 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 230 | if (manf != TC3589x_MANFCODE_MAGIC) { |
| 231 | dev_err(tc3589x->dev, "unknown manufacturer: %#x\n", manf); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 232 | return -EINVAL; |
| 233 | } |
| 234 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 235 | dev_info(tc3589x->dev, "manufacturer: %#x, version: %#x\n", manf, ver); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 236 | |
Sundar Iyer | 523bc38 | 2010-12-13 09:33:17 +0530 | [diff] [blame] | 237 | /* |
| 238 | * Put everything except the IRQ module into reset; |
| 239 | * also spare the GPIO module for any pin initialization |
| 240 | * done during pre-kernel boot |
| 241 | */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 242 | ret = tc3589x_reg_write(tc3589x, TC3589x_RSTCTRL, |
| 243 | TC3589x_RSTCTRL_TIMRST |
| 244 | | TC3589x_RSTCTRL_ROTRST |
Sundar Iyer | 523bc38 | 2010-12-13 09:33:17 +0530 | [diff] [blame] | 245 | | TC3589x_RSTCTRL_KBDRST); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 246 | if (ret < 0) |
| 247 | return ret; |
| 248 | |
| 249 | /* Clear the reset interrupt. */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 250 | return tc3589x_reg_write(tc3589x, TC3589x_RSTINTCLR, 0x1); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Sundar Iyer | 611b759 | 2010-12-13 09:33:15 +0530 | [diff] [blame] | 253 | static int __devinit tc3589x_device_init(struct tc3589x *tc3589x) |
| 254 | { |
| 255 | int ret = 0; |
| 256 | unsigned int blocks = tc3589x->pdata->block; |
| 257 | |
| 258 | if (blocks & TC3589x_BLOCK_GPIO) { |
| 259 | ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio, |
| 260 | ARRAY_SIZE(tc3589x_dev_gpio), NULL, |
| 261 | tc3589x->irq_base); |
| 262 | if (ret) { |
| 263 | dev_err(tc3589x->dev, "failed to add gpio child\n"); |
| 264 | return ret; |
| 265 | } |
| 266 | dev_info(tc3589x->dev, "added gpio block\n"); |
| 267 | } |
| 268 | |
| 269 | return ret; |
| 270 | |
| 271 | } |
| 272 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 273 | static int __devinit tc3589x_probe(struct i2c_client *i2c, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 274 | const struct i2c_device_id *id) |
| 275 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 276 | struct tc3589x_platform_data *pdata = i2c->dev.platform_data; |
| 277 | struct tc3589x *tc3589x; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 278 | int ret; |
| 279 | |
| 280 | if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
| 281 | | I2C_FUNC_SMBUS_I2C_BLOCK)) |
| 282 | return -EIO; |
| 283 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 284 | tc3589x = kzalloc(sizeof(struct tc3589x), GFP_KERNEL); |
| 285 | if (!tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 286 | return -ENOMEM; |
| 287 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 288 | mutex_init(&tc3589x->lock); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 289 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 290 | tc3589x->dev = &i2c->dev; |
| 291 | tc3589x->i2c = i2c; |
| 292 | tc3589x->pdata = pdata; |
| 293 | tc3589x->irq_base = pdata->irq_base; |
| 294 | tc3589x->num_gpio = id->driver_data; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 295 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 296 | i2c_set_clientdata(i2c, tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 297 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 298 | ret = tc3589x_chip_init(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 299 | if (ret) |
| 300 | goto out_free; |
| 301 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 302 | ret = tc3589x_irq_init(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 303 | if (ret) |
| 304 | goto out_free; |
| 305 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 306 | ret = request_threaded_irq(tc3589x->i2c->irq, NULL, tc3589x_irq, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 307 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 308 | "tc3589x", tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 309 | if (ret) { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 310 | dev_err(tc3589x->dev, "failed to request IRQ: %d\n", ret); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 311 | goto out_removeirq; |
| 312 | } |
| 313 | |
Sundar Iyer | 611b759 | 2010-12-13 09:33:15 +0530 | [diff] [blame] | 314 | ret = tc3589x_device_init(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 315 | if (ret) { |
Sundar Iyer | 611b759 | 2010-12-13 09:33:15 +0530 | [diff] [blame] | 316 | dev_err(tc3589x->dev, "failed to add child devices\n"); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 317 | goto out_freeirq; |
| 318 | } |
| 319 | |
| 320 | return 0; |
| 321 | |
| 322 | out_freeirq: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 323 | free_irq(tc3589x->i2c->irq, tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 324 | out_removeirq: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 325 | tc3589x_irq_remove(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 326 | out_free: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 327 | kfree(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 328 | return ret; |
| 329 | } |
| 330 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 331 | static int __devexit tc3589x_remove(struct i2c_client *client) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 332 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 333 | struct tc3589x *tc3589x = i2c_get_clientdata(client); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 334 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 335 | mfd_remove_devices(tc3589x->dev); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 336 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 337 | free_irq(tc3589x->i2c->irq, tc3589x); |
| 338 | tc3589x_irq_remove(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 339 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 340 | kfree(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Sundar Iyer | 593e9d7 | 2010-12-13 09:33:18 +0530 | [diff] [blame^] | 345 | static int tc3589x_suspend(struct device *dev) |
| 346 | { |
| 347 | struct tc3589x *tc3589x = dev_get_drvdata(dev); |
| 348 | struct i2c_client *client = tc3589x->i2c; |
| 349 | int ret = 0; |
| 350 | |
| 351 | /* put the system to sleep mode */ |
| 352 | if (!device_may_wakeup(&client->dev)) |
| 353 | ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE, |
| 354 | TC3589x_CLKMODE_MODCTL_SLEEP); |
| 355 | |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | static int tc3589x_resume(struct device *dev) |
| 360 | { |
| 361 | struct tc3589x *tc3589x = dev_get_drvdata(dev); |
| 362 | struct i2c_client *client = tc3589x->i2c; |
| 363 | int ret = 0; |
| 364 | |
| 365 | /* enable the system into operation */ |
| 366 | if (!device_may_wakeup(&client->dev)) |
| 367 | ret = tc3589x_reg_write(tc3589x, TC3589x_CLKMODE, |
| 368 | TC3589x_CLKMODE_MODCTL_OPERATION); |
| 369 | |
| 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | static const SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend, |
| 374 | tc3589x_resume); |
| 375 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 376 | static const struct i2c_device_id tc3589x_id[] = { |
| 377 | { "tc3589x", 24 }, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 378 | { } |
| 379 | }; |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 380 | MODULE_DEVICE_TABLE(i2c, tc3589x_id); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 381 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 382 | static struct i2c_driver tc3589x_driver = { |
| 383 | .driver.name = "tc3589x", |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 384 | .driver.owner = THIS_MODULE, |
Sundar Iyer | 593e9d7 | 2010-12-13 09:33:18 +0530 | [diff] [blame^] | 385 | #ifdef CONFIG_PM |
| 386 | .driver.pm = &tc3589x_dev_pm_ops, |
| 387 | #endif |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 388 | .probe = tc3589x_probe, |
| 389 | .remove = __devexit_p(tc3589x_remove), |
| 390 | .id_table = tc3589x_id, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 391 | }; |
| 392 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 393 | static int __init tc3589x_init(void) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 394 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 395 | return i2c_add_driver(&tc3589x_driver); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 396 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 397 | subsys_initcall(tc3589x_init); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 398 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 399 | static void __exit tc3589x_exit(void) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 400 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 401 | i2c_del_driver(&tc3589x_driver); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 402 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 403 | module_exit(tc3589x_exit); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 404 | |
| 405 | MODULE_LICENSE("GPL v2"); |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 406 | MODULE_DESCRIPTION("TC3589x MFD core driver"); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 407 | MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent"); |