ir_remote_con_mc96.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. /*
  2. * driver/irda IRDA driver
  3. *
  4. * Copyright (C) 2012 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. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/err.h>
  24. #include <linux/i2c.h>
  25. #include <linux/irq.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/slab.h>
  29. #include <linux/delay.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/device.h>
  32. #include <linux/ir_remote_con_mc96.h>
  33. #include <linux/regulator/consumer.h>
  34. #if defined (CONFIG_OF)
  35. #include <linux/of_device.h>
  36. #include <linux/of_gpio.h>
  37. #endif
  38. #include <linux/earlysuspend.h>
  39. #include "irda_fw_version202.h"
  40. #include "irda_fw_version103.h"
  41. #include <mach/gpio.h>
  42. #include <linux/ir_remote_con_mc96.h>
  43. #define MAX_SIZE 2048
  44. #define MC96_READ_LENGTH 8
  45. #define DUMMY 0xffff
  46. #define MC96FR116C_0x101 0x101
  47. #define MC96FR332A_0x201 0x201
  48. #define MC96FR116C_0x103 0x103
  49. #define MC96FR332A_0x202 0x202
  50. struct ir_remocon_data {
  51. struct mutex mutex;
  52. struct i2c_client *client;
  53. struct mc96_platform_data *pdata;
  54. struct early_suspend early_suspend;
  55. char signal[MAX_SIZE];
  56. int length;
  57. int count;
  58. int dev_id;
  59. int ir_freq;
  60. int ir_sum;
  61. int on_off;
  62. };
  63. #ifdef CONFIG_HAS_EARLYSUSPEND
  64. static void ir_remocon_early_suspend(struct early_suspend *h);
  65. static void ir_remocon_late_resume(struct early_suspend *h);
  66. #endif
  67. static int count_number;
  68. static int ack_number;
  69. static int download_pass;
  70. #ifdef CONFIG_IR_REMOCON_MC96
  71. static void irda_wake_en(struct mc96_platform_data *pdata, bool onoff)
  72. {
  73. /*Need to add parser before this*/
  74. gpio_direction_output(pdata->irda_wake_en, onoff);
  75. printk(KERN_ERR "%s: irda_wake_en : %d\n", __func__, onoff);
  76. }
  77. static int vled_ic_onoff;
  78. static struct regulator *vled_ic;
  79. static int irda_vdd_onoff(bool onoff)
  80. {
  81. int ret = 0;
  82. if (onoff) {
  83. ret = regulator_set_voltage(vled_ic,1900000,1900000);
  84. if (ret) {
  85. pr_err("%s regulaor set volatge failed\n",__func__);
  86. goto regulator_fail;
  87. }
  88. ret = regulator_enable(vled_ic);
  89. if (ret) {
  90. pr_err("%s regulaor enable failed\n",__func__);
  91. goto regulator_fail;
  92. }
  93. vled_ic_onoff = 1;
  94. printk(KERN_CRIT "%s Regulator On!\n",__func__);
  95. } else if (vled_ic_onoff == 1) {
  96. ret = regulator_disable(vled_ic);
  97. if (ret) {
  98. pr_err("%s regulaor disable failed\n",__func__);
  99. goto regulator_fail;
  100. }
  101. vled_ic_onoff = 0;
  102. printk(KERN_CRIT "%s Regulator OFF!\n",__func__);
  103. }
  104. return ret;
  105. regulator_fail:
  106. regulator_put(vled_ic);
  107. return ret;
  108. }
  109. #endif
  110. static int irda_fw_update(struct ir_remocon_data *ir_data)
  111. {
  112. struct ir_remocon_data *data = ir_data;
  113. struct i2c_client *client = data->client;
  114. int i, k, ret, ret2, checksum, checksum2, frame_count;
  115. u8 buf_ir_test[8];
  116. const u8 *IRDA_fw;
  117. ret = 0;
  118. ret = irda_vdd_onoff(0);
  119. if (ret) {
  120. pr_err("%s Regulator setting failed\n", __func__);
  121. goto err_regulator;
  122. }
  123. data->pdata->ir_wake_en(data->pdata, 0);
  124. msleep(100);
  125. ret = irda_vdd_onoff(1);
  126. if (ret) {
  127. pr_err("%s Regulator setting failed\n", __func__);
  128. goto err_regulator;
  129. }
  130. data->pdata->ir_wake_en(data->pdata,1);
  131. gpio_tlmm_config(GPIO_CFG(data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT,
  132. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  133. msleep(70);
  134. ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH);
  135. if (ret < 0) {
  136. printk(KERN_ERR "%s: err %d\n", __func__, ret);
  137. ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH);
  138. if (ret < 0) {
  139. printk(KERN_INFO "%s: broken FW!\n", __func__);
  140. goto err_bootmode;
  141. }
  142. }
  143. #ifdef DEBUG
  144. print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1,
  145. DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1);
  146. #endif
  147. ret = buf_ir_test[2] << 8 | buf_ir_test[3];
  148. if ((ret == MC96FR116C_0x103) || (ret == MC96FR332A_0x202)) {
  149. data->pdata->ir_wake_en(data->pdata,0);
  150. ret = irda_vdd_onoff(0);
  151. if (ret) {
  152. pr_err("%s Regulator setting failed\n", __func__);
  153. goto err_regulator;
  154. }
  155. data->on_off = 0;
  156. msleep(100);
  157. download_pass = 1;
  158. return 0;
  159. }
  160. if (ret == MC96FR116C_0x101) {
  161. IRDA_fw = IRDA_binary_103;
  162. frame_count = FRAME_COUNT_103;
  163. printk(KERN_ERR "%s: chip : %04x, bin : %04x, need update!\n",
  164. __func__, ret, MC96FR116C_0x103);
  165. }
  166. else if (ret == MC96FR332A_0x201) {
  167. IRDA_fw = IRDA_binary_202;
  168. frame_count = FRAME_COUNT_202;
  169. printk(KERN_ERR "%s: chip : %04x, bin : %04x, need update!\n",
  170. __func__, ret, MC96FR332A_0x202);
  171. }
  172. else
  173. goto err_bootmode;
  174. printk(KERN_ERR "irda frame count = %d\n", frame_count);
  175. ret = irda_vdd_onoff(0);
  176. if (ret) {
  177. pr_err("%s Regulator setting failed\n", __func__);
  178. goto err_regulator;
  179. }
  180. data->pdata->ir_wake_en(data->pdata, 0);
  181. msleep(100);
  182. ret = irda_vdd_onoff(1);
  183. if (ret) {
  184. pr_err("%s Regulator setting failed\n", __func__);
  185. goto err_regulator;
  186. }
  187. msleep(70);
  188. ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH);
  189. if (ret < 0)
  190. printk(KERN_ERR " %s: err %d\n", __func__, ret);
  191. #ifdef DEBUG
  192. print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1,
  193. DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1);
  194. #endif
  195. ret = buf_ir_test[6] << 8 | buf_ir_test[7];
  196. checksum = 0;
  197. for (k = 0; k < 6; k++)
  198. checksum += buf_ir_test[k];
  199. if (ret == checksum)
  200. printk(KERN_INFO "%s: boot mode, FW download start! ret=%04x\n",
  201. __func__, ret);
  202. else {
  203. printk(KERN_ERR "ABOV IC bootcode broken\n");
  204. goto err_bootmode;
  205. }
  206. msleep(30);
  207. for (i = 0; i < frame_count; i++) {
  208. if (i == frame_count-1) {
  209. ret = i2c_master_send(client,
  210. &IRDA_fw[i * 70], 6);
  211. if (ret < 0)
  212. goto err_update;
  213. } else {
  214. ret = i2c_master_send(client,
  215. &IRDA_fw[i * 70], 70);
  216. if (ret < 0)
  217. goto err_update;
  218. }
  219. msleep(30);
  220. }
  221. ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH);
  222. if (ret < 0)
  223. printk(KERN_ERR "5. %s: err %d\n", __func__, ret);
  224. #ifdef DEBUG
  225. print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1,
  226. DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1);
  227. #endif
  228. ret = buf_ir_test[6] << 8 | buf_ir_test[7];
  229. checksum = 0;
  230. for (k = 0; k < 6; k++)
  231. checksum += buf_ir_test[k];
  232. msleep(20);
  233. ret2 = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH);
  234. if (ret2 < 0)
  235. printk(KERN_ERR "6. %s: err %d\n", __func__, ret2);
  236. ret2 = buf_ir_test[6] << 8 | buf_ir_test[7];
  237. for (k = 0; k < 6; k++)
  238. checksum2 += buf_ir_test[k];
  239. if (ret == checksum) {
  240. printk(KERN_INFO "1. %s: boot down complete\n",
  241. __func__);
  242. download_pass = 1;
  243. } else if (ret2 == checksum2) {
  244. printk(KERN_INFO "2. %s: boot down complete\n",
  245. __func__);
  246. download_pass = 1;
  247. } else {
  248. printk(KERN_ERR "FW Checksum fail\n");
  249. goto err_bootmode;
  250. }
  251. ret = irda_vdd_onoff(0);
  252. if (ret) {
  253. pr_err("%s Regulator setting failed\n", __func__);
  254. goto err_regulator;
  255. }
  256. msleep(100);
  257. ret = irda_vdd_onoff(1);
  258. if (ret) {
  259. pr_err("%s Regulator setting failed\n", __func__);
  260. goto err_regulator;
  261. }
  262. data->pdata->ir_wake_en(data->pdata, 1);
  263. msleep(70);
  264. ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH);
  265. ret = buf_ir_test[2] << 8 | buf_ir_test[3];
  266. printk(KERN_INFO "7. %s: user mode : Upgrade FW_version : %04x\n",
  267. __func__, ret);
  268. #ifdef DEBUG
  269. print_hex_dump(KERN_CRIT, "IRDA Master Rx: ", 16, 1,
  270. DUMP_PREFIX_ADDRESS, buf_ir_test, 8, 1);
  271. #endif
  272. data->pdata->ir_wake_en(data->pdata,0);
  273. ret = irda_vdd_onoff(0);
  274. if (ret) {
  275. pr_err("%s Regulator setting failed\n", __func__);
  276. goto err_regulator;
  277. }
  278. data->on_off = 0;
  279. if ((ret == MC96FR116C_0x103) || (ret == MC96FR332A_0x202))
  280. download_pass = 1;
  281. return 0;
  282. err_update:
  283. printk(KERN_ERR "%s: update fail! count : %x, ret = %x\n",
  284. __func__, i, ret);
  285. return ret;
  286. err_bootmode:
  287. printk(KERN_ERR "%s: update fail, checksum = %x ret = %x\n",
  288. __func__, checksum, ret);
  289. data->pdata->ir_wake_en(data->pdata,0);
  290. ret = irda_vdd_onoff(0);
  291. if (ret) {
  292. pr_err("%s Regulator setting failed\n", __func__);
  293. goto err_regulator;
  294. }
  295. data->on_off = 0;
  296. err_regulator:
  297. return ret;
  298. }
  299. static void irda_add_checksum_length(struct ir_remocon_data *ir_data, int count)
  300. {
  301. struct ir_remocon_data *data = ir_data;
  302. int i = 0, csum = 0;
  303. #if 0
  304. printk(KERN_INFO "%s: length: %04x\n", __func__, count);
  305. #endif
  306. data->signal[0] = count >> 8;
  307. data->signal[1] = count & 0xff;
  308. while (i < count) {
  309. csum += data->signal[i];
  310. i++;
  311. }
  312. printk(KERN_INFO "%s: checksum: %04x\n", __func__, csum);
  313. data->signal[count] = csum >> 8;
  314. data->signal[count+1] = csum & 0xff;
  315. }
  316. static int irda_read_device_info(struct ir_remocon_data *ir_data)
  317. {
  318. struct ir_remocon_data *data = ir_data;
  319. struct i2c_client *client = data->client;
  320. u8 buf_ir_test[8];
  321. int ret;
  322. printk(KERN_INFO"%s called\n", __func__);
  323. ret = irda_vdd_onoff(1);
  324. if (ret) {
  325. pr_err("%s Regulator setting failed\n", __func__);
  326. goto err_regulator;
  327. }
  328. data->pdata->ir_wake_en(data->pdata,1);
  329. msleep(60);
  330. ret = i2c_master_recv(client, buf_ir_test, MC96_READ_LENGTH);
  331. if (ret < 0)
  332. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  333. printk(KERN_INFO "%s: buf_ir dev_id: 0x%02x, 0x%02x\n", __func__,
  334. buf_ir_test[2], buf_ir_test[3]);
  335. ret = data->dev_id = (buf_ir_test[2] << 8 | buf_ir_test[3]);
  336. data->pdata->ir_wake_en(data->pdata,0);
  337. ret = irda_vdd_onoff(0);
  338. if (ret) {
  339. pr_err("%s Regulator setting failed\n", __func__);
  340. goto err_regulator;
  341. }
  342. data->on_off = 0;
  343. err_regulator:
  344. return ret;
  345. }
  346. static void irda_remocon_work(struct ir_remocon_data *ir_data, int count)
  347. {
  348. struct ir_remocon_data *data = ir_data;
  349. struct i2c_client *client = data->client;
  350. int buf_size = count+2;
  351. int ret;
  352. int sleep_timing;
  353. int end_data;
  354. int emission_time;
  355. int ack_pin_onoff;
  356. if (count_number >= 100)
  357. count_number = 0;
  358. count_number++;
  359. gpio_tlmm_config(GPIO_CFG(ir_data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT,
  360. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  361. printk(KERN_INFO "%s: total buf_size: %d\n", __func__, buf_size);
  362. irda_add_checksum_length(data, count);
  363. mutex_lock(&data->mutex);
  364. ret = i2c_master_send(client, data->signal, buf_size);
  365. if (ret < 0) {
  366. dev_err(&client->dev, "%s: err1 %d\n", __func__, ret);
  367. ret = i2c_master_send(client, data->signal, buf_size);
  368. if (ret < 0)
  369. dev_err(&client->dev, "%s: err2 %d\n", __func__, ret);
  370. }
  371. mdelay(10);
  372. ack_pin_onoff = 0;
  373. if (gpio_get_value(data->pdata->irda_irq_gpio)) {
  374. printk(KERN_INFO "%s : %d Checksum NG!\n",
  375. __func__, count_number);
  376. ack_pin_onoff = 1;
  377. } else {
  378. printk(KERN_INFO "%s : %d Checksum OK!\n",
  379. __func__, count_number);
  380. ack_pin_onoff = 2;
  381. }
  382. ack_number = ack_pin_onoff;
  383. mutex_unlock(&data->mutex);
  384. #if 0
  385. for (i = 0; i < buf_size; i++) {
  386. printk(KERN_INFO "%s: data[%d] : 0x%02x\n", __func__, i,
  387. data->signal[i]);
  388. }
  389. #endif
  390. data->count = 2;
  391. end_data = data->signal[count-2] << 8 | data->signal[count-1];
  392. emission_time = \
  393. (1000 * (data->ir_sum - end_data) / (data->ir_freq)) + 10;
  394. sleep_timing = emission_time - 130;
  395. if (sleep_timing > 0)
  396. msleep(sleep_timing);
  397. /*
  398. printk(KERN_INFO "%s: sleep_timing = %d\n", __func__, sleep_timing);
  399. */
  400. emission_time = \
  401. (1000 * (data->ir_sum) / (data->ir_freq)) + 50;
  402. if (emission_time > 0)
  403. msleep(emission_time);
  404. printk(KERN_INFO "%s: emission_time = %d\n",
  405. __func__, emission_time);
  406. if (gpio_get_value(data->pdata->irda_irq_gpio)) {
  407. printk(KERN_INFO "%s : %d Sending IR OK!\n",
  408. __func__, count_number);
  409. ack_pin_onoff = 4;
  410. } else {
  411. printk(KERN_INFO "%s : %d Sending IR NG!\n",
  412. __func__, count_number);
  413. ack_pin_onoff = 2;
  414. }
  415. ack_number += ack_pin_onoff;
  416. #ifndef USE_STOP_MODE
  417. data->on_off = 0;
  418. data->pdata->ir_wake_en(data->pdata,0);
  419. irda_vdd_onoff(0);
  420. gpio_set_value(data->pdata->irda_led_en, 0);
  421. #endif
  422. data->ir_freq = 0;
  423. data->ir_sum = 0;
  424. gpio_tlmm_config(GPIO_CFG(ir_data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT,
  425. GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  426. }
  427. static ssize_t remocon_store(struct device *dev, struct device_attribute *attr,
  428. const char *buf, size_t size)
  429. {
  430. struct ir_remocon_data *data = dev_get_drvdata(dev);
  431. unsigned int _data;
  432. int count, i, ret;
  433. ret = 0;
  434. gpio_set_value(data->pdata->irda_led_en, 1);
  435. for (i = 0; i < MAX_SIZE; i++) {
  436. if (sscanf(buf++, "%u", &_data) == 1) {
  437. if (_data == 0 || buf == '\0')
  438. break;
  439. if (data->count == 2) {
  440. data->ir_freq = _data;
  441. if (data->on_off) {
  442. data->pdata->ir_wake_en(data->pdata,0);
  443. udelay(200);
  444. data->pdata->ir_wake_en(data->pdata,1);
  445. msleep(30);
  446. } else {
  447. ret = irda_vdd_onoff(1);
  448. if (ret) {
  449. pr_err("%s regulaor disable failed\n",
  450. __func__);
  451. return ret;
  452. }
  453. data->pdata->ir_wake_en(data->pdata,1);
  454. msleep(80);
  455. data->on_off = 1;
  456. }
  457. data->signal[2] = _data >> 16;
  458. data->signal[3] = (_data >> 8) & 0xFF;
  459. data->signal[4] = _data & 0xFF;
  460. data->count += 3;
  461. } else {
  462. data->ir_sum += _data;
  463. count = data->count;
  464. data->signal[count] = _data >> 8;
  465. data->signal[count+1] = _data & 0xFF;
  466. data->count += 2;
  467. }
  468. while (_data > 0) {
  469. buf++;
  470. _data /= 10;
  471. }
  472. } else {
  473. break;
  474. }
  475. }
  476. irda_remocon_work(data, data->count);
  477. return size;
  478. }
  479. static ssize_t remocon_show(struct device *dev, struct device_attribute *attr,
  480. char *buf)
  481. {
  482. struct ir_remocon_data *data = dev_get_drvdata(dev);
  483. int i;
  484. char *bufp = buf;
  485. for (i = 5; i < MAX_SIZE - 1; i++) {
  486. if (data->signal[i] == 0 && data->signal[i+1] == 0)
  487. break;
  488. else
  489. bufp += sprintf(bufp, "%u,", data->signal[i]);
  490. }
  491. return strlen(buf);
  492. }
  493. static ssize_t remocon_ack(struct device *dev, struct device_attribute *attr,
  494. char *buf)
  495. {
  496. //struct ir_remocon_data *data = dev_get_drvdata(dev);
  497. printk(KERN_INFO "%s : ack_number = %d\n", __func__, ack_number);
  498. if (ack_number == 6)
  499. return sprintf(buf, "1\n");
  500. else
  501. return sprintf(buf, "0\n");
  502. }
  503. static DEVICE_ATTR(ir_send, 0664, remocon_show, remocon_store);
  504. static DEVICE_ATTR(ir_send_result, 0664, remocon_ack, NULL);
  505. static ssize_t check_ir_show(struct device *dev, struct device_attribute *attr,
  506. char *buf)
  507. {
  508. struct ir_remocon_data *data = dev_get_drvdata(dev);
  509. int ret;
  510. ret = irda_read_device_info(data);
  511. return snprintf(buf, 4, "%d\n", ret);
  512. }
  513. static DEVICE_ATTR(check_ir, 0664, check_ir_show, NULL);
  514. #ifdef CONFIG_OF
  515. static int irda_mc96_parse_dt(struct device *dev, struct mc96_platform_data *pdata)
  516. {
  517. struct device_node *np = dev->of_node;
  518. pdata->irda_irq_gpio = of_get_named_gpio_flags(np, "mc96fr332,irda_irq_gpio",
  519. 0, &pdata->irq_gpio_flags);
  520. if (pdata->irda_irq_gpio < 0) {
  521. pr_err("%s failed to get irda_irq_gpio\n", __func__);
  522. return pdata->irda_irq_gpio;
  523. }
  524. pdata->irda_led_en = of_get_named_gpio_flags(np, "mc96fr332,irda_led_en",
  525. 0, &pdata->led_en_flags);
  526. if (pdata->irda_led_en < 0) {
  527. pr_err("%s failed to get irda_led_en\n", __func__);
  528. return pdata->irda_led_en;
  529. }
  530. pdata->irda_wake_en = of_get_named_gpio_flags(np, "mc96fr332,irda_wake",
  531. 0, &pdata->wake_en_flags);
  532. if (pdata->irda_wake_en < 0) {
  533. pr_err("%s failed to get irda_wake_en\n", __func__);
  534. return pdata->irda_wake_en;
  535. }
  536. pdata->irda_scl_gpio = of_get_named_gpio_flags(np, "mc96fr332,scl-gpio",
  537. 0, &pdata->irda_scl_flags);
  538. if (pdata->irda_scl_gpio < 0) {
  539. pr_err("%s failed to get irda_scl_gpio\n", __func__);
  540. return pdata->irda_wake_en;
  541. }
  542. pdata->irda_sda_gpio = of_get_named_gpio_flags(np, "mc96fr332,sda-gpio",
  543. 0, &pdata->irda_sda_flags);
  544. if (pdata->irda_sda_gpio < 0) {
  545. pr_err("%s failed to get irda_sda_gpio\n", __func__);
  546. return pdata->irda_sda_gpio;
  547. }
  548. pr_info("%s: irq-gpio:%u led_en:%u wake_up:%u irda-scl:%u irda-sda:%u \n", __func__,
  549. pdata->irda_irq_gpio,pdata->irda_led_en,pdata->irda_wake_en,pdata->irda_scl_gpio,pdata->irda_sda_gpio);
  550. return 0;
  551. }
  552. #endif
  553. static int __devinit irda_remocon_probe(struct i2c_client *client,
  554. const struct i2c_device_id *id)
  555. {
  556. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  557. struct ir_remocon_data *data;
  558. struct device *ir_remocon_dev;
  559. struct mc96_platform_data *pdata;
  560. int i, error;
  561. int ret;
  562. printk(KERN_INFO "%s start!\n", __func__);
  563. dev_info(&client->dev,"%s:ir_remocon probe called \n",__func__);
  564. if(client->dev.of_node) {
  565. pdata = devm_kzalloc(&client->dev,
  566. sizeof(struct mc96_platform_data), GFP_KERNEL);
  567. if (!pdata) {
  568. dev_err(&client->dev, "Failed to allocate memory \n");
  569. return -ENOMEM;
  570. }
  571. ret = irda_mc96_parse_dt(&client->dev, pdata);
  572. if (ret < 0)
  573. {
  574. dev_err(&client->dev,"Parse failed \n");
  575. return ret;
  576. }
  577. pdata->ir_wake_en = irda_wake_en;
  578. if(gpio_request(pdata->irda_wake_en, "IRDA Wakeup EN Pin"))
  579. pr_err("%s IRDA Wakeup EN GPIO Request failed\n",__func__);
  580. gpio_tlmm_config(GPIO_CFG(pdata->irda_wake_en, 0, GPIO_CFG_OUTPUT,
  581. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_DISABLE);
  582. gpio_tlmm_config(GPIO_CFG(pdata->irda_led_en, 0, GPIO_CFG_OUTPUT,
  583. GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  584. gpio_request(pdata->irda_led_en, "irda_led_en");
  585. gpio_direction_output(pdata->irda_led_en, 1);
  586. if (gpio_request(pdata->irda_irq_gpio, "ira_irq"))
  587. pr_err("%s IRDA LED IRQ GPIO Request failed\n",__func__);
  588. gpio_direction_input(pdata->irda_irq_gpio);
  589. } else
  590. pdata = client->dev.platform_data;
  591. if (!pdata)
  592. return -EINVAL;
  593. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  594. return -EIO;
  595. data = kzalloc(sizeof(struct ir_remocon_data), GFP_KERNEL);
  596. if (NULL == data) {
  597. pr_err("Failed to data allocate %s\n", __func__);
  598. error = -ENOMEM;
  599. goto err_free_mem;
  600. }
  601. data->client = client;
  602. if (client->dev.of_node)
  603. {
  604. data->pdata = pdata;
  605. }else
  606. data->pdata = client->dev.platform_data;
  607. mutex_init(&data->mutex);
  608. data->count = 2;
  609. data->on_off = 0;
  610. vled_ic = regulator_get(&client->dev, "vled_ic_1.9v");
  611. if (IS_ERR(vled_ic)) {
  612. pr_err("%s could not get regulator vled_ic_1.9v\n",__func__);
  613. error = -EBUSY;
  614. goto err_free_mem;
  615. }
  616. i2c_set_clientdata(client, data);
  617. for (i = 0; i < 2; i++) {
  618. if (download_pass == 1)
  619. break;
  620. irda_fw_update(data);
  621. }
  622. if (download_pass != 1)
  623. goto err_fw_update_fail;
  624. gpio_set_value(pdata->irda_led_en, 0);
  625. // irda_read_device_info(data);
  626. ir_remocon_dev = device_create(sec_class, NULL, 0, data, "sec_ir");
  627. if (IS_ERR(ir_remocon_dev))
  628. pr_err("Failed to create ir_remocon_dev device\n");
  629. if (device_create_file(ir_remocon_dev, &dev_attr_ir_send) < 0)
  630. pr_err("Failed to create device file(%s)!\n",
  631. dev_attr_ir_send.attr.name);
  632. if (device_create_file(ir_remocon_dev, &dev_attr_ir_send_result) < 0)
  633. pr_err("Failed to create device file(%s)!\n",
  634. dev_attr_ir_send.attr.name);
  635. if (device_create_file(ir_remocon_dev, &dev_attr_check_ir) < 0)
  636. pr_err("Failed to create device file(%s)!\n",
  637. dev_attr_check_ir.attr.name);
  638. #ifdef CONFIG_HAS_EARLYSUSPEND
  639. data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  640. data->early_suspend.suspend = ir_remocon_early_suspend;
  641. data->early_suspend.resume = ir_remocon_late_resume;
  642. register_early_suspend(&data->early_suspend);
  643. #endif
  644. gpio_tlmm_config(GPIO_CFG(data->pdata->irda_irq_gpio, 0, GPIO_CFG_INPUT,
  645. GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  646. return 0;
  647. err_fw_update_fail:
  648. regulator_put(vled_ic);
  649. err_free_mem:
  650. kfree(data);
  651. return error;
  652. }
  653. #if defined(CONFIG_PM) || defined(CONFIG_HAS_EARLYSUSPEND)
  654. static int ir_remocon_suspend(struct device *dev)
  655. {
  656. struct i2c_client *client = to_i2c_client(dev);
  657. struct ir_remocon_data *data = i2c_get_clientdata(client);
  658. int ret = 0;
  659. ret = irda_vdd_onoff(0);
  660. if (ret)
  661. pr_err("%s Regulator setting failed\n", __func__);
  662. data->on_off = 0;
  663. data->pdata->ir_wake_en(data->pdata,0);
  664. return ret;
  665. }
  666. static int ir_remocon_resume(struct device *dev)
  667. {
  668. return 0;
  669. }
  670. #endif
  671. #ifdef CONFIG_HAS_EARLYSUSPEND
  672. static void ir_remocon_early_suspend(struct early_suspend *h)
  673. {
  674. struct ir_remocon_data *data;
  675. data = container_of(h, struct ir_remocon_data, early_suspend);
  676. ir_remocon_suspend(&data->client->dev);
  677. }
  678. static void ir_remocon_late_resume(struct early_suspend *h)
  679. {
  680. struct ir_remocon_data *data;
  681. data = container_of(h, struct ir_remocon_data, early_suspend);
  682. ir_remocon_resume(&data->client->dev);
  683. }
  684. #endif
  685. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND)
  686. static const struct dev_pm_ops ir_remocon_pm_ops = {
  687. .suspend = ir_remocon_suspend,
  688. .resume = ir_remocon_resume,
  689. };
  690. #endif
  691. static int __devexit ir_remocon_remove(struct i2c_client *client)
  692. {
  693. struct ir_remocon_data *data = i2c_get_clientdata(client);
  694. mutex_destroy(&data->mutex);
  695. i2c_set_clientdata(client, NULL);
  696. regulator_disable(vled_ic);
  697. regulator_put(vled_ic);
  698. kfree(data);
  699. return 0;
  700. }
  701. static const struct i2c_device_id mc96_id[] = {
  702. {"mc96", 0},
  703. {}
  704. };
  705. MODULE_DEVICE_TABLE(i2c, mc96_id);
  706. static struct of_device_id mc96_i2c_match_table[] = {
  707. { .compatible = "mc96fr332,i2c",},
  708. {},
  709. };
  710. MODULE_DEVICE_TABLE(of, mc96_i2c_match_table);
  711. static struct i2c_driver mc96_i2c_driver = {
  712. .driver = {
  713. .name = "mc96",
  714. .owner = THIS_MODULE,
  715. .of_match_table = mc96_i2c_match_table,
  716. },
  717. .probe = irda_remocon_probe,
  718. .remove = __devexit_p(ir_remocon_remove),
  719. #if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND)
  720. //.pm = &ir_remocon_pm_ops,
  721. #endif
  722. .id_table = mc96_id,
  723. };
  724. static int __init ir_remocon_init(void)
  725. {
  726. return i2c_add_driver(&mc96_i2c_driver);
  727. }
  728. module_init(ir_remocon_init);
  729. static void __exit ir_remocon_exit(void)
  730. {
  731. i2c_del_driver(&mc96_i2c_driver);
  732. }
  733. module_exit(ir_remocon_exit);
  734. MODULE_LICENSE("GPL");
  735. MODULE_DESCRIPTION("SEC IR remote controller");