au1200fb.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Au1200 LCD Driver.
  4. *
  5. * Copyright 2004-2005 AMD
  6. * Author: AMD
  7. *
  8. * Based on:
  9. * linux/drivers/video/skeletonfb.c -- Skeleton for a frame buffer device
  10. * Created 28 Dec 1997 by Geert Uytterhoeven
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  20. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  23. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * You should have received a copy of the GNU General Public License along
  29. * with this program; if not, write to the Free Software Foundation, Inc.,
  30. * 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #include <linux/clk.h>
  33. #include <linux/module.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/kernel.h>
  36. #include <linux/errno.h>
  37. #include <linux/string.h>
  38. #include <linux/mm.h>
  39. #include <linux/fb.h>
  40. #include <linux/init.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/ctype.h>
  43. #include <linux/dma-mapping.h>
  44. #include <linux/slab.h>
  45. #include <linux/uaccess.h>
  46. #include <asm/mach-au1x00/au1000.h>
  47. #include <asm/mach-au1x00/au1200fb.h> /* platform_data */
  48. #include "au1200fb.h"
  49. #define DRIVER_NAME "au1200fb"
  50. #define DRIVER_DESC "LCD controller driver for AU1200 processors"
  51. #define DEBUG 0
  52. #define print_err(f, arg...) printk(KERN_ERR DRIVER_NAME ": " f "\n", ## arg)
  53. #define print_warn(f, arg...) printk(KERN_WARNING DRIVER_NAME ": " f "\n", ## arg)
  54. #define print_info(f, arg...) printk(KERN_INFO DRIVER_NAME ": " f "\n", ## arg)
  55. #if DEBUG
  56. #define print_dbg(f, arg...) printk(KERN_DEBUG __FILE__ ": " f "\n", ## arg)
  57. #else
  58. #define print_dbg(f, arg...) do {} while (0)
  59. #endif
  60. #define AU1200_LCD_FB_IOCTL 0x46FF
  61. #define AU1200_LCD_SET_SCREEN 1
  62. #define AU1200_LCD_GET_SCREEN 2
  63. #define AU1200_LCD_SET_WINDOW 3
  64. #define AU1200_LCD_GET_WINDOW 4
  65. #define AU1200_LCD_SET_PANEL 5
  66. #define AU1200_LCD_GET_PANEL 6
  67. #define SCREEN_SIZE (1<< 1)
  68. #define SCREEN_BACKCOLOR (1<< 2)
  69. #define SCREEN_BRIGHTNESS (1<< 3)
  70. #define SCREEN_COLORKEY (1<< 4)
  71. #define SCREEN_MASK (1<< 5)
  72. struct au1200_lcd_global_regs_t {
  73. unsigned int flags;
  74. unsigned int xsize;
  75. unsigned int ysize;
  76. unsigned int backcolor;
  77. unsigned int brightness;
  78. unsigned int colorkey;
  79. unsigned int mask;
  80. unsigned int panel_choice;
  81. char panel_desc[80];
  82. };
  83. #define WIN_POSITION (1<< 0)
  84. #define WIN_ALPHA_COLOR (1<< 1)
  85. #define WIN_ALPHA_MODE (1<< 2)
  86. #define WIN_PRIORITY (1<< 3)
  87. #define WIN_CHANNEL (1<< 4)
  88. #define WIN_BUFFER_FORMAT (1<< 5)
  89. #define WIN_COLOR_ORDER (1<< 6)
  90. #define WIN_PIXEL_ORDER (1<< 7)
  91. #define WIN_SIZE (1<< 8)
  92. #define WIN_COLORKEY_MODE (1<< 9)
  93. #define WIN_DOUBLE_BUFFER_MODE (1<< 10)
  94. #define WIN_RAM_ARRAY_MODE (1<< 11)
  95. #define WIN_BUFFER_SCALE (1<< 12)
  96. #define WIN_ENABLE (1<< 13)
  97. struct au1200_lcd_window_regs_t {
  98. unsigned int flags;
  99. unsigned int xpos;
  100. unsigned int ypos;
  101. unsigned int alpha_color;
  102. unsigned int alpha_mode;
  103. unsigned int priority;
  104. unsigned int channel;
  105. unsigned int buffer_format;
  106. unsigned int color_order;
  107. unsigned int pixel_order;
  108. unsigned int xsize;
  109. unsigned int ysize;
  110. unsigned int colorkey_mode;
  111. unsigned int double_buffer_mode;
  112. unsigned int ram_array_mode;
  113. unsigned int xscale;
  114. unsigned int yscale;
  115. unsigned int enable;
  116. };
  117. struct au1200_lcd_iodata_t {
  118. unsigned int subcmd;
  119. struct au1200_lcd_global_regs_t global;
  120. struct au1200_lcd_window_regs_t window;
  121. };
  122. #if defined(__BIG_ENDIAN)
  123. #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_11
  124. #else
  125. #define LCD_CONTROL_DEFAULT_PO LCD_CONTROL_PO_00
  126. #endif
  127. #define LCD_CONTROL_DEFAULT_SBPPF LCD_CONTROL_SBPPF_565
  128. /* Private, per-framebuffer management information (independent of the panel itself) */
  129. struct au1200fb_device {
  130. struct fb_info *fb_info; /* FB driver info record */
  131. struct au1200fb_platdata *pd;
  132. int plane;
  133. unsigned char* fb_mem; /* FrameBuffer memory map */
  134. unsigned int fb_len;
  135. dma_addr_t fb_phys;
  136. };
  137. /********************************************************************/
  138. /* LCD controller restrictions */
  139. #define AU1200_LCD_MAX_XRES 1280
  140. #define AU1200_LCD_MAX_YRES 1024
  141. #define AU1200_LCD_MAX_BPP 32
  142. #define AU1200_LCD_MAX_CLK 96000000 /* fixme: this needs to go away ? */
  143. #define AU1200_LCD_NBR_PALETTE_ENTRIES 256
  144. /* Default number of visible screen buffer to allocate */
  145. #define AU1200FB_NBR_VIDEO_BUFFERS 1
  146. /* Default maximum number of fb devices to create */
  147. #define MAX_DEVICE_COUNT 4
  148. /* Default window configuration entry to use (see windows[]) */
  149. #define DEFAULT_WINDOW_INDEX 2
  150. /********************************************************************/
  151. static struct fb_info *_au1200fb_infos[MAX_DEVICE_COUNT];
  152. static struct au1200_lcd *lcd = (struct au1200_lcd *) AU1200_LCD_ADDR;
  153. static int device_count = MAX_DEVICE_COUNT;
  154. static int window_index = DEFAULT_WINDOW_INDEX; /* default is zero */
  155. static int panel_index = 2; /* default is zero */
  156. static struct window_settings *win;
  157. static struct panel_settings *panel;
  158. static int noblanking = 1;
  159. static int nohwcursor = 0;
  160. struct window_settings {
  161. unsigned char name[64];
  162. uint32 mode_backcolor;
  163. uint32 mode_colorkey;
  164. uint32 mode_colorkeymsk;
  165. struct {
  166. int xres;
  167. int yres;
  168. int xpos;
  169. int ypos;
  170. uint32 mode_winctrl1; /* winctrl1[FRM,CCO,PO,PIPE] */
  171. uint32 mode_winenable;
  172. } w[4];
  173. };
  174. #if defined(__BIG_ENDIAN)
  175. #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_00
  176. #else
  177. #define LCD_WINCTRL1_PO_16BPP LCD_WINCTRL1_PO_01
  178. #endif
  179. /*
  180. * Default window configurations
  181. */
  182. static struct window_settings windows[] = {
  183. { /* Index 0 */
  184. "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
  185. /* mode_backcolor */ 0x006600ff,
  186. /* mode_colorkey,msk*/ 0, 0,
  187. {
  188. {
  189. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  190. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  191. LCD_WINCTRL1_PO_16BPP,
  192. /* mode_winenable*/ LCD_WINENABLE_WEN0,
  193. },
  194. {
  195. /* xres, yres, xpos, ypos */ 100, 100, 100, 100,
  196. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  197. LCD_WINCTRL1_PO_16BPP |
  198. LCD_WINCTRL1_PIPE,
  199. /* mode_winenable*/ LCD_WINENABLE_WEN1,
  200. },
  201. {
  202. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  203. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  204. LCD_WINCTRL1_PO_16BPP,
  205. /* mode_winenable*/ 0,
  206. },
  207. {
  208. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  209. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  210. LCD_WINCTRL1_PO_16BPP |
  211. LCD_WINCTRL1_PIPE,
  212. /* mode_winenable*/ 0,
  213. },
  214. },
  215. },
  216. { /* Index 1 */
  217. "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
  218. /* mode_backcolor */ 0x006600ff,
  219. /* mode_colorkey,msk*/ 0, 0,
  220. {
  221. {
  222. /* xres, yres, xpos, ypos */ 320, 240, 5, 5,
  223. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_24BPP |
  224. LCD_WINCTRL1_PO_00,
  225. /* mode_winenable*/ LCD_WINENABLE_WEN0,
  226. },
  227. {
  228. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  229. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565
  230. | LCD_WINCTRL1_PO_16BPP,
  231. /* mode_winenable*/ 0,
  232. },
  233. {
  234. /* xres, yres, xpos, ypos */ 100, 100, 0, 0,
  235. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  236. LCD_WINCTRL1_PO_16BPP |
  237. LCD_WINCTRL1_PIPE,
  238. /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
  239. },
  240. {
  241. /* xres, yres, xpos, ypos */ 200, 25, 0, 0,
  242. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  243. LCD_WINCTRL1_PO_16BPP |
  244. LCD_WINCTRL1_PIPE,
  245. /* mode_winenable*/ 0,
  246. },
  247. },
  248. },
  249. { /* Index 2 */
  250. "0-FS gfx, 1-video, 2-ovly gfx, 3-ovly gfx",
  251. /* mode_backcolor */ 0x006600ff,
  252. /* mode_colorkey,msk*/ 0, 0,
  253. {
  254. {
  255. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  256. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  257. LCD_WINCTRL1_PO_16BPP,
  258. /* mode_winenable*/ LCD_WINENABLE_WEN0,
  259. },
  260. {
  261. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  262. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  263. LCD_WINCTRL1_PO_16BPP,
  264. /* mode_winenable*/ 0,
  265. },
  266. {
  267. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  268. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_32BPP |
  269. LCD_WINCTRL1_PO_00|LCD_WINCTRL1_PIPE,
  270. /* mode_winenable*/ 0/*LCD_WINENABLE_WEN2*/,
  271. },
  272. {
  273. /* xres, yres, xpos, ypos */ 0, 0, 0, 0,
  274. /* mode_winctrl1 */ LCD_WINCTRL1_FRM_16BPP565 |
  275. LCD_WINCTRL1_PO_16BPP |
  276. LCD_WINCTRL1_PIPE,
  277. /* mode_winenable*/ 0,
  278. },
  279. },
  280. },
  281. /* Need VGA 640 @ 24bpp, @ 32bpp */
  282. /* Need VGA 800 @ 24bpp, @ 32bpp */
  283. /* Need VGA 1024 @ 24bpp, @ 32bpp */
  284. };
  285. /*
  286. * Controller configurations for various panels.
  287. */
  288. struct panel_settings
  289. {
  290. const char name[25]; /* Full name <vendor>_<model> */
  291. struct fb_monspecs monspecs; /* FB monitor specs */
  292. /* panel timings */
  293. uint32 mode_screen;
  294. uint32 mode_horztiming;
  295. uint32 mode_verttiming;
  296. uint32 mode_clkcontrol;
  297. uint32 mode_pwmdiv;
  298. uint32 mode_pwmhi;
  299. uint32 mode_outmask;
  300. uint32 mode_fifoctrl;
  301. uint32 mode_backlight;
  302. uint32 lcdclk;
  303. #define Xres min_xres
  304. #define Yres min_yres
  305. u32 min_xres; /* Minimum horizontal resolution */
  306. u32 max_xres; /* Maximum horizontal resolution */
  307. u32 min_yres; /* Minimum vertical resolution */
  308. u32 max_yres; /* Maximum vertical resolution */
  309. };
  310. /********************************************************************/
  311. /* fixme: Maybe a modedb for the CRT ? otherwise panels should be as-is */
  312. /* List of panels known to work with the AU1200 LCD controller.
  313. * To add a new panel, enter the same specifications as the
  314. * Generic_TFT one, and MAKE SURE that it doesn't conflicts
  315. * with the controller restrictions. Restrictions are:
  316. *
  317. * STN color panels: max_bpp <= 12
  318. * STN mono panels: max_bpp <= 4
  319. * TFT panels: max_bpp <= 16
  320. * max_xres <= 800
  321. * max_yres <= 600
  322. */
  323. static struct panel_settings known_lcd_panels[] =
  324. {
  325. [0] = { /* QVGA 320x240 H:33.3kHz V:110Hz */
  326. .name = "QVGA_320x240",
  327. .monspecs = {
  328. .modedb = NULL,
  329. .modedb_len = 0,
  330. .hfmin = 30000,
  331. .hfmax = 70000,
  332. .vfmin = 60,
  333. .vfmax = 60,
  334. .dclkmin = 6000000,
  335. .dclkmax = 28000000,
  336. .input = FB_DISP_RGB,
  337. },
  338. .mode_screen = LCD_SCREEN_SX_N(320) |
  339. LCD_SCREEN_SY_N(240),
  340. .mode_horztiming = 0x00c4623b,
  341. .mode_verttiming = 0x00502814,
  342. .mode_clkcontrol = 0x00020002, /* /4=24Mhz */
  343. .mode_pwmdiv = 0x00000000,
  344. .mode_pwmhi = 0x00000000,
  345. .mode_outmask = 0x00FFFFFF,
  346. .mode_fifoctrl = 0x2f2f2f2f,
  347. .mode_backlight = 0x00000000,
  348. .lcdclk = 96,
  349. 320, 320,
  350. 240, 240,
  351. },
  352. [1] = { /* VGA 640x480 H:30.3kHz V:58Hz */
  353. .name = "VGA_640x480",
  354. .monspecs = {
  355. .modedb = NULL,
  356. .modedb_len = 0,
  357. .hfmin = 30000,
  358. .hfmax = 70000,
  359. .vfmin = 60,
  360. .vfmax = 60,
  361. .dclkmin = 6000000,
  362. .dclkmax = 28000000,
  363. .input = FB_DISP_RGB,
  364. },
  365. .mode_screen = 0x13f9df80,
  366. .mode_horztiming = 0x003c5859,
  367. .mode_verttiming = 0x00741201,
  368. .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
  369. .mode_pwmdiv = 0x00000000,
  370. .mode_pwmhi = 0x00000000,
  371. .mode_outmask = 0x00FFFFFF,
  372. .mode_fifoctrl = 0x2f2f2f2f,
  373. .mode_backlight = 0x00000000,
  374. .lcdclk = 96,
  375. 640, 480,
  376. 640, 480,
  377. },
  378. [2] = { /* SVGA 800x600 H:46.1kHz V:69Hz */
  379. .name = "SVGA_800x600",
  380. .monspecs = {
  381. .modedb = NULL,
  382. .modedb_len = 0,
  383. .hfmin = 30000,
  384. .hfmax = 70000,
  385. .vfmin = 60,
  386. .vfmax = 60,
  387. .dclkmin = 6000000,
  388. .dclkmax = 28000000,
  389. .input = FB_DISP_RGB,
  390. },
  391. .mode_screen = 0x18fa5780,
  392. .mode_horztiming = 0x00dc7e77,
  393. .mode_verttiming = 0x00584805,
  394. .mode_clkcontrol = 0x00020000, /* /2=48Mhz */
  395. .mode_pwmdiv = 0x00000000,
  396. .mode_pwmhi = 0x00000000,
  397. .mode_outmask = 0x00FFFFFF,
  398. .mode_fifoctrl = 0x2f2f2f2f,
  399. .mode_backlight = 0x00000000,
  400. .lcdclk = 96,
  401. 800, 800,
  402. 600, 600,
  403. },
  404. [3] = { /* XVGA 1024x768 H:56.2kHz V:70Hz */
  405. .name = "XVGA_1024x768",
  406. .monspecs = {
  407. .modedb = NULL,
  408. .modedb_len = 0,
  409. .hfmin = 30000,
  410. .hfmax = 70000,
  411. .vfmin = 60,
  412. .vfmax = 60,
  413. .dclkmin = 6000000,
  414. .dclkmax = 28000000,
  415. .input = FB_DISP_RGB,
  416. },
  417. .mode_screen = 0x1ffaff80,
  418. .mode_horztiming = 0x007d0e57,
  419. .mode_verttiming = 0x00740a01,
  420. .mode_clkcontrol = 0x000A0000, /* /1 */
  421. .mode_pwmdiv = 0x00000000,
  422. .mode_pwmhi = 0x00000000,
  423. .mode_outmask = 0x00FFFFFF,
  424. .mode_fifoctrl = 0x2f2f2f2f,
  425. .mode_backlight = 0x00000000,
  426. .lcdclk = 72,
  427. 1024, 1024,
  428. 768, 768,
  429. },
  430. [4] = { /* XVGA XVGA 1280x1024 H:68.5kHz V:65Hz */
  431. .name = "XVGA_1280x1024",
  432. .monspecs = {
  433. .modedb = NULL,
  434. .modedb_len = 0,
  435. .hfmin = 30000,
  436. .hfmax = 70000,
  437. .vfmin = 60,
  438. .vfmax = 60,
  439. .dclkmin = 6000000,
  440. .dclkmax = 28000000,
  441. .input = FB_DISP_RGB,
  442. },
  443. .mode_screen = 0x27fbff80,
  444. .mode_horztiming = 0x00cdb2c7,
  445. .mode_verttiming = 0x00600002,
  446. .mode_clkcontrol = 0x000A0000, /* /1 */
  447. .mode_pwmdiv = 0x00000000,
  448. .mode_pwmhi = 0x00000000,
  449. .mode_outmask = 0x00FFFFFF,
  450. .mode_fifoctrl = 0x2f2f2f2f,
  451. .mode_backlight = 0x00000000,
  452. .lcdclk = 120,
  453. 1280, 1280,
  454. 1024, 1024,
  455. },
  456. [5] = { /* Samsung 1024x768 TFT */
  457. .name = "Samsung_1024x768_TFT",
  458. .monspecs = {
  459. .modedb = NULL,
  460. .modedb_len = 0,
  461. .hfmin = 30000,
  462. .hfmax = 70000,
  463. .vfmin = 60,
  464. .vfmax = 60,
  465. .dclkmin = 6000000,
  466. .dclkmax = 28000000,
  467. .input = FB_DISP_RGB,
  468. },
  469. .mode_screen = 0x1ffaff80,
  470. .mode_horztiming = 0x018cc677,
  471. .mode_verttiming = 0x00241217,
  472. .mode_clkcontrol = 0x00000000, /* SCB 0x1 /4=24Mhz */
  473. .mode_pwmdiv = 0x8000063f, /* SCB 0x0 */
  474. .mode_pwmhi = 0x03400000, /* SCB 0x0 */
  475. .mode_outmask = 0x00FFFFFF,
  476. .mode_fifoctrl = 0x2f2f2f2f,
  477. .mode_backlight = 0x00000000,
  478. .lcdclk = 96,
  479. 1024, 1024,
  480. 768, 768,
  481. },
  482. [6] = { /* Toshiba 640x480 TFT */
  483. .name = "Toshiba_640x480_TFT",
  484. .monspecs = {
  485. .modedb = NULL,
  486. .modedb_len = 0,
  487. .hfmin = 30000,
  488. .hfmax = 70000,
  489. .vfmin = 60,
  490. .vfmax = 60,
  491. .dclkmin = 6000000,
  492. .dclkmax = 28000000,
  493. .input = FB_DISP_RGB,
  494. },
  495. .mode_screen = LCD_SCREEN_SX_N(640) |
  496. LCD_SCREEN_SY_N(480),
  497. .mode_horztiming = LCD_HORZTIMING_HPW_N(96) |
  498. LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(51),
  499. .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
  500. LCD_VERTTIMING_VND1_N(11) | LCD_VERTTIMING_VND2_N(32),
  501. .mode_clkcontrol = 0x00000000, /* /4=24Mhz */
  502. .mode_pwmdiv = 0x8000063f,
  503. .mode_pwmhi = 0x03400000,
  504. .mode_outmask = 0x00fcfcfc,
  505. .mode_fifoctrl = 0x2f2f2f2f,
  506. .mode_backlight = 0x00000000,
  507. .lcdclk = 96,
  508. 640, 480,
  509. 640, 480,
  510. },
  511. [7] = { /* Sharp 320x240 TFT */
  512. .name = "Sharp_320x240_TFT",
  513. .monspecs = {
  514. .modedb = NULL,
  515. .modedb_len = 0,
  516. .hfmin = 12500,
  517. .hfmax = 20000,
  518. .vfmin = 38,
  519. .vfmax = 81,
  520. .dclkmin = 4500000,
  521. .dclkmax = 6800000,
  522. .input = FB_DISP_RGB,
  523. },
  524. .mode_screen = LCD_SCREEN_SX_N(320) |
  525. LCD_SCREEN_SY_N(240),
  526. .mode_horztiming = LCD_HORZTIMING_HPW_N(60) |
  527. LCD_HORZTIMING_HND1_N(13) | LCD_HORZTIMING_HND2_N(2),
  528. .mode_verttiming = LCD_VERTTIMING_VPW_N(2) |
  529. LCD_VERTTIMING_VND1_N(2) | LCD_VERTTIMING_VND2_N(5),
  530. .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(7), /*16=6Mhz*/
  531. .mode_pwmdiv = 0x8000063f,
  532. .mode_pwmhi = 0x03400000,
  533. .mode_outmask = 0x00fcfcfc,
  534. .mode_fifoctrl = 0x2f2f2f2f,
  535. .mode_backlight = 0x00000000,
  536. .lcdclk = 96, /* 96MHz AUXPLL */
  537. 320, 320,
  538. 240, 240,
  539. },
  540. [8] = { /* Toppoly TD070WGCB2 7" 856x480 TFT */
  541. .name = "Toppoly_TD070WGCB2",
  542. .monspecs = {
  543. .modedb = NULL,
  544. .modedb_len = 0,
  545. .hfmin = 30000,
  546. .hfmax = 70000,
  547. .vfmin = 60,
  548. .vfmax = 60,
  549. .dclkmin = 6000000,
  550. .dclkmax = 28000000,
  551. .input = FB_DISP_RGB,
  552. },
  553. .mode_screen = LCD_SCREEN_SX_N(856) |
  554. LCD_SCREEN_SY_N(480),
  555. .mode_horztiming = LCD_HORZTIMING_HND2_N(43) |
  556. LCD_HORZTIMING_HND1_N(43) | LCD_HORZTIMING_HPW_N(114),
  557. .mode_verttiming = LCD_VERTTIMING_VND2_N(20) |
  558. LCD_VERTTIMING_VND1_N(21) | LCD_VERTTIMING_VPW_N(4),
  559. .mode_clkcontrol = 0x00020001, /* /4=24Mhz */
  560. .mode_pwmdiv = 0x8000063f,
  561. .mode_pwmhi = 0x03400000,
  562. .mode_outmask = 0x00fcfcfc,
  563. .mode_fifoctrl = 0x2f2f2f2f,
  564. .mode_backlight = 0x00000000,
  565. .lcdclk = 96,
  566. 856, 856,
  567. 480, 480,
  568. },
  569. [9] = {
  570. .name = "DB1300_800x480",
  571. .monspecs = {
  572. .modedb = NULL,
  573. .modedb_len = 0,
  574. .hfmin = 30000,
  575. .hfmax = 70000,
  576. .vfmin = 60,
  577. .vfmax = 60,
  578. .dclkmin = 6000000,
  579. .dclkmax = 28000000,
  580. .input = FB_DISP_RGB,
  581. },
  582. .mode_screen = LCD_SCREEN_SX_N(800) |
  583. LCD_SCREEN_SY_N(480),
  584. .mode_horztiming = LCD_HORZTIMING_HPW_N(5) |
  585. LCD_HORZTIMING_HND1_N(16) |
  586. LCD_HORZTIMING_HND2_N(8),
  587. .mode_verttiming = LCD_VERTTIMING_VPW_N(4) |
  588. LCD_VERTTIMING_VND1_N(8) |
  589. LCD_VERTTIMING_VND2_N(5),
  590. .mode_clkcontrol = LCD_CLKCONTROL_PCD_N(1) |
  591. LCD_CLKCONTROL_IV |
  592. LCD_CLKCONTROL_IH,
  593. .mode_pwmdiv = 0x00000000,
  594. .mode_pwmhi = 0x00000000,
  595. .mode_outmask = 0x00FFFFFF,
  596. .mode_fifoctrl = 0x2f2f2f2f,
  597. .mode_backlight = 0x00000000,
  598. .lcdclk = 96,
  599. 800, 800,
  600. 480, 480,
  601. },
  602. };
  603. #define NUM_PANELS (ARRAY_SIZE(known_lcd_panels))
  604. /********************************************************************/
  605. static int winbpp (unsigned int winctrl1)
  606. {
  607. int bits = 0;
  608. /* how many bits are needed for each pixel format */
  609. switch (winctrl1 & LCD_WINCTRL1_FRM) {
  610. case LCD_WINCTRL1_FRM_1BPP:
  611. bits = 1;
  612. break;
  613. case LCD_WINCTRL1_FRM_2BPP:
  614. bits = 2;
  615. break;
  616. case LCD_WINCTRL1_FRM_4BPP:
  617. bits = 4;
  618. break;
  619. case LCD_WINCTRL1_FRM_8BPP:
  620. bits = 8;
  621. break;
  622. case LCD_WINCTRL1_FRM_12BPP:
  623. case LCD_WINCTRL1_FRM_16BPP655:
  624. case LCD_WINCTRL1_FRM_16BPP565:
  625. case LCD_WINCTRL1_FRM_16BPP556:
  626. case LCD_WINCTRL1_FRM_16BPPI1555:
  627. case LCD_WINCTRL1_FRM_16BPPI5551:
  628. case LCD_WINCTRL1_FRM_16BPPA1555:
  629. case LCD_WINCTRL1_FRM_16BPPA5551:
  630. bits = 16;
  631. break;
  632. case LCD_WINCTRL1_FRM_24BPP:
  633. case LCD_WINCTRL1_FRM_32BPP:
  634. bits = 32;
  635. break;
  636. }
  637. return bits;
  638. }
  639. static int fbinfo2index (struct fb_info *fb_info)
  640. {
  641. int i;
  642. for (i = 0; i < device_count; ++i) {
  643. if (fb_info == _au1200fb_infos[i])
  644. return i;
  645. }
  646. printk("au1200fb: ERROR: fbinfo2index failed!\n");
  647. return -1;
  648. }
  649. static int au1200_setlocation (struct au1200fb_device *fbdev, int plane,
  650. int xpos, int ypos)
  651. {
  652. uint32 winctrl0, winctrl1, winenable, fb_offset = 0;
  653. int xsz, ysz;
  654. /* FIX!!! NOT CHECKING FOR COMPLETE OFFSCREEN YET */
  655. winctrl0 = lcd->window[plane].winctrl0;
  656. winctrl1 = lcd->window[plane].winctrl1;
  657. winctrl0 &= (LCD_WINCTRL0_A | LCD_WINCTRL0_AEN);
  658. winctrl1 &= ~(LCD_WINCTRL1_SZX | LCD_WINCTRL1_SZY);
  659. /* Check for off-screen adjustments */
  660. xsz = win->w[plane].xres;
  661. ysz = win->w[plane].yres;
  662. if ((xpos + win->w[plane].xres) > panel->Xres) {
  663. /* Off-screen to the right */
  664. xsz = panel->Xres - xpos; /* off by 1 ??? */
  665. /*printk("off screen right\n");*/
  666. }
  667. if ((ypos + win->w[plane].yres) > panel->Yres) {
  668. /* Off-screen to the bottom */
  669. ysz = panel->Yres - ypos; /* off by 1 ??? */
  670. /*printk("off screen bottom\n");*/
  671. }
  672. if (xpos < 0) {
  673. /* Off-screen to the left */
  674. xsz = win->w[plane].xres + xpos;
  675. fb_offset += (((0 - xpos) * winbpp(lcd->window[plane].winctrl1))/8);
  676. xpos = 0;
  677. /*printk("off screen left\n");*/
  678. }
  679. if (ypos < 0) {
  680. /* Off-screen to the top */
  681. ysz = win->w[plane].yres + ypos;
  682. /* fixme: fb_offset += ((0-ypos)*fb_pars[plane].line_length); */
  683. ypos = 0;
  684. /*printk("off screen top\n");*/
  685. }
  686. /* record settings */
  687. win->w[plane].xpos = xpos;
  688. win->w[plane].ypos = ypos;
  689. xsz -= 1;
  690. ysz -= 1;
  691. winctrl0 |= (xpos << 21);
  692. winctrl0 |= (ypos << 10);
  693. winctrl1 |= (xsz << 11);
  694. winctrl1 |= (ysz << 0);
  695. /* Disable the window while making changes, then restore WINEN */
  696. winenable = lcd->winenable & (1 << plane);
  697. wmb(); /* drain writebuffer */
  698. lcd->winenable &= ~(1 << plane);
  699. lcd->window[plane].winctrl0 = winctrl0;
  700. lcd->window[plane].winctrl1 = winctrl1;
  701. lcd->window[plane].winbuf0 =
  702. lcd->window[plane].winbuf1 = fbdev->fb_phys;
  703. lcd->window[plane].winbufctrl = 0; /* select winbuf0 */
  704. lcd->winenable |= winenable;
  705. wmb(); /* drain writebuffer */
  706. return 0;
  707. }
  708. static void au1200_setpanel(struct panel_settings *newpanel,
  709. struct au1200fb_platdata *pd)
  710. {
  711. /*
  712. * Perform global setup/init of LCD controller
  713. */
  714. uint32 winenable;
  715. /* Make sure all windows disabled */
  716. winenable = lcd->winenable;
  717. lcd->winenable = 0;
  718. wmb(); /* drain writebuffer */
  719. /*
  720. * Ensure everything is disabled before reconfiguring
  721. */
  722. if (lcd->screen & LCD_SCREEN_SEN) {
  723. /* Wait for vertical sync period */
  724. lcd->intstatus = LCD_INT_SS;
  725. while ((lcd->intstatus & LCD_INT_SS) == 0)
  726. ;
  727. lcd->screen &= ~LCD_SCREEN_SEN; /*disable the controller*/
  728. do {
  729. lcd->intstatus = lcd->intstatus; /*clear interrupts*/
  730. wmb(); /* drain writebuffer */
  731. /*wait for controller to shut down*/
  732. } while ((lcd->intstatus & LCD_INT_SD) == 0);
  733. /* Call shutdown of current panel (if up) */
  734. /* this must occur last, because if an external clock is driving
  735. the controller, the clock cannot be turned off before first
  736. shutting down the controller.
  737. */
  738. if (pd->panel_shutdown)
  739. pd->panel_shutdown();
  740. }
  741. /* Newpanel == NULL indicates a shutdown operation only */
  742. if (newpanel == NULL)
  743. return;
  744. panel = newpanel;
  745. printk("Panel(%s), %dx%d\n", panel->name, panel->Xres, panel->Yres);
  746. /*
  747. * Setup clocking if internal LCD clock source (assumes sys_auxpll valid)
  748. */
  749. if (!(panel->mode_clkcontrol & LCD_CLKCONTROL_EXT))
  750. {
  751. struct clk *c = clk_get(NULL, "lcd_intclk");
  752. long r, pc = panel->lcdclk * 1000000;
  753. if (!IS_ERR(c)) {
  754. r = clk_round_rate(c, pc);
  755. if ((pc - r) < (pc / 10)) { /* 10% slack */
  756. clk_set_rate(c, r);
  757. clk_prepare_enable(c);
  758. }
  759. clk_put(c);
  760. }
  761. }
  762. /*
  763. * Configure panel timings
  764. */
  765. lcd->screen = panel->mode_screen;
  766. lcd->horztiming = panel->mode_horztiming;
  767. lcd->verttiming = panel->mode_verttiming;
  768. lcd->clkcontrol = panel->mode_clkcontrol;
  769. lcd->pwmdiv = panel->mode_pwmdiv;
  770. lcd->pwmhi = panel->mode_pwmhi;
  771. lcd->outmask = panel->mode_outmask;
  772. lcd->fifoctrl = panel->mode_fifoctrl;
  773. wmb(); /* drain writebuffer */
  774. /* fixme: Check window settings to make sure still valid
  775. * for new geometry */
  776. #if 0
  777. au1200_setlocation(fbdev, 0, win->w[0].xpos, win->w[0].ypos);
  778. au1200_setlocation(fbdev, 1, win->w[1].xpos, win->w[1].ypos);
  779. au1200_setlocation(fbdev, 2, win->w[2].xpos, win->w[2].ypos);
  780. au1200_setlocation(fbdev, 3, win->w[3].xpos, win->w[3].ypos);
  781. #endif
  782. lcd->winenable = winenable;
  783. /*
  784. * Re-enable screen now that it is configured
  785. */
  786. lcd->screen |= LCD_SCREEN_SEN;
  787. wmb(); /* drain writebuffer */
  788. /* Call init of panel */
  789. if (pd->panel_init)
  790. pd->panel_init();
  791. /* FIX!!!! not appropriate on panel change!!! Global setup/init */
  792. lcd->intenable = 0;
  793. lcd->intstatus = ~0;
  794. lcd->backcolor = win->mode_backcolor;
  795. /* Setup Color Key - FIX!!! */
  796. lcd->colorkey = win->mode_colorkey;
  797. lcd->colorkeymsk = win->mode_colorkeymsk;
  798. /* Setup HWCursor - FIX!!! Need to support this eventually */
  799. lcd->hwc.cursorctrl = 0;
  800. lcd->hwc.cursorpos = 0;
  801. lcd->hwc.cursorcolor0 = 0;
  802. lcd->hwc.cursorcolor1 = 0;
  803. lcd->hwc.cursorcolor2 = 0;
  804. lcd->hwc.cursorcolor3 = 0;
  805. #if 0
  806. #define D(X) printk("%25s: %08X\n", #X, X)
  807. D(lcd->screen);
  808. D(lcd->horztiming);
  809. D(lcd->verttiming);
  810. D(lcd->clkcontrol);
  811. D(lcd->pwmdiv);
  812. D(lcd->pwmhi);
  813. D(lcd->outmask);
  814. D(lcd->fifoctrl);
  815. D(lcd->window[0].winctrl0);
  816. D(lcd->window[0].winctrl1);
  817. D(lcd->window[0].winctrl2);
  818. D(lcd->window[0].winbuf0);
  819. D(lcd->window[0].winbuf1);
  820. D(lcd->window[0].winbufctrl);
  821. D(lcd->window[1].winctrl0);
  822. D(lcd->window[1].winctrl1);
  823. D(lcd->window[1].winctrl2);
  824. D(lcd->window[1].winbuf0);
  825. D(lcd->window[1].winbuf1);
  826. D(lcd->window[1].winbufctrl);
  827. D(lcd->window[2].winctrl0);
  828. D(lcd->window[2].winctrl1);
  829. D(lcd->window[2].winctrl2);
  830. D(lcd->window[2].winbuf0);
  831. D(lcd->window[2].winbuf1);
  832. D(lcd->window[2].winbufctrl);
  833. D(lcd->window[3].winctrl0);
  834. D(lcd->window[3].winctrl1);
  835. D(lcd->window[3].winctrl2);
  836. D(lcd->window[3].winbuf0);
  837. D(lcd->window[3].winbuf1);
  838. D(lcd->window[3].winbufctrl);
  839. D(lcd->winenable);
  840. D(lcd->intenable);
  841. D(lcd->intstatus);
  842. D(lcd->backcolor);
  843. D(lcd->winenable);
  844. D(lcd->colorkey);
  845. D(lcd->colorkeymsk);
  846. D(lcd->hwc.cursorctrl);
  847. D(lcd->hwc.cursorpos);
  848. D(lcd->hwc.cursorcolor0);
  849. D(lcd->hwc.cursorcolor1);
  850. D(lcd->hwc.cursorcolor2);
  851. D(lcd->hwc.cursorcolor3);
  852. #endif
  853. }
  854. static void au1200_setmode(struct au1200fb_device *fbdev)
  855. {
  856. int plane = fbdev->plane;
  857. /* Window/plane setup */
  858. lcd->window[plane].winctrl1 = ( 0
  859. | LCD_WINCTRL1_PRI_N(plane)
  860. | win->w[plane].mode_winctrl1 /* FRM,CCO,PO,PIPE */
  861. ) ;
  862. au1200_setlocation(fbdev, plane, win->w[plane].xpos, win->w[plane].ypos);
  863. lcd->window[plane].winctrl2 = ( 0
  864. | LCD_WINCTRL2_CKMODE_00
  865. | LCD_WINCTRL2_DBM
  866. | LCD_WINCTRL2_BX_N(fbdev->fb_info->fix.line_length)
  867. | LCD_WINCTRL2_SCX_1
  868. | LCD_WINCTRL2_SCY_1
  869. ) ;
  870. lcd->winenable |= win->w[plane].mode_winenable;
  871. wmb(); /* drain writebuffer */
  872. }
  873. /* Inline helpers */
  874. /*#define panel_is_dual(panel) ((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
  875. /*#define panel_is_active(panel)((panel->mode_screen & LCD_SCREEN_PT) == LCD_SCREEN_PT_010)*/
  876. #define panel_is_color(panel) ((panel->mode_screen & LCD_SCREEN_PT) <= LCD_SCREEN_PT_CDSTN)
  877. /* Bitfields format supported by the controller. */
  878. static struct fb_bitfield rgb_bitfields[][4] = {
  879. /* Red, Green, Blue, Transp */
  880. [LCD_WINCTRL1_FRM_16BPP655 >> 25] =
  881. { { 10, 6, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  882. [LCD_WINCTRL1_FRM_16BPP565 >> 25] =
  883. { { 11, 5, 0 }, { 5, 6, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  884. [LCD_WINCTRL1_FRM_16BPP556 >> 25] =
  885. { { 11, 5, 0 }, { 6, 5, 0 }, { 0, 6, 0 }, { 0, 0, 0 } },
  886. [LCD_WINCTRL1_FRM_16BPPI1555 >> 25] =
  887. { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 0, 0, 0 } },
  888. [LCD_WINCTRL1_FRM_16BPPI5551 >> 25] =
  889. { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 0, 0 } },
  890. [LCD_WINCTRL1_FRM_16BPPA1555 >> 25] =
  891. { { 10, 5, 0 }, { 5, 5, 0 }, { 0, 5, 0 }, { 15, 1, 0 } },
  892. [LCD_WINCTRL1_FRM_16BPPA5551 >> 25] =
  893. { { 11, 5, 0 }, { 6, 5, 0 }, { 1, 5, 0 }, { 0, 1, 0 } },
  894. [LCD_WINCTRL1_FRM_24BPP >> 25] =
  895. { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 0, 0, 0 } },
  896. [LCD_WINCTRL1_FRM_32BPP >> 25] =
  897. { { 16, 8, 0 }, { 8, 8, 0 }, { 0, 8, 0 }, { 24, 0, 0 } },
  898. };
  899. /*-------------------------------------------------------------------------*/
  900. /* Helpers */
  901. static void au1200fb_update_fbinfo(struct fb_info *fbi)
  902. {
  903. /* FIX!!!! This also needs to take the window pixel format into account!!! */
  904. /* Update var-dependent FB info */
  905. if (panel_is_color(panel)) {
  906. if (fbi->var.bits_per_pixel <= 8) {
  907. /* palettized */
  908. fbi->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  909. fbi->fix.line_length = fbi->var.xres_virtual /
  910. (8/fbi->var.bits_per_pixel);
  911. } else {
  912. /* non-palettized */
  913. fbi->fix.visual = FB_VISUAL_TRUECOLOR;
  914. fbi->fix.line_length = fbi->var.xres_virtual * (fbi->var.bits_per_pixel / 8);
  915. }
  916. } else {
  917. /* mono FIX!!! mono 8 and 4 bits */
  918. fbi->fix.visual = FB_VISUAL_MONO10;
  919. fbi->fix.line_length = fbi->var.xres_virtual / 8;
  920. }
  921. fbi->screen_size = fbi->fix.line_length * fbi->var.yres_virtual;
  922. print_dbg("line length: %d\n", fbi->fix.line_length);
  923. print_dbg("bits_per_pixel: %d\n", fbi->var.bits_per_pixel);
  924. }
  925. /*-------------------------------------------------------------------------*/
  926. /* AU1200 framebuffer driver */
  927. /* fb_check_var
  928. * Validate var settings with hardware restrictions and modify it if necessary
  929. */
  930. static int au1200fb_fb_check_var(struct fb_var_screeninfo *var,
  931. struct fb_info *fbi)
  932. {
  933. struct au1200fb_device *fbdev = fbi->par;
  934. u32 pixclock;
  935. int screen_size, plane;
  936. plane = fbdev->plane;
  937. /* Make sure that the mode respect all LCD controller and
  938. * panel restrictions. */
  939. var->xres = win->w[plane].xres;
  940. var->yres = win->w[plane].yres;
  941. /* No need for virtual resolution support */
  942. var->xres_virtual = var->xres;
  943. var->yres_virtual = var->yres;
  944. var->bits_per_pixel = winbpp(win->w[plane].mode_winctrl1);
  945. screen_size = var->xres_virtual * var->yres_virtual;
  946. if (var->bits_per_pixel > 8) screen_size *= (var->bits_per_pixel / 8);
  947. else screen_size /= (8/var->bits_per_pixel);
  948. if (fbdev->fb_len < screen_size)
  949. return -EINVAL; /* Virtual screen is to big, abort */
  950. /* FIX!!!! what are the implicaitons of ignoring this for windows ??? */
  951. /* The max LCD clock is fixed to 48MHz (value of AUX_CLK). The pixel
  952. * clock can only be obtain by dividing this value by an even integer.
  953. * Fallback to a slower pixel clock if necessary. */
  954. pixclock = max((u32)(PICOS2KHZ(var->pixclock) * 1000), fbi->monspecs.dclkmin);
  955. pixclock = min3(pixclock, fbi->monspecs.dclkmax, (u32)AU1200_LCD_MAX_CLK/2);
  956. if (AU1200_LCD_MAX_CLK % pixclock) {
  957. int diff = AU1200_LCD_MAX_CLK % pixclock;
  958. pixclock -= diff;
  959. }
  960. var->pixclock = KHZ2PICOS(pixclock/1000);
  961. #if 0
  962. if (!panel_is_active(panel)) {
  963. int pcd = AU1200_LCD_MAX_CLK / (pixclock * 2) - 1;
  964. if (!panel_is_color(panel)
  965. && (panel->control_base & LCD_CONTROL_MPI) && (pcd < 3)) {
  966. /* STN 8bit mono panel support is up to 6MHz pixclock */
  967. var->pixclock = KHZ2PICOS(6000);
  968. } else if (!pcd) {
  969. /* Other STN panel support is up to 12MHz */
  970. var->pixclock = KHZ2PICOS(12000);
  971. }
  972. }
  973. #endif
  974. /* Set bitfield accordingly */
  975. switch (var->bits_per_pixel) {
  976. case 16:
  977. {
  978. /* 16bpp True color.
  979. * These must be set to MATCH WINCTRL[FORM] */
  980. int idx;
  981. idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
  982. var->red = rgb_bitfields[idx][0];
  983. var->green = rgb_bitfields[idx][1];
  984. var->blue = rgb_bitfields[idx][2];
  985. var->transp = rgb_bitfields[idx][3];
  986. break;
  987. }
  988. case 32:
  989. {
  990. /* 32bpp True color.
  991. * These must be set to MATCH WINCTRL[FORM] */
  992. int idx;
  993. idx = (win->w[0].mode_winctrl1 & LCD_WINCTRL1_FRM) >> 25;
  994. var->red = rgb_bitfields[idx][0];
  995. var->green = rgb_bitfields[idx][1];
  996. var->blue = rgb_bitfields[idx][2];
  997. var->transp = rgb_bitfields[idx][3];
  998. break;
  999. }
  1000. default:
  1001. print_dbg("Unsupported depth %dbpp", var->bits_per_pixel);
  1002. return -EINVAL;
  1003. }
  1004. return 0;
  1005. }
  1006. /* fb_set_par
  1007. * Set hardware with var settings. This will enable the controller with a
  1008. * specific mode, normally validated with the fb_check_var method
  1009. */
  1010. static int au1200fb_fb_set_par(struct fb_info *fbi)
  1011. {
  1012. struct au1200fb_device *fbdev = fbi->par;
  1013. au1200fb_update_fbinfo(fbi);
  1014. au1200_setmode(fbdev);
  1015. return 0;
  1016. }
  1017. /* fb_setcolreg
  1018. * Set color in LCD palette.
  1019. */
  1020. static int au1200fb_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1021. unsigned blue, unsigned transp, struct fb_info *fbi)
  1022. {
  1023. volatile u32 *palette = lcd->palette;
  1024. u32 value;
  1025. if (regno > (AU1200_LCD_NBR_PALETTE_ENTRIES - 1))
  1026. return -EINVAL;
  1027. if (fbi->var.grayscale) {
  1028. /* Convert color to grayscale */
  1029. red = green = blue =
  1030. (19595 * red + 38470 * green + 7471 * blue) >> 16;
  1031. }
  1032. if (fbi->fix.visual == FB_VISUAL_TRUECOLOR) {
  1033. /* Place color in the pseudopalette */
  1034. if (regno > 16)
  1035. return -EINVAL;
  1036. palette = (u32*) fbi->pseudo_palette;
  1037. red >>= (16 - fbi->var.red.length);
  1038. green >>= (16 - fbi->var.green.length);
  1039. blue >>= (16 - fbi->var.blue.length);
  1040. value = (red << fbi->var.red.offset) |
  1041. (green << fbi->var.green.offset)|
  1042. (blue << fbi->var.blue.offset);
  1043. value &= 0xFFFF;
  1044. } else if (1 /*FIX!!! panel_is_active(fbdev->panel)*/) {
  1045. /* COLOR TFT PALLETTIZED (use RGB 565) */
  1046. value = (red & 0xF800)|((green >> 5) &
  1047. 0x07E0)|((blue >> 11) & 0x001F);
  1048. value &= 0xFFFF;
  1049. } else if (0 /*panel_is_color(fbdev->panel)*/) {
  1050. /* COLOR STN MODE */
  1051. value = 0x1234;
  1052. value &= 0xFFF;
  1053. } else {
  1054. /* MONOCHROME MODE */
  1055. value = (green >> 12) & 0x000F;
  1056. value &= 0xF;
  1057. }
  1058. palette[regno] = value;
  1059. return 0;
  1060. }
  1061. /* fb_blank
  1062. * Blank the screen. Depending on the mode, the screen will be
  1063. * activated with the backlight color, or desactivated
  1064. */
  1065. static int au1200fb_fb_blank(int blank_mode, struct fb_info *fbi)
  1066. {
  1067. struct au1200fb_device *fbdev = fbi->par;
  1068. /* Short-circuit screen blanking */
  1069. if (noblanking)
  1070. return 0;
  1071. switch (blank_mode) {
  1072. case FB_BLANK_UNBLANK:
  1073. case FB_BLANK_NORMAL:
  1074. /* printk("turn on panel\n"); */
  1075. au1200_setpanel(panel, fbdev->pd);
  1076. break;
  1077. case FB_BLANK_VSYNC_SUSPEND:
  1078. case FB_BLANK_HSYNC_SUSPEND:
  1079. case FB_BLANK_POWERDOWN:
  1080. /* printk("turn off panel\n"); */
  1081. au1200_setpanel(NULL, fbdev->pd);
  1082. break;
  1083. default:
  1084. break;
  1085. }
  1086. /* FB_BLANK_NORMAL is a soft blank */
  1087. return (blank_mode == FB_BLANK_NORMAL) ? -EINVAL : 0;
  1088. }
  1089. /* fb_mmap
  1090. * Map video memory in user space. We don't use the generic fb_mmap
  1091. * method mainly to allow the use of the TLB streaming flag (CCA=6)
  1092. */
  1093. static int au1200fb_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
  1094. {
  1095. struct au1200fb_device *fbdev = info->par;
  1096. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  1097. pgprot_val(vma->vm_page_prot) |= _CACHE_MASK; /* CCA=7 */
  1098. return vm_iomap_memory(vma, fbdev->fb_phys, fbdev->fb_len);
  1099. }
  1100. static void set_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
  1101. {
  1102. unsigned int hi1, divider;
  1103. /* SCREEN_SIZE: user cannot reset size, must switch panel choice */
  1104. if (pdata->flags & SCREEN_BACKCOLOR)
  1105. lcd->backcolor = pdata->backcolor;
  1106. if (pdata->flags & SCREEN_BRIGHTNESS) {
  1107. // limit brightness pwm duty to >= 30/1600
  1108. if (pdata->brightness < 30) {
  1109. pdata->brightness = 30;
  1110. }
  1111. divider = (lcd->pwmdiv & 0x3FFFF) + 1;
  1112. hi1 = (((pdata->brightness & 0xFF)+1) * divider >> 8);
  1113. lcd->pwmhi &= 0xFFFF;
  1114. lcd->pwmhi |= (hi1 << 16);
  1115. }
  1116. if (pdata->flags & SCREEN_COLORKEY)
  1117. lcd->colorkey = pdata->colorkey;
  1118. if (pdata->flags & SCREEN_MASK)
  1119. lcd->colorkeymsk = pdata->mask;
  1120. wmb(); /* drain writebuffer */
  1121. }
  1122. static void get_global(u_int cmd, struct au1200_lcd_global_regs_t *pdata)
  1123. {
  1124. unsigned int hi1, divider;
  1125. pdata->xsize = ((lcd->screen & LCD_SCREEN_SX) >> 19) + 1;
  1126. pdata->ysize = ((lcd->screen & LCD_SCREEN_SY) >> 8) + 1;
  1127. pdata->backcolor = lcd->backcolor;
  1128. pdata->colorkey = lcd->colorkey;
  1129. pdata->mask = lcd->colorkeymsk;
  1130. // brightness
  1131. hi1 = (lcd->pwmhi >> 16) + 1;
  1132. divider = (lcd->pwmdiv & 0x3FFFF) + 1;
  1133. pdata->brightness = ((hi1 << 8) / divider) - 1;
  1134. wmb(); /* drain writebuffer */
  1135. }
  1136. static void set_window(unsigned int plane,
  1137. struct au1200_lcd_window_regs_t *pdata)
  1138. {
  1139. unsigned int val, bpp;
  1140. /* Window control register 0 */
  1141. if (pdata->flags & WIN_POSITION) {
  1142. val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_OX |
  1143. LCD_WINCTRL0_OY);
  1144. val |= ((pdata->xpos << 21) & LCD_WINCTRL0_OX);
  1145. val |= ((pdata->ypos << 10) & LCD_WINCTRL0_OY);
  1146. lcd->window[plane].winctrl0 = val;
  1147. }
  1148. if (pdata->flags & WIN_ALPHA_COLOR) {
  1149. val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_A);
  1150. val |= ((pdata->alpha_color << 2) & LCD_WINCTRL0_A);
  1151. lcd->window[plane].winctrl0 = val;
  1152. }
  1153. if (pdata->flags & WIN_ALPHA_MODE) {
  1154. val = lcd->window[plane].winctrl0 & ~(LCD_WINCTRL0_AEN);
  1155. val |= ((pdata->alpha_mode << 1) & LCD_WINCTRL0_AEN);
  1156. lcd->window[plane].winctrl0 = val;
  1157. }
  1158. /* Window control register 1 */
  1159. if (pdata->flags & WIN_PRIORITY) {
  1160. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PRI);
  1161. val |= ((pdata->priority << 30) & LCD_WINCTRL1_PRI);
  1162. lcd->window[plane].winctrl1 = val;
  1163. }
  1164. if (pdata->flags & WIN_CHANNEL) {
  1165. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PIPE);
  1166. val |= ((pdata->channel << 29) & LCD_WINCTRL1_PIPE);
  1167. lcd->window[plane].winctrl1 = val;
  1168. }
  1169. if (pdata->flags & WIN_BUFFER_FORMAT) {
  1170. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_FRM);
  1171. val |= ((pdata->buffer_format << 25) & LCD_WINCTRL1_FRM);
  1172. lcd->window[plane].winctrl1 = val;
  1173. }
  1174. if (pdata->flags & WIN_COLOR_ORDER) {
  1175. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_CCO);
  1176. val |= ((pdata->color_order << 24) & LCD_WINCTRL1_CCO);
  1177. lcd->window[plane].winctrl1 = val;
  1178. }
  1179. if (pdata->flags & WIN_PIXEL_ORDER) {
  1180. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_PO);
  1181. val |= ((pdata->pixel_order << 22) & LCD_WINCTRL1_PO);
  1182. lcd->window[plane].winctrl1 = val;
  1183. }
  1184. if (pdata->flags & WIN_SIZE) {
  1185. val = lcd->window[plane].winctrl1 & ~(LCD_WINCTRL1_SZX |
  1186. LCD_WINCTRL1_SZY);
  1187. val |= (((pdata->xsize << 11) - 1) & LCD_WINCTRL1_SZX);
  1188. val |= (((pdata->ysize) - 1) & LCD_WINCTRL1_SZY);
  1189. lcd->window[plane].winctrl1 = val;
  1190. /* program buffer line width */
  1191. bpp = winbpp(val) / 8;
  1192. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_BX);
  1193. val |= (((pdata->xsize * bpp) << 8) & LCD_WINCTRL2_BX);
  1194. lcd->window[plane].winctrl2 = val;
  1195. }
  1196. /* Window control register 2 */
  1197. if (pdata->flags & WIN_COLORKEY_MODE) {
  1198. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_CKMODE);
  1199. val |= ((pdata->colorkey_mode << 24) & LCD_WINCTRL2_CKMODE);
  1200. lcd->window[plane].winctrl2 = val;
  1201. }
  1202. if (pdata->flags & WIN_DOUBLE_BUFFER_MODE) {
  1203. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_DBM);
  1204. val |= ((pdata->double_buffer_mode << 23) & LCD_WINCTRL2_DBM);
  1205. lcd->window[plane].winctrl2 = val;
  1206. }
  1207. if (pdata->flags & WIN_RAM_ARRAY_MODE) {
  1208. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_RAM);
  1209. val |= ((pdata->ram_array_mode << 21) & LCD_WINCTRL2_RAM);
  1210. lcd->window[plane].winctrl2 = val;
  1211. }
  1212. /* Buffer line width programmed with WIN_SIZE */
  1213. if (pdata->flags & WIN_BUFFER_SCALE) {
  1214. val = lcd->window[plane].winctrl2 & ~(LCD_WINCTRL2_SCX |
  1215. LCD_WINCTRL2_SCY);
  1216. val |= ((pdata->xsize << 11) & LCD_WINCTRL2_SCX);
  1217. val |= ((pdata->ysize) & LCD_WINCTRL2_SCY);
  1218. lcd->window[plane].winctrl2 = val;
  1219. }
  1220. if (pdata->flags & WIN_ENABLE) {
  1221. val = lcd->winenable;
  1222. val &= ~(1<<plane);
  1223. val |= (pdata->enable & 1) << plane;
  1224. lcd->winenable = val;
  1225. }
  1226. wmb(); /* drain writebuffer */
  1227. }
  1228. static void get_window(unsigned int plane,
  1229. struct au1200_lcd_window_regs_t *pdata)
  1230. {
  1231. /* Window control register 0 */
  1232. pdata->xpos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OX) >> 21;
  1233. pdata->ypos = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_OY) >> 10;
  1234. pdata->alpha_color = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_A) >> 2;
  1235. pdata->alpha_mode = (lcd->window[plane].winctrl0 & LCD_WINCTRL0_AEN) >> 1;
  1236. /* Window control register 1 */
  1237. pdata->priority = (lcd->window[plane].winctrl1& LCD_WINCTRL1_PRI) >> 30;
  1238. pdata->channel = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PIPE) >> 29;
  1239. pdata->buffer_format = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_FRM) >> 25;
  1240. pdata->color_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_CCO) >> 24;
  1241. pdata->pixel_order = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_PO) >> 22;
  1242. pdata->xsize = ((lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZX) >> 11) + 1;
  1243. pdata->ysize = (lcd->window[plane].winctrl1 & LCD_WINCTRL1_SZY) + 1;
  1244. /* Window control register 2 */
  1245. pdata->colorkey_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_CKMODE) >> 24;
  1246. pdata->double_buffer_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_DBM) >> 23;
  1247. pdata->ram_array_mode = (lcd->window[plane].winctrl2 & LCD_WINCTRL2_RAM) >> 21;
  1248. pdata->enable = (lcd->winenable >> plane) & 1;
  1249. wmb(); /* drain writebuffer */
  1250. }
  1251. static int au1200fb_ioctl(struct fb_info *info, unsigned int cmd,
  1252. unsigned long arg)
  1253. {
  1254. struct au1200fb_device *fbdev = info->par;
  1255. int plane;
  1256. int val;
  1257. plane = fbinfo2index(info);
  1258. print_dbg("au1200fb: ioctl %d on plane %d\n", cmd, plane);
  1259. if (cmd == AU1200_LCD_FB_IOCTL) {
  1260. struct au1200_lcd_iodata_t iodata;
  1261. if (copy_from_user(&iodata, (void __user *) arg, sizeof(iodata)))
  1262. return -EFAULT;
  1263. print_dbg("FB IOCTL called\n");
  1264. switch (iodata.subcmd) {
  1265. case AU1200_LCD_SET_SCREEN:
  1266. print_dbg("AU1200_LCD_SET_SCREEN\n");
  1267. set_global(cmd, &iodata.global);
  1268. break;
  1269. case AU1200_LCD_GET_SCREEN:
  1270. print_dbg("AU1200_LCD_GET_SCREEN\n");
  1271. get_global(cmd, &iodata.global);
  1272. break;
  1273. case AU1200_LCD_SET_WINDOW:
  1274. print_dbg("AU1200_LCD_SET_WINDOW\n");
  1275. set_window(plane, &iodata.window);
  1276. break;
  1277. case AU1200_LCD_GET_WINDOW:
  1278. print_dbg("AU1200_LCD_GET_WINDOW\n");
  1279. get_window(plane, &iodata.window);
  1280. break;
  1281. case AU1200_LCD_SET_PANEL:
  1282. print_dbg("AU1200_LCD_SET_PANEL\n");
  1283. if ((iodata.global.panel_choice >= 0) &&
  1284. (iodata.global.panel_choice <
  1285. NUM_PANELS))
  1286. {
  1287. struct panel_settings *newpanel;
  1288. panel_index = iodata.global.panel_choice;
  1289. newpanel = &known_lcd_panels[panel_index];
  1290. au1200_setpanel(newpanel, fbdev->pd);
  1291. }
  1292. break;
  1293. case AU1200_LCD_GET_PANEL:
  1294. print_dbg("AU1200_LCD_GET_PANEL\n");
  1295. iodata.global.panel_choice = panel_index;
  1296. break;
  1297. default:
  1298. return -EINVAL;
  1299. }
  1300. val = copy_to_user((void __user *) arg, &iodata, sizeof(iodata));
  1301. if (val) {
  1302. print_dbg("error: could not copy %d bytes\n", val);
  1303. return -EFAULT;
  1304. }
  1305. }
  1306. return 0;
  1307. }
  1308. static struct fb_ops au1200fb_fb_ops = {
  1309. .owner = THIS_MODULE,
  1310. .fb_check_var = au1200fb_fb_check_var,
  1311. .fb_set_par = au1200fb_fb_set_par,
  1312. .fb_setcolreg = au1200fb_fb_setcolreg,
  1313. .fb_blank = au1200fb_fb_blank,
  1314. .fb_fillrect = sys_fillrect,
  1315. .fb_copyarea = sys_copyarea,
  1316. .fb_imageblit = sys_imageblit,
  1317. .fb_read = fb_sys_read,
  1318. .fb_write = fb_sys_write,
  1319. .fb_sync = NULL,
  1320. .fb_ioctl = au1200fb_ioctl,
  1321. .fb_mmap = au1200fb_fb_mmap,
  1322. };
  1323. /*-------------------------------------------------------------------------*/
  1324. static irqreturn_t au1200fb_handle_irq(int irq, void* dev_id)
  1325. {
  1326. /* Nothing to do for now, just clear any pending interrupt */
  1327. lcd->intstatus = lcd->intstatus;
  1328. wmb(); /* drain writebuffer */
  1329. return IRQ_HANDLED;
  1330. }
  1331. /*-------------------------------------------------------------------------*/
  1332. /* AU1200 LCD device probe helpers */
  1333. static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
  1334. {
  1335. struct fb_info *fbi = fbdev->fb_info;
  1336. int bpp, ret;
  1337. fbi->fbops = &au1200fb_fb_ops;
  1338. bpp = winbpp(win->w[fbdev->plane].mode_winctrl1);
  1339. /* Copy monitor specs from panel data */
  1340. /* fixme: we're setting up LCD controller windows, so these dont give a
  1341. damn as to what the monitor specs are (the panel itself does, but that
  1342. isn't done here...so maybe need a generic catchall monitor setting??? */
  1343. memcpy(&fbi->monspecs, &panel->monspecs, sizeof(struct fb_monspecs));
  1344. /* We first try the user mode passed in argument. If that failed,
  1345. * or if no one has been specified, we default to the first mode of the
  1346. * panel list. Note that after this call, var data will be set */
  1347. if (!fb_find_mode(&fbi->var,
  1348. fbi,
  1349. NULL, /* drv_info.opt_mode, */
  1350. fbi->monspecs.modedb,
  1351. fbi->monspecs.modedb_len,
  1352. fbi->monspecs.modedb,
  1353. bpp)) {
  1354. print_err("Cannot find valid mode for panel %s", panel->name);
  1355. return -EFAULT;
  1356. }
  1357. fbi->pseudo_palette = kcalloc(16, sizeof(u32), GFP_KERNEL);
  1358. if (!fbi->pseudo_palette)
  1359. return -ENOMEM;
  1360. ret = fb_alloc_cmap(&fbi->cmap, AU1200_LCD_NBR_PALETTE_ENTRIES, 0);
  1361. if (ret < 0) {
  1362. print_err("Fail to allocate colormap (%d entries)",
  1363. AU1200_LCD_NBR_PALETTE_ENTRIES);
  1364. return ret;
  1365. }
  1366. strncpy(fbi->fix.id, "AU1200", sizeof(fbi->fix.id));
  1367. fbi->fix.smem_start = fbdev->fb_phys;
  1368. fbi->fix.smem_len = fbdev->fb_len;
  1369. fbi->fix.type = FB_TYPE_PACKED_PIXELS;
  1370. fbi->fix.xpanstep = 0;
  1371. fbi->fix.ypanstep = 0;
  1372. fbi->fix.mmio_start = 0;
  1373. fbi->fix.mmio_len = 0;
  1374. fbi->fix.accel = FB_ACCEL_NONE;
  1375. fbi->screen_base = (char __iomem *) fbdev->fb_mem;
  1376. au1200fb_update_fbinfo(fbi);
  1377. return 0;
  1378. }
  1379. /*-------------------------------------------------------------------------*/
  1380. static int au1200fb_setup(struct au1200fb_platdata *pd)
  1381. {
  1382. char *options = NULL;
  1383. char *this_opt, *endptr;
  1384. int num_panels = ARRAY_SIZE(known_lcd_panels);
  1385. int panel_idx = -1;
  1386. fb_get_options(DRIVER_NAME, &options);
  1387. if (!options)
  1388. goto out;
  1389. while ((this_opt = strsep(&options, ",")) != NULL) {
  1390. /* Panel option - can be panel name,
  1391. * "bs" for board-switch, or number/index */
  1392. if (!strncmp(this_opt, "panel:", 6)) {
  1393. int i;
  1394. long int li;
  1395. char *endptr;
  1396. this_opt += 6;
  1397. /* First check for index, which allows
  1398. * to short circuit this mess */
  1399. li = simple_strtol(this_opt, &endptr, 0);
  1400. if (*endptr == '\0')
  1401. panel_idx = (int)li;
  1402. else if (strcmp(this_opt, "bs") == 0)
  1403. panel_idx = pd->panel_index();
  1404. else {
  1405. for (i = 0; i < num_panels; i++) {
  1406. if (!strcmp(this_opt,
  1407. known_lcd_panels[i].name)) {
  1408. panel_idx = i;
  1409. break;
  1410. }
  1411. }
  1412. }
  1413. if ((panel_idx < 0) || (panel_idx >= num_panels))
  1414. print_warn("Panel %s not supported!", this_opt);
  1415. else
  1416. panel_index = panel_idx;
  1417. } else if (strncmp(this_opt, "nohwcursor", 10) == 0)
  1418. nohwcursor = 1;
  1419. else if (strncmp(this_opt, "devices:", 8) == 0) {
  1420. this_opt += 8;
  1421. device_count = simple_strtol(this_opt, &endptr, 0);
  1422. if ((device_count < 0) ||
  1423. (device_count > MAX_DEVICE_COUNT))
  1424. device_count = MAX_DEVICE_COUNT;
  1425. } else if (strncmp(this_opt, "wincfg:", 7) == 0) {
  1426. this_opt += 7;
  1427. window_index = simple_strtol(this_opt, &endptr, 0);
  1428. if ((window_index < 0) ||
  1429. (window_index >= ARRAY_SIZE(windows)))
  1430. window_index = DEFAULT_WINDOW_INDEX;
  1431. } else if (strncmp(this_opt, "off", 3) == 0)
  1432. return 1;
  1433. else
  1434. print_warn("Unsupported option \"%s\"", this_opt);
  1435. }
  1436. out:
  1437. return 0;
  1438. }
  1439. /* AU1200 LCD controller device driver */
  1440. static int au1200fb_drv_probe(struct platform_device *dev)
  1441. {
  1442. struct au1200fb_device *fbdev;
  1443. struct au1200fb_platdata *pd;
  1444. struct fb_info *fbi = NULL;
  1445. unsigned long page;
  1446. int bpp, plane, ret, irq;
  1447. print_info("" DRIVER_DESC "");
  1448. pd = dev->dev.platform_data;
  1449. if (!pd)
  1450. return -ENODEV;
  1451. /* Setup driver with options */
  1452. if (au1200fb_setup(pd))
  1453. return -ENODEV;
  1454. /* Point to the panel selected */
  1455. panel = &known_lcd_panels[panel_index];
  1456. win = &windows[window_index];
  1457. printk(DRIVER_NAME ": Panel %d %s\n", panel_index, panel->name);
  1458. printk(DRIVER_NAME ": Win %d %s\n", window_index, win->name);
  1459. for (plane = 0; plane < device_count; ++plane) {
  1460. bpp = winbpp(win->w[plane].mode_winctrl1);
  1461. if (win->w[plane].xres == 0)
  1462. win->w[plane].xres = panel->Xres;
  1463. if (win->w[plane].yres == 0)
  1464. win->w[plane].yres = panel->Yres;
  1465. fbi = framebuffer_alloc(sizeof(struct au1200fb_device),
  1466. &dev->dev);
  1467. if (!fbi) {
  1468. ret = -ENOMEM;
  1469. goto failed;
  1470. }
  1471. _au1200fb_infos[plane] = fbi;
  1472. fbdev = fbi->par;
  1473. fbdev->fb_info = fbi;
  1474. fbdev->pd = pd;
  1475. fbdev->plane = plane;
  1476. /* Allocate the framebuffer to the maximum screen size */
  1477. fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
  1478. fbdev->fb_mem = dmam_alloc_attrs(&dev->dev,
  1479. PAGE_ALIGN(fbdev->fb_len),
  1480. &fbdev->fb_phys, GFP_KERNEL,
  1481. DMA_ATTR_NON_CONSISTENT);
  1482. if (!fbdev->fb_mem) {
  1483. print_err("fail to allocate framebuffer (size: %dK))",
  1484. fbdev->fb_len / 1024);
  1485. ret = -ENOMEM;
  1486. goto failed;
  1487. }
  1488. /*
  1489. * Set page reserved so that mmap will work. This is necessary
  1490. * since we'll be remapping normal memory.
  1491. */
  1492. for (page = (unsigned long)fbdev->fb_phys;
  1493. page < PAGE_ALIGN((unsigned long)fbdev->fb_phys +
  1494. fbdev->fb_len);
  1495. page += PAGE_SIZE) {
  1496. SetPageReserved(pfn_to_page(page >> PAGE_SHIFT)); /* LCD DMA is NOT coherent on Au1200 */
  1497. }
  1498. print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
  1499. print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
  1500. /* Init FB data */
  1501. ret = au1200fb_init_fbinfo(fbdev);
  1502. if (ret < 0)
  1503. goto failed;
  1504. /* Register new framebuffer */
  1505. ret = register_framebuffer(fbi);
  1506. if (ret < 0) {
  1507. print_err("cannot register new framebuffer");
  1508. goto failed;
  1509. }
  1510. au1200fb_fb_set_par(fbi);
  1511. #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
  1512. if (plane == 0)
  1513. if (fb_prepare_logo(fbi, FB_ROTATE_UR)) {
  1514. /* Start display and show logo on boot */
  1515. fb_set_cmap(&fbi->cmap, fbi);
  1516. fb_show_logo(fbi, FB_ROTATE_UR);
  1517. }
  1518. #endif
  1519. }
  1520. /* Now hook interrupt too */
  1521. irq = platform_get_irq(dev, 0);
  1522. ret = request_irq(irq, au1200fb_handle_irq,
  1523. IRQF_SHARED, "lcd", (void *)dev);
  1524. if (ret) {
  1525. print_err("fail to request interrupt line %d (err: %d)",
  1526. irq, ret);
  1527. goto failed;
  1528. }
  1529. platform_set_drvdata(dev, pd);
  1530. /* Kickstart the panel */
  1531. au1200_setpanel(panel, pd);
  1532. return 0;
  1533. failed:
  1534. for (plane = 0; plane < device_count; ++plane) {
  1535. fbi = _au1200fb_infos[plane];
  1536. if (!fbi)
  1537. break;
  1538. /* Clean up all probe data */
  1539. unregister_framebuffer(fbi);
  1540. if (fbi->cmap.len != 0)
  1541. fb_dealloc_cmap(&fbi->cmap);
  1542. kfree(fbi->pseudo_palette);
  1543. framebuffer_release(fbi);
  1544. _au1200fb_infos[plane] = NULL;
  1545. }
  1546. return ret;
  1547. }
  1548. static int au1200fb_drv_remove(struct platform_device *dev)
  1549. {
  1550. struct au1200fb_platdata *pd = platform_get_drvdata(dev);
  1551. struct fb_info *fbi;
  1552. int plane;
  1553. /* Turn off the panel */
  1554. au1200_setpanel(NULL, pd);
  1555. for (plane = 0; plane < device_count; ++plane) {
  1556. fbi = _au1200fb_infos[plane];
  1557. /* Clean up all probe data */
  1558. unregister_framebuffer(fbi);
  1559. if (fbi->cmap.len != 0)
  1560. fb_dealloc_cmap(&fbi->cmap);
  1561. kfree(fbi->pseudo_palette);
  1562. framebuffer_release(fbi);
  1563. _au1200fb_infos[plane] = NULL;
  1564. }
  1565. free_irq(platform_get_irq(dev, 0), (void *)dev);
  1566. return 0;
  1567. }
  1568. #ifdef CONFIG_PM
  1569. static int au1200fb_drv_suspend(struct device *dev)
  1570. {
  1571. struct au1200fb_platdata *pd = dev_get_drvdata(dev);
  1572. au1200_setpanel(NULL, pd);
  1573. lcd->outmask = 0;
  1574. wmb(); /* drain writebuffer */
  1575. return 0;
  1576. }
  1577. static int au1200fb_drv_resume(struct device *dev)
  1578. {
  1579. struct au1200fb_platdata *pd = dev_get_drvdata(dev);
  1580. struct fb_info *fbi;
  1581. int i;
  1582. /* Kickstart the panel */
  1583. au1200_setpanel(panel, pd);
  1584. for (i = 0; i < device_count; i++) {
  1585. fbi = _au1200fb_infos[i];
  1586. au1200fb_fb_set_par(fbi);
  1587. }
  1588. return 0;
  1589. }
  1590. static const struct dev_pm_ops au1200fb_pmops = {
  1591. .suspend = au1200fb_drv_suspend,
  1592. .resume = au1200fb_drv_resume,
  1593. .freeze = au1200fb_drv_suspend,
  1594. .thaw = au1200fb_drv_resume,
  1595. };
  1596. #define AU1200FB_PMOPS (&au1200fb_pmops)
  1597. #else
  1598. #define AU1200FB_PMOPS NULL
  1599. #endif /* CONFIG_PM */
  1600. static struct platform_driver au1200fb_driver = {
  1601. .driver = {
  1602. .name = "au1200-lcd",
  1603. .pm = AU1200FB_PMOPS,
  1604. },
  1605. .probe = au1200fb_drv_probe,
  1606. .remove = au1200fb_drv_remove,
  1607. };
  1608. module_platform_driver(au1200fb_driver);
  1609. MODULE_DESCRIPTION(DRIVER_DESC);
  1610. MODULE_LICENSE("GPL");