au1200fb.c 51 KB

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