23 #define DSS_SUBSYS_NAME "RFBI"
25 #include <linux/kernel.h>
27 #include <linux/export.h>
34 #include <linux/hrtimer.h>
45 #define RFBI_REG(idx) ((const struct rfbi_reg) { idx })
47 #define RFBI_REVISION RFBI_REG(0x0000)
48 #define RFBI_SYSCONFIG RFBI_REG(0x0010)
49 #define RFBI_SYSSTATUS RFBI_REG(0x0014)
50 #define RFBI_CONTROL RFBI_REG(0x0040)
51 #define RFBI_PIXEL_CNT RFBI_REG(0x0044)
52 #define RFBI_LINE_NUMBER RFBI_REG(0x0048)
53 #define RFBI_CMD RFBI_REG(0x004c)
54 #define RFBI_PARAM RFBI_REG(0x0050)
55 #define RFBI_DATA RFBI_REG(0x0054)
56 #define RFBI_READ RFBI_REG(0x0058)
57 #define RFBI_STATUS RFBI_REG(0x005c)
59 #define RFBI_CONFIG(n) RFBI_REG(0x0060 + (n)*0x18)
60 #define RFBI_ONOFF_TIME(n) RFBI_REG(0x0064 + (n)*0x18)
61 #define RFBI_CYCLE_TIME(n) RFBI_REG(0x0068 + (n)*0x18)
62 #define RFBI_DATA_CYCLE1(n) RFBI_REG(0x006c + (n)*0x18)
63 #define RFBI_DATA_CYCLE2(n) RFBI_REG(0x0070 + (n)*0x18)
64 #define RFBI_DATA_CYCLE3(n) RFBI_REG(0x0074 + (n)*0x18)
66 #define RFBI_VSYNC_WIDTH RFBI_REG(0x0090)
67 #define RFBI_HSYNC_WIDTH RFBI_REG(0x0094)
69 #define REG_FLD_MOD(idx, val, start, end) \
70 rfbi_write_reg(idx, FLD_MOD(rfbi_read_reg(idx), val, start, end))
94 static void rfbi_get_clk_info(
u32 *clk_period,
u32 *max_clk_div);
133 static int rfbi_runtime_get(
void)
137 DSSDBG(
"rfbi_runtime_get\n");
139 r = pm_runtime_get_sync(&rfbi.pdev->dev);
141 return r < 0 ? r : 0;
144 static void rfbi_runtime_put(
void)
148 DSSDBG(
"rfbi_runtime_put\n");
150 r = pm_runtime_put_sync(&rfbi.pdev->dev);
156 down(&rfbi.bus_lock);
168 switch (rfbi.parallelmode) {
181 for (; len; len -= 2)
196 switch (rfbi.parallelmode) {
211 for (; len; len -= 2) {
228 switch (rfbi.parallelmode) {
241 for (; len; len -= 2)
260 int horiz_offset = scr_width -
w;
269 for (i = 0; i <
w; ++
i) {
283 for (i = 0; i <
w; ++
i) {
298 for (i = 0; i <
w; ++
i) {
322 DSSDBG(
"rfbi_transfer_area %dx%d\n", width, height);
331 rfbi.framedone_callback_data =
data;
337 if (!rfbi.te_enabled)
354 rfbi.framedone_callback =
NULL;
357 callback(rfbi.framedone_callback_data);
361 static void rfbi_print_timings(
void)
367 time = 1000000000 / rfbi.l4_khz;
371 DSSDBG(
"Tick time %u ps\n", time);
373 DSSDBG(
"CSONTIME %d, CSOFFTIME %d, WEONTIME %d, WEOFFTIME %d, "
374 "REONTIME %d, REOFFTIME %d\n",
375 l & 0x0f, (l >> 4) & 0x3f, (l >> 10) & 0x0f, (l >> 14) & 0x3f,
376 (l >> 20) & 0x0f, (l >> 24) & 0x3f);
379 DSSDBG(
"WECYCLETIME %d, RECYCLETIME %d, CSPULSEWIDTH %d, "
381 (l & 0x3f), (l >> 6) & 0x3f, (l >> 12) & 0x3f,
385 static void rfbi_print_timings(
void) {}
393 static inline unsigned long round_to_extif_ticks(
unsigned long ps,
int div)
395 int bus_tick = extif_clk_period *
div;
396 return (ps + bus_tick - 1) / bus_tick * bus_tick;
417 DSSDBG(
"[reg]cson %d csoff %d reon %d reoff %d\n",
419 DSSDBG(
"[reg]weon %d weoff %d recyc %d wecyc %d\n",
422 DSSDBG(
"[reg]rdaccess %d cspulse %d\n",
425 return rfbi_convert_timings(t);
433 rfbi_get_clk_info(&extif_clk_period, &max_clk_div);
434 for (div = 1; div <= max_clk_div; div++) {
435 if (calc_reg_timing(t, div) == 0)
439 if (div <= max_clk_div)
442 DSSERR(
"can't setup timings\n");
447 static void rfbi_set_timings(
int rfbi_module,
struct rfbi_timings *t)
452 r = calc_extif_timings(t);
454 DSSERR(
"Failed to calc timings\n");
464 (t->
tim[2] ? 1 : 0), 4, 4);
466 rfbi_print_timings();
469 static int ps_to_rfbi_ticks(
int time,
int div)
471 unsigned long tick_ps;
475 tick_ps = 1000000000 / (rfbi.l4_khz) * div;
477 ret = (time + tick_ps - 1) / tick_ps;
482 static void rfbi_get_clk_info(
u32 *clk_period,
u32 *max_clk_div)
484 *clk_period = 1000000000 / rfbi.l4_khz;
491 int reon, reoff, weon, weoff, cson, csoff, cs_pulse;
492 int actim, recyc, wecyc;
495 if (div <= 0 || div > 2)
524 if (csoff <
max(weoff, reoff))
525 csoff =
max(weoff, reoff);
578 unsigned hs_pulse_time,
unsigned vs_pulse_time,
579 int hs_pol_inv,
int vs_pol_inv,
int extif_div)
585 hs = ps_to_rfbi_ticks(hs_pulse_time, 1);
586 vs = ps_to_rfbi_ticks(vs_pulse_time, 1);
598 DSSDBG(
"setup_te: mode %d hs %d vs %d hs_inv %d vs_inv %d\n",
599 mode, hs, vs, hs_pol_inv, vs_pol_inv);
623 DSSDBG(
"te %d line %d mode %d\n", enable, line, rfbi.te_mode);
624 if (line > (1 << 11) - 1)
631 l |= rfbi.te_mode << 2;
641 static int rfbi_configure(
int rfbi_module,
int bpp,
int lines)
644 int cycle1 = 0, cycle2 = 0, cycle3 = 0;
687 if ((bpp % lines) == 0) {
688 switch (bpp / lines) {
702 }
else if ((2 * bpp % lines) == 0) {
703 if ((2 * bpp / lines) == 3)
714 switch (cycleformat) {
732 cycle2 = (lines / 2) | ((lines / 2) << 16);
733 cycle3 = (lines << 16);
740 l |=
FLD_VAL(parallelmode, 1, 0);
746 l |=
FLD_VAL(cycleformat, 10, 9);
762 l =
FLD_MOD(l, rfbi_module+1, 3, 2);
767 DSSDBG(
"RFBI config: bpp %d, lines %d, cycles: 0x%x 0x%x 0x%x\n",
768 bpp, lines, cycle1, cycle2, cycle3);
775 return rfbi_configure(dssdev->
phy.
rfbi.channel, rfbi.pixel_size,
783 return rfbi_transfer_area(dssdev,
callback, data);
789 rfbi.timings.x_res =
w;
790 rfbi.timings.y_res =
h;
809 rfbi.intf_timings = *timings;
813 static void rfbi_dump_regs(
struct seq_file *
s)
815 #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, rfbi_read_reg(r))
817 if (rfbi_runtime_get())
864 mgr_config.video_port_width = rfbi.pixel_size;
874 rfbi.timings.hsw = 1;
875 rfbi.timings.hfp = 1;
876 rfbi.timings.hbp = 1;
877 rfbi.timings.vsw = 1;
878 rfbi.timings.vfp = 0;
879 rfbi.timings.vbp = 0;
881 rfbi.timings.interlace =
false;
897 DSSERR(
"failed to enable display: no output/manager\n");
901 r = rfbi_runtime_get();
907 DSSERR(
"failed to start device\n");
914 DSSERR(
"can't get FRAMEDONE irq\n");
918 rfbi_config_lcd_manager(dssdev);
920 rfbi_configure(dssdev->
phy.
rfbi.channel, rfbi.pixel_size,
923 rfbi_set_timings(dssdev->
phy.
rfbi.channel, &rfbi.intf_timings);
965 if (def_dssdev ==
NULL)
968 if (def_disp_name !=
NULL &&
984 plat_dssdev = rfbi_find_dssdev(rfbidev);
995 r = rfbi_init_display(dssdev);
997 DSSERR(
"device %s init failed: %d\n", dssdev->
name, r);
1004 DSSERR(
"device %s register failed: %d\n", dssdev->
name, r);
1038 sema_init(&rfbi.bus_lock, 1);
1042 DSSERR(
"can't get IORESOURCE_MEM RFBI\n");
1047 resource_size(rfbi_mem));
1049 DSSERR(
"can't ioremap RFBI\n");
1055 DSSERR(
"can't get ick\n");
1056 return PTR_ERR(clk);
1065 r = rfbi_runtime_get();
1067 goto err_runtime_get;
1079 rfbi_init_output(pdev);
1081 rfbi_probe_pdata(pdev);
1086 pm_runtime_disable(&pdev->
dev);
1094 rfbi_uninit_output(pdev);
1096 pm_runtime_disable(&pdev->
dev);
1101 static int rfbi_runtime_suspend(
struct device *
dev)
1108 static int rfbi_runtime_resume(
struct device *
dev)
1119 static const struct dev_pm_ops rfbi_pm_ops = {
1120 .runtime_suspend = rfbi_runtime_suspend,
1121 .runtime_resume = rfbi_runtime_resume,
1125 .remove =
__exit_p(omap_rfbihw_remove),
1127 .name =
"omapdss_rfbi",