blob: 6b7f2da6f90796538c458b8d752410574bffd6e5 [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>
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070029#include <linux/interrupt.h>
30#include <linux/clk.h>
Chaithrika U Se04e5482009-12-15 16:46:29 -080031#include <linux/cpufreq.h>
Chaithrika U S1d3c6c72009-12-15 16:46:39 -080032#include <linux/console.h>
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +053033#include <linux/spinlock.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Aditya Nellutla3b9cc4e2012-05-23 11:36:31 +053035#include <linux/lcm.h>
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070036#include <video/da8xx-fb.h>
Manjunathappa, Prakash12fa8352012-02-09 11:54:06 +053037#include <asm/div64.h>
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070038
39#define DRIVER_NAME "da8xx_lcdc"
40
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +053041#define LCD_VERSION_1 1
42#define LCD_VERSION_2 2
43
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070044/* LCD Status Register */
Martin Ambrose1f9c3e12010-05-24 14:34:01 -070045#define LCD_END_OF_FRAME1 BIT(9)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070046#define LCD_END_OF_FRAME0 BIT(8)
Martin Ambrose1f9c3e12010-05-24 14:34:01 -070047#define LCD_PL_LOAD_DONE BIT(6)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070048#define LCD_FIFO_UNDERFLOW BIT(5)
49#define LCD_SYNC_LOST BIT(2)
50
51/* LCD DMA Control Register */
52#define LCD_DMA_BURST_SIZE(x) ((x) << 4)
53#define LCD_DMA_BURST_1 0x0
54#define LCD_DMA_BURST_2 0x1
55#define LCD_DMA_BURST_4 0x2
56#define LCD_DMA_BURST_8 0x3
57#define LCD_DMA_BURST_16 0x4
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +053058#define LCD_V1_END_OF_FRAME_INT_ENA BIT(2)
59#define LCD_V2_END_OF_FRAME0_INT_ENA BIT(8)
60#define LCD_V2_END_OF_FRAME1_INT_ENA BIT(9)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070061#define LCD_DUAL_FRAME_BUFFER_ENABLE BIT(0)
62
63/* LCD Control Register */
64#define LCD_CLK_DIVISOR(x) ((x) << 8)
65#define LCD_RASTER_MODE 0x01
66
67/* LCD Raster Control Register */
68#define LCD_PALETTE_LOAD_MODE(x) ((x) << 20)
69#define PALETTE_AND_DATA 0x00
70#define PALETTE_ONLY 0x01
Martin Ambrose1f9c3e12010-05-24 14:34:01 -070071#define DATA_ONLY 0x02
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070072
73#define LCD_MONO_8BIT_MODE BIT(9)
74#define LCD_RASTER_ORDER BIT(8)
75#define LCD_TFT_MODE BIT(7)
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +053076#define LCD_V1_UNDERFLOW_INT_ENA BIT(6)
77#define LCD_V2_UNDERFLOW_INT_ENA BIT(5)
78#define LCD_V1_PL_INT_ENA BIT(4)
79#define LCD_V2_PL_INT_ENA BIT(6)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070080#define LCD_MONOCHROME_MODE BIT(1)
81#define LCD_RASTER_ENABLE BIT(0)
82#define LCD_TFT_ALT_ENABLE BIT(23)
83#define LCD_STN_565_ENABLE BIT(24)
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +053084#define LCD_V2_DMA_CLK_EN BIT(2)
85#define LCD_V2_LIDD_CLK_EN BIT(1)
86#define LCD_V2_CORE_CLK_EN BIT(0)
87#define LCD_V2_LPP_B10 26
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -070088
89/* LCD Raster Timing 2 Register */
90#define LCD_AC_BIAS_TRANSITIONS_PER_INT(x) ((x) << 16)
91#define LCD_AC_BIAS_FREQUENCY(x) ((x) << 8)
92#define LCD_SYNC_CTRL BIT(25)
93#define LCD_SYNC_EDGE BIT(24)
94#define LCD_INVERT_PIXEL_CLOCK BIT(22)
95#define LCD_INVERT_LINE_CLOCK BIT(21)
96#define LCD_INVERT_FRAME_CLOCK BIT(20)
97
98/* LCD Block */
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +053099#define LCD_PID_REG 0x0
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700100#define LCD_CTRL_REG 0x4
101#define LCD_STAT_REG 0x8
102#define LCD_RASTER_CTRL_REG 0x28
103#define LCD_RASTER_TIMING_0_REG 0x2C
104#define LCD_RASTER_TIMING_1_REG 0x30
105#define LCD_RASTER_TIMING_2_REG 0x34
106#define LCD_DMA_CTRL_REG 0x40
107#define LCD_DMA_FRM_BUF_BASE_ADDR_0_REG 0x44
108#define LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG 0x48
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700109#define LCD_DMA_FRM_BUF_BASE_ADDR_1_REG 0x4C
110#define LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG 0x50
111
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530112/* Interrupt Registers available only in Version 2 */
113#define LCD_RAW_STAT_REG 0x58
114#define LCD_MASKED_STAT_REG 0x5c
115#define LCD_INT_ENABLE_SET_REG 0x60
116#define LCD_INT_ENABLE_CLR_REG 0x64
117#define LCD_END_OF_INT_IND_REG 0x68
118
119/* Clock registers available only on Version 2 */
120#define LCD_CLK_ENABLE_REG 0x6c
121#define LCD_CLK_RESET_REG 0x70
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530122#define LCD_CLK_MAIN_RESET BIT(3)
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530123
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700124#define LCD_NUM_BUFFERS 2
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700125
126#define WSI_TIMEOUT 50
127#define PALETTE_SIZE 256
128#define LEFT_MARGIN 64
129#define RIGHT_MARGIN 64
130#define UPPER_MARGIN 32
131#define LOWER_MARGIN 32
132
133static resource_size_t da8xx_fb_reg_base;
134static struct resource *lcdc_regs;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530135static unsigned int lcd_revision;
136static irq_handler_t lcdc_irq_handler;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700137
138static inline unsigned int lcdc_read(unsigned int addr)
139{
140 return (unsigned int)__raw_readl(da8xx_fb_reg_base + (addr));
141}
142
143static inline void lcdc_write(unsigned int val, unsigned int addr)
144{
145 __raw_writel(val, da8xx_fb_reg_base + (addr));
146}
147
148struct da8xx_fb_par {
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700149 resource_size_t p_palette_base;
150 unsigned char *v_palette_base;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700151 dma_addr_t vram_phys;
152 unsigned long vram_size;
153 void *vram_virt;
154 unsigned int dma_start;
155 unsigned int dma_end;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700156 struct clk *lcdc_clk;
157 int irq;
158 unsigned short pseudo_palette[16];
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700159 unsigned int palette_sz;
Chaithrika U S8097b172009-12-15 16:46:29 -0800160 unsigned int pxl_clk;
Chaithrika U S36113802009-12-15 16:46:38 -0800161 int blank;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700162 wait_queue_head_t vsync_wait;
163 int vsync_flag;
164 int vsync_timeout;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530165 spinlock_t lock_for_chan_update;
166
167 /*
168 * LCDC has 2 ping pong DMA channels, channel 0
169 * and channel 1.
170 */
171 unsigned int which_dma_channel_done;
Chaithrika U Se04e5482009-12-15 16:46:29 -0800172#ifdef CONFIG_CPU_FREQ
173 struct notifier_block freq_transition;
Manjunathappa, Prakashf8209172012-01-03 18:10:51 +0530174 unsigned int lcd_fck_rate;
Chaithrika U Se04e5482009-12-15 16:46:29 -0800175#endif
Chaithrika U S36113802009-12-15 16:46:38 -0800176 void (*panel_power_ctrl)(int);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700177};
178
179/* Variable Screen Information */
180static struct fb_var_screeninfo da8xx_fb_var __devinitdata = {
181 .xoffset = 0,
182 .yoffset = 0,
183 .transp = {0, 0, 0},
184 .nonstd = 0,
185 .activate = 0,
186 .height = -1,
187 .width = -1,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700188 .accel_flags = 0,
189 .left_margin = LEFT_MARGIN,
190 .right_margin = RIGHT_MARGIN,
191 .upper_margin = UPPER_MARGIN,
192 .lower_margin = LOWER_MARGIN,
193 .sync = 0,
194 .vmode = FB_VMODE_NONINTERLACED
195};
196
197static struct fb_fix_screeninfo da8xx_fb_fix __devinitdata = {
198 .id = "DA8xx FB Drv",
199 .type = FB_TYPE_PACKED_PIXELS,
200 .type_aux = 0,
201 .visual = FB_VISUAL_PSEUDOCOLOR,
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700202 .xpanstep = 0,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700203 .ypanstep = 1,
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700204 .ywrapstep = 0,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700205 .accel = FB_ACCEL_NONE
206};
207
208struct da8xx_panel {
209 const char name[25]; /* Full name <vendor>_<model> */
210 unsigned short width;
211 unsigned short height;
212 int hfp; /* Horizontal front porch */
213 int hbp; /* Horizontal back porch */
214 int hsw; /* Horizontal Sync Pulse Width */
215 int vfp; /* Vertical front porch */
216 int vbp; /* Vertical back porch */
217 int vsw; /* Vertical Sync Pulse Width */
Chaithrika U S8097b172009-12-15 16:46:29 -0800218 unsigned int pxl_clk; /* Pixel clock */
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700219 unsigned char invert_pxl_clk; /* Invert Pixel clock */
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700220};
221
222static struct da8xx_panel known_lcd_panels[] = {
223 /* Sharp LCD035Q3DG01 */
224 [0] = {
225 .name = "Sharp_LCD035Q3DG01",
226 .width = 320,
227 .height = 240,
228 .hfp = 8,
229 .hbp = 6,
230 .hsw = 0,
231 .vfp = 2,
232 .vbp = 2,
233 .vsw = 0,
Chaithrika U S8097b172009-12-15 16:46:29 -0800234 .pxl_clk = 4608000,
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700235 .invert_pxl_clk = 1,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700236 },
237 /* Sharp LK043T1DG01 */
238 [1] = {
239 .name = "Sharp_LK043T1DG01",
240 .width = 480,
241 .height = 272,
242 .hfp = 2,
243 .hbp = 2,
244 .hsw = 41,
245 .vfp = 2,
246 .vbp = 2,
247 .vsw = 10,
Chaithrika U S8097b172009-12-15 16:46:29 -0800248 .pxl_clk = 7833600,
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700249 .invert_pxl_clk = 0,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700250 },
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100251 [2] = {
252 /* Hitachi SP10Q010 */
253 .name = "SP10Q010",
254 .width = 320,
255 .height = 240,
256 .hfp = 10,
257 .hbp = 10,
258 .hsw = 10,
259 .vfp = 10,
260 .vbp = 10,
261 .vsw = 10,
262 .pxl_clk = 7833600,
263 .invert_pxl_clk = 0,
264 },
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700265};
266
Chaithrika U S36113802009-12-15 16:46:38 -0800267/* Enable the Raster Engine of the LCD Controller */
268static inline void lcd_enable_raster(void)
269{
270 u32 reg;
271
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530272 /* Bring LCDC out of reset */
273 if (lcd_revision == LCD_VERSION_2)
274 lcdc_write(0, LCD_CLK_RESET_REG);
275
Chaithrika U S36113802009-12-15 16:46:38 -0800276 reg = lcdc_read(LCD_RASTER_CTRL_REG);
277 if (!(reg & LCD_RASTER_ENABLE))
278 lcdc_write(reg | LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG);
279}
280
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700281/* Disable the Raster Engine of the LCD Controller */
Chaithrika U S36113802009-12-15 16:46:38 -0800282static inline void lcd_disable_raster(void)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700283{
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700284 u32 reg;
285
286 reg = lcdc_read(LCD_RASTER_CTRL_REG);
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700287 if (reg & LCD_RASTER_ENABLE)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700288 lcdc_write(reg & ~LCD_RASTER_ENABLE, LCD_RASTER_CTRL_REG);
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530289
290 if (lcd_revision == LCD_VERSION_2)
291 /* Write 1 to reset LCDC */
292 lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700293}
294
295static void lcd_blit(int load_mode, struct da8xx_fb_par *par)
296{
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700297 u32 start;
298 u32 end;
299 u32 reg_ras;
300 u32 reg_dma;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530301 u32 reg_int;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700302
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700303 /* init reg to clear PLM (loading mode) fields */
304 reg_ras = lcdc_read(LCD_RASTER_CTRL_REG);
305 reg_ras &= ~(3 << 20);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700306
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700307 reg_dma = lcdc_read(LCD_DMA_CTRL_REG);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700308
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700309 if (load_mode == LOAD_DATA) {
310 start = par->dma_start;
311 end = par->dma_end;
312
313 reg_ras |= LCD_PALETTE_LOAD_MODE(DATA_ONLY);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530314 if (lcd_revision == LCD_VERSION_1) {
315 reg_dma |= LCD_V1_END_OF_FRAME_INT_ENA;
316 } else {
317 reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
318 LCD_V2_END_OF_FRAME0_INT_ENA |
319 LCD_V2_END_OF_FRAME1_INT_ENA;
320 lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
321 }
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700322 reg_dma |= LCD_DUAL_FRAME_BUFFER_ENABLE;
323
324 lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
325 lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
326 lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
327 lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
328 } else if (load_mode == LOAD_PALETTE) {
329 start = par->p_palette_base;
330 end = start + par->palette_sz - 1;
331
332 reg_ras |= LCD_PALETTE_LOAD_MODE(PALETTE_ONLY);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530333
334 if (lcd_revision == LCD_VERSION_1) {
335 reg_ras |= LCD_V1_PL_INT_ENA;
336 } else {
337 reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
338 LCD_V2_PL_INT_ENA;
339 lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
340 }
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700341
342 lcdc_write(start, LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
343 lcdc_write(end, LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
344 }
345
346 lcdc_write(reg_dma, LCD_DMA_CTRL_REG);
347 lcdc_write(reg_ras, LCD_RASTER_CTRL_REG);
348
349 /*
350 * The Raster enable bit must be set after all other control fields are
351 * set.
352 */
353 lcd_enable_raster();
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700354}
355
356/* Configure the Burst Size of DMA */
357static int lcd_cfg_dma(int burst_size)
358{
359 u32 reg;
360
361 reg = lcdc_read(LCD_DMA_CTRL_REG) & 0x00000001;
362 switch (burst_size) {
363 case 1:
364 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_1);
365 break;
366 case 2:
367 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_2);
368 break;
369 case 4:
370 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_4);
371 break;
372 case 8:
373 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_8);
374 break;
375 case 16:
376 reg |= LCD_DMA_BURST_SIZE(LCD_DMA_BURST_16);
377 break;
378 default:
379 return -EINVAL;
380 }
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700381 lcdc_write(reg, LCD_DMA_CTRL_REG);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700382
383 return 0;
384}
385
386static void lcd_cfg_ac_bias(int period, int transitions_per_int)
387{
388 u32 reg;
389
390 /* Set the AC Bias Period and Number of Transisitons per Interrupt */
391 reg = lcdc_read(LCD_RASTER_TIMING_2_REG) & 0xFFF00000;
392 reg |= LCD_AC_BIAS_FREQUENCY(period) |
393 LCD_AC_BIAS_TRANSITIONS_PER_INT(transitions_per_int);
394 lcdc_write(reg, LCD_RASTER_TIMING_2_REG);
395}
396
397static void lcd_cfg_horizontal_sync(int back_porch, int pulse_width,
398 int front_porch)
399{
400 u32 reg;
401
402 reg = lcdc_read(LCD_RASTER_TIMING_0_REG) & 0xf;
403 reg |= ((back_porch & 0xff) << 24)
404 | ((front_porch & 0xff) << 16)
405 | ((pulse_width & 0x3f) << 10);
406 lcdc_write(reg, LCD_RASTER_TIMING_0_REG);
407}
408
409static void lcd_cfg_vertical_sync(int back_porch, int pulse_width,
410 int front_porch)
411{
412 u32 reg;
413
414 reg = lcdc_read(LCD_RASTER_TIMING_1_REG) & 0x3ff;
415 reg |= ((back_porch & 0xff) << 24)
416 | ((front_porch & 0xff) << 16)
417 | ((pulse_width & 0x3f) << 10);
418 lcdc_write(reg, LCD_RASTER_TIMING_1_REG);
419}
420
421static int lcd_cfg_display(const struct lcd_ctrl_config *cfg)
422{
423 u32 reg;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530424 u32 reg_int;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700425
426 reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(LCD_TFT_MODE |
427 LCD_MONO_8BIT_MODE |
428 LCD_MONOCHROME_MODE);
429
430 switch (cfg->p_disp_panel->panel_shade) {
431 case MONOCHROME:
432 reg |= LCD_MONOCHROME_MODE;
433 if (cfg->mono_8bit_mode)
434 reg |= LCD_MONO_8BIT_MODE;
435 break;
436 case COLOR_ACTIVE:
437 reg |= LCD_TFT_MODE;
438 if (cfg->tft_alt_mode)
439 reg |= LCD_TFT_ALT_ENABLE;
440 break;
441
442 case COLOR_PASSIVE:
443 if (cfg->stn_565_mode)
444 reg |= LCD_STN_565_ENABLE;
445 break;
446
447 default:
448 return -EINVAL;
449 }
450
451 /* enable additional interrupts here */
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530452 if (lcd_revision == LCD_VERSION_1) {
453 reg |= LCD_V1_UNDERFLOW_INT_ENA;
454 } else {
455 reg_int = lcdc_read(LCD_INT_ENABLE_SET_REG) |
456 LCD_V2_UNDERFLOW_INT_ENA;
457 lcdc_write(reg_int, LCD_INT_ENABLE_SET_REG);
458 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700459
460 lcdc_write(reg, LCD_RASTER_CTRL_REG);
461
462 reg = lcdc_read(LCD_RASTER_TIMING_2_REG);
463
464 if (cfg->sync_ctrl)
465 reg |= LCD_SYNC_CTRL;
466 else
467 reg &= ~LCD_SYNC_CTRL;
468
469 if (cfg->sync_edge)
470 reg |= LCD_SYNC_EDGE;
471 else
472 reg &= ~LCD_SYNC_EDGE;
473
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700474 if (cfg->invert_line_clock)
475 reg |= LCD_INVERT_LINE_CLOCK;
476 else
477 reg &= ~LCD_INVERT_LINE_CLOCK;
478
479 if (cfg->invert_frm_clock)
480 reg |= LCD_INVERT_FRAME_CLOCK;
481 else
482 reg &= ~LCD_INVERT_FRAME_CLOCK;
483
484 lcdc_write(reg, LCD_RASTER_TIMING_2_REG);
485
486 return 0;
487}
488
489static int lcd_cfg_frame_buffer(struct da8xx_fb_par *par, u32 width, u32 height,
490 u32 bpp, u32 raster_order)
491{
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700492 u32 reg;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700493
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700494 /* Set the Panel Width */
495 /* Pixels per line = (PPL + 1)*16 */
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530496 if (lcd_revision == LCD_VERSION_1) {
497 /*
498 * 0x3F in bits 4..9 gives max horizontal resolution = 1024
499 * pixels.
500 */
501 width &= 0x3f0;
502 } else {
503 /*
504 * 0x7F in bits 4..10 gives max horizontal resolution = 2048
505 * pixels.
506 */
507 width &= 0x7f0;
508 }
509
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700510 reg = lcdc_read(LCD_RASTER_TIMING_0_REG);
511 reg &= 0xfffffc00;
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530512 if (lcd_revision == LCD_VERSION_1) {
513 reg |= ((width >> 4) - 1) << 4;
514 } else {
515 width = (width >> 4) - 1;
516 reg |= ((width & 0x3f) << 4) | ((width & 0x40) >> 3);
517 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700518 lcdc_write(reg, LCD_RASTER_TIMING_0_REG);
519
520 /* Set the Panel Height */
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530521 /* Set bits 9:0 of Lines Per Pixel */
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700522 reg = lcdc_read(LCD_RASTER_TIMING_1_REG);
523 reg = ((height - 1) & 0x3ff) | (reg & 0xfffffc00);
524 lcdc_write(reg, LCD_RASTER_TIMING_1_REG);
525
Manjunathappa, Prakash4d740802011-07-18 09:58:53 +0530526 /* Set bit 10 of Lines Per Pixel */
527 if (lcd_revision == LCD_VERSION_2) {
528 reg = lcdc_read(LCD_RASTER_TIMING_2_REG);
529 reg |= ((height - 1) & 0x400) << 16;
530 lcdc_write(reg, LCD_RASTER_TIMING_2_REG);
531 }
532
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700533 /* Set the Raster Order of the Frame Buffer */
534 reg = lcdc_read(LCD_RASTER_CTRL_REG) & ~(1 << 8);
535 if (raster_order)
536 reg |= LCD_RASTER_ORDER;
537 lcdc_write(reg, LCD_RASTER_CTRL_REG);
538
539 switch (bpp) {
540 case 1:
541 case 2:
542 case 4:
543 case 16:
544 par->palette_sz = 16 * 2;
545 break;
546
547 case 8:
548 par->palette_sz = 256 * 2;
549 break;
550
551 default:
552 return -EINVAL;
553 }
554
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700555 return 0;
556}
557
558static int fb_setcolreg(unsigned regno, unsigned red, unsigned green,
559 unsigned blue, unsigned transp,
560 struct fb_info *info)
561{
562 struct da8xx_fb_par *par = info->par;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700563 unsigned short *palette = (unsigned short *) par->v_palette_base;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700564 u_short pal;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700565 int update_hw = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700566
567 if (regno > 255)
568 return 1;
569
570 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR)
571 return 1;
572
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100573 if (info->var.bits_per_pixel == 4) {
574 if (regno > 15)
575 return 1;
576
577 if (info->var.grayscale) {
578 pal = regno;
579 } else {
580 red >>= 4;
581 green >>= 8;
582 blue >>= 12;
583
584 pal = (red & 0x0f00);
585 pal |= (green & 0x00f0);
586 pal |= (blue & 0x000f);
587 }
588 if (regno == 0)
589 pal |= 0x2000;
590 palette[regno] = pal;
591
592 } else if (info->var.bits_per_pixel == 8) {
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700593 red >>= 4;
594 green >>= 8;
595 blue >>= 12;
596
597 pal = (red & 0x0f00);
598 pal |= (green & 0x00f0);
599 pal |= (blue & 0x000f);
600
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700601 if (palette[regno] != pal) {
602 update_hw = 1;
603 palette[regno] = pal;
604 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700605 } else if ((info->var.bits_per_pixel == 16) && regno < 16) {
606 red >>= (16 - info->var.red.length);
607 red <<= info->var.red.offset;
608
609 green >>= (16 - info->var.green.length);
610 green <<= info->var.green.offset;
611
612 blue >>= (16 - info->var.blue.length);
613 blue <<= info->var.blue.offset;
614
615 par->pseudo_palette[regno] = red | green | blue;
616
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700617 if (palette[0] != 0x4000) {
618 update_hw = 1;
619 palette[0] = 0x4000;
620 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700621 }
622
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700623 /* Update the palette in the h/w as needed. */
624 if (update_hw)
625 lcd_blit(LOAD_PALETTE, par);
626
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700627 return 0;
628}
629
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700630static void lcd_reset(struct da8xx_fb_par *par)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700631{
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700632 /* Disable the Raster if previously Enabled */
Chaithrika U S36113802009-12-15 16:46:38 -0800633 lcd_disable_raster();
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700634
635 /* DMA has to be disabled */
636 lcdc_write(0, LCD_DMA_CTRL_REG);
637 lcdc_write(0, LCD_RASTER_CTRL_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530638
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530639 if (lcd_revision == LCD_VERSION_2) {
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530640 lcdc_write(0, LCD_INT_ENABLE_SET_REG);
Manjunathappa, Prakash74a0efd2011-11-15 17:32:23 +0530641 /* Write 1 to reset */
642 lcdc_write(LCD_CLK_MAIN_RESET, LCD_CLK_RESET_REG);
643 lcdc_write(0, LCD_CLK_RESET_REG);
644 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700645}
646
Chaithrika U S8097b172009-12-15 16:46:29 -0800647static void lcd_calc_clk_divider(struct da8xx_fb_par *par)
648{
649 unsigned int lcd_clk, div;
650
651 lcd_clk = clk_get_rate(par->lcdc_clk);
652 div = lcd_clk / par->pxl_clk;
653
654 /* Configure the LCD clock divisor. */
655 lcdc_write(LCD_CLK_DIVISOR(div) |
656 (LCD_RASTER_MODE & 0x1), LCD_CTRL_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530657
658 if (lcd_revision == LCD_VERSION_2)
659 lcdc_write(LCD_V2_DMA_CLK_EN | LCD_V2_LIDD_CLK_EN |
660 LCD_V2_CORE_CLK_EN, LCD_CLK_ENABLE_REG);
661
Chaithrika U S8097b172009-12-15 16:46:29 -0800662}
663
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700664static int lcd_init(struct da8xx_fb_par *par, const struct lcd_ctrl_config *cfg,
665 struct da8xx_panel *panel)
666{
667 u32 bpp;
668 int ret = 0;
669
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700670 lcd_reset(par);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700671
Chaithrika U S8097b172009-12-15 16:46:29 -0800672 /* Calculate the divider */
673 lcd_calc_clk_divider(par);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700674
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700675 if (panel->invert_pxl_clk)
676 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG) |
677 LCD_INVERT_PIXEL_CLOCK), LCD_RASTER_TIMING_2_REG);
678 else
679 lcdc_write((lcdc_read(LCD_RASTER_TIMING_2_REG) &
680 ~LCD_INVERT_PIXEL_CLOCK), LCD_RASTER_TIMING_2_REG);
681
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700682 /* Configure the DMA burst size. */
683 ret = lcd_cfg_dma(cfg->dma_burst_sz);
684 if (ret < 0)
685 return ret;
686
687 /* Configure the AC bias properties. */
688 lcd_cfg_ac_bias(cfg->ac_bias, cfg->ac_bias_intrpt);
689
690 /* Configure the vertical and horizontal sync properties. */
691 lcd_cfg_vertical_sync(panel->vbp, panel->vsw, panel->vfp);
692 lcd_cfg_horizontal_sync(panel->hbp, panel->hsw, panel->hfp);
693
694 /* Configure for disply */
695 ret = lcd_cfg_display(cfg);
696 if (ret < 0)
697 return ret;
698
699 if (QVGA != cfg->p_disp_panel->panel_type)
700 return -EINVAL;
701
702 if (cfg->bpp <= cfg->p_disp_panel->max_bpp &&
703 cfg->bpp >= cfg->p_disp_panel->min_bpp)
704 bpp = cfg->bpp;
705 else
706 bpp = cfg->p_disp_panel->max_bpp;
707 if (bpp == 12)
708 bpp = 16;
709 ret = lcd_cfg_frame_buffer(par, (unsigned int)panel->width,
710 (unsigned int)panel->height, bpp,
711 cfg->raster_order);
712 if (ret < 0)
713 return ret;
714
715 /* Configure FDD */
716 lcdc_write((lcdc_read(LCD_RASTER_CTRL_REG) & 0xfff00fff) |
717 (cfg->fdd << 12), LCD_RASTER_CTRL_REG);
718
719 return 0;
720}
721
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530722/* IRQ handler for version 2 of LCDC */
723static irqreturn_t lcdc_irq_handler_rev02(int irq, void *arg)
724{
725 struct da8xx_fb_par *par = arg;
726 u32 stat = lcdc_read(LCD_MASKED_STAT_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530727
728 if ((stat & LCD_SYNC_LOST) && (stat & LCD_FIFO_UNDERFLOW)) {
729 lcd_disable_raster();
730 lcdc_write(stat, LCD_MASKED_STAT_REG);
731 lcd_enable_raster();
732 } else if (stat & LCD_PL_LOAD_DONE) {
733 /*
734 * Must disable raster before changing state of any control bit.
735 * And also must be disabled before clearing the PL loading
736 * interrupt via the following write to the status register. If
737 * this is done after then one gets multiple PL done interrupts.
738 */
739 lcd_disable_raster();
740
741 lcdc_write(stat, LCD_MASKED_STAT_REG);
742
Manjunathappa, Prakash8a81dcc2012-07-18 20:51:11 +0530743 /* Disable PL completion interrupt */
744 lcdc_write(LCD_V2_PL_INT_ENA, LCD_INT_ENABLE_CLR_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530745
746 /* Setup and start data loading mode */
747 lcd_blit(LOAD_DATA, par);
748 } else {
749 lcdc_write(stat, LCD_MASKED_STAT_REG);
750
751 if (stat & LCD_END_OF_FRAME0) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530752 par->which_dma_channel_done = 0;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530753 lcdc_write(par->dma_start,
754 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
755 lcdc_write(par->dma_end,
756 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
757 par->vsync_flag = 1;
758 wake_up_interruptible(&par->vsync_wait);
759 }
760
761 if (stat & LCD_END_OF_FRAME1) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530762 par->which_dma_channel_done = 1;
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530763 lcdc_write(par->dma_start,
764 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
765 lcdc_write(par->dma_end,
766 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
767 par->vsync_flag = 1;
768 wake_up_interruptible(&par->vsync_wait);
769 }
770 }
771
772 lcdc_write(0, LCD_END_OF_INT_IND_REG);
773 return IRQ_HANDLED;
774}
775
776/* IRQ handler for version 1 LCDC */
777static irqreturn_t lcdc_irq_handler_rev01(int irq, void *arg)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700778{
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700779 struct da8xx_fb_par *par = arg;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700780 u32 stat = lcdc_read(LCD_STAT_REG);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700781 u32 reg_ras;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700782
783 if ((stat & LCD_SYNC_LOST) && (stat & LCD_FIFO_UNDERFLOW)) {
Chaithrika U S36113802009-12-15 16:46:38 -0800784 lcd_disable_raster();
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700785 lcdc_write(stat, LCD_STAT_REG);
Chaithrika U S36113802009-12-15 16:46:38 -0800786 lcd_enable_raster();
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700787 } else if (stat & LCD_PL_LOAD_DONE) {
788 /*
789 * Must disable raster before changing state of any control bit.
790 * And also must be disabled before clearing the PL loading
791 * interrupt via the following write to the status register. If
792 * this is done after then one gets multiple PL done interrupts.
793 */
794 lcd_disable_raster();
795
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700796 lcdc_write(stat, LCD_STAT_REG);
797
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700798 /* Disable PL completion inerrupt */
799 reg_ras = lcdc_read(LCD_RASTER_CTRL_REG);
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +0530800 reg_ras &= ~LCD_V1_PL_INT_ENA;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700801 lcdc_write(reg_ras, LCD_RASTER_CTRL_REG);
802
803 /* Setup and start data loading mode */
804 lcd_blit(LOAD_DATA, par);
805 } else {
806 lcdc_write(stat, LCD_STAT_REG);
807
808 if (stat & LCD_END_OF_FRAME0) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530809 par->which_dma_channel_done = 0;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700810 lcdc_write(par->dma_start,
811 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
812 lcdc_write(par->dma_end,
813 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
814 par->vsync_flag = 1;
815 wake_up_interruptible(&par->vsync_wait);
816 }
817
818 if (stat & LCD_END_OF_FRAME1) {
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +0530819 par->which_dma_channel_done = 1;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700820 lcdc_write(par->dma_start,
821 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
822 lcdc_write(par->dma_end,
823 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
824 par->vsync_flag = 1;
825 wake_up_interruptible(&par->vsync_wait);
826 }
827 }
828
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700829 return IRQ_HANDLED;
830}
831
832static int fb_check_var(struct fb_var_screeninfo *var,
833 struct fb_info *info)
834{
835 int err = 0;
836
837 switch (var->bits_per_pixel) {
838 case 1:
839 case 8:
840 var->red.offset = 0;
841 var->red.length = 8;
842 var->green.offset = 0;
843 var->green.length = 8;
844 var->blue.offset = 0;
845 var->blue.length = 8;
846 var->transp.offset = 0;
847 var->transp.length = 0;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100848 var->nonstd = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700849 break;
850 case 4:
851 var->red.offset = 0;
852 var->red.length = 4;
853 var->green.offset = 0;
854 var->green.length = 4;
855 var->blue.offset = 0;
856 var->blue.length = 4;
857 var->transp.offset = 0;
858 var->transp.length = 0;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100859 var->nonstd = FB_NONSTD_REV_PIX_IN_B;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700860 break;
861 case 16: /* RGB 565 */
Sudhakar Rajashekhara3510b8f2009-12-01 13:17:43 -0800862 var->red.offset = 11;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700863 var->red.length = 5;
864 var->green.offset = 5;
865 var->green.length = 6;
Sudhakar Rajashekhara3510b8f2009-12-01 13:17:43 -0800866 var->blue.offset = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700867 var->blue.length = 5;
868 var->transp.offset = 0;
869 var->transp.length = 0;
Anatolij Gustschinf4130702012-03-13 14:13:57 +0100870 var->nonstd = 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700871 break;
872 default:
873 err = -EINVAL;
874 }
875
876 var->red.msb_right = 0;
877 var->green.msb_right = 0;
878 var->blue.msb_right = 0;
879 var->transp.msb_right = 0;
880 return err;
881}
882
Chaithrika U Se04e5482009-12-15 16:46:29 -0800883#ifdef CONFIG_CPU_FREQ
884static int lcd_da8xx_cpufreq_transition(struct notifier_block *nb,
885 unsigned long val, void *data)
886{
887 struct da8xx_fb_par *par;
Chaithrika U Se04e5482009-12-15 16:46:29 -0800888
889 par = container_of(nb, struct da8xx_fb_par, freq_transition);
Manjunathappa, Prakashf8209172012-01-03 18:10:51 +0530890 if (val == CPUFREQ_POSTCHANGE) {
891 if (par->lcd_fck_rate != clk_get_rate(par->lcdc_clk)) {
892 par->lcd_fck_rate = clk_get_rate(par->lcdc_clk);
893 lcd_disable_raster();
894 lcd_calc_clk_divider(par);
895 lcd_enable_raster();
896 }
Chaithrika U Se04e5482009-12-15 16:46:29 -0800897 }
898
899 return 0;
900}
901
902static inline int lcd_da8xx_cpufreq_register(struct da8xx_fb_par *par)
903{
904 par->freq_transition.notifier_call = lcd_da8xx_cpufreq_transition;
905
906 return cpufreq_register_notifier(&par->freq_transition,
907 CPUFREQ_TRANSITION_NOTIFIER);
908}
909
910static inline void lcd_da8xx_cpufreq_deregister(struct da8xx_fb_par *par)
911{
912 cpufreq_unregister_notifier(&par->freq_transition,
913 CPUFREQ_TRANSITION_NOTIFIER);
914}
915#endif
916
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700917static int __devexit fb_remove(struct platform_device *dev)
918{
919 struct fb_info *info = dev_get_drvdata(&dev->dev);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700920
921 if (info) {
922 struct da8xx_fb_par *par = info->par;
923
Chaithrika U Se04e5482009-12-15 16:46:29 -0800924#ifdef CONFIG_CPU_FREQ
925 lcd_da8xx_cpufreq_deregister(par);
926#endif
Chaithrika U S36113802009-12-15 16:46:38 -0800927 if (par->panel_power_ctrl)
928 par->panel_power_ctrl(0);
929
930 lcd_disable_raster();
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700931 lcdc_write(0, LCD_RASTER_CTRL_REG);
932
933 /* disable DMA */
934 lcdc_write(0, LCD_DMA_CTRL_REG);
935
936 unregister_framebuffer(info);
937 fb_dealloc_cmap(&info->cmap);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700938 dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base,
939 par->p_palette_base);
940 dma_free_coherent(NULL, par->vram_size, par->vram_virt,
941 par->vram_phys);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700942 free_irq(par->irq, par);
943 clk_disable(par->lcdc_clk);
944 clk_put(par->lcdc_clk);
945 framebuffer_release(info);
946 iounmap((void __iomem *)da8xx_fb_reg_base);
947 release_mem_region(lcdc_regs->start, resource_size(lcdc_regs));
948
949 }
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700950 return 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700951}
952
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700953/*
954 * Function to wait for vertical sync which for this LCD peripheral
955 * translates into waiting for the current raster frame to complete.
956 */
957static int fb_wait_for_vsync(struct fb_info *info)
958{
959 struct da8xx_fb_par *par = info->par;
960 int ret;
961
962 /*
963 * 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 -0300964 * race condition here where the ISR could have occurred just before or
Martin Ambrose1f9c3e12010-05-24 14:34:01 -0700965 * just after this set. But since we are just coarsely waiting for
966 * a frame to complete then that's OK. i.e. if the frame completed
967 * just before this code executed then we have to wait another full
968 * frame time but there is no way to avoid such a situation. On the
969 * other hand if the frame completed just after then we don't need
970 * to wait long at all. Either way we are guaranteed to return to the
971 * user immediately after a frame completion which is all that is
972 * required.
973 */
974 par->vsync_flag = 0;
975 ret = wait_event_interruptible_timeout(par->vsync_wait,
976 par->vsync_flag != 0,
977 par->vsync_timeout);
978 if (ret < 0)
979 return ret;
980 if (ret == 0)
981 return -ETIMEDOUT;
982
983 return 0;
984}
985
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700986static int fb_ioctl(struct fb_info *info, unsigned int cmd,
987 unsigned long arg)
988{
989 struct lcd_sync_arg sync_arg;
990
991 switch (cmd) {
992 case FBIOGET_CONTRAST:
993 case FBIOPUT_CONTRAST:
994 case FBIGET_BRIGHTNESS:
995 case FBIPUT_BRIGHTNESS:
996 case FBIGET_COLOR:
997 case FBIPUT_COLOR:
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -0700998 return -ENOTTY;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -0700999 case FBIPUT_HSYNC:
1000 if (copy_from_user(&sync_arg, (char *)arg,
1001 sizeof(struct lcd_sync_arg)))
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -07001002 return -EFAULT;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001003 lcd_cfg_horizontal_sync(sync_arg.back_porch,
1004 sync_arg.pulse_width,
1005 sync_arg.front_porch);
1006 break;
1007 case FBIPUT_VSYNC:
1008 if (copy_from_user(&sync_arg, (char *)arg,
1009 sizeof(struct lcd_sync_arg)))
Sudhakar Rajashekhara2f93e8f2009-09-22 16:47:06 -07001010 return -EFAULT;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001011 lcd_cfg_vertical_sync(sync_arg.back_porch,
1012 sync_arg.pulse_width,
1013 sync_arg.front_porch);
1014 break;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001015 case FBIO_WAITFORVSYNC:
1016 return fb_wait_for_vsync(info);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001017 default:
1018 return -EINVAL;
1019 }
1020 return 0;
1021}
1022
Chaithrika U S312d9712009-12-15 16:46:39 -08001023static int cfb_blank(int blank, struct fb_info *info)
1024{
1025 struct da8xx_fb_par *par = info->par;
1026 int ret = 0;
1027
1028 if (par->blank == blank)
1029 return 0;
1030
1031 par->blank = blank;
1032 switch (blank) {
1033 case FB_BLANK_UNBLANK:
1034 if (par->panel_power_ctrl)
1035 par->panel_power_ctrl(1);
1036
1037 lcd_enable_raster();
1038 break;
Yegor Yefremov99a647d2012-07-06 16:01:28 +02001039 case FB_BLANK_NORMAL:
1040 case FB_BLANK_VSYNC_SUSPEND:
1041 case FB_BLANK_HSYNC_SUSPEND:
Chaithrika U S312d9712009-12-15 16:46:39 -08001042 case FB_BLANK_POWERDOWN:
1043 if (par->panel_power_ctrl)
1044 par->panel_power_ctrl(0);
1045
1046 lcd_disable_raster();
1047 break;
1048 default:
1049 ret = -EINVAL;
1050 }
1051
1052 return ret;
1053}
1054
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001055/*
1056 * Set new x,y offsets in the virtual display for the visible area and switch
1057 * to the new mode.
1058 */
1059static int da8xx_pan_display(struct fb_var_screeninfo *var,
1060 struct fb_info *fbi)
1061{
1062 int ret = 0;
1063 struct fb_var_screeninfo new_var;
1064 struct da8xx_fb_par *par = fbi->par;
1065 struct fb_fix_screeninfo *fix = &fbi->fix;
1066 unsigned int end;
1067 unsigned int start;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +05301068 unsigned long irq_flags;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001069
1070 if (var->xoffset != fbi->var.xoffset ||
1071 var->yoffset != fbi->var.yoffset) {
1072 memcpy(&new_var, &fbi->var, sizeof(new_var));
1073 new_var.xoffset = var->xoffset;
1074 new_var.yoffset = var->yoffset;
1075 if (fb_check_var(&new_var, fbi))
1076 ret = -EINVAL;
1077 else {
1078 memcpy(&fbi->var, &new_var, sizeof(new_var));
1079
1080 start = fix->smem_start +
1081 new_var.yoffset * fix->line_length +
Laurent Pincharte6c4d3d2011-06-14 09:24:45 +00001082 new_var.xoffset * fbi->var.bits_per_pixel / 8;
1083 end = start + fbi->var.yres * fix->line_length - 1;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001084 par->dma_start = start;
1085 par->dma_end = end;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +05301086 spin_lock_irqsave(&par->lock_for_chan_update,
1087 irq_flags);
1088 if (par->which_dma_channel_done == 0) {
1089 lcdc_write(par->dma_start,
1090 LCD_DMA_FRM_BUF_BASE_ADDR_0_REG);
1091 lcdc_write(par->dma_end,
1092 LCD_DMA_FRM_BUF_CEILING_ADDR_0_REG);
1093 } else if (par->which_dma_channel_done == 1) {
1094 lcdc_write(par->dma_start,
1095 LCD_DMA_FRM_BUF_BASE_ADDR_1_REG);
1096 lcdc_write(par->dma_end,
1097 LCD_DMA_FRM_BUF_CEILING_ADDR_1_REG);
1098 }
1099 spin_unlock_irqrestore(&par->lock_for_chan_update,
1100 irq_flags);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001101 }
1102 }
1103
1104 return ret;
1105}
1106
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001107static struct fb_ops da8xx_fb_ops = {
1108 .owner = THIS_MODULE,
1109 .fb_check_var = fb_check_var,
1110 .fb_setcolreg = fb_setcolreg,
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001111 .fb_pan_display = da8xx_pan_display,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001112 .fb_ioctl = fb_ioctl,
1113 .fb_fillrect = cfb_fillrect,
1114 .fb_copyarea = cfb_copyarea,
1115 .fb_imageblit = cfb_imageblit,
Chaithrika U S312d9712009-12-15 16:46:39 -08001116 .fb_blank = cfb_blank,
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001117};
1118
Manjunathappa, Prakash12fa8352012-02-09 11:54:06 +05301119/* Calculate and return pixel clock period in pico seconds */
1120static unsigned int da8xxfb_pixel_clk_period(struct da8xx_fb_par *par)
1121{
1122 unsigned int lcd_clk, div;
1123 unsigned int configured_pix_clk;
1124 unsigned long long pix_clk_period_picosec = 1000000000000ULL;
1125
1126 lcd_clk = clk_get_rate(par->lcdc_clk);
1127 div = lcd_clk / par->pxl_clk;
1128 configured_pix_clk = (lcd_clk / div);
1129
1130 do_div(pix_clk_period_picosec, configured_pix_clk);
1131
1132 return pix_clk_period_picosec;
1133}
1134
axel lin1db41e02011-02-22 01:52:42 +00001135static int __devinit fb_probe(struct platform_device *device)
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001136{
1137 struct da8xx_lcdc_platform_data *fb_pdata =
1138 device->dev.platform_data;
1139 struct lcd_ctrl_config *lcd_cfg;
1140 struct da8xx_panel *lcdc_info;
1141 struct fb_info *da8xx_fb_info;
1142 struct clk *fb_clk = NULL;
1143 struct da8xx_fb_par *par;
1144 resource_size_t len;
1145 int ret, i;
Aditya Nellutla3b9cc4e2012-05-23 11:36:31 +05301146 unsigned long ulcm;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001147
1148 if (fb_pdata == NULL) {
1149 dev_err(&device->dev, "Can not get platform data\n");
1150 return -ENOENT;
1151 }
1152
1153 lcdc_regs = platform_get_resource(device, IORESOURCE_MEM, 0);
1154 if (!lcdc_regs) {
1155 dev_err(&device->dev,
1156 "Can not get memory resource for LCD controller\n");
1157 return -ENOENT;
1158 }
1159
1160 len = resource_size(lcdc_regs);
1161
1162 lcdc_regs = request_mem_region(lcdc_regs->start, len, lcdc_regs->name);
1163 if (!lcdc_regs)
1164 return -EBUSY;
1165
1166 da8xx_fb_reg_base = (resource_size_t)ioremap(lcdc_regs->start, len);
1167 if (!da8xx_fb_reg_base) {
1168 ret = -EBUSY;
1169 goto err_request_mem;
1170 }
1171
1172 fb_clk = clk_get(&device->dev, NULL);
1173 if (IS_ERR(fb_clk)) {
1174 dev_err(&device->dev, "Can not get device clock\n");
1175 ret = -ENODEV;
1176 goto err_ioremap;
1177 }
1178 ret = clk_enable(fb_clk);
1179 if (ret)
1180 goto err_clk_put;
1181
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +05301182 /* Determine LCD IP Version */
1183 switch (lcdc_read(LCD_PID_REG)) {
1184 case 0x4C100102:
1185 lcd_revision = LCD_VERSION_1;
1186 break;
1187 case 0x4F200800:
1188 lcd_revision = LCD_VERSION_2;
1189 break;
1190 default:
1191 dev_warn(&device->dev, "Unknown PID Reg value 0x%x, "
1192 "defaulting to LCD revision 1\n",
1193 lcdc_read(LCD_PID_REG));
1194 lcd_revision = LCD_VERSION_1;
1195 break;
1196 }
1197
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001198 for (i = 0, lcdc_info = known_lcd_panels;
1199 i < ARRAY_SIZE(known_lcd_panels);
1200 i++, lcdc_info++) {
1201 if (strcmp(fb_pdata->type, lcdc_info->name) == 0)
1202 break;
1203 }
1204
1205 if (i == ARRAY_SIZE(known_lcd_panels)) {
1206 dev_err(&device->dev, "GLCD: No valid panel found\n");
Roel Kluindd04a6b2009-11-17 14:06:15 -08001207 ret = -ENODEV;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001208 goto err_clk_disable;
1209 } else
1210 dev_info(&device->dev, "GLCD: Found %s panel\n",
1211 fb_pdata->type);
1212
1213 lcd_cfg = (struct lcd_ctrl_config *)fb_pdata->controller_data;
1214
1215 da8xx_fb_info = framebuffer_alloc(sizeof(struct da8xx_fb_par),
1216 &device->dev);
1217 if (!da8xx_fb_info) {
1218 dev_dbg(&device->dev, "Memory allocation failed for fb_info\n");
1219 ret = -ENOMEM;
1220 goto err_clk_disable;
1221 }
1222
1223 par = da8xx_fb_info->par;
Chaithrika U S8097b172009-12-15 16:46:29 -08001224 par->lcdc_clk = fb_clk;
Manjunathappa, Prakashf8209172012-01-03 18:10:51 +05301225#ifdef CONFIG_CPU_FREQ
1226 par->lcd_fck_rate = clk_get_rate(fb_clk);
1227#endif
Chaithrika U S8097b172009-12-15 16:46:29 -08001228 par->pxl_clk = lcdc_info->pxl_clk;
Chaithrika U S36113802009-12-15 16:46:38 -08001229 if (fb_pdata->panel_power_ctrl) {
1230 par->panel_power_ctrl = fb_pdata->panel_power_ctrl;
1231 par->panel_power_ctrl(1);
1232 }
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001233
1234 if (lcd_init(par, lcd_cfg, lcdc_info) < 0) {
1235 dev_err(&device->dev, "lcd_init failed\n");
1236 ret = -EFAULT;
1237 goto err_release_fb;
1238 }
1239
1240 /* allocate frame buffer */
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001241 par->vram_size = lcdc_info->width * lcdc_info->height * lcd_cfg->bpp;
Aditya Nellutla3b9cc4e2012-05-23 11:36:31 +05301242 ulcm = lcm((lcdc_info->width * lcd_cfg->bpp)/8, PAGE_SIZE);
1243 par->vram_size = roundup(par->vram_size/8, ulcm);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001244 par->vram_size = par->vram_size * LCD_NUM_BUFFERS;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001245
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001246 par->vram_virt = dma_alloc_coherent(NULL,
1247 par->vram_size,
1248 (resource_size_t *) &par->vram_phys,
1249 GFP_KERNEL | GFP_DMA);
1250 if (!par->vram_virt) {
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001251 dev_err(&device->dev,
1252 "GLCD: kmalloc for frame buffer failed\n");
1253 ret = -EINVAL;
1254 goto err_release_fb;
1255 }
1256
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001257 da8xx_fb_info->screen_base = (char __iomem *) par->vram_virt;
1258 da8xx_fb_fix.smem_start = par->vram_phys;
1259 da8xx_fb_fix.smem_len = par->vram_size;
1260 da8xx_fb_fix.line_length = (lcdc_info->width * lcd_cfg->bpp) / 8;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001261
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001262 par->dma_start = par->vram_phys;
1263 par->dma_end = par->dma_start + lcdc_info->height *
1264 da8xx_fb_fix.line_length - 1;
1265
1266 /* allocate palette buffer */
1267 par->v_palette_base = dma_alloc_coherent(NULL,
1268 PALETTE_SIZE,
1269 (resource_size_t *)
1270 &par->p_palette_base,
1271 GFP_KERNEL | GFP_DMA);
1272 if (!par->v_palette_base) {
1273 dev_err(&device->dev,
1274 "GLCD: kmalloc for palette buffer failed\n");
1275 ret = -EINVAL;
1276 goto err_release_fb_mem;
1277 }
1278 memset(par->v_palette_base, 0, PALETTE_SIZE);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001279
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001280 par->irq = platform_get_irq(device, 0);
1281 if (par->irq < 0) {
1282 ret = -ENOENT;
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001283 goto err_release_pl_mem;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001284 }
1285
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001286 /* Initialize par */
1287 da8xx_fb_info->var.bits_per_pixel = lcd_cfg->bpp;
1288
1289 da8xx_fb_var.xres = lcdc_info->width;
1290 da8xx_fb_var.xres_virtual = lcdc_info->width;
1291
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001292 da8xx_fb_var.yres = lcdc_info->height;
1293 da8xx_fb_var.yres_virtual = lcdc_info->height * LCD_NUM_BUFFERS;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001294
1295 da8xx_fb_var.grayscale =
1296 lcd_cfg->p_disp_panel->panel_shade == MONOCHROME ? 1 : 0;
1297 da8xx_fb_var.bits_per_pixel = lcd_cfg->bpp;
1298
1299 da8xx_fb_var.hsync_len = lcdc_info->hsw;
1300 da8xx_fb_var.vsync_len = lcdc_info->vsw;
Anatolij Gustschin084e1042012-03-13 14:13:04 +01001301 da8xx_fb_var.right_margin = lcdc_info->hfp;
1302 da8xx_fb_var.left_margin = lcdc_info->hbp;
1303 da8xx_fb_var.lower_margin = lcdc_info->vfp;
1304 da8xx_fb_var.upper_margin = lcdc_info->vbp;
Manjunathappa, Prakash12fa8352012-02-09 11:54:06 +05301305 da8xx_fb_var.pixclock = da8xxfb_pixel_clk_period(par);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001306
1307 /* Initialize fbinfo */
1308 da8xx_fb_info->flags = FBINFO_FLAG_DEFAULT;
1309 da8xx_fb_info->fix = da8xx_fb_fix;
1310 da8xx_fb_info->var = da8xx_fb_var;
1311 da8xx_fb_info->fbops = &da8xx_fb_ops;
1312 da8xx_fb_info->pseudo_palette = par->pseudo_palette;
Sudhakar Rajashekhara3510b8f2009-12-01 13:17:43 -08001313 da8xx_fb_info->fix.visual = (da8xx_fb_info->var.bits_per_pixel <= 8) ?
1314 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001315
1316 ret = fb_alloc_cmap(&da8xx_fb_info->cmap, PALETTE_SIZE, 0);
1317 if (ret)
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001318 goto err_release_pl_mem;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001319 da8xx_fb_info->cmap.len = par->palette_sz;
1320
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001321 /* initialize var_screeninfo */
1322 da8xx_fb_var.activate = FB_ACTIVATE_FORCE;
1323 fb_set_var(da8xx_fb_info, &da8xx_fb_var);
1324
1325 dev_set_drvdata(&device->dev, da8xx_fb_info);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001326
1327 /* initialize the vsync wait queue */
1328 init_waitqueue_head(&par->vsync_wait);
1329 par->vsync_timeout = HZ / 5;
Manjunathappa, Prakashdeb95c62012-07-18 21:01:56 +05301330 par->which_dma_channel_done = -1;
1331 spin_lock_init(&par->lock_for_chan_update);
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001332
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001333 /* Register the Frame Buffer */
1334 if (register_framebuffer(da8xx_fb_info) < 0) {
1335 dev_err(&device->dev,
1336 "GLCD: Frame Buffer Registration Failed!\n");
1337 ret = -EINVAL;
1338 goto err_dealloc_cmap;
1339 }
1340
Chaithrika U Se04e5482009-12-15 16:46:29 -08001341#ifdef CONFIG_CPU_FREQ
1342 ret = lcd_da8xx_cpufreq_register(par);
1343 if (ret) {
1344 dev_err(&device->dev, "failed to register cpufreq\n");
1345 goto err_cpu_freq;
1346 }
1347#endif
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001348
Manjunathappa, Prakashc6daf052011-07-05 15:51:20 +05301349 if (lcd_revision == LCD_VERSION_1)
1350 lcdc_irq_handler = lcdc_irq_handler_rev01;
1351 else
1352 lcdc_irq_handler = lcdc_irq_handler_rev02;
1353
1354 ret = request_irq(par->irq, lcdc_irq_handler, 0,
1355 DRIVER_NAME, par);
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001356 if (ret)
1357 goto irq_freq;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001358 return 0;
1359
Caglar Akyuz93c176f2010-11-30 20:04:14 +00001360irq_freq:
Chaithrika U Se04e5482009-12-15 16:46:29 -08001361#ifdef CONFIG_CPU_FREQ
axel lin360c2022011-01-20 03:50:51 +00001362 lcd_da8xx_cpufreq_deregister(par);
Chaithrika U Se04e5482009-12-15 16:46:29 -08001363err_cpu_freq:
Manjunathappa, Prakash3a844092012-02-09 10:34:38 +05301364#endif
Chaithrika U Se04e5482009-12-15 16:46:29 -08001365 unregister_framebuffer(da8xx_fb_info);
Chaithrika U Se04e5482009-12-15 16:46:29 -08001366
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001367err_dealloc_cmap:
1368 fb_dealloc_cmap(&da8xx_fb_info->cmap);
1369
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001370err_release_pl_mem:
1371 dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base,
1372 par->p_palette_base);
1373
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001374err_release_fb_mem:
Martin Ambrose1f9c3e12010-05-24 14:34:01 -07001375 dma_free_coherent(NULL, par->vram_size, par->vram_virt, par->vram_phys);
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001376
1377err_release_fb:
1378 framebuffer_release(da8xx_fb_info);
1379
1380err_clk_disable:
1381 clk_disable(fb_clk);
1382
1383err_clk_put:
1384 clk_put(fb_clk);
1385
1386err_ioremap:
1387 iounmap((void __iomem *)da8xx_fb_reg_base);
1388
1389err_request_mem:
1390 release_mem_region(lcdc_regs->start, len);
1391
1392 return ret;
1393}
1394
1395#ifdef CONFIG_PM
1396static int fb_suspend(struct platform_device *dev, pm_message_t state)
1397{
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001398 struct fb_info *info = platform_get_drvdata(dev);
1399 struct da8xx_fb_par *par = info->par;
1400
Torben Hohnac751ef2011-01-25 15:07:35 -08001401 console_lock();
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001402 if (par->panel_power_ctrl)
1403 par->panel_power_ctrl(0);
1404
1405 fb_set_suspend(info, 1);
1406 lcd_disable_raster();
1407 clk_disable(par->lcdc_clk);
Torben Hohnac751ef2011-01-25 15:07:35 -08001408 console_unlock();
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001409
1410 return 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001411}
1412static int fb_resume(struct platform_device *dev)
1413{
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001414 struct fb_info *info = platform_get_drvdata(dev);
1415 struct da8xx_fb_par *par = info->par;
1416
Torben Hohnac751ef2011-01-25 15:07:35 -08001417 console_lock();
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001418 if (par->panel_power_ctrl)
1419 par->panel_power_ctrl(1);
1420
1421 clk_enable(par->lcdc_clk);
1422 lcd_enable_raster();
1423 fb_set_suspend(info, 0);
Torben Hohnac751ef2011-01-25 15:07:35 -08001424 console_unlock();
Chaithrika U S1d3c6c72009-12-15 16:46:39 -08001425
1426 return 0;
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001427}
1428#else
1429#define fb_suspend NULL
1430#define fb_resume NULL
1431#endif
1432
1433static struct platform_driver da8xx_fb_driver = {
1434 .probe = fb_probe,
axel lin1db41e02011-02-22 01:52:42 +00001435 .remove = __devexit_p(fb_remove),
Sudhakar Rajashekhara4ed824d2009-09-22 16:47:06 -07001436 .suspend = fb_suspend,
1437 .resume = fb_resume,
1438 .driver = {
1439 .name = DRIVER_NAME,
1440 .owner = THIS_MODULE,
1441 },
1442};
1443
1444static int __init da8xx_fb_init(void)
1445{
1446 return platform_driver_register(&da8xx_fb_driver);
1447}
1448
1449static void __exit da8xx_fb_cleanup(void)
1450{
1451 platform_driver_unregister(&da8xx_fb_driver);
1452}
1453
1454module_init(da8xx_fb_init);
1455module_exit(da8xx_fb_cleanup);
1456
1457MODULE_DESCRIPTION("Framebuffer driver for TI da8xx/omap-l1xx");
1458MODULE_AUTHOR("Texas Instruments");
1459MODULE_LICENSE("GPL");