vpbe_osd.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  1. /*
  2. * Copyright (C) 2007-2010 Texas Instruments Inc
  3. * Copyright (C) 2007 MontaVista Software, Inc.
  4. *
  5. * Andy Lowe (alowe@mvista.com), MontaVista Software
  6. * - Initial version
  7. * Murali Karicheri (mkaricheri@gmail.com), Texas Instruments Ltd.
  8. * - ported to sub device interface
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation version 2.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <linux/module.h>
  25. #include <linux/kernel.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/clk.h>
  29. #include <linux/slab.h>
  30. #include <mach/cputype.h>
  31. #include <mach/hardware.h>
  32. #include <media/davinci/vpss.h>
  33. #include <media/v4l2-device.h>
  34. #include <media/davinci/vpbe_types.h>
  35. #include <media/davinci/vpbe_osd.h>
  36. #include <linux/io.h>
  37. #include "vpbe_osd_regs.h"
  38. #define MODULE_NAME "davinci-vpbe-osd"
  39. static struct platform_device_id vpbe_osd_devtype[] = {
  40. {
  41. .name = DM644X_VPBE_OSD_SUBDEV_NAME,
  42. .driver_data = VPBE_VERSION_1,
  43. }, {
  44. .name = DM365_VPBE_OSD_SUBDEV_NAME,
  45. .driver_data = VPBE_VERSION_2,
  46. }, {
  47. .name = DM355_VPBE_OSD_SUBDEV_NAME,
  48. .driver_data = VPBE_VERSION_3,
  49. },
  50. {
  51. /* sentinel */
  52. }
  53. };
  54. MODULE_DEVICE_TABLE(platform, vpbe_osd_devtype);
  55. /* register access routines */
  56. static inline u32 osd_read(struct osd_state *sd, u32 offset)
  57. {
  58. struct osd_state *osd = sd;
  59. return readl(osd->osd_base + offset);
  60. }
  61. static inline u32 osd_write(struct osd_state *sd, u32 val, u32 offset)
  62. {
  63. struct osd_state *osd = sd;
  64. writel(val, osd->osd_base + offset);
  65. return val;
  66. }
  67. static inline u32 osd_set(struct osd_state *sd, u32 mask, u32 offset)
  68. {
  69. struct osd_state *osd = sd;
  70. void __iomem *addr = osd->osd_base + offset;
  71. u32 val = readl(addr) | mask;
  72. writel(val, addr);
  73. return val;
  74. }
  75. static inline u32 osd_clear(struct osd_state *sd, u32 mask, u32 offset)
  76. {
  77. struct osd_state *osd = sd;
  78. void __iomem *addr = osd->osd_base + offset;
  79. u32 val = readl(addr) & ~mask;
  80. writel(val, addr);
  81. return val;
  82. }
  83. static inline u32 osd_modify(struct osd_state *sd, u32 mask, u32 val,
  84. u32 offset)
  85. {
  86. struct osd_state *osd = sd;
  87. void __iomem *addr = osd->osd_base + offset;
  88. u32 new_val = (readl(addr) & ~mask) | (val & mask);
  89. writel(new_val, addr);
  90. return new_val;
  91. }
  92. /* define some macros for layer and pixfmt classification */
  93. #define is_osd_win(layer) (((layer) == WIN_OSD0) || ((layer) == WIN_OSD1))
  94. #define is_vid_win(layer) (((layer) == WIN_VID0) || ((layer) == WIN_VID1))
  95. #define is_rgb_pixfmt(pixfmt) \
  96. (((pixfmt) == PIXFMT_RGB565) || ((pixfmt) == PIXFMT_RGB888))
  97. #define is_yc_pixfmt(pixfmt) \
  98. (((pixfmt) == PIXFMT_YCBCRI) || ((pixfmt) == PIXFMT_YCRCBI) || \
  99. ((pixfmt) == PIXFMT_NV12))
  100. #define MAX_WIN_SIZE OSD_VIDWIN0XP_V0X
  101. #define MAX_LINE_LENGTH (OSD_VIDWIN0OFST_V0LO << 5)
  102. /**
  103. * _osd_dm6446_vid0_pingpong() - field inversion fix for DM6446
  104. * @sd - ptr to struct osd_state
  105. * @field_inversion - inversion flag
  106. * @fb_base_phys - frame buffer address
  107. * @lconfig - ptr to layer config
  108. *
  109. * This routine implements a workaround for the field signal inversion silicon
  110. * erratum described in Advisory 1.3.8 for the DM6446. The fb_base_phys and
  111. * lconfig parameters apply to the vid0 window. This routine should be called
  112. * whenever the vid0 layer configuration or start address is modified, or when
  113. * the OSD field inversion setting is modified.
  114. * Returns: 1 if the ping-pong buffers need to be toggled in the vsync isr, or
  115. * 0 otherwise
  116. */
  117. static int _osd_dm6446_vid0_pingpong(struct osd_state *sd,
  118. int field_inversion,
  119. unsigned long fb_base_phys,
  120. const struct osd_layer_config *lconfig)
  121. {
  122. struct osd_platform_data *pdata;
  123. pdata = (struct osd_platform_data *)sd->dev->platform_data;
  124. if (pdata != NULL && pdata->field_inv_wa_enable) {
  125. if (!field_inversion || !lconfig->interlaced) {
  126. osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN0ADR);
  127. osd_write(sd, fb_base_phys & ~0x1F, OSD_PPVWIN0ADR);
  128. osd_modify(sd, OSD_MISCCTL_PPSW | OSD_MISCCTL_PPRV, 0,
  129. OSD_MISCCTL);
  130. return 0;
  131. } else {
  132. unsigned miscctl = OSD_MISCCTL_PPRV;
  133. osd_write(sd,
  134. (fb_base_phys & ~0x1F) - lconfig->line_length,
  135. OSD_VIDWIN0ADR);
  136. osd_write(sd,
  137. (fb_base_phys & ~0x1F) + lconfig->line_length,
  138. OSD_PPVWIN0ADR);
  139. osd_modify(sd,
  140. OSD_MISCCTL_PPSW | OSD_MISCCTL_PPRV, miscctl,
  141. OSD_MISCCTL);
  142. return 1;
  143. }
  144. }
  145. return 0;
  146. }
  147. static void _osd_set_field_inversion(struct osd_state *sd, int enable)
  148. {
  149. unsigned fsinv = 0;
  150. if (enable)
  151. fsinv = OSD_MODE_FSINV;
  152. osd_modify(sd, OSD_MODE_FSINV, fsinv, OSD_MODE);
  153. }
  154. static void _osd_set_blink_attribute(struct osd_state *sd, int enable,
  155. enum osd_blink_interval blink)
  156. {
  157. u32 osdatrmd = 0;
  158. if (enable) {
  159. osdatrmd |= OSD_OSDATRMD_BLNK;
  160. osdatrmd |= blink << OSD_OSDATRMD_BLNKINT_SHIFT;
  161. }
  162. /* caller must ensure that OSD1 is configured in attribute mode */
  163. osd_modify(sd, OSD_OSDATRMD_BLNKINT | OSD_OSDATRMD_BLNK, osdatrmd,
  164. OSD_OSDATRMD);
  165. }
  166. static void _osd_set_rom_clut(struct osd_state *sd,
  167. enum osd_rom_clut rom_clut)
  168. {
  169. if (rom_clut == ROM_CLUT0)
  170. osd_clear(sd, OSD_MISCCTL_RSEL, OSD_MISCCTL);
  171. else
  172. osd_set(sd, OSD_MISCCTL_RSEL, OSD_MISCCTL);
  173. }
  174. static void _osd_set_palette_map(struct osd_state *sd,
  175. enum osd_win_layer osdwin,
  176. unsigned char pixel_value,
  177. unsigned char clut_index,
  178. enum osd_pix_format pixfmt)
  179. {
  180. static const int map_2bpp[] = { 0, 5, 10, 15 };
  181. static const int map_1bpp[] = { 0, 15 };
  182. int bmp_offset;
  183. int bmp_shift;
  184. int bmp_mask;
  185. int bmp_reg;
  186. switch (pixfmt) {
  187. case PIXFMT_1BPP:
  188. bmp_reg = map_1bpp[pixel_value & 0x1];
  189. break;
  190. case PIXFMT_2BPP:
  191. bmp_reg = map_2bpp[pixel_value & 0x3];
  192. break;
  193. case PIXFMT_4BPP:
  194. bmp_reg = pixel_value & 0xf;
  195. break;
  196. default:
  197. return;
  198. }
  199. switch (osdwin) {
  200. case OSDWIN_OSD0:
  201. bmp_offset = OSD_W0BMP01 + (bmp_reg >> 1) * sizeof(u32);
  202. break;
  203. case OSDWIN_OSD1:
  204. bmp_offset = OSD_W1BMP01 + (bmp_reg >> 1) * sizeof(u32);
  205. break;
  206. default:
  207. return;
  208. }
  209. if (bmp_reg & 1) {
  210. bmp_shift = 8;
  211. bmp_mask = 0xff << 8;
  212. } else {
  213. bmp_shift = 0;
  214. bmp_mask = 0xff;
  215. }
  216. osd_modify(sd, bmp_mask, clut_index << bmp_shift, bmp_offset);
  217. }
  218. static void _osd_set_rec601_attenuation(struct osd_state *sd,
  219. enum osd_win_layer osdwin, int enable)
  220. {
  221. switch (osdwin) {
  222. case OSDWIN_OSD0:
  223. osd_modify(sd, OSD_OSDWIN0MD_ATN0E,
  224. enable ? OSD_OSDWIN0MD_ATN0E : 0,
  225. OSD_OSDWIN0MD);
  226. if (sd->vpbe_type == VPBE_VERSION_1)
  227. osd_modify(sd, OSD_OSDWIN0MD_ATN0E,
  228. enable ? OSD_OSDWIN0MD_ATN0E : 0,
  229. OSD_OSDWIN0MD);
  230. else if ((sd->vpbe_type == VPBE_VERSION_3) ||
  231. (sd->vpbe_type == VPBE_VERSION_2))
  232. osd_modify(sd, OSD_EXTMODE_ATNOSD0EN,
  233. enable ? OSD_EXTMODE_ATNOSD0EN : 0,
  234. OSD_EXTMODE);
  235. break;
  236. case OSDWIN_OSD1:
  237. osd_modify(sd, OSD_OSDWIN1MD_ATN1E,
  238. enable ? OSD_OSDWIN1MD_ATN1E : 0,
  239. OSD_OSDWIN1MD);
  240. if (sd->vpbe_type == VPBE_VERSION_1)
  241. osd_modify(sd, OSD_OSDWIN1MD_ATN1E,
  242. enable ? OSD_OSDWIN1MD_ATN1E : 0,
  243. OSD_OSDWIN1MD);
  244. else if ((sd->vpbe_type == VPBE_VERSION_3) ||
  245. (sd->vpbe_type == VPBE_VERSION_2))
  246. osd_modify(sd, OSD_EXTMODE_ATNOSD1EN,
  247. enable ? OSD_EXTMODE_ATNOSD1EN : 0,
  248. OSD_EXTMODE);
  249. break;
  250. }
  251. }
  252. static void _osd_set_blending_factor(struct osd_state *sd,
  253. enum osd_win_layer osdwin,
  254. enum osd_blending_factor blend)
  255. {
  256. switch (osdwin) {
  257. case OSDWIN_OSD0:
  258. osd_modify(sd, OSD_OSDWIN0MD_BLND0,
  259. blend << OSD_OSDWIN0MD_BLND0_SHIFT, OSD_OSDWIN0MD);
  260. break;
  261. case OSDWIN_OSD1:
  262. osd_modify(sd, OSD_OSDWIN1MD_BLND1,
  263. blend << OSD_OSDWIN1MD_BLND1_SHIFT, OSD_OSDWIN1MD);
  264. break;
  265. }
  266. }
  267. static void _osd_enable_rgb888_pixblend(struct osd_state *sd,
  268. enum osd_win_layer osdwin)
  269. {
  270. osd_modify(sd, OSD_MISCCTL_BLDSEL, 0, OSD_MISCCTL);
  271. switch (osdwin) {
  272. case OSDWIN_OSD0:
  273. osd_modify(sd, OSD_EXTMODE_OSD0BLDCHR,
  274. OSD_EXTMODE_OSD0BLDCHR, OSD_EXTMODE);
  275. break;
  276. case OSDWIN_OSD1:
  277. osd_modify(sd, OSD_EXTMODE_OSD1BLDCHR,
  278. OSD_EXTMODE_OSD1BLDCHR, OSD_EXTMODE);
  279. break;
  280. }
  281. }
  282. static void _osd_enable_color_key(struct osd_state *sd,
  283. enum osd_win_layer osdwin,
  284. unsigned colorkey,
  285. enum osd_pix_format pixfmt)
  286. {
  287. switch (pixfmt) {
  288. case PIXFMT_1BPP:
  289. case PIXFMT_2BPP:
  290. case PIXFMT_4BPP:
  291. case PIXFMT_8BPP:
  292. if (sd->vpbe_type == VPBE_VERSION_3) {
  293. switch (osdwin) {
  294. case OSDWIN_OSD0:
  295. osd_modify(sd, OSD_TRANSPBMPIDX_BMP0,
  296. colorkey <<
  297. OSD_TRANSPBMPIDX_BMP0_SHIFT,
  298. OSD_TRANSPBMPIDX);
  299. break;
  300. case OSDWIN_OSD1:
  301. osd_modify(sd, OSD_TRANSPBMPIDX_BMP1,
  302. colorkey <<
  303. OSD_TRANSPBMPIDX_BMP1_SHIFT,
  304. OSD_TRANSPBMPIDX);
  305. break;
  306. }
  307. }
  308. break;
  309. case PIXFMT_RGB565:
  310. if (sd->vpbe_type == VPBE_VERSION_1)
  311. osd_write(sd, colorkey & OSD_TRANSPVAL_RGBTRANS,
  312. OSD_TRANSPVAL);
  313. else if (sd->vpbe_type == VPBE_VERSION_3)
  314. osd_write(sd, colorkey & OSD_TRANSPVALL_RGBL,
  315. OSD_TRANSPVALL);
  316. break;
  317. case PIXFMT_YCBCRI:
  318. case PIXFMT_YCRCBI:
  319. if (sd->vpbe_type == VPBE_VERSION_3)
  320. osd_modify(sd, OSD_TRANSPVALU_Y, colorkey,
  321. OSD_TRANSPVALU);
  322. break;
  323. case PIXFMT_RGB888:
  324. if (sd->vpbe_type == VPBE_VERSION_3) {
  325. osd_write(sd, colorkey & OSD_TRANSPVALL_RGBL,
  326. OSD_TRANSPVALL);
  327. osd_modify(sd, OSD_TRANSPVALU_RGBU, colorkey >> 16,
  328. OSD_TRANSPVALU);
  329. }
  330. break;
  331. default:
  332. break;
  333. }
  334. switch (osdwin) {
  335. case OSDWIN_OSD0:
  336. osd_set(sd, OSD_OSDWIN0MD_TE0, OSD_OSDWIN0MD);
  337. break;
  338. case OSDWIN_OSD1:
  339. osd_set(sd, OSD_OSDWIN1MD_TE1, OSD_OSDWIN1MD);
  340. break;
  341. }
  342. }
  343. static void _osd_disable_color_key(struct osd_state *sd,
  344. enum osd_win_layer osdwin)
  345. {
  346. switch (osdwin) {
  347. case OSDWIN_OSD0:
  348. osd_clear(sd, OSD_OSDWIN0MD_TE0, OSD_OSDWIN0MD);
  349. break;
  350. case OSDWIN_OSD1:
  351. osd_clear(sd, OSD_OSDWIN1MD_TE1, OSD_OSDWIN1MD);
  352. break;
  353. }
  354. }
  355. static void _osd_set_osd_clut(struct osd_state *sd,
  356. enum osd_win_layer osdwin,
  357. enum osd_clut clut)
  358. {
  359. u32 winmd = 0;
  360. switch (osdwin) {
  361. case OSDWIN_OSD0:
  362. if (clut == RAM_CLUT)
  363. winmd |= OSD_OSDWIN0MD_CLUTS0;
  364. osd_modify(sd, OSD_OSDWIN0MD_CLUTS0, winmd, OSD_OSDWIN0MD);
  365. break;
  366. case OSDWIN_OSD1:
  367. if (clut == RAM_CLUT)
  368. winmd |= OSD_OSDWIN1MD_CLUTS1;
  369. osd_modify(sd, OSD_OSDWIN1MD_CLUTS1, winmd, OSD_OSDWIN1MD);
  370. break;
  371. }
  372. }
  373. static void _osd_set_zoom(struct osd_state *sd, enum osd_layer layer,
  374. enum osd_zoom_factor h_zoom,
  375. enum osd_zoom_factor v_zoom)
  376. {
  377. u32 winmd = 0;
  378. switch (layer) {
  379. case WIN_OSD0:
  380. winmd |= (h_zoom << OSD_OSDWIN0MD_OHZ0_SHIFT);
  381. winmd |= (v_zoom << OSD_OSDWIN0MD_OVZ0_SHIFT);
  382. osd_modify(sd, OSD_OSDWIN0MD_OHZ0 | OSD_OSDWIN0MD_OVZ0, winmd,
  383. OSD_OSDWIN0MD);
  384. break;
  385. case WIN_VID0:
  386. winmd |= (h_zoom << OSD_VIDWINMD_VHZ0_SHIFT);
  387. winmd |= (v_zoom << OSD_VIDWINMD_VVZ0_SHIFT);
  388. osd_modify(sd, OSD_VIDWINMD_VHZ0 | OSD_VIDWINMD_VVZ0, winmd,
  389. OSD_VIDWINMD);
  390. break;
  391. case WIN_OSD1:
  392. winmd |= (h_zoom << OSD_OSDWIN1MD_OHZ1_SHIFT);
  393. winmd |= (v_zoom << OSD_OSDWIN1MD_OVZ1_SHIFT);
  394. osd_modify(sd, OSD_OSDWIN1MD_OHZ1 | OSD_OSDWIN1MD_OVZ1, winmd,
  395. OSD_OSDWIN1MD);
  396. break;
  397. case WIN_VID1:
  398. winmd |= (h_zoom << OSD_VIDWINMD_VHZ1_SHIFT);
  399. winmd |= (v_zoom << OSD_VIDWINMD_VVZ1_SHIFT);
  400. osd_modify(sd, OSD_VIDWINMD_VHZ1 | OSD_VIDWINMD_VVZ1, winmd,
  401. OSD_VIDWINMD);
  402. break;
  403. }
  404. }
  405. static void _osd_disable_layer(struct osd_state *sd, enum osd_layer layer)
  406. {
  407. switch (layer) {
  408. case WIN_OSD0:
  409. osd_clear(sd, OSD_OSDWIN0MD_OACT0, OSD_OSDWIN0MD);
  410. break;
  411. case WIN_VID0:
  412. osd_clear(sd, OSD_VIDWINMD_ACT0, OSD_VIDWINMD);
  413. break;
  414. case WIN_OSD1:
  415. /* disable attribute mode as well as disabling the window */
  416. osd_clear(sd, OSD_OSDWIN1MD_OASW | OSD_OSDWIN1MD_OACT1,
  417. OSD_OSDWIN1MD);
  418. break;
  419. case WIN_VID1:
  420. osd_clear(sd, OSD_VIDWINMD_ACT1, OSD_VIDWINMD);
  421. break;
  422. }
  423. }
  424. static void osd_disable_layer(struct osd_state *sd, enum osd_layer layer)
  425. {
  426. struct osd_state *osd = sd;
  427. struct osd_window_state *win = &osd->win[layer];
  428. unsigned long flags;
  429. spin_lock_irqsave(&osd->lock, flags);
  430. if (!win->is_enabled) {
  431. spin_unlock_irqrestore(&osd->lock, flags);
  432. return;
  433. }
  434. win->is_enabled = 0;
  435. _osd_disable_layer(sd, layer);
  436. spin_unlock_irqrestore(&osd->lock, flags);
  437. }
  438. static void _osd_enable_attribute_mode(struct osd_state *sd)
  439. {
  440. /* enable attribute mode for OSD1 */
  441. osd_set(sd, OSD_OSDWIN1MD_OASW, OSD_OSDWIN1MD);
  442. }
  443. static void _osd_enable_layer(struct osd_state *sd, enum osd_layer layer)
  444. {
  445. switch (layer) {
  446. case WIN_OSD0:
  447. osd_set(sd, OSD_OSDWIN0MD_OACT0, OSD_OSDWIN0MD);
  448. break;
  449. case WIN_VID0:
  450. osd_set(sd, OSD_VIDWINMD_ACT0, OSD_VIDWINMD);
  451. break;
  452. case WIN_OSD1:
  453. /* enable OSD1 and disable attribute mode */
  454. osd_modify(sd, OSD_OSDWIN1MD_OASW | OSD_OSDWIN1MD_OACT1,
  455. OSD_OSDWIN1MD_OACT1, OSD_OSDWIN1MD);
  456. break;
  457. case WIN_VID1:
  458. osd_set(sd, OSD_VIDWINMD_ACT1, OSD_VIDWINMD);
  459. break;
  460. }
  461. }
  462. static int osd_enable_layer(struct osd_state *sd, enum osd_layer layer,
  463. int otherwin)
  464. {
  465. struct osd_state *osd = sd;
  466. struct osd_window_state *win = &osd->win[layer];
  467. struct osd_layer_config *cfg = &win->lconfig;
  468. unsigned long flags;
  469. spin_lock_irqsave(&osd->lock, flags);
  470. /*
  471. * use otherwin flag to know this is the other vid window
  472. * in YUV420 mode, if is, skip this check
  473. */
  474. if (!otherwin && (!win->is_allocated ||
  475. !win->fb_base_phys ||
  476. !cfg->line_length ||
  477. !cfg->xsize ||
  478. !cfg->ysize)) {
  479. spin_unlock_irqrestore(&osd->lock, flags);
  480. return -1;
  481. }
  482. if (win->is_enabled) {
  483. spin_unlock_irqrestore(&osd->lock, flags);
  484. return 0;
  485. }
  486. win->is_enabled = 1;
  487. if (cfg->pixfmt != PIXFMT_OSD_ATTR)
  488. _osd_enable_layer(sd, layer);
  489. else {
  490. _osd_enable_attribute_mode(sd);
  491. _osd_set_blink_attribute(sd, osd->is_blinking, osd->blink);
  492. }
  493. spin_unlock_irqrestore(&osd->lock, flags);
  494. return 0;
  495. }
  496. #define OSD_SRC_ADDR_HIGH4 0x7800000
  497. #define OSD_SRC_ADDR_HIGH7 0x7F0000
  498. #define OSD_SRCADD_OFSET_SFT 23
  499. #define OSD_SRCADD_ADD_SFT 16
  500. #define OSD_WINADL_MASK 0xFFFF
  501. #define OSD_WINOFST_MASK 0x1000
  502. #define VPBE_REG_BASE 0x80000000
  503. static void _osd_start_layer(struct osd_state *sd, enum osd_layer layer,
  504. unsigned long fb_base_phys,
  505. unsigned long cbcr_ofst)
  506. {
  507. if (sd->vpbe_type == VPBE_VERSION_1) {
  508. switch (layer) {
  509. case WIN_OSD0:
  510. osd_write(sd, fb_base_phys & ~0x1F, OSD_OSDWIN0ADR);
  511. break;
  512. case WIN_VID0:
  513. osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN0ADR);
  514. break;
  515. case WIN_OSD1:
  516. osd_write(sd, fb_base_phys & ~0x1F, OSD_OSDWIN1ADR);
  517. break;
  518. case WIN_VID1:
  519. osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN1ADR);
  520. break;
  521. }
  522. } else if (sd->vpbe_type == VPBE_VERSION_3) {
  523. unsigned long fb_offset_32 =
  524. (fb_base_phys - VPBE_REG_BASE) >> 5;
  525. switch (layer) {
  526. case WIN_OSD0:
  527. osd_modify(sd, OSD_OSDWINADH_O0AH,
  528. fb_offset_32 >> (OSD_SRCADD_ADD_SFT -
  529. OSD_OSDWINADH_O0AH_SHIFT),
  530. OSD_OSDWINADH);
  531. osd_write(sd, fb_offset_32 & OSD_OSDWIN0ADL_O0AL,
  532. OSD_OSDWIN0ADL);
  533. break;
  534. case WIN_VID0:
  535. osd_modify(sd, OSD_VIDWINADH_V0AH,
  536. fb_offset_32 >> (OSD_SRCADD_ADD_SFT -
  537. OSD_VIDWINADH_V0AH_SHIFT),
  538. OSD_VIDWINADH);
  539. osd_write(sd, fb_offset_32 & OSD_VIDWIN0ADL_V0AL,
  540. OSD_VIDWIN0ADL);
  541. break;
  542. case WIN_OSD1:
  543. osd_modify(sd, OSD_OSDWINADH_O1AH,
  544. fb_offset_32 >> (OSD_SRCADD_ADD_SFT -
  545. OSD_OSDWINADH_O1AH_SHIFT),
  546. OSD_OSDWINADH);
  547. osd_write(sd, fb_offset_32 & OSD_OSDWIN1ADL_O1AL,
  548. OSD_OSDWIN1ADL);
  549. break;
  550. case WIN_VID1:
  551. osd_modify(sd, OSD_VIDWINADH_V1AH,
  552. fb_offset_32 >> (OSD_SRCADD_ADD_SFT -
  553. OSD_VIDWINADH_V1AH_SHIFT),
  554. OSD_VIDWINADH);
  555. osd_write(sd, fb_offset_32 & OSD_VIDWIN1ADL_V1AL,
  556. OSD_VIDWIN1ADL);
  557. break;
  558. }
  559. } else if (sd->vpbe_type == VPBE_VERSION_2) {
  560. struct osd_window_state *win = &sd->win[layer];
  561. unsigned long fb_offset_32, cbcr_offset_32;
  562. fb_offset_32 = fb_base_phys - VPBE_REG_BASE;
  563. if (cbcr_ofst)
  564. cbcr_offset_32 = cbcr_ofst;
  565. else
  566. cbcr_offset_32 = win->lconfig.line_length *
  567. win->lconfig.ysize;
  568. cbcr_offset_32 += fb_offset_32;
  569. fb_offset_32 = fb_offset_32 >> 5;
  570. cbcr_offset_32 = cbcr_offset_32 >> 5;
  571. /*
  572. * DM365: start address is 27-bit long address b26 - b23 are
  573. * in offset register b12 - b9, and * bit 26 has to be '1'
  574. */
  575. if (win->lconfig.pixfmt == PIXFMT_NV12) {
  576. switch (layer) {
  577. case WIN_VID0:
  578. case WIN_VID1:
  579. /* Y is in VID0 */
  580. osd_modify(sd, OSD_VIDWIN0OFST_V0AH,
  581. ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
  582. (OSD_SRCADD_OFSET_SFT -
  583. OSD_WINOFST_AH_SHIFT)) |
  584. OSD_WINOFST_MASK, OSD_VIDWIN0OFST);
  585. osd_modify(sd, OSD_VIDWINADH_V0AH,
  586. (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
  587. (OSD_SRCADD_ADD_SFT -
  588. OSD_VIDWINADH_V0AH_SHIFT),
  589. OSD_VIDWINADH);
  590. osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
  591. OSD_VIDWIN0ADL);
  592. /* CbCr is in VID1 */
  593. osd_modify(sd, OSD_VIDWIN1OFST_V1AH,
  594. ((cbcr_offset_32 &
  595. OSD_SRC_ADDR_HIGH4) >>
  596. (OSD_SRCADD_OFSET_SFT -
  597. OSD_WINOFST_AH_SHIFT)) |
  598. OSD_WINOFST_MASK, OSD_VIDWIN1OFST);
  599. osd_modify(sd, OSD_VIDWINADH_V1AH,
  600. (cbcr_offset_32 &
  601. OSD_SRC_ADDR_HIGH7) >>
  602. (OSD_SRCADD_ADD_SFT -
  603. OSD_VIDWINADH_V1AH_SHIFT),
  604. OSD_VIDWINADH);
  605. osd_write(sd, cbcr_offset_32 & OSD_WINADL_MASK,
  606. OSD_VIDWIN1ADL);
  607. break;
  608. default:
  609. break;
  610. }
  611. }
  612. switch (layer) {
  613. case WIN_OSD0:
  614. osd_modify(sd, OSD_OSDWIN0OFST_O0AH,
  615. ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
  616. (OSD_SRCADD_OFSET_SFT -
  617. OSD_WINOFST_AH_SHIFT)) | OSD_WINOFST_MASK,
  618. OSD_OSDWIN0OFST);
  619. osd_modify(sd, OSD_OSDWINADH_O0AH,
  620. (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
  621. (OSD_SRCADD_ADD_SFT -
  622. OSD_OSDWINADH_O0AH_SHIFT), OSD_OSDWINADH);
  623. osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
  624. OSD_OSDWIN0ADL);
  625. break;
  626. case WIN_VID0:
  627. if (win->lconfig.pixfmt != PIXFMT_NV12) {
  628. osd_modify(sd, OSD_VIDWIN0OFST_V0AH,
  629. ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
  630. (OSD_SRCADD_OFSET_SFT -
  631. OSD_WINOFST_AH_SHIFT)) |
  632. OSD_WINOFST_MASK, OSD_VIDWIN0OFST);
  633. osd_modify(sd, OSD_VIDWINADH_V0AH,
  634. (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
  635. (OSD_SRCADD_ADD_SFT -
  636. OSD_VIDWINADH_V0AH_SHIFT),
  637. OSD_VIDWINADH);
  638. osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
  639. OSD_VIDWIN0ADL);
  640. }
  641. break;
  642. case WIN_OSD1:
  643. osd_modify(sd, OSD_OSDWIN1OFST_O1AH,
  644. ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
  645. (OSD_SRCADD_OFSET_SFT -
  646. OSD_WINOFST_AH_SHIFT)) | OSD_WINOFST_MASK,
  647. OSD_OSDWIN1OFST);
  648. osd_modify(sd, OSD_OSDWINADH_O1AH,
  649. (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
  650. (OSD_SRCADD_ADD_SFT -
  651. OSD_OSDWINADH_O1AH_SHIFT),
  652. OSD_OSDWINADH);
  653. osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
  654. OSD_OSDWIN1ADL);
  655. break;
  656. case WIN_VID1:
  657. if (win->lconfig.pixfmt != PIXFMT_NV12) {
  658. osd_modify(sd, OSD_VIDWIN1OFST_V1AH,
  659. ((fb_offset_32 & OSD_SRC_ADDR_HIGH4) >>
  660. (OSD_SRCADD_OFSET_SFT -
  661. OSD_WINOFST_AH_SHIFT)) |
  662. OSD_WINOFST_MASK, OSD_VIDWIN1OFST);
  663. osd_modify(sd, OSD_VIDWINADH_V1AH,
  664. (fb_offset_32 & OSD_SRC_ADDR_HIGH7) >>
  665. (OSD_SRCADD_ADD_SFT -
  666. OSD_VIDWINADH_V1AH_SHIFT),
  667. OSD_VIDWINADH);
  668. osd_write(sd, fb_offset_32 & OSD_WINADL_MASK,
  669. OSD_VIDWIN1ADL);
  670. }
  671. break;
  672. }
  673. }
  674. }
  675. static void osd_start_layer(struct osd_state *sd, enum osd_layer layer,
  676. unsigned long fb_base_phys,
  677. unsigned long cbcr_ofst)
  678. {
  679. struct osd_state *osd = sd;
  680. struct osd_window_state *win = &osd->win[layer];
  681. struct osd_layer_config *cfg = &win->lconfig;
  682. unsigned long flags;
  683. spin_lock_irqsave(&osd->lock, flags);
  684. win->fb_base_phys = fb_base_phys & ~0x1F;
  685. _osd_start_layer(sd, layer, fb_base_phys, cbcr_ofst);
  686. if (layer == WIN_VID0) {
  687. osd->pingpong =
  688. _osd_dm6446_vid0_pingpong(sd, osd->field_inversion,
  689. win->fb_base_phys,
  690. cfg);
  691. }
  692. spin_unlock_irqrestore(&osd->lock, flags);
  693. }
  694. static void osd_get_layer_config(struct osd_state *sd, enum osd_layer layer,
  695. struct osd_layer_config *lconfig)
  696. {
  697. struct osd_state *osd = sd;
  698. struct osd_window_state *win = &osd->win[layer];
  699. unsigned long flags;
  700. spin_lock_irqsave(&osd->lock, flags);
  701. *lconfig = win->lconfig;
  702. spin_unlock_irqrestore(&osd->lock, flags);
  703. }
  704. /**
  705. * try_layer_config() - Try a specific configuration for the layer
  706. * @sd - ptr to struct osd_state
  707. * @layer - layer to configure
  708. * @lconfig - layer configuration to try
  709. *
  710. * If the requested lconfig is completely rejected and the value of lconfig on
  711. * exit is the current lconfig, then try_layer_config() returns 1. Otherwise,
  712. * try_layer_config() returns 0. A return value of 0 does not necessarily mean
  713. * that the value of lconfig on exit is identical to the value of lconfig on
  714. * entry, but merely that it represents a change from the current lconfig.
  715. */
  716. static int try_layer_config(struct osd_state *sd, enum osd_layer layer,
  717. struct osd_layer_config *lconfig)
  718. {
  719. struct osd_state *osd = sd;
  720. struct osd_window_state *win = &osd->win[layer];
  721. int bad_config = 0;
  722. /* verify that the pixel format is compatible with the layer */
  723. switch (lconfig->pixfmt) {
  724. case PIXFMT_1BPP:
  725. case PIXFMT_2BPP:
  726. case PIXFMT_4BPP:
  727. case PIXFMT_8BPP:
  728. case PIXFMT_RGB565:
  729. if (osd->vpbe_type == VPBE_VERSION_1)
  730. bad_config = !is_vid_win(layer);
  731. break;
  732. case PIXFMT_YCBCRI:
  733. case PIXFMT_YCRCBI:
  734. bad_config = !is_vid_win(layer);
  735. break;
  736. case PIXFMT_RGB888:
  737. if (osd->vpbe_type == VPBE_VERSION_1)
  738. bad_config = !is_vid_win(layer);
  739. else if ((osd->vpbe_type == VPBE_VERSION_3) ||
  740. (osd->vpbe_type == VPBE_VERSION_2))
  741. bad_config = !is_osd_win(layer);
  742. break;
  743. case PIXFMT_NV12:
  744. if (osd->vpbe_type != VPBE_VERSION_2)
  745. bad_config = 1;
  746. else
  747. bad_config = is_osd_win(layer);
  748. break;
  749. case PIXFMT_OSD_ATTR:
  750. bad_config = (layer != WIN_OSD1);
  751. break;
  752. default:
  753. bad_config = 1;
  754. break;
  755. }
  756. if (bad_config) {
  757. /*
  758. * The requested pixel format is incompatible with the layer,
  759. * so keep the current layer configuration.
  760. */
  761. *lconfig = win->lconfig;
  762. return bad_config;
  763. }
  764. /* DM6446: */
  765. /* only one OSD window at a time can use RGB pixel formats */
  766. if ((osd->vpbe_type == VPBE_VERSION_1) &&
  767. is_osd_win(layer) && is_rgb_pixfmt(lconfig->pixfmt)) {
  768. enum osd_pix_format pixfmt;
  769. if (layer == WIN_OSD0)
  770. pixfmt = osd->win[WIN_OSD1].lconfig.pixfmt;
  771. else
  772. pixfmt = osd->win[WIN_OSD0].lconfig.pixfmt;
  773. if (is_rgb_pixfmt(pixfmt)) {
  774. /*
  775. * The other OSD window is already configured for an
  776. * RGB, so keep the current layer configuration.
  777. */
  778. *lconfig = win->lconfig;
  779. return 1;
  780. }
  781. }
  782. /* DM6446: only one video window at a time can use RGB888 */
  783. if ((osd->vpbe_type == VPBE_VERSION_1) && is_vid_win(layer) &&
  784. lconfig->pixfmt == PIXFMT_RGB888) {
  785. enum osd_pix_format pixfmt;
  786. if (layer == WIN_VID0)
  787. pixfmt = osd->win[WIN_VID1].lconfig.pixfmt;
  788. else
  789. pixfmt = osd->win[WIN_VID0].lconfig.pixfmt;
  790. if (pixfmt == PIXFMT_RGB888) {
  791. /*
  792. * The other video window is already configured for
  793. * RGB888, so keep the current layer configuration.
  794. */
  795. *lconfig = win->lconfig;
  796. return 1;
  797. }
  798. }
  799. /* window dimensions must be non-zero */
  800. if (!lconfig->line_length || !lconfig->xsize || !lconfig->ysize) {
  801. *lconfig = win->lconfig;
  802. return 1;
  803. }
  804. /* round line_length up to a multiple of 32 */
  805. lconfig->line_length = ((lconfig->line_length + 31) / 32) * 32;
  806. lconfig->line_length =
  807. min(lconfig->line_length, (unsigned)MAX_LINE_LENGTH);
  808. lconfig->xsize = min(lconfig->xsize, (unsigned)MAX_WIN_SIZE);
  809. lconfig->ysize = min(lconfig->ysize, (unsigned)MAX_WIN_SIZE);
  810. lconfig->xpos = min(lconfig->xpos, (unsigned)MAX_WIN_SIZE);
  811. lconfig->ypos = min(lconfig->ypos, (unsigned)MAX_WIN_SIZE);
  812. lconfig->interlaced = (lconfig->interlaced != 0);
  813. if (lconfig->interlaced) {
  814. /* ysize and ypos must be even for interlaced displays */
  815. lconfig->ysize &= ~1;
  816. lconfig->ypos &= ~1;
  817. }
  818. return 0;
  819. }
  820. static void _osd_disable_vid_rgb888(struct osd_state *sd)
  821. {
  822. /*
  823. * The DM6446 supports RGB888 pixel format in a single video window.
  824. * This routine disables RGB888 pixel format for both video windows.
  825. * The caller must ensure that neither video window is currently
  826. * configured for RGB888 pixel format.
  827. */
  828. if (sd->vpbe_type == VPBE_VERSION_1)
  829. osd_clear(sd, OSD_MISCCTL_RGBEN, OSD_MISCCTL);
  830. }
  831. static void _osd_enable_vid_rgb888(struct osd_state *sd,
  832. enum osd_layer layer)
  833. {
  834. /*
  835. * The DM6446 supports RGB888 pixel format in a single video window.
  836. * This routine enables RGB888 pixel format for the specified video
  837. * window. The caller must ensure that the other video window is not
  838. * currently configured for RGB888 pixel format, as this routine will
  839. * disable RGB888 pixel format for the other window.
  840. */
  841. if (sd->vpbe_type == VPBE_VERSION_1) {
  842. if (layer == WIN_VID0)
  843. osd_modify(sd, OSD_MISCCTL_RGBEN | OSD_MISCCTL_RGBWIN,
  844. OSD_MISCCTL_RGBEN, OSD_MISCCTL);
  845. else if (layer == WIN_VID1)
  846. osd_modify(sd, OSD_MISCCTL_RGBEN | OSD_MISCCTL_RGBWIN,
  847. OSD_MISCCTL_RGBEN | OSD_MISCCTL_RGBWIN,
  848. OSD_MISCCTL);
  849. }
  850. }
  851. static void _osd_set_cbcr_order(struct osd_state *sd,
  852. enum osd_pix_format pixfmt)
  853. {
  854. /*
  855. * The caller must ensure that all windows using YC pixfmt use the same
  856. * Cb/Cr order.
  857. */
  858. if (pixfmt == PIXFMT_YCBCRI)
  859. osd_clear(sd, OSD_MODE_CS, OSD_MODE);
  860. else if (pixfmt == PIXFMT_YCRCBI)
  861. osd_set(sd, OSD_MODE_CS, OSD_MODE);
  862. }
  863. static void _osd_set_layer_config(struct osd_state *sd, enum osd_layer layer,
  864. const struct osd_layer_config *lconfig)
  865. {
  866. u32 winmd = 0, winmd_mask = 0, bmw = 0;
  867. _osd_set_cbcr_order(sd, lconfig->pixfmt);
  868. switch (layer) {
  869. case WIN_OSD0:
  870. if (sd->vpbe_type == VPBE_VERSION_1) {
  871. winmd_mask |= OSD_OSDWIN0MD_RGB0E;
  872. if (lconfig->pixfmt == PIXFMT_RGB565)
  873. winmd |= OSD_OSDWIN0MD_RGB0E;
  874. } else if ((sd->vpbe_type == VPBE_VERSION_3) ||
  875. (sd->vpbe_type == VPBE_VERSION_2)) {
  876. winmd_mask |= OSD_OSDWIN0MD_BMP0MD;
  877. switch (lconfig->pixfmt) {
  878. case PIXFMT_RGB565:
  879. winmd |= (1 <<
  880. OSD_OSDWIN0MD_BMP0MD_SHIFT);
  881. break;
  882. case PIXFMT_RGB888:
  883. winmd |= (2 << OSD_OSDWIN0MD_BMP0MD_SHIFT);
  884. _osd_enable_rgb888_pixblend(sd, OSDWIN_OSD0);
  885. break;
  886. case PIXFMT_YCBCRI:
  887. case PIXFMT_YCRCBI:
  888. winmd |= (3 << OSD_OSDWIN0MD_BMP0MD_SHIFT);
  889. break;
  890. default:
  891. break;
  892. }
  893. }
  894. winmd_mask |= OSD_OSDWIN0MD_BMW0 | OSD_OSDWIN0MD_OFF0;
  895. switch (lconfig->pixfmt) {
  896. case PIXFMT_1BPP:
  897. bmw = 0;
  898. break;
  899. case PIXFMT_2BPP:
  900. bmw = 1;
  901. break;
  902. case PIXFMT_4BPP:
  903. bmw = 2;
  904. break;
  905. case PIXFMT_8BPP:
  906. bmw = 3;
  907. break;
  908. default:
  909. break;
  910. }
  911. winmd |= (bmw << OSD_OSDWIN0MD_BMW0_SHIFT);
  912. if (lconfig->interlaced)
  913. winmd |= OSD_OSDWIN0MD_OFF0;
  914. osd_modify(sd, winmd_mask, winmd, OSD_OSDWIN0MD);
  915. osd_write(sd, lconfig->line_length >> 5, OSD_OSDWIN0OFST);
  916. osd_write(sd, lconfig->xpos, OSD_OSDWIN0XP);
  917. osd_write(sd, lconfig->xsize, OSD_OSDWIN0XL);
  918. if (lconfig->interlaced) {
  919. osd_write(sd, lconfig->ypos >> 1, OSD_OSDWIN0YP);
  920. osd_write(sd, lconfig->ysize >> 1, OSD_OSDWIN0YL);
  921. } else {
  922. osd_write(sd, lconfig->ypos, OSD_OSDWIN0YP);
  923. osd_write(sd, lconfig->ysize, OSD_OSDWIN0YL);
  924. }
  925. break;
  926. case WIN_VID0:
  927. winmd_mask |= OSD_VIDWINMD_VFF0;
  928. if (lconfig->interlaced)
  929. winmd |= OSD_VIDWINMD_VFF0;
  930. osd_modify(sd, winmd_mask, winmd, OSD_VIDWINMD);
  931. osd_write(sd, lconfig->line_length >> 5, OSD_VIDWIN0OFST);
  932. osd_write(sd, lconfig->xpos, OSD_VIDWIN0XP);
  933. osd_write(sd, lconfig->xsize, OSD_VIDWIN0XL);
  934. /*
  935. * For YUV420P format the register contents are
  936. * duplicated in both VID registers
  937. */
  938. if ((sd->vpbe_type == VPBE_VERSION_2) &&
  939. (lconfig->pixfmt == PIXFMT_NV12)) {
  940. /* other window also */
  941. if (lconfig->interlaced) {
  942. winmd_mask |= OSD_VIDWINMD_VFF1;
  943. winmd |= OSD_VIDWINMD_VFF1;
  944. osd_modify(sd, winmd_mask, winmd,
  945. OSD_VIDWINMD);
  946. }
  947. osd_modify(sd, OSD_MISCCTL_S420D,
  948. OSD_MISCCTL_S420D, OSD_MISCCTL);
  949. osd_write(sd, lconfig->line_length >> 5,
  950. OSD_VIDWIN1OFST);
  951. osd_write(sd, lconfig->xpos, OSD_VIDWIN1XP);
  952. osd_write(sd, lconfig->xsize, OSD_VIDWIN1XL);
  953. /*
  954. * if NV21 pixfmt and line length not 32B
  955. * aligned (e.g. NTSC), Need to set window
  956. * X pixel size to be 32B aligned as well
  957. */
  958. if (lconfig->xsize % 32) {
  959. osd_write(sd,
  960. ((lconfig->xsize + 31) & ~31),
  961. OSD_VIDWIN1XL);
  962. osd_write(sd,
  963. ((lconfig->xsize + 31) & ~31),
  964. OSD_VIDWIN0XL);
  965. }
  966. } else if ((sd->vpbe_type == VPBE_VERSION_2) &&
  967. (lconfig->pixfmt != PIXFMT_NV12)) {
  968. osd_modify(sd, OSD_MISCCTL_S420D, ~OSD_MISCCTL_S420D,
  969. OSD_MISCCTL);
  970. }
  971. if (lconfig->interlaced) {
  972. osd_write(sd, lconfig->ypos >> 1, OSD_VIDWIN0YP);
  973. osd_write(sd, lconfig->ysize >> 1, OSD_VIDWIN0YL);
  974. if ((sd->vpbe_type == VPBE_VERSION_2) &&
  975. lconfig->pixfmt == PIXFMT_NV12) {
  976. osd_write(sd, lconfig->ypos >> 1,
  977. OSD_VIDWIN1YP);
  978. osd_write(sd, lconfig->ysize >> 1,
  979. OSD_VIDWIN1YL);
  980. }
  981. } else {
  982. osd_write(sd, lconfig->ypos, OSD_VIDWIN0YP);
  983. osd_write(sd, lconfig->ysize, OSD_VIDWIN0YL);
  984. if ((sd->vpbe_type == VPBE_VERSION_2) &&
  985. lconfig->pixfmt == PIXFMT_NV12) {
  986. osd_write(sd, lconfig->ypos, OSD_VIDWIN1YP);
  987. osd_write(sd, lconfig->ysize, OSD_VIDWIN1YL);
  988. }
  989. }
  990. break;
  991. case WIN_OSD1:
  992. /*
  993. * The caller must ensure that OSD1 is disabled prior to
  994. * switching from a normal mode to attribute mode or from
  995. * attribute mode to a normal mode.
  996. */
  997. if (lconfig->pixfmt == PIXFMT_OSD_ATTR) {
  998. if (sd->vpbe_type == VPBE_VERSION_1) {
  999. winmd_mask |= OSD_OSDWIN1MD_ATN1E |
  1000. OSD_OSDWIN1MD_RGB1E | OSD_OSDWIN1MD_CLUTS1 |
  1001. OSD_OSDWIN1MD_BLND1 | OSD_OSDWIN1MD_TE1;
  1002. } else {
  1003. winmd_mask |= OSD_OSDWIN1MD_BMP1MD |
  1004. OSD_OSDWIN1MD_CLUTS1 | OSD_OSDWIN1MD_BLND1 |
  1005. OSD_OSDWIN1MD_TE1;
  1006. }
  1007. } else {
  1008. if (sd->vpbe_type == VPBE_VERSION_1) {
  1009. winmd_mask |= OSD_OSDWIN1MD_RGB1E;
  1010. if (lconfig->pixfmt == PIXFMT_RGB565)
  1011. winmd |= OSD_OSDWIN1MD_RGB1E;
  1012. } else if ((sd->vpbe_type == VPBE_VERSION_3)
  1013. || (sd->vpbe_type == VPBE_VERSION_2)) {
  1014. winmd_mask |= OSD_OSDWIN1MD_BMP1MD;
  1015. switch (lconfig->pixfmt) {
  1016. case PIXFMT_RGB565:
  1017. winmd |=
  1018. (1 << OSD_OSDWIN1MD_BMP1MD_SHIFT);
  1019. break;
  1020. case PIXFMT_RGB888:
  1021. winmd |=
  1022. (2 << OSD_OSDWIN1MD_BMP1MD_SHIFT);
  1023. _osd_enable_rgb888_pixblend(sd,
  1024. OSDWIN_OSD1);
  1025. break;
  1026. case PIXFMT_YCBCRI:
  1027. case PIXFMT_YCRCBI:
  1028. winmd |=
  1029. (3 << OSD_OSDWIN1MD_BMP1MD_SHIFT);
  1030. break;
  1031. default:
  1032. break;
  1033. }
  1034. }
  1035. winmd_mask |= OSD_OSDWIN1MD_BMW1;
  1036. switch (lconfig->pixfmt) {
  1037. case PIXFMT_1BPP:
  1038. bmw = 0;
  1039. break;
  1040. case PIXFMT_2BPP:
  1041. bmw = 1;
  1042. break;
  1043. case PIXFMT_4BPP:
  1044. bmw = 2;
  1045. break;
  1046. case PIXFMT_8BPP:
  1047. bmw = 3;
  1048. break;
  1049. default:
  1050. break;
  1051. }
  1052. winmd |= (bmw << OSD_OSDWIN1MD_BMW1_SHIFT);
  1053. }
  1054. winmd_mask |= OSD_OSDWIN1MD_OFF1;
  1055. if (lconfig->interlaced)
  1056. winmd |= OSD_OSDWIN1MD_OFF1;
  1057. osd_modify(sd, winmd_mask, winmd, OSD_OSDWIN1MD);
  1058. osd_write(sd, lconfig->line_length >> 5, OSD_OSDWIN1OFST);
  1059. osd_write(sd, lconfig->xpos, OSD_OSDWIN1XP);
  1060. osd_write(sd, lconfig->xsize, OSD_OSDWIN1XL);
  1061. if (lconfig->interlaced) {
  1062. osd_write(sd, lconfig->ypos >> 1, OSD_OSDWIN1YP);
  1063. osd_write(sd, lconfig->ysize >> 1, OSD_OSDWIN1YL);
  1064. } else {
  1065. osd_write(sd, lconfig->ypos, OSD_OSDWIN1YP);
  1066. osd_write(sd, lconfig->ysize, OSD_OSDWIN1YL);
  1067. }
  1068. break;
  1069. case WIN_VID1:
  1070. winmd_mask |= OSD_VIDWINMD_VFF1;
  1071. if (lconfig->interlaced)
  1072. winmd |= OSD_VIDWINMD_VFF1;
  1073. osd_modify(sd, winmd_mask, winmd, OSD_VIDWINMD);
  1074. osd_write(sd, lconfig->line_length >> 5, OSD_VIDWIN1OFST);
  1075. osd_write(sd, lconfig->xpos, OSD_VIDWIN1XP);
  1076. osd_write(sd, lconfig->xsize, OSD_VIDWIN1XL);
  1077. /*
  1078. * For YUV420P format the register contents are
  1079. * duplicated in both VID registers
  1080. */
  1081. if (sd->vpbe_type == VPBE_VERSION_2) {
  1082. if (lconfig->pixfmt == PIXFMT_NV12) {
  1083. /* other window also */
  1084. if (lconfig->interlaced) {
  1085. winmd_mask |= OSD_VIDWINMD_VFF0;
  1086. winmd |= OSD_VIDWINMD_VFF0;
  1087. osd_modify(sd, winmd_mask, winmd,
  1088. OSD_VIDWINMD);
  1089. }
  1090. osd_modify(sd, OSD_MISCCTL_S420D,
  1091. OSD_MISCCTL_S420D, OSD_MISCCTL);
  1092. osd_write(sd, lconfig->line_length >> 5,
  1093. OSD_VIDWIN0OFST);
  1094. osd_write(sd, lconfig->xpos, OSD_VIDWIN0XP);
  1095. osd_write(sd, lconfig->xsize, OSD_VIDWIN0XL);
  1096. } else {
  1097. osd_modify(sd, OSD_MISCCTL_S420D,
  1098. ~OSD_MISCCTL_S420D, OSD_MISCCTL);
  1099. }
  1100. }
  1101. if (lconfig->interlaced) {
  1102. osd_write(sd, lconfig->ypos >> 1, OSD_VIDWIN1YP);
  1103. osd_write(sd, lconfig->ysize >> 1, OSD_VIDWIN1YL);
  1104. if ((sd->vpbe_type == VPBE_VERSION_2) &&
  1105. lconfig->pixfmt == PIXFMT_NV12) {
  1106. osd_write(sd, lconfig->ypos >> 1,
  1107. OSD_VIDWIN0YP);
  1108. osd_write(sd, lconfig->ysize >> 1,
  1109. OSD_VIDWIN0YL);
  1110. }
  1111. } else {
  1112. osd_write(sd, lconfig->ypos, OSD_VIDWIN1YP);
  1113. osd_write(sd, lconfig->ysize, OSD_VIDWIN1YL);
  1114. if ((sd->vpbe_type == VPBE_VERSION_2) &&
  1115. lconfig->pixfmt == PIXFMT_NV12) {
  1116. osd_write(sd, lconfig->ypos, OSD_VIDWIN0YP);
  1117. osd_write(sd, lconfig->ysize, OSD_VIDWIN0YL);
  1118. }
  1119. }
  1120. break;
  1121. }
  1122. }
  1123. static int osd_set_layer_config(struct osd_state *sd, enum osd_layer layer,
  1124. struct osd_layer_config *lconfig)
  1125. {
  1126. struct osd_state *osd = sd;
  1127. struct osd_window_state *win = &osd->win[layer];
  1128. struct osd_layer_config *cfg = &win->lconfig;
  1129. unsigned long flags;
  1130. int reject_config;
  1131. spin_lock_irqsave(&osd->lock, flags);
  1132. reject_config = try_layer_config(sd, layer, lconfig);
  1133. if (reject_config) {
  1134. spin_unlock_irqrestore(&osd->lock, flags);
  1135. return reject_config;
  1136. }
  1137. /* update the current Cb/Cr order */
  1138. if (is_yc_pixfmt(lconfig->pixfmt))
  1139. osd->yc_pixfmt = lconfig->pixfmt;
  1140. /*
  1141. * If we are switching OSD1 from normal mode to attribute mode or from
  1142. * attribute mode to normal mode, then we must disable the window.
  1143. */
  1144. if (layer == WIN_OSD1) {
  1145. if (((lconfig->pixfmt == PIXFMT_OSD_ATTR) &&
  1146. (cfg->pixfmt != PIXFMT_OSD_ATTR)) ||
  1147. ((lconfig->pixfmt != PIXFMT_OSD_ATTR) &&
  1148. (cfg->pixfmt == PIXFMT_OSD_ATTR))) {
  1149. win->is_enabled = 0;
  1150. _osd_disable_layer(sd, layer);
  1151. }
  1152. }
  1153. _osd_set_layer_config(sd, layer, lconfig);
  1154. if (layer == WIN_OSD1) {
  1155. struct osd_osdwin_state *osdwin_state =
  1156. &osd->osdwin[OSDWIN_OSD1];
  1157. if ((lconfig->pixfmt != PIXFMT_OSD_ATTR) &&
  1158. (cfg->pixfmt == PIXFMT_OSD_ATTR)) {
  1159. /*
  1160. * We just switched OSD1 from attribute mode to normal
  1161. * mode, so we must initialize the CLUT select, the
  1162. * blend factor, transparency colorkey enable, and
  1163. * attenuation enable (DM6446 only) bits in the
  1164. * OSDWIN1MD register.
  1165. */
  1166. _osd_set_osd_clut(sd, OSDWIN_OSD1,
  1167. osdwin_state->clut);
  1168. _osd_set_blending_factor(sd, OSDWIN_OSD1,
  1169. osdwin_state->blend);
  1170. if (osdwin_state->colorkey_blending) {
  1171. _osd_enable_color_key(sd, OSDWIN_OSD1,
  1172. osdwin_state->
  1173. colorkey,
  1174. lconfig->pixfmt);
  1175. } else
  1176. _osd_disable_color_key(sd, OSDWIN_OSD1);
  1177. _osd_set_rec601_attenuation(sd, OSDWIN_OSD1,
  1178. osdwin_state->
  1179. rec601_attenuation);
  1180. } else if ((lconfig->pixfmt == PIXFMT_OSD_ATTR) &&
  1181. (cfg->pixfmt != PIXFMT_OSD_ATTR)) {
  1182. /*
  1183. * We just switched OSD1 from normal mode to attribute
  1184. * mode, so we must initialize the blink enable and
  1185. * blink interval bits in the OSDATRMD register.
  1186. */
  1187. _osd_set_blink_attribute(sd, osd->is_blinking,
  1188. osd->blink);
  1189. }
  1190. }
  1191. /*
  1192. * If we just switched to a 1-, 2-, or 4-bits-per-pixel bitmap format
  1193. * then configure a default palette map.
  1194. */
  1195. if ((lconfig->pixfmt != cfg->pixfmt) &&
  1196. ((lconfig->pixfmt == PIXFMT_1BPP) ||
  1197. (lconfig->pixfmt == PIXFMT_2BPP) ||
  1198. (lconfig->pixfmt == PIXFMT_4BPP))) {
  1199. enum osd_win_layer osdwin =
  1200. ((layer == WIN_OSD0) ? OSDWIN_OSD0 : OSDWIN_OSD1);
  1201. struct osd_osdwin_state *osdwin_state =
  1202. &osd->osdwin[osdwin];
  1203. unsigned char clut_index;
  1204. unsigned char clut_entries = 0;
  1205. switch (lconfig->pixfmt) {
  1206. case PIXFMT_1BPP:
  1207. clut_entries = 2;
  1208. break;
  1209. case PIXFMT_2BPP:
  1210. clut_entries = 4;
  1211. break;
  1212. case PIXFMT_4BPP:
  1213. clut_entries = 16;
  1214. break;
  1215. default:
  1216. break;
  1217. }
  1218. /*
  1219. * The default palette map maps the pixel value to the clut
  1220. * index, i.e. pixel value 0 maps to clut entry 0, pixel value
  1221. * 1 maps to clut entry 1, etc.
  1222. */
  1223. for (clut_index = 0; clut_index < 16; clut_index++) {
  1224. osdwin_state->palette_map[clut_index] = clut_index;
  1225. if (clut_index < clut_entries) {
  1226. _osd_set_palette_map(sd, osdwin, clut_index,
  1227. clut_index,
  1228. lconfig->pixfmt);
  1229. }
  1230. }
  1231. }
  1232. *cfg = *lconfig;
  1233. /* DM6446: configure the RGB888 enable and window selection */
  1234. if (osd->win[WIN_VID0].lconfig.pixfmt == PIXFMT_RGB888)
  1235. _osd_enable_vid_rgb888(sd, WIN_VID0);
  1236. else if (osd->win[WIN_VID1].lconfig.pixfmt == PIXFMT_RGB888)
  1237. _osd_enable_vid_rgb888(sd, WIN_VID1);
  1238. else
  1239. _osd_disable_vid_rgb888(sd);
  1240. if (layer == WIN_VID0) {
  1241. osd->pingpong =
  1242. _osd_dm6446_vid0_pingpong(sd, osd->field_inversion,
  1243. win->fb_base_phys,
  1244. cfg);
  1245. }
  1246. spin_unlock_irqrestore(&osd->lock, flags);
  1247. return 0;
  1248. }
  1249. static void osd_init_layer(struct osd_state *sd, enum osd_layer layer)
  1250. {
  1251. struct osd_state *osd = sd;
  1252. struct osd_window_state *win = &osd->win[layer];
  1253. enum osd_win_layer osdwin;
  1254. struct osd_osdwin_state *osdwin_state;
  1255. struct osd_layer_config *cfg = &win->lconfig;
  1256. unsigned long flags;
  1257. spin_lock_irqsave(&osd->lock, flags);
  1258. win->is_enabled = 0;
  1259. _osd_disable_layer(sd, layer);
  1260. win->h_zoom = ZOOM_X1;
  1261. win->v_zoom = ZOOM_X1;
  1262. _osd_set_zoom(sd, layer, win->h_zoom, win->v_zoom);
  1263. win->fb_base_phys = 0;
  1264. _osd_start_layer(sd, layer, win->fb_base_phys, 0);
  1265. cfg->line_length = 0;
  1266. cfg->xsize = 0;
  1267. cfg->ysize = 0;
  1268. cfg->xpos = 0;
  1269. cfg->ypos = 0;
  1270. cfg->interlaced = 0;
  1271. switch (layer) {
  1272. case WIN_OSD0:
  1273. case WIN_OSD1:
  1274. osdwin = (layer == WIN_OSD0) ? OSDWIN_OSD0 : OSDWIN_OSD1;
  1275. osdwin_state = &osd->osdwin[osdwin];
  1276. /*
  1277. * Other code relies on the fact that OSD windows default to a
  1278. * bitmap pixel format when they are deallocated, so don't
  1279. * change this default pixel format.
  1280. */
  1281. cfg->pixfmt = PIXFMT_8BPP;
  1282. _osd_set_layer_config(sd, layer, cfg);
  1283. osdwin_state->clut = RAM_CLUT;
  1284. _osd_set_osd_clut(sd, osdwin, osdwin_state->clut);
  1285. osdwin_state->colorkey_blending = 0;
  1286. _osd_disable_color_key(sd, osdwin);
  1287. osdwin_state->blend = OSD_8_VID_0;
  1288. _osd_set_blending_factor(sd, osdwin, osdwin_state->blend);
  1289. osdwin_state->rec601_attenuation = 0;
  1290. _osd_set_rec601_attenuation(sd, osdwin,
  1291. osdwin_state->
  1292. rec601_attenuation);
  1293. if (osdwin == OSDWIN_OSD1) {
  1294. osd->is_blinking = 0;
  1295. osd->blink = BLINK_X1;
  1296. }
  1297. break;
  1298. case WIN_VID0:
  1299. case WIN_VID1:
  1300. cfg->pixfmt = osd->yc_pixfmt;
  1301. _osd_set_layer_config(sd, layer, cfg);
  1302. break;
  1303. }
  1304. spin_unlock_irqrestore(&osd->lock, flags);
  1305. }
  1306. static void osd_release_layer(struct osd_state *sd, enum osd_layer layer)
  1307. {
  1308. struct osd_state *osd = sd;
  1309. struct osd_window_state *win = &osd->win[layer];
  1310. unsigned long flags;
  1311. spin_lock_irqsave(&osd->lock, flags);
  1312. if (!win->is_allocated) {
  1313. spin_unlock_irqrestore(&osd->lock, flags);
  1314. return;
  1315. }
  1316. spin_unlock_irqrestore(&osd->lock, flags);
  1317. osd_init_layer(sd, layer);
  1318. spin_lock_irqsave(&osd->lock, flags);
  1319. win->is_allocated = 0;
  1320. spin_unlock_irqrestore(&osd->lock, flags);
  1321. }
  1322. static int osd_request_layer(struct osd_state *sd, enum osd_layer layer)
  1323. {
  1324. struct osd_state *osd = sd;
  1325. struct osd_window_state *win = &osd->win[layer];
  1326. unsigned long flags;
  1327. spin_lock_irqsave(&osd->lock, flags);
  1328. if (win->is_allocated) {
  1329. spin_unlock_irqrestore(&osd->lock, flags);
  1330. return -1;
  1331. }
  1332. win->is_allocated = 1;
  1333. spin_unlock_irqrestore(&osd->lock, flags);
  1334. return 0;
  1335. }
  1336. static void _osd_init(struct osd_state *sd)
  1337. {
  1338. osd_write(sd, 0, OSD_MODE);
  1339. osd_write(sd, 0, OSD_VIDWINMD);
  1340. osd_write(sd, 0, OSD_OSDWIN0MD);
  1341. osd_write(sd, 0, OSD_OSDWIN1MD);
  1342. osd_write(sd, 0, OSD_RECTCUR);
  1343. osd_write(sd, 0, OSD_MISCCTL);
  1344. if (sd->vpbe_type == VPBE_VERSION_3) {
  1345. osd_write(sd, 0, OSD_VBNDRY);
  1346. osd_write(sd, 0, OSD_EXTMODE);
  1347. osd_write(sd, OSD_MISCCTL_DMANG, OSD_MISCCTL);
  1348. }
  1349. }
  1350. static void osd_set_left_margin(struct osd_state *sd, u32 val)
  1351. {
  1352. osd_write(sd, val, OSD_BASEPX);
  1353. }
  1354. static void osd_set_top_margin(struct osd_state *sd, u32 val)
  1355. {
  1356. osd_write(sd, val, OSD_BASEPY);
  1357. }
  1358. static int osd_initialize(struct osd_state *osd)
  1359. {
  1360. if (osd == NULL)
  1361. return -ENODEV;
  1362. _osd_init(osd);
  1363. /* set default Cb/Cr order */
  1364. osd->yc_pixfmt = PIXFMT_YCBCRI;
  1365. if (osd->vpbe_type == VPBE_VERSION_3) {
  1366. /*
  1367. * ROM CLUT1 on the DM355 is similar (identical?) to ROM CLUT0
  1368. * on the DM6446, so make ROM_CLUT1 the default on the DM355.
  1369. */
  1370. osd->rom_clut = ROM_CLUT1;
  1371. }
  1372. _osd_set_field_inversion(osd, osd->field_inversion);
  1373. _osd_set_rom_clut(osd, osd->rom_clut);
  1374. osd_init_layer(osd, WIN_OSD0);
  1375. osd_init_layer(osd, WIN_VID0);
  1376. osd_init_layer(osd, WIN_OSD1);
  1377. osd_init_layer(osd, WIN_VID1);
  1378. return 0;
  1379. }
  1380. static const struct vpbe_osd_ops osd_ops = {
  1381. .initialize = osd_initialize,
  1382. .request_layer = osd_request_layer,
  1383. .release_layer = osd_release_layer,
  1384. .enable_layer = osd_enable_layer,
  1385. .disable_layer = osd_disable_layer,
  1386. .set_layer_config = osd_set_layer_config,
  1387. .get_layer_config = osd_get_layer_config,
  1388. .start_layer = osd_start_layer,
  1389. .set_left_margin = osd_set_left_margin,
  1390. .set_top_margin = osd_set_top_margin,
  1391. };
  1392. static int osd_probe(struct platform_device *pdev)
  1393. {
  1394. const struct platform_device_id *pdev_id;
  1395. struct osd_state *osd;
  1396. struct resource *res;
  1397. pdev_id = platform_get_device_id(pdev);
  1398. if (!pdev_id)
  1399. return -EINVAL;
  1400. osd = devm_kzalloc(&pdev->dev, sizeof(struct osd_state), GFP_KERNEL);
  1401. if (osd == NULL)
  1402. return -ENOMEM;
  1403. osd->dev = &pdev->dev;
  1404. osd->vpbe_type = pdev_id->driver_data;
  1405. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1406. osd->osd_base = devm_ioremap_resource(&pdev->dev, res);
  1407. if (IS_ERR(osd->osd_base))
  1408. return PTR_ERR(osd->osd_base);
  1409. osd->osd_base_phys = res->start;
  1410. osd->osd_size = resource_size(res);
  1411. spin_lock_init(&osd->lock);
  1412. osd->ops = osd_ops;
  1413. platform_set_drvdata(pdev, osd);
  1414. dev_notice(osd->dev, "OSD sub device probe success\n");
  1415. return 0;
  1416. }
  1417. static int osd_remove(struct platform_device *pdev)
  1418. {
  1419. return 0;
  1420. }
  1421. static struct platform_driver osd_driver = {
  1422. .probe = osd_probe,
  1423. .remove = osd_remove,
  1424. .driver = {
  1425. .name = MODULE_NAME,
  1426. },
  1427. .id_table = vpbe_osd_devtype
  1428. };
  1429. module_platform_driver(osd_driver);
  1430. MODULE_LICENSE("GPL");
  1431. MODULE_DESCRIPTION("DaVinci OSD Manager Driver");
  1432. MODULE_AUTHOR("Texas Instruments");