Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Base driver for Marvell 88PM8607 |
| 3 | * |
| 4 | * Copyright (C) 2009 Marvell International Ltd. |
| 5 | * Haojian Zhuang <haojian.zhuang@marvell.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 14 | #include <linux/i2c.h> |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 15 | #include <linux/irq.h> |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/mfd/core.h> |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 19 | #include <linux/mfd/88pm860x.h> |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 20 | #include <linux/regulator/machine.h> |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 21 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 22 | #define INT_STATUS_NUM 3 |
| 23 | |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 24 | static struct resource bk_resources[] __initdata = { |
| 25 | {PM8606_BACKLIGHT1, PM8606_BACKLIGHT1, "backlight-0", IORESOURCE_IO,}, |
| 26 | {PM8606_BACKLIGHT2, PM8606_BACKLIGHT2, "backlight-1", IORESOURCE_IO,}, |
| 27 | {PM8606_BACKLIGHT3, PM8606_BACKLIGHT3, "backlight-2", IORESOURCE_IO,}, |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 28 | }; |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 29 | |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 30 | static struct resource led_resources[] __initdata = { |
| 31 | {PM8606_LED1_RED, PM8606_LED1_RED, "led0-red", IORESOURCE_IO,}, |
| 32 | {PM8606_LED1_GREEN, PM8606_LED1_GREEN, "led0-green", IORESOURCE_IO,}, |
| 33 | {PM8606_LED1_BLUE, PM8606_LED1_BLUE, "led0-blue", IORESOURCE_IO,}, |
| 34 | {PM8606_LED2_RED, PM8606_LED2_RED, "led1-red", IORESOURCE_IO,}, |
| 35 | {PM8606_LED2_GREEN, PM8606_LED2_GREEN, "led1-green", IORESOURCE_IO,}, |
| 36 | {PM8606_LED2_BLUE, PM8606_LED2_BLUE, "led1-blue", IORESOURCE_IO,}, |
| 37 | }; |
| 38 | |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 39 | static struct resource regulator_resources[] __initdata = { |
| 40 | {PM8607_ID_BUCK1, PM8607_ID_BUCK1, "buck-1", IORESOURCE_IO,}, |
| 41 | {PM8607_ID_BUCK2, PM8607_ID_BUCK2, "buck-2", IORESOURCE_IO,}, |
| 42 | {PM8607_ID_BUCK3, PM8607_ID_BUCK3, "buck-3", IORESOURCE_IO,}, |
| 43 | {PM8607_ID_LDO1, PM8607_ID_LDO1, "ldo-01", IORESOURCE_IO,}, |
| 44 | {PM8607_ID_LDO2, PM8607_ID_LDO2, "ldo-02", IORESOURCE_IO,}, |
| 45 | {PM8607_ID_LDO3, PM8607_ID_LDO3, "ldo-03", IORESOURCE_IO,}, |
| 46 | {PM8607_ID_LDO4, PM8607_ID_LDO4, "ldo-04", IORESOURCE_IO,}, |
| 47 | {PM8607_ID_LDO5, PM8607_ID_LDO5, "ldo-05", IORESOURCE_IO,}, |
| 48 | {PM8607_ID_LDO6, PM8607_ID_LDO6, "ldo-06", IORESOURCE_IO,}, |
| 49 | {PM8607_ID_LDO7, PM8607_ID_LDO7, "ldo-07", IORESOURCE_IO,}, |
| 50 | {PM8607_ID_LDO8, PM8607_ID_LDO8, "ldo-08", IORESOURCE_IO,}, |
| 51 | {PM8607_ID_LDO9, PM8607_ID_LDO9, "ldo-09", IORESOURCE_IO,}, |
| 52 | {PM8607_ID_LDO10, PM8607_ID_LDO10, "ldo-10", IORESOURCE_IO,}, |
| 53 | {PM8607_ID_LDO11, PM8607_ID_LDO11, "ldo-11", IORESOURCE_IO,}, |
| 54 | {PM8607_ID_LDO12, PM8607_ID_LDO12, "ldo-12", IORESOURCE_IO,}, |
| 55 | {PM8607_ID_LDO13, PM8607_ID_LDO13, "ldo-13", IORESOURCE_IO,}, |
| 56 | {PM8607_ID_LDO14, PM8607_ID_LDO14, "ldo-14", IORESOURCE_IO,}, |
| 57 | {PM8607_ID_LDO15, PM8607_ID_LDO15, "ldo-15", IORESOURCE_IO,}, |
| 58 | }; |
| 59 | |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 60 | static struct resource touch_resources[] __initdata = { |
| 61 | {PM8607_IRQ_PEN, PM8607_IRQ_PEN, "touch", IORESOURCE_IRQ,}, |
| 62 | }; |
| 63 | |
| 64 | static struct resource onkey_resources[] __initdata = { |
| 65 | {PM8607_IRQ_ONKEY, PM8607_IRQ_ONKEY, "onkey", IORESOURCE_IRQ,}, |
| 66 | }; |
| 67 | |
| 68 | static struct resource codec_resources[] __initdata = { |
| 69 | /* Headset microphone insertion or removal */ |
| 70 | {PM8607_IRQ_MICIN, PM8607_IRQ_MICIN, "micin", IORESOURCE_IRQ,}, |
| 71 | /* Hook-switch press or release */ |
| 72 | {PM8607_IRQ_HOOK, PM8607_IRQ_HOOK, "hook", IORESOURCE_IRQ,}, |
| 73 | /* Headset insertion or removal */ |
| 74 | {PM8607_IRQ_HEADSET, PM8607_IRQ_HEADSET, "headset", IORESOURCE_IRQ,}, |
| 75 | /* Audio short */ |
| 76 | {PM8607_IRQ_AUDIO_SHORT, PM8607_IRQ_AUDIO_SHORT, "audio-short", IORESOURCE_IRQ,}, |
| 77 | }; |
| 78 | |
| 79 | static struct resource battery_resources[] __initdata = { |
| 80 | {PM8607_IRQ_CC, PM8607_IRQ_CC, "columb counter", IORESOURCE_IRQ,}, |
| 81 | {PM8607_IRQ_BAT, PM8607_IRQ_BAT, "battery", IORESOURCE_IRQ,}, |
| 82 | }; |
| 83 | |
| 84 | static struct resource charger_resources[] __initdata = { |
| 85 | {PM8607_IRQ_CHG, PM8607_IRQ_CHG, "charger detect", IORESOURCE_IRQ,}, |
| 86 | {PM8607_IRQ_CHG_DONE, PM8607_IRQ_CHG_DONE, "charging done", IORESOURCE_IRQ,}, |
| 87 | {PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging timeout", IORESOURCE_IRQ,}, |
| 88 | {PM8607_IRQ_GPADC1, PM8607_IRQ_GPADC1, "battery temperature", IORESOURCE_IRQ,}, |
| 89 | {PM8607_IRQ_VBAT, PM8607_IRQ_VBAT, "battery voltage", IORESOURCE_IRQ,}, |
| 90 | {PM8607_IRQ_VCHG, PM8607_IRQ_VCHG, "vchg voltage", IORESOURCE_IRQ,}, |
| 91 | }; |
| 92 | |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 93 | static struct mfd_cell bk_devs[] __initdata = { |
| 94 | {"88pm860x-backlight", 0,}, |
| 95 | {"88pm860x-backlight", 1,}, |
| 96 | {"88pm860x-backlight", 2,}, |
| 97 | }; |
| 98 | |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 99 | static struct mfd_cell led_devs[] __initdata = { |
| 100 | {"88pm860x-led", 0,}, |
| 101 | {"88pm860x-led", 1,}, |
| 102 | {"88pm860x-led", 2,}, |
| 103 | {"88pm860x-led", 3,}, |
| 104 | {"88pm860x-led", 4,}, |
| 105 | {"88pm860x-led", 5,}, |
| 106 | }; |
| 107 | |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 108 | static struct mfd_cell regulator_devs[] __initdata = { |
| 109 | {"88pm860x-regulator", 0,}, |
| 110 | {"88pm860x-regulator", 1,}, |
| 111 | {"88pm860x-regulator", 2,}, |
| 112 | {"88pm860x-regulator", 3,}, |
| 113 | {"88pm860x-regulator", 4,}, |
| 114 | {"88pm860x-regulator", 5,}, |
| 115 | {"88pm860x-regulator", 6,}, |
| 116 | {"88pm860x-regulator", 7,}, |
| 117 | {"88pm860x-regulator", 8,}, |
| 118 | {"88pm860x-regulator", 9,}, |
| 119 | {"88pm860x-regulator", 10,}, |
| 120 | {"88pm860x-regulator", 11,}, |
| 121 | {"88pm860x-regulator", 12,}, |
| 122 | {"88pm860x-regulator", 13,}, |
| 123 | {"88pm860x-regulator", 14,}, |
| 124 | {"88pm860x-regulator", 15,}, |
| 125 | {"88pm860x-regulator", 16,}, |
| 126 | {"88pm860x-regulator", 17,}, |
| 127 | }; |
| 128 | |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 129 | static struct mfd_cell touch_devs[] __initdata = { |
| 130 | {"88pm860x-touch", -1,}, |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 131 | }; |
| 132 | |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 133 | static struct mfd_cell onkey_devs[] __initdata = { |
| 134 | {"88pm860x-onkey", -1,}, |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 135 | }; |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 136 | |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 137 | static struct mfd_cell codec_devs[] __initdata = { |
| 138 | {"88pm860x-codec", -1,}, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | static struct mfd_cell power_devs[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 142 | {"88pm860x-battery", -1,}, |
| 143 | {"88pm860x-charger", -1,}, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 144 | }; |
| 145 | |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 146 | static struct pm860x_backlight_pdata bk_pdata[ARRAY_SIZE(bk_devs)]; |
| 147 | static struct pm860x_led_pdata led_pdata[ARRAY_SIZE(led_devs)]; |
| 148 | static struct regulator_init_data regulator_pdata[ARRAY_SIZE(regulator_devs)]; |
| 149 | static struct pm860x_touch_pdata touch_pdata; |
| 150 | static struct pm860x_power_pdata power_pdata; |
Haojian Zhuang | 2c36af7 | 2010-08-12 11:59:33 +0800 | [diff] [blame] | 151 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 152 | struct pm860x_irq_data { |
| 153 | int reg; |
| 154 | int mask_reg; |
| 155 | int enable; /* enable or not */ |
| 156 | int offs; /* bit offset in mask register */ |
| 157 | }; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 158 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 159 | static struct pm860x_irq_data pm860x_irqs[] = { |
| 160 | [PM8607_IRQ_ONKEY] = { |
| 161 | .reg = PM8607_INT_STATUS1, |
| 162 | .mask_reg = PM8607_INT_MASK_1, |
| 163 | .offs = 1 << 0, |
| 164 | }, |
| 165 | [PM8607_IRQ_EXTON] = { |
| 166 | .reg = PM8607_INT_STATUS1, |
| 167 | .mask_reg = PM8607_INT_MASK_1, |
| 168 | .offs = 1 << 1, |
| 169 | }, |
| 170 | [PM8607_IRQ_CHG] = { |
| 171 | .reg = PM8607_INT_STATUS1, |
| 172 | .mask_reg = PM8607_INT_MASK_1, |
| 173 | .offs = 1 << 2, |
| 174 | }, |
| 175 | [PM8607_IRQ_BAT] = { |
| 176 | .reg = PM8607_INT_STATUS1, |
| 177 | .mask_reg = PM8607_INT_MASK_1, |
| 178 | .offs = 1 << 3, |
| 179 | }, |
| 180 | [PM8607_IRQ_RTC] = { |
| 181 | .reg = PM8607_INT_STATUS1, |
| 182 | .mask_reg = PM8607_INT_MASK_1, |
| 183 | .offs = 1 << 4, |
| 184 | }, |
| 185 | [PM8607_IRQ_CC] = { |
| 186 | .reg = PM8607_INT_STATUS1, |
| 187 | .mask_reg = PM8607_INT_MASK_1, |
| 188 | .offs = 1 << 5, |
| 189 | }, |
| 190 | [PM8607_IRQ_VBAT] = { |
| 191 | .reg = PM8607_INT_STATUS2, |
| 192 | .mask_reg = PM8607_INT_MASK_2, |
| 193 | .offs = 1 << 0, |
| 194 | }, |
| 195 | [PM8607_IRQ_VCHG] = { |
| 196 | .reg = PM8607_INT_STATUS2, |
| 197 | .mask_reg = PM8607_INT_MASK_2, |
| 198 | .offs = 1 << 1, |
| 199 | }, |
| 200 | [PM8607_IRQ_VSYS] = { |
| 201 | .reg = PM8607_INT_STATUS2, |
| 202 | .mask_reg = PM8607_INT_MASK_2, |
| 203 | .offs = 1 << 2, |
| 204 | }, |
| 205 | [PM8607_IRQ_TINT] = { |
| 206 | .reg = PM8607_INT_STATUS2, |
| 207 | .mask_reg = PM8607_INT_MASK_2, |
| 208 | .offs = 1 << 3, |
| 209 | }, |
| 210 | [PM8607_IRQ_GPADC0] = { |
| 211 | .reg = PM8607_INT_STATUS2, |
| 212 | .mask_reg = PM8607_INT_MASK_2, |
| 213 | .offs = 1 << 4, |
| 214 | }, |
| 215 | [PM8607_IRQ_GPADC1] = { |
| 216 | .reg = PM8607_INT_STATUS2, |
| 217 | .mask_reg = PM8607_INT_MASK_2, |
| 218 | .offs = 1 << 5, |
| 219 | }, |
| 220 | [PM8607_IRQ_GPADC2] = { |
| 221 | .reg = PM8607_INT_STATUS2, |
| 222 | .mask_reg = PM8607_INT_MASK_2, |
| 223 | .offs = 1 << 6, |
| 224 | }, |
| 225 | [PM8607_IRQ_GPADC3] = { |
| 226 | .reg = PM8607_INT_STATUS2, |
| 227 | .mask_reg = PM8607_INT_MASK_2, |
| 228 | .offs = 1 << 7, |
| 229 | }, |
| 230 | [PM8607_IRQ_AUDIO_SHORT] = { |
| 231 | .reg = PM8607_INT_STATUS3, |
| 232 | .mask_reg = PM8607_INT_MASK_3, |
| 233 | .offs = 1 << 0, |
| 234 | }, |
| 235 | [PM8607_IRQ_PEN] = { |
| 236 | .reg = PM8607_INT_STATUS3, |
| 237 | .mask_reg = PM8607_INT_MASK_3, |
| 238 | .offs = 1 << 1, |
| 239 | }, |
| 240 | [PM8607_IRQ_HEADSET] = { |
| 241 | .reg = PM8607_INT_STATUS3, |
| 242 | .mask_reg = PM8607_INT_MASK_3, |
| 243 | .offs = 1 << 2, |
| 244 | }, |
| 245 | [PM8607_IRQ_HOOK] = { |
| 246 | .reg = PM8607_INT_STATUS3, |
| 247 | .mask_reg = PM8607_INT_MASK_3, |
| 248 | .offs = 1 << 3, |
| 249 | }, |
| 250 | [PM8607_IRQ_MICIN] = { |
| 251 | .reg = PM8607_INT_STATUS3, |
| 252 | .mask_reg = PM8607_INT_MASK_3, |
| 253 | .offs = 1 << 4, |
| 254 | }, |
| 255 | [PM8607_IRQ_CHG_FAIL] = { |
| 256 | .reg = PM8607_INT_STATUS3, |
| 257 | .mask_reg = PM8607_INT_MASK_3, |
| 258 | .offs = 1 << 5, |
| 259 | }, |
| 260 | [PM8607_IRQ_CHG_DONE] = { |
| 261 | .reg = PM8607_INT_STATUS3, |
| 262 | .mask_reg = PM8607_INT_MASK_3, |
| 263 | .offs = 1 << 6, |
| 264 | }, |
| 265 | [PM8607_IRQ_CHG_FAULT] = { |
| 266 | .reg = PM8607_INT_STATUS3, |
| 267 | .mask_reg = PM8607_INT_MASK_3, |
| 268 | .offs = 1 << 7, |
| 269 | }, |
| 270 | }; |
| 271 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 272 | static irqreturn_t pm860x_irq(int irq, void *data) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 273 | { |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 274 | struct pm860x_chip *chip = data; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 275 | struct pm860x_irq_data *irq_data; |
| 276 | struct i2c_client *i2c; |
| 277 | int read_reg = -1, value = 0; |
| 278 | int i; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 279 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 280 | i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; |
| 281 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { |
| 282 | irq_data = &pm860x_irqs[i]; |
| 283 | if (read_reg != irq_data->reg) { |
| 284 | read_reg = irq_data->reg; |
| 285 | value = pm860x_reg_read(i2c, irq_data->reg); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 286 | } |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 287 | if (value & irq_data->enable) |
| 288 | handle_nested_irq(chip->irq_base + i); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 289 | } |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 290 | return IRQ_HANDLED; |
| 291 | } |
| 292 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 293 | static void pm860x_irq_lock(struct irq_data *data) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 294 | { |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 295 | struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 296 | |
| 297 | mutex_lock(&chip->irq_lock); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 298 | } |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 299 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 300 | static void pm860x_irq_sync_unlock(struct irq_data *data) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 301 | { |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 302 | struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 303 | struct pm860x_irq_data *irq_data; |
| 304 | struct i2c_client *i2c; |
| 305 | static unsigned char cached[3] = {0x0, 0x0, 0x0}; |
| 306 | unsigned char mask[3]; |
| 307 | int i; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 308 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 309 | i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; |
| 310 | /* Load cached value. In initial, all IRQs are masked */ |
| 311 | for (i = 0; i < 3; i++) |
| 312 | mask[i] = cached[i]; |
| 313 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { |
| 314 | irq_data = &pm860x_irqs[i]; |
| 315 | switch (irq_data->mask_reg) { |
| 316 | case PM8607_INT_MASK_1: |
| 317 | mask[0] &= ~irq_data->offs; |
| 318 | mask[0] |= irq_data->enable; |
| 319 | break; |
| 320 | case PM8607_INT_MASK_2: |
| 321 | mask[1] &= ~irq_data->offs; |
| 322 | mask[1] |= irq_data->enable; |
| 323 | break; |
| 324 | case PM8607_INT_MASK_3: |
| 325 | mask[2] &= ~irq_data->offs; |
| 326 | mask[2] |= irq_data->enable; |
| 327 | break; |
| 328 | default: |
| 329 | dev_err(chip->dev, "wrong IRQ\n"); |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | /* update mask into registers */ |
| 334 | for (i = 0; i < 3; i++) { |
| 335 | if (mask[i] != cached[i]) { |
| 336 | cached[i] = mask[i]; |
| 337 | pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]); |
| 338 | } |
| 339 | } |
| 340 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 341 | mutex_unlock(&chip->irq_lock); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 342 | } |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 343 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 344 | static void pm860x_irq_enable(struct irq_data *data) |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 345 | { |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 346 | struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); |
| 347 | pm860x_irqs[data->irq - chip->irq_base].enable |
| 348 | = pm860x_irqs[data->irq - chip->irq_base].offs; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 349 | } |
| 350 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 351 | static void pm860x_irq_disable(struct irq_data *data) |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 352 | { |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 353 | struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); |
| 354 | pm860x_irqs[data->irq - chip->irq_base].enable = 0; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static struct irq_chip pm860x_irq_chip = { |
| 358 | .name = "88pm860x", |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 359 | .irq_bus_lock = pm860x_irq_lock, |
| 360 | .irq_bus_sync_unlock = pm860x_irq_sync_unlock, |
| 361 | .irq_enable = pm860x_irq_enable, |
| 362 | .irq_disable = pm860x_irq_disable, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 363 | }; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 364 | |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 365 | static int __devinit device_gpadc_init(struct pm860x_chip *chip, |
| 366 | struct pm860x_platform_data *pdata) |
| 367 | { |
| 368 | struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ |
| 369 | : chip->companion; |
Dan Carpenter | eb6e8dd | 2010-05-27 00:54:09 +0200 | [diff] [blame] | 370 | int data; |
| 371 | int ret; |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 372 | |
| 373 | /* initialize GPADC without activating it */ |
| 374 | |
Dan Carpenter | eb6e8dd | 2010-05-27 00:54:09 +0200 | [diff] [blame] | 375 | if (!pdata || !pdata->touch) |
| 376 | return -EINVAL; |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 377 | |
Dan Carpenter | eb6e8dd | 2010-05-27 00:54:09 +0200 | [diff] [blame] | 378 | /* set GPADC MISC1 register */ |
| 379 | data = 0; |
| 380 | data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK; |
| 381 | data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK; |
| 382 | data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK; |
| 383 | data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK; |
| 384 | if (data) { |
| 385 | ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data); |
| 386 | if (ret < 0) |
| 387 | goto out; |
| 388 | } |
| 389 | /* set tsi prebias time */ |
| 390 | if (pdata->touch->tsi_prebias) { |
| 391 | data = pdata->touch->tsi_prebias; |
| 392 | ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data); |
| 393 | if (ret < 0) |
| 394 | goto out; |
| 395 | } |
| 396 | /* set prebias & prechg time of pen detect */ |
| 397 | data = 0; |
| 398 | data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK; |
| 399 | data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK; |
| 400 | if (data) { |
| 401 | ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data); |
| 402 | if (ret < 0) |
| 403 | goto out; |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 404 | } |
| 405 | |
Dan Carpenter | eb6e8dd | 2010-05-27 00:54:09 +0200 | [diff] [blame] | 406 | ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1, |
| 407 | PM8607_GPADC_EN, PM8607_GPADC_EN); |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 408 | out: |
| 409 | return ret; |
| 410 | } |
| 411 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 412 | static int __devinit device_irq_init(struct pm860x_chip *chip, |
| 413 | struct pm860x_platform_data *pdata) |
| 414 | { |
| 415 | struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ |
| 416 | : chip->companion; |
| 417 | unsigned char status_buf[INT_STATUS_NUM]; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 418 | unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 419 | int i, data, mask, ret = -EINVAL; |
| 420 | int __irq; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 421 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 422 | if (!pdata || !pdata->irq_base) { |
| 423 | dev_warn(chip->dev, "No interrupt support on IRQ base\n"); |
| 424 | return -EINVAL; |
| 425 | } |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 426 | |
| 427 | mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR |
| 428 | | PM8607_B0_MISC1_INT_MASK; |
| 429 | data = 0; |
| 430 | chip->irq_mode = 0; |
| 431 | if (pdata && pdata->irq_mode) { |
| 432 | /* |
| 433 | * irq_mode defines the way of clearing interrupt. If it's 1, |
| 434 | * clear IRQ by write. Otherwise, clear it by read. |
| 435 | * This control bit is valid from 88PM8607 B0 steping. |
| 436 | */ |
| 437 | data |= PM8607_B0_MISC1_INT_CLEAR; |
| 438 | chip->irq_mode = 1; |
| 439 | } |
| 440 | ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data); |
| 441 | if (ret < 0) |
| 442 | goto out; |
| 443 | |
| 444 | /* mask all IRQs */ |
| 445 | memset(status_buf, 0, INT_STATUS_NUM); |
| 446 | ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1, |
| 447 | INT_STATUS_NUM, status_buf); |
| 448 | if (ret < 0) |
| 449 | goto out; |
| 450 | |
| 451 | if (chip->irq_mode) { |
| 452 | /* clear interrupt status by write */ |
| 453 | memset(status_buf, 0xFF, INT_STATUS_NUM); |
| 454 | ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1, |
| 455 | INT_STATUS_NUM, status_buf); |
| 456 | } else { |
| 457 | /* clear interrupt status by read */ |
| 458 | ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1, |
| 459 | INT_STATUS_NUM, status_buf); |
| 460 | } |
| 461 | if (ret < 0) |
| 462 | goto out; |
| 463 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 464 | mutex_init(&chip->irq_lock); |
| 465 | chip->irq_base = pdata->irq_base; |
| 466 | chip->core_irq = i2c->irq; |
| 467 | if (!chip->core_irq) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 468 | goto out; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 469 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 470 | /* register IRQ by genirq */ |
| 471 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { |
| 472 | __irq = i + chip->irq_base; |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 473 | irq_set_chip_data(__irq, chip); |
| 474 | irq_set_chip_and_handler(__irq, &pm860x_irq_chip, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 475 | handle_edge_irq); |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 476 | irq_set_nested_thread(__irq, 1); |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 477 | #ifdef CONFIG_ARM |
| 478 | set_irq_flags(__irq, IRQF_VALID); |
| 479 | #else |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 480 | irq_set_noprobe(__irq); |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 481 | #endif |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 482 | } |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 483 | |
| 484 | ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags, |
| 485 | "88pm860x", chip); |
| 486 | if (ret) { |
| 487 | dev_err(chip->dev, "Failed to request IRQ: %d\n", ret); |
| 488 | chip->core_irq = 0; |
| 489 | } |
| 490 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 491 | return 0; |
| 492 | out: |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 493 | chip->core_irq = 0; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 494 | return ret; |
| 495 | } |
| 496 | |
Henrik Kretzschmar | 872c1b1 | 2010-03-26 02:40:13 +0100 | [diff] [blame] | 497 | static void device_irq_exit(struct pm860x_chip *chip) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 498 | { |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 499 | if (chip->core_irq) |
| 500 | free_irq(chip->core_irq, chip); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 501 | } |
| 502 | |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 503 | static void __devinit device_bk_init(struct pm860x_chip *chip, |
| 504 | struct i2c_client *i2c, |
| 505 | struct pm860x_platform_data *pdata) |
| 506 | { |
| 507 | int ret; |
| 508 | int i, j, id; |
| 509 | |
| 510 | if ((pdata == NULL) || (pdata->backlight == NULL)) |
| 511 | return; |
| 512 | |
| 513 | if (pdata->num_backlights > ARRAY_SIZE(bk_devs)) |
| 514 | pdata->num_backlights = ARRAY_SIZE(bk_devs); |
| 515 | |
| 516 | for (i = 0; i < pdata->num_backlights; i++) { |
| 517 | memcpy(&bk_pdata[i], &pdata->backlight[i], |
| 518 | sizeof(struct pm860x_backlight_pdata)); |
| 519 | bk_devs[i].mfd_data = &bk_pdata[i]; |
| 520 | |
| 521 | for (j = 0; j < ARRAY_SIZE(bk_devs); j++) { |
| 522 | id = bk_resources[j].start; |
| 523 | if (bk_pdata[i].flags != id) |
| 524 | continue; |
| 525 | |
| 526 | bk_devs[i].num_resources = 1; |
| 527 | bk_devs[i].resources = &bk_resources[j]; |
| 528 | ret = mfd_add_devices(chip->dev, 0, |
| 529 | &bk_devs[i], 1, |
| 530 | &bk_resources[j], 0); |
| 531 | if (ret < 0) { |
| 532 | dev_err(chip->dev, "Failed to add " |
| 533 | "backlight subdev\n"); |
| 534 | return; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 540 | static void __devinit device_led_init(struct pm860x_chip *chip, |
| 541 | struct i2c_client *i2c, |
| 542 | struct pm860x_platform_data *pdata) |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 543 | { |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 544 | int ret; |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 545 | int i, j, id; |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 546 | |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 547 | if ((pdata == NULL) || (pdata->led == NULL)) |
| 548 | return; |
| 549 | |
| 550 | if (pdata->num_leds > ARRAY_SIZE(led_devs)) |
| 551 | pdata->num_leds = ARRAY_SIZE(led_devs); |
| 552 | |
| 553 | for (i = 0; i < pdata->num_leds; i++) { |
| 554 | memcpy(&led_pdata[i], &pdata->led[i], |
| 555 | sizeof(struct pm860x_led_pdata)); |
| 556 | led_devs[i].mfd_data = &led_pdata[i]; |
| 557 | |
| 558 | for (j = 0; j < ARRAY_SIZE(led_devs); j++) { |
| 559 | id = led_resources[j].start; |
| 560 | if (led_pdata[i].flags != id) |
| 561 | continue; |
| 562 | |
| 563 | led_devs[i].num_resources = 1; |
| 564 | led_devs[i].resources = &led_resources[j], |
| 565 | ret = mfd_add_devices(chip->dev, 0, |
| 566 | &led_devs[i], 1, |
| 567 | &led_resources[j], 0); |
| 568 | if (ret < 0) { |
| 569 | dev_err(chip->dev, "Failed to add " |
| 570 | "led subdev\n"); |
| 571 | return; |
| 572 | } |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 573 | } |
| 574 | } |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 575 | } |
| 576 | |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 577 | static void __devinit device_regulator_init(struct pm860x_chip *chip, |
| 578 | struct i2c_client *i2c, |
| 579 | struct pm860x_platform_data *pdata) |
| 580 | { |
| 581 | struct regulator_init_data *initdata; |
| 582 | int ret; |
| 583 | int i, j; |
| 584 | |
| 585 | if ((pdata == NULL) || (pdata->regulator == NULL)) |
| 586 | return; |
| 587 | |
| 588 | if (pdata->num_regulators > ARRAY_SIZE(regulator_devs)) |
| 589 | pdata->num_regulators = ARRAY_SIZE(regulator_devs); |
| 590 | |
| 591 | for (i = 0, j = -1; i < pdata->num_regulators; i++) { |
| 592 | initdata = &pdata->regulator[i]; |
| 593 | if (strstr(initdata->constraints.name, "BUCK")) { |
| 594 | sscanf(initdata->constraints.name, "BUCK%d", &j); |
| 595 | /* BUCK1 ~ BUCK3 */ |
| 596 | if ((j < 1) || (j > 3)) { |
| 597 | dev_err(chip->dev, "Failed to add constraint " |
| 598 | "(%s)\n", initdata->constraints.name); |
| 599 | goto out; |
| 600 | } |
| 601 | j = (j - 1) + PM8607_ID_BUCK1; |
| 602 | } |
| 603 | if (strstr(initdata->constraints.name, "LDO")) { |
| 604 | sscanf(initdata->constraints.name, "LDO%d", &j); |
| 605 | /* LDO1 ~ LDO15 */ |
| 606 | if ((j < 1) || (j > 15)) { |
| 607 | dev_err(chip->dev, "Failed to add constraint " |
| 608 | "(%s)\n", initdata->constraints.name); |
| 609 | goto out; |
| 610 | } |
| 611 | j = (j - 1) + PM8607_ID_LDO1; |
| 612 | } |
| 613 | if (j == -1) { |
| 614 | dev_err(chip->dev, "Failed to add constraint (%s)\n", |
| 615 | initdata->constraints.name); |
| 616 | goto out; |
| 617 | } |
| 618 | memcpy(®ulator_pdata[i], &pdata->regulator[i], |
| 619 | sizeof(struct regulator_init_data)); |
| 620 | regulator_devs[i].mfd_data = ®ulator_pdata[i]; |
| 621 | regulator_devs[i].num_resources = 1; |
| 622 | regulator_devs[i].resources = ®ulator_resources[j]; |
| 623 | |
| 624 | ret = mfd_add_devices(chip->dev, 0, ®ulator_devs[i], 1, |
| 625 | ®ulator_resources[j], 0); |
| 626 | if (ret < 0) { |
| 627 | dev_err(chip->dev, "Failed to add regulator subdev\n"); |
| 628 | goto out; |
| 629 | } |
| 630 | } |
| 631 | out: |
| 632 | return; |
| 633 | } |
| 634 | |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 635 | static void __devinit device_touch_init(struct pm860x_chip *chip, |
| 636 | struct i2c_client *i2c, |
| 637 | struct pm860x_platform_data *pdata) |
| 638 | { |
| 639 | int ret; |
| 640 | |
| 641 | if ((pdata == NULL) || (pdata->touch == NULL)) |
| 642 | return; |
| 643 | |
| 644 | memcpy(&touch_pdata, pdata->touch, sizeof(struct pm860x_touch_pdata)); |
| 645 | touch_devs[0].mfd_data = &touch_pdata; |
| 646 | touch_devs[0].num_resources = ARRAY_SIZE(touch_resources); |
| 647 | touch_devs[0].resources = &touch_resources[0]; |
| 648 | ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], |
| 649 | ARRAY_SIZE(touch_devs), &touch_resources[0], |
| 650 | chip->irq_base); |
| 651 | if (ret < 0) |
| 652 | dev_err(chip->dev, "Failed to add touch subdev\n"); |
| 653 | } |
| 654 | |
| 655 | static void __devinit device_power_init(struct pm860x_chip *chip, |
| 656 | struct i2c_client *i2c, |
| 657 | struct pm860x_platform_data *pdata) |
| 658 | { |
| 659 | int ret; |
| 660 | |
| 661 | if ((pdata == NULL) || (pdata->power == NULL)) |
| 662 | return; |
| 663 | |
| 664 | memcpy(&power_pdata, pdata->power, sizeof(struct pm860x_power_pdata)); |
| 665 | power_devs[0].mfd_data = &power_pdata; |
| 666 | power_devs[0].num_resources = ARRAY_SIZE(battery_resources); |
| 667 | power_devs[0].resources = &battery_resources[0], |
| 668 | ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 1, |
| 669 | &battery_resources[0], chip->irq_base); |
| 670 | if (ret < 0) |
| 671 | dev_err(chip->dev, "Failed to add battery subdev\n"); |
| 672 | |
| 673 | power_devs[1].mfd_data = &power_pdata; |
| 674 | power_devs[1].num_resources = ARRAY_SIZE(charger_resources); |
| 675 | power_devs[1].resources = &charger_resources[0], |
| 676 | ret = mfd_add_devices(chip->dev, 0, &power_devs[1], 1, |
| 677 | &charger_resources[0], chip->irq_base); |
| 678 | if (ret < 0) |
| 679 | dev_err(chip->dev, "Failed to add charger subdev\n"); |
| 680 | } |
| 681 | |
| 682 | static void __devinit device_onkey_init(struct pm860x_chip *chip, |
| 683 | struct i2c_client *i2c, |
| 684 | struct pm860x_platform_data *pdata) |
| 685 | { |
| 686 | int ret; |
| 687 | |
| 688 | onkey_devs[0].num_resources = ARRAY_SIZE(onkey_resources); |
| 689 | onkey_devs[0].resources = &onkey_resources[0], |
| 690 | ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], |
| 691 | ARRAY_SIZE(onkey_devs), &onkey_resources[0], |
| 692 | chip->irq_base); |
| 693 | if (ret < 0) |
| 694 | dev_err(chip->dev, "Failed to add onkey subdev\n"); |
| 695 | } |
| 696 | |
| 697 | static void __devinit device_codec_init(struct pm860x_chip *chip, |
| 698 | struct i2c_client *i2c, |
| 699 | struct pm860x_platform_data *pdata) |
| 700 | { |
| 701 | int ret; |
| 702 | |
| 703 | codec_devs[0].num_resources = ARRAY_SIZE(codec_resources); |
| 704 | codec_devs[0].resources = &codec_resources[0], |
| 705 | ret = mfd_add_devices(chip->dev, 0, &codec_devs[0], |
| 706 | ARRAY_SIZE(codec_devs), &codec_resources[0], 0); |
| 707 | if (ret < 0) |
| 708 | dev_err(chip->dev, "Failed to add codec subdev\n"); |
| 709 | } |
| 710 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 711 | static void __devinit device_8607_init(struct pm860x_chip *chip, |
| 712 | struct i2c_client *i2c, |
| 713 | struct pm860x_platform_data *pdata) |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 714 | { |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 715 | int data, ret; |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 716 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 717 | ret = pm860x_reg_read(i2c, PM8607_CHIP_ID); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 718 | if (ret < 0) { |
| 719 | dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); |
| 720 | goto out; |
| 721 | } |
Haojian Zhuang | 38b3405 | 2010-09-08 09:44:34 -0400 | [diff] [blame] | 722 | switch (ret & PM8607_VERSION_MASK) { |
| 723 | case 0x40: |
| 724 | case 0x50: |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 725 | dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", |
| 726 | ret); |
Haojian Zhuang | 38b3405 | 2010-09-08 09:44:34 -0400 | [diff] [blame] | 727 | break; |
| 728 | default: |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 729 | dev_err(chip->dev, "Failed to detect Marvell 88PM8607. " |
| 730 | "Chip ID: %02x\n", ret); |
| 731 | goto out; |
| 732 | } |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 733 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 734 | ret = pm860x_reg_read(i2c, PM8607_BUCK3); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 735 | if (ret < 0) { |
| 736 | dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); |
| 737 | goto out; |
| 738 | } |
| 739 | if (ret & PM8607_BUCK3_DOUBLE) |
| 740 | chip->buck3_double = 1; |
| 741 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 742 | ret = pm860x_reg_read(i2c, PM8607_B0_MISC1); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 743 | if (ret < 0) { |
| 744 | dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); |
| 745 | goto out; |
| 746 | } |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 747 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 748 | if (pdata && (pdata->i2c_port == PI2C_PORT)) |
| 749 | data = PM8607_B0_MISC1_PI2C; |
| 750 | else |
| 751 | data = 0; |
| 752 | ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data); |
| 753 | if (ret < 0) { |
| 754 | dev_err(chip->dev, "Failed to access MISC1:%d\n", ret); |
| 755 | goto out; |
| 756 | } |
| 757 | |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 758 | ret = device_gpadc_init(chip, pdata); |
| 759 | if (ret < 0) |
| 760 | goto out; |
| 761 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 762 | ret = device_irq_init(chip, pdata); |
| 763 | if (ret < 0) |
| 764 | goto out; |
| 765 | |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 766 | device_regulator_init(chip, i2c, pdata); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 767 | device_onkey_init(chip, i2c, pdata); |
| 768 | device_touch_init(chip, i2c, pdata); |
| 769 | device_power_init(chip, i2c, pdata); |
| 770 | device_codec_init(chip, i2c, pdata); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 771 | out: |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 772 | return; |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 773 | } |
| 774 | |
Henrik Kretzschmar | 872c1b1 | 2010-03-26 02:40:13 +0100 | [diff] [blame] | 775 | int __devinit pm860x_device_init(struct pm860x_chip *chip, |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 776 | struct pm860x_platform_data *pdata) |
| 777 | { |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 778 | chip->core_irq = 0; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 779 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 780 | switch (chip->id) { |
| 781 | case CHIP_PM8606: |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 782 | device_bk_init(chip, chip->client, pdata); |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 783 | device_led_init(chip, chip->client, pdata); |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 784 | break; |
| 785 | case CHIP_PM8607: |
| 786 | device_8607_init(chip, chip->client, pdata); |
| 787 | break; |
| 788 | } |
| 789 | |
| 790 | if (chip->companion) { |
| 791 | switch (chip->id) { |
| 792 | case CHIP_PM8607: |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 793 | device_bk_init(chip, chip->companion, pdata); |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 794 | device_led_init(chip, chip->companion, pdata); |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 795 | break; |
| 796 | case CHIP_PM8606: |
| 797 | device_8607_init(chip, chip->companion, pdata); |
| 798 | break; |
| 799 | } |
| 800 | } |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 801 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 802 | return 0; |
| 803 | } |
| 804 | |
Henrik Kretzschmar | 872c1b1 | 2010-03-26 02:40:13 +0100 | [diff] [blame] | 805 | void __devexit pm860x_device_exit(struct pm860x_chip *chip) |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 806 | { |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 807 | device_irq_exit(chip); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 808 | mfd_remove_devices(chip->dev); |
| 809 | } |
| 810 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 811 | MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x"); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 812 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); |
| 813 | MODULE_LICENSE("GPL"); |