You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
kernel_samsung_sm7125/drivers/muic/sm5713-muic-afc.c

1033 lines
35 KiB

/*
* sm5713-muic-afc.c - afc driver for the SiliconMitus sm5713
*
* Copyright (C) 2017 SiliconMitus
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This driver is based on max77843-muic-afc.c
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/workqueue.h>
//#include <linux/wakelock.h>
#include <linux/delay.h>
#include <linux/power_supply.h>
#include <linux/device.h>
//#include <linux/battery/sec_battery.h>
#include <linux/mfd/sm5713.h>
#include <linux/mfd/sm5713-private.h>
/* MUIC header file */
#include <linux/muic/muic.h>
#include <linux/muic/sm5713-muic.h>
#if defined(CONFIG_MUIC_NOTIFIER)
#include <linux/muic/muic_notifier.h>
#endif /* CONFIG_MUIC_NOTIFIER */
#define SM5713_MUIC_REG_AFCTASTATUS 0x2D
#define SM5713_MUIC_REG_REVID1 0x3e
#define SM5713_MUIC_AFC_TA 0x00
#define SM5713_MUIC_QC20 0x01
static muic_data_t *afc_init_data;
/* To make AFC work properly on boot */
static int is_charger_ready;
static struct work_struct muic_afc_init_work;
static int afc_prepare_state;
static int afc_prepare_afctxd;
static int afc_prepare_qc20;
int muic_get_vbus_value(void);
int muic_request_disable_afc_state(void)
{
muic_data_t *muic_data = afc_init_data;
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
muic_data->voltage_down_completed = 1;
muic_data->afc_active = 1;
muic_disable_afc(1); /* 9V(12V) -> 5V */
return 0;
}
EXPORT_SYMBOL(muic_request_disable_afc_state);
int muic_done_disable_afc_state(void)
{
muic_data_t *muic_data = afc_init_data;
pr_info("[%s:%s]voltage_down_completed(%d)\n", MUIC_DEV_NAME, __func__, muic_data->voltage_down_completed);
return muic_data->voltage_down_completed;
}
EXPORT_SYMBOL(muic_done_disable_afc_state);
int muic_get_afc_active(void)
{
muic_data_t *muic_data = afc_init_data;
pr_info("[%s:%s]afc_active(%d)\n", MUIC_DEV_NAME, __func__, muic_data->afc_active);
return muic_data->afc_active;
}
EXPORT_SYMBOL(muic_get_afc_active);
int muic_check_fled_state(bool enable, u8 mode)
{
muic_data_t *muic_data = afc_init_data;
pr_info("[%s:%s] enable(%d), mode(%d)\n", MUIC_DEV_NAME, __func__, enable, mode);
if (mode == FLED_MODE_TORCH) { /* torch */
cancel_delayed_work(&muic_data->afc_torch_work);
pr_info("[%s:%s] afc_torch_work cancel\n", MUIC_DEV_NAME, __func__);
muic_data->fled_torch_enable = enable;
} else if (mode == FLED_MODE_FLASH) { /* flash */
muic_data->fled_flash_enable = enable;
}
pr_info("[%s:%s] fled_torch_enable(%d), fled_flash_enable(%d)\n", MUIC_DEV_NAME, __func__, muic_data->fled_torch_enable, muic_data->fled_flash_enable);
if ((muic_data->fled_torch_enable == false) && (muic_data->fled_flash_enable == false)) {
if ((mode == FLED_MODE_TORCH) && (enable == false)) {
cancel_delayed_work(&muic_data->afc_torch_work);
schedule_delayed_work(&muic_data->afc_torch_work, msecs_to_jiffies(5000));
pr_info("[%s:%s] afc_torch_work start(5sec)\n", MUIC_DEV_NAME, __func__);
} else {
muic_data->voltage_down_completed = 0;
muic_data->afc_active = 1;
muic_disable_afc(0); /* 5V -> 9V(12V) */
}
}
return 0;
}
EXPORT_SYMBOL(muic_check_fled_state);
int muic_disable_afc(int disable)
{
muic_data_t *muic_data = afc_init_data;
struct i2c_client *i2c = muic_data->i2c;
int ret = 0;
pr_info("[%s:%s] disable: %d\n", MUIC_DEV_NAME, __func__, disable);
if (disable) { /* AFC disable : 9V(12V) -> 5V */
if ((muic_data->attached_dev == ATTACHED_DEV_AFC_CHARGER_9V_MUIC) ||
(muic_data->attached_dev == ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC) ||
(muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_9V_MUIC) ||
(muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC)
) {
pr_info("[%s:%s] attached_dev(%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
if (muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_9V_MUIC) {
muic_data->old_afctxd = muic_data->qc20_vbus;
sm5713_muic_voltage_control(SM5713_ENQC20_5V, SM5713_MUIC_QC20);
} else {
muic_data->old_afctxd = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCTXD);
sm5713_muic_voltage_control(SM5713_MUIC_HV_5V, SM5713_MUIC_AFC_TA);
}
} else {
pr_info("[%s:%s] skip: attached_dev(%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
return 0;
}
} else { /* AFC enable : 5V -> 9V(12V) */
if ((muic_data->attached_dev == ATTACHED_DEV_AFC_CHARGER_5V_MUIC) ||
(muic_data->attached_dev == ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC) ||
(muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_5V_MUIC) ||
(muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_PREPARE_MUIC)
) {
pr_info("[%s:%s] attached_dev(%d) , old_afctxd(0x%x)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev, muic_data->old_afctxd);
if (muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_5V_MUIC) {
muic_data->old_afctxd = muic_data->qc20_vbus;
sm5713_muic_voltage_control(SM5713_ENQC20_9V, SM5713_MUIC_QC20);
} else {
if (muic_data->old_afctxd == 0x00) {
sm5713_muic_voltage_control(SM5713_MUIC_HV_9V, SM5713_MUIC_AFC_TA);
} else {
sm5713_muic_voltage_control(muic_data->old_afctxd, SM5713_MUIC_AFC_TA);
}
}
} else {
pr_info("[%s:%s] skip: attached_dev(%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
return 0;
}
}
return ret;
}
int sm5713_muic_voltage_control(int afctxd, int qc20)
{
muic_data_t *muic_data = afc_init_data;
pr_info("[%s:%s] old_afctxd(0x%x), afctxd(0x%x), qc20(0x%x)\n", MUIC_DEV_NAME, __func__, muic_data->old_afctxd, afctxd, qc20);
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC;
muic_notifier_attach_attached_dev(ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC);
afc_prepare_state = true;
afc_prepare_afctxd = afctxd;
afc_prepare_qc20 = qc20;
cancel_delayed_work(&muic_data->afc_prepare_work);
schedule_delayed_work(&muic_data->afc_prepare_work, msecs_to_jiffies(100)); /* 100ms */
pr_info("[%s:%s] afc_prepare_work(afctxd=0x%x,qc20=%d) start\n", MUIC_DEV_NAME, __func__, afc_prepare_afctxd, afc_prepare_qc20);
return 0;
}
static void muic_afc_prepare_work(struct work_struct *work)
{
muic_data_t *muic_data = afc_init_data;
struct i2c_client *i2c = muic_data->i2c;
union power_supply_propval value;
int ret = 0, reg_val = 0;
int retry = 0;
int intmask2 = 0;
int irqafc = 0;
int afcstatus = 0, afc_dpreset = 0;
int vbus_voltage = 0;
int vbus_txd_voltage = 0;
int voltage_min = 0, voltage_max = 0;
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
for (retry = 0; retry < 10; retry++) {
//psy_do_property("sm5713-charger", get, POWER_SUPPLY_PROP_CURRENT_MAX, value);
if (value.intval <= 500) {
pr_info("[%s:%s]PREPARE Success(%d), retry(%d)\n", MUIC_DEV_NAME, __func__, value.intval, retry);
break;
} else if (value.intval == 1650) {
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC;
muic_notifier_attach_attached_dev(ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC);
pr_info("[%s:%s]PREPARE(RE) fail(%d), retry(%d)\n", MUIC_DEV_NAME, __func__, value.intval, retry);
} else {
pr_info("[%s:%s]PREPARE fail(%d), retry(%d)\n", MUIC_DEV_NAME, __func__, value.intval, retry);
}
msleep(50);
}
/* QC20 */
if (afc_prepare_qc20 == SM5713_MUIC_QC20) {
pr_info("[%s:%s]QC20: afctxd(0x%x)\n", MUIC_DEV_NAME, __func__, afc_prepare_afctxd);
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCCNTL);
reg_val = (ret & 0x3F) | (afc_prepare_afctxd<<6);
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCCNTL, reg_val);
pr_info("[%s:%s] read REG_AFCCNTL=0x%x , write REG_AFCCNTL=0x%x , qc20_vbus=%d\n",
MUIC_DEV_NAME, __func__, ret, reg_val, afc_prepare_afctxd);
muic_data->qc20_vbus = afc_prepare_afctxd;
if (muic_data->qc20_vbus == SM5713_ENQC20_5V) {
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
if (muic_data->fled_torch_enable == 1) {
muic_data->voltage_down_completed = 2;
}
} else if (muic_data->qc20_vbus == SM5713_ENQC20_9V) {
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
} else {
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
}
pr_info("[%s:%s] voltage_down_completed (%d)\n", MUIC_DEV_NAME, __func__, muic_data->voltage_down_completed);
} else { /* AFC TA */
pr_info("[%s:%s] AFC: afctxd(0x%x), old_afctxd(0x%x)\n", MUIC_DEV_NAME, __func__, afc_prepare_afctxd, muic_data->old_afctxd);
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCTXD, afc_prepare_afctxd);
/* AFC(INT2) mask */
intmask2 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_INTMASK2);
intmask2 = intmask2 | 0x3F;
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_INTMASK2, intmask2);
/* ENAFC set '1' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 1);
afc_dpreset = 0;
for (retry = 0; retry < 30 ; retry++) {
msleep(50);
irqafc = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_INT2);
if (irqafc & INT2_AFC_ACCEPTED_MASK) {
pr_info("[%s:%s] AFC_ACCEPTED Success(0x%x), retry(%d)\n",
MUIC_DEV_NAME, __func__, irqafc, retry);
break;
} else if (irqafc & INT2_AFC_ERROR_MASK) {
/* ENAFC set '0' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 0);
/* read AFC_STATUS */
afcstatus = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCSTATUS);
pr_info("[%s:%s] AFC_ERROR(0x%x), afcstatus(0x%x), retry(%d)\n",
MUIC_DEV_NAME, __func__, irqafc, afcstatus, retry);
/* DP_RESET '1' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_DP_RESET, 1);
afc_dpreset = 1;
} else if ( (irqafc & INT2_AFC_TA_ATTACHED_MASK) && (afc_dpreset == 1)) {
pr_info("[%s:%s] AFC_TA_ATTACHED(0x%x), retry(%d)\n",
MUIC_DEV_NAME, __func__, irqafc, retry);
break;
} else {
pr_info("[%s:%s] AFC_ACCEPTED Fail(0x%x), retry(%d)\n",
MUIC_DEV_NAME, __func__, irqafc, retry);
}
}
/* ENAFC set '0' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 0);
/* AFC(INT2) unmask */
intmask2 = intmask2 & 0xC0;
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_INTMASK2, intmask2);
vbus_voltage = muic_get_vbus_value();
vbus_txd_voltage = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCTXD);
pr_info("[%s:%s] AFC_TXD [0x%02x]\n", MUIC_DEV_NAME, __func__, vbus_txd_voltage);
vbus_txd_voltage = 5000 + ((vbus_txd_voltage&0xF0)>>4)*1000;
pr_info("[%s:%s] vbus_voltage:%d mV , AFC_TXD_VOLTAGE:%d mV\n",
MUIC_DEV_NAME, __func__, vbus_voltage, vbus_txd_voltage);
voltage_min = vbus_txd_voltage - 2000; /* - 2000mV */
voltage_max = vbus_txd_voltage + 1000; /* + 1000mV */
if ((voltage_min <= vbus_voltage) && (vbus_voltage <= voltage_max)) { /* AFC DONE */
if (vbus_txd_voltage == 12000) { /* 12V */
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] AFC 12V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
} else if (vbus_txd_voltage == 9000) { /* 9V */
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] AFC 9V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
} else { /* 5V */
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] AFC 5V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
if (muic_data->fled_torch_enable == 1) {
muic_data->voltage_down_completed = 2;
}
pr_info("[%s:%s] voltage_down_completed (%d)\n", MUIC_DEV_NAME, __func__, muic_data->voltage_down_completed);
}
} else {
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] AFC 5V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
}
}
muic_data->afc_active = 0;
afc_prepare_state = false;
afc_prepare_qc20 = 0;
return;
}
int muic_check_afc_state(int state)
{
pr_info("[%s:%s] state(%d)\n", MUIC_DEV_NAME, __func__, state);
return 1;
}
EXPORT_SYMBOL(muic_check_afc_state);
int muic_get_vbus_value(void)
{
muic_data_t *muic_data = afc_init_data;
struct i2c_client *i2c = muic_data->i2c;
int vbus_voltage = 0, voltage1 = 0, voltage2 = 0;
int irqvbus = 0;
int intmask2 = 0;
int retry = 0;
pr_info("[%s:%s] attached_dev(%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
intmask2 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_INTMASK2);
intmask2 = intmask2 | 0x04;
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_INTMASK2, intmask2);
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 1);
for (retry = 0; retry < 10 ; retry++) {
msleep(20);
irqvbus = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_INT2);
if (irqvbus & INT2_VBUS_UPDATE_MASK) {
pr_info("[%s:%s] VBUS update Success(%d), retry: %d)\n",
MUIC_DEV_NAME, __func__, irqvbus, retry);
break;
} else {
pr_info("[%s:%s] VBUS update Fail(%d), retry: %d)\n",
MUIC_DEV_NAME, __func__, irqvbus, retry);
}
}
intmask2 = intmask2 & 0xFB;
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_INTMASK2, intmask2);
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 0);
if (retry >= 5) {
pr_info("[%s:%s] VBUS update Failed(%d)\n", MUIC_DEV_NAME, __func__, retry);
return 0;
}
voltage1 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_VBUS_VOLTAGE1);
voltage2 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_VBUS_VOLTAGE2);
vbus_voltage = voltage1*1000 + (voltage2*3900)/1000;
pr_info("[%s:%s] voltage1=[0x%02x], voltage2=[0x%02x], vbus_voltage=%d mV\n",
MUIC_DEV_NAME, __func__, voltage1, voltage2, vbus_voltage);
return vbus_voltage;
}
EXPORT_SYMBOL(muic_get_vbus_value);
int sm5713_afc_ta_attach(muic_data_t *muic_data)
{
struct i2c_client *i2c = muic_data->i2c;
union power_supply_propval value;
int ret = 0, afctxd = 0;
int retry = 0;
if (!is_charger_ready) {
pr_info("[%s:%s] charger is not ready, return\n", MUIC_DEV_NAME, __func__);
return ret;
}
pr_info("[%s:%s] AFC_TA_ATTACHED\n", MUIC_DEV_NAME, __func__);
/* read VBUS VALID */
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_REVID1);
if (ret < 0)
printk(KERN_ERR "[%s:%s] err read VBUS %d\n", MUIC_DEV_NAME, __func__, ret);
pr_info("[%s:%s] VBUS[0x%02x]\n", MUIC_DEV_NAME, __func__, ret);
if ((ret&0x01) == 0x00) {
pr_info("[%s:%s] VBUS NOT VALID [0x%02x] just return\n", MUIC_DEV_NAME, __func__, ret);
return 0;
}
/* read clear : AFC_STATUS */
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCSTATUS);
if (ret < 0)
printk(KERN_ERR "[%s:%s] err read AFC_STATUS %d\n", MUIC_DEV_NAME, __func__, ret);
pr_info("[%s:%s] AFC_STATUS [0x%02x]\n", MUIC_DEV_NAME, __func__, ret);
#if defined(CONFIG_MUIC_SUPPORT_CCIC)
if (muic_data->afc_abnormal_disable == 1) {
pr_info("[%s:%s] CCIC Abnormal State\n", MUIC_DEV_NAME, __func__);
cancel_delayed_work(&muic_data->afc_retry_work);
pr_info("[%s:%s] afc_retry_work(ACCEPTED) cancel\n", MUIC_DEV_NAME, __func__);
return 0;
}
#endif
if ((muic_data->fled_torch_enable == 1) || (muic_data->fled_flash_enable == 1)) {
pr_info("[%s:%s] FLASH or Torch On, Skip AFC\n", MUIC_DEV_NAME, __func__);
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(ATTACHED_DEV_AFC_CHARGER_5V_MUIC);
return 0;
}
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
for (retry = 0; retry < 20; retry++) {
msleep(50);
//psy_do_property("sm5713-charger", get, POWER_SUPPLY_PROP_CURRENT_MAX, value);
if (value.intval <= 500) {
pr_info("[%s:%s]PREPARE Success(%d mA)\n", MUIC_DEV_NAME, __func__, value.intval);
break;
} else {
pr_info("[%s:%s]PREPARE fail(%d mA)\n", MUIC_DEV_NAME, __func__, value.intval);
}
}
cancel_delayed_work(&muic_data->afc_retry_work);
schedule_delayed_work(&muic_data->afc_retry_work, msecs_to_jiffies(5000)); /* 5sec */
pr_info("[%s:%s] afc_retry_work(ATTACH) start\n", MUIC_DEV_NAME, __func__);
/* voltage(9.0V) + current(1.65A) setting : 0x46 */
/* voltage(12.0V) + current(2.1A) setting : 0x79 */
afctxd = AFC_TXBYTE_9V_1_65A;
ret = sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCTXD, afctxd);
if (ret < 0)
printk(KERN_ERR "[%s:%s] err write AFC_TXD(%d)\n", MUIC_DEV_NAME, __func__, ret);
pr_info("[%s:%s] AFC_TXD [0x%02x]\n", MUIC_DEV_NAME, __func__, afctxd);
/* ENAFC set '1' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 1);
pr_info("[%s:%s] AFCCTRL_ENAFC 1\n", MUIC_DEV_NAME, __func__);
muic_data->afc_retry_count = 0;
muic_data->afc_vbus_retry_count = 0;
muic_data->voltage_down_completed = 0;
muic_data->afc_active = 1;
return 0;
}
int sm5713_afc_ta_accept(muic_data_t *muic_data)
{
struct i2c_client *i2c = muic_data->i2c;
int dev1 = 0;
pr_info("[%s:%s] AFC_ACCEPTED\n", MUIC_DEV_NAME, __func__);
/* ENAFC set '0' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 0);
cancel_delayed_work(&muic_data->afc_retry_work);
pr_info("[%s:%s] afc_retry_work(ACCEPTED) cancel\n", MUIC_DEV_NAME, __func__);
if ((muic_data->fled_torch_enable == 1) || (muic_data->fled_flash_enable == 1)) {
pr_info("[%s:%s] FLASH or Torch On, AFC_ACCEPTED VBUS(9V->5V)\n", MUIC_DEV_NAME, __func__);
muic_data->voltage_down_completed = 2;
muic_data->afc_active = 1;
muic_disable_afc(1); /* 9V(12V) -> 5V */
return 0;
}
dev1 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_DEVICETYPE1);
pr_info("[%s:%s] dev1 [0x%02x]\n", MUIC_DEV_NAME, __func__, dev1);
if (dev1 & DEV_TYPE1_AFC_TA) {
/* VBUS_READ */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 1);
pr_info("[%s:%s] VBUS READ start(AFC)\n", MUIC_DEV_NAME, __func__);
if (muic_data->attached_dev != ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC) {
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
}
muic_data->afc_vbus_retry_count = 0;
} else {
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] attached_dev(%d) \n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
muic_data->afc_active = 0;
}
return 0;
}
int sm5713_afc_vbus_update(muic_data_t *muic_data)
{
struct i2c_client *i2c = muic_data->i2c;
int vbus_txd_voltage = 0;
int vbus_voltage = 0, voltage1 = 0, voltage2 = 0;
int voltage_min = 0, voltage_max = 0;
int dev1 = 0;
int ret = 0, reg_val = 0;
pr_info("[%s:%s] AFC_VBUS_UPDATE \n", MUIC_DEV_NAME, __func__);
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 0);
if (muic_data->attached_dev == ATTACHED_DEV_NONE_MUIC) {
pr_info("[%s:%s] Device type is None\n", MUIC_DEV_NAME, __func__);
return 0;
}
voltage1 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_VBUS_VOLTAGE1);
voltage2 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_VBUS_VOLTAGE2);
vbus_voltage = voltage1*1000 + (voltage2*3900)/1000;
pr_info("[%s:%s] voltage1=[0x%02x], voltage2=[0x%02x], vbus_voltage=%d mV\n",
MUIC_DEV_NAME, __func__, voltage1, voltage2, vbus_voltage);
dev1 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_DEVICETYPE1);
pr_info("[%s:%s] DEVICE_TYPE1 [0x%02x]\n", MUIC_DEV_NAME, __func__, dev1);
if (dev1 & DEV_TYPE1_QC20_TA) { /* QC20_TA vbus update */
if (muic_data->qc20_vbus == SM5713_ENQC20_12V) {
voltage_min = 10000; /* - 10000mV */
voltage_max = 13000; /* + 13000mV */
} else if (muic_data->qc20_vbus == SM5713_ENQC20_9V) {
voltage_min = 7000; /* - 7000mV */
voltage_max = 10000; /* + 10000mV */
}
pr_info("[%s:%s] QC20 vbus_voltage:%d mV (%d)\n",
MUIC_DEV_NAME, __func__, vbus_voltage, muic_data->qc20_vbus);
if ((voltage_min <= vbus_voltage) && (vbus_voltage <= voltage_max)) { /* AFC DONE */
if (muic_data->qc20_vbus == SM5713_ENQC20_12V) {
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] QC20 12V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
} else if (muic_data->qc20_vbus == SM5713_ENQC20_9V) {
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] QC20 9V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
} else if (muic_data->qc20_vbus == SM5713_ENQC20_5V) {
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] QC20 5V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
if (muic_data->fled_torch_enable == 1) {
muic_data->voltage_down_completed = 2;
}
pr_info("[%s:%s] voltage_down_completed (%d)\n", MUIC_DEV_NAME, __func__, muic_data->voltage_down_completed);
}
} else { /* vbus fail */
if (muic_data->qc20_vbus == SM5713_ENQC20_12V) { /* 12V retry */
if (muic_data->afc_vbus_retry_count < 3) {
msleep(100);
muic_data->afc_vbus_retry_count++;
/* VBUS_READ */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 1);
pr_info("[%s:%s] [QC20-12V] VBUS READ retry = %d\n", MUIC_DEV_NAME, __func__,
muic_data->afc_vbus_retry_count);
} else {
msleep(100);
muic_data->qc20_vbus = SM5713_ENQC20_9V;
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCCNTL);
reg_val = (ret & 0x3F) | (SM5713_ENQC20_9V<<6); /* QC20 9V */
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCCNTL, reg_val);
pr_info("[%s:%s] read REG_AFCCNTL=0x%x , write REG_AFCCNTL=0x%x , qc20_vbus=%d\n",
MUIC_DEV_NAME, __func__, ret, reg_val, muic_data->qc20_vbus);
/* VBUS_READ */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 1);
pr_info("[%s:%s] VBUS READ start(QC20-9V)\n", MUIC_DEV_NAME, __func__);
muic_data->afc_vbus_retry_count = 0;
return 0;
}
} else {
if (muic_data->afc_vbus_retry_count < 3) {
msleep(100);
muic_data->afc_vbus_retry_count++;
/* VBUS_READ */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 1);
pr_info("[%s:%s] [QC20-9V] VBUS READ retry = %d\n", MUIC_DEV_NAME, __func__,
muic_data->afc_vbus_retry_count);
} else {
muic_data->qc20_vbus = SM5713_ENQC20_5V;
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCCNTL);
reg_val = (ret & 0x3F) | (SM5713_ENQC20_5V<<6); /* QC20 none */
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCCNTL, reg_val);
pr_info("[%s:%s] read REG_AFCCNTL=0x%x , write REG_AFCCNTL=0x%x , qc20_vbus=%d\n",
MUIC_DEV_NAME, __func__, ret, reg_val, muic_data->qc20_vbus);
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
}
}
}
} else { /* AFC vbus update */
vbus_txd_voltage = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCTXD);
pr_info("[%s:%s] AFC_TXD [0x%02x]\n", MUIC_DEV_NAME, __func__, vbus_txd_voltage);
vbus_txd_voltage = 5000 + ((vbus_txd_voltage&0xF0)>>4)*1000;
pr_info("[%s:%s] vbus_voltage:%d mV , AFC_TXD_VOLTAGE:%d mV \n",
MUIC_DEV_NAME, __func__, vbus_voltage, vbus_txd_voltage);
voltage_min = vbus_txd_voltage - 2000; /* - 2000mV */
voltage_max = vbus_txd_voltage + 1000; /* + 1000mV */
if ((voltage_min <= vbus_voltage) && (vbus_voltage <= voltage_max)) { /* AFC DONE */
muic_data->afc_vbus_retry_count = 0;
pr_info("[%s:%s] AFC done \n", MUIC_DEV_NAME, __func__);
if (vbus_txd_voltage == 12000) { /* 12V */
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] AFC 12V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
} else if (vbus_txd_voltage == 9000) { /* 9V */
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_9V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] AFC 9V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
} else { /* 5V */
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
pr_info("[%s:%s] AFC 5V (%d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
if (muic_data->fled_torch_enable == 1) {
muic_data->voltage_down_completed = 2;
}
pr_info("[%s:%s] voltage_down_completed (%d)\n", MUIC_DEV_NAME, __func__, muic_data->voltage_down_completed);
}
} else {
/* VBUS_READ */
if (muic_data->afc_vbus_retry_count < 3) {
msleep(100);
muic_data->afc_vbus_retry_count++;
/* VBUS_READ */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 1);
pr_info("[%s:%s] VBUS READ retry = %d\n", MUIC_DEV_NAME, __func__,
muic_data->afc_vbus_retry_count);
} else {
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
muic_data->afc_vbus_retry_count = 0;
}
}
} /* if (dev1 & DEV_TYPE1_QC20_TA){ // QC20_TA vbus update */
muic_data->afc_active = 0;
return 0;
}
int sm5713_afc_multi_byte(muic_data_t *muic_data)
{
struct i2c_client *i2c = muic_data->i2c;
int multi_byte[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int i = 0;
int ret = 0;
int voltage_find = 0;
pr_info("[%s:%s] AFC_MULTI_BYTE\n", MUIC_DEV_NAME, __func__);
/* ENAFC set '0' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 0);
/* read AFC_RXD1 ~ RXD15 */
voltage_find = 0;
for (i = 0 ; i < 15 ; i++) {
multi_byte[i] = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFC_RXD1 + i);
if (multi_byte[i] < 0) {
printk(KERN_ERR "[%s:%s] err read AFC_RXD%d %d\n",
MUIC_DEV_NAME, __func__, i+1, multi_byte[i]);
}
pr_info("[%s:%s] AFC_RXD%d [0x%02x]\n", MUIC_DEV_NAME, __func__, i+1, multi_byte[i]);
if (multi_byte[i] == 0x00) {
break;
}
if (i >= 1) { /* voltate find */
if (((multi_byte[i]&0xF0)>>4) >= ((multi_byte[voltage_find]&0xF0)>>4)) {
voltage_find = i;
}
}
}
pr_info("[%s:%s] AFC_RXD%d multi_byte[%d]=0x%02x\n", MUIC_DEV_NAME, __func__,
voltage_find+1, voltage_find, multi_byte[voltage_find]);
ret = sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCTXD, multi_byte[voltage_find]);
if (ret < 0)
printk(KERN_ERR "[%s:%s] err write AFC_TXD(%d)\n", MUIC_DEV_NAME, __func__, ret);
/* ENAFC set '1' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 1);
pr_info("[%s:%s] AFCCTRL_ENAFC 1\n", MUIC_DEV_NAME, __func__);
return 0;
}
int sm5713_afc_error(muic_data_t *muic_data)
{
struct i2c_client *i2c = muic_data->i2c;
int value = 0;
int dev1 = 0;
int ret = 0, reg_val = 0;
pr_info("[%s:%s] AFC_ERROR (%d)\n", MUIC_DEV_NAME, __func__, muic_data->afc_retry_count);
/* ENAFC set '0' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 0);
/* read AFC_STATUS */
value = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCSTATUS);
if (value < 0)
printk(KERN_ERR "[%s:%s] err read AFC_STATUS %d\n", MUIC_DEV_NAME, __func__, value);
pr_info("[%s:%s] REG_AFCSTATUS [0x%02x]\n", MUIC_DEV_NAME, __func__, value);
if (muic_data->afc_retry_count < 5) {
dev1 = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_DEVICETYPE1);
pr_info("[%s:%s] DEVICE_TYPE1 [0x%02x]\n", MUIC_DEV_NAME, __func__, dev1);
if ((dev1 & DEV_TYPE1_QC20_TA) && (muic_data->afc_retry_count >= 2)) { /* QC20_TA */
muic_data->qc20_vbus = SM5713_ENQC20_9V;
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCCNTL);
reg_val = (ret & 0x3F) | (SM5713_ENQC20_9V<<6); /* QC20 9V */
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCCNTL, reg_val);
pr_info("[%s:%s] read REG_AFCCNTL=0x%x , write REG_AFCCNTL=0x%x , qc20_vbus=%d\n",
MUIC_DEV_NAME, __func__, ret, reg_val, muic_data->qc20_vbus);
/* VBUS_READ */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_VBUS_READ, 1);
pr_info("[%s:%s] VBUS READ start(QC20-9V)\n", MUIC_DEV_NAME, __func__);
msleep(50); /* 50ms delay */
} else {
msleep(100); /* 100ms delay */
/* ENAFC set '1' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 1);
muic_data->afc_retry_count++;
pr_info("[%s:%s] re-start AFC (afc_retry_count=%d)\n", MUIC_DEV_NAME, __func__, muic_data->afc_retry_count);
}
} else {
pr_info("[%s:%s] ENAFC end = %d\n", MUIC_DEV_NAME, __func__, muic_data->afc_retry_count);
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_5V_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
}
return 0;
}
int sm5713_afc_sta_chg(muic_data_t *muic_data)
{
pr_info("[%s:%s] AFC_STA_CHG (attached_dev: %d)\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
return 0;
}
int sm5713_set_afc_ctrl_reg(muic_data_t *muic_data, int shift, bool on)
{
struct i2c_client *i2c = muic_data->i2c;
u8 reg_val = 0;
int ret = 0;
pr_info("[%s:%s] Register[%d], set [%d]\n", MUIC_DEV_NAME, __func__, shift, on);
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCCNTL);
if (ret < 0)
printk(KERN_ERR "[%s:%s](%d)\n", MUIC_DEV_NAME, __func__, ret);
if (on)
reg_val = ret | (0x1 << shift);
else
reg_val = ret & ~(0x1 << shift);
if (reg_val ^ ret) {
printk(KERN_DEBUG "[%s:%s] reg_val(0x%x) != AFC_CTRL reg(0x%x), update reg\n",
MUIC_DEV_NAME, __func__, reg_val, ret);
ret = sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCCNTL, reg_val);
if (ret < 0)
printk(KERN_ERR "[%s:%s] err write AFC_CTRL(%d)\n",
MUIC_DEV_NAME, __func__, ret);
} else {
printk(KERN_DEBUG "[%s:%s] (0x%x), just return\n",
MUIC_DEV_NAME, __func__, ret);
return 0;
}
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCCNTL);
if (ret < 0)
printk(KERN_ERR "[%s:%s] err read AFC_CTRL(%d)\n",
MUIC_DEV_NAME, __func__, ret);
else
printk(KERN_DEBUG "[%s:%s] AFC_CTRL reg after change(0x%x)\n",
MUIC_DEV_NAME, __func__, ret);
return ret;
}
void hv_muic_change_afc_voltage(int tx_data)
{
muic_data_t *muic_data = afc_init_data;
struct i2c_client *i2c = muic_data->i2c;
u8 val = 0;
union power_supply_propval value;
int retry = 0;
pr_info("[%s:%s] change afc voltage(%x)\n", MUIC_DEV_NAME, __func__, tx_data);
/* QC20 */
if ((muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_9V_MUIC) ||
(muic_data->attached_dev == ATTACHED_DEV_QC_CHARGER_5V_MUIC)) {
switch (tx_data) {
case SM5713_MUIC_HV_5V:
/* QC20 5V */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_QC20_9V, 0);
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_5V_MUIC;
break;
case SM5713_MUIC_HV_9V:
/* QC20 9V */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_QC20_9V, 1);
muic_data->attached_dev = ATTACHED_DEV_QC_CHARGER_9V_MUIC;
break;
default:
break;
}
} else { /* AFC */
val = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCTXD);
if (val == tx_data) {
pr_info("[%s:%s] same to current voltage 0x%x\n", MUIC_DEV_NAME, __func__, val);
return;
}
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
muic_data->attached_dev = ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC;
muic_notifier_attach_attached_dev(ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC);
for (retry = 0; retry < 10; retry++) {
msleep(50);
//psy_do_property("sm5713-charger", get, POWER_SUPPLY_PROP_CURRENT_MAX, value);
if (value.intval <= 500) {
pr_info("[%s:%s]PREPARE Success(%d)\n", MUIC_DEV_NAME, __func__, value.intval);
break;
} else {
pr_info("[%s:%s]PREPARE fail(%d)\n", MUIC_DEV_NAME, __func__, value.intval);
}
}
cancel_delayed_work(&muic_data->afc_retry_work);
schedule_delayed_work(&muic_data->afc_retry_work, msecs_to_jiffies(5000)); /* 5sec */
pr_info("[%s:%s] afc_retry_work(afc voltage) start\n", MUIC_DEV_NAME, __func__);
sm5713_i2c_write_byte(i2c, SM5713_MUIC_REG_AFCTXD, tx_data);
/* ENAFC set '1' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_ENAFC, 1);
}
}
int sm5713_muic_afc_set_voltage(int vol)
{
pr_info("[%s:%s] vol = %d V\n", MUIC_DEV_NAME, __func__, vol);
if (vol == 5) {
hv_muic_change_afc_voltage(SM5713_MUIC_HV_5V);
} else if (vol == 9) {
hv_muic_change_afc_voltage(SM5713_MUIC_HV_9V);
} else if (vol == 12) {
hv_muic_change_afc_voltage(SM5713_MUIC_HV_12V);
} else {
pr_warn("[%s:%s]invalid value\n", MUIC_DEV_NAME, __func__);
return -EINVAL;
}
return 0;
}
static void muic_afc_torch_work(struct work_struct *work)
{
muic_data_t *muic_data = afc_init_data;
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
muic_data->voltage_down_completed = 0;
muic_data->afc_active = 1;
muic_disable_afc(0); /* 5V -> 9V(12V) */
return;
}
static void muic_afc_retry_work(struct work_struct *work)
{
muic_data_t *muic_data = afc_init_data;
struct i2c_client *i2c = muic_data->i2c;
int ret = 0, vbus = 0;
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
ret = sm5713_i2c_read_byte(i2c, SM5713_MUIC_REG_AFCSTATUS);
pr_info("[%s:%s]: Read REG_AFCSTATUS = [0x%02x]\n", MUIC_DEV_NAME, __func__, ret);
pr_info("[%s:%s] attached_dev = %d\n", MUIC_DEV_NAME, __func__, muic_data->attached_dev);
if (muic_data->attached_dev == ATTACHED_DEV_AFC_CHARGER_PREPARE_MUIC) {
vbus = sm5713_i2c_read_byte(i2c, 0x3E);
if (!(vbus & 0x01)) {
pr_info("[%s:%s] VBUS is nothing\n", MUIC_DEV_NAME, __func__);
muic_data->attached_dev = ATTACHED_DEV_NONE_MUIC;
muic_notifier_attach_attached_dev(muic_data->attached_dev);
return;
}
pr_info("[%s:%s] [MUIC] device type is afc prepare - DP_RESET\n", MUIC_DEV_NAME, __func__);
/* DP_RESET '1' */
sm5713_set_afc_ctrl_reg(muic_data, AFCCTRL_DP_RESET, 1);
}
}
void sm5713_hv_muic_init_detect(muic_data_t *muic_data)
{
int afc_ta_attached = 0;
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
afc_ta_attached = sm5713_i2c_read_byte(muic_data->i2c, SM5713_MUIC_REG_AFCTASTATUS);
pr_info("[%s:%s] REG_AFCTASTATUS:[0x%02x]\n", MUIC_DEV_NAME, __func__, afc_ta_attached);
if (afc_ta_attached & 0x01) { /* AFC_TA_ATTACHED */
sm5713_afc_ta_attach(muic_data);
}
}
static void muic_focrced_detection_by_charger(struct work_struct *work)
{
muic_data_t *muic_data = afc_init_data;
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
sm5713_hv_muic_init_detect(muic_data);
return;
}
int sm5713_muic_charger_init(void)
{
int ret = -EINVAL;
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
if (!afc_init_data) {
pr_info("[%s:%s] MUIC AFC is not ready.\n", MUIC_DEV_NAME, __func__);
return ret;
}
if (is_charger_ready) {
pr_info("[%s:%s] charger is already ready.\n", MUIC_DEV_NAME, __func__);
return ret;
}
is_charger_ready = true;
if (afc_init_data->attached_dev == ATTACHED_DEV_TA_MUIC)
schedule_work(&muic_afc_init_work);
return 0;
}
void sm5713_hv_muic_initialize(muic_data_t *muic_data)
{
pr_info("[%s:%s]\n", MUIC_DEV_NAME, __func__);
afc_init_data = muic_data;
is_charger_ready = false;
afc_prepare_state = false;
/* To make AFC work properly on boot */
INIT_WORK(&muic_afc_init_work, muic_focrced_detection_by_charger);
INIT_DELAYED_WORK(&muic_data->afc_retry_work, muic_afc_retry_work);
INIT_DELAYED_WORK(&muic_data->afc_torch_work, muic_afc_torch_work);
INIT_DELAYED_WORK(&muic_data->afc_prepare_work, muic_afc_prepare_work);
return;
}