barcode_emul_ice4_hlte.c 36 KB

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