1 // SPDX-License-Identifier: GPL-2.0-only
3 * I2C driver for Marvell 88PM80x
5 * Copyright (C) 2012 Marvell International Ltd.
6 * Haojian Zhuang <haojian.zhuang@marvell.com>
7 * Joseph(Yossi) Hanin <yhanin@marvell.com>
8 * Qiao Zhou <zhouqiao@marvell.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/i2c.h>
13 #include <linux/mfd/88pm80x.h>
14 #include <linux/slab.h>
15 #include <linux/uaccess.h>
16 #include <linux/err.h>
18 /* 88pm80x chips have same definition for chip id register. */
19 #define PM80X_CHIP_ID (0x00)
20 #define PM80X_CHIP_ID_NUM(x) (((x) >> 5) & 0x7)
21 #define PM80X_CHIP_ID_REVISION(x) ((x) & 0x1F)
23 struct pm80x_chip_mapping
{
28 static struct pm80x_chip_mapping chip_mapping
[] = {
29 /* 88PM800 chip id number */
31 /* 88PM805 chip id number */
33 /* 88PM860 chip id number */
38 * workaround: some registers needed by pm805 are defined in pm800, so
39 * need to use this global variable to maintain the relation between
40 * pm800 and pm805. would remove it after HW chip fixes the issue.
42 static struct pm80x_chip
*g_pm80x_chip
;
44 const struct regmap_config pm80x_regmap_config
= {
48 EXPORT_SYMBOL_GPL(pm80x_regmap_config
);
51 int pm80x_init(struct i2c_client
*client
)
53 struct pm80x_chip
*chip
;
59 devm_kzalloc(&client
->dev
, sizeof(struct pm80x_chip
), GFP_KERNEL
);
63 map
= devm_regmap_init_i2c(client
, &pm80x_regmap_config
);
66 dev_err(&client
->dev
, "Failed to allocate register map: %d\n",
71 chip
->client
= client
;
74 chip
->irq
= client
->irq
;
76 chip
->dev
= &client
->dev
;
77 i2c_set_clientdata(chip
->client
, chip
);
79 ret
= regmap_read(chip
->regmap
, PM80X_CHIP_ID
, &val
);
81 dev_err(chip
->dev
, "Failed to read CHIP ID: %d\n", ret
);
85 for (i
= 0; i
< ARRAY_SIZE(chip_mapping
); i
++) {
86 if (chip_mapping
[i
].id
== PM80X_CHIP_ID_NUM(val
)) {
87 chip
->type
= chip_mapping
[i
].type
;
92 if (i
== ARRAY_SIZE(chip_mapping
)) {
94 "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val
);
98 device_init_wakeup(&client
->dev
, 1);
101 * workaround: set g_pm80x_chip to the first probed chip. if the
102 * second chip is probed, just point to the companion to each
103 * other so that pm805 can access those specific register. would
104 * remove it after HW chip fixes the issue.
109 chip
->companion
= g_pm80x_chip
->client
;
110 g_pm80x_chip
->companion
= chip
->client
;
115 EXPORT_SYMBOL_GPL(pm80x_init
);
117 int pm80x_deinit(void)
120 * workaround: clear the dependency between pm800 and pm805.
121 * would remove it after HW chip fixes the issue.
123 if (g_pm80x_chip
->companion
)
124 g_pm80x_chip
->companion
= NULL
;
129 EXPORT_SYMBOL_GPL(pm80x_deinit
);
131 static int pm80x_suspend(struct device
*dev
)
133 struct i2c_client
*client
= to_i2c_client(dev
);
134 struct pm80x_chip
*chip
= i2c_get_clientdata(client
);
136 if (chip
&& chip
->wu_flag
)
137 if (device_may_wakeup(chip
->dev
))
138 enable_irq_wake(chip
->irq
);
143 static int pm80x_resume(struct device
*dev
)
145 struct i2c_client
*client
= to_i2c_client(dev
);
146 struct pm80x_chip
*chip
= i2c_get_clientdata(client
);
148 if (chip
&& chip
->wu_flag
)
149 if (device_may_wakeup(chip
->dev
))
150 disable_irq_wake(chip
->irq
);
155 EXPORT_GPL_SIMPLE_DEV_PM_OPS(pm80x_pm_ops
, pm80x_suspend
, pm80x_resume
);
157 MODULE_DESCRIPTION("I2C Driver for Marvell 88PM80x");
158 MODULE_AUTHOR("Qiao Zhou <zhouqiao@marvell.com>");
159 MODULE_LICENSE("GPL");