blob: dfe757254e2682729fa744acb0478d2a9643d400 [file] [log] [blame]
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001/*
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, Prakash9dd44d52012-09-21 21:20:57 +053029#include <linux/pm_runtime.h>
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070030#include <linux/interrupt.h>
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +053031#include <linux/wait.h>
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070032#include <linux/clk.h>
Chaithrika U Se04e5482009-12-15 16:46:29 -080033#include <linux/cpufreq.h>
Chaithrika U S1d3c6c72009-12-15 16:46:39 -080034#include <linux/console.h>
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +053035#include <linux/spinlock.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Florian Tobias Schandinata0239072012-07-29 16:47:40 +000037#include <linux/delay.h>
Aditya Nellutla3b9cc4e2012-05-23 11:36:31 +053038#include <linux/lcm.h>
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070039#include <video/da8xx-fb.h>
Manjunathappa, Prakash12fa8352012-02-09 11:54:06 +053040#include <asm/div64.h>
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070041
42#define DRIVER_NAME "da8xx_lcdc"
43
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +053044#define LCD_VERSION_1 1
45#define LCD_VERSION_2 2
46
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070047/* LCD Status Register */
Martin Ambrose1f9c3e12010-05-24 14:34:01 -070048#define LCD_END_OF_FRAME1 BIT(9)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070049#define LCD_END_OF_FRAME0 BIT(8)
Martin Ambrose1f9c3e12010-05-24 14:34:01 -070050#define LCD_PL_LOAD_DONE BIT(6)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070051#define LCD_FIFO_UNDERFLOW BIT(5)
52#define LCD_SYNC_LOST BIT(2)
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +053053#define LCD_FRAME_DONE BIT(0)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070054
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, Prakashc6daf052011-07-05 15:51:20 +053062#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 Rajashekhara4ed824d2009-09-22 16:47:06 -070065#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 Ambrose1f9c3e12010-05-24 14:34:01 -070075#define DATA_ONLY 0x02
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070076
77#define LCD_MONO_8BIT_MODE BIT(9)
78#define LCD_RASTER_ORDER BIT(8)
79#define LCD_TFT_MODE BIT(7)
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +053080#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 Rajashekhara4ed824d2009-09-22 16:47:06 -070084#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, Prakashc6daf052011-07-05 15:51:20 +053088#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, Prakash1a2b7502012-08-14 18:51:42 +053092#define LCD_V2_TFT_24BPP_MODE BIT(25)
93#define LCD_V2_TFT_24BPP_UNPACK BIT(26)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070094
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, Prakashc6daf052011-07-05 15:51:20 +0530105#define LCD_PID_REG 0x0
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700106#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 Ambrose1f9c3e12010-05-24 14:34:01 -0700115#define LCD_DMA_FRM_BUF_BASE_ADDR_1_REG 0x4C
116#define LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG 0x50
117
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530118/* 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, Prakash74a0efd2011-11-15 17:32:23 +0530128#define LCD_CLK_MAIN_RESET BIT(3)
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530129
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700130#define LCD_NUM_BUFFERS 2
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700131
132#define WSI_TIMEOUT 50
133#define PALETTE_SIZE 256
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700134
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500135#define CLK_MIN_DIV 2
136#define CLK_MAX_DIV 255
137
Arnd Bergmann34aef6e2012-09-14 20:33:43 +0000138static void __iomem *da8xx_fb_reg_base;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530139static unsigned int lcd_revision;
140static irq_handler_t lcdc_irq_handler;
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +0530141static wait_queue_head_t frame_done_wq;
142static int frame_done_flag;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700143
144static inline unsigned int lcdc_read(unsigned int addr)
145{
146 return (unsigned int)__raw_readl(da8xx_fb_reg_base + (addr));
147}
148
149static inline void lcdc_write(unsigned int val, unsigned int addr)
150{
151 __raw_writel(val, da8xx_fb_reg_base + (addr));
152}
153
154struct da8xx_fb_par {
Afzal Mohammeddbe8e482013-08-05 17:02:27 -0500155 struct device *dev;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700156 resource_size_t p_palette_base;
157 unsigned char *v_palette_base;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700158 dma_addr_t vram_phys;
159 unsigned long vram_size;
160 void *vram_virt;
161 unsigned int dma_start;
162 unsigned int dma_end;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700163 struct clk *lcdc_clk;
164 int irq;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700165 unsigned int palette_sz;
Chaithrika U S36113802009-12-15 16:46:38 -0800166 int blank;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700167 wait_queue_head_t vsync_wait;
168 int vsync_flag;
169 int vsync_timeout;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530170 spinlock_t lock_for_chan_update;
171
172 /*
173 * LCDC has 2 ping pong DMA channels, channel 0
174 * and channel 1.
175 */
176 unsigned int which_dma_channel_done;
Chaithrika U Se04e5482009-12-15 16:46:29 -0800177#ifdef CONFIG_CPU_FREQ
178 struct notifier_block freq_transition;
179#endif
Afzal Mohammed44f627a2013-08-05 17:02:25 -0500180 unsigned int lcd_fck_rate;
Chaithrika U S36113802009-12-15 16:46:38 -0800181 void (*panel_power_ctrl)(int);
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530182 u32 pseudo_palette[16];
Afzal Mohammedb6dbe8e2013-08-05 17:02:24 -0500183 struct fb_videomode mode;
184 struct lcd_ctrl_config cfg;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700185};
186
Afzal Mohammedbe0f6db2013-08-05 17:02:23 -0500187static struct fb_var_screeninfo da8xx_fb_var;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700188
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -0800189static struct fb_fix_screeninfo da8xx_fb_fix = {
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700190 .id = "DA8xx FB Drv",
191 .type = FB_TYPE_PACKED_PIXELS,
192 .type_aux = 0,
193 .visual = FB_VISUAL_PSEUDOCOLOR,
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700194 .xpanstep = 0,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700195 .ypanstep = 1,
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700196 .ywrapstep = 0,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700197 .accel = FB_ACCEL_NONE
198};
199
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530200static struct fb_videomode known_lcd_panels[] = {
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700201 /* Sharp LCD035Q3DG01 */
202 [0] = {
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530203 .name = "Sharp_LCD035Q3DG01",
204 .xres = 320,
205 .yres = 240,
Darren Etheridgea6a799f2013-08-05 17:02:26 -0500206 .pixclock = KHZ2PICOS(4607),
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530207 .left_margin = 6,
208 .right_margin = 8,
209 .upper_margin = 2,
210 .lower_margin = 2,
211 .hsync_len = 0,
212 .vsync_len = 0,
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530213 .sync = FB_SYNC_CLK_INVERT |
214 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700215 },
216 /* Sharp LK043T1DG01 */
217 [1] = {
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530218 .name = "Sharp_LK043T1DG01",
219 .xres = 480,
220 .yres = 272,
Darren Etheridgea6a799f2013-08-05 17:02:26 -0500221 .pixclock = KHZ2PICOS(7833),
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530222 .left_margin = 2,
223 .right_margin = 2,
224 .upper_margin = 2,
225 .lower_margin = 2,
226 .hsync_len = 41,
227 .vsync_len = 10,
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530228 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530229 .flag = 0,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700230 },
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100231 [2] = {
232 /* Hitachi SP10Q010 */
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530233 .name = "SP10Q010",
234 .xres = 320,
235 .yres = 240,
Darren Etheridgea6a799f2013-08-05 17:02:26 -0500236 .pixclock = KHZ2PICOS(7833),
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530237 .left_margin = 10,
238 .right_margin = 10,
239 .upper_margin = 10,
240 .lower_margin = 10,
241 .hsync_len = 10,
242 .vsync_len = 10,
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530243 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530244 .flag = 0,
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100245 },
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700246};
247
Darren Etheridgefe8c98f2013-08-05 17:02:29 -0500248static inline bool da8xx_fb_is_raster_enabled(void)
249{
250 return !!(lcdc_read(LCD_RASTER_CTRL_REG) & LCD_RASTER_ENABLE);
251}
252
Chaithrika U S36113802009-12-15 16:46:38 -0800253/* Enable the Raster Engine of the LCD Controller */
254static inline void lcd_enable_raster(void)
255{
256 u32 reg;
257
Manjunathappa, Prakash92b4e452012-07-20 21:21:11 +0530258 /* Put LCDC in reset for several cycles */
259 if (lcd_revision == LCD_VERSION_2)
260 /* Write 1 to reset LCDC */
261 lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG);
262 mdelay(1);
263
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530264 /* Bring LCDC out of reset */
265 if (lcd_revision == LCD_VERSION_2)
266 lcdc_write(0, LCD_CLK_RESET_REG);
Manjunathappa, Prakash92b4e452012-07-20 21:21:11 +0530267 mdelay(1);
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530268
Manjunathappa, Prakash92b4e452012-07-20 21:21:11 +0530269 /* Above reset sequence doesnot reset register context */
Chaithrika U S36113802009-12-15 16:46:38 -0800270 reg = lcdc_read(LCD_RASTER_CTRL_REG);
271 if (!(reg & LCD_RASTER_ENABLE))
272 lcdc_write(reg | LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG);
273}
274
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700275/* Disable the Raster Engine of the LCD Controller */
Darren Etheridge26e71642013-08-05 17:02:30 -0500276static inline void lcd_disable_raster(enum da8xx_frame_complete
277 wait_for_frame_done)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700278{
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700279 u32 reg;
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +0530280 int ret;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700281
282 reg = lcdc_read(LCD_RASTER_CTRL_REG);
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700283 if (reg & LCD_RASTER_ENABLE)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700284 lcdc_write(reg & ~LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG);
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +0530285 else
286 /* return if already disabled */
287 return;
288
Darren Etheridge26e71642013-08-05 17:02:30 -0500289 if ((wait_for_frame_done == DA8XX_FRAME_WAIT) &&
290 (lcd_revision == LCD_VERSION_2)) {
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +0530291 frame_done_flag = 0;
292 ret = wait_event_interruptible_timeout(frame_done_wq,
293 frame_done_flag != 0,
294 msecs_to_jiffies(50));
295 if (ret == 0)
296 pr_err("LCD Controller timed out\n");
297 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700298}
299
300static void lcd_blit(int load_mode, struct da8xx_fb_par *par)
301{
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700302 u32 start;
303 u32 end;
304 u32 reg_ras;
305 u32 reg_dma;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530306 u32 reg_int;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700307
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700308 /* init reg to clear PLM (loading mode) fields */
309 reg_ras = lcdc_read(LCD_RASTER_CTRL_REG);
310 reg_ras &= ~(3 << 20);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700311
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700312 reg_dma = lcdc_read(LCD_DMA_CTRL_REG);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700313
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700314 if (load_mode == LOAD_DATA) {
315 start = par->dma_start;
316 end = par->dma_end;
317
318 reg_ras |= LCD_PALETTE_LOAD_MODE(DATA_ONLY);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530319 if (lcd_revision == LCD_VERSION_1) {
320 reg_dma |= LCD_V1_END_OF_FRAME_INT_ENA;
321 } else {
322 reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
323 LCD_V2_END_OF_FRAME0_INT_ENA |
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +0530324 LCD_V2_END_OF_FRAME1_INT_ENA |
Afzal Mohammede4008e22013-08-05 17:02:32 -0500325 LCD_FRAME_DONE | LCD_SYNC_LOST;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530326 lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
327 }
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700328 reg_dma |= LCD_DUAL_FRAME_BUFFER_ENABLE;
329
330 lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
331 lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
332 lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
333 lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
334 } else if (load_mode == LOAD_PALETTE) {
335 start = par->p_palette_base;
336 end = start + par->palette_sz - 1;
337
338 reg_ras |= LCD_PALETTE_LOAD_MODE(PALETTE_ONLY);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530339
340 if (lcd_revision == LCD_VERSION_1) {
341 reg_ras |= LCD_V1_PL_INT_ENA;
342 } else {
343 reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
344 LCD_V2_PL_INT_ENA;
345 lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
346 }
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700347
348 lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
349 lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
350 }
351
352 lcdc_write(reg_dma, LCD_DMA_CTRL_REG);
353 lcdc_write(reg_ras, LCD_RASTER_CTRL_REG);
354
355 /*
356 * The Raster enable bit must be set after all other control fields are
357 * set.
358 */
359 lcd_enable_raster();
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700360}
361
Manjunathappa, Prakashfb8fa942012-07-18 21:03:36 +0530362/* Configure the Burst Size and fifo threhold of DMA */
363static int lcd_cfg_dma(int burst_size, int fifo_th)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700364{
365 u32 reg;
366
367 reg = lcdc_read(LCD_DMA_CTRL_REG) & 0x00000001;
368 switch (burst_size) {
369 case 1:
370 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_1);
371 break;
372 case 2:
373 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_2);
374 break;
375 case 4:
376 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_4);
377 break;
378 case 8:
379 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_8);
380 break;
381 case 16:
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530382 default:
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700383 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_16);
384 break;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700385 }
Manjunathappa, Prakashfb8fa942012-07-18 21:03:36 +0530386
387 reg |= (fifo_th << 8);
388
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700389 lcdc_write(reg, LCD_DMA_CTRL_REG);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700390
391 return 0;
392}
393
394static void lcd_cfg_ac_bias(int period, int transitions_per_int)
395{
396 u32 reg;
397
398 /* Set the AC Bias Period and Number of Transisitons per Interrupt */
399 reg = lcdc_read(LCD_RASTER_TIMING_2_REG) & 0xFFF00000;
400 reg |= LCD_AC_BIAS_FREQUENCY(period) |
401 LCD_AC_BIAS_TRANSITIONS_PER_INT(transitions_per_int);
402 lcdc_write(reg, LCD_RASTER_TIMING_2_REG);
403}
404
405static void lcd_cfg_horizontal_sync(int back_porch, int pulse_width,
406 int front_porch)
407{
408 u32 reg;
409
410 reg = lcdc_read(LCD_RASTER_TIMING_0_REG) & 0xf;
411 reg |= ((back_porch & 0xff) << 24)
412 | ((front_porch & 0xff) << 16)
413 | ((pulse_width & 0x3f) << 10);
414 lcdc_write(reg, LCD_RASTER_TIMING_0_REG);
415}
416
417static void lcd_cfg_vertical_sync(int back_porch, int pulse_width,
418 int front_porch)
419{
420 u32 reg;
421
422 reg = lcdc_read(LCD_RASTER_TIMING_1_REG) & 0x3ff;
423 reg |= ((back_porch & 0xff) << 24)
424 | ((front_porch & 0xff) << 16)
425 | ((pulse_width & 0x3f) << 10);
426 lcdc_write(reg, LCD_RASTER_TIMING_1_REG);
427}
428
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530429static int lcd_cfg_display(const struct lcd_ctrl_config *cfg,
430 struct fb_videomode *panel)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700431{
432 u32 reg;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530433 u32 reg_int;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700434
435 reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(LCD_TFT_MODE |
436 LCD_MONO_8BIT_MODE |
437 LCD_MONOCHROME_MODE);
438
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530439 switch (cfg->panel_shade) {
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700440 case MONOCHROME:
441 reg |= LCD_MONOCHROME_MODE;
442 if (cfg->mono_8bit_mode)
443 reg |= LCD_MONO_8BIT_MODE;
444 break;
445 case COLOR_ACTIVE:
446 reg |= LCD_TFT_MODE;
447 if (cfg->tft_alt_mode)
448 reg |= LCD_TFT_ALT_ENABLE;
449 break;
450
451 case COLOR_PASSIVE:
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530452 /* AC bias applicable only for Pasive panels */
453 lcd_cfg_ac_bias(cfg->ac_bias, cfg->ac_bias_intrpt);
454 if (cfg->bpp == 12 && cfg->stn_565_mode)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700455 reg |= LCD_STN_565_ENABLE;
456 break;
457
458 default:
459 return -EINVAL;
460 }
461
462 /* enable additional interrupts here */
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530463 if (lcd_revision == LCD_VERSION_1) {
464 reg |= LCD_V1_UNDERFLOW_INT_ENA;
465 } else {
466 reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
467 LCD_V2_UNDERFLOW_INT_ENA;
468 lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
469 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700470
471 lcdc_write(reg, LCD_RASTER_CTRL_REG);
472
473 reg = lcdc_read(LCD_RASTER_TIMING_2_REG);
474
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530475 reg |= LCD_SYNC_CTRL;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700476
477 if (cfg->sync_edge)
478 reg |= LCD_SYNC_EDGE;
479 else
480 reg &= ~LCD_SYNC_EDGE;
481
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530482 if (panel->sync & FB_SYNC_HOR_HIGH_ACT)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700483 reg |= LCD_INVERT_LINE_CLOCK;
484 else
485 reg &= ~LCD_INVERT_LINE_CLOCK;
486
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530487 if (panel->sync & FB_SYNC_VERT_HIGH_ACT)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700488 reg |= LCD_INVERT_FRAME_CLOCK;
489 else
490 reg &= ~LCD_INVERT_FRAME_CLOCK;
491
492 lcdc_write(reg, LCD_RASTER_TIMING_2_REG);
493
494 return 0;
495}
496
497static int lcd_cfg_frame_buffer(struct da8xx_fb_par *par, u32 width, u32 height,
498 u32 bpp, u32 raster_order)
499{
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700500 u32 reg;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700501
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530502 if (bpp > 16 && lcd_revision == LCD_VERSION_1)
503 return -EINVAL;
504
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700505 /* Set the Panel Width */
506 /* Pixels per line = (PPL + 1)*16 */
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530507 if (lcd_revision == LCD_VERSION_1) {
508 /*
509 * 0x3F in bits 4..9 gives max horizontal resolution = 1024
510 * pixels.
511 */
512 width &= 0x3f0;
513 } else {
514 /*
515 * 0x7F in bits 4..10 gives max horizontal resolution = 2048
516 * pixels.
517 */
518 width &= 0x7f0;
519 }
520
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700521 reg = lcdc_read(LCD_RASTER_TIMING_0_REG);
522 reg &= 0xfffffc00;
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530523 if (lcd_revision == LCD_VERSION_1) {
524 reg |= ((width >> 4) - 1) << 4;
525 } else {
526 width = (width >> 4) - 1;
527 reg |= ((width & 0x3f) << 4) | ((width & 0x40) >> 3);
528 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700529 lcdc_write(reg, LCD_RASTER_TIMING_0_REG);
530
531 /* Set the Panel Height */
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530532 /* Set bits 9:0 of Lines Per Pixel */
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700533 reg = lcdc_read(LCD_RASTER_TIMING_1_REG);
534 reg = ((height - 1) & 0x3ff) | (reg & 0xfffffc00);
535 lcdc_write(reg, LCD_RASTER_TIMING_1_REG);
536
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530537 /* Set bit 10 of Lines Per Pixel */
538 if (lcd_revision == LCD_VERSION_2) {
539 reg = lcdc_read(LCD_RASTER_TIMING_2_REG);
540 reg |= ((height - 1) & 0x400) << 16;
541 lcdc_write(reg, LCD_RASTER_TIMING_2_REG);
542 }
543
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700544 /* Set the Raster Order of the Frame Buffer */
545 reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(1 << 8);
546 if (raster_order)
547 reg |= LCD_RASTER_ORDER;
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530548
549 par->palette_sz = 16 * 2;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700550
551 switch (bpp) {
552 case 1:
553 case 2:
554 case 4:
555 case 16:
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530556 break;
557 case 24:
558 reg |= LCD_V2_TFT_24BPP_MODE;
Darren Etheridgefa8a00c2013-08-05 17:02:31 -0500559 break;
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530560 case 32:
Darren Etheridgefa8a00c2013-08-05 17:02:31 -0500561 reg |= LCD_V2_TFT_24BPP_MODE;
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530562 reg |= LCD_V2_TFT_24BPP_UNPACK;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700563 break;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700564 case 8:
565 par->palette_sz = 256 * 2;
566 break;
567
568 default:
569 return -EINVAL;
570 }
571
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530572 lcdc_write(reg, LCD_RASTER_CTRL_REG);
573
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700574 return 0;
575}
576
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530577#define CNVT_TOHW(val, width) ((((val) << (width)) + 0x7FFF - (val)) >> 16)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700578static int fb_setcolreg(unsigned regno, unsigned red, unsigned green,
579 unsigned blue, unsigned transp,
580 struct fb_info *info)
581{
582 struct da8xx_fb_par *par = info->par;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700583 unsigned short *palette = (unsigned short *) par->v_palette_base;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700584 u_short pal;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700585 int update_hw = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700586
587 if (regno > 255)
588 return 1;
589
590 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR)
591 return 1;
592
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530593 if (info->var.bits_per_pixel > 16 && lcd_revision == LCD_VERSION_1)
594 return -EINVAL;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100595
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530596 switch (info->fix.visual) {
597 case FB_VISUAL_TRUECOLOR:
598 red = CNVT_TOHW(red, info->var.red.length);
599 green = CNVT_TOHW(green, info->var.green.length);
600 blue = CNVT_TOHW(blue, info->var.blue.length);
601 break;
602 case FB_VISUAL_PSEUDOCOLOR:
603 switch (info->var.bits_per_pixel) {
604 case 4:
605 if (regno > 15)
606 return -EINVAL;
607
608 if (info->var.grayscale) {
609 pal = regno;
610 } else {
611 red >>= 4;
612 green >>= 8;
613 blue >>= 12;
614
615 pal = red & 0x0f00;
616 pal |= green & 0x00f0;
617 pal |= blue & 0x000f;
618 }
619 if (regno == 0)
620 pal |= 0x2000;
621 palette[regno] = pal;
622 break;
623
624 case 8:
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100625 red >>= 4;
626 green >>= 8;
627 blue >>= 12;
628
629 pal = (red & 0x0f00);
630 pal |= (green & 0x00f0);
631 pal |= (blue & 0x000f);
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530632
633 if (palette[regno] != pal) {
634 update_hw = 1;
635 palette[regno] = pal;
636 }
637 break;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100638 }
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530639 break;
640 }
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100641
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530642 /* Truecolor has hardware independent palette */
643 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
644 u32 v;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700645
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530646 if (regno > 15)
647 return -EINVAL;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700648
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530649 v = (red << info->var.red.offset) |
650 (green << info->var.green.offset) |
651 (blue << info->var.blue.offset);
652
653 switch (info->var.bits_per_pixel) {
654 case 16:
655 ((u16 *) (info->pseudo_palette))[regno] = v;
656 break;
657 case 24:
658 case 32:
659 ((u32 *) (info->pseudo_palette))[regno] = v;
660 break;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700661 }
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700662 if (palette[0] != 0x4000) {
663 update_hw = 1;
664 palette[0] = 0x4000;
665 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700666 }
667
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700668 /* Update the palette in the h/w as needed. */
669 if (update_hw)
670 lcd_blit(LOAD_PALETTE, par);
671
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700672 return 0;
673}
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530674#undef CNVT_TOHW
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700675
Afzal Mohammed39c87d42013-08-05 17:02:21 -0500676static void da8xx_fb_lcd_reset(void)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700677{
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700678 /* DMA has to be disabled */
679 lcdc_write(0, LCD_DMA_CTRL_REG);
680 lcdc_write(0, LCD_RASTER_CTRL_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530681
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530682 if (lcd_revision == LCD_VERSION_2) {
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530683 lcdc_write(0, LCD_INT_ENABLE_SET_REG);
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530684 /* Write 1 to reset */
685 lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG);
686 lcdc_write(0, LCD_CLK_RESET_REG);
687 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700688}
689
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500690static int da8xx_fb_config_clk_divider(struct da8xx_fb_par *par,
691 unsigned lcdc_clk_div,
692 unsigned lcdc_clk_rate)
Chaithrika U S8097b172009-12-15 16:46:29 -0800693{
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500694 int ret;
Chaithrika U S8097b172009-12-15 16:46:29 -0800695
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500696 if (par->lcd_fck_rate != lcdc_clk_rate) {
697 ret = clk_set_rate(par->lcdc_clk, lcdc_clk_rate);
698 if (IS_ERR_VALUE(ret)) {
699 dev_err(par->dev,
700 "unable to set clock rate at %u\n",
701 lcdc_clk_rate);
702 return ret;
703 }
704 par->lcd_fck_rate = clk_get_rate(par->lcdc_clk);
705 }
Afzal Mohammed404fdfe2013-08-05 17:02:28 -0500706
Chaithrika U S8097b172009-12-15 16:46:29 -0800707 /* Configure the LCD clock divisor. */
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500708 lcdc_write(LCD_CLK_DIVISOR(lcdc_clk_div) |
Chaithrika U S8097b172009-12-15 16:46:29 -0800709 (LCD_RASTER_MODE & 0x1), LCD_CTRL_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530710
711 if (lcd_revision == LCD_VERSION_2)
712 lcdc_write(LCD_V2_DMA_CLK_EN | LCD_V2_LIDD_CLK_EN |
713 LCD_V2_CORE_CLK_EN, LCD_CLK_ENABLE_REG);
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500714
715 return 0;
Darren Etheridgea6a799f2013-08-05 17:02:26 -0500716}
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530717
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500718static unsigned int da8xx_fb_calc_clk_divider(struct da8xx_fb_par *par,
719 unsigned pixclock,
720 unsigned *lcdc_clk_rate)
Darren Etheridgea6a799f2013-08-05 17:02:26 -0500721{
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500722 unsigned lcdc_clk_div;
Darren Etheridgea6a799f2013-08-05 17:02:26 -0500723
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500724 pixclock = PICOS2KHZ(pixclock) * 1000;
725
726 *lcdc_clk_rate = par->lcd_fck_rate;
727
728 if (pixclock < (*lcdc_clk_rate / CLK_MAX_DIV)) {
729 *lcdc_clk_rate = clk_round_rate(par->lcdc_clk,
730 pixclock * CLK_MAX_DIV);
731 lcdc_clk_div = CLK_MAX_DIV;
732 } else if (pixclock > (*lcdc_clk_rate / CLK_MIN_DIV)) {
733 *lcdc_clk_rate = clk_round_rate(par->lcdc_clk,
734 pixclock * CLK_MIN_DIV);
735 lcdc_clk_div = CLK_MIN_DIV;
736 } else {
737 lcdc_clk_div = *lcdc_clk_rate / pixclock;
738 }
739
740 return lcdc_clk_div;
741}
742
743static int da8xx_fb_calc_config_clk_divider(struct da8xx_fb_par *par,
744 struct fb_videomode *mode)
745{
746 unsigned lcdc_clk_rate;
747 unsigned lcdc_clk_div = da8xx_fb_calc_clk_divider(par, mode->pixclock,
748 &lcdc_clk_rate);
749
750 return da8xx_fb_config_clk_divider(par, lcdc_clk_div, lcdc_clk_rate);
751}
752
753static inline unsigned da8xx_fb_round_clk(struct da8xx_fb_par *par,
754 unsigned pixclock)
755{
756 unsigned lcdc_clk_div, lcdc_clk_rate;
757
758 lcdc_clk_div = da8xx_fb_calc_clk_divider(par, pixclock, &lcdc_clk_rate);
759 return KHZ2PICOS(lcdc_clk_rate / (1000 * lcdc_clk_div));
Chaithrika U S8097b172009-12-15 16:46:29 -0800760}
761
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700762static int lcd_init(struct da8xx_fb_par *par, const struct lcd_ctrl_config *cfg,
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530763 struct fb_videomode *panel)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700764{
765 u32 bpp;
766 int ret = 0;
767
Darren Etheridge2dfa77a2013-08-05 17:02:36 -0500768 ret = da8xx_fb_calc_config_clk_divider(par, panel);
769 if (IS_ERR_VALUE(ret)) {
770 dev_err(par->dev, "unable to configure clock\n");
771 return ret;
772 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700773
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530774 if (panel->sync & FB_SYNC_CLK_INVERT)
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700775 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG) |
776 LCD_INVERT_PIXEL_CLOCK), LCD_RASTER_TIMING_2_REG);
777 else
778 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG) &
779 ~LCD_INVERT_PIXEL_CLOCK), LCD_RASTER_TIMING_2_REG);
780
Manjunathappa, Prakashfb8fa942012-07-18 21:03:36 +0530781 /* Configure the DMA burst size and fifo threshold. */
782 ret = lcd_cfg_dma(cfg->dma_burst_sz, cfg->fifo_th);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700783 if (ret < 0)
784 return ret;
785
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700786 /* Configure the vertical and horizontal sync properties. */
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530787 lcd_cfg_vertical_sync(panel->lower_margin, panel->vsync_len,
788 panel->upper_margin);
789 lcd_cfg_horizontal_sync(panel->right_margin, panel->hsync_len,
790 panel->left_margin);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700791
792 /* Configure for disply */
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530793 ret = lcd_cfg_display(cfg, panel);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700794 if (ret < 0)
795 return ret;
796
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +0530797 bpp = cfg->bpp;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700798
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700799 if (bpp == 12)
800 bpp = 16;
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +0530801 ret = lcd_cfg_frame_buffer(par, (unsigned int)panel->xres,
802 (unsigned int)panel->yres, bpp,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700803 cfg->raster_order);
804 if (ret < 0)
805 return ret;
806
807 /* Configure FDD */
808 lcdc_write((lcdc_read(LCD_RASTER_CTRL_REG) & 0xfff00fff) |
809 (cfg->fdd << 12), LCD_RASTER_CTRL_REG);
810
811 return 0;
812}
813
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530814/* IRQ handler for version 2 of LCDC */
815static irqreturn_t lcdc_irq_handler_rev02(int irq, void *arg)
816{
817 struct da8xx_fb_par *par = arg;
818 u32 stat = lcdc_read(LCD_MASKED_STAT_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530819
820 if ((stat & LCD_SYNC_LOST) && (stat & LCD_FIFO_UNDERFLOW)) {
Darren Etheridge26e71642013-08-05 17:02:30 -0500821 lcd_disable_raster(DA8XX_FRAME_NOWAIT);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530822 lcdc_write(stat, LCD_MASKED_STAT_REG);
823 lcd_enable_raster();
824 } else if (stat & LCD_PL_LOAD_DONE) {
825 /*
826 * Must disable raster before changing state of any control bit.
827 * And also must be disabled before clearing the PL loading
828 * interrupt via the following write to the status register. If
829 * this is done after then one gets multiple PL done interrupts.
830 */
Darren Etheridge26e71642013-08-05 17:02:30 -0500831 lcd_disable_raster(DA8XX_FRAME_NOWAIT);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530832
833 lcdc_write(stat, LCD_MASKED_STAT_REG);
834
Manjunathappa, Prakash8a81dcc2012-07-18 20:51:11 +0530835 /* Disable PL completion interrupt */
836 lcdc_write(LCD_V2_PL_INT_ENA, LCD_INT_ENABLE_CLR_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530837
838 /* Setup and start data loading mode */
839 lcd_blit(LOAD_DATA, par);
840 } else {
841 lcdc_write(stat, LCD_MASKED_STAT_REG);
842
843 if (stat & LCD_END_OF_FRAME0) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530844 par->which_dma_channel_done = 0;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530845 lcdc_write(par->dma_start,
846 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
847 lcdc_write(par->dma_end,
848 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
849 par->vsync_flag = 1;
850 wake_up_interruptible(&par->vsync_wait);
851 }
852
853 if (stat & LCD_END_OF_FRAME1) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530854 par->which_dma_channel_done = 1;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530855 lcdc_write(par->dma_start,
856 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
857 lcdc_write(par->dma_end,
858 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
859 par->vsync_flag = 1;
860 wake_up_interruptible(&par->vsync_wait);
861 }
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +0530862
863 /* Set only when controller is disabled and at the end of
864 * active frame
865 */
866 if (stat & BIT(0)) {
867 frame_done_flag = 1;
868 wake_up_interruptible(&frame_done_wq);
869 }
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530870 }
871
872 lcdc_write(0, LCD_END_OF_INT_IND_REG);
873 return IRQ_HANDLED;
874}
875
876/* IRQ handler for version 1 LCDC */
877static irqreturn_t lcdc_irq_handler_rev01(int irq, void *arg)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700878{
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700879 struct da8xx_fb_par *par = arg;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700880 u32 stat = lcdc_read(LCD_STAT_REG);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700881 u32 reg_ras;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700882
883 if ((stat & LCD_SYNC_LOST) && (stat & LCD_FIFO_UNDERFLOW)) {
Darren Etheridge26e71642013-08-05 17:02:30 -0500884 lcd_disable_raster(DA8XX_FRAME_NOWAIT);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700885 lcdc_write(stat, LCD_STAT_REG);
Chaithrika U S36113802009-12-15 16:46:38 -0800886 lcd_enable_raster();
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700887 } else if (stat & LCD_PL_LOAD_DONE) {
888 /*
889 * Must disable raster before changing state of any control bit.
890 * And also must be disabled before clearing the PL loading
891 * interrupt via the following write to the status register. If
892 * this is done after then one gets multiple PL done interrupts.
893 */
Darren Etheridge26e71642013-08-05 17:02:30 -0500894 lcd_disable_raster(DA8XX_FRAME_NOWAIT);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700895
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700896 lcdc_write(stat, LCD_STAT_REG);
897
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700898 /* Disable PL completion inerrupt */
899 reg_ras = lcdc_read(LCD_RASTER_CTRL_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530900 reg_ras &= ~LCD_V1_PL_INT_ENA;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700901 lcdc_write(reg_ras, LCD_RASTER_CTRL_REG);
902
903 /* Setup and start data loading mode */
904 lcd_blit(LOAD_DATA, par);
905 } else {
906 lcdc_write(stat, LCD_STAT_REG);
907
908 if (stat & LCD_END_OF_FRAME0) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530909 par->which_dma_channel_done = 0;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700910 lcdc_write(par->dma_start,
911 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
912 lcdc_write(par->dma_end,
913 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
914 par->vsync_flag = 1;
915 wake_up_interruptible(&par->vsync_wait);
916 }
917
918 if (stat & LCD_END_OF_FRAME1) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530919 par->which_dma_channel_done = 1;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700920 lcdc_write(par->dma_start,
921 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
922 lcdc_write(par->dma_end,
923 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
924 par->vsync_flag = 1;
925 wake_up_interruptible(&par->vsync_wait);
926 }
927 }
928
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700929 return IRQ_HANDLED;
930}
931
932static int fb_check_var(struct fb_var_screeninfo *var,
933 struct fb_info *info)
934{
935 int err = 0;
Afzal Mohammed87dac712013-08-05 17:02:20 -0500936 struct da8xx_fb_par *par = info->par;
937 int bpp = var->bits_per_pixel >> 3;
938 unsigned long line_size = var->xres_virtual * bpp;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700939
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530940 if (var->bits_per_pixel > 16 && lcd_revision == LCD_VERSION_1)
941 return -EINVAL;
942
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700943 switch (var->bits_per_pixel) {
944 case 1:
945 case 8:
946 var->red.offset = 0;
947 var->red.length = 8;
948 var->green.offset = 0;
949 var->green.length = 8;
950 var->blue.offset = 0;
951 var->blue.length = 8;
952 var->transp.offset = 0;
953 var->transp.length = 0;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100954 var->nonstd = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700955 break;
956 case 4:
957 var->red.offset = 0;
958 var->red.length = 4;
959 var->green.offset = 0;
960 var->green.length = 4;
961 var->blue.offset = 0;
962 var->blue.length = 4;
963 var->transp.offset = 0;
964 var->transp.length = 0;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100965 var->nonstd = FB_NONSTD_REV_PIX_IN_B;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700966 break;
967 case 16: /* RGB 565 */
Sudhakar Rajashekhara3510b8f2009-12-01 13:17:43 -0800968 var->red.offset = 11;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700969 var->red.length = 5;
970 var->green.offset = 5;
971 var->green.length = 6;
Sudhakar Rajashekhara3510b8f2009-12-01 13:17:43 -0800972 var->blue.offset = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700973 var->blue.length = 5;
974 var->transp.offset = 0;
975 var->transp.length = 0;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100976 var->nonstd = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700977 break;
Manjunathappa, Prakash1a2b7502012-08-14 18:51:42 +0530978 case 24:
979 var->red.offset = 16;
980 var->red.length = 8;
981 var->green.offset = 8;
982 var->green.length = 8;
983 var->blue.offset = 0;
984 var->blue.length = 8;
985 var->nonstd = 0;
986 break;
987 case 32:
988 var->transp.offset = 24;
989 var->transp.length = 8;
990 var->red.offset = 16;
991 var->red.length = 8;
992 var->green.offset = 8;
993 var->green.length = 8;
994 var->blue.offset = 0;
995 var->blue.length = 8;
996 var->nonstd = 0;
997 break;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700998 default:
999 err = -EINVAL;
1000 }
1001
1002 var->red.msb_right = 0;
1003 var->green.msb_right = 0;
1004 var->blue.msb_right = 0;
1005 var->transp.msb_right = 0;
Afzal Mohammed87dac712013-08-05 17:02:20 -05001006
1007 if (line_size * var->yres_virtual > par->vram_size)
1008 var->yres_virtual = par->vram_size / line_size;
1009
1010 if (var->yres > var->yres_virtual)
1011 var->yres = var->yres_virtual;
1012
1013 if (var->xres > var->xres_virtual)
1014 var->xres = var->xres_virtual;
1015
1016 if (var->xres + var->xoffset > var->xres_virtual)
1017 var->xoffset = var->xres_virtual - var->xres;
1018 if (var->yres + var->yoffset > var->yres_virtual)
1019 var->yoffset = var->yres_virtual - var->yres;
1020
Afzal Mohammed404fdfe2013-08-05 17:02:28 -05001021 var->pixclock = da8xx_fb_round_clk(par, var->pixclock);
1022
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001023 return err;
1024}
1025
Chaithrika U Se04e5482009-12-15 16:46:29 -08001026#ifdef CONFIG_CPU_FREQ
1027static int lcd_da8xx_cpufreq_transition(struct notifier_block *nb,
1028 unsigned long val, void *data)
1029{
1030 struct da8xx_fb_par *par;
Chaithrika U Se04e5482009-12-15 16:46:29 -08001031
1032 par = container_of(nb, struct da8xx_fb_par, freq_transition);
Manjunathappa, Prakashf8209172012-01-03 18:10:51 +05301033 if (val == CPUFREQ_POSTCHANGE) {
1034 if (par->lcd_fck_rate != clk_get_rate(par->lcdc_clk)) {
1035 par->lcd_fck_rate = clk_get_rate(par->lcdc_clk);
Darren Etheridge26e71642013-08-05 17:02:30 -05001036 lcd_disable_raster(DA8XX_FRAME_WAIT);
Darren Etheridgea6a799f2013-08-05 17:02:26 -05001037 da8xx_fb_calc_config_clk_divider(par, &par->mode);
Manjunathappa, Prakash67900812012-08-31 19:48:59 +05301038 if (par->blank == FB_BLANK_UNBLANK)
1039 lcd_enable_raster();
Manjunathappa, Prakashf8209172012-01-03 18:10:51 +05301040 }
Chaithrika U Se04e5482009-12-15 16:46:29 -08001041 }
1042
1043 return 0;
1044}
1045
1046static inline int lcd_da8xx_cpufreq_register(struct da8xx_fb_par *par)
1047{
1048 par->freq_transition.notifier_call = lcd_da8xx_cpufreq_transition;
1049
1050 return cpufreq_register_notifier(&par->freq_transition,
1051 CPUFREQ_TRANSITION_NOTIFIER);
1052}
1053
1054static inline void lcd_da8xx_cpufreq_deregister(struct da8xx_fb_par *par)
1055{
1056 cpufreq_unregister_notifier(&par->freq_transition,
1057 CPUFREQ_TRANSITION_NOTIFIER);
1058}
1059#endif
1060
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001061static int fb_remove(struct platform_device *dev)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001062{
1063 struct fb_info *info = dev_get_drvdata(&dev->dev);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001064
1065 if (info) {
1066 struct da8xx_fb_par *par = info->par;
1067
Chaithrika U Se04e5482009-12-15 16:46:29 -08001068#ifdef CONFIG_CPU_FREQ
1069 lcd_da8xx_cpufreq_deregister(par);
1070#endif
Chaithrika U S36113802009-12-15 16:46:38 -08001071 if (par->panel_power_ctrl)
1072 par->panel_power_ctrl(0);
1073
Darren Etheridge26e71642013-08-05 17:02:30 -05001074 lcd_disable_raster(DA8XX_FRAME_WAIT);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001075 lcdc_write(0, LCD_RASTER_CTRL_REG);
1076
1077 /* disable DMA */
1078 lcdc_write(0, LCD_DMA_CTRL_REG);
1079
1080 unregister_framebuffer(info);
1081 fb_dealloc_cmap(&info->cmap);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001082 dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base,
1083 par->p_palette_base);
1084 dma_free_coherent(NULL, par->vram_size, par->vram_virt,
1085 par->vram_phys);
Manjunathappa, Prakash9dd44d52012-09-21 21:20:57 +05301086 pm_runtime_put_sync(&dev->dev);
1087 pm_runtime_disable(&dev->dev);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001088 framebuffer_release(info);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001089
1090 }
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -07001091 return 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001092}
1093
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001094/*
1095 * Function to wait for vertical sync which for this LCD peripheral
1096 * translates into waiting for the current raster frame to complete.
1097 */
1098static int fb_wait_for_vsync(struct fb_info *info)
1099{
1100 struct da8xx_fb_par *par = info->par;
1101 int ret;
1102
1103 /*
1104 * Set flag to 0 and wait for isr to set to 1. It would seem there is a
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001105 * race condition here where the ISR could have occurred just before or
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001106 * just after this set. But since we are just coarsely waiting for
1107 * a frame to complete then that's OK. i.e. if the frame completed
1108 * just before this code executed then we have to wait another full
1109 * frame time but there is no way to avoid such a situation. On the
1110 * other hand if the frame completed just after then we don't need
1111 * to wait long at all. Either way we are guaranteed to return to the
1112 * user immediately after a frame completion which is all that is
1113 * required.
1114 */
1115 par->vsync_flag = 0;
1116 ret = wait_event_interruptible_timeout(par->vsync_wait,
1117 par->vsync_flag != 0,
1118 par->vsync_timeout);
1119 if (ret < 0)
1120 return ret;
1121 if (ret == 0)
1122 return -ETIMEDOUT;
1123
1124 return 0;
1125}
1126
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001127static int fb_ioctl(struct fb_info *info, unsigned int cmd,
1128 unsigned long arg)
1129{
1130 struct lcd_sync_arg sync_arg;
1131
1132 switch (cmd) {
1133 case FBIOGET_CONTRAST:
1134 case FBIOPUT_CONTRAST:
1135 case FBIGET_BRIGHTNESS:
1136 case FBIPUT_BRIGHTNESS:
1137 case FBIGET_COLOR:
1138 case FBIPUT_COLOR:
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -07001139 return -ENOTTY;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001140 case FBIPUT_HSYNC:
1141 if (copy_from_user(&sync_arg, (char *)arg,
1142 sizeof(struct lcd_sync_arg)))
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -07001143 return -EFAULT;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001144 lcd_cfg_horizontal_sync(sync_arg.back_porch,
1145 sync_arg.pulse_width,
1146 sync_arg.front_porch);
1147 break;
1148 case FBIPUT_VSYNC:
1149 if (copy_from_user(&sync_arg, (char *)arg,
1150 sizeof(struct lcd_sync_arg)))
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -07001151 return -EFAULT;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001152 lcd_cfg_vertical_sync(sync_arg.back_porch,
1153 sync_arg.pulse_width,
1154 sync_arg.front_porch);
1155 break;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001156 case FBIO_WAITFORVSYNC:
1157 return fb_wait_for_vsync(info);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001158 default:
1159 return -EINVAL;
1160 }
1161 return 0;
1162}
1163
Chaithrika U S312d9712009-12-15 16:46:39 -08001164static int cfb_blank(int blank, struct fb_info *info)
1165{
1166 struct da8xx_fb_par *par = info->par;
1167 int ret = 0;
1168
1169 if (par->blank == blank)
1170 return 0;
1171
1172 par->blank = blank;
1173 switch (blank) {
1174 case FB_BLANK_UNBLANK:
Manjunathappa, Prakashf7c848b2012-07-24 09:45:25 +05301175 lcd_enable_raster();
1176
Chaithrika U S312d9712009-12-15 16:46:39 -08001177 if (par->panel_power_ctrl)
1178 par->panel_power_ctrl(1);
Chaithrika U S312d9712009-12-15 16:46:39 -08001179 break;
Yegor Yefremov99a647d2012-07-06 16:01:28 +02001180 case FB_BLANK_NORMAL:
1181 case FB_BLANK_VSYNC_SUSPEND:
1182 case FB_BLANK_HSYNC_SUSPEND:
Chaithrika U S312d9712009-12-15 16:46:39 -08001183 case FB_BLANK_POWERDOWN:
1184 if (par->panel_power_ctrl)
1185 par->panel_power_ctrl(0);
1186
Darren Etheridge26e71642013-08-05 17:02:30 -05001187 lcd_disable_raster(DA8XX_FRAME_WAIT);
Chaithrika U S312d9712009-12-15 16:46:39 -08001188 break;
1189 default:
1190 ret = -EINVAL;
1191 }
1192
1193 return ret;
1194}
1195
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001196/*
1197 * Set new x,y offsets in the virtual display for the visible area and switch
1198 * to the new mode.
1199 */
1200static int da8xx_pan_display(struct fb_var_screeninfo *var,
1201 struct fb_info *fbi)
1202{
1203 int ret = 0;
1204 struct fb_var_screeninfo new_var;
1205 struct da8xx_fb_par *par = fbi->par;
1206 struct fb_fix_screeninfo *fix = &fbi->fix;
1207 unsigned int end;
1208 unsigned int start;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +05301209 unsigned long irq_flags;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001210
1211 if (var->xoffset != fbi->var.xoffset ||
1212 var->yoffset != fbi->var.yoffset) {
1213 memcpy(&new_var, &fbi->var, sizeof(new_var));
1214 new_var.xoffset = var->xoffset;
1215 new_var.yoffset = var->yoffset;
1216 if (fb_check_var(&new_var, fbi))
1217 ret = -EINVAL;
1218 else {
1219 memcpy(&fbi->var, &new_var, sizeof(new_var));
1220
1221 start = fix->smem_start +
1222 new_var.yoffset * fix->line_length +
Laurent Pincharte6c4d3d2011-06-14 09:24:45 +00001223 new_var.xoffset * fbi->var.bits_per_pixel / 8;
1224 end = start + fbi->var.yres * fix->line_length - 1;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001225 par->dma_start = start;
1226 par->dma_end = end;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +05301227 spin_lock_irqsave(&par->lock_for_chan_update,
1228 irq_flags);
1229 if (par->which_dma_channel_done == 0) {
1230 lcdc_write(par->dma_start,
1231 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
1232 lcdc_write(par->dma_end,
1233 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
1234 } else if (par->which_dma_channel_done == 1) {
1235 lcdc_write(par->dma_start,
1236 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
1237 lcdc_write(par->dma_end,
1238 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
1239 }
1240 spin_unlock_irqrestore(&par->lock_for_chan_update,
1241 irq_flags);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001242 }
1243 }
1244
1245 return ret;
1246}
1247
Darren Etheridgefe8c98f2013-08-05 17:02:29 -05001248static int da8xxfb_set_par(struct fb_info *info)
1249{
1250 struct da8xx_fb_par *par = info->par;
1251 int ret;
1252 bool raster = da8xx_fb_is_raster_enabled();
1253
1254 if (raster)
Darren Etheridge26e71642013-08-05 17:02:30 -05001255 lcd_disable_raster(DA8XX_FRAME_WAIT);
Darren Etheridgefe8c98f2013-08-05 17:02:29 -05001256
1257 fb_var_to_videomode(&par->mode, &info->var);
1258
1259 par->cfg.bpp = info->var.bits_per_pixel;
1260
1261 info->fix.visual = (par->cfg.bpp <= 8) ?
1262 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
1263 info->fix.line_length = (par->mode.xres * par->cfg.bpp) / 8;
1264
1265 ret = lcd_init(par, &par->cfg, &par->mode);
1266 if (ret < 0) {
1267 dev_err(par->dev, "lcd init failed\n");
1268 return ret;
1269 }
1270
1271 par->dma_start = info->fix.smem_start +
1272 info->var.yoffset * info->fix.line_length +
1273 info->var.xoffset * info->var.bits_per_pixel / 8;
1274 par->dma_end = par->dma_start +
1275 info->var.yres * info->fix.line_length - 1;
1276
1277 lcdc_write(par->dma_start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
1278 lcdc_write(par->dma_end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
1279 lcdc_write(par->dma_start, LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
1280 lcdc_write(par->dma_end, LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
1281
1282 if (raster)
1283 lcd_enable_raster();
1284
1285 return 0;
1286}
1287
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001288static struct fb_ops da8xx_fb_ops = {
1289 .owner = THIS_MODULE,
1290 .fb_check_var = fb_check_var,
Darren Etheridgefe8c98f2013-08-05 17:02:29 -05001291 .fb_set_par = da8xxfb_set_par,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001292 .fb_setcolreg = fb_setcolreg,
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001293 .fb_pan_display = da8xx_pan_display,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001294 .fb_ioctl = fb_ioctl,
1295 .fb_fillrect = cfb_fillrect,
1296 .fb_copyarea = cfb_copyarea,
1297 .fb_imageblit = cfb_imageblit,
Chaithrika U S312d9712009-12-15 16:46:39 -08001298 .fb_blank = cfb_blank,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001299};
1300
Afzal Mohammed2bdff062013-08-05 17:02:35 -05001301static struct fb_videomode *da8xx_fb_get_videomode(struct platform_device *dev)
1302{
1303 struct da8xx_lcdc_platform_data *fb_pdata = dev->dev.platform_data;
1304 struct fb_videomode *lcdc_info;
1305 int i;
1306
1307 for (i = 0, lcdc_info = known_lcd_panels;
1308 i < ARRAY_SIZE(known_lcd_panels); i++, lcdc_info++) {
1309 if (strcmp(fb_pdata->type, lcdc_info->name) == 0)
1310 break;
1311 }
1312
1313 if (i == ARRAY_SIZE(known_lcd_panels)) {
1314 dev_err(&dev->dev, "no panel found\n");
1315 return NULL;
1316 }
1317 dev_info(&dev->dev, "found %s panel\n", lcdc_info->name);
1318
1319 return lcdc_info;
1320}
1321
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001322static int fb_probe(struct platform_device *device)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001323{
1324 struct da8xx_lcdc_platform_data *fb_pdata =
1325 device->dev.platform_data;
Darren Etheridgec45757f2013-08-05 17:02:33 -05001326 static struct resource *lcdc_regs;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001327 struct lcd_ctrl_config *lcd_cfg;
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +05301328 struct fb_videomode *lcdc_info;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001329 struct fb_info *da8xx_fb_info;
1330 struct clk *fb_clk = NULL;
1331 struct da8xx_fb_par *par;
Afzal Mohammed2bdff062013-08-05 17:02:35 -05001332 int ret;
Aditya Nellutla3b9cc4e2012-05-23 11:36:31 +05301333 unsigned long ulcm;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001334
1335 if (fb_pdata == NULL) {
1336 dev_err(&device->dev, "Can not get platform data\n");
1337 return -ENOENT;
1338 }
1339
Afzal Mohammed2bdff062013-08-05 17:02:35 -05001340 lcdc_info = da8xx_fb_get_videomode(device);
1341 if (lcdc_info == NULL)
1342 return -ENODEV;
1343
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001344 lcdc_regs = platform_get_resource(device, IORESOURCE_MEM, 0);
Darren Etheridgec45757f2013-08-05 17:02:33 -05001345 da8xx_fb_reg_base = devm_ioremap_resource(&device->dev, lcdc_regs);
1346 if (IS_ERR(da8xx_fb_reg_base))
1347 return PTR_ERR(da8xx_fb_reg_base);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001348
Darren Etheridgec45757f2013-08-05 17:02:33 -05001349 fb_clk = devm_clk_get(&device->dev, "fck");
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001350 if (IS_ERR(fb_clk)) {
1351 dev_err(&device->dev, "Can not get device clock\n");
Darren Etheridgec45757f2013-08-05 17:02:33 -05001352 return PTR_ERR(fb_clk);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001353 }
Manjunathappa, Prakash9dd44d52012-09-21 21:20:57 +05301354
1355 pm_runtime_enable(&device->dev);
1356 pm_runtime_get_sync(&device->dev);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001357
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +05301358 /* Determine LCD IP Version */
1359 switch (lcdc_read(LCD_PID_REG)) {
1360 case 0x4C100102:
1361 lcd_revision = LCD_VERSION_1;
1362 break;
1363 case 0x4F200800:
Pantelis Antoniou8f22e8e2012-10-31 17:56:24 +02001364 case 0x4F201000:
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +05301365 lcd_revision = LCD_VERSION_2;
1366 break;
1367 default:
1368 dev_warn(&device->dev, "Unknown PID Reg value 0x%x, "
1369 "defaulting to LCD revision 1\n",
1370 lcdc_read(LCD_PID_REG));
1371 lcd_revision = LCD_VERSION_1;
1372 break;
1373 }
1374
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001375 lcd_cfg = (struct lcd_ctrl_config *)fb_pdata->controller_data;
1376
Afzal Mohammed3a581012013-08-05 17:02:34 -05001377 if (!lcd_cfg) {
1378 ret = -EINVAL;
1379 goto err_pm_runtime_disable;
1380 }
1381
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001382 da8xx_fb_info = framebuffer_alloc(sizeof(struct da8xx_fb_par),
1383 &device->dev);
1384 if (!da8xx_fb_info) {
1385 dev_dbg(&device->dev, "Memory allocation failed for fb_info\n");
1386 ret = -ENOMEM;
Manjunathappa, Prakash9dd44d52012-09-21 21:20:57 +05301387 goto err_pm_runtime_disable;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001388 }
1389
1390 par = da8xx_fb_info->par;
Afzal Mohammeddbe8e482013-08-05 17:02:27 -05001391 par->dev = &device->dev;
Chaithrika U S8097b172009-12-15 16:46:29 -08001392 par->lcdc_clk = fb_clk;
Manjunathappa, Prakashf8209172012-01-03 18:10:51 +05301393 par->lcd_fck_rate = clk_get_rate(fb_clk);
Chaithrika U S36113802009-12-15 16:46:38 -08001394 if (fb_pdata->panel_power_ctrl) {
1395 par->panel_power_ctrl = fb_pdata->panel_power_ctrl;
1396 par->panel_power_ctrl(1);
1397 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001398
Afzal Mohammedb8664582013-08-05 17:02:22 -05001399 fb_videomode_to_var(&da8xx_fb_var, lcdc_info);
Afzal Mohammedb6dbe8e2013-08-05 17:02:24 -05001400 par->cfg = *lcd_cfg;
Afzal Mohammedb8664582013-08-05 17:02:22 -05001401
Darren Etheridgefe8c98f2013-08-05 17:02:29 -05001402 da8xx_fb_lcd_reset();
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001403
1404 /* allocate frame buffer */
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +05301405 par->vram_size = lcdc_info->xres * lcdc_info->yres * lcd_cfg->bpp;
1406 ulcm = lcm((lcdc_info->xres * lcd_cfg->bpp)/8, PAGE_SIZE);
Aditya Nellutla3b9cc4e2012-05-23 11:36:31 +05301407 par->vram_size = roundup(par->vram_size/8, ulcm);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001408 par->vram_size = par->vram_size * LCD_NUM_BUFFERS;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001409
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001410 par->vram_virt = dma_alloc_coherent(NULL,
1411 par->vram_size,
1412 (resource_size_t *) &par->vram_phys,
1413 GFP_KERNEL | GFP_DMA);
1414 if (!par->vram_virt) {
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001415 dev_err(&device->dev,
1416 "GLCD: kmalloc for frame buffer failed\n");
1417 ret = -EINVAL;
1418 goto err_release_fb;
1419 }
1420
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001421 da8xx_fb_info->screen_base = (char __iomem *) par->vram_virt;
1422 da8xx_fb_fix.smem_start = par->vram_phys;
1423 da8xx_fb_fix.smem_len = par->vram_size;
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +05301424 da8xx_fb_fix.line_length = (lcdc_info->xres * lcd_cfg->bpp) / 8;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001425
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001426 par->dma_start = par->vram_phys;
Manjunathappa, Prakashf772fab2012-10-16 10:23:15 +05301427 par->dma_end = par->dma_start + lcdc_info->yres *
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001428 da8xx_fb_fix.line_length - 1;
1429
1430 /* allocate palette buffer */
1431 par->v_palette_base = dma_alloc_coherent(NULL,
1432 PALETTE_SIZE,
1433 (resource_size_t *)
1434 &par->p_palette_base,
1435 GFP_KERNEL | GFP_DMA);
1436 if (!par->v_palette_base) {
1437 dev_err(&device->dev,
1438 "GLCD: kmalloc for palette buffer failed\n");
1439 ret = -EINVAL;
1440 goto err_release_fb_mem;
1441 }
1442 memset(par->v_palette_base, 0, PALETTE_SIZE);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001443
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001444 par->irq = platform_get_irq(device, 0);
1445 if (par->irq < 0) {
1446 ret = -ENOENT;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001447 goto err_release_pl_mem;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001448 }
1449
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001450 da8xx_fb_var.grayscale =
Manjunathappa, Prakash3b43ad22012-10-16 10:23:16 +05301451 lcd_cfg->panel_shade == MONOCHROME ? 1 : 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001452 da8xx_fb_var.bits_per_pixel = lcd_cfg->bpp;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001453
1454 /* Initialize fbinfo */
1455 da8xx_fb_info->flags = FBINFO_FLAG_DEFAULT;
1456 da8xx_fb_info->fix = da8xx_fb_fix;
1457 da8xx_fb_info->var = da8xx_fb_var;
1458 da8xx_fb_info->fbops = &da8xx_fb_ops;
1459 da8xx_fb_info->pseudo_palette = par->pseudo_palette;
Sudhakar Rajashekhara3510b8f2009-12-01 13:17:43 -08001460 da8xx_fb_info->fix.visual = (da8xx_fb_info->var.bits_per_pixel <= 8) ?
1461 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001462
1463 ret = fb_alloc_cmap(&da8xx_fb_info->cmap, PALETTE_SIZE, 0);
1464 if (ret)
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001465 goto err_release_pl_mem;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001466 da8xx_fb_info->cmap.len = par->palette_sz;
1467
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001468 /* initialize var_screeninfo */
1469 da8xx_fb_var.activate = FB_ACTIVATE_FORCE;
1470 fb_set_var(da8xx_fb_info, &da8xx_fb_var);
1471
1472 dev_set_drvdata(&device->dev, da8xx_fb_info);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001473
1474 /* initialize the vsync wait queue */
1475 init_waitqueue_head(&par->vsync_wait);
1476 par->vsync_timeout = HZ / 5;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +05301477 par->which_dma_channel_done = -1;
1478 spin_lock_init(&par->lock_for_chan_update);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001479
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001480 /* Register the Frame Buffer */
1481 if (register_framebuffer(da8xx_fb_info) < 0) {
1482 dev_err(&device->dev,
1483 "GLCD: Frame Buffer Registration Failed!\n");
1484 ret = -EINVAL;
1485 goto err_dealloc_cmap;
1486 }
1487
Chaithrika U Se04e5482009-12-15 16:46:29 -08001488#ifdef CONFIG_CPU_FREQ
1489 ret = lcd_da8xx_cpufreq_register(par);
1490 if (ret) {
1491 dev_err(&device->dev, "failed to register cpufreq\n");
1492 goto err_cpu_freq;
1493 }
1494#endif
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001495
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +05301496 if (lcd_revision == LCD_VERSION_1)
1497 lcdc_irq_handler = lcdc_irq_handler_rev01;
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +05301498 else {
1499 init_waitqueue_head(&frame_done_wq);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +05301500 lcdc_irq_handler = lcdc_irq_handler_rev02;
Manjunathappa, Prakasha481b372012-08-24 18:43:00 +05301501 }
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +05301502
Darren Etheridgec45757f2013-08-05 17:02:33 -05001503 ret = devm_request_irq(&device->dev, par->irq, lcdc_irq_handler, 0,
1504 DRIVER_NAME, par);
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001505 if (ret)
1506 goto irq_freq;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001507 return 0;
1508
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001509irq_freq:
Chaithrika U Se04e5482009-12-15 16:46:29 -08001510#ifdef CONFIG_CPU_FREQ
axel lin360c2022011-01-20 03:50:51 +00001511 lcd_da8xx_cpufreq_deregister(par);
Chaithrika U Se04e5482009-12-15 16:46:29 -08001512err_cpu_freq:
Manjunathappa, Prakash3a844092012-02-09 10:34:38 +05301513#endif
Chaithrika U Se04e5482009-12-15 16:46:29 -08001514 unregister_framebuffer(da8xx_fb_info);
Chaithrika U Se04e5482009-12-15 16:46:29 -08001515
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001516err_dealloc_cmap:
1517 fb_dealloc_cmap(&da8xx_fb_info->cmap);
1518
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001519err_release_pl_mem:
1520 dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base,
1521 par->p_palette_base);
1522
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001523err_release_fb_mem:
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001524 dma_free_coherent(NULL, par->vram_size, par->vram_virt, par->vram_phys);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001525
1526err_release_fb:
1527 framebuffer_release(da8xx_fb_info);
1528
Manjunathappa, Prakash9dd44d52012-09-21 21:20:57 +05301529err_pm_runtime_disable:
1530 pm_runtime_put_sync(&device->dev);
1531 pm_runtime_disable(&device->dev);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001532
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001533 return ret;
1534}
1535
1536#ifdef CONFIG_PM
Manjunathappa, Prakash7a93cbb2012-09-25 19:41:41 +05301537struct lcdc_context {
1538 u32 clk_enable;
1539 u32 ctrl;
1540 u32 dma_ctrl;
1541 u32 raster_timing_0;
1542 u32 raster_timing_1;
1543 u32 raster_timing_2;
1544 u32 int_enable_set;
1545 u32 dma_frm_buf_base_addr_0;
1546 u32 dma_frm_buf_ceiling_addr_0;
1547 u32 dma_frm_buf_base_addr_1;
1548 u32 dma_frm_buf_ceiling_addr_1;
1549 u32 raster_ctrl;
1550} reg_context;
1551
1552static void lcd_context_save(void)
1553{
1554 if (lcd_revision == LCD_VERSION_2) {
1555 reg_context.clk_enable = lcdc_read(LCD_CLK_ENABLE_REG);
1556 reg_context.int_enable_set = lcdc_read(LCD_INT_ENABLE_SET_REG);
1557 }
1558
1559 reg_context.ctrl = lcdc_read(LCD_CTRL_REG);
1560 reg_context.dma_ctrl = lcdc_read(LCD_DMA_CTRL_REG);
1561 reg_context.raster_timing_0 = lcdc_read(LCD_RASTER_TIMING_0_REG);
1562 reg_context.raster_timing_1 = lcdc_read(LCD_RASTER_TIMING_1_REG);
1563 reg_context.raster_timing_2 = lcdc_read(LCD_RASTER_TIMING_2_REG);
1564 reg_context.dma_frm_buf_base_addr_0 =
1565 lcdc_read(LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
1566 reg_context.dma_frm_buf_ceiling_addr_0 =
1567 lcdc_read(LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
1568 reg_context.dma_frm_buf_base_addr_1 =
1569 lcdc_read(LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
1570 reg_context.dma_frm_buf_ceiling_addr_1 =
1571 lcdc_read(LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
1572 reg_context.raster_ctrl = lcdc_read(LCD_RASTER_CTRL_REG);
1573 return;
1574}
1575
1576static void lcd_context_restore(void)
1577{
1578 if (lcd_revision == LCD_VERSION_2) {
1579 lcdc_write(reg_context.clk_enable, LCD_CLK_ENABLE_REG);
1580 lcdc_write(reg_context.int_enable_set, LCD_INT_ENABLE_SET_REG);
1581 }
1582
1583 lcdc_write(reg_context.ctrl, LCD_CTRL_REG);
1584 lcdc_write(reg_context.dma_ctrl, LCD_DMA_CTRL_REG);
1585 lcdc_write(reg_context.raster_timing_0, LCD_RASTER_TIMING_0_REG);
1586 lcdc_write(reg_context.raster_timing_1, LCD_RASTER_TIMING_1_REG);
1587 lcdc_write(reg_context.raster_timing_2, LCD_RASTER_TIMING_2_REG);
1588 lcdc_write(reg_context.dma_frm_buf_base_addr_0,
1589 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
1590 lcdc_write(reg_context.dma_frm_buf_ceiling_addr_0,
1591 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
1592 lcdc_write(reg_context.dma_frm_buf_base_addr_1,
1593 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
1594 lcdc_write(reg_context.dma_frm_buf_ceiling_addr_1,
1595 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
1596 lcdc_write(reg_context.raster_ctrl, LCD_RASTER_CTRL_REG);
1597 return;
1598}
1599
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001600static int fb_suspend(struct platform_device *dev, pm_message_t state)
1601{
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001602 struct fb_info *info = platform_get_drvdata(dev);
1603 struct da8xx_fb_par *par = info->par;
1604
Torben Hohnac751ef2011-01-25 15:07:35 -08001605 console_lock();
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001606 if (par->panel_power_ctrl)
1607 par->panel_power_ctrl(0);
1608
1609 fb_set_suspend(info, 1);
Darren Etheridge26e71642013-08-05 17:02:30 -05001610 lcd_disable_raster(DA8XX_FRAME_WAIT);
Manjunathappa, Prakash7a93cbb2012-09-25 19:41:41 +05301611 lcd_context_save();
Manjunathappa, Prakash9dd44d52012-09-21 21:20:57 +05301612 pm_runtime_put_sync(&dev->dev);
Torben Hohnac751ef2011-01-25 15:07:35 -08001613 console_unlock();
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001614
1615 return 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001616}
1617static int fb_resume(struct platform_device *dev)
1618{
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001619 struct fb_info *info = platform_get_drvdata(dev);
1620 struct da8xx_fb_par *par = info->par;
1621
Torben Hohnac751ef2011-01-25 15:07:35 -08001622 console_lock();
Manjunathappa, Prakash9dd44d52012-09-21 21:20:57 +05301623 pm_runtime_get_sync(&dev->dev);
Manjunathappa, Prakash7a93cbb2012-09-25 19:41:41 +05301624 lcd_context_restore();
Manjunathappa, Prakash67900812012-08-31 19:48:59 +05301625 if (par->blank == FB_BLANK_UNBLANK) {
1626 lcd_enable_raster();
Manjunathappa, Prakashf7c848b2012-07-24 09:45:25 +05301627
Manjunathappa, Prakash67900812012-08-31 19:48:59 +05301628 if (par->panel_power_ctrl)
1629 par->panel_power_ctrl(1);
1630 }
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001631
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001632 fb_set_suspend(info, 0);
Torben Hohnac751ef2011-01-25 15:07:35 -08001633 console_unlock();
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001634
1635 return 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001636}
1637#else
1638#define fb_suspend NULL
1639#define fb_resume NULL
1640#endif
1641
1642static struct platform_driver da8xx_fb_driver = {
1643 .probe = fb_probe,
Greg Kroah-Hartman48c68c42012-12-21 13:07:39 -08001644 .remove = fb_remove,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001645 .suspend = fb_suspend,
1646 .resume = fb_resume,
1647 .driver = {
1648 .name = DRIVER_NAME,
1649 .owner = THIS_MODULE,
1650 },
1651};
1652
1653static int __init da8xx_fb_init(void)
1654{
1655 return platform_driver_register(&da8xx_fb_driver);
1656}
1657
1658static void __exit da8xx_fb_cleanup(void)
1659{
1660 platform_driver_unregister(&da8xx_fb_driver);
1661}
1662
1663module_init(da8xx_fb_init);
1664module_exit(da8xx_fb_cleanup);
1665
1666MODULE_DESCRIPTION("Framebuffer driver for TI da8xx/omap-l1xx");
1667MODULE_AUTHOR("Texas Instruments");
1668MODULE_LICENSE("GPL");