extcon-max77803.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628
  1. /*
  2. * max77803-muic.c - MUIC driver for the Maxim 77803
  3. *
  4. * Copyright (C) 2012 Samsung Electronics.
  5. * <sukdong.kim@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/i2c.h>
  24. #include <linux/gpio.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/err.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/workqueue.h>
  30. #include <linux/input.h>
  31. #include <linux/mfd/max77803.h>
  32. #include <linux/mfd/max77803-private.h>
  33. //#include <linux/host_notify.h>
  34. #include <linux/wakelock.h>
  35. #include <linux/switch.h>
  36. #ifdef CONFIG_USBHUB_USB3803
  37. #include <linux/usb3803.h>
  38. #endif
  39. #include <linux/delay.h>
  40. #include <linux/extcon.h>
  41. #define DEV_NAME "max77803-muic"
  42. /* for providing API */
  43. static struct max77803_muic_info *gInfo;
  44. /* For restore charger interrupt states */
  45. static u8 chg_int_state;
  46. /* MAX77803 MUIC CHG_TYP setting values */
  47. enum {
  48. /* No Valid voltage at VB (Vvb < Vvbdet) */
  49. CHGTYP_NO_VOLTAGE = 0x00,
  50. /* Unknown (D+/D- does not present a valid USB charger signature) */
  51. CHGTYP_USB = 0x01,
  52. /* Charging Downstream Port */
  53. CHGTYP_DOWNSTREAM_PORT = 0x02,
  54. /* Dedicated Charger (D+/D- shorted) */
  55. CHGTYP_DEDICATED_CHGR = 0x03,
  56. /* Special 500mA charger, max current 500mA */
  57. CHGTYP_500MA = 0x04,
  58. /* Special 1A charger, max current 1A */
  59. CHGTYP_1A = 0x05,
  60. /* Reserved for Future Use */
  61. CHGTYP_RFU = 0x06,
  62. /* Dead Battery Charging, max current 100mA */
  63. CHGTYP_DB_100MA = 0x07,
  64. CHGTYP_MAX,
  65. CHGTYP_INIT,
  66. CHGTYP_MIN = CHGTYP_NO_VOLTAGE
  67. };
  68. #define CHGTYP (CHGTYP_USB | CHGTYP_DOWNSTREAM_PORT |\
  69. CHGTYP_DEDICATED_CHGR | CHGTYP_500MA | CHGTYP_1A)
  70. enum {
  71. ADC_GND = 0x00,
  72. ADC_MHL = 0x01,
  73. ADC_INCOMPATIBLE1_CHG = 0x08, /* 0x01000 10.0K ohm*/
  74. ADC_VZW_USB_DOCK = 0x0e, /* 0x01110 28.7K ohm VZW Dock */
  75. ADC_SMARTDOCK = 0x10, /* 0x10000 40.2K ohm */
  76. ADC_INCOMPATIBLE2_CHG = 0x11, /* 0x10001 49.9K ohm */
  77. ADC_AUDIODOCK = 0x12, /* 0x10010 64.9K ohm */
  78. ADC_CEA936ATYPE1_CHG = 0x17, /* 0x10111 200K ohm */
  79. ADC_JIG_USB_OFF = 0x18, /* 0x11000 255K ohm */
  80. ADC_JIG_USB_ON = 0x19, /* 0x11001 301K ohm */
  81. ADC_DESKDOCK = 0x1a, /* 0x11010 365K ohm */
  82. ADC_CEA936ATYPE2_CHG = 0x1b, /* 0x11011 442K ohm */
  83. ADC_JIG_UART_OFF = 0x1c, /* 0x11100 523K ohm */
  84. ADC_JIG_UART_ON = 0x1d, /* 0x11101 619K ohm */
  85. ADC_CARDOCK = 0x1d, /* 0x11101 619K ohm */
  86. ADC_OPEN = 0x1f
  87. };
  88. struct max77803_muic_info {
  89. struct device *dev;
  90. struct max77803_dev *max77803;
  91. struct i2c_client *muic;
  92. struct max77803_muic_data *muic_data;
  93. struct extcon_dev *edev;
  94. int irq_adc;
  95. int irq_chgtype;
  96. int irq_vbvolt;
  97. int irq_adc1k;
  98. int mansw;
  99. struct wake_lock muic_wake_lock;
  100. enum cable_type_muic cable_type;
  101. struct delayed_work dock_work;
  102. struct delayed_work init_work;
  103. struct delayed_work usb_work;
  104. struct delayed_work dock_usb_work;
  105. struct delayed_work mhl_work;
  106. struct delayed_work usb_connection_work;
  107. struct mutex mutex;
  108. #if !defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  109. bool is_factory_start;
  110. #endif /* !CONFIG_MUIC_MAX77803_SUPORT_CAR_DOCK */
  111. bool is_usb_ready;
  112. bool is_mhl_ready;
  113. u8 adc;
  114. u8 chgtyp;
  115. u8 vbvolt;
  116. bool is_adc_open_prev;
  117. };
  118. static struct switch_dev switch_uart3 = {
  119. .name = "uart3", /* /sys/class/switch/uart3/state */
  120. };
  121. static int if_muic_info;
  122. static int switch_sel;
  123. static int if_pmic_rev;
  124. int is_cardock;
  125. EXPORT_SYMBOL(is_cardock);
  126. /* func : get_if_pmic_inifo
  127. * switch_sel value get from bootloader comand line
  128. * switch_sel data consist 8 bits (xxxxzzzz)
  129. * first 4bits(zzzz) mean path infomation.
  130. * next 4bits(xxxx) mean if pmic version info
  131. */
  132. static int get_if_pmic_inifo(char *str)
  133. {
  134. get_option(&str, &if_muic_info);
  135. switch_sel = if_muic_info & 0x0f;
  136. if_pmic_rev = (if_muic_info & 0xf0) >> 4;
  137. pr_info("%s %s: switch_sel: %x if_pmic_rev:%x\n",
  138. __FILE__, __func__, switch_sel, if_pmic_rev);
  139. return if_muic_info;
  140. }
  141. __setup("pmic_info=", get_if_pmic_inifo);
  142. int get_switch_sel(void)
  143. {
  144. return switch_sel;
  145. }
  146. static int max77803_muic_set_comp2_comn1_pass2
  147. (struct max77803_muic_info *info, int type, int path)
  148. {
  149. /* type 0 == usb, type 1 == uart */
  150. u8 cntl1_val, cntl1_msk;
  151. int ret = 0;
  152. int val;
  153. dev_info(info->dev, "func: %s type: %d path: %d\n",
  154. __func__, type, path);
  155. if (type == 0) {
  156. if (path == AP_USB_MODE) {
  157. info->muic_data->sw_path = AP_USB_MODE;
  158. val = MAX77803_MUIC_CTRL1_BIN_1_001;
  159. } else if (path == CP_USB_MODE) {
  160. info->muic_data->sw_path = CP_USB_MODE;
  161. val = MAX77803_MUIC_CTRL1_BIN_4_100;
  162. } else {
  163. dev_err(info->dev, "func: %s invalid usb path\n"
  164. , __func__);
  165. return -EINVAL;
  166. }
  167. } else if (type == 1) {
  168. if (path == UART_PATH_AP) {
  169. info->muic_data->uart_path = UART_PATH_AP;
  170. val = MAX77803_MUIC_CTRL1_BIN_3_011;
  171. } else if (path == UART_PATH_CP) {
  172. info->muic_data->uart_path = UART_PATH_CP;
  173. val = MAX77803_MUIC_CTRL1_BIN_5_101;
  174. } else {
  175. dev_err(info->dev, "func: %s invalid uart path\n"
  176. , __func__);
  177. return -EINVAL;
  178. }
  179. }
  180. else {
  181. dev_err(info->dev, "func: %s invalid path type(%d)\n"
  182. , __func__, type);
  183. return -EINVAL;
  184. }
  185. cntl1_val = (val << COMN1SW_SHIFT) | (val << COMP2SW_SHIFT);
  186. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK;
  187. max77803_update_reg(info->muic, MAX77803_MUIC_REG_CTRL1, cntl1_val,
  188. cntl1_msk);
  189. return ret;
  190. }
  191. static int max77803_muic_set_uart_path_pass2
  192. (struct max77803_muic_info *info, int path)
  193. {
  194. int ret = 0;
  195. ret = max77803_muic_set_comp2_comn1_pass2(info, 1/*uart*/, path);
  196. return ret;
  197. }
  198. static ssize_t max77803_muic_show_usb_state(struct device *dev,
  199. struct device_attribute *attr,
  200. char *buf)
  201. {
  202. struct max77803_muic_info *info = dev_get_drvdata(dev);
  203. dev_info(info->dev, "func:%s info->cable_type:%d\n",
  204. __func__, info->cable_type);
  205. switch (info->cable_type) {
  206. case CABLE_TYPE_USB_MUIC:
  207. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  208. case CABLE_TYPE_JIG_USB_ON_MUIC:
  209. return sprintf(buf, "USB_STATE_CONFIGURED\n");
  210. default:
  211. break;
  212. }
  213. return sprintf(buf, "USB_STATE_NOTCONFIGURED\n");
  214. }
  215. static ssize_t max77803_muic_show_device(struct device *dev,
  216. struct device_attribute *attr,
  217. char *buf)
  218. {
  219. struct max77803_muic_info *info = dev_get_drvdata(dev);
  220. dev_info(info->dev, "func:%s info->cable_type:%d\n",
  221. __func__, info->cable_type);
  222. switch (info->cable_type) {
  223. case CABLE_TYPE_NONE_MUIC:
  224. return sprintf(buf, "No cable\n");
  225. case CABLE_TYPE_USB_MUIC:
  226. return sprintf(buf, "USB\n");
  227. case CABLE_TYPE_OTG_MUIC:
  228. return sprintf(buf, "OTG\n");
  229. case CABLE_TYPE_TA_MUIC:
  230. return sprintf(buf, "TA\n");
  231. case CABLE_TYPE_DESKDOCK_MUIC:
  232. return sprintf(buf, "Desk Dock\n");
  233. case CABLE_TYPE_SMARTDOCK_MUIC:
  234. return sprintf(buf, "Smart Dock\n");
  235. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  236. return sprintf(buf, "Smart Dock with TA\n");
  237. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  238. return sprintf(buf, "Smart Dock with USB\n");
  239. case CABLE_TYPE_AUDIODOCK_MUIC:
  240. return sprintf(buf, "Audio Dock\n");
  241. case CABLE_TYPE_CARDOCK_MUIC:
  242. return sprintf(buf, "Car Dock\n");
  243. case CABLE_TYPE_JIG_UART_OFF_MUIC:
  244. return sprintf(buf, "JIG UART OFF\n");
  245. case CABLE_TYPE_JIG_UART_OFF_VB_MUIC:
  246. return sprintf(buf, "JIG UART OFF/VB\n");
  247. case CABLE_TYPE_JIG_UART_ON_MUIC:
  248. return sprintf(buf, "JIG UART ON\n");
  249. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  250. return sprintf(buf, "JIG USB OFF\n");
  251. case CABLE_TYPE_JIG_USB_ON_MUIC:
  252. return sprintf(buf, "JIG USB ON\n");
  253. case CABLE_TYPE_MHL_MUIC:
  254. return sprintf(buf, "mHL\n");
  255. case CABLE_TYPE_MHL_VB_MUIC:
  256. return sprintf(buf, "mHL charging\n");
  257. case CABLE_TYPE_INCOMPATIBLE_MUIC:
  258. return sprintf(buf, "Incompatible TA\n");
  259. default:
  260. break;
  261. }
  262. return sprintf(buf, "UNKNOWN\n");
  263. }
  264. static ssize_t max77803_muic_show_manualsw(struct device *dev,
  265. struct device_attribute *attr,
  266. char *buf)
  267. {
  268. struct max77803_muic_info *info = dev_get_drvdata(dev);
  269. dev_info(info->dev, "func:%s ap(0),cp(1),vps(2)sw_path:%d\n",
  270. __func__, info->muic_data->sw_path);/*For debuging*/
  271. switch (info->muic_data->sw_path) {
  272. case AP_USB_MODE:
  273. return sprintf(buf, "PDA\n");
  274. case CP_USB_MODE:
  275. return sprintf(buf, "MODEM\n");
  276. case AUDIO_MODE:
  277. return sprintf(buf, "Audio\n");
  278. default:
  279. break;
  280. }
  281. return sprintf(buf, "UNKNOWN\n");
  282. }
  283. static int max77803_muic_set_usb_path(struct max77803_muic_info *info,
  284. int path);
  285. static ssize_t max77803_muic_set_manualsw(struct device *dev,
  286. struct device_attribute *attr,
  287. const char *buf, size_t count)
  288. {
  289. struct max77803_muic_info *info = dev_get_drvdata(dev);
  290. dev_info(info->dev, "func:%s buf:%s,count:%d\n", __func__, buf, count);
  291. if (!strncasecmp(buf, "PDA", 3)) {
  292. info->muic_data->sw_path = AP_USB_MODE;
  293. dev_info(info->dev, "%s: AP_USB_MODE\n", __func__);
  294. } else if (!strncasecmp(buf, "MODEM", 5)) {
  295. info->muic_data->sw_path = CP_USB_MODE;
  296. dev_info(info->dev, "%s: CP_USB_MODE\n", __func__);
  297. max77803_muic_set_usb_path(info, CP_USB_MODE);
  298. } else
  299. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  300. return count;
  301. }
  302. static ssize_t max77803_muic_show_adc(struct device *dev,
  303. struct device_attribute *attr, char *buf)
  304. {
  305. struct max77803_muic_info *info = dev_get_drvdata(dev);
  306. int ret;
  307. u8 val;
  308. ret = max77803_read_reg(info->muic, MAX77803_MUIC_REG_STATUS1, &val);
  309. dev_info(info->dev, "func:%s ret:%d val:%x\n", __func__, ret, val);
  310. if (ret) {
  311. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  312. return sprintf(buf, "UNKNOWN\n");
  313. }
  314. return sprintf(buf, "%x\n", (val & STATUS1_ADC_MASK));
  315. }
  316. static ssize_t max77803_muic_show_audio_path(struct device *dev,
  317. struct device_attribute *attr,
  318. char *buf)
  319. {
  320. struct max77803_muic_info *info = dev_get_drvdata(dev);
  321. int ret;
  322. u8 val;
  323. ret = max77803_read_reg(info->muic, MAX77803_MUIC_REG_CTRL1, &val);
  324. dev_info(info->dev, "func:%s ret:%d val:%x\n", __func__, ret, val);
  325. if (ret) {
  326. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  327. return sprintf(buf, "UNKNOWN\n");
  328. }
  329. return sprintf(buf, "%x\n", val);
  330. }
  331. static ssize_t max77803_muic_set_audio_path(struct device *dev,
  332. struct device_attribute *attr,
  333. const char *buf, size_t count)
  334. {
  335. struct max77803_muic_info *info = dev_get_drvdata(dev);
  336. struct i2c_client *client = info->muic;
  337. u8 cntl1_val, cntl1_msk;
  338. u8 val;
  339. dev_info(info->dev, "func:%s buf:%s\n", __func__, buf);
  340. if (!strncmp(buf, "0", 1))
  341. val = MAX77803_MUIC_CTRL1_BIN_0_000;
  342. else if (!strncmp(buf, "1", 1))
  343. val = MAX77803_MUIC_CTRL1_BIN_2_010;
  344. else {
  345. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  346. return count;
  347. }
  348. cntl1_val = (val << COMN1SW_SHIFT) | (val << COMP2SW_SHIFT) |
  349. (0 << MICEN_SHIFT);
  350. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK | MICEN_MASK;
  351. max77803_update_reg(client, MAX77803_MUIC_REG_CTRL1, cntl1_val,
  352. cntl1_msk);
  353. dev_info(info->dev, "MUIC cntl1_val:%x, cntl1_msk:%x\n", cntl1_val,
  354. cntl1_msk);
  355. cntl1_val = MAX77803_MUIC_CTRL1_BIN_0_000;
  356. max77803_read_reg(client, MAX77803_MUIC_REG_CTRL1, &cntl1_val);
  357. dev_info(info->dev, "%s: CNTL1(0x%02x)\n", __func__, cntl1_val);
  358. return count;
  359. }
  360. static ssize_t max77803_muic_show_otg_test(struct device *dev,
  361. struct device_attribute *attr,
  362. char *buf)
  363. {
  364. struct max77803_muic_info *info = dev_get_drvdata(dev);
  365. int ret;
  366. u8 val;
  367. ret = max77803_read_reg(info->muic, MAX77803_MUIC_REG_CDETCTRL1, &val);
  368. dev_info(info->dev, "func:%s ret:%d val:%x buf%s\n",
  369. __func__, ret, val, buf);
  370. if (ret) {
  371. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  372. return sprintf(buf, "UNKNOWN\n");
  373. }
  374. val &= CHGDETEN_MASK;
  375. return sprintf(buf, "%x\n", val);
  376. }
  377. static ssize_t max77803_muic_set_otg_test(struct device *dev,
  378. struct device_attribute *attr,
  379. const char *buf, size_t count)
  380. {
  381. struct max77803_muic_info *info = dev_get_drvdata(dev);
  382. struct i2c_client *client = info->muic;
  383. u8 val;
  384. dev_info(info->dev, "func:%s buf:%s\n", __func__, buf);
  385. if (!strncmp(buf, "0", 1))
  386. val = 0;
  387. else if (!strncmp(buf, "1", 1))
  388. val = 1;
  389. else {
  390. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  391. return count;
  392. }
  393. max77803_update_reg(client, MAX77803_MUIC_REG_CDETCTRL1,
  394. val << CHGDETEN_SHIFT, CHGDETEN_MASK);
  395. val = 0;
  396. max77803_read_reg(client, MAX77803_MUIC_REG_CDETCTRL1, &val);
  397. dev_info(info->dev, "%s: CDETCTRL(0x%02x)\n", __func__, val);
  398. return count;
  399. }
  400. static void max77803_muic_set_adcdbset(struct max77803_muic_info *info,
  401. int value)
  402. {
  403. int ret;
  404. u8 val;
  405. dev_info(info->dev, "func:%s value:%x\n", __func__, value);
  406. if (value > 3) {
  407. dev_err(info->dev, "%s: invalid value(%x)\n", __func__, value);
  408. return;
  409. }
  410. if (!info->muic) {
  411. dev_err(info->dev, "%s: no muic i2c client\n", __func__);
  412. return;
  413. }
  414. val = value << CTRL3_ADCDBSET_SHIFT;
  415. dev_info(info->dev, "%s: ADCDBSET(0x%02x)\n", __func__, val);
  416. ret = max77803_update_reg(info->muic, MAX77803_MUIC_REG_CTRL3, val,
  417. CTRL3_ADCDBSET_MASK);
  418. if (ret < 0)
  419. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  420. }
  421. static ssize_t max77803_muic_show_adc_debounce_time(struct device *dev,
  422. struct device_attribute *attr, char *buf)
  423. {
  424. struct max77803_muic_info *info = dev_get_drvdata(dev);
  425. int ret;
  426. u8 val;
  427. dev_info(info->dev, "func:%s buf:%s\n", __func__, buf);
  428. if (!info->muic)
  429. return sprintf(buf, "No I2C client\n");
  430. ret = max77803_read_reg(info->muic, MAX77803_MUIC_REG_CTRL3, &val);
  431. if (ret) {
  432. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  433. return sprintf(buf, "UNKNOWN\n");
  434. }
  435. val &= CTRL3_ADCDBSET_MASK;
  436. val = val >> CTRL3_ADCDBSET_SHIFT;
  437. dev_info(info->dev, "func:%s val:%x\n", __func__, val);
  438. return sprintf(buf, "%x\n", val);
  439. }
  440. static ssize_t max77803_muic_set_adc_debounce_time(struct device *dev,
  441. struct device_attribute *attr,
  442. const char *buf, size_t count)
  443. {
  444. struct max77803_muic_info *info = dev_get_drvdata(dev);
  445. int value;
  446. sscanf(buf, "%d", &value);
  447. value = (value & 0x3);
  448. dev_info(info->dev, "%s: Do nothing\n", __func__);
  449. return count;
  450. }
  451. static ssize_t max77803_muic_set_uart_sel(struct device *dev,
  452. struct device_attribute *attr,
  453. const char *buf, size_t count)
  454. {
  455. struct max77803_muic_info *info = dev_get_drvdata(dev);
  456. dev_info(info->dev, "%s, buf : %s\n",__func__,buf);
  457. if (!strncasecmp(buf, "AP", 2)) {
  458. int ret = max77803_muic_set_uart_path_pass2
  459. (info, UART_PATH_AP);
  460. if (ret >= 0){
  461. info->muic_data->uart_path = UART_PATH_AP;
  462. dev_info(info->dev, "UART PATH(CP:0, AP:1):%d\n",
  463. info->muic_data->uart_path);
  464. }else
  465. dev_err(info->dev, "%s: Change(AP) fail!!", __func__);
  466. } else if (!strncasecmp(buf, "CP", 2)) {
  467. int ret = max77803_muic_set_uart_path_pass2
  468. (info, UART_PATH_CP);
  469. if (ret >= 0){
  470. info->muic_data->uart_path = UART_PATH_CP;
  471. dev_info(info->dev, "UART PATH(CP:0, AP:1):%d\n",
  472. info->muic_data->uart_path);
  473. }else
  474. dev_err(info->dev, "%s: Change(CP) fail!!", __func__);
  475. } else {
  476. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  477. }
  478. return count;
  479. }
  480. static ssize_t max77803_muic_show_uart_sel(struct device *dev,
  481. struct device_attribute *attr,
  482. char *buf)
  483. {
  484. struct max77803_muic_info *info = dev_get_drvdata(dev);
  485. dev_info(info->dev, "func:%s cp(0),ap(1)sw_path:%d\n",
  486. __func__, info->muic_data->uart_path);/*For debuging*/
  487. switch (info->muic_data->uart_path) {
  488. case UART_PATH_AP:
  489. return sprintf(buf, "AP\n");
  490. break;
  491. case UART_PATH_CP:
  492. return sprintf(buf, "CP\n");
  493. break;
  494. default:
  495. break;
  496. }
  497. return sprintf(buf, "UNKNOWN\n");
  498. }
  499. static ssize_t max77803_muic_show_charger_type(struct device *dev,
  500. struct device_attribute *attr,
  501. char *buf)
  502. {
  503. struct max77803_muic_info *info = dev_get_drvdata(dev);
  504. u8 adc, status;
  505. int ret;
  506. ret = max77803_read_reg(info->muic, MAX77803_MUIC_REG_STATUS1, &status);
  507. adc = status & STATUS1_ADC_MASK;
  508. /* SYSFS Node : chg_type
  509. * SYSFS State
  510. * 0 : Dedicated Charger
  511. * 1 : Non-Dedicated Charger
  512. * 2 : Cigar Jack
  513. */
  514. switch (adc){
  515. case ADC_MHL:
  516. case ADC_VZW_USB_DOCK:
  517. case ADC_SMARTDOCK:
  518. case ADC_AUDIODOCK:
  519. case ADC_DESKDOCK:
  520. case ADC_CARDOCK:
  521. case ADC_OPEN:
  522. dev_info(info->dev, "%s: Dedicated Charger State\n", __func__);
  523. return snprintf(buf, 4, "%d\n", 0);
  524. break;
  525. case ADC_CEA936ATYPE1_CHG:
  526. case ADC_INCOMPATIBLE1_CHG:
  527. case ADC_INCOMPATIBLE2_CHG:
  528. dev_info(info->dev, "%s: Undedicated Charger State\n", __func__);
  529. return snprintf(buf, 4, "%d\n", 1);
  530. break;
  531. case ADC_CEA936ATYPE2_CHG:
  532. dev_info(info->dev, "%s: Dedicated Charger State\n", __func__);
  533. return snprintf(buf, 4, "%d\n", 2);
  534. break;
  535. default:
  536. dev_info(info->dev, "%s: Undeclared State\n", __func__);
  537. break;
  538. }
  539. return snprintf(buf, 9, "%s\n", "UNKNOWN");
  540. }
  541. #if !defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  542. static ssize_t max77803_muic_show_apo_factory(struct device *dev,
  543. struct device_attribute *attr,
  544. char *buf)
  545. {
  546. struct max77803_muic_info *info = dev_get_drvdata(dev);
  547. const char *mode;
  548. /* true: Factory mode, false: not Factory mode */
  549. if (info->is_factory_start)
  550. mode = "FACTORY_MODE";
  551. else
  552. mode = "NOT_FACTORY_MODE";
  553. pr_info("%s:%s apo factory=%s\n", DEV_NAME, __func__, mode);
  554. return sprintf(buf, "%s\n", mode);
  555. }
  556. static ssize_t max77803_muic_set_apo_factory(struct device *dev,
  557. struct device_attribute *attr,
  558. const char *buf, size_t count)
  559. {
  560. struct max77803_muic_info *info = dev_get_drvdata(dev);
  561. const char *mode;
  562. pr_info("%s:%s buf:%s\n", DEV_NAME, __func__, buf);
  563. /* "FACTORY_START": factory mode */
  564. if (!strncmp(buf, "FACTORY_START", 13)) {
  565. info->is_factory_start = true;
  566. mode = "FACTORY_MODE";
  567. } else {
  568. pr_warn("%s:%s Wrong command\n", DEV_NAME, __func__);
  569. return count;
  570. }
  571. pr_info("%s:%s apo factory=%s\n", DEV_NAME, __func__, mode);
  572. return count;
  573. }
  574. #endif /* !CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK */
  575. #if !defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  576. static DEVICE_ATTR(apo_factory, 0664,
  577. max77803_muic_show_apo_factory,
  578. max77803_muic_set_apo_factory);
  579. #endif /* !CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK */
  580. static DEVICE_ATTR(chg_type, 0664, max77803_muic_show_charger_type, NULL);
  581. static DEVICE_ATTR(uart_sel, 0664, max77803_muic_show_uart_sel,
  582. max77803_muic_set_uart_sel);
  583. static DEVICE_ATTR(usb_state, S_IRUGO, max77803_muic_show_usb_state, NULL);
  584. static DEVICE_ATTR(device, S_IRUGO, max77803_muic_show_device, NULL);
  585. static DEVICE_ATTR(usb_sel, 0664,
  586. max77803_muic_show_manualsw, max77803_muic_set_manualsw);
  587. static DEVICE_ATTR(adc, S_IRUGO, max77803_muic_show_adc, NULL);
  588. static DEVICE_ATTR(audio_path, 0664,
  589. max77803_muic_show_audio_path, max77803_muic_set_audio_path);
  590. static DEVICE_ATTR(otg_test, 0664,
  591. max77803_muic_show_otg_test, max77803_muic_set_otg_test);
  592. static DEVICE_ATTR(adc_debounce_time, 0664,
  593. max77803_muic_show_adc_debounce_time,
  594. max77803_muic_set_adc_debounce_time);
  595. static struct attribute *max77803_muic_attributes[] = {
  596. &dev_attr_uart_sel.attr,
  597. &dev_attr_usb_state.attr,
  598. &dev_attr_device.attr,
  599. &dev_attr_usb_sel.attr,
  600. &dev_attr_adc.attr,
  601. &dev_attr_audio_path.attr,
  602. &dev_attr_otg_test.attr,
  603. &dev_attr_adc_debounce_time.attr,
  604. &dev_attr_chg_type.attr,
  605. #if !defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  606. &dev_attr_apo_factory.attr,
  607. #endif /* !CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK */
  608. NULL
  609. };
  610. static void max77803_muic_uart_uevent(int state)
  611. {
  612. if (switch_uart3.dev != NULL) {
  613. switch_set_state(&switch_uart3, state);
  614. dev_info(gInfo->dev, "%s: state:%d\n", __func__, state);
  615. }
  616. }
  617. static const struct attribute_group max77803_muic_group = {
  618. .attrs = max77803_muic_attributes,
  619. };
  620. static int max77803_muic_set_usb_path(struct max77803_muic_info *info, int path)
  621. {
  622. struct i2c_client *client = info->muic;
  623. struct max77803_muic_data *mdata = info->muic_data;
  624. int ret;
  625. int gpio_val;
  626. u8 cntl1_val, cntl1_msk;
  627. int val;
  628. dev_info(info->dev, "func:%s path:%d, cable_type:%d\n", __func__, path, info->cable_type);
  629. if (mdata->set_safeout) {
  630. ret = mdata->set_safeout(path);
  631. if (ret) {
  632. dev_err(info->dev, "%s: fail to set safout!\n",
  633. __func__);
  634. return ret;
  635. }
  636. }
  637. switch (path) {
  638. case AP_USB_MODE:
  639. dev_info(info->dev, "%s: AP_USB_MODE\n", __func__);
  640. gpio_val = 0;
  641. val = MAX77803_MUIC_CTRL1_BIN_1_001;
  642. cntl1_val = (val << COMN1SW_SHIFT) | (val << COMP2SW_SHIFT);
  643. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK;
  644. break;
  645. case AUDIO_MODE:
  646. dev_info(info->dev, "%s: AUDIO_MODE\n", __func__);
  647. gpio_val = 0;
  648. /* SL1, SR2 */
  649. cntl1_val = (MAX77803_MUIC_CTRL1_BIN_2_010 << COMN1SW_SHIFT)
  650. | (MAX77803_MUIC_CTRL1_BIN_2_010 << COMP2SW_SHIFT) |
  651. (0 << MICEN_SHIFT);
  652. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK | MICEN_MASK;
  653. break;
  654. case CP_USB_MODE:
  655. dev_info(info->dev, "%s: CP_USB_MODE\n", __func__);
  656. gpio_val = 1;
  657. val = MAX77803_MUIC_CTRL1_BIN_4_100;
  658. cntl1_val = (val << COMN1SW_SHIFT) | (val << COMP2SW_SHIFT);
  659. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK;
  660. break;
  661. case OPEN_USB_MODE:
  662. dev_info(info->dev, "%s: OPEN_USB_MODE\n", __func__);
  663. gpio_val = 0;
  664. val = MAX77803_MUIC_CTRL1_BIN_0_000;
  665. cntl1_val = (val << COMN1SW_SHIFT) | (val << COMP2SW_SHIFT);
  666. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK;
  667. break;
  668. default:
  669. dev_warn(info->dev, "%s: invalid path(%d)\n", __func__, path);
  670. return -EINVAL;
  671. }
  672. if (info->max77803->pmic_rev < MAX77803_REV_PASS2) {
  673. if (gpio_is_valid(info->muic_data->gpio_usb_sel))
  674. gpio_direction_output(mdata->gpio_usb_sel, gpio_val);
  675. }
  676. dev_info(info->dev, "%s: Set manual path\n", __func__);
  677. if (info->cable_type != CABLE_TYPE_CARDOCK_MUIC)
  678. max77803_update_reg(client, MAX77803_MUIC_REG_CTRL1, cntl1_val,
  679. cntl1_msk);
  680. max77803_update_reg(client, MAX77803_MUIC_REG_CTRL2,
  681. CTRL2_CPEn1_LOWPWD0,
  682. CTRL2_CPEn_MASK | CTRL2_LOWPWD_MASK);
  683. cntl1_val = MAX77803_MUIC_CTRL1_BIN_0_000;
  684. max77803_read_reg(client, MAX77803_MUIC_REG_CTRL1, &cntl1_val);
  685. dev_info(info->dev, "%s: CNTL1(0x%02x)\n", __func__, cntl1_val);
  686. cntl1_val = MAX77803_MUIC_CTRL1_BIN_0_000;
  687. max77803_read_reg(client, MAX77803_MUIC_REG_CTRL2, &cntl1_val);
  688. dev_info(info->dev, "%s: CNTL2(0x%02x)\n", __func__, cntl1_val);
  689. sysfs_notify(&switch_dev->kobj, NULL, "usb_sel");
  690. return 0;
  691. }
  692. int max77803_muic_get_charging_type(void)
  693. {
  694. if (gInfo)
  695. return gInfo->cable_type;
  696. else
  697. return CABLE_TYPE_NONE_MUIC;
  698. }
  699. void max77803_muic_send_event(int val)
  700. {
  701. char *envp[2];
  702. if (val == 0)
  703. envp[0] = "USB_CONNECTION=READY";
  704. else
  705. envp[0] = "USB_CONNECTION=DISCONNECTED";
  706. envp[1] = NULL;
  707. dev_info(gInfo->dev, "%s\n", __func__);
  708. kobject_uevent_env(&gInfo->dev->kobj, KOBJ_CHANGE, envp);
  709. }
  710. extern int system_rev;
  711. static int max77803_muic_set_charging_type(struct max77803_muic_info *info,
  712. bool force_disable)
  713. {
  714. struct max77803_muic_data *mdata = info->muic_data;
  715. int ret = 0;
  716. dev_info(info->dev, "func:%s force_disable:%d\n",
  717. __func__, force_disable);
  718. if (mdata->charger_cb) {
  719. if (force_disable) {
  720. ret = mdata->charger_cb(CABLE_TYPE_NONE_MUIC);
  721. } else {
  722. ret = mdata->charger_cb(info->cable_type);
  723. }
  724. }
  725. if (ret) {
  726. dev_err(info->dev, "%s: error from charger_cb(%d)\n", __func__,
  727. ret);
  728. return ret;
  729. }
  730. return 0;
  731. }
  732. static int max77803_muic_attach_usb_type(struct max77803_muic_info *info,
  733. int adc)
  734. {
  735. int ret, path;
  736. dev_info(info->dev, "func:%s adc:%x cable_type:%d\n",
  737. __func__, adc, info->cable_type);
  738. if (info->cable_type == CABLE_TYPE_MHL_MUIC
  739. || info->cable_type == CABLE_TYPE_MHL_VB_MUIC) {
  740. dev_warn(info->dev, "%s: mHL was attached!\n", __func__);
  741. return 0;
  742. }
  743. switch (adc) {
  744. case ADC_JIG_USB_OFF:
  745. if (info->cable_type == CABLE_TYPE_JIG_USB_OFF_MUIC) {
  746. dev_info(info->dev, "%s: duplicated(JIG USB OFF)\n",
  747. __func__);
  748. return 0;
  749. }
  750. dev_info(info->dev, "%s:JIG USB BOOTOFF\n", __func__);
  751. info->cable_type = CABLE_TYPE_JIG_USB_OFF_MUIC;
  752. path = AP_USB_MODE;
  753. break;
  754. case ADC_JIG_USB_ON:
  755. if (info->cable_type == CABLE_TYPE_JIG_USB_ON_MUIC) {
  756. dev_info(info->dev, "%s: duplicated(JIG USB ON)\n",
  757. __func__);
  758. return 0;
  759. }
  760. dev_info(info->dev, "%s:JIG USB BOOTON\n", __func__);
  761. info->cable_type = CABLE_TYPE_JIG_USB_ON_MUIC;
  762. path = AP_USB_MODE;
  763. break;
  764. case ADC_OPEN:
  765. if (info->cable_type == CABLE_TYPE_USB_MUIC) {
  766. dev_info(info->dev, "%s: duplicated(USB)\n", __func__);
  767. return 0;
  768. }
  769. dev_info(info->dev, "%s:USB\n", __func__);
  770. if (info->cable_type == CABLE_TYPE_CDP_MUIC)
  771. info->cable_type = CABLE_TYPE_CDP_MUIC;
  772. else
  773. info->cable_type = CABLE_TYPE_USB_MUIC;
  774. path = AP_USB_MODE;
  775. break;
  776. default:
  777. dev_info(info->dev, "%s: Unkown cable(0x%x)\n", __func__, adc);
  778. return 0;
  779. }
  780. ret = max77803_muic_set_charging_type(info, false);
  781. if (ret) {
  782. info->cable_type = CABLE_TYPE_NONE_MUIC;
  783. return ret;
  784. }
  785. max77803_muic_set_usb_path(info, path);
  786. if (path == AP_USB_MODE) {
  787. if (info->is_usb_ready)
  788. #ifdef CONFIG_USBHUB_USB3803
  789. /* setting usb hub in Diagnostic(hub) mode */
  790. usb3803_set_mode(USB_3803_MODE_HUB);
  791. #endif /* CONFIG_USBHUB_USB3803 */
  792. if (work_busy(&info->usb_connection_work.work)) {
  793. cancel_delayed_work(&info->usb_connection_work);
  794. pr_info("%s cancel_delayed_work \n",__func__);
  795. }
  796. max77803_muic_send_event (0); // USB Ready
  797. schedule_delayed_work(&info->usb_connection_work, msecs_to_jiffies(1));
  798. }
  799. return 0;
  800. }
  801. static int max77803_muic_attach_dock_type(struct max77803_muic_info *info,
  802. int adc, int chgtyp)
  803. {
  804. struct max77803_muic_data *mdata = info->muic_data;
  805. int path;
  806. dev_info(info->dev, "func:%s adc:%x, open(%d)\n",
  807. __func__, adc, info->is_adc_open_prev);
  808. /*Workaround for unstable adc*/
  809. if (info->is_adc_open_prev == false)
  810. return 0;
  811. switch (adc) {
  812. case ADC_DESKDOCK:
  813. /* Desk Dock */
  814. if (info->cable_type == CABLE_TYPE_DESKDOCK_MUIC) {
  815. dev_info(info->dev, "%s: duplicated(DeskDock)\n",
  816. __func__);
  817. return 0;
  818. }
  819. dev_info(info->dev, "%s:DeskDock\n", __func__);
  820. info->cable_type = CABLE_TYPE_DESKDOCK_MUIC;
  821. path = AUDIO_MODE;
  822. if (mdata->dock_cb)
  823. mdata->dock_cb(MAX77803_MUIC_DOCK_DESKDOCK);
  824. break;
  825. case ADC_CARDOCK:
  826. /* Car Dock */
  827. if (info->cable_type == CABLE_TYPE_CARDOCK_MUIC) {
  828. dev_info(info->dev, "%s: duplicated(CarDock)\n",
  829. __func__);
  830. return 0;
  831. }
  832. dev_info(info->dev, "%s:CarDock\n", __func__);
  833. info->cable_type = CABLE_TYPE_CARDOCK_MUIC;
  834. path = AUDIO_MODE;
  835. is_cardock = 1;
  836. if (mdata->dock_cb)
  837. mdata->dock_cb(MAX77803_MUIC_DOCK_CARDOCK);
  838. break;
  839. case ADC_AUDIODOCK:
  840. /* Audio Dock */
  841. if (info->cable_type == CABLE_TYPE_AUDIODOCK_MUIC) {
  842. dev_info(info->dev, "%s: duplicated(AudioDock)\n",
  843. __func__);
  844. return 0;
  845. }
  846. dev_info(info->dev, "%s:AudioDock\n", __func__);
  847. info->cable_type = CABLE_TYPE_AUDIODOCK_MUIC;
  848. if (info->is_usb_ready) {
  849. pr_info("%s:%s usb is ready, D+,D- line(AP_USB)\n",
  850. DEV_NAME, __func__);
  851. path = AP_USB_MODE;
  852. } else {
  853. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  854. DEV_NAME, __func__);
  855. path = OPEN_USB_MODE;
  856. }
  857. msleep(40);
  858. max77803_muic_set_charging_type(info, false);
  859. if (mdata->usb_cb && info->is_usb_ready)
  860. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  861. if (mdata->dock_cb)
  862. mdata->dock_cb(MAX77803_MUIC_DOCK_AUDIODOCK);
  863. break;
  864. case ADC_SMARTDOCK:
  865. /* Smart Dock */
  866. if (info->cable_type == CABLE_TYPE_SMARTDOCK_MUIC
  867. || info->cable_type == CABLE_TYPE_SMARTDOCK_TA_MUIC
  868. || info->cable_type == CABLE_TYPE_SMARTDOCK_USB_MUIC) {
  869. dev_info(info->dev, "%s: duplicated(SmartDock)\n",
  870. __func__);
  871. return 0;
  872. }
  873. dev_info(info->dev, "%s:SmartDock\n", __func__);
  874. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  875. info->cable_type = CABLE_TYPE_SMARTDOCK_TA_MUIC;
  876. } else if (chgtyp == CHGTYP_USB) {
  877. info->cable_type = CABLE_TYPE_SMARTDOCK_USB_MUIC;
  878. } else {
  879. info->cable_type = CABLE_TYPE_SMARTDOCK_MUIC;
  880. }
  881. if (info->is_usb_ready) {
  882. pr_info("%s:%s usb is ready, D+,D- line(AP_USB)\n",
  883. DEV_NAME, __func__);
  884. path = AP_USB_MODE;
  885. } else {
  886. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  887. DEV_NAME, __func__);
  888. path = OPEN_USB_MODE;
  889. }
  890. max77803_muic_set_charging_type(info, false);
  891. msleep(40);
  892. if (mdata->mhl_cb && info->is_mhl_ready)
  893. mdata->mhl_cb(MAX77803_MUIC_ATTACHED);
  894. if (mdata->dock_cb)
  895. mdata->dock_cb(MAX77803_MUIC_DOCK_SMARTDOCK);
  896. break;
  897. default:
  898. dev_info(info->dev, "%s: should not reach here(0x%x)\n",
  899. __func__, adc);
  900. return 0;
  901. }
  902. max77803_muic_set_usb_path(info, path);
  903. return 0;
  904. }
  905. static void max77803_muic_attach_mhl(struct max77803_muic_info *info, u8 chgtyp)
  906. {
  907. struct max77803_muic_data *mdata = info->muic_data;
  908. dev_info(info->dev, "func:%s chgtyp:%x\n", __func__, chgtyp);
  909. if (info->cable_type == CABLE_TYPE_USB_MUIC) {
  910. if (info->is_usb_ready)
  911. extcon_set_cable_state(info->edev,
  912. extcon_cable_name[EXTCON_USB],
  913. USB_CABLE_DETACHED);
  914. max77803_muic_set_charging_type(info, true);
  915. }
  916. info->cable_type = CABLE_TYPE_MHL_MUIC;
  917. if (mdata->mhl_cb && info->is_mhl_ready)
  918. mdata->mhl_cb(MAX77803_MUIC_ATTACHED);
  919. if (chgtyp == CHGTYP_USB) {
  920. info->cable_type = CABLE_TYPE_MHL_VB_MUIC;
  921. max77803_muic_set_charging_type(info, false);
  922. }
  923. }
  924. static void max77803_muic_handle_jig_uart(struct max77803_muic_info *info,
  925. u8 vbvolt)
  926. {
  927. // struct max77803_muic_data *mdata = info->muic_data;
  928. // enum cable_type_muic prev_ct = info->cable_type;
  929. // bool is_otgtest = false;
  930. u8 cntl1_val, cntl1_msk;
  931. u8 val = MAX77803_MUIC_CTRL1_BIN_3_011;
  932. dev_info(info->dev, "func:%s vbvolt:%x cable_type:%d\n",
  933. __func__, vbvolt, info->cable_type);
  934. dev_info(info->dev, "%s: JIG UART/BOOTOFF(0x%x)\n", __func__, vbvolt);
  935. val = MAX77803_MUIC_CTRL1_BIN_3_011;
  936. cntl1_val = (val << COMN1SW_SHIFT) | (val << COMP2SW_SHIFT);
  937. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK;
  938. max77803_update_reg(info->muic, MAX77803_MUIC_REG_CTRL1, cntl1_val,
  939. cntl1_msk);
  940. max77803_update_reg(info->muic, MAX77803_MUIC_REG_CTRL2,
  941. CTRL2_CPEn1_LOWPWD0,
  942. CTRL2_CPEn_MASK | CTRL2_LOWPWD_MASK);
  943. #if 0
  944. if (vbvolt & STATUS2_VBVOLT_MASK) {
  945. if (mdata->host_notify_cb) {
  946. int mode = mdata->host_notify_cb(1);
  947. if (mode == NOTIFY_TEST_MODE ||
  948. mode == NOTIFY_HOST_MODE) {
  949. is_otgtest = true;
  950. dev_info(info->dev, "%s: OTG TEST\n", __func__);
  951. }
  952. }
  953. info->cable_type = CABLE_TYPE_JIG_UART_OFF_VB_MUIC;
  954. max77803_muic_set_charging_type(info, is_otgtest);
  955. } else {
  956. info->cable_type = CABLE_TYPE_JIG_UART_OFF_MUIC;
  957. if (prev_ct == CABLE_TYPE_JIG_UART_OFF_VB_MUIC) {
  958. max77803_muic_set_charging_type(info, false);
  959. if (mdata->host_notify_cb)
  960. mdata->host_notify_cb(0);
  961. }
  962. }
  963. #endif
  964. }
  965. void max77803_otg_control(struct max77803_muic_info *info, int enable)
  966. {
  967. u8 int_mask, cdetctrl1, chg_cnfg_00;
  968. pr_info("%s: enable(%d)\n", __func__, enable);
  969. if (enable) {
  970. /* disable charger interrupt */
  971. max77803_read_reg(info->max77803->i2c,
  972. MAX77803_CHG_REG_CHG_INT_MASK, &int_mask);
  973. chg_int_state = int_mask;
  974. int_mask |= (1 << 4); /* disable chgin intr */
  975. int_mask |= (1 << 6); /* disable chg */
  976. int_mask &= ~(1 << 0); /* enable byp intr */
  977. max77803_write_reg(info->max77803->i2c,
  978. MAX77803_CHG_REG_CHG_INT_MASK, int_mask);
  979. /* disable charger detection */
  980. max77803_read_reg(info->max77803->muic,
  981. MAX77803_MUIC_REG_CDETCTRL1, &cdetctrl1);
  982. cdetctrl1 &= ~(1 << 0);
  983. max77803_write_reg(info->max77803->muic,
  984. MAX77803_MUIC_REG_CDETCTRL1, cdetctrl1);
  985. /* OTG on, boost on, DIS_MUIC_CTRL=1 */
  986. max77803_read_reg(info->max77803->i2c,
  987. MAX77803_CHG_REG_CHG_CNFG_00, &chg_cnfg_00);
  988. chg_cnfg_00 &= ~(CHG_CNFG_00_OTG_MASK
  989. | CHG_CNFG_00_BOOST_MASK
  990. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
  991. chg_cnfg_00 |= (CHG_CNFG_00_OTG_MASK
  992. | CHG_CNFG_00_BOOST_MASK
  993. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
  994. max77803_write_reg(info->max77803->i2c,
  995. MAX77803_CHG_REG_CHG_CNFG_00, chg_cnfg_00);
  996. /* Update CHG_CNFG_11 to 0x50(5V) */
  997. max77803_write_reg(info->max77803->i2c,
  998. MAX77803_CHG_REG_CHG_CNFG_11, 0x50);
  999. } else {
  1000. /* OTG off, boost off, (buck on),
  1001. DIS_MUIC_CTRL = 0 unless CHG_ENA = 1 */
  1002. max77803_read_reg(info->max77803->i2c,
  1003. MAX77803_CHG_REG_CHG_CNFG_00, &chg_cnfg_00);
  1004. chg_cnfg_00 &= ~(CHG_CNFG_00_OTG_MASK
  1005. | CHG_CNFG_00_BOOST_MASK
  1006. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
  1007. chg_cnfg_00 |= CHG_CNFG_00_BUCK_MASK;
  1008. max77803_write_reg(info->max77803->i2c,
  1009. MAX77803_CHG_REG_CHG_CNFG_00, chg_cnfg_00);
  1010. /* Update CHG_CNFG_11 to 0x00(3V) */
  1011. max77803_write_reg(info->max77803->i2c,
  1012. MAX77803_CHG_REG_CHG_CNFG_11, 0x00);
  1013. mdelay(50);
  1014. /* [MAX77804] Workaround to get rid of reading dummy(0x00) */
  1015. /* disable charger detection again */
  1016. max77803_read_reg(info->max77803->muic,
  1017. MAX77803_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1018. cdetctrl1 &= ~(1 << 0);
  1019. max77803_write_reg(info->max77803->muic,
  1020. MAX77803_MUIC_REG_CDETCTRL1, cdetctrl1);
  1021. mdelay(10);
  1022. /* enable charger detection */
  1023. max77803_read_reg(info->max77803->muic,
  1024. MAX77803_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1025. cdetctrl1 |= (1 << 0);
  1026. max77803_write_reg(info->max77803->muic,
  1027. MAX77803_MUIC_REG_CDETCTRL1, cdetctrl1);
  1028. /* enable charger interrupt */
  1029. max77803_write_reg(info->max77803->i2c,
  1030. MAX77803_CHG_REG_CHG_INT_MASK, chg_int_state);
  1031. max77803_read_reg(info->max77803->i2c,
  1032. MAX77803_CHG_REG_CHG_INT_MASK, &int_mask);
  1033. }
  1034. pr_info("%s: INT_MASK(0x%x), CDETCTRL1(0x%x), CHG_CNFG_00(0x%x)\n",
  1035. __func__, int_mask, cdetctrl1, chg_cnfg_00);
  1036. }
  1037. void max77803_powered_otg_control(struct max77803_muic_info *info, int enable)
  1038. {
  1039. pr_info("%s: enable(%d)\n", __func__, enable);
  1040. if (enable) {
  1041. /* OTG on, boost on */
  1042. max77803_write_reg(info->max77803->i2c,
  1043. MAX77803_CHG_REG_CHG_CNFG_00, 0x05);
  1044. max77803_write_reg(info->max77803->i2c,
  1045. MAX77803_CHG_REG_CHG_CNFG_02, 0x0E);
  1046. /* Update CHG_CNFG_11 to 0x50(5V) */
  1047. max77803_write_reg(info->max77803->i2c,
  1048. MAX77803_CHG_REG_CHG_CNFG_11, 0x50);
  1049. } else {
  1050. /* OTG off, boost off, (buck on) */
  1051. max77803_write_reg(info->max77803->i2c,
  1052. MAX77803_CHG_REG_CHG_CNFG_00, 0x04);
  1053. /* Update CHG_CNFG_11 to 0x00(3V) */
  1054. max77803_write_reg(info->max77803->i2c,
  1055. MAX77803_CHG_REG_CHG_CNFG_11, 0x00);
  1056. }
  1057. }
  1058. /* use in mach for otg */
  1059. int muic_otg_control(int enable)
  1060. {
  1061. pr_debug("%s: enable(%d)\n", __func__, enable);
  1062. max77803_otg_control(gInfo, enable);
  1063. return 0;
  1064. }
  1065. /* use in mach for powered-otg */
  1066. void powered_otg_control(int enable)
  1067. {
  1068. pr_debug("%s: enable(%d)\n", __func__, enable);
  1069. max77803_powered_otg_control(gInfo, enable);
  1070. }
  1071. static void max77803_muic_set_cddelay(struct max77803_muic_info *info)
  1072. {
  1073. u8 cdetctrl1;
  1074. int ret;
  1075. ret = max77803_read_reg(info->max77803->muic,
  1076. MAX77803_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1077. pr_info("%s:%s read CDETCTRL1=0x%x, ret=%d\n", DEV_NAME, __func__,
  1078. cdetctrl1, ret);
  1079. if ((cdetctrl1 & 0x10) == 0x10) {
  1080. pr_info("%s:%s CDDelay already setted, return\n", DEV_NAME,
  1081. __func__);
  1082. return;
  1083. }
  1084. cdetctrl1 |= 0x10;
  1085. ret = max77803_write_reg(info->max77803->muic,
  1086. MAX77803_MUIC_REG_CDETCTRL1, cdetctrl1);
  1087. pr_info("%s:%s write CDETCTRL1=0x%x, ret=%d\n", DEV_NAME,
  1088. __func__, cdetctrl1, ret);
  1089. }
  1090. static void max77803_muic_clear_cddelay(struct max77803_muic_info *info)
  1091. {
  1092. u8 cdetctrl1;
  1093. int ret;
  1094. ret = max77803_read_reg(info->max77803->muic,
  1095. MAX77803_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1096. pr_info("%s:%s read CDETCTRL1=0x%x, ret=%d\n", DEV_NAME, __func__,
  1097. cdetctrl1, ret);
  1098. if ((cdetctrl1 & 0x10) == 0x0) {
  1099. pr_info("%s:%s CDDelay already cleared, return\n", DEV_NAME,
  1100. __func__);
  1101. return;
  1102. }
  1103. cdetctrl1 &= ~(0x10);
  1104. ret = max77803_write_reg(info->max77803->muic,
  1105. MAX77803_MUIC_REG_CDETCTRL1, cdetctrl1);
  1106. pr_info("%s:%s write CDETCTRL1=0x%x, ret=%d\n", DEV_NAME,
  1107. __func__, cdetctrl1, ret);
  1108. }
  1109. static void max77803_muic_detach_smart_dock(struct max77803_muic_info *info)
  1110. {
  1111. struct max77803_muic_data *mdata = info->muic_data;
  1112. enum cable_type_muic tmp_cable_type = info->cable_type;
  1113. pr_info("%s:%s\n", DEV_NAME, __func__);
  1114. if (info->cable_type != CABLE_TYPE_SMARTDOCK_MUIC &&
  1115. info->cable_type != CABLE_TYPE_SMARTDOCK_TA_MUIC &&
  1116. info->cable_type != CABLE_TYPE_SMARTDOCK_USB_MUIC) {
  1117. pr_info("%s:%s cable_type is not SMARTDOCK\n", DEV_NAME,
  1118. __func__);
  1119. return;
  1120. }
  1121. if (mdata->dock_cb)
  1122. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1123. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1124. max77803_muic_set_charging_type(info, false);
  1125. #ifdef CONFIG_EXTCON
  1126. if (info->edev && info->is_mhl_ready)
  1127. extcon_set_cable_state(info->edev, "MHL", false);
  1128. #else
  1129. if (mdata->mhl_cb && info->is_mhl_ready)
  1130. mdata->mhl_cb(MAX77803_MUIC_DETACHED);
  1131. #endif
  1132. switch (tmp_cable_type) {
  1133. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1134. pr_info("%s:%s SMARTDOCK+TA\n", DEV_NAME, __func__);
  1135. if (mdata->usb_cb && info->is_usb_ready)
  1136. mdata->usb_cb(USB_POWERED_HOST_DETACHED);
  1137. break;
  1138. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1139. pr_info("%s:%s SMARTDOCK+USB\n", DEV_NAME, __func__);
  1140. if (info->is_usb_ready)
  1141. extcon_set_cable_state(info->edev,
  1142. extcon_cable_name[EXTCON_USB],
  1143. USB_CABLE_DETACHED);
  1144. break;
  1145. case CABLE_TYPE_SMARTDOCK_MUIC:
  1146. /* clear CDDelay 500ms */
  1147. max77803_muic_clear_cddelay(info);
  1148. pr_info("%s:%s SMARTDOCK\n", DEV_NAME, __func__);
  1149. break;
  1150. default:
  1151. pr_warn("%s:%s should not reach here!\n", DEV_NAME,
  1152. __func__);
  1153. return;
  1154. break;
  1155. }
  1156. }
  1157. static void max77803_muic_attach_smart_dock(struct max77803_muic_info *info,
  1158. u8 adc, u8 vbvolt, u8 chgtyp)
  1159. {
  1160. struct max77803_muic_data *mdata = info->muic_data;
  1161. switch (info->cable_type) {
  1162. case CABLE_TYPE_SMARTDOCK_MUIC:
  1163. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1164. /* clear CDDelay 500ms */
  1165. max77803_muic_clear_cddelay(info);
  1166. pr_info("%s:%s SMART_DOCK+TA=OTG Enable\n", DEV_NAME,
  1167. __func__);
  1168. if (mdata->usb_cb && info->is_usb_ready)
  1169. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1170. info->cable_type = CABLE_TYPE_SMARTDOCK_TA_MUIC;
  1171. } else if (chgtyp == CHGTYP_USB) {
  1172. /* clear CDDelay 500ms */
  1173. max77803_muic_clear_cddelay(info);
  1174. pr_info("%s:%s SMART_DOCK+USB=USB Enable\n", DEV_NAME,
  1175. __func__);
  1176. if (info->is_usb_ready)
  1177. extcon_set_cable_state(info->edev,
  1178. extcon_cable_name[EXTCON_USB],
  1179. USB_CABLE_ATTACHED);
  1180. info->cable_type = CABLE_TYPE_SMARTDOCK_USB_MUIC;
  1181. } else
  1182. pr_info("%s:%s SMART_DOCK + [%d] = ?\n", DEV_NAME,
  1183. __func__, chgtyp);
  1184. break;
  1185. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1186. if (chgtyp == CHGTYP_DEDICATED_CHGR)
  1187. pr_info("%s:%s Duplicated(SMARTDOCK+TA)\n", DEV_NAME,
  1188. __func__);
  1189. else if (vbvolt)
  1190. pr_info("%s:%s SMART_DOCK + TA -> chgtyp:%x\n",
  1191. DEV_NAME, __func__, chgtyp);
  1192. else
  1193. max77803_muic_detach_smart_dock(info);
  1194. break;
  1195. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1196. if (chgtyp == CHGTYP_USB)
  1197. pr_info("%s:%s Duplicated(SMARTDOCK+USB)\n", DEV_NAME,
  1198. __func__);
  1199. else if (vbvolt)
  1200. pr_info("%s:%s SMART_DOCK + USB -> chgtyp:%x\n",
  1201. DEV_NAME, __func__, chgtyp);
  1202. else
  1203. max77803_muic_detach_smart_dock(info);
  1204. break;
  1205. default:
  1206. if (vbvolt) {
  1207. pr_info("%s:%s SMART_DOCK+vbvolt=chgdetrun\n",
  1208. DEV_NAME, __func__);
  1209. if (chgtyp == 0) {
  1210. pr_info("%s:%s SMART_DOCK + [%d] = ?? end\n", DEV_NAME,
  1211. __func__, chgtyp);
  1212. return;
  1213. }
  1214. max77803_muic_attach_dock_type(info, adc, chgtyp);
  1215. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1216. /* clear CDDelay 500ms */
  1217. max77803_muic_clear_cddelay(info);
  1218. pr_info("%s:%s SMART_DOCK+TA=OTG Enable\n", DEV_NAME,
  1219. __func__);
  1220. if (mdata->usb_cb && info->is_usb_ready)
  1221. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1222. } else if (chgtyp == CHGTYP_USB) {
  1223. /* clear CDDelay 500ms */
  1224. max77803_muic_clear_cddelay(info);
  1225. pr_info("%s:%s SMART_DOCK+USB=USB Enable\n", DEV_NAME,
  1226. __func__);
  1227. if (info->is_usb_ready)
  1228. extcon_set_cable_state(info->edev,
  1229. extcon_cable_name[EXTCON_USB],
  1230. USB_CABLE_ATTACHED);
  1231. }
  1232. } else {
  1233. /* set CDDelay 500ms */
  1234. max77803_muic_set_cddelay(info);
  1235. dev_warn(info->dev, "no vbus in SAMRTDOCK\n");
  1236. }
  1237. break;
  1238. }
  1239. }
  1240. static int max77803_muic_handle_attach(struct max77803_muic_info *info,
  1241. u8 status1, u8 status2, int irq)
  1242. {
  1243. struct max77803_muic_data *mdata = info->muic_data;
  1244. u8 adc, vbvolt, chgtyp, chgdetrun, adc1k;
  1245. int ret = 0;
  1246. adc = status1 & STATUS1_ADC_MASK;
  1247. adc1k = status1 & STATUS1_ADC1K_MASK;
  1248. chgtyp = status2 & STATUS2_CHGTYP_MASK;
  1249. vbvolt = status2 & STATUS2_VBVOLT_MASK;
  1250. chgdetrun = status2 & STATUS2_CHGDETRUN_MASK;
  1251. dev_info(info->dev, "func:%s st1:%x st2:%x cable_type:%d\n",
  1252. __func__, status1, status2, info->cable_type);
  1253. switch (info->cable_type) {
  1254. case CABLE_TYPE_JIG_UART_OFF_MUIC:
  1255. case CABLE_TYPE_JIG_UART_OFF_VB_MUIC:
  1256. /* Workaround for Factory mode.
  1257. * Abandon adc interrupt of approximately +-100K range
  1258. * if previous cable status was JIG UART BOOT OFF.
  1259. */
  1260. if (adc == (ADC_JIG_UART_OFF + 1) ||
  1261. adc == (ADC_JIG_UART_OFF - 1)) {
  1262. /* Workaround for factory mode in MUIC PASS2
  1263. * In uart path cp, adc is unstable state
  1264. * MUIC PASS2 turn to AP_UART mode automatically
  1265. * So, in this state set correct path manually.
  1266. * !! NEEDED ONLY IF PMIC PASS2 !!
  1267. */
  1268. max77803_muic_handle_jig_uart(info, vbvolt);
  1269. #if !defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  1270. if (info->is_factory_start &&
  1271. (adc == ADC_JIG_UART_ON)) {
  1272. pr_info("%s:%s factory start, keep attach\n",
  1273. DEV_NAME, __func__);
  1274. break;
  1275. }
  1276. #endif /* !CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK */
  1277. dev_warn(info->dev, "%s: abandon ADC\n", __func__);
  1278. return 0;
  1279. }
  1280. if (adc != ADC_JIG_UART_OFF) {
  1281. dev_warn(info->dev, "%s: assume jig uart off detach\n",
  1282. __func__);
  1283. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1284. }
  1285. break;
  1286. case CABLE_TYPE_DESKDOCK_MUIC:
  1287. if (adc != ADC_DESKDOCK) {
  1288. dev_warn(info->dev, "%s: assume deskdock detach\n", __func__);
  1289. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1290. max77803_muic_set_charging_type(info, false);
  1291. info->is_adc_open_prev = false;
  1292. if (mdata->dock_cb)
  1293. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1294. }
  1295. break;
  1296. case CABLE_TYPE_CARDOCK_MUIC:
  1297. if (adc != ADC_CARDOCK) {
  1298. dev_warn(info->dev, "%s: assume cardock detach\n", __func__);
  1299. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1300. max77803_muic_set_charging_type(info, false);
  1301. info->is_adc_open_prev = false;
  1302. is_cardock = 0;
  1303. if (mdata->dock_cb)
  1304. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1305. }
  1306. break;
  1307. #if !defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  1308. case CABLE_TYPE_JIG_UART_ON_MUIC:
  1309. if ((adc != ADC_JIG_UART_ON) &&
  1310. info->is_factory_start) {
  1311. pr_warn("%s:%s assume jig uart on detach\n",
  1312. DEV_NAME, __func__);
  1313. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1314. if (mdata->dock_cb)
  1315. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1316. }
  1317. break;
  1318. #endif /* !CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK */
  1319. case CABLE_TYPE_SMARTDOCK_MUIC:
  1320. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1321. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1322. if (adc != ADC_SMARTDOCK) {
  1323. dev_warn(info->dev, "%s: assume smartdock detach\n",
  1324. __func__);
  1325. max77803_muic_detach_smart_dock(info);
  1326. info->is_adc_open_prev = false;
  1327. }
  1328. break;
  1329. case CABLE_TYPE_AUDIODOCK_MUIC:
  1330. if ((adc != ADC_AUDIODOCK) || (!vbvolt)) {
  1331. dev_warn(info->dev, "%s: assume audiodock detach\n",
  1332. __func__);
  1333. dev_info(info->dev, "%s: AUDIODOCK\n", __func__);
  1334. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1335. if (mdata->dock_cb)
  1336. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1337. if (mdata->usb_cb && info->is_usb_ready)
  1338. mdata->usb_cb(USB_POWERED_HOST_DETACHED);
  1339. ret = max77803_muic_set_charging_type(info, false);
  1340. max77803_muic_set_charging_type(info, false);
  1341. }
  1342. break;
  1343. case CABLE_TYPE_MHL_MUIC:
  1344. case CABLE_TYPE_MHL_VB_MUIC:
  1345. if (!adc1k) {
  1346. dev_warn(info->dev, "%s: assume mhl detach\n", __func__);
  1347. dev_info(info->dev, "%s: MHL\n", __func__);
  1348. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1349. max77803_muic_set_charging_type(info, false);
  1350. if (mdata->mhl_cb && info->is_mhl_ready)
  1351. mdata->mhl_cb(MAX77803_MUIC_DETACHED);
  1352. }
  1353. break;
  1354. default:
  1355. break;
  1356. }
  1357. /* 1Kohm ID regiter detection (mHL)
  1358. * Old MUIC : ADC value:0x00 or 0x01, ADCLow:1
  1359. * New MUIC : ADC value is not set(Open), ADCLow:1, ADCError:1
  1360. */
  1361. if (adc1k) {
  1362. if (irq == info->irq_adc
  1363. || irq == info->irq_chgtype
  1364. || irq == info->irq_vbvolt) {
  1365. dev_warn(info->dev,
  1366. "%s: Ignore irq:%d at MHL detection\n",
  1367. __func__, irq);
  1368. if (vbvolt) {
  1369. dev_info(info->dev, "%s: call charger_cb(%d)"
  1370. , __func__, vbvolt);
  1371. max77803_muic_set_charging_type(info, false);
  1372. } else {
  1373. dev_info(info->dev, "%s: call charger_cb(%d)"
  1374. , __func__, vbvolt);
  1375. max77803_muic_set_charging_type(info, true);
  1376. }
  1377. return 0;
  1378. }
  1379. max77803_muic_attach_mhl(info, chgtyp);
  1380. return 0;
  1381. }
  1382. switch (adc) {
  1383. case ADC_GND:
  1384. if (chgtyp == CHGTYP_NO_VOLTAGE) {
  1385. if (info->cable_type == CABLE_TYPE_OTG_MUIC) {
  1386. dev_info(info->dev,
  1387. "%s: duplicated(OTG)\n", __func__);
  1388. break;
  1389. }
  1390. info->cable_type = CABLE_TYPE_OTG_MUIC;
  1391. max77803_muic_set_usb_path(info, AP_USB_MODE);
  1392. msleep(40);
  1393. if (mdata->usb_cb && info->is_usb_ready)
  1394. mdata->usb_cb(USB_OTGHOST_ATTACHED);
  1395. } else if (chgtyp == CHGTYP_USB ||
  1396. chgtyp == CHGTYP_DOWNSTREAM_PORT ||
  1397. chgtyp == CHGTYP_DEDICATED_CHGR ||
  1398. chgtyp == CHGTYP_500MA || chgtyp == CHGTYP_1A) {
  1399. dev_info(info->dev, "%s: OTG charging pump\n",
  1400. __func__);
  1401. ret = max77803_muic_set_charging_type(info, !vbvolt);
  1402. }
  1403. break;
  1404. case ADC_SMARTDOCK:
  1405. max77803_muic_attach_smart_dock(info, adc, vbvolt, chgtyp);
  1406. break;
  1407. case ADC_VZW_USB_DOCK:
  1408. case ADC_AUDIODOCK:
  1409. if(!!vbvolt)
  1410. max77803_muic_attach_dock_type(info, adc, chgtyp);
  1411. break;
  1412. case ADC_JIG_UART_OFF:
  1413. max77803_muic_handle_jig_uart(info, vbvolt);
  1414. mdata->jig_state(true);
  1415. max77803_muic_uart_uevent(true);
  1416. break;
  1417. case ADC_JIG_USB_OFF:
  1418. case ADC_JIG_USB_ON:
  1419. if (vbvolt & STATUS2_VBVOLT_MASK) {
  1420. dev_info(info->dev, "%s: SKIP_JIG_USB\n", __func__);
  1421. ret = max77803_muic_attach_usb_type(info, adc);
  1422. }
  1423. mdata->jig_state(true);
  1424. max77803_muic_uart_uevent(true);
  1425. break;
  1426. case ADC_DESKDOCK:
  1427. max77803_muic_attach_dock_type(info, adc, chgtyp);
  1428. if (chgtyp == CHGTYP_USB ||
  1429. chgtyp == CHGTYP_DOWNSTREAM_PORT ||
  1430. chgtyp == CHGTYP_DEDICATED_CHGR ||
  1431. chgtyp == CHGTYP_500MA || chgtyp == CHGTYP_1A)
  1432. ret = max77803_muic_set_charging_type(info, false);
  1433. else if (chgtyp == CHGTYP_NO_VOLTAGE && !chgdetrun)
  1434. ret = max77803_muic_set_charging_type(info, !vbvolt);
  1435. /* For MAX77803 IC doesn`t occur chgtyp IRQ
  1436. * because of audio noise prevention.
  1437. * So, If below condition is set,
  1438. * we do charging at CARDOCK.
  1439. */
  1440. break;
  1441. case ADC_CARDOCK:
  1442. #if defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  1443. max77803_muic_attach_dock_type(info, adc, chgtyp);
  1444. if (chgtyp == CHGTYP_USB ||
  1445. chgtyp == CHGTYP_DOWNSTREAM_PORT ||
  1446. chgtyp == CHGTYP_DEDICATED_CHGR ||
  1447. chgtyp == CHGTYP_500MA || chgtyp == CHGTYP_1A)
  1448. ret = max77803_muic_set_charging_type(info, false);
  1449. else if (chgtyp == CHGTYP_NO_VOLTAGE && !chgdetrun)
  1450. ret = max77803_muic_set_charging_type(info, !vbvolt);
  1451. /* For MAX77803 IC doesn`t occur chgtyp IRQ
  1452. * because of audio noise prevention.
  1453. * So, If below condition is set,
  1454. * we do charging at CARDOCK.
  1455. */
  1456. #else
  1457. /* because of change FACTORY CPOriented to APOriented,
  1458. * at manufacture need AP wake-up method. write apo_factory
  1459. * FACTORY_START is set is_factory_start true.
  1460. */
  1461. if (info->is_factory_start) {
  1462. if (info->cable_type == CABLE_TYPE_JIG_UART_ON_MUIC) {
  1463. pr_info("%s:%s duplicated(JIG_UART_ON)\n",
  1464. DEV_NAME, __func__);
  1465. break;
  1466. }
  1467. pr_info("%s:%s JIG_UART_ON\n", DEV_NAME, __func__);
  1468. info->cable_type = CABLE_TYPE_JIG_UART_ON_MUIC;
  1469. if (mdata->dock_cb)
  1470. mdata->dock_cb(MAX77803_MUIC_DOCK_CARDOCK);
  1471. return 0;
  1472. }
  1473. #endif /* CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK */
  1474. break;
  1475. case ADC_CEA936ATYPE1_CHG:
  1476. case ADC_CEA936ATYPE2_CHG:
  1477. case ADC_OPEN:
  1478. switch (chgtyp) {
  1479. case CHGTYP_USB:
  1480. case CHGTYP_DOWNSTREAM_PORT:
  1481. if (adc == ADC_CEA936ATYPE1_CHG
  1482. || adc == ADC_CEA936ATYPE2_CHG) {
  1483. dev_info(info->dev, "%s:TA\n", __func__);
  1484. info->cable_type = CABLE_TYPE_TA_MUIC;
  1485. #ifdef CONFIG_USBHUB_USB3803
  1486. /* setting usb hub in default mode (standby) */
  1487. usb3803_set_mode(USB_3803_MODE_STANDBY);
  1488. #endif /* CONFIG_USBHUB_USB3803 */
  1489. ret = max77803_muic_set_charging_type(info, !vbvolt);
  1490. if (ret)
  1491. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1492. break;
  1493. }
  1494. if (chgtyp == CHGTYP_DOWNSTREAM_PORT) {
  1495. dev_info(info->dev, "%s, CDP(charging)\n",
  1496. __func__);
  1497. info->cable_type = CABLE_TYPE_CDP_MUIC;
  1498. ret = max77803_muic_set_charging_type(info, !vbvolt);
  1499. if(ret)
  1500. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1501. }
  1502. if (info->cable_type == CABLE_TYPE_MHL_MUIC) {
  1503. dev_info(info->dev, "%s: MHL(charging)\n",
  1504. __func__);
  1505. info->cable_type = CABLE_TYPE_MHL_VB_MUIC;
  1506. ret = max77803_muic_set_charging_type(info,
  1507. !vbvolt);
  1508. return ret;
  1509. }
  1510. ret = max77803_muic_attach_usb_type(info, adc);
  1511. break;
  1512. case CHGTYP_DEDICATED_CHGR:
  1513. case CHGTYP_500MA:
  1514. case CHGTYP_1A:
  1515. default:
  1516. dev_info(info->dev, "%s:TA\n", __func__);
  1517. info->cable_type = CABLE_TYPE_TA_MUIC;
  1518. #ifdef CONFIG_USBHUB_USB3803
  1519. /* setting usb hub in default mode (standby) */
  1520. usb3803_set_mode(USB_3803_MODE_STANDBY);
  1521. #endif /* CONFIG_USBHUB_USB3803 */
  1522. ret = max77803_muic_set_charging_type(info, !vbvolt);
  1523. if (ret)
  1524. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1525. break;
  1526. }
  1527. break;
  1528. default:
  1529. dev_warn(info->dev, "%s: unsupported adc=0x%x\n", __func__, adc);
  1530. info->cable_type = CABLE_TYPE_INCOMPATIBLE_MUIC;
  1531. ret = max77803_muic_set_charging_type(info, !vbvolt);
  1532. if (ret)
  1533. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1534. break;
  1535. }
  1536. return ret;
  1537. }
  1538. static int max77803_muic_handle_detach(struct max77803_muic_info *info, int irq)
  1539. {
  1540. struct i2c_client *client = info->muic;
  1541. struct max77803_muic_data *mdata = info->muic_data;
  1542. enum cable_type_muic prev_ct = CABLE_TYPE_NONE_MUIC;
  1543. u8 cntl2_val;
  1544. int ret = 0;
  1545. dev_info(info->dev, "func:%s\n", __func__);
  1546. info->is_adc_open_prev = true;
  1547. /* Workaround: irq doesn't occur after detaching mHL cable */
  1548. max77803_write_reg(client, MAX77803_MUIC_REG_CTRL1,
  1549. MAX77803_MUIC_CTRL1_BIN_0_000);
  1550. /* Enable Factory Accessory Detection State Machine */
  1551. max77803_update_reg(client, MAX77803_MUIC_REG_CTRL2,
  1552. (1 << CTRL2_ACCDET_SHIFT), CTRL2_ACCDET_MASK);
  1553. max77803_update_reg(client, MAX77803_MUIC_REG_CTRL2,
  1554. CTRL2_CPEn0_LOWPWD1,
  1555. CTRL2_CPEn_MASK | CTRL2_LOWPWD_MASK);
  1556. max77803_read_reg(client, MAX77803_MUIC_REG_CTRL2, &cntl2_val);
  1557. dev_info(info->dev, "%s: CNTL2(0x%02x)\n", __func__, cntl2_val);
  1558. #ifdef CONFIG_USBHUB_USB3803
  1559. /* setting usb hub in default mode (standby) */
  1560. usb3803_set_mode(USB_3803_MODE_STANDBY);
  1561. #endif /* CONFIG_USBHUB_USB3803 */
  1562. /* clear CDDelay 500ms */
  1563. max77803_muic_clear_cddelay(info);
  1564. if (info->cable_type == CABLE_TYPE_NONE_MUIC) {
  1565. dev_info(info->dev, "%s: duplicated(NONE)\n", __func__);
  1566. return 0;
  1567. }
  1568. switch (info->cable_type) {
  1569. case CABLE_TYPE_OTG_MUIC:
  1570. dev_info(info->dev, "%s: OTG\n", __func__);
  1571. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1572. if (mdata->usb_cb && info->is_usb_ready)
  1573. mdata->usb_cb(USB_OTGHOST_DETACHED);
  1574. break;
  1575. case CABLE_TYPE_USB_MUIC:
  1576. case CABLE_TYPE_CDP_MUIC:
  1577. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  1578. case CABLE_TYPE_JIG_USB_ON_MUIC:
  1579. dev_info(info->dev, "%s: USB(0x%x)\n", __func__,
  1580. info->cable_type);
  1581. prev_ct = info->cable_type;
  1582. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1583. ret = max77803_muic_set_charging_type(info, false);
  1584. if (ret) {
  1585. info->cable_type = prev_ct;
  1586. break;
  1587. }
  1588. if (info->is_usb_ready) {
  1589. if (work_busy(&info->usb_connection_work.work)) {
  1590. cancel_delayed_work(&info->usb_connection_work);
  1591. printk(KERN_ERR"max77803_muic_handle_detach canceling the work\n");
  1592. }
  1593. max77803_muic_send_event (1); // USB Disconnected
  1594. extcon_set_cable_state(info->edev,
  1595. extcon_cable_name[EXTCON_USB],
  1596. USB_CABLE_DETACHED);
  1597. }
  1598. break;
  1599. case CABLE_TYPE_DESKDOCK_MUIC:
  1600. dev_info(info->dev, "%s: DESKDOCK\n", __func__);
  1601. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1602. ret = max77803_muic_set_charging_type(info, false);
  1603. if (ret) {
  1604. info->cable_type = CABLE_TYPE_DESKDOCK_MUIC;
  1605. break;
  1606. }
  1607. if ((info->adc!=ADC_DESKDOCK) && mdata->dock_cb)
  1608. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1609. break;
  1610. case CABLE_TYPE_CARDOCK_MUIC:
  1611. dev_info(info->dev, "%s: CARDOCK\n", __func__);
  1612. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1613. is_cardock = 0;
  1614. ret = max77803_muic_set_charging_type(info, false);
  1615. if (ret) {
  1616. info->cable_type = CABLE_TYPE_CARDOCK_MUIC;
  1617. break;
  1618. }
  1619. if (mdata->dock_cb)
  1620. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1621. break;
  1622. case CABLE_TYPE_TA_MUIC:
  1623. case CABLE_TYPE_INCOMPATIBLE_MUIC:
  1624. dev_info(info->dev, "%s: TA\n", __func__);
  1625. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1626. ret = max77803_muic_set_charging_type(info, false);
  1627. if (ret)
  1628. info->cable_type = CABLE_TYPE_TA_MUIC;
  1629. break;
  1630. case CABLE_TYPE_JIG_UART_ON_MUIC:
  1631. #if defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  1632. dev_info(info->dev, "%s: JIG UART/BOOTON\n", __func__);
  1633. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1634. #else
  1635. if (info->is_factory_start) {
  1636. pr_info("%s:%s JIG_UART_ON\n", DEV_NAME, __func__);
  1637. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1638. if (mdata->dock_cb)
  1639. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1640. }
  1641. #endif /* CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK */
  1642. break;
  1643. case CABLE_TYPE_JIG_UART_OFF_MUIC:
  1644. dev_info(info->dev, "%s: JIG UART/BOOTOFF\n", __func__);
  1645. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1646. break;
  1647. case CABLE_TYPE_SMARTDOCK_MUIC:
  1648. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1649. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1650. max77803_muic_detach_smart_dock(info);
  1651. break;
  1652. case CABLE_TYPE_AUDIODOCK_MUIC:
  1653. dev_info(info->dev, "%s: AUDIODOCK\n", __func__);
  1654. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1655. if ((info->adc!=ADC_DESKDOCK) && mdata->dock_cb)
  1656. mdata->dock_cb(MAX77803_MUIC_DOCK_DETACHED);
  1657. if (mdata->usb_cb && info->is_usb_ready)
  1658. mdata->usb_cb(USB_POWERED_HOST_DETACHED);
  1659. ret = max77803_muic_set_charging_type(info, false);
  1660. max77803_muic_set_charging_type(info, false);
  1661. break;
  1662. case CABLE_TYPE_JIG_UART_OFF_VB_MUIC:
  1663. dev_info(info->dev, "%s: JIG UART/OFF/VB\n", __func__);
  1664. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1665. ret = max77803_muic_set_charging_type(info, false);
  1666. if (ret)
  1667. info->cable_type = CABLE_TYPE_JIG_UART_OFF_VB_MUIC;
  1668. break;
  1669. case CABLE_TYPE_MHL_MUIC:
  1670. if (irq == info->irq_adc || irq == info->irq_chgtype) {
  1671. dev_warn(info->dev, "Detech mhl: Ignore irq:%d\n", irq);
  1672. break;
  1673. }
  1674. dev_info(info->dev, "%s: MHL\n", __func__);
  1675. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1676. max77803_muic_set_charging_type(info, false);
  1677. if (mdata->mhl_cb && info->is_mhl_ready)
  1678. mdata->mhl_cb(MAX77803_MUIC_DETACHED);
  1679. break;
  1680. case CABLE_TYPE_MHL_VB_MUIC:
  1681. if (irq == info->irq_adc || irq == info->irq_chgtype) {
  1682. dev_warn(info->dev,
  1683. "Detech vbMhl: Ignore irq:%d\n", irq);
  1684. break;
  1685. }
  1686. dev_info(info->dev, "%s: MHL VBUS\n", __func__);
  1687. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1688. max77803_muic_set_charging_type(info, false);
  1689. if (mdata->mhl_cb && info->is_mhl_ready)
  1690. mdata->mhl_cb(MAX77803_MUIC_DETACHED);
  1691. break;
  1692. case CABLE_TYPE_UNKNOWN_MUIC:
  1693. dev_info(info->dev, "%s: UNKNOWN\n", __func__);
  1694. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1695. ret = max77803_muic_set_charging_type(info, false);
  1696. if (ret)
  1697. info->cable_type = CABLE_TYPE_UNKNOWN_MUIC;
  1698. break;
  1699. default:
  1700. dev_info(info->dev, "%s:invalid cable type %d\n",
  1701. __func__, info->cable_type);
  1702. break;
  1703. }
  1704. /* jig state clear */
  1705. mdata->jig_state(false);
  1706. max77803_muic_uart_uevent(false);
  1707. return ret;
  1708. }
  1709. static int max77803_muic_filter_dev(struct max77803_muic_info *info,
  1710. u8 status1, u8 status2)
  1711. {
  1712. u8 adc, adclow, adcerr, adc1k, chgtyp, vbvolt, dxovp;
  1713. int intr = INT_ATTACH;
  1714. adc = status1 & STATUS1_ADC_MASK;
  1715. adclow = status1 & STATUS1_ADCLOW_MASK;
  1716. adcerr = status1 & STATUS1_ADCERR_MASK;
  1717. adc1k = status1 & STATUS1_ADC1K_MASK;
  1718. chgtyp = status2 & STATUS2_CHGTYP_MASK;
  1719. vbvolt = status2 & STATUS2_VBVOLT_MASK;
  1720. dxovp = status2 & STATUS2_DXOVP_MASK;
  1721. dev_info(info->dev, "adc:%x adcerr:%x chgtyp:%x vb:%x dxovp:%x cable_type:%d\n",
  1722. adc, adcerr, chgtyp, vbvolt, dxovp, info->cable_type);
  1723. #if defined(CONFIG_MUIC_MAX77803_SUPPORT_MHL_CABLE_DETECTION)
  1724. if (adclow && adc1k) {
  1725. pr_info("%s:%s MHL cable connected\n", DEV_NAME, __func__);
  1726. return INT_ATTACH;
  1727. }
  1728. #endif /* CONFIG_MUIC_MAX77803_SUPPORT_MHL_CABLE_DETECTION */
  1729. switch (adc) {
  1730. case ADC_GND:
  1731. if (!adclow) {
  1732. pr_info("%s:%s ADC_GND & !adclow = OTG\n", DEV_NAME,
  1733. __func__);
  1734. } else {
  1735. pr_info("%s:%s ADC_GND & adclow != OTG\n", DEV_NAME,
  1736. __func__);
  1737. intr = INT_DETACH;
  1738. }
  1739. break;
  1740. case (ADC_CEA936ATYPE1_CHG) ... (ADC_JIG_UART_ON):
  1741. if(info->cable_type != CABLE_TYPE_NONE_MUIC
  1742. && chgtyp == CHGTYP_NO_VOLTAGE
  1743. && info->chgtyp != chgtyp) {
  1744. intr = INT_DETACH;
  1745. }
  1746. break;
  1747. case ADC_OPEN:
  1748. if (!adcerr) {
  1749. if (chgtyp == CHGTYP_NO_VOLTAGE) {
  1750. if (dxovp)
  1751. break;
  1752. else
  1753. intr = INT_DETACH;
  1754. } else if (chgtyp & CHGTYP) {
  1755. switch (info->cable_type) {
  1756. case CABLE_TYPE_OTG_MUIC:
  1757. case CABLE_TYPE_DESKDOCK_MUIC:
  1758. case CABLE_TYPE_CARDOCK_MUIC:
  1759. case CABLE_TYPE_SMARTDOCK_MUIC:
  1760. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1761. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1762. case CABLE_TYPE_AUDIODOCK_MUIC:
  1763. intr = INT_DETACH;
  1764. break;
  1765. default:
  1766. break;
  1767. }
  1768. }
  1769. }
  1770. break;
  1771. default:
  1772. break;
  1773. }
  1774. return intr;
  1775. }
  1776. static void max77803_muic_detect_dev(struct max77803_muic_info *info, int irq)
  1777. {
  1778. struct i2c_client *client = info->muic;
  1779. u8 status[2];
  1780. int intr = INT_ATTACH;
  1781. int ret;
  1782. u8 cntl1_val;
  1783. ret = max77803_read_reg(client, MAX77803_MUIC_REG_CTRL1, &cntl1_val);
  1784. dev_info(info->dev, "func:%s CONTROL1:%x\n", __func__, cntl1_val);
  1785. ret = max77803_bulk_read(client, MAX77803_MUIC_REG_STATUS1, 2, status);
  1786. dev_info(info->dev, "func:%s irq:%d ret:%d\n", __func__, irq, ret);
  1787. if (ret) {
  1788. dev_err(info->dev, "%s: fail to read muic reg(%d)\n", __func__,
  1789. ret);
  1790. return;
  1791. }
  1792. dev_info(info->dev, "%s: STATUS1:0x%x, 2:0x%x\n", __func__,
  1793. status[0], status[1]);
  1794. wake_lock_timeout(&info->muic_wake_lock, HZ * 2);
  1795. intr = max77803_muic_filter_dev(info, status[0], status[1]);
  1796. info->adc = status[0] & STATUS1_ADC_MASK;
  1797. info->chgtyp = status[1] & STATUS2_CHGTYP_MASK;
  1798. info->vbvolt = status[1] & STATUS2_VBVOLT_MASK;
  1799. if (intr == INT_ATTACH) {
  1800. dev_info(info->dev, "%s: ATTACHED\n", __func__);
  1801. max77803_muic_handle_attach(info, status[0], status[1], irq);
  1802. } else if (intr == INT_DETACH) {
  1803. dev_info(info->dev, "%s: DETACHED\n", __func__);
  1804. max77803_muic_handle_detach(info, irq);
  1805. } else {
  1806. pr_info("%s:%s device filtered, nothing affect.\n", DEV_NAME,
  1807. __func__);
  1808. }
  1809. return;
  1810. }
  1811. static irqreturn_t max77803_muic_irq(int irq, void *data)
  1812. {
  1813. struct max77803_muic_info *info = data;
  1814. dev_info(info->dev, "%s: irq:%d\n", __func__, irq);
  1815. mutex_lock(&info->mutex);
  1816. max77803_muic_detect_dev(info, irq);
  1817. mutex_unlock(&info->mutex);
  1818. return IRQ_HANDLED;
  1819. }
  1820. #define REQUEST_IRQ(_irq, _name) \
  1821. do { \
  1822. ret = request_threaded_irq(_irq, NULL, max77803_muic_irq, \
  1823. 0, _name, info); \
  1824. if (ret < 0) \
  1825. dev_err(info->dev, "Failed to request IRQ #%d: %d\n", \
  1826. _irq, ret); \
  1827. } while (0)
  1828. static int max77803_muic_irq_init(struct max77803_muic_info *info)
  1829. {
  1830. int ret, count;
  1831. u8 val;
  1832. dev_info(info->dev, "func:%s\n", __func__);
  1833. /* dev_info(info->dev, "%s: system_rev=%x\n", __func__, system_rev); */
  1834. /* INTMASK1 3:ADC1K 2:ADCErr 1:ADCLow 0:ADC */
  1835. /* INTMASK2 0:Chgtype */
  1836. max77803_write_reg(info->muic, MAX77803_MUIC_REG_INTMASK1, 0x09);
  1837. max77803_write_reg(info->muic, MAX77803_MUIC_REG_INTMASK2, 0x11);
  1838. max77803_write_reg(info->muic, MAX77803_MUIC_REG_INTMASK3, 0x00);
  1839. REQUEST_IRQ(info->irq_adc, "muic-adc");
  1840. REQUEST_IRQ(info->irq_chgtype, "muic-chgtype");
  1841. REQUEST_IRQ(info->irq_vbvolt, "muic-vbvolt");
  1842. REQUEST_IRQ(info->irq_adc1k, "muic-adc1k");
  1843. dev_info(info->dev, "adc:%d chgtype:%d adc1k:%d vbvolt:%d",
  1844. info->irq_adc, info->irq_chgtype,
  1845. info->irq_adc1k, info->irq_vbvolt);
  1846. for (count = 1; count < 9 ; count ++) {
  1847. max77803_read_reg(info->muic, count, &val);
  1848. dev_info(info->dev, "%s: reg=%x, val=%x\n", __func__,
  1849. count, val);
  1850. }
  1851. return 0;
  1852. }
  1853. static void max77803_muic_dock_detect(struct work_struct *work)
  1854. {
  1855. struct max77803_muic_info *info =
  1856. container_of(work, struct max77803_muic_info, dock_work.work);
  1857. struct i2c_client *client = info->muic;
  1858. u8 status[2];
  1859. int ret;
  1860. u8 cntl1_val;
  1861. u8 adc, adclow, adcerr, adc1k, chgtyp, vbvolt, dxovp;
  1862. mutex_lock(&info->mutex);
  1863. ret = max77803_read_reg(client, MAX77803_MUIC_REG_CTRL1, &cntl1_val);
  1864. pr_info("%s:%s CONTROL1:%x\n", DEV_NAME, __func__, cntl1_val);
  1865. ret = max77803_bulk_read(client, MAX77803_MUIC_REG_STATUS1, 2, status);
  1866. if (ret) {
  1867. pr_err("%s:%s fail to read muic reg(%d)\n", DEV_NAME, __func__,
  1868. ret);
  1869. goto end;
  1870. }
  1871. pr_info("%s:%s STATUS1:0x%x, 2:0x%x\n", DEV_NAME, __func__, status[0],
  1872. status[1]);
  1873. adc = status[0] & STATUS1_ADC_MASK;
  1874. adclow = status[0] & STATUS1_ADCLOW_MASK;
  1875. adcerr = status[0] & STATUS1_ADCERR_MASK;
  1876. adc1k = status[0] & STATUS1_ADC1K_MASK;
  1877. chgtyp = status[1] & STATUS2_CHGTYP_MASK;
  1878. vbvolt = status[1] & STATUS2_VBVOLT_MASK;
  1879. dxovp = status[1] & STATUS2_DXOVP_MASK;
  1880. pr_info("%s:%s adc:%x adcerr:%x chgtyp:%x vb:%x dxovp:%x"\
  1881. " cable_type:%d\n", DEV_NAME, __func__, adc, adcerr, chgtyp,
  1882. vbvolt, dxovp, info->cable_type);
  1883. if (adc1k) {
  1884. pr_info("%s:%s MHL attached, goto end\n", DEV_NAME, __func__);
  1885. goto end;
  1886. }
  1887. if (adcerr) {
  1888. pr_info("%s:%s ADC error, goto end\n", DEV_NAME, __func__);
  1889. goto end;
  1890. }
  1891. switch (adc) {
  1892. case ADC_SMARTDOCK:
  1893. pr_info("%s:%s Smart Dock\n", DEV_NAME, __func__);
  1894. if (vbvolt && !info->is_usb_ready) {
  1895. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  1896. DEV_NAME, __func__);
  1897. max77803_muic_set_usb_path(info, OPEN_USB_MODE);
  1898. } else
  1899. max77803_muic_set_usb_path(info, AP_USB_MODE);
  1900. break;
  1901. case ADC_AUDIODOCK:
  1902. pr_info("%s:%s Audio Dock\n", DEV_NAME, __func__);
  1903. if (vbvolt && !info->is_usb_ready) {
  1904. pr_info("%s:%s usb not ready yet, D+,D- line(Open), usb_state:%d\n",
  1905. DEV_NAME, __func__, info->is_usb_ready);
  1906. max77803_muic_set_usb_path(info, OPEN_USB_MODE);
  1907. } else
  1908. max77803_muic_set_usb_path(info, AP_USB_MODE);
  1909. break;
  1910. default:
  1911. break;
  1912. }
  1913. end:
  1914. mutex_unlock(&info->mutex);
  1915. }
  1916. static void max77803_muic_init_detect(struct work_struct *work)
  1917. {
  1918. struct max77803_muic_info *info =
  1919. container_of(work, struct max77803_muic_info, init_work.work);
  1920. dev_info(info->dev, "func:%s\n", __func__);
  1921. mutex_lock(&info->mutex);
  1922. max77803_muic_detect_dev(info, -1);
  1923. mutex_unlock(&info->mutex);
  1924. }
  1925. static void max77803_muic_usb_detect(struct work_struct *work)
  1926. {
  1927. struct max77803_muic_info *info =
  1928. container_of(work, struct max77803_muic_info, usb_work.work);
  1929. dev_info(info->dev, "func:%s info->muic_data->sw_path:%d\n",
  1930. __func__, info->muic_data->sw_path);
  1931. mutex_lock(&info->mutex);
  1932. info->is_usb_ready = true;
  1933. switch (info->cable_type) {
  1934. case CABLE_TYPE_CDP_MUIC:
  1935. case CABLE_TYPE_USB_MUIC:
  1936. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  1937. case CABLE_TYPE_JIG_USB_ON_MUIC:
  1938. #ifdef CONFIG_USBHUB_USB3803
  1939. /* setting usb hub in Diagnostic(hub) mode */
  1940. usb3803_set_mode(USB_3803_MODE_HUB);
  1941. #endif /* CONFIG_USBHUB_USB3803 */
  1942. extcon_set_cable_state(info->edev,
  1943. extcon_cable_name[EXTCON_USB],
  1944. USB_CABLE_ATTACHED);
  1945. break;
  1946. default :
  1947. break;
  1948. }
  1949. mutex_unlock(&info->mutex);
  1950. }
  1951. static void max77803_muic_dock_usb_detect(struct work_struct *work)
  1952. {
  1953. struct max77803_muic_info *info =
  1954. container_of(work, struct max77803_muic_info, dock_usb_work.work);
  1955. struct max77803_muic_data *mdata = info->muic_data;
  1956. dev_info(info->dev, "func:%s info->muic_data->sw_path:%d\n",
  1957. __func__, info->muic_data->sw_path);
  1958. mutex_lock(&info->mutex);
  1959. info->is_usb_ready = true;
  1960. if (mdata->usb_cb) {
  1961. switch (info->cable_type) {
  1962. case CABLE_TYPE_OTG_MUIC:
  1963. mdata->usb_cb(USB_OTGHOST_ATTACHED);
  1964. break;
  1965. case CABLE_TYPE_SMARTDOCK_MUIC:
  1966. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1967. pr_info("%s:%s now usb ready, turn"\
  1968. "D+,D- line to AP_USB\n", DEV_NAME,
  1969. __func__);
  1970. max77803_muic_set_usb_path(info, AP_USB_MODE);
  1971. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1972. break;
  1973. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1974. pr_info("%s:%s now usb ready, turn"\
  1975. "D+,D- line to AP_USB\n", DEV_NAME,
  1976. __func__);
  1977. max77803_muic_set_usb_path(info, AP_USB_MODE);
  1978. extcon_set_cable_state(info->edev,
  1979. extcon_cable_name[EXTCON_USB],
  1980. USB_CABLE_ATTACHED);
  1981. break;
  1982. case CABLE_TYPE_AUDIODOCK_MUIC:
  1983. pr_info("%s:%s now usb ready, turn"\
  1984. "D+,D- line to AP_USB\n", DEV_NAME,
  1985. __func__);
  1986. max77803_muic_set_usb_path(info, AP_USB_MODE);
  1987. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1988. break;
  1989. default:
  1990. break;
  1991. }
  1992. }
  1993. mutex_unlock(&info->mutex);
  1994. }
  1995. static void max77803_muic_mhl_detect(struct work_struct *work)
  1996. {
  1997. struct max77803_muic_info *info =
  1998. container_of(work, struct max77803_muic_info, mhl_work.work);
  1999. struct max77803_muic_data *mdata = info->muic_data;
  2000. dev_info(info->dev, "func:%s cable_type:%d\n", __func__,
  2001. info->cable_type);
  2002. mutex_lock(&info->mutex);
  2003. info->is_mhl_ready = true;
  2004. if (info->cable_type == CABLE_TYPE_MHL_MUIC ||
  2005. info->cable_type == CABLE_TYPE_MHL_VB_MUIC ||
  2006. info->cable_type == CABLE_TYPE_SMARTDOCK_MUIC ||
  2007. info->cable_type == CABLE_TYPE_SMARTDOCK_TA_MUIC ||
  2008. info->cable_type == CABLE_TYPE_SMARTDOCK_USB_MUIC) {
  2009. if (mdata->mhl_cb)
  2010. mdata->mhl_cb(MAX77803_MUIC_ATTACHED);
  2011. }
  2012. mutex_unlock(&info->mutex);
  2013. }
  2014. #define MAX_SPEAKER_CHECK 50
  2015. void max77803_muic_usb_connection_delay(struct work_struct *work)
  2016. {
  2017. struct max77803_muic_info *info =
  2018. container_of(work, struct max77803_muic_info, usb_connection_work.work);
  2019. // Don't be entered this function. if usb cable was detached.
  2020. if (info->cable_type == CABLE_TYPE_NONE_MUIC) {
  2021. pr_info("%s CABLE_TYPE_NONE \n",__func__);
  2022. return;
  2023. }
  2024. // Do usb connection
  2025. if ( info->cable_type == CABLE_TYPE_USB_MUIC)
  2026. extcon_set_cable_state(info->edev,
  2027. extcon_cable_name[EXTCON_USB],
  2028. USB_CABLE_ATTACHED);
  2029. }
  2030. int max77803_muic_get_status1_adc1k_value(void)
  2031. {
  2032. u8 adc1k;
  2033. int ret;
  2034. ret = max77803_read_reg(gInfo->muic,
  2035. MAX77803_MUIC_REG_STATUS1, &adc1k);
  2036. if (ret) {
  2037. dev_err(gInfo->dev, "%s: fail to read muic reg(%d)\n",
  2038. __func__, ret);
  2039. return -EINVAL;
  2040. }
  2041. adc1k = adc1k & STATUS1_ADC1K_MASK ? 1 : 0;
  2042. pr_info("func:%s, adc1k: %d\n", __func__, adc1k);
  2043. /* -1:err, 0:adc1k not detected, 1:adc1k detected */
  2044. return adc1k;
  2045. }
  2046. int max77803_muic_get_status1_adc_value(void)
  2047. {
  2048. u8 adc;
  2049. int ret;
  2050. ret = max77803_read_reg(gInfo->muic,
  2051. MAX77803_MUIC_REG_STATUS1, &adc);
  2052. if (ret) {
  2053. dev_err(gInfo->dev, "%s: fail to read muic reg(%d)\n",
  2054. __func__, ret);
  2055. return -EINVAL;
  2056. }
  2057. return adc & STATUS1_ADC_MASK;
  2058. }
  2059. /*
  2060. * func: max77803_muic_set_audio_switch
  2061. * arg: bool enable(true:set vps path, false:set path open)
  2062. * return: only 0 success
  2063. */
  2064. int max77803_muic_set_audio_switch(bool enable)
  2065. {
  2066. struct i2c_client *client = gInfo->muic;
  2067. u8 cntl1_val, cntl1_msk;
  2068. int ret;
  2069. pr_info("func:%s enable(%d)", __func__, enable);
  2070. if (enable) {
  2071. cntl1_val = (MAX77803_MUIC_CTRL1_BIN_2_010 << COMN1SW_SHIFT)
  2072. | (MAX77803_MUIC_CTRL1_BIN_2_010 << COMP2SW_SHIFT) |
  2073. (0 << MICEN_SHIFT);
  2074. } else {
  2075. cntl1_val = 0x3f;
  2076. }
  2077. cntl1_msk = COMN1SW_MASK | COMP2SW_MASK | MICEN_MASK;
  2078. ret = max77803_update_reg(client, MAX77803_MUIC_REG_CTRL1, cntl1_val,
  2079. cntl1_msk);
  2080. cntl1_val = MAX77803_MUIC_CTRL1_BIN_0_000;
  2081. max77803_read_reg(client, MAX77803_MUIC_REG_CTRL1, &cntl1_val);
  2082. dev_info(gInfo->dev, "%s: CNTL1(0x%02x)\n", __func__, cntl1_val);
  2083. return ret;
  2084. }
  2085. void max77803_update_jig_state(struct max77803_muic_info *info)
  2086. {
  2087. struct i2c_client *client = info->muic;
  2088. struct max77803_muic_data *mdata = info->muic_data;
  2089. u8 reg_data, adc;
  2090. int ret, jig_state;
  2091. ret = max77803_read_reg(client, MAX77803_MUIC_REG_STATUS1, &reg_data);
  2092. if (ret) {
  2093. dev_err(info->dev, "%s: fail to read muic reg(%d)\n",
  2094. __func__, ret);
  2095. return;
  2096. }
  2097. adc = reg_data & STATUS1_ADC_MASK;
  2098. switch (adc) {
  2099. case ADC_JIG_UART_OFF:
  2100. case ADC_JIG_USB_OFF:
  2101. case ADC_JIG_USB_ON:
  2102. jig_state = true;
  2103. break;
  2104. default:
  2105. jig_state = false;
  2106. break;
  2107. }
  2108. mdata->jig_state(jig_state);
  2109. max77803_muic_uart_uevent(jig_state);
  2110. }
  2111. static int __devinit max77803_muic_probe(struct platform_device *pdev)
  2112. {
  2113. struct max77803_dev *max77803 = dev_get_drvdata(pdev->dev.parent);
  2114. struct max77803_platform_data *pdata = dev_get_platdata(max77803->dev);
  2115. struct max77803_muic_info *info;
  2116. int ret;
  2117. u8 cdetctrl1;
  2118. pr_info("func:%s\n", __func__);
  2119. info = kzalloc(sizeof(struct max77803_muic_info), GFP_KERNEL);
  2120. if (!info) {
  2121. dev_err(&pdev->dev, "%s: failed to allocate info\n", __func__);
  2122. ret = -ENOMEM;
  2123. goto err_return;
  2124. }
  2125. info->dev = &pdev->dev;
  2126. info->max77803 = max77803;
  2127. info->muic = max77803->muic;
  2128. info->irq_adc = max77803->irq_base + MAX77803_MUIC_IRQ_INT1_ADC;
  2129. info->irq_chgtype = max77803->irq_base + MAX77803_MUIC_IRQ_INT2_CHGTYP;
  2130. info->irq_vbvolt = max77803->irq_base + MAX77803_MUIC_IRQ_INT2_VBVOLT;
  2131. info->irq_adc1k = max77803->irq_base + MAX77803_MUIC_IRQ_INT1_ADC1K;
  2132. info->muic_data = pdata->muic_data;
  2133. info->muic_data->uart_path = UART_PATH_AP;
  2134. info->is_adc_open_prev = true;
  2135. #if !defined(CONFIG_MUIC_MAX77803_SUPPORT_CAR_DOCK)
  2136. info->is_factory_start = false;
  2137. #endif /* !CONFIG_MUIC_MZX77803_SUPPORT_CAR_DOCK */
  2138. info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
  2139. GFP_KERNEL);
  2140. if (!info->edev) {
  2141. dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
  2142. ret = -ENOMEM;
  2143. goto err_input;
  2144. }
  2145. info->edev->name=DEV_NAME;
  2146. info->edev->supported_cable = extcon_cable_name;
  2147. ret = extcon_dev_register(info->edev, NULL);
  2148. if (ret) {
  2149. dev_err(&pdev->dev, "failed to register extcon device\n");
  2150. goto err_input;
  2151. }
  2152. wake_lock_init(&info->muic_wake_lock, WAKE_LOCK_SUSPEND,
  2153. "muic wake lock");
  2154. info->cable_type = CABLE_TYPE_UNKNOWN_MUIC;
  2155. info->muic_data->sw_path = AP_USB_MODE;
  2156. gInfo = info;
  2157. platform_set_drvdata(pdev, info);
  2158. dev_info(info->dev, "adc:%d chgtype:%d, adc1k%d\n",
  2159. info->irq_adc, info->irq_chgtype, info->irq_adc1k);
  2160. /* create sysfs group */
  2161. ret = sysfs_create_group(&switch_dev->kobj, &max77803_muic_group);
  2162. dev_set_drvdata(switch_dev, info);
  2163. if (ret) {
  2164. dev_err(&pdev->dev,
  2165. "failed to create max77803 muic attribute group\n");
  2166. goto err_input;
  2167. }
  2168. if (info->muic_data->init_cb)
  2169. info->muic_data->init_cb();
  2170. mutex_init(&info->mutex);
  2171. /* Set ADC debounce time: 25ms */
  2172. max77803_muic_set_adcdbset(info, 2);
  2173. /* Set DCDTmr to 2sec */
  2174. max77803_read_reg(info->max77803->muic,
  2175. MAX77803_MUIC_REG_CDETCTRL1, &cdetctrl1);
  2176. cdetctrl1 &= ~(1 << 5);
  2177. max77803_write_reg(info->max77803->muic,
  2178. MAX77803_MUIC_REG_CDETCTRL1, cdetctrl1);
  2179. pr_info("%s: CDETCTRL1(0x%02x)\n", __func__, cdetctrl1);
  2180. ret = switch_dev_register(&switch_uart3);
  2181. if (ret < 0) {
  2182. pr_err("%s : Failed to register switch_uart3 device\n", __func__);
  2183. goto err_switch_uart3_dev_register;
  2184. }
  2185. ret = max77803_muic_irq_init(info);
  2186. if (ret < 0) {
  2187. dev_err(&pdev->dev, "Failed to initialize MUIC irq:%d\n", ret);
  2188. goto fail;
  2189. }
  2190. /* initial cable detection */
  2191. INIT_DELAYED_WORK(&info->dock_work, max77803_muic_dock_detect);
  2192. schedule_delayed_work(&info->dock_work, msecs_to_jiffies(50));
  2193. INIT_DELAYED_WORK(&info->init_work, max77803_muic_init_detect);
  2194. schedule_delayed_work(&info->init_work, msecs_to_jiffies(3000));
  2195. INIT_DELAYED_WORK(&info->usb_work, max77803_muic_usb_detect);
  2196. schedule_delayed_work(&info->usb_work, msecs_to_jiffies(10000));
  2197. INIT_DELAYED_WORK(&info->dock_usb_work, max77803_muic_dock_usb_detect);
  2198. schedule_delayed_work(&info->dock_usb_work, msecs_to_jiffies(22000));
  2199. INIT_DELAYED_WORK(&info->mhl_work, max77803_muic_mhl_detect);
  2200. schedule_delayed_work(&info->mhl_work, msecs_to_jiffies(25000));
  2201. INIT_DELAYED_WORK(&info->usb_connection_work, max77803_muic_usb_connection_delay);
  2202. /* init jig state */
  2203. max77803_update_jig_state(info);
  2204. return 0;
  2205. fail:
  2206. if (info->irq_adc)
  2207. free_irq(info->irq_adc, NULL);
  2208. if (info->irq_chgtype)
  2209. free_irq(info->irq_chgtype, NULL);
  2210. if (info->irq_vbvolt)
  2211. free_irq(info->irq_vbvolt, NULL);
  2212. if (info->irq_adc1k)
  2213. free_irq(info->irq_adc1k, NULL);
  2214. mutex_destroy(&info->mutex);
  2215. err_input:
  2216. platform_set_drvdata(pdev, NULL);
  2217. wake_lock_destroy(&info->muic_wake_lock);
  2218. err_switch_uart3_dev_register:
  2219. kfree(info);
  2220. switch_dev_unregister(&switch_uart3);
  2221. err_return:
  2222. return ret;
  2223. }
  2224. static int __devexit max77803_muic_remove(struct platform_device *pdev)
  2225. {
  2226. struct max77803_muic_info *info = platform_get_drvdata(pdev);
  2227. sysfs_remove_group(&switch_dev->kobj, &max77803_muic_group);
  2228. if (info) {
  2229. dev_info(info->dev, "func:%s\n", __func__);
  2230. cancel_delayed_work(&info->dock_work);
  2231. cancel_delayed_work(&info->init_work);
  2232. cancel_delayed_work(&info->usb_work);
  2233. cancel_delayed_work(&info->dock_usb_work);
  2234. cancel_delayed_work(&info->mhl_work);
  2235. cancel_delayed_work(&info->usb_connection_work);
  2236. free_irq(info->irq_adc, info);
  2237. free_irq(info->irq_chgtype, info);
  2238. free_irq(info->irq_vbvolt, info);
  2239. free_irq(info->irq_adc1k, info);
  2240. wake_lock_destroy(&info->muic_wake_lock);
  2241. mutex_destroy(&info->mutex);
  2242. kfree(info);
  2243. }
  2244. return 0;
  2245. }
  2246. void max77803_muic_shutdown(struct device *dev)
  2247. {
  2248. struct max77803_muic_info *info = dev_get_drvdata(dev);
  2249. int ret;
  2250. u8 val;
  2251. dev_info(info->dev, "func:%s\n", __func__);
  2252. if (!info->muic) {
  2253. dev_err(info->dev, "%s: no muic i2c client\n", __func__);
  2254. return;
  2255. }
  2256. dev_info(info->dev, "%s: JIGSet: auto detection\n", __func__);
  2257. val = (0 << CTRL3_JIGSET_SHIFT) | (0 << CTRL3_BOOTSET_SHIFT);
  2258. ret = max77803_update_reg(info->muic, MAX77803_MUIC_REG_CTRL3, val,
  2259. CTRL3_JIGSET_MASK | CTRL3_BOOTSET_MASK);
  2260. if (ret < 0) {
  2261. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  2262. return;
  2263. }
  2264. }
  2265. static struct platform_driver max77803_muic_driver = {
  2266. .driver = {
  2267. .name = DEV_NAME,
  2268. .owner = THIS_MODULE,
  2269. .shutdown = max77803_muic_shutdown,
  2270. },
  2271. .probe = max77803_muic_probe,
  2272. .remove = __devexit_p(max77803_muic_remove),
  2273. };
  2274. static int __init max77803_muic_init(void)
  2275. {
  2276. pr_info("func:%s\n", __func__);
  2277. return platform_driver_register(&max77803_muic_driver);
  2278. }
  2279. module_init(max77803_muic_init);
  2280. static void __exit max77803_muic_exit(void)
  2281. {
  2282. pr_info("func:%s\n", __func__);
  2283. platform_driver_unregister(&max77803_muic_driver);
  2284. }
  2285. module_exit(max77803_muic_exit);
  2286. MODULE_DESCRIPTION("Maxim MAX77803 MUIC driver");
  2287. MODULE_AUTHOR("<sukdong.kim@samsung.com>");
  2288. MODULE_LICENSE("GPL");