ark_tool_serial.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. /*
  2. * Arkmicro mcu serial driver
  3. *
  4. * Licensed under GPLv2 or later.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/ioport.h>
  8. #include <linux/init.h>
  9. #include <linux/console.h>
  10. #include <linux/sysrq.h>
  11. #include <linux/device.h>
  12. #include <linux/tty.h>
  13. #include <linux/tty_flip.h>
  14. #include <linux/serial_core.h>
  15. #include <linux/serial.h>
  16. #include <linux/amba/bus.h>
  17. #include <linux/amba/serial.h>
  18. #include <linux/clk.h>
  19. #include <linux/slab.h>
  20. #include <linux/dmaengine.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/delay.h>
  24. #include <linux/types.h>
  25. #include <linux/of.h>
  26. #include <linux/of_device.h>
  27. #include <linux/pinctrl/consumer.h>
  28. #include <linux/sizes.h>
  29. #include <linux/io.h>
  30. #include <linux/acpi.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/device.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/workqueue.h>
  36. #define LCD_BASE 0xE0500000
  37. #define LCD_CONTROL 0x004
  38. #define LCD_TIMING0 0x008
  39. #define LCD_TIMING1 0x00c
  40. #define LCD_TIMING2 0x010
  41. #define LCD_TIMING3 0x014
  42. #define LCD_VIDEO2_VP_REG_1 0x134
  43. #define LCD_OSD1_VP_REG_1 0x144
  44. #define LCD_OSD2_VP_REG_1 0x14c
  45. #define LCD_OSD3_VP_REG_1 0x154
  46. #define LCD_VIDEO_VP_REG_1 0x1d8
  47. #define LCD_GAMMA_REG_0 0x1ec
  48. #define TV_CONTROL 0x2b0
  49. #define TV_TIMING0 0x2b4
  50. #define TV_TIMING1 0x2b8
  51. #define TV_TIMING2 0x2bc
  52. #define TV_TIMING3 0x2c0
  53. #define LCD_TIMING_FRAME_START_CNT_TV 0x2c4
  54. #define LCD_YPBPR_CTRL0 0x304
  55. #define LCD_VIDEO_CTL 0x3c
  56. #define LCD_OSD1_CTL 0x74
  57. #define LCD_OSD2_CTL 0x88
  58. #define LCD_OSD3_CTL 0x98
  59. #define LCD_TV_PARAM_REG0 0x800
  60. #define LCD_TV_PARAM_REG1 0x804
  61. #define LCD_TV_PARAM_REG2 0x808
  62. #define LCD_TV_PARAM_REG3 0x80C
  63. #define LCD_TV_PARAM_REG4 0x810
  64. #define LCD_TV_PARAM_REG5 0x814
  65. #define LCD_TV_PARAM_REG6 0x818
  66. #define LCD_TV_PARAM_REG7 0x81c
  67. #define LCD_TV_PARAM_REG8 0x820
  68. #define LCD_TV_PARAM_REG9 0x824
  69. #define LCD_TV_PARAM_REG10 0x828
  70. #define LCD_TV_PARAM_REG11 0x82c
  71. #define LCD_TV_PARAM_REG12 0x830
  72. #define LCD_TV_PARAM_REG13 0x834
  73. #define LCD_TV_PARAM_REG14 0x838
  74. #define LCD_TV_PARAM_REG15 0x83c
  75. #define LCD_TV_PARAM_REG16 0x840
  76. #define LCD_TV_PARAM_REG17 0x844
  77. #define LCD_TV_PARAM_REG18 0x848
  78. #define LCD_TV_PARAM_REG19 0x84c
  79. #define LCD_TV_PARAM_REG20 0x850
  80. #define LCD_TV_PARAM_REG21 0x854
  81. #define ITU656_BYP_MODE_CONTROL 0x3d0
  82. #define ITU656_BYP_MODE_NTSC_REG0 0x3d4
  83. #define ITU656_BYP_MODE_NTSC_REG1 0x3d8
  84. #define ITU656_BYP_MODE_NTSC_REG2 0x3dc
  85. #define ITU656_BYP_MODE_NTSC_REG3 0x3e0
  86. #define ITU656_BYP_MODE_NTSC_REG4 0x3e4
  87. #define ITU656_BYP_MODE_PAL_REG0 0x3e8
  88. #define ITU656_BYP_MODE_PAL_REG1 0x3ec
  89. #define ITU656_BYP_MODE_PAL_REG2 0x3f0
  90. #define ITU656_BYP_MODE_PAL_REG3 0x3f4
  91. #define ITU656_BYP_MODE_PAL_REG4 0x3f8
  92. #define ITU656_BYP_MODE_REG0 0x3fc
  93. #define SYS_BASE 0xE4900000
  94. #define SYS_LCD_CLOCK_CFG 0x054
  95. #define SYS_DEVICE_CLK_CFG2 0x068
  96. #define SYS_CLK_DLY_CFG 0x070
  97. #define SYS_ANALOG_REG1 0x144
  98. #define SYS_PLL_RFCK_CTL 0x14c
  99. #define SYS_CPUPLL_CFG 0x150
  100. #define SYS_SYSPLL_CFG 0x154
  101. #define SYS_LVDS_CTRL_CFG 0x190
  102. #define SYS_DDS_CLK_CFG 0x198
  103. #define DMA_BASE 0xE0000000
  104. #define GPU_BASE 0xE0F00000
  105. #define I2S_BASE 0xE4000000
  106. #define UART4_BASE 0xE4F00000
  107. #define UART2_BASE 0xE8000000
  108. #define UART3_BASE 0xE8100000
  109. #define I2S2_BASE 0xE8200000
  110. //command id
  111. #define READ_COMMAND_ID_BASE 0x80
  112. #define READ_REGISTER_ACCESS 0x81
  113. #define READ_TIMING_DEBUG 0x82
  114. #define READ_LVDS_SPECIAL 0x83
  115. #define READ_DISPLAY_SHOW 0x84
  116. #define READ_GAMMA_DEBUG 0x85
  117. #define READ_ITU656_DIRECT 0x86
  118. #define READ_CLOCK_DEBUG 0x87
  119. #define READ_SYSPLL_DDS 0x88
  120. #define READ_COMMAND_ID_END 0x9F
  121. #define WRITE_COMMAND_ID_BASE 0xB0
  122. #define WRITE_REGISTER_ACCESS 0xB1
  123. #define WRITE_TIMING_DEBUG 0xB2
  124. #define WRITE_LVDS_SPECIAL 0xB3
  125. #define WRITE_DISPLAY_SHOW 0xB4
  126. #define WRITE_GAMMA_DEBUG 0xB5
  127. #define WRITE_ITU656_DIRECT 0xB6
  128. #define WRITE_CLOCK_DEBUG 0xB7
  129. //#define WRITE_SYSPLL_COMMAND_ID 0xB8
  130. #define WRITE_DISPLAY_INTERFACE 0xCE
  131. #define WRITE_COMMAND_ID_END 0xCF
  132. #define REQUEST_READ_COMMAND_ID_BASE 0xD0
  133. #define REQUEST_READ_REGISTER_ACCESS 0xD1
  134. #define REQUEST_READ_TIMING_DEBUG 0xD2
  135. #define REQUEST_READ_LVDS_SPECIAL 0xD3
  136. #define REQUEST_READ_DISPLAY_SHOW 0xD4
  137. #define REQUEST_READ_GAMMA_DEBUG 0xD5
  138. #define REQUEST_READ_ITU656_DIRECT 0xD6
  139. #define REQUEST_READ_CLOCK_DEBUG 0xD7
  140. #define REQUEST_READ_SYSPLL_DDS 0xD8
  141. #define REQUEST_READ_COMMAND_ID_END 0xEF
  142. #define CUSTOMER_ARK_FLAG 0xAC
  143. //ÏÔʾ²ã
  144. #define DISP_VIDEO1 (0x01)
  145. #define DISP_VIDEO2 (0x02)
  146. #define DISP_OSD1 (0x04)
  147. #define DISP_OSD2 (0x08)
  148. #define DISP_OSD3 (0x10)
  149. #define BUF_SIZE_MAX 255
  150. #define GAMMA_REG_MAX 48
  151. #define PRINT_FLAG 1
  152. #define PAL 0
  153. #define NTSC 1
  154. //ScreenType
  155. #define SCREEN_TYPE_RGB565 (1<<0)
  156. #define SCREEN_TYPE_RGB888 (1<<1)
  157. #define SCREEN_TYPE_LVDS (1<<2)
  158. #define SCREEN_TYPE_VGA (1<<3)
  159. #define SCREEN_TYPE_CVBS (1<<4)
  160. #define SCREEN_TYPE_YPBPR (1<<5)
  161. #define SCREEN_TYPE_ITU656 (1<<6)
  162. #define SCREEN_TYPE_ITU601 (1<<7)
  163. //YPBPR
  164. #define i480hz60 0
  165. #define i576hz50 1
  166. #define p480hz60 2
  167. #define p576hz50 3
  168. #define p720hz60 4
  169. #define p720hz50 5
  170. #define i1080hz60 6
  171. #define i1080hz50 7
  172. #define i1080hz50_1250 8
  173. #define p1080hz60 9
  174. #define p1080hz50 10
  175. //TV encoder setting
  176. #define chroma_freq_palbg 0x2a098acb //pal
  177. #define chroma_freq_palm 0x21e6efa4 //palm
  178. #define chroma_freq_palnc 0x21f69446 //palnc
  179. #define chroma_freq_ntsc 0x21f07c1f //ntsc
  180. #define chroma_phase 0x2a
  181. #define clrbar_sel 0
  182. #define clrbar_mode 0
  183. #define bypass_yclamp 0
  184. #define yc_delay 4
  185. #define cvbs_enable 1
  186. #define chroma_bw_1 0 // bw_1,bw_0 : 00: narrow band; 01: wide band; 10: extra wide; 11: ultra wide.
  187. #define chroma_bw_0 1
  188. #define comp_yuv 0
  189. #define compchgain 0
  190. #define hsync_width 0x3f //0x7e*2
  191. #define burst_width 0x44 //pal 0x3e ntsc 0x44
  192. #define back_porch 0x3b //pal 0x45 ntsc 0x3b
  193. #define cb_burst_amp 0x20
  194. #define cr_burst_amp 0x00 //pal 0x20 ntsc 0x00
  195. #define slave_mode 0x1
  196. #define black_level 0xf2
  197. #define blank_level 0xf0
  198. #define n1 0x17
  199. #define n3 0x21
  200. #define n8 0x1b
  201. #define n9 0x1b
  202. #define n10 0x24
  203. #define num_lines 525 // pal: 625; ntsc: 525.
  204. #define n0 0x3e
  205. #define n13 0x0f
  206. #define n14 0x0f
  207. #define n15 0x60
  208. #define n5 0x05
  209. #define white_level 0x320
  210. #define cb_gain 0x89
  211. #define n20 0x04
  212. #define cr_gain 0x89
  213. #define n16 0x1
  214. #define n7 0x2
  215. #define tint 0
  216. #define n17 0x0a
  217. #define n19 0x05
  218. #define n18 0x00
  219. #define breeze_way 0x16
  220. #define n21 0x3ff
  221. #define front_porch 0x10 //pal 0x0c ntsc 0x10 ??
  222. #define n11 0x7ce
  223. #define n12 0x000
  224. #define activeline 1440
  225. #define firstvideoline 0xe
  226. #define uv_order 0
  227. #define pal_mode 0 //pal 0x1 ntsc 0x0
  228. #define invert_top 0
  229. #define sys625_50 0
  230. #define cphase_rst 3
  231. #define vsync5 1
  232. #define sync_level 0x48
  233. #define n22 0
  234. #define agc_pulse_level 0xa3
  235. #define bp_pulse_level 0xc8
  236. #define n4 0x15
  237. #define n6 0x05
  238. #define n2 0x15
  239. #define vbi_blank_level 0x128
  240. #define soft_rst 0
  241. #define row63 0
  242. #define row64 0x07
  243. #define wss_clock 0x2f7
  244. #define wss_dataf1 0
  245. #define wss_dataf0 0
  246. #define wss_linef1 0
  247. #define wss_linef0 0
  248. #define wss_level 0x3ff
  249. #define venc_en 1
  250. #define uv_first 0
  251. #define uv_flter_en 1
  252. #define notch_en 0
  253. #define notch_wide 0
  254. #define notch_freq 0
  255. #define row78 0
  256. #define row79 0
  257. #define row80 0
  258. //TV encoder setting pal
  259. #define burst_width_pal 0x3e //pal 0x3e ntsc 0x44
  260. #define back_porch_pal 0x45 //pal 0x45 ntsc 0x3b
  261. #define cr_burst_amp_pal 0x20 //pal 0x20 ntsc 0x00
  262. #define num_lines_pal 625 // pal: 625; ntsc: 525.
  263. #define front_porch_pal 0x0c //pal 0x0c ntsc 0x10
  264. #define pal_mode_pal 1 //pal 0x1 ntsc 0x0
  265. #define ARKTOOL_DATA_NONE 0
  266. #define ARKTOOL_DATA_START 1
  267. typedef enum
  268. {
  269. TV_PAL,
  270. TV_NTSC,
  271. }TV_SYSTEM;
  272. typedef enum
  273. {
  274. REG_WRITE_READ = 1,
  275. LCD_TIMING_DEBUG,
  276. LVDS_SPECIAL,
  277. DISPLAY_SHOW,
  278. GAMMA_DEBUG,
  279. ITU656_DIRECT,
  280. } FUNC_TYPE;
  281. typedef enum
  282. {
  283. CLK_24M=0,
  284. SYSPLL =1,
  285. DDS ,
  286. CPUPLL=4 ,
  287. } CLOCK_TYPE;
  288. struct tool_context
  289. {
  290. //register access
  291. unsigned int reg_value;
  292. unsigned int reg_addr;
  293. //lcd timming
  294. unsigned int timing0_val;
  295. unsigned int timing1_val;
  296. unsigned int timing2_val;
  297. //lcd clock debug
  298. unsigned int screen_type;
  299. unsigned int subscreen_type;
  300. unsigned int interlace;
  301. unsigned int lcd_clock_config_val;
  302. unsigned int lcd_clk_dly_cfg_val;
  303. unsigned int lcd_clk_freq_val;
  304. //lcd vp
  305. unsigned int lcd_con_val;
  306. unsigned int vp_val;
  307. //lvds setting
  308. unsigned int lvds_spec_val;
  309. //gamma
  310. unsigned int gamma_reg0_val;
  311. unsigned int gamma_val[GAMMA_REG_MAX];
  312. //itu656 bypress
  313. unsigned int tv_type;
  314. unsigned int itu656byp_conval;
  315. unsigned int itu656byp_npreg0val;
  316. unsigned int itu656byp_npreg1val;
  317. unsigned int itu656byp_npreg2val;
  318. unsigned int itu656byp_npreg3val;
  319. unsigned int itu656byp_npreg4val;
  320. unsigned int itu656byp_reg0val;
  321. };
  322. #define ARK_TOOL_DBG
  323. #ifdef ARK_TOOL_DBG
  324. #define TOOL_DBG(...) printk(KERN_ALERT __VA_ARGS__)
  325. #else
  326. #define TOOL_DBG(...)
  327. #endif
  328. #define RX_BUF_SIZE PAGE_SIZE
  329. #define ARK1668_LINUX_MIRCO
  330. struct tool_serial_info {
  331. void __iomem *mmio;
  332. void __iomem *sysreg;
  333. struct tool_context context;
  334. struct work_struct rx_task;
  335. spinlock_t lock;
  336. bool arktool_enable;
  337. unsigned int recv_flag;
  338. unsigned int recv;
  339. unsigned int recv_len;
  340. unsigned char recv_buf[BUF_SIZE_MAX];
  341. unsigned int request_read_id;
  342. unsigned char read_buf[BUF_SIZE_MAX];
  343. unsigned int write_len;
  344. unsigned char write_buf[BUF_SIZE_MAX];
  345. };
  346. extern int tool_serial_send(const unsigned char *buf, int len);
  347. extern void tool_serial_register_rev_handler(bool (*handler)(char ch), bool (*enable_check)(char ch));
  348. extern void tool_serial_unregister_rev_handler(void);
  349. static struct tool_serial_info *tsinfo;
  350. #define tool_readl(reg) __raw_readl(tsinfo->mmio+(reg))
  351. #define tool_writel(val, reg) __raw_writel(val, tsinfo->mmio+(reg))
  352. #define tool_readl_sys(reg) __raw_readl(tsinfo->sysreg+(reg))
  353. #define tool_writel_sys(val, reg) __raw_writel(val, tsinfo->sysreg+(reg))
  354. static void cvbs_ntsc_init(void)
  355. {
  356. unsigned int val;
  357. val = chroma_freq_ntsc ;//´Ë´¦¶¨Òå NÖÆ PÖÆ
  358. tool_writel(val, LCD_TV_PARAM_REG0);
  359. val = chroma_bw_1<<27 | comp_yuv<<26|compchgain<<24|yc_delay<<17|cvbs_enable<<16|
  360. clrbar_sel<<10|clrbar_mode<<9|bypass_yclamp<<8 | chroma_phase ;
  361. tool_writel(val, LCD_TV_PARAM_REG1);
  362. val = cb_burst_amp<<24 | back_porch<<16 | burst_width<<8 | hsync_width;
  363. tool_writel(val, LCD_TV_PARAM_REG2);
  364. val = black_level<< 16 | slave_mode<<8 | cr_burst_amp ;
  365. tool_writel(val, LCD_TV_PARAM_REG3);
  366. val = n3<<24| n1<<16 | blank_level ;
  367. tool_writel(val, LCD_TV_PARAM_REG4);
  368. val = n10<<24| n9<<16 | n8 ;
  369. tool_writel(val, LCD_TV_PARAM_REG5);
  370. val = num_lines ;
  371. tool_writel(val, LCD_TV_PARAM_REG6);
  372. val = n15<<24 | n14<<16| n13<<8 | n0 ;
  373. tool_writel(val, LCD_TV_PARAM_REG7);
  374. val = cb_gain<<24 | white_level<<8 | n5 ;
  375. tool_writel(val, LCD_TV_PARAM_REG8);
  376. val = n7<<24| n16 <<16 | cr_gain<<8 | n20 ;
  377. tool_writel(val, LCD_TV_PARAM_REG9);
  378. val = n18<<24| n19 <<16 | n17<<8| tint ;
  379. tool_writel(val, LCD_TV_PARAM_REG10);
  380. val = front_porch<<24| n21<<8| breeze_way ;
  381. tool_writel(val, LCD_TV_PARAM_REG11);
  382. val = n12 <<16 | n11 ;
  383. tool_writel(val, LCD_TV_PARAM_REG12);
  384. val = activeline ;
  385. tool_writel(val, LCD_TV_PARAM_REG13);
  386. val = n22<<24 | sync_level <<16 | uv_order<<15|pal_mode<<14|chroma_bw_0<<13|
  387. invert_top<<12|sys625_50<<11|cphase_rst<<9|vsync5<<8 | firstvideoline ;
  388. tool_writel(val, LCD_TV_PARAM_REG14);
  389. val = n6<<24 | n4 <<16 | bp_pulse_level<<8 | agc_pulse_level ;
  390. tool_writel(val, LCD_TV_PARAM_REG15);
  391. val = soft_rst<<24| vbi_blank_level<<8 | n2 ;
  392. tool_writel(val, LCD_TV_PARAM_REG16);
  393. val = row64 <<16| wss_clock ;
  394. tool_writel(val, LCD_TV_PARAM_REG17);
  395. val = wss_dataf1 ;
  396. tool_writel(val, LCD_TV_PARAM_REG18);
  397. val = wss_dataf0 ;
  398. tool_writel(val, LCD_TV_PARAM_REG19);
  399. val = wss_level <<16 | wss_linef0<<8| wss_linef1 ;
  400. tool_writel(val, LCD_TV_PARAM_REG20);
  401. val = row80<<24 | row79<<16 | row78<<8 | venc_en<<7 | uv_first <<6 |
  402. uv_flter_en<<5 |notch_en<<4 | notch_wide<<3 | notch_freq ;
  403. tool_writel(val, LCD_TV_PARAM_REG21);
  404. TOOL_DBG("%s\n", __FUNCTION__);
  405. }
  406. static void cvbs_pal_init(void)
  407. {
  408. unsigned int val;
  409. val = chroma_freq_palbg;
  410. tool_writel(val, LCD_TV_PARAM_REG0);
  411. val = chroma_bw_1<<27 | comp_yuv<<26|compchgain<<24|yc_delay<<17|cvbs_enable<<16|
  412. clrbar_sel<<10|clrbar_mode<<9|bypass_yclamp<<8 | chroma_phase ;
  413. tool_writel(val, LCD_TV_PARAM_REG1);
  414. val = cb_burst_amp<<24 | back_porch_pal<<16 | burst_width_pal<<8 | hsync_width;
  415. tool_writel(val, LCD_TV_PARAM_REG2);
  416. val = black_level<< 16 | slave_mode<<8 | cr_burst_amp_pal;
  417. tool_writel(val, LCD_TV_PARAM_REG3);
  418. val = n3<<24| n1<<16 | blank_level ;
  419. tool_writel(val, LCD_TV_PARAM_REG4);
  420. val = n10<<24 | n9<<16 | n8 ;
  421. tool_writel(val, LCD_TV_PARAM_REG5);
  422. val = num_lines_pal ;
  423. tool_writel(val, LCD_TV_PARAM_REG6);
  424. val = n15<<24 | n14<<16| n13<<8 | n0 ;
  425. tool_writel(val, LCD_TV_PARAM_REG7);
  426. val = cb_gain<<24 | white_level<<8 | n5 ;
  427. tool_writel(val, LCD_TV_PARAM_REG8);
  428. val = n7<<24| n16 <<16 | cr_gain<<8 | n20 ;
  429. tool_writel(val, LCD_TV_PARAM_REG9);
  430. val = n18<<24| n19 <<16 | n17<<8| tint ;
  431. tool_writel(val, LCD_TV_PARAM_REG10);
  432. val = front_porch_pal<<24| n21<<8| breeze_way ;
  433. tool_writel(val, LCD_TV_PARAM_REG11);
  434. val = n12 <<16| n11 ;
  435. tool_writel(val, LCD_TV_PARAM_REG12);
  436. val = activeline ;
  437. tool_writel(val, LCD_TV_PARAM_REG13);
  438. val = n22<<24| sync_level <<16 | uv_order<<15|pal_mode_pal<<14|chroma_bw_0<<13|
  439. invert_top<<12|sys625_50<<11|cphase_rst<<9|vsync5<<8| firstvideoline ;
  440. tool_writel(val, LCD_TV_PARAM_REG14);
  441. val = n6<<24| n4 <<16| bp_pulse_level<<8| agc_pulse_level ;
  442. tool_writel(val, LCD_TV_PARAM_REG15);
  443. val = soft_rst<<24| vbi_blank_level<<8| n2 ;
  444. tool_writel(val, LCD_TV_PARAM_REG16);
  445. val = row64 <<16 | wss_clock ;
  446. tool_writel(val, LCD_TV_PARAM_REG17);
  447. val = wss_dataf1 ;
  448. tool_writel(val, LCD_TV_PARAM_REG18);
  449. val = wss_dataf0 ;
  450. tool_writel(val, LCD_TV_PARAM_REG19);
  451. val = wss_level <<16 | wss_linef0<<8| wss_linef1 ;
  452. tool_writel(val, LCD_TV_PARAM_REG20);
  453. val = row80<<24 | row79<<16 | row78<<8|venc_en<<7| uv_first <<6 |uv_flter_en<<5|
  454. notch_en<<4 |notch_wide<<3 | notch_freq ;
  455. tool_writel(val, LCD_TV_PARAM_REG21);
  456. TOOL_DBG("%s\n", __FUNCTION__);
  457. }
  458. static void ypbpr_config_interlace_mode(unsigned int mode)
  459. {
  460. unsigned int scan_mode, val;
  461. if(mode==i480hz60||mode==i576hz50||mode==i1080hz60||
  462. mode==i1080hz50||mode==i1080hz50_1250){
  463. scan_mode = 1;
  464. }else{
  465. scan_mode = 0;
  466. }
  467. //interlace, encoder_en
  468. val = tool_readl(TV_CONTROL);
  469. if(scan_mode == 1) {
  470. val |= (1<<8);
  471. }else{
  472. val &= ~(1<<8);
  473. }
  474. val |= (1<<0);
  475. tool_writel(val, TV_CONTROL);
  476. //Ypbpr
  477. val = 0;
  478. tool_writel(0, LCD_YPBPR_CTRL0);
  479. if(mode<=3){
  480. val = (1<<7)|(scan_mode<<6)|(mode<<2)|(1<<1)|(1<<0);
  481. }else{
  482. val = (0<<7)|(scan_mode<<6)|(mode<<2)|(1<<1)|(1<<0);
  483. }
  484. tool_writel(val, LCD_YPBPR_CTRL0);
  485. if(scan_mode == 1){
  486. tool_writel(tool_readl(LCD_VIDEO_CTL)| (1<<7), LCD_VIDEO_CTL);
  487. tool_writel(tool_readl(LCD_OSD1_CTL) | (1<<26), LCD_OSD1_CTL);
  488. tool_writel(tool_readl(LCD_OSD2_CTL) | (1<<26), LCD_OSD2_CTL);
  489. tool_writel(tool_readl(LCD_OSD3_CTL) | (1<<26), LCD_OSD3_CTL);
  490. }else{
  491. tool_writel(tool_readl(LCD_VIDEO_CTL)& ~(1<<7), LCD_VIDEO_CTL);
  492. tool_writel(tool_readl(LCD_OSD1_CTL) & ~(1<<26), LCD_OSD1_CTL);
  493. tool_writel(tool_readl(LCD_OSD2_CTL) & ~(1<<26), LCD_OSD2_CTL);
  494. tool_writel(tool_readl(LCD_OSD3_CTL) & ~(1<<26), LCD_OSD3_CTL);
  495. }
  496. TOOL_DBG("%s mode=%d, scan_mode=%d\n", __FUNCTION__, mode, scan_mode);
  497. }
  498. static unsigned int get_cpupll_frequency(void)
  499. {
  500. unsigned int val,ref_clk,no,nf,enable,speed;
  501. speed = 0;
  502. val = tool_readl_sys(SYS_PLL_RFCK_CTL);
  503. ref_clk = 6000000 * ((val & 0x1) + 1);
  504. val = tool_readl_sys(SYS_CPUPLL_CFG);
  505. no = (val >> 12) & 0x03;
  506. if(no == 0)
  507. no = 1;
  508. else if(no == 1)
  509. no = 2;
  510. else if(no == 2)
  511. no = 4;
  512. else
  513. no = 8;
  514. nf = (val & 0xFF)+1;
  515. enable = (val >> 14) & 0x1;
  516. if(enable)
  517. speed = ref_clk * nf /no;
  518. return speed;
  519. }
  520. static unsigned int get_dds_frequency(void)
  521. {
  522. unsigned int val, dto_inc, dds_cofe, dds_clk, div, scaler_factor;
  523. val = tool_readl_sys(SYS_DDS_CLK_CFG);
  524. TOOL_DBG("SYS_DDS_CLK_CFG = 0x%08x \n",val);
  525. dto_inc = val&0x3FFFFF;
  526. val = tool_readl_sys(SYS_ANALOG_REG1);
  527. TOOL_DBG("SYS_ANALOG_REG1 = 0x%08x \n",val);
  528. if(val & 0x4)
  529. scaler_factor = 64;
  530. else
  531. scaler_factor = 32;
  532. div = ((val >> 10) & 0x07);
  533. if(scaler_factor == 64 && div > 6)
  534. return 0;
  535. if(scaler_factor == 32 && div > 5)
  536. return 0;
  537. scaler_factor = scaler_factor >> div;
  538. dds_cofe = 1<<22;
  539. //dds_clk = (unsigned int)(24000000.0f*dto_inc*scaler_factor/(double)dds_cofe);// 24M*dto_inc*4.0f/dds_cofe
  540. dds_clk = (24*dto_inc*scaler_factor/dds_cofe)*1000000;
  541. TOOL_DBG("dds_clk = 24000000*dto_inc*scaler_factor/dds_cofe \n");
  542. TOOL_DBG("dds_clk=%d dto_inc= %d scaler_factor= %d dds_cofe= %d \n",
  543. dds_clk,dto_inc,scaler_factor,dds_cofe);
  544. return dds_clk;
  545. }
  546. static unsigned int get_syspll_frequency(void)
  547. {
  548. unsigned int val, ref_clk, no, nf, enable, speed;
  549. speed = 0;
  550. val = tool_readl_sys(SYS_PLL_RFCK_CTL);
  551. TOOL_DBG("SYS_PLL_RFCK_CTL = 0x%08x \n",val);
  552. ref_clk = 6000000 * (((val>>3) & 0x1) + 1);
  553. val = tool_readl_sys(SYS_SYSPLL_CFG);
  554. TOOL_DBG("SYS_SYSPLL_CFG = 0x%08x \n",val);
  555. no = (val >> 12) & 0x03;
  556. if(no == 0)
  557. no = 1;
  558. else if(no == 1)
  559. no = 2;
  560. else if(no == 2)
  561. no = 4;
  562. else
  563. no = 8;
  564. nf = (val & 0xFF)+1;
  565. enable = (val >> 14) & 0x1;
  566. if(enable)
  567. speed = ref_clk * nf /no;
  568. TOOL_DBG("speed = ref_clk * nf /no \n");
  569. TOOL_DBG("speed=%d ref_clk=%d nf=%d no=%d \n",speed,ref_clk,nf,no);
  570. return speed;
  571. }
  572. static void set_dds_frequency(unsigned int dds_clk)
  573. {
  574. unsigned int dto_inc, dds_cofe, val;
  575. val = tool_readl_sys(SYS_ANALOG_REG1);
  576. val &= ~(0x1<<2);// scaler_factor = 32
  577. val &= ~(0x07<<10);
  578. val |= (1<<18); // enable
  579. tool_writel_sys(val, SYS_ANALOG_REG1);
  580. TOOL_DBG("set SYS_ANALOG_REG1=0x%08x\n",val);
  581. dds_cofe = 1<<22;
  582. dds_clk /= 1000000;//lwang
  583. dto_inc = dds_cofe*dds_clk/(24*32);
  584. TOOL_DBG("dto_inc = dds_cofe*dds_clk/(24*32)\n");
  585. TOOL_DBG("dto_inc=%d dds_cofe=%d dds_clk=%d\n",dto_inc,dds_cofe,dds_clk);
  586. val = tool_readl_sys(SYS_DDS_CLK_CFG);
  587. val &= ~(0x3fffff);
  588. val |= dto_inc;
  589. tool_writel_sys(val, SYS_DDS_CLK_CFG);
  590. TOOL_DBG("set SYS_DDS_CLK_CFG = 0x%08x\n",val);
  591. }
  592. static bool fill_trans_data(unsigned int cmd_id)
  593. {
  594. struct tool_context *ptc = &tsinfo->context;
  595. unsigned char *pw = tsinfo->write_buf;
  596. unsigned char check_sum = 0;
  597. unsigned int data_len = 0;
  598. bool ret = true;
  599. int i,j;
  600. //TOOL_DBG("%s: cmd_id = %0x.\n",__FUNCTION__, cmd_id);
  601. i = 0;
  602. memset(pw,0,BUF_SIZE_MAX);
  603. pw[i++] = CUSTOMER_ARK_FLAG;
  604. switch(cmd_id)
  605. {
  606. case REQUEST_READ_REGISTER_ACCESS:
  607. pw[i++] = 0x09;
  608. pw[i++] = READ_REGISTER_ACCESS;
  609. pw[i++] = (ptc->reg_addr >> 0) & 0xFF;
  610. pw[i++] = (ptc->reg_addr >> 8) & 0xFF;
  611. pw[i++] = (ptc->reg_addr >> 16) & 0xFF;
  612. pw[i++] = (ptc->reg_addr >> 24) & 0xFF;
  613. pw[i++] = (ptc->reg_value >> 0) & 0xFF;
  614. pw[i++] = (ptc->reg_value >> 8) & 0xFF;
  615. pw[i++] = (ptc->reg_value >> 16)& 0xFF;
  616. pw[i++] = (ptc->reg_value >> 24)& 0xFF;
  617. break;
  618. case REQUEST_READ_TIMING_DEBUG:
  619. pw[i++] = 0x0d;
  620. pw[i++] = READ_TIMING_DEBUG;
  621. pw[i++] = (ptc->timing0_val >> 0) & 0xFF;
  622. pw[i++] = (ptc->timing0_val >> 8) & 0xFF;
  623. pw[i++] = (ptc->timing0_val >> 16)& 0xFF;
  624. pw[i++] = (ptc->timing0_val >> 24)& 0xFF;
  625. pw[i++] = (ptc->timing1_val >> 0) & 0xFF;
  626. pw[i++] = (ptc->timing1_val >> 8) & 0xFF;
  627. pw[i++] = (ptc->timing1_val >> 16)& 0xFF;
  628. pw[i++] = (ptc->timing1_val >> 24)& 0xFF;
  629. pw[i++] = (ptc->timing2_val >> 0) & 0xFF;
  630. pw[i++] = (ptc->timing2_val >> 8) & 0xFF;
  631. pw[i++] = (ptc->timing2_val >> 16)& 0xFF;
  632. pw[i++] = (ptc->timing2_val >> 24)& 0xFF;
  633. break;
  634. case REQUEST_READ_LVDS_SPECIAL:
  635. pw[i++] = 0x05;
  636. pw[i++] = READ_LVDS_SPECIAL;
  637. pw[i++] = (ptc->lvds_spec_val >> 0) & 0xFF;
  638. pw[i++] = (ptc->lvds_spec_val >> 8) & 0xFF;
  639. pw[i++] = (ptc->lvds_spec_val >> 16)& 0xFF;
  640. pw[i++] = (ptc->lvds_spec_val >> 24)& 0xFF;
  641. break;
  642. case REQUEST_READ_DISPLAY_SHOW:
  643. pw[i++] = 0x05;
  644. pw[i++] = READ_DISPLAY_SHOW;
  645. pw[i++] = (ptc->vp_val >> 0) & 0xFF;
  646. pw[i++] = (ptc->vp_val >> 8) & 0xFF;
  647. pw[i++] = (ptc->vp_val >> 16)& 0xFF;
  648. pw[i++] = (ptc->vp_val >> 24)& 0xFF;
  649. break;
  650. case REQUEST_READ_GAMMA_DEBUG:
  651. pw[i++] = 48*4 +2;
  652. pw[i++] = READ_GAMMA_DEBUG;
  653. pw[i++] = ptc->gamma_reg0_val & 0x03;
  654. for (j = 0;j < GAMMA_REG_MAX ;j++)
  655. {
  656. pw[i++] = (ptc->gamma_val[j] >> 0) & 0xFF;
  657. pw[i++] = (ptc->gamma_val[j] >> 8) & 0xFF;
  658. pw[i++] = (ptc->gamma_val[j] >> 16)& 0xFF;
  659. pw[i++] = (ptc->gamma_val[j] >> 24)& 0xFF;
  660. }
  661. break;
  662. case REQUEST_READ_ITU656_DIRECT:
  663. pw[i++] = 0x1E;
  664. pw[i++] = READ_ITU656_DIRECT;
  665. pw[i++] = ptc->tv_type & 0xFF;
  666. pw[i++] = (ptc->itu656byp_conval >> 0) & 0xFF;
  667. pw[i++] = (ptc->itu656byp_conval >> 8) & 0xFF;
  668. pw[i++] = (ptc->itu656byp_conval >> 16)& 0xFF;
  669. pw[i++] = (ptc->itu656byp_conval >> 24)& 0xFF;
  670. pw[i++] = (ptc->itu656byp_npreg0val >> 0) & 0xFF;
  671. pw[i++] = (ptc->itu656byp_npreg0val >> 8) & 0xFF;
  672. pw[i++] = (ptc->itu656byp_npreg0val >> 16)& 0xFF;
  673. pw[i++] = (ptc->itu656byp_npreg0val >> 24)& 0xFF;
  674. pw[i++] = (ptc->itu656byp_npreg1val >> 0) & 0xFF;
  675. pw[i++] = (ptc->itu656byp_npreg1val >> 8) & 0xFF;
  676. pw[i++] = (ptc->itu656byp_npreg1val >> 16)& 0xFF;
  677. pw[i++] = (ptc->itu656byp_npreg1val >> 24)& 0xFF;
  678. pw[i++] = (ptc->itu656byp_npreg2val >> 0) & 0xFF;
  679. pw[i++] = (ptc->itu656byp_npreg2val >> 8) & 0xFF;
  680. pw[i++] = (ptc->itu656byp_npreg2val >> 16)& 0xFF;
  681. pw[i++] = (ptc->itu656byp_npreg2val >> 24)& 0xFF;
  682. pw[i++] = (ptc->itu656byp_npreg3val >> 0) & 0xFF;
  683. pw[i++] = (ptc->itu656byp_npreg3val >> 8) & 0xFF;
  684. pw[i++] = (ptc->itu656byp_npreg3val >> 16)& 0xFF;
  685. pw[i++] = (ptc->itu656byp_npreg3val >> 24)& 0xFF;
  686. pw[i++] = (ptc->itu656byp_npreg4val >> 0) & 0xFF;
  687. pw[i++] = (ptc->itu656byp_npreg4val >> 8) & 0xFF;
  688. pw[i++] = (ptc->itu656byp_npreg4val >> 16)& 0xFF;
  689. pw[i++] = (ptc->itu656byp_npreg4val >> 24)& 0xFF;
  690. pw[i++] = (ptc->itu656byp_reg0val >> 0) & 0xFF;
  691. pw[i++] = (ptc->itu656byp_reg0val >> 8) & 0xFF;
  692. pw[i++] = (ptc->itu656byp_reg0val >> 16)& 0xFF;
  693. pw[i++] = (ptc->itu656byp_reg0val >> 24)& 0xFF;
  694. break;
  695. case REQUEST_READ_CLOCK_DEBUG:
  696. pw[i++] = 0x0d;
  697. pw[i++] = READ_CLOCK_DEBUG;
  698. pw[i++] = (ptc->lcd_clock_config_val >> 0) & 0xFF;
  699. pw[i++] = (ptc->lcd_clock_config_val >> 8) & 0xFF;
  700. pw[i++] = (ptc->lcd_clock_config_val >> 16)& 0xFF;
  701. pw[i++] = (ptc->lcd_clock_config_val >> 24)& 0xFF;
  702. pw[i++] = (ptc->lcd_clk_dly_cfg_val >> 0) & 0xFF;
  703. pw[i++] = (ptc->lcd_clk_dly_cfg_val >> 8) & 0xFF;
  704. pw[i++] = (ptc->lcd_clk_dly_cfg_val >> 16) & 0xFF;
  705. pw[i++] = (ptc->lcd_clk_dly_cfg_val >> 24) & 0xFF;
  706. pw[i++] = (ptc->lcd_clk_freq_val >> 0) & 0xFF;
  707. pw[i++] = (ptc->lcd_clk_freq_val >> 8) & 0xFF;
  708. pw[i++] = (ptc->lcd_clk_freq_val >> 16)& 0xFF;
  709. pw[i++] = (ptc->lcd_clk_freq_val >> 24)& 0xFF;
  710. break;
  711. case REQUEST_READ_SYSPLL_DDS:
  712. pw[i++] = 0x05;
  713. pw[i++] = READ_SYSPLL_DDS;
  714. pw[i++] = (ptc->lcd_clk_freq_val >> 0) & 0xFF;
  715. pw[i++] = (ptc->lcd_clk_freq_val >> 8) & 0xFF;
  716. pw[i++] = (ptc->lcd_clk_freq_val >> 16) & 0xFF;
  717. pw[i++] = (ptc->lcd_clk_freq_val >> 24) & 0xFF;
  718. break;
  719. default:
  720. ret = false;
  721. break;
  722. }
  723. if ((REQUEST_READ_COMMAND_ID_BASE <= cmd_id) && (cmd_id <=REQUEST_READ_COMMAND_ID_END)){
  724. data_len = tsinfo->write_buf[1];
  725. tsinfo->write_len = data_len + 3;
  726. for (i = 0;i < data_len + 2;i++ )
  727. check_sum ^= tsinfo->write_buf[i];
  728. tsinfo->write_buf[data_len+2] = check_sum;
  729. tsinfo->request_read_id = cmd_id;
  730. //TOOL_DBG("fill trans data: set request_read_id = %0x\n",tsinfo->request_read_id);
  731. }
  732. return ret;
  733. }
  734. static bool data_check_sum(unsigned char *buf)
  735. {
  736. unsigned int data_len,i;
  737. unsigned char check_sum = 0;
  738. if (buf[0] != CUSTOMER_ARK_FLAG){
  739. TOOL_DBG("%s --> CUSTOMER_ARK_FLAG error.\n", __FUNCTION__);
  740. memset(buf,0,BUF_SIZE_MAX);
  741. return false;
  742. }
  743. data_len = buf[1];
  744. for (i = 0;i < data_len + 2;i++ ){
  745. check_sum ^= buf[i];
  746. //TOOL_DBG("%02x, ",rbuf[i]);
  747. //if((i+1)%10 == 0 || (i >= data_len + 1))
  748. //TOOL_DBG("\r\n");
  749. }
  750. if (buf[data_len+2] != check_sum){
  751. TOOL_DBG("%s --> error, cmd_id=%0x length=%d. \n", __FUNCTION__ ,buf[2],buf[1]);
  752. memset(buf,0,BUF_SIZE_MAX);
  753. return false;
  754. }
  755. TOOL_DBG("\n ------------------------------------------- \n");
  756. return true;
  757. }
  758. static bool tool_data_process(void)
  759. {
  760. unsigned int base_offset, val, i;
  761. unsigned int screen_type, subscreen_type;
  762. struct tool_context *ptc = &tsinfo->context;
  763. unsigned char *rbuf = tsinfo->read_buf;
  764. int lcd_clk_sel, command_id;
  765. bool ret = true;
  766. if(!data_check_sum(rbuf))
  767. return false;
  768. command_id = rbuf[2];
  769. switch(command_id)
  770. {
  771. case WRITE_REGISTER_ACCESS:
  772. {
  773. unsigned int* pvirt_addr = NULL;
  774. ptc->reg_addr = (rbuf[3] << 0) | (rbuf[4] << 8) | (rbuf[5] << 16) | (rbuf[6] << 24);
  775. ptc->reg_value= (rbuf[7] << 0) | (rbuf[8] << 8) | (rbuf[9] << 16) | (rbuf[10] << 24);
  776. if (ptc->reg_addr >= LCD_BASE && ptc->reg_addr < LCD_BASE+0x2000){
  777. base_offset = ptc->reg_addr - LCD_BASE;
  778. tool_writel(ptc->reg_value, base_offset);
  779. }else if(ptc->reg_addr >= SYS_BASE && ptc->reg_addr < SYS_BASE+0x1000){
  780. base_offset = ptc->reg_addr - SYS_BASE;
  781. tool_writel_sys(ptc->reg_value, base_offset);
  782. }else if((ptc->reg_addr >= DMA_BASE && ptc->reg_addr < DMA_BASE+0x1000000)
  783. ||(ptc->reg_addr >= I2S_BASE && ptc->reg_addr < I2S_BASE+0x1000000)
  784. ||(ptc->reg_addr >= UART2_BASE && ptc->reg_addr < UART2_BASE+0x300000)){
  785. pvirt_addr = (unsigned int*)ioremap(ptc->reg_addr, 0x04);
  786. if(!pvirt_addr){
  787. TOOL_DBG("WRITE_REGISTER --> ioremap reg_addr:0x%08x fail.\n",ptc->reg_addr);
  788. break;
  789. }
  790. writel(ptc->reg_value, pvirt_addr);
  791. iounmap(pvirt_addr);
  792. }else{
  793. TOOL_DBG("WRITE_REGISTER -->not support\n");
  794. break;
  795. }
  796. TOOL_DBG("WRITE_REGISTER --> reg_addr:0x%08x=0x%08x\n",ptc->reg_addr,ptc->reg_value);
  797. break;
  798. }
  799. case WRITE_TIMING_DEBUG:
  800. {
  801. unsigned int hsw, hfp, hbp, vsw;
  802. ptc->timing0_val = (rbuf[3] << 0) | (rbuf[4] << 8) | (rbuf[5] << 16) | (rbuf[6] << 24);
  803. ptc->timing1_val = (rbuf[7] << 0) | (rbuf[8] << 8) | (rbuf[9] << 16) | (rbuf[10] << 24);
  804. ptc->timing2_val = (rbuf[11] << 0)| (rbuf[12] << 8)| (rbuf[13]<< 16) | (rbuf[14] << 24);
  805. screen_type = ptc->screen_type;
  806. subscreen_type = ptc->subscreen_type;
  807. TOOL_DBG("WRITE_TIMING -->screen_type=%d, subscreen_type=%d\n",screen_type,subscreen_type);
  808. if(screen_type==SCREEN_TYPE_RGB565||screen_type==SCREEN_TYPE_RGB888||
  809. screen_type==SCREEN_TYPE_LVDS||screen_type==SCREEN_TYPE_ITU601){
  810. #ifdef ARK1668_LINUX_MIRCO
  811. hfp = ((ptc->timing0_val >> 0) & 0x3ff) - 1;
  812. hbp = ((ptc->timing0_val >> 10) & 0x3ff) - 1;
  813. hsw = ((ptc->timing0_val >> 20) & 0x3ff) - 1;
  814. ptc->timing0_val &= ~(0x3fffffff);
  815. ptc->timing0_val |= hsw << 20 | hbp << 10 | hfp;
  816. vsw = ((ptc->timing1_val >> 13) & 0x3f) - 1;
  817. ptc->timing1_val &= ~(0x0007E000);
  818. ptc->timing1_val |= vsw << 13;
  819. #endif
  820. tool_writel(ptc->timing0_val, LCD_TIMING0);
  821. tool_writel(ptc->timing1_val, LCD_TIMING1);
  822. tool_writel(ptc->timing2_val, LCD_TIMING2);
  823. }else if(screen_type==SCREEN_TYPE_VGA||screen_type==SCREEN_TYPE_CVBS||
  824. screen_type==SCREEN_TYPE_YPBPR||screen_type==SCREEN_TYPE_ITU656){
  825. #ifdef ARK1668_LINUX_MIRCO
  826. if(screen_type!=SCREEN_TYPE_VGA){
  827. hfp = ((ptc->timing0_val >> 0) & 0x3ff) - 1;
  828. hbp = ((ptc->timing0_val >> 10) & 0x3ff) - 1;
  829. ptc->timing0_val &= ~(0xfffff);
  830. ptc->timing0_val |= hbp << 10 | hfp;
  831. }
  832. #endif
  833. tool_writel(ptc->timing0_val, TV_TIMING0);
  834. tool_writel(ptc->timing1_val, TV_TIMING1);
  835. tool_writel(ptc->timing2_val, TV_TIMING2);
  836. tool_writel(((ptc->timing1_val >> 13) & 0x3F)/2, LCD_TIMING_FRAME_START_CNT_TV);
  837. }
  838. if(screen_type == SCREEN_TYPE_ITU656){
  839. val = tool_readl(TV_CONTROL);
  840. val &= ~(0x01 << 1);
  841. if(ptc->subscreen_type == NTSC){
  842. val |= (0x01 << 1);
  843. TOOL_DBG("SCREEN_TYPE_ITU656 NTSC\n");
  844. }else{
  845. TOOL_DBG("SCREEN_TYPE_ITU656 PAL\n");
  846. }
  847. tool_writel(val, TV_CONTROL);
  848. }else if (screen_type == SCREEN_TYPE_YPBPR){
  849. ypbpr_config_interlace_mode(subscreen_type);
  850. }else if(screen_type == SCREEN_TYPE_CVBS){
  851. val = tool_readl(TV_CONTROL);
  852. if(ptc->subscreen_type == NTSC){
  853. val |= (0x01 << 1);
  854. cvbs_ntsc_init();
  855. }else{
  856. val &= ~(0x01 << 1);
  857. cvbs_pal_init();
  858. }
  859. tool_writel(val, TV_CONTROL);
  860. }
  861. TOOL_DBG("0x%08x 0x%08x 0x%08x\n",ptc->timing0_val,ptc->timing1_val,ptc->timing2_val);
  862. break;
  863. }
  864. case WRITE_LVDS_SPECIAL:
  865. ptc->lvds_spec_val = (rbuf[3] << 0) | (rbuf[4] << 8) | (rbuf[5] << 16) | (rbuf[6] << 24);
  866. tool_writel_sys(ptc->lvds_spec_val, SYS_LVDS_CTRL_CFG);
  867. TOOL_DBG("WRITE_LVDS --> lvds_spec_val=0x%08x\n",ptc->lvds_spec_val);
  868. break;
  869. case WRITE_DISPLAY_SHOW:
  870. val = rbuf[3] & 0x1F;;
  871. ptc->vp_val = (rbuf[4] << 0) | (rbuf[5] << 8) | (rbuf[6] << 16) | (rbuf[7] << 24);
  872. if (val == DISP_VIDEO1){
  873. base_offset = LCD_VIDEO_VP_REG_1;
  874. }else if (val == DISP_VIDEO2){
  875. base_offset = LCD_VIDEO2_VP_REG_1;
  876. }else if (val == DISP_OSD1){
  877. base_offset = LCD_OSD1_VP_REG_1;
  878. }else if (val == DISP_OSD2){
  879. base_offset = LCD_OSD2_VP_REG_1;
  880. }else if (val == DISP_OSD3){
  881. base_offset = LCD_OSD3_VP_REG_1;
  882. }else{
  883. TOOL_DBG("WRITE_DISPLAY_SHOW: error. \n");
  884. break;
  885. }
  886. tool_writel(ptc->vp_val, base_offset);
  887. TOOL_DBG("WRITE_DISPLAY_SHOW --> reg base_offset=0x%08x, vp_val=0x%08x\n",
  888. base_offset,ptc->vp_val);
  889. break;
  890. case WRITE_GAMMA_DEBUG:
  891. {
  892. unsigned int cur_read;
  893. base_offset = LCD_GAMMA_REG_0;
  894. ptc->gamma_reg0_val = rbuf[3];
  895. tool_writel(ptc->gamma_reg0_val, base_offset);
  896. base_offset += 4;
  897. TOOL_DBG("WRITE_GAMMA --> gamma_reg0_val=0x%0x\n",ptc->gamma_reg0_val);
  898. if(rbuf[3] == 0x03){
  899. for (i = 0;i < GAMMA_REG_MAX;i++){
  900. cur_read = 4*i;
  901. ptc->gamma_val[i] = (rbuf[4+cur_read] << 0) | (rbuf[5+cur_read] << 8) |
  902. (rbuf[6+cur_read] << 16)| (rbuf[7+cur_read] << 24);
  903. }
  904. for (i = 0;i < GAMMA_REG_MAX;i++){
  905. tool_writel(ptc->gamma_val[i], base_offset);
  906. base_offset += 4;
  907. }
  908. //for (i = 0;i < GAMMA_REG_MAX;i++)
  909. //TOOL_DBG("WRITE_GAMMA --> gamma_val[%d]=0x%08x\n ",i,ptc->gamma_val[i]);
  910. }
  911. break;
  912. }
  913. case WRITE_ITU656_DIRECT:
  914. ptc->tv_type = rbuf[3] & 0xFF;
  915. ptc->itu656byp_conval = (rbuf[4] << 0) | (rbuf[5] << 8) | (rbuf[6] << 16) | (rbuf[7] << 24);
  916. ptc->itu656byp_npreg0val = (rbuf[8] << 0) | (rbuf[9] << 8) | (rbuf[10] << 16)| (rbuf[11] << 24);
  917. ptc->itu656byp_npreg1val = (rbuf[12] << 0)| (rbuf[13] << 8)| (rbuf[14] << 16)| (rbuf[15] << 24);
  918. ptc->itu656byp_npreg2val = (rbuf[16] << 0)| (rbuf[17] << 8)| (rbuf[18] << 16)| (rbuf[19] << 24);
  919. ptc->itu656byp_npreg3val = (rbuf[20] << 0)| (rbuf[21] << 8)| (rbuf[22] << 16)| (rbuf[23] << 24);
  920. ptc->itu656byp_npreg4val = (rbuf[24] << 0)| (rbuf[25] << 8)| (rbuf[26] << 16)| (rbuf[27] << 24);
  921. ptc->itu656byp_reg0val = (rbuf[28] << 0)| (rbuf[29] << 8)| (rbuf[30] << 16)| (rbuf[31] << 24);
  922. TOOL_DBG("WRITE_ITU656 --> tv_type:%d 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  923. ptc->tv_type,ptc->itu656byp_conval,ptc->itu656byp_npreg0val,
  924. ptc->itu656byp_npreg1val,ptc->itu656byp_npreg2val,ptc->itu656byp_npreg3val,
  925. ptc->itu656byp_npreg4val,ptc->itu656byp_reg0val );
  926. tool_writel(ptc->itu656byp_conval, ITU656_BYP_MODE_CONTROL);
  927. tool_writel(ptc->itu656byp_reg0val, ITU656_BYP_MODE_REG0);
  928. if(ptc->tv_type == TV_NTSC){
  929. tool_writel(ptc->itu656byp_npreg0val, ITU656_BYP_MODE_NTSC_REG0);
  930. tool_writel(ptc->itu656byp_npreg1val, ITU656_BYP_MODE_NTSC_REG1);
  931. tool_writel(ptc->itu656byp_npreg2val, ITU656_BYP_MODE_NTSC_REG2);
  932. tool_writel(ptc->itu656byp_npreg3val, ITU656_BYP_MODE_NTSC_REG3);
  933. tool_writel(ptc->itu656byp_npreg4val, ITU656_BYP_MODE_NTSC_REG4);
  934. }else if(ptc->tv_type == TV_PAL){
  935. tool_writel(ptc->itu656byp_npreg0val, ITU656_BYP_MODE_PAL_REG0);
  936. tool_writel(ptc->itu656byp_npreg1val, ITU656_BYP_MODE_PAL_REG1);
  937. tool_writel(ptc->itu656byp_npreg2val, ITU656_BYP_MODE_PAL_REG2);
  938. tool_writel(ptc->itu656byp_npreg3val, ITU656_BYP_MODE_PAL_REG3);
  939. tool_writel(ptc->itu656byp_npreg4val, ITU656_BYP_MODE_PAL_REG4);
  940. }
  941. break;
  942. case WRITE_CLOCK_DEBUG:
  943. lcd_clk_sel = -1;
  944. ptc->lcd_clock_config_val = (rbuf[3] << 0) | (rbuf[4] << 8) | (rbuf[5] << 16) | (rbuf[6] << 24);
  945. ptc->lcd_clk_dly_cfg_val = (rbuf[7] << 0) | (rbuf[8] << 8) | (rbuf[9] << 16) | (rbuf[10] << 24);
  946. ptc->lcd_clk_freq_val = (rbuf[11]<< 0) |(rbuf[12] << 8) | (rbuf[13]<< 16) | (rbuf[14] << 24);
  947. tool_writel_sys(ptc->lcd_clock_config_val, SYS_LCD_CLOCK_CFG);
  948. tool_writel_sys(ptc->lcd_clk_dly_cfg_val, SYS_CLK_DLY_CFG);
  949. TOOL_DBG("WRITE_CLOCK --> lcd_clock_config_val=0x%08x lcd_clk_dly_cfg_val=0x%08x\n",\
  950. ptc->lcd_clock_config_val,ptc->lcd_clk_dly_cfg_val);
  951. screen_type = ptc->screen_type;
  952. if (screen_type == SCREEN_TYPE_LVDS||screen_type==SCREEN_TYPE_RGB565||
  953. screen_type==SCREEN_TYPE_RGB888||screen_type==SCREEN_TYPE_ITU601){
  954. lcd_clk_sel = (ptc->lcd_clock_config_val >> 7) & 0x0F;
  955. }else if(screen_type==SCREEN_TYPE_YPBPR||screen_type==SCREEN_TYPE_VGA||
  956. screen_type==SCREEN_TYPE_CVBS||screen_type==SCREEN_TYPE_ITU656){
  957. val = tool_readl_sys(SYS_DEVICE_CLK_CFG2);
  958. val &= ~(0xF << 20);
  959. val |= (DDS << 20);
  960. tool_writel_sys(val, SYS_DEVICE_CLK_CFG2);
  961. lcd_clk_sel = DDS;
  962. }
  963. if (lcd_clk_sel == DDS){
  964. TOOL_DBG("WRITE_CLOCK --> DDS set lcd_clk_freq_val=%d\n",ptc->lcd_clk_freq_val);
  965. set_dds_frequency(ptc->lcd_clk_freq_val);
  966. }
  967. break;
  968. case WRITE_DISPLAY_INTERFACE:
  969. ptc->screen_type = rbuf[3];
  970. ptc->subscreen_type = rbuf[4];
  971. ptc->interlace = rbuf[5];
  972. TOOL_DBG("WRITE_DISPLAY_INTERFACE --> screen_type = 0x%08x,subscreen_type=0x%08x,interlace=%d\n",
  973. ptc->screen_type,ptc->subscreen_type,ptc->interlace);
  974. break;
  975. case REQUEST_READ_REGISTER_ACCESS:
  976. {
  977. unsigned int* pvirt_addr = NULL;
  978. ptc->reg_addr = (rbuf[3] << 0) | (rbuf[4] << 8) | (rbuf[5] << 16) | (rbuf[6] << 24);
  979. if (ptc->reg_addr >= LCD_BASE && ptc->reg_addr < LCD_BASE+0x2000){
  980. base_offset = ptc->reg_addr - LCD_BASE;
  981. ptc->reg_value = tool_readl(base_offset);
  982. }else if(ptc->reg_addr >= SYS_BASE && ptc->reg_addr < SYS_BASE+0x1000){
  983. base_offset = ptc->reg_addr - SYS_BASE;
  984. ptc->reg_value = tool_readl_sys(base_offset);
  985. }else if((ptc->reg_addr >= DMA_BASE && ptc->reg_addr < DMA_BASE+0x1000000)
  986. ||(ptc->reg_addr >= I2S_BASE && ptc->reg_addr < I2S_BASE+0x1000000)
  987. ||(ptc->reg_addr >= UART2_BASE && ptc->reg_addr < UART2_BASE+0x300000)){
  988. pvirt_addr = (unsigned int*)ioremap(ptc->reg_addr, 0x04);
  989. if(!pvirt_addr){
  990. TOOL_DBG("WRITE_REGISTER --> ioremap reg_addr:0x%08x fail.\n",ptc->reg_addr);
  991. break;
  992. }
  993. ptc->reg_value = readl(pvirt_addr);
  994. iounmap(pvirt_addr);
  995. }else{
  996. TOOL_DBG("REQUEST_READ_REGISTER <-- reg_addr:0x%08x not support\n",ptc->reg_addr);
  997. break;
  998. }
  999. TOOL_DBG("REQUEST_READ_REGISTER <-- reg_addr:0x%08x=0x%08x\n",ptc->reg_addr,ptc->reg_value);
  1000. fill_trans_data(REQUEST_READ_REGISTER_ACCESS);
  1001. break;
  1002. }
  1003. case REQUEST_READ_TIMING_DEBUG:
  1004. {
  1005. unsigned int hsw, hfp, hbp, vsw;
  1006. screen_type = ptc->screen_type;
  1007. if(screen_type==SCREEN_TYPE_VGA||screen_type==SCREEN_TYPE_CVBS||
  1008. screen_type==SCREEN_TYPE_YPBPR||screen_type==SCREEN_TYPE_ITU656){
  1009. ptc->timing0_val = tool_readl(TV_TIMING0);
  1010. ptc->timing1_val = tool_readl(TV_TIMING1);
  1011. ptc->timing2_val = tool_readl(TV_TIMING2);
  1012. #ifdef ARK1668_LINUX_MIRCO
  1013. if(screen_type!=SCREEN_TYPE_VGA){
  1014. hfp = ((ptc->timing0_val >> 0) & 0x3ff) + 1;
  1015. hbp = ((ptc->timing0_val >> 10) & 0x3ff) + 1;
  1016. ptc->timing0_val &= ~(0xfffff);
  1017. ptc->timing0_val |= hbp << 10 | hfp;
  1018. }
  1019. #endif
  1020. TOOL_DBG("REQUEST_READ_TIMING <-- TVtiming \n");
  1021. }else{
  1022. ptc->timing0_val = tool_readl(LCD_TIMING0);
  1023. ptc->timing1_val = tool_readl(LCD_TIMING1);
  1024. ptc->timing2_val = tool_readl(LCD_TIMING2);
  1025. TOOL_DBG("REQUEST_READ_TIMING <-- LCDtiming \n");
  1026. #ifdef ARK1668_LINUX_MIRCO
  1027. hfp = ((ptc->timing0_val >> 0) & 0x3ff) + 1;
  1028. hbp = ((ptc->timing0_val >> 10) & 0x3ff) + 1;
  1029. hsw = ((ptc->timing0_val >> 20) & 0x3ff) + 1;
  1030. ptc->timing0_val &= ~(0x3fffffff);
  1031. ptc->timing0_val |= hsw << 20 | hbp << 10 | hfp;
  1032. vsw = ((ptc->timing1_val >> 13) & 0x3f) + 1;
  1033. ptc->timing1_val &= ~(0x0007E000);
  1034. ptc->timing1_val |= vsw << 13;
  1035. #endif
  1036. }
  1037. TOOL_DBG("0x%08x 0x%08x 0x%08x\n",ptc->timing0_val,ptc->timing1_val,ptc->timing2_val);
  1038. fill_trans_data(REQUEST_READ_TIMING_DEBUG);
  1039. }
  1040. break;
  1041. case REQUEST_READ_LVDS_SPECIAL:
  1042. ptc->lvds_spec_val = tool_readl_sys(SYS_LVDS_CTRL_CFG);
  1043. TOOL_DBG("REQUEST_READ_LVDS <-- 0x%08x\n",ptc->lvds_spec_val);
  1044. fill_trans_data(REQUEST_READ_LVDS_SPECIAL);
  1045. break;
  1046. case REQUEST_READ_DISPLAY_SHOW:
  1047. val = rbuf[3] & 0x1F;
  1048. if (val == DISP_VIDEO1){
  1049. base_offset = LCD_VIDEO_VP_REG_1;
  1050. }else if (val == DISP_VIDEO2){
  1051. base_offset = LCD_VIDEO2_VP_REG_1;
  1052. }else if (val == DISP_OSD1){
  1053. base_offset = LCD_OSD1_VP_REG_1;
  1054. }else if (val == DISP_OSD2){
  1055. base_offset = LCD_OSD2_VP_REG_1;
  1056. }else if (val == DISP_OSD3){
  1057. base_offset = LCD_OSD3_VP_REG_1;
  1058. }else{
  1059. TOOL_DBG("REQUEST_READ_DISPLAY: type error!\n");
  1060. break;
  1061. }
  1062. ptc->vp_val = tool_readl(base_offset);
  1063. TOOL_DBG("REQUEST_READ_DISPLAY <-- base_offset=0x%08x vp_val=0x%08x\n",base_offset, ptc->vp_val);
  1064. fill_trans_data(REQUEST_READ_DISPLAY_SHOW);
  1065. break;
  1066. case REQUEST_READ_GAMMA_DEBUG:
  1067. base_offset = LCD_GAMMA_REG_0;
  1068. ptc->gamma_reg0_val = tool_readl(base_offset);
  1069. base_offset += 4;
  1070. for (i = 0;i < GAMMA_REG_MAX ;i++){
  1071. ptc->gamma_val[i] = tool_readl(base_offset);
  1072. base_offset += 4;
  1073. }
  1074. for (i = 0;i < GAMMA_REG_MAX;i++)
  1075. TOOL_DBG("REQUEST_READ_GAMMA <-- gamma_val[%d]=0x%08x\n",i,ptc->gamma_val[i]);
  1076. fill_trans_data(REQUEST_READ_GAMMA_DEBUG);
  1077. break;
  1078. case REQUEST_READ_ITU656_DIRECT:
  1079. ptc->tv_type = rbuf[3] & 0xFF;
  1080. ptc->itu656byp_conval = tool_readl(ITU656_BYP_MODE_CONTROL);
  1081. ptc->itu656byp_reg0val = tool_readl(ITU656_BYP_MODE_REG0);
  1082. if(ptc->tv_type == TV_NTSC){
  1083. ptc->itu656byp_npreg0val = tool_readl(ITU656_BYP_MODE_NTSC_REG0);
  1084. ptc->itu656byp_npreg1val = tool_readl(ITU656_BYP_MODE_NTSC_REG1);
  1085. ptc->itu656byp_npreg2val = tool_readl(ITU656_BYP_MODE_NTSC_REG2);
  1086. ptc->itu656byp_npreg3val = tool_readl(ITU656_BYP_MODE_NTSC_REG3);
  1087. ptc->itu656byp_npreg4val = tool_readl(ITU656_BYP_MODE_NTSC_REG4);
  1088. }else if(ptc->tv_type == TV_PAL){
  1089. ptc->itu656byp_npreg0val = tool_readl(ITU656_BYP_MODE_PAL_REG0);
  1090. ptc->itu656byp_npreg1val = tool_readl(ITU656_BYP_MODE_PAL_REG1);
  1091. ptc->itu656byp_npreg2val = tool_readl(ITU656_BYP_MODE_PAL_REG2);
  1092. ptc->itu656byp_npreg3val = tool_readl(ITU656_BYP_MODE_PAL_REG3);
  1093. ptc->itu656byp_npreg4val = tool_readl(ITU656_BYP_MODE_PAL_REG4);
  1094. }
  1095. TOOL_DBG("REQUEST_READ_ITU656 <-- tv_type:%d 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",\
  1096. ptc->tv_type,ptc->itu656byp_conval,ptc->itu656byp_npreg0val,
  1097. ptc->itu656byp_npreg1val,ptc->itu656byp_npreg2val,ptc->itu656byp_npreg3val,
  1098. ptc->itu656byp_npreg4val,ptc->itu656byp_reg0val );
  1099. fill_trans_data(REQUEST_READ_ITU656_DIRECT);
  1100. break;
  1101. case REQUEST_READ_CLOCK_DEBUG:
  1102. lcd_clk_sel = -1;
  1103. screen_type = ptc->screen_type;
  1104. ptc->lcd_clock_config_val = tool_readl_sys(SYS_LCD_CLOCK_CFG);
  1105. ptc->lcd_clk_dly_cfg_val = tool_readl_sys(SYS_CLK_DLY_CFG);
  1106. TOOL_DBG("REQUEST_READ_CLOCK <-- lcd_clock_config_val=0x%08x,lcd_clk_dly_cfg_val=0x%08x\n",
  1107. ptc->lcd_clock_config_val,ptc->lcd_clk_dly_cfg_val);
  1108. if((ptc->lcd_clock_config_val & 0x70) == 0)
  1109. ptc->lcd_clock_config_val |= (0x01 << 4);
  1110. if (screen_type== SCREEN_TYPE_LVDS||screen_type==SCREEN_TYPE_RGB565||
  1111. screen_type==SCREEN_TYPE_RGB888||screen_type== SCREEN_TYPE_ITU601){
  1112. lcd_clk_sel = (ptc->lcd_clock_config_val >> 7) & 0x0F;
  1113. }else if(screen_type== SCREEN_TYPE_YPBPR||screen_type== SCREEN_TYPE_VGA||
  1114. screen_type==SCREEN_TYPE_CVBS||screen_type==SCREEN_TYPE_ITU656){
  1115. val = tool_readl_sys(SYS_DEVICE_CLK_CFG2);
  1116. lcd_clk_sel = (val >> 20) & 0x0F;
  1117. lcd_clk_sel = DDS;
  1118. }
  1119. if (lcd_clk_sel == SYSPLL){
  1120. ptc->lcd_clk_freq_val = get_syspll_frequency();
  1121. TOOL_DBG("SYSPLL lcd_clk_freq_val=%d\n",ptc->lcd_clk_freq_val);
  1122. }else if (lcd_clk_sel == DDS){
  1123. ptc->lcd_clk_freq_val = get_dds_frequency();
  1124. TOOL_DBG("DDS lcd_clk_freq_val=%d\n",ptc->lcd_clk_freq_val);
  1125. }else if (lcd_clk_sel == CPUPLL){
  1126. ptc->lcd_clk_freq_val = get_cpupll_frequency();
  1127. TOOL_DBG("CPU lcd_clk_freq_val=%d\n",ptc->lcd_clk_freq_val);
  1128. }else{
  1129. TOOL_DBG("error! \n");
  1130. break;
  1131. }
  1132. fill_trans_data(REQUEST_READ_CLOCK_DEBUG);
  1133. break;
  1134. case REQUEST_READ_SYSPLL_DDS:
  1135. lcd_clk_sel = rbuf[3];
  1136. TOOL_DBG("REQUEST_READ_SYSPLL_DDS <-- lcd_clk_sel=%0x \n",lcd_clk_sel);
  1137. if (lcd_clk_sel == SYSPLL){
  1138. ptc->lcd_clk_freq_val = get_syspll_frequency();
  1139. TOOL_DBG("SYSPLL lcd_clk_freq_val=%d \n",ptc->lcd_clk_freq_val);
  1140. }else if (lcd_clk_sel == DDS){
  1141. ptc->lcd_clk_freq_val = get_dds_frequency();
  1142. TOOL_DBG("DDS lcd_clk_freq_val=%d \n",ptc->lcd_clk_freq_val);
  1143. }else{
  1144. TOOL_DBG("error! \n");
  1145. break;
  1146. }
  1147. fill_trans_data(REQUEST_READ_SYSPLL_DDS);
  1148. break;
  1149. default:
  1150. ret = false;
  1151. break;
  1152. }
  1153. memset(rbuf,0,BUF_SIZE_MAX);
  1154. return ret;
  1155. }
  1156. static bool arktool_mem_init(void)
  1157. {
  1158. struct tool_serial_info *p = tsinfo;
  1159. if(!p) return false;
  1160. p->mmio = ioremap(LCD_BASE, 0x1000);
  1161. if(!p->mmio)
  1162. return false;
  1163. p->sysreg = ioremap(SYS_BASE, 0x200);
  1164. if(!p->sysreg){
  1165. iounmap(p->mmio);
  1166. return false;
  1167. }
  1168. return true;
  1169. }
  1170. static void arktool_mem_deinit(void)
  1171. {
  1172. struct tool_serial_info *p = tsinfo;
  1173. if(p->mmio)
  1174. iounmap(tsinfo->mmio);
  1175. if(p->sysreg)
  1176. iounmap(tsinfo->sysreg);
  1177. }
  1178. static void send_uart_data(unsigned char *buf, int len)
  1179. {
  1180. tool_serial_send(buf, len);
  1181. }
  1182. static void reset_uart_recv(void)
  1183. {
  1184. struct tool_serial_info *p = tsinfo;
  1185. memset(&p->recv_buf,0,BUF_SIZE_MAX);
  1186. p->recv_flag = ARKTOOL_DATA_NONE;
  1187. p->recv = 0;
  1188. }
  1189. static bool is_command_id(unsigned char id)
  1190. {
  1191. struct tool_serial_info *p = tsinfo;
  1192. bool ret = true;
  1193. if(id == WRITE_GAMMA_DEBUG){
  1194. if(p->recv_buf[1] != 194)
  1195. ret = false;
  1196. }
  1197. else if((id > READ_COMMAND_ID_BASE && id <= READ_SYSPLL_DDS) || \
  1198. (id > WRITE_COMMAND_ID_BASE && id <= WRITE_CLOCK_DEBUG) || \
  1199. (id > REQUEST_READ_COMMAND_ID_BASE && id <= REQUEST_READ_SYSPLL_DDS) || \
  1200. id == WRITE_DISPLAY_INTERFACE){
  1201. if(p->recv_buf[1] > 50)
  1202. ret = false;
  1203. }else{
  1204. ret = false;
  1205. }
  1206. return ret;
  1207. }
  1208. static bool store_uart_data(char ch)
  1209. {
  1210. struct tool_serial_info *p = tsinfo;
  1211. unsigned int lenth = 0;
  1212. p->recv_buf[p->recv] = ch;
  1213. lenth = p->recv_buf[1]+3;
  1214. if((p->recv == 1 && p->recv_buf[1] > 240) ||
  1215. (p->recv == 2 && !is_command_id(p->recv_buf[2]))){
  1216. reset_uart_recv();
  1217. return false;
  1218. }
  1219. if (p->recv_buf[0] == CUSTOMER_ARK_FLAG){
  1220. p->recv++;
  1221. if(p->recv >= lenth){
  1222. if(p->read_buf[0] != CUSTOMER_ARK_FLAG){
  1223. memcpy(p->read_buf,p->recv_buf,lenth);
  1224. if(data_check_sum(p->read_buf)){
  1225. reset_uart_recv();
  1226. return true;
  1227. }
  1228. }
  1229. reset_uart_recv();
  1230. }
  1231. }
  1232. return false;
  1233. }
  1234. static void arktool_func(void)
  1235. {
  1236. struct tool_serial_info *p = tsinfo;
  1237. unsigned char write_flag[3] = {'A','r','K'};
  1238. tool_data_process();
  1239. if ((p->request_read_id >= REQUEST_READ_COMMAND_ID_BASE) &&
  1240. (p->request_read_id <=REQUEST_READ_COMMAND_ID_END)){
  1241. //TOOL_DBG("send_uart_data.\n");
  1242. p->request_read_id = 0;
  1243. send_uart_data(write_flag, 3);
  1244. send_uart_data(p->write_buf, p->write_len);
  1245. }
  1246. }
  1247. static bool check_arktool_enable(char ch)
  1248. {
  1249. struct tool_serial_info *p = tsinfo;
  1250. char arktool_flag[20] = "arktoolenablenow";
  1251. static int i = 0;
  1252. if(!p || !p->mmio || !p->sysreg)
  1253. return false;
  1254. if(p->arktool_enable)
  1255. return true;
  1256. if(arktool_flag[i] == ch)
  1257. i++;
  1258. else
  1259. i = 0;
  1260. if(i >= 16){
  1261. p->arktool_enable = 1;
  1262. TOOL_DBG("arktool enable.\n");
  1263. }
  1264. return false;
  1265. }
  1266. static bool tool_serial_get_ch(char ch)
  1267. {
  1268. struct tool_serial_info *p = tsinfo;
  1269. bool ret = false;
  1270. if(!p || !p->arktool_enable)
  1271. return ret;
  1272. if((ch & 0xff) == CUSTOMER_ARK_FLAG && p->recv_flag != ARKTOOL_DATA_START)
  1273. p->recv_flag = ARKTOOL_DATA_START;
  1274. if (p->recv_flag == ARKTOOL_DATA_START){
  1275. //TOOL_DBG("receive: %02x\r\n",ch&0xff);
  1276. if (store_uart_data(ch)){
  1277. schedule_work(&p->rx_task);
  1278. p->recv_flag = ARKTOOL_DATA_NONE;
  1279. }
  1280. ret = true;
  1281. }
  1282. return ret;
  1283. }
  1284. static void tool_serial_rx_task(struct work_struct *work)
  1285. {
  1286. arktool_func();
  1287. return;
  1288. }
  1289. static int ark_tool_serial_probe(struct platform_device *pdev)
  1290. {
  1291. struct tool_serial_info *info = NULL;
  1292. info = devm_kzalloc(&pdev->dev, sizeof(struct tool_serial_info),GFP_KERNEL);
  1293. if (!info) {
  1294. TOOL_DBG("kzalloc tsinfo failed .\n");
  1295. return -ENOMEM;
  1296. }
  1297. memset(info, 0 ,sizeof(struct tool_serial_info));
  1298. tsinfo = info;
  1299. arktool_mem_init();
  1300. INIT_WORK(&info->rx_task, tool_serial_rx_task);
  1301. tool_serial_register_rev_handler(tool_serial_get_ch, check_arktool_enable);
  1302. platform_set_drvdata(pdev, info);
  1303. return 0;
  1304. }
  1305. static int ark_tool_serial_remove(struct platform_device *pdev)
  1306. {
  1307. struct tool_serial_info *info = platform_get_drvdata(pdev);
  1308. cancel_work_sync(&info->rx_task);
  1309. tool_serial_unregister_rev_handler();
  1310. arktool_mem_deinit();
  1311. return 0;
  1312. }
  1313. static const struct of_device_id ark_tool_serial_of_match[] = {
  1314. { .compatible = "arkmicro,ark-tool-serial", },
  1315. {},
  1316. };
  1317. static struct platform_driver ark_tool_serial_platform_driver = {
  1318. .probe = ark_tool_serial_probe,
  1319. .remove = ark_tool_serial_remove,
  1320. .driver = {
  1321. .name = "ark-tool-serial",
  1322. .of_match_table = of_match_ptr(ark_tool_serial_of_match),
  1323. },
  1324. };
  1325. static int __init ark_tool_serial_init(void)
  1326. {
  1327. return platform_driver_register(&ark_tool_serial_platform_driver);
  1328. }
  1329. static void __exit ark_tool_serial_exit(void)
  1330. {
  1331. platform_driver_unregister(&ark_tool_serial_platform_driver);
  1332. }
  1333. /*
  1334. * While this can be a module, if builtin it's most likely the console
  1335. * So let's leave module_exit but move module_init to an earlier place
  1336. */
  1337. arch_initcall(ark_tool_serial_init);
  1338. module_exit(ark_tool_serial_exit);
  1339. MODULE_AUTHOR("Leo");
  1340. MODULE_DESCRIPTION("Arkmicro arktool serial driver");
  1341. MODULE_LICENSE("GPL v2");