sa1100fb.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. /*
  2. * linux/drivers/video/sa1100fb.c
  3. *
  4. * Copyright (C) 1999 Eric A. Thomas
  5. * Based on acornfb.c Copyright (C) Russell King.
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. *
  11. * StrongARM 1100 LCD Controller Frame Buffer Driver
  12. *
  13. * Please direct your questions and comments on this driver to the following
  14. * email address:
  15. *
  16. * linux-arm-kernel@lists.arm.linux.org.uk
  17. *
  18. * Clean patches should be sent to the ARM Linux Patch System. Please see the
  19. * following web page for more information:
  20. *
  21. * http://www.arm.linux.org.uk/developer/patches/info.shtml
  22. *
  23. * Thank you.
  24. *
  25. * Known problems:
  26. * - With the Neponset plugged into an Assabet, LCD powerdown
  27. * doesn't work (LCD stays powered up). Therefore we shouldn't
  28. * blank the screen.
  29. * - We don't limit the CPU clock rate nor the mode selection
  30. * according to the available SDRAM bandwidth.
  31. *
  32. * Other notes:
  33. * - Linear grayscale palettes and the kernel.
  34. * Such code does not belong in the kernel. The kernel frame buffer
  35. * drivers do not expect a linear colourmap, but a colourmap based on
  36. * the VT100 standard mapping.
  37. *
  38. * If your _userspace_ requires a linear colourmap, then the setup of
  39. * such a colourmap belongs _in userspace_, not in the kernel. Code
  40. * to set the colourmap correctly from user space has been sent to
  41. * David Neuer. It's around 8 lines of C code, plus another 4 to
  42. * detect if we are using grayscale.
  43. *
  44. * - The following must never be specified in a panel definition:
  45. * LCCR0_LtlEnd, LCCR3_PixClkDiv, LCCR3_VrtSnchL, LCCR3_HorSnchL
  46. *
  47. * - The following should be specified:
  48. * either LCCR0_Color or LCCR0_Mono
  49. * either LCCR0_Sngl or LCCR0_Dual
  50. * either LCCR0_Act or LCCR0_Pas
  51. * either LCCR3_OutEnH or LCCD3_OutEnL
  52. * either LCCR3_PixRsEdg or LCCR3_PixFlEdg
  53. * either LCCR3_ACBsDiv or LCCR3_ACBsCntOff
  54. *
  55. * Code Status:
  56. * 1999/04/01:
  57. * - Driver appears to be working for Brutus 320x200x8bpp mode. Other
  58. * resolutions are working, but only the 8bpp mode is supported.
  59. * Changes need to be made to the palette encode and decode routines
  60. * to support 4 and 16 bpp modes.
  61. * Driver is not designed to be a module. The FrameBuffer is statically
  62. * allocated since dynamic allocation of a 300k buffer cannot be
  63. * guaranteed.
  64. *
  65. * 1999/06/17:
  66. * - FrameBuffer memory is now allocated at run-time when the
  67. * driver is initialized.
  68. *
  69. * 2000/04/10: Nicolas Pitre <nico@fluxnic.net>
  70. * - Big cleanup for dynamic selection of machine type at run time.
  71. *
  72. * 2000/07/19: Jamey Hicks <jamey@crl.dec.com>
  73. * - Support for Bitsy aka Compaq iPAQ H3600 added.
  74. *
  75. * 2000/08/07: Tak-Shing Chan <tchan.rd@idthk.com>
  76. * Jeff Sutherland <jsutherland@accelent.com>
  77. * - Resolved an issue caused by a change made to the Assabet's PLD
  78. * earlier this year which broke the framebuffer driver for newer
  79. * Phase 4 Assabets. Some other parameters were changed to optimize
  80. * for the Sharp display.
  81. *
  82. * 2000/08/09: Kunihiko IMAI <imai@vasara.co.jp>
  83. * - XP860 support added
  84. *
  85. * 2000/08/19: Mark Huang <mhuang@livetoy.com>
  86. * - Allows standard options to be passed on the kernel command line
  87. * for most common passive displays.
  88. *
  89. * 2000/08/29:
  90. * - s/save_flags_cli/local_irq_save/
  91. * - remove unneeded extra save_flags_cli in sa1100fb_enable_lcd_controller
  92. *
  93. * 2000/10/10: Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
  94. * - Updated LART stuff. Fixed some minor bugs.
  95. *
  96. * 2000/10/30: Murphy Chen <murphy@mail.dialogue.com.tw>
  97. * - Pangolin support added
  98. *
  99. * 2000/10/31: Roman Jordan <jor@hoeft-wessel.de>
  100. * - Huw Webpanel support added
  101. *
  102. * 2000/11/23: Eric Peng <ericpeng@coventive.com>
  103. * - Freebird add
  104. *
  105. * 2001/02/07: Jamey Hicks <jamey.hicks@compaq.com>
  106. * Cliff Brake <cbrake@accelent.com>
  107. * - Added PM callback
  108. *
  109. * 2001/05/26: <rmk@arm.linux.org.uk>
  110. * - Fix 16bpp so that (a) we use the right colours rather than some
  111. * totally random colour depending on what was in page 0, and (b)
  112. * we don't de-reference a NULL pointer.
  113. * - remove duplicated implementation of consistent_alloc()
  114. * - convert dma address types to dma_addr_t
  115. * - remove unused 'montype' stuff
  116. * - remove redundant zero inits of init_var after the initial
  117. * memset.
  118. * - remove allow_modeset (acornfb idea does not belong here)
  119. *
  120. * 2001/05/28: <rmk@arm.linux.org.uk>
  121. * - massive cleanup - move machine dependent data into structures
  122. * - I've left various #warnings in - if you see one, and know
  123. * the hardware concerned, please get in contact with me.
  124. *
  125. * 2001/05/31: <rmk@arm.linux.org.uk>
  126. * - Fix LCCR1 HSW value, fix all machine type specifications to
  127. * keep values in line. (Please check your machine type specs)
  128. *
  129. * 2001/06/10: <rmk@arm.linux.org.uk>
  130. * - Fiddle with the LCD controller from task context only; mainly
  131. * so that we can run with interrupts on, and sleep.
  132. * - Convert #warnings into #errors. No pain, no gain. ;)
  133. *
  134. * 2001/06/14: <rmk@arm.linux.org.uk>
  135. * - Make the palette BPS value for 12bpp come out correctly.
  136. * - Take notice of "greyscale" on any colour depth.
  137. * - Make truecolor visuals use the RGB channel encoding information.
  138. *
  139. * 2001/07/02: <rmk@arm.linux.org.uk>
  140. * - Fix colourmap problems.
  141. *
  142. * 2001/07/13: <abraham@2d3d.co.za>
  143. * - Added support for the ICP LCD-Kit01 on LART. This LCD is
  144. * manufactured by Prime View, model no V16C6448AB
  145. *
  146. * 2001/07/23: <rmk@arm.linux.org.uk>
  147. * - Hand merge version from handhelds.org CVS tree. See patch
  148. * notes for 595/1 for more information.
  149. * - Drop 12bpp (it's 16bpp with different colour register mappings).
  150. * - This hardware can not do direct colour. Therefore we don't
  151. * support it.
  152. *
  153. * 2001/07/27: <rmk@arm.linux.org.uk>
  154. * - Halve YRES on dual scan LCDs.
  155. *
  156. * 2001/08/22: <rmk@arm.linux.org.uk>
  157. * - Add b/w iPAQ pixclock value.
  158. *
  159. * 2001/10/12: <rmk@arm.linux.org.uk>
  160. * - Add patch 681/1 and clean up stork definitions.
  161. */
  162. #include <linux/module.h>
  163. #include <linux/kernel.h>
  164. #include <linux/sched.h>
  165. #include <linux/errno.h>
  166. #include <linux/string.h>
  167. #include <linux/interrupt.h>
  168. #include <linux/slab.h>
  169. #include <linux/mm.h>
  170. #include <linux/fb.h>
  171. #include <linux/delay.h>
  172. #include <linux/init.h>
  173. #include <linux/ioport.h>
  174. #include <linux/cpufreq.h>
  175. #include <linux/gpio.h>
  176. #include <linux/platform_device.h>
  177. #include <linux/dma-mapping.h>
  178. #include <linux/mutex.h>
  179. #include <linux/io.h>
  180. #include <linux/clk.h>
  181. #include <video/sa1100fb.h>
  182. #include <mach/hardware.h>
  183. #include <asm/mach-types.h>
  184. #include <mach/shannon.h>
  185. /*
  186. * Complain if VAR is out of range.
  187. */
  188. #define DEBUG_VAR 1
  189. #include "sa1100fb.h"
  190. static const struct sa1100fb_rgb rgb_4 = {
  191. .red = { .offset = 0, .length = 4, },
  192. .green = { .offset = 0, .length = 4, },
  193. .blue = { .offset = 0, .length = 4, },
  194. .transp = { .offset = 0, .length = 0, },
  195. };
  196. static const struct sa1100fb_rgb rgb_8 = {
  197. .red = { .offset = 0, .length = 8, },
  198. .green = { .offset = 0, .length = 8, },
  199. .blue = { .offset = 0, .length = 8, },
  200. .transp = { .offset = 0, .length = 0, },
  201. };
  202. static const struct sa1100fb_rgb def_rgb_16 = {
  203. .red = { .offset = 11, .length = 5, },
  204. .green = { .offset = 5, .length = 6, },
  205. .blue = { .offset = 0, .length = 5, },
  206. .transp = { .offset = 0, .length = 0, },
  207. };
  208. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *);
  209. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state);
  210. static inline void sa1100fb_schedule_work(struct sa1100fb_info *fbi, u_int state)
  211. {
  212. unsigned long flags;
  213. local_irq_save(flags);
  214. /*
  215. * We need to handle two requests being made at the same time.
  216. * There are two important cases:
  217. * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
  218. * We must perform the unblanking, which will do our REENABLE for us.
  219. * 2. When we are blanking, but immediately unblank before we have
  220. * blanked. We do the "REENABLE" thing here as well, just to be sure.
  221. */
  222. if (fbi->task_state == C_ENABLE && state == C_REENABLE)
  223. state = (u_int) -1;
  224. if (fbi->task_state == C_DISABLE && state == C_ENABLE)
  225. state = C_REENABLE;
  226. if (state != (u_int)-1) {
  227. fbi->task_state = state;
  228. schedule_work(&fbi->task);
  229. }
  230. local_irq_restore(flags);
  231. }
  232. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  233. {
  234. chan &= 0xffff;
  235. chan >>= 16 - bf->length;
  236. return chan << bf->offset;
  237. }
  238. /*
  239. * Convert bits-per-pixel to a hardware palette PBS value.
  240. */
  241. static inline u_int palette_pbs(struct fb_var_screeninfo *var)
  242. {
  243. int ret = 0;
  244. switch (var->bits_per_pixel) {
  245. case 4: ret = 0 << 12; break;
  246. case 8: ret = 1 << 12; break;
  247. case 16: ret = 2 << 12; break;
  248. }
  249. return ret;
  250. }
  251. static int
  252. sa1100fb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
  253. u_int trans, struct fb_info *info)
  254. {
  255. struct sa1100fb_info *fbi =
  256. container_of(info, struct sa1100fb_info, fb);
  257. u_int val, ret = 1;
  258. if (regno < fbi->palette_size) {
  259. val = ((red >> 4) & 0xf00);
  260. val |= ((green >> 8) & 0x0f0);
  261. val |= ((blue >> 12) & 0x00f);
  262. if (regno == 0)
  263. val |= palette_pbs(&fbi->fb.var);
  264. fbi->palette_cpu[regno] = val;
  265. ret = 0;
  266. }
  267. return ret;
  268. }
  269. static int
  270. sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  271. u_int trans, struct fb_info *info)
  272. {
  273. struct sa1100fb_info *fbi =
  274. container_of(info, struct sa1100fb_info, fb);
  275. unsigned int val;
  276. int ret = 1;
  277. /*
  278. * If inverse mode was selected, invert all the colours
  279. * rather than the register number. The register number
  280. * is what you poke into the framebuffer to produce the
  281. * colour you requested.
  282. */
  283. if (fbi->inf->cmap_inverse) {
  284. red = 0xffff - red;
  285. green = 0xffff - green;
  286. blue = 0xffff - blue;
  287. }
  288. /*
  289. * If greyscale is true, then we convert the RGB value
  290. * to greyscale no mater what visual we are using.
  291. */
  292. if (fbi->fb.var.grayscale)
  293. red = green = blue = (19595 * red + 38470 * green +
  294. 7471 * blue) >> 16;
  295. switch (fbi->fb.fix.visual) {
  296. case FB_VISUAL_TRUECOLOR:
  297. /*
  298. * 12 or 16-bit True Colour. We encode the RGB value
  299. * according to the RGB bitfield information.
  300. */
  301. if (regno < 16) {
  302. u32 *pal = fbi->fb.pseudo_palette;
  303. val = chan_to_field(red, &fbi->fb.var.red);
  304. val |= chan_to_field(green, &fbi->fb.var.green);
  305. val |= chan_to_field(blue, &fbi->fb.var.blue);
  306. pal[regno] = val;
  307. ret = 0;
  308. }
  309. break;
  310. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  311. case FB_VISUAL_PSEUDOCOLOR:
  312. ret = sa1100fb_setpalettereg(regno, red, green, blue, trans, info);
  313. break;
  314. }
  315. return ret;
  316. }
  317. #ifdef CONFIG_CPU_FREQ
  318. /*
  319. * sa1100fb_display_dma_period()
  320. * Calculate the minimum period (in picoseconds) between two DMA
  321. * requests for the LCD controller. If we hit this, it means we're
  322. * doing nothing but LCD DMA.
  323. */
  324. static inline unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
  325. {
  326. /*
  327. * Period = pixclock * bits_per_byte * bytes_per_transfer
  328. * / memory_bits_per_pixel;
  329. */
  330. return var->pixclock * 8 * 16 / var->bits_per_pixel;
  331. }
  332. #endif
  333. /*
  334. * sa1100fb_check_var():
  335. * Round up in the following order: bits_per_pixel, xres,
  336. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  337. * bitfields, horizontal timing, vertical timing.
  338. */
  339. static int
  340. sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  341. {
  342. struct sa1100fb_info *fbi =
  343. container_of(info, struct sa1100fb_info, fb);
  344. int rgbidx;
  345. if (var->xres < MIN_XRES)
  346. var->xres = MIN_XRES;
  347. if (var->yres < MIN_YRES)
  348. var->yres = MIN_YRES;
  349. if (var->xres > fbi->inf->xres)
  350. var->xres = fbi->inf->xres;
  351. if (var->yres > fbi->inf->yres)
  352. var->yres = fbi->inf->yres;
  353. var->xres_virtual = max(var->xres_virtual, var->xres);
  354. var->yres_virtual = max(var->yres_virtual, var->yres);
  355. dev_dbg(fbi->dev, "var->bits_per_pixel=%d\n", var->bits_per_pixel);
  356. switch (var->bits_per_pixel) {
  357. case 4:
  358. rgbidx = RGB_4;
  359. break;
  360. case 8:
  361. rgbidx = RGB_8;
  362. break;
  363. case 16:
  364. rgbidx = RGB_16;
  365. break;
  366. default:
  367. return -EINVAL;
  368. }
  369. /*
  370. * Copy the RGB parameters for this display
  371. * from the machine specific parameters.
  372. */
  373. var->red = fbi->rgb[rgbidx]->red;
  374. var->green = fbi->rgb[rgbidx]->green;
  375. var->blue = fbi->rgb[rgbidx]->blue;
  376. var->transp = fbi->rgb[rgbidx]->transp;
  377. dev_dbg(fbi->dev, "RGBT length = %d:%d:%d:%d\n",
  378. var->red.length, var->green.length, var->blue.length,
  379. var->transp.length);
  380. dev_dbg(fbi->dev, "RGBT offset = %d:%d:%d:%d\n",
  381. var->red.offset, var->green.offset, var->blue.offset,
  382. var->transp.offset);
  383. #ifdef CONFIG_CPU_FREQ
  384. dev_dbg(fbi->dev, "dma period = %d ps, clock = %ld kHz\n",
  385. sa1100fb_display_dma_period(var),
  386. clk_get_rate(fbi->clk) / 1000);
  387. #endif
  388. return 0;
  389. }
  390. static void sa1100fb_set_visual(struct sa1100fb_info *fbi, u32 visual)
  391. {
  392. if (fbi->inf->set_visual)
  393. fbi->inf->set_visual(visual);
  394. }
  395. /*
  396. * sa1100fb_set_par():
  397. * Set the user defined part of the display for the specified console
  398. */
  399. static int sa1100fb_set_par(struct fb_info *info)
  400. {
  401. struct sa1100fb_info *fbi =
  402. container_of(info, struct sa1100fb_info, fb);
  403. struct fb_var_screeninfo *var = &info->var;
  404. unsigned long palette_mem_size;
  405. dev_dbg(fbi->dev, "set_par\n");
  406. if (var->bits_per_pixel == 16)
  407. fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  408. else if (!fbi->inf->cmap_static)
  409. fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  410. else {
  411. /*
  412. * Some people have weird ideas about wanting static
  413. * pseudocolor maps. I suspect their user space
  414. * applications are broken.
  415. */
  416. fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  417. }
  418. fbi->fb.fix.line_length = var->xres_virtual *
  419. var->bits_per_pixel / 8;
  420. fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
  421. palette_mem_size = fbi->palette_size * sizeof(u16);
  422. dev_dbg(fbi->dev, "palette_mem_size = 0x%08lx\n", palette_mem_size);
  423. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  424. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  425. /*
  426. * Set (any) board control register to handle new color depth
  427. */
  428. sa1100fb_set_visual(fbi, fbi->fb.fix.visual);
  429. sa1100fb_activate_var(var, fbi);
  430. return 0;
  431. }
  432. #if 0
  433. static int
  434. sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  435. struct fb_info *info)
  436. {
  437. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  438. /*
  439. * Make sure the user isn't doing something stupid.
  440. */
  441. if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->inf->cmap_static))
  442. return -EINVAL;
  443. return gen_set_cmap(cmap, kspc, con, info);
  444. }
  445. #endif
  446. /*
  447. * Formal definition of the VESA spec:
  448. * On
  449. * This refers to the state of the display when it is in full operation
  450. * Stand-By
  451. * This defines an optional operating state of minimal power reduction with
  452. * the shortest recovery time
  453. * Suspend
  454. * This refers to a level of power management in which substantial power
  455. * reduction is achieved by the display. The display can have a longer
  456. * recovery time from this state than from the Stand-by state
  457. * Off
  458. * This indicates that the display is consuming the lowest level of power
  459. * and is non-operational. Recovery from this state may optionally require
  460. * the user to manually power on the monitor
  461. *
  462. * Now, the fbdev driver adds an additional state, (blank), where they
  463. * turn off the video (maybe by colormap tricks), but don't mess with the
  464. * video itself: think of it semantically between on and Stand-By.
  465. *
  466. * So here's what we should do in our fbdev blank routine:
  467. *
  468. * VESA_NO_BLANKING (mode 0) Video on, front/back light on
  469. * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
  470. * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
  471. * VESA_POWERDOWN (mode 3) Video off, front/back light off
  472. *
  473. * This will match the matrox implementation.
  474. */
  475. /*
  476. * sa1100fb_blank():
  477. * Blank the display by setting all palette values to zero. Note, the
  478. * 12 and 16 bpp modes don't really use the palette, so this will not
  479. * blank the display in all modes.
  480. */
  481. static int sa1100fb_blank(int blank, struct fb_info *info)
  482. {
  483. struct sa1100fb_info *fbi =
  484. container_of(info, struct sa1100fb_info, fb);
  485. int i;
  486. dev_dbg(fbi->dev, "sa1100fb_blank: blank=%d\n", blank);
  487. switch (blank) {
  488. case FB_BLANK_POWERDOWN:
  489. case FB_BLANK_VSYNC_SUSPEND:
  490. case FB_BLANK_HSYNC_SUSPEND:
  491. case FB_BLANK_NORMAL:
  492. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  493. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  494. for (i = 0; i < fbi->palette_size; i++)
  495. sa1100fb_setpalettereg(i, 0, 0, 0, 0, info);
  496. sa1100fb_schedule_work(fbi, C_DISABLE);
  497. break;
  498. case FB_BLANK_UNBLANK:
  499. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  500. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  501. fb_set_cmap(&fbi->fb.cmap, info);
  502. sa1100fb_schedule_work(fbi, C_ENABLE);
  503. }
  504. return 0;
  505. }
  506. static int sa1100fb_mmap(struct fb_info *info,
  507. struct vm_area_struct *vma)
  508. {
  509. struct sa1100fb_info *fbi =
  510. container_of(info, struct sa1100fb_info, fb);
  511. unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
  512. if (off < info->fix.smem_len) {
  513. vma->vm_pgoff += 1; /* skip over the palette */
  514. return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
  515. fbi->map_dma, fbi->map_size);
  516. }
  517. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  518. return vm_iomap_memory(vma, info->fix.mmio_start, info->fix.mmio_len);
  519. }
  520. static struct fb_ops sa1100fb_ops = {
  521. .owner = THIS_MODULE,
  522. .fb_check_var = sa1100fb_check_var,
  523. .fb_set_par = sa1100fb_set_par,
  524. // .fb_set_cmap = sa1100fb_set_cmap,
  525. .fb_setcolreg = sa1100fb_setcolreg,
  526. .fb_fillrect = cfb_fillrect,
  527. .fb_copyarea = cfb_copyarea,
  528. .fb_imageblit = cfb_imageblit,
  529. .fb_blank = sa1100fb_blank,
  530. .fb_mmap = sa1100fb_mmap,
  531. };
  532. /*
  533. * Calculate the PCD value from the clock rate (in picoseconds).
  534. * We take account of the PPCR clock setting.
  535. */
  536. static inline unsigned int get_pcd(struct sa1100fb_info *fbi,
  537. unsigned int pixclock)
  538. {
  539. unsigned int pcd = clk_get_rate(fbi->clk) / 100 / 1000;
  540. pcd *= pixclock;
  541. pcd /= 10000000;
  542. return pcd + 1; /* make up for integer math truncations */
  543. }
  544. /*
  545. * sa1100fb_activate_var():
  546. * Configures LCD Controller based on entries in var parameter. Settings are
  547. * only written to the controller if changes were made.
  548. */
  549. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *fbi)
  550. {
  551. struct sa1100fb_lcd_reg new_regs;
  552. u_int half_screen_size, yres, pcd;
  553. u_long flags;
  554. dev_dbg(fbi->dev, "Configuring SA1100 LCD\n");
  555. dev_dbg(fbi->dev, "var: xres=%d hslen=%d lm=%d rm=%d\n",
  556. var->xres, var->hsync_len,
  557. var->left_margin, var->right_margin);
  558. dev_dbg(fbi->dev, "var: yres=%d vslen=%d um=%d bm=%d\n",
  559. var->yres, var->vsync_len,
  560. var->upper_margin, var->lower_margin);
  561. #if DEBUG_VAR
  562. if (var->xres < 16 || var->xres > 1024)
  563. dev_err(fbi->dev, "%s: invalid xres %d\n",
  564. fbi->fb.fix.id, var->xres);
  565. if (var->hsync_len < 1 || var->hsync_len > 64)
  566. dev_err(fbi->dev, "%s: invalid hsync_len %d\n",
  567. fbi->fb.fix.id, var->hsync_len);
  568. if (var->left_margin < 1 || var->left_margin > 255)
  569. dev_err(fbi->dev, "%s: invalid left_margin %d\n",
  570. fbi->fb.fix.id, var->left_margin);
  571. if (var->right_margin < 1 || var->right_margin > 255)
  572. dev_err(fbi->dev, "%s: invalid right_margin %d\n",
  573. fbi->fb.fix.id, var->right_margin);
  574. if (var->yres < 1 || var->yres > 1024)
  575. dev_err(fbi->dev, "%s: invalid yres %d\n",
  576. fbi->fb.fix.id, var->yres);
  577. if (var->vsync_len < 1 || var->vsync_len > 64)
  578. dev_err(fbi->dev, "%s: invalid vsync_len %d\n",
  579. fbi->fb.fix.id, var->vsync_len);
  580. if (var->upper_margin < 0 || var->upper_margin > 255)
  581. dev_err(fbi->dev, "%s: invalid upper_margin %d\n",
  582. fbi->fb.fix.id, var->upper_margin);
  583. if (var->lower_margin < 0 || var->lower_margin > 255)
  584. dev_err(fbi->dev, "%s: invalid lower_margin %d\n",
  585. fbi->fb.fix.id, var->lower_margin);
  586. #endif
  587. new_regs.lccr0 = fbi->inf->lccr0 |
  588. LCCR0_LEN | LCCR0_LDM | LCCR0_BAM |
  589. LCCR0_ERM | LCCR0_LtlEnd | LCCR0_DMADel(0);
  590. new_regs.lccr1 =
  591. LCCR1_DisWdth(var->xres) +
  592. LCCR1_HorSnchWdth(var->hsync_len) +
  593. LCCR1_BegLnDel(var->left_margin) +
  594. LCCR1_EndLnDel(var->right_margin);
  595. /*
  596. * If we have a dual scan LCD, then we need to halve
  597. * the YRES parameter.
  598. */
  599. yres = var->yres;
  600. if (fbi->inf->lccr0 & LCCR0_Dual)
  601. yres /= 2;
  602. new_regs.lccr2 =
  603. LCCR2_DisHght(yres) +
  604. LCCR2_VrtSnchWdth(var->vsync_len) +
  605. LCCR2_BegFrmDel(var->upper_margin) +
  606. LCCR2_EndFrmDel(var->lower_margin);
  607. pcd = get_pcd(fbi, var->pixclock);
  608. new_regs.lccr3 = LCCR3_PixClkDiv(pcd) | fbi->inf->lccr3 |
  609. (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
  610. (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  611. dev_dbg(fbi->dev, "nlccr0 = 0x%08lx\n", new_regs.lccr0);
  612. dev_dbg(fbi->dev, "nlccr1 = 0x%08lx\n", new_regs.lccr1);
  613. dev_dbg(fbi->dev, "nlccr2 = 0x%08lx\n", new_regs.lccr2);
  614. dev_dbg(fbi->dev, "nlccr3 = 0x%08lx\n", new_regs.lccr3);
  615. half_screen_size = var->bits_per_pixel;
  616. half_screen_size = half_screen_size * var->xres * var->yres / 16;
  617. /* Update shadow copy atomically */
  618. local_irq_save(flags);
  619. fbi->dbar1 = fbi->palette_dma;
  620. fbi->dbar2 = fbi->screen_dma + half_screen_size;
  621. fbi->reg_lccr0 = new_regs.lccr0;
  622. fbi->reg_lccr1 = new_regs.lccr1;
  623. fbi->reg_lccr2 = new_regs.lccr2;
  624. fbi->reg_lccr3 = new_regs.lccr3;
  625. local_irq_restore(flags);
  626. /*
  627. * Only update the registers if the controller is enabled
  628. * and something has changed.
  629. */
  630. if (readl_relaxed(fbi->base + LCCR0) != fbi->reg_lccr0 ||
  631. readl_relaxed(fbi->base + LCCR1) != fbi->reg_lccr1 ||
  632. readl_relaxed(fbi->base + LCCR2) != fbi->reg_lccr2 ||
  633. readl_relaxed(fbi->base + LCCR3) != fbi->reg_lccr3 ||
  634. readl_relaxed(fbi->base + DBAR1) != fbi->dbar1 ||
  635. readl_relaxed(fbi->base + DBAR2) != fbi->dbar2)
  636. sa1100fb_schedule_work(fbi, C_REENABLE);
  637. return 0;
  638. }
  639. /*
  640. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  641. * Do not call them directly; set_ctrlr_state does the correct serialisation
  642. * to ensure that things happen in the right way 100% of time time.
  643. * -- rmk
  644. */
  645. static inline void __sa1100fb_backlight_power(struct sa1100fb_info *fbi, int on)
  646. {
  647. dev_dbg(fbi->dev, "backlight o%s\n", on ? "n" : "ff");
  648. if (fbi->inf->backlight_power)
  649. fbi->inf->backlight_power(on);
  650. }
  651. static inline void __sa1100fb_lcd_power(struct sa1100fb_info *fbi, int on)
  652. {
  653. dev_dbg(fbi->dev, "LCD power o%s\n", on ? "n" : "ff");
  654. if (fbi->inf->lcd_power)
  655. fbi->inf->lcd_power(on);
  656. }
  657. static void sa1100fb_setup_gpio(struct sa1100fb_info *fbi)
  658. {
  659. u_int mask = 0;
  660. /*
  661. * Enable GPIO<9:2> for LCD use if:
  662. * 1. Active display, or
  663. * 2. Color Dual Passive display
  664. *
  665. * see table 11.8 on page 11-27 in the SA1100 manual
  666. * -- Erik.
  667. *
  668. * SA1110 spec update nr. 25 says we can and should
  669. * clear LDD15 to 12 for 4 or 8bpp modes with active
  670. * panels.
  671. */
  672. if ((fbi->reg_lccr0 & LCCR0_CMS) == LCCR0_Color &&
  673. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) != 0) {
  674. mask = GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  675. if (fbi->fb.var.bits_per_pixel > 8 ||
  676. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) == LCCR0_Dual)
  677. mask |= GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12;
  678. }
  679. if (mask) {
  680. unsigned long flags;
  681. /*
  682. * SA-1100 requires the GPIO direction register set
  683. * appropriately for the alternate function. Hence
  684. * we set it here via bitmask rather than excessive
  685. * fiddling via the GPIO subsystem - and even then
  686. * we'll still have to deal with GAFR.
  687. */
  688. local_irq_save(flags);
  689. GPDR |= mask;
  690. GAFR |= mask;
  691. local_irq_restore(flags);
  692. }
  693. }
  694. static void sa1100fb_enable_controller(struct sa1100fb_info *fbi)
  695. {
  696. dev_dbg(fbi->dev, "Enabling LCD controller\n");
  697. /*
  698. * Make sure the mode bits are present in the first palette entry
  699. */
  700. fbi->palette_cpu[0] &= 0xcfff;
  701. fbi->palette_cpu[0] |= palette_pbs(&fbi->fb.var);
  702. /* enable LCD controller clock */
  703. clk_prepare_enable(fbi->clk);
  704. /* Sequence from 11.7.10 */
  705. writel_relaxed(fbi->reg_lccr3, fbi->base + LCCR3);
  706. writel_relaxed(fbi->reg_lccr2, fbi->base + LCCR2);
  707. writel_relaxed(fbi->reg_lccr1, fbi->base + LCCR1);
  708. writel_relaxed(fbi->reg_lccr0 & ~LCCR0_LEN, fbi->base + LCCR0);
  709. writel_relaxed(fbi->dbar1, fbi->base + DBAR1);
  710. writel_relaxed(fbi->dbar2, fbi->base + DBAR2);
  711. writel_relaxed(fbi->reg_lccr0 | LCCR0_LEN, fbi->base + LCCR0);
  712. if (machine_is_shannon())
  713. gpio_set_value(SHANNON_GPIO_DISP_EN, 1);
  714. dev_dbg(fbi->dev, "DBAR1: 0x%08x\n", readl_relaxed(fbi->base + DBAR1));
  715. dev_dbg(fbi->dev, "DBAR2: 0x%08x\n", readl_relaxed(fbi->base + DBAR2));
  716. dev_dbg(fbi->dev, "LCCR0: 0x%08x\n", readl_relaxed(fbi->base + LCCR0));
  717. dev_dbg(fbi->dev, "LCCR1: 0x%08x\n", readl_relaxed(fbi->base + LCCR1));
  718. dev_dbg(fbi->dev, "LCCR2: 0x%08x\n", readl_relaxed(fbi->base + LCCR2));
  719. dev_dbg(fbi->dev, "LCCR3: 0x%08x\n", readl_relaxed(fbi->base + LCCR3));
  720. }
  721. static void sa1100fb_disable_controller(struct sa1100fb_info *fbi)
  722. {
  723. DECLARE_WAITQUEUE(wait, current);
  724. u32 lccr0;
  725. dev_dbg(fbi->dev, "Disabling LCD controller\n");
  726. if (machine_is_shannon())
  727. gpio_set_value(SHANNON_GPIO_DISP_EN, 0);
  728. set_current_state(TASK_UNINTERRUPTIBLE);
  729. add_wait_queue(&fbi->ctrlr_wait, &wait);
  730. /* Clear LCD Status Register */
  731. writel_relaxed(~0, fbi->base + LCSR);
  732. lccr0 = readl_relaxed(fbi->base + LCCR0);
  733. lccr0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
  734. writel_relaxed(lccr0, fbi->base + LCCR0);
  735. lccr0 &= ~LCCR0_LEN; /* Disable LCD Controller */
  736. writel_relaxed(lccr0, fbi->base + LCCR0);
  737. schedule_timeout(20 * HZ / 1000);
  738. remove_wait_queue(&fbi->ctrlr_wait, &wait);
  739. /* disable LCD controller clock */
  740. clk_disable_unprepare(fbi->clk);
  741. }
  742. /*
  743. * sa1100fb_handle_irq: Handle 'LCD DONE' interrupts.
  744. */
  745. static irqreturn_t sa1100fb_handle_irq(int irq, void *dev_id)
  746. {
  747. struct sa1100fb_info *fbi = dev_id;
  748. unsigned int lcsr = readl_relaxed(fbi->base + LCSR);
  749. if (lcsr & LCSR_LDD) {
  750. u32 lccr0 = readl_relaxed(fbi->base + LCCR0) | LCCR0_LDM;
  751. writel_relaxed(lccr0, fbi->base + LCCR0);
  752. wake_up(&fbi->ctrlr_wait);
  753. }
  754. writel_relaxed(lcsr, fbi->base + LCSR);
  755. return IRQ_HANDLED;
  756. }
  757. /*
  758. * This function must be called from task context only, since it will
  759. * sleep when disabling the LCD controller, or if we get two contending
  760. * processes trying to alter state.
  761. */
  762. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
  763. {
  764. u_int old_state;
  765. mutex_lock(&fbi->ctrlr_lock);
  766. old_state = fbi->state;
  767. /*
  768. * Hack around fbcon initialisation.
  769. */
  770. if (old_state == C_STARTUP && state == C_REENABLE)
  771. state = C_ENABLE;
  772. switch (state) {
  773. case C_DISABLE_CLKCHANGE:
  774. /*
  775. * Disable controller for clock change. If the
  776. * controller is already disabled, then do nothing.
  777. */
  778. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  779. fbi->state = state;
  780. sa1100fb_disable_controller(fbi);
  781. }
  782. break;
  783. case C_DISABLE_PM:
  784. case C_DISABLE:
  785. /*
  786. * Disable controller
  787. */
  788. if (old_state != C_DISABLE) {
  789. fbi->state = state;
  790. __sa1100fb_backlight_power(fbi, 0);
  791. if (old_state != C_DISABLE_CLKCHANGE)
  792. sa1100fb_disable_controller(fbi);
  793. __sa1100fb_lcd_power(fbi, 0);
  794. }
  795. break;
  796. case C_ENABLE_CLKCHANGE:
  797. /*
  798. * Enable the controller after clock change. Only
  799. * do this if we were disabled for the clock change.
  800. */
  801. if (old_state == C_DISABLE_CLKCHANGE) {
  802. fbi->state = C_ENABLE;
  803. sa1100fb_enable_controller(fbi);
  804. }
  805. break;
  806. case C_REENABLE:
  807. /*
  808. * Re-enable the controller only if it was already
  809. * enabled. This is so we reprogram the control
  810. * registers.
  811. */
  812. if (old_state == C_ENABLE) {
  813. sa1100fb_disable_controller(fbi);
  814. sa1100fb_setup_gpio(fbi);
  815. sa1100fb_enable_controller(fbi);
  816. }
  817. break;
  818. case C_ENABLE_PM:
  819. /*
  820. * Re-enable the controller after PM. This is not
  821. * perfect - think about the case where we were doing
  822. * a clock change, and we suspended half-way through.
  823. */
  824. if (old_state != C_DISABLE_PM)
  825. break;
  826. /* fall through */
  827. case C_ENABLE:
  828. /*
  829. * Power up the LCD screen, enable controller, and
  830. * turn on the backlight.
  831. */
  832. if (old_state != C_ENABLE) {
  833. fbi->state = C_ENABLE;
  834. sa1100fb_setup_gpio(fbi);
  835. __sa1100fb_lcd_power(fbi, 1);
  836. sa1100fb_enable_controller(fbi);
  837. __sa1100fb_backlight_power(fbi, 1);
  838. }
  839. break;
  840. }
  841. mutex_unlock(&fbi->ctrlr_lock);
  842. }
  843. /*
  844. * Our LCD controller task (which is called when we blank or unblank)
  845. * via keventd.
  846. */
  847. static void sa1100fb_task(struct work_struct *w)
  848. {
  849. struct sa1100fb_info *fbi = container_of(w, struct sa1100fb_info, task);
  850. u_int state = xchg(&fbi->task_state, -1);
  851. set_ctrlr_state(fbi, state);
  852. }
  853. #ifdef CONFIG_CPU_FREQ
  854. /*
  855. * Calculate the minimum DMA period over all displays that we own.
  856. * This, together with the SDRAM bandwidth defines the slowest CPU
  857. * frequency that can be selected.
  858. */
  859. static unsigned int sa1100fb_min_dma_period(struct sa1100fb_info *fbi)
  860. {
  861. #if 0
  862. unsigned int min_period = (unsigned int)-1;
  863. int i;
  864. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  865. struct display *disp = &fb_display[i];
  866. unsigned int period;
  867. /*
  868. * Do we own this display?
  869. */
  870. if (disp->fb_info != &fbi->fb)
  871. continue;
  872. /*
  873. * Ok, calculate its DMA period
  874. */
  875. period = sa1100fb_display_dma_period(&disp->var);
  876. if (period < min_period)
  877. min_period = period;
  878. }
  879. return min_period;
  880. #else
  881. /*
  882. * FIXME: we need to verify _all_ consoles.
  883. */
  884. return sa1100fb_display_dma_period(&fbi->fb.var);
  885. #endif
  886. }
  887. /*
  888. * CPU clock speed change handler. We need to adjust the LCD timing
  889. * parameters when the CPU clock is adjusted by the power management
  890. * subsystem.
  891. */
  892. static int
  893. sa1100fb_freq_transition(struct notifier_block *nb, unsigned long val,
  894. void *data)
  895. {
  896. struct sa1100fb_info *fbi = TO_INF(nb, freq_transition);
  897. u_int pcd;
  898. switch (val) {
  899. case CPUFREQ_PRECHANGE:
  900. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  901. break;
  902. case CPUFREQ_POSTCHANGE:
  903. pcd = get_pcd(fbi, fbi->fb.var.pixclock);
  904. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
  905. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  906. break;
  907. }
  908. return 0;
  909. }
  910. static int
  911. sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
  912. void *data)
  913. {
  914. struct sa1100fb_info *fbi = TO_INF(nb, freq_policy);
  915. struct cpufreq_policy *policy = data;
  916. switch (val) {
  917. case CPUFREQ_ADJUST:
  918. case CPUFREQ_INCOMPATIBLE:
  919. dev_dbg(fbi->dev, "min dma period: %d ps, "
  920. "new clock %d kHz\n", sa1100fb_min_dma_period(fbi),
  921. policy->max);
  922. /* todo: fill in min/max values */
  923. break;
  924. case CPUFREQ_NOTIFY:
  925. do {} while(0);
  926. /* todo: panic if min/max values aren't fulfilled
  927. * [can't really happen unless there's a bug in the
  928. * CPU policy verififcation process *
  929. */
  930. break;
  931. }
  932. return 0;
  933. }
  934. #endif
  935. #ifdef CONFIG_PM
  936. /*
  937. * Power management hooks. Note that we won't be called from IRQ context,
  938. * unlike the blank functions above, so we may sleep.
  939. */
  940. static int sa1100fb_suspend(struct platform_device *dev, pm_message_t state)
  941. {
  942. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  943. set_ctrlr_state(fbi, C_DISABLE_PM);
  944. return 0;
  945. }
  946. static int sa1100fb_resume(struct platform_device *dev)
  947. {
  948. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  949. set_ctrlr_state(fbi, C_ENABLE_PM);
  950. return 0;
  951. }
  952. #else
  953. #define sa1100fb_suspend NULL
  954. #define sa1100fb_resume NULL
  955. #endif
  956. /*
  957. * sa1100fb_map_video_memory():
  958. * Allocates the DRAM memory for the frame buffer. This buffer is
  959. * remapped into a non-cached, non-buffered, memory region to
  960. * allow palette and pixel writes to occur without flushing the
  961. * cache. Once this area is remapped, all virtual memory
  962. * access to the video memory should occur at the new region.
  963. */
  964. static int sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
  965. {
  966. /*
  967. * We reserve one page for the palette, plus the size
  968. * of the framebuffer.
  969. */
  970. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  971. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  972. &fbi->map_dma, GFP_KERNEL);
  973. if (fbi->map_cpu) {
  974. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  975. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  976. /*
  977. * FIXME: this is actually the wrong thing to place in
  978. * smem_start. But fbdev suffers from the problem that
  979. * it needs an API which doesn't exist (in this case,
  980. * dma_writecombine_mmap)
  981. */
  982. fbi->fb.fix.smem_start = fbi->screen_dma;
  983. }
  984. return fbi->map_cpu ? 0 : -ENOMEM;
  985. }
  986. /* Fake monspecs to fill in fbinfo structure */
  987. static struct fb_monspecs monspecs = {
  988. .hfmin = 30000,
  989. .hfmax = 70000,
  990. .vfmin = 50,
  991. .vfmax = 65,
  992. };
  993. static struct sa1100fb_info *sa1100fb_init_fbinfo(struct device *dev)
  994. {
  995. struct sa1100fb_mach_info *inf = dev_get_platdata(dev);
  996. struct sa1100fb_info *fbi;
  997. unsigned i;
  998. fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
  999. GFP_KERNEL);
  1000. if (!fbi)
  1001. return NULL;
  1002. memset(fbi, 0, sizeof(struct sa1100fb_info));
  1003. fbi->dev = dev;
  1004. strcpy(fbi->fb.fix.id, SA1100_NAME);
  1005. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1006. fbi->fb.fix.type_aux = 0;
  1007. fbi->fb.fix.xpanstep = 0;
  1008. fbi->fb.fix.ypanstep = 0;
  1009. fbi->fb.fix.ywrapstep = 0;
  1010. fbi->fb.fix.accel = FB_ACCEL_NONE;
  1011. fbi->fb.var.nonstd = 0;
  1012. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  1013. fbi->fb.var.height = -1;
  1014. fbi->fb.var.width = -1;
  1015. fbi->fb.var.accel_flags = 0;
  1016. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  1017. fbi->fb.fbops = &sa1100fb_ops;
  1018. fbi->fb.flags = FBINFO_DEFAULT;
  1019. fbi->fb.monspecs = monspecs;
  1020. fbi->fb.pseudo_palette = (fbi + 1);
  1021. fbi->rgb[RGB_4] = &rgb_4;
  1022. fbi->rgb[RGB_8] = &rgb_8;
  1023. fbi->rgb[RGB_16] = &def_rgb_16;
  1024. /*
  1025. * People just don't seem to get this. We don't support
  1026. * anything but correct entries now, so panic if someone
  1027. * does something stupid.
  1028. */
  1029. if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
  1030. inf->pixclock == 0)
  1031. panic("sa1100fb error: invalid LCCR3 fields set or zero "
  1032. "pixclock.");
  1033. fbi->fb.var.xres = inf->xres;
  1034. fbi->fb.var.xres_virtual = inf->xres;
  1035. fbi->fb.var.yres = inf->yres;
  1036. fbi->fb.var.yres_virtual = inf->yres;
  1037. fbi->fb.var.bits_per_pixel = inf->bpp;
  1038. fbi->fb.var.pixclock = inf->pixclock;
  1039. fbi->fb.var.hsync_len = inf->hsync_len;
  1040. fbi->fb.var.left_margin = inf->left_margin;
  1041. fbi->fb.var.right_margin = inf->right_margin;
  1042. fbi->fb.var.vsync_len = inf->vsync_len;
  1043. fbi->fb.var.upper_margin = inf->upper_margin;
  1044. fbi->fb.var.lower_margin = inf->lower_margin;
  1045. fbi->fb.var.sync = inf->sync;
  1046. fbi->fb.var.grayscale = inf->cmap_greyscale;
  1047. fbi->state = C_STARTUP;
  1048. fbi->task_state = (u_char)-1;
  1049. fbi->fb.fix.smem_len = inf->xres * inf->yres *
  1050. inf->bpp / 8;
  1051. fbi->inf = inf;
  1052. /* Copy the RGB bitfield overrides */
  1053. for (i = 0; i < NR_RGB; i++)
  1054. if (inf->rgb[i])
  1055. fbi->rgb[i] = inf->rgb[i];
  1056. init_waitqueue_head(&fbi->ctrlr_wait);
  1057. INIT_WORK(&fbi->task, sa1100fb_task);
  1058. mutex_init(&fbi->ctrlr_lock);
  1059. return fbi;
  1060. }
  1061. static int sa1100fb_probe(struct platform_device *pdev)
  1062. {
  1063. struct sa1100fb_info *fbi;
  1064. struct resource *res;
  1065. int ret, irq;
  1066. if (!dev_get_platdata(&pdev->dev)) {
  1067. dev_err(&pdev->dev, "no platform LCD data\n");
  1068. return -EINVAL;
  1069. }
  1070. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1071. irq = platform_get_irq(pdev, 0);
  1072. if (irq < 0 || !res)
  1073. return -EINVAL;
  1074. if (!request_mem_region(res->start, resource_size(res), "LCD"))
  1075. return -EBUSY;
  1076. fbi = sa1100fb_init_fbinfo(&pdev->dev);
  1077. ret = -ENOMEM;
  1078. if (!fbi)
  1079. goto failed;
  1080. fbi->clk = clk_get(&pdev->dev, NULL);
  1081. if (IS_ERR(fbi->clk)) {
  1082. ret = PTR_ERR(fbi->clk);
  1083. fbi->clk = NULL;
  1084. goto failed;
  1085. }
  1086. fbi->base = ioremap(res->start, resource_size(res));
  1087. if (!fbi->base)
  1088. goto failed;
  1089. /* Initialize video memory */
  1090. ret = sa1100fb_map_video_memory(fbi);
  1091. if (ret)
  1092. goto failed;
  1093. ret = request_irq(irq, sa1100fb_handle_irq, 0, "LCD", fbi);
  1094. if (ret) {
  1095. dev_err(&pdev->dev, "request_irq failed: %d\n", ret);
  1096. goto failed;
  1097. }
  1098. if (machine_is_shannon()) {
  1099. ret = gpio_request_one(SHANNON_GPIO_DISP_EN,
  1100. GPIOF_OUT_INIT_LOW, "display enable");
  1101. if (ret)
  1102. goto err_free_irq;
  1103. }
  1104. /*
  1105. * This makes sure that our colour bitfield
  1106. * descriptors are correctly initialised.
  1107. */
  1108. sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
  1109. platform_set_drvdata(pdev, fbi);
  1110. ret = register_framebuffer(&fbi->fb);
  1111. if (ret < 0)
  1112. goto err_reg_fb;
  1113. #ifdef CONFIG_CPU_FREQ
  1114. fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
  1115. fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
  1116. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1117. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1118. #endif
  1119. /* This driver cannot be unloaded at the moment */
  1120. return 0;
  1121. err_reg_fb:
  1122. if (machine_is_shannon())
  1123. gpio_free(SHANNON_GPIO_DISP_EN);
  1124. err_free_irq:
  1125. free_irq(irq, fbi);
  1126. failed:
  1127. if (fbi)
  1128. iounmap(fbi->base);
  1129. if (fbi->clk)
  1130. clk_put(fbi->clk);
  1131. kfree(fbi);
  1132. release_mem_region(res->start, resource_size(res));
  1133. return ret;
  1134. }
  1135. static struct platform_driver sa1100fb_driver = {
  1136. .probe = sa1100fb_probe,
  1137. .suspend = sa1100fb_suspend,
  1138. .resume = sa1100fb_resume,
  1139. .driver = {
  1140. .name = "sa11x0-fb",
  1141. },
  1142. };
  1143. int __init sa1100fb_init(void)
  1144. {
  1145. if (fb_get_options("sa1100fb", NULL))
  1146. return -ENODEV;
  1147. return platform_driver_register(&sa1100fb_driver);
  1148. }
  1149. int __init sa1100fb_setup(char *options)
  1150. {
  1151. #if 0
  1152. char *this_opt;
  1153. if (!options || !*options)
  1154. return 0;
  1155. while ((this_opt = strsep(&options, ",")) != NULL) {
  1156. if (!strncmp(this_opt, "bpp:", 4))
  1157. current_par.max_bpp =
  1158. simple_strtoul(this_opt + 4, NULL, 0);
  1159. if (!strncmp(this_opt, "lccr0:", 6))
  1160. lcd_shadow.lccr0 =
  1161. simple_strtoul(this_opt + 6, NULL, 0);
  1162. if (!strncmp(this_opt, "lccr1:", 6)) {
  1163. lcd_shadow.lccr1 =
  1164. simple_strtoul(this_opt + 6, NULL, 0);
  1165. current_par.max_xres =
  1166. (lcd_shadow.lccr1 & 0x3ff) + 16;
  1167. }
  1168. if (!strncmp(this_opt, "lccr2:", 6)) {
  1169. lcd_shadow.lccr2 =
  1170. simple_strtoul(this_opt + 6, NULL, 0);
  1171. current_par.max_yres =
  1172. (lcd_shadow.
  1173. lccr0 & LCCR0_SDS) ? ((lcd_shadow.
  1174. lccr2 & 0x3ff) +
  1175. 1) *
  1176. 2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);
  1177. }
  1178. if (!strncmp(this_opt, "lccr3:", 6))
  1179. lcd_shadow.lccr3 =
  1180. simple_strtoul(this_opt + 6, NULL, 0);
  1181. }
  1182. #endif
  1183. return 0;
  1184. }
  1185. module_init(sa1100fb_init);
  1186. MODULE_DESCRIPTION("StrongARM-1100/1110 framebuffer driver");
  1187. MODULE_LICENSE("GPL");