2 * Base driver for Marvell 88PM805
4 * Copyright (C) 2012 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
6 * Joseph(Yossi) Hanin <yhanin@marvell.com>
7 * Qiao Zhou <zhouqiao@marvell.com>
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of this
11 * archive for more details.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/i2c.h>
26 #include <linux/irq.h>
27 #include <linux/mfd/core.h>
28 #include <linux/mfd/88pm80x.h>
29 #include <linux/slab.h>
30 #include <linux/delay.h>
32 #define PM805_CHIP_ID (0x00)
34 static const struct i2c_device_id pm80x_id_table
[] = {
35 {"88PM805", CHIP_PM805
},
37 MODULE_DEVICE_TABLE(i2c
, pm80x_id_table
);
39 /* Interrupt Number in 88PM805 */
41 PM805_IRQ_LDO_OFF
, /*0 */
42 PM805_IRQ_SRC_DPLL_LOCK
, /*1 */
44 PM805_IRQ_MIC_CONFLICT
,
46 PM805_IRQ_HP1_SHRT
, /*5 */
47 PM805_IRQ_FINE_PLL_FAULT
,
48 PM805_IRQ_RAW_PLL_FAULT
,
49 PM805_IRQ_VOLP_BTN_DET
,
50 PM805_IRQ_VOLM_BTN_DET
,
51 PM805_IRQ_SHRT_BTN_DET
, /*10 */
52 PM805_IRQ_MIC_DET
, /*11 */
57 static struct resource codec_resources
[] = {
59 /* Headset microphone insertion or removal */
61 .start
= PM805_IRQ_MIC_DET
,
62 .end
= PM805_IRQ_MIC_DET
,
63 .flags
= IORESOURCE_IRQ
,
67 .name
= "audio-short1",
68 .start
= PM805_IRQ_HP1_SHRT
,
69 .end
= PM805_IRQ_HP1_SHRT
,
70 .flags
= IORESOURCE_IRQ
,
74 .name
= "audio-short2",
75 .start
= PM805_IRQ_HP2_SHRT
,
76 .end
= PM805_IRQ_HP2_SHRT
,
77 .flags
= IORESOURCE_IRQ
,
81 static struct mfd_cell codec_devs
[] = {
83 .name
= "88pm80x-codec",
84 .num_resources
= ARRAY_SIZE(codec_resources
),
85 .resources
= &codec_resources
[0],
90 static struct regmap_irq pm805_irqs
[] = {
92 [PM805_IRQ_LDO_OFF
] = {
93 .mask
= PM805_INT1_HP1_SHRT
,
95 [PM805_IRQ_SRC_DPLL_LOCK
] = {
96 .mask
= PM805_INT1_HP2_SHRT
,
98 [PM805_IRQ_CLIP_FAULT
] = {
99 .mask
= PM805_INT1_MIC_CONFLICT
,
101 [PM805_IRQ_MIC_CONFLICT
] = {
102 .mask
= PM805_INT1_CLIP_FAULT
,
104 [PM805_IRQ_HP2_SHRT
] = {
105 .mask
= PM805_INT1_LDO_OFF
,
107 [PM805_IRQ_HP1_SHRT
] = {
108 .mask
= PM805_INT1_SRC_DPLL_LOCK
,
111 [PM805_IRQ_FINE_PLL_FAULT
] = {
113 .mask
= PM805_INT2_MIC_DET
,
115 [PM805_IRQ_RAW_PLL_FAULT
] = {
117 .mask
= PM805_INT2_SHRT_BTN_DET
,
119 [PM805_IRQ_VOLP_BTN_DET
] = {
121 .mask
= PM805_INT2_VOLM_BTN_DET
,
123 [PM805_IRQ_VOLM_BTN_DET
] = {
125 .mask
= PM805_INT2_VOLP_BTN_DET
,
127 [PM805_IRQ_SHRT_BTN_DET
] = {
129 .mask
= PM805_INT2_RAW_PLL_FAULT
,
131 [PM805_IRQ_MIC_DET
] = {
133 .mask
= PM805_INT2_FINE_PLL_FAULT
,
137 static int __devinit
device_irq_init_805(struct pm80x_chip
*chip
)
139 struct regmap
*map
= chip
->regmap
;
140 unsigned long flags
= IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
;
141 int data
, mask
, ret
= -EINVAL
;
143 if (!map
|| !chip
->irq
) {
144 dev_err(chip
->dev
, "incorrect parameters\n");
149 * irq_mode defines the way of clearing interrupt. it's read-clear by
153 PM805_STATUS0_INT_CLEAR
| PM805_STATUS0_INV_INT
|
154 PM800_STATUS0_INT_MASK
;
156 data
= PM805_STATUS0_INT_CLEAR
;
157 ret
= regmap_update_bits(map
, PM805_INT_STATUS0
, mask
, data
);
159 * PM805_INT_STATUS is under 32K clock domain, so need to
160 * add proper delay before the next I2C register access.
168 regmap_add_irq_chip(chip
->regmap
, chip
->irq
, flags
, -1,
169 chip
->regmap_irq_chip
, &chip
->irq_data
);
175 static void device_irq_exit_805(struct pm80x_chip
*chip
)
177 regmap_del_irq_chip(chip
->irq
, chip
->irq_data
);
180 static struct regmap_irq_chip pm805_irq_chip
= {
183 .num_irqs
= ARRAY_SIZE(pm805_irqs
),
186 .status_base
= PM805_INT_STATUS1
,
187 .mask_base
= PM805_INT_MASK1
,
188 .ack_base
= PM805_INT_STATUS1
,
191 static int __devinit
device_805_init(struct pm80x_chip
*chip
)
194 struct regmap
*map
= chip
->regmap
;
197 dev_err(chip
->dev
, "regmap is invalid\n");
201 regmap_read(map
, PM805_CHIP_ID
, &ret
);
203 dev_err(chip
->dev
, "Failed to read CHIP ID: %d\n", ret
);
208 chip
->regmap_irq_chip
= &pm805_irq_chip
;
210 ret
= device_irq_init_805(chip
);
212 dev_err(chip
->dev
, "Failed to init pm805 irq!\n");
216 ret
= mfd_add_devices(chip
->dev
, 0, &codec_devs
[0],
217 ARRAY_SIZE(codec_devs
), &codec_resources
[0], 0);
219 dev_err(chip
->dev
, "Failed to add codec subdev\n");
222 dev_info(chip
->dev
, "[%s]:Added mfd codec_devs\n", __func__
);
227 device_irq_exit_805(chip
);
232 static int __devinit
pm805_probe(struct i2c_client
*client
,
233 const struct i2c_device_id
*id
)
236 struct pm80x_chip
*chip
;
237 struct pm80x_platform_data
*pdata
= client
->dev
.platform_data
;
239 ret
= pm80x_init(client
, id
);
241 dev_err(&client
->dev
, "pm805_init fail!\n");
245 chip
= i2c_get_clientdata(client
);
247 ret
= device_805_init(chip
);
249 dev_err(chip
->dev
, "%s id 0x%x failed!\n", __func__
, chip
->id
);
253 if (pdata
->plat_config
)
254 pdata
->plat_config(chip
, pdata
);
257 pm80x_deinit(client
);
262 static int __devexit
pm805_remove(struct i2c_client
*client
)
264 struct pm80x_chip
*chip
= i2c_get_clientdata(client
);
266 mfd_remove_devices(chip
->dev
);
267 device_irq_exit_805(chip
);
269 pm80x_deinit(client
);
274 static struct i2c_driver pm805_driver
= {
277 .owner
= THIS_MODULE
,
280 .probe
= pm805_probe
,
281 .remove
= __devexit_p(pm805_remove
),
282 .id_table
= pm80x_id_table
,
285 static int __init
pm805_i2c_init(void)
287 return i2c_add_driver(&pm805_driver
);
289 subsys_initcall(pm805_i2c_init
);
291 static void __exit
pm805_i2c_exit(void)
293 i2c_del_driver(&pm805_driver
);
295 module_exit(pm805_i2c_exit
);
297 MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM805");
298 MODULE_AUTHOR("Qiao Zhou <zhouqiao@marvell.com>");
299 MODULE_LICENSE("GPL");