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