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