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