blob: e87bd93811d48fb3646754e2c4a95db55862e1e2 [file] [log] [blame]
Kamil Debski91884732011-10-06 11:32:12 -03001/*
2 * Samsung S5P G2D - 2D Graphics Accelerator Driver
3 *
4 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
5 * Kamil Debski, <k.debski@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version
11 */
12
13#include <linux/io.h>
14
15#include "g2d.h"
16#include "g2d-regs.h"
17
18#define w(x, a) writel((x), d->regs + (a))
19#define r(a) readl(d->regs + (a))
20
21/* g2d_reset clears all g2d registers */
22void g2d_reset(struct g2d_dev *d)
23{
24 w(1, SOFT_RESET_REG);
25}
26
27void g2d_set_src_size(struct g2d_dev *d, struct g2d_frame *f)
28{
29 u32 n;
Kamil Debski91884732011-10-06 11:32:12 -030030
Sachin Kamat62ce2722013-01-17 00:07:18 -030031 w(0, SRC_SELECT_REG);
Kamil Debski91884732011-10-06 11:32:12 -030032 w(f->stride & 0xFFFF, SRC_STRIDE_REG);
33
34 n = f->o_height & 0xFFF;
35 n <<= 16;
36 n |= f->o_width & 0xFFF;
37 w(n, SRC_LEFT_TOP_REG);
38
39 n = f->bottom & 0xFFF;
40 n <<= 16;
41 n |= f->right & 0xFFF;
42 w(n, SRC_RIGHT_BOTTOM_REG);
43
44 w(f->fmt->hw, SRC_COLOR_MODE_REG);
45}
46
47void g2d_set_src_addr(struct g2d_dev *d, dma_addr_t a)
48{
49 w(a, SRC_BASE_ADDR_REG);
50}
51
52void g2d_set_dst_size(struct g2d_dev *d, struct g2d_frame *f)
53{
54 u32 n;
Kamil Debski91884732011-10-06 11:32:12 -030055
Sachin Kamat62ce2722013-01-17 00:07:18 -030056 w(0, DST_SELECT_REG);
Kamil Debski91884732011-10-06 11:32:12 -030057 w(f->stride & 0xFFFF, DST_STRIDE_REG);
58
59 n = f->o_height & 0xFFF;
60 n <<= 16;
61 n |= f->o_width & 0xFFF;
62 w(n, DST_LEFT_TOP_REG);
63
64 n = f->bottom & 0xFFF;
65 n <<= 16;
66 n |= f->right & 0xFFF;
67 w(n, DST_RIGHT_BOTTOM_REG);
68
69 w(f->fmt->hw, DST_COLOR_MODE_REG);
70}
71
72void g2d_set_dst_addr(struct g2d_dev *d, dma_addr_t a)
73{
74 w(a, DST_BASE_ADDR_REG);
75}
76
77void g2d_set_rop4(struct g2d_dev *d, u32 r)
78{
79 w(r, ROP4_REG);
80}
81
Sachin Kamatd0d28322012-02-16 10:52:16 -030082void g2d_set_flip(struct g2d_dev *d, u32 r)
83{
84 w(r, SRC_MSK_DIRECT_REG);
85}
86
Sachin Kamat62ce2722013-01-17 00:07:18 -030087void g2d_set_v41_stretch(struct g2d_dev *d, struct g2d_frame *src,
88 struct g2d_frame *dst)
Kamil Debski91884732011-10-06 11:32:12 -030089{
Sachin Kamat62ce2722013-01-17 00:07:18 -030090 w(DEFAULT_SCALE_MODE, SRC_SCALE_CTRL_REG);
91
92 /* inversed scaling factor: src is numerator */
93 w((src->c_width << 16) / dst->c_width, SRC_XSCALE_REG);
94 w((src->c_height << 16) / dst->c_height, SRC_YSCALE_REG);
Kamil Debski91884732011-10-06 11:32:12 -030095}
96
97void g2d_set_cmd(struct g2d_dev *d, u32 c)
98{
99 w(c, BITBLT_COMMAND_REG);
100}
101
102void g2d_start(struct g2d_dev *d)
103{
104 /* Clear cache */
Sachin Kamat62ce2722013-01-17 00:07:18 -0300105 if (d->variant->hw_rev == TYPE_G2D_3X)
106 w(0x7, CACHECTL_REG);
107
Kamil Debski91884732011-10-06 11:32:12 -0300108 /* Enable interrupt */
109 w(1, INTEN_REG);
110 /* Start G2D engine */
111 w(1, BITBLT_START_REG);
112}
113
114void g2d_clear_int(struct g2d_dev *d)
115{
116 w(1, INTC_PEND_REG);
117}