ASoC: use snd_soc_component_init_regmap() on wm5110
[sfrench/cifs-2.6.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / ia_css_3a.h
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #ifndef __IA_CSS_3A_H
16 #define __IA_CSS_3A_H
17
18 /** @file
19  * This file contains types used for 3A statistics
20  */
21
22 #include <type_support.h>
23 #include "ia_css_types.h"
24 #include "ia_css_err.h"
25 #include "system_global.h"
26
27 enum ia_css_3a_tables {
28         IA_CSS_S3A_TBL_HI,
29         IA_CSS_S3A_TBL_LO,
30         IA_CSS_RGBY_TBL,
31         IA_CSS_NUM_3A_TABLES
32 };
33
34 /** Structure that holds 3A statistics in the ISP internal
35  * format. Use ia_css_get_3a_statistics() to translate
36  * this to the format used on the host (3A library).
37  * */
38 struct ia_css_isp_3a_statistics {
39         union {
40                 struct {
41                         ia_css_ptr s3a_tbl;
42                 } dmem;
43                 struct {
44                         ia_css_ptr s3a_tbl_hi;
45                         ia_css_ptr s3a_tbl_lo;
46                 } vmem;
47         } data;
48         struct {
49                 ia_css_ptr rgby_tbl;
50         } data_hmem;
51         uint32_t exp_id;     /**< exposure id, to match statistics to a frame,
52                                   see ia_css_event_public.h for more detail. */
53         uint32_t isp_config_id;/**< Unique ID to track which config was actually applied to a particular frame */
54         ia_css_ptr data_ptr; /**< pointer to base of all data */
55         uint32_t   size;     /**< total size of all data */
56         uint32_t   dmem_size;
57         uint32_t   vmem_size; /**< both lo and hi have this size */
58         uint32_t   hmem_size;
59 };
60 #define SIZE_OF_DMEM_STRUCT                                             \
61         (SIZE_OF_IA_CSS_PTR)
62
63 #define SIZE_OF_VMEM_STRUCT                                             \
64         (2 * SIZE_OF_IA_CSS_PTR)
65
66 #define SIZE_OF_DATA_UNION                                              \
67         (MAX(SIZE_OF_DMEM_STRUCT, SIZE_OF_VMEM_STRUCT))
68
69 #define SIZE_OF_DATA_HMEM_STRUCT                                        \
70         (SIZE_OF_IA_CSS_PTR)
71
72 #define SIZE_OF_IA_CSS_ISP_3A_STATISTICS_STRUCT                         \
73         (SIZE_OF_DATA_UNION +                                           \
74          SIZE_OF_DATA_HMEM_STRUCT +                                     \
75          sizeof(uint32_t) +                                             \
76          sizeof(uint32_t) +                                             \
77          SIZE_OF_IA_CSS_PTR +                                           \
78          4 * sizeof(uint32_t))
79
80 /** Map with host-side pointers to ISP-format statistics.
81  * These pointers can either be copies of ISP data or memory mapped
82  * ISP pointers.
83  * All of the data behind these pointers is allocated contiguously, the
84  * allocated pointer is stored in the data_ptr field. The other fields
85  * point into this one block of data.
86  */
87 struct ia_css_isp_3a_statistics_map {
88         void                    *data_ptr; /**< Pointer to start of memory */
89         struct ia_css_3a_output *dmem_stats;
90         uint16_t                *vmem_stats_hi;
91         uint16_t                *vmem_stats_lo;
92         struct ia_css_bh_table  *hmem_stats;
93         uint32_t                 size; /**< total size in bytes of data_ptr */
94         uint32_t                 data_allocated; /**< indicate whether data_ptr
95                                                     was allocated or not. */
96 };
97
98 /** @brief Copy and translate 3A statistics from an ISP buffer to a host buffer
99  * @param[out]  host_stats Host buffer.
100  * @param[in]   isp_stats ISP buffer.
101  * @return      error value if temporary memory cannot be allocated
102  *
103  * This copies 3a statistics from an ISP pointer to a host pointer and then
104  * translates some of the statistics, details depend on which ISP binary is
105  * used.
106  * Always use this function, never copy the buffer directly.
107  */
108 enum ia_css_err
109 ia_css_get_3a_statistics(struct ia_css_3a_statistics           *host_stats,
110                          const struct ia_css_isp_3a_statistics *isp_stats);
111
112 /** @brief Translate 3A statistics from ISP format to host format.
113  * @param[out]  host_stats host-format statistics
114  * @param[in]   isp_stats  ISP-format statistics
115  * @return      None
116  *
117  * This function translates statistics from the internal ISP-format to
118  * the host-format. This function does not include an additional copy
119  * step.
120  * */
121 void
122 ia_css_translate_3a_statistics(
123                 struct ia_css_3a_statistics               *host_stats,
124                 const struct ia_css_isp_3a_statistics_map *isp_stats);
125
126 /* Convenience functions for alloc/free of certain datatypes */
127
128 /** @brief Allocate memory for the 3a statistics on the ISP
129  * @param[in]   grid The grid.
130  * @return              Pointer to the allocated 3a statistics buffer on the ISP
131 */
132 struct ia_css_isp_3a_statistics *
133 ia_css_isp_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid);
134
135 /** @brief Free the 3a statistics memory on the isp
136  * @param[in]   me Pointer to the 3a statistics buffer on the ISP.
137  * @return              None
138 */
139 void
140 ia_css_isp_3a_statistics_free(struct ia_css_isp_3a_statistics *me);
141
142 /** @brief Allocate memory for the 3a statistics on the host
143  * @param[in]   grid The grid.
144  * @return              Pointer to the allocated 3a statistics buffer on the host
145 */
146 struct ia_css_3a_statistics *
147 ia_css_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid);
148
149 /** @brief Free the 3a statistics memory on the host
150  * @param[in]   me Pointer to the 3a statistics buffer on the host.
151  * @return              None
152  */
153 void
154 ia_css_3a_statistics_free(struct ia_css_3a_statistics *me);
155
156 /** @brief Allocate a 3a statistics map structure
157  * @param[in]   isp_stats pointer to ISP 3a statistis struct
158  * @param[in]   data_ptr  host-side pointer to ISP 3a statistics.
159  * @return              Pointer to the allocated 3a statistics map
160  *
161  * This function allocates the ISP 3a statistics map structure
162  * and uses the data_ptr as base pointer to set the appropriate
163  * pointers to all relevant subsets of the 3a statistics (dmem,
164  * vmem, hmem).
165  * If the data_ptr is NULL, this function will allocate the host-side
166  * memory. This information is stored in the struct and used in the
167  * ia_css_isp_3a_statistics_map_free() function to determine whether
168  * the memory should be freed or not.
169  * Note that this function does not allocate or map any ISP
170  * memory.
171 */
172 struct ia_css_isp_3a_statistics_map *
173 ia_css_isp_3a_statistics_map_allocate(
174         const struct ia_css_isp_3a_statistics *isp_stats,
175         void *data_ptr);
176
177 /** @brief Free the 3a statistics map
178  * @param[in]   me Pointer to the 3a statistics map
179  * @return              None
180  *
181  * This function frees the map struct. If the data_ptr inside it
182  * was allocated inside ia_css_isp_3a_statistics_map_allocate(), it
183  * will be freed in this function. Otherwise it will not be freed.
184  */
185 void
186 ia_css_isp_3a_statistics_map_free(struct ia_css_isp_3a_statistics_map *me);
187
188 #endif /* __IA_CSS_3A_H */