1 #include <linux/device.h>
2 #include <linux/dma-mapping.h>
3 #include <linux/amba/bus.h>
4 #include <linux/amba/clcd.h>
5 #include <linux/platform_data/video-clcd-versatile.h>
7 #include <linux/of_graph.h>
8 #include <linux/regmap.h>
9 #include <linux/mfd/syscon.h>
10 #include <linux/bitops.h>
11 #include "amba-clcd-versatile.h"
13 static struct clcd_panel vga
= {
27 .vmode
= FB_VMODE_NONINTERLACED
,
31 .tim2
= TIM2_BCD
| TIM2_IPC
,
32 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
33 .caps
= CLCD_CAP_5551
| CLCD_CAP_565
| CLCD_CAP_888
,
37 static struct clcd_panel xvga
= {
51 .vmode
= FB_VMODE_NONINTERLACED
,
55 .tim2
= TIM2_BCD
| TIM2_IPC
,
56 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
57 .caps
= CLCD_CAP_5551
| CLCD_CAP_565
| CLCD_CAP_888
,
61 /* Sanyo TM38QV67A02A - 3.8 inch QVGA (320x240) Color TFT */
62 static struct clcd_panel sanyo_tm38qv67a02a
= {
64 .name
= "Sanyo TM38QV67A02A",
76 .vmode
= FB_VMODE_NONINTERLACED
,
81 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
82 .caps
= CLCD_CAP_5551
,
86 static struct clcd_panel sanyo_2_5_in
= {
88 .name
= "Sanyo QVGA Portrait",
99 .sync
= FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
100 .vmode
= FB_VMODE_NONINTERLACED
,
104 .tim2
= TIM2_IVS
| TIM2_IHS
| TIM2_IPC
,
105 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
106 .caps
= CLCD_CAP_5551
,
110 /* Epson L2F50113T00 - 2.2 inch 176x220 Color TFT */
111 static struct clcd_panel epson_l2f50113t00
= {
113 .name
= "Epson L2F50113T00",
125 .vmode
= FB_VMODE_NONINTERLACED
,
129 .tim2
= TIM2_BCD
| TIM2_IPC
,
130 .cntl
= CNTL_LCDTFT
| CNTL_BGR
| CNTL_LCDVCOMP(1),
131 .caps
= CLCD_CAP_5551
,
135 static struct clcd_panel
*panels
[] = {
143 struct clcd_panel
*versatile_clcd_get_panel(const char *name
)
147 for (i
= 0; i
< ARRAY_SIZE(panels
); i
++)
148 if (strcmp(panels
[i
]->mode
.name
, name
) == 0)
151 if (i
< ARRAY_SIZE(panels
))
154 pr_err("CLCD: couldn't get parameters for panel %s\n", name
);
159 int versatile_clcd_setup_dma(struct clcd_fb
*fb
, unsigned long framesize
)
163 fb
->fb
.screen_base
= dma_alloc_wc(&fb
->dev
->dev
, framesize
, &dma
,
165 if (!fb
->fb
.screen_base
) {
166 pr_err("CLCD: unable to map framebuffer\n");
170 fb
->fb
.fix
.smem_start
= dma
;
171 fb
->fb
.fix
.smem_len
= framesize
;
176 int versatile_clcd_mmap_dma(struct clcd_fb
*fb
, struct vm_area_struct
*vma
)
178 return dma_mmap_wc(&fb
->dev
->dev
, vma
, fb
->fb
.screen_base
,
179 fb
->fb
.fix
.smem_start
, fb
->fb
.fix
.smem_len
);
182 void versatile_clcd_remove_dma(struct clcd_fb
*fb
)
184 dma_free_wc(&fb
->dev
->dev
, fb
->fb
.fix
.smem_len
, fb
->fb
.screen_base
,
185 fb
->fb
.fix
.smem_start
);
190 static struct regmap
*versatile_syscon_map
;
191 static struct regmap
*versatile_ib2_map
;
194 * We detect the different syscon types from the compatible strings.
196 enum versatile_clcd
{
200 REALVIEW_CLCD_PB1176
,
201 REALVIEW_CLCD_PB11MP
,
206 static const struct of_device_id versatile_clcd_of_match
[] = {
208 .compatible
= "arm,core-module-integrator",
209 .data
= (void *)INTEGRATOR_CLCD_CM
,
212 .compatible
= "arm,versatile-sysreg",
213 .data
= (void *)VERSATILE_CLCD
,
216 .compatible
= "arm,realview-eb-syscon",
217 .data
= (void *)REALVIEW_CLCD_EB
,
220 .compatible
= "arm,realview-pb1176-syscon",
221 .data
= (void *)REALVIEW_CLCD_PB1176
,
224 .compatible
= "arm,realview-pb11mp-syscon",
225 .data
= (void *)REALVIEW_CLCD_PB11MP
,
228 .compatible
= "arm,realview-pba8-syscon",
229 .data
= (void *)REALVIEW_CLCD_PBA8
,
232 .compatible
= "arm,realview-pbx-syscon",
233 .data
= (void *)REALVIEW_CLCD_PBX
,
239 * Core module CLCD control on the Integrator/CP, bits
240 * 8 thru 19 of the CM_CONTROL register controls a bunch
243 #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
244 #define INTEGRATOR_CLCD_LCDBIASEN BIT(8)
245 #define INTEGRATOR_CLCD_LCDBIASUP BIT(9)
246 #define INTEGRATOR_CLCD_LCDBIASDN BIT(10)
247 /* Bits 11,12,13 controls the LCD type */
248 #define INTEGRATOR_CLCD_LCDMUX_MASK (BIT(11)|BIT(12)|BIT(13))
249 #define INTEGRATOR_CLCD_LCDMUX_LCD24 BIT(11)
250 #define INTEGRATOR_CLCD_LCDMUX_VGA565 BIT(12)
251 #define INTEGRATOR_CLCD_LCDMUX_SHARP (BIT(11)|BIT(12))
252 #define INTEGRATOR_CLCD_LCDMUX_VGA555 BIT(13)
253 #define INTEGRATOR_CLCD_LCDMUX_VGA24 (BIT(11)|BIT(12)|BIT(13))
254 #define INTEGRATOR_CLCD_LCD0_EN BIT(14)
255 #define INTEGRATOR_CLCD_LCD1_EN BIT(15)
256 /* R/L flip on Sharp */
257 #define INTEGRATOR_CLCD_LCD_STATIC1 BIT(16)
258 /* U/D flip on Sharp */
259 #define INTEGRATOR_CLCD_LCD_STATIC2 BIT(17)
260 /* No connection on Sharp */
261 #define INTEGRATOR_CLCD_LCD_STATIC BIT(18)
262 /* 0 = 24bit VGA, 1 = 18bit VGA */
263 #define INTEGRATOR_CLCD_LCD_N24BITEN BIT(19)
265 #define INTEGRATOR_CLCD_MASK (INTEGRATOR_CLCD_LCDBIASEN | \
266 INTEGRATOR_CLCD_LCDBIASUP | \
267 INTEGRATOR_CLCD_LCDBIASDN | \
268 INTEGRATOR_CLCD_LCDMUX_MASK | \
269 INTEGRATOR_CLCD_LCD0_EN | \
270 INTEGRATOR_CLCD_LCD1_EN | \
271 INTEGRATOR_CLCD_LCD_STATIC1 | \
272 INTEGRATOR_CLCD_LCD_STATIC2 | \
273 INTEGRATOR_CLCD_LCD_STATIC | \
274 INTEGRATOR_CLCD_LCD_N24BITEN)
276 static void integrator_clcd_enable(struct clcd_fb
*fb
)
278 struct fb_var_screeninfo
*var
= &fb
->fb
.var
;
281 dev_info(&fb
->dev
->dev
, "enable Integrator CLCD connectors\n");
283 /* FIXME: really needed? */
284 val
= INTEGRATOR_CLCD_LCD_STATIC1
| INTEGRATOR_CLCD_LCD_STATIC2
|
285 INTEGRATOR_CLCD_LCD0_EN
| INTEGRATOR_CLCD_LCD1_EN
;
286 if (var
->bits_per_pixel
<= 8 ||
287 (var
->bits_per_pixel
== 16 && var
->green
.length
== 5))
288 /* Pseudocolor, RGB555, BGR555 */
289 val
|= INTEGRATOR_CLCD_LCDMUX_VGA555
;
290 else if (fb
->fb
.var
.bits_per_pixel
<= 16)
291 /* truecolor RGB565 */
292 val
|= INTEGRATOR_CLCD_LCDMUX_VGA565
;
294 val
= 0; /* no idea for this, don't trust the docs */
296 regmap_update_bits(versatile_syscon_map
,
297 INTEGRATOR_HDR_CTRL_OFFSET
,
298 INTEGRATOR_CLCD_MASK
,
303 * This configuration register in the Versatile and RealView
304 * family is uniformly present but appears more and more
305 * unutilized starting with the RealView series.
307 #define SYS_CLCD 0x50
308 #define SYS_CLCD_MODE_MASK (BIT(0)|BIT(1))
309 #define SYS_CLCD_MODE_888 0
310 #define SYS_CLCD_MODE_5551 BIT(0)
311 #define SYS_CLCD_MODE_565_R_LSB BIT(1)
312 #define SYS_CLCD_MODE_565_B_LSB (BIT(0)|BIT(1))
313 #define SYS_CLCD_CONNECTOR_MASK (BIT(2)|BIT(3)|BIT(4)|BIT(5))
314 #define SYS_CLCD_NLCDIOON BIT(2)
315 #define SYS_CLCD_VDDPOSSWITCH BIT(3)
316 #define SYS_CLCD_PWR3V5SWITCH BIT(4)
317 #define SYS_CLCD_VDDNEGSWITCH BIT(5)
318 #define SYS_CLCD_TSNSS BIT(6) /* touchscreen enable */
319 #define SYS_CLCD_SSPEXP BIT(7) /* SSP expansion enable */
321 /* The Versatile can detect the connected panel type */
322 #define SYS_CLCD_CLCDID_MASK (BIT(8)|BIT(9)|BIT(10)|BIT(11)|BIT(12))
323 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
324 #define SYS_CLCD_ID_SHARP_8_4 (0x01 << 8)
325 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
326 #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
327 #define SYS_CLCD_ID_VGA (0x1f << 8)
329 #define SYS_CLCD_TSNDAV BIT(13) /* data ready from TS */
331 /* IB2 control register for the Versatile daughterboard */
332 #define IB2_CTRL 0x00
333 #define IB2_CTRL_LCD_SD BIT(1) /* 1 = shut down LCD */
334 #define IB2_CTRL_LCD_BL_ON BIT(0)
335 #define IB2_CTRL_LCD_MASK (BIT(0)|BIT(1))
337 static void versatile_clcd_disable(struct clcd_fb
*fb
)
339 dev_info(&fb
->dev
->dev
, "disable Versatile CLCD connectors\n");
340 regmap_update_bits(versatile_syscon_map
,
342 SYS_CLCD_CONNECTOR_MASK
,
345 /* If we're on an IB2 daughterboard, turn off display */
346 if (versatile_ib2_map
) {
347 dev_info(&fb
->dev
->dev
, "disable IB2 display\n");
348 regmap_update_bits(versatile_ib2_map
,
355 static void versatile_clcd_enable(struct clcd_fb
*fb
)
357 struct fb_var_screeninfo
*var
= &fb
->fb
.var
;
360 dev_info(&fb
->dev
->dev
, "enable Versatile CLCD connectors\n");
361 switch (var
->green
.length
) {
363 val
|= SYS_CLCD_MODE_5551
;
366 if (var
->red
.offset
== 0)
367 val
|= SYS_CLCD_MODE_565_R_LSB
;
369 val
|= SYS_CLCD_MODE_565_B_LSB
;
372 val
|= SYS_CLCD_MODE_888
;
377 regmap_update_bits(versatile_syscon_map
,
382 /* Then enable the display */
383 regmap_update_bits(versatile_syscon_map
,
385 SYS_CLCD_CONNECTOR_MASK
,
386 SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
);
388 /* If we're on an IB2 daughterboard, turn on display */
389 if (versatile_ib2_map
) {
390 dev_info(&fb
->dev
->dev
, "enable IB2 display\n");
391 regmap_update_bits(versatile_ib2_map
,
398 static void versatile_clcd_decode(struct clcd_fb
*fb
, struct clcd_regs
*regs
)
400 clcdfb_decode(fb
, regs
);
402 /* Always clear BGR for RGB565: we do the routing externally */
403 if (fb
->fb
.var
.green
.length
== 6)
404 regs
->cntl
&= ~CNTL_BGR
;
407 static void realview_clcd_disable(struct clcd_fb
*fb
)
409 dev_info(&fb
->dev
->dev
, "disable RealView CLCD connectors\n");
410 regmap_update_bits(versatile_syscon_map
,
412 SYS_CLCD_CONNECTOR_MASK
,
416 static void realview_clcd_enable(struct clcd_fb
*fb
)
418 dev_info(&fb
->dev
->dev
, "enable RealView CLCD connectors\n");
419 regmap_update_bits(versatile_syscon_map
,
421 SYS_CLCD_CONNECTOR_MASK
,
422 SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
);
425 struct versatile_panel
{
431 static const struct versatile_panel versatile_panels
[] = {
433 .id
= SYS_CLCD_ID_VGA
,
437 .id
= SYS_CLCD_ID_SANYO_3_8
,
438 .compatible
= "sanyo,tm38qv67a02a",
441 .id
= SYS_CLCD_ID_SHARP_8_4
,
442 .compatible
= "sharp,lq084v1dg21",
445 .id
= SYS_CLCD_ID_EPSON_2_2
,
446 .compatible
= "epson,l2f50113t00",
449 .id
= SYS_CLCD_ID_SANYO_2_5
,
450 .compatible
= "sanyo,alr252rgt",
455 static void versatile_panel_probe(struct device
*dev
, struct device_node
*panel
)
457 struct versatile_panel
const *vpanel
= NULL
;
463 * The Versatile CLCD has a panel auto-detection mechanism.
464 * We use this and look for the compatible panel in the
467 ret
= regmap_read(versatile_syscon_map
, SYS_CLCD
, &val
);
469 dev_err(dev
, "cannot read CLCD syscon register\n");
472 val
&= SYS_CLCD_CLCDID_MASK
;
474 /* First find corresponding panel information */
475 for (i
= 0; i
< ARRAY_SIZE(versatile_panels
); i
++) {
476 vpanel
= &versatile_panels
[i
];
478 if (val
== vpanel
->id
) {
479 dev_err(dev
, "autodetected panel \"%s\"\n",
484 if (i
== ARRAY_SIZE(versatile_panels
)) {
485 dev_err(dev
, "could not auto-detect panel\n");
489 if (!of_device_is_compatible(panel
, vpanel
->compatible
))
490 dev_err(dev
, "panel in DT is not compatible with the "
491 "auto-detected panel, continuing anyway\n");
494 * If we have a Sanyo 2.5" port
495 * that we're running on an IB2 and proceed to look for the
501 versatile_ib2_map
= syscon_regmap_lookup_by_compatible(
502 "arm,versatile-ib2-syscon");
503 if (IS_ERR(versatile_ib2_map
)) {
504 dev_err(dev
, "could not locate IB2 control register\n");
505 versatile_ib2_map
= NULL
;
510 int versatile_clcd_init_panel(struct clcd_fb
*fb
, struct device_node
*panel
)
512 const struct of_device_id
*clcd_id
;
513 enum versatile_clcd versatile_clcd_type
;
514 struct device_node
*np
;
516 struct device
*dev
= &fb
->dev
->dev
;
518 np
= of_find_matching_node_and_match(NULL
, versatile_clcd_of_match
,
521 /* Vexpress does not have this */
524 versatile_clcd_type
= (enum versatile_clcd
)clcd_id
->data
;
526 map
= syscon_node_to_regmap(np
);
528 dev_err(dev
, "no Versatile syscon regmap\n");
532 switch (versatile_clcd_type
) {
533 case INTEGRATOR_CLCD_CM
:
534 versatile_syscon_map
= map
;
535 fb
->board
->enable
= integrator_clcd_enable
;
536 /* Override the caps, we have only these */
537 fb
->board
->caps
= CLCD_CAP_5551
| CLCD_CAP_RGB565
|
539 dev_info(dev
, "set up callbacks for Integrator PL110\n");
542 versatile_syscon_map
= map
;
543 fb
->board
->enable
= versatile_clcd_enable
;
544 fb
->board
->disable
= versatile_clcd_disable
;
545 fb
->board
->decode
= versatile_clcd_decode
;
546 versatile_panel_probe(dev
, panel
);
547 dev_info(dev
, "set up callbacks for Versatile\n");
549 case REALVIEW_CLCD_EB
:
550 case REALVIEW_CLCD_PB1176
:
551 case REALVIEW_CLCD_PB11MP
:
552 case REALVIEW_CLCD_PBA8
:
553 case REALVIEW_CLCD_PBX
:
554 versatile_syscon_map
= map
;
555 fb
->board
->enable
= realview_clcd_enable
;
556 fb
->board
->disable
= realview_clcd_disable
;
557 dev_info(dev
, "set up callbacks for RealView PL111\n");
560 dev_info(dev
, "unknown Versatile system controller\n");
566 EXPORT_SYMBOL_GPL(versatile_clcd_init_panel
);