max77803-muic.c 92 KB

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