aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorChao Xie <chao.xie@marvell.com>2013-06-14 01:21:51 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2013-06-18 03:41:10 -0400
commit03dcc544bff9ff36b9ac5e2b992a7a4890e6edc4 (patch)
tree06dd1030dc9875f099c93674296e2b40cce3ee06 /drivers
parent52705344d00512f0bb48c66478582bd10eb1750f (diff)
mfd: 88pm80x: Change chip id definition and detection
Change the chip id definition and detection and then: 1. We no longer need to add PM800_CHIP_XXX for the coming revision. 2. We no longer need to pass driver_data in i2c_device_id as we can distinguish the chips from the CHIP_ID register. Signed-off-by: Chao Xie <chao.xie@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mfd/88pm800.c42
-rw-r--r--drivers/mfd/88pm805.c16
-rw-r--r--drivers/mfd/88pm80x.c47
3 files changed, 49 insertions, 56 deletions
diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c
index 4ebb2e215bac..2c0b4155181f 100644
--- a/drivers/mfd/88pm800.c
+++ b/drivers/mfd/88pm800.c
@@ -28,8 +28,6 @@
28#include <linux/mfd/88pm80x.h> 28#include <linux/mfd/88pm80x.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31#define PM800_CHIP_ID (0x00)
32
33/* Interrupt Registers */ 31/* Interrupt Registers */
34#define PM800_INT_STATUS1 (0x05) 32#define PM800_INT_STATUS1 (0x05)
35#define PM800_ONKEY_INT_STS1 (1 << 0) 33#define PM800_ONKEY_INT_STS1 (1 << 0)
@@ -114,20 +112,11 @@ enum {
114 PM800_MAX_IRQ, 112 PM800_MAX_IRQ,
115}; 113};
116 114
117enum { 115/* PM800: generation identification number */
118 /* Procida */ 116#define PM800_CHIP_GEN_ID_NUM 0x3
119 PM800_CHIP_A0 = 0x60,
120 PM800_CHIP_A1 = 0x61,
121 PM800_CHIP_B0 = 0x62,
122 PM800_CHIP_C0 = 0x63,
123 PM800_CHIP_END = PM800_CHIP_C0,
124
125 /* Make sure to update this to the last stepping */
126 PM8XXX_CHIP_END = PM800_CHIP_END
127};
128 117
129static const struct i2c_device_id pm80x_id_table[] = { 118static const struct i2c_device_id pm80x_id_table[] = {
130 {"88PM800", CHIP_PM800}, 119 {"88PM800", 0},
131 {} /* NULL terminated */ 120 {} /* NULL terminated */
132}; 121};
133MODULE_DEVICE_TABLE(i2c, pm80x_id_table); 122MODULE_DEVICE_TABLE(i2c, pm80x_id_table);
@@ -434,28 +423,9 @@ static void pm800_pages_exit(struct pm80x_chip *chip)
434static int device_800_init(struct pm80x_chip *chip, 423static int device_800_init(struct pm80x_chip *chip,
435 struct pm80x_platform_data *pdata) 424 struct pm80x_platform_data *pdata)
436{ 425{
437 int ret, pmic_id; 426 int ret;
438 unsigned int val; 427 unsigned int val;
439 428
440 ret = regmap_read(chip->regmap, PM800_CHIP_ID, &val);
441 if (ret < 0) {
442 dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
443 goto out;
444 }
445
446 pmic_id = val & PM80X_VERSION_MASK;
447
448 if ((pmic_id >= PM800_CHIP_A0) && (pmic_id <= PM800_CHIP_END)) {
449 chip->version = val;
450 dev_info(chip->dev,
451 "88PM80x:Marvell 88PM800 (ID:0x%x) detected\n", val);
452 } else {
453 dev_err(chip->dev,
454 "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val);
455 ret = -EINVAL;
456 goto out;
457 }
458
459 /* 429 /*
460 * alarm wake up bit will be clear in device_irq_init(), 430 * alarm wake up bit will be clear in device_irq_init(),
461 * read before that 431 * read before that
@@ -523,7 +493,7 @@ static int pm800_probe(struct i2c_client *client,
523 struct pm80x_platform_data *pdata = client->dev.platform_data; 493 struct pm80x_platform_data *pdata = client->dev.platform_data;
524 struct pm80x_subchip *subchip; 494 struct pm80x_subchip *subchip;
525 495
526 ret = pm80x_init(client, id); 496 ret = pm80x_init(client);
527 if (ret) { 497 if (ret) {
528 dev_err(&client->dev, "pm800_init fail\n"); 498 dev_err(&client->dev, "pm800_init fail\n");
529 goto out_init; 499 goto out_init;
@@ -553,7 +523,7 @@ static int pm800_probe(struct i2c_client *client,
553 523
554 ret = device_800_init(chip, pdata); 524 ret = device_800_init(chip, pdata);
555 if (ret) { 525 if (ret) {
556 dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id); 526 dev_err(chip->dev, "Failed to initialize 88pm800 devices\n");
557 goto err_device_init; 527 goto err_device_init;
558 } 528 }
559 529
diff --git a/drivers/mfd/88pm805.c b/drivers/mfd/88pm805.c
index 0e82c2a1e842..521602231c7b 100644
--- a/drivers/mfd/88pm805.c
+++ b/drivers/mfd/88pm805.c
@@ -29,10 +29,8 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31 31
32#define PM805_CHIP_ID (0x00)
33
34static const struct i2c_device_id pm80x_id_table[] = { 32static const struct i2c_device_id pm80x_id_table[] = {
35 {"88PM805", CHIP_PM805}, 33 {"88PM805", 0},
36 {} /* NULL terminated */ 34 {} /* NULL terminated */
37}; 35};
38MODULE_DEVICE_TABLE(i2c, pm80x_id_table); 36MODULE_DEVICE_TABLE(i2c, pm80x_id_table);
@@ -192,7 +190,6 @@ static struct regmap_irq_chip pm805_irq_chip = {
192static int device_805_init(struct pm80x_chip *chip) 190static int device_805_init(struct pm80x_chip *chip)
193{ 191{
194 int ret = 0; 192 int ret = 0;
195 unsigned int val;
196 struct regmap *map = chip->regmap; 193 struct regmap *map = chip->regmap;
197 194
198 if (!map) { 195 if (!map) {
@@ -200,13 +197,6 @@ static int device_805_init(struct pm80x_chip *chip)
200 return -EINVAL; 197 return -EINVAL;
201 } 198 }
202 199
203 ret = regmap_read(map, PM805_CHIP_ID, &val);
204 if (ret < 0) {
205 dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
206 goto out_irq_init;
207 }
208 chip->version = val;
209
210 chip->regmap_irq_chip = &pm805_irq_chip; 200 chip->regmap_irq_chip = &pm805_irq_chip;
211 201
212 ret = device_irq_init_805(chip); 202 ret = device_irq_init_805(chip);
@@ -239,7 +229,7 @@ static int pm805_probe(struct i2c_client *client,
239 struct pm80x_chip *chip; 229 struct pm80x_chip *chip;
240 struct pm80x_platform_data *pdata = client->dev.platform_data; 230 struct pm80x_platform_data *pdata = client->dev.platform_data;
241 231
242 ret = pm80x_init(client, id); 232 ret = pm80x_init(client);
243 if (ret) { 233 if (ret) {
244 dev_err(&client->dev, "pm805_init fail!\n"); 234 dev_err(&client->dev, "pm805_init fail!\n");
245 goto out_init; 235 goto out_init;
@@ -249,7 +239,7 @@ static int pm805_probe(struct i2c_client *client,
249 239
250 ret = device_805_init(chip); 240 ret = device_805_init(chip);
251 if (ret) { 241 if (ret) {
252 dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id); 242 dev_err(chip->dev, "Failed to initialize 88pm805 devices\n");
253 goto err_805_init; 243 goto err_805_init;
254 } 244 }
255 245
diff --git a/drivers/mfd/88pm80x.c b/drivers/mfd/88pm80x.c
index f736a46eb8c0..5e72f65ef94c 100644
--- a/drivers/mfd/88pm80x.c
+++ b/drivers/mfd/88pm80x.c
@@ -18,6 +18,23 @@
18#include <linux/uaccess.h> 18#include <linux/uaccess.h>
19#include <linux/err.h> 19#include <linux/err.h>
20 20
21/* 88pm80x chips have same definition for chip id register. */
22#define PM80X_CHIP_ID (0x00)
23#define PM80X_CHIP_ID_NUM(x) (((x) >> 5) & 0x7)
24#define PM80X_CHIP_ID_REVISION(x) ((x) & 0x1F)
25
26struct pm80x_chip_mapping {
27 unsigned int id;
28 int type;
29};
30
31static struct pm80x_chip_mapping chip_mapping[] = {
32 /* 88PM800 chip id number */
33 {0x3, CHIP_PM800},
34 /* 88PM805 chip id number */
35 {0x0, CHIP_PM805},
36};
37
21/* 38/*
22 * workaround: some registers needed by pm805 are defined in pm800, so 39 * workaround: some registers needed by pm805 are defined in pm800, so
23 * need to use this global variable to maintain the relation between 40 * need to use this global variable to maintain the relation between
@@ -31,12 +48,13 @@ const struct regmap_config pm80x_regmap_config = {
31}; 48};
32EXPORT_SYMBOL_GPL(pm80x_regmap_config); 49EXPORT_SYMBOL_GPL(pm80x_regmap_config);
33 50
34int pm80x_init(struct i2c_client *client, 51
35 const struct i2c_device_id *id) 52int pm80x_init(struct i2c_client *client)
36{ 53{
37 struct pm80x_chip *chip; 54 struct pm80x_chip *chip;
38 struct regmap *map; 55 struct regmap *map;
39 int ret = 0; 56 unsigned int val;
57 int i, ret = 0;
40 58
41 chip = 59 chip =
42 devm_kzalloc(&client->dev, sizeof(struct pm80x_chip), GFP_KERNEL); 60 devm_kzalloc(&client->dev, sizeof(struct pm80x_chip), GFP_KERNEL);
@@ -51,10 +69,6 @@ int pm80x_init(struct i2c_client *client,
51 return ret; 69 return ret;
52 } 70 }
53 71
54 chip->id = id->driver_data;
55 if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805)
56 return -EINVAL;
57
58 chip->client = client; 72 chip->client = client;
59 chip->regmap = map; 73 chip->regmap = map;
60 74
@@ -64,6 +78,25 @@ int pm80x_init(struct i2c_client *client,
64 dev_set_drvdata(chip->dev, chip); 78 dev_set_drvdata(chip->dev, chip);
65 i2c_set_clientdata(chip->client, chip); 79 i2c_set_clientdata(chip->client, chip);
66 80
81 ret = regmap_read(chip->regmap, PM80X_CHIP_ID, &val);
82 if (ret < 0) {
83 dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
84 return ret;
85 }
86
87 for (i = 0; i < ARRAY_SIZE(chip_mapping); i++) {
88 if (chip_mapping[i].id == PM80X_CHIP_ID_NUM(val)) {
89 chip->type = chip_mapping[i].type;
90 break;
91 }
92 }
93
94 if (i == ARRAY_SIZE(chip_mapping)) {
95 dev_err(chip->dev,
96 "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val);
97 return -EINVAL;
98 }
99
67 device_init_wakeup(&client->dev, 1); 100 device_init_wakeup(&client->dev, 1);
68 101
69 /* 102 /*