#include <linux/mfd/88pm80x.h>
#include <linux/slab.h>
-#define PM800_CHIP_ID (0x00)
-
/* Interrupt Registers */
#define PM800_INT_STATUS1 (0x05)
#define PM800_ONKEY_INT_STS1 (1 << 0)
PM800_MAX_IRQ,
};
-enum {
- /* Procida */
- PM800_CHIP_A0 = 0x60,
- PM800_CHIP_A1 = 0x61,
- PM800_CHIP_B0 = 0x62,
- PM800_CHIP_C0 = 0x63,
- PM800_CHIP_END = PM800_CHIP_C0,
-
- /* Make sure to update this to the last stepping */
- PM8XXX_CHIP_END = PM800_CHIP_END
-};
+/* PM800: generation identification number */
+#define PM800_CHIP_GEN_ID_NUM 0x3
static const struct i2c_device_id pm80x_id_table[] = {
- {"88PM800", CHIP_PM800},
+ {"88PM800", 0},
{} /* NULL terminated */
};
MODULE_DEVICE_TABLE(i2c, pm80x_id_table);
static int device_800_init(struct pm80x_chip *chip,
struct pm80x_platform_data *pdata)
{
- int ret, pmic_id;
+ int ret;
unsigned int val;
- ret = regmap_read(chip->regmap, PM800_CHIP_ID, &val);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
- goto out;
- }
-
- pmic_id = val & PM80X_VERSION_MASK;
-
- if ((pmic_id >= PM800_CHIP_A0) && (pmic_id <= PM800_CHIP_END)) {
- chip->version = val;
- dev_info(chip->dev,
- "88PM80x:Marvell 88PM800 (ID:0x%x) detected\n", val);
- } else {
- dev_err(chip->dev,
- "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val);
- ret = -EINVAL;
- goto out;
- }
-
/*
* alarm wake up bit will be clear in device_irq_init(),
* read before that
struct pm80x_platform_data *pdata = client->dev.platform_data;
struct pm80x_subchip *subchip;
- ret = pm80x_init(client, id);
+ ret = pm80x_init(client);
if (ret) {
dev_err(&client->dev, "pm800_init fail\n");
goto out_init;
ret = device_800_init(chip, pdata);
if (ret) {
- dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id);
+ dev_err(chip->dev, "Failed to initialize 88pm800 devices\n");
goto err_device_init;
}
#include <linux/slab.h>
#include <linux/delay.h>
-#define PM805_CHIP_ID (0x00)
-
static const struct i2c_device_id pm80x_id_table[] = {
- {"88PM805", CHIP_PM805},
+ {"88PM805", 0},
{} /* NULL terminated */
};
MODULE_DEVICE_TABLE(i2c, pm80x_id_table);
static int device_805_init(struct pm80x_chip *chip)
{
int ret = 0;
- unsigned int val;
struct regmap *map = chip->regmap;
if (!map) {
return -EINVAL;
}
- ret = regmap_read(map, PM805_CHIP_ID, &val);
- if (ret < 0) {
- dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
- goto out_irq_init;
- }
- chip->version = val;
-
chip->regmap_irq_chip = &pm805_irq_chip;
ret = device_irq_init_805(chip);
struct pm80x_chip *chip;
struct pm80x_platform_data *pdata = client->dev.platform_data;
- ret = pm80x_init(client, id);
+ ret = pm80x_init(client);
if (ret) {
dev_err(&client->dev, "pm805_init fail!\n");
goto out_init;
ret = device_805_init(chip);
if (ret) {
- dev_err(chip->dev, "%s id 0x%x failed!\n", __func__, chip->id);
+ dev_err(chip->dev, "Failed to initialize 88pm805 devices\n");
goto err_805_init;
}
#include <linux/uaccess.h>
#include <linux/err.h>
+/* 88pm80x chips have same definition for chip id register. */
+#define PM80X_CHIP_ID (0x00)
+#define PM80X_CHIP_ID_NUM(x) (((x) >> 5) & 0x7)
+#define PM80X_CHIP_ID_REVISION(x) ((x) & 0x1F)
+
+struct pm80x_chip_mapping {
+ unsigned int id;
+ int type;
+};
+
+static struct pm80x_chip_mapping chip_mapping[] = {
+ /* 88PM800 chip id number */
+ {0x3, CHIP_PM800},
+ /* 88PM805 chip id number */
+ {0x0, CHIP_PM805},
+};
+
/*
* workaround: some registers needed by pm805 are defined in pm800, so
* need to use this global variable to maintain the relation between
};
EXPORT_SYMBOL_GPL(pm80x_regmap_config);
-int pm80x_init(struct i2c_client *client,
- const struct i2c_device_id *id)
+
+int pm80x_init(struct i2c_client *client)
{
struct pm80x_chip *chip;
struct regmap *map;
- int ret = 0;
+ unsigned int val;
+ int i, ret = 0;
chip =
devm_kzalloc(&client->dev, sizeof(struct pm80x_chip), GFP_KERNEL);
return ret;
}
- chip->id = id->driver_data;
- if (chip->id < CHIP_PM800 || chip->id > CHIP_PM805)
- return -EINVAL;
-
chip->client = client;
chip->regmap = map;
dev_set_drvdata(chip->dev, chip);
i2c_set_clientdata(chip->client, chip);
+ ret = regmap_read(chip->regmap, PM80X_CHIP_ID, &val);
+ if (ret < 0) {
+ dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
+ return ret;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(chip_mapping); i++) {
+ if (chip_mapping[i].id == PM80X_CHIP_ID_NUM(val)) {
+ chip->type = chip_mapping[i].type;
+ break;
+ }
+ }
+
+ if (i == ARRAY_SIZE(chip_mapping)) {
+ dev_err(chip->dev,
+ "Failed to detect Marvell 88PM800:ChipID[0x%x]\n", val);
+ return -EINVAL;
+ }
+
device_init_wakeup(&client->dev, 1);
/*
#include <linux/regmap.h>
#include <linux/atomic.h>
-#define PM80X_VERSION_MASK (0xFF) /* 80X chip ID mask */
enum {
CHIP_INVALID = 0,
CHIP_PM800,
struct regmap *regmap;
struct regmap_irq_chip *regmap_irq_chip;
struct regmap_irq_chip_data *irq_data;
- unsigned char version;
- int id;
+ int type;
int irq;
int irq_mode;
unsigned long wu_flag;
}
#endif
-extern int pm80x_init(struct i2c_client *client,
- const struct i2c_device_id *id);
+extern int pm80x_init(struct i2c_client *client);
extern int pm80x_deinit(void);
#endif /* __LINUX_MFD_88PM80X_H */