sh_mobile_lcdcfb.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860
  1. /*
  2. * SuperH Mobile LCDC Framebuffer
  3. *
  4. * Copyright (c) 2008 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/atomic.h>
  11. #include <linux/backlight.h>
  12. #include <linux/clk.h>
  13. #include <linux/console.h>
  14. #include <linux/ctype.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/delay.h>
  17. #include <linux/gpio.h>
  18. #include <linux/init.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/ioctl.h>
  21. #include <linux/kernel.h>
  22. #include <linux/mm.h>
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/slab.h>
  27. #include <linux/videodev2.h>
  28. #include <linux/vmalloc.h>
  29. #include <video/sh_mobile_lcdc.h>
  30. #include <video/sh_mobile_meram.h>
  31. #include "sh_mobile_lcdcfb.h"
  32. /* ----------------------------------------------------------------------------
  33. * Overlay register definitions
  34. */
  35. #define LDBCR 0xb00
  36. #define LDBCR_UPC(n) (1 << ((n) + 16))
  37. #define LDBCR_UPF(n) (1 << ((n) + 8))
  38. #define LDBCR_UPD(n) (1 << ((n) + 0))
  39. #define LDBnBSIFR(n) (0xb20 + (n) * 0x20 + 0x00)
  40. #define LDBBSIFR_EN (1 << 31)
  41. #define LDBBSIFR_VS (1 << 29)
  42. #define LDBBSIFR_BRSEL (1 << 28)
  43. #define LDBBSIFR_MX (1 << 27)
  44. #define LDBBSIFR_MY (1 << 26)
  45. #define LDBBSIFR_CV3 (3 << 24)
  46. #define LDBBSIFR_CV2 (2 << 24)
  47. #define LDBBSIFR_CV1 (1 << 24)
  48. #define LDBBSIFR_CV0 (0 << 24)
  49. #define LDBBSIFR_CV_MASK (3 << 24)
  50. #define LDBBSIFR_LAY_MASK (0xff << 16)
  51. #define LDBBSIFR_LAY_SHIFT 16
  52. #define LDBBSIFR_ROP3_MASK (0xff << 16)
  53. #define LDBBSIFR_ROP3_SHIFT 16
  54. #define LDBBSIFR_AL_PL8 (3 << 14)
  55. #define LDBBSIFR_AL_PL1 (2 << 14)
  56. #define LDBBSIFR_AL_PK (1 << 14)
  57. #define LDBBSIFR_AL_1 (0 << 14)
  58. #define LDBBSIFR_AL_MASK (3 << 14)
  59. #define LDBBSIFR_SWPL (1 << 10)
  60. #define LDBBSIFR_SWPW (1 << 9)
  61. #define LDBBSIFR_SWPB (1 << 8)
  62. #define LDBBSIFR_RY (1 << 7)
  63. #define LDBBSIFR_CHRR_420 (2 << 0)
  64. #define LDBBSIFR_CHRR_422 (1 << 0)
  65. #define LDBBSIFR_CHRR_444 (0 << 0)
  66. #define LDBBSIFR_RPKF_ARGB32 (0x00 << 0)
  67. #define LDBBSIFR_RPKF_RGB16 (0x03 << 0)
  68. #define LDBBSIFR_RPKF_RGB24 (0x0b << 0)
  69. #define LDBBSIFR_RPKF_MASK (0x1f << 0)
  70. #define LDBnBSSZR(n) (0xb20 + (n) * 0x20 + 0x04)
  71. #define LDBBSSZR_BVSS_MASK (0xfff << 16)
  72. #define LDBBSSZR_BVSS_SHIFT 16
  73. #define LDBBSSZR_BHSS_MASK (0xfff << 0)
  74. #define LDBBSSZR_BHSS_SHIFT 0
  75. #define LDBnBLOCR(n) (0xb20 + (n) * 0x20 + 0x08)
  76. #define LDBBLOCR_CVLC_MASK (0xfff << 16)
  77. #define LDBBLOCR_CVLC_SHIFT 16
  78. #define LDBBLOCR_CHLC_MASK (0xfff << 0)
  79. #define LDBBLOCR_CHLC_SHIFT 0
  80. #define LDBnBSMWR(n) (0xb20 + (n) * 0x20 + 0x0c)
  81. #define LDBBSMWR_BSMWA_MASK (0xffff << 16)
  82. #define LDBBSMWR_BSMWA_SHIFT 16
  83. #define LDBBSMWR_BSMW_MASK (0xffff << 0)
  84. #define LDBBSMWR_BSMW_SHIFT 0
  85. #define LDBnBSAYR(n) (0xb20 + (n) * 0x20 + 0x10)
  86. #define LDBBSAYR_FG1A_MASK (0xff << 24)
  87. #define LDBBSAYR_FG1A_SHIFT 24
  88. #define LDBBSAYR_FG1R_MASK (0xff << 16)
  89. #define LDBBSAYR_FG1R_SHIFT 16
  90. #define LDBBSAYR_FG1G_MASK (0xff << 8)
  91. #define LDBBSAYR_FG1G_SHIFT 8
  92. #define LDBBSAYR_FG1B_MASK (0xff << 0)
  93. #define LDBBSAYR_FG1B_SHIFT 0
  94. #define LDBnBSACR(n) (0xb20 + (n) * 0x20 + 0x14)
  95. #define LDBBSACR_FG2A_MASK (0xff << 24)
  96. #define LDBBSACR_FG2A_SHIFT 24
  97. #define LDBBSACR_FG2R_MASK (0xff << 16)
  98. #define LDBBSACR_FG2R_SHIFT 16
  99. #define LDBBSACR_FG2G_MASK (0xff << 8)
  100. #define LDBBSACR_FG2G_SHIFT 8
  101. #define LDBBSACR_FG2B_MASK (0xff << 0)
  102. #define LDBBSACR_FG2B_SHIFT 0
  103. #define LDBnBSAAR(n) (0xb20 + (n) * 0x20 + 0x18)
  104. #define LDBBSAAR_AP_MASK (0xff << 24)
  105. #define LDBBSAAR_AP_SHIFT 24
  106. #define LDBBSAAR_R_MASK (0xff << 16)
  107. #define LDBBSAAR_R_SHIFT 16
  108. #define LDBBSAAR_GY_MASK (0xff << 8)
  109. #define LDBBSAAR_GY_SHIFT 8
  110. #define LDBBSAAR_B_MASK (0xff << 0)
  111. #define LDBBSAAR_B_SHIFT 0
  112. #define LDBnBPPCR(n) (0xb20 + (n) * 0x20 + 0x1c)
  113. #define LDBBPPCR_AP_MASK (0xff << 24)
  114. #define LDBBPPCR_AP_SHIFT 24
  115. #define LDBBPPCR_R_MASK (0xff << 16)
  116. #define LDBBPPCR_R_SHIFT 16
  117. #define LDBBPPCR_GY_MASK (0xff << 8)
  118. #define LDBBPPCR_GY_SHIFT 8
  119. #define LDBBPPCR_B_MASK (0xff << 0)
  120. #define LDBBPPCR_B_SHIFT 0
  121. #define LDBnBBGCL(n) (0xb10 + (n) * 0x04)
  122. #define LDBBBGCL_BGA_MASK (0xff << 24)
  123. #define LDBBBGCL_BGA_SHIFT 24
  124. #define LDBBBGCL_BGR_MASK (0xff << 16)
  125. #define LDBBBGCL_BGR_SHIFT 16
  126. #define LDBBBGCL_BGG_MASK (0xff << 8)
  127. #define LDBBBGCL_BGG_SHIFT 8
  128. #define LDBBBGCL_BGB_MASK (0xff << 0)
  129. #define LDBBBGCL_BGB_SHIFT 0
  130. #define SIDE_B_OFFSET 0x1000
  131. #define MIRROR_OFFSET 0x2000
  132. #define MAX_XRES 1920
  133. #define MAX_YRES 1080
  134. enum sh_mobile_lcdc_overlay_mode {
  135. LCDC_OVERLAY_BLEND,
  136. LCDC_OVERLAY_ROP3,
  137. };
  138. /*
  139. * struct sh_mobile_lcdc_overlay - LCDC display overlay
  140. *
  141. * @channel: LCDC channel this overlay belongs to
  142. * @cfg: Overlay configuration
  143. * @info: Frame buffer device
  144. * @index: Overlay index (0-3)
  145. * @base: Overlay registers base address
  146. * @enabled: True if the overlay is enabled
  147. * @mode: Overlay blending mode (alpha blend or ROP3)
  148. * @alpha: Global alpha blending value (0-255, for alpha blending mode)
  149. * @rop3: Raster operation (for ROP3 mode)
  150. * @fb_mem: Frame buffer virtual memory address
  151. * @fb_size: Frame buffer size in bytes
  152. * @dma_handle: Frame buffer DMA address
  153. * @base_addr_y: Overlay base address (RGB or luma component)
  154. * @base_addr_c: Overlay base address (chroma component)
  155. * @pan_y_offset: Panning linear offset in bytes (luma component)
  156. * @format: Current pixelf format
  157. * @xres: Horizontal visible resolution
  158. * @xres_virtual: Horizontal total resolution
  159. * @yres: Vertical visible resolution
  160. * @yres_virtual: Vertical total resolution
  161. * @pitch: Overlay line pitch
  162. * @pos_x: Horizontal overlay position
  163. * @pos_y: Vertical overlay position
  164. */
  165. struct sh_mobile_lcdc_overlay {
  166. struct sh_mobile_lcdc_chan *channel;
  167. const struct sh_mobile_lcdc_overlay_cfg *cfg;
  168. struct fb_info *info;
  169. unsigned int index;
  170. unsigned long base;
  171. bool enabled;
  172. enum sh_mobile_lcdc_overlay_mode mode;
  173. unsigned int alpha;
  174. unsigned int rop3;
  175. void *fb_mem;
  176. unsigned long fb_size;
  177. dma_addr_t dma_handle;
  178. unsigned long base_addr_y;
  179. unsigned long base_addr_c;
  180. unsigned long pan_y_offset;
  181. const struct sh_mobile_lcdc_format_info *format;
  182. unsigned int xres;
  183. unsigned int xres_virtual;
  184. unsigned int yres;
  185. unsigned int yres_virtual;
  186. unsigned int pitch;
  187. int pos_x;
  188. int pos_y;
  189. };
  190. struct sh_mobile_lcdc_priv {
  191. void __iomem *base;
  192. int irq;
  193. atomic_t hw_usecnt;
  194. struct device *dev;
  195. struct clk *dot_clk;
  196. unsigned long lddckr;
  197. struct sh_mobile_lcdc_chan ch[2];
  198. struct sh_mobile_lcdc_overlay overlays[4];
  199. struct notifier_block notifier;
  200. int started;
  201. int forced_fourcc; /* 2 channel LCDC must share fourcc setting */
  202. struct sh_mobile_meram_info *meram_dev;
  203. };
  204. /* -----------------------------------------------------------------------------
  205. * Registers access
  206. */
  207. static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
  208. [LDDCKPAT1R] = 0x400,
  209. [LDDCKPAT2R] = 0x404,
  210. [LDMT1R] = 0x418,
  211. [LDMT2R] = 0x41c,
  212. [LDMT3R] = 0x420,
  213. [LDDFR] = 0x424,
  214. [LDSM1R] = 0x428,
  215. [LDSM2R] = 0x42c,
  216. [LDSA1R] = 0x430,
  217. [LDSA2R] = 0x434,
  218. [LDMLSR] = 0x438,
  219. [LDHCNR] = 0x448,
  220. [LDHSYNR] = 0x44c,
  221. [LDVLNR] = 0x450,
  222. [LDVSYNR] = 0x454,
  223. [LDPMR] = 0x460,
  224. [LDHAJR] = 0x4a0,
  225. };
  226. static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
  227. [LDDCKPAT1R] = 0x408,
  228. [LDDCKPAT2R] = 0x40c,
  229. [LDMT1R] = 0x600,
  230. [LDMT2R] = 0x604,
  231. [LDMT3R] = 0x608,
  232. [LDDFR] = 0x60c,
  233. [LDSM1R] = 0x610,
  234. [LDSM2R] = 0x614,
  235. [LDSA1R] = 0x618,
  236. [LDMLSR] = 0x620,
  237. [LDHCNR] = 0x624,
  238. [LDHSYNR] = 0x628,
  239. [LDVLNR] = 0x62c,
  240. [LDVSYNR] = 0x630,
  241. [LDPMR] = 0x63c,
  242. };
  243. static bool banked(int reg_nr)
  244. {
  245. switch (reg_nr) {
  246. case LDMT1R:
  247. case LDMT2R:
  248. case LDMT3R:
  249. case LDDFR:
  250. case LDSM1R:
  251. case LDSA1R:
  252. case LDSA2R:
  253. case LDMLSR:
  254. case LDHCNR:
  255. case LDHSYNR:
  256. case LDVLNR:
  257. case LDVSYNR:
  258. return true;
  259. }
  260. return false;
  261. }
  262. static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
  263. {
  264. return chan->cfg->chan == LCDC_CHAN_SUBLCD;
  265. }
  266. static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
  267. int reg_nr, unsigned long data)
  268. {
  269. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
  270. if (banked(reg_nr))
  271. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
  272. SIDE_B_OFFSET);
  273. }
  274. static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
  275. int reg_nr, unsigned long data)
  276. {
  277. iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
  278. MIRROR_OFFSET);
  279. }
  280. static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
  281. int reg_nr)
  282. {
  283. return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
  284. }
  285. static void lcdc_write_overlay(struct sh_mobile_lcdc_overlay *ovl,
  286. int reg, unsigned long data)
  287. {
  288. iowrite32(data, ovl->channel->lcdc->base + reg);
  289. iowrite32(data, ovl->channel->lcdc->base + reg + SIDE_B_OFFSET);
  290. }
  291. static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
  292. unsigned long reg_offs, unsigned long data)
  293. {
  294. iowrite32(data, priv->base + reg_offs);
  295. }
  296. static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
  297. unsigned long reg_offs)
  298. {
  299. return ioread32(priv->base + reg_offs);
  300. }
  301. static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
  302. unsigned long reg_offs,
  303. unsigned long mask, unsigned long until)
  304. {
  305. while ((lcdc_read(priv, reg_offs) & mask) != until)
  306. cpu_relax();
  307. }
  308. /* -----------------------------------------------------------------------------
  309. * Clock management
  310. */
  311. static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
  312. {
  313. if (atomic_inc_and_test(&priv->hw_usecnt)) {
  314. if (priv->dot_clk)
  315. clk_enable(priv->dot_clk);
  316. pm_runtime_get_sync(priv->dev);
  317. if (priv->meram_dev && priv->meram_dev->pdev)
  318. pm_runtime_get_sync(&priv->meram_dev->pdev->dev);
  319. }
  320. }
  321. static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
  322. {
  323. if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
  324. if (priv->meram_dev && priv->meram_dev->pdev)
  325. pm_runtime_put_sync(&priv->meram_dev->pdev->dev);
  326. pm_runtime_put(priv->dev);
  327. if (priv->dot_clk)
  328. clk_disable(priv->dot_clk);
  329. }
  330. }
  331. static int sh_mobile_lcdc_setup_clocks(struct sh_mobile_lcdc_priv *priv,
  332. int clock_source)
  333. {
  334. struct clk *clk;
  335. char *str;
  336. switch (clock_source) {
  337. case LCDC_CLK_BUS:
  338. str = "bus_clk";
  339. priv->lddckr = LDDCKR_ICKSEL_BUS;
  340. break;
  341. case LCDC_CLK_PERIPHERAL:
  342. str = "peripheral_clk";
  343. priv->lddckr = LDDCKR_ICKSEL_MIPI;
  344. break;
  345. case LCDC_CLK_EXTERNAL:
  346. str = NULL;
  347. priv->lddckr = LDDCKR_ICKSEL_HDMI;
  348. break;
  349. default:
  350. return -EINVAL;
  351. }
  352. if (str == NULL)
  353. return 0;
  354. clk = clk_get(priv->dev, str);
  355. if (IS_ERR(clk)) {
  356. dev_err(priv->dev, "cannot get dot clock %s\n", str);
  357. return PTR_ERR(clk);
  358. }
  359. priv->dot_clk = clk;
  360. return 0;
  361. }
  362. /* -----------------------------------------------------------------------------
  363. * Display, panel and deferred I/O
  364. */
  365. static void lcdc_sys_write_index(void *handle, unsigned long data)
  366. {
  367. struct sh_mobile_lcdc_chan *ch = handle;
  368. lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT);
  369. lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
  370. lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
  371. (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  372. lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
  373. }
  374. static void lcdc_sys_write_data(void *handle, unsigned long data)
  375. {
  376. struct sh_mobile_lcdc_chan *ch = handle;
  377. lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW);
  378. lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
  379. lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
  380. (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  381. lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
  382. }
  383. static unsigned long lcdc_sys_read_data(void *handle)
  384. {
  385. struct sh_mobile_lcdc_chan *ch = handle;
  386. lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR);
  387. lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
  388. lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA |
  389. (lcdc_chan_is_sublcd(ch) ? 2 : 0));
  390. udelay(1);
  391. lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
  392. return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK;
  393. }
  394. static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
  395. lcdc_sys_write_index,
  396. lcdc_sys_write_data,
  397. lcdc_sys_read_data,
  398. };
  399. static int sh_mobile_lcdc_sginit(struct fb_info *info,
  400. struct list_head *pagelist)
  401. {
  402. struct sh_mobile_lcdc_chan *ch = info->par;
  403. unsigned int nr_pages_max = ch->fb_size >> PAGE_SHIFT;
  404. struct page *page;
  405. int nr_pages = 0;
  406. sg_init_table(ch->sglist, nr_pages_max);
  407. list_for_each_entry(page, pagelist, lru)
  408. sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
  409. return nr_pages;
  410. }
  411. static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
  412. struct list_head *pagelist)
  413. {
  414. struct sh_mobile_lcdc_chan *ch = info->par;
  415. const struct sh_mobile_lcdc_panel_cfg *panel = &ch->cfg->panel_cfg;
  416. /* enable clocks before accessing hardware */
  417. sh_mobile_lcdc_clk_on(ch->lcdc);
  418. /*
  419. * It's possible to get here without anything on the pagelist via
  420. * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
  421. * invocation. In the former case, the acceleration routines are
  422. * stepped in to when using the framebuffer console causing the
  423. * workqueue to be scheduled without any dirty pages on the list.
  424. *
  425. * Despite this, a panel update is still needed given that the
  426. * acceleration routines have their own methods for writing in
  427. * that still need to be updated.
  428. *
  429. * The fsync() and empty pagelist case could be optimized for,
  430. * but we don't bother, as any application exhibiting such
  431. * behaviour is fundamentally broken anyways.
  432. */
  433. if (!list_empty(pagelist)) {
  434. unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
  435. /* trigger panel update */
  436. dma_map_sg(ch->lcdc->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
  437. if (panel->start_transfer)
  438. panel->start_transfer(ch, &sh_mobile_lcdc_sys_bus_ops);
  439. lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
  440. dma_unmap_sg(ch->lcdc->dev, ch->sglist, nr_pages,
  441. DMA_TO_DEVICE);
  442. } else {
  443. if (panel->start_transfer)
  444. panel->start_transfer(ch, &sh_mobile_lcdc_sys_bus_ops);
  445. lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
  446. }
  447. }
  448. static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
  449. {
  450. struct fb_deferred_io *fbdefio = info->fbdefio;
  451. if (fbdefio)
  452. schedule_delayed_work(&info->deferred_work, fbdefio->delay);
  453. }
  454. static void sh_mobile_lcdc_display_on(struct sh_mobile_lcdc_chan *ch)
  455. {
  456. const struct sh_mobile_lcdc_panel_cfg *panel = &ch->cfg->panel_cfg;
  457. if (ch->tx_dev) {
  458. int ret;
  459. ret = ch->tx_dev->ops->display_on(ch->tx_dev);
  460. if (ret < 0)
  461. return;
  462. if (ret == SH_MOBILE_LCDC_DISPLAY_DISCONNECTED)
  463. ch->info->state = FBINFO_STATE_SUSPENDED;
  464. }
  465. /* HDMI must be enabled before LCDC configuration */
  466. if (panel->display_on)
  467. panel->display_on();
  468. }
  469. static void sh_mobile_lcdc_display_off(struct sh_mobile_lcdc_chan *ch)
  470. {
  471. const struct sh_mobile_lcdc_panel_cfg *panel = &ch->cfg->panel_cfg;
  472. if (panel->display_off)
  473. panel->display_off();
  474. if (ch->tx_dev)
  475. ch->tx_dev->ops->display_off(ch->tx_dev);
  476. }
  477. static bool
  478. sh_mobile_lcdc_must_reconfigure(struct sh_mobile_lcdc_chan *ch,
  479. const struct fb_videomode *new_mode)
  480. {
  481. dev_dbg(ch->info->dev, "Old %ux%u, new %ux%u\n",
  482. ch->display.mode.xres, ch->display.mode.yres,
  483. new_mode->xres, new_mode->yres);
  484. /* It can be a different monitor with an equal video-mode */
  485. if (fb_mode_is_equal(&ch->display.mode, new_mode))
  486. return false;
  487. dev_dbg(ch->info->dev, "Switching %u -> %u lines\n",
  488. ch->display.mode.yres, new_mode->yres);
  489. ch->display.mode = *new_mode;
  490. return true;
  491. }
  492. static int sh_mobile_lcdc_check_var(struct fb_var_screeninfo *var,
  493. struct fb_info *info);
  494. static int sh_mobile_lcdc_display_notify(struct sh_mobile_lcdc_chan *ch,
  495. enum sh_mobile_lcdc_entity_event event,
  496. const struct fb_videomode *mode,
  497. const struct fb_monspecs *monspec)
  498. {
  499. struct fb_info *info = ch->info;
  500. struct fb_var_screeninfo var;
  501. int ret = 0;
  502. switch (event) {
  503. case SH_MOBILE_LCDC_EVENT_DISPLAY_CONNECT:
  504. /* HDMI plug in */
  505. if (lock_fb_info(info)) {
  506. console_lock();
  507. ch->display.width = monspec->max_x * 10;
  508. ch->display.height = monspec->max_y * 10;
  509. if (!sh_mobile_lcdc_must_reconfigure(ch, mode) &&
  510. info->state == FBINFO_STATE_RUNNING) {
  511. /* First activation with the default monitor.
  512. * Just turn on, if we run a resume here, the
  513. * logo disappears.
  514. */
  515. info->var.width = ch->display.width;
  516. info->var.height = ch->display.height;
  517. sh_mobile_lcdc_display_on(ch);
  518. } else {
  519. /* New monitor or have to wake up */
  520. fb_set_suspend(info, 0);
  521. }
  522. console_unlock();
  523. unlock_fb_info(info);
  524. }
  525. break;
  526. case SH_MOBILE_LCDC_EVENT_DISPLAY_DISCONNECT:
  527. /* HDMI disconnect */
  528. if (lock_fb_info(info)) {
  529. console_lock();
  530. fb_set_suspend(info, 1);
  531. console_unlock();
  532. unlock_fb_info(info);
  533. }
  534. break;
  535. case SH_MOBILE_LCDC_EVENT_DISPLAY_MODE:
  536. /* Validate a proposed new mode */
  537. fb_videomode_to_var(&var, mode);
  538. var.bits_per_pixel = info->var.bits_per_pixel;
  539. var.grayscale = info->var.grayscale;
  540. ret = sh_mobile_lcdc_check_var(&var, info);
  541. break;
  542. }
  543. return ret;
  544. }
  545. /* -----------------------------------------------------------------------------
  546. * Format helpers
  547. */
  548. struct sh_mobile_lcdc_format_info {
  549. u32 fourcc;
  550. unsigned int bpp;
  551. bool yuv;
  552. u32 lddfr;
  553. };
  554. static const struct sh_mobile_lcdc_format_info sh_mobile_format_infos[] = {
  555. {
  556. .fourcc = V4L2_PIX_FMT_RGB565,
  557. .bpp = 16,
  558. .yuv = false,
  559. .lddfr = LDDFR_PKF_RGB16,
  560. }, {
  561. .fourcc = V4L2_PIX_FMT_BGR24,
  562. .bpp = 24,
  563. .yuv = false,
  564. .lddfr = LDDFR_PKF_RGB24,
  565. }, {
  566. .fourcc = V4L2_PIX_FMT_BGR32,
  567. .bpp = 32,
  568. .yuv = false,
  569. .lddfr = LDDFR_PKF_ARGB32,
  570. }, {
  571. .fourcc = V4L2_PIX_FMT_NV12,
  572. .bpp = 12,
  573. .yuv = true,
  574. .lddfr = LDDFR_CC | LDDFR_YF_420,
  575. }, {
  576. .fourcc = V4L2_PIX_FMT_NV21,
  577. .bpp = 12,
  578. .yuv = true,
  579. .lddfr = LDDFR_CC | LDDFR_YF_420,
  580. }, {
  581. .fourcc = V4L2_PIX_FMT_NV16,
  582. .bpp = 16,
  583. .yuv = true,
  584. .lddfr = LDDFR_CC | LDDFR_YF_422,
  585. }, {
  586. .fourcc = V4L2_PIX_FMT_NV61,
  587. .bpp = 16,
  588. .yuv = true,
  589. .lddfr = LDDFR_CC | LDDFR_YF_422,
  590. }, {
  591. .fourcc = V4L2_PIX_FMT_NV24,
  592. .bpp = 24,
  593. .yuv = true,
  594. .lddfr = LDDFR_CC | LDDFR_YF_444,
  595. }, {
  596. .fourcc = V4L2_PIX_FMT_NV42,
  597. .bpp = 24,
  598. .yuv = true,
  599. .lddfr = LDDFR_CC | LDDFR_YF_444,
  600. },
  601. };
  602. static const struct sh_mobile_lcdc_format_info *
  603. sh_mobile_format_info(u32 fourcc)
  604. {
  605. unsigned int i;
  606. for (i = 0; i < ARRAY_SIZE(sh_mobile_format_infos); ++i) {
  607. if (sh_mobile_format_infos[i].fourcc == fourcc)
  608. return &sh_mobile_format_infos[i];
  609. }
  610. return NULL;
  611. }
  612. static int sh_mobile_format_fourcc(const struct fb_var_screeninfo *var)
  613. {
  614. if (var->grayscale > 1)
  615. return var->grayscale;
  616. switch (var->bits_per_pixel) {
  617. case 16:
  618. return V4L2_PIX_FMT_RGB565;
  619. case 24:
  620. return V4L2_PIX_FMT_BGR24;
  621. case 32:
  622. return V4L2_PIX_FMT_BGR32;
  623. default:
  624. return 0;
  625. }
  626. }
  627. static int sh_mobile_format_is_fourcc(const struct fb_var_screeninfo *var)
  628. {
  629. return var->grayscale > 1;
  630. }
  631. /* -----------------------------------------------------------------------------
  632. * Start, stop and IRQ
  633. */
  634. static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
  635. {
  636. struct sh_mobile_lcdc_priv *priv = data;
  637. struct sh_mobile_lcdc_chan *ch;
  638. unsigned long ldintr;
  639. int is_sub;
  640. int k;
  641. /* Acknowledge interrupts and disable further VSYNC End IRQs. */
  642. ldintr = lcdc_read(priv, _LDINTR);
  643. lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE);
  644. /* figure out if this interrupt is for main or sub lcd */
  645. is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
  646. /* wake up channel and disable clocks */
  647. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  648. ch = &priv->ch[k];
  649. if (!ch->enabled)
  650. continue;
  651. /* Frame End */
  652. if (ldintr & LDINTR_FS) {
  653. if (is_sub == lcdc_chan_is_sublcd(ch)) {
  654. ch->frame_end = 1;
  655. wake_up(&ch->frame_end_wait);
  656. sh_mobile_lcdc_clk_off(priv);
  657. }
  658. }
  659. /* VSYNC End */
  660. if (ldintr & LDINTR_VES)
  661. complete(&ch->vsync_completion);
  662. }
  663. return IRQ_HANDLED;
  664. }
  665. static int sh_mobile_lcdc_wait_for_vsync(struct sh_mobile_lcdc_chan *ch)
  666. {
  667. unsigned long ldintr;
  668. int ret;
  669. /* Enable VSync End interrupt and be careful not to acknowledge any
  670. * pending interrupt.
  671. */
  672. ldintr = lcdc_read(ch->lcdc, _LDINTR);
  673. ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK;
  674. lcdc_write(ch->lcdc, _LDINTR, ldintr);
  675. ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
  676. msecs_to_jiffies(100));
  677. if (!ret)
  678. return -ETIMEDOUT;
  679. return 0;
  680. }
  681. static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
  682. int start)
  683. {
  684. unsigned long tmp = lcdc_read(priv, _LDCNT2R);
  685. int k;
  686. /* start or stop the lcdc */
  687. if (start)
  688. lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
  689. else
  690. lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
  691. /* wait until power is applied/stopped on all channels */
  692. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  693. if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
  694. while (1) {
  695. tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
  696. & LDPMR_LPS;
  697. if (start && tmp == LDPMR_LPS)
  698. break;
  699. if (!start && tmp == 0)
  700. break;
  701. cpu_relax();
  702. }
  703. if (!start)
  704. lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
  705. }
  706. static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
  707. {
  708. const struct fb_var_screeninfo *var = &ch->info->var;
  709. const struct fb_videomode *mode = &ch->display.mode;
  710. unsigned long h_total, hsync_pos, display_h_total;
  711. u32 tmp;
  712. tmp = ch->ldmt1r_value;
  713. tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
  714. tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
  715. tmp |= (ch->cfg->flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
  716. tmp |= (ch->cfg->flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
  717. tmp |= (ch->cfg->flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
  718. tmp |= (ch->cfg->flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
  719. tmp |= (ch->cfg->flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
  720. lcdc_write_chan(ch, LDMT1R, tmp);
  721. /* setup SYS bus */
  722. lcdc_write_chan(ch, LDMT2R, ch->cfg->sys_bus_cfg.ldmt2r);
  723. lcdc_write_chan(ch, LDMT3R, ch->cfg->sys_bus_cfg.ldmt3r);
  724. /* horizontal configuration */
  725. h_total = mode->xres + mode->hsync_len + mode->left_margin
  726. + mode->right_margin;
  727. tmp = h_total / 8; /* HTCN */
  728. tmp |= (min(mode->xres, ch->xres) / 8) << 16; /* HDCN */
  729. lcdc_write_chan(ch, LDHCNR, tmp);
  730. hsync_pos = mode->xres + mode->right_margin;
  731. tmp = hsync_pos / 8; /* HSYNP */
  732. tmp |= (mode->hsync_len / 8) << 16; /* HSYNW */
  733. lcdc_write_chan(ch, LDHSYNR, tmp);
  734. /* vertical configuration */
  735. tmp = mode->yres + mode->vsync_len + mode->upper_margin
  736. + mode->lower_margin; /* VTLN */
  737. tmp |= min(mode->yres, ch->yres) << 16; /* VDLN */
  738. lcdc_write_chan(ch, LDVLNR, tmp);
  739. tmp = mode->yres + mode->lower_margin; /* VSYNP */
  740. tmp |= mode->vsync_len << 16; /* VSYNW */
  741. lcdc_write_chan(ch, LDVSYNR, tmp);
  742. /* Adjust horizontal synchronisation for HDMI */
  743. display_h_total = mode->xres + mode->hsync_len + mode->left_margin
  744. + mode->right_margin;
  745. tmp = ((mode->xres & 7) << 24) | ((display_h_total & 7) << 16)
  746. | ((mode->hsync_len & 7) << 8) | (hsync_pos & 7);
  747. lcdc_write_chan(ch, LDHAJR, tmp);
  748. }
  749. static void sh_mobile_lcdc_overlay_setup(struct sh_mobile_lcdc_overlay *ovl)
  750. {
  751. u32 format = 0;
  752. if (!ovl->enabled) {
  753. lcdc_write(ovl->channel->lcdc, LDBCR, LDBCR_UPC(ovl->index));
  754. lcdc_write_overlay(ovl, LDBnBSIFR(ovl->index), 0);
  755. lcdc_write(ovl->channel->lcdc, LDBCR,
  756. LDBCR_UPF(ovl->index) | LDBCR_UPD(ovl->index));
  757. return;
  758. }
  759. ovl->base_addr_y = ovl->dma_handle;
  760. ovl->base_addr_c = ovl->dma_handle
  761. + ovl->xres_virtual * ovl->yres_virtual;
  762. switch (ovl->mode) {
  763. case LCDC_OVERLAY_BLEND:
  764. format = LDBBSIFR_EN | (ovl->alpha << LDBBSIFR_LAY_SHIFT);
  765. break;
  766. case LCDC_OVERLAY_ROP3:
  767. format = LDBBSIFR_EN | LDBBSIFR_BRSEL
  768. | (ovl->rop3 << LDBBSIFR_ROP3_SHIFT);
  769. break;
  770. }
  771. switch (ovl->format->fourcc) {
  772. case V4L2_PIX_FMT_RGB565:
  773. case V4L2_PIX_FMT_NV21:
  774. case V4L2_PIX_FMT_NV61:
  775. case V4L2_PIX_FMT_NV42:
  776. format |= LDBBSIFR_SWPL | LDBBSIFR_SWPW;
  777. break;
  778. case V4L2_PIX_FMT_BGR24:
  779. case V4L2_PIX_FMT_NV12:
  780. case V4L2_PIX_FMT_NV16:
  781. case V4L2_PIX_FMT_NV24:
  782. format |= LDBBSIFR_SWPL | LDBBSIFR_SWPW | LDBBSIFR_SWPB;
  783. break;
  784. case V4L2_PIX_FMT_BGR32:
  785. default:
  786. format |= LDBBSIFR_SWPL;
  787. break;
  788. }
  789. switch (ovl->format->fourcc) {
  790. case V4L2_PIX_FMT_RGB565:
  791. format |= LDBBSIFR_AL_1 | LDBBSIFR_RY | LDBBSIFR_RPKF_RGB16;
  792. break;
  793. case V4L2_PIX_FMT_BGR24:
  794. format |= LDBBSIFR_AL_1 | LDBBSIFR_RY | LDBBSIFR_RPKF_RGB24;
  795. break;
  796. case V4L2_PIX_FMT_BGR32:
  797. format |= LDBBSIFR_AL_PK | LDBBSIFR_RY | LDDFR_PKF_ARGB32;
  798. break;
  799. case V4L2_PIX_FMT_NV12:
  800. case V4L2_PIX_FMT_NV21:
  801. format |= LDBBSIFR_AL_1 | LDBBSIFR_CHRR_420;
  802. break;
  803. case V4L2_PIX_FMT_NV16:
  804. case V4L2_PIX_FMT_NV61:
  805. format |= LDBBSIFR_AL_1 | LDBBSIFR_CHRR_422;
  806. break;
  807. case V4L2_PIX_FMT_NV24:
  808. case V4L2_PIX_FMT_NV42:
  809. format |= LDBBSIFR_AL_1 | LDBBSIFR_CHRR_444;
  810. break;
  811. }
  812. lcdc_write(ovl->channel->lcdc, LDBCR, LDBCR_UPC(ovl->index));
  813. lcdc_write_overlay(ovl, LDBnBSIFR(ovl->index), format);
  814. lcdc_write_overlay(ovl, LDBnBSSZR(ovl->index),
  815. (ovl->yres << LDBBSSZR_BVSS_SHIFT) |
  816. (ovl->xres << LDBBSSZR_BHSS_SHIFT));
  817. lcdc_write_overlay(ovl, LDBnBLOCR(ovl->index),
  818. (ovl->pos_y << LDBBLOCR_CVLC_SHIFT) |
  819. (ovl->pos_x << LDBBLOCR_CHLC_SHIFT));
  820. lcdc_write_overlay(ovl, LDBnBSMWR(ovl->index),
  821. ovl->pitch << LDBBSMWR_BSMW_SHIFT);
  822. lcdc_write_overlay(ovl, LDBnBSAYR(ovl->index), ovl->base_addr_y);
  823. lcdc_write_overlay(ovl, LDBnBSACR(ovl->index), ovl->base_addr_c);
  824. lcdc_write(ovl->channel->lcdc, LDBCR,
  825. LDBCR_UPF(ovl->index) | LDBCR_UPD(ovl->index));
  826. }
  827. /*
  828. * __sh_mobile_lcdc_start - Configure and start the LCDC
  829. * @priv: LCDC device
  830. *
  831. * Configure all enabled channels and start the LCDC device. All external
  832. * devices (clocks, MERAM, panels, ...) are not touched by this function.
  833. */
  834. static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
  835. {
  836. struct sh_mobile_lcdc_chan *ch;
  837. unsigned long tmp;
  838. int k, m;
  839. /* Enable LCDC channels. Read data from external memory, avoid using the
  840. * BEU for now.
  841. */
  842. lcdc_write(priv, _LDCNT2R, priv->ch[0].enabled | priv->ch[1].enabled);
  843. /* Stop the LCDC first and disable all interrupts. */
  844. sh_mobile_lcdc_start_stop(priv, 0);
  845. lcdc_write(priv, _LDINTR, 0);
  846. /* Configure power supply, dot clocks and start them. */
  847. tmp = priv->lddckr;
  848. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  849. ch = &priv->ch[k];
  850. if (!ch->enabled)
  851. continue;
  852. /* Power supply */
  853. lcdc_write_chan(ch, LDPMR, 0);
  854. m = ch->cfg->clock_divider;
  855. if (!m)
  856. continue;
  857. /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
  858. * denominator.
  859. */
  860. lcdc_write_chan(ch, LDDCKPAT1R, 0);
  861. lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
  862. if (m == 1)
  863. m = LDDCKR_MOSEL;
  864. tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
  865. }
  866. lcdc_write(priv, _LDDCKR, tmp);
  867. lcdc_write(priv, _LDDCKSTPR, 0);
  868. lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
  869. /* Setup geometry, format, frame buffer memory and operation mode. */
  870. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  871. ch = &priv->ch[k];
  872. if (!ch->enabled)
  873. continue;
  874. sh_mobile_lcdc_geometry(ch);
  875. tmp = ch->format->lddfr;
  876. if (ch->format->yuv) {
  877. switch (ch->colorspace) {
  878. case V4L2_COLORSPACE_REC709:
  879. tmp |= LDDFR_CF1;
  880. break;
  881. case V4L2_COLORSPACE_JPEG:
  882. tmp |= LDDFR_CF0;
  883. break;
  884. }
  885. }
  886. lcdc_write_chan(ch, LDDFR, tmp);
  887. lcdc_write_chan(ch, LDMLSR, ch->line_size);
  888. lcdc_write_chan(ch, LDSA1R, ch->base_addr_y);
  889. if (ch->format->yuv)
  890. lcdc_write_chan(ch, LDSA2R, ch->base_addr_c);
  891. /* When using deferred I/O mode, configure the LCDC for one-shot
  892. * operation and enable the frame end interrupt. Otherwise use
  893. * continuous read mode.
  894. */
  895. if (ch->ldmt1r_value & LDMT1R_IFM &&
  896. ch->cfg->sys_bus_cfg.deferred_io_msec) {
  897. lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
  898. lcdc_write(priv, _LDINTR, LDINTR_FE);
  899. } else {
  900. lcdc_write_chan(ch, LDSM1R, 0);
  901. }
  902. }
  903. /* Word and long word swap. */
  904. switch (priv->ch[0].format->fourcc) {
  905. case V4L2_PIX_FMT_RGB565:
  906. case V4L2_PIX_FMT_NV21:
  907. case V4L2_PIX_FMT_NV61:
  908. case V4L2_PIX_FMT_NV42:
  909. tmp = LDDDSR_LS | LDDDSR_WS;
  910. break;
  911. case V4L2_PIX_FMT_BGR24:
  912. case V4L2_PIX_FMT_NV12:
  913. case V4L2_PIX_FMT_NV16:
  914. case V4L2_PIX_FMT_NV24:
  915. tmp = LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
  916. break;
  917. case V4L2_PIX_FMT_BGR32:
  918. default:
  919. tmp = LDDDSR_LS;
  920. break;
  921. }
  922. lcdc_write(priv, _LDDDSR, tmp);
  923. /* Enable the display output. */
  924. lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
  925. sh_mobile_lcdc_start_stop(priv, 1);
  926. priv->started = 1;
  927. }
  928. static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
  929. {
  930. struct sh_mobile_meram_info *mdev = priv->meram_dev;
  931. struct sh_mobile_lcdc_chan *ch;
  932. unsigned long tmp;
  933. int ret;
  934. int k;
  935. /* enable clocks before accessing the hardware */
  936. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  937. if (priv->ch[k].enabled)
  938. sh_mobile_lcdc_clk_on(priv);
  939. }
  940. /* reset */
  941. lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
  942. lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
  943. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  944. const struct sh_mobile_lcdc_panel_cfg *panel;
  945. ch = &priv->ch[k];
  946. if (!ch->enabled)
  947. continue;
  948. panel = &ch->cfg->panel_cfg;
  949. if (panel->setup_sys) {
  950. ret = panel->setup_sys(ch, &sh_mobile_lcdc_sys_bus_ops);
  951. if (ret)
  952. return ret;
  953. }
  954. }
  955. /* Compute frame buffer base address and pitch for each channel. */
  956. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  957. int pixelformat;
  958. void *cache;
  959. ch = &priv->ch[k];
  960. if (!ch->enabled)
  961. continue;
  962. ch->base_addr_y = ch->dma_handle;
  963. ch->base_addr_c = ch->dma_handle
  964. + ch->xres_virtual * ch->yres_virtual;
  965. ch->line_size = ch->pitch;
  966. /* Enable MERAM if possible. */
  967. if (mdev == NULL || ch->cfg->meram_cfg == NULL)
  968. continue;
  969. /* Free the allocated MERAM cache. */
  970. if (ch->cache) {
  971. sh_mobile_meram_cache_free(mdev, ch->cache);
  972. ch->cache = NULL;
  973. }
  974. switch (ch->format->fourcc) {
  975. case V4L2_PIX_FMT_NV12:
  976. case V4L2_PIX_FMT_NV21:
  977. case V4L2_PIX_FMT_NV16:
  978. case V4L2_PIX_FMT_NV61:
  979. pixelformat = SH_MOBILE_MERAM_PF_NV;
  980. break;
  981. case V4L2_PIX_FMT_NV24:
  982. case V4L2_PIX_FMT_NV42:
  983. pixelformat = SH_MOBILE_MERAM_PF_NV24;
  984. break;
  985. case V4L2_PIX_FMT_RGB565:
  986. case V4L2_PIX_FMT_BGR24:
  987. case V4L2_PIX_FMT_BGR32:
  988. default:
  989. pixelformat = SH_MOBILE_MERAM_PF_RGB;
  990. break;
  991. }
  992. cache = sh_mobile_meram_cache_alloc(mdev, ch->cfg->meram_cfg,
  993. ch->pitch, ch->yres, pixelformat,
  994. &ch->line_size);
  995. if (!IS_ERR(cache)) {
  996. sh_mobile_meram_cache_update(mdev, cache,
  997. ch->base_addr_y, ch->base_addr_c,
  998. &ch->base_addr_y, &ch->base_addr_c);
  999. ch->cache = cache;
  1000. }
  1001. }
  1002. for (k = 0; k < ARRAY_SIZE(priv->overlays); ++k) {
  1003. struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[k];
  1004. sh_mobile_lcdc_overlay_setup(ovl);
  1005. }
  1006. /* Start the LCDC. */
  1007. __sh_mobile_lcdc_start(priv);
  1008. /* Setup deferred I/O, tell the board code to enable the panels, and
  1009. * turn backlight on.
  1010. */
  1011. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  1012. ch = &priv->ch[k];
  1013. if (!ch->enabled)
  1014. continue;
  1015. tmp = ch->cfg->sys_bus_cfg.deferred_io_msec;
  1016. if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
  1017. ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
  1018. ch->defio.delay = msecs_to_jiffies(tmp);
  1019. ch->info->fbdefio = &ch->defio;
  1020. fb_deferred_io_init(ch->info);
  1021. }
  1022. sh_mobile_lcdc_display_on(ch);
  1023. if (ch->bl) {
  1024. ch->bl->props.power = FB_BLANK_UNBLANK;
  1025. backlight_update_status(ch->bl);
  1026. }
  1027. }
  1028. return 0;
  1029. }
  1030. static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
  1031. {
  1032. struct sh_mobile_lcdc_chan *ch;
  1033. int k;
  1034. /* clean up deferred io and ask board code to disable panel */
  1035. for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
  1036. ch = &priv->ch[k];
  1037. if (!ch->enabled)
  1038. continue;
  1039. /* deferred io mode:
  1040. * flush frame, and wait for frame end interrupt
  1041. * clean up deferred io and enable clock
  1042. */
  1043. if (ch->info && ch->info->fbdefio) {
  1044. ch->frame_end = 0;
  1045. schedule_delayed_work(&ch->info->deferred_work, 0);
  1046. wait_event(ch->frame_end_wait, ch->frame_end);
  1047. fb_deferred_io_cleanup(ch->info);
  1048. ch->info->fbdefio = NULL;
  1049. sh_mobile_lcdc_clk_on(priv);
  1050. }
  1051. if (ch->bl) {
  1052. ch->bl->props.power = FB_BLANK_POWERDOWN;
  1053. backlight_update_status(ch->bl);
  1054. }
  1055. sh_mobile_lcdc_display_off(ch);
  1056. /* Free the MERAM cache. */
  1057. if (ch->cache) {
  1058. sh_mobile_meram_cache_free(priv->meram_dev, ch->cache);
  1059. ch->cache = 0;
  1060. }
  1061. }
  1062. /* stop the lcdc */
  1063. if (priv->started) {
  1064. sh_mobile_lcdc_start_stop(priv, 0);
  1065. priv->started = 0;
  1066. }
  1067. /* stop clocks */
  1068. for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
  1069. if (priv->ch[k].enabled)
  1070. sh_mobile_lcdc_clk_off(priv);
  1071. }
  1072. static int __sh_mobile_lcdc_check_var(struct fb_var_screeninfo *var,
  1073. struct fb_info *info)
  1074. {
  1075. if (var->xres > MAX_XRES || var->yres > MAX_YRES)
  1076. return -EINVAL;
  1077. /* Make sure the virtual resolution is at least as big as the visible
  1078. * resolution.
  1079. */
  1080. if (var->xres_virtual < var->xres)
  1081. var->xres_virtual = var->xres;
  1082. if (var->yres_virtual < var->yres)
  1083. var->yres_virtual = var->yres;
  1084. if (sh_mobile_format_is_fourcc(var)) {
  1085. const struct sh_mobile_lcdc_format_info *format;
  1086. format = sh_mobile_format_info(var->grayscale);
  1087. if (format == NULL)
  1088. return -EINVAL;
  1089. var->bits_per_pixel = format->bpp;
  1090. /* Default to RGB and JPEG color-spaces for RGB and YUV formats
  1091. * respectively.
  1092. */
  1093. if (!format->yuv)
  1094. var->colorspace = V4L2_COLORSPACE_SRGB;
  1095. else if (var->colorspace != V4L2_COLORSPACE_REC709)
  1096. var->colorspace = V4L2_COLORSPACE_JPEG;
  1097. } else {
  1098. if (var->bits_per_pixel <= 16) { /* RGB 565 */
  1099. var->bits_per_pixel = 16;
  1100. var->red.offset = 11;
  1101. var->red.length = 5;
  1102. var->green.offset = 5;
  1103. var->green.length = 6;
  1104. var->blue.offset = 0;
  1105. var->blue.length = 5;
  1106. var->transp.offset = 0;
  1107. var->transp.length = 0;
  1108. } else if (var->bits_per_pixel <= 24) { /* RGB 888 */
  1109. var->bits_per_pixel = 24;
  1110. var->red.offset = 16;
  1111. var->red.length = 8;
  1112. var->green.offset = 8;
  1113. var->green.length = 8;
  1114. var->blue.offset = 0;
  1115. var->blue.length = 8;
  1116. var->transp.offset = 0;
  1117. var->transp.length = 0;
  1118. } else if (var->bits_per_pixel <= 32) { /* RGBA 888 */
  1119. var->bits_per_pixel = 32;
  1120. var->red.offset = 16;
  1121. var->red.length = 8;
  1122. var->green.offset = 8;
  1123. var->green.length = 8;
  1124. var->blue.offset = 0;
  1125. var->blue.length = 8;
  1126. var->transp.offset = 24;
  1127. var->transp.length = 8;
  1128. } else
  1129. return -EINVAL;
  1130. var->red.msb_right = 0;
  1131. var->green.msb_right = 0;
  1132. var->blue.msb_right = 0;
  1133. var->transp.msb_right = 0;
  1134. }
  1135. /* Make sure we don't exceed our allocated memory. */
  1136. if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
  1137. info->fix.smem_len)
  1138. return -EINVAL;
  1139. return 0;
  1140. }
  1141. /* -----------------------------------------------------------------------------
  1142. * Frame buffer operations - Overlays
  1143. */
  1144. static ssize_t
  1145. overlay_alpha_show(struct device *dev, struct device_attribute *attr, char *buf)
  1146. {
  1147. struct fb_info *info = dev_get_drvdata(dev);
  1148. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1149. return scnprintf(buf, PAGE_SIZE, "%u\n", ovl->alpha);
  1150. }
  1151. static ssize_t
  1152. overlay_alpha_store(struct device *dev, struct device_attribute *attr,
  1153. const char *buf, size_t count)
  1154. {
  1155. struct fb_info *info = dev_get_drvdata(dev);
  1156. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1157. unsigned int alpha;
  1158. char *endp;
  1159. alpha = simple_strtoul(buf, &endp, 10);
  1160. if (isspace(*endp))
  1161. endp++;
  1162. if (endp - buf != count)
  1163. return -EINVAL;
  1164. if (alpha > 255)
  1165. return -EINVAL;
  1166. if (ovl->alpha != alpha) {
  1167. ovl->alpha = alpha;
  1168. if (ovl->mode == LCDC_OVERLAY_BLEND && ovl->enabled)
  1169. sh_mobile_lcdc_overlay_setup(ovl);
  1170. }
  1171. return count;
  1172. }
  1173. static ssize_t
  1174. overlay_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
  1175. {
  1176. struct fb_info *info = dev_get_drvdata(dev);
  1177. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1178. return scnprintf(buf, PAGE_SIZE, "%u\n", ovl->mode);
  1179. }
  1180. static ssize_t
  1181. overlay_mode_store(struct device *dev, struct device_attribute *attr,
  1182. const char *buf, size_t count)
  1183. {
  1184. struct fb_info *info = dev_get_drvdata(dev);
  1185. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1186. unsigned int mode;
  1187. char *endp;
  1188. mode = simple_strtoul(buf, &endp, 10);
  1189. if (isspace(*endp))
  1190. endp++;
  1191. if (endp - buf != count)
  1192. return -EINVAL;
  1193. if (mode != LCDC_OVERLAY_BLEND && mode != LCDC_OVERLAY_ROP3)
  1194. return -EINVAL;
  1195. if (ovl->mode != mode) {
  1196. ovl->mode = mode;
  1197. if (ovl->enabled)
  1198. sh_mobile_lcdc_overlay_setup(ovl);
  1199. }
  1200. return count;
  1201. }
  1202. static ssize_t
  1203. overlay_position_show(struct device *dev, struct device_attribute *attr,
  1204. char *buf)
  1205. {
  1206. struct fb_info *info = dev_get_drvdata(dev);
  1207. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1208. return scnprintf(buf, PAGE_SIZE, "%d,%d\n", ovl->pos_x, ovl->pos_y);
  1209. }
  1210. static ssize_t
  1211. overlay_position_store(struct device *dev, struct device_attribute *attr,
  1212. const char *buf, size_t count)
  1213. {
  1214. struct fb_info *info = dev_get_drvdata(dev);
  1215. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1216. char *endp;
  1217. int pos_x;
  1218. int pos_y;
  1219. pos_x = simple_strtol(buf, &endp, 10);
  1220. if (*endp != ',')
  1221. return -EINVAL;
  1222. pos_y = simple_strtol(endp + 1, &endp, 10);
  1223. if (isspace(*endp))
  1224. endp++;
  1225. if (endp - buf != count)
  1226. return -EINVAL;
  1227. if (ovl->pos_x != pos_x || ovl->pos_y != pos_y) {
  1228. ovl->pos_x = pos_x;
  1229. ovl->pos_y = pos_y;
  1230. if (ovl->enabled)
  1231. sh_mobile_lcdc_overlay_setup(ovl);
  1232. }
  1233. return count;
  1234. }
  1235. static ssize_t
  1236. overlay_rop3_show(struct device *dev, struct device_attribute *attr, char *buf)
  1237. {
  1238. struct fb_info *info = dev_get_drvdata(dev);
  1239. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1240. return scnprintf(buf, PAGE_SIZE, "%u\n", ovl->rop3);
  1241. }
  1242. static ssize_t
  1243. overlay_rop3_store(struct device *dev, struct device_attribute *attr,
  1244. const char *buf, size_t count)
  1245. {
  1246. struct fb_info *info = dev_get_drvdata(dev);
  1247. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1248. unsigned int rop3;
  1249. char *endp;
  1250. rop3 = !!simple_strtoul(buf, &endp, 10);
  1251. if (isspace(*endp))
  1252. endp++;
  1253. if (endp - buf != count)
  1254. return -EINVAL;
  1255. if (rop3 > 255)
  1256. return -EINVAL;
  1257. if (ovl->rop3 != rop3) {
  1258. ovl->rop3 = rop3;
  1259. if (ovl->mode == LCDC_OVERLAY_ROP3 && ovl->enabled)
  1260. sh_mobile_lcdc_overlay_setup(ovl);
  1261. }
  1262. return count;
  1263. }
  1264. static const struct device_attribute overlay_sysfs_attrs[] = {
  1265. __ATTR(ovl_alpha, S_IRUGO|S_IWUSR,
  1266. overlay_alpha_show, overlay_alpha_store),
  1267. __ATTR(ovl_mode, S_IRUGO|S_IWUSR,
  1268. overlay_mode_show, overlay_mode_store),
  1269. __ATTR(ovl_position, S_IRUGO|S_IWUSR,
  1270. overlay_position_show, overlay_position_store),
  1271. __ATTR(ovl_rop3, S_IRUGO|S_IWUSR,
  1272. overlay_rop3_show, overlay_rop3_store),
  1273. };
  1274. static const struct fb_fix_screeninfo sh_mobile_lcdc_overlay_fix = {
  1275. .id = "SH Mobile LCDC",
  1276. .type = FB_TYPE_PACKED_PIXELS,
  1277. .visual = FB_VISUAL_TRUECOLOR,
  1278. .accel = FB_ACCEL_NONE,
  1279. .xpanstep = 1,
  1280. .ypanstep = 1,
  1281. .ywrapstep = 0,
  1282. .capabilities = FB_CAP_FOURCC,
  1283. };
  1284. static int sh_mobile_lcdc_overlay_pan(struct fb_var_screeninfo *var,
  1285. struct fb_info *info)
  1286. {
  1287. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1288. unsigned long base_addr_y;
  1289. unsigned long base_addr_c;
  1290. unsigned long y_offset;
  1291. unsigned long c_offset;
  1292. if (!ovl->format->yuv) {
  1293. y_offset = (var->yoffset * ovl->xres_virtual + var->xoffset)
  1294. * ovl->format->bpp / 8;
  1295. c_offset = 0;
  1296. } else {
  1297. unsigned int xsub = ovl->format->bpp < 24 ? 2 : 1;
  1298. unsigned int ysub = ovl->format->bpp < 16 ? 2 : 1;
  1299. y_offset = var->yoffset * ovl->xres_virtual + var->xoffset;
  1300. c_offset = var->yoffset / ysub * ovl->xres_virtual * 2 / xsub
  1301. + var->xoffset * 2 / xsub;
  1302. }
  1303. /* If the Y offset hasn't changed, the C offset hasn't either. There's
  1304. * nothing to do in that case.
  1305. */
  1306. if (y_offset == ovl->pan_y_offset)
  1307. return 0;
  1308. /* Set the source address for the next refresh */
  1309. base_addr_y = ovl->dma_handle + y_offset;
  1310. base_addr_c = ovl->dma_handle + ovl->xres_virtual * ovl->yres_virtual
  1311. + c_offset;
  1312. ovl->base_addr_y = base_addr_y;
  1313. ovl->base_addr_c = base_addr_c;
  1314. ovl->pan_y_offset = y_offset;
  1315. lcdc_write(ovl->channel->lcdc, LDBCR, LDBCR_UPC(ovl->index));
  1316. lcdc_write_overlay(ovl, LDBnBSAYR(ovl->index), ovl->base_addr_y);
  1317. lcdc_write_overlay(ovl, LDBnBSACR(ovl->index), ovl->base_addr_c);
  1318. lcdc_write(ovl->channel->lcdc, LDBCR,
  1319. LDBCR_UPF(ovl->index) | LDBCR_UPD(ovl->index));
  1320. return 0;
  1321. }
  1322. static int sh_mobile_lcdc_overlay_ioctl(struct fb_info *info, unsigned int cmd,
  1323. unsigned long arg)
  1324. {
  1325. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1326. switch (cmd) {
  1327. case FBIO_WAITFORVSYNC:
  1328. return sh_mobile_lcdc_wait_for_vsync(ovl->channel);
  1329. default:
  1330. return -ENOIOCTLCMD;
  1331. }
  1332. }
  1333. static int sh_mobile_lcdc_overlay_check_var(struct fb_var_screeninfo *var,
  1334. struct fb_info *info)
  1335. {
  1336. return __sh_mobile_lcdc_check_var(var, info);
  1337. }
  1338. static int sh_mobile_lcdc_overlay_set_par(struct fb_info *info)
  1339. {
  1340. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1341. ovl->format =
  1342. sh_mobile_format_info(sh_mobile_format_fourcc(&info->var));
  1343. ovl->xres = info->var.xres;
  1344. ovl->xres_virtual = info->var.xres_virtual;
  1345. ovl->yres = info->var.yres;
  1346. ovl->yres_virtual = info->var.yres_virtual;
  1347. if (ovl->format->yuv)
  1348. ovl->pitch = info->var.xres_virtual;
  1349. else
  1350. ovl->pitch = info->var.xres_virtual * ovl->format->bpp / 8;
  1351. sh_mobile_lcdc_overlay_setup(ovl);
  1352. info->fix.line_length = ovl->pitch;
  1353. if (sh_mobile_format_is_fourcc(&info->var)) {
  1354. info->fix.type = FB_TYPE_FOURCC;
  1355. info->fix.visual = FB_VISUAL_FOURCC;
  1356. } else {
  1357. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1358. info->fix.visual = FB_VISUAL_TRUECOLOR;
  1359. }
  1360. return 0;
  1361. }
  1362. /* Overlay blanking. Disable the overlay when blanked. */
  1363. static int sh_mobile_lcdc_overlay_blank(int blank, struct fb_info *info)
  1364. {
  1365. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1366. ovl->enabled = !blank;
  1367. sh_mobile_lcdc_overlay_setup(ovl);
  1368. /* Prevent the backlight from receiving a blanking event by returning
  1369. * a non-zero value.
  1370. */
  1371. return 1;
  1372. }
  1373. static int
  1374. sh_mobile_lcdc_overlay_mmap(struct fb_info *info, struct vm_area_struct *vma)
  1375. {
  1376. struct sh_mobile_lcdc_overlay *ovl = info->par;
  1377. return dma_mmap_coherent(ovl->channel->lcdc->dev, vma, ovl->fb_mem,
  1378. ovl->dma_handle, ovl->fb_size);
  1379. }
  1380. static struct fb_ops sh_mobile_lcdc_overlay_ops = {
  1381. .owner = THIS_MODULE,
  1382. .fb_read = fb_sys_read,
  1383. .fb_write = fb_sys_write,
  1384. .fb_fillrect = sys_fillrect,
  1385. .fb_copyarea = sys_copyarea,
  1386. .fb_imageblit = sys_imageblit,
  1387. .fb_blank = sh_mobile_lcdc_overlay_blank,
  1388. .fb_pan_display = sh_mobile_lcdc_overlay_pan,
  1389. .fb_ioctl = sh_mobile_lcdc_overlay_ioctl,
  1390. .fb_check_var = sh_mobile_lcdc_overlay_check_var,
  1391. .fb_set_par = sh_mobile_lcdc_overlay_set_par,
  1392. .fb_mmap = sh_mobile_lcdc_overlay_mmap,
  1393. };
  1394. static void
  1395. sh_mobile_lcdc_overlay_fb_unregister(struct sh_mobile_lcdc_overlay *ovl)
  1396. {
  1397. struct fb_info *info = ovl->info;
  1398. if (info == NULL || info->dev == NULL)
  1399. return;
  1400. unregister_framebuffer(ovl->info);
  1401. }
  1402. static int
  1403. sh_mobile_lcdc_overlay_fb_register(struct sh_mobile_lcdc_overlay *ovl)
  1404. {
  1405. struct sh_mobile_lcdc_priv *lcdc = ovl->channel->lcdc;
  1406. struct fb_info *info = ovl->info;
  1407. unsigned int i;
  1408. int ret;
  1409. if (info == NULL)
  1410. return 0;
  1411. ret = register_framebuffer(info);
  1412. if (ret < 0)
  1413. return ret;
  1414. dev_info(lcdc->dev, "registered %s/overlay %u as %dx%d %dbpp.\n",
  1415. dev_name(lcdc->dev), ovl->index, info->var.xres,
  1416. info->var.yres, info->var.bits_per_pixel);
  1417. for (i = 0; i < ARRAY_SIZE(overlay_sysfs_attrs); ++i) {
  1418. ret = device_create_file(info->dev, &overlay_sysfs_attrs[i]);
  1419. if (ret < 0)
  1420. return ret;
  1421. }
  1422. return 0;
  1423. }
  1424. static void
  1425. sh_mobile_lcdc_overlay_fb_cleanup(struct sh_mobile_lcdc_overlay *ovl)
  1426. {
  1427. struct fb_info *info = ovl->info;
  1428. if (info == NULL || info->device == NULL)
  1429. return;
  1430. framebuffer_release(info);
  1431. }
  1432. static int
  1433. sh_mobile_lcdc_overlay_fb_init(struct sh_mobile_lcdc_overlay *ovl)
  1434. {
  1435. struct sh_mobile_lcdc_priv *priv = ovl->channel->lcdc;
  1436. struct fb_var_screeninfo *var;
  1437. struct fb_info *info;
  1438. /* Allocate and initialize the frame buffer device. */
  1439. info = framebuffer_alloc(0, priv->dev);
  1440. if (info == NULL) {
  1441. dev_err(priv->dev, "unable to allocate fb_info\n");
  1442. return -ENOMEM;
  1443. }
  1444. ovl->info = info;
  1445. info->flags = FBINFO_FLAG_DEFAULT;
  1446. info->fbops = &sh_mobile_lcdc_overlay_ops;
  1447. info->device = priv->dev;
  1448. info->screen_base = ovl->fb_mem;
  1449. info->par = ovl;
  1450. /* Initialize fixed screen information. Restrict pan to 2 lines steps
  1451. * for NV12 and NV21.
  1452. */
  1453. info->fix = sh_mobile_lcdc_overlay_fix;
  1454. snprintf(info->fix.id, sizeof(info->fix.id),
  1455. "SH Mobile LCDC Overlay %u", ovl->index);
  1456. info->fix.smem_start = ovl->dma_handle;
  1457. info->fix.smem_len = ovl->fb_size;
  1458. info->fix.line_length = ovl->pitch;
  1459. if (ovl->format->yuv)
  1460. info->fix.visual = FB_VISUAL_FOURCC;
  1461. else
  1462. info->fix.visual = FB_VISUAL_TRUECOLOR;
  1463. switch (ovl->format->fourcc) {
  1464. case V4L2_PIX_FMT_NV12:
  1465. case V4L2_PIX_FMT_NV21:
  1466. info->fix.ypanstep = 2;
  1467. case V4L2_PIX_FMT_NV16:
  1468. case V4L2_PIX_FMT_NV61:
  1469. info->fix.xpanstep = 2;
  1470. }
  1471. /* Initialize variable screen information. */
  1472. var = &info->var;
  1473. memset(var, 0, sizeof(*var));
  1474. var->xres = ovl->xres;
  1475. var->yres = ovl->yres;
  1476. var->xres_virtual = ovl->xres_virtual;
  1477. var->yres_virtual = ovl->yres_virtual;
  1478. var->activate = FB_ACTIVATE_NOW;
  1479. /* Use the legacy API by default for RGB formats, and the FOURCC API
  1480. * for YUV formats.
  1481. */
  1482. if (!ovl->format->yuv)
  1483. var->bits_per_pixel = ovl->format->bpp;
  1484. else
  1485. var->grayscale = ovl->format->fourcc;
  1486. return sh_mobile_lcdc_overlay_check_var(var, info);
  1487. }
  1488. /* -----------------------------------------------------------------------------
  1489. * Frame buffer operations - main frame buffer
  1490. */
  1491. static int sh_mobile_lcdc_setcolreg(u_int regno,
  1492. u_int red, u_int green, u_int blue,
  1493. u_int transp, struct fb_info *info)
  1494. {
  1495. u32 *palette = info->pseudo_palette;
  1496. if (regno >= PALETTE_NR)
  1497. return -EINVAL;
  1498. /* only FB_VISUAL_TRUECOLOR supported */
  1499. red >>= 16 - info->var.red.length;
  1500. green >>= 16 - info->var.green.length;
  1501. blue >>= 16 - info->var.blue.length;
  1502. transp >>= 16 - info->var.transp.length;
  1503. palette[regno] = (red << info->var.red.offset) |
  1504. (green << info->var.green.offset) |
  1505. (blue << info->var.blue.offset) |
  1506. (transp << info->var.transp.offset);
  1507. return 0;
  1508. }
  1509. static const struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
  1510. .id = "SH Mobile LCDC",
  1511. .type = FB_TYPE_PACKED_PIXELS,
  1512. .visual = FB_VISUAL_TRUECOLOR,
  1513. .accel = FB_ACCEL_NONE,
  1514. .xpanstep = 1,
  1515. .ypanstep = 1,
  1516. .ywrapstep = 0,
  1517. .capabilities = FB_CAP_FOURCC,
  1518. };
  1519. static void sh_mobile_lcdc_fillrect(struct fb_info *info,
  1520. const struct fb_fillrect *rect)
  1521. {
  1522. sys_fillrect(info, rect);
  1523. sh_mobile_lcdc_deferred_io_touch(info);
  1524. }
  1525. static void sh_mobile_lcdc_copyarea(struct fb_info *info,
  1526. const struct fb_copyarea *area)
  1527. {
  1528. sys_copyarea(info, area);
  1529. sh_mobile_lcdc_deferred_io_touch(info);
  1530. }
  1531. static void sh_mobile_lcdc_imageblit(struct fb_info *info,
  1532. const struct fb_image *image)
  1533. {
  1534. sys_imageblit(info, image);
  1535. sh_mobile_lcdc_deferred_io_touch(info);
  1536. }
  1537. static int sh_mobile_lcdc_pan(struct fb_var_screeninfo *var,
  1538. struct fb_info *info)
  1539. {
  1540. struct sh_mobile_lcdc_chan *ch = info->par;
  1541. struct sh_mobile_lcdc_priv *priv = ch->lcdc;
  1542. unsigned long ldrcntr;
  1543. unsigned long base_addr_y, base_addr_c;
  1544. unsigned long y_offset;
  1545. unsigned long c_offset;
  1546. if (!ch->format->yuv) {
  1547. y_offset = (var->yoffset * ch->xres_virtual + var->xoffset)
  1548. * ch->format->bpp / 8;
  1549. c_offset = 0;
  1550. } else {
  1551. unsigned int xsub = ch->format->bpp < 24 ? 2 : 1;
  1552. unsigned int ysub = ch->format->bpp < 16 ? 2 : 1;
  1553. y_offset = var->yoffset * ch->xres_virtual + var->xoffset;
  1554. c_offset = var->yoffset / ysub * ch->xres_virtual * 2 / xsub
  1555. + var->xoffset * 2 / xsub;
  1556. }
  1557. /* If the Y offset hasn't changed, the C offset hasn't either. There's
  1558. * nothing to do in that case.
  1559. */
  1560. if (y_offset == ch->pan_y_offset)
  1561. return 0;
  1562. /* Set the source address for the next refresh */
  1563. base_addr_y = ch->dma_handle + y_offset;
  1564. base_addr_c = ch->dma_handle + ch->xres_virtual * ch->yres_virtual
  1565. + c_offset;
  1566. if (ch->cache)
  1567. sh_mobile_meram_cache_update(priv->meram_dev, ch->cache,
  1568. base_addr_y, base_addr_c,
  1569. &base_addr_y, &base_addr_c);
  1570. ch->base_addr_y = base_addr_y;
  1571. ch->base_addr_c = base_addr_c;
  1572. ch->pan_y_offset = y_offset;
  1573. lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
  1574. if (ch->format->yuv)
  1575. lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
  1576. ldrcntr = lcdc_read(priv, _LDRCNTR);
  1577. if (lcdc_chan_is_sublcd(ch))
  1578. lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
  1579. else
  1580. lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
  1581. sh_mobile_lcdc_deferred_io_touch(info);
  1582. return 0;
  1583. }
  1584. static int sh_mobile_lcdc_ioctl(struct fb_info *info, unsigned int cmd,
  1585. unsigned long arg)
  1586. {
  1587. struct sh_mobile_lcdc_chan *ch = info->par;
  1588. int retval;
  1589. switch (cmd) {
  1590. case FBIO_WAITFORVSYNC:
  1591. retval = sh_mobile_lcdc_wait_for_vsync(ch);
  1592. break;
  1593. default:
  1594. retval = -ENOIOCTLCMD;
  1595. break;
  1596. }
  1597. return retval;
  1598. }
  1599. static void sh_mobile_fb_reconfig(struct fb_info *info)
  1600. {
  1601. struct sh_mobile_lcdc_chan *ch = info->par;
  1602. struct fb_var_screeninfo var;
  1603. struct fb_videomode mode;
  1604. struct fb_event event;
  1605. int evnt = FB_EVENT_MODE_CHANGE_ALL;
  1606. if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
  1607. /* More framebuffer users are active */
  1608. return;
  1609. fb_var_to_videomode(&mode, &info->var);
  1610. if (fb_mode_is_equal(&ch->display.mode, &mode))
  1611. return;
  1612. /* Display has been re-plugged, framebuffer is free now, reconfigure */
  1613. var = info->var;
  1614. fb_videomode_to_var(&var, &ch->display.mode);
  1615. var.width = ch->display.width;
  1616. var.height = ch->display.height;
  1617. var.activate = FB_ACTIVATE_NOW;
  1618. if (fb_set_var(info, &var) < 0)
  1619. /* Couldn't reconfigure, hopefully, can continue as before */
  1620. return;
  1621. /*
  1622. * fb_set_var() calls the notifier change internally, only if
  1623. * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
  1624. * user event, we have to call the chain ourselves.
  1625. */
  1626. event.info = info;
  1627. event.data = &ch->display.mode;
  1628. fb_notifier_call_chain(evnt, &event);
  1629. }
  1630. /*
  1631. * Locking: both .fb_release() and .fb_open() are called with info->lock held if
  1632. * user == 1, or with console sem held, if user == 0.
  1633. */
  1634. static int sh_mobile_lcdc_release(struct fb_info *info, int user)
  1635. {
  1636. struct sh_mobile_lcdc_chan *ch = info->par;
  1637. mutex_lock(&ch->open_lock);
  1638. dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
  1639. ch->use_count--;
  1640. /* Nothing to reconfigure, when called from fbcon */
  1641. if (user) {
  1642. console_lock();
  1643. sh_mobile_fb_reconfig(info);
  1644. console_unlock();
  1645. }
  1646. mutex_unlock(&ch->open_lock);
  1647. return 0;
  1648. }
  1649. static int sh_mobile_lcdc_open(struct fb_info *info, int user)
  1650. {
  1651. struct sh_mobile_lcdc_chan *ch = info->par;
  1652. mutex_lock(&ch->open_lock);
  1653. ch->use_count++;
  1654. dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
  1655. mutex_unlock(&ch->open_lock);
  1656. return 0;
  1657. }
  1658. static int sh_mobile_lcdc_check_var(struct fb_var_screeninfo *var,
  1659. struct fb_info *info)
  1660. {
  1661. struct sh_mobile_lcdc_chan *ch = info->par;
  1662. struct sh_mobile_lcdc_priv *p = ch->lcdc;
  1663. unsigned int best_dist = (unsigned int)-1;
  1664. unsigned int best_xres = 0;
  1665. unsigned int best_yres = 0;
  1666. unsigned int i;
  1667. int ret;
  1668. /* If board code provides us with a list of available modes, make sure
  1669. * we use one of them. Find the mode closest to the requested one. The
  1670. * distance between two modes is defined as the size of the
  1671. * non-overlapping parts of the two rectangles.
  1672. */
  1673. for (i = 0; i < ch->cfg->num_modes; ++i) {
  1674. const struct fb_videomode *mode = &ch->cfg->lcd_modes[i];
  1675. unsigned int dist;
  1676. /* We can only round up. */
  1677. if (var->xres > mode->xres || var->yres > mode->yres)
  1678. continue;
  1679. dist = var->xres * var->yres + mode->xres * mode->yres
  1680. - 2 * min(var->xres, mode->xres)
  1681. * min(var->yres, mode->yres);
  1682. if (dist < best_dist) {
  1683. best_xres = mode->xres;
  1684. best_yres = mode->yres;
  1685. best_dist = dist;
  1686. }
  1687. }
  1688. /* If no available mode can be used, return an error. */
  1689. if (ch->cfg->num_modes != 0) {
  1690. if (best_dist == (unsigned int)-1)
  1691. return -EINVAL;
  1692. var->xres = best_xres;
  1693. var->yres = best_yres;
  1694. }
  1695. ret = __sh_mobile_lcdc_check_var(var, info);
  1696. if (ret < 0)
  1697. return ret;
  1698. /* only accept the forced_fourcc for dual channel configurations */
  1699. if (p->forced_fourcc &&
  1700. p->forced_fourcc != sh_mobile_format_fourcc(var))
  1701. return -EINVAL;
  1702. return 0;
  1703. }
  1704. static int sh_mobile_lcdc_set_par(struct fb_info *info)
  1705. {
  1706. struct sh_mobile_lcdc_chan *ch = info->par;
  1707. int ret;
  1708. sh_mobile_lcdc_stop(ch->lcdc);
  1709. ch->format = sh_mobile_format_info(sh_mobile_format_fourcc(&info->var));
  1710. ch->colorspace = info->var.colorspace;
  1711. ch->xres = info->var.xres;
  1712. ch->xres_virtual = info->var.xres_virtual;
  1713. ch->yres = info->var.yres;
  1714. ch->yres_virtual = info->var.yres_virtual;
  1715. if (ch->format->yuv)
  1716. ch->pitch = info->var.xres_virtual;
  1717. else
  1718. ch->pitch = info->var.xres_virtual * ch->format->bpp / 8;
  1719. ret = sh_mobile_lcdc_start(ch->lcdc);
  1720. if (ret < 0)
  1721. dev_err(info->dev, "%s: unable to restart LCDC\n", __func__);
  1722. info->fix.line_length = ch->pitch;
  1723. if (sh_mobile_format_is_fourcc(&info->var)) {
  1724. info->fix.type = FB_TYPE_FOURCC;
  1725. info->fix.visual = FB_VISUAL_FOURCC;
  1726. } else {
  1727. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1728. info->fix.visual = FB_VISUAL_TRUECOLOR;
  1729. }
  1730. return ret;
  1731. }
  1732. /*
  1733. * Screen blanking. Behavior is as follows:
  1734. * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
  1735. * FB_BLANK_NORMAL: screen blanked, clocks enabled
  1736. * FB_BLANK_VSYNC,
  1737. * FB_BLANK_HSYNC,
  1738. * FB_BLANK_POWEROFF: screen blanked, clocks disabled
  1739. */
  1740. static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
  1741. {
  1742. struct sh_mobile_lcdc_chan *ch = info->par;
  1743. struct sh_mobile_lcdc_priv *p = ch->lcdc;
  1744. /* blank the screen? */
  1745. if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
  1746. struct fb_fillrect rect = {
  1747. .width = ch->xres,
  1748. .height = ch->yres,
  1749. };
  1750. sh_mobile_lcdc_fillrect(info, &rect);
  1751. }
  1752. /* turn clocks on? */
  1753. if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
  1754. sh_mobile_lcdc_clk_on(p);
  1755. }
  1756. /* turn clocks off? */
  1757. if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
  1758. /* make sure the screen is updated with the black fill before
  1759. * switching the clocks off. one vsync is not enough since
  1760. * blanking may occur in the middle of a refresh. deferred io
  1761. * mode will reenable the clocks and update the screen in time,
  1762. * so it does not need this. */
  1763. if (!info->fbdefio) {
  1764. sh_mobile_lcdc_wait_for_vsync(ch);
  1765. sh_mobile_lcdc_wait_for_vsync(ch);
  1766. }
  1767. sh_mobile_lcdc_clk_off(p);
  1768. }
  1769. ch->blank_status = blank;
  1770. return 0;
  1771. }
  1772. static int
  1773. sh_mobile_lcdc_mmap(struct fb_info *info, struct vm_area_struct *vma)
  1774. {
  1775. struct sh_mobile_lcdc_chan *ch = info->par;
  1776. return dma_mmap_coherent(ch->lcdc->dev, vma, ch->fb_mem,
  1777. ch->dma_handle, ch->fb_size);
  1778. }
  1779. static struct fb_ops sh_mobile_lcdc_ops = {
  1780. .owner = THIS_MODULE,
  1781. .fb_setcolreg = sh_mobile_lcdc_setcolreg,
  1782. .fb_read = fb_sys_read,
  1783. .fb_write = fb_sys_write,
  1784. .fb_fillrect = sh_mobile_lcdc_fillrect,
  1785. .fb_copyarea = sh_mobile_lcdc_copyarea,
  1786. .fb_imageblit = sh_mobile_lcdc_imageblit,
  1787. .fb_blank = sh_mobile_lcdc_blank,
  1788. .fb_pan_display = sh_mobile_lcdc_pan,
  1789. .fb_ioctl = sh_mobile_lcdc_ioctl,
  1790. .fb_open = sh_mobile_lcdc_open,
  1791. .fb_release = sh_mobile_lcdc_release,
  1792. .fb_check_var = sh_mobile_lcdc_check_var,
  1793. .fb_set_par = sh_mobile_lcdc_set_par,
  1794. .fb_mmap = sh_mobile_lcdc_mmap,
  1795. };
  1796. static void
  1797. sh_mobile_lcdc_channel_fb_unregister(struct sh_mobile_lcdc_chan *ch)
  1798. {
  1799. if (ch->info && ch->info->dev)
  1800. unregister_framebuffer(ch->info);
  1801. }
  1802. static int
  1803. sh_mobile_lcdc_channel_fb_register(struct sh_mobile_lcdc_chan *ch)
  1804. {
  1805. struct fb_info *info = ch->info;
  1806. int ret;
  1807. if (info->fbdefio) {
  1808. ch->sglist = vmalloc(sizeof(struct scatterlist) *
  1809. ch->fb_size >> PAGE_SHIFT);
  1810. if (!ch->sglist) {
  1811. dev_err(ch->lcdc->dev, "cannot allocate sglist\n");
  1812. return -ENOMEM;
  1813. }
  1814. }
  1815. info->bl_dev = ch->bl;
  1816. ret = register_framebuffer(info);
  1817. if (ret < 0)
  1818. return ret;
  1819. dev_info(ch->lcdc->dev, "registered %s/%s as %dx%d %dbpp.\n",
  1820. dev_name(ch->lcdc->dev), (ch->cfg->chan == LCDC_CHAN_MAINLCD) ?
  1821. "mainlcd" : "sublcd", info->var.xres, info->var.yres,
  1822. info->var.bits_per_pixel);
  1823. /* deferred io mode: disable clock to save power */
  1824. if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
  1825. sh_mobile_lcdc_clk_off(ch->lcdc);
  1826. return ret;
  1827. }
  1828. static void
  1829. sh_mobile_lcdc_channel_fb_cleanup(struct sh_mobile_lcdc_chan *ch)
  1830. {
  1831. struct fb_info *info = ch->info;
  1832. if (!info || !info->device)
  1833. return;
  1834. if (ch->sglist)
  1835. vfree(ch->sglist);
  1836. fb_dealloc_cmap(&info->cmap);
  1837. framebuffer_release(info);
  1838. }
  1839. static int
  1840. sh_mobile_lcdc_channel_fb_init(struct sh_mobile_lcdc_chan *ch,
  1841. const struct fb_videomode *modes,
  1842. unsigned int num_modes)
  1843. {
  1844. struct sh_mobile_lcdc_priv *priv = ch->lcdc;
  1845. struct fb_var_screeninfo *var;
  1846. struct fb_info *info;
  1847. int ret;
  1848. /* Allocate and initialize the frame buffer device. Create the modes
  1849. * list and allocate the color map.
  1850. */
  1851. info = framebuffer_alloc(0, priv->dev);
  1852. if (info == NULL) {
  1853. dev_err(priv->dev, "unable to allocate fb_info\n");
  1854. return -ENOMEM;
  1855. }
  1856. ch->info = info;
  1857. info->flags = FBINFO_FLAG_DEFAULT;
  1858. info->fbops = &sh_mobile_lcdc_ops;
  1859. info->device = priv->dev;
  1860. info->screen_base = ch->fb_mem;
  1861. info->pseudo_palette = &ch->pseudo_palette;
  1862. info->par = ch;
  1863. fb_videomode_to_modelist(modes, num_modes, &info->modelist);
  1864. ret = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
  1865. if (ret < 0) {
  1866. dev_err(priv->dev, "unable to allocate cmap\n");
  1867. return ret;
  1868. }
  1869. /* Initialize fixed screen information. Restrict pan to 2 lines steps
  1870. * for NV12 and NV21.
  1871. */
  1872. info->fix = sh_mobile_lcdc_fix;
  1873. info->fix.smem_start = ch->dma_handle;
  1874. info->fix.smem_len = ch->fb_size;
  1875. info->fix.line_length = ch->pitch;
  1876. if (ch->format->yuv)
  1877. info->fix.visual = FB_VISUAL_FOURCC;
  1878. else
  1879. info->fix.visual = FB_VISUAL_TRUECOLOR;
  1880. switch (ch->format->fourcc) {
  1881. case V4L2_PIX_FMT_NV12:
  1882. case V4L2_PIX_FMT_NV21:
  1883. info->fix.ypanstep = 2;
  1884. case V4L2_PIX_FMT_NV16:
  1885. case V4L2_PIX_FMT_NV61:
  1886. info->fix.xpanstep = 2;
  1887. }
  1888. /* Initialize variable screen information using the first mode as
  1889. * default.
  1890. */
  1891. var = &info->var;
  1892. fb_videomode_to_var(var, modes);
  1893. var->width = ch->display.width;
  1894. var->height = ch->display.height;
  1895. var->xres_virtual = ch->xres_virtual;
  1896. var->yres_virtual = ch->yres_virtual;
  1897. var->activate = FB_ACTIVATE_NOW;
  1898. /* Use the legacy API by default for RGB formats, and the FOURCC API
  1899. * for YUV formats.
  1900. */
  1901. if (!ch->format->yuv)
  1902. var->bits_per_pixel = ch->format->bpp;
  1903. else
  1904. var->grayscale = ch->format->fourcc;
  1905. ret = sh_mobile_lcdc_check_var(var, info);
  1906. if (ret)
  1907. return ret;
  1908. return 0;
  1909. }
  1910. /* -----------------------------------------------------------------------------
  1911. * Backlight
  1912. */
  1913. static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
  1914. {
  1915. struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
  1916. int brightness = bdev->props.brightness;
  1917. if (bdev->props.power != FB_BLANK_UNBLANK ||
  1918. bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
  1919. brightness = 0;
  1920. ch->bl_brightness = brightness;
  1921. return ch->cfg->bl_info.set_brightness(brightness);
  1922. }
  1923. static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
  1924. {
  1925. struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
  1926. return ch->bl_brightness;
  1927. }
  1928. static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
  1929. struct fb_info *info)
  1930. {
  1931. return (info->bl_dev == bdev);
  1932. }
  1933. static struct backlight_ops sh_mobile_lcdc_bl_ops = {
  1934. .options = BL_CORE_SUSPENDRESUME,
  1935. .update_status = sh_mobile_lcdc_update_bl,
  1936. .get_brightness = sh_mobile_lcdc_get_brightness,
  1937. .check_fb = sh_mobile_lcdc_check_fb,
  1938. };
  1939. static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
  1940. struct sh_mobile_lcdc_chan *ch)
  1941. {
  1942. struct backlight_device *bl;
  1943. bl = backlight_device_register(ch->cfg->bl_info.name, parent, ch,
  1944. &sh_mobile_lcdc_bl_ops, NULL);
  1945. if (IS_ERR(bl)) {
  1946. dev_err(parent, "unable to register backlight device: %ld\n",
  1947. PTR_ERR(bl));
  1948. return NULL;
  1949. }
  1950. bl->props.max_brightness = ch->cfg->bl_info.max_brightness;
  1951. bl->props.brightness = bl->props.max_brightness;
  1952. backlight_update_status(bl);
  1953. return bl;
  1954. }
  1955. static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
  1956. {
  1957. backlight_device_unregister(bdev);
  1958. }
  1959. /* -----------------------------------------------------------------------------
  1960. * Power management
  1961. */
  1962. static int sh_mobile_lcdc_suspend(struct device *dev)
  1963. {
  1964. struct platform_device *pdev = to_platform_device(dev);
  1965. sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
  1966. return 0;
  1967. }
  1968. static int sh_mobile_lcdc_resume(struct device *dev)
  1969. {
  1970. struct platform_device *pdev = to_platform_device(dev);
  1971. return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
  1972. }
  1973. static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
  1974. {
  1975. struct platform_device *pdev = to_platform_device(dev);
  1976. struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
  1977. /* turn off LCDC hardware */
  1978. lcdc_write(priv, _LDCNT1R, 0);
  1979. return 0;
  1980. }
  1981. static int sh_mobile_lcdc_runtime_resume(struct device *dev)
  1982. {
  1983. struct platform_device *pdev = to_platform_device(dev);
  1984. struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
  1985. __sh_mobile_lcdc_start(priv);
  1986. return 0;
  1987. }
  1988. static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
  1989. .suspend = sh_mobile_lcdc_suspend,
  1990. .resume = sh_mobile_lcdc_resume,
  1991. .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
  1992. .runtime_resume = sh_mobile_lcdc_runtime_resume,
  1993. };
  1994. /* -----------------------------------------------------------------------------
  1995. * Framebuffer notifier
  1996. */
  1997. /* locking: called with info->lock held */
  1998. static int sh_mobile_lcdc_notify(struct notifier_block *nb,
  1999. unsigned long action, void *data)
  2000. {
  2001. struct fb_event *event = data;
  2002. struct fb_info *info = event->info;
  2003. struct sh_mobile_lcdc_chan *ch = info->par;
  2004. if (&ch->lcdc->notifier != nb)
  2005. return NOTIFY_DONE;
  2006. dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
  2007. __func__, action, event->data);
  2008. switch(action) {
  2009. case FB_EVENT_SUSPEND:
  2010. sh_mobile_lcdc_display_off(ch);
  2011. sh_mobile_lcdc_stop(ch->lcdc);
  2012. break;
  2013. case FB_EVENT_RESUME:
  2014. mutex_lock(&ch->open_lock);
  2015. sh_mobile_fb_reconfig(info);
  2016. mutex_unlock(&ch->open_lock);
  2017. sh_mobile_lcdc_display_on(ch);
  2018. sh_mobile_lcdc_start(ch->lcdc);
  2019. }
  2020. return NOTIFY_OK;
  2021. }
  2022. /* -----------------------------------------------------------------------------
  2023. * Probe/remove and driver init/exit
  2024. */
  2025. static const struct fb_videomode default_720p = {
  2026. .name = "HDMI 720p",
  2027. .xres = 1280,
  2028. .yres = 720,
  2029. .left_margin = 220,
  2030. .right_margin = 110,
  2031. .hsync_len = 40,
  2032. .upper_margin = 20,
  2033. .lower_margin = 5,
  2034. .vsync_len = 5,
  2035. .pixclock = 13468,
  2036. .refresh = 60,
  2037. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  2038. };
  2039. static int sh_mobile_lcdc_remove(struct platform_device *pdev)
  2040. {
  2041. struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
  2042. unsigned int i;
  2043. fb_unregister_client(&priv->notifier);
  2044. for (i = 0; i < ARRAY_SIZE(priv->overlays); i++)
  2045. sh_mobile_lcdc_overlay_fb_unregister(&priv->overlays[i]);
  2046. for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
  2047. sh_mobile_lcdc_channel_fb_unregister(&priv->ch[i]);
  2048. sh_mobile_lcdc_stop(priv);
  2049. for (i = 0; i < ARRAY_SIZE(priv->overlays); i++) {
  2050. struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[i];
  2051. sh_mobile_lcdc_overlay_fb_cleanup(ovl);
  2052. if (ovl->fb_mem)
  2053. dma_free_coherent(&pdev->dev, ovl->fb_size,
  2054. ovl->fb_mem, ovl->dma_handle);
  2055. }
  2056. for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
  2057. struct sh_mobile_lcdc_chan *ch = &priv->ch[i];
  2058. if (ch->tx_dev) {
  2059. ch->tx_dev->lcdc = NULL;
  2060. module_put(ch->cfg->tx_dev->dev.driver->owner);
  2061. }
  2062. sh_mobile_lcdc_channel_fb_cleanup(ch);
  2063. if (ch->fb_mem)
  2064. dma_free_coherent(&pdev->dev, ch->fb_size,
  2065. ch->fb_mem, ch->dma_handle);
  2066. }
  2067. for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
  2068. struct sh_mobile_lcdc_chan *ch = &priv->ch[i];
  2069. if (ch->bl)
  2070. sh_mobile_lcdc_bl_remove(ch->bl);
  2071. mutex_destroy(&ch->open_lock);
  2072. }
  2073. if (priv->dot_clk) {
  2074. pm_runtime_disable(&pdev->dev);
  2075. clk_put(priv->dot_clk);
  2076. }
  2077. if (priv->base)
  2078. iounmap(priv->base);
  2079. if (priv->irq)
  2080. free_irq(priv->irq, priv);
  2081. kfree(priv);
  2082. return 0;
  2083. }
  2084. static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
  2085. {
  2086. int interface_type = ch->cfg->interface_type;
  2087. switch (interface_type) {
  2088. case RGB8:
  2089. case RGB9:
  2090. case RGB12A:
  2091. case RGB12B:
  2092. case RGB16:
  2093. case RGB18:
  2094. case RGB24:
  2095. case SYS8A:
  2096. case SYS8B:
  2097. case SYS8C:
  2098. case SYS8D:
  2099. case SYS9:
  2100. case SYS12:
  2101. case SYS16A:
  2102. case SYS16B:
  2103. case SYS16C:
  2104. case SYS18:
  2105. case SYS24:
  2106. break;
  2107. default:
  2108. return -EINVAL;
  2109. }
  2110. /* SUBLCD only supports SYS interface */
  2111. if (lcdc_chan_is_sublcd(ch)) {
  2112. if (!(interface_type & LDMT1R_IFM))
  2113. return -EINVAL;
  2114. interface_type &= ~LDMT1R_IFM;
  2115. }
  2116. ch->ldmt1r_value = interface_type;
  2117. return 0;
  2118. }
  2119. static int
  2120. sh_mobile_lcdc_overlay_init(struct sh_mobile_lcdc_overlay *ovl)
  2121. {
  2122. const struct sh_mobile_lcdc_format_info *format;
  2123. struct device *dev = ovl->channel->lcdc->dev;
  2124. int ret;
  2125. if (ovl->cfg->fourcc == 0)
  2126. return 0;
  2127. /* Validate the format. */
  2128. format = sh_mobile_format_info(ovl->cfg->fourcc);
  2129. if (format == NULL) {
  2130. dev_err(dev, "Invalid FOURCC %08x\n", ovl->cfg->fourcc);
  2131. return -EINVAL;
  2132. }
  2133. ovl->enabled = false;
  2134. ovl->mode = LCDC_OVERLAY_BLEND;
  2135. ovl->alpha = 255;
  2136. ovl->rop3 = 0;
  2137. ovl->pos_x = 0;
  2138. ovl->pos_y = 0;
  2139. /* The default Y virtual resolution is twice the panel size to allow for
  2140. * double-buffering.
  2141. */
  2142. ovl->format = format;
  2143. ovl->xres = ovl->cfg->max_xres;
  2144. ovl->xres_virtual = ovl->xres;
  2145. ovl->yres = ovl->cfg->max_yres;
  2146. ovl->yres_virtual = ovl->yres * 2;
  2147. if (!format->yuv)
  2148. ovl->pitch = ovl->xres_virtual * format->bpp / 8;
  2149. else
  2150. ovl->pitch = ovl->xres_virtual;
  2151. /* Allocate frame buffer memory. */
  2152. ovl->fb_size = ovl->cfg->max_xres * ovl->cfg->max_yres
  2153. * format->bpp / 8 * 2;
  2154. ovl->fb_mem = dma_alloc_coherent(dev, ovl->fb_size, &ovl->dma_handle,
  2155. GFP_KERNEL);
  2156. if (!ovl->fb_mem) {
  2157. dev_err(dev, "unable to allocate buffer\n");
  2158. return -ENOMEM;
  2159. }
  2160. ret = sh_mobile_lcdc_overlay_fb_init(ovl);
  2161. if (ret < 0)
  2162. return ret;
  2163. return 0;
  2164. }
  2165. static int
  2166. sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_chan *ch)
  2167. {
  2168. const struct sh_mobile_lcdc_format_info *format;
  2169. const struct sh_mobile_lcdc_chan_cfg *cfg = ch->cfg;
  2170. struct device *dev = ch->lcdc->dev;
  2171. const struct fb_videomode *max_mode;
  2172. const struct fb_videomode *mode;
  2173. unsigned int num_modes;
  2174. unsigned int max_size;
  2175. unsigned int i;
  2176. mutex_init(&ch->open_lock);
  2177. ch->notify = sh_mobile_lcdc_display_notify;
  2178. /* Validate the format. */
  2179. format = sh_mobile_format_info(cfg->fourcc);
  2180. if (format == NULL) {
  2181. dev_err(dev, "Invalid FOURCC %08x.\n", cfg->fourcc);
  2182. return -EINVAL;
  2183. }
  2184. /* Iterate through the modes to validate them and find the highest
  2185. * resolution.
  2186. */
  2187. max_mode = NULL;
  2188. max_size = 0;
  2189. for (i = 0, mode = cfg->lcd_modes; i < cfg->num_modes; i++, mode++) {
  2190. unsigned int size = mode->yres * mode->xres;
  2191. /* NV12/NV21 buffers must have even number of lines */
  2192. if ((cfg->fourcc == V4L2_PIX_FMT_NV12 ||
  2193. cfg->fourcc == V4L2_PIX_FMT_NV21) && (mode->yres & 0x1)) {
  2194. dev_err(dev, "yres must be multiple of 2 for "
  2195. "YCbCr420 mode.\n");
  2196. return -EINVAL;
  2197. }
  2198. if (size > max_size) {
  2199. max_mode = mode;
  2200. max_size = size;
  2201. }
  2202. }
  2203. if (!max_size)
  2204. max_size = MAX_XRES * MAX_YRES;
  2205. else
  2206. dev_dbg(dev, "Found largest videomode %ux%u\n",
  2207. max_mode->xres, max_mode->yres);
  2208. if (cfg->lcd_modes == NULL) {
  2209. mode = &default_720p;
  2210. num_modes = 1;
  2211. } else {
  2212. mode = cfg->lcd_modes;
  2213. num_modes = cfg->num_modes;
  2214. }
  2215. /* Use the first mode as default. The default Y virtual resolution is
  2216. * twice the panel size to allow for double-buffering.
  2217. */
  2218. ch->format = format;
  2219. ch->xres = mode->xres;
  2220. ch->xres_virtual = mode->xres;
  2221. ch->yres = mode->yres;
  2222. ch->yres_virtual = mode->yres * 2;
  2223. if (!format->yuv) {
  2224. ch->colorspace = V4L2_COLORSPACE_SRGB;
  2225. ch->pitch = ch->xres_virtual * format->bpp / 8;
  2226. } else {
  2227. ch->colorspace = V4L2_COLORSPACE_REC709;
  2228. ch->pitch = ch->xres_virtual;
  2229. }
  2230. ch->display.width = cfg->panel_cfg.width;
  2231. ch->display.height = cfg->panel_cfg.height;
  2232. ch->display.mode = *mode;
  2233. /* Allocate frame buffer memory. */
  2234. ch->fb_size = max_size * format->bpp / 8 * 2;
  2235. ch->fb_mem = dma_alloc_coherent(dev, ch->fb_size, &ch->dma_handle,
  2236. GFP_KERNEL);
  2237. if (ch->fb_mem == NULL) {
  2238. dev_err(dev, "unable to allocate buffer\n");
  2239. return -ENOMEM;
  2240. }
  2241. /* Initialize the transmitter device if present. */
  2242. if (cfg->tx_dev) {
  2243. if (!cfg->tx_dev->dev.driver ||
  2244. !try_module_get(cfg->tx_dev->dev.driver->owner)) {
  2245. dev_warn(dev, "unable to get transmitter device\n");
  2246. return -EINVAL;
  2247. }
  2248. ch->tx_dev = platform_get_drvdata(cfg->tx_dev);
  2249. ch->tx_dev->lcdc = ch;
  2250. ch->tx_dev->def_mode = *mode;
  2251. }
  2252. return sh_mobile_lcdc_channel_fb_init(ch, mode, num_modes);
  2253. }
  2254. static int sh_mobile_lcdc_probe(struct platform_device *pdev)
  2255. {
  2256. struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
  2257. struct sh_mobile_lcdc_priv *priv;
  2258. struct resource *res;
  2259. int num_channels;
  2260. int error;
  2261. int i;
  2262. if (!pdata) {
  2263. dev_err(&pdev->dev, "no platform data defined\n");
  2264. return -EINVAL;
  2265. }
  2266. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2267. i = platform_get_irq(pdev, 0);
  2268. if (!res || i < 0) {
  2269. dev_err(&pdev->dev, "cannot get platform resources\n");
  2270. return -ENOENT;
  2271. }
  2272. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  2273. if (!priv) {
  2274. dev_err(&pdev->dev, "cannot allocate device data\n");
  2275. return -ENOMEM;
  2276. }
  2277. priv->dev = &pdev->dev;
  2278. priv->meram_dev = pdata->meram_dev;
  2279. platform_set_drvdata(pdev, priv);
  2280. error = request_irq(i, sh_mobile_lcdc_irq, 0,
  2281. dev_name(&pdev->dev), priv);
  2282. if (error) {
  2283. dev_err(&pdev->dev, "unable to request irq\n");
  2284. goto err1;
  2285. }
  2286. priv->irq = i;
  2287. atomic_set(&priv->hw_usecnt, -1);
  2288. for (i = 0, num_channels = 0; i < ARRAY_SIZE(pdata->ch); i++) {
  2289. struct sh_mobile_lcdc_chan *ch = priv->ch + num_channels;
  2290. ch->lcdc = priv;
  2291. ch->cfg = &pdata->ch[i];
  2292. error = sh_mobile_lcdc_check_interface(ch);
  2293. if (error) {
  2294. dev_err(&pdev->dev, "unsupported interface type\n");
  2295. goto err1;
  2296. }
  2297. init_waitqueue_head(&ch->frame_end_wait);
  2298. init_completion(&ch->vsync_completion);
  2299. /* probe the backlight is there is one defined */
  2300. if (ch->cfg->bl_info.max_brightness)
  2301. ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
  2302. switch (pdata->ch[i].chan) {
  2303. case LCDC_CHAN_MAINLCD:
  2304. ch->enabled = LDCNT2R_ME;
  2305. ch->reg_offs = lcdc_offs_mainlcd;
  2306. num_channels++;
  2307. break;
  2308. case LCDC_CHAN_SUBLCD:
  2309. ch->enabled = LDCNT2R_SE;
  2310. ch->reg_offs = lcdc_offs_sublcd;
  2311. num_channels++;
  2312. break;
  2313. }
  2314. }
  2315. if (!num_channels) {
  2316. dev_err(&pdev->dev, "no channels defined\n");
  2317. error = -EINVAL;
  2318. goto err1;
  2319. }
  2320. /* for dual channel LCDC (MAIN + SUB) force shared format setting */
  2321. if (num_channels == 2)
  2322. priv->forced_fourcc = pdata->ch[0].fourcc;
  2323. priv->base = ioremap_nocache(res->start, resource_size(res));
  2324. if (!priv->base)
  2325. goto err1;
  2326. error = sh_mobile_lcdc_setup_clocks(priv, pdata->clock_source);
  2327. if (error) {
  2328. dev_err(&pdev->dev, "unable to setup clocks\n");
  2329. goto err1;
  2330. }
  2331. /* Enable runtime PM. */
  2332. pm_runtime_enable(&pdev->dev);
  2333. for (i = 0; i < num_channels; i++) {
  2334. struct sh_mobile_lcdc_chan *ch = &priv->ch[i];
  2335. error = sh_mobile_lcdc_channel_init(ch);
  2336. if (error)
  2337. goto err1;
  2338. }
  2339. for (i = 0; i < ARRAY_SIZE(pdata->overlays); i++) {
  2340. struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[i];
  2341. ovl->cfg = &pdata->overlays[i];
  2342. ovl->channel = &priv->ch[0];
  2343. error = sh_mobile_lcdc_overlay_init(ovl);
  2344. if (error)
  2345. goto err1;
  2346. }
  2347. error = sh_mobile_lcdc_start(priv);
  2348. if (error) {
  2349. dev_err(&pdev->dev, "unable to start hardware\n");
  2350. goto err1;
  2351. }
  2352. for (i = 0; i < num_channels; i++) {
  2353. struct sh_mobile_lcdc_chan *ch = priv->ch + i;
  2354. error = sh_mobile_lcdc_channel_fb_register(ch);
  2355. if (error)
  2356. goto err1;
  2357. }
  2358. for (i = 0; i < ARRAY_SIZE(pdata->overlays); i++) {
  2359. struct sh_mobile_lcdc_overlay *ovl = &priv->overlays[i];
  2360. error = sh_mobile_lcdc_overlay_fb_register(ovl);
  2361. if (error)
  2362. goto err1;
  2363. }
  2364. /* Failure ignored */
  2365. priv->notifier.notifier_call = sh_mobile_lcdc_notify;
  2366. fb_register_client(&priv->notifier);
  2367. return 0;
  2368. err1:
  2369. sh_mobile_lcdc_remove(pdev);
  2370. return error;
  2371. }
  2372. static struct platform_driver sh_mobile_lcdc_driver = {
  2373. .driver = {
  2374. .name = "sh_mobile_lcdc_fb",
  2375. .owner = THIS_MODULE,
  2376. .pm = &sh_mobile_lcdc_dev_pm_ops,
  2377. },
  2378. .probe = sh_mobile_lcdc_probe,
  2379. .remove = sh_mobile_lcdc_remove,
  2380. };
  2381. module_platform_driver(sh_mobile_lcdc_driver);
  2382. MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
  2383. MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
  2384. MODULE_LICENSE("GPL v2");