blizzard.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  1. /*
  2. * Epson Blizzard LCD controller driver
  3. *
  4. * Copyright (C) 2004-2005 Nokia Corporation
  5. * Authors: Juha Yrjola <juha.yrjola@nokia.com>
  6. * Imre Deak <imre.deak@nokia.com>
  7. * YUV support: Jussi Laako <jussi.laako@nokia.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/mm.h>
  25. #include <linux/fb.h>
  26. #include <linux/delay.h>
  27. #include <linux/clk.h>
  28. #include <plat/dma.h>
  29. #include <plat/blizzard.h>
  30. #include "omapfb.h"
  31. #include "dispc.h"
  32. #define MODULE_NAME "blizzard"
  33. #define BLIZZARD_REV_CODE 0x00
  34. #define BLIZZARD_CONFIG 0x02
  35. #define BLIZZARD_PLL_DIV 0x04
  36. #define BLIZZARD_PLL_LOCK_RANGE 0x06
  37. #define BLIZZARD_PLL_CLOCK_SYNTH_0 0x08
  38. #define BLIZZARD_PLL_CLOCK_SYNTH_1 0x0a
  39. #define BLIZZARD_PLL_MODE 0x0c
  40. #define BLIZZARD_CLK_SRC 0x0e
  41. #define BLIZZARD_MEM_BANK0_ACTIVATE 0x10
  42. #define BLIZZARD_MEM_BANK0_STATUS 0x14
  43. #define BLIZZARD_PANEL_CONFIGURATION 0x28
  44. #define BLIZZARD_HDISP 0x2a
  45. #define BLIZZARD_HNDP 0x2c
  46. #define BLIZZARD_VDISP0 0x2e
  47. #define BLIZZARD_VDISP1 0x30
  48. #define BLIZZARD_VNDP 0x32
  49. #define BLIZZARD_HSW 0x34
  50. #define BLIZZARD_VSW 0x38
  51. #define BLIZZARD_DISPLAY_MODE 0x68
  52. #define BLIZZARD_INPUT_WIN_X_START_0 0x6c
  53. #define BLIZZARD_DATA_SOURCE_SELECT 0x8e
  54. #define BLIZZARD_DISP_MEM_DATA_PORT 0x90
  55. #define BLIZZARD_DISP_MEM_READ_ADDR0 0x92
  56. #define BLIZZARD_POWER_SAVE 0xE6
  57. #define BLIZZARD_NDISP_CTRL_STATUS 0xE8
  58. /* Data source select */
  59. /* For S1D13745 */
  60. #define BLIZZARD_SRC_WRITE_LCD_BACKGROUND 0x00
  61. #define BLIZZARD_SRC_WRITE_LCD_DESTRUCTIVE 0x01
  62. #define BLIZZARD_SRC_WRITE_OVERLAY_ENABLE 0x04
  63. #define BLIZZARD_SRC_DISABLE_OVERLAY 0x05
  64. /* For S1D13744 */
  65. #define BLIZZARD_SRC_WRITE_LCD 0x00
  66. #define BLIZZARD_SRC_BLT_LCD 0x06
  67. #define BLIZZARD_COLOR_RGB565 0x01
  68. #define BLIZZARD_COLOR_YUV420 0x09
  69. #define BLIZZARD_VERSION_S1D13745 0x01 /* Hailstorm */
  70. #define BLIZZARD_VERSION_S1D13744 0x02 /* Blizzard */
  71. #define BLIZZARD_AUTO_UPDATE_TIME (HZ / 20)
  72. /* Reserve 4 request slots for requests in irq context */
  73. #define REQ_POOL_SIZE 24
  74. #define IRQ_REQ_POOL_SIZE 4
  75. #define REQ_FROM_IRQ_POOL 0x01
  76. #define REQ_COMPLETE 0
  77. #define REQ_PENDING 1
  78. struct blizzard_reg_list {
  79. int start;
  80. int end;
  81. };
  82. /* These need to be saved / restored separately from the rest. */
  83. static const struct blizzard_reg_list blizzard_pll_regs[] = {
  84. {
  85. .start = 0x04, /* Don't save PLL ctrl (0x0C) */
  86. .end = 0x0a,
  87. },
  88. {
  89. .start = 0x0e, /* Clock configuration */
  90. .end = 0x0e,
  91. },
  92. };
  93. static const struct blizzard_reg_list blizzard_gen_regs[] = {
  94. {
  95. .start = 0x18, /* SDRAM control */
  96. .end = 0x20,
  97. },
  98. {
  99. .start = 0x28, /* LCD Panel configuration */
  100. .end = 0x5a, /* HSSI interface, TV configuration */
  101. },
  102. };
  103. static u8 blizzard_reg_cache[0x5a / 2];
  104. struct update_param {
  105. int plane;
  106. int x, y, width, height;
  107. int out_x, out_y;
  108. int out_width, out_height;
  109. int color_mode;
  110. int bpp;
  111. int flags;
  112. };
  113. struct blizzard_request {
  114. struct list_head entry;
  115. unsigned int flags;
  116. int (*handler)(struct blizzard_request *req);
  117. void (*complete)(void *data);
  118. void *complete_data;
  119. union {
  120. struct update_param update;
  121. struct completion *sync;
  122. } par;
  123. };
  124. struct plane_info {
  125. unsigned long offset;
  126. int pos_x, pos_y;
  127. int width, height;
  128. int out_width, out_height;
  129. int scr_width;
  130. int color_mode;
  131. int bpp;
  132. };
  133. struct blizzard_struct {
  134. enum omapfb_update_mode update_mode;
  135. enum omapfb_update_mode update_mode_before_suspend;
  136. struct timer_list auto_update_timer;
  137. int stop_auto_update;
  138. struct omapfb_update_window auto_update_window;
  139. int enabled_planes;
  140. int vid_nonstd_color;
  141. int vid_scaled;
  142. int last_color_mode;
  143. int zoom_on;
  144. int zoom_area_gx1;
  145. int zoom_area_gx2;
  146. int zoom_area_gy1;
  147. int zoom_area_gy2;
  148. int screen_width;
  149. int screen_height;
  150. unsigned te_connected:1;
  151. unsigned vsync_only:1;
  152. struct plane_info plane[OMAPFB_PLANE_NUM];
  153. struct blizzard_request req_pool[REQ_POOL_SIZE];
  154. struct list_head pending_req_list;
  155. struct list_head free_req_list;
  156. struct semaphore req_sema;
  157. spinlock_t req_lock;
  158. unsigned long sys_ck_rate;
  159. struct extif_timings reg_timings, lut_timings;
  160. u32 max_transmit_size;
  161. u32 extif_clk_period;
  162. int extif_clk_div;
  163. unsigned long pix_tx_time;
  164. unsigned long line_upd_time;
  165. struct omapfb_device *fbdev;
  166. struct lcd_ctrl_extif *extif;
  167. const struct lcd_ctrl *int_ctrl;
  168. void (*power_up)(struct device *dev);
  169. void (*power_down)(struct device *dev);
  170. int version;
  171. } blizzard;
  172. struct lcd_ctrl blizzard_ctrl;
  173. static u8 blizzard_read_reg(u8 reg)
  174. {
  175. u8 data;
  176. blizzard.extif->set_bits_per_cycle(8);
  177. blizzard.extif->write_command(&reg, 1);
  178. blizzard.extif->read_data(&data, 1);
  179. return data;
  180. }
  181. static void blizzard_write_reg(u8 reg, u8 val)
  182. {
  183. blizzard.extif->set_bits_per_cycle(8);
  184. blizzard.extif->write_command(&reg, 1);
  185. blizzard.extif->write_data(&val, 1);
  186. }
  187. static void blizzard_restart_sdram(void)
  188. {
  189. unsigned long tmo;
  190. blizzard_write_reg(BLIZZARD_MEM_BANK0_ACTIVATE, 0);
  191. udelay(50);
  192. blizzard_write_reg(BLIZZARD_MEM_BANK0_ACTIVATE, 1);
  193. tmo = jiffies + msecs_to_jiffies(200);
  194. while (!(blizzard_read_reg(BLIZZARD_MEM_BANK0_STATUS) & 0x01)) {
  195. if (time_after(jiffies, tmo)) {
  196. dev_err(blizzard.fbdev->dev,
  197. "s1d1374x: SDRAM not ready\n");
  198. break;
  199. }
  200. msleep(1);
  201. }
  202. }
  203. static void blizzard_stop_sdram(void)
  204. {
  205. blizzard_write_reg(BLIZZARD_MEM_BANK0_ACTIVATE, 0);
  206. }
  207. /* Wait until the last window was completely written into the controllers
  208. * SDRAM and we can start transferring the next window.
  209. */
  210. static void blizzard_wait_line_buffer(void)
  211. {
  212. unsigned long tmo = jiffies + msecs_to_jiffies(30);
  213. while (blizzard_read_reg(BLIZZARD_NDISP_CTRL_STATUS) & (1 << 7)) {
  214. if (time_after(jiffies, tmo)) {
  215. if (printk_ratelimit())
  216. dev_err(blizzard.fbdev->dev,
  217. "s1d1374x: line buffer not ready\n");
  218. break;
  219. }
  220. }
  221. }
  222. /* Wait until the YYC color space converter is idle. */
  223. static void blizzard_wait_yyc(void)
  224. {
  225. unsigned long tmo = jiffies + msecs_to_jiffies(30);
  226. while (blizzard_read_reg(BLIZZARD_NDISP_CTRL_STATUS) & (1 << 4)) {
  227. if (time_after(jiffies, tmo)) {
  228. if (printk_ratelimit())
  229. dev_err(blizzard.fbdev->dev,
  230. "s1d1374x: YYC not ready\n");
  231. break;
  232. }
  233. }
  234. }
  235. static void disable_overlay(void)
  236. {
  237. blizzard_write_reg(BLIZZARD_DATA_SOURCE_SELECT,
  238. BLIZZARD_SRC_DISABLE_OVERLAY);
  239. }
  240. static void set_window_regs(int x_start, int y_start, int x_end, int y_end,
  241. int x_out_start, int y_out_start,
  242. int x_out_end, int y_out_end, int color_mode,
  243. int zoom_off, int flags)
  244. {
  245. u8 tmp[18];
  246. u8 cmd;
  247. x_end--;
  248. y_end--;
  249. tmp[0] = x_start;
  250. tmp[1] = x_start >> 8;
  251. tmp[2] = y_start;
  252. tmp[3] = y_start >> 8;
  253. tmp[4] = x_end;
  254. tmp[5] = x_end >> 8;
  255. tmp[6] = y_end;
  256. tmp[7] = y_end >> 8;
  257. x_out_end--;
  258. y_out_end--;
  259. tmp[8] = x_out_start;
  260. tmp[9] = x_out_start >> 8;
  261. tmp[10] = y_out_start;
  262. tmp[11] = y_out_start >> 8;
  263. tmp[12] = x_out_end;
  264. tmp[13] = x_out_end >> 8;
  265. tmp[14] = y_out_end;
  266. tmp[15] = y_out_end >> 8;
  267. tmp[16] = color_mode;
  268. if (zoom_off && blizzard.version == BLIZZARD_VERSION_S1D13745)
  269. tmp[17] = BLIZZARD_SRC_WRITE_LCD_BACKGROUND;
  270. else if (flags & OMAPFB_FORMAT_FLAG_ENABLE_OVERLAY)
  271. tmp[17] = BLIZZARD_SRC_WRITE_OVERLAY_ENABLE;
  272. else
  273. tmp[17] = blizzard.version == BLIZZARD_VERSION_S1D13744 ?
  274. BLIZZARD_SRC_WRITE_LCD :
  275. BLIZZARD_SRC_WRITE_LCD_DESTRUCTIVE;
  276. blizzard.extif->set_bits_per_cycle(8);
  277. cmd = BLIZZARD_INPUT_WIN_X_START_0;
  278. blizzard.extif->write_command(&cmd, 1);
  279. blizzard.extif->write_data(tmp, 18);
  280. }
  281. static void enable_tearsync(int y, int width, int height, int screen_height,
  282. int out_height, int force_vsync)
  283. {
  284. u8 b;
  285. b = blizzard_read_reg(BLIZZARD_NDISP_CTRL_STATUS);
  286. b |= 1 << 3;
  287. blizzard_write_reg(BLIZZARD_NDISP_CTRL_STATUS, b);
  288. if (likely(blizzard.vsync_only || force_vsync)) {
  289. blizzard.extif->enable_tearsync(1, 0);
  290. return;
  291. }
  292. if (width * blizzard.pix_tx_time < blizzard.line_upd_time) {
  293. blizzard.extif->enable_tearsync(1, 0);
  294. return;
  295. }
  296. if ((width * blizzard.pix_tx_time / 1000) * height <
  297. (y + out_height) * (blizzard.line_upd_time / 1000)) {
  298. blizzard.extif->enable_tearsync(1, 0);
  299. return;
  300. }
  301. blizzard.extif->enable_tearsync(1, y + 1);
  302. }
  303. static void disable_tearsync(void)
  304. {
  305. u8 b;
  306. blizzard.extif->enable_tearsync(0, 0);
  307. b = blizzard_read_reg(BLIZZARD_NDISP_CTRL_STATUS);
  308. b &= ~(1 << 3);
  309. blizzard_write_reg(BLIZZARD_NDISP_CTRL_STATUS, b);
  310. b = blizzard_read_reg(BLIZZARD_NDISP_CTRL_STATUS);
  311. }
  312. static inline void set_extif_timings(const struct extif_timings *t);
  313. static inline struct blizzard_request *alloc_req(void)
  314. {
  315. unsigned long flags;
  316. struct blizzard_request *req;
  317. int req_flags = 0;
  318. if (!in_interrupt())
  319. down(&blizzard.req_sema);
  320. else
  321. req_flags = REQ_FROM_IRQ_POOL;
  322. spin_lock_irqsave(&blizzard.req_lock, flags);
  323. BUG_ON(list_empty(&blizzard.free_req_list));
  324. req = list_entry(blizzard.free_req_list.next,
  325. struct blizzard_request, entry);
  326. list_del(&req->entry);
  327. spin_unlock_irqrestore(&blizzard.req_lock, flags);
  328. INIT_LIST_HEAD(&req->entry);
  329. req->flags = req_flags;
  330. return req;
  331. }
  332. static inline void free_req(struct blizzard_request *req)
  333. {
  334. unsigned long flags;
  335. spin_lock_irqsave(&blizzard.req_lock, flags);
  336. list_move(&req->entry, &blizzard.free_req_list);
  337. if (!(req->flags & REQ_FROM_IRQ_POOL))
  338. up(&blizzard.req_sema);
  339. spin_unlock_irqrestore(&blizzard.req_lock, flags);
  340. }
  341. static void process_pending_requests(void)
  342. {
  343. unsigned long flags;
  344. spin_lock_irqsave(&blizzard.req_lock, flags);
  345. while (!list_empty(&blizzard.pending_req_list)) {
  346. struct blizzard_request *req;
  347. void (*complete)(void *);
  348. void *complete_data;
  349. req = list_entry(blizzard.pending_req_list.next,
  350. struct blizzard_request, entry);
  351. spin_unlock_irqrestore(&blizzard.req_lock, flags);
  352. if (req->handler(req) == REQ_PENDING)
  353. return;
  354. complete = req->complete;
  355. complete_data = req->complete_data;
  356. free_req(req);
  357. if (complete)
  358. complete(complete_data);
  359. spin_lock_irqsave(&blizzard.req_lock, flags);
  360. }
  361. spin_unlock_irqrestore(&blizzard.req_lock, flags);
  362. }
  363. static void submit_req_list(struct list_head *head)
  364. {
  365. unsigned long flags;
  366. int process = 1;
  367. spin_lock_irqsave(&blizzard.req_lock, flags);
  368. if (likely(!list_empty(&blizzard.pending_req_list)))
  369. process = 0;
  370. list_splice_init(head, blizzard.pending_req_list.prev);
  371. spin_unlock_irqrestore(&blizzard.req_lock, flags);
  372. if (process)
  373. process_pending_requests();
  374. }
  375. static void request_complete(void *data)
  376. {
  377. struct blizzard_request *req = (struct blizzard_request *)data;
  378. void (*complete)(void *);
  379. void *complete_data;
  380. complete = req->complete;
  381. complete_data = req->complete_data;
  382. free_req(req);
  383. if (complete)
  384. complete(complete_data);
  385. process_pending_requests();
  386. }
  387. static int do_full_screen_update(struct blizzard_request *req)
  388. {
  389. int i;
  390. int flags;
  391. for (i = 0; i < 3; i++) {
  392. struct plane_info *p = &blizzard.plane[i];
  393. if (!(blizzard.enabled_planes & (1 << i))) {
  394. blizzard.int_ctrl->enable_plane(i, 0);
  395. continue;
  396. }
  397. dev_dbg(blizzard.fbdev->dev, "pw %d ph %d\n",
  398. p->width, p->height);
  399. blizzard.int_ctrl->setup_plane(i,
  400. OMAPFB_CHANNEL_OUT_LCD, p->offset,
  401. p->scr_width, p->pos_x, p->pos_y,
  402. p->width, p->height,
  403. p->color_mode);
  404. blizzard.int_ctrl->enable_plane(i, 1);
  405. }
  406. dev_dbg(blizzard.fbdev->dev, "sw %d sh %d\n",
  407. blizzard.screen_width, blizzard.screen_height);
  408. blizzard_wait_line_buffer();
  409. flags = req->par.update.flags;
  410. if (flags & OMAPFB_FORMAT_FLAG_TEARSYNC)
  411. enable_tearsync(0, blizzard.screen_width,
  412. blizzard.screen_height,
  413. blizzard.screen_height,
  414. blizzard.screen_height,
  415. flags & OMAPFB_FORMAT_FLAG_FORCE_VSYNC);
  416. else
  417. disable_tearsync();
  418. set_window_regs(0, 0, blizzard.screen_width, blizzard.screen_height,
  419. 0, 0, blizzard.screen_width, blizzard.screen_height,
  420. BLIZZARD_COLOR_RGB565, blizzard.zoom_on, flags);
  421. blizzard.zoom_on = 0;
  422. blizzard.extif->set_bits_per_cycle(16);
  423. /* set_window_regs has left the register index at the right
  424. * place, so no need to set it here.
  425. */
  426. blizzard.extif->transfer_area(blizzard.screen_width,
  427. blizzard.screen_height,
  428. request_complete, req);
  429. return REQ_PENDING;
  430. }
  431. static int check_1d_intersect(int a1, int a2, int b1, int b2)
  432. {
  433. if (a2 <= b1 || b2 <= a1)
  434. return 0;
  435. return 1;
  436. }
  437. /* Setup all planes with an overlapping area with the update window. */
  438. static int do_partial_update(struct blizzard_request *req, int plane,
  439. int x, int y, int w, int h,
  440. int x_out, int y_out, int w_out, int h_out,
  441. int wnd_color_mode, int bpp)
  442. {
  443. int i;
  444. int gx1, gy1, gx2, gy2;
  445. int gx1_out, gy1_out, gx2_out, gy2_out;
  446. int color_mode;
  447. int flags;
  448. int zoom_off;
  449. int have_zoom_for_this_update = 0;
  450. /* Global coordinates, relative to pixel 0,0 of the LCD */
  451. gx1 = x + blizzard.plane[plane].pos_x;
  452. gy1 = y + blizzard.plane[plane].pos_y;
  453. gx2 = gx1 + w;
  454. gy2 = gy1 + h;
  455. flags = req->par.update.flags;
  456. if (flags & OMAPFB_FORMAT_FLAG_DOUBLE) {
  457. gx1_out = gx1;
  458. gy1_out = gy1;
  459. gx2_out = gx1 + w * 2;
  460. gy2_out = gy1 + h * 2;
  461. } else {
  462. gx1_out = x_out + blizzard.plane[plane].pos_x;
  463. gy1_out = y_out + blizzard.plane[plane].pos_y;
  464. gx2_out = gx1_out + w_out;
  465. gy2_out = gy1_out + h_out;
  466. }
  467. for (i = 0; i < OMAPFB_PLANE_NUM; i++) {
  468. struct plane_info *p = &blizzard.plane[i];
  469. int px1, py1;
  470. int px2, py2;
  471. int pw, ph;
  472. int pposx, pposy;
  473. unsigned long offset;
  474. if (!(blizzard.enabled_planes & (1 << i)) ||
  475. (wnd_color_mode && i != plane)) {
  476. blizzard.int_ctrl->enable_plane(i, 0);
  477. continue;
  478. }
  479. /* Plane coordinates */
  480. if (i == plane) {
  481. /* Plane in which we are doing the update.
  482. * Local coordinates are the one in the update
  483. * request.
  484. */
  485. px1 = x;
  486. py1 = y;
  487. px2 = x + w;
  488. py2 = y + h;
  489. pposx = 0;
  490. pposy = 0;
  491. } else {
  492. /* Check if this plane has an overlapping part */
  493. px1 = gx1 - p->pos_x;
  494. py1 = gy1 - p->pos_y;
  495. px2 = gx2 - p->pos_x;
  496. py2 = gy2 - p->pos_y;
  497. if (px1 >= p->width || py1 >= p->height ||
  498. px2 <= 0 || py2 <= 0) {
  499. blizzard.int_ctrl->enable_plane(i, 0);
  500. continue;
  501. }
  502. /* Calculate the coordinates for the overlapping
  503. * part in the plane's local coordinates.
  504. */
  505. pposx = -px1;
  506. pposy = -py1;
  507. if (px1 < 0)
  508. px1 = 0;
  509. if (py1 < 0)
  510. py1 = 0;
  511. if (px2 > p->width)
  512. px2 = p->width;
  513. if (py2 > p->height)
  514. py2 = p->height;
  515. if (pposx < 0)
  516. pposx = 0;
  517. if (pposy < 0)
  518. pposy = 0;
  519. }
  520. pw = px2 - px1;
  521. ph = py2 - py1;
  522. offset = p->offset + (p->scr_width * py1 + px1) * p->bpp / 8;
  523. if (wnd_color_mode)
  524. /* Window embedded in the plane with a differing
  525. * color mode / bpp. Calculate the number of DMA
  526. * transfer elements in terms of the plane's bpp.
  527. */
  528. pw = (pw + 1) * bpp / p->bpp;
  529. #ifdef VERBOSE
  530. dev_dbg(blizzard.fbdev->dev,
  531. "plane %d offset %#08lx pposx %d pposy %d "
  532. "px1 %d py1 %d pw %d ph %d\n",
  533. i, offset, pposx, pposy, px1, py1, pw, ph);
  534. #endif
  535. blizzard.int_ctrl->setup_plane(i,
  536. OMAPFB_CHANNEL_OUT_LCD, offset,
  537. p->scr_width,
  538. pposx, pposy, pw, ph,
  539. p->color_mode);
  540. blizzard.int_ctrl->enable_plane(i, 1);
  541. }
  542. switch (wnd_color_mode) {
  543. case OMAPFB_COLOR_YUV420:
  544. color_mode = BLIZZARD_COLOR_YUV420;
  545. /* Currently only the 16 bits/pixel cycle format is
  546. * supported on the external interface. Adjust the number
  547. * of transfer elements per line for 12bpp format.
  548. */
  549. w = (w + 1) * 3 / 4;
  550. break;
  551. default:
  552. color_mode = BLIZZARD_COLOR_RGB565;
  553. break;
  554. }
  555. blizzard_wait_line_buffer();
  556. if (blizzard.last_color_mode == BLIZZARD_COLOR_YUV420)
  557. blizzard_wait_yyc();
  558. blizzard.last_color_mode = color_mode;
  559. if (flags & OMAPFB_FORMAT_FLAG_TEARSYNC)
  560. enable_tearsync(gy1, w, h,
  561. blizzard.screen_height,
  562. h_out,
  563. flags & OMAPFB_FORMAT_FLAG_FORCE_VSYNC);
  564. else
  565. disable_tearsync();
  566. if ((gx2_out - gx1_out) != (gx2 - gx1) ||
  567. (gy2_out - gy1_out) != (gy2 - gy1))
  568. have_zoom_for_this_update = 1;
  569. /* 'background' type of screen update (as opposed to 'destructive')
  570. can be used to disable scaling if scaling is active */
  571. zoom_off = blizzard.zoom_on && !have_zoom_for_this_update &&
  572. (gx1_out == 0) && (gx2_out == blizzard.screen_width) &&
  573. (gy1_out == 0) && (gy2_out == blizzard.screen_height) &&
  574. (gx1 == 0) && (gy1 == 0);
  575. if (blizzard.zoom_on && !have_zoom_for_this_update && !zoom_off &&
  576. check_1d_intersect(blizzard.zoom_area_gx1, blizzard.zoom_area_gx2,
  577. gx1_out, gx2_out) &&
  578. check_1d_intersect(blizzard.zoom_area_gy1, blizzard.zoom_area_gy2,
  579. gy1_out, gy2_out)) {
  580. /* Previous screen update was using scaling, current update
  581. * is not using it. Additionally, current screen update is
  582. * going to overlap with the scaled area. Scaling needs to be
  583. * disabled in order to avoid 'magnifying glass' effect.
  584. * Dummy setup of background window can be used for this.
  585. */
  586. set_window_regs(0, 0, blizzard.screen_width,
  587. blizzard.screen_height,
  588. 0, 0, blizzard.screen_width,
  589. blizzard.screen_height,
  590. BLIZZARD_COLOR_RGB565, 1, flags);
  591. blizzard.zoom_on = 0;
  592. }
  593. /* remember scaling settings if we have scaled update */
  594. if (have_zoom_for_this_update) {
  595. blizzard.zoom_on = 1;
  596. blizzard.zoom_area_gx1 = gx1_out;
  597. blizzard.zoom_area_gx2 = gx2_out;
  598. blizzard.zoom_area_gy1 = gy1_out;
  599. blizzard.zoom_area_gy2 = gy2_out;
  600. }
  601. set_window_regs(gx1, gy1, gx2, gy2, gx1_out, gy1_out, gx2_out, gy2_out,
  602. color_mode, zoom_off, flags);
  603. if (zoom_off)
  604. blizzard.zoom_on = 0;
  605. blizzard.extif->set_bits_per_cycle(16);
  606. /* set_window_regs has left the register index at the right
  607. * place, so no need to set it here.
  608. */
  609. blizzard.extif->transfer_area(w, h, request_complete, req);
  610. return REQ_PENDING;
  611. }
  612. static int send_frame_handler(struct blizzard_request *req)
  613. {
  614. struct update_param *par = &req->par.update;
  615. int plane = par->plane;
  616. #ifdef VERBOSE
  617. dev_dbg(blizzard.fbdev->dev,
  618. "send_frame: x %d y %d w %d h %d "
  619. "x_out %d y_out %d w_out %d h_out %d "
  620. "color_mode %04x flags %04x planes %01x\n",
  621. par->x, par->y, par->width, par->height,
  622. par->out_x, par->out_y, par->out_width, par->out_height,
  623. par->color_mode, par->flags, blizzard.enabled_planes);
  624. #endif
  625. if (par->flags & OMAPFB_FORMAT_FLAG_DISABLE_OVERLAY)
  626. disable_overlay();
  627. if ((blizzard.enabled_planes & blizzard.vid_nonstd_color) ||
  628. (blizzard.enabled_planes & blizzard.vid_scaled))
  629. return do_full_screen_update(req);
  630. return do_partial_update(req, plane, par->x, par->y,
  631. par->width, par->height,
  632. par->out_x, par->out_y,
  633. par->out_width, par->out_height,
  634. par->color_mode, par->bpp);
  635. }
  636. static void send_frame_complete(void *data)
  637. {
  638. }
  639. #define ADD_PREQ(_x, _y, _w, _h, _x_out, _y_out, _w_out, _h_out) do { \
  640. req = alloc_req(); \
  641. req->handler = send_frame_handler; \
  642. req->complete = send_frame_complete; \
  643. req->par.update.plane = plane_idx; \
  644. req->par.update.x = _x; \
  645. req->par.update.y = _y; \
  646. req->par.update.width = _w; \
  647. req->par.update.height = _h; \
  648. req->par.update.out_x = _x_out; \
  649. req->par.update.out_y = _y_out; \
  650. req->par.update.out_width = _w_out; \
  651. req->par.update.out_height = _h_out; \
  652. req->par.update.bpp = bpp; \
  653. req->par.update.color_mode = color_mode;\
  654. req->par.update.flags = flags; \
  655. list_add_tail(&req->entry, req_head); \
  656. } while(0)
  657. static void create_req_list(int plane_idx,
  658. struct omapfb_update_window *win,
  659. struct list_head *req_head)
  660. {
  661. struct blizzard_request *req;
  662. int x = win->x;
  663. int y = win->y;
  664. int width = win->width;
  665. int height = win->height;
  666. int x_out = win->out_x;
  667. int y_out = win->out_y;
  668. int width_out = win->out_width;
  669. int height_out = win->out_height;
  670. int color_mode;
  671. int bpp;
  672. int flags;
  673. unsigned int ystart = y;
  674. unsigned int yspan = height;
  675. unsigned int ystart_out = y_out;
  676. unsigned int yspan_out = height_out;
  677. flags = win->format & ~OMAPFB_FORMAT_MASK;
  678. color_mode = win->format & OMAPFB_FORMAT_MASK;
  679. switch (color_mode) {
  680. case OMAPFB_COLOR_YUV420:
  681. /* Embedded window with different color mode */
  682. bpp = 12;
  683. /* X, Y, height must be aligned at 2, width at 4 pixels */
  684. x &= ~1;
  685. y &= ~1;
  686. height = yspan = height & ~1;
  687. width = width & ~3;
  688. break;
  689. default:
  690. /* Same as the plane color mode */
  691. bpp = blizzard.plane[plane_idx].bpp;
  692. break;
  693. }
  694. if (width * height * bpp / 8 > blizzard.max_transmit_size) {
  695. yspan = blizzard.max_transmit_size / (width * bpp / 8);
  696. yspan_out = yspan * height_out / height;
  697. ADD_PREQ(x, ystart, width, yspan, x_out, ystart_out,
  698. width_out, yspan_out);
  699. ystart += yspan;
  700. ystart_out += yspan_out;
  701. yspan = height - yspan;
  702. yspan_out = height_out - yspan_out;
  703. flags &= ~OMAPFB_FORMAT_FLAG_TEARSYNC;
  704. }
  705. ADD_PREQ(x, ystart, width, yspan, x_out, ystart_out,
  706. width_out, yspan_out);
  707. }
  708. static void auto_update_complete(void *data)
  709. {
  710. if (!blizzard.stop_auto_update)
  711. mod_timer(&blizzard.auto_update_timer,
  712. jiffies + BLIZZARD_AUTO_UPDATE_TIME);
  713. }
  714. static void blizzard_update_window_auto(unsigned long arg)
  715. {
  716. LIST_HEAD(req_list);
  717. struct blizzard_request *last;
  718. struct omapfb_plane_struct *plane;
  719. plane = blizzard.fbdev->fb_info[0]->par;
  720. create_req_list(plane->idx,
  721. &blizzard.auto_update_window, &req_list);
  722. last = list_entry(req_list.prev, struct blizzard_request, entry);
  723. last->complete = auto_update_complete;
  724. last->complete_data = NULL;
  725. submit_req_list(&req_list);
  726. }
  727. int blizzard_update_window_async(struct fb_info *fbi,
  728. struct omapfb_update_window *win,
  729. void (*complete_callback)(void *arg),
  730. void *complete_callback_data)
  731. {
  732. LIST_HEAD(req_list);
  733. struct blizzard_request *last;
  734. struct omapfb_plane_struct *plane = fbi->par;
  735. if (unlikely(blizzard.update_mode != OMAPFB_MANUAL_UPDATE))
  736. return -EINVAL;
  737. if (unlikely(!blizzard.te_connected &&
  738. (win->format & OMAPFB_FORMAT_FLAG_TEARSYNC)))
  739. return -EINVAL;
  740. create_req_list(plane->idx, win, &req_list);
  741. last = list_entry(req_list.prev, struct blizzard_request, entry);
  742. last->complete = complete_callback;
  743. last->complete_data = (void *)complete_callback_data;
  744. submit_req_list(&req_list);
  745. return 0;
  746. }
  747. EXPORT_SYMBOL(blizzard_update_window_async);
  748. static int update_full_screen(void)
  749. {
  750. return blizzard_update_window_async(blizzard.fbdev->fb_info[0],
  751. &blizzard.auto_update_window, NULL, NULL);
  752. }
  753. static int blizzard_setup_plane(int plane, int channel_out,
  754. unsigned long offset, int screen_width,
  755. int pos_x, int pos_y, int width, int height,
  756. int color_mode)
  757. {
  758. struct plane_info *p;
  759. #ifdef VERBOSE
  760. dev_dbg(blizzard.fbdev->dev,
  761. "plane %d ch_out %d offset %#08lx scr_width %d "
  762. "pos_x %d pos_y %d width %d height %d color_mode %d\n",
  763. plane, channel_out, offset, screen_width,
  764. pos_x, pos_y, width, height, color_mode);
  765. #endif
  766. if ((unsigned)plane > OMAPFB_PLANE_NUM)
  767. return -EINVAL;
  768. p = &blizzard.plane[plane];
  769. switch (color_mode) {
  770. case OMAPFB_COLOR_YUV422:
  771. case OMAPFB_COLOR_YUY422:
  772. p->bpp = 16;
  773. blizzard.vid_nonstd_color &= ~(1 << plane);
  774. break;
  775. case OMAPFB_COLOR_YUV420:
  776. p->bpp = 12;
  777. blizzard.vid_nonstd_color |= 1 << plane;
  778. break;
  779. case OMAPFB_COLOR_RGB565:
  780. p->bpp = 16;
  781. blizzard.vid_nonstd_color &= ~(1 << plane);
  782. break;
  783. default:
  784. return -EINVAL;
  785. }
  786. p->offset = offset;
  787. p->pos_x = pos_x;
  788. p->pos_y = pos_y;
  789. p->width = width;
  790. p->height = height;
  791. p->scr_width = screen_width;
  792. if (!p->out_width)
  793. p->out_width = width;
  794. if (!p->out_height)
  795. p->out_height = height;
  796. p->color_mode = color_mode;
  797. return 0;
  798. }
  799. static int blizzard_set_scale(int plane, int orig_w, int orig_h,
  800. int out_w, int out_h)
  801. {
  802. struct plane_info *p = &blizzard.plane[plane];
  803. int r;
  804. dev_dbg(blizzard.fbdev->dev,
  805. "plane %d orig_w %d orig_h %d out_w %d out_h %d\n",
  806. plane, orig_w, orig_h, out_w, out_h);
  807. if ((unsigned)plane > OMAPFB_PLANE_NUM)
  808. return -ENODEV;
  809. r = blizzard.int_ctrl->set_scale(plane, orig_w, orig_h, out_w, out_h);
  810. if (r < 0)
  811. return r;
  812. p->width = orig_w;
  813. p->height = orig_h;
  814. p->out_width = out_w;
  815. p->out_height = out_h;
  816. if (orig_w == out_w && orig_h == out_h)
  817. blizzard.vid_scaled &= ~(1 << plane);
  818. else
  819. blizzard.vid_scaled |= 1 << plane;
  820. return 0;
  821. }
  822. static int blizzard_set_rotate(int angle)
  823. {
  824. u32 l;
  825. l = blizzard_read_reg(BLIZZARD_PANEL_CONFIGURATION);
  826. l &= ~0x03;
  827. switch (angle) {
  828. case 0:
  829. l = l | 0x00;
  830. break;
  831. case 90:
  832. l = l | 0x03;
  833. break;
  834. case 180:
  835. l = l | 0x02;
  836. break;
  837. case 270:
  838. l = l | 0x01;
  839. break;
  840. default:
  841. return -EINVAL;
  842. }
  843. blizzard_write_reg(BLIZZARD_PANEL_CONFIGURATION, l);
  844. return 0;
  845. }
  846. static int blizzard_enable_plane(int plane, int enable)
  847. {
  848. if (enable)
  849. blizzard.enabled_planes |= 1 << plane;
  850. else
  851. blizzard.enabled_planes &= ~(1 << plane);
  852. return 0;
  853. }
  854. static int sync_handler(struct blizzard_request *req)
  855. {
  856. complete(req->par.sync);
  857. return REQ_COMPLETE;
  858. }
  859. static void blizzard_sync(void)
  860. {
  861. LIST_HEAD(req_list);
  862. struct blizzard_request *req;
  863. struct completion comp;
  864. req = alloc_req();
  865. req->handler = sync_handler;
  866. req->complete = NULL;
  867. init_completion(&comp);
  868. req->par.sync = &comp;
  869. list_add(&req->entry, &req_list);
  870. submit_req_list(&req_list);
  871. wait_for_completion(&comp);
  872. }
  873. static void blizzard_bind_client(struct omapfb_notifier_block *nb)
  874. {
  875. if (blizzard.update_mode == OMAPFB_MANUAL_UPDATE) {
  876. omapfb_notify_clients(blizzard.fbdev, OMAPFB_EVENT_READY);
  877. }
  878. }
  879. static int blizzard_set_update_mode(enum omapfb_update_mode mode)
  880. {
  881. if (unlikely(mode != OMAPFB_MANUAL_UPDATE &&
  882. mode != OMAPFB_AUTO_UPDATE &&
  883. mode != OMAPFB_UPDATE_DISABLED))
  884. return -EINVAL;
  885. if (mode == blizzard.update_mode)
  886. return 0;
  887. dev_info(blizzard.fbdev->dev, "s1d1374x: setting update mode to %s\n",
  888. mode == OMAPFB_UPDATE_DISABLED ? "disabled" :
  889. (mode == OMAPFB_AUTO_UPDATE ? "auto" : "manual"));
  890. switch (blizzard.update_mode) {
  891. case OMAPFB_MANUAL_UPDATE:
  892. omapfb_notify_clients(blizzard.fbdev, OMAPFB_EVENT_DISABLED);
  893. break;
  894. case OMAPFB_AUTO_UPDATE:
  895. blizzard.stop_auto_update = 1;
  896. del_timer_sync(&blizzard.auto_update_timer);
  897. break;
  898. case OMAPFB_UPDATE_DISABLED:
  899. break;
  900. }
  901. blizzard.update_mode = mode;
  902. blizzard_sync();
  903. blizzard.stop_auto_update = 0;
  904. switch (mode) {
  905. case OMAPFB_MANUAL_UPDATE:
  906. omapfb_notify_clients(blizzard.fbdev, OMAPFB_EVENT_READY);
  907. break;
  908. case OMAPFB_AUTO_UPDATE:
  909. blizzard_update_window_auto(0);
  910. break;
  911. case OMAPFB_UPDATE_DISABLED:
  912. break;
  913. }
  914. return 0;
  915. }
  916. static enum omapfb_update_mode blizzard_get_update_mode(void)
  917. {
  918. return blizzard.update_mode;
  919. }
  920. static inline void set_extif_timings(const struct extif_timings *t)
  921. {
  922. blizzard.extif->set_timings(t);
  923. }
  924. static inline unsigned long round_to_extif_ticks(unsigned long ps, int div)
  925. {
  926. int bus_tick = blizzard.extif_clk_period * div;
  927. return (ps + bus_tick - 1) / bus_tick * bus_tick;
  928. }
  929. static int calc_reg_timing(unsigned long sysclk, int div)
  930. {
  931. struct extif_timings *t;
  932. unsigned long systim;
  933. /* CSOnTime 0, WEOnTime 2 ns, REOnTime 2 ns,
  934. * AccessTime 2 ns + 12.2 ns (regs),
  935. * WEOffTime = WEOnTime + 1 ns,
  936. * REOffTime = REOnTime + 12 ns (regs),
  937. * CSOffTime = REOffTime + 1 ns
  938. * ReadCycle = 2ns + 2*SYSCLK (regs),
  939. * WriteCycle = 2*SYSCLK + 2 ns,
  940. * CSPulseWidth = 10 ns */
  941. systim = 1000000000 / (sysclk / 1000);
  942. dev_dbg(blizzard.fbdev->dev,
  943. "Blizzard systim %lu ps extif_clk_period %u div %d\n",
  944. systim, blizzard.extif_clk_period, div);
  945. t = &blizzard.reg_timings;
  946. memset(t, 0, sizeof(*t));
  947. t->clk_div = div;
  948. t->cs_on_time = 0;
  949. t->we_on_time = round_to_extif_ticks(t->cs_on_time + 2000, div);
  950. t->re_on_time = round_to_extif_ticks(t->cs_on_time + 2000, div);
  951. t->access_time = round_to_extif_ticks(t->re_on_time + 12200, div);
  952. t->we_off_time = round_to_extif_ticks(t->we_on_time + 1000, div);
  953. t->re_off_time = round_to_extif_ticks(t->re_on_time + 13000, div);
  954. t->cs_off_time = round_to_extif_ticks(t->re_off_time + 1000, div);
  955. t->we_cycle_time = round_to_extif_ticks(2 * systim + 2000, div);
  956. if (t->we_cycle_time < t->we_off_time)
  957. t->we_cycle_time = t->we_off_time;
  958. t->re_cycle_time = round_to_extif_ticks(2 * systim + 2000, div);
  959. if (t->re_cycle_time < t->re_off_time)
  960. t->re_cycle_time = t->re_off_time;
  961. t->cs_pulse_width = 0;
  962. dev_dbg(blizzard.fbdev->dev, "[reg]cson %d csoff %d reon %d reoff %d\n",
  963. t->cs_on_time, t->cs_off_time, t->re_on_time, t->re_off_time);
  964. dev_dbg(blizzard.fbdev->dev, "[reg]weon %d weoff %d recyc %d wecyc %d\n",
  965. t->we_on_time, t->we_off_time, t->re_cycle_time,
  966. t->we_cycle_time);
  967. dev_dbg(blizzard.fbdev->dev, "[reg]rdaccess %d cspulse %d\n",
  968. t->access_time, t->cs_pulse_width);
  969. return blizzard.extif->convert_timings(t);
  970. }
  971. static int calc_lut_timing(unsigned long sysclk, int div)
  972. {
  973. struct extif_timings *t;
  974. unsigned long systim;
  975. /* CSOnTime 0, WEOnTime 2 ns, REOnTime 2 ns,
  976. * AccessTime 2 ns + 4 * SYSCLK + 26 (lut),
  977. * WEOffTime = WEOnTime + 1 ns,
  978. * REOffTime = REOnTime + 4*SYSCLK + 26 ns (lut),
  979. * CSOffTime = REOffTime + 1 ns
  980. * ReadCycle = 2ns + 4*SYSCLK + 26 ns (lut),
  981. * WriteCycle = 2*SYSCLK + 2 ns,
  982. * CSPulseWidth = 10 ns */
  983. systim = 1000000000 / (sysclk / 1000);
  984. dev_dbg(blizzard.fbdev->dev,
  985. "Blizzard systim %lu ps extif_clk_period %u div %d\n",
  986. systim, blizzard.extif_clk_period, div);
  987. t = &blizzard.lut_timings;
  988. memset(t, 0, sizeof(*t));
  989. t->clk_div = div;
  990. t->cs_on_time = 0;
  991. t->we_on_time = round_to_extif_ticks(t->cs_on_time + 2000, div);
  992. t->re_on_time = round_to_extif_ticks(t->cs_on_time + 2000, div);
  993. t->access_time = round_to_extif_ticks(t->re_on_time + 4 * systim +
  994. 26000, div);
  995. t->we_off_time = round_to_extif_ticks(t->we_on_time + 1000, div);
  996. t->re_off_time = round_to_extif_ticks(t->re_on_time + 4 * systim +
  997. 26000, div);
  998. t->cs_off_time = round_to_extif_ticks(t->re_off_time + 1000, div);
  999. t->we_cycle_time = round_to_extif_ticks(2 * systim + 2000, div);
  1000. if (t->we_cycle_time < t->we_off_time)
  1001. t->we_cycle_time = t->we_off_time;
  1002. t->re_cycle_time = round_to_extif_ticks(2000 + 4 * systim + 26000, div);
  1003. if (t->re_cycle_time < t->re_off_time)
  1004. t->re_cycle_time = t->re_off_time;
  1005. t->cs_pulse_width = 0;
  1006. dev_dbg(blizzard.fbdev->dev,
  1007. "[lut]cson %d csoff %d reon %d reoff %d\n",
  1008. t->cs_on_time, t->cs_off_time, t->re_on_time, t->re_off_time);
  1009. dev_dbg(blizzard.fbdev->dev,
  1010. "[lut]weon %d weoff %d recyc %d wecyc %d\n",
  1011. t->we_on_time, t->we_off_time, t->re_cycle_time,
  1012. t->we_cycle_time);
  1013. dev_dbg(blizzard.fbdev->dev, "[lut]rdaccess %d cspulse %d\n",
  1014. t->access_time, t->cs_pulse_width);
  1015. return blizzard.extif->convert_timings(t);
  1016. }
  1017. static int calc_extif_timings(unsigned long sysclk, int *extif_mem_div)
  1018. {
  1019. int max_clk_div;
  1020. int div;
  1021. blizzard.extif->get_clk_info(&blizzard.extif_clk_period, &max_clk_div);
  1022. for (div = 1; div <= max_clk_div; div++) {
  1023. if (calc_reg_timing(sysclk, div) == 0)
  1024. break;
  1025. }
  1026. if (div > max_clk_div) {
  1027. dev_dbg(blizzard.fbdev->dev, "reg timing failed\n");
  1028. goto err;
  1029. }
  1030. *extif_mem_div = div;
  1031. for (div = 1; div <= max_clk_div; div++) {
  1032. if (calc_lut_timing(sysclk, div) == 0)
  1033. break;
  1034. }
  1035. if (div > max_clk_div)
  1036. goto err;
  1037. blizzard.extif_clk_div = div;
  1038. return 0;
  1039. err:
  1040. dev_err(blizzard.fbdev->dev, "can't setup timings\n");
  1041. return -1;
  1042. }
  1043. static void calc_blizzard_clk_rates(unsigned long ext_clk,
  1044. unsigned long *sys_clk, unsigned long *pix_clk)
  1045. {
  1046. int pix_clk_src;
  1047. int sys_div = 0, sys_mul = 0;
  1048. int pix_div;
  1049. pix_clk_src = blizzard_read_reg(BLIZZARD_CLK_SRC);
  1050. pix_div = ((pix_clk_src >> 3) & 0x1f) + 1;
  1051. if ((pix_clk_src & (0x3 << 1)) == 0) {
  1052. /* Source is the PLL */
  1053. sys_div = (blizzard_read_reg(BLIZZARD_PLL_DIV) & 0x3f) + 1;
  1054. sys_mul = blizzard_read_reg(BLIZZARD_PLL_CLOCK_SYNTH_0);
  1055. sys_mul |= ((blizzard_read_reg(BLIZZARD_PLL_CLOCK_SYNTH_1)
  1056. & 0x0f) << 11);
  1057. *sys_clk = ext_clk * sys_mul / sys_div;
  1058. } else /* else source is ext clk, or oscillator */
  1059. *sys_clk = ext_clk;
  1060. *pix_clk = *sys_clk / pix_div; /* HZ */
  1061. dev_dbg(blizzard.fbdev->dev,
  1062. "ext_clk %ld pix_src %d pix_div %d sys_div %d sys_mul %d\n",
  1063. ext_clk, pix_clk_src & (0x3 << 1), pix_div, sys_div, sys_mul);
  1064. dev_dbg(blizzard.fbdev->dev, "sys_clk %ld pix_clk %ld\n",
  1065. *sys_clk, *pix_clk);
  1066. }
  1067. static int setup_tearsync(unsigned long pix_clk, int extif_div)
  1068. {
  1069. int hdisp, vdisp;
  1070. int hndp, vndp;
  1071. int hsw, vsw;
  1072. int hs, vs;
  1073. int hs_pol_inv, vs_pol_inv;
  1074. int use_hsvs, use_ndp;
  1075. u8 b;
  1076. hsw = blizzard_read_reg(BLIZZARD_HSW);
  1077. vsw = blizzard_read_reg(BLIZZARD_VSW);
  1078. hs_pol_inv = !(hsw & 0x80);
  1079. vs_pol_inv = !(vsw & 0x80);
  1080. hsw = hsw & 0x7f;
  1081. vsw = vsw & 0x3f;
  1082. hdisp = blizzard_read_reg(BLIZZARD_HDISP) * 8;
  1083. vdisp = blizzard_read_reg(BLIZZARD_VDISP0) +
  1084. ((blizzard_read_reg(BLIZZARD_VDISP1) & 0x3) << 8);
  1085. hndp = blizzard_read_reg(BLIZZARD_HNDP) & 0x3f;
  1086. vndp = blizzard_read_reg(BLIZZARD_VNDP);
  1087. /* time to transfer one pixel (16bpp) in ps */
  1088. blizzard.pix_tx_time = blizzard.reg_timings.we_cycle_time;
  1089. if (blizzard.extif->get_max_tx_rate != NULL) {
  1090. /* The external interface might have a rate limitation,
  1091. * if so, we have to maximize our transfer rate.
  1092. */
  1093. unsigned long min_tx_time;
  1094. unsigned long max_tx_rate = blizzard.extif->get_max_tx_rate();
  1095. dev_dbg(blizzard.fbdev->dev, "max_tx_rate %ld HZ\n",
  1096. max_tx_rate);
  1097. min_tx_time = 1000000000 / (max_tx_rate / 1000); /* ps */
  1098. if (blizzard.pix_tx_time < min_tx_time)
  1099. blizzard.pix_tx_time = min_tx_time;
  1100. }
  1101. /* time to update one line in ps */
  1102. blizzard.line_upd_time = (hdisp + hndp) * 1000000 / (pix_clk / 1000);
  1103. blizzard.line_upd_time *= 1000;
  1104. if (hdisp * blizzard.pix_tx_time > blizzard.line_upd_time)
  1105. /* transfer speed too low, we might have to use both
  1106. * HS and VS */
  1107. use_hsvs = 1;
  1108. else
  1109. /* decent transfer speed, we'll always use only VS */
  1110. use_hsvs = 0;
  1111. if (use_hsvs && (hs_pol_inv || vs_pol_inv)) {
  1112. /* HS or'ed with VS doesn't work, use the active high
  1113. * TE signal based on HNDP / VNDP */
  1114. use_ndp = 1;
  1115. hs_pol_inv = 0;
  1116. vs_pol_inv = 0;
  1117. hs = hndp;
  1118. vs = vndp;
  1119. } else {
  1120. /* Use HS or'ed with VS as a TE signal if both are needed
  1121. * or VNDP if only vsync is needed. */
  1122. use_ndp = 0;
  1123. hs = hsw;
  1124. vs = vsw;
  1125. if (!use_hsvs) {
  1126. hs_pol_inv = 0;
  1127. vs_pol_inv = 0;
  1128. }
  1129. }
  1130. hs = hs * 1000000 / (pix_clk / 1000); /* ps */
  1131. hs *= 1000;
  1132. vs = vs * (hdisp + hndp) * 1000000 / (pix_clk / 1000); /* ps */
  1133. vs *= 1000;
  1134. if (vs <= hs)
  1135. return -EDOM;
  1136. /* set VS to 120% of HS to minimize VS detection time */
  1137. vs = hs * 12 / 10;
  1138. /* minimize HS too */
  1139. if (hs > 10000)
  1140. hs = 10000;
  1141. b = blizzard_read_reg(BLIZZARD_NDISP_CTRL_STATUS);
  1142. b &= ~0x3;
  1143. b |= use_hsvs ? 1 : 0;
  1144. b |= (use_ndp && use_hsvs) ? 0 : 2;
  1145. blizzard_write_reg(BLIZZARD_NDISP_CTRL_STATUS, b);
  1146. blizzard.vsync_only = !use_hsvs;
  1147. dev_dbg(blizzard.fbdev->dev,
  1148. "pix_clk %ld HZ pix_tx_time %ld ps line_upd_time %ld ps\n",
  1149. pix_clk, blizzard.pix_tx_time, blizzard.line_upd_time);
  1150. dev_dbg(blizzard.fbdev->dev,
  1151. "hs %d ps vs %d ps mode %d vsync_only %d\n",
  1152. hs, vs, b & 0x3, !use_hsvs);
  1153. return blizzard.extif->setup_tearsync(1, hs, vs,
  1154. hs_pol_inv, vs_pol_inv,
  1155. extif_div);
  1156. }
  1157. static void blizzard_get_caps(int plane, struct omapfb_caps *caps)
  1158. {
  1159. blizzard.int_ctrl->get_caps(plane, caps);
  1160. caps->ctrl |= OMAPFB_CAPS_MANUAL_UPDATE |
  1161. OMAPFB_CAPS_WINDOW_PIXEL_DOUBLE |
  1162. OMAPFB_CAPS_WINDOW_SCALE |
  1163. OMAPFB_CAPS_WINDOW_OVERLAY |
  1164. OMAPFB_CAPS_WINDOW_ROTATE;
  1165. if (blizzard.te_connected)
  1166. caps->ctrl |= OMAPFB_CAPS_TEARSYNC;
  1167. caps->wnd_color |= (1 << OMAPFB_COLOR_RGB565) |
  1168. (1 << OMAPFB_COLOR_YUV420);
  1169. }
  1170. static void _save_regs(const struct blizzard_reg_list *list, int cnt)
  1171. {
  1172. int i;
  1173. for (i = 0; i < cnt; i++, list++) {
  1174. int reg;
  1175. for (reg = list->start; reg <= list->end; reg += 2)
  1176. blizzard_reg_cache[reg / 2] = blizzard_read_reg(reg);
  1177. }
  1178. }
  1179. static void _restore_regs(const struct blizzard_reg_list *list, int cnt)
  1180. {
  1181. int i;
  1182. for (i = 0; i < cnt; i++, list++) {
  1183. int reg;
  1184. for (reg = list->start; reg <= list->end; reg += 2)
  1185. blizzard_write_reg(reg, blizzard_reg_cache[reg / 2]);
  1186. }
  1187. }
  1188. static void blizzard_save_all_regs(void)
  1189. {
  1190. _save_regs(blizzard_pll_regs, ARRAY_SIZE(blizzard_pll_regs));
  1191. _save_regs(blizzard_gen_regs, ARRAY_SIZE(blizzard_gen_regs));
  1192. }
  1193. static void blizzard_restore_pll_regs(void)
  1194. {
  1195. _restore_regs(blizzard_pll_regs, ARRAY_SIZE(blizzard_pll_regs));
  1196. }
  1197. static void blizzard_restore_gen_regs(void)
  1198. {
  1199. _restore_regs(blizzard_gen_regs, ARRAY_SIZE(blizzard_gen_regs));
  1200. }
  1201. static void blizzard_suspend(void)
  1202. {
  1203. u32 l;
  1204. unsigned long tmo;
  1205. if (blizzard.last_color_mode) {
  1206. update_full_screen();
  1207. blizzard_sync();
  1208. }
  1209. blizzard.update_mode_before_suspend = blizzard.update_mode;
  1210. /* the following will disable clocks as well */
  1211. blizzard_set_update_mode(OMAPFB_UPDATE_DISABLED);
  1212. blizzard_save_all_regs();
  1213. blizzard_stop_sdram();
  1214. l = blizzard_read_reg(BLIZZARD_POWER_SAVE);
  1215. /* Standby, Sleep. We assume we use an external clock. */
  1216. l |= 0x03;
  1217. blizzard_write_reg(BLIZZARD_POWER_SAVE, l);
  1218. tmo = jiffies + msecs_to_jiffies(100);
  1219. while (!(blizzard_read_reg(BLIZZARD_PLL_MODE) & (1 << 1))) {
  1220. if (time_after(jiffies, tmo)) {
  1221. dev_err(blizzard.fbdev->dev,
  1222. "s1d1374x: sleep timeout, stopping PLL manually\n");
  1223. l = blizzard_read_reg(BLIZZARD_PLL_MODE);
  1224. l &= ~0x03;
  1225. /* Disable PLL, counter function */
  1226. l |= 0x2;
  1227. blizzard_write_reg(BLIZZARD_PLL_MODE, l);
  1228. break;
  1229. }
  1230. msleep(1);
  1231. }
  1232. if (blizzard.power_down != NULL)
  1233. blizzard.power_down(blizzard.fbdev->dev);
  1234. }
  1235. static void blizzard_resume(void)
  1236. {
  1237. u32 l;
  1238. if (blizzard.power_up != NULL)
  1239. blizzard.power_up(blizzard.fbdev->dev);
  1240. l = blizzard_read_reg(BLIZZARD_POWER_SAVE);
  1241. /* Standby, Sleep */
  1242. l &= ~0x03;
  1243. blizzard_write_reg(BLIZZARD_POWER_SAVE, l);
  1244. blizzard_restore_pll_regs();
  1245. l = blizzard_read_reg(BLIZZARD_PLL_MODE);
  1246. l &= ~0x03;
  1247. /* Enable PLL, counter function */
  1248. l |= 0x1;
  1249. blizzard_write_reg(BLIZZARD_PLL_MODE, l);
  1250. while (!(blizzard_read_reg(BLIZZARD_PLL_DIV) & (1 << 7)))
  1251. msleep(1);
  1252. blizzard_restart_sdram();
  1253. blizzard_restore_gen_regs();
  1254. /* Enable display */
  1255. blizzard_write_reg(BLIZZARD_DISPLAY_MODE, 0x01);
  1256. /* the following will enable clocks as necessary */
  1257. blizzard_set_update_mode(blizzard.update_mode_before_suspend);
  1258. /* Force a background update */
  1259. blizzard.zoom_on = 1;
  1260. update_full_screen();
  1261. blizzard_sync();
  1262. }
  1263. static int blizzard_init(struct omapfb_device *fbdev, int ext_mode,
  1264. struct omapfb_mem_desc *req_vram)
  1265. {
  1266. int r = 0, i;
  1267. u8 rev, conf;
  1268. unsigned long ext_clk;
  1269. int extif_div;
  1270. unsigned long sys_clk, pix_clk;
  1271. struct omapfb_platform_data *omapfb_conf;
  1272. struct blizzard_platform_data *ctrl_conf;
  1273. blizzard.fbdev = fbdev;
  1274. BUG_ON(!fbdev->ext_if || !fbdev->int_ctrl);
  1275. blizzard.fbdev = fbdev;
  1276. blizzard.extif = fbdev->ext_if;
  1277. blizzard.int_ctrl = fbdev->int_ctrl;
  1278. omapfb_conf = fbdev->dev->platform_data;
  1279. ctrl_conf = omapfb_conf->ctrl_platform_data;
  1280. if (ctrl_conf == NULL || ctrl_conf->get_clock_rate == NULL) {
  1281. dev_err(fbdev->dev, "s1d1374x: missing platform data\n");
  1282. r = -ENOENT;
  1283. goto err1;
  1284. }
  1285. blizzard.power_down = ctrl_conf->power_down;
  1286. blizzard.power_up = ctrl_conf->power_up;
  1287. spin_lock_init(&blizzard.req_lock);
  1288. if ((r = blizzard.int_ctrl->init(fbdev, 1, req_vram)) < 0)
  1289. goto err1;
  1290. if ((r = blizzard.extif->init(fbdev)) < 0)
  1291. goto err2;
  1292. blizzard_ctrl.set_color_key = blizzard.int_ctrl->set_color_key;
  1293. blizzard_ctrl.get_color_key = blizzard.int_ctrl->get_color_key;
  1294. blizzard_ctrl.setup_mem = blizzard.int_ctrl->setup_mem;
  1295. blizzard_ctrl.mmap = blizzard.int_ctrl->mmap;
  1296. ext_clk = ctrl_conf->get_clock_rate(fbdev->dev);
  1297. if ((r = calc_extif_timings(ext_clk, &extif_div)) < 0)
  1298. goto err3;
  1299. set_extif_timings(&blizzard.reg_timings);
  1300. if (blizzard.power_up != NULL)
  1301. blizzard.power_up(fbdev->dev);
  1302. calc_blizzard_clk_rates(ext_clk, &sys_clk, &pix_clk);
  1303. if ((r = calc_extif_timings(sys_clk, &extif_div)) < 0)
  1304. goto err3;
  1305. set_extif_timings(&blizzard.reg_timings);
  1306. if (!(blizzard_read_reg(BLIZZARD_PLL_DIV) & 0x80)) {
  1307. dev_err(fbdev->dev,
  1308. "controller not initialized by the bootloader\n");
  1309. r = -ENODEV;
  1310. goto err3;
  1311. }
  1312. if (ctrl_conf->te_connected) {
  1313. if ((r = setup_tearsync(pix_clk, extif_div)) < 0)
  1314. goto err3;
  1315. blizzard.te_connected = 1;
  1316. }
  1317. rev = blizzard_read_reg(BLIZZARD_REV_CODE);
  1318. conf = blizzard_read_reg(BLIZZARD_CONFIG);
  1319. switch (rev & 0xfc) {
  1320. case 0x9c:
  1321. blizzard.version = BLIZZARD_VERSION_S1D13744;
  1322. pr_info("omapfb: s1d13744 LCD controller rev %d "
  1323. "initialized (CNF pins %x)\n", rev & 0x03, conf & 0x07);
  1324. break;
  1325. case 0xa4:
  1326. blizzard.version = BLIZZARD_VERSION_S1D13745;
  1327. pr_info("omapfb: s1d13745 LCD controller rev %d "
  1328. "initialized (CNF pins %x)\n", rev & 0x03, conf & 0x07);
  1329. break;
  1330. default:
  1331. dev_err(fbdev->dev, "invalid s1d1374x revision %02x\n",
  1332. rev);
  1333. r = -ENODEV;
  1334. goto err3;
  1335. }
  1336. blizzard.max_transmit_size = blizzard.extif->max_transmit_size;
  1337. blizzard.update_mode = OMAPFB_UPDATE_DISABLED;
  1338. blizzard.auto_update_window.x = 0;
  1339. blizzard.auto_update_window.y = 0;
  1340. blizzard.auto_update_window.width = fbdev->panel->x_res;
  1341. blizzard.auto_update_window.height = fbdev->panel->y_res;
  1342. blizzard.auto_update_window.out_x = 0;
  1343. blizzard.auto_update_window.out_y = 0;
  1344. blizzard.auto_update_window.out_width = fbdev->panel->x_res;
  1345. blizzard.auto_update_window.out_height = fbdev->panel->y_res;
  1346. blizzard.auto_update_window.format = 0;
  1347. blizzard.screen_width = fbdev->panel->x_res;
  1348. blizzard.screen_height = fbdev->panel->y_res;
  1349. init_timer(&blizzard.auto_update_timer);
  1350. blizzard.auto_update_timer.function = blizzard_update_window_auto;
  1351. blizzard.auto_update_timer.data = 0;
  1352. INIT_LIST_HEAD(&blizzard.free_req_list);
  1353. INIT_LIST_HEAD(&blizzard.pending_req_list);
  1354. for (i = 0; i < ARRAY_SIZE(blizzard.req_pool); i++)
  1355. list_add(&blizzard.req_pool[i].entry, &blizzard.free_req_list);
  1356. BUG_ON(i <= IRQ_REQ_POOL_SIZE);
  1357. sema_init(&blizzard.req_sema, i - IRQ_REQ_POOL_SIZE);
  1358. return 0;
  1359. err3:
  1360. if (blizzard.power_down != NULL)
  1361. blizzard.power_down(fbdev->dev);
  1362. blizzard.extif->cleanup();
  1363. err2:
  1364. blizzard.int_ctrl->cleanup();
  1365. err1:
  1366. return r;
  1367. }
  1368. static void blizzard_cleanup(void)
  1369. {
  1370. blizzard_set_update_mode(OMAPFB_UPDATE_DISABLED);
  1371. blizzard.extif->cleanup();
  1372. blizzard.int_ctrl->cleanup();
  1373. if (blizzard.power_down != NULL)
  1374. blizzard.power_down(blizzard.fbdev->dev);
  1375. }
  1376. struct lcd_ctrl blizzard_ctrl = {
  1377. .name = "blizzard",
  1378. .init = blizzard_init,
  1379. .cleanup = blizzard_cleanup,
  1380. .bind_client = blizzard_bind_client,
  1381. .get_caps = blizzard_get_caps,
  1382. .set_update_mode = blizzard_set_update_mode,
  1383. .get_update_mode = blizzard_get_update_mode,
  1384. .setup_plane = blizzard_setup_plane,
  1385. .set_scale = blizzard_set_scale,
  1386. .enable_plane = blizzard_enable_plane,
  1387. .set_rotate = blizzard_set_rotate,
  1388. .update_window = blizzard_update_window_async,
  1389. .sync = blizzard_sync,
  1390. .suspend = blizzard_suspend,
  1391. .resume = blizzard_resume,
  1392. };