Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chao Xie and committed by
Samuel Ortiz
03dcc544 52705344

+51 -61
+6 -36
drivers/mfd/88pm800.c
··· 28 28 #include <linux/mfd/88pm80x.h> 29 29 #include <linux/slab.h> 30 30 31 - #define PM800_CHIP_ID (0x00) 32 - 33 31 /* Interrupt Registers */ 34 32 #define PM800_INT_STATUS1 (0x05) 35 33 #define PM800_ONKEY_INT_STS1 (1 << 0) ··· 112 114 PM800_MAX_IRQ, 113 115 }; 114 116 115 - enum { 116 - /* Procida */ 117 - PM800_CHIP_A0 = 0x60, 118 - PM800_CHIP_A1 = 0x61, 119 - PM800_CHIP_B0 = 0x62, 120 - PM800_CHIP_C0 = 0x63, 121 - PM800_CHIP_END = PM800_CHIP_C0, 122 - 123 - /* Make sure to update this to the last stepping */ 124 - PM8XXX_CHIP_END = PM800_CHIP_END 125 - }; 117 + /* PM800: generation identification number */ 118 + #define PM800_CHIP_GEN_ID_NUM 0x3 126 119 127 120 static const struct i2c_device_id pm80x_id_table[] = { 128 - {"88PM800", CHIP_PM800}, 121 + {"88PM800", 0}, 129 122 {} /* NULL terminated */ 130 123 }; 131 124 MODULE_DEVICE_TABLE(i2c, pm80x_id_table); ··· 423 434 static int device_800_init(struct pm80x_chip *chip, 424 435 struct pm80x_platform_data *pdata) 425 436 { 426 - int ret, pmic_id; 437 + int ret; 427 438 unsigned int val; 428 - 429 - ret = regmap_read(chip->regmap, PM800_CHIP_ID, &val); 430 - if (ret < 0) { 431 - dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); 432 - goto out; 433 - } 434 - 435 - pmic_id = val & PM80X_VERSION_MASK; 436 - 437 - if ((pmic_id >= PM800_CHIP_A0) && (pmic_id <= PM800_CHIP_END)) { 438 - chip->version = val; 439 - dev_info(chip->dev, 440 - "88PM80x:Marvell 88PM800 (ID:0x%x) detected\n", val); 441 - } else { 442 - dev_err(chip->dev, 443 - "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val); 444 - ret = -EINVAL; 445 - goto out; 446 - } 447 439 448 440 /* 449 441 * alarm wake up bit will be clear in device_irq_init(), ··· 493 523 struct pm80x_platform_data *pdata = client->dev.platform_data; 494 524 struct pm80x_subchip *subchip; 495 525 496 - ret = pm80x_init(client, id); 526 + ret = pm80x_init(client); 497 527 if (ret) { 498 528 dev_err(&client->dev, "pm800_init fail\n"); 499 529 goto out_init; ··· 523 553 524 554 ret = device_800_init(chip, pdata); 525 555 if (ret) { 526 - dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id); 556 + dev_err(chip->dev, "Failed to initialize 88pm800 devices\n"); 527 557 goto err_device_init; 528 558 } 529 559
+3 -13
drivers/mfd/88pm805.c
··· 29 29 #include <linux/slab.h> 30 30 #include <linux/delay.h> 31 31 32 - #define PM805_CHIP_ID (0x00) 33 - 34 32 static const struct i2c_device_id pm80x_id_table[] = { 35 - {"88PM805", CHIP_PM805}, 33 + {"88PM805", 0}, 36 34 {} /* NULL terminated */ 37 35 }; 38 36 MODULE_DEVICE_TABLE(i2c, pm80x_id_table); ··· 190 192 static int device_805_init(struct pm80x_chip *chip) 191 193 { 192 194 int ret = 0; 193 - unsigned int val; 194 195 struct regmap *map = chip->regmap; 195 196 196 197 if (!map) { 197 198 dev_err(chip->dev, "regmap is invalid\n"); 198 199 return -EINVAL; 199 200 } 200 - 201 - ret = regmap_read(map, PM805_CHIP_ID, &val); 202 - if (ret < 0) { 203 - dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); 204 - goto out_irq_init; 205 - } 206 - chip->version = val; 207 201 208 202 chip->regmap_irq_chip = &pm805_irq_chip; 209 203 ··· 229 239 struct pm80x_chip *chip; 230 240 struct pm80x_platform_data *pdata = client->dev.platform_data; 231 241 232 - ret = pm80x_init(client, id); 242 + ret = pm80x_init(client); 233 243 if (ret) { 234 244 dev_err(&client->dev, "pm805_init fail!\n"); 235 245 goto out_init; ··· 239 249 240 250 ret = device_805_init(chip); 241 251 if (ret) { 242 - dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id); 252 + dev_err(chip->dev, "Failed to initialize 88pm805 devices\n"); 243 253 goto err_805_init; 244 254 } 245 255
+40 -7
drivers/mfd/88pm80x.c
··· 18 18 #include <linux/uaccess.h> 19 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 + 26 + struct pm80x_chip_mapping { 27 + unsigned int id; 28 + int type; 29 + }; 30 + 31 + static 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 39 * workaround: some registers needed by pm805 are defined in pm800, so 23 40 * need to use this global variable to maintain the relation between ··· 48 31 }; 49 32 EXPORT_SYMBOL_GPL(pm80x_regmap_config); 50 33 51 - int pm80x_init(struct i2c_client *client, 52 - const struct i2c_device_id *id) 34 + 35 + int pm80x_init(struct i2c_client *client) 53 36 { 54 37 struct pm80x_chip *chip; 55 38 struct regmap *map; 56 - int ret = 0; 39 + unsigned int val; 40 + int i, ret = 0; 57 41 58 42 chip = 59 43 devm_kzalloc(&client->dev, sizeof(struct pm80x_chip), GFP_KERNEL); ··· 69 51 return ret; 70 52 } 71 53 72 - chip->id = id->driver_data; 73 - if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805) 74 - return -EINVAL; 75 - 76 54 chip->client = client; 77 55 chip->regmap = map; 78 56 ··· 77 63 chip->dev = &client->dev; 78 64 dev_set_drvdata(chip->dev, chip); 79 65 i2c_set_clientdata(chip->client, chip); 66 + 67 + ret = regmap_read(chip->regmap, PM80X_CHIP_ID, &val); 68 + if (ret < 0) { 69 + dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); 70 + return ret; 71 + } 72 + 73 + for (i = 0; i < ARRAY_SIZE(chip_mapping); i++) { 74 + if (chip_mapping[i].id == PM80X_CHIP_ID_NUM(val)) { 75 + chip->type = chip_mapping[i].type; 76 + break; 77 + } 78 + } 79 + 80 + if (i == ARRAY_SIZE(chip_mapping)) { 81 + dev_err(chip->dev, 82 + "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val); 83 + return -EINVAL; 84 + } 80 85 81 86 device_init_wakeup(&client->dev, 1); 82 87
+2 -5
include/linux/mfd/88pm80x.h
··· 17 17 #include <linux/regmap.h> 18 18 #include <linux/atomic.h> 19 19 20 - #define PM80X_VERSION_MASK (0xFF) /* 80X chip ID mask */ 21 20 enum { 22 21 CHIP_INVALID = 0, 23 22 CHIP_PM800, ··· 298 299 struct regmap *regmap; 299 300 struct regmap_irq_chip *regmap_irq_chip; 300 301 struct regmap_irq_chip_data *irq_data; 301 - unsigned char version; 302 - int id; 302 + int type; 303 303 int irq; 304 304 int irq_mode; 305 305 unsigned long wu_flag; ··· 359 361 } 360 362 #endif 361 363 362 - extern int pm80x_init(struct i2c_client *client, 363 - const struct i2c_device_id *id); 364 + extern int pm80x_init(struct i2c_client *client); 364 365 extern int pm80x_deinit(void); 365 366 #endif /* __LINUX_MFD_88PM80X_H */