2 * linux/drivers/video/omap2/dss/rfbi.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "RFBI"
25 #include <linux/kernel.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/export.h>
28 #include <linux/vmalloc.h>
29 #include <linux/clk.h>
31 #include <linux/delay.h>
32 #include <linux/kfifo.h>
33 #include <linux/ktime.h>
34 #include <linux/hrtimer.h>
35 #include <linux/seq_file.h>
36 #include <linux/semaphore.h>
37 #include <linux/platform_device.h>
38 #include <linux/pm_runtime.h>
39 #include <linux/component.h>
41 #include <video/omapdss.h>
44 struct rfbi_reg
{ u16 idx
; };
46 #define RFBI_REG(idx) ((const struct rfbi_reg) { idx })
48 #define RFBI_REVISION RFBI_REG(0x0000)
49 #define RFBI_SYSCONFIG RFBI_REG(0x0010)
50 #define RFBI_SYSSTATUS RFBI_REG(0x0014)
51 #define RFBI_CONTROL RFBI_REG(0x0040)
52 #define RFBI_PIXEL_CNT RFBI_REG(0x0044)
53 #define RFBI_LINE_NUMBER RFBI_REG(0x0048)
54 #define RFBI_CMD RFBI_REG(0x004c)
55 #define RFBI_PARAM RFBI_REG(0x0050)
56 #define RFBI_DATA RFBI_REG(0x0054)
57 #define RFBI_READ RFBI_REG(0x0058)
58 #define RFBI_STATUS RFBI_REG(0x005c)
60 #define RFBI_CONFIG(n) RFBI_REG(0x0060 + (n)*0x18)
61 #define RFBI_ONOFF_TIME(n) RFBI_REG(0x0064 + (n)*0x18)
62 #define RFBI_CYCLE_TIME(n) RFBI_REG(0x0068 + (n)*0x18)
63 #define RFBI_DATA_CYCLE1(n) RFBI_REG(0x006c + (n)*0x18)
64 #define RFBI_DATA_CYCLE2(n) RFBI_REG(0x0070 + (n)*0x18)
65 #define RFBI_DATA_CYCLE3(n) RFBI_REG(0x0074 + (n)*0x18)
67 #define RFBI_VSYNC_WIDTH RFBI_REG(0x0090)
68 #define RFBI_HSYNC_WIDTH RFBI_REG(0x0094)
70 #define REG_FLD_MOD(idx, val, start, end) \
71 rfbi_write_reg(idx, FLD_MOD(rfbi_read_reg(idx), val, start, end))
73 enum omap_rfbi_cycleformat
{
74 OMAP_DSS_RFBI_CYCLEFORMAT_1_1
= 0,
75 OMAP_DSS_RFBI_CYCLEFORMAT_2_1
= 1,
76 OMAP_DSS_RFBI_CYCLEFORMAT_3_1
= 2,
77 OMAP_DSS_RFBI_CYCLEFORMAT_3_2
= 3,
80 enum omap_rfbi_datatype
{
81 OMAP_DSS_RFBI_DATATYPE_12
= 0,
82 OMAP_DSS_RFBI_DATATYPE_16
= 1,
83 OMAP_DSS_RFBI_DATATYPE_18
= 2,
84 OMAP_DSS_RFBI_DATATYPE_24
= 3,
87 enum omap_rfbi_parallelmode
{
88 OMAP_DSS_RFBI_PARALLELMODE_8
= 0,
89 OMAP_DSS_RFBI_PARALLELMODE_9
= 1,
90 OMAP_DSS_RFBI_PARALLELMODE_12
= 2,
91 OMAP_DSS_RFBI_PARALLELMODE_16
= 3,
94 static int rfbi_convert_timings(struct rfbi_timings
*t
);
95 static void rfbi_get_clk_info(u32
*clk_period
, u32
*max_clk_div
);
98 struct platform_device
*pdev
;
101 unsigned long l4_khz
;
103 enum omap_rfbi_datatype datatype
;
104 enum omap_rfbi_parallelmode parallelmode
;
106 enum omap_rfbi_te_mode te_mode
;
109 void (*framedone_callback
)(void *data
);
110 void *framedone_callback_data
;
112 struct omap_dss_device
*dssdev
[2];
114 struct semaphore bus_lock
;
116 struct omap_video_timings timings
;
119 struct rfbi_timings intf_timings
;
121 struct omap_dss_device output
;
124 static inline void rfbi_write_reg(const struct rfbi_reg idx
, u32 val
)
126 __raw_writel(val
, rfbi
.base
+ idx
.idx
);
129 static inline u32
rfbi_read_reg(const struct rfbi_reg idx
)
131 return __raw_readl(rfbi
.base
+ idx
.idx
);
134 static int rfbi_runtime_get(void)
138 DSSDBG("rfbi_runtime_get\n");
140 r
= pm_runtime_get_sync(&rfbi
.pdev
->dev
);
142 return r
< 0 ? r
: 0;
145 static void rfbi_runtime_put(void)
149 DSSDBG("rfbi_runtime_put\n");
151 r
= pm_runtime_put_sync(&rfbi
.pdev
->dev
);
152 WARN_ON(r
< 0 && r
!= -ENOSYS
);
155 static void rfbi_bus_lock(void)
157 down(&rfbi
.bus_lock
);
160 static void rfbi_bus_unlock(void)
165 static void rfbi_write_command(const void *buf
, u32 len
)
167 switch (rfbi
.parallelmode
) {
168 case OMAP_DSS_RFBI_PARALLELMODE_8
:
172 rfbi_write_reg(RFBI_CMD
, *b
++);
176 case OMAP_DSS_RFBI_PARALLELMODE_16
:
180 for (; len
; len
-= 2)
181 rfbi_write_reg(RFBI_CMD
, *w
++);
185 case OMAP_DSS_RFBI_PARALLELMODE_9
:
186 case OMAP_DSS_RFBI_PARALLELMODE_12
:
192 static void rfbi_read_data(void *buf
, u32 len
)
194 switch (rfbi
.parallelmode
) {
195 case OMAP_DSS_RFBI_PARALLELMODE_8
:
199 rfbi_write_reg(RFBI_READ
, 0);
200 *b
++ = rfbi_read_reg(RFBI_READ
);
205 case OMAP_DSS_RFBI_PARALLELMODE_16
:
209 for (; len
; len
-= 2) {
210 rfbi_write_reg(RFBI_READ
, 0);
211 *w
++ = rfbi_read_reg(RFBI_READ
);
216 case OMAP_DSS_RFBI_PARALLELMODE_9
:
217 case OMAP_DSS_RFBI_PARALLELMODE_12
:
223 static void rfbi_write_data(const void *buf
, u32 len
)
225 switch (rfbi
.parallelmode
) {
226 case OMAP_DSS_RFBI_PARALLELMODE_8
:
230 rfbi_write_reg(RFBI_PARAM
, *b
++);
234 case OMAP_DSS_RFBI_PARALLELMODE_16
:
238 for (; len
; len
-= 2)
239 rfbi_write_reg(RFBI_PARAM
, *w
++);
243 case OMAP_DSS_RFBI_PARALLELMODE_9
:
244 case OMAP_DSS_RFBI_PARALLELMODE_12
:
251 static void rfbi_write_pixels(const void __iomem
*buf
, int scr_width
,
255 int start_offset
= scr_width
* y
+ x
;
256 int horiz_offset
= scr_width
- w
;
259 if (rfbi
.datatype
== OMAP_DSS_RFBI_DATATYPE_16
&&
260 rfbi
.parallelmode
== OMAP_DSS_RFBI_PARALLELMODE_8
) {
261 const u16 __iomem
*pd
= buf
;
265 for (i
= 0; i
< w
; ++i
) {
266 const u8 __iomem
*b
= (const u8 __iomem
*)pd
;
267 rfbi_write_reg(RFBI_PARAM
, __raw_readb(b
+1));
268 rfbi_write_reg(RFBI_PARAM
, __raw_readb(b
+0));
273 } else if (rfbi
.datatype
== OMAP_DSS_RFBI_DATATYPE_24
&&
274 rfbi
.parallelmode
== OMAP_DSS_RFBI_PARALLELMODE_8
) {
275 const u32 __iomem
*pd
= buf
;
279 for (i
= 0; i
< w
; ++i
) {
280 const u8 __iomem
*b
= (const u8 __iomem
*)pd
;
281 rfbi_write_reg(RFBI_PARAM
, __raw_readb(b
+2));
282 rfbi_write_reg(RFBI_PARAM
, __raw_readb(b
+1));
283 rfbi_write_reg(RFBI_PARAM
, __raw_readb(b
+0));
288 } else if (rfbi
.datatype
== OMAP_DSS_RFBI_DATATYPE_16
&&
289 rfbi
.parallelmode
== OMAP_DSS_RFBI_PARALLELMODE_16
) {
290 const u16 __iomem
*pd
= buf
;
294 for (i
= 0; i
< w
; ++i
) {
295 rfbi_write_reg(RFBI_PARAM
, __raw_readw(pd
));
305 static int rfbi_transfer_area(struct omap_dss_device
*dssdev
,
306 void (*callback
)(void *data
), void *data
)
310 struct omap_overlay_manager
*mgr
= rfbi
.output
.manager
;
311 u16 width
= rfbi
.timings
.x_res
;
312 u16 height
= rfbi
.timings
.y_res
;
314 /*BUG_ON(callback == 0);*/
315 BUG_ON(rfbi
.framedone_callback
!= NULL
);
317 DSSDBG("rfbi_transfer_area %dx%d\n", width
, height
);
319 dss_mgr_set_timings(mgr
, &rfbi
.timings
);
321 r
= dss_mgr_enable(mgr
);
325 rfbi
.framedone_callback
= callback
;
326 rfbi
.framedone_callback_data
= data
;
328 rfbi_write_reg(RFBI_PIXEL_CNT
, width
* height
);
330 l
= rfbi_read_reg(RFBI_CONTROL
);
331 l
= FLD_MOD(l
, 1, 0, 0); /* enable */
332 if (!rfbi
.te_enabled
)
333 l
= FLD_MOD(l
, 1, 4, 4); /* ITE */
335 rfbi_write_reg(RFBI_CONTROL
, l
);
340 static void framedone_callback(void *data
)
342 void (*callback
)(void *data
);
344 DSSDBG("FRAMEDONE\n");
346 REG_FLD_MOD(RFBI_CONTROL
, 0, 0, 0);
348 callback
= rfbi
.framedone_callback
;
349 rfbi
.framedone_callback
= NULL
;
351 if (callback
!= NULL
)
352 callback(rfbi
.framedone_callback_data
);
356 static void rfbi_print_timings(void)
361 l
= rfbi_read_reg(RFBI_CONFIG(0));
362 time
= 1000000000 / rfbi
.l4_khz
;
366 DSSDBG("Tick time %u ps\n", time
);
367 l
= rfbi_read_reg(RFBI_ONOFF_TIME(0));
368 DSSDBG("CSONTIME %d, CSOFFTIME %d, WEONTIME %d, WEOFFTIME %d, "
369 "REONTIME %d, REOFFTIME %d\n",
370 l
& 0x0f, (l
>> 4) & 0x3f, (l
>> 10) & 0x0f, (l
>> 14) & 0x3f,
371 (l
>> 20) & 0x0f, (l
>> 24) & 0x3f);
373 l
= rfbi_read_reg(RFBI_CYCLE_TIME(0));
374 DSSDBG("WECYCLETIME %d, RECYCLETIME %d, CSPULSEWIDTH %d, "
376 (l
& 0x3f), (l
>> 6) & 0x3f, (l
>> 12) & 0x3f,
380 static void rfbi_print_timings(void) {}
386 static u32 extif_clk_period
;
388 static inline unsigned long round_to_extif_ticks(unsigned long ps
, int div
)
390 int bus_tick
= extif_clk_period
* div
;
391 return (ps
+ bus_tick
- 1) / bus_tick
* bus_tick
;
394 static int calc_reg_timing(struct rfbi_timings
*t
, int div
)
398 t
->cs_on_time
= round_to_extif_ticks(t
->cs_on_time
, div
);
400 t
->we_on_time
= round_to_extif_ticks(t
->we_on_time
, div
);
401 t
->we_off_time
= round_to_extif_ticks(t
->we_off_time
, div
);
402 t
->we_cycle_time
= round_to_extif_ticks(t
->we_cycle_time
, div
);
404 t
->re_on_time
= round_to_extif_ticks(t
->re_on_time
, div
);
405 t
->re_off_time
= round_to_extif_ticks(t
->re_off_time
, div
);
406 t
->re_cycle_time
= round_to_extif_ticks(t
->re_cycle_time
, div
);
408 t
->access_time
= round_to_extif_ticks(t
->access_time
, div
);
409 t
->cs_off_time
= round_to_extif_ticks(t
->cs_off_time
, div
);
410 t
->cs_pulse_width
= round_to_extif_ticks(t
->cs_pulse_width
, div
);
412 DSSDBG("[reg]cson %d csoff %d reon %d reoff %d\n",
413 t
->cs_on_time
, t
->cs_off_time
, t
->re_on_time
, t
->re_off_time
);
414 DSSDBG("[reg]weon %d weoff %d recyc %d wecyc %d\n",
415 t
->we_on_time
, t
->we_off_time
, t
->re_cycle_time
,
417 DSSDBG("[reg]rdaccess %d cspulse %d\n",
418 t
->access_time
, t
->cs_pulse_width
);
420 return rfbi_convert_timings(t
);
423 static int calc_extif_timings(struct rfbi_timings
*t
)
428 rfbi_get_clk_info(&extif_clk_period
, &max_clk_div
);
429 for (div
= 1; div
<= max_clk_div
; div
++) {
430 if (calc_reg_timing(t
, div
) == 0)
434 if (div
<= max_clk_div
)
437 DSSERR("can't setup timings\n");
442 static void rfbi_set_timings(int rfbi_module
, struct rfbi_timings
*t
)
447 r
= calc_extif_timings(t
);
449 DSSERR("Failed to calc timings\n");
452 BUG_ON(!t
->converted
);
454 rfbi_write_reg(RFBI_ONOFF_TIME(rfbi_module
), t
->tim
[0]);
455 rfbi_write_reg(RFBI_CYCLE_TIME(rfbi_module
), t
->tim
[1]);
457 /* TIMEGRANULARITY */
458 REG_FLD_MOD(RFBI_CONFIG(rfbi_module
),
459 (t
->tim
[2] ? 1 : 0), 4, 4);
461 rfbi_print_timings();
464 static int ps_to_rfbi_ticks(int time
, int div
)
466 unsigned long tick_ps
;
469 /* Calculate in picosecs to yield more exact results */
470 tick_ps
= 1000000000 / (rfbi
.l4_khz
) * div
;
472 ret
= (time
+ tick_ps
- 1) / tick_ps
;
477 static void rfbi_get_clk_info(u32
*clk_period
, u32
*max_clk_div
)
479 *clk_period
= 1000000000 / rfbi
.l4_khz
;
483 static int rfbi_convert_timings(struct rfbi_timings
*t
)
486 int reon
, reoff
, weon
, weoff
, cson
, csoff
, cs_pulse
;
487 int actim
, recyc
, wecyc
;
488 int div
= t
->clk_div
;
490 if (div
<= 0 || div
> 2)
493 /* Make sure that after conversion it still holds that:
494 * weoff > weon, reoff > reon, recyc >= reoff, wecyc >= weoff,
495 * csoff > cson, csoff >= max(weoff, reoff), actim > reon
497 weon
= ps_to_rfbi_ticks(t
->we_on_time
, div
);
498 weoff
= ps_to_rfbi_ticks(t
->we_off_time
, div
);
506 reon
= ps_to_rfbi_ticks(t
->re_on_time
, div
);
507 reoff
= ps_to_rfbi_ticks(t
->re_off_time
, div
);
515 cson
= ps_to_rfbi_ticks(t
->cs_on_time
, div
);
516 csoff
= ps_to_rfbi_ticks(t
->cs_off_time
, div
);
519 if (csoff
< max(weoff
, reoff
))
520 csoff
= max(weoff
, reoff
);
535 actim
= ps_to_rfbi_ticks(t
->access_time
, div
);
541 wecyc
= ps_to_rfbi_ticks(t
->we_cycle_time
, div
);
547 recyc
= ps_to_rfbi_ticks(t
->re_cycle_time
, div
);
553 cs_pulse
= ps_to_rfbi_ticks(t
->cs_pulse_width
, div
);
571 /* xxx FIX module selection missing */
572 static int rfbi_setup_te(enum omap_rfbi_te_mode mode
,
573 unsigned hs_pulse_time
, unsigned vs_pulse_time
,
574 int hs_pol_inv
, int vs_pol_inv
, int extif_div
)
580 hs
= ps_to_rfbi_ticks(hs_pulse_time
, 1);
581 vs
= ps_to_rfbi_ticks(vs_pulse_time
, 1);
584 if (mode
== OMAP_DSS_RFBI_TE_MODE_2
)
586 else /* OMAP_DSS_RFBI_TE_MODE_1 */
593 DSSDBG("setup_te: mode %d hs %d vs %d hs_inv %d vs_inv %d\n",
594 mode
, hs
, vs
, hs_pol_inv
, vs_pol_inv
);
596 rfbi_write_reg(RFBI_HSYNC_WIDTH
, hs
);
597 rfbi_write_reg(RFBI_VSYNC_WIDTH
, vs
);
599 l
= rfbi_read_reg(RFBI_CONFIG(0));
612 /* xxx FIX module selection missing */
613 static int rfbi_enable_te(bool enable
, unsigned line
)
617 DSSDBG("te %d line %d mode %d\n", enable
, line
, rfbi
.te_mode
);
618 if (line
> (1 << 11) - 1)
621 l
= rfbi_read_reg(RFBI_CONFIG(0));
625 l
|= rfbi
.te_mode
<< 2;
628 rfbi_write_reg(RFBI_CONFIG(0), l
);
629 rfbi_write_reg(RFBI_LINE_NUMBER
, line
);
634 static int rfbi_configure_bus(int rfbi_module
, int bpp
, int lines
)
637 int cycle1
= 0, cycle2
= 0, cycle3
= 0;
638 enum omap_rfbi_cycleformat cycleformat
;
639 enum omap_rfbi_datatype datatype
;
640 enum omap_rfbi_parallelmode parallelmode
;
644 datatype
= OMAP_DSS_RFBI_DATATYPE_12
;
647 datatype
= OMAP_DSS_RFBI_DATATYPE_16
;
650 datatype
= OMAP_DSS_RFBI_DATATYPE_18
;
653 datatype
= OMAP_DSS_RFBI_DATATYPE_24
;
659 rfbi
.datatype
= datatype
;
663 parallelmode
= OMAP_DSS_RFBI_PARALLELMODE_8
;
666 parallelmode
= OMAP_DSS_RFBI_PARALLELMODE_9
;
669 parallelmode
= OMAP_DSS_RFBI_PARALLELMODE_12
;
672 parallelmode
= OMAP_DSS_RFBI_PARALLELMODE_16
;
678 rfbi
.parallelmode
= parallelmode
;
680 if ((bpp
% lines
) == 0) {
681 switch (bpp
/ lines
) {
683 cycleformat
= OMAP_DSS_RFBI_CYCLEFORMAT_1_1
;
686 cycleformat
= OMAP_DSS_RFBI_CYCLEFORMAT_2_1
;
689 cycleformat
= OMAP_DSS_RFBI_CYCLEFORMAT_3_1
;
695 } else if ((2 * bpp
% lines
) == 0) {
696 if ((2 * bpp
/ lines
) == 3)
697 cycleformat
= OMAP_DSS_RFBI_CYCLEFORMAT_3_2
;
707 switch (cycleformat
) {
708 case OMAP_DSS_RFBI_CYCLEFORMAT_1_1
:
712 case OMAP_DSS_RFBI_CYCLEFORMAT_2_1
:
717 case OMAP_DSS_RFBI_CYCLEFORMAT_3_1
:
723 case OMAP_DSS_RFBI_CYCLEFORMAT_3_2
:
725 cycle2
= (lines
/ 2) | ((lines
/ 2) << 16);
726 cycle3
= (lines
<< 16);
730 REG_FLD_MOD(RFBI_CONTROL
, 0, 3, 2); /* clear CS */
733 l
|= FLD_VAL(parallelmode
, 1, 0);
734 l
|= FLD_VAL(0, 3, 2); /* TRIGGERMODE: ITE */
735 l
|= FLD_VAL(0, 4, 4); /* TIMEGRANULARITY */
736 l
|= FLD_VAL(datatype
, 6, 5);
737 /* l |= FLD_VAL(2, 8, 7); */ /* L4FORMAT, 2pix/L4 */
738 l
|= FLD_VAL(0, 8, 7); /* L4FORMAT, 1pix/L4 */
739 l
|= FLD_VAL(cycleformat
, 10, 9);
740 l
|= FLD_VAL(0, 12, 11); /* UNUSEDBITS */
741 l
|= FLD_VAL(0, 16, 16); /* A0POLARITY */
742 l
|= FLD_VAL(0, 17, 17); /* REPOLARITY */
743 l
|= FLD_VAL(0, 18, 18); /* WEPOLARITY */
744 l
|= FLD_VAL(0, 19, 19); /* CSPOLARITY */
745 l
|= FLD_VAL(1, 20, 20); /* TE_VSYNC_POLARITY */
746 l
|= FLD_VAL(1, 21, 21); /* HSYNCPOLARITY */
747 rfbi_write_reg(RFBI_CONFIG(rfbi_module
), l
);
749 rfbi_write_reg(RFBI_DATA_CYCLE1(rfbi_module
), cycle1
);
750 rfbi_write_reg(RFBI_DATA_CYCLE2(rfbi_module
), cycle2
);
751 rfbi_write_reg(RFBI_DATA_CYCLE3(rfbi_module
), cycle3
);
754 l
= rfbi_read_reg(RFBI_CONTROL
);
755 l
= FLD_MOD(l
, rfbi_module
+1, 3, 2); /* Select CSx */
756 l
= FLD_MOD(l
, 0, 1, 1); /* clear bypass */
757 rfbi_write_reg(RFBI_CONTROL
, l
);
760 DSSDBG("RFBI config: bpp %d, lines %d, cycles: 0x%x 0x%x 0x%x\n",
761 bpp
, lines
, cycle1
, cycle2
, cycle3
);
766 static int rfbi_configure(struct omap_dss_device
*dssdev
)
768 return rfbi_configure_bus(dssdev
->phy
.rfbi
.channel
, rfbi
.pixel_size
,
772 static int rfbi_update(struct omap_dss_device
*dssdev
, void (*callback
)(void *),
775 return rfbi_transfer_area(dssdev
, callback
, data
);
778 static void rfbi_set_size(struct omap_dss_device
*dssdev
, u16 w
, u16 h
)
780 rfbi
.timings
.x_res
= w
;
781 rfbi
.timings
.y_res
= h
;
784 static void rfbi_set_pixel_size(struct omap_dss_device
*dssdev
, int pixel_size
)
786 rfbi
.pixel_size
= pixel_size
;
789 static void rfbi_set_data_lines(struct omap_dss_device
*dssdev
, int data_lines
)
791 rfbi
.data_lines
= data_lines
;
794 static void rfbi_set_interface_timings(struct omap_dss_device
*dssdev
,
795 struct rfbi_timings
*timings
)
797 rfbi
.intf_timings
= *timings
;
800 static void rfbi_dump_regs(struct seq_file
*s
)
802 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, rfbi_read_reg(r))
804 if (rfbi_runtime_get())
807 DUMPREG(RFBI_REVISION
);
808 DUMPREG(RFBI_SYSCONFIG
);
809 DUMPREG(RFBI_SYSSTATUS
);
810 DUMPREG(RFBI_CONTROL
);
811 DUMPREG(RFBI_PIXEL_CNT
);
812 DUMPREG(RFBI_LINE_NUMBER
);
817 DUMPREG(RFBI_STATUS
);
819 DUMPREG(RFBI_CONFIG(0));
820 DUMPREG(RFBI_ONOFF_TIME(0));
821 DUMPREG(RFBI_CYCLE_TIME(0));
822 DUMPREG(RFBI_DATA_CYCLE1(0));
823 DUMPREG(RFBI_DATA_CYCLE2(0));
824 DUMPREG(RFBI_DATA_CYCLE3(0));
826 DUMPREG(RFBI_CONFIG(1));
827 DUMPREG(RFBI_ONOFF_TIME(1));
828 DUMPREG(RFBI_CYCLE_TIME(1));
829 DUMPREG(RFBI_DATA_CYCLE1(1));
830 DUMPREG(RFBI_DATA_CYCLE2(1));
831 DUMPREG(RFBI_DATA_CYCLE3(1));
833 DUMPREG(RFBI_VSYNC_WIDTH
);
834 DUMPREG(RFBI_HSYNC_WIDTH
);
840 static void rfbi_config_lcd_manager(struct omap_dss_device
*dssdev
)
842 struct omap_overlay_manager
*mgr
= rfbi
.output
.manager
;
843 struct dss_lcd_mgr_config mgr_config
;
845 mgr_config
.io_pad_mode
= DSS_IO_PAD_MODE_RFBI
;
847 mgr_config
.stallmode
= true;
848 /* Do we need fifohandcheck for RFBI? */
849 mgr_config
.fifohandcheck
= false;
851 mgr_config
.video_port_width
= rfbi
.pixel_size
;
852 mgr_config
.lcden_sig_polarity
= 0;
854 dss_mgr_set_lcd_config(mgr
, &mgr_config
);
857 * Set rfbi.timings with default values, the x_res and y_res fields
858 * are expected to be already configured by the panel driver via
859 * omapdss_rfbi_set_size()
861 rfbi
.timings
.hsw
= 1;
862 rfbi
.timings
.hfp
= 1;
863 rfbi
.timings
.hbp
= 1;
864 rfbi
.timings
.vsw
= 1;
865 rfbi
.timings
.vfp
= 0;
866 rfbi
.timings
.vbp
= 0;
868 rfbi
.timings
.interlace
= false;
869 rfbi
.timings
.hsync_level
= OMAPDSS_SIG_ACTIVE_HIGH
;
870 rfbi
.timings
.vsync_level
= OMAPDSS_SIG_ACTIVE_HIGH
;
871 rfbi
.timings
.data_pclk_edge
= OMAPDSS_DRIVE_SIG_RISING_EDGE
;
872 rfbi
.timings
.de_level
= OMAPDSS_SIG_ACTIVE_HIGH
;
873 rfbi
.timings
.sync_pclk_edge
= OMAPDSS_DRIVE_SIG_FALLING_EDGE
;
875 dss_mgr_set_timings(mgr
, &rfbi
.timings
);
878 static int rfbi_display_enable(struct omap_dss_device
*dssdev
)
880 struct omap_dss_device
*out
= &rfbi
.output
;
883 if (out
->manager
== NULL
) {
884 DSSERR("failed to enable display: no output/manager\n");
888 r
= rfbi_runtime_get();
892 r
= dss_mgr_register_framedone_handler(out
->manager
,
893 framedone_callback
, NULL
);
895 DSSERR("can't get FRAMEDONE irq\n");
899 rfbi_config_lcd_manager(dssdev
);
901 rfbi_configure_bus(dssdev
->phy
.rfbi
.channel
, rfbi
.pixel_size
,
904 rfbi_set_timings(dssdev
->phy
.rfbi
.channel
, &rfbi
.intf_timings
);
912 static void rfbi_display_disable(struct omap_dss_device
*dssdev
)
914 struct omap_dss_device
*out
= &rfbi
.output
;
916 dss_mgr_unregister_framedone_handler(out
->manager
,
917 framedone_callback
, NULL
);
922 static int rfbi_init_display(struct omap_dss_device
*dssdev
)
924 rfbi
.dssdev
[dssdev
->phy
.rfbi
.channel
] = dssdev
;
928 static void rfbi_init_output(struct platform_device
*pdev
)
930 struct omap_dss_device
*out
= &rfbi
.output
;
932 out
->dev
= &pdev
->dev
;
933 out
->id
= OMAP_DSS_OUTPUT_DBI
;
934 out
->output_type
= OMAP_DISPLAY_TYPE_DBI
;
935 out
->name
= "rfbi.0";
936 out
->dispc_channel
= OMAP_DSS_CHANNEL_LCD
;
937 out
->owner
= THIS_MODULE
;
939 omapdss_register_output(out
);
942 static void rfbi_uninit_output(struct platform_device
*pdev
)
944 struct omap_dss_device
*out
= &rfbi
.output
;
946 omapdss_unregister_output(out
);
949 /* RFBI HW IP initialisation */
950 static int rfbi_bind(struct device
*dev
, struct device
*master
, void *data
)
952 struct platform_device
*pdev
= to_platform_device(dev
);
954 struct resource
*rfbi_mem
;
960 sema_init(&rfbi
.bus_lock
, 1);
962 rfbi_mem
= platform_get_resource(rfbi
.pdev
, IORESOURCE_MEM
, 0);
964 DSSERR("can't get IORESOURCE_MEM RFBI\n");
968 rfbi
.base
= devm_ioremap(&pdev
->dev
, rfbi_mem
->start
,
969 resource_size(rfbi_mem
));
971 DSSERR("can't ioremap RFBI\n");
975 clk
= clk_get(&pdev
->dev
, "ick");
977 DSSERR("can't get ick\n");
981 rfbi
.l4_khz
= clk_get_rate(clk
) / 1000;
985 pm_runtime_enable(&pdev
->dev
);
987 r
= rfbi_runtime_get();
989 goto err_runtime_get
;
993 rev
= rfbi_read_reg(RFBI_REVISION
);
994 dev_dbg(&pdev
->dev
, "OMAP RFBI rev %d.%d\n",
995 FLD_GET(rev
, 7, 4), FLD_GET(rev
, 3, 0));
999 dss_debugfs_create_file("rfbi", rfbi_dump_regs
);
1001 rfbi_init_output(pdev
);
1006 pm_runtime_disable(&pdev
->dev
);
1010 static void rfbi_unbind(struct device
*dev
, struct device
*master
, void *data
)
1012 struct platform_device
*pdev
= to_platform_device(dev
);
1014 rfbi_uninit_output(pdev
);
1016 pm_runtime_disable(&pdev
->dev
);
1021 static const struct component_ops rfbi_component_ops
= {
1023 .unbind
= rfbi_unbind
,
1026 static int rfbi_probe(struct platform_device
*pdev
)
1028 return component_add(&pdev
->dev
, &rfbi_component_ops
);
1031 static int rfbi_remove(struct platform_device
*pdev
)
1033 component_del(&pdev
->dev
, &rfbi_component_ops
);
1037 static int rfbi_runtime_suspend(struct device
*dev
)
1039 dispc_runtime_put();
1044 static int rfbi_runtime_resume(struct device
*dev
)
1048 r
= dispc_runtime_get();
1055 static const struct dev_pm_ops rfbi_pm_ops
= {
1056 .runtime_suspend
= rfbi_runtime_suspend
,
1057 .runtime_resume
= rfbi_runtime_resume
,
1060 static struct platform_driver omap_rfbihw_driver
= {
1061 .probe
= rfbi_probe
,
1062 .remove
= rfbi_remove
,
1064 .name
= "omapdss_rfbi",
1066 .suppress_bind_attrs
= true,
1070 int __init
rfbi_init_platform_driver(void)
1072 return platform_driver_register(&omap_rfbihw_driver
);
1075 void rfbi_uninit_platform_driver(void)
1077 platform_driver_unregister(&omap_rfbihw_driver
);