]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/kernel-video.git/commitdiff
mfd: Palmas: Introduce palmas_pmic_data structure
authorJ Keerthy <j-keerthy@ti.com>
Wed, 24 Apr 2013 06:20:49 +0000 (11:50 +0530)
committerJ Keerthy <j-keerthy@ti.com>
Tue, 28 May 2013 05:38:59 +0000 (11:08 +0530)
Introduce palmas_pmic_data structure so that Palmas variants
like TWL6035, TWL6037, TPS65913 can populate data specific
to them. This enables driver to support variants.

Signed-off-by: J Keerthy <j-keerthy@ti.com>
drivers/mfd/palmas.c
include/linux/mfd/palmas.h

index b077bedda03ef18d211c6d30446ac6fc1679d61d..e7947cbbd55ae885a88d3073644874941e58e6bd 100644 (file)
@@ -333,6 +333,22 @@ err:
        return ret;
 }
 
+static struct palmas_pmic_data palmas_data = {
+       .irq_chip = &palmas_irq_chip,
+       .regmap_config = palmas_regmap_config,
+       .mfd_cell = palmas_children,
+       .id = TWL6035,
+       .has_usb = 1,
+};
+
+static const struct of_device_id of_palmas_match_tbl[] = {
+       {
+               .compatible = "ti,palmas",
+               .data = &palmas_data,
+       },
+       { },
+};
+
 static int palmas_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
 {
@@ -343,6 +359,8 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
        unsigned int reg, addr;
        int slave;
        struct mfd_cell *children;
+       const struct of_device_id *match;
+       const struct palmas_pmic_data *pmic_data;
 
        pdata = dev_get_platdata(&i2c->dev);
 
@@ -364,9 +382,18 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
 
        i2c_set_clientdata(i2c, palmas);
        palmas->dev = &i2c->dev;
-       palmas->id = id->driver_data;
+       palmas->palmas_id = id->driver_data;
        palmas->irq = i2c->irq;
 
+       match = of_match_device(of_match_ptr(of_palmas_match_tbl), &i2c->dev);
+
+       if (match) {
+               pmic_data = match->data;
+               palmas->palmas_id = pmic_data->id;
+       } else {
+               return -ENODATA;
+       }
+
        for (i = 0; i < PALMAS_NUM_CLIENTS; i++) {
                if (i == 0)
                        palmas->i2c_clients[i] = i2c;
@@ -382,7 +409,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
                        }
                }
                palmas->regmap[i] = devm_regmap_init_i2c(palmas->i2c_clients[i],
-                               &palmas_regmap_config[i]);
+                               pmic_data->regmap_config + i);
                if (IS_ERR(palmas->regmap[i])) {
                        ret = PTR_ERR(palmas->regmap[i]);
                        dev_err(palmas->dev,
@@ -400,7 +427,7 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
        regmap_write(palmas->regmap[slave], addr, reg);
 
        ret = regmap_add_irq_chip(palmas->regmap[slave], palmas->irq,
-                       IRQF_ONESHOT, 0, &palmas_irq_chip,
+                       IRQF_ONESHOT, 0, pmic_data->irq_chip,
                        &palmas->irq_data);
        if (ret < 0)
                goto err;
@@ -491,6 +518,10 @@ static int palmas_i2c_probe(struct i2c_client *i2c,
                        return ret;
        }
 
+       /*
+        * For now all PMICs belonging to palmas family are assumed to get the
+        * same childern as PALMAS
+        */
        children = kmemdup(palmas_children, sizeof(palmas_children),
                           GFP_KERNEL);
        if (!children) {
@@ -545,19 +576,14 @@ static int palmas_i2c_remove(struct i2c_client *i2c)
 }
 
 static const struct i2c_device_id palmas_i2c_id[] = {
-       { "palmas", },
-       { "twl6035", },
-       { "twl6037", },
-       { "tps65913", },
+       { "palmas", TWL6035},
+       { "twl6035", TWL6035},
+       { "twl6037", TWL6037},
+       { "tps65913", TPS65913},
        { /* end */ }
 };
 MODULE_DEVICE_TABLE(i2c, palmas_i2c_id);
 
-static struct of_device_id of_palmas_match_tbl[] = {
-       { .compatible = "ti,palmas", },
-       { /* end */ }
-};
-
 static struct i2c_driver palmas_i2c_driver = {
        .driver = {
                   .name = "palmas",
index 82932db7fdb4c533673b343641e8b7da96410cf9..7838df7f4d3cea2572b47a0d4322ac730c76880d 100644 (file)
@@ -38,6 +38,7 @@ struct palmas {
        int designrev;
        int sw_revision;
 
+       int palmas_id;
        /* IRQ Data */
        int irq;
        u32 irq_mask;
@@ -132,6 +133,12 @@ struct palmas_reg_init {
 
 };
 
+enum pmic_ids {
+       TWL6035,
+       TWL6037,
+       TPS65913,
+};
+
 enum palmas_regulators {
        /* SMPS regulators */
        PALMAS_REG_SMPS12,
@@ -361,6 +368,26 @@ struct palmas_usb {
        u8 linkstat;
 };
 
+/**
+ * struct palmas_pmic_data -   Maintains the specific data for PMICs of PALMAS
+ *                             family
+ * @irq_chip:                  regmap_irq_chip specific to individual members
+ *                             of PALMAS family.
+ * @regmap_config:             regmap_config specific to the individual members
+ *                             of PALMAS family.
+ * @mfd_cell:                  mfd cell  specific to the individual members of
+ *                             PALMAS family.
+ * @id:                                Id of the member of the PALMAS family.
+ * @has_usb:                   Flag indicating whether PMIC supports USB
+ */
+struct palmas_pmic_data {
+       struct regmap_irq_chip *irq_chip;
+       const struct regmap_config *regmap_config;
+       const struct mfd_cell *mfd_cell;
+       int id;
+       int has_usb;
+};
+
 #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator)
 
 enum usb_irq_events {