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 | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 14 | #include <linux/err.h> |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 15 | #include <linux/i2c.h> |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 16 | #include <linux/irq.h> |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Haojian Zhuang | 837c829 | 2012-10-02 10:23:20 +0800 | [diff] [blame] | 18 | #include <linux/irqdomain.h> |
Haojian Zhuang | 2e57d56 | 2012-09-21 18:06:52 +0800 | [diff] [blame] | 19 | #include <linux/of.h> |
| 20 | #include <linux/of_platform.h> |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 22 | #include <linux/regmap.h> |
| 23 | #include <linux/slab.h> |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 24 | #include <linux/mfd/core.h> |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 25 | #include <linux/mfd/88pm860x.h> |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 26 | #include <linux/regulator/machine.h> |
Jett.Zhou | a830d28 | 2012-07-27 16:27:16 +0800 | [diff] [blame] | 27 | #include <linux/power/charger-manager.h> |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 28 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 29 | #define INT_STATUS_NUM 3 |
| 30 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 31 | static struct resource bk0_resources[] = { |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 32 | {2, 2, "duty cycle", IORESOURCE_REG, }, |
| 33 | {3, 3, "always on", IORESOURCE_REG, }, |
| 34 | {3, 3, "current", IORESOURCE_REG, }, |
| 35 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 36 | static struct resource bk1_resources[] = { |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 37 | {4, 4, "duty cycle", IORESOURCE_REG, }, |
| 38 | {5, 5, "always on", IORESOURCE_REG, }, |
| 39 | {5, 5, "current", IORESOURCE_REG, }, |
| 40 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 41 | static struct resource bk2_resources[] = { |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 42 | {6, 6, "duty cycle", IORESOURCE_REG, }, |
| 43 | {7, 7, "always on", IORESOURCE_REG, }, |
| 44 | {5, 5, "current", IORESOURCE_REG, }, |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 45 | }; |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 46 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 47 | static struct resource led0_resources[] = { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 48 | /* RGB1 Red LED */ |
| 49 | {0xd, 0xd, "control", IORESOURCE_REG, }, |
| 50 | {0xc, 0xc, "blink", IORESOURCE_REG, }, |
| 51 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 52 | static struct resource led1_resources[] = { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 53 | /* RGB1 Green LED */ |
| 54 | {0xe, 0xe, "control", IORESOURCE_REG, }, |
| 55 | {0xc, 0xc, "blink", IORESOURCE_REG, }, |
| 56 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 57 | static struct resource led2_resources[] = { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 58 | /* RGB1 Blue LED */ |
| 59 | {0xf, 0xf, "control", IORESOURCE_REG, }, |
| 60 | {0xc, 0xc, "blink", IORESOURCE_REG, }, |
| 61 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 62 | static struct resource led3_resources[] = { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 63 | /* RGB2 Red LED */ |
| 64 | {0x9, 0x9, "control", IORESOURCE_REG, }, |
| 65 | {0x8, 0x8, "blink", IORESOURCE_REG, }, |
| 66 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 67 | static struct resource led4_resources[] = { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 68 | /* RGB2 Green LED */ |
| 69 | {0xa, 0xa, "control", IORESOURCE_REG, }, |
| 70 | {0x8, 0x8, "blink", IORESOURCE_REG, }, |
| 71 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 72 | static struct resource led5_resources[] = { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 73 | /* RGB2 Blue LED */ |
| 74 | {0xb, 0xb, "control", IORESOURCE_REG, }, |
| 75 | {0x8, 0x8, "blink", IORESOURCE_REG, }, |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 76 | }; |
| 77 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 78 | static struct resource buck1_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 79 | {0x24, 0x24, "buck set", IORESOURCE_REG, }, |
| 80 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 81 | static struct resource buck2_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 82 | {0x25, 0x25, "buck set", IORESOURCE_REG, }, |
| 83 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 84 | static struct resource buck3_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 85 | {0x26, 0x26, "buck set", IORESOURCE_REG, }, |
| 86 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 87 | static struct resource ldo1_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 88 | {0x10, 0x10, "ldo set", IORESOURCE_REG, }, |
| 89 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 90 | static struct resource ldo2_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 91 | {0x11, 0x11, "ldo set", IORESOURCE_REG, }, |
| 92 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 93 | static struct resource ldo3_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 94 | {0x12, 0x12, "ldo set", IORESOURCE_REG, }, |
| 95 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 96 | static struct resource ldo4_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 97 | {0x13, 0x13, "ldo set", IORESOURCE_REG, }, |
| 98 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 99 | static struct resource ldo5_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 100 | {0x14, 0x14, "ldo set", IORESOURCE_REG, }, |
| 101 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 102 | static struct resource ldo6_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 103 | {0x15, 0x15, "ldo set", IORESOURCE_REG, }, |
| 104 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 105 | static struct resource ldo7_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 106 | {0x16, 0x16, "ldo set", IORESOURCE_REG, }, |
| 107 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 108 | static struct resource ldo8_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 109 | {0x17, 0x17, "ldo set", IORESOURCE_REG, }, |
| 110 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 111 | static struct resource ldo9_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 112 | {0x18, 0x18, "ldo set", IORESOURCE_REG, }, |
| 113 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 114 | static struct resource ldo10_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 115 | {0x19, 0x19, "ldo set", IORESOURCE_REG, }, |
| 116 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 117 | static struct resource ldo12_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 118 | {0x1a, 0x1a, "ldo set", IORESOURCE_REG, }, |
| 119 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 120 | static struct resource ldo_vibrator_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 121 | {0x28, 0x28, "ldo set", IORESOURCE_REG, }, |
| 122 | }; |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 123 | static struct resource ldo14_resources[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 124 | {0x1b, 0x1b, "ldo set", IORESOURCE_REG, }, |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 125 | }; |
| 126 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 127 | static struct resource touch_resources[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 128 | {PM8607_IRQ_PEN, PM8607_IRQ_PEN, "touch", IORESOURCE_IRQ,}, |
| 129 | }; |
| 130 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 131 | static struct resource onkey_resources[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 132 | {PM8607_IRQ_ONKEY, PM8607_IRQ_ONKEY, "onkey", IORESOURCE_IRQ,}, |
| 133 | }; |
| 134 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 135 | static struct resource codec_resources[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 136 | /* Headset microphone insertion or removal */ |
| 137 | {PM8607_IRQ_MICIN, PM8607_IRQ_MICIN, "micin", IORESOURCE_IRQ,}, |
| 138 | /* Hook-switch press or release */ |
| 139 | {PM8607_IRQ_HOOK, PM8607_IRQ_HOOK, "hook", IORESOURCE_IRQ,}, |
| 140 | /* Headset insertion or removal */ |
| 141 | {PM8607_IRQ_HEADSET, PM8607_IRQ_HEADSET, "headset", IORESOURCE_IRQ,}, |
| 142 | /* Audio short */ |
| 143 | {PM8607_IRQ_AUDIO_SHORT, PM8607_IRQ_AUDIO_SHORT, "audio-short", IORESOURCE_IRQ,}, |
| 144 | }; |
| 145 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 146 | static struct resource battery_resources[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 147 | {PM8607_IRQ_CC, PM8607_IRQ_CC, "columb counter", IORESOURCE_IRQ,}, |
| 148 | {PM8607_IRQ_BAT, PM8607_IRQ_BAT, "battery", IORESOURCE_IRQ,}, |
| 149 | }; |
| 150 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 151 | static struct resource charger_resources[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 152 | {PM8607_IRQ_CHG, PM8607_IRQ_CHG, "charger detect", IORESOURCE_IRQ,}, |
| 153 | {PM8607_IRQ_CHG_DONE, PM8607_IRQ_CHG_DONE, "charging done", IORESOURCE_IRQ,}, |
Jett.Zhou | a830d28 | 2012-07-27 16:27:16 +0800 | [diff] [blame] | 154 | {PM8607_IRQ_CHG_FAIL, PM8607_IRQ_CHG_FAIL, "charging timeout", IORESOURCE_IRQ,}, |
| 155 | {PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging fault", IORESOURCE_IRQ,}, |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 156 | {PM8607_IRQ_GPADC1, PM8607_IRQ_GPADC1, "battery temperature", IORESOURCE_IRQ,}, |
| 157 | {PM8607_IRQ_VBAT, PM8607_IRQ_VBAT, "battery voltage", IORESOURCE_IRQ,}, |
| 158 | {PM8607_IRQ_VCHG, PM8607_IRQ_VCHG, "vchg voltage", IORESOURCE_IRQ,}, |
| 159 | }; |
| 160 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 161 | static struct resource rtc_resources[] = { |
Mark Brown | 0236702 | 2012-08-07 19:42:48 +0100 | [diff] [blame] | 162 | {PM8607_IRQ_RTC, PM8607_IRQ_RTC, "rtc", IORESOURCE_IRQ,}, |
Haojian Zhuang | 008b304 | 2011-05-06 17:21:20 +0800 | [diff] [blame] | 163 | }; |
| 164 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 165 | static struct mfd_cell bk_devs[] = { |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 166 | { |
| 167 | .name = "88pm860x-backlight", |
| 168 | .id = 0, |
| 169 | .num_resources = ARRAY_SIZE(bk0_resources), |
| 170 | .resources = bk0_resources, |
| 171 | }, { |
| 172 | .name = "88pm860x-backlight", |
| 173 | .id = 1, |
| 174 | .num_resources = ARRAY_SIZE(bk1_resources), |
| 175 | .resources = bk1_resources, |
| 176 | }, { |
| 177 | .name = "88pm860x-backlight", |
| 178 | .id = 2, |
| 179 | .num_resources = ARRAY_SIZE(bk2_resources), |
| 180 | .resources = bk2_resources, |
| 181 | }, |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 182 | }; |
| 183 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 184 | static struct mfd_cell led_devs[] = { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 185 | { |
| 186 | .name = "88pm860x-led", |
| 187 | .id = 0, |
| 188 | .num_resources = ARRAY_SIZE(led0_resources), |
| 189 | .resources = led0_resources, |
| 190 | }, { |
| 191 | .name = "88pm860x-led", |
| 192 | .id = 1, |
| 193 | .num_resources = ARRAY_SIZE(led1_resources), |
| 194 | .resources = led1_resources, |
| 195 | }, { |
| 196 | .name = "88pm860x-led", |
| 197 | .id = 2, |
| 198 | .num_resources = ARRAY_SIZE(led2_resources), |
| 199 | .resources = led2_resources, |
| 200 | }, { |
| 201 | .name = "88pm860x-led", |
| 202 | .id = 3, |
| 203 | .num_resources = ARRAY_SIZE(led3_resources), |
| 204 | .resources = led3_resources, |
| 205 | }, { |
| 206 | .name = "88pm860x-led", |
| 207 | .id = 4, |
| 208 | .num_resources = ARRAY_SIZE(led4_resources), |
| 209 | .resources = led4_resources, |
| 210 | }, { |
| 211 | .name = "88pm860x-led", |
| 212 | .id = 5, |
| 213 | .num_resources = ARRAY_SIZE(led5_resources), |
| 214 | .resources = led5_resources, |
| 215 | }, |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 216 | }; |
| 217 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 218 | static struct mfd_cell reg_devs[] = { |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 219 | { |
| 220 | .name = "88pm860x-regulator", |
| 221 | .id = 0, |
| 222 | .num_resources = ARRAY_SIZE(buck1_resources), |
| 223 | .resources = buck1_resources, |
| 224 | }, { |
| 225 | .name = "88pm860x-regulator", |
| 226 | .id = 1, |
| 227 | .num_resources = ARRAY_SIZE(buck2_resources), |
| 228 | .resources = buck2_resources, |
| 229 | }, { |
| 230 | .name = "88pm860x-regulator", |
| 231 | .id = 2, |
| 232 | .num_resources = ARRAY_SIZE(buck3_resources), |
| 233 | .resources = buck3_resources, |
| 234 | }, { |
| 235 | .name = "88pm860x-regulator", |
| 236 | .id = 3, |
| 237 | .num_resources = ARRAY_SIZE(ldo1_resources), |
| 238 | .resources = ldo1_resources, |
| 239 | }, { |
| 240 | .name = "88pm860x-regulator", |
| 241 | .id = 4, |
| 242 | .num_resources = ARRAY_SIZE(ldo2_resources), |
| 243 | .resources = ldo2_resources, |
| 244 | }, { |
| 245 | .name = "88pm860x-regulator", |
| 246 | .id = 5, |
| 247 | .num_resources = ARRAY_SIZE(ldo3_resources), |
| 248 | .resources = ldo3_resources, |
| 249 | }, { |
| 250 | .name = "88pm860x-regulator", |
| 251 | .id = 6, |
| 252 | .num_resources = ARRAY_SIZE(ldo4_resources), |
| 253 | .resources = ldo4_resources, |
| 254 | }, { |
| 255 | .name = "88pm860x-regulator", |
| 256 | .id = 7, |
| 257 | .num_resources = ARRAY_SIZE(ldo5_resources), |
| 258 | .resources = ldo5_resources, |
| 259 | }, { |
| 260 | .name = "88pm860x-regulator", |
| 261 | .id = 8, |
| 262 | .num_resources = ARRAY_SIZE(ldo6_resources), |
| 263 | .resources = ldo6_resources, |
| 264 | }, { |
| 265 | .name = "88pm860x-regulator", |
| 266 | .id = 9, |
| 267 | .num_resources = ARRAY_SIZE(ldo7_resources), |
| 268 | .resources = ldo7_resources, |
| 269 | }, { |
| 270 | .name = "88pm860x-regulator", |
| 271 | .id = 10, |
| 272 | .num_resources = ARRAY_SIZE(ldo8_resources), |
| 273 | .resources = ldo8_resources, |
| 274 | }, { |
| 275 | .name = "88pm860x-regulator", |
| 276 | .id = 11, |
| 277 | .num_resources = ARRAY_SIZE(ldo9_resources), |
| 278 | .resources = ldo9_resources, |
| 279 | }, { |
| 280 | .name = "88pm860x-regulator", |
| 281 | .id = 12, |
| 282 | .num_resources = ARRAY_SIZE(ldo10_resources), |
| 283 | .resources = ldo10_resources, |
| 284 | }, { |
| 285 | .name = "88pm860x-regulator", |
| 286 | .id = 13, |
| 287 | .num_resources = ARRAY_SIZE(ldo12_resources), |
| 288 | .resources = ldo12_resources, |
| 289 | }, { |
| 290 | .name = "88pm860x-regulator", |
| 291 | .id = 14, |
| 292 | .num_resources = ARRAY_SIZE(ldo_vibrator_resources), |
| 293 | .resources = ldo_vibrator_resources, |
| 294 | }, { |
| 295 | .name = "88pm860x-regulator", |
| 296 | .id = 15, |
| 297 | .num_resources = ARRAY_SIZE(ldo14_resources), |
| 298 | .resources = ldo14_resources, |
| 299 | }, |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 300 | }; |
| 301 | |
Haojian Zhuang | a5156f1 | 2011-04-26 11:06:22 +0200 | [diff] [blame] | 302 | static struct mfd_cell touch_devs[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 303 | {"88pm860x-touch", -1,}, |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 304 | }; |
| 305 | |
Haojian Zhuang | a5156f1 | 2011-04-26 11:06:22 +0200 | [diff] [blame] | 306 | static struct mfd_cell onkey_devs[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 307 | {"88pm860x-onkey", -1,}, |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 308 | }; |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 309 | |
Haojian Zhuang | a5156f1 | 2011-04-26 11:06:22 +0200 | [diff] [blame] | 310 | static struct mfd_cell codec_devs[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 311 | {"88pm860x-codec", -1,}, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 312 | }; |
| 313 | |
Jett.Zhou | 2573f6d | 2012-07-06 10:59:58 +0800 | [diff] [blame] | 314 | static struct regulator_consumer_supply preg_supply[] = { |
| 315 | REGULATOR_SUPPLY("preg", "charger-manager"), |
| 316 | }; |
| 317 | |
| 318 | static struct regulator_init_data preg_init_data = { |
| 319 | .num_consumer_supplies = ARRAY_SIZE(preg_supply), |
| 320 | .consumer_supplies = &preg_supply[0], |
| 321 | }; |
| 322 | |
Anton Vorontsov | f1ade35 | 2012-08-22 20:31:33 -0700 | [diff] [blame] | 323 | static struct charger_regulator chg_desc_regulator_data[] = { |
| 324 | { .regulator_name = "preg", }, |
Jett.Zhou | a830d28 | 2012-07-27 16:27:16 +0800 | [diff] [blame] | 325 | }; |
| 326 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 327 | static struct mfd_cell power_devs[] = { |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 328 | {"88pm860x-battery", -1,}, |
| 329 | {"88pm860x-charger", -1,}, |
Jett.Zhou | 2573f6d | 2012-07-06 10:59:58 +0800 | [diff] [blame] | 330 | {"88pm860x-preg", -1,}, |
Jett.Zhou | a830d28 | 2012-07-27 16:27:16 +0800 | [diff] [blame] | 331 | {"charger-manager", -1,}, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 332 | }; |
| 333 | |
Haojian Zhuang | 008b304 | 2011-05-06 17:21:20 +0800 | [diff] [blame] | 334 | static struct mfd_cell rtc_devs[] = { |
| 335 | {"88pm860x-rtc", -1,}, |
| 336 | }; |
| 337 | |
Haojian Zhuang | 2c36af7 | 2010-08-12 11:59:33 +0800 | [diff] [blame] | 338 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 339 | struct pm860x_irq_data { |
| 340 | int reg; |
| 341 | int mask_reg; |
| 342 | int enable; /* enable or not */ |
| 343 | int offs; /* bit offset in mask register */ |
| 344 | }; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 345 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 346 | static struct pm860x_irq_data pm860x_irqs[] = { |
| 347 | [PM8607_IRQ_ONKEY] = { |
| 348 | .reg = PM8607_INT_STATUS1, |
| 349 | .mask_reg = PM8607_INT_MASK_1, |
| 350 | .offs = 1 << 0, |
| 351 | }, |
| 352 | [PM8607_IRQ_EXTON] = { |
| 353 | .reg = PM8607_INT_STATUS1, |
| 354 | .mask_reg = PM8607_INT_MASK_1, |
| 355 | .offs = 1 << 1, |
| 356 | }, |
| 357 | [PM8607_IRQ_CHG] = { |
| 358 | .reg = PM8607_INT_STATUS1, |
| 359 | .mask_reg = PM8607_INT_MASK_1, |
| 360 | .offs = 1 << 2, |
| 361 | }, |
| 362 | [PM8607_IRQ_BAT] = { |
| 363 | .reg = PM8607_INT_STATUS1, |
| 364 | .mask_reg = PM8607_INT_MASK_1, |
| 365 | .offs = 1 << 3, |
| 366 | }, |
| 367 | [PM8607_IRQ_RTC] = { |
| 368 | .reg = PM8607_INT_STATUS1, |
| 369 | .mask_reg = PM8607_INT_MASK_1, |
| 370 | .offs = 1 << 4, |
| 371 | }, |
| 372 | [PM8607_IRQ_CC] = { |
| 373 | .reg = PM8607_INT_STATUS1, |
| 374 | .mask_reg = PM8607_INT_MASK_1, |
| 375 | .offs = 1 << 5, |
| 376 | }, |
| 377 | [PM8607_IRQ_VBAT] = { |
| 378 | .reg = PM8607_INT_STATUS2, |
| 379 | .mask_reg = PM8607_INT_MASK_2, |
| 380 | .offs = 1 << 0, |
| 381 | }, |
| 382 | [PM8607_IRQ_VCHG] = { |
| 383 | .reg = PM8607_INT_STATUS2, |
| 384 | .mask_reg = PM8607_INT_MASK_2, |
| 385 | .offs = 1 << 1, |
| 386 | }, |
| 387 | [PM8607_IRQ_VSYS] = { |
| 388 | .reg = PM8607_INT_STATUS2, |
| 389 | .mask_reg = PM8607_INT_MASK_2, |
| 390 | .offs = 1 << 2, |
| 391 | }, |
| 392 | [PM8607_IRQ_TINT] = { |
| 393 | .reg = PM8607_INT_STATUS2, |
| 394 | .mask_reg = PM8607_INT_MASK_2, |
| 395 | .offs = 1 << 3, |
| 396 | }, |
| 397 | [PM8607_IRQ_GPADC0] = { |
| 398 | .reg = PM8607_INT_STATUS2, |
| 399 | .mask_reg = PM8607_INT_MASK_2, |
| 400 | .offs = 1 << 4, |
| 401 | }, |
| 402 | [PM8607_IRQ_GPADC1] = { |
| 403 | .reg = PM8607_INT_STATUS2, |
| 404 | .mask_reg = PM8607_INT_MASK_2, |
| 405 | .offs = 1 << 5, |
| 406 | }, |
| 407 | [PM8607_IRQ_GPADC2] = { |
| 408 | .reg = PM8607_INT_STATUS2, |
| 409 | .mask_reg = PM8607_INT_MASK_2, |
| 410 | .offs = 1 << 6, |
| 411 | }, |
| 412 | [PM8607_IRQ_GPADC3] = { |
| 413 | .reg = PM8607_INT_STATUS2, |
| 414 | .mask_reg = PM8607_INT_MASK_2, |
| 415 | .offs = 1 << 7, |
| 416 | }, |
| 417 | [PM8607_IRQ_AUDIO_SHORT] = { |
| 418 | .reg = PM8607_INT_STATUS3, |
| 419 | .mask_reg = PM8607_INT_MASK_3, |
| 420 | .offs = 1 << 0, |
| 421 | }, |
| 422 | [PM8607_IRQ_PEN] = { |
| 423 | .reg = PM8607_INT_STATUS3, |
| 424 | .mask_reg = PM8607_INT_MASK_3, |
| 425 | .offs = 1 << 1, |
| 426 | }, |
| 427 | [PM8607_IRQ_HEADSET] = { |
| 428 | .reg = PM8607_INT_STATUS3, |
| 429 | .mask_reg = PM8607_INT_MASK_3, |
| 430 | .offs = 1 << 2, |
| 431 | }, |
| 432 | [PM8607_IRQ_HOOK] = { |
| 433 | .reg = PM8607_INT_STATUS3, |
| 434 | .mask_reg = PM8607_INT_MASK_3, |
| 435 | .offs = 1 << 3, |
| 436 | }, |
| 437 | [PM8607_IRQ_MICIN] = { |
| 438 | .reg = PM8607_INT_STATUS3, |
| 439 | .mask_reg = PM8607_INT_MASK_3, |
| 440 | .offs = 1 << 4, |
| 441 | }, |
| 442 | [PM8607_IRQ_CHG_FAIL] = { |
| 443 | .reg = PM8607_INT_STATUS3, |
| 444 | .mask_reg = PM8607_INT_MASK_3, |
| 445 | .offs = 1 << 5, |
| 446 | }, |
| 447 | [PM8607_IRQ_CHG_DONE] = { |
| 448 | .reg = PM8607_INT_STATUS3, |
| 449 | .mask_reg = PM8607_INT_MASK_3, |
| 450 | .offs = 1 << 6, |
| 451 | }, |
| 452 | [PM8607_IRQ_CHG_FAULT] = { |
| 453 | .reg = PM8607_INT_STATUS3, |
| 454 | .mask_reg = PM8607_INT_MASK_3, |
| 455 | .offs = 1 << 7, |
| 456 | }, |
| 457 | }; |
| 458 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 459 | static irqreturn_t pm860x_irq(int irq, void *data) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 460 | { |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 461 | struct pm860x_chip *chip = data; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 462 | struct pm860x_irq_data *irq_data; |
| 463 | struct i2c_client *i2c; |
| 464 | int read_reg = -1, value = 0; |
| 465 | int i; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 466 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 467 | i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; |
| 468 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { |
| 469 | irq_data = &pm860x_irqs[i]; |
| 470 | if (read_reg != irq_data->reg) { |
| 471 | read_reg = irq_data->reg; |
| 472 | value = pm860x_reg_read(i2c, irq_data->reg); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 473 | } |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 474 | if (value & irq_data->enable) |
| 475 | handle_nested_irq(chip->irq_base + i); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 476 | } |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 477 | return IRQ_HANDLED; |
| 478 | } |
| 479 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 480 | static void pm860x_irq_lock(struct irq_data *data) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 481 | { |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 482 | struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 483 | |
| 484 | mutex_lock(&chip->irq_lock); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 485 | } |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 486 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 487 | static void pm860x_irq_sync_unlock(struct irq_data *data) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 488 | { |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 489 | struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 490 | struct pm860x_irq_data *irq_data; |
| 491 | struct i2c_client *i2c; |
| 492 | static unsigned char cached[3] = {0x0, 0x0, 0x0}; |
| 493 | unsigned char mask[3]; |
| 494 | int i; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 495 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 496 | i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; |
| 497 | /* Load cached value. In initial, all IRQs are masked */ |
| 498 | for (i = 0; i < 3; i++) |
| 499 | mask[i] = cached[i]; |
| 500 | for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { |
| 501 | irq_data = &pm860x_irqs[i]; |
| 502 | switch (irq_data->mask_reg) { |
| 503 | case PM8607_INT_MASK_1: |
| 504 | mask[0] &= ~irq_data->offs; |
| 505 | mask[0] |= irq_data->enable; |
| 506 | break; |
| 507 | case PM8607_INT_MASK_2: |
| 508 | mask[1] &= ~irq_data->offs; |
| 509 | mask[1] |= irq_data->enable; |
| 510 | break; |
| 511 | case PM8607_INT_MASK_3: |
| 512 | mask[2] &= ~irq_data->offs; |
| 513 | mask[2] |= irq_data->enable; |
| 514 | break; |
| 515 | default: |
| 516 | dev_err(chip->dev, "wrong IRQ\n"); |
| 517 | break; |
| 518 | } |
| 519 | } |
| 520 | /* update mask into registers */ |
| 521 | for (i = 0; i < 3; i++) { |
| 522 | if (mask[i] != cached[i]) { |
| 523 | cached[i] = mask[i]; |
| 524 | pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]); |
| 525 | } |
| 526 | } |
| 527 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 528 | mutex_unlock(&chip->irq_lock); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 529 | } |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 530 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 531 | static void pm860x_irq_enable(struct irq_data *data) |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 532 | { |
Haojian Zhuang | 837c829 | 2012-10-02 10:23:20 +0800 | [diff] [blame] | 533 | pm860x_irqs[data->hwirq].enable = pm860x_irqs[data->hwirq].offs; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 534 | } |
| 535 | |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 536 | static void pm860x_irq_disable(struct irq_data *data) |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 537 | { |
Haojian Zhuang | 837c829 | 2012-10-02 10:23:20 +0800 | [diff] [blame] | 538 | pm860x_irqs[data->hwirq].enable = 0; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static struct irq_chip pm860x_irq_chip = { |
| 542 | .name = "88pm860x", |
Mark Brown | 49f89d9 | 2010-12-11 12:31:31 +0000 | [diff] [blame] | 543 | .irq_bus_lock = pm860x_irq_lock, |
| 544 | .irq_bus_sync_unlock = pm860x_irq_sync_unlock, |
| 545 | .irq_enable = pm860x_irq_enable, |
| 546 | .irq_disable = pm860x_irq_disable, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 547 | }; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 548 | |
Haojian Zhuang | 837c829 | 2012-10-02 10:23:20 +0800 | [diff] [blame] | 549 | static int pm860x_irq_domain_map(struct irq_domain *d, unsigned int virq, |
| 550 | irq_hw_number_t hw) |
| 551 | { |
| 552 | irq_set_chip_data(virq, d->host_data); |
| 553 | irq_set_chip_and_handler(virq, &pm860x_irq_chip, handle_edge_irq); |
| 554 | irq_set_nested_thread(virq, 1); |
| 555 | #ifdef CONFIG_ARM |
| 556 | set_irq_flags(virq, IRQF_VALID); |
| 557 | #else |
| 558 | irq_set_noprobe(virq); |
| 559 | #endif |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | static struct irq_domain_ops pm860x_irq_domain_ops = { |
| 564 | .map = pm860x_irq_domain_map, |
| 565 | .xlate = irq_domain_xlate_onetwocell, |
| 566 | }; |
| 567 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 568 | static int device_irq_init(struct pm860x_chip *chip, |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 569 | struct pm860x_platform_data *pdata) |
| 570 | { |
| 571 | struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ |
| 572 | : chip->companion; |
| 573 | unsigned char status_buf[INT_STATUS_NUM]; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 574 | unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; |
Haojian Zhuang | 837c829 | 2012-10-02 10:23:20 +0800 | [diff] [blame] | 575 | int data, mask, ret = -EINVAL; |
| 576 | int nr_irqs, irq_base = -1; |
| 577 | struct device_node *node = i2c->dev.of_node; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 578 | |
| 579 | mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR |
| 580 | | PM8607_B0_MISC1_INT_MASK; |
| 581 | data = 0; |
| 582 | chip->irq_mode = 0; |
| 583 | if (pdata && pdata->irq_mode) { |
| 584 | /* |
| 585 | * irq_mode defines the way of clearing interrupt. If it's 1, |
| 586 | * clear IRQ by write. Otherwise, clear it by read. |
| 587 | * This control bit is valid from 88PM8607 B0 steping. |
| 588 | */ |
| 589 | data |= PM8607_B0_MISC1_INT_CLEAR; |
| 590 | chip->irq_mode = 1; |
| 591 | } |
| 592 | ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data); |
| 593 | if (ret < 0) |
| 594 | goto out; |
| 595 | |
| 596 | /* mask all IRQs */ |
| 597 | memset(status_buf, 0, INT_STATUS_NUM); |
| 598 | ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1, |
| 599 | INT_STATUS_NUM, status_buf); |
| 600 | if (ret < 0) |
| 601 | goto out; |
| 602 | |
| 603 | if (chip->irq_mode) { |
| 604 | /* clear interrupt status by write */ |
| 605 | memset(status_buf, 0xFF, INT_STATUS_NUM); |
| 606 | ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1, |
| 607 | INT_STATUS_NUM, status_buf); |
| 608 | } else { |
| 609 | /* clear interrupt status by read */ |
| 610 | ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1, |
| 611 | INT_STATUS_NUM, status_buf); |
| 612 | } |
| 613 | if (ret < 0) |
| 614 | goto out; |
| 615 | |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 616 | mutex_init(&chip->irq_lock); |
Haojian Zhuang | 837c829 | 2012-10-02 10:23:20 +0800 | [diff] [blame] | 617 | |
| 618 | if (pdata && pdata->irq_base) |
| 619 | irq_base = pdata->irq_base; |
| 620 | nr_irqs = ARRAY_SIZE(pm860x_irqs); |
| 621 | chip->irq_base = irq_alloc_descs(irq_base, 0, nr_irqs, 0); |
| 622 | if (chip->irq_base < 0) { |
| 623 | dev_err(&i2c->dev, "Failed to allocate interrupts, ret:%d\n", |
| 624 | chip->irq_base); |
| 625 | ret = -EBUSY; |
| 626 | goto out; |
| 627 | } |
| 628 | irq_domain_add_legacy(node, nr_irqs, chip->irq_base, 0, |
| 629 | &pm860x_irq_domain_ops, chip); |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 630 | chip->core_irq = i2c->irq; |
| 631 | if (!chip->core_irq) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 632 | goto out; |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 633 | |
Fengguang Wu | 5016498 | 2012-09-19 09:30:51 +0800 | [diff] [blame] | 634 | ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags | IRQF_ONESHOT, |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 635 | "88pm860x", chip); |
| 636 | if (ret) { |
| 637 | dev_err(chip->dev, "Failed to request IRQ: %d\n", ret); |
| 638 | chip->core_irq = 0; |
| 639 | } |
| 640 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 641 | return 0; |
| 642 | out: |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 643 | chip->core_irq = 0; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 644 | return ret; |
| 645 | } |
| 646 | |
Henrik Kretzschmar | 872c1b1 | 2010-03-26 02:40:13 +0100 | [diff] [blame] | 647 | static void device_irq_exit(struct pm860x_chip *chip) |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 648 | { |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 649 | if (chip->core_irq) |
| 650 | free_irq(chip->core_irq, chip); |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 651 | } |
| 652 | |
Jett.Zhou | 23de435 | 2012-03-01 11:59:19 +0100 | [diff] [blame] | 653 | int pm8606_osc_enable(struct pm860x_chip *chip, unsigned short client) |
| 654 | { |
| 655 | int ret = -EIO; |
| 656 | struct i2c_client *i2c = (chip->id == CHIP_PM8606) ? |
| 657 | chip->client : chip->companion; |
| 658 | |
| 659 | dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client); |
| 660 | dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n", |
| 661 | __func__, chip->osc_vote, |
| 662 | chip->osc_status); |
| 663 | |
| 664 | mutex_lock(&chip->osc_lock); |
| 665 | /* Update voting status */ |
| 666 | chip->osc_vote |= client; |
| 667 | /* If reference group is off - turn on*/ |
| 668 | if (chip->osc_status != PM8606_REF_GP_OSC_ON) { |
| 669 | chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN; |
| 670 | /* Enable Reference group Vsys */ |
| 671 | if (pm860x_set_bits(i2c, PM8606_VSYS, |
| 672 | PM8606_VSYS_EN, PM8606_VSYS_EN)) |
| 673 | goto out; |
| 674 | |
| 675 | /*Enable Internal Oscillator */ |
| 676 | if (pm860x_set_bits(i2c, PM8606_MISC, |
| 677 | PM8606_MISC_OSC_EN, PM8606_MISC_OSC_EN)) |
| 678 | goto out; |
| 679 | /* Update status (only if writes succeed) */ |
| 680 | chip->osc_status = PM8606_REF_GP_OSC_ON; |
| 681 | } |
| 682 | mutex_unlock(&chip->osc_lock); |
| 683 | |
| 684 | dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n", |
| 685 | __func__, chip->osc_vote, |
| 686 | chip->osc_status, ret); |
| 687 | return 0; |
| 688 | out: |
| 689 | mutex_unlock(&chip->osc_lock); |
| 690 | return ret; |
| 691 | } |
Samuel Ortiz | 2f5f89b | 2012-03-06 08:06:14 +0100 | [diff] [blame] | 692 | EXPORT_SYMBOL(pm8606_osc_enable); |
Jett.Zhou | 23de435 | 2012-03-01 11:59:19 +0100 | [diff] [blame] | 693 | |
| 694 | int pm8606_osc_disable(struct pm860x_chip *chip, unsigned short client) |
| 695 | { |
| 696 | int ret = -EIO; |
| 697 | struct i2c_client *i2c = (chip->id == CHIP_PM8606) ? |
| 698 | chip->client : chip->companion; |
| 699 | |
| 700 | dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client); |
| 701 | dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n", |
| 702 | __func__, chip->osc_vote, |
| 703 | chip->osc_status); |
| 704 | |
| 705 | mutex_lock(&chip->osc_lock); |
| 706 | /*Update voting status */ |
| 707 | chip->osc_vote &= ~(client); |
| 708 | /* If reference group is off and this is the last client to release |
| 709 | * - turn off */ |
| 710 | if ((chip->osc_status != PM8606_REF_GP_OSC_OFF) && |
| 711 | (chip->osc_vote == REF_GP_NO_CLIENTS)) { |
| 712 | chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN; |
| 713 | /* Disable Reference group Vsys */ |
| 714 | if (pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0)) |
| 715 | goto out; |
| 716 | /* Disable Internal Oscillator */ |
| 717 | if (pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0)) |
| 718 | goto out; |
| 719 | chip->osc_status = PM8606_REF_GP_OSC_OFF; |
| 720 | } |
| 721 | mutex_unlock(&chip->osc_lock); |
| 722 | |
| 723 | dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n", |
| 724 | __func__, chip->osc_vote, |
| 725 | chip->osc_status, ret); |
| 726 | return 0; |
| 727 | out: |
| 728 | mutex_unlock(&chip->osc_lock); |
| 729 | return ret; |
| 730 | } |
Samuel Ortiz | 2f5f89b | 2012-03-06 08:06:14 +0100 | [diff] [blame] | 731 | EXPORT_SYMBOL(pm8606_osc_disable); |
Jett.Zhou | 23de435 | 2012-03-01 11:59:19 +0100 | [diff] [blame] | 732 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 733 | static void device_osc_init(struct i2c_client *i2c) |
Jett.Zhou | 23de435 | 2012-03-01 11:59:19 +0100 | [diff] [blame] | 734 | { |
| 735 | struct pm860x_chip *chip = i2c_get_clientdata(i2c); |
| 736 | |
| 737 | mutex_init(&chip->osc_lock); |
| 738 | /* init portofino reference group voting and status */ |
| 739 | /* Disable Reference group Vsys */ |
| 740 | pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0); |
| 741 | /* Disable Internal Oscillator */ |
| 742 | pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0); |
| 743 | |
| 744 | chip->osc_vote = REF_GP_NO_CLIENTS; |
| 745 | chip->osc_status = PM8606_REF_GP_OSC_OFF; |
| 746 | } |
| 747 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 748 | static void device_bk_init(struct pm860x_chip *chip, |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 749 | struct pm860x_platform_data *pdata) |
| 750 | { |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 751 | int ret, i; |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 752 | |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 753 | if (pdata && pdata->backlight) { |
| 754 | if (pdata->num_backlights > ARRAY_SIZE(bk_devs)) |
| 755 | pdata->num_backlights = ARRAY_SIZE(bk_devs); |
| 756 | for (i = 0; i < pdata->num_backlights; i++) { |
| 757 | bk_devs[i].platform_data = &pdata->backlight[i]; |
| 758 | bk_devs[i].pdata_size = |
| 759 | sizeof(struct pm860x_backlight_pdata); |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 760 | } |
| 761 | } |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 762 | ret = mfd_add_devices(chip->dev, 0, bk_devs, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 763 | ARRAY_SIZE(bk_devs), NULL, 0, NULL); |
Haojian Zhuang | a6ccdcd | 2012-08-08 23:17:26 +0800 | [diff] [blame] | 764 | if (ret < 0) |
| 765 | dev_err(chip->dev, "Failed to add backlight subdev\n"); |
Haojian Zhuang | adb7048 | 2011-03-07 23:43:09 +0800 | [diff] [blame] | 766 | } |
| 767 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 768 | static void device_led_init(struct pm860x_chip *chip, |
Haojian Zhuang | 3154c34 | 2011-03-07 23:43:10 +0800 | [diff] [blame] | 769 | struct pm860x_platform_data *pdata) |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 770 | { |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 771 | int ret, i; |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 772 | |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 773 | if (pdata && pdata->led) { |
| 774 | if (pdata->num_leds > ARRAY_SIZE(led_devs)) |
| 775 | pdata->num_leds = ARRAY_SIZE(led_devs); |
| 776 | for (i = 0; i < pdata->num_leds; i++) { |
| 777 | led_devs[i].platform_data = &pdata->led[i]; |
| 778 | led_devs[i].pdata_size = |
| 779 | sizeof(struct pm860x_led_pdata); |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 780 | } |
| 781 | } |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 782 | ret = mfd_add_devices(chip->dev, 0, led_devs, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 783 | ARRAY_SIZE(led_devs), NULL, 0, NULL); |
Haojian Zhuang | 894fc8f | 2012-08-08 23:17:27 +0800 | [diff] [blame] | 784 | if (ret < 0) { |
| 785 | dev_err(chip->dev, "Failed to add led subdev\n"); |
| 786 | return; |
| 787 | } |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 788 | } |
| 789 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 790 | static void device_regulator_init(struct pm860x_chip *chip, |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 791 | struct pm860x_platform_data *pdata) |
| 792 | { |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 793 | int ret; |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 794 | |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 795 | if (pdata == NULL) |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 796 | return; |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 797 | if (pdata->buck1) { |
| 798 | reg_devs[0].platform_data = pdata->buck1; |
| 799 | reg_devs[0].pdata_size = sizeof(struct regulator_init_data); |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 800 | } |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 801 | if (pdata->buck2) { |
| 802 | reg_devs[1].platform_data = pdata->buck2; |
| 803 | reg_devs[1].pdata_size = sizeof(struct regulator_init_data); |
| 804 | } |
| 805 | if (pdata->buck3) { |
| 806 | reg_devs[2].platform_data = pdata->buck3; |
| 807 | reg_devs[2].pdata_size = sizeof(struct regulator_init_data); |
| 808 | } |
| 809 | if (pdata->ldo1) { |
| 810 | reg_devs[3].platform_data = pdata->ldo1; |
| 811 | reg_devs[3].pdata_size = sizeof(struct regulator_init_data); |
| 812 | } |
| 813 | if (pdata->ldo2) { |
| 814 | reg_devs[4].platform_data = pdata->ldo2; |
| 815 | reg_devs[4].pdata_size = sizeof(struct regulator_init_data); |
| 816 | } |
| 817 | if (pdata->ldo3) { |
| 818 | reg_devs[5].platform_data = pdata->ldo3; |
| 819 | reg_devs[5].pdata_size = sizeof(struct regulator_init_data); |
| 820 | } |
| 821 | if (pdata->ldo4) { |
| 822 | reg_devs[6].platform_data = pdata->ldo4; |
| 823 | reg_devs[6].pdata_size = sizeof(struct regulator_init_data); |
| 824 | } |
| 825 | if (pdata->ldo5) { |
| 826 | reg_devs[7].platform_data = pdata->ldo5; |
| 827 | reg_devs[7].pdata_size = sizeof(struct regulator_init_data); |
| 828 | } |
| 829 | if (pdata->ldo6) { |
| 830 | reg_devs[8].platform_data = pdata->ldo6; |
| 831 | reg_devs[8].pdata_size = sizeof(struct regulator_init_data); |
| 832 | } |
| 833 | if (pdata->ldo7) { |
| 834 | reg_devs[9].platform_data = pdata->ldo7; |
| 835 | reg_devs[9].pdata_size = sizeof(struct regulator_init_data); |
| 836 | } |
| 837 | if (pdata->ldo8) { |
| 838 | reg_devs[10].platform_data = pdata->ldo8; |
| 839 | reg_devs[10].pdata_size = sizeof(struct regulator_init_data); |
| 840 | } |
| 841 | if (pdata->ldo9) { |
| 842 | reg_devs[11].platform_data = pdata->ldo9; |
| 843 | reg_devs[11].pdata_size = sizeof(struct regulator_init_data); |
| 844 | } |
| 845 | if (pdata->ldo10) { |
| 846 | reg_devs[12].platform_data = pdata->ldo10; |
| 847 | reg_devs[12].pdata_size = sizeof(struct regulator_init_data); |
| 848 | } |
| 849 | if (pdata->ldo12) { |
| 850 | reg_devs[13].platform_data = pdata->ldo12; |
| 851 | reg_devs[13].pdata_size = sizeof(struct regulator_init_data); |
| 852 | } |
| 853 | if (pdata->ldo_vibrator) { |
| 854 | reg_devs[14].platform_data = pdata->ldo_vibrator; |
| 855 | reg_devs[14].pdata_size = sizeof(struct regulator_init_data); |
| 856 | } |
| 857 | if (pdata->ldo14) { |
| 858 | reg_devs[15].platform_data = pdata->ldo14; |
| 859 | reg_devs[15].pdata_size = sizeof(struct regulator_init_data); |
| 860 | } |
| 861 | ret = mfd_add_devices(chip->dev, 0, reg_devs, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 862 | ARRAY_SIZE(reg_devs), NULL, 0, NULL); |
Haojian Zhuang | a70abac | 2012-08-08 23:17:28 +0800 | [diff] [blame] | 863 | if (ret < 0) { |
| 864 | dev_err(chip->dev, "Failed to add regulator subdev\n"); |
| 865 | return; |
| 866 | } |
Haojian Zhuang | 22aad00 | 2011-03-07 23:43:11 +0800 | [diff] [blame] | 867 | } |
| 868 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 869 | static void device_rtc_init(struct pm860x_chip *chip, |
Haojian Zhuang | 008b304 | 2011-05-06 17:21:20 +0800 | [diff] [blame] | 870 | struct pm860x_platform_data *pdata) |
| 871 | { |
| 872 | int ret; |
| 873 | |
| 874 | if ((pdata == NULL)) |
| 875 | return; |
| 876 | |
| 877 | rtc_devs[0].platform_data = pdata->rtc; |
| 878 | rtc_devs[0].pdata_size = sizeof(struct pm860x_rtc_pdata); |
| 879 | rtc_devs[0].num_resources = ARRAY_SIZE(rtc_resources); |
| 880 | rtc_devs[0].resources = &rtc_resources[0]; |
| 881 | ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], |
| 882 | ARRAY_SIZE(rtc_devs), &rtc_resources[0], |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 883 | chip->irq_base, NULL); |
Haojian Zhuang | 008b304 | 2011-05-06 17:21:20 +0800 | [diff] [blame] | 884 | if (ret < 0) |
| 885 | dev_err(chip->dev, "Failed to add rtc subdev\n"); |
| 886 | } |
| 887 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 888 | static void device_touch_init(struct pm860x_chip *chip, |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 889 | struct pm860x_platform_data *pdata) |
| 890 | { |
| 891 | int ret; |
| 892 | |
Haojian Zhuang | f5fb758 | 2011-05-06 17:21:21 +0800 | [diff] [blame] | 893 | if (pdata == NULL) |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 894 | return; |
| 895 | |
Haojian Zhuang | f5fb758 | 2011-05-06 17:21:21 +0800 | [diff] [blame] | 896 | touch_devs[0].platform_data = pdata->touch; |
| 897 | touch_devs[0].pdata_size = sizeof(struct pm860x_touch_pdata); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 898 | touch_devs[0].num_resources = ARRAY_SIZE(touch_resources); |
| 899 | touch_devs[0].resources = &touch_resources[0]; |
| 900 | ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], |
| 901 | ARRAY_SIZE(touch_devs), &touch_resources[0], |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 902 | chip->irq_base, NULL); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 903 | if (ret < 0) |
| 904 | dev_err(chip->dev, "Failed to add touch subdev\n"); |
| 905 | } |
| 906 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 907 | static void device_power_init(struct pm860x_chip *chip, |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 908 | struct pm860x_platform_data *pdata) |
| 909 | { |
| 910 | int ret; |
| 911 | |
Haojian Zhuang | f5fb758 | 2011-05-06 17:21:21 +0800 | [diff] [blame] | 912 | if (pdata == NULL) |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 913 | return; |
| 914 | |
Haojian Zhuang | f5fb758 | 2011-05-06 17:21:21 +0800 | [diff] [blame] | 915 | power_devs[0].platform_data = pdata->power; |
| 916 | power_devs[0].pdata_size = sizeof(struct pm860x_power_pdata); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 917 | power_devs[0].num_resources = ARRAY_SIZE(battery_resources); |
| 918 | power_devs[0].resources = &battery_resources[0], |
| 919 | ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 1, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 920 | &battery_resources[0], chip->irq_base, NULL); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 921 | if (ret < 0) |
| 922 | dev_err(chip->dev, "Failed to add battery subdev\n"); |
| 923 | |
Haojian Zhuang | f5fb758 | 2011-05-06 17:21:21 +0800 | [diff] [blame] | 924 | power_devs[1].platform_data = pdata->power; |
| 925 | power_devs[1].pdata_size = sizeof(struct pm860x_power_pdata); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 926 | power_devs[1].num_resources = ARRAY_SIZE(charger_resources); |
| 927 | power_devs[1].resources = &charger_resources[0], |
| 928 | ret = mfd_add_devices(chip->dev, 0, &power_devs[1], 1, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 929 | &charger_resources[0], chip->irq_base, NULL); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 930 | if (ret < 0) |
| 931 | dev_err(chip->dev, "Failed to add charger subdev\n"); |
Jett.Zhou | 2573f6d | 2012-07-06 10:59:58 +0800 | [diff] [blame] | 932 | |
| 933 | power_devs[2].platform_data = &preg_init_data; |
| 934 | power_devs[2].pdata_size = sizeof(struct regulator_init_data); |
Jett.Zhou | 2573f6d | 2012-07-06 10:59:58 +0800 | [diff] [blame] | 935 | ret = mfd_add_devices(chip->dev, 0, &power_devs[2], 1, |
Haojian Zhuang | ff13e9e | 2012-09-17 12:19:07 +0800 | [diff] [blame] | 936 | NULL, chip->irq_base, NULL); |
Jett.Zhou | 2573f6d | 2012-07-06 10:59:58 +0800 | [diff] [blame] | 937 | if (ret < 0) |
| 938 | dev_err(chip->dev, "Failed to add preg subdev\n"); |
Jett.Zhou | a830d28 | 2012-07-27 16:27:16 +0800 | [diff] [blame] | 939 | |
| 940 | if (pdata->chg_desc) { |
| 941 | pdata->chg_desc->charger_regulators = |
| 942 | &chg_desc_regulator_data[0]; |
| 943 | pdata->chg_desc->num_charger_regulators = |
| 944 | ARRAY_SIZE(chg_desc_regulator_data), |
| 945 | power_devs[3].platform_data = pdata->chg_desc; |
| 946 | power_devs[3].pdata_size = sizeof(*pdata->chg_desc); |
| 947 | ret = mfd_add_devices(chip->dev, 0, &power_devs[3], 1, |
Anton Vorontsov | 18766f0 | 2012-09-24 19:10:08 -0700 | [diff] [blame] | 948 | NULL, chip->irq_base, NULL); |
Jett.Zhou | a830d28 | 2012-07-27 16:27:16 +0800 | [diff] [blame] | 949 | if (ret < 0) |
| 950 | dev_err(chip->dev, "Failed to add chg-manager subdev\n"); |
| 951 | } |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 952 | } |
| 953 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 954 | static void device_onkey_init(struct pm860x_chip *chip, |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 955 | struct pm860x_platform_data *pdata) |
| 956 | { |
| 957 | int ret; |
| 958 | |
| 959 | onkey_devs[0].num_resources = ARRAY_SIZE(onkey_resources); |
| 960 | onkey_devs[0].resources = &onkey_resources[0], |
| 961 | ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], |
| 962 | ARRAY_SIZE(onkey_devs), &onkey_resources[0], |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 963 | chip->irq_base, NULL); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 964 | if (ret < 0) |
| 965 | dev_err(chip->dev, "Failed to add onkey subdev\n"); |
| 966 | } |
| 967 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 968 | static void device_codec_init(struct pm860x_chip *chip, |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 969 | struct pm860x_platform_data *pdata) |
| 970 | { |
| 971 | int ret; |
| 972 | |
| 973 | codec_devs[0].num_resources = ARRAY_SIZE(codec_resources); |
| 974 | codec_devs[0].resources = &codec_resources[0], |
| 975 | ret = mfd_add_devices(chip->dev, 0, &codec_devs[0], |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 976 | ARRAY_SIZE(codec_devs), &codec_resources[0], 0, |
| 977 | NULL); |
Haojian Zhuang | c9f560b | 2011-03-07 23:43:12 +0800 | [diff] [blame] | 978 | if (ret < 0) |
| 979 | dev_err(chip->dev, "Failed to add codec subdev\n"); |
| 980 | } |
| 981 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 982 | static void device_8607_init(struct pm860x_chip *chip, |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 983 | struct i2c_client *i2c, |
| 984 | struct pm860x_platform_data *pdata) |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 985 | { |
Haojian Zhuang | a16122b | 2009-12-15 16:04:36 -0500 | [diff] [blame] | 986 | int data, ret; |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 987 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 988 | ret = pm860x_reg_read(i2c, PM8607_CHIP_ID); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 989 | if (ret < 0) { |
| 990 | dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); |
| 991 | goto out; |
| 992 | } |
Haojian Zhuang | 38b34052 | 2010-09-08 09:44:34 -0400 | [diff] [blame] | 993 | switch (ret & PM8607_VERSION_MASK) { |
| 994 | case 0x40: |
| 995 | case 0x50: |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 996 | dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", |
| 997 | ret); |
Haojian Zhuang | 38b34052 | 2010-09-08 09:44:34 -0400 | [diff] [blame] | 998 | break; |
| 999 | default: |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1000 | dev_err(chip->dev, "Failed to detect Marvell 88PM8607. " |
| 1001 | "Chip ID: %02x\n", ret); |
| 1002 | goto out; |
| 1003 | } |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1004 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1005 | ret = pm860x_reg_read(i2c, PM8607_BUCK3); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1006 | if (ret < 0) { |
| 1007 | dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); |
| 1008 | goto out; |
| 1009 | } |
| 1010 | if (ret & PM8607_BUCK3_DOUBLE) |
| 1011 | chip->buck3_double = 1; |
| 1012 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 1013 | ret = pm860x_reg_read(i2c, PM8607_B0_MISC1); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1014 | if (ret < 0) { |
| 1015 | dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); |
| 1016 | goto out; |
| 1017 | } |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1018 | |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 1019 | if (pdata && (pdata->i2c_port == PI2C_PORT)) |
| 1020 | data = PM8607_B0_MISC1_PI2C; |
| 1021 | else |
| 1022 | data = 0; |
| 1023 | ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data); |
| 1024 | if (ret < 0) { |
| 1025 | dev_err(chip->dev, "Failed to access MISC1:%d\n", ret); |
| 1026 | goto out; |
| 1027 | } |
| 1028 | |
| 1029 | ret = device_irq_init(chip, pdata); |
| 1030 | if (ret < 0) |
| 1031 | goto out; |
| 1032 | |
Haojian Zhuang | cea438d | 2011-05-06 17:21:24 +0800 | [diff] [blame] | 1033 | device_regulator_init(chip, pdata); |
| 1034 | device_rtc_init(chip, pdata); |
| 1035 | device_onkey_init(chip, pdata); |
| 1036 | device_touch_init(chip, pdata); |
| 1037 | device_power_init(chip, pdata); |
| 1038 | device_codec_init(chip, pdata); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1039 | out: |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1040 | return; |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1041 | } |
| 1042 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 1043 | static void device_8606_init(struct pm860x_chip *chip, |
Jett.Zhou | 7825806 | 2012-02-28 10:58:42 +0800 | [diff] [blame] | 1044 | struct i2c_client *i2c, |
| 1045 | struct pm860x_platform_data *pdata) |
| 1046 | { |
| 1047 | device_osc_init(i2c); |
| 1048 | device_bk_init(chip, pdata); |
| 1049 | device_led_init(chip, pdata); |
| 1050 | } |
| 1051 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 1052 | static int pm860x_device_init(struct pm860x_chip *chip, |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1053 | struct pm860x_platform_data *pdata) |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1054 | { |
Haojian Zhuang | 2afa62e | 2010-02-08 05:02:00 -0500 | [diff] [blame] | 1055 | chip->core_irq = 0; |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 1056 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1057 | switch (chip->id) { |
| 1058 | case CHIP_PM8606: |
Jett.Zhou | 7825806 | 2012-02-28 10:58:42 +0800 | [diff] [blame] | 1059 | device_8606_init(chip, chip->client, pdata); |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1060 | break; |
| 1061 | case CHIP_PM8607: |
| 1062 | device_8607_init(chip, chip->client, pdata); |
| 1063 | break; |
| 1064 | } |
| 1065 | |
| 1066 | if (chip->companion) { |
| 1067 | switch (chip->id) { |
| 1068 | case CHIP_PM8607: |
Jett.Zhou | 7825806 | 2012-02-28 10:58:42 +0800 | [diff] [blame] | 1069 | device_8606_init(chip, chip->companion, pdata); |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1070 | break; |
| 1071 | case CHIP_PM8606: |
| 1072 | device_8607_init(chip, chip->companion, pdata); |
| 1073 | break; |
| 1074 | } |
| 1075 | } |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 1076 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1077 | return 0; |
| 1078 | } |
| 1079 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 1080 | static void pm860x_device_exit(struct pm860x_chip *chip) |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1081 | { |
Haojian Zhuang | 5c42e8c | 2009-12-15 16:01:47 -0500 | [diff] [blame] | 1082 | device_irq_exit(chip); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1083 | mfd_remove_devices(chip->dev); |
| 1084 | } |
| 1085 | |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1086 | static int verify_addr(struct i2c_client *i2c) |
| 1087 | { |
| 1088 | unsigned short addr_8607[] = {0x30, 0x34}; |
| 1089 | unsigned short addr_8606[] = {0x10, 0x11}; |
| 1090 | int size, i; |
| 1091 | |
| 1092 | if (i2c == NULL) |
| 1093 | return 0; |
| 1094 | size = ARRAY_SIZE(addr_8606); |
| 1095 | for (i = 0; i < size; i++) { |
| 1096 | if (i2c->addr == *(addr_8606 + i)) |
| 1097 | return CHIP_PM8606; |
| 1098 | } |
| 1099 | size = ARRAY_SIZE(addr_8607); |
| 1100 | for (i = 0; i < size; i++) { |
| 1101 | if (i2c->addr == *(addr_8607 + i)) |
| 1102 | return CHIP_PM8607; |
| 1103 | } |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static struct regmap_config pm860x_regmap_config = { |
| 1108 | .reg_bits = 8, |
| 1109 | .val_bits = 8, |
| 1110 | }; |
| 1111 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 1112 | static int pm860x_dt_init(struct device_node *np, |
Haojian Zhuang | 2e57d56 | 2012-09-21 18:06:52 +0800 | [diff] [blame] | 1113 | struct device *dev, |
| 1114 | struct pm860x_platform_data *pdata) |
| 1115 | { |
| 1116 | int ret; |
| 1117 | |
| 1118 | if (of_get_property(np, "marvell,88pm860x-irq-read-clr", NULL)) |
| 1119 | pdata->irq_mode = 1; |
| 1120 | ret = of_property_read_u32(np, "marvell,88pm860x-slave-addr", |
| 1121 | &pdata->companion_addr); |
| 1122 | if (ret) { |
| 1123 | dev_err(dev, "Not found \"marvell,88pm860x-slave-addr\" " |
| 1124 | "property\n"); |
| 1125 | pdata->companion_addr = 0; |
| 1126 | } |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 1130 | static int pm860x_probe(struct i2c_client *client, |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1131 | const struct i2c_device_id *id) |
| 1132 | { |
Jingoo Han | 334a41c | 2013-07-30 17:10:05 +0900 | [diff] [blame] | 1133 | struct pm860x_platform_data *pdata = dev_get_platdata(&client->dev); |
Haojian Zhuang | 2e57d56 | 2012-09-21 18:06:52 +0800 | [diff] [blame] | 1134 | struct device_node *node = client->dev.of_node; |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1135 | struct pm860x_chip *chip; |
| 1136 | int ret; |
| 1137 | |
Haojian Zhuang | 2e57d56 | 2012-09-21 18:06:52 +0800 | [diff] [blame] | 1138 | if (node && !pdata) { |
| 1139 | /* parse DT to get platform data */ |
| 1140 | pdata = devm_kzalloc(&client->dev, |
| 1141 | sizeof(struct pm860x_platform_data), |
| 1142 | GFP_KERNEL); |
| 1143 | if (!pdata) |
| 1144 | return -ENOMEM; |
| 1145 | ret = pm860x_dt_init(node, &client->dev, pdata); |
| 1146 | if (ret) |
Jingoo Han | 8552957 | 2013-02-20 18:27:21 +0900 | [diff] [blame] | 1147 | return ret; |
Haojian Zhuang | 2e57d56 | 2012-09-21 18:06:52 +0800 | [diff] [blame] | 1148 | } else if (!pdata) { |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1149 | pr_info("No platform data in %s!\n", __func__); |
| 1150 | return -EINVAL; |
| 1151 | } |
| 1152 | |
Lee Jones | a1ace0a | 2013-05-23 16:25:03 +0100 | [diff] [blame] | 1153 | chip = devm_kzalloc(&client->dev, |
| 1154 | sizeof(struct pm860x_chip), GFP_KERNEL); |
Jingoo Han | 8552957 | 2013-02-20 18:27:21 +0900 | [diff] [blame] | 1155 | if (chip == NULL) |
| 1156 | return -ENOMEM; |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1157 | |
| 1158 | chip->id = verify_addr(client); |
Sachin Kamat | aaaab42 | 2013-06-12 13:55:43 +0530 | [diff] [blame] | 1159 | chip->regmap = devm_regmap_init_i2c(client, &pm860x_regmap_config); |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1160 | if (IS_ERR(chip->regmap)) { |
| 1161 | ret = PTR_ERR(chip->regmap); |
| 1162 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
| 1163 | ret); |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1164 | return ret; |
| 1165 | } |
| 1166 | chip->client = client; |
| 1167 | i2c_set_clientdata(client, chip); |
| 1168 | chip->dev = &client->dev; |
| 1169 | dev_set_drvdata(chip->dev, chip); |
| 1170 | |
| 1171 | /* |
| 1172 | * Both client and companion client shares same platform driver. |
| 1173 | * Driver distinguishes them by pdata->companion_addr. |
| 1174 | * pdata->companion_addr is only assigned if companion chip exists. |
| 1175 | * At the same time, the companion_addr shouldn't equal to client |
| 1176 | * address. |
| 1177 | */ |
| 1178 | if (pdata->companion_addr && (pdata->companion_addr != client->addr)) { |
| 1179 | chip->companion_addr = pdata->companion_addr; |
| 1180 | chip->companion = i2c_new_dummy(chip->client->adapter, |
| 1181 | chip->companion_addr); |
| 1182 | chip->regmap_companion = regmap_init_i2c(chip->companion, |
| 1183 | &pm860x_regmap_config); |
| 1184 | if (IS_ERR(chip->regmap_companion)) { |
| 1185 | ret = PTR_ERR(chip->regmap_companion); |
| 1186 | dev_err(&chip->companion->dev, |
| 1187 | "Failed to allocate register map: %d\n", ret); |
| 1188 | return ret; |
| 1189 | } |
| 1190 | i2c_set_clientdata(chip->companion, chip); |
| 1191 | } |
| 1192 | |
| 1193 | pm860x_device_init(chip, pdata); |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 1197 | static int pm860x_remove(struct i2c_client *client) |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1198 | { |
| 1199 | struct pm860x_chip *chip = i2c_get_clientdata(client); |
| 1200 | |
| 1201 | pm860x_device_exit(chip); |
| 1202 | if (chip->companion) { |
| 1203 | regmap_exit(chip->regmap_companion); |
| 1204 | i2c_unregister_device(chip->companion); |
| 1205 | } |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1206 | return 0; |
| 1207 | } |
| 1208 | |
| 1209 | #ifdef CONFIG_PM_SLEEP |
| 1210 | static int pm860x_suspend(struct device *dev) |
| 1211 | { |
| 1212 | struct i2c_client *client = container_of(dev, struct i2c_client, dev); |
| 1213 | struct pm860x_chip *chip = i2c_get_clientdata(client); |
| 1214 | |
| 1215 | if (device_may_wakeup(dev) && chip->wakeup_flag) |
| 1216 | enable_irq_wake(chip->core_irq); |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | static int pm860x_resume(struct device *dev) |
| 1221 | { |
| 1222 | struct i2c_client *client = container_of(dev, struct i2c_client, dev); |
| 1223 | struct pm860x_chip *chip = i2c_get_clientdata(client); |
| 1224 | |
| 1225 | if (device_may_wakeup(dev) && chip->wakeup_flag) |
| 1226 | disable_irq_wake(chip->core_irq); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | #endif |
| 1230 | |
| 1231 | static SIMPLE_DEV_PM_OPS(pm860x_pm_ops, pm860x_suspend, pm860x_resume); |
| 1232 | |
Haojian Zhuang | 2e57d56 | 2012-09-21 18:06:52 +0800 | [diff] [blame] | 1233 | static const struct i2c_device_id pm860x_id_table[] = { |
| 1234 | { "88PM860x", 0 }, |
| 1235 | {} |
| 1236 | }; |
| 1237 | MODULE_DEVICE_TABLE(i2c, pm860x_id_table); |
| 1238 | |
| 1239 | static const struct of_device_id pm860x_dt_ids[] = { |
| 1240 | { .compatible = "marvell,88pm860x", }, |
| 1241 | {}, |
| 1242 | }; |
| 1243 | MODULE_DEVICE_TABLE(of, pm860x_dt_ids); |
| 1244 | |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1245 | static struct i2c_driver pm860x_driver = { |
| 1246 | .driver = { |
| 1247 | .name = "88PM860x", |
| 1248 | .owner = THIS_MODULE, |
| 1249 | .pm = &pm860x_pm_ops, |
Haojian Zhuang | 2e57d56 | 2012-09-21 18:06:52 +0800 | [diff] [blame] | 1250 | .of_match_table = of_match_ptr(pm860x_dt_ids), |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1251 | }, |
| 1252 | .probe = pm860x_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 1253 | .remove = pm860x_remove, |
Haojian Zhuang | f2f218c | 2012-09-17 12:19:08 +0800 | [diff] [blame] | 1254 | .id_table = pm860x_id_table, |
| 1255 | }; |
| 1256 | |
| 1257 | static int __init pm860x_i2c_init(void) |
| 1258 | { |
| 1259 | int ret; |
| 1260 | ret = i2c_add_driver(&pm860x_driver); |
| 1261 | if (ret != 0) |
| 1262 | pr_err("Failed to register 88PM860x I2C driver: %d\n", ret); |
| 1263 | return ret; |
| 1264 | } |
| 1265 | subsys_initcall(pm860x_i2c_init); |
| 1266 | |
| 1267 | static void __exit pm860x_i2c_exit(void) |
| 1268 | { |
| 1269 | i2c_del_driver(&pm860x_driver); |
| 1270 | } |
| 1271 | module_exit(pm860x_i2c_exit); |
| 1272 | |
Haojian Zhuang | 53dbab7 | 2010-01-08 06:01:24 -0500 | [diff] [blame] | 1273 | MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x"); |
Haojian Zhuang | bbd51b1 | 2010-01-06 17:04:18 -0500 | [diff] [blame] | 1274 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); |
| 1275 | MODULE_LICENSE("GPL"); |