connector_setup.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /*
  2. * connector_setup.c
  3. *
  4. * Copyright (C) 2017 Samsung Electronics
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/sti/sec_abc_detect_conn.h>
  18. #if defined(CONFIG_SEC_KUNIT)
  19. #define __mockable __weak
  20. #define __visible_for_testing
  21. #define KUNIT_TEST_STRLEN 30
  22. struct device *sec_abc_detect_conn_dev;
  23. char kunit_test_str[KUNIT_TEST_STRLEN];
  24. #else
  25. #define __mockable
  26. #define __visible_for_testing static
  27. #endif
  28. __visible_for_testing int gsec_abc_detect_conn_enabled;
  29. struct sec_det_conn_info *gpinfo;
  30. #if IS_ENABLED(CONFIG_OF)
  31. static const struct of_device_id sec_abc_detect_conn_dt_match[] = {
  32. { .compatible = "samsung,sec_abc_detect_conn" },
  33. { }
  34. };
  35. #endif //CONFIG_OF
  36. #if IS_ENABLED(CONFIG_PM)
  37. static int sec_abc_detect_conn_pm_suspend(struct device *dev)
  38. {
  39. return 0;
  40. }
  41. static int sec_abc_detect_conn_pm_resume(struct device *dev)
  42. {
  43. return 0;
  44. }
  45. static const struct dev_pm_ops sec_abc_detect_conn_pm = {
  46. .suspend = sec_abc_detect_conn_pm_suspend,
  47. .resume = sec_abc_detect_conn_pm_resume,
  48. };
  49. #endif //CONFIG_PM
  50. /*
  51. * Send uevent from irq handler.
  52. */
  53. void sec_abc_detect_send_uevent_by_num(int num,
  54. struct sec_det_conn_info *pinfo,
  55. int level)
  56. {
  57. char *uevent_conn_str[3] = {"", "", NULL};
  58. char uevent_dev_str[UEVENT_CONN_MAX_DEV_NAME];
  59. char uevent_dev_type_str[UEVENT_CONN_MAX_DEV_NAME];
  60. /* Send Uevent Data */
  61. snprintf(uevent_dev_str, UEVENT_CONN_MAX_DEV_NAME, "CONNECTOR_NAME=%s",
  62. pinfo->pdata->name[num]);
  63. uevent_conn_str[0] = uevent_dev_str;
  64. if (level == 1)
  65. snprintf(uevent_dev_type_str, UEVENT_CONN_MAX_DEV_NAME,
  66. "CONNECTOR_TYPE=HIGH_LEVEL");
  67. else
  68. snprintf(uevent_dev_type_str, UEVENT_CONN_MAX_DEV_NAME,
  69. "CONNECTOR_TYPE=LOW_LEVEL");
  70. uevent_conn_str[1] = uevent_dev_type_str;
  71. kobject_uevent_env(&pinfo->dev->kobj, KOBJ_CHANGE, uevent_conn_str);
  72. SEC_CONN_PRINT("send uevent pin[%d]:CONNECTOR_NAME=%s, TYPE=[%d].\n",
  73. num, pinfo->pdata->name[num], level);
  74. #if defined(CONFIG_SEC_KUNIT)
  75. snprintf(kunit_test_str, KUNIT_TEST_STRLEN, "CONNECTOR_TYPE=HIGH_LEVEL");
  76. #endif
  77. }
  78. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  79. /*
  80. * Check gpio and send uevent.
  81. */
  82. __visible_for_testing void check_gpio_and_send_uevent(int i,
  83. struct sec_det_conn_info *pinfo)
  84. {
  85. if (gpio_get_value(pinfo->pdata->irq_gpio[i])) {
  86. SEC_CONN_PRINT("%s status changed [disconnected]\n",
  87. pinfo->pdata->name[i]);
  88. sec_abc_detect_send_uevent_by_num(i, pinfo, 1);
  89. } else {
  90. SEC_CONN_PRINT("%s status changed [connected]\n",
  91. pinfo->pdata->name[i]);
  92. sec_abc_detect_send_uevent_by_num(i, pinfo, 0);
  93. }
  94. }
  95. #endif
  96. #if IS_ENABLED(CONFIG_SEC_ABC_HUB) && IS_ENABLED(CONFIG_SEC_ABC_HUB_COND)
  97. /**
  98. * Send an ABC_event about given gpio pin number.
  99. */
  100. void send_ABC_event_by_num(int i, struct sec_det_conn_info *pinfo)
  101. {
  102. char ABC_event_dev_str[ABCEVENT_CONN_MAX_DEV_STRING];
  103. if (sec_abc_get_enabled() == 0)
  104. return;
  105. /*Send ABC Event Data*/
  106. if (gpio_get_value(pinfo->pdata->irq_gpio[i])) {
  107. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  108. snprintf(ABC_event_dev_str, ABCEVENT_CONN_MAX_DEV_STRING,
  109. "MODULE=cond@INFO=%s", pinfo->pdata->name[i]);
  110. #else
  111. snprintf(ABC_event_dev_str, ABCEVENT_CONN_MAX_DEV_STRING,
  112. "MODULE=cond@WARN=%s", pinfo->pdata->name[i]);
  113. #endif
  114. sec_abc_send_event(ABC_event_dev_str);
  115. SEC_CONN_PRINT("send ABC cond event %s status is [disconnected] : %s\n",
  116. pinfo->pdata->name[i], ABC_event_dev_str);
  117. } else {
  118. SEC_CONN_PRINT("do not send ABC cond event %s status is [connected]\n",
  119. pinfo->pdata->name[i]);
  120. }
  121. }
  122. #endif
  123. /*
  124. * Check and send uevent from irq handler.
  125. */
  126. void sec_abc_detect_send_uevent_irq(int irq,
  127. struct sec_det_conn_info *pinfo,
  128. int type)
  129. {
  130. int i;
  131. for (i = 0; i < pinfo->pdata->gpio_total_cnt; i++) {
  132. if (irq == pinfo->pdata->irq_number[i]) {
  133. /* apply s/w debounce time */
  134. usleep_range(DET_CONN_DEBOUNCE_TIME_MS * 1000, DET_CONN_DEBOUNCE_TIME_MS * 1000);
  135. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  136. check_gpio_and_send_uevent(i, pinfo);
  137. #endif
  138. #if IS_ENABLED(CONFIG_SEC_ABC_HUB) && IS_ENABLED(CONFIG_SEC_ABC_HUB_COND)
  139. send_ABC_event_by_num(i, pinfo);
  140. #endif
  141. increase_connector_disconnected_count(i, pinfo);
  142. }
  143. }
  144. }
  145. /*
  146. * Called when the connector pin state changes.
  147. */
  148. static irqreturn_t sec_abc_detect_conn_interrupt_handler(int irq, void *handle)
  149. {
  150. int type;
  151. struct sec_det_conn_info *pinfo = handle;
  152. if (gsec_abc_detect_conn_enabled != 0) {
  153. SEC_CONN_PRINT("%s\n", __func__);
  154. type = irq_get_trigger_type(irq);
  155. sec_abc_detect_send_uevent_irq(irq, pinfo, type);
  156. }
  157. return IRQ_HANDLED;
  158. }
  159. /*
  160. * Enable all gpio pin IRQ which is from Device Tree.
  161. */
  162. int detect_conn_irq_enable(struct sec_det_conn_info *pinfo, bool enable,
  163. int pin)
  164. {
  165. int ret = 0;
  166. int i;
  167. if (!enable) {
  168. for (i = 0; i < pinfo->pdata->gpio_total_cnt; i++) {
  169. if (pinfo->irq_enabled[i]) {
  170. disable_irq(pinfo->pdata->irq_number[i]);
  171. pinfo->irq_enabled[i] = DET_CONN_GPIO_IRQ_DISABLED;
  172. }
  173. }
  174. return ret;
  175. }
  176. if (pin >= pinfo->pdata->gpio_total_cnt)
  177. return ret;
  178. if (pinfo->irq_enabled[pin] == DET_CONN_GPIO_IRQ_NOT_INIT) {
  179. ret = request_threaded_irq(pinfo->pdata->irq_number[pin], NULL,
  180. sec_abc_detect_conn_interrupt_handler,
  181. pinfo->pdata->irq_type[pin] | IRQF_ONESHOT,
  182. pinfo->pdata->name[pin], pinfo);
  183. if (ret) {
  184. SEC_CONN_PRINT("%s: Failed to request irq %d.\n", __func__,
  185. ret);
  186. return ret;
  187. }
  188. SEC_CONN_PRINT("%s: Succeeded to request threaded irq %d:\n",
  189. __func__, ret);
  190. } else if (pinfo->irq_enabled[pin] == DET_CONN_GPIO_IRQ_DISABLED) {
  191. enable_irq(pinfo->pdata->irq_number[pin]);
  192. }
  193. SEC_CONN_PRINT("irq_num[%d], type[%x],name[%s].\n",
  194. pinfo->pdata->irq_number[pin],
  195. pinfo->pdata->irq_type[pin], pinfo->pdata->name[pin]);
  196. pinfo->irq_enabled[pin] = DET_CONN_GPIO_IRQ_ENABLED;
  197. return ret;
  198. }
  199. /*
  200. * Check and send an uevent if the pin level is high.
  201. * And then enable gpio pin interrupt.
  202. */
  203. __visible_for_testing int one_gpio_irq_enable(int i, struct sec_det_conn_p_data *pdata,
  204. const char *buf)
  205. {
  206. int ret = 0;
  207. SEC_CONN_PRINT("%s driver enabled.\n", buf);
  208. gsec_abc_detect_conn_enabled |= (1 << i);
  209. SEC_CONN_PRINT("gpio [%d] level %d\n", pdata->irq_gpio[i],
  210. gpio_get_value(pdata->irq_gpio[i]));
  211. /*get level value of the gpio pin.*/
  212. /*if there's gpio low pin, send uevent*/
  213. #if IS_ENABLED(CONFIG_SEC_FACTORY)
  214. check_gpio_and_send_uevent(i, pdata->pinfo);
  215. #endif
  216. #if IS_ENABLED(CONFIG_SEC_ABC_HUB) && IS_ENABLED(CONFIG_SEC_ABC_HUB_COND)
  217. send_ABC_event_by_num(i, pdata->pinfo);
  218. #endif
  219. increase_connector_disconnected_count(i, pdata->pinfo);
  220. /*Enable interrupt.*/
  221. ret = detect_conn_irq_enable(pdata->pinfo, true, i);
  222. if (ret < 0)
  223. SEC_CONN_PRINT("%s Interrupt not enabled.\n", buf);
  224. return ret;
  225. }
  226. /*
  227. * Triggered when "enabled" node is set.
  228. * Check and send an uevent if the pin level is high.
  229. * And then gpio pin interrupt is enabled.
  230. */
  231. __visible_for_testing ssize_t enabled_store(struct device *dev, struct device_attribute *attr,
  232. const char *buf, size_t count)
  233. {
  234. struct sec_det_conn_p_data *pdata;
  235. struct sec_det_conn_info *pinfo;
  236. int ret;
  237. int i;
  238. int buf_len;
  239. int pin_name_len;
  240. if (gpinfo == 0)
  241. return count;
  242. pinfo = gpinfo;
  243. pdata = pinfo->pdata;
  244. buf_len = strlen(buf);
  245. SEC_CONN_PRINT("buf = %s, buf_len = %d\n", buf, buf_len);
  246. /* disable irq when "enabled" value set to 0*/
  247. if (!strncmp(buf, "0", 1)) {
  248. SEC_CONN_PRINT("sec detect connector driver disable.\n");
  249. gsec_abc_detect_conn_enabled = 0;
  250. ret = detect_conn_irq_enable(pinfo, false, 0);
  251. if (ret) {
  252. SEC_CONN_PRINT("Interrupt not disabled.\n");
  253. return ret;
  254. }
  255. return count;
  256. }
  257. for (i = 0; i < pdata->gpio_total_cnt; i++) {
  258. pin_name_len = strlen(pdata->name[i]);
  259. SEC_CONN_PRINT("pinName = %s\n", pdata->name[i]);
  260. SEC_CONN_PRINT("pin_name_len = %d\n", pin_name_len);
  261. if (pin_name_len == buf_len) {
  262. if (!strncmp(buf, pdata->name[i], buf_len)) {
  263. /* buf sting is equal to pdata->name[i] */
  264. ret = one_gpio_irq_enable(i, pdata, buf);
  265. if (ret < 0)
  266. return ret;
  267. }
  268. }
  269. /*
  270. * For ALL_CONNECT input,
  271. * enable all nodes except already enabled node.
  272. */
  273. if (buf_len >= 11) {
  274. if (strncmp(buf, "ALL_CONNECT", 11)) {
  275. /* buf sting is not equal to ALL_CONNECT */
  276. continue;
  277. }
  278. /* buf sting is equal to pdata->name[i] */
  279. if (!(gsec_abc_detect_conn_enabled & (1 << i))) {
  280. ret = one_gpio_irq_enable(i, pdata, buf);
  281. if (ret < 0)
  282. return ret;
  283. }
  284. }
  285. }
  286. return count;
  287. }
  288. __visible_for_testing ssize_t enabled_show(struct device *dev, struct device_attribute *attr,
  289. char *buf)
  290. {
  291. return snprintf(buf, 12, "%d\n", gsec_abc_detect_conn_enabled);
  292. }
  293. static DEVICE_ATTR_RW(enabled);
  294. __visible_for_testing ssize_t available_pins_show(struct device *dev,
  295. struct device_attribute *attr,
  296. char *buf)
  297. {
  298. struct sec_det_conn_p_data *pdata;
  299. struct sec_det_conn_info *pinfo;
  300. char available_pins_string[1024] = {0, };
  301. int i;
  302. if (gpinfo == 0)
  303. return 0;
  304. pinfo = gpinfo;
  305. pdata = pinfo->pdata;
  306. for (i = 0; i < pdata->gpio_total_cnt; i++) {
  307. SEC_CONN_PRINT("pinName = %s\n", pdata->name[i]);
  308. strlcat(available_pins_string, pdata->name[i], 1024);
  309. strlcat(available_pins_string, "/", 1024);
  310. }
  311. available_pins_string[strlen(available_pins_string) - 1] = '\0';
  312. return snprintf(buf, 1024, "%s\n", available_pins_string);
  313. }
  314. static DEVICE_ATTR_RO(available_pins);
  315. /**
  316. * Fill out the gpio cnt
  317. */
  318. static void fill_gpio_cnt(struct sec_det_conn_p_data *pdata, struct device_node *np, char *gpio_name)
  319. {
  320. int gpio_name_cnt;
  321. gpio_name_cnt = of_gpio_named_count(np, gpio_name);
  322. if (gpio_name_cnt < 1) {
  323. SEC_CONN_PRINT("fill gpio cnt failed %s < 1 %d.\n",
  324. gpio_name,
  325. gpio_name_cnt);
  326. gpio_name_cnt = 0;
  327. }
  328. pdata->gpio_last_cnt = pdata->gpio_total_cnt;
  329. pdata->gpio_total_cnt = pdata->gpio_total_cnt + gpio_name_cnt;
  330. SEC_CONN_PRINT("fill out %s gpio cnt, gpio_total_count = %d", gpio_name, pdata->gpio_total_cnt);
  331. }
  332. /**
  333. * Fill out the gpio name
  334. */
  335. static void fill_gpio_name(struct sec_det_conn_p_data *pdata,
  336. struct device_node *np,
  337. char *conn_name,
  338. int offset,
  339. int index)
  340. {
  341. /*Get connector name*/
  342. of_property_read_string_index(np, conn_name, offset, &pdata->name[index]);
  343. }
  344. /**
  345. * Fill out the irq info
  346. */
  347. static int fill_irq_info(struct sec_det_conn_p_data *pdata,
  348. struct device_node *np,
  349. char *gpio_name,
  350. int offset,
  351. int index)
  352. {
  353. /* get connector gpio number*/
  354. pdata->irq_gpio[index] = of_get_named_gpio(np, gpio_name, offset);
  355. if (!gpio_is_valid(pdata->irq_gpio[index])) {
  356. SEC_CONN_PRINT("[%s] gpio[%d] is not valid\n", gpio_name, offset);
  357. return 0;
  358. }
  359. pdata->irq_number[index] = gpio_to_irq(pdata->irq_gpio[index]);
  360. pdata->irq_type[index] = IRQ_TYPE_EDGE_BOTH;
  361. SEC_CONN_PRINT("i = %d, irq_gpio[i] = %d, irq_num[i] = %d, level = %d\n", index,
  362. pdata->irq_gpio[index],
  363. pdata->irq_number[index],
  364. gpio_get_value(pdata->irq_gpio[index]));
  365. return 1;
  366. }
  367. /**
  368. * Parse the AP device tree and get gpio number, irq type.
  369. * Request gpio
  370. */
  371. static void parse_ap_dt(struct sec_det_conn_p_data *pdata, struct device_node *np)
  372. {
  373. int i;
  374. fill_gpio_cnt(pdata, np, "sec,det_conn_gpios");
  375. for (i = pdata->gpio_last_cnt; i < pdata->gpio_total_cnt; i++) {
  376. fill_gpio_name(pdata, np, "sec,det_conn_name", i - pdata->gpio_last_cnt, i);
  377. if (!fill_irq_info(pdata, np, "sec,det_conn_gpios", i - pdata->gpio_last_cnt, i))
  378. break;
  379. }
  380. }
  381. #if IS_ENABLED(CONFIG_QCOM_SEC_ABC_DETECT)
  382. /**
  383. * gpio pinctrl by pinctrl-name
  384. */
  385. static void set_pinctrl_by_pinctrl_name(struct device *dev, char *pinctrl_name)
  386. {
  387. struct pinctrl *conn_pinctrl;
  388. conn_pinctrl = devm_pinctrl_get_select(dev, pinctrl_name);
  389. if (IS_ERR_OR_NULL(conn_pinctrl))
  390. SEC_CONN_PRINT("%s detect_pinctrl_init failed.\n", pinctrl_name);
  391. else
  392. SEC_CONN_PRINT("%s detect_pinctrl_init passed.\n", pinctrl_name);
  393. }
  394. /**
  395. * Parse the Expander device tree and get gpio number, irq type.
  396. * Request gpio
  397. */
  398. static void parse_exp_dt(struct sec_det_conn_p_data *pdata, struct device_node *np)
  399. {
  400. int i;
  401. fill_gpio_cnt(pdata, np, "sec,det_exp_conn_gpios");
  402. for (i = pdata->gpio_last_cnt; i < pdata->gpio_total_cnt; i++) {
  403. fill_gpio_name(pdata, np, "sec,det_exp_conn_name", i - pdata->gpio_last_cnt, i);
  404. if (!fill_irq_info(pdata, np, "sec,det_exp_conn_gpios", i - pdata->gpio_last_cnt, i))
  405. break;
  406. }
  407. }
  408. /**
  409. * Parse the PM device tree and get gpio number, irq type.
  410. * Request gpio
  411. */
  412. static void parse_pmic_dt(struct sec_det_conn_p_data *pdata, struct device_node *np)
  413. {
  414. int i;
  415. fill_gpio_cnt(pdata, np, "sec,det_pm_conn_gpios");
  416. for (i = pdata->gpio_last_cnt; i < pdata->gpio_total_cnt; i++) {
  417. fill_gpio_name(pdata, np, "sec,det_pm_conn_name", i - pdata->gpio_last_cnt, i);
  418. if (!fill_irq_info(pdata, np, "sec,det_pm_conn_gpios", i - pdata->gpio_last_cnt, i))
  419. break;
  420. }
  421. }
  422. #endif
  423. #if IS_ENABLED(CONFIG_OF)
  424. /**
  425. * Parse the device tree and get gpio number, irq type.
  426. * Request gpio
  427. */
  428. static int parse_detect_conn_dt(struct device *dev)
  429. {
  430. struct sec_det_conn_p_data *pdata = dev->platform_data;
  431. struct device_node *np = dev->of_node;
  432. #if IS_ENABLED(CONFIG_QCOM_SEC_ABC_DETECT)
  433. set_pinctrl_by_pinctrl_name(dev, "det_ap_connect");
  434. #endif
  435. parse_ap_dt(pdata, np);
  436. #if IS_ENABLED(CONFIG_QCOM_SEC_ABC_DETECT)
  437. set_pinctrl_by_pinctrl_name(dev, "det_exp_connect");
  438. parse_exp_dt(pdata, np);
  439. set_pinctrl_by_pinctrl_name(dev, "det_pm_connect");
  440. set_pinctrl_by_pinctrl_name(dev, "det_pm_2_connect");
  441. parse_pmic_dt(pdata, np);
  442. #endif
  443. return 0;
  444. }
  445. #endif //CONFIG_OF
  446. static int sec_abc_detect_conn_probe(struct platform_device *pdev)
  447. {
  448. struct sec_det_conn_p_data *pdata;
  449. struct sec_det_conn_info *pinfo;
  450. int ret = 0;
  451. SEC_CONN_PRINT("%s\n", __func__);
  452. /* First Get the GPIO pins; if it fails, we'll defer the probe. */
  453. if (pdev->dev.of_node) {
  454. pdata = devm_kzalloc(&pdev->dev,
  455. sizeof(struct sec_det_conn_p_data),
  456. GFP_KERNEL);
  457. if (!pdata) {
  458. dev_err(&pdev->dev, "Failed to allocate pdata.\n");
  459. return -ENOMEM;
  460. }
  461. pdev->dev.platform_data = pdata;
  462. #if IS_ENABLED(CONFIG_OF)
  463. ret = parse_detect_conn_dt(&pdev->dev);
  464. #endif
  465. if (ret) {
  466. dev_err(&pdev->dev, "Failed to parse dt data.\n");
  467. return ret;
  468. }
  469. pr_info("%s: parse dt done.\n", __func__);
  470. } else {
  471. pdata = pdev->dev.platform_data;
  472. }
  473. if (!pdata) {
  474. dev_err(&pdev->dev, "There are no platform data.\n");
  475. return -EINVAL;
  476. }
  477. pinfo = devm_kzalloc(&pdev->dev, sizeof(struct sec_det_conn_info),
  478. GFP_KERNEL);
  479. if (!pinfo) {
  480. SEC_CONN_PRINT("pinfo : failed to allocate pinfo.\n");
  481. return -ENOMEM;
  482. }
  483. #if defined(CONFIG_SEC_KUNIT)
  484. sec_abc_detect_conn_dev = pinfo->dev;
  485. #endif
  486. /* Create sys device /sys/class/sec/sec_detect_conn */
  487. pinfo->dev = sec_device_create(pinfo, "sec_detect_conn");
  488. if (IS_ERR(pinfo->dev)) {
  489. pr_err("%s Failed to create device(sec_abc_detect_conn).\n",
  490. __func__);
  491. ret = -ENODEV;
  492. goto out;
  493. }
  494. /* Create sys node /sys/class/sec/sec_detect_conn/enabled */
  495. ret = device_create_file(pinfo->dev, &dev_attr_enabled);
  496. if (ret) {
  497. dev_err(&pdev->dev, "%s: Failed to create device file.\n",
  498. __func__);
  499. goto err_create_detect_conn_sysfs;
  500. }
  501. /* Create sys node /sys/class/sec/sec_detect_conn/available_pins */
  502. ret = device_create_file(pinfo->dev, &dev_attr_available_pins);
  503. if (ret) {
  504. dev_err(&pdev->dev, "%s: Failed to create device file.\n",
  505. __func__);
  506. goto err_create_detect_conn_sysfs;
  507. }
  508. create_current_connection_state_sysnode_files(pinfo);
  509. create_connector_disconnected_count_sysnode_file(pinfo);
  510. /*save pinfo data to pdata to interrupt enable*/
  511. pdata->pinfo = pinfo;
  512. /*save pdata data to pinfo for enable node*/
  513. pinfo->pdata = pdata;
  514. /* save pinfo to gpinfo to enabled node*/
  515. gpinfo = pinfo;
  516. #if !IS_ENABLED(CONFIG_SEC_FACTORY)
  517. /* enable gpio irq for Big data */
  518. enabled_store(pinfo->dev, (struct device_attribute *)0, "ALL_CONNECT", 0);
  519. #endif
  520. return ret;
  521. err_create_detect_conn_sysfs:
  522. sec_device_destroy(pinfo->dev->devt);
  523. out:
  524. gpinfo = 0;
  525. kfree(pinfo);
  526. kfree(pdata);
  527. return ret;
  528. }
  529. static int sec_abc_detect_conn_remove(struct platform_device *pdev)
  530. {
  531. return 0;
  532. }
  533. static struct platform_driver sec_abc_detect_conn_driver = {
  534. .probe = sec_abc_detect_conn_probe,
  535. .remove = sec_abc_detect_conn_remove,
  536. .driver = {
  537. .name = "sec_abc_detect_conn",
  538. .owner = THIS_MODULE,
  539. #if IS_ENABLED(CONFIG_PM)
  540. .pm = &sec_abc_detect_conn_pm,
  541. #endif
  542. #if IS_ENABLED(CONFIG_OF)
  543. .of_match_table = of_match_ptr(sec_abc_detect_conn_dt_match),
  544. #endif
  545. },
  546. };
  547. static int __init sec_abc_detect_conn_init(void)
  548. {
  549. SEC_CONN_PRINT("%s gogo\n", __func__);
  550. return platform_driver_register(&sec_abc_detect_conn_driver);
  551. }
  552. static void __exit sec_abc_detect_conn_exit(void)
  553. {
  554. return platform_driver_unregister(&sec_abc_detect_conn_driver);
  555. }
  556. #if IS_ENABLED(CONFIG_SEC_ABC_HUB) && IS_ENABLED(CONFIG_SEC_ABC_HUB_COND)
  557. /**
  558. * This function is not used for ABC driver due to the Big Data always on Concept
  559. */
  560. void abc_hub_cond_enable(struct device *dev, int enable)
  561. {
  562. }
  563. EXPORT_SYMBOL(abc_hub_cond_enable);
  564. #endif
  565. module_init(sec_abc_detect_conn_init);
  566. module_exit(sec_abc_detect_conn_exit);
  567. MODULE_DESCRIPTION("Samsung Detecting Connector Driver");
  568. MODULE_AUTHOR("Samsung Electronics");
  569. MODULE_LICENSE("GPL");