sa1100fb.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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 <video/sa1100fb.h>
  181. #include <mach/hardware.h>
  182. #include <asm/mach-types.h>
  183. #include <mach/shannon.h>
  184. /*
  185. * Complain if VAR is out of range.
  186. */
  187. #define DEBUG_VAR 1
  188. #include "sa1100fb.h"
  189. static const struct sa1100fb_rgb rgb_4 = {
  190. .red = { .offset = 0, .length = 4, },
  191. .green = { .offset = 0, .length = 4, },
  192. .blue = { .offset = 0, .length = 4, },
  193. .transp = { .offset = 0, .length = 0, },
  194. };
  195. static const struct sa1100fb_rgb rgb_8 = {
  196. .red = { .offset = 0, .length = 8, },
  197. .green = { .offset = 0, .length = 8, },
  198. .blue = { .offset = 0, .length = 8, },
  199. .transp = { .offset = 0, .length = 0, },
  200. };
  201. static const struct sa1100fb_rgb def_rgb_16 = {
  202. .red = { .offset = 11, .length = 5, },
  203. .green = { .offset = 5, .length = 6, },
  204. .blue = { .offset = 0, .length = 5, },
  205. .transp = { .offset = 0, .length = 0, },
  206. };
  207. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *);
  208. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state);
  209. static inline void sa1100fb_schedule_work(struct sa1100fb_info *fbi, u_int state)
  210. {
  211. unsigned long flags;
  212. local_irq_save(flags);
  213. /*
  214. * We need to handle two requests being made at the same time.
  215. * There are two important cases:
  216. * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE)
  217. * We must perform the unblanking, which will do our REENABLE for us.
  218. * 2. When we are blanking, but immediately unblank before we have
  219. * blanked. We do the "REENABLE" thing here as well, just to be sure.
  220. */
  221. if (fbi->task_state == C_ENABLE && state == C_REENABLE)
  222. state = (u_int) -1;
  223. if (fbi->task_state == C_DISABLE && state == C_ENABLE)
  224. state = C_REENABLE;
  225. if (state != (u_int)-1) {
  226. fbi->task_state = state;
  227. schedule_work(&fbi->task);
  228. }
  229. local_irq_restore(flags);
  230. }
  231. static inline u_int chan_to_field(u_int chan, struct fb_bitfield *bf)
  232. {
  233. chan &= 0xffff;
  234. chan >>= 16 - bf->length;
  235. return chan << bf->offset;
  236. }
  237. /*
  238. * Convert bits-per-pixel to a hardware palette PBS value.
  239. */
  240. static inline u_int palette_pbs(struct fb_var_screeninfo *var)
  241. {
  242. int ret = 0;
  243. switch (var->bits_per_pixel) {
  244. case 4: ret = 0 << 12; break;
  245. case 8: ret = 1 << 12; break;
  246. case 16: ret = 2 << 12; break;
  247. }
  248. return ret;
  249. }
  250. static int
  251. sa1100fb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
  252. u_int trans, struct fb_info *info)
  253. {
  254. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  255. u_int val, ret = 1;
  256. if (regno < fbi->palette_size) {
  257. val = ((red >> 4) & 0xf00);
  258. val |= ((green >> 8) & 0x0f0);
  259. val |= ((blue >> 12) & 0x00f);
  260. if (regno == 0)
  261. val |= palette_pbs(&fbi->fb.var);
  262. fbi->palette_cpu[regno] = val;
  263. ret = 0;
  264. }
  265. return ret;
  266. }
  267. static int
  268. sa1100fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  269. u_int trans, struct fb_info *info)
  270. {
  271. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  272. unsigned int val;
  273. int ret = 1;
  274. /*
  275. * If inverse mode was selected, invert all the colours
  276. * rather than the register number. The register number
  277. * is what you poke into the framebuffer to produce the
  278. * colour you requested.
  279. */
  280. if (fbi->inf->cmap_inverse) {
  281. red = 0xffff - red;
  282. green = 0xffff - green;
  283. blue = 0xffff - blue;
  284. }
  285. /*
  286. * If greyscale is true, then we convert the RGB value
  287. * to greyscale no mater what visual we are using.
  288. */
  289. if (fbi->fb.var.grayscale)
  290. red = green = blue = (19595 * red + 38470 * green +
  291. 7471 * blue) >> 16;
  292. switch (fbi->fb.fix.visual) {
  293. case FB_VISUAL_TRUECOLOR:
  294. /*
  295. * 12 or 16-bit True Colour. We encode the RGB value
  296. * according to the RGB bitfield information.
  297. */
  298. if (regno < 16) {
  299. u32 *pal = fbi->fb.pseudo_palette;
  300. val = chan_to_field(red, &fbi->fb.var.red);
  301. val |= chan_to_field(green, &fbi->fb.var.green);
  302. val |= chan_to_field(blue, &fbi->fb.var.blue);
  303. pal[regno] = val;
  304. ret = 0;
  305. }
  306. break;
  307. case FB_VISUAL_STATIC_PSEUDOCOLOR:
  308. case FB_VISUAL_PSEUDOCOLOR:
  309. ret = sa1100fb_setpalettereg(regno, red, green, blue, trans, info);
  310. break;
  311. }
  312. return ret;
  313. }
  314. #ifdef CONFIG_CPU_FREQ
  315. /*
  316. * sa1100fb_display_dma_period()
  317. * Calculate the minimum period (in picoseconds) between two DMA
  318. * requests for the LCD controller. If we hit this, it means we're
  319. * doing nothing but LCD DMA.
  320. */
  321. static inline unsigned int sa1100fb_display_dma_period(struct fb_var_screeninfo *var)
  322. {
  323. /*
  324. * Period = pixclock * bits_per_byte * bytes_per_transfer
  325. * / memory_bits_per_pixel;
  326. */
  327. return var->pixclock * 8 * 16 / var->bits_per_pixel;
  328. }
  329. #endif
  330. /*
  331. * sa1100fb_check_var():
  332. * Round up in the following order: bits_per_pixel, xres,
  333. * yres, xres_virtual, yres_virtual, xoffset, yoffset, grayscale,
  334. * bitfields, horizontal timing, vertical timing.
  335. */
  336. static int
  337. sa1100fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  338. {
  339. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  340. int rgbidx;
  341. if (var->xres < MIN_XRES)
  342. var->xres = MIN_XRES;
  343. if (var->yres < MIN_YRES)
  344. var->yres = MIN_YRES;
  345. if (var->xres > fbi->inf->xres)
  346. var->xres = fbi->inf->xres;
  347. if (var->yres > fbi->inf->yres)
  348. var->yres = fbi->inf->yres;
  349. var->xres_virtual = max(var->xres_virtual, var->xres);
  350. var->yres_virtual = max(var->yres_virtual, var->yres);
  351. dev_dbg(fbi->dev, "var->bits_per_pixel=%d\n", var->bits_per_pixel);
  352. switch (var->bits_per_pixel) {
  353. case 4:
  354. rgbidx = RGB_4;
  355. break;
  356. case 8:
  357. rgbidx = RGB_8;
  358. break;
  359. case 16:
  360. rgbidx = RGB_16;
  361. break;
  362. default:
  363. return -EINVAL;
  364. }
  365. /*
  366. * Copy the RGB parameters for this display
  367. * from the machine specific parameters.
  368. */
  369. var->red = fbi->rgb[rgbidx]->red;
  370. var->green = fbi->rgb[rgbidx]->green;
  371. var->blue = fbi->rgb[rgbidx]->blue;
  372. var->transp = fbi->rgb[rgbidx]->transp;
  373. dev_dbg(fbi->dev, "RGBT length = %d:%d:%d:%d\n",
  374. var->red.length, var->green.length, var->blue.length,
  375. var->transp.length);
  376. dev_dbg(fbi->dev, "RGBT offset = %d:%d:%d:%d\n",
  377. var->red.offset, var->green.offset, var->blue.offset,
  378. var->transp.offset);
  379. #ifdef CONFIG_CPU_FREQ
  380. dev_dbg(fbi->dev, "dma period = %d ps, clock = %d kHz\n",
  381. sa1100fb_display_dma_period(var),
  382. cpufreq_get(smp_processor_id()));
  383. #endif
  384. return 0;
  385. }
  386. static void sa1100fb_set_visual(struct sa1100fb_info *fbi, u32 visual)
  387. {
  388. if (fbi->inf->set_visual)
  389. fbi->inf->set_visual(visual);
  390. }
  391. /*
  392. * sa1100fb_set_par():
  393. * Set the user defined part of the display for the specified console
  394. */
  395. static int sa1100fb_set_par(struct fb_info *info)
  396. {
  397. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  398. struct fb_var_screeninfo *var = &info->var;
  399. unsigned long palette_mem_size;
  400. dev_dbg(fbi->dev, "set_par\n");
  401. if (var->bits_per_pixel == 16)
  402. fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  403. else if (!fbi->inf->cmap_static)
  404. fbi->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  405. else {
  406. /*
  407. * Some people have weird ideas about wanting static
  408. * pseudocolor maps. I suspect their user space
  409. * applications are broken.
  410. */
  411. fbi->fb.fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
  412. }
  413. fbi->fb.fix.line_length = var->xres_virtual *
  414. var->bits_per_pixel / 8;
  415. fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16;
  416. palette_mem_size = fbi->palette_size * sizeof(u16);
  417. dev_dbg(fbi->dev, "palette_mem_size = 0x%08lx\n", palette_mem_size);
  418. fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size);
  419. fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
  420. /*
  421. * Set (any) board control register to handle new color depth
  422. */
  423. sa1100fb_set_visual(fbi, fbi->fb.fix.visual);
  424. sa1100fb_activate_var(var, fbi);
  425. return 0;
  426. }
  427. #if 0
  428. static int
  429. sa1100fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
  430. struct fb_info *info)
  431. {
  432. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  433. /*
  434. * Make sure the user isn't doing something stupid.
  435. */
  436. if (!kspc && (fbi->fb.var.bits_per_pixel == 16 || fbi->inf->cmap_static))
  437. return -EINVAL;
  438. return gen_set_cmap(cmap, kspc, con, info);
  439. }
  440. #endif
  441. /*
  442. * Formal definition of the VESA spec:
  443. * On
  444. * This refers to the state of the display when it is in full operation
  445. * Stand-By
  446. * This defines an optional operating state of minimal power reduction with
  447. * the shortest recovery time
  448. * Suspend
  449. * This refers to a level of power management in which substantial power
  450. * reduction is achieved by the display. The display can have a longer
  451. * recovery time from this state than from the Stand-by state
  452. * Off
  453. * This indicates that the display is consuming the lowest level of power
  454. * and is non-operational. Recovery from this state may optionally require
  455. * the user to manually power on the monitor
  456. *
  457. * Now, the fbdev driver adds an additional state, (blank), where they
  458. * turn off the video (maybe by colormap tricks), but don't mess with the
  459. * video itself: think of it semantically between on and Stand-By.
  460. *
  461. * So here's what we should do in our fbdev blank routine:
  462. *
  463. * VESA_NO_BLANKING (mode 0) Video on, front/back light on
  464. * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
  465. * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
  466. * VESA_POWERDOWN (mode 3) Video off, front/back light off
  467. *
  468. * This will match the matrox implementation.
  469. */
  470. /*
  471. * sa1100fb_blank():
  472. * Blank the display by setting all palette values to zero. Note, the
  473. * 12 and 16 bpp modes don't really use the palette, so this will not
  474. * blank the display in all modes.
  475. */
  476. static int sa1100fb_blank(int blank, struct fb_info *info)
  477. {
  478. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  479. int i;
  480. dev_dbg(fbi->dev, "sa1100fb_blank: blank=%d\n", blank);
  481. switch (blank) {
  482. case FB_BLANK_POWERDOWN:
  483. case FB_BLANK_VSYNC_SUSPEND:
  484. case FB_BLANK_HSYNC_SUSPEND:
  485. case FB_BLANK_NORMAL:
  486. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  487. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  488. for (i = 0; i < fbi->palette_size; i++)
  489. sa1100fb_setpalettereg(i, 0, 0, 0, 0, info);
  490. sa1100fb_schedule_work(fbi, C_DISABLE);
  491. break;
  492. case FB_BLANK_UNBLANK:
  493. if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
  494. fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
  495. fb_set_cmap(&fbi->fb.cmap, info);
  496. sa1100fb_schedule_work(fbi, C_ENABLE);
  497. }
  498. return 0;
  499. }
  500. static int sa1100fb_mmap(struct fb_info *info,
  501. struct vm_area_struct *vma)
  502. {
  503. struct sa1100fb_info *fbi = (struct sa1100fb_info *)info;
  504. unsigned long start, len, off = vma->vm_pgoff << PAGE_SHIFT;
  505. if (off < info->fix.smem_len) {
  506. vma->vm_pgoff += 1; /* skip over the palette */
  507. return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
  508. fbi->map_dma, fbi->map_size);
  509. }
  510. start = info->fix.mmio_start;
  511. len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
  512. if ((vma->vm_end - vma->vm_start + off) > len)
  513. return -EINVAL;
  514. off += start & PAGE_MASK;
  515. vma->vm_pgoff = off >> PAGE_SHIFT;
  516. vma->vm_flags |= VM_IO;
  517. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  518. return io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
  519. vma->vm_end - vma->vm_start,
  520. vma->vm_page_prot);
  521. }
  522. static struct fb_ops sa1100fb_ops = {
  523. .owner = THIS_MODULE,
  524. .fb_check_var = sa1100fb_check_var,
  525. .fb_set_par = sa1100fb_set_par,
  526. // .fb_set_cmap = sa1100fb_set_cmap,
  527. .fb_setcolreg = sa1100fb_setcolreg,
  528. .fb_fillrect = cfb_fillrect,
  529. .fb_copyarea = cfb_copyarea,
  530. .fb_imageblit = cfb_imageblit,
  531. .fb_blank = sa1100fb_blank,
  532. .fb_mmap = sa1100fb_mmap,
  533. };
  534. /*
  535. * Calculate the PCD value from the clock rate (in picoseconds).
  536. * We take account of the PPCR clock setting.
  537. */
  538. static inline unsigned int get_pcd(unsigned int pixclock, unsigned int cpuclock)
  539. {
  540. unsigned int pcd = cpuclock / 100;
  541. pcd *= pixclock;
  542. pcd /= 10000000;
  543. return pcd + 1; /* make up for integer math truncations */
  544. }
  545. /*
  546. * sa1100fb_activate_var():
  547. * Configures LCD Controller based on entries in var parameter. Settings are
  548. * only written to the controller if changes were made.
  549. */
  550. static int sa1100fb_activate_var(struct fb_var_screeninfo *var, struct sa1100fb_info *fbi)
  551. {
  552. struct sa1100fb_lcd_reg new_regs;
  553. u_int half_screen_size, yres, pcd;
  554. u_long flags;
  555. dev_dbg(fbi->dev, "Configuring SA1100 LCD\n");
  556. dev_dbg(fbi->dev, "var: xres=%d hslen=%d lm=%d rm=%d\n",
  557. var->xres, var->hsync_len,
  558. var->left_margin, var->right_margin);
  559. dev_dbg(fbi->dev, "var: yres=%d vslen=%d um=%d bm=%d\n",
  560. var->yres, var->vsync_len,
  561. var->upper_margin, var->lower_margin);
  562. #if DEBUG_VAR
  563. if (var->xres < 16 || var->xres > 1024)
  564. dev_err(fbi->dev, "%s: invalid xres %d\n",
  565. fbi->fb.fix.id, var->xres);
  566. if (var->hsync_len < 1 || var->hsync_len > 64)
  567. dev_err(fbi->dev, "%s: invalid hsync_len %d\n",
  568. fbi->fb.fix.id, var->hsync_len);
  569. if (var->left_margin < 1 || var->left_margin > 255)
  570. dev_err(fbi->dev, "%s: invalid left_margin %d\n",
  571. fbi->fb.fix.id, var->left_margin);
  572. if (var->right_margin < 1 || var->right_margin > 255)
  573. dev_err(fbi->dev, "%s: invalid right_margin %d\n",
  574. fbi->fb.fix.id, var->right_margin);
  575. if (var->yres < 1 || var->yres > 1024)
  576. dev_err(fbi->dev, "%s: invalid yres %d\n",
  577. fbi->fb.fix.id, var->yres);
  578. if (var->vsync_len < 1 || var->vsync_len > 64)
  579. dev_err(fbi->dev, "%s: invalid vsync_len %d\n",
  580. fbi->fb.fix.id, var->vsync_len);
  581. if (var->upper_margin < 0 || var->upper_margin > 255)
  582. dev_err(fbi->dev, "%s: invalid upper_margin %d\n",
  583. fbi->fb.fix.id, var->upper_margin);
  584. if (var->lower_margin < 0 || var->lower_margin > 255)
  585. dev_err(fbi->dev, "%s: invalid lower_margin %d\n",
  586. fbi->fb.fix.id, var->lower_margin);
  587. #endif
  588. new_regs.lccr0 = fbi->inf->lccr0 |
  589. LCCR0_LEN | LCCR0_LDM | LCCR0_BAM |
  590. LCCR0_ERM | LCCR0_LtlEnd | LCCR0_DMADel(0);
  591. new_regs.lccr1 =
  592. LCCR1_DisWdth(var->xres) +
  593. LCCR1_HorSnchWdth(var->hsync_len) +
  594. LCCR1_BegLnDel(var->left_margin) +
  595. LCCR1_EndLnDel(var->right_margin);
  596. /*
  597. * If we have a dual scan LCD, then we need to halve
  598. * the YRES parameter.
  599. */
  600. yres = var->yres;
  601. if (fbi->inf->lccr0 & LCCR0_Dual)
  602. yres /= 2;
  603. new_regs.lccr2 =
  604. LCCR2_DisHght(yres) +
  605. LCCR2_VrtSnchWdth(var->vsync_len) +
  606. LCCR2_BegFrmDel(var->upper_margin) +
  607. LCCR2_EndFrmDel(var->lower_margin);
  608. pcd = get_pcd(var->pixclock, cpufreq_get(0));
  609. new_regs.lccr3 = LCCR3_PixClkDiv(pcd) | fbi->inf->lccr3 |
  610. (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) |
  611. (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL);
  612. dev_dbg(fbi->dev, "nlccr0 = 0x%08lx\n", new_regs.lccr0);
  613. dev_dbg(fbi->dev, "nlccr1 = 0x%08lx\n", new_regs.lccr1);
  614. dev_dbg(fbi->dev, "nlccr2 = 0x%08lx\n", new_regs.lccr2);
  615. dev_dbg(fbi->dev, "nlccr3 = 0x%08lx\n", new_regs.lccr3);
  616. half_screen_size = var->bits_per_pixel;
  617. half_screen_size = half_screen_size * var->xres * var->yres / 16;
  618. /* Update shadow copy atomically */
  619. local_irq_save(flags);
  620. fbi->dbar1 = fbi->palette_dma;
  621. fbi->dbar2 = fbi->screen_dma + half_screen_size;
  622. fbi->reg_lccr0 = new_regs.lccr0;
  623. fbi->reg_lccr1 = new_regs.lccr1;
  624. fbi->reg_lccr2 = new_regs.lccr2;
  625. fbi->reg_lccr3 = new_regs.lccr3;
  626. local_irq_restore(flags);
  627. /*
  628. * Only update the registers if the controller is enabled
  629. * and something has changed.
  630. */
  631. if (readl_relaxed(fbi->base + LCCR0) != fbi->reg_lccr0 ||
  632. readl_relaxed(fbi->base + LCCR1) != fbi->reg_lccr1 ||
  633. readl_relaxed(fbi->base + LCCR2) != fbi->reg_lccr2 ||
  634. readl_relaxed(fbi->base + LCCR3) != fbi->reg_lccr3 ||
  635. readl_relaxed(fbi->base + DBAR1) != fbi->dbar1 ||
  636. readl_relaxed(fbi->base + DBAR2) != fbi->dbar2)
  637. sa1100fb_schedule_work(fbi, C_REENABLE);
  638. return 0;
  639. }
  640. /*
  641. * NOTE! The following functions are purely helpers for set_ctrlr_state.
  642. * Do not call them directly; set_ctrlr_state does the correct serialisation
  643. * to ensure that things happen in the right way 100% of time time.
  644. * -- rmk
  645. */
  646. static inline void __sa1100fb_backlight_power(struct sa1100fb_info *fbi, int on)
  647. {
  648. dev_dbg(fbi->dev, "backlight o%s\n", on ? "n" : "ff");
  649. if (fbi->inf->backlight_power)
  650. fbi->inf->backlight_power(on);
  651. }
  652. static inline void __sa1100fb_lcd_power(struct sa1100fb_info *fbi, int on)
  653. {
  654. dev_dbg(fbi->dev, "LCD power o%s\n", on ? "n" : "ff");
  655. if (fbi->inf->lcd_power)
  656. fbi->inf->lcd_power(on);
  657. }
  658. static void sa1100fb_setup_gpio(struct sa1100fb_info *fbi)
  659. {
  660. u_int mask = 0;
  661. /*
  662. * Enable GPIO<9:2> for LCD use if:
  663. * 1. Active display, or
  664. * 2. Color Dual Passive display
  665. *
  666. * see table 11.8 on page 11-27 in the SA1100 manual
  667. * -- Erik.
  668. *
  669. * SA1110 spec update nr. 25 says we can and should
  670. * clear LDD15 to 12 for 4 or 8bpp modes with active
  671. * panels.
  672. */
  673. if ((fbi->reg_lccr0 & LCCR0_CMS) == LCCR0_Color &&
  674. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) != 0) {
  675. mask = GPIO_LDD11 | GPIO_LDD10 | GPIO_LDD9 | GPIO_LDD8;
  676. if (fbi->fb.var.bits_per_pixel > 8 ||
  677. (fbi->reg_lccr0 & (LCCR0_Dual|LCCR0_Act)) == LCCR0_Dual)
  678. mask |= GPIO_LDD15 | GPIO_LDD14 | GPIO_LDD13 | GPIO_LDD12;
  679. }
  680. if (mask) {
  681. unsigned long flags;
  682. /*
  683. * SA-1100 requires the GPIO direction register set
  684. * appropriately for the alternate function. Hence
  685. * we set it here via bitmask rather than excessive
  686. * fiddling via the GPIO subsystem - and even then
  687. * we'll still have to deal with GAFR.
  688. */
  689. local_irq_save(flags);
  690. GPDR |= mask;
  691. GAFR |= mask;
  692. local_irq_restore(flags);
  693. }
  694. }
  695. static void sa1100fb_enable_controller(struct sa1100fb_info *fbi)
  696. {
  697. dev_dbg(fbi->dev, "Enabling LCD controller\n");
  698. /*
  699. * Make sure the mode bits are present in the first palette entry
  700. */
  701. fbi->palette_cpu[0] &= 0xcfff;
  702. fbi->palette_cpu[0] |= palette_pbs(&fbi->fb.var);
  703. /* Sequence from 11.7.10 */
  704. writel_relaxed(fbi->reg_lccr3, fbi->base + LCCR3);
  705. writel_relaxed(fbi->reg_lccr2, fbi->base + LCCR2);
  706. writel_relaxed(fbi->reg_lccr1, fbi->base + LCCR1);
  707. writel_relaxed(fbi->reg_lccr0 & ~LCCR0_LEN, fbi->base + LCCR0);
  708. writel_relaxed(fbi->dbar1, fbi->base + DBAR1);
  709. writel_relaxed(fbi->dbar2, fbi->base + DBAR2);
  710. writel_relaxed(fbi->reg_lccr0 | LCCR0_LEN, fbi->base + LCCR0);
  711. if (machine_is_shannon())
  712. gpio_set_value(SHANNON_GPIO_DISP_EN, 1);
  713. dev_dbg(fbi->dev, "DBAR1: 0x%08x\n", readl_relaxed(fbi->base + DBAR1));
  714. dev_dbg(fbi->dev, "DBAR2: 0x%08x\n", readl_relaxed(fbi->base + DBAR2));
  715. dev_dbg(fbi->dev, "LCCR0: 0x%08x\n", readl_relaxed(fbi->base + LCCR0));
  716. dev_dbg(fbi->dev, "LCCR1: 0x%08x\n", readl_relaxed(fbi->base + LCCR1));
  717. dev_dbg(fbi->dev, "LCCR2: 0x%08x\n", readl_relaxed(fbi->base + LCCR2));
  718. dev_dbg(fbi->dev, "LCCR3: 0x%08x\n", readl_relaxed(fbi->base + LCCR3));
  719. }
  720. static void sa1100fb_disable_controller(struct sa1100fb_info *fbi)
  721. {
  722. DECLARE_WAITQUEUE(wait, current);
  723. u32 lccr0;
  724. dev_dbg(fbi->dev, "Disabling LCD controller\n");
  725. if (machine_is_shannon())
  726. gpio_set_value(SHANNON_GPIO_DISP_EN, 0);
  727. set_current_state(TASK_UNINTERRUPTIBLE);
  728. add_wait_queue(&fbi->ctrlr_wait, &wait);
  729. /* Clear LCD Status Register */
  730. writel_relaxed(~0, fbi->base + LCSR);
  731. lccr0 = readl_relaxed(fbi->base + LCCR0);
  732. lccr0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
  733. writel_relaxed(lccr0, fbi->base + LCCR0);
  734. lccr0 &= ~LCCR0_LEN; /* Disable LCD Controller */
  735. writel_relaxed(lccr0, fbi->base + LCCR0);
  736. schedule_timeout(20 * HZ / 1000);
  737. remove_wait_queue(&fbi->ctrlr_wait, &wait);
  738. }
  739. /*
  740. * sa1100fb_handle_irq: Handle 'LCD DONE' interrupts.
  741. */
  742. static irqreturn_t sa1100fb_handle_irq(int irq, void *dev_id)
  743. {
  744. struct sa1100fb_info *fbi = dev_id;
  745. unsigned int lcsr = readl_relaxed(fbi->base + LCSR);
  746. if (lcsr & LCSR_LDD) {
  747. u32 lccr0 = readl_relaxed(fbi->base + LCCR0) | LCCR0_LDM;
  748. writel_relaxed(lccr0, fbi->base + LCCR0);
  749. wake_up(&fbi->ctrlr_wait);
  750. }
  751. writel_relaxed(lcsr, fbi->base + LCSR);
  752. return IRQ_HANDLED;
  753. }
  754. /*
  755. * This function must be called from task context only, since it will
  756. * sleep when disabling the LCD controller, or if we get two contending
  757. * processes trying to alter state.
  758. */
  759. static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
  760. {
  761. u_int old_state;
  762. mutex_lock(&fbi->ctrlr_lock);
  763. old_state = fbi->state;
  764. /*
  765. * Hack around fbcon initialisation.
  766. */
  767. if (old_state == C_STARTUP && state == C_REENABLE)
  768. state = C_ENABLE;
  769. switch (state) {
  770. case C_DISABLE_CLKCHANGE:
  771. /*
  772. * Disable controller for clock change. If the
  773. * controller is already disabled, then do nothing.
  774. */
  775. if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
  776. fbi->state = state;
  777. sa1100fb_disable_controller(fbi);
  778. }
  779. break;
  780. case C_DISABLE_PM:
  781. case C_DISABLE:
  782. /*
  783. * Disable controller
  784. */
  785. if (old_state != C_DISABLE) {
  786. fbi->state = state;
  787. __sa1100fb_backlight_power(fbi, 0);
  788. if (old_state != C_DISABLE_CLKCHANGE)
  789. sa1100fb_disable_controller(fbi);
  790. __sa1100fb_lcd_power(fbi, 0);
  791. }
  792. break;
  793. case C_ENABLE_CLKCHANGE:
  794. /*
  795. * Enable the controller after clock change. Only
  796. * do this if we were disabled for the clock change.
  797. */
  798. if (old_state == C_DISABLE_CLKCHANGE) {
  799. fbi->state = C_ENABLE;
  800. sa1100fb_enable_controller(fbi);
  801. }
  802. break;
  803. case C_REENABLE:
  804. /*
  805. * Re-enable the controller only if it was already
  806. * enabled. This is so we reprogram the control
  807. * registers.
  808. */
  809. if (old_state == C_ENABLE) {
  810. sa1100fb_disable_controller(fbi);
  811. sa1100fb_setup_gpio(fbi);
  812. sa1100fb_enable_controller(fbi);
  813. }
  814. break;
  815. case C_ENABLE_PM:
  816. /*
  817. * Re-enable the controller after PM. This is not
  818. * perfect - think about the case where we were doing
  819. * a clock change, and we suspended half-way through.
  820. */
  821. if (old_state != C_DISABLE_PM)
  822. break;
  823. /* fall through */
  824. case C_ENABLE:
  825. /*
  826. * Power up the LCD screen, enable controller, and
  827. * turn on the backlight.
  828. */
  829. if (old_state != C_ENABLE) {
  830. fbi->state = C_ENABLE;
  831. sa1100fb_setup_gpio(fbi);
  832. __sa1100fb_lcd_power(fbi, 1);
  833. sa1100fb_enable_controller(fbi);
  834. __sa1100fb_backlight_power(fbi, 1);
  835. }
  836. break;
  837. }
  838. mutex_unlock(&fbi->ctrlr_lock);
  839. }
  840. /*
  841. * Our LCD controller task (which is called when we blank or unblank)
  842. * via keventd.
  843. */
  844. static void sa1100fb_task(struct work_struct *w)
  845. {
  846. struct sa1100fb_info *fbi = container_of(w, struct sa1100fb_info, task);
  847. u_int state = xchg(&fbi->task_state, -1);
  848. set_ctrlr_state(fbi, state);
  849. }
  850. #ifdef CONFIG_CPU_FREQ
  851. /*
  852. * Calculate the minimum DMA period over all displays that we own.
  853. * This, together with the SDRAM bandwidth defines the slowest CPU
  854. * frequency that can be selected.
  855. */
  856. static unsigned int sa1100fb_min_dma_period(struct sa1100fb_info *fbi)
  857. {
  858. #if 0
  859. unsigned int min_period = (unsigned int)-1;
  860. int i;
  861. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  862. struct display *disp = &fb_display[i];
  863. unsigned int period;
  864. /*
  865. * Do we own this display?
  866. */
  867. if (disp->fb_info != &fbi->fb)
  868. continue;
  869. /*
  870. * Ok, calculate its DMA period
  871. */
  872. period = sa1100fb_display_dma_period(&disp->var);
  873. if (period < min_period)
  874. min_period = period;
  875. }
  876. return min_period;
  877. #else
  878. /*
  879. * FIXME: we need to verify _all_ consoles.
  880. */
  881. return sa1100fb_display_dma_period(&fbi->fb.var);
  882. #endif
  883. }
  884. /*
  885. * CPU clock speed change handler. We need to adjust the LCD timing
  886. * parameters when the CPU clock is adjusted by the power management
  887. * subsystem.
  888. */
  889. static int
  890. sa1100fb_freq_transition(struct notifier_block *nb, unsigned long val,
  891. void *data)
  892. {
  893. struct sa1100fb_info *fbi = TO_INF(nb, freq_transition);
  894. struct cpufreq_freqs *f = data;
  895. u_int pcd;
  896. switch (val) {
  897. case CPUFREQ_PRECHANGE:
  898. set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE);
  899. break;
  900. case CPUFREQ_POSTCHANGE:
  901. pcd = get_pcd(fbi->fb.var.pixclock, f->new);
  902. fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd);
  903. set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
  904. break;
  905. }
  906. return 0;
  907. }
  908. static int
  909. sa1100fb_freq_policy(struct notifier_block *nb, unsigned long val,
  910. void *data)
  911. {
  912. struct sa1100fb_info *fbi = TO_INF(nb, freq_policy);
  913. struct cpufreq_policy *policy = data;
  914. switch (val) {
  915. case CPUFREQ_ADJUST:
  916. case CPUFREQ_INCOMPATIBLE:
  917. dev_dbg(fbi->dev, "min dma period: %d ps, "
  918. "new clock %d kHz\n", sa1100fb_min_dma_period(fbi),
  919. policy->max);
  920. /* todo: fill in min/max values */
  921. break;
  922. case CPUFREQ_NOTIFY:
  923. do {} while(0);
  924. /* todo: panic if min/max values aren't fulfilled
  925. * [can't really happen unless there's a bug in the
  926. * CPU policy verififcation process *
  927. */
  928. break;
  929. }
  930. return 0;
  931. }
  932. #endif
  933. #ifdef CONFIG_PM
  934. /*
  935. * Power management hooks. Note that we won't be called from IRQ context,
  936. * unlike the blank functions above, so we may sleep.
  937. */
  938. static int sa1100fb_suspend(struct platform_device *dev, pm_message_t state)
  939. {
  940. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  941. set_ctrlr_state(fbi, C_DISABLE_PM);
  942. return 0;
  943. }
  944. static int sa1100fb_resume(struct platform_device *dev)
  945. {
  946. struct sa1100fb_info *fbi = platform_get_drvdata(dev);
  947. set_ctrlr_state(fbi, C_ENABLE_PM);
  948. return 0;
  949. }
  950. #else
  951. #define sa1100fb_suspend NULL
  952. #define sa1100fb_resume NULL
  953. #endif
  954. /*
  955. * sa1100fb_map_video_memory():
  956. * Allocates the DRAM memory for the frame buffer. This buffer is
  957. * remapped into a non-cached, non-buffered, memory region to
  958. * allow palette and pixel writes to occur without flushing the
  959. * cache. Once this area is remapped, all virtual memory
  960. * access to the video memory should occur at the new region.
  961. */
  962. static int __devinit sa1100fb_map_video_memory(struct sa1100fb_info *fbi)
  963. {
  964. /*
  965. * We reserve one page for the palette, plus the size
  966. * of the framebuffer.
  967. */
  968. fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE);
  969. fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
  970. &fbi->map_dma, GFP_KERNEL);
  971. if (fbi->map_cpu) {
  972. fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE;
  973. fbi->screen_dma = fbi->map_dma + PAGE_SIZE;
  974. /*
  975. * FIXME: this is actually the wrong thing to place in
  976. * smem_start. But fbdev suffers from the problem that
  977. * it needs an API which doesn't exist (in this case,
  978. * dma_writecombine_mmap)
  979. */
  980. fbi->fb.fix.smem_start = fbi->screen_dma;
  981. }
  982. return fbi->map_cpu ? 0 : -ENOMEM;
  983. }
  984. /* Fake monspecs to fill in fbinfo structure */
  985. static struct fb_monspecs monspecs __devinitdata = {
  986. .hfmin = 30000,
  987. .hfmax = 70000,
  988. .vfmin = 50,
  989. .vfmax = 65,
  990. };
  991. static struct sa1100fb_info * __devinit sa1100fb_init_fbinfo(struct device *dev)
  992. {
  993. struct sa1100fb_mach_info *inf = dev->platform_data;
  994. struct sa1100fb_info *fbi;
  995. unsigned i;
  996. fbi = kmalloc(sizeof(struct sa1100fb_info) + sizeof(u32) * 16,
  997. GFP_KERNEL);
  998. if (!fbi)
  999. return NULL;
  1000. memset(fbi, 0, sizeof(struct sa1100fb_info));
  1001. fbi->dev = dev;
  1002. strcpy(fbi->fb.fix.id, SA1100_NAME);
  1003. fbi->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  1004. fbi->fb.fix.type_aux = 0;
  1005. fbi->fb.fix.xpanstep = 0;
  1006. fbi->fb.fix.ypanstep = 0;
  1007. fbi->fb.fix.ywrapstep = 0;
  1008. fbi->fb.fix.accel = FB_ACCEL_NONE;
  1009. fbi->fb.var.nonstd = 0;
  1010. fbi->fb.var.activate = FB_ACTIVATE_NOW;
  1011. fbi->fb.var.height = -1;
  1012. fbi->fb.var.width = -1;
  1013. fbi->fb.var.accel_flags = 0;
  1014. fbi->fb.var.vmode = FB_VMODE_NONINTERLACED;
  1015. fbi->fb.fbops = &sa1100fb_ops;
  1016. fbi->fb.flags = FBINFO_DEFAULT;
  1017. fbi->fb.monspecs = monspecs;
  1018. fbi->fb.pseudo_palette = (fbi + 1);
  1019. fbi->rgb[RGB_4] = &rgb_4;
  1020. fbi->rgb[RGB_8] = &rgb_8;
  1021. fbi->rgb[RGB_16] = &def_rgb_16;
  1022. /*
  1023. * People just don't seem to get this. We don't support
  1024. * anything but correct entries now, so panic if someone
  1025. * does something stupid.
  1026. */
  1027. if (inf->lccr3 & (LCCR3_VrtSnchL|LCCR3_HorSnchL|0xff) ||
  1028. inf->pixclock == 0)
  1029. panic("sa1100fb error: invalid LCCR3 fields set or zero "
  1030. "pixclock.");
  1031. fbi->fb.var.xres = inf->xres;
  1032. fbi->fb.var.xres_virtual = inf->xres;
  1033. fbi->fb.var.yres = inf->yres;
  1034. fbi->fb.var.yres_virtual = inf->yres;
  1035. fbi->fb.var.bits_per_pixel = inf->bpp;
  1036. fbi->fb.var.pixclock = inf->pixclock;
  1037. fbi->fb.var.hsync_len = inf->hsync_len;
  1038. fbi->fb.var.left_margin = inf->left_margin;
  1039. fbi->fb.var.right_margin = inf->right_margin;
  1040. fbi->fb.var.vsync_len = inf->vsync_len;
  1041. fbi->fb.var.upper_margin = inf->upper_margin;
  1042. fbi->fb.var.lower_margin = inf->lower_margin;
  1043. fbi->fb.var.sync = inf->sync;
  1044. fbi->fb.var.grayscale = inf->cmap_greyscale;
  1045. fbi->state = C_STARTUP;
  1046. fbi->task_state = (u_char)-1;
  1047. fbi->fb.fix.smem_len = inf->xres * inf->yres *
  1048. inf->bpp / 8;
  1049. fbi->inf = inf;
  1050. /* Copy the RGB bitfield overrides */
  1051. for (i = 0; i < NR_RGB; i++)
  1052. if (inf->rgb[i])
  1053. fbi->rgb[i] = inf->rgb[i];
  1054. init_waitqueue_head(&fbi->ctrlr_wait);
  1055. INIT_WORK(&fbi->task, sa1100fb_task);
  1056. mutex_init(&fbi->ctrlr_lock);
  1057. return fbi;
  1058. }
  1059. static int __devinit sa1100fb_probe(struct platform_device *pdev)
  1060. {
  1061. struct sa1100fb_info *fbi;
  1062. struct resource *res;
  1063. int ret, irq;
  1064. if (!pdev->dev.platform_data) {
  1065. dev_err(&pdev->dev, "no platform LCD data\n");
  1066. return -EINVAL;
  1067. }
  1068. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1069. irq = platform_get_irq(pdev, 0);
  1070. if (irq < 0 || !res)
  1071. return -EINVAL;
  1072. if (!request_mem_region(res->start, resource_size(res), "LCD"))
  1073. return -EBUSY;
  1074. fbi = sa1100fb_init_fbinfo(&pdev->dev);
  1075. ret = -ENOMEM;
  1076. if (!fbi)
  1077. goto failed;
  1078. fbi->base = ioremap(res->start, resource_size(res));
  1079. if (!fbi->base)
  1080. goto failed;
  1081. /* Initialize video memory */
  1082. ret = sa1100fb_map_video_memory(fbi);
  1083. if (ret)
  1084. goto failed;
  1085. ret = request_irq(irq, sa1100fb_handle_irq, 0, "LCD", fbi);
  1086. if (ret) {
  1087. dev_err(&pdev->dev, "request_irq failed: %d\n", ret);
  1088. goto failed;
  1089. }
  1090. if (machine_is_shannon()) {
  1091. ret = gpio_request_one(SHANNON_GPIO_DISP_EN,
  1092. GPIOF_OUT_INIT_LOW, "display enable");
  1093. if (ret)
  1094. goto err_free_irq;
  1095. }
  1096. /*
  1097. * This makes sure that our colour bitfield
  1098. * descriptors are correctly initialised.
  1099. */
  1100. sa1100fb_check_var(&fbi->fb.var, &fbi->fb);
  1101. platform_set_drvdata(pdev, fbi);
  1102. ret = register_framebuffer(&fbi->fb);
  1103. if (ret < 0)
  1104. goto err_reg_fb;
  1105. #ifdef CONFIG_CPU_FREQ
  1106. fbi->freq_transition.notifier_call = sa1100fb_freq_transition;
  1107. fbi->freq_policy.notifier_call = sa1100fb_freq_policy;
  1108. cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER);
  1109. cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER);
  1110. #endif
  1111. /* This driver cannot be unloaded at the moment */
  1112. return 0;
  1113. err_reg_fb:
  1114. if (machine_is_shannon())
  1115. gpio_free(SHANNON_GPIO_DISP_EN);
  1116. err_free_irq:
  1117. free_irq(irq, fbi);
  1118. failed:
  1119. if (fbi)
  1120. iounmap(fbi->base);
  1121. platform_set_drvdata(pdev, NULL);
  1122. kfree(fbi);
  1123. release_mem_region(res->start, resource_size(res));
  1124. return ret;
  1125. }
  1126. static struct platform_driver sa1100fb_driver = {
  1127. .probe = sa1100fb_probe,
  1128. .suspend = sa1100fb_suspend,
  1129. .resume = sa1100fb_resume,
  1130. .driver = {
  1131. .name = "sa11x0-fb",
  1132. .owner = THIS_MODULE,
  1133. },
  1134. };
  1135. int __init sa1100fb_init(void)
  1136. {
  1137. if (fb_get_options("sa1100fb", NULL))
  1138. return -ENODEV;
  1139. return platform_driver_register(&sa1100fb_driver);
  1140. }
  1141. int __init sa1100fb_setup(char *options)
  1142. {
  1143. #if 0
  1144. char *this_opt;
  1145. if (!options || !*options)
  1146. return 0;
  1147. while ((this_opt = strsep(&options, ",")) != NULL) {
  1148. if (!strncmp(this_opt, "bpp:", 4))
  1149. current_par.max_bpp =
  1150. simple_strtoul(this_opt + 4, NULL, 0);
  1151. if (!strncmp(this_opt, "lccr0:", 6))
  1152. lcd_shadow.lccr0 =
  1153. simple_strtoul(this_opt + 6, NULL, 0);
  1154. if (!strncmp(this_opt, "lccr1:", 6)) {
  1155. lcd_shadow.lccr1 =
  1156. simple_strtoul(this_opt + 6, NULL, 0);
  1157. current_par.max_xres =
  1158. (lcd_shadow.lccr1 & 0x3ff) + 16;
  1159. }
  1160. if (!strncmp(this_opt, "lccr2:", 6)) {
  1161. lcd_shadow.lccr2 =
  1162. simple_strtoul(this_opt + 6, NULL, 0);
  1163. current_par.max_yres =
  1164. (lcd_shadow.
  1165. lccr0 & LCCR0_SDS) ? ((lcd_shadow.
  1166. lccr2 & 0x3ff) +
  1167. 1) *
  1168. 2 : ((lcd_shadow.lccr2 & 0x3ff) + 1);
  1169. }
  1170. if (!strncmp(this_opt, "lccr3:", 6))
  1171. lcd_shadow.lccr3 =
  1172. simple_strtoul(this_opt + 6, NULL, 0);
  1173. }
  1174. #endif
  1175. return 0;
  1176. }
  1177. module_init(sa1100fb_init);
  1178. MODULE_DESCRIPTION("StrongARM-1100/1110 framebuffer driver");
  1179. MODULE_LICENSE("GPL");