2 * File: drivers/video/omap/omap1/sossi.c
4 * OMAP1 Special OptimiSed Screen Interface support
6 * Copyright (C) 2004-2005 Nokia Corporation
7 * Author: Juha Yrjölä <juha.yrjola@nokia.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <linux/config.h>
24 #include <linux/module.h>
26 #include <linux/clk.h>
30 #include <asm/arch/dma.h>
31 #include <asm/arch/omapfb.h>
35 #define MODULE_NAME "omapfb-sossi"
37 #define OMAP_SOSSI_BASE 0xfffbac00
38 #define SOSSI_ID_REG 0x00
39 #define SOSSI_INIT1_REG 0x04
40 #define SOSSI_INIT2_REG 0x08
41 #define SOSSI_INIT3_REG 0x0c
42 #define SOSSI_FIFO_REG 0x10
43 #define SOSSI_REOTABLE_REG 0x14
44 #define SOSSI_TEARING_REG 0x18
45 #define SOSSI_INIT1B_REG 0x1c
46 #define SOSSI_FIFOB_REG 0x20
48 #define DMA_GSCR 0xfffedc04
49 #define DMA_LCD_CCR 0xfffee3c2
50 #define DMA_LCD_CTRL 0xfffee3c4
51 #define DMA_LCD_LCH_CTRL 0xfffee3ea
56 #define SOSSI_MAX_XMIT_BYTES (512 * 1024)
60 unsigned long dpll_khz;
62 void (*lcdc_callback)(void *data);
63 void *lcdc_callback_data;
64 /* timing for read and write access */
68 /* if last_access is the same as current we don't have to change
73 struct omapfb_device *fbdev;
74 struct lcd_ctrl_extif *extif;
77 static inline u32 sossi_read_reg(int reg)
79 return readl(sossi.base + reg);
82 static inline u16 sossi_read_reg16(int reg)
84 return readw(sossi.base + reg);
87 static inline u8 sossi_read_reg8(int reg)
89 return readb(sossi.base + reg);
92 static inline void sossi_write_reg(int reg, u32 value)
94 writel(value, sossi.base + reg);
97 static inline void sossi_write_reg16(int reg, u16 value)
99 writew(value, sossi.base + reg);
102 static inline void sossi_write_reg8(int reg, u8 value)
104 writeb(value, sossi.base + reg);
107 static void sossi_set_bits(int reg, u32 bits)
109 sossi_write_reg(reg, sossi_read_reg(reg) | bits);
112 static void sossi_clear_bits(int reg, u32 bits)
114 sossi_write_reg(reg, sossi_read_reg(reg) & ~bits);
117 #define MOD_CONF_CTRL_1 0xfffe1110
118 #define CONF_SOSSI_RESET_R (1 << 23)
119 #define CONF_MOD_SOSSI_CLK_EN_R (1 << 16)
121 static void sossi_dma_callback(void *data);
123 #define KHZ_TO_PS(x) (1000000000 / (x))
125 static u32 ps_to_sossi_ticks(u32 ps, int div)
127 u32 clk_period = KHZ_TO_PS(sossi.dpll_khz) * 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;
137 /* Make sure that after conversion it still holds that:
138 * reoff > reon, recyc >= reoff, actim > reon
140 reon = ps_to_sossi_ticks(t->re_on_time, div);
141 /* reon will be exactly one sossi tick */
145 reoff = ps_to_sossi_ticks(t->re_off_time, div);
154 recyc = ps_to_sossi_ticks(t->re_cycle_time, div);
159 /* values less then 3 result in the SOSSI block resetting itself */
165 actim = ps_to_sossi_ticks(t->access_time, div);
168 /* access time (data hold time) will be exactly one sossi
171 if (actim - reoff > 1)
180 static int calc_wr_timings(struct extif_timings *t)
183 int weon, weoff, wecyc;
184 int div = t->clk_div;
186 /* Make sure that after conversion it still holds that:
187 * weoff > weon, wecyc >= weoff
189 weon = ps_to_sossi_ticks(t->we_on_time, div);
190 /* weon will be exactly one sossi tick */
194 weoff = ps_to_sossi_ticks(t->we_off_time, div);
201 wecyc = ps_to_sossi_ticks(t->we_cycle_time, div);
206 /* values less then 3 result in the SOSSI block resetting itself */
218 static void _set_timing(int div, int tw0, int tw1)
223 dev_dbg(sossi.fbdev->dev, "Using TW0 = %d, TW1 = %d, div = %d\n",
224 tw0 + 1, tw1 + 1, div + 1);
227 l = omap_readl(MOD_CONF_CTRL_1);
230 omap_writel(l, MOD_CONF_CTRL_1);
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);
238 static inline void set_timing(int access)
240 if (access != sossi.last_access) {
241 sossi.last_access = access;
242 _set_timing(sossi.clk_div,
243 sossi.clk_tw0[access], sossi.clk_tw1[access]);
247 static void sossi_start_transfer(void)
250 sossi_clear_bits(SOSSI_INIT2_REG, 1 << 4);
252 sossi_clear_bits(SOSSI_INIT1_REG, 1 << 30);
253 /* FIXME: locking? */
256 static void sossi_stop_transfer(void)
259 sossi_set_bits(SOSSI_INIT2_REG, 1 << 4);
261 sossi_set_bits(SOSSI_INIT1_REG, 1 << 30);
262 /* FIXME: locking? */
265 static void wait_end_of_write(void)
267 /* Before reading we must check if some writings are going on */
268 while (!(sossi_read_reg(SOSSI_INIT2_REG) & (1 << 3)));
271 static void send_data(const void *data, unsigned int len)
274 sossi_write_reg(SOSSI_FIFO_REG, *(const u32 *) data);
279 sossi_write_reg16(SOSSI_FIFO_REG, *(const u16 *) data);
284 sossi_write_reg8(SOSSI_FIFO_REG, *(const u8 *) data);
290 static void set_cycles(unsigned int len)
292 unsigned long nr_cycles = len / (sossi.bus_pick_width / 8);
294 BUG_ON((nr_cycles - 1) & ~0x3ffff);
296 sossi_clear_bits(SOSSI_INIT1_REG, 0x3ffff);
297 sossi_set_bits(SOSSI_INIT1_REG, (nr_cycles - 1) & 0x3ffff);
300 static int sossi_convert_timings(struct extif_timings *t)
303 int div = t->clk_div;
307 if (div <= 0 || div > 8)
310 /* no CS on SOSSI, so ignore cson, csoff, cs_pulsewidth */
311 if ((r = calc_rd_timings(t)) < 0)
314 if ((r = calc_wr_timings(t)) < 0)
324 static void sossi_set_timings(const struct extif_timings *t)
326 BUG_ON(!t->converted);
328 sossi.clk_tw0[RD_ACCESS] = t->tim[0];
329 sossi.clk_tw1[RD_ACCESS] = t->tim[1];
331 sossi.clk_tw0[WR_ACCESS] = t->tim[2];
332 sossi.clk_tw1[WR_ACCESS] = t->tim[3];
334 sossi.clk_div = t->tim[4];
337 static void sossi_get_clk_info(u32 *clk_period, u32 *max_clk_div)
339 *clk_period = KHZ_TO_PS(sossi.dpll_khz);
343 static void sossi_set_bits_per_cycle(int bpc)
346 int bus_pick_count, bus_pick_width;
348 /* We set explicitly the the bus_pick_count as well, although
349 * with remapping/reordering disabled it will be calculated by HW
350 * as (32 / bus_pick_width).
365 l = sossi_read_reg(SOSSI_INIT3_REG);
366 sossi.bus_pick_width = bus_pick_width;
368 l |= ((bus_pick_count - 1) << 5) | ((bus_pick_width - 1) & 0x1f);
369 sossi_write_reg(SOSSI_INIT3_REG, l);
372 static void sossi_write_command(const void *data, unsigned int len)
374 set_timing(WR_ACCESS);
376 sossi_clear_bits(SOSSI_INIT1_REG, 1 << 18);
378 sossi_start_transfer();
379 send_data(data, len);
380 sossi_stop_transfer();
384 static void sossi_write_data(const void *data, unsigned int len)
386 set_timing(WR_ACCESS);
388 sossi_set_bits(SOSSI_INIT1_REG, 1 << 18);
390 sossi_start_transfer();
391 send_data(data, len);
392 sossi_stop_transfer();
396 static void sossi_transfer_area(int width, int height,
397 void (callback)(void *data), void *data)
399 BUG_ON(callback == NULL);
401 sossi.lcdc_callback = callback;
402 sossi.lcdc_callback_data = data;
404 set_timing(WR_ACCESS);
406 sossi_set_bits(SOSSI_INIT1_REG, 1 << 18);
407 set_cycles(width * height * sossi.bus_pick_width / 8);
409 sossi_start_transfer();
410 omap_enable_lcd_dma();
413 static void sossi_dma_callback(void *data)
416 sossi_stop_transfer();
417 sossi.lcdc_callback(sossi.lcdc_callback_data);
420 static void sossi_read_data(void *data, unsigned int len)
422 set_timing(RD_ACCESS);
424 sossi_set_bits(SOSSI_INIT1_REG, 1 << 18);
426 sossi_start_transfer();
428 *(u32 *) data = sossi_read_reg(SOSSI_FIFO_REG);
433 *(u16 *) data = sossi_read_reg16(SOSSI_FIFO_REG);
438 *(u8 *) data = sossi_read_reg8(SOSSI_FIFO_REG);
442 sossi_stop_transfer();
445 static int sossi_init(struct omapfb_device *fbdev)
448 struct clk *dpll_clk;
453 sossi.base = (void __iomem *)IO_ADDRESS(OMAP_SOSSI_BASE);
454 dpll_clk = clk_get(fbdev->dev, "ck_dpll1");
455 if (IS_ERR(dpll_clk)) {
456 dev_err(fbdev->dev, "can't get dpll1 clock\n");
457 return PTR_ERR(dpll_clk);
460 sossi.dpll_khz = clk_get_rate(dpll_clk) / 1000;
463 /* Reset and enable the SoSSI module */
464 l = omap_readl(MOD_CONF_CTRL_1);
465 l |= CONF_SOSSI_RESET_R;
466 omap_writel(l, MOD_CONF_CTRL_1);
467 l &= ~CONF_SOSSI_RESET_R;
468 omap_writel(l, MOD_CONF_CTRL_1);
470 l |= CONF_MOD_SOSSI_CLK_EN_R;
471 omap_writel(l, MOD_CONF_CTRL_1);
473 omap_writel(omap_readl(ARM_IDLECT2) | (1 << 11), ARM_IDLECT2);
474 omap_writel(omap_readl(ARM_IDLECT1) | (1 << 6), ARM_IDLECT1);
476 l = sossi_read_reg(SOSSI_INIT2_REG);
477 /* Enable and reset the SoSSI block */
478 l |= (1 << 0) | (1 << 1);
479 sossi_write_reg(SOSSI_INIT2_REG, l);
480 /* Take SoSSI out of reset */
482 sossi_write_reg(SOSSI_INIT2_REG, l);
484 sossi_write_reg(SOSSI_ID_REG, 0);
485 l = sossi_read_reg(SOSSI_ID_REG);
486 k = sossi_read_reg(SOSSI_ID_REG);
488 if (l != 0x55555555 || k != 0xaaaaaaaa) {
490 "invalid SoSSI sync pattern: %08x, %08x\n", l, k);
494 if ((r = omap_lcdc_set_dma_callback(sossi_dma_callback, NULL)) < 0) {
495 dev_err(fbdev->dev, "can't get LCDC IRQ\n");
499 l = sossi_read_reg(SOSSI_ID_REG); /* Component code */
500 l = sossi_read_reg(SOSSI_ID_REG);
501 pr_info("omapfb: SoSSI version %d.%d initialized\n",
502 l >> 16, l & 0xffff);
504 l = sossi_read_reg(SOSSI_INIT1_REG);
505 l |= (1 << 19); /* DMA_MODE */
506 l &= ~(1 << 31); /* REORDERING */
507 sossi_write_reg(SOSSI_INIT1_REG, l);
512 static void sossi_cleanup(void)
514 omap_lcdc_free_dma_callback();
517 const struct lcd_ctrl_extif omap1_ext_if = {
519 .cleanup = sossi_cleanup,
520 .get_clk_info = sossi_get_clk_info,
521 .convert_timings = sossi_convert_timings,
522 .set_timings = sossi_set_timings,
523 .set_bits_per_cycle = sossi_set_bits_per_cycle,
524 .write_command = sossi_write_command,
525 .read_data = sossi_read_data,
526 .write_data = sossi_write_data,
527 .transfer_area = sossi_transfer_area,
529 .max_transmit_size = SOSSI_MAX_XMIT_BYTES,