max77804k-muic.c 95 KB

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