drm/omap: Fix error handling path in 'omap_dmm_probe()'
[linux/fpc-iii.git] / drivers / gpu / drm / sti / sti_awg_utils.c
blob00d0698be9d33e7b4517c9e39c186607676a8399
1 /*
2 * Copyright (C) STMicroelectronics SA 2014
3 * Author: Vincent Abriou <vincent.abriou@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
5 */
7 #include "sti_awg_utils.h"
9 #define AWG_OPCODE_OFFSET 10
11 enum opcode {
12 SET,
13 RPTSET,
14 RPLSET,
15 SKIP,
16 STOP,
17 REPEAT,
18 REPLAY,
19 JUMP,
20 HOLD,
23 static int awg_generate_instr(enum opcode opcode,
24 long int arg,
25 long int mux_sel,
26 long int data_en,
27 struct awg_code_generation_params *fwparams)
29 u32 instruction = 0;
30 u32 mux = (mux_sel << 8) & 0x1ff;
31 u32 data_enable = (data_en << 9) & 0x2ff;
32 long int arg_tmp = arg;
34 /* skip, repeat and replay arg should not exceed 1023.
35 * If user wants to exceed this value, the instruction should be
36 * duplicate and arg should be adjust for each duplicated instruction.
39 while (arg_tmp > 0) {
40 arg = arg_tmp;
41 if (fwparams->instruction_offset >= AWG_MAX_INST) {
42 DRM_ERROR("too many number of instructions\n");
43 return -EINVAL;
46 switch (opcode) {
47 case SKIP:
48 /* leave 'arg' + 1 pixel elapsing without changing
49 * output bus */
50 arg--; /* pixel adjustment */
51 arg_tmp--;
53 if (arg < 0) {
54 /* SKIP instruction not needed */
55 return 0;
58 if (arg == 0) {
59 /* SKIP 0 not permitted but we want to skip 1
60 * pixel. So we transform SKIP into SET
61 * instruction */
62 opcode = SET;
63 break;
66 mux = 0;
67 data_enable = 0;
68 arg &= (0x3ff);
69 break;
70 case REPEAT:
71 case REPLAY:
72 if (arg == 0) {
73 /* REPEAT or REPLAY instruction not needed */
74 return 0;
77 mux = 0;
78 data_enable = 0;
79 arg &= (0x3ff);
80 break;
81 case JUMP:
82 mux = 0;
83 data_enable = 0;
84 arg |= 0x40; /* for jump instruction 7th bit is 1 */
85 arg &= 0x3ff;
86 break;
87 case STOP:
88 arg = 0;
89 break;
90 case SET:
91 case RPTSET:
92 case RPLSET:
93 case HOLD:
94 arg &= (0x0ff);
95 break;
96 default:
97 DRM_ERROR("instruction %d does not exist\n", opcode);
98 return -EINVAL;
101 arg_tmp = arg_tmp - arg;
103 arg = ((arg + mux) + data_enable);
105 instruction = ((opcode) << AWG_OPCODE_OFFSET) | arg;
106 fwparams->ram_code[fwparams->instruction_offset] =
107 instruction & (0x3fff);
108 fwparams->instruction_offset++;
110 return 0;
113 int sti_awg_generate_code_data_enable_mode(
114 struct awg_code_generation_params *fwparams,
115 struct awg_timing *timing)
117 long int val;
118 long int data_en;
119 int ret = 0;
121 if (timing->trailing_lines > 0) {
122 /* skip trailing lines */
123 val = timing->blanking_level;
124 data_en = 0;
125 ret |= awg_generate_instr(RPLSET, val, 0, data_en, fwparams);
127 val = timing->trailing_lines - 1;
128 data_en = 0;
129 ret |= awg_generate_instr(REPLAY, val, 0, data_en, fwparams);
132 if (timing->trailing_pixels > 0) {
133 /* skip trailing pixel */
134 val = timing->blanking_level;
135 data_en = 0;
136 ret |= awg_generate_instr(RPLSET, val, 0, data_en, fwparams);
138 val = timing->trailing_pixels - 1;
139 data_en = 0;
140 ret |= awg_generate_instr(SKIP, val, 0, data_en, fwparams);
143 /* set DE signal high */
144 val = timing->blanking_level;
145 data_en = 1;
146 ret |= awg_generate_instr((timing->trailing_pixels > 0) ? SET : RPLSET,
147 val, 0, data_en, fwparams);
149 if (timing->blanking_pixels > 0) {
150 /* skip the number of active pixel */
151 val = timing->active_pixels - 1;
152 data_en = 1;
153 ret |= awg_generate_instr(SKIP, val, 0, data_en, fwparams);
155 /* set DE signal low */
156 val = timing->blanking_level;
157 data_en = 0;
158 ret |= awg_generate_instr(SET, val, 0, data_en, fwparams);
161 /* replay the sequence as many active lines defined */
162 val = timing->active_lines - 1;
163 data_en = 0;
164 ret |= awg_generate_instr(REPLAY, val, 0, data_en, fwparams);
166 if (timing->blanking_lines > 0) {
167 /* skip blanking lines */
168 val = timing->blanking_level;
169 data_en = 0;
170 ret |= awg_generate_instr(RPLSET, val, 0, data_en, fwparams);
172 val = timing->blanking_lines - 1;
173 data_en = 0;
174 ret |= awg_generate_instr(REPLAY, val, 0, data_en, fwparams);
177 return ret;