max77828-muic.c 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605
  1. /*
  2. * max77828-muic.c - MUIC driver for the Maxim 77828
  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/max77828.h>
  32. #include <linux/mfd/max77828-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. #if defined(CONFIG_SWITCH_DUAL_MODEM)
  41. #include <linux/sec_param.h>
  42. #endif
  43. #define DEV_NAME "max77828-muic"
  44. /* For testing of Adaptive Charging */
  45. #ifndef TEST
  46. #define TEST 1
  47. #endif
  48. /* for providing API */
  49. static struct max77828_muic_info *gInfo;
  50. /* For restore charger interrupt states */
  51. //static u8 chg_int_state;
  52. /* MAX77828 MUIC CHG_TYP setting values */
  53. enum {
  54. /* No Valid voltage at VB (Vvb < Vvbdet) */
  55. CHGTYP_NO_VOLTAGE = 0x00,
  56. /* Unknown (D+/D- does not present a valid USB charger signature) */
  57. CHGTYP_USB = 0x01,
  58. /* Charging Downstream Port */
  59. CHGTYP_DOWNSTREAM_PORT = 0x02,
  60. /* Dedicated Charger (D+/D- shorted) */
  61. CHGTYP_DEDICATED_CHGR = 0x03,
  62. /* Special 500mA charger, max current 500mA */
  63. CHGTYP_500MA = 0x04,
  64. /* Special 1A charger, max current 1A */
  65. CHGTYP_1A = 0x05,
  66. /* Reserved for Future Use */
  67. CHGTYP_RFU = 0x06,
  68. /* Dead Battery Charging, max current 100mA */
  69. CHGTYP_DB_100MA = 0x07,
  70. CHGTYP_MAX,
  71. CHGTYP_INIT,
  72. CHGTYP_MIN = CHGTYP_NO_VOLTAGE
  73. };
  74. enum {
  75. ADC_GND = 0x00,
  76. #if defined(CONFIG_MUIC_DET_JACK)
  77. ADC_MHL_OR_SENDEND = 0x01,
  78. #else
  79. ADC_MHL = 0x01,
  80. #endif
  81. ADC_DOCK_PREV_KEY = 0x04,
  82. ADC_DOCK_NEXT_KEY = 0x07,
  83. ADC_INCOMPATIBLE1_CHG = 0x08, /* 0x01000 10.0K ohm*/
  84. ADC_DOCK_VOL_DN = 0x0a, /* 0x01010 14.46K ohm */
  85. ADC_DOCK_VOL_UP = 0x0b, /* 0x01011 17.26K ohm */
  86. ADC_DOCK_PLAY_PAUSE_KEY = 0x0d,
  87. ADC_VZW_USB_DOCK = 0x0e, /* 0x01110 28.7K ohm VZW Dock */
  88. ADC_SMARTDOCK = 0x10, /* 0x10000 40.2K ohm */
  89. ADC_HMT = 0x11, /* 0x10001 49.9K ohm */
  90. ADC_AUDIODOCK = 0x12, /* 0x10010 64.9K ohm */
  91. ADC_CEA936ATYPE1_CHG = 0x17, /* 0x10111 200K ohm */
  92. ADC_JIG_USB_OFF = 0x18, /* 0x11000 255K ohm */
  93. ADC_JIG_USB_ON = 0x19, /* 0x11001 301K ohm */
  94. ADC_DESKDOCK = 0x1a, /* 0x11010 365K ohm */
  95. ADC_CEA936ATYPE2_CHG = 0x1b, /* 0x11011 442K ohm */
  96. ADC_JIG_UART_OFF = 0x1c, /* 0x11100 523K ohm */
  97. ADC_JIG_UART_ON = 0x1d, /* 0x11101 619K ohm */
  98. ADC_CARDOCK = 0x1d, /* 0x11101 619K ohm */
  99. #if defined(CONFIG_MUIC_DET_JACK)
  100. ADC_EARJACK = 0x1e, /* 0x11110 1000 or 1002 ohm */
  101. #endif
  102. ADC_OPEN = 0x1f
  103. };
  104. enum {
  105. DOCK_KEY_NONE = 0,
  106. DOCK_KEY_VOL_UP_PRESSED,
  107. DOCK_KEY_VOL_UP_RELEASED,
  108. DOCK_KEY_VOL_DOWN_PRESSED,
  109. DOCK_KEY_VOL_DOWN_RELEASED,
  110. DOCK_KEY_PREV_PRESSED,
  111. DOCK_KEY_PREV_RELEASED,
  112. DOCK_KEY_PLAY_PAUSE_PRESSED,
  113. DOCK_KEY_PLAY_PAUSE_RELEASED,
  114. DOCK_KEY_NEXT_PRESSED,
  115. DOCK_KEY_NEXT_RELEASED,
  116. };
  117. struct max77828_muic_info {
  118. struct device *dev;
  119. struct max77828_dev *max77828;
  120. struct i2c_client *muic;
  121. struct max77828_muic_data *muic_data;
  122. int irq_adc;
  123. int irq_chgtype;
  124. int irq_vbvolt;
  125. int irq_adc1k;
  126. int mansw;
  127. u8 tx_data;
  128. struct timer_list timer;
  129. struct wake_lock muic_wake_lock;
  130. enum cable_type_muic cable_type;
  131. struct delayed_work dock_work;
  132. struct delayed_work init_work;
  133. struct delayed_work usb_work;
  134. struct delayed_work dock_usb_work;
  135. struct delayed_work mhl_work;
  136. #if defined(CONFIG_SEC_H_PROJECT) || defined (CONFIG_SEC_K_PROJECT)
  137. struct delayed_work usb_connection_work;
  138. int speaker_check_count;
  139. #endif
  140. #if defined(CONFIG_MUIC_DET_JACK)
  141. struct work_struct earjack_work;
  142. struct work_struct earjackkey_work;
  143. #endif
  144. struct mutex mutex;
  145. #if !defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  146. bool is_factory_start;
  147. #endif /* !CONFIG_MUIC_MAX77828_SUPORT_CAR_DOCK */
  148. bool is_usb_ready;
  149. bool is_mhl_ready;
  150. u8 adc;
  151. u8 chgtyp;
  152. u8 vbvolt;
  153. struct input_dev *input;
  154. int previous_key;
  155. bool is_adc_open_prev;
  156. #if defined(CONFIG_MUIC_DET_JACK)
  157. bool eardetacted;
  158. bool earkeypressed;
  159. int init_detect_done;
  160. unsigned int old_keycode;
  161. unsigned int keycode;
  162. #endif
  163. };
  164. #if defined(CONFIG_MUIC_DET_JACK)
  165. struct switch_dev switch_earjack = {
  166. .name = "h2w", /* /sys/class/switch/h2w/state */
  167. };
  168. struct switch_dev switch_earjackkey = {
  169. .name = "send_end", /* /sys/class/switch/send_end/state */
  170. };
  171. #endif
  172. struct switch_dev switch_uart3 = {
  173. .name = "uart3", /* /sys/class/switch/uart3/state */
  174. };
  175. static int if_muic_info;
  176. static int switch_sel;
  177. static int if_pmic_rev;
  178. int is_cardock;
  179. #if defined(CONFIG_MACH_MONTBLANC) || defined(CONFIG_MACH_VIKALCU)
  180. bool gEarDetected = false;
  181. #endif
  182. EXPORT_SYMBOL(is_cardock);
  183. /* func : get_if_pmic_inifo
  184. * switch_sel value get from bootloader comand line
  185. * switch_sel data consist 8 bits (xxxxzzzz)
  186. * first 4bits(zzzz) mean path infomation.
  187. * next 4bits(xxxx) mean if pmic version info
  188. */
  189. static int get_if_pmic_inifo(char *str)
  190. {
  191. get_option(&str, &if_muic_info);
  192. switch_sel = if_muic_info & 0x0f;
  193. if_pmic_rev = (if_muic_info & 0xf0) >> 4;
  194. pr_info("%s %s: switch_sel: %x if_pmic_rev:%x\n",
  195. __FILE__, __func__, switch_sel, if_pmic_rev);
  196. return if_muic_info;
  197. }
  198. __setup("pmic_info=", get_if_pmic_inifo);
  199. int get_switch_sel(void)
  200. {
  201. return switch_sel;
  202. }
  203. static int max77828_muic_set_comp2_comn1_pass2
  204. (struct max77828_muic_info *info, int type, int path)
  205. {
  206. /* type 0 == usb, type 1 == uart */
  207. u8 cntl1_val, cntl1_msk;
  208. int ret = 0;
  209. int val;
  210. dev_info(info->dev, "func: %s type: %d path: %d\n",
  211. __func__, type, path);
  212. if (type == 0) {
  213. if (path == AP_USB_MODE) {
  214. info->muic_data->sw_path = AP_USB_MODE;
  215. val = MAX77828_MUIC_CTRL1_BIN_1_001;
  216. } else if (path == CP_USB_MODE) {
  217. info->muic_data->sw_path = CP_USB_MODE;
  218. val = MAX77828_MUIC_CTRL1_BIN_4_100;
  219. } else {
  220. dev_err(info->dev, "func: %s invalid usb path\n"
  221. , __func__);
  222. return -EINVAL;
  223. }
  224. } else if (type == 1) {
  225. if (path == UART_PATH_AP) {
  226. info->muic_data->uart_path = UART_PATH_AP;
  227. val = MAX77828_MUIC_CTRL1_BIN_3_011;
  228. } else if (path == UART_PATH_CP) {
  229. info->muic_data->uart_path = UART_PATH_CP;
  230. val = MAX77828_MUIC_CTRL1_BIN_5_101;
  231. } else {
  232. dev_err(info->dev, "func: %s invalid uart path\n"
  233. , __func__);
  234. return -EINVAL;
  235. }
  236. }
  237. #if defined(CONFIG_MUIC_DET_JACK)
  238. else if (type == 2) {
  239. val = MAX77828_MUIC_CTRL1_BIN_2_010;
  240. }
  241. #endif
  242. else {
  243. dev_err(info->dev, "func: %s invalid path type(%d)\n"
  244. , __func__, type);
  245. return -EINVAL;
  246. }
  247. cntl1_val = (val << CTRL1_COMN1SW_SHIFT) | (val << CTRL1_COMP2SW_SHIFT);
  248. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  249. max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL1, cntl1_val,
  250. cntl1_msk);
  251. return ret;
  252. }
  253. static int max77828_muic_set_uart_path_pass2
  254. (struct max77828_muic_info *info, int path)
  255. {
  256. int ret = 0;
  257. ret = max77828_muic_set_comp2_comn1_pass2(info, 1/*uart*/, path);
  258. return ret;
  259. }
  260. #if defined(CONFIG_MUIC_DET_JACK)
  261. static int max77828_muic_set_audio_path_pass2(struct max77828_muic_info *info, int path)
  262. {
  263. int ret = 0;
  264. ret = max77828_muic_set_comp2_comn1_pass2(info, 2/*audio*/, path);
  265. return ret;
  266. }
  267. #endif
  268. static ssize_t max77828_muic_show_usb_state(struct device *dev,
  269. struct device_attribute *attr,
  270. char *buf)
  271. {
  272. struct max77828_muic_info *info = dev_get_drvdata(dev);
  273. dev_info(info->dev, "func:%s info->cable_type:%d\n",
  274. __func__, info->cable_type);
  275. switch (info->cable_type) {
  276. case CABLE_TYPE_USB_MUIC:
  277. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  278. case CABLE_TYPE_JIG_USB_ON_MUIC:
  279. return sprintf(buf, "USB_STATE_CONFIGURED\n");
  280. default:
  281. break;
  282. }
  283. return sprintf(buf, "USB_STATE_NOTCONFIGURED\n");
  284. }
  285. static ssize_t max77828_muic_show_device(struct device *dev,
  286. struct device_attribute *attr,
  287. char *buf)
  288. {
  289. struct max77828_muic_info *info = dev_get_drvdata(dev);
  290. dev_info(info->dev, "func:%s info->cable_type:%d\n",
  291. __func__, info->cable_type);
  292. switch (info->cable_type) {
  293. case CABLE_TYPE_NONE_MUIC:
  294. return sprintf(buf, "No cable\n");
  295. case CABLE_TYPE_USB_MUIC:
  296. return sprintf(buf, "USB\n");
  297. case CABLE_TYPE_OTG_MUIC:
  298. return sprintf(buf, "OTG\n");
  299. case CABLE_TYPE_TA_MUIC:
  300. return sprintf(buf, "TA\n");
  301. #if defined(CONFIG_MACH_KLTE_JPN)
  302. case CABLE_TYPE_HV_TA_MUIC:
  303. return sprintf(buf, "TA\n");
  304. #endif
  305. case CABLE_TYPE_DESKDOCK_MUIC:
  306. return sprintf(buf, "Desk Dock\n");
  307. case CABLE_TYPE_SMARTDOCK_MUIC:
  308. return sprintf(buf, "Smart Dock\n");
  309. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  310. return sprintf(buf, "Smart Dock with TA\n");
  311. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  312. return sprintf(buf, "Smart Dock with USB\n");
  313. case CABLE_TYPE_HMT_MUIC:
  314. return sprintf(buf, "HMT Dock\n");
  315. case CABLE_TYPE_HMT_TA_MUIC:
  316. return sprintf(buf, "HMT Dock with TA\n");
  317. case CABLE_TYPE_AUDIODOCK_MUIC:
  318. return sprintf(buf, "Audio Dock\n");
  319. case CABLE_TYPE_CARDOCK_MUIC:
  320. return sprintf(buf, "Car Dock\n");
  321. case CABLE_TYPE_JIG_UART_OFF_MUIC:
  322. return sprintf(buf, "JIG UART OFF\n");
  323. case CABLE_TYPE_JIG_UART_OFF_VB_MUIC:
  324. return sprintf(buf, "JIG UART OFF/VB\n");
  325. case CABLE_TYPE_JIG_UART_ON_MUIC:
  326. return sprintf(buf, "JIG UART ON\n");
  327. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  328. return sprintf(buf, "JIG USB OFF\n");
  329. case CABLE_TYPE_JIG_USB_ON_MUIC:
  330. return sprintf(buf, "JIG USB ON\n");
  331. case CABLE_TYPE_MHL_MUIC:
  332. return sprintf(buf, "mHL\n");
  333. case CABLE_TYPE_MHL_VB_MUIC:
  334. return sprintf(buf, "mHL charging\n");
  335. case CABLE_TYPE_INCOMPATIBLE_MUIC:
  336. return sprintf(buf, "Incompatible TA\n");
  337. default:
  338. break;
  339. }
  340. return sprintf(buf, "UNKNOWN\n");
  341. }
  342. static ssize_t max77828_muic_show_manualsw(struct device *dev,
  343. struct device_attribute *attr,
  344. char *buf)
  345. {
  346. struct max77828_muic_info *info = dev_get_drvdata(dev);
  347. dev_info(info->dev, "func:%s ap(0),cp(1),vps(2)sw_path:%d\n",
  348. __func__, info->muic_data->sw_path);/*For debuging*/
  349. switch (info->muic_data->sw_path) {
  350. case AP_USB_MODE:
  351. return sprintf(buf, "PDA\n");
  352. case CP_USB_MODE:
  353. return sprintf(buf, "MODEM\n");
  354. case AUDIO_MODE:
  355. return sprintf(buf, "Audio\n");
  356. default:
  357. break;
  358. }
  359. return sprintf(buf, "UNKNOWN\n");
  360. }
  361. static int max77828_muic_set_usb_path(struct max77828_muic_info *info,
  362. int path);
  363. static ssize_t max77828_muic_set_manualsw(struct device *dev,
  364. struct device_attribute *attr,
  365. const char *buf, size_t count)
  366. {
  367. struct max77828_muic_info *info = dev_get_drvdata(dev);
  368. dev_info(info->dev, "func:%s buf:%s,count:%d\n", __func__, buf, count);
  369. if (!strncasecmp(buf, "PDA", 3)) {
  370. info->muic_data->sw_path = AP_USB_MODE;
  371. dev_info(info->dev, "%s: AP_USB_MODE\n", __func__);
  372. } else if (!strncasecmp(buf, "MODEM", 5)) {
  373. info->muic_data->sw_path = CP_USB_MODE;
  374. dev_info(info->dev, "%s: CP_USB_MODE\n", __func__);
  375. max77828_muic_set_usb_path(info, CP_USB_MODE);
  376. } else
  377. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  378. return count;
  379. }
  380. static ssize_t max77828_muic_show_adc(struct device *dev,
  381. struct device_attribute *attr, char *buf)
  382. {
  383. struct max77828_muic_info *info = dev_get_drvdata(dev);
  384. int ret;
  385. u8 val;
  386. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_STATUS1, &val);
  387. dev_info(info->dev, "func:%s ret:%d val:%x\n", __func__, ret, val);
  388. if (ret) {
  389. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  390. return sprintf(buf, "UNKNOWN\n");
  391. }
  392. return sprintf(buf, "%x\n", (val & STATUS1_ADC_MASK));
  393. }
  394. static ssize_t max77828_muic_show_audio_path(struct device *dev,
  395. struct device_attribute *attr,
  396. char *buf)
  397. {
  398. struct max77828_muic_info *info = dev_get_drvdata(dev);
  399. int ret;
  400. u8 val;
  401. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_CTRL1, &val);
  402. dev_info(info->dev, "func:%s ret:%d val:%x\n", __func__, ret, val);
  403. if (ret) {
  404. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  405. return sprintf(buf, "UNKNOWN\n");
  406. }
  407. return sprintf(buf, "%x\n", val);
  408. }
  409. static ssize_t max77828_muic_set_audio_path(struct device *dev,
  410. struct device_attribute *attr,
  411. const char *buf, size_t count)
  412. {
  413. struct max77828_muic_info *info = dev_get_drvdata(dev);
  414. struct i2c_client *client = info->muic;
  415. u8 cntl1_val, cntl1_msk;
  416. u8 val;
  417. dev_info(info->dev, "func:%s buf:%s\n", __func__, buf);
  418. if (!strncmp(buf, "0", 1))
  419. val = MAX77828_MUIC_CTRL1_BIN_0_000;
  420. else if (!strncmp(buf, "1", 1))
  421. val = MAX77828_MUIC_CTRL1_BIN_2_010;
  422. else {
  423. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  424. return count;
  425. }
  426. cntl1_val = (val << CTRL1_COMN1SW_SHIFT) | (val << CTRL1_COMP2SW_SHIFT);
  427. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  428. max77828_update_reg(client, MAX77828_MUIC_REG_CTRL1, cntl1_val,
  429. cntl1_msk);
  430. dev_info(info->dev, "MUIC cntl1_val:%x, cntl1_msk:%x\n", cntl1_val,
  431. cntl1_msk);
  432. cntl1_val = MAX77828_MUIC_CTRL1_BIN_0_000;
  433. max77828_read_reg(client, MAX77828_MUIC_REG_CTRL1, &cntl1_val);
  434. dev_info(info->dev, "%s: CNTL1(0x%02x)\n", __func__, cntl1_val);
  435. return count;
  436. }
  437. static ssize_t max77828_muic_show_otg_test(struct device *dev,
  438. struct device_attribute *attr,
  439. char *buf)
  440. {
  441. struct max77828_muic_info *info = dev_get_drvdata(dev);
  442. int ret;
  443. u8 val;
  444. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_CDETCTRL1, &val);
  445. dev_info(info->dev, "func:%s ret:%d val:%x buf%s\n",
  446. __func__, ret, val, buf);
  447. if (ret) {
  448. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  449. return sprintf(buf, "UNKNOWN\n");
  450. }
  451. val &= CDETCTRL1_CHGDETEN_MASK;
  452. return sprintf(buf, "%x\n", val);
  453. }
  454. static ssize_t max77828_muic_set_otg_test(struct device *dev,
  455. struct device_attribute *attr,
  456. const char *buf, size_t count)
  457. {
  458. struct max77828_muic_info *info = dev_get_drvdata(dev);
  459. struct i2c_client *client = info->muic;
  460. u8 val;
  461. dev_info(info->dev, "func:%s buf:%s\n", __func__, buf);
  462. if (!strncmp(buf, "0", 1))
  463. val = 0;
  464. else if (!strncmp(buf, "1", 1))
  465. val = 1;
  466. else {
  467. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  468. return count;
  469. }
  470. max77828_update_reg(client, MAX77828_MUIC_REG_CDETCTRL1,
  471. val << CDETCTRL1_CHGDETEN_SHIFT, CDETCTRL1_CHGDETEN_MASK);
  472. val = 0;
  473. max77828_read_reg(client, MAX77828_MUIC_REG_CDETCTRL1, &val);
  474. dev_info(info->dev, "%s: CDETCTRL(0x%02x)\n", __func__, val);
  475. return count;
  476. }
  477. static void max77828_muic_start_check_hv(struct max77828_muic_info *info)
  478. {
  479. int ret;
  480. u8 val;
  481. if (!info->muic) {
  482. dev_err(info->dev, "%s: no muic i2c client\n", __func__);
  483. return;
  484. }
  485. #if defined(CONFIG_MACH_KLTE_JPN)
  486. /* Clear INT3 */
  487. max77828_read_reg(info->muic, MAX77828_MUIC_REG_INT3, &val);
  488. #endif
  489. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_HVCTRL1, &val);
  490. dev_info(info->dev, "%s: Read HVCTRL1 (0x%02x)\n", __func__, val);
  491. if (ret) {
  492. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  493. }
  494. #if defined(CONFIG_MACH_KLTE_JPN)
  495. /* set HVCONTROL1=0x11 */
  496. val |= (HVCTRL1_DPVD_D06 | HVCTRL1_DPDNVDEN_MASK);
  497. dev_info(info->dev, "%s: Write HVCTRL1 (0x%02x)\n", __func__, val);
  498. ret = max77828_write_reg(info->muic, MAX77828_MUIC_REG_HVCTRL1, val);
  499. if (ret < 0)
  500. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  501. //Test to read back the written value
  502. #if TEST
  503. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_HVCTRL1, &val);
  504. dev_info(info->dev, "%s: result HVCTRL1 (0x%02x)\n", __func__, val);
  505. if (ret) {
  506. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  507. }
  508. #endif
  509. /* Delete it because we use polling method to check INT3 */
  510. /* set INTMASK3 = 0x02 */
  511. ret = max77828_write_reg(info->muic, MAX77828_MUIC_REG_INT3, 0x3);
  512. if (ret < 0)
  513. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  514. #else
  515. val |= (0x10 << HVCTRL1_DPVD_SHIFT);
  516. dev_info(info->dev, "%s: SET HVCTRL1 (0x%02x)\n", __func__, val);
  517. ret = max77828_update_reg(info->muic, MAX77828_MUIC_REG_HVCTRL1, val,
  518. HVCTRL1_DPVD_MASK);
  519. dev_info(info->dev, "%s: result HVCTRL1 (0x%02x)\n", __func__, val);
  520. if (ret < 0)
  521. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  522. #endif
  523. info->timer.expires = jiffies + 15 * HZ / 10;
  524. add_timer(&info->timer);
  525. }
  526. static void max77828_check_hv(unsigned long arg)
  527. {
  528. u8 value;
  529. int ret;
  530. /* Clear INT3 Register */
  531. ret = max77828_read_reg(gInfo->muic, MAX77828_MUIC_REG_INT3, &value);
  532. if(IS_ERR_VALUE(ret))
  533. {
  534. dev_err(gInfo->dev, "%s:cannot read INT3:%d\n", __func__, ret);
  535. return;
  536. }
  537. /* Check VDNMon Interrupt is checked or not */
  538. if(!value & 0x01)
  539. return;
  540. ret = max77828_read_reg(gInfo->muic, MAX77828_MUIC_REG_STATUS3, &value);
  541. if(IS_ERR_VALUE(ret))
  542. {
  543. dev_err(gInfo->dev, "%s:cannot read STATUS3%d\n", __func__, ret);
  544. return;
  545. }
  546. dev_info(gInfo->dev, "%s: Get MAX77828_MUIC_REG_STATUS3 (0x%02x)\n", __func__, value);
  547. /* Check VDNMon Value is checked or not*/
  548. if (value & 0x10)
  549. return;
  550. dev_info(gInfo->dev, "%s:HV charger is detected.\n", __func__);
  551. /* Set values about HV Charging
  552. * HVCTRL1 = 0x00
  553. * HVCTRL2 = 0x06
  554. */
  555. max77828_write_reg(gInfo->max77828->muic, MAX77828_MUIC_REG_STATUS2, 0x06);
  556. max77828_write_reg(gInfo->max77828->muic, MAX77828_MUIC_REG_STATUS1, 0x00);
  557. /* Disable INT3 */
  558. ret = max77828_write_reg(gInfo->muic, MAX77828_MUIC_REG_INT3, 0x0);
  559. if (ret < 0)
  560. dev_err(gInfo->dev, "%s: fail to update reg\n", __func__);
  561. /* Set TX Data */
  562. // value = gInfo->tx_data;
  563. /* TX Data = 0x45 */
  564. value = 0x45;
  565. max77828_write_reg(gInfo->max77828->muic, MAX77828_MUIC_REG_HVTXBYTE, value);
  566. /* Set HVCTRL2 = 0x1B*/
  567. // max77828_write_reg(gInfo->max77828->muic, MAX77828_MUIC_REG_HVCTRL2, 0x1B);
  568. /* disable DNResN + enable HVDigEn + Mping + MTxEn + MPngEnb */
  569. max77828_write_reg(gInfo->max77828->muic, MAX77828_MUIC_REG_HVCTRL2, 0x5B);
  570. }
  571. static int max77828_muic_check_vdnmon_status(struct max77828_muic_info *info)
  572. {
  573. int ret;
  574. u8 val;
  575. dev_info(info->dev, "func:%s\n", __func__);
  576. if (!info->muic) {
  577. dev_err(info->dev, "%s: no muic i2c client\n", __func__);
  578. return -ENODEV;
  579. }
  580. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_STATUS3, &val);
  581. if (ret) {
  582. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  583. }
  584. dev_info(info->dev, "Value read from REG func:%s val:%x\n", __func__, val);
  585. val &= STATUS3_VDNMON_MASK;
  586. val = val >> STATUS3_VDNMON_SHIFT;
  587. dev_info(info->dev, "func:%s val:%x\n", __func__, val);
  588. return val;
  589. }
  590. static void max77828_muic_set_dpdnvden(struct max77828_muic_info *info,
  591. int value)
  592. {
  593. int ret;
  594. u8 val;
  595. if (!info->muic) {
  596. dev_err(info->dev, "%s: no muic i2c client\n", __func__);
  597. return;
  598. }
  599. val = value << HVCTRL1_DPDNVDEN_SHIFT;
  600. dev_info(info->dev, "%s: DPDNVdEN(0x%02x)\n", __func__, val);
  601. ret = max77828_update_reg(info->muic, MAX77828_MUIC_REG_HVCTRL1, val,
  602. HVCTRL1_DPDNVDEN_MASK);
  603. if (ret < 0)
  604. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  605. }
  606. static void max77828_muic_set_adcdbset(struct max77828_muic_info *info,
  607. int value)
  608. {
  609. int ret;
  610. u8 val;
  611. dev_info(info->dev, "func:%s value:%x\n", __func__, value);
  612. if (value > 3) {
  613. dev_err(info->dev, "%s: invalid value(%x)\n", __func__, value);
  614. return;
  615. }
  616. if (!info->muic) {
  617. dev_err(info->dev, "%s: no muic i2c client\n", __func__);
  618. return;
  619. }
  620. val = value << CTRL4_ADCDBSET_SHIFT;
  621. dev_info(info->dev, "%s: ADCDBSET(0x%02x)\n", __func__, val);
  622. ret = max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL4, val,
  623. CTRL4_ADCDBSET_MASK);
  624. if (ret < 0)
  625. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  626. }
  627. static ssize_t max77828_muic_show_adc_debounce_time(struct device *dev,
  628. struct device_attribute *attr, char *buf)
  629. {
  630. struct max77828_muic_info *info = dev_get_drvdata(dev);
  631. int ret;
  632. u8 val;
  633. dev_info(info->dev, "func:%s buf:%s\n", __func__, buf);
  634. if (!info->muic)
  635. return sprintf(buf, "No I2C client\n");
  636. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_CTRL3, &val);
  637. if (ret) {
  638. dev_err(info->dev, "%s: fail to read muic reg\n", __func__);
  639. return sprintf(buf, "UNKNOWN\n");
  640. }
  641. val &= CTRL4_ADCDBSET_MASK;
  642. val = val >> CTRL4_ADCDBSET_SHIFT;
  643. dev_info(info->dev, "func:%s val:%x\n", __func__, val);
  644. return sprintf(buf, "%x\n", val);
  645. }
  646. static ssize_t max77828_muic_set_adc_debounce_time(struct device *dev,
  647. struct device_attribute *attr,
  648. const char *buf, size_t count)
  649. {
  650. struct max77828_muic_info *info = dev_get_drvdata(dev);
  651. int value;
  652. sscanf(buf, "%d", &value);
  653. value = (value & 0x3);
  654. dev_info(info->dev, "%s: Do nothing\n", __func__);
  655. return count;
  656. }
  657. static ssize_t max77828_muic_set_uart_sel(struct device *dev,
  658. struct device_attribute *attr,
  659. const char *buf, size_t count)
  660. {
  661. struct max77828_muic_info *info = dev_get_drvdata(dev);
  662. dev_info(info->dev, "%s, buf : %s\n",__func__,buf);
  663. if (!strncasecmp(buf, "AP", 2)) {
  664. int ret = max77828_muic_set_uart_path_pass2
  665. (info, UART_PATH_AP);
  666. if (ret >= 0){
  667. info->muic_data->uart_path = UART_PATH_AP;
  668. dev_info(info->dev, "UART PATH(CP:0, AP:1):%d\n",
  669. info->muic_data->uart_path);
  670. }else
  671. dev_err(info->dev, "%s: Change(AP) fail!!", __func__);
  672. #if defined(CONFIG_SWITCH_DUAL_MODEM)
  673. } else if (!strncasecmp(buf, "CP2", 2)) {
  674. #else
  675. } else if (!strncasecmp(buf, "CP", 2)) {
  676. #endif
  677. int ret = max77828_muic_set_uart_path_pass2
  678. (info, UART_PATH_CP);
  679. if (ret >= 0){
  680. info->muic_data->uart_path = UART_PATH_CP;
  681. dev_info(info->dev, "UART PATH(CP:0, AP:1):%d\n",
  682. info->muic_data->uart_path);
  683. }else
  684. dev_err(info->dev, "%s: Change(CP) fail!!", __func__);
  685. } else {
  686. dev_warn(info->dev, "%s: Wrong command\n", __func__);
  687. }
  688. return count;
  689. }
  690. static ssize_t max77828_muic_show_uart_sel(struct device *dev,
  691. struct device_attribute *attr,
  692. char *buf)
  693. {
  694. struct max77828_muic_info *info = dev_get_drvdata(dev);
  695. dev_info(info->dev, "func:%s cp(0),ap(1)sw_path:%d\n",
  696. __func__, info->muic_data->uart_path);/*For debuging*/
  697. switch (info->muic_data->uart_path) {
  698. case UART_PATH_AP:
  699. return sprintf(buf, "AP\n");
  700. break;
  701. case UART_PATH_CP:
  702. #if defined(CONFIG_SWITCH_DUAL_MODEM)
  703. return sprintf(buf, "CP2\n");
  704. #else
  705. return sprintf(buf, "CP\n");
  706. #endif
  707. break;
  708. default:
  709. break;
  710. }
  711. return sprintf(buf, "UNKNOWN\n");
  712. }
  713. static ssize_t max77828_muic_show_charger_type(struct device *dev,
  714. struct device_attribute *attr,
  715. char *buf)
  716. {
  717. struct max77828_muic_info *info = dev_get_drvdata(dev);
  718. u8 adc, status;
  719. int ret;
  720. ret = max77828_read_reg(info->muic, MAX77828_MUIC_REG_STATUS1, &status);
  721. adc = status & STATUS1_ADC_MASK;
  722. /* SYSFS Node : chg_type
  723. * SYSFS State
  724. * 0 : Dedicated Charger
  725. * 1 : Non-Dedicated Charger
  726. * 2 : Cigar Jack
  727. */
  728. switch (adc){
  729. #if defined(CONFIG_MUIC_DET_JACK)
  730. case ADC_MHL_OR_SENDEND:
  731. #else
  732. case ADC_MHL:
  733. #endif
  734. case ADC_VZW_USB_DOCK:
  735. case ADC_SMARTDOCK:
  736. case ADC_AUDIODOCK:
  737. case ADC_DESKDOCK:
  738. case ADC_CARDOCK:
  739. case ADC_OPEN:
  740. dev_info(info->dev, "%s: Dedicated Charger State\n", __func__);
  741. return snprintf(buf, 4, "%d\n", 0);
  742. break;
  743. case ADC_CEA936ATYPE1_CHG:
  744. case ADC_INCOMPATIBLE1_CHG:
  745. dev_info(info->dev, "%s: Undedicated Charger State\n", __func__);
  746. return snprintf(buf, 4, "%d\n", 1);
  747. break;
  748. case ADC_CEA936ATYPE2_CHG:
  749. dev_info(info->dev, "%s: Dedicated Charger State\n", __func__);
  750. return snprintf(buf, 4, "%d\n", 2);
  751. break;
  752. default:
  753. dev_info(info->dev, "%s: Undeclared State\n", __func__);
  754. break;
  755. }
  756. return snprintf(buf, 9, "%s\n", "UNKNOWN");
  757. }
  758. #if !defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  759. static ssize_t max77828_muic_show_apo_factory(struct device *dev,
  760. struct device_attribute *attr,
  761. char *buf)
  762. {
  763. struct max77828_muic_info *info = dev_get_drvdata(dev);
  764. const char *mode;
  765. /* true: Factory mode, false: not Factory mode */
  766. if (info->is_factory_start)
  767. mode = "FACTORY_MODE";
  768. else
  769. mode = "NOT_FACTORY_MODE";
  770. pr_info("%s:%s apo factory=%s\n", DEV_NAME, __func__, mode);
  771. return sprintf(buf, "%s\n", mode);
  772. }
  773. static ssize_t max77828_muic_set_apo_factory(struct device *dev,
  774. struct device_attribute *attr,
  775. const char *buf, size_t count)
  776. {
  777. struct max77828_muic_info *info = dev_get_drvdata(dev);
  778. const char *mode;
  779. pr_info("%s:%s buf:%s\n", DEV_NAME, __func__, buf);
  780. /* "FACTORY_START": factory mode */
  781. if (!strncmp(buf, "FACTORY_START", 13)) {
  782. info->is_factory_start = true;
  783. mode = "FACTORY_MODE";
  784. } else {
  785. pr_warn("%s:%s Wrong command\n", DEV_NAME, __func__);
  786. return count;
  787. }
  788. pr_info("%s:%s apo factory=%s\n", DEV_NAME, __func__, mode);
  789. return count;
  790. }
  791. #endif /* !CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK */
  792. #if defined(CONFIG_MUIC_DET_JACK)
  793. static ssize_t key_state_onoff_show(struct device *dev, struct device_attribute *attr, char *buf)
  794. {
  795. struct max77828_muic_info *info = dev_get_drvdata(dev);
  796. int value = 0;
  797. if (info->earkeypressed && info->keycode == KEY_MEDIA)
  798. value = 1;
  799. return snprintf(buf, 4, "%d\n", value);
  800. }
  801. static ssize_t earjack_state_onoff_show(struct device *dev, struct device_attribute *attr, char *buf)
  802. {
  803. struct max77828_muic_info *info = dev_get_drvdata(dev);
  804. int value = 0;
  805. if (info->eardetacted == true)
  806. value = 1;
  807. return snprintf(buf, 4, "%d\n", value);
  808. }
  809. #endif
  810. #if !defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  811. static DEVICE_ATTR(apo_factory, 0664,
  812. max77828_muic_show_apo_factory,
  813. max77828_muic_set_apo_factory);
  814. #endif /* !CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK */
  815. static DEVICE_ATTR(chg_type, 0664, max77828_muic_show_charger_type, NULL);
  816. static DEVICE_ATTR(uart_sel, 0664, max77828_muic_show_uart_sel,
  817. max77828_muic_set_uart_sel);
  818. static DEVICE_ATTR(usb_state, S_IRUGO, max77828_muic_show_usb_state, NULL);
  819. static DEVICE_ATTR(device, S_IRUGO, max77828_muic_show_device, NULL);
  820. static DEVICE_ATTR(usb_sel, 0664,
  821. max77828_muic_show_manualsw, max77828_muic_set_manualsw);
  822. static DEVICE_ATTR(adc, S_IRUGO, max77828_muic_show_adc, NULL);
  823. static DEVICE_ATTR(audio_path, 0664,
  824. max77828_muic_show_audio_path, max77828_muic_set_audio_path);
  825. static DEVICE_ATTR(otg_test, 0664,
  826. max77828_muic_show_otg_test, max77828_muic_set_otg_test);
  827. static DEVICE_ATTR(adc_debounce_time, 0664,
  828. max77828_muic_show_adc_debounce_time,
  829. max77828_muic_set_adc_debounce_time);
  830. #if defined(CONFIG_MUIC_DET_JACK)
  831. static DEVICE_ATTR(key_state, 0664,
  832. key_state_onoff_show, NULL);
  833. static DEVICE_ATTR(state, 0664,
  834. earjack_state_onoff_show, NULL);
  835. #endif
  836. static struct attribute *max77828_muic_attributes[] = {
  837. &dev_attr_uart_sel.attr,
  838. &dev_attr_usb_state.attr,
  839. &dev_attr_device.attr,
  840. &dev_attr_usb_sel.attr,
  841. &dev_attr_adc.attr,
  842. &dev_attr_audio_path.attr,
  843. &dev_attr_otg_test.attr,
  844. &dev_attr_adc_debounce_time.attr,
  845. &dev_attr_chg_type.attr,
  846. #if !defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  847. &dev_attr_apo_factory.attr,
  848. #endif /* !CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK */
  849. NULL
  850. };
  851. static void max77828_muic_uart_uevent(int state)
  852. {
  853. #if !defined(CONFIG_MACH_MONTBLANC) && !defined(CONFIG_MACH_VIKALCU)
  854. if (switch_uart3.dev != NULL) {
  855. switch_set_state(&switch_uart3, state);
  856. dev_info(gInfo->dev, "%s: state:%d\n", __func__, state);
  857. }
  858. #endif
  859. }
  860. static const struct attribute_group max77828_muic_group = {
  861. .attrs = max77828_muic_attributes,
  862. };
  863. static int max77828_muic_set_usb_path(struct max77828_muic_info *info, int path)
  864. {
  865. struct i2c_client *client = info->muic;
  866. struct max77828_muic_data *mdata = info->muic_data;
  867. int ret;
  868. int gpio_val;
  869. u8 cntl1_val, cntl1_msk;
  870. int val;
  871. dev_info(info->dev, "func:%s path:%d, cable_type:%d\n", __func__, path, info->cable_type);
  872. if (mdata->set_safeout) {
  873. ret = mdata->set_safeout(path);
  874. if (ret) {
  875. dev_err(info->dev, "%s: fail to set safout!\n",
  876. __func__);
  877. return ret;
  878. }
  879. }
  880. switch (path) {
  881. case AP_USB_MODE:
  882. dev_info(info->dev, "%s: AP_USB_MODE\n", __func__);
  883. gpio_val = 0;
  884. val = MAX77828_MUIC_CTRL1_BIN_1_001;
  885. cntl1_val = (val << CTRL1_COMN1SW_SHIFT) | (val << CTRL1_COMP2SW_SHIFT);
  886. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  887. break;
  888. case AUDIO_MODE:
  889. dev_info(info->dev, "%s: AUDIO_MODE\n", __func__);
  890. gpio_val = 0;
  891. /* SL1, SR2 */
  892. cntl1_val = (MAX77828_MUIC_CTRL1_BIN_2_010 << CTRL1_COMN1SW_SHIFT)
  893. | (MAX77828_MUIC_CTRL1_BIN_2_010 << CTRL1_COMP2SW_SHIFT);
  894. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  895. break;
  896. case CP_USB_MODE:
  897. dev_info(info->dev, "%s: CP_USB_MODE\n", __func__);
  898. gpio_val = 1;
  899. val = MAX77828_MUIC_CTRL1_BIN_4_100;
  900. cntl1_val = (val << CTRL1_COMN1SW_SHIFT) | (val << CTRL1_COMP2SW_SHIFT);
  901. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  902. break;
  903. case OPEN_USB_MODE:
  904. dev_info(info->dev, "%s: OPEN_USB_MODE\n", __func__);
  905. gpio_val = 0;
  906. val = MAX77828_MUIC_CTRL1_BIN_0_000;
  907. cntl1_val = (val << CTRL1_COMN1SW_SHIFT) | (val << CTRL1_COMP2SW_SHIFT);
  908. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  909. break;
  910. default:
  911. dev_warn(info->dev, "%s: invalid path(%d)\n", __func__, path);
  912. return -EINVAL;
  913. }
  914. if (info->max77828->pmic_rev < MAX77828_REV_PASS2) {
  915. if (gpio_is_valid(info->muic_data->gpio_usb_sel))
  916. gpio_direction_output(mdata->gpio_usb_sel, gpio_val);
  917. }
  918. dev_info(info->dev, "%s: Set manual path\n", __func__);
  919. if (info->cable_type != CABLE_TYPE_CARDOCK_MUIC)
  920. max77828_update_reg(client, MAX77828_MUIC_REG_CTRL1, cntl1_val,
  921. cntl1_msk);
  922. max77828_update_reg(client, MAX77828_MUIC_REG_CTRL2,
  923. CTRL2_CPEn1_LOWPWD0,
  924. CTRL2_CPEn_MASK | CTRL2_LOWPWD_MASK);
  925. cntl1_val = MAX77828_MUIC_CTRL1_BIN_0_000;
  926. max77828_read_reg(client, MAX77828_MUIC_REG_CTRL1, &cntl1_val);
  927. dev_info(info->dev, "%s: CNTL1(0x%02x)\n", __func__, cntl1_val);
  928. cntl1_val = MAX77828_MUIC_CTRL1_BIN_0_000;
  929. max77828_read_reg(client, MAX77828_MUIC_REG_CTRL2, &cntl1_val);
  930. dev_info(info->dev, "%s: CNTL2(0x%02x)\n", __func__, cntl1_val);
  931. sysfs_notify(&switch_dev->kobj, NULL, "usb_sel");
  932. return 0;
  933. }
  934. int max77828_muic_get_charging_type(void)
  935. {
  936. if (gInfo)
  937. return gInfo->cable_type;
  938. else
  939. return CABLE_TYPE_NONE_MUIC;
  940. }
  941. #if defined(CONFIG_SEC_H_PROJECT) || defined (CONFIG_SEC_K_PROJECT)
  942. void max77828_muic_send_event(int val)
  943. {
  944. char *envp[2];
  945. if (val == 0)
  946. envp[0] = "USB_CONNECTION=READY";
  947. else
  948. envp[0] = "USB_CONNECTION=DISCONNECTED";
  949. envp[1] = NULL;
  950. dev_info(gInfo->dev, "%s\n", __func__);
  951. kobject_uevent_env(&gInfo->dev->kobj, KOBJ_CHANGE, envp);
  952. }
  953. #endif
  954. extern int system_rev;
  955. static int max77828_muic_set_charging_type(struct max77828_muic_info *info,
  956. bool force_disable)
  957. {
  958. struct max77828_muic_data *mdata = info->muic_data;
  959. int ret = 0;
  960. #if defined(CONFIG_MACH_HLTEVZW) || defined(CONFIG_MACH_HLTESPR) || defined(CONFIG_MACH_HLTEUSC)
  961. u8 val;
  962. #endif
  963. dev_info(info->dev, "func:%s force_disable:%d\n",
  964. __func__, force_disable);
  965. if (mdata->charger_cb) {
  966. if (force_disable) {
  967. #if defined(CONFIG_MACH_HLTEVZW) || defined(CONFIG_MACH_HLTESPR) || defined(CONFIG_MACH_HLTEUSC)
  968. if (system_rev == 6) {
  969. val = (0 << CTRL3_JIGSET_SHIFT);
  970. max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL3, val,
  971. CTRL3_JIGSET_MASK);
  972. }
  973. #endif
  974. ret = mdata->charger_cb(CABLE_TYPE_NONE_MUIC);
  975. } else {
  976. #if defined(CONFIG_MACH_HLTEVZW) || defined(CONFIG_MACH_HLTESPR) || defined(CONFIG_MACH_HLTEUSC)
  977. if (system_rev == 6) {
  978. val = (1 << CTRL3_JIGSET_SHIFT);
  979. max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL3, val,
  980. CTRL3_JIGSET_MASK);
  981. }
  982. #endif
  983. ret = mdata->charger_cb(info->cable_type);
  984. }
  985. }
  986. if (ret) {
  987. #if defined(CONFIG_MACH_HLTEVZW) || defined(CONFIG_MACH_HLTESPR) || defined(CONFIG_MACH_HLTEUSC)
  988. if (system_rev == 6) {
  989. val = (0 << CTRL3_JIGSET_SHIFT);
  990. max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL3, val,
  991. CTRL3_JIGSET_MASK);
  992. }
  993. #endif
  994. dev_err(info->dev, "%s: error from charger_cb(%d)\n", __func__,
  995. ret);
  996. return ret;
  997. }
  998. return 0;
  999. }
  1000. static int max77828_muic_handle_dock_vol_key(struct max77828_muic_info *info,
  1001. u8 status1)
  1002. {
  1003. struct input_dev *input = info->input;
  1004. int pre_key = info->previous_key;
  1005. unsigned int code;
  1006. int state;
  1007. u8 adc;
  1008. adc = status1 & STATUS1_ADC_MASK;
  1009. dev_info(info->dev,
  1010. "func:%s status1:%x adc:%x cable_type:%d\n",
  1011. __func__, status1, adc, info->cable_type);
  1012. if (info->cable_type != CABLE_TYPE_DESKDOCK_MUIC)
  1013. return 0;
  1014. if (adc == ADC_OPEN) {
  1015. switch (pre_key) {
  1016. case DOCK_KEY_VOL_UP_PRESSED:
  1017. code = KEY_VOLUMEUP;
  1018. state = 0;
  1019. info->previous_key = DOCK_KEY_VOL_UP_RELEASED;
  1020. break;
  1021. case DOCK_KEY_VOL_DOWN_PRESSED:
  1022. code = KEY_VOLUMEDOWN;
  1023. state = 0;
  1024. info->previous_key = DOCK_KEY_VOL_DOWN_RELEASED;
  1025. break;
  1026. case DOCK_KEY_PREV_PRESSED:
  1027. code = KEY_PREVIOUSSONG;
  1028. state = 0;
  1029. info->previous_key = DOCK_KEY_PREV_RELEASED;
  1030. break;
  1031. case DOCK_KEY_PLAY_PAUSE_PRESSED:
  1032. code = KEY_PLAYPAUSE;
  1033. state = 0;
  1034. info->previous_key = DOCK_KEY_PLAY_PAUSE_RELEASED;
  1035. break;
  1036. case DOCK_KEY_NEXT_PRESSED:
  1037. code = KEY_NEXTSONG;
  1038. state = 0;
  1039. info->previous_key = DOCK_KEY_NEXT_RELEASED;
  1040. break;
  1041. default:
  1042. return 0;
  1043. }
  1044. input_event(input, EV_KEY, code, state);
  1045. input_sync(input);
  1046. return 0;
  1047. }
  1048. if (pre_key == DOCK_KEY_NONE) {
  1049. /*
  1050. if (adc != ADC_DOCK_VOL_UP && adc != ADC_DOCK_VOL_DN && \
  1051. adc != ADC_DOCK_PREV_KEY && adc != ADC_DOCK_PLAY_PAUSE_KEY \
  1052. && adc != ADC_DOCK_NEXT_KEY)
  1053. */
  1054. if ((adc < 0x03) || (adc > 0x0d))
  1055. return 0;
  1056. }
  1057. dev_info(info->dev, "%s: dock vol key(%d)\n", __func__, pre_key);
  1058. switch (adc) {
  1059. case ADC_DOCK_VOL_UP:
  1060. code = KEY_VOLUMEUP;
  1061. state = 1;
  1062. info->previous_key = DOCK_KEY_VOL_UP_PRESSED;
  1063. break;
  1064. case ADC_DOCK_VOL_DN:
  1065. code = KEY_VOLUMEDOWN;
  1066. state = 1;
  1067. info->previous_key = DOCK_KEY_VOL_DOWN_PRESSED;
  1068. break;
  1069. case ADC_DOCK_PREV_KEY-1 ... ADC_DOCK_PREV_KEY+1:
  1070. code = KEY_PREVIOUSSONG;
  1071. state = 1;
  1072. info->previous_key = DOCK_KEY_PREV_PRESSED;
  1073. break;
  1074. case ADC_DOCK_PLAY_PAUSE_KEY-1 ... ADC_DOCK_PLAY_PAUSE_KEY+1:
  1075. code = KEY_PLAYPAUSE;
  1076. state = 1;
  1077. info->previous_key = DOCK_KEY_PLAY_PAUSE_PRESSED;
  1078. break;
  1079. case ADC_DOCK_NEXT_KEY-1 ... ADC_DOCK_NEXT_KEY+1:
  1080. code = KEY_NEXTSONG;
  1081. state = 1;
  1082. info->previous_key = DOCK_KEY_NEXT_PRESSED;
  1083. break;
  1084. case ADC_DESKDOCK: /* key release routine */
  1085. if (pre_key == DOCK_KEY_VOL_UP_PRESSED) {
  1086. code = KEY_VOLUMEUP;
  1087. state = 0;
  1088. info->previous_key = DOCK_KEY_VOL_UP_RELEASED;
  1089. } else if (pre_key == DOCK_KEY_VOL_DOWN_PRESSED) {
  1090. code = KEY_VOLUMEDOWN;
  1091. state = 0;
  1092. info->previous_key = DOCK_KEY_VOL_DOWN_RELEASED;
  1093. } else if (pre_key == DOCK_KEY_PREV_PRESSED) {
  1094. code = KEY_PREVIOUSSONG;
  1095. state = 0;
  1096. info->previous_key = DOCK_KEY_PREV_RELEASED;
  1097. } else if (pre_key == DOCK_KEY_PLAY_PAUSE_PRESSED) {
  1098. code = KEY_PLAYPAUSE;
  1099. state = 0;
  1100. info->previous_key = DOCK_KEY_PLAY_PAUSE_RELEASED;
  1101. } else if (pre_key == DOCK_KEY_NEXT_PRESSED) {
  1102. code = KEY_NEXTSONG;
  1103. state = 0;
  1104. info->previous_key = DOCK_KEY_NEXT_RELEASED;
  1105. } else {
  1106. dev_warn(info->dev, "%s:%d should not reach here\n",
  1107. __func__, __LINE__);
  1108. return 0;
  1109. }
  1110. break;
  1111. default:
  1112. dev_warn(info->dev, "%s: unsupported ADC(0x%02x)\n", __func__,
  1113. adc);
  1114. return 0;
  1115. }
  1116. input_event(input, EV_KEY, code, state);
  1117. input_sync(input);
  1118. return 1;
  1119. }
  1120. static int max77828_muic_attach_usb_type(struct max77828_muic_info *info,
  1121. int adc)
  1122. {
  1123. struct max77828_muic_data *mdata = info->muic_data;
  1124. int ret, path;
  1125. dev_info(info->dev, "func:%s adc:%x cable_type:%d\n",
  1126. __func__, adc, info->cable_type);
  1127. if (info->cable_type == CABLE_TYPE_MHL_MUIC
  1128. || info->cable_type == CABLE_TYPE_MHL_VB_MUIC) {
  1129. dev_warn(info->dev, "%s: mHL was attached!\n", __func__);
  1130. return 0;
  1131. }
  1132. switch (adc) {
  1133. case ADC_JIG_USB_OFF:
  1134. if (info->cable_type == CABLE_TYPE_JIG_USB_OFF_MUIC) {
  1135. dev_info(info->dev, "%s: duplicated(JIG USB OFF)\n",
  1136. __func__);
  1137. return 0;
  1138. }
  1139. dev_info(info->dev, "%s:JIG USB BOOTOFF\n", __func__);
  1140. info->cable_type = CABLE_TYPE_JIG_USB_OFF_MUIC;
  1141. path = AP_USB_MODE;
  1142. break;
  1143. case ADC_JIG_USB_ON:
  1144. if (info->cable_type == CABLE_TYPE_JIG_USB_ON_MUIC) {
  1145. dev_info(info->dev, "%s: duplicated(JIG USB ON)\n",
  1146. __func__);
  1147. return 0;
  1148. }
  1149. dev_info(info->dev, "%s:JIG USB BOOTON\n", __func__);
  1150. info->cable_type = CABLE_TYPE_JIG_USB_ON_MUIC;
  1151. path = AP_USB_MODE;
  1152. break;
  1153. case ADC_OPEN:
  1154. if (info->cable_type == CABLE_TYPE_USB_MUIC) {
  1155. dev_info(info->dev, "%s: duplicated(USB)\n", __func__);
  1156. return 0;
  1157. }
  1158. dev_info(info->dev, "%s:USB\n", __func__);
  1159. if (info->cable_type == CABLE_TYPE_CDP_MUIC)
  1160. info->cable_type = CABLE_TYPE_CDP_MUIC;
  1161. else
  1162. info->cable_type = CABLE_TYPE_USB_MUIC;
  1163. #if defined(CONFIG_SWITCH_DUAL_MODEM)
  1164. if (info->muic_data->sw_path == CP_USB_MODE)
  1165. path = CP_USB_MODE;
  1166. else
  1167. path = AP_USB_MODE;
  1168. dev_info(info->dev, "%s: usb path: %x\n", __func__, mdata->uart_path);
  1169. #else
  1170. path = AP_USB_MODE;
  1171. #endif
  1172. break;
  1173. default:
  1174. dev_info(info->dev, "%s: Unkown cable(0x%x)\n", __func__, adc);
  1175. return 0;
  1176. }
  1177. ret = max77828_muic_set_charging_type(info, false);
  1178. if (ret) {
  1179. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1180. return ret;
  1181. }
  1182. max77828_muic_set_usb_path(info, path);
  1183. if (path == AP_USB_MODE) {
  1184. if (mdata->usb_cb && info->is_usb_ready)
  1185. #ifdef CONFIG_USBHUB_USB3803
  1186. /* setting usb hub in Diagnostic(hub) mode */
  1187. usb3803_set_mode(USB_3803_MODE_HUB);
  1188. #endif /* CONFIG_USBHUB_USB3803 */
  1189. #if defined(CONFIG_SEC_H_PROJECT) || defined (CONFIG_SEC_K_PROJECT)
  1190. info->speaker_check_count = 0;
  1191. if (work_busy(&info->usb_connection_work.work)) {
  1192. cancel_delayed_work(&info->usb_connection_work);
  1193. pr_info("%s cancel_delayed_work \n",__func__);
  1194. }
  1195. max77828_muic_send_event (0); // USB Ready
  1196. schedule_delayed_work(&info->usb_connection_work, msecs_to_jiffies(1));
  1197. #else
  1198. mdata->usb_cb(USB_CABLE_ATTACHED);
  1199. #endif
  1200. }
  1201. return 0;
  1202. }
  1203. static int max77828_muic_attach_dock_type(struct max77828_muic_info *info,
  1204. int adc, int chgtyp)
  1205. {
  1206. struct max77828_muic_data *mdata = info->muic_data;
  1207. int path;
  1208. dev_info(info->dev, "func:%s adc:%x, open(%d)\n",
  1209. __func__, adc, info->is_adc_open_prev);
  1210. /*Workaround for unstable adc*/
  1211. if (info->is_adc_open_prev == false)
  1212. return 0;
  1213. switch (adc) {
  1214. case ADC_DESKDOCK:
  1215. /* Desk Dock */
  1216. if (info->cable_type == CABLE_TYPE_DESKDOCK_MUIC) {
  1217. dev_info(info->dev, "%s: duplicated(DeskDock)\n",
  1218. __func__);
  1219. return 0;
  1220. }
  1221. dev_info(info->dev, "%s:DeskDock\n", __func__);
  1222. info->cable_type = CABLE_TYPE_DESKDOCK_MUIC;
  1223. path = AUDIO_MODE;
  1224. if (mdata->dock_cb)
  1225. mdata->dock_cb(MAX77828_MUIC_DOCK_DESKDOCK);
  1226. break;
  1227. case ADC_CARDOCK:
  1228. /* Car Dock */
  1229. if (info->cable_type == CABLE_TYPE_CARDOCK_MUIC) {
  1230. dev_info(info->dev, "%s: duplicated(CarDock)\n",
  1231. __func__);
  1232. return 0;
  1233. }
  1234. dev_info(info->dev, "%s:CarDock\n", __func__);
  1235. info->cable_type = CABLE_TYPE_CARDOCK_MUIC;
  1236. path = AUDIO_MODE;
  1237. is_cardock = 1;
  1238. if (mdata->dock_cb)
  1239. mdata->dock_cb(MAX77828_MUIC_DOCK_CARDOCK);
  1240. break;
  1241. case ADC_AUDIODOCK:
  1242. /* Audio Dock */
  1243. if (info->cable_type == CABLE_TYPE_AUDIODOCK_MUIC) {
  1244. dev_info(info->dev, "%s: duplicated(AudioDock)\n",
  1245. __func__);
  1246. return 0;
  1247. }
  1248. dev_info(info->dev, "%s:AudioDock\n", __func__);
  1249. info->cable_type = CABLE_TYPE_AUDIODOCK_MUIC;
  1250. if (info->is_usb_ready) {
  1251. pr_info("%s:%s usb is ready, D+,D- line(AP_USB)\n",
  1252. DEV_NAME, __func__);
  1253. path = AP_USB_MODE;
  1254. } else {
  1255. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  1256. DEV_NAME, __func__);
  1257. path = OPEN_USB_MODE;
  1258. }
  1259. msleep(40);
  1260. max77828_muic_set_charging_type(info, false);
  1261. if (mdata->usb_cb && info->is_usb_ready)
  1262. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1263. if (mdata->dock_cb)
  1264. mdata->dock_cb(MAX77828_MUIC_DOCK_AUDIODOCK);
  1265. break;
  1266. case ADC_HMT:
  1267. if (info->cable_type == CABLE_TYPE_HMT_MUIC
  1268. || info->cable_type == CABLE_TYPE_HMT_TA_MUIC) {
  1269. dev_info(info->dev, "%s: duplicated(HMT)\n",
  1270. __func__);
  1271. return 0;
  1272. }
  1273. dev_info(info->dev, "%s:HMT\n", __func__);
  1274. if (info->is_usb_ready) {
  1275. pr_info("%s:%s usb is ready, D+,D- line(AP_USB)\n",
  1276. DEV_NAME, __func__);
  1277. path = AP_USB_MODE;
  1278. } else {
  1279. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  1280. DEV_NAME, __func__);
  1281. path = OPEN_USB_MODE;
  1282. }
  1283. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1284. info->cable_type = CABLE_TYPE_HMT_TA_MUIC;
  1285. } else {
  1286. info->cable_type = CABLE_TYPE_HMT_MUIC;
  1287. }
  1288. max77828_muic_set_charging_type(info, false);
  1289. msleep(40);
  1290. if (mdata->dock_cb)
  1291. mdata->dock_cb(MAX77828_MUIC_DOCK_HMT);
  1292. break;
  1293. case ADC_SMARTDOCK:
  1294. /* Smart Dock */
  1295. if (info->cable_type == CABLE_TYPE_SMARTDOCK_MUIC
  1296. || info->cable_type == CABLE_TYPE_SMARTDOCK_TA_MUIC
  1297. || info->cable_type == CABLE_TYPE_SMARTDOCK_USB_MUIC) {
  1298. dev_info(info->dev, "%s: duplicated(SmartDock)\n",
  1299. __func__);
  1300. return 0;
  1301. }
  1302. dev_info(info->dev, "%s:SmartDock\n", __func__);
  1303. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1304. info->cable_type = CABLE_TYPE_SMARTDOCK_TA_MUIC;
  1305. } else if (chgtyp == CHGTYP_USB) {
  1306. info->cable_type = CABLE_TYPE_SMARTDOCK_USB_MUIC;
  1307. } else {
  1308. info->cable_type = CABLE_TYPE_SMARTDOCK_MUIC;
  1309. }
  1310. if (info->is_usb_ready) {
  1311. pr_info("%s:%s usb is ready, D+,D- line(AP_USB)\n",
  1312. DEV_NAME, __func__);
  1313. path = AP_USB_MODE;
  1314. } else {
  1315. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  1316. DEV_NAME, __func__);
  1317. path = OPEN_USB_MODE;
  1318. }
  1319. max77828_muic_set_charging_type(info, false);
  1320. msleep(40);
  1321. if (mdata->mhl_cb && info->is_mhl_ready)
  1322. mdata->mhl_cb(MAX77828_MUIC_ATTACHED);
  1323. if (mdata->dock_cb)
  1324. mdata->dock_cb(MAX77828_MUIC_DOCK_SMARTDOCK);
  1325. break;
  1326. default:
  1327. dev_info(info->dev, "%s: should not reach here(0x%x)\n",
  1328. __func__, adc);
  1329. return 0;
  1330. }
  1331. max77828_muic_set_usb_path(info, path);
  1332. return 0;
  1333. }
  1334. static void max77828_muic_attach_mhl(struct max77828_muic_info *info, u8 chgtyp)
  1335. {
  1336. struct max77828_muic_data *mdata = info->muic_data;
  1337. dev_info(info->dev, "func:%s chgtyp:%x\n", __func__, chgtyp);
  1338. if (info->cable_type == CABLE_TYPE_USB_MUIC) {
  1339. if (mdata->usb_cb && info->is_usb_ready)
  1340. mdata->usb_cb(USB_CABLE_DETACHED);
  1341. max77828_muic_set_charging_type(info, true);
  1342. }
  1343. info->cable_type = CABLE_TYPE_MHL_MUIC;
  1344. if (mdata->mhl_cb && info->is_mhl_ready)
  1345. mdata->mhl_cb(MAX77828_MUIC_ATTACHED);
  1346. if (chgtyp == CHGTYP_USB) {
  1347. info->cable_type = CABLE_TYPE_MHL_VB_MUIC;
  1348. max77828_muic_set_charging_type(info, false);
  1349. }
  1350. }
  1351. #if defined(CONFIG_MUIC_DET_JACK)
  1352. static void max77828_muic_earjack_detect_workfunc(struct work_struct *work)
  1353. {
  1354. struct max77828_muic_info *info = container_of(work, struct max77828_muic_info, earjack_work);
  1355. #if defined(CONFIG_MACH_MONTBLANC) || defined(CONFIG_MACH_VIKALCU)
  1356. int ret;
  1357. static struct regulator *reg_l17;
  1358. #endif
  1359. dev_info(info->dev, "%s:EarJack Work eardetacted= %d\n", __func__, info->eardetacted);
  1360. #if defined(CONFIG_MACH_MONTBLANC) || defined(CONFIG_MACH_VIKALCU)
  1361. if (!reg_l17) {
  1362. reg_l17 = regulator_get(NULL, "8941_l17");
  1363. ret = regulator_set_voltage(reg_l17, 3000000, 3000000);
  1364. if (IS_ERR(reg_l17)) {
  1365. printk(KERN_ERR"could not get 8941_l17, rc = %ld\n", PTR_ERR(reg_l17));
  1366. return;
  1367. }
  1368. }
  1369. if(info->eardetacted) {
  1370. ret = regulator_enable(reg_l17);
  1371. if (ret) {
  1372. printk(KERN_ERR"enable l17 failed, rc=%d\n", ret);
  1373. return;
  1374. }
  1375. }
  1376. else {
  1377. if (regulator_is_enabled(reg_l17)) {
  1378. ret = regulator_disable(reg_l17);
  1379. if (ret) {
  1380. printk(KERN_ERR"disable l17 failed, rc=%d\n", ret);
  1381. return;
  1382. }
  1383. }
  1384. }
  1385. #endif
  1386. /* send event jack type to upper layer */
  1387. switch_set_state(&switch_earjack, info->eardetacted);
  1388. return;
  1389. }
  1390. static int max77828_muic_earjack_detect(struct max77828_muic_info *info, bool attached)
  1391. {
  1392. dev_info(info->dev, "%s:EarJack attached= %d\n", __func__,attached);
  1393. if (info->init_detect_done == NOT_INIT) {
  1394. return 0;
  1395. }
  1396. if (info->cable_type == CABLE_TYPE_EARJACK_MUIC) {
  1397. dev_info(info->dev, "%s: duplicated(EarJack)\n", __func__);
  1398. return 0;
  1399. }
  1400. if(attached) {
  1401. info->eardetacted = true;
  1402. }
  1403. else {
  1404. info->eardetacted = false;
  1405. }
  1406. #if defined(CONFIG_MACH_MONTBLANC) || defined(CONFIG_MACH_VIKALCU)
  1407. gEarDetected = info->eardetacted;
  1408. #endif
  1409. schedule_work(&info->earjack_work);
  1410. max77828_muic_set_audio_path_pass2(info, 0);
  1411. return 0;
  1412. }
  1413. static void max77828_muic_earjack_key_detect_workfunc(struct work_struct *work)
  1414. {
  1415. struct max77828_muic_info *info = container_of(work, struct max77828_muic_info, earjackkey_work);
  1416. dev_info(info->dev, "%s:EarJackKey Work earkeypressed= %d\n", __func__, info->earkeypressed);
  1417. /* send event sendend key type to upper layer */
  1418. switch_set_state(&switch_earjackkey, info->earkeypressed);
  1419. return;
  1420. }
  1421. static int max77828_muic_earjack_key_detect(struct max77828_muic_info *info, int adc)
  1422. {
  1423. unsigned int code;
  1424. dev_info(info->dev, "%s:EarJackKey\n", __func__);
  1425. if (info->earkeypressed) {
  1426. switch (adc) {
  1427. case ADC_MHL_OR_SENDEND:
  1428. code = KEY_MEDIA;
  1429. info->old_keycode = KEY_MEDIA;
  1430. break;
  1431. case ADC_DOCK_VOL_UP:
  1432. code = KEY_VOLUMEUP;
  1433. info->old_keycode = KEY_VOLUMEUP;
  1434. break;
  1435. case ADC_DOCK_VOL_DN:
  1436. code = KEY_VOLUMEDOWN;
  1437. info->old_keycode = KEY_VOLUMEDOWN;
  1438. break;
  1439. default:
  1440. dev_info(info->dev, "%s: should not reach here(0x%x)\n", __func__, adc);
  1441. return 0;
  1442. }
  1443. info->keycode = code;
  1444. }
  1445. else {
  1446. code = info->old_keycode;
  1447. }
  1448. /* send event sendend key type to upper layer */
  1449. input_event(info->input, EV_KEY, code, info->earkeypressed);
  1450. input_sync(info->input);
  1451. schedule_work(&info->earjackkey_work);
  1452. return 0;
  1453. }
  1454. #endif
  1455. static void max77828_muic_handle_jig_uart(struct max77828_muic_info *info,
  1456. u8 vbvolt)
  1457. {
  1458. struct max77828_muic_data *mdata = info->muic_data;
  1459. enum cable_type_muic prev_ct = info->cable_type;
  1460. bool is_otgtest = false;
  1461. u8 cntl1_val, cntl1_msk;
  1462. u8 val = MAX77828_MUIC_CTRL1_BIN_3_011;
  1463. dev_info(info->dev, "func:%s vbvolt:%x cable_type:%d\n",
  1464. __func__, vbvolt, info->cable_type);
  1465. dev_info(info->dev, "%s: JIG UART/BOOTOFF(0x%x)\n", __func__, vbvolt);
  1466. #if defined(CONFIG_SWITCH_DUAL_MODEM)
  1467. dev_info(info->dev, "%s: uart_path : %x\n", __func__, mdata->uart_path);
  1468. if (mdata->uart_path == UART_PATH_AP)
  1469. val = MAX77828_MUIC_CTRL1_BIN_3_011;
  1470. else if (mdata->uart_path == UART_PATH_CP)
  1471. val = MAX77828_MUIC_CTRL1_BIN_5_101;
  1472. else
  1473. val = MAX77828_MUIC_CTRL1_BIN_3_011;
  1474. #else
  1475. val = MAX77828_MUIC_CTRL1_BIN_3_011;
  1476. #endif
  1477. cntl1_val = (val << CTRL1_COMN1SW_SHIFT) | (val << CTRL1_COMP2SW_SHIFT);
  1478. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  1479. max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL1, cntl1_val,
  1480. cntl1_msk);
  1481. max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL2,
  1482. CTRL2_CPEn1_LOWPWD0,
  1483. CTRL2_CPEn_MASK | CTRL2_LOWPWD_MASK);
  1484. if (vbvolt & STATUS2_VBVOLT_MASK) {
  1485. if (mdata->host_notify_cb) {
  1486. int mode = mdata->host_notify_cb(1);
  1487. if (mode == NOTIFY_TEST_MODE ||
  1488. mode == NOTIFY_HOST_MODE) {
  1489. is_otgtest = true;
  1490. dev_info(info->dev, "%s: OTG TEST\n", __func__);
  1491. }
  1492. }
  1493. info->cable_type = CABLE_TYPE_JIG_UART_OFF_VB_MUIC;
  1494. max77828_muic_set_charging_type(info, is_otgtest);
  1495. } else {
  1496. info->cable_type = CABLE_TYPE_JIG_UART_OFF_MUIC;
  1497. if (prev_ct == CABLE_TYPE_JIG_UART_OFF_VB_MUIC) {
  1498. max77828_muic_set_charging_type(info, false);
  1499. if (mdata->host_notify_cb)
  1500. mdata->host_notify_cb(0);
  1501. }
  1502. }
  1503. }
  1504. void max77828_otg_control(struct max77828_muic_info *info, int enable)
  1505. {
  1506. #if 0
  1507. u8 int_mask, cdetctrl1, chg_cnfg_00;
  1508. pr_info("%s: enable(%d)\n", __func__, enable);
  1509. if (enable) {
  1510. /* disable charger interrupt */
  1511. max77828_read_reg(info->max77828->i2c,
  1512. MAX77828_CHG_REG_CHG_INT_MASK, &int_mask);
  1513. chg_int_state = int_mask;
  1514. int_mask |= (1 << 4); /* disable chgin intr */
  1515. int_mask |= (1 << 6); /* disable chg */
  1516. int_mask &= ~(1 << 0); /* enable byp intr */
  1517. max77828_write_reg(info->max77828->i2c,
  1518. MAX77828_CHG_REG_CHG_INT_MASK, int_mask);
  1519. /* disable charger detection */
  1520. max77828_read_reg(info->max77828->muic,
  1521. MAX77828_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1522. cdetctrl1 &= ~(1 << 0);
  1523. max77828_write_reg(info->max77828->muic,
  1524. MAX77828_MUIC_REG_CDETCTRL1, cdetctrl1);
  1525. /* OTG on, boost on, DIS_MUIC_CTRL=1 */
  1526. max77828_read_reg(info->max77828->i2c,
  1527. MAX77828_CHG_REG_CHG_CNFG_00, &chg_cnfg_00);
  1528. chg_cnfg_00 &= ~(CHG_CNFG_00_OTG_MASK
  1529. | CHG_CNFG_00_BOOST_MASK
  1530. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
  1531. chg_cnfg_00 |= (CHG_CNFG_00_OTG_MASK
  1532. | CHG_CNFG_00_BOOST_MASK
  1533. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
  1534. max77828_write_reg(info->max77828->i2c,
  1535. MAX77828_CHG_REG_CHG_CNFG_00, chg_cnfg_00);
  1536. /* Update CHG_CNFG_11 to 0x50(5V) */
  1537. max77828_write_reg(info->max77828->i2c,
  1538. MAX77828_CHG_REG_CHG_CNFG_11, 0x50);
  1539. } else {
  1540. /* OTG off, boost off, (buck on),
  1541. DIS_MUIC_CTRL = 0 unless CHG_ENA = 1 */
  1542. max77828_read_reg(info->max77828->i2c,
  1543. MAX77828_CHG_REG_CHG_CNFG_00, &chg_cnfg_00);
  1544. chg_cnfg_00 &= ~(CHG_CNFG_00_OTG_MASK
  1545. | CHG_CNFG_00_BOOST_MASK
  1546. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
  1547. chg_cnfg_00 |= CHG_CNFG_00_BUCK_MASK;
  1548. max77828_write_reg(info->max77828->i2c,
  1549. MAX77828_CHG_REG_CHG_CNFG_00, chg_cnfg_00);
  1550. /* Update CHG_CNFG_11 to 0x00(3V) */
  1551. max77828_write_reg(info->max77828->i2c,
  1552. MAX77828_CHG_REG_CHG_CNFG_11, 0x00);
  1553. mdelay(50);
  1554. #if defined(CONFIG_MACH_HLTEEUR) || defined(CONFIG_MACH_HLTEATT) \
  1555. || defined(CONFIG_MACH_HLTETMO) || defined(CONFIG_MACH_HLTEVZW) \
  1556. || defined(CONFIG_MACH_HLTESPR) || defined(CONFIG_MACH_HLTEUSC) \
  1557. || defined(CONFIG_MACH_HLTESKT) || defined(CONFIG_MACH_HLTEKTT) \
  1558. || defined(CONFIG_MACH_HLTELGT) || defined(CONFIG_MACH_FLTESKT) \
  1559. || defined(CONFIG_MACH_FLTEKTT) || defined(CONFIG_MACH_FLTELGT) \
  1560. || defined(CONFIG_MACH_H3GDUOS_CTC) || defined(CONFIG_MACH_LT03SKT) \
  1561. || defined(CONFIG_MACH_LT03KTT) || defined(CONFIG_MACH_LT03LGT)
  1562. /* [MAX77804] Workaround to get rid of reading dummy(0x00) */
  1563. /* disable charger detection again */
  1564. max77828_read_reg(info->max77828->muic,
  1565. MAX77828_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1566. cdetctrl1 &= ~(1 << 0);
  1567. max77828_write_reg(info->max77828->muic,
  1568. MAX77828_MUIC_REG_CDETCTRL1, cdetctrl1);
  1569. mdelay(10);
  1570. #endif
  1571. /* enable charger detection */
  1572. max77828_read_reg(info->max77828->muic,
  1573. MAX77828_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1574. cdetctrl1 |= (1 << 0);
  1575. max77828_write_reg(info->max77828->muic,
  1576. MAX77828_MUIC_REG_CDETCTRL1, cdetctrl1);
  1577. /* enable charger interrupt */
  1578. max77828_write_reg(info->max77828->i2c,
  1579. MAX77828_CHG_REG_CHG_INT_MASK, chg_int_state);
  1580. max77828_read_reg(info->max77828->i2c,
  1581. MAX77828_CHG_REG_CHG_INT_MASK, &int_mask);
  1582. }
  1583. pr_info("%s: INT_MASK(0x%x), CDETCTRL1(0x%x), CHG_CNFG_00(0x%x)\n",
  1584. __func__, int_mask, cdetctrl1, chg_cnfg_00);
  1585. #endif
  1586. }
  1587. void max77828_powered_otg_control(struct max77828_muic_info *info, int enable)
  1588. {
  1589. #if 0
  1590. pr_info("%s: enable(%d)\n", __func__, enable);
  1591. if (enable) {
  1592. /* OTG on, boost on */
  1593. max77828_write_reg(info->max77828->i2c,
  1594. MAX77828_CHG_REG_CHG_CNFG_00, 0x05);
  1595. max77828_write_reg(info->max77828->i2c,
  1596. MAX77828_CHG_REG_CHG_CNFG_02, 0x0E);
  1597. /* Update CHG_CNFG_11 to 0x50(5V) */
  1598. max77828_write_reg(info->max77828->i2c,
  1599. MAX77828_CHG_REG_CHG_CNFG_11, 0x50);
  1600. } else {
  1601. /* OTG off, boost off, (buck on) */
  1602. max77828_write_reg(info->max77828->i2c,
  1603. MAX77828_CHG_REG_CHG_CNFG_00, 0x04);
  1604. /* Update CHG_CNFG_11 to 0x00(3V) */
  1605. max77828_write_reg(info->max77828->i2c,
  1606. MAX77828_CHG_REG_CHG_CNFG_11, 0x00);
  1607. }
  1608. #endif
  1609. }
  1610. /* use in mach for otg */
  1611. int muic_otg_control(int enable)
  1612. {
  1613. pr_debug("%s: enable(%d)\n", __func__, enable);
  1614. max77828_otg_control(gInfo, enable);
  1615. return 0;
  1616. }
  1617. /* use in mach for powered-otg */
  1618. void powered_otg_control(int enable)
  1619. {
  1620. pr_debug("%s: enable(%d)\n", __func__, enable);
  1621. max77828_powered_otg_control(gInfo, enable);
  1622. }
  1623. static void max77828_muic_set_cddelay(struct max77828_muic_info *info)
  1624. {
  1625. u8 cdetctrl1;
  1626. int ret;
  1627. ret = max77828_read_reg(info->max77828->muic,
  1628. MAX77828_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1629. pr_info("%s:%s read CDETCTRL1=0x%x, ret=%d\n", DEV_NAME, __func__,
  1630. cdetctrl1, ret);
  1631. if ((cdetctrl1 & 0x10) == 0x10) {
  1632. pr_info("%s:%s CDDelay already setted, return\n", DEV_NAME,
  1633. __func__);
  1634. return;
  1635. }
  1636. cdetctrl1 |= 0x10;
  1637. ret = max77828_write_reg(info->max77828->muic,
  1638. MAX77828_MUIC_REG_CDETCTRL1, cdetctrl1);
  1639. pr_info("%s:%s write CDETCTRL1=0x%x, ret=%d\n", DEV_NAME,
  1640. __func__, cdetctrl1, ret);
  1641. }
  1642. static void max77828_muic_clear_cddelay(struct max77828_muic_info *info)
  1643. {
  1644. u8 cdetctrl1;
  1645. int ret;
  1646. ret = max77828_read_reg(info->max77828->muic,
  1647. MAX77828_MUIC_REG_CDETCTRL1, &cdetctrl1);
  1648. pr_info("%s:%s read CDETCTRL1=0x%x, ret=%d\n", DEV_NAME, __func__,
  1649. cdetctrl1, ret);
  1650. if ((cdetctrl1 & 0x10) == 0x0) {
  1651. pr_info("%s:%s CDDelay already cleared, return\n", DEV_NAME,
  1652. __func__);
  1653. return;
  1654. }
  1655. cdetctrl1 &= ~(0x10);
  1656. ret = max77828_write_reg(info->max77828->muic,
  1657. MAX77828_MUIC_REG_CDETCTRL1, cdetctrl1);
  1658. pr_info("%s:%s write CDETCTRL1=0x%x, ret=%d\n", DEV_NAME,
  1659. __func__, cdetctrl1, ret);
  1660. }
  1661. static void max77828_muic_detach_smart_dock(struct max77828_muic_info *info)
  1662. {
  1663. struct max77828_muic_data *mdata = info->muic_data;
  1664. enum cable_type_muic tmp_cable_type = info->cable_type;
  1665. pr_info("%s:%s\n", DEV_NAME, __func__);
  1666. if (info->cable_type != CABLE_TYPE_SMARTDOCK_MUIC &&
  1667. info->cable_type != CABLE_TYPE_SMARTDOCK_TA_MUIC &&
  1668. info->cable_type != CABLE_TYPE_SMARTDOCK_USB_MUIC) {
  1669. pr_info("%s:%s cable_type is not SMARTDOCK\n", DEV_NAME,
  1670. __func__);
  1671. return;
  1672. }
  1673. if (mdata->dock_cb)
  1674. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  1675. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1676. max77828_muic_set_charging_type(info, false);
  1677. #ifdef CONFIG_EXTCON
  1678. if (info->edev && info->is_mhl_ready)
  1679. extcon_set_cable_state(info->edev, "MHL", false);
  1680. #else
  1681. if (mdata->mhl_cb && info->is_mhl_ready)
  1682. mdata->mhl_cb(MAX77828_MUIC_DETACHED);
  1683. #endif
  1684. switch (tmp_cable_type) {
  1685. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1686. pr_info("%s:%s SMARTDOCK+TA\n", DEV_NAME, __func__);
  1687. if (mdata->usb_cb && info->is_usb_ready)
  1688. mdata->usb_cb(USB_POWERED_HOST_DETACHED);
  1689. break;
  1690. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1691. pr_info("%s:%s SMARTDOCK+USB\n", DEV_NAME, __func__);
  1692. if (mdata->usb_cb && info->is_usb_ready)
  1693. mdata->usb_cb(USB_CABLE_DETACHED);
  1694. break;
  1695. case CABLE_TYPE_SMARTDOCK_MUIC:
  1696. /* clear CDDelay 500ms */
  1697. max77828_muic_clear_cddelay(info);
  1698. pr_info("%s:%s SMARTDOCK\n", DEV_NAME, __func__);
  1699. break;
  1700. default:
  1701. pr_warn("%s:%s should not reach here!\n", DEV_NAME,
  1702. __func__);
  1703. return;
  1704. break;
  1705. }
  1706. }
  1707. static void max77828_muic_attach_smart_dock(struct max77828_muic_info *info,
  1708. u8 adc, u8 vbvolt, u8 chgtyp)
  1709. {
  1710. struct max77828_muic_data *mdata = info->muic_data;
  1711. switch (info->cable_type) {
  1712. case CABLE_TYPE_SMARTDOCK_MUIC:
  1713. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1714. /* clear CDDelay 500ms */
  1715. max77828_muic_clear_cddelay(info);
  1716. pr_info("%s:%s SMART_DOCK+TA=OTG Enable\n", DEV_NAME,
  1717. __func__);
  1718. if (mdata->usb_cb && info->is_usb_ready)
  1719. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1720. info->cable_type = CABLE_TYPE_SMARTDOCK_TA_MUIC;
  1721. } else if (chgtyp == CHGTYP_USB) {
  1722. /* clear CDDelay 500ms */
  1723. max77828_muic_clear_cddelay(info);
  1724. pr_info("%s:%s SMART_DOCK+USB=USB Enable\n", DEV_NAME,
  1725. __func__);
  1726. if (mdata->usb_cb && info->is_usb_ready)
  1727. mdata->usb_cb(USB_CABLE_ATTACHED);
  1728. info->cable_type = CABLE_TYPE_SMARTDOCK_USB_MUIC;
  1729. } else
  1730. pr_info("%s:%s SMART_DOCK + [%d] = ?\n", DEV_NAME,
  1731. __func__, chgtyp);
  1732. break;
  1733. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1734. if (chgtyp == CHGTYP_DEDICATED_CHGR)
  1735. pr_info("%s:%s Duplicated(SMARTDOCK+TA)\n", DEV_NAME,
  1736. __func__);
  1737. else if (vbvolt)
  1738. pr_info("%s:%s SMART_DOCK + TA -> chgtyp:%x\n",
  1739. DEV_NAME, __func__, chgtyp);
  1740. else
  1741. max77828_muic_detach_smart_dock(info);
  1742. break;
  1743. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1744. if (chgtyp == CHGTYP_USB)
  1745. pr_info("%s:%s Duplicated(SMARTDOCK+USB)\n", DEV_NAME,
  1746. __func__);
  1747. else if (vbvolt)
  1748. pr_info("%s:%s SMART_DOCK + USB -> chgtyp:%x\n",
  1749. DEV_NAME, __func__, chgtyp);
  1750. else
  1751. max77828_muic_detach_smart_dock(info);
  1752. break;
  1753. default:
  1754. if (vbvolt) {
  1755. pr_info("%s:%s SMART_DOCK+vbvolt=chgdetrun\n",
  1756. DEV_NAME, __func__);
  1757. if (chgtyp == 0) {
  1758. pr_info("%s:%s SMART_DOCK + [%d] = ?? end\n", DEV_NAME,
  1759. __func__, chgtyp);
  1760. return;
  1761. }
  1762. max77828_muic_attach_dock_type(info, adc, chgtyp);
  1763. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1764. /* clear CDDelay 500ms */
  1765. max77828_muic_clear_cddelay(info);
  1766. pr_info("%s:%s SMART_DOCK+TA=OTG Enable\n", DEV_NAME,
  1767. __func__);
  1768. if (mdata->usb_cb && info->is_usb_ready)
  1769. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1770. } else if (chgtyp == CHGTYP_USB) {
  1771. /* clear CDDelay 500ms */
  1772. max77828_muic_clear_cddelay(info);
  1773. pr_info("%s:%s SMART_DOCK+USB=USB Enable\n", DEV_NAME,
  1774. __func__);
  1775. if (mdata->usb_cb && info->is_usb_ready)
  1776. mdata->usb_cb(USB_CABLE_ATTACHED);
  1777. }
  1778. } else {
  1779. /* set CDDelay 500ms */
  1780. max77828_muic_set_cddelay(info);
  1781. dev_warn(info->dev, "no vbus in SAMRTDOCK\n");
  1782. }
  1783. break;
  1784. }
  1785. }
  1786. static void max77828_muic_detach_hmt(struct max77828_muic_info *info)
  1787. {
  1788. struct max77828_muic_data *mdata = info->muic_data;
  1789. enum cable_type_muic tmp_cable_type = info->cable_type;
  1790. pr_info("%s:%s\n", DEV_NAME, __func__);
  1791. if (info->cable_type != CABLE_TYPE_HMT_MUIC &&
  1792. info->cable_type != CABLE_TYPE_HMT_TA_MUIC) {
  1793. pr_info("%s:%s cable_type is not HMT\n", DEV_NAME,
  1794. __func__);
  1795. return;
  1796. }
  1797. if (mdata->dock_cb)
  1798. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  1799. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1800. max77828_muic_set_charging_type(info, false);
  1801. switch (tmp_cable_type) {
  1802. case CABLE_TYPE_HMT_TA_MUIC:
  1803. pr_info("%s:%s HMT+TA\n", DEV_NAME, __func__);
  1804. if (mdata->usb_cb && info->is_usb_ready)
  1805. mdata->usb_cb(USB_POWERED_HOST_DETACHED);
  1806. break;
  1807. case CABLE_TYPE_HMT_MUIC:
  1808. pr_info("%s:%s HMT\n", DEV_NAME, __func__);
  1809. if (mdata->usb_cb && info->is_usb_ready)
  1810. mdata->usb_cb(USB_OTGHOST_DETACHED);
  1811. break;
  1812. default:
  1813. pr_warn("%s:%s should not reach here!\n", DEV_NAME,
  1814. __func__);
  1815. if(mdata->usb_cb && info->is_usb_ready)
  1816. mdata->usb_cb(USB_OTGHOST_DETACHED);
  1817. break;
  1818. }
  1819. }
  1820. static void max77828_muic_attach_hmt(struct max77828_muic_info *info,
  1821. u8 adc, u8 vbvolt, u8 chgtyp)
  1822. {
  1823. struct max77828_muic_data *mdata = info->muic_data;
  1824. pr_info("%s:%s Attached HMT adc(0x%x), vbvolt(0x%x), chgtyp(0x%x)",
  1825. DEV_NAME, __func__, adc, vbvolt, chgtyp);
  1826. switch (info->cable_type) {
  1827. case CABLE_TYPE_HMT_MUIC:
  1828. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1829. pr_info("%s:%s HMT+TA=OTG Enable\n", DEV_NAME,
  1830. __func__);
  1831. if (mdata->usb_cb && info->is_usb_ready)
  1832. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1833. info->cable_type = CABLE_TYPE_HMT_TA_MUIC;
  1834. } else {
  1835. pr_info("%s:%s HMT + [%d] = ?\n", DEV_NAME,
  1836. __func__, chgtyp);
  1837. }
  1838. break;
  1839. case CABLE_TYPE_HMT_TA_MUIC:
  1840. if (chgtyp == CHGTYP_DEDICATED_CHGR)
  1841. pr_info("%s:%s Duplicated(HMT+TA)\n", DEV_NAME,
  1842. __func__);
  1843. else if (vbvolt)
  1844. pr_info("%s:%s HMT + TA -> chgtyp:%x\n",
  1845. DEV_NAME, __func__, chgtyp);
  1846. else
  1847. max77828_muic_detach_hmt(info);
  1848. break;
  1849. default:
  1850. if (vbvolt) {
  1851. pr_info("%s:%s HMT+vbvolt=chgdetrun\n",
  1852. DEV_NAME, __func__);
  1853. if (chgtyp == 0) {
  1854. pr_info("%s:%s HMT + [%d] = ?? end\n", DEV_NAME,
  1855. __func__, chgtyp);
  1856. return;
  1857. }
  1858. info->cable_type = CABLE_TYPE_HMT_TA_MUIC;
  1859. max77828_muic_attach_dock_type(info, adc, chgtyp);
  1860. if (chgtyp == CHGTYP_DEDICATED_CHGR) {
  1861. pr_info("%s:%s HMT+TA=OTG Enable\n", DEV_NAME,
  1862. __func__);
  1863. if (mdata->usb_cb && info->is_usb_ready)
  1864. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  1865. }
  1866. } else {
  1867. pr_info("%s:%s, No vbus in HMT\n", DEV_NAME, __func__);
  1868. max77828_muic_attach_dock_type(info, adc, chgtyp);
  1869. if(mdata->usb_cb && info->is_usb_ready)
  1870. mdata->usb_cb(USB_OTGHOST_ATTACHED);
  1871. }
  1872. break;
  1873. }
  1874. }
  1875. static int max77828_muic_handle_attach(struct max77828_muic_info *info,
  1876. u8 status1, u8 status2, int irq)
  1877. {
  1878. struct max77828_muic_data *mdata = info->muic_data;
  1879. u8 adc, vbvolt, chgtyp, chgdetrun, adc1k;
  1880. int ret = 0;
  1881. adc = status1 & STATUS1_ADC_MASK;
  1882. adc1k = status1 & STATUS1_ADC1K_MASK;
  1883. chgtyp = status2 & STATUS2_CHGTYP_MASK;
  1884. vbvolt = status2 & STATUS2_VBVOLT_MASK;
  1885. chgdetrun = status2 & STATUS2_CHGDETRUN_MASK;
  1886. dev_info(info->dev, "func:%s st1:%x st2:%x cable_type:%d\n",
  1887. __func__, status1, status2, info->cable_type);
  1888. switch (info->cable_type) {
  1889. case CABLE_TYPE_JIG_UART_OFF_MUIC:
  1890. case CABLE_TYPE_JIG_UART_OFF_VB_MUIC:
  1891. /* Workaround for Factory mode.
  1892. * Abandon adc interrupt of approximately +-100K range
  1893. * if previous cable status was JIG UART BOOT OFF.
  1894. */
  1895. if (adc == (ADC_JIG_UART_OFF + 1) ||
  1896. adc == (ADC_JIG_UART_OFF - 1)) {
  1897. /* Workaround for factory mode in MUIC PASS2
  1898. * In uart path cp, adc is unstable state
  1899. * MUIC PASS2 turn to AP_UART mode automatically
  1900. * So, in this state set correct path manually.
  1901. * !! NEEDED ONLY IF PMIC PASS2 !!
  1902. */
  1903. max77828_muic_handle_jig_uart(info, vbvolt);
  1904. #if !defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  1905. if (info->is_factory_start &&
  1906. (adc == ADC_JIG_UART_ON)) {
  1907. pr_info("%s:%s factory start, keep attach\n",
  1908. DEV_NAME, __func__);
  1909. break;
  1910. }
  1911. #endif /* !CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK */
  1912. dev_warn(info->dev, "%s: abandon ADC\n", __func__);
  1913. return 0;
  1914. }
  1915. if (adc != ADC_JIG_UART_OFF) {
  1916. dev_warn(info->dev, "%s: assume jig uart off detach\n",
  1917. __func__);
  1918. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1919. }
  1920. break;
  1921. case CABLE_TYPE_DESKDOCK_MUIC:
  1922. if (adc != ADC_DESKDOCK) {
  1923. dev_warn(info->dev, "%s: assume deskdock detach\n", __func__);
  1924. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1925. max77828_muic_set_charging_type(info, false);
  1926. info->is_adc_open_prev = false;
  1927. if (mdata->dock_cb)
  1928. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  1929. }
  1930. break;
  1931. case CABLE_TYPE_CARDOCK_MUIC:
  1932. if (adc != ADC_CARDOCK) {
  1933. dev_warn(info->dev, "%s: assume cardock detach\n", __func__);
  1934. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1935. max77828_muic_set_charging_type(info, false);
  1936. info->is_adc_open_prev = false;
  1937. is_cardock = 0;
  1938. if (mdata->dock_cb)
  1939. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  1940. }
  1941. break;
  1942. #if !defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  1943. case CABLE_TYPE_JIG_UART_ON_MUIC:
  1944. if ((adc != ADC_JIG_UART_ON) &&
  1945. info->is_factory_start) {
  1946. pr_warn("%s:%s assume jig uart on detach\n",
  1947. DEV_NAME, __func__);
  1948. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1949. if (mdata->dock_cb)
  1950. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  1951. }
  1952. break;
  1953. #endif /* !CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK */
  1954. case CABLE_TYPE_SMARTDOCK_MUIC:
  1955. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  1956. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  1957. if (adc != ADC_SMARTDOCK) {
  1958. dev_warn(info->dev, "%s: assume smartdock detach\n",
  1959. __func__);
  1960. max77828_muic_detach_smart_dock(info);
  1961. info->is_adc_open_prev = false;
  1962. }
  1963. break;
  1964. case CABLE_TYPE_HMT_MUIC:
  1965. case CABLE_TYPE_HMT_TA_MUIC:
  1966. if (adc != ADC_HMT) {
  1967. dev_warn(info->dev, "%s: assume hmt detach\n",
  1968. __func__);
  1969. max77828_muic_detach_hmt(info);
  1970. info->is_adc_open_prev = false;
  1971. }
  1972. break;
  1973. case CABLE_TYPE_AUDIODOCK_MUIC:
  1974. if ((adc != ADC_AUDIODOCK) || (!vbvolt)) {
  1975. dev_warn(info->dev, "%s: assume audiodock detach\n",
  1976. __func__);
  1977. dev_info(info->dev, "%s: AUDIODOCK\n", __func__);
  1978. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1979. if (mdata->dock_cb)
  1980. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  1981. if (mdata->usb_cb && info->is_usb_ready)
  1982. mdata->usb_cb(USB_POWERED_HOST_DETACHED);
  1983. ret = max77828_muic_set_charging_type(info, false);
  1984. max77828_muic_set_charging_type(info, false);
  1985. }
  1986. break;
  1987. case CABLE_TYPE_MHL_MUIC:
  1988. case CABLE_TYPE_MHL_VB_MUIC:
  1989. if (!adc1k) {
  1990. dev_warn(info->dev, "%s: assume mhl detach\n", __func__);
  1991. dev_info(info->dev, "%s: MHL\n", __func__);
  1992. info->cable_type = CABLE_TYPE_NONE_MUIC;
  1993. max77828_muic_set_charging_type(info, false);
  1994. if (mdata->mhl_cb && info->is_mhl_ready)
  1995. mdata->mhl_cb(MAX77828_MUIC_DETACHED);
  1996. }
  1997. break;
  1998. default:
  1999. break;
  2000. }
  2001. /* 1Kohm ID regiter detection (mHL)
  2002. * New MUIC : ADC value is not set(Open), ADC1K:1, ADCError:1
  2003. */
  2004. if (adc1k) {
  2005. if (irq == info->irq_adc
  2006. || irq == info->irq_chgtype
  2007. || irq == info->irq_vbvolt) {
  2008. dev_warn(info->dev,
  2009. "%s: Ignore irq:%d at MHL detection\n",
  2010. __func__, irq);
  2011. if (vbvolt) {
  2012. dev_info(info->dev, "%s: call charger_cb(%d)"
  2013. , __func__, vbvolt);
  2014. max77828_muic_set_charging_type(info, false);
  2015. } else {
  2016. dev_info(info->dev, "%s: call charger_cb(%d)"
  2017. , __func__, vbvolt);
  2018. max77828_muic_set_charging_type(info, true);
  2019. }
  2020. return 0;
  2021. }
  2022. max77828_muic_attach_mhl(info, chgtyp);
  2023. return 0;
  2024. }
  2025. switch (adc) {
  2026. case ADC_GND:
  2027. if (chgtyp == CHGTYP_NO_VOLTAGE) {
  2028. if (info->cable_type == CABLE_TYPE_OTG_MUIC) {
  2029. dev_info(info->dev,
  2030. "%s: duplicated(OTG)\n", __func__);
  2031. break;
  2032. }
  2033. info->cable_type = CABLE_TYPE_OTG_MUIC;
  2034. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2035. msleep(40);
  2036. if (mdata->usb_cb && info->is_usb_ready)
  2037. mdata->usb_cb(USB_OTGHOST_ATTACHED);
  2038. } else if (chgtyp == CHGTYP_USB ||
  2039. chgtyp == CHGTYP_DOWNSTREAM_PORT ||
  2040. chgtyp == CHGTYP_DEDICATED_CHGR ||
  2041. chgtyp == CHGTYP_500MA || chgtyp == CHGTYP_1A) {
  2042. dev_info(info->dev, "%s: OTG charging pump\n",
  2043. __func__);
  2044. ret = max77828_muic_set_charging_type(info, !vbvolt);
  2045. }
  2046. break;
  2047. case ADC_SMARTDOCK:
  2048. max77828_muic_attach_smart_dock(info, adc, vbvolt, chgtyp);
  2049. break;
  2050. case ADC_HMT:
  2051. max77828_muic_attach_hmt(info, adc, vbvolt, chgtyp);
  2052. break;
  2053. case ADC_VZW_USB_DOCK:
  2054. case ADC_AUDIODOCK:
  2055. if(!!vbvolt)
  2056. max77828_muic_attach_dock_type(info, adc, chgtyp);
  2057. break;
  2058. case ADC_JIG_UART_OFF:
  2059. max77828_muic_handle_jig_uart(info, vbvolt);
  2060. mdata->jig_state(true);
  2061. max77828_muic_uart_uevent(true);
  2062. break;
  2063. case ADC_JIG_USB_OFF:
  2064. case ADC_JIG_USB_ON:
  2065. if (vbvolt & STATUS2_VBVOLT_MASK) {
  2066. dev_info(info->dev, "%s: SKIP_JIG_USB\n", __func__);
  2067. ret = max77828_muic_attach_usb_type(info, adc);
  2068. }
  2069. mdata->jig_state(true);
  2070. max77828_muic_uart_uevent(true);
  2071. break;
  2072. case ADC_DESKDOCK:
  2073. max77828_muic_attach_dock_type(info, adc, chgtyp);
  2074. if (chgtyp == CHGTYP_USB ||
  2075. chgtyp == CHGTYP_DOWNSTREAM_PORT ||
  2076. chgtyp == CHGTYP_DEDICATED_CHGR ||
  2077. chgtyp == CHGTYP_500MA || chgtyp == CHGTYP_1A)
  2078. ret = max77828_muic_set_charging_type(info, false);
  2079. else if (chgtyp == CHGTYP_NO_VOLTAGE && !chgdetrun)
  2080. ret = max77828_muic_set_charging_type(info, !vbvolt);
  2081. /* For MAX77828 IC doesn`t occur chgtyp IRQ
  2082. * because of audio noise prevention.
  2083. * So, If below condition is set,
  2084. * we do charging at CARDOCK.
  2085. */
  2086. break;
  2087. #if defined(CONFIG_MUIC_DET_JACK)
  2088. case ADC_MHL_OR_SENDEND:
  2089. case ADC_DOCK_VOL_UP:
  2090. case ADC_DOCK_VOL_DN:
  2091. if ((!adc1k) && (info->cable_type == CABLE_TYPE_EARJACK_MUIC)) {
  2092. info->earkeypressed = true;
  2093. max77828_muic_earjack_key_detect(info, adc);
  2094. }
  2095. break;
  2096. case ADC_EARJACK:
  2097. if ((info->cable_type == CABLE_TYPE_EARJACK_MUIC) && (info->earkeypressed)) {
  2098. info->earkeypressed = false;
  2099. max77828_muic_earjack_key_detect(info, adc);
  2100. } else {
  2101. max77828_muic_earjack_detect(info, true);
  2102. info->cable_type = CABLE_TYPE_EARJACK_MUIC;
  2103. }
  2104. break;
  2105. #endif
  2106. case ADC_CARDOCK:
  2107. #if defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  2108. max77828_muic_attach_dock_type(info, adc, chgtyp);
  2109. if (chgtyp == CHGTYP_USB ||
  2110. chgtyp == CHGTYP_DOWNSTREAM_PORT ||
  2111. chgtyp == CHGTYP_DEDICATED_CHGR ||
  2112. chgtyp == CHGTYP_500MA || chgtyp == CHGTYP_1A)
  2113. ret = max77828_muic_set_charging_type(info, false);
  2114. else if (chgtyp == CHGTYP_NO_VOLTAGE && !chgdetrun)
  2115. ret = max77828_muic_set_charging_type(info, !vbvolt);
  2116. /* For MAX77828 IC doesn`t occur chgtyp IRQ
  2117. * because of audio noise prevention.
  2118. * So, If below condition is set,
  2119. * we do charging at CARDOCK.
  2120. */
  2121. #else
  2122. /* because of change FACTORY CPOriented to APOriented,
  2123. * at manufacture need AP wake-up method. write apo_factory
  2124. * FACTORY_START is set is_factory_start true.
  2125. */
  2126. if (info->is_factory_start) {
  2127. if (info->cable_type == CABLE_TYPE_JIG_UART_ON_MUIC) {
  2128. pr_info("%s:%s duplicated(JIG_UART_ON)\n",
  2129. DEV_NAME, __func__);
  2130. break;
  2131. }
  2132. pr_info("%s:%s JIG_UART_ON\n", DEV_NAME, __func__);
  2133. info->cable_type = CABLE_TYPE_JIG_UART_ON_MUIC;
  2134. if (mdata->dock_cb)
  2135. mdata->dock_cb(MAX77828_MUIC_DOCK_CARDOCK);
  2136. return 0;
  2137. }
  2138. #endif /* CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK */
  2139. break;
  2140. case ADC_CEA936ATYPE1_CHG:
  2141. case ADC_CEA936ATYPE2_CHG:
  2142. case ADC_OPEN:
  2143. switch (chgtyp) {
  2144. case CHGTYP_USB:
  2145. case CHGTYP_DOWNSTREAM_PORT:
  2146. if (adc == ADC_CEA936ATYPE1_CHG
  2147. || adc == ADC_CEA936ATYPE2_CHG) {
  2148. dev_info(info->dev, "%s:TA\n", __func__);
  2149. info->cable_type = CABLE_TYPE_TA_MUIC;
  2150. #ifdef CONFIG_USBHUB_USB3803
  2151. /* setting usb hub in default mode (standby) */
  2152. usb3803_set_mode(USB_3803_MODE_STANDBY);
  2153. #endif /* CONFIG_USBHUB_USB3803 */
  2154. ret = max77828_muic_set_charging_type(info, !vbvolt);
  2155. if (ret)
  2156. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2157. break;
  2158. }
  2159. if (chgtyp == CHGTYP_DOWNSTREAM_PORT) {
  2160. dev_info(info->dev, "%s, CDP(charging)\n",
  2161. __func__);
  2162. info->cable_type = CABLE_TYPE_CDP_MUIC;
  2163. ret = max77828_muic_set_charging_type(info, !vbvolt);
  2164. if(ret)
  2165. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2166. }
  2167. if (info->cable_type == CABLE_TYPE_MHL_MUIC) {
  2168. dev_info(info->dev, "%s: MHL(charging)\n",
  2169. __func__);
  2170. info->cable_type = CABLE_TYPE_MHL_VB_MUIC;
  2171. ret = max77828_muic_set_charging_type(info,
  2172. !vbvolt);
  2173. return ret;
  2174. }
  2175. ret = max77828_muic_attach_usb_type(info, adc);
  2176. break;
  2177. case CHGTYP_DEDICATED_CHGR:
  2178. max77828_muic_start_check_hv(info);
  2179. case CHGTYP_500MA:
  2180. case CHGTYP_1A:
  2181. default:
  2182. dev_info(info->dev, "%s:TA\n", __func__);
  2183. ret = max77828_muic_check_vdnmon_status(info);
  2184. if (ret == 0)
  2185. {
  2186. info->cable_type = CABLE_TYPE_HV_TA_MUIC;
  2187. dev_info(info->dev, "%s: HV_TA(charging)\n", __func__);
  2188. }
  2189. else
  2190. {
  2191. info->cable_type = CABLE_TYPE_TA_MUIC;
  2192. dev_info(info->dev, "%s: TA(charging)\n", __func__);
  2193. }
  2194. #ifdef CONFIG_USBHUB_USB3803
  2195. /* setting usb hub in default mode (standby) */
  2196. usb3803_set_mode(USB_3803_MODE_STANDBY);
  2197. #endif /* CONFIG_USBHUB_USB3803 */
  2198. ret = max77828_muic_set_charging_type(info, !vbvolt);
  2199. if (ret)
  2200. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2201. break;
  2202. }
  2203. break;
  2204. default:
  2205. dev_warn(info->dev, "%s: unsupported adc=0x%x\n", __func__, adc);
  2206. info->cable_type = CABLE_TYPE_INCOMPATIBLE_MUIC;
  2207. ret = max77828_muic_set_charging_type(info, !vbvolt);
  2208. if (ret)
  2209. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2210. break;
  2211. }
  2212. return ret;
  2213. }
  2214. static int max77828_muic_handle_detach(struct max77828_muic_info *info, int irq)
  2215. {
  2216. struct i2c_client *client = info->muic;
  2217. struct max77828_muic_data *mdata = info->muic_data;
  2218. enum cable_type_muic prev_ct = CABLE_TYPE_NONE_MUIC;
  2219. u8 cntl2_val;
  2220. int ret = 0;
  2221. dev_info(info->dev, "func:%s\n", __func__);
  2222. info->is_adc_open_prev = true;
  2223. /* Workaround: irq doesn't occur after detaching mHL cable */
  2224. max77828_write_reg(client, MAX77828_MUIC_REG_CTRL1,
  2225. MAX77828_MUIC_CTRL1_BIN_0_000);
  2226. /* Enable Factory Accessory Detection State Machine */
  2227. max77828_update_reg(client, MAX77828_MUIC_REG_CTRL2,
  2228. (1 << CTRL2_ACCDET_SHIFT), CTRL2_ACCDET_MASK);
  2229. max77828_update_reg(client, MAX77828_MUIC_REG_CTRL2,
  2230. #if defined(CONFIG_SWITCH_DUAL_MODEM)
  2231. CTRL2_CPEn1_LOWPWD0,
  2232. #else
  2233. CTRL2_CPEn0_LOWPWD1,
  2234. #endif
  2235. CTRL2_CPEn_MASK | CTRL2_LOWPWD_MASK);
  2236. max77828_read_reg(client, MAX77828_MUIC_REG_CTRL2, &cntl2_val);
  2237. dev_info(info->dev, "%s: CNTL2(0x%02x)\n", __func__, cntl2_val);
  2238. #ifdef CONFIG_USBHUB_USB3803
  2239. /* setting usb hub in default mode (standby) */
  2240. usb3803_set_mode(USB_3803_MODE_STANDBY);
  2241. #endif /* CONFIG_USBHUB_USB3803 */
  2242. info->previous_key = DOCK_KEY_NONE;
  2243. /* clear CDDelay 500ms */
  2244. max77828_muic_clear_cddelay(info);
  2245. if (info->cable_type == CABLE_TYPE_NONE_MUIC) {
  2246. dev_info(info->dev, "%s: duplicated(NONE)\n", __func__);
  2247. return 0;
  2248. }
  2249. switch (info->cable_type) {
  2250. case CABLE_TYPE_OTG_MUIC:
  2251. dev_info(info->dev, "%s: OTG\n", __func__);
  2252. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2253. if (mdata->usb_cb && info->is_usb_ready)
  2254. mdata->usb_cb(USB_OTGHOST_DETACHED);
  2255. break;
  2256. case CABLE_TYPE_USB_MUIC:
  2257. case CABLE_TYPE_CDP_MUIC:
  2258. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  2259. case CABLE_TYPE_JIG_USB_ON_MUIC:
  2260. dev_info(info->dev, "%s: USB(0x%x)\n", __func__,
  2261. info->cable_type);
  2262. prev_ct = info->cable_type;
  2263. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2264. ret = max77828_muic_set_charging_type(info, false);
  2265. if (ret) {
  2266. info->cable_type = prev_ct;
  2267. break;
  2268. }
  2269. if (mdata->usb_cb && info->is_usb_ready) {
  2270. #if defined(CONFIG_SEC_H_PROJECT) || defined (CONFIG_SEC_K_PROJECT)
  2271. if (work_busy(&info->usb_connection_work.work)) {
  2272. cancel_delayed_work(&info->usb_connection_work);
  2273. printk(KERN_ERR"max77828_muic_handle_detach canceling the work\n");
  2274. }
  2275. max77828_muic_send_event (1); // USB Disconnected
  2276. #endif
  2277. mdata->usb_cb(USB_CABLE_DETACHED);
  2278. }
  2279. break;
  2280. case CABLE_TYPE_DESKDOCK_MUIC:
  2281. dev_info(info->dev, "%s: DESKDOCK\n", __func__);
  2282. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2283. ret = max77828_muic_set_charging_type(info, false);
  2284. if (ret) {
  2285. info->cable_type = CABLE_TYPE_DESKDOCK_MUIC;
  2286. break;
  2287. }
  2288. if ((info->adc!=ADC_DESKDOCK) && mdata->dock_cb)
  2289. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  2290. break;
  2291. case CABLE_TYPE_CARDOCK_MUIC:
  2292. dev_info(info->dev, "%s: CARDOCK\n", __func__);
  2293. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2294. is_cardock = 0;
  2295. ret = max77828_muic_set_charging_type(info, false);
  2296. if (ret) {
  2297. info->cable_type = CABLE_TYPE_CARDOCK_MUIC;
  2298. break;
  2299. }
  2300. if (mdata->dock_cb)
  2301. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  2302. break;
  2303. case CABLE_TYPE_TA_MUIC:
  2304. case CABLE_TYPE_INCOMPATIBLE_MUIC:
  2305. case CABLE_TYPE_HV_TA_MUIC:
  2306. dev_info(info->dev, "%s: TA\n", __func__);
  2307. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2308. ret = max77828_muic_set_charging_type(info, false);
  2309. if (ret)
  2310. info->cable_type = CABLE_TYPE_TA_MUIC;
  2311. break;
  2312. case CABLE_TYPE_JIG_UART_ON_MUIC:
  2313. #if defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  2314. dev_info(info->dev, "%s: JIG UART/BOOTON\n", __func__);
  2315. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2316. #else
  2317. if (info->is_factory_start) {
  2318. pr_info("%s:%s JIG_UART_ON\n", DEV_NAME, __func__);
  2319. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2320. if (mdata->dock_cb)
  2321. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  2322. }
  2323. #endif /* CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK */
  2324. break;
  2325. case CABLE_TYPE_JIG_UART_OFF_MUIC:
  2326. dev_info(info->dev, "%s: JIG UART/BOOTOFF\n", __func__);
  2327. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2328. break;
  2329. case CABLE_TYPE_SMARTDOCK_MUIC:
  2330. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  2331. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  2332. max77828_muic_detach_smart_dock(info);
  2333. break;
  2334. case CABLE_TYPE_HMT_MUIC:
  2335. case CABLE_TYPE_HMT_TA_MUIC:
  2336. max77828_muic_detach_hmt(info);
  2337. break;
  2338. case CABLE_TYPE_AUDIODOCK_MUIC:
  2339. dev_info(info->dev, "%s: AUDIODOCK\n", __func__);
  2340. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2341. if ((info->adc!=ADC_DESKDOCK) && mdata->dock_cb)
  2342. mdata->dock_cb(MAX77828_MUIC_DOCK_DETACHED);
  2343. if (mdata->usb_cb && info->is_usb_ready)
  2344. mdata->usb_cb(USB_POWERED_HOST_DETACHED);
  2345. ret = max77828_muic_set_charging_type(info, false);
  2346. max77828_muic_set_charging_type(info, false);
  2347. break;
  2348. case CABLE_TYPE_JIG_UART_OFF_VB_MUIC:
  2349. dev_info(info->dev, "%s: JIG UART/OFF/VB\n", __func__);
  2350. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2351. ret = max77828_muic_set_charging_type(info, false);
  2352. if (ret)
  2353. info->cable_type = CABLE_TYPE_JIG_UART_OFF_VB_MUIC;
  2354. break;
  2355. case CABLE_TYPE_MHL_MUIC:
  2356. if (irq == info->irq_adc || irq == info->irq_chgtype) {
  2357. dev_warn(info->dev, "Detech mhl: Ignore irq:%d\n", irq);
  2358. break;
  2359. }
  2360. dev_info(info->dev, "%s: MHL\n", __func__);
  2361. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2362. max77828_muic_set_charging_type(info, false);
  2363. if (mdata->mhl_cb && info->is_mhl_ready)
  2364. mdata->mhl_cb(MAX77828_MUIC_DETACHED);
  2365. break;
  2366. case CABLE_TYPE_MHL_VB_MUIC:
  2367. if (irq == info->irq_adc || irq == info->irq_chgtype) {
  2368. dev_warn(info->dev,
  2369. "Detech vbMhl: Ignore irq:%d\n", irq);
  2370. break;
  2371. }
  2372. dev_info(info->dev, "%s: MHL VBUS\n", __func__);
  2373. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2374. max77828_muic_set_charging_type(info, false);
  2375. if (mdata->mhl_cb && info->is_mhl_ready)
  2376. mdata->mhl_cb(MAX77828_MUIC_DETACHED);
  2377. break;
  2378. #if defined(CONFIG_MUIC_DET_JACK)
  2379. case CABLE_TYPE_EARJACK_MUIC:
  2380. dev_info(info->dev, "%s: EARJACK\n", __func__);
  2381. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2382. max77828_muic_earjack_detect(info, false);
  2383. break;
  2384. #endif
  2385. case CABLE_TYPE_UNKNOWN_MUIC:
  2386. dev_info(info->dev, "%s: UNKNOWN\n", __func__);
  2387. info->cable_type = CABLE_TYPE_NONE_MUIC;
  2388. ret = max77828_muic_set_charging_type(info, false);
  2389. if (ret)
  2390. info->cable_type = CABLE_TYPE_UNKNOWN_MUIC;
  2391. break;
  2392. default:
  2393. dev_info(info->dev, "%s:invalid cable type %d\n",
  2394. __func__, info->cable_type);
  2395. break;
  2396. }
  2397. /* jig state clear */
  2398. mdata->jig_state(false);
  2399. max77828_muic_uart_uevent(false);
  2400. return ret;
  2401. }
  2402. static int max77828_muic_filter_dev(struct max77828_muic_info *info,
  2403. u8 status1, u8 status2)
  2404. {
  2405. u8 adc, adcerr, adc1k, chgtyp, vbvolt, dxovp;
  2406. int intr = INT_ATTACH;
  2407. adc = status1 & STATUS1_ADC_MASK;
  2408. adcerr = status1 & STATUS1_ADCERR_MASK;
  2409. adc1k = status1 & STATUS1_ADC1K_MASK;
  2410. chgtyp = status2 & STATUS2_CHGTYP_MASK;
  2411. vbvolt = status2 & STATUS2_VBVOLT_MASK;
  2412. dxovp = status2 & STATUS2_DXOVP_MASK;
  2413. dev_info(info->dev, "adc:%x adcerr:%x chgtyp:%x vb:%x dxovp:%x cable_type:%d\n",
  2414. adc, adcerr, chgtyp, vbvolt, dxovp, info->cable_type);
  2415. #if defined(CONFIG_MUIC_MAX77828_SUPPORT_MHL_CABLE_DETECTION)
  2416. if (adc1k) {
  2417. pr_info("%s:%s MHL cable connected\n", DEV_NAME, __func__);
  2418. return INT_ATTACH;
  2419. }
  2420. #endif /* CONFIG_MUIC_MAX77828_SUPPORT_MHL_CABLE_DETECTION */
  2421. switch (adc) {
  2422. case ADC_GND:
  2423. pr_info("%s:%s ADC_GND == OTG\n", DEV_NAME, __func__);
  2424. break;
  2425. case (ADC_CEA936ATYPE1_CHG) ... (ADC_JIG_UART_ON):
  2426. if(info->cable_type != CABLE_TYPE_NONE_MUIC
  2427. && chgtyp == CHGTYP_NO_VOLTAGE
  2428. && info->chgtyp != chgtyp) {
  2429. intr = INT_DETACH;
  2430. }
  2431. break;
  2432. case ADC_OPEN:
  2433. if (!adcerr) {
  2434. if (chgtyp == CHGTYP_NO_VOLTAGE) {
  2435. if (dxovp)
  2436. break;
  2437. else
  2438. intr = INT_DETACH;
  2439. } else if (chgtyp == CHGTYP_USB ||
  2440. chgtyp == CHGTYP_DOWNSTREAM_PORT ||
  2441. chgtyp == CHGTYP_DEDICATED_CHGR ||
  2442. chgtyp == CHGTYP_500MA ||
  2443. chgtyp == CHGTYP_1A) {
  2444. switch (info->cable_type) {
  2445. case CABLE_TYPE_OTG_MUIC:
  2446. case CABLE_TYPE_DESKDOCK_MUIC:
  2447. case CABLE_TYPE_CARDOCK_MUIC:
  2448. case CABLE_TYPE_SMARTDOCK_MUIC:
  2449. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  2450. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  2451. case CABLE_TYPE_AUDIODOCK_MUIC:
  2452. case CABLE_TYPE_HMT_MUIC:
  2453. case CABLE_TYPE_HMT_TA_MUIC:
  2454. intr = INT_DETACH;
  2455. break;
  2456. default:
  2457. break;
  2458. }
  2459. }
  2460. }
  2461. break;
  2462. default:
  2463. break;
  2464. }
  2465. return intr;
  2466. }
  2467. static void max77828_muic_detect_dev(struct max77828_muic_info *info, int irq)
  2468. {
  2469. struct i2c_client *client = info->muic;
  2470. u8 status[2];
  2471. int intr = INT_ATTACH;
  2472. int ret;
  2473. u8 cntl1_val;
  2474. ret = max77828_read_reg(client, MAX77828_MUIC_REG_CTRL1, &cntl1_val);
  2475. dev_info(info->dev, "func:%s CONTROL1:%x\n", __func__, cntl1_val);
  2476. ret = max77828_bulk_read(client, MAX77828_MUIC_REG_STATUS1, 2, status);
  2477. dev_info(info->dev, "func:%s irq:%d ret:%d\n", __func__, irq, ret);
  2478. if (ret) {
  2479. dev_err(info->dev, "%s: fail to read muic reg(%d)\n", __func__,
  2480. ret);
  2481. return;
  2482. }
  2483. dev_info(info->dev, "%s: STATUS1:0x%x, 2:0x%x\n", __func__,
  2484. status[0], status[1]);
  2485. if ((irq == info->irq_adc) &&
  2486. max77828_muic_handle_dock_vol_key(info, status[0])) {
  2487. dev_info(info->dev,
  2488. "max77828_muic_handle_dock_vol_key(irq_adc:%x)", irq);
  2489. return;
  2490. }
  2491. wake_lock_timeout(&info->muic_wake_lock, HZ * 2);
  2492. intr = max77828_muic_filter_dev(info, status[0], status[1]);
  2493. info->adc = status[0] & STATUS1_ADC_MASK;
  2494. info->chgtyp = status[1] & STATUS2_CHGTYP_MASK;
  2495. info->vbvolt = status[1] & STATUS2_VBVOLT_MASK;
  2496. if (intr == INT_ATTACH) {
  2497. dev_info(info->dev, "%s: ATTACHED\n", __func__);
  2498. max77828_muic_handle_attach(info, status[0], status[1], irq);
  2499. } else if (intr == INT_DETACH) {
  2500. dev_info(info->dev, "%s: DETACHED\n", __func__);
  2501. max77828_muic_handle_detach(info, irq);
  2502. } else {
  2503. pr_info("%s:%s device filtered, nothing affect.\n", DEV_NAME,
  2504. __func__);
  2505. }
  2506. return;
  2507. }
  2508. static irqreturn_t max77828_muic_irq(int irq, void *data)
  2509. {
  2510. struct max77828_muic_info *info = data;
  2511. dev_info(info->dev, "%s: irq:%d\n", __func__, irq);
  2512. mutex_lock(&info->mutex);
  2513. max77828_muic_detect_dev(info, irq);
  2514. mutex_unlock(&info->mutex);
  2515. return IRQ_HANDLED;
  2516. }
  2517. #define REQUEST_IRQ(_irq, _name) \
  2518. do { \
  2519. ret = request_threaded_irq(_irq, NULL, max77828_muic_irq, \
  2520. 0, _name, info); \
  2521. if (ret < 0) \
  2522. dev_err(info->dev, "Failed to request IRQ #%d: %d\n", \
  2523. _irq, ret); \
  2524. } while (0)
  2525. static int max77828_muic_irq_init(struct max77828_muic_info *info)
  2526. {
  2527. int ret;
  2528. u8 val;
  2529. dev_info(info->dev, "func:%s\n", __func__);
  2530. /* dev_info(info->dev, "%s: system_rev=%x\n", __func__, system_rev); */
  2531. /* INTMASK1 3:ADC1K 2:ADCErr 0:ADC */
  2532. /* INTMASK2 0:Chgtype */
  2533. max77828_write_reg(info->muic, MAX77828_MUIC_REG_INTMASK1, 0x09);
  2534. max77828_write_reg(info->muic, MAX77828_MUIC_REG_INTMASK2, 0x11);
  2535. max77828_write_reg(info->muic, MAX77828_MUIC_REG_INTMASK3, 0x00);
  2536. REQUEST_IRQ(info->irq_adc, "muic-adc");
  2537. dev_info(info->dev, "func:%s muic-adc\n", __func__);
  2538. REQUEST_IRQ(info->irq_chgtype, "muic-chgtype");
  2539. dev_info(info->dev, "func:%s muic-chgtype\n", __func__);
  2540. REQUEST_IRQ(info->irq_vbvolt, "muic-vbvolt");
  2541. dev_info(info->dev, "func:%s muic-vbvolt\n", __func__);
  2542. REQUEST_IRQ(info->irq_adc1k, "muic-adc1k");
  2543. dev_info(info->dev, "func:%s muic-adc1k\n", __func__);
  2544. dev_info(info->dev, "adc:%d chgtype:%d adc1k:%d vbvolt:%d",
  2545. info->irq_adc, info->irq_chgtype,
  2546. info->irq_adc1k, info->irq_vbvolt);
  2547. max77828_read_reg(info->muic, MAX77828_MUIC_REG_INTMASK1, &val);
  2548. dev_info(info->dev, "%s: reg=%x, val=%x\n", __func__,
  2549. MAX77828_MUIC_REG_INTMASK1, val);
  2550. max77828_read_reg(info->muic, MAX77828_MUIC_REG_INTMASK2, &val);
  2551. dev_info(info->dev, "%s: reg=%x, val=%x\n", __func__,
  2552. MAX77828_MUIC_REG_INTMASK2, val);
  2553. max77828_read_reg(info->muic, MAX77828_MUIC_REG_INTMASK3, &val);
  2554. dev_info(info->dev, "%s: reg=%x, val=%x\n", __func__,
  2555. MAX77828_MUIC_REG_INTMASK3, val);
  2556. max77828_read_reg(info->muic, MAX77828_MUIC_REG_INT1, &val);
  2557. dev_info(info->dev, "%s: reg=%x, val=%x\n", __func__,
  2558. MAX77828_MUIC_REG_INT1, val);
  2559. max77828_read_reg(info->muic, MAX77828_MUIC_REG_INT2, &val);
  2560. dev_info(info->dev, "%s: reg=%x, val=%x\n", __func__,
  2561. MAX77828_MUIC_REG_INT2, val);
  2562. max77828_read_reg(info->muic, MAX77828_MUIC_REG_INT3, &val);
  2563. dev_info(info->dev, "%s: reg=%x, val=%x\n", __func__,
  2564. MAX77828_MUIC_REG_INT3, val);
  2565. return 0;
  2566. }
  2567. #define CHECK_GPIO(_gpio, _name) \
  2568. do { \
  2569. if (!_gpio) { \
  2570. dev_err(&pdev->dev, _name " GPIO defined as 0 !\n"); \
  2571. WARN_ON(!_gpio); \
  2572. ret = -EIO; \
  2573. goto err_kfree; \
  2574. } \
  2575. } while (0)
  2576. static void max77828_muic_dock_detect(struct work_struct *work)
  2577. {
  2578. struct max77828_muic_info *info =
  2579. container_of(work, struct max77828_muic_info, dock_work.work);
  2580. struct i2c_client *client = info->muic;
  2581. u8 status[2];
  2582. int ret;
  2583. u8 cntl1_val;
  2584. u8 adc, adcerr, adc1k, chgtyp, vbvolt, dxovp;
  2585. mutex_lock(&info->mutex);
  2586. ret = max77828_read_reg(client, MAX77828_MUIC_REG_CTRL1, &cntl1_val);
  2587. pr_info("%s:%s CONTROL1:%x\n", DEV_NAME, __func__, cntl1_val);
  2588. ret = max77828_bulk_read(client, MAX77828_MUIC_REG_STATUS1, 2, status);
  2589. if (ret) {
  2590. pr_err("%s:%s fail to read muic reg(%d)\n", DEV_NAME, __func__,
  2591. ret);
  2592. goto end;
  2593. }
  2594. pr_info("%s:%s STATUS1:0x%x, 2:0x%x\n", DEV_NAME, __func__, status[0],
  2595. status[1]);
  2596. adc = status[0] & STATUS1_ADC_MASK;
  2597. adcerr = status[0] & STATUS1_ADCERR_MASK;
  2598. adc1k = status[0] & STATUS1_ADC1K_MASK;
  2599. chgtyp = status[1] & STATUS2_CHGTYP_MASK;
  2600. vbvolt = status[1] & STATUS2_VBVOLT_MASK;
  2601. dxovp = status[1] & STATUS2_DXOVP_MASK;
  2602. pr_info("%s:%s adc:%x adcerr:%x chgtyp:%x vb:%x dxovp:%x"\
  2603. " cable_type:%d\n", DEV_NAME, __func__, adc, adcerr, chgtyp,
  2604. vbvolt, dxovp, info->cable_type);
  2605. if (adc1k) {
  2606. pr_info("%s:%s MHL attached, goto end\n", DEV_NAME, __func__);
  2607. goto end;
  2608. }
  2609. if (adcerr) {
  2610. pr_info("%s:%s ADC error, goto end\n", DEV_NAME, __func__);
  2611. goto end;
  2612. }
  2613. switch (adc) {
  2614. case ADC_SMARTDOCK:
  2615. pr_info("%s:%s Smart Dock\n", DEV_NAME, __func__);
  2616. if (vbvolt && !info->is_usb_ready) {
  2617. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  2618. DEV_NAME, __func__);
  2619. max77828_muic_set_usb_path(info, OPEN_USB_MODE);
  2620. } else
  2621. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2622. break;
  2623. case ADC_HMT:
  2624. pr_info("%s:%s HMT\n", DEV_NAME, __func__);
  2625. if (vbvolt && !info->is_usb_ready) {
  2626. pr_info("%s:%s usb not ready yet, D+,D- line(Open)\n",
  2627. DEV_NAME, __func__);
  2628. max77828_muic_set_usb_path(info, OPEN_USB_MODE);
  2629. } else
  2630. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2631. break;
  2632. case ADC_AUDIODOCK:
  2633. pr_info("%s:%s Audio Dock\n", DEV_NAME, __func__);
  2634. if (vbvolt && !info->is_usb_ready) {
  2635. pr_info("%s:%s usb not ready yet, D+,D- line(Open), usb_state:%d\n",
  2636. DEV_NAME, __func__, info->is_usb_ready);
  2637. max77828_muic_set_usb_path(info, OPEN_USB_MODE);
  2638. } else
  2639. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2640. break;
  2641. default:
  2642. break;
  2643. }
  2644. end:
  2645. mutex_unlock(&info->mutex);
  2646. }
  2647. static void max77828_muic_init_detect(struct work_struct *work)
  2648. {
  2649. struct max77828_muic_info *info =
  2650. container_of(work, struct max77828_muic_info, init_work.work);
  2651. dev_info(info->dev, "func:%s\n", __func__);
  2652. mutex_lock(&info->mutex);
  2653. #if defined(CONFIG_MUIC_DET_JACK)
  2654. info->init_detect_done = INIT_START;
  2655. #endif
  2656. max77828_muic_detect_dev(info, -1);
  2657. #if defined(CONFIG_MUIC_DET_JACK)
  2658. info->init_detect_done = INIT_DONE;
  2659. #endif
  2660. mutex_unlock(&info->mutex);
  2661. }
  2662. static void max77828_muic_usb_detect(struct work_struct *work)
  2663. {
  2664. struct max77828_muic_info *info =
  2665. container_of(work, struct max77828_muic_info, usb_work.work);
  2666. struct max77828_muic_data *mdata = info->muic_data;
  2667. dev_info(info->dev, "func:%s info->muic_data->sw_path:%d\n",
  2668. __func__, info->muic_data->sw_path);
  2669. mutex_lock(&info->mutex);
  2670. info->is_usb_ready = true;
  2671. if (mdata->usb_cb) {
  2672. switch (info->cable_type) {
  2673. case CABLE_TYPE_CDP_MUIC:
  2674. case CABLE_TYPE_USB_MUIC:
  2675. case CABLE_TYPE_JIG_USB_OFF_MUIC:
  2676. case CABLE_TYPE_JIG_USB_ON_MUIC:
  2677. #ifdef CONFIG_USBHUB_USB3803
  2678. /* setting usb hub in Diagnostic(hub) mode */
  2679. usb3803_set_mode(USB_3803_MODE_HUB);
  2680. #endif /* CONFIG_USBHUB_USB3803 */
  2681. mdata->usb_cb(USB_CABLE_ATTACHED);
  2682. break;
  2683. default :
  2684. break;
  2685. }
  2686. }
  2687. mutex_unlock(&info->mutex);
  2688. }
  2689. static void max77828_muic_dock_usb_detect(struct work_struct *work)
  2690. {
  2691. struct max77828_muic_info *info =
  2692. container_of(work, struct max77828_muic_info, dock_usb_work.work);
  2693. struct max77828_muic_data *mdata = info->muic_data;
  2694. dev_info(info->dev, "func:%s info->muic_data->sw_path:%d\n",
  2695. __func__, info->muic_data->sw_path);
  2696. mutex_lock(&info->mutex);
  2697. info->is_usb_ready = true;
  2698. if (mdata->usb_cb) {
  2699. switch (info->cable_type) {
  2700. case CABLE_TYPE_OTG_MUIC:
  2701. mdata->usb_cb(USB_OTGHOST_ATTACHED);
  2702. break;
  2703. case CABLE_TYPE_SMARTDOCK_MUIC:
  2704. case CABLE_TYPE_SMARTDOCK_TA_MUIC:
  2705. pr_info("%s:%s now usb ready, turn"\
  2706. "D+,D- line to AP_USB\n", DEV_NAME,
  2707. __func__);
  2708. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2709. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  2710. break;
  2711. case CABLE_TYPE_SMARTDOCK_USB_MUIC:
  2712. pr_info("%s:%s now usb ready, turn"\
  2713. "D+,D- line to AP_USB\n", DEV_NAME,
  2714. __func__);
  2715. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2716. mdata->usb_cb(USB_CABLE_ATTACHED);
  2717. break;
  2718. case CABLE_TYPE_HMT_MUIC:
  2719. pr_info("%s:%s now usb ready, turn"\
  2720. "D+,D- line to AP_USB\n", DEV_NAME,
  2721. __func__);
  2722. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2723. mdata->usb_cb(USB_OTGHOST_ATTACHED);
  2724. break;
  2725. case CABLE_TYPE_HMT_TA_MUIC:
  2726. pr_info("%s:%s now usb ready, turn"\
  2727. "D+,D- line to AP_USB\n", DEV_NAME,
  2728. __func__);
  2729. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2730. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  2731. break;
  2732. case CABLE_TYPE_AUDIODOCK_MUIC:
  2733. pr_info("%s:%s now usb ready, turn"\
  2734. "D+,D- line to AP_USB\n", DEV_NAME,
  2735. __func__);
  2736. max77828_muic_set_usb_path(info, AP_USB_MODE);
  2737. mdata->usb_cb(USB_POWERED_HOST_ATTACHED);
  2738. break;
  2739. default:
  2740. break;
  2741. }
  2742. }
  2743. mutex_unlock(&info->mutex);
  2744. }
  2745. static void max77828_muic_mhl_detect(struct work_struct *work)
  2746. {
  2747. struct max77828_muic_info *info =
  2748. container_of(work, struct max77828_muic_info, mhl_work.work);
  2749. struct max77828_muic_data *mdata = info->muic_data;
  2750. dev_info(info->dev, "func:%s cable_type:%d\n", __func__,
  2751. info->cable_type);
  2752. mutex_lock(&info->mutex);
  2753. info->is_mhl_ready = true;
  2754. if (info->cable_type == CABLE_TYPE_MHL_MUIC ||
  2755. info->cable_type == CABLE_TYPE_MHL_VB_MUIC ||
  2756. info->cable_type == CABLE_TYPE_SMARTDOCK_MUIC ||
  2757. info->cable_type == CABLE_TYPE_SMARTDOCK_TA_MUIC ||
  2758. info->cable_type == CABLE_TYPE_SMARTDOCK_USB_MUIC) {
  2759. if (mdata->mhl_cb)
  2760. mdata->mhl_cb(MAX77828_MUIC_ATTACHED);
  2761. }
  2762. mutex_unlock(&info->mutex);
  2763. }
  2764. #if defined(CONFIG_SEC_H_PROJECT) || defined (CONFIG_SEC_K_PROJECT)
  2765. #define MAX_SPEAKER_CHECK 50
  2766. extern int speaker_status; // Check speak on/off
  2767. void max77828_muic_usb_connection_delay(struct work_struct *work)
  2768. {
  2769. struct max77828_muic_info *info =
  2770. container_of(work, struct max77828_muic_info, usb_connection_work.work);
  2771. struct max77828_muic_data *mdata = info->muic_data;
  2772. // Don't be entered this function. if usb cable was detached.
  2773. if (info->cable_type == CABLE_TYPE_NONE_MUIC) {
  2774. pr_info("%s CABLE_TYPE_NONE \n",__func__);
  2775. return;
  2776. }
  2777. // Delay the usb connection during speaker on
  2778. /*
  2779. if (speaker_status > 0) {
  2780. info->speaker_check_count++;
  2781. if (info->speaker_check_count < MAX_SPEAKER_CHECK) { // Total 4.5s delay
  2782. schedule_delayed_work(&info->usb_connection_work, msecs_to_jiffies(100));
  2783. return;
  2784. }
  2785. }
  2786. */
  2787. // Do usb connection
  2788. if (mdata->usb_cb) {
  2789. if ( info->cable_type == CABLE_TYPE_USB_MUIC)
  2790. mdata->usb_cb(USB_CABLE_ATTACHED);
  2791. }
  2792. }
  2793. #endif
  2794. int max77828_muic_get_status1_adc1k_value(void)
  2795. {
  2796. u8 adc1k;
  2797. int ret;
  2798. ret = max77828_read_reg(gInfo->muic,
  2799. MAX77828_MUIC_REG_STATUS1, &adc1k);
  2800. if (ret) {
  2801. dev_err(gInfo->dev, "%s: fail to read muic reg(%d)\n",
  2802. __func__, ret);
  2803. return -EINVAL;
  2804. }
  2805. adc1k = adc1k & STATUS1_ADC1K_MASK ? 1 : 0;
  2806. pr_info("func:%s, adc1k: %d\n", __func__, adc1k);
  2807. /* -1:err, 0:adc1k not detected, 1:adc1k detected */
  2808. return adc1k;
  2809. }
  2810. int max77828_muic_get_status1_adc_value(void)
  2811. {
  2812. u8 adc;
  2813. int ret;
  2814. ret = max77828_read_reg(gInfo->muic,
  2815. MAX77828_MUIC_REG_STATUS1, &adc);
  2816. if (ret) {
  2817. dev_err(gInfo->dev, "%s: fail to read muic reg(%d)\n",
  2818. __func__, ret);
  2819. return -EINVAL;
  2820. }
  2821. return adc & STATUS1_ADC_MASK;
  2822. }
  2823. /*
  2824. * func: max77828_muic_set_audio_switch
  2825. * arg: bool enable(true:set vps path, false:set path open)
  2826. * return: only 0 success
  2827. */
  2828. int max77828_muic_set_audio_switch(bool enable)
  2829. {
  2830. struct i2c_client *client = gInfo->muic;
  2831. u8 cntl1_val, cntl1_msk;
  2832. int ret;
  2833. pr_info("func:%s enable(%d)", __func__, enable);
  2834. if (enable) {
  2835. cntl1_val = (MAX77828_MUIC_CTRL1_BIN_2_010 << CTRL1_COMN1SW_SHIFT)
  2836. | (MAX77828_MUIC_CTRL1_BIN_2_010 << CTRL1_COMP2SW_SHIFT);
  2837. } else {
  2838. cntl1_val = 0x3f;
  2839. }
  2840. cntl1_msk = CTRL1_COMN1SW_MASK | CTRL1_COMP2SW_MASK;
  2841. ret = max77828_update_reg(client, MAX77828_MUIC_REG_CTRL1, cntl1_val,
  2842. cntl1_msk);
  2843. cntl1_val = MAX77828_MUIC_CTRL1_BIN_0_000;
  2844. max77828_read_reg(client, MAX77828_MUIC_REG_CTRL1, &cntl1_val);
  2845. dev_info(gInfo->dev, "%s: CNTL1(0x%02x)\n", __func__, cntl1_val);
  2846. return ret;
  2847. }
  2848. void max77828_update_jig_state(struct max77828_muic_info *info)
  2849. {
  2850. struct i2c_client *client = info->muic;
  2851. struct max77828_muic_data *mdata = info->muic_data;
  2852. u8 reg_data, adc;
  2853. int ret, jig_state;
  2854. ret = max77828_read_reg(client, MAX77828_MUIC_REG_STATUS1, &reg_data);
  2855. if (ret) {
  2856. dev_err(info->dev, "%s: fail to read muic reg(%d)\n",
  2857. __func__, ret);
  2858. return;
  2859. }
  2860. adc = reg_data & STATUS1_ADC_MASK;
  2861. switch (adc) {
  2862. case ADC_JIG_UART_OFF:
  2863. case ADC_JIG_USB_OFF:
  2864. case ADC_JIG_USB_ON:
  2865. jig_state = true;
  2866. break;
  2867. default:
  2868. jig_state = false;
  2869. break;
  2870. }
  2871. mdata->jig_state(jig_state);
  2872. max77828_muic_uart_uevent(jig_state);
  2873. }
  2874. static int __devinit max77828_muic_probe(struct platform_device *pdev)
  2875. {
  2876. struct max77828_dev *max77828 = dev_get_drvdata(pdev->dev.parent);
  2877. struct max77828_platform_data *pdata = dev_get_platdata(max77828->dev);
  2878. struct max77828_muic_info *info;
  2879. struct input_dev *input;
  2880. #if defined(CONFIG_MUIC_DET_JACK)
  2881. struct class *audio;
  2882. struct device *earjack;
  2883. #endif
  2884. int ret;
  2885. u8 cdetctrl1;
  2886. pr_info("func:%s\n", __func__);
  2887. info = kzalloc(sizeof(struct max77828_muic_info), GFP_KERNEL);
  2888. if (!info) {
  2889. dev_err(&pdev->dev, "%s: failed to allocate info\n", __func__);
  2890. ret = -ENOMEM;
  2891. goto err_return;
  2892. }
  2893. input = input_allocate_device();
  2894. if (!input) {
  2895. dev_err(&pdev->dev, "%s: failed to allocate input\n", __func__);
  2896. ret = -ENOMEM;
  2897. goto err_kfree;
  2898. }
  2899. info->dev = &pdev->dev;
  2900. info->max77828 = max77828;
  2901. info->muic = max77828->muic;
  2902. info->input = input;
  2903. info->irq_adc = max77828->irq_base + MAX77828_MUIC_IRQ_INT1_ADC;
  2904. info->irq_chgtype = max77828->irq_base + MAX77828_MUIC_IRQ_INT2_CHGTYP;
  2905. info->irq_vbvolt = max77828->irq_base + MAX77828_MUIC_IRQ_INT2_VBVOLT;
  2906. info->irq_adc1k = max77828->irq_base + MAX77828_MUIC_IRQ_INT1_ADC1K;
  2907. info->muic_data = pdata->muic_data;
  2908. info->muic_data->uart_path = UART_PATH_AP;
  2909. info->is_adc_open_prev = true;
  2910. #if !defined(CONFIG_MUIC_MAX77828_SUPPORT_CAR_DOCK)
  2911. info->is_factory_start = false;
  2912. #endif /* !CONFIG_MUIC_MZX77828_SUPPORT_CAR_DOCK */
  2913. wake_lock_init(&info->muic_wake_lock, WAKE_LOCK_SUSPEND,
  2914. "muic wake lock");
  2915. info->cable_type = CABLE_TYPE_UNKNOWN_MUIC;
  2916. info->muic_data->sw_path = AP_USB_MODE;
  2917. #if defined(CONFIG_MUIC_DET_JACK)
  2918. info->eardetacted = false;
  2919. info->earkeypressed = false;
  2920. info->init_detect_done = NOT_INIT;
  2921. info->old_keycode = 0;
  2922. info->keycode = 0;
  2923. #endif
  2924. #if defined(CONFIG_SEC_H_PROJECT)
  2925. info->speaker_check_count = 0;
  2926. #endif
  2927. gInfo = info;
  2928. platform_set_drvdata(pdev, info);
  2929. dev_info(info->dev, "adc:%d chgtype:%d, adc1k%d\n",
  2930. info->irq_adc, info->irq_chgtype, info->irq_adc1k);
  2931. input->name = pdev->name;
  2932. input->phys = "deskdock-key/input0";
  2933. input->dev.parent = &pdev->dev;
  2934. input->id.bustype = BUS_HOST;
  2935. input->id.vendor = 0x0001;
  2936. input->id.product = 0x0001;
  2937. input->id.version = 0x0001;
  2938. /* Enable auto repeat feature of Linux input subsystem */
  2939. __set_bit(EV_REP, input->evbit);
  2940. dev_info(info->dev, "input->name:%s\n", input->name);
  2941. #if defined(CONFIG_MUIC_DET_JACK)
  2942. input_set_capability(input, EV_KEY, KEY_MEDIA);
  2943. #endif
  2944. input_set_capability(input, EV_KEY, KEY_VOLUMEUP);
  2945. input_set_capability(input, EV_KEY, KEY_VOLUMEDOWN);
  2946. input_set_capability(input, EV_KEY, KEY_PLAYPAUSE);
  2947. input_set_capability(input, EV_KEY, KEY_PREVIOUSSONG);
  2948. input_set_capability(input, EV_KEY, KEY_NEXTSONG);
  2949. init_timer(&info->timer);
  2950. info->timer.data = (unsigned long)info;
  2951. info->timer.function = max77828_check_hv;
  2952. ret = input_register_device(input);
  2953. if (ret) {
  2954. dev_err(info->dev, "%s: Unable to register input device, "
  2955. "error: %d\n", __func__, ret);
  2956. goto err_input;
  2957. }
  2958. #if defined(CONFIG_SWITCH_DUAL_MODEM)
  2959. switch_sel &= 0xf;
  2960. if ((switch_sel & MAX77828_SWITCH_SEL_1st_BIT_USB) == 0x1)
  2961. info->muic_data->sw_path = AP_USB_MODE;
  2962. else
  2963. info->muic_data->sw_path = CP_USB_MODE;
  2964. if ((switch_sel & MAX77828_SWITCH_SEL_2nd_BIT_UART)
  2965. == 0x1 << 1)
  2966. info->muic_data->uart_path = UART_PATH_AP;
  2967. else
  2968. info->muic_data->uart_path = UART_PATH_CP;
  2969. pr_err("%s: switch_sel: %x\n", __func__, switch_sel);
  2970. #endif
  2971. /* create sysfs group */
  2972. ret = sysfs_create_group(&switch_dev->kobj, &max77828_muic_group);
  2973. dev_set_drvdata(switch_dev, info);
  2974. if (ret) {
  2975. dev_err(&pdev->dev,
  2976. "failed to create max77828 muic attribute group\n");
  2977. goto fail;
  2978. }
  2979. if (info->muic_data->init_cb)
  2980. info->muic_data->init_cb();
  2981. mutex_init(&info->mutex);
  2982. /* Set ADC debounce time: 25ms */
  2983. max77828_muic_set_adcdbset(info, 2);
  2984. /* Set DPDNVdEN Enable */
  2985. max77828_muic_set_dpdnvden(info, 1);
  2986. /* Set DCDTmr to 2sec */
  2987. max77828_read_reg(info->max77828->muic,
  2988. MAX77828_MUIC_REG_CDETCTRL1, &cdetctrl1);
  2989. cdetctrl1 &= ~(1 << 5);
  2990. max77828_write_reg(info->max77828->muic,
  2991. MAX77828_MUIC_REG_CDETCTRL1, cdetctrl1);
  2992. pr_info("%s: CDETCTRL1(0x%02x)\n", __func__, cdetctrl1);
  2993. #if defined(CONFIG_MUIC_DET_JACK)
  2994. ret = switch_dev_register(&switch_earjack);
  2995. if (ret < 0) {
  2996. pr_info("%s : Failed to register switch device\n", __func__);
  2997. goto err_switch_dev_register;
  2998. }
  2999. ret = switch_dev_register(&switch_earjackkey);
  3000. if (ret < 0) {
  3001. pr_info("%s : Failed to register switch device\n", __func__);
  3002. goto err_switch_dev_register;
  3003. }
  3004. audio = class_create(THIS_MODULE, "audio");
  3005. if (IS_ERR(audio))
  3006. pr_err("Failed to create class(audio)!\n");
  3007. earjack = device_create(audio, NULL, 0, NULL, "earjack");
  3008. if (IS_ERR(earjack))
  3009. pr_err("Failed to create device(earjack)!\n");
  3010. ret = device_create_file(earjack, &dev_attr_key_state);
  3011. if (ret)
  3012. pr_err("Failed to create device file in sysfs entries(%s)!\n",
  3013. dev_attr_key_state.attr.name);
  3014. ret = device_create_file(earjack, &dev_attr_state);
  3015. if (ret)
  3016. pr_err("Failed to create device file in sysfs entries(%s)!\n",
  3017. dev_attr_state.attr.name);
  3018. dev_set_drvdata(earjack, info);
  3019. #endif
  3020. ret = switch_dev_register(&switch_uart3);
  3021. if (ret < 0) {
  3022. pr_err("%s : Failed to register switch_uart3 device\n", __func__);
  3023. goto err_switch_uart3_dev_register;
  3024. }
  3025. ret = max77828_muic_irq_init(info);
  3026. if (ret < 0) {
  3027. dev_err(&pdev->dev, "Failed to initialize MUIC irq:%d\n", ret);
  3028. goto fail;
  3029. }
  3030. /* initial cable detection */
  3031. INIT_DELAYED_WORK(&info->dock_work, max77828_muic_dock_detect);
  3032. schedule_delayed_work(&info->dock_work, msecs_to_jiffies(50));
  3033. INIT_DELAYED_WORK(&info->init_work, max77828_muic_init_detect);
  3034. schedule_delayed_work(&info->init_work, msecs_to_jiffies(3000));
  3035. INIT_DELAYED_WORK(&info->usb_work, max77828_muic_usb_detect);
  3036. schedule_delayed_work(&info->usb_work, msecs_to_jiffies(10000));
  3037. INIT_DELAYED_WORK(&info->dock_usb_work, max77828_muic_dock_usb_detect);
  3038. schedule_delayed_work(&info->dock_usb_work, msecs_to_jiffies(22000));
  3039. INIT_DELAYED_WORK(&info->mhl_work, max77828_muic_mhl_detect);
  3040. schedule_delayed_work(&info->mhl_work, msecs_to_jiffies(25000));
  3041. #if defined(CONFIG_SEC_H_PROJECT) || defined (CONFIG_SEC_K_PROJECT)
  3042. INIT_DELAYED_WORK(&info->usb_connection_work, max77828_muic_usb_connection_delay);
  3043. #endif
  3044. #if defined(CONFIG_MUIC_DET_JACK)
  3045. INIT_WORK(&info->earjack_work, max77828_muic_earjack_detect_workfunc);
  3046. INIT_WORK(&info->earjackkey_work, max77828_muic_earjack_key_detect_workfunc);
  3047. #endif
  3048. /* init jig state */
  3049. max77828_update_jig_state(info);
  3050. return 0;
  3051. fail:
  3052. if (info->irq_adc)
  3053. free_irq(info->irq_adc, NULL);
  3054. if (info->irq_chgtype)
  3055. free_irq(info->irq_chgtype, NULL);
  3056. if (info->irq_vbvolt)
  3057. free_irq(info->irq_vbvolt, NULL);
  3058. if (info->irq_adc1k)
  3059. free_irq(info->irq_adc1k, NULL);
  3060. mutex_destroy(&info->mutex);
  3061. err_input:
  3062. platform_set_drvdata(pdev, NULL);
  3063. input_free_device(input);
  3064. wake_lock_destroy(&info->muic_wake_lock);
  3065. err_kfree:
  3066. kfree(info);
  3067. #if defined(CONFIG_MUIC_DET_JACK)
  3068. err_switch_dev_register:
  3069. switch_dev_unregister(&switch_earjack);
  3070. switch_dev_unregister(&switch_earjackkey);
  3071. #endif
  3072. err_switch_uart3_dev_register:
  3073. switch_dev_unregister(&switch_uart3);
  3074. err_return:
  3075. return ret;
  3076. }
  3077. static int __devexit max77828_muic_remove(struct platform_device *pdev)
  3078. {
  3079. struct max77828_muic_info *info = platform_get_drvdata(pdev);
  3080. sysfs_remove_group(&switch_dev->kobj, &max77828_muic_group);
  3081. if (info) {
  3082. dev_info(info->dev, "func:%s\n", __func__);
  3083. input_unregister_device(info->input);
  3084. cancel_delayed_work(&info->dock_work);
  3085. cancel_delayed_work(&info->init_work);
  3086. cancel_delayed_work(&info->usb_work);
  3087. cancel_delayed_work(&info->dock_usb_work);
  3088. cancel_delayed_work(&info->mhl_work);
  3089. #if defined(CONFIG_SEC_H_PROJECT) || defined (CONFIG_SEC_K_PROJECT)
  3090. cancel_delayed_work(&info->usb_connection_work);
  3091. #endif
  3092. free_irq(info->irq_adc, info);
  3093. free_irq(info->irq_chgtype, info);
  3094. free_irq(info->irq_vbvolt, info);
  3095. free_irq(info->irq_adc1k, info);
  3096. wake_lock_destroy(&info->muic_wake_lock);
  3097. #ifndef CONFIG_TARGET_LOCALE_NA
  3098. gpio_free(info->muic_data->gpio_usb_sel);
  3099. #endif /* CONFIG_TARGET_LOCALE_NA */
  3100. mutex_destroy(&info->mutex);
  3101. kfree(info);
  3102. }
  3103. return 0;
  3104. }
  3105. void max77828_muic_shutdown(struct device *dev)
  3106. {
  3107. struct max77828_muic_info *info = dev_get_drvdata(dev);
  3108. int ret;
  3109. u8 val;
  3110. dev_info(info->dev, "func:%s\n", __func__);
  3111. if (!info->muic) {
  3112. dev_err(info->dev, "%s: no muic i2c client\n", __func__);
  3113. return;
  3114. }
  3115. dev_info(info->dev, "%s: JIGSet: auto detection\n", __func__);
  3116. val = (0 << CTRL3_JIGSET_SHIFT);
  3117. ret = max77828_update_reg(info->muic, MAX77828_MUIC_REG_CTRL3, val,
  3118. CTRL3_JIGSET_MASK);
  3119. if (ret < 0) {
  3120. dev_err(info->dev, "%s: fail to update reg\n", __func__);
  3121. return;
  3122. }
  3123. }
  3124. static struct platform_driver max77828_muic_driver = {
  3125. .driver = {
  3126. .name = DEV_NAME,
  3127. .owner = THIS_MODULE,
  3128. .shutdown = max77828_muic_shutdown,
  3129. },
  3130. .probe = max77828_muic_probe,
  3131. .remove = __devexit_p(max77828_muic_remove),
  3132. };
  3133. static int __init max77828_muic_init(void)
  3134. {
  3135. pr_info("func:%s\n", __func__);
  3136. return platform_driver_register(&max77828_muic_driver);
  3137. }
  3138. module_init(max77828_muic_init);
  3139. static void __exit max77828_muic_exit(void)
  3140. {
  3141. pr_info("func:%s\n", __func__);
  3142. platform_driver_unregister(&max77828_muic_driver);
  3143. }
  3144. module_exit(max77828_muic_exit);
  3145. MODULE_DESCRIPTION("Maxim MAX77828 MUIC driver");
  3146. MODULE_AUTHOR("<sukdong.kim@samsung.com>");
  3147. MODULE_LICENSE("GPL");