Skip to content

Commit b797a55

Browse files
broonieSamuel Ortiz
authored andcommitted
mfd: Refactor WM8350 chip identification
Since the WM8350 driver was originally written the semantics for the identification registers of the chip have been clarified, allowing us to do an exact match on all the fields. This avoids mistakenly running on unsupported hardware. Also change to using the datasheet names more consistently for legibility and fix a printk() that should be dev_err(). Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Samuel Ortiz <sameo@openedhand.com>
1 parent d756f4a commit b797a55

2 files changed

Lines changed: 43 additions & 17 deletions

File tree

‎drivers/mfd/wm8350-core.c‎

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,52 +1227,72 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
12271227
struct wm8350_platform_data *pdata)
12281228
{
12291229
int ret = -EINVAL;
1230-
u16 id1, id2, mask, mode;
1230+
u16 id1, id2, mask_rev;
1231+
u16 cust_id, mode, chip_rev;
12311232

12321233
/* get WM8350 revision and config mode */
12331234
wm8350->read_dev(wm8350, WM8350_RESET_ID, sizeof(id1), &id1);
12341235
wm8350->read_dev(wm8350, WM8350_ID, sizeof(id2), &id2);
1236+
wm8350->read_dev(wm8350, WM8350_REVISION, sizeof(mask_rev), &mask_rev);
12351237

12361238
id1 = be16_to_cpu(id1);
12371239
id2 = be16_to_cpu(id2);
1240+
mask_rev = be16_to_cpu(mask_rev);
12381241

1239-
if (id1 == 0x6143) {
1240-
switch ((id2 & WM8350_CHIP_REV_MASK) >> 12) {
1242+
if (id1 != 0x6143) {
1243+
dev_err(wm8350->dev,
1244+
"Device with ID %x is not a WM8350\n", id1);
1245+
ret = -ENODEV;
1246+
goto err;
1247+
}
1248+
1249+
mode = id2 & WM8350_CONF_STS_MASK >> 10;
1250+
cust_id = id2 & WM8350_CUST_ID_MASK;
1251+
chip_rev = (id2 & WM8350_CHIP_REV_MASK) >> 12;
1252+
dev_info(wm8350->dev,
1253+
"CONF_STS %d, CUST_ID %d, MASK_REV %d, CHIP_REV %d\n",
1254+
mode, cust_id, mask_rev, chip_rev);
1255+
1256+
if (cust_id != 0) {
1257+
dev_err(wm8350->dev, "Unsupported CUST_ID\n");
1258+
ret = -ENODEV;
1259+
goto err;
1260+
}
1261+
1262+
switch (mask_rev) {
1263+
case 0:
1264+
switch (chip_rev) {
12411265
case WM8350_REV_E:
1242-
dev_info(wm8350->dev, "Found Rev E device\n");
1266+
dev_info(wm8350->dev, "WM8350 Rev E\n");
12431267
break;
12441268
case WM8350_REV_F:
1245-
dev_info(wm8350->dev, "Found Rev F device\n");
1269+
dev_info(wm8350->dev, "WM8350 Rev F\n");
12461270
break;
12471271
case WM8350_REV_G:
1248-
dev_info(wm8350->dev, "Found Rev G device\n");
1272+
dev_info(wm8350->dev, "WM8350 Rev G\n");
12491273
wm8350->power.rev_g_coeff = 1;
12501274
break;
12511275
case WM8350_REV_H:
1252-
dev_info(wm8350->dev, "Found Rev H device\n");
1276+
dev_info(wm8350->dev, "WM8350 Rev H\n");
12531277
wm8350->power.rev_g_coeff = 1;
12541278
break;
12551279
default:
12561280
/* For safety we refuse to run on unknown hardware */
1257-
dev_info(wm8350->dev, "Found unknown rev %x\n",
1258-
(id2 & WM8350_CHIP_REV_MASK) >> 12);
1281+
dev_err(wm8350->dev, "Unknown WM8350 CHIP_REV\n");
12591282
ret = -ENODEV;
12601283
goto err;
12611284
}
1262-
} else {
1263-
dev_info(wm8350->dev, "Device with ID %x is not a WM8350\n",
1264-
id1);
1285+
break;
1286+
1287+
default:
1288+
dev_err(wm8350->dev, "Unknown MASK_REV\n");
12651289
ret = -ENODEV;
12661290
goto err;
12671291
}
12681292

1269-
mode = id2 & WM8350_CONF_STS_MASK >> 10;
1270-
mask = id2 & WM8350_CUST_ID_MASK;
1271-
dev_info(wm8350->dev, "Config mode %d, ROM mask %d\n", mode, mask);
1272-
12731293
ret = wm8350_create_cache(wm8350, mode);
12741294
if (ret < 0) {
1275-
printk(KERN_ERR "wm8350: failed to create register cache\n");
1295+
dev_err(wm8350->dev, "Failed to create register cache\n");
12761296
return ret;
12771297
}
12781298

‎include/linux/mfd/wm8350/core.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
#define WM8350_RESET_ID 0x00
3131
#define WM8350_ID 0x01
32+
#define WM8350_REVISION 0x02
3233
#define WM8350_SYSTEM_CONTROL_1 0x03
3334
#define WM8350_SYSTEM_CONTROL_2 0x04
3435
#define WM8350_SYSTEM_HIBERNATE 0x05
@@ -79,6 +80,11 @@
7980
#define WM8350_CONF_STS_MASK 0x0C00
8081
#define WM8350_CUST_ID_MASK 0x00FF
8182

83+
/*
84+
* R2 (0x02) - Revision
85+
*/
86+
#define WM8350_MASK_REV_MASK 0x00FF
87+
8288
/*
8389
* R3 (0x03) - System Control 1
8490
*/

0 commit comments

Comments
 (0)