mfd: palmas: read internal design rev and sw otp revsion of device
Laxman Dewangan [Sat, 9 Feb 2013 19:14:58 +0000 (00:14 +0530)]
Read internal design revision and sw otp version of the device and
print this message.

This will help on implementing the errata of different ES version of
device.

bug 1228386
bug 1195226

Change-Id: I616aafd20cc0fce0f75a2f730107905f739f77cb
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/199131
Reviewed-by: Automatic_Commit_Validation_User

drivers/mfd/palmas.c
include/linux/mfd/palmas.h

index a3f7cf9..4abc140 100644 (file)
@@ -534,6 +534,63 @@ static void palmas_power_off(void)
        palmas_control_update(palmas_dev, PALMAS_DEV_CTRL, 1, 0);
 }
 
+static int palmas_read_version_information(struct palmas *palmas)
+{
+       unsigned int sw_rev, des_rev;
+       int ret;
+
+       ret = palmas_read(palmas, PALMAS_PMU_CONTROL_BASE,
+                               PALMAS_SW_REVISION, &sw_rev);
+       if (ret < 0) {
+               dev_err(palmas->dev, "SW_REVISION read failed: %d\n", ret);
+               return ret;
+       }
+
+       ret = palmas_read(palmas, PALMAS_PAGE3_BASE,
+                               PALMAS_INTERNAL_DESIGNREV, &des_rev);
+       if (ret < 0) {
+               dev_err(palmas->dev,
+                       "INTERNAL_DESIGNREV read failed: %d\n", ret);
+               return ret;
+       }
+
+       palmas->sw_otp_version = sw_rev;
+
+       dev_info(palmas->dev, "Internal DesignRev 0x%02X, SWRev 0x%02X\n",
+                       des_rev, sw_rev);
+       des_rev = PALMAS_INTERNAL_DESIGNREV_DESIGNREV(des_rev);
+       switch (des_rev) {
+       case 0:
+               palmas->es_major_version = 1;
+               palmas->es_minor_version = 0;
+               palmas->design_revision = 0xA0;
+               break;
+       case 1:
+               palmas->es_major_version = 2;
+               palmas->es_minor_version = 0;
+               palmas->design_revision = 0xB0;
+               break;
+       case 2:
+               palmas->es_major_version = 2;
+               palmas->es_minor_version = 1;
+               palmas->design_revision = 0xB1;
+               break;
+       case 3:
+               palmas->es_major_version = 2;
+               palmas->es_minor_version = 2;
+               palmas->design_revision = 0xB2;
+               break;
+       default:
+               dev_err(palmas->dev, "Invalid design revision\n");
+               return -EINVAL;
+       }
+
+       dev_info(palmas->dev, "ES version %d.%d: ChipRevision 0x%02X%02X\n",
+               palmas->es_major_version, palmas->es_minor_version,
+               palmas->design_revision, palmas->sw_otp_version);
+       return 0;
+}
+
 static int __devinit palmas_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
 {
@@ -583,6 +640,10 @@ static int __devinit palmas_i2c_probe(struct i2c_client *i2c,
                }
        }
 
+       ret = palmas_read_version_information(palmas);
+       if (ret < 0)
+               goto err;
+
        /* Change interrupt line output polarity */
        slave = PALMAS_BASE_TO_SLAVE(PALMAS_PU_PD_OD_BASE);
        addr = PALMAS_BASE_TO_REG(PALMAS_PU_PD_OD_BASE, PALMAS_POLARITY_CTRL);
index 947fc09..a3a6599 100644 (file)
@@ -50,6 +50,11 @@ struct palmas {
        u8 gpio_muxed;
        u8 led_muxed;
        u8 pwm_muxed;
+
+       int design_revision;
+       int sw_otp_version;
+       int es_minor_version;
+       int es_major_version;
 };
 
 struct palmas_reg_init {
@@ -317,6 +322,7 @@ struct palmas_pmic {
 #define PALMAS_USB_BASE                                                0x290
 #define PALMAS_GPADC_BASE                                      0x2C0
 #define PALMAS_TRIM_GPADC_BASE                                 0x3CD
+#define PALMAS_PAGE3_BASE                                      0x300
 
 /* Registers for function RTC */
 #define PALMAS_SECONDS_REG                                     0x0
@@ -2668,6 +2674,9 @@ struct palmas_pmic {
 #define PALMAS_GPADC_SMPS_VSEL_MONITORING_SMPS_VSEL_MONITORING_MASK    0x7f
 #define PALMAS_GPADC_SMPS_VSEL_MONITORING_SMPS_VSEL_MONITORING_SHIFT   0
 
+#define PALMAS_INTERNAL_DESIGNREV                              0x57
+#define PALMAS_INTERNAL_DESIGNREV_DESIGNREV(val)               ((val) & 0xF)
+
 /* Registers for function GPADC */
 #define PALMAS_GPADC_TRIM1                                     0x0
 #define PALMAS_GPADC_TRIM2                                     0x1