au1200fb.c 49 KB

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