summaryrefslogtreecommitdiff
path: root/drivers/media/platform/exynos5-is/fimc-is-backend.c
blob: cdcf0c29db0b16f130af0e53414122589761dc5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
 * Samsung EXYNOS5/EXYNOS3250 FIMC-IS (Imaging Subsystem) driver
 *
 * Copyright (C) 2013-2014 Samsung Electronics Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */
#include "fimc-is-backend.h"
#include "fimc-is.h"
#include "fimc-is-cmd.h"
#include "fimc-is-fw.h"

/**
 * @brief Default set of MCUCTL_HIC_REG and MCUCTL_IHC_REG
 *
 * This is required as those two sets of registers are necessary
 * to properly initialize the communcication with FIMC IS
 * Those to are basic (mandatory) registers and their offsets
 * should ramin the same between differen firmware revisions
 */
static const struct mcuctl_sreg_desc mcuctl_sregs_default[] = {
        [MCUCTL_HIC_REG         ] =
                MCUCTL_SHARED_REG(0x00,  6, 4,MCUCTL_SHARED_REG_RW),
        [MCUCTL_IHC_REG         ] =
                MCUCTL_SHARED_REG(0x024, 7, 4, MCUCTL_SHARED_REG_RW),
};

/**
 * @breif Set of supported MCUCTL Shared registers
 * 	  for  FW FIMC_IS_FW_V120-driven FIMC IS
 */
static const struct mcuctl_sreg_desc fw_120_mcuctl_sregs[] = {
        [MCUCTL_HIC_REG		] =
                MCUCTL_SHARED_REG(0x000, 6, 4, MCUCTL_SHARED_REG_RW),
        [MCUCTL_IHC_REG		] =
                MCUCTL_SHARED_REG(0x024, 7, 4, MCUCTL_SHARED_REG_RW),
        [MCUCTL_ISP_REG		] =
                MCUCTL_SHARED_REG(0x04c, 4, 2, MCUCTL_SHARED_REG_RW),
        [MCUCTL_SCC_REG		] =
                MCUCTL_SHARED_REG(0x06c, 5, 3, MCUCTL_SHARED_REG_RW),
        [MCUCTL_DNR_REG		] =
                MCUCTL_SHARED_REG(0x08c, 4, 2, MCUCTL_SHARED_REG_RW),
        [MCUCTL_SCP_REG		] =
                MCUCTL_SHARED_REG(0x0ac, 5, 3, MCUCTL_SHARED_REG_RW),
        [MCUCTL_YUV_REG		] =
                MCUCTL_SHARED_REG(0x0c4, 4, 2, MCUCTL_SHARED_REG_RW),
        [MCUCTL_SHOT_REG	] =
                MCUCTL_SHARED_REG(0x0d8, 4, 2, MCUCTL_SHARED_REG_RW),
        [MCUCTL_META_REG	] =
                MCUCTL_SHARED_REG(0x0ec, 3, 1, MCUCTL_SHARED_REG_RW),
        [MCUCTL_FRAME_COUNT_REG	] =
                MCUCTL_SHARED_REG(0x0fc, 1, 1, MCUCTL_SHARED_REG_RW),
};

/**
 * @brief Set of supported MCUCTL Shared registers
 * 	  for  FW FIMC_IS_FW_V130-driven FIMC IS
 */
static const struct mcuctl_sreg_desc fw_130_mcuctl_sregs[] = {
        [MCUCTL_HIC_REG		] =
                MCUCTL_SHARED_REG(0x00,  6, 4, MCUCTL_SHARED_REG_RW),
        [MCUCTL_IHC_REG		] =
                MCUCTL_SHARED_REG(0x024, 7, 4, MCUCTL_SHARED_REG_RW),
        [MCUCTL_3AA0C_REG	] =
                MCUCTL_SHARED_REG(0x04c, 5, 3, MCUCTL_SHARED_REG_RW),
        [MCUCTL_3AA1C_REG	] =
                MCUCTL_SHARED_REG(0x064, 5, 3, MCUCTL_SHARED_REG_RW),
        [MCUCTL_SCC_REG		] =
                MCUCTL_SHARED_REG(0x080, 6, 4, MCUCTL_SHARED_REG_RW),
        [MCUCTL_DIS_REG		] =
                MCUCTL_SHARED_REG(0x08c, 5, 3, MCUCTL_SHARED_REG_RW),
        [MCUCTL_SCP_REG		] =
                MCUCTL_SHARED_REG(0x0ac, 5, 3, MCUCTL_SHARED_REG_RW),
        [MCUCTL_SHOT_REG	] =
                MCUCTL_SHARED_REG(0x0d8, 5, 3, MCUCTL_SHARED_REG_RW),
        [MCUCTL_FRAME_COUNT_REG	] =
                MCUCTL_SHARED_REG(0x0f0, 4, 4, MCUCTL_SHARED_REG_RW),
};


#define MCUCTL_SHARED_REG_VALIDATE(regs_desc, reg_range_id, reg_type) \
        (((reg_range_id) < MCUCTL_END_REG) 			      \
        && (regs_desc[reg_range_id].type&reg_type))


/**
 * @brief Retrieve the descriptor for given set of
 * 	  MCUCTL shared registers.
 *
 * @param[in] mcuctl_desc_id       - MCUCTL shared registers map ID
 * @param[in] mcuctl_sreg_id       - the ID of shared regs set
 * @parma[in/out] mcuctl_sreg_desc - requested registers descriptor
 *
 * @return - 0 upon success, EINVAL otherwise
 */

int mcuctl_sreg_get_desc(struct fimc_is_fw_data *fw_data,
                         unsigned int mcuctl_sreg_id,
                         struct mcuctl_sreg_desc *mcuctl_shared_desc)
{
        const struct mcuctl_sreg_desc *regs_map = fw_data->mcuctl_sreg_map;

        if (!mcuctl_shared_desc || !regs_map)
                return -EINVAL;

        if ((MCUCTL_SHARED_REG_VALIDATE(regs_map, mcuctl_sreg_id,
                                        MCUCTL_SHARED_REG_RW))){
                memcpy(mcuctl_shared_desc, &regs_map[mcuctl_sreg_id],
                       sizeof(struct mcuctl_sreg_desc));
                return 0;
        }
        return -EINVAL;
}

static int mcuctl_sreg_get_info(struct fimc_is_fw_data *fw_data,
                                unsigned int mcuctl_sreg_id,
                                unsigned int info_offset,
                                unsigned long *info)
{
        const struct mcuctl_sreg_desc *regs_desc = fw_data->mcuctl_sreg_map;

        if (!info || !regs_desc)
                return -EINVAL;

        if (MCUCTL_SHARED_REG_VALIDATE(regs_desc,
                        mcuctl_sreg_id, MCUCTL_SHARED_REG_RW)){
                *info = *( ((char*)&regs_desc[mcuctl_sreg_id] )+ info_offset);
                return 0;
        }
        return -EINVAL;
}

/**
 * @breif Retrive the base offset of given set of registers
 * 	  relative to the begining of MCUCTL shared area
 *
 * @param[in] mcuctl_desc_id - MCUCTL shared registers map ID
 * @param[in] mcuctl_sreg_id - the ID of shared regs set
 * @param[in/out] offset     - base offset of requested set of registers
 *
 * @return - 0 upon success, EINVAL otherwise
 */
int mcuctl_sreg_get_offset(struct fimc_is_fw_data *fw_data,
                           unsigned int mcuctl_sreg_id,
                           unsigned long * offset)
{
        return mcuctl_sreg_get_info(fw_data,mcuctl_sreg_id,
                offsetof(struct mcuctl_sreg_desc, base_offset), offset);
}

/**
 * @brief Get the range of requested set of MCUCTL shared registers
 *
 * @parma[in] mcuctl_desc_id - MCUCTL shared registers map ID
 * @param[in] mcuctl_sreg_id - the ID of shared regs set
 * @param[in/out] range      - range of requested set of registers
 *
 * @return - 0 upon success, EINVAL otherwise
 */

int mcuctl_sreg_get_range(struct fimc_is_fw_data *fw_data,
                          unsigned int mcuctl_sreg_id,
                          unsigned long *range)
{

         return mcuctl_sreg_get_info(fw_data,mcuctl_sreg_id,
		offsetof(struct mcuctl_sreg_desc, range),
                range);

}

/**
 * @brief Get the range of data registers
 * 	  for given set of MCUCTL shared registers
 *
 * @param[in] mcuctl_desc_id - MCUCTL shared registers map ID
 * @param[in] mcuctl_sreg_id - the ID of shared regs set
 * @param[in/out] data_range - range of data registers from within
 * 			       requested set
 *
 * @return - 0 upon success, EINVAL otherwise
 */

int mcuctl_sreg_get_data_range(struct fimc_is_fw_data *fw_data,
                               unsigned int mcuctl_sreg_id,
                               unsigned int *data_range)
{
        return mcuctl_sreg_get_info(fw_data,mcuctl_sreg_id,
		offsetof(struct mcuctl_sreg_desc, data_range),
                (unsigned long*)data_range);
}

/**
 * @breif Validate requested shared registers ser
 *
 * @param[in] mcuctl_desc_id - MCUCTL shared registers map ID
 * @param[in] mcuctl_sreg_id - the ID of shared regs set
 *
 * @return -	1 case given registers set is valid (readable/writable)
 * 		0 otherwise
 */

int mcuctl_sreg_is_valid(struct fimc_is_fw_data *fw_data,
                         unsigned int mcuctl_sreg_id)
{
        const struct mcuctl_sreg_desc *regs_desc = fw_data->mcuctl_sreg_map;
        if (regs_desc) {
                return MCUCTL_SHARED_REG_VALIDATE(regs_desc,
                        mcuctl_sreg_id, MCUCTL_SHARED_REG_RW);
        }
        return 0;
}

static const unsigned int fw_intrsrc_map_default[] = {
        INTR_GENERAL,
};

static const unsigned int fw_120_intrsrc_map[] = {
        INTR_GENERAL,
        INTR_ISP_DONE,
        INTR_SCC_DONE,
        INTR_DNR_DONE,
        INTR_SCP_DONE,
        INTR_ISP_YUV_DONE,
        INTR_META_DONE,
        INTR_SHOT_DONE
};

static const unsigned int fw_130_intrsrc_map[] = {
        INTR_GENERAL,
        INTR_ISP_DONE,
        INTR_3A0C_DONE,
        INTR_3A1C_DONE,
        INTR_SCC_DONE,
        INTR_DIS_DONE,
        INTR_SCP_DONE,
        INTR_SHOT_DONE,
};

static struct fimc_is_fw_data fw_internal[] = {
        {
                .version = FIMC_IS_FW_VER_UNKNOWN,
                .mcuctl_sreg_map = mcuctl_sregs_default,
                .instruction_set = {
                        .hic_bitmap = 0x3ffffffffULL,
                        .ihc_bitmap = 0xffULL,
                },
                .interrupt_map = fw_intrsrc_map_default,
                .interrupt_map_size =  ARRAY_SIZE(fw_intrsrc_map_default),


        },
        {
                .version = FIMC_IS_FW_V120,
                .instruction_set =  {
                        .hic_bitmap = 0x7ff7fffULL,
                        .ihc_bitmap = 0x7fULL,
                },
                .mcuctl_sreg_map = fw_120_mcuctl_sregs,
                .interrupt_map  = fw_120_intrsrc_map,
                .interrupt_map_size = ARRAY_SIZE(fw_120_intrsrc_map),
        },{
                .version = FIMC_IS_FW_V130,
                .instruction_set =  {
                        .hic_bitmap = 0x3ffffffffULL,
                        .ihc_bitmap = 0xffULL,
                },
                .mcuctl_sreg_map = fw_130_mcuctl_sregs,
                .interrupt_map  = fw_130_intrsrc_map,
                .interrupt_map_size = ARRAY_SIZE(fw_130_intrsrc_map),
        },
        {}
};


void fimc_is_fw_set_default(struct fimc_is_fw_data **fw_data)
{
        BUG_ON(!fw_data);
        *fw_data = &fw_internal[0];
}

int fimc_is_fw_config(struct fimc_is_fw_data **fw_data, unsigned int fw_version)
{
        int i;
        /*
         * Drop the last digit from the firmware version :
         * e.g.: ver. 130-139 should fall back to 130
         */
        fw_version -= fw_version%10;

        for (i = 0; i < ARRAY_SIZE(fw_internal); ++i) {
                if (fw_version == fw_internal[i].version) {
                        *fw_data = &fw_internal[i];
                        return 0;
                }
        }
        return -EINVAL;
}