Merge branch 'i2c/for-mergewindow' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / drivers / i2c / busses / i2c-cht-wc.c
index 8ccf0c9..de15f09 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/power/bq24190_charger.h>
+#include <linux/power/bq25890_charger.h>
 #include <linux/slab.h>
 
 #define CHT_WC_I2C_CTRL                        0x5e24
@@ -263,6 +264,7 @@ static const struct irq_chip cht_wc_i2c_irq_chip = {
        .name                   = "cht_wc_ext_chrg_irq_chip",
 };
 
+/********** GPD Win / Pocket charger IC settings **********/
 static const char * const bq24190_suppliers[] = {
        "tcpm-source-psy-i2c-fusb302" };
 
@@ -297,17 +299,92 @@ static struct bq24190_platform_data bq24190_pdata = {
        .regulator_init_data = &bq24190_vbus_init_data,
 };
 
+static struct i2c_board_info gpd_win_board_info = {
+       .type = "bq24190",
+       .addr = 0x6b,
+       .dev_name = "bq24190",
+       .swnode = &bq24190_node,
+       .platform_data = &bq24190_pdata,
+};
+
+/********** Xiaomi Mi Pad 2 charger IC settings  **********/
+static struct regulator_consumer_supply bq2589x_vbus_consumer = {
+       .supply = "vbus",
+       .dev_name = "cht_wcove_pwrsrc",
+};
+
+static const struct regulator_init_data bq2589x_vbus_init_data = {
+       .constraints = {
+               .valid_ops_mask = REGULATOR_CHANGE_STATUS,
+       },
+       .consumer_supplies = &bq2589x_vbus_consumer,
+       .num_consumer_supplies = 1,
+};
+
+static struct bq25890_platform_data bq2589x_pdata = {
+       .regulator_init_data = &bq2589x_vbus_init_data,
+};
+
+static const struct property_entry xiaomi_mipad2_props[] = {
+       PROPERTY_ENTRY_BOOL("linux,skip-reset"),
+       PROPERTY_ENTRY_BOOL("linux,read-back-settings"),
+       { }
+};
+
+static const struct software_node xiaomi_mipad2_node = {
+       .properties = xiaomi_mipad2_props,
+};
+
+static struct i2c_board_info xiaomi_mipad2_board_info = {
+       .type = "bq25890",
+       .addr = 0x6a,
+       .dev_name = "bq25890",
+       .swnode = &xiaomi_mipad2_node,
+       .platform_data = &bq2589x_pdata,
+};
+
+/********** Lenovo Yogabook YB1-X90F/-X91F/-X91L charger settings **********/
+static const char * const lenovo_yb1_bq25892_suppliers[] = { "cht_wcove_pwrsrc" };
+
+static const struct property_entry lenovo_yb1_bq25892_props[] = {
+       PROPERTY_ENTRY_STRING_ARRAY("supplied-from",
+                                   lenovo_yb1_bq25892_suppliers),
+       PROPERTY_ENTRY_U32("linux,pump-express-vbus-max", 12000000),
+       PROPERTY_ENTRY_BOOL("linux,skip-reset"),
+       /*
+        * The firmware sets everything to the defaults, which leads to a
+        * somewhat low charge-current of 2048mA and worse to a battery-voltage
+        * of 4.2V instead of 4.35V (when booted without a charger connected).
+        * Use our own values instead of "linux,read-back-settings" to fix this.
+        */
+       PROPERTY_ENTRY_U32("ti,charge-current", 4224000),
+       PROPERTY_ENTRY_U32("ti,battery-regulation-voltage", 4352000),
+       PROPERTY_ENTRY_U32("ti,termination-current", 256000),
+       PROPERTY_ENTRY_U32("ti,precharge-current", 128000),
+       PROPERTY_ENTRY_U32("ti,minimum-sys-voltage", 3500000),
+       PROPERTY_ENTRY_U32("ti,boost-voltage", 4998000),
+       PROPERTY_ENTRY_U32("ti,boost-max-current", 1400000),
+       PROPERTY_ENTRY_BOOL("ti,use-ilim-pin"),
+       { }
+};
+
+static const struct software_node lenovo_yb1_bq25892_node = {
+       .properties = lenovo_yb1_bq25892_props,
+};
+
+static struct i2c_board_info lenovo_yogabook1_board_info = {
+       .type = "bq25892",
+       .addr = 0x6b,
+       .dev_name = "bq25892",
+       .swnode = &lenovo_yb1_bq25892_node,
+       .platform_data = &bq2589x_pdata,
+};
+
 static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev)
 {
        struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
+       struct i2c_board_info *board_info = NULL;
        struct cht_wc_i2c_adap *adap;
-       struct i2c_board_info board_info = {
-               .type = "bq24190",
-               .addr = 0x6b,
-               .dev_name = "bq24190",
-               .swnode = &bq24190_node,
-               .platform_data = &bq24190_pdata,
-       };
        int ret, reg, irq;
 
        irq = platform_get_irq(pdev, 0);
@@ -372,17 +449,24 @@ static int cht_wc_i2c_adap_i2c_probe(struct platform_device *pdev)
        if (ret)
                goto remove_irq_domain;
 
-       /*
-        * Normally the Whiskey Cove PMIC is paired with a TI bq24292i charger,
-        * connected to this i2c bus, and a max17047 fuel-gauge and a fusb302
-        * USB Type-C controller connected to another i2c bus. In this setup
-        * the max17047 and fusb302 devices are enumerated through an INT33FE
-        * ACPI device. If this device is present register an i2c-client for
-        * the TI bq24292i charger.
-        */
-       if (acpi_dev_present("INT33FE", NULL, -1)) {
-               board_info.irq = adap->client_irq;
-               adap->client = i2c_new_client_device(&adap->adapter, &board_info);
+       switch (pmic->cht_wc_model) {
+       case INTEL_CHT_WC_GPD_WIN_POCKET:
+               board_info = &gpd_win_board_info;
+               break;
+       case INTEL_CHT_WC_XIAOMI_MIPAD2:
+               board_info = &xiaomi_mipad2_board_info;
+               break;
+       case INTEL_CHT_WC_LENOVO_YOGABOOK1:
+               board_info = &lenovo_yogabook1_board_info;
+               break;
+       default:
+               dev_warn(&pdev->dev, "Unknown model, not instantiating charger device\n");
+               break;
+       }
+
+       if (board_info) {
+               board_info->irq = adap->client_irq;
+               adap->client = i2c_new_client_device(&adap->adapter, board_info);
                if (IS_ERR(adap->client)) {
                        ret = PTR_ERR(adap->client);
                        goto del_adapter;