Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/omap2/dss/dispc.c |
| 3 | * |
| 4 | * Copyright (C) 2009 Nokia Corporation |
| 5 | * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com> |
| 6 | * |
| 7 | * Some code and ideas taken from drivers/video/omap/ driver |
| 8 | * by Imre Deak. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published by |
| 12 | * the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
| 22 | |
| 23 | #define DSS_SUBSYS_NAME "DISPC" |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/dma-mapping.h> |
| 27 | #include <linux/vmalloc.h> |
Paul Gortmaker | a8a3593 | 2011-07-10 13:20:26 -0400 | [diff] [blame] | 28 | #include <linux/export.h> |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 29 | #include <linux/clk.h> |
| 30 | #include <linux/io.h> |
| 31 | #include <linux/jiffies.h> |
| 32 | #include <linux/seq_file.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/workqueue.h> |
Tomi Valkeinen | ab83b14 | 2010-06-09 15:31:01 +0300 | [diff] [blame] | 35 | #include <linux/hardirq.h> |
Tomi Valkeinen | 24e6289 | 2011-05-23 11:51:18 +0300 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 37 | #include <linux/pm_runtime.h> |
Tomi Valkeinen | 33366d0 | 2012-09-28 13:54:35 +0300 | [diff] [blame] | 38 | #include <linux/sizes.h> |
Tomi Valkeinen | 0006fd6 | 2014-09-05 19:15:03 +0000 | [diff] [blame] | 39 | #include <linux/mfd/syscon.h> |
| 40 | #include <linux/regmap.h> |
| 41 | #include <linux/of.h> |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 42 | #include <linux/component.h> |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 43 | |
Peter Ujfalusi | 32043da | 2016-05-27 14:40:49 +0300 | [diff] [blame] | 44 | #include "omapdss.h" |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 45 | #include "dss.h" |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 46 | #include "dss_features.h" |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 47 | #include "dispc.h" |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 48 | |
| 49 | /* DISPC */ |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 50 | #define DISPC_SZ_REGS SZ_4K |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 51 | |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 52 | enum omap_burst_size { |
| 53 | BURST_SIZE_X2 = 0, |
| 54 | BURST_SIZE_X4 = 1, |
| 55 | BURST_SIZE_X8 = 2, |
| 56 | }; |
| 57 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 58 | #define REG_GET(idx, start, end) \ |
| 59 | FLD_GET(dispc_read_reg(idx), start, end) |
| 60 | |
| 61 | #define REG_FLD_MOD(idx, val, start, end) \ |
| 62 | dispc_write_reg(idx, FLD_MOD(dispc_read_reg(idx), val, start, end)) |
| 63 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 64 | struct dispc_features { |
| 65 | u8 sw_start; |
| 66 | u8 fp_start; |
| 67 | u8 bp_start; |
| 68 | u16 sw_max; |
| 69 | u16 vp_max; |
| 70 | u16 hp_max; |
Archit Taneja | 33b8992 | 2012-11-14 13:50:15 +0530 | [diff] [blame] | 71 | u8 mgr_width_start; |
| 72 | u8 mgr_height_start; |
| 73 | u16 mgr_width_max; |
| 74 | u16 mgr_height_max; |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 75 | unsigned long max_lcd_pclk; |
| 76 | unsigned long max_tv_pclk; |
Tomi Valkeinen | 0c6921d | 2012-10-19 15:43:29 +0300 | [diff] [blame] | 77 | int (*calc_scaling) (unsigned long pclk, unsigned long lclk, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 78 | const struct videomode *vm, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 79 | u16 width, u16 height, u16 out_width, u16 out_height, |
| 80 | enum omap_color_mode color_mode, bool *five_taps, |
| 81 | int *x_predecim, int *y_predecim, int *decim_x, int *decim_y, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 82 | u16 pos_x, unsigned long *core_clk, bool mem_to_mem); |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 83 | unsigned long (*calc_core_clk) (unsigned long pclk, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 84 | u16 width, u16 height, u16 out_width, u16 out_height, |
| 85 | bool mem_to_mem); |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 86 | u8 num_fifos; |
Tomi Valkeinen | 66a0f9e | 2012-08-22 16:57:02 +0300 | [diff] [blame] | 87 | |
| 88 | /* swap GFX & WB fifos */ |
| 89 | bool gfx_fifo_workaround:1; |
Tomi Valkeinen | cffa947 | 2012-11-08 10:01:33 +0200 | [diff] [blame] | 90 | |
| 91 | /* no DISPC_IRQ_FRAMEDONETV on this SoC */ |
| 92 | bool no_framedone_tv:1; |
Archit Taneja | d0df9a2 | 2013-03-26 19:15:25 +0530 | [diff] [blame] | 93 | |
| 94 | /* revert to the OMAP4 mechanism of DISPC Smart Standby operation */ |
| 95 | bool mstandby_workaround:1; |
Archit Taneja | 8bc6555 | 2013-12-17 16:40:21 +0530 | [diff] [blame] | 96 | |
| 97 | bool set_max_preload:1; |
Tomi Valkeinen | f2aee31 | 2015-04-10 12:48:34 +0300 | [diff] [blame] | 98 | |
| 99 | /* PIXEL_INC is not added to the last pixel of a line */ |
| 100 | bool last_pixel_inc_missing:1; |
Tomi Valkeinen | e5f8091 | 2015-10-21 13:08:59 +0300 | [diff] [blame] | 101 | |
| 102 | /* POL_FREQ has ALIGN bit */ |
| 103 | bool supports_sync_align:1; |
Tomi Valkeinen | 20efbc3 | 2015-11-04 17:10:44 +0200 | [diff] [blame] | 104 | |
| 105 | bool has_writeback:1; |
Tomi Valkeinen | 3a38ed53 | 2016-01-13 18:41:31 +0200 | [diff] [blame] | 106 | |
| 107 | bool supports_double_pixel:1; |
Tomi Valkeinen | b7536d6 | 2016-01-13 18:41:36 +0200 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * Field order for VENC is different than HDMI. We should handle this in |
| 111 | * some intelligent manner, but as the SoCs have either HDMI or VENC, |
| 112 | * never both, we can just use this flag for now. |
| 113 | */ |
| 114 | bool reverse_ilace_field_order:1; |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 115 | |
| 116 | bool has_gamma_table:1; |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 117 | |
| 118 | bool has_gamma_i734_bug:1; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 119 | }; |
| 120 | |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 121 | #define DISPC_MAX_NR_FIFOS 5 |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 122 | #define DISPC_MAX_CHANNEL_GAMMA 4 |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 123 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 124 | static struct { |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 125 | struct platform_device *pdev; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 126 | void __iomem *base; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 127 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 128 | int irq; |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 129 | irq_handler_t user_handler; |
| 130 | void *user_data; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 131 | |
Tomi Valkeinen | 7b3926b | 2013-03-06 15:54:11 +0200 | [diff] [blame] | 132 | unsigned long core_clk_rate; |
Tomi Valkeinen | 5391e87 | 2013-05-16 10:44:13 +0300 | [diff] [blame] | 133 | unsigned long tv_pclk_rate; |
Tomi Valkeinen | 7b3926b | 2013-03-06 15:54:11 +0200 | [diff] [blame] | 134 | |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 135 | u32 fifo_size[DISPC_MAX_NR_FIFOS]; |
| 136 | /* maps which plane is using a fifo. fifo-id -> plane-id */ |
| 137 | int fifo_assignment[DISPC_MAX_NR_FIFOS]; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 138 | |
Tomi Valkeinen | 49ea86f | 2011-06-01 15:54:06 +0300 | [diff] [blame] | 139 | bool ctx_valid; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 140 | u32 ctx[DISPC_SZ_REGS / sizeof(u32)]; |
Tomi Valkeinen | dfc0fd8 | 2009-12-17 14:35:21 +0200 | [diff] [blame] | 141 | |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 142 | u32 *gamma_table[DISPC_MAX_CHANNEL_GAMMA]; |
| 143 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 144 | const struct dispc_features *feat; |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 145 | |
| 146 | bool is_enabled; |
Tomi Valkeinen | 0006fd6 | 2014-09-05 19:15:03 +0000 | [diff] [blame] | 147 | |
| 148 | struct regmap *syscon_pol; |
| 149 | u32 syscon_pol_offset; |
Tomi Valkeinen | d49cd15 | 2014-11-10 12:23:00 +0200 | [diff] [blame] | 150 | |
| 151 | /* DISPC_CONTROL & DISPC_CONFIG lock*/ |
| 152 | spinlock_t control_lock; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 153 | } dispc; |
| 154 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 155 | enum omap_color_component { |
| 156 | /* used for all color formats for OMAP3 and earlier |
| 157 | * and for RGB and Y color component on OMAP4 |
| 158 | */ |
| 159 | DISPC_COLOR_COMPONENT_RGB_Y = 1 << 0, |
| 160 | /* used for UV component for |
| 161 | * OMAP_DSS_COLOR_YUV2, OMAP_DSS_COLOR_UYVY, OMAP_DSS_COLOR_NV12 |
| 162 | * color formats on OMAP4 |
| 163 | */ |
| 164 | DISPC_COLOR_COMPONENT_UV = 1 << 1, |
| 165 | }; |
| 166 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 167 | enum mgr_reg_fields { |
| 168 | DISPC_MGR_FLD_ENABLE, |
| 169 | DISPC_MGR_FLD_STNTFT, |
| 170 | DISPC_MGR_FLD_GO, |
| 171 | DISPC_MGR_FLD_TFTDATALINES, |
| 172 | DISPC_MGR_FLD_STALLMODE, |
| 173 | DISPC_MGR_FLD_TCKENABLE, |
| 174 | DISPC_MGR_FLD_TCKSELECTION, |
| 175 | DISPC_MGR_FLD_CPR, |
| 176 | DISPC_MGR_FLD_FIFOHANDCHECK, |
| 177 | /* used to maintain a count of the above fields */ |
| 178 | DISPC_MGR_FLD_NUM, |
| 179 | }; |
| 180 | |
Jyri Sarha | 5c348ba | 2014-04-11 16:25:06 +0300 | [diff] [blame] | 181 | struct dispc_reg_field { |
| 182 | u16 reg; |
| 183 | u8 high; |
| 184 | u8 low; |
| 185 | }; |
| 186 | |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 187 | struct dispc_gamma_desc { |
| 188 | u32 len; |
| 189 | u32 bits; |
| 190 | u16 reg; |
| 191 | bool has_index; |
| 192 | }; |
| 193 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 194 | static const struct { |
| 195 | const char *name; |
| 196 | u32 vsync_irq; |
| 197 | u32 framedone_irq; |
| 198 | u32 sync_lost_irq; |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 199 | struct dispc_gamma_desc gamma; |
Jyri Sarha | 5c348ba | 2014-04-11 16:25:06 +0300 | [diff] [blame] | 200 | struct dispc_reg_field reg_desc[DISPC_MGR_FLD_NUM]; |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 201 | } mgr_desc[] = { |
| 202 | [OMAP_DSS_CHANNEL_LCD] = { |
| 203 | .name = "LCD", |
| 204 | .vsync_irq = DISPC_IRQ_VSYNC, |
| 205 | .framedone_irq = DISPC_IRQ_FRAMEDONE, |
| 206 | .sync_lost_irq = DISPC_IRQ_SYNC_LOST, |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 207 | .gamma = { |
| 208 | .len = 256, |
| 209 | .bits = 8, |
| 210 | .reg = DISPC_GAMMA_TABLE0, |
| 211 | .has_index = true, |
| 212 | }, |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 213 | .reg_desc = { |
| 214 | [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 0, 0 }, |
| 215 | [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL, 3, 3 }, |
| 216 | [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 5, 5 }, |
| 217 | [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL, 9, 8 }, |
| 218 | [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL, 11, 11 }, |
| 219 | [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 10, 10 }, |
| 220 | [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 11, 11 }, |
| 221 | [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG, 15, 15 }, |
| 222 | [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 }, |
| 223 | }, |
| 224 | }, |
| 225 | [OMAP_DSS_CHANNEL_DIGIT] = { |
| 226 | .name = "DIGIT", |
| 227 | .vsync_irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN, |
Tomi Valkeinen | cffa947 | 2012-11-08 10:01:33 +0200 | [diff] [blame] | 228 | .framedone_irq = DISPC_IRQ_FRAMEDONETV, |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 229 | .sync_lost_irq = DISPC_IRQ_SYNC_LOST_DIGIT, |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 230 | .gamma = { |
| 231 | .len = 1024, |
| 232 | .bits = 10, |
| 233 | .reg = DISPC_GAMMA_TABLE2, |
| 234 | .has_index = false, |
| 235 | }, |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 236 | .reg_desc = { |
| 237 | [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL, 1, 1 }, |
| 238 | [DISPC_MGR_FLD_STNTFT] = { }, |
| 239 | [DISPC_MGR_FLD_GO] = { DISPC_CONTROL, 6, 6 }, |
| 240 | [DISPC_MGR_FLD_TFTDATALINES] = { }, |
| 241 | [DISPC_MGR_FLD_STALLMODE] = { }, |
| 242 | [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG, 12, 12 }, |
| 243 | [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG, 13, 13 }, |
| 244 | [DISPC_MGR_FLD_CPR] = { }, |
| 245 | [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG, 16, 16 }, |
| 246 | }, |
| 247 | }, |
| 248 | [OMAP_DSS_CHANNEL_LCD2] = { |
| 249 | .name = "LCD2", |
| 250 | .vsync_irq = DISPC_IRQ_VSYNC2, |
| 251 | .framedone_irq = DISPC_IRQ_FRAMEDONE2, |
| 252 | .sync_lost_irq = DISPC_IRQ_SYNC_LOST2, |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 253 | .gamma = { |
| 254 | .len = 256, |
| 255 | .bits = 8, |
| 256 | .reg = DISPC_GAMMA_TABLE1, |
| 257 | .has_index = true, |
| 258 | }, |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 259 | .reg_desc = { |
| 260 | [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL2, 0, 0 }, |
| 261 | [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL2, 3, 3 }, |
| 262 | [DISPC_MGR_FLD_GO] = { DISPC_CONTROL2, 5, 5 }, |
| 263 | [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL2, 9, 8 }, |
| 264 | [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL2, 11, 11 }, |
| 265 | [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG2, 10, 10 }, |
| 266 | [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG2, 11, 11 }, |
| 267 | [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG2, 15, 15 }, |
| 268 | [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG2, 16, 16 }, |
| 269 | }, |
| 270 | }, |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 271 | [OMAP_DSS_CHANNEL_LCD3] = { |
| 272 | .name = "LCD3", |
| 273 | .vsync_irq = DISPC_IRQ_VSYNC3, |
| 274 | .framedone_irq = DISPC_IRQ_FRAMEDONE3, |
| 275 | .sync_lost_irq = DISPC_IRQ_SYNC_LOST3, |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 276 | .gamma = { |
| 277 | .len = 256, |
| 278 | .bits = 8, |
| 279 | .reg = DISPC_GAMMA_TABLE3, |
| 280 | .has_index = true, |
| 281 | }, |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 282 | .reg_desc = { |
| 283 | [DISPC_MGR_FLD_ENABLE] = { DISPC_CONTROL3, 0, 0 }, |
| 284 | [DISPC_MGR_FLD_STNTFT] = { DISPC_CONTROL3, 3, 3 }, |
| 285 | [DISPC_MGR_FLD_GO] = { DISPC_CONTROL3, 5, 5 }, |
| 286 | [DISPC_MGR_FLD_TFTDATALINES] = { DISPC_CONTROL3, 9, 8 }, |
| 287 | [DISPC_MGR_FLD_STALLMODE] = { DISPC_CONTROL3, 11, 11 }, |
| 288 | [DISPC_MGR_FLD_TCKENABLE] = { DISPC_CONFIG3, 10, 10 }, |
| 289 | [DISPC_MGR_FLD_TCKSELECTION] = { DISPC_CONFIG3, 11, 11 }, |
| 290 | [DISPC_MGR_FLD_CPR] = { DISPC_CONFIG3, 15, 15 }, |
| 291 | [DISPC_MGR_FLD_FIFOHANDCHECK] = { DISPC_CONFIG3, 16, 16 }, |
| 292 | }, |
| 293 | }, |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 294 | }; |
| 295 | |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 296 | struct color_conv_coef { |
| 297 | int ry, rcr, rcb, gy, gcr, gcb, by, bcr, bcb; |
| 298 | int full_range; |
| 299 | }; |
| 300 | |
Tomi Valkeinen | 6590415 | 2015-11-04 17:10:57 +0200 | [diff] [blame] | 301 | static unsigned long dispc_fclk_rate(void); |
| 302 | static unsigned long dispc_core_clk_rate(void); |
| 303 | static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel); |
| 304 | static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel); |
| 305 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 306 | static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane); |
| 307 | static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 308 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 309 | static void dispc_clear_irqstatus(u32 mask); |
| 310 | static bool dispc_mgr_is_enabled(enum omap_channel channel); |
| 311 | static void dispc_clear_irqstatus(u32 mask); |
| 312 | |
Archit Taneja | 55978cc | 2011-05-06 11:45:51 +0530 | [diff] [blame] | 313 | static inline void dispc_write_reg(const u16 idx, u32 val) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 314 | { |
Archit Taneja | 55978cc | 2011-05-06 11:45:51 +0530 | [diff] [blame] | 315 | __raw_writel(val, dispc.base + idx); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 316 | } |
| 317 | |
Archit Taneja | 55978cc | 2011-05-06 11:45:51 +0530 | [diff] [blame] | 318 | static inline u32 dispc_read_reg(const u16 idx) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 319 | { |
Archit Taneja | 55978cc | 2011-05-06 11:45:51 +0530 | [diff] [blame] | 320 | return __raw_readl(dispc.base + idx); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 323 | static u32 mgr_fld_read(enum omap_channel channel, enum mgr_reg_fields regfld) |
| 324 | { |
Jyri Sarha | 5c348ba | 2014-04-11 16:25:06 +0300 | [diff] [blame] | 325 | const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld]; |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 326 | return REG_GET(rfld.reg, rfld.high, rfld.low); |
| 327 | } |
| 328 | |
| 329 | static void mgr_fld_write(enum omap_channel channel, |
| 330 | enum mgr_reg_fields regfld, int val) { |
Jyri Sarha | 5c348ba | 2014-04-11 16:25:06 +0300 | [diff] [blame] | 331 | const struct dispc_reg_field rfld = mgr_desc[channel].reg_desc[regfld]; |
Tomi Valkeinen | d49cd15 | 2014-11-10 12:23:00 +0200 | [diff] [blame] | 332 | const bool need_lock = rfld.reg == DISPC_CONTROL || rfld.reg == DISPC_CONFIG; |
| 333 | unsigned long flags; |
| 334 | |
| 335 | if (need_lock) |
| 336 | spin_lock_irqsave(&dispc.control_lock, flags); |
| 337 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 338 | REG_FLD_MOD(rfld.reg, val, rfld.high, rfld.low); |
Tomi Valkeinen | d49cd15 | 2014-11-10 12:23:00 +0200 | [diff] [blame] | 339 | |
| 340 | if (need_lock) |
| 341 | spin_unlock_irqrestore(&dispc.control_lock, flags); |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 342 | } |
| 343 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 344 | #define SR(reg) \ |
Archit Taneja | 55978cc | 2011-05-06 11:45:51 +0530 | [diff] [blame] | 345 | dispc.ctx[DISPC_##reg / sizeof(u32)] = dispc_read_reg(DISPC_##reg) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 346 | #define RR(reg) \ |
Archit Taneja | 55978cc | 2011-05-06 11:45:51 +0530 | [diff] [blame] | 347 | dispc_write_reg(DISPC_##reg, dispc.ctx[DISPC_##reg / sizeof(u32)]) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 348 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 349 | static void dispc_save_context(void) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 350 | { |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 351 | int i, j; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 352 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 353 | DSSDBG("dispc_save_context\n"); |
| 354 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 355 | SR(IRQENABLE); |
| 356 | SR(CONTROL); |
| 357 | SR(CONFIG); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 358 | SR(LINE_NUMBER); |
Archit Taneja | 11354dd | 2011-09-26 11:47:29 +0530 | [diff] [blame] | 359 | if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) || |
| 360 | dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 361 | SR(GLOBAL_ALPHA); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 362 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 363 | SR(CONTROL2); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 364 | SR(CONFIG2); |
| 365 | } |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 366 | if (dss_has_feature(FEAT_MGR_LCD3)) { |
| 367 | SR(CONTROL3); |
| 368 | SR(CONFIG3); |
| 369 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 370 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 371 | for (i = 0; i < dss_feat_get_num_mgrs(); i++) { |
| 372 | SR(DEFAULT_COLOR(i)); |
| 373 | SR(TRANS_COLOR(i)); |
| 374 | SR(SIZE_MGR(i)); |
| 375 | if (i == OMAP_DSS_CHANNEL_DIGIT) |
| 376 | continue; |
| 377 | SR(TIMING_H(i)); |
| 378 | SR(TIMING_V(i)); |
| 379 | SR(POL_FREQ(i)); |
| 380 | SR(DIVISORo(i)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 381 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 382 | SR(DATA_CYCLE1(i)); |
| 383 | SR(DATA_CYCLE2(i)); |
| 384 | SR(DATA_CYCLE3(i)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 385 | |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 386 | if (dss_has_feature(FEAT_CPR)) { |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 387 | SR(CPR_COEF_R(i)); |
| 388 | SR(CPR_COEF_G(i)); |
| 389 | SR(CPR_COEF_B(i)); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | for (i = 0; i < dss_feat_get_num_ovls(); i++) { |
| 394 | SR(OVL_BA0(i)); |
| 395 | SR(OVL_BA1(i)); |
| 396 | SR(OVL_POSITION(i)); |
| 397 | SR(OVL_SIZE(i)); |
| 398 | SR(OVL_ATTRIBUTES(i)); |
| 399 | SR(OVL_FIFO_THRESHOLD(i)); |
| 400 | SR(OVL_ROW_INC(i)); |
| 401 | SR(OVL_PIXEL_INC(i)); |
| 402 | if (dss_has_feature(FEAT_PRELOAD)) |
| 403 | SR(OVL_PRELOAD(i)); |
| 404 | if (i == OMAP_DSS_GFX) { |
| 405 | SR(OVL_WINDOW_SKIP(i)); |
| 406 | SR(OVL_TABLE_BA(i)); |
| 407 | continue; |
| 408 | } |
| 409 | SR(OVL_FIR(i)); |
| 410 | SR(OVL_PICTURE_SIZE(i)); |
| 411 | SR(OVL_ACCU0(i)); |
| 412 | SR(OVL_ACCU1(i)); |
| 413 | |
| 414 | for (j = 0; j < 8; j++) |
| 415 | SR(OVL_FIR_COEF_H(i, j)); |
| 416 | |
| 417 | for (j = 0; j < 8; j++) |
| 418 | SR(OVL_FIR_COEF_HV(i, j)); |
| 419 | |
| 420 | for (j = 0; j < 5; j++) |
| 421 | SR(OVL_CONV_COEF(i, j)); |
| 422 | |
| 423 | if (dss_has_feature(FEAT_FIR_COEF_V)) { |
| 424 | for (j = 0; j < 8; j++) |
| 425 | SR(OVL_FIR_COEF_V(i, j)); |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 426 | } |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 427 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 428 | if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) { |
| 429 | SR(OVL_BA0_UV(i)); |
| 430 | SR(OVL_BA1_UV(i)); |
| 431 | SR(OVL_FIR2(i)); |
| 432 | SR(OVL_ACCU2_0(i)); |
| 433 | SR(OVL_ACCU2_1(i)); |
| 434 | |
| 435 | for (j = 0; j < 8; j++) |
| 436 | SR(OVL_FIR_COEF_H2(i, j)); |
| 437 | |
| 438 | for (j = 0; j < 8; j++) |
| 439 | SR(OVL_FIR_COEF_HV2(i, j)); |
| 440 | |
| 441 | for (j = 0; j < 8; j++) |
| 442 | SR(OVL_FIR_COEF_V2(i, j)); |
| 443 | } |
| 444 | if (dss_has_feature(FEAT_ATTR2)) |
| 445 | SR(OVL_ATTRIBUTES2(i)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 446 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 447 | |
Murthy, Raghuveer | 0cf35df | 2011-03-03 09:28:00 -0600 | [diff] [blame] | 448 | if (dss_has_feature(FEAT_CORE_CLK_DIV)) |
| 449 | SR(DIVISOR); |
Tomi Valkeinen | 49ea86f | 2011-06-01 15:54:06 +0300 | [diff] [blame] | 450 | |
Tomi Valkeinen | 49ea86f | 2011-06-01 15:54:06 +0300 | [diff] [blame] | 451 | dispc.ctx_valid = true; |
| 452 | |
Tomi Valkeinen | 9229b51 | 2014-02-14 09:37:09 +0200 | [diff] [blame] | 453 | DSSDBG("context saved\n"); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 454 | } |
| 455 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 456 | static void dispc_restore_context(void) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 457 | { |
Tomi Valkeinen | 9229b51 | 2014-02-14 09:37:09 +0200 | [diff] [blame] | 458 | int i, j; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 459 | |
| 460 | DSSDBG("dispc_restore_context\n"); |
| 461 | |
Tomi Valkeinen | 49ea86f | 2011-06-01 15:54:06 +0300 | [diff] [blame] | 462 | if (!dispc.ctx_valid) |
| 463 | return; |
| 464 | |
Ville Syrjälä | 75c7d59 | 2010-03-05 01:13:11 +0200 | [diff] [blame] | 465 | /*RR(IRQENABLE);*/ |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 466 | /*RR(CONTROL);*/ |
| 467 | RR(CONFIG); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 468 | RR(LINE_NUMBER); |
Archit Taneja | 11354dd | 2011-09-26 11:47:29 +0530 | [diff] [blame] | 469 | if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) || |
| 470 | dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 471 | RR(GLOBAL_ALPHA); |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 472 | if (dss_has_feature(FEAT_MGR_LCD2)) |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 473 | RR(CONFIG2); |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 474 | if (dss_has_feature(FEAT_MGR_LCD3)) |
| 475 | RR(CONFIG3); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 476 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 477 | for (i = 0; i < dss_feat_get_num_mgrs(); i++) { |
| 478 | RR(DEFAULT_COLOR(i)); |
| 479 | RR(TRANS_COLOR(i)); |
| 480 | RR(SIZE_MGR(i)); |
| 481 | if (i == OMAP_DSS_CHANNEL_DIGIT) |
| 482 | continue; |
| 483 | RR(TIMING_H(i)); |
| 484 | RR(TIMING_V(i)); |
| 485 | RR(POL_FREQ(i)); |
| 486 | RR(DIVISORo(i)); |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 487 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 488 | RR(DATA_CYCLE1(i)); |
| 489 | RR(DATA_CYCLE2(i)); |
| 490 | RR(DATA_CYCLE3(i)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 491 | |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 492 | if (dss_has_feature(FEAT_CPR)) { |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 493 | RR(CPR_COEF_R(i)); |
| 494 | RR(CPR_COEF_G(i)); |
| 495 | RR(CPR_COEF_B(i)); |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 496 | } |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 497 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 498 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 499 | for (i = 0; i < dss_feat_get_num_ovls(); i++) { |
| 500 | RR(OVL_BA0(i)); |
| 501 | RR(OVL_BA1(i)); |
| 502 | RR(OVL_POSITION(i)); |
| 503 | RR(OVL_SIZE(i)); |
| 504 | RR(OVL_ATTRIBUTES(i)); |
| 505 | RR(OVL_FIFO_THRESHOLD(i)); |
| 506 | RR(OVL_ROW_INC(i)); |
| 507 | RR(OVL_PIXEL_INC(i)); |
| 508 | if (dss_has_feature(FEAT_PRELOAD)) |
| 509 | RR(OVL_PRELOAD(i)); |
| 510 | if (i == OMAP_DSS_GFX) { |
| 511 | RR(OVL_WINDOW_SKIP(i)); |
| 512 | RR(OVL_TABLE_BA(i)); |
| 513 | continue; |
| 514 | } |
| 515 | RR(OVL_FIR(i)); |
| 516 | RR(OVL_PICTURE_SIZE(i)); |
| 517 | RR(OVL_ACCU0(i)); |
| 518 | RR(OVL_ACCU1(i)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 519 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 520 | for (j = 0; j < 8; j++) |
| 521 | RR(OVL_FIR_COEF_H(i, j)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 522 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 523 | for (j = 0; j < 8; j++) |
| 524 | RR(OVL_FIR_COEF_HV(i, j)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 525 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 526 | for (j = 0; j < 5; j++) |
| 527 | RR(OVL_CONV_COEF(i, j)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 528 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 529 | if (dss_has_feature(FEAT_FIR_COEF_V)) { |
| 530 | for (j = 0; j < 8; j++) |
| 531 | RR(OVL_FIR_COEF_V(i, j)); |
| 532 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 533 | |
Archit Taneja | c6104b8 | 2011-08-05 19:06:02 +0530 | [diff] [blame] | 534 | if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) { |
| 535 | RR(OVL_BA0_UV(i)); |
| 536 | RR(OVL_BA1_UV(i)); |
| 537 | RR(OVL_FIR2(i)); |
| 538 | RR(OVL_ACCU2_0(i)); |
| 539 | RR(OVL_ACCU2_1(i)); |
| 540 | |
| 541 | for (j = 0; j < 8; j++) |
| 542 | RR(OVL_FIR_COEF_H2(i, j)); |
| 543 | |
| 544 | for (j = 0; j < 8; j++) |
| 545 | RR(OVL_FIR_COEF_HV2(i, j)); |
| 546 | |
| 547 | for (j = 0; j < 8; j++) |
| 548 | RR(OVL_FIR_COEF_V2(i, j)); |
| 549 | } |
| 550 | if (dss_has_feature(FEAT_ATTR2)) |
| 551 | RR(OVL_ATTRIBUTES2(i)); |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 552 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 553 | |
Murthy, Raghuveer | 0cf35df | 2011-03-03 09:28:00 -0600 | [diff] [blame] | 554 | if (dss_has_feature(FEAT_CORE_CLK_DIV)) |
| 555 | RR(DIVISOR); |
| 556 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 557 | /* enable last, because LCD & DIGIT enable are here */ |
| 558 | RR(CONTROL); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 559 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 560 | RR(CONTROL2); |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 561 | if (dss_has_feature(FEAT_MGR_LCD3)) |
| 562 | RR(CONTROL3); |
Ville Syrjälä | 75c7d59 | 2010-03-05 01:13:11 +0200 | [diff] [blame] | 563 | /* clear spurious SYNC_LOST_DIGIT interrupts */ |
Tomi Valkeinen | 4e0397c | 2012-10-10 15:13:14 +0300 | [diff] [blame] | 564 | dispc_clear_irqstatus(DISPC_IRQ_SYNC_LOST_DIGIT); |
Ville Syrjälä | 75c7d59 | 2010-03-05 01:13:11 +0200 | [diff] [blame] | 565 | |
| 566 | /* |
| 567 | * enable last so IRQs won't trigger before |
| 568 | * the context is fully restored |
| 569 | */ |
| 570 | RR(IRQENABLE); |
Tomi Valkeinen | 49ea86f | 2011-06-01 15:54:06 +0300 | [diff] [blame] | 571 | |
| 572 | DSSDBG("context restored\n"); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | #undef SR |
| 576 | #undef RR |
| 577 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 578 | int dispc_runtime_get(void) |
| 579 | { |
| 580 | int r; |
| 581 | |
| 582 | DSSDBG("dispc_runtime_get\n"); |
| 583 | |
| 584 | r = pm_runtime_get_sync(&dispc.pdev->dev); |
| 585 | WARN_ON(r < 0); |
| 586 | return r < 0 ? r : 0; |
| 587 | } |
| 588 | |
| 589 | void dispc_runtime_put(void) |
| 590 | { |
| 591 | int r; |
| 592 | |
| 593 | DSSDBG("dispc_runtime_put\n"); |
| 594 | |
Tomi Valkeinen | 0eaf9f5 | 2012-01-23 13:23:08 +0200 | [diff] [blame] | 595 | r = pm_runtime_put_sync(&dispc.pdev->dev); |
Tomi Valkeinen | 5be3aeb | 2012-06-27 16:37:18 +0300 | [diff] [blame] | 596 | WARN_ON(r < 0 && r != -ENOSYS); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 597 | } |
| 598 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 599 | static u32 dispc_mgr_get_vsync_irq(enum omap_channel channel) |
Tomi Valkeinen | 3dcec4d | 2011-11-07 15:50:09 +0200 | [diff] [blame] | 600 | { |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 601 | return mgr_desc[channel].vsync_irq; |
Tomi Valkeinen | 3dcec4d | 2011-11-07 15:50:09 +0200 | [diff] [blame] | 602 | } |
| 603 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 604 | static u32 dispc_mgr_get_framedone_irq(enum omap_channel channel) |
Tomi Valkeinen | 7d1365c | 2011-11-18 15:39:52 +0200 | [diff] [blame] | 605 | { |
Tomi Valkeinen | cffa947 | 2012-11-08 10:01:33 +0200 | [diff] [blame] | 606 | if (channel == OMAP_DSS_CHANNEL_DIGIT && dispc.feat->no_framedone_tv) |
| 607 | return 0; |
| 608 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 609 | return mgr_desc[channel].framedone_irq; |
Tomi Valkeinen | 7d1365c | 2011-11-18 15:39:52 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 612 | static u32 dispc_mgr_get_sync_lost_irq(enum omap_channel channel) |
Tomi Valkeinen | cb69920 | 2012-10-17 10:38:52 +0300 | [diff] [blame] | 613 | { |
| 614 | return mgr_desc[channel].sync_lost_irq; |
| 615 | } |
| 616 | |
Archit Taneja | 0b23e5b | 2012-09-22 12:39:33 +0530 | [diff] [blame] | 617 | u32 dispc_wb_get_framedone_irq(void) |
| 618 | { |
| 619 | return DISPC_IRQ_FRAMEDONEWB; |
| 620 | } |
| 621 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 622 | static void dispc_mgr_enable(enum omap_channel channel, bool enable) |
Laurent Pinchart | 03af815 | 2016-04-18 03:09:48 +0300 | [diff] [blame] | 623 | { |
| 624 | mgr_fld_write(channel, DISPC_MGR_FLD_ENABLE, enable); |
| 625 | /* flush posted write */ |
| 626 | mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE); |
| 627 | } |
Laurent Pinchart | 03af815 | 2016-04-18 03:09:48 +0300 | [diff] [blame] | 628 | |
| 629 | static bool dispc_mgr_is_enabled(enum omap_channel channel) |
| 630 | { |
| 631 | return !!mgr_fld_read(channel, DISPC_MGR_FLD_ENABLE); |
| 632 | } |
| 633 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 634 | static bool dispc_mgr_go_busy(enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 635 | { |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 636 | return mgr_fld_read(channel, DISPC_MGR_FLD_GO) == 1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 637 | } |
| 638 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 639 | static void dispc_mgr_go(enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 640 | { |
Luis de Bethencourt | 0bcfdba | 2015-10-15 13:29:38 +0100 | [diff] [blame] | 641 | WARN_ON(!dispc_mgr_is_enabled(channel)); |
Tomi Valkeinen | 3c91ee8 | 2012-10-19 15:06:07 +0300 | [diff] [blame] | 642 | WARN_ON(dispc_mgr_go_busy(channel)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 643 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 644 | DSSDBG("GO %s\n", mgr_desc[channel].name); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 645 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 646 | mgr_fld_write(channel, DISPC_MGR_FLD_GO, 1); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 647 | } |
| 648 | |
Archit Taneja | 0b23e5b | 2012-09-22 12:39:33 +0530 | [diff] [blame] | 649 | bool dispc_wb_go_busy(void) |
| 650 | { |
| 651 | return REG_GET(DISPC_CONTROL2, 6, 6) == 1; |
| 652 | } |
| 653 | |
| 654 | void dispc_wb_go(void) |
| 655 | { |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 656 | enum omap_plane_id plane = OMAP_DSS_WB; |
Archit Taneja | 0b23e5b | 2012-09-22 12:39:33 +0530 | [diff] [blame] | 657 | bool enable, go; |
| 658 | |
| 659 | enable = REG_GET(DISPC_OVL_ATTRIBUTES(plane), 0, 0) == 1; |
| 660 | |
| 661 | if (!enable) |
| 662 | return; |
| 663 | |
| 664 | go = REG_GET(DISPC_CONTROL2, 6, 6) == 1; |
| 665 | if (go) { |
| 666 | DSSERR("GO bit not down for WB\n"); |
| 667 | return; |
| 668 | } |
| 669 | |
| 670 | REG_FLD_MOD(DISPC_CONTROL2, 1, 6, 6); |
| 671 | } |
| 672 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 673 | static void dispc_ovl_write_firh_reg(enum omap_plane_id plane, int reg, |
| 674 | u32 value) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 675 | { |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 676 | dispc_write_reg(DISPC_OVL_FIR_COEF_H(plane, reg), value); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 677 | } |
| 678 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 679 | static void dispc_ovl_write_firhv_reg(enum omap_plane_id plane, int reg, |
| 680 | u32 value) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 681 | { |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 682 | dispc_write_reg(DISPC_OVL_FIR_COEF_HV(plane, reg), value); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 683 | } |
| 684 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 685 | static void dispc_ovl_write_firv_reg(enum omap_plane_id plane, int reg, |
| 686 | u32 value) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 687 | { |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 688 | dispc_write_reg(DISPC_OVL_FIR_COEF_V(plane, reg), value); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 689 | } |
| 690 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 691 | static void dispc_ovl_write_firh2_reg(enum omap_plane_id plane, int reg, |
| 692 | u32 value) |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 693 | { |
| 694 | BUG_ON(plane == OMAP_DSS_GFX); |
| 695 | |
| 696 | dispc_write_reg(DISPC_OVL_FIR_COEF_H2(plane, reg), value); |
| 697 | } |
| 698 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 699 | static void dispc_ovl_write_firhv2_reg(enum omap_plane_id plane, int reg, |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 700 | u32 value) |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 701 | { |
| 702 | BUG_ON(plane == OMAP_DSS_GFX); |
| 703 | |
| 704 | dispc_write_reg(DISPC_OVL_FIR_COEF_HV2(plane, reg), value); |
| 705 | } |
| 706 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 707 | static void dispc_ovl_write_firv2_reg(enum omap_plane_id plane, int reg, |
| 708 | u32 value) |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 709 | { |
| 710 | BUG_ON(plane == OMAP_DSS_GFX); |
| 711 | |
| 712 | dispc_write_reg(DISPC_OVL_FIR_COEF_V2(plane, reg), value); |
| 713 | } |
| 714 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 715 | static void dispc_ovl_set_scale_coef(enum omap_plane_id plane, int fir_hinc, |
Chandrabhanu Mahapatra | debd907 | 2011-12-19 14:03:44 +0530 | [diff] [blame] | 716 | int fir_vinc, int five_taps, |
| 717 | enum omap_color_component color_comp) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 718 | { |
Chandrabhanu Mahapatra | debd907 | 2011-12-19 14:03:44 +0530 | [diff] [blame] | 719 | const struct dispc_coef *h_coef, *v_coef; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 720 | int i; |
| 721 | |
Chandrabhanu Mahapatra | debd907 | 2011-12-19 14:03:44 +0530 | [diff] [blame] | 722 | h_coef = dispc_ovl_get_scale_coef(fir_hinc, true); |
| 723 | v_coef = dispc_ovl_get_scale_coef(fir_vinc, five_taps); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 724 | |
| 725 | for (i = 0; i < 8; i++) { |
| 726 | u32 h, hv; |
| 727 | |
Chandrabhanu Mahapatra | debd907 | 2011-12-19 14:03:44 +0530 | [diff] [blame] | 728 | h = FLD_VAL(h_coef[i].hc0_vc00, 7, 0) |
| 729 | | FLD_VAL(h_coef[i].hc1_vc0, 15, 8) |
| 730 | | FLD_VAL(h_coef[i].hc2_vc1, 23, 16) |
| 731 | | FLD_VAL(h_coef[i].hc3_vc2, 31, 24); |
| 732 | hv = FLD_VAL(h_coef[i].hc4_vc22, 7, 0) |
| 733 | | FLD_VAL(v_coef[i].hc1_vc0, 15, 8) |
| 734 | | FLD_VAL(v_coef[i].hc2_vc1, 23, 16) |
| 735 | | FLD_VAL(v_coef[i].hc3_vc2, 31, 24); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 736 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 737 | if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) { |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 738 | dispc_ovl_write_firh_reg(plane, i, h); |
| 739 | dispc_ovl_write_firhv_reg(plane, i, hv); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 740 | } else { |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 741 | dispc_ovl_write_firh2_reg(plane, i, h); |
| 742 | dispc_ovl_write_firhv2_reg(plane, i, hv); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 743 | } |
| 744 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 745 | } |
| 746 | |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 747 | if (five_taps) { |
| 748 | for (i = 0; i < 8; i++) { |
| 749 | u32 v; |
Chandrabhanu Mahapatra | debd907 | 2011-12-19 14:03:44 +0530 | [diff] [blame] | 750 | v = FLD_VAL(v_coef[i].hc0_vc00, 7, 0) |
| 751 | | FLD_VAL(v_coef[i].hc4_vc22, 15, 8); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 752 | if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 753 | dispc_ovl_write_firv_reg(plane, i, v); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 754 | else |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 755 | dispc_ovl_write_firv2_reg(plane, i, v); |
Grazvydas Ignotas | 66be8f6 | 2010-08-24 15:18:43 +0200 | [diff] [blame] | 756 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 760 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 761 | static void dispc_ovl_write_color_conv_coef(enum omap_plane_id plane, |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 762 | const struct color_conv_coef *ct) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 763 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 764 | #define CVAL(x, y) (FLD_VAL(x, 26, 16) | FLD_VAL(y, 10, 0)) |
| 765 | |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 766 | dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 0), CVAL(ct->rcr, ct->ry)); |
| 767 | dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 1), CVAL(ct->gy, ct->rcb)); |
| 768 | dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 2), CVAL(ct->gcb, ct->gcr)); |
| 769 | dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 3), CVAL(ct->bcr, ct->by)); |
| 770 | dispc_write_reg(DISPC_OVL_CONV_COEF(plane, 4), CVAL(0, ct->bcb)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 771 | |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 772 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), ct->full_range, 11, 11); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 773 | |
| 774 | #undef CVAL |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 775 | } |
| 776 | |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 777 | static void dispc_setup_color_conv_coef(void) |
| 778 | { |
| 779 | int i; |
| 780 | int num_ovl = dss_feat_get_num_ovls(); |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 781 | const struct color_conv_coef ctbl_bt601_5_ovl = { |
Tomi Valkeinen | 7d18bbe | 2015-11-04 17:10:52 +0200 | [diff] [blame] | 782 | /* YUV -> RGB */ |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 783 | 298, 409, 0, 298, -208, -100, 298, 0, 517, 0, |
| 784 | }; |
| 785 | const struct color_conv_coef ctbl_bt601_5_wb = { |
Tomi Valkeinen | 7d18bbe | 2015-11-04 17:10:52 +0200 | [diff] [blame] | 786 | /* RGB -> YUV */ |
| 787 | 66, 129, 25, 112, -94, -18, -38, -74, 112, 0, |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 788 | }; |
| 789 | |
| 790 | for (i = 1; i < num_ovl; i++) |
| 791 | dispc_ovl_write_color_conv_coef(i, &ctbl_bt601_5_ovl); |
| 792 | |
Tomi Valkeinen | 20efbc3 | 2015-11-04 17:10:44 +0200 | [diff] [blame] | 793 | if (dispc.feat->has_writeback) |
| 794 | dispc_ovl_write_color_conv_coef(OMAP_DSS_WB, &ctbl_bt601_5_wb); |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 795 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 796 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 797 | static void dispc_ovl_set_ba0(enum omap_plane_id plane, u32 paddr) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 798 | { |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 799 | dispc_write_reg(DISPC_OVL_BA0(plane), paddr); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 800 | } |
| 801 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 802 | static void dispc_ovl_set_ba1(enum omap_plane_id plane, u32 paddr) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 803 | { |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 804 | dispc_write_reg(DISPC_OVL_BA1(plane), paddr); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 805 | } |
| 806 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 807 | static void dispc_ovl_set_ba0_uv(enum omap_plane_id plane, u32 paddr) |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 808 | { |
| 809 | dispc_write_reg(DISPC_OVL_BA0_UV(plane), paddr); |
| 810 | } |
| 811 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 812 | static void dispc_ovl_set_ba1_uv(enum omap_plane_id plane, u32 paddr) |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 813 | { |
| 814 | dispc_write_reg(DISPC_OVL_BA1_UV(plane), paddr); |
| 815 | } |
| 816 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 817 | static void dispc_ovl_set_pos(enum omap_plane_id plane, |
Archit Taneja | d79db85 | 2012-09-22 12:30:17 +0530 | [diff] [blame] | 818 | enum omap_overlay_caps caps, int x, int y) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 819 | { |
Archit Taneja | d79db85 | 2012-09-22 12:30:17 +0530 | [diff] [blame] | 820 | u32 val; |
| 821 | |
| 822 | if ((caps & OMAP_DSS_OVL_CAP_POS) == 0) |
| 823 | return; |
| 824 | |
| 825 | val = FLD_VAL(y, 26, 16) | FLD_VAL(x, 10, 0); |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 826 | |
| 827 | dispc_write_reg(DISPC_OVL_POSITION(plane), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 828 | } |
| 829 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 830 | static void dispc_ovl_set_input_size(enum omap_plane_id plane, int width, |
Archit Taneja | 78b687f | 2012-09-21 14:51:49 +0530 | [diff] [blame] | 831 | int height) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 832 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 833 | u32 val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 834 | |
Archit Taneja | 36d87d9 | 2012-07-28 22:59:03 +0530 | [diff] [blame] | 835 | if (plane == OMAP_DSS_GFX || plane == OMAP_DSS_WB) |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 836 | dispc_write_reg(DISPC_OVL_SIZE(plane), val); |
| 837 | else |
| 838 | dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 839 | } |
| 840 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 841 | static void dispc_ovl_set_output_size(enum omap_plane_id plane, int width, |
Archit Taneja | 78b687f | 2012-09-21 14:51:49 +0530 | [diff] [blame] | 842 | int height) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 843 | { |
| 844 | u32 val; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 845 | |
| 846 | BUG_ON(plane == OMAP_DSS_GFX); |
| 847 | |
| 848 | val = FLD_VAL(height - 1, 26, 16) | FLD_VAL(width - 1, 10, 0); |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 849 | |
Archit Taneja | 36d87d9 | 2012-07-28 22:59:03 +0530 | [diff] [blame] | 850 | if (plane == OMAP_DSS_WB) |
| 851 | dispc_write_reg(DISPC_OVL_PICTURE_SIZE(plane), val); |
| 852 | else |
| 853 | dispc_write_reg(DISPC_OVL_SIZE(plane), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 854 | } |
| 855 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 856 | static void dispc_ovl_set_zorder(enum omap_plane_id plane, |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 857 | enum omap_overlay_caps caps, u8 zorder) |
Archit Taneja | 5412870 | 2011-09-08 11:29:17 +0530 | [diff] [blame] | 858 | { |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 859 | if ((caps & OMAP_DSS_OVL_CAP_ZORDER) == 0) |
Archit Taneja | 5412870 | 2011-09-08 11:29:17 +0530 | [diff] [blame] | 860 | return; |
| 861 | |
| 862 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), zorder, 27, 26); |
| 863 | } |
| 864 | |
| 865 | static void dispc_ovl_enable_zorder_planes(void) |
| 866 | { |
| 867 | int i; |
| 868 | |
| 869 | if (!dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) |
| 870 | return; |
| 871 | |
| 872 | for (i = 0; i < dss_feat_get_num_ovls(); i++) |
| 873 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(i), 1, 25, 25); |
| 874 | } |
| 875 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 876 | static void dispc_ovl_set_pre_mult_alpha(enum omap_plane_id plane, |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 877 | enum omap_overlay_caps caps, bool enable) |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 878 | { |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 879 | if ((caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0) |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 880 | return; |
| 881 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 882 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 28, 28); |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 885 | static void dispc_ovl_setup_global_alpha(enum omap_plane_id plane, |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 886 | enum omap_overlay_caps caps, u8 global_alpha) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 887 | { |
Archit Taneja | b8c095b | 2011-09-13 18:20:33 +0530 | [diff] [blame] | 888 | static const unsigned shifts[] = { 0, 8, 16, 24, }; |
Tomi Valkeinen | fe3cc9d | 2011-08-15 11:51:50 +0300 | [diff] [blame] | 889 | int shift; |
| 890 | |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 891 | if ((caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0) |
Rajkumar N | fd28a39 | 2010-11-04 12:28:42 +0100 | [diff] [blame] | 892 | return; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 893 | |
Tomi Valkeinen | fe3cc9d | 2011-08-15 11:51:50 +0300 | [diff] [blame] | 894 | shift = shifts[plane]; |
| 895 | REG_FLD_MOD(DISPC_GLOBAL_ALPHA, global_alpha, shift + 7, shift); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 896 | } |
| 897 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 898 | static void dispc_ovl_set_pix_inc(enum omap_plane_id plane, s32 inc) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 899 | { |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 900 | dispc_write_reg(DISPC_OVL_PIXEL_INC(plane), inc); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 901 | } |
| 902 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 903 | static void dispc_ovl_set_row_inc(enum omap_plane_id plane, s32 inc) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 904 | { |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 905 | dispc_write_reg(DISPC_OVL_ROW_INC(plane), inc); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 906 | } |
| 907 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 908 | static void dispc_ovl_set_color_mode(enum omap_plane_id plane, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 909 | enum omap_color_mode color_mode) |
| 910 | { |
| 911 | u32 m = 0; |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 912 | if (plane != OMAP_DSS_GFX) { |
| 913 | switch (color_mode) { |
| 914 | case OMAP_DSS_COLOR_NV12: |
| 915 | m = 0x0; break; |
Lajos Molnar | 08f3267 | 2012-02-21 19:36:30 +0530 | [diff] [blame] | 916 | case OMAP_DSS_COLOR_RGBX16: |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 917 | m = 0x1; break; |
| 918 | case OMAP_DSS_COLOR_RGBA16: |
| 919 | m = 0x2; break; |
Lajos Molnar | 08f3267 | 2012-02-21 19:36:30 +0530 | [diff] [blame] | 920 | case OMAP_DSS_COLOR_RGB12U: |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 921 | m = 0x4; break; |
| 922 | case OMAP_DSS_COLOR_ARGB16: |
| 923 | m = 0x5; break; |
| 924 | case OMAP_DSS_COLOR_RGB16: |
| 925 | m = 0x6; break; |
| 926 | case OMAP_DSS_COLOR_ARGB16_1555: |
| 927 | m = 0x7; break; |
| 928 | case OMAP_DSS_COLOR_RGB24U: |
| 929 | m = 0x8; break; |
| 930 | case OMAP_DSS_COLOR_RGB24P: |
| 931 | m = 0x9; break; |
| 932 | case OMAP_DSS_COLOR_YUV2: |
| 933 | m = 0xa; break; |
| 934 | case OMAP_DSS_COLOR_UYVY: |
| 935 | m = 0xb; break; |
| 936 | case OMAP_DSS_COLOR_ARGB32: |
| 937 | m = 0xc; break; |
| 938 | case OMAP_DSS_COLOR_RGBA32: |
| 939 | m = 0xd; break; |
| 940 | case OMAP_DSS_COLOR_RGBX32: |
| 941 | m = 0xe; break; |
| 942 | case OMAP_DSS_COLOR_XRGB16_1555: |
| 943 | m = 0xf; break; |
| 944 | default: |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 945 | BUG(); return; |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 946 | } |
| 947 | } else { |
| 948 | switch (color_mode) { |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 949 | case OMAP_DSS_COLOR_RGB12U: |
| 950 | m = 0x4; break; |
| 951 | case OMAP_DSS_COLOR_ARGB16: |
| 952 | m = 0x5; break; |
| 953 | case OMAP_DSS_COLOR_RGB16: |
| 954 | m = 0x6; break; |
| 955 | case OMAP_DSS_COLOR_ARGB16_1555: |
| 956 | m = 0x7; break; |
| 957 | case OMAP_DSS_COLOR_RGB24U: |
| 958 | m = 0x8; break; |
| 959 | case OMAP_DSS_COLOR_RGB24P: |
| 960 | m = 0x9; break; |
Lajos Molnar | 08f3267 | 2012-02-21 19:36:30 +0530 | [diff] [blame] | 961 | case OMAP_DSS_COLOR_RGBX16: |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 962 | m = 0xa; break; |
Lajos Molnar | 08f3267 | 2012-02-21 19:36:30 +0530 | [diff] [blame] | 963 | case OMAP_DSS_COLOR_RGBA16: |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 964 | m = 0xb; break; |
| 965 | case OMAP_DSS_COLOR_ARGB32: |
| 966 | m = 0xc; break; |
| 967 | case OMAP_DSS_COLOR_RGBA32: |
| 968 | m = 0xd; break; |
| 969 | case OMAP_DSS_COLOR_RGBX32: |
| 970 | m = 0xe; break; |
| 971 | case OMAP_DSS_COLOR_XRGB16_1555: |
| 972 | m = 0xf; break; |
| 973 | default: |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 974 | BUG(); return; |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 975 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 976 | } |
| 977 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 978 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), m, 4, 1); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 979 | } |
| 980 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 981 | static void dispc_ovl_configure_burst_type(enum omap_plane_id plane, |
Chandrabhanu Mahapatra | 65e006f | 2012-05-11 19:19:55 +0530 | [diff] [blame] | 982 | enum omap_dss_rotation_type rotation_type) |
| 983 | { |
| 984 | if (dss_has_feature(FEAT_BURST_2D) == 0) |
| 985 | return; |
| 986 | |
| 987 | if (rotation_type == OMAP_DSS_ROT_TILER) |
| 988 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 1, 29, 29); |
| 989 | else |
| 990 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), 0, 29, 29); |
| 991 | } |
| 992 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 993 | static void dispc_ovl_set_channel_out(enum omap_plane_id plane, |
| 994 | enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 995 | { |
| 996 | int shift; |
| 997 | u32 val; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 998 | int chan = 0, chan2 = 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 999 | |
| 1000 | switch (plane) { |
| 1001 | case OMAP_DSS_GFX: |
| 1002 | shift = 8; |
| 1003 | break; |
| 1004 | case OMAP_DSS_VIDEO1: |
| 1005 | case OMAP_DSS_VIDEO2: |
Archit Taneja | b8c095b | 2011-09-13 18:20:33 +0530 | [diff] [blame] | 1006 | case OMAP_DSS_VIDEO3: |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1007 | shift = 16; |
| 1008 | break; |
| 1009 | default: |
| 1010 | BUG(); |
| 1011 | return; |
| 1012 | } |
| 1013 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1014 | val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane)); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1015 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 1016 | switch (channel) { |
| 1017 | case OMAP_DSS_CHANNEL_LCD: |
| 1018 | chan = 0; |
| 1019 | chan2 = 0; |
| 1020 | break; |
| 1021 | case OMAP_DSS_CHANNEL_DIGIT: |
| 1022 | chan = 1; |
| 1023 | chan2 = 0; |
| 1024 | break; |
| 1025 | case OMAP_DSS_CHANNEL_LCD2: |
| 1026 | chan = 0; |
| 1027 | chan2 = 1; |
| 1028 | break; |
Chandrabhanu Mahapatra | e86d456 | 2012-06-29 10:43:13 +0530 | [diff] [blame] | 1029 | case OMAP_DSS_CHANNEL_LCD3: |
| 1030 | if (dss_has_feature(FEAT_MGR_LCD3)) { |
| 1031 | chan = 0; |
| 1032 | chan2 = 2; |
| 1033 | } else { |
| 1034 | BUG(); |
| 1035 | return; |
| 1036 | } |
| 1037 | break; |
Tomi Valkeinen | c2665c4 | 2015-11-04 17:10:47 +0200 | [diff] [blame] | 1038 | case OMAP_DSS_CHANNEL_WB: |
| 1039 | chan = 0; |
| 1040 | chan2 = 3; |
| 1041 | break; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1042 | default: |
| 1043 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 1044 | return; |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | val = FLD_MOD(val, chan, shift, shift); |
| 1048 | val = FLD_MOD(val, chan2, 31, 30); |
| 1049 | } else { |
| 1050 | val = FLD_MOD(val, channel, shift, shift); |
| 1051 | } |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1052 | dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1053 | } |
| 1054 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1055 | static enum omap_channel dispc_ovl_get_channel_out(enum omap_plane_id plane) |
Tomi Valkeinen | 2cc5d1a | 2011-11-03 17:03:44 +0200 | [diff] [blame] | 1056 | { |
| 1057 | int shift; |
| 1058 | u32 val; |
Tomi Valkeinen | 2cc5d1a | 2011-11-03 17:03:44 +0200 | [diff] [blame] | 1059 | |
| 1060 | switch (plane) { |
| 1061 | case OMAP_DSS_GFX: |
| 1062 | shift = 8; |
| 1063 | break; |
| 1064 | case OMAP_DSS_VIDEO1: |
| 1065 | case OMAP_DSS_VIDEO2: |
| 1066 | case OMAP_DSS_VIDEO3: |
| 1067 | shift = 16; |
| 1068 | break; |
| 1069 | default: |
| 1070 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 1071 | return 0; |
Tomi Valkeinen | 2cc5d1a | 2011-11-03 17:03:44 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane)); |
| 1075 | |
Tomi Valkeinen | d7df5ad | 2015-11-04 17:10:46 +0200 | [diff] [blame] | 1076 | if (FLD_GET(val, shift, shift) == 1) |
| 1077 | return OMAP_DSS_CHANNEL_DIGIT; |
Tomi Valkeinen | 2cc5d1a | 2011-11-03 17:03:44 +0200 | [diff] [blame] | 1078 | |
Tomi Valkeinen | d7df5ad | 2015-11-04 17:10:46 +0200 | [diff] [blame] | 1079 | if (!dss_has_feature(FEAT_MGR_LCD2)) |
| 1080 | return OMAP_DSS_CHANNEL_LCD; |
| 1081 | |
| 1082 | switch (FLD_GET(val, 31, 30)) { |
| 1083 | case 0: |
| 1084 | default: |
| 1085 | return OMAP_DSS_CHANNEL_LCD; |
| 1086 | case 1: |
| 1087 | return OMAP_DSS_CHANNEL_LCD2; |
| 1088 | case 2: |
| 1089 | return OMAP_DSS_CHANNEL_LCD3; |
Tomi Valkeinen | c2665c4 | 2015-11-04 17:10:47 +0200 | [diff] [blame] | 1090 | case 3: |
| 1091 | return OMAP_DSS_CHANNEL_WB; |
Tomi Valkeinen | d7df5ad | 2015-11-04 17:10:46 +0200 | [diff] [blame] | 1092 | } |
Tomi Valkeinen | 2cc5d1a | 2011-11-03 17:03:44 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
Archit Taneja | d9ac773 | 2012-09-22 12:38:19 +0530 | [diff] [blame] | 1095 | void dispc_wb_set_channel_in(enum dss_writeback_channel channel) |
| 1096 | { |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1097 | enum omap_plane_id plane = OMAP_DSS_WB; |
Archit Taneja | d9ac773 | 2012-09-22 12:38:19 +0530 | [diff] [blame] | 1098 | |
| 1099 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), channel, 18, 16); |
| 1100 | } |
| 1101 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1102 | static void dispc_ovl_set_burst_size(enum omap_plane_id plane, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1103 | enum omap_burst_size burst_size) |
| 1104 | { |
Archit Taneja | 8bbe09e | 2012-09-10 17:31:39 +0530 | [diff] [blame] | 1105 | static const unsigned shifts[] = { 6, 14, 14, 14, 14, }; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1106 | int shift; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1107 | |
Tomi Valkeinen | fe3cc9d | 2011-08-15 11:51:50 +0300 | [diff] [blame] | 1108 | shift = shifts[plane]; |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1109 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), burst_size, shift + 1, shift); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1110 | } |
| 1111 | |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1112 | static void dispc_configure_burst_sizes(void) |
| 1113 | { |
| 1114 | int i; |
| 1115 | const int burst_size = BURST_SIZE_X8; |
| 1116 | |
| 1117 | /* Configure burst size always to maximum size */ |
Tomi Valkeinen | 392faa0 | 2012-10-15 15:37:22 +0300 | [diff] [blame] | 1118 | for (i = 0; i < dss_feat_get_num_ovls(); ++i) |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1119 | dispc_ovl_set_burst_size(i, burst_size); |
Tomi Valkeinen | 5b354af | 2015-11-04 17:10:48 +0200 | [diff] [blame] | 1120 | if (dispc.feat->has_writeback) |
| 1121 | dispc_ovl_set_burst_size(OMAP_DSS_WB, burst_size); |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1122 | } |
| 1123 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1124 | static u32 dispc_ovl_get_burst_size(enum omap_plane_id plane) |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1125 | { |
| 1126 | unsigned unit = dss_feat_get_burst_size_unit(); |
| 1127 | /* burst multiplier is always x8 (see dispc_configure_burst_sizes()) */ |
| 1128 | return unit * 8; |
| 1129 | } |
| 1130 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1131 | static enum omap_color_mode dispc_ovl_get_color_modes(enum omap_plane_id plane) |
Tomi Valkeinen | c283400 | 2015-11-05 19:54:33 +0200 | [diff] [blame] | 1132 | { |
| 1133 | return dss_feat_get_supported_color_modes(plane); |
| 1134 | } |
Tomi Valkeinen | c283400 | 2015-11-05 19:54:33 +0200 | [diff] [blame] | 1135 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 1136 | static int dispc_get_num_ovls(void) |
Tomi Valkeinen | c283400 | 2015-11-05 19:54:33 +0200 | [diff] [blame] | 1137 | { |
| 1138 | return dss_feat_get_num_ovls(); |
| 1139 | } |
Tomi Valkeinen | c283400 | 2015-11-05 19:54:33 +0200 | [diff] [blame] | 1140 | |
Tomi Valkeinen | c64dca4 | 2011-11-04 18:14:20 +0200 | [diff] [blame] | 1141 | static void dispc_mgr_enable_cpr(enum omap_channel channel, bool enable) |
Tomi Valkeinen | 3c07cae | 2011-06-21 09:34:30 +0300 | [diff] [blame] | 1142 | { |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 1143 | if (channel == OMAP_DSS_CHANNEL_DIGIT) |
Tomi Valkeinen | 3c07cae | 2011-06-21 09:34:30 +0300 | [diff] [blame] | 1144 | return; |
| 1145 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 1146 | mgr_fld_write(channel, DISPC_MGR_FLD_CPR, enable); |
Tomi Valkeinen | 3c07cae | 2011-06-21 09:34:30 +0300 | [diff] [blame] | 1147 | } |
| 1148 | |
Tomi Valkeinen | c64dca4 | 2011-11-04 18:14:20 +0200 | [diff] [blame] | 1149 | static void dispc_mgr_set_cpr_coef(enum omap_channel channel, |
Tomi Valkeinen | a8f3fcd | 2012-10-03 09:09:11 +0200 | [diff] [blame] | 1150 | const struct omap_dss_cpr_coefs *coefs) |
Tomi Valkeinen | 3c07cae | 2011-06-21 09:34:30 +0300 | [diff] [blame] | 1151 | { |
| 1152 | u32 coef_r, coef_g, coef_b; |
| 1153 | |
Archit Taneja | dd88b7a | 2012-06-29 14:41:30 +0530 | [diff] [blame] | 1154 | if (!dss_mgr_is_lcd(channel)) |
Tomi Valkeinen | 3c07cae | 2011-06-21 09:34:30 +0300 | [diff] [blame] | 1155 | return; |
| 1156 | |
| 1157 | coef_r = FLD_VAL(coefs->rr, 31, 22) | FLD_VAL(coefs->rg, 20, 11) | |
| 1158 | FLD_VAL(coefs->rb, 9, 0); |
| 1159 | coef_g = FLD_VAL(coefs->gr, 31, 22) | FLD_VAL(coefs->gg, 20, 11) | |
| 1160 | FLD_VAL(coefs->gb, 9, 0); |
| 1161 | coef_b = FLD_VAL(coefs->br, 31, 22) | FLD_VAL(coefs->bg, 20, 11) | |
| 1162 | FLD_VAL(coefs->bb, 9, 0); |
| 1163 | |
| 1164 | dispc_write_reg(DISPC_CPR_COEF_R(channel), coef_r); |
| 1165 | dispc_write_reg(DISPC_CPR_COEF_G(channel), coef_g); |
| 1166 | dispc_write_reg(DISPC_CPR_COEF_B(channel), coef_b); |
| 1167 | } |
| 1168 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1169 | static void dispc_ovl_set_vid_color_conv(enum omap_plane_id plane, |
| 1170 | bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1171 | { |
| 1172 | u32 val; |
| 1173 | |
| 1174 | BUG_ON(plane == OMAP_DSS_GFX); |
| 1175 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1176 | val = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1177 | val = FLD_MOD(val, enable, 9, 9); |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1178 | dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1179 | } |
| 1180 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1181 | static void dispc_ovl_enable_replication(enum omap_plane_id plane, |
Archit Taneja | d79db85 | 2012-09-22 12:30:17 +0530 | [diff] [blame] | 1182 | enum omap_overlay_caps caps, bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1183 | { |
Archit Taneja | b8c095b | 2011-09-13 18:20:33 +0530 | [diff] [blame] | 1184 | static const unsigned shifts[] = { 5, 10, 10, 10 }; |
Tomi Valkeinen | fe3cc9d | 2011-08-15 11:51:50 +0300 | [diff] [blame] | 1185 | int shift; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1186 | |
Archit Taneja | d79db85 | 2012-09-22 12:30:17 +0530 | [diff] [blame] | 1187 | if ((caps & OMAP_DSS_OVL_CAP_REPLICATION) == 0) |
| 1188 | return; |
| 1189 | |
Tomi Valkeinen | fe3cc9d | 2011-08-15 11:51:50 +0300 | [diff] [blame] | 1190 | shift = shifts[plane]; |
| 1191 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, shift, shift); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 1194 | static void dispc_mgr_set_size(enum omap_channel channel, u16 width, |
Archit Taneja | e5c09e0 | 2012-04-16 12:53:42 +0530 | [diff] [blame] | 1195 | u16 height) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1196 | { |
| 1197 | u32 val; |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 1198 | |
Archit Taneja | 33b8992 | 2012-11-14 13:50:15 +0530 | [diff] [blame] | 1199 | val = FLD_VAL(height - 1, dispc.feat->mgr_height_start, 16) | |
| 1200 | FLD_VAL(width - 1, dispc.feat->mgr_width_start, 0); |
| 1201 | |
Archit Taneja | 702d144 | 2011-05-06 11:45:50 +0530 | [diff] [blame] | 1202 | dispc_write_reg(DISPC_SIZE_MGR(channel), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1203 | } |
| 1204 | |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 1205 | static void dispc_init_fifos(void) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1206 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1207 | u32 size; |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 1208 | int fifo; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1209 | u8 start, end; |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1210 | u32 unit; |
Tomi Valkeinen | 47fc469 | 2014-09-29 20:46:17 +0000 | [diff] [blame] | 1211 | int i; |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1212 | |
| 1213 | unit = dss_feat_get_buffer_size_unit(); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1214 | |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1215 | dss_feat_get_reg_field(FEAT_REG_FIFOSIZE, &start, &end); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1216 | |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 1217 | for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) { |
| 1218 | size = REG_GET(DISPC_OVL_FIFO_SIZE_STATUS(fifo), start, end); |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1219 | size *= unit; |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 1220 | dispc.fifo_size[fifo] = size; |
| 1221 | |
| 1222 | /* |
| 1223 | * By default fifos are mapped directly to overlays, fifo 0 to |
| 1224 | * ovl 0, fifo 1 to ovl 1, etc. |
| 1225 | */ |
| 1226 | dispc.fifo_assignment[fifo] = fifo; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1227 | } |
Tomi Valkeinen | 66a0f9e | 2012-08-22 16:57:02 +0300 | [diff] [blame] | 1228 | |
| 1229 | /* |
| 1230 | * The GFX fifo on OMAP4 is smaller than the other fifos. The small fifo |
| 1231 | * causes problems with certain use cases, like using the tiler in 2D |
| 1232 | * mode. The below hack swaps the fifos of GFX and WB planes, thus |
| 1233 | * giving GFX plane a larger fifo. WB but should work fine with a |
| 1234 | * smaller fifo. |
| 1235 | */ |
| 1236 | if (dispc.feat->gfx_fifo_workaround) { |
| 1237 | u32 v; |
| 1238 | |
| 1239 | v = dispc_read_reg(DISPC_GLOBAL_BUFFER); |
| 1240 | |
| 1241 | v = FLD_MOD(v, 4, 2, 0); /* GFX BUF top to WB */ |
| 1242 | v = FLD_MOD(v, 4, 5, 3); /* GFX BUF bottom to WB */ |
| 1243 | v = FLD_MOD(v, 0, 26, 24); /* WB BUF top to GFX */ |
| 1244 | v = FLD_MOD(v, 0, 29, 27); /* WB BUF bottom to GFX */ |
| 1245 | |
| 1246 | dispc_write_reg(DISPC_GLOBAL_BUFFER, v); |
| 1247 | |
| 1248 | dispc.fifo_assignment[OMAP_DSS_GFX] = OMAP_DSS_WB; |
| 1249 | dispc.fifo_assignment[OMAP_DSS_WB] = OMAP_DSS_GFX; |
| 1250 | } |
Tomi Valkeinen | 47fc469 | 2014-09-29 20:46:17 +0000 | [diff] [blame] | 1251 | |
| 1252 | /* |
| 1253 | * Setup default fifo thresholds. |
| 1254 | */ |
| 1255 | for (i = 0; i < dss_feat_get_num_ovls(); ++i) { |
| 1256 | u32 low, high; |
| 1257 | const bool use_fifomerge = false; |
| 1258 | const bool manual_update = false; |
| 1259 | |
| 1260 | dispc_ovl_compute_fifo_thresholds(i, &low, &high, |
| 1261 | use_fifomerge, manual_update); |
| 1262 | |
| 1263 | dispc_ovl_set_fifo_threshold(i, low, high); |
| 1264 | } |
Tomi Valkeinen | 65e116e | 2015-11-04 17:10:49 +0200 | [diff] [blame] | 1265 | |
| 1266 | if (dispc.feat->has_writeback) { |
| 1267 | u32 low, high; |
| 1268 | const bool use_fifomerge = false; |
| 1269 | const bool manual_update = false; |
| 1270 | |
| 1271 | dispc_ovl_compute_fifo_thresholds(OMAP_DSS_WB, &low, &high, |
| 1272 | use_fifomerge, manual_update); |
| 1273 | |
| 1274 | dispc_ovl_set_fifo_threshold(OMAP_DSS_WB, low, high); |
| 1275 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1276 | } |
| 1277 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1278 | static u32 dispc_ovl_get_fifo_size(enum omap_plane_id plane) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1279 | { |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 1280 | int fifo; |
| 1281 | u32 size = 0; |
| 1282 | |
| 1283 | for (fifo = 0; fifo < dispc.feat->num_fifos; ++fifo) { |
| 1284 | if (dispc.fifo_assignment[fifo] == plane) |
| 1285 | size += dispc.fifo_size[fifo]; |
| 1286 | } |
| 1287 | |
| 1288 | return size; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1289 | } |
| 1290 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1291 | void dispc_ovl_set_fifo_threshold(enum omap_plane_id plane, u32 low, |
| 1292 | u32 high) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1293 | { |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1294 | u8 hi_start, hi_end, lo_start, lo_end; |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 1295 | u32 unit; |
| 1296 | |
| 1297 | unit = dss_feat_get_buffer_size_unit(); |
| 1298 | |
| 1299 | WARN_ON(low % unit != 0); |
| 1300 | WARN_ON(high % unit != 0); |
| 1301 | |
| 1302 | low /= unit; |
| 1303 | high /= unit; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1304 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1305 | dss_feat_get_reg_field(FEAT_REG_FIFOHIGHTHRESHOLD, &hi_start, &hi_end); |
| 1306 | dss_feat_get_reg_field(FEAT_REG_FIFOLOWTHRESHOLD, &lo_start, &lo_end); |
| 1307 | |
Tomi Valkeinen | 3cb5d96 | 2012-01-13 13:14:57 +0200 | [diff] [blame] | 1308 | DSSDBG("fifo(%d) threshold (bytes), old %u/%u, new %u/%u\n", |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1309 | plane, |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1310 | REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane), |
Tomi Valkeinen | 3cb5d96 | 2012-01-13 13:14:57 +0200 | [diff] [blame] | 1311 | lo_start, lo_end) * unit, |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1312 | REG_GET(DISPC_OVL_FIFO_THRESHOLD(plane), |
Tomi Valkeinen | 3cb5d96 | 2012-01-13 13:14:57 +0200 | [diff] [blame] | 1313 | hi_start, hi_end) * unit, |
| 1314 | low * unit, high * unit); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1315 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1316 | dispc_write_reg(DISPC_OVL_FIFO_THRESHOLD(plane), |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1317 | FLD_VAL(high, hi_start, hi_end) | |
| 1318 | FLD_VAL(low, lo_start, lo_end)); |
Archit Taneja | 8bc6555 | 2013-12-17 16:40:21 +0530 | [diff] [blame] | 1319 | |
| 1320 | /* |
| 1321 | * configure the preload to the pipeline's high threhold, if HT it's too |
| 1322 | * large for the preload field, set the threshold to the maximum value |
| 1323 | * that can be held by the preload register |
| 1324 | */ |
| 1325 | if (dss_has_feature(FEAT_PRELOAD) && dispc.feat->set_max_preload && |
| 1326 | plane != OMAP_DSS_WB) |
| 1327 | dispc_write_reg(DISPC_OVL_PRELOAD(plane), min(high, 0xfffu)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | void dispc_enable_fifomerge(bool enable) |
| 1331 | { |
Tomi Valkeinen | e6b0f88 | 2012-01-13 13:24:04 +0200 | [diff] [blame] | 1332 | if (!dss_has_feature(FEAT_FIFO_MERGE)) { |
| 1333 | WARN_ON(enable); |
| 1334 | return; |
| 1335 | } |
| 1336 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1337 | DSSDBG("FIFO merge %s\n", enable ? "enabled" : "disabled"); |
| 1338 | REG_FLD_MOD(DISPC_CONFIG, enable ? 1 : 0, 14, 14); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1341 | void dispc_ovl_compute_fifo_thresholds(enum omap_plane_id plane, |
Tomi Valkeinen | 3568f2a | 2012-05-15 15:31:01 +0300 | [diff] [blame] | 1342 | u32 *fifo_low, u32 *fifo_high, bool use_fifomerge, |
| 1343 | bool manual_update) |
Tomi Valkeinen | 83fa2f2 | 2012-01-13 13:17:01 +0200 | [diff] [blame] | 1344 | { |
| 1345 | /* |
| 1346 | * All sizes are in bytes. Both the buffer and burst are made of |
| 1347 | * buffer_units, and the fifo thresholds must be buffer_unit aligned. |
| 1348 | */ |
| 1349 | |
| 1350 | unsigned buf_unit = dss_feat_get_buffer_size_unit(); |
Tomi Valkeinen | e0e405b | 2012-01-13 13:18:11 +0200 | [diff] [blame] | 1351 | unsigned ovl_fifo_size, total_fifo_size, burst_size; |
| 1352 | int i; |
Tomi Valkeinen | 83fa2f2 | 2012-01-13 13:17:01 +0200 | [diff] [blame] | 1353 | |
| 1354 | burst_size = dispc_ovl_get_burst_size(plane); |
Tomi Valkeinen | e0e405b | 2012-01-13 13:18:11 +0200 | [diff] [blame] | 1355 | ovl_fifo_size = dispc_ovl_get_fifo_size(plane); |
Tomi Valkeinen | 83fa2f2 | 2012-01-13 13:17:01 +0200 | [diff] [blame] | 1356 | |
Tomi Valkeinen | e0e405b | 2012-01-13 13:18:11 +0200 | [diff] [blame] | 1357 | if (use_fifomerge) { |
| 1358 | total_fifo_size = 0; |
Tomi Valkeinen | 392faa0 | 2012-10-15 15:37:22 +0300 | [diff] [blame] | 1359 | for (i = 0; i < dss_feat_get_num_ovls(); ++i) |
Tomi Valkeinen | e0e405b | 2012-01-13 13:18:11 +0200 | [diff] [blame] | 1360 | total_fifo_size += dispc_ovl_get_fifo_size(i); |
| 1361 | } else { |
| 1362 | total_fifo_size = ovl_fifo_size; |
| 1363 | } |
| 1364 | |
| 1365 | /* |
| 1366 | * We use the same low threshold for both fifomerge and non-fifomerge |
| 1367 | * cases, but for fifomerge we calculate the high threshold using the |
| 1368 | * combined fifo size |
| 1369 | */ |
| 1370 | |
Tomi Valkeinen | 3568f2a | 2012-05-15 15:31:01 +0300 | [diff] [blame] | 1371 | if (manual_update && dss_has_feature(FEAT_OMAP3_DSI_FIFO_BUG)) { |
Tomi Valkeinen | e0e405b | 2012-01-13 13:18:11 +0200 | [diff] [blame] | 1372 | *fifo_low = ovl_fifo_size - burst_size * 2; |
| 1373 | *fifo_high = total_fifo_size - burst_size; |
Archit Taneja | 8bbe09e | 2012-09-10 17:31:39 +0530 | [diff] [blame] | 1374 | } else if (plane == OMAP_DSS_WB) { |
| 1375 | /* |
| 1376 | * Most optimal configuration for writeback is to push out data |
| 1377 | * to the interconnect the moment writeback pushes enough pixels |
| 1378 | * in the FIFO to form a burst |
| 1379 | */ |
| 1380 | *fifo_low = 0; |
| 1381 | *fifo_high = burst_size; |
Tomi Valkeinen | e0e405b | 2012-01-13 13:18:11 +0200 | [diff] [blame] | 1382 | } else { |
| 1383 | *fifo_low = ovl_fifo_size - burst_size; |
| 1384 | *fifo_high = total_fifo_size - buf_unit; |
| 1385 | } |
Tomi Valkeinen | 83fa2f2 | 2012-01-13 13:17:01 +0200 | [diff] [blame] | 1386 | } |
| 1387 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1388 | static void dispc_ovl_set_mflag(enum omap_plane_id plane, bool enable) |
Tomi Valkeinen | c64aa3a | 2014-09-29 20:46:18 +0000 | [diff] [blame] | 1389 | { |
| 1390 | int bit; |
| 1391 | |
| 1392 | if (plane == OMAP_DSS_GFX) |
| 1393 | bit = 14; |
| 1394 | else |
| 1395 | bit = 23; |
| 1396 | |
| 1397 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable, bit, bit); |
| 1398 | } |
| 1399 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1400 | static void dispc_ovl_set_mflag_threshold(enum omap_plane_id plane, |
Tomi Valkeinen | c64aa3a | 2014-09-29 20:46:18 +0000 | [diff] [blame] | 1401 | int low, int high) |
| 1402 | { |
| 1403 | dispc_write_reg(DISPC_OVL_MFLAG_THRESHOLD(plane), |
| 1404 | FLD_VAL(high, 31, 16) | FLD_VAL(low, 15, 0)); |
| 1405 | } |
| 1406 | |
| 1407 | static void dispc_init_mflag(void) |
| 1408 | { |
| 1409 | int i; |
| 1410 | |
Tomi Valkeinen | fe59e5c | 2014-11-19 12:50:16 +0200 | [diff] [blame] | 1411 | /* |
| 1412 | * HACK: NV12 color format and MFLAG seem to have problems working |
| 1413 | * together: using two displays, and having an NV12 overlay on one of |
| 1414 | * the displays will cause underflows/synclosts when MFLAG_CTRL=2. |
| 1415 | * Changing MFLAG thresholds and PRELOAD to certain values seem to |
| 1416 | * remove the errors, but there doesn't seem to be a clear logic on |
| 1417 | * which values work and which not. |
| 1418 | * |
| 1419 | * As a work-around, set force MFLAG to always on. |
| 1420 | */ |
Tomi Valkeinen | c64aa3a | 2014-09-29 20:46:18 +0000 | [diff] [blame] | 1421 | dispc_write_reg(DISPC_GLOBAL_MFLAG_ATTRIBUTE, |
Tomi Valkeinen | fe59e5c | 2014-11-19 12:50:16 +0200 | [diff] [blame] | 1422 | (1 << 0) | /* MFLAG_CTRL = force always on */ |
Tomi Valkeinen | c64aa3a | 2014-09-29 20:46:18 +0000 | [diff] [blame] | 1423 | (0 << 2)); /* MFLAG_START = disable */ |
| 1424 | |
| 1425 | for (i = 0; i < dss_feat_get_num_ovls(); ++i) { |
| 1426 | u32 size = dispc_ovl_get_fifo_size(i); |
| 1427 | u32 unit = dss_feat_get_buffer_size_unit(); |
| 1428 | u32 low, high; |
| 1429 | |
| 1430 | dispc_ovl_set_mflag(i, true); |
| 1431 | |
| 1432 | /* |
| 1433 | * Simulation team suggests below thesholds: |
| 1434 | * HT = fifosize * 5 / 8; |
| 1435 | * LT = fifosize * 4 / 8; |
| 1436 | */ |
| 1437 | |
| 1438 | low = size * 4 / 8 / unit; |
| 1439 | high = size * 5 / 8 / unit; |
| 1440 | |
| 1441 | dispc_ovl_set_mflag_threshold(i, low, high); |
| 1442 | } |
Tomi Valkeinen | ecb0b36 | 2015-11-04 17:10:50 +0200 | [diff] [blame] | 1443 | |
| 1444 | if (dispc.feat->has_writeback) { |
| 1445 | u32 size = dispc_ovl_get_fifo_size(OMAP_DSS_WB); |
| 1446 | u32 unit = dss_feat_get_buffer_size_unit(); |
| 1447 | u32 low, high; |
| 1448 | |
| 1449 | dispc_ovl_set_mflag(OMAP_DSS_WB, true); |
| 1450 | |
| 1451 | /* |
| 1452 | * Simulation team suggests below thesholds: |
| 1453 | * HT = fifosize * 5 / 8; |
| 1454 | * LT = fifosize * 4 / 8; |
| 1455 | */ |
| 1456 | |
| 1457 | low = size * 4 / 8 / unit; |
| 1458 | high = size * 5 / 8 / unit; |
| 1459 | |
| 1460 | dispc_ovl_set_mflag_threshold(OMAP_DSS_WB, low, high); |
| 1461 | } |
Tomi Valkeinen | c64aa3a | 2014-09-29 20:46:18 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1464 | static void dispc_ovl_set_fir(enum omap_plane_id plane, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1465 | int hinc, int vinc, |
| 1466 | enum omap_color_component color_comp) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1467 | { |
| 1468 | u32 val; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1469 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1470 | if (color_comp == DISPC_COLOR_COMPONENT_RGB_Y) { |
| 1471 | u8 hinc_start, hinc_end, vinc_start, vinc_end; |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1472 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1473 | dss_feat_get_reg_field(FEAT_REG_FIRHINC, |
| 1474 | &hinc_start, &hinc_end); |
| 1475 | dss_feat_get_reg_field(FEAT_REG_FIRVINC, |
| 1476 | &vinc_start, &vinc_end); |
| 1477 | val = FLD_VAL(vinc, vinc_start, vinc_end) | |
| 1478 | FLD_VAL(hinc, hinc_start, hinc_end); |
Archit Taneja | a0acb55 | 2010-09-15 19:20:00 +0530 | [diff] [blame] | 1479 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1480 | dispc_write_reg(DISPC_OVL_FIR(plane), val); |
| 1481 | } else { |
| 1482 | val = FLD_VAL(vinc, 28, 16) | FLD_VAL(hinc, 12, 0); |
| 1483 | dispc_write_reg(DISPC_OVL_FIR2(plane), val); |
| 1484 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1485 | } |
| 1486 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1487 | static void dispc_ovl_set_vid_accu0(enum omap_plane_id plane, int haccu, |
| 1488 | int vaccu) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1489 | { |
| 1490 | u32 val; |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1491 | u8 hor_start, hor_end, vert_start, vert_end; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1492 | |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1493 | dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end); |
| 1494 | dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end); |
| 1495 | |
| 1496 | val = FLD_VAL(vaccu, vert_start, vert_end) | |
| 1497 | FLD_VAL(haccu, hor_start, hor_end); |
| 1498 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1499 | dispc_write_reg(DISPC_OVL_ACCU0(plane), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1500 | } |
| 1501 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1502 | static void dispc_ovl_set_vid_accu1(enum omap_plane_id plane, int haccu, |
| 1503 | int vaccu) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1504 | { |
| 1505 | u32 val; |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1506 | u8 hor_start, hor_end, vert_start, vert_end; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1507 | |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1508 | dss_feat_get_reg_field(FEAT_REG_HORIZONTALACCU, &hor_start, &hor_end); |
| 1509 | dss_feat_get_reg_field(FEAT_REG_VERTICALACCU, &vert_start, &vert_end); |
| 1510 | |
| 1511 | val = FLD_VAL(vaccu, vert_start, vert_end) | |
| 1512 | FLD_VAL(haccu, hor_start, hor_end); |
| 1513 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1514 | dispc_write_reg(DISPC_OVL_ACCU1(plane), val); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1515 | } |
| 1516 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1517 | static void dispc_ovl_set_vid_accu2_0(enum omap_plane_id plane, int haccu, |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1518 | int vaccu) |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 1519 | { |
| 1520 | u32 val; |
| 1521 | |
| 1522 | val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0); |
| 1523 | dispc_write_reg(DISPC_OVL_ACCU2_0(plane), val); |
| 1524 | } |
| 1525 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1526 | static void dispc_ovl_set_vid_accu2_1(enum omap_plane_id plane, int haccu, |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1527 | int vaccu) |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 1528 | { |
| 1529 | u32 val; |
| 1530 | |
| 1531 | val = FLD_VAL(vaccu, 26, 16) | FLD_VAL(haccu, 10, 0); |
| 1532 | dispc_write_reg(DISPC_OVL_ACCU2_1(plane), val); |
| 1533 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1534 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1535 | static void dispc_ovl_set_scale_param(enum omap_plane_id plane, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1536 | u16 orig_width, u16 orig_height, |
| 1537 | u16 out_width, u16 out_height, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1538 | bool five_taps, u8 rotation, |
| 1539 | enum omap_color_component color_comp) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1540 | { |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1541 | int fir_hinc, fir_vinc; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1542 | |
Amber Jain | ed14a3c | 2011-05-19 19:47:51 +0530 | [diff] [blame] | 1543 | fir_hinc = 1024 * orig_width / out_width; |
| 1544 | fir_vinc = 1024 * orig_height / out_height; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1545 | |
Chandrabhanu Mahapatra | debd907 | 2011-12-19 14:03:44 +0530 | [diff] [blame] | 1546 | dispc_ovl_set_scale_coef(plane, fir_hinc, fir_vinc, five_taps, |
| 1547 | color_comp); |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1548 | dispc_ovl_set_fir(plane, fir_hinc, fir_vinc, color_comp); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1549 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1550 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1551 | static void dispc_ovl_set_accu_uv(enum omap_plane_id plane, |
Chandrabhanu Mahapatra | 05dd0f5 | 2012-05-15 12:22:34 +0530 | [diff] [blame] | 1552 | u16 orig_width, u16 orig_height, u16 out_width, u16 out_height, |
| 1553 | bool ilace, enum omap_color_mode color_mode, u8 rotation) |
| 1554 | { |
| 1555 | int h_accu2_0, h_accu2_1; |
| 1556 | int v_accu2_0, v_accu2_1; |
| 1557 | int chroma_hinc, chroma_vinc; |
| 1558 | int idx; |
| 1559 | |
| 1560 | struct accu { |
| 1561 | s8 h0_m, h0_n; |
| 1562 | s8 h1_m, h1_n; |
| 1563 | s8 v0_m, v0_n; |
| 1564 | s8 v1_m, v1_n; |
| 1565 | }; |
| 1566 | |
| 1567 | const struct accu *accu_table; |
| 1568 | const struct accu *accu_val; |
| 1569 | |
| 1570 | static const struct accu accu_nv12[4] = { |
| 1571 | { 0, 1, 0, 1 , -1, 2, 0, 1 }, |
| 1572 | { 1, 2, -3, 4 , 0, 1, 0, 1 }, |
| 1573 | { -1, 1, 0, 1 , -1, 2, 0, 1 }, |
| 1574 | { -1, 2, -1, 2 , -1, 1, 0, 1 }, |
| 1575 | }; |
| 1576 | |
| 1577 | static const struct accu accu_nv12_ilace[4] = { |
| 1578 | { 0, 1, 0, 1 , -3, 4, -1, 4 }, |
| 1579 | { -1, 4, -3, 4 , 0, 1, 0, 1 }, |
| 1580 | { -1, 1, 0, 1 , -1, 4, -3, 4 }, |
| 1581 | { -3, 4, -3, 4 , -1, 1, 0, 1 }, |
| 1582 | }; |
| 1583 | |
| 1584 | static const struct accu accu_yuv[4] = { |
| 1585 | { 0, 1, 0, 1, 0, 1, 0, 1 }, |
| 1586 | { 0, 1, 0, 1, 0, 1, 0, 1 }, |
| 1587 | { -1, 1, 0, 1, 0, 1, 0, 1 }, |
| 1588 | { 0, 1, 0, 1, -1, 1, 0, 1 }, |
| 1589 | }; |
| 1590 | |
| 1591 | switch (rotation) { |
| 1592 | case OMAP_DSS_ROT_0: |
| 1593 | idx = 0; |
| 1594 | break; |
| 1595 | case OMAP_DSS_ROT_90: |
| 1596 | idx = 1; |
| 1597 | break; |
| 1598 | case OMAP_DSS_ROT_180: |
| 1599 | idx = 2; |
| 1600 | break; |
| 1601 | case OMAP_DSS_ROT_270: |
| 1602 | idx = 3; |
| 1603 | break; |
| 1604 | default: |
| 1605 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 1606 | return; |
Chandrabhanu Mahapatra | 05dd0f5 | 2012-05-15 12:22:34 +0530 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | switch (color_mode) { |
| 1610 | case OMAP_DSS_COLOR_NV12: |
| 1611 | if (ilace) |
| 1612 | accu_table = accu_nv12_ilace; |
| 1613 | else |
| 1614 | accu_table = accu_nv12; |
| 1615 | break; |
| 1616 | case OMAP_DSS_COLOR_YUV2: |
| 1617 | case OMAP_DSS_COLOR_UYVY: |
| 1618 | accu_table = accu_yuv; |
| 1619 | break; |
| 1620 | default: |
| 1621 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 1622 | return; |
Chandrabhanu Mahapatra | 05dd0f5 | 2012-05-15 12:22:34 +0530 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | accu_val = &accu_table[idx]; |
| 1626 | |
| 1627 | chroma_hinc = 1024 * orig_width / out_width; |
| 1628 | chroma_vinc = 1024 * orig_height / out_height; |
| 1629 | |
| 1630 | h_accu2_0 = (accu_val->h0_m * chroma_hinc / accu_val->h0_n) % 1024; |
| 1631 | h_accu2_1 = (accu_val->h1_m * chroma_hinc / accu_val->h1_n) % 1024; |
| 1632 | v_accu2_0 = (accu_val->v0_m * chroma_vinc / accu_val->v0_n) % 1024; |
| 1633 | v_accu2_1 = (accu_val->v1_m * chroma_vinc / accu_val->v1_n) % 1024; |
| 1634 | |
| 1635 | dispc_ovl_set_vid_accu2_0(plane, h_accu2_0, v_accu2_0); |
| 1636 | dispc_ovl_set_vid_accu2_1(plane, h_accu2_1, v_accu2_1); |
| 1637 | } |
| 1638 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1639 | static void dispc_ovl_set_scaling_common(enum omap_plane_id plane, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1640 | u16 orig_width, u16 orig_height, |
| 1641 | u16 out_width, u16 out_height, |
| 1642 | bool ilace, bool five_taps, |
| 1643 | bool fieldmode, enum omap_color_mode color_mode, |
| 1644 | u8 rotation) |
| 1645 | { |
| 1646 | int accu0 = 0; |
| 1647 | int accu1 = 0; |
| 1648 | u32 l; |
| 1649 | |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1650 | dispc_ovl_set_scale_param(plane, orig_width, orig_height, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1651 | out_width, out_height, five_taps, |
| 1652 | rotation, DISPC_COLOR_COMPONENT_RGB_Y); |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1653 | l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1654 | |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1655 | /* RESIZEENABLE and VERTICALTAPS */ |
| 1656 | l &= ~((0x3 << 5) | (0x1 << 21)); |
Amber Jain | ed14a3c | 2011-05-19 19:47:51 +0530 | [diff] [blame] | 1657 | l |= (orig_width != out_width) ? (1 << 5) : 0; |
| 1658 | l |= (orig_height != out_height) ? (1 << 6) : 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1659 | l |= five_taps ? (1 << 21) : 0; |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1660 | |
| 1661 | /* VRESIZECONF and HRESIZECONF */ |
| 1662 | if (dss_has_feature(FEAT_RESIZECONF)) { |
| 1663 | l &= ~(0x3 << 7); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1664 | l |= (orig_width <= out_width) ? 0 : (1 << 7); |
| 1665 | l |= (orig_height <= out_height) ? 0 : (1 << 8); |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | /* LINEBUFFERSPLIT */ |
| 1669 | if (dss_has_feature(FEAT_LINEBUFFERSPLIT)) { |
| 1670 | l &= ~(0x1 << 22); |
| 1671 | l |= five_taps ? (1 << 22) : 0; |
| 1672 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1673 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1674 | dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1675 | |
| 1676 | /* |
| 1677 | * field 0 = even field = bottom field |
| 1678 | * field 1 = odd field = top field |
| 1679 | */ |
| 1680 | if (ilace && !fieldmode) { |
| 1681 | accu1 = 0; |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1682 | accu0 = ((1024 * orig_height / out_height) / 2) & 0x3ff; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1683 | if (accu0 >= 1024/2) { |
| 1684 | accu1 = 1024/2; |
| 1685 | accu0 -= accu1; |
| 1686 | } |
| 1687 | } |
| 1688 | |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1689 | dispc_ovl_set_vid_accu0(plane, 0, accu0); |
| 1690 | dispc_ovl_set_vid_accu1(plane, 0, accu1); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1691 | } |
| 1692 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1693 | static void dispc_ovl_set_scaling_uv(enum omap_plane_id plane, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1694 | u16 orig_width, u16 orig_height, |
| 1695 | u16 out_width, u16 out_height, |
| 1696 | bool ilace, bool five_taps, |
| 1697 | bool fieldmode, enum omap_color_mode color_mode, |
| 1698 | u8 rotation) |
| 1699 | { |
| 1700 | int scale_x = out_width != orig_width; |
| 1701 | int scale_y = out_height != orig_height; |
Andrew F. Davis | 0cac5b6 | 2016-07-01 09:27:21 -0500 | [diff] [blame] | 1702 | bool chroma_upscale = plane != OMAP_DSS_WB; |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1703 | |
| 1704 | if (!dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) |
| 1705 | return; |
| 1706 | if ((color_mode != OMAP_DSS_COLOR_YUV2 && |
| 1707 | color_mode != OMAP_DSS_COLOR_UYVY && |
| 1708 | color_mode != OMAP_DSS_COLOR_NV12)) { |
| 1709 | /* reset chroma resampling for RGB formats */ |
Archit Taneja | 2a5561b | 2012-07-16 16:37:45 +0530 | [diff] [blame] | 1710 | if (plane != OMAP_DSS_WB) |
| 1711 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 8, 8); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1712 | return; |
| 1713 | } |
Tomi Valkeinen | 3637735 | 2012-05-15 15:54:15 +0300 | [diff] [blame] | 1714 | |
| 1715 | dispc_ovl_set_accu_uv(plane, orig_width, orig_height, out_width, |
| 1716 | out_height, ilace, color_mode, rotation); |
| 1717 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1718 | switch (color_mode) { |
| 1719 | case OMAP_DSS_COLOR_NV12: |
Archit Taneja | 20fbb50 | 2012-08-22 17:04:48 +0530 | [diff] [blame] | 1720 | if (chroma_upscale) { |
| 1721 | /* UV is subsampled by 2 horizontally and vertically */ |
| 1722 | orig_height >>= 1; |
| 1723 | orig_width >>= 1; |
| 1724 | } else { |
| 1725 | /* UV is downsampled by 2 horizontally and vertically */ |
| 1726 | orig_height <<= 1; |
| 1727 | orig_width <<= 1; |
| 1728 | } |
| 1729 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1730 | break; |
| 1731 | case OMAP_DSS_COLOR_YUV2: |
| 1732 | case OMAP_DSS_COLOR_UYVY: |
Archit Taneja | 20fbb50 | 2012-08-22 17:04:48 +0530 | [diff] [blame] | 1733 | /* For YUV422 with 90/270 rotation, we don't upsample chroma */ |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1734 | if (rotation == OMAP_DSS_ROT_0 || |
Archit Taneja | 20fbb50 | 2012-08-22 17:04:48 +0530 | [diff] [blame] | 1735 | rotation == OMAP_DSS_ROT_180) { |
| 1736 | if (chroma_upscale) |
| 1737 | /* UV is subsampled by 2 horizontally */ |
| 1738 | orig_width >>= 1; |
| 1739 | else |
| 1740 | /* UV is downsampled by 2 horizontally */ |
| 1741 | orig_width <<= 1; |
| 1742 | } |
| 1743 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1744 | /* must use FIR for YUV422 if rotated */ |
| 1745 | if (rotation != OMAP_DSS_ROT_0) |
| 1746 | scale_x = scale_y = true; |
Archit Taneja | 20fbb50 | 2012-08-22 17:04:48 +0530 | [diff] [blame] | 1747 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1748 | break; |
| 1749 | default: |
| 1750 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 1751 | return; |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | if (out_width != orig_width) |
| 1755 | scale_x = true; |
| 1756 | if (out_height != orig_height) |
| 1757 | scale_y = true; |
| 1758 | |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1759 | dispc_ovl_set_scale_param(plane, orig_width, orig_height, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1760 | out_width, out_height, five_taps, |
| 1761 | rotation, DISPC_COLOR_COMPONENT_UV); |
| 1762 | |
Archit Taneja | 2a5561b | 2012-07-16 16:37:45 +0530 | [diff] [blame] | 1763 | if (plane != OMAP_DSS_WB) |
| 1764 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), |
| 1765 | (scale_x || scale_y) ? 1 : 0, 8, 8); |
| 1766 | |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1767 | /* set H scaling */ |
| 1768 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_x ? 1 : 0, 5, 5); |
| 1769 | /* set V scaling */ |
| 1770 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), scale_y ? 1 : 0, 6, 6); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1771 | } |
| 1772 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 1773 | static void dispc_ovl_set_scaling(enum omap_plane_id plane, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1774 | u16 orig_width, u16 orig_height, |
| 1775 | u16 out_width, u16 out_height, |
| 1776 | bool ilace, bool five_taps, |
| 1777 | bool fieldmode, enum omap_color_mode color_mode, |
| 1778 | u8 rotation) |
| 1779 | { |
| 1780 | BUG_ON(plane == OMAP_DSS_GFX); |
| 1781 | |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1782 | dispc_ovl_set_scaling_common(plane, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1783 | orig_width, orig_height, |
| 1784 | out_width, out_height, |
| 1785 | ilace, five_taps, |
| 1786 | fieldmode, color_mode, |
| 1787 | rotation); |
| 1788 | |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 1789 | dispc_ovl_set_scaling_uv(plane, |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 1790 | orig_width, orig_height, |
| 1791 | out_width, out_height, |
| 1792 | ilace, five_taps, |
| 1793 | fieldmode, color_mode, |
| 1794 | rotation); |
| 1795 | } |
| 1796 | |
Jyri Sarha | 273ffea | 2017-03-24 16:47:53 +0200 | [diff] [blame] | 1797 | static void dispc_ovl_set_rotation_attrs(enum omap_plane_id plane, u8 rotation, |
Archit Taneja | c35eeb2 | 2013-03-26 19:15:24 +0530 | [diff] [blame] | 1798 | enum omap_dss_rotation_type rotation_type, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1799 | bool mirroring, enum omap_color_mode color_mode) |
| 1800 | { |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1801 | bool row_repeat = false; |
| 1802 | int vidrot = 0; |
| 1803 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1804 | if (color_mode == OMAP_DSS_COLOR_YUV2 || |
| 1805 | color_mode == OMAP_DSS_COLOR_UYVY) { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1806 | |
| 1807 | if (mirroring) { |
| 1808 | switch (rotation) { |
| 1809 | case OMAP_DSS_ROT_0: |
| 1810 | vidrot = 2; |
| 1811 | break; |
| 1812 | case OMAP_DSS_ROT_90: |
| 1813 | vidrot = 1; |
| 1814 | break; |
| 1815 | case OMAP_DSS_ROT_180: |
| 1816 | vidrot = 0; |
| 1817 | break; |
| 1818 | case OMAP_DSS_ROT_270: |
| 1819 | vidrot = 3; |
| 1820 | break; |
| 1821 | } |
| 1822 | } else { |
| 1823 | switch (rotation) { |
| 1824 | case OMAP_DSS_ROT_0: |
| 1825 | vidrot = 0; |
| 1826 | break; |
| 1827 | case OMAP_DSS_ROT_90: |
| 1828 | vidrot = 1; |
| 1829 | break; |
| 1830 | case OMAP_DSS_ROT_180: |
| 1831 | vidrot = 2; |
| 1832 | break; |
| 1833 | case OMAP_DSS_ROT_270: |
| 1834 | vidrot = 3; |
| 1835 | break; |
| 1836 | } |
| 1837 | } |
| 1838 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1839 | if (rotation == OMAP_DSS_ROT_90 || rotation == OMAP_DSS_ROT_270) |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1840 | row_repeat = true; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1841 | else |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1842 | row_repeat = false; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1843 | } |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1844 | |
Tomi Valkeinen | 3397cc6 | 2015-04-09 13:51:30 +0300 | [diff] [blame] | 1845 | /* |
| 1846 | * OMAP4/5 Errata i631: |
| 1847 | * NV12 in 1D mode must use ROTATION=1. Otherwise DSS will fetch extra |
| 1848 | * rows beyond the framebuffer, which may cause OCP error. |
| 1849 | */ |
| 1850 | if (color_mode == OMAP_DSS_COLOR_NV12 && |
| 1851 | rotation_type != OMAP_DSS_ROT_TILER) |
| 1852 | vidrot = 1; |
| 1853 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1854 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), vidrot, 13, 12); |
Archit Taneja | 87a7484 | 2011-03-02 11:19:50 +0530 | [diff] [blame] | 1855 | if (dss_has_feature(FEAT_ROWREPEATENABLE)) |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 1856 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), |
| 1857 | row_repeat ? 1 : 0, 18, 18); |
Archit Taneja | c35eeb2 | 2013-03-26 19:15:24 +0530 | [diff] [blame] | 1858 | |
Tomi Valkeinen | 6d86278 | 2016-08-29 11:15:49 +0300 | [diff] [blame] | 1859 | if (dss_feat_color_mode_supported(plane, OMAP_DSS_COLOR_NV12)) { |
| 1860 | bool doublestride = |
| 1861 | color_mode == OMAP_DSS_COLOR_NV12 && |
| 1862 | rotation_type == OMAP_DSS_ROT_TILER && |
| 1863 | (rotation == OMAP_DSS_ROT_0 || rotation == OMAP_DSS_ROT_180); |
| 1864 | |
Archit Taneja | c35eeb2 | 2013-03-26 19:15:24 +0530 | [diff] [blame] | 1865 | /* DOUBLESTRIDE */ |
| 1866 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), doublestride, 22, 22); |
| 1867 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | static int color_mode_to_bpp(enum omap_color_mode color_mode) |
| 1871 | { |
| 1872 | switch (color_mode) { |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 1873 | case OMAP_DSS_COLOR_NV12: |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1874 | return 8; |
| 1875 | case OMAP_DSS_COLOR_RGB12U: |
| 1876 | case OMAP_DSS_COLOR_RGB16: |
| 1877 | case OMAP_DSS_COLOR_ARGB16: |
| 1878 | case OMAP_DSS_COLOR_YUV2: |
| 1879 | case OMAP_DSS_COLOR_UYVY: |
Amber Jain | f20e422 | 2011-05-19 19:47:50 +0530 | [diff] [blame] | 1880 | case OMAP_DSS_COLOR_RGBA16: |
| 1881 | case OMAP_DSS_COLOR_RGBX16: |
| 1882 | case OMAP_DSS_COLOR_ARGB16_1555: |
| 1883 | case OMAP_DSS_COLOR_XRGB16_1555: |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1884 | return 16; |
| 1885 | case OMAP_DSS_COLOR_RGB24P: |
| 1886 | return 24; |
| 1887 | case OMAP_DSS_COLOR_RGB24U: |
| 1888 | case OMAP_DSS_COLOR_ARGB32: |
| 1889 | case OMAP_DSS_COLOR_RGBA32: |
| 1890 | case OMAP_DSS_COLOR_RGBX32: |
| 1891 | return 32; |
| 1892 | default: |
| 1893 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 1894 | return 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | static s32 pixinc(int pixels, u8 ps) |
| 1899 | { |
| 1900 | if (pixels == 1) |
| 1901 | return 1; |
| 1902 | else if (pixels > 1) |
| 1903 | return 1 + (pixels - 1) * ps; |
| 1904 | else if (pixels < 0) |
| 1905 | return 1 - (-pixels + 1) * ps; |
| 1906 | else |
| 1907 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 1908 | return 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 1909 | } |
| 1910 | |
Tomi Valkeinen | 517a8a95 | 2017-05-03 14:14:27 +0300 | [diff] [blame^] | 1911 | static void calc_offset(u16 screen_width, u16 width, |
Chandrabhanu Mahapatra | 65e006f | 2012-05-11 19:19:55 +0530 | [diff] [blame] | 1912 | enum omap_color_mode color_mode, bool fieldmode, |
| 1913 | unsigned int field_offset, unsigned *offset0, unsigned *offset1, |
| 1914 | s32 *row_inc, s32 *pix_inc, int x_predecim, int y_predecim) |
| 1915 | { |
| 1916 | u8 ps; |
| 1917 | |
Tomi Valkeinen | 4b9cdd9 | 2017-03-10 10:32:30 +0200 | [diff] [blame] | 1918 | ps = color_mode_to_bpp(color_mode) / 8; |
Chandrabhanu Mahapatra | 65e006f | 2012-05-11 19:19:55 +0530 | [diff] [blame] | 1919 | |
| 1920 | DSSDBG("scrw %d, width %d\n", screen_width, width); |
| 1921 | |
| 1922 | /* |
| 1923 | * field 0 = even field = bottom field |
| 1924 | * field 1 = odd field = top field |
| 1925 | */ |
| 1926 | *offset1 = 0; |
| 1927 | if (field_offset) |
| 1928 | *offset0 = *offset1 + field_offset * screen_width * ps; |
| 1929 | else |
| 1930 | *offset0 = *offset1; |
| 1931 | *row_inc = pixinc(1 + (y_predecim * screen_width - width * x_predecim) + |
| 1932 | (fieldmode ? screen_width : 0), ps); |
| 1933 | if (color_mode == OMAP_DSS_COLOR_YUV2 || |
| 1934 | color_mode == OMAP_DSS_COLOR_UYVY) |
| 1935 | *pix_inc = pixinc(x_predecim, 2 * ps); |
| 1936 | else |
| 1937 | *pix_inc = pixinc(x_predecim, ps); |
| 1938 | } |
| 1939 | |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1940 | /* |
| 1941 | * This function is used to avoid synclosts in OMAP3, because of some |
| 1942 | * undocumented horizontal position and timing related limitations. |
| 1943 | */ |
Tomi Valkeinen | 465ec13 | 2012-10-19 15:40:24 +0300 | [diff] [blame] | 1944 | static int check_horiz_timing_omap3(unsigned long pclk, unsigned long lclk, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 1945 | const struct videomode *vm, u16 pos_x, |
Ivaylo Dimitrov | e4998634 | 2014-01-13 18:33:02 +0200 | [diff] [blame] | 1946 | u16 width, u16 height, u16 out_width, u16 out_height, |
| 1947 | bool five_taps) |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1948 | { |
Tomi Valkeinen | 230edc0 | 2012-11-05 14:40:19 +0200 | [diff] [blame] | 1949 | const int ds = DIV_ROUND_UP(height, out_height); |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 1950 | unsigned long nonactive; |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1951 | static const u8 limits[3] = { 8, 10, 20 }; |
| 1952 | u64 val, blank; |
| 1953 | int i; |
| 1954 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 1955 | nonactive = vm->hactive + vm->hfront_porch + vm->hsync_len + |
| 1956 | vm->hback_porch - out_width; |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1957 | |
| 1958 | i = 0; |
| 1959 | if (out_height < height) |
| 1960 | i++; |
| 1961 | if (out_width < width) |
| 1962 | i++; |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 1963 | blank = div_u64((u64)(vm->hback_porch + vm->hsync_len + vm->hfront_porch) * |
Peter Ujfalusi | 0a30e15 | 2016-09-22 14:06:49 +0300 | [diff] [blame] | 1964 | lclk, pclk); |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1965 | DSSDBG("blanking period + ppl = %llu (limit = %u)\n", blank, limits[i]); |
| 1966 | if (blank <= limits[i]) |
| 1967 | return -EINVAL; |
| 1968 | |
Ivaylo Dimitrov | e4998634 | 2014-01-13 18:33:02 +0200 | [diff] [blame] | 1969 | /* FIXME add checks for 3-tap filter once the limitations are known */ |
| 1970 | if (!five_taps) |
| 1971 | return 0; |
| 1972 | |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1973 | /* |
| 1974 | * Pixel data should be prepared before visible display point starts. |
| 1975 | * So, atleast DS-2 lines must have already been fetched by DISPC |
| 1976 | * during nonactive - pos_x period. |
| 1977 | */ |
| 1978 | val = div_u64((u64)(nonactive - pos_x) * lclk, pclk); |
| 1979 | DSSDBG("(nonactive - pos_x) * pcd = %llu max(0, DS - 2) * width = %d\n", |
Tomi Valkeinen | 230edc0 | 2012-11-05 14:40:19 +0200 | [diff] [blame] | 1980 | val, max(0, ds - 2) * width); |
| 1981 | if (val < max(0, ds - 2) * width) |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1982 | return -EINVAL; |
| 1983 | |
| 1984 | /* |
| 1985 | * All lines need to be refilled during the nonactive period of which |
| 1986 | * only one line can be loaded during the active period. So, atleast |
| 1987 | * DS - 1 lines should be loaded during nonactive period. |
| 1988 | */ |
| 1989 | val = div_u64((u64)nonactive * lclk, pclk); |
| 1990 | DSSDBG("nonactive * pcd = %llu, max(0, DS - 1) * width = %d\n", |
Tomi Valkeinen | 230edc0 | 2012-11-05 14:40:19 +0200 | [diff] [blame] | 1991 | val, max(0, ds - 1) * width); |
| 1992 | if (val < max(0, ds - 1) * width) |
Chandrabhanu Mahapatra | 7faa923 | 2012-04-02 20:43:17 +0530 | [diff] [blame] | 1993 | return -EINVAL; |
| 1994 | |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 1998 | static unsigned long calc_core_clk_five_taps(unsigned long pclk, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 1999 | const struct videomode *vm, u16 width, |
Archit Taneja | 81ab95b | 2012-05-08 15:53:20 +0530 | [diff] [blame] | 2000 | u16 height, u16 out_width, u16 out_height, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 2001 | enum omap_color_mode color_mode) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2002 | { |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2003 | u32 core_clk = 0; |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 2004 | u64 tmp; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2005 | |
Chandrabhanu Mahapatra | 7282f1b | 2011-12-19 14:03:56 +0530 | [diff] [blame] | 2006 | if (height <= out_height && width <= out_width) |
| 2007 | return (unsigned long) pclk; |
| 2008 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2009 | if (height > out_height) { |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2010 | unsigned int ppl = vm->hactive; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2011 | |
Tomi Valkeinen | c582935 | 2015-04-10 12:48:36 +0300 | [diff] [blame] | 2012 | tmp = (u64)pclk * height * out_width; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2013 | do_div(tmp, 2 * out_height * ppl); |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2014 | core_clk = tmp; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2015 | |
Ville Syrjälä | 2d9c559 | 2010-01-08 11:56:41 +0200 | [diff] [blame] | 2016 | if (height > 2 * out_height) { |
| 2017 | if (ppl == out_width) |
| 2018 | return 0; |
| 2019 | |
Tomi Valkeinen | c582935 | 2015-04-10 12:48:36 +0300 | [diff] [blame] | 2020 | tmp = (u64)pclk * (height - 2 * out_height) * out_width; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2021 | do_div(tmp, 2 * out_height * (ppl - out_width)); |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2022 | core_clk = max_t(u32, core_clk, tmp); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | if (width > out_width) { |
Tomi Valkeinen | c582935 | 2015-04-10 12:48:36 +0300 | [diff] [blame] | 2027 | tmp = (u64)pclk * width; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2028 | do_div(tmp, out_width); |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2029 | core_clk = max_t(u32, core_clk, tmp); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2030 | |
| 2031 | if (color_mode == OMAP_DSS_COLOR_RGB24U) |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2032 | core_clk <<= 1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2033 | } |
| 2034 | |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2035 | return core_clk; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2036 | } |
| 2037 | |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 2038 | static unsigned long calc_core_clk_24xx(unsigned long pclk, u16 width, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2039 | u16 height, u16 out_width, u16 out_height, bool mem_to_mem) |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2040 | { |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2041 | if (height > out_height && width > out_width) |
| 2042 | return pclk * 4; |
| 2043 | else |
| 2044 | return pclk * 2; |
| 2045 | } |
| 2046 | |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 2047 | static unsigned long calc_core_clk_34xx(unsigned long pclk, u16 width, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2048 | u16 height, u16 out_width, u16 out_height, bool mem_to_mem) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2049 | { |
| 2050 | unsigned int hf, vf; |
| 2051 | |
| 2052 | /* |
| 2053 | * FIXME how to determine the 'A' factor |
| 2054 | * for the no downscaling case ? |
| 2055 | */ |
| 2056 | |
| 2057 | if (width > 3 * out_width) |
| 2058 | hf = 4; |
| 2059 | else if (width > 2 * out_width) |
| 2060 | hf = 3; |
| 2061 | else if (width > out_width) |
| 2062 | hf = 2; |
| 2063 | else |
| 2064 | hf = 1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2065 | if (height > out_height) |
| 2066 | vf = 2; |
| 2067 | else |
| 2068 | vf = 1; |
| 2069 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2070 | return pclk * vf * hf; |
| 2071 | } |
| 2072 | |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 2073 | static unsigned long calc_core_clk_44xx(unsigned long pclk, u16 width, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2074 | u16 height, u16 out_width, u16 out_height, bool mem_to_mem) |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2075 | { |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2076 | /* |
| 2077 | * If the overlay/writeback is in mem to mem mode, there are no |
| 2078 | * downscaling limitations with respect to pixel clock, return 1 as |
| 2079 | * required core clock to represent that we have sufficient enough |
| 2080 | * core clock to do maximum downscaling |
| 2081 | */ |
| 2082 | if (mem_to_mem) |
| 2083 | return 1; |
| 2084 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2085 | if (width > out_width) |
| 2086 | return DIV_ROUND_UP(pclk, out_width) * width; |
| 2087 | else |
| 2088 | return pclk; |
| 2089 | } |
| 2090 | |
Tomi Valkeinen | 0c6921d | 2012-10-19 15:43:29 +0300 | [diff] [blame] | 2091 | static int dispc_ovl_calc_scaling_24xx(unsigned long pclk, unsigned long lclk, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2092 | const struct videomode *vm, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2093 | u16 width, u16 height, u16 out_width, u16 out_height, |
| 2094 | enum omap_color_mode color_mode, bool *five_taps, |
| 2095 | int *x_predecim, int *y_predecim, int *decim_x, int *decim_y, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2096 | u16 pos_x, unsigned long *core_clk, bool mem_to_mem) |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2097 | { |
| 2098 | int error; |
| 2099 | u16 in_width, in_height; |
| 2100 | int min_factor = min(*decim_x, *decim_y); |
| 2101 | const int maxsinglelinewidth = |
| 2102 | dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH); |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 2103 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2104 | *five_taps = false; |
| 2105 | |
| 2106 | do { |
Tomi Valkeinen | eec77da | 2014-01-27 11:29:53 +0200 | [diff] [blame] | 2107 | in_height = height / *decim_y; |
| 2108 | in_width = width / *decim_x; |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 2109 | *core_clk = dispc.feat->calc_core_clk(pclk, in_width, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2110 | in_height, out_width, out_height, mem_to_mem); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2111 | error = (in_width > maxsinglelinewidth || !*core_clk || |
| 2112 | *core_clk > dispc_core_clk_rate()); |
| 2113 | if (error) { |
| 2114 | if (*decim_x == *decim_y) { |
| 2115 | *decim_x = min_factor; |
| 2116 | ++*decim_y; |
| 2117 | } else { |
| 2118 | swap(*decim_x, *decim_y); |
| 2119 | if (*decim_x < *decim_y) |
| 2120 | ++*decim_x; |
| 2121 | } |
| 2122 | } |
| 2123 | } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error); |
| 2124 | |
Tomi Valkeinen | 3ce17b4 | 2015-04-10 12:48:37 +0300 | [diff] [blame] | 2125 | if (error) { |
| 2126 | DSSERR("failed to find scaling settings\n"); |
| 2127 | return -EINVAL; |
| 2128 | } |
| 2129 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2130 | if (in_width > maxsinglelinewidth) { |
| 2131 | DSSERR("Cannot scale max input width exceeded"); |
| 2132 | return -EINVAL; |
Chandrabhanu Mahapatra | 7282f1b | 2011-12-19 14:03:56 +0530 | [diff] [blame] | 2133 | } |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2134 | return 0; |
| 2135 | } |
| 2136 | |
Tomi Valkeinen | 0c6921d | 2012-10-19 15:43:29 +0300 | [diff] [blame] | 2137 | static int dispc_ovl_calc_scaling_34xx(unsigned long pclk, unsigned long lclk, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2138 | const struct videomode *vm, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2139 | u16 width, u16 height, u16 out_width, u16 out_height, |
| 2140 | enum omap_color_mode color_mode, bool *five_taps, |
| 2141 | int *x_predecim, int *y_predecim, int *decim_x, int *decim_y, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2142 | u16 pos_x, unsigned long *core_clk, bool mem_to_mem) |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2143 | { |
| 2144 | int error; |
| 2145 | u16 in_width, in_height; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2146 | const int maxsinglelinewidth = |
| 2147 | dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH); |
| 2148 | |
| 2149 | do { |
Tomi Valkeinen | eec77da | 2014-01-27 11:29:53 +0200 | [diff] [blame] | 2150 | in_height = height / *decim_y; |
| 2151 | in_width = width / *decim_x; |
Ivaylo Dimitrov | e4998634 | 2014-01-13 18:33:02 +0200 | [diff] [blame] | 2152 | *five_taps = in_height > out_height; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2153 | |
| 2154 | if (in_width > maxsinglelinewidth) |
| 2155 | if (in_height > out_height && |
| 2156 | in_height < out_height * 2) |
| 2157 | *five_taps = false; |
Ivaylo Dimitrov | e4998634 | 2014-01-13 18:33:02 +0200 | [diff] [blame] | 2158 | again: |
| 2159 | if (*five_taps) |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2160 | *core_clk = calc_core_clk_five_taps(pclk, vm, |
Ivaylo Dimitrov | e4998634 | 2014-01-13 18:33:02 +0200 | [diff] [blame] | 2161 | in_width, in_height, out_width, |
| 2162 | out_height, color_mode); |
| 2163 | else |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 2164 | *core_clk = dispc.feat->calc_core_clk(pclk, in_width, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2165 | in_height, out_width, out_height, |
| 2166 | mem_to_mem); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2167 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2168 | error = check_horiz_timing_omap3(pclk, lclk, vm, |
Ivaylo Dimitrov | e4998634 | 2014-01-13 18:33:02 +0200 | [diff] [blame] | 2169 | pos_x, in_width, in_height, out_width, |
| 2170 | out_height, *five_taps); |
| 2171 | if (error && *five_taps) { |
| 2172 | *five_taps = false; |
| 2173 | goto again; |
| 2174 | } |
| 2175 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2176 | error = (error || in_width > maxsinglelinewidth * 2 || |
| 2177 | (in_width > maxsinglelinewidth && *five_taps) || |
| 2178 | !*core_clk || *core_clk > dispc_core_clk_rate()); |
Tomi Valkeinen | ab6b258 | 2015-03-17 15:31:10 +0200 | [diff] [blame] | 2179 | |
| 2180 | if (!error) { |
| 2181 | /* verify that we're inside the limits of scaler */ |
| 2182 | if (in_width / 4 > out_width) |
| 2183 | error = 1; |
| 2184 | |
| 2185 | if (*five_taps) { |
| 2186 | if (in_height / 4 > out_height) |
| 2187 | error = 1; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2188 | } else { |
Tomi Valkeinen | ab6b258 | 2015-03-17 15:31:10 +0200 | [diff] [blame] | 2189 | if (in_height / 2 > out_height) |
| 2190 | error = 1; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2191 | } |
| 2192 | } |
Tomi Valkeinen | ab6b258 | 2015-03-17 15:31:10 +0200 | [diff] [blame] | 2193 | |
Tomi Valkeinen | 7059e3d | 2015-04-10 12:48:38 +0300 | [diff] [blame] | 2194 | if (error) |
| 2195 | ++*decim_y; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2196 | } while (*decim_x <= *x_predecim && *decim_y <= *y_predecim && error); |
| 2197 | |
Tomi Valkeinen | 3ce17b4 | 2015-04-10 12:48:37 +0300 | [diff] [blame] | 2198 | if (error) { |
| 2199 | DSSERR("failed to find scaling settings\n"); |
| 2200 | return -EINVAL; |
| 2201 | } |
| 2202 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2203 | if (check_horiz_timing_omap3(pclk, lclk, vm, pos_x, in_width, |
Tomi Valkeinen | f5a7348 | 2015-03-17 15:31:09 +0200 | [diff] [blame] | 2204 | in_height, out_width, out_height, *five_taps)) { |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2205 | DSSERR("horizontal timing too tight\n"); |
| 2206 | return -EINVAL; |
| 2207 | } |
| 2208 | |
| 2209 | if (in_width > (maxsinglelinewidth * 2)) { |
| 2210 | DSSERR("Cannot setup scaling"); |
| 2211 | DSSERR("width exceeds maximum width possible"); |
| 2212 | return -EINVAL; |
| 2213 | } |
| 2214 | |
| 2215 | if (in_width > maxsinglelinewidth && *five_taps) { |
| 2216 | DSSERR("cannot setup scaling with five taps"); |
| 2217 | return -EINVAL; |
| 2218 | } |
| 2219 | return 0; |
| 2220 | } |
| 2221 | |
Tomi Valkeinen | 0c6921d | 2012-10-19 15:43:29 +0300 | [diff] [blame] | 2222 | static int dispc_ovl_calc_scaling_44xx(unsigned long pclk, unsigned long lclk, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2223 | const struct videomode *vm, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2224 | u16 width, u16 height, u16 out_width, u16 out_height, |
| 2225 | enum omap_color_mode color_mode, bool *five_taps, |
| 2226 | int *x_predecim, int *y_predecim, int *decim_x, int *decim_y, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2227 | u16 pos_x, unsigned long *core_clk, bool mem_to_mem) |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2228 | { |
| 2229 | u16 in_width, in_width_max; |
| 2230 | int decim_x_min = *decim_x; |
Tomi Valkeinen | eec77da | 2014-01-27 11:29:53 +0200 | [diff] [blame] | 2231 | u16 in_height = height / *decim_y; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2232 | const int maxsinglelinewidth = |
| 2233 | dss_feat_get_param_max(FEAT_PARAM_LINEWIDTH); |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2234 | const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2235 | |
Archit Taneja | 5d50108 | 2012-11-07 11:45:02 +0530 | [diff] [blame] | 2236 | if (mem_to_mem) { |
| 2237 | in_width_max = out_width * maxdownscale; |
| 2238 | } else { |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2239 | in_width_max = dispc_core_clk_rate() / |
| 2240 | DIV_ROUND_UP(pclk, out_width); |
Archit Taneja | 5d50108 | 2012-11-07 11:45:02 +0530 | [diff] [blame] | 2241 | } |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 2242 | |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2243 | *decim_x = DIV_ROUND_UP(width, in_width_max); |
| 2244 | |
| 2245 | *decim_x = *decim_x > decim_x_min ? *decim_x : decim_x_min; |
| 2246 | if (*decim_x > *x_predecim) |
| 2247 | return -EINVAL; |
| 2248 | |
| 2249 | do { |
Tomi Valkeinen | eec77da | 2014-01-27 11:29:53 +0200 | [diff] [blame] | 2250 | in_width = width / *decim_x; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2251 | } while (*decim_x <= *x_predecim && |
| 2252 | in_width > maxsinglelinewidth && ++*decim_x); |
| 2253 | |
| 2254 | if (in_width > maxsinglelinewidth) { |
| 2255 | DSSERR("Cannot scale width exceeds max line width"); |
| 2256 | return -EINVAL; |
| 2257 | } |
| 2258 | |
Jyri Sarha | 1b30ab0 | 2017-02-08 16:08:06 +0200 | [diff] [blame] | 2259 | if (*decim_x > 4 && color_mode != OMAP_DSS_COLOR_NV12) { |
| 2260 | /* |
| 2261 | * Let's disable all scaling that requires horizontal |
| 2262 | * decimation with higher factor than 4, until we have |
| 2263 | * better estimates of what we can and can not |
| 2264 | * do. However, NV12 color format appears to work Ok |
| 2265 | * with all decimation factors. |
| 2266 | * |
| 2267 | * When decimating horizontally by more that 4 the dss |
| 2268 | * is not able to fetch the data in burst mode. When |
| 2269 | * this happens it is hard to tell if there enough |
| 2270 | * bandwidth. Despite what theory says this appears to |
| 2271 | * be true also for 16-bit color formats. |
| 2272 | */ |
| 2273 | DSSERR("Not enough bandwidth, too much downscaling (x-decimation factor %d > 4)", *decim_x); |
| 2274 | |
| 2275 | return -EINVAL; |
| 2276 | } |
| 2277 | |
Tomi Valkeinen | 8702ee5 | 2012-10-19 15:36:11 +0300 | [diff] [blame] | 2278 | *core_clk = dispc.feat->calc_core_clk(pclk, in_width, in_height, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2279 | out_width, out_height, mem_to_mem); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2280 | return 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
Tomi Valkeinen | e4c5ae7 | 2015-04-10 12:48:39 +0300 | [diff] [blame] | 2283 | #define DIV_FRAC(dividend, divisor) \ |
| 2284 | ((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100)) |
| 2285 | |
Tomi Valkeinen | 74e1645 | 2012-10-19 15:46:30 +0300 | [diff] [blame] | 2286 | static int dispc_ovl_calc_scaling(unsigned long pclk, unsigned long lclk, |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 2287 | enum omap_overlay_caps caps, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2288 | const struct videomode *vm, |
Archit Taneja | 81ab95b | 2012-05-08 15:53:20 +0530 | [diff] [blame] | 2289 | u16 width, u16 height, u16 out_width, u16 out_height, |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2290 | enum omap_color_mode color_mode, bool *five_taps, |
Chandrabhanu Mahapatra | d557a9c | 2012-09-24 12:08:27 +0530 | [diff] [blame] | 2291 | int *x_predecim, int *y_predecim, u16 pos_x, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2292 | enum omap_dss_rotation_type rotation_type, bool mem_to_mem) |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2293 | { |
Archit Taneja | 0373cac | 2011-09-08 13:25:17 +0530 | [diff] [blame] | 2294 | const int maxdownscale = dss_feat_get_param_max(FEAT_PARAM_DOWNSCALE); |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2295 | const int max_decim_limit = 16; |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2296 | unsigned long core_clk = 0; |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2297 | int decim_x, decim_y, ret; |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2298 | |
Tomi Valkeinen | f95cb5e | 2011-11-01 10:50:45 +0200 | [diff] [blame] | 2299 | if (width == out_width && height == out_height) |
| 2300 | return 0; |
| 2301 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2302 | if (!mem_to_mem && (pclk == 0 || vm->pixelclock == 0)) { |
Tomi Valkeinen | 4e1d3ca | 2014-10-03 15:14:09 +0000 | [diff] [blame] | 2303 | DSSERR("cannot calculate scaling settings: pclk is zero\n"); |
| 2304 | return -EINVAL; |
| 2305 | } |
| 2306 | |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 2307 | if ((caps & OMAP_DSS_OVL_CAP_SCALE) == 0) |
Tomi Valkeinen | f95cb5e | 2011-11-01 10:50:45 +0200 | [diff] [blame] | 2308 | return -EINVAL; |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2309 | |
Tomi Valkeinen | 74e1645 | 2012-10-19 15:46:30 +0300 | [diff] [blame] | 2310 | if (mem_to_mem) { |
Archit Taneja | 1c03144 | 2012-11-07 11:45:03 +0530 | [diff] [blame] | 2311 | *x_predecim = *y_predecim = 1; |
| 2312 | } else { |
| 2313 | *x_predecim = max_decim_limit; |
| 2314 | *y_predecim = (rotation_type == OMAP_DSS_ROT_TILER && |
| 2315 | dss_has_feature(FEAT_BURST_2D)) ? |
| 2316 | 2 : max_decim_limit; |
| 2317 | } |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2318 | |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2319 | decim_x = DIV_ROUND_UP(DIV_ROUND_UP(width, out_width), maxdownscale); |
| 2320 | decim_y = DIV_ROUND_UP(DIV_ROUND_UP(height, out_height), maxdownscale); |
| 2321 | |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2322 | if (decim_x > *x_predecim || out_width > width * 8) |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2323 | return -EINVAL; |
| 2324 | |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2325 | if (decim_y > *y_predecim || out_height > height * 8) |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2326 | return -EINVAL; |
| 2327 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2328 | ret = dispc.feat->calc_scaling(pclk, lclk, vm, width, height, |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 2329 | out_width, out_height, color_mode, five_taps, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2330 | x_predecim, y_predecim, &decim_x, &decim_y, pos_x, &core_clk, |
| 2331 | mem_to_mem); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2332 | if (ret) |
| 2333 | return ret; |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2334 | |
Tomi Valkeinen | e4c5ae7 | 2015-04-10 12:48:39 +0300 | [diff] [blame] | 2335 | DSSDBG("%dx%d -> %dx%d (%d.%02d x %d.%02d), decim %dx%d %dx%d (%d.%02d x %d.%02d), taps %d, req clk %lu, cur clk %lu\n", |
| 2336 | width, height, |
| 2337 | out_width, out_height, |
| 2338 | out_width / width, DIV_FRAC(out_width, width), |
| 2339 | out_height / height, DIV_FRAC(out_height, height), |
| 2340 | |
| 2341 | decim_x, decim_y, |
| 2342 | width / decim_x, height / decim_y, |
| 2343 | out_width / (width / decim_x), DIV_FRAC(out_width, width / decim_x), |
| 2344 | out_height / (height / decim_y), DIV_FRAC(out_height, height / decim_y), |
| 2345 | |
| 2346 | *five_taps ? 5 : 3, |
| 2347 | core_clk, dispc_core_clk_rate()); |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2348 | |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2349 | if (!core_clk || core_clk > dispc_core_clk_rate()) { |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2350 | DSSERR("failed to set up scaling, " |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 2351 | "required core clk rate = %lu Hz, " |
| 2352 | "current core clk rate = %lu Hz\n", |
| 2353 | core_clk, dispc_core_clk_rate()); |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2354 | return -EINVAL; |
| 2355 | } |
| 2356 | |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2357 | *x_predecim = decim_x; |
| 2358 | *y_predecim = decim_y; |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2359 | return 0; |
| 2360 | } |
| 2361 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 2362 | static int dispc_ovl_setup_common(enum omap_plane_id plane, |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 2363 | enum omap_overlay_caps caps, u32 paddr, u32 p_uv_addr, |
| 2364 | u16 screen_width, int pos_x, int pos_y, u16 width, u16 height, |
| 2365 | u16 out_width, u16 out_height, enum omap_color_mode color_mode, |
| 2366 | u8 rotation, bool mirror, u8 zorder, u8 pre_mult_alpha, |
| 2367 | u8 global_alpha, enum omap_dss_rotation_type rotation_type, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2368 | bool replication, const struct videomode *vm, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2369 | bool mem_to_mem) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2370 | { |
Chandrabhanu Mahapatra | 7282f1b | 2011-12-19 14:03:56 +0530 | [diff] [blame] | 2371 | bool five_taps = true; |
Peter Senna Tschudin | 62a8318 | 2013-09-22 20:44:11 +0200 | [diff] [blame] | 2372 | bool fieldmode = false; |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2373 | int r, cconv = 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2374 | unsigned offset0, offset1; |
| 2375 | s32 row_inc; |
| 2376 | s32 pix_inc; |
Archit Taneja | 6be0d73 | 2012-11-07 11:45:04 +0530 | [diff] [blame] | 2377 | u16 frame_width, frame_height; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2378 | unsigned int field_offset = 0; |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2379 | u16 in_height = height; |
| 2380 | u16 in_width = width; |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2381 | int x_predecim = 1, y_predecim = 1; |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2382 | bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED); |
Tomi Valkeinen | 74e1645 | 2012-10-19 15:46:30 +0300 | [diff] [blame] | 2383 | unsigned long pclk = dispc_plane_pclk_rate(plane); |
| 2384 | unsigned long lclk = dispc_plane_lclk_rate(plane); |
Tomi Valkeinen | 2cc5d1a | 2011-11-03 17:03:44 +0200 | [diff] [blame] | 2385 | |
Tomi Valkeinen | e566658 | 2014-11-28 14:34:15 +0200 | [diff] [blame] | 2386 | if (paddr == 0 && rotation_type != OMAP_DSS_ROT_TILER) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2387 | return -EINVAL; |
| 2388 | |
Tomi Valkeinen | c4661b3 | 2015-02-27 13:07:58 +0200 | [diff] [blame] | 2389 | switch (color_mode) { |
| 2390 | case OMAP_DSS_COLOR_YUV2: |
| 2391 | case OMAP_DSS_COLOR_UYVY: |
| 2392 | case OMAP_DSS_COLOR_NV12: |
| 2393 | if (in_width & 1) { |
| 2394 | DSSERR("input width %d is not even for YUV format\n", |
| 2395 | in_width); |
| 2396 | return -EINVAL; |
| 2397 | } |
| 2398 | break; |
| 2399 | |
| 2400 | default: |
| 2401 | break; |
| 2402 | } |
| 2403 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2404 | out_width = out_width == 0 ? width : out_width; |
| 2405 | out_height = out_height == 0 ? height : out_height; |
Tomi Valkeinen | cf07366 | 2011-11-03 16:08:27 +0200 | [diff] [blame] | 2406 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2407 | if (ilace && height == out_height) |
Peter Senna Tschudin | 62a8318 | 2013-09-22 20:44:11 +0200 | [diff] [blame] | 2408 | fieldmode = true; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2409 | |
| 2410 | if (ilace) { |
| 2411 | if (fieldmode) |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2412 | in_height /= 2; |
Archit Taneja | 8eeb701 | 2012-08-22 12:33:49 +0530 | [diff] [blame] | 2413 | pos_y /= 2; |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2414 | out_height /= 2; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2415 | |
| 2416 | DSSDBG("adjusting for ilace: height %d, pos_y %d, " |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2417 | "out_height %d\n", in_height, pos_y, |
| 2418 | out_height); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2419 | } |
| 2420 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2421 | if (!dss_feat_color_mode_supported(plane, color_mode)) |
Archit Taneja | 8dad2ab | 2010-11-25 17:58:10 +0530 | [diff] [blame] | 2422 | return -EINVAL; |
| 2423 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2424 | r = dispc_ovl_calc_scaling(pclk, lclk, caps, vm, in_width, |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2425 | in_height, out_width, out_height, color_mode, |
| 2426 | &five_taps, &x_predecim, &y_predecim, pos_x, |
Archit Taneja | 8ba8530 | 2012-09-26 17:00:37 +0530 | [diff] [blame] | 2427 | rotation_type, mem_to_mem); |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2428 | if (r) |
| 2429 | return r; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2430 | |
Tomi Valkeinen | eec77da | 2014-01-27 11:29:53 +0200 | [diff] [blame] | 2431 | in_width = in_width / x_predecim; |
| 2432 | in_height = in_height / y_predecim; |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2433 | |
Tomi Valkeinen | c4661b3 | 2015-02-27 13:07:58 +0200 | [diff] [blame] | 2434 | if (x_predecim > 1 || y_predecim > 1) |
| 2435 | DSSDBG("predecimation %d x %x, new input size %d x %d\n", |
| 2436 | x_predecim, y_predecim, in_width, in_height); |
| 2437 | |
| 2438 | switch (color_mode) { |
| 2439 | case OMAP_DSS_COLOR_YUV2: |
| 2440 | case OMAP_DSS_COLOR_UYVY: |
| 2441 | case OMAP_DSS_COLOR_NV12: |
| 2442 | if (in_width & 1) { |
| 2443 | DSSDBG("predecimated input width is not even for YUV format\n"); |
| 2444 | DSSDBG("adjusting input width %d -> %d\n", |
| 2445 | in_width, in_width & ~1); |
| 2446 | |
| 2447 | in_width &= ~1; |
| 2448 | } |
| 2449 | break; |
| 2450 | |
| 2451 | default: |
| 2452 | break; |
| 2453 | } |
| 2454 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2455 | if (color_mode == OMAP_DSS_COLOR_YUV2 || |
| 2456 | color_mode == OMAP_DSS_COLOR_UYVY || |
| 2457 | color_mode == OMAP_DSS_COLOR_NV12) |
Archit Taneja | 79ad75f | 2011-09-08 13:15:11 +0530 | [diff] [blame] | 2458 | cconv = 1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2459 | |
| 2460 | if (ilace && !fieldmode) { |
| 2461 | /* |
| 2462 | * when downscaling the bottom field may have to start several |
| 2463 | * source lines below the top field. Unfortunately ACCUI |
| 2464 | * registers will only hold the fractional part of the offset |
| 2465 | * so the integer part must be added to the base address of the |
| 2466 | * bottom field. |
| 2467 | */ |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2468 | if (!in_height || in_height == out_height) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2469 | field_offset = 0; |
| 2470 | else |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2471 | field_offset = in_height / out_height / 2; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | /* Fields are independent but interleaved in memory. */ |
| 2475 | if (fieldmode) |
| 2476 | field_offset = 1; |
| 2477 | |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2478 | offset0 = 0; |
| 2479 | offset1 = 0; |
| 2480 | row_inc = 0; |
| 2481 | pix_inc = 0; |
| 2482 | |
Archit Taneja | 6be0d73 | 2012-11-07 11:45:04 +0530 | [diff] [blame] | 2483 | if (plane == OMAP_DSS_WB) { |
| 2484 | frame_width = out_width; |
| 2485 | frame_height = out_height; |
| 2486 | } else { |
| 2487 | frame_width = in_width; |
| 2488 | frame_height = height; |
| 2489 | } |
| 2490 | |
Tomi Valkeinen | 517a8a95 | 2017-05-03 14:14:27 +0300 | [diff] [blame^] | 2491 | calc_offset(screen_width, frame_width, |
| 2492 | color_mode, fieldmode, field_offset, |
| 2493 | &offset0, &offset1, &row_inc, &pix_inc, |
| 2494 | x_predecim, y_predecim); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2495 | |
| 2496 | DSSDBG("offset0 %u, offset1 %u, row_inc %d, pix_inc %d\n", |
| 2497 | offset0, offset1, row_inc, pix_inc); |
| 2498 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2499 | dispc_ovl_set_color_mode(plane, color_mode); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2500 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2501 | dispc_ovl_configure_burst_type(plane, rotation_type); |
Chandrabhanu Mahapatra | 65e006f | 2012-05-11 19:19:55 +0530 | [diff] [blame] | 2502 | |
Tomi Valkeinen | b7536d6 | 2016-01-13 18:41:36 +0200 | [diff] [blame] | 2503 | if (dispc.feat->reverse_ilace_field_order) |
| 2504 | swap(offset0, offset1); |
| 2505 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2506 | dispc_ovl_set_ba0(plane, paddr + offset0); |
| 2507 | dispc_ovl_set_ba1(plane, paddr + offset1); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2508 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2509 | if (OMAP_DSS_COLOR_NV12 == color_mode) { |
| 2510 | dispc_ovl_set_ba0_uv(plane, p_uv_addr + offset0); |
| 2511 | dispc_ovl_set_ba1_uv(plane, p_uv_addr + offset1); |
Amber Jain | 0d66cbb | 2011-05-19 19:47:54 +0530 | [diff] [blame] | 2512 | } |
| 2513 | |
Tomi Valkeinen | f2aee31 | 2015-04-10 12:48:34 +0300 | [diff] [blame] | 2514 | if (dispc.feat->last_pixel_inc_missing) |
| 2515 | row_inc += pix_inc - 1; |
| 2516 | |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 2517 | dispc_ovl_set_row_inc(plane, row_inc); |
| 2518 | dispc_ovl_set_pix_inc(plane, pix_inc); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2519 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2520 | DSSDBG("%d,%d %dx%d -> %dx%d\n", pos_x, pos_y, in_width, |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2521 | in_height, out_width, out_height); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2522 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2523 | dispc_ovl_set_pos(plane, caps, pos_x, pos_y); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2524 | |
Archit Taneja | 78b687f | 2012-09-21 14:51:49 +0530 | [diff] [blame] | 2525 | dispc_ovl_set_input_size(plane, in_width, in_height); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2526 | |
Archit Taneja | 5b54ed3 | 2012-09-26 16:55:27 +0530 | [diff] [blame] | 2527 | if (caps & OMAP_DSS_OVL_CAP_SCALE) { |
Chandrabhanu Mahapatra | aed74b55 | 2012-04-02 20:43:16 +0530 | [diff] [blame] | 2528 | dispc_ovl_set_scaling(plane, in_width, in_height, out_width, |
| 2529 | out_height, ilace, five_taps, fieldmode, |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2530 | color_mode, rotation); |
Archit Taneja | 78b687f | 2012-09-21 14:51:49 +0530 | [diff] [blame] | 2531 | dispc_ovl_set_output_size(plane, out_width, out_height); |
Tomi Valkeinen | f0e5caa | 2011-08-16 13:25:00 +0300 | [diff] [blame] | 2532 | dispc_ovl_set_vid_color_conv(plane, cconv); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2533 | } |
| 2534 | |
Archit Taneja | c35eeb2 | 2013-03-26 19:15:24 +0530 | [diff] [blame] | 2535 | dispc_ovl_set_rotation_attrs(plane, rotation, rotation_type, mirror, |
| 2536 | color_mode); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2537 | |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2538 | dispc_ovl_set_zorder(plane, caps, zorder); |
| 2539 | dispc_ovl_set_pre_mult_alpha(plane, caps, pre_mult_alpha); |
| 2540 | dispc_ovl_setup_global_alpha(plane, caps, global_alpha); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2541 | |
Archit Taneja | d79db85 | 2012-09-22 12:30:17 +0530 | [diff] [blame] | 2542 | dispc_ovl_enable_replication(plane, caps, replication); |
Archit Taneja | c3d92529 | 2011-09-14 11:52:54 +0530 | [diff] [blame] | 2543 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2544 | return 0; |
| 2545 | } |
| 2546 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 2547 | static int dispc_ovl_setup(enum omap_plane_id plane, |
Jyri Sarha | 273ffea | 2017-03-24 16:47:53 +0200 | [diff] [blame] | 2548 | const struct omap_overlay_info *oi, |
Tomi Valkeinen | 49a3057 | 2017-02-17 12:30:07 +0200 | [diff] [blame] | 2549 | const struct videomode *vm, bool mem_to_mem, |
| 2550 | enum omap_channel channel) |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2551 | { |
| 2552 | int r; |
Tomi Valkeinen | 16bf20c | 2012-10-15 15:33:22 +0300 | [diff] [blame] | 2553 | enum omap_overlay_caps caps = dss_feat_get_overlay_caps(plane); |
Tomi Valkeinen | be2d68c | 2016-08-29 13:15:02 +0300 | [diff] [blame] | 2554 | const bool replication = true; |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2555 | |
Arnd Bergmann | 24f13a6 | 2014-04-24 13:28:18 +0100 | [diff] [blame] | 2556 | DSSDBG("dispc_ovl_setup %d, pa %pad, pa_uv %pad, sw %d, %d,%d, %dx%d ->" |
| 2557 | " %dx%d, cmode %x, rot %d, mir %d, chan %d repl %d\n", |
| 2558 | plane, &oi->paddr, &oi->p_uv_addr, oi->screen_width, oi->pos_x, |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2559 | oi->pos_y, oi->width, oi->height, oi->out_width, oi->out_height, |
| 2560 | oi->color_mode, oi->rotation, oi->mirror, channel, replication); |
| 2561 | |
Tomi Valkeinen | 49a3057 | 2017-02-17 12:30:07 +0200 | [diff] [blame] | 2562 | dispc_ovl_set_channel_out(plane, channel); |
| 2563 | |
Tomi Valkeinen | 16bf20c | 2012-10-15 15:33:22 +0300 | [diff] [blame] | 2564 | r = dispc_ovl_setup_common(plane, caps, oi->paddr, oi->p_uv_addr, |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 2565 | oi->screen_width, oi->pos_x, oi->pos_y, oi->width, oi->height, |
| 2566 | oi->out_width, oi->out_height, oi->color_mode, oi->rotation, |
| 2567 | oi->mirror, oi->zorder, oi->pre_mult_alpha, oi->global_alpha, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2568 | oi->rotation_type, replication, vm, mem_to_mem); |
Archit Taneja | 84a880f | 2012-09-26 16:57:37 +0530 | [diff] [blame] | 2569 | |
| 2570 | return r; |
| 2571 | } |
| 2572 | |
Archit Taneja | 749feff | 2012-08-31 12:32:52 +0530 | [diff] [blame] | 2573 | int dispc_wb_setup(const struct omap_dss_writeback_info *wi, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2574 | bool mem_to_mem, const struct videomode *vm) |
Archit Taneja | 749feff | 2012-08-31 12:32:52 +0530 | [diff] [blame] | 2575 | { |
| 2576 | int r; |
Archit Taneja | 9e4a0fc | 2012-08-24 16:59:26 +0530 | [diff] [blame] | 2577 | u32 l; |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 2578 | enum omap_plane_id plane = OMAP_DSS_WB; |
Archit Taneja | 749feff | 2012-08-31 12:32:52 +0530 | [diff] [blame] | 2579 | const int pos_x = 0, pos_y = 0; |
| 2580 | const u8 zorder = 0, global_alpha = 0; |
Tomi Valkeinen | be2d68c | 2016-08-29 13:15:02 +0300 | [diff] [blame] | 2581 | const bool replication = true; |
Archit Taneja | 9e4a0fc | 2012-08-24 16:59:26 +0530 | [diff] [blame] | 2582 | bool truncation; |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2583 | int in_width = vm->hactive; |
| 2584 | int in_height = vm->vactive; |
Archit Taneja | 749feff | 2012-08-31 12:32:52 +0530 | [diff] [blame] | 2585 | enum omap_overlay_caps caps = |
| 2586 | OMAP_DSS_OVL_CAP_SCALE | OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA; |
| 2587 | |
| 2588 | DSSDBG("dispc_wb_setup, pa %x, pa_uv %x, %d,%d -> %dx%d, cmode %x, " |
| 2589 | "rot %d, mir %d\n", wi->paddr, wi->p_uv_addr, in_width, |
| 2590 | in_height, wi->width, wi->height, wi->color_mode, wi->rotation, |
| 2591 | wi->mirror); |
| 2592 | |
| 2593 | r = dispc_ovl_setup_common(plane, caps, wi->paddr, wi->p_uv_addr, |
| 2594 | wi->buf_width, pos_x, pos_y, in_width, in_height, wi->width, |
| 2595 | wi->height, wi->color_mode, wi->rotation, wi->mirror, zorder, |
| 2596 | wi->pre_mult_alpha, global_alpha, wi->rotation_type, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2597 | replication, vm, mem_to_mem); |
Archit Taneja | 9e4a0fc | 2012-08-24 16:59:26 +0530 | [diff] [blame] | 2598 | |
| 2599 | switch (wi->color_mode) { |
| 2600 | case OMAP_DSS_COLOR_RGB16: |
| 2601 | case OMAP_DSS_COLOR_RGB24P: |
| 2602 | case OMAP_DSS_COLOR_ARGB16: |
| 2603 | case OMAP_DSS_COLOR_RGBA16: |
| 2604 | case OMAP_DSS_COLOR_RGB12U: |
| 2605 | case OMAP_DSS_COLOR_ARGB16_1555: |
| 2606 | case OMAP_DSS_COLOR_XRGB16_1555: |
| 2607 | case OMAP_DSS_COLOR_RGBX16: |
| 2608 | truncation = true; |
| 2609 | break; |
| 2610 | default: |
| 2611 | truncation = false; |
| 2612 | break; |
| 2613 | } |
| 2614 | |
| 2615 | /* setup extra DISPC_WB_ATTRIBUTES */ |
| 2616 | l = dispc_read_reg(DISPC_OVL_ATTRIBUTES(plane)); |
| 2617 | l = FLD_MOD(l, truncation, 10, 10); /* TRUNCATIONENABLE */ |
| 2618 | l = FLD_MOD(l, mem_to_mem, 19, 19); /* WRITEBACKMODE */ |
Tomi Valkeinen | 4c055ce | 2015-11-04 17:10:53 +0200 | [diff] [blame] | 2619 | if (mem_to_mem) |
| 2620 | l = FLD_MOD(l, 1, 26, 24); /* CAPTUREMODE */ |
Tomi Valkeinen | 98cd579 | 2015-11-04 17:10:54 +0200 | [diff] [blame] | 2621 | else |
| 2622 | l = FLD_MOD(l, 0, 26, 24); /* CAPTUREMODE */ |
Archit Taneja | 9e4a0fc | 2012-08-24 16:59:26 +0530 | [diff] [blame] | 2623 | dispc_write_reg(DISPC_OVL_ATTRIBUTES(plane), l); |
Archit Taneja | 749feff | 2012-08-31 12:32:52 +0530 | [diff] [blame] | 2624 | |
Tomi Valkeinen | 98cd579 | 2015-11-04 17:10:54 +0200 | [diff] [blame] | 2625 | if (mem_to_mem) { |
| 2626 | /* WBDELAYCOUNT */ |
| 2627 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), 0, 7, 0); |
| 2628 | } else { |
| 2629 | int wbdelay; |
| 2630 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2631 | wbdelay = min(vm->vfront_porch + |
| 2632 | vm->vsync_len + vm->vback_porch, (u32)255); |
Tomi Valkeinen | 98cd579 | 2015-11-04 17:10:54 +0200 | [diff] [blame] | 2633 | |
| 2634 | /* WBDELAYCOUNT */ |
| 2635 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES2(plane), wbdelay, 7, 0); |
| 2636 | } |
| 2637 | |
Archit Taneja | 749feff | 2012-08-31 12:32:52 +0530 | [diff] [blame] | 2638 | return r; |
| 2639 | } |
| 2640 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 2641 | static int dispc_ovl_enable(enum omap_plane_id plane, bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2642 | { |
Tomi Valkeinen | e6d80f9 | 2011-05-19 14:12:26 +0300 | [diff] [blame] | 2643 | DSSDBG("dispc_enable_plane %d, %d\n", plane, enable); |
| 2644 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 2645 | REG_FLD_MOD(DISPC_OVL_ATTRIBUTES(plane), enable ? 1 : 0, 0, 0); |
Tomi Valkeinen | e6d80f9 | 2011-05-19 14:12:26 +0300 | [diff] [blame] | 2646 | |
| 2647 | return 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2648 | } |
| 2649 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 2650 | static enum omap_dss_output_id dispc_mgr_get_supported_outputs(enum omap_channel channel) |
Tomi Valkeinen | 7b9cb5e | 2015-11-04 15:11:25 +0200 | [diff] [blame] | 2651 | { |
| 2652 | return dss_feat_get_supported_outputs(channel); |
| 2653 | } |
Tomi Valkeinen | 7b9cb5e | 2015-11-04 15:11:25 +0200 | [diff] [blame] | 2654 | |
Tomi Valkeinen | fb2cec1 | 2012-09-12 13:30:39 +0300 | [diff] [blame] | 2655 | static void dispc_lcd_enable_signal_polarity(bool act_high) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2656 | { |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame] | 2657 | if (!dss_has_feature(FEAT_LCDENABLEPOL)) |
| 2658 | return; |
| 2659 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2660 | REG_FLD_MOD(DISPC_CONTROL, act_high ? 1 : 0, 29, 29); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | void dispc_lcd_enable_signal(bool enable) |
| 2664 | { |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame] | 2665 | if (!dss_has_feature(FEAT_LCDENABLESIGNAL)) |
| 2666 | return; |
| 2667 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2668 | REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 28, 28); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | void dispc_pck_free_enable(bool enable) |
| 2672 | { |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame] | 2673 | if (!dss_has_feature(FEAT_PCKFREEENABLE)) |
| 2674 | return; |
| 2675 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2676 | REG_FLD_MOD(DISPC_CONTROL, enable ? 1 : 0, 27, 27); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2677 | } |
| 2678 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 2679 | static int dispc_get_num_mgrs(void) |
Tomi Valkeinen | c283400 | 2015-11-05 19:54:33 +0200 | [diff] [blame] | 2680 | { |
| 2681 | return dss_feat_get_num_mgrs(); |
| 2682 | } |
Tomi Valkeinen | c283400 | 2015-11-05 19:54:33 +0200 | [diff] [blame] | 2683 | |
Tomi Valkeinen | fb2cec1 | 2012-09-12 13:30:39 +0300 | [diff] [blame] | 2684 | static void dispc_mgr_enable_fifohandcheck(enum omap_channel channel, bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2685 | { |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 2686 | mgr_fld_write(channel, DISPC_MGR_FLD_FIFOHANDCHECK, enable); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | |
Tomi Valkeinen | fb2cec1 | 2012-09-12 13:30:39 +0300 | [diff] [blame] | 2690 | static void dispc_mgr_set_lcd_type_tft(enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2691 | { |
Archit Taneja | d21f43b | 2012-06-21 09:45:11 +0530 | [diff] [blame] | 2692 | mgr_fld_write(channel, DISPC_MGR_FLD_STNTFT, 1); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2693 | } |
| 2694 | |
Tomi Valkeinen | 6590415 | 2015-11-04 17:10:57 +0200 | [diff] [blame] | 2695 | static void dispc_set_loadmode(enum omap_dss_load_mode mode) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2696 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2697 | REG_FLD_MOD(DISPC_CONFIG, mode, 2, 1); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | |
Tomi Valkeinen | c64dca4 | 2011-11-04 18:14:20 +0200 | [diff] [blame] | 2701 | static void dispc_mgr_set_default_color(enum omap_channel channel, u32 color) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2702 | { |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2703 | dispc_write_reg(DISPC_DEFAULT_COLOR(channel), color); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2704 | } |
| 2705 | |
Tomi Valkeinen | c64dca4 | 2011-11-04 18:14:20 +0200 | [diff] [blame] | 2706 | static void dispc_mgr_set_trans_key(enum omap_channel ch, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2707 | enum omap_dss_trans_key_type type, |
| 2708 | u32 trans_key) |
| 2709 | { |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 2710 | mgr_fld_write(ch, DISPC_MGR_FLD_TCKSELECTION, type); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2711 | |
Sumit Semwal | 8613b00 | 2010-12-02 11:27:09 +0000 | [diff] [blame] | 2712 | dispc_write_reg(DISPC_TRANS_COLOR(ch), trans_key); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2713 | } |
| 2714 | |
Tomi Valkeinen | c64dca4 | 2011-11-04 18:14:20 +0200 | [diff] [blame] | 2715 | static void dispc_mgr_enable_trans_key(enum omap_channel ch, bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2716 | { |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 2717 | mgr_fld_write(ch, DISPC_MGR_FLD_TCKENABLE, enable); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2718 | } |
Archit Taneja | 11354dd | 2011-09-26 11:47:29 +0530 | [diff] [blame] | 2719 | |
Tomi Valkeinen | c64dca4 | 2011-11-04 18:14:20 +0200 | [diff] [blame] | 2720 | static void dispc_mgr_enable_alpha_fixed_zorder(enum omap_channel ch, |
| 2721 | bool enable) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2722 | { |
Archit Taneja | 11354dd | 2011-09-26 11:47:29 +0530 | [diff] [blame] | 2723 | if (!dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2724 | return; |
| 2725 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2726 | if (ch == OMAP_DSS_CHANNEL_LCD) |
| 2727 | REG_FLD_MOD(DISPC_CONFIG, enable, 18, 18); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 2728 | else if (ch == OMAP_DSS_CHANNEL_DIGIT) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2729 | REG_FLD_MOD(DISPC_CONFIG, enable, 19, 19); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2730 | } |
Archit Taneja | 11354dd | 2011-09-26 11:47:29 +0530 | [diff] [blame] | 2731 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 2732 | static void dispc_mgr_setup(enum omap_channel channel, |
Tomi Valkeinen | a8f3fcd | 2012-10-03 09:09:11 +0200 | [diff] [blame] | 2733 | const struct omap_overlay_manager_info *info) |
Tomi Valkeinen | c64dca4 | 2011-11-04 18:14:20 +0200 | [diff] [blame] | 2734 | { |
| 2735 | dispc_mgr_set_default_color(channel, info->default_color); |
| 2736 | dispc_mgr_set_trans_key(channel, info->trans_key_type, info->trans_key); |
| 2737 | dispc_mgr_enable_trans_key(channel, info->trans_enabled); |
| 2738 | dispc_mgr_enable_alpha_fixed_zorder(channel, |
| 2739 | info->partial_alpha_enabled); |
| 2740 | if (dss_has_feature(FEAT_CPR)) { |
| 2741 | dispc_mgr_enable_cpr(channel, info->cpr_enable); |
| 2742 | dispc_mgr_set_cpr_coef(channel, &info->cpr_coefs); |
| 2743 | } |
| 2744 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2745 | |
Tomi Valkeinen | fb2cec1 | 2012-09-12 13:30:39 +0300 | [diff] [blame] | 2746 | static void dispc_mgr_set_tft_data_lines(enum omap_channel channel, u8 data_lines) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2747 | { |
| 2748 | int code; |
| 2749 | |
| 2750 | switch (data_lines) { |
| 2751 | case 12: |
| 2752 | code = 0; |
| 2753 | break; |
| 2754 | case 16: |
| 2755 | code = 1; |
| 2756 | break; |
| 2757 | case 18: |
| 2758 | code = 2; |
| 2759 | break; |
| 2760 | case 24: |
| 2761 | code = 3; |
| 2762 | break; |
| 2763 | default: |
| 2764 | BUG(); |
| 2765 | return; |
| 2766 | } |
| 2767 | |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 2768 | mgr_fld_write(channel, DISPC_MGR_FLD_TFTDATALINES, code); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2769 | } |
| 2770 | |
Tomi Valkeinen | fb2cec1 | 2012-09-12 13:30:39 +0300 | [diff] [blame] | 2771 | static void dispc_mgr_set_io_pad_mode(enum dss_io_pad_mode mode) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2772 | { |
| 2773 | u32 l; |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 2774 | int gpout0, gpout1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2775 | |
| 2776 | switch (mode) { |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 2777 | case DSS_IO_PAD_MODE_RESET: |
| 2778 | gpout0 = 0; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2779 | gpout1 = 0; |
| 2780 | break; |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 2781 | case DSS_IO_PAD_MODE_RFBI: |
| 2782 | gpout0 = 1; |
| 2783 | gpout1 = 0; |
| 2784 | break; |
| 2785 | case DSS_IO_PAD_MODE_BYPASS: |
| 2786 | gpout0 = 1; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2787 | gpout1 = 1; |
| 2788 | break; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2789 | default: |
| 2790 | BUG(); |
| 2791 | return; |
| 2792 | } |
| 2793 | |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 2794 | l = dispc_read_reg(DISPC_CONTROL); |
| 2795 | l = FLD_MOD(l, gpout0, 15, 15); |
| 2796 | l = FLD_MOD(l, gpout1, 16, 16); |
| 2797 | dispc_write_reg(DISPC_CONTROL, l); |
| 2798 | } |
| 2799 | |
Tomi Valkeinen | fb2cec1 | 2012-09-12 13:30:39 +0300 | [diff] [blame] | 2800 | static void dispc_mgr_enable_stallmode(enum omap_channel channel, bool enable) |
Archit Taneja | 569969d | 2011-08-22 17:41:57 +0530 | [diff] [blame] | 2801 | { |
Chandrabhanu Mahapatra | efa70b3 | 2012-06-21 11:07:44 +0530 | [diff] [blame] | 2802 | mgr_fld_write(channel, DISPC_MGR_FLD_STALLMODE, enable); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2803 | } |
| 2804 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 2805 | static void dispc_mgr_set_lcd_config(enum omap_channel channel, |
Tomi Valkeinen | fb2cec1 | 2012-09-12 13:30:39 +0300 | [diff] [blame] | 2806 | const struct dss_lcd_mgr_config *config) |
| 2807 | { |
| 2808 | dispc_mgr_set_io_pad_mode(config->io_pad_mode); |
| 2809 | |
| 2810 | dispc_mgr_enable_stallmode(channel, config->stallmode); |
| 2811 | dispc_mgr_enable_fifohandcheck(channel, config->fifohandcheck); |
| 2812 | |
| 2813 | dispc_mgr_set_clock_div(channel, &config->clock_info); |
| 2814 | |
| 2815 | dispc_mgr_set_tft_data_lines(channel, config->video_port_width); |
| 2816 | |
| 2817 | dispc_lcd_enable_signal_polarity(config->lcden_sig_polarity); |
| 2818 | |
| 2819 | dispc_mgr_set_lcd_type_tft(channel); |
| 2820 | } |
| 2821 | |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 2822 | static bool _dispc_mgr_size_ok(u16 width, u16 height) |
| 2823 | { |
Archit Taneja | 33b8992 | 2012-11-14 13:50:15 +0530 | [diff] [blame] | 2824 | return width <= dispc.feat->mgr_width_max && |
| 2825 | height <= dispc.feat->mgr_height_max; |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 2826 | } |
| 2827 | |
Peter Ujfalusi | 4dc2250 | 2016-09-22 14:06:48 +0300 | [diff] [blame] | 2828 | static bool _dispc_lcd_timings_ok(int hsync_len, int hfp, int hbp, |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2829 | int vsw, int vfp, int vbp) |
| 2830 | { |
Peter Ujfalusi | 4dc2250 | 2016-09-22 14:06:48 +0300 | [diff] [blame] | 2831 | if (hsync_len < 1 || hsync_len > dispc.feat->sw_max || |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 2832 | hfp < 1 || hfp > dispc.feat->hp_max || |
| 2833 | hbp < 1 || hbp > dispc.feat->hp_max || |
| 2834 | vsw < 1 || vsw > dispc.feat->sw_max || |
| 2835 | vfp < 0 || vfp > dispc.feat->vp_max || |
| 2836 | vbp < 0 || vbp > dispc.feat->vp_max) |
| 2837 | return false; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2838 | return true; |
| 2839 | } |
| 2840 | |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 2841 | static bool _dispc_mgr_pclk_ok(enum omap_channel channel, |
| 2842 | unsigned long pclk) |
| 2843 | { |
| 2844 | if (dss_mgr_is_lcd(channel)) |
Andrew F. Davis | 0cac5b6 | 2016-07-01 09:27:21 -0500 | [diff] [blame] | 2845 | return pclk <= dispc.feat->max_lcd_pclk; |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 2846 | else |
Andrew F. Davis | 0cac5b6 | 2016-07-01 09:27:21 -0500 | [diff] [blame] | 2847 | return pclk <= dispc.feat->max_tv_pclk; |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 2848 | } |
| 2849 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2850 | bool dispc_mgr_timings_ok(enum omap_channel channel, const struct videomode *vm) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2851 | { |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2852 | if (!_dispc_mgr_size_ok(vm->hactive, vm->vactive)) |
Tomi Valkeinen | eadd33b | 2014-06-05 11:36:08 +0300 | [diff] [blame] | 2853 | return false; |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 2854 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2855 | if (!_dispc_mgr_pclk_ok(channel, vm->pixelclock)) |
Tomi Valkeinen | eadd33b | 2014-06-05 11:36:08 +0300 | [diff] [blame] | 2856 | return false; |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 2857 | |
| 2858 | if (dss_mgr_is_lcd(channel)) { |
Tomi Valkeinen | beb8384 | 2014-06-05 11:35:10 +0300 | [diff] [blame] | 2859 | /* TODO: OMAP4+ supports interlace for LCD outputs */ |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2860 | if (vm->flags & DISPLAY_FLAGS_INTERLACED) |
Tomi Valkeinen | eadd33b | 2014-06-05 11:36:08 +0300 | [diff] [blame] | 2861 | return false; |
Tomi Valkeinen | beb8384 | 2014-06-05 11:35:10 +0300 | [diff] [blame] | 2862 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2863 | if (!_dispc_lcd_timings_ok(vm->hsync_len, |
| 2864 | vm->hfront_porch, vm->hback_porch, |
| 2865 | vm->vsync_len, vm->vfront_porch, |
| 2866 | vm->vback_porch)) |
Tomi Valkeinen | eadd33b | 2014-06-05 11:36:08 +0300 | [diff] [blame] | 2867 | return false; |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 2868 | } |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 2869 | |
Tomi Valkeinen | eadd33b | 2014-06-05 11:36:08 +0300 | [diff] [blame] | 2870 | return true; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2871 | } |
| 2872 | |
Peter Ujfalusi | 3b59293 | 2016-09-22 14:06:56 +0300 | [diff] [blame] | 2873 | static void _dispc_mgr_set_lcd_timings(enum omap_channel channel, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2874 | const struct videomode *vm) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2875 | { |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2876 | u32 timing_h, timing_v, l; |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2877 | bool onoff, rf, ipc, vs, hs, de; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2878 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2879 | timing_h = FLD_VAL(vm->hsync_len - 1, dispc.feat->sw_start, 0) | |
| 2880 | FLD_VAL(vm->hfront_porch - 1, dispc.feat->fp_start, 8) | |
| 2881 | FLD_VAL(vm->hback_porch - 1, dispc.feat->bp_start, 20); |
| 2882 | timing_v = FLD_VAL(vm->vsync_len - 1, dispc.feat->sw_start, 0) | |
| 2883 | FLD_VAL(vm->vfront_porch, dispc.feat->fp_start, 8) | |
| 2884 | FLD_VAL(vm->vback_porch, dispc.feat->bp_start, 20); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2885 | |
Sumit Semwal | 64ba4f7 | 2010-12-02 11:27:10 +0000 | [diff] [blame] | 2886 | dispc_write_reg(DISPC_TIMING_H(channel), timing_h); |
| 2887 | dispc_write_reg(DISPC_TIMING_V(channel), timing_v); |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2888 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2889 | if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH) |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2890 | vs = false; |
Peter Ujfalusi | 6b44cd2 | 2016-09-22 14:06:57 +0300 | [diff] [blame] | 2891 | else |
| 2892 | vs = true; |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2893 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2894 | if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH) |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2895 | hs = false; |
Peter Ujfalusi | 6b44cd2 | 2016-09-22 14:06:57 +0300 | [diff] [blame] | 2896 | else |
| 2897 | hs = true; |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2898 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2899 | if (vm->flags & DISPLAY_FLAGS_DE_HIGH) |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2900 | de = false; |
Peter Ujfalusi | 3fa3ab4 | 2016-09-22 14:06:58 +0300 | [diff] [blame] | 2901 | else |
| 2902 | de = true; |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2903 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2904 | if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE) |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2905 | ipc = false; |
Peter Ujfalusi | f149e17 | 2016-09-22 14:07:00 +0300 | [diff] [blame] | 2906 | else |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2907 | ipc = true; |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2908 | |
Tomi Valkeinen | 7a16360 | 2014-10-02 17:58:48 +0000 | [diff] [blame] | 2909 | /* always use the 'rf' setting */ |
| 2910 | onoff = true; |
| 2911 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2912 | if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE) |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2913 | rf = true; |
Peter Ujfalusi | d34afb7 | 2016-09-22 14:07:01 +0300 | [diff] [blame] | 2914 | else |
| 2915 | rf = false; |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2916 | |
Tomi Valkeinen | d80e02e | 2014-04-25 11:46:16 +0300 | [diff] [blame] | 2917 | l = FLD_VAL(onoff, 17, 17) | |
| 2918 | FLD_VAL(rf, 16, 16) | |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2919 | FLD_VAL(de, 15, 15) | |
Tomi Valkeinen | d80e02e | 2014-04-25 11:46:16 +0300 | [diff] [blame] | 2920 | FLD_VAL(ipc, 14, 14) | |
Tomi Valkeinen | ed35188 | 2014-10-02 17:58:49 +0000 | [diff] [blame] | 2921 | FLD_VAL(hs, 13, 13) | |
| 2922 | FLD_VAL(vs, 12, 12); |
Tomi Valkeinen | d80e02e | 2014-04-25 11:46:16 +0300 | [diff] [blame] | 2923 | |
Tomi Valkeinen | e5f8091 | 2015-10-21 13:08:59 +0300 | [diff] [blame] | 2924 | /* always set ALIGN bit when available */ |
| 2925 | if (dispc.feat->supports_sync_align) |
| 2926 | l |= (1 << 18); |
| 2927 | |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2928 | dispc_write_reg(DISPC_POL_FREQ(channel), l); |
Tomi Valkeinen | 0006fd6 | 2014-09-05 19:15:03 +0000 | [diff] [blame] | 2929 | |
| 2930 | if (dispc.syscon_pol) { |
| 2931 | const int shifts[] = { |
| 2932 | [OMAP_DSS_CHANNEL_LCD] = 0, |
| 2933 | [OMAP_DSS_CHANNEL_LCD2] = 1, |
| 2934 | [OMAP_DSS_CHANNEL_LCD3] = 2, |
| 2935 | }; |
| 2936 | |
| 2937 | u32 mask, val; |
| 2938 | |
| 2939 | mask = (1 << 0) | (1 << 3) | (1 << 6); |
| 2940 | val = (rf << 0) | (ipc << 3) | (onoff << 6); |
| 2941 | |
| 2942 | mask <<= 16 + shifts[channel]; |
| 2943 | val <<= 16 + shifts[channel]; |
| 2944 | |
| 2945 | regmap_update_bits(dispc.syscon_pol, dispc.syscon_pol_offset, |
| 2946 | mask, val); |
| 2947 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2948 | } |
| 2949 | |
Tomi Valkeinen | 956d4f9 | 2016-11-23 13:23:42 +0200 | [diff] [blame] | 2950 | static int vm_flag_to_int(enum display_flags flags, enum display_flags high, |
| 2951 | enum display_flags low) |
| 2952 | { |
| 2953 | if (flags & high) |
| 2954 | return 1; |
| 2955 | if (flags & low) |
| 2956 | return -1; |
| 2957 | return 0; |
| 2958 | } |
| 2959 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2960 | /* change name to mode? */ |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 2961 | static void dispc_mgr_set_timings(enum omap_channel channel, |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2962 | const struct videomode *vm) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2963 | { |
| 2964 | unsigned xtot, ytot; |
| 2965 | unsigned long ht, vt; |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2966 | struct videomode t = *vm; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2967 | |
Peter Ujfalusi | fb7f3c4 | 2016-09-22 14:06:47 +0300 | [diff] [blame] | 2968 | DSSDBG("channel %d xres %u yres %u\n", channel, t.hactive, t.vactive); |
Archit Taneja | c51d921 | 2012-04-16 12:53:43 +0530 | [diff] [blame] | 2969 | |
Archit Taneja | 2aefad4 | 2012-05-18 14:36:54 +0530 | [diff] [blame] | 2970 | if (!dispc_mgr_timings_ok(channel, &t)) { |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 2971 | BUG(); |
Tomi Valkeinen | c6eee96 | 2012-05-18 11:47:02 +0300 | [diff] [blame] | 2972 | return; |
| 2973 | } |
Archit Taneja | c51d921 | 2012-04-16 12:53:43 +0530 | [diff] [blame] | 2974 | |
Archit Taneja | dd88b7a | 2012-06-29 14:41:30 +0530 | [diff] [blame] | 2975 | if (dss_mgr_is_lcd(channel)) { |
Peter Ujfalusi | 3b59293 | 2016-09-22 14:06:56 +0300 | [diff] [blame] | 2976 | _dispc_mgr_set_lcd_timings(channel, &t); |
Archit Taneja | c51d921 | 2012-04-16 12:53:43 +0530 | [diff] [blame] | 2977 | |
Peter Ujfalusi | a85f4a8 | 2016-09-22 14:06:50 +0300 | [diff] [blame] | 2978 | xtot = t.hactive + t.hfront_porch + t.hsync_len + t.hback_porch; |
Peter Ujfalusi | 458540c | 2016-09-22 14:06:53 +0300 | [diff] [blame] | 2979 | ytot = t.vactive + t.vfront_porch + t.vsync_len + t.vback_porch; |
Archit Taneja | c51d921 | 2012-04-16 12:53:43 +0530 | [diff] [blame] | 2980 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2981 | ht = vm->pixelclock / xtot; |
| 2982 | vt = vm->pixelclock / xtot / ytot; |
Archit Taneja | c51d921 | 2012-04-16 12:53:43 +0530 | [diff] [blame] | 2983 | |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 2984 | DSSDBG("pck %lu\n", vm->pixelclock); |
Peter Ujfalusi | 4dc2250 | 2016-09-22 14:06:48 +0300 | [diff] [blame] | 2985 | DSSDBG("hsync_len %d hfp %d hbp %d vsw %d vfp %d vbp %d\n", |
Peter Ujfalusi | a85f4a8 | 2016-09-22 14:06:50 +0300 | [diff] [blame] | 2986 | t.hsync_len, t.hfront_porch, t.hback_porch, |
Peter Ujfalusi | 458540c | 2016-09-22 14:06:53 +0300 | [diff] [blame] | 2987 | t.vsync_len, t.vfront_porch, t.vback_porch); |
Archit Taneja | 655e294 | 2012-06-21 10:37:43 +0530 | [diff] [blame] | 2988 | DSSDBG("vsync_level %d hsync_level %d data_pclk_edge %d de_level %d sync_pclk_edge %d\n", |
Tomi Valkeinen | 956d4f9 | 2016-11-23 13:23:42 +0200 | [diff] [blame] | 2989 | vm_flag_to_int(t.flags, DISPLAY_FLAGS_VSYNC_HIGH, DISPLAY_FLAGS_VSYNC_LOW), |
| 2990 | vm_flag_to_int(t.flags, DISPLAY_FLAGS_HSYNC_HIGH, DISPLAY_FLAGS_HSYNC_LOW), |
| 2991 | vm_flag_to_int(t.flags, DISPLAY_FLAGS_PIXDATA_POSEDGE, DISPLAY_FLAGS_PIXDATA_NEGEDGE), |
| 2992 | vm_flag_to_int(t.flags, DISPLAY_FLAGS_DE_HIGH, DISPLAY_FLAGS_DE_LOW), |
| 2993 | vm_flag_to_int(t.flags, DISPLAY_FLAGS_SYNC_POSEDGE, DISPLAY_FLAGS_SYNC_NEGEDGE)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 2994 | |
Archit Taneja | c51d921 | 2012-04-16 12:53:43 +0530 | [diff] [blame] | 2995 | DSSDBG("hsync %luHz, vsync %luHz\n", ht, vt); |
Archit Taneja | 2aefad4 | 2012-05-18 14:36:54 +0530 | [diff] [blame] | 2996 | } else { |
Peter Ujfalusi | 5305829 | 2016-09-22 14:06:55 +0300 | [diff] [blame] | 2997 | if (t.flags & DISPLAY_FLAGS_INTERLACED) |
Peter Ujfalusi | fb7f3c4 | 2016-09-22 14:06:47 +0300 | [diff] [blame] | 2998 | t.vactive /= 2; |
Tomi Valkeinen | 3a38ed53 | 2016-01-13 18:41:31 +0200 | [diff] [blame] | 2999 | |
| 3000 | if (dispc.feat->supports_double_pixel) |
Peter Ujfalusi | 531efb3 | 2016-09-22 14:06:59 +0300 | [diff] [blame] | 3001 | REG_FLD_MOD(DISPC_CONTROL, |
| 3002 | !!(t.flags & DISPLAY_FLAGS_DOUBLECLK), |
| 3003 | 19, 17); |
Archit Taneja | c51d921 | 2012-04-16 12:53:43 +0530 | [diff] [blame] | 3004 | } |
Archit Taneja | 8f36616 | 2012-04-16 12:53:44 +0530 | [diff] [blame] | 3005 | |
Peter Ujfalusi | fb7f3c4 | 2016-09-22 14:06:47 +0300 | [diff] [blame] | 3006 | dispc_mgr_set_size(channel, t.hactive, t.vactive); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3007 | } |
| 3008 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 3009 | static void dispc_mgr_set_lcd_divisor(enum omap_channel channel, u16 lck_div, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 3010 | u16 pck_div) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3011 | { |
| 3012 | BUG_ON(lck_div < 1); |
Tomi Valkeinen | 9eaaf20 | 2011-08-29 15:56:04 +0300 | [diff] [blame] | 3013 | BUG_ON(pck_div < 1); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3014 | |
Murthy, Raghuveer | ce7fa5e | 2011-03-03 09:27:59 -0600 | [diff] [blame] | 3015 | dispc_write_reg(DISPC_DIVISORo(channel), |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3016 | FLD_VAL(lck_div, 23, 16) | FLD_VAL(pck_div, 7, 0)); |
Tomi Valkeinen | 7b3926b | 2013-03-06 15:54:11 +0200 | [diff] [blame] | 3017 | |
Luis de Bethencourt | 0bcfdba | 2015-10-15 13:29:38 +0100 | [diff] [blame] | 3018 | if (!dss_has_feature(FEAT_CORE_CLK_DIV) && |
Tomi Valkeinen | 7b3926b | 2013-03-06 15:54:11 +0200 | [diff] [blame] | 3019 | channel == OMAP_DSS_CHANNEL_LCD) |
| 3020 | dispc.core_clk_rate = dispc_fclk_rate() / lck_div; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3021 | } |
| 3022 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 3023 | static void dispc_mgr_get_lcd_divisor(enum omap_channel channel, int *lck_div, |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3024 | int *pck_div) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3025 | { |
| 3026 | u32 l; |
Murthy, Raghuveer | ce7fa5e | 2011-03-03 09:27:59 -0600 | [diff] [blame] | 3027 | l = dispc_read_reg(DISPC_DIVISORo(channel)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3028 | *lck_div = FLD_GET(l, 23, 16); |
| 3029 | *pck_div = FLD_GET(l, 7, 0); |
| 3030 | } |
| 3031 | |
Tomi Valkeinen | 6590415 | 2015-11-04 17:10:57 +0200 | [diff] [blame] | 3032 | static unsigned long dispc_fclk_rate(void) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3033 | { |
Tomi Valkeinen | ef03b40 | 2016-05-18 13:52:14 +0300 | [diff] [blame] | 3034 | unsigned long r; |
| 3035 | enum dss_clk_source src; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3036 | |
Tomi Valkeinen | ef03b40 | 2016-05-18 13:52:14 +0300 | [diff] [blame] | 3037 | src = dss_get_dispc_clk_source(); |
| 3038 | |
| 3039 | if (src == DSS_CLK_SRC_FCK) { |
Tomi Valkeinen | 5aaee69 | 2012-12-12 10:37:03 +0200 | [diff] [blame] | 3040 | r = dss_get_dispc_clk_rate(); |
Tomi Valkeinen | ef03b40 | 2016-05-18 13:52:14 +0300 | [diff] [blame] | 3041 | } else { |
| 3042 | struct dss_pll *pll; |
| 3043 | unsigned clkout_idx; |
Tomi Valkeinen | 9355092 | 2014-12-31 11:25:48 +0200 | [diff] [blame] | 3044 | |
Tomi Valkeinen | ef03b40 | 2016-05-18 13:52:14 +0300 | [diff] [blame] | 3045 | pll = dss_pll_find_by_src(src); |
| 3046 | clkout_idx = dss_pll_get_clkout_idx_for_src(src); |
Tomi Valkeinen | 9355092 | 2014-12-31 11:25:48 +0200 | [diff] [blame] | 3047 | |
Tomi Valkeinen | ef03b40 | 2016-05-18 13:52:14 +0300 | [diff] [blame] | 3048 | r = pll->cinfo.clkout[clkout_idx]; |
Taneja, Archit | 66534e8 | 2011-03-08 05:50:34 -0600 | [diff] [blame] | 3049 | } |
| 3050 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3051 | return r; |
| 3052 | } |
| 3053 | |
Tomi Valkeinen | 6590415 | 2015-11-04 17:10:57 +0200 | [diff] [blame] | 3054 | static unsigned long dispc_mgr_lclk_rate(enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3055 | { |
| 3056 | int lcd; |
| 3057 | unsigned long r; |
Tomi Valkeinen | 0157577 | 2016-05-17 16:08:34 +0300 | [diff] [blame] | 3058 | enum dss_clk_source src; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3059 | |
Tomi Valkeinen | 0157577 | 2016-05-17 16:08:34 +0300 | [diff] [blame] | 3060 | /* for TV, LCLK rate is the FCLK rate */ |
| 3061 | if (!dss_mgr_is_lcd(channel)) |
Tomi Valkeinen | c31cba8 | 2012-10-23 11:50:10 +0300 | [diff] [blame] | 3062 | return dispc_fclk_rate(); |
Tomi Valkeinen | 0157577 | 2016-05-17 16:08:34 +0300 | [diff] [blame] | 3063 | |
| 3064 | src = dss_get_lcd_clk_source(channel); |
| 3065 | |
| 3066 | if (src == DSS_CLK_SRC_FCK) { |
| 3067 | r = dss_get_dispc_clk_rate(); |
| 3068 | } else { |
| 3069 | struct dss_pll *pll; |
| 3070 | unsigned clkout_idx; |
| 3071 | |
| 3072 | pll = dss_pll_find_by_src(src); |
| 3073 | clkout_idx = dss_pll_get_clkout_idx_for_src(src); |
| 3074 | |
| 3075 | r = pll->cinfo.clkout[clkout_idx]; |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 3076 | } |
Tomi Valkeinen | 0157577 | 2016-05-17 16:08:34 +0300 | [diff] [blame] | 3077 | |
| 3078 | lcd = REG_GET(DISPC_DIVISORo(channel), 23, 16); |
| 3079 | |
| 3080 | return r / lcd; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3081 | } |
| 3082 | |
Tomi Valkeinen | 6590415 | 2015-11-04 17:10:57 +0200 | [diff] [blame] | 3083 | static unsigned long dispc_mgr_pclk_rate(enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3084 | { |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3085 | unsigned long r; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3086 | |
Archit Taneja | dd88b7a | 2012-06-29 14:41:30 +0530 | [diff] [blame] | 3087 | if (dss_mgr_is_lcd(channel)) { |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 3088 | int pcd; |
| 3089 | u32 l; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3090 | |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 3091 | l = dispc_read_reg(DISPC_DIVISORo(channel)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3092 | |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 3093 | pcd = FLD_GET(l, 7, 0); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3094 | |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 3095 | r = dispc_mgr_lclk_rate(channel); |
| 3096 | |
| 3097 | return r / pcd; |
| 3098 | } else { |
Tomi Valkeinen | 5391e87 | 2013-05-16 10:44:13 +0300 | [diff] [blame] | 3099 | return dispc.tv_pclk_rate; |
Archit Taneja | c3dc6a7 | 2011-09-13 18:28:41 +0530 | [diff] [blame] | 3100 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3101 | } |
| 3102 | |
Tomi Valkeinen | 5391e87 | 2013-05-16 10:44:13 +0300 | [diff] [blame] | 3103 | void dispc_set_tv_pclk(unsigned long pclk) |
| 3104 | { |
| 3105 | dispc.tv_pclk_rate = pclk; |
| 3106 | } |
| 3107 | |
Tomi Valkeinen | 6590415 | 2015-11-04 17:10:57 +0200 | [diff] [blame] | 3108 | static unsigned long dispc_core_clk_rate(void) |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 3109 | { |
Tomi Valkeinen | 7b3926b | 2013-03-06 15:54:11 +0200 | [diff] [blame] | 3110 | return dispc.core_clk_rate; |
Chandrabhanu Mahapatra | 8b53d99 | 2012-04-23 12:16:50 +0530 | [diff] [blame] | 3111 | } |
| 3112 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 3113 | static unsigned long dispc_plane_pclk_rate(enum omap_plane_id plane) |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 3114 | { |
Tomi Valkeinen | 251886d | 2012-11-15 13:20:02 +0200 | [diff] [blame] | 3115 | enum omap_channel channel; |
| 3116 | |
| 3117 | if (plane == OMAP_DSS_WB) |
| 3118 | return 0; |
| 3119 | |
| 3120 | channel = dispc_ovl_get_channel_out(plane); |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 3121 | |
| 3122 | return dispc_mgr_pclk_rate(channel); |
| 3123 | } |
| 3124 | |
Jyri Sarha | 864050c | 2017-03-24 16:47:52 +0200 | [diff] [blame] | 3125 | static unsigned long dispc_plane_lclk_rate(enum omap_plane_id plane) |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 3126 | { |
Tomi Valkeinen | 251886d | 2012-11-15 13:20:02 +0200 | [diff] [blame] | 3127 | enum omap_channel channel; |
| 3128 | |
| 3129 | if (plane == OMAP_DSS_WB) |
| 3130 | return 0; |
| 3131 | |
| 3132 | channel = dispc_ovl_get_channel_out(plane); |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 3133 | |
Tomi Valkeinen | c31cba8 | 2012-10-23 11:50:10 +0300 | [diff] [blame] | 3134 | return dispc_mgr_lclk_rate(channel); |
Archit Taneja | 3e8a6ff | 2012-09-26 16:58:52 +0530 | [diff] [blame] | 3135 | } |
Tomi Valkeinen | c31cba8 | 2012-10-23 11:50:10 +0300 | [diff] [blame] | 3136 | |
Chandrabhanu Mahapatra | 6f1891f | 2012-06-21 11:23:56 +0530 | [diff] [blame] | 3137 | static void dispc_dump_clocks_channel(struct seq_file *s, enum omap_channel channel) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3138 | { |
| 3139 | int lcd, pcd; |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame] | 3140 | enum dss_clk_source lcd_clk_src; |
Chandrabhanu Mahapatra | 6f1891f | 2012-06-21 11:23:56 +0530 | [diff] [blame] | 3141 | |
| 3142 | seq_printf(s, "- %s -\n", mgr_desc[channel].name); |
| 3143 | |
| 3144 | lcd_clk_src = dss_get_lcd_clk_source(channel); |
| 3145 | |
Tomi Valkeinen | 557a154 | 2016-05-17 13:49:18 +0300 | [diff] [blame] | 3146 | seq_printf(s, "%s clk source = %s\n", mgr_desc[channel].name, |
Tomi Valkeinen | 407bd56 | 2016-05-17 13:50:55 +0300 | [diff] [blame] | 3147 | dss_get_clk_source_name(lcd_clk_src)); |
Chandrabhanu Mahapatra | 6f1891f | 2012-06-21 11:23:56 +0530 | [diff] [blame] | 3148 | |
| 3149 | dispc_mgr_get_lcd_divisor(channel, &lcd, &pcd); |
| 3150 | |
| 3151 | seq_printf(s, "lck\t\t%-16lulck div\t%u\n", |
| 3152 | dispc_mgr_lclk_rate(channel), lcd); |
| 3153 | seq_printf(s, "pck\t\t%-16lupck div\t%u\n", |
| 3154 | dispc_mgr_pclk_rate(channel), pcd); |
| 3155 | } |
| 3156 | |
| 3157 | void dispc_dump_clocks(struct seq_file *s) |
| 3158 | { |
| 3159 | int lcd; |
Murthy, Raghuveer | 0cf35df | 2011-03-03 09:28:00 -0600 | [diff] [blame] | 3160 | u32 l; |
Tomi Valkeinen | dc0352d | 2016-05-17 13:45:09 +0300 | [diff] [blame] | 3161 | enum dss_clk_source dispc_clk_src = dss_get_dispc_clk_source(); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3162 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 3163 | if (dispc_runtime_get()) |
| 3164 | return; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3165 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3166 | seq_printf(s, "- DISPC -\n"); |
| 3167 | |
Tomi Valkeinen | 557a154 | 2016-05-17 13:49:18 +0300 | [diff] [blame] | 3168 | seq_printf(s, "dispc fclk source = %s\n", |
Tomi Valkeinen | 407bd56 | 2016-05-17 13:50:55 +0300 | [diff] [blame] | 3169 | dss_get_clk_source_name(dispc_clk_src)); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3170 | |
| 3171 | seq_printf(s, "fck\t\t%-16lu\n", dispc_fclk_rate()); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3172 | |
Murthy, Raghuveer | 0cf35df | 2011-03-03 09:28:00 -0600 | [diff] [blame] | 3173 | if (dss_has_feature(FEAT_CORE_CLK_DIV)) { |
| 3174 | seq_printf(s, "- DISPC-CORE-CLK -\n"); |
| 3175 | l = dispc_read_reg(DISPC_DIVISOR); |
| 3176 | lcd = FLD_GET(l, 23, 16); |
| 3177 | |
| 3178 | seq_printf(s, "lck\t\t%-16lulck div\t%u\n", |
| 3179 | (dispc_fclk_rate()/lcd), lcd); |
| 3180 | } |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3181 | |
Chandrabhanu Mahapatra | 6f1891f | 2012-06-21 11:23:56 +0530 | [diff] [blame] | 3182 | dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD); |
Taneja, Archit | ea75159 | 2011-03-08 05:50:35 -0600 | [diff] [blame] | 3183 | |
Chandrabhanu Mahapatra | 6f1891f | 2012-06-21 11:23:56 +0530 | [diff] [blame] | 3184 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 3185 | dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD2); |
| 3186 | if (dss_has_feature(FEAT_MGR_LCD3)) |
| 3187 | dispc_dump_clocks_channel(s, OMAP_DSS_CHANNEL_LCD3); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 3188 | |
| 3189 | dispc_runtime_put(); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3190 | } |
| 3191 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 3192 | static void dispc_dump_regs(struct seq_file *s) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3193 | { |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3194 | int i, j; |
| 3195 | const char *mgr_names[] = { |
| 3196 | [OMAP_DSS_CHANNEL_LCD] = "LCD", |
| 3197 | [OMAP_DSS_CHANNEL_DIGIT] = "TV", |
| 3198 | [OMAP_DSS_CHANNEL_LCD2] = "LCD2", |
Chandrabhanu Mahapatra | 6f1891f | 2012-06-21 11:23:56 +0530 | [diff] [blame] | 3199 | [OMAP_DSS_CHANNEL_LCD3] = "LCD3", |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3200 | }; |
| 3201 | const char *ovl_names[] = { |
| 3202 | [OMAP_DSS_GFX] = "GFX", |
| 3203 | [OMAP_DSS_VIDEO1] = "VID1", |
| 3204 | [OMAP_DSS_VIDEO2] = "VID2", |
Archit Taneja | b8c095b | 2011-09-13 18:20:33 +0530 | [diff] [blame] | 3205 | [OMAP_DSS_VIDEO3] = "VID3", |
Tomi Valkeinen | 06c525f | 2015-11-04 17:10:42 +0200 | [diff] [blame] | 3206 | [OMAP_DSS_WB] = "WB", |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3207 | }; |
| 3208 | const char **p_names; |
| 3209 | |
Archit Taneja | 9b372c2 | 2011-05-06 11:45:49 +0530 | [diff] [blame] | 3210 | #define DUMPREG(r) seq_printf(s, "%-50s %08x\n", #r, dispc_read_reg(r)) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3211 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 3212 | if (dispc_runtime_get()) |
| 3213 | return; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3214 | |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3215 | /* DISPC common registers */ |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3216 | DUMPREG(DISPC_REVISION); |
| 3217 | DUMPREG(DISPC_SYSCONFIG); |
| 3218 | DUMPREG(DISPC_SYSSTATUS); |
| 3219 | DUMPREG(DISPC_IRQSTATUS); |
| 3220 | DUMPREG(DISPC_IRQENABLE); |
| 3221 | DUMPREG(DISPC_CONTROL); |
| 3222 | DUMPREG(DISPC_CONFIG); |
| 3223 | DUMPREG(DISPC_CAPABLE); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3224 | DUMPREG(DISPC_LINE_STATUS); |
| 3225 | DUMPREG(DISPC_LINE_NUMBER); |
Archit Taneja | 11354dd | 2011-09-26 11:47:29 +0530 | [diff] [blame] | 3226 | if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER) || |
| 3227 | dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 3228 | DUMPREG(DISPC_GLOBAL_ALPHA); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3229 | if (dss_has_feature(FEAT_MGR_LCD2)) { |
| 3230 | DUMPREG(DISPC_CONTROL2); |
| 3231 | DUMPREG(DISPC_CONFIG2); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3232 | } |
Chandrabhanu Mahapatra | 6f1891f | 2012-06-21 11:23:56 +0530 | [diff] [blame] | 3233 | if (dss_has_feature(FEAT_MGR_LCD3)) { |
| 3234 | DUMPREG(DISPC_CONTROL3); |
| 3235 | DUMPREG(DISPC_CONFIG3); |
| 3236 | } |
Tomi Valkeinen | 29fceee | 2013-11-14 11:38:25 +0200 | [diff] [blame] | 3237 | if (dss_has_feature(FEAT_MFLAG)) |
| 3238 | DUMPREG(DISPC_GLOBAL_MFLAG_ATTRIBUTE); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3239 | |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3240 | #undef DUMPREG |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3241 | |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3242 | #define DISPC_REG(i, name) name(i) |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3243 | #define DUMPREG(i, r) seq_printf(s, "%s(%s)%*s %08x\n", #r, p_names[i], \ |
Tomi Valkeinen | 311d5ce | 2012-09-28 13:58:14 +0300 | [diff] [blame] | 3244 | (int)(48 - strlen(#r) - strlen(p_names[i])), " ", \ |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3245 | dispc_read_reg(DISPC_REG(i, r))) |
| 3246 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3247 | p_names = mgr_names; |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3248 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3249 | /* DISPC channel specific registers */ |
| 3250 | for (i = 0; i < dss_feat_get_num_mgrs(); i++) { |
| 3251 | DUMPREG(i, DISPC_DEFAULT_COLOR); |
| 3252 | DUMPREG(i, DISPC_TRANS_COLOR); |
| 3253 | DUMPREG(i, DISPC_SIZE_MGR); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3254 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3255 | if (i == OMAP_DSS_CHANNEL_DIGIT) |
| 3256 | continue; |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3257 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3258 | DUMPREG(i, DISPC_TIMING_H); |
| 3259 | DUMPREG(i, DISPC_TIMING_V); |
| 3260 | DUMPREG(i, DISPC_POL_FREQ); |
| 3261 | DUMPREG(i, DISPC_DIVISORo); |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3262 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3263 | DUMPREG(i, DISPC_DATA_CYCLE1); |
| 3264 | DUMPREG(i, DISPC_DATA_CYCLE2); |
| 3265 | DUMPREG(i, DISPC_DATA_CYCLE3); |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3266 | |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 3267 | if (dss_has_feature(FEAT_CPR)) { |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3268 | DUMPREG(i, DISPC_CPR_COEF_R); |
| 3269 | DUMPREG(i, DISPC_CPR_COEF_G); |
| 3270 | DUMPREG(i, DISPC_CPR_COEF_B); |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 3271 | } |
Sumit Semwal | 2a205f3 | 2010-12-02 11:27:12 +0000 | [diff] [blame] | 3272 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3273 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3274 | p_names = ovl_names; |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3275 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3276 | for (i = 0; i < dss_feat_get_num_ovls(); i++) { |
| 3277 | DUMPREG(i, DISPC_OVL_BA0); |
| 3278 | DUMPREG(i, DISPC_OVL_BA1); |
| 3279 | DUMPREG(i, DISPC_OVL_POSITION); |
| 3280 | DUMPREG(i, DISPC_OVL_SIZE); |
| 3281 | DUMPREG(i, DISPC_OVL_ATTRIBUTES); |
| 3282 | DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD); |
| 3283 | DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS); |
| 3284 | DUMPREG(i, DISPC_OVL_ROW_INC); |
| 3285 | DUMPREG(i, DISPC_OVL_PIXEL_INC); |
Tomi Valkeinen | aba837a | 2014-09-29 20:46:16 +0000 | [diff] [blame] | 3286 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3287 | if (dss_has_feature(FEAT_PRELOAD)) |
| 3288 | DUMPREG(i, DISPC_OVL_PRELOAD); |
Tomi Valkeinen | aba837a | 2014-09-29 20:46:16 +0000 | [diff] [blame] | 3289 | if (dss_has_feature(FEAT_MFLAG)) |
| 3290 | DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3291 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3292 | if (i == OMAP_DSS_GFX) { |
| 3293 | DUMPREG(i, DISPC_OVL_WINDOW_SKIP); |
| 3294 | DUMPREG(i, DISPC_OVL_TABLE_BA); |
| 3295 | continue; |
| 3296 | } |
| 3297 | |
| 3298 | DUMPREG(i, DISPC_OVL_FIR); |
| 3299 | DUMPREG(i, DISPC_OVL_PICTURE_SIZE); |
| 3300 | DUMPREG(i, DISPC_OVL_ACCU0); |
| 3301 | DUMPREG(i, DISPC_OVL_ACCU1); |
| 3302 | if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) { |
| 3303 | DUMPREG(i, DISPC_OVL_BA0_UV); |
| 3304 | DUMPREG(i, DISPC_OVL_BA1_UV); |
| 3305 | DUMPREG(i, DISPC_OVL_FIR2); |
| 3306 | DUMPREG(i, DISPC_OVL_ACCU2_0); |
| 3307 | DUMPREG(i, DISPC_OVL_ACCU2_1); |
| 3308 | } |
| 3309 | if (dss_has_feature(FEAT_ATTR2)) |
| 3310 | DUMPREG(i, DISPC_OVL_ATTRIBUTES2); |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3311 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3312 | |
Tomi Valkeinen | 20efbc3 | 2015-11-04 17:10:44 +0200 | [diff] [blame] | 3313 | if (dispc.feat->has_writeback) { |
Tomi Valkeinen | 06c525f | 2015-11-04 17:10:42 +0200 | [diff] [blame] | 3314 | i = OMAP_DSS_WB; |
| 3315 | DUMPREG(i, DISPC_OVL_BA0); |
| 3316 | DUMPREG(i, DISPC_OVL_BA1); |
| 3317 | DUMPREG(i, DISPC_OVL_SIZE); |
| 3318 | DUMPREG(i, DISPC_OVL_ATTRIBUTES); |
| 3319 | DUMPREG(i, DISPC_OVL_FIFO_THRESHOLD); |
| 3320 | DUMPREG(i, DISPC_OVL_FIFO_SIZE_STATUS); |
| 3321 | DUMPREG(i, DISPC_OVL_ROW_INC); |
| 3322 | DUMPREG(i, DISPC_OVL_PIXEL_INC); |
| 3323 | |
| 3324 | if (dss_has_feature(FEAT_MFLAG)) |
| 3325 | DUMPREG(i, DISPC_OVL_MFLAG_THRESHOLD); |
| 3326 | |
| 3327 | DUMPREG(i, DISPC_OVL_FIR); |
| 3328 | DUMPREG(i, DISPC_OVL_PICTURE_SIZE); |
| 3329 | DUMPREG(i, DISPC_OVL_ACCU0); |
| 3330 | DUMPREG(i, DISPC_OVL_ACCU1); |
| 3331 | if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) { |
| 3332 | DUMPREG(i, DISPC_OVL_BA0_UV); |
| 3333 | DUMPREG(i, DISPC_OVL_BA1_UV); |
| 3334 | DUMPREG(i, DISPC_OVL_FIR2); |
| 3335 | DUMPREG(i, DISPC_OVL_ACCU2_0); |
| 3336 | DUMPREG(i, DISPC_OVL_ACCU2_1); |
| 3337 | } |
| 3338 | if (dss_has_feature(FEAT_ATTR2)) |
| 3339 | DUMPREG(i, DISPC_OVL_ATTRIBUTES2); |
| 3340 | } |
| 3341 | |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3342 | #undef DISPC_REG |
| 3343 | #undef DUMPREG |
| 3344 | |
| 3345 | #define DISPC_REG(plane, name, i) name(plane, i) |
| 3346 | #define DUMPREG(plane, name, i) \ |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3347 | seq_printf(s, "%s_%d(%s)%*s %08x\n", #name, i, p_names[plane], \ |
Tomi Valkeinen | 311d5ce | 2012-09-28 13:58:14 +0300 | [diff] [blame] | 3348 | (int)(46 - strlen(#name) - strlen(p_names[plane])), " ", \ |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3349 | dispc_read_reg(DISPC_REG(plane, name, i))) |
| 3350 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3351 | /* Video pipeline coefficient registers */ |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3352 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3353 | /* start from OMAP_DSS_VIDEO1 */ |
| 3354 | for (i = 1; i < dss_feat_get_num_ovls(); i++) { |
| 3355 | for (j = 0; j < 8; j++) |
| 3356 | DUMPREG(i, DISPC_OVL_FIR_COEF_H, j); |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3357 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3358 | for (j = 0; j < 8; j++) |
| 3359 | DUMPREG(i, DISPC_OVL_FIR_COEF_HV, j); |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3360 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3361 | for (j = 0; j < 5; j++) |
| 3362 | DUMPREG(i, DISPC_OVL_CONV_COEF, j); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3363 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3364 | if (dss_has_feature(FEAT_FIR_COEF_V)) { |
| 3365 | for (j = 0; j < 8; j++) |
| 3366 | DUMPREG(i, DISPC_OVL_FIR_COEF_V, j); |
| 3367 | } |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 3368 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3369 | if (dss_has_feature(FEAT_HANDLE_UV_SEPARATE)) { |
| 3370 | for (j = 0; j < 8; j++) |
| 3371 | DUMPREG(i, DISPC_OVL_FIR_COEF_H2, j); |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 3372 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3373 | for (j = 0; j < 8; j++) |
| 3374 | DUMPREG(i, DISPC_OVL_FIR_COEF_HV2, j); |
Amber Jain | ab5ca07 | 2011-05-19 19:47:53 +0530 | [diff] [blame] | 3375 | |
Archit Taneja | 4dd2da1 | 2011-08-05 19:06:01 +0530 | [diff] [blame] | 3376 | for (j = 0; j < 8; j++) |
| 3377 | DUMPREG(i, DISPC_OVL_FIR_COEF_V2, j); |
| 3378 | } |
Tomi Valkeinen | 332e9d7 | 2011-05-27 14:22:16 +0300 | [diff] [blame] | 3379 | } |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3380 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 3381 | dispc_runtime_put(); |
Archit Taneja | 5010be8 | 2011-08-05 19:06:00 +0530 | [diff] [blame] | 3382 | |
| 3383 | #undef DISPC_REG |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3384 | #undef DUMPREG |
| 3385 | } |
| 3386 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3387 | /* calculate clock rates using dividers in cinfo */ |
| 3388 | int dispc_calc_clock_rates(unsigned long dispc_fclk_rate, |
| 3389 | struct dispc_clock_info *cinfo) |
| 3390 | { |
| 3391 | if (cinfo->lck_div > 255 || cinfo->lck_div == 0) |
| 3392 | return -EINVAL; |
Tomi Valkeinen | 9eaaf20 | 2011-08-29 15:56:04 +0300 | [diff] [blame] | 3393 | if (cinfo->pck_div < 1 || cinfo->pck_div > 255) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3394 | return -EINVAL; |
| 3395 | |
| 3396 | cinfo->lck = dispc_fclk_rate / cinfo->lck_div; |
| 3397 | cinfo->pck = cinfo->lck / cinfo->pck_div; |
| 3398 | |
| 3399 | return 0; |
| 3400 | } |
| 3401 | |
Tomi Valkeinen | 7c284e6 | 2013-03-05 16:32:08 +0200 | [diff] [blame] | 3402 | bool dispc_div_calc(unsigned long dispc, |
| 3403 | unsigned long pck_min, unsigned long pck_max, |
| 3404 | dispc_div_calc_func func, void *data) |
| 3405 | { |
| 3406 | int lckd, lckd_start, lckd_stop; |
| 3407 | int pckd, pckd_start, pckd_stop; |
| 3408 | unsigned long pck, lck; |
| 3409 | unsigned long lck_max; |
| 3410 | unsigned long pckd_hw_min, pckd_hw_max; |
| 3411 | unsigned min_fck_per_pck; |
| 3412 | unsigned long fck; |
| 3413 | |
| 3414 | #ifdef CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK |
| 3415 | min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK; |
| 3416 | #else |
| 3417 | min_fck_per_pck = 0; |
| 3418 | #endif |
| 3419 | |
| 3420 | pckd_hw_min = dss_feat_get_param_min(FEAT_PARAM_DSS_PCD); |
| 3421 | pckd_hw_max = dss_feat_get_param_max(FEAT_PARAM_DSS_PCD); |
| 3422 | |
| 3423 | lck_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK); |
| 3424 | |
| 3425 | pck_min = pck_min ? pck_min : 1; |
| 3426 | pck_max = pck_max ? pck_max : ULONG_MAX; |
| 3427 | |
| 3428 | lckd_start = max(DIV_ROUND_UP(dispc, lck_max), 1ul); |
| 3429 | lckd_stop = min(dispc / pck_min, 255ul); |
| 3430 | |
| 3431 | for (lckd = lckd_start; lckd <= lckd_stop; ++lckd) { |
| 3432 | lck = dispc / lckd; |
| 3433 | |
| 3434 | pckd_start = max(DIV_ROUND_UP(lck, pck_max), pckd_hw_min); |
| 3435 | pckd_stop = min(lck / pck_min, pckd_hw_max); |
| 3436 | |
| 3437 | for (pckd = pckd_start; pckd <= pckd_stop; ++pckd) { |
| 3438 | pck = lck / pckd; |
| 3439 | |
| 3440 | /* |
| 3441 | * For OMAP2/3 the DISPC fclk is the same as LCD's logic |
| 3442 | * clock, which means we're configuring DISPC fclk here |
| 3443 | * also. Thus we need to use the calculated lck. For |
| 3444 | * OMAP4+ the DISPC fclk is a separate clock. |
| 3445 | */ |
| 3446 | if (dss_has_feature(FEAT_CORE_CLK_DIV)) |
| 3447 | fck = dispc_core_clk_rate(); |
| 3448 | else |
| 3449 | fck = lck; |
| 3450 | |
| 3451 | if (fck < pck * min_fck_per_pck) |
| 3452 | continue; |
| 3453 | |
| 3454 | if (func(lckd, pckd, lck, pck, data)) |
| 3455 | return true; |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | return false; |
| 3460 | } |
| 3461 | |
Archit Taneja | f0d08f8 | 2012-06-29 14:00:54 +0530 | [diff] [blame] | 3462 | void dispc_mgr_set_clock_div(enum omap_channel channel, |
Tomi Valkeinen | a8f3fcd | 2012-10-03 09:09:11 +0200 | [diff] [blame] | 3463 | const struct dispc_clock_info *cinfo) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3464 | { |
| 3465 | DSSDBG("lck = %lu (%u)\n", cinfo->lck, cinfo->lck_div); |
| 3466 | DSSDBG("pck = %lu (%u)\n", cinfo->pck, cinfo->pck_div); |
| 3467 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 3468 | dispc_mgr_set_lcd_divisor(channel, cinfo->lck_div, cinfo->pck_div); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3469 | } |
| 3470 | |
Tomi Valkeinen | 26d9dd0 | 2011-08-16 13:45:15 +0300 | [diff] [blame] | 3471 | int dispc_mgr_get_clock_div(enum omap_channel channel, |
Sumit Semwal | ff1b2cd | 2010-12-02 11:27:11 +0000 | [diff] [blame] | 3472 | struct dispc_clock_info *cinfo) |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3473 | { |
| 3474 | unsigned long fck; |
| 3475 | |
| 3476 | fck = dispc_fclk_rate(); |
| 3477 | |
Murthy, Raghuveer | ce7fa5e | 2011-03-03 09:27:59 -0600 | [diff] [blame] | 3478 | cinfo->lck_div = REG_GET(DISPC_DIVISORo(channel), 23, 16); |
| 3479 | cinfo->pck_div = REG_GET(DISPC_DIVISORo(channel), 7, 0); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3480 | |
| 3481 | cinfo->lck = fck / cinfo->lck_div; |
| 3482 | cinfo->pck = cinfo->lck / cinfo->pck_div; |
| 3483 | |
| 3484 | return 0; |
| 3485 | } |
| 3486 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 3487 | static u32 dispc_read_irqstatus(void) |
Tomi Valkeinen | 4e0397c | 2012-10-10 15:13:14 +0300 | [diff] [blame] | 3488 | { |
| 3489 | return dispc_read_reg(DISPC_IRQSTATUS); |
| 3490 | } |
| 3491 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 3492 | static void dispc_clear_irqstatus(u32 mask) |
Tomi Valkeinen | 4e0397c | 2012-10-10 15:13:14 +0300 | [diff] [blame] | 3493 | { |
| 3494 | dispc_write_reg(DISPC_IRQSTATUS, mask); |
| 3495 | } |
| 3496 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 3497 | static void dispc_write_irqenable(u32 mask) |
Tomi Valkeinen | 4e0397c | 2012-10-10 15:13:14 +0300 | [diff] [blame] | 3498 | { |
| 3499 | u32 old_mask = dispc_read_reg(DISPC_IRQENABLE); |
| 3500 | |
| 3501 | /* clear the irqstatus for newly enabled irqs */ |
| 3502 | dispc_clear_irqstatus((mask ^ old_mask) & mask); |
| 3503 | |
| 3504 | dispc_write_reg(DISPC_IRQENABLE, mask); |
Tomi Valkeinen | 2e953d8 | 2017-02-20 13:18:38 +0200 | [diff] [blame] | 3505 | |
| 3506 | /* flush posted write */ |
| 3507 | dispc_read_reg(DISPC_IRQENABLE); |
Tomi Valkeinen | 4e0397c | 2012-10-10 15:13:14 +0300 | [diff] [blame] | 3508 | } |
| 3509 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3510 | void dispc_enable_sidle(void) |
| 3511 | { |
| 3512 | REG_FLD_MOD(DISPC_SYSCONFIG, 2, 4, 3); /* SIDLEMODE: smart idle */ |
| 3513 | } |
| 3514 | |
| 3515 | void dispc_disable_sidle(void) |
| 3516 | { |
| 3517 | REG_FLD_MOD(DISPC_SYSCONFIG, 1, 4, 3); /* SIDLEMODE: no idle */ |
| 3518 | } |
| 3519 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 3520 | static u32 dispc_mgr_gamma_size(enum omap_channel channel) |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 3521 | { |
| 3522 | const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma; |
| 3523 | |
| 3524 | if (!dispc.feat->has_gamma_table) |
| 3525 | return 0; |
| 3526 | |
| 3527 | return gdesc->len; |
| 3528 | } |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 3529 | |
| 3530 | static void dispc_mgr_write_gamma_table(enum omap_channel channel) |
| 3531 | { |
| 3532 | const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma; |
| 3533 | u32 *table = dispc.gamma_table[channel]; |
| 3534 | unsigned int i; |
| 3535 | |
| 3536 | DSSDBG("%s: channel %d\n", __func__, channel); |
| 3537 | |
| 3538 | for (i = 0; i < gdesc->len; ++i) { |
| 3539 | u32 v = table[i]; |
| 3540 | |
| 3541 | if (gdesc->has_index) |
| 3542 | v |= i << 24; |
| 3543 | else if (i == 0) |
| 3544 | v |= 1 << 31; |
| 3545 | |
| 3546 | dispc_write_reg(gdesc->reg, v); |
| 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | static void dispc_restore_gamma_tables(void) |
| 3551 | { |
| 3552 | DSSDBG("%s()\n", __func__); |
| 3553 | |
| 3554 | if (!dispc.feat->has_gamma_table) |
| 3555 | return; |
| 3556 | |
| 3557 | dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD); |
| 3558 | |
| 3559 | dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_DIGIT); |
| 3560 | |
| 3561 | if (dss_has_feature(FEAT_MGR_LCD2)) |
| 3562 | dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD2); |
| 3563 | |
| 3564 | if (dss_has_feature(FEAT_MGR_LCD3)) |
| 3565 | dispc_mgr_write_gamma_table(OMAP_DSS_CHANNEL_LCD3); |
| 3566 | } |
| 3567 | |
| 3568 | static const struct drm_color_lut dispc_mgr_gamma_default_lut[] = { |
| 3569 | { .red = 0, .green = 0, .blue = 0, }, |
| 3570 | { .red = U16_MAX, .green = U16_MAX, .blue = U16_MAX, }, |
| 3571 | }; |
| 3572 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 3573 | static void dispc_mgr_set_gamma(enum omap_channel channel, |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 3574 | const struct drm_color_lut *lut, |
| 3575 | unsigned int length) |
| 3576 | { |
| 3577 | const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma; |
| 3578 | u32 *table = dispc.gamma_table[channel]; |
| 3579 | uint i; |
| 3580 | |
| 3581 | DSSDBG("%s: channel %d, lut len %u, hw len %u\n", __func__, |
| 3582 | channel, length, gdesc->len); |
| 3583 | |
| 3584 | if (!dispc.feat->has_gamma_table) |
| 3585 | return; |
| 3586 | |
| 3587 | if (lut == NULL || length < 2) { |
| 3588 | lut = dispc_mgr_gamma_default_lut; |
| 3589 | length = ARRAY_SIZE(dispc_mgr_gamma_default_lut); |
| 3590 | } |
| 3591 | |
| 3592 | for (i = 0; i < length - 1; ++i) { |
| 3593 | uint first = i * (gdesc->len - 1) / (length - 1); |
| 3594 | uint last = (i + 1) * (gdesc->len - 1) / (length - 1); |
| 3595 | uint w = last - first; |
| 3596 | u16 r, g, b; |
| 3597 | uint j; |
| 3598 | |
| 3599 | if (w == 0) |
| 3600 | continue; |
| 3601 | |
| 3602 | for (j = 0; j <= w; j++) { |
| 3603 | r = (lut[i].red * (w - j) + lut[i+1].red * j) / w; |
| 3604 | g = (lut[i].green * (w - j) + lut[i+1].green * j) / w; |
| 3605 | b = (lut[i].blue * (w - j) + lut[i+1].blue * j) / w; |
| 3606 | |
| 3607 | r >>= 16 - gdesc->bits; |
| 3608 | g >>= 16 - gdesc->bits; |
| 3609 | b >>= 16 - gdesc->bits; |
| 3610 | |
| 3611 | table[first + j] = (r << (gdesc->bits * 2)) | |
| 3612 | (g << gdesc->bits) | b; |
| 3613 | } |
| 3614 | } |
| 3615 | |
| 3616 | if (dispc.is_enabled) |
| 3617 | dispc_mgr_write_gamma_table(channel); |
| 3618 | } |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 3619 | |
| 3620 | static int dispc_init_gamma_tables(void) |
| 3621 | { |
| 3622 | int channel; |
| 3623 | |
| 3624 | if (!dispc.feat->has_gamma_table) |
| 3625 | return 0; |
| 3626 | |
| 3627 | for (channel = 0; channel < ARRAY_SIZE(dispc.gamma_table); channel++) { |
| 3628 | const struct dispc_gamma_desc *gdesc = &mgr_desc[channel].gamma; |
| 3629 | u32 *gt; |
| 3630 | |
| 3631 | if (channel == OMAP_DSS_CHANNEL_LCD2 && |
| 3632 | !dss_has_feature(FEAT_MGR_LCD2)) |
| 3633 | continue; |
| 3634 | |
| 3635 | if (channel == OMAP_DSS_CHANNEL_LCD3 && |
| 3636 | !dss_has_feature(FEAT_MGR_LCD3)) |
| 3637 | continue; |
| 3638 | |
| 3639 | gt = devm_kmalloc_array(&dispc.pdev->dev, gdesc->len, |
| 3640 | sizeof(u32), GFP_KERNEL); |
| 3641 | if (!gt) |
| 3642 | return -ENOMEM; |
| 3643 | |
| 3644 | dispc.gamma_table[channel] = gt; |
| 3645 | |
| 3646 | dispc_mgr_set_gamma(channel, NULL, 0); |
| 3647 | } |
| 3648 | return 0; |
| 3649 | } |
| 3650 | |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3651 | static void _omap_dispc_initial_config(void) |
| 3652 | { |
| 3653 | u32 l; |
| 3654 | |
Murthy, Raghuveer | 0cf35df | 2011-03-03 09:28:00 -0600 | [diff] [blame] | 3655 | /* Exclusively enable DISPC_CORE_CLK and set divider to 1 */ |
| 3656 | if (dss_has_feature(FEAT_CORE_CLK_DIV)) { |
| 3657 | l = dispc_read_reg(DISPC_DIVISOR); |
| 3658 | /* Use DISPC_DIVISOR.LCD, instead of DISPC_DIVISOR1.LCD */ |
| 3659 | l = FLD_MOD(l, 1, 0, 0); |
| 3660 | l = FLD_MOD(l, 1, 23, 16); |
| 3661 | dispc_write_reg(DISPC_DIVISOR, l); |
Tomi Valkeinen | 7b3926b | 2013-03-06 15:54:11 +0200 | [diff] [blame] | 3662 | |
| 3663 | dispc.core_clk_rate = dispc_fclk_rate(); |
Murthy, Raghuveer | 0cf35df | 2011-03-03 09:28:00 -0600 | [diff] [blame] | 3664 | } |
| 3665 | |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 3666 | /* Use gamma table mode, instead of palette mode */ |
| 3667 | if (dispc.feat->has_gamma_table) |
| 3668 | REG_FLD_MOD(DISPC_CONFIG, 1, 3, 3); |
| 3669 | |
| 3670 | /* For older DSS versions (FEAT_FUNCGATED) this enables |
| 3671 | * func-clock auto-gating. For newer versions |
| 3672 | * (dispc.feat->has_gamma_table) this enables tv-out gamma tables. |
| 3673 | */ |
| 3674 | if (dss_has_feature(FEAT_FUNCGATED) || dispc.feat->has_gamma_table) |
Archit Taneja | 6ced40b | 2010-12-02 11:27:13 +0000 | [diff] [blame] | 3675 | REG_FLD_MOD(DISPC_CONFIG, 1, 9, 9); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3676 | |
Archit Taneja | 6e5264b | 2012-09-11 12:04:47 +0530 | [diff] [blame] | 3677 | dispc_setup_color_conv_coef(); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3678 | |
| 3679 | dispc_set_loadmode(OMAP_DSS_LOAD_FRAME_ONLY); |
| 3680 | |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 3681 | dispc_init_fifos(); |
Tomi Valkeinen | 5ed8cf5 | 2011-06-21 09:35:36 +0300 | [diff] [blame] | 3682 | |
| 3683 | dispc_configure_burst_sizes(); |
Archit Taneja | 5412870 | 2011-09-08 11:29:17 +0530 | [diff] [blame] | 3684 | |
| 3685 | dispc_ovl_enable_zorder_planes(); |
Archit Taneja | d0df9a2 | 2013-03-26 19:15:25 +0530 | [diff] [blame] | 3686 | |
| 3687 | if (dispc.feat->mstandby_workaround) |
| 3688 | REG_FLD_MOD(DISPC_MSTANDBY_CTRL, 1, 0, 0); |
Tomi Valkeinen | c64aa3a | 2014-09-29 20:46:18 +0000 | [diff] [blame] | 3689 | |
| 3690 | if (dss_has_feature(FEAT_MFLAG)) |
| 3691 | dispc_init_mflag(); |
Tomi Valkeinen | 80c3971 | 2009-11-12 11:41:42 +0200 | [diff] [blame] | 3692 | } |
| 3693 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 3694 | static const struct dispc_features omap24xx_dispc_feats = { |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3695 | .sw_start = 5, |
| 3696 | .fp_start = 15, |
| 3697 | .bp_start = 27, |
| 3698 | .sw_max = 64, |
| 3699 | .vp_max = 255, |
| 3700 | .hp_max = 256, |
Archit Taneja | 33b8992 | 2012-11-14 13:50:15 +0530 | [diff] [blame] | 3701 | .mgr_width_start = 10, |
| 3702 | .mgr_height_start = 26, |
| 3703 | .mgr_width_max = 2048, |
| 3704 | .mgr_height_max = 2048, |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 3705 | .max_lcd_pclk = 66500000, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3706 | .calc_scaling = dispc_ovl_calc_scaling_24xx, |
| 3707 | .calc_core_clk = calc_core_clk_24xx, |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 3708 | .num_fifos = 3, |
Tomi Valkeinen | cffa947 | 2012-11-08 10:01:33 +0200 | [diff] [blame] | 3709 | .no_framedone_tv = true, |
Archit Taneja | 8bc6555 | 2013-12-17 16:40:21 +0530 | [diff] [blame] | 3710 | .set_max_preload = false, |
Tomi Valkeinen | f2aee31 | 2015-04-10 12:48:34 +0300 | [diff] [blame] | 3711 | .last_pixel_inc_missing = true, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3712 | }; |
| 3713 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 3714 | static const struct dispc_features omap34xx_rev1_0_dispc_feats = { |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3715 | .sw_start = 5, |
| 3716 | .fp_start = 15, |
| 3717 | .bp_start = 27, |
| 3718 | .sw_max = 64, |
| 3719 | .vp_max = 255, |
| 3720 | .hp_max = 256, |
Archit Taneja | 33b8992 | 2012-11-14 13:50:15 +0530 | [diff] [blame] | 3721 | .mgr_width_start = 10, |
| 3722 | .mgr_height_start = 26, |
| 3723 | .mgr_width_max = 2048, |
| 3724 | .mgr_height_max = 2048, |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 3725 | .max_lcd_pclk = 173000000, |
| 3726 | .max_tv_pclk = 59000000, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3727 | .calc_scaling = dispc_ovl_calc_scaling_34xx, |
| 3728 | .calc_core_clk = calc_core_clk_34xx, |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 3729 | .num_fifos = 3, |
Tomi Valkeinen | cffa947 | 2012-11-08 10:01:33 +0200 | [diff] [blame] | 3730 | .no_framedone_tv = true, |
Archit Taneja | 8bc6555 | 2013-12-17 16:40:21 +0530 | [diff] [blame] | 3731 | .set_max_preload = false, |
Tomi Valkeinen | f2aee31 | 2015-04-10 12:48:34 +0300 | [diff] [blame] | 3732 | .last_pixel_inc_missing = true, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3733 | }; |
| 3734 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 3735 | static const struct dispc_features omap34xx_rev3_0_dispc_feats = { |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3736 | .sw_start = 7, |
| 3737 | .fp_start = 19, |
| 3738 | .bp_start = 31, |
| 3739 | .sw_max = 256, |
| 3740 | .vp_max = 4095, |
| 3741 | .hp_max = 4096, |
Archit Taneja | 33b8992 | 2012-11-14 13:50:15 +0530 | [diff] [blame] | 3742 | .mgr_width_start = 10, |
| 3743 | .mgr_height_start = 26, |
| 3744 | .mgr_width_max = 2048, |
| 3745 | .mgr_height_max = 2048, |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 3746 | .max_lcd_pclk = 173000000, |
| 3747 | .max_tv_pclk = 59000000, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3748 | .calc_scaling = dispc_ovl_calc_scaling_34xx, |
| 3749 | .calc_core_clk = calc_core_clk_34xx, |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 3750 | .num_fifos = 3, |
Tomi Valkeinen | cffa947 | 2012-11-08 10:01:33 +0200 | [diff] [blame] | 3751 | .no_framedone_tv = true, |
Archit Taneja | 8bc6555 | 2013-12-17 16:40:21 +0530 | [diff] [blame] | 3752 | .set_max_preload = false, |
Tomi Valkeinen | f2aee31 | 2015-04-10 12:48:34 +0300 | [diff] [blame] | 3753 | .last_pixel_inc_missing = true, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3754 | }; |
| 3755 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 3756 | static const struct dispc_features omap44xx_dispc_feats = { |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3757 | .sw_start = 7, |
| 3758 | .fp_start = 19, |
| 3759 | .bp_start = 31, |
| 3760 | .sw_max = 256, |
| 3761 | .vp_max = 4095, |
| 3762 | .hp_max = 4096, |
Archit Taneja | 33b8992 | 2012-11-14 13:50:15 +0530 | [diff] [blame] | 3763 | .mgr_width_start = 10, |
| 3764 | .mgr_height_start = 26, |
| 3765 | .mgr_width_max = 2048, |
| 3766 | .mgr_height_max = 2048, |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 3767 | .max_lcd_pclk = 170000000, |
| 3768 | .max_tv_pclk = 185625000, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3769 | .calc_scaling = dispc_ovl_calc_scaling_44xx, |
| 3770 | .calc_core_clk = calc_core_clk_44xx, |
Tomi Valkeinen | 42a6961 | 2012-08-22 16:56:57 +0300 | [diff] [blame] | 3771 | .num_fifos = 5, |
Tomi Valkeinen | 66a0f9e | 2012-08-22 16:57:02 +0300 | [diff] [blame] | 3772 | .gfx_fifo_workaround = true, |
Archit Taneja | 8bc6555 | 2013-12-17 16:40:21 +0530 | [diff] [blame] | 3773 | .set_max_preload = true, |
Tomi Valkeinen | e5f8091 | 2015-10-21 13:08:59 +0300 | [diff] [blame] | 3774 | .supports_sync_align = true, |
Tomi Valkeinen | 20efbc3 | 2015-11-04 17:10:44 +0200 | [diff] [blame] | 3775 | .has_writeback = true, |
Tomi Valkeinen | 3a38ed53 | 2016-01-13 18:41:31 +0200 | [diff] [blame] | 3776 | .supports_double_pixel = true, |
Tomi Valkeinen | b7536d6 | 2016-01-13 18:41:36 +0200 | [diff] [blame] | 3777 | .reverse_ilace_field_order = true, |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 3778 | .has_gamma_table = true, |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 3779 | .has_gamma_i734_bug = true, |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3780 | }; |
| 3781 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 3782 | static const struct dispc_features omap54xx_dispc_feats = { |
Archit Taneja | 264236f | 2012-11-14 13:50:16 +0530 | [diff] [blame] | 3783 | .sw_start = 7, |
| 3784 | .fp_start = 19, |
| 3785 | .bp_start = 31, |
| 3786 | .sw_max = 256, |
| 3787 | .vp_max = 4095, |
| 3788 | .hp_max = 4096, |
| 3789 | .mgr_width_start = 11, |
| 3790 | .mgr_height_start = 27, |
| 3791 | .mgr_width_max = 4096, |
| 3792 | .mgr_height_max = 4096, |
Archit Taneja | ca5ca69 | 2013-03-26 19:15:22 +0530 | [diff] [blame] | 3793 | .max_lcd_pclk = 170000000, |
| 3794 | .max_tv_pclk = 186000000, |
Archit Taneja | 264236f | 2012-11-14 13:50:16 +0530 | [diff] [blame] | 3795 | .calc_scaling = dispc_ovl_calc_scaling_44xx, |
| 3796 | .calc_core_clk = calc_core_clk_44xx, |
| 3797 | .num_fifos = 5, |
| 3798 | .gfx_fifo_workaround = true, |
Archit Taneja | d0df9a2 | 2013-03-26 19:15:25 +0530 | [diff] [blame] | 3799 | .mstandby_workaround = true, |
Archit Taneja | 8bc6555 | 2013-12-17 16:40:21 +0530 | [diff] [blame] | 3800 | .set_max_preload = true, |
Tomi Valkeinen | e5f8091 | 2015-10-21 13:08:59 +0300 | [diff] [blame] | 3801 | .supports_sync_align = true, |
Tomi Valkeinen | 20efbc3 | 2015-11-04 17:10:44 +0200 | [diff] [blame] | 3802 | .has_writeback = true, |
Tomi Valkeinen | 3a38ed53 | 2016-01-13 18:41:31 +0200 | [diff] [blame] | 3803 | .supports_double_pixel = true, |
Tomi Valkeinen | b7536d6 | 2016-01-13 18:41:36 +0200 | [diff] [blame] | 3804 | .reverse_ilace_field_order = true, |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 3805 | .has_gamma_table = true, |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 3806 | .has_gamma_i734_bug = true, |
Archit Taneja | 264236f | 2012-11-14 13:50:16 +0530 | [diff] [blame] | 3807 | }; |
| 3808 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 3809 | static int dispc_init_features(struct platform_device *pdev) |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3810 | { |
| 3811 | const struct dispc_features *src; |
| 3812 | struct dispc_features *dst; |
| 3813 | |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 3814 | dst = devm_kzalloc(&pdev->dev, sizeof(*dst), GFP_KERNEL); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3815 | if (!dst) { |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 3816 | dev_err(&pdev->dev, "Failed to allocate DISPC Features\n"); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3817 | return -ENOMEM; |
| 3818 | } |
| 3819 | |
Tomi Valkeinen | b2c7d54 | 2012-10-18 13:46:29 +0300 | [diff] [blame] | 3820 | switch (omapdss_get_version()) { |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 3821 | case OMAPDSS_VER_OMAP24xx: |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3822 | src = &omap24xx_dispc_feats; |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 3823 | break; |
| 3824 | |
| 3825 | case OMAPDSS_VER_OMAP34xx_ES1: |
| 3826 | src = &omap34xx_rev1_0_dispc_feats; |
| 3827 | break; |
| 3828 | |
| 3829 | case OMAPDSS_VER_OMAP34xx_ES3: |
| 3830 | case OMAPDSS_VER_OMAP3630: |
| 3831 | case OMAPDSS_VER_AM35xx: |
Sathya Prakash M R | d6279d4 | 2014-03-24 16:31:51 +0530 | [diff] [blame] | 3832 | case OMAPDSS_VER_AM43xx: |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 3833 | src = &omap34xx_rev3_0_dispc_feats; |
| 3834 | break; |
| 3835 | |
| 3836 | case OMAPDSS_VER_OMAP4430_ES1: |
| 3837 | case OMAPDSS_VER_OMAP4430_ES2: |
| 3838 | case OMAPDSS_VER_OMAP4: |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3839 | src = &omap44xx_dispc_feats; |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 3840 | break; |
| 3841 | |
| 3842 | case OMAPDSS_VER_OMAP5: |
Tomi Valkeinen | 9355092 | 2014-12-31 11:25:48 +0200 | [diff] [blame] | 3843 | case OMAPDSS_VER_DRA7xx: |
Archit Taneja | 264236f | 2012-11-14 13:50:16 +0530 | [diff] [blame] | 3844 | src = &omap54xx_dispc_feats; |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 3845 | break; |
| 3846 | |
| 3847 | default: |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 3848 | return -ENODEV; |
| 3849 | } |
| 3850 | |
| 3851 | memcpy(dst, src, sizeof(*dst)); |
| 3852 | dispc.feat = dst; |
| 3853 | |
| 3854 | return 0; |
| 3855 | } |
| 3856 | |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 3857 | static irqreturn_t dispc_irq_handler(int irq, void *arg) |
| 3858 | { |
| 3859 | if (!dispc.is_enabled) |
| 3860 | return IRQ_NONE; |
| 3861 | |
| 3862 | return dispc.user_handler(irq, dispc.user_data); |
| 3863 | } |
| 3864 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 3865 | static int dispc_request_irq(irq_handler_t handler, void *dev_id) |
Tomi Valkeinen | 96e2e63 | 2012-10-10 15:55:19 +0300 | [diff] [blame] | 3866 | { |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 3867 | int r; |
| 3868 | |
| 3869 | if (dispc.user_handler != NULL) |
| 3870 | return -EBUSY; |
| 3871 | |
| 3872 | dispc.user_handler = handler; |
| 3873 | dispc.user_data = dev_id; |
| 3874 | |
| 3875 | /* ensure the dispc_irq_handler sees the values above */ |
| 3876 | smp_wmb(); |
| 3877 | |
| 3878 | r = devm_request_irq(&dispc.pdev->dev, dispc.irq, dispc_irq_handler, |
| 3879 | IRQF_SHARED, "OMAP DISPC", &dispc); |
| 3880 | if (r) { |
| 3881 | dispc.user_handler = NULL; |
| 3882 | dispc.user_data = NULL; |
| 3883 | } |
| 3884 | |
| 3885 | return r; |
Tomi Valkeinen | 96e2e63 | 2012-10-10 15:55:19 +0300 | [diff] [blame] | 3886 | } |
| 3887 | |
Tomi Valkeinen | 5034b1f | 2015-11-05 20:06:06 +0200 | [diff] [blame] | 3888 | static void dispc_free_irq(void *dev_id) |
Tomi Valkeinen | 96e2e63 | 2012-10-10 15:55:19 +0300 | [diff] [blame] | 3889 | { |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 3890 | devm_free_irq(&dispc.pdev->dev, dispc.irq, &dispc); |
| 3891 | |
| 3892 | dispc.user_handler = NULL; |
| 3893 | dispc.user_data = NULL; |
Tomi Valkeinen | 96e2e63 | 2012-10-10 15:55:19 +0300 | [diff] [blame] | 3894 | } |
| 3895 | |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 3896 | /* |
| 3897 | * Workaround for errata i734 in DSS dispc |
| 3898 | * - LCD1 Gamma Correction Is Not Working When GFX Pipe Is Disabled |
| 3899 | * |
| 3900 | * For gamma tables to work on LCD1 the GFX plane has to be used at |
| 3901 | * least once after DSS HW has come out of reset. The workaround |
| 3902 | * sets up a minimal LCD setup with GFX plane and waits for one |
| 3903 | * vertical sync irq before disabling the setup and continuing with |
| 3904 | * the context restore. The physical outputs are gated during the |
| 3905 | * operation. This workaround requires that gamma table's LOADMODE |
| 3906 | * is set to 0x2 in DISPC_CONTROL1 register. |
| 3907 | * |
| 3908 | * For details see: |
| 3909 | * OMAP543x Multimedia Device Silicon Revision 2.0 Silicon Errata |
| 3910 | * Literature Number: SWPZ037E |
| 3911 | * Or some other relevant errata document for the DSS IP version. |
| 3912 | */ |
| 3913 | |
| 3914 | static const struct dispc_errata_i734_data { |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 3915 | struct videomode vm; |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 3916 | struct omap_overlay_info ovli; |
| 3917 | struct omap_overlay_manager_info mgri; |
| 3918 | struct dss_lcd_mgr_config lcd_conf; |
| 3919 | } i734 = { |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 3920 | .vm = { |
Peter Ujfalusi | fb7f3c4 | 2016-09-22 14:06:47 +0300 | [diff] [blame] | 3921 | .hactive = 8, .vactive = 1, |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 3922 | .pixelclock = 16000000, |
Peter Ujfalusi | a85f4a8 | 2016-09-22 14:06:50 +0300 | [diff] [blame] | 3923 | .hsync_len = 8, .hfront_porch = 4, .hback_porch = 4, |
Peter Ujfalusi | 458540c | 2016-09-22 14:06:53 +0300 | [diff] [blame] | 3924 | .vsync_len = 1, .vfront_porch = 1, .vback_porch = 1, |
Peter Ujfalusi | 6b44cd2 | 2016-09-22 14:06:57 +0300 | [diff] [blame] | 3925 | |
Peter Ujfalusi | 3fa3ab4 | 2016-09-22 14:06:58 +0300 | [diff] [blame] | 3926 | .flags = DISPLAY_FLAGS_HSYNC_LOW | DISPLAY_FLAGS_VSYNC_LOW | |
Peter Ujfalusi | d34afb7 | 2016-09-22 14:07:01 +0300 | [diff] [blame] | 3927 | DISPLAY_FLAGS_DE_HIGH | DISPLAY_FLAGS_SYNC_POSEDGE | |
| 3928 | DISPLAY_FLAGS_PIXDATA_POSEDGE, |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 3929 | }, |
| 3930 | .ovli = { |
| 3931 | .screen_width = 1, |
| 3932 | .width = 1, .height = 1, |
| 3933 | .color_mode = OMAP_DSS_COLOR_RGB24U, |
| 3934 | .rotation = OMAP_DSS_ROT_0, |
Tomi Valkeinen | 517a8a95 | 2017-05-03 14:14:27 +0300 | [diff] [blame^] | 3935 | .rotation_type = OMAP_DSS_ROT_NONE, |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 3936 | .mirror = 0, |
| 3937 | .pos_x = 0, .pos_y = 0, |
| 3938 | .out_width = 0, .out_height = 0, |
| 3939 | .global_alpha = 0xff, |
| 3940 | .pre_mult_alpha = 0, |
| 3941 | .zorder = 0, |
| 3942 | }, |
| 3943 | .mgri = { |
| 3944 | .default_color = 0, |
| 3945 | .trans_enabled = false, |
| 3946 | .partial_alpha_enabled = false, |
| 3947 | .cpr_enable = false, |
| 3948 | }, |
| 3949 | .lcd_conf = { |
| 3950 | .io_pad_mode = DSS_IO_PAD_MODE_BYPASS, |
| 3951 | .stallmode = false, |
| 3952 | .fifohandcheck = false, |
| 3953 | .clock_info = { |
| 3954 | .lck_div = 1, |
| 3955 | .pck_div = 2, |
| 3956 | }, |
| 3957 | .video_port_width = 24, |
| 3958 | .lcden_sig_polarity = 0, |
| 3959 | }, |
| 3960 | }; |
| 3961 | |
| 3962 | static struct i734_buf { |
| 3963 | size_t size; |
| 3964 | dma_addr_t paddr; |
| 3965 | void *vaddr; |
| 3966 | } i734_buf; |
| 3967 | |
| 3968 | static int dispc_errata_i734_wa_init(void) |
| 3969 | { |
| 3970 | if (!dispc.feat->has_gamma_i734_bug) |
| 3971 | return 0; |
| 3972 | |
| 3973 | i734_buf.size = i734.ovli.width * i734.ovli.height * |
| 3974 | color_mode_to_bpp(i734.ovli.color_mode) / 8; |
| 3975 | |
| 3976 | i734_buf.vaddr = dma_alloc_writecombine(&dispc.pdev->dev, i734_buf.size, |
| 3977 | &i734_buf.paddr, GFP_KERNEL); |
| 3978 | if (!i734_buf.vaddr) { |
| 3979 | dev_err(&dispc.pdev->dev, "%s: dma_alloc_writecombine failed", |
| 3980 | __func__); |
| 3981 | return -ENOMEM; |
| 3982 | } |
| 3983 | |
| 3984 | return 0; |
| 3985 | } |
| 3986 | |
| 3987 | static void dispc_errata_i734_wa_fini(void) |
| 3988 | { |
| 3989 | if (!dispc.feat->has_gamma_i734_bug) |
| 3990 | return; |
| 3991 | |
| 3992 | dma_free_writecombine(&dispc.pdev->dev, i734_buf.size, i734_buf.vaddr, |
| 3993 | i734_buf.paddr); |
| 3994 | } |
| 3995 | |
| 3996 | static void dispc_errata_i734_wa(void) |
| 3997 | { |
| 3998 | u32 framedone_irq = dispc_mgr_get_framedone_irq(OMAP_DSS_CHANNEL_LCD); |
| 3999 | struct omap_overlay_info ovli; |
| 4000 | struct dss_lcd_mgr_config lcd_conf; |
| 4001 | u32 gatestate; |
| 4002 | unsigned int count; |
| 4003 | |
| 4004 | if (!dispc.feat->has_gamma_i734_bug) |
| 4005 | return; |
| 4006 | |
| 4007 | gatestate = REG_GET(DISPC_CONFIG, 8, 4); |
| 4008 | |
| 4009 | ovli = i734.ovli; |
| 4010 | ovli.paddr = i734_buf.paddr; |
| 4011 | lcd_conf = i734.lcd_conf; |
| 4012 | |
| 4013 | /* Gate all LCD1 outputs */ |
| 4014 | REG_FLD_MOD(DISPC_CONFIG, 0x1f, 8, 4); |
| 4015 | |
| 4016 | /* Setup and enable GFX plane */ |
Tomi Valkeinen | 49a3057 | 2017-02-17 12:30:07 +0200 | [diff] [blame] | 4017 | dispc_ovl_setup(OMAP_DSS_GFX, &ovli, &i734.vm, false, |
| 4018 | OMAP_DSS_CHANNEL_LCD); |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 4019 | dispc_ovl_enable(OMAP_DSS_GFX, true); |
| 4020 | |
| 4021 | /* Set up and enable display manager for LCD1 */ |
| 4022 | dispc_mgr_setup(OMAP_DSS_CHANNEL_LCD, &i734.mgri); |
| 4023 | dispc_calc_clock_rates(dss_get_dispc_clk_rate(), |
| 4024 | &lcd_conf.clock_info); |
| 4025 | dispc_mgr_set_lcd_config(OMAP_DSS_CHANNEL_LCD, &lcd_conf); |
Peter Ujfalusi | da11bbbb | 2016-09-22 14:07:04 +0300 | [diff] [blame] | 4026 | dispc_mgr_set_timings(OMAP_DSS_CHANNEL_LCD, &i734.vm); |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 4027 | |
| 4028 | dispc_clear_irqstatus(framedone_irq); |
| 4029 | |
| 4030 | /* Enable and shut the channel to produce just one frame */ |
| 4031 | dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, true); |
| 4032 | dispc_mgr_enable(OMAP_DSS_CHANNEL_LCD, false); |
| 4033 | |
| 4034 | /* Busy wait for framedone. We can't fiddle with irq handlers |
| 4035 | * in PM resume. Typically the loop runs less than 5 times and |
| 4036 | * waits less than a micro second. |
| 4037 | */ |
| 4038 | count = 0; |
| 4039 | while (!(dispc_read_irqstatus() & framedone_irq)) { |
| 4040 | if (count++ > 10000) { |
| 4041 | dev_err(&dispc.pdev->dev, "%s: framedone timeout\n", |
| 4042 | __func__); |
| 4043 | break; |
| 4044 | } |
| 4045 | } |
| 4046 | dispc_ovl_enable(OMAP_DSS_GFX, false); |
| 4047 | |
| 4048 | /* Clear all irq bits before continuing */ |
| 4049 | dispc_clear_irqstatus(0xffffffff); |
| 4050 | |
| 4051 | /* Restore the original state to LCD1 output gates */ |
| 4052 | REG_FLD_MOD(DISPC_CONFIG, gatestate, 8, 4); |
| 4053 | } |
| 4054 | |
Tomi Valkeinen | a1a37647 | 2015-11-05 19:44:38 +0200 | [diff] [blame] | 4055 | static const struct dispc_ops dispc_ops = { |
| 4056 | .read_irqstatus = dispc_read_irqstatus, |
| 4057 | .clear_irqstatus = dispc_clear_irqstatus, |
Tomi Valkeinen | a1a37647 | 2015-11-05 19:44:38 +0200 | [diff] [blame] | 4058 | .write_irqenable = dispc_write_irqenable, |
| 4059 | |
| 4060 | .request_irq = dispc_request_irq, |
| 4061 | .free_irq = dispc_free_irq, |
| 4062 | |
| 4063 | .runtime_get = dispc_runtime_get, |
| 4064 | .runtime_put = dispc_runtime_put, |
| 4065 | |
| 4066 | .get_num_ovls = dispc_get_num_ovls, |
| 4067 | .get_num_mgrs = dispc_get_num_mgrs, |
| 4068 | |
| 4069 | .mgr_enable = dispc_mgr_enable, |
| 4070 | .mgr_is_enabled = dispc_mgr_is_enabled, |
| 4071 | .mgr_get_vsync_irq = dispc_mgr_get_vsync_irq, |
| 4072 | .mgr_get_framedone_irq = dispc_mgr_get_framedone_irq, |
| 4073 | .mgr_get_sync_lost_irq = dispc_mgr_get_sync_lost_irq, |
| 4074 | .mgr_go_busy = dispc_mgr_go_busy, |
| 4075 | .mgr_go = dispc_mgr_go, |
| 4076 | .mgr_set_lcd_config = dispc_mgr_set_lcd_config, |
| 4077 | .mgr_set_timings = dispc_mgr_set_timings, |
| 4078 | .mgr_setup = dispc_mgr_setup, |
| 4079 | .mgr_get_supported_outputs = dispc_mgr_get_supported_outputs, |
| 4080 | .mgr_gamma_size = dispc_mgr_gamma_size, |
| 4081 | .mgr_set_gamma = dispc_mgr_set_gamma, |
| 4082 | |
| 4083 | .ovl_enable = dispc_ovl_enable, |
Tomi Valkeinen | a1a37647 | 2015-11-05 19:44:38 +0200 | [diff] [blame] | 4084 | .ovl_setup = dispc_ovl_setup, |
| 4085 | .ovl_get_color_modes = dispc_ovl_get_color_modes, |
| 4086 | }; |
| 4087 | |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4088 | /* DISPC HW IP initialisation */ |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4089 | static int dispc_bind(struct device *dev, struct device *master, void *data) |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4090 | { |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4091 | struct platform_device *pdev = to_platform_device(dev); |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4092 | u32 rev; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4093 | int r = 0; |
Senthilvadivu Guruswamy | ea9da36 | 2011-01-24 06:22:04 +0000 | [diff] [blame] | 4094 | struct resource *dispc_mem; |
Tomi Valkeinen | 0006fd6 | 2014-09-05 19:15:03 +0000 | [diff] [blame] | 4095 | struct device_node *np = pdev->dev.of_node; |
Senthilvadivu Guruswamy | ea9da36 | 2011-01-24 06:22:04 +0000 | [diff] [blame] | 4096 | |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4097 | dispc.pdev = pdev; |
| 4098 | |
Tomi Valkeinen | d49cd15 | 2014-11-10 12:23:00 +0200 | [diff] [blame] | 4099 | spin_lock_init(&dispc.control_lock); |
| 4100 | |
Tomi Valkeinen | 84b47623 | 2012-09-28 12:54:03 +0300 | [diff] [blame] | 4101 | r = dispc_init_features(dispc.pdev); |
Chandrabhanu Mahapatra | dcbe765 | 2012-07-03 12:26:51 +0530 | [diff] [blame] | 4102 | if (r) |
| 4103 | return r; |
| 4104 | |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 4105 | r = dispc_errata_i734_wa_init(); |
| 4106 | if (r) |
| 4107 | return r; |
| 4108 | |
Senthilvadivu Guruswamy | ea9da36 | 2011-01-24 06:22:04 +0000 | [diff] [blame] | 4109 | dispc_mem = platform_get_resource(dispc.pdev, IORESOURCE_MEM, 0); |
Laurent Pinchart | b22622f | 2017-05-07 00:29:09 +0300 | [diff] [blame] | 4110 | dispc.base = devm_ioremap_resource(&pdev->dev, dispc_mem); |
| 4111 | if (IS_ERR(dispc.base)) |
| 4112 | return PTR_ERR(dispc.base); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 4113 | |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4114 | dispc.irq = platform_get_irq(dispc.pdev, 0); |
| 4115 | if (dispc.irq < 0) { |
| 4116 | DSSERR("platform_get_irq failed\n"); |
Tomi Valkeinen | cd3b344 | 2012-01-25 13:31:04 +0200 | [diff] [blame] | 4117 | return -ENODEV; |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
Tomi Valkeinen | 0006fd6 | 2014-09-05 19:15:03 +0000 | [diff] [blame] | 4120 | if (np && of_property_read_bool(np, "syscon-pol")) { |
| 4121 | dispc.syscon_pol = syscon_regmap_lookup_by_phandle(np, "syscon-pol"); |
| 4122 | if (IS_ERR(dispc.syscon_pol)) { |
| 4123 | dev_err(&pdev->dev, "failed to get syscon-pol regmap\n"); |
| 4124 | return PTR_ERR(dispc.syscon_pol); |
| 4125 | } |
| 4126 | |
| 4127 | if (of_property_read_u32_index(np, "syscon-pol", 1, |
| 4128 | &dispc.syscon_pol_offset)) { |
| 4129 | dev_err(&pdev->dev, "failed to get syscon-pol offset\n"); |
| 4130 | return -EINVAL; |
| 4131 | } |
| 4132 | } |
| 4133 | |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 4134 | r = dispc_init_gamma_tables(); |
| 4135 | if (r) |
| 4136 | return r; |
| 4137 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4138 | pm_runtime_enable(&pdev->dev); |
| 4139 | |
| 4140 | r = dispc_runtime_get(); |
| 4141 | if (r) |
| 4142 | goto err_runtime_get; |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4143 | |
| 4144 | _omap_dispc_initial_config(); |
| 4145 | |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4146 | rev = dispc_read_reg(DISPC_REVISION); |
Sumit Semwal | a06b62f | 2011-01-24 06:22:03 +0000 | [diff] [blame] | 4147 | dev_dbg(&pdev->dev, "OMAP DISPC rev %d.%d\n", |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4148 | FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0)); |
| 4149 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4150 | dispc_runtime_put(); |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4151 | |
Tomi Valkeinen | a1a37647 | 2015-11-05 19:44:38 +0200 | [diff] [blame] | 4152 | dispc_set_ops(&dispc_ops); |
| 4153 | |
Tomi Valkeinen | e40402c | 2012-03-02 18:01:07 +0200 | [diff] [blame] | 4154 | dss_debugfs_create_file("dispc", dispc_dump_regs); |
| 4155 | |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4156 | return 0; |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4157 | |
| 4158 | err_runtime_get: |
| 4159 | pm_runtime_disable(&pdev->dev); |
archit taneja | affe360 | 2011-02-23 08:41:03 +0000 | [diff] [blame] | 4160 | return r; |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4163 | static void dispc_unbind(struct device *dev, struct device *master, |
| 4164 | void *data) |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4165 | { |
Tomi Valkeinen | a1a37647 | 2015-11-05 19:44:38 +0200 | [diff] [blame] | 4166 | dispc_set_ops(NULL); |
| 4167 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4168 | pm_runtime_disable(dev); |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 4169 | |
| 4170 | dispc_errata_i734_wa_fini(); |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4171 | } |
Tomi Valkeinen | 04b1fc0 | 2013-05-14 10:55:19 +0300 | [diff] [blame] | 4172 | |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4173 | static const struct component_ops dispc_component_ops = { |
| 4174 | .bind = dispc_bind, |
| 4175 | .unbind = dispc_unbind, |
| 4176 | }; |
| 4177 | |
| 4178 | static int dispc_probe(struct platform_device *pdev) |
| 4179 | { |
| 4180 | return component_add(&pdev->dev, &dispc_component_ops); |
| 4181 | } |
| 4182 | |
| 4183 | static int dispc_remove(struct platform_device *pdev) |
| 4184 | { |
| 4185 | component_del(&pdev->dev, &dispc_component_ops); |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4186 | return 0; |
| 4187 | } |
| 4188 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4189 | static int dispc_runtime_suspend(struct device *dev) |
| 4190 | { |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 4191 | dispc.is_enabled = false; |
| 4192 | /* ensure the dispc_irq_handler sees the is_enabled value */ |
| 4193 | smp_wmb(); |
| 4194 | /* wait for current handler to finish before turning the DISPC off */ |
| 4195 | synchronize_irq(dispc.irq); |
| 4196 | |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4197 | dispc_save_context(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4198 | |
| 4199 | return 0; |
| 4200 | } |
| 4201 | |
| 4202 | static int dispc_runtime_resume(struct device *dev) |
| 4203 | { |
Tomi Valkeinen | 9229b51 | 2014-02-14 09:37:09 +0200 | [diff] [blame] | 4204 | /* |
| 4205 | * The reset value for load mode is 0 (OMAP_DSS_LOAD_CLUT_AND_FRAME) |
| 4206 | * but we always initialize it to 2 (OMAP_DSS_LOAD_FRAME_ONLY) in |
| 4207 | * _omap_dispc_initial_config(). We can thus use it to detect if |
| 4208 | * we have lost register context. |
| 4209 | */ |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 4210 | if (REG_GET(DISPC_CONFIG, 2, 1) != OMAP_DSS_LOAD_FRAME_ONLY) { |
| 4211 | _omap_dispc_initial_config(); |
Tomi Valkeinen | 9229b51 | 2014-02-14 09:37:09 +0200 | [diff] [blame] | 4212 | |
Jyri Sarha | fbff010 | 2016-06-07 15:09:16 +0300 | [diff] [blame] | 4213 | dispc_errata_i734_wa(); |
| 4214 | |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 4215 | dispc_restore_context(); |
Jyri Sarha | acc3a23 | 2016-06-07 15:09:15 +0300 | [diff] [blame] | 4216 | |
| 4217 | dispc_restore_gamma_tables(); |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 4218 | } |
Tomi Valkeinen | be07dcd7 | 2013-11-21 16:01:40 +0200 | [diff] [blame] | 4219 | |
Tomi Valkeinen | 0925afc | 2014-04-11 13:49:55 +0300 | [diff] [blame] | 4220 | dispc.is_enabled = true; |
| 4221 | /* ensure the dispc_irq_handler sees the is_enabled value */ |
| 4222 | smp_wmb(); |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4223 | |
| 4224 | return 0; |
| 4225 | } |
| 4226 | |
| 4227 | static const struct dev_pm_ops dispc_pm_ops = { |
| 4228 | .runtime_suspend = dispc_runtime_suspend, |
| 4229 | .runtime_resume = dispc_runtime_resume, |
| 4230 | }; |
| 4231 | |
Tomi Valkeinen | d7977f8 | 2013-12-17 11:54:02 +0200 | [diff] [blame] | 4232 | static const struct of_device_id dispc_of_match[] = { |
| 4233 | { .compatible = "ti,omap2-dispc", }, |
| 4234 | { .compatible = "ti,omap3-dispc", }, |
| 4235 | { .compatible = "ti,omap4-dispc", }, |
Tomi Valkeinen | 2e7e6b6 | 2014-04-16 13:16:43 +0300 | [diff] [blame] | 4236 | { .compatible = "ti,omap5-dispc", }, |
Tomi Valkeinen | 9355092 | 2014-12-31 11:25:48 +0200 | [diff] [blame] | 4237 | { .compatible = "ti,dra7-dispc", }, |
Tomi Valkeinen | d7977f8 | 2013-12-17 11:54:02 +0200 | [diff] [blame] | 4238 | {}, |
| 4239 | }; |
| 4240 | |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4241 | static struct platform_driver omap_dispchw_driver = { |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4242 | .probe = dispc_probe, |
| 4243 | .remove = dispc_remove, |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4244 | .driver = { |
| 4245 | .name = "omapdss_dispc", |
Tomi Valkeinen | 4fbafaf | 2011-05-27 10:52:19 +0300 | [diff] [blame] | 4246 | .pm = &dispc_pm_ops, |
Tomi Valkeinen | d7977f8 | 2013-12-17 11:54:02 +0200 | [diff] [blame] | 4247 | .of_match_table = dispc_of_match, |
Tomi Valkeinen | 422ccbd | 2014-10-16 09:54:25 +0300 | [diff] [blame] | 4248 | .suppress_bind_attrs = true, |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4249 | }, |
| 4250 | }; |
| 4251 | |
Tomi Valkeinen | 6e7e8f0 | 2012-02-17 17:41:13 +0200 | [diff] [blame] | 4252 | int __init dispc_init_platform_driver(void) |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4253 | { |
Tomi Valkeinen | 736e60d | 2015-06-04 15:22:23 +0300 | [diff] [blame] | 4254 | return platform_driver_register(&omap_dispchw_driver); |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4255 | } |
| 4256 | |
Tomi Valkeinen | ede9269 | 2015-06-04 14:12:16 +0300 | [diff] [blame] | 4257 | void dispc_uninit_platform_driver(void) |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4258 | { |
Tomi Valkeinen | 04c742c | 2012-02-23 15:32:37 +0200 | [diff] [blame] | 4259 | platform_driver_unregister(&omap_dispchw_driver); |
Senthilvadivu Guruswamy | 060b6d9 | 2011-01-24 06:22:00 +0000 | [diff] [blame] | 4260 | } |