[RAMEN9610-19595]ccic : add function which control abnormal attach
authorJunhan Bae <junhan84.bae@samsung.com>
Fri, 14 Jun 2019 01:44:01 +0000 (10:44 +0900)
committerKim Gunho <gunho.kim@samsung.com>
Mon, 9 Sep 2019 11:08:07 +0000 (20:08 +0900)
Change-Id: Ie888e46deb67ea81c0ec5e160978a42802b9477e
Signed-off-by: Junhan Bae <junhan84.bae@samsung.com>
drivers/ccic/s2mu106-usbpd.c

index 85ed4d642909eef35bb8cdc09a5961cea1a0c9a7..1a05a931f23aced035c0c3731becf8261b69b65c 100644 (file)
@@ -1281,6 +1281,24 @@ static int s2mu106_set_check_msg_pass(void *_data, int val)
 
        return 0;
 }
+
+static void s2mu106_usbpd_set_threshold(struct s2mu106_usbpd_data *pdic_data,
+                       CCIC_RP_RD_SEL port_sel, CCIC_THRESHOLD_SEL threshold_sel)
+{
+       struct i2c_client *i2c = pdic_data->i2c;
+
+       if (threshold_sel > S2MU106_THRESHOLD_MAX)
+               dev_err(pdic_data->dev, "%s : threshold overflow!!\n", __func__);
+       else {
+               if (port_sel == PLUG_CTRL_RD)
+                       s2mu106_usbpd_write_reg(i2c,
+                               S2MU106_REG_PLUG_CTRL_SET_RD, threshold_sel);
+               else if (port_sel == PLUG_CTRL_RP)
+                       s2mu106_usbpd_write_reg(i2c,
+                               S2MU106_REG_PLUG_CTRL_SET_RP, threshold_sel);
+       }
+}
+
 #ifndef CONFIG_SEC_FACTORY
 static void s2mu106_usbpd_set_rp_scr_sel(struct s2mu106_usbpd_data *pdic_data,
                                                        CCIC_RP_SCR_SEL scr_sel)
@@ -2086,6 +2104,22 @@ static void s2mu106_usbpd_prevent_watchdog_reset(
        mutex_unlock(&pdic_data->lpm_mutex);
 }
 
+static int s2mu106_usbpd_check_abnormal_attach(struct s2mu106_usbpd_data *pdic_data)
+{
+       struct i2c_client *i2c = pdic_data->i2c;
+       u8 data = 0;
+
+       s2mu106_usbpd_set_threshold(pdic_data, PLUG_CTRL_RP,
+                                                                               S2MU106_THRESHOLD_1371MV);
+       msleep(20);
+
+       s2mu106_usbpd_read_reg(i2c, S2MU106_REG_PLUG_MON2, &data);
+       if ((data & S2MU106_PR_MASK) == S2MU106_PDIC_SOURCE)
+               return true;
+       else
+               return false;
+}
+
 static void s2mu106_usbpd_rp_current_check(struct s2mu106_usbpd_data *pdic_data)
 {
        struct i2c_client *i2c = pdic_data->i2c;
@@ -2372,6 +2406,11 @@ static int s2mu106_check_port_detect(struct s2mu106_usbpd_data *pdic_data)
                s2mu106_usbpd_rp_current_check(pdic_data);
        } else if ((data & S2MU106_PR_MASK) == S2MU106_PDIC_SOURCE) {
                dev_info(dev, "SOURCE\n");
+               ret = s2mu106_usbpd_check_abnormal_attach(pdic_data);
+               if (ret == false) {
+                       dev_err(&i2c->dev, "%s, abnormal attach\n", __func__);
+                       return -1;
+               }
                s2mu106_usbpd_set_rp_scr_sel(pdic_data, PLUG_CTRL_RP180);
                ret = s2mu106_usbpd_check_accessory(pdic_data);
                if (ret < 0) {