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