static void oplus_vooc_switch_check_work(struct work_struct *work)
1719 {
1720 struct delayed_work *dwork = to_delayed_work(work);
1721 struct oplus_chg_vooc *chip = container_of(dwork, struct oplus_chg_vooc,
1722 vooc_switch_check_work);
1723 int chg_type;
1724 bool present = false;
1725 bool retry_flag = false;
1726 static unsigned long fastchg_check_timeout;
1727 unsigned long schedule_delay = 0;
1728 int rc;
1729 union mms_msg_data data = { 0 };
1730 struct timespec64 uptime;
1731
1732 chg_info("vooc switch check\n");
1733
1734 rc = oplus_vooc_cpa_switch_start(chip);
1735 if (rc < 0) {
1736 chg_info("cpa protocol not vooc, return\n");
1737 return;
1738 }
1739 if (!chip->config.svooc_support) {
1740 chg_info("The SVOOC project does not allow fast charge"
1741 "again after the VOOC adapter is recognized\n");
1742 oplus_vooc_cpa_switch_end(chip);
1743 return;
1744 }
1745
1746 present = oplus_wired_is_present();
1747 if (!present) {
1748 if (!chip->vooc_online) {
1749 chip->switch_retry_count = 0;
1750 oplus_vooc_cpa_switch_end(chip);
1751 }
1752 chg_info("vooc_online = %d, present is false, return\n", chip->vooc_online);
1753 return;
1754 }
1755
1756 if (chip->abnormal_adapter_dis_cnt > 0 &&
1757 chip->support_abnormal_over_80w_adapter &&
1758 (chip->pre_is_abnormal_adapter & ABNOMAL_ADAPTER_IS_OVER_80W_ADAPTER)) {
1759 if (chip->abnormal_adapter_dis_cnt >= chip->abnormal_over_80w_adapter_cur_arraycnt) {
1760 chg_info("abnormal over_80w adapter dis cnt is %d >= vooc_max, switch to noraml and clear the count \n",
1761 chip->abnormal_adapter_dis_cnt);
1762 chip->abnormal_adapter_dis_cnt = 0;
1763 oplus_chg_clear_abnormal_adapter_var(chip);
1764 if (oplus_chg_vooc_get_switch_mode(chip->vooc_ic) !=
1765 VOOC_SWITCH_MODE_NORMAL) {
1766 switch_normal_chg(chip->vooc_ic);
1767 oplus_vooc_set_reset_sleep(chip->vooc_ic);
1768 }
1769 oplus_vooc_cpa_switch_end(chip);
1770 return;
1771 }
1772 } else if (chip->abnormal_adapter_dis_cnt > 0 &&
1773 chip->support_abnormal_adapter &&
1774 (chip->pre_is_abnormal_adapter & ABNOMAL_ADAPTER_IS_65W_ABNOMAL_ADAPTER) &&
1775 (chip->abnormal_adapter_dis_cnt >= chip->abnormal_adapter_cur_arraycnt)) {
1776 chg_info("abnormal adapter dis cnt is %d >= vooc_max, switch to noraml and clear the count\n",
1777 chip->abnormal_adapter_dis_cnt);
1778 chip->abnormal_adapter_dis_cnt = 0;
1779 oplus_chg_clear_abnormal_adapter_var(chip);
1780 if (oplus_chg_vooc_get_switch_mode(chip->vooc_ic) !=
1781 VOOC_SWITCH_MODE_NORMAL) {
1782 switch_normal_chg(chip->vooc_ic);
1783 oplus_vooc_set_reset_sleep(chip->vooc_ic);
1784 }
1785 oplus_vooc_cpa_switch_end(chip);
1786 return;
1787 }
1788
1789 if (chip->fastchg_disable) {
1790 chip->switch_retry_count = 0;
1791 chg_info("fastchg disable, return\n");
1792 oplus_vooc_cpa_switch_end(chip);
1793 return;
1794 }
1795 if (chip->fastchg_started) {
1796 chip->switch_retry_count = 0;
1797 chg_err("fastchg_started=%d\n", chip->fastchg_started);
1798 return;
1799 }
1800
1801 if (chip->cpa_support)
1802 chg_type = oplus_vooc_get_real_wired_type(chip);
1803 else
1804 chg_type = oplus_wired_get_chg_type();
1805 if ((chip->ufcs_vid == OPLUS_SVID) &&
1806 (chg_type == OPLUS_CHG_USB_TYPE_PD_PPS || chg_type == OPLUS_CHG_USB_TYPE_PD)) {
1807 chg_err("chg type is pd/pps and get ufcs vid is 0x22d9, enable pd svooc\n");
1808 vote(chip->pd_svooc_votable, SVID_VOTER, true, 1, false);
1809 }
1810 /* The cpa module will ensure the correctness of the type*/
1811 if (!chip->cpa_support) {
1812 switch (chg_type) {
1813 case OPLUS_CHG_USB_TYPE_DCP:
1814 case OPLUS_CHG_USB_TYPE_ACA:
1815 case OPLUS_CHG_USB_TYPE_APPLE_BRICK_ID:
1816 case OPLUS_CHG_USB_TYPE_SVOOC:
1817 case OPLUS_CHG_USB_TYPE_VOOC:
1818 break;
1819 case OPLUS_CHG_USB_TYPE_PD:
1820 case OPLUS_CHG_USB_TYPE_PD_PPS:
1821 if (!chip->pd_svooc) {
1822 chip->switch_retry_count = 0;
1823 chg_info("pd_svooc=false\n");
1824 return;
1825 }
1826 break;
1827 default:
1828 chip->switch_retry_count = 0;
1829 chg_info("chg_type=%s, not support fastchg\n",
1830 oplus_wired_get_chg_type_str(chg_type));
1831 return;
1832 }
1833 } else {
1834 /* The cpa module not ensure pd_svooc when pd_pps*/
1835 if ((chg_type == OPLUS_CHG_USB_TYPE_PD_PPS ||
1836 chg_type == OPLUS_CHG_USB_TYPE_PD) &&
1837 !chip->pd_svooc) {
1838 reinit_completion(&chip->pdsvooc_check_ack);
1839 rc = wait_for_completion_timeout(&chip->pdsvooc_check_ack,
1840 msecs_to_jiffies(PDSVOOC_CHECK_WAIT_TIME_MS));
1841 chg_info("pdsvooc check ack rc: %d, pd_svooc: %d\n", rc, chip->pd_svooc);
1842 if (!rc || !chip->pd_svooc) {
1843 chip->switch_retry_count = 0;
1844 oplus_cpa_switch_end(chip->cpa_topic, CHG_PROTOCOL_VOOC);
1845 return;
1846 }
1847 }
1848 }
1849
1850 reinit_completion(&chip->vooc_wait_bc12);
1851 chg_info("chg_type=%d\n", chg_type);
1852 if (chg_type == OPLUS_CHG_USB_TYPE_UNKNOWN) {
1853 wait_for_completion_timeout(
1854 &chip->vooc_wait_bc12,
1855 msecs_to_jiffies(VOOC_WAIT_BC1P2_GET_TYPE));
1856 chg_type = oplus_wired_get_chg_type();
1857 if (chg_type == OPLUS_CHG_USB_TYPE_UNKNOWN || chip->fastchg_started) {
1858 if (!chip->vooc_online) {
1859 chip->switch_retry_count = 0;
1860 oplus_cpa_switch_end(chip->cpa_topic, CHG_PROTOCOL_VOOC);
1861 }
1862 return;
1863 }
1864 }
1865
1866 if (chip->switch_retry_count == 0 && oplus_wired_get_ibus() < BEFORE_VOOC_CURR_CHECK) {
1867 rc = oplus_mms_get_item_data(chip->wired_topic, WIRED_ITEM_ICL_DONE_STATUS, &data, true);
1868 if (rc == 0 && data.intval == 0) {
1869 reinit_completion(&chip->icl_done_ack);
1870 rc = wait_for_completion_timeout(&chip->icl_done_ack,
1871 msecs_to_jiffies(WAIT_CURR_STARUP));
1872 chg_info("wait wired icl done over\n");
1873 }
1874 }
1875
1876 chg_info("switch_retry_count=%d, fast_chg_status=%d fastchg_check_timeout=%lu\n",
1877 chip->switch_retry_count, chip->fast_chg_status, fastchg_check_timeout);
1878 if (chip->switch_retry_count == 0) {
1879 if (oplus_chg_get_boot_reset_adapter_support_flags() && !chip->check_boot_reset_adapter) {
1880 ktime_get_boottime_ts64(&uptime);
1881 if ((unsigned long)uptime.tv_sec < BOOT_RESETADAPTER_20S) {
1882 chip->check_boot_reset_adapter = true;
1883 chip->reset_adapter = true;
1884 }
1885 }
1886 if ((chip->fast_chg_status ==
1887 CHARGER_STATUS_SWITCH_TEMP_RANGE ||
1888 chip->fast_chg_status == CHARGER_STATUS_FAST_TO_WARM ||
1889 chip->fast_chg_status == CHARGER_STATUS_FAST_DUMMY ||
1890 chip->fast_chg_status == CHARGER_STATUS_TIMEOUT_RETRY ||
1891 chip->fast_chg_status == CHARGER_STATUS_CURR_LIMIT ||
1892 chip->reset_adapter) &&
1893 oplus_vooc_is_allow_fast_chg(chip) &&
1894 is_wired_charge_suspend_votable_available(chip)) {
1895 chg_info("fast_chg_status=%d reset adapter\n",
1896 chip->fast_chg_status);
1897 chip->reset_adapter = false;
1898 /* Reset adapter */
1899 oplus_reset_adapter(chip);
1900 }
1901
1902 fastchg_check_timeout = jiffies;
1903 chg_err("switch to fastchg, jiffies=%lu\n", fastchg_check_timeout);
1904
1905 chip->switch_retry_count++;
1906 oplus_vooc_switch_fast_chg(chip);
1907 schedule_delayed_work(&chip->vooc_switch_check_work, msecs_to_jiffies(5000));
1908 return;
1909
1910 } else if (chip->switch_retry_count <= RETRY_15S_COUNT) {
1911 if ((chip->switch_retry_count == 1) &&
1912 time_is_after_jiffies(fastchg_check_timeout + (unsigned long)(5 * HZ))) {
1913 schedule_delay = fastchg_check_timeout + (unsigned long)(5 * HZ) - jiffies;
1914 schedule_delayed_work(&chip->vooc_switch_check_work, schedule_delay);
1915 chg_err("Concurrent invalid calls lead to early triggering."
1916 "The 5s interval has not expired, so continue to wait %lu jiffies\n",
1917 schedule_delay);
1918 return;
1919 } else if ((chip->switch_retry_count == RETRY_15S_COUNT) &&
1920 time_is_after_jiffies(fastchg_check_timeout + (unsigned long)(15 * HZ))) {
1921 schedule_delay = fastchg_check_timeout + (unsigned long)(15 * HZ) - jiffies;
1922 schedule_delayed_work(&chip->vooc_switch_check_work, schedule_delay);
1923 chg_err("Concurrent invalid calls lead to early triggering."
1924 "The 15s interval has not expired, so continue to wait %lu jiffies\n",
1925 schedule_delay);
1926 return;
1927 }
1928
1929 oplus_vooc_get_retry_flag(chip->vooc_ic, &retry_flag);
1930 if (chip->switch_retry_count == 1 && !retry_flag) {
1931 chip->switch_retry_count++;
1932 schedule_delayed_work(&chip->vooc_switch_check_work, msecs_to_jiffies(10000));
1933 return;
1934 }
1935 if (is_wired_charge_suspend_votable_available(chip)) {
1936 if (chip->vooc_ic->type == OPLUS_CHG_IC_VIRTUAL_VPHY)
1937 switch_normal_chg(chip->vooc_ic);
1938 /* Reset adapter */
1939 oplus_reset_adapter(chip);
1940 }
1941 if (chip->wired_online &&
1942 (oplus_chg_vooc_get_switch_mode(chip->vooc_ic) !=
1943 VOOC_SWITCH_MODE_VOOC)) {
1944 switch_fast_chg(chip->vooc_ic);
1945 chg_err("D+D- did not switch to VOOC mode, try switching\n");
1946 }
1947 oplus_vooc_set_reset_active(chip->vooc_ic);
1948 if (chip->switch_retry_count == RETRY_15S_COUNT)
1949 schedule_delayed_work(&chip->vooc_switch_check_work, msecs_to_jiffies(15000));
1950 else
1951 schedule_delayed_work(&chip->vooc_switch_check_work, msecs_to_jiffies(10000));
1952 chip->switch_retry_count++;
1953 return;
1954 } else {
1955 if ((chip->switch_retry_count == 3) &&
1956 time_is_after_jiffies(fastchg_check_timeout + (unsigned long)(30 * HZ))) {
1957 schedule_delay = fastchg_check_timeout + (unsigned long)(30 * HZ) - jiffies;
1958 schedule_delayed_work(&chip->vooc_switch_check_work, schedule_delay);
1959 chg_err("Concurrent invalid calls lead to early triggering."
1960 "The 30s interval has not expired, so continue to wait %lu jiffies\n",
1961 schedule_delay);
1962 return;
1963 }
1964
1965 chip->switch_retry_count = 0;
1966 switch_normal_chg(chip->vooc_ic);
1967 oplus_vooc_set_reset_sleep(chip->vooc_ic);
1968
1969 if (chg_type == OPLUS_CHG_USB_TYPE_QC2 ||
1970 chg_type == OPLUS_CHG_USB_TYPE_QC3 ||
1971 chg_type == OPLUS_CHG_USB_TYPE_DCP ||
1972 chg_type == OPLUS_CHG_USB_TYPE_APPLE_BRICK_ID) {
1973 if (is_wired_charge_suspend_votable_available(chip)) {
1974 chg_err("reset adapter before detect qc\n");
1975 vote(chip->wired_charge_suspend_votable, ADAPTER_RESET_VOTER, true, 1, false);
1976 if (chip->wired_online)
1977 msleep(MSLEEP_1000MS);
1978 vote(chip->wired_charge_suspend_votable, ADAPTER_RESET_VOTER, false, 0, false);
1979 if (chip->wired_online)
1980 msleep(MSLEEP_500MS);
1981 }
1982 if (!chip->cpa_support) {
1983 chg_err("detect qc\n");
1984 oplus_qc_check_setup_timer(chip, QC_CHECK_TIMER);
1985 oplus_wired_qc_detect_enable(true);
1986 } else {
1987 oplus_cpa_request(chip->cpa_topic, CHG_PROTOCOL_QC);
1988 }
1989 }
1990 if (chip->cpa_support && chip->pd_svooc) {
1991 /* recheck pd */
1992 oplus_cpa_request(chip->cpa_topic, CHG_PROTOCOL_PD);
1993 }
1994
1995 if (chip->wired_online)
1996 vote(chip->vooc_disable_votable, TIMEOUT_VOTER, true, 1, false);
1997 vote(chip->pd_svooc_votable, DEF_VOTER, false, 0, false);
1998 vote(chip->pd_svooc_votable, SVID_VOTER, false, 0, false);
1999 oplus_cpa_switch_end(chip->cpa_topic, CHG_PROTOCOL_VOOC);
2000 return;
2001 }
2002 }
2003 逐行注释