2 * OMAP1 Special OptimiSed Screen Interface support
4 * Copyright (C) 2004-2005 Nokia Corporation
5 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <linux/module.h>
23 #include <linux/clk.h>
24 #include <linux/irq.h>
26 #include <linux/interrupt.h>
28 #include <linux/omap-dma.h>
33 #define MODULE_NAME "omapfb-sossi"
35 #define OMAP_SOSSI_BASE 0xfffbac00
36 #define SOSSI_ID_REG 0x00
37 #define SOSSI_INIT1_REG 0x04
38 #define SOSSI_INIT2_REG 0x08
39 #define SOSSI_INIT3_REG 0x0c
40 #define SOSSI_FIFO_REG 0x10
41 #define SOSSI_REOTABLE_REG 0x14
42 #define SOSSI_TEARING_REG 0x18
43 #define SOSSI_INIT1B_REG 0x1c
44 #define SOSSI_FIFOB_REG 0x20
46 #define DMA_GSCR 0xfffedc04
47 #define DMA_LCD_CCR 0xfffee3c2
48 #define DMA_LCD_CTRL 0xfffee3c4
49 #define DMA_LCD_LCH_CTRL 0xfffee3ea
51 #define CONF_SOSSI_RESET_R (1 << 23)
56 #define SOSSI_MAX_XMIT_BYTES (512 * 1024)
67 void (*lcdc_callback
)(void *data
);
68 void *lcdc_callback_data
;
69 int vsync_dma_pending
;
70 /* timing for read and write access */
75 * if last_access is the same as current we don't have to change
80 struct omapfb_device
*fbdev
;
83 static inline u32
sossi_read_reg(int reg
)
85 return readl(sossi
.base
+ reg
);
88 static inline u16
sossi_read_reg16(int reg
)
90 return readw(sossi
.base
+ reg
);
93 static inline u8
sossi_read_reg8(int reg
)
95 return readb(sossi
.base
+ reg
);
98 static inline void sossi_write_reg(int reg
, u32 value
)
100 writel(value
, sossi
.base
+ reg
);
103 static inline void sossi_write_reg16(int reg
, u16 value
)
105 writew(value
, sossi
.base
+ reg
);
108 static inline void sossi_write_reg8(int reg
, u8 value
)
110 writeb(value
, sossi
.base
+ reg
);
113 static void sossi_set_bits(int reg
, u32 bits
)
115 sossi_write_reg(reg
, sossi_read_reg(reg
) | bits
);
118 static void sossi_clear_bits(int reg
, u32 bits
)
120 sossi_write_reg(reg
, sossi_read_reg(reg
) & ~bits
);
123 #define HZ_TO_PS(x) (1000000000 / (x / 1000))
125 static u32
ps_to_sossi_ticks(u32 ps
, int div
)
127 u32 clk_period
= HZ_TO_PS(sossi
.fck_hz
) * div
;
128 return (clk_period
+ ps
- 1) / clk_period
;
131 static int calc_rd_timings(struct extif_timings
*t
)
134 int reon
, reoff
, recyc
, actim
;
135 int div
= t
->clk_div
;
138 * Make sure that after conversion it still holds that:
139 * reoff > reon, recyc >= reoff, actim > reon
141 reon
= ps_to_sossi_ticks(t
->re_on_time
, div
);
142 /* reon will be exactly one sossi tick */
146 reoff
= ps_to_sossi_ticks(t
->re_off_time
, div
);
155 recyc
= ps_to_sossi_ticks(t
->re_cycle_time
, div
);
160 /* values less then 3 result in the SOSSI block resetting itself */
166 actim
= ps_to_sossi_ticks(t
->access_time
, div
);
170 * access time (data hold time) will be exactly one sossi
173 if (actim
- reoff
> 1)
182 static int calc_wr_timings(struct extif_timings
*t
)
185 int weon
, weoff
, wecyc
;
186 int div
= t
->clk_div
;
189 * Make sure that after conversion it still holds that:
190 * weoff > weon, wecyc >= weoff
192 weon
= ps_to_sossi_ticks(t
->we_on_time
, div
);
193 /* weon will be exactly one sossi tick */
197 weoff
= ps_to_sossi_ticks(t
->we_off_time
, div
);
204 wecyc
= ps_to_sossi_ticks(t
->we_cycle_time
, div
);
209 /* values less then 3 result in the SOSSI block resetting itself */
221 static void _set_timing(int div
, int tw0
, int tw1
)
226 dev_dbg(sossi
.fbdev
->dev
, "Using TW0 = %d, TW1 = %d, div = %d\n",
227 tw0
+ 1, tw1
+ 1, div
);
230 clk_set_rate(sossi
.fck
, sossi
.fck_hz
/ div
);
231 clk_enable(sossi
.fck
);
232 l
= sossi_read_reg(SOSSI_INIT1_REG
);
233 l
&= ~((0x0f << 20) | (0x3f << 24));
234 l
|= (tw0
<< 20) | (tw1
<< 24);
235 sossi_write_reg(SOSSI_INIT1_REG
, l
);
236 clk_disable(sossi
.fck
);
239 static void _set_bits_per_cycle(int bus_pick_count
, int bus_pick_width
)
243 l
= sossi_read_reg(SOSSI_INIT3_REG
);
245 l
|= ((bus_pick_count
- 1) << 5) | ((bus_pick_width
- 1) & 0x1f);
246 sossi_write_reg(SOSSI_INIT3_REG
, l
);
249 static void _set_tearsync_mode(int mode
, unsigned line
)
253 l
= sossi_read_reg(SOSSI_TEARING_REG
);
254 l
&= ~(((1 << 11) - 1) << 15);
258 sossi_write_reg(SOSSI_TEARING_REG
, l
);
260 sossi_set_bits(SOSSI_INIT2_REG
, 1 << 6); /* TE logic */
262 sossi_clear_bits(SOSSI_INIT2_REG
, 1 << 6);
265 static inline void set_timing(int access
)
267 if (access
!= sossi
.last_access
) {
268 sossi
.last_access
= access
;
269 _set_timing(sossi
.clk_div
,
270 sossi
.clk_tw0
[access
], sossi
.clk_tw1
[access
]);
274 static void sossi_start_transfer(void)
277 sossi_clear_bits(SOSSI_INIT2_REG
, 1 << 4);
279 sossi_clear_bits(SOSSI_INIT1_REG
, 1 << 30);
282 static void sossi_stop_transfer(void)
285 sossi_set_bits(SOSSI_INIT2_REG
, 1 << 4);
287 sossi_set_bits(SOSSI_INIT1_REG
, 1 << 30);
290 static void wait_end_of_write(void)
292 /* Before reading we must check if some writings are going on */
293 while (!(sossi_read_reg(SOSSI_INIT2_REG
) & (1 << 3)));
296 static void send_data(const void *data
, unsigned int len
)
299 sossi_write_reg(SOSSI_FIFO_REG
, *(const u32
*) data
);
304 sossi_write_reg16(SOSSI_FIFO_REG
, *(const u16
*) data
);
309 sossi_write_reg8(SOSSI_FIFO_REG
, *(const u8
*) data
);
315 static void set_cycles(unsigned int len
)
317 unsigned long nr_cycles
= len
/ (sossi
.bus_pick_width
/ 8);
319 BUG_ON((nr_cycles
- 1) & ~0x3ffff);
321 sossi_clear_bits(SOSSI_INIT1_REG
, 0x3ffff);
322 sossi_set_bits(SOSSI_INIT1_REG
, (nr_cycles
- 1) & 0x3ffff);
325 static int sossi_convert_timings(struct extif_timings
*t
)
328 int div
= t
->clk_div
;
332 if (div
<= 0 || div
> 8)
335 /* no CS on SOSSI, so ignore cson, csoff, cs_pulsewidth */
336 if ((r
= calc_rd_timings(t
)) < 0)
339 if ((r
= calc_wr_timings(t
)) < 0)
349 static void sossi_set_timings(const struct extif_timings
*t
)
351 BUG_ON(!t
->converted
);
353 sossi
.clk_tw0
[RD_ACCESS
] = t
->tim
[0];
354 sossi
.clk_tw1
[RD_ACCESS
] = t
->tim
[1];
356 sossi
.clk_tw0
[WR_ACCESS
] = t
->tim
[2];
357 sossi
.clk_tw1
[WR_ACCESS
] = t
->tim
[3];
359 sossi
.clk_div
= t
->tim
[4];
362 static void sossi_get_clk_info(u32
*clk_period
, u32
*max_clk_div
)
364 *clk_period
= HZ_TO_PS(sossi
.fck_hz
);
368 static void sossi_set_bits_per_cycle(int bpc
)
370 int bus_pick_count
, bus_pick_width
;
373 * We set explicitly the the bus_pick_count as well, although
374 * with remapping/reordering disabled it will be calculated by HW
375 * as (32 / bus_pick_width).
390 sossi
.bus_pick_width
= bus_pick_width
;
391 sossi
.bus_pick_count
= bus_pick_count
;
394 static int sossi_setup_tearsync(unsigned pin_cnt
,
395 unsigned hs_pulse_time
, unsigned vs_pulse_time
,
396 int hs_pol_inv
, int vs_pol_inv
, int div
)
401 if (pin_cnt
!= 1 || div
< 1 || div
> 8)
404 hs
= ps_to_sossi_ticks(hs_pulse_time
, div
);
405 vs
= ps_to_sossi_ticks(vs_pulse_time
, div
);
406 if (vs
< 8 || vs
<= hs
|| vs
>= (1 << 12))
415 dev_dbg(sossi
.fbdev
->dev
,
416 "setup_tearsync: hs %d vs %d hs_inv %d vs_inv %d\n",
417 hs
, vs
, hs_pol_inv
, vs_pol_inv
);
419 clk_enable(sossi
.fck
);
420 l
= sossi_read_reg(SOSSI_TEARING_REG
);
421 l
&= ~((1 << 15) - 1);
432 sossi_write_reg(SOSSI_TEARING_REG
, l
);
433 clk_disable(sossi
.fck
);
438 static int sossi_enable_tearsync(int enable
, unsigned line
)
442 dev_dbg(sossi
.fbdev
->dev
, "tearsync %d line %d\n", enable
, line
);
447 mode
= 2; /* HS or VS */
449 mode
= 3; /* VS only */
452 sossi
.tearsync_line
= line
;
453 sossi
.tearsync_mode
= mode
;
458 static void sossi_write_command(const void *data
, unsigned int len
)
460 clk_enable(sossi
.fck
);
461 set_timing(WR_ACCESS
);
462 _set_bits_per_cycle(sossi
.bus_pick_count
, sossi
.bus_pick_width
);
464 sossi_clear_bits(SOSSI_INIT1_REG
, 1 << 18);
466 sossi_start_transfer();
467 send_data(data
, len
);
468 sossi_stop_transfer();
470 clk_disable(sossi
.fck
);
473 static void sossi_write_data(const void *data
, unsigned int len
)
475 clk_enable(sossi
.fck
);
476 set_timing(WR_ACCESS
);
477 _set_bits_per_cycle(sossi
.bus_pick_count
, sossi
.bus_pick_width
);
479 sossi_set_bits(SOSSI_INIT1_REG
, 1 << 18);
481 sossi_start_transfer();
482 send_data(data
, len
);
483 sossi_stop_transfer();
485 clk_disable(sossi
.fck
);
488 static void sossi_transfer_area(int width
, int height
,
489 void (callback
)(void *data
), void *data
)
491 BUG_ON(callback
== NULL
);
493 sossi
.lcdc_callback
= callback
;
494 sossi
.lcdc_callback_data
= data
;
496 clk_enable(sossi
.fck
);
497 set_timing(WR_ACCESS
);
498 _set_bits_per_cycle(sossi
.bus_pick_count
, sossi
.bus_pick_width
);
499 _set_tearsync_mode(sossi
.tearsync_mode
, sossi
.tearsync_line
);
501 sossi_set_bits(SOSSI_INIT1_REG
, 1 << 18);
502 set_cycles(width
* height
* sossi
.bus_pick_width
/ 8);
504 sossi_start_transfer();
505 if (sossi
.tearsync_mode
) {
507 * Wait for the sync signal and start the transfer only
508 * then. We can't seem to be able to use HW sync DMA for
509 * this since LCD DMA shows huge latencies, as if it
510 * would ignore some of the DMA requests from SoSSI.
514 spin_lock_irqsave(&sossi
.lock
, flags
);
515 sossi
.vsync_dma_pending
++;
516 spin_unlock_irqrestore(&sossi
.lock
, flags
);
518 /* Just start the transfer right away. */
519 omap_enable_lcd_dma();
522 static void sossi_dma_callback(void *data
)
525 sossi_stop_transfer();
526 clk_disable(sossi
.fck
);
527 sossi
.lcdc_callback(sossi
.lcdc_callback_data
);
530 static void sossi_read_data(void *data
, unsigned int len
)
532 clk_enable(sossi
.fck
);
533 set_timing(RD_ACCESS
);
534 _set_bits_per_cycle(sossi
.bus_pick_count
, sossi
.bus_pick_width
);
536 sossi_set_bits(SOSSI_INIT1_REG
, 1 << 18);
538 sossi_start_transfer();
540 *(u32
*) data
= sossi_read_reg(SOSSI_FIFO_REG
);
545 *(u16
*) data
= sossi_read_reg16(SOSSI_FIFO_REG
);
550 *(u8
*) data
= sossi_read_reg8(SOSSI_FIFO_REG
);
554 sossi_stop_transfer();
555 clk_disable(sossi
.fck
);
558 static irqreturn_t
sossi_match_irq(int irq
, void *data
)
562 spin_lock_irqsave(&sossi
.lock
, flags
);
563 if (sossi
.vsync_dma_pending
) {
564 sossi
.vsync_dma_pending
--;
565 omap_enable_lcd_dma();
567 spin_unlock_irqrestore(&sossi
.lock
, flags
);
571 static int sossi_init(struct omapfb_device
*fbdev
)
575 struct clk
*dpll1out_ck
;
578 sossi
.base
= ioremap(OMAP_SOSSI_BASE
, SZ_1K
);
580 dev_err(fbdev
->dev
, "can't ioremap SoSSI\n");
585 spin_lock_init(&sossi
.lock
);
587 dpll1out_ck
= clk_get(fbdev
->dev
, "ck_dpll1out");
588 if (IS_ERR(dpll1out_ck
)) {
589 dev_err(fbdev
->dev
, "can't get DPLL1OUT clock\n");
590 return PTR_ERR(dpll1out_ck
);
593 * We need the parent clock rate, which we might divide further
594 * depending on the timing requirements of the controller. See
597 sossi
.fck_hz
= clk_get_rate(dpll1out_ck
);
598 clk_put(dpll1out_ck
);
600 fck
= clk_get(fbdev
->dev
, "ck_sossi");
602 dev_err(fbdev
->dev
, "can't get SoSSI functional clock\n");
607 /* Reset and enable the SoSSI module */
608 l
= omap_readl(MOD_CONF_CTRL_1
);
609 l
|= CONF_SOSSI_RESET_R
;
610 omap_writel(l
, MOD_CONF_CTRL_1
);
611 l
&= ~CONF_SOSSI_RESET_R
;
612 omap_writel(l
, MOD_CONF_CTRL_1
);
614 clk_enable(sossi
.fck
);
615 l
= omap_readl(ARM_IDLECT2
);
616 l
&= ~(1 << 8); /* DMACK_REQ */
617 omap_writel(l
, ARM_IDLECT2
);
619 l
= sossi_read_reg(SOSSI_INIT2_REG
);
620 /* Enable and reset the SoSSI block */
621 l
|= (1 << 0) | (1 << 1);
622 sossi_write_reg(SOSSI_INIT2_REG
, l
);
623 /* Take SoSSI out of reset */
625 sossi_write_reg(SOSSI_INIT2_REG
, l
);
627 sossi_write_reg(SOSSI_ID_REG
, 0);
628 l
= sossi_read_reg(SOSSI_ID_REG
);
629 k
= sossi_read_reg(SOSSI_ID_REG
);
631 if (l
!= 0x55555555 || k
!= 0xaaaaaaaa) {
633 "invalid SoSSI sync pattern: %08x, %08x\n", l
, k
);
638 if ((r
= omap_lcdc_set_dma_callback(sossi_dma_callback
, NULL
)) < 0) {
639 dev_err(fbdev
->dev
, "can't get LCDC IRQ\n");
644 l
= sossi_read_reg(SOSSI_ID_REG
); /* Component code */
645 l
= sossi_read_reg(SOSSI_ID_REG
);
646 dev_info(fbdev
->dev
, "SoSSI version %d.%d initialized\n",
647 l
>> 16, l
& 0xffff);
649 l
= sossi_read_reg(SOSSI_INIT1_REG
);
650 l
|= (1 << 19); /* DMA_MODE */
651 l
&= ~(1 << 31); /* REORDERING */
652 sossi_write_reg(SOSSI_INIT1_REG
, l
);
654 if ((r
= request_irq(INT_1610_SoSSI_MATCH
, sossi_match_irq
,
655 IRQ_TYPE_EDGE_FALLING
,
656 "sossi_match", sossi
.fbdev
->dev
)) < 0) {
657 dev_err(sossi
.fbdev
->dev
, "can't get SoSSI match IRQ\n");
661 clk_disable(sossi
.fck
);
665 clk_disable(sossi
.fck
);
670 static void sossi_cleanup(void)
672 omap_lcdc_free_dma_callback();
677 struct lcd_ctrl_extif omap1_ext_if
= {
679 .cleanup
= sossi_cleanup
,
680 .get_clk_info
= sossi_get_clk_info
,
681 .convert_timings
= sossi_convert_timings
,
682 .set_timings
= sossi_set_timings
,
683 .set_bits_per_cycle
= sossi_set_bits_per_cycle
,
684 .setup_tearsync
= sossi_setup_tearsync
,
685 .enable_tearsync
= sossi_enable_tearsync
,
686 .write_command
= sossi_write_command
,
687 .read_data
= sossi_read_data
,
688 .write_data
= sossi_write_data
,
689 .transfer_area
= sossi_transfer_area
,
691 .max_transmit_size
= SOSSI_MAX_XMIT_BYTES
,