Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008-2009 MontaVista Software Inc. |
| 3 | * Copyright (C) 2008-2009 Texas Instruments Inc |
| 4 | * |
| 5 | * Based on the LCD driver for TI Avalanche processors written by |
| 6 | * Ajay Singh and Shalom Hai. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option)any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/fb.h> |
| 25 | #include <linux/dma-mapping.h> |
| 26 | #include <linux/device.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/uaccess.h> |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 29 | #include <linux/pm_runtime.h> |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 30 | #include <linux/interrupt.h> |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 31 | #include <linux/wait.h> |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 32 | #include <linux/clk.h> |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 33 | #include <linux/cpufreq.h> |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 34 | #include <linux/console.h> |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 35 | #include <linux/spinlock.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> |
Florian Tobias Schandinat | a023907 | 2012-07-29 16:47:40 +0000 | [diff] [blame] | 37 | #include <linux/delay.h> |
Aditya Nellutla | 3b9cc4e | 2012-05-23 11:36:31 +0530 | [diff] [blame] | 38 | #include <linux/lcm.h> |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 39 | #include <video/da8xx-fb.h> |
Manjunathappa, Prakash | 12fa835 | 2012-02-09 11:54:06 +0530 | [diff] [blame] | 40 | #include <asm/div64.h> |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 41 | |
| 42 | #define DRIVER_NAME "da8xx_lcdc" |
| 43 | |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 44 | #define LCD_VERSION_1 1 |
| 45 | #define LCD_VERSION_2 2 |
| 46 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 47 | /* LCD Status Register */ |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 48 | #define LCD_END_OF_FRAME1 BIT(9) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 49 | #define LCD_END_OF_FRAME0 BIT(8) |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 50 | #define LCD_PL_LOAD_DONE BIT(6) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 51 | #define LCD_FIFO_UNDERFLOW BIT(5) |
| 52 | #define LCD_SYNC_LOST BIT(2) |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 53 | #define LCD_FRAME_DONE BIT(0) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 54 | |
| 55 | /* LCD DMA Control Register */ |
| 56 | #define LCD_DMA_BURST_SIZE(x) ((x) << 4) |
| 57 | #define LCD_DMA_BURST_1 0x0 |
| 58 | #define LCD_DMA_BURST_2 0x1 |
| 59 | #define LCD_DMA_BURST_4 0x2 |
| 60 | #define LCD_DMA_BURST_8 0x3 |
| 61 | #define LCD_DMA_BURST_16 0x4 |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 62 | #define LCD_V1_END_OF_FRAME_INT_ENA BIT(2) |
| 63 | #define LCD_V2_END_OF_FRAME0_INT_ENA BIT(8) |
| 64 | #define LCD_V2_END_OF_FRAME1_INT_ENA BIT(9) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 65 | #define LCD_DUAL_FRAME_BUFFER_ENABLE BIT(0) |
| 66 | |
| 67 | /* LCD Control Register */ |
| 68 | #define LCD_CLK_DIVISOR(x) ((x) << 8) |
| 69 | #define LCD_RASTER_MODE 0x01 |
| 70 | |
| 71 | /* LCD Raster Control Register */ |
| 72 | #define LCD_PALETTE_LOAD_MODE(x) ((x) << 20) |
| 73 | #define PALETTE_AND_DATA 0x00 |
| 74 | #define PALETTE_ONLY 0x01 |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 75 | #define DATA_ONLY 0x02 |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 76 | |
| 77 | #define LCD_MONO_8BIT_MODE BIT(9) |
| 78 | #define LCD_RASTER_ORDER BIT(8) |
| 79 | #define LCD_TFT_MODE BIT(7) |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 80 | #define LCD_V1_UNDERFLOW_INT_ENA BIT(6) |
| 81 | #define LCD_V2_UNDERFLOW_INT_ENA BIT(5) |
| 82 | #define LCD_V1_PL_INT_ENA BIT(4) |
| 83 | #define LCD_V2_PL_INT_ENA BIT(6) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 84 | #define LCD_MONOCHROME_MODE BIT(1) |
| 85 | #define LCD_RASTER_ENABLE BIT(0) |
| 86 | #define LCD_TFT_ALT_ENABLE BIT(23) |
| 87 | #define LCD_STN_565_ENABLE BIT(24) |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 88 | #define LCD_V2_DMA_CLK_EN BIT(2) |
| 89 | #define LCD_V2_LIDD_CLK_EN BIT(1) |
| 90 | #define LCD_V2_CORE_CLK_EN BIT(0) |
| 91 | #define LCD_V2_LPP_B10 26 |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 92 | #define LCD_V2_TFT_24BPP_MODE BIT(25) |
| 93 | #define LCD_V2_TFT_24BPP_UNPACK BIT(26) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 94 | |
| 95 | /* LCD Raster Timing 2 Register */ |
| 96 | #define LCD_AC_BIAS_TRANSITIONS_PER_INT(x) ((x) << 16) |
| 97 | #define LCD_AC_BIAS_FREQUENCY(x) ((x) << 8) |
| 98 | #define LCD_SYNC_CTRL BIT(25) |
| 99 | #define LCD_SYNC_EDGE BIT(24) |
| 100 | #define LCD_INVERT_PIXEL_CLOCK BIT(22) |
| 101 | #define LCD_INVERT_LINE_CLOCK BIT(21) |
| 102 | #define LCD_INVERT_FRAME_CLOCK BIT(20) |
| 103 | |
| 104 | /* LCD Block */ |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 105 | #define LCD_PID_REG 0x0 |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 106 | #define LCD_CTRL_REG 0x4 |
| 107 | #define LCD_STAT_REG 0x8 |
| 108 | #define LCD_RASTER_CTRL_REG 0x28 |
| 109 | #define LCD_RASTER_TIMING_0_REG 0x2C |
| 110 | #define LCD_RASTER_TIMING_1_REG 0x30 |
| 111 | #define LCD_RASTER_TIMING_2_REG 0x34 |
| 112 | #define LCD_DMA_CTRL_REG 0x40 |
| 113 | #define LCD_DMA_FRM_BUF_BASE_ADDR_0_REG 0x44 |
| 114 | #define LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG 0x48 |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 115 | #define LCD_DMA_FRM_BUF_BASE_ADDR_1_REG 0x4C |
| 116 | #define LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG 0x50 |
| 117 | |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 118 | /* Interrupt Registers available only in Version 2 */ |
| 119 | #define LCD_RAW_STAT_REG 0x58 |
| 120 | #define LCD_MASKED_STAT_REG 0x5c |
| 121 | #define LCD_INT_ENABLE_SET_REG 0x60 |
| 122 | #define LCD_INT_ENABLE_CLR_REG 0x64 |
| 123 | #define LCD_END_OF_INT_IND_REG 0x68 |
| 124 | |
| 125 | /* Clock registers available only on Version 2 */ |
| 126 | #define LCD_CLK_ENABLE_REG 0x6c |
| 127 | #define LCD_CLK_RESET_REG 0x70 |
Manjunathappa, Prakash | 74a0efd | 2011-11-15 17:32:23 +0530 | [diff] [blame] | 128 | #define LCD_CLK_MAIN_RESET BIT(3) |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 129 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 130 | #define LCD_NUM_BUFFERS 2 |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 131 | |
| 132 | #define WSI_TIMEOUT 50 |
| 133 | #define PALETTE_SIZE 256 |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 134 | |
Arnd Bergmann | 34aef6e | 2012-09-14 20:33:43 +0000 | [diff] [blame] | 135 | static void __iomem *da8xx_fb_reg_base; |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 136 | static unsigned int lcd_revision; |
| 137 | static irq_handler_t lcdc_irq_handler; |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 138 | static wait_queue_head_t frame_done_wq; |
| 139 | static int frame_done_flag; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 140 | |
| 141 | static inline unsigned int lcdc_read(unsigned int addr) |
| 142 | { |
| 143 | return (unsigned int)__raw_readl(da8xx_fb_reg_base + (addr)); |
| 144 | } |
| 145 | |
| 146 | static inline void lcdc_write(unsigned int val, unsigned int addr) |
| 147 | { |
| 148 | __raw_writel(val, da8xx_fb_reg_base + (addr)); |
| 149 | } |
| 150 | |
| 151 | struct da8xx_fb_par { |
Afzal Mohammed | dbe8e48 | 2013-08-05 17:02:27 -0500 | [diff] [blame] | 152 | struct device *dev; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 153 | resource_size_t p_palette_base; |
| 154 | unsigned char *v_palette_base; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 155 | dma_addr_t vram_phys; |
| 156 | unsigned long vram_size; |
| 157 | void *vram_virt; |
| 158 | unsigned int dma_start; |
| 159 | unsigned int dma_end; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 160 | struct clk *lcdc_clk; |
| 161 | int irq; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 162 | unsigned int palette_sz; |
Chaithrika U S | 3611380 | 2009-12-15 16:46:38 -0800 | [diff] [blame] | 163 | int blank; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 164 | wait_queue_head_t vsync_wait; |
| 165 | int vsync_flag; |
| 166 | int vsync_timeout; |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 167 | spinlock_t lock_for_chan_update; |
| 168 | |
| 169 | /* |
| 170 | * LCDC has 2 ping pong DMA channels, channel 0 |
| 171 | * and channel 1. |
| 172 | */ |
| 173 | unsigned int which_dma_channel_done; |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 174 | #ifdef CONFIG_CPU_FREQ |
| 175 | struct notifier_block freq_transition; |
| 176 | #endif |
Afzal Mohammed | 44f627a | 2013-08-05 17:02:25 -0500 | [diff] [blame] | 177 | unsigned int lcd_fck_rate; |
Chaithrika U S | 3611380 | 2009-12-15 16:46:38 -0800 | [diff] [blame] | 178 | void (*panel_power_ctrl)(int); |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 179 | u32 pseudo_palette[16]; |
Afzal Mohammed | b6dbe8e | 2013-08-05 17:02:24 -0500 | [diff] [blame] | 180 | struct fb_videomode mode; |
| 181 | struct lcd_ctrl_config cfg; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Afzal Mohammed | be0f6db | 2013-08-05 17:02:23 -0500 | [diff] [blame] | 184 | static struct fb_var_screeninfo da8xx_fb_var; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 185 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 186 | static struct fb_fix_screeninfo da8xx_fb_fix = { |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 187 | .id = "DA8xx FB Drv", |
| 188 | .type = FB_TYPE_PACKED_PIXELS, |
| 189 | .type_aux = 0, |
| 190 | .visual = FB_VISUAL_PSEUDOCOLOR, |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 191 | .xpanstep = 0, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 192 | .ypanstep = 1, |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 193 | .ywrapstep = 0, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 194 | .accel = FB_ACCEL_NONE |
| 195 | }; |
| 196 | |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 197 | static struct fb_videomode known_lcd_panels[] = { |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 198 | /* Sharp LCD035Q3DG01 */ |
| 199 | [0] = { |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 200 | .name = "Sharp_LCD035Q3DG01", |
| 201 | .xres = 320, |
| 202 | .yres = 240, |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 203 | .pixclock = KHZ2PICOS(4607), |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 204 | .left_margin = 6, |
| 205 | .right_margin = 8, |
| 206 | .upper_margin = 2, |
| 207 | .lower_margin = 2, |
| 208 | .hsync_len = 0, |
| 209 | .vsync_len = 0, |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 210 | .sync = FB_SYNC_CLK_INVERT | |
| 211 | FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 212 | }, |
| 213 | /* Sharp LK043T1DG01 */ |
| 214 | [1] = { |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 215 | .name = "Sharp_LK043T1DG01", |
| 216 | .xres = 480, |
| 217 | .yres = 272, |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 218 | .pixclock = KHZ2PICOS(7833), |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 219 | .left_margin = 2, |
| 220 | .right_margin = 2, |
| 221 | .upper_margin = 2, |
| 222 | .lower_margin = 2, |
| 223 | .hsync_len = 41, |
| 224 | .vsync_len = 10, |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 225 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 226 | .flag = 0, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 227 | }, |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 228 | [2] = { |
| 229 | /* Hitachi SP10Q010 */ |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 230 | .name = "SP10Q010", |
| 231 | .xres = 320, |
| 232 | .yres = 240, |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 233 | .pixclock = KHZ2PICOS(7833), |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 234 | .left_margin = 10, |
| 235 | .right_margin = 10, |
| 236 | .upper_margin = 10, |
| 237 | .lower_margin = 10, |
| 238 | .hsync_len = 10, |
| 239 | .vsync_len = 10, |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 240 | .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 241 | .flag = 0, |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 242 | }, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
Darren Etheridge | fe8c98f | 2013-08-05 17:02:29 -0500 | [diff] [blame] | 245 | static inline bool da8xx_fb_is_raster_enabled(void) |
| 246 | { |
| 247 | return !!(lcdc_read(LCD_RASTER_CTRL_REG) & LCD_RASTER_ENABLE); |
| 248 | } |
| 249 | |
Chaithrika U S | 3611380 | 2009-12-15 16:46:38 -0800 | [diff] [blame] | 250 | /* Enable the Raster Engine of the LCD Controller */ |
| 251 | static inline void lcd_enable_raster(void) |
| 252 | { |
| 253 | u32 reg; |
| 254 | |
Manjunathappa, Prakash | 92b4e45 | 2012-07-20 21:21:11 +0530 | [diff] [blame] | 255 | /* Put LCDC in reset for several cycles */ |
| 256 | if (lcd_revision == LCD_VERSION_2) |
| 257 | /* Write 1 to reset LCDC */ |
| 258 | lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG); |
| 259 | mdelay(1); |
| 260 | |
Manjunathappa, Prakash | 74a0efd | 2011-11-15 17:32:23 +0530 | [diff] [blame] | 261 | /* Bring LCDC out of reset */ |
| 262 | if (lcd_revision == LCD_VERSION_2) |
| 263 | lcdc_write(0, LCD_CLK_RESET_REG); |
Manjunathappa, Prakash | 92b4e45 | 2012-07-20 21:21:11 +0530 | [diff] [blame] | 264 | mdelay(1); |
Manjunathappa, Prakash | 74a0efd | 2011-11-15 17:32:23 +0530 | [diff] [blame] | 265 | |
Manjunathappa, Prakash | 92b4e45 | 2012-07-20 21:21:11 +0530 | [diff] [blame] | 266 | /* Above reset sequence doesnot reset register context */ |
Chaithrika U S | 3611380 | 2009-12-15 16:46:38 -0800 | [diff] [blame] | 267 | reg = lcdc_read(LCD_RASTER_CTRL_REG); |
| 268 | if (!(reg & LCD_RASTER_ENABLE)) |
| 269 | lcdc_write(reg | LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG); |
| 270 | } |
| 271 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 272 | /* Disable the Raster Engine of the LCD Controller */ |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 273 | static inline void lcd_disable_raster(enum da8xx_frame_complete |
| 274 | wait_for_frame_done) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 275 | { |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 276 | u32 reg; |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 277 | int ret; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 278 | |
| 279 | reg = lcdc_read(LCD_RASTER_CTRL_REG); |
Sudhakar Rajashekhara | 2f93e8f | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 280 | if (reg & LCD_RASTER_ENABLE) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 281 | lcdc_write(reg & ~LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG); |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 282 | else |
| 283 | /* return if already disabled */ |
| 284 | return; |
| 285 | |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 286 | if ((wait_for_frame_done == DA8XX_FRAME_WAIT) && |
| 287 | (lcd_revision == LCD_VERSION_2)) { |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 288 | frame_done_flag = 0; |
| 289 | ret = wait_event_interruptible_timeout(frame_done_wq, |
| 290 | frame_done_flag != 0, |
| 291 | msecs_to_jiffies(50)); |
| 292 | if (ret == 0) |
| 293 | pr_err("LCD Controller timed out\n"); |
| 294 | } |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void lcd_blit(int load_mode, struct da8xx_fb_par *par) |
| 298 | { |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 299 | u32 start; |
| 300 | u32 end; |
| 301 | u32 reg_ras; |
| 302 | u32 reg_dma; |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 303 | u32 reg_int; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 304 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 305 | /* init reg to clear PLM (loading mode) fields */ |
| 306 | reg_ras = lcdc_read(LCD_RASTER_CTRL_REG); |
| 307 | reg_ras &= ~(3 << 20); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 308 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 309 | reg_dma = lcdc_read(LCD_DMA_CTRL_REG); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 310 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 311 | if (load_mode == LOAD_DATA) { |
| 312 | start = par->dma_start; |
| 313 | end = par->dma_end; |
| 314 | |
| 315 | reg_ras |= LCD_PALETTE_LOAD_MODE(DATA_ONLY); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 316 | if (lcd_revision == LCD_VERSION_1) { |
| 317 | reg_dma |= LCD_V1_END_OF_FRAME_INT_ENA; |
| 318 | } else { |
| 319 | reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) | |
| 320 | LCD_V2_END_OF_FRAME0_INT_ENA | |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 321 | LCD_V2_END_OF_FRAME1_INT_ENA | |
Afzal Mohammed | e4008e2 | 2013-08-05 17:02:32 -0500 | [diff] [blame] | 322 | LCD_FRAME_DONE | LCD_SYNC_LOST; |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 323 | lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG); |
| 324 | } |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 325 | reg_dma |= LCD_DUAL_FRAME_BUFFER_ENABLE; |
| 326 | |
| 327 | lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 328 | lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 329 | lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_1_REG); |
| 330 | lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG); |
| 331 | } else if (load_mode == LOAD_PALETTE) { |
| 332 | start = par->p_palette_base; |
| 333 | end = start + par->palette_sz - 1; |
| 334 | |
| 335 | reg_ras |= LCD_PALETTE_LOAD_MODE(PALETTE_ONLY); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 336 | |
| 337 | if (lcd_revision == LCD_VERSION_1) { |
| 338 | reg_ras |= LCD_V1_PL_INT_ENA; |
| 339 | } else { |
| 340 | reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) | |
| 341 | LCD_V2_PL_INT_ENA; |
| 342 | lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG); |
| 343 | } |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 344 | |
| 345 | lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 346 | lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 347 | } |
| 348 | |
| 349 | lcdc_write(reg_dma, LCD_DMA_CTRL_REG); |
| 350 | lcdc_write(reg_ras, LCD_RASTER_CTRL_REG); |
| 351 | |
| 352 | /* |
| 353 | * The Raster enable bit must be set after all other control fields are |
| 354 | * set. |
| 355 | */ |
| 356 | lcd_enable_raster(); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Manjunathappa, Prakash | fb8fa94 | 2012-07-18 21:03:36 +0530 | [diff] [blame] | 359 | /* Configure the Burst Size and fifo threhold of DMA */ |
| 360 | static int lcd_cfg_dma(int burst_size, int fifo_th) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 361 | { |
| 362 | u32 reg; |
| 363 | |
| 364 | reg = lcdc_read(LCD_DMA_CTRL_REG) & 0x00000001; |
| 365 | switch (burst_size) { |
| 366 | case 1: |
| 367 | reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_1); |
| 368 | break; |
| 369 | case 2: |
| 370 | reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_2); |
| 371 | break; |
| 372 | case 4: |
| 373 | reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_4); |
| 374 | break; |
| 375 | case 8: |
| 376 | reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_8); |
| 377 | break; |
| 378 | case 16: |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 379 | default: |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 380 | reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_16); |
| 381 | break; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 382 | } |
Manjunathappa, Prakash | fb8fa94 | 2012-07-18 21:03:36 +0530 | [diff] [blame] | 383 | |
| 384 | reg |= (fifo_th << 8); |
| 385 | |
Sudhakar Rajashekhara | 2f93e8f | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 386 | lcdc_write(reg, LCD_DMA_CTRL_REG); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | static void lcd_cfg_ac_bias(int period, int transitions_per_int) |
| 392 | { |
| 393 | u32 reg; |
| 394 | |
| 395 | /* Set the AC Bias Period and Number of Transisitons per Interrupt */ |
| 396 | reg = lcdc_read(LCD_RASTER_TIMING_2_REG) & 0xFFF00000; |
| 397 | reg |= LCD_AC_BIAS_FREQUENCY(period) | |
| 398 | LCD_AC_BIAS_TRANSITIONS_PER_INT(transitions_per_int); |
| 399 | lcdc_write(reg, LCD_RASTER_TIMING_2_REG); |
| 400 | } |
| 401 | |
| 402 | static void lcd_cfg_horizontal_sync(int back_porch, int pulse_width, |
| 403 | int front_porch) |
| 404 | { |
| 405 | u32 reg; |
| 406 | |
| 407 | reg = lcdc_read(LCD_RASTER_TIMING_0_REG) & 0xf; |
| 408 | reg |= ((back_porch & 0xff) << 24) |
| 409 | | ((front_porch & 0xff) << 16) |
| 410 | | ((pulse_width & 0x3f) << 10); |
| 411 | lcdc_write(reg, LCD_RASTER_TIMING_0_REG); |
| 412 | } |
| 413 | |
| 414 | static void lcd_cfg_vertical_sync(int back_porch, int pulse_width, |
| 415 | int front_porch) |
| 416 | { |
| 417 | u32 reg; |
| 418 | |
| 419 | reg = lcdc_read(LCD_RASTER_TIMING_1_REG) & 0x3ff; |
| 420 | reg |= ((back_porch & 0xff) << 24) |
| 421 | | ((front_porch & 0xff) << 16) |
| 422 | | ((pulse_width & 0x3f) << 10); |
| 423 | lcdc_write(reg, LCD_RASTER_TIMING_1_REG); |
| 424 | } |
| 425 | |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 426 | static int lcd_cfg_display(const struct lcd_ctrl_config *cfg, |
| 427 | struct fb_videomode *panel) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 428 | { |
| 429 | u32 reg; |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 430 | u32 reg_int; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 431 | |
| 432 | reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(LCD_TFT_MODE | |
| 433 | LCD_MONO_8BIT_MODE | |
| 434 | LCD_MONOCHROME_MODE); |
| 435 | |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 436 | switch (cfg->panel_shade) { |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 437 | case MONOCHROME: |
| 438 | reg |= LCD_MONOCHROME_MODE; |
| 439 | if (cfg->mono_8bit_mode) |
| 440 | reg |= LCD_MONO_8BIT_MODE; |
| 441 | break; |
| 442 | case COLOR_ACTIVE: |
| 443 | reg |= LCD_TFT_MODE; |
| 444 | if (cfg->tft_alt_mode) |
| 445 | reg |= LCD_TFT_ALT_ENABLE; |
| 446 | break; |
| 447 | |
| 448 | case COLOR_PASSIVE: |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 449 | /* AC bias applicable only for Pasive panels */ |
| 450 | lcd_cfg_ac_bias(cfg->ac_bias, cfg->ac_bias_intrpt); |
| 451 | if (cfg->bpp == 12 && cfg->stn_565_mode) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 452 | reg |= LCD_STN_565_ENABLE; |
| 453 | break; |
| 454 | |
| 455 | default: |
| 456 | return -EINVAL; |
| 457 | } |
| 458 | |
| 459 | /* enable additional interrupts here */ |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 460 | if (lcd_revision == LCD_VERSION_1) { |
| 461 | reg |= LCD_V1_UNDERFLOW_INT_ENA; |
| 462 | } else { |
| 463 | reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) | |
| 464 | LCD_V2_UNDERFLOW_INT_ENA; |
| 465 | lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG); |
| 466 | } |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 467 | |
| 468 | lcdc_write(reg, LCD_RASTER_CTRL_REG); |
| 469 | |
| 470 | reg = lcdc_read(LCD_RASTER_TIMING_2_REG); |
| 471 | |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 472 | reg |= LCD_SYNC_CTRL; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 473 | |
| 474 | if (cfg->sync_edge) |
| 475 | reg |= LCD_SYNC_EDGE; |
| 476 | else |
| 477 | reg &= ~LCD_SYNC_EDGE; |
| 478 | |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 479 | if (panel->sync & FB_SYNC_HOR_HIGH_ACT) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 480 | reg |= LCD_INVERT_LINE_CLOCK; |
| 481 | else |
| 482 | reg &= ~LCD_INVERT_LINE_CLOCK; |
| 483 | |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 484 | if (panel->sync & FB_SYNC_VERT_HIGH_ACT) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 485 | reg |= LCD_INVERT_FRAME_CLOCK; |
| 486 | else |
| 487 | reg &= ~LCD_INVERT_FRAME_CLOCK; |
| 488 | |
| 489 | lcdc_write(reg, LCD_RASTER_TIMING_2_REG); |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static int lcd_cfg_frame_buffer(struct da8xx_fb_par *par, u32 width, u32 height, |
| 495 | u32 bpp, u32 raster_order) |
| 496 | { |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 497 | u32 reg; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 498 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 499 | if (bpp > 16 && lcd_revision == LCD_VERSION_1) |
| 500 | return -EINVAL; |
| 501 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 502 | /* Set the Panel Width */ |
| 503 | /* Pixels per line = (PPL + 1)*16 */ |
Manjunathappa, Prakash | 4d74080 | 2011-07-18 09:58:53 +0530 | [diff] [blame] | 504 | if (lcd_revision == LCD_VERSION_1) { |
| 505 | /* |
| 506 | * 0x3F in bits 4..9 gives max horizontal resolution = 1024 |
| 507 | * pixels. |
| 508 | */ |
| 509 | width &= 0x3f0; |
| 510 | } else { |
| 511 | /* |
| 512 | * 0x7F in bits 4..10 gives max horizontal resolution = 2048 |
| 513 | * pixels. |
| 514 | */ |
| 515 | width &= 0x7f0; |
| 516 | } |
| 517 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 518 | reg = lcdc_read(LCD_RASTER_TIMING_0_REG); |
| 519 | reg &= 0xfffffc00; |
Manjunathappa, Prakash | 4d74080 | 2011-07-18 09:58:53 +0530 | [diff] [blame] | 520 | if (lcd_revision == LCD_VERSION_1) { |
| 521 | reg |= ((width >> 4) - 1) << 4; |
| 522 | } else { |
| 523 | width = (width >> 4) - 1; |
| 524 | reg |= ((width & 0x3f) << 4) | ((width & 0x40) >> 3); |
| 525 | } |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 526 | lcdc_write(reg, LCD_RASTER_TIMING_0_REG); |
| 527 | |
| 528 | /* Set the Panel Height */ |
Manjunathappa, Prakash | 4d74080 | 2011-07-18 09:58:53 +0530 | [diff] [blame] | 529 | /* Set bits 9:0 of Lines Per Pixel */ |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 530 | reg = lcdc_read(LCD_RASTER_TIMING_1_REG); |
| 531 | reg = ((height - 1) & 0x3ff) | (reg & 0xfffffc00); |
| 532 | lcdc_write(reg, LCD_RASTER_TIMING_1_REG); |
| 533 | |
Manjunathappa, Prakash | 4d74080 | 2011-07-18 09:58:53 +0530 | [diff] [blame] | 534 | /* Set bit 10 of Lines Per Pixel */ |
| 535 | if (lcd_revision == LCD_VERSION_2) { |
| 536 | reg = lcdc_read(LCD_RASTER_TIMING_2_REG); |
| 537 | reg |= ((height - 1) & 0x400) << 16; |
| 538 | lcdc_write(reg, LCD_RASTER_TIMING_2_REG); |
| 539 | } |
| 540 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 541 | /* Set the Raster Order of the Frame Buffer */ |
| 542 | reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(1 << 8); |
| 543 | if (raster_order) |
| 544 | reg |= LCD_RASTER_ORDER; |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 545 | |
| 546 | par->palette_sz = 16 * 2; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 547 | |
| 548 | switch (bpp) { |
| 549 | case 1: |
| 550 | case 2: |
| 551 | case 4: |
| 552 | case 16: |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 553 | break; |
| 554 | case 24: |
| 555 | reg |= LCD_V2_TFT_24BPP_MODE; |
Darren Etheridge | fa8a00c | 2013-08-05 17:02:31 -0500 | [diff] [blame] | 556 | break; |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 557 | case 32: |
Darren Etheridge | fa8a00c | 2013-08-05 17:02:31 -0500 | [diff] [blame] | 558 | reg |= LCD_V2_TFT_24BPP_MODE; |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 559 | reg |= LCD_V2_TFT_24BPP_UNPACK; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 560 | break; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 561 | case 8: |
| 562 | par->palette_sz = 256 * 2; |
| 563 | break; |
| 564 | |
| 565 | default: |
| 566 | return -EINVAL; |
| 567 | } |
| 568 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 569 | lcdc_write(reg, LCD_RASTER_CTRL_REG); |
| 570 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 574 | #define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 575 | static int fb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 576 | unsigned blue, unsigned transp, |
| 577 | struct fb_info *info) |
| 578 | { |
| 579 | struct da8xx_fb_par *par = info->par; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 580 | unsigned short *palette = (unsigned short *) par->v_palette_base; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 581 | u_short pal; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 582 | int update_hw = 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 583 | |
| 584 | if (regno > 255) |
| 585 | return 1; |
| 586 | |
| 587 | if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) |
| 588 | return 1; |
| 589 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 590 | if (info->var.bits_per_pixel > 16 && lcd_revision == LCD_VERSION_1) |
| 591 | return -EINVAL; |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 592 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 593 | switch (info->fix.visual) { |
| 594 | case FB_VISUAL_TRUECOLOR: |
| 595 | red = CNVT_TOHW(red, info->var.red.length); |
| 596 | green = CNVT_TOHW(green, info->var.green.length); |
| 597 | blue = CNVT_TOHW(blue, info->var.blue.length); |
| 598 | break; |
| 599 | case FB_VISUAL_PSEUDOCOLOR: |
| 600 | switch (info->var.bits_per_pixel) { |
| 601 | case 4: |
| 602 | if (regno > 15) |
| 603 | return -EINVAL; |
| 604 | |
| 605 | if (info->var.grayscale) { |
| 606 | pal = regno; |
| 607 | } else { |
| 608 | red >>= 4; |
| 609 | green >>= 8; |
| 610 | blue >>= 12; |
| 611 | |
| 612 | pal = red & 0x0f00; |
| 613 | pal |= green & 0x00f0; |
| 614 | pal |= blue & 0x000f; |
| 615 | } |
| 616 | if (regno == 0) |
| 617 | pal |= 0x2000; |
| 618 | palette[regno] = pal; |
| 619 | break; |
| 620 | |
| 621 | case 8: |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 622 | red >>= 4; |
| 623 | green >>= 8; |
| 624 | blue >>= 12; |
| 625 | |
| 626 | pal = (red & 0x0f00); |
| 627 | pal |= (green & 0x00f0); |
| 628 | pal |= (blue & 0x000f); |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 629 | |
| 630 | if (palette[regno] != pal) { |
| 631 | update_hw = 1; |
| 632 | palette[regno] = pal; |
| 633 | } |
| 634 | break; |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 635 | } |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 636 | break; |
| 637 | } |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 638 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 639 | /* Truecolor has hardware independent palette */ |
| 640 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 641 | u32 v; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 642 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 643 | if (regno > 15) |
| 644 | return -EINVAL; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 645 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 646 | v = (red << info->var.red.offset) | |
| 647 | (green << info->var.green.offset) | |
| 648 | (blue << info->var.blue.offset); |
| 649 | |
| 650 | switch (info->var.bits_per_pixel) { |
| 651 | case 16: |
| 652 | ((u16 *) (info->pseudo_palette))[regno] = v; |
| 653 | break; |
| 654 | case 24: |
| 655 | case 32: |
| 656 | ((u32 *) (info->pseudo_palette))[regno] = v; |
| 657 | break; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 658 | } |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 659 | if (palette[0] != 0x4000) { |
| 660 | update_hw = 1; |
| 661 | palette[0] = 0x4000; |
| 662 | } |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 665 | /* Update the palette in the h/w as needed. */ |
| 666 | if (update_hw) |
| 667 | lcd_blit(LOAD_PALETTE, par); |
| 668 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 669 | return 0; |
| 670 | } |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 671 | #undef CNVT_TOHW |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 672 | |
Afzal Mohammed | 39c87d4 | 2013-08-05 17:02:21 -0500 | [diff] [blame] | 673 | static void da8xx_fb_lcd_reset(void) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 674 | { |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 675 | /* DMA has to be disabled */ |
| 676 | lcdc_write(0, LCD_DMA_CTRL_REG); |
| 677 | lcdc_write(0, LCD_RASTER_CTRL_REG); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 678 | |
Manjunathappa, Prakash | 74a0efd | 2011-11-15 17:32:23 +0530 | [diff] [blame] | 679 | if (lcd_revision == LCD_VERSION_2) { |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 680 | lcdc_write(0, LCD_INT_ENABLE_SET_REG); |
Manjunathappa, Prakash | 74a0efd | 2011-11-15 17:32:23 +0530 | [diff] [blame] | 681 | /* Write 1 to reset */ |
| 682 | lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG); |
| 683 | lcdc_write(0, LCD_CLK_RESET_REG); |
| 684 | } |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 687 | static inline unsigned da8xx_fb_calc_clk_divider(struct da8xx_fb_par *par, |
| 688 | unsigned pixclock) |
Chaithrika U S | 8097b17 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 689 | { |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 690 | return par->lcd_fck_rate / (PICOS2KHZ(pixclock) * 1000); |
| 691 | } |
Chaithrika U S | 8097b17 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 692 | |
Afzal Mohammed | 404fdfe | 2013-08-05 17:02:28 -0500 | [diff] [blame] | 693 | static inline unsigned da8xx_fb_round_clk(struct da8xx_fb_par *par, |
| 694 | unsigned pixclock) |
| 695 | { |
| 696 | unsigned div; |
| 697 | |
| 698 | div = da8xx_fb_calc_clk_divider(par, pixclock); |
| 699 | return KHZ2PICOS(par->lcd_fck_rate / (1000 * div)); |
| 700 | } |
| 701 | |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 702 | static inline void da8xx_fb_config_clk_divider(unsigned div) |
| 703 | { |
Chaithrika U S | 8097b17 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 704 | /* Configure the LCD clock divisor. */ |
| 705 | lcdc_write(LCD_CLK_DIVISOR(div) | |
| 706 | (LCD_RASTER_MODE & 0x1), LCD_CTRL_REG); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 707 | |
| 708 | if (lcd_revision == LCD_VERSION_2) |
| 709 | lcdc_write(LCD_V2_DMA_CLK_EN | LCD_V2_LIDD_CLK_EN | |
| 710 | LCD_V2_CORE_CLK_EN, LCD_CLK_ENABLE_REG); |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 711 | } |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 712 | |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 713 | static inline void da8xx_fb_calc_config_clk_divider(struct da8xx_fb_par *par, |
| 714 | struct fb_videomode *mode) |
| 715 | { |
| 716 | unsigned div = da8xx_fb_calc_clk_divider(par, mode->pixclock); |
| 717 | |
| 718 | da8xx_fb_config_clk_divider(div); |
Chaithrika U S | 8097b17 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 719 | } |
| 720 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 721 | static int lcd_init(struct da8xx_fb_par *par, const struct lcd_ctrl_config *cfg, |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 722 | struct fb_videomode *panel) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 723 | { |
| 724 | u32 bpp; |
| 725 | int ret = 0; |
| 726 | |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 727 | da8xx_fb_calc_config_clk_divider(par, panel); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 728 | |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 729 | if (panel->sync & FB_SYNC_CLK_INVERT) |
Sudhakar Rajashekhara | 2f93e8f | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 730 | lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG) | |
| 731 | LCD_INVERT_PIXEL_CLOCK), LCD_RASTER_TIMING_2_REG); |
| 732 | else |
| 733 | lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG) & |
| 734 | ~LCD_INVERT_PIXEL_CLOCK), LCD_RASTER_TIMING_2_REG); |
| 735 | |
Manjunathappa, Prakash | fb8fa94 | 2012-07-18 21:03:36 +0530 | [diff] [blame] | 736 | /* Configure the DMA burst size and fifo threshold. */ |
| 737 | ret = lcd_cfg_dma(cfg->dma_burst_sz, cfg->fifo_th); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 738 | if (ret < 0) |
| 739 | return ret; |
| 740 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 741 | /* Configure the vertical and horizontal sync properties. */ |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 742 | lcd_cfg_vertical_sync(panel->lower_margin, panel->vsync_len, |
| 743 | panel->upper_margin); |
| 744 | lcd_cfg_horizontal_sync(panel->right_margin, panel->hsync_len, |
| 745 | panel->left_margin); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 746 | |
| 747 | /* Configure for disply */ |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 748 | ret = lcd_cfg_display(cfg, panel); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 749 | if (ret < 0) |
| 750 | return ret; |
| 751 | |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 752 | bpp = cfg->bpp; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 753 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 754 | if (bpp == 12) |
| 755 | bpp = 16; |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 756 | ret = lcd_cfg_frame_buffer(par, (unsigned int)panel->xres, |
| 757 | (unsigned int)panel->yres, bpp, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 758 | cfg->raster_order); |
| 759 | if (ret < 0) |
| 760 | return ret; |
| 761 | |
| 762 | /* Configure FDD */ |
| 763 | lcdc_write((lcdc_read(LCD_RASTER_CTRL_REG) & 0xfff00fff) | |
| 764 | (cfg->fdd << 12), LCD_RASTER_CTRL_REG); |
| 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 769 | /* IRQ handler for version 2 of LCDC */ |
| 770 | static irqreturn_t lcdc_irq_handler_rev02(int irq, void *arg) |
| 771 | { |
| 772 | struct da8xx_fb_par *par = arg; |
| 773 | u32 stat = lcdc_read(LCD_MASKED_STAT_REG); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 774 | |
| 775 | if ((stat & LCD_SYNC_LOST) && (stat & LCD_FIFO_UNDERFLOW)) { |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 776 | lcd_disable_raster(DA8XX_FRAME_NOWAIT); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 777 | lcdc_write(stat, LCD_MASKED_STAT_REG); |
| 778 | lcd_enable_raster(); |
| 779 | } else if (stat & LCD_PL_LOAD_DONE) { |
| 780 | /* |
| 781 | * Must disable raster before changing state of any control bit. |
| 782 | * And also must be disabled before clearing the PL loading |
| 783 | * interrupt via the following write to the status register. If |
| 784 | * this is done after then one gets multiple PL done interrupts. |
| 785 | */ |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 786 | lcd_disable_raster(DA8XX_FRAME_NOWAIT); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 787 | |
| 788 | lcdc_write(stat, LCD_MASKED_STAT_REG); |
| 789 | |
Manjunathappa, Prakash | 8a81dcc | 2012-07-18 20:51:11 +0530 | [diff] [blame] | 790 | /* Disable PL completion interrupt */ |
| 791 | lcdc_write(LCD_V2_PL_INT_ENA, LCD_INT_ENABLE_CLR_REG); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 792 | |
| 793 | /* Setup and start data loading mode */ |
| 794 | lcd_blit(LOAD_DATA, par); |
| 795 | } else { |
| 796 | lcdc_write(stat, LCD_MASKED_STAT_REG); |
| 797 | |
| 798 | if (stat & LCD_END_OF_FRAME0) { |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 799 | par->which_dma_channel_done = 0; |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 800 | lcdc_write(par->dma_start, |
| 801 | LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 802 | lcdc_write(par->dma_end, |
| 803 | LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 804 | par->vsync_flag = 1; |
| 805 | wake_up_interruptible(&par->vsync_wait); |
| 806 | } |
| 807 | |
| 808 | if (stat & LCD_END_OF_FRAME1) { |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 809 | par->which_dma_channel_done = 1; |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 810 | lcdc_write(par->dma_start, |
| 811 | LCD_DMA_FRM_BUF_BASE_ADDR_1_REG); |
| 812 | lcdc_write(par->dma_end, |
| 813 | LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG); |
| 814 | par->vsync_flag = 1; |
| 815 | wake_up_interruptible(&par->vsync_wait); |
| 816 | } |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 817 | |
| 818 | /* Set only when controller is disabled and at the end of |
| 819 | * active frame |
| 820 | */ |
| 821 | if (stat & BIT(0)) { |
| 822 | frame_done_flag = 1; |
| 823 | wake_up_interruptible(&frame_done_wq); |
| 824 | } |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | lcdc_write(0, LCD_END_OF_INT_IND_REG); |
| 828 | return IRQ_HANDLED; |
| 829 | } |
| 830 | |
| 831 | /* IRQ handler for version 1 LCDC */ |
| 832 | static irqreturn_t lcdc_irq_handler_rev01(int irq, void *arg) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 833 | { |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 834 | struct da8xx_fb_par *par = arg; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 835 | u32 stat = lcdc_read(LCD_STAT_REG); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 836 | u32 reg_ras; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 837 | |
| 838 | if ((stat & LCD_SYNC_LOST) && (stat & LCD_FIFO_UNDERFLOW)) { |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 839 | lcd_disable_raster(DA8XX_FRAME_NOWAIT); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 840 | lcdc_write(stat, LCD_STAT_REG); |
Chaithrika U S | 3611380 | 2009-12-15 16:46:38 -0800 | [diff] [blame] | 841 | lcd_enable_raster(); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 842 | } else if (stat & LCD_PL_LOAD_DONE) { |
| 843 | /* |
| 844 | * Must disable raster before changing state of any control bit. |
| 845 | * And also must be disabled before clearing the PL loading |
| 846 | * interrupt via the following write to the status register. If |
| 847 | * this is done after then one gets multiple PL done interrupts. |
| 848 | */ |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 849 | lcd_disable_raster(DA8XX_FRAME_NOWAIT); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 850 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 851 | lcdc_write(stat, LCD_STAT_REG); |
| 852 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 853 | /* Disable PL completion inerrupt */ |
| 854 | reg_ras = lcdc_read(LCD_RASTER_CTRL_REG); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 855 | reg_ras &= ~LCD_V1_PL_INT_ENA; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 856 | lcdc_write(reg_ras, LCD_RASTER_CTRL_REG); |
| 857 | |
| 858 | /* Setup and start data loading mode */ |
| 859 | lcd_blit(LOAD_DATA, par); |
| 860 | } else { |
| 861 | lcdc_write(stat, LCD_STAT_REG); |
| 862 | |
| 863 | if (stat & LCD_END_OF_FRAME0) { |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 864 | par->which_dma_channel_done = 0; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 865 | lcdc_write(par->dma_start, |
| 866 | LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 867 | lcdc_write(par->dma_end, |
| 868 | LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 869 | par->vsync_flag = 1; |
| 870 | wake_up_interruptible(&par->vsync_wait); |
| 871 | } |
| 872 | |
| 873 | if (stat & LCD_END_OF_FRAME1) { |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 874 | par->which_dma_channel_done = 1; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 875 | lcdc_write(par->dma_start, |
| 876 | LCD_DMA_FRM_BUF_BASE_ADDR_1_REG); |
| 877 | lcdc_write(par->dma_end, |
| 878 | LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG); |
| 879 | par->vsync_flag = 1; |
| 880 | wake_up_interruptible(&par->vsync_wait); |
| 881 | } |
| 882 | } |
| 883 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 884 | return IRQ_HANDLED; |
| 885 | } |
| 886 | |
| 887 | static int fb_check_var(struct fb_var_screeninfo *var, |
| 888 | struct fb_info *info) |
| 889 | { |
| 890 | int err = 0; |
Afzal Mohammed | 87dac71 | 2013-08-05 17:02:20 -0500 | [diff] [blame] | 891 | struct da8xx_fb_par *par = info->par; |
| 892 | int bpp = var->bits_per_pixel >> 3; |
| 893 | unsigned long line_size = var->xres_virtual * bpp; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 894 | |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 895 | if (var->bits_per_pixel > 16 && lcd_revision == LCD_VERSION_1) |
| 896 | return -EINVAL; |
| 897 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 898 | switch (var->bits_per_pixel) { |
| 899 | case 1: |
| 900 | case 8: |
| 901 | var->red.offset = 0; |
| 902 | var->red.length = 8; |
| 903 | var->green.offset = 0; |
| 904 | var->green.length = 8; |
| 905 | var->blue.offset = 0; |
| 906 | var->blue.length = 8; |
| 907 | var->transp.offset = 0; |
| 908 | var->transp.length = 0; |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 909 | var->nonstd = 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 910 | break; |
| 911 | case 4: |
| 912 | var->red.offset = 0; |
| 913 | var->red.length = 4; |
| 914 | var->green.offset = 0; |
| 915 | var->green.length = 4; |
| 916 | var->blue.offset = 0; |
| 917 | var->blue.length = 4; |
| 918 | var->transp.offset = 0; |
| 919 | var->transp.length = 0; |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 920 | var->nonstd = FB_NONSTD_REV_PIX_IN_B; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 921 | break; |
| 922 | case 16: /* RGB 565 */ |
Sudhakar Rajashekhara | 3510b8f | 2009-12-01 13:17:43 -0800 | [diff] [blame] | 923 | var->red.offset = 11; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 924 | var->red.length = 5; |
| 925 | var->green.offset = 5; |
| 926 | var->green.length = 6; |
Sudhakar Rajashekhara | 3510b8f | 2009-12-01 13:17:43 -0800 | [diff] [blame] | 927 | var->blue.offset = 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 928 | var->blue.length = 5; |
| 929 | var->transp.offset = 0; |
| 930 | var->transp.length = 0; |
Anatolij Gustschin | f413070 | 2012-03-13 14:13:57 +0100 | [diff] [blame] | 931 | var->nonstd = 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 932 | break; |
Manjunathappa, Prakash | 1a2b750 | 2012-08-14 18:51:42 +0530 | [diff] [blame] | 933 | case 24: |
| 934 | var->red.offset = 16; |
| 935 | var->red.length = 8; |
| 936 | var->green.offset = 8; |
| 937 | var->green.length = 8; |
| 938 | var->blue.offset = 0; |
| 939 | var->blue.length = 8; |
| 940 | var->nonstd = 0; |
| 941 | break; |
| 942 | case 32: |
| 943 | var->transp.offset = 24; |
| 944 | var->transp.length = 8; |
| 945 | var->red.offset = 16; |
| 946 | var->red.length = 8; |
| 947 | var->green.offset = 8; |
| 948 | var->green.length = 8; |
| 949 | var->blue.offset = 0; |
| 950 | var->blue.length = 8; |
| 951 | var->nonstd = 0; |
| 952 | break; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 953 | default: |
| 954 | err = -EINVAL; |
| 955 | } |
| 956 | |
| 957 | var->red.msb_right = 0; |
| 958 | var->green.msb_right = 0; |
| 959 | var->blue.msb_right = 0; |
| 960 | var->transp.msb_right = 0; |
Afzal Mohammed | 87dac71 | 2013-08-05 17:02:20 -0500 | [diff] [blame] | 961 | |
| 962 | if (line_size * var->yres_virtual > par->vram_size) |
| 963 | var->yres_virtual = par->vram_size / line_size; |
| 964 | |
| 965 | if (var->yres > var->yres_virtual) |
| 966 | var->yres = var->yres_virtual; |
| 967 | |
| 968 | if (var->xres > var->xres_virtual) |
| 969 | var->xres = var->xres_virtual; |
| 970 | |
| 971 | if (var->xres + var->xoffset > var->xres_virtual) |
| 972 | var->xoffset = var->xres_virtual - var->xres; |
| 973 | if (var->yres + var->yoffset > var->yres_virtual) |
| 974 | var->yoffset = var->yres_virtual - var->yres; |
| 975 | |
Afzal Mohammed | 404fdfe | 2013-08-05 17:02:28 -0500 | [diff] [blame] | 976 | var->pixclock = da8xx_fb_round_clk(par, var->pixclock); |
| 977 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 978 | return err; |
| 979 | } |
| 980 | |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 981 | #ifdef CONFIG_CPU_FREQ |
| 982 | static int lcd_da8xx_cpufreq_transition(struct notifier_block *nb, |
| 983 | unsigned long val, void *data) |
| 984 | { |
| 985 | struct da8xx_fb_par *par; |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 986 | |
| 987 | par = container_of(nb, struct da8xx_fb_par, freq_transition); |
Manjunathappa, Prakash | f820917 | 2012-01-03 18:10:51 +0530 | [diff] [blame] | 988 | if (val == CPUFREQ_POSTCHANGE) { |
| 989 | if (par->lcd_fck_rate != clk_get_rate(par->lcdc_clk)) { |
| 990 | par->lcd_fck_rate = clk_get_rate(par->lcdc_clk); |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 991 | lcd_disable_raster(DA8XX_FRAME_WAIT); |
Darren Etheridge | a6a799f | 2013-08-05 17:02:26 -0500 | [diff] [blame] | 992 | da8xx_fb_calc_config_clk_divider(par, &par->mode); |
Manjunathappa, Prakash | 6790081 | 2012-08-31 19:48:59 +0530 | [diff] [blame] | 993 | if (par->blank == FB_BLANK_UNBLANK) |
| 994 | lcd_enable_raster(); |
Manjunathappa, Prakash | f820917 | 2012-01-03 18:10:51 +0530 | [diff] [blame] | 995 | } |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | static inline int lcd_da8xx_cpufreq_register(struct da8xx_fb_par *par) |
| 1002 | { |
| 1003 | par->freq_transition.notifier_call = lcd_da8xx_cpufreq_transition; |
| 1004 | |
| 1005 | return cpufreq_register_notifier(&par->freq_transition, |
| 1006 | CPUFREQ_TRANSITION_NOTIFIER); |
| 1007 | } |
| 1008 | |
| 1009 | static inline void lcd_da8xx_cpufreq_deregister(struct da8xx_fb_par *par) |
| 1010 | { |
| 1011 | cpufreq_unregister_notifier(&par->freq_transition, |
| 1012 | CPUFREQ_TRANSITION_NOTIFIER); |
| 1013 | } |
| 1014 | #endif |
| 1015 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1016 | static int fb_remove(struct platform_device *dev) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1017 | { |
| 1018 | struct fb_info *info = dev_get_drvdata(&dev->dev); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1019 | |
| 1020 | if (info) { |
| 1021 | struct da8xx_fb_par *par = info->par; |
| 1022 | |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 1023 | #ifdef CONFIG_CPU_FREQ |
| 1024 | lcd_da8xx_cpufreq_deregister(par); |
| 1025 | #endif |
Chaithrika U S | 3611380 | 2009-12-15 16:46:38 -0800 | [diff] [blame] | 1026 | if (par->panel_power_ctrl) |
| 1027 | par->panel_power_ctrl(0); |
| 1028 | |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 1029 | lcd_disable_raster(DA8XX_FRAME_WAIT); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1030 | lcdc_write(0, LCD_RASTER_CTRL_REG); |
| 1031 | |
| 1032 | /* disable DMA */ |
| 1033 | lcdc_write(0, LCD_DMA_CTRL_REG); |
| 1034 | |
| 1035 | unregister_framebuffer(info); |
| 1036 | fb_dealloc_cmap(&info->cmap); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1037 | dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base, |
| 1038 | par->p_palette_base); |
| 1039 | dma_free_coherent(NULL, par->vram_size, par->vram_virt, |
| 1040 | par->vram_phys); |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 1041 | pm_runtime_put_sync(&dev->dev); |
| 1042 | pm_runtime_disable(&dev->dev); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1043 | framebuffer_release(info); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1044 | |
| 1045 | } |
Sudhakar Rajashekhara | 2f93e8f | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1046 | return 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1049 | /* |
| 1050 | * Function to wait for vertical sync which for this LCD peripheral |
| 1051 | * translates into waiting for the current raster frame to complete. |
| 1052 | */ |
| 1053 | static int fb_wait_for_vsync(struct fb_info *info) |
| 1054 | { |
| 1055 | struct da8xx_fb_par *par = info->par; |
| 1056 | int ret; |
| 1057 | |
| 1058 | /* |
| 1059 | * Set flag to 0 and wait for isr to set to 1. It would seem there is a |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1060 | * race condition here where the ISR could have occurred just before or |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1061 | * just after this set. But since we are just coarsely waiting for |
| 1062 | * a frame to complete then that's OK. i.e. if the frame completed |
| 1063 | * just before this code executed then we have to wait another full |
| 1064 | * frame time but there is no way to avoid such a situation. On the |
| 1065 | * other hand if the frame completed just after then we don't need |
| 1066 | * to wait long at all. Either way we are guaranteed to return to the |
| 1067 | * user immediately after a frame completion which is all that is |
| 1068 | * required. |
| 1069 | */ |
| 1070 | par->vsync_flag = 0; |
| 1071 | ret = wait_event_interruptible_timeout(par->vsync_wait, |
| 1072 | par->vsync_flag != 0, |
| 1073 | par->vsync_timeout); |
| 1074 | if (ret < 0) |
| 1075 | return ret; |
| 1076 | if (ret == 0) |
| 1077 | return -ETIMEDOUT; |
| 1078 | |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1082 | static int fb_ioctl(struct fb_info *info, unsigned int cmd, |
| 1083 | unsigned long arg) |
| 1084 | { |
| 1085 | struct lcd_sync_arg sync_arg; |
| 1086 | |
| 1087 | switch (cmd) { |
| 1088 | case FBIOGET_CONTRAST: |
| 1089 | case FBIOPUT_CONTRAST: |
| 1090 | case FBIGET_BRIGHTNESS: |
| 1091 | case FBIPUT_BRIGHTNESS: |
| 1092 | case FBIGET_COLOR: |
| 1093 | case FBIPUT_COLOR: |
Sudhakar Rajashekhara | 2f93e8f | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1094 | return -ENOTTY; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1095 | case FBIPUT_HSYNC: |
| 1096 | if (copy_from_user(&sync_arg, (char *)arg, |
| 1097 | sizeof(struct lcd_sync_arg))) |
Sudhakar Rajashekhara | 2f93e8f | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1098 | return -EFAULT; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1099 | lcd_cfg_horizontal_sync(sync_arg.back_porch, |
| 1100 | sync_arg.pulse_width, |
| 1101 | sync_arg.front_porch); |
| 1102 | break; |
| 1103 | case FBIPUT_VSYNC: |
| 1104 | if (copy_from_user(&sync_arg, (char *)arg, |
| 1105 | sizeof(struct lcd_sync_arg))) |
Sudhakar Rajashekhara | 2f93e8f | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1106 | return -EFAULT; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1107 | lcd_cfg_vertical_sync(sync_arg.back_porch, |
| 1108 | sync_arg.pulse_width, |
| 1109 | sync_arg.front_porch); |
| 1110 | break; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1111 | case FBIO_WAITFORVSYNC: |
| 1112 | return fb_wait_for_vsync(info); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1113 | default: |
| 1114 | return -EINVAL; |
| 1115 | } |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
Chaithrika U S | 312d971 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1119 | static int cfb_blank(int blank, struct fb_info *info) |
| 1120 | { |
| 1121 | struct da8xx_fb_par *par = info->par; |
| 1122 | int ret = 0; |
| 1123 | |
| 1124 | if (par->blank == blank) |
| 1125 | return 0; |
| 1126 | |
| 1127 | par->blank = blank; |
| 1128 | switch (blank) { |
| 1129 | case FB_BLANK_UNBLANK: |
Manjunathappa, Prakash | f7c848b | 2012-07-24 09:45:25 +0530 | [diff] [blame] | 1130 | lcd_enable_raster(); |
| 1131 | |
Chaithrika U S | 312d971 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1132 | if (par->panel_power_ctrl) |
| 1133 | par->panel_power_ctrl(1); |
Chaithrika U S | 312d971 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1134 | break; |
Yegor Yefremov | 99a647d | 2012-07-06 16:01:28 +0200 | [diff] [blame] | 1135 | case FB_BLANK_NORMAL: |
| 1136 | case FB_BLANK_VSYNC_SUSPEND: |
| 1137 | case FB_BLANK_HSYNC_SUSPEND: |
Chaithrika U S | 312d971 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1138 | case FB_BLANK_POWERDOWN: |
| 1139 | if (par->panel_power_ctrl) |
| 1140 | par->panel_power_ctrl(0); |
| 1141 | |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 1142 | lcd_disable_raster(DA8XX_FRAME_WAIT); |
Chaithrika U S | 312d971 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1143 | break; |
| 1144 | default: |
| 1145 | ret = -EINVAL; |
| 1146 | } |
| 1147 | |
| 1148 | return ret; |
| 1149 | } |
| 1150 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1151 | /* |
| 1152 | * Set new x,y offsets in the virtual display for the visible area and switch |
| 1153 | * to the new mode. |
| 1154 | */ |
| 1155 | static int da8xx_pan_display(struct fb_var_screeninfo *var, |
| 1156 | struct fb_info *fbi) |
| 1157 | { |
| 1158 | int ret = 0; |
| 1159 | struct fb_var_screeninfo new_var; |
| 1160 | struct da8xx_fb_par *par = fbi->par; |
| 1161 | struct fb_fix_screeninfo *fix = &fbi->fix; |
| 1162 | unsigned int end; |
| 1163 | unsigned int start; |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 1164 | unsigned long irq_flags; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1165 | |
| 1166 | if (var->xoffset != fbi->var.xoffset || |
| 1167 | var->yoffset != fbi->var.yoffset) { |
| 1168 | memcpy(&new_var, &fbi->var, sizeof(new_var)); |
| 1169 | new_var.xoffset = var->xoffset; |
| 1170 | new_var.yoffset = var->yoffset; |
| 1171 | if (fb_check_var(&new_var, fbi)) |
| 1172 | ret = -EINVAL; |
| 1173 | else { |
| 1174 | memcpy(&fbi->var, &new_var, sizeof(new_var)); |
| 1175 | |
| 1176 | start = fix->smem_start + |
| 1177 | new_var.yoffset * fix->line_length + |
Laurent Pinchart | e6c4d3d | 2011-06-14 09:24:45 +0000 | [diff] [blame] | 1178 | new_var.xoffset * fbi->var.bits_per_pixel / 8; |
| 1179 | end = start + fbi->var.yres * fix->line_length - 1; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1180 | par->dma_start = start; |
| 1181 | par->dma_end = end; |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 1182 | spin_lock_irqsave(&par->lock_for_chan_update, |
| 1183 | irq_flags); |
| 1184 | if (par->which_dma_channel_done == 0) { |
| 1185 | lcdc_write(par->dma_start, |
| 1186 | LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 1187 | lcdc_write(par->dma_end, |
| 1188 | LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 1189 | } else if (par->which_dma_channel_done == 1) { |
| 1190 | lcdc_write(par->dma_start, |
| 1191 | LCD_DMA_FRM_BUF_BASE_ADDR_1_REG); |
| 1192 | lcdc_write(par->dma_end, |
| 1193 | LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG); |
| 1194 | } |
| 1195 | spin_unlock_irqrestore(&par->lock_for_chan_update, |
| 1196 | irq_flags); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | return ret; |
| 1201 | } |
| 1202 | |
Darren Etheridge | fe8c98f | 2013-08-05 17:02:29 -0500 | [diff] [blame] | 1203 | static int da8xxfb_set_par(struct fb_info *info) |
| 1204 | { |
| 1205 | struct da8xx_fb_par *par = info->par; |
| 1206 | int ret; |
| 1207 | bool raster = da8xx_fb_is_raster_enabled(); |
| 1208 | |
| 1209 | if (raster) |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 1210 | lcd_disable_raster(DA8XX_FRAME_WAIT); |
Darren Etheridge | fe8c98f | 2013-08-05 17:02:29 -0500 | [diff] [blame] | 1211 | |
| 1212 | fb_var_to_videomode(&par->mode, &info->var); |
| 1213 | |
| 1214 | par->cfg.bpp = info->var.bits_per_pixel; |
| 1215 | |
| 1216 | info->fix.visual = (par->cfg.bpp <= 8) ? |
| 1217 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
| 1218 | info->fix.line_length = (par->mode.xres * par->cfg.bpp) / 8; |
| 1219 | |
| 1220 | ret = lcd_init(par, &par->cfg, &par->mode); |
| 1221 | if (ret < 0) { |
| 1222 | dev_err(par->dev, "lcd init failed\n"); |
| 1223 | return ret; |
| 1224 | } |
| 1225 | |
| 1226 | par->dma_start = info->fix.smem_start + |
| 1227 | info->var.yoffset * info->fix.line_length + |
| 1228 | info->var.xoffset * info->var.bits_per_pixel / 8; |
| 1229 | par->dma_end = par->dma_start + |
| 1230 | info->var.yres * info->fix.line_length - 1; |
| 1231 | |
| 1232 | lcdc_write(par->dma_start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 1233 | lcdc_write(par->dma_end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 1234 | lcdc_write(par->dma_start, LCD_DMA_FRM_BUF_BASE_ADDR_1_REG); |
| 1235 | lcdc_write(par->dma_end, LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG); |
| 1236 | |
| 1237 | if (raster) |
| 1238 | lcd_enable_raster(); |
| 1239 | |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1243 | static struct fb_ops da8xx_fb_ops = { |
| 1244 | .owner = THIS_MODULE, |
| 1245 | .fb_check_var = fb_check_var, |
Darren Etheridge | fe8c98f | 2013-08-05 17:02:29 -0500 | [diff] [blame] | 1246 | .fb_set_par = da8xxfb_set_par, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1247 | .fb_setcolreg = fb_setcolreg, |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1248 | .fb_pan_display = da8xx_pan_display, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1249 | .fb_ioctl = fb_ioctl, |
| 1250 | .fb_fillrect = cfb_fillrect, |
| 1251 | .fb_copyarea = cfb_copyarea, |
| 1252 | .fb_imageblit = cfb_imageblit, |
Chaithrika U S | 312d971 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1253 | .fb_blank = cfb_blank, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1254 | }; |
| 1255 | |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1256 | static int fb_probe(struct platform_device *device) |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1257 | { |
| 1258 | struct da8xx_lcdc_platform_data *fb_pdata = |
| 1259 | device->dev.platform_data; |
Darren Etheridge | c45757f | 2013-08-05 17:02:33 -0500 | [diff] [blame^] | 1260 | static struct resource *lcdc_regs; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1261 | struct lcd_ctrl_config *lcd_cfg; |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 1262 | struct fb_videomode *lcdc_info; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1263 | struct fb_info *da8xx_fb_info; |
| 1264 | struct clk *fb_clk = NULL; |
| 1265 | struct da8xx_fb_par *par; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1266 | int ret, i; |
Aditya Nellutla | 3b9cc4e | 2012-05-23 11:36:31 +0530 | [diff] [blame] | 1267 | unsigned long ulcm; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1268 | |
| 1269 | if (fb_pdata == NULL) { |
| 1270 | dev_err(&device->dev, "Can not get platform data\n"); |
| 1271 | return -ENOENT; |
| 1272 | } |
| 1273 | |
| 1274 | lcdc_regs = platform_get_resource(device, IORESOURCE_MEM, 0); |
Darren Etheridge | c45757f | 2013-08-05 17:02:33 -0500 | [diff] [blame^] | 1275 | da8xx_fb_reg_base = devm_ioremap_resource(&device->dev, lcdc_regs); |
| 1276 | if (IS_ERR(da8xx_fb_reg_base)) |
| 1277 | return PTR_ERR(da8xx_fb_reg_base); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1278 | |
Darren Etheridge | c45757f | 2013-08-05 17:02:33 -0500 | [diff] [blame^] | 1279 | fb_clk = devm_clk_get(&device->dev, "fck"); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1280 | if (IS_ERR(fb_clk)) { |
| 1281 | dev_err(&device->dev, "Can not get device clock\n"); |
Darren Etheridge | c45757f | 2013-08-05 17:02:33 -0500 | [diff] [blame^] | 1282 | return PTR_ERR(fb_clk); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1283 | } |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 1284 | |
| 1285 | pm_runtime_enable(&device->dev); |
| 1286 | pm_runtime_get_sync(&device->dev); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1287 | |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 1288 | /* Determine LCD IP Version */ |
| 1289 | switch (lcdc_read(LCD_PID_REG)) { |
| 1290 | case 0x4C100102: |
| 1291 | lcd_revision = LCD_VERSION_1; |
| 1292 | break; |
| 1293 | case 0x4F200800: |
Pantelis Antoniou | 8f22e8e | 2012-10-31 17:56:24 +0200 | [diff] [blame] | 1294 | case 0x4F201000: |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 1295 | lcd_revision = LCD_VERSION_2; |
| 1296 | break; |
| 1297 | default: |
| 1298 | dev_warn(&device->dev, "Unknown PID Reg value 0x%x, " |
| 1299 | "defaulting to LCD revision 1\n", |
| 1300 | lcdc_read(LCD_PID_REG)); |
| 1301 | lcd_revision = LCD_VERSION_1; |
| 1302 | break; |
| 1303 | } |
| 1304 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1305 | for (i = 0, lcdc_info = known_lcd_panels; |
| 1306 | i < ARRAY_SIZE(known_lcd_panels); |
| 1307 | i++, lcdc_info++) { |
| 1308 | if (strcmp(fb_pdata->type, lcdc_info->name) == 0) |
| 1309 | break; |
| 1310 | } |
| 1311 | |
| 1312 | if (i == ARRAY_SIZE(known_lcd_panels)) { |
| 1313 | dev_err(&device->dev, "GLCD: No valid panel found\n"); |
Roel Kluin | dd04a6b | 2009-11-17 14:06:15 -0800 | [diff] [blame] | 1314 | ret = -ENODEV; |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 1315 | goto err_pm_runtime_disable; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1316 | } else |
| 1317 | dev_info(&device->dev, "GLCD: Found %s panel\n", |
| 1318 | fb_pdata->type); |
| 1319 | |
| 1320 | lcd_cfg = (struct lcd_ctrl_config *)fb_pdata->controller_data; |
| 1321 | |
| 1322 | da8xx_fb_info = framebuffer_alloc(sizeof(struct da8xx_fb_par), |
| 1323 | &device->dev); |
| 1324 | if (!da8xx_fb_info) { |
| 1325 | dev_dbg(&device->dev, "Memory allocation failed for fb_info\n"); |
| 1326 | ret = -ENOMEM; |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 1327 | goto err_pm_runtime_disable; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | par = da8xx_fb_info->par; |
Afzal Mohammed | dbe8e48 | 2013-08-05 17:02:27 -0500 | [diff] [blame] | 1331 | par->dev = &device->dev; |
Chaithrika U S | 8097b17 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 1332 | par->lcdc_clk = fb_clk; |
Manjunathappa, Prakash | f820917 | 2012-01-03 18:10:51 +0530 | [diff] [blame] | 1333 | par->lcd_fck_rate = clk_get_rate(fb_clk); |
Chaithrika U S | 3611380 | 2009-12-15 16:46:38 -0800 | [diff] [blame] | 1334 | if (fb_pdata->panel_power_ctrl) { |
| 1335 | par->panel_power_ctrl = fb_pdata->panel_power_ctrl; |
| 1336 | par->panel_power_ctrl(1); |
| 1337 | } |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1338 | |
Afzal Mohammed | b866458 | 2013-08-05 17:02:22 -0500 | [diff] [blame] | 1339 | fb_videomode_to_var(&da8xx_fb_var, lcdc_info); |
Afzal Mohammed | b6dbe8e | 2013-08-05 17:02:24 -0500 | [diff] [blame] | 1340 | par->cfg = *lcd_cfg; |
Afzal Mohammed | b866458 | 2013-08-05 17:02:22 -0500 | [diff] [blame] | 1341 | |
Darren Etheridge | fe8c98f | 2013-08-05 17:02:29 -0500 | [diff] [blame] | 1342 | da8xx_fb_lcd_reset(); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1343 | |
| 1344 | /* allocate frame buffer */ |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 1345 | par->vram_size = lcdc_info->xres * lcdc_info->yres * lcd_cfg->bpp; |
| 1346 | ulcm = lcm((lcdc_info->xres * lcd_cfg->bpp)/8, PAGE_SIZE); |
Aditya Nellutla | 3b9cc4e | 2012-05-23 11:36:31 +0530 | [diff] [blame] | 1347 | par->vram_size = roundup(par->vram_size/8, ulcm); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1348 | par->vram_size = par->vram_size * LCD_NUM_BUFFERS; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1349 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1350 | par->vram_virt = dma_alloc_coherent(NULL, |
| 1351 | par->vram_size, |
| 1352 | (resource_size_t *) &par->vram_phys, |
| 1353 | GFP_KERNEL | GFP_DMA); |
| 1354 | if (!par->vram_virt) { |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1355 | dev_err(&device->dev, |
| 1356 | "GLCD: kmalloc for frame buffer failed\n"); |
| 1357 | ret = -EINVAL; |
| 1358 | goto err_release_fb; |
| 1359 | } |
| 1360 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1361 | da8xx_fb_info->screen_base = (char __iomem *) par->vram_virt; |
| 1362 | da8xx_fb_fix.smem_start = par->vram_phys; |
| 1363 | da8xx_fb_fix.smem_len = par->vram_size; |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 1364 | da8xx_fb_fix.line_length = (lcdc_info->xres * lcd_cfg->bpp) / 8; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1365 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1366 | par->dma_start = par->vram_phys; |
Manjunathappa, Prakash | f772fab | 2012-10-16 10:23:15 +0530 | [diff] [blame] | 1367 | par->dma_end = par->dma_start + lcdc_info->yres * |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1368 | da8xx_fb_fix.line_length - 1; |
| 1369 | |
| 1370 | /* allocate palette buffer */ |
| 1371 | par->v_palette_base = dma_alloc_coherent(NULL, |
| 1372 | PALETTE_SIZE, |
| 1373 | (resource_size_t *) |
| 1374 | &par->p_palette_base, |
| 1375 | GFP_KERNEL | GFP_DMA); |
| 1376 | if (!par->v_palette_base) { |
| 1377 | dev_err(&device->dev, |
| 1378 | "GLCD: kmalloc for palette buffer failed\n"); |
| 1379 | ret = -EINVAL; |
| 1380 | goto err_release_fb_mem; |
| 1381 | } |
| 1382 | memset(par->v_palette_base, 0, PALETTE_SIZE); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1383 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1384 | par->irq = platform_get_irq(device, 0); |
| 1385 | if (par->irq < 0) { |
| 1386 | ret = -ENOENT; |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1387 | goto err_release_pl_mem; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1390 | da8xx_fb_var.grayscale = |
Manjunathappa, Prakash | 3b43ad2 | 2012-10-16 10:23:16 +0530 | [diff] [blame] | 1391 | lcd_cfg->panel_shade == MONOCHROME ? 1 : 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1392 | da8xx_fb_var.bits_per_pixel = lcd_cfg->bpp; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1393 | |
| 1394 | /* Initialize fbinfo */ |
| 1395 | da8xx_fb_info->flags = FBINFO_FLAG_DEFAULT; |
| 1396 | da8xx_fb_info->fix = da8xx_fb_fix; |
| 1397 | da8xx_fb_info->var = da8xx_fb_var; |
| 1398 | da8xx_fb_info->fbops = &da8xx_fb_ops; |
| 1399 | da8xx_fb_info->pseudo_palette = par->pseudo_palette; |
Sudhakar Rajashekhara | 3510b8f | 2009-12-01 13:17:43 -0800 | [diff] [blame] | 1400 | da8xx_fb_info->fix.visual = (da8xx_fb_info->var.bits_per_pixel <= 8) ? |
| 1401 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1402 | |
| 1403 | ret = fb_alloc_cmap(&da8xx_fb_info->cmap, PALETTE_SIZE, 0); |
| 1404 | if (ret) |
Caglar Akyuz | 93c176f | 2010-11-30 20:04:14 +0000 | [diff] [blame] | 1405 | goto err_release_pl_mem; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1406 | da8xx_fb_info->cmap.len = par->palette_sz; |
| 1407 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1408 | /* initialize var_screeninfo */ |
| 1409 | da8xx_fb_var.activate = FB_ACTIVATE_FORCE; |
| 1410 | fb_set_var(da8xx_fb_info, &da8xx_fb_var); |
| 1411 | |
| 1412 | dev_set_drvdata(&device->dev, da8xx_fb_info); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1413 | |
| 1414 | /* initialize the vsync wait queue */ |
| 1415 | init_waitqueue_head(&par->vsync_wait); |
| 1416 | par->vsync_timeout = HZ / 5; |
Manjunathappa, Prakash | deb95c6 | 2012-07-18 21:01:56 +0530 | [diff] [blame] | 1417 | par->which_dma_channel_done = -1; |
| 1418 | spin_lock_init(&par->lock_for_chan_update); |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1419 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1420 | /* Register the Frame Buffer */ |
| 1421 | if (register_framebuffer(da8xx_fb_info) < 0) { |
| 1422 | dev_err(&device->dev, |
| 1423 | "GLCD: Frame Buffer Registration Failed!\n"); |
| 1424 | ret = -EINVAL; |
| 1425 | goto err_dealloc_cmap; |
| 1426 | } |
| 1427 | |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 1428 | #ifdef CONFIG_CPU_FREQ |
| 1429 | ret = lcd_da8xx_cpufreq_register(par); |
| 1430 | if (ret) { |
| 1431 | dev_err(&device->dev, "failed to register cpufreq\n"); |
| 1432 | goto err_cpu_freq; |
| 1433 | } |
| 1434 | #endif |
Caglar Akyuz | 93c176f | 2010-11-30 20:04:14 +0000 | [diff] [blame] | 1435 | |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 1436 | if (lcd_revision == LCD_VERSION_1) |
| 1437 | lcdc_irq_handler = lcdc_irq_handler_rev01; |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 1438 | else { |
| 1439 | init_waitqueue_head(&frame_done_wq); |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 1440 | lcdc_irq_handler = lcdc_irq_handler_rev02; |
Manjunathappa, Prakash | a481b37 | 2012-08-24 18:43:00 +0530 | [diff] [blame] | 1441 | } |
Manjunathappa, Prakash | c6daf05 | 2011-07-05 15:51:20 +0530 | [diff] [blame] | 1442 | |
Darren Etheridge | c45757f | 2013-08-05 17:02:33 -0500 | [diff] [blame^] | 1443 | ret = devm_request_irq(&device->dev, par->irq, lcdc_irq_handler, 0, |
| 1444 | DRIVER_NAME, par); |
Caglar Akyuz | 93c176f | 2010-11-30 20:04:14 +0000 | [diff] [blame] | 1445 | if (ret) |
| 1446 | goto irq_freq; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1447 | return 0; |
| 1448 | |
Caglar Akyuz | 93c176f | 2010-11-30 20:04:14 +0000 | [diff] [blame] | 1449 | irq_freq: |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 1450 | #ifdef CONFIG_CPU_FREQ |
axel lin | 360c202 | 2011-01-20 03:50:51 +0000 | [diff] [blame] | 1451 | lcd_da8xx_cpufreq_deregister(par); |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 1452 | err_cpu_freq: |
Manjunathappa, Prakash | 3a84409 | 2012-02-09 10:34:38 +0530 | [diff] [blame] | 1453 | #endif |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 1454 | unregister_framebuffer(da8xx_fb_info); |
Chaithrika U S | e04e548 | 2009-12-15 16:46:29 -0800 | [diff] [blame] | 1455 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1456 | err_dealloc_cmap: |
| 1457 | fb_dealloc_cmap(&da8xx_fb_info->cmap); |
| 1458 | |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1459 | err_release_pl_mem: |
| 1460 | dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base, |
| 1461 | par->p_palette_base); |
| 1462 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1463 | err_release_fb_mem: |
Martin Ambrose | 1f9c3e1 | 2010-05-24 14:34:01 -0700 | [diff] [blame] | 1464 | dma_free_coherent(NULL, par->vram_size, par->vram_virt, par->vram_phys); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1465 | |
| 1466 | err_release_fb: |
| 1467 | framebuffer_release(da8xx_fb_info); |
| 1468 | |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 1469 | err_pm_runtime_disable: |
| 1470 | pm_runtime_put_sync(&device->dev); |
| 1471 | pm_runtime_disable(&device->dev); |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1472 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1473 | return ret; |
| 1474 | } |
| 1475 | |
| 1476 | #ifdef CONFIG_PM |
Manjunathappa, Prakash | 7a93cbb | 2012-09-25 19:41:41 +0530 | [diff] [blame] | 1477 | struct lcdc_context { |
| 1478 | u32 clk_enable; |
| 1479 | u32 ctrl; |
| 1480 | u32 dma_ctrl; |
| 1481 | u32 raster_timing_0; |
| 1482 | u32 raster_timing_1; |
| 1483 | u32 raster_timing_2; |
| 1484 | u32 int_enable_set; |
| 1485 | u32 dma_frm_buf_base_addr_0; |
| 1486 | u32 dma_frm_buf_ceiling_addr_0; |
| 1487 | u32 dma_frm_buf_base_addr_1; |
| 1488 | u32 dma_frm_buf_ceiling_addr_1; |
| 1489 | u32 raster_ctrl; |
| 1490 | } reg_context; |
| 1491 | |
| 1492 | static void lcd_context_save(void) |
| 1493 | { |
| 1494 | if (lcd_revision == LCD_VERSION_2) { |
| 1495 | reg_context.clk_enable = lcdc_read(LCD_CLK_ENABLE_REG); |
| 1496 | reg_context.int_enable_set = lcdc_read(LCD_INT_ENABLE_SET_REG); |
| 1497 | } |
| 1498 | |
| 1499 | reg_context.ctrl = lcdc_read(LCD_CTRL_REG); |
| 1500 | reg_context.dma_ctrl = lcdc_read(LCD_DMA_CTRL_REG); |
| 1501 | reg_context.raster_timing_0 = lcdc_read(LCD_RASTER_TIMING_0_REG); |
| 1502 | reg_context.raster_timing_1 = lcdc_read(LCD_RASTER_TIMING_1_REG); |
| 1503 | reg_context.raster_timing_2 = lcdc_read(LCD_RASTER_TIMING_2_REG); |
| 1504 | reg_context.dma_frm_buf_base_addr_0 = |
| 1505 | lcdc_read(LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 1506 | reg_context.dma_frm_buf_ceiling_addr_0 = |
| 1507 | lcdc_read(LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 1508 | reg_context.dma_frm_buf_base_addr_1 = |
| 1509 | lcdc_read(LCD_DMA_FRM_BUF_BASE_ADDR_1_REG); |
| 1510 | reg_context.dma_frm_buf_ceiling_addr_1 = |
| 1511 | lcdc_read(LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG); |
| 1512 | reg_context.raster_ctrl = lcdc_read(LCD_RASTER_CTRL_REG); |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | static void lcd_context_restore(void) |
| 1517 | { |
| 1518 | if (lcd_revision == LCD_VERSION_2) { |
| 1519 | lcdc_write(reg_context.clk_enable, LCD_CLK_ENABLE_REG); |
| 1520 | lcdc_write(reg_context.int_enable_set, LCD_INT_ENABLE_SET_REG); |
| 1521 | } |
| 1522 | |
| 1523 | lcdc_write(reg_context.ctrl, LCD_CTRL_REG); |
| 1524 | lcdc_write(reg_context.dma_ctrl, LCD_DMA_CTRL_REG); |
| 1525 | lcdc_write(reg_context.raster_timing_0, LCD_RASTER_TIMING_0_REG); |
| 1526 | lcdc_write(reg_context.raster_timing_1, LCD_RASTER_TIMING_1_REG); |
| 1527 | lcdc_write(reg_context.raster_timing_2, LCD_RASTER_TIMING_2_REG); |
| 1528 | lcdc_write(reg_context.dma_frm_buf_base_addr_0, |
| 1529 | LCD_DMA_FRM_BUF_BASE_ADDR_0_REG); |
| 1530 | lcdc_write(reg_context.dma_frm_buf_ceiling_addr_0, |
| 1531 | LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG); |
| 1532 | lcdc_write(reg_context.dma_frm_buf_base_addr_1, |
| 1533 | LCD_DMA_FRM_BUF_BASE_ADDR_1_REG); |
| 1534 | lcdc_write(reg_context.dma_frm_buf_ceiling_addr_1, |
| 1535 | LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG); |
| 1536 | lcdc_write(reg_context.raster_ctrl, LCD_RASTER_CTRL_REG); |
| 1537 | return; |
| 1538 | } |
| 1539 | |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1540 | static int fb_suspend(struct platform_device *dev, pm_message_t state) |
| 1541 | { |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1542 | struct fb_info *info = platform_get_drvdata(dev); |
| 1543 | struct da8xx_fb_par *par = info->par; |
| 1544 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1545 | console_lock(); |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1546 | if (par->panel_power_ctrl) |
| 1547 | par->panel_power_ctrl(0); |
| 1548 | |
| 1549 | fb_set_suspend(info, 1); |
Darren Etheridge | 26e7164 | 2013-08-05 17:02:30 -0500 | [diff] [blame] | 1550 | lcd_disable_raster(DA8XX_FRAME_WAIT); |
Manjunathappa, Prakash | 7a93cbb | 2012-09-25 19:41:41 +0530 | [diff] [blame] | 1551 | lcd_context_save(); |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 1552 | pm_runtime_put_sync(&dev->dev); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1553 | console_unlock(); |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1554 | |
| 1555 | return 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1556 | } |
| 1557 | static int fb_resume(struct platform_device *dev) |
| 1558 | { |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1559 | struct fb_info *info = platform_get_drvdata(dev); |
| 1560 | struct da8xx_fb_par *par = info->par; |
| 1561 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1562 | console_lock(); |
Manjunathappa, Prakash | 9dd44d5 | 2012-09-21 21:20:57 +0530 | [diff] [blame] | 1563 | pm_runtime_get_sync(&dev->dev); |
Manjunathappa, Prakash | 7a93cbb | 2012-09-25 19:41:41 +0530 | [diff] [blame] | 1564 | lcd_context_restore(); |
Manjunathappa, Prakash | 6790081 | 2012-08-31 19:48:59 +0530 | [diff] [blame] | 1565 | if (par->blank == FB_BLANK_UNBLANK) { |
| 1566 | lcd_enable_raster(); |
Manjunathappa, Prakash | f7c848b | 2012-07-24 09:45:25 +0530 | [diff] [blame] | 1567 | |
Manjunathappa, Prakash | 6790081 | 2012-08-31 19:48:59 +0530 | [diff] [blame] | 1568 | if (par->panel_power_ctrl) |
| 1569 | par->panel_power_ctrl(1); |
| 1570 | } |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1571 | |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1572 | fb_set_suspend(info, 0); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1573 | console_unlock(); |
Chaithrika U S | 1d3c6c7 | 2009-12-15 16:46:39 -0800 | [diff] [blame] | 1574 | |
| 1575 | return 0; |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1576 | } |
| 1577 | #else |
| 1578 | #define fb_suspend NULL |
| 1579 | #define fb_resume NULL |
| 1580 | #endif |
| 1581 | |
| 1582 | static struct platform_driver da8xx_fb_driver = { |
| 1583 | .probe = fb_probe, |
Greg Kroah-Hartman | 48c68c4 | 2012-12-21 13:07:39 -0800 | [diff] [blame] | 1584 | .remove = fb_remove, |
Sudhakar Rajashekhara | 4ed824d | 2009-09-22 16:47:06 -0700 | [diff] [blame] | 1585 | .suspend = fb_suspend, |
| 1586 | .resume = fb_resume, |
| 1587 | .driver = { |
| 1588 | .name = DRIVER_NAME, |
| 1589 | .owner = THIS_MODULE, |
| 1590 | }, |
| 1591 | }; |
| 1592 | |
| 1593 | static int __init da8xx_fb_init(void) |
| 1594 | { |
| 1595 | return platform_driver_register(&da8xx_fb_driver); |
| 1596 | } |
| 1597 | |
| 1598 | static void __exit da8xx_fb_cleanup(void) |
| 1599 | { |
| 1600 | platform_driver_unregister(&da8xx_fb_driver); |
| 1601 | } |
| 1602 | |
| 1603 | module_init(da8xx_fb_init); |
| 1604 | module_exit(da8xx_fb_cleanup); |
| 1605 | |
| 1606 | MODULE_DESCRIPTION("Framebuffer driver for TI da8xx/omap-l1xx"); |
| 1607 | MODULE_AUTHOR("Texas Instruments"); |
| 1608 | MODULE_LICENSE("GPL"); |