max77888-muic.c 97 KB

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