sh_mobile_lcdcfb.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /*
  2. * SuperH Mobile LCDC Framebuffer
  3. *
  4. * Copyright (c) 2008 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/delay.h>
  13. #include <linux/mm.h>
  14. #include <linux/fb.h>
  15. #include <linux/clk.h>
  16. #include <linux/pm_runtime.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/dma-mapping.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/vmalloc.h>
  21. #include <video/sh_mobile_lcdc.h>
  22. #include <asm/atomic.h>
  23. #define PALETTE_NR 16
  24. #define SIDE_B_OFFSET 0x1000
  25. #define MIRROR_OFFSET 0x2000
  26. /* shared registers */
  27. #define _LDDCKR 0x410
  28. #define _LDDCKSTPR 0x414
  29. #define _LDINTR 0x468
  30. #define _LDSR 0x46c
  31. #define _LDCNT1R 0x470
  32. #define _LDCNT2R 0x474
  33. #define _LDRCNTR 0x478
  34. #define _LDDDSR 0x47c
  35. #define _LDDWD0R 0x800
  36. #define _LDDRDR 0x840
  37. #define _LDDWAR 0x900
  38. #define _LDDRAR 0x904
  39. /* shared registers and their order for context save/restore */
  40. static int lcdc_shared_regs[] = {
  41. _LDDCKR,
  42. _LDDCKSTPR,
  43. _LDINTR,
  44. _LDDDSR,
  45. _LDCNT1R,
  46. _LDCNT2R,
  47. };
  48. #define NR_SHARED_REGS ARRAY_SIZE(lcdc_shared_regs)
  49. /* per-channel registers */
  50. enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R,
  51. LDSM2R, LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR,
  52. NR_CH_REGS };
  53. static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
  54. [LDDCKPAT1R] = 0x400,
  55. [LDDCKPAT2R] = 0x404,
  56. [LDMT1R] = 0x418,
  57. [LDMT2R] = 0x41c,
  58. [LDMT3R] = 0x420,
  59. [LDDFR] = 0x424,
  60. [LDSM1R] = 0x428,
  61. [LDSM2R] = 0x42c,
  62. [LDSA1R] = 0x430,
  63. [LDMLSR] = 0x438,
  64. [LDHCNR] = 0x448,
  65. [LDHSYNR] = 0x44c,
  66. [LDVLNR] = 0x450,
  67. [LDVSYNR] = 0x454,
  68. [LDPMR] = 0x460,
  69. };
  70. static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
  71. [LDDCKPAT1R] = 0x408,
  72. [LDDCKPAT2R] = 0x40c,
  73. [LDMT1R] = 0x600,
  74. [LDMT2R] = 0x604,
  75. [LDMT3R] = 0x608,
  76. [LDDFR] = 0x60c,
  77. [LDSM1R] = 0x610,
  78. [LDSM2R] = 0x614,
  79. [LDSA1R] = 0x618,
  80. [LDMLSR] = 0x620,
  81. [LDHCNR] = 0x624,
  82. [LDHSYNR] = 0x628,
  83. [LDVLNR] = 0x62c,
  84. [LDVSYNR] = 0x630,
  85. [LDPMR] = 0x63c,
  86. };
  87. #define START_LCDC 0x00000001
  88. #define LCDC_RESET 0x00000100
  89. #define DISPLAY_BEU 0x00000008
  90. #define LCDC_ENABLE 0x00000001
  91. #define LDINTR_FE 0x00000400
  92. #define LDINTR_VSE 0x00000200
  93. #define LDINTR_VEE 0x00000100
  94. #define LDINTR_FS 0x00000004
  95. #define LDINTR_VSS 0x00000002
  96. #define LDINTR_VES 0x00000001
  97. #define LDRCNTR_SRS 0x00020000
  98. #define LDRCNTR_SRC 0x00010000
  99. #define LDRCNTR_MRS 0x00000002
  100. #define LDRCNTR_MRC 0x00000001
  101. struct sh_mobile_lcdc_priv;
  102. struct sh_mobile_lcdc_chan {
  103. struct sh_mobile_lcdc_priv *lcdc;
  104. unsigned long *reg_offs;
  105. unsigned long ldmt1r_value;
  106. unsigned long enabled; /* ME and SE in LDCNT2R */
  107. struct sh_mobile_lcdc_chan_cfg cfg;
  108. u32 pseudo_palette[PALETTE_NR];
  109. unsigned long saved_ch_regs[NR_CH_REGS];
  110. struct fb_info *info;
  111. dma_addr_t dma_handle;
  112. struct fb_deferred_io defio;
  113. struct scatterlist *sglist;
  114. unsigned long frame_end;
  115. unsigned long pan_offset;
  116. unsigned long new_pan_offset;
  117. wait_queue_head_t frame_end_wait;
  118. };
  119. struct sh_mobile_lcdc_priv {
  120. void __iomem *base;
  121. int irq;
  122. atomic_t hw_usecnt;
  123. struct device *dev;
  124. struct clk *dot_clk;
  125. unsigned long lddckr;
  126. struct sh_mobile_lcdc_chan ch[2];
  127. unsigned long saved_shared_regs[NR_SHARED_REGS];
  128. int started;
  129. };
  130. static bool banked(int reg_nr)
  131. {
  132. switch (reg_nr) {
  133. case LDMT1R:
  134. case LDMT2R:
  135. case LDMT3R:
  136. case LDDFR:
  137. case LDSM1R:
  138. case LDSA1R:
  139. case LDMLSR:
  140. case LDHCNR:
  141. case LDHSYNR:
  142. case LDVLNR:
  143. case LDVSYNR:
  144. return true;
  145. }
  146. return false;
  147. }
  148. static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
  149. int reg_nr, unsigned long data)
  150. {
  151. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
  152. if (banked(reg_nr))
  153. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
  154. SIDE_B_OFFSET);
  155. }
  156. static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
  157. int reg_nr, unsigned long data)
  158. {
  159. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
  160. MIRROR_OFFSET);
  161. }
  162. static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
  163. int reg_nr)
  164. {
  165. return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
  166. }
  167. static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
  168. unsigned long reg_offs, unsigned long data)
  169. {
  170. iowrite32(data, priv->base + reg_offs);
  171. }
  172. static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
  173. unsigned long reg_offs)
  174. {
  175. return ioread32(priv->base + reg_offs);
  176. }
  177. static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
  178. unsigned long reg_offs,
  179. unsigned long mask, unsigned long until)
  180. {
  181. while ((lcdc_read(priv, reg_offs) & mask) != until)
  182. cpu_relax();
  183. }
  184. static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
  185. {
  186. return chan->cfg.chan == LCDC_CHAN_SUBLCD;
  187. }
  188. static void lcdc_sys_write_index(void *handle, unsigned long data)
  189. {
  190. struct sh_mobile_lcdc_chan *ch = handle;
  191. lcdc_write(ch->lcdc, _LDDWD0R, data | 0x10000000);
  192. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  193. lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  194. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  195. }
  196. static void lcdc_sys_write_data(void *handle, unsigned long data)
  197. {
  198. struct sh_mobile_lcdc_chan *ch = handle;
  199. lcdc_write(ch->lcdc, _LDDWD0R, data | 0x11000000);
  200. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  201. lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  202. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  203. }
  204. static unsigned long lcdc_sys_read_data(void *handle)
  205. {
  206. struct sh_mobile_lcdc_chan *ch = handle;
  207. lcdc_write(ch->lcdc, _LDDRDR, 0x01000000);
  208. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  209. lcdc_write(ch->lcdc, _LDDRAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  210. udelay(1);
  211. lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
  212. return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
  213. }
  214. struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
  215. lcdc_sys_write_index,
  216. lcdc_sys_write_data,
  217. lcdc_sys_read_data,
  218. };
  219. static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
  220. {
  221. if (atomic_inc_and_test(&priv->hw_usecnt)) {
  222. pm_runtime_get_sync(priv->dev);
  223. if (priv->dot_clk)
  224. clk_enable(priv->dot_clk);
  225. }
  226. }
  227. static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
  228. {
  229. if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
  230. if (priv->dot_clk)
  231. clk_disable(priv->dot_clk);
  232. pm_runtime_put(priv->dev);
  233. }
  234. }
  235. static int sh_mobile_lcdc_sginit(struct fb_info *info,
  236. struct list_head *pagelist)
  237. {
  238. struct sh_mobile_lcdc_chan *ch = info->par;
  239. unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
  240. struct page *page;
  241. int nr_pages = 0;
  242. sg_init_table(ch->sglist, nr_pages_max);
  243. list_for_each_entry(page, pagelist, lru)
  244. sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
  245. return nr_pages;
  246. }
  247. static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
  248. struct list_head *pagelist)
  249. {
  250. struct sh_mobile_lcdc_chan *ch = info->par;
  251. struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg;
  252. /* enable clocks before accessing hardware */
  253. sh_mobile_lcdc_clk_on(ch->lcdc);
  254. /*
  255. * It's possible to get here without anything on the pagelist via
  256. * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
  257. * invocation. In the former case, the acceleration routines are
  258. * stepped in to when using the framebuffer console causing the
  259. * workqueue to be scheduled without any dirty pages on the list.
  260. *
  261. * Despite this, a panel update is still needed given that the
  262. * acceleration routines have their own methods for writing in
  263. * that still need to be updated.
  264. *
  265. * The fsync() and empty pagelist case could be optimized for,
  266. * but we don't bother, as any application exhibiting such
  267. * behaviour is fundamentally broken anyways.
  268. */
  269. if (!list_empty(pagelist)) {
  270. unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
  271. /* trigger panel update */
  272. dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
  273. if (bcfg->start_transfer)
  274. bcfg->start_transfer(bcfg->board_data, ch,
  275. &sh_mobile_lcdc_sys_bus_ops);
  276. lcdc_write_chan(ch, LDSM2R, 1);
  277. dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
  278. } else {
  279. if (bcfg->start_transfer)
  280. bcfg->start_transfer(bcfg->board_data, ch,
  281. &sh_mobile_lcdc_sys_bus_ops);
  282. lcdc_write_chan(ch, LDSM2R, 1);
  283. }
  284. }
  285. static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
  286. {
  287. struct fb_deferred_io *fbdefio = info->fbdefio;
  288. if (fbdefio)
  289. schedule_delayed_work(&info->deferred_work, fbdefio->delay);
  290. }
  291. static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
  292. {
  293. struct sh_mobile_lcdc_priv *priv = data;
  294. struct sh_mobile_lcdc_chan *ch;
  295. unsigned long tmp;
  296. unsigned long ldintr;
  297. int is_sub;
  298. int k;
  299. /* acknowledge interrupt */
  300. ldintr = tmp = lcdc_read(priv, _LDINTR);
  301. /*
  302. * disable further VSYNC End IRQs, preserve all other enabled IRQs,
  303. * write 0 to bits 0-6 to ack all triggered IRQs.
  304. */
  305. tmp &= 0xffffff00 & ~LDINTR_VEE;
  306. lcdc_write(priv, _LDINTR, tmp);
  307. /* figure out if this interrupt is for main or sub lcd */
  308. is_sub = (lcdc_read(priv, _LDSR) & (1 << 10)) ? 1 : 0;
  309. /* wake up channel and disable clocks */
  310. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  311. ch = &priv->ch[k];
  312. if (!ch->enabled)
  313. continue;
  314. /* Frame Start */
  315. if (ldintr & LDINTR_FS) {
  316. if (is_sub == lcdc_chan_is_sublcd(ch)) {
  317. ch->frame_end = 1;
  318. wake_up(&ch->frame_end_wait);
  319. sh_mobile_lcdc_clk_off(priv);
  320. }
  321. }
  322. /* VSYNC End */
  323. if (ldintr & LDINTR_VES) {
  324. unsigned long ldrcntr = lcdc_read(priv, _LDRCNTR);
  325. /* Set the source address for the next refresh */
  326. lcdc_write_chan_mirror(ch, LDSA1R, ch->dma_handle +
  327. ch->new_pan_offset);
  328. if (lcdc_chan_is_sublcd(ch))
  329. lcdc_write(ch->lcdc, _LDRCNTR,
  330. ldrcntr ^ LDRCNTR_SRS);
  331. else
  332. lcdc_write(ch->lcdc, _LDRCNTR,
  333. ldrcntr ^ LDRCNTR_MRS);
  334. ch->pan_offset = ch->new_pan_offset;
  335. }
  336. }
  337. return IRQ_HANDLED;
  338. }
  339. static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
  340. int start)
  341. {
  342. unsigned long tmp = lcdc_read(priv, _LDCNT2R);
  343. int k;
  344. /* start or stop the lcdc */
  345. if (start)
  346. lcdc_write(priv, _LDCNT2R, tmp | START_LCDC);
  347. else
  348. lcdc_write(priv, _LDCNT2R, tmp & ~START_LCDC);
  349. /* wait until power is applied/stopped on all channels */
  350. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  351. if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
  352. while (1) {
  353. tmp = lcdc_read_chan(&priv->ch[k], LDPMR) & 3;
  354. if (start && tmp == 3)
  355. break;
  356. if (!start && tmp == 0)
  357. break;
  358. cpu_relax();
  359. }
  360. if (!start)
  361. lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
  362. }
  363. static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
  364. {
  365. struct sh_mobile_lcdc_chan *ch;
  366. struct fb_videomode *lcd_cfg;
  367. struct sh_mobile_lcdc_board_cfg *board_cfg;
  368. unsigned long tmp;
  369. int k, m;
  370. int ret = 0;
  371. /* enable clocks before accessing the hardware */
  372. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  373. if (priv->ch[k].enabled)
  374. sh_mobile_lcdc_clk_on(priv);
  375. /* reset */
  376. lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LCDC_RESET);
  377. lcdc_wait_bit(priv, _LDCNT2R, LCDC_RESET, 0);
  378. /* enable LCDC channels */
  379. tmp = lcdc_read(priv, _LDCNT2R);
  380. tmp |= priv->ch[0].enabled;
  381. tmp |= priv->ch[1].enabled;
  382. lcdc_write(priv, _LDCNT2R, tmp);
  383. /* read data from external memory, avoid using the BEU for now */
  384. lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~DISPLAY_BEU);
  385. /* stop the lcdc first */
  386. sh_mobile_lcdc_start_stop(priv, 0);
  387. /* configure clocks */
  388. tmp = priv->lddckr;
  389. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  390. ch = &priv->ch[k];
  391. if (!priv->ch[k].enabled)
  392. continue;
  393. m = ch->cfg.clock_divider;
  394. if (!m)
  395. continue;
  396. if (m == 1)
  397. m = 1 << 6;
  398. tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
  399. lcdc_write_chan(ch, LDDCKPAT1R, 0x00000000);
  400. lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
  401. }
  402. lcdc_write(priv, _LDDCKR, tmp);
  403. /* start dotclock again */
  404. lcdc_write(priv, _LDDCKSTPR, 0);
  405. lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
  406. /* interrupts are disabled to begin with */
  407. lcdc_write(priv, _LDINTR, 0);
  408. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  409. ch = &priv->ch[k];
  410. lcd_cfg = &ch->cfg.lcd_cfg;
  411. if (!ch->enabled)
  412. continue;
  413. tmp = ch->ldmt1r_value;
  414. tmp |= (lcd_cfg->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
  415. tmp |= (lcd_cfg->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
  416. tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
  417. tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
  418. tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
  419. tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
  420. tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
  421. lcdc_write_chan(ch, LDMT1R, tmp);
  422. /* setup SYS bus */
  423. lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
  424. lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
  425. /* horizontal configuration */
  426. tmp = lcd_cfg->xres + lcd_cfg->hsync_len;
  427. tmp += lcd_cfg->left_margin;
  428. tmp += lcd_cfg->right_margin;
  429. tmp /= 8; /* HTCN */
  430. tmp |= (lcd_cfg->xres / 8) << 16; /* HDCN */
  431. lcdc_write_chan(ch, LDHCNR, tmp);
  432. tmp = lcd_cfg->xres;
  433. tmp += lcd_cfg->right_margin;
  434. tmp /= 8; /* HSYNP */
  435. tmp |= (lcd_cfg->hsync_len / 8) << 16; /* HSYNW */
  436. lcdc_write_chan(ch, LDHSYNR, tmp);
  437. /* power supply */
  438. lcdc_write_chan(ch, LDPMR, 0);
  439. /* vertical configuration */
  440. tmp = lcd_cfg->yres + lcd_cfg->vsync_len;
  441. tmp += lcd_cfg->upper_margin;
  442. tmp += lcd_cfg->lower_margin; /* VTLN */
  443. tmp |= lcd_cfg->yres << 16; /* VDLN */
  444. lcdc_write_chan(ch, LDVLNR, tmp);
  445. tmp = lcd_cfg->yres;
  446. tmp += lcd_cfg->lower_margin; /* VSYNP */
  447. tmp |= lcd_cfg->vsync_len << 16; /* VSYNW */
  448. lcdc_write_chan(ch, LDVSYNR, tmp);
  449. board_cfg = &ch->cfg.board_cfg;
  450. if (board_cfg->setup_sys)
  451. ret = board_cfg->setup_sys(board_cfg->board_data, ch,
  452. &sh_mobile_lcdc_sys_bus_ops);
  453. if (ret)
  454. return ret;
  455. }
  456. /* word and long word swap */
  457. lcdc_write(priv, _LDDDSR, lcdc_read(priv, _LDDDSR) | 6);
  458. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  459. ch = &priv->ch[k];
  460. if (!priv->ch[k].enabled)
  461. continue;
  462. /* set bpp format in PKF[4:0] */
  463. tmp = lcdc_read_chan(ch, LDDFR);
  464. tmp &= ~(0x0001001f);
  465. tmp |= (ch->info->var.bits_per_pixel == 16) ? 3 : 0;
  466. lcdc_write_chan(ch, LDDFR, tmp);
  467. /* point out our frame buffer */
  468. lcdc_write_chan(ch, LDSA1R, ch->info->fix.smem_start);
  469. /* set line size */
  470. lcdc_write_chan(ch, LDMLSR, ch->info->fix.line_length);
  471. /* setup deferred io if SYS bus */
  472. tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
  473. if (ch->ldmt1r_value & (1 << 12) && tmp) {
  474. ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
  475. ch->defio.delay = msecs_to_jiffies(tmp);
  476. ch->info->fbdefio = &ch->defio;
  477. fb_deferred_io_init(ch->info);
  478. /* one-shot mode */
  479. lcdc_write_chan(ch, LDSM1R, 1);
  480. /* enable "Frame End Interrupt Enable" bit */
  481. lcdc_write(priv, _LDINTR, LDINTR_FE);
  482. } else {
  483. /* continuous read mode */
  484. lcdc_write_chan(ch, LDSM1R, 0);
  485. }
  486. }
  487. /* display output */
  488. lcdc_write(priv, _LDCNT1R, LCDC_ENABLE);
  489. /* start the lcdc */
  490. sh_mobile_lcdc_start_stop(priv, 1);
  491. priv->started = 1;
  492. /* tell the board code to enable the panel */
  493. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  494. ch = &priv->ch[k];
  495. if (!ch->enabled)
  496. continue;
  497. board_cfg = &ch->cfg.board_cfg;
  498. if (board_cfg->display_on)
  499. board_cfg->display_on(board_cfg->board_data);
  500. }
  501. return 0;
  502. }
  503. static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
  504. {
  505. struct sh_mobile_lcdc_chan *ch;
  506. struct sh_mobile_lcdc_board_cfg *board_cfg;
  507. int k;
  508. /* clean up deferred io and ask board code to disable panel */
  509. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  510. ch = &priv->ch[k];
  511. if (!ch->enabled)
  512. continue;
  513. /* deferred io mode:
  514. * flush frame, and wait for frame end interrupt
  515. * clean up deferred io and enable clock
  516. */
  517. if (ch->info->fbdefio) {
  518. ch->frame_end = 0;
  519. schedule_delayed_work(&ch->info->deferred_work, 0);
  520. wait_event(ch->frame_end_wait, ch->frame_end);
  521. fb_deferred_io_cleanup(ch->info);
  522. ch->info->fbdefio = NULL;
  523. sh_mobile_lcdc_clk_on(priv);
  524. }
  525. board_cfg = &ch->cfg.board_cfg;
  526. if (board_cfg->display_off)
  527. board_cfg->display_off(board_cfg->board_data);
  528. }
  529. /* stop the lcdc */
  530. if (priv->started) {
  531. sh_mobile_lcdc_start_stop(priv, 0);
  532. priv->started = 0;
  533. }
  534. /* stop clocks */
  535. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  536. if (priv->ch[k].enabled)
  537. sh_mobile_lcdc_clk_off(priv);
  538. }
  539. static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
  540. {
  541. int ifm, miftyp;
  542. switch (ch->cfg.interface_type) {
  543. case RGB8: ifm = 0; miftyp = 0; break;
  544. case RGB9: ifm = 0; miftyp = 4; break;
  545. case RGB12A: ifm = 0; miftyp = 5; break;
  546. case RGB12B: ifm = 0; miftyp = 6; break;
  547. case RGB16: ifm = 0; miftyp = 7; break;
  548. case RGB18: ifm = 0; miftyp = 10; break;
  549. case RGB24: ifm = 0; miftyp = 11; break;
  550. case SYS8A: ifm = 1; miftyp = 0; break;
  551. case SYS8B: ifm = 1; miftyp = 1; break;
  552. case SYS8C: ifm = 1; miftyp = 2; break;
  553. case SYS8D: ifm = 1; miftyp = 3; break;
  554. case SYS9: ifm = 1; miftyp = 4; break;
  555. case SYS12: ifm = 1; miftyp = 5; break;
  556. case SYS16A: ifm = 1; miftyp = 7; break;
  557. case SYS16B: ifm = 1; miftyp = 8; break;
  558. case SYS16C: ifm = 1; miftyp = 9; break;
  559. case SYS18: ifm = 1; miftyp = 10; break;
  560. case SYS24: ifm = 1; miftyp = 11; break;
  561. default: goto bad;
  562. }
  563. /* SUBLCD only supports SYS interface */
  564. if (lcdc_chan_is_sublcd(ch)) {
  565. if (ifm == 0)
  566. goto bad;
  567. else
  568. ifm = 0;
  569. }
  570. ch->ldmt1r_value = (ifm << 12) | miftyp;
  571. return 0;
  572. bad:
  573. return -EINVAL;
  574. }
  575. static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
  576. int clock_source,
  577. struct sh_mobile_lcdc_priv *priv)
  578. {
  579. char *str;
  580. int icksel;
  581. switch (clock_source) {
  582. case LCDC_CLK_BUS: str = "bus_clk"; icksel = 0; break;
  583. case LCDC_CLK_PERIPHERAL: str = "peripheral_clk"; icksel = 1; break;
  584. case LCDC_CLK_EXTERNAL: str = NULL; icksel = 2; break;
  585. default:
  586. return -EINVAL;
  587. }
  588. priv->lddckr = icksel << 16;
  589. if (str) {
  590. priv->dot_clk = clk_get(&pdev->dev, str);
  591. if (IS_ERR(priv->dot_clk)) {
  592. dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
  593. return PTR_ERR(priv->dot_clk);
  594. }
  595. }
  596. atomic_set(&priv->hw_usecnt, -1);
  597. /* Runtime PM support involves two step for this driver:
  598. * 1) Enable Runtime PM
  599. * 2) Force Runtime PM Resume since hardware is accessed from probe()
  600. */
  601. pm_runtime_enable(priv->dev);
  602. pm_runtime_resume(priv->dev);
  603. return 0;
  604. }
  605. static int sh_mobile_lcdc_setcolreg(u_int regno,
  606. u_int red, u_int green, u_int blue,
  607. u_int transp, struct fb_info *info)
  608. {
  609. u32 *palette = info->pseudo_palette;
  610. if (regno >= PALETTE_NR)
  611. return -EINVAL;
  612. /* only FB_VISUAL_TRUECOLOR supported */
  613. red >>= 16 - info->var.red.length;
  614. green >>= 16 - info->var.green.length;
  615. blue >>= 16 - info->var.blue.length;
  616. transp >>= 16 - info->var.transp.length;
  617. palette[regno] = (red << info->var.red.offset) |
  618. (green << info->var.green.offset) |
  619. (blue << info->var.blue.offset) |
  620. (transp << info->var.transp.offset);
  621. return 0;
  622. }
  623. static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
  624. .id = "SH Mobile LCDC",
  625. .type = FB_TYPE_PACKED_PIXELS,
  626. .visual = FB_VISUAL_TRUECOLOR,
  627. .accel = FB_ACCEL_NONE,
  628. .xpanstep = 0,
  629. .ypanstep = 1,
  630. .ywrapstep = 0,
  631. };
  632. static void sh_mobile_lcdc_fillrect(struct fb_info *info,
  633. const struct fb_fillrect *rect)
  634. {
  635. sys_fillrect(info, rect);
  636. sh_mobile_lcdc_deferred_io_touch(info);
  637. }
  638. static void sh_mobile_lcdc_copyarea(struct fb_info *info,
  639. const struct fb_copyarea *area)
  640. {
  641. sys_copyarea(info, area);
  642. sh_mobile_lcdc_deferred_io_touch(info);
  643. }
  644. static void sh_mobile_lcdc_imageblit(struct fb_info *info,
  645. const struct fb_image *image)
  646. {
  647. sys_imageblit(info, image);
  648. sh_mobile_lcdc_deferred_io_touch(info);
  649. }
  650. static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
  651. struct fb_info *info)
  652. {
  653. struct sh_mobile_lcdc_chan *ch = info->par;
  654. if (info->var.xoffset == var->xoffset &&
  655. info->var.yoffset == var->yoffset)
  656. return 0; /* No change, do nothing */
  657. ch->new_pan_offset = (var->yoffset * info->fix.line_length) +
  658. (var->xoffset * (info->var.bits_per_pixel / 8));
  659. if (ch->new_pan_offset != ch->pan_offset) {
  660. unsigned long ldintr;
  661. ldintr = lcdc_read(ch->lcdc, _LDINTR);
  662. ldintr |= LDINTR_VEE;
  663. lcdc_write(ch->lcdc, _LDINTR, ldintr);
  664. sh_mobile_lcdc_deferred_io_touch(info);
  665. }
  666. return 0;
  667. }
  668. static struct fb_ops sh_mobile_lcdc_ops = {
  669. .owner = THIS_MODULE,
  670. .fb_setcolreg = sh_mobile_lcdc_setcolreg,
  671. .fb_read = fb_sys_read,
  672. .fb_write = fb_sys_write,
  673. .fb_fillrect = sh_mobile_lcdc_fillrect,
  674. .fb_copyarea = sh_mobile_lcdc_copyarea,
  675. .fb_imageblit = sh_mobile_lcdc_imageblit,
  676. .fb_pan_display = sh_mobile_fb_pan_display,
  677. };
  678. static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
  679. {
  680. switch (bpp) {
  681. case 16: /* PKF[4:0] = 00011 - RGB 565 */
  682. var->red.offset = 11;
  683. var->red.length = 5;
  684. var->green.offset = 5;
  685. var->green.length = 6;
  686. var->blue.offset = 0;
  687. var->blue.length = 5;
  688. var->transp.offset = 0;
  689. var->transp.length = 0;
  690. break;
  691. case 32: /* PKF[4:0] = 00000 - RGB 888
  692. * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
  693. * this may be because LDDDSR has word swap enabled..
  694. */
  695. var->red.offset = 0;
  696. var->red.length = 8;
  697. var->green.offset = 24;
  698. var->green.length = 8;
  699. var->blue.offset = 16;
  700. var->blue.length = 8;
  701. var->transp.offset = 0;
  702. var->transp.length = 0;
  703. break;
  704. default:
  705. return -EINVAL;
  706. }
  707. var->bits_per_pixel = bpp;
  708. var->red.msb_right = 0;
  709. var->green.msb_right = 0;
  710. var->blue.msb_right = 0;
  711. var->transp.msb_right = 0;
  712. return 0;
  713. }
  714. static int sh_mobile_lcdc_suspend(struct device *dev)
  715. {
  716. struct platform_device *pdev = to_platform_device(dev);
  717. sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
  718. return 0;
  719. }
  720. static int sh_mobile_lcdc_resume(struct device *dev)
  721. {
  722. struct platform_device *pdev = to_platform_device(dev);
  723. return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
  724. }
  725. static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
  726. {
  727. struct platform_device *pdev = to_platform_device(dev);
  728. struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
  729. struct sh_mobile_lcdc_chan *ch;
  730. int k, n;
  731. /* save per-channel registers */
  732. for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
  733. ch = &p->ch[k];
  734. if (!ch->enabled)
  735. continue;
  736. for (n = 0; n < NR_CH_REGS; n++)
  737. ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
  738. }
  739. /* save shared registers */
  740. for (n = 0; n < NR_SHARED_REGS; n++)
  741. p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
  742. /* turn off LCDC hardware */
  743. lcdc_write(p, _LDCNT1R, 0);
  744. return 0;
  745. }
  746. static int sh_mobile_lcdc_runtime_resume(struct device *dev)
  747. {
  748. struct platform_device *pdev = to_platform_device(dev);
  749. struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
  750. struct sh_mobile_lcdc_chan *ch;
  751. int k, n;
  752. /* restore per-channel registers */
  753. for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
  754. ch = &p->ch[k];
  755. if (!ch->enabled)
  756. continue;
  757. for (n = 0; n < NR_CH_REGS; n++)
  758. lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
  759. }
  760. /* restore shared registers */
  761. for (n = 0; n < NR_SHARED_REGS; n++)
  762. lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
  763. return 0;
  764. }
  765. static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
  766. .suspend = sh_mobile_lcdc_suspend,
  767. .resume = sh_mobile_lcdc_resume,
  768. .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
  769. .runtime_resume = sh_mobile_lcdc_runtime_resume,
  770. };
  771. static int sh_mobile_lcdc_remove(struct platform_device *pdev);
  772. static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
  773. {
  774. struct fb_info *info;
  775. struct sh_mobile_lcdc_priv *priv;
  776. struct sh_mobile_lcdc_info *pdata;
  777. struct sh_mobile_lcdc_chan_cfg *cfg;
  778. struct resource *res;
  779. int error;
  780. void *buf;
  781. int i, j;
  782. if (!pdev->dev.platform_data) {
  783. dev_err(&pdev->dev, "no platform data defined\n");
  784. error = -EINVAL;
  785. goto err0;
  786. }
  787. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  788. i = platform_get_irq(pdev, 0);
  789. if (!res || i < 0) {
  790. dev_err(&pdev->dev, "cannot get platform resources\n");
  791. error = -ENOENT;
  792. goto err0;
  793. }
  794. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  795. if (!priv) {
  796. dev_err(&pdev->dev, "cannot allocate device data\n");
  797. error = -ENOMEM;
  798. goto err0;
  799. }
  800. error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
  801. dev_name(&pdev->dev), priv);
  802. if (error) {
  803. dev_err(&pdev->dev, "unable to request irq\n");
  804. goto err1;
  805. }
  806. priv->irq = i;
  807. priv->dev = &pdev->dev;
  808. platform_set_drvdata(pdev, priv);
  809. pdata = pdev->dev.platform_data;
  810. j = 0;
  811. for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
  812. priv->ch[j].lcdc = priv;
  813. memcpy(&priv->ch[j].cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
  814. error = sh_mobile_lcdc_check_interface(&priv->ch[i]);
  815. if (error) {
  816. dev_err(&pdev->dev, "unsupported interface type\n");
  817. goto err1;
  818. }
  819. init_waitqueue_head(&priv->ch[i].frame_end_wait);
  820. priv->ch[j].pan_offset = 0;
  821. priv->ch[j].new_pan_offset = 0;
  822. switch (pdata->ch[i].chan) {
  823. case LCDC_CHAN_MAINLCD:
  824. priv->ch[j].enabled = 1 << 1;
  825. priv->ch[j].reg_offs = lcdc_offs_mainlcd;
  826. j++;
  827. break;
  828. case LCDC_CHAN_SUBLCD:
  829. priv->ch[j].enabled = 1 << 2;
  830. priv->ch[j].reg_offs = lcdc_offs_sublcd;
  831. j++;
  832. break;
  833. }
  834. }
  835. if (!j) {
  836. dev_err(&pdev->dev, "no channels defined\n");
  837. error = -EINVAL;
  838. goto err1;
  839. }
  840. error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
  841. if (error) {
  842. dev_err(&pdev->dev, "unable to setup clocks\n");
  843. goto err1;
  844. }
  845. priv->base = ioremap_nocache(res->start, (res->end - res->start) + 1);
  846. for (i = 0; i < j; i++) {
  847. cfg = &priv->ch[i].cfg;
  848. priv->ch[i].info = framebuffer_alloc(0, &pdev->dev);
  849. if (!priv->ch[i].info) {
  850. dev_err(&pdev->dev, "unable to allocate fb_info\n");
  851. error = -ENOMEM;
  852. break;
  853. }
  854. info = priv->ch[i].info;
  855. info->fbops = &sh_mobile_lcdc_ops;
  856. info->var.xres = info->var.xres_virtual = cfg->lcd_cfg.xres;
  857. info->var.yres = cfg->lcd_cfg.yres;
  858. /* Default Y virtual resolution is 2x panel size */
  859. info->var.yres_virtual = info->var.yres * 2;
  860. info->var.width = cfg->lcd_size_cfg.width;
  861. info->var.height = cfg->lcd_size_cfg.height;
  862. info->var.activate = FB_ACTIVATE_NOW;
  863. error = sh_mobile_lcdc_set_bpp(&info->var, cfg->bpp);
  864. if (error)
  865. break;
  866. info->fix = sh_mobile_lcdc_fix;
  867. info->fix.line_length = cfg->lcd_cfg.xres * (cfg->bpp / 8);
  868. info->fix.smem_len = info->fix.line_length *
  869. info->var.yres_virtual;
  870. buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
  871. &priv->ch[i].dma_handle, GFP_KERNEL);
  872. if (!buf) {
  873. dev_err(&pdev->dev, "unable to allocate buffer\n");
  874. error = -ENOMEM;
  875. break;
  876. }
  877. info->pseudo_palette = &priv->ch[i].pseudo_palette;
  878. info->flags = FBINFO_FLAG_DEFAULT;
  879. error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
  880. if (error < 0) {
  881. dev_err(&pdev->dev, "unable to allocate cmap\n");
  882. dma_free_coherent(&pdev->dev, info->fix.smem_len,
  883. buf, priv->ch[i].dma_handle);
  884. break;
  885. }
  886. memset(buf, 0, info->fix.smem_len);
  887. info->fix.smem_start = priv->ch[i].dma_handle;
  888. info->screen_base = buf;
  889. info->device = &pdev->dev;
  890. info->par = &priv->ch[i];
  891. }
  892. if (error)
  893. goto err1;
  894. error = sh_mobile_lcdc_start(priv);
  895. if (error) {
  896. dev_err(&pdev->dev, "unable to start hardware\n");
  897. goto err1;
  898. }
  899. for (i = 0; i < j; i++) {
  900. struct sh_mobile_lcdc_chan *ch = priv->ch + i;
  901. info = ch->info;
  902. if (info->fbdefio) {
  903. priv->ch->sglist = vmalloc(sizeof(struct scatterlist) *
  904. info->fix.smem_len >> PAGE_SHIFT);
  905. if (!priv->ch->sglist) {
  906. dev_err(&pdev->dev, "cannot allocate sglist\n");
  907. goto err1;
  908. }
  909. }
  910. error = register_framebuffer(info);
  911. if (error < 0)
  912. goto err1;
  913. dev_info(info->dev,
  914. "registered %s/%s as %dx%d %dbpp.\n",
  915. pdev->name,
  916. (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
  917. "mainlcd" : "sublcd",
  918. (int) ch->cfg.lcd_cfg.xres,
  919. (int) ch->cfg.lcd_cfg.yres,
  920. ch->cfg.bpp);
  921. /* deferred io mode: disable clock to save power */
  922. if (info->fbdefio)
  923. sh_mobile_lcdc_clk_off(priv);
  924. }
  925. return 0;
  926. err1:
  927. sh_mobile_lcdc_remove(pdev);
  928. err0:
  929. return error;
  930. }
  931. static int sh_mobile_lcdc_remove(struct platform_device *pdev)
  932. {
  933. struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
  934. struct fb_info *info;
  935. int i;
  936. for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
  937. if (priv->ch[i].info->dev)
  938. unregister_framebuffer(priv->ch[i].info);
  939. sh_mobile_lcdc_stop(priv);
  940. for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
  941. info = priv->ch[i].info;
  942. if (!info || !info->device)
  943. continue;
  944. if (priv->ch[i].sglist)
  945. vfree(priv->ch[i].sglist);
  946. dma_free_coherent(&pdev->dev, info->fix.smem_len,
  947. info->screen_base, priv->ch[i].dma_handle);
  948. fb_dealloc_cmap(&info->cmap);
  949. framebuffer_release(info);
  950. }
  951. if (priv->dot_clk)
  952. clk_put(priv->dot_clk);
  953. pm_runtime_disable(priv->dev);
  954. if (priv->base)
  955. iounmap(priv->base);
  956. if (priv->irq)
  957. free_irq(priv->irq, priv);
  958. kfree(priv);
  959. return 0;
  960. }
  961. static struct platform_driver sh_mobile_lcdc_driver = {
  962. .driver = {
  963. .name = "sh_mobile_lcdc_fb",
  964. .owner = THIS_MODULE,
  965. .pm = &sh_mobile_lcdc_dev_pm_ops,
  966. },
  967. .probe = sh_mobile_lcdc_probe,
  968. .remove = sh_mobile_lcdc_remove,
  969. };
  970. static int __init sh_mobile_lcdc_init(void)
  971. {
  972. return platform_driver_register(&sh_mobile_lcdc_driver);
  973. }
  974. static void __exit sh_mobile_lcdc_exit(void)
  975. {
  976. platform_driver_unregister(&sh_mobile_lcdc_driver);
  977. }
  978. module_init(sh_mobile_lcdc_init);
  979. module_exit(sh_mobile_lcdc_exit);
  980. MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
  981. MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
  982. MODULE_LICENSE("GPL v2");