diff --git a/Documentation/devicetree/bindings/media/i2c/ams,mira016.yaml b/Documentation/devicetree/bindings/media/i2c/ams,mira016.yaml new file mode 100644 index 00000000000000..49a606fca6cba8 --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/ams,mira016.yaml @@ -0,0 +1,97 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/ams,mira016.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: AMS 0.16 MP NIR enhanced global shutter image sensor + +maintainers: + - Jacopo Mondi + - Philippe Baetens + +description: + Mira016 is a 0.16 MP NIR enhanced global shutter image sensor designed for 2D + and 3D consumer and industrial machine vision applications. The sensor is + compliant to the MIPI CSI-2 v1.3 protocol interface and the D-PHY v1.2 + physical layer specifications to transmit the image data to the host + processor. It uses one data lane and one clock lane operating up to 1.5 Gbps. + +allOf: + - $ref: /schemas/media/video-interface-devices.yaml# + +properties: + compatible: + const: ams,mira016 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + vdd28-supply: + description: + I/O voltage supply, 2.8 volts + + vdd11-supply: + description: + I/O voltage supply, 1.1 volts + + reset-gpios: + description: Sensor reset (RST_N) GPIO + maxItems: 1 + + port: + $ref: /schemas/graph.yaml#/$defs/port-base + additionalProperties: false + description: + Video output port + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + properties: + data-lanes: + items: + - const: 1 + + required: + - data-lanes + - link-frequencies + +required: + - compatible + - reg + - clocks + - vdd28-supply + - vdd11-supply + - port + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + camera@36 { + compatible = "ams,mira016"; + reg = <0x36>; + clocks = <&cam1_clk>; + + vdd28-supply = <&cam1_reg>; + vdd11-supply = <&cam_dummy_reg>; + + port { + endpoint { + data-lanes = <1>; + link-frequencies = /bits/ 64 <750000000>; + }; + }; + }; + }; +... diff --git a/Documentation/devicetree/bindings/media/i2c/ams,mira220.yaml b/Documentation/devicetree/bindings/media/i2c/ams,mira220.yaml new file mode 100644 index 00000000000000..f809530ee6605a --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/ams,mira220.yaml @@ -0,0 +1,103 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/ams,mira220.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: AMS 2.2 MP NIR enhanced global shutter image sensor + +maintainers: + - Jacopo Mondi + - Philippe Baetens + +description: + Mira220 is a 2.2 MP NIR enhanced global shutter image sensor designed for 2D + and 3D consumer and industrial machine vision applications. Due to its small + size, configurability and high sensitivity both in visual as well as NIR, the + Mira220 is well suited for 2D and 3D applications, which include Active Stereo + Vision, Structured Light Vision for Robotics and AR/VR. + +allOf: + - $ref: /schemas/media/video-interface-devices.yaml# + +properties: + compatible: + const: ams,mira220 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + vdig-supply: + description: + Digital I/O voltage supply, 1.35 volts + + vana-supply: + description: + Analog1 voltage supply, 2.8 volts + + vddl-supply: + description: + Digital core voltage supply, 1.8 volts + + reset-gpios: + description: Sensor reset (XCLR) GPIO + maxItems: 1 + + port: + $ref: /schemas/graph.yaml#/$defs/port-base + additionalProperties: false + description: + Video output port + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + properties: + data-lanes: + items: + - const: 1 + - const: 2 + + required: + - data-lanes + - link-frequencies + +required: + - compatible + - reg + - clocks + - vdig-supply + - vana-supply + - vddl-supply + - port + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + camera@54 { + compatible = "ams,mira220"; + reg = <0x54>; + clocks = <&cam1_clk>; + vana-supply = <&cam1_reg>; + vdig-supply = <&cam_dummy_reg>; + vddl-supply = <&cam_dummy_reg>; + port { + endpoint { + clock-lanes = <0>; + data-lanes = <1 2>; + link-frequencies = /bits/ 64 <750000000>; + }; + }; + }; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index bdf1fb6393601f..f8f949559955db 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1376,6 +1376,21 @@ S: Maintained F: Documentation/devicetree/bindings/iio/light/ams,as73211.yaml F: drivers/iio/light/as73211.c +AMS MIRA016 DRIVER +M: Jacopo Mondi +M: Philippe Baetens +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/media/i2c/ams,mira016.yaml +F: drivers/media/i2c/mira016.c + +AMS MIRA220 DRIVER +M: Jacopo Mondi +M: Philippe Baetens +L: linux-media@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/media/i2c/ams,mira220.yaml + AMT (Automatic Multicast Tunneling) M: Taehee Yoo L: netdev@vger.kernel.org diff --git a/arch/arm/boot/dts/overlays/Makefile b/arch/arm/boot/dts/overlays/Makefile index c1b8633700b564..5927713f3b1966 100644 --- a/arch/arm/boot/dts/overlays/Makefile +++ b/arch/arm/boot/dts/overlays/Makefile @@ -201,6 +201,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \ minipitft13.dtbo \ miniuart-bt.dtbo \ mipi-dbi-spi.dtbo \ + mira016.dtbo \ mira220.dtbo \ mlx90640.dtbo \ mmc.dtbo \ diff --git a/arch/arm/boot/dts/overlays/README b/arch/arm/boot/dts/overlays/README index eba94a49c2e049..410cfec433253f 100644 --- a/arch/arm/boot/dts/overlays/README +++ b/arch/arm/boot/dts/overlays/README @@ -920,6 +920,8 @@ Params: cam0-arducam-64mp Select Arducam64MP for camera on port 0 cam0-imx477 Select IMX477 for camera on port 0 cam0-imx519 Select IMX519 for camera on port 0 cam0-imx708 Select IMX708 for camera on port 0 + cam0-mira016 Select Mira016 for camera on port 0 + cam0-mira220 Select Mira220 for camera on port 0 cam0-ov2311 Select OV2311 for camera on port 0 cam0-ov5647 Select OV5647 for camera on port 0 cam0-ov64a40 Select OV64A40 for camera on port 0 @@ -933,6 +935,8 @@ Params: cam0-arducam-64mp Select Arducam64MP for camera on port 0 cam1-imx477 Select IMX477 for camera on port 1 cam1-imx519 Select IMX519 for camera on port 1 cam1-imx708 Select IMX708 for camera on port 1 + cam1-mira016 Select Mira016 for camera on port 1 + cam1-mira220 Select Mira220 for camera on port 1 cam1-ov2311 Select OV2311 for camera on port 1 cam1-ov5647 Select OV5647 for camera on port 1 cam1-ov64a40 Select OV64A40 for camera on port 1 @@ -960,6 +964,8 @@ Params: cam0-arducam-64mp Select Arducam64MP for camera on port 0 cam0-imx477 Select IMX477 for camera on port 0 cam0-imx519 Select IMX519 for camera on port 0 cam0-imx708 Select IMX708 for camera on port 0 + cam0-mira016 Select Mira016 for camera on port 0 + cam0-mira220 Select Mira220 for camera on port 0 cam0-ov2311 Select OV2311 for camera on port 0 cam0-ov5647 Select OV5647 for camera on port 0 cam0-ov64a40 Select OV64A40 for camera on port 0 @@ -973,6 +979,8 @@ Params: cam0-arducam-64mp Select Arducam64MP for camera on port 0 cam1-imx477 Select IMX477 for camera on port 1 cam1-imx519 Select IMX519 for camera on port 1 cam1-imx708 Select IMX708 for camera on port 1 + cam1-mira016 Select Mira016 for camera on port 1 + cam1-mira220 Select Mira220 for camera on port 1 cam1-ov2311 Select OV2311 for camera on port 1 cam1-ov5647 Select OV5647 for camera on port 1 cam1-ov64a40 Select OV64A40 for camera on port 1 @@ -986,6 +994,8 @@ Params: cam0-arducam-64mp Select Arducam64MP for camera on port 0 cam2-imx477 Select IMX477 for camera on port 2 cam2-imx519 Select IMX519 for camera on port 2 cam2-imx708 Select IMX708 for camera on port 2 + cam2-mira016 Select Mira016 for camera on port 2 + cam2-mira220 Select Mira220 for camera on port 2 cam2-ov2311 Select OV2311 for camera on port 2 cam2-ov5647 Select OV5647 for camera on port 2 cam2-ov64a40 Select OV64A40 for camera on port 2 @@ -999,6 +1009,8 @@ Params: cam0-arducam-64mp Select Arducam64MP for camera on port 0 cam3-imx477 Select IMX477 for camera on port 3 cam3-imx519 Select IMX519 for camera on port 3 cam3-imx708 Select IMX708 for camera on port 3 + cam3-mira016 Select Mira016 for camera on port 3 + cam3-mira220 Select Mira220 for camera on port 3 cam3-ov2311 Select OV2311 for camera on port 3 cam3-ov5647 Select OV5647 for camera on port 3 cam3-ov64a40 Select OV64A40 for camera on port 3 @@ -3879,6 +3891,21 @@ Params: (default 16). +Name: mira016 +Info: ams mira016 camera module. + Uses Unicam 1, which is the standard camera connector on most Pi + variants. +Load: dtoverlay=mira016,= +Params: rotation Mounting rotation of the camera sensor (0 or + 180, default 0) + orientation Sensor orientation (0 = front, 1 = rear, + 2 = external, default external) + media-controller Configure use of Media Controller API for + configuring the sensor (default on) + cam0 Adopt the default configuration for CAM0 on a + Compute Module (CSI0, i2c_vc, and cam0_reg). + + Name: mira220 Info: ams mira220 camera module. Uses Unicam 1, which is the standard camera connector on most Pi diff --git a/arch/arm/boot/dts/overlays/camera-mux-2port-overlay.dts b/arch/arm/boot/dts/overlays/camera-mux-2port-overlay.dts index 296477c11a4e8e..0c8bb498ef303f 100644 --- a/arch/arm/boot/dts/overlays/camera-mux-2port-overlay.dts +++ b/arch/arm/boot/dts/overlays/camera-mux-2port-overlay.dts @@ -142,6 +142,22 @@ #undef vcm_node #undef cam1_clk + #define cam_node mira016_0 + #define cam_endpoint mira016_0_ep + #define cam1_clk clk_24mhz + #include "mira016.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + + #define cam_node mira220_0 + #define cam_endpoint mira220_0_ep + #define cam1_clk clk_38mhz + #include "mira220.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + #define cam_node ov5647_0 #define cam_endpoint ov5647_0_ep #define cam1_clk clk_25mhz @@ -252,6 +268,22 @@ #undef vcm_node #undef cam1_clk + #define cam_node mira016_1 + #define cam_endpoint mira016_1_ep + #define cam1_clk clk_24mhz + #include "mira016.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + + #define cam_node mira220_1 + #define cam_endpoint mira220_1_ep + #define cam1_clk clk_38mhz + #include "mira220.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + #define cam_node ov5647_1 #define cam_endpoint ov5647_1_ep #define cam1_clk clk_25mhz @@ -396,6 +428,14 @@ status = "okay"; }; + clk_38mhz: clk_38mhz_1 { + compatible = "fixed-clock"; + #clock-cells = <0>; + + clock-frequency = <38400000>; + status = "okay"; + }; + clk_imx290: clk_imx290_1 { compatible = "fixed-clock"; #clock-cells = <0>; @@ -451,6 +491,14 @@ <&imx708_0>, "status=okay", <&imx708_0_vcm>, "status=okay", <&imx708_0>,"lens-focus:0=", <&imx708_0_vcm>; + cam0-mira016 = <&mux_in0>, "remote-endpoint:0=",<&mira016_0_ep>, + <&mira016_0_ep>, "remote-endpoint:0=",<&mux_in0>, + <&mux_in0>, "clock-noncontinuous?", + <&mira016_0>, "status=okay", + <0>,"+100-101"; + cam0-mira220 = <&mux_in0>, "remote-endpoint:0=",<&mira220_0_ep>, + <&mira220_0_ep>, "remote-endpoint:0=",<&mux_in0>, + <&mira220_0>, "status=okay"; cam0-ov5647 = <&mux_in0>, "remote-endpoint:0=",<&ov5647_0_ep>, <&ov5647_0_ep>, "remote-endpoint:0=",<&mux_in0>, <&mux_in0>, "clock-noncontinuous?", @@ -504,6 +552,14 @@ <&imx708_1>, "status=okay", <&imx708_1_vcm>, "status=okay", <&imx708_1>,"lens-focus:0=", <&imx708_1_vcm>; + cam1-mira016 = <&mux_in1>, "remote-endpoint:0=",<&mira016_1_ep>, + <&mira016_1_ep>, "remote-endpoint:0=",<&mux_in1>, + <&mux_in1>, "clock-noncontinuous?", + <&mira016_1>, "status=okay", + <0>,"+102-103"; + cam1-mira220 = <&mux_in1>, "remote-endpoint:0=",<&mira220_1_ep>, + <&mira220_1_ep>, "remote-endpoint:0=",<&mux_in1>, + <&mira220_1>, "status=okay"; cam1-ov5647 = <&mux_in1>, "remote-endpoint:0=",<&ov5647_1_ep>, <&ov5647_1_ep>, "remote-endpoint:0=",<&mux_in1>, <&mux_in1>, "clock-noncontinuous?", @@ -542,6 +598,7 @@ <&videomux>, "reg:0=0", <&clk_24mhz>, "name=clk_24mhz_0", <&clk_25mhz>, "name=clk_25mhz_0", + <&clk_38mhz>, "name=clk_38mhz_0", <&clk_imx290>, "name=clk_imx290_0"; cam0-sync-source = <&imx477_0>, "trigger-mode:0=1"; diff --git a/arch/arm/boot/dts/overlays/camera-mux-4port-overlay.dts b/arch/arm/boot/dts/overlays/camera-mux-4port-overlay.dts index 75330970f17423..d5493c3b18cbb8 100644 --- a/arch/arm/boot/dts/overlays/camera-mux-4port-overlay.dts +++ b/arch/arm/boot/dts/overlays/camera-mux-4port-overlay.dts @@ -200,6 +200,22 @@ #undef vcm_node #undef cam1_clk + #define cam_node mira016_0 + #define cam_endpoint mira016_0_ep + #define cam1_clk clk_24mhz + #include "mira016.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + + #define cam_node mira220_0 + #define cam_endpoint mira220_0_ep + #define cam1_clk clk_38mhz + #include "mira220.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + #define cam_node ov5647_0 #define cam_endpoint ov5647_0_ep #define cam1_clk clk_25mhz @@ -310,6 +326,22 @@ #undef vcm_node #undef cam1_clk + #define cam_node mira016_1 + #define cam_endpoint mira016_1_ep + #define cam1_clk clk_24mhz + #include "mira016.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + + #define cam_node mira220_1 + #define cam_endpoint mira220_1_ep + #define cam1_clk clk_38mhz + #include "mira220.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + #define cam_node ov5647_1 #define cam_endpoint ov5647_1_ep #define cam1_clk clk_25mhz @@ -420,6 +452,22 @@ #undef vcm_node #undef cam1_clk + #define cam_node mira016_2 + #define cam_endpoint mira016_2_ep + #define cam1_clk clk_24mhz + #include "mira016.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + + #define cam_node mira220_2 + #define cam_endpoint mira220_2_ep + #define cam1_clk clk_38mhz + #include "mira220.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + #define cam_node ov5647_2 #define cam_endpoint ov5647_2_ep #define cam1_clk clk_25mhz @@ -530,6 +578,22 @@ #undef vcm_node #undef cam1_clk + #define cam_node mira016_3 + #define cam_endpoint mira016_3_ep + #define cam1_clk clk_24mhz + #include "mira016.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + + #define cam_node mira220_3 + #define cam_endpoint mira220_3_ep + #define cam1_clk clk_38mhz + #include "mira220.dtsi" + #undef cam_node + #undef cam_endpoint + #undef cam1_clk + #define cam_node ov5647_3 #define cam_endpoint ov5647_3_ep #define cam1_clk clk_25mhz @@ -702,6 +766,14 @@ status = "okay"; }; + clk_38mhz: clk_38mhz_1 { + compatible = "fixed-clock"; + #clock-cells = <0>; + + clock-frequency = <38400000>; + status = "okay"; + }; + clk_imx290: clk_imx290_1 { compatible = "fixed-clock"; #clock-cells = <0>; @@ -746,6 +818,14 @@ <&imx708_0>, "status=okay", <&imx708_0_vcm>, "status=okay", <&imx708_0>,"lens-focus:0=", <&imx708_0_vcm>; + cam0-mira016 = <&mux_in0>, "remote-endpoint:0=",<&mira016_0_ep>, + <&mira016_0_ep>, "remote-endpoint:0=",<&mux_in0>, + <&mux_in0>, "clock-noncontinuous?", + <&mira016_0>, "status=okay", + <0>,"+100-101"; + cam0-mira220 = <&mux_in0>, "remote-endpoint:0=",<&mira220_0_ep>, + <&mira220_0_ep>, "remote-endpoint:0=",<&mux_in0>, + <&mira220_0>, "status=okay"; cam0-ov5647 = <&mux_in0>, "remote-endpoint:0=",<&ov5647_0_ep>, <&ov5647_0_ep>, "remote-endpoint:0=",<&mux_in0>, <&mux_in0>, "clock-noncontinuous?", @@ -799,6 +879,14 @@ <&imx708_1>, "status=okay", <&imx708_1_vcm>, "status=okay", <&imx708_1>,"lens-focus:0=", <&imx708_1_vcm>; + cam1-mira016 = <&mux_in1>, "remote-endpoint:0=",<&mira016_1_ep>, + <&mira016_1_ep>, "remote-endpoint:0=",<&mux_in1>, + <&mux_in1>, "clock-noncontinuous?", + <&mira016_1>, "status=okay", + <0>,"+102-103"; + cam1-mira220 = <&mux_in1>, "remote-endpoint:0=",<&mira220_1_ep>, + <&mira220_1_ep>, "remote-endpoint:0=",<&mux_in1>, + <&mira220_1>, "status=okay"; cam1-ov5647 = <&mux_in1>, "remote-endpoint:0=",<&ov5647_1_ep>, <&ov5647_1_ep>, "remote-endpoint:0=",<&mux_in1>, <&mux_in1>, "clock-noncontinuous?", @@ -852,6 +940,14 @@ <&imx708_2>, "status=okay", <&imx708_2_vcm>, "status=okay", <&imx708_2>,"lens-focus:0=", <&imx708_2_vcm>; + cam2-mira016 = <&mux_in2>, "remote-endpoint:0=",<&mira016_2_ep>, + <&mira016_2_ep>, "remote-endpoint:0=",<&mux_in2>, + <&mux_in2>, "clock-noncontinuous?", + <&mira016_2>, "status=okay", + <0>,"+104-105"; + cam2-mira220 = <&mux_in2>, "remote-endpoint:0=",<&mira220_2_ep>, + <&mira220_2_ep>, "remote-endpoint:0=",<&mux_in2>, + <&mira220_2>, "status=okay"; cam2-ov5647 = <&mux_in2>, "remote-endpoint:0=",<&ov5647_2_ep>, <&ov5647_2_ep>, "remote-endpoint:0=",<&mux_in2>, <&mux_in2>, "clock-noncontinuous?", @@ -905,6 +1001,14 @@ <&imx708_3>, "status=okay", <&imx708_3_vcm>, "status=okay", <&imx708_3>,"lens-focus:0=", <&imx708_3_vcm>; + cam3-mira016 = <&mux_in3>, "remote-endpoint:0=",<&mira016_3_ep>, + <&mira016_3_ep>, "remote-endpoint:0=",<&mux_in3>, + <&mux_in3>, "clock-noncontinuous?", + <&mira016_3>, "status=okay", + <0>,"+106-107"; + cam3-mira220 = <&mux_in3>, "remote-endpoint:0=",<&mira220_3_ep>, + <&mira220_3_ep>, "remote-endpoint:0=",<&mux_in3>, + <&mira220_3>, "status=okay"; cam3-ov5647 = <&mux_in3>, "remote-endpoint:0=",<&ov5647_3_ep>, <&ov5647_3_ep>, "remote-endpoint:0=",<&mux_in3>, <&mux_in3>, "clock-noncontinuous?", @@ -947,6 +1051,7 @@ <&videomux>, "reg:0=0", <&clk_24mhz>, "name=clk_24mhz_0", <&clk_25mhz>, "name=clk_25mhz_0", + <&clk_38mhz>, "name=clk_38mhz_0", <&clk_imx290>, "name=clk_imx290_0"; cam0-sync-source = <&imx477_0>, "trigger-mode:0=1"; diff --git a/arch/arm/boot/dts/overlays/mira016-overlay.dts b/arch/arm/boot/dts/overlays/mira016-overlay.dts new file mode 100644 index 00000000000000..d47ad2517a80d2 --- /dev/null +++ b/arch/arm/boot/dts/overlays/mira016-overlay.dts @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Definitions for MIRA016 camera module on VC I2C bus +/dts-v1/; +/plugin/; + +/{ + compatible = "brcm,bcm2835"; + + fragment@0 { + target = <&i2c0if>; + __overlay__ { + status = "okay"; + }; + }; + + clk_frag: fragment@1 { + target = <&cam1_clk>; + __overlay__ { + status = "okay"; + clock-frequency = <24000000>; + }; + }; + + fragment@2 { + target = <&i2c0mux>; + __overlay__ { + status = "okay"; + }; + }; + + reg_frag: fragment@3 { + target = <&cam1_reg>; + cam_reg: __overlay__ { + startup-delay-us = <120000>; + off-on-delay-us = <40000>; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <2800000>; + }; + }; + + i2c_frag: fragment@100 { + target = <&i2c_csi_dsi>; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + + #include "mira016.dtsi" + }; + }; + + csi_frag: fragment@101 { + target = <&csi1>; + csi: __overlay__ { + status = "okay"; + + port { + csi_ep: endpoint { + remote-endpoint = <&cam_endpoint>; + clock-lanes = <0>; + data-lanes = <1>; + clock-noncontinuous; + }; + }; + }; + }; + + fragment@102 { + target = <&csi1>; + __dormant__ { + compatible = "brcm,bcm2835-unicam-legacy"; + }; + }; + + __overrides__ { + rotation = <&cam_node>,"rotation:0"; + orientation = <&cam_node>,"orientation:0"; + media-controller = <0>,"!102"; + cam0 = <&i2c_frag>, "target:0=",<&i2c_csi_dsi0>, + <&csi_frag>, "target:0=",<&csi0>, + <&clk_frag>, "target:0=",<&cam0_clk>, + <®_frag>, "target:0=",<&cam0_reg>, + <&cam_node>, "clocks:0=",<&cam0_clk>, + <&cam_node>, "vdd28-supply:0=",<&cam0_reg>; + }; +}; + +&cam_node { + status = "okay"; +}; + +&cam_endpoint { + remote-endpoint = <&csi_ep>; +}; diff --git a/arch/arm/boot/dts/overlays/mira016.dtsi b/arch/arm/boot/dts/overlays/mira016.dtsi new file mode 100644 index 00000000000000..a907b77d0c7be1 --- /dev/null +++ b/arch/arm/boot/dts/overlays/mira016.dtsi @@ -0,0 +1,20 @@ +// Fragment that configures an mira016 + +cam_node: mira016@36 { + compatible = "ams,mira016"; + reg = <0x36>; + status = "disabled"; + clocks = <&cam1_clk>; + vdd28-supply = <&cam1_reg>; /* 1.8v */ + vdd11-supply = <&cam_dummy_reg>; /* 1.2v */ + + port { + cam_endpoint: endpoint { + clock-lanes = <0>; + data-lanes = <1>; + clock-noncontinuous; + link-frequencies = + /bits/ 64 <750000000>; + }; + }; +}; diff --git a/arch/arm/boot/dts/overlays/mira220-overlay.dts b/arch/arm/boot/dts/overlays/mira220-overlay.dts index c969e55f4ba9a0..b05bc66475079f 100644 --- a/arch/arm/boot/dts/overlays/mira220-overlay.dts +++ b/arch/arm/boot/dts/overlays/mira220-overlay.dts @@ -3,8 +3,6 @@ /dts-v1/; /plugin/; -#include - /{ compatible = "brcm,bcm2835"; @@ -30,6 +28,16 @@ }; }; + reg_frag: fragment@3 { + target = <&cam1_reg>; + cam_reg: __overlay__ { + startup-delay-us = <120000>; + off-on-delay-us = <40000>; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <2800000>; + }; + }; + i2c_frag: fragment@100 { target = <&i2c_csi_dsi>; __overlay__ { @@ -38,7 +46,6 @@ status = "okay"; #include "mira220.dtsi" - }; }; @@ -52,7 +59,6 @@ remote-endpoint = <&cam_endpoint>; clock-lanes = <0>; data-lanes = <1 2>; - // clock-noncontinuous; // mira220 use cont clk }; }; }; @@ -65,7 +71,6 @@ }; }; - __overrides__ { rotation = <&cam_node>,"rotation:0"; orientation = <&cam_node>,"orientation:0"; @@ -73,6 +78,7 @@ cam0 = <&i2c_frag>, "target:0=",<&i2c_csi_dsi0>, <&csi_frag>, "target:0=",<&csi0>, <&clk_frag>, "target:0=",<&cam0_clk>, + <®_frag>, "target:0=",<&cam0_reg>, <&cam_node>, "clocks:0=",<&cam0_clk>, <&cam_node>, "vana-supply:0=",<&cam0_reg>; }; diff --git a/arch/arm/boot/dts/overlays/mira220.dtsi b/arch/arm/boot/dts/overlays/mira220.dtsi index 4e171657a3a6e0..b5d15a6f6e357f 100644 --- a/arch/arm/boot/dts/overlays/mira220.dtsi +++ b/arch/arm/boot/dts/overlays/mira220.dtsi @@ -19,7 +19,6 @@ cam_node: mira220@10 { cam_endpoint: endpoint { clock-lanes = <0>; data-lanes = <1 2>; - // clock-noncontinuous; link-frequencies = /bits/ 64 <750000000>; }; diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 1fbdd48104be5f..2cb27011302b44 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -360,6 +360,18 @@ select VIDEO_SONY_STARVIS2 IMX678 camera. This sensor is now supported by the common Sony Starvis 2 sensor driver. +config VIDEO_MIRA016 + tristate "ams OSRAM MIRA016 sensor support" + depends on I2C && VIDEO_DEV + depends on GPIOLIB + select V4L2_CCI_I2C + help + This is a Video4Linux2 sensor driver for the ams OSRAM + MIRA016 camera. + + To compile this driver as a module, choose M here: the + module will be called mira016. + config VIDEO_MAX9271_LIB tristate diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 41c31e23cef52e..6ee2ae5e10cc5c 100644 --- a/drivers/media/i2c/Makefile +++ b/drivers/media/i2c/Makefile @@ -80,6 +80,7 @@ obj-$(CONFIG_VIDEO_MAX9271_LIB) += max9271.o obj-$(CONFIG_VIDEO_MAX9286) += max9286.o obj-$(CONFIG_VIDEO_MAX96714) += max96714.o obj-$(CONFIG_VIDEO_MAX96717) += max96717.o +obj-$(CONFIG_VIDEO_MIRA016) += mira016.o obj-$(CONFIG_VIDEO_MIRA220) += mira220.o obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o diff --git a/drivers/media/i2c/mira016.c b/drivers/media/i2c/mira016.c new file mode 100644 index 00000000000000..56c7b77d92d189 --- /dev/null +++ b/drivers/media/i2c/mira016.c @@ -0,0 +1,2375 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2026, ams OSRAM + * Copyright (C) 2026, Ideas On Board Oy + * + * Based on AMS Mira220 driver + * Copyright (C) 2026, ams OSRAM + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +/* Register select. */ +#define MIRA016_BANK_SEL_REG CCI_REG8(0xe000) +#define MIRA016_ACTIVE_CONTEXT_REG CCI_REG8(0x4002) +#define MIRA016_NEXT_ACTIVE_CONTEXT_REG CCI_REG8(0xe003) +#define MIRA016_RW_CONTEXT_REG CCI_REG8(0xe004) +#define MIRA016_CMD_REQ_1_REG CCI_REG8(0x000a) +#define MIRA016_CMD_HALT_BLOCK_REG CCI_REG8(0x000c) + +/* Chip id */ +#define MIRA016_CHIP_ID_REG CCI_REG8(0x011B) +#define MIRA016_CHIP_ID 33 + +/* PLL config */ +#define MHZ(f) ((u32)(f) * HZ_PER_MHZ) +#define MIRA016_PLL_N_MIN 1 +#define MIRA016_PLL_N_MAX 32 +#define MIRA016_PLL_M_MIN 16 +#define MIRA016_PLL_M_MAX 255 +#define MIRA016_PLL_PLL1_MIN MHZ(12) +#define MIRA016_PLL_PLL1_MAX MHZ(22) +#define MIRA016_PLL_PLL2_MIN MHZ(640) +#define MIRA016_PLL_PLL2_MAX MHZ(1500) + +#define MIRA016_PLL_DIV_M_REG CCI_REG8(0x2076) +#define MIRA016_PLL_DIV_N_REG CCI_REG8(0x2077) +#define MIRA016_CLKGEN_CP_DIV_REG CCI_REG8(0x00ce) +#define MIRA016_OTP_GRANULARITY_REG CCI_REG8(0x0070) +#define MIRA016_GRAN_TG_REG CCI_REG8(0x016d) +#define MIRA016_LUT_DEL008_REG CCI_REG8(0x0176) +#define MIRA016_CLKGEN_TX_ESC_H_REG CCI_REG24(0x20c6) +#define MIRA016_CLKGEN_TX_ESC_L_REG CCI_REG24(0x20c9) +#define MIRA016_PLL_PD_REG CCI_REG8(0x2075) +#define MIRA016_PLL_LOCK_REG CCI_REG8(0x207c) +#define MIRA016_PLL_LOCKED BIT(0) + +#define MIRA016_EXP_TIME_L_REG CCI_REG32(0x000e) +#define MIRA016_EXP_TIME_S_REG CCI_REG32(0x0012) +#define MIRA016_NUM_FRAMES_REG CCI_REG8(0x0007) +#define MIRA016_TARGET_FRAME_TIME_REG CCI_REG32(0x0008) + +#define MIRA016_TIME_UNIT_REG CCI_REG16(0x0012) +#define MIRA016_GLOB_TIME_REG CCI_REG16(0x015a) +#define MIRA016_GLOB_TIME_A_REG CCI_REG16(0x015c) +#define MIRA016_GLOB_TIME_B_REG CCI_REG16(0x015e) +/* + * TODO: LPS timings should be calculated to support new link frequency as + * their value derives from the BYTE_PERIOD bus parameter. + * + * Use the hardcoded values for 1500Mbps. + */ +#define MIRA016_ENTER_LPS_TIME_REG CCI_REG16(0x0162) +#define MIRA016_ENTER_LPS_TIME_1500MBPS 5 +#define MIRA016_EXIT_LPS_TIME_REG CCI_REG16(0x0164) +#define MIRA016_EXIT_LPS_TIME_1500MBPS 0x479 +#define MIRA016_LPS_CYCLE_TIME_REG CCI_REG16(0x0166) +#define MIRA016_LPS_CYCLE_TIME_1500MBPS 0x479 + +#define MIRA016_ROW_TIMINGS_REG CCI_REG16(0x0032) + +#define MIRA016_PIXEL_ARRAY_TOP 14 +#define MIRA016_PIXEL_ARRAY_LEFT 14 +#define MIRA016_PIXEL_ARRAY_WIDTH 400 +#define MIRA016_PIXEL_ARRAY_HEIGHT 400 +#define MIRA016_NATIVE_WIDTH 428 +#define MIRA016_NATIVE_HEIGHT 428 + +/* X ROI */ +#define MIRA016_XWIN_LEFT_REG CCI_REG16(0xe02c) +#define MIRA016_XWIN_RIGHT_REG CCI_REG16(0xe02e) +#define MIRA016_XMIRROR_REG CCI_REG8(0xe030) +#define MIRA016_XSUBSAMPLING_REG CCI_REG8(0xe025) +#define MIRA016_XBINNING_REG CCI_REG8(0xe02a) +#define MIRA016_MIPI_DATA_FIFO_THR_REG CCI_REG8(0x2029) +#define MIRA016_HSYNC_LENGTH CCI_REG16(0x0034) + +/* Y ROI Bank 1 */ +#define MIRA016_YWIN_ENA_REG CCI_REG16(0x001e) +#define MIRA016_YBINNING_REG CCI_REG8(0x002b) +/* Y ROI Bank 0 */ +#define MIRA016_YWIN_BLACK_REG CCI_REG16(0X001f) +#define MIRA016_YWIN_DIR_REG CCI_REG8(0x0023) +#define MIRA016_YWIN_BASE_SIZE 0x0024 +#define MIRA016_YWIN_BASE_START 0x0026 +#define MIRA016_YWIN_BASE_SUBS 0x0028 +#define MIRA016_YWIN_SIZE_REG(x) CCI_REG16(MIRA016_YWIN_BASE_SIZE \ + + (x) * 5) +#define MIRA016_YWIN_START_REG(x) CCI_REG16(MIRA016_YWIN_BASE_START \ + + (x) * 5) +#define MIRA016_YWIN_SUBS_REG(x) CCI_REG8(MIRA016_YWIN_BASE_SUBS \ + + (x) * 5) +#define MIRA016_NUM_Y_WIND 10 + +/* Data format */ +#define MIRA016_DPATH_BITMODE_REG CCI_REG8(0x016a) +#define MIRA016_DPATH_BITWIDTH_A_REG CCI_REG16(0x00c0) +#define MIRA016_DPATH_BITWIDTH_B_REG CCI_REG16(0x00c2) +#define MIRA016_CSI2_DATA_TYPE_REG CCI_REG8(0x0168) + +/* Fine analogue gain */ +#define MIRA016_GDIG_PREAMP CCI_REG8(0x0195) +#define MIRA016_BIAS_RG_ADCGAIN CCI_REG8(0x01f0) +#define MIRA016_BIAS_RG_ADCGAIN_MAX 63 +#define MIRA016_BIAS_RG_MULT CCI_REG8(0x01f3) + +#define MIRA016_GAIN_UNIT 1000 +#define MIRA016_GAIN_MAX_8B 16000 +#define MIRA016_GAIN_MAX_10B 4000 +#define MIRA016_ADC_GAIN_VAL(n) (57000 << (n)) +#define MIRA016_FINE_GAIN_REF_MULT 2 + +/* MIPI CSI-2 link frequency for 1.5Mbps per lane */ +#define MIRA016_LINK_FREQ_750M 750000000 + +#define MIRA016_DEFAULT_DURATION_NSEC 8333000ULL +#define MIRA016_MAX_VBLANK 500000 + +/* + * Copied from the libcamera IPA. The sensor manual doesn't really specify a + * minimum difference between the exposure time and the frame duration. + */ +#define MIRA016_FRAME_INTEGRATION_DIFF 4 + +#define MIRA016_MAX_EXPOSURE 500000 +#define MIRA016_EXPOSURE_DEF_NSEC 1000000ULL + +static const s64 mira016_link_freqs[] = { + [0] = MIRA016_LINK_FREQ_750M, +}; + +static const char *const mira016_supplies[] = { + /* Supplies shall be enabled in the following order */ + "vdd11", + "vdd28", +}; + +struct mira016 { + struct device *dev; + struct v4l2_subdev sd; + struct media_pad pad; + + struct clk *xclk; + u32 xclk_freq; + + struct gpio_desc *reset_gpio; + + struct regulator *supplies[ARRAY_SIZE(mira016_supplies)]; + + unsigned long link_freq_bitmap; + unsigned int bus_config; + + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *vflip; + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vblank; + struct v4l2_ctrl *exposure; + struct v4l2_ctrl *gain; + struct v4l2_ctrl *prate; + + struct { + u8 n; + u8 m; + u8 cp_div; + u8 otp_gran; + u8 gran_tg; + u8 lut_del; + u32 esc_h; + u32 esc_l; + u32 esc_period; + u32 byte_period; + u32 data_rate_mbps; + } pll; + + struct { + /* + * Mira016 timings registers are expressed in useconds + * with a time base of `seq_time_base`: + * + * line_duration = seq_time_base * row_length; + * + * As a typical value for seq_time_base is 5.333 nanoseconds + * for a 1500Mbps@24MHz configuration, calculate the base time + * in picoseconds otherwise we would lose precision. + */ + u32 time_base; + u32 seq_time_base; + u32 min_exposure_time; + u32 glob_time; + u32 row_length; + } timings; + + struct regmap *regmap; +}; + +static inline struct mira016 *to_mira016(struct v4l2_subdev *sd) +{ + return container_of_const(sd, struct mira016, sd); +} + +/* + * All Mira016 timing registers are expressed in useconds, while V4L2 + * specifies timings in line. + * + * Convert back and forth using these helpers which use the row time (in + * picoseconds, see the comment on the 'timings' anonymous structure). + */ + +static inline u32 mira016_trow_psec(struct mira016 *mira016) +{ + return mira016->timings.seq_time_base * mira016->timings.row_length; +} + +static inline u32 mira016_lines_to_usec(struct mira016 *mira016, u32 lines) +{ + return div_u64((u64)lines * mira016_trow_psec(mira016), HZ_PER_MHZ); +} + +static inline u32 mira016_nsec_to_lines(struct mira016 *mira016, u32 nsec) +{ + return nsec / (mira016_trow_psec(mira016) / HZ_PER_KHZ); +} + +static inline u32 mira016_calc_prate(struct mira016 *mira016, u32 h_tot) +{ + /* + * Pixel rate is calculate as the row duration divided by the total line + * length. + * + * pixel time (psec) = t_row(psec) / h_tot + * pixel rate (mbps) = 10^12 / pixel_time + * = 10^12 * h_tot / t_row + * = h_tot * 10^6 / t_row * 10^6 to avoid overflows + */ + u32 trow_psec = mira016_trow_psec(mira016); + + return h_tot * HZ_PER_MHZ / trow_psec * HZ_PER_MHZ; +} + +static inline u32 mira016_calc_min_vblank(struct mira016 *mira016, u32 y_tot) +{ + /* + * See 3.15.2 Frame Rate, equation 4. + * + * TODO: The minimum frame duration has to be expanded if embedded data + * are used. + */ + u32 trow_nsec = mira016_trow_psec(mira016) / HZ_PER_KHZ; + u32 min_duration_nsec = trow_nsec * (y_tot + 35) + 50 * HZ_PER_KHZ; + + return mira016_nsec_to_lines(mira016, min_duration_nsec) - y_tot; +} + +static const struct cci_reg_sequence mira016_8b_fine_gain_init[] = { + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x01bb), 0xb4 }, + { CCI_REG8(0x01bc), 0xac }, + { CCI_REG8(0x00d0), 0x0 }, + { CCI_REG8(0x016e), 0xfd }, + { CCI_REG8(0x0172), 0x0 }, + { CCI_REG8(0x0173), 0x0 }, + { CCI_REG8(0x016f), 0x7e }, + { CCI_REG8(0x0170), 0x0 }, + { CCI_REG8(0x0171), 0xfd }, + { CCI_REG8(0x0174), 0x0 }, + { CCI_REG8(0x0175), 0x0 }, + { CCI_REG8(0x0177), 0x78 }, + { CCI_REG8(0x018b), 0x4 }, + { CCI_REG8(0x018c), 0xe }, + { CCI_REG8(0x018d), 0x2 }, + { CCI_REG8(0x018e), 0x56 }, + { CCI_REG8(0x018f), 0x6 }, + { CCI_REG8(0x0190), 0xe }, + { CCI_REG8(0x00e8), 0x8 }, + { CCI_REG8(0x01ee), 0x1b }, + { CCI_REG8(0x01ef), 0x46 }, + { CCI_REG8(0x01a2), 0x0 }, + { CCI_REG8(0x01a3), 0x1 }, + { CCI_REG8(0x031f), 0x0 }, + { CCI_REG8(0x0320), 0xa }, + { CCI_REG8(0x01a6), 0x0 }, + { CCI_REG8(0x01a7), 0x98 }, + { CCI_REG8(0x01a4), 0x4 }, + { CCI_REG8(0x01a5), 0x27 }, + { CCI_REG8(0x0321), 0x4 }, + { CCI_REG8(0x0322), 0x30 }, + { CCI_REG8(0x01a8), 0x4 }, + { CCI_REG8(0x01a9), 0xbe }, + { CCI_REG8(0x01a0), 0x1 }, + { CCI_REG8(0x01a1), 0x3a }, + { CCI_REG8(0x01b2), 0x1 }, + { CCI_REG8(0x01b3), 0x54 }, + { CCI_REG8(0x01b0), 0x1 }, + { CCI_REG8(0x01b1), 0x4d }, + { CCI_REG8(0x01ac), 0x1 }, + { CCI_REG8(0x01ad), 0x58 }, + { CCI_REG8(0x01f0), 0x24 }, + { CCI_REG8(0x01f3), 0x2 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0xe024), 0xf }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x005c), 0x0 }, + { CCI_REG8(0x005d), 0x6 }, +}; + +static const struct cci_reg_sequence mira016_10b_fine_gain_init[] = { + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x01bb), 0xb4 }, + { CCI_REG8(0x01bc), 0xac }, + { CCI_REG8(0x00d0), 0x0 }, + { CCI_REG8(0x016e), 0xfd }, + { CCI_REG8(0x0172), 0x0 }, + { CCI_REG8(0x0173), 0x0 }, + { CCI_REG8(0x016f), 0x7e }, + { CCI_REG8(0x0170), 0x0 }, + { CCI_REG8(0x0171), 0xfd }, + { CCI_REG8(0x0174), 0x0 }, + { CCI_REG8(0x0175), 0x0 }, + { CCI_REG8(0x0177), 0x78 }, + { CCI_REG8(0x018b), 0x4 }, + { CCI_REG8(0x018c), 0x4 }, + { CCI_REG8(0x018d), 0x2 }, + { CCI_REG8(0x018e), 0x60 }, + { CCI_REG8(0x018f), 0x6 }, + { CCI_REG8(0x0190), 0x4 }, + { CCI_REG8(0x00e8), 0x8 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0xe024), 0xf }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x005c), 0x0 }, + { CCI_REG8(0x005d), 0x18 }, + { CCI_REG8(0x01ee), 0x1b }, + { CCI_REG8(0x01ef), 0x46 }, + { CCI_REG8(0x01a2), 0x0 }, + { CCI_REG8(0x01a3), 0x1 }, + { CCI_REG8(0x031f), 0x0 }, + { CCI_REG8(0x0320), 0xa }, + { CCI_REG8(0x01a6), 0x0 }, + { CCI_REG8(0x01a7), 0x98 }, + { CCI_REG8(0x01a4), 0x4 }, + { CCI_REG8(0x01a5), 0x27 }, + { CCI_REG8(0x0321), 0x4 }, + { CCI_REG8(0x0322), 0x30 }, + { CCI_REG8(0x01a8), 0x4 }, + { CCI_REG8(0x01a9), 0xbe }, + { CCI_REG8(0x01a0), 0x0 }, + { CCI_REG8(0x01a1), 0xfb }, + { CCI_REG8(0x01b2), 0x1 }, + { CCI_REG8(0x01b3), 0x15 }, + { CCI_REG8(0x01b0), 0x1 }, + { CCI_REG8(0x01b1), 0xe }, + { CCI_REG8(0x01ac), 0x1 }, + { CCI_REG8(0x01ad), 0x19 }, + { CCI_REG8(0x01f0), 0x24 }, + { CCI_REG8(0x01f3), 0x2 }, +}; + +static const struct cci_reg_sequence mira016_12b_fixed_gain_init[] = { + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x01bb), 0xb4 }, + { CCI_REG8(0x01bc), 0xac }, + { CCI_REG8(0x00d0), 0x0 }, + { CCI_REG8(0x01f0), 0x7 }, + { CCI_REG8(0x01f3), 0x1 }, + { CCI_REG8(0x016e), 0xfd }, + { CCI_REG8(0x0172), 0x0 }, + { CCI_REG8(0x0173), 0x0 }, + { CCI_REG8(0x016f), 0xff }, + { CCI_REG8(0x0170), 0xff }, + { CCI_REG8(0x0171), 0xfd }, + { CCI_REG8(0x0174), 0x0 }, + { CCI_REG8(0x0175), 0x0 }, + { CCI_REG8(0x0177), 0xdc }, + { CCI_REG8(0x018b), 0x4 }, + { CCI_REG8(0x018c), 0xe }, + { CCI_REG8(0x018d), 0x2 }, + { CCI_REG8(0x018e), 0x56 }, + { CCI_REG8(0x018f), 0xc }, + { CCI_REG8(0x0190), 0xe }, + { CCI_REG8(0x00e8), 0x3 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0xe024), 0xf }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x005c), 0x0 }, + { CCI_REG8(0x005d), 0x60 }, + { CCI_REG8(0x01ee), 0x1b }, + { CCI_REG8(0x01ef), 0x46 }, + { CCI_REG8(0x01a2), 0x0 }, + { CCI_REG8(0x01a3), 0x1 }, + { CCI_REG8(0x031f), 0x0 }, + { CCI_REG8(0x0320), 0xa }, + { CCI_REG8(0x01a6), 0x0 }, + { CCI_REG8(0x01a7), 0x98 }, + { CCI_REG8(0x01a4), 0x5 }, + { CCI_REG8(0x01a5), 0xa7 }, + { CCI_REG8(0x0321), 0x5 }, + { CCI_REG8(0x0322), 0xb0 }, + { CCI_REG8(0x01a8), 0x6 }, + { CCI_REG8(0x01a9), 0x3e }, + { CCI_REG8(0x01a0), 0x0 }, + { CCI_REG8(0x01a1), 0xf3 }, + { CCI_REG8(0x01b2), 0x1 }, + { CCI_REG8(0x01b3), 0xd }, + { CCI_REG8(0x01b0), 0x1 }, + { CCI_REG8(0x01b1), 0x6 }, + { CCI_REG8(0x01ac), 0x1 }, + { CCI_REG8(0x01ad), 0x11 }, +}; + +static const struct cci_reg_sequence mira016_init_sequence[] = { + { CCI_REG8(0x01e4), 0x0 }, + { CCI_REG8(0x01e5), 0x13 }, + { CCI_REG8(0x01e2), 0x17 }, + { CCI_REG8(0x01e3), 0xa8 }, + { CCI_REG8(0x01e6), 0x0 }, + { CCI_REG8(0x01e7), 0xca }, + { CCI_REG8(0x016c), 0x1 }, + { CCI_REG8(0x016b), 0x1 }, + { CCI_REG8(0x0208), 0x1 }, + { CCI_REG8(0x0209), 0xf0 }, + { CCI_REG8(0x020a), 0x3 }, + { CCI_REG8(0x020b), 0x4d }, + { CCI_REG8(0x020c), 0x2 }, + { CCI_REG8(0x020d), 0x10 }, + { CCI_REG8(0x020e), 0x3 }, + { CCI_REG8(0x020f), 0x1 }, + { CCI_REG8(0x0210), 0x0 }, + { CCI_REG8(0x0211), 0x13 }, + { CCI_REG8(0x0212), 0x0 }, + { CCI_REG8(0x0213), 0x3 }, + { CCI_REG8(0x0214), 0x3 }, + { CCI_REG8(0x0215), 0xef }, + { CCI_REG8(0x0216), 0x3 }, + { CCI_REG8(0x0217), 0xf3 }, + { CCI_REG8(0x0218), 0x3 }, + { CCI_REG8(0x0219), 0xf4 }, + { CCI_REG8(0x021a), 0x0 }, + { CCI_REG8(0x021b), 0x1 }, + { CCI_REG8(0x021c), 0x3 }, + { CCI_REG8(0x021d), 0xf8 }, + { CCI_REG8(0x021e), 0x0 }, + { CCI_REG8(0x021f), 0x2 }, + { CCI_REG8(0x0220), 0x1 }, + { CCI_REG8(0x0221), 0xf2 }, + { CCI_REG8(0x0222), 0x3 }, + { CCI_REG8(0x0223), 0x1b }, + { CCI_REG8(0x0224), 0x0 }, + { CCI_REG8(0x0225), 0x21 }, + { CCI_REG8(0x0226), 0x3 }, + { CCI_REG8(0x0227), 0xf0 }, + { CCI_REG8(0x0228), 0x3 }, + { CCI_REG8(0x0229), 0xf1 }, + { CCI_REG8(0x022a), 0x3 }, + { CCI_REG8(0x022b), 0xf2 }, + { CCI_REG8(0x022c), 0x3 }, + { CCI_REG8(0x022d), 0xf5 }, + { CCI_REG8(0x022e), 0x3 }, + { CCI_REG8(0x022f), 0xf6 }, + { CCI_REG8(0x0230), 0x0 }, + { CCI_REG8(0x0231), 0xc1 }, + { CCI_REG8(0x0232), 0x0 }, + { CCI_REG8(0x0233), 0x2 }, + { CCI_REG8(0x0234), 0x1 }, + { CCI_REG8(0x0235), 0xf2 }, + { CCI_REG8(0x0236), 0x3 }, + { CCI_REG8(0x0237), 0x6b }, + { CCI_REG8(0x0238), 0x3 }, + { CCI_REG8(0x0239), 0xff }, + { CCI_REG8(0x023a), 0x3 }, + { CCI_REG8(0x023b), 0x31 }, + { CCI_REG8(0x023c), 0x1 }, + { CCI_REG8(0x023d), 0xf0 }, + { CCI_REG8(0x023e), 0x3 }, + { CCI_REG8(0x023f), 0x87 }, + { CCI_REG8(0x0240), 0x0 }, + { CCI_REG8(0x0241), 0xa }, + { CCI_REG8(0x0242), 0x0 }, + { CCI_REG8(0x0243), 0xb }, + { CCI_REG8(0x0244), 0x1 }, + { CCI_REG8(0x0245), 0xf9 }, + { CCI_REG8(0x0246), 0x3 }, + { CCI_REG8(0x0247), 0xd }, + { CCI_REG8(0x0248), 0x0 }, + { CCI_REG8(0x0249), 0x7 }, + { CCI_REG8(0x024a), 0x3 }, + { CCI_REG8(0x024b), 0xef }, + { CCI_REG8(0x024c), 0x3 }, + { CCI_REG8(0x024d), 0xf3 }, + { CCI_REG8(0x024e), 0x3 }, + { CCI_REG8(0x024f), 0xf4 }, + { CCI_REG8(0x0250), 0x3 }, + { CCI_REG8(0x0251), 0x0 }, + { CCI_REG8(0x0252), 0x0 }, + { CCI_REG8(0x0253), 0x7 }, + { CCI_REG8(0x0254), 0x0 }, + { CCI_REG8(0x0255), 0xc }, + { CCI_REG8(0x0256), 0x1 }, + { CCI_REG8(0x0257), 0xf1 }, + { CCI_REG8(0x0258), 0x3 }, + { CCI_REG8(0x0259), 0x43 }, + { CCI_REG8(0x025a), 0x1 }, + { CCI_REG8(0x025b), 0xf8 }, + { CCI_REG8(0x025c), 0x3 }, + { CCI_REG8(0x025d), 0x10 }, + { CCI_REG8(0x025e), 0x0 }, + { CCI_REG8(0x025f), 0x7 }, + { CCI_REG8(0x0260), 0x3 }, + { CCI_REG8(0x0261), 0xf0 }, + { CCI_REG8(0x0262), 0x3 }, + { CCI_REG8(0x0263), 0xf1 }, + { CCI_REG8(0x0264), 0x3 }, + { CCI_REG8(0x0265), 0xf2 }, + { CCI_REG8(0x0266), 0x3 }, + { CCI_REG8(0x0267), 0xf5 }, + { CCI_REG8(0x0268), 0x3 }, + { CCI_REG8(0x0269), 0xf6 }, + { CCI_REG8(0x026a), 0x3 }, + { CCI_REG8(0x026b), 0x0 }, + { CCI_REG8(0x026c), 0x2 }, + { CCI_REG8(0x026d), 0x87 }, + { CCI_REG8(0x026e), 0x0 }, + { CCI_REG8(0x026f), 0x1 }, + { CCI_REG8(0x0270), 0x3 }, + { CCI_REG8(0x0271), 0xff }, + { CCI_REG8(0x0272), 0x3 }, + { CCI_REG8(0x0273), 0x0 }, + { CCI_REG8(0x0274), 0x3 }, + { CCI_REG8(0x0275), 0xff }, + { CCI_REG8(0x0276), 0x2 }, + { CCI_REG8(0x0277), 0x87 }, + { CCI_REG8(0x0278), 0x3 }, + { CCI_REG8(0x0279), 0x2 }, + { CCI_REG8(0x027a), 0x3 }, + { CCI_REG8(0x027b), 0xf }, + { CCI_REG8(0x027c), 0x3 }, + { CCI_REG8(0x027d), 0xf7 }, + { CCI_REG8(0x027e), 0x0 }, + { CCI_REG8(0x027f), 0x16 }, + { CCI_REG8(0x0280), 0x0 }, + { CCI_REG8(0x0281), 0x33 }, + { CCI_REG8(0x0282), 0x0 }, + { CCI_REG8(0x0283), 0x4 }, + { CCI_REG8(0x0284), 0x0 }, + { CCI_REG8(0x0285), 0x11 }, + { CCI_REG8(0x0286), 0x3 }, + { CCI_REG8(0x0287), 0x9 }, + { CCI_REG8(0x0288), 0x0 }, + { CCI_REG8(0x0289), 0x2 }, + { CCI_REG8(0x028a), 0x0 }, + { CCI_REG8(0x028b), 0x20 }, + { CCI_REG8(0x028c), 0x0 }, + { CCI_REG8(0x028d), 0xb5 }, + { CCI_REG8(0x028e), 0x0 }, + { CCI_REG8(0x028f), 0xe5 }, + { CCI_REG8(0x0290), 0x0 }, + { CCI_REG8(0x0291), 0x12 }, + { CCI_REG8(0x0292), 0x0 }, + { CCI_REG8(0x0293), 0xb5 }, + { CCI_REG8(0x0294), 0x0 }, + { CCI_REG8(0x0295), 0xe5 }, + { CCI_REG8(0x0296), 0x0 }, + { CCI_REG8(0x0297), 0x10 }, + { CCI_REG8(0x0298), 0x0 }, + { CCI_REG8(0x0299), 0x2 }, + { CCI_REG8(0x029a), 0x0 }, + { CCI_REG8(0x029b), 0x20 }, + { CCI_REG8(0x029c), 0x0 }, + { CCI_REG8(0x029d), 0xb5 }, + { CCI_REG8(0x029e), 0x0 }, + { CCI_REG8(0x029f), 0xe5 }, + { CCI_REG8(0x02a0), 0x0 }, + { CCI_REG8(0x02a1), 0x12 }, + { CCI_REG8(0x02a2), 0x0 }, + { CCI_REG8(0x02a3), 0xb5 }, + { CCI_REG8(0x02a4), 0x0 }, + { CCI_REG8(0x02a5), 0xe5 }, + { CCI_REG8(0x02a6), 0x0 }, + { CCI_REG8(0x02a7), 0x0 }, + { CCI_REG8(0x02a8), 0x0 }, + { CCI_REG8(0x02a9), 0x12 }, + { CCI_REG8(0x02aa), 0x0 }, + { CCI_REG8(0x02ab), 0x12 }, + { CCI_REG8(0x02ac), 0x0 }, + { CCI_REG8(0x02ad), 0x20 }, + { CCI_REG8(0x02ae), 0x0 }, + { CCI_REG8(0x02af), 0xb5 }, + { CCI_REG8(0x02b0), 0x0 }, + { CCI_REG8(0x02b1), 0xe5 }, + { CCI_REG8(0x02b2), 0x0 }, + { CCI_REG8(0x02b3), 0x0 }, + { CCI_REG8(0x02b4), 0x0 }, + { CCI_REG8(0x02b5), 0x12 }, + { CCI_REG8(0x02b6), 0x0 }, + { CCI_REG8(0x02b7), 0x12 }, + { CCI_REG8(0x02b8), 0x0 }, + { CCI_REG8(0x02b9), 0x20 }, + { CCI_REG8(0x02ba), 0x0 }, + { CCI_REG8(0x02bb), 0x47 }, + { CCI_REG8(0x02bc), 0x0 }, + { CCI_REG8(0x02bd), 0x27 }, + { CCI_REG8(0x02be), 0x0 }, + { CCI_REG8(0x02bf), 0xb5 }, + { CCI_REG8(0x02c0), 0x0 }, + { CCI_REG8(0x02c1), 0xe5 }, + { CCI_REG8(0x02c2), 0x0 }, + { CCI_REG8(0x02c3), 0x0 }, + { CCI_REG8(0x02c4), 0x0 }, + { CCI_REG8(0x02c5), 0x4 }, + { CCI_REG8(0x02c6), 0x0 }, + { CCI_REG8(0x02c7), 0x43 }, + { CCI_REG8(0x02c8), 0x0 }, + { CCI_REG8(0x02c9), 0x1 }, + { CCI_REG8(0x02ca), 0x3 }, + { CCI_REG8(0x02cb), 0x2 }, + { CCI_REG8(0x02cc), 0x0 }, + { CCI_REG8(0x02cd), 0x8 }, + { CCI_REG8(0x02ce), 0x3 }, + { CCI_REG8(0x02cf), 0xff }, + { CCI_REG8(0x02d0), 0x2 }, + { CCI_REG8(0x02d1), 0x87 }, + { CCI_REG8(0x02d2), 0x3 }, + { CCI_REG8(0x02d3), 0xc7 }, + { CCI_REG8(0x02d4), 0x3 }, + { CCI_REG8(0x02d5), 0xf7 }, + { CCI_REG8(0x02d6), 0x0 }, + { CCI_REG8(0x02d7), 0x77 }, + { CCI_REG8(0x02d8), 0x0 }, + { CCI_REG8(0x02d9), 0x17 }, + { CCI_REG8(0x02da), 0x0 }, + { CCI_REG8(0x02db), 0x8 }, + { CCI_REG8(0x02dc), 0x3 }, + { CCI_REG8(0x02dd), 0xff }, + { CCI_REG8(0x02de), 0x0 }, + { CCI_REG8(0x02df), 0x38 }, + { CCI_REG8(0x02e0), 0x0 }, + { CCI_REG8(0x02e1), 0x17 }, + { CCI_REG8(0x02e2), 0x0 }, + { CCI_REG8(0x02e3), 0x8 }, + { CCI_REG8(0x02e4), 0x3 }, + { CCI_REG8(0x02e5), 0xff }, + { CCI_REG8(0x02e6), 0x3 }, + { CCI_REG8(0x02e7), 0xff }, + { CCI_REG8(0x02e8), 0x3 }, + { CCI_REG8(0x02e9), 0xff }, + { CCI_REG8(0x02ea), 0x3 }, + { CCI_REG8(0x02eb), 0xff }, + { CCI_REG8(0x02ec), 0x3 }, + { CCI_REG8(0x02ed), 0xff }, + { CCI_REG8(0x02ee), 0x3 }, + { CCI_REG8(0x02ef), 0xff }, + { CCI_REG8(0x02f0), 0x3 }, + { CCI_REG8(0x02f1), 0xff }, + { CCI_REG8(0x02f2), 0x3 }, + { CCI_REG8(0x02f3), 0xff }, + { CCI_REG8(0x02f4), 0x3 }, + { CCI_REG8(0x02f5), 0xff }, + { CCI_REG8(0x02f6), 0x3 }, + { CCI_REG8(0x02f7), 0xff }, + { CCI_REG8(0x02f8), 0x3 }, + { CCI_REG8(0x02f9), 0xff }, + { CCI_REG8(0x02fa), 0x3 }, + { CCI_REG8(0x02fb), 0xff }, + { CCI_REG8(0x02fc), 0x3 }, + { CCI_REG8(0x02fd), 0xff }, + { CCI_REG8(0x02fe), 0x3 }, + { CCI_REG8(0x02ff), 0xff }, + { CCI_REG8(0x0300), 0x3 }, + { CCI_REG8(0x0301), 0xff }, + { CCI_REG8(0x0302), 0x3 }, + { CCI_REG8(0x0303), 0xff }, + { CCI_REG8(0x01e9), 0x0 }, + { CCI_REG8(0x01e8), 0x19 }, + { CCI_REG8(0x01ea), 0x35 }, + { CCI_REG8(0x01eb), 0x37 }, + { CCI_REG8(0x01ec), 0x64 }, + { CCI_REG8(0x01ed), 0x6b }, + { CCI_REG8(0x01f8), 0xf }, + { CCI_REG8(0x01d8), 0x1 }, + { CCI_REG8(0x01dc), 0x1 }, + { CCI_REG8(0x01de), 0x1 }, + { CCI_REG8(0x0189), 0x1 }, + { CCI_REG8(0x01b7), 0x1 }, + { CCI_REG8(0x01c1), 0x7 }, + { CCI_REG8(0x01c2), 0xf6 }, + { CCI_REG8(0x01c3), 0xff }, + { CCI_REG8(0x01c9), 0x7 }, + { CCI_REG8(0x0325), 0x0 }, + { CCI_REG8(0xe159), 0x0 }, + { CCI_REG8(0x033a), 0x0 }, + { CCI_REG8(0x01b8), 0x1 }, + { CCI_REG8(0x01ba), 0x33 }, + { CCI_REG8(0x01be), 0x74 }, + { CCI_REG8(0x01bf), 0x36 }, + { CCI_REG8(0x01c0), 0x53 }, + { CCI_REG8(0x00ef), 0x0 }, + { CCI_REG8(0x0326), 0x0 }, + { CCI_REG8(0x00f0), 0x0 }, + { CCI_REG8(0x00f1), 0x0 }, + { CCI_REG8(0x0327), 0x0 }, + { CCI_REG8(0x00f2), 0x0 }, + { CCI_REG8(0x0071), 0x1 }, + { CCI_REG8(0x01b4), 0x1 }, + { CCI_REG8(0x01b5), 0x1 }, + { CCI_REG8(0x01f1), 0x1 }, + { CCI_REG8(0x01f4), 0x1 }, + { CCI_REG8(0x01f5), 0x1 }, + { CCI_REG8(0x0314), 0x1 }, + { CCI_REG8(0x0315), 0x1 }, + { CCI_REG8(0x0316), 0x1 }, + { CCI_REG8(0x0207), 0x0 }, + { CCI_REG8(0x4207), 0x2 }, + { CCI_REG8(0x2207), 0x2 }, + { CCI_REG8(0xe088), 0x1 }, + { CCI_REG8(0xe08d), 0x0 }, + { CCI_REG8(0xe08e), 0x30 }, + { CCI_REG8(0xe08f), 0xd4 }, + { CCI_REG8(0xe089), 0x56 }, + { CCI_REG8(0xe08a), 0x10 }, + { CCI_REG8(0xe08b), 0x1f }, + { CCI_REG8(0xe08c), 0xf }, + { CCI_REG8(0xe0a6), 0x0 }, + { CCI_REG8(0xe0a9), 0x10 }, + { CCI_REG8(0xe0aa), 0x0 }, + { CCI_REG8(0xe0ad), 0xa }, + { CCI_REG8(0xe0a8), 0x30 }, + { CCI_REG8(0xe0a7), 0xf }, + { CCI_REG8(0xe0ac), 0x10 }, + { CCI_REG8(0xe0ab), 0xf }, + { CCI_REG8(0x209d), 0x0 }, + { CCI_REG8(0x0328), 0x0 }, + { CCI_REG8(0x0063), 0x1 }, + { CCI_REG8(0x01f7), 0xf }, + { CCI_REG8(0xe0e3), 0x1 }, + { CCI_REG8(0xe0e7), 0x3 }, + { CCI_REG8(0xe33b), 0x0 }, + { CCI_REG8(0xe336), 0x0 }, + { CCI_REG8(0xe337), 0x0 }, + { CCI_REG8(0xe338), 0x0 }, + { CCI_REG8(0xe339), 0x0 }, + { CCI_REG8(0x00e9), 0x1 }, + { CCI_REG8(0x00ea), 0xfe }, + { CCI_REG8(0x0309), 0x3 }, + { CCI_REG8(0x030a), 0x2 }, + { CCI_REG8(0x030b), 0x2 }, + { CCI_REG8(0x030c), 0x5 }, + { CCI_REG8(0x030e), 0x15 }, + { CCI_REG8(0x030d), 0x14 }, + { CCI_REG8(0x030f), 0x1 }, + { CCI_REG8(0x0310), 0xd }, + { CCI_REG8(0x01d0), 0x1f }, + { CCI_REG8(0x01d1), 0x1f }, + { CCI_REG8(0x01cd), 0x11 }, + { CCI_REG8(0x0016), 0x0 }, + { CCI_REG8(0x0017), 0x5 }, + { CCI_REG8(0x01f2), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0xe0a2), 0x0 }, + { CCI_REG8(0xe07b), 0x0 }, + { CCI_REG8(0xe078), 0x0 }, + { CCI_REG8(0xe079), 0x1 }, + { CCI_REG8(0xe136), 0x0 }, + { CCI_REG8(0xe0c6), 0x0 }, + { CCI_REG8(0xe0c7), 0x0 }, + { CCI_REG8(0xe0c8), 0x1 }, + { CCI_REG8(0xe0c9), 0x0 }, + { CCI_REG8(0xe0ca), 0x0 }, + { CCI_REG8(0xe0cb), 0x1 }, + { CCI_REG8(0xe0cc), 0x80 }, + { CCI_REG8(0xe0cd), 0x80 }, + { CCI_REG8(0xe0be), 0x2 }, + { CCI_REG8(0xe0bf), 0x2 }, + { CCI_REG8(0xe0c4), 0x8 }, + { CCI_REG8(0xe0c5), 0x8 }, + { CCI_REG8(0x2075), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x001e), 0x1 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x207e), 0x0 }, + { CCI_REG8(0xe084), 0x0 }, + { CCI_REG8(0xe085), 0x0 }, + { CCI_REG8(0xe086), 0x1 }, + { CCI_REG8(0xe087), 0x0 }, + { CCI_REG8(0x207f), 0x0 }, + { CCI_REG8(0x2080), 0x0 }, + { CCI_REG8(0x2081), 0x3 }, + { CCI_REG8(0x2082), 0x0 }, + { CCI_REG8(0x2083), 0x2 }, + { CCI_REG8(0x0090), 0x0 }, + { CCI_REG8(0x2097), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x0011), 0x3 }, + { CCI_REG8(0x011d), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x0193), 0x8 }, + { CCI_REG8(0x0194), 0x4 }, + { CCI_REG8(0xe32c), 0x1 }, + { CCI_REG8(0xe32d), 0x0 }, + { CCI_REG8(0xe14e), 0x0 }, + { CCI_REG8(0xe312), 0x7f }, + { CCI_REG8(0xe329), 0x1 }, + { CCI_REG8(0xe32b), 0x0 }, + { CCI_REG8(0xe331), 0xf }, + { CCI_REG8(0xe332), 0x3 }, + { CCI_REG8(0xe32a), 0x0 }, + { CCI_REG8(0xe11e), 0x1 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0xe009), 0x1 }, + { CCI_REG8(0x212f), 0x1 }, + { CCI_REG8(0x2130), 0x1 }, + { CCI_REG8(0x2131), 0x1 }, + { CCI_REG8(0x2132), 0x1 }, + { CCI_REG8(0x2133), 0x1 }, + { CCI_REG8(0x2134), 0x1 }, + { CCI_REG8(0x2135), 0x1 }, + { CCI_REG8(0xe0e1), 0x1 }, + { CCI_REG8(0x018a), 0x1 }, + { CCI_REG8(0x00e0), 0x1 }, + { CCI_REG8(0xe32e), 0x1 }, + { CCI_REG8(0xe340), 0x1 }, + { CCI_REG8(0xe004), 0x0 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0x000e), 0x0 }, + { CCI_REG8(0x000f), 0x0 }, + { CCI_REG8(0x0010), 0x3 }, + { CCI_REG8(0x0011), 0xe8 }, + { CCI_REG8(0x0012), 0x0 }, + { CCI_REG8(0x0013), 0x0 }, + { CCI_REG8(0x0014), 0x0 }, + { CCI_REG8(0x0015), 0x0 }, + { CCI_REG8(0xe004), 0x1 }, + { CCI_REG8(0x000e), 0x0 }, + { CCI_REG8(0x000f), 0x0 }, + { CCI_REG8(0x0010), 0x3 }, + { CCI_REG8(0x0011), 0xe8 }, + { CCI_REG8(0x0012), 0x0 }, + { CCI_REG8(0x0013), 0x0 }, + { CCI_REG8(0x0014), 0x0 }, + { CCI_REG8(0x0015), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x0057), 0x0 }, + { CCI_REG8(0x0058), 0x0 }, + { CCI_REG8(0x0059), 0x2 }, + { CCI_REG8(0x005a), 0x2 }, + { CCI_REG8(0x005b), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0xe008), 0x0 }, + { CCI_REG8(0x0006), 0x1 }, + { CCI_REG8(0xe003), 0x0 }, + { CCI_REG8(0x0006), 0x0 }, + { CCI_REG8(0xe008), 0x0 }, + { CCI_REG8(0xe004), 0x0 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0x0031), 0x0 }, + { CCI_REG8(0xe004), 0x1 }, + { CCI_REG8(0x0031), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x0138), 0x0 }, + { CCI_REG8(0xe005), 0x0 }, + { CCI_REG8(0x0139), 0x0 }, + { CCI_REG8(0x013a), 0x0 }, + { CCI_REG8(0x013b), 0x64 }, + { CCI_REG8(0x013c), 0x0 }, + { CCI_REG8(0x013d), 0x0 }, + { CCI_REG8(0x013e), 0x64 }, + { CCI_REG8(0x013f), 0x6 }, + { CCI_REG8(0x0140), 0x1 }, + { CCI_REG8(0x0141), 0x10 }, + { CCI_REG8(0x0142), 0x1 }, + { CCI_REG8(0x0143), 0x0 }, + { CCI_REG8(0x0144), 0x0 }, + { CCI_REG8(0x0146), 0x0 }, + { CCI_REG8(0x0147), 0x0 }, + { CCI_REG8(0x0148), 0x0 }, + { CCI_REG8(0xe004), 0x0 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0x0026), 0x0 }, + { CCI_REG8(0xe004), 0x1 }, + { CCI_REG8(0x0026), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x0169), 0x12 }, + { CCI_REG8(0xe004), 0x0 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0x001c), 0x0 }, + { CCI_REG8(0x0019), 0x0 }, + { CCI_REG8(0x001a), 0x7 }, + { CCI_REG8(0x001b), 0x53 }, + { CCI_REG8(0x0016), 0x8 }, + { CCI_REG8(0x0017), 0x0 }, + { CCI_REG8(0x0018), 0x0 }, + { CCI_REG8(0xe004), 0x1 }, + { CCI_REG8(0x001c), 0x0 }, + { CCI_REG8(0x0019), 0x0 }, + { CCI_REG8(0x001a), 0x7 }, + { CCI_REG8(0x001b), 0x53 }, + { CCI_REG8(0x0016), 0x8 }, + { CCI_REG8(0x0017), 0x0 }, + { CCI_REG8(0x0018), 0x0 }, + { CCI_REG8(0xe004), 0x0 }, + { CCI_REG8(0xe000), 0x1 }, + { CCI_REG8(0x001d), 0x0 }, + { CCI_REG8(0xe004), 0x1 }, + { CCI_REG8(0x001d), 0x0 }, + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0x001a), 0x0 }, + { CCI_REG8(0x001b), 0x0 }, + { CCI_REG8(0x001c), 0x0 }, +}; + +static const struct cci_reg_sequence mira016_soft_reset_release[] = { + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0xe009), 0x1 }, + { CCI_REG8(0x212f), 0x1 }, + { CCI_REG8(0x2130), 0x1 }, + { CCI_REG8(0x2131), 0x1 }, + { CCI_REG8(0x2132), 0x1 }, + { CCI_REG8(0x2133), 0x1 }, + { CCI_REG8(0x2134), 0x1 }, + { CCI_REG8(0x2135), 0x1 }, + { CCI_REG8(0xe0e1), 0x1 }, + { CCI_REG8(0x018a), 0x1 }, + { CCI_REG8(0x00e0), 0x1 }, +}; + +static const struct cci_reg_sequence mira016_soft_reset_assert[] = { + { CCI_REG8(0xe000), 0x0 }, + { CCI_REG8(0xe009), 0x0 }, + { CCI_REG8(0x018a), 0x0 }, + { CCI_REG8(0x00e0), 0x0 }, + { CCI_REG8(0xe0e1), 0x0 }, + { CCI_REG8(0x212f), 0x0 }, + { CCI_REG8(0x2130), 0x0 }, + { CCI_REG8(0x2131), 0x0 }, + { CCI_REG8(0x2132), 0x0 }, + { CCI_REG8(0x2133), 0x0 }, + { CCI_REG8(0x2134), 0x0 }, + { CCI_REG8(0x2135), 0x0 }, + { CCI_REG8(0xe009), 0x0 }, +}; + +struct mira016_fine_gain { + u8 gdig_preamp; + u8 rg_adcgain; + u8 rg_mult; +}; + +/* + * Fine analogue gain of the Mira016, from the formula: + * + * analogue_gain = 57 * 2^(MIRA016_RG_REF - RG_MULT) / (ADC_GAIN + 21) + * + * with ADC_GAIN in the [21, 63] range and MIRA016_RG_REF fixed at 2 for Mira016. + * + * The analogue gain is realized by controlling the ADC ramp current which gives + * a gain multiplier up to 4x. In 8-bit mode the digital gain GDIG_PREAMP takes + * the 10-bit ADC result to 8 bit and gives an additional 4x. + * + * @max_shift: 2 in 8-bit mode, 0 in 10-bit mode + * @bit_factor: 4 in 8-bit mode, 1 in 10-bit mode + * @fg: the calculated register values + */ +static void mira016_fine_gain(u32 code, u32 gain, struct mira016_fine_gain *fg) +{ + unsigned int bit_shift; + unsigned int n, k, j; + int adc; + + /* + * In 8-bit mode the digital gain takes the 10-bit ADC result to 8 bit + * and gives another 4x. + */ + switch (code) { + case MEDIA_BUS_FMT_Y8_1X8: + bit_shift = 2; + break; + case MEDIA_BUS_FMT_Y10_1X10: + bit_shift = 0; + break; + default: + /* 12 bit gain is fixed, we shouldn't be getting here. */ + return; + }; + + gain = clamp_t(u32, gain, MIRA016_GAIN_UNIT, + (4U * MIRA016_GAIN_UNIT) << bit_shift); + + /* + * Analogue octave: largest n with 57 * 2^n <= 84 * gain (84 = 63 + 21). + * + * Limited to 2 for 10 bits, goes up to 4 for 8 bits. The remainder of + * the gain that cannot be obtained through the ADC ramp current goes to + * the digital part for the 8-bits mode. + */ + for (n = 0; n < 2 + bit_shift; n++) { + if (MIRA016_ADC_GAIN_VAL(n + 1) > 84U * gain) + break; + } + + k = min(n, 2U); + j = n - k; + adc = (int)DIV_ROUND_CLOSEST(MIRA016_ADC_GAIN_VAL(n), gain) - 21; + + fg->rg_adcgain = clamp(adc, 0, MIRA016_BIAS_RG_ADCGAIN_MAX); + fg->rg_mult = MIRA016_FINE_GAIN_REF_MULT - k; + fg->gdig_preamp = (16U << j) / BIT(bit_shift) - 1; +} + +static const u32 mira016_mbus_formats[] = { + MEDIA_BUS_FMT_Y12_1X12, + MEDIA_BUS_FMT_Y10_1X10, + MEDIA_BUS_FMT_Y8_1X8, +}; + +static void mira016_update_pad_format(struct mira016 *mira016, + struct v4l2_mbus_framefmt *fmt) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(mira016_mbus_formats); ++i) { + if (mira016_mbus_formats[i] == fmt->code) + break; + } + if (i == ARRAY_SIZE(mira016_mbus_formats)) + fmt->code = mira016_mbus_formats[0]; + + fmt->width = MIRA016_PIXEL_ARRAY_WIDTH; + fmt->height = MIRA016_PIXEL_ARRAY_HEIGHT; + fmt->field = V4L2_FIELD_NONE; + fmt->colorspace = V4L2_COLORSPACE_RAW; + fmt->ycbcr_enc = V4L2_YCBCR_ENC_601; + fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; + fmt->xfer_func = V4L2_XFER_FUNC_NONE; +} + +static u32 mira016_calc_phy_timings(struct mira016 *mira016, + struct v4l2_mbus_framefmt *fmt) +{ + u32 phy_time = 580; + + /* + * PHY timings depend on format, clock mode and integration mode. + * Assume 'global timing mode' unconditionally. + */ + + switch (fmt->code) { + case MEDIA_BUS_FMT_Y8_1X8: + break; + case MEDIA_BUS_FMT_Y10_1X10: + phy_time += 100; + break; + case MEDIA_BUS_FMT_Y12_1X12: + phy_time += 200; + break; + } + + if (mira016->bus_config & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK) + phy_time += 130; + + return phy_time; +} + +static u32 mira016_calc_adc_timings(struct mira016 *mira016, + struct v4l2_mbus_framefmt *fmt) +{ + u32 adc_time = 1062; + + /* + * ADC timings depend on format, gain mode, clock mode and binning. + * + * TODO: assume 'fine' gain model for 8 and 10 bit modes and no binning + * until proper support is implemented using the Common Raw Sensor + * model. + */ + switch (fmt->code) { + case MEDIA_BUS_FMT_Y8_1X8: + adc_time = 1062; + break; + case MEDIA_BUS_FMT_Y10_1X10: + adc_time = 1062; + break; + case MEDIA_BUS_FMT_Y12_1X12: + adc_time = 1504; + break; + } + + return adc_time; +} + +static int mira016_calc_row_length(struct mira016 *mira016, + struct v4l2_subdev_state *state) +{ + struct v4l2_mbus_framefmt *fmt = v4l2_subdev_state_get_format(state, 0); + u32 phy_timings = mira016_calc_phy_timings(mira016, fmt); + u32 adc_timings = mira016_calc_adc_timings(mira016, fmt); + + mira016->timings.row_length = max(phy_timings, adc_timings); + + return 0; +} + +static int mira016_set_pad_format(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *fmt) +{ + struct mira016 *mira016 = to_mira016(sd); + struct v4l2_rect *crop; + u32 pixel_rate; + u32 min_vblank; + u32 gain_max; + int ret; + + /* + * Changing the active image format implies updating the row_length + * parameter, which changes the line duration and the pixel rate + * consequentially. Also, changing the image format changes the analogue + * gain limits. + * + * Do not allow to change image format while the subdevice is streaming. + * + * TODO: row length depends on binning, update it also in the + * implementation of set_selection. + */ + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE && + v4l2_subdev_is_streaming(sd)) + return -EBUSY; + + mira016_update_pad_format(mira016, &fmt->format); + *v4l2_subdev_state_get_format(state, 0) = fmt->format; + + crop = v4l2_subdev_state_get_crop(state, 0); + crop->width = fmt->format.width; + crop->height = fmt->format.height; + crop->left = MIRA016_PIXEL_ARRAY_LEFT; + crop->top = MIRA016_PIXEL_ARRAY_TOP; + + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) + return 0; + + switch (fmt->format.code) { + case MEDIA_BUS_FMT_Y8_1X8: + gain_max = MIRA016_GAIN_MAX_8B; + break; + case MEDIA_BUS_FMT_Y10_1X10: + gain_max = MIRA016_GAIN_MAX_10B; + break; + case MEDIA_BUS_FMT_Y12_1X12: + default: + /* + * TODO: Clarify how to handle 12 bit 2x fixed gain which + * changes the line timings while streaming. Only allow 1x + * for the time being. + */ + gain_max = MIRA016_GAIN_UNIT; + break; + } + + ret = __v4l2_ctrl_modify_range(mira016->gain, MIRA016_GAIN_UNIT, + gain_max, 1, MIRA016_GAIN_UNIT); + if (ret) + return ret; + + mira016_calc_row_length(mira016, state); + + min_vblank = mira016_calc_min_vblank(mira016, crop->height); + ret = __v4l2_ctrl_modify_range(mira016->vblank, min_vblank, + MIRA016_MAX_VBLANK, 1, min_vblank); + if (ret) + return ret; + + pixel_rate = mira016_calc_prate(mira016, crop->width); + + return __v4l2_ctrl_modify_range(mira016->prate, pixel_rate, pixel_rate, + 1, pixel_rate); +} + +static int mira016_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_mbus_code_enum *code) +{ + if (code->index >= ARRAY_SIZE(mira016_mbus_formats)) + return -EINVAL; + + code->code = mira016_mbus_formats[code->index]; + + return 0; +} + +static int mira016_get_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_selection *sel) +{ + switch (sel->target) { + case V4L2_SEL_TGT_CROP: + sel->r = *v4l2_subdev_state_get_crop(state, 0); + return 0; + + case V4L2_SEL_TGT_NATIVE_SIZE: + sel->r.top = 0; + sel->r.left = 0; + sel->r.width = MIRA016_NATIVE_WIDTH; + sel->r.height = MIRA016_NATIVE_HEIGHT; + return 0; + + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP_BOUNDS: + sel->r.top = MIRA016_PIXEL_ARRAY_TOP; + sel->r.left = MIRA016_PIXEL_ARRAY_LEFT; + sel->r.width = MIRA016_PIXEL_ARRAY_WIDTH; + sel->r.height = MIRA016_PIXEL_ARRAY_HEIGHT; + return 0; + } + + return -EINVAL; +} + +static int mira016_enum_frame_size(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_frame_size_enum *fse) +{ + unsigned int i; + + if (fse->index) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(mira016_mbus_formats); ++i) { + if (mira016_mbus_formats[i] == fse->code) + break; + } + if (i == ARRAY_SIZE(mira016_mbus_formats)) + return -EINVAL; + + fse->min_width = MIRA016_PIXEL_ARRAY_WIDTH; + fse->max_width = fse->min_width; + fse->min_height = MIRA016_PIXEL_ARRAY_HEIGHT; + fse->max_height = fse->min_height; + + return 0; +} + +static int mira016_start_streaming(struct mira016 *mira016) +{ + int ret = 0; + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_CMD_REQ_1_REG, 1, &ret); + fsleep(10); + cci_write(mira016->regmap, MIRA016_CMD_REQ_1_REG, 0, &ret); + fsleep(10); + + return ret; +} + +static int mira016_stop_streaming(struct mira016 *mira016) +{ + int ret = 0; + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_CMD_HALT_BLOCK_REG, 1, &ret); + fsleep(10); + cci_write(mira016->regmap, MIRA016_CMD_HALT_BLOCK_REG, 0, &ret); + fsleep(10); + + return ret; +} + +static int mira016_configure_pll(struct mira016 *mira016) +{ + int ret = 0; + u64 val; + + /* Configure the PLL clock tree. */ + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 0, &ret); + + cci_write(mira016->regmap, MIRA016_PLL_DIV_N_REG, mira016->pll.n, &ret); + cci_write(mira016->regmap, MIRA016_PLL_DIV_M_REG, mira016->pll.m, &ret); + cci_write(mira016->regmap, MIRA016_CLKGEN_CP_DIV_REG, + mira016->pll.cp_div, &ret); + cci_write(mira016->regmap, MIRA016_OTP_GRANULARITY_REG, + mira016->pll.otp_gran, &ret); + cci_write(mira016->regmap, MIRA016_GRAN_TG_REG, mira016->pll.gran_tg, &ret); + cci_write(mira016->regmap, MIRA016_LUT_DEL008_REG, + mira016->pll.lut_del, &ret); + cci_write(mira016->regmap, MIRA016_CLKGEN_TX_ESC_H_REG, + mira016->pll.esc_h, &ret); + cci_write(mira016->regmap, MIRA016_CLKGEN_TX_ESC_L_REG, + mira016->pll.esc_l, &ret); + cci_write(mira016->regmap, MIRA016_PLL_PD_REG, 0, &ret); + if (ret) + return ret; + + return read_poll_timeout(cci_read, ret, + (ret < 0 || (val & MIRA016_PLL_LOCKED)), + 500, 10000, false, mira016->regmap, + MIRA016_PLL_LOCK_REG, &val, NULL); +} + +static int mira016_configure_timings(struct mira016 *mira016) +{ + int ret = 0; + /* Configure the sensor timings. */ + + cci_write(mira016->regmap, MIRA016_TIME_UNIT_REG, + mira016->timings.time_base, &ret); + cci_write(mira016->regmap, MIRA016_GLOB_TIME_REG, + mira016->timings.glob_time, &ret); + cci_write(mira016->regmap, MIRA016_GLOB_TIME_A_REG, + mira016->timings.glob_time, &ret); + cci_write(mira016->regmap, MIRA016_GLOB_TIME_B_REG, + mira016->timings.glob_time, &ret); + cci_write(mira016->regmap, MIRA016_ENTER_LPS_TIME_REG, + MIRA016_ENTER_LPS_TIME_1500MBPS, &ret); + cci_write(mira016->regmap, MIRA016_EXIT_LPS_TIME_REG, + MIRA016_EXIT_LPS_TIME_1500MBPS, &ret); + cci_write(mira016->regmap, MIRA016_LPS_CYCLE_TIME_REG, + MIRA016_LPS_CYCLE_TIME_1500MBPS, &ret); + + return ret; +} + +static int mira016_configure_horizontal_roi(struct mira016 *mira016, + struct v4l2_subdev_state *state) +{ + /* + * TODO: Support for binning and subsampling using the Common Raw + * Sensor model. This will require to re-calculate the FIFO threshold + * and the hsync length with an updated: + * + * reduction_factor = 2 ^ xbinning * 2 ^ xsubsampling + */ + u16 reduction_factor = 4; + struct v4l2_mbus_framefmt *fmt = v4l2_subdev_state_get_format(state, 0); + struct v4l2_rect *crop = v4l2_subdev_state_get_crop(state, 0); + u16 nr_of_pixels = crop->width / reduction_factor; + u16 xwin_right = crop->left + crop->width - 1; + u16 fifo_threshold; + u16 hsync_length; + int ret = 0; + + cci_write(mira016->regmap, MIRA016_XWIN_LEFT_REG, crop->left, &ret); + cci_write(mira016->regmap, MIRA016_XWIN_RIGHT_REG, xwin_right, &ret); + cci_write(mira016->regmap, MIRA016_XMIRROR_REG, + mira016->hflip->val, &ret); + + cci_write(mira016->regmap, MIRA016_XSUBSAMPLING_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_XBINNING_REG, 0, &ret); + + fifo_threshold = nr_of_pixels - (nr_of_pixels / reduction_factor); + fifo_threshold = max(70, fifo_threshold); + + /* + * FIXME: override for 8 bit mode with magic number from register + * sequences. Using the value calculated according to the datasheet + * introduces artifacts in 8-bit mode. + */ + if (fmt->code == MEDIA_BUS_FMT_Y8_1X8) + fifo_threshold = 0x28; + + cci_write(mira016->regmap, MIRA016_MIPI_DATA_FIFO_THR_REG, + fifo_threshold, &ret); + + /* Assume Global Timing mode when calculating HSYNC length. */ + hsync_length = max(56, crop->width / 2); + cci_write(mira016->regmap, MIRA016_HSYNC_LENGTH, hsync_length, &ret); + + return ret; +} + +static int mira016_configure_vertical_roi(struct mira016 *mira016, + struct v4l2_subdev_state *state) +{ + struct v4l2_rect *crop = v4l2_subdev_state_get_crop(state, 0); + int ret = 0; + u32 top; + + /* + * Program the first two windows and zero the other 8 to disable them. + * + * FIXME: Mira016 workaround - Window 1 is not functional. Program + * 2 identical windows in Window 1 and Window 2 but only use the second + * one (YWIN_ENA = 2). + * + * TODO: Support for binning and subsampling using the Common Raw + * Sensor model. + */ + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_ENA_REG, 0x02, &ret); + cci_write(mira016->regmap, MIRA016_YBINNING_REG, 0x00, &ret); + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_ENA_REG, 0x02, &ret); + cci_write(mira016->regmap, MIRA016_YBINNING_REG, 0x00, &ret); + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_BLACK_REG, 0x00, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_DIR_REG, + mira016->vflip->val, &ret); + + /* The vertical start position depends on the reading direction. */ + top = mira016->vflip->val ? crop->top + crop->height - 1 : crop->top; + cci_write(mira016->regmap, MIRA016_YWIN_SIZE_REG(0), crop->height, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_START_REG(0), top, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_SUBS_REG(0), 0x00, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_SIZE_REG(1), crop->height, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_START_REG(1), top, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_SUBS_REG(1), 0x00, &ret); + + for (unsigned int i = 2; i < MIRA016_NUM_Y_WIND; ++i) { + cci_write(mira016->regmap, MIRA016_YWIN_SIZE_REG(i), 0x00, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_START_REG(i), 0x00, &ret); + cci_write(mira016->regmap, MIRA016_YWIN_SUBS_REG(i), 0x00, &ret); + } + + return ret; +} + +static int mira016_configure_roi(struct mira016 *mira016, + struct v4l2_subdev_state *state) +{ + int ret = 0; + + /* + * Write horizontal configuration to context 0 first, then repeat for + * context 1. + */ + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 1, &ret); + if (ret) + return ret; + + ret = mira016_configure_horizontal_roi(mira016, state); + if (ret) + return ret; + + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 1, &ret); + if (ret) + return ret; + + ret = mira016_configure_horizontal_roi(mira016, state); + if (ret) + return ret; + + ret = mira016_configure_vertical_roi(mira016, state); + if (ret) + return ret; + + return 0; +} + +static int mira016_configure_row_length(struct mira016 *mira016) +{ + int ret = 0; + + /* Configure ROW_LENGTH in both contexts. */ + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_ROW_TIMINGS_REG, + mira016->timings.row_length, &ret); + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_ROW_TIMINGS_REG, + mira016->timings.row_length, &ret); + + return ret; +} + +static int mira016_configure_format(struct mira016 *mira016, + struct v4l2_subdev_state *state) +{ + struct v4l2_mbus_framefmt *fmt = v4l2_subdev_state_get_format(state, 0); + u16 bitwidth; + u8 bitmode; + u8 csi2_dt; + int ret = 0; + + switch (fmt->code) { + case MEDIA_BUS_FMT_Y8_1X8: + csi2_dt = MIPI_CSI2_DT_RAW8; + bitwidth = 8; + bitmode = 0; + break; + case MEDIA_BUS_FMT_Y10_1X10: + csi2_dt = MIPI_CSI2_DT_RAW10; + bitwidth = 16; + bitmode = 1; + break; + case MEDIA_BUS_FMT_Y12_1X12: + default: + csi2_dt = MIPI_CSI2_DT_RAW12; + bitwidth = 32; + bitmode = 2; + break; + } + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_DPATH_BITMODE_REG, bitmode, &ret); + cci_write(mira016->regmap, MIRA016_DPATH_BITWIDTH_A_REG, bitwidth, &ret); + cci_write(mira016->regmap, MIRA016_DPATH_BITWIDTH_B_REG, bitwidth, &ret); + cci_write(mira016->regmap, MIRA016_CSI2_DATA_TYPE_REG, csi2_dt, &ret); + + return ret; +} + +static int mira016_init_analogue_gain(struct mira016 *mira016, + struct v4l2_subdev_state *state) +{ + struct v4l2_mbus_framefmt *fmt = v4l2_subdev_state_get_format(state, 0); + const struct cci_reg_sequence *gain_init_seq; + size_t gain_init_num_regs; + + switch (fmt->code) { + case MEDIA_BUS_FMT_Y8_1X8: + gain_init_seq = mira016_8b_fine_gain_init; + gain_init_num_regs = ARRAY_SIZE(mira016_8b_fine_gain_init); + break; + case MEDIA_BUS_FMT_Y10_1X10: + gain_init_seq = mira016_10b_fine_gain_init; + gain_init_num_regs = ARRAY_SIZE(mira016_10b_fine_gain_init); + break; + case MEDIA_BUS_FMT_Y12_1X12: + default: + gain_init_seq = mira016_12b_fixed_gain_init; + gain_init_num_regs = ARRAY_SIZE(mira016_12b_fixed_gain_init); + break; + } + + return cci_multi_reg_write(mira016->regmap, gain_init_seq, + gain_init_num_regs, NULL); +} + +static int mira016_enable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) +{ + struct mira016 *mira016 = to_mira016(sd); + u32 xclk_mhz = mira016->xclk_freq / HZ_PER_MHZ; + /* t_rst is 5000 * clk_in (plus 100usec margin for safety) */ + u32 t_rst_usec = HZ_PER_KHZ / xclk_mhz * 5 + 100; + int ret; + + /* + * vflip and hflip cannot change during streaming as they're programmed + * with the ROI windows. + */ + __v4l2_ctrl_grab(mira016->hflip, true); + __v4l2_ctrl_grab(mira016->vflip, true); + + ret = pm_runtime_resume_and_get(mira016->dev); + if (ret < 0) + goto err_flip_grab; + + ret = cci_multi_reg_write(mira016->regmap, mira016_soft_reset_release, + ARRAY_SIZE(mira016_soft_reset_release), + NULL); + fsleep(t_rst_usec); + + if (!ret) + ret = mira016_configure_format(mira016, state); + if (!ret) + ret = mira016_configure_timings(mira016); + if (!ret) + ret = mira016_init_analogue_gain(mira016, state); + if (!ret) + ret = mira016_configure_roi(mira016, state); + if (!ret) + ret = mira016_configure_row_length(mira016); + if (!ret) + ret = __v4l2_ctrl_handler_setup(mira016->sd.ctrl_handler); + if (!ret) + ret = mira016_start_streaming(mira016); + if (ret) + goto err_rpm_put; + + return 0; + +err_rpm_put: + pm_runtime_put_autosuspend(mira016->dev); +err_flip_grab: + __v4l2_ctrl_grab(mira016->hflip, false); + __v4l2_ctrl_grab(mira016->vflip, false); + + return ret; +} + +static int mira016_disable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) +{ + struct mira016 *mira016 = to_mira016(sd); + + mira016_stop_streaming(mira016); + + cci_multi_reg_write(mira016->regmap, mira016_soft_reset_assert, + ARRAY_SIZE(mira016_soft_reset_assert), NULL); + + __v4l2_ctrl_grab(mira016->hflip, false); + __v4l2_ctrl_grab(mira016->vflip, false); + + pm_runtime_put_autosuspend(mira016->dev); + + return 0; +} + +static const struct v4l2_subdev_pad_ops mira016_pad_ops = { + .enum_mbus_code = mira016_enum_mbus_code, + .get_fmt = v4l2_subdev_get_fmt, + .set_fmt = mira016_set_pad_format, + .get_selection = mira016_get_selection, + .enum_frame_size = mira016_enum_frame_size, + .enable_streams = mira016_enable_streams, + .disable_streams = mira016_disable_streams, +}; + +static const struct v4l2_subdev_video_ops mira016_video_ops = { + .s_stream = v4l2_subdev_s_stream_helper, +}; + +static const struct v4l2_subdev_ops mira016_subdev_ops = { + .video = &mira016_video_ops, + .pad = &mira016_pad_ops, +}; + +static int mira016_init_state(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state) +{ + struct v4l2_subdev_format fmt = { + .which = V4L2_SUBDEV_FORMAT_TRY, + .pad = 0, + .format = { + .code = MEDIA_BUS_FMT_Y12_1X12, + .width = MIRA016_PIXEL_ARRAY_WIDTH, + .height = MIRA016_PIXEL_ARRAY_HEIGHT + }, + }; + + return mira016_set_pad_format(sd, state, &fmt); +} + +static const struct v4l2_subdev_internal_ops mira016_internal_ops = { + .init_state = mira016_init_state, +}; + +static int mira016_write_exposure_reg(struct mira016 *mira016, + u32 exposure_lines) +{ + u32 exposure_us; + int ret = 0; + + exposure_us = mira016_lines_to_usec(mira016, exposure_lines); + + /* Write Bank 1 context 0 and context 1 */ + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_EXP_TIME_L_REG, exposure_us, &ret); + + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_EXP_TIME_L_REG, exposure_us, &ret); + + return ret; +} + +static int mira016_write_frame_duration_reg(struct mira016 *mira016, + struct v4l2_subdev_state *state, + u32 vblank_lines) +{ + struct v4l2_rect *crop = v4l2_subdev_state_get_crop(state, 0); + u32 frame_duration; + int ret = 0; + + frame_duration = mira016_lines_to_usec(mira016, + crop->height + vblank_lines); + + /* Write Bank 1 context 0 and context 1 */ + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 0, &ret); + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_NUM_FRAMES_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_TARGET_FRAME_TIME_REG, + frame_duration, &ret); + + cci_write(mira016->regmap, MIRA016_RW_CONTEXT_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_NUM_FRAMES_REG, 1, &ret); + cci_write(mira016->regmap, MIRA016_TARGET_FRAME_TIME_REG, + frame_duration, &ret); + + return ret; +} + +static int mira016_write_analogue_gain(struct mira016 *mira016, + struct v4l2_subdev_state *state, + u32 gain) +{ + struct v4l2_mbus_framefmt *format; + struct mira016_fine_gain fg = {}; + int ret = 0; + + format = v4l2_subdev_state_get_format(state, 0); + switch (format->code) { + case MEDIA_BUS_FMT_Y8_1X8: + fallthrough; + case MEDIA_BUS_FMT_Y10_1X10: + mira016_fine_gain(format->code, gain, &fg); + break; + default: + /* 12 bit gain is fixed, nothing to do here. */ + return 0; + } + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 0, &ret); + + cci_write(mira016->regmap, MIRA016_BIAS_RG_ADCGAIN, fg.rg_adcgain, &ret); + cci_write(mira016->regmap, MIRA016_BIAS_RG_MULT, fg.rg_mult, &ret); + cci_write(mira016->regmap, MIRA016_GDIG_PREAMP, fg.gdig_preamp, &ret); + + return ret; +} + +static int mira016_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct mira016 *mira016 = + container_of(ctrl->handler, struct mira016, ctrl_handler); + struct v4l2_subdev_state *state; + struct v4l2_rect *crop; + int ret = 0; + + state = v4l2_subdev_get_locked_active_state(&mira016->sd); + crop = v4l2_subdev_state_get_crop(state, 0); + + if (ctrl->id == V4L2_CID_VBLANK) { + s32 exposure_min = + mira016_nsec_to_lines(mira016, + mira016->timings.min_exposure_time); + s32 exposure_max = crop->height + ctrl->val + - MIRA016_FRAME_INTEGRATION_DIFF; + s32 exposure_def = min(exposure_max, + mira016->exposure->val); + + ret = __v4l2_ctrl_modify_range(mira016->exposure, + exposure_min, + exposure_max, + mira016->exposure->step, + exposure_def); + if (ret) + return ret; + } + + if (!pm_runtime_get_if_in_use(mira016->dev)) + return 0; + + switch (ctrl->id) { + case V4L2_CID_EXPOSURE: + ret = mira016_write_exposure_reg(mira016, ctrl->val); + break; + case V4L2_CID_VBLANK: + ret = mira016_write_frame_duration_reg(mira016, state, ctrl->val); + break; + case V4L2_CID_ANALOGUE_GAIN: + ret = mira016_write_analogue_gain(mira016, state, ctrl->val); + break; + default: + ret = -EINVAL; + break; + } + + pm_runtime_put_autosuspend(mira016->dev); + + return ret; +} + +static const struct v4l2_ctrl_ops mira016_ctrl_ops = { + .s_ctrl = mira016_set_ctrl, +}; + +static int mira016_identify_module(struct mira016 *mira016) +{ + int ret = 0; + u64 val; + + cci_write(mira016->regmap, MIRA016_BANK_SEL_REG, 0, &ret); + cci_read(mira016->regmap, MIRA016_CHIP_ID_REG, &val, &ret); + if (ret || val != MIRA016_CHIP_ID) + return -EINVAL; + + return 0; +} + +/* Power/clock management functions */ +static int mira016_power_off(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct mira016 *mira016 = to_mira016(sd); + + gpiod_set_value_cansleep(mira016->reset_gpio, 1); + clk_disable_unprepare(mira016->xclk); + for (int i = ARRAY_SIZE(mira016_supplies) - 1; i >= 0; i--) + regulator_disable(mira016->supplies[i]); + + return 0; +} + +static int mira016_power_on(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct mira016 *mira016 = to_mira016(sd); + int reg_counter; + int ret; + + for (reg_counter = 0; + reg_counter < ARRAY_SIZE(mira016_supplies); ++reg_counter) { + ret = regulator_enable(mira016->supplies[reg_counter]); + if (ret) { + dev_err(mira016->dev, "failed to enable regulator %s\n", + mira016_supplies[reg_counter]); + goto err_reg_disable; + } + + fsleep(500); + } + + ret = clk_prepare_enable(mira016->xclk); + if (ret) { + dev_err(mira016->dev, "%s: failed to enable clock\n", __func__); + goto err_reg_disable; + } + + gpiod_set_value_cansleep(mira016->reset_gpio, 0); + + fsleep(500); + + ret = cci_multi_reg_write(mira016->regmap, mira016_init_sequence, + ARRAY_SIZE(mira016_init_sequence), NULL); + if (!ret) + ret = mira016_configure_pll(mira016); + if (ret) + goto err_reset_assert; + + return 0; + +err_reset_assert: + gpiod_set_value_cansleep(mira016->reset_gpio, 1); + clk_disable_unprepare(mira016->xclk); +err_reg_disable: + for (reg_counter--; reg_counter >= 0; reg_counter--) + regulator_disable(mira016->supplies[reg_counter]); + return ret; +} + +static const struct dev_pm_ops mira016_pm_ops = { + SET_RUNTIME_PM_OPS(mira016_power_off, mira016_power_on, NULL) +}; + +static int mira016_init_controls(struct mira016 *mira016) +{ + struct v4l2_fwnode_device_properties props; + struct v4l2_ctrl_handler *ctrl_hdlr; + struct v4l2_ctrl *link_freq; + struct v4l2_ctrl *hblank; + u32 min_exposure_lines; + u32 def_exposure; + u32 min_vblank; + u32 def_vblank; + u32 pixel_rate; + int ret; + + ret = v4l2_fwnode_device_parse(mira016->dev, &props); + if (ret) + return ret; + + ctrl_hdlr = &mira016->ctrl_handler; + v4l2_ctrl_handler_init(ctrl_hdlr, 12); + + /* By default, PIXEL_RATE is read only */ + pixel_rate = mira016_calc_prate(mira016, MIRA016_PIXEL_ARRAY_WIDTH); + mira016->prate = v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_PIXEL_RATE, + pixel_rate, pixel_rate, 1, + pixel_rate); + + def_vblank = mira016_nsec_to_lines(mira016, + MIRA016_DEFAULT_DURATION_NSEC); + def_vblank -= MIRA016_PIXEL_ARRAY_HEIGHT; + + min_vblank = mira016_calc_min_vblank(mira016, + MIRA016_PIXEL_ARRAY_HEIGHT); + mira016->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &mira016_ctrl_ops, + V4L2_CID_VBLANK, min_vblank, + MIRA016_MAX_VBLANK, 1, + def_vblank); + + /* Fixed 0 horizontal blanking. */ + hblank = v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_HBLANK, 0, + 0, 1, 0); + + link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &mira016_link_freqs[0]); + + min_exposure_lines = mira016_nsec_to_lines(mira016, + mira016->timings.min_exposure_time); + def_exposure = mira016_nsec_to_lines(mira016, + MIRA016_EXPOSURE_DEF_NSEC); + mira016->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &mira016_ctrl_ops, + V4L2_CID_EXPOSURE, + min_exposure_lines, + MIRA016_MAX_EXPOSURE, 1, + def_exposure); + + mira016->gain = v4l2_ctrl_new_std(ctrl_hdlr, &mira016_ctrl_ops, + V4L2_CID_ANALOGUE_GAIN, + MIRA016_GAIN_UNIT, MIRA016_GAIN_UNIT, + 1, MIRA016_GAIN_UNIT); + + /* + * Changing VFLIP requires re-programming the top point, hence we + * program flips along with the ROI windows at enable_streams time. As + * we grab the flip controls there, there's no need to handle the two + * controls while streaming. + */ + mira016->hflip = v4l2_ctrl_new_std(ctrl_hdlr, NULL, + V4L2_CID_HFLIP, 0, 1, 1, 0); + + mira016->vflip = v4l2_ctrl_new_std(ctrl_hdlr, NULL, + V4L2_CID_VFLIP, 0, 1, 1, 0); + + v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &mira016_ctrl_ops, + &props); + + if (ctrl_hdlr->error) + goto error; + + link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + mira016->sd.ctrl_handler = ctrl_hdlr; + + return 0; + +error: + v4l2_ctrl_handler_free(ctrl_hdlr); + return ctrl_hdlr->error; +} + +static void mira016_timings_calc(struct mira016 *mira016) +{ + /* Time base is the number of input clock cycles per microsecond. */ + mira016->timings.time_base = mira016->xclk_freq / HZ_PER_MHZ; + + /* Seq time base is in pico-seconds, to not lose precision. */ + mira016->timings.seq_time_base = 8 * HZ_PER_MHZ + / mira016->pll.data_rate_mbps; + + /* Min exposure time is in nanoseconds. */ + mira016->timings.min_exposure_time = (151 + mira016->pll.lut_del) + * mira016->pll.gran_tg + * mira016->timings.seq_time_base + / HZ_PER_KHZ; + + /* Glob time is in microseconds. */ + mira016->timings.glob_time = (252 + mira016->pll.lut_del) + * mira016->pll.gran_tg + * mira016->timings.seq_time_base + / HZ_PER_MHZ; +} + +static u8 mira016_n_to_pll_n(u32 pll_n) +{ + /* Table 11: Lookup table for “N to PLL_DIV_N” mapping */ + static const struct pll_n_div { + u8 n; + u8 pll_n; + } pll_n_lut[] = { + { 1, 31 }, { 2, 0 }, { 3, 16 }, { 4, 24 }, { 5, 28 }, + { 6, 14 }, { 7, 7 }, { 8, 19 }, { 9, 9 }, { 10, 4}, + { 11, 2 }, { 12, 17 }, { 13, 8 }, { 14, 20 }, { 15, 10 }, + { 16, 21 }, { 17, 26 }, { 18, 29 }, { 19, 30 }, { 20, 15 }, + { 21, 23 }, { 22, 27 }, { 23, 13 }, { 24, 22 }, { 25, 11 }, + { 26, 5 }, { 27, 18 }, { 28, 25 }, { 29, 12 }, + { 30, 6 }, { 31, 3 }, { 32, 1 } + }; + + for (unsigned int i = 0; i < ARRAY_SIZE(pll_n_lut); ++i) { + if (pll_n_lut[i].n != pll_n) + continue; + + return pll_n_lut[i].pll_n; + } + + return 0; +} + +static u8 mira016_m_to_pll_m(u32 pll_m) +{ + /* Table 12: Lookup table for “M to PLL_DIV_M” mapping */ + static const struct pll_m_div { + u8 m_min; + u8 m_max; + u8 pll_m_min; + u8 pll_m_max; + } pll_m_lut[] = { + { 16, 31, 224, 239 }, { 32, 63, 192, 223 }, + { 64, 127, 128, 191 }, { 128, 255, 0, 127 }, + }; + + for (unsigned int i = 0; i < ARRAY_SIZE(pll_m_lut); ++i) { + const struct pll_m_div *p = &pll_m_lut[i]; + + if (pll_m > p->m_max) + continue; + + return p->pll_m_min + pll_m - p->m_min; + } + + return 0; +} + +static void mira016_pll_calc(struct mira016 *mira016) +{ + /* Multiply link_freq by 2 to account for D-PHY DDR. */ + u64 target_mbps = mira016_link_freqs[__ffs(mira016->link_freq_bitmap)] * 2; + u32 clk_in = mira016->xclk_freq; + u32 best = UINT_MAX; + bool found = false; + u64 data_rate_mbps; + u32 n_best = 0; + u32 m_best = 0; + u32 gran_tg; + u32 n; + u32 m; + + /* + * The PLL clock tree is quite simple: + * + * clk_in / n * m / 2 = csi_link_freq + * + * Test all the m/n values in the accepted ranges and if we can't get + * the exact output frequency use the best approximation we can find. + */ + for (n = MIRA016_PLL_N_MIN; n < MIRA016_PLL_N_MAX; ++n) { + u32 pll1 = clk_in / n; + + if (pll1 < MIRA016_PLL_PLL1_MIN || pll1 > MIRA016_PLL_PLL1_MAX) + continue; + + for (m = MIRA016_PLL_M_MIN; m < MIRA016_PLL_M_MAX; ++m) { + u32 pll2 = pll1 * m; + + if (pll2 < MIRA016_PLL_PLL2_MIN || + pll2 > MIRA016_PLL_PLL2_MAX) + continue; + + if (pll2 == target_mbps) { + found = true; + break; + } + + if (abs(pll2 - target_mbps) < best) { + n_best = n; + m_best = m; + best = abs(pll2 - target_mbps); + } + } + if (found) + break; + } + + if (!found) { + dev_info(mira016->dev, + "Unable to achieve the desired link frequency; frame rate might not be accurate\n"); + n = n_best; + m = m_best; + } + + /* + * Re-calculate the actual output bandwidth in Mbps. The effective data + * rate is required to calculate the sensor base timings. + */ + data_rate_mbps = DIV_ROUND_DOWN_ULL((u64)(clk_in / n) * m, HZ_PER_MHZ); + if (data_rate_mbps < 640 || data_rate_mbps > 1500) { + dev_info(mira016->dev, "Invalid data rate %llu\n", + data_rate_mbps); + data_rate_mbps = 1500; + } + mira016->pll.data_rate_mbps = (u32)data_rate_mbps; + + /* + * Translate the m and n values to their register codes using two + * dedicated look-up tables and complete the PLL configuration. + */ + mira016->pll.n = mira016_n_to_pll_n(n); + mira016->pll.m = mira016_m_to_pll_m(m); + + mira016->pll.otp_gran = DIV_ROUND_UP_ULL(mira016->pll.data_rate_mbps, 160) - 1; + + /* + * As the division might introduce rounding errors, compute gran_tg + * in the Kbps domain and then divide by 10^3. + */ + gran_tg = DIV_ROUND_DOWN_ULL(data_rate_mbps * KHZ_PER_MHZ, 1500); + mira016->pll.gran_tg = DIV_ROUND_UP_ULL(gran_tg * 50, KHZ_PER_MHZ); + + mira016->pll.lut_del = DIV_ROUND_UP_ULL(7000, mira016->pll.gran_tg) - 140; + mira016->pll.byte_period = DIV_ROUND_DOWN_ULL(8000, + mira016->pll.data_rate_mbps); +} + +static int mira016_parse_endpoint(struct device *dev, struct mira016 *mira016) +{ + struct fwnode_handle *endpoint __free(fwnode_handle) = NULL; + struct v4l2_fwnode_endpoint ep_cfg = { + .bus_type = V4L2_MBUS_CSI2_DPHY + }; + int ret; + + endpoint = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0); + if (!endpoint) + return -ENODEV; + + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep_cfg); + if (ret) + return ret; + + /* + * Link frequencies: the driver supports a single link frequency, + * no need to check bitmap after this call. + */ + ret = v4l2_link_freq_to_bitmap(dev, ep_cfg.link_frequencies, + ep_cfg.nr_of_link_frequencies, + mira016_link_freqs, + ARRAY_SIZE(mira016_link_freqs), + &mira016->link_freq_bitmap); + if (ret) { + v4l2_fwnode_endpoint_free(&ep_cfg); + return ret; + } + + /* TODO: Implement D-PHY configuration to support continuous clock. */ + if (!(ep_cfg.bus.mipi_csi2.flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK)) { + dev_err(dev, "Continuous clock is not supported\n"); + v4l2_fwnode_endpoint_free(&ep_cfg); + return -EINVAL; + } + + mira016->bus_config = ep_cfg.bus.mipi_csi2.flags; + + v4l2_fwnode_endpoint_free(&ep_cfg); + + return 0; +} + +static int mira016_get_regulators(struct mira016 *mira016) +{ + for (unsigned int i = 0; i < ARRAY_SIZE(mira016_supplies); i++) { + struct regulator *supply = devm_regulator_get(mira016->dev, + mira016_supplies[i]); + if (IS_ERR(supply)) { + dev_err(mira016->dev, "Failed to get supply %s\n", + mira016_supplies[i]); + return PTR_ERR(supply); + } + mira016->supplies[i] = supply; + } + + return 0; +} + +static int mira016_validate_xclk_freq(struct mira016 *mira016) +{ + u32 xclk_mhz = mira016->xclk_freq / HZ_PER_MHZ; + + /* + * Valid clock frequencies input range: + * 12MHz <= xclk < 20MHz - 24MHz >= xclk <= 64MHz + */ + if (xclk_mhz < 12 || xclk_mhz > 64 || (xclk_mhz >= 20 && xclk_mhz < 24)) + return -EINVAL; + + /* Set the PLL parameters that depend on the input clock frequency */ + mira016->pll.cp_div = xclk_mhz <= 30 ? 1 : 2; + mira016->pll.esc_h = xclk_mhz < 20 ? 0 : xclk_mhz < 40 ? 1 : 2; + mira016->pll.esc_l = xclk_mhz < 20 ? 0 : xclk_mhz < 60 ? 1 : 2; + mira016->pll.esc_period = xclk_mhz < 20 ? + DIV_ROUND_CLOSEST(1000, xclk_mhz) + : xclk_mhz < 40 ? + DIV_ROUND_CLOSEST(2000, xclk_mhz) + : xclk_mhz < 60 ? + DIV_ROUND_CLOSEST(3000, xclk_mhz) + : DIV_ROUND_CLOSEST(4000, xclk_mhz); + + return 0; +} + +static int mira016_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct mira016 *mira016; + int ret; + + mira016 = devm_kzalloc(&client->dev, sizeof(*mira016), GFP_KERNEL); + if (!mira016) + return -ENOMEM; + + mira016->dev = &client->dev; + + ret = mira016_parse_endpoint(dev, mira016); + if (ret) + return ret; + + v4l2_i2c_subdev_init(&mira016->sd, client, &mira016_subdev_ops); + + mira016->regmap = devm_cci_regmap_init_i2c(client, 16); + if (IS_ERR(mira016->regmap)) + return dev_err_probe(dev, PTR_ERR(mira016->regmap), + "failed to initialize CCI\n"); + + mira016->xclk = devm_v4l2_sensor_clk_get(dev, NULL); + if (IS_ERR(mira016->xclk)) + return dev_err_probe(dev, PTR_ERR(mira016->xclk), + "failed to get xclk\n"); + + mira016->xclk_freq = clk_get_rate(mira016->xclk); + if (mira016_validate_xclk_freq(mira016)) { + dev_err(dev, "xclk frequency not supported: %d Hz\n", + mira016->xclk_freq); + return -EINVAL; + } + + ret = mira016_get_regulators(mira016); + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); + + mira016->reset_gpio = devm_gpiod_get_optional(dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(mira016->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(mira016->reset_gpio), + "failed to get reset gpio\n"); + + /* + * Calculate the PLL configuration based on the link frequency + * selected by .dts and compute the sensor timing bases. + * + * Initialize row_length to a value matching the default format for + * exposure and frame time limits calculations. + */ + mira016_pll_calc(mira016); + mira016_timings_calc(mira016); + mira016->timings.row_length = 1504; + + ret = mira016_power_on(dev); + if (ret) + return ret; + + /* Enable runtime PM and power on the device */ + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + ret = mira016_identify_module(mira016); + if (ret) + goto error_power_off; + + ret = mira016_init_controls(mira016); + if (ret) + goto error_power_off; + + /* Initialize subdev */ + mira016->sd.internal_ops = &mira016_internal_ops; + mira016->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + mira016->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; + + /* Initialize source pads */ + mira016->pad.flags = MEDIA_PAD_FL_SOURCE; + + ret = media_entity_pads_init(&mira016->sd.entity, 1, &mira016->pad); + if (ret) { + dev_err_probe(dev, ret, "failed to init entity pads\n"); + goto error_handler_free; + } + + mira016->sd.state_lock = mira016->ctrl_handler.lock; + ret = v4l2_subdev_init_finalize(&mira016->sd); + if (ret < 0) { + dev_err_probe(dev, ret, "subdev init error\n"); + goto error_media_entity; + } + + ret = v4l2_async_register_subdev_sensor(&mira016->sd); + if (ret < 0) { + dev_err_probe(dev, ret, + "failed to register sensor sub-device\n"); + goto error_subdev_cleanup; + } + + pm_runtime_set_autosuspend_delay(dev, 1000); + pm_runtime_use_autosuspend(dev); + pm_runtime_idle(dev); + + return 0; + +error_subdev_cleanup: + v4l2_subdev_cleanup(&mira016->sd); +error_media_entity: + media_entity_cleanup(&mira016->sd.entity); +error_handler_free: + v4l2_ctrl_handler_free(mira016->sd.ctrl_handler); +error_power_off: + pm_runtime_disable(dev); + mira016_power_off(dev); + pm_runtime_set_suspended(dev); + return ret; +} + +static void mira016_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct mira016 *mira016 = to_mira016(sd); + + v4l2_ctrl_handler_free(mira016->sd.ctrl_handler); + + v4l2_async_unregister_subdev(sd); + v4l2_subdev_cleanup(&mira016->sd); + media_entity_cleanup(&sd->entity); + + pm_runtime_disable(mira016->dev); + if (!pm_runtime_status_suspended(mira016->dev)) { + mira016_power_off(mira016->dev); + pm_runtime_set_suspended(mira016->dev); + } + pm_runtime_dont_use_autosuspend(mira016->dev); +} + +static const struct of_device_id mira016_dt_ids[] = { + { .compatible = "ams,mira016" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mira016_dt_ids); + +static struct i2c_driver mira016_i2c_driver = { + .driver = { + .name = "mira016", + .of_match_table = mira016_dt_ids, + .pm = pm_ptr(&mira016_pm_ops), + }, + .probe = mira016_probe, + .remove = mira016_remove, +}; + +module_i2c_driver(mira016_i2c_driver); + +MODULE_AUTHOR("Jacopo Mondi "); +MODULE_DESCRIPTION("ams OSRAM MIRA016 sensor driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/i2c/mira220.c b/drivers/media/i2c/mira220.c index 69dcc969e5d3a4..f5bbba81c1181d 100644 --- a/drivers/media/i2c/mira220.c +++ b/drivers/media/i2c/mira220.c @@ -1,7 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 /* - * A V4L2 driver for ams MIRA220 cameras. - * Copyright (C) 2022, ams-OSRAM + * A V4L2 driver for ams OSRAM MIRA220 cameras. + * + * Mira220 comes in monochrome, RGB and IR-RGB variants. The driver supports + * the mono and RGB variants. + * + * Copyright (C) 2026, ams OSRAM * * Based on Sony IMX219 camera driver * Copyright (C) 2019, Raspberry Pi (Trading) Ltd @@ -10,197 +14,219 @@ #include #include #include -#include #include #include #include + +#include +#include #include #include -#include #include #include -#include -#include -/* Active pixel array is 1600 (H) x 1400 (V) pixels. +/* + * Active pixel array is 1600 (H) x 1400 (V) pixels. * Physical resolution including buffer pixels: 1642 (H) x 1464 (V) pixels. */ -#define MIRA220_NATIVE_WIDTH 1642U -#define MIRA220_NATIVE_HEIGHT 1464U -#define MIRA220_PIXEL_ARRAY_LEFT 21U -#define MIRA220_PIXEL_ARRAY_TOP 32U -#define MIRA220_PIXEL_ARRAY_WIDTH 1600U -#define MIRA220_PIXEL_ARRAY_HEIGHT 1400U +#define MIRA220_NATIVE_WIDTH 1642U +#define MIRA220_NATIVE_HEIGHT 1464U +#define MIRA220_PIXEL_ARRAY_LEFT 21U +#define MIRA220_PIXEL_ARRAY_TOP 32U +#define MIRA220_PIXEL_ARRAY_WIDTH 1600U +#define MIRA220_PIXEL_ARRAY_HEIGHT 1400U /* Mira220 does not support analog gain. */ -#define MIRA220_ANALOG_GAIN_MIN 1 -#define MIRA220_ANALOG_GAIN_MAX 1 -#define MIRA220_ANALOG_GAIN_STEP 1 -#define MIRA220_ANALOG_GAIN_DEFAULT MIRA220_ANALOG_GAIN_MIN +#define MIRA220_ANALOG_GAIN_MIN 1 +#define MIRA220_ANALOG_GAIN_MAX 1 +#define MIRA220_ANALOG_GAIN_STEP 1 +#define MIRA220_ANALOG_GAIN_DEFAULT MIRA220_ANALOG_GAIN_MIN + +/* Bit order */ +#define MIRA220_BIT_ORDER_REG CCI_REG8(0x2063) +#define MIRA220_BIT_ORDER_NORMAL 0x00 +#define MIRA220_BIT_ORDER_REVERSED 0x01 /* Bit depth */ -#define MIRA220_BIT_DEPTH_REG CCI_REG8(0x209E) -#define MIRA220_BIT_DEPTH_12_BIT 0x02 -#define MIRA220_BIT_DEPTH_10_BIT 0x04 -#define MIRA220_BIT_DEPTH_8_BIT 0x06 -#define MIRA220_CSI_DATA_TYPE_REG CCI_REG8(0x208D) -#define MIRA220_CSI_DATA_TYPE_12_BIT 0x04 -#define MIRA220_CSI_DATA_TYPE_10_BIT 0x02 -#define MIRA220_CSI_DATA_TYPE_8_BIT 0x01 +#define MIRA220_BIT_DEPTH_REG CCI_REG8(0x209e) +#define MIRA220_BIT_DEPTH_12_BIT 0x02 +#define MIRA220_BIT_DEPTH_10_BIT 0x04 +#define MIRA220_BIT_DEPTH_8_BIT 0x06 +#define MIRA220_CSI_DATA_TYPE_REG CCI_REG8(0x208d) +#define MIRA220_CSI_DATA_TYPE_12_BIT 0x04 +#define MIRA220_CSI_DATA_TYPE_10_BIT 0x02 +#define MIRA220_CSI_DATA_TYPE_8_BIT 0x01 /* Imager state master/slave registers */ -#define MIRA220_IMAGER_STATE_REG CCI_REG8(0x1003) -#define MIRA220_IMAGER_STATE_STOP_AT_ROW 0x02 -#define MIRA220_IMAGER_STATE_STOP_AT_FRAME 0x04 -#define MIRA220_IMAGER_STATE_MASTER_CONTROL 0x10 -#define MIRA220_IMAGER_STATE_SLAVE_CONTROL 0x08 +#define MIRA220_IMAGER_STATE_REG CCI_REG8(0x1003) +#define MIRA220_IMAGER_STATE_STOP_AT_ROW 0x02 +#define MIRA220_IMAGER_STATE_STOP_AT_FRAME 0x04 +#define MIRA220_IMAGER_STATE_MASTER_CONTROL 0x10 +#define MIRA220_IMAGER_STATE_SLAVE_CONTROL 0x08 /* Start image acquisition */ -#define MIRA220_IMAGER_RUN_REG CCI_REG8(0x10F0) -#define MIRA220_IMAGER_RUN_START 0x01 -#define MIRA220_IMAGER_RUN_STOP 0x00 +#define MIRA220_IMAGER_RUN_REG CCI_REG8(0x10f0) +#define MIRA220_IMAGER_RUN_START 0x01 +#define MIRA220_IMAGER_RUN_STOP 0x00 /* Continuous running, not limited to nr of frames. */ -#define MIRA220_IMAGER_RUN_CONT_REG CCI_REG8(0x1002) -#define MIRA220_IMAGER_RUN_CONT_ENABLE 0x04 -#define MIRA220_IMAGER_RUN_CONT_DISABLE 0x00 +#define MIRA220_IMAGER_RUN_CONT_REG CCI_REG8(0x1002) +#define MIRA220_IMAGER_RUN_CONT_ENABLE 0x04 +#define MIRA220_IMAGER_RUN_CONT_DISABLE 0x00 /* Exposure time is indicated in number of rows */ -#define MIRA220_EXP_TIME_REG CCI_REG16_LE(0x100C) +#define MIRA220_EXP_TIME_REG CCI_REG16_LE(0x100c) /* Vertical Blank */ -#define MIRA220_VBLANK_REG CCI_REG16_LE(0x1012) +#define MIRA220_VBLANK_REG CCI_REG16_LE(0x1012) +#define MIRA220_MIN_VBLANK_MARGIN 11 +#define MIRA220_MAX_VBLANK 0xffff /* Horizontal flip */ -#define MIRA220_HFLIP_REG CCI_REG8(0x209C) -#define MIRA220_HFLIP_ENABLE_MIRROR 1 -#define MIRA220_HFLIP_DISABLE_MIRROR 0 +#define MIRA220_HFLIP_REG CCI_REG8(0x209c) +#define MIRA220_HFLIP_ENABLE_MIRROR 1 +#define MIRA220_HFLIP_DISABLE_MIRROR 0 /* Vertical flip */ -#define MIRA220_VFLIP_REG CCI_REG8(0x1095) -#define MIRA220_VFLIP_ENABLE_FLIP 1 -#define MIRA220_VFLIP_DISABLE_FLIP 0 +#define MIRA220_VFLIP_REG CCI_REG8(0x1095) +#define MIRA220_VFLIP_ENABLE_FLIP 1 +#define MIRA220_VFLIP_DISABLE_FLIP 0 + +#define MIRA220_VSIZE_REG CCI_REG16_LE(0x1087) +#define MIRA220_VSTART_REG CCI_REG16_LE(0x107d) +#define MIRA220_HSIZE_REG CCI_REG16_LE(0x2008) +#define MIRA220_HSIZE_MASK GENMASK(9, 0) +#define MIRA220_HSTART_REG CCI_REG16_LE(0x200a) +#define MIRA220_HSTART_MASK GENMASK(9, 0) +#define MIRA220_MIPI_HSIZE_REG CCI_REG16_LE(0x207d) + +/* MIPI bus control */ +#define MIRA220_MIPI_LANES_REG CCI_REG8(0x6012) + +#define MIRA220_MIPI_CLK_MODE_REG CCI_REG8(0x6013) +#define MIRA220_MIPI_CLK_CONTINUOUS 0x00 +#define MIRA220_MIPI_CLK_NON_CONTINUOUS 0x01 /* OTP control */ -#define MIRA220_OTP_CMD_REG CCI_REG8(0x0080) -#define MIRA220_OTP_CMD_UP 0x4 -#define MIRA220_OTP_CMD_DOWN 0x8 +#define MIRA220_OTP_CMD_REG CCI_REG8(0x0080) +#define MIRA220_OTP_CMD_UP 0x4 +#define MIRA220_OTP_CMD_DOWN 0x8 /* Global sampling time */ -#define MIRA220_GLOB_NUM_CLK_CYCLES 1928 +#define MIRA220_GLOB_NUM_CLK_CYCLES 1928 /* External clock frequency is 38.4 M */ -#define MIRA220_SUPPORTED_XCLK_FREQ 38400000 - -// Default exposure is adjusted to mode with smallest height -#define MIRA220_DEFAULT_EXPOSURE 1000 -#define MIRA220_EXPOSURE_MIN 1 -// Power on function timing -#define MIRA220_XCLR_MIN_DELAY_US 100000 -#define MIRA220_XCLR_DELAY_RANGE_US 30 - -/* Pixel rate is an artificial value - * This value is used for timing calculations - * in combination with vblank/hblank +#define MIRA220_SUPPORTED_XCLK_FREQ 38400000 + +/* Default exposure is adjusted to mode with smallest height */ +#define MIRA220_DEFAULT_EXPOSURE 1000 +#define MIRA220_MAX_EXPOSURE 0xffff +#define MIRA220_EXPOSURE_MIN 1 + +/* + * Pixel rate is an artificial value. This value is used for timing calculations + * in combination with vblank/hblank. */ -#define MIRA220_PIXEL_RATE 384000000 //384M (x10) +#define MIRA220_PIXEL_RATE 384000000 -#define MIRA220_HBLANK_1600x1400_304 1440 +/* Total line length for 2 lanes calculated for ROW_LENGTH = 304. */ +#define MIRA220_LLP_1600x1400_304 3040 + +/* + * ROW_LENGTH: duration of row length in clk_in cycles; set to minimum supported + * value for higher frame rate. + */ +#define MIRA220_REG_ROW_LENGTH CCI_REG16_LE(0x102b) +#define MIRA220_ROW_LENGTH_MIN 304 + +/* MIPI CSI-2 link frequency for 1.5Mbps per lane */ +#define MIRA220_LINK_FREQ_750M 750000000 /* Test Pattern */ -#define MIRA220_REG_TEST_PATTERN CCI_REG8(0x2091) -#define MIRA220_TEST_PATTERN_DISABLE 0x00 +#define MIRA220_REG_TEST_PATTERN CCI_REG8(0x2091) +#define MIRA220_TEST_PATTERN_DISABLE 0x00 #define MIRA220_TEST_PATTERN_VERTICAL_GRADIENT 0x01 -struct mira220_reg { - u16 address; - u8 val; -}; - -struct mira220_reg_list { - unsigned int num_of_regs; - const struct cci_reg_sequence *regs; +/* Module variant identifiers */ +#define MIRA220_MONO_PLAIN_PF 0x1e62a032 +#define MIRA220_MONO_PLAIN_NO_PF 0x1e62a045 +#define MIRA220_MONO_AR_PF 0x1e62a036 +#define MIRA220_RGB_PLAIN_PF 0x1e62a03b +#define MIRA220_RGB_PLAIN_NO_PF 0x1e62a046 +#define MIRA220_RGB_AR_PF 0x1e62a03d + +enum mira220_variants { + MIRA220_VARIANT_MONO, + MIRA220_VARIANT_RGB, }; - -/* Mode : resolution and related config&values */ -struct mira220_mode { - unsigned int width; - unsigned int height; - struct v4l2_rect crop; - struct mira220_reg_list reg_list; - u32 row_length; - u32 pixel_rate; - u32 min_vblank; - u32 max_vblank; - u32 hblank; - u32 code; +static const s64 mira220_link_freqs[] = { + [0] = MIRA220_LINK_FREQ_750M, }; -static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { +static const struct cci_reg_sequence mira220_init_reg_list[] = { /* Base configuration*/ - { CCI_REG8(0x1003), 0x2 }, { CCI_REG8(0x6006), 0x0 }, { CCI_REG8(0x6012), 0x1 }, { CCI_REG8(0x6013), 0x0 }, { CCI_REG8(0x6006), 0x1 }, - { CCI_REG8(0x205D), 0x0 }, + { CCI_REG8(0x205d), 0x0 }, { CCI_REG8(0x2063), 0x0 }, - { CCI_REG8(0x24DC), 0x13 }, - { CCI_REG8(0x24DD), 0x3 }, - { CCI_REG8(0x24DE), 0x3 }, - { CCI_REG8(0x24DF), 0x0 }, + { CCI_REG8(0x24dc), 0x13 }, + { CCI_REG8(0x24dd), 0x3 }, + { CCI_REG8(0x24de), 0x3 }, + { CCI_REG8(0x24df), 0x0 }, { CCI_REG8(0x4006), 0x8 }, - { CCI_REG8(0x401C), 0x6F }, - { CCI_REG8(0x204B), 0x3 }, - { CCI_REG8(0x205B), 0x64 }, - { CCI_REG8(0x205C), 0x0 }, - { CCI_REG8(0x4018), 0x3F }, - { CCI_REG8(0x403B), 0xB }, - { CCI_REG8(0x403E), 0xE }, - { CCI_REG8(0x402B), 0x6 }, - { CCI_REG8(0x401E), 0x2 }, - { CCI_REG8(0x4038), 0x3B }, + { CCI_REG8(0x401c), 0x6f }, + { CCI_REG8(0x204b), 0x3 }, + { CCI_REG8(0x205b), 0x64 }, + { CCI_REG8(0x205c), 0x0 }, + { CCI_REG8(0x4018), 0x3f }, + { CCI_REG8(0x403b), 0xb }, + { CCI_REG8(0x403e), 0xe }, + { CCI_REG8(0x402b), 0x6 }, + { CCI_REG8(0x401e), 0x2 }, + { CCI_REG8(0x4038), 0x3b }, { CCI_REG8(0x1077), 0x0 }, { CCI_REG8(0x1078), 0x0 }, { CCI_REG8(0x1009), 0x8 }, - { CCI_REG8(0x100A), 0x0 }, - { CCI_REG8(0x110F), 0x8 }, + { CCI_REG8(0x100a), 0x0 }, + { CCI_REG8(0x110f), 0x8 }, { CCI_REG8(0x1110), 0x0 }, { CCI_REG8(0x1006), 0x2 }, - { CCI_REG8(0x402C), 0x64 }, + { CCI_REG8(0x402c), 0x64 }, { CCI_REG8(0x3064), 0x0 }, - { CCI_REG8(0x3065), 0xF0 }, + { CCI_REG8(0x3065), 0xf0 }, { CCI_REG8(0x4013), 0x13 }, - { CCI_REG8(0x401F), 0x9 }, + { CCI_REG8(0x401f), 0x9 }, { CCI_REG8(0x4020), 0x13 }, { CCI_REG8(0x4044), 0x75 }, { CCI_REG8(0x4027), 0x0 }, { CCI_REG8(0x3215), 0x69 }, - { CCI_REG8(0x3216), 0xF }, - { CCI_REG8(0x322B), 0x69 }, - { CCI_REG8(0x322C), 0xF }, + { CCI_REG8(0x3216), 0xf }, + { CCI_REG8(0x322b), 0x69 }, + { CCI_REG8(0x322c), 0xf }, { CCI_REG8(0x4051), 0x80 }, { CCI_REG8(0x4052), 0x10 }, { CCI_REG8(0x4057), 0x80 }, { CCI_REG8(0x4058), 0x10 }, { CCI_REG8(0x3212), 0x59 }, - { CCI_REG8(0x4047), 0x8F }, + { CCI_REG8(0x4047), 0x8f }, { CCI_REG8(0x4026), 0x10 }, { CCI_REG8(0x4032), 0x53 }, { CCI_REG8(0x4036), 0x17 }, - { CCI_REG8(0x50B8), 0xF4 }, + { CCI_REG8(0x50b8), 0xf4 }, { CCI_REG8(0x3016), 0x0 }, - { CCI_REG8(0x3017), 0x2C }, - { CCI_REG8(0x3018), 0x8C }, + { CCI_REG8(0x3017), 0x2c }, + { CCI_REG8(0x3018), 0x8c }, { CCI_REG8(0x3019), 0x45 }, - { CCI_REG8(0x301A), 0x5 }, - { CCI_REG8(0x3013), 0xA }, - { CCI_REG8(0x301B), 0x0 }, - { CCI_REG8(0x301C), 0x4 }, - { CCI_REG8(0x301D), 0x88 }, - { CCI_REG8(0x301E), 0x45 }, - { CCI_REG8(0x301F), 0x5 }, + { CCI_REG8(0x301a), 0x5 }, + { CCI_REG8(0x3013), 0xa }, + { CCI_REG8(0x301b), 0x0 }, + { CCI_REG8(0x301c), 0x4 }, + { CCI_REG8(0x301d), 0x88 }, + { CCI_REG8(0x301e), 0x45 }, + { CCI_REG8(0x301f), 0x5 }, { CCI_REG8(0x3020), 0x0 }, { CCI_REG8(0x3021), 0x4 }, { CCI_REG8(0x3022), 0x88 }, @@ -211,77 +237,77 @@ static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { CCI_REG8(0x3027), 0x88 }, { CCI_REG8(0x3028), 0x45 }, { CCI_REG8(0x3029), 0x5 }, - { CCI_REG8(0x302F), 0x0 }, + { CCI_REG8(0x302f), 0x0 }, { CCI_REG8(0x3056), 0x0 }, { CCI_REG8(0x3057), 0x0 }, { CCI_REG8(0x3300), 0x1 }, { CCI_REG8(0x3301), 0x0 }, - { CCI_REG8(0x3302), 0xB0 }, - { CCI_REG8(0x3303), 0xB0 }, + { CCI_REG8(0x3302), 0xb0 }, + { CCI_REG8(0x3303), 0xb0 }, { CCI_REG8(0x3304), 0x16 }, { CCI_REG8(0x3305), 0x15 }, { CCI_REG8(0x3306), 0x1 }, { CCI_REG8(0x3307), 0x0 }, { CCI_REG8(0x3308), 0x30 }, - { CCI_REG8(0x3309), 0xA0 }, - { CCI_REG8(0x330A), 0x16 }, - { CCI_REG8(0x330B), 0x15 }, - { CCI_REG8(0x330C), 0x1 }, - { CCI_REG8(0x330D), 0x0 }, - { CCI_REG8(0x330E), 0x30 }, - { CCI_REG8(0x330F), 0xA0 }, + { CCI_REG8(0x3309), 0xa0 }, + { CCI_REG8(0x330a), 0x16 }, + { CCI_REG8(0x330b), 0x15 }, + { CCI_REG8(0x330c), 0x1 }, + { CCI_REG8(0x330d), 0x0 }, + { CCI_REG8(0x330e), 0x30 }, + { CCI_REG8(0x330f), 0xa0 }, { CCI_REG8(0x3310), 0x16 }, { CCI_REG8(0x3311), 0x15 }, { CCI_REG8(0x3312), 0x1 }, { CCI_REG8(0x3313), 0x0 }, { CCI_REG8(0x3314), 0x30 }, - { CCI_REG8(0x3315), 0xA0 }, + { CCI_REG8(0x3315), 0xa0 }, { CCI_REG8(0x3316), 0x16 }, { CCI_REG8(0x3317), 0x15 }, { CCI_REG8(0x3318), 0x1 }, { CCI_REG8(0x3319), 0x0 }, - { CCI_REG8(0x331A), 0x30 }, - { CCI_REG8(0x331B), 0xA0 }, - { CCI_REG8(0x331C), 0x16 }, - { CCI_REG8(0x331D), 0x15 }, - { CCI_REG8(0x331E), 0x1 }, - { CCI_REG8(0x331F), 0x0 }, + { CCI_REG8(0x331a), 0x30 }, + { CCI_REG8(0x331b), 0xa0 }, + { CCI_REG8(0x331c), 0x16 }, + { CCI_REG8(0x331d), 0x15 }, + { CCI_REG8(0x331e), 0x1 }, + { CCI_REG8(0x331f), 0x0 }, { CCI_REG8(0x3320), 0x30 }, - { CCI_REG8(0x3321), 0xA0 }, + { CCI_REG8(0x3321), 0xa0 }, { CCI_REG8(0x3322), 0x16 }, { CCI_REG8(0x3323), 0x15 }, { CCI_REG8(0x3324), 0x1 }, { CCI_REG8(0x3325), 0x0 }, { CCI_REG8(0x3326), 0x30 }, - { CCI_REG8(0x3327), 0xA0 }, + { CCI_REG8(0x3327), 0xa0 }, { CCI_REG8(0x3328), 0x16 }, { CCI_REG8(0x3329), 0x15 }, - { CCI_REG8(0x332A), 0x2B }, - { CCI_REG8(0x332B), 0x0 }, - { CCI_REG8(0x332C), 0x30 }, - { CCI_REG8(0x332D), 0xA0 }, - { CCI_REG8(0x332E), 0x16 }, - { CCI_REG8(0x332F), 0x15 }, + { CCI_REG8(0x332a), 0x2b }, + { CCI_REG8(0x332b), 0x0 }, + { CCI_REG8(0x332c), 0x30 }, + { CCI_REG8(0x332d), 0xa0 }, + { CCI_REG8(0x332e), 0x16 }, + { CCI_REG8(0x332f), 0x15 }, { CCI_REG8(0x3330), 0x1 }, { CCI_REG8(0x3331), 0x0 }, { CCI_REG8(0x3332), 0x10 }, - { CCI_REG8(0x3333), 0xA0 }, + { CCI_REG8(0x3333), 0xa0 }, { CCI_REG8(0x3334), 0x16 }, { CCI_REG8(0x3335), 0x15 }, { CCI_REG8(0x3058), 0x8 }, { CCI_REG8(0x3059), 0x0 }, - { CCI_REG8(0x305A), 0x9 }, - { CCI_REG8(0x305B), 0x0 }, + { CCI_REG8(0x305a), 0x9 }, + { CCI_REG8(0x305b), 0x0 }, { CCI_REG8(0x3336), 0x1 }, { CCI_REG8(0x3337), 0x0 }, { CCI_REG8(0x3338), 0x90 }, - { CCI_REG8(0x3339), 0xB0 }, - { CCI_REG8(0x333A), 0x16 }, - { CCI_REG8(0x333B), 0x15 }, - { CCI_REG8(0x333C), 0x1F }, - { CCI_REG8(0x333D), 0x0 }, - { CCI_REG8(0x333E), 0x10 }, - { CCI_REG8(0x333F), 0xA0 }, + { CCI_REG8(0x3339), 0xb0 }, + { CCI_REG8(0x333a), 0x16 }, + { CCI_REG8(0x333b), 0x15 }, + { CCI_REG8(0x333c), 0x1f }, + { CCI_REG8(0x333d), 0x0 }, + { CCI_REG8(0x333e), 0x10 }, + { CCI_REG8(0x333f), 0xa0 }, { CCI_REG8(0x3340), 0x16 }, { CCI_REG8(0x3341), 0x15 }, { CCI_REG8(0x3342), 0x52 }, @@ -292,44 +318,44 @@ static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { CCI_REG8(0x3347), 0x15 }, { CCI_REG8(0x3348), 0x1 }, { CCI_REG8(0x3349), 0x0 }, - { CCI_REG8(0x334A), 0x10 }, - { CCI_REG8(0x334B), 0x80 }, - { CCI_REG8(0x334C), 0x16 }, - { CCI_REG8(0x334D), 0x1D }, - { CCI_REG8(0x334E), 0x1 }, - { CCI_REG8(0x334F), 0x0 }, + { CCI_REG8(0x334a), 0x10 }, + { CCI_REG8(0x334b), 0x80 }, + { CCI_REG8(0x334c), 0x16 }, + { CCI_REG8(0x334d), 0x1d }, + { CCI_REG8(0x334e), 0x1 }, + { CCI_REG8(0x334f), 0x0 }, { CCI_REG8(0x3350), 0x50 }, { CCI_REG8(0x3351), 0x84 }, { CCI_REG8(0x3352), 0x16 }, - { CCI_REG8(0x3353), 0x1D }, + { CCI_REG8(0x3353), 0x1d }, { CCI_REG8(0x3354), 0x18 }, { CCI_REG8(0x3355), 0x0 }, { CCI_REG8(0x3356), 0x10 }, { CCI_REG8(0x3357), 0x84 }, { CCI_REG8(0x3358), 0x16 }, - { CCI_REG8(0x3359), 0x1D }, - { CCI_REG8(0x335A), 0x80 }, - { CCI_REG8(0x335B), 0x2 }, - { CCI_REG8(0x335C), 0x10 }, - { CCI_REG8(0x335D), 0xC4 }, - { CCI_REG8(0x335E), 0x14 }, - { CCI_REG8(0x335F), 0x1D }, - { CCI_REG8(0x3360), 0xA5 }, + { CCI_REG8(0x3359), 0x1d }, + { CCI_REG8(0x335a), 0x80 }, + { CCI_REG8(0x335b), 0x2 }, + { CCI_REG8(0x335c), 0x10 }, + { CCI_REG8(0x335d), 0xc4 }, + { CCI_REG8(0x335e), 0x14 }, + { CCI_REG8(0x335f), 0x1d }, + { CCI_REG8(0x3360), 0xa5 }, { CCI_REG8(0x3361), 0x0 }, { CCI_REG8(0x3362), 0x10 }, { CCI_REG8(0x3363), 0x84 }, { CCI_REG8(0x3364), 0x16 }, - { CCI_REG8(0x3365), 0x1D }, + { CCI_REG8(0x3365), 0x1d }, { CCI_REG8(0x3366), 0x1 }, { CCI_REG8(0x3367), 0x0 }, { CCI_REG8(0x3368), 0x90 }, { CCI_REG8(0x3369), 0x84 }, - { CCI_REG8(0x336A), 0x16 }, - { CCI_REG8(0x336B), 0x1D }, - { CCI_REG8(0x336C), 0x12 }, - { CCI_REG8(0x336D), 0x0 }, - { CCI_REG8(0x336E), 0x10 }, - { CCI_REG8(0x336F), 0x84 }, + { CCI_REG8(0x336a), 0x16 }, + { CCI_REG8(0x336b), 0x1d }, + { CCI_REG8(0x336c), 0x12 }, + { CCI_REG8(0x336d), 0x0 }, + { CCI_REG8(0x336e), 0x10 }, + { CCI_REG8(0x336f), 0x84 }, { CCI_REG8(0x3370), 0x16 }, { CCI_REG8(0x3371), 0x15 }, { CCI_REG8(0x3372), 0x32 }, @@ -340,239 +366,239 @@ static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { CCI_REG8(0x3377), 0x15 }, { CCI_REG8(0x3378), 0x26 }, { CCI_REG8(0x3379), 0x0 }, - { CCI_REG8(0x337A), 0x10 }, - { CCI_REG8(0x337B), 0x84 }, - { CCI_REG8(0x337C), 0x16 }, - { CCI_REG8(0x337D), 0x15 }, - { CCI_REG8(0x337E), 0x80 }, - { CCI_REG8(0x337F), 0x2 }, + { CCI_REG8(0x337a), 0x10 }, + { CCI_REG8(0x337b), 0x84 }, + { CCI_REG8(0x337c), 0x16 }, + { CCI_REG8(0x337d), 0x15 }, + { CCI_REG8(0x337e), 0x80 }, + { CCI_REG8(0x337f), 0x2 }, { CCI_REG8(0x3380), 0x10 }, - { CCI_REG8(0x3381), 0xC4 }, + { CCI_REG8(0x3381), 0xc4 }, { CCI_REG8(0x3382), 0x14 }, { CCI_REG8(0x3383), 0x15 }, - { CCI_REG8(0x3384), 0xA9 }, + { CCI_REG8(0x3384), 0xa9 }, { CCI_REG8(0x3385), 0x0 }, { CCI_REG8(0x3386), 0x10 }, { CCI_REG8(0x3387), 0x84 }, { CCI_REG8(0x3388), 0x16 }, { CCI_REG8(0x3389), 0x15 }, - { CCI_REG8(0x338A), 0x41 }, - { CCI_REG8(0x338B), 0x0 }, - { CCI_REG8(0x338C), 0x10 }, - { CCI_REG8(0x338D), 0x80 }, - { CCI_REG8(0x338E), 0x16 }, - { CCI_REG8(0x338F), 0x15 }, + { CCI_REG8(0x338a), 0x41 }, + { CCI_REG8(0x338b), 0x0 }, + { CCI_REG8(0x338c), 0x10 }, + { CCI_REG8(0x338d), 0x80 }, + { CCI_REG8(0x338e), 0x16 }, + { CCI_REG8(0x338f), 0x15 }, { CCI_REG8(0x3390), 0x2 }, { CCI_REG8(0x3391), 0x0 }, { CCI_REG8(0x3392), 0x10 }, - { CCI_REG8(0x3393), 0xA0 }, + { CCI_REG8(0x3393), 0xa0 }, { CCI_REG8(0x3394), 0x16 }, { CCI_REG8(0x3395), 0x15 }, - { CCI_REG8(0x305C), 0x18 }, - { CCI_REG8(0x305D), 0x0 }, - { CCI_REG8(0x305E), 0x19 }, - { CCI_REG8(0x305F), 0x0 }, + { CCI_REG8(0x305c), 0x18 }, + { CCI_REG8(0x305d), 0x0 }, + { CCI_REG8(0x305e), 0x19 }, + { CCI_REG8(0x305f), 0x0 }, { CCI_REG8(0x3396), 0x1 }, { CCI_REG8(0x3397), 0x0 }, { CCI_REG8(0x3398), 0x90 }, { CCI_REG8(0x3399), 0x30 }, - { CCI_REG8(0x339A), 0x56 }, - { CCI_REG8(0x339B), 0x57 }, - { CCI_REG8(0x339C), 0x1 }, - { CCI_REG8(0x339D), 0x0 }, - { CCI_REG8(0x339E), 0x10 }, - { CCI_REG8(0x339F), 0x20 }, - { CCI_REG8(0x33A0), 0xD6 }, - { CCI_REG8(0x33A1), 0x17 }, - { CCI_REG8(0x33A2), 0x1 }, - { CCI_REG8(0x33A3), 0x0 }, - { CCI_REG8(0x33A4), 0x10 }, - { CCI_REG8(0x33A5), 0x28 }, - { CCI_REG8(0x33A6), 0xD6 }, - { CCI_REG8(0x33A7), 0x17 }, - { CCI_REG8(0x33A8), 0x3 }, - { CCI_REG8(0x33A9), 0x0 }, - { CCI_REG8(0x33AA), 0x10 }, - { CCI_REG8(0x33AB), 0x20 }, - { CCI_REG8(0x33AC), 0xD6 }, - { CCI_REG8(0x33AD), 0x17 }, - { CCI_REG8(0x33AE), 0x61 }, - { CCI_REG8(0x33AF), 0x0 }, - { CCI_REG8(0x33B0), 0x10 }, - { CCI_REG8(0x33B1), 0x20 }, - { CCI_REG8(0x33B2), 0xD6 }, - { CCI_REG8(0x33B3), 0x15 }, - { CCI_REG8(0x33B4), 0x1 }, - { CCI_REG8(0x33B5), 0x0 }, - { CCI_REG8(0x33B6), 0x10 }, - { CCI_REG8(0x33B7), 0x20 }, - { CCI_REG8(0x33B8), 0xD6 }, - { CCI_REG8(0x33B9), 0x1D }, - { CCI_REG8(0x33BA), 0x1 }, - { CCI_REG8(0x33BB), 0x0 }, - { CCI_REG8(0x33BC), 0x50 }, - { CCI_REG8(0x33BD), 0x20 }, - { CCI_REG8(0x33BE), 0xD6 }, - { CCI_REG8(0x33BF), 0x1D }, - { CCI_REG8(0x33C0), 0x2C }, - { CCI_REG8(0x33C1), 0x0 }, - { CCI_REG8(0x33C2), 0x10 }, - { CCI_REG8(0x33C3), 0x20 }, - { CCI_REG8(0x33C4), 0xD6 }, - { CCI_REG8(0x33C5), 0x1D }, - { CCI_REG8(0x33C6), 0x1 }, - { CCI_REG8(0x33C7), 0x0 }, - { CCI_REG8(0x33C8), 0x90 }, - { CCI_REG8(0x33C9), 0x20 }, - { CCI_REG8(0x33CA), 0xD6 }, - { CCI_REG8(0x33CB), 0x1D }, - { CCI_REG8(0x33CC), 0x83 }, - { CCI_REG8(0x33CD), 0x0 }, - { CCI_REG8(0x33CE), 0x10 }, - { CCI_REG8(0x33CF), 0x20 }, - { CCI_REG8(0x33D0), 0xD6 }, - { CCI_REG8(0x33D1), 0x15 }, - { CCI_REG8(0x33D2), 0x1 }, - { CCI_REG8(0x33D3), 0x0 }, - { CCI_REG8(0x33D4), 0x10 }, - { CCI_REG8(0x33D5), 0x30 }, - { CCI_REG8(0x33D6), 0xD6 }, - { CCI_REG8(0x33D7), 0x15 }, - { CCI_REG8(0x33D8), 0x1 }, - { CCI_REG8(0x33D9), 0x0 }, - { CCI_REG8(0x33DA), 0x10 }, - { CCI_REG8(0x33DB), 0x20 }, - { CCI_REG8(0x33DC), 0xD6 }, - { CCI_REG8(0x33DD), 0x15 }, - { CCI_REG8(0x33DE), 0x1 }, - { CCI_REG8(0x33DF), 0x0 }, - { CCI_REG8(0x33E0), 0x10 }, - { CCI_REG8(0x33E1), 0x20 }, - { CCI_REG8(0x33E2), 0x56 }, - { CCI_REG8(0x33E3), 0x15 }, - { CCI_REG8(0x33E4), 0x7 }, - { CCI_REG8(0x33E5), 0x0 }, - { CCI_REG8(0x33E6), 0x10 }, - { CCI_REG8(0x33E7), 0x20 }, - { CCI_REG8(0x33E8), 0x16 }, - { CCI_REG8(0x33E9), 0x15 }, + { CCI_REG8(0x339a), 0x56 }, + { CCI_REG8(0x339b), 0x57 }, + { CCI_REG8(0x339c), 0x1 }, + { CCI_REG8(0x339d), 0x0 }, + { CCI_REG8(0x339e), 0x10 }, + { CCI_REG8(0x339f), 0x20 }, + { CCI_REG8(0x33a0), 0xd6 }, + { CCI_REG8(0x33a1), 0x17 }, + { CCI_REG8(0x33a2), 0x1 }, + { CCI_REG8(0x33a3), 0x0 }, + { CCI_REG8(0x33a4), 0x10 }, + { CCI_REG8(0x33a5), 0x28 }, + { CCI_REG8(0x33a6), 0xd6 }, + { CCI_REG8(0x33a7), 0x17 }, + { CCI_REG8(0x33a8), 0x3 }, + { CCI_REG8(0x33a9), 0x0 }, + { CCI_REG8(0x33aa), 0x10 }, + { CCI_REG8(0x33ab), 0x20 }, + { CCI_REG8(0x33ac), 0xd6 }, + { CCI_REG8(0x33ad), 0x17 }, + { CCI_REG8(0x33ae), 0x61 }, + { CCI_REG8(0x33af), 0x0 }, + { CCI_REG8(0x33b0), 0x10 }, + { CCI_REG8(0x33b1), 0x20 }, + { CCI_REG8(0x33b2), 0xd6 }, + { CCI_REG8(0x33b3), 0x15 }, + { CCI_REG8(0x33b4), 0x1 }, + { CCI_REG8(0x33b5), 0x0 }, + { CCI_REG8(0x33b6), 0x10 }, + { CCI_REG8(0x33b7), 0x20 }, + { CCI_REG8(0x33b8), 0xd6 }, + { CCI_REG8(0x33b9), 0x1d }, + { CCI_REG8(0x33ba), 0x1 }, + { CCI_REG8(0x33bb), 0x0 }, + { CCI_REG8(0x33bc), 0x50 }, + { CCI_REG8(0x33bd), 0x20 }, + { CCI_REG8(0x33be), 0xd6 }, + { CCI_REG8(0x33bf), 0x1d }, + { CCI_REG8(0x33c0), 0x2c }, + { CCI_REG8(0x33c1), 0x0 }, + { CCI_REG8(0x33c2), 0x10 }, + { CCI_REG8(0x33c3), 0x20 }, + { CCI_REG8(0x33c4), 0xd6 }, + { CCI_REG8(0x33c5), 0x1d }, + { CCI_REG8(0x33c6), 0x1 }, + { CCI_REG8(0x33c7), 0x0 }, + { CCI_REG8(0x33c8), 0x90 }, + { CCI_REG8(0x33c9), 0x20 }, + { CCI_REG8(0x33ca), 0xd6 }, + { CCI_REG8(0x33cb), 0x1d }, + { CCI_REG8(0x33cc), 0x83 }, + { CCI_REG8(0x33cd), 0x0 }, + { CCI_REG8(0x33ce), 0x10 }, + { CCI_REG8(0x33cf), 0x20 }, + { CCI_REG8(0x33d0), 0xd6 }, + { CCI_REG8(0x33d1), 0x15 }, + { CCI_REG8(0x33d2), 0x1 }, + { CCI_REG8(0x33d3), 0x0 }, + { CCI_REG8(0x33d4), 0x10 }, + { CCI_REG8(0x33d5), 0x30 }, + { CCI_REG8(0x33d6), 0xd6 }, + { CCI_REG8(0x33d7), 0x15 }, + { CCI_REG8(0x33d8), 0x1 }, + { CCI_REG8(0x33d9), 0x0 }, + { CCI_REG8(0x33da), 0x10 }, + { CCI_REG8(0x33db), 0x20 }, + { CCI_REG8(0x33dc), 0xd6 }, + { CCI_REG8(0x33dd), 0x15 }, + { CCI_REG8(0x33de), 0x1 }, + { CCI_REG8(0x33df), 0x0 }, + { CCI_REG8(0x33e0), 0x10 }, + { CCI_REG8(0x33e1), 0x20 }, + { CCI_REG8(0x33e2), 0x56 }, + { CCI_REG8(0x33e3), 0x15 }, + { CCI_REG8(0x33e4), 0x7 }, + { CCI_REG8(0x33e5), 0x0 }, + { CCI_REG8(0x33e6), 0x10 }, + { CCI_REG8(0x33e7), 0x20 }, + { CCI_REG8(0x33e8), 0x16 }, + { CCI_REG8(0x33e9), 0x15 }, { CCI_REG8(0x3060), 0x26 }, { CCI_REG8(0x3061), 0x0 }, - { CCI_REG8(0x302A), 0xFF }, - { CCI_REG8(0x302B), 0xFF }, - { CCI_REG8(0x302C), 0xFF }, - { CCI_REG8(0x302D), 0xFF }, - { CCI_REG8(0x302E), 0x3F }, - { CCI_REG8(0x3013), 0xB }, - { CCI_REG8(0x102B), 0x2C }, - { CCI_REG8(0x102C), 0x1 }, + { CCI_REG8(0x302a), 0xff }, + { CCI_REG8(0x302b), 0xff }, + { CCI_REG8(0x302c), 0xff }, + { CCI_REG8(0x302d), 0xff }, + { CCI_REG8(0x302e), 0x3f }, + { CCI_REG8(0x3013), 0xb }, + { CCI_REG8(0x102b), 0x2c }, + { CCI_REG8(0x102c), 0x1 }, { CCI_REG8(0x1035), 0x54 }, { CCI_REG8(0x1036), 0x0 }, - { CCI_REG8(0x3090), 0x2A }, + { CCI_REG8(0x3090), 0x2a }, { CCI_REG8(0x3091), 0x1 }, - { CCI_REG8(0x30C6), 0x5 }, - { CCI_REG8(0x30C7), 0x0 }, - { CCI_REG8(0x30C8), 0x0 }, - { CCI_REG8(0x30C9), 0x0 }, - { CCI_REG8(0x30CA), 0x0 }, - { CCI_REG8(0x30CB), 0x0 }, - { CCI_REG8(0x30CC), 0x0 }, - { CCI_REG8(0x30CD), 0x0 }, - { CCI_REG8(0x30CE), 0x0 }, - { CCI_REG8(0x30CF), 0x5 }, - { CCI_REG8(0x30D0), 0x0 }, - { CCI_REG8(0x30D1), 0x0 }, - { CCI_REG8(0x30D2), 0x0 }, - { CCI_REG8(0x30D3), 0x0 }, - { CCI_REG8(0x30D4), 0x0 }, - { CCI_REG8(0x30D5), 0x0 }, - { CCI_REG8(0x30D6), 0x0 }, - { CCI_REG8(0x30D7), 0x0 }, - { CCI_REG8(0x30F3), 0x5 }, - { CCI_REG8(0x30F4), 0x0 }, - { CCI_REG8(0x30F5), 0x0 }, - { CCI_REG8(0x30F6), 0x0 }, - { CCI_REG8(0x30F7), 0x0 }, - { CCI_REG8(0x30F8), 0x0 }, - { CCI_REG8(0x30F9), 0x0 }, - { CCI_REG8(0x30FA), 0x0 }, - { CCI_REG8(0x30FB), 0x0 }, - { CCI_REG8(0x30D8), 0x5 }, - { CCI_REG8(0x30D9), 0x0 }, - { CCI_REG8(0x30DA), 0x0 }, - { CCI_REG8(0x30DB), 0x0 }, - { CCI_REG8(0x30DC), 0x0 }, - { CCI_REG8(0x30DD), 0x0 }, - { CCI_REG8(0x30DE), 0x0 }, - { CCI_REG8(0x30DF), 0x0 }, - { CCI_REG8(0x30E0), 0x0 }, - { CCI_REG8(0x30E1), 0x5 }, - { CCI_REG8(0x30E2), 0x0 }, - { CCI_REG8(0x30E3), 0x0 }, - { CCI_REG8(0x30E4), 0x0 }, - { CCI_REG8(0x30E5), 0x0 }, - { CCI_REG8(0x30E6), 0x0 }, - { CCI_REG8(0x30E7), 0x0 }, - { CCI_REG8(0x30E8), 0x0 }, - { CCI_REG8(0x30E9), 0x0 }, - { CCI_REG8(0x30F3), 0x5 }, - { CCI_REG8(0x30F4), 0x2 }, - { CCI_REG8(0x30F5), 0x0 }, - { CCI_REG8(0x30F6), 0x17 }, - { CCI_REG8(0x30F7), 0x1 }, - { CCI_REG8(0x30F8), 0x0 }, - { CCI_REG8(0x30F9), 0x0 }, - { CCI_REG8(0x30FA), 0x0 }, - { CCI_REG8(0x30FB), 0x0 }, - { CCI_REG8(0x30D8), 0x3 }, - { CCI_REG8(0x30D9), 0x1 }, - { CCI_REG8(0x30DA), 0x0 }, - { CCI_REG8(0x30DB), 0x19 }, - { CCI_REG8(0x30DC), 0x1 }, - { CCI_REG8(0x30DD), 0x0 }, - { CCI_REG8(0x30DE), 0x0 }, - { CCI_REG8(0x30DF), 0x0 }, - { CCI_REG8(0x30E0), 0x0 }, - { CCI_REG8(0x30A2), 0x5 }, - { CCI_REG8(0x30A3), 0x2 }, - { CCI_REG8(0x30A4), 0x0 }, - { CCI_REG8(0x30A5), 0x22 }, - { CCI_REG8(0x30A6), 0x0 }, - { CCI_REG8(0x30A7), 0x0 }, - { CCI_REG8(0x30A8), 0x0 }, - { CCI_REG8(0x30A9), 0x0 }, - { CCI_REG8(0x30AA), 0x0 }, - { CCI_REG8(0x30AB), 0x5 }, - { CCI_REG8(0x30AC), 0x2 }, - { CCI_REG8(0x30AD), 0x0 }, - { CCI_REG8(0x30AE), 0x22 }, - { CCI_REG8(0x30AF), 0x0 }, - { CCI_REG8(0x30B0), 0x0 }, - { CCI_REG8(0x30B1), 0x0 }, - { CCI_REG8(0x30B2), 0x0 }, - { CCI_REG8(0x30B3), 0x0 }, - { CCI_REG8(0x30BD), 0x5 }, - { CCI_REG8(0x30BE), 0x9F }, - { CCI_REG8(0x30BF), 0x0 }, - { CCI_REG8(0x30C0), 0x7D }, - { CCI_REG8(0x30C1), 0x0 }, - { CCI_REG8(0x30C2), 0x0 }, - { CCI_REG8(0x30C3), 0x0 }, - { CCI_REG8(0x30C4), 0x0 }, - { CCI_REG8(0x30C5), 0x0 }, - { CCI_REG8(0x30B4), 0x4 }, - { CCI_REG8(0x30B5), 0x9C }, - { CCI_REG8(0x30B6), 0x0 }, - { CCI_REG8(0x30B7), 0x7D }, - { CCI_REG8(0x30B8), 0x0 }, - { CCI_REG8(0x30B9), 0x0 }, - { CCI_REG8(0x30BA), 0x0 }, - { CCI_REG8(0x30BB), 0x0 }, - { CCI_REG8(0x30BC), 0x0 }, - { CCI_REG8(0x30FC), 0x5 }, - { CCI_REG8(0x30FD), 0x0 }, - { CCI_REG8(0x30FE), 0x0 }, - { CCI_REG8(0x30FF), 0x0 }, + { CCI_REG8(0x30c6), 0x5 }, + { CCI_REG8(0x30c7), 0x0 }, + { CCI_REG8(0x30c8), 0x0 }, + { CCI_REG8(0x30c9), 0x0 }, + { CCI_REG8(0x30ca), 0x0 }, + { CCI_REG8(0x30cb), 0x0 }, + { CCI_REG8(0x30cc), 0x0 }, + { CCI_REG8(0x30cd), 0x0 }, + { CCI_REG8(0x30ce), 0x0 }, + { CCI_REG8(0x30cf), 0x5 }, + { CCI_REG8(0x30d0), 0x0 }, + { CCI_REG8(0x30d1), 0x0 }, + { CCI_REG8(0x30d2), 0x0 }, + { CCI_REG8(0x30d3), 0x0 }, + { CCI_REG8(0x30d4), 0x0 }, + { CCI_REG8(0x30d5), 0x0 }, + { CCI_REG8(0x30d6), 0x0 }, + { CCI_REG8(0x30d7), 0x0 }, + { CCI_REG8(0x30f3), 0x5 }, + { CCI_REG8(0x30f4), 0x0 }, + { CCI_REG8(0x30f5), 0x0 }, + { CCI_REG8(0x30f6), 0x0 }, + { CCI_REG8(0x30f7), 0x0 }, + { CCI_REG8(0x30f8), 0x0 }, + { CCI_REG8(0x30f9), 0x0 }, + { CCI_REG8(0x30fa), 0x0 }, + { CCI_REG8(0x30fb), 0x0 }, + { CCI_REG8(0x30d8), 0x5 }, + { CCI_REG8(0x30d9), 0x0 }, + { CCI_REG8(0x30da), 0x0 }, + { CCI_REG8(0x30db), 0x0 }, + { CCI_REG8(0x30dc), 0x0 }, + { CCI_REG8(0x30dd), 0x0 }, + { CCI_REG8(0x30de), 0x0 }, + { CCI_REG8(0x30df), 0x0 }, + { CCI_REG8(0x30e0), 0x0 }, + { CCI_REG8(0x30e1), 0x5 }, + { CCI_REG8(0x30e2), 0x0 }, + { CCI_REG8(0x30e3), 0x0 }, + { CCI_REG8(0x30e4), 0x0 }, + { CCI_REG8(0x30e5), 0x0 }, + { CCI_REG8(0x30e6), 0x0 }, + { CCI_REG8(0x30e7), 0x0 }, + { CCI_REG8(0x30e8), 0x0 }, + { CCI_REG8(0x30e9), 0x0 }, + { CCI_REG8(0x30f3), 0x5 }, + { CCI_REG8(0x30f4), 0x2 }, + { CCI_REG8(0x30f5), 0x0 }, + { CCI_REG8(0x30f6), 0x17 }, + { CCI_REG8(0x30f7), 0x1 }, + { CCI_REG8(0x30f8), 0x0 }, + { CCI_REG8(0x30f9), 0x0 }, + { CCI_REG8(0x30fa), 0x0 }, + { CCI_REG8(0x30fb), 0x0 }, + { CCI_REG8(0x30d8), 0x3 }, + { CCI_REG8(0x30d9), 0x1 }, + { CCI_REG8(0x30da), 0x0 }, + { CCI_REG8(0x30db), 0x19 }, + { CCI_REG8(0x30dc), 0x1 }, + { CCI_REG8(0x30dd), 0x0 }, + { CCI_REG8(0x30de), 0x0 }, + { CCI_REG8(0x30df), 0x0 }, + { CCI_REG8(0x30e0), 0x0 }, + { CCI_REG8(0x30a2), 0x5 }, + { CCI_REG8(0x30a3), 0x2 }, + { CCI_REG8(0x30a4), 0x0 }, + { CCI_REG8(0x30a5), 0x22 }, + { CCI_REG8(0x30a6), 0x0 }, + { CCI_REG8(0x30a7), 0x0 }, + { CCI_REG8(0x30a8), 0x0 }, + { CCI_REG8(0x30a9), 0x0 }, + { CCI_REG8(0x30aa), 0x0 }, + { CCI_REG8(0x30ab), 0x5 }, + { CCI_REG8(0x30ac), 0x2 }, + { CCI_REG8(0x30ad), 0x0 }, + { CCI_REG8(0x30ae), 0x22 }, + { CCI_REG8(0x30af), 0x0 }, + { CCI_REG8(0x30b0), 0x0 }, + { CCI_REG8(0x30b1), 0x0 }, + { CCI_REG8(0x30b2), 0x0 }, + { CCI_REG8(0x30b3), 0x0 }, + { CCI_REG8(0x30bd), 0x5 }, + { CCI_REG8(0x30be), 0x9f }, + { CCI_REG8(0x30bf), 0x0 }, + { CCI_REG8(0x30c0), 0x7d }, + { CCI_REG8(0x30c1), 0x0 }, + { CCI_REG8(0x30c2), 0x0 }, + { CCI_REG8(0x30c3), 0x0 }, + { CCI_REG8(0x30c4), 0x0 }, + { CCI_REG8(0x30c5), 0x0 }, + { CCI_REG8(0x30b4), 0x4 }, + { CCI_REG8(0x30b5), 0x9c }, + { CCI_REG8(0x30b6), 0x0 }, + { CCI_REG8(0x30b7), 0x7d }, + { CCI_REG8(0x30b8), 0x0 }, + { CCI_REG8(0x30b9), 0x0 }, + { CCI_REG8(0x30ba), 0x0 }, + { CCI_REG8(0x30bb), 0x0 }, + { CCI_REG8(0x30bc), 0x0 }, + { CCI_REG8(0x30fc), 0x5 }, + { CCI_REG8(0x30fd), 0x0 }, + { CCI_REG8(0x30fe), 0x0 }, + { CCI_REG8(0x30ff), 0x0 }, { CCI_REG8(0x3100), 0x0 }, { CCI_REG8(0x3101), 0x0 }, { CCI_REG8(0x3102), 0x0 }, @@ -583,23 +609,23 @@ static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { CCI_REG8(0x3107), 0x0 }, { CCI_REG8(0x3108), 0x0 }, { CCI_REG8(0x3109), 0x0 }, - { CCI_REG8(0x310A), 0x0 }, - { CCI_REG8(0x310B), 0x0 }, - { CCI_REG8(0x310C), 0x0 }, - { CCI_REG8(0x310D), 0x0 }, + { CCI_REG8(0x310a), 0x0 }, + { CCI_REG8(0x310b), 0x0 }, + { CCI_REG8(0x310c), 0x0 }, + { CCI_REG8(0x310d), 0x0 }, { CCI_REG8(0x3099), 0x5 }, - { CCI_REG8(0x309A), 0x96 }, - { CCI_REG8(0x309B), 0x0 }, - { CCI_REG8(0x309C), 0x6 }, - { CCI_REG8(0x309D), 0x0 }, - { CCI_REG8(0x309E), 0x0 }, - { CCI_REG8(0x309F), 0x0 }, - { CCI_REG8(0x30A0), 0x0 }, - { CCI_REG8(0x30A1), 0x0 }, - { CCI_REG8(0x310E), 0x5 }, - { CCI_REG8(0x310F), 0x2 }, + { CCI_REG8(0x309a), 0x96 }, + { CCI_REG8(0x309b), 0x0 }, + { CCI_REG8(0x309c), 0x6 }, + { CCI_REG8(0x309d), 0x0 }, + { CCI_REG8(0x309e), 0x0 }, + { CCI_REG8(0x309f), 0x0 }, + { CCI_REG8(0x30a0), 0x0 }, + { CCI_REG8(0x30a1), 0x0 }, + { CCI_REG8(0x310e), 0x5 }, + { CCI_REG8(0x310f), 0x2 }, { CCI_REG8(0x3110), 0x0 }, - { CCI_REG8(0x3111), 0x2B }, + { CCI_REG8(0x3111), 0x2b }, { CCI_REG8(0x3112), 0x0 }, { CCI_REG8(0x3113), 0x0 }, { CCI_REG8(0x3114), 0x0 }, @@ -608,142 +634,142 @@ static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { CCI_REG8(0x3117), 0x5 }, { CCI_REG8(0x3118), 0x2 }, { CCI_REG8(0x3119), 0x0 }, - { CCI_REG8(0x311A), 0x2C }, - { CCI_REG8(0x311B), 0x0 }, - { CCI_REG8(0x311C), 0x0 }, - { CCI_REG8(0x311D), 0x0 }, - { CCI_REG8(0x311E), 0x0 }, - { CCI_REG8(0x311F), 0x0 }, - { CCI_REG8(0x30EA), 0x0 }, - { CCI_REG8(0x30EB), 0x0 }, - { CCI_REG8(0x30EC), 0x0 }, - { CCI_REG8(0x30ED), 0x0 }, - { CCI_REG8(0x30EE), 0x0 }, - { CCI_REG8(0x30EF), 0x0 }, - { CCI_REG8(0x30F0), 0x0 }, - { CCI_REG8(0x30F1), 0x0 }, - { CCI_REG8(0x30F2), 0x0 }, - { CCI_REG8(0x313B), 0x3 }, - { CCI_REG8(0x313C), 0x31 }, - { CCI_REG8(0x313D), 0x0 }, - { CCI_REG8(0x313E), 0x7 }, - { CCI_REG8(0x313F), 0x0 }, + { CCI_REG8(0x311a), 0x2c }, + { CCI_REG8(0x311b), 0x0 }, + { CCI_REG8(0x311c), 0x0 }, + { CCI_REG8(0x311d), 0x0 }, + { CCI_REG8(0x311e), 0x0 }, + { CCI_REG8(0x311f), 0x0 }, + { CCI_REG8(0x30ea), 0x0 }, + { CCI_REG8(0x30eb), 0x0 }, + { CCI_REG8(0x30ec), 0x0 }, + { CCI_REG8(0x30ed), 0x0 }, + { CCI_REG8(0x30ee), 0x0 }, + { CCI_REG8(0x30ef), 0x0 }, + { CCI_REG8(0x30f0), 0x0 }, + { CCI_REG8(0x30f1), 0x0 }, + { CCI_REG8(0x30f2), 0x0 }, + { CCI_REG8(0x313b), 0x3 }, + { CCI_REG8(0x313c), 0x31 }, + { CCI_REG8(0x313d), 0x0 }, + { CCI_REG8(0x313e), 0x7 }, + { CCI_REG8(0x313f), 0x0 }, { CCI_REG8(0x3140), 0x68 }, { CCI_REG8(0x3141), 0x0 }, { CCI_REG8(0x3142), 0x34 }, { CCI_REG8(0x3143), 0x0 }, - { CCI_REG8(0x31A0), 0x3 }, - { CCI_REG8(0x31A1), 0x16 }, - { CCI_REG8(0x31A2), 0x0 }, - { CCI_REG8(0x31A3), 0x8 }, - { CCI_REG8(0x31A4), 0x0 }, - { CCI_REG8(0x31A5), 0x7E }, - { CCI_REG8(0x31A6), 0x0 }, - { CCI_REG8(0x31A7), 0x8 }, - { CCI_REG8(0x31A8), 0x0 }, - { CCI_REG8(0x31A9), 0x3 }, - { CCI_REG8(0x31AA), 0x16 }, - { CCI_REG8(0x31AB), 0x0 }, - { CCI_REG8(0x31AC), 0x8 }, - { CCI_REG8(0x31AD), 0x0 }, - { CCI_REG8(0x31AE), 0x7E }, - { CCI_REG8(0x31AF), 0x0 }, - { CCI_REG8(0x31B0), 0x8 }, - { CCI_REG8(0x31B1), 0x0 }, - { CCI_REG8(0x31B2), 0x3 }, - { CCI_REG8(0x31B3), 0x16 }, - { CCI_REG8(0x31B4), 0x0 }, - { CCI_REG8(0x31B5), 0x8 }, - { CCI_REG8(0x31B6), 0x0 }, - { CCI_REG8(0x31B7), 0x7E }, - { CCI_REG8(0x31B8), 0x0 }, - { CCI_REG8(0x31B9), 0x8 }, - { CCI_REG8(0x31BA), 0x0 }, + { CCI_REG8(0x31a0), 0x3 }, + { CCI_REG8(0x31a1), 0x16 }, + { CCI_REG8(0x31a2), 0x0 }, + { CCI_REG8(0x31a3), 0x8 }, + { CCI_REG8(0x31a4), 0x0 }, + { CCI_REG8(0x31a5), 0x7e }, + { CCI_REG8(0x31a6), 0x0 }, + { CCI_REG8(0x31a7), 0x8 }, + { CCI_REG8(0x31a8), 0x0 }, + { CCI_REG8(0x31a9), 0x3 }, + { CCI_REG8(0x31aa), 0x16 }, + { CCI_REG8(0x31ab), 0x0 }, + { CCI_REG8(0x31ac), 0x8 }, + { CCI_REG8(0x31ad), 0x0 }, + { CCI_REG8(0x31ae), 0x7e }, + { CCI_REG8(0x31af), 0x0 }, + { CCI_REG8(0x31b0), 0x8 }, + { CCI_REG8(0x31b1), 0x0 }, + { CCI_REG8(0x31b2), 0x3 }, + { CCI_REG8(0x31b3), 0x16 }, + { CCI_REG8(0x31b4), 0x0 }, + { CCI_REG8(0x31b5), 0x8 }, + { CCI_REG8(0x31b6), 0x0 }, + { CCI_REG8(0x31b7), 0x7e }, + { CCI_REG8(0x31b8), 0x0 }, + { CCI_REG8(0x31b9), 0x8 }, + { CCI_REG8(0x31ba), 0x0 }, { CCI_REG8(0x3120), 0x5 }, { CCI_REG8(0x3121), 0x45 }, { CCI_REG8(0x3122), 0x0 }, - { CCI_REG8(0x3123), 0x1D }, + { CCI_REG8(0x3123), 0x1d }, { CCI_REG8(0x3124), 0x0 }, - { CCI_REG8(0x3125), 0xA9 }, + { CCI_REG8(0x3125), 0xa9 }, { CCI_REG8(0x3126), 0x0 }, - { CCI_REG8(0x3127), 0x6D }, + { CCI_REG8(0x3127), 0x6d }, { CCI_REG8(0x3128), 0x0 }, { CCI_REG8(0x3129), 0x5 }, - { CCI_REG8(0x312A), 0x15 }, - { CCI_REG8(0x312B), 0x0 }, - { CCI_REG8(0x312C), 0xA }, - { CCI_REG8(0x312D), 0x0 }, - { CCI_REG8(0x312E), 0x45 }, - { CCI_REG8(0x312F), 0x0 }, - { CCI_REG8(0x3130), 0x1D }, + { CCI_REG8(0x312a), 0x15 }, + { CCI_REG8(0x312b), 0x0 }, + { CCI_REG8(0x312c), 0xa }, + { CCI_REG8(0x312d), 0x0 }, + { CCI_REG8(0x312e), 0x45 }, + { CCI_REG8(0x312f), 0x0 }, + { CCI_REG8(0x3130), 0x1d }, { CCI_REG8(0x3131), 0x0 }, { CCI_REG8(0x3132), 0x5 }, - { CCI_REG8(0x3133), 0x7D }, + { CCI_REG8(0x3133), 0x7d }, { CCI_REG8(0x3134), 0x0 }, - { CCI_REG8(0x3135), 0xA }, + { CCI_REG8(0x3135), 0xa }, { CCI_REG8(0x3136), 0x0 }, - { CCI_REG8(0x3137), 0xA9 }, + { CCI_REG8(0x3137), 0xa9 }, { CCI_REG8(0x3138), 0x0 }, - { CCI_REG8(0x3139), 0x6D }, - { CCI_REG8(0x313A), 0x0 }, + { CCI_REG8(0x3139), 0x6d }, + { CCI_REG8(0x313a), 0x0 }, { CCI_REG8(0x3144), 0x5 }, { CCI_REG8(0x3145), 0x0 }, { CCI_REG8(0x3146), 0x0 }, { CCI_REG8(0x3147), 0x30 }, { CCI_REG8(0x3148), 0x0 }, { CCI_REG8(0x3149), 0x0 }, - { CCI_REG8(0x314A), 0x0 }, - { CCI_REG8(0x314B), 0x0 }, - { CCI_REG8(0x314C), 0x0 }, - { CCI_REG8(0x314D), 0x3 }, - { CCI_REG8(0x314E), 0x0 }, - { CCI_REG8(0x314F), 0x0 }, + { CCI_REG8(0x314a), 0x0 }, + { CCI_REG8(0x314b), 0x0 }, + { CCI_REG8(0x314c), 0x0 }, + { CCI_REG8(0x314d), 0x3 }, + { CCI_REG8(0x314e), 0x0 }, + { CCI_REG8(0x314f), 0x0 }, { CCI_REG8(0x3150), 0x31 }, { CCI_REG8(0x3151), 0x0 }, { CCI_REG8(0x3152), 0x0 }, { CCI_REG8(0x3153), 0x0 }, { CCI_REG8(0x3154), 0x0 }, { CCI_REG8(0x3155), 0x0 }, - { CCI_REG8(0x31D8), 0x5 }, - { CCI_REG8(0x31D9), 0x3A }, - { CCI_REG8(0x31DA), 0x0 }, - { CCI_REG8(0x31DB), 0x2E }, - { CCI_REG8(0x31DC), 0x0 }, - { CCI_REG8(0x31DD), 0x9E }, - { CCI_REG8(0x31DE), 0x0 }, - { CCI_REG8(0x31DF), 0x7E }, - { CCI_REG8(0x31E0), 0x0 }, - { CCI_REG8(0x31E1), 0x5 }, - { CCI_REG8(0x31E2), 0x4 }, - { CCI_REG8(0x31E3), 0x0 }, - { CCI_REG8(0x31E4), 0x4 }, - { CCI_REG8(0x31E5), 0x0 }, - { CCI_REG8(0x31E6), 0x73 }, - { CCI_REG8(0x31E7), 0x0 }, - { CCI_REG8(0x31E8), 0x4 }, - { CCI_REG8(0x31E9), 0x0 }, - { CCI_REG8(0x31EA), 0x5 }, - { CCI_REG8(0x31EB), 0x0 }, - { CCI_REG8(0x31EC), 0x0 }, - { CCI_REG8(0x31ED), 0x0 }, - { CCI_REG8(0x31EE), 0x0 }, - { CCI_REG8(0x31EF), 0x0 }, - { CCI_REG8(0x31F0), 0x0 }, - { CCI_REG8(0x31F1), 0x0 }, - { CCI_REG8(0x31F2), 0x0 }, - { CCI_REG8(0x31F3), 0x0 }, - { CCI_REG8(0x31F4), 0x0 }, - { CCI_REG8(0x31F5), 0x0 }, - { CCI_REG8(0x31F6), 0x0 }, - { CCI_REG8(0x31F7), 0x0 }, - { CCI_REG8(0x31F8), 0x0 }, - { CCI_REG8(0x31F9), 0x0 }, - { CCI_REG8(0x31FA), 0x0 }, - { CCI_REG8(0x31FB), 0x5 }, - { CCI_REG8(0x31FC), 0x0 }, - { CCI_REG8(0x31FD), 0x0 }, - { CCI_REG8(0x31FE), 0x0 }, - { CCI_REG8(0x31FF), 0x0 }, + { CCI_REG8(0x31d8), 0x5 }, + { CCI_REG8(0x31d9), 0x3a }, + { CCI_REG8(0x31da), 0x0 }, + { CCI_REG8(0x31db), 0x2e }, + { CCI_REG8(0x31dc), 0x0 }, + { CCI_REG8(0x31dd), 0x9e }, + { CCI_REG8(0x31de), 0x0 }, + { CCI_REG8(0x31df), 0x7e }, + { CCI_REG8(0x31e0), 0x0 }, + { CCI_REG8(0x31e1), 0x5 }, + { CCI_REG8(0x31e2), 0x4 }, + { CCI_REG8(0x31e3), 0x0 }, + { CCI_REG8(0x31e4), 0x4 }, + { CCI_REG8(0x31e5), 0x0 }, + { CCI_REG8(0x31e6), 0x73 }, + { CCI_REG8(0x31e7), 0x0 }, + { CCI_REG8(0x31e8), 0x4 }, + { CCI_REG8(0x31e9), 0x0 }, + { CCI_REG8(0x31ea), 0x5 }, + { CCI_REG8(0x31eb), 0x0 }, + { CCI_REG8(0x31ec), 0x0 }, + { CCI_REG8(0x31ed), 0x0 }, + { CCI_REG8(0x31ee), 0x0 }, + { CCI_REG8(0x31ef), 0x0 }, + { CCI_REG8(0x31f0), 0x0 }, + { CCI_REG8(0x31f1), 0x0 }, + { CCI_REG8(0x31f2), 0x0 }, + { CCI_REG8(0x31f3), 0x0 }, + { CCI_REG8(0x31f4), 0x0 }, + { CCI_REG8(0x31f5), 0x0 }, + { CCI_REG8(0x31f6), 0x0 }, + { CCI_REG8(0x31f7), 0x0 }, + { CCI_REG8(0x31f8), 0x0 }, + { CCI_REG8(0x31f9), 0x0 }, + { CCI_REG8(0x31fa), 0x0 }, + { CCI_REG8(0x31fb), 0x5 }, + { CCI_REG8(0x31fc), 0x0 }, + { CCI_REG8(0x31fd), 0x0 }, + { CCI_REG8(0x31fe), 0x0 }, + { CCI_REG8(0x31ff), 0x0 }, { CCI_REG8(0x3200), 0x0 }, { CCI_REG8(0x3201), 0x0 }, { CCI_REG8(0x3202), 0x0 }, @@ -754,199 +780,121 @@ static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { CCI_REG8(0x3207), 0x0 }, { CCI_REG8(0x3208), 0x0 }, { CCI_REG8(0x3209), 0x0 }, - { CCI_REG8(0x320A), 0x0 }, - { CCI_REG8(0x320B), 0x0 }, + { CCI_REG8(0x320a), 0x0 }, + { CCI_REG8(0x320b), 0x0 }, { CCI_REG8(0x3164), 0x5 }, { CCI_REG8(0x3165), 0x14 }, { CCI_REG8(0x3166), 0x0 }, - { CCI_REG8(0x3167), 0xC }, + { CCI_REG8(0x3167), 0xc }, { CCI_REG8(0x3168), 0x0 }, { CCI_REG8(0x3169), 0x44 }, - { CCI_REG8(0x316A), 0x0 }, - { CCI_REG8(0x316B), 0x1F }, - { CCI_REG8(0x316C), 0x0 }, - { CCI_REG8(0x316D), 0x5 }, - { CCI_REG8(0x316E), 0x7C }, - { CCI_REG8(0x316F), 0x0 }, - { CCI_REG8(0x3170), 0xC }, + { CCI_REG8(0x316a), 0x0 }, + { CCI_REG8(0x316b), 0x1f }, + { CCI_REG8(0x316c), 0x0 }, + { CCI_REG8(0x316d), 0x5 }, + { CCI_REG8(0x316e), 0x7c }, + { CCI_REG8(0x316f), 0x0 }, + { CCI_REG8(0x3170), 0xc }, { CCI_REG8(0x3171), 0x0 }, - { CCI_REG8(0x3172), 0xA8 }, + { CCI_REG8(0x3172), 0xa8 }, { CCI_REG8(0x3173), 0x0 }, - { CCI_REG8(0x3174), 0x6F }, + { CCI_REG8(0x3174), 0x6f }, { CCI_REG8(0x3175), 0x0 }, - { CCI_REG8(0x31C4), 0x5 }, - { CCI_REG8(0x31C5), 0x24 }, - { CCI_REG8(0x31C6), 0x1 }, - { CCI_REG8(0x31C7), 0x4 }, - { CCI_REG8(0x31C8), 0x0 }, - { CCI_REG8(0x31C9), 0x5 }, - { CCI_REG8(0x31CA), 0x24 }, - { CCI_REG8(0x31CB), 0x1 }, - { CCI_REG8(0x31CC), 0x4 }, - { CCI_REG8(0x31CD), 0x0 }, - { CCI_REG8(0x31CE), 0x5 }, - { CCI_REG8(0x31CF), 0x24 }, - { CCI_REG8(0x31D0), 0x1 }, - { CCI_REG8(0x31D1), 0x4 }, - { CCI_REG8(0x31D2), 0x0 }, - { CCI_REG8(0x31D3), 0x5 }, - { CCI_REG8(0x31D4), 0x73 }, - { CCI_REG8(0x31D5), 0x0 }, - { CCI_REG8(0x31D6), 0xB1 }, - { CCI_REG8(0x31D7), 0x0 }, + { CCI_REG8(0x31c4), 0x5 }, + { CCI_REG8(0x31c5), 0x24 }, + { CCI_REG8(0x31c6), 0x1 }, + { CCI_REG8(0x31c7), 0x4 }, + { CCI_REG8(0x31c8), 0x0 }, + { CCI_REG8(0x31c9), 0x5 }, + { CCI_REG8(0x31ca), 0x24 }, + { CCI_REG8(0x31cb), 0x1 }, + { CCI_REG8(0x31cc), 0x4 }, + { CCI_REG8(0x31cd), 0x0 }, + { CCI_REG8(0x31ce), 0x5 }, + { CCI_REG8(0x31cf), 0x24 }, + { CCI_REG8(0x31d0), 0x1 }, + { CCI_REG8(0x31d1), 0x4 }, + { CCI_REG8(0x31d2), 0x0 }, + { CCI_REG8(0x31d3), 0x5 }, + { CCI_REG8(0x31d4), 0x73 }, + { CCI_REG8(0x31d5), 0x0 }, + { CCI_REG8(0x31d6), 0xb1 }, + { CCI_REG8(0x31d7), 0x0 }, { CCI_REG8(0x3176), 0x5 }, { CCI_REG8(0x3177), 0x10 }, { CCI_REG8(0x3178), 0x0 }, { CCI_REG8(0x3179), 0x56 }, - { CCI_REG8(0x317A), 0x0 }, - { CCI_REG8(0x317B), 0x0 }, - { CCI_REG8(0x317C), 0x0 }, - { CCI_REG8(0x317D), 0x0 }, - { CCI_REG8(0x317E), 0x0 }, - { CCI_REG8(0x317F), 0x5 }, - { CCI_REG8(0x3180), 0x6A }, + { CCI_REG8(0x317a), 0x0 }, + { CCI_REG8(0x317b), 0x0 }, + { CCI_REG8(0x317c), 0x0 }, + { CCI_REG8(0x317d), 0x0 }, + { CCI_REG8(0x317e), 0x0 }, + { CCI_REG8(0x317f), 0x5 }, + { CCI_REG8(0x3180), 0x6a }, { CCI_REG8(0x3181), 0x0 }, - { CCI_REG8(0x3182), 0xAD }, + { CCI_REG8(0x3182), 0xad }, { CCI_REG8(0x3183), 0x0 }, { CCI_REG8(0x3184), 0x0 }, { CCI_REG8(0x3185), 0x0 }, { CCI_REG8(0x3186), 0x0 }, { CCI_REG8(0x3187), 0x0 }, - { CCI_REG8(0x100C), 0x7E }, - { CCI_REG8(0x100D), 0x0 }, - { CCI_REG8(0x1012), 0xDF }, - { CCI_REG8(0x1013), 0x2B }, - { CCI_REG8(0x1002), 0x4 }, + { CCI_REG8(0x100d), 0x0 }, + { CCI_REG8(0x1013), 0x2b }, /* Sensor control mode */ { CCI_REG8(0x0043), 0x0 }, // Sensor Control Mode.SLEEP_POWER_MODE(0) { CCI_REG8(0x0043), 0x0 }, // Sensor Control Mode.IDLE_POWER_MODE(0) { CCI_REG8(0x0043), 0x4 }, // Sensor Control Mode.SYSTEM_CLOCK_ENABLE(0) { CCI_REG8(0x0043), 0xC }, // Sensor Control Mode.SRAM_CLOCK_ENABLE(0) - { CCI_REG8(0x1002), 0x4 }, // Sensor Control Mode.IMAGER_RUN_CONT(0) { CCI_REG8(0x1001), 0x41 }, // Sensor Control Mode.EXT_EVENT_SEL(0) - { CCI_REG8(0x10F2), 0x1 }, // Sensor Control Mode.NB_OF_FRAMES_A(0) - { CCI_REG8(0x10F3), 0x0 }, // Sensor Control Mode.NB_OF_FRAMES_A(1) - { CCI_REG8(0x1111), 0x1 }, // Sensor Control Mode.NB_OF_FRAMES_B(0) - { CCI_REG8(0x1112), 0x0 }, // Sensor Control Mode.NB_OF_FRAMES_B(1) + { CCI_REG8(0x10f2), 0x1 }, // Sensor Control Mode.NB_OF_FRAMES_A(0) + { CCI_REG8(0x10f3), 0x0 }, // Sensor Control Mode.NB_OF_FRAMES_A(1) { CCI_REG8(0x0012), 0x0 }, // IO Drive Strength.DIG_DRIVE_STRENGTH(0) { CCI_REG8(0x0012), 0x0 }, // IO Drive Strength.CCI_DRIVE_STRENGTH(0) { CCI_REG8(0x1001), 0x41 }, // Readout && Exposure.EXT_EXP_PW_SEL(0) - { CCI_REG8(0x10D0), 0x0 }, // Readout && Exposure.EXT_EXP_PW_DELAY(0) - { CCI_REG8(0x10D1), 0x0 }, // Readout && Exposure.EXT_EXP_PW_DELAY(1) - { CCI_REG8(0x1012), 0x91 }, // Readout && Exposure.VBLANK_A(0) - { CCI_REG8(0x1013), 0xD }, // Readout && Exposure.VBLANK_A(1) - { CCI_REG8(0x1103), 0x91 }, // Readout && Exposure.VBLANK_B(0) - { CCI_REG8(0x1104), 0xD }, // Readout && Exposure.VBLANK_B(1) - { CCI_REG8(0x100C), 0x80 }, // Readout && Exposure.EXP_TIME_A(0) - { CCI_REG8(0x100D), 0x0 }, // Readout && Exposure.EXP_TIME_A(1) - { CCI_REG8(0x1115), 0x80 }, // Readout && Exposure.EXP_TIME_B(0) - { CCI_REG8(0x1116), 0x0 }, // Readout && Exposure.EXP_TIME_B(1) - { CCI_REG8(0x102B), 0x30 }, // Readout && Exposure.ROW_LENGTH_A(0) - { CCI_REG8(0x102C), 0x1 }, // Readout && Exposure.ROW_LENGTH_A(1) - { CCI_REG8(0x1113), 0x30 }, // Readout && Exposure.ROW_LENGTH_B(0) - { CCI_REG8(0x1114), 0x1 }, // Readout && Exposure.ROW_LENGTH_B(1) - /* ROI */ - { CCI_REG8(0x2008), 0x20 }, // Horizontal ROI.HSIZE_A(0) - { CCI_REG8(0x2009), 0x3 }, // Horizontal ROI.HSIZE_A(1) - { CCI_REG8(0x2098), 0x20 }, // Horizontal ROI.HSIZE_B(0) - { CCI_REG8(0x2099), 0x3 }, // Horizontal ROI.HSIZE_B(1) - { CCI_REG8(0x200A), 0x0 }, // Horizontal ROI.HSTART_A(0) - { CCI_REG8(0x200B), 0x0 }, // Horizontal ROI.HSTART_A(1) - { CCI_REG8(0x209A), 0x0 }, // Horizontal ROI.HSTART_B(0) - { CCI_REG8(0x209B), 0x0 }, // Horizontal ROI.HSTART_B(1) - { CCI_REG8(0x207D), 0x40 }, // Horizontal ROI.MIPI_HSIZE(0) - { CCI_REG8(0x207E), 0x6 }, // Horizontal ROI.MIPI_HSIZE(1) - { CCI_REG8(0x107D), 0x0 }, // Vertical ROI.VSTART0_A(0) - { CCI_REG8(0x107E), 0x0 }, // Vertical ROI.VSTART0_A(1) - { CCI_REG8(0x1087), 0x78 }, // Vertical ROI.VSIZE0_A(0) - { CCI_REG8(0x1088), 0x5 }, // Vertical ROI.VSIZE0_A(1) - { CCI_REG8(0x1105), 0x0 }, // Vertical ROI.VSTART0_B(0) - { CCI_REG8(0x1106), 0x0 }, // Vertical ROI.VSTART0_B(1) - { CCI_REG8(0x110A), 0x78 }, // Vertical ROI.VSIZE0_B(0) - { CCI_REG8(0x110B), 0x5 }, // Vertical ROI.VSIZE0_B(1) - { CCI_REG8(0x107D), 0x0 }, // Vertical ROI.VSTART1_A(0) - { CCI_REG8(0x107E), 0x0 }, // Vertical ROI.VSTART1_A(1) - { CCI_REG8(0x107F), 0x0 }, // Vertical ROI.VSTART1_A(2) - { CCI_REG8(0x1087), 0x78 }, // Vertical ROI.VSIZE1_A(0) - { CCI_REG8(0x1088), 0x5 }, // Vertical ROI.VSIZE1_A(1) - { CCI_REG8(0x1089), 0x0 }, // Vertical ROI.VSIZE1_A(2) - { CCI_REG8(0x1105), 0x0 }, // Vertical ROI.VSTART1_B(0) - { CCI_REG8(0x1106), 0x0 }, // Vertical ROI.VSTART1_B(1) - { CCI_REG8(0x1107), 0x0 }, // Vertical ROI.VSTART1_B(2) - { CCI_REG8(0x110A), 0x78 }, // Vertical ROI.VSIZE1_B(0) - { CCI_REG8(0x110B), 0x5 }, // Vertical ROI.VSIZE1_B(1) - { CCI_REG8(0x110C), 0x0 }, // Vertical ROI.VSIZE1_B(2) - { CCI_REG8(0x107D), 0x0 }, // Vertical ROI.VSTART2_A(0) - { CCI_REG8(0x107E), 0x0 }, // Vertical ROI.VSTART2_A(1) - { CCI_REG8(0x107F), 0x0 }, // Vertical ROI.VSTART2_A(2) - { CCI_REG8(0x1080), 0x0 }, // Vertical ROI.VSTART2_A(3) - { CCI_REG8(0x1081), 0x0 }, // Vertical ROI.VSTART2_A(4) - { CCI_REG8(0x1087), 0x78 }, // Vertical ROI.VSIZE2_A(0) - { CCI_REG8(0x1088), 0x5 }, // Vertical ROI.VSIZE2_A(1) - { CCI_REG8(0x1089), 0x0 }, // Vertical ROI.VSIZE2_A(2) - { CCI_REG8(0x108A), 0x0 }, // Vertical ROI.VSIZE2_A(3) - { CCI_REG8(0x108B), 0x0 }, // Vertical ROI.VSIZE2_A(4) - { CCI_REG8(0x1105), 0x0 }, // Vertical ROI.VSTART2_B(0) - { CCI_REG8(0x1106), 0x0 }, // Vertical ROI.VSTART2_B(1) - { CCI_REG8(0x1107), 0x0 }, // Vertical ROI.VSTART2_B(2) - { CCI_REG8(0x1108), 0x0 }, // Vertical ROI.VSTART2_B(3) - { CCI_REG8(0x1109), 0x0 }, // Vertical ROI.VSTART2_B(4) - { CCI_REG8(0x110A), 0x78 }, // Vertical ROI.VSIZE2_B(0) - { CCI_REG8(0x110B), 0x5 }, // Vertical ROI.VSIZE2_B(1) - { CCI_REG8(0x110C), 0x0 }, // Vertical ROI.VSIZE2_B(2) - { CCI_REG8(0x110D), 0x0 }, // Vertical ROI.VSIZE2_B(3) - { CCI_REG8(0x110E), 0x0 }, // Vertical ROI.VSIZE2_B(4) - /* Mirror and Flip */ - { CCI_REG8(0x209C), 0x0 }, // Mirroring && Flipping.HFLIP_A(0) - { CCI_REG8(0x209D), 0x0 }, // Mirroring && Flipping.HFLIP_B(0) - { CCI_REG8(0x1095), 0x0 }, // Mirroring && Flipping.VFLIP(0) - { CCI_REG8(0x2063), 0x0 }, // Mirroring && Flipping.BIT_ORDER(0) + { CCI_REG8(0x10d0), 0x0 }, // Readout && Exposure.EXT_EXP_PW_DELAY(0) + { CCI_REG8(0x10d1), 0x0 }, // Readout && Exposure.EXT_EXP_PW_DELAY(1) /* MIPI */ { CCI_REG8(0x6006), 0x0 }, // MIPI.TX_CTRL_EN(0) { CCI_REG8(0x5004), 0x1 }, // MIPI.datarate { CCI_REG8(0x5086), 0x2 }, // MIPI.datarate - { CCI_REG8(0x5087), 0x4E }, // MIPI.datarate + { CCI_REG8(0x5087), 0x4e }, // MIPI.datarate { CCI_REG8(0x5088), 0x0 }, // MIPI.datarate { CCI_REG8(0x5090), 0x0 }, // MIPI.datarate { CCI_REG8(0x5091), 0x8 }, // MIPI.datarate { CCI_REG8(0x5092), 0x14 }, // MIPI.datarate - { CCI_REG8(0x5093), 0xF }, // MIPI.datarate + { CCI_REG8(0x5093), 0xf }, // MIPI.datarate { CCI_REG8(0x5094), 0x6 }, // MIPI.datarate { CCI_REG8(0x5095), 0x32 }, // MIPI.datarate - { CCI_REG8(0x5096), 0xE }, // MIPI.datarate + { CCI_REG8(0x5096), 0xe }, // MIPI.datarate { CCI_REG8(0x5097), 0x0 }, // MIPI.datarate { CCI_REG8(0x5098), 0x11 }, // MIPI.datarate { CCI_REG8(0x5004), 0x0 }, // MIPI.datarate - { CCI_REG8(0x2066), 0x6C }, // MIPI.datarate + { CCI_REG8(0x2066), 0x6c }, // MIPI.datarate { CCI_REG8(0x2067), 0x7 }, // MIPI.datarate - { CCI_REG8(0x206E), 0x7E }, // MIPI.datarate - { CCI_REG8(0x206F), 0x6 }, // MIPI.datarate - { CCI_REG8(0x20AC), 0x7E }, // MIPI.datarate - { CCI_REG8(0x20AD), 0x6 }, // MIPI.datarate - { CCI_REG8(0x2076), 0xC8 }, // MIPI.datarate + { CCI_REG8(0x206e), 0x7e }, // MIPI.datarate + { CCI_REG8(0x206f), 0x6 }, // MIPI.datarate + { CCI_REG8(0x20ac), 0x7e }, // MIPI.datarate + { CCI_REG8(0x20ad), 0x6 }, // MIPI.datarate + { CCI_REG8(0x2076), 0xc8 }, // MIPI.datarate { CCI_REG8(0x2077), 0x0 }, // MIPI.datarate - { CCI_REG8(0x20B4), 0xC8 }, // MIPI.datarate - { CCI_REG8(0x20B5), 0x0 }, // MIPI.datarate - { CCI_REG8(0x2078), 0x1E }, // MIPI.datarate + { CCI_REG8(0x20b4), 0xc8 }, // MIPI.datarate + { CCI_REG8(0x20b5), 0x0 }, // MIPI.datarate + { CCI_REG8(0x2078), 0x1e }, // MIPI.datarate { CCI_REG8(0x2079), 0x4 }, // MIPI.datarate - { CCI_REG8(0x20B6), 0x1E }, // MIPI.datarate - { CCI_REG8(0x20B7), 0x4 }, // MIPI.datarate - { CCI_REG8(0x207A), 0xD4 }, // MIPI.datarate - { CCI_REG8(0x207B), 0x4 }, // MIPI.datarate - { CCI_REG8(0x20B8), 0xD4 }, // MIPI.datarate - { CCI_REG8(0x20B9), 0x4 }, // MIPI.datarate - { CCI_REG8(0x208D), 0x4 }, // MIPI.CSI2_DTYPE(0) - { CCI_REG8(0x208E), 0x0 }, // MIPI.CSI2_DTYPE(1) - { CCI_REG8(0x207C), 0x0 }, // MIPI.VC_ID(0) + { CCI_REG8(0x20b6), 0x1e }, // MIPI.datarate + { CCI_REG8(0x20b7), 0x4 }, // MIPI.datarate + { CCI_REG8(0x207a), 0xd4 }, // MIPI.datarate + { CCI_REG8(0x207b), 0x4 }, // MIPI.datarate + { CCI_REG8(0x20b8), 0xd4 }, // MIPI.datarate + { CCI_REG8(0x20b9), 0x4 }, // MIPI.datarate + { CCI_REG8(0x207c), 0x0 }, // MIPI.VC_ID(0) { CCI_REG8(0x6001), 0x7 }, // MIPI.TINIT(0) - { CCI_REG8(0x6002), 0xD8 }, // MIPI.TINIT(1) + { CCI_REG8(0x6002), 0xd8 }, // MIPI.TINIT(1) { CCI_REG8(0x6010), 0x0 }, // MIPI.FRAME_MODE(0) { CCI_REG8(0x6010), 0x0 }, // MIPI.EMBEDDED_FRAME_MODE(0) { CCI_REG8(0x6011), 0x0 }, // MIPI.DATA_ENABLE_POLARITY(0) { CCI_REG8(0x6011), 0x0 }, // MIPI.HSYNC_POLARITY(0) { CCI_REG8(0x6011), 0x0 }, // MIPI.VSYNC_POLARITY(0) - { CCI_REG8(0x6012), 0x1 }, // MIPI.LANE(0) - { CCI_REG8(0x6013), 0x0 }, // MIPI.CLK_MODE(0) { CCI_REG8(0x6016), 0x0 }, // MIPI.FRAME_COUNTER(0) { CCI_REG8(0x6017), 0x0 }, // MIPI.FRAME_COUNTER(1) { CCI_REG8(0x6037), 0x1 }, // MIPI.LINE_COUNT_RAW8(0) @@ -957,44 +905,45 @@ static const struct cci_reg_sequence full_1600_1400_1500_12b_2lanes_reg_new[] = { CCI_REG8(0x6018), 0x0 }, // MIPI.CCI_WRITE_INTERRUPT_EN(0) { CCI_REG8(0x6065), 0x0 }, // MIPI.TWAKE_TIMER(0) { CCI_REG8(0x6066), 0x0 }, // MIPI.TWAKE_TIMER(1) - { CCI_REG8(0x601C), 0x0 }, // MIPI.SKEW_CAL_EN(0) - { CCI_REG8(0x601D), 0x0 }, // MIPI.SKEW_COUNT(0) - { CCI_REG8(0x601E), 0x22 }, // MIPI.SKEW_COUNT(1) - { CCI_REG8(0x601F), 0x0 }, // MIPI.SCRAMBLING_EN(0) - { CCI_REG8(0x6003), 0x1 }, // MIPI.INIT_SKEW_EN(0) - { CCI_REG8(0x6004), 0x7A }, // MIPI.INIT_SKEW(0) + { CCI_REG8(0x601c), 0x0 }, // MIPI.SKEW_CAL_EN(0) + { CCI_REG8(0x601d), 0x0 }, // MIPI.SKEW_COUNT(0) + { CCI_REG8(0x601e), 0x22 }, // MIPI.SKEW_COUNT(1) + { CCI_REG8(0x601f), 0x0 }, // MIPI.SCRAMBLING_EN(0) + { CCI_REG8(0x6003), 0x0 }, // MIPI.INIT_SKEW_EN(0) + { CCI_REG8(0x6004), 0x7a }, // MIPI.INIT_SKEW(0) { CCI_REG8(0x6005), 0x12 }, // MIPI.INIT_SKEW(1) { CCI_REG8(0x6006), 0x1 }, // MIPI.TX_CTRL_EN(0) /* Processing */ { CCI_REG8(0x4006), 0x8 }, // Processing.BSP(0) - { CCI_REG8(0x209E), 0x2 }, // Processing.BIT_DEPTH(0) { CCI_REG8(0x2045), 0x1 }, // Processing.CDS_RNC(0) { CCI_REG8(0x2048), 0x1 }, // Processing.CDS_IMG(0) - { CCI_REG8(0x204B), 0x3 }, // Processing.RNC_EN(0) - { CCI_REG8(0x205B), 0x64 }, // Processing.RNC_DARK_TARGET(0) - { CCI_REG8(0x205C), 0x0 }, // Processing.RNC_DARK_TARGET(1) - { CCI_REG8(0x24DC), 0x12 }, // Defect Pixel Correction.DC_ENABLE(0) - { CCI_REG8(0x24DC), 0x10 }, // Defect Pixel Correction.DC_MODE(0) - { CCI_REG8(0x24DC), 0x0 }, // Defect Pixel Correction.DC_REPLACEMENT_VALUE(0) - { CCI_REG8(0x24DD), 0x0 }, // Defect Pixel Correction.DC_LIMIT_LOW(0) - { CCI_REG8(0x24DE), 0x0 }, // Defect Pixel Correction.DC_LIMIT_HIGH(0) - { CCI_REG8(0x24DF), 0x0 }, // Defect Pixel Correction.DC_LIMIT_HIGH_MODE(0) + { CCI_REG8(0x204b), 0x3 }, // Processing.RNC_EN(0) + { CCI_REG8(0x205b), 0x64 }, // Processing.RNC_DARK_TARGET(0) + { CCI_REG8(0x205c), 0x0 }, // Processing.RNC_DARK_TARGET(1) + { CCI_REG8(0x24dc), 0x12 }, // Defect Pixel Correction.DC_ENABLE(0) + { CCI_REG8(0x24dc), 0x10 }, // Defect Pixel Correction.DC_MODE(0) + { CCI_REG8(0x24dc), 0x0 }, // Defect Pixel Correction.DC_REPLACEMENT_VALUE(0) + { CCI_REG8(0x24dd), 0x0 }, // Defect Pixel Correction.DC_LIMIT_LOW(0) + { CCI_REG8(0x24de), 0x0 }, // Defect Pixel Correction.DC_LIMIT_HIGH(0) + { CCI_REG8(0x24df), 0x0 }, // Defect Pixel Correction.DC_LIMIT_HIGH_MODE(0) /* Illumination */ - { CCI_REG8(0x10D7), 0x1 }, // Illumination Trigger.ILLUM_EN(0) - { CCI_REG8(0x10D8), 0x2 }, // Illumination Trigger.ILLUM_POL(0) + { CCI_REG8(0x10d7), 0x1 }, // Illumination Trigger.ILLUM_EN(0) + { CCI_REG8(0x10d8), 0x2 }, // Illumination Trigger.ILLUM_POL(0) /* Histogram */ - { CCI_REG8(0x205D), 0x0 }, // Histogram.HIST_EN(0) - { CCI_REG8(0x205E), 0x0 }, // Histogram.HIST_USAGE_RATIO(0) + { CCI_REG8(0x205d), 0x0 }, // Histogram.HIST_EN(0) + { CCI_REG8(0x205e), 0x0 }, // Histogram.HIST_USAGE_RATIO(0) { CCI_REG8(0x2063), 0x0 }, // Histogram.PIXEL_DATA_SUPP(0) { CCI_REG8(0x2063), 0x0 }, // Histogram.PIXEL_TRANSMISSION(0) /* TP */ { CCI_REG8(0x2091), 0x0 }, // Test Pattern Generator.TPG_EN(0) { CCI_REG8(0x2091), 0x0 }, // Test Pattern Generator.TPG_CONFIG(0) + /* Reduce Slew Rate - fix for defect line */ + { CCI_REG8(0x402d), 0x7b }, }; static const char *const mira220_test_pattern_menu[] = { "Disabled", - "Vertial Gradient", + "Vertical Gradient", }; static const int mira220_test_pattern_val[] = { @@ -1003,101 +952,90 @@ static const int mira220_test_pattern_val[] = { }; /* regulator supplies */ -static const char *const mira220_supply_name[] = { +static const char *const mira220_supplies[] = { /* Supplies can be enabled in any order */ "vana", /* Analog (2.8V) supply */ "vdig", /* Digital Core (1.8V) supply */ "vddl", /* IF (1.2V) supply */ }; -#define MIRA220_NUM_SUPPLIES ARRAY_SIZE(mira220_supply_name) +struct mira220 { + struct v4l2_subdev sd; + struct media_pad pad; + + enum mira220_variants variant; + + struct clk *xclk; + u32 xclk_freq; + + struct regulator_bulk_data supplies[ARRAY_SIZE(mira220_supplies)]; + + struct gpio_desc *reset_gpio; + + unsigned int lanes; + + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_ctrl *vflip; + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vblank; + struct v4l2_ctrl *exposure; + + struct regmap *regmap; +}; + +static inline struct mira220 *to_mira220(struct v4l2_subdev *sd) +{ + return container_of_const(sd, struct mira220, sd); +} + +static bool mira220_is_mono(struct mira220 *mira220) +{ + return mira220->variant == MIRA220_VARIANT_MONO; +} +static unsigned int mira220_min_row_length(struct mira220 *mira220) +{ + return MIRA220_ROW_LENGTH_MIN * (2 / mira220->lanes); +} -// Mira220 comes in monochrome and RGB variants. This driver implements the RGB variant. /* - * The supported formats. - * This table MUST contain 4 entries per format, to cover the various flip - * combinations in the order + * The supported formats. This table contains 4 entries per format, to cover the + * various flip combinations in the order: * - no flip * - h flip * - v flip * - h&v flips */ -static const u32 mira220_mbus_formats[] = { - MEDIA_BUS_FMT_SRGGB12_1X12, +static const u32 mira220_mbus_color_formats[] = { MEDIA_BUS_FMT_SGRBG12_1X12, - MEDIA_BUS_FMT_SGBRG12_1X12, + MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SBGGR12_1X12, + MEDIA_BUS_FMT_SGBRG12_1X12, - MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SGRBG10_1X10, - MEDIA_BUS_FMT_SGBRG10_1X10, + MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SBGGR10_1X10, + MEDIA_BUS_FMT_SGBRG10_1X10, - MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SGRBG8_1X8, - MEDIA_BUS_FMT_SGBRG8_1X8, + MEDIA_BUS_FMT_SRGGB8_1X8, MEDIA_BUS_FMT_SBGGR8_1X8, - + MEDIA_BUS_FMT_SGBRG8_1X8, }; -/* Mode configs */ -static const struct mira220_mode supported_modes[] = { - /* 2 MPx 30fps 12bpp mode */ - { - .width = 1600, - .height = 1400, - .crop = { - .left = MIRA220_PIXEL_ARRAY_LEFT, - .top = MIRA220_PIXEL_ARRAY_TOP, - .width = 1600, - .height = 1400 - }, - .reg_list = { - .num_of_regs = ARRAY_SIZE(full_1600_1400_1500_12b_2lanes_reg_new), - .regs = full_1600_1400_1500_12b_2lanes_reg_new, - }, - // vblank is ceil(MIRA220_GLOB_NUM_CLK_CYCLES / ROW_LENGTH) + 11 - // ROW_LENGTH is configured by register 0x102B, 0x102C. - .row_length = 304, - .pixel_rate = MIRA220_PIXEL_RATE, - .min_vblank = 20, - .max_vblank = 50000, - .hblank = MIRA220_HBLANK_1600x1400_304, - }, +static const u32 mira220_mbus_mono_formats[] = { + MEDIA_BUS_FMT_Y12_1X12, + MEDIA_BUS_FMT_Y10_1X10, + MEDIA_BUS_FMT_Y8_1X8, }; -struct mira220 { - struct v4l2_subdev sd; - struct media_pad pad; - - struct v4l2_mbus_framefmt fmt; - - struct clk *xclk; /* system clock to MIRA220 */ - u32 xclk_freq; - - struct regulator_bulk_data supplies[MIRA220_NUM_SUPPLIES]; - - struct v4l2_ctrl_handler ctrl_handler; - struct v4l2_ctrl *pixel_rate; - struct v4l2_ctrl *vflip; - struct v4l2_ctrl *hflip; - struct v4l2_ctrl *vblank; - struct v4l2_ctrl *hblank; - struct v4l2_ctrl *exposure; - struct v4l2_ctrl *gain; - - /* Current mode */ - const struct mira220_mode *mode; - - struct mutex mutex; - - struct regmap *regmap; -}; - -static inline struct mira220 *to_mira220(struct v4l2_subdev *_sd) +#define MIRA220_FLIP_FORMAT_MASK 0x3 +static inline unsigned int mira220_flip_format_index(struct mira220 *mira220, + unsigned int index) { - return container_of(_sd, struct mira220, sd); + return (index & ~MIRA220_FLIP_FORMAT_MASK) | + (mira220->vflip->val ? BIT(1) : 0) | + (mira220->hflip->val ? BIT(0) : 0); } /* Power/clock management functions */ @@ -1106,27 +1044,28 @@ static int mira220_power_on(struct device *dev) struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *sd = i2c_get_clientdata(client); struct mira220 *mira220 = to_mira220(sd); - int ret = -EINVAL; + int ret; - ret = regulator_bulk_enable(MIRA220_NUM_SUPPLIES, mira220->supplies); + ret = regulator_bulk_enable(ARRAY_SIZE(mira220_supplies), + mira220->supplies); if (ret) { dev_err(&client->dev, "%s: failed to enable regulators\n", __func__); - goto reg_off; + return ret; } + ret = clk_prepare_enable(mira220->xclk); if (ret) { dev_err(&client->dev, "%s: failed to enable clock\n", __func__); - goto clk_off; + goto reg_off; } - fsleep(MIRA220_XCLR_MIN_DELAY_US); + + gpiod_set_value_cansleep(mira220->reset_gpio, 0); return 0; -clk_off: - clk_disable_unprepare(mira220->xclk); reg_off: - ret = regulator_bulk_disable(MIRA220_NUM_SUPPLIES, mira220->supplies); + regulator_bulk_disable(ARRAY_SIZE(mira220_supplies), mira220->supplies); return ret; } @@ -1135,103 +1074,73 @@ static int mira220_power_off(struct device *dev) struct i2c_client *client = to_i2c_client(dev); struct v4l2_subdev *sd = i2c_get_clientdata(client); struct mira220 *mira220 = to_mira220(sd); - (void)mira220; + gpiod_set_value_cansleep(mira220->reset_gpio, 1); clk_disable_unprepare(mira220->xclk); - regulator_bulk_disable(MIRA220_NUM_SUPPLIES, mira220->supplies); + regulator_bulk_disable(ARRAY_SIZE(mira220_supplies), mira220->supplies); return 0; } static int mira220_write_start_streaming_regs(struct mira220 *mira220) { - struct i2c_client *const client = v4l2_get_subdevdata(&mira220->sd); int ret = 0; - // Setting master control - ret = cci_write(mira220->regmap, MIRA220_IMAGER_STATE_REG, - MIRA220_IMAGER_STATE_MASTER_CONTROL, NULL); - if (ret) { - dev_err(&client->dev, "Error setting master control"); - return ret; - } - - // Enable continuous streaming - ret = cci_write(mira220->regmap, MIRA220_IMAGER_RUN_CONT_REG, - MIRA220_IMAGER_RUN_CONT_ENABLE, NULL); - if (ret) { - dev_err(&client->dev, "Error enabling continuous streaming"); - return ret; - } + /* Setting master control */ + cci_write(mira220->regmap, MIRA220_IMAGER_STATE_REG, + MIRA220_IMAGER_STATE_MASTER_CONTROL, &ret); - ret = cci_write(mira220->regmap, MIRA220_IMAGER_RUN_REG, - MIRA220_IMAGER_RUN_START, NULL); - if (ret) { - dev_err(&client->dev, "Error setting internal trigger"); - return ret; - } + /* Enable continuous streaming */ + cci_write(mira220->regmap, MIRA220_IMAGER_RUN_CONT_REG, + MIRA220_IMAGER_RUN_CONT_ENABLE, &ret); + cci_write(mira220->regmap, MIRA220_IMAGER_RUN_REG, + MIRA220_IMAGER_RUN_START, &ret); return ret; } static int mira220_write_stop_streaming_regs(struct mira220 *mira220) { - struct i2c_client *const client = v4l2_get_subdevdata(&mira220->sd); int ret = 0; - ret = cci_write(mira220->regmap, MIRA220_IMAGER_STATE_REG, - MIRA220_IMAGER_STATE_STOP_AT_ROW, NULL); + cci_write(mira220->regmap, MIRA220_IMAGER_STATE_REG, + MIRA220_IMAGER_STATE_STOP_AT_ROW, &ret); + cci_write(mira220->regmap, MIRA220_IMAGER_RUN_REG, + MIRA220_IMAGER_RUN_STOP, &ret); - if (ret) { - dev_err(&client->dev, - "Error setting stop-at-row imager state after multiple attempts. Exiting."); - return ret; - } - - ret = cci_write(mira220->regmap, MIRA220_IMAGER_RUN_REG, - MIRA220_IMAGER_RUN_STOP, NULL); - if (ret) { - dev_err(&client->dev, "Error setting run reg to stop"); - return ret; - } + return ret; +} - fsleep(40000); +/* + * Returns the exposure in lines. Calculation is baded on Mira220 datasheet + * Section 9.2. + */ +static u32 mira220_calc_exposure(struct mira220 *mira220, u32 height, u32 vblank) +{ + u32 max_exposure = (height + vblank) - + (MIRA220_GLOB_NUM_CLK_CYCLES / + mira220_min_row_length(mira220)); - return ret; + return min(max_exposure, MIRA220_MAX_EXPOSURE); } -// Returns the maximum exposure time in row_length (reg value). -// Calculation is baded on Mira220 datasheet Section 9.2. -static u32 mira220_calculate_max_exposure_time(u32 height, u32 vblank, - u32 row_length) +static u32 mira220_calc_min_vblank(struct mira220 *mira220) { - return (height + vblank) - - (int)(MIRA220_GLOB_NUM_CLK_CYCLES / row_length); + return (MIRA220_GLOB_NUM_CLK_CYCLES / mira220_min_row_length(mira220)) + + MIRA220_MIN_VBLANK_MARGIN; } static int mira220_write_exposure_reg(struct mira220 *mira220, u32 exposure) { struct i2c_client *const client = v4l2_get_subdevdata(&mira220->sd); - const u32 max_exposure = mira220_calculate_max_exposure_time( - mira220->mode->height, mira220->vblank->val, - mira220->mode->row_length); - u32 ret = 0; - - u32 capped_exposure = exposure; - - if (exposure > max_exposure) - capped_exposure = max_exposure; - - - ret = cci_write(mira220->regmap, MIRA220_EXP_TIME_REG, capped_exposure, - NULL); - + int ret; + ret = cci_write(mira220->regmap, MIRA220_EXP_TIME_REG, exposure, NULL); if (ret) { dev_err_ratelimited(&client->dev, "Error setting exposure time to %d", - capped_exposure); - return -EINVAL; + exposure); + return ret; } return 0; @@ -1242,59 +1151,63 @@ static u32 mira220_get_format_code(struct mira220 *mira220, u32 code) { unsigned int i; - for (i = 0; i < ARRAY_SIZE(mira220_mbus_formats); i++) - if (mira220_mbus_formats[i] == code) - break; + if (mira220_is_mono(mira220)) { + for (i = 0; i < ARRAY_SIZE(mira220_mbus_mono_formats); i++) { + if (mira220_mbus_mono_formats[i] == code) + return mira220_mbus_mono_formats[i]; + } - if (i >= ARRAY_SIZE(mira220_mbus_formats)) - i = 0; + return mira220_mbus_mono_formats[0]; + } - i = (i & ~3) | (mira220->vflip->val ? 2 : 0) | (mira220->hflip->val ? 0 : 1); + for (i = 0; i < ARRAY_SIZE(mira220_mbus_color_formats); i++) { + if (mira220_mbus_color_formats[i] == code) + break; + } + if (i >= ARRAY_SIZE(mira220_mbus_color_formats)) + i = 0; + i = mira220_flip_format_index(mira220, i); - return mira220_mbus_formats[i]; + return mira220_mbus_color_formats[i]; } - static int mira220_set_ctrl(struct v4l2_ctrl *ctrl) { struct mira220 *mira220 = container_of(ctrl->handler, struct mira220, ctrl_handler); struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); + struct v4l2_mbus_framefmt *format; + struct v4l2_subdev_state *state; int ret = 0; + state = v4l2_subdev_get_locked_active_state(&mira220->sd); + format = v4l2_subdev_state_get_format(state, 0); + if (ctrl->id == V4L2_CID_VBLANK) { int exposure_max, exposure_def; /* Update max exposure while meeting expected vblanking */ - exposure_max = mira220_calculate_max_exposure_time( - mira220->mode->height, ctrl->val, - mira220->mode->row_length); - exposure_def = (exposure_max < MIRA220_DEFAULT_EXPOSURE) ? - exposure_max : - MIRA220_DEFAULT_EXPOSURE; - __v4l2_ctrl_modify_range(mira220->exposure, - mira220->exposure->minimum, - exposure_max, mira220->exposure->step, - exposure_def); + exposure_max = mira220_calc_exposure(mira220, format->height, + ctrl->val); + exposure_def = min(exposure_max, MIRA220_DEFAULT_EXPOSURE); + ret = __v4l2_ctrl_modify_range(mira220->exposure, + mira220->exposure->minimum, + exposure_max, + mira220->exposure->step, + exposure_def); + if (ret) + return ret; } - /* - * Applying V4L2 control value only happens - * when power is up for streaming - */ + /* Update the format code to adjust it to the new flip state. */ + if (ctrl->id == V4L2_CID_VFLIP || ctrl->id == V4L2_CID_HFLIP) + format->code = mira220_get_format_code(mira220, format->code); - if (pm_runtime_get_if_in_use(&client->dev) == 0) { - dev_info( - &client->dev, - "device in use, ctrl(id:0x%x,val:0x%x) is not handled\n", - ctrl->id, ctrl->val); + if (!pm_runtime_get_if_in_use(&client->dev)) return 0; - } switch (ctrl->id) { - case V4L2_CID_ANALOGUE_GAIN: - break; case V4L2_CID_EXPOSURE: ret = mira220_write_exposure_reg(mira220, ctrl->val); break; @@ -1303,20 +1216,16 @@ static int mira220_set_ctrl(struct v4l2_ctrl *ctrl) mira220_test_pattern_val[ctrl->val], NULL); break; case V4L2_CID_HFLIP: - ret = cci_write(mira220->regmap, MIRA220_HFLIP_REG, mira220->hflip->val, - NULL); + ret = cci_write(mira220->regmap, MIRA220_HFLIP_REG, + mira220->hflip->val, NULL); break; - case V4L2_CID_VFLIP: - ret = cci_write(mira220->regmap, MIRA220_VFLIP_REG, mira220->vflip->val, - NULL); + ret = cci_write(mira220->regmap, MIRA220_VFLIP_REG, + mira220->vflip->val, NULL); break; case V4L2_CID_VBLANK: ret = cci_write(mira220->regmap, MIRA220_VBLANK_REG, ctrl->val, NULL); - - break; - case V4L2_CID_HBLANK: break; default: dev_info(&client->dev, @@ -1326,7 +1235,7 @@ static int mira220_set_ctrl(struct v4l2_ctrl *ctrl) break; } - pm_runtime_put(&client->dev); + pm_runtime_put_autosuspend(&client->dev); return ret; } @@ -1335,15 +1244,19 @@ static const struct v4l2_ctrl_ops mira220_ctrl_ops = { .s_ctrl = mira220_set_ctrl, }; - static void mira220_update_pad_format(struct mira220 *mira220, - const struct mira220_mode *mode, - struct v4l2_mbus_framefmt *fmt, u32 code) + struct v4l2_mbus_framefmt *fmt, u32 code) { /* Bayer order varies with flips */ fmt->code = mira220_get_format_code(mira220, code); - fmt->width = mode->width; - fmt->height = mode->height; + /* + * The mira220 sensor doesn't support binning/skipping but only + * cropping to reduce the frame size so the correct API to configure + * windowing is the .set_selection one, while format is fixed to + * the full resolution 1600x1400 one. + */ + fmt->width = MIRA220_PIXEL_ARRAY_WIDTH; + fmt->height = MIRA220_PIXEL_ARRAY_HEIGHT; fmt->field = V4L2_FIELD_NONE; fmt->colorspace = V4L2_COLORSPACE_RAW; fmt->ycbcr_enc = V4L2_YCBCR_ENC_601; @@ -1356,81 +1269,51 @@ static int mira220_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_format *fmt) { struct mira220 *mira220 = to_mira220(sd); - const struct mira220_mode *mode; - struct v4l2_mbus_framefmt *format; struct v4l2_rect *crop; + u32 min_vblank; + int ret; - u32 max_exposure = 0, default_exp = 0; - - // /* Validate format or use default */ - - - mode = v4l2_find_nearest_size(supported_modes, - ARRAY_SIZE(supported_modes), width, - height, fmt->format.width, - fmt->format.height); - - mira220_update_pad_format(mira220, mode, &fmt->format, fmt->format.code); - - format = v4l2_subdev_state_get_format(state, 0); - *format = fmt->format; + mira220_update_pad_format(mira220, &fmt->format, fmt->format.code); + *v4l2_subdev_state_get_format(state, 0) = fmt->format; crop = v4l2_subdev_state_get_crop(state, 0); - crop->width = format->width * 1; - crop->height = format->height * 1; + crop->width = fmt->format.width; + crop->height = fmt->format.height; crop->left = MIRA220_PIXEL_ARRAY_LEFT; crop->top = MIRA220_PIXEL_ARRAY_TOP; - if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { - // mira220->fmt = fmt->format; - // mira220->mode = mode; - - // Update controls based on new mode (range and current value). - max_exposure = mira220_calculate_max_exposure_time( - mira220->mode->height, mira220->mode->min_vblank, - mira220->mode->row_length); - default_exp = (max_exposure < MIRA220_DEFAULT_EXPOSURE) ? - max_exposure : - MIRA220_DEFAULT_EXPOSURE; - __v4l2_ctrl_modify_range(mira220->exposure, - MIRA220_EXPOSURE_MIN, max_exposure, 1, - default_exp); - - // Update pixel rate based on new mode. - __v4l2_ctrl_modify_range(mira220->pixel_rate, - mira220->mode->pixel_rate, - mira220->mode->pixel_rate, 1, - mira220->mode->pixel_rate); - - // Update hblank based on new mode. - __v4l2_ctrl_modify_range(mira220->hblank, mira220->mode->hblank, - mira220->mode->hblank, 1, - mira220->mode->hblank); - - __v4l2_ctrl_modify_range(mira220->vblank, - mira220->mode->min_vblank, - mira220->mode->max_vblank, 1, - mira220->mode->min_vblank); - - __v4l2_ctrl_s_ctrl(mira220->vblank, mira220->mode->min_vblank); - } + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) + return 0; - return 0; + /* Update vblank based on new mode. */ + min_vblank = mira220_calc_min_vblank(mira220); + ret = __v4l2_ctrl_modify_range(mira220->vblank, min_vblank, + MIRA220_MAX_VBLANK, 1, min_vblank); + if (ret) + return ret; + + return __v4l2_ctrl_s_ctrl(mira220->vblank, min_vblank); } -// This function should enumerate all the media bus formats for the requested pads. If the requested -// format index is beyond the number of avaialble formats it shall return -EINVAL; static int mira220_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_mbus_code_enum *code) { struct mira220 *mira220 = to_mira220(sd); + bool mono = mira220_is_mono(mira220); + unsigned int num_formats; + unsigned int index; + const u32 *codes; - if (code->index >= (ARRAY_SIZE(mira220_mbus_formats) / 4)) + num_formats = mono ? ARRAY_SIZE(mira220_mbus_mono_formats) : + (ARRAY_SIZE(mira220_mbus_color_formats) / 4); + + if (code->index >= num_formats) return -EINVAL; - code->code = mira220_get_format_code( - mira220, mira220_mbus_formats[code->index * 4]); + index = mono ? code->index : (code->index * 4); + codes = mono ? mira220_mbus_mono_formats : mira220_mbus_color_formats; + code->code = mira220_get_format_code(mira220, codes[index]); return 0; } @@ -1442,19 +1325,18 @@ static int mira220_enum_frame_size(struct v4l2_subdev *sd, struct mira220 *mira220 = to_mira220(sd); u32 code; - if (fse->index >= ARRAY_SIZE(supported_modes)) + if (fse->index) return -EINVAL; code = mira220_get_format_code(mira220, fse->code); if (fse->code != code) return -EINVAL; - fse->min_width = supported_modes[fse->index].width; + fse->min_width = MIRA220_PIXEL_ARRAY_WIDTH; fse->max_width = fse->min_width; - fse->min_height = supported_modes[fse->index].height; + fse->min_height = MIRA220_PIXEL_ARRAY_HEIGHT; fse->max_height = fse->min_height; - return 0; } @@ -1466,8 +1348,8 @@ static int mira220_init_state(struct v4l2_subdev *sd, .pad = 0, .format = { .code = MEDIA_BUS_FMT_SGRBG12_1X12, - .width = supported_modes[0].width, - .height = supported_modes[0].height, + .width = MIRA220_PIXEL_ARRAY_WIDTH, + .height = MIRA220_PIXEL_ARRAY_HEIGHT, }, }; @@ -1476,16 +1358,35 @@ static int mira220_init_state(struct v4l2_subdev *sd, return 0; } +static int mira220_set_bus_config(struct mira220 *mira220) +{ + int ret = 0; + + cci_write(mira220->regmap, MIRA220_MIPI_LANES_REG, + mira220->lanes - 1, &ret); + + cci_write(mira220->regmap, MIRA220_MIPI_CLK_MODE_REG, + MIRA220_MIPI_CLK_CONTINUOUS, &ret); + + return ret; +} static int mira220_set_framefmt(struct mira220 *mira220, - struct v4l2_subdev_state *state) + struct v4l2_subdev_state *state) { const struct v4l2_mbus_framefmt *format; - const struct v4l2_rect *crop; + u32 top, left; int ret = 0; format = v4l2_subdev_state_get_format(state, 0); - crop = v4l2_subdev_state_get_crop(state, 0); + + /* Program the image format bit order, bit depth and CSI-2 data type */ + + ret = cci_write(mira220->regmap, MIRA220_BIT_ORDER_REG, + MIRA220_BIT_ORDER_NORMAL, NULL); + if (ret) + return ret; + switch (format->code) { case MEDIA_BUS_FMT_Y8_1X8: case MEDIA_BUS_FMT_SRGGB8_1X8: @@ -1493,9 +1394,9 @@ static int mira220_set_framefmt(struct mira220 *mira220, case MEDIA_BUS_FMT_SGBRG8_1X8: case MEDIA_BUS_FMT_SBGGR8_1X8: cci_write(mira220->regmap, MIRA220_BIT_DEPTH_REG, - MIRA220_BIT_DEPTH_8_BIT, NULL); + MIRA220_BIT_DEPTH_8_BIT, &ret); cci_write(mira220->regmap, MIRA220_CSI_DATA_TYPE_REG, - MIRA220_CSI_DATA_TYPE_8_BIT, NULL); + MIRA220_CSI_DATA_TYPE_8_BIT, &ret); break; case MEDIA_BUS_FMT_Y10_1X10: case MEDIA_BUS_FMT_SRGGB10_1X10: @@ -1503,9 +1404,9 @@ static int mira220_set_framefmt(struct mira220 *mira220, case MEDIA_BUS_FMT_SGBRG10_1X10: case MEDIA_BUS_FMT_SBGGR10_1X10: cci_write(mira220->regmap, MIRA220_BIT_DEPTH_REG, - MIRA220_BIT_DEPTH_10_BIT, NULL); + MIRA220_BIT_DEPTH_10_BIT, &ret); cci_write(mira220->regmap, MIRA220_CSI_DATA_TYPE_REG, - MIRA220_CSI_DATA_TYPE_10_BIT, NULL); + MIRA220_CSI_DATA_TYPE_10_BIT, &ret); break; case MEDIA_BUS_FMT_Y12_1X12: @@ -1514,29 +1415,52 @@ static int mira220_set_framefmt(struct mira220 *mira220, case MEDIA_BUS_FMT_SBGGR12_1X12: case MEDIA_BUS_FMT_SRGGB12_1X12: cci_write(mira220->regmap, MIRA220_BIT_DEPTH_REG, - MIRA220_BIT_DEPTH_12_BIT, NULL); + MIRA220_BIT_DEPTH_12_BIT, &ret); cci_write(mira220->regmap, MIRA220_CSI_DATA_TYPE_REG, - MIRA220_CSI_DATA_TYPE_12_BIT, NULL); + MIRA220_CSI_DATA_TYPE_12_BIT, &ret); break; default: - ret = -EINVAL; - break; + ret = -EINVAL; + break; } + if (ret) + return ret; + + /* Program the sensor's row length. */ + ret = cci_write(mira220->regmap, MIRA220_REG_ROW_LENGTH, + mira220_min_row_length(mira220), NULL); + if (ret) + return ret; + + /* + * Program the ROI area, centered in the sensor's pixel array. + * + * TODO: Use the crop rectangle sizes once the driver is ported to the + * new RAW camera sensor model. + */ + top = (MIRA220_PIXEL_ARRAY_HEIGHT - format->height) / 2; + left = (MIRA220_PIXEL_ARRAY_WIDTH - format->width) / 2; + + cci_write(mira220->regmap, MIRA220_VSTART_REG, top, &ret); + cci_write(mira220->regmap, MIRA220_HSTART_REG, + left & MIRA220_HSTART_MASK, &ret); + cci_write(mira220->regmap, MIRA220_VSIZE_REG, format->height, &ret); + cci_write(mira220->regmap, MIRA220_HSIZE_REG, + (format->width / 2) & MIRA220_HSIZE_MASK, &ret); + cci_write(mira220->regmap, MIRA220_MIPI_HSIZE_REG, format->width, &ret); return ret; } - static int mira220_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { switch (sel->target) { - case V4L2_SEL_TGT_CROP: { + case V4L2_SEL_TGT_CROP: sel->r = *v4l2_subdev_state_get_crop(state, 0); return 0; - } case V4L2_SEL_TGT_NATIVE_SIZE: sel->r.top = 0; @@ -1557,175 +1481,267 @@ static int mira220_get_selection(struct v4l2_subdev *sd, return -EINVAL; } -static int mira220_start_streaming(struct mira220 *mira220, - struct v4l2_subdev_state *state) +/* OTP power on */ +static int mira220_otp_power_on(struct mira220 *mira220) { - struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); - const struct mira220_reg_list *reg_list; - int ret; - /* Follow examples of other camera driver, here use pm_runtime_resume_and_get */ + int ret = cci_write(mira220->regmap, MIRA220_OTP_CMD_REG, + MIRA220_OTP_CMD_UP, NULL); + fsleep(100); - ret = pm_runtime_resume_and_get(&client->dev); + return ret; +} - if (ret < 0) { - pm_runtime_put_noidle(&client->dev); - return ret; - } +/* OTP power off */ +static int mira220_otp_power_off(struct mira220 *mira220) +{ + return cci_write(mira220->regmap, MIRA220_OTP_CMD_REG, + MIRA220_OTP_CMD_DOWN, NULL); +} - /* Apply default values of current mode */ - /* Stop treaming before uploading register sequence */ - ret = mira220_write_stop_streaming_regs(mira220); - if (ret) { - dev_err(&client->dev, "Could not write stream-on sequence"); - goto err_rpm_put; - } +/* OTP power on */ +static int mira220_otp_read(struct mira220 *mira220, u8 addr, u8 offset, + u8 *val, int *err) +{ + u64 readback; + int ret = 0; - reg_list = &mira220->mode->reg_list; - ret = cci_multi_reg_write(mira220->regmap, reg_list->regs, - reg_list->num_of_regs, NULL); - if (ret) { - dev_err(&client->dev, "%s failed to set mode\n", __func__); - goto err_rpm_put; - } + if (err && *err) + return *err; - ret = mira220_set_framefmt(mira220, state); - if (ret) { - dev_err(&client->dev, "%s failed to set frame format: %d\n", - __func__, ret); - goto err_rpm_put; - } - - /* Apply customized values from user */ - ret = __v4l2_ctrl_handler_setup(mira220->sd.ctrl_handler); + cci_write(mira220->regmap, CCI_REG8(0x0086), addr, &ret); + cci_write(mira220->regmap, CCI_REG8(0x0080), 0x02, &ret); + cci_read(mira220->regmap, CCI_REG8(0x0082 + offset), &readback, &ret); if (ret) - goto err_rpm_put; + goto out; - ret = mira220_write_start_streaming_regs(mira220); - if (ret) { - dev_err(&client->dev, "Could not write stream-on sequence"); - goto err_rpm_put; - } - /* vflip and hflip cannot change during streaming */ - __v4l2_ctrl_grab(mira220->hflip, true); - __v4l2_ctrl_grab(mira220->vflip, true); + *val = readback & 0xFF; return 0; -err_rpm_put: - pm_runtime_put(&client->dev); +out: + if (err) + *err = ret; return ret; } -static void mira220_stop_streaming(struct mira220 *mira220) +/* Verify chip ID, module version, unique ID and variant */ +static int mira220_identify_module(struct mira220 *mira220) { struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); - int ret = 0; + u8 b0, b1, b2, b3, b4, b5, b6, b7; + u32 variant; + int ret; + u8 val; + u8 id; - ret = mira220_write_stop_streaming_regs(mira220); - if (ret) { + ret = mira220_otp_power_on(mira220); + if (ret) + return ret; + + /* Log module version checks */ + mira220_otp_read(mira220, 0x0d, 0, &val, &ret); + mira220_otp_read(mira220, 0x1e, 0, &val, &ret); + if (ret) + goto err_power_off; + + /* Check unique module hardware ID version */ + ret = mira220_otp_read(mira220, 0x3a, 0, &id, NULL); + if (ret) + goto err_power_off; + + if (id < 1 || id > 2) { dev_err(&client->dev, - "Could not write the stream-off sequence"); + "Read OTP 0x3a, id must be 1 or 2, but got: 0x%02x\n", id); + ret = -EINVAL; + goto err_power_off; } - __v4l2_ctrl_grab(mira220->hflip, false); - __v4l2_ctrl_grab(mira220->vflip, false); - pm_runtime_put(&client->dev); -} -static int mira220_set_stream(struct v4l2_subdev *sd, int enable) -{ - struct mira220 *mira220 = to_mira220(sd); - struct v4l2_subdev_state *state; - int ret = 0; + /* Read Unique ID bytes sequentially using the correct 4-argument signature */ + mira220_otp_read(mira220, 0x25, 0, &b0, &ret); + mira220_otp_read(mira220, 0x1e, 0, &b1, &ret); + mira220_otp_read(mira220, 0x1e, 1, &b2, &ret); + mira220_otp_read(mira220, 0x1e, 2, &b3, &ret); + mira220_otp_read(mira220, 0x1d, 0, &b4, &ret); + mira220_otp_read(mira220, 0x1d, 1, &b5, &ret); + mira220_otp_read(mira220, 0x1d, 2, &b6, &ret); + mira220_otp_read(mira220, 0x1d, 3, &b7, &ret); + if (ret) + goto err_power_off; + + dev_dbg(&client->dev, "Unique ID: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", + b7, b6, b5, b4, b3, b2, b1, b0); - state = v4l2_subdev_lock_and_get_active_state(sd); + mira220_otp_read(mira220, 0x3e, 0, &b0, &ret); + mira220_otp_read(mira220, 0x3e, 1, &b1, &ret); + mira220_otp_read(mira220, 0x3e, 2, &b2, &ret); + mira220_otp_read(mira220, 0x3e, 3, &b3, &ret); + if (ret) + goto err_power_off; - if (enable) - ret = mira220_start_streaming(mira220, state); - else - mira220_stop_streaming(mira220); + variant = b0 | b1 << 8 | b2 << 16 | b3 << 24; - v4l2_subdev_unlock_state(state); + switch (variant) { + case MIRA220_MONO_PLAIN_PF: + case MIRA220_MONO_PLAIN_NO_PF: + case MIRA220_MONO_AR_PF: + dev_dbg(&client->dev, "Mira220 MONO variant: %x\n", variant); + mira220->variant = MIRA220_VARIANT_MONO; + break; + case MIRA220_RGB_PLAIN_PF: + case MIRA220_RGB_PLAIN_NO_PF: + case MIRA220_RGB_AR_PF: + dev_dbg(&client->dev, "Mira220 RGB variant: %x\n", variant); + mira220->variant = MIRA220_VARIANT_RGB; + break; + default: + dev_info(&client->dev, + "Unsupported mira220 variant %x; default to RGB\n", + variant); + mira220->variant = MIRA220_VARIANT_RGB; + break; + } + +err_power_off: + mira220_otp_power_off(mira220); return ret; } -static int mira220_get_regulators(struct mira220 *mira220) +static int mira220_otp_restore(struct mira220 *mira220) { struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); - unsigned int i; + static const u16 reg_list[] = { + 0x4015, 0x4016, 0x4017, 0x4018, 0x403B, 0x4040, 0x4041, 0x4042, + 0x402a, 0x4029, 0x4009 + }; + u8 val; + int ret; - for (i = 0; i < MIRA220_NUM_SUPPLIES; i++) - mira220->supplies[i].supply = mira220_supply_name[i]; + ret = mira220_otp_power_on(mira220); + if (ret) + return ret; - return devm_regulator_bulk_get(&client->dev, MIRA220_NUM_SUPPLIES, - mira220->supplies); -} + /* Write OTP to image sensor when programmed */ + ret = mira220_otp_read(mira220, 0x1d, 0, &val, NULL); + if (ret < 0) { + dev_err(&client->dev, "Failed to read OTP programming status\n"); + goto out; + } -/* OTP power on */ -static void mira220_otp_power_on(struct mira220 *mira220) -{ - int ret; + if (val == 0xff) { + dev_info(&client->dev, "OTP not programmed, skipping calibration\n"); + return mira220_otp_power_off(mira220); + } + + for (unsigned int i = 0; i < ARRAY_SIZE(reg_list); i++) { + ret = mira220_otp_read(mira220, i, 0, &val, NULL); + if (ret < 0) { + dev_err(&client->dev, "Failed to read OTP address %d\n", i); + goto out; + } + ret = cci_write(mira220->regmap, CCI_REG8(reg_list[i]), val, NULL); + if (ret < 0) { + dev_err(&client->dev, + "Failed to write register 0x%04x\n", reg_list[i]); + goto out; + } + dev_dbg(&client->dev, "OTP CALIBRATION: 0x%04x, val=0x%02x\n", + reg_list[i], val); + } + + ret = mira220_otp_read(mira220, 0x0d, 0, &val, NULL); + if (ret < 0) { + dev_err(&client->dev, "Failed to read OTP address 0x0d\n"); + goto out; + } - ret = cci_write(mira220->regmap, MIRA220_OTP_CMD_REG, - MIRA220_OTP_CMD_UP, NULL); + ret = cci_write(mira220->regmap, CCI_REG8(0x403e), val, NULL); + if (ret < 0) + dev_err(&client->dev, "Failed to write register 0x403e\n"); +out: + mira220_otp_power_off(mira220); + return ret; } -/* OTP power off */ -static void mira220_otp_power_off(struct mira220 *mira220) +static int mira220_enable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) { + struct mira220 *mira220 = to_mira220(sd); + struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); int ret; - ret = cci_write(mira220->regmap, MIRA220_OTP_CMD_REG, - MIRA220_OTP_CMD_DOWN, NULL); + ret = pm_runtime_resume_and_get(&client->dev); + if (ret < 0) + return ret; -} + /* + * Apply default values of current mode. Stop streaming before + * uploading register sequence. + */ + if (!ret) + ret = mira220_write_stop_streaming_regs(mira220); + if (!ret) + ret = cci_multi_reg_write(mira220->regmap, mira220_init_reg_list, + ARRAY_SIZE(mira220_init_reg_list), NULL); + if (!ret) + ret = mira220_otp_restore(mira220); + if (!ret) + ret = mira220_set_bus_config(mira220); + if (!ret) + ret = mira220_set_framefmt(mira220, state); -/* OTP power on */ -static int mira220_otp_read(struct mira220 *mira220, u8 addr, u8 offset, - u8 *val) -{ - int ret; - u64 readback; + /* Apply customized values from user */ + if (!ret) + ret = __v4l2_ctrl_handler_setup(mira220->sd.ctrl_handler); + if (!ret) + ret = mira220_write_start_streaming_regs(mira220); - ret = cci_write(mira220->regmap, CCI_REG8(0x0086), addr, NULL); - ret = cci_write(mira220->regmap, CCI_REG8(0x0080), 0x02, NULL); - ret = cci_read(mira220->regmap, CCI_REG8(0x0082 + offset), &readback, - NULL); - *val = readback & 0xFF; + if (ret) + goto err_rpm_put; + + /* vflip and hflip cannot change during streaming */ + __v4l2_ctrl_grab(mira220->hflip, true); + __v4l2_ctrl_grab(mira220->vflip, true); + return 0; + +err_rpm_put: + pm_runtime_put_autosuspend(&client->dev); return ret; } -/* Verify chip ID */ -static int mira220_identify_module(struct mira220 *mira220) +static int mira220_disable_streams(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, u32 pad, + u64 streams_mask) { + struct mira220 *mira220 = to_mira220(sd); struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); - int ret; - u8 val; - mira220_otp_power_on(mira220); + mira220_write_stop_streaming_regs(mira220); - fsleep(100); - - ret = mira220_otp_read(mira220, 0x0d, 0, &val); - dev_err(&client->dev, "Read OTP add 0x0d with val %x\n", val); - ret = mira220_otp_read(mira220, 0x19, 0, &val); - dev_err(&client->dev, "Read OTP add 0x19 with val %x\n", val); - ret = mira220_otp_read(mira220, 0x19, 1, &val); - dev_err(&client->dev, "Read OTP add 0x19+1 with val %x\n", val); + __v4l2_ctrl_grab(mira220->hflip, false); + __v4l2_ctrl_grab(mira220->vflip, false); - mira220_otp_power_off(mira220); + pm_runtime_put_autosuspend(&client->dev); - return ret; + return 0; } -static const struct v4l2_subdev_core_ops mira220_core_ops = { - .subscribe_event = v4l2_ctrl_subdev_subscribe_event, - .unsubscribe_event = v4l2_event_subdev_unsubscribe, -}; +static int mira220_get_regulators(struct mira220 *mira220) +{ + struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); + + for (unsigned int i = 0; i < ARRAY_SIZE(mira220_supplies); i++) + mira220->supplies[i].supply = mira220_supplies[i]; + + return devm_regulator_bulk_get(&client->dev, + ARRAY_SIZE(mira220_supplies), + mira220->supplies); +} static const struct v4l2_subdev_video_ops mira220_video_ops = { - .s_stream = mira220_set_stream, + .s_stream = v4l2_subdev_s_stream_helper, }; static const struct v4l2_subdev_pad_ops mira220_pad_ops = { @@ -1734,10 +1750,11 @@ static const struct v4l2_subdev_pad_ops mira220_pad_ops = { .set_fmt = mira220_set_pad_format, .get_selection = mira220_get_selection, .enum_frame_size = mira220_enum_frame_size, + .enable_streams = mira220_enable_streams, + .disable_streams = mira220_disable_streams, }; static const struct v4l2_subdev_ops mira220_subdev_ops = { - .core = &mira220_core_ops, .video = &mira220_video_ops, .pad = &mira220_pad_ops, }; @@ -1752,82 +1769,78 @@ static int mira220_init_controls(struct mira220 *mira220) struct i2c_client *client = v4l2_get_subdevdata(&mira220->sd); struct v4l2_ctrl_handler *ctrl_hdlr; struct v4l2_fwnode_device_properties props; - int ret; - + struct v4l2_ctrl *link_freq; + struct v4l2_ctrl *hblank; u32 max_exposure = 0; + u32 min_vblank; + u32 hblank_val; + int ret; ctrl_hdlr = &mira220->ctrl_handler; - /* v4l2_ctrl_handler_init gives a hint/guess of the number of v4l2_ctrl_new */ - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 9); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12); if (ret) return ret; - mutex_init(&mira220->mutex); - ctrl_hdlr->lock = &mira220->mutex; /* By default, PIXEL_RATE is read only */ - mira220->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, - V4L2_CID_PIXEL_RATE, - mira220->mode->pixel_rate, - mira220->mode->pixel_rate, 1, - mira220->mode->pixel_rate); + v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, V4L2_CID_PIXEL_RATE, + MIRA220_PIXEL_RATE, MIRA220_PIXEL_RATE, 1, + MIRA220_PIXEL_RATE); + min_vblank = mira220_calc_min_vblank(mira220); mira220->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, V4L2_CID_VBLANK, - mira220->mode->min_vblank, - mira220->mode->max_vblank, 1, - mira220->mode->min_vblank); - - mira220->hblank = - v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, V4L2_CID_HBLANK, - mira220->mode->hblank, mira220->mode->hblank, - 1, mira220->mode->hblank); - - // Exposure is indicated in number of lines here - // Max is determined by vblank + vsize and Tglob. - max_exposure = mira220_calculate_max_exposure_time( - mira220->mode->height, mira220->vblank->val, - mira220->mode->row_length); - - mira220->exposure = - v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, - V4L2_CID_EXPOSURE, MIRA220_EXPOSURE_MIN, - max_exposure, 1, MIRA220_DEFAULT_EXPOSURE); - - mira220->gain = v4l2_ctrl_new_std( - ctrl_hdlr, &mira220_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, - MIRA220_ANALOG_GAIN_MIN, MIRA220_ANALOG_GAIN_MAX, - MIRA220_ANALOG_GAIN_STEP, MIRA220_ANALOG_GAIN_DEFAULT); + min_vblank, MIRA220_MAX_VBLANK, 1, + min_vblank); + + link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, NULL, V4L2_CID_LINK_FREQ, + 0, 0, &mira220_link_freqs[0]); + + /* + * Scale hblank according to the number of enabled data lanes to match + * row_length. + */ + hblank_val = MIRA220_LLP_1600x1400_304 * (2 / mira220->lanes) + - MIRA220_PIXEL_ARRAY_WIDTH; + hblank = v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_HBLANK, hblank_val, + hblank_val, 1, hblank_val); + + /* Max exposure is determined by vblank + vsize and Tglob. */ + max_exposure = mira220_calc_exposure(mira220, + MIRA220_PIXEL_ARRAY_HEIGHT, + min_vblank); + mira220->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, + V4L2_CID_EXPOSURE, + MIRA220_EXPOSURE_MIN, + max_exposure, 1, + MIRA220_DEFAULT_EXPOSURE); + + v4l2_ctrl_new_std(ctrl_hdlr, NULL, V4L2_CID_ANALOGUE_GAIN, + MIRA220_ANALOG_GAIN_MIN, MIRA220_ANALOG_GAIN_MAX, + MIRA220_ANALOG_GAIN_STEP, + MIRA220_ANALOG_GAIN_DEFAULT); mira220->hflip = v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0); - if (mira220->hflip) - mira220->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; mira220->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &mira220_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); - if (mira220->vflip) - mira220->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &mira220_ctrl_ops, V4L2_CID_TEST_PATTERN, ARRAY_SIZE(mira220_test_pattern_menu) - 1, 0, 0, mira220_test_pattern_menu); - if (ctrl_hdlr->error) { - ret = ctrl_hdlr->error; - dev_err(&client->dev, "%s control init failed (%d)\n", __func__, - ret); - goto error; - } + v4l2_fwnode_device_parse(&client->dev, &props); + v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &mira220_ctrl_ops, + &props); - ret = v4l2_fwnode_device_parse(&client->dev, &props); - if (ret) + if (ctrl_hdlr->error) goto error; - ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &mira220_ctrl_ops, - &props); - if (ret) - goto error; + mira220->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + mira220->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; + link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; mira220->sd.ctrl_handler = ctrl_hdlr; @@ -1835,15 +1848,59 @@ static int mira220_init_controls(struct mira220 *mira220) error: v4l2_ctrl_handler_free(ctrl_hdlr); - mutex_destroy(&mira220->mutex); - - return ret; + return ctrl_hdlr->error; } -static void mira220_free_controls(struct mira220 *mira220) +static int mira220_parse_endpoint(struct device *dev, struct mira220 *mira220) { - v4l2_ctrl_handler_free(mira220->sd.ctrl_handler); - mutex_destroy(&mira220->mutex); + struct v4l2_fwnode_endpoint ep_cfg = { + .bus_type = V4L2_MBUS_CSI2_DPHY + }; + struct fwnode_handle *endpoint; + unsigned long bitmap; + int ret; + + endpoint = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev), 0, 0, 0); + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &ep_cfg); + fwnode_handle_put(endpoint); + if (ret) + return dev_err_probe(dev, -EINVAL, "Failed to parse endpoint\n"); + + /* Non-continuous mode not implemented. */ + if (ep_cfg.bus.mipi_csi2.flags & V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK) { + dev_err(dev, "clock non-continuous mode not supported\n"); + ret = -EINVAL; + goto err_ep_free; + } + + /* + * Link frequencies: the driver supports a single link frequency, + * no need to check bitmap after this call. + */ + if (v4l2_link_freq_to_bitmap(dev, ep_cfg.link_frequencies, + ep_cfg.nr_of_link_frequencies, + mira220_link_freqs, + ARRAY_SIZE(mira220_link_freqs), + &bitmap)) { + ret = -EINVAL; + goto err_ep_free; + } + + /* Check the number of MIPI CSI2 data lanes */ + if (ep_cfg.bus.mipi_csi2.num_data_lanes != 1 && + ep_cfg.bus.mipi_csi2.num_data_lanes != 2) { + dev_err(dev, "%u data lanes are not supported\n", + ep_cfg.bus.mipi_csi2.num_data_lanes); + ret = -EINVAL; + goto err_ep_free; + } + + mira220->lanes = ep_cfg.bus.mipi_csi2.num_data_lanes; + +err_ep_free: + v4l2_fwnode_endpoint_free(&ep_cfg); + + return ret; } static int mira220_probe(struct i2c_client *client) @@ -1859,16 +1916,21 @@ static int mira220_probe(struct i2c_client *client) v4l2_i2c_subdev_init(&mira220->sd, client, &mira220_subdev_ops); mira220->sd.internal_ops = &mira220_internal_ops; + ret = mira220_parse_endpoint(dev, mira220); + if (ret) + return ret; + mira220->regmap = devm_cci_regmap_init_i2c(client, 16); if (IS_ERR(mira220->regmap)) return dev_err_probe(dev, PTR_ERR(mira220->regmap), "failed to initialize CCI\n"); + /* Get system clock (xclk) */ - mira220->xclk = devm_clk_get(dev, NULL); - if (IS_ERR(mira220->xclk)) { - dev_err(dev, "failed to get xclk\n"); - return PTR_ERR(mira220->xclk); - } + mira220->xclk = devm_v4l2_sensor_clk_get(dev, NULL); + if (IS_ERR(mira220->xclk)) + return dev_err_probe(dev, PTR_ERR(mira220->xclk), + "failed to get xclk\n"); + mira220->xclk_freq = clk_get_rate(mira220->xclk); if (mira220->xclk_freq != MIRA220_SUPPORTED_XCLK_FREQ) { dev_err(dev, "xclk frequency not supported: %d Hz\n", @@ -1877,44 +1939,39 @@ static int mira220_probe(struct i2c_client *client) } ret = mira220_get_regulators(mira220); - if (ret) { - dev_err(dev, "failed to get regulators\n"); - return ret; - } - - fsleep(10000); + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); - // The sensor must be powered for mira220_identify_module() - // to be able to read the CHIP_ID register + mira220->reset_gpio = devm_gpiod_get_optional(dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(mira220->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(mira220->reset_gpio), + "failed to get reset gpio\n"); - ret = mira220_power_on(dev); + ret = mira220_power_on(dev); if (ret) return ret; - fsleep(100000); + /* Enable runtime PM and power on the device */ + pm_runtime_set_active(dev); + pm_runtime_enable(dev); ret = mira220_identify_module(mira220); if (ret) goto error_power_off; - /* Set default mode to max resolution */ - mira220->mode = &supported_modes[0]; - ret = mira220_init_controls(mira220); if (ret) goto error_power_off; /* Initialize subdev */ mira220->sd.internal_ops = &mira220_internal_ops; - mira220->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | - V4L2_SUBDEV_FL_HAS_EVENTS; + mira220->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; mira220->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; /* Initialize source pads */ mira220->pad.flags = MEDIA_PAD_FL_SOURCE; - - ret = media_entity_pads_init(&mira220->sd.entity, 1, &mira220->pad); if (ret) { dev_err_probe(dev, ret, "failed to init entity pads\n"); @@ -1935,25 +1992,22 @@ static int mira220_probe(struct i2c_client *client) goto error_subdev_cleanup; } - /* Enable runtime PM and turn off the device */ - pm_runtime_set_active(dev); - pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, 1000); + pm_runtime_use_autosuspend(dev); pm_runtime_idle(dev); return 0; error_subdev_cleanup: v4l2_subdev_cleanup(&mira220->sd); - error_media_entity: media_entity_cleanup(&mira220->sd.entity); - error_handler_free: - mira220_free_controls(mira220); - + v4l2_ctrl_handler_free(mira220->sd.ctrl_handler); error_power_off: + pm_runtime_disable(dev); mira220_power_off(dev); - + pm_runtime_set_suspended(dev); return ret; } @@ -1963,29 +2017,33 @@ static void mira220_remove(struct i2c_client *client) struct mira220 *mira220 = to_mira220(sd); v4l2_async_unregister_subdev(sd); + v4l2_subdev_cleanup(&mira220->sd); media_entity_cleanup(&sd->entity); - mira220_free_controls(mira220); + + v4l2_ctrl_handler_free(mira220->sd.ctrl_handler); pm_runtime_disable(&client->dev); - if (!pm_runtime_status_suspended(&client->dev)) + if (!pm_runtime_status_suspended(&client->dev)) { mira220_power_off(&client->dev); - pm_runtime_set_suspended(&client->dev); + pm_runtime_set_suspended(&client->dev); + } } static const struct dev_pm_ops mira220_pm_ops = { - SET_RUNTIME_PM_OPS(mira220_power_off, mira220_power_on, NULL) + SET_RUNTIME_PM_OPS(mira220_power_off, mira220_power_on, NULL) }; static const struct of_device_id mira220_dt_ids[] = { { .compatible = "ams,mira220" }, - { /* sentinel */ } }; + { /* sentinel */ } +}; MODULE_DEVICE_TABLE(of, mira220_dt_ids); static struct i2c_driver mira220_i2c_driver = { .driver = { .name = "mira220", .of_match_table = mira220_dt_ids, - .pm = &mira220_pm_ops, + .pm = pm_ptr(&mira220_pm_ops), }, .probe = mira220_probe, .remove = mira220_remove, @@ -1994,5 +2052,5 @@ static struct i2c_driver mira220_i2c_driver = { module_i2c_driver(mira220_i2c_driver); MODULE_AUTHOR("Philippe Baetens "); -MODULE_DESCRIPTION("ams MIRA220 sensor driver"); +MODULE_DESCRIPTION("ams OSRAM MIRA220 sensor driver"); MODULE_LICENSE("GPL");