summaryrefslogtreecommitdiff
path: root/src/ipa/ipu3
AgeCommit message (Collapse)Author
2022-03-28ipa: ipu3: Ensure controls exists in before they are queriedUmang Jain
Add a validation check for sensor controls validateSensorControls() before they are queried in IPAIPU3::updateSessionConfiguration(). Fail the IPAIPU3::configure() if the required sensor controls are not found. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-03-28ipa: ipu3: Drop sensor controls private members from IPAIPU3Umang Jain
Drop exposure, gain private members from IPAIPU3 because the values are handled directly via IPAFrameContext. Move the default vblank value from IPAIPU3 to IPASessionConfiguration structure as it is a default static value not expected to change for a session. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-03-28ipa: ipu3: Consolidate querying of exposure and gain limitsUmang Jain
The exposure and gain limits are required for AGC configuration handled in IPAIPU3::updateSessionConfiguration(), which is happening already. Therefore the max/min private members in IPAIPU3 class for exposure/gain serve no use except setting initial values of exposure_ and gain_ members. Drop the max/min private members from IPAIPU3 class and set initial gain_ and exposure_ in IPAIPU3::updateSessionConfiguration(). Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-03-17ipa: ipu3: agc: Use existing local short-hand variable in configure()Laurent Pinchart
The configure() function has a local configuration variable referencing context.configuration for the purpose of shortening lines. Use it instead of context.configuration in the remaining locations, and constify it while at it as the configuration isn't meant to be modified. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-03-17ipa: ipu3: agc: Reset frame count when configuring AGCLaurent Pinchart
The frame count is used to skip the gain and exposure filtering when starting. It thus needs to be reset when configuring the algorithm, to avoid slower convergence when stopping and restarting. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-03-15ipa: ipu3: Send lens controls to pipeline handlerDaniel Scally
Pick up the focus value from the AF algorithm and send lens controls along in the frame context. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Daniel Scally <djrscally@gmail.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-03-15libcamera: ipa: Rename ctrls_ memberDaniel Scally
Now that we have added lens controls, rename the existiing member of the class to clarify that it relates to the sensor's controls. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Daniel Scally <djrscally@gmail.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-03-15libcamera: ipa: Add lens control member to ipu3 ipa interfaceDaniel Scally
Add further members to the ipu3 ipa interface that will hold lens controls passed in by configInfo Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Daniel Scally <djrscally@gmail.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-03-15ipa: ipu3: af: Auto focus for dw9719 Surface Go2 VCMKate Hsuan
Since VCM for surface Go 2 (dw9719) had been successfully driven, this Af module can be used to control the VCM and determine the focus value based on the IPU3 AF state. Based on the values from the IPU3 AF buffer, the variance of each focus step is determined and a greedy approach is used to find the maximum variance of the AF state and an appropriate focus value. The grid configuration is implemented as a context. Also, the grid parameter- AF_MIN_BLOCK_WIDTH is set to 4 (default is 3) since if the default value is used, x_start (x_start > 640) will be at an incorrect location of the image (rightmost of the sensor). Signed-off-by: Kate Hsuan <hpa@redhat.com> Tested-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-03-11ipa: ipu3: awb: Clamp gain valuesJean-Michel Hautbois
The gain values are coded as u3.13 fixed point values, ie they can not be more than 8. Clamp the values in order to avoid any off limits value which could make the IPU3 behave in a weird manner. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2022-03-11ipa: ipu3: agc: Introduce lineDuration in IPASessionConfigurationJean-Michel Hautbois
Instead of having a local cached value for line duration, store it in the IPASessionConfiguration::sensor structure. While at it, configure the default analogue gain and shutter speed to controlled fixed values. The latter is set to be 10ms as it will in most cases be close to the one needed, making the AGC faster to converge. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
2022-03-11ipa: ipu3: Shorten exposure and gain linesJean-Michel Hautbois
When the effective sensor values are stored during the EventStatReady event, the lines are long. Fix it. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
2022-03-11ipa: ipu3: Return filtered valueJean-Michel Hautbois
When the current exposure value is calculated, it is cached and used by filterExposure(). Use private filteredExposure_ and pass currentExposure as a parameter. In order to limit the use of filteredExposure_, return the value from filterExposure(). While at it, remove a stale comment. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
2021-12-07libcamera: Use utils::abs_diff()Laurent Pinchart
Use the new utils::abs_diff() function where appropriate to replace manual implementations. While at it fix a header ordering issue in src/libcamera/pipeline/raspberrypi/raspberrypi.cpp. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-11-30ipa: ipu3: Rectify gain value reporting in request metadataUmang Jain
Report value of sensor's gain pertaining to the current request completion, as that is the gain value the request completed with. The Agc algorithm processes the gain value for incoming next request hence it should not be reported in request's metadata. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-29ipa: libipa: Introduce Algorithm class templateJean-Michel Hautbois
The algorithms are using the same function names with specialized parameters. Instead of duplicating code, introduce a libipa Algorithm class which implements a base class with template parameters in libipa, and use it in each IPA. As we now won't need an algorithm class for each IPA, move the documentation to libipa, and make it agnostic of the IPA used. While at it, fix the IPU3::Algorithm::Awb documentation. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-11-29ipa: Do not modify the sensor limitsJean-Michel Hautbois
The driver is responsible for setting the proper limits for its controls. The IMX219 has an analogue gain of 1.0 when the gain code is set to 0, therefore we can not clamp to a minimum gain code of 1. Rework this for both IPU3 and RkISP1, for both Exposure and Gain controls. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-24ipa: ipu3: Convert to pragma onceKieran Bingham
Remove the verbose #ifndef/#define/#endif pattern for maintaining header idempotency, and replace it with a simple #pragma once. This simplifies the headers, and prevents redundant changes when header files get moved. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-11-23ipa: ipu3: Fix IPAContext documentationJean-Michel Hautbois
The shutter speed limits and analogue gains limits are in the agc structure in IPASessionConfiguration. They are badly mentioned as being part of the grid structure, fix it. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-11-23ipa: ipu3: agc: Saturate the averages when computing relative luminanceLaurent Pinchart
The relative luminance is calculated using an iterative process to account for saturation in the sensor, as multiplying pixels by a gain doesn't increase the relative luminance by the same factor if some regions are saturated. Relative luminance estimation doesn't apply a saturation, which produces a value that doesn't match what the sensor will output, and defeats the point of the iterative process. Fix it. Fixes: f8f07f9468c6 ("ipa: ipu3: agc: Improve gain calculation") Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-23ipa: ipu3: agc: Return the inter-quantile mean from measureBrightness()Laurent Pinchart
The inter-quantile mean is a value that is computed as part of the AGC run. It doesn't need to be stored in a member variable. Return it from measureBrightness(), which makes the flow of data easier to follow. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-23ipa: ipu3: agc: Rename currentYGainLaurent Pinchart
The "current" prefix in the currentYGain variable name is confusing: - In Agc::estimateLuminance(), the variable contains the gain to be applied to the image, which is neither a "current" gain nor a "Y" gain. Rename it to "gain". - In Agc::computeExposure(), the variable contains the gain computed by the relative luminance method, so rename it to "yGain". While at it, rename variables to match the libcamera coding style. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-23ipa: ipu3: agc: Standardize vocabulary on "relative luminance"Laurent Pinchart
The AGC computes the average relative luminance of the frame and calls the value "normalized luma", "brightness" or "initialY". The latter is the most accurate term, as the relative luminance is abbreviated Y, but the "initial" prefix isn't accurate. Standardize the vocabulary on "relative luminance" in code and comments, abbreviating it to Y when needed. While at it, rename variables to match the libcamera coding style. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-23ipa: ipu3: agc: Drop kMaxLuminance constantLaurent Pinchart
The kMaxLuminance constant is badly named, it's not a maximum luminance, but the maximum integer value output by the AWB statistics engine for per-channel averages. The constant is used in a single place, hardcoding the value is actually more readable. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-16ipa: ipu3: agc: Remove the threshold for the histogram calculationJean-Michel Hautbois
Until commit f8f07f9468c6 (ipa: ipu3: agc: Improve gain calculation) the gain to apply on the exposure value was only using the histogram. Now that the global brightness of the frame is estimated too, we don't need to remove part of the saturated pixels from the equation anymore. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-11-15ipa: ipu3: Set the AnalogueGain controlJean-Michel Hautbois
We can report the controls::AnalogueGain metadata now that AGC is updating it correctly. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: Move ExposureTime to IPAJean-Michel Hautbois
Now that we have the exposure time calculated, report it in the controls::ExposureTime and don't use the pipeline handler for it anymore. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: Cache line duration at configure callJean-Michel Hautbois
We use the line duration several times in the IPAIPU3. Instead of recalculating it each time, cache the value as a utils::Duration. ExposureTime and FrameDuration units are in micro-seconds, cast the Duration accordingly. As sensorInfo is no longer used in updateSessionConfiguration remove the reference to it. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: Send color temperature in the metadataJean-Michel Hautbois
Now that the color temperature is updated per-frame, use the value and set the corresponding controls::ColourTemperature. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: awb: Add support for color temperatureJean-Michel Hautbois
The AWB estimates the color temperature, but it is not used at all. It can be useful for debug purpose at least, but also for lux estimation later, to be able to know the temperature estimated for a given frame. Add a new member to the IPAFrameContext::awb for this purpose, and update the value in AWB. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: agc: Store exposure in units of timeJean-Michel Hautbois
The minimum and maximum exposure are stored in lines. Replace it by values in time to simplify the calculations. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: agc: Update previous exposure valueJean-Michel Hautbois
Previously, the exposure value was calculated based on the estimated shutter time and gain applied. Now that we have the real values for the current frame, use those before estimating the next one and rename the variable accordingly. As the exposure value is updated in the beginning of the computation, there is no need to initialize effectiveExposureValue anymore in the configure call, and it can be a local variable and not a class variable anymore. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: agc: Improve gain calculationJean-Michel Hautbois
When an image is partially saturated, its brightness is not increasing linearly when the shutter time or gain increases. It is a big issue with a backlight as the algorithm is fading to darkness right now. Introduce a function to estimate the brightness of the frame, based on the current exposure/gain and loop on it several times to estimate it again and approach the non linear function. Inspired-by: 7de5506c30b3 ("libcamera: src: ipa: raspberrypi: agc: Improve gain update calculation for partly saturated images") Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-11-15ipa: ipu3: agc: Refactor ev gain calculation and testingJean-Michel Hautbois
When we compute the new gain, we use the iqMean_ and estimate an exposure value gain to apply. Return early when the gain is less than 1%. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: agc: Compute the gain for each frameJean-Michel Hautbois
Now that we have the real exposure applied at each frame, remove the early return based on a frame counter and compute the gain for each frame. Introduce a number of startup frames during which the filter speed is 1.0, meaning we apply instantly the exposure value calculated and not a slower filtered one. This is used to have a faster convergence, and those frames may be dropped in a future development to hide the convergance process from the viewer. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: agc: Limit the number of saturated cellsJean-Michel Hautbois
When the histogram is calculated, we check if a cell is saturated or not before cumulating its green value. This is wrong, and it can lead to an empty histogram in case of a fully saturated frame. Use a constant to limit the amount of pixels within a cell before considering it saturated. If at the end of the loop we still have an empty histogram, then make it a fully saturated one. Bug: https://bugs.libcamera.org/show_bug.cgi?id=84 Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: Use sensor controls to update frameContextJean-Michel Hautbois
The pipeline handler populates the new sensorControls ControlList, to have the effective exposure and gain values for the current frame. This is done when a statistics buffer is received. Make those values the frameContext::sensor values for the frame when the EventStatReady event is received. AGC also needs to use frameContext.sensor as its input values and frameContext.agc as its output values. Modify computeExposure by passing it the frameContext instead of individual exposure and gain values. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-15ipa: ipu3: Extend ipu3 ipa interface for sensor controlsHan-Lin Chen
IPU3Event and IPU3Action use single ControlList for both libcamera and V4L2 controls, and it's content could be either one based on the context. Extend IPU3Event and IPU3Action for sensor V4L2 controls, and preserve the original one for only libcamera Controls to make the content of an event more specific. Signed-off-by: Han-Lin Chen <hanlinchen@chromium.org> [Jean-Michel: remove lensControls from the original patch] Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-11-06ipa: ipu3: List the events in their order of callingJean-Michel Hautbois
The IPU3 IPA has three events which are handled from the pipeline handler. The events are received in the sequence, EventProcessControls, EventFillParams, and finally EventStatReady, while the code lists these in a different order. Update the flow of IPAIPU3::processEvent() to match the expected sequence of events, to help support the reader in interpreting the flow of events through the IPA. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-10-26ipa: ipu3: agc: Clamp shutter speedJean-Michel Hautbois
In case the maximum exposure received from the sensor is very high, we can have a very high shutter speed with a small analogue gain, and it may result in very slow framerate. We are not really supporting it for the moment, so clamp the shutter speed to an arbitrary value of 60ms. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Tested-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-10-26ipa: ipu3: ipa_context: Fix doxygen warningsKieran Bingham
The IPAFrameContext uses unnamed structures to group items. Doxygen doesn't seem to support this properly, documentation isn't properly generated and warnings are output during compilation. Suppress the warning with a workaround that still results in incorrect generated documentation until Doxygen gets fixed. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> [JMH: Fix doxygen variable usage] Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-10-26ipa: ipu3: Implement an empty stop() functionJean-Michel Hautbois
While the stop() function does not currently perform any action, it forms part of the IPA interface and is a public function in the class. Promote it to a full (but basic) function implementation and begin the documentation accordingly so that there is an appropriate stub to perform stop operations if they come up. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-10-26ipa: ipu3: Fix badly documented context variablesJean-Michel Hautbois
Doxygen warns us because the structures are referenced as \struct while they should be \var. Fix it. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-10-26ipa: ipu3: Isolate ipa_context documentationKieran Bingham
The IPU3 IPA core is growing with additional documentation. The ipa_context documentation is stored here, but it pushes the IPU3 documentation and implementation further from the head of the file. Furthermore, the ipa_context documentation is outside of the ipa::ipu3 namespace and isn't identified correctly by Doxygen. Move the ipa_context to its own compilation object even though there isn't any code, but to maintain consistency with our documentation model. Correctly re-introduce the documentation into the libcamera::ipa::ipu3 namespace during the move. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-10-26ipa: ipu3: algorithms: awb: Privatize internal structuresKieran Bingham
The struct RGB and struct AwbStatus are used only by the internal implementation of the AWB algorithm module. Move them into the private class declaration. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-10-26ipa: ipu3: Fix the IPU3 AWB doxygen referencesKieran Bingham
The AWB AwbStatus structure is contained within the Awb class. Fix the Doxygen reference so that it can be found. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-10-26ipa: ipu3: ipa_context: Fix file referenceKieran Bingham
The ipa_context.h entry incorrectly referenced its file name. Fix it. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-10-26Documentation: IPU3 IPA Design guideKieran Bingham
The IPU3 IPA implements the basic 3A using the ImgU ISP. Provide an overview document to describe its operations, and provide a block diagram to help visualise how the components are put together to assist any new developers exploring the code. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
2021-10-26ipa: ipu3: tonemapping: Add the documentation for ToneMappingJean-Michel Hautbois
The tone mapping algorithm is currently undocumented. Provide an introduction and overview to the implementation as the class definition and document how the algorithm operates in the process and prepare methods. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-10-26ipa: ipu3: tonemapping: Implement configure callJean-Michel Hautbois
Let the algorithm perform its initial configuration. Implement configure() to set a default gamma value and let process do the updates needed. Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/* Copyright (C) 2017 - 2018 Intel Corporation */

#ifndef __IPU3_UAPI_H
#define __IPU3_UAPI_H

#include <linux/types.h>

/* from /drivers/staging/media/ipu3/include/videodev2.h */

/* Vendor specific - used for IPU3 camera sub-system */
/* IPU3 processing parameters */
#define V4L2_META_FMT_IPU3_PARAMS	v4l2_fourcc('i', 'p', '3', 'p')
/* IPU3 3A statistics */
#define V4L2_META_FMT_IPU3_STAT_3A	v4l2_fourcc('i', 'p', '3', 's')

/* from include/uapi/linux/v4l2-controls.h */
#define V4L2_CID_INTEL_IPU3_BASE	(V4L2_CID_USER_BASE + 0x10c0)
#define V4L2_CID_INTEL_IPU3_MODE	(V4L2_CID_INTEL_IPU3_BASE + 1)

/******************* ipu3_uapi_stats_3a *******************/

#define IPU3_UAPI_MAX_STRIPES				2
#define IPU3_UAPI_MAX_BUBBLE_SIZE			10

#define IPU3_UAPI_GRID_START_MASK			((1 << 12) - 1)
#define IPU3_UAPI_GRID_Y_START_EN			(1 << 15)

/* controls generation of meta_data (like FF enable/disable) */
#define IPU3_UAPI_AWB_RGBS_THR_B_EN			(1 << 14)
#define IPU3_UAPI_AWB_RGBS_THR_B_INCL_SAT		(1 << 15)

/**
 * struct ipu3_uapi_grid_config - Grid plane config
 *
 * @width:	Grid horizontal dimensions, in number of grid blocks(cells).
 *		For AWB, the range is (16, 80).
 *		For AF/AE, the range is (16, 32).
 * @height:	Grid vertical dimensions, in number of grid cells.
 *		For AWB, the range is (16, 60).
 *		For AF/AE, the range is (16, 24).
 * @block_width_log2:	Log2 of the width of each cell in pixels.
 *			For AWB, the range is [3, 6].
 *			For AF/AE, the range is [3, 7].
 * @block_height_log2:	Log2 of the height of each cell in pixels.
 *			For AWB, the range is [3, 6].
 *			For AF/AE, the range is [3, 7].
 * @height_per_slice:	The number of blocks in vertical axis per slice.
 *			Default 2.
 * @x_start: X value of top left corner of Region of Interest(ROI).
 * @y_start: Y value of top left corner of ROI
 * @x_end: X value of bottom right corner of ROI
 * @y_end: Y value of bottom right corner of ROI
 *
 * Due to the size of total amount of collected data, most statistics
 * create a grid-based output, and the data is then divided into "slices".
 */
struct ipu3_uapi_grid_config {
	__u8 width;
	__u8 height;
	__u16 block_width_log2:3;
	__u16 block_height_log2:3;
	__u16 height_per_slice:8;
	__u16 x_start;
	__u16 y_start;
	__u16 x_end;
	__u16 y_end;
} __attribute__((packed));

/**
 * struct ipu3_uapi_awb_set_item - Memory layout for each cell in AWB
 *
 * @Gr_avg:	Green average for red lines in the cell.
 * @R_avg:	Red average in the cell.
 * @B_avg:	Blue average in the cell.
 * @Gb_avg:	Green average for blue lines in the cell.
 * @sat_ratio:  Percentage of pixels over the thresholds specified in
 *		ipu3_uapi_awb_config_s, coded from 0 to 255.
 * @padding0:   Unused byte for padding.
 * @padding1:   Unused byte for padding.
 * @padding2:   Unused byte for padding.
 */
struct ipu3_uapi_awb_set_item {
	__u8 Gr_avg;
	__u8 R_avg;
	__u8 B_avg;
	__u8 Gb_avg;
	__u8 sat_ratio;
	__u8 padding0;
	__u8 padding1;
	__u8 padding2;
} __attribute__((packed));

/*
 * The grid based data is divided into "slices" called set, each slice of setX
 * refers to ipu3_uapi_grid_config width * height_per_slice.
 */
#define IPU3_UAPI_AWB_MAX_SETS				60
/* Based on grid size 80 * 60 and cell size 16 x 16 */
#define IPU3_UAPI_AWB_SET_SIZE				160
#define IPU3_UAPI_AWB_SPARE_FOR_BUBBLES \
	(IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES)
#define IPU3_UAPI_AWB_MAX_BUFFER_SIZE \
	(IPU3_UAPI_AWB_MAX_SETS * \
	 (IPU3_UAPI_AWB_SET_SIZE + IPU3_UAPI_AWB_SPARE_FOR_BUBBLES))

/**
 * struct ipu3_uapi_awb_raw_buffer - AWB raw buffer
 *
 * @meta_data: buffer to hold auto white balance meta data which is
 *		the average values for each color channel.
 */
struct ipu3_uapi_awb_raw_buffer {
	struct ipu3_uapi_awb_set_item meta_data[IPU3_UAPI_AWB_MAX_BUFFER_SIZE]
		__attribute__((aligned(32)));
} __attribute__((packed));

/**
 * struct ipu3_uapi_awb_config_s - AWB config
 *
 * @rgbs_thr_gr: gr threshold value.
 * @rgbs_thr_r: Red threshold value.
 * @rgbs_thr_gb: gb threshold value.
 * @rgbs_thr_b: Blue threshold value.
 * @grid: &ipu3_uapi_grid_config, the default grid resolution is 16x16 cells.
 *
 * The threshold is a saturation measure range [0, 8191], 8191 is default.
 * Values over threshold may be optionally rejected for averaging.
 */
struct ipu3_uapi_awb_config_s {
	__u16 rgbs_thr_gr;
	__u16 rgbs_thr_r;
	__u16 rgbs_thr_gb;
	__u16 rgbs_thr_b;
	struct ipu3_uapi_grid_config grid;
} __attribute__((aligned(32))) __attribute__((packed));

/**
 * struct ipu3_uapi_awb_config - AWB config wrapper
 *
 * @config: config for auto white balance as defined by &ipu3_uapi_awb_config_s
 */
struct ipu3_uapi_awb_config {
	struct ipu3_uapi_awb_config_s config __attribute__((aligned(32)));
} __attribute__((packed));

#define IPU3_UAPI_AE_COLORS				4	/* R, G, B, Y */
#define IPU3_UAPI_AE_BINS				256
#define IPU3_UAPI_AE_WEIGHTS				96

/**
 * struct ipu3_uapi_ae_raw_buffer - AE global weighted histogram
 *
 * @vals: Sum of IPU3_UAPI_AE_COLORS in cell
 *
 * Each histogram contains IPU3_UAPI_AE_BINS bins. Each bin has 24 bit unsigned
 * for counting the number of the pixel.
 */
struct ipu3_uapi_ae_raw_buffer {
	__u32 vals[IPU3_UAPI_AE_BINS * IPU3_UAPI_AE_COLORS];
} __attribute__((packed));

/**
 * struct ipu3_uapi_ae_raw_buffer_aligned - AE raw buffer
 *
 * @buff: &ipu3_uapi_ae_raw_buffer to hold full frame meta data.
 */
struct ipu3_uapi_ae_raw_buffer_aligned {
	struct ipu3_uapi_ae_raw_buffer buff __attribute__((aligned(32)));
} __attribute__((packed));

/**
 * struct ipu3_uapi_ae_grid_config - AE weight grid
 *
 * @width: Grid horizontal dimensions. Value: [16, 32], default 16.
 * @height: Grid vertical dimensions. Value: [16, 24], default 16.
 * @block_width_log2: Log2 of the width of the grid cell, value: [3, 7].
 * @block_height_log2: Log2 of the height of the grid cell, value: [3, 7].
 *			default is 3 (cell size 8x8), 4 cell per grid.
 * @reserved0: reserved
 * @ae_en: 0: does not write to &ipu3_uapi_ae_raw_buffer_aligned array,
 *		1: write normally.
 * @rst_hist_array: write 1 to trigger histogram array reset.
 * @done_rst_hist_array: flag for histogram array reset done.
 * @x_start: X value of top left corner of ROI, default 0.
 * @y_start: Y value of top left corner of ROI, default 0.
 * @x_end: X value of bottom right corner of ROI
 * @y_end: Y value of bottom right corner of ROI
 *
 * The AE block accumulates 4 global weighted histograms(R, G, B, Y) over
 * a defined ROI within the frame. The contribution of each pixel into the
 * histogram, defined by &ipu3_uapi_ae_weight_elem LUT, is indexed by a grid.
 */
struct ipu3_uapi_ae_grid_config {
	__u8 width;
	__u8 height;
	__u8 block_width_log2:4;
	__u8 block_height_log2:4;
	__u8 reserved0:5;
	__u8 ae_en:1;
	__u8 rst_hist_array:1;
	__u8 done_rst_hist_array:1;
	__u16 x_start;
	__u16 y_start;
	__u16 x_end;
	__u16 y_end;
} __attribute__((packed));

/**
 * struct ipu3_uapi_ae_weight_elem - AE weights LUT
 *
 * @cell0: weighted histogram grid value.
 * @cell1: weighted histogram grid value.
 * @cell2: weighted histogram grid value.
 * @cell3: weighted histogram grid value.
 * @cell4: weighted histogram grid value.
 * @cell5: weighted histogram grid value.
 * @cell6: weighted histogram grid value.
 * @cell7: weighted histogram grid value.
 *
 * Use weighted grid value to give a different contribution factor to each cell.
 * Precision u4, range [0, 15].
 */
struct ipu3_uapi_ae_weight_elem {
	__u32 cell0:4;
	__u32 cell1:4;
	__u32 cell2:4;
	__u32 cell3:4;
	__u32 cell4:4;
	__u32 cell5:4;
	__u32 cell6:4;
	__u32 cell7:4;
} __attribute__((packed));

/**
 * struct ipu3_uapi_ae_ccm - AE coefficients for WB and CCM
 *
 * @gain_gr: WB gain factor for the gr channels. Default 256.
 * @gain_r: WB gain factor for the r channel. Default 256.
 * @gain_b: WB gain factor for the b channel. Default 256.
 * @gain_gb: WB gain factor for the gb channels. Default 256.
 * @mat: 4x4 matrix that transforms Bayer quad output from WB to RGB+Y.
 *
 * Default:
 *	128, 0, 0, 0,
 *	0, 128, 0, 0,
 *	0, 0, 128, 0,
 *	0, 0, 0, 128,
 *
 * As part of the raw frame pre-process stage, the WB and color conversion need
 * to be applied to expose the impact of these gain operations.
 */
struct ipu3_uapi_ae_ccm {
	__u16 gain_gr;
	__u16 gain_r;
	__u16 gain_b;
	__u16 gain_gb;
	__s16 mat[16];
} __attribute__((packed));

/**
 * struct ipu3_uapi_ae_config - AE config
 *
 * @grid_cfg:	config for auto exposure statistics grid. See struct
 *		&ipu3_uapi_ae_grid_config, as Imgu did not support output
 *		auto exposure statistics, so user can ignore this configuration
 *		and use the RGB table in auto-whitebalance statistics instead.
 * @weights:	&IPU3_UAPI_AE_WEIGHTS is based on 32x24 blocks in the grid.
 *		Each grid cell has a corresponding value in weights LUT called
 *		grid value, global histogram is updated based on grid value and
 *		pixel value.
 * @ae_ccm:	Color convert matrix pre-processing block.
 *
 * Calculate AE grid from image resolution, resample ae weights.
 */
struct ipu3_uapi_ae_config {
	struct ipu3_uapi_ae_grid_config grid_cfg __attribute__((aligned(32)));
	struct ipu3_uapi_ae_weight_elem weights[IPU3_UAPI_AE_WEIGHTS]
						__attribute__((aligned(32)));
	struct ipu3_uapi_ae_ccm ae_ccm __attribute__((aligned(32)));
} __attribute__((packed));

/**
 * struct ipu3_uapi_af_filter_config - AF 2D filter for contrast measurements
 *
 * @y1_coeff_0:	filter Y1, structure: 3x11, support both symmetry and
 *		anti-symmetry type. A12 is center, A1-A11 are neighbours.
 *		for analyzing low frequency content, used to calculate sum
 *		of gradients in x direction.
 * @y1_coeff_0.a1:	filter1 coefficients A1, u8, default 0.
 * @y1_coeff_0.a2:	filter1 coefficients A2, u8, default 0.
 * @y1_coeff_0.a3:	filter1 coefficients A3, u8, default 0.
 * @y1_coeff_0.a4:	filter1 coefficients A4, u8, default 0.
 * @y1_coeff_1:		Struct
 * @y1_coeff_1.a5:	filter1 coefficients A5, u8, default 0.
 * @y1_coeff_1.a6:	filter1 coefficients A6, u8, default 0.
 * @y1_coeff_1.a7:	filter1 coefficients A7, u8, default 0.
 * @y1_coeff_1.a8:	filter1 coefficients A8, u8, default 0.
 * @y1_coeff_2:		Struct
 * @y1_coeff_2.a9:	filter1 coefficients A9, u8, default 0.
 * @y1_coeff_2.a10:	filter1 coefficients A10, u8, default 0.
 * @y1_coeff_2.a11:	filter1 coefficients A11, u8, default 0.
 * @y1_coeff_2.a12:	filter1 coefficients A12, u8, default 128.
 * @y1_sign_vec:	Each bit corresponds to one coefficient sign bit,
 *			0: positive, 1: negative, default 0.
 * @y2_coeff_0:	Y2, same structure as Y1. For analyzing high frequency content.
 * @y2_coeff_0.a1:	filter2 coefficients A1, u8, default 0.
 * @y2_coeff_0.a2:	filter2 coefficients A2, u8, default 0.
 * @y2_coeff_0.a3:	filter2 coefficients A3, u8, default 0.
 * @y2_coeff_0.a4:	filter2 coefficients A4, u8, default 0.
 * @y2_coeff_1:	Struct
 * @y2_coeff_1.a5:	filter2 coefficients A5, u8, default 0.
 * @y2_coeff_1.a6:	filter2 coefficients A6, u8, default 0.
 * @y2_coeff_1.a7:	filter2 coefficients A7, u8, default 0.
 * @y2_coeff_1.a8:	filter2 coefficients A8, u8, default 0.
 * @y2_coeff_2:	Struct
 * @y2_coeff_2.a9:	filter1 coefficients A9, u8, default 0.
 * @y2_coeff_2.a10:	filter1 coefficients A10, u8, default 0.
 * @y2_coeff_2.a11:	filter1 coefficients A11, u8, default 0.
 * @y2_coeff_2.a12:	filter1 coefficients A12, u8, default 128.
 * @y2_sign_vec:	Each bit corresponds to one coefficient sign bit,
 *			0: positive, 1: negative, default 0.
 * @y_calc:	Pre-processing that converts Bayer quad to RGB+Y values to be
 *		used for building histogram. Range [0, 32], default 8.
 * Rule:
 *		y_gen_rate_gr + y_gen_rate_r + y_gen_rate_b + y_gen_rate_gb = 32
 *		A single Y is calculated based on sum of Gr/R/B/Gb based on
 *		their contribution ratio.
 * @y_calc.y_gen_rate_gr:	Contribution ratio Gr for Y
 * @y_calc.y_gen_rate_r:	Contribution ratio R for Y
 * @y_calc.y_gen_rate_b:	Contribution ratio B for Y
 * @y_calc.y_gen_rate_gb:	Contribution ratio Gb for Y
 * @nf:	The shift right value that should be applied during the Y1/Y2 filter to
 *	make sure the total memory needed is 2 bytes per grid cell.
 * @nf.reserved0:	reserved
 * @nf.y1_nf:	Normalization factor for the convolution coeffs of y1,
 *		should be log2 of the sum of the abs values of the filter
 *		coeffs, default 7 (2^7 = 128).
 * @nf.reserved1:	reserved
 * @nf.y2_nf:	Normalization factor for y2, should be log2 of the sum of the
 *		abs values of the filter coeffs.
 * @nf.reserved2:	reserved
 */
struct ipu3_uapi_af_filter_config {
	struct {
		__u8 a1;
		__u8 a2;
		__u8 a3;
		__u8 a4;
	} y1_coeff_0;
	struct {
		__u8 a5;
		__u8 a6;
		__u8 a7;
		__u8 a8;
	} y1_coeff_1;
	struct {
		__u8 a9;
		__u8 a10;
		__u8 a11;
		__u8 a12;
	} y1_coeff_2;

	__u32 y1_sign_vec;

	struct {
		__u8 a1;
		__u8 a2;
		__u8 a3;
		__u8 a4;
	} y2_coeff_0;
	struct {
		__u8 a5;
		__u8 a6;
		__u8 a7;
		__u8 a8;
	} y2_coeff_1;
	struct {
		__u8 a9;
		__u8 a10;
		__u8 a11;
		__u8 a12;
	} y2_coeff_2;

	__u32 y2_sign_vec;

	struct {
		__u8 y_gen_rate_gr;
		__u8 y_gen_rate_r;
		__u8 y_gen_rate_b;
		__u8 y_gen_rate_gb;
	} y_calc;

	struct {
		__u32 reserved0:8;
		__u32 y1_nf:4;
		__u32 reserved1:4;
		__u32 y2_nf:4;
		__u32 reserved2:12;
	} nf;
} __attribute__((packed));

#define IPU3_UAPI_AF_MAX_SETS				24
#define IPU3_UAPI_AF_MD_ITEM_SIZE			4
#define IPU3_UAPI_AF_SPARE_FOR_BUBBLES \
	(IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \
	 IPU3_UAPI_AF_MD_ITEM_SIZE)
#define IPU3_UAPI_AF_Y_TABLE_SET_SIZE			128
#define IPU3_UAPI_AF_Y_TABLE_MAX_SIZE \
	(IPU3_UAPI_AF_MAX_SETS * \
	 (IPU3_UAPI_AF_Y_TABLE_SET_SIZE + IPU3_UAPI_AF_SPARE_FOR_BUBBLES) * \
	 IPU3_UAPI_MAX_STRIPES)

/**
 * struct ipu3_uapi_af_raw_buffer - AF meta data
 *
 * @y_table:	Each color component will be convolved separately with filter1
 *		and filter2 and the result will be summed out and averaged for
 *		each cell.
 */
struct ipu3_uapi_af_raw_buffer {
	__u8 y_table[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE] __attribute__((aligned(32)));
} __attribute__((packed));

/**
 * struct ipu3_uapi_af_config_s - AF config
 *
 * @filter_config: AF uses Y1 and Y2 filters as configured in
 *		   &ipu3_uapi_af_filter_config
 * @padding: paddings
 * @grid_cfg: See &ipu3_uapi_grid_config, default resolution 16x16. Use large
 *	      grid size for large image and vice versa.
 */
struct ipu3_uapi_af_config_s {
	struct ipu3_uapi_af_filter_config filter_config __attribute__((aligned(32)));
	__u8 padding[4];
	struct ipu3_uapi_grid_config grid_cfg __attribute__((aligned(32)));
} __attribute__((packed));

#define IPU3_UAPI_AWB_FR_MAX_SETS			24
#define IPU3_UAPI_AWB_FR_MD_ITEM_SIZE			8
#define IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE			256
#define IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES \
	(IPU3_UAPI_MAX_BUBBLE_SIZE * IPU3_UAPI_MAX_STRIPES * \
	 IPU3_UAPI_AWB_FR_MD_ITEM_SIZE)
#define IPU3_UAPI_AWB_FR_BAYER_TABLE_MAX_SIZE \
	(IPU3_UAPI_AWB_FR_MAX_SETS * \
	(IPU3_UAPI_AWB_FR_BAYER_TBL_SIZE + \
	 IPU3_UAPI_AWB_FR_SPARE_FOR_BUBBLES) * IPU3_UAPI_MAX_STRIPES)

/**
 * struct ipu3_uapi_awb_fr_raw_buffer - AWB filter response meta data
 *
 * @meta_data: Statistics output on the grid after convolving with 1D filter.
 */
struct ipu3_uapi_awb_fr_raw_buffer {
	__u8 meta_data[IPU3_UAPI_AWB_FR_BAYER_TABLE_MAX_SIZE]
		__attribute__((aligned(32)));
} __attribute__((packed));

/**
 * struct ipu3_uapi_awb_fr_config_s - AWB filter response config
 *
 * @grid_cfg:	grid config, default 16x16.
 * @bayer_coeff:	1D Filter 1x11 center symmetry/anti-symmetry.
 *			coefficients defaults { 0, 0, 0, 0, 0, 128 }.
 *			Applied on whole image for each Bayer channel separately
 *			by a weighted sum of its 11x1 neighbors.
 * @reserved1:	reserved
 * @bayer_sign:	sign of filter coefficients, default 0.
 * @bayer_nf:	normalization factor for the convolution coeffs, to make sure
 *		total memory needed is within pre-determined range.
 *		NF should be the log2 of the sum of the abs values of the
 *		filter coeffs, range [7, 14], default 7.
 * @reserved2:	reserved
 */
struct ipu3_uapi_awb_fr_config_s {
	struct ipu3_uapi_grid_config grid_cfg;
	__u8 bayer_coeff[6];
	__u16 reserved1;
	__u32 bayer_sign;
	__u8 bayer_nf;
	__u8 reserved2[7];
} __attribute__((packed));

/**
 * struct ipu3_uapi_4a_config - 4A config
 *
 * @awb_config: &ipu3_uapi_awb_config_s, default resolution 16x16
 * @ae_grd_config: auto exposure statistics &ipu3_uapi_ae_grid_config
 * @padding: paddings
 * @af_config: auto focus config &ipu3_uapi_af_config_s
 * @awb_fr_config: &ipu3_uapi_awb_fr_config_s, default resolution 16x16
 */
struct ipu3_uapi_4a_config {
	struct ipu3_uapi_awb_config_s awb_config __attribute__((aligned(32)));
	struct ipu3_uapi_ae_grid_config ae_grd_config;
	__u8 padding[20];
	struct ipu3_uapi_af_config_s af_config;
	struct ipu3_uapi_awb_fr_config_s awb_fr_config
		__attribute__((aligned(32)));
} __attribute__((packed));

/**
 * struct ipu3_uapi_bubble_info - Bubble info for host side debugging
 *
 * @num_of_stripes: A single frame is divided into several parts called stripes
 *		    due to limitation on line buffer memory.
 *		    The separation between the stripes is vertical. Each such
 *		    stripe is processed as a single frame by the ISP pipe.
 * @padding: padding bytes.
 * @num_sets: number of sets.
 * @padding1: padding bytes.
 * @size_of_set: set size.
 * @padding2: padding bytes.
 * @bubble_size: is the amount of padding in the bubble expressed in "sets".
 * @padding3: padding bytes.
 */
struct ipu3_uapi_bubble_info {
	__u32 num_of_stripes __attribute__((aligned(32)));
	__u8 padding[28];
	__u32 num_sets;
	__u8 padding1[28];
	__u32 size_of_set;
	__u8 padding2[28];
	__u32 bubble_size;
	__u8 padding3[28];
} __attribute__((packed));

/*
 * struct ipu3_uapi_stats_3a_bubble_info_per_stripe
 */
struct ipu3_uapi_stats_3a_bubble_info_per_stripe {
	struct ipu3_uapi_bubble_info awb[IPU3_UAPI_MAX_STRIPES];
	struct ipu3_uapi_bubble_info af[IPU3_UAPI_MAX_STRIPES];
	struct ipu3_uapi_bubble_info awb_fr[IPU3_UAPI_MAX_STRIPES];
} __attribute__((packed));

/**
 * struct ipu3_uapi_ff_status - Enable bits for each 3A fixed function
 *
 * @awb_en: auto white balance enable
 * @padding: padding config
 * @ae_en: auto exposure enable
 * @padding1: padding config
 * @af_en: auto focus enable
 * @padding2: padding config
 * @awb_fr_en: awb filter response enable bit
 * @padding3: padding config
 */
struct ipu3_uapi_ff_status {
	__u32 awb_en __attribute__((aligned(32)));
	__u8 padding[28];
	__u32 ae_en;
	__u8 padding1[28];
	__u32 af_en;
	__u8 padding2[28];
	__u32 awb_fr_en;
	__u8 padding3[28];
} __attribute__((packed));

/**
 * struct ipu3_uapi_stats_3a - 3A statistics
 *
 * @awb_raw_buffer: auto white balance meta data &ipu3_uapi_awb_raw_buffer
 * @ae_raw_buffer: auto exposure raw data &ipu3_uapi_ae_raw_buffer_aligned
 *                 current Imgu does not output the auto exposure statistics
 *                 to ae_raw_buffer, the user such as 3A algorithm can use the
 *                 RGB table in &ipu3_uapi_awb_raw_buffer to do auto-exposure.
 * @af_raw_buffer: &ipu3_uapi_af_raw_buffer for auto focus meta data
 * @awb_fr_raw_buffer: value as specified by &ipu3_uapi_awb_fr_raw_buffer
 * @stats_4a_config: 4a statistics config as defined by &ipu3_uapi_4a_config.
 * @ae_join_buffers: 1 to use ae_raw_buffer.
 * @padding: padding config
 * @stats_3a_bubble_per_stripe: a &ipu3_uapi_stats_3a_bubble_info_per_stripe
 * @stats_3a_status: 3a statistics status set in &ipu3_uapi_ff_status
 */
struct ipu3_uapi_stats_3a {
	struct ipu3_uapi_awb_raw_buffer awb_raw_buffer;
	struct ipu3_uapi_ae_raw_buffer_aligned
			ae_raw_buffer[IPU3_UAPI_MAX_STRIPES];
	struct ipu3_uapi_af_raw_buffer af_raw_buffer;
	struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer;
	struct ipu3_uapi_4a_config stats_4a_config;
	__u32 ae_join_buffers;
	__u8 padding[28];
	struct ipu3_uapi_stats_3a_bubble_info_per_stripe
			stats_3a_bubble_per_stripe;
	struct ipu3_uapi_ff_status stats_3a_status;
} __attribute__((packed));

/******************* ipu3_uapi_acc_param *******************/

#define IPU3_UAPI_ISP_VEC_ELEMS				64
#define IPU3_UAPI_ISP_TNR3_VMEM_LEN			9

#define IPU3_UAPI_BNR_LUT_SIZE				32

/* number of elements in gamma correction LUT */
#define IPU3_UAPI_GAMMA_CORR_LUT_ENTRIES		256

/* largest grid is 73x56, for grid_height_per_slice of 2, 73x2 = 146 */
#define IPU3_UAPI_SHD_MAX_CELLS_PER_SET			146
#define IPU3_UAPI_SHD_MAX_CFG_SETS			28
/* Normalization shift aka nf */
#define IPU3_UAPI_SHD_BLGR_NF_SHIFT			13
#define IPU3_UAPI_SHD_BLGR_NF_MASK			7

#define IPU3_UAPI_YUVP2_TCC_MACC_TABLE_ELEMENTS		16
#define IPU3_UAPI_YUVP2_TCC_INV_Y_LUT_ELEMENTS		14
#define IPU3_UAPI_YUVP2_TCC_GAIN_PCWL_LUT_ELEMENTS	258
#define IPU3_UAPI_YUVP2_TCC_R_SQR_LUT_ELEMENTS		24

#define IPU3_UAPI_ANR_LUT_SIZE				26
#define IPU3_UAPI_ANR_PYRAMID_SIZE			22

#define IPU3_UAPI_LIN_LUT_SIZE				64

/* Bayer Noise Reduction related structs */

/**
 * struct ipu3_uapi_bnr_static_config_wb_gains_config - White balance gains
 *
 * @gr:	white balance gain for Gr channel.
 * @r:	white balance gain for R channel.
 * @b:	white balance gain for B channel.
 * @gb:	white balance gain for Gb channel.
 *
 * Precision u3.13, range [0, 8). White balance correction is done by applying
 * a multiplicative gain to each color channels prior to BNR.
 */
struct ipu3_uapi_bnr_static_config_wb_gains_config {
	__u16 gr;
	__u16 r;
	__u16 b;
	__u16 gb;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_wb_gains_thr_config - Threshold config
 *
 * @gr:	white balance threshold gain for Gr channel.
 * @r:	white balance threshold gain for R channel.
 * @b:	white balance threshold gain for B channel.
 * @gb:	white balance threshold gain for Gb channel.
 *
 * Defines the threshold that specifies how different a defect pixel can be from
 * its neighbors.(used by dynamic defect pixel correction sub block)
 * Precision u4.4 range [0, 8].
 */
struct ipu3_uapi_bnr_static_config_wb_gains_thr_config {
	__u8 gr;
	__u8 r;
	__u8 b;
	__u8 gb;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_thr_coeffs_config - Noise model
 *				coefficients that controls noise threshold
 *
 * @cf:	Free coefficient for threshold calculation, range [0, 8191], default 0.
 * @reserved0:	reserved
 * @cg:	Gain coefficient for threshold calculation, [0, 31], default 8.
 * @ci:	Intensity coefficient for threshold calculation. range [0, 0x1f]
 *	default 6.
 *	format: u3.2 (3 most significant bits represent whole number,
 *	2 least significant bits represent the fractional part
 *	with each count representing 0.25)
 *	e.g. 6 in binary format is 00110, that translates to 1.5
 * @reserved1:	reserved
 * @r_nf:	Normalization shift value for r^2 calculation, range [12, 20]
 *		where r is a radius of pixel [row, col] from centor of sensor.
 *		default 14.
 *
 * Threshold used to distinguish between noise and details.
 */
struct ipu3_uapi_bnr_static_config_thr_coeffs_config {
	__u32 cf:13;
	__u32 reserved0:3;
	__u32 cg:5;
	__u32 ci:5;
	__u32 reserved1:1;
	__u32 r_nf:5;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_thr_ctrl_shd_config - Shading config
 *
 * @gr:	Coefficient defines lens shading gain approximation for gr channel
 * @r:	Coefficient defines lens shading gain approximation for r channel
 * @b:	Coefficient defines lens shading gain approximation for b channel
 * @gb:	Coefficient defines lens shading gain approximation for gb channel
 *
 * Parameters for noise model (NM) adaptation of BNR due to shading correction.
 * All above have precision of u3.3, default to 0.
 */
struct ipu3_uapi_bnr_static_config_thr_ctrl_shd_config {
	__u8 gr;
	__u8 r;
	__u8 b;
	__u8 gb;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_opt_center_config - Optical center config
 *
 * @x_reset:	Reset value of X (col start - X center). Precision s12.0.
 * @reserved0:	reserved
 * @y_reset:	Reset value of Y (row start - Y center). Precision s12.0.
 * @reserved2:	reserved
 *
 * Distance from corner to optical center for NM adaptation due to shading
 * correction (should be calculated based on shading tables)
 */
struct ipu3_uapi_bnr_static_config_opt_center_config {
	__s32 x_reset:13;
	__u32 reserved0:3;
	__s32 y_reset:13;
	__u32 reserved2:3;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_lut_config - BNR square root lookup table
 *
 * @values: pre-calculated values of square root function.
 *
 * LUT implementation of square root operation.
 */
struct ipu3_uapi_bnr_static_config_lut_config {
	__u8 values[IPU3_UAPI_BNR_LUT_SIZE];
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_bp_ctrl_config - Detect bad pixels (bp)
 *
 * @bp_thr_gain:	Defines the threshold that specifies how different a
 *			defect pixel can be from its neighbors. Threshold is
 *			dependent on de-noise threshold calculated by algorithm.
 *			Range [4, 31], default 4.
 * @reserved0:	reserved
 * @defect_mode:	Mode of addressed defect pixels,
 *			0 - single defect pixel is expected,
 *			1 - 2 adjacent defect pixels are expected, default 1.
 * @bp_gain:	Defines how 2nd derivation that passes through a defect pixel
 *		is different from 2nd derivations that pass through
 *		neighbor pixels. u4.2, range [0, 256], default 8.
 * @reserved1:	reserved
 * @w0_coeff:	Blending coefficient of defect pixel correction.
 *		Precision u4, range [0, 8], default 8.
 * @reserved2:	reserved
 * @w1_coeff:	Enable influence of incorrect defect pixel correction to be
 *		avoided. Precision u4, range [1, 8], default 8.
 * @reserved3:	reserved
 */
struct ipu3_uapi_bnr_static_config_bp_ctrl_config {
	__u32 bp_thr_gain:5;
	__u32 reserved0:2;
	__u32 defect_mode:1;
	__u32 bp_gain:6;
	__u32 reserved1:18;
	__u32 w0_coeff:4;
	__u32 reserved2:4;
	__u32 w1_coeff:4;
	__u32 reserved3:20;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_dn_detect_ctrl_config - Denoising config
 *
 * @alpha:	Weight of central element of smoothing filter.
 * @beta:	Weight of peripheral elements of smoothing filter, default 4.
 * @gamma:	Weight of diagonal elements of smoothing filter, default 4.
 *
 * beta and gamma parameter define the strength of the noise removal filter.
 *		All above has precision u0.4, range [0, 0xf]
 *		format: u0.4 (no / zero bits represent whole number,
 *		4 bits represent the fractional part
 *		with each count representing 0.0625)
 *		e.g. 0xf translates to 0.0625x15 = 0.9375
 *
 * @reserved0:	reserved
 * @max_inf:	Maximum increase of peripheral or diagonal element influence
 *		relative to the pre-defined value range: [0x5, 0xa]
 * @reserved1:	reserved
 * @gd_enable:	Green disparity enable control, 0 - disable, 1 - enable.
 * @bpc_enable:	Bad pixel correction enable control, 0 - disable, 1 - enable.
 * @bnr_enable:	Bayer noise removal enable control, 0 - disable, 1 - enable.
 * @ff_enable:	Fixed function enable, 0 - disable, 1 - enable.
 * @reserved2:	reserved
 */
struct ipu3_uapi_bnr_static_config_dn_detect_ctrl_config {
	__u32 alpha:4;
	__u32 beta:4;
	__u32 gamma:4;
	__u32 reserved0:4;
	__u32 max_inf:4;
	__u32 reserved1:7;
	__u32 gd_enable:1;
	__u32 bpc_enable:1;
	__u32 bnr_enable:1;
	__u32 ff_enable:1;
	__u32 reserved2:1;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_opt_center_sqr_config - BNR optical square
 *
 * @x_sqr_reset: Reset value of X^2.
 * @y_sqr_reset: Reset value of Y^2.
 *
 * Please note:
 *
 *    #. X and Y ref to
 *       &ipu3_uapi_bnr_static_config_opt_center_config
 *    #. Both structs are used in threshold formula to calculate r^2, where r
 *       is a radius of pixel [row, col] from centor of sensor.
 */
struct ipu3_uapi_bnr_static_config_opt_center_sqr_config {
	__u32 x_sqr_reset;
	__u32 y_sqr_reset;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config - BNR static config
 *
 * @wb_gains:	white balance gains &ipu3_uapi_bnr_static_config_wb_gains_config
 * @wb_gains_thr:	white balance gains threshold as defined by
 *			&ipu3_uapi_bnr_static_config_wb_gains_thr_config
 * @thr_coeffs:	coefficients of threshold
 *		&ipu3_uapi_bnr_static_config_thr_coeffs_config
 * @thr_ctrl_shd:	control of shading threshold
 *			&ipu3_uapi_bnr_static_config_thr_ctrl_shd_config
 * @opt_center:	optical center &ipu3_uapi_bnr_static_config_opt_center_config
 *
 * Above parameters and opt_center_sqr are used for white balance and shading.
 *
 * @lut:	lookup table &ipu3_uapi_bnr_static_config_lut_config
 * @bp_ctrl:	detect and remove bad pixels as defined in struct
 *		&ipu3_uapi_bnr_static_config_bp_ctrl_config
 * @dn_detect_ctrl:	detect and remove noise.
 *			&ipu3_uapi_bnr_static_config_dn_detect_ctrl_config
 * @column_size:	The number of pixels in column.
 * @opt_center_sqr:	Reset value of r^2 to optical center, see
 *			&ipu3_uapi_bnr_static_config_opt_center_sqr_config.
 */
struct ipu3_uapi_bnr_static_config {
	struct ipu3_uapi_bnr_static_config_wb_gains_config wb_gains;
	struct ipu3_uapi_bnr_static_config_wb_gains_thr_config wb_gains_thr;
	struct ipu3_uapi_bnr_static_config_thr_coeffs_config thr_coeffs;
	struct ipu3_uapi_bnr_static_config_thr_ctrl_shd_config thr_ctrl_shd;
	struct ipu3_uapi_bnr_static_config_opt_center_config opt_center;
	struct ipu3_uapi_bnr_static_config_lut_config lut;
	struct ipu3_uapi_bnr_static_config_bp_ctrl_config bp_ctrl;
	struct ipu3_uapi_bnr_static_config_dn_detect_ctrl_config dn_detect_ctrl;
	__u32 column_size;
	struct ipu3_uapi_bnr_static_config_opt_center_sqr_config opt_center_sqr;
} __attribute__((packed));

/**
 * struct ipu3_uapi_bnr_static_config_green_disparity - Correct green disparity
 *
 * @gd_red:	Shading gain coeff for gr disparity level in bright red region.
 *		Precision u0.6, default 4(0.0625).
 * @reserved0:	reserved
 * @gd_green:	Shading gain coeff for gr disparity level in bright green
 *		region. Precision u0.6, default 4(0.0625).
 * @reserved1:	reserved
 * @gd_blue:	Shading gain coeff for gr disparity level in bright blue region.
 *		Precision u0.6, default 4(0.0625).
 * @reserved2:	reserved
 * @gd_black:	Maximal green disparity level in dark region (stronger disparity
 *		assumed to be image detail). Precision u14, default 80.
 * @reserved3:	reserved
 * @gd_shading:	Change maximal green disparity level according to square
 *		distance from image center.
 * @reserved4:	reserved
 * @gd_support:	Lower bound for the number of second green color pixels in
 *		current pixel neighborhood with less than threshold difference
 *		from it.
 *
 * The shading gain coeff of red, green, blue and black are used to calculate
 * threshold given a pixel's color value and its coordinates in the image.
 *
 * @reserved5:	reserved
 * @gd_clip:	Turn green disparity clip on/off, [0, 1], default 1.
 * @gd_central_weight:	Central pixel weight in 9 pixels weighted sum.
 */
struct ipu3_uapi_bnr_static_config_green_disparity {
	__u32 gd_red:6;
	__u32 reserved0:2;
	__u32 gd_green:6;
	__u32 reserved1:2;
	__u32 gd_blue:6;
	__u32 reserved2:10;
	__u32 gd_black:14;
	__u32 reserved3:2;
	__u32 gd_shading:7;
	__u32 reserved4:1;
	__u32 gd_support:2;
	__u32 reserved5:1;
	__u32 gd_clip:1;
	__u32 gd_central_weight:4;
} __attribute__((packed));

/**
 * struct ipu3_uapi_dm_config - De-mosaic parameters
 *
 * @dm_en:	de-mosaic enable.
 * @ch_ar_en:	Checker artifacts removal enable flag. Default 0.
 * @fcc_en:	False color correction (FCC) enable flag. Default 0.
 * @reserved0:	reserved
 * @frame_width:	do not care
 * @gamma_sc:	Sharpening coefficient (coefficient of 2-d derivation of
 *		complementary color in Hamilton-Adams interpolation).
 *		u5, range [0, 31], default 8.
 * @reserved1:	reserved
 * @lc_ctrl:	Parameter that controls weights of Chroma Homogeneity metric
 *		in calculation of final homogeneity metric.
 *		u5, range [0, 31], default 7.
 * @reserved2:	reserved
 * @cr_param1:	First parameter that defines Checker artifact removal
 *		feature gain. Precision u5, range [0, 31], default 8.
 * @reserved3:	reserved
 * @cr_param2:	Second parameter that defines Checker artifact removal
 *		feature gain. Precision u5, range [0, 31], default 8.
 * @reserved4:	reserved
 * @coring_param:	Defines power of false color correction operation.
 *			low for preserving edge colors, high for preserving gray
 *			edge artifacts.
 *			Precision u1.4, range [0, 1.9375], default 4 (0.25).
 * @reserved5:	reserved
 *
 * The demosaic fixed function block is responsible to covert Bayer(mosaiced)
 * images into color images based on demosaicing algorithm.
 */
struct ipu3_uapi_dm_config {
	__u32 dm_en:1;
	__u32 ch_ar_en:1;
	__u32 fcc_en:1;
	__u32 reserved0:13;
	__u32 frame_width:16;

	__u32 gamma_sc:5;
	__u32 reserved1:3;
	__u32 lc_ctrl:5;
	__u32 reserved2:3;
	__u32 cr_param1:5;
	__u32 reserved3:3;
	__u32 cr_param2:5;
	__u32 reserved4:3;

	__u32 coring_param:5;
	__u32 reserved5:27;
} __attribute__((packed));

/**
 * struct ipu3_uapi_ccm_mat_config - Color correction matrix
 *
 * @coeff_m11: CCM 3x3 coefficient, range [-65536, 65535]
 * @coeff_m12: CCM 3x3 coefficient, range [-8192, 8191]
 * @coeff_m13: CCM 3x3 coefficient, range [-32768, 32767]
 * @coeff_o_r: Bias 3x1 coefficient, range [-8191, 8181]
 * @coeff_m21: CCM 3x3 coefficient, range [-32767, 32767]
 * @coeff_m22: CCM 3x3 coefficient, range [-8192, 8191]
 * @coeff_m23: CCM 3x3 coefficient, range [-32768, 32767]
 * @coeff_o_g: Bias 3x1 coefficient, range [-8191, 8181]
 * @coeff_m31: CCM 3x3 coefficient, range [-32768, 32767]
 * @coeff_m32: CCM 3x3 coefficient, range [-8192, 8191]
 * @coeff_m33: CCM 3x3 coefficient, range [-32768, 32767]
 * @coeff_o_b: Bias 3x1 coefficient, range [-8191, 8181]
 *
 * Transform sensor specific color space to standard sRGB by applying 3x3 matrix
 * and adding a bias vector O. The transformation is basically a rotation and
 * translation in the 3-dimensional color spaces. Here are the defaults:
 *
 *	9775,	-2671,	1087,	0
 *	-1071,	8303,	815,	0
 *	-23,	-7887,	16103,	0
 */
struct ipu3_uapi_ccm_mat_config {
	__s16 coeff_m11;
	__s16 coeff_m12;
	__s16 coeff_m13;
	__s16 coeff_o_r;
	__s16 coeff_m21;
	__s16 coeff_m22;
	__s16 coeff_m23;
	__s16 coeff_o_g;
	__s16 coeff_m31;
	__s16 coeff_m32;
	__s16 coeff_m33;
	__s16 coeff_o_b;
} __attribute__((packed));

/**
 * struct ipu3_uapi_gamma_corr_ctrl - Gamma correction
 *
 * @enable: gamma correction enable.
 * @reserved: reserved
 */
struct ipu3_uapi_gamma_corr_ctrl {
	__u32 enable:1;
	__u32 reserved:31;
} __attribute__((packed));

/**
 * struct ipu3_uapi_gamma_corr_lut - Per-pixel tone mapping implemented as LUT.
 *
 * @lut:	256 tabulated values of the gamma function. LUT[1].. LUT[256]
 *		format u13.0, range [0, 8191].
 *
 * The tone mapping operation is done by a Piece wise linear graph
 * that is implemented as a lookup table(LUT). The pixel component input
 * intensity is the X-axis of the graph which is the table entry.
 */
struct ipu3_uapi_gamma_corr_lut {
	__u16 lut[IPU3_UAPI_GAMMA_CORR_LUT_ENTRIES];
} __attribute__((packed));

/**
 * struct ipu3_uapi_gamma_config - Gamma config
 *
 * @gc_ctrl: control of gamma correction &ipu3_uapi_gamma_corr_ctrl
 * @gc_lut: lookup table of gamma correction &ipu3_uapi_gamma_corr_lut
 */
struct ipu3_uapi_gamma_config {
	struct ipu3_uapi_gamma_corr_ctrl gc_ctrl __attribute__((aligned(32)));
	struct ipu3_uapi_gamma_corr_lut gc_lut __attribute__((aligned(32)));
} __attribute__((packed));

/**
 * struct ipu3_uapi_csc_mat_config - Color space conversion matrix config
 *
 * @coeff_c11:	Conversion matrix value, format s0.14, range [-16384, 16383].
 * @coeff_c12:	Conversion matrix value, format s0.14, range [-8192, 8191].
 * @coeff_c13:	Conversion matrix value, format s0.14, range [-16384, 16383].
 * @coeff_b1:	Bias 3x1 coefficient, s13.0 range [-8192, 8191].
 * @coeff_c21:	Conversion matrix value, format s0.14, range [-16384, 16383].
 * @coeff_c22:	Conversion matrix value, format s0.14, range [-8192, 8191].
 * @coeff_c23:	Conversion matrix value, format s0.14, range [-16384, 16383].
 * @coeff_b2:	Bias 3x1 coefficient, s13.0 range [-8192, 8191].
 * @coeff_c31:	Conversion matrix value, format s0.14, range [-16384, 16383].
 * @coeff_c32:	Conversion matrix value, format s0.14, range [-8192, 8191].
 * @coeff_c33:	Conversion matrix value, format s0.14, range [-16384, 16383].
 * @coeff_b3:	Bias 3x1 coefficient, s13.0 range [-8192, 8191].
 *
 * To transform each pixel from RGB to YUV (Y - brightness/luminance,
 * UV -chroma) by applying the pixel's values by a 3x3 matrix and adding an
 * optional bias 3x1 vector. Here are the default values for the matrix:
 *
 *	4898,   9617,  1867, 0,
 *	-2410, -4732,  7143, 0,
 *	10076, -8437, -1638, 0,
 *
 *	(i.e. for real number 0.299, 0.299 * 2^14 becomes 4898.)
 */
struct ipu3_uapi_csc_mat_config {
	__s16 coeff_c11;
	__s16 coeff_c12;
	__s16 coeff_c13;
	__s16 coeff_b1;
	__s16 coeff_c21;
	__s16 coeff_c22;
	__s16 coeff_c23;
	__s16 coeff_b2;
	__s16 coeff_c31;
	__s16 coeff_c32;
	__s16 coeff_c33;
	__s16 coeff_b3;
} __attribute__((packed));

/**
 * struct ipu3_uapi_cds_params - Chroma down-scaling
 *
 * @ds_c00:	range [0, 3]
 * @ds_c01:	range [0, 3]
 * @ds_c02:	range [0, 3]
 * @ds_c03:	range [0, 3]
 * @ds_c10:	range [0, 3]
 * @ds_c11:	range [0, 3]
 * @ds_c12:	range [0, 3]