tsu6721.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. /*
  2. * driver/misc/tsu6721.c - TSU6721 micro USB switch device driver
  3. *
  4. * Copyright (C) 2013 Samsung Electronics
  5. * Jeongrae Kim <jryu.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. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/err.h>
  25. #include <linux/i2c.h>
  26. #include <linux/i2c/tsu6721.h>
  27. #include <linux/irq.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/slab.h>
  31. #include <linux/gpio.h>
  32. #include <linux/delay.h>
  33. #include <linux/regulator/consumer.h>
  34. #include <linux/mfd/pmic8058.h>
  35. #include <linux/input.h>
  36. #include <linux/switch.h>
  37. #if defined (CONFIG_OF)
  38. #include <linux/of_device.h>
  39. #include <linux/of_gpio.h>
  40. #endif
  41. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  42. #include <linux/sec_param.h>
  43. #endif
  44. #ifdef CONFIG_USB_HOST_NOTIFY
  45. #include <linux/host_notify.h>
  46. #endif
  47. /* spmi control */
  48. extern int spmi_ext_register_writel_extra(u8 sid, u16 ad, u8 *buf, int len);
  49. extern int spmi_ext_register_readl_extra(u8 sid, u16 ad, u8 *buf, int len);
  50. extern int system_rev;
  51. #define INT_MASK1 0x5C
  52. #define INT_MASK2 0x20
  53. /* DEVICE ID */
  54. #define TSU6721_DEV_ID 0x0A
  55. #define TSU6721_DEV_ID_REV 0x12
  56. /* TSU6721 I2C registers */
  57. #define REG_DEVICE_ID 0x01
  58. #define REG_CONTROL 0x02
  59. #define REG_INT1 0x03
  60. #define REG_INT2 0x04
  61. #define REG_INT_MASK1 0x05
  62. #define REG_INT_MASK2 0x06
  63. #define REG_ADC 0x07
  64. #define REG_TIMING_SET1 0x08
  65. #define REG_TIMING_SET2 0x09
  66. #define REG_DEVICE_TYPE1 0x0a
  67. #define REG_DEVICE_TYPE2 0x0b
  68. #define REG_BUTTON1 0x0c
  69. #define REG_BUTTON2 0x0d
  70. #define REG_MANUAL_SW1 0x13
  71. #define REG_MANUAL_SW2 0x14
  72. #define REG_DEVICE_TYPE3 0x15
  73. #define REG_RESET 0x1B
  74. #define REG_TIMER_SET 0x20
  75. #define REG_OCL_OCP_SET1 0x21
  76. #define REG_OCL_OCP_SET2 0x22
  77. #define REG_DEVICE_TYPE4 0x23
  78. #define DATA_NONE 0x00
  79. /* Control */
  80. #define CON_SWITCH_OPEN (1 << 4)
  81. #define CON_RAW_DATA (1 << 3)
  82. #define CON_MANUAL_SW (1 << 2)
  83. #define CON_WAIT (1 << 1)
  84. #define CON_INT_MASK (1 << 0)
  85. #define CON_MASK (CON_SWITCH_OPEN | CON_RAW_DATA | \
  86. CON_MANUAL_SW | CON_WAIT)
  87. /* Device Type 1 */
  88. #define DEV_USB_OTG (1 << 7)
  89. #define DEV_DEDICATED_CHG (1 << 6)
  90. #define DEV_USB_CHG (1 << 5)
  91. #define DEV_CAR_KIT (1 << 4)
  92. #define DEV_UART (1 << 3)
  93. #define DEV_USB (1 << 2)
  94. #define DEV_AUDIO_2 (1 << 1)
  95. #define DEV_AUDIO_1 (1 << 0)
  96. #define DEV_T1_USB_MASK (DEV_USB_OTG | DEV_USB_CHG | DEV_USB)
  97. #define DEV_T1_UART_MASK (DEV_UART)
  98. #define DEV_T1_CHARGER_MASK (DEV_DEDICATED_CHG | DEV_CAR_KIT)
  99. #define MANSW1_OPEN_RUSTPROOF ((0x0 << 5)| (0x3 << 2) |(1 << 0))
  100. /* Device Type 2 */
  101. #define DEV_LG_CABLE (1 << 9)
  102. #define DEV_AUDIO_DOCK (1 << 8)
  103. #define DEV_SMARTDOCK (1 << 7)
  104. #define DEV_AV (1 << 6)
  105. #define DEV_TTY (1 << 5)
  106. #define DEV_PPD (1 << 4)
  107. #define DEV_JIG_UART_OFF (1 << 3)
  108. #define DEV_JIG_UART_ON (1 << 2)
  109. #define DEV_JIG_USB_OFF (1 << 1)
  110. #define DEV_JIG_USB_ON (1 << 0)
  111. #define DEV_T2_USB_MASK (DEV_JIG_USB_OFF | DEV_JIG_USB_ON)
  112. #define DEV_T2_UART_MASK (DEV_JIG_UART_OFF)
  113. #define DEV_T2_JIG_MASK (DEV_JIG_USB_OFF | DEV_JIG_USB_ON | \
  114. DEV_JIG_UART_OFF)
  115. #define DEV_T2_JIG_ALL_MASK (DEV_JIG_USB_OFF | DEV_JIG_USB_ON | \
  116. DEV_JIG_UART_OFF | DEV_JIG_UART_ON)
  117. /* Device Type 3 */
  118. #define DEV_MHL (1 << 0)
  119. #define DEV_VBUS_DEBOUNCE (1 << 1)
  120. #define DEV_NON_STANDARD (1 << 2)
  121. #define DEV_AV_VBUS (1 << 4)
  122. #define DEV_APPLE_CHARGER (1 << 5)
  123. #define DEV_U200_CHARGER (1 << 6)
  124. #define DEV_T3_CHARGER_MASK (DEV_NON_STANDARD | DEV_APPLE_CHARGER | \
  125. DEV_U200_CHARGER)
  126. /*
  127. * Manual Switch
  128. * D- [7:5] / D+ [4:2]
  129. * 000: Open all / 001: USB / 010: AUDIO / 011: UART / 100: V_AUDIO
  130. */
  131. #define SW_VAUDIO ((4 << 5) | (4 << 2) | (1 << 1) | (1 << 0))
  132. #define SW_UART ((3 << 5) | (3 << 2))
  133. #define SW_AUDIO ((2 << 5) | (2 << 2) | (1 << 0))
  134. #define SW_DHOST ((1 << 5) | (1 << 2) | (1 << 0))
  135. #define SW_AUTO ((0 << 5) | (0 << 2))
  136. #define SW_USB_OPEN (1 << 0)
  137. #define SW_ALL_OPEN (0)
  138. #define SW_ALL_OPEN_WITH_VBUS ((0 << 5) | (0 << 2) | (1 << 0))
  139. /* Interrupt 1 */
  140. #define INT_OXP_DISABLE (1 << 7)
  141. #define INT_OCP_ENABLE (1 << 6)
  142. #define INT_OVP_ENABLE (1 << 5)
  143. #define INT_LONG_KEY_RELEASE (1 << 4)
  144. #define INT_LONG_KEY_PRESS (1 << 3)
  145. #define INT_KEY_PRESS (1 << 2)
  146. #define INT_DETACH (1 << 1)
  147. #define INT_ATTACH (1 << 0)
  148. /* Interrupt 2 */
  149. #define INT_VBUS (1 << 7)
  150. #define INT_OTP_ENABLE (1 << 6)
  151. #define INT_CONNECT (1 << 5)
  152. #define INT_STUCK_KEY_RCV (1 << 4)
  153. #define INT_STUCK_KEY (1 << 3)
  154. #define INT_ADC_CHANGE (1 << 2)
  155. #define INT_RESERVED_ATTACH (1 << 1)
  156. #define INT_AV_CHANGE (1 << 0)
  157. /* ADC VALUE */
  158. #define ADC_OTG 0x00
  159. #define ADC_MHL 0x01
  160. #define ADC_SMART_DOCK 0x10
  161. #define ADC_AUDIO_DOCK 0x12
  162. #define ADC_LG_CABLE 0x17
  163. #define ADC_JIG_USB_OFF 0x18
  164. #define ADC_JIG_USB_ON 0x19
  165. #define ADC_DESKDOCK 0x1a
  166. #define ADC_JIG_UART_OFF 0x1c
  167. #define ADC_JIG_UART_ON 0x1d
  168. #define ADC_CARDOCK 0x1d
  169. #define ADC_OPEN 0x1f
  170. int uart_connecting;
  171. EXPORT_SYMBOL(uart_connecting);
  172. int detached_status;
  173. EXPORT_SYMBOL(detached_status);
  174. static int jig_state;
  175. struct tsu6721_usbsw {
  176. struct i2c_client *client;
  177. struct tsu6721_platform_data *pdata;
  178. int dev1;
  179. int dev2;
  180. int dev3;
  181. int mansw;
  182. int dock_attached;
  183. int dev_id;
  184. struct delayed_work init_work;
  185. struct mutex mutex;
  186. int adc;
  187. /* muic current attached device */
  188. enum muic_attached_dev attached_dev;
  189. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  190. bool is_factory_start;
  191. #endif
  192. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  193. bool is_rustproof;
  194. #endif
  195. };
  196. static struct tsu6721_usbsw *local_usbsw;
  197. static int tsu6721_attach_dev(struct tsu6721_usbsw *usbsw);
  198. static int tsu6721_detach_dev(struct tsu6721_usbsw *usbsw);
  199. static int tsu6721_write_reg(struct i2c_client *client, int reg, int val)
  200. {
  201. int ret;
  202. ret = i2c_smbus_write_byte_data(client, reg, val);
  203. if (ret < 0)
  204. {
  205. dev_err(&client->dev,
  206. "%s, i2c write error %d\n",__func__, ret);
  207. }
  208. return ret;
  209. }
  210. static int tsu6721_read_reg(struct i2c_client *client, int reg)
  211. {
  212. int ret;
  213. ret = i2c_smbus_read_byte_data(client, reg);
  214. if (ret < 0)
  215. {
  216. dev_err(&client->dev,
  217. "%s, i2c read error %d\n",__func__, ret);
  218. }
  219. return ret;
  220. }
  221. static void tsu6721_disable_interrupt(void)
  222. {
  223. struct i2c_client *client = local_usbsw->client;
  224. int value, ret;
  225. value = i2c_smbus_read_byte_data(client, REG_CONTROL);
  226. value |= CON_INT_MASK;
  227. ret = i2c_smbus_write_byte_data(client, REG_CONTROL, value);
  228. if (ret < 0)
  229. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  230. }
  231. static void tsu6721_enable_interrupt(void)
  232. {
  233. struct i2c_client *client = local_usbsw->client;
  234. int value, ret;
  235. value = i2c_smbus_read_byte_data(client, REG_CONTROL);
  236. value &= (~CON_INT_MASK);
  237. ret = i2c_smbus_write_byte_data(client, REG_CONTROL, value);
  238. if (ret < 0)
  239. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  240. }
  241. static void tsu6721_dock_control(struct tsu6721_usbsw *usbsw,
  242. int dock_type, int state, int path)
  243. {
  244. struct i2c_client *client = usbsw->client;
  245. struct tsu6721_platform_data *pdata = usbsw->pdata;
  246. int ret;
  247. if (state) {
  248. usbsw->mansw = path;
  249. pdata->callback(dock_type, state);
  250. if (dock_type == CABLE_TYPE_DESK_DOCK_NO_VB)
  251. switch_set_state(&switch_dock, state);
  252. ret = i2c_smbus_write_byte_data(client, REG_MANUAL_SW1, path);
  253. if (ret < 0)
  254. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  255. ret = i2c_smbus_read_byte_data(client, REG_CONTROL);
  256. if (ret < 0)
  257. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  258. else {
  259. ret = i2c_smbus_write_byte_data(client,
  260. REG_CONTROL, ret & ~CON_MANUAL_SW);
  261. }
  262. if (ret < 0)
  263. dev_err(&client->dev, "%s: err %x\n", __func__, ret);
  264. } else {
  265. pdata->callback(dock_type, state);
  266. if (dock_type == CABLE_TYPE_DESK_DOCK_NO_VB)
  267. switch_set_state(&switch_dock, state);
  268. ret = i2c_smbus_read_byte_data(client, REG_CONTROL);
  269. if (ret < 0)
  270. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  271. ret = i2c_smbus_write_byte_data(client, REG_CONTROL,
  272. ret | CON_MANUAL_SW | CON_RAW_DATA);
  273. if (ret < 0)
  274. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  275. }
  276. }
  277. static void tsu6721_reg_init(struct tsu6721_usbsw *usbsw)
  278. {
  279. struct i2c_client *client = usbsw->client;
  280. unsigned int ctrl = CON_MASK;
  281. int ret;
  282. pr_info("tsu6721_reg_init is called\n");
  283. usbsw->dev_id = i2c_smbus_read_byte_data(client, REG_DEVICE_ID);
  284. local_usbsw->dev_id = usbsw->dev_id;
  285. if (usbsw->dev_id < 0)
  286. dev_err(&client->dev, "%s: err %d\n", __func__, usbsw->dev_id);
  287. dev_info(&client->dev, " tsu6721_reg_init dev ID: 0x%x\n",
  288. usbsw->dev_id);
  289. ret = i2c_smbus_write_byte_data(client, REG_INT_MASK1, INT_MASK1);
  290. if (ret < 0)
  291. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  292. ret = i2c_smbus_write_byte_data(client, REG_INT_MASK2, INT_MASK2);
  293. if (ret < 0)
  294. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  295. usbsw->mansw = i2c_smbus_read_byte_data(client, REG_MANUAL_SW1);
  296. if (usbsw->mansw < 0)
  297. dev_err(&client->dev, "%s: err %d\n", __func__, usbsw->mansw);
  298. if (usbsw->mansw)
  299. ctrl &= ~CON_MANUAL_SW; /* Manual Switching Mode */
  300. else
  301. ctrl &= ~(CON_INT_MASK);
  302. ret = i2c_smbus_write_byte_data(client, REG_OCL_OCP_SET1, 0x29);
  303. if (ret < 0)
  304. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  305. ret = i2c_smbus_write_byte_data(client, REG_OCL_OCP_SET2, 0x1A);
  306. if (ret < 0)
  307. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  308. ret = i2c_smbus_write_byte_data(client, REG_CONTROL, ctrl);
  309. if (ret < 0)
  310. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  311. ret = i2c_smbus_write_byte_data(client, REG_TIMING_SET1, 0xb);
  312. if (ret < 0)
  313. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  314. }
  315. static ssize_t tsu6721_muic_show_attached_dev(struct device *dev,
  316. struct device_attribute *attr,
  317. char *buf)
  318. {
  319. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  320. pr_info("[MUIC] TSU6721:%s attached_dev:%d\n",
  321. __func__,usbsw->attached_dev);
  322. switch(usbsw->attached_dev) {
  323. case ATTACHED_DEV_NONE_MUIC:
  324. return sprintf(buf, "No VPS\n");
  325. case ATTACHED_DEV_USB_MUIC:
  326. return sprintf(buf, "USB\n");
  327. case ATTACHED_DEV_CDP_MUIC:
  328. return sprintf(buf, "CDP\n");
  329. case ATTACHED_DEV_OTG_MUIC:
  330. return sprintf(buf, "OTG\n");
  331. case ATTACHED_DEV_TA_MUIC:
  332. return sprintf(buf, "TA\n");
  333. case ATTACHED_DEV_JIG_UART_OFF_MUIC:
  334. return sprintf(buf, "JIG UART OFF\n");
  335. case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC:
  336. return sprintf(buf, "JIG UART OFF/VB\n");
  337. case ATTACHED_DEV_JIG_UART_ON_MUIC:
  338. return sprintf(buf, "JIG UART ON\n");
  339. case ATTACHED_DEV_JIG_USB_OFF_MUIC:
  340. return sprintf(buf, "JIG USB OFF\n");
  341. case ATTACHED_DEV_JIG_USB_ON_MUIC:
  342. return sprintf(buf, "JIG USB ON\n");
  343. case ATTACHED_DEV_DESKDOCK_MUIC:
  344. return sprintf(buf, "DESKDOCK\n");
  345. case ATTACHED_DEV_AUDIODOCK_MUIC:
  346. return sprintf(buf, "AUDIODOCK\n");
  347. default:
  348. break;
  349. }
  350. return sprintf(buf, "UNKNOWN\n");
  351. }
  352. static ssize_t tsu6721_show_control(struct device *dev,
  353. struct device_attribute *attr,
  354. char *buf)
  355. {
  356. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  357. struct i2c_client *client = usbsw->client;
  358. int value;
  359. value = i2c_smbus_read_byte_data(client, REG_CONTROL);
  360. if (value < 0)
  361. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  362. return snprintf(buf, 13, "CONTROL: %02x\n", value);
  363. }
  364. static ssize_t tsu6721_show_device_type(struct device *dev,
  365. struct device_attribute *attr,
  366. char *buf)
  367. {
  368. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  369. struct i2c_client *client = usbsw->client;
  370. int value;
  371. value = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE1);
  372. if (value < 0)
  373. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  374. return snprintf(buf, 11, "DEV_TYP %02x\n", value);
  375. }
  376. static ssize_t tsu6721_show_manualsw(struct device *dev,
  377. struct device_attribute *attr, char *buf)
  378. {
  379. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  380. struct i2c_client *client = usbsw->client;
  381. int value;
  382. value = i2c_smbus_read_byte_data(client, REG_MANUAL_SW1);
  383. if (value < 0)
  384. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  385. if (value == SW_VAUDIO)
  386. return snprintf(buf, 7, "VAUDIO\n");
  387. else if (value == SW_UART)
  388. return snprintf(buf, 5, "UART\n");
  389. else if (value == SW_AUDIO)
  390. return snprintf(buf, 6, "AUDIO\n");
  391. else if (value == SW_DHOST)
  392. return snprintf(buf, 6, "DHOST\n");
  393. else if (value == SW_AUTO)
  394. return snprintf(buf, 5, "AUTO\n");
  395. else
  396. return snprintf(buf, 4, "%x", value);
  397. }
  398. static ssize_t tsu6721_set_manualsw(struct device *dev,
  399. struct device_attribute *attr,
  400. const char *buf, size_t count)
  401. {
  402. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  403. struct i2c_client *client = usbsw->client;
  404. int value, ret;
  405. unsigned int path = 0;
  406. value = i2c_smbus_read_byte_data(client, REG_CONTROL);
  407. if (value < 0)
  408. dev_err(&client->dev, "%s: err %d\n", __func__, value);
  409. if ((value & ~CON_MANUAL_SW) !=
  410. (CON_SWITCH_OPEN | CON_RAW_DATA | CON_WAIT))
  411. return 0;
  412. if (!strncmp(buf, "VAUDIO", 6)) {
  413. path = SW_VAUDIO;
  414. value &= ~CON_MANUAL_SW;
  415. } else if (!strncmp(buf, "UART", 4)) {
  416. path = SW_UART;
  417. value &= ~CON_MANUAL_SW;
  418. } else if (!strncmp(buf, "AUDIO", 5)) {
  419. path = SW_AUDIO;
  420. value &= ~CON_MANUAL_SW;
  421. } else if (!strncmp(buf, "DHOST", 5)) {
  422. path = SW_DHOST;
  423. value &= ~CON_MANUAL_SW;
  424. } else if (!strncmp(buf, "AUTO", 4)) {
  425. path = SW_AUTO;
  426. value |= CON_MANUAL_SW;
  427. } else {
  428. dev_err(dev, "Wrong command\n");
  429. return 0;
  430. }
  431. usbsw->mansw = path;
  432. ret = i2c_smbus_write_byte_data(client, REG_MANUAL_SW1, path);
  433. if (ret < 0)
  434. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  435. ret = i2c_smbus_write_byte_data(client, REG_CONTROL, value);
  436. if (ret < 0)
  437. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  438. return count;
  439. }
  440. static ssize_t tsu6721_show_usb_state(struct device *dev,
  441. struct device_attribute *attr,
  442. char *buf)
  443. {
  444. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  445. struct i2c_client *client = usbsw->client;
  446. int device_type1, device_type2;
  447. device_type1 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE1);
  448. if (device_type1 < 0) {
  449. dev_err(&client->dev, "%s: err %d ", __func__, device_type1);
  450. return (ssize_t)device_type1;
  451. }
  452. device_type2 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE2);
  453. if (device_type2 < 0) {
  454. dev_err(&client->dev, "%s: err %d ", __func__, device_type2);
  455. return (ssize_t)device_type2;
  456. }
  457. if (device_type1 & DEV_T1_USB_MASK || device_type2 & DEV_T2_USB_MASK)
  458. return snprintf(buf, 22, "USB_STATE_CONFIGURED\n");
  459. return snprintf(buf, 25, "USB_STATE_NOTCONFIGURED\n");
  460. }
  461. static ssize_t tsu6721_show_adc(struct device *dev,
  462. struct device_attribute *attr,
  463. char *buf)
  464. {
  465. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  466. struct i2c_client *client = usbsw->client;
  467. int adc;
  468. adc = i2c_smbus_read_byte_data(client, REG_ADC);
  469. if (adc < 0) {
  470. dev_err(&client->dev,
  471. "%s: err at read adc %d\n", __func__, adc);
  472. return snprintf(buf, 9, "UNKNOWN\n");
  473. }
  474. return snprintf(buf, 4, "%x\n", adc);
  475. }
  476. static ssize_t tsu6721_reset(struct device *dev,
  477. struct device_attribute *attr,
  478. const char *buf, size_t count)
  479. {
  480. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  481. struct i2c_client *client = usbsw->client;
  482. if (!strncmp(buf, "1", 1)) {
  483. dev_info(&client->dev,
  484. "tsu6721 reset after delay 1000 msec.\n");
  485. msleep(1000);
  486. tsu6721_write_reg(client, REG_RESET, 0x01);
  487. dev_info(&client->dev, "tsu6721_reset_control done!\n");
  488. } else {
  489. dev_info(&client->dev,
  490. "tsu6721_reset_control, but not reset_value!\n");
  491. }
  492. #ifdef CONFIG_MUIC_SUPPORT_RUSTPROOF
  493. usbsw->is_rustproof = false;
  494. #endif
  495. usbsw->attached_dev = ATTACHED_DEV_NONE_MUIC;
  496. tsu6721_reg_init(usbsw);
  497. return count;
  498. }
  499. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  500. static ssize_t tsu6721_show_apo_factory(struct device *dev,
  501. struct device_attribute *attr,
  502. char *buf)
  503. {
  504. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  505. const char *mode;
  506. /* true: Factory mode, false: not Factory mode */
  507. if (usbsw->is_factory_start)
  508. mode = "FACTORY_MODE";
  509. else
  510. mode = "NOT_FACTORY_MODE";
  511. pr_info("%s apo factory=%s\n", __func__, mode);
  512. return sprintf(buf, "%s\n", mode);
  513. }
  514. static int tsu6721_attach_dev(struct tsu6721_usbsw *usbsw);
  515. static ssize_t tsu6721_set_apo_factory(struct device *dev,
  516. struct device_attribute *attr,
  517. const char *buf, size_t count)
  518. {
  519. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  520. pr_info("%s buf:%s\n", __func__, buf);
  521. /* "FACTORY_START": factory mode */
  522. if (!strncmp(buf, "FACTORY_START", 13)) {
  523. usbsw->is_factory_start = true;
  524. pr_info("%s FACTORY_MODE\n", __func__);
  525. tsu6721_attach_dev(usbsw);
  526. } else {
  527. pr_warn("%s Wrong command\n", __func__);
  528. return count;
  529. }
  530. return count;
  531. }
  532. #endif
  533. #ifdef CONFIG_MUIC_SUPPORT_RUSTPROOF
  534. static void muic_rustproof_feature(struct i2c_client *client, int state);
  535. /* Keystring "*#0*#" sysfs implementation */
  536. static ssize_t uart_en_show(struct device *dev,
  537. struct device_attribute *attr, char *buf)
  538. {
  539. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  540. /*is_rustproof is false then UART can be enabled*/
  541. return snprintf(buf, 4, "%d\n", !(usbsw->is_rustproof));
  542. }
  543. static ssize_t uart_en_store(struct device *dev,
  544. struct device_attribute *attr,
  545. const char *buf, size_t size)
  546. {
  547. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  548. struct i2c_client *client = usbsw->client;
  549. if (!strncmp(buf, "1", 1)) {
  550. dev_info(&client->dev,
  551. "[MUIC]Runtime enabling the UART.\n");
  552. usbsw->is_rustproof = false;
  553. muic_rustproof_feature(client,TSU6721_DETACHED);
  554. } else {
  555. dev_info(&client->dev,
  556. "[MUIC]Runtime disabling the UART.\n");
  557. usbsw->is_rustproof = true;
  558. }
  559. /* reinvoke the attach detection function to set proper paths */
  560. tsu6721_attach_dev(usbsw);
  561. return size;
  562. }
  563. static DEVICE_ATTR(uart_en, S_IRUGO | S_IWUSR ,
  564. uart_en_show, uart_en_store);
  565. static ssize_t uart_sel_show(struct device *dev,
  566. struct device_attribute *attr, char *buf)
  567. {
  568. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  569. /*for sm5502 paths are always switch to AP*/
  570. if(usbsw->attached_dev != ATTACHED_DEV_NONE_MUIC)
  571. return snprintf(buf, 4, "AP\n");
  572. else
  573. return snprintf(buf, 9, "UNKNOWN\n");
  574. }
  575. static ssize_t uart_sel_store(struct device *dev,
  576. struct device_attribute *attr,
  577. const char *buf, size_t size)
  578. {
  579. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  580. struct i2c_client *client = usbsw->client;
  581. dev_info(&client->dev,"[MUIC]Enabling AP UART Path, dummy Call\n");
  582. return size;
  583. }
  584. static DEVICE_ATTR(uart_sel, S_IRUGO | S_IWUSR ,
  585. uart_sel_show, uart_sel_store);
  586. static ssize_t usbsel_show(struct device *dev,
  587. struct device_attribute *attr, char *buf)
  588. {
  589. return snprintf(buf, 4, "PDA\n");
  590. }
  591. static ssize_t usbsel_store(struct device *dev,
  592. struct device_attribute *attr,
  593. const char *buf, size_t size)
  594. {
  595. struct tsu6721_usbsw *usbsw = dev_get_drvdata(dev);
  596. struct i2c_client *client = usbsw->client;
  597. dev_info(&client->dev,"[MUIC]Enabling AP UART Path, dummy Call\n");
  598. return size;
  599. }
  600. static DEVICE_ATTR(usb_sel, S_IRUGO | S_IWUSR ,
  601. usbsel_show, usbsel_store);
  602. #endif
  603. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  604. static DEVICE_ATTR(apo_factory, 0664, tsu6721_show_apo_factory,
  605. tsu6721_set_apo_factory);
  606. #endif
  607. static DEVICE_ATTR(control, S_IRUGO, tsu6721_show_control, NULL);
  608. static DEVICE_ATTR(device_type, S_IRUGO, tsu6721_show_device_type, NULL);
  609. static DEVICE_ATTR(switch, S_IRUGO | S_IWUSR,
  610. tsu6721_show_manualsw, tsu6721_set_manualsw);
  611. static DEVICE_ATTR(usb_state, S_IRUGO, tsu6721_show_usb_state, NULL);
  612. static DEVICE_ATTR(adc, S_IRUGO, tsu6721_show_adc, NULL);
  613. static DEVICE_ATTR(reset_switch, S_IWUSR | S_IWGRP, NULL, tsu6721_reset);
  614. static DEVICE_ATTR(attached_dev, S_IRUGO, tsu6721_muic_show_attached_dev, NULL);
  615. static struct attribute *tsu6721_attributes[] = {
  616. &dev_attr_control.attr,
  617. &dev_attr_device_type.attr,
  618. &dev_attr_switch.attr,
  619. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  620. &dev_attr_apo_factory.attr,
  621. #endif
  622. NULL
  623. };
  624. static const struct attribute_group tsu6721_group = {
  625. .attrs = tsu6721_attributes,
  626. };
  627. #if (!defined(CONFIG_MACH_CT01) && !defined(CONFIG_MACH_CT01_CHN_CU))
  628. #define PMIC_SLAVE_ID 0x0
  629. #define PMIC_SMBBP_BAT_IF_BPD_CTRL 0x1248
  630. /* control flash function without BAT_ID */
  631. static void flash_control(bool en) {
  632. u8 sid = PMIC_SLAVE_ID;
  633. u8 buf[16];
  634. int addr = PMIC_SMBBP_BAT_IF_BPD_CTRL;
  635. spmi_ext_register_readl_extra(sid, addr, buf, 1);
  636. if (en)
  637. buf[0] &= ~BIT(0);
  638. else
  639. buf[0] |= BIT(0);
  640. spmi_ext_register_writel_extra(sid, addr, buf, 1);
  641. }
  642. #endif
  643. #if defined(CONFIG_USB_HOST_NOTIFY)
  644. static void tsu6721_set_otg(struct tsu6721_usbsw *usbsw, int state)
  645. {
  646. int ret;
  647. struct i2c_client *client = usbsw->client;
  648. if (state == TSU6721_ATTACHED) {
  649. ret = i2c_smbus_write_byte_data(client, REG_MANUAL_SW1, 0x25);
  650. if (ret < 0)
  651. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  652. ret = i2c_smbus_write_byte_data(client, REG_MANUAL_SW2, 0x02);
  653. if (ret < 0)
  654. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  655. ret = i2c_smbus_write_byte_data(client, REG_CONTROL, 0x1A);
  656. if (ret < 0)
  657. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  658. } else {
  659. ret = i2c_smbus_write_byte_data(client, REG_MANUAL_SW2, 0x00);
  660. if (ret < 0)
  661. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  662. ret = i2c_smbus_write_byte_data(client, REG_MANUAL_SW1,
  663. SW_ALL_OPEN);
  664. if (ret < 0)
  665. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  666. ret = i2c_smbus_write_byte_data(client, REG_CONTROL, 0x1E);
  667. if (ret < 0)
  668. dev_info(&client->dev, "%s: err %d\n", __func__, ret);
  669. }
  670. }
  671. #endif
  672. #if defined(CONFIG_VIDEO_MHL_V2)
  673. int dock_det(void)
  674. {
  675. return local_usbsw->dock_attached;
  676. }
  677. EXPORT_SYMBOL(dock_det);
  678. #endif
  679. int check_jig_state(void)
  680. {
  681. return jig_state;
  682. }
  683. EXPORT_SYMBOL(check_jig_state);
  684. #if defined(CONFIG_TOUCHSCREEN_MMS144)
  685. extern void tsp_charger_infom(bool en);
  686. #endif
  687. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  688. static void muic_rustproof_feature(struct i2c_client *client, int state)
  689. {
  690. int val;
  691. if(state) {
  692. val = i2c_smbus_write_byte_data(client, REG_MANUAL_SW1,
  693. SW_ALL_OPEN_WITH_VBUS);
  694. if(val < 0)
  695. dev_info(&client->dev, "%s:MANUAL SW1,err %d\n",__func__,val);
  696. val = i2c_smbus_read_byte_data(client,REG_CONTROL);
  697. if(val < 0)
  698. dev_info(&client->dev, "%s:CTRL REG,err %d\n",__func__,val);
  699. val &= 0xFB;
  700. val = i2c_smbus_write_byte_data(client,REG_CONTROL,val);
  701. if(val < 0)
  702. dev_info(&client->dev, "%s:CTRL REG,err %d\n",__func__,val);
  703. } else
  704. {
  705. val = i2c_smbus_write_byte_data(client, REG_MANUAL_SW2, 0x00);
  706. if (val < 0)
  707. dev_info(&client->dev, "%s: MANUAL SW2,err %d\n", __func__,val);
  708. val = i2c_smbus_write_byte_data(client, REG_MANUAL_SW1,SW_ALL_OPEN);
  709. if (val < 0)
  710. dev_info(&client->dev, "%s: MANUAL SW1,err %d\n", __func__,val);
  711. val = i2c_smbus_read_byte_data(client, REG_CONTROL);
  712. if (val < 0)
  713. dev_info(&client->dev, "%s: CTRL REG,err %d\n", __func__,val);
  714. val = val | 0x04; /*Automatic Connection S/W enable*/
  715. val = i2c_smbus_write_byte_data(client, REG_CONTROL, val);
  716. if (val < 0)
  717. dev_info(&client->dev, "%s: CTRL REG,err %d\n", __func__,val);
  718. }
  719. }
  720. #endif
  721. static void muic_update_jig_state(struct tsu6721_usbsw *usbsw, int dev_type2, int vbus)
  722. {
  723. if(dev_type2 & DEV_JIG_UART_OFF && !vbus)
  724. usbsw->attached_dev = ATTACHED_DEV_JIG_UART_OFF_MUIC;
  725. else if(dev_type2 & DEV_JIG_UART_OFF && vbus)
  726. usbsw->attached_dev = ATTACHED_DEV_JIG_UART_OFF_VB_MUIC;
  727. else if(dev_type2 & DEV_JIG_UART_ON)
  728. usbsw->attached_dev = ATTACHED_DEV_JIG_UART_ON_MUIC;
  729. else if(dev_type2 & DEV_JIG_USB_OFF)
  730. usbsw->attached_dev = ATTACHED_DEV_JIG_USB_OFF_MUIC;
  731. else if(dev_type2 & DEV_JIG_USB_ON)
  732. usbsw->attached_dev = ATTACHED_DEV_JIG_USB_ON_MUIC;
  733. }
  734. static int tsu6721_attach_dev(struct tsu6721_usbsw *usbsw)
  735. {
  736. int adc;
  737. int val1, val2, val3;
  738. struct tsu6721_platform_data *pdata = usbsw->pdata;
  739. struct i2c_client *client = usbsw->client;
  740. #if defined(CONFIG_VIDEO_MHL_V2)
  741. /*u8 mhl_ret = 0;*/
  742. #endif
  743. #if defined(CONFIG_TOUCHSCREEN_MMS144)
  744. int tsp_noti_ignore = 0;
  745. #endif
  746. val1 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE1);
  747. if (val1 < 0) {
  748. dev_err(&client->dev, "%s: err %d\n", __func__, val1);
  749. return val1;
  750. }
  751. val2 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE2);
  752. if (val2 < 0) {
  753. dev_err(&client->dev, "%s: err %d\n", __func__, val2);
  754. return val2;
  755. }
  756. jig_state = (val2 & DEV_T2_JIG_ALL_MASK) ? 1 : 0;
  757. val3 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE3);
  758. if (val3 < 0) {
  759. dev_err(&client->dev, "%s: err %d\n", __func__, val3);
  760. return val3;
  761. }
  762. adc = i2c_smbus_read_byte_data(client, REG_ADC);
  763. if (adc == ADC_SMART_DOCK) {
  764. val2 = DEV_SMARTDOCK;
  765. val1 = 0;
  766. }
  767. #if defined(CONFIG_USB_HOST_NOTIFY)
  768. if (adc == 0x11 || adc == ADC_AUDIO_DOCK) {
  769. val2 = DEV_AUDIO_DOCK;
  770. val1 = 0;
  771. }
  772. #endif
  773. if (adc == ADC_LG_CABLE) {
  774. val2 = DEV_LG_CABLE;
  775. val1 = 0;
  776. }
  777. dev_err(&client->dev,
  778. "dev1: 0x%x, dev2: 0x%x, dev3: 0x%x, ADC: 0x%x Jig:%s\n",
  779. val1, val2, val3, adc,
  780. (check_jig_state() ? "ON" : "OFF"));
  781. /* USB */
  782. if (val1 & DEV_USB) {
  783. pr_info("[MUIC] USB Connected\n");
  784. usbsw->attached_dev = ATTACHED_DEV_USB_MUIC;
  785. pdata->callback(CABLE_TYPE_USB, TSU6721_ATTACHED);
  786. /* USB_CDP */
  787. } else if (val1 & DEV_USB_CHG) {
  788. pr_info("[MUIC] CDP Connected\n");
  789. usbsw->attached_dev = ATTACHED_DEV_CDP_MUIC;
  790. pdata->callback(CABLE_TYPE_CDP, TSU6721_ATTACHED);
  791. /* UART FACTORY JIG CASE*/
  792. } else if (val1 & DEV_T1_UART_MASK || val2 & DEV_T2_UART_MASK) {
  793. uart_connecting = 1;
  794. muic_update_jig_state(usbsw,val2,(val3 & DEV_VBUS_DEBOUNCE));
  795. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  796. if(usbsw->is_rustproof) {
  797. pr_info("[MUIC] RustProof mode, close UART Path\n");
  798. muic_rustproof_feature(client,TSU6721_ATTACHED);
  799. } else
  800. #endif
  801. {
  802. pr_info("[MUIC] UART Connected\n");
  803. if((adc == ADC_JIG_UART_OFF) && (val3 & DEV_VBUS_DEBOUNCE))
  804. pdata->callback(CABLE_TYPE_JIG_UART_OFF_VB, TSU6721_ATTACHED);
  805. else
  806. pdata->callback(CABLE_TYPE_UARTOFF, TSU6721_ATTACHED);
  807. #if (!defined(CONFIG_MACH_CT01) && !defined(CONFIG_MACH_CT01_CHN_CU))
  808. flash_control(true);
  809. #endif
  810. }
  811. /* CHARGER */
  812. } else if ((val1 & DEV_T1_CHARGER_MASK) ||
  813. (val3 & DEV_T3_CHARGER_MASK)) {
  814. pr_info("[MUIC] Charger Connected\n");
  815. usbsw->attached_dev = ATTACHED_DEV_TA_MUIC;
  816. pdata->callback(CABLE_TYPE_AC, TSU6721_ATTACHED);
  817. #if defined(CONFIG_USB_HOST_NOTIFY)
  818. /* for SAMSUNG OTG */
  819. } else if (val1 & DEV_USB_OTG) {
  820. pr_info("[MUIC] OTG Connected\n");
  821. usbsw->attached_dev = ATTACHED_DEV_OTG_MUIC;
  822. tsu6721_set_otg(usbsw, TSU6721_ATTACHED);
  823. pdata->callback(CABLE_TYPE_OTG, TSU6721_ATTACHED);
  824. #endif
  825. /* JIG */
  826. } else if (val2 & DEV_T2_USB_MASK) {
  827. pr_info("[MUIC] JIG USB Connected\n");
  828. muic_update_jig_state(usbsw,val2,(val3 & DEV_VBUS_DEBOUNCE));
  829. if(val3 & DEV_VBUS_DEBOUNCE)
  830. pdata->callback(CABLE_TYPE_USB, TSU6721_ATTACHED);
  831. else
  832. pdata->callback(CABLE_TYPE_JIG, TSU6721_ATTACHED);
  833. #if (!defined(CONFIG_MACH_CT01) && !defined(CONFIG_MACH_CT01_CHN_CU))
  834. flash_control(true);
  835. #endif
  836. /* Desk Dock */
  837. } else if ((val2 & DEV_AV) || (val3 & DEV_AV_VBUS)) {
  838. pr_info("[MUIC] Deskdock Connected\n");
  839. usbsw->attached_dev = ATTACHED_DEV_DESKDOCK_MUIC;
  840. local_usbsw->dock_attached = TSU6721_ATTACHED;
  841. if(val3 & DEV_VBUS_DEBOUNCE)
  842. tsu6721_dock_control(usbsw, CABLE_TYPE_DESK_DOCK,
  843. TSU6721_ATTACHED, SW_AUDIO);
  844. else
  845. tsu6721_dock_control(usbsw, CABLE_TYPE_DESK_DOCK_NO_VB,
  846. TSU6721_ATTACHED, SW_AUDIO);
  847. #if defined(CONFIG_VIDEO_MHL_V2)
  848. /* MHL */
  849. } else if (val3 & DEV_MHL) {
  850. pr_info("[MUIC] MHL Connected\n");
  851. tsu6721_disable_interrupt();
  852. if (!poweroff_charging)
  853. /*mhl_ret = mhl_onoff_ex(1); support from sii8240*/
  854. else
  855. pr_info("LPM mode, skip MHL sequence\n");
  856. tsu6721_enable_interrupt();
  857. #endif
  858. /* Car Dock */
  859. } else if (val2 & DEV_JIG_UART_ON) {
  860. muic_update_jig_state(usbsw,val2,(val3 & DEV_VBUS_DEBOUNCE));
  861. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  862. if (usbsw->is_factory_start) {
  863. #endif
  864. pr_info("[MUIC] Cardock Connected\n");
  865. local_usbsw->dock_attached = TSU6721_ATTACHED;
  866. tsu6721_dock_control(usbsw, CABLE_TYPE_CARDOCK,
  867. TSU6721_ATTACHED, SW_AUDIO);
  868. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  869. } else {
  870. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  871. if(usbsw->is_rustproof) {
  872. pr_info("[MUIC] RustProof mode, close UART Path\n");
  873. muic_rustproof_feature(client,TSU6721_ATTACHED);
  874. } else
  875. #endif
  876. {
  877. uart_connecting = 1;
  878. pr_info("[MUIC] UART Connected\n");
  879. pdata->callback(CABLE_TYPE_UARTOFF, TSU6721_ATTACHED);
  880. }
  881. }
  882. #endif
  883. /* SmartDock */
  884. } else if (val2 & DEV_SMARTDOCK) {
  885. pr_info("[MUIC] Smartdock Connected\n");
  886. tsu6721_dock_control(usbsw, CABLE_TYPE_SMART_DOCK,
  887. TSU6721_ATTACHED, SW_DHOST);
  888. #if defined(CONFIG_VIDEO_MHL_V2)
  889. /*mhl_onoff_ex(1); support can be added once mhl is up*/
  890. #endif
  891. #if defined(CONFIG_USB_HOST_NOTIFY)
  892. /* Audio Dock */
  893. } else if (val2 & DEV_AUDIO_DOCK) {
  894. pr_info("[MUIC] Audiodock Connected\n");
  895. usbsw->attached_dev = ATTACHED_DEV_AUDIODOCK_MUIC;
  896. tsu6721_dock_control(usbsw, CABLE_TYPE_AUDIO_DOCK,
  897. TSU6721_ATTACHED, SW_DHOST);
  898. #endif
  899. /*LG cable support*/
  900. } else if (val2 & DEV_LG_CABLE) {
  901. pr_info("[MUIC] LG Data Cable connected \n");
  902. usbsw->attached_dev = ATTACHED_DEV_USB_MUIC;
  903. pdata->callback(CABLE_TYPE_USB, TSU6721_ATTACHED);
  904. /* Incompatible */
  905. } else if (val3 & DEV_VBUS_DEBOUNCE) {
  906. pr_info("[MUIC] Incompatible Charger Connected\n");
  907. usbsw->attached_dev = ATTACHED_DEV_UNKNOWN_MUIC;
  908. pdata->callback(CABLE_TYPE_INCOMPATIBLE,
  909. TSU6721_ATTACHED);
  910. }
  911. #if defined(CONFIG_TOUCHSCREEN_MMS144)
  912. else{
  913. tsp_noti_ignore = 1;
  914. printk("[TSP] attached, but don't noti \n");
  915. }
  916. if(!tsp_noti_ignore)
  917. tsp_charger_infom(1);
  918. #endif
  919. usbsw->dev1 = val1;
  920. usbsw->dev2 = val2;
  921. usbsw->dev3 = val3;
  922. usbsw->adc = adc;
  923. return adc;
  924. }
  925. static int tsu6721_detach_dev(struct tsu6721_usbsw *usbsw)
  926. {
  927. struct tsu6721_platform_data *pdata = usbsw->pdata;
  928. #if defined(CONFIG_TOUCHSCREEN_MMS144)
  929. int tsp_noti_ignore = 0;
  930. #endif
  931. /* USB */
  932. if (usbsw->dev1 & DEV_USB) {
  933. pr_info("[MUIC] USB Disonnected\n");
  934. pdata->callback(CABLE_TYPE_USB, TSU6721_DETACHED);
  935. } else if (usbsw->dev1 & DEV_USB_CHG) {
  936. pdata->callback(CABLE_TYPE_CDP, TSU6721_DETACHED);
  937. /* UART */
  938. } else if (usbsw->dev1 & DEV_T1_UART_MASK ||
  939. usbsw->dev2 & DEV_T2_UART_MASK) {
  940. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  941. if(usbsw->is_rustproof) {
  942. pr_info("[MUIC] RustProof mode Disconnected Event\n");
  943. muic_rustproof_feature(usbsw->client,TSU6721_DETACHED);
  944. } else
  945. #endif
  946. {
  947. pr_info("[MUIC] UART Disonnected\n");
  948. if((usbsw->adc == ADC_JIG_UART_OFF) && (usbsw->dev3 & DEV_VBUS_DEBOUNCE))
  949. pdata->callback(CABLE_TYPE_JIG_UART_OFF_VB, TSU6721_DETACHED);
  950. else
  951. pdata->callback(CABLE_TYPE_UARTOFF, TSU6721_DETACHED);
  952. uart_connecting = 0;
  953. #if (!defined(CONFIG_MACH_CT01) && !defined(CONFIG_MACH_CT01_CHN_CU))
  954. flash_control(false);
  955. #endif
  956. }
  957. /* CHARGER */
  958. } else if ((usbsw->dev1 & DEV_T1_CHARGER_MASK) ||
  959. (usbsw->dev3 & DEV_T3_CHARGER_MASK)) {
  960. pr_info("[MUIC] Charger Disonnected\n");
  961. pdata->callback(CABLE_TYPE_AC, TSU6721_DETACHED);
  962. #if defined(CONFIG_USB_HOST_NOTIFY)
  963. /* for SAMSUNG OTG */
  964. } else if (usbsw->dev1 & DEV_USB_OTG) {
  965. pr_info("[MUIC] OTG Disonnected\n");
  966. tsu6721_set_otg(usbsw, TSU6721_DETACHED);
  967. pdata->callback(CABLE_TYPE_OTG, TSU6721_DETACHED);
  968. #endif
  969. /* JIG */
  970. } else if (usbsw->dev2 & DEV_T2_USB_MASK) {
  971. pr_info("[MUIC] JIG USB Disonnected\n");
  972. if(usbsw->dev3 & DEV_VBUS_DEBOUNCE)
  973. pdata->callback(CABLE_TYPE_USB, TSU6721_DETACHED);
  974. else
  975. pdata->callback(CABLE_TYPE_JIG, TSU6721_DETACHED);
  976. #if (!defined(CONFIG_MACH_CT01) && !defined(CONFIG_MACH_CT01_CHN_CU))
  977. flash_control(false);
  978. #endif
  979. /* Desk Dock */
  980. } else if ((usbsw->dev2 & DEV_AV) ||
  981. (usbsw->dev3 & DEV_AV_VBUS)) {
  982. pr_info("[MUIC] Deskdock Disonnected\n");
  983. local_usbsw->dock_attached = TSU6721_DETACHED;
  984. if(usbsw->dev3 & DEV_VBUS_DEBOUNCE)
  985. tsu6721_dock_control(usbsw, CABLE_TYPE_DESK_DOCK,
  986. TSU6721_DETACHED, SW_ALL_OPEN);
  987. else
  988. tsu6721_dock_control(usbsw, CABLE_TYPE_DESK_DOCK_NO_VB,
  989. TSU6721_DETACHED, SW_ALL_OPEN);
  990. #if defined(CONFIG_MHL_D3_SUPPORT)
  991. /* MHL */
  992. } else if (usbsw->dev3 & DEV_MHL) {
  993. pr_info("[MUIC] MHL Disonnected\n");
  994. //mhl_onoff_ex(false);
  995. detached_status = 1;
  996. #endif
  997. /* Car Dock */
  998. } else if (usbsw->dev2 & DEV_JIG_UART_ON) {
  999. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  1000. if (usbsw->is_factory_start) {
  1001. #endif
  1002. pr_info("[MUIC] Cardock Disonnected\n");
  1003. local_usbsw->dock_attached = TSU6721_DETACHED;
  1004. tsu6721_dock_control(usbsw, CABLE_TYPE_CARDOCK,
  1005. TSU6721_DETACHED, SW_ALL_OPEN);
  1006. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  1007. } else {
  1008. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  1009. if(usbsw->is_rustproof) {
  1010. pr_info("[MUIC] RustProof mode, disconnected Event\n");
  1011. muic_rustproof_feature(usbsw->client,TSU6721_DETACHED);
  1012. } else
  1013. #endif
  1014. {
  1015. pr_info("[MUIC] UART Disonnected\n");
  1016. pdata->callback(CABLE_TYPE_UARTOFF, TSU6721_DETACHED);
  1017. uart_connecting = 0;
  1018. }
  1019. }
  1020. #endif
  1021. /* Smart Dock */
  1022. } else if (usbsw->dev2 == DEV_SMARTDOCK) {
  1023. pr_info("[MUIC] Smartdock Disonnected\n");
  1024. tsu6721_dock_control(usbsw, CABLE_TYPE_SMART_DOCK,
  1025. TSU6721_DETACHED, SW_ALL_OPEN);
  1026. #if defined(CONFIG_VIDEO_MHL_V2)
  1027. //mhl_onoff_ex(false);
  1028. #endif
  1029. #if defined(CONFIG_USB_HOST_NOTIFY)
  1030. /* Audio Dock */
  1031. } else if (usbsw->dev2 == DEV_AUDIO_DOCK) {
  1032. pr_info("[MUIC] Audiodock Disonnected\n");
  1033. tsu6721_dock_control(usbsw, CABLE_TYPE_AUDIO_DOCK,
  1034. TSU6721_DETACHED, SW_ALL_OPEN);
  1035. #endif
  1036. /*LG cable support*/
  1037. } else if (usbsw->dev2 == DEV_LG_CABLE) {
  1038. pr_info("[MUIC] LG Data Cable Disconnected \n");
  1039. pdata->callback(CABLE_TYPE_USB, TSU6721_DETACHED);
  1040. /* Incompatible */
  1041. } else if (usbsw->dev3 & DEV_VBUS_DEBOUNCE) {
  1042. pr_info("[MUIC] Incompatible Charger Disonnected\n");
  1043. pdata->callback(CABLE_TYPE_INCOMPATIBLE,
  1044. TSU6721_DETACHED);
  1045. }
  1046. #if defined(CONFIG_TOUCHSCREEN_MMS144)
  1047. else{
  1048. tsp_noti_ignore = 1;
  1049. printk("[TSP] detached, but don't noti \n");
  1050. }
  1051. if(!tsp_noti_ignore)
  1052. tsp_charger_infom(0);
  1053. #endif
  1054. usbsw->dev1 = 0;
  1055. usbsw->dev2 = 0;
  1056. usbsw->dev3 = 0;
  1057. usbsw->adc = 0;
  1058. usbsw->attached_dev = ATTACHED_DEV_NONE_MUIC;
  1059. return 0;
  1060. }
  1061. static irqreturn_t tsu6721_irq_thread(int irq, void *data)
  1062. {
  1063. struct tsu6721_usbsw *usbsw = data;
  1064. struct i2c_client *client = usbsw->client;
  1065. int intr1, intr2;
  1066. int val1, val3, adc;
  1067. /* TSU6721 : Read interrupt -> Read Device */
  1068. pr_info("tsu6721_irq_thread is called\n");
  1069. mutex_lock(&usbsw->mutex);
  1070. tsu6721_disable_interrupt();
  1071. intr1 = i2c_smbus_read_byte_data(client, REG_INT1);
  1072. intr2 = i2c_smbus_read_byte_data(client, REG_INT2);
  1073. tsu6721_enable_interrupt();
  1074. adc = i2c_smbus_read_byte_data(client, REG_ADC);
  1075. dev_info(&client->dev, "%s: intr1: 0x%x, intr2: 0x%x, adc: 0x%x",
  1076. __func__, intr1, intr2, adc);
  1077. /* MUIC OVP Check */
  1078. if (intr1 & INT_OVP_ENABLE)
  1079. usbsw->pdata->oxp_callback(ENABLE);
  1080. else if (intr1 & INT_OXP_DISABLE)
  1081. usbsw->pdata->oxp_callback(DISABLE);
  1082. /* device detection */
  1083. /* interrupt both attach and detach */
  1084. if (intr1 == (INT_ATTACH + INT_DETACH)) {
  1085. val1 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE1);
  1086. val3 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE3);
  1087. if ((adc == ADC_OPEN) && (val1 == DATA_NONE) &&
  1088. ((val3 == DATA_NONE) ||
  1089. (val3 == DEV_VBUS_DEBOUNCE)))
  1090. tsu6721_detach_dev(usbsw);
  1091. else
  1092. tsu6721_attach_dev(usbsw);
  1093. }
  1094. /* interrupt attach */
  1095. else if (intr1 & INT_ATTACH || (intr2 & INT_RESERVED_ATTACH))
  1096. tsu6721_attach_dev(usbsw);
  1097. /* interrupt detach */
  1098. else if (intr1 & INT_DETACH)
  1099. tsu6721_detach_dev(usbsw);
  1100. else if (intr2 & INT_VBUS) {
  1101. dev_info(&client->dev,"[MUIC]: VBUSOUT_ON\n");
  1102. #ifdef CONFIG_USB_HOST_NOTIFY
  1103. sec_otg_notify(HNOTIFY_OTG_POWER_ON);
  1104. if(sec_get_notification(HNOTIFY_MODE) == NOTIFY_TEST_MODE)
  1105. goto exit_irq_handler;
  1106. #endif
  1107. /*Jig UART Boot-Off Or Deskdock VBUS Attached*/
  1108. if (adc == ADC_JIG_UART_OFF) {
  1109. tsu6721_attach_dev(usbsw);
  1110. } else if (adc == ADC_DESKDOCK) {
  1111. #if defined(DEBUG)
  1112. val1 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE1);
  1113. val3 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE3);
  1114. printk("%s, dev1 0x%x dev3 0x%x \n", __func__, val1, val3);
  1115. #endif
  1116. /*When VBUS is changing only, no need to switch paths again*/
  1117. usbsw->pdata->callback(CABLE_TYPE_DESK_DOCK, TSU6721_ATTACHED);
  1118. }
  1119. }
  1120. else if (intr2 & INT_AV_CHANGE) {
  1121. dev_info(&client->dev,"[MUIC]: VBUSOUT_OFF\n");
  1122. #ifdef CONFIG_USB_HOST_NOTIFY
  1123. sec_otg_notify(HNOTIFY_OTG_POWER_OFF);
  1124. if(sec_get_notification(HNOTIFY_MODE) == NOTIFY_TEST_MODE)
  1125. goto exit_irq_handler;
  1126. #endif
  1127. /*Jig UART Boot-Off Or Deskdock VBUS Detached*/
  1128. if (adc == ADC_JIG_UART_OFF) {
  1129. tsu6721_detach_dev(usbsw);
  1130. } else if (adc == ADC_DESKDOCK) {
  1131. #if defined(DEBUG)
  1132. val1 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE1);
  1133. val3 = i2c_smbus_read_byte_data(client, REG_DEVICE_TYPE3);
  1134. printk("%s, dev1 0x%x dev3 0x%x \n", __func__, val1, val3);
  1135. #endif
  1136. /*When VBUS is changing only, no need to switch paths again*/
  1137. usbsw->pdata->callback(CABLE_TYPE_DESK_DOCK_NO_VB, TSU6721_DETACHED);
  1138. }
  1139. }
  1140. #ifdef CONFIG_USB_HOST_NOTIFY
  1141. exit_irq_handler:
  1142. #endif
  1143. mutex_unlock(&usbsw->mutex);
  1144. pr_info("tsu6721_irq_thread,end\n");
  1145. return IRQ_HANDLED;
  1146. }
  1147. static int tsu6721_irq_init(struct tsu6721_usbsw *usbsw)
  1148. {
  1149. struct i2c_client *client = usbsw->client;
  1150. int ret;
  1151. if (client->irq) {
  1152. ret = request_threaded_irq(client->irq, NULL,
  1153. tsu6721_irq_thread, IRQF_TRIGGER_FALLING,
  1154. "tsu6721 micro USB", usbsw);
  1155. if (ret) {
  1156. dev_err(&client->dev, "failed to reqeust IRQ\n");
  1157. return ret;
  1158. }
  1159. enable_irq_wake(client->irq);
  1160. }
  1161. return 0;
  1162. }
  1163. static void tsu6721_init_detect(struct work_struct *work)
  1164. {
  1165. struct tsu6721_usbsw *usbsw = container_of(work,
  1166. struct tsu6721_usbsw, init_work.work);
  1167. int ret;
  1168. int int_reg1, int_reg2;
  1169. int val1, val3, adc;
  1170. dev_info(&usbsw->client->dev, "%s\n", __func__);
  1171. mutex_lock(&usbsw->mutex);
  1172. tsu6721_attach_dev(usbsw);
  1173. mutex_unlock(&usbsw->mutex);
  1174. ret = tsu6721_irq_init(usbsw);
  1175. if (ret)
  1176. dev_info(&usbsw->client->dev,
  1177. "failed to enable irq init %s\n", __func__);
  1178. int_reg1 = tsu6721_read_reg(usbsw->client, REG_INT1);
  1179. dev_info(&usbsw->client->dev, "%s: intr1 : 0x%x\n",
  1180. __func__, int_reg1);
  1181. int_reg2 = i2c_smbus_read_byte_data(usbsw->client, REG_INT2);
  1182. dev_info(&usbsw->client->dev, "%s: intr2 : 0x%x\n",
  1183. __func__, int_reg2);
  1184. /* device detection */
  1185. /* interrupt detach */
  1186. adc = i2c_smbus_read_byte_data(usbsw->client, REG_ADC);
  1187. if (int_reg1 == (INT_ATTACH)) {
  1188. val1 = i2c_smbus_read_byte_data(usbsw->client, REG_DEVICE_TYPE1);
  1189. val3 = i2c_smbus_read_byte_data(usbsw->client, REG_DEVICE_TYPE3);
  1190. if ((adc == ADC_OPEN) && (val1 == DATA_NONE) &&
  1191. ((val3 == DATA_NONE) ||
  1192. (val3 == (DEV_VBUS_DEBOUNCE | DEV_NON_STANDARD)))){
  1193. dev_info(&usbsw->client->dev, "%s: val1 : 0x%x val3 : 0x%x\n",
  1194. __func__, val1, val3);
  1195. tsu6721_detach_dev(usbsw);
  1196. }
  1197. }
  1198. }
  1199. #ifdef CONFIG_OF
  1200. static int tsu6721_parse_dt(struct device *dev, struct tsu6721_platform_data *pdata)
  1201. {
  1202. struct device_node *np = dev->of_node;
  1203. /*changes can be added later, when needed*/
  1204. #if 0
  1205. /* regulator info */
  1206. pdata->i2c_pull_up = of_property_read_bool(np, "tsu6721,i2c-pull-up");
  1207. #endif
  1208. pdata->gpio_scl = of_get_named_gpio_flags(np, "tsu6721,gpio-scl",
  1209. 0, &pdata->scl_gpio_flags);
  1210. pdata->gpio_uart_on = of_get_named_gpio_flags(np, "tsu6721,uarton-gpio",
  1211. 0, &pdata->uarton_gpio_flags);
  1212. pdata->gpio_sda = of_get_named_gpio_flags(np, "tsu6721,gpio-sda",
  1213. 0, &pdata->sda_gpio_flags);
  1214. pdata->gpio_int = of_get_named_gpio_flags(np, "tsu6721,irq-gpio",
  1215. 0, &pdata->irq_gpio_flags);
  1216. pr_info("%s: irq-gpio: %u \n", __func__, pdata->gpio_int);
  1217. return 0;
  1218. }
  1219. #endif
  1220. static int __devinit tsu6721_probe(struct i2c_client *client,
  1221. const struct i2c_device_id *id)
  1222. {
  1223. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  1224. struct tsu6721_usbsw *usbsw;
  1225. int ret = 0;
  1226. struct device *switch_dev;
  1227. struct tsu6721_platform_data *pdata;
  1228. dev_info(&client->dev,"%s:tsu6721 probe called \n",__func__);
  1229. if(client->dev.of_node) {
  1230. pdata = devm_kzalloc(&client->dev,
  1231. sizeof(struct tsu6721_platform_data), GFP_KERNEL);
  1232. if (!pdata) {
  1233. dev_err(&client->dev, "Failed to allocate memory \n");
  1234. return -ENOMEM;
  1235. }
  1236. ret = tsu6721_parse_dt(&client->dev, pdata);
  1237. if (ret < 0) {
  1238. dev_err(&client->dev, "sm5502_parse_dt failed\n");
  1239. goto fail;
  1240. }
  1241. pdata->callback = tsu6721_callback;
  1242. pdata->dock_init = tsu6721_dock_init;
  1243. pdata->oxp_callback = tsu6721_oxp_callback;
  1244. pdata->mhl_sel = NULL;
  1245. gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 0, GPIO_CFG_INPUT,
  1246. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  1247. gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 0, GPIO_CFG_INPUT,
  1248. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  1249. #if defined(CONFIG_SEC_HESTIA_PROJECT)
  1250. if (system_rev == 6) {
  1251. gpio_tlmm_config(GPIO_CFG(pdata->gpio_sda, 0, GPIO_CFG_INPUT,
  1252. GPIO_CFG_PULL_UP, GPIO_CFG_4MA), GPIO_CFG_ENABLE);
  1253. gpio_tlmm_config(GPIO_CFG(pdata->gpio_scl, 0, GPIO_CFG_INPUT,
  1254. GPIO_CFG_PULL_UP, GPIO_CFG_4MA), GPIO_CFG_ENABLE);
  1255. }
  1256. #endif
  1257. #if defined(CONFIG_SEC_BERLUTI_PROJECT) || defined(CONFIG_SEC_GNOTE_PROJECT)
  1258. gpio_tlmm_config(GPIO_CFG(pdata->gpio_int, 0, GPIO_CFG_INPUT,
  1259. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_DISABLE);
  1260. gpio_tlmm_config(GPIO_CFG(pdata->gpio_uart_on, 0, GPIO_CFG_INPUT,
  1261. GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_DISABLE);
  1262. #else
  1263. gpio_tlmm_config(GPIO_CFG(pdata->gpio_int, 0, GPIO_CFG_INPUT,
  1264. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE);
  1265. gpio_tlmm_config(GPIO_CFG(pdata->gpio_uart_on, 0, GPIO_CFG_INPUT,
  1266. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE);
  1267. #endif
  1268. client->irq = gpio_to_irq(pdata->gpio_int);
  1269. } else {
  1270. pdata = client->dev.platform_data;
  1271. if (!pdata)
  1272. return -EINVAL;
  1273. }
  1274. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
  1275. dev_err(&client->dev, "i2c functionality check failed...!\n");
  1276. ret = -EIO;
  1277. goto fail;
  1278. }
  1279. usbsw = kzalloc(sizeof(struct tsu6721_usbsw), GFP_KERNEL);
  1280. if (!usbsw) {
  1281. dev_err(&client->dev, "failed to allocate driver data\n");
  1282. ret = -ENOMEM;
  1283. goto fail;
  1284. }
  1285. usbsw->client = client;
  1286. if (client->dev.of_node)
  1287. usbsw->pdata = pdata;
  1288. else
  1289. usbsw->pdata = client->dev.platform_data;
  1290. if (!usbsw->pdata)
  1291. goto fail1;
  1292. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  1293. usbsw->is_factory_start = false;
  1294. #endif
  1295. i2c_set_clientdata(client, usbsw);
  1296. mutex_init(&usbsw->mutex);
  1297. local_usbsw = usbsw;
  1298. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  1299. ret = tsu6721_read_reg(client,REG_MANUAL_SW1);
  1300. if(ret<0) {
  1301. dev_err(&client->dev, "failed to read MANUAL SW1 Reg, err:%d\n",ret);
  1302. }
  1303. /* Keep the feature disabled by default */
  1304. usbsw->is_rustproof = false;
  1305. /* RUSTPROOF: disable UART connection if MANSW1 from BL is OPEN_RUSTPROOF*/
  1306. if(ret == MANSW1_OPEN_RUSTPROOF)
  1307. usbsw->is_rustproof = true;
  1308. #endif
  1309. /* tsu6721 soft reset*/
  1310. ret = i2c_smbus_write_byte_data(client,REG_RESET, 0x01);
  1311. if (ret < 0)
  1312. dev_err(&client->dev,"cannot soft reset, err %d\n", ret);
  1313. tsu6721_reg_init(usbsw);
  1314. ret = sysfs_create_group(&client->dev.kobj, &tsu6721_group);
  1315. if (ret) {
  1316. dev_err(&client->dev,
  1317. "failed to create tsu6721 attribute group\n");
  1318. goto fail2;
  1319. }
  1320. /* make sysfs node /sys/class/sec/switch/ */
  1321. switch_dev = device_create(sec_class, NULL, 0, NULL, "switch");
  1322. if (IS_ERR(switch_dev)) {
  1323. pr_err("[TSU6721] Failed to create device (switch_dev)!\n");
  1324. ret = PTR_ERR(switch_dev);
  1325. goto fail2;
  1326. }
  1327. ret = device_create_file(switch_dev, &dev_attr_usb_state);
  1328. if (ret < 0) {
  1329. pr_err("[TSU6721] Failed to create file (usb_state)!\n");
  1330. goto err_create_file_state;
  1331. }
  1332. ret = device_create_file(switch_dev, &dev_attr_adc);
  1333. if (ret < 0) {
  1334. pr_err("[TSU6721] Failed to create file (adc)!\n");
  1335. goto err_create_file_adc;
  1336. }
  1337. ret = device_create_file(switch_dev, &dev_attr_reset_switch);
  1338. if (ret < 0) {
  1339. pr_err("[TSU6721] Failed to create file (reset_switch)!\n");
  1340. goto err_create_file_reset_switch;
  1341. }
  1342. ret = device_create_file(switch_dev, &dev_attr_attached_dev);
  1343. if (ret < 0) {
  1344. pr_err("[TSU6721] Failed to create file (attached_dev)!\n");
  1345. goto err_create_file_attached_dev;
  1346. }
  1347. local_usbsw->attached_dev = ATTACHED_DEV_NONE_MUIC;
  1348. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  1349. ret = device_create_file(switch_dev, &dev_attr_uart_en);
  1350. if (ret < 0) {
  1351. pr_err("[TSU6721] Failed to create file (uart_en)!\n");
  1352. goto err_create_file_uart_en;
  1353. }
  1354. ret = device_create_file(switch_dev, &dev_attr_uart_sel);
  1355. if (ret < 0) {
  1356. pr_err("[TSU6721] Failed to create file (uart_sel)!\n");
  1357. goto err_create_file_uart_sel;
  1358. }
  1359. ret = device_create_file(switch_dev, &dev_attr_usb_sel);
  1360. if (ret < 0) {
  1361. pr_err("[TSU6721] Failed to create file (usb_sel)!\n");
  1362. goto err_create_file_usb_sel;
  1363. }
  1364. #endif
  1365. #if !defined(CONFIG_MUIC_SUPPORT_CAR_DOCK)
  1366. ret = device_create_file(switch_dev, &dev_attr_apo_factory);
  1367. if (ret < 0) {
  1368. pr_err("[TSU6721] Failed to create file (apo_factory)!\n");
  1369. goto err_create_file_reset_switch;
  1370. }
  1371. #endif
  1372. dev_set_drvdata(switch_dev, usbsw);
  1373. /* tsu6721 dock init*/
  1374. if (usbsw->pdata->dock_init)
  1375. usbsw->pdata->dock_init();
  1376. /* initial cable detection */
  1377. INIT_DELAYED_WORK(&usbsw->init_work, tsu6721_init_detect);
  1378. schedule_delayed_work(&usbsw->init_work, msecs_to_jiffies(2700));
  1379. return 0;
  1380. #if defined(CONFIG_MUIC_SUPPORT_RUSTPROOF)
  1381. err_create_file_usb_sel:
  1382. device_remove_file(switch_dev, &dev_attr_usb_sel);
  1383. err_create_file_uart_sel:
  1384. device_remove_file(switch_dev, &dev_attr_uart_sel);
  1385. err_create_file_uart_en:
  1386. device_remove_file(switch_dev, &dev_attr_uart_en);
  1387. #endif
  1388. err_create_file_attached_dev:
  1389. device_remove_file(switch_dev, &dev_attr_attached_dev);
  1390. err_create_file_reset_switch:
  1391. device_remove_file(switch_dev, &dev_attr_reset_switch);
  1392. err_create_file_adc:
  1393. device_remove_file(switch_dev, &dev_attr_adc);
  1394. err_create_file_state:
  1395. device_remove_file(switch_dev, &dev_attr_usb_state);
  1396. fail2:
  1397. if (client->irq)
  1398. free_irq(client->irq, usbsw);
  1399. mutex_destroy(&usbsw->mutex);
  1400. i2c_set_clientdata(client, NULL);
  1401. fail1:
  1402. kfree(usbsw);
  1403. fail:
  1404. kfree(pdata);
  1405. return ret;
  1406. }
  1407. static int __devexit tsu6721_remove(struct i2c_client *client)
  1408. {
  1409. struct tsu6721_usbsw *usbsw = i2c_get_clientdata(client);
  1410. cancel_delayed_work(&usbsw->init_work);
  1411. if (client->irq) {
  1412. disable_irq_wake(client->irq);
  1413. free_irq(client->irq, usbsw);
  1414. }
  1415. mutex_destroy(&usbsw->mutex);
  1416. i2c_set_clientdata(client, NULL);
  1417. sysfs_remove_group(&client->dev.kobj, &tsu6721_group);
  1418. kfree(usbsw);
  1419. return 0;
  1420. }
  1421. static int tsu6721_resume(struct i2c_client *client)
  1422. {
  1423. struct tsu6721_usbsw *usbsw = i2c_get_clientdata(client);
  1424. pr_info("%s: resume \n",__func__);
  1425. i2c_smbus_read_byte_data(client, REG_INT1);
  1426. i2c_smbus_read_byte_data(client, REG_INT2);
  1427. /* device detection */
  1428. mutex_lock(&usbsw->mutex);
  1429. tsu6721_attach_dev(usbsw);
  1430. mutex_unlock(&usbsw->mutex);
  1431. return 0;
  1432. }
  1433. static const struct i2c_device_id tsu6721_id[] = {
  1434. {"tsu6721", 0},
  1435. {}
  1436. };
  1437. MODULE_DEVICE_TABLE(i2c, tsu6721_id);
  1438. static struct of_device_id tsu6721_i2c_match_table[] = {
  1439. { .compatible = "tsu6721,i2c",},
  1440. {},
  1441. };
  1442. MODULE_DEVICE_TABLE(of, tsu6721_i2c_match_table);
  1443. static struct i2c_driver tsu6721_i2c_driver = {
  1444. .driver = {
  1445. .name = "tsu6721",
  1446. .owner = THIS_MODULE,
  1447. .of_match_table = tsu6721_i2c_match_table,
  1448. },
  1449. .probe = tsu6721_probe,
  1450. .remove = __devexit_p(tsu6721_remove),
  1451. .resume = tsu6721_resume,
  1452. .id_table = tsu6721_id,
  1453. };
  1454. static int __init tsu6721_init(void)
  1455. {
  1456. #if defined(CONFIG_MACH_S3VE_CHN_OPEN) || defined(CONFIG_MACH_S3VE_CHN_CMCC)
  1457. if (system_rev >= 3)
  1458. return 0;
  1459. #endif
  1460. return i2c_add_driver(&tsu6721_i2c_driver);
  1461. }
  1462. late_initcall(tsu6721_init);
  1463. static void __exit tsu6721_exit(void)
  1464. {
  1465. i2c_del_driver(&tsu6721_i2c_driver);
  1466. }
  1467. module_exit(tsu6721_exit);
  1468. MODULE_AUTHOR("Jeongrae Kim <Jryu.kim@samsung.com>");
  1469. MODULE_DESCRIPTION("TSU6721 Micro USB Switch driver");
  1470. MODULE_LICENSE("GPL");