barcode_emul_ice4.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. /*
  2. * driver/barcode_emul Barcode emulator 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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/err.h>
  25. #include <linux/i2c.h>
  26. #include <linux/irq.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/irq.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/slab.h>
  31. #include <linux/delay.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/device.h>
  34. #include <linux/earlysuspend.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/gpio.h>
  37. #include <linux/uaccess.h>
  38. #include <linux/fs.h>
  39. #include <linux/clk.h>
  40. #include <linux/firmware.h>
  41. #include <linux/barcode_emul.h>
  42. #include <linux/regulator/consumer.h>
  43. #include <linux/of_gpio.h>
  44. #if defined(CONFIG_IR_REMOCON_FPGA)
  45. #include <linux/ir_remote_con.h>
  46. #endif
  47. #include "barcode_emul_ice4.h"
  48. #include <linux/err.h>
  49. #define US_TO_PATTERN 1000000
  50. #if defined(TEST_DEBUG)
  51. #define pr_barcode pr_emerg
  52. #else
  53. #define pr_barcode pr_info
  54. #endif
  55. #define LOOP_BACK 48
  56. #define TEST_CODE1 49
  57. #define TEST_CODE2 50
  58. #define FW_VER_ADDR 0x80
  59. #define BEAM_STATUS_ADDR 0xFE
  60. #define SEC_FPGA_MAX_FW_PATH 255
  61. #define SEC_FPGA_FW_FILENAME "i2c_top_bitmap.bin"
  62. #define IRDA_BUFFER_MAX_SIZE 255
  63. #define BARCODE_I2C_ADDR 0x6C
  64. #define FIRMWARE_MAX_RETRY 2
  65. #define GPIO_FPGA_MAIN_CLK 26
  66. #define MSM_SEC_FPGA_I2C_BUS_ID 13
  67. #if defined(CONFIG_IR_REMOCON_FPGA)
  68. #define IRDA_I2C_ADDR 0x50
  69. #define IRDA_TEST_CODE_SIZE 140
  70. #define IRDA_TEST_CODE_ADDR 0x00
  71. #define MAX_SIZE 2048
  72. #define READ_LENGTH 8
  73. #endif
  74. struct barcode_emul_data {
  75. struct i2c_client *client;
  76. struct workqueue_struct *firmware_dl;
  77. struct delayed_work fw_dl;
  78. const struct firmware *fw;
  79. #if defined(CONFIG_IR_REMOCON_FPGA)
  80. struct mutex mutex;
  81. struct {
  82. unsigned char addr;
  83. unsigned char data[MAX_SIZE];
  84. } i2c_block_transfer;
  85. struct mc96_platform_data *pdata;
  86. int length;
  87. int count;
  88. int dev_id;
  89. int ir_freq;
  90. int ir_sum;
  91. int on_off;
  92. #endif
  93. };
  94. #if defined(CONFIG_IR_REMOCON_FPGA)
  95. static int ack_number;
  96. static int count_number;
  97. #endif
  98. static struct barcode_emul_platform_data *g_pdata;
  99. static int Is_clk_enabled;
  100. static int enable_counte;
  101. static int Is_beaming;
  102. static struct mutex en_mutex;
  103. static struct i2c_client *g_client;
  104. static int gpiox_state;
  105. static bool fw_dl_complete;
  106. #if defined(CONFIG_SEC_MELIUSCA_PROJECT)
  107. static struct regulator *barcode_l20_2p95=NULL;
  108. static int bc_poweron(struct device dev)
  109. {
  110. int ret;
  111. printk(KERN_ERR "%s\n",__func__);
  112. barcode_l20_2p95 = regulator_get(NULL, "8941_l20");
  113. if (IS_ERR(barcode_l20_2p95)) {
  114. pr_err("%s: could not get vdda vreg, rc=%ld\n",
  115. __func__, PTR_ERR(barcode_l20_2p95));
  116. return PTR_ERR(barcode_l20_2p95);
  117. }
  118. ret = regulator_set_voltage(barcode_l20_2p95,
  119. 2950000, 2950000);
  120. if (ret)
  121. pr_err("%s: error vreg_l20 set voltage ret=%d\n",
  122. __func__, ret);
  123. ret = regulator_enable(barcode_l20_2p95);
  124. if (ret)
  125. pr_err("%s: error l20 enabling regulator\n", __func__);
  126. return 0;
  127. }
  128. #endif
  129. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  130. static int check_cdone_state(void)
  131. {
  132. if (gpio_get_value(g_pdata->cdone) != 1) {
  133. pr_err("%s: cdone fail & set gpio!\n", __func__);
  134. gpio_tlmm_config(GPIO_CFG(g_pdata->cdone, 0,
  135. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  136. udelay(100);
  137. }
  138. return 0;
  139. }
  140. #endif
  141. #if defined(CONFIG_SEC_MELIUSCA_PROJECT)
  142. static void irda_wake_en(bool onoff)
  143. {
  144. gpio_direction_output(g_pdata->rst_n, onoff);
  145. printk(KERN_ERR "%s: %d\n", __func__, onoff);
  146. }
  147. #else
  148. static void irda_wake_en(bool onoff)
  149. {
  150. gpio_direction_output(g_pdata->irda_wake, onoff);
  151. printk(KERN_ERR "%s: %d\n", __func__, onoff);
  152. }
  153. #endif
  154. static int ice4_clock_en(int onoff)
  155. {
  156. static struct clk *fpga_main_src_clk;
  157. static struct clk *fpga_main_clk;
  158. if (!fpga_main_src_clk){
  159. fpga_main_src_clk = clk_get(NULL, "cam_gp0_src_clk");
  160. }
  161. if (IS_ERR(fpga_main_src_clk)) {
  162. pr_err( "%s: unable to get fpga_main_src_clk\n", __func__);
  163. }
  164. if (!fpga_main_clk){
  165. fpga_main_clk = clk_get(NULL, "cam_gp0_clk");
  166. }
  167. if (IS_ERR(fpga_main_clk)) {
  168. pr_err( "%s: unable to get fpga_main_clk\n", __func__);
  169. }
  170. if (onoff) {
  171. clk_set_rate(fpga_main_src_clk, 24000000);
  172. clk_prepare_enable(fpga_main_clk);
  173. } else {
  174. clk_disable_unprepare(fpga_main_clk);
  175. clk_put(fpga_main_src_clk);
  176. clk_put(fpga_main_clk);
  177. fpga_main_src_clk = NULL;
  178. fpga_main_clk = NULL;
  179. }
  180. return 0;
  181. }
  182. static void fpga_enable(int enable)
  183. {
  184. int ret;
  185. printk(KERN_ERR "%s start %d,%d,%d,%d\n",__func__,enable,Is_clk_enabled,enable_counte,Is_beaming);
  186. if (enable) {
  187. enable_counte++;
  188. if (!Is_clk_enabled && (enable_counte ==1)) {
  189. mutex_lock(&en_mutex);
  190. ret = ice4_clock_en(1);
  191. gpio_set_value(g_pdata->rst_n, GPIO_LEVEL_HIGH);
  192. usleep_range(1000, 2000);
  193. printk(KERN_ERR "%s enable usleep end count =%d\n",__func__,enable_counte);
  194. Is_clk_enabled = 1;
  195. }
  196. } else {
  197. if (Is_clk_enabled && !Is_beaming && (enable_counte==1)) {
  198. usleep_range(20000, 25000);
  199. printk(KERN_ERR "%s disable usleep end count =%d\n",__func__,enable_counte);
  200. if (enable_counte==1) {
  201. Is_clk_enabled = 0;
  202. gpio_set_value(g_pdata->rst_n, GPIO_LEVEL_LOW);
  203. ret = ice4_clock_en(0);
  204. mutex_unlock(&en_mutex);
  205. }
  206. }
  207. if(enable_counte<0){
  208. printk(KERN_ERR "%s enable_counte ERR!= %d\n",__func__,enable_counte);
  209. enable_counte =0;
  210. }else{
  211. enable_counte--;
  212. }
  213. }
  214. printk(KERN_ERR "%s end %d,%d,%d,%d\n",__func__,enable,Is_clk_enabled,enable_counte,Is_beaming);
  215. }
  216. #ifdef CONFIG_OF
  217. static int barcode_parse_dt(struct device *dev,
  218. struct barcode_emul_platform_data *pdata)
  219. {
  220. struct device_node *np = dev->of_node;
  221. /* reset, irq gpio info */
  222. pdata->cresetb = of_get_named_gpio_flags(np, "barcode,cresetb",
  223. 0, &pdata->cresetb_flag);
  224. pdata->rst_n = of_get_named_gpio_flags(np, "barcode,reset_n",
  225. 0, &pdata->rst_n_flag);
  226. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  227. pdata->cdone = of_get_named_gpio_flags(np, "barcode,cdone",
  228. 0, &pdata->cdone_flag);
  229. pdata->irda_wake = of_get_named_gpio(np, "barcode,irda_en", 0);
  230. #endif
  231. pdata->spi_clk =of_get_named_gpio_flags(np, "barcode,scl-gpio",
  232. 0, &pdata->spi_clk_flag);
  233. pdata->spi_si =of_get_named_gpio_flags(np, "barcode,sda-gpio",
  234. 0, &pdata->spi_si_flag);
  235. pdata->irda_irq =of_get_named_gpio_flags(np, "barcode,irq-gpio",
  236. 0, &pdata->irda_irq_flag);
  237. return 0;
  238. }
  239. #else
  240. static int barcode_parse_dt(struct device *dev,
  241. struct cypress_touchkey_platform_data *pdata)
  242. {
  243. return -ENODEV;
  244. }
  245. #endif
  246. static void barcode_gpio_config(void)
  247. {
  248. pr_info("%s\n", __func__);
  249. gpio_tlmm_config(GPIO_CFG(g_pdata->spi_si, 0,
  250. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  251. gpio_tlmm_config(GPIO_CFG(g_pdata->spi_clk, 0,
  252. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  253. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  254. gpio_tlmm_config(GPIO_CFG(g_pdata->cdone, 0,
  255. GPIO_CFG_INPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  256. gpio_request(g_pdata->irda_wake, "irda_en");
  257. gpio_direction_output(g_pdata->irda_wake,0);
  258. #endif
  259. gpio_request(g_pdata->cresetb, "irda_creset");
  260. gpio_direction_output(g_pdata->cresetb, 0);
  261. gpio_request(g_pdata->rst_n, "irda_rst_n");
  262. gpio_direction_output(g_pdata->rst_n, 0);
  263. gpio_request(g_pdata->irda_irq, "irda_irq");
  264. gpio_direction_input(g_pdata->irda_irq);
  265. gpio_tlmm_config(GPIO_CFG(GPIO_FPGA_MAIN_CLK, \
  266. 6, GPIO_CFG_OUTPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  267. }
  268. /*
  269. * Send barcode emulator firmware data thougth spi communication
  270. */
  271. static int barcode_send_firmware_data(const u8 *data, int len)
  272. {
  273. unsigned int i, j;
  274. unsigned char spibit;
  275. i = 0;
  276. while (i < len) {
  277. j = 0;
  278. spibit = data[i];
  279. while (j < 8) {
  280. gpio_set_value_cansleep(g_pdata->spi_clk,
  281. GPIO_LEVEL_LOW);
  282. if (spibit & 0x80)
  283. gpio_set_value_cansleep(g_pdata->spi_si,
  284. GPIO_LEVEL_HIGH);
  285. else
  286. gpio_set_value_cansleep(g_pdata->spi_si,
  287. GPIO_LEVEL_LOW);
  288. j = j+1;
  289. gpio_set_value_cansleep(g_pdata->spi_clk,
  290. GPIO_LEVEL_HIGH);
  291. spibit = spibit<<1;
  292. }
  293. i = i+1;
  294. }
  295. i = 0;
  296. while (i < 200) {
  297. gpio_set_value_cansleep(g_pdata->spi_clk, GPIO_LEVEL_LOW);
  298. i = i+1;
  299. gpio_set_value_cansleep(g_pdata->spi_clk, GPIO_LEVEL_HIGH);
  300. }
  301. return 0;
  302. }
  303. static int barcode_fpga_fimrware_update_start(const u8 *data, int len)
  304. {
  305. int retry = FIRMWARE_MAX_RETRY;
  306. pr_barcode("%s\n", __func__);
  307. fpga_enable(1);
  308. do {
  309. gpio_set_value(g_pdata->rst_n, GPIO_LEVEL_LOW);
  310. gpio_set_value(g_pdata->cresetb, GPIO_LEVEL_LOW);
  311. usleep_range(30, 50);
  312. gpio_set_value(g_pdata->cresetb, GPIO_LEVEL_HIGH);
  313. usleep_range(1000, 1300);
  314. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  315. if (gpio_get_value(g_pdata->cdone))
  316. pr_err("%s cdone HIGH before firmware download",
  317. __func__);
  318. #endif
  319. barcode_send_firmware_data(data, len);
  320. usleep_range(50, 70);
  321. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  322. if (gpio_get_value(g_pdata->cdone)) {
  323. udelay(5);
  324. pr_barcode("FPGA firmware update success\n");
  325. fw_dl_complete = true;
  326. break;
  327. } else {
  328. pr_barcode("FPGA firmware update fail\n");
  329. if (--retry)
  330. pr_err("FPGA firmware update retry..");
  331. else
  332. pr_err("FPGA FIRMWARE_MAX_RETRY reached");
  333. }
  334. #else
  335. udelay(5);
  336. pr_barcode("FPGA firmware update success\n");
  337. fw_dl_complete = true;
  338. break;
  339. #endif
  340. } while (retry);
  341. fpga_enable(0);
  342. return 0;
  343. }
  344. void ice4_fpga_firmware_update(void)
  345. {
  346. if (g_pdata->fw_type == ICE_19M)
  347. barcode_fpga_fimrware_update_start(spiword,
  348. sizeof(spiword));
  349. else if (g_pdata->fw_type == ICE_I2C)
  350. barcode_fpga_fimrware_update_start(spiword_i2c,
  351. sizeof(spiword_i2c));
  352. else if (g_pdata->fw_type == ICE_24M)
  353. barcode_fpga_fimrware_update_start(spiword_24m,
  354. sizeof(spiword_24m));
  355. else
  356. barcode_fpga_fimrware_update_start(spiword,
  357. sizeof(spiword));
  358. //verification with dummy gpio
  359. gpio_tlmm_config(GPIO_CFG(g_pdata->spi_si, 3,
  360. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  361. gpio_tlmm_config(GPIO_CFG(g_pdata->spi_clk, 3,
  362. GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), 1);
  363. usleep_range(10000, 12000);
  364. ice_gpiox_get(1);
  365. }
  366. static ssize_t barcode_emul_store(struct device *dev,
  367. struct device_attribute *attr,
  368. const char *buf, size_t size)
  369. {
  370. int ret;
  371. struct barcode_emul_data *data = dev_get_drvdata(dev);
  372. struct i2c_client *client = data->client;
  373. pr_barcode("%s start\n", __func__);
  374. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  375. check_cdone_state();
  376. if (gpio_get_value(g_pdata->cdone) != 1) {
  377. pr_err("%s: cdone fail !!\n", __func__);
  378. return 1;
  379. }
  380. #endif
  381. fpga_enable(1);
  382. client->addr = BARCODE_I2C_ADDR;
  383. ret = i2c_master_send(client, buf, size);
  384. if (ret < 0) {
  385. pr_err("%s: i2c err1 %d\n", __func__, ret);
  386. ret = i2c_master_send(client, buf, size);
  387. if (ret < 0)
  388. pr_err("%s: i2c err2 %d\n", __func__, ret);
  389. }
  390. pr_barcode("%s complete\n", __func__);
  391. if ((buf[0] == 0xFF) && (buf[1] != STOP_BEAMING)) {
  392. pr_barcode("%s BEAMING START\n", __func__);
  393. Is_beaming = BEAMING_ON;
  394. } else if ((buf[0] == 0xFF) && (buf[1] == STOP_BEAMING)) {
  395. pr_barcode("%s BEAMING STOP\n", __func__);
  396. Is_beaming = BEAMING_OFF;
  397. }
  398. fpga_enable(0);
  399. return size;
  400. }
  401. static ssize_t barcode_emul_show(struct device *dev,
  402. struct device_attribute *attr,
  403. char *buf)
  404. {
  405. return strlen(buf);
  406. }
  407. static DEVICE_ATTR(barcode_send, 0664, barcode_emul_show, barcode_emul_store);
  408. static ssize_t barcode_emul_fw_update_store(struct device *dev,
  409. struct device_attribute *attr,
  410. const char *buf, size_t size)
  411. {
  412. struct barcode_emul_data *data = dev_get_drvdata(dev);
  413. if (request_firmware(&data->fw, SEC_FPGA_FW_FILENAME,
  414. dev)) {
  415. pr_err("%s: Can't open firmware file\n",
  416. __func__);
  417. goto firmwareload_fail;
  418. }
  419. barcode_fpga_fimrware_update_start(data->fw->data, data->fw->size);
  420. release_firmware(data->fw);
  421. firmwareload_fail:
  422. return size;
  423. }
  424. static ssize_t barcode_emul_fw_update_show(struct device *dev,
  425. struct device_attribute *attr,
  426. char *buf)
  427. {
  428. return strlen(buf);
  429. }
  430. static DEVICE_ATTR(barcode_fw_update, 0664,
  431. barcode_emul_fw_update_show,
  432. barcode_emul_fw_update_store);
  433. static int barcode_emul_read(struct i2c_client *client, u16 addr,
  434. u8 length, u8 *value)
  435. {
  436. struct i2c_msg msg[2];
  437. int ret;
  438. msg[0].addr = client->addr;
  439. msg[0].flags = 0x00;
  440. msg[0].len = 1;
  441. msg[0].buf = (u8 *) &addr;
  442. msg[1].addr = client->addr;
  443. msg[1].flags = I2C_M_RD;
  444. msg[1].len = length;
  445. msg[1].buf = (u8 *) value;
  446. fpga_enable(1);
  447. ret = i2c_transfer(client->adapter, msg, 2);
  448. if (ret == 2) {
  449. fpga_enable(0);
  450. return 0;
  451. } else {
  452. pr_barcode("%s: err1 %d\n", __func__, ret);
  453. fpga_enable(0);
  454. return -EIO;
  455. }
  456. }
  457. static ssize_t barcode_emul_test_store(struct device *dev,
  458. struct device_attribute *attr,
  459. const char *buf, size_t size)
  460. {
  461. int ret, i;
  462. struct barcode_emul_data *data = dev_get_drvdata(dev);
  463. struct i2c_client *client = data->client;
  464. struct {
  465. unsigned char addr;
  466. unsigned char data[20];
  467. } i2c_block_transfer;
  468. unsigned char barcode_data[14] = {0xFF, 0xAC, 0xDB, 0x36, 0x42, 0x85,
  469. 0x0A, 0xA8, 0xD1, 0xA3, 0x46, 0xC5, 0xDA, 0xFF};
  470. client->addr = BARCODE_I2C_ADDR;
  471. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  472. check_cdone_state();
  473. if (gpio_get_value(g_pdata->cdone) != 1) {
  474. pr_err("%s: cdone fail !!\n", __func__);
  475. return 1;
  476. }
  477. #endif
  478. fpga_enable(1);
  479. if (buf[0] == LOOP_BACK) {
  480. for (i = 0; i < size; i++)
  481. i2c_block_transfer.data[i] = *buf++;
  482. i2c_block_transfer.addr = 0x01;
  483. pr_barcode("%s: write addr: %d, value: %d\n", __func__,
  484. i2c_block_transfer.addr, i2c_block_transfer.data[0]);
  485. ret = i2c_master_send(client,
  486. (unsigned char *) &i2c_block_transfer, 2);
  487. if (ret < 0) {
  488. pr_barcode("%s: err1 %d\n", __func__, ret);
  489. ret = i2c_master_send(client,
  490. (unsigned char *) &i2c_block_transfer, 2);
  491. if (ret < 0)
  492. pr_barcode("%s: err2 %d\n", __func__, ret);
  493. }
  494. } else if (buf[0] == TEST_CODE1) {
  495. unsigned char BSR_data[6] =\
  496. {0xC8, 0x00, 0x32, 0x01, 0x00, 0x32};
  497. pr_barcode("barcode test code start\n");
  498. /* send NH */
  499. i2c_block_transfer.addr = 0x80;
  500. i2c_block_transfer.data[0] = 0x05;
  501. ret = i2c_master_send(client,
  502. (unsigned char *) &i2c_block_transfer, 2);
  503. if (ret < 0) {
  504. pr_err("%s: err1 %d\n", __func__, ret);
  505. ret = i2c_master_send(client,
  506. (unsigned char *) &i2c_block_transfer, 2);
  507. if (ret < 0)
  508. pr_err("%s: err2 %d\n", __func__, ret);
  509. }
  510. /* setup BSR data */
  511. for (i = 0; i < 6; i++)
  512. i2c_block_transfer.data[i+1] = BSR_data[i];
  513. /* send BSR1 */
  514. /* NS 1= 200, ISD 1 = 100us, IPD 1 = 200us,
  515. BL 1=14, BW 1=4MHZ */
  516. i2c_block_transfer.addr = 0x81;
  517. i2c_block_transfer.data[0] = 0x00;
  518. ret = i2c_master_send(client,
  519. (unsigned char *) &i2c_block_transfer, 8);
  520. if (ret < 0) {
  521. pr_err("%s: err1 %d\n", __func__, ret);
  522. ret = i2c_master_send(client,
  523. (unsigned char *) &i2c_block_transfer, 8);
  524. if (ret < 0)
  525. pr_err("%s: err2 %d\n", __func__, ret);
  526. }
  527. /* send BSR2 */
  528. /* NS 2= 200, ISD 2 = 100us, IPD 2 = 200us,
  529. BL 2=14, BW 2=2MHZ*/
  530. i2c_block_transfer.addr = 0x88;
  531. i2c_block_transfer.data[0] = 0x01;
  532. ret = i2c_master_send(client,
  533. (unsigned char *) &i2c_block_transfer, 8);
  534. if (ret < 0) {
  535. pr_err("%s: err1 %d\n", __func__, ret);
  536. ret = i2c_master_send(client,
  537. (unsigned char *) &i2c_block_transfer, 8);
  538. if (ret < 0)
  539. pr_err("%s: err2 %d\n", __func__, ret);
  540. }
  541. /* send BSR3 */
  542. /* NS 3= 200, ISD 3 = 100us, IPD 3 = 200us,
  543. BL 3=14, BW 3=1MHZ*/
  544. i2c_block_transfer.addr = 0x8F;
  545. i2c_block_transfer.data[0] = 0x02;
  546. ret = i2c_master_send(client,
  547. (unsigned char *) &i2c_block_transfer, 8);
  548. if (ret < 0) {
  549. pr_err("%s: err1 %d\n", __func__, ret);
  550. ret = i2c_master_send(client,
  551. (unsigned char *) &i2c_block_transfer, 8);
  552. if (ret < 0)
  553. pr_err("%s: err2 %d\n", __func__, ret);
  554. }
  555. /* send BSR4 */
  556. /* NS 4= 200, ISD 4 = 100us, IPD 4 = 200us,
  557. BL 4=14, BW 4=500KHZ*/
  558. i2c_block_transfer.addr = 0x96;
  559. i2c_block_transfer.data[0] = 0x04;
  560. ret = i2c_master_send(client,
  561. (unsigned char *) &i2c_block_transfer, 8);
  562. if (ret < 0) {
  563. pr_err("%s: err1 %d\n", __func__, ret);
  564. ret = i2c_master_send(client,
  565. (unsigned char *) &i2c_block_transfer, 8);
  566. if (ret < 0)
  567. pr_err("%s: err2 %d\n", __func__, ret);
  568. }
  569. /* send BSR5 */
  570. /* NS 5= 200, ISD 5 = 100us, IPD 5 = 200us,
  571. BL 5=14, BW 5=250KHZ*/
  572. i2c_block_transfer.addr = 0x9D;
  573. i2c_block_transfer.data[0] = 0x08;
  574. ret = i2c_master_send(client,
  575. (unsigned char *) &i2c_block_transfer, 8);
  576. if (ret < 0) {
  577. pr_err("%s: err1 %d\n", __func__, ret);
  578. ret = i2c_master_send(client,
  579. (unsigned char *) &i2c_block_transfer, 8);
  580. if (ret < 0)
  581. pr_err("%s: err2 %d\n", __func__, ret);
  582. }
  583. /* send barcode data */
  584. i2c_block_transfer.addr = 0x00;
  585. for (i = 0; i < 14; i++)
  586. i2c_block_transfer.data[i] = barcode_data[i];
  587. ret = i2c_master_send(client,
  588. (unsigned char *) &i2c_block_transfer, 15);
  589. if (ret < 0) {
  590. pr_err("%s: err1 %d\n", __func__, ret);
  591. ret = i2c_master_send(client,
  592. (unsigned char *) &i2c_block_transfer, 15);
  593. if (ret < 0)
  594. pr_err("%s: err2 %d\n", __func__, ret);
  595. }
  596. /* send START */
  597. i2c_block_transfer.addr = 0xFF;
  598. i2c_block_transfer.data[0] = 0x0E;
  599. ret = i2c_master_send(client,
  600. (unsigned char *) &i2c_block_transfer, 2);
  601. if (ret < 0) {
  602. pr_err("%s: err1 %d\n", __func__, ret);
  603. ret = i2c_master_send(client,
  604. (unsigned char *) &i2c_block_transfer, 2);
  605. if (ret < 0)
  606. pr_err("%s: err2 %d\n", __func__, ret);
  607. }
  608. } else if (buf[0] == TEST_CODE2) {
  609. pr_barcode("barcode test code stop\n");
  610. i2c_block_transfer.addr = 0xFF;
  611. i2c_block_transfer.data[0] = 0x00;
  612. ret = i2c_master_send(client,
  613. (unsigned char *) &i2c_block_transfer, 2);
  614. if (ret < 0) {
  615. pr_err("%s: err1 %d\n", __func__, ret);
  616. ret = i2c_master_send(client,
  617. (unsigned char *) &i2c_block_transfer, 2);
  618. if (ret < 0)
  619. pr_err("%s: err2 %d\n", __func__, ret);
  620. }
  621. fpga_enable(0);
  622. }
  623. return size;
  624. }
  625. static ssize_t barcode_emul_test_show(struct device *dev,
  626. struct device_attribute *attr,
  627. char *buf)
  628. {
  629. return strlen(buf);
  630. }
  631. static DEVICE_ATTR(barcode_test_send, 0664,
  632. barcode_emul_test_show, barcode_emul_test_store);
  633. static ssize_t barcode_ver_check_show(struct device *dev,
  634. struct device_attribute *attr,
  635. char *buf)
  636. {
  637. struct barcode_emul_data *data = dev_get_drvdata(dev);
  638. u8 fw_ver;
  639. barcode_emul_read(data->client, FW_VER_ADDR, 1, &fw_ver);
  640. fw_ver = (fw_ver >> 5) & 0x7;
  641. return snprintf(buf, IRDA_BUFFER_MAX_SIZE, "%d\n", fw_ver+14);
  642. }
  643. static DEVICE_ATTR(barcode_ver_check, 0664, barcode_ver_check_show, NULL);
  644. static ssize_t barcode_led_status_show(struct device *dev,
  645. struct device_attribute *attr,
  646. char *buf)
  647. {
  648. struct barcode_emul_data *data = dev_get_drvdata(dev);
  649. u8 status;
  650. barcode_emul_read(data->client, BEAM_STATUS_ADDR, 1, &status);
  651. status = status & 0x1;
  652. return snprintf(buf, IRDA_BUFFER_MAX_SIZE, "%d\n", status);
  653. }
  654. static DEVICE_ATTR(barcode_led_status, 0664, barcode_led_status_show, NULL);
  655. #if defined(CONFIG_IR_REMOCON_FPGA)
  656. static void irda_add_checksum_length(struct barcode_emul_data *ir_data,
  657. int count)
  658. {
  659. struct barcode_emul_data *data = ir_data;
  660. int i = 0, csum = 0;
  661. pr_barcode("%s: length: %04x\n", __func__, count);
  662. data->i2c_block_transfer.data[0] = count >> 8;
  663. data->i2c_block_transfer.data[1] = count & 0xff;
  664. while (i < count) {
  665. csum += data->i2c_block_transfer.data[i];
  666. i++;
  667. }
  668. pr_barcode("%s: checksum: %04x\n", __func__, csum);
  669. data->i2c_block_transfer.data[count] = csum >> 8;
  670. data->i2c_block_transfer.data[count+1] = csum & 0xff;
  671. }
  672. /* sysfs node ir_send */
  673. static void ir_remocon_work(struct barcode_emul_data *ir_data, int count)
  674. {
  675. struct barcode_emul_data *data = ir_data;
  676. struct i2c_client *client = data->client;
  677. int buf_size = count+2;
  678. int ret;
  679. int emission_time;
  680. int ack_pin_onoff;
  681. if (count_number >= 100)
  682. count_number = 0;
  683. count_number++;
  684. pr_barcode("%s: total buf_size: %d\n", __func__, buf_size);
  685. fpga_enable(1);
  686. mutex_lock(&data->mutex);
  687. client->addr = IRDA_I2C_ADDR;
  688. if (g_pdata->fw_type) {
  689. data->i2c_block_transfer.addr = 0x00;
  690. data->i2c_block_transfer.data[0] = count >> 8;
  691. data->i2c_block_transfer.data[1] = count & 0xff;
  692. buf_size++;
  693. ret = i2c_master_send(client,
  694. (unsigned char *) &(data->i2c_block_transfer),
  695. buf_size);
  696. if (ret < 0) {
  697. dev_err(&client->dev, "%s: err1 %d\n", __func__, ret);
  698. ret = i2c_master_send(client,
  699. (unsigned char *) &(data->i2c_block_transfer),
  700. buf_size);
  701. if (ret < 0)
  702. dev_err(&client->dev, "%s: err2 %d\n",
  703. __func__, ret);
  704. }
  705. } else {
  706. irda_add_checksum_length(data, count);
  707. ret = i2c_master_send(client, data->i2c_block_transfer.data,
  708. buf_size);
  709. if (ret < 0) {
  710. dev_err(&client->dev, "%s: err1 %d\n", __func__, ret);
  711. ret = i2c_master_send(client,
  712. data->i2c_block_transfer.data, buf_size);
  713. if (ret < 0)
  714. dev_err(&client->dev, "%s: err2 %d\n",
  715. __func__, ret);
  716. }
  717. }
  718. usleep_range(10000, 12000);
  719. ack_pin_onoff = 0;
  720. /* Unavailable in Lattice */
  721. if (gpio_get_value(g_pdata->irda_irq)) {
  722. pr_barcode("%s : %d Checksum NG!\n",
  723. __func__, count_number);
  724. ack_pin_onoff = 1;
  725. } else {
  726. pr_barcode("%s : %d Checksum OK!\n",
  727. __func__, count_number);
  728. ack_pin_onoff = 2;
  729. }
  730. ack_number = ack_pin_onoff;
  731. mutex_unlock(&data->mutex);
  732. /*
  733. for (int i = 0; i < buf_size; i++) {
  734. printk(KERN_INFO "%s: data[%d] : 0x%02x\n", __func__, i,
  735. data->i2c_block_transfer.data[i]);
  736. }
  737. */
  738. data->count = 2;
  739. emission_time = \
  740. (1000 * (data->ir_sum) / (data->ir_freq)) + 50;
  741. if (emission_time > 0)
  742. msleep(emission_time);
  743. pr_barcode("%s: emission_time = %d\n",
  744. __func__, emission_time);
  745. if (gpio_get_value(g_pdata->irda_irq)) {
  746. pr_barcode("%s : %d Sending IR OK!\n",
  747. __func__, count_number);
  748. ack_pin_onoff = 4;
  749. } else {
  750. pr_barcode("%s : %d Sending IR NG!\n",
  751. __func__, count_number);
  752. ack_pin_onoff = 2;
  753. }
  754. ack_number += ack_pin_onoff;
  755. #ifndef USE_STOP_MODE
  756. data->on_off = 0;
  757. irda_wake_en(0);
  758. #endif
  759. data->ir_freq = 0;
  760. data->ir_sum = 0;
  761. fpga_enable(0);
  762. }
  763. static ssize_t remocon_store(struct device *dev, struct device_attribute *attr,
  764. const char *buf, size_t size)
  765. {
  766. struct barcode_emul_data *data = dev_get_drvdata(dev);
  767. unsigned int _data, _tdata;
  768. int count, i, converting_factor = 1;
  769. pr_barcode("ir_send called\n");
  770. for (i = 0; i < MAX_SIZE; i++) {
  771. if (sscanf(buf++, "%u", &_data) == 1) {
  772. if (_data == 0 || buf == '\0')
  773. break;
  774. if (data->count == 2) {
  775. data->ir_freq = _data;
  776. converting_factor = US_TO_PATTERN / data->ir_freq;
  777. if (data->on_off) {
  778. irda_wake_en(0);
  779. usleep_range(200, 300);
  780. irda_wake_en(1);
  781. msleep(30);
  782. } else {
  783. irda_wake_en(1);
  784. msleep(60);
  785. data->on_off = 1;
  786. }
  787. data->i2c_block_transfer.data[2]
  788. = _data >> 16;
  789. data->i2c_block_transfer.data[3]
  790. = (_data >> 8) & 0xFF;
  791. data->i2c_block_transfer.data[4]
  792. = _data & 0xFF;
  793. data->count += 3;
  794. } else {
  795. _tdata = _data / converting_factor;
  796. data->ir_sum += _tdata;
  797. count = data->count;
  798. data->i2c_block_transfer.data[count]
  799. = _tdata >> 8;
  800. data->i2c_block_transfer.data[count+1]
  801. = _tdata & 0xFF;
  802. data->count += 2;
  803. }
  804. while (_data > 0) {
  805. buf++;
  806. _data /= 10;
  807. }
  808. } else {
  809. break;
  810. }
  811. }
  812. ir_remocon_work(data, data->count);
  813. return size;
  814. }
  815. static ssize_t remocon_show(struct device *dev, struct device_attribute *attr,
  816. char *buf)
  817. {
  818. struct barcode_emul_data *data = dev_get_drvdata(dev);
  819. int i;
  820. char *bufp = buf;
  821. for (i = 5; i < MAX_SIZE - 1; i++) {
  822. if (data->i2c_block_transfer.data[i] == 0
  823. && data->i2c_block_transfer.data[i+1] == 0)
  824. break;
  825. else
  826. bufp += sprintf(bufp, "%u,",
  827. data->i2c_block_transfer.data[i]);
  828. }
  829. return strlen(buf);
  830. }
  831. /* sysfs node ir_send_result */
  832. static ssize_t remocon_ack(struct device *dev, struct device_attribute *attr,
  833. char *buf)
  834. {
  835. pr_barcode("%s : ack_number = %d\n", __func__, ack_number);
  836. if (ack_number == 6)
  837. return sprintf(buf, "1\n");
  838. else
  839. return sprintf(buf, "0\n");
  840. }
  841. static int irda_read_device_info(struct barcode_emul_data *ir_data)
  842. {
  843. struct barcode_emul_data *data = ir_data;
  844. struct i2c_client *client = data->client;
  845. u8 buf_ir_test[8];
  846. int ret;
  847. pr_barcode("%s called\n", __func__);
  848. irda_wake_en(1);
  849. msleep(60);
  850. fpga_enable(1);
  851. client->addr = IRDA_I2C_ADDR;
  852. ret = i2c_master_recv(client, buf_ir_test, READ_LENGTH);
  853. if (ret < 0)
  854. dev_err(&client->dev, "%s: err %d\n", __func__, ret);
  855. pr_barcode("%s: buf_ir dev_id: 0x%02x, 0x%02x\n", __func__,
  856. buf_ir_test[2], buf_ir_test[3]);
  857. ret = data->dev_id = (buf_ir_test[2] << 8 | buf_ir_test[3]);
  858. irda_wake_en(0);
  859. data->on_off = 0;
  860. fpga_enable(0);
  861. return ret;
  862. }
  863. /* sysfs node check_ir */
  864. static ssize_t check_ir_show(struct device *dev, struct device_attribute *attr,
  865. char *buf)
  866. {
  867. struct barcode_emul_data *data = dev_get_drvdata(dev);
  868. int ret;
  869. ret = irda_read_device_info(data);
  870. return snprintf(buf, 4, "%d\n", ret);
  871. }
  872. /* sysfs node irda_test */
  873. static ssize_t irda_test_store(struct device *dev,
  874. struct device_attribute *attr, const char *buf, size_t size)
  875. {
  876. int ret, i;
  877. struct barcode_emul_data *data = dev_get_drvdata(dev);
  878. struct i2c_client *client = data->client;
  879. struct {
  880. unsigned char addr;
  881. unsigned char data[IRDA_TEST_CODE_SIZE];
  882. } i2c_block_transfer;
  883. unsigned char BSR_data[IRDA_TEST_CODE_SIZE] = {
  884. 0x8D, 0x00, 0x96, 0x00, 0x01, 0x50, 0x00, 0xA8,
  885. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x15,
  886. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x15,
  887. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x15,
  888. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x15,
  889. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x3F,
  890. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x3F,
  891. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x3F,
  892. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x3F,
  893. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x3F,
  894. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x15,
  895. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x15,
  896. 0x00, 0x15, 0x00, 0x15, 0x00, 0x15, 0x00, 0x15,
  897. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x15,
  898. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x3F,
  899. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x3F,
  900. 0x00, 0x15, 0x00, 0x3F, 0x00, 0x15, 0x00, 0x3F,
  901. 0x00, 0x15, 0x00, 0x3F
  902. };
  903. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  904. check_cdone_state();
  905. if (gpio_get_value(g_pdata->cdone) != 1) {
  906. pr_err("%s: cdone fail !!\n", __func__);
  907. return 1;
  908. }
  909. #endif
  910. pr_barcode("IRDA test code start\n");
  911. /* change address for IRDA */
  912. client->addr = IRDA_I2C_ADDR;
  913. /* make data for sending */
  914. for (i = 0; i < IRDA_TEST_CODE_SIZE; i++)
  915. i2c_block_transfer.data[i] = BSR_data[i];
  916. fpga_enable(1);
  917. /* sending data by I2C */
  918. i2c_block_transfer.addr = IRDA_TEST_CODE_ADDR;
  919. ret = i2c_master_send(client, (unsigned char *) &i2c_block_transfer,
  920. IRDA_TEST_CODE_SIZE);
  921. if (ret < 0) {
  922. pr_err("%s: err1 %d\n", __func__, ret);
  923. ret = i2c_master_send(client,
  924. (unsigned char *) &i2c_block_transfer, IRDA_TEST_CODE_SIZE);
  925. if (ret < 0)
  926. pr_err("%s: err2 %d\n", __func__, ret);
  927. }
  928. fpga_enable(0);
  929. return size;
  930. }
  931. static ssize_t irda_test_show(struct device *dev, struct device_attribute *attr,
  932. char *buf)
  933. {
  934. return strlen(buf);
  935. }
  936. static struct device_attribute ir_attrs[] = {
  937. __ATTR(check_ir, S_IRUGO|S_IWUSR|S_IWGRP, check_ir_show, NULL),
  938. __ATTR(ir_send, S_IRUGO|S_IWUSR|S_IWGRP, remocon_show, remocon_store),
  939. __ATTR(ir_send_result, S_IRUGO|S_IWUSR|S_IWGRP, remocon_ack, NULL),
  940. __ATTR(irda_test, S_IRUGO|S_IWUSR|S_IWGRP, irda_test_show, irda_test_store)
  941. };
  942. #endif
  943. static int ice_gpio_get(struct gpio_chip *chip, unsigned offset)
  944. {
  945. return ice_gpiox_get((unsigned)offset);
  946. }
  947. static void ice_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  948. {
  949. ice_gpiox_set((unsigned)offset, value);
  950. }
  951. static struct gpio_chip ice_gpio = {
  952. .label = "ice-fpga-gpio",
  953. .get = ice_gpio_get,
  954. .set = ice_gpio_set,
  955. .base = FPGA_GPIO_BASE,
  956. .ngpio = NR_FPGA_GPIO,
  957. };
  958. int ice_gpiox_get(int num)
  959. {
  960. int ret;
  961. int cmd;
  962. if (!fw_dl_complete)
  963. return -EBUSY;
  964. g_client->addr = BARCODE_I2C_ADDR;
  965. if (g_pdata->fw_type == ICE_24M)
  966. cmd = 0xFC | (num >> 3);
  967. else
  968. cmd = num >> 3;
  969. fpga_enable(1);
  970. ret = i2c_smbus_read_byte_data(g_client, cmd);
  971. if (ret) {
  972. fpga_enable(0);
  973. fpga_enable(1);
  974. ret = i2c_smbus_read_byte_data(g_client, cmd);
  975. }
  976. fpga_enable(0);
  977. if (ret < 0) {
  978. pr_err("%s i2c error : %d\n", __func__, ret);
  979. return ret;
  980. } else if (ret & (1 << (num&7))) {
  981. pr_barcode("%s : num = %d , val = 1\n", __func__, num);
  982. return 1;
  983. } else {
  984. pr_barcode("%s : num = %d , val = 0\n", __func__, num);
  985. return 0;
  986. }
  987. }
  988. EXPORT_SYMBOL(ice_gpiox_get);
  989. int ice_gpiox_set(int num, int val)
  990. {
  991. int ret;
  992. int cmd;
  993. if (!fw_dl_complete)
  994. return -EBUSY;
  995. g_client->addr = BARCODE_I2C_ADDR;
  996. if (g_pdata->fw_type == ICE_24M)
  997. cmd = 0xFC | (num >> 3);
  998. else
  999. cmd = num >> 3;
  1000. if (val)
  1001. gpiox_state |= 1 << num;
  1002. else
  1003. gpiox_state &= ~(1 << num);
  1004. pr_barcode("%s : num = %d , val = %d\n", __func__, num, val);
  1005. fpga_enable(1);
  1006. ret = i2c_smbus_write_byte_data(g_client, cmd,
  1007. (num >> 3) ? (gpiox_state >> 8) : gpiox_state);
  1008. if (ret) {
  1009. fpga_enable(0);
  1010. fpga_enable(1);
  1011. ret = i2c_smbus_write_byte_data(g_client, cmd,
  1012. (num >> 3) ? (gpiox_state >> 8) : gpiox_state);
  1013. }
  1014. fpga_enable(0);
  1015. if (ret)
  1016. pr_err("%s i2c error : %d\n", __func__, ret);
  1017. return ret;
  1018. }
  1019. EXPORT_SYMBOL(ice_gpiox_set);
  1020. static void fw_work(struct work_struct *work)
  1021. {
  1022. ice4_fpga_firmware_update();
  1023. #if !defined(CONFIG_SEC_MELIUSCA_PROJECT)
  1024. check_cdone_state();
  1025. if (gpio_get_value(g_pdata->cdone) != 1) {
  1026. pr_err("%s: cdone fail !!\n", __func__);
  1027. return;
  1028. }
  1029. #endif
  1030. Is_clk_enabled = 0;
  1031. }
  1032. static int __devinit barcode_emul_probe(struct i2c_client *client,
  1033. const struct i2c_device_id *id)
  1034. {
  1035. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  1036. struct barcode_emul_data *data;
  1037. struct barcode_emul_platform_data *pdata;
  1038. struct device *barcode_emul_dev;
  1039. int error;
  1040. #ifdef CONFIG_IR_REMOCON_FPGA
  1041. int i;
  1042. #endif
  1043. enable_counte =0;
  1044. pr_barcode("%s probe!\n", __func__);
  1045. if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
  1046. return -EIO;
  1047. if (client->dev.of_node) {
  1048. pdata = devm_kzalloc(&client->dev,
  1049. sizeof(struct barcode_emul_platform_data),
  1050. GFP_KERNEL);
  1051. if (!pdata) {
  1052. dev_err(&client->dev, "Failed to allocate memory\n");
  1053. return -ENOMEM;
  1054. }
  1055. error = barcode_parse_dt(&client->dev, pdata);
  1056. if (error)
  1057. return error;
  1058. } else
  1059. pdata = client->dev.platform_data;
  1060. pdata->fw_type = ICE_24M;
  1061. g_pdata = pdata;
  1062. pr_barcode("%s setting gpio config.\n", __func__);
  1063. barcode_gpio_config();
  1064. #if defined(CONFIG_SEC_MELIUSCA_PROJECT)
  1065. bc_poweron(client->dev);
  1066. #endif
  1067. client->irq = gpio_to_irq(pdata->irda_irq);
  1068. data = kzalloc(sizeof(struct barcode_emul_data), GFP_KERNEL);
  1069. if (NULL == data) {
  1070. pr_err("Failed to data allocate %s\n", __func__);
  1071. error = -ENOMEM;
  1072. goto err_free_mem;
  1073. }
  1074. data->client = client;
  1075. mutex_init(&en_mutex);
  1076. #ifdef CONFIG_IR_REMOCON_FPGA
  1077. data->pdata = client->dev.platform_data;
  1078. mutex_init(&data->mutex);
  1079. data->count = 2;
  1080. data->on_off = 0;
  1081. #endif
  1082. i2c_set_clientdata(client, data);
  1083. barcode_emul_dev = device_create(sec_class, NULL, 0,
  1084. data, "sec_barcode_emul");
  1085. if (IS_ERR(barcode_emul_dev))
  1086. pr_err("Failed to create barcode_emul_dev device\n");
  1087. if (device_create_file(barcode_emul_dev, &dev_attr_barcode_send) < 0)
  1088. pr_err("Failed to create device file(%s)!\n",
  1089. dev_attr_barcode_send.attr.name);
  1090. if (device_create_file(barcode_emul_dev,
  1091. &dev_attr_barcode_test_send) < 0)
  1092. pr_err("Failed to create device file(%s)!\n",
  1093. dev_attr_barcode_test_send.attr.name);
  1094. if (device_create_file(barcode_emul_dev,
  1095. &dev_attr_barcode_fw_update) < 0)
  1096. pr_err("Failed to create device file(%s)!\n",
  1097. dev_attr_barcode_fw_update.attr.name);
  1098. if (device_create_file(barcode_emul_dev,
  1099. &dev_attr_barcode_ver_check) < 0)
  1100. pr_err("Failed to create device file(%s)!\n",
  1101. dev_attr_barcode_ver_check.attr.name);
  1102. if (device_create_file(barcode_emul_dev,
  1103. &dev_attr_barcode_led_status) < 0)
  1104. pr_err("Failed to create device file(%s)!\n",
  1105. dev_attr_barcode_led_status.attr.name);
  1106. #if defined(CONFIG_IR_REMOCON_FPGA)
  1107. barcode_emul_dev = device_create(sec_class, NULL, 0, data, "sec_ir");
  1108. if (IS_ERR(barcode_emul_dev))
  1109. pr_err("Failed to create barcode_emul_dev device in sec_ir\n");
  1110. /* sysfs entries */
  1111. for (i = 0; i < ARRAY_SIZE(ir_attrs); i++) {
  1112. if (device_create_file(barcode_emul_dev, &ir_attrs[i]) < 0)
  1113. pr_err("Failed to create device file(%s)!\n", ir_attrs[i].attr.name);
  1114. }
  1115. #endif
  1116. /*Create dedicated thread so that
  1117. the delay of our work does not affect others*/
  1118. data->firmware_dl =
  1119. create_singlethread_workqueue("barcode_firmware_dl");
  1120. INIT_DELAYED_WORK(&data->fw_dl, fw_work);
  1121. /* min 1ms is needed */
  1122. queue_delayed_work(data->firmware_dl,
  1123. &data->fw_dl, msecs_to_jiffies(20));
  1124. g_client = client;
  1125. Is_beaming = BEAMING_OFF;
  1126. pr_err("probe complete %s\n", __func__);
  1127. return 0;
  1128. err_free_mem:
  1129. kfree(data);
  1130. return error;
  1131. }
  1132. static int __devexit barcode_emul_remove(struct i2c_client *client)
  1133. {
  1134. struct barcode_emul_data *data = i2c_get_clientdata(client);
  1135. i2c_set_clientdata(client, NULL);
  1136. kfree(data);
  1137. return 0;
  1138. }
  1139. static const struct i2c_device_id barcode_id[] = {
  1140. {"barcode", 0},
  1141. {}
  1142. };
  1143. MODULE_DEVICE_TABLE(i2c, barcode_id);
  1144. #ifdef CONFIG_OF
  1145. static struct of_device_id barcode_match_table[] = {
  1146. { .compatible = "barcode,barcode_emul",},
  1147. { },
  1148. };
  1149. #else
  1150. #define barcode_match_table NULL
  1151. #endif
  1152. static struct i2c_driver ice4_i2c_driver = {
  1153. .driver = {
  1154. .name = "barcode",
  1155. .owner = THIS_MODULE,
  1156. .of_match_table = barcode_match_table,
  1157. },
  1158. .probe = barcode_emul_probe,
  1159. .remove = __devexit_p(barcode_emul_remove),
  1160. .id_table = barcode_id,
  1161. };
  1162. static int __init barcode_emul_init(void)
  1163. {
  1164. int ret;
  1165. ret = gpiochip_add(&ice_gpio);
  1166. if (ret) {
  1167. pr_err("gpiochip_add failed ret = %d\n", ret);
  1168. return ret;
  1169. }
  1170. return i2c_add_driver(&ice4_i2c_driver);
  1171. }
  1172. late_initcall(barcode_emul_init);
  1173. static void __exit barcode_emul_exit(void)
  1174. {
  1175. i2c_del_driver(&ice4_i2c_driver);
  1176. }
  1177. module_exit(barcode_emul_exit);
  1178. MODULE_LICENSE("GPL");
  1179. MODULE_DESCRIPTION("SEC Barcode emulator");