sa1100fb.c 42 KB

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