fsa9485.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  1. /*
  2. * driver/misc/fsa9485.c - FSA9485 micro USB switch device driver
  3. *
  4. * Copyright (C) 2010 Samsung Electronics
  5. * Minkyu Kang <mk7.kang@samsung.com>
  6. * Wonguk Jeong <wonguk.jeong@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/err.h>
  26. #include <linux/i2c.h>
  27. #include <linux/i2c/fsa9485.h>
  28. #include <linux/irq.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/slab.h>
  32. #include <linux/gpio.h>
  33. #include <linux/delay.h>
  34. #include <linux/regulator/consumer.h>
  35. #include <linux/mfd/pmic8058.h>
  36. #include <linux/input.h>
  37. #include <linux/of_gpio.h>
  38. extern int poweroff_charging;
  39. extern void fsa9485_set_mhl_cable(bool attached);
  40. int uart_connecting;
  41. EXPORT_SYMBOL(uart_connecting);
  42. int detached_status;
  43. EXPORT_SYMBOL(detached_status);
  44. static int mmdock_connect;
  45. static int mmdock_flag;
  46. static int jig_state;
  47. struct fsa9485_usbsw {
  48. struct i2c_client *client;
  49. struct fsa9485_platform_data *pdata;
  50. struct input_dev *input;
  51. struct delayed_work init_work;
  52. struct delayed_work audio_work;
  53. struct delayed_work mhl_work;
  54. struct mutex mutex;
  55. int adc;
  56. int dev1;
  57. int dev2;
  58. int dev3;
  59. int mansw;
  60. int dock_attached;
  61. int dock_ready;
  62. int mhl_ready;
  63. int deskdock;
  64. int previous_key;
  65. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  66. unsigned int previous_dock;
  67. unsigned int lanhub_ta_status;
  68. #endif
  69. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  70. bool is_factory_start;
  71. #endif /* !CONFIG_MUIC_FSA9485_SUPORT_CAR_DOCK */
  72. };
  73. static struct fsa9485_usbsw *local_usbsw;
  74. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  75. enum mhl_attached_type {
  76. MHL_DETACHED = 0,
  77. MHL_ATTACHED = 1,
  78. };
  79. #define MHL_DEVICE 2
  80. static int isDeskdockconnected;
  81. static int isMhlAttached = MHL_DETACHED;
  82. int mhl_connection_state(void)
  83. {
  84. return isMhlAttached;
  85. }
  86. EXPORT_SYMBOL(mhl_connection_state);
  87. #endif
  88. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  89. static void DisableFSA9485Interrupts(void)
  90. {
  91. struct i2c_client *client = local_usbsw->client;
  92. int value, ret;
  93. value = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  94. value |= 0x01;
  95. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_CTRL, value);
  96. if (ret < 0)
  97. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  98. }
  99. static void EnableFSA9485Interrupts(void)
  100. {
  101. struct i2c_client *client = local_usbsw->client;
  102. int value, ret;
  103. value = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  104. value &= 0xFE;
  105. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_CTRL, value);
  106. if (ret < 0)
  107. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  108. }
  109. #endif
  110. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  111. /* RAW DATA Detection*/
  112. static void fsa9485_disable_rawdataInterrupts(void)
  113. {
  114. struct i2c_client *client = local_usbsw->client;
  115. int value, ret;
  116. value = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  117. value |= 0x08;
  118. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_CTRL, value);
  119. pr_info("%s:set CONTROL value to 0x%x", __func__, value);
  120. if (ret < 0)
  121. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  122. }
  123. static void fsa9485_enable_rawdataInterrupts(void)
  124. {
  125. struct i2c_client *client = local_usbsw->client;
  126. u8 value, ret;
  127. value = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  128. value &= 0xF7;
  129. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_CTRL, value);
  130. pr_info("%s:set CONTROL value to 0x%x", __func__, value);
  131. if (ret < 0)
  132. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  133. }
  134. #endif
  135. #if defined(CONFIG_MACH_AEGIS2)
  136. void fsa9485_checkandhookaudiodockfornoise(int value)
  137. {
  138. struct i2c_client *client = local_usbsw->client;
  139. int ret = 0;
  140. if (isDeskdockconnected) {
  141. ret = i2c_smbus_write_byte_data(client,
  142. FSA9485_REG_MANSW1, value);
  143. if (ret < 0)
  144. dev_err(&client->dev, "%s: err %d\n",
  145. __func__, ret);
  146. ret = i2c_smbus_read_byte_data(client,
  147. FSA9485_REG_CTRL);
  148. if (ret < 0)
  149. dev_err(&client->dev, "%s: err %d\n",
  150. __func__, ret);
  151. ret = i2c_smbus_write_byte_data(client,
  152. FSA9485_REG_CTRL,
  153. ret & ~CON_MANUAL_SW & ~CON_RAW_DATA);
  154. if (ret < 0)
  155. dev_err(&client->dev,
  156. "%s: err %d\n", __func__, ret);
  157. } else
  158. pr_info("Dock is not connect\n");
  159. }
  160. #endif
  161. void FSA9485_CheckAndHookAudioDock(int value)
  162. {
  163. struct i2c_client *client = local_usbsw->client;
  164. struct fsa9485_platform_data *pdata = local_usbsw->pdata;
  165. unsigned int dev3;
  166. int ret = 0;
  167. dev3 = i2c_smbus_read_byte_data(client,
  168. FSA9485_REG_RESERVED_1D);
  169. if(dev3 < 0) {
  170. dev_err(&client->dev, "%s: err %d\n", __func__, dev3);
  171. return ;
  172. }
  173. if (value) {
  174. pr_info("FSA9485_CheckAndHookAudioDock ON\n");
  175. if (pdata->dock_cb) {
  176. if(dev3 & 0x02) // check vbus valid
  177. pdata->dock_cb(FSA9485_ATTACHED_DESK_DOCK);
  178. else
  179. pdata->dock_cb(FSA9485_ATTACHED_DESK_DOCK_NO_VBUS);
  180. }
  181. ret = i2c_smbus_write_byte_data(client,
  182. FSA9485_REG_MANSW1, SW_AUDIO);
  183. if (ret < 0)
  184. dev_err(&client->dev, "%s: err %d\n",
  185. __func__, ret);
  186. ret = i2c_smbus_read_byte_data(client,
  187. FSA9485_REG_CTRL);
  188. if (ret < 0)
  189. dev_err(&client->dev, "%s: err %d\n",
  190. __func__, ret);
  191. ret = i2c_smbus_write_byte_data(client,
  192. FSA9485_REG_CTRL,
  193. ret & ~CON_MANUAL_SW & ~CON_RAW_DATA);
  194. if (ret < 0)
  195. dev_err(&client->dev,
  196. "%s: err %d\n", __func__, ret);
  197. } else {
  198. dev_info(&client->dev,
  199. "FSA9485_CheckAndHookAudioDock Off\n");
  200. if (pdata->dock_cb)
  201. pdata->dock_cb(FSA9485_DETACHED_DOCK);
  202. ret = i2c_smbus_read_byte_data(client,
  203. FSA9485_REG_CTRL);
  204. if (ret < 0)
  205. dev_err(&client->dev,
  206. "%s: err %d\n", __func__, ret);
  207. ret = i2c_smbus_write_byte_data(client,
  208. FSA9485_REG_CTRL,
  209. ret | CON_MANUAL_SW | CON_RAW_DATA);
  210. if (ret < 0)
  211. dev_err(&client->dev,
  212. "%s: err %d\n", __func__, ret);
  213. }
  214. }
  215. static void fsa9485_reg_init(struct fsa9485_usbsw *usbsw)
  216. {
  217. struct i2c_client *client = usbsw->client;
  218. unsigned int ctrl = CON_MASK;
  219. int ret;
  220. pr_info("%s called\n", __func__);
  221. /* mask interrupts (unmask attach/detach only) */
  222. ret = i2c_smbus_write_word_data(client, FSA9485_REG_INT1_MASK, 0x18fc);
  223. if (ret < 0)
  224. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  225. /* mask all car kit interrupts */
  226. ret = i2c_smbus_write_word_data(client,
  227. FSA9485_REG_CK_INTMASK1, 0x07ff);
  228. if (ret < 0)
  229. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  230. /* ADC Detect Time: 500ms */
  231. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_TIMING1, 0x0);
  232. if (ret < 0)
  233. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  234. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_CTRL, ctrl);
  235. if (ret < 0)
  236. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  237. /* apply Battery Charging Spec. 1.1 @TA/USB detect */
  238. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_RESERVED_20, 0x04);
  239. if (ret < 0)
  240. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  241. ret = i2c_smbus_read_byte_data(client, FSA9485_REG_DEVID);
  242. if (ret < 0)
  243. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  244. dev_info(&client->dev, " fsa9485_reg_init dev ID: 0x%02x\n", ret);
  245. }
  246. static ssize_t fsa9485_show_control(struct device *dev,
  247. struct device_attribute *attr, char *buf)
  248. {
  249. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  250. struct i2c_client *client = usbsw->client;
  251. int value;
  252. value = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  253. if (value < 0)
  254. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  255. pr_info("%s: value: 0x%02x\n", __func__, value);
  256. return snprintf(buf, 13, "CONTROL: %02x\n", value);
  257. }
  258. static ssize_t fsa9485_show_device_type(struct device *dev,
  259. struct device_attribute *attr, char *buf)
  260. {
  261. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  262. struct i2c_client *client = usbsw->client;
  263. int value;
  264. value = i2c_smbus_read_byte_data(client, FSA9485_REG_DEV_T1);
  265. if (value < 0)
  266. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  267. pr_info("%s: value: 0x%02x\n", __func__, value);
  268. return snprintf(buf, 11, "DEVICE_TYPE: %02x\n", value);
  269. }
  270. static ssize_t fsa9485_show_manualsw(struct device *dev,
  271. struct device_attribute *attr, char *buf)
  272. {
  273. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  274. struct i2c_client *client = usbsw->client;
  275. int value;
  276. value = i2c_smbus_read_byte_data(client, FSA9485_REG_MANSW1);
  277. if (value < 0)
  278. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  279. pr_info("%s: value: 0x%02x\n", __func__, value);
  280. if (value == SW_VAUDIO)
  281. return snprintf(buf, 7, "VAUDIO\n");
  282. else if (value == SW_UART)
  283. return snprintf(buf, 5, "UART\n");
  284. else if (value == SW_AUDIO)
  285. return snprintf(buf, 6, "AUDIO\n");
  286. else if (value == SW_DHOST)
  287. return snprintf(buf, 6, "DHOST\n");
  288. else if (value == SW_AUTO)
  289. return snprintf(buf, 5, "AUTO\n");
  290. else
  291. return snprintf(buf, 4, "%x", value);
  292. }
  293. static ssize_t fsa9485_set_manualsw(struct device *dev,
  294. struct device_attribute *attr, const char *buf, size_t count)
  295. {
  296. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  297. struct i2c_client *client = usbsw->client;
  298. int value, ret;
  299. unsigned int path = 0;
  300. value = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  301. if (value < 0)
  302. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  303. if ((value & ~CON_MANUAL_SW) !=
  304. (CON_SWITCH_OPEN | CON_RAW_DATA | CON_WAIT))
  305. return 0;
  306. if (!strncmp(buf, "VAUDIO", 6)) {
  307. path = SW_VAUDIO;
  308. value &= ~CON_MANUAL_SW;
  309. } else if (!strncmp(buf, "UART", 4)) {
  310. path = SW_UART;
  311. value &= ~CON_MANUAL_SW;
  312. } else if (!strncmp(buf, "AUDIO", 5)) {
  313. path = SW_AUDIO;
  314. value &= ~CON_MANUAL_SW;
  315. } else if (!strncmp(buf, "DHOST", 5)) {
  316. path = SW_DHOST;
  317. value &= ~CON_MANUAL_SW;
  318. } else if (!strncmp(buf, "AUTO", 4)) {
  319. path = SW_AUTO;
  320. value |= CON_MANUAL_SW;
  321. } else {
  322. dev_err(dev, "Wrong command\n");
  323. return 0;
  324. }
  325. usbsw->mansw = path;
  326. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_MANSW1, path);
  327. if (ret < 0)
  328. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  329. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_CTRL, value);
  330. if (ret < 0)
  331. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  332. pr_info("%s: %s, path: 0x%02x, control: 0x%02x\n", __func__,
  333. buf, path, value);
  334. return count;
  335. }
  336. static ssize_t fsa9485_show_usb_state(struct device *dev,
  337. struct device_attribute *attr, char *buf)
  338. {
  339. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  340. struct i2c_client *client = usbsw->client;
  341. int device_type;
  342. unsigned char device_type1, device_type2;
  343. device_type = i2c_smbus_read_word_data(client, FSA9485_REG_DEV_T1);
  344. if (device_type < 0) {
  345. dev_err(&client->dev, "%s: err %d ", __func__, device_type);
  346. return (ssize_t)device_type;
  347. }
  348. device_type1 = device_type & 0xff;
  349. device_type2 = device_type >> 8;
  350. pr_info("%s: dev_type1: 0x%02x, dev_type2: 0x%02x\n", __func__,
  351. device_type1, device_type2);
  352. if (device_type1 & DEV_T1_USB_MASK || device_type2 & DEV_T2_USB_MASK)
  353. return snprintf(buf, 22, "USB_STATE_CONFIGURED\n");
  354. return snprintf(buf, 25, "USB_STATE_NOTCONFIGURED\n");
  355. }
  356. static ssize_t fsa9485_show_adc(struct device *dev,
  357. struct device_attribute *attr,
  358. char *buf)
  359. {
  360. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  361. struct i2c_client *client = usbsw->client;
  362. int adc;
  363. adc = i2c_smbus_read_byte_data(client, FSA9485_REG_ADC);
  364. pr_info("%s: value: 0x%02x\n", __func__, adc);
  365. if (adc < 0) {
  366. dev_err(&client->dev,
  367. "%s: err at read adc %d\n", __func__, adc);
  368. return snprintf(buf, 9, "UNKNOWN\n");
  369. }
  370. return snprintf(buf, 4, "%x\n", adc);
  371. }
  372. static ssize_t fsa9485_reset(struct device *dev,
  373. struct device_attribute *attr,
  374. const char *buf, size_t count)
  375. {
  376. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  377. struct i2c_client *client = usbsw->client;
  378. int ret;
  379. if (!strncmp(buf, "1", 1)) {
  380. dev_info(&client->dev, "fsa9485 reset after delay 1000 msec.\n");
  381. mdelay(1000);
  382. ret = i2c_smbus_write_byte_data(client,
  383. FSA9485_REG_MANUAL_OVERRIDES1, 0x01);
  384. if (ret < 0)
  385. dev_err(&client->dev,
  386. "cannot soft reset, err %d\n", ret);
  387. dev_info(&client->dev, "fsa9485_reset_control done!\n");
  388. } else {
  389. dev_info(&client->dev,
  390. "fsa9485_reset_control, but not reset_value!\n");
  391. }
  392. fsa9485_reg_init(usbsw);
  393. return count;
  394. }
  395. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  396. static ssize_t fsa9485_show_apo_factory(struct device *dev,
  397. struct device_attribute *attr,
  398. char *buf)
  399. {
  400. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  401. const char *mode;
  402. /* true: Factory mode, false: not Factory mode */
  403. if (usbsw->is_factory_start)
  404. mode = "FACTORY_MODE";
  405. else
  406. mode = "NOT_FACTORY_MODE";
  407. pr_info("%s apo factory=%s\n", __func__, mode);
  408. return sprintf(buf, "%s\n", mode);
  409. }
  410. static int fsa9485_detect_dev(struct fsa9485_usbsw *usbsw);
  411. static ssize_t fsa9485_set_apo_factory(struct device *dev,
  412. struct device_attribute *attr,
  413. const char *buf, size_t count)
  414. {
  415. struct fsa9485_usbsw *usbsw = dev_get_drvdata(dev);
  416. pr_info("%s buf:%s\n", __func__, buf);
  417. /* "FACTORY_START": factory mode */
  418. if (!strncmp(buf, "FACTORY_START", 13)) {
  419. usbsw->is_factory_start = true;
  420. pr_info("%s FACTORY_MODE\n", __func__);
  421. fsa9485_detect_dev(usbsw);
  422. } else {
  423. pr_warn("%s Wrong command\n", __func__);
  424. return count;
  425. }
  426. return count;
  427. }
  428. #endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
  429. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  430. static DEVICE_ATTR(apo_factory, 0664, fsa9485_show_apo_factory,
  431. fsa9485_set_apo_factory);
  432. #endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
  433. static DEVICE_ATTR(control, S_IRUGO, fsa9485_show_control, NULL);
  434. static DEVICE_ATTR(device_type, S_IRUGO, fsa9485_show_device_type, NULL);
  435. static DEVICE_ATTR(switch, S_IRUGO | S_IWUSR,
  436. fsa9485_show_manualsw, fsa9485_set_manualsw);
  437. static DEVICE_ATTR(usb_state, S_IRUGO, fsa9485_show_usb_state, NULL);
  438. static DEVICE_ATTR(adc, S_IRUGO, fsa9485_show_adc, NULL);
  439. static DEVICE_ATTR(reset_switch, S_IWUSR | S_IWGRP, NULL, fsa9485_reset);
  440. static struct attribute *fsa9485_attributes[] = {
  441. &dev_attr_control.attr,
  442. &dev_attr_device_type.attr,
  443. &dev_attr_switch.attr,
  444. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  445. &dev_attr_apo_factory.attr,
  446. #endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
  447. NULL
  448. };
  449. static const struct attribute_group fsa9485_group = {
  450. .attrs = fsa9485_attributes,
  451. };
  452. void fsa9485_otg_detach(void)
  453. {
  454. unsigned int data = 0;
  455. int ret;
  456. struct i2c_client *client = local_usbsw->client;
  457. if (local_usbsw->dev1 & DEV_USB_OTG) {
  458. dev_info(&client->dev, "%s: real device\n", __func__);
  459. data = 0x00;
  460. ret = i2c_smbus_write_byte_data(client,
  461. FSA9485_REG_MANSW2, data);
  462. if (ret < 0)
  463. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  464. data = SW_ALL_OPEN;
  465. ret = i2c_smbus_write_byte_data(client,
  466. FSA9485_REG_MANSW1, data);
  467. if (ret < 0)
  468. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  469. data = 0x1A;
  470. ret = i2c_smbus_write_byte_data(client,
  471. FSA9485_REG_CTRL, data);
  472. if (ret < 0)
  473. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  474. } else
  475. dev_info(&client->dev, "%s: not real device\n", __func__);
  476. }
  477. EXPORT_SYMBOL(fsa9485_otg_detach);
  478. void fsa9485_manual_switching(int path)
  479. {
  480. struct i2c_client *client = local_usbsw->client;
  481. int value, ret;
  482. unsigned int data = 0;
  483. pr_info("%s: path: 0x%02x\n", __func__, path);
  484. value = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  485. if (value < 0)
  486. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  487. if ((value & ~CON_MANUAL_SW) !=
  488. (CON_SWITCH_OPEN | CON_RAW_DATA | CON_WAIT))
  489. return;
  490. if (path == SWITCH_PORT_VAUDIO) {
  491. data = SW_VAUDIO;
  492. value &= ~CON_MANUAL_SW;
  493. } else if (path == SWITCH_PORT_UART) {
  494. data = SW_UART;
  495. value &= ~CON_MANUAL_SW;
  496. } else if (path == SWITCH_PORT_AUDIO) {
  497. data = SW_AUDIO;
  498. value &= ~CON_MANUAL_SW;
  499. } else if (path == SWITCH_PORT_USB) {
  500. data = SW_DHOST;
  501. value &= ~CON_MANUAL_SW;
  502. } else if (path == SWITCH_PORT_AUTO) {
  503. data = SW_AUTO;
  504. value |= CON_MANUAL_SW;
  505. } else if (path == SWITCH_PORT_USB_OPEN) {
  506. data = SW_USB_OPEN;
  507. value &= ~CON_MANUAL_SW;
  508. } else if (path == SWITCH_PORT_ALL_OPEN) {
  509. data = SW_ALL_OPEN;
  510. value &= ~CON_MANUAL_SW;
  511. } else {
  512. pr_info("%s: wrong path (%d)\n", __func__, path);
  513. return;
  514. }
  515. local_usbsw->mansw = data;
  516. /* path for FTM sleep */
  517. if (path == SWITCH_PORT_ALL_OPEN) {
  518. ret = i2c_smbus_write_byte_data(client,
  519. FSA9485_REG_MANUAL_OVERRIDES1, 0x0a);
  520. if (ret < 0)
  521. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  522. ret = i2c_smbus_write_byte_data(client,
  523. FSA9485_REG_MANSW1, data);
  524. if (ret < 0)
  525. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  526. ret = i2c_smbus_write_byte_data(client,
  527. FSA9485_REG_MANSW2, data);
  528. if (ret < 0)
  529. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  530. ret = i2c_smbus_write_byte_data(client,
  531. FSA9485_REG_CTRL, value);
  532. if (ret < 0)
  533. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  534. } else {
  535. ret = i2c_smbus_write_byte_data(client,
  536. FSA9485_REG_MANSW1, data);
  537. if (ret < 0)
  538. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  539. ret = i2c_smbus_write_byte_data(client,
  540. FSA9485_REG_CTRL, value);
  541. if (ret < 0)
  542. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  543. }
  544. }
  545. EXPORT_SYMBOL(fsa9485_manual_switching);
  546. int check_jig_state(void)
  547. {
  548. return jig_state;
  549. }
  550. EXPORT_SYMBOL(check_jig_state);
  551. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  552. static int fsa9485_detect_lanhub(struct fsa9485_usbsw *usbsw) {
  553. int device_type, ret;
  554. unsigned int dev1, dev2, adc;
  555. struct fsa9485_platform_data *pdata = usbsw->pdata;
  556. struct i2c_client *client = usbsw->client;
  557. pr_info("%s", __func__);
  558. device_type = i2c_smbus_read_word_data(client, FSA9485_REG_DEV_T1);
  559. if (device_type < 0) {
  560. dev_err(&client->dev, "%s: err %d\n", __func__, device_type);
  561. return device_type;
  562. }
  563. dev1 = device_type & 0xff;
  564. dev2 = device_type >> 8;
  565. adc = i2c_smbus_read_byte_data(client, FSA9485_REG_ADC);
  566. dev_info(&client->dev, "dev1: 0x%02x, dev2: 0x%02x, adc: 0x%02x\n",
  567. dev1, dev2, adc);
  568. /* Attached */
  569. switch(adc){
  570. /* Switch LANHUB+TA to LANHUB */
  571. case ADC_GND:
  572. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  573. if(usbsw->previous_dock == FSA9485_NONE) {
  574. dev_info(&client->dev, "%s:otg(lanhub) connect\n", __func__);
  575. if (pdata->otg_cb)
  576. pdata->otg_cb(FSA9485_ATTACHED);
  577. } else if (usbsw->previous_dock == ADC_LANHUB) {
  578. dev_info(&client->dev, "%s:switch lanhub+ta to lanhub\n", __func__);
  579. usbsw->lanhub_ta_status=0;
  580. if (pdata->lanhubta_cb)
  581. pdata->lanhubta_cb(FSA9485_DETACHED);
  582. }
  583. usbsw->dock_attached = FSA9485_ATTACHED;
  584. usbsw->previous_dock = ADC_GND;
  585. #else
  586. dev_info(&client->dev, "%s:otg connect\n", __func__);
  587. if (pdata->otg_cb)
  588. pdata->otg_cb(FSA9485_ATTACHED);
  589. usbsw->dock_attached = FSA9485_ATTACHED;
  590. #endif
  591. i2c_smbus_write_byte_data(client, FSA9485_REG_MANSW1, 0x27);
  592. i2c_smbus_write_byte_data(client, FSA9485_REG_MANSW2, 0x02);
  593. break;
  594. /* Switch LANHUB to LANHUB+TA */
  595. case ADC_LANHUB:
  596. usbsw->adc = adc;
  597. dev_info(&client->dev, "%s:switch lanhub to lanhub+ta\n", __func__);
  598. if(usbsw->previous_dock == FSA9485_NONE) {
  599. dev_info(&client->dev, "%s:switch lanhub to lanhub+ta\n", __func__);
  600. if (pdata->lanhub_cb)
  601. pdata->lanhub_cb(FSA9485_ATTACHED);
  602. } else if (usbsw->previous_dock == ADC_GND) {
  603. dev_info(&client->dev, "%s:switch lanhub to lanhub+ta\n", __func__);
  604. usbsw->lanhub_ta_status = 1;
  605. if (pdata->lanhubta_cb)
  606. pdata->lanhubta_cb(FSA9485_ATTACHED);
  607. }
  608. usbsw->dock_attached = FSA9485_ATTACHED;
  609. usbsw->previous_dock = ADC_LANHUB;
  610. usbsw->mansw = SW_DHOST;
  611. ret = i2c_smbus_write_byte_data(client,
  612. FSA9485_REG_MANSW1, SW_DHOST);
  613. if (ret < 0)
  614. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  615. ret = i2c_smbus_read_byte_data(client, FSA9485_REG_CTRL);
  616. if (ret < 0)
  617. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  618. ret = i2c_smbus_write_byte_data(client,
  619. FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
  620. if (ret < 0)
  621. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  622. break;
  623. case ADC_OPEN:
  624. dev_info(&client->dev, "%s:ignore ADC_OPEN case\n", __func__);
  625. usbsw->previous_dock = FSA9485_NONE;
  626. break;
  627. default:
  628. dev_info(&client->dev, "%s:Not reaching here(adc:0x%02x)\n",
  629. __func__, adc);
  630. break;
  631. }
  632. return adc;
  633. }
  634. #endif
  635. void fsa9485_mmdock_attach(void){
  636. int ret;
  637. struct i2c_client *client = local_usbsw->client;
  638. struct fsa9485_platform_data *pdata = local_usbsw->pdata;
  639. dev_info(&client->dev, "MM dock connect\n");
  640. mmdock_flag = 1;
  641. ret = i2c_smbus_write_byte_data(client,FSA9485_REG_MANSW1, SW_DHOST);
  642. if (ret < 0)
  643. dev_err(&client->dev,"%s: err %d\n", __func__, ret);
  644. ret = i2c_smbus_read_byte_data(client,
  645. FSA9485_REG_CTRL);
  646. if (ret < 0)
  647. dev_err(&client->dev,
  648. "%s: err %d\n", __func__, ret);
  649. ret = i2c_smbus_write_byte_data(client,
  650. FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
  651. if (ret < 0)
  652. dev_err(&client->dev,
  653. "%s: err %d\n", __func__, ret);
  654. #if defined(CONFIG_VIDEO_MHL_V2)
  655. if (pdata->mhl_cb)
  656. {
  657. pr_info("MMDock callback from FSA chip for PSY setting in MHL driver\n");
  658. pdata->mhl_cb(FSA9485_MMDOCK_ATTACHED);
  659. }
  660. #endif
  661. if (pdata->otg_cb)
  662. pdata->otg_cb(FSA9485_ATTACHED);
  663. if (pdata->mmdock_cb)
  664. pdata->mmdock_cb(FSA9485_ATTACHED);
  665. }
  666. void fsa9485_mmdock_detach(void){
  667. int ret;
  668. struct i2c_client *client = local_usbsw->client;
  669. struct fsa9485_platform_data *pdata = local_usbsw->pdata;
  670. dev_info(&client->dev, "MM dock disconnect\n");
  671. mmdock_flag = 0;
  672. ret = i2c_smbus_read_byte_data(client,FSA9485_REG_CTRL);
  673. if (ret < 0)
  674. dev_err(&client->dev,"%s: err %d\n", __func__, ret);
  675. ret = i2c_smbus_write_byte_data(client,FSA9485_REG_CTRL,ret | CON_MANUAL_SW);
  676. if (ret < 0)
  677. dev_err(&client->dev,"%s: err %d\n", __func__, ret);
  678. if (pdata->otg_cb)
  679. pdata->otg_cb(FSA9485_DETACHED);
  680. #if defined(CONFIG_VIDEO_MHL_V2)
  681. if (pdata->mhl_cb)
  682. pdata->mhl_cb(FSA9485_DETACHED);
  683. #endif
  684. if (pdata->mmdock_cb)
  685. pdata->mmdock_cb(FSA9485_DETACHED);
  686. }
  687. void fsa9485_mmdock_vbus_check(bool vbus_status)
  688. {
  689. if(vbus_status){
  690. if(mmdock_connect ==1 && mmdock_flag ==0)
  691. fsa9485_mmdock_attach();
  692. }
  693. else{
  694. if(mmdock_connect == 1 && mmdock_flag ==1)
  695. fsa9485_mmdock_detach();
  696. }
  697. }
  698. EXPORT_SYMBOL(fsa9485_mmdock_vbus_check);
  699. int check_mmdock_connect(void){
  700. return mmdock_connect;
  701. }
  702. EXPORT_SYMBOL(check_mmdock_connect);
  703. static int fsa9485_detect_dev(struct fsa9485_usbsw *usbsw)
  704. {
  705. int device_type, ret;
  706. unsigned int dev1, dev2, dev3, adc;
  707. struct fsa9485_platform_data *pdata = usbsw->pdata;
  708. struct i2c_client *client = usbsw->client;
  709. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  710. // u8 mhl_ret = 0;
  711. #endif
  712. pr_info("%s", __func__);
  713. device_type = i2c_smbus_read_word_data(client, FSA9485_REG_DEV_T1);
  714. if (device_type < 0) {
  715. dev_err(&client->dev, "%s: err %d\n", __func__, device_type);
  716. return device_type;
  717. }
  718. dev1 = device_type & 0xff;
  719. dev2 = device_type >> 8;
  720. jig_state = (dev2 & DEV_T2_JIG_MASK) ? 1 : 0;
  721. adc = i2c_smbus_read_byte_data(client, FSA9485_REG_ADC);
  722. /* remove for right perform for lanhub / defence code for factory */
  723. #if 0
  724. if (usbsw->dock_attached && usbsw->previous_dock == FSA9485_NONE)
  725. pdata->dock_cb(FSA9485_DETACHED_DOCK);
  726. #endif
  727. if (local_usbsw->dock_ready == 1) {
  728. if (adc == 0x0f)
  729. dev2 = DEV_INCOMPATIBLE;
  730. else if (adc == 0x10)
  731. dev2 = DEV_SMARTDOCK;
  732. else if (adc == 0x12)
  733. dev2 = DEV_AUDIO_DOCK;
  734. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  735. else if (adc == 0x13)
  736. dev2 = DEV_LANHUB;
  737. #endif
  738. else if (adc == 0x14)
  739. dev2 = DEV_CHARGING_CABLE;
  740. else if (adc == 0x15){
  741. dev2 = DEV_MMDOCK;
  742. ret = i2c_smbus_read_byte_data(client,FSA9485_REG_CTRL);
  743. if (ret < 0)
  744. dev_err(&client->dev,"%s: err %d\n", __func__, ret);
  745. ret = i2c_smbus_write_byte_data(client, FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
  746. if (ret < 0)
  747. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  748. mmdock_connect = 1;
  749. }
  750. }
  751. dev3 = i2c_smbus_read_byte_data(client,
  752. FSA9485_REG_RESERVED_1D);
  753. if(dev3 < 0) {
  754. dev_err(&client->dev, "%s: err %d\n", __func__, dev3);
  755. return dev3;
  756. }
  757. dev3 = dev3 & 0x02;
  758. dev_info(&client->dev, "dev1: 0x%02x, dev2: 0x%02x,dev3: 0x%02x, adc: 0x%02x\n",
  759. dev1, dev2, dev3, adc);
  760. /* Attached */
  761. if (dev1 || dev2) {
  762. /* USB */
  763. if (dev1 & DEV_USB || dev2 & DEV_T2_USB_MASK) {
  764. dev_info(&client->dev, "usb connect\n");
  765. if (pdata->usb_cb)
  766. pdata->usb_cb(FSA9485_ATTACHED);
  767. if (usbsw->mansw) {
  768. ret = i2c_smbus_write_byte_data(client,
  769. FSA9485_REG_MANSW1, usbsw->mansw);
  770. if (ret < 0)
  771. dev_err(&client->dev,
  772. "%s: err %d\n", __func__, ret);
  773. }
  774. /* USB_CDP */
  775. } else if (dev1 & DEV_USB_CHG) {
  776. dev_info(&client->dev, "usb_cdp connect\n");
  777. if (pdata->usb_cdp_cb)
  778. pdata->usb_cdp_cb(FSA9485_ATTACHED);
  779. if (usbsw->mansw) {
  780. ret = i2c_smbus_write_byte_data(client,
  781. FSA9485_REG_MANSW1, usbsw->mansw);
  782. if (ret < 0)
  783. dev_err(&client->dev,
  784. "%s: err %d\n", __func__, ret);
  785. }
  786. /* UART */
  787. } else if (dev1 & DEV_T1_UART_MASK || dev2 & DEV_T2_UART_MASK) {
  788. uart_connecting = 1;
  789. dev_info(&client->dev, "uart connect\n");
  790. i2c_smbus_write_byte_data(client,
  791. FSA9485_REG_CTRL, 0x1E);
  792. if (pdata->uart_cb)
  793. pdata->uart_cb(FSA9485_ATTACHED);
  794. if (usbsw->mansw) {
  795. ret = i2c_smbus_write_byte_data(client,
  796. FSA9485_REG_MANSW1, SW_UART);
  797. if (ret < 0)
  798. dev_err(&client->dev,
  799. "%s: err %d\n", __func__, ret);
  800. }
  801. /* CHARGER */
  802. } else if (dev1 & DEV_T1_CHARGER_MASK) {
  803. dev_info(&client->dev, "charger connect\n");
  804. if (pdata->charger_cb)
  805. pdata->charger_cb(FSA9485_ATTACHED);
  806. /* for SAMSUNG OTG */
  807. } else if (dev1 & DEV_USB_OTG) {
  808. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  809. /* Enable RAWDATA Interrupts */
  810. fsa9485_enable_rawdataInterrupts();
  811. #endif
  812. usbsw->dock_attached = FSA9485_ATTACHED;
  813. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  814. usbsw->previous_dock = ADC_GND;
  815. #endif
  816. dev_info(&client->dev, "otg connect\n");
  817. if (pdata->otg_cb)
  818. pdata->otg_cb(FSA9485_ATTACHED);
  819. i2c_smbus_write_byte_data(client,
  820. FSA9485_REG_MANSW1, 0x27);
  821. i2c_smbus_write_byte_data(client,
  822. FSA9485_REG_MANSW2, 0x02);
  823. /* JIG */
  824. } else if (dev2 & DEV_T2_JIG_MASK) {
  825. dev_info(&client->dev, "jig connect\n");
  826. if (pdata->jig_cb)
  827. pdata->jig_cb(FSA9485_ATTACHED);
  828. /* Desk Dock */
  829. } else if (dev2 & DEV_AV) {
  830. if ((adc & 0x1F) == ADC_DESKDOCK) {
  831. dev_info(&client->dev, "FSA Deskdock Attach\n");
  832. FSA9485_CheckAndHookAudioDock(1);
  833. usbsw->deskdock = 1;
  834. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  835. isDeskdockconnected = 1;
  836. #endif
  837. i2c_smbus_write_byte_data(client,
  838. FSA9485_REG_RESERVED_20, 0x08);
  839. } else {
  840. dev_info(&client->dev, "FSA MHL Attach\n");
  841. i2c_smbus_write_byte_data(client,
  842. FSA9485_REG_RESERVED_20, 0x08);
  843. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  844. DisableFSA9485Interrupts();
  845. if (isMhlAttached != MHL_ATTACHED) {
  846. isMhlAttached = MHL_ATTACHED;
  847. schedule_delayed_work(&usbsw->mhl_work, msecs_to_jiffies(100));
  848. } else {
  849. dev_info(&client->dev, "FSA mhl is initializing... bypass\n");
  850. }
  851. EnableFSA9485Interrupts();
  852. #else
  853. dev_info(&client->dev, "FSA mhl attach, but not support MHL feature!\n");
  854. #endif
  855. }
  856. /* Car Dock */
  857. } else if (dev2 & DEV_JIG_UART_ON) {
  858. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  859. if (usbsw->is_factory_start) {
  860. #endif
  861. dev_info(&client->dev, "car dock connect\n");
  862. if (pdata->dock_cb)
  863. pdata->dock_cb(FSA9485_ATTACHED_CAR_DOCK);
  864. ret = i2c_smbus_write_byte_data(client,
  865. FSA9485_REG_MANSW1, SW_AUDIO);
  866. if (ret < 0)
  867. dev_err(&client->dev,
  868. "%s: err %d\n", __func__, ret);
  869. ret = i2c_smbus_read_byte_data(client,
  870. FSA9485_REG_CTRL);
  871. if (ret < 0)
  872. dev_err(&client->dev,
  873. "%s: err %d\n", __func__, ret);
  874. ret = i2c_smbus_write_byte_data(client,
  875. FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
  876. if (ret < 0)
  877. dev_err(&client->dev,
  878. "%s: err %d\n", __func__, ret);
  879. usbsw->dock_attached = FSA9485_ATTACHED;
  880. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  881. } else {
  882. uart_connecting = 1;
  883. dev_info(&client->dev, "uart connect\n");
  884. i2c_smbus_write_byte_data(client,
  885. FSA9485_REG_CTRL, 0x1E);
  886. if (pdata->uart_cb)
  887. pdata->uart_cb(FSA9485_ATTACHED);
  888. if (usbsw->mansw) {
  889. ret = i2c_smbus_write_byte_data(client,
  890. FSA9485_REG_MANSW1, SW_UART);
  891. if (ret < 0)
  892. dev_err(&client->dev,
  893. "%s: err %d\n", __func__, ret);
  894. }
  895. }
  896. #endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
  897. } else if (dev2 & DEV_INCOMPATIBLE) {
  898. usbsw->adc = adc;
  899. dev_info(&client->dev, "Inompatible CHARGER connect\n");
  900. if (pdata->in_charger_cb)
  901. pdata->in_charger_cb(FSA9485_ATTACHED);
  902. /* SmartDock */
  903. } else if (dev2 & DEV_SMARTDOCK) {
  904. usbsw->adc = adc;
  905. dev_info(&client->dev, "smart dock connect\n");
  906. usbsw->mansw = SW_DHOST;
  907. ret = i2c_smbus_write_byte_data(client,
  908. FSA9485_REG_MANSW1, SW_DHOST);
  909. if (ret < 0)
  910. dev_err(&client->dev,
  911. "%s: err %d\n", __func__, ret);
  912. ret = i2c_smbus_read_byte_data(client,
  913. FSA9485_REG_CTRL);
  914. if (ret < 0)
  915. dev_err(&client->dev,
  916. "%s: err %d\n", __func__, ret);
  917. ret = i2c_smbus_write_byte_data(client,
  918. FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
  919. if (ret < 0)
  920. dev_err(&client->dev,
  921. "%s: err %d\n", __func__, ret);
  922. if (pdata->smartdock_cb)
  923. pdata->smartdock_cb(FSA9485_ATTACHED);
  924. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  925. // mhl_onoff_ex(1);
  926. #endif
  927. /*MMDock*/
  928. } else if ((dev2 & DEV_MMDOCK) && (dev3 & 0x02)) {
  929. if(mmdock_flag == 0)
  930. fsa9485_mmdock_attach();
  931. } else if (dev2 & DEV_AUDIO_DOCK) {
  932. usbsw->adc = adc;
  933. dev_info(&client->dev, "audio dock connect\n");
  934. usbsw->mansw = SW_DHOST;
  935. ret = i2c_smbus_write_byte_data(client,
  936. FSA9485_REG_MANSW1, SW_DHOST);
  937. if (ret < 0)
  938. dev_err(&client->dev,
  939. "%s: err %d\n", __func__, ret);
  940. ret = i2c_smbus_read_byte_data(client,
  941. FSA9485_REG_CTRL);
  942. if (ret < 0)
  943. dev_err(&client->dev,
  944. "%s: err %d\n", __func__, ret);
  945. ret = i2c_smbus_write_byte_data(client,
  946. FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
  947. if (ret < 0)
  948. dev_err(&client->dev,
  949. "%s: err %d\n", __func__, ret);
  950. if (pdata->audio_dock_cb)
  951. pdata->audio_dock_cb(FSA9485_ATTACHED);
  952. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  953. /* LANHUB */
  954. } else if (dev2 & DEV_LANHUB) {
  955. /* Enable RAWDATA Interrupts */
  956. fsa9485_enable_rawdataInterrupts();
  957. usbsw->adc = adc;
  958. dev_info(&client->dev, "lanhub connect\n");
  959. usbsw->dock_attached = FSA9485_ATTACHED;
  960. usbsw->previous_dock = ADC_LANHUB;
  961. usbsw->lanhub_ta_status=1;
  962. usbsw->mansw = SW_DHOST;
  963. ret = i2c_smbus_write_byte_data(client,
  964. FSA9485_REG_MANSW1, SW_DHOST);
  965. if (ret < 0)
  966. dev_err(&client->dev,
  967. "%s: err %d\n", __func__, ret);
  968. ret = i2c_smbus_read_byte_data(client,
  969. FSA9485_REG_CTRL);
  970. if (ret < 0)
  971. dev_err(&client->dev,
  972. "%s: err %d\n", __func__, ret);
  973. ret = i2c_smbus_write_byte_data(client,
  974. FSA9485_REG_CTRL, ret & ~CON_MANUAL_SW);
  975. if (ret < 0)
  976. dev_err(&client->dev,
  977. "%s: err %d\n", __func__, ret);
  978. if (pdata->lanhub_cb)
  979. pdata->lanhub_cb(FSA9485_ATTACHED);
  980. #endif
  981. /* CHARGING CABLE */
  982. } else if (dev2 & DEV_CHARGING_CABLE) {
  983. dev_info(&client->dev, "charging cable connect\n");
  984. usbsw->dock_attached = FSA9485_ATTACHED;
  985. usbsw->adc = adc;
  986. if (pdata->charge_cb)
  987. pdata->charge_cb(FSA9485_ATTACHED);
  988. /* Incompatible */
  989. } else if (dev3 & DEV_VBUS_DEBOUNCE) {
  990. dev_info(&client->dev,
  991. "Unsupported ADC, VBUS is valid = CHARGER\n");
  992. if (pdata->charger_cb)
  993. pdata->charger_cb(FSA9485_ATTACHED);
  994. }
  995. /* Detached */
  996. } else {
  997. /* USB */
  998. if (usbsw->dev1 & DEV_USB ||
  999. usbsw->dev2 & DEV_T2_USB_MASK) {
  1000. if (pdata->usb_cb)
  1001. pdata->usb_cb(FSA9485_DETACHED);
  1002. } else if (usbsw->dev1 & DEV_USB_CHG) {
  1003. if (pdata->usb_cdp_cb)
  1004. pdata->usb_cdp_cb(FSA9485_DETACHED);
  1005. /* UART */
  1006. } else if (usbsw->dev1 & DEV_T1_UART_MASK ||
  1007. usbsw->dev2 & DEV_T2_UART_MASK) {
  1008. if (pdata->uart_cb)
  1009. pdata->uart_cb(FSA9485_DETACHED);
  1010. uart_connecting = 0;
  1011. dev_info(&client->dev, "[FSA9485] uart disconnect\n");
  1012. /* CHARGER */
  1013. } else if (usbsw->dev1 & DEV_T1_CHARGER_MASK) {
  1014. if (pdata->charger_cb)
  1015. pdata->charger_cb(FSA9485_DETACHED);
  1016. /* for SAMSUNG OTG */
  1017. } else if (usbsw->dev1 & DEV_USB_OTG) {
  1018. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  1019. /* Disable RAWDATA Interrupts */
  1020. fsa9485_disable_rawdataInterrupts();
  1021. dev_info(&client->dev, "%s:lanhub_ta_status(%d)\n",
  1022. __func__, usbsw->lanhub_ta_status);
  1023. if (pdata->otg_cb && usbsw->lanhub_ta_status == 0)
  1024. pdata->otg_cb(FSA9485_DETACHED);
  1025. else if (pdata->lanhub_cb && usbsw->lanhub_ta_status == 1)
  1026. pdata->lanhub_cb(FSA9485_DETACHED);
  1027. usbsw->dock_attached = FSA9485_DETACHED;
  1028. usbsw->lanhub_ta_status=0;
  1029. #else
  1030. if (pdata->otg_cb)
  1031. pdata->otg_cb(FSA9485_DETACHED);
  1032. usbsw->dock_attached = FSA9485_DETACHED;
  1033. #endif
  1034. i2c_smbus_write_byte_data(client,
  1035. FSA9485_REG_CTRL, 0x1E);
  1036. /* JIG */
  1037. } else if (usbsw->dev2 & DEV_T2_JIG_MASK) {
  1038. if (pdata->jig_cb)
  1039. pdata->jig_cb(FSA9485_DETACHED);
  1040. /* Desk Dock */
  1041. } else if (usbsw->dev2 & DEV_AV) {
  1042. pr_info("FSA MHL Detach\n");
  1043. i2c_smbus_write_byte_data(client,
  1044. FSA9485_REG_RESERVED_20, 0x04);
  1045. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  1046. if (isDeskdockconnected)
  1047. FSA9485_CheckAndHookAudioDock(0);
  1048. isMhlAttached = MHL_DETACHED;
  1049. cancel_delayed_work(&usbsw->mhl_work);
  1050. schedule_delayed_work(&usbsw->mhl_work, msecs_to_jiffies(10));
  1051. isDeskdockconnected = 0;
  1052. #else
  1053. if (usbsw->deskdock) {
  1054. FSA9485_CheckAndHookAudioDock(0);
  1055. usbsw->deskdock = 0;
  1056. } else {
  1057. pr_info("FSA detach mhl cable, but not support MHL feature\n");
  1058. }
  1059. #endif
  1060. /* Car Dock */
  1061. } else if (usbsw->dev2 & DEV_JIG_UART_ON) {
  1062. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  1063. if (usbsw->is_factory_start) {
  1064. #endif
  1065. if (pdata->dock_cb)
  1066. pdata->dock_cb(FSA9485_DETACHED_DOCK);
  1067. ret = i2c_smbus_read_byte_data(client,
  1068. FSA9485_REG_CTRL);
  1069. if (ret < 0)
  1070. dev_err(&client->dev,
  1071. "%s: err %d\n", __func__, ret);
  1072. ret = i2c_smbus_write_byte_data(client,
  1073. FSA9485_REG_CTRL,
  1074. ret | CON_MANUAL_SW);
  1075. if (ret < 0)
  1076. dev_err(&client->dev,
  1077. "%s: err %d\n", __func__, ret);
  1078. usbsw->dock_attached = FSA9485_DETACHED;
  1079. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  1080. } else {
  1081. if (pdata->uart_cb)
  1082. pdata->uart_cb(FSA9485_DETACHED);
  1083. uart_connecting = 0;
  1084. dev_info(&client->dev, "[FSA9485] uart disconnect\n");
  1085. }
  1086. #endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
  1087. } else if (usbsw->adc == 0x0f) {
  1088. dev_info(&client->dev, "Incompatible Charger disconnect\n");
  1089. if (pdata->in_charger_cb)
  1090. pdata->in_charger_cb(FSA9485_DETACHED);
  1091. usbsw->adc = 0;
  1092. } else if (usbsw->adc == 0x10) {
  1093. dev_info(&client->dev, "smart dock disconnect\n");
  1094. ret = i2c_smbus_read_byte_data(client,
  1095. FSA9485_REG_CTRL);
  1096. if (ret < 0)
  1097. dev_err(&client->dev,
  1098. "%s: err %d\n", __func__, ret);
  1099. ret = i2c_smbus_write_byte_data(client,
  1100. FSA9485_REG_CTRL,
  1101. ret | CON_MANUAL_SW);
  1102. if (ret < 0)
  1103. dev_err(&client->dev,
  1104. "%s: err %d\n", __func__, ret);
  1105. if (pdata->smartdock_cb)
  1106. pdata->smartdock_cb(FSA9485_DETACHED);
  1107. usbsw->adc = 0;
  1108. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  1109. // mhl_onoff_ex(false);
  1110. #endif
  1111. } else if (usbsw->adc == 0x12) {
  1112. dev_info(&client->dev, "audio dock disconnect\n");
  1113. ret = i2c_smbus_read_byte_data(client,
  1114. FSA9485_REG_CTRL);
  1115. if (ret < 0)
  1116. dev_err(&client->dev,
  1117. "%s: err %d\n", __func__, ret);
  1118. ret = i2c_smbus_write_byte_data(client,
  1119. FSA9485_REG_CTRL,
  1120. ret | CON_MANUAL_SW);
  1121. if (ret < 0)
  1122. dev_err(&client->dev,
  1123. "%s: err %d\n", __func__, ret);
  1124. if (pdata->audio_dock_cb)
  1125. pdata->audio_dock_cb(FSA9485_DETACHED);
  1126. usbsw->adc = 0;
  1127. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  1128. /* LANHUB */
  1129. } else if (usbsw->adc == 0x13) {
  1130. dev_info(&client->dev, "lanhub disconnect\n");
  1131. /* Disable RAWDATA Interrupts */
  1132. fsa9485_disable_rawdataInterrupts();
  1133. ret = i2c_smbus_read_byte_data(client,
  1134. FSA9485_REG_CTRL);
  1135. if (ret < 0)
  1136. dev_err(&client->dev, "%s: err %d\n",
  1137. __func__, ret);
  1138. ret = i2c_smbus_write_byte_data(client,
  1139. FSA9485_REG_CTRL, ret | CON_MANUAL_SW);
  1140. if (ret < 0)
  1141. dev_err(&client->dev, "%s: err %d\n",
  1142. __func__, ret);
  1143. dev_info(&client->dev, "%s:lanhub_ta_status(%d)\n",
  1144. __func__, usbsw->lanhub_ta_status);
  1145. if (pdata->lanhub_cb && usbsw->lanhub_ta_status==1)
  1146. pdata->lanhub_cb(FSA9485_DETACHED);
  1147. else if (pdata->otg_cb && usbsw->lanhub_ta_status == 0)
  1148. pdata->otg_cb(FSA9485_DETACHED);
  1149. usbsw->dock_attached = FSA9485_DETACHED;
  1150. usbsw->adc = 0;
  1151. usbsw->lanhub_ta_status=0;
  1152. #endif
  1153. /* Charging Cable */
  1154. } else if (usbsw->adc == 0x14) {
  1155. dev_info(&client->dev, "charging_cable disconnect\n");
  1156. usbsw->dock_attached = FSA9485_DETACHED;
  1157. usbsw->adc = 0;
  1158. usbsw->dev2 = 0;
  1159. if (pdata->charge_cb)
  1160. pdata->charge_cb(FSA9485_DETACHED);
  1161. /*MM DOCK*/
  1162. }else if (mmdock_connect == 1) {
  1163. mmdock_connect = 0;
  1164. if(mmdock_flag == 1)
  1165. fsa9485_mmdock_detach();
  1166. } else if (usbsw->dev3 & DEV_VBUS_DEBOUNCE) {
  1167. dev_info(&client->dev,
  1168. "Unsupported adc, Charger disconnect\n");
  1169. if (pdata->charger_cb)
  1170. pdata->charger_cb(FSA9485_DETACHED);
  1171. }
  1172. /* set auto mode */
  1173. i2c_smbus_write_byte_data(client,FSA9485_REG_CTRL, 0x1E);
  1174. }
  1175. usbsw->dev1 = dev1;
  1176. usbsw->dev2 = dev2;
  1177. usbsw->dev3 = dev3;
  1178. return adc;
  1179. }
  1180. static int fsa9485_check_dev(struct fsa9485_usbsw *usbsw)
  1181. {
  1182. struct i2c_client *client = usbsw->client;
  1183. int device_type;
  1184. device_type = i2c_smbus_read_word_data(client, FSA9485_REG_DEV_T1);
  1185. if (device_type < 0) {
  1186. dev_err(&client->dev, "%s: err %d\n", __func__, device_type);
  1187. return 0;
  1188. }
  1189. return device_type;
  1190. }
  1191. static irqreturn_t fsa9485_irq_thread(int irq, void *data)
  1192. {
  1193. struct fsa9485_usbsw *usbsw = data;
  1194. struct i2c_client *client = usbsw->client;
  1195. int intr, intr2, detect;
  1196. /* FSA9480 : Read interrupt -> Read Device
  1197. * FSA9485 : Read Device -> Read interrupt */
  1198. dev_info(&usbsw->client->dev, "%s\n", __func__);
  1199. /* read and clear interrupt status bits */
  1200. intr = i2c_smbus_read_word_data(client, FSA9485_REG_INT1);
  1201. intr2 = intr >> 8;
  1202. dev_info(&client->dev, "%s: intr : 0x%02x intr2 : 0x%02x\n",
  1203. __func__, intr & 0xff, intr2);
  1204. /* device detection */
  1205. mutex_lock(&usbsw->mutex);
  1206. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  1207. if((intr&0xff) == 0x00 && intr2 == 0x04)
  1208. detect = fsa9485_detect_lanhub(usbsw);
  1209. else
  1210. detect = fsa9485_detect_dev(usbsw);
  1211. #else
  1212. detect = fsa9485_detect_dev(usbsw);
  1213. #endif
  1214. mutex_unlock(&usbsw->mutex);
  1215. pr_info("%s: detect dev_adc: 0x%02x\n", __func__, detect);
  1216. if (intr < 0) {
  1217. msleep(100);
  1218. dev_err(&client->dev, "%s: err 0x%02x\n", __func__, intr);
  1219. intr = i2c_smbus_read_word_data(client, FSA9485_REG_INT1);
  1220. if (intr < 0)
  1221. dev_err(&client->dev,
  1222. "%s: err at read 0x%02x\n", __func__, intr);
  1223. fsa9485_reg_init(usbsw);
  1224. return IRQ_HANDLED;
  1225. } else if (intr == 0) {
  1226. /* interrupt was fired, but no status bits were set,
  1227. so device was reset. In this case, the registers were
  1228. reset to defaults so they need to be reinitialised. */
  1229. fsa9485_reg_init(usbsw);
  1230. }
  1231. return IRQ_HANDLED;
  1232. }
  1233. static int fsa9485_irq_init(struct fsa9485_usbsw *usbsw)
  1234. {
  1235. struct i2c_client *client = usbsw->client;
  1236. int ret;
  1237. dev_info(&usbsw->client->dev, "%s\n", __func__);
  1238. if (client->irq) {
  1239. ret = request_threaded_irq(client->irq, NULL,
  1240. fsa9485_irq_thread, IRQF_TRIGGER_FALLING,
  1241. "fsa9485 micro USB", usbsw);
  1242. if (ret) {
  1243. dev_err(&client->dev, "failed to reqeust IRQ\n");
  1244. return ret;
  1245. }
  1246. ret = enable_irq_wake(client->irq);
  1247. if (ret < 0)
  1248. dev_err(&client->dev,
  1249. "failed to enable wakeup src %d\n", ret);
  1250. }
  1251. return 0;
  1252. }
  1253. static void fsa9485_init_detect(struct work_struct *work)
  1254. {
  1255. struct fsa9485_usbsw *usbsw = container_of(work,
  1256. struct fsa9485_usbsw, init_work.work);
  1257. int ret = 0;
  1258. dev_info(&usbsw->client->dev, "%s\n", __func__);
  1259. mutex_lock(&usbsw->mutex);
  1260. fsa9485_detect_dev(usbsw);
  1261. mutex_unlock(&usbsw->mutex);
  1262. ret = fsa9485_irq_init(usbsw);
  1263. if (ret)
  1264. dev_info(&usbsw->client->dev,
  1265. "failed to enable irq init %s\n", __func__);
  1266. }
  1267. static void fsa9485_delayed_audio(struct work_struct *work)
  1268. {
  1269. struct fsa9485_usbsw *usbsw = container_of(work,
  1270. struct fsa9485_usbsw, audio_work.work);
  1271. int device_type;
  1272. unsigned int dev1;
  1273. dev_info(&usbsw->client->dev, "%s\n", __func__);
  1274. local_usbsw->dock_ready = 1;
  1275. local_usbsw->mhl_ready = 1;
  1276. device_type = i2c_smbus_read_word_data(usbsw->client, FSA9485_REG_DEV_T1);
  1277. if (device_type < 0) {
  1278. dev_err(&usbsw->client->dev, "%s: err %d\n", __func__, device_type);
  1279. return;
  1280. }
  1281. dev1 = device_type & 0xff;
  1282. if(dev1 & DEV_USB_OTG) return;
  1283. mutex_lock(&usbsw->mutex);
  1284. fsa9485_detect_dev(usbsw);
  1285. mutex_unlock(&usbsw->mutex);
  1286. }
  1287. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  1288. static void fsa9485_mhl_detect(struct work_struct *work)
  1289. {
  1290. struct delayed_work *dw = to_delayed_work(work);
  1291. struct fsa9485_usbsw *usbsw = container_of(dw,
  1292. struct fsa9485_usbsw, mhl_work);
  1293. struct fsa9485_platform_data *pdata = usbsw->pdata;
  1294. if (local_usbsw->mhl_ready == 0) {
  1295. fsa9485_set_mhl_cable(isMhlAttached);
  1296. dev_info(&usbsw->client->dev, "%s: ignore mhl-detection in booting time\n", __func__);
  1297. isMhlAttached = MHL_DETACHED;
  1298. return;
  1299. }
  1300. dev_info(&usbsw->client->dev, "%s(%d)\n", __func__, isMhlAttached);
  1301. if (isMhlAttached == MHL_ATTACHED) {
  1302. if (pdata->mhl_cb)
  1303. pdata->mhl_cb(FSA9485_ATTACHED);
  1304. } else if(isMhlAttached == MHL_DETACHED) {
  1305. if (pdata->mhl_cb)
  1306. pdata->mhl_cb(FSA9485_DETACHED);
  1307. } else {
  1308. dev_err(&usbsw->client->dev, "[ERROR] %s() mhl known state\n", __func__);
  1309. }
  1310. }
  1311. #endif
  1312. #if 10
  1313. static int fsa9485_parse_dt(struct device *dev,
  1314. struct fsa9485_platform_data *pdata)
  1315. {
  1316. struct device_node *np = dev->of_node;
  1317. /* i2c, irq gpio info */
  1318. pdata->gpio_scl = of_get_named_gpio_flags(np, "fsa9485,scl-gpio",
  1319. 0, &pdata->scl_gpio_flags);
  1320. pdata->gpio_sda = of_get_named_gpio_flags(np, "fsa9485,sda-gpio",
  1321. 0, &pdata->sda_gpio_flags);
  1322. pdata->gpio_int = of_get_named_gpio_flags(np, "fsa9485,irq-gpio",
  1323. 0, &pdata->irq_gpio_flags);
  1324. dev_info(dev, "%s: scl: %d, sda: %d, irq: %d\n", __func__,
  1325. pdata->gpio_scl, pdata->gpio_sda, pdata->gpio_int);
  1326. return 0;
  1327. }
  1328. #endif
  1329. static int __devinit fsa9485_probe(struct i2c_client *client,
  1330. const struct i2c_device_id *id)
  1331. {
  1332. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  1333. struct fsa9485_usbsw *usbsw;
  1334. int ret = 0;
  1335. struct input_dev *input;
  1336. struct device *switch_dev;
  1337. struct fsa9485_platform_data *pdata;
  1338. dev_info(&client->dev, "%s\n", __func__);
  1339. if (client->dev.of_node) {
  1340. pdata = devm_kzalloc(&client->dev,
  1341. sizeof(struct fsa9485_platform_data), GFP_KERNEL);
  1342. if (!pdata) {
  1343. dev_err(&client->dev, "Failed to allocate memory\n");
  1344. return -ENOMEM;
  1345. }
  1346. pdata = &fsa9485_pdata;
  1347. fsa9485_parse_dt(&client->dev, pdata);
  1348. client->irq = gpio_to_irq(pdata->gpio_int);
  1349. } else
  1350. pdata = client->dev.platform_data;
  1351. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  1352. return -EIO;
  1353. input = input_allocate_device();
  1354. if (!input) {
  1355. dev_err(&client->dev, "failed to allocate input device data\n");
  1356. return -ENOMEM;
  1357. }
  1358. usbsw = kzalloc(sizeof(struct fsa9485_usbsw), GFP_KERNEL);
  1359. if (!usbsw) {
  1360. dev_err(&client->dev, "failed to allocate driver data\n");
  1361. input_free_device(input);
  1362. return -ENOMEM;
  1363. }
  1364. usbsw->input = input;
  1365. input->name = client->name;
  1366. input->phys = "deskdock-key/input0";
  1367. input->dev.parent = &client->dev;
  1368. input->id.bustype = BUS_HOST;
  1369. input->id.vendor = 0x0001;
  1370. input->id.product = 0x0001;
  1371. input->id.version = 0x0001;
  1372. /* Enable auto repeat feature of Linux input subsystem */
  1373. __set_bit(EV_REP, input->evbit);
  1374. input_set_capability(input, EV_KEY, KEY_VOLUMEUP);
  1375. input_set_capability(input, EV_KEY, KEY_VOLUMEDOWN);
  1376. input_set_capability(input, EV_KEY, KEY_PLAYPAUSE);
  1377. input_set_capability(input, EV_KEY, KEY_PREVIOUSSONG);
  1378. input_set_capability(input, EV_KEY, KEY_NEXTSONG);
  1379. ret = input_register_device(input);
  1380. if (ret) {
  1381. dev_err(&client->dev,
  1382. "input_register_device %s: err %d\n", __func__, ret);
  1383. input_free_device(input);
  1384. kfree(usbsw);
  1385. return ret;
  1386. }
  1387. usbsw->client = client;
  1388. usbsw->pdata = pdata;
  1389. if (!usbsw->pdata)
  1390. goto fail1;
  1391. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  1392. usbsw->is_factory_start = false;
  1393. #endif /* !CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK */
  1394. i2c_set_clientdata(client, usbsw);
  1395. mutex_init(&usbsw->mutex);
  1396. local_usbsw = usbsw;
  1397. if (usbsw->pdata->cfg_gpio)
  1398. usbsw->pdata->cfg_gpio();
  1399. fsa9485_reg_init(usbsw);
  1400. uart_connecting = 0;
  1401. ret = sysfs_create_group(&client->dev.kobj, &fsa9485_group);
  1402. if (ret) {
  1403. dev_err(&client->dev,
  1404. "failed to create fsa9485 attribute group\n");
  1405. goto fail2;
  1406. }
  1407. /* make sysfs node /sys/class/sec/switch/usb_state */
  1408. switch_dev = device_create(sec_class, NULL, 0, NULL, "switch");
  1409. if (IS_ERR(switch_dev)) {
  1410. pr_err("[FSA9485] Failed to create device (switch_dev)!\n");
  1411. ret = PTR_ERR(switch_dev);
  1412. goto fail2;
  1413. }
  1414. ret = device_create_file(switch_dev, &dev_attr_usb_state);
  1415. if (ret < 0) {
  1416. pr_err("[FSA9485] Failed to create file (usb_state)!\n");
  1417. goto fail2;
  1418. }
  1419. ret = device_create_file(switch_dev, &dev_attr_adc);
  1420. if (ret < 0) {
  1421. pr_err("[FSA9485] Failed to create file (adc)!\n");
  1422. goto err_create_file_state;
  1423. }
  1424. ret = device_create_file(switch_dev, &dev_attr_reset_switch);
  1425. if (ret < 0) {
  1426. pr_err("[FSA9485] Failed to create file (reset_switch)!\n");
  1427. goto err_create_file_adc;
  1428. }
  1429. #if !defined(CONFIG_MUIC_FSA9485_SUPPORT_CAR_DOCK)
  1430. ret = device_create_file(switch_dev, &dev_attr_apo_factory);
  1431. if (ret < 0) {
  1432. pr_err("[FSA9485] Failed to create file (apo_factory)!\n");
  1433. goto err_create_file_reset_switch;
  1434. }
  1435. #endif
  1436. dev_set_drvdata(switch_dev, usbsw);
  1437. /* fsa9485 dock init*/
  1438. if (usbsw->pdata->dock_init)
  1439. usbsw->pdata->dock_init();
  1440. /* fsa9485 reset */
  1441. if (usbsw->pdata->reset_cb)
  1442. usbsw->pdata->reset_cb();
  1443. /* set fsa9485 init flag. */
  1444. if (usbsw->pdata->set_init_flag)
  1445. usbsw->pdata->set_init_flag();
  1446. local_usbsw->dock_ready = 0;
  1447. local_usbsw->mhl_ready = 0;
  1448. #ifdef CONFIG_MUIC_FSA9485_SUPPORT_LANHUB
  1449. local_usbsw->previous_dock = 0;
  1450. local_usbsw->lanhub_ta_status = 0;
  1451. #endif
  1452. /* initial cable detection */
  1453. INIT_DELAYED_WORK(&usbsw->init_work, fsa9485_init_detect);
  1454. if(poweroff_charging)
  1455. schedule_delayed_work(&usbsw->init_work, msecs_to_jiffies(1000));
  1456. else
  1457. #ifdef CONFIG_SEC_BERLUTI_PROJECT
  1458. schedule_delayed_work(&usbsw->init_work, msecs_to_jiffies(100));
  1459. #else
  1460. schedule_delayed_work(&usbsw->init_work, msecs_to_jiffies(3000));
  1461. #endif
  1462. INIT_DELAYED_WORK(&usbsw->audio_work, fsa9485_delayed_audio);
  1463. schedule_delayed_work(&usbsw->audio_work, msecs_to_jiffies(20000));
  1464. #if defined(CONFIG_VIDEO_MHL_V1) || defined(CONFIG_VIDEO_MHL_V2)
  1465. INIT_DELAYED_WORK(&usbsw->mhl_work, fsa9485_mhl_detect);
  1466. #endif
  1467. return 0;
  1468. err_create_file_reset_switch:
  1469. device_remove_file(switch_dev, &dev_attr_reset_switch);
  1470. err_create_file_adc:
  1471. device_remove_file(switch_dev, &dev_attr_adc);
  1472. err_create_file_state:
  1473. device_remove_file(switch_dev, &dev_attr_usb_state);
  1474. fail2:
  1475. if (client->irq)
  1476. free_irq(client->irq, usbsw);
  1477. fail1:
  1478. input_unregister_device(input);
  1479. mutex_destroy(&usbsw->mutex);
  1480. i2c_set_clientdata(client, NULL);
  1481. input_free_device(input);
  1482. kfree(usbsw);
  1483. return ret;
  1484. }
  1485. static int __devexit fsa9485_remove(struct i2c_client *client)
  1486. {
  1487. struct fsa9485_usbsw *usbsw = i2c_get_clientdata(client);
  1488. cancel_delayed_work(&usbsw->init_work);
  1489. cancel_delayed_work(&usbsw->audio_work);
  1490. if (client->irq) {
  1491. disable_irq_wake(client->irq);
  1492. free_irq(client->irq, usbsw);
  1493. }
  1494. mutex_destroy(&usbsw->mutex);
  1495. i2c_set_clientdata(client, NULL);
  1496. sysfs_remove_group(&client->dev.kobj, &fsa9485_group);
  1497. kfree(usbsw);
  1498. return 0;
  1499. }
  1500. static int fsa9485_resume(struct i2c_client *client)
  1501. {
  1502. struct fsa9485_usbsw *usbsw = i2c_get_clientdata(client);
  1503. /* add for fsa9485_irq_thread i2c error during wakeup */
  1504. fsa9485_check_dev(usbsw);
  1505. i2c_smbus_read_byte_data(client, FSA9485_REG_INT1);
  1506. /* device detection */
  1507. mutex_lock(&usbsw->mutex);
  1508. fsa9485_detect_dev(usbsw);
  1509. mutex_unlock(&usbsw->mutex);
  1510. return 0;
  1511. }
  1512. static const struct i2c_device_id fsa9485_id[] = {
  1513. {"fsa9485", 0},
  1514. {}
  1515. };
  1516. MODULE_DEVICE_TABLE(i2c, fsa9485_id);
  1517. static struct of_device_id muic_match_table[] = {
  1518. { .compatible = "fsa9485,muic",},
  1519. { },
  1520. };
  1521. static struct i2c_driver fsa9485_i2c_driver = {
  1522. .driver = {
  1523. .name = "fsa9485",
  1524. .owner = THIS_MODULE,
  1525. .of_match_table = muic_match_table,
  1526. },
  1527. .probe = fsa9485_probe,
  1528. .remove = __devexit_p(fsa9485_remove),
  1529. .resume = fsa9485_resume,
  1530. .id_table = fsa9485_id,
  1531. };
  1532. static int __init fsa9485_init(void)
  1533. {
  1534. return i2c_add_driver(&fsa9485_i2c_driver);
  1535. }
  1536. module_init(fsa9485_init);
  1537. static void __exit fsa9485_exit(void)
  1538. {
  1539. i2c_del_driver(&fsa9485_i2c_driver);
  1540. }
  1541. module_exit(fsa9485_exit);
  1542. MODULE_AUTHOR("Minkyu Kang <mk7.kang@samsung.com>");
  1543. MODULE_DESCRIPTION("FSA9485 USB Switch driver");
  1544. MODULE_LICENSE("GPL");