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 | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 145 | status = tc3589x_reg_read(tc3589x, TC3589x_IRQST); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 146 | if (status < 0) |
| 147 | return IRQ_NONE; |
| 148 | |
| 149 | while (status) { |
| 150 | int bit = __ffs(status); |
| 151 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 152 | handle_nested_irq(tc3589x->irq_base + bit); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 153 | status &= ~(1 << bit); |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * A dummy read or write (to any register) appears to be necessary to |
| 158 | * have the last interrupt clear (for example, GPIO IC write) take |
| 159 | * effect. |
| 160 | */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 161 | tc3589x_reg_read(tc3589x, TC3589x_IRQST); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 162 | |
| 163 | return IRQ_HANDLED; |
| 164 | } |
| 165 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 166 | static void tc3589x_irq_dummy(unsigned int irq) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 167 | { |
| 168 | /* No mask/unmask at this level */ |
| 169 | } |
| 170 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 171 | static struct irq_chip tc3589x_irq_chip = { |
| 172 | .name = "tc3589x", |
| 173 | .mask = tc3589x_irq_dummy, |
| 174 | .unmask = tc3589x_irq_dummy, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 175 | }; |
| 176 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 177 | static int tc3589x_irq_init(struct tc3589x *tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 178 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 179 | int base = tc3589x->irq_base; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 180 | int irq; |
| 181 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 182 | for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) { |
| 183 | set_irq_chip_data(irq, tc3589x); |
| 184 | set_irq_chip_and_handler(irq, &tc3589x_irq_chip, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 185 | handle_edge_irq); |
| 186 | set_irq_nested_thread(irq, 1); |
| 187 | #ifdef CONFIG_ARM |
| 188 | set_irq_flags(irq, IRQF_VALID); |
| 189 | #else |
| 190 | set_irq_noprobe(irq); |
| 191 | #endif |
| 192 | } |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 197 | static void tc3589x_irq_remove(struct tc3589x *tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 198 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 199 | int base = tc3589x->irq_base; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 200 | int irq; |
| 201 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 202 | for (irq = base; irq < base + TC3589x_NR_INTERNAL_IRQS; irq++) { |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 203 | #ifdef CONFIG_ARM |
| 204 | set_irq_flags(irq, 0); |
| 205 | #endif |
| 206 | set_irq_chip_and_handler(irq, NULL, NULL); |
| 207 | set_irq_chip_data(irq, NULL); |
| 208 | } |
| 209 | } |
| 210 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 211 | static int tc3589x_chip_init(struct tc3589x *tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 212 | { |
| 213 | int manf, ver, ret; |
| 214 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 215 | manf = tc3589x_reg_read(tc3589x, TC3589x_MANFCODE); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 216 | if (manf < 0) |
| 217 | return manf; |
| 218 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 219 | ver = tc3589x_reg_read(tc3589x, TC3589x_VERSION); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 220 | if (ver < 0) |
| 221 | return ver; |
| 222 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 223 | if (manf != TC3589x_MANFCODE_MAGIC) { |
| 224 | dev_err(tc3589x->dev, "unknown manufacturer: %#x\n", manf); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 225 | return -EINVAL; |
| 226 | } |
| 227 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 228 | dev_info(tc3589x->dev, "manufacturer: %#x, version: %#x\n", manf, ver); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 229 | |
| 230 | /* Put everything except the IRQ module into reset */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 231 | ret = tc3589x_reg_write(tc3589x, TC3589x_RSTCTRL, |
| 232 | TC3589x_RSTCTRL_TIMRST |
| 233 | | TC3589x_RSTCTRL_ROTRST |
| 234 | | TC3589x_RSTCTRL_KBDRST |
| 235 | | TC3589x_RSTCTRL_GPIRST); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 236 | if (ret < 0) |
| 237 | return ret; |
| 238 | |
| 239 | /* Clear the reset interrupt. */ |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 240 | return tc3589x_reg_write(tc3589x, TC3589x_RSTINTCLR, 0x1); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Sundar Iyer | 611b759 | 2010-12-13 09:33:15 +0530 | [diff] [blame^] | 243 | static int __devinit tc3589x_device_init(struct tc3589x *tc3589x) |
| 244 | { |
| 245 | int ret = 0; |
| 246 | unsigned int blocks = tc3589x->pdata->block; |
| 247 | |
| 248 | if (blocks & TC3589x_BLOCK_GPIO) { |
| 249 | ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio, |
| 250 | ARRAY_SIZE(tc3589x_dev_gpio), NULL, |
| 251 | tc3589x->irq_base); |
| 252 | if (ret) { |
| 253 | dev_err(tc3589x->dev, "failed to add gpio child\n"); |
| 254 | return ret; |
| 255 | } |
| 256 | dev_info(tc3589x->dev, "added gpio block\n"); |
| 257 | } |
| 258 | |
| 259 | return ret; |
| 260 | |
| 261 | } |
| 262 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 263 | static int __devinit tc3589x_probe(struct i2c_client *i2c, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 264 | const struct i2c_device_id *id) |
| 265 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 266 | struct tc3589x_platform_data *pdata = i2c->dev.platform_data; |
| 267 | struct tc3589x *tc3589x; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 268 | int ret; |
| 269 | |
| 270 | if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
| 271 | | I2C_FUNC_SMBUS_I2C_BLOCK)) |
| 272 | return -EIO; |
| 273 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 274 | tc3589x = kzalloc(sizeof(struct tc3589x), GFP_KERNEL); |
| 275 | if (!tc3589x) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 276 | return -ENOMEM; |
| 277 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 278 | mutex_init(&tc3589x->lock); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 279 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 280 | tc3589x->dev = &i2c->dev; |
| 281 | tc3589x->i2c = i2c; |
| 282 | tc3589x->pdata = pdata; |
| 283 | tc3589x->irq_base = pdata->irq_base; |
| 284 | tc3589x->num_gpio = id->driver_data; |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 285 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 286 | i2c_set_clientdata(i2c, tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 287 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 288 | ret = tc3589x_chip_init(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 289 | if (ret) |
| 290 | goto out_free; |
| 291 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 292 | ret = tc3589x_irq_init(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 293 | if (ret) |
| 294 | goto out_free; |
| 295 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 296 | ret = request_threaded_irq(tc3589x->i2c->irq, NULL, tc3589x_irq, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 297 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 298 | "tc3589x", tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 299 | if (ret) { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 300 | dev_err(tc3589x->dev, "failed to request IRQ: %d\n", ret); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 301 | goto out_removeirq; |
| 302 | } |
| 303 | |
Sundar Iyer | 611b759 | 2010-12-13 09:33:15 +0530 | [diff] [blame^] | 304 | ret = tc3589x_device_init(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 305 | if (ret) { |
Sundar Iyer | 611b759 | 2010-12-13 09:33:15 +0530 | [diff] [blame^] | 306 | dev_err(tc3589x->dev, "failed to add child devices\n"); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 307 | goto out_freeirq; |
| 308 | } |
| 309 | |
| 310 | return 0; |
| 311 | |
| 312 | out_freeirq: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 313 | free_irq(tc3589x->i2c->irq, tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 314 | out_removeirq: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 315 | tc3589x_irq_remove(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 316 | out_free: |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 317 | kfree(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 318 | return ret; |
| 319 | } |
| 320 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 321 | static int __devexit tc3589x_remove(struct i2c_client *client) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 322 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 323 | struct tc3589x *tc3589x = i2c_get_clientdata(client); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 324 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 325 | mfd_remove_devices(tc3589x->dev); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 326 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 327 | free_irq(tc3589x->i2c->irq, tc3589x); |
| 328 | tc3589x_irq_remove(tc3589x); |
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 | kfree(tc3589x); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 335 | static const struct i2c_device_id tc3589x_id[] = { |
| 336 | { "tc3589x", 24 }, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 337 | { } |
| 338 | }; |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 339 | MODULE_DEVICE_TABLE(i2c, tc3589x_id); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 340 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 341 | static struct i2c_driver tc3589x_driver = { |
| 342 | .driver.name = "tc3589x", |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 343 | .driver.owner = THIS_MODULE, |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 344 | .probe = tc3589x_probe, |
| 345 | .remove = __devexit_p(tc3589x_remove), |
| 346 | .id_table = tc3589x_id, |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 347 | }; |
| 348 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 349 | static int __init tc3589x_init(void) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 350 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 351 | return i2c_add_driver(&tc3589x_driver); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 352 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 353 | subsys_initcall(tc3589x_init); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 354 | |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 355 | static void __exit tc3589x_exit(void) |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 356 | { |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 357 | i2c_del_driver(&tc3589x_driver); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 358 | } |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 359 | module_exit(tc3589x_exit); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 360 | |
| 361 | MODULE_LICENSE("GPL v2"); |
Sundar Iyer | 20406eb | 2010-12-13 09:33:14 +0530 | [diff] [blame] | 362 | MODULE_DESCRIPTION("TC3589x MFD core driver"); |
Rabin Vincent | b4ecd32 | 2010-05-10 23:39:47 +0200 | [diff] [blame] | 363 | MODULE_AUTHOR("Hanumath Prasad, Rabin Vincent"); |