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