CCS driver
Sakari Ailus
maintainerv2 cover CCS driver
Hello everyone,
Here's a set of patches that turn the existing SMIA driver into a MIPI CCS driver while maintaining SMIA support. A number of bugs in the existing code are fixed in this set, too.
The changes at this point are primarily focused on dealing with new mandatory driver features related to PLL configuration (as CCS allows for much more variation there) and things such as integer conversion from U16.U16 format instead of float. There are some other new features as well such as digital gain and support for getting device specific analogue gain coefficients.
A new feature in CCS is CCS static data which makes it possible to obtain sensor's capabilities and limits from a file chosen based on sensor identification. CCS static data is used also for storing MSR registers so supporting new, CCS compliant devices requires no driver changes.
Note that the library as well as the register definitions are dual licensed under GNU GPL v2 OR BSD 3-clause licenses for use outside the Linux kernel.
Also DT bindings are updated accordingly and converted to YAML format.
More information on MIPI CCS can be found here:
<URL:https://www.mipi.org/specifications/camera-command-set>
Comments are welcome.
since v1 (DT bindings):
- Remove DT vendor prefix, use vendor-less compatible string
- Add spec version specific compatible strings together with the generic one
- Add VCore and VIO regulators
- Fix rotation property description
- Use less verbose definition of data-lanes property
- Remove CSI-1 bus; this isn't really there, the old stuff is all CCP2
- Make bus-type a required property
- Use additionalProperties: false on the device
- Fix the example (change compatible string, remove nokia,nvm leftover property)
- Fix MAINTAINERS
since v1 (driver):
- Generate register and limit definitions from source
- Style fixes in ccs-pll.c
- Use correct MODULE_LICENSE in ccs-pll.c
- Support for VCore and VIO regulators
- Remove extra delays from power-up sequence
- Adapt to parsing changes in v4l2_fwnode_endpoint_alloc_parse(), i.e. call it just once. This also fixes parsing bus-type-less DT binaries.
- Fix MAINTAINERS
Sakari Ailus (106):
smiapp: Generate CCS register definitions and limits
smiapp: Use CCS register flags
smiapp: Calculate CCS limit offsets and limit buffer size
smiapp: Remove macros for defining registers, merge definitions
smiapp: Add macros for accessing CCS registers
smiapp: Use MIPI CCS version and manufacturer ID information
smiapp: Read CCS limit values
smiapp: Switch to CCS limits
smiapp: Obtain frame descriptor from CCS limits
smiapp: Use CCS limits in reading data format descriptors
smiapp: Use CCS limits in reading binning capabilities
smiapp: Use CCS registers
smiapp: Remove quirk function for writing a single 8-bit register
smiapp: Rename register access functions
smiapp: Internal rename to CCS
smiapp: Differentiate CCS sensors from SMIA in subdev naming
smiapp: Rename as "ccs"
ccs: Remove profile concept
ccs: Give all subdevs a function
dt-bindings: nokia,smia: Fix link-frequencies documentation
dt-bindings: nokia,smia: Make vana-supply optional
dt-bindings: nokia,smia: Remove nokia,nvm-size property
dt-bindings: nokia,smia: Convert to YAML
dt-bindings: nokia,smia: Use better active polarity for reset
dt-bindings: nokia,smia: Amend SMIA bindings with MIPI CCS support
dt-bindings: mipi-ccs: Add bus-type for C-PHY support
ccs: Request for "reset" GPIO
ccs: Add MIPI CCS compatible strings
ccs: Remove the I²C ID table
ccs: Remove remaining support for platform data
ccs: Make hwcfg part of the device specific struct
ccs: Fix obtaining bus information from firmware
ccs: Add CCS static data parser library
ccs: Combine revision number major and minor into one
ccs: Read CCS static data from firmware binaries
ccs: Stop reading arrays after the first zero
ccs: The functions to get compose or crop rectangle never return NULL
ccs: Replace somewhat harsh internal checks based on BUG with WARN_ON
ccs: Refactor register reading a little
ccs: Make real to integer number conversion optional
ccs: Move limit value real to integer conversion from read to access
time
ccs: Read ireal numbers correctly
smiapp-pll: Rename as ccs-pll
ccs-pll: Fix MODULE_LICENSE
ccs: Change my e-mail address
ccs: Add support for manufacturer regs from sensor and module files
ccs: Use static data read-only registers
ccs: Clean up runtime PM usage
ccs: Wrap long lines, unwrap short ones
ccs: Add device compatible identifiers for telling SMIA and CCS apart
ccs: Use longer pre-I²C sleep for CCS compliant devices
ccs: Remove unnecessary delays from power-up sequence
dt-bindings: mipi,ccs: Don't mention vana voltage
dt-bindings: mipi,ccs: Add vcore and vio supplies
ccs: Use all regulators
ccs-pll: Don't use div_u64 to divide a 32-bit number
ccs-pll: Split limits and PLL configuration into front and back parts
ccs-pll: Use correct VT divisor for calculating VT SYS divisor
ccs-pll: End search if there are no better values available
ccs-pll: Remove parallel bus support
ccs-pll: Differentiate between CSI-2 D-PHY and C-PHY
ccs-pll: Move the flags field down, away from 8-bit fields
ccs-pll: Document the structs in the header as well as the function
ccs-pll: Use the BIT macro
ccs-pll: Begin calculation from OP system clock frequency
ccs-pll: Fix condition for pre-PLL divider lower bound
ccs-pll: Avoid overflow in pre-PLL divisor lower bound search
ccs-pll: Fix comment on check against maximum PLL multiplier
ccs-pll: Fix check for PLL multiplier upper bound
ccs-pll: Use explicit 32-bit unsigned type
ccs-pll: Add support for lane speed model
ccs: Add support for lane speed model
ccs-pll: Add support for decoupled OP domain calculation
ccs-pll: Add support for extended input PLL clock divider
ccs-pll: Support two cycles per pixel on OP domain
ccs-pll: Add support flexible OP PLL pixel clock divider
ccs-pll: Add sanity checks
ccs-pll: Add C-PHY support
ccs-pll: Split off VT subtree calculation
ccs-pll: Check for derating and overrating, support non-derating
sensors
ccs-pll: Better separate OP and VT sub-tree calculation
ccs-pll: Print relevant information on PLL tree
ccs-pll: Rework bounds checks
ccs-pll: Make VT divisors 16-bit
ccs-pll: Fix VT post-PLL divisor calculation
ccs-pll: Separate VT divisor limit calculation from the rest
ccs-pll: Add trivial dual PLL support
ccs: Dual PLL support
ccs-pll: Add support for DDR OP system and pixel clocks
ccs: Add support for DDR OP SYS and OP PIX clocks
ccs: Print written register values
ccs-pll: Print pixel rates
ccs: Add support for obtaining C-PHY configuration from firmware
ccs: Add digital gain support
ccs: Add support for old-style SMIA digital gain
ccs: Remove analogue gain field
ccs: Only add analogue gain control if the device supports it
v4l: uapi: Add user control base for CCS controls
v4l: uapi: ccs: Add controls for analogue gain constants
ccs: Add support for analogue gain coefficient controls
v4l: uapi: ccs: Add controls for CCS alternative analogue gain
ccs: Add support for alternate analogue global gain
ccs: Add debug prints for MSR registers
v4l: uapi: ccs: Add CCS controls for shading correction
ccs: Add shading correction and luminance correction level controls
ccs: Add CCS ACPI device ID
.../bindings/media/i2c/mipi-ccs.yaml | 135 +
.../bindings/media/i2c/nokia,smia.txt | 66 -
MAINTAINERS | 21 +-
drivers/media/i2c/Kconfig | 4 +-
drivers/media/i2c/Makefile | 4 +-
drivers/media/i2c/{smiapp-pll.c => ccs-pll.c} | 1012 ++++---
drivers/media/i2c/{smiapp-pll.h => ccs-pll.h} | 196 +-
drivers/media/i2c/{smiapp => ccs}/Kconfig | 9 +-
drivers/media/i2c/{smiapp => ccs}/Makefile | 18 +-
.../{smiapp/smiapp-core.c => ccs/ccs-core.c} | 2426 ++++++++++-------
drivers/media/i2c/ccs/ccs-data-defs.h | 215 ++
drivers/media/i2c/ccs/ccs-data.c | 949 +++++++
drivers/media/i2c/ccs/ccs-data.h | 116 +
drivers/media/i2c/ccs/ccs-os.h | 15 +
.../smiapp-quirk.c => ccs/ccs-quirk.c} | 105 +-
.../smiapp-quirk.h => ccs/ccs-quirk.h} | 54 +-
.../smiapp-regs.c => ccs/ccs-reg-access.c} | 296 +-
.../smiapp-regs.h => ccs/ccs-reg-access.h} | 40 +-
drivers/media/i2c/ccs/ccs-regs.txt | 1041 +++++++
.../media/i2c/{smiapp/smiapp.h => ccs/ccs.h} | 185 +-
drivers/media/i2c/ccs/mk-ccs-regs | 405 +++
.../smiapp-reg.h => ccs/smiapp-reg-defs.h} | 502 +++-
drivers/media/i2c/smiapp/smiapp-limits.c | 118 -
drivers/media/i2c/smiapp/smiapp-limits.h | 114 -
drivers/media/i2c/smiapp/smiapp-reg-defs.h | 489 ----
include/uapi/linux/ccs.h | 21 +
include/uapi/linux/v4l2-controls.h | 6 +
27 files changed, 6166 insertions(+), 2396 deletions(-)
create mode 100644 Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml
delete mode 100644 Documentation/devicetree/bindings/media/i2c/nokia,smia.txt
rename drivers/media/i2c/{smiapp-pll.c => ccs-pll.c} (16%)
rename drivers/media/i2c/{smiapp-pll.h => ccs-pll.h} (18%)
rename drivers/media/i2c/{smiapp => ccs}/Kconfig (48%)
rename drivers/media/i2c/{smiapp => ccs}/Makefile (14%)
rename drivers/media/i2c/{smiapp/smiapp-core.c => ccs/ccs-core.c} (43%)
create mode 100644 drivers/media/i2c/ccs/ccs-data-defs.h
create mode 100644 drivers/media/i2c/ccs/ccs-data.c
create mode 100644 drivers/media/i2c/ccs/ccs-data.h
create mode 100644 drivers/media/i2c/ccs/ccs-os.h
rename drivers/media/i2c/{smiapp/smiapp-quirk.c => ccs/ccs-quirk.c} (63%)
rename drivers/media/i2c/{smiapp/smiapp-quirk.h => ccs/ccs-quirk.h} (53%)
rename drivers/media/i2c/{smiapp/smiapp-regs.c => ccs/ccs-reg-access.c} (37%)
rename drivers/media/i2c/{smiapp/smiapp-regs.h => ccs/ccs-reg-access.h} (16%)
create mode 100644 drivers/media/i2c/ccs/ccs-regs.txt
rename drivers/media/i2c/{smiapp/smiapp.h => ccs/ccs.h} (52%)
create mode 100644 drivers/media/i2c/ccs/mk-ccs-regs
rename drivers/media/i2c/{smiapp/smiapp-reg.h => ccs/smiapp-reg-defs.h} (10%)
delete mode 100644 drivers/media/i2c/smiapp/smiapp-limits.c
delete mode 100644 drivers/media/i2c/smiapp/smiapp-limits.h
delete mode 100644 drivers/media/i2c/smiapp/smiapp-reg-defs.h
create mode 100644 include/uapi/linux/ccs.hSignature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 21/106 dt-bindings: nokia,smia: Make vana-supply optional
vana-supply is optional in the spec, therefore make it optional in bindings, too.
--- Documentation/devicetree/bindings/media/i2c/nokia,smia.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +2 -2
@@ -16,8 +16,6 @@ Mandatory properties - compatible: "nokia,smia" - reg: I2C address (0x10, or an alternative address) -- vana-supply: Analogue voltage supply (VANA), typically 2,8 volts (sensor - dependent). - clocks: External clock to the sensor - clock-frequency: Frequency of the external clock to the sensor
@@ -31,6 +29,8 @@ Optional properties - rotation: Integer property; valid values are 0 (sensor mounted upright) and 180 (sensor mounted upside down). See ../video-interfaces.txt . +- vana-supply: Analogue voltage supply (VANA), typically 2,8 volts (sensor + dependent). Endpoint node mandatory properties
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 22/106 dt-bindings: nokia,smia: Remove nokia,nvm-size property
In reply to Sakari Ailusnokia,nvm-size property was removed from the bindings but it was left in the example. Remove it from the example, too.
--- Documentation/devicetree/bindings/media/i2c/nokia,smia.txt | 1 - 1 file changed, 1 deletion(-)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +0 -1
@@ -54,7 +54,6 @@ Example vana-supply = <&vaux3>; clocks = <&omap3_isp 0>; clock-frequency = <9600000>; - nokia,nvm-size = <512>; /* 8 * 64 */ port { smiapp_ep: endpoint { data-lanes = <1 2>;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 23/106 dt-bindings: nokia,smia: Convert to YAML
In reply to Sakari AilusConvert nokia,smia DT bindings to YAML.
Also add explicit license to bindings.
--- .../bindings/media/i2c/nokia,smia.txt | 67 ----------- .../bindings/media/i2c/nokia,smia.yaml | 106 ++++++++++++++++++ MAINTAINERS | 2 +- 3 files changed, 107 insertions(+), 68 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/i2c/nokia,smia.txt create mode 100644 Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt deleted +0 -67
@@ -1,67 +0,0 @@ -SMIA/SMIA++ sensor - -SMIA (Standard Mobile Imaging Architecture) is an image sensor standard -defined jointly by Nokia and ST. SMIA++, defined by Nokia, is an extension -of that. These definitions are valid for both types of sensors. - -More detailed documentation can be found in -Documentation/devicetree/bindings/media/video-interfaces.txt . - -The device node should contain a "port" node which may contain one or more -endpoint nodes, in accordance with video interface bindings defined in -Documentation/devicetree/bindings/media/video-interfaces.txt . - -Mandatory properties --------------------- - -- compatible: "nokia,smia" -- reg: I2C address (0x10, or an alternative address) -- clocks: External clock to the sensor -- clock-frequency: Frequency of the external clock to the sensor - - -Optional properties -------------------- - -- reset-gpios: XSHUTDOWN GPIO -- flash-leds: See ../video-interfaces.txt -- lens-focus: See ../video-interfaces.txt -- rotation: Integer property; valid values are 0 (sensor mounted upright) - and 180 (sensor mounted upside down). See - ../video-interfaces.txt . -- vana-supply: Analogue voltage supply (VANA), typically 2,8 volts (sensor - dependent). - - -Endpoint node mandatory properties ----------------------------------- - -- data-lanes: <1..n> -- link-frequencies: List of allowed data link frequencies. An array of - 64-bit elements. - - -Example -------- - -&i2c2 { - clock-frequency = <400000>; - - camera-sensor@10 { - compatible = "nokia,smia"; - reg = <0x10>; - reset-gpios = <&gpio3 20 0>; - vana-supply = <&vaux3>; - clocks = <&omap3_isp 0>; - clock-frequency = <9600000>; - port { - smiapp_ep: endpoint { - data-lanes = <1 2>; - remote-endpoint = <&csi2a_ep>; - link-frequencies = - /bits/ 64 <199200000 210000000 - 499200000>; - }; - }; - }; -};
Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml new file +106 -0
106 lines not on this page · raw message
MAINTAINERS +1 -1
@@ -11564,7 +11564,7 @@ MIPI CCS, SMIA AND SMIA++ IMAGE SENSOR DRIVER M: Sakari Ailus <[email protected]> L: [email protected] S: Maintained -F: Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +F: Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml F: drivers/media/i2c/ccs/ F: drivers/media/i2c/smiapp-pll.c F: drivers/media/i2c/smiapp-pll.h
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 20/106 dt-bindings: nokia,smia: Fix link-frequencies documentation
In reply to Sakari AilusThe link-frequencies property belongs to the endpoint, not to the node representing the device.
--- .../devicetree/bindings/media/i2c/nokia,smia.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +5 -3
@@ -20,8 +20,6 @@ Mandatory properties dependent). - clocks: External clock to the sensor - clock-frequency: Frequency of the external clock to the sensor -- link-frequencies: List of allowed data link frequencies. An array of - 64-bit elements. Optional properties
@@ -39,6 +37,8 @@ Endpoint node mandatory properties ---------------------------------- - data-lanes: <1..n> +- link-frequencies: List of allowed data link frequencies. An array of + 64-bit elements. Example
@@ -55,11 +55,13 @@ Example clocks = <&omap3_isp 0>; clock-frequency = <9600000>; nokia,nvm-size = <512>; /* 8 * 64 */ - link-frequencies = /bits/ 64 <199200000 210000000 499200000>; port { smiapp_ep: endpoint { data-lanes = <1 2>; remote-endpoint = <&csi2a_ep>; + link-frequencies = + /bits/ 64 <199200000 210000000 + 499200000>; }; }; };
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 24/106 dt-bindings: nokia,smia: Use better active polarity for reset
In reply to Sakari AilusGenerally reset signal is active low on camera sensors. The example had it high. Make it low, and use GPIO_ACTIVE_LOW in gpio.h for that.
--- Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml +3 -1
@@ -80,6 +80,8 @@ additionalProperties: false examples: - | + #include <dt-bindings/gpio/gpio.h> + i2c2 { #address-cells = <1>; #size-cells = <0>;
@@ -89,7 +91,7 @@ examples: camera-sensor@10 { compatible = "nokia,smia"; reg = <0x10>; - reset-gpios = <&gpio3 20 0>; + reset-gpios = <&gpio3 20 GPIO_ACTIVE_LOW>; vana-supply = <&vaux3>; clocks = <&omap3_isp 0>; clock-frequency = <9600000>;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 25/106 dt-bindings: nokia,smia: Amend SMIA bindings with MIPI CCS support
In reply to Sakari AilusAmend the existing SMIA bindings by adding MIPI CCS support, with separate compatible strings for CCS 1.0 and CCS 1.1. Rename the old bindings accordingly as CCS is the current standard.
---
.../i2c/{nokia,smia.yaml => mipi-ccs.yaml} | 23 ++++++++++++++-----
MAINTAINERS | 2 +-
2 files changed, 18 insertions(+), 7 deletions(-)
rename Documentation/devicetree/bindings/media/i2c/{nokia,smia.yaml => mipi-ccs.yaml} (81%)Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml renamed from Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml +17 -6
@@ -1,26 +1,37 @@ # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) # Copyright (C) 2014--2020 Intel Corporation -$id: http://devicetree.org/schemas/media/i2c/nokia,smia.yaml# +$id: http://devicetree.org/schemas/media/i2c/mipi-ccs.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: SMIA/SMIA++ sensor +title: MIPI CCS, SMIA++ and SMIA compliant camera sensors maintainers: - Sakari Ailus <[email protected]> description: + CCS (Camera Command Set) is a raw Bayer camera sensor standard defined by the + MIPI Alliance; see + <URL:https://www.mipi.org/specifications/camera-command-set>. + SMIA (Standard Mobile Imaging Architecture) is an image sensor standard defined jointly by Nokia and ST. SMIA++, defined by Nokia, is an extension of - that. These definitions are valid for both types of sensors. + that. More detailed documentation can be found in Documentation/devicetree/bindings/media/video-interfaces.txt . properties: compatible: - const: nokia,smia + oneOf: + - items: + - const: mipi-ccs-1.1 + - const: mipi-ccs + - items: + - const: mipi-ccs-1.0 + - const: mipi-ccs + - const: nokia,smia reg: maxItems: 1
@@ -89,14 +100,14 @@ examples: clock-frequency = <400000>; camera-sensor@10 { - compatible = "nokia,smia"; + compatible = "mipi-ccs-1.0", "mipi-ccs"; reg = <0x10>; reset-gpios = <&gpio3 20 GPIO_ACTIVE_LOW>; vana-supply = <&vaux3>; clocks = <&omap3_isp 0>; clock-frequency = <9600000>; port { - smiapp_ep: endpoint { + ccs_ep: endpoint { data-lanes = <1 2>; remote-endpoint = <&csi2a_ep>; link-frequencies = /bits/ 64 <199200000 210000000
MAINTAINERS +1 -1
@@ -11564,7 +11564,7 @@ MIPI CCS, SMIA AND SMIA++ IMAGE SENSOR DRIVER M: Sakari Ailus <[email protected]> L: [email protected] S: Maintained -F: Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml +F: Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml F: drivers/media/i2c/ccs/ F: drivers/media/i2c/smiapp-pll.c F: drivers/media/i2c/smiapp-pll.h
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 26/106 dt-bindings: mipi-ccs: Add bus-type for C-PHY support
In reply to Sakari AilusThe bus-type property is required for C-PHY support. Add it, including values for CCP2 and CSI-2 D-PHY.
Also require the bus-type property. Effectively all new sensors are MIPI D-PHY or C-PHY that cannot be told apart without the bus-type property.
--- .../devicetree/bindings/media/i2c/mipi-ccs.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml +9 -0
@@ -77,9 +77,17 @@ properties: data-lanes: minItems: 1 maxItems: 8 + bus-type: + description: The type of the data bus. + oneOf: + - const: 1 # CSI-2 C-PHY + - const: 3 # CCP2 + - const: 4 # CSI-2 D-PHY + required: - link-frequencies - data-lanes + - bus-type required: - compatible
@@ -112,6 +120,7 @@ examples: remote-endpoint = <&csi2a_ep>; link-frequencies = /bits/ 64 <199200000 210000000 499200000>; + bus-type = <4>; }; }; };
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 54/106 dt-bindings: mipi,ccs: Add vcore and vio supplies
In reply to Sakari AilusVcore and vio supplies are also part of the spec and used by many sensors. Do not specify the voltages as they are generally sensor dependent.
--- Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml +8 -0
@@ -40,6 +40,14 @@ properties: description: Analogue voltage supply (VANA), sensor dependent. maxItems: 1 + vcore-supply: + description: Core voltage supply (VCore), sensor dependent. + maxItems: 1 + + vio-supply: + description: I/O voltage supply (VIO), sensor dependent. + maxItems: 1 + clocks: description: External clock to the sensor. maxItems: 1
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 53/106 dt-bindings: mipi,ccs: Don't mention vana voltage
In reply to Sakari AilusIt was mentioned vana voltage is typically 2,8 volts. This is truly sensor dependent, and nowadays 2,8 volts is a lot.
--- Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml +1 -2
@@ -37,8 +37,7 @@ properties: maxItems: 1 vana-supply: - description: Analogue voltage supply (VANA), typically 2,8 volts (sensor - dependent). + description: Analogue voltage supply (VANA), sensor dependent. maxItems: 1 clocks:
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 2/106 smiapp: Use CCS register flags
In reply to Sakari AilusUse the CCS register flags instead of the old smia flags. The new flags include the register width information that was separate from the register flags previously.
--- drivers/media/i2c/smiapp/smiapp-reg-defs.h | 8 ++++---- drivers/media/i2c/smiapp/smiapp-regs.c | 20 +++++++++++++------- drivers/media/i2c/smiapp/smiapp-regs.h | 13 ++++--------- 3 files changed, 21 insertions(+), 20 deletions(-)
drivers/media/i2c/smiapp/smiapp-reg-defs.h +4 -4
@@ -7,11 +7,11 @@* Copyright (C) 2011--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */ -#define SMIAPP_REG_MK_U8 (r) ((SMIAPP_REG_8BIT << 16) | (r)) -#define SMIAPP_REG_MK_U16 (r) ((SMIAPP_REG_16BIT << 16) | (r)) -#define SMIAPP_REG_MK_U32 (r) ((SMIAPP_REG_32BIT << 16) | (r)) +#define SMIAPP_REG_MK_U8 (r) (r) +#define SMIAPP_REG_MK_U16 (r) (CCS_FL_16BIT | (r)) +#define SMIAPP_REG_MK_U32 (r) (CCS_FL_32BIT | (r)) -#define SMIAPP_REG_MK_F32 (r) (SMIAPP_REG_FLAG_FLOAT | (SMIAPP_REG_32BIT << 16) | (r)) +#define SMIAPP_REG_MK_F32 (r) (CCS_FL_FLOAT_IREAL | CCS_FL_32BIT | (r))#define SMIAPP_REG_U16_MODEL_ID SMIAPP_REG_MK_U16(0x0000)#define SMIAPP_REG_U8_REVISION_NUMBER_MAJOR SMIAPP_REG_MK_U8(0x0002)
drivers/media/i2c/smiapp/smiapp-regs.c +13 -7
@@ -133,6 +133,16 @@ static int ____smiapp_read_8only(struct smiapp_sensor *sensor, u16 reg,return 0 ; } +unsigned int ccs_reg_width (u32 reg) +{ +if (reg &CCS_FL_16BIT ) +return sizeof (uint16_t ); +if (reg &CCS_FL_32BIT ) +return sizeof (uint32_t ); + +return sizeof (uint8_t ); +} +/* * Read a 8/16/32-bit i2c register. The value is returned in 'val'. * Returns zero if successful, or non-zero otherwise.
@@ -141,13 +151,9 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val, bool only8) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); -u8 len =SMIAPP_REG_WIDTH (reg); +unsigned int len =ccs_reg_width (reg);int rval; -if (len !=SMIAPP_REG_8BIT && len !=SMIAPP_REG_16BIT - && len !=SMIAPP_REG_32BIT ) -return -EINVAL ; -if (!only8) rval =____smiapp_read (sensor,SMIAPP_REG_ADDR (reg), len, val);else
@@ -156,7 +162,7 @@ static int __smiapp_read(struct smiapp_sensor *sensor, u32 reg, u32 *val,if (rval <0 )return rval; -if (reg &SMIAPP_REG_FLAG_FLOAT ) +if (reg &CCS_FL_FLOAT_IREAL ) *val =float_to_u32_mul_1000000 (client, *val);return 0 ;
@@ -204,7 +210,7 @@ int smiapp_write_no_quirk(struct smiapp_sensor *sensor, u32 reg, u32 val)struct i2c_msg msg;unsigned char data[6 ];unsigned int retries; -u8 len =SMIAPP_REG_WIDTH (reg); +unsigned int len =ccs_reg_width (reg);int r;if (len >sizeof (data) -2 )
drivers/media/i2c/smiapp/smiapp-regs.h +4 -9
@@ -14,16 +14,9 @@#include <linux/i2c.h> #include <linux/types.h> -#define SMIAPP_REG_ADDR (reg) ((u16)reg) -#define SMIAPP_REG_WIDTH (reg) ((u8)(reg >> 16)) -#define SMIAPP_REG_FLAGS (reg) ((u8)(reg >> 24)) - -/* Use upper 8 bits of the type field for flags */ -#define SMIAPP_REG_FLAG_FLOAT (1 << 24) +#include "ccs-regs.h" -#define SMIAPP_REG_8BIT 1 -#define SMIAPP_REG_16BIT 2 -#define SMIAPP_REG_32BIT 4 +#define SMIAPP_REG_ADDR (reg) ((u16)reg)struct smiapp_sensor ;
@@ -33,4 +26,6 @@ int smiapp_read_8only(struct smiapp_sensor *sensor, u32 reg, u32 *val);int smiapp_write_no_quirk (struct smiapp_sensor *sensor,u32 reg,u32 val);int smiapp_write (struct smiapp_sensor *sensor,u32 reg,u32 val); +unsigned int ccs_reg_width (u32 reg); +#endif
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 3/106 smiapp: Calculate CCS limit offsets and limit buffer size
In reply to Sakari AilusCalculate the limit offsets and the size of the limit buffer. CCS limits are read into this buffer, and the offsets are helpful in accessing the information in it.
--- drivers/media/i2c/smiapp/smiapp-core.c | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/media/i2c/smiapp/smiapp-core.c +39 -1
@@ -27,6 +27,7 @@#include <media/v4l2-fwnode.h> #include <media/v4l2-device.h> +#include "ccs-limits.h" #include "smiapp.h" #define SMIAPP_ALIGN_DIM (dim, flags) \
@@ -34,6 +35,11 @@ ? ALIGN((dim), 2) \ : (dim) & ~1) +struct ccs_limit_offset { +u16 lim; +u16 info; +} ccs_limit_offsets[CCS_L_LAST +1 ]; +/* * smiapp_module_idents - supported camera modules */
@@ -3166,7 +3172,39 @@ static struct i2c_driver smiapp_i2c_driver = { .id_table = smiapp_id_table, }; -module_i2c_driver (smiapp_i2c_driver); +static int smiapp_module_init (void ) +{ +unsigned int i, l; + +for (i =0 , l =0 ; ccs_limits[i].size && l <CCS_L_LAST ; i++) { +if (!(ccs_limits[i].flags &CCS_L_FL_SAME_REG )) { + ccs_limit_offsets[l +1 ].lim = +ALIGN (ccs_limit_offsets[l].lim + + ccs_limits[i].size, +ccs_reg_width (ccs_limits[i +1 ].reg)); + ccs_limit_offsets[l].info = i; + l++; + }else { + ccs_limit_offsets[l].lim += ccs_limits[i].size; + } + } + +if (WARN_ON (ccs_limits[i].size)) +return -EINVAL ; + +if (WARN_ON (l !=CCS_L_LAST )) +return -EINVAL ; + +return i2c_register_driver (THIS_MODULE , &smiapp_i2c_driver); +} + +static void smiapp_module_cleanup (void ) +{ +i2c_del_driver (&smiapp_i2c_driver); +} + +module_init (smiapp_module_init); +module_exit (smiapp_module_cleanup);MODULE_AUTHOR ("Sakari Ailus <[email protected]>" );MODULE_DESCRIPTION ("Generic SMIA/SMIA++ camera module driver" );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 5/106 smiapp: Add macros for accessing CCS registers
In reply to Sakari AilusAdd two helper macros for reading and writing the CCS registers as defined in ccs-regs.h.
--- drivers/media/i2c/smiapp/smiapp-regs.h | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/media/i2c/smiapp/smiapp-regs.h +6 -0
@@ -28,4 +28,10 @@ int smiapp_write(struct smiapp_sensor *sensor, u32 reg, u32 val);unsigned int ccs_reg_width (u32 reg); +#define ccs_read (sensor, reg_name, val) \ + smiapp_read(sensor, CCS_R_##reg_name, val) + +#define ccs_write (sensor, reg_name, val) \ + smiapp_write(sensor, CCS_R_##reg_name, val) +#endif
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 4/106 smiapp: Remove macros for defining registers, merge definitions
In reply to Sakari AilusRemove macros for defining new SMIA registers, instead put the register flags to the register definition itself. Also move the register flags to the same file.
This is not expected to be updated but rather left there as a reference.
--- drivers/media/i2c/smiapp/smiapp-quirk.c | 2 +- drivers/media/i2c/smiapp/smiapp-reg-defs.h | 1046 +++++++++++--------- drivers/media/i2c/smiapp/smiapp-reg.h | 116 --- drivers/media/i2c/smiapp/smiapp.h | 2 +- 4 files changed, 570 insertions(+), 596 deletions(-) delete mode 100644 drivers/media/i2c/smiapp/smiapp-reg.h
drivers/media/i2c/smiapp/smiapp-quirk.c +1 -1
@@ -14,7 +14,7 @@static int smiapp_write_8 (struct smiapp_sensor *sensor,u16 reg,u8 val) { -return smiapp_write (sensor,SMIAPP_REG_MK_U8 (reg), val); +return smiapp_write (sensor, reg, val); } static int smiapp_write_8s(struct smiapp_sensor *sensor,
drivers/media/i2c/smiapp/smiapp-reg-defs.h +568 -478
1,051 lines not on this page · raw message
drivers/media/i2c/smiapp/smiapp-reg.h deleted +0 -116
116 lines not on this page · raw message
drivers/media/i2c/smiapp/smiapp.h +1 -1
@@ -16,7 +16,7 @@#include <media/v4l2-subdev.h> #include "smiapp-pll.h" -#include "smiapp-reg.h" +#include "smiapp-reg-defs.h" #include "smiapp-regs.h" #include "smiapp-quirk.h"
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 9/106 smiapp: Obtain frame descriptor from CCS limits
In reply to Sakari AilusObtain the frame descriptor from the CCS limits, instead of reading them directly from the frame descriptor registers.
--- drivers/media/i2c/smiapp/smiapp-core.c | 70 +++++++++++--------------- 1 file changed, 30 insertions(+), 40 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +30 -40
@@ -228,34 +228,29 @@ static int ccs_read_all_limits(struct smiapp_sensor *sensor)static int smiapp_read_frame_fmt (struct smiapp_sensor *sensor) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); -u32 fmt_model_type, fmt_model_subtype, ncol_desc, nrow_desc; +u8 fmt_model_type, fmt_model_subtype, ncol_desc, nrow_desc;unsigned int i;int pixel_count =0 ;int line_count =0 ; -int rval; - - rval =smiapp_read (sensor,SMIAPP_REG_U8_FRAME_FORMAT_MODEL_TYPE , - &fmt_model_type); -if (rval) -return rval; - rval =smiapp_read (sensor,SMIAPP_REG_U8_FRAME_FORMAT_MODEL_SUBTYPE , - &fmt_model_subtype); -if (rval) -return rval; + fmt_model_type =CCS_LIM (sensor,FRAME_FORMAT_MODEL_TYPE ); + fmt_model_subtype =CCS_LIM (sensor,FRAME_FORMAT_MODEL_SUBTYPE ); ncol_desc = (fmt_model_subtype - &SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_MASK ) - >>SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NCOLS_SHIFT ; + &CCS_FRAME_FORMAT_MODEL_SUBTYPE_COLUMNS_MASK ) + >>CCS_FRAME_FORMAT_MODEL_SUBTYPE_COLUMNS_SHIFT ; nrow_desc = fmt_model_subtype - &SMIAPP_FRAME_FORMAT_MODEL_SUBTYPE_NROWS_MASK ; + &CCS_FRAME_FORMAT_MODEL_SUBTYPE_ROWS_MASK ;dev_dbg (&client->dev,"format_model_type %s\n" , - fmt_model_type ==SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE + fmt_model_type ==CCS_FRAME_FORMAT_MODEL_TYPE_2_BYTE ?"2 byte" : - fmt_model_type ==SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE + fmt_model_type ==CCS_FRAME_FORMAT_MODEL_TYPE_4_BYTE ?"4 byte" :"is simply bad" ); +dev_dbg (&client->dev,"%u column and %u row descriptors\n" , + ncol_desc, nrow_desc); +for (i =0 ; i < ncol_desc + nrow_desc; i++) {u32 desc;u32 pixelcode;
@@ -264,29 +259,24 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)char *what;u32 reg; -if (fmt_model_type ==SMIAPP_FRAME_FORMAT_MODEL_TYPE_2BYTE ) { - reg =SMIAPP_REG_U16_FRAME_FORMAT_DESCRIPTOR_2 (i); - rval =smiapp_read (sensor, reg, &desc); -if (rval) -return rval; +if (fmt_model_type ==CCS_FRAME_FORMAT_MODEL_TYPE_2_BYTE ) { + desc =CCS_LIM_AT (sensor,FRAME_FORMAT_DESCRIPTOR , i); pixelcode = (desc - &SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_MASK ) - >>SMIAPP_FRAME_FORMAT_DESC_2_PIXELCODE_SHIFT ; - pixels = desc &SMIAPP_FRAME_FORMAT_DESC_2_PIXELS_MASK ; + &CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_MASK ) + >>CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_SHIFT ; + pixels = desc &CCS_FRAME_FORMAT_DESCRIPTOR_PIXELS_MASK ; }else if (fmt_model_type - ==SMIAPP_FRAME_FORMAT_MODEL_TYPE_4BYTE ) { - reg =SMIAPP_REG_U32_FRAME_FORMAT_DESCRIPTOR_4 (i); - rval =smiapp_read (sensor, reg, &desc); -if (rval) -return rval; + ==CCS_FRAME_FORMAT_MODEL_TYPE_4_BYTE ) { + desc =CCS_LIM_AT (sensor,FRAME_FORMAT_DESCRIPTOR_4 , i); pixelcode = (desc - &SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_MASK ) - >>SMIAPP_FRAME_FORMAT_DESC_4_PIXELCODE_SHIFT ; - pixels = desc &SMIAPP_FRAME_FORMAT_DESC_4_PIXELS_MASK ; + &CCS_FRAME_FORMAT_DESCRIPTOR_4_PCODE_MASK ) + >>CCS_FRAME_FORMAT_DESCRIPTOR_4_PCODE_SHIFT ; + pixels = desc & +CCS_FRAME_FORMAT_DESCRIPTOR_4_PIXELS_MASK ; }else { dev_dbg(&client->dev, "invalid frame format model type %d\n",
@@ -300,19 +290,19 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor) which ="rows" ;switch (pixelcode) { -case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED : +case CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_EMBEDDED : what ="embedded" ;break ; -case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DUMMY : +case CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_DUMMY_PIXEL : what ="dummy" ;break ; -case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_BLACK : +case CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_BLACK_PIXEL : what ="black" ;break ; -case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_DARK : +case CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_DARK_PIXEL : what ="dark" ;break ; -case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE : +case CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_VISIBLE_PIXEL : what ="visible" ;break ;default :
@@ -326,7 +316,7 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)if (i < ncol_desc) {if (pixelcode == -SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE ) +CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_VISIBLE_PIXEL ) sensor->visible_pixel_start = pixel_count; pixel_count += pixels;continue ;
@@ -334,13 +324,13 @@ static int smiapp_read_frame_fmt(struct smiapp_sensor *sensor)/* Handle row descriptors */ switch (pixelcode) { -case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_EMBEDDED : +case CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_EMBEDDED :if (sensor->embedded_end)break ; sensor->embedded_start = line_count; sensor->embedded_end = line_count + pixels;break ; -case SMIAPP_FRAME_FORMAT_DESC_PIXELCODE_VISIBLE : +case CCS_FRAME_FORMAT_DESCRIPTOR_PCODE_VISIBLE_PIXEL : sensor->image_start = line_count;break ; }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 8/106 smiapp: Switch to CCS limits
In reply to Sakari AilusUse the CCS limit definitions instead of the SMIA ones. This allows accessing CCS capabilities where needed as well as dropping the old SMIA limits.
--- drivers/media/i2c/smiapp/Makefile | 3 +- drivers/media/i2c/smiapp/smiapp-core.c | 255 ++++++++++------------- drivers/media/i2c/smiapp/smiapp-limits.c | 118 ----------- drivers/media/i2c/smiapp/smiapp-limits.h | 114 ---------- drivers/media/i2c/smiapp/smiapp-quirk.c | 25 +-- drivers/media/i2c/smiapp/smiapp-quirk.h | 3 - drivers/media/i2c/smiapp/smiapp.h | 10 - 7 files changed, 113 insertions(+), 415 deletions(-) delete mode 100644 drivers/media/i2c/smiapp/smiapp-limits.c delete mode 100644 drivers/media/i2c/smiapp/smiapp-limits.h
drivers/media/i2c/smiapp/Makefile +1 -2
@@ -1,7 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only smiapp-objs += smiapp-core.o smiapp-regs.o \ - smiapp-quirk.o smiapp-limits.o \ - ccs-limits.o + smiapp-quirk.o ccs-limits.o obj-$(CONFIG_VIDEO_SMIAPP) += smiapp.o ccflags-y += -I $(srctree)/drivers/media/i2c
drivers/media/i2c/smiapp/smiapp-core.c +105 -150
451 lines not on this page · raw message
drivers/media/i2c/smiapp/smiapp-limits.c deleted +0 -118
118 lines not on this page · raw message
drivers/media/i2c/smiapp/smiapp-limits.h deleted +0 -114
114 lines not on this page · raw message
drivers/media/i2c/smiapp/smiapp-quirk.c +7 -18
@@ -10,6 +10,8 @@#include <linux/delay.h> +#include "ccs-limits.h" +#include "smiapp.h" static int smiapp_write_8 (struct smiapp_sensor *sensor,u16 reg,u8 val)
@@ -36,17 +38,6 @@ static int smiapp_write_8s(struct smiapp_sensor *sensor,return 0 ; } -void smiapp_replace_limit (struct smiapp_sensor *sensor, -u32 limit,u32 val) -{ -struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); - -dev_dbg (&client->dev,"quirk: 0x%8.8x \"%s\" = %d, 0x%x\n" , - smiapp_reg_limits[limit].addr, - smiapp_reg_limits[limit].what, val, val); - sensor->limits[limit] = val; -} -static int jt8ew9_limits (struct smiapp_sensor *sensor) {if (sensor->minfo.revision_number_major <0x03 )
@@ -54,9 +45,8 @@ static int jt8ew9_limits(struct smiapp_sensor *sensor)/* Below 24 gain doesn't have effect at all, */ /* but ~59 is needed for full dynamic range */ -smiapp_replace_limit (sensor,SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MIN ,59 ); -smiapp_replace_limit ( - sensor,SMIAPP_LIMIT_ANALOGUE_GAIN_CODE_MAX ,6000 ); +ccs_replace_limit (sensor,CCS_L_ANALOG_GAIN_CODE_MIN ,0 ,59 ); +ccs_replace_limit (sensor,CCS_L_ANALOG_GAIN_CODE_MAX ,0 ,6000 );return 0 ; }
@@ -126,9 +116,8 @@ const struct smiapp_quirk smiapp_imx125es_quirk = {static int jt8ev1_limits (struct smiapp_sensor *sensor) { -smiapp_replace_limit (sensor,SMIAPP_LIMIT_X_ADDR_MAX ,4271 ); -smiapp_replace_limit (sensor, -SMIAPP_LIMIT_MIN_LINE_BLANKING_PCK_BIN ,184 ); +ccs_replace_limit (sensor,CCS_L_X_ADDR_MAX ,0 ,4271 ); +ccs_replace_limit (sensor,CCS_L_MIN_LINE_BLANKING_PCK_BIN ,0 ,184 );return 0 ; }
@@ -221,7 +210,7 @@ const struct smiapp_quirk smiapp_jt8ev1_quirk = {static int tcm8500md_limits (struct smiapp_sensor *sensor) { -smiapp_replace_limit (sensor,SMIAPP_LIMIT_MIN_PLL_IP_FREQ_HZ ,2700000 ); +ccs_replace_limit (sensor,CCS_L_MIN_PLL_IP_CLK_FREQ_MHZ ,0 ,2700000 );return 0 ; }
drivers/media/i2c/smiapp/smiapp-quirk.h +0 -3
@@ -55,9 +55,6 @@ struct smiapp_reg_8 {u8 val; }; -void smiapp_replace_limit (struct smiapp_sensor *sensor, -u32 limit,u32 val); -#define SMIAPP_MK_QUIRK_REG_8 (_reg, _val) \ { \ .reg = (u16)_reg, \
drivers/media/i2c/smiapp/smiapp.h +0 -10
@@ -84,8 +84,6 @@ struct smiapp_hwconfig {struct smiapp_flash_strobe_parms *strobe_setup; }; -#include "smiapp-limits.h" -struct smiapp_quirk ;#define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)
@@ -167,13 +165,6 @@ struct smiapp_module_info { .flags = 0, \ .name = _name, } -struct smiapp_reg_limits { -u32 addr; -char *what; -}; - -extern struct smiapp_reg_limits smiapp_reg_limits[]; -struct smiapp_csi_data_format {u32 code;u8 width;
@@ -227,7 +218,6 @@ struct smiapp_sensor {struct regulator *vana;struct clk *ext_clk;struct gpio_desc *xshutdown; -u32 limits[SMIAPP_LIMIT_LAST ];void *ccs_limits;u8 nbinning_subtypes;struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES ];
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 10/106 smiapp: Use CCS limits in reading data format descriptors
In reply to Sakari AilusThe CCS limits have the information so use it instead.
--- drivers/media/i2c/smiapp/smiapp-core.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +9 -13
@@ -842,10 +842,7 @@ static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)unsigned int i, pixel_order;int rval; - rval =smiapp_read ( - sensor,SMIAPP_REG_U8_DATA_FORMAT_MODEL_TYPE , &type); -if (rval) -return rval; + type =CCS_LIM (sensor,DATA_FORMAT_MODEL_TYPE );dev_dbg (&client->dev,"data_format_model_type %d\n" , type);
@@ -863,11 +860,11 @@ static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor) pixel_order_str[pixel_order]);switch (type) { -case SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL : +case CCS_DATA_FORMAT_MODEL_TYPE_NORMAL : n =SMIAPP_DATA_FORMAT_MODEL_TYPE_NORMAL_N ;break ; -case SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED : - n =SMIAPP_DATA_FORMAT_MODEL_TYPE_EXTENDED_N ; +case CCS_DATA_FORMAT_MODEL_TYPE_EXTENDED : + n =CCS_LIM_DATA_FORMAT_DESCRIPTOR_MAX_N +1 ;break ;default :return -EINVAL ;
@@ -879,11 +876,7 @@ static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)for (i =0 ; i < n; i++) {unsigned int fmt, j; - rval =smiapp_read ( - sensor, -SMIAPP_REG_U16_DATA_FORMAT_DESCRIPTOR (i), &fmt); -if (rval) -return rval; + fmt =CCS_LIM_AT (sensor,DATA_FORMAT_DESCRIPTOR , i);dev_dbg (&client->dev,"%u: bpp %u, compressed %u\n" , i, fmt >>8 , (u8 )fmt);
@@ -895,7 +888,10 @@ static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)if (f->pixel_order !=SMIAPP_PIXEL_ORDER_GRBG )continue ; -if (f->width != fmt >>8 || f->compressed != (u8 )fmt) +if (f->width != fmt >> +CCS_DATA_FORMAT_DESCRIPTOR_UNCOMPRESSED_SHIFT || + f->compressed != + (fmt &CCS_DATA_FORMAT_DESCRIPTOR_COMPRESSED_MASK ))continue ;dev_dbg (&client->dev,"jolly good! %d\n" , j);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 13/106 smiapp: Remove quirk function for writing a single 8-bit register
In reply to Sakari AilusThis function is no longer needed as the smiapp_write() function can be used to write 8-bit registers with plain register addresses.
--- drivers/media/i2c/smiapp/smiapp-quirk.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/media/i2c/smiapp/smiapp-quirk.c +5 -10
@@ -14,11 +14,6 @@#include "smiapp.h" -static int smiapp_write_8 (struct smiapp_sensor *sensor,u16 reg,u8 val) -{ -return smiapp_write (sensor, reg, val); -} -static int smiapp_write_8s (struct smiapp_sensor *sensor,const struct smiapp_reg_8 *regs,int len) {
@@ -26,7 +21,7 @@ static int smiapp_write_8s(struct smiapp_sensor *sensor,int rval;for (; len >0 ; len--, regs++) { - rval =smiapp_write_8 (sensor, regs->reg, regs->val); + rval =smiapp_write (sensor, regs->reg, regs->val);if (rval <0 ) { dev_err(&client->dev, "error %d writing reg 0x%4.4x, val 0x%2.2x",
@@ -170,7 +165,7 @@ static int jt8ev1_post_poweron(struct smiapp_sensor *sensor)static int jt8ev1_pre_streamon (struct smiapp_sensor *sensor) { -return smiapp_write_8 (sensor,0x3328 ,0x00 ); +return smiapp_write (sensor,0x3328 ,0x00 ); }static int jt8ev1_post_streamoff (struct smiapp_sensor *sensor)
@@ -178,7 +173,7 @@ static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)int rval;/* Workaround: allows fast standby to work properly */ - rval =smiapp_write_8 (sensor,0x3205 ,0x04 ); + rval =smiapp_write (sensor,0x3205 ,0x04 );if (rval <0 )return rval;
@@ -186,11 +181,11 @@ static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)usleep_range (2000 ,2050 );/* Restore it */ - rval =smiapp_write_8 (sensor,0x3205 ,0x00 ); + rval =smiapp_write (sensor,0x3205 ,0x00 );if (rval <0 )return rval; -return smiapp_write_8 (sensor,0x3328 ,0x80 ); +return smiapp_write (sensor,0x3328 ,0x80 ); }static int jt8ev1_init (struct smiapp_sensor *sensor)
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 28/106 ccs: Add MIPI CCS compatible strings
In reply to Sakari AilusAdd "mipi-ccs-1.0" and "mipi-ccs-1.1" compatible strings to the CCS driver.
--- drivers/media/i2c/ccs/ccs-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +3 -0
@@ -3236,6 +3236,9 @@ static int ccs_remove(struct i2c_client *client) }static const struct of_device_id ccs_of_table[] = { + { .compatible ="mipi-ccs-1.1" }, + { .compatible ="mipi-ccs-1.0" }, + { .compatible ="mipi-ccs" }, { .compatible ="nokia,smia" }, { }, };
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 19/106 ccs: Give all subdevs a function
In reply to Sakari AilusThis removes a warning at driver probe time telling that one or two entities have no function set. The function used for both the binner and scaler is the scaler.
--- drivers/media/i2c/ccs/ccs-core.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +8 -6
@@ -2685,7 +2685,7 @@ static void ccs_cleanup(struct ccs_sensor *sensor)static void ccs_create_subdev (struct ccs_sensor *sensor,struct ccs_subdev *ssd,const char *name, -unsigned short num_pads) +unsigned short num_pads,u32 function) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);
@@ -2696,6 +2696,7 @@ static void ccs_create_subdev(struct ccs_sensor *sensor,v4l2_subdev_init (&ssd->sd, &ccs_ops); ssd->sd.flags |=V4L2_SUBDEV_FL_HAS_DEVNODE ; + ssd->sd.entity.function = function; ssd->sensor = sensor; ssd->npads = num_pads;
@@ -3123,11 +3124,12 @@ static int ccs_probe(struct i2c_client *client) sensor->pll.ext_clk_freq_hz = sensor->hwcfg->ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN ); -ccs_create_subdev (sensor, sensor->scaler," scaler" ,2 ); -ccs_create_subdev (sensor, sensor->binner," binner" ,2 ); -ccs_create_subdev (sensor, sensor->pixel_array," pixel_array" ,1 ); - - sensor->pixel_array->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; +ccs_create_subdev (sensor, sensor->scaler," scaler" ,2 , +MEDIA_ENT_F_CAM_SENSOR ); +ccs_create_subdev (sensor, sensor->binner," binner" ,2 , +MEDIA_ENT_F_PROC_VIDEO_SCALER ); +ccs_create_subdev (sensor, sensor->pixel_array," pixel_array" ,1 , +MEDIA_ENT_F_PROC_VIDEO_SCALER ); rval =ccs_init_controls (sensor);if (rval <0 )
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 30/106 ccs: Remove remaining support for platform data
In reply to Sakari AilusNo need to support platform data; remove support for conveying hardware configuration that way.
--- drivers/media/i2c/ccs/ccs-core.c | 3 --- 1 file changed, 3 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +0 -3
@@ -2854,9 +2854,6 @@ static struct ccs_hwconfig *ccs_get_hwconfig(struct device *dev)int i;int rval; -if (!fwnode) -return dev->platform_data; - ep =fwnode_graph_get_next_endpoint (fwnode,NULL );if (!ep)return NULL ;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 32/106 ccs: Fix obtaining bus information from firmware
In reply to Sakari AilusLet v4l2_fwnode_endpoint_alloc_parse to figure out the type of the data bus. As the old bindings did not require the "bus-type" property, we need to rely on guessing between CSI-2 D-PHY and CCP2. Setting the type to CSI-2 D-PHY will parse just that and succeed even if no data-lanes are set.
Also add a comment on the matter to the driver to avoid breaking this in the future.
--- drivers/media/i2c/ccs/ccs-core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +6 -7
@@ -2847,7 +2847,7 @@ static int __maybe_unused ccs_resume(struct device *dev)static int ccs_get_hwconfig (struct ccs_sensor *sensor,struct device *dev) {struct ccs_hwconfig *hwcfg = &sensor->hwcfg; -struct v4l2_fwnode_endpoint bus_cfg = { .bus_type =0 }; +struct v4l2_fwnode_endpoint bus_cfg = { .bus_type =V4L2_MBUS_UNKNOWN };struct fwnode_handle *ep;struct fwnode_handle *fwnode =dev_fwnode (dev);u32 rotation;
@@ -2858,13 +2858,11 @@ static int ccs_get_hwconfig(struct ccs_sensor *sensor, struct device *dev)if (!ep)return -ENODEV ; - bus_cfg.bus_type =V4L2_MBUS_CSI2_DPHY ; +/* +* Note that we do need to rely on detecting the bus type between CSI-2 +* D-PHY and CCP2 as the old bindings did not require it. +*/ rval =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg); -if (rval == -ENXIO ) { - bus_cfg = (struct v4l2_fwnode_endpoint ) - { .bus_type =V4L2_MBUS_CCP2 }; - rval =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg); - }if (rval) goto out_err;
@@ -2873,6 +2871,7 @@ static int ccs_get_hwconfig(struct ccs_sensor *sensor, struct device *dev) hwcfg->csi_signalling_mode =CCS_CSI_SIGNALING_MODE_CSI_2_DPHY ; hwcfg->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;break ; +case V4L2_MBUS_CSI1 :case V4L2_MBUS_CCP2 : hwcfg->csi_signalling_mode = (bus_cfg.bus.mipi_csi1.strobe) ? SMIAPP_CSI_SIGNALLING_MODE_CCP2_DATA_STROBE :
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 31/106 ccs: Make hwcfg part of the device specific struct
In reply to Sakari AilusThere's no need to allocate the hardware configuration struct separately. Put it in struct ccs_sensor.
--- drivers/media/i2c/ccs/ccs-core.c | 94 ++++++++++++++++--------------- drivers/media/i2c/ccs/ccs-quirk.c | 4 +- drivers/media/i2c/ccs/ccs.h | 2 +- 3 files changed, 51 insertions(+), 49 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +48 -46
@@ -803,7 +803,7 @@ static int ccs_init_late_controls(struct ccs_sensor *sensor) sensor->link_freq =v4l2_ctrl_new_int_menu ( &sensor->src->ctrl_handler, &ccs_ctrl_ops,V4L2_CID_LINK_FREQ ,__fls (*valid_link_freqs), -__ffs (*valid_link_freqs), sensor->hwcfg->op_sys_clock); +__ffs (*valid_link_freqs), sensor->hwcfg.op_sys_clock);return sensor->src->ctrl_handler.error; }
@@ -916,8 +916,8 @@ static int ccs_get_mbus_formats(struct ccs_sensor *sensor) pll->bits_per_pixel = f->compressed; -for (j =0 ; sensor->hwcfg->op_sys_clock[j]; j++) { - pll->link_freq = sensor->hwcfg->op_sys_clock[j]; +for (j =0 ; sensor->hwcfg.op_sys_clock[j]; j++) { + pll->link_freq = sensor->hwcfg.op_sys_clock[j]; rval =ccs_pll_try (sensor, pll); dev_dbg(&client->dev, "link freq %u Hz, bpp %u %s\n",
@@ -1117,21 +1117,21 @@ static int ccs_change_cci_addr(struct ccs_sensor *sensor)int rval;u32 val; - client->addr = sensor->hwcfg->i2c_addr_dfl; + client->addr = sensor->hwcfg.i2c_addr_dfl; rval =ccs_write (sensor,CCI_ADDRESS_CTRL , - sensor->hwcfg->i2c_addr_alt <<1 ); + sensor->hwcfg.i2c_addr_alt <<1 );if (rval)return rval; - client->addr = sensor->hwcfg->i2c_addr_alt; + client->addr = sensor->hwcfg.i2c_addr_alt;/* verify addr change went ok */ rval =ccs_read (sensor,CCI_ADDRESS_CTRL , &val);if (rval)return rval; -if (val != sensor->hwcfg->i2c_addr_alt <<1 ) +if (val != sensor->hwcfg.i2c_addr_alt <<1 )return -ENODEV ;return 0 ;
@@ -1145,13 +1145,13 @@ static int ccs_change_cci_addr(struct ccs_sensor *sensor)static int ccs_setup_flash_strobe (struct ccs_sensor *sensor) {struct ccs_flash_strobe_parms *strobe_setup; -unsigned int ext_freq = sensor->hwcfg->ext_clk; +unsigned int ext_freq = sensor->hwcfg.ext_clk;u32 tmp;u32 strobe_adjustment;u32 strobe_width_high_rs;int rval; - strobe_setup = sensor->hwcfg->strobe_setup; + strobe_setup = sensor->hwcfg.strobe_setup;/* * How to calculate registers related to strobe length. Please
@@ -1259,7 +1259,7 @@ static int ccs_setup_flash_strobe(struct ccs_sensor *sensor) rval =ccs_write (sensor,FLASH_TRIGGER_RS , strobe_setup->trigger); out: - sensor->hwcfg->strobe_setup->trigger =0 ; + sensor->hwcfg.strobe_setup->trigger =0 ;return rval; }
@@ -1298,7 +1298,7 @@ static int ccs_power_on(struct device *dev)gpiod_set_value (sensor->reset,0 );gpiod_set_value (sensor->xshutdown,1 ); - sleep =SMIAPP_RESET_DELAY (sensor->hwcfg->ext_clk); + sleep =SMIAPP_RESET_DELAY (sensor->hwcfg.ext_clk);usleep_range (sleep, sleep);/*
@@ -1312,7 +1312,7 @@ static int ccs_power_on(struct device *dev)* is found. */ -if (sensor->hwcfg->i2c_addr_alt) { +if (sensor->hwcfg.i2c_addr_alt) { rval =ccs_change_cci_addr (sensor);if (rval) {dev_err (dev,"cci address change error\n" );
@@ -1326,7 +1326,7 @@ static int ccs_power_on(struct device *dev) goto out_cci_addr_fail; } -if (sensor->hwcfg->i2c_addr_alt) { +if (sensor->hwcfg.i2c_addr_alt) { rval =ccs_change_cci_addr (sensor);if (rval) {dev_err (dev,"cci address change error\n" );
@@ -1342,13 +1342,13 @@ static int ccs_power_on(struct device *dev) } rval =ccs_write (sensor,EXTCLK_FREQUENCY_MHZ , - sensor->hwcfg->ext_clk / (1000000 / (1 <<8 ))); + sensor->hwcfg.ext_clk / (1000000 / (1 <<8 )));if (rval) {dev_err (dev,"extclk frequency set failed\n" ); goto out_cci_addr_fail; } - rval =ccs_write (sensor,CSI_LANE_MODE , sensor->hwcfg->lanes -1 ); + rval =ccs_write (sensor,CSI_LANE_MODE , sensor->hwcfg.lanes -1 );if (rval) {dev_err (dev,"csi lane mode set failed\n" ); goto out_cci_addr_fail;
@@ -1362,7 +1362,7 @@ static int ccs_power_on(struct device *dev) } rval =ccs_write (sensor,CSI_SIGNALING_MODE , - sensor->hwcfg->csi_signalling_mode); + sensor->hwcfg.csi_signalling_mode);if (rval) {dev_err (dev,"csi signalling mode set failed\n" ); goto out_cci_addr_fail;
@@ -1406,7 +1406,7 @@ static int ccs_power_off(struct device *dev)* really see a power off and next time the cci address change * will fail. So do a soft reset explicitly here. */ -if (sensor->hwcfg->i2c_addr_alt) +if (sensor->hwcfg.i2c_addr_alt)ccs_write (sensor,SOFTWARE_RESET ,CCS_SOFTWARE_RESET_ON );gpiod_set_value (sensor->reset,1 );
@@ -1545,8 +1545,8 @@ static int ccs_start_streaming(struct ccs_sensor *sensor)if (CCS_LIM (sensor,FLASH_MODE_CAPABILITY ) & (CCS_FLASH_MODE_CAPABILITY_SINGLE_STROBE |SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE ) && - sensor->hwcfg->strobe_setup !=NULL && - sensor->hwcfg->strobe_setup->trigger !=0 ) { + sensor->hwcfg.strobe_setup !=NULL && + sensor->hwcfg.strobe_setup->trigger !=0 ) { rval =ccs_setup_flash_strobe (sensor);if (rval) goto out;
@@ -2844,9 +2844,9 @@ static int __maybe_unused ccs_resume(struct device *dev)return rval; } -static struct ccs_hwconfig *ccs_get_hwconfig (struct device *dev) +static int ccs_get_hwconfig (struct ccs_sensor *sensor,struct device *dev) { -struct ccs_hwconfig *hwcfg; +struct ccs_hwconfig *hwcfg = &sensor->hwcfg;struct v4l2_fwnode_endpoint bus_cfg = { .bus_type =0 };struct fwnode_handle *ep;struct fwnode_handle *fwnode =dev_fwnode (dev);
@@ -2856,7 +2856,7 @@ static struct ccs_hwconfig *ccs_get_hwconfig(struct device *dev) ep =fwnode_graph_get_next_endpoint (fwnode,NULL );if (!ep) -return NULL ; +return -ENODEV ; bus_cfg.bus_type =V4L2_MBUS_CSI2_DPHY ; rval =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg);
@@ -2868,10 +2868,6 @@ static struct ccs_hwconfig *ccs_get_hwconfig(struct device *dev)if (rval) goto out_err; - hwcfg =devm_kzalloc (dev,sizeof (*hwcfg),GFP_KERNEL ); -if (!hwcfg) - goto out_err; -switch (bus_cfg.bus_type) {case V4L2_MBUS_CSI2_DPHY : hwcfg->csi_signalling_mode =CCS_CSI_SIGNALING_MODE_CSI_2_DPHY ;
@@ -2885,6 +2881,7 @@ static struct ccs_hwconfig *ccs_get_hwconfig(struct device *dev)break ;default :dev_err (dev,"unsupported bus %u\n" , bus_cfg.bus_type); + rval = -EINVAL ; goto out_err; }
@@ -2901,6 +2898,7 @@ static struct ccs_hwconfig *ccs_get_hwconfig(struct device *dev)break ;default :dev_err (dev,"invalid rotation %u\n" , rotation); + rval = -EINVAL ; goto out_err; } }
@@ -2915,14 +2913,17 @@ static struct ccs_hwconfig *ccs_get_hwconfig(struct device *dev)if (!bus_cfg.nr_of_link_frequencies) {dev_warn (dev,"no link frequencies defined\n" ); + rval = -EINVAL ; goto out_err; } hwcfg->op_sys_clock =devm_kcalloc ( dev, bus_cfg.nr_of_link_frequencies +1 /* guardian */ ,sizeof (*hwcfg->op_sys_clock),GFP_KERNEL ); -if (!hwcfg->op_sys_clock) +if (!hwcfg->op_sys_clock) { + rval = -ENOMEM ; goto out_err; + }for (i =0 ; i < bus_cfg.nr_of_link_frequencies; i++) { hwcfg->op_sys_clock[i] = bus_cfg.link_frequencies[i];
@@ -2931,29 +2932,30 @@ static struct ccs_hwconfig *ccs_get_hwconfig(struct device *dev)v4l2_fwnode_endpoint_free (&bus_cfg);fwnode_handle_put (ep); -return hwcfg; + +return 0 ; out_err:v4l2_fwnode_endpoint_free (&bus_cfg);fwnode_handle_put (ep); -return NULL ; + +return rval; }static int ccs_probe (struct i2c_client *client) {struct ccs_sensor *sensor; -struct ccs_hwconfig *hwcfg =ccs_get_hwconfig (&client->dev);unsigned int i;int rval; -if (hwcfg ==NULL ) -return -ENODEV ; - sensor =devm_kzalloc (&client->dev,sizeof (*sensor),GFP_KERNEL );if (sensor ==NULL )return -ENOMEM ; - sensor->hwcfg = hwcfg; + rval =ccs_get_hwconfig (sensor, &client->dev); +if (rval) +return rval; + sensor->src = &sensor->ssds[sensor->ssds_used];v4l2_i2c_subdev_init (&sensor->src->sd, client, &ccs_ops);
@@ -2976,33 +2978,33 @@ static int ccs_probe(struct i2c_client *client) }if (sensor->ext_clk) { -if (sensor->hwcfg->ext_clk) { +if (sensor->hwcfg.ext_clk) {unsigned long rate; rval =clk_set_rate (sensor->ext_clk, - sensor->hwcfg->ext_clk); + sensor->hwcfg.ext_clk);if (rval <0 ) {dev_err (&client->dev,"unable to set clock freq to %u\n" , - sensor->hwcfg->ext_clk); + sensor->hwcfg.ext_clk);return rval; } rate =clk_get_rate (sensor->ext_clk); -if (rate != sensor->hwcfg->ext_clk) { +if (rate != sensor->hwcfg.ext_clk) {dev_err (&client->dev,"can't set clock freq, asked for %u but got %lu\n" , - sensor->hwcfg->ext_clk, rate); + sensor->hwcfg.ext_clk, rate);return rval; } }else { - sensor->hwcfg->ext_clk =clk_get_rate (sensor->ext_clk); + sensor->hwcfg.ext_clk =clk_get_rate (sensor->ext_clk);dev_dbg (&client->dev,"obtained clock freq %u\n" , - sensor->hwcfg->ext_clk); + sensor->hwcfg.ext_clk); } - }else if (sensor->hwcfg->ext_clk) { + }else if (sensor->hwcfg.ext_clk) {dev_dbg (&client->dev,"assuming clock freq %u\n" , - sensor->hwcfg->ext_clk); + sensor->hwcfg.ext_clk); }else {dev_err (&client->dev,"unable to obtain clock freq\n" );return -EINVAL ;
@@ -3055,7 +3057,7 @@ static int ccs_probe(struct i2c_client *client)* * Rotation also changes the bayer pattern. */ -if (sensor->hwcfg->module_board_orient == +if (sensor->hwcfg.module_board_orient ==CCS_MODULE_BOARD_ORIENT_180 ) sensor->hvflip_inv_mask = CCS_IMAGE_ORIENTATION_HORIZONTAL_MIRROR |
@@ -3127,8 +3129,8 @@ static int ccs_probe(struct i2c_client *client)/* prepare PLL configuration input values */ sensor->pll.bus_type =SMIAPP_PLL_BUS_TYPE_CSI2 ; - sensor->pll.csi2.lanes = sensor->hwcfg->lanes; - sensor->pll.ext_clk_freq_hz = sensor->hwcfg->ext_clk; + sensor->pll.csi2.lanes = sensor->hwcfg.lanes; + sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN ); ccs_create_subdev(sensor, sensor->scaler, " scaler", 2,
drivers/media/i2c/ccs/ccs-quirk.c +2 -2
@@ -152,13 +152,13 @@ static int jt8ev1_post_poweron(struct ccs_sensor *sensor)if (rval <0 )return rval; -switch (sensor->hwcfg->ext_clk) { +switch (sensor->hwcfg.ext_clk) {case 9600000 :return ccs_write_addr_8s (sensor, regs_96,ARRAY_SIZE (regs_96));default :dev_warn (&client->dev,"no MSRs for %d Hz ext_clk\n" , - sensor->hwcfg->ext_clk); + sensor->hwcfg.ext_clk);return 0 ; } }
drivers/media/i2c/ccs/ccs.h +1 -1
@@ -215,7 +215,7 @@ struct ccs_sensor {struct ccs_subdev *binner;struct ccs_subdev *scaler;struct ccs_subdev *pixel_array; -struct ccs_hwconfig *hwcfg; +struct ccs_hwconfig hwcfg;struct regulator *vana;struct clk *ext_clk;struct gpio_desc *xshutdown;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 41/106 ccs: Move limit value real to integer conversion from read to access time
In reply to Sakari AilusInstead of converting the limit values at register read time, do that at access time instead.
--- drivers/media/i2c/ccs/ccs-core.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +12 -7
@@ -124,6 +124,7 @@ static u32 ccs_get_limit(struct ccs_sensor *sensor, unsigned int limit, unsigned int offset) { void *ptr; +u32 val;int ret; ret =ccs_limit_ptr (sensor, limit, offset, &ptr);
@@ -132,16 +133,20 @@ static u32 ccs_get_limit(struct ccs_sensor *sensor,switch (ccs_reg_width (ccs_limits[ccs_limit_offsets[limit].info].reg)) {case sizeof (u8): -return *(u8 *)ptr; + val = *(u8 *)ptr; +break ;case sizeof (u16): -return *(u16 *)ptr; + val = *(u16 *)ptr; +break ;case sizeof (u32): -return *(u32 *)ptr; + val = *(u32 *)ptr; +break ; +default : +WARN_ON (1 ); +return 0 ; } -WARN_ON (1 ); - -return 0 ; +return ccs_reg_conv (sensor, ccs_limits[limit].reg, val); }#define CCS_LIM (sensor, limit) \
@@ -182,7 +187,7 @@ static int ccs_read_all_limits(struct ccs_sensor *sensor) j++, reg += width, ptr += width) {u32 val; - ret =ccs_read_addr (sensor, reg, &val); + ret =ccs_read_addr_noconv (sensor, reg, &val);if (ret) goto out_err;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 45/106 ccs: Change my e-mail address
In reply to Sakari AilusUse my @linux.intel.com e-mail address in the CCS driver.
--- drivers/media/i2c/ccs-pll.c | 4 ++-- drivers/media/i2c/ccs-pll.h | 2 +- drivers/media/i2c/ccs/ccs-core.c | 6 +++--- drivers/media/i2c/ccs/ccs-quirk.c | 2 +- drivers/media/i2c/ccs/ccs-quirk.h | 2 +- drivers/media/i2c/ccs/ccs-reg-access.c | 2 +- drivers/media/i2c/ccs/ccs-reg-access.h | 2 +- drivers/media/i2c/ccs/ccs.h | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-)
drivers/media/i2c/ccs-pll.c +2 -2
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> */ #include <linux/device.h>
@@ -475,6 +475,6 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits, }EXPORT_SYMBOL_GPL (ccs_pll_calculate); -MODULE_AUTHOR ("Sakari Ailus <[email protected]>" ); +MODULE_AUTHOR ("Sakari Ailus <[email protected]>" );MODULE_DESCRIPTION ("Generic MIPI CCS/SMIA/SMIA++ PLL calculator" );MODULE_LICENSE ("GPL v2" );
drivers/media/i2c/ccs-pll.h +1 -1
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> */ #ifndef CCS_PLL_H
drivers/media/i2c/ccs/ccs-core.c +3 -3
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2010--2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> * * Based on smiapp driver by Vimarsh Zutshi * Based on jt8ev1.c by Vimarsh Zutshi
@@ -1162,7 +1162,7 @@ static int ccs_setup_flash_strobe(struct ccs_sensor *sensor)* do not change, or if you do at least know what you're * doing. :-) * -* Sakari Ailus <[email protected]> 2010-10-25 +* Sakari Ailus <[email protected]> 2010-10-25 * * flash_strobe_length [us] / 10^6 = (tFlash_strobe_width_ctrl * / EXTCLK freq [Hz]) * flash_strobe_adjustment
@@ -3323,7 +3323,7 @@ static void ccs_module_cleanup(void)module_init (ccs_module_init);module_exit (ccs_module_cleanup); -MODULE_AUTHOR ("Sakari Ailus <[email protected]>" ); +MODULE_AUTHOR ("Sakari Ailus <[email protected]>" );MODULE_DESCRIPTION ("Generic MIPI CCS/SMIA/SMIA++ camera sensor driver" );MODULE_LICENSE ("GPL v2" );MODULE_ALIAS ("smiapp" );
drivers/media/i2c/ccs/ccs-quirk.c +1 -1
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> */ #include <linux/delay.h>
drivers/media/i2c/ccs/ccs-quirk.h +1 -1
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> */ #ifndef __CCS_QUIRK__
drivers/media/i2c/ccs/ccs-reg-access.c +1 -1
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> */ #include <asm/unaligned.h>
drivers/media/i2c/ccs/ccs-reg-access.h +1 -1
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> */ #ifndef SMIAPP_REGS_H
drivers/media/i2c/ccs/ccs.h +1 -1
@@ -6,7 +6,7 @@* * Copyright (C) 2020 Intel Corporation * Copyright (C) 2010--2012 Nokia Corporation -* Contact: Sakari Ailus <[email protected]> +* Contact: Sakari Ailus <[email protected]> */ #ifndef __CCS_H__
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 42/106 ccs: Read ireal numbers correctly
In reply to Sakari AilusSome limit values are available in q16.q16 format, referred to as 32-bit unsigned ireal in CCS. Read these correctly.
--- drivers/media/i2c/ccs/ccs-core.c | 10 ++-------- drivers/media/i2c/ccs/ccs-reg-access.c | 23 +++++++++++++++++++++-- drivers/media/i2c/ccs/ccs.h | 9 +++++++++ 3 files changed, 32 insertions(+), 10 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +2 -8
@@ -120,8 +120,8 @@ void ccs_replace_limit(struct ccs_sensor *sensor,ccs_assign_limit (ptr,ccs_reg_width (linfo->reg), val); } -static u32 ccs_get_limit (struct ccs_sensor *sensor, -unsigned int limit,unsigned int offset) +u32 ccs_get_limit (struct ccs_sensor *sensor,unsigned int limit, +unsigned int offset) {void *ptr;u32 val;
@@ -149,12 +149,6 @@ static u32 ccs_get_limit(struct ccs_sensor *sensor,return ccs_reg_conv (sensor, ccs_limits[limit].reg, val); } -#define CCS_LIM (sensor, limit) \ - ccs_get_limit(sensor, CCS_L_##limit, 0) - -#define CCS_LIM_AT (sensor, limit, offset) \ - ccs_get_limit(sensor, CCS_L_##limit, CCS_L_##limit##_OFFSET(offset)) -static int ccs_read_all_limits (struct ccs_sensor *sensor) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);
drivers/media/i2c/ccs/ccs-reg-access.c +21 -2
@@ -15,6 +15,7 @@#include <linux/i2c.h> #include "ccs.h" +#include "ccs-limits.h" static uint32_t float_to_u32_mul_1000000 (struct i2c_client *client,uint32_t phloat)
@@ -143,12 +144,30 @@ unsigned int ccs_reg_width(u32 reg)return sizeof (uint8_t ); } +static u32 ireal32_to_u32_mul_1000000 (struct i2c_client *client,u32 val) +{ +if (val >>10 >U32_MAX /15625 ) { +dev_warn (&client->dev,"value %u overflows!\n" , val); +return U32_MAX ; + } + +return ((val >>10 ) *15625 ) + + (val &GENMASK (9 ,0 )) *15625 /1024 ; +} +u32 ccs_reg_conv (struct ccs_sensor *sensor,u32 reg,u32 val) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); -if (reg &CCS_FL_FLOAT_IREAL ) - val =float_to_u32_mul_1000000 (client, val); +if (reg &CCS_FL_FLOAT_IREAL ) { +if (CCS_LIM (sensor,CLOCK_CAPA_TYPE_CAPABILITY ) & +CCS_CLOCK_CAPA_TYPE_CAPABILITY_IREAL ) + val =ireal32_to_u32_mul_1000000 (client, val); +else + val =float_to_u32_mul_1000000 (client, val); + }else if (reg &CCS_FL_IREAL ) { + val =ireal32_to_u32_mul_1000000 (client, val); + }return val; }
drivers/media/i2c/ccs/ccs.h +9 -0
@@ -17,6 +17,7 @@#include <media/v4l2-subdev.h> #include "ccs-data.h" +#include "ccs-limits.h" #include "ccs-quirk.h" #include "ccs-regs.h" #include "ccs-reg-access.h"
@@ -50,6 +51,12 @@#define CCS_DFL_I2C_ADDR (0x20 >> 1)/* Default I2C Address */ #define CCS_ALT_I2C_ADDR (0x6e >> 1)/* Alternate I2C Address */ +#define CCS_LIM (sensor, limit) \ + ccs_get_limit(sensor, CCS_L_##limit, 0) + +#define CCS_LIM_AT (sensor, limit, offset) \ + ccs_get_limit(sensor, CCS_L_##limit, CCS_L_##limit##_OFFSET(offset)) +/* * Sometimes due to board layout considerations the camera module can be * mounted rotated. The typical rotation used is 180 degrees which can be
@@ -277,5 +284,7 @@ struct ccs_sensor {void ccs_replace_limit (struct ccs_sensor *sensor,unsigned int limit,unsigned int offset,u32 val); +u32 ccs_get_limit (struct ccs_sensor *sensor,unsigned int limit, +unsigned int offset);#endif /* __CCS_H__ */
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 50/106 ccs: Add device compatible identifiers for telling SMIA and CCS apart
In reply to Sakari AilusAdd device data specific to DT compatible ID to tell SMIA and CCS devices apart already in power-up.
--- drivers/media/i2c/ccs/ccs-core.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +16 -4
@@ -59,6 +59,12 @@ static const struct ccs_module_ident ccs_module_idents[] = { CCS_IDENT_LQ(0x10, 0x4241, -1, "imx125es", &smiapp_imx125es_quirk), }; +#define CCS_DEVICE_FLAG_IS_SMIA BIT(0) + +struct ccs_device { +unsigned char flags; +}; +/* * * Dynamic Capability Identification
@@ -3276,11 +3282,17 @@ static int ccs_remove(struct i2c_client *client)return 0 ; } +static const struct ccs_device smia_device = { + .flags =CCS_DEVICE_FLAG_IS_SMIA , +}; + +static const struct ccs_device ccs_device = {}; +static const struct of_device_id ccs_of_table[] = { - { .compatible ="mipi-ccs-1.1" }, - { .compatible ="mipi-ccs-1.0" }, - { .compatible ="mipi-ccs" }, - { .compatible ="nokia,smia" }, + { .compatible ="mipi-ccs-1.1" , .data = &ccs_device }, + { .compatible ="mipi-ccs-1.0" , .data = &ccs_device }, + { .compatible ="mipi-ccs" , .data = &ccs_device }, + { .compatible ="nokia,smia" , .data = &smia_device }, { }, };MODULE_DEVICE_TABLE (of, ccs_of_table);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 44/106 ccs-pll: Fix MODULE_LICENSE
In reply to Sakari AilusChange MODULE_LICENSE to "GPL v2" as indicated by the SPDX tag.
--- drivers/media/i2c/ccs-pll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs-pll.c +1 -1
@@ -477,4 +477,4 @@ EXPORT_SYMBOL_GPL(ccs_pll_calculate);MODULE_AUTHOR ("Sakari Ailus <[email protected]>" );MODULE_DESCRIPTION ("Generic MIPI CCS/SMIA/SMIA++ PLL calculator" ); -MODULE_LICENSE ("GPL" ); +MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 51/106 ccs: Use longer pre-I²C sleep for CCS compliant devices
In reply to Sakari AilusLonger idle period is required on I²C bus before the first transaction after lifting xshutdown.
--- drivers/media/i2c/ccs/ccs-core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +6 -1
@@ -1300,6 +1300,7 @@ static int ccs_power_on(struct device *dev)*/ struct ccs_sensor *sensor = container_of(ssd, struct ccs_sensor, ssds[0]); +const struct ccs_device *ccsdev =device_get_match_data (dev);unsigned int sleep;int rval;
@@ -1320,7 +1321,11 @@ static int ccs_power_on(struct device *dev)gpiod_set_value (sensor->reset,0 );gpiod_set_value (sensor->xshutdown,1 ); - sleep =SMIAPP_RESET_DELAY (sensor->hwcfg.ext_clk); +if (ccsdev->flags &CCS_DEVICE_FLAG_IS_SMIA ) + sleep =SMIAPP_RESET_DELAY (sensor->hwcfg.ext_clk); +else + sleep =5000 ; +usleep_range (sleep, sleep);/*
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 43/106 smiapp-pll: Rename as ccs-pll
In reply to Sakari AilusMIPI CCS replaces SMIA and SMIA++ as the current standard. CCS brings new features while existing functionality will be supported. Rename the smiapp-pll as ccs-pll accordingly.
Also add Intel copyright to the files.
---
MAINTAINERS | 4 +-
drivers/media/i2c/Kconfig | 2 +-
drivers/media/i2c/Makefile | 2 +-
drivers/media/i2c/{smiapp-pll.c => ccs-pll.c} | 60 +++++++++----------
drivers/media/i2c/{smiapp-pll.h => ccs-pll.h} | 40 ++++++-------
drivers/media/i2c/ccs/Kconfig | 2 +-
drivers/media/i2c/ccs/ccs-core.c | 18 +++---
drivers/media/i2c/ccs/ccs-quirk.c | 2 +-
drivers/media/i2c/ccs/ccs.h | 4 +-
9 files changed, 66 insertions(+), 68 deletions(-)
rename drivers/media/i2c/{smiapp-pll.c => ccs-pll.c} (90%)
rename drivers/media/i2c/{smiapp-pll.h => ccs-pll.h} (68%)MAINTAINERS +2 -2
@@ -11566,8 +11566,8 @@ L: [email protected] S: Maintained F: Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml F: drivers/media/i2c/ccs/ -F: drivers/media/i2c/smiapp-pll.c -F: drivers/media/i2c/smiapp-pll.h +F: drivers/media/i2c/ccs-pll.c +F: drivers/media/i2c/ccs-pll.h F: include/uapi/linux/smiapp.h MIPS
drivers/media/i2c/Kconfig +1 -1
@@ -722,7 +722,7 @@ menu "Camera sensor devices" config VIDEO_APTINA_PLL tristate -config VIDEO_SMIAPP_PLL +config VIDEO_CCS_PLL tristate config VIDEO_HI556
drivers/media/i2c/Makefile +1 -1
@@ -104,7 +104,7 @@ obj-$(CONFIG_VIDEO_S5C73M3) += s5c73m3/ obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o obj-$(CONFIG_VIDEO_LM3560) += lm3560.o obj-$(CONFIG_VIDEO_LM3646) += lm3646.o -obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o +obj-$(CONFIG_VIDEO_CCS_PLL) += ccs-pll.o obj-$(CONFIG_VIDEO_AK881X) += ak881x.o obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o obj-$(CONFIG_VIDEO_I2C) += video-i2c.o
drivers/media/i2c/ccs-pll.c renamed from drivers/media/i2c/smiapp-pll.c +29 -31
153 lines not on this page · raw message
drivers/media/i2c/ccs-pll.h renamed from drivers/media/i2c/smiapp-pll.h +20 -20
@@ -1,32 +1,33 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* drivers/media/i2c/smiapp-pll.h +* drivers/media/i2c/ccs-pll.h * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic MIPI CCS/SMIA/SMIA++ PLL calculator * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */ -#ifndef SMIAPP_PLL_H -#define SMIAPP_PLL_H +#ifndef CCS_PLL_H +#define CCS_PLL_H /* CSI-2 or CCP-2 */ -#define SMIAPP_PLL_BUS_TYPE_CSI2 0x00 -#define SMIAPP_PLL_BUS_TYPE_PARALLEL 0x01 +#define CCS_PLL_BUS_TYPE_CSI2 0x00 +#define CCS_PLL_BUS_TYPE_PARALLEL 0x01 /* op pix clock is for all lanes in total normally */ -#define SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE (1 << 0) -#define SMIAPP_PLL_FLAG_NO_OP_CLOCKS (1 << 1) +#define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE (1 << 0) +#define CCS_PLL_FLAG_NO_OP_CLOCKS (1 << 1) -struct smiapp_pll_branch { +struct ccs_pll_branch { uint16_t sys_clk_div; uint16_t pix_clk_div; uint32_t sys_clk_freq_hz; uint32_t pix_clk_freq_hz; }; -struct smiapp_pll { +struct ccs_pll { /* input values */ uint8_t bus_type; union {
@@ -51,14 +52,14 @@ struct smiapp_pll {uint16_t pll_multiplier;uint32_t pll_ip_clk_freq_hz;uint32_t pll_op_clk_freq_hz; -struct smiapp_pll_branch vt; -struct smiapp_pll_branch op; +struct ccs_pll_branch vt; +struct ccs_pll_branch op;uint32_t pixel_rate_csi;uint32_t pixel_rate_pixel_array; }; -struct smiapp_pll_branch_limits { +struct ccs_pll_branch_limits {uint16_t min_sys_clk_div;uint16_t max_sys_clk_div;uint32_t min_sys_clk_freq_hz;
@@ -69,7 +70,7 @@ struct smiapp_pll_branch_limits {uint32_t max_pix_clk_freq_hz; }; -struct smiapp_pll_limits { +struct ccs_pll_limits {/* Strict PLL limits */ uint32_t min_ext_clk_freq_hz;uint32_t max_ext_clk_freq_hz;
@@ -82,8 +83,8 @@ struct smiapp_pll_limits {uint32_t min_pll_op_freq_hz;uint32_t max_pll_op_freq_hz; -struct smiapp_pll_branch_limits vt; -struct smiapp_pll_branch_limits op; +struct ccs_pll_branch_limits vt; +struct ccs_pll_branch_limits op;/* Other relevant limits */ uint32_t min_line_length_pck_bin;
@@ -92,8 +93,7 @@ struct smiapp_pll_limits {struct device ; -int smiapp_pll_calculate (struct device *dev, -const struct smiapp_pll_limits *limits, -struct smiapp_pll *pll); +int ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *limits, +struct ccs_pll *pll); -#endif /* SMIAPP_PLL_H */ +#endif /* CCS_PLL_H */
drivers/media/i2c/ccs/Kconfig +1 -1
@@ -4,7 +4,7 @@ config VIDEO_CCS depends on I2C && VIDEO_V4L2 && HAVE_CLK select MEDIA_CONTROLLER select VIDEO_V4L2_SUBDEV_API - select VIDEO_SMIAPP_PLL + select VIDEO_CCS_PLL select V4L2_FWNODE help This is a generic driver for MIPI CCS, SMIA++ and SMIA compliant
drivers/media/i2c/ccs/ccs-core.c +9 -9
@@ -357,7 +357,7 @@ static int ccs_read_frame_fmt(struct ccs_sensor *sensor)static int ccs_pll_configure (struct ccs_sensor *sensor) { -struct smiapp_pll *pll = &sensor->pll; +struct ccs_pll *pll = &sensor->pll;int rval; rval =ccs_write (sensor,VT_PIX_CLK_DIV , pll->vt.pix_clk_div);
@@ -380,7 +380,7 @@ static int ccs_pll_configure(struct ccs_sensor *sensor) rval =ccs_write (sensor,REQUESTED_LINK_RATE ,DIV_ROUND_UP (pll->op.sys_clk_freq_hz,1000000 /256 /256 )); -if (rval <0 || sensor->pll.flags &SMIAPP_PLL_FLAG_NO_OP_CLOCKS ) +if (rval <0 || sensor->pll.flags &CCS_PLL_FLAG_NO_OP_CLOCKS )return rval; rval =ccs_write (sensor,OP_PIX_CLK_DIV , pll->op.pix_clk_div);
@@ -390,10 +390,10 @@ static int ccs_pll_configure(struct ccs_sensor *sensor)return ccs_write (sensor,OP_SYS_CLK_DIV , pll->op.sys_clk_div); } -static int ccs_pll_try (struct ccs_sensor *sensor,struct smiapp_pll *pll) +static int ccs_pll_try (struct ccs_sensor *sensor,struct ccs_pll *pll) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); -struct smiapp_pll_limits lim = { +struct ccs_pll_limits lim = { .min_pre_pll_clk_div =CCS_LIM (sensor,MIN_PRE_PLL_CLK_DIV ), .max_pre_pll_clk_div =CCS_LIM (sensor,MAX_PRE_PLL_CLK_DIV ), .min_pll_ip_freq_hz =CCS_LIM (sensor,MIN_PLL_IP_CLK_FREQ_MHZ ),
@@ -425,12 +425,12 @@ static int ccs_pll_try(struct ccs_sensor *sensor, struct smiapp_pll *pll) .min_line_length_pck = CCS_LIM(sensor, MIN_LINE_LENGTH_PCK), }; -return smiapp_pll_calculate (&client->dev, &lim, pll); +return ccs_pll_calculate (&client->dev, &lim, pll); }static int ccs_pll_update (struct ccs_sensor *sensor) { -struct smiapp_pll *pll = &sensor->pll; +struct ccs_pll *pll = &sensor->pll;int rval; pll->binning_horizontal = sensor->binning_horizontal;
@@ -823,7 +823,7 @@ static void ccs_free_controls(struct ccs_sensor *sensor)static int ccs_get_mbus_formats (struct ccs_sensor *sensor) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); -struct smiapp_pll *pll = &sensor->pll; +struct ccs_pll *pll = &sensor->pll;u8 compressed_max_bpp =0 ;unsigned int type, n;unsigned int i, pixel_order;
@@ -3140,7 +3140,7 @@ static int ccs_probe(struct i2c_client *client) !CCS_LIM(sensor, MIN_OP_PIX_CLK_DIV) || !CCS_LIM(sensor, MAX_OP_PIX_CLK_DIV)) {/* No OP clock branch */ - sensor->pll.flags |=SMIAPP_PLL_FLAG_NO_OP_CLOCKS ; + sensor->pll.flags |=CCS_PLL_FLAG_NO_OP_CLOCKS ; } else if (CCS_LIM(sensor, SCALING_CAPABILITY) != CCS_SCALING_CAPABILITY_NONE || CCS_LIM(sensor, DIGITAL_CROP_CAPABILITY)
@@ -3157,7 +3157,7 @@ static int ccs_probe(struct i2c_client *client) sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN );/* prepare PLL configuration input values */ - sensor->pll.bus_type =SMIAPP_PLL_BUS_TYPE_CSI2 ; + sensor->pll.bus_type =CCS_PLL_BUS_TYPE_CSI2 ; sensor->pll.csi2.lanes = sensor->hwcfg.lanes; sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
drivers/media/i2c/ccs/ccs-quirk.c +1 -1
@@ -190,7 +190,7 @@ static int jt8ev1_post_streamoff(struct ccs_sensor *sensor)static int jt8ev1_init (struct ccs_sensor *sensor) { - sensor->pll.flags |=SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE ; + sensor->pll.flags |=CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE ;return 0 ; }
drivers/media/i2c/ccs/ccs.h +2 -2
@@ -21,7 +21,7 @@#include "ccs-quirk.h" #include "ccs-regs.h" #include "ccs-reg-access.h" -#include "../smiapp-pll.h" +#include "../ccs-pll.h" #include "smiapp-reg-defs.h" /*
@@ -256,7 +256,7 @@ struct ccs_sensor {struct ccs_module_info minfo; -struct smiapp_pll pll; +struct ccs_pll pll;/* Is a default format supported for a given BPP? */ unsigned long *valid_link_freqs;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 56/106 ccs-pll: Don't use div_u64 to divide a 32-bit number
In reply to Sakari Ailuspll->pll_op_clk_freq is a 32-bit number. It does not need div_u64 to divide it.
--- drivers/media/i2c/ccs-pll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs-pll.c +1 -1
@@ -445,7 +445,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits, min_pre_pll_clk_div, max_pre_pll_clk_div); i =gcd (pll->pll_op_clk_freq_hz, pll->ext_clk_freq_hz); - mul =div_u64 (pll->pll_op_clk_freq_hz, i); + mul = pll->pll_op_clk_freq_hz / i; div = pll->ext_clk_freq_hz / i;dev_dbg (dev,"mul %u / div %u\n" , mul, div);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 63/106 ccs-pll: Document the structs in the header as well as the function
In reply to Sakari AilusThe CCS pll is used by the CCS driver at the moment, but documenting the interface makes sense. It's non-trivial and the calculator could be used elsewhere.
--- drivers/media/i2c/ccs-pll.h | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+)
drivers/media/i2c/ccs-pll.h +88 -0
@@ -20,6 +20,16 @@#define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE (1 << 0)#define CCS_PLL_FLAG_NO_OP_CLOCKS (1 << 1) +/** +* struct ccs_pll_branch_fr - CCS PLL configuration (front) +* +* A single branch front-end of the CCS PLL tree. +* +* @pre_pll_clk_div: Pre-PLL clock divisor +* @pll_multiplier: PLL multiplier +* @pll_ip_freq_hz: PLL input clock frequency +* @pll_op_freq_hz: PLL output clock frequency +*/ struct ccs_pll_branch_fr {uint16_t pre_pll_clk_div;uint16_t pll_multiplier;
@@ -27,6 +37,16 @@ struct ccs_pll_branch_fr {uint32_t pll_op_clk_freq_hz; }; +/** +* struct ccs_pll_branch_bk - CCS PLL configuration (back) +* +* A single branch back-end of the CCS PLL tree. +* +* @sys_clk_div: System clock divider +* @pix_clk_div: Pixel clock divider +* @sys_clk_freq_hz: System clock frequency +* @pix_clk_freq_hz: Pixel clock frequency +*/ struct ccs_pll_branch_bk {uint16_t sys_clk_div;uint16_t pix_clk_div;
@@ -34,6 +54,29 @@ struct ccs_pll_branch_bk {uint32_t pix_clk_freq_hz; }; +/** +* struct ccs_pll - Full CCS PLL configuration +* +* All information required to calculate CCS PLL configuration. +* +* @bus_type: Type of the data bus, CCS_PLL_BUS_TYPE_* (input) +* @csi2.lanes: The number of the CSI-2 data lanes (input) +* @binning_vertical: Vertical binning factor (input) +* @binning_horizontal: Horizontal binning factor (input) +* @scale_m: Downscaling factor, M component, [16, max] (input) +* @scale_n: Downscaling factor, N component, typically 16 (input) +* @bits_per_pixel: Bits per pixel on the output data bus (input) +* @flags: CCS_PLL_FLAG_* (input) +* @link_freq: Chosen link frequency (input) +* @ext_clk_freq_hz: External clock frequency, i.e. the sensor's input clock +* (input) +* @vt_fr: Video timing front-end configuration (output) +* @vt_bk: Video timing back-end configuration (output) +* @op_bk: Operational timing back-end configuration (output) +* @pixel_rate_csi: Pixel rate on the output data bus (output) +* @pixel_rate_pixel_array: Nominal pixel rate in the sensor's pixel array +* (output) +*/ struct ccs_pll {/* input values */ uint8_t bus_type;
@@ -58,6 +101,18 @@ struct ccs_pll {uint32_t pixel_rate_pixel_array; }; +/** +* struct ccs_pll_branch_limits_fr - CCS PLL front-end limits +* +* @min_pre_pll_clk_div: Minimum pre-PLL clock divider +* @max_pre_pll_clk_div: Maximum pre-PLL clock divider +* @min_pll_ip_freq_hz: Minimum PLL input clock frequency +* @max_pll_ip_freq_hz: Maximum PLL input clock frequency +* @min_pll_multiplier: Minimum PLL multiplier +* @max_pll_multiplier: Maximum PLL multiplier +* @min_pll_op_freq_hz: Minimum PLL output clock frequency +* @max_pll_op_freq_hz: Maximum PLL output clock frequency +*/ struct ccs_pll_branch_limits_fr {uint16_t min_pre_pll_clk_div;uint16_t max_pre_pll_clk_div;
@@ -69,6 +124,18 @@ struct ccs_pll_branch_limits_fr {uint32_t max_pll_op_clk_freq_hz; }; +/** +* struct ccs_pll_branch_limits_bk - CCS PLL back-end limits +* +* @min_sys_clk_div: Minimum system clock divider +* @max_sys_clk_div: Maximum system clock divider +* @min_sys_clk_freq_hz: Minimum system clock frequency +* @max_sys_clk_freq_hz: Maximum system clock frequency +* @min_pix_clk_div: Minimum pixel clock divider +* @max_pix_clk_div: Maximum pixel clock divider +* @min_pix_clk_freq_hz: Minimum pixel clock frequency +* @max_pix_clk_freq_hz: Maximum pixel clock frequency +*/ struct ccs_pll_branch_limits_bk {uint16_t min_sys_clk_div;uint16_t max_sys_clk_div;
@@ -80,6 +147,17 @@ struct ccs_pll_branch_limits_bk {uint32_t max_pix_clk_freq_hz; }; +/** +* struct ccs_pll_limits - CCS PLL limits +* +* @min_ext_clk_freq_hz: Minimum external clock frequency +* @max_ext_clk_freq_hz: Maximum external clock frequency +* @vt_fr: Video timing front-end limits +* @vt_bk: Video timing back-end limits +* @op_bk: Operational timing back-end limits +* @min_line_length_pck_bin: Minimum line length in pixels, with binning +* @min_line_length_pck: Minimum line length in pixels without binning +*/ struct ccs_pll_limits {/* Strict PLL limits */ uint32_t min_ext_clk_freq_hz;
@@ -96,6 +174,16 @@ struct ccs_pll_limits {struct device ; +/** +* ccs_pll_calculate - Calculate CCS PLL configuration based on input parameters +* +* @dev: Device pointer, used for printing messages +* @limits: Limits specific to the sensor +* @pll: Given PLL configuration +* +* Calculate the CCS PLL configuration based on the limits as well as given +* device specific, system specific or user configured input data. +*/ int ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *limits,struct ccs_pll *pll);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 70/106 ccs-pll: Use explicit 32-bit unsigned type
In reply to Sakari AilusUse uint32_t instead of unsigned int for a variable that contains explicitly 32-bit numbers.
--- drivers/media/i2c/ccs-pll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs-pll.c +2 -2
@@ -177,7 +177,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,uint32_t more_mul_factor;uint32_t min_vt_div, max_vt_div, vt_div;uint32_t min_sys_div, max_sys_div; -unsigned int i; +uint32_t i;/* * Get pre_pll_clk_div so that our pll_op_clk_freq_hz won't be
@@ -406,7 +406,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,uint16_t max_op_pre_pll_clk_div;uint32_t lane_op_clock_ratio;uint32_t mul, div; -unsigned int i; +uint32_t i;int rval = -EINVAL ;if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) {
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 76/106 ccs-pll: Add support flexible OP PLL pixel clock divider
In reply to Sakari AilusFlexible OP PLL pixel clock divider allows a higher OP pixel clock than what the bus can transfer. This generally makes it easier to select pixel clock dividers.
This changes how the pixel rate on the bus and minimum VT divisor are calculated, as the pixel rate is no longer directly determined by the OP pixel clock and the number of the lanes.
Also add a sanity check for sensors that do not support flexible OP PLL pixel clock divider. This could have caused the PLL calculator to come up with an invalid configuration for those devices.
--- drivers/media/i2c/ccs-pll.c | 26 +++++++++++++++++++------- drivers/media/i2c/ccs-pll.h | 1 + drivers/media/i2c/ccs/ccs-core.c | 4 +++- 3 files changed, 23 insertions(+), 8 deletions(-)
drivers/media/i2c/ccs-pll.c +19 -7
@@ -294,11 +294,11 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,* Find absolute limits for the factor of vt divider. */ dev_dbg (dev,"scale_m: %u\n" , pll->scale_m); - min_vt_div =DIV_ROUND_UP (op_pll_bk->pix_clk_div - * op_pll_bk->sys_clk_div * pll->scale_n - * pll->vt_lanes * l, - pll->op_lanes * vt_op_binning_div - * pll->scale_m); + min_vt_div =DIV_ROUND_UP (pll->bits_per_pixel * op_pll_bk->sys_clk_div + * pll->scale_n * pll->vt_lanes, + (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? + pll->csi2.lanes :1 ) + * vt_op_binning_div * pll->scale_m);/* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div);
@@ -420,6 +420,18 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->op_lanes =1 ; pll->vt_lanes =1 ; } + +/* +* Make sure op_pix_clk_div will be integer --- unless flexible +* op_pix_clk_div is supported +*/ +if (!(pll->flags &CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV ) && + (pll->bits_per_pixel * pll->op_lanes) % (pll->csi2.lanes * l)) { +dev_dbg (dev,"op_pix_clk_div not an integer (bpp %u, op lanes %u, lanes %u, l %u)\n" , + pll->bits_per_pixel, pll->op_lanes, pll->csi2.lanes, l); +return -EINVAL ; + } +dev_dbg (dev,"vt_lanes: %u\n" , pll->vt_lanes);dev_dbg (dev,"op_lanes: %u\n" , pll->op_lanes);
@@ -449,9 +461,9 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, } pll->pixel_rate_csi = - op_pll_bk->pix_clk_freq_hz + op_pll_bk->sys_clk_freq_hz * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? - pll->csi2.lanes :1 ) / l; + pll->csi2.lanes :1 ) / pll->bits_per_pixel / l;/* Figure out limits for OP pre-pll divider based on extclk */ dev_dbg(dev, "min / max op_pre_pll_clk_div: %u / %u\n",
drivers/media/i2c/ccs-pll.h +1 -0
@@ -26,6 +26,7 @@#define CCS_PLL_FLAG_LANE_SPEED_MODEL BIT(2)#define CCS_PLL_FLAG_LINK_DECOUPLED BIT(3)#define CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER BIT(4) +#define CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV BIT(5)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
drivers/media/i2c/ccs/ccs-core.c +3 -1
@@ -30,7 +30,6 @@#include <media/v4l2-device.h> #include "ccs.h" -#include "ccs-limits.h" #define CCS_ALIGN_DIM (dim, flags) \ ((flags) & V4L2_SEL_FLAG_GE \
@@ -3214,6 +3213,9 @@ static int ccs_probe(struct i2c_client *client)if (CCS_LIM (sensor,CLOCK_TREE_PLL_CAPABILITY ) &CCS_CLOCK_TREE_PLL_CAPABILITY_EXT_DIVIDER ) sensor->pll.flags |=CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER ; +if (CCS_LIM (sensor,CLOCK_TREE_PLL_CAPABILITY ) & +CCS_CLOCK_TREE_PLL_CAPABILITY_FLEXIBLE_OP_PIX_CLK_DIV ) + sensor->pll.flags |=CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV ; sensor->pll.op_bits_per_lane =CCS_LIM (sensor,OP_BITS_PER_LANE ); sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 73/106 ccs-pll: Add support for decoupled OP domain calculation
In reply to Sakari AilusAdd support for decoupled OP domain clock calculation. This means that the number of VT and OP domain clocks are no longer dependent on the number of CSI-2 lanes in the lane speed mode.
The support also replaces the existing quirk flag to calculate OP domain clocks per lane.
Also support decoupled OP domain calculation in the CCS driver.
--- drivers/media/i2c/ccs-pll.c | 22 +++++++--------------- drivers/media/i2c/ccs-pll.h | 1 + drivers/media/i2c/ccs/ccs-core.c | 14 +++++++++++--- drivers/media/i2c/ccs/ccs-quirk.c | 5 ++++- 4 files changed, 23 insertions(+), 19 deletions(-)
drivers/media/i2c/ccs-pll.c +7 -15
@@ -162,7 +162,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,const struct ccs_pll_branch_limits_bk *op_lim_bk, struct ccs_pll *pll, struct ccs_pll_branch_fr *op_pll_fr, struct ccs_pll_branch_bk *op_pll_bk, uint32_t mul, - uint32_t div, uint32_t lane_op_clock_ratio) + uint32_t div) { uint32_t sys_div;uint32_t best_pix_div =INT_MAX >>1 ;
@@ -194,7 +194,8 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,min_t (uint32_t, more_mul_max, op_lim_fr->max_pll_op_clk_freq_hz - / (pll->ext_clk_freq_hz / op_pll_fr->pre_pll_clk_div * mul)); + / (pll->ext_clk_freq_hz / + op_pll_fr->pre_pll_clk_div * mul));dev_dbg (dev,"more_mul_max: max_pll_op_clk_freq_hz check: %u\n" , more_mul_max);/* Don't go above the division capability of op sys clock divider. */
@@ -257,7 +258,6 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div;dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div); -if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) {/* No OP clocks --- VT clocks are used instead. */ goto out_skip_vt_calc;
@@ -293,7 +293,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,* op_pll_bk->sys_clk_div * pll->scale_n * pll->vt_lanes, pll->op_lanes * vt_op_binning_div -* pll->scale_m * lane_op_clock_ratio); +* pll->scale_m); /* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div);
@@ -405,7 +405,6 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,struct ccs_pll_branch_bk *op_pll_bk = &pll->op_bk;uint16_t min_op_pre_pll_clk_div;uint16_t max_op_pre_pll_clk_div; -uint32_t lane_op_clock_ratio;uint32_t mul, div;uint32_t i;int rval = -EINVAL ;
@@ -428,12 +427,6 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_bk = &pll->vt_bk; } -if (pll->flags &CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE ) - lane_op_clock_ratio = pll->csi2.lanes; -else - lane_op_clock_ratio =1 ; -dev_dbg (dev,"lane_op_clock_ratio: %u\n" , lane_op_clock_ratio); -dev_dbg (dev,"binning: %ux%u\n" , pll->binning_horizontal, pll->binning_vertical);
@@ -442,7 +435,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,/* CSI transfers 2 bits per clock per lane; thus times 2 */ op_pll_bk->sys_clk_freq_hz = pll->link_freq *2 * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? -1 : pll->csi2.lanes) / lane_op_clock_ratio; +1 : pll->csi2.lanes);break ;default :return -EINVAL ;
@@ -451,7 +444,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->pixel_rate_csi = op_pll_bk->pix_clk_freq_hz * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? - pll->csi2.lanes :1 ) * lane_op_clock_ratio; + pll->csi2.lanes :1 );/* Figure out limits for OP pre-pll divider based on extclk */ dev_dbg(dev, "min / max op_pre_pll_clk_div: %u / %u\n",
@@ -487,8 +480,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_fr->pre_pll_clk_div <= max_op_pre_pll_clk_div; op_pll_fr->pre_pll_clk_div += 2 - (op_pll_fr->pre_pll_clk_div & 1)) { rval =__ccs_pll_calculate (dev, lim, op_lim_fr, op_lim_bk, pll, - op_pll_fr, op_pll_bk, mul, div, - lane_op_clock_ratio); + op_pll_fr, op_pll_bk, mul, div);if (rval)continue ;
drivers/media/i2c/ccs-pll.h +1 -0
@@ -24,6 +24,7 @@#define CCS_PLL_FLAG_NO_OP_CLOCKS BIT(1)/* CCS PLL flags */ #define CCS_PLL_FLAG_LANE_SPEED_MODEL BIT(2) +#define CCS_PLL_FLAG_LINK_DECOUPLED BIT(3)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
drivers/media/i2c/ccs/ccs-core.c +11 -3
@@ -3198,10 +3198,18 @@ static int ccs_probe(struct i2c_client *client) sensor->pll.csi2.lanes = sensor->hwcfg.lanes;if (CCS_LIM (sensor,CLOCK_CALCULATION ) &CCS_CLOCK_CALCULATION_LANE_SPEED ) { - sensor->pll.vt_lanes = -CCS_LIM (sensor,NUM_OF_VT_LANES ) +1 ; - sensor->pll.op_lanes = sensor->pll.vt_lanes; sensor->pll.flags |=CCS_PLL_FLAG_LANE_SPEED_MODEL ; +if (CCS_LIM (sensor,CLOCK_CALCULATION ) & +CCS_CLOCK_CALCULATION_LINK_DECOUPLED ) { + sensor->pll.vt_lanes = +CCS_LIM (sensor,NUM_OF_VT_LANES ) +1 ; + sensor->pll.op_lanes = +CCS_LIM (sensor,NUM_OF_OP_LANES ) +1 ; + sensor->pll.flags |=CCS_PLL_FLAG_LINK_DECOUPLED ; + }else { + sensor->pll.vt_lanes = sensor->pll.csi2.lanes; + sensor->pll.op_lanes = sensor->pll.csi2.lanes; + } } sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
drivers/media/i2c/ccs/ccs-quirk.c +4 -1
@@ -190,7 +190,10 @@ static int jt8ev1_post_streamoff(struct ccs_sensor *sensor)static int jt8ev1_init (struct ccs_sensor *sensor) { - sensor->pll.flags |=CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE ; + sensor->pll.flags |=CCS_PLL_FLAG_LANE_SPEED_MODEL | +CCS_PLL_FLAG_LINK_DECOUPLED ; + sensor->pll.vt_lanes =1 ; + sensor->pll.op_lanes = sensor->pll.csi2.lanes;return 0 ; }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 78/106 ccs-pll: Add C-PHY support
In reply to Sakari AilusAdd C-PHY support for the CCS PLL calculator.
--- drivers/media/i2c/ccs-pll.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
drivers/media/i2c/ccs-pll.c +26 -9
@@ -145,6 +145,10 @@ static int check_all_bounds(struct device *dev,return rval; } +#define CPHY_CONST 7 +#define DPHY_CONST 16 +#define PHY_CONST_DIV 16 +/* * Heuristically guess the PLL tree for a given common multiplier and * divisor. Begin with the operational timing and continue to video
@@ -162,7 +166,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,const struct ccs_pll_branch_limits_bk *op_lim_bk, struct ccs_pll *pll, struct ccs_pll_branch_fr *op_pll_fr, struct ccs_pll_branch_bk *op_pll_bk, uint32_t mul, - uint32_t div, uint32_t l) + uint32_t div, uint32_t l, bool cphy, uint32_t phy_const) { uint32_t sys_div;uint32_t best_pix_div =INT_MAX >>1 ;
@@ -254,9 +258,11 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,if (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ) op_pll_bk->pix_clk_div = pll->bits_per_pixel - * pll->op_lanes / pll->csi2.lanes / l; + * pll->op_lanes * phy_const + /PHY_CONST_DIV / pll->csi2.lanes / l;else - op_pll_bk->pix_clk_div = pll->bits_per_pixel / l; + op_pll_bk->pix_clk_div = + pll->bits_per_pixel * phy_const /PHY_CONST_DIV / l; op_pll_bk->pix_clk_freq_hz = op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div;
@@ -295,10 +301,11 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,*/ dev_dbg (dev,"scale_m: %u\n" , pll->scale_m); min_vt_div =DIV_ROUND_UP (pll->bits_per_pixel * op_pll_bk->sys_clk_div - * pll->scale_n * pll->vt_lanes, + * pll->scale_n * pll->vt_lanes * phy_const, (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? pll->csi2.lanes :1 ) - * vt_op_binning_div * pll->scale_m); + * vt_op_binning_div * pll->scale_m + *PHY_CONST_DIV );/* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div);
@@ -408,6 +415,8 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,const struct ccs_pll_branch_limits_bk *op_lim_bk = &lim->op_bk;struct ccs_pll_branch_fr *op_pll_fr = &pll->vt_fr;struct ccs_pll_branch_bk *op_pll_bk = &pll->op_bk; +bool cphy = pll->bus_type ==CCS_PLL_BUS_TYPE_CSI2_CPHY ; +uint32_t phy_const = cphy ?CPHY_CONST :DPHY_CONST ;uint16_t min_op_pre_pll_clk_div;uint16_t max_op_pre_pll_clk_div;uint32_t mul, div;
@@ -465,14 +474,21 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ?1 : pll->csi2.lanes);break ; +case CCS_PLL_BUS_TYPE_CSI2_CPHY : + op_pll_bk->sys_clk_freq_hz = + pll->link_freq + * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? +1 : pll->csi2.lanes); +break ;default :return -EINVAL ; } pll->pixel_rate_csi = - op_pll_bk->sys_clk_freq_hz - * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? - pll->csi2.lanes :1 ) / pll->bits_per_pixel / l; +div_u64 ((uint64_t )op_pll_bk->sys_clk_freq_hz + * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? + pll->csi2.lanes :1 ) *PHY_CONST_DIV , + phy_const * pll->bits_per_pixel * l);/* Figure out limits for OP pre-pll divider based on extclk */ dev_dbg(dev, "min / max op_pre_pll_clk_div: %u / %u\n",
@@ -510,7 +526,8 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, (pll->flags & CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER) ? 1 : 2 - (op_pll_fr->pre_pll_clk_div & 1)) { rval =__ccs_pll_calculate (dev, lim, op_lim_fr, op_lim_bk, pll, - op_pll_fr, op_pll_bk, mul, div, l); + op_pll_fr, op_pll_bk, mul, div, l, + cphy, phy_const);if (rval)continue ;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 83/106 ccs-pll: Rework bounds checks
In reply to Sakari AilusRefactor bounds checks so that the caller can decide what to check. This allows doing the checks early, when the values are available.
This also adds front OP PLL configuration and limits.
--- drivers/media/i2c/ccs-pll.c | 148 ++++++++++++++++++++++-------------- drivers/media/i2c/ccs-pll.h | 2 + 2 files changed, 93 insertions(+), 57 deletions(-)
drivers/media/i2c/ccs-pll.c +91 -57
@@ -46,12 +46,14 @@ static inline uint32_t one_or_more(uint32_t a) }static int bounds_check (struct device *dev,uint32_t val, -uint32_t min,uint32_t max,char *str) +uint32_t min,uint32_t max,const char *prefix, +char *str) {if (val >= min && val <= max)return 0 ; -dev_dbg (dev,"%s out of bounds: %d (%d--%d)\n" , str, val, min, max); +dev_dbg (dev,"%s_%s out of bounds: %d (%d--%d)\n" , prefix, + str, val, min, max);return -EINVAL ; }
@@ -81,7 +83,7 @@ static void print_pll(struct device *dev, struct ccs_pll *pll)unsigned int which; } branches[] = { { &pll->vt_fr, &pll->vt_bk, PLL_VT }, - { NULL, &pll->op_bk, PLL_OP } + { &pll->op_fr, &pll->op_bk, PLL_OP } }, *br;unsigned int i;
@@ -127,68 +129,90 @@ static void print_pll(struct device *dev, struct ccs_pll *pll) pll->flags & PLL_FL(FIFO_OVERRATING) ? " fifo-overrating" : ""); } -static int check_all_bounds (struct device *dev, -const struct ccs_pll_limits *lim, -const struct ccs_pll_branch_limits_fr *op_lim_fr, -const struct ccs_pll_branch_limits_bk *op_lim_bk, -struct ccs_pll *pll, -struct ccs_pll_branch_fr *op_pll_fr, -struct ccs_pll_branch_bk *op_pll_bk) +static int check_fr_bounds (struct device *dev, +const struct ccs_pll_limits *lim, +struct ccs_pll *pll,unsigned int which) { +const struct ccs_pll_branch_limits_fr *lim_fr; +struct ccs_pll_branch_fr *pll_fr; +const char *s =pll_string (which);int rval; - rval =bounds_check (dev, op_pll_fr->pll_ip_clk_freq_hz, - op_lim_fr->min_pll_ip_clk_freq_hz, - op_lim_fr->max_pll_ip_clk_freq_hz, -"pll_ip_clk_freq_hz" ); -if (!rval) - rval =bounds_check ( - dev, op_pll_fr->pll_multiplier, - op_lim_fr->min_pll_multiplier, - op_lim_fr->max_pll_multiplier,"pll_multiplier" ); -if (!rval) - rval =bounds_check ( - dev, op_pll_fr->pll_op_clk_freq_hz, - op_lim_fr->min_pll_op_clk_freq_hz, - op_lim_fr->max_pll_op_clk_freq_hz,"pll_op_clk_freq_hz" ); +if (which ==PLL_OP ) { + lim_fr = &lim->op_fr; + pll_fr = &pll->op_fr; + }else { + lim_fr = &lim->vt_fr; + pll_fr = &pll->vt_fr; + } + + rval =bounds_check (dev, pll_fr->pre_pll_clk_div, + lim_fr->min_pre_pll_clk_div, + lim_fr->max_pre_pll_clk_div, s,"pre_pll_clk_div" ); +if (!rval) - rval =bounds_check ( - dev, op_pll_bk->sys_clk_div, - op_lim_bk->min_sys_clk_div, op_lim_bk->max_sys_clk_div, -"op_sys_clk_div" ); + rval =bounds_check (dev, pll_fr->pll_ip_clk_freq_hz, + lim_fr->min_pll_ip_clk_freq_hz, + lim_fr->max_pll_ip_clk_freq_hz, + s,"pll_ip_clk_freq_hz" );if (!rval) - rval =bounds_check ( - dev, op_pll_bk->sys_clk_freq_hz, - op_lim_bk->min_sys_clk_freq_hz, - op_lim_bk->max_sys_clk_freq_hz, -"op_sys_clk_freq_hz" ); + rval =bounds_check (dev, pll_fr->pll_multiplier, + lim_fr->min_pll_multiplier, + lim_fr->max_pll_multiplier, + s,"pll_multiplier" );if (!rval) - rval =bounds_check ( - dev, op_pll_bk->pix_clk_freq_hz, - op_lim_bk->min_pix_clk_freq_hz, - op_lim_bk->max_pix_clk_freq_hz, -"op_pix_clk_freq_hz" ); + rval =bounds_check (dev, pll_fr->pll_op_clk_freq_hz, + lim_fr->min_pll_op_clk_freq_hz, + lim_fr->max_pll_op_clk_freq_hz, + s,"pll_op_clk_freq_hz" ); -/* -* If there are no OP clocks, the VT clocks are contained in -* the OP clock struct. -*/ -if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) -return rval; +return rval; +} + +static int check_bk_bounds (struct device *dev, +const struct ccs_pll_limits *lim, +struct ccs_pll *pll,unsigned int which) +{ +const struct ccs_pll_branch_limits_bk *lim_bk; +struct ccs_pll_branch_bk *pll_bk; +const char *s =pll_string (which); +int rval; + +if (which ==PLL_OP ) { +if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) +return 0 ; + lim_bk = &lim->op_bk; + pll_bk = &pll->op_bk; + }else { + lim_bk = &lim->vt_bk; + pll_bk = &pll->vt_bk; + } + + rval =bounds_check (dev, pll_bk->sys_clk_div, + lim_bk->min_sys_clk_div, + lim_bk->max_sys_clk_div, s,"op_sys_clk_div" ); +if (!rval) + rval =bounds_check (dev, pll_bk->sys_clk_freq_hz, + lim_bk->min_sys_clk_freq_hz, + lim_bk->max_sys_clk_freq_hz, + s,"sys_clk_freq_hz" );if (!rval) - rval =bounds_check ( - dev, pll->vt_bk.sys_clk_freq_hz, - lim->vt_bk.min_sys_clk_freq_hz, - lim->vt_bk.max_sys_clk_freq_hz, -"vt_sys_clk_freq_hz" ); + rval =bounds_check (dev, pll_bk->sys_clk_div, + lim_bk->min_sys_clk_div, + lim_bk->max_sys_clk_div, + s,"sys_clk_div" );if (!rval) - rval =bounds_check ( - dev, pll->vt_bk.pix_clk_freq_hz, - lim->vt_bk.min_pix_clk_freq_hz, - lim->vt_bk.max_pix_clk_freq_hz, -"vt_pix_clk_freq_hz" ); + rval =bounds_check (dev, pll_bk->pix_clk_freq_hz, + lim_bk->min_pix_clk_freq_hz, + lim_bk->max_pix_clk_freq_hz, + s,"pix_clk_freq_hz" ); + +return rval; +} +static int check_ext_bounds (struct device *dev,struct ccs_pll *pll) +{if (!(pll->flags &CCS_PLL_FLAG_FIFO_DERATING ) && pll->pixel_rate_pixel_array > pll->pixel_rate_csi) {dev_dbg (dev,"device does not support derating\n" );
@@ -201,7 +225,7 @@ static int check_all_bounds(struct device *dev,return -EINVAL ; } -return rval; +return 0 ; }#define CPHY_CONST 7
@@ -610,11 +634,21 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,if (rval)continue ; + rval =check_fr_bounds (dev, lim, pll,PLL_VT ); +if (rval) +continue ; + + rval =check_bk_bounds (dev, lim, pll,PLL_OP ); +if (rval) +continue ; +ccs_pll_calculate_vt (dev, lim, op_lim_bk, pll, op_pll_fr, op_pll_bk, cphy, phy_const); - rval =check_all_bounds (dev, lim, op_lim_fr, op_lim_bk, pll, - op_pll_fr, op_pll_bk); + rval =check_bk_bounds (dev, lim, pll,PLL_VT ); +if (rval) +continue ; + rval =check_ext_bounds (dev, pll);if (rval)continue ;
drivers/media/i2c/ccs-pll.h +2 -0
@@ -111,6 +111,7 @@ struct ccs_pll {/* output values */ struct ccs_pll_branch_fr vt_fr;struct ccs_pll_branch_bk vt_bk; +struct ccs_pll_branch_fr op_fr;struct ccs_pll_branch_bk op_bk;uint32_t pixel_rate_csi;
@@ -181,6 +182,7 @@ struct ccs_pll_limits {struct ccs_pll_branch_limits_fr vt_fr;struct ccs_pll_branch_limits_bk vt_bk; +struct ccs_pll_branch_limits_fr op_fr;struct ccs_pll_branch_limits_bk op_bk;/* Other relevant limits */
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 85/106 ccs-pll: Fix VT post-PLL divisor calculation
In reply to Sakari AilusThe PLL calculator only searched even total divisor values apart from one, but this is wrong: the total divisor is odd in cases where system divisor is one. Fix this by including odd total PLL values where system divisor is one to the search.
--- drivers/media/i2c/ccs-pll.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/media/i2c/ccs-pll.c +7 -5
@@ -347,14 +347,16 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,* into a value which is not smaller than div, the desired * divisor. */ -for (vt_div = min_vt_div; vt_div <= max_vt_div; - vt_div +=2 - (vt_div &1 )) { -for (sys_div = min_sys_div; - sys_div <= max_sys_div; +for (vt_div = min_vt_div; vt_div <= max_vt_div; vt_div++) { +uint16_t __max_sys_div = vt_div &1 ?1 : max_sys_div; + +for (sys_div = min_sys_div; sys_div <= __max_sys_div; sys_div +=2 - (sys_div &1 )) { -uint16_t pix_div =DIV_ROUND_UP (vt_div, sys_div); +uint16_t pix_div;uint16_t rounded_div; + pix_div =DIV_ROUND_UP (vt_div, sys_div); +if (pix_div < lim->vt_bk.min_pix_clk_div || pix_div > lim->vt_bk.max_pix_clk_div) { dev_dbg(dev,
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 82/106 ccs-pll: Print relevant information on PLL tree
In reply to Sakari AilusPrint information on PLL tree configuration based on the flags. This also adds support for printing dual PLL trees, and better separates between OP and VT PLL trees.
--- drivers/media/i2c/ccs-pll.c | 85 ++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 19 deletions(-)
drivers/media/i2c/ccs-pll.c +66 -19
@@ -56,28 +56,75 @@ static int bounds_check(struct device *dev, uint32_t val,return -EINVAL ; } -static void print_pll (struct device *dev,struct ccs_pll *pll) +#define PLL_OP 1 +#define PLL_VT 2 + +static const char *pll_string (unsigned int which) { -dev_dbg (dev,"pre_pll_clk_div\t%u\n" , pll->vt_fr.pre_pll_clk_div); -dev_dbg (dev,"pll_multiplier \t%u\n" , pll->vt_fr.pll_multiplier); -if (!(pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS )) { -dev_dbg (dev,"op_sys_clk_div \t%u\n" , pll->op_bk.sys_clk_div); -dev_dbg (dev,"op_pix_clk_div \t%u\n" , pll->op_bk.pix_clk_div); +switch (which) { +case PLL_OP : +return "op" ; +case PLL_VT : +return "vt" ; } -dev_dbg (dev,"vt_sys_clk_div \t%u\n" , pll->vt_bk.sys_clk_div); -dev_dbg (dev,"vt_pix_clk_div \t%u\n" , pll->vt_bk.pix_clk_div); - -dev_dbg (dev,"ext_clk_freq_hz \t%u\n" , pll->ext_clk_freq_hz); -dev_dbg (dev,"pll_ip_clk_freq_hz \t%u\n" , pll->vt_fr.pll_ip_clk_freq_hz); -dev_dbg (dev,"pll_op_clk_freq_hz \t%u\n" , pll->vt_fr.pll_op_clk_freq_hz); -if (!(pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS )) { -dev_dbg (dev,"op_sys_clk_freq_hz \t%u\n" , - pll->op_bk.sys_clk_freq_hz); -dev_dbg (dev,"op_pix_clk_freq_hz \t%u\n" , - pll->op_bk.pix_clk_freq_hz); + +return NULL ; +} + +#define PLL_FL (f) CCS_PLL_FLAG_##f + +static void print_pll (struct device *dev,struct ccs_pll *pll) +{ +const struct { +struct ccs_pll_branch_fr *fr; +struct ccs_pll_branch_bk *bk; +unsigned int which; + } branches[] = { + { &pll->vt_fr, &pll->vt_bk,PLL_VT }, + {NULL , &pll->op_bk,PLL_OP } + }, *br; +unsigned int i; + +dev_dbg (dev,"ext_clk_freq_hz\t\t%u\n" , pll->ext_clk_freq_hz); + +for (i =0 , br = branches; i <ARRAY_SIZE (branches); i++, br++) { +const char *s =pll_string (br->which); + +if (br->which ==PLL_VT ) { +dev_dbg (dev,"%s_pre_pll_clk_div\t\t%u\n" , s, + br->fr->pre_pll_clk_div); +dev_dbg (dev,"%s_pll_multiplier\t\t%u\n" , s, + br->fr->pll_multiplier); + +dev_dbg (dev,"%s_pll_ip_clk_freq_hz\t%u\n" , s, + br->fr->pll_ip_clk_freq_hz); +dev_dbg (dev,"%s_pll_op_clk_freq_hz\t%u\n" , s, + br->fr->pll_op_clk_freq_hz); + } + +if (!(pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) || + br->which ==PLL_VT ) { +dev_dbg (dev,"%s_sys_clk_div\t\t%u\n" , s, + br->bk->sys_clk_div); +dev_dbg (dev,"%s_pix_clk_div\t\t%u\n" , s, + br->bk->pix_clk_div); + +dev_dbg (dev,"%s_sys_clk_freq_hz\t%u\n" , s, + br->bk->sys_clk_freq_hz); +dev_dbg (dev,"%s_pix_clk_freq_hz\t%u\n" , s, + br->bk->pix_clk_freq_hz); + } } -dev_dbg (dev,"vt_sys_clk_freq_hz \t%u\n" , pll->vt_bk.sys_clk_freq_hz); -dev_dbg (dev,"vt_pix_clk_freq_hz \t%u\n" , pll->vt_bk.pix_clk_freq_hz); + +dev_dbg (dev,"flags%s%s%s%s%s%s\n" , + pll->flags &PLL_FL (LANE_SPEED_MODEL ) ?" lane-speed" :"" , + pll->flags &PLL_FL (LINK_DECOUPLED ) ?" link-decoupled" :"" , + pll->flags &PLL_FL (EXT_IP_PLL_DIVIDER ) ? +" ext-ip-pll-divider" :"" , + pll->flags &PLL_FL (FLEXIBLE_OP_PIX_CLK_DIV ) ? +" flexible-op-pix-div" :"" , + pll->flags &PLL_FL (FIFO_DERATING ) ?" fifo-derating" :"" , + pll->flags &PLL_FL (FIFO_OVERRATING ) ?" fifo-overrating" :"" ); } static int check_all_bounds(struct device *dev,
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 89/106 ccs-pll: Add support for DDR OP system and pixel clocks
In reply to Sakari AilusAdd support for dual data rate operational system and pixel clocks. This is implemented using two PLL flags.
--- drivers/media/i2c/ccs-pll.c | 64 +++++++++++++++++++++++++------------ drivers/media/i2c/ccs-pll.h | 2 ++ 2 files changed, 46 insertions(+), 20 deletions(-)
drivers/media/i2c/ccs-pll.c +44 -20
@@ -119,7 +119,7 @@ static void print_pll(struct device *dev, struct ccs_pll *pll) } } - dev_dbg(dev, "flags%s%s%s%s%s%s%s\n", + dev_dbg(dev, "flags%s%s%s%s%s%s%s%s%s\n", pll->flags & PLL_FL(LANE_SPEED_MODEL) ? " lane-speed" : "", pll->flags & PLL_FL(LINK_DECOUPLED) ? " link-decoupled" : "", pll->flags & PLL_FL(EXT_IP_PLL_DIVIDER) ?
@@ -128,7 +128,19 @@ static void print_pll(struct device *dev, struct ccs_pll *pll) " flexible-op-pix-div" : "", pll->flags &PLL_FL (FIFO_DERATING ) ?" fifo-derating" :"" , pll->flags &PLL_FL (FIFO_OVERRATING ) ?" fifo-overrating" :"" , - pll->flags & PLL_FL(DUAL_PLL) ? " dual-pll" : ""); + pll->flags &PLL_FL (DUAL_PLL ) ?" dual-pll" :"" , + pll->flags &PLL_FL (OP_SYS_DDR ) ?" op-sys-ddr" :"" , + pll->flags & PLL_FL(OP_PIX_DDR) ? " op-pix-ddr" : ""); +} + +static uint32_t op_sys_ddr (uint32_t flags) +{ +return flags &CCS_PLL_FLAG_OP_SYS_DDR ?1 :0 ; +} + +static uint32_t op_pix_ddr (uint32_t flags) +{ +return flags &CCS_PLL_FLAG_OP_PIX_DDR ?1 :0 ; } static int check_fr_bounds(struct device *dev,
@@ -441,8 +453,8 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,if (!(pll->flags &CCS_PLL_FLAG_FIFO_DERATING )) { min_vt_div = op_pll_bk->sys_clk_div * op_pll_bk->pix_clk_div - * pll->vt_lanes * phy_const - / pll->op_lanes /PHY_CONST_DIV ; + * pll->vt_lanes * phy_const / pll->op_lanes + / (PHY_CONST_DIV <<op_pix_ddr (pll->flags)); }else {/* * Some sensors perform analogue binning and some do this
@@ -478,7 +490,7 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,CCS_PLL_FLAG_LANE_SPEED_MODEL ? pll->csi2.lanes : 1) * vt_op_binning_div * pll->scale_m - * PHY_CONST_DIV); + * PHY_CONST_DIV << op_pix_ddr(pll->flags)); }/* Find smallest and biggest allowed vt divisor. */
@@ -572,7 +584,8 @@ ccs_pll_calculate_op(struct device *dev, const struct ccs_pll_limits *lim,const struct ccs_pll_branch_limits_bk *op_lim_bk, struct ccs_pll *pll, struct ccs_pll_branch_fr *op_pll_fr, struct ccs_pll_branch_bk *op_pll_bk, uint32_t mul, - uint32_t div, uint32_t l, bool cphy, uint32_t phy_const) + uint32_t div, uint32_t op_sys_clk_freq_hz_sdr, uint32_t l, + bool cphy, uint32_t phy_const) {/* * Higher multipliers (and divisors) are often required than
@@ -658,15 +671,22 @@ ccs_pll_calculate_op(struct device *dev, const struct ccs_pll_limits *lim, * op_pll_fr->pll_multiplier;if (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ) - op_pll_bk->pix_clk_div = pll->bits_per_pixel - * pll->op_lanes * phy_const - /PHY_CONST_DIV / pll->csi2.lanes / l; + op_pll_bk->pix_clk_div = + (pll->bits_per_pixel + * pll->op_lanes * (phy_const <<op_sys_ddr (pll->flags)) + /PHY_CONST_DIV / pll->csi2.lanes / l) + >>op_pix_ddr (pll->flags);else op_pll_bk->pix_clk_div = - pll->bits_per_pixel * phy_const /PHY_CONST_DIV / l; + (pll->bits_per_pixel + * (phy_const <<op_sys_ddr (pll->flags)) + /PHY_CONST_DIV / l) >>op_pix_ddr (pll->flags); op_pll_bk->pix_clk_freq_hz = - op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div; + (op_sys_clk_freq_hz_sdr >>op_pix_ddr (pll->flags)) + / op_pll_bk->pix_clk_div; + op_pll_bk->sys_clk_freq_hz = + op_sys_clk_freq_hz_sdr >>op_sys_ddr (pll->flags);dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div);
@@ -682,6 +702,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,struct ccs_pll_branch_bk *op_pll_bk;bool cphy = pll->bus_type ==CCS_PLL_BUS_TYPE_CSI2_CPHY ;uint32_t phy_const = cphy ?CPHY_CONST :DPHY_CONST ; +uint32_t op_sys_clk_freq_hz_sdr;uint16_t min_op_pre_pll_clk_div;uint16_t max_op_pre_pll_clk_div;uint32_t mul, div;
@@ -731,7 +752,8 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,* op_pix_clk_div is supported */ if (!(pll->flags &CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV ) && - (pll->bits_per_pixel * pll->op_lanes) % (pll->csi2.lanes * l)) { + (pll->bits_per_pixel * pll->op_lanes) % + (pll->csi2.lanes * l <<op_pix_ddr (pll->flags))) {dev_dbg (dev,"op_pix_clk_div not an integer (bpp %u, op lanes %u, lanes %u, l %u)\n" , pll->bits_per_pixel, pll->op_lanes, pll->csi2.lanes, l);return -EINVAL ;
@@ -746,12 +768,12 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,switch (pll->bus_type) {case CCS_PLL_BUS_TYPE_CSI2_DPHY :/* CSI transfers 2 bits per clock per lane; thus times 2 */ - op_pll_bk->sys_clk_freq_hz = pll->link_freq *2 + op_sys_clk_freq_hz_sdr = pll->link_freq *2 * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ?1 : pll->csi2.lanes);break ;case CCS_PLL_BUS_TYPE_CSI2_CPHY : - op_pll_bk->sys_clk_freq_hz = + op_sys_clk_freq_hz_sdr = pll->link_freq * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ?1 : pll->csi2.lanes);
@@ -761,7 +783,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, } pll->pixel_rate_csi = -div_u64 ((uint64_t )op_pll_bk->sys_clk_freq_hz +div_u64 ((uint64_t )op_sys_clk_freq_hz_sdr * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? pll->csi2.lanes :1 ) *PHY_CONST_DIV , phy_const * pll->bits_per_pixel * l);
@@ -781,9 +803,10 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,dev_dbg (dev,"pre-pll check: min / max op_pre_pll_clk_div: %u / %u\n" , min_op_pre_pll_clk_div, max_op_pre_pll_clk_div); - i =gcd (op_pll_bk->sys_clk_freq_hz, pll->ext_clk_freq_hz); - mul = op_pll_bk->sys_clk_freq_hz / i; - div = pll->ext_clk_freq_hz / i; + i =gcd (op_sys_clk_freq_hz_sdr, + pll->ext_clk_freq_hz <<op_pix_ddr (pll->flags)); + mul = op_sys_clk_freq_hz_sdr / i; + div = (pll->ext_clk_freq_hz <<op_pix_ddr (pll->flags)) / i;dev_dbg (dev,"mul %u / div %u\n" , mul, div); min_op_pre_pll_clk_div =
@@ -802,8 +825,9 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, (pll->flags & CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER) ? 1 : 2 - (op_pll_fr->pre_pll_clk_div & 1)) { rval =ccs_pll_calculate_op (dev, lim, op_lim_fr, op_lim_bk, pll, - op_pll_fr, op_pll_bk, mul, div, l, - cphy, phy_const); + op_pll_fr, op_pll_bk, mul, div, + op_sys_clk_freq_hz_sdr, l, cphy, + phy_const);if (rval)continue ;
drivers/media/i2c/ccs-pll.h +2 -0
@@ -30,6 +30,8 @@#define CCS_PLL_FLAG_FIFO_DERATING BIT(6)#define CCS_PLL_FLAG_FIFO_OVERRATING BIT(7)#define CCS_PLL_FLAG_DUAL_PLL BIT(8) +#define CCS_PLL_FLAG_OP_SYS_DDR BIT(9) +#define CCS_PLL_FLAG_OP_PIX_DDR BIT(10)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 93/106 ccs: Add support for obtaining C-PHY configuration from firmware
In reply to Sakari AilusTry parsing the firmware also as C-PHY. Do this only after D-PHY as older firmware may not explicitly specify bus-type in which case D-PHY is the default.
--- drivers/media/i2c/ccs/ccs-core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +4 -0
@@ -2926,6 +2926,10 @@ static int ccs_get_hwconfig(struct ccs_sensor *sensor, struct device *dev) hwcfg->csi_signalling_mode =CCS_CSI_SIGNALING_MODE_CSI_2_DPHY ; hwcfg->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;break ; +case V4L2_MBUS_CSI2_CPHY : + hwcfg->csi_signalling_mode =CCS_CSI_SIGNALING_MODE_CSI_2_CPHY ; + hwcfg->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes; +break ;case V4L2_MBUS_CSI1 :case V4L2_MBUS_CCP2 : hwcfg->csi_signalling_mode = (bus_cfg.bus.mipi_csi1.strobe) ?
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 96/106 ccs: Remove analogue gain field
In reply to Sakari AilusThe analogue gain control was stored to the device specific struct but was never used. Remove it.
--- drivers/media/i2c/ccs/ccs-core.c | 13 ++++++------- drivers/media/i2c/ccs/ccs.h | 1 - 2 files changed, 6 insertions(+), 8 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +6 -7
@@ -778,13 +778,12 @@ static int ccs_init_controls(struct ccs_sensor *sensor) sensor->pixel_array->ctrl_handler.lock = &sensor->mutex; - sensor->analog_gain =v4l2_ctrl_new_std ( - &sensor->pixel_array->ctrl_handler, &ccs_ctrl_ops, -V4L2_CID_ANALOGUE_GAIN , -CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN ), -CCS_LIM (sensor,ANALOG_GAIN_CODE_MAX ), -max (CCS_LIM (sensor,ANALOG_GAIN_CODE_STEP ),1U ), -CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN )); +v4l2_ctrl_new_std (&sensor->pixel_array->ctrl_handler, &ccs_ctrl_ops, +V4L2_CID_ANALOGUE_GAIN , +CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN ), +CCS_LIM (sensor,ANALOG_GAIN_CODE_MAX ), +max (CCS_LIM (sensor,ANALOG_GAIN_CODE_STEP ),1U ), +CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN )); if (CCS_LIM(sensor, DIGITAL_GAIN_CAPABILITY) == CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL ||
drivers/media/i2c/ccs/ccs.h +0 -1
@@ -262,7 +262,6 @@ struct ccs_sensor {unsigned long *valid_link_freqs;/* Pixel array controls */ -struct v4l2_ctrl *analog_gain;struct v4l2_ctrl *exposure;struct v4l2_ctrl *hflip;struct v4l2_ctrl *vflip;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 98/106 v4l: uapi: Add user control base for CCS controls
In reply to Sakari AilusAdd a control base for CCS controls, and reserve 128 controls. Luckily these numbers are cheap.
--- include/uapi/linux/v4l2-controls.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/uapi/linux/v4l2-controls.h +6 -0
@@ -198,6 +198,12 @@ enum v4l2_colorfx {*/ #define V4L2_CID_USER_ATMEL_ISC_BASE (V4L2_CID_USER_BASE + 0x10c0) +/* +* The base for MIPI CCS driver controls. +* We reserve 128 controls for this driver. +*/ +#define V4L2_CID_USER_CCS_BASE (V4L2_CID_USER_BASE + 0x10e0) +/* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 100/106 ccs: Add support for analogue gain coefficient controls
In reply to Sakari AilusAdd four controls for reading CCS analogue gain coefficients. The values are constants that are device specific.
--- drivers/media/i2c/ccs/ccs-core.c | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +36 -2
@@ -28,6 +28,7 @@#include <linux/v4l2-mediabus.h> #include <media/v4l2-fwnode.h> #include <media/v4l2-device.h> +#include <uapi/linux/ccs.h> #include "ccs.h"
@@ -772,14 +773,46 @@ static int ccs_init_controls(struct ccs_sensor *sensor)struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);int rval; - rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,13 ); + rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,17 );if (rval)return rval; sensor->pixel_array->ctrl_handler.lock = &sensor->mutex;switch (CCS_LIM (sensor,ANALOG_GAIN_CAPABILITY )) { -case CCS_ANALOG_GAIN_CAPABILITY_GLOBAL : +case CCS_ANALOG_GAIN_CAPABILITY_GLOBAL : { +struct { +const char *name; +u32 id; +s32 value; + }const gain_ctrls[] = { + {"Analogue Gain m0" ,V4L2_CID_CCS_ANALOGUE_GAIN_M0 , +CCS_LIM (sensor,ANALOG_GAIN_M0 ), }, + {"Analogue Gain c0" ,V4L2_CID_CCS_ANALOGUE_GAIN_C0 , +CCS_LIM (sensor,ANALOG_GAIN_C0 ), }, + {"Analogue Gain m1" ,V4L2_CID_CCS_ANALOGUE_GAIN_M1 , +CCS_LIM (sensor,ANALOG_GAIN_M1 ), }, + {"Analogue Gain c1" ,V4L2_CID_CCS_ANALOGUE_GAIN_C1 , +CCS_LIM (sensor,ANALOG_GAIN_C1 ), }, + }; +struct v4l2_ctrl_config ctrl_cfg = { + .type =V4L2_CTRL_TYPE_INTEGER , + .ops = &ccs_ctrl_ops, + .flags =V4L2_CTRL_FLAG_READ_ONLY , + .step =1 , + }; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (gain_ctrls); i++) { + ctrl_cfg.name = gain_ctrls[i].name; + ctrl_cfg.id = gain_ctrls[i].id; + ctrl_cfg.min = ctrl_cfg.max = ctrl_cfg.def = + gain_ctrls[i].value; + +v4l2_ctrl_new_custom (&sensor->pixel_array->ctrl_handler, + &ctrl_cfg,NULL ); + } + v4l2_ctrl_new_std(&sensor->pixel_array->ctrl_handler, &ccs_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, CCS_LIM(sensor, ANALOG_GAIN_CODE_MIN),
@@ -788,6 +821,7 @@ static int ccs_init_controls(struct ccs_sensor *sensor) 1U), CCS_LIM(sensor, ANALOG_GAIN_CODE_MIN)); } + } if (CCS_LIM(sensor, DIGITAL_GAIN_CAPABILITY) == CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL ||
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 101/106 v4l: uapi: ccs: Add controls for CCS alternative analogue gain
In reply to Sakari AilusAdd two new controls for alternative analogue gain some CCS compliant camera sensors support.
--- include/uapi/linux/ccs.h | 2 ++ 1 file changed, 2 insertions(+)
include/uapi/linux/ccs.h +2 -0
@@ -10,5 +10,7 @@#define V4L2_CID_CCS_ANALOGUE_GAIN_C0 (V4L2_CID_USER_CCS_BASE + 2)#define V4L2_CID_CCS_ANALOGUE_GAIN_M1 (V4L2_CID_USER_CCS_BASE + 3)#define V4L2_CID_CCS_ANALOGUE_GAIN_C1 (V4L2_CID_USER_CCS_BASE + 4) +#define V4L2_CID_CCS_ANALOGUE_LINEAR_GAIN (V4L2_CID_USER_CCS_BASE + 5) +#define V4L2_CID_CCS_ANALOGUE_EXPONENTIAL_GAIN (V4L2_CID_USER_CCS_BASE + 6)#endif
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 102/106 ccs: Add support for alternate analogue global gain
In reply to Sakari AilusThe CCS spec defines an alternative implementation for global analogue gain. Add support for that in the driver.
--- drivers/media/i2c/ccs/ccs-core.c | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +55 -0
@@ -674,6 +674,17 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)break ; +case V4L2_CID_CCS_ANALOGUE_LINEAR_GAIN : + rval =ccs_write (sensor,ANALOG_LINEAR_GAIN_GLOBAL , ctrl->val); + +break ; + +case V4L2_CID_CCS_ANALOGUE_EXPONENTIAL_GAIN : + rval =ccs_write (sensor,ANALOG_EXPONENTIAL_GAIN_GLOBAL , + ctrl->val); + +break ; +case V4L2_CID_DIGITAL_GAIN :if (CCS_LIM (sensor,DIGITAL_GAIN_CAPABILITY ) ==CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL ) {
@@ -820,6 +831,50 @@ static int ccs_init_controls(struct ccs_sensor *sensor)max (CCS_LIM (sensor,ANALOG_GAIN_CODE_STEP ),1U ), CCS_LIM(sensor, ANALOG_GAIN_CODE_MIN)); + } +break ; + +case CCS_ANALOG_GAIN_CAPABILITY_ALTERNATE_GLOBAL : { +struct { +const char *name; +u32 id; +u16 min, max, step; + }const gain_ctrls[] = { + { +"Analogue Linear Gain" , +V4L2_CID_CCS_ANALOGUE_LINEAR_GAIN , +CCS_LIM (sensor,ANALOG_LINEAR_GAIN_MIN ), +CCS_LIM (sensor,ANALOG_LINEAR_GAIN_MAX ), +max (CCS_LIM (sensor, +ANALOG_LINEAR_GAIN_STEP_SIZE ), +1U ), + }, + { +"Analogue Exponential Gain" , +V4L2_CID_CCS_ANALOGUE_EXPONENTIAL_GAIN , +CCS_LIM (sensor,ANALOG_EXPONENTIAL_GAIN_MIN ), +CCS_LIM (sensor,ANALOG_EXPONENTIAL_GAIN_MAX ), +max (CCS_LIM (sensor, +ANALOG_EXPONENTIAL_GAIN_STEP_SIZE ), +1U ), + }, + }; +struct v4l2_ctrl_config ctrl_cfg = { + .type =V4L2_CTRL_TYPE_INTEGER , + .ops = &ccs_ctrl_ops, + }; +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (gain_ctrls); i++) { + ctrl_cfg.name = gain_ctrls[i].name; + ctrl_cfg.min = ctrl_cfg.def = gain_ctrls[i].min; + ctrl_cfg.max = gain_ctrls[i].max; + ctrl_cfg.step = gain_ctrls[i].step; + ctrl_cfg.id = gain_ctrls[i].id; + +v4l2_ctrl_new_custom (&sensor->pixel_array->ctrl_handler, + &ctrl_cfg,NULL ); + } } }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 104/106 v4l: uapi: ccs: Add CCS controls for shading correction
In reply to Sakari AilusAdd V4L2 controls for controlling CCS lens shading correction as well as conveying its capabilities.
--- include/uapi/linux/ccs.h | 5 +++++ 1 file changed, 5 insertions(+)
include/uapi/linux/ccs.h +5 -0
@@ -12,5 +12,10 @@#define V4L2_CID_CCS_ANALOGUE_GAIN_C1 (V4L2_CID_USER_CCS_BASE + 4)#define V4L2_CID_CCS_ANALOGUE_LINEAR_GAIN (V4L2_CID_USER_CCS_BASE + 5)#define V4L2_CID_CCS_ANALOGUE_EXPONENTIAL_GAIN (V4L2_CID_USER_CCS_BASE + 6) +#define V4L2_CID_CCS_SHADING_CORRECTION_CAPABILITY (V4L2_CID_USER_CCS_BASE + 7) +#define V4L2_CCS_SHADING_CORRECTION_COLOUR (1U << 0) +#define V4L2_CCS_SHADING_CORRECTION_LUMINANCE (1U << 1) +#define V4L2_CID_CCS_SHADING_CORRECTION (V4L2_CID_USER_CCS_BASE + 8) +#define V4L2_CID_CCS_LUMINANCE_SHADING_CORRECTION (V4L2_CID_USER_CCS_BASE + 9)#endif
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 106/106 ccs: Add CCS ACPI device ID
In reply to Sakari AilusThe CCS compliant sensors use device ID "MIPI0200". Use this id for ACPI device matching.
--- drivers/media/i2c/ccs/ccs-core.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +7 -0
@@ -3604,6 +3604,12 @@ static const struct ccs_device smia_device = {static const struct ccs_device ccs_device = {}; +static const struct acpi_device_id ccs_acpi_table[] = { + { .id ="MIPI0200" , .driver_data = (unsigned long )&ccs_device }, + { }, +}; +MODULE_DEVICE_TABLE (acpi, ccs_acpi_table); +static const struct of_device_id ccs_of_table[] = { { .compatible ="mipi-ccs-1.1" , .data = &ccs_device }, { .compatible ="mipi-ccs-1.0" , .data = &ccs_device },
@@ -3620,6 +3626,7 @@ static const struct dev_pm_ops ccs_pm_ops = {static struct i2c_driver ccs_i2c_driver = { .driver = { + .acpi_match_table = ccs_acpi_table, .of_match_table = ccs_of_table, .name =CCS_NAME , .pm = &ccs_pm_ops,
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 99/106 v4l: uapi: ccs: Add controls for analogue gain constants
In reply to Sakari AilusAdd a V4L2 controls for analogue gai constants required to control analogue gain. The values are device specific and thus need to be obtained from the driver.
--- MAINTAINERS | 1 + include/uapi/linux/ccs.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 include/uapi/linux/ccs.h
MAINTAINERS +1 -0
@@ -11569,6 +11569,7 @@ F: drivers/media/i2c/ccs/ F: drivers/media/i2c/ccs-pll.c F: drivers/media/i2c/ccs-pll.h F: include/uapi/linux/smiapp.h +F: include/uapi/linux/ccs.h MIPS M: Thomas Bogendoerfer <[email protected]>
include/uapi/linux/ccs.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only AND BSD-3-Clause */ +/* Copyright (C) 2020 Intel Corporation */ + +#ifndef __UAPI_CCS_H__ +#define __UAPI_CCS_H__ + +#include <linux/videodev2.h> + +#define V4L2_CID_CCS_ANALOGUE_GAIN_M0 (V4L2_CID_USER_CCS_BASE + 1) +#define V4L2_CID_CCS_ANALOGUE_GAIN_C0 (V4L2_CID_USER_CCS_BASE + 2) +#define V4L2_CID_CCS_ANALOGUE_GAIN_M1 (V4L2_CID_USER_CCS_BASE + 3) +#define V4L2_CID_CCS_ANALOGUE_GAIN_C1 (V4L2_CID_USER_CCS_BASE + 4) + +#endif
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 105/106 ccs: Add shading correction and luminance correction level controls
In reply to Sakari AilusAdd controls for supporting lens shading correction.
--- drivers/media/i2c/ccs/ccs-core.c | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +74 -0
@@ -757,6 +757,25 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)case V4L2_CID_TEST_PATTERN_GREENB : rval =ccs_write (sensor,TEST_DATA_GREENB , ctrl->val); +break ; +case V4L2_CID_CCS_SHADING_CORRECTION : +if (!(CCS_LIM (sensor,SHADING_CORRECTION_CAPABILITY ) & + (CCS_SHADING_CORRECTION_CAPABILITY_COLOR_SHADING | +CCS_SHADING_CORRECTION_CAPABILITY_LUMINANCE_CORRECTION ))) +break ; + + rval =ccs_write (sensor,SHADING_CORRECTION_EN , + ctrl->val ?CCS_SHADING_CORRECTION_EN_ENABLE : +0 ); + +break ; +case V4L2_CID_CCS_LUMINANCE_SHADING_CORRECTION : +if (!(CCS_LIM (sensor,SHADING_CORRECTION_CAPABILITY ) & +CCS_SHADING_CORRECTION_CAPABILITY_LUMINANCE_CORRECTION )) +break ; + + rval =ccs_write (sensor,LUMINANCE_CORRECTION_LEVEL , ctrl->val); +break ;case V4L2_CID_PIXEL_RATE :/* For v4l2_ctrl_s_ctrl_int64() used internally. */
@@ -878,6 +897,61 @@ static int ccs_init_controls(struct ccs_sensor *sensor) } } +if (CCS_LIM (sensor,SHADING_CORRECTION_CAPABILITY ) & +CCS_SHADING_CORRECTION_CAPABILITY_COLOR_SHADING ) { +const struct v4l2_ctrl_config ctrl_cfg = { + .name ="Shading Correction" , + .type =V4L2_CTRL_TYPE_BOOLEAN , + .id =V4L2_CID_CCS_SHADING_CORRECTION , + .ops = &ccs_ctrl_ops, + .max =1 , + .step =1 , + }; + +v4l2_ctrl_new_custom (&sensor->pixel_array->ctrl_handler, + &ctrl_cfg,NULL ); + } + +if (CCS_LIM (sensor,SHADING_CORRECTION_CAPABILITY ) & +CCS_SHADING_CORRECTION_CAPABILITY_LUMINANCE_CORRECTION ) { +const struct v4l2_ctrl_config ctrl_cfg = { + .name ="Luminance Shading Correction" , + .type =V4L2_CTRL_TYPE_BOOLEAN , + .id =V4L2_CID_CCS_LUMINANCE_SHADING_CORRECTION , + .ops = &ccs_ctrl_ops, + .max =255 , + .step =1 , + .def =128 , + }; + +v4l2_ctrl_new_custom (&sensor->pixel_array->ctrl_handler, + &ctrl_cfg,NULL ); + } + +if (CCS_LIM (sensor,SHADING_CORRECTION_CAPABILITY ) & + (CCS_SHADING_CORRECTION_CAPABILITY_COLOR_SHADING | +CCS_SHADING_CORRECTION_CAPABILITY_LUMINANCE_CORRECTION )) { +u32 val = + ((CCS_LIM (sensor,SHADING_CORRECTION_CAPABILITY ) & +CCS_SHADING_CORRECTION_CAPABILITY_COLOR_SHADING ) ? +V4L2_CCS_SHADING_CORRECTION_COLOUR :0 ) | + ((CCS_LIM (sensor,SHADING_CORRECTION_CAPABILITY ) & +CCS_SHADING_CORRECTION_CAPABILITY_LUMINANCE_CORRECTION ) ? +V4L2_CCS_SHADING_CORRECTION_LUMINANCE :0 ); +const struct v4l2_ctrl_config ctrl_cfg = { + .name ="Shading Correction Capability" , + .type =V4L2_CTRL_TYPE_BITMASK , + .id =V4L2_CID_CCS_SHADING_CORRECTION_CAPABILITY , + .ops = &ccs_ctrl_ops, + .max = val, + .def = val, + .flags =V4L2_CTRL_FLAG_READ_ONLY , + }; + +v4l2_ctrl_new_custom (&sensor->pixel_array->ctrl_handler, + &ctrl_cfg,NULL ); + } +if (CCS_LIM (sensor,DIGITAL_GAIN_CAPABILITY ) ==CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL || CCS_LIM(sensor, DIGITAL_GAIN_CAPABILITY) ==
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 97/106 ccs: Only add analogue gain control if the device supports it
In reply to Sakari AilusSome devices do not implement analogue gain this way. Only add the control when a device does have the support.
--- drivers/media/i2c/ccs/ccs-core.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +10 -6
@@ -778,12 +778,16 @@ static int ccs_init_controls(struct ccs_sensor *sensor) sensor->pixel_array->ctrl_handler.lock = &sensor->mutex; -v4l2_ctrl_new_std (&sensor->pixel_array->ctrl_handler, &ccs_ctrl_ops, -V4L2_CID_ANALOGUE_GAIN , -CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN ), -CCS_LIM (sensor,ANALOG_GAIN_CODE_MAX ), -max (CCS_LIM (sensor,ANALOG_GAIN_CODE_STEP ),1U ), -CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN )); +switch (CCS_LIM (sensor,ANALOG_GAIN_CAPABILITY )) { +case CCS_ANALOG_GAIN_CAPABILITY_GLOBAL : +v4l2_ctrl_new_std (&sensor->pixel_array->ctrl_handler, + &ccs_ctrl_ops,V4L2_CID_ANALOGUE_GAIN , +CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN ), +CCS_LIM (sensor,ANALOG_GAIN_CODE_MAX ), +max (CCS_LIM (sensor,ANALOG_GAIN_CODE_STEP ), +1U ), +CCS_LIM (sensor,ANALOG_GAIN_CODE_MIN )); + } if (CCS_LIM(sensor, DIGITAL_GAIN_CAPABILITY) == CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL ||
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 103/106 ccs: Add debug prints for MSR registers
In reply to Sakari AilusAlso print out MSR registers written to the sensor. This isn't entirely optimal as the debug strings are produced even if they're not used but that isn't really a grave issue --- the I²C bus is very slow anyway.
--- drivers/media/i2c/ccs/ccs-reg-access.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/i2c/ccs/ccs-reg-access.c +8 -0
@@ -387,12 +387,20 @@ int ccs_write_data_regs(struct ccs_sensor *sensor, struct ccs_reg *regs,for (j =0 ; j < regs->len; j += msg.len -2 , regdata += msg.len -2 ) { +char printbuf[(MAX_WRITE_LEN <<1 ) +1 /* nil */ ] = + {0 };int rval; msg.len =min (regs->len - j,MAX_WRITE_LEN ); +bin2hex (printbuf, regdata, msg.len); +dev_dbg (&client->dev, +"writing msr reg 0x%4.4x value 0x%s\n" , + regs->addr + j, printbuf); +put_unaligned_be16 (regs->addr + j, buf);memcpy (buf +2 , regdata, msg.len); + msg.len +=2 ; rval =ccs_write_retry (client, &msg);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 95/106 ccs: Add support for old-style SMIA digital gain
In reply to Sakari AilusSMIA only has per-component digital gain. Add support for it.
--- drivers/media/i2c/ccs/ccs-core.c | 33 +++++++++++++++++++++++-- drivers/media/i2c/ccs/smiapp-reg-defs.h | 2 ++ 2 files changed, 33 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +31 -2
@@ -674,7 +674,34 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_DIGITAL_GAIN : - rval =ccs_write (sensor,DIGITAL_GAIN_GLOBAL , ctrl->val); +if (CCS_LIM (sensor,DIGITAL_GAIN_CAPABILITY ) == +CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL ) { + rval =ccs_write (sensor,DIGITAL_GAIN_GLOBAL , + ctrl->val); +break ; + } + + rval =ccs_write_addr (sensor, +SMIAPP_REG_U16_DIGITAL_GAIN_GREENR , + ctrl->val); +if (rval) +break ; + + rval =ccs_write_addr (sensor, +SMIAPP_REG_U16_DIGITAL_GAIN_RED , + ctrl->val); +if (rval) +break ; + + rval =ccs_write_addr (sensor, +SMIAPP_REG_U16_DIGITAL_GAIN_BLUE , + ctrl->val); +if (rval) +break ; + + rval =ccs_write_addr (sensor, +SMIAPP_REG_U16_DIGITAL_GAIN_GREENB , + ctrl->val);break ;case V4L2_CID_EXPOSURE :
@@ -760,7 +787,9 @@ static int ccs_init_controls(struct ccs_sensor *sensor) CCS_LIM(sensor, ANALOG_GAIN_CODE_MIN));if (CCS_LIM (sensor,DIGITAL_GAIN_CAPABILITY ) == -CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL ) +CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL || +CCS_LIM (sensor,DIGITAL_GAIN_CAPABILITY ) == +SMIAPP_DIGITAL_GAIN_CAPABILITY_PER_CHANNEL ) v4l2_ctrl_new_std(&sensor->pixel_array->ctrl_handler, &ccs_ctrl_ops, V4L2_CID_DIGITAL_GAIN, CCS_LIM(sensor, DIGITAL_GAIN_MIN),
drivers/media/i2c/ccs/smiapp-reg-defs.h +2 -0
@@ -535,6 +535,8 @@#define SMIAPP_DIGITAL_CROP_CAPABILITY_NONE 0#define SMIAPP_DIGITAL_CROP_CAPABILITY_INPUT_CROP 1 +#define SMIAPP_DIGITAL_GAIN_CAPABILITY_PER_CHANNEL 1 +#define SMIAPP_BINNING_CAPABILITY_NO 0#define SMIAPP_BINNING_CAPABILITY_YES 1
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 75/106 ccs-pll: Support two cycles per pixel on OP domain
In reply to Sakari AilusThe l parameter defines the number of clock cycles to process a single pixel per OP lane. It is calculated based on a new register op_bits_per_lane.
--- drivers/media/i2c/ccs-pll.c | 19 +++++++++++++------ drivers/media/i2c/ccs-pll.h | 2 ++ drivers/media/i2c/ccs/ccs-core.c | 1 + 3 files changed, 16 insertions(+), 6 deletions(-)
drivers/media/i2c/ccs-pll.c +13 -6
@@ -162,7 +162,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,const struct ccs_pll_branch_limits_bk *op_lim_bk, struct ccs_pll *pll, struct ccs_pll_branch_fr *op_pll_fr, struct ccs_pll_branch_bk *op_pll_bk, uint32_t mul, - uint32_t div) + uint32_t div, uint32_t l) { uint32_t sys_div;uint32_t best_pix_div =INT_MAX >>1 ;
@@ -252,10 +252,15 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_fr->pll_op_clk_freq_hz = op_pll_fr->pll_ip_clk_freq_hz * op_pll_fr->pll_multiplier; - op_pll_bk->pix_clk_div = pll->bits_per_pixel - * pll->op_lanes / pll->csi2.lanes; +if (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ) + op_pll_bk->pix_clk_div = pll->bits_per_pixel + * pll->op_lanes / pll->csi2.lanes / l; +else + op_pll_bk->pix_clk_div = pll->bits_per_pixel / l; + op_pll_bk->pix_clk_freq_hz = op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div; +dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div);if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) {
@@ -291,7 +296,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,dev_dbg (dev,"scale_m: %u\n" , pll->scale_m); min_vt_div =DIV_ROUND_UP (op_pll_bk->pix_clk_div * op_pll_bk->sys_clk_div * pll->scale_n - * pll->vt_lanes, + * pll->vt_lanes * l, pll->op_lanes * vt_op_binning_div * pll->scale_m);
@@ -406,6 +411,8 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,uint16_t min_op_pre_pll_clk_div;uint16_t max_op_pre_pll_clk_div;uint32_t mul, div; +uint32_t l = (!pll->op_bits_per_lane || + pll->op_bits_per_lane >= pll->bits_per_pixel) ?1 :2 ;uint32_t i;int rval = -EINVAL ;
@@ -444,7 +451,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->pixel_rate_csi = op_pll_bk->pix_clk_freq_hz * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? - pll->csi2.lanes :1 ); + pll->csi2.lanes :1 ) / l;/* Figure out limits for OP pre-pll divider based on extclk */ dev_dbg(dev, "min / max op_pre_pll_clk_div: %u / %u\n",
@@ -482,7 +489,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, (pll->flags & CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER) ? 1 : 2 - (op_pll_fr->pre_pll_clk_div & 1)) { rval =__ccs_pll_calculate (dev, lim, op_lim_fr, op_lim_bk, pll, - op_pll_fr, op_pll_bk, mul, div); + op_pll_fr, op_pll_bk, mul, div, l);if (rval)continue ;
drivers/media/i2c/ccs-pll.h +2 -0
@@ -75,6 +75,7 @@ struct ccs_pll_branch_bk {* @scale_m: Downscaling factor, M component, [16, max] (input) * @scale_n: Downscaling factor, N component, typically 16 (input) * @bits_per_pixel: Bits per pixel on the output data bus (input) +* @op_bits_per_lane: Number of bits per OP lane (input) * @flags: CCS_PLL_FLAG_* (input) * @link_freq: Chosen link frequency (input) * @ext_clk_freq_hz: External clock frequency, i.e. the sensor's input clock
@@ -99,6 +100,7 @@ struct ccs_pll {uint8_t scale_m;uint8_t scale_n;uint8_t bits_per_pixel; +uint8_t op_bits_per_lane;uint16_t flags;uint32_t link_freq;uint32_t ext_clk_freq_hz;
drivers/media/i2c/ccs/ccs-core.c +1 -0
@@ -3214,6 +3214,7 @@ static int ccs_probe(struct i2c_client *client)if (CCS_LIM (sensor,CLOCK_TREE_PLL_CAPABILITY ) &CCS_CLOCK_TREE_PLL_CAPABILITY_EXT_DIVIDER ) sensor->pll.flags |=CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER ; + sensor->pll.op_bits_per_lane =CCS_LIM (sensor,OP_BITS_PER_LANE ); sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 92/106 ccs-pll: Print pixel rates
In reply to Sakari AilusPrint pixel rates on CSI-2 bus as well as in pixel array as the variation allowed in PLL capabilities makes this non-trivial to figure out otherwise.
--- drivers/media/i2c/ccs-pll.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/i2c/ccs-pll.c +5 -0
@@ -119,6 +119,11 @@ static void print_pll(struct device *dev, struct ccs_pll *pll) } } +dev_dbg (dev,"pixel rate in pixel array:\t%u\n" , + pll->pixel_rate_pixel_array); +dev_dbg (dev,"pixel rate on CSI-2 bus:\t%u\n" , + pll->pixel_rate_csi); + dev_dbg(dev, "flags%s%s%s%s%s%s%s%s%s\n", pll->flags & PLL_FL(LANE_SPEED_MODEL) ? " lane-speed" : "", pll->flags & PLL_FL(LINK_DECOUPLED) ? " link-decoupled" : "",
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 94/106 ccs: Add digital gain support
In reply to Sakari AilusCCS supports global (all-component) digital gain. Add support for it.
--- drivers/media/i2c/ccs/ccs-core.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +16 -1
@@ -671,6 +671,11 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)case V4L2_CID_ANALOGUE_GAIN : rval =ccs_write (sensor,ANALOG_GAIN_CODE_GLOBAL , ctrl->val); +break ; + +case V4L2_CID_DIGITAL_GAIN : + rval =ccs_write (sensor,DIGITAL_GAIN_GLOBAL , ctrl->val); +break ;case V4L2_CID_EXPOSURE : rval =ccs_write (sensor,COARSE_INTEGRATION_TIME , ctrl->val);
@@ -740,7 +745,7 @@ static int ccs_init_controls(struct ccs_sensor *sensor)struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);int rval; - rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,12 ); + rval =v4l2_ctrl_handler_init (&sensor->pixel_array->ctrl_handler,13 );if (rval)return rval;
@@ -754,6 +759,16 @@ static int ccs_init_controls(struct ccs_sensor *sensor)max (CCS_LIM (sensor,ANALOG_GAIN_CODE_STEP ),1U ), CCS_LIM(sensor, ANALOG_GAIN_CODE_MIN)); +if (CCS_LIM (sensor,DIGITAL_GAIN_CAPABILITY ) == +CCS_DIGITAL_GAIN_CAPABILITY_GLOBAL ) +v4l2_ctrl_new_std (&sensor->pixel_array->ctrl_handler, + &ccs_ctrl_ops,V4L2_CID_DIGITAL_GAIN , +CCS_LIM (sensor,DIGITAL_GAIN_MIN ), +CCS_LIM (sensor,DIGITAL_GAIN_MAX ), +max (CCS_LIM (sensor,DIGITAL_GAIN_STEP_SIZE ), +1U ), +0x100 ); +/* Exposure limits will be updated soon, use just something here. */ sensor->exposure = v4l2_ctrl_new_std( &sensor->pixel_array->ctrl_handler, &ccs_ctrl_ops,
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 90/106 ccs: Add support for DDR OP SYS and OP PIX clocks
In reply to Sakari AilusSupport dual data rate operational system and pixel clocks by conveying the flags to the PLL calculator and updating how the link rate is calculated.
--- drivers/media/i2c/ccs/ccs-core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +8 -1
@@ -388,7 +388,8 @@ static int ccs_pll_configure(struct ccs_sensor *sensor)DIV_ROUND_UP (pll->op_bk.sys_clk_freq_hz,1000000 /256 /256 ) * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? - sensor->pll.csi2.lanes : 1)); + sensor->pll.csi2.lanes :1 ) << + (pll->flags & CCS_PLL_FLAG_OP_SYS_DDR ? 1 : 0));if (rval <0 || sensor->pll.flags &CCS_PLL_FLAG_NO_OP_CLOCKS )return rval;
@@ -3265,6 +3266,12 @@ static int ccs_probe(struct i2c_client *client) }else { sensor->pll.flags |=CCS_PLL_FLAG_DUAL_PLL ; } +if (CCS_LIM (sensor,CLOCK_CALCULATION ) & +CCS_CLOCK_CALCULATION_DUAL_PLL_OP_SYS_DDR ) + sensor->pll.flags |=CCS_PLL_FLAG_OP_SYS_DDR ; +if (CCS_LIM (sensor,CLOCK_CALCULATION ) & +CCS_CLOCK_CALCULATION_DUAL_PLL_OP_PIX_DDR ) + sensor->pll.flags |=CCS_PLL_FLAG_OP_PIX_DDR ; } sensor->pll.op_bits_per_lane =CCS_LIM (sensor,OP_BITS_PER_LANE ); sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 88/106 ccs: Dual PLL support
In reply to Sakari AilusAdd support for sensors that either require dual PLL or support single or dual PLL but use dual PLL as default.
Use sensor default configuration for sensors that support both modes.
--- drivers/media/i2c/ccs-pll.c | 9 +++++-- drivers/media/i2c/ccs/ccs-core.c | 45 +++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-)
drivers/media/i2c/ccs-pll.c +7 -2
@@ -331,7 +331,10 @@ __ccs_pll_calculate_vt_tree(struct device *dev,continue ; } -if (pix_div * sys_div <= best_div) { +dev_dbg (dev,"sys/pix/best_pix: %u,%u,%u\n" , sys_div, pix_div, + best_pix_div); + +if (pix_div * sys_div <= best_pix_div) { best_pix_div = pix_div; best_div = pix_div * sys_div; }
@@ -804,7 +807,9 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,if (rval)continue ; - rval =check_fr_bounds (dev, lim, pll,PLL_VT ); + rval =check_fr_bounds (dev, lim, pll, + pll->flags &CCS_PLL_FLAG_DUAL_PLL ? +PLL_OP :PLL_VT );if (rval)continue ;
drivers/media/i2c/ccs/ccs-core.c +44 -1
63 lines not on this page · raw message
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 65/106 ccs-pll: Begin calculation from OP system clock frequency
In reply to Sakari AilusThe OP system clock frequency defines the CSI-2 bus clock frequency, not the PLL output clock frequency. Both values were overwritten in the end, but the wrong limit value was used for the OP system clock frequency, possibly leading to too high frequencies being used.
Also remove now duplicated calculation of OP system clock frequency later in the PLL calculator.
--- drivers/media/i2c/ccs-pll.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/media/i2c/ccs-pll.c +4 -8
@@ -247,10 +247,6 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_fr->pll_op_clk_freq_hz = op_pll_fr->pll_ip_clk_freq_hz * op_pll_fr->pll_multiplier; -/* Derive pll_op_clk_freq_hz. */ - op_pll_bk->sys_clk_freq_hz = - op_pll_fr->pll_op_clk_freq_hz / op_pll_bk->sys_clk_div; - op_pll_bk->pix_clk_div = pll->bits_per_pixel;dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div);
@@ -432,7 +428,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,switch (pll->bus_type) {case CCS_PLL_BUS_TYPE_CSI2_DPHY :/* CSI transfers 2 bits per clock per lane; thus times 2 */ - op_pll_fr->pll_op_clk_freq_hz = pll->link_freq *2 + op_pll_bk->sys_clk_freq_hz = pll->link_freq *2 * (pll->csi2.lanes / lane_op_clock_ratio);break ;default :
@@ -454,8 +450,8 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,dev_dbg (dev,"pre-pll check: min / max op_pre_pll_clk_div: %u / %u\n" , min_op_pre_pll_clk_div, max_op_pre_pll_clk_div); - i =gcd (op_pll_fr->pll_op_clk_freq_hz, pll->ext_clk_freq_hz); - mul = op_pll_fr->pll_op_clk_freq_hz / i; + i =gcd (op_pll_bk->sys_clk_freq_hz, pll->ext_clk_freq_hz); + mul = op_pll_bk->sys_clk_freq_hz / i; div = pll->ext_clk_freq_hz / i;dev_dbg (dev,"mul %u / div %u\n" , mul, div);
@@ -463,7 +459,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,max_t (uint16_t, min_op_pre_pll_clk_div,clk_div_even_up (DIV_ROUND_UP (mul * pll->ext_clk_freq_hz, - op_lim_fr->max_pll_op_clk_freq_hz))); + op_lim_bk->max_sys_clk_freq_hz)));dev_dbg (dev,"pll_op check: min / max op_pre_pll_clk_div: %u / %u\n" , min_op_pre_pll_clk_div, max_op_pre_pll_clk_div);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 87/106 ccs-pll: Add trivial dual PLL support
In reply to Sakari AilusAdd support for sensors that have separate VT and OP domain PLLs.
This support is trivial in the sense that it aims for the same VT pixel rate than that on the CSI-2 bus. The vast majority of sensors is better supported by higher frequencies in VT domain in binned and possibly scaled configurations.
--- drivers/media/i2c/ccs-pll.c | 217 ++++++++++++++++++++++++++++++++---- drivers/media/i2c/ccs-pll.h | 1 + 2 files changed, 196 insertions(+), 22 deletions(-)
drivers/media/i2c/ccs-pll.c +195 -22
@@ -92,7 +92,8 @@ static void print_pll(struct device *dev, struct ccs_pll *pll)for (i =0 , br = branches; i <ARRAY_SIZE (branches); i++, br++) {const char *s =pll_string (br->which); -if (br->which ==PLL_VT ) { +if (pll->flags &CCS_PLL_FLAG_DUAL_PLL || + br->which ==PLL_VT ) {dev_dbg (dev,"%s_pre_pll_clk_div\t\t%u\n" , s, br->fr->pre_pll_clk_div); dev_dbg(dev, "%s_pll_multiplier\t\t%u\n", s,
@@ -118,7 +119,7 @@ static void print_pll(struct device *dev, struct ccs_pll *pll) } } - dev_dbg(dev, "flags%s%s%s%s%s%s\n", + dev_dbg(dev, "flags%s%s%s%s%s%s%s\n", pll->flags & PLL_FL(LANE_SPEED_MODEL) ? " lane-speed" : "", pll->flags & PLL_FL(LINK_DECOUPLED) ? " link-decoupled" : "", pll->flags & PLL_FL(EXT_IP_PLL_DIVIDER) ?
@@ -126,7 +127,8 @@ static void print_pll(struct device *dev, struct ccs_pll *pll) pll->flags &PLL_FL (FLEXIBLE_OP_PIX_CLK_DIV ) ?" flexible-op-pix-div" :"" , pll->flags &PLL_FL (FIFO_DERATING ) ?" fifo-derating" :"" , - pll->flags & PLL_FL(FIFO_OVERRATING) ? " fifo-overrating" : ""); + pll->flags &PLL_FL (FIFO_OVERRATING ) ?" fifo-overrating" :"" , + pll->flags & PLL_FL(DUAL_PLL) ? " dual-pll" : ""); } static int check_fr_bounds(struct device *dev,
@@ -267,6 +269,152 @@ ccs_pll_find_vt_sys_div(struct device *dev, const struct ccs_pll_limits *lim,#define DPHY_CONST 16#define PHY_CONST_DIV 16 +static inline int +__ccs_pll_calculate_vt_tree (struct device *dev, +const struct ccs_pll_limits *lim, +struct ccs_pll *pll,uint32_t mul,uint32_t div) +{ +const struct ccs_pll_branch_limits_fr *lim_fr = &lim->vt_fr; +const struct ccs_pll_branch_limits_bk *lim_bk = &lim->vt_bk; +struct ccs_pll_branch_fr *pll_fr = &pll->vt_fr; +struct ccs_pll_branch_bk *pll_bk = &pll->vt_bk; +uint32_t more_mul; +uint16_t best_pix_div =SHRT_MAX >>1 , best_div; +uint16_t vt_div, min_sys_div, max_sys_div, sys_div; + + pll_fr->pll_ip_clk_freq_hz = + pll->ext_clk_freq_hz / pll_fr->pre_pll_clk_div; + +dev_dbg (dev,"vt_pll_ip_clk_freq_hz %u\n" , pll_fr->pll_ip_clk_freq_hz); + + more_mul =one_or_more (DIV_ROUND_UP (lim_fr->min_pll_op_clk_freq_hz, + pll_fr->pll_ip_clk_freq_hz * mul)); + +dev_dbg (dev,"more_mul: %u\n" , more_mul); + more_mul *=DIV_ROUND_UP (lim_fr->min_pll_multiplier, mul * more_mul); +dev_dbg (dev,"more_mul2: %u\n" , more_mul); + + pll_fr->pll_multiplier = mul * more_mul; + +if (pll_fr->pll_multiplier * pll_fr->pll_ip_clk_freq_hz > + lim_fr->max_pll_op_clk_freq_hz) +return -EINVAL ; + + pll_fr->pll_op_clk_freq_hz = + pll_fr->pll_ip_clk_freq_hz * pll_fr->pll_multiplier; + + vt_div = div * more_mul; + +ccs_pll_find_vt_sys_div (dev, lim, pll, pll_fr, vt_div, vt_div, + &min_sys_div, &max_sys_div); + + max_sys_div = (vt_div &1 ) ?1 : max_sys_div; + +dev_dbg (dev,"vt min/max_sys_div: %u,%u\n" , min_sys_div, max_sys_div); + +for (sys_div = min_sys_div; sys_div <= max_sys_div; + sys_div +=2 - (sys_div &1 )) { +uint16_t pix_div; + +if (vt_div % sys_div) +continue ; + + pix_div = vt_div / sys_div; + +if (pix_div < lim_bk->min_pix_clk_div || + pix_div > lim_bk->max_pix_clk_div) { +dev_dbg (dev, +"pix_div %u too small or too big (%u--%u)\n" , + pix_div, + lim_bk->min_pix_clk_div, + lim_bk->max_pix_clk_div); +continue ; + } + +if (pix_div * sys_div <= best_div) { + best_pix_div = pix_div; + best_div = pix_div * sys_div; + } + } +if (best_pix_div ==SHRT_MAX >>1 ) +return -EINVAL ; + + pll_bk->sys_clk_div = best_div / best_pix_div; + pll_bk->pix_clk_div = best_pix_div; + + pll_bk->sys_clk_freq_hz = + pll_fr->pll_op_clk_freq_hz / pll_bk->sys_clk_div; + pll_bk->pix_clk_freq_hz = + pll_bk->sys_clk_freq_hz / pll_bk->pix_clk_div; + + pll->pixel_rate_pixel_array = + pll_bk->pix_clk_freq_hz * pll->vt_lanes; + +return 0 ; +} + +static int ccs_pll_calculate_vt_tree (struct device *dev, +const struct ccs_pll_limits *lim, +struct ccs_pll *pll) +{ +const struct ccs_pll_branch_limits_fr *lim_fr = &lim->vt_fr; +struct ccs_pll_branch_fr *pll_fr = &pll->vt_fr; +uint16_t min_pre_pll_clk_div = lim_fr->min_pre_pll_clk_div; +uint16_t max_pre_pll_clk_div = lim_fr->max_pre_pll_clk_div; +uint32_t pre_mul, pre_div; + + pre_div =gcd (pll->pixel_rate_csi, + pll->ext_clk_freq_hz * pll->vt_lanes); + pre_mul = pll->pixel_rate_csi / pre_div; + pre_div = pll->ext_clk_freq_hz * pll->vt_lanes / pre_div; + +/* Make sure PLL input frequency is within limits */ + max_pre_pll_clk_div = +min_t (uint16_t, max_pre_pll_clk_div, +DIV_ROUND_UP (pll->ext_clk_freq_hz, + lim_fr->min_pll_ip_clk_freq_hz)); + + min_pre_pll_clk_div =max_t (uint16_t, min_pre_pll_clk_div, + pll->ext_clk_freq_hz / + lim_fr->max_pll_ip_clk_freq_hz); + +dev_dbg (dev,"vt min/max_pre_pll_clk_div: %u,%u\n" , + min_pre_pll_clk_div, max_pre_pll_clk_div); + +for (pll_fr->pre_pll_clk_div = min_pre_pll_clk_div; + pll_fr->pre_pll_clk_div <= max_pre_pll_clk_div; + pll_fr->pre_pll_clk_div += + (pll->flags &CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER ) ?1 : +2 - (pll_fr->pre_pll_clk_div &1 )) { +uint32_t mul, div; +int rval; + + div =gcd (pre_mul * pll_fr->pre_pll_clk_div, pre_div); + mul = pre_mul * pll_fr->pre_pll_clk_div / div; + div = pre_div / div; + +dev_dbg (dev,"vt pre-div/mul/div: %u,%u,%u\n" , + pll_fr->pre_pll_clk_div, mul, div); + + rval =__ccs_pll_calculate_vt_tree (dev, lim, pll, + mul, div); +if (rval) +continue ; + + rval =check_fr_bounds (dev, lim, pll,PLL_VT ); +if (rval) +continue ; + + rval =check_bk_bounds (dev, lim, pll,PLL_VT ); +if (rval) +continue ; + +return 0 ; + } + +return -EINVAL ; +} + static void ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, const struct ccs_pll_branch_limits_bk *op_lim_bk,
@@ -525,10 +673,10 @@ ccs_pll_calculate_op(struct device *dev, const struct ccs_pll_limits *lim,int ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *lim,struct ccs_pll *pll) { -const struct ccs_pll_branch_limits_fr *op_lim_fr = &lim->vt_fr; -const struct ccs_pll_branch_limits_bk *op_lim_bk = &lim->op_bk; -struct ccs_pll_branch_fr *op_pll_fr = &pll->vt_fr; -struct ccs_pll_branch_bk *op_pll_bk = &pll->op_bk; +const struct ccs_pll_branch_limits_fr *op_lim_fr; +const struct ccs_pll_branch_limits_bk *op_lim_bk; +struct ccs_pll_branch_fr *op_pll_fr; +struct ccs_pll_branch_bk *op_pll_bk;bool cphy = pll->bus_type ==CCS_PLL_BUS_TYPE_CSI2_CPHY ;uint32_t phy_const = cphy ?CPHY_CONST :DPHY_CONST ;uint16_t min_op_pre_pll_clk_div;
@@ -544,6 +692,28 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->vt_lanes =1 ; } +if (pll->flags &CCS_PLL_FLAG_DUAL_PLL ) { + op_lim_fr = &lim->op_fr; + op_lim_bk = &lim->op_bk; + op_pll_fr = &pll->op_fr; + op_pll_bk = &pll->op_bk; + }else if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) { +/* +* If there's no OP PLL at all, use the VT values +* instead. The OP values are ignored for the rest of +* the PLL calculation. +*/ + op_lim_fr = &lim->vt_fr; + op_lim_bk = &lim->vt_bk; + op_pll_fr = &pll->vt_fr; + op_pll_bk = &pll->vt_bk; + }else { + op_lim_fr = &lim->vt_fr; + op_lim_bk = &lim->op_bk; + op_pll_fr = &pll->vt_fr; + op_pll_bk = &pll->op_bk; + } + if (!pll->op_lanes || !pll->vt_lanes || !pll->bits_per_pixel || !pll->ext_clk_freq_hz || !pll->link_freq || !pll->scale_m || !op_lim_fr->min_pll_ip_clk_freq_hz ||
@@ -567,17 +737,6 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,dev_dbg (dev,"vt_lanes: %u\n" , pll->vt_lanes);dev_dbg (dev,"op_lanes: %u\n" , pll->op_lanes); -if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) { -/* -* If there's no OP PLL at all, use the VT values -* instead. The OP values are ignored for the rest of -* the PLL calculation. -*/ - op_lim_fr = &lim->vt_fr; - op_lim_bk = &lim->vt_bk; - op_pll_bk = &pll->vt_bk; - } -dev_dbg (dev,"binning: %ux%u\n" , pll->binning_horizontal, pll->binning_vertical);
@@ -653,6 +812,9 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,if (rval)continue ; +if (pll->flags &CCS_PLL_FLAG_DUAL_PLL ) +break ; +ccs_pll_calculate_vt (dev, lim, op_lim_bk, pll, op_pll_fr, op_pll_bk, cphy, phy_const);
@@ -663,14 +825,25 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,if (rval)continue ; -print_pll (dev, pll); +break ; + } + +if (rval) { +dev_dbg (dev,"unable to compute pre_pll divisor\n" ); -return 0 ; +return rval; } -dev_dbg (dev,"unable to compute pre_pll divisor\n" ); +if (pll->flags &CCS_PLL_FLAG_DUAL_PLL ) { + rval =ccs_pll_calculate_vt_tree (dev, lim, pll); -return rval; +if (rval) +return rval; + } + +print_pll (dev, pll); + +return 0 ; }EXPORT_SYMBOL_GPL (ccs_pll_calculate);
drivers/media/i2c/ccs-pll.h +1 -0
@@ -29,6 +29,7 @@#define CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV BIT(5)#define CCS_PLL_FLAG_FIFO_DERATING BIT(6)#define CCS_PLL_FLAG_FIFO_OVERRATING BIT(7) +#define CCS_PLL_FLAG_DUAL_PLL BIT(8)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 66/106 ccs-pll: Fix condition for pre-PLL divider lower bound
In reply to Sakari AilusThe lower bound of the pre-PLL divider was calculated based on OP SYS clock frequency which is also affected by the OP SYS clock divider. This is wrong. The right clock frequency is that of the PLL output clock.
--- drivers/media/i2c/ccs-pll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs-pll.c +1 -1
@@ -459,7 +459,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,max_t (uint16_t, min_op_pre_pll_clk_div,clk_div_even_up (DIV_ROUND_UP (mul * pll->ext_clk_freq_hz, - op_lim_bk->max_sys_clk_freq_hz))); + op_lim_fr->max_pll_op_clk_freq_hz)));dev_dbg (dev,"pll_op check: min / max op_pre_pll_clk_div: %u / %u\n" , min_op_pre_pll_clk_div, max_op_pre_pll_clk_div);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 84/106 ccs-pll: Make VT divisors 16-bit
In reply to Sakari AilusMake VT divisors 16-bit unsigned numbers. They don't need 32 bits after all.
--- drivers/media/i2c/ccs-pll.c | 51 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 26 deletions(-)
drivers/media/i2c/ccs-pll.c +25 -26
@@ -239,11 +239,11 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, struct ccs_pll_branch_bk *op_pll_bk, bool cphy, uint32_t phy_const) { - uint32_t sys_div; -uint32_t best_pix_div =INT_MAX >>1 ; -uint32_t vt_op_binning_div; -uint32_t min_vt_div, max_vt_div, vt_div; -uint32_t min_sys_div, max_sys_div; + uint16_t sys_div; +uint16_t best_pix_div =SHRT_MAX >>1 ; +uint16_t vt_op_binning_div; +uint16_t min_vt_div, max_vt_div, vt_div; +uint16_t min_sys_div, max_sys_div;if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) goto out_calc_pixel_rate;
@@ -297,20 +297,19 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,/* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div); - min_vt_div =max (min_vt_div, -DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, - lim->vt_bk.max_pix_clk_freq_hz)); + min_vt_div =max_t (uint16_t, min_vt_div, +DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, + lim->vt_bk.max_pix_clk_freq_hz));dev_dbg (dev,"min_vt_div: max_vt_pix_clk_freq_hz: %u\n" , min_vt_div); - min_vt_div =max_t (uint32_t, min_vt_div, - lim->vt_bk.min_pix_clk_div - * lim->vt_bk.min_sys_clk_div); + min_vt_div =max_t (uint16_t, min_vt_div, lim->vt_bk.min_pix_clk_div + * lim->vt_bk.min_sys_clk_div);dev_dbg (dev,"min_vt_div: min_vt_clk_div: %u\n" , min_vt_div); max_vt_div = lim->vt_bk.max_sys_clk_div * lim->vt_bk.max_pix_clk_div;dev_dbg (dev,"max_vt_div: %u\n" , max_vt_div); - max_vt_div =min (max_vt_div, -DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, + max_vt_div =min_t (uint16_t, max_vt_div, +DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, lim->vt_bk.min_pix_clk_freq_hz));dev_dbg (dev,"max_vt_div: min_vt_pix_clk_freq_hz: %u\n" , max_vt_div);
@@ -321,26 +320,26 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,*/ min_sys_div = lim->vt_bk.min_sys_clk_div;dev_dbg (dev,"min_sys_div: %u\n" , min_sys_div); - min_sys_div =max (min_sys_div, -DIV_ROUND_UP (min_vt_div, - lim->vt_bk.max_pix_clk_div)); + min_sys_div =max_t (uint16_t, min_sys_div, +DIV_ROUND_UP (min_vt_div, + lim->vt_bk.max_pix_clk_div));dev_dbg (dev,"min_sys_div: max_vt_pix_clk_div: %u\n" , min_sys_div); - min_sys_div =max (min_sys_div, - pll_fr->pll_op_clk_freq_hz - / lim->vt_bk.max_sys_clk_freq_hz); + min_sys_div =max_t (uint16_t, min_sys_div, + pll_fr->pll_op_clk_freq_hz + / lim->vt_bk.max_sys_clk_freq_hz);dev_dbg (dev,"min_sys_div: max_pll_op_clk_freq_hz: %u\n" , min_sys_div); min_sys_div =clk_div_even_up (min_sys_div);dev_dbg (dev,"min_sys_div: one or even: %u\n" , min_sys_div); max_sys_div = lim->vt_bk.max_sys_clk_div;dev_dbg (dev,"max_sys_div: %u\n" , max_sys_div); - max_sys_div =min (max_sys_div, -DIV_ROUND_UP (max_vt_div, - lim->vt_bk.min_pix_clk_div)); + max_sys_div =min_t (uint16_t, max_sys_div, +DIV_ROUND_UP (max_vt_div, + lim->vt_bk.min_pix_clk_div));dev_dbg (dev,"max_sys_div: min_vt_pix_clk_div: %u\n" , max_sys_div); - max_sys_div =min (max_sys_div, -DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, - lim->vt_bk.min_pix_clk_freq_hz)); + max_sys_div =min_t (uint16_t, max_sys_div, +DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, + lim->vt_bk.min_pix_clk_freq_hz));dev_dbg (dev,"max_sys_div: min_vt_pix_clk_freq_hz: %u\n" , max_sys_div);/*
@@ -376,7 +375,7 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,if (vt_div == rounded_div)break ; } -if (best_pix_div <INT_MAX >>1 ) +if (best_pix_div <SHRT_MAX >>1 )break ; }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 91/106 ccs: Print written register values
In reply to Sakari AilusThis helps debugging register writes.
--- drivers/media/i2c/ccs/ccs-reg-access.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ccs/ccs-reg-access.c +4 -0
@@ -338,6 +338,10 @@ int ccs_write_addr_no_quirk(struct ccs_sensor *sensor, u32 reg, u32 val)put_unaligned_be16 (CCS_REG_ADDR (reg), data);put_unaligned_be32 (val << (8 * (sizeof (val) - len)), data +2 ); +dev_dbg (&client->dev,"writing reg 0x%4.4x value 0x%*.*x (%u)\n" , +CCS_REG_ADDR (reg),ccs_reg_width (reg) <<1 , +ccs_reg_width (reg) <<1 , val, val); + r =ccs_write_retry (client, &msg);if (r) dev_err(&client->dev,
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 86/106 ccs-pll: Separate VT divisor limit calculation from the rest
In reply to Sakari AilusSeparate VT divisor limit calculation from the rest of the VT PLL branch calculation. This way it can be used for dual PLL support as well.
--- drivers/media/i2c/ccs-pll.c | 64 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 27 deletions(-)
drivers/media/i2c/ccs-pll.c +37 -27
@@ -228,6 +228,41 @@ static int check_ext_bounds(struct device *dev, struct ccs_pll *pll)return 0 ; } +static void +ccs_pll_find_vt_sys_div (struct device *dev,const struct ccs_pll_limits *lim, +struct ccs_pll *pll,struct ccs_pll_branch_fr *pll_fr, +uint16_t min_vt_div,uint16_t max_vt_div, +uint16_t *min_sys_div,uint16_t *max_sys_div) +{ +/* +* Find limits for sys_clk_div. Not all values are possible with all +* values of pix_clk_div. +*/ + *min_sys_div = lim->vt_bk.min_sys_clk_div; +dev_dbg (dev,"min_sys_div: %u\n" , *min_sys_div); + *min_sys_div =max_t (uint16_t, *min_sys_div, +DIV_ROUND_UP (min_vt_div, + lim->vt_bk.max_pix_clk_div)); +dev_dbg (dev,"min_sys_div: max_vt_pix_clk_div: %u\n" , *min_sys_div); + *min_sys_div =max_t (uint16_t, *min_sys_div, + pll_fr->pll_op_clk_freq_hz + / lim->vt_bk.max_sys_clk_freq_hz); +dev_dbg (dev,"min_sys_div: max_pll_op_clk_freq_hz: %u\n" , *min_sys_div); + *min_sys_div =clk_div_even_up (*min_sys_div); +dev_dbg (dev,"min_sys_div: one or even: %u\n" , *min_sys_div); + + *max_sys_div = lim->vt_bk.max_sys_clk_div; +dev_dbg (dev,"max_sys_div: %u\n" , *max_sys_div); + *max_sys_div =min_t (uint16_t, *max_sys_div, +DIV_ROUND_UP (max_vt_div, + lim->vt_bk.min_pix_clk_div)); +dev_dbg (dev,"max_sys_div: min_vt_pix_clk_div: %u\n" , *max_sys_div); + *max_sys_div =min_t (uint16_t, *max_sys_div, +DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, + lim->vt_bk.min_pix_clk_freq_hz)); +dev_dbg (dev,"max_sys_div: min_vt_pix_clk_freq_hz: %u\n" , *max_sys_div); +} +#define CPHY_CONST 7#define DPHY_CONST 16#define PHY_CONST_DIV 16
@@ -314,33 +349,8 @@ ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,dev_dbg (dev,"max_vt_div: min_vt_pix_clk_freq_hz: %u\n" , max_vt_div); -/* -* Find limitsits for sys_clk_div. Not all values are possible -* with all values of pix_clk_div. -*/ - min_sys_div = lim->vt_bk.min_sys_clk_div; -dev_dbg (dev,"min_sys_div: %u\n" , min_sys_div); - min_sys_div =max_t (uint16_t, min_sys_div, -DIV_ROUND_UP (min_vt_div, - lim->vt_bk.max_pix_clk_div)); -dev_dbg (dev,"min_sys_div: max_vt_pix_clk_div: %u\n" , min_sys_div); - min_sys_div =max_t (uint16_t, min_sys_div, - pll_fr->pll_op_clk_freq_hz - / lim->vt_bk.max_sys_clk_freq_hz); -dev_dbg (dev,"min_sys_div: max_pll_op_clk_freq_hz: %u\n" , min_sys_div); - min_sys_div =clk_div_even_up (min_sys_div); -dev_dbg (dev,"min_sys_div: one or even: %u\n" , min_sys_div); - - max_sys_div = lim->vt_bk.max_sys_clk_div; -dev_dbg (dev,"max_sys_div: %u\n" , max_sys_div); - max_sys_div =min_t (uint16_t, max_sys_div, -DIV_ROUND_UP (max_vt_div, - lim->vt_bk.min_pix_clk_div)); -dev_dbg (dev,"max_sys_div: min_vt_pix_clk_div: %u\n" , max_sys_div); - max_sys_div =min_t (uint16_t, max_sys_div, -DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, - lim->vt_bk.min_pix_clk_freq_hz)); -dev_dbg (dev,"max_sys_div: min_vt_pix_clk_freq_hz: %u\n" , max_sys_div); +ccs_pll_find_vt_sys_div (dev, lim, pll, pll_fr, min_vt_div, + max_vt_div, &min_sys_div, &max_sys_div);/* * Find pix_div such that a legal pix_div * sys_div results
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 57/106 ccs-pll: Split limits and PLL configuration into front and back parts
In reply to Sakari AilusThe CCS spec supports a lot of variation in the PLL. Split the PLL in front and back parts to better prepare for supporting it.
Also use CCS compliant naming for IP and OP PLL frequencies (i.e. include "clk" in the name).
--- drivers/media/i2c/ccs-pll.c | 282 ++++++++++++++++--------------- drivers/media/i2c/ccs-pll.h | 44 +++-- drivers/media/i2c/ccs/ccs-core.c | 71 ++++---- 3 files changed, 209 insertions(+), 188 deletions(-)
drivers/media/i2c/ccs-pll.c +146 -136
@@ -53,65 +53,68 @@ static int bounds_check(struct device *dev, uint32_t val,static void print_pll (struct device *dev,struct ccs_pll *pll) { -dev_dbg (dev,"pre_pll_clk_div\t%u\n" , pll->pre_pll_clk_div); -dev_dbg (dev,"pll_multiplier \t%u\n" , pll->pll_multiplier); +dev_dbg (dev,"pre_pll_clk_div\t%u\n" , pll->vt_fr.pre_pll_clk_div); +dev_dbg (dev,"pll_multiplier \t%u\n" , pll->vt_fr.pll_multiplier);if (!(pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS )) { -dev_dbg (dev,"op_sys_clk_div \t%u\n" , pll->op.sys_clk_div); -dev_dbg (dev,"op_pix_clk_div \t%u\n" , pll->op.pix_clk_div); +dev_dbg (dev,"op_sys_clk_div \t%u\n" , pll->op_bk.sys_clk_div); +dev_dbg (dev,"op_pix_clk_div \t%u\n" , pll->op_bk.pix_clk_div); } -dev_dbg (dev,"vt_sys_clk_div \t%u\n" , pll->vt.sys_clk_div); -dev_dbg (dev,"vt_pix_clk_div \t%u\n" , pll->vt.pix_clk_div); +dev_dbg (dev,"vt_sys_clk_div \t%u\n" , pll->vt_bk.sys_clk_div); +dev_dbg (dev,"vt_pix_clk_div \t%u\n" , pll->vt_bk.pix_clk_div);dev_dbg (dev,"ext_clk_freq_hz \t%u\n" , pll->ext_clk_freq_hz); -dev_dbg (dev,"pll_ip_clk_freq_hz \t%u\n" , pll->pll_ip_clk_freq_hz); -dev_dbg (dev,"pll_op_clk_freq_hz \t%u\n" , pll->pll_op_clk_freq_hz); +dev_dbg (dev,"pll_ip_clk_freq_hz \t%u\n" , pll->vt_fr.pll_ip_clk_freq_hz); +dev_dbg (dev,"pll_op_clk_freq_hz \t%u\n" , pll->vt_fr.pll_op_clk_freq_hz);if (!(pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS )) {dev_dbg (dev,"op_sys_clk_freq_hz \t%u\n" , - pll->op.sys_clk_freq_hz); + pll->op_bk.sys_clk_freq_hz);dev_dbg (dev,"op_pix_clk_freq_hz \t%u\n" , - pll->op.pix_clk_freq_hz); + pll->op_bk.pix_clk_freq_hz); } -dev_dbg (dev,"vt_sys_clk_freq_hz \t%u\n" , pll->vt.sys_clk_freq_hz); -dev_dbg (dev,"vt_pix_clk_freq_hz \t%u\n" , pll->vt.pix_clk_freq_hz); +dev_dbg (dev,"vt_sys_clk_freq_hz \t%u\n" , pll->vt_bk.sys_clk_freq_hz); +dev_dbg (dev,"vt_pix_clk_freq_hz \t%u\n" , pll->vt_bk.pix_clk_freq_hz); }static int check_all_bounds (struct device *dev, -const struct ccs_pll_limits *limits, -const struct ccs_pll_branch_limits *op_limits, -struct ccs_pll *pll,struct ccs_pll_branch *op_pll) +const struct ccs_pll_limits *lim, +const struct ccs_pll_branch_limits_fr *op_lim_fr, +const struct ccs_pll_branch_limits_bk *op_lim_bk, +struct ccs_pll *pll, +struct ccs_pll_branch_fr *op_pll_fr, +struct ccs_pll_branch_bk *op_pll_bk) {int rval; - rval =bounds_check (dev, pll->pll_ip_clk_freq_hz, - limits->min_pll_ip_freq_hz, - limits->max_pll_ip_freq_hz, + rval =bounds_check (dev, op_pll_fr->pll_ip_clk_freq_hz, + op_lim_fr->min_pll_ip_clk_freq_hz, + op_lim_fr->max_pll_ip_clk_freq_hz,"pll_ip_clk_freq_hz" );if (!rval) rval =bounds_check ( - dev, pll->pll_multiplier, - limits->min_pll_multiplier, limits->max_pll_multiplier, -"pll_multiplier" ); + dev, op_pll_fr->pll_multiplier, + op_lim_fr->min_pll_multiplier, + op_lim_fr->max_pll_multiplier,"pll_multiplier" );if (!rval) rval =bounds_check ( - dev, pll->pll_op_clk_freq_hz, - limits->min_pll_op_freq_hz, limits->max_pll_op_freq_hz, -"pll_op_clk_freq_hz" ); + dev, op_pll_fr->pll_op_clk_freq_hz, + op_lim_fr->min_pll_op_clk_freq_hz, + op_lim_fr->max_pll_op_clk_freq_hz,"pll_op_clk_freq_hz" );if (!rval) rval =bounds_check ( - dev, op_pll->sys_clk_div, - op_limits->min_sys_clk_div, op_limits->max_sys_clk_div, + dev, op_pll_bk->sys_clk_div, + op_lim_bk->min_sys_clk_div, op_lim_bk->max_sys_clk_div,"op_sys_clk_div" );if (!rval) rval =bounds_check ( - dev, op_pll->sys_clk_freq_hz, - op_limits->min_sys_clk_freq_hz, - op_limits->max_sys_clk_freq_hz, + dev, op_pll_bk->sys_clk_freq_hz, + op_lim_bk->min_sys_clk_freq_hz, + op_lim_bk->max_sys_clk_freq_hz,"op_sys_clk_freq_hz" );if (!rval) rval =bounds_check ( - dev, op_pll->pix_clk_freq_hz, - op_limits->min_pix_clk_freq_hz, - op_limits->max_pix_clk_freq_hz, + dev, op_pll_bk->pix_clk_freq_hz, + op_lim_bk->min_pix_clk_freq_hz, + op_lim_bk->max_pix_clk_freq_hz,"op_pix_clk_freq_hz" );/*
@@ -123,15 +126,15 @@ static int check_all_bounds(struct device *dev,if (!rval) rval =bounds_check ( - dev, pll->vt.sys_clk_freq_hz, - limits->vt.min_sys_clk_freq_hz, - limits->vt.max_sys_clk_freq_hz, + dev, pll->vt_bk.sys_clk_freq_hz, + lim->vt_bk.min_sys_clk_freq_hz, + lim->vt_bk.max_sys_clk_freq_hz,"vt_sys_clk_freq_hz" );if (!rval) rval =bounds_check ( - dev, pll->vt.pix_clk_freq_hz, - limits->vt.min_pix_clk_freq_hz, - limits->vt.max_pix_clk_freq_hz, + dev, pll->vt_bk.pix_clk_freq_hz, + lim->vt_bk.min_pix_clk_freq_hz, + lim->vt_bk.max_pix_clk_freq_hz,"vt_pix_clk_freq_hz" );return rval;
@@ -149,10 +152,12 @@ static int check_all_bounds(struct device *dev,* @return Zero on success, error code on error. */ static int -__ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *limits, -const struct ccs_pll_branch_limits *op_limits, -struct ccs_pll *pll,struct ccs_pll_branch *op_pll, -uint32_t mul,uint32_t div,uint32_t lane_op_clock_ratio) +__ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *lim, +const struct ccs_pll_branch_limits_fr *op_lim_fr, +const struct ccs_pll_branch_limits_bk *op_lim_bk, +struct ccs_pll *pll,struct ccs_pll_branch_fr *op_pll_fr, +struct ccs_pll_branch_bk *op_pll_bk,uint32_t mul, +uint32_t div,uint32_t lane_op_clock_ratio) {uint32_t sys_div;uint32_t best_pix_div =INT_MAX >>1 ;
@@ -173,42 +178,42 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,* Get pre_pll_clk_div so that our pll_op_clk_freq_hz won't be * too high. */ -dev_dbg (dev,"pre_pll_clk_div %u\n" , pll->pre_pll_clk_div); +dev_dbg (dev,"op_pre_pll_clk_div %u\n" , op_pll_fr->pre_pll_clk_div);/* Don't go above max pll multiplier. */ - more_mul_max = limits->max_pll_multiplier / mul; -dev_dbg (dev,"more_mul_max: max_pll_multiplier check: %u\n" , + more_mul_max = op_lim_fr->max_pll_multiplier / mul; +dev_dbg (dev,"more_mul_max: max_op_pll_multiplier check: %u\n" , more_mul_max);/* Don't go above max pll op frequency. */ more_mul_max =min_t (uint32_t, more_mul_max, - limits->max_pll_op_freq_hz - / (pll->ext_clk_freq_hz / pll->pre_pll_clk_div * mul)); -dev_dbg (dev,"more_mul_max: max_pll_op_freq_hz check: %u\n" , + op_lim_fr->max_pll_op_clk_freq_hz + / (pll->ext_clk_freq_hz / op_pll_fr->pre_pll_clk_div * mul)); +dev_dbg (dev,"more_mul_max: max_pll_op_clk_freq_hz check: %u\n" , more_mul_max);/* Don't go above the division capability of op sys clock divider. */ more_mul_max =min (more_mul_max, - op_limits->max_sys_clk_div * pll->pre_pll_clk_div + op_lim_bk->max_sys_clk_div * op_pll_fr->pre_pll_clk_div / div);dev_dbg (dev,"more_mul_max: max_op_sys_clk_div check: %u\n" , more_mul_max);/* Ensure we won't go above min_pll_multiplier. */ more_mul_max =min (more_mul_max, -DIV_ROUND_UP (limits->max_pll_multiplier, mul)); +DIV_ROUND_UP (op_lim_fr->max_pll_multiplier, mul));dev_dbg (dev,"more_mul_max: min_pll_multiplier check: %u\n" , more_mul_max); -/* Ensure we won't go below min_pll_op_freq_hz. */ - more_mul_min =DIV_ROUND_UP (limits->min_pll_op_freq_hz, - pll->ext_clk_freq_hz / pll->pre_pll_clk_div - * mul); -dev_dbg (dev,"more_mul_min: min_pll_op_freq_hz check: %u\n" , +/* Ensure we won't go below min_pll_op_clk_freq_hz. */ + more_mul_min =DIV_ROUND_UP (op_lim_fr->min_pll_op_clk_freq_hz, + pll->ext_clk_freq_hz / + op_pll_fr->pre_pll_clk_div * mul); +dev_dbg (dev,"more_mul_min: min_op_pll_op_clk_freq_hz check: %u\n" , more_mul_min);/* Ensure we won't go below min_pll_multiplier. */ more_mul_min =max (more_mul_min, -DIV_ROUND_UP (limits->min_pll_multiplier, mul)); -dev_dbg (dev,"more_mul_min: min_pll_multiplier check: %u\n" , +DIV_ROUND_UP (op_lim_fr->min_pll_multiplier, mul)); +dev_dbg (dev,"more_mul_min: min_op_pll_multiplier check: %u\n" , more_mul_min);if (more_mul_min > more_mul_max) {
@@ -217,9 +222,9 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,return -EINVAL ; } - more_mul_factor =lcm (div, pll->pre_pll_clk_div) / div; + more_mul_factor =lcm (div, op_pll_fr->pre_pll_clk_div) / div;dev_dbg (dev,"more_mul_factor: %u\n" , more_mul_factor); - more_mul_factor =lcm (more_mul_factor, op_limits->min_sys_clk_div); + more_mul_factor =lcm (more_mul_factor, op_lim_bk->min_sys_clk_div);dev_dbg (dev,"more_mul_factor: min_op_sys_clk_div: %d\n" , more_mul_factor); i =roundup (more_mul_min, more_mul_factor);
@@ -232,25 +237,25 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,return -EINVAL ; } - pll->pll_multiplier = mul * i; - op_pll->sys_clk_div = div * i / pll->pre_pll_clk_div; -dev_dbg (dev,"op_sys_clk_div: %u\n" , op_pll->sys_clk_div); + op_pll_fr->pll_multiplier = mul * i; + op_pll_bk->sys_clk_div = div * i / op_pll_fr->pre_pll_clk_div; +dev_dbg (dev,"op_sys_clk_div: %u\n" , op_pll_bk->sys_clk_div); - pll->pll_ip_clk_freq_hz = pll->ext_clk_freq_hz - / pll->pre_pll_clk_div; + op_pll_fr->pll_ip_clk_freq_hz = pll->ext_clk_freq_hz + / op_pll_fr->pre_pll_clk_div; - pll->pll_op_clk_freq_hz = pll->pll_ip_clk_freq_hz - * pll->pll_multiplier; + op_pll_fr->pll_op_clk_freq_hz = op_pll_fr->pll_ip_clk_freq_hz + * op_pll_fr->pll_multiplier;/* Derive pll_op_clk_freq_hz. */ - op_pll->sys_clk_freq_hz = - pll->pll_op_clk_freq_hz / op_pll->sys_clk_div; + op_pll_bk->sys_clk_freq_hz = + op_pll_fr->pll_op_clk_freq_hz / op_pll_bk->sys_clk_div; - op_pll->pix_clk_div = pll->bits_per_pixel; -dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll->pix_clk_div); + op_pll_bk->pix_clk_div = pll->bits_per_pixel; +dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div); - op_pll->pix_clk_freq_hz = - op_pll->sys_clk_freq_hz / op_pll->pix_clk_div; + op_pll_bk->pix_clk_freq_hz = + op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div;if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) {/* No OP clocks --- VT clocks are used instead. */
@@ -264,7 +269,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,* should run at higher clock rate, so smaller divisor is used * on video timing side. */ -if (limits->min_line_length_pck_bin > limits->min_line_length_pck +if (lim->min_line_length_pck_bin > lim->min_line_length_pck / pll->binning_horizontal) vt_op_binning_div = pll->binning_horizontal;else
@@ -283,28 +288,28 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,* Find absolute limits for the factor of vt divider. */ dev_dbg (dev,"scale_m: %u\n" , pll->scale_m); - min_vt_div =DIV_ROUND_UP (op_pll->pix_clk_div * op_pll->sys_clk_div - * pll->scale_n, + min_vt_div =DIV_ROUND_UP (op_pll_bk->pix_clk_div + * op_pll_bk->sys_clk_div * pll->scale_n, lane_op_clock_ratio * vt_op_binning_div * pll->scale_m);/* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div); min_vt_div =max (min_vt_div, -DIV_ROUND_UP (pll->pll_op_clk_freq_hz, - limits->vt.max_pix_clk_freq_hz)); +DIV_ROUND_UP (op_pll_fr->pll_op_clk_freq_hz, + lim->vt_bk.max_pix_clk_freq_hz));dev_dbg (dev,"min_vt_div: max_vt_pix_clk_freq_hz: %u\n" , min_vt_div); min_vt_div =max_t (uint32_t, min_vt_div, - limits->vt.min_pix_clk_div - * limits->vt.min_sys_clk_div); + lim->vt_bk.min_pix_clk_div + * lim->vt_bk.min_sys_clk_div);dev_dbg (dev,"min_vt_div: min_vt_clk_div: %u\n" , min_vt_div); - max_vt_div = limits->vt.max_sys_clk_div * limits->vt.max_pix_clk_div; + max_vt_div = lim->vt_bk.max_sys_clk_div * lim->vt_bk.max_pix_clk_div;dev_dbg (dev,"max_vt_div: %u\n" , max_vt_div); max_vt_div =min (max_vt_div, -DIV_ROUND_UP (pll->pll_op_clk_freq_hz, - limits->vt.min_pix_clk_freq_hz)); +DIV_ROUND_UP (op_pll_fr->pll_op_clk_freq_hz, + lim->vt_bk.min_pix_clk_freq_hz));dev_dbg (dev,"max_vt_div: min_vt_pix_clk_freq_hz: %u\n" , max_vt_div);
@@ -312,28 +317,28 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,* Find limitsits for sys_clk_div. Not all values are possible * with all values of pix_clk_div. */ - min_sys_div = limits->vt.min_sys_clk_div; + min_sys_div = lim->vt_bk.min_sys_clk_div;dev_dbg (dev,"min_sys_div: %u\n" , min_sys_div); min_sys_div =max (min_sys_div,DIV_ROUND_UP (min_vt_div, - limits->vt.max_pix_clk_div)); + lim->vt_bk.max_pix_clk_div));dev_dbg (dev,"min_sys_div: max_vt_pix_clk_div: %u\n" , min_sys_div); min_sys_div =max (min_sys_div, - pll->pll_op_clk_freq_hz - / limits->vt.max_sys_clk_freq_hz); + op_pll_fr->pll_op_clk_freq_hz + / lim->vt_bk.max_sys_clk_freq_hz);dev_dbg (dev,"min_sys_div: max_pll_op_clk_freq_hz: %u\n" , min_sys_div); min_sys_div =clk_div_even_up (min_sys_div);dev_dbg (dev,"min_sys_div: one or even: %u\n" , min_sys_div); - max_sys_div = limits->vt.max_sys_clk_div; + max_sys_div = lim->vt_bk.max_sys_clk_div;dev_dbg (dev,"max_sys_div: %u\n" , max_sys_div); max_sys_div =min (max_sys_div,DIV_ROUND_UP (max_vt_div, - limits->vt.min_pix_clk_div)); + lim->vt_bk.min_pix_clk_div));dev_dbg (dev,"max_sys_div: min_vt_pix_clk_div: %u\n" , max_sys_div); max_sys_div =min (max_sys_div, -DIV_ROUND_UP (pll->pll_op_clk_freq_hz, - limits->vt.min_pix_clk_freq_hz)); +DIV_ROUND_UP (op_pll_fr->pll_op_clk_freq_hz, + lim->vt_bk.min_pix_clk_freq_hz));dev_dbg (dev,"max_sys_div: min_vt_pix_clk_freq_hz: %u\n" , max_sys_div);/*
@@ -348,13 +353,13 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits, sys_div += 2 - (sys_div & 1)) {uint16_t pix_div =DIV_ROUND_UP (vt_div, sys_div); -if (pix_div < limits->vt.min_pix_clk_div - || pix_div > limits->vt.max_pix_clk_div) { +if (pix_div < lim->vt_bk.min_pix_clk_div + || pix_div > lim->vt_bk.max_pix_clk_div) {dev_dbg (dev,"pix_div %u too small or too big (%u--%u)\n" , pix_div, - limits->vt.min_pix_clk_div, - limits->vt.max_pix_clk_div); + lim->vt_bk.min_pix_clk_div, + lim->vt_bk.max_pix_clk_div);continue ; }
@@ -367,29 +372,32 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,break ; } - pll->vt.sys_clk_div =DIV_ROUND_UP (min_vt_div, best_pix_div); - pll->vt.pix_clk_div = best_pix_div; + pll->vt_bk.sys_clk_div =DIV_ROUND_UP (min_vt_div, best_pix_div); + pll->vt_bk.pix_clk_div = best_pix_div; - pll->vt.sys_clk_freq_hz = - pll->pll_op_clk_freq_hz / pll->vt.sys_clk_div; - pll->vt.pix_clk_freq_hz = - pll->vt.sys_clk_freq_hz / pll->vt.pix_clk_div; + pll->vt_bk.sys_clk_freq_hz = + op_pll_fr->pll_op_clk_freq_hz / pll->vt_bk.sys_clk_div; + pll->vt_bk.pix_clk_freq_hz = + pll->vt_bk.sys_clk_freq_hz / pll->vt_bk.pix_clk_div; out_skip_vt_calc: pll->pixel_rate_csi = - op_pll->pix_clk_freq_hz * lane_op_clock_ratio; - pll->pixel_rate_pixel_array = pll->vt.pix_clk_freq_hz; + op_pll_bk->pix_clk_freq_hz * lane_op_clock_ratio; + pll->pixel_rate_pixel_array = pll->vt_bk.pix_clk_freq_hz; -return check_all_bounds (dev, limits, op_limits, pll, op_pll); +return check_all_bounds (dev, lim, op_lim_fr, op_lim_bk, pll, op_pll_fr, + op_pll_bk); } -int ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *limits, +int ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *lim,struct ccs_pll *pll) { -const struct ccs_pll_branch_limits *op_limits = &limits->op; -struct ccs_pll_branch *op_pll = &pll->op; -uint16_t min_pre_pll_clk_div; -uint16_t max_pre_pll_clk_div; +const struct ccs_pll_branch_limits_fr *op_lim_fr = &lim->vt_fr; +const struct ccs_pll_branch_limits_bk *op_lim_bk = &lim->op_bk; +struct ccs_pll_branch_fr *op_pll_fr = &pll->vt_fr; +struct ccs_pll_branch_bk *op_pll_bk = &pll->op_bk; +uint16_t min_op_pre_pll_clk_div; +uint16_t max_op_pre_pll_clk_div;uint32_t lane_op_clock_ratio;uint32_t mul, div;unsigned int i;
@@ -401,8 +409,9 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,* instead. The OP values are ignored for the rest of * the PLL calculation. */ - op_limits = &limits->vt; - op_pll = &pll->vt; + op_lim_fr = &lim->vt_fr; + op_lim_bk = &lim->vt_bk; + op_pll_bk = &pll->vt_bk; }if (pll->flags &CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE )
@@ -417,11 +426,11 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,switch (pll->bus_type) {case CCS_PLL_BUS_TYPE_CSI2 :/* CSI transfers 2 bits per clock per lane; thus times 2 */ - pll->pll_op_clk_freq_hz = pll->link_freq *2 + op_pll_fr->pll_op_clk_freq_hz = pll->link_freq *2 * (pll->csi2.lanes / lane_op_clock_ratio);break ;case CCS_PLL_BUS_TYPE_PARALLEL : - pll->pll_op_clk_freq_hz = pll->link_freq * pll->bits_per_pixel + op_pll_fr->pll_op_clk_freq_hz = pll->link_freq * pll->bits_per_pixel /DIV_ROUND_UP (pll->bits_per_pixel, pll->parallel.bus_width);break ;
@@ -429,39 +438,40 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *limits,return -EINVAL ; } -/* Figure out limits for pre-pll divider based on extclk */ -dev_dbg (dev,"min / max pre_pll_clk_div: %u / %u\n" , - limits->min_pre_pll_clk_div, limits->max_pre_pll_clk_div); - max_pre_pll_clk_div = -min_t (uint16_t, limits->max_pre_pll_clk_div, +/* Figure out limits for OP pre-pll divider based on extclk */ +dev_dbg (dev,"min / max op_pre_pll_clk_div: %u / %u\n" , + op_lim_fr->min_pre_pll_clk_div, op_lim_fr->max_pre_pll_clk_div); + max_op_pre_pll_clk_div = +min_t (uint16_t, op_lim_fr->max_pre_pll_clk_div,clk_div_even (pll->ext_clk_freq_hz / - limits->min_pll_ip_freq_hz)); - min_pre_pll_clk_div = -max_t (uint16_t, limits->min_pre_pll_clk_div, + op_lim_fr->min_pll_ip_clk_freq_hz)); + min_op_pre_pll_clk_div = +max_t (uint16_t, op_lim_fr->min_pre_pll_clk_div,clk_div_even_up (DIV_ROUND_UP (pll->ext_clk_freq_hz, - limits->max_pll_ip_freq_hz))); -dev_dbg (dev,"pre-pll check: min / max pre_pll_clk_div: %u / %u\n" , - min_pre_pll_clk_div, max_pre_pll_clk_div); + op_lim_fr->max_pll_ip_clk_freq_hz))); +dev_dbg (dev,"pre-pll check: min / max op_pre_pll_clk_div: %u / %u\n" , + min_op_pre_pll_clk_div, max_op_pre_pll_clk_div); - i =gcd (pll->pll_op_clk_freq_hz, pll->ext_clk_freq_hz); - mul = pll->pll_op_clk_freq_hz / i; + i =gcd (op_pll_fr->pll_op_clk_freq_hz, pll->ext_clk_freq_hz); + mul = op_pll_fr->pll_op_clk_freq_hz / i; div = pll->ext_clk_freq_hz / i;dev_dbg (dev,"mul %u / div %u\n" , mul, div); - min_pre_pll_clk_div = -max_t (uint16_t, min_pre_pll_clk_div, + min_op_pre_pll_clk_div = +max_t (uint16_t, min_op_pre_pll_clk_div,clk_div_even_up (DIV_ROUND_UP (mul * pll->ext_clk_freq_hz, - limits->max_pll_op_freq_hz))); -dev_dbg (dev,"pll_op check: min / max pre_pll_clk_div: %u / %u\n" , - min_pre_pll_clk_div, max_pre_pll_clk_div); - -for (pll->pre_pll_clk_div = min_pre_pll_clk_div; - pll->pre_pll_clk_div <= max_pre_pll_clk_div; - pll->pre_pll_clk_div +=2 - (pll->pre_pll_clk_div &1 )) { - rval =__ccs_pll_calculate (dev, limits, op_limits, pll, op_pll, - mul, div, lane_op_clock_ratio); + op_lim_fr->max_pll_op_clk_freq_hz))); +dev_dbg (dev,"pll_op check: min / max op_pre_pll_clk_div: %u / %u\n" , + min_op_pre_pll_clk_div, max_op_pre_pll_clk_div); + +for (op_pll_fr->pre_pll_clk_div = min_op_pre_pll_clk_div; + op_pll_fr->pre_pll_clk_div <= max_op_pre_pll_clk_div; + op_pll_fr->pre_pll_clk_div +=2 - (op_pll_fr->pre_pll_clk_div &1 )) { + rval =__ccs_pll_calculate (dev, lim, op_lim_fr, op_lim_bk, pll, + op_pll_fr, op_pll_bk, mul, div, + lane_op_clock_ratio);if (rval)continue ;
drivers/media/i2c/ccs-pll.h +26 -18
68 lines not on this page · raw message
drivers/media/i2c/ccs/ccs-core.c +37 -34
104 lines not on this page · raw message
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 80/106 ccs-pll: Check for derating and overrating, support non-derating sensors
In reply to Sakari AilusSome sensors support derating (VT domain speed faster than OP) or overrating (VT domain speed slower than OP). While this was supported for the driver, the hardware support for the feature was never verified. Do that now, and for those devices without that support, VT and OP speeds have to match.
--- drivers/media/i2c/ccs-pll.c | 84 +++++++++++++++++++++----------- drivers/media/i2c/ccs-pll.h | 2 + drivers/media/i2c/ccs/ccs-core.c | 7 +++ 3 files changed, 64 insertions(+), 29 deletions(-)
drivers/media/i2c/ccs-pll.c +55 -29
@@ -142,6 +142,18 @@ static int check_all_bounds(struct device *dev, lim->vt_bk.max_pix_clk_freq_hz, "vt_pix_clk_freq_hz"); +if (!(pll->flags &CCS_PLL_FLAG_FIFO_DERATING ) && + pll->pixel_rate_pixel_array > pll->pixel_rate_csi) { +dev_dbg (dev,"device does not support derating\n" ); +return -EINVAL ; + } + +if (!(pll->flags &CCS_PLL_FLAG_FIFO_OVERRATING ) && + pll->pixel_rate_pixel_array < pll->pixel_rate_csi) { +dev_dbg (dev,"device does not support overrating\n" ); +return -EINVAL ; + } +return rval; }
@@ -163,37 +175,51 @@ __ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,uint32_t min_sys_div, max_sys_div;/* -* Some sensors perform analogue binning and some do this -* digitally. The ones doing this digitally can be roughly be -* found out using this formula. The ones doing this digitally -* should run at higher clock rate, so smaller divisor is used -* on video timing side. +* Find out whether a sensor supports derating. If it does not, VT and +* OP domains are required to run at the same pixel rate. */ -if (lim->min_line_length_pck_bin > lim->min_line_length_pck - / pll->binning_horizontal) - vt_op_binning_div = pll->binning_horizontal; -else - vt_op_binning_div =1 ; -dev_dbg (dev,"vt_op_binning_div: %u\n" , vt_op_binning_div); +if (!(pll->flags &CCS_PLL_FLAG_FIFO_DERATING )) { + min_vt_div = + op_pll_bk->sys_clk_div * op_pll_bk->pix_clk_div + * pll->vt_lanes * phy_const + / pll->op_lanes /PHY_CONST_DIV ; + }else { +/* +* Some sensors perform analogue binning and some do this +* digitally. The ones doing this digitally can be roughly be +* found out using this formula. The ones doing this digitally +* should run at higher clock rate, so smaller divisor is used +* on video timing side. +*/ +if (lim->min_line_length_pck_bin > lim->min_line_length_pck + / pll->binning_horizontal) + vt_op_binning_div = pll->binning_horizontal; +else + vt_op_binning_div =1 ; +dev_dbg (dev,"vt_op_binning_div: %u\n" , vt_op_binning_div); -/* -* Profile 2 supports vt_pix_clk_div E [4, 10] -* -* Horizontal binning can be used as a base for difference in -* divisors. One must make sure that horizontal blanking is -* enough to accommodate the CSI-2 sync codes. -* -* Take scaling factor and number of VT lanes into account as well. -* -* Find absolute limits for the factor of vt divider. -*/ -dev_dbg (dev,"scale_m: %u\n" , pll->scale_m); - min_vt_div =DIV_ROUND_UP (pll->bits_per_pixel * op_pll_bk->sys_clk_div - * pll->scale_n * pll->vt_lanes * phy_const, - (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? - pll->csi2.lanes :1 ) - * vt_op_binning_div * pll->scale_m - *PHY_CONST_DIV ); +/* +* Profile 2 supports vt_pix_clk_div E [4, 10] +* +* Horizontal binning can be used as a base for difference in +* divisors. One must make sure that horizontal blanking is +* enough to accommodate the CSI-2 sync codes. +* +* Take scaling factor and number of VT lanes into account as well. +* +* Find absolute limits for the factor of vt divider. +*/ +dev_dbg (dev,"scale_m: %u\n" , pll->scale_m); + min_vt_div = +DIV_ROUND_UP (pll->bits_per_pixel + * op_pll_bk->sys_clk_div * pll->scale_n + * pll->vt_lanes * phy_const, + (pll->flags & +CCS_PLL_FLAG_LANE_SPEED_MODEL ? + pll->csi2.lanes :1 ) + * vt_op_binning_div * pll->scale_m + *PHY_CONST_DIV ); + }/* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div);
drivers/media/i2c/ccs-pll.h +2 -0
@@ -27,6 +27,8 @@#define CCS_PLL_FLAG_LINK_DECOUPLED BIT(3)#define CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER BIT(4)#define CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV BIT(5) +#define CCS_PLL_FLAG_FIFO_DERATING BIT(6) +#define CCS_PLL_FLAG_FIFO_OVERRATING BIT(7)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
drivers/media/i2c/ccs/ccs-core.c +7 -0
@@ -3216,6 +3216,13 @@ static int ccs_probe(struct i2c_client *client)if (CCS_LIM (sensor,CLOCK_TREE_PLL_CAPABILITY ) &CCS_CLOCK_TREE_PLL_CAPABILITY_FLEXIBLE_OP_PIX_CLK_DIV ) sensor->pll.flags |=CCS_PLL_FLAG_FLEXIBLE_OP_PIX_CLK_DIV ; +if (CCS_LIM (sensor,FIFO_SUPPORT_CAPABILITY ) & +CCS_FIFO_SUPPORT_CAPABILITY_DERATING ) + sensor->pll.flags |=CCS_PLL_FLAG_FIFO_DERATING ; +if (CCS_LIM (sensor,FIFO_SUPPORT_CAPABILITY ) & +CCS_FIFO_SUPPORT_CAPABILITY_DERATING_OVERRATING ) + sensor->pll.flags |=CCS_PLL_FLAG_FIFO_DERATING | +CCS_PLL_FLAG_FIFO_OVERRATING ; sensor->pll.op_bits_per_lane =CCS_LIM (sensor,OP_BITS_PER_LANE ); sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 55/106 ccs: Use all regulators
In reply to Sakari AilusUse regulators vio and vcore besides vana. The regulators were always there but on many boards they've been hard wired. Control them explicitly now.
--- drivers/media/i2c/ccs/ccs-core.c | 30 +++++++++++++++++++++++------- drivers/media/i2c/ccs/ccs.h | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +23 -7
@@ -65,6 +65,8 @@ struct ccs_device {unsigned char flags; }; +static const char *const ccs_regulators[] = {"vcore" ,"vio" ,"vana" }; +/* * * Dynamic Capability Identification
@@ -1304,7 +1306,8 @@ static int ccs_power_on(struct device *dev)unsigned int sleep;int rval; - rval =regulator_enable (sensor->vana); + rval =regulator_bulk_enable (ARRAY_SIZE (ccs_regulators), + sensor->regulators);if (rval) {dev_err (dev,"failed to enable vana regulator\n" );return rval;
@@ -1416,7 +1419,8 @@ static int ccs_power_on(struct device *dev)clk_disable_unprepare (sensor->ext_clk); out_xclk_fail: -regulator_disable (sensor->vana); +regulator_bulk_disable (ARRAY_SIZE (ccs_regulators), + sensor->regulators);return rval; }
@@ -1442,7 +1446,8 @@ static int ccs_power_off(struct device *dev)gpiod_set_value (sensor->xshutdown,0 );clk_disable_unprepare (sensor->ext_clk);usleep_range (5000 ,5000 ); -regulator_disable (sensor->vana); +regulator_bulk_disable (ARRAY_SIZE (ccs_regulators), + sensor->regulators); sensor->streaming = false;return 0 ;
@@ -2981,10 +2986,21 @@ static int ccs_probe(struct i2c_client *client)v4l2_i2c_subdev_init (&sensor->src->sd, client, &ccs_ops); sensor->src->sd.internal_ops = &ccs_internal_src_ops; - sensor->vana =devm_regulator_get (&client->dev,"vana" ); -if (IS_ERR (sensor->vana)) { -dev_err (&client->dev,"could not get regulator for vana\n" ); -return PTR_ERR (sensor->vana); + sensor->regulators =devm_kcalloc (&client->dev, +ARRAY_SIZE (ccs_regulators), +sizeof (*sensor->regulators), +GFP_KERNEL ); +if (!sensor->regulators) +return -ENOMEM ; + +for (i =0 ; i <ARRAY_SIZE (ccs_regulators); i++) + sensor->regulators[i].supply = ccs_regulators[i]; + + rval =devm_regulator_bulk_get (&client->dev,ARRAY_SIZE (ccs_regulators), + sensor->regulators); +if (rval) { +dev_err (&client->dev,"could not get regulators\n" ); +return rval; } sensor->ext_clk =devm_clk_get (&client->dev,NULL );
drivers/media/i2c/ccs/ccs.h +1 -1
@@ -223,7 +223,7 @@ struct ccs_sensor {struct ccs_subdev *scaler;struct ccs_subdev *pixel_array;struct ccs_hwconfig hwcfg; -struct regulator *vana; +struct regulator_bulk_data *regulators;struct clk *ext_clk;struct gpio_desc *xshutdown;struct gpio_desc *reset;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 77/106 ccs-pll: Add sanity checks
In reply to Sakari AilusAdd sanity checks for fields that could cause division by zero.
--- drivers/media/i2c/ccs-pll.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/media/i2c/ccs-pll.c +9 -0
@@ -421,6 +421,15 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->vt_lanes =1 ; } +if (!pll->op_lanes || !pll->vt_lanes || !pll->bits_per_pixel || + !pll->ext_clk_freq_hz || !pll->link_freq || !pll->scale_m || + !op_lim_fr->min_pll_ip_clk_freq_hz || + !op_lim_fr->max_pll_ip_clk_freq_hz || + !op_lim_fr->min_pll_op_clk_freq_hz || + !op_lim_fr->max_pll_op_clk_freq_hz || + !op_lim_bk->max_sys_clk_div || !op_lim_fr->max_pll_multiplier) +return -EINVAL ; +/* * Make sure op_pix_clk_div will be integer --- unless flexible * op_pix_clk_div is supported
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 81/106 ccs-pll: Better separate OP and VT sub-tree calculation
In reply to Sakari AilusBetter separate OP PLL branch calculation from VT branch calculation.
--- drivers/media/i2c/ccs-pll.c | 54 +++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 23 deletions(-)
drivers/media/i2c/ccs-pll.c +31 -23
@@ -162,11 +162,11 @@ static int check_all_bounds(struct device *dev,#define PHY_CONST_DIV 16static void -__ccs_pll_calculate_vt (struct device *dev,const struct ccs_pll_limits *lim, -const struct ccs_pll_branch_limits_bk *op_lim_bk, -struct ccs_pll *pll,struct ccs_pll_branch_fr *pll_fr, -struct ccs_pll_branch_bk *op_pll_bk,bool cphy, -uint32_t phy_const) +ccs_pll_calculate_vt (struct device *dev,const struct ccs_pll_limits *lim, +const struct ccs_pll_branch_limits_bk *op_lim_bk, +struct ccs_pll *pll,struct ccs_pll_branch_fr *pll_fr, +struct ccs_pll_branch_bk *op_pll_bk,bool cphy, +uint32_t phy_const) {uint32_t sys_div;uint32_t best_pix_div =INT_MAX >>1 ;
@@ -174,6 +174,9 @@ __ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,uint32_t min_vt_div, max_vt_div, vt_div;uint32_t min_sys_div, max_sys_div; +if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) + goto out_calc_pixel_rate; +/* * Find out whether a sensor supports derating. If it does not, VT and * OP domains are required to run at the same pixel rate.
@@ -313,6 +316,10 @@ __ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim, pll_fr->pll_op_clk_freq_hz / pll->vt_bk.sys_clk_div; pll->vt_bk.pix_clk_freq_hz = pll->vt_bk.sys_clk_freq_hz / pll->vt_bk.pix_clk_div; + +out_calc_pixel_rate: + pll->pixel_rate_pixel_array = + pll->vt_bk.pix_clk_freq_hz * pll->vt_lanes; }/*
@@ -327,12 +334,12 @@ __ccs_pll_calculate_vt(struct device *dev, const struct ccs_pll_limits *lim,* @return Zero on success, error code on error. */ static int -__ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *lim, -const struct ccs_pll_branch_limits_fr *op_lim_fr, -const struct ccs_pll_branch_limits_bk *op_lim_bk, -struct ccs_pll *pll,struct ccs_pll_branch_fr *op_pll_fr, -struct ccs_pll_branch_bk *op_pll_bk,uint32_t mul, -uint32_t div,uint32_t l,bool cphy,uint32_t phy_const) +ccs_pll_calculate_op (struct device *dev,const struct ccs_pll_limits *lim, +const struct ccs_pll_branch_limits_fr *op_lim_fr, +const struct ccs_pll_branch_limits_bk *op_lim_bk, +struct ccs_pll *pll,struct ccs_pll_branch_fr *op_pll_fr, +struct ccs_pll_branch_bk *op_pll_bk,uint32_t mul, +uint32_t div,uint32_t l,bool cphy,uint32_t phy_const) {/* * Higher multipliers (and divisors) are often required than
@@ -430,15 +437,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div); -if (!(pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS )) -__ccs_pll_calculate_vt (dev, lim, op_lim_bk, pll, op_pll_fr, - op_pll_bk, cphy, phy_const); - - pll->pixel_rate_pixel_array = - pll->vt_bk.pix_clk_freq_hz * pll->vt_lanes; - -return check_all_bounds (dev, lim, op_lim_fr, op_lim_bk, pll, op_pll_fr, - op_pll_bk); +return 0 ; } int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,
@@ -558,13 +557,22 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_fr->pre_pll_clk_div += (pll->flags & CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER) ? 1 : 2 - (op_pll_fr->pre_pll_clk_div & 1)) { - rval =__ccs_pll_calculate (dev, lim, op_lim_fr, op_lim_bk, pll, - op_pll_fr, op_pll_bk, mul, div, l, - cphy, phy_const); + rval =ccs_pll_calculate_op (dev, lim, op_lim_fr, op_lim_bk, pll, + op_pll_fr, op_pll_bk, mul, div, l, + cphy, phy_const); +if (rval) +continue ; + +ccs_pll_calculate_vt (dev, lim, op_lim_bk, pll, op_pll_fr, + op_pll_bk, cphy, phy_const); + + rval =check_all_bounds (dev, lim, op_lim_fr, op_lim_bk, pll, + op_pll_fr, op_pll_bk);if (rval)continue ;print_pll (dev, pll); +return 0 ; }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 79/106 ccs-pll: Split off VT subtree calculation
In reply to Sakari AilusSplit off the VT sub clock tree calculation from the rest, into its own function. Also call the op_pll_fr argument pll_fr, since soon these may not be OP tree values.
This paves way for additional features in the future such as dual PLL support.
--- drivers/media/i2c/ccs-pll.c | 255 ++++++++++++++++++------------------ 1 file changed, 131 insertions(+), 124 deletions(-)
drivers/media/i2c/ccs-pll.c +131 -124
@@ -149,130 +149,18 @@ static int check_all_bounds(struct device *dev,#define DPHY_CONST 16#define PHY_CONST_DIV 16 -/* -* Heuristically guess the PLL tree for a given common multiplier and -* divisor. Begin with the operational timing and continue to video -* timing once operational timing has been verified. -* -* @mul is the PLL multiplier and @div is the common divisor -* (pre_pll_clk_div and op_sys_clk_div combined). The final PLL -* multiplier will be a multiple of @mul. -* -* @return Zero on success, error code on error. -*/ -static int -__ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *lim, -const struct ccs_pll_branch_limits_fr *op_lim_fr, -const struct ccs_pll_branch_limits_bk *op_lim_bk, -struct ccs_pll *pll,struct ccs_pll_branch_fr *op_pll_fr, -struct ccs_pll_branch_bk *op_pll_bk,uint32_t mul, -uint32_t div,uint32_t l,bool cphy,uint32_t phy_const) +static void +__ccs_pll_calculate_vt (struct device *dev,const struct ccs_pll_limits *lim, +const struct ccs_pll_branch_limits_bk *op_lim_bk, +struct ccs_pll *pll,struct ccs_pll_branch_fr *pll_fr, +struct ccs_pll_branch_bk *op_pll_bk,bool cphy, +uint32_t phy_const) {uint32_t sys_div;uint32_t best_pix_div =INT_MAX >>1 ;uint32_t vt_op_binning_div; -/* -* Higher multipliers (and divisors) are often required than -* necessitated by the external clock and the output clocks. -* There are limits for all values in the clock tree. These -* are the minimum and maximum multiplier for mul. -*/ -uint32_t more_mul_min, more_mul_max; -uint32_t more_mul_factor;uint32_t min_vt_div, max_vt_div, vt_div;uint32_t min_sys_div, max_sys_div; -uint32_t i; - -/* -* Get pre_pll_clk_div so that our pll_op_clk_freq_hz won't be -* too high. -*/ -dev_dbg (dev,"op_pre_pll_clk_div %u\n" , op_pll_fr->pre_pll_clk_div); - -/* Don't go above max pll multiplier. */ - more_mul_max = op_lim_fr->max_pll_multiplier / mul; -dev_dbg (dev,"more_mul_max: max_op_pll_multiplier check: %u\n" , - more_mul_max); -/* Don't go above max pll op frequency. */ - more_mul_max = -min_t (uint32_t, - more_mul_max, - op_lim_fr->max_pll_op_clk_freq_hz - / (pll->ext_clk_freq_hz / - op_pll_fr->pre_pll_clk_div * mul)); -dev_dbg (dev,"more_mul_max: max_pll_op_clk_freq_hz check: %u\n" , - more_mul_max); -/* Don't go above the division capability of op sys clock divider. */ - more_mul_max =min (more_mul_max, - op_lim_bk->max_sys_clk_div * op_pll_fr->pre_pll_clk_div - / div); -dev_dbg (dev,"more_mul_max: max_op_sys_clk_div check: %u\n" , - more_mul_max); -/* Ensure we won't go above max_pll_multiplier. */ - more_mul_max =min (more_mul_max, op_lim_fr->max_pll_multiplier / mul); -dev_dbg (dev,"more_mul_max: min_pll_multiplier check: %u\n" , - more_mul_max); - -/* Ensure we won't go below min_pll_op_clk_freq_hz. */ - more_mul_min =DIV_ROUND_UP (op_lim_fr->min_pll_op_clk_freq_hz, - pll->ext_clk_freq_hz / - op_pll_fr->pre_pll_clk_div * mul); -dev_dbg (dev,"more_mul_min: min_op_pll_op_clk_freq_hz check: %u\n" , - more_mul_min); -/* Ensure we won't go below min_pll_multiplier. */ - more_mul_min =max (more_mul_min, -DIV_ROUND_UP (op_lim_fr->min_pll_multiplier, mul)); -dev_dbg (dev,"more_mul_min: min_op_pll_multiplier check: %u\n" , - more_mul_min); - -if (more_mul_min > more_mul_max) { -dev_dbg (dev, -"unable to compute more_mul_min and more_mul_max\n" ); -return -EINVAL ; - } - - more_mul_factor =lcm (div, op_pll_fr->pre_pll_clk_div) / div; -dev_dbg (dev,"more_mul_factor: %u\n" , more_mul_factor); - more_mul_factor =lcm (more_mul_factor, op_lim_bk->min_sys_clk_div); -dev_dbg (dev,"more_mul_factor: min_op_sys_clk_div: %d\n" , - more_mul_factor); - i =roundup (more_mul_min, more_mul_factor); -if (!is_one_or_even (i)) - i <<=1 ; - -dev_dbg (dev,"final more_mul: %u\n" , i); -if (i > more_mul_max) { -dev_dbg (dev,"final more_mul is bad, max %u\n" , more_mul_max); -return -EINVAL ; - } - - op_pll_fr->pll_multiplier = mul * i; - op_pll_bk->sys_clk_div = div * i / op_pll_fr->pre_pll_clk_div; -dev_dbg (dev,"op_sys_clk_div: %u\n" , op_pll_bk->sys_clk_div); - - op_pll_fr->pll_ip_clk_freq_hz = pll->ext_clk_freq_hz - / op_pll_fr->pre_pll_clk_div; - - op_pll_fr->pll_op_clk_freq_hz = op_pll_fr->pll_ip_clk_freq_hz - * op_pll_fr->pll_multiplier; - -if (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ) - op_pll_bk->pix_clk_div = pll->bits_per_pixel - * pll->op_lanes * phy_const - /PHY_CONST_DIV / pll->csi2.lanes / l; -else - op_pll_bk->pix_clk_div = - pll->bits_per_pixel * phy_const /PHY_CONST_DIV / l; - - op_pll_bk->pix_clk_freq_hz = - op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div; - -dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div); - -if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) { -/* No OP clocks --- VT clocks are used instead. */ - goto out_skip_vt_calc; - }/* * Some sensors perform analogue binning and some do this
@@ -310,7 +198,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,/* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div); min_vt_div =max (min_vt_div, -DIV_ROUND_UP (op_pll_fr->pll_op_clk_freq_hz, +DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, lim->vt_bk.max_pix_clk_freq_hz));dev_dbg (dev,"min_vt_div: max_vt_pix_clk_freq_hz: %u\n" , min_vt_div);
@@ -322,7 +210,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, max_vt_div = lim->vt_bk.max_sys_clk_div * lim->vt_bk.max_pix_clk_div;dev_dbg (dev,"max_vt_div: %u\n" , max_vt_div); max_vt_div =min (max_vt_div, -DIV_ROUND_UP (op_pll_fr->pll_op_clk_freq_hz, +DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, lim->vt_bk.min_pix_clk_freq_hz));dev_dbg (dev,"max_vt_div: min_vt_pix_clk_freq_hz: %u\n" , max_vt_div);
@@ -338,7 +226,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, lim->vt_bk.max_pix_clk_div));dev_dbg (dev,"min_sys_div: max_vt_pix_clk_div: %u\n" , min_sys_div); min_sys_div =max (min_sys_div, - op_pll_fr->pll_op_clk_freq_hz + pll_fr->pll_op_clk_freq_hz / lim->vt_bk.max_sys_clk_freq_hz);dev_dbg (dev,"min_sys_div: max_pll_op_clk_freq_hz: %u\n" , min_sys_div); min_sys_div =clk_div_even_up (min_sys_div);
@@ -351,7 +239,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, lim->vt_bk.min_pix_clk_div));dev_dbg (dev,"max_sys_div: min_vt_pix_clk_div: %u\n" , max_sys_div); max_sys_div =min (max_sys_div, -DIV_ROUND_UP (op_pll_fr->pll_op_clk_freq_hz, +DIV_ROUND_UP (pll_fr->pll_op_clk_freq_hz, lim->vt_bk.min_pix_clk_freq_hz));dev_dbg (dev,"max_sys_div: min_vt_pix_clk_freq_hz: %u\n" , max_sys_div);
@@ -396,11 +284,130 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->vt_bk.pix_clk_div = best_pix_div; pll->vt_bk.sys_clk_freq_hz = - op_pll_fr->pll_op_clk_freq_hz / pll->vt_bk.sys_clk_div; + pll_fr->pll_op_clk_freq_hz / pll->vt_bk.sys_clk_div; pll->vt_bk.pix_clk_freq_hz = pll->vt_bk.sys_clk_freq_hz / pll->vt_bk.pix_clk_div; +} + +/* +* Heuristically guess the PLL tree for a given common multiplier and +* divisor. Begin with the operational timing and continue to video +* timing once operational timing has been verified. +* +* @mul is the PLL multiplier and @div is the common divisor +* (pre_pll_clk_div and op_sys_clk_div combined). The final PLL +* multiplier will be a multiple of @mul. +* +* @return Zero on success, error code on error. +*/ +static int +__ccs_pll_calculate (struct device *dev,const struct ccs_pll_limits *lim, +const struct ccs_pll_branch_limits_fr *op_lim_fr, +const struct ccs_pll_branch_limits_bk *op_lim_bk, +struct ccs_pll *pll,struct ccs_pll_branch_fr *op_pll_fr, +struct ccs_pll_branch_bk *op_pll_bk,uint32_t mul, +uint32_t div,uint32_t l,bool cphy,uint32_t phy_const) +{ +/* +* Higher multipliers (and divisors) are often required than +* necessitated by the external clock and the output clocks. +* There are limits for all values in the clock tree. These +* are the minimum and maximum multiplier for mul. +*/ +uint32_t more_mul_min, more_mul_max; +uint32_t more_mul_factor; +uint32_t i; + +/* +* Get pre_pll_clk_div so that our pll_op_clk_freq_hz won't be +* too high. +*/ +dev_dbg (dev,"op_pre_pll_clk_div %u\n" , op_pll_fr->pre_pll_clk_div); + +/* Don't go above max pll multiplier. */ + more_mul_max = op_lim_fr->max_pll_multiplier / mul; +dev_dbg (dev,"more_mul_max: max_op_pll_multiplier check: %u\n" , + more_mul_max); +/* Don't go above max pll op frequency. */ + more_mul_max = +min_t (uint32_t, + more_mul_max, + op_lim_fr->max_pll_op_clk_freq_hz + / (pll->ext_clk_freq_hz / + op_pll_fr->pre_pll_clk_div * mul)); +dev_dbg (dev,"more_mul_max: max_pll_op_clk_freq_hz check: %u\n" , + more_mul_max); +/* Don't go above the division capability of op sys clock divider. */ + more_mul_max =min (more_mul_max, + op_lim_bk->max_sys_clk_div * op_pll_fr->pre_pll_clk_div + / div); +dev_dbg (dev,"more_mul_max: max_op_sys_clk_div check: %u\n" , + more_mul_max); +/* Ensure we won't go above max_pll_multiplier. */ + more_mul_max =min (more_mul_max, op_lim_fr->max_pll_multiplier / mul); +dev_dbg (dev,"more_mul_max: min_pll_multiplier check: %u\n" , + more_mul_max); + +/* Ensure we won't go below min_pll_op_clk_freq_hz. */ + more_mul_min =DIV_ROUND_UP (op_lim_fr->min_pll_op_clk_freq_hz, + pll->ext_clk_freq_hz / + op_pll_fr->pre_pll_clk_div * mul); +dev_dbg (dev,"more_mul_min: min_op_pll_op_clk_freq_hz check: %u\n" , + more_mul_min); +/* Ensure we won't go below min_pll_multiplier. */ + more_mul_min =max (more_mul_min, +DIV_ROUND_UP (op_lim_fr->min_pll_multiplier, mul)); +dev_dbg (dev,"more_mul_min: min_op_pll_multiplier check: %u\n" , + more_mul_min); + +if (more_mul_min > more_mul_max) { +dev_dbg (dev, +"unable to compute more_mul_min and more_mul_max\n" ); +return -EINVAL ; + } + + more_mul_factor =lcm (div, op_pll_fr->pre_pll_clk_div) / div; +dev_dbg (dev,"more_mul_factor: %u\n" , more_mul_factor); + more_mul_factor =lcm (more_mul_factor, op_lim_bk->min_sys_clk_div); +dev_dbg (dev,"more_mul_factor: min_op_sys_clk_div: %d\n" , + more_mul_factor); + i =roundup (more_mul_min, more_mul_factor); +if (!is_one_or_even (i)) + i <<=1 ; + +dev_dbg (dev,"final more_mul: %u\n" , i); +if (i > more_mul_max) { +dev_dbg (dev,"final more_mul is bad, max %u\n" , more_mul_max); +return -EINVAL ; + } + + op_pll_fr->pll_multiplier = mul * i; + op_pll_bk->sys_clk_div = div * i / op_pll_fr->pre_pll_clk_div; +dev_dbg (dev,"op_sys_clk_div: %u\n" , op_pll_bk->sys_clk_div); + + op_pll_fr->pll_ip_clk_freq_hz = pll->ext_clk_freq_hz + / op_pll_fr->pre_pll_clk_div; + + op_pll_fr->pll_op_clk_freq_hz = op_pll_fr->pll_ip_clk_freq_hz + * op_pll_fr->pll_multiplier; + +if (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ) + op_pll_bk->pix_clk_div = pll->bits_per_pixel + * pll->op_lanes * phy_const + /PHY_CONST_DIV / pll->csi2.lanes / l; +else + op_pll_bk->pix_clk_div = + pll->bits_per_pixel * phy_const /PHY_CONST_DIV / l; + + op_pll_bk->pix_clk_freq_hz = + op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div; + +dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div); + +if (!(pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS )) +__ccs_pll_calculate_vt (dev, lim, op_lim_bk, pll, op_pll_fr, + op_pll_bk, cphy, phy_const); -out_skip_vt_calc: pll->pixel_rate_pixel_array = pll->vt_bk.pix_clk_freq_hz * pll->vt_lanes;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 72/106 ccs: Add support for lane speed model
In reply to Sakari AilusConvey the relevant PLL flags to the PLL calculator. Also the lane speed model affects how the link rate is calculated on the CSI-2 bus, as the rate is total of all lanes.
--- drivers/media/i2c/ccs/ccs-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +10 -1
@@ -387,7 +387,9 @@ static int ccs_pll_configure(struct ccs_sensor *sensor)/* Lane op clock ratio does not apply here. */ rval =ccs_write (sensor,REQUESTED_LINK_RATE ,DIV_ROUND_UP (pll->op_bk.sys_clk_freq_hz, -1000000 /256 /256 )); +1000000 /256 /256 ) * + (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? + sensor->pll.csi2.lanes :1 ));if (rval <0 || sensor->pll.flags &CCS_PLL_FLAG_NO_OP_CLOCKS )return rval;
@@ -3194,6 +3196,13 @@ static int ccs_probe(struct i2c_client *client)/* prepare PLL configuration input values */ sensor->pll.bus_type =CCS_PLL_BUS_TYPE_CSI2_DPHY ; sensor->pll.csi2.lanes = sensor->hwcfg.lanes; +if (CCS_LIM (sensor,CLOCK_CALCULATION ) & +CCS_CLOCK_CALCULATION_LANE_SPEED ) { + sensor->pll.vt_lanes = +CCS_LIM (sensor,NUM_OF_VT_LANES ) +1 ; + sensor->pll.op_lanes = sensor->pll.vt_lanes; + sensor->pll.flags |=CCS_PLL_FLAG_LANE_SPEED_MODEL ; + } sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 71/106 ccs-pll: Add support for lane speed model
In reply to Sakari AilusCCS PLL includes a capability to calculate the VT clocks on per-lane basis. Add support for this feature.
Move calculation of the pixel rate on the CSI-2 bus early in the function as everything needed to calculate it is already available.
--- drivers/media/i2c/ccs-pll.c | 36 +++++++++++++++++++++++++----------- drivers/media/i2c/ccs-pll.h | 6 ++++++ 2 files changed, 31 insertions(+), 11 deletions(-)
drivers/media/i2c/ccs-pll.c +25 -11
@@ -251,11 +251,12 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_fr->pll_op_clk_freq_hz = op_pll_fr->pll_ip_clk_freq_hz * op_pll_fr->pll_multiplier; - op_pll_bk->pix_clk_div = pll->bits_per_pixel; -dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div); - + op_pll_bk->pix_clk_div = pll->bits_per_pixel + * pll->op_lanes / pll->csi2.lanes; op_pll_bk->pix_clk_freq_hz = op_pll_bk->sys_clk_freq_hz / op_pll_bk->pix_clk_div; +dev_dbg (dev,"op_pix_clk_div: %u\n" , op_pll_bk->pix_clk_div); +if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) {/* No OP clocks --- VT clocks are used instead. */
@@ -283,15 +284,16 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,* divisors. One must make sure that horizontal blanking is * enough to accommodate the CSI-2 sync codes. * -* Take scaling factor into account as well. +* Take scaling factor and number of VT lanes into account as well. * * Find absolute limits for the factor of vt divider. */ dev_dbg (dev,"scale_m: %u\n" , pll->scale_m); min_vt_div =DIV_ROUND_UP (op_pll_bk->pix_clk_div - * op_pll_bk->sys_clk_div * pll->scale_n, - lane_op_clock_ratio * vt_op_binning_div - * pll->scale_m); + * op_pll_bk->sys_clk_div * pll->scale_n + * pll->vt_lanes, + pll->op_lanes * vt_op_binning_div + * pll->scale_m * lane_op_clock_ratio);/* Find smallest and biggest allowed vt divisor. */ dev_dbg (dev,"min_vt_div: %u\n" , min_vt_div);
@@ -387,9 +389,8 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->vt_bk.sys_clk_freq_hz / pll->vt_bk.pix_clk_div; out_skip_vt_calc: - pll->pixel_rate_csi = - op_pll_bk->pix_clk_freq_hz * lane_op_clock_ratio; - pll->pixel_rate_pixel_array = pll->vt_bk.pix_clk_freq_hz; + pll->pixel_rate_pixel_array = + pll->vt_bk.pix_clk_freq_hz * pll->vt_lanes;return check_all_bounds (dev, lim, op_lim_fr, op_lim_bk, pll, op_pll_fr, op_pll_bk);
@@ -409,6 +410,13 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,uint32_t i;int rval = -EINVAL ; +if (!(pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL )) { + pll->op_lanes =1 ; + pll->vt_lanes =1 ; + } +dev_dbg (dev,"vt_lanes: %u\n" , pll->vt_lanes); +dev_dbg (dev,"op_lanes: %u\n" , pll->op_lanes); +if (pll->flags &CCS_PLL_FLAG_NO_OP_CLOCKS ) {/* * If there's no OP PLL at all, use the VT values
@@ -433,12 +441,18 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,case CCS_PLL_BUS_TYPE_CSI2_DPHY :/* CSI transfers 2 bits per clock per lane; thus times 2 */ op_pll_bk->sys_clk_freq_hz = pll->link_freq *2 - * (pll->csi2.lanes / lane_op_clock_ratio); + * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? +1 : pll->csi2.lanes) / lane_op_clock_ratio;break ;default :return -EINVAL ; } + pll->pixel_rate_csi = + op_pll_bk->pix_clk_freq_hz + * (pll->flags &CCS_PLL_FLAG_LANE_SPEED_MODEL ? + pll->csi2.lanes :1 ) * lane_op_clock_ratio; +/* Figure out limits for OP pre-pll divider based on extclk */ dev_dbg (dev,"min / max op_pre_pll_clk_div: %u / %u\n" , op_lim_fr->min_pre_pll_clk_div, op_lim_fr->max_pre_pll_clk_div);
drivers/media/i2c/ccs-pll.h +6 -0
@@ -22,6 +22,8 @@/* op pix clock is for all lanes in total normally */ #define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE BIT(0)#define CCS_PLL_FLAG_NO_OP_CLOCKS BIT(1) +/* CCS PLL flags */ +#define CCS_PLL_FLAG_LANE_SPEED_MODEL BIT(2)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
@@ -63,6 +65,8 @@ struct ccs_pll_branch_bk {* All information required to calculate CCS PLL configuration. * * @bus_type: Type of the data bus, CCS_PLL_BUS_TYPE_* (input) +* @op_lanes: Number of operational lanes (input) +* @vt_lanes: Number of video timing lanes (input) * @csi2.lanes: The number of the CSI-2 data lanes (input) * @binning_vertical: Vertical binning factor (input) * @binning_horizontal: Horizontal binning factor (input)
@@ -83,6 +87,8 @@ struct ccs_pll_branch_bk {struct ccs_pll {/* input values */ uint8_t bus_type; +uint8_t op_lanes; +uint8_t vt_lanes;struct {uint8_t lanes; } csi2;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 74/106 ccs-pll: Add support for extended input PLL clock divider
In reply to Sakari AilusCCS allows odd PLL dividers other than 1, granted that the corresponding capability bit is set. Support this both in the PLL calculator and the CCS driver.
--- drivers/media/i2c/ccs-pll.c | 4 +++- drivers/media/i2c/ccs-pll.h | 1 + drivers/media/i2c/ccs/ccs-core.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-)
drivers/media/i2c/ccs-pll.c +3 -1
@@ -478,7 +478,9 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,for (op_pll_fr->pre_pll_clk_div = min_op_pre_pll_clk_div; op_pll_fr->pre_pll_clk_div <= max_op_pre_pll_clk_div; - op_pll_fr->pre_pll_clk_div +=2 - (op_pll_fr->pre_pll_clk_div &1 )) { + op_pll_fr->pre_pll_clk_div += + (pll->flags &CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER ) ?1 : +2 - (op_pll_fr->pre_pll_clk_div &1 )) { rval =__ccs_pll_calculate (dev, lim, op_lim_fr, op_lim_bk, pll, op_pll_fr, op_pll_bk, mul, div);if (rval)
drivers/media/i2c/ccs-pll.h +1 -0
@@ -25,6 +25,7 @@/* CCS PLL flags */ #define CCS_PLL_FLAG_LANE_SPEED_MODEL BIT(2)#define CCS_PLL_FLAG_LINK_DECOUPLED BIT(3) +#define CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER BIT(4)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
drivers/media/i2c/ccs/ccs-core.c +3 -0
@@ -3211,6 +3211,9 @@ static int ccs_probe(struct i2c_client *client) sensor->pll.op_lanes = sensor->pll.csi2.lanes; } } +if (CCS_LIM (sensor,CLOCK_TREE_PLL_CAPABILITY ) & +CCS_CLOCK_TREE_PLL_CAPABILITY_EXT_DIVIDER ) + sensor->pll.flags |=CCS_PLL_FLAG_EXT_IP_PLL_DIVIDER ; sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 58/106 ccs-pll: Use correct VT divisor for calculating VT SYS divisor
In reply to Sakari AilusUse the correct video timing divisor to calculate the SYS divisor. Instead of the current value, the minimum was used. This could have resulted in a too low SYS divisor.
--- drivers/media/i2c/ccs-pll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs-pll.c +2 -2
@@ -365,14 +365,14 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,/* Check if this one is better. */ if (pix_div * sys_div - <=roundup (min_vt_div, best_pix_div)) + <=roundup (vt_div, best_pix_div)) best_pix_div = pix_div; }if (best_pix_div <INT_MAX >>1 )break ; } - pll->vt_bk.sys_clk_div =DIV_ROUND_UP (min_vt_div, best_pix_div); + pll->vt_bk.sys_clk_div =DIV_ROUND_UP (vt_div, best_pix_div); pll->vt_bk.pix_clk_div = best_pix_div; pll->vt_bk.sys_clk_freq_hz =
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 68/106 ccs-pll: Fix comment on check against maximum PLL multiplier
In reply to Sakari AilusThe comment is about minimum PLL multiplier but the related check really deals with the maximum PLL multiplier.
--- drivers/media/i2c/ccs-pll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs-pll.c +1 -1
@@ -203,7 +203,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, / div);dev_dbg (dev,"more_mul_max: max_op_sys_clk_div check: %u\n" , more_mul_max); -/* Ensure we won't go above min_pll_multiplier. */ +/* Ensure we won't go above max_pll_multiplier. */ more_mul_max =min (more_mul_max,DIV_ROUND_UP (op_lim_fr->max_pll_multiplier, mul)); dev_dbg(dev, "more_mul_max: min_pll_multiplier check: %u\n",
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 60/106 ccs-pll: Remove parallel bus support
In reply to Sakari AilusThe parallel bus PLL calculation has no users. Remove it.
--- drivers/media/i2c/ccs-pll.c | 5 ----- drivers/media/i2c/ccs-pll.h | 14 ++++---------- 2 files changed, 4 insertions(+), 15 deletions(-)
drivers/media/i2c/ccs-pll.c +0 -5
@@ -435,11 +435,6 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, op_pll_fr->pll_op_clk_freq_hz = pll->link_freq *2 * (pll->csi2.lanes / lane_op_clock_ratio);break ; -case CCS_PLL_BUS_TYPE_PARALLEL : - op_pll_fr->pll_op_clk_freq_hz = pll->link_freq * pll->bits_per_pixel - /DIV_ROUND_UP (pll->bits_per_pixel, - pll->parallel.bus_width); -break ;default :return -EINVAL ; }
drivers/media/i2c/ccs-pll.h +4 -10
@@ -13,8 +13,7 @@#define CCS_PLL_H /* CSI-2 or CCP-2 */ -#define CCS_PLL_BUS_TYPE_CSI2 0x00 -#define CCS_PLL_BUS_TYPE_PARALLEL 0x01 +#define CCS_PLL_BUS_TYPE_CSI2 0x00/* op pix clock is for all lanes in total normally */ #define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE (1 << 0)
@@ -37,14 +36,9 @@ struct ccs_pll_branch_bk {struct ccs_pll {/* input values */ uint8_t bus_type; -union { -struct { -uint8_t lanes; - } csi2; -struct { -uint8_t bus_width; - } parallel; - }; +struct { +uint8_t lanes; + } csi2;unsigned long flags;uint8_t binning_horizontal;uint8_t binning_vertical;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 64/106 ccs-pll: Use the BIT macro
In reply to Sakari AilusUse the BIT macro for setting individual bits.
--- drivers/media/i2c/ccs-pll.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs-pll.h +5 -2
@@ -12,13 +12,16 @@#ifndef CCS_PLL_H #define CCS_PLL_H +#include <linux/bits.h> +/* CSI-2 or CCP-2 */ #define CCS_PLL_BUS_TYPE_CSI2_DPHY 0x00#define CCS_PLL_BUS_TYPE_CSI2_CPHY 0x01 +/* Old SMIA and implementation specific flags */ /* op pix clock is for all lanes in total normally */ -#define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE (1 << 0) -#define CCS_PLL_FLAG_NO_OP_CLOCKS (1 << 1) +#define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE BIT(0) +#define CCS_PLL_FLAG_NO_OP_CLOCKS BIT(1)/** * struct ccs_pll_branch_fr - CCS PLL configuration (front)
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 67/106 ccs-pll: Avoid overflow in pre-PLL divisor lower bound search
In reply to Sakari AilusThe external clock frequency times the PLL multiplier may exceed the value range of 32-bit unsigned integers. Instead perform the same calculation y using two divisions.
The result has some potential to be different, but that's ok: this number is used to limit the range of pre-PLL divisors to find optimal values. So the effect of the rare case of a different result here would mean an invalid pre-PLL divisor is tried. That will be found out a little later in any case.
Also guard against dividing by zero if the external clock frequency is higher than the maximum OP PLL output clock --- a rather improbable case.
--- drivers/media/i2c/ccs-pll.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs-pll.c +9 -2
@@ -40,6 +40,11 @@ static inline uint32_t is_one_or_even(uint32_t a)return 1 ; } +static inline uint32_t one_or_more (uint32_t a) +{ +return a ?:1 ; +} +static int bounds_check (struct device *dev,uint32_t val,uint32_t min,uint32_t max,char *str) {
@@ -458,8 +463,10 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, min_op_pre_pll_clk_div =max_t (uint16_t, min_op_pre_pll_clk_div,clk_div_even_up ( -DIV_ROUND_UP (mul * pll->ext_clk_freq_hz, - op_lim_fr->max_pll_op_clk_freq_hz))); + mul / +one_or_more ( +DIV_ROUND_UP (op_lim_fr->max_pll_op_clk_freq_hz, + pll->ext_clk_freq_hz))));dev_dbg (dev,"pll_op check: min / max op_pre_pll_clk_div: %u / %u\n" , min_op_pre_pll_clk_div, max_op_pre_pll_clk_div);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 69/106 ccs-pll: Fix check for PLL multiplier upper bound
In reply to Sakari AilusThe additional multiplier (for higher VT timing) of the PLL multiplier was checked against the upper limit but the result was rounded up, possibly producing too high additional multiplier. Round down instead to keep within hardware limits.
--- drivers/media/i2c/ccs-pll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ccs-pll.c +1 -2
@@ -204,8 +204,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,dev_dbg (dev,"more_mul_max: max_op_sys_clk_div check: %u\n" , more_mul_max);/* Ensure we won't go above max_pll_multiplier. */ - more_mul_max =min (more_mul_max, -DIV_ROUND_UP (op_lim_fr->max_pll_multiplier, mul)); + more_mul_max =min (more_mul_max, op_lim_fr->max_pll_multiplier / mul);dev_dbg (dev,"more_mul_max: min_pll_multiplier check: %u\n" , more_mul_max);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 61/106 ccs-pll: Differentiate between CSI-2 D-PHY and C-PHY
In reply to Sakari AilusDifferentiate between CSI-2 D-PHY and C-PHY. This does not yet include support for C-PHY.
--- drivers/media/i2c/ccs-pll.c | 2 +- drivers/media/i2c/ccs-pll.h | 3 ++- drivers/media/i2c/ccs/ccs-core.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/ccs-pll.c +1 -1
@@ -430,7 +430,7 @@ int ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, pll->binning_vertical);switch (pll->bus_type) { -case CCS_PLL_BUS_TYPE_CSI2 : +case CCS_PLL_BUS_TYPE_CSI2_DPHY :/* CSI transfers 2 bits per clock per lane; thus times 2 */ op_pll_fr->pll_op_clk_freq_hz = pll->link_freq *2 * (pll->csi2.lanes / lane_op_clock_ratio);
drivers/media/i2c/ccs-pll.h +2 -1
@@ -13,7 +13,8 @@#define CCS_PLL_H /* CSI-2 or CCP-2 */ -#define CCS_PLL_BUS_TYPE_CSI2 0x00 +#define CCS_PLL_BUS_TYPE_CSI2_DPHY 0x00 +#define CCS_PLL_BUS_TYPE_CSI2_CPHY 0x01/* op pix clock is for all lanes in total normally */ #define CCS_PLL_FLAG_OP_PIX_CLOCK_PER_LANE (1 << 0)
drivers/media/i2c/ccs/ccs-core.c +1 -1
@@ -3192,7 +3192,7 @@ static int ccs_probe(struct i2c_client *client) sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN );/* prepare PLL configuration input values */ - sensor->pll.bus_type =CCS_PLL_BUS_TYPE_CSI2 ; + sensor->pll.bus_type =CCS_PLL_BUS_TYPE_CSI2_DPHY ; sensor->pll.csi2.lanes = sensor->hwcfg.lanes; sensor->pll.ext_clk_freq_hz = sensor->hwcfg.ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 59/106 ccs-pll: End search if there are no better values available
In reply to Sakari AilusThe VT divisor search can be ended if we've already found the value that corresponds exactly the total divisor, as there are no better (lower) values available.
--- drivers/media/i2c/ccs-pll.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs-pll.c +8 -2
@@ -352,6 +352,7 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim, sys_div <= max_sys_div; sys_div += 2 - (sys_div & 1)) {uint16_t pix_div =DIV_ROUND_UP (vt_div, sys_div); +uint16_t rounded_div;if (pix_div < lim->vt_bk.min_pix_clk_div || pix_div > lim->vt_bk.max_pix_clk_div) {
@@ -363,10 +364,15 @@ __ccs_pll_calculate(struct device *dev, const struct ccs_pll_limits *lim,continue ; } + rounded_div =roundup (vt_div, best_pix_div); +/* Check if this one is better. */ -if (pix_div * sys_div - <=roundup (vt_div, best_pix_div)) +if (pix_div * sys_div <= rounded_div) best_pix_div = pix_div; + +/* Bail out if we've already found the best value. */ +if (vt_div == rounded_div) +break ; }if (best_pix_div <INT_MAX >>1 )break ;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 62/106 ccs-pll: Move the flags field down, away from 8-bit fields
In reply to Sakari AilusThis way the struct will use less memory, with better packing and no waste due to unsigned long.
--- drivers/media/i2c/ccs-pll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs-pll.h +1 -1
@@ -40,12 +40,12 @@ struct ccs_pll {struct {uint8_t lanes; } csi2; -unsigned long flags;uint8_t binning_horizontal;uint8_t binning_vertical;uint8_t scale_m;uint8_t scale_n;uint8_t bits_per_pixel; +uint16_t flags;uint32_t link_freq;uint32_t ext_clk_freq_hz;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 47/106 ccs: Use static data read-only registers
In reply to Sakari AilusAccess read-only registers from CCS static data.
--- drivers/media/i2c/ccs/ccs-reg-access.c | 64 ++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-)
drivers/media/i2c/ccs/ccs-reg-access.c +60 -4
@@ -198,11 +198,67 @@ static int __ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val,return 0 ; } +static int __ccs_read_data (struct ccs_reg *regs,size_t num_regs, +u32 reg,u32 *val) +{ +unsigned int width =ccs_reg_width (reg); +size_t i; + +for (i =0 ; i < num_regs; i++, regs++) { +uint8_t *data; + +if (regs->addr + regs->len <CCS_REG_ADDR (reg) + width) +continue ; + +if (regs->addr >CCS_REG_ADDR (reg)) +break ; + + data = ®s->value[CCS_REG_ADDR (reg) - regs->addr]; + +switch (width) { +case sizeof (uint8_t ): + *val = *data; +break ; +case sizeof (uint16_t ): + *val =get_unaligned_be16 (data); +break ; +case sizeof (uint32_t ): + *val =get_unaligned_be32 (data); +break ; +default : +WARN_ON (1 ); +return -EINVAL ; + } + +return 0 ; + } + +return -ENOENT ; +} + +static int ccs_read_data (struct ccs_sensor *sensor,u32 reg,u32 *val) +{ +if (!__ccs_read_data (sensor->sdata.sensor_read_only_regs, + sensor->sdata.num_sensor_read_only_regs, + reg, val)) +return 0 ; + +return __ccs_read_data (sensor->mdata.module_read_only_regs, + sensor->mdata.num_module_read_only_regs, + reg, val); +} +static int ccs_read_addr_raw (struct ccs_sensor *sensor,u32 reg,u32 *val, -bool force8,bool quirk,bool conv) +bool force8,bool quirk,bool conv,bool data) {int rval; +if (data) { + rval =ccs_read_data (sensor, reg, val); +if (!rval) +return 0 ; + } +if (quirk) { *val =0 ; rval =ccs_call_quirk (sensor, reg_access, false, ®, val);
@@ -223,17 +279,17 @@ static int ccs_read_addr_raw(struct ccs_sensor *sensor, u32 reg, u32 *val,int ccs_read_addr (struct ccs_sensor *sensor,u32 reg,u32 *val) { -return ccs_read_addr_raw (sensor, reg, val, false, true, true); +return ccs_read_addr_raw (sensor, reg, val, false, true, true, true); }int ccs_read_addr_8only (struct ccs_sensor *sensor,u32 reg,u32 *val) { -return ccs_read_addr_raw (sensor, reg, val, true, true, true); +return ccs_read_addr_raw (sensor, reg, val, true, true, true, true); }int ccs_read_addr_noconv (struct ccs_sensor *sensor,u32 reg,u32 *val) { -return ccs_read_addr_raw (sensor, reg, val, false, true, false); +return ccs_read_addr_raw (sensor, reg, val, false, true, false, true); }static int ccs_write_retry (struct i2c_client *client,struct i2c_msg *msg)
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 52/106 ccs: Remove unnecessary delays from power-up sequence
In reply to Sakari AilusSMIA nor CCS need these delays; remove them.
--- drivers/media/i2c/ccs/ccs-core.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +0 -2
@@ -1309,14 +1309,12 @@ static int ccs_power_on(struct device *dev)dev_err (dev,"failed to enable vana regulator\n" );return rval; } -usleep_range (1000 ,1000 ); rval =clk_prepare_enable (sensor->ext_clk);if (rval <0 ) {dev_dbg (dev,"failed to enable xclk\n" ); goto out_xclk_fail; } -usleep_range (1000 ,1000 );gpiod_set_value (sensor->reset,0 );gpiod_set_value (sensor->xshutdown,1 );
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 33/106 ccs: Add CCS static data parser library
In reply to Sakari AilusAdd a parser library for parsing the CCS static data format.
The library may be also compiled in user space as the format has uses also in the user space. Therefore it is dual licensed under the 3-clause BSD license as well.
--- drivers/media/i2c/ccs/Makefile | 2 +- drivers/media/i2c/ccs/ccs-data-defs.h | 215 ++++++ drivers/media/i2c/ccs/ccs-data.c | 949 ++++++++++++++++++++++++++ drivers/media/i2c/ccs/ccs-data.h | 116 ++++ 4 files changed, 1281 insertions(+), 1 deletion(-) create mode 100644 drivers/media/i2c/ccs/ccs-data-defs.h create mode 100644 drivers/media/i2c/ccs/ccs-data.c create mode 100644 drivers/media/i2c/ccs/ccs-data.h
drivers/media/i2c/ccs/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only ccs-objs += ccs-core.o ccs-reg-access.o \ - ccs-quirk.o ccs-limits.o + ccs-quirk.o ccs-limits.o ccs-data.o obj-$(CONFIG_VIDEO_CCS) += ccs.o ccflags-y += -I $(srctree)/drivers/media/i2c
drivers/media/i2c/ccs/ccs-data-defs.h new file +215 -0
215 lines not on this page · raw message
drivers/media/i2c/ccs/ccs-data.c new file +949 -0
949 lines not on this page · raw message
drivers/media/i2c/ccs/ccs-data.h new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 49/106 ccs: Wrap long lines, unwrap short ones
In reply to Sakari AilusOver the years (and renaming) some lines that may well be wrapped ended up being over 80 characters, likewise there are shorter lines that can be merged. Do that.
--- drivers/media/i2c/ccs/ccs-core.c | 45 +++++++++++++------------------- 1 file changed, 18 insertions(+), 27 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +18 -27
@@ -651,8 +651,7 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)break ;case V4L2_CID_HBLANK : rval =ccs_write (sensor,LINE_LENGTH_PCK , - sensor->pixel_array->crop[ -CCS_PA_PAD_SRC ].width + sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width + ctrl->val);break ;
@@ -983,15 +982,13 @@ static void ccs_update_blanking(struct ccs_sensor *sensor) min =max_t (int,CCS_LIM (sensor,MIN_FRAME_BLANKING_LINES ), - min_fll - - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height); + min_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height); max = max_fll - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].height;__v4l2_ctrl_modify_range (vblank, min, max, vblank->step, min); min =max_t (int, - min_llp - - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width, + min_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width, min_lbp); max = max_llp - sensor->pixel_array->crop[CCS_PA_PAD_SRC ].width;
@@ -1778,7 +1775,8 @@ static void ccs_get_crop_compose(struct v4l2_subdev *subdev, }else {if (crops) {for (i =0 ; i < subdev->entity.num_pads; i++) - crops[i] =v4l2_subdev_get_try_crop (subdev, cfg, i); + crops[i] =v4l2_subdev_get_try_crop (subdev, + cfg, i); }if (comps) *comps = v4l2_subdev_get_try_compose(subdev, cfg,
@@ -1803,8 +1801,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev, comp->height = crops[CCS_PAD_SINK ]->height;if (which ==V4L2_SUBDEV_FORMAT_ACTIVE ) {if (ssd == sensor->scaler) { - sensor->scale_m = -CCS_LIM (sensor,SCALER_N_MIN ); + sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN ); sensor->scaling_mode =CCS_SCALING_MODE_NO_SCALING ; }else if (ssd == sensor->binner) {
@@ -2230,9 +2227,11 @@ static int ccs_set_crop(struct v4l2_subdev *subdev,if (sel->pad == ssd->sink_pad) { _r.left =0 ; _r.top =0 ; - _r.width =v4l2_subdev_get_try_format (subdev, cfg, sel->pad) + _r.width =v4l2_subdev_get_try_format (subdev, cfg, + sel->pad) ->width; - _r.height =v4l2_subdev_get_try_format (subdev, cfg, sel->pad) + _r.height =v4l2_subdev_get_try_format (subdev, cfg, + sel->pad) ->height; src_size = &_r; }else {
@@ -2350,11 +2349,9 @@ static int ccs_set_selection(struct v4l2_subdev *subdev, sel->r.width =CCS_ALIGN_DIM (sel->r.width, sel->flags); sel->r.height =CCS_ALIGN_DIM (sel->r.height, sel->flags); - sel->r.width = max_t(unsigned int, -CCS_LIM (sensor,MIN_X_OUTPUT_SIZE ), + sel->r.width = max_t(unsigned int, CCS_LIM(sensor, MIN_X_OUTPUT_SIZE), sel->r.width); - sel->r.height = max_t(unsigned int, -CCS_LIM (sensor,MIN_Y_OUTPUT_SIZE ), + sel->r.height = max_t(unsigned int, CCS_LIM(sensor, MIN_Y_OUTPUT_SIZE), sel->r.height);switch (sel->target) {
@@ -2607,8 +2604,7 @@ static int ccs_identify_module(struct ccs_sensor *sensor)dev_warn (&client->dev,"no quirks for this module; let's hope it's fully compliant\n" ); -dev_dbg (&client->dev,"the sensor is called %s\n" , - minfo->name); +dev_dbg (&client->dev,"the sensor is called %s\n" , minfo->name);return 0 ; }
@@ -2628,19 +2624,15 @@ static int ccs_register_subdev(struct ccs_sensor *sensor,if (!sink_ssd)return 0 ; - rval =media_entity_pads_init (&ssd->sd.entity, - ssd->npads, ssd->pads); + rval =media_entity_pads_init (&ssd->sd.entity, ssd->npads, ssd->pads);if (rval) { -dev_err (&client->dev, -"media_entity_pads_init failed\n" ); +dev_err (&client->dev,"media_entity_pads_init failed\n" );return rval; } - rval =v4l2_device_register_subdev (sensor->src->sd.v4l2_dev, - &ssd->sd); + rval =v4l2_device_register_subdev (sensor->src->sd.v4l2_dev, &ssd->sd);if (rval) { -dev_err (&client->dev, -"v4l2_device_register_subdev failed\n" ); +dev_err (&client->dev,"v4l2_device_register_subdev failed\n" );return rval; }
@@ -2648,8 +2640,7 @@ static int ccs_register_subdev(struct ccs_sensor *sensor, &sink_ssd->sd.entity, sink_pad, link_flags);if (rval) { -dev_err (&client->dev, -"media_create_pad_link failed\n" ); +dev_err (&client->dev,"media_create_pad_link failed\n" );v4l2_device_unregister_subdev (&ssd->sd);return rval; }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 46/106 ccs: Add support for manufacturer regs from sensor and module files
In reply to Sakari AilusWrite manufacturer specific registers (MSRs) from file to the sensor on sensor power-on.
--- drivers/media/i2c/ccs/ccs-core.c | 23 +++++++ drivers/media/i2c/ccs/ccs-reg-access.c | 94 ++++++++++++++++++++------ drivers/media/i2c/ccs/ccs-reg-access.h | 2 + 3 files changed, 97 insertions(+), 22 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +23 -0
@@ -1272,6 +1272,21 @@ static int ccs_setup_flash_strobe(struct ccs_sensor *sensor)* Power management */ +static int ccs_write_msr_regs (struct ccs_sensor *sensor) +{ +int rval; + + rval =ccs_write_data_regs (sensor, + sensor->sdata.sensor_manufacturer_regs, + sensor->sdata.num_sensor_manufacturer_regs); +if (rval) +return rval; + +return ccs_write_data_regs (sensor, + sensor->mdata.module_manufacturer_regs, + sensor->mdata.num_module_manufacturer_regs); +} +static int ccs_power_on (struct device *dev) {struct v4l2_subdev *subdev =dev_get_drvdata (dev);
@@ -1377,6 +1392,10 @@ static int ccs_power_on(struct device *dev)if (rval <0 ) goto out_cci_addr_fail; + rval =ccs_write_msr_regs (sensor); +if (rval) + goto out_cci_addr_fail; + rval =ccs_call_quirk (sensor, post_poweron);if (rval) {dev_err (dev,"post_poweron quirks failed\n" );
@@ -3205,6 +3224,10 @@ static int ccs_probe(struct i2c_client *client)if (rval <0 ) goto out_media_entity_cleanup; + rval =ccs_write_msr_regs (sensor); +if (rval) + goto out_media_entity_cleanup; +pm_runtime_set_active (&client->dev);pm_runtime_get_noresume (&client->dev);pm_runtime_enable (&client->dev);
drivers/media/i2c/ccs/ccs-reg-access.c +72 -22
114 lines not on this page · raw message
drivers/media/i2c/ccs/ccs-reg-access.h +2 -0
@@ -27,6 +27,8 @@ int ccs_read_addr_8only(struct ccs_sensor *sensor, u32 reg, u32 *val);int ccs_read_addr_noconv (struct ccs_sensor *sensor,u32 reg,u32 *val);int ccs_write_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 val);int ccs_write_addr (struct ccs_sensor *sensor,u32 reg,u32 val); +int ccs_write_data_regs (struct ccs_sensor *sensor,struct ccs_reg *regs, +size_t num_regs);unsigned int ccs_reg_width (u32 reg);u32 ccs_reg_conv (struct ccs_sensor *sensor,u32 reg,u32 val);
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 48/106 ccs: Clean up runtime PM usage
In reply to Sakari AilusIf pm_runtime_get_sync() fails, there's no need to set the device active again. Also, in the same case to return the usage_count to zero, pm_runtime_put_noidle() is enough.
--- drivers/media/i2c/ccs/ccs-core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +2 -5
@@ -1619,8 +1619,6 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor) rval =pm_runtime_get_sync (&client->dev);if (rval <0 ) { -if (rval != -EBUSY && rval != -EAGAIN ) -pm_runtime_set_active (&client->dev);pm_runtime_put_noidle (&client->dev);return rval;
@@ -2836,9 +2834,8 @@ static int __maybe_unused ccs_suspend(struct device *dev) rval =pm_runtime_get_sync (dev);if (rval <0 ) { -if (rval != -EBUSY && rval != -EAGAIN ) -pm_runtime_set_active (&client->dev); -pm_runtime_put (dev); +pm_runtime_put_noidle (dev); +return -EAGAIN ; }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 34/106 ccs: Combine revision number major and minor into one
In reply to Sakari AilusThe module revision number major and minor are both 8 bits while the sensor revision number is 16 bits. Combine the module revision into one number.
This also adds printing the lowest 8 bits of the module version through the sysfs attribute.
--- drivers/media/i2c/ccs/ccs-core.c | 25 ++++++++++++++----------- drivers/media/i2c/ccs/ccs-quirk.c | 2 +- drivers/media/i2c/ccs/ccs.h | 3 +-- 3 files changed, 16 insertions(+), 14 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +14 -11
@@ -2421,11 +2421,11 @@ ccs_sysfs_ident_read(struct device *dev, struct device_attribute *attr,if (minfo->mipi_manufacturer_id)return snprintf (buf,PAGE_SIZE ,"%4.4x%4.4x%2.2x\n" , minfo->mipi_manufacturer_id, minfo->model_id, - minfo->revision_number_major) +1 ; + minfo->revision_number) +1 ;else return snprintf (buf,PAGE_SIZE ,"%2.2x%4.4x%2.2x\n" , minfo->smia_manufacturer_id, minfo->model_id, - minfo->revision_number_major) +1 ; + minfo->revision_number) +1 ; } static DEVICE_ATTR(ident, S_IRUGO, ccs_sysfs_ident_read, NULL);
@@ -2439,6 +2439,7 @@ static int ccs_identify_module(struct ccs_sensor *sensor)struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);struct ccs_module_info *minfo = &sensor->minfo;unsigned int i; +u32 rev;int rval =0 ;/* Module info */
@@ -2454,11 +2455,13 @@ static int ccs_identify_module(struct ccs_sensor *sensor)if (!rval) rval =ccs_read_addr_8only (sensor,CCS_R_MODULE_REVISION_NUMBER_MAJOR , - &minfo->revision_number_major); -if (!rval) + &rev); +if (!rval) { rval =ccs_read_addr_8only (sensor,CCS_R_MODULE_REVISION_NUMBER_MINOR , - &minfo->revision_number_minor); + &minfo->revision_number); + minfo->revision_number |= rev <<8 ; + }if (!rval) rval =ccs_read_addr_8only (sensor,CCS_R_MODULE_DATE_YEAR , &minfo->module_year);
@@ -2513,9 +2516,9 @@ static int ccs_identify_module(struct ccs_sensor *sensor) minfo->smia_manufacturer_id, minfo->model_id);dev_dbg (&client->dev, -"module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n" , - minfo->revision_number_major, minfo->revision_number_minor, - minfo->module_year, minfo->module_month, minfo->module_day); +"module revision 0x%4.4x date %2.2d-%2.2d-%2.2d\n" , + minfo->revision_number, minfo->module_year, minfo->module_month, + minfo->module_day);if (minfo->sensor_mipi_manufacturer_id) dev_dbg(&client->dev, "MIPI CCS sensor 0x%4.4x-0x%4.4x\n",
@@ -2553,7 +2556,7 @@ static int ccs_identify_module(struct ccs_sensor *sensor) minfo->smia_manufacturer_id = minfo->sensor_smia_manufacturer_id; minfo->model_id = minfo->sensor_model_id; - minfo->revision_number_major = minfo->sensor_revision_number; + minfo->revision_number = minfo->sensor_revision_number; }for (i =0 ; i <ARRAY_SIZE (ccs_module_idents); i++) {
@@ -2570,11 +2573,11 @@ static int ccs_identify_module(struct ccs_sensor *sensor)if (ccs_module_idents[i].flags &CCS_MODULE_IDENT_FLAG_REV_LE ) {if (ccs_module_idents[i].revision_number_major - < minfo->revision_number_major) + < (minfo->revision_number >>8 ))continue ; }else {if (ccs_module_idents[i].revision_number_major - != minfo->revision_number_major) + != (minfo->revision_number >>8 ))continue ; }
drivers/media/i2c/ccs/ccs-quirk.c +1 -1
@@ -35,7 +35,7 @@ static int ccs_write_addr_8s(struct ccs_sensor *sensor,static int jt8ew9_limits (struct ccs_sensor *sensor) { -if (sensor->minfo.revision_number_major <0x03 ) +if (sensor->minfo.revision_number <0x0300 ) sensor->frame_skip =1 ;/* Below 24 gain doesn't have effect at all, */
drivers/media/i2c/ccs/ccs.h +1 -2
@@ -107,8 +107,7 @@ struct ccs_module_info {u32 smia_manufacturer_id;u32 mipi_manufacturer_id;u32 model_id; -u32 revision_number_major; -u32 revision_number_minor; +u32 revision_number;u32 module_year;u32 module_month;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 35/106 ccs: Read CCS static data from firmware binaries
In reply to Sakari AilusRead the CCS static data for sensors and modules. The files are expected to be found in "ccs" directory.
--- drivers/media/i2c/ccs/ccs-core.c | 30 ++++++++++++++++++++++++++++++ drivers/media/i2c/ccs/ccs.h | 2 ++ 2 files changed, 32 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +30 -0
@@ -16,6 +16,7 @@#include <linux/clk.h> #include <linux/delay.h> #include <linux/device.h> +#include <linux/firmware.h> #include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/module.h>
@@ -2947,6 +2948,8 @@ static int ccs_get_hwconfig(struct ccs_sensor *sensor, struct device *dev)static int ccs_probe (struct i2c_client *client) {struct ccs_sensor *sensor; +const struct firmware *fw; +char filename[40 ];unsigned int i;int rval;
@@ -3036,6 +3039,31 @@ static int ccs_probe(struct i2c_client *client) goto out_power_off; } +WARN_ON (snprintf (filename,sizeof (filename), +"ccs/ccs-sensor-%4.4x-%4.4x-%4.4x.fw" , + sensor->minfo.sensor_mipi_manufacturer_id, + sensor->minfo.sensor_model_id, + sensor->minfo.sensor_revision_number) >= +sizeof (filename)); + rval =request_firmware (&fw, filename, &client->dev); +if (!rval) { +ccs_data_parse (&sensor->sdata, fw->data, fw->size, &client->dev, + true); +release_firmware (fw); + } + +WARN_ON (snprintf (filename,sizeof (filename), +"ccs/ccs-module-%4.4x-%4.4x-%4.4x.fw" , + sensor->minfo.mipi_manufacturer_id, + sensor->minfo.model_id, + sensor->minfo.revision_number) >=sizeof (filename)); + rval =request_firmware (&fw, filename, &client->dev); +if (!rval) { +ccs_data_parse (&sensor->mdata, fw->data, fw->size, &client->dev, + true); +release_firmware (fw); + } + rval =ccs_read_all_limits (sensor);if (rval) goto out_power_off;
@@ -3232,6 +3260,8 @@ static int ccs_remove(struct i2c_client *client)ccs_cleanup (sensor);mutex_destroy (&sensor->mutex);kfree (sensor->ccs_limits); +kvfree (sensor->sdata.backing); +kvfree (sensor->mdata.backing);return 0 ; }
drivers/media/i2c/ccs/ccs.h +2 -0
@@ -16,6 +16,7 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-subdev.h> +#include "ccs-data.h" #include "ccs-quirk.h" #include "ccs-regs.h" #include "ccs-reg-access.h"
@@ -227,6 +228,7 @@ struct ccs_sensor {const struct ccs_csi_data_format *internal_csi_format;u32 default_mbus_frame_fmts;int default_pixel_order; +struct ccs_data_container sdata, mdata;u8 binning_horizontal;u8 binning_vertical;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 40/106 ccs: Make real to integer number conversion optional
In reply to Sakari AilusThe limit values will be raw soon, and the conversion takes place later on. Prepare for that.
--- drivers/media/i2c/ccs/ccs-reg-access.c | 35 +++++++++++++++++++------- drivers/media/i2c/ccs/ccs-reg-access.h | 2 ++ 2 files changed, 28 insertions(+), 9 deletions(-)
drivers/media/i2c/ccs/ccs-reg-access.c +26 -9
@@ -143,14 +143,23 @@ unsigned int ccs_reg_width(u32 reg)return sizeof (uint8_t ); } +u32 ccs_reg_conv (struct ccs_sensor *sensor,u32 reg,u32 val) +{ +struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); + +if (reg &CCS_FL_FLOAT_IREAL ) + val =float_to_u32_mul_1000000 (client, val); + +return val; +} +/* * Read a 8/16/32-bit i2c register. The value is returned in 'val'. * Returns zero if successful, or non-zero otherwise. */ static int __ccs_read_addr (struct ccs_sensor *sensor,u32 reg,u32 *val, -bool only8) +bool only8,bool conv) { -struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);unsigned int len =ccs_reg_width (reg);int rval;
@@ -162,14 +171,16 @@ static int __ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val,if (rval <0 )return rval; -if (reg &CCS_FL_FLOAT_IREAL ) - *val =float_to_u32_mul_1000000 (client, *val); +if (!conv) +return 0 ; + + *val =ccs_reg_conv (sensor, reg, *val);return 0 ; }static int ccs_read_addr_raw (struct ccs_sensor *sensor,u32 reg,u32 *val, -bool force8,bool quirk) +bool force8,bool quirk,bool conv) {int rval;
@@ -182,22 +193,28 @@ static int ccs_read_addr_raw(struct ccs_sensor *sensor, u32 reg, u32 *val,return rval;if (force8) -return __ccs_read_addr (sensor, reg, val, true); +return __ccs_read_addr (sensor, reg, val, true, conv); }return __ccs_read_addr (sensor, reg, val,ccs_needs_quirk (sensor, -CCS_QUIRK_FLAG_8BIT_READ_ONLY )); +CCS_QUIRK_FLAG_8BIT_READ_ONLY ), + conv); }int ccs_read_addr (struct ccs_sensor *sensor,u32 reg,u32 *val) { -return ccs_read_addr_raw (sensor, reg, val, false, true); +return ccs_read_addr_raw (sensor, reg, val, false, true, true); }int ccs_read_addr_8only (struct ccs_sensor *sensor,u32 reg,u32 *val) { -return ccs_read_addr_raw (sensor, reg, val, true, true); +return ccs_read_addr_raw (sensor, reg, val, true, true, true); +} + +int ccs_read_addr_noconv (struct ccs_sensor *sensor,u32 reg,u32 *val) +{ +return ccs_read_addr_raw (sensor, reg, val, false, true, false); }int ccs_write_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 val)
drivers/media/i2c/ccs/ccs-reg-access.h +2 -0
@@ -24,10 +24,12 @@ struct ccs_sensor;int ccs_read_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 *val);int ccs_read_addr (struct ccs_sensor *sensor,u32 reg,u32 *val);int ccs_read_addr_8only (struct ccs_sensor *sensor,u32 reg,u32 *val); +int ccs_read_addr_noconv (struct ccs_sensor *sensor,u32 reg,u32 *val);int ccs_write_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 val);int ccs_write_addr (struct ccs_sensor *sensor,u32 reg,u32 val);unsigned int ccs_reg_width (u32 reg); +u32 ccs_reg_conv (struct ccs_sensor *sensor,u32 reg,u32 val);#define ccs_read (sensor, reg_name, val) \ ccs_read_addr(sensor, CCS_R_##reg_name, val)
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 36/106 ccs: Stop reading arrays after the first zero
In reply to Sakari AilusThe register arrays have a certain size but not all the entries will be relevant. In practice reading can be stopped after encountering a zero value in the array. Do that to avoid extra reads.
--- drivers/media/i2c/ccs/ccs-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/i2c/ccs/ccs-core.c +3 -0
@@ -193,6 +193,9 @@ static int ccs_read_all_limits(struct ccs_sensor *sensor) goto out_err; } +if (!val && j) +break ; +ccs_assign_limit (ptr, width, val); dev_dbg(&client->dev, "0x%8.8x \"%s\" = %u, 0x%x\n",
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 18/106 ccs: Remove profile concept
In reply to Sakari AilusThe driver doesn't do anything tangible with profiles. Remove the notion, and use the capabilities directly.
--- drivers/media/i2c/ccs/ccs-core.c | 23 ++++++----------------- drivers/media/i2c/ccs/ccs.h | 2 -- 2 files changed, 6 insertions(+), 19 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +6 -17
@@ -377,7 +377,7 @@ static int ccs_pll_configure(struct ccs_sensor *sensor) rval =ccs_write (sensor,REQUESTED_LINK_RATE ,DIV_ROUND_UP (pll->op.sys_clk_freq_hz,1000000 /256 /256 )); -if (rval <0 || sensor->minfo.smiapp_profile ==SMIAPP_PROFILE_0 ) +if (rval <0 || sensor->pll.flags &SMIAPP_PLL_FLAG_NO_OP_CLOCKS )return rval; rval =ccs_write (sensor,OP_PIX_CLK_DIV , pll->op.pix_clk_div);
@@ -3096,23 +3096,17 @@ static int ccs_probe(struct i2c_client *client) } } -/* We consider this as profile 0 sensor if any of these are zero. */ if (!CCS_LIM (sensor,MIN_OP_SYS_CLK_DIV ) || !CCS_LIM (sensor,MAX_OP_SYS_CLK_DIV ) || !CCS_LIM (sensor,MIN_OP_PIX_CLK_DIV ) || !CCS_LIM (sensor,MAX_OP_PIX_CLK_DIV )) { - sensor->minfo.smiapp_profile =SMIAPP_PROFILE_0 ; +/* No OP clock branch */ + sensor->pll.flags |=SMIAPP_PLL_FLAG_NO_OP_CLOCKS ; }else if (CCS_LIM (sensor,SCALING_CAPABILITY ) - !=CCS_SCALING_CAPABILITY_NONE ) { -if (CCS_LIM (sensor,SCALING_CAPABILITY ) - ==CCS_SCALING_CAPABILITY_HORIZONTAL ) - sensor->minfo.smiapp_profile =SMIAPP_PROFILE_1 ; -else - sensor->minfo.smiapp_profile =SMIAPP_PROFILE_2 ; - sensor->scaler = &sensor->ssds[sensor->ssds_used]; - sensor->ssds_used++; - }else if (CCS_LIM (sensor,DIGITAL_CROP_CAPABILITY ) + !=CCS_SCALING_CAPABILITY_NONE || +CCS_LIM (sensor,DIGITAL_CROP_CAPABILITY ) ==CCS_DIGITAL_CROP_CAPABILITY_INPUT_CROP ) { +/* We have a scaler or digital crop. */ sensor->scaler = &sensor->ssds[sensor->ssds_used]; sensor->ssds_used++; }
@@ -3128,16 +3122,11 @@ static int ccs_probe(struct i2c_client *client) sensor->pll.csi2.lanes = sensor->hwcfg->lanes; sensor->pll.ext_clk_freq_hz = sensor->hwcfg->ext_clk; sensor->pll.scale_n =CCS_LIM (sensor,SCALER_N_MIN ); -/* Profile 0 sensors have no separate OP clock branch. */ -if (sensor->minfo.smiapp_profile ==SMIAPP_PROFILE_0 ) - sensor->pll.flags |=SMIAPP_PLL_FLAG_NO_OP_CLOCKS ;ccs_create_subdev (sensor, sensor->scaler," scaler" ,2 );ccs_create_subdev (sensor, sensor->binner," binner" ,2 );ccs_create_subdev (sensor, sensor->pixel_array," pixel_array" ,1 ); -dev_dbg (&client->dev,"profile %d\n" , sensor->minfo.smiapp_profile); - sensor->pixel_array->sd.entity.function =MEDIA_ENT_F_CAM_SENSOR ; rval =ccs_init_controls (sensor);
drivers/media/i2c/ccs/ccs.h +0 -2
@@ -124,8 +124,6 @@ struct ccs_module_info {u32 smiapp_version;u32 ccs_version; -u32 smiapp_profile; -char *name;const struct ccs_quirk *quirk; };
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 37/106 ccs: The functions to get compose or crop rectangle never return NULL
In reply to Sakari AilusThe NULL check is not needed as the functions do not return NULL. Remove the check (and BUG).
--- drivers/media/i2c/ccs/ccs-core.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +2 -6
@@ -1760,16 +1760,12 @@ static void ccs_get_crop_compose(struct v4l2_subdev *subdev, *comps = &ssd->compose; }else {if (crops) { -for (i =0 ; i < subdev->entity.num_pads; i++) { +for (i =0 ; i < subdev->entity.num_pads; i++) crops[i] =v4l2_subdev_get_try_crop (subdev, cfg, i); -BUG_ON (!crops[i]); - } } -if (comps) { +if (comps) *comps =v4l2_subdev_get_try_compose (subdev, cfg,CCS_PAD_SINK ); -BUG_ON (!*comps); - } } }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 38/106 ccs: Replace somewhat harsh internal checks based on BUG with WARN_ON
In reply to Sakari AilusIf an internal driver error was encountered, BUG was issued. Instead, do less harsh WARN_ON_ONCE and try to manage with the consequences.
--- drivers/media/i2c/ccs/ccs-core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +5 -4
@@ -540,6 +540,10 @@ static void ccs_update_mbus_formats(struct ccs_sensor *sensor)to_csi_format_idx (sensor->internal_csi_format) & ~3 ;unsigned int pixel_order =ccs_pixel_order (sensor); +if (WARN_ON_ONCE (max (internal_csi_format_idx, csi_format_idx) + + pixel_order >=ARRAY_SIZE (ccs_csi_data_formats))) +return ; + sensor->mbus_frame_fmts = sensor->default_mbus_frame_fmts << pixel_order; sensor->csi_format =
@@ -548,9 +552,6 @@ static void ccs_update_mbus_formats(struct ccs_sensor *sensor) &ccs_csi_data_formats[internal_csi_format_idx + pixel_order]; -BUG_ON (max (internal_csi_format_idx, csi_format_idx) + pixel_order - >=ARRAY_SIZE (ccs_csi_data_formats)); -dev_dbg (&client->dev,"new pixel order %s\n" , pixel_order_str[pixel_order]); }
@@ -1800,7 +1801,7 @@ static void ccs_propagate(struct v4l2_subdev *subdev, *crops[CCS_PAD_SRC ] = *comp;break ;default : -BUG (); +WARN_ON_ONCE (1 ); } }
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 39/106 ccs: Refactor register reading a little
In reply to Sakari AilusRework quirk and 8-bit only access functions with a single function that takes arguments. This is later extensible to support yet more flags.
--- drivers/media/i2c/ccs/ccs-reg-access.c | 37 ++++++++++++-------------- 1 file changed, 17 insertions(+), 20 deletions(-)
drivers/media/i2c/ccs/ccs-reg-access.c +17 -20
@@ -168,39 +168,36 @@ static int __ccs_read_addr(struct ccs_sensor *sensor, u32 reg, u32 *val,return 0 ; } -int ccs_read_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 *val) -{ -return __ccs_read_addr ( - sensor, reg, val, -ccs_needs_quirk (sensor,CCS_QUIRK_FLAG_8BIT_READ_ONLY )); -} - -static int ccs_read_addr_quirk (struct ccs_sensor *sensor,u32 reg,u32 *val, -bool force8) +static int ccs_read_addr_raw (struct ccs_sensor *sensor,u32 reg,u32 *val, +bool force8,bool quirk) {int rval; - *val =0 ; - rval =ccs_call_quirk (sensor, reg_access, false, ®, val); -if (rval == -ENOIOCTLCMD ) -return 0 ; -if (rval <0 ) -return rval; +if (quirk) { + *val =0 ; + rval =ccs_call_quirk (sensor, reg_access, false, ®, val); +if (rval == -ENOIOCTLCMD ) +return 0 ; +if (rval <0 ) +return rval; -if (force8) -return __ccs_read_addr (sensor, reg, val, true); +if (force8) +return __ccs_read_addr (sensor, reg, val, true); + } -return ccs_read_addr_no_quirk (sensor, reg, val); +return __ccs_read_addr (sensor, reg, val, +ccs_needs_quirk (sensor, +CCS_QUIRK_FLAG_8BIT_READ_ONLY )); }int ccs_read_addr (struct ccs_sensor *sensor,u32 reg,u32 *val) { -return ccs_read_addr_quirk (sensor, reg, val, false); +return ccs_read_addr_raw (sensor, reg, val, false, true); }int ccs_read_addr_8only (struct ccs_sensor *sensor,u32 reg,u32 *val) { -return ccs_read_addr_quirk (sensor, reg, val, true); +return ccs_read_addr_raw (sensor, reg, val, true, true); }int ccs_write_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 val)
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 14/106 smiapp: Rename register access functions
In reply to Sakari AilusRename register access functions by changing smiapp to ccs.
The functions operating on register addresses have "addr" appended to the name.
--- drivers/media/i2c/smiapp/smiapp-core.c | 67 +++++++++++++------------ drivers/media/i2c/smiapp/smiapp-quirk.c | 22 ++++---- drivers/media/i2c/smiapp/smiapp-regs.c | 47 ++++++++--------- drivers/media/i2c/smiapp/smiapp-regs.h | 14 +++--- 4 files changed, 76 insertions(+), 74 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +34 -33
@@ -180,7 +180,7 @@ static int ccs_read_all_limits(struct smiapp_sensor *sensor) j++, reg += width, ptr += width) {u32 val; - ret =smiapp_read (sensor, reg, &val); + ret =ccs_read_addr (sensor, reg, &val);if (ret) goto out_err;
@@ -2450,59 +2450,60 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor) rval =ccs_read (sensor,MODULE_MANUFACTURER_ID , &minfo->mipi_manufacturer_id);if (!rval && !minfo->mipi_manufacturer_id) - rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_MANUFACTURER_ID , - &minfo->smia_manufacturer_id); + rval =ccs_read_addr_8only (sensor, +SMIAPP_REG_U8_MANUFACTURER_ID , + &minfo->smia_manufacturer_id);if (!rval) - rval =smiapp_read_8only (sensor,CCS_R_MODULE_MODEL_ID , - &minfo->model_id); + rval =ccs_read_addr_8only (sensor,CCS_R_MODULE_MODEL_ID , + &minfo->model_id);if (!rval) - rval =smiapp_read_8only (sensor, -CCS_R_MODULE_REVISION_NUMBER_MAJOR , - &minfo->revision_number_major); + rval =ccs_read_addr_8only (sensor, +CCS_R_MODULE_REVISION_NUMBER_MAJOR , + &minfo->revision_number_major);if (!rval) - rval =smiapp_read_8only (sensor, -CCS_R_MODULE_REVISION_NUMBER_MINOR , - &minfo->revision_number_minor); + rval =ccs_read_addr_8only (sensor, +CCS_R_MODULE_REVISION_NUMBER_MINOR , + &minfo->revision_number_minor);if (!rval) - rval =smiapp_read_8only (sensor,CCS_R_MODULE_DATE_YEAR , - &minfo->module_year); + rval =ccs_read_addr_8only (sensor,CCS_R_MODULE_DATE_YEAR , + &minfo->module_year);if (!rval) - rval =smiapp_read_8only (sensor,CCS_R_MODULE_DATE_MONTH , - &minfo->module_month); + rval =ccs_read_addr_8only (sensor,CCS_R_MODULE_DATE_MONTH , + &minfo->module_month);if (!rval) - rval =smiapp_read_8only (sensor,CCS_R_MODULE_DATE_DAY , - &minfo->module_day); + rval =ccs_read_addr_8only (sensor,CCS_R_MODULE_DATE_DAY , + &minfo->module_day);/* Sensor info */ if (!rval) rval =ccs_read (sensor,SENSOR_MANUFACTURER_ID , &minfo->sensor_mipi_manufacturer_id);if (!rval && !minfo->sensor_mipi_manufacturer_id) - rval =smiapp_read_8only (sensor, -CCS_R_SENSOR_MANUFACTURER_ID , - &minfo->sensor_smia_manufacturer_id); + rval =ccs_read_addr_8only (sensor, +CCS_R_SENSOR_MANUFACTURER_ID , + &minfo->sensor_smia_manufacturer_id);if (!rval) - rval =smiapp_read_8only (sensor, -CCS_R_SENSOR_MODEL_ID , - &minfo->sensor_model_id); + rval =ccs_read_addr_8only (sensor, +CCS_R_SENSOR_MODEL_ID , + &minfo->sensor_model_id);if (!rval) - rval =smiapp_read_8only (sensor, -CCS_R_SENSOR_REVISION_NUMBER , - &minfo->sensor_revision_number); + rval =ccs_read_addr_8only (sensor, +CCS_R_SENSOR_REVISION_NUMBER , + &minfo->sensor_revision_number);if (!rval) - rval =smiapp_read_8only (sensor, -CCS_R_SENSOR_FIRMWARE_VERSION , - &minfo->sensor_firmware_version); + rval =ccs_read_addr_8only (sensor, +CCS_R_SENSOR_FIRMWARE_VERSION , + &minfo->sensor_firmware_version);/* SMIA */ if (!rval) rval =ccs_read (sensor,MIPI_CCS_VERSION , &minfo->ccs_version);if (!rval && !minfo->ccs_version) - rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_SMIA_VERSION , - &minfo->smia_version); + rval =ccs_read_addr_8only (sensor,SMIAPP_REG_U8_SMIA_VERSION , + &minfo->smia_version);if (!rval && !minfo->ccs_version) - rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_SMIAPP_VERSION , - &minfo->smiapp_version); + rval =ccs_read_addr_8only (sensor,SMIAPP_REG_U8_SMIAPP_VERSION , + &minfo->smiapp_version);if (rval) {dev_err (&client->dev,"sensor detection failed\n" );
drivers/media/i2c/smiapp/smiapp-quirk.c +11 -11
@@ -14,14 +14,14 @@#include "smiapp.h" -static int smiapp_write_8s (struct smiapp_sensor *sensor, -const struct smiapp_reg_8 *regs,int len) +static int ccs_write_addr_8s (struct smiapp_sensor *sensor, +const struct smiapp_reg_8 *regs,int len) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);int rval;for (; len >0 ; len--, regs++) { - rval =smiapp_write (sensor, regs->reg, regs->val); + rval =ccs_write_addr (sensor, regs->reg, regs->val);if (rval <0 ) { dev_err(&client->dev, "error %d writing reg 0x%4.4x, val 0x%2.2x",
@@ -81,7 +81,7 @@ static int jt8ew9_post_poweron(struct smiapp_sensor *sensor) }; -return smiapp_write_8s (sensor, regs,ARRAY_SIZE (regs)); +return ccs_write_addr_8s (sensor, regs,ARRAY_SIZE (regs)); }const struct smiapp_quirk smiapp_jt8ew9_quirk = {
@@ -102,7 +102,7 @@ static int imx125es_post_poweron(struct smiapp_sensor *sensor) { 0x3b08, 0x8c }, }; -return smiapp_write_8s (sensor, regs,ARRAY_SIZE (regs)); +return ccs_write_addr_8s (sensor, regs,ARRAY_SIZE (regs)); }const struct smiapp_quirk smiapp_imx125es_quirk = {
@@ -148,13 +148,13 @@ static int jt8ev1_post_poweron(struct smiapp_sensor *sensor) { 0x30b0, 0x01 }, }; - rval =smiapp_write_8s (sensor, regs,ARRAY_SIZE (regs)); + rval =ccs_write_addr_8s (sensor, regs,ARRAY_SIZE (regs));if (rval <0 )return rval;switch (sensor->hwcfg->ext_clk) {case 9600000 : -return smiapp_write_8s (sensor, regs_96, +return ccs_write_addr_8s (sensor, regs_96,ARRAY_SIZE (regs_96));default : dev_warn(&client->dev, "no MSRs for %d Hz ext_clk\n",
@@ -165,7 +165,7 @@ static int jt8ev1_post_poweron(struct smiapp_sensor *sensor)static int jt8ev1_pre_streamon (struct smiapp_sensor *sensor) { -return smiapp_write (sensor,0x3328 ,0x00 ); +return ccs_write_addr (sensor,0x3328 ,0x00 ); }static int jt8ev1_post_streamoff (struct smiapp_sensor *sensor)
@@ -173,7 +173,7 @@ static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)int rval;/* Workaround: allows fast standby to work properly */ - rval =smiapp_write (sensor,0x3205 ,0x04 ); + rval =ccs_write_addr (sensor,0x3205 ,0x04 );if (rval <0 )return rval;
@@ -181,11 +181,11 @@ static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)usleep_range (2000 ,2050 );/* Restore it */ - rval =smiapp_write (sensor,0x3205 ,0x00 ); + rval =ccs_write_addr (sensor,0x3205 ,0x00 );if (rval <0 )return rval; -return smiapp_write (sensor,0x3328 ,0x80 ); +return ccs_write_addr (sensor,0x3328 ,0x80 ); }static int jt8ev1_init (struct smiapp_sensor *sensor)
drivers/media/i2c/smiapp/smiapp-regs.c +24 -23
115 lines not on this page · raw message
drivers/media/i2c/smiapp/smiapp-regs.h +7 -7
@@ -20,18 +20,18 @@struct smiapp_sensor ; -int smiapp_read_no_quirk (struct smiapp_sensor *sensor,u32 reg,u32 *val); -int smiapp_read (struct smiapp_sensor *sensor,u32 reg,u32 *val); -int smiapp_read_8only (struct smiapp_sensor *sensor,u32 reg,u32 *val); -int smiapp_write_no_quirk (struct smiapp_sensor *sensor,u32 reg,u32 val); -int smiapp_write (struct smiapp_sensor *sensor,u32 reg,u32 val); +int ccs_read_addr_no_quirk (struct smiapp_sensor *sensor,u32 reg,u32 *val); +int ccs_read_addr (struct smiapp_sensor *sensor,u32 reg,u32 *val); +int ccs_read_addr_8only (struct smiapp_sensor *sensor,u32 reg,u32 *val); +int ccs_write_addr_no_quirk (struct smiapp_sensor *sensor,u32 reg,u32 val); +int ccs_write_addr (struct smiapp_sensor *sensor,u32 reg,u32 val);unsigned int ccs_reg_width (u32 reg);#define ccs_read (sensor, reg_name, val) \ - smiapp_read(sensor, CCS_R_##reg_name, val) + ccs_read_addr(sensor, CCS_R_##reg_name, val)#define ccs_write (sensor, reg_name, val) \ - smiapp_write(sensor, CCS_R_##reg_name, val) + ccs_write_addr(sensor, CCS_R_##reg_name, val)#endif
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 29/106 ccs: Remove the I²C ID table
In reply to Sakari AilusThe I²C ID table is no longer needed; remove it.
--- drivers/media/i2c/ccs/ccs-core.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +0 -7
@@ -3244,12 +3244,6 @@ static const struct of_device_id ccs_of_table[] = { };MODULE_DEVICE_TABLE (of, ccs_of_table); -static const struct i2c_device_id ccs_id_table[] = { - {SMIAPP_NAME ,0 }, - { }, -}; -MODULE_DEVICE_TABLE (i2c, ccs_id_table); -static const struct dev_pm_ops ccs_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(ccs_suspend, ccs_resume)SET_RUNTIME_PM_OPS (ccs_power_off, ccs_power_on,NULL )
@@ -3263,7 +3257,6 @@ static struct i2c_driver ccs_i2c_driver = { }, .probe_new = ccs_probe, .remove = ccs_remove, - .id_table = ccs_id_table, };static int ccs_module_init (void )
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 6/106 smiapp: Use MIPI CCS version and manufacturer ID information
In reply to Sakari AilusRead MIPI CCS manufacturer and version information, and use the CCS IDs over SMIA whenever they are set.
--- drivers/media/i2c/smiapp/smiapp-core.c | 76 +++++++++++++++++++------- drivers/media/i2c/smiapp/smiapp.h | 20 ++++--- 2 files changed, 68 insertions(+), 28 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +56 -20
@@ -2356,9 +2356,14 @@ smiapp_sysfs_ident_read(struct device *dev, struct device_attribute *attr,struct smiapp_sensor *sensor =to_smiapp_sensor (subdev);struct smiapp_module_info *minfo = &sensor->minfo; -return snprintf (buf,PAGE_SIZE ,"%2.2x%4.4x%2.2x\n" , - minfo->manufacturer_id, minfo->model_id, - minfo->revision_number_major) +1 ; +if (minfo->mipi_manufacturer_id) +return snprintf (buf,PAGE_SIZE ,"%4.4x%4.4x%2.2x\n" , + minfo->mipi_manufacturer_id, minfo->model_id, + minfo->revision_number_major) +1 ; +else +return snprintf (buf,PAGE_SIZE ,"%2.2x%4.4x%2.2x\n" , + minfo->smia_manufacturer_id, minfo->model_id, + minfo->revision_number_major) +1 ; } static DEVICE_ATTR(ident, S_IRUGO, smiapp_sysfs_ident_read, NULL);
@@ -2377,8 +2382,11 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor) minfo->name =SMIAPP_NAME ;/* Module info */ - rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_MANUFACTURER_ID , - &minfo->manufacturer_id); + rval =ccs_read (sensor,MODULE_MANUFACTURER_ID , + &minfo->mipi_manufacturer_id); +if (!rval && !minfo->mipi_manufacturer_id) + rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_MANUFACTURER_ID , + &minfo->smia_manufacturer_id);if (!rval) rval =smiapp_read_8only (sensor,SMIAPP_REG_U16_MODEL_ID , &minfo->model_id);
@@ -2404,9 +2412,12 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor)/* Sensor info */ if (!rval) + rval =ccs_read (sensor,SENSOR_MANUFACTURER_ID , + &minfo->sensor_mipi_manufacturer_id); +if (!rval && !minfo->sensor_mipi_manufacturer_id) rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID , - &minfo->sensor_manufacturer_id); + &minfo->sensor_smia_manufacturer_id);if (!rval) rval = smiapp_read_8only(sensor, SMIAPP_REG_U16_SENSOR_MODEL_ID,
@@ -2422,9 +2433,11 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor)/* SMIA */ if (!rval) + rval =ccs_read (sensor,MIPI_CCS_VERSION , &minfo->ccs_version); +if (!rval && !minfo->ccs_version) rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_SMIA_VERSION , &minfo->smia_version); -if (!rval) +if (!rval && !minfo->ccs_version) rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_SMIAPP_VERSION , &minfo->smiapp_version);
@@ -2433,38 +2446,62 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor)return -ENODEV ; } -dev_dbg (&client->dev,"module 0x%2.2x-0x%4.4x\n" , - minfo->manufacturer_id, minfo->model_id); +if (minfo->mipi_manufacturer_id) +dev_dbg (&client->dev,"MIPI CCS module 0x%4.4x-0x%4.4x\n" , + minfo->mipi_manufacturer_id, minfo->model_id); +else +dev_dbg (&client->dev,"SMIA module 0x%2.2x-0x%4.4x\n" , + minfo->smia_manufacturer_id, minfo->model_id);dev_dbg (&client->dev,"module revision 0x%2.2x-0x%2.2x date %2.2d-%2.2d-%2.2d\n" , minfo->revision_number_major, minfo->revision_number_minor, minfo->module_year, minfo->module_month, minfo->module_day); -dev_dbg (&client->dev,"sensor 0x%2.2x-0x%4.4x\n" , - minfo->sensor_manufacturer_id, minfo->sensor_model_id); +if (minfo->sensor_mipi_manufacturer_id) +dev_dbg (&client->dev,"MIPI CCS sensor 0x%4.4x-0x%4.4x\n" , + minfo->sensor_mipi_manufacturer_id, + minfo->sensor_model_id); +else +dev_dbg (&client->dev,"SMIA sensor 0x%2.2x-0x%4.4x\n" , + minfo->sensor_smia_manufacturer_id, + minfo->sensor_model_id);dev_dbg (&client->dev,"sensor revision 0x%2.2x firmware version 0x%2.2x\n" , minfo->sensor_revision_number, minfo->sensor_firmware_version); -dev_dbg (&client->dev,"smia version %2.2d smiapp version %2.2d\n" , - minfo->smia_version, minfo->smiapp_version); +if (minfo->ccs_version) +dev_dbg (&client->dev,"MIPI CCS version %u.%u" , + (minfo->ccs_version &CCS_MIPI_CCS_VERSION_MAJOR_MASK ) + >>CCS_MIPI_CCS_VERSION_MAJOR_SHIFT , + (minfo->ccs_version &CCS_MIPI_CCS_VERSION_MINOR_MASK )); +else +dev_dbg (&client->dev, +"smia version %2.2d smiapp version %2.2d\n" , + minfo->smia_version, minfo->smiapp_version);/* * Some modules have bad data in the lvalues below. Hope the * rvalues have better stuff. The lvalues are module * parameters whereas the rvalues are sensor parameters. */ -if (!minfo->manufacturer_id && !minfo->model_id) { - minfo->manufacturer_id = minfo->sensor_manufacturer_id; +if (minfo->sensor_smia_manufacturer_id && + !minfo->smia_manufacturer_id && !minfo->model_id) { + minfo->smia_manufacturer_id = + minfo->sensor_smia_manufacturer_id; minfo->model_id = minfo->sensor_model_id; minfo->revision_number_major = minfo->sensor_revision_number; }for (i =0 ; i <ARRAY_SIZE (smiapp_module_idents); i++) { -if (smiapp_module_idents[i].manufacturer_id - != minfo->manufacturer_id) +if (smiapp_module_idents[i].mipi_manufacturer_id && + smiapp_module_idents[i].mipi_manufacturer_id + != minfo->mipi_manufacturer_id) +continue ; +if (smiapp_module_idents[i].smia_manufacturer_id && + smiapp_module_idents[i].smia_manufacturer_id + != minfo->smia_manufacturer_id)continue ;if (smiapp_module_idents[i].model_id != minfo->model_id)continue ;
@@ -2488,9 +2525,8 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor)dev_warn (&client->dev,"no quirks for this module; let's hope it's fully compliant\n" ); -dev_dbg (&client->dev,"the sensor is called %s, ident %2.2x%4.4x%2.2x\n" , - minfo->name, minfo->manufacturer_id, minfo->model_id, - minfo->revision_number_major); +dev_dbg (&client->dev,"the sensor is called %s\n" , + minfo->name);return 0 ; }
drivers/media/i2c/smiapp/smiapp.h +12 -8
@@ -91,8 +91,9 @@ struct smiapp_quirk;#define SMIAPP_MODULE_IDENT_FLAG_REV_LE (1 << 0)struct smiapp_module_ident { -u8 manufacturer_id; +u16 mipi_manufacturer_id;u16 model_id; +u8 smia_manufacturer_id;u8 revision_number_major;u8 flags;
@@ -102,7 +103,8 @@ struct smiapp_module_ident { };struct smiapp_module_info { -u32 manufacturer_id; +u32 smia_manufacturer_id; +u32 mipi_manufacturer_id;u32 model_id;u32 revision_number_major;u32 revision_number_minor;
@@ -111,13 +113,15 @@ struct smiapp_module_info {u32 module_month;u32 module_day; -u32 sensor_manufacturer_id; +u32 sensor_smia_manufacturer_id; +u32 sensor_mipi_manufacturer_id;u32 sensor_model_id;u32 sensor_revision_number;u32 sensor_firmware_version;u32 smia_version;u32 smiapp_version; +u32 ccs_version;u32 smiapp_profile;
@@ -126,7 +130,7 @@ struct smiapp_module_info { };#define SMIAPP_IDENT_FQ (manufacturer, model, rev, fl, _name, _quirk) \ - { .manufacturer_id = manufacturer, \ + { .smia_manufacturer_id = manufacturer, \ .model_id = model, \ .revision_number_major = rev, \ .flags = fl, \
@@ -134,7 +138,7 @@ struct smiapp_module_info { .quirk = _quirk, }#define SMIAPP_IDENT_LQ (manufacturer, model, rev, _name, _quirk) \ - { .manufacturer_id = manufacturer, \ + { .smia_manufacturer_id = manufacturer, \ .model_id = model, \ .revision_number_major = rev, \ .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \
@@ -142,14 +146,14 @@ struct smiapp_module_info { .quirk = _quirk, }#define SMIAPP_IDENT_L (manufacturer, model, rev, _name) \ - { .manufacturer_id = manufacturer, \ + { .smia_manufacturer_id = manufacturer, \ .model_id = model, \ .revision_number_major = rev, \ .flags = SMIAPP_MODULE_IDENT_FLAG_REV_LE, \ .name = _name, }#define SMIAPP_IDENT_Q (manufacturer, model, rev, _name, _quirk) \ - { .manufacturer_id = manufacturer, \ + { .smia_manufacturer_id = manufacturer, \ .model_id = model, \ .revision_number_major = rev, \ .flags = 0, \
@@ -157,7 +161,7 @@ struct smiapp_module_info { .quirk = _quirk, }#define SMIAPP_IDENT (manufacturer, model, rev, _name) \ - { .manufacturer_id = manufacturer, \ + { .smia_manufacturer_id = manufacturer, \ .model_id = model, \ .revision_number_major = rev, \ .flags = 0, \
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 27/106 ccs: Request for "reset" GPIO
In reply to Sakari AilusThe DT bindings documented "reset-gpios" property but the driver never made use of it. Instead it used a GPIO called "xshutdown", with apprently wrong polarity.
Fix this by requesting "reset" GPIO with the right polarity first, and if that fails, then request "xshutdown" GPIO with the old polarity. This way it works for new users as expected while if someone, somewhere, depended on "xshutdown" GPIO, that continues to work as well.
--- drivers/media/i2c/ccs/ccs-core.c | 14 ++++++++++++-- drivers/media/i2c/ccs/ccs.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +12 -2
@@ -1295,6 +1295,7 @@ static int ccs_power_on(struct device *dev) }usleep_range (1000 ,1000 ); +gpiod_set_value (sensor->reset,0 );gpiod_set_value (sensor->xshutdown,1 ); sleep =SMIAPP_RESET_DELAY (sensor->hwcfg->ext_clk);
@@ -1381,6 +1382,7 @@ static int ccs_power_on(struct device *dev)return 0 ; out_cci_addr_fail: +gpiod_set_value (sensor->reset,1 );gpiod_set_value (sensor->xshutdown,0 );clk_disable_unprepare (sensor->ext_clk);
@@ -1407,6 +1409,7 @@ static int ccs_power_off(struct device *dev)if (sensor->hwcfg->i2c_addr_alt)ccs_write (sensor,SOFTWARE_RESET ,CCS_SOFTWARE_RESET_ON ); +gpiod_set_value (sensor->reset,1 );gpiod_set_value (sensor->xshutdown,0 );clk_disable_unprepare (sensor->ext_clk);usleep_range (5000 ,5000 );
@@ -3008,8 +3011,15 @@ static int ccs_probe(struct i2c_client *client)return -EINVAL ; } - sensor->xshutdown =devm_gpiod_get_optional (&client->dev,"xshutdown" , -GPIOD_OUT_LOW ); + sensor->reset =devm_gpiod_get_optional (&client->dev,"reset" , +GPIOD_OUT_HIGH ); +if (IS_ERR (sensor->reset)) +return PTR_ERR (sensor->reset); +/* Support old users that may have used "xshutdown" property. */ +if (!sensor->reset) + sensor->xshutdown =devm_gpiod_get_optional (&client->dev, +"xshutdown" , +GPIOD_OUT_LOW );if (IS_ERR (sensor->xshutdown))return PTR_ERR (sensor->xshutdown);
drivers/media/i2c/ccs/ccs.h +1 -0
@@ -219,6 +219,7 @@ struct ccs_sensor {struct regulator *vana;struct clk *ext_clk;struct gpio_desc *xshutdown; +struct gpio_desc *reset;void *ccs_limits;u8 nbinning_subtypes;struct ccs_binning_subtype binning_subtypes[CCS_LIM_BINNING_SUB_TYPE_MAX_N +1 ];
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 15/106 smiapp: Internal rename to CCS
In reply to Sakari AilusRename internal names to reflect the driver's new reference. The module name remains the same.
Also fix trivial coding style issues on the way related to e.g. alignment changes due to the rename.
---
drivers/media/i2c/smiapp/Makefile | 4 +-
.../i2c/smiapp/{smiapp-core.c => ccs-core.c} | 888 +++++++++---------
.../smiapp/{smiapp-quirk.c => ccs-quirk.c} | 43 +-
.../smiapp/{smiapp-quirk.h => ccs-quirk.h} | 46 +-
.../{smiapp-regs.c => ccs-reg-access.c} | 41 +-
.../{smiapp-regs.h => ccs-reg-access.h} | 16 +-
drivers/media/i2c/smiapp/{smiapp.h => ccs.h} | 124 +--
7 files changed, 576 insertions(+), 586 deletions(-)
rename drivers/media/i2c/smiapp/{smiapp-core.c => ccs-core.c} (75%)
rename drivers/media/i2c/smiapp/{smiapp-quirk.c => ccs-quirk.c} (83%)
rename drivers/media/i2c/smiapp/{smiapp-quirk.h => ccs-quirk.h} (59%)
rename drivers/media/i2c/smiapp/{smiapp-regs.c => ccs-reg-access.c} (79%)
rename drivers/media/i2c/smiapp/{smiapp-regs.h => ccs-reg-access.h} (55%)
rename drivers/media/i2c/smiapp/{smiapp.h => ccs.h} (65%)drivers/media/i2c/smiapp/Makefile +2 -2
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only -smiapp-objs += smiapp-core.o smiapp-regs.o \ - smiapp-quirk.o ccs-limits.o +smiapp-objs += ccs-core.o ccs-reg-access.o \ + ccs-quirk.o ccs-limits.o obj-$(CONFIG_VIDEO_SMIAPP) += smiapp.o ccflags-y += -I $(srctree)/drivers/media/i2c
drivers/media/i2c/smiapp/ccs-core.c renamed from drivers/media/i2c/smiapp/smiapp-core.c +441 -447
2,057 lines not on this page · raw message
drivers/media/i2c/smiapp/ccs-quirk.c renamed from drivers/media/i2c/smiapp/smiapp-quirk.c +21 -22
138 lines not on this page · raw message
drivers/media/i2c/smiapp/ccs-quirk.h renamed from drivers/media/i2c/smiapp/smiapp-quirk.h +23 -23
85 lines not on this page · raw message
drivers/media/i2c/smiapp/ccs-reg-access.c renamed from drivers/media/i2c/smiapp/smiapp-regs.c +19 -22
128 lines not on this page · raw message
drivers/media/i2c/smiapp/ccs-reg-access.h renamed from drivers/media/i2c/smiapp/smiapp-regs.h +8 -8
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* include/media/smiapp/smiapp-regs.h +* include/media/smiapp/ccs-regs.h * * Generic driver for SMIA/SMIA++ compliant camera modules *
@@ -16,15 +16,15 @@#include "ccs-regs.h" -#define SMIAPP_REG_ADDR (reg) ((u16)reg) +#define CCS_REG_ADDR (reg) ((u16)reg) -struct smiapp_sensor ; +struct ccs_sensor ; -int ccs_read_addr_no_quirk (struct smiapp_sensor *sensor,u32 reg,u32 *val); -int ccs_read_addr (struct smiapp_sensor *sensor,u32 reg,u32 *val); -int ccs_read_addr_8only (struct smiapp_sensor *sensor,u32 reg,u32 *val); -int ccs_write_addr_no_quirk (struct smiapp_sensor *sensor,u32 reg,u32 val); -int ccs_write_addr (struct smiapp_sensor *sensor,u32 reg,u32 val); +int ccs_read_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 *val); +int ccs_read_addr (struct ccs_sensor *sensor,u32 reg,u32 *val); +int ccs_read_addr_8only (struct ccs_sensor *sensor,u32 reg,u32 *val); +int ccs_write_addr_no_quirk (struct ccs_sensor *sensor,u32 reg,u32 val); +int ccs_write_addr (struct ccs_sensor *sensor,u32 reg,u32 val);unsigned int ccs_reg_width (u32 reg);
drivers/media/i2c/smiapp/ccs.h renamed from drivers/media/i2c/smiapp/smiapp.h +62 -62
273 lines not on this page · raw message
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 17/106 smiapp: Rename as "ccs"
In reply to Sakari AilusRename the "smiapp" driver as "ccs". MIPI CCS is the contemporary standard for raw Bayer camera sensors. The driver retains support for the SMIA++ and SMIA compliant camera sensors. A module alias is added for old user space using "smiapp" module name.
Add Intel copyright while at it.
---
MAINTAINERS | 20 +++++++++----------
drivers/media/i2c/Kconfig | 2 +-
drivers/media/i2c/Makefile | 2 +-
drivers/media/i2c/{smiapp => ccs}/Kconfig | 7 ++++---
drivers/media/i2c/{smiapp => ccs}/Makefile | 4 ++--
drivers/media/i2c/{smiapp => ccs}/ccs-core.c | 6 ++++--
drivers/media/i2c/{smiapp => ccs}/ccs-os.h | 0
drivers/media/i2c/{smiapp => ccs}/ccs-quirk.c | 5 +++--
drivers/media/i2c/{smiapp => ccs}/ccs-quirk.h | 5 +++--
.../i2c/{smiapp => ccs}/ccs-reg-access.c | 5 +++--
.../i2c/{smiapp => ccs}/ccs-reg-access.h | 5 +++--
.../media/i2c/{smiapp => ccs}/ccs-regs.txt | 0
drivers/media/i2c/{smiapp => ccs}/ccs.h | 3 ++-
drivers/media/i2c/{smiapp => ccs}/mk-ccs-regs | 0
.../i2c/{smiapp => ccs}/smiapp-reg-defs.h | 3 ++-
15 files changed, 38 insertions(+), 29 deletions(-)
rename drivers/media/i2c/{smiapp => ccs}/Kconfig (55%)
rename drivers/media/i2c/{smiapp => ccs}/Makefile (85%)
rename drivers/media/i2c/{smiapp => ccs}/ccs-core.c (99%)
rename drivers/media/i2c/{smiapp => ccs}/ccs-os.h (100%)
rename drivers/media/i2c/{smiapp => ccs}/ccs-quirk.c (97%)
rename drivers/media/i2c/{smiapp => ccs}/ccs-quirk.h (94%)
rename drivers/media/i2c/{smiapp => ccs}/ccs-reg-access.c (97%)
rename drivers/media/i2c/{smiapp => ccs}/ccs-reg-access.h (86%)
rename drivers/media/i2c/{smiapp => ccs}/ccs-regs.txt (100%)
rename drivers/media/i2c/{smiapp => ccs}/ccs.h (98%)
rename drivers/media/i2c/{smiapp => ccs}/mk-ccs-regs (100%)
rename drivers/media/i2c/{smiapp => ccs}/smiapp-reg-defs.h (99%)MAINTAINERS +10 -10
@@ -11560,6 +11560,16 @@ M: Oliver Neukum <[email protected]> S: Maintained F: drivers/usb/image/microtek.* +MIPI CCS, SMIA AND SMIA++ IMAGE SENSOR DRIVER +M: Sakari Ailus <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/media/i2c/nokia,smia.txt +F: drivers/media/i2c/ccs/ +F: drivers/media/i2c/smiapp-pll.c +F: drivers/media/i2c/smiapp-pll.h +F: include/uapi/linux/smiapp.h + MIPS M: Thomas Bogendoerfer <[email protected]> L: [email protected]
@@ -15957,16 +15967,6 @@ S: Maintained F: drivers/firmware/smccc/ F: include/linux/arm-smccc.h -SMIA AND SMIA++ IMAGE SENSOR DRIVER -M: Sakari Ailus <[email protected]> -L: [email protected] -S: Maintained -F: Documentation/devicetree/bindings/media/i2c/nokia,smia.txt -F: drivers/media/i2c/smiapp-pll.c -F: drivers/media/i2c/smiapp-pll.h -F: drivers/media/i2c/smiapp/ -F: include/uapi/linux/smiapp.h - SMM665 HARDWARE MONITOR DRIVER M: Guenter Roeck <[email protected]> L: [email protected]
drivers/media/i2c/Kconfig +1 -1
@@ -1233,7 +1233,7 @@ config VIDEO_S5K5BAF This is a V4L2 sensor driver for Samsung S5K5BAF 2M camera sensor with an embedded SoC image signal processor. -source "drivers/media/i2c/smiapp/Kconfig" +source "drivers/media/i2c/ccs/Kconfig" source "drivers/media/i2c/et8ek8/Kconfig" config VIDEO_S5C73M3
drivers/media/i2c/Makefile +1 -1
@@ -2,7 +2,7 @@ msp3400-objs := msp3400-driver.o msp3400-kthreads.o obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o -obj-$(CONFIG_VIDEO_SMIAPP) += smiapp/ +obj-$(CONFIG_VIDEO_CCS) += ccs/ obj-$(CONFIG_VIDEO_ET8EK8) += et8ek8/ obj-$(CONFIG_VIDEO_CX25840) += cx25840/ obj-$(CONFIG_VIDEO_M5MOLS) += m5mols/
drivers/media/i2c/ccs/Kconfig renamed from drivers/media/i2c/smiapp/Kconfig +4 -3
@@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only -config VIDEO_SMIAPP - tristate "SMIA++/SMIA sensor support" +config VIDEO_CCS + tristate "MIPI CCS/SMIA++/SMIA sensor support" depends on I2C && VIDEO_V4L2 && HAVE_CLK select MEDIA_CONTROLLER select VIDEO_V4L2_SUBDEV_API select VIDEO_SMIAPP_PLL select V4L2_FWNODE help - This is a generic driver for SMIA++/SMIA camera modules. + This is a generic driver for MIPI CCS, SMIA++ and SMIA compliant + camera sensors.
drivers/media/i2c/ccs/Makefile renamed from drivers/media/i2c/smiapp/Makefile +2 -2
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only -smiapp-objs += ccs-core.o ccs-reg-access.o \ +ccs-objs += ccs-core.o ccs-reg-access.o \ ccs-quirk.o ccs-limits.o -obj-$(CONFIG_VIDEO_SMIAPP) += smiapp.o +obj-$(CONFIG_VIDEO_CCS) += ccs.o ccflags-y += -I $(srctree)/drivers/media/i2c
drivers/media/i2c/ccs/ccs-core.c renamed from drivers/media/i2c/smiapp/ccs-core.c +4 -2
@@ -1,9 +1,10 @@// SPDX-License-Identifier: GPL-2.0-only /* -* drivers/media/i2c/smiapp/ccs-core.c +* drivers/media/i2c/ccs/ccs-core.c * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2010--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> *
@@ -3298,3 +3299,4 @@ module_exit(ccs_module_cleanup);MODULE_AUTHOR ("Sakari Ailus <[email protected]>" );MODULE_DESCRIPTION ("Generic MIPI CCS/SMIA/SMIA++ camera sensor driver" );MODULE_LICENSE ("GPL v2" ); +MODULE_ALIAS ("smiapp" );
drivers/media/i2c/ccs/ccs-os.h renamed from drivers/media/i2c/smiapp/ccs-os.h +0 -0
drivers/media/i2c/ccs/ccs-quirk.c renamed from drivers/media/i2c/smiapp/ccs-quirk.c +3 -2
@@ -1,9 +1,10 @@// SPDX-License-Identifier: GPL-2.0-only /* -* drivers/media/i2c/smiapp/ccs-quirk.c +* drivers/media/i2c/ccs/ccs-quirk.c * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */
drivers/media/i2c/ccs/ccs-quirk.h renamed from drivers/media/i2c/smiapp/ccs-quirk.h +3 -2
@@ -1,9 +1,10 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* drivers/media/i2c/smiapp/ccs-quirk.h +* drivers/media/i2c/ccs/ccs-quirk.h * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */
drivers/media/i2c/ccs/ccs-reg-access.c renamed from drivers/media/i2c/smiapp/ccs-reg-access.c +3 -2
@@ -1,9 +1,10 @@// SPDX-License-Identifier: GPL-2.0-only /* -* drivers/media/i2c/smiapp/ccs-regs.c +* drivers/media/i2c/ccs/ccs-reg-access.c * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */
drivers/media/i2c/ccs/ccs-reg-access.h renamed from drivers/media/i2c/smiapp/ccs-reg-access.h +3 -2
@@ -1,9 +1,10 @@/* SPDX-License-Identifier: GPL-2.0-only */ /* -* include/media/smiapp/ccs-regs.h +* include/media/ccs/ccs-reg-access.h * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */
drivers/media/i2c/ccs/ccs-regs.txt renamed from drivers/media/i2c/smiapp/ccs-regs.txt +0 -0
drivers/media/i2c/ccs/ccs.h renamed from drivers/media/i2c/smiapp/ccs.h +2 -1
@@ -2,8 +2,9 @@/* * drivers/media/i2c/smiapp/ccs.h * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2010--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */
drivers/media/i2c/ccs/mk-ccs-regs renamed from drivers/media/i2c/smiapp/mk-ccs-regs +0 -0
drivers/media/i2c/ccs/smiapp-reg-defs.h renamed from drivers/media/i2c/smiapp/smiapp-reg-defs.h +2 -1
@@ -2,8 +2,9 @@/* * drivers/media/i2c/smiapp/smiapp-reg-defs.h * -* Generic driver for SMIA/SMIA++ compliant camera modules +* Generic driver for MIPI CCS/SMIA/SMIA++ compliant camera sensors * +* Copyright (C) 2020 Intel Corporation * Copyright (C) 2011--2012 Nokia Corporation * Contact: Sakari Ailus <[email protected]> */
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 16/106 smiapp: Differentiate CCS sensors from SMIA in subdev naming
In reply to Sakari AilusCall CCS compliant sensors as "ccs" instead of "smiapp" in absence of a device specific name. This is done based on the value of the manufacturer ID register that is only present in CCS.
--- drivers/media/i2c/smiapp/ccs-core.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/i2c/smiapp/ccs-core.c +5 -4
@@ -2437,8 +2437,6 @@ static int ccs_identify_module(struct ccs_sensor *sensor)unsigned int i;int rval =0 ; - minfo->name =SMIAPP_NAME ; -/* Module info */ rval =ccs_read (sensor,MODULE_MANUFACTURER_ID , &minfo->mipi_manufacturer_id);
@@ -2528,15 +2526,18 @@ static int ccs_identify_module(struct ccs_sensor *sensor)"sensor revision 0x%2.2x firmware version 0x%2.2x\n" , minfo->sensor_revision_number, minfo->sensor_firmware_version); -if (minfo->ccs_version) +if (minfo->ccs_version) {dev_dbg (&client->dev,"MIPI CCS version %u.%u" , (minfo->ccs_version &CCS_MIPI_CCS_VERSION_MAJOR_MASK ) >>CCS_MIPI_CCS_VERSION_MAJOR_SHIFT , (minfo->ccs_version &CCS_MIPI_CCS_VERSION_MINOR_MASK )); -else + minfo->name =CCS_NAME ; + }else {dev_dbg (&client->dev,"smia version %2.2d smiapp version %2.2d\n" , minfo->smia_version, minfo->smiapp_version); + minfo->name =SMIAPP_NAME ; + }/* * Some modules have bad data in the lvalues below. Hope the
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 11/106 smiapp: Use CCS limits in reading binning capabilities
In reply to Sakari AilusUse CCS limits for obtaining binning capabilities and subtypes.
--- drivers/media/i2c/smiapp/smiapp-core.c | 27 +++++++++----------------- 1 file changed, 9 insertions(+), 18 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +9 -18
@@ -3105,26 +3105,17 @@ static int smiapp_probe(struct i2c_client *client) }if (CCS_LIM (sensor,BINNING_CAPABILITY )) { -u32 val; - - rval =smiapp_read (sensor, -SMIAPP_REG_U8_BINNING_SUBTYPES , &val); -if (rval <0 ) { - rval = -ENODEV ; - goto out_free_ccs_limits; - } - sensor->nbinning_subtypes =min_t (u8, val, -SMIAPP_BINNING_SUBTYPES ); + sensor->nbinning_subtypes = +min_t (u8,CCS_LIM (sensor,BINNING_SUB_TYPES ), +CCS_LIM_BINNING_SUB_TYPE_MAX_N );for (i =0 ; i < sensor->nbinning_subtypes; i++) { - rval =smiapp_read ( - sensor,SMIAPP_REG_U8_BINNING_TYPE_n (i), &val); -if (rval <0 ) { - rval = -ENODEV ; - goto out_free_ccs_limits; - } - sensor->binning_subtypes[i] = - *(struct smiapp_binning_subtype *)&val; + sensor->binning_subtypes[i].horizontal = +CCS_LIM_AT (sensor,BINNING_SUB_TYPE , i) >> +CCS_BINNING_SUB_TYPE_COLUMN_SHIFT ; + sensor->binning_subtypes[i].vertical = +CCS_LIM_AT (sensor,BINNING_SUB_TYPE , i) & +CCS_BINNING_SUB_TYPE_ROW_MASK ; dev_dbg(&client->dev, "binning %xx%x\n", sensor->binning_subtypes[i].horizontal,
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 12/106 smiapp: Use CCS registers
In reply to Sakari AilusSwitch to CCS standard registers where they exist. The still relevant SMIA registers are left as-is and the redundant ones are removed.
--- drivers/media/i2c/smiapp/smiapp-core.c | 272 +++++++++++-------------- drivers/media/i2c/smiapp/smiapp.h | 4 +- 2 files changed, 118 insertions(+), 158 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +115 -157
@@ -28,7 +28,6 @@#include <media/v4l2-device.h> #include "ccs-limits.h" -#include "ccs-regs.h" #include "smiapp.h" #define SMIAPP_ALIGN_DIM (dim, flags) \
@@ -357,40 +356,34 @@ static int smiapp_pll_configure(struct smiapp_sensor *sensor)struct smiapp_pll *pll = &sensor->pll;int rval; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_VT_PIX_CLK_DIV , pll->vt.pix_clk_div); + rval =ccs_write (sensor,VT_PIX_CLK_DIV , pll->vt.pix_clk_div);if (rval <0 )return rval; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_VT_SYS_CLK_DIV , pll->vt.sys_clk_div); + rval =ccs_write (sensor,VT_SYS_CLK_DIV , pll->vt.sys_clk_div);if (rval <0 )return rval; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_PRE_PLL_CLK_DIV , pll->pre_pll_clk_div); + rval =ccs_write (sensor,PRE_PLL_CLK_DIV , pll->pre_pll_clk_div);if (rval <0 )return rval; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_PLL_MULTIPLIER , pll->pll_multiplier); + rval =ccs_write (sensor,PLL_MULTIPLIER , pll->pll_multiplier);if (rval <0 )return rval;/* Lane op clock ratio does not apply here. */ - rval =smiapp_write ( - sensor,SMIAPP_REG_U32_REQUESTED_LINK_BIT_RATE_MBPS , -DIV_ROUND_UP (pll->op.sys_clk_freq_hz,1000000 /256 /256 )); + rval =ccs_write (sensor,REQUESTED_LINK_RATE , +DIV_ROUND_UP (pll->op.sys_clk_freq_hz, +1000000 /256 /256 ));if (rval <0 || sensor->minfo.smiapp_profile ==SMIAPP_PROFILE_0 )return rval; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_OP_PIX_CLK_DIV , pll->op.pix_clk_div); + rval =ccs_write (sensor,OP_PIX_CLK_DIV , pll->op.pix_clk_div);if (rval <0 )return rval; -return smiapp_write ( - sensor,SMIAPP_REG_U16_OP_SYS_CLK_DIV , pll->op.sys_clk_div); +return ccs_write (sensor,OP_SYS_CLK_DIV , pll->op.sys_clk_div); } static int smiapp_pll_try(struct smiapp_sensor *sensor,
@@ -522,10 +515,10 @@ static u32 smiapp_pixel_order(struct smiapp_sensor *sensor)if (sensor->hflip) {if (sensor->hflip->val) - flip |=SMIAPP_IMAGE_ORIENTATION_HFLIP ; + flip |=CCS_IMAGE_ORIENTATION_HORIZONTAL_MIRROR ;if (sensor->vflip->val) - flip |=SMIAPP_IMAGE_ORIENTATION_VFLIP ; + flip |=CCS_IMAGE_ORIENTATION_VERTICAL_FLIP ; } flip ^= sensor->hvflip_inv_mask;
@@ -585,10 +578,10 @@ static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)return -EBUSY ;if (sensor->hflip->val) - orient |=SMIAPP_IMAGE_ORIENTATION_HFLIP ; + orient |=CCS_IMAGE_ORIENTATION_HORIZONTAL_MIRROR ;if (sensor->vflip->val) - orient |=SMIAPP_IMAGE_ORIENTATION_VFLIP ; + orient |=CCS_IMAGE_ORIENTATION_VERTICAL_FLIP ; orient ^= sensor->hvflip_inv_mask;
@@ -633,60 +626,50 @@ static int smiapp_set_ctrl(struct v4l2_ctrl *ctrl)switch (ctrl->id) {case V4L2_CID_ANALOGUE_GAIN : - rval =smiapp_write ( - sensor, -SMIAPP_REG_U16_ANALOGUE_GAIN_CODE_GLOBAL , ctrl->val); + rval =ccs_write (sensor,ANALOG_GAIN_CODE_GLOBAL , ctrl->val);break ;case V4L2_CID_EXPOSURE : - rval =smiapp_write ( - sensor, -SMIAPP_REG_U16_COARSE_INTEGRATION_TIME , ctrl->val); + rval =ccs_write (sensor,COARSE_INTEGRATION_TIME , ctrl->val);break ;case V4L2_CID_HFLIP :case V4L2_CID_VFLIP : - rval =smiapp_write (sensor,SMIAPP_REG_U8_IMAGE_ORIENTATION , - orient); + rval =ccs_write (sensor,IMAGE_ORIENTATION , orient);break ;case V4L2_CID_VBLANK : - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_FRAME_LENGTH_LINES , - sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].height - + ctrl->val); + rval =ccs_write (sensor,FRAME_LENGTH_LINES , + sensor->pixel_array->crop[ +SMIAPP_PA_PAD_SRC ].height + + ctrl->val);break ;case V4L2_CID_HBLANK : - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_LINE_LENGTH_PCK , - sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].width - + ctrl->val); + rval =ccs_write (sensor,LINE_LENGTH_PCK , + sensor->pixel_array->crop[ +SMIAPP_PA_PAD_SRC ].width + + ctrl->val);break ;case V4L2_CID_TEST_PATTERN : - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_TEST_PATTERN_MODE , ctrl->val); + rval =ccs_write (sensor,TEST_PATTERN_MODE , ctrl->val);break ;case V4L2_CID_TEST_PATTERN_RED : - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_TEST_DATA_RED , ctrl->val); + rval =ccs_write (sensor,TEST_DATA_RED , ctrl->val);break ;case V4L2_CID_TEST_PATTERN_GREENR : - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_TEST_DATA_GREENR , ctrl->val); + rval =ccs_write (sensor,TEST_DATA_GREENR , ctrl->val);break ;case V4L2_CID_TEST_PATTERN_BLUE : - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_TEST_DATA_BLUE , ctrl->val); + rval =ccs_write (sensor,TEST_DATA_BLUE , ctrl->val);break ;case V4L2_CID_TEST_PATTERN_GREENB : - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_TEST_DATA_GREENB , ctrl->val); + rval =ccs_write (sensor,TEST_DATA_GREENB , ctrl->val);break ;case V4L2_CID_PIXEL_RATE :
@@ -846,8 +829,7 @@ static int smiapp_get_mbus_formats(struct smiapp_sensor *sensor)dev_dbg (&client->dev,"data_format_model_type %d\n" , type); - rval =smiapp_read (sensor,SMIAPP_REG_U8_PIXEL_ORDER , - &pixel_order); + rval =ccs_read (sensor,PIXEL_ORDER , &pixel_order);if (rval)return rval;
@@ -1054,22 +1036,20 @@ static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm, *status =0 ; - rval =smiapp_write (sensor, -SMIAPP_REG_U8_DATA_TRANSFER_IF_1_PAGE_SELECT , p); + rval =ccs_write (sensor,DATA_TRANSFER_IF_1_PAGE_SELECT , p);if (rval)return rval; - rval =smiapp_write (sensor,SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL , -SMIAPP_DATA_TRANSFER_IF_1_CTRL_EN ); + rval =ccs_write (sensor,DATA_TRANSFER_IF_1_CTRL , +CCS_DATA_TRANSFER_IF_1_CTRL_ENABLE );if (rval)return rval; - rval =smiapp_read (sensor,SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS , - &s); + rval =ccs_read (sensor,DATA_TRANSFER_IF_1_STATUS , &s);if (rval)return rval; -if (s &SMIAPP_DATA_TRANSFER_IF_1_STATUS_EUSAGE ) { +if (s &CCS_DATA_TRANSFER_IF_1_STATUS_IMPROPER_IF_USAGE ) { *status = s;return -ENODATA ; }
@@ -1077,14 +1057,10 @@ static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm,if (CCS_LIM (sensor,DATA_TRANSFER_IF_CAPABILITY ) &CCS_DATA_TRANSFER_IF_CAPABILITY_POLLING ) {for (i =1000 ; i >0 ; i--) { -if (s &SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY ) +if (s &CCS_DATA_TRANSFER_IF_1_STATUS_READ_IF_READY )break ; - rval =smiapp_read ( - sensor, -SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS , - &s); - + rval =ccs_read (sensor,DATA_TRANSFER_IF_1_STATUS , &s);if (rval)return rval; }
@@ -1093,12 +1069,10 @@ static int smiapp_read_nvm_page(struct smiapp_sensor *sensor, u32 p, u8 *nvm,return -ETIMEDOUT ; } -for (i =0 ; i <SMIAPP_NVM_PAGE_SIZE ; i++) { +for (i =0 ; i <=CCS_LIM_DATA_TRANSFER_IF_1_DATA_MAX_P ; i++) {u32 v; - rval =smiapp_read (sensor, -SMIAPP_REG_U8_DATA_TRANSFER_IF_1_DATA_0 + i, - &v); + rval =ccs_read (sensor,DATA_TRANSFER_IF_1_DATA (i), &v);if (rval)return rval;
@@ -1115,20 +1089,21 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor, unsigned char *nvm,u32 p;int rval =0 , rval2; -for (p =0 ; p < nvm_size /SMIAPP_NVM_PAGE_SIZE && !rval; p++) { +for (p =0 ; p < nvm_size / (CCS_LIM_DATA_TRANSFER_IF_1_DATA_MAX_P +1 ) + && !rval; p++) { rval =smiapp_read_nvm_page (sensor, p, nvm, &status); - nvm +=SMIAPP_NVM_PAGE_SIZE ; + nvm +=CCS_LIM_DATA_TRANSFER_IF_1_DATA_MAX_P +1 ; }if (rval == -ENODATA && - status &SMIAPP_DATA_TRANSFER_IF_1_STATUS_EUSAGE ) + status &CCS_DATA_TRANSFER_IF_1_STATUS_IMPROPER_IF_USAGE ) rval =0 ; - rval2 =smiapp_write (sensor,SMIAPP_REG_U8_DATA_TRANSFER_IF_1_CTRL ,0 ); + rval2 =ccs_write (sensor,DATA_TRANSFER_IF_1_CTRL ,0 );if (rval <0 )return rval;else -return rval2 ?: p *SMIAPP_NVM_PAGE_SIZE ; +return rval2 ?: p * (CCS_LIM_DATA_TRANSFER_IF_1_DATA_MAX_P +1 ); }/*
@@ -1144,16 +1119,15 @@ static int smiapp_change_cci_addr(struct smiapp_sensor *sensor) client->addr = sensor->hwcfg->i2c_addr_dfl; - rval =smiapp_write (sensor, -SMIAPP_REG_U8_CCI_ADDRESS_CONTROL , - sensor->hwcfg->i2c_addr_alt <<1 ); + rval =ccs_write (sensor,CCI_ADDRESS_CTRL , + sensor->hwcfg->i2c_addr_alt <<1 );if (rval)return rval; client->addr = sensor->hwcfg->i2c_addr_alt;/* verify addr change went ok */ - rval =smiapp_read (sensor,SMIAPP_REG_U8_CCI_ADDRESS_CONTROL , &val); + rval =ccs_read (sensor,CCI_ADDRESS_CTRL , &val);if (rval)return rval;
@@ -1259,34 +1233,30 @@ static int smiapp_setup_flash_strobe(struct smiapp_sensor *sensor) strobe_width_high_rs = (tmp + strobe_adjustment -1 ) / strobe_adjustment; - rval =smiapp_write (sensor,SMIAPP_REG_U8_FLASH_MODE_RS , - strobe_setup->mode); + rval =ccs_write (sensor,FLASH_MODE_RS , strobe_setup->mode);if (rval <0 ) goto out; - rval =smiapp_write (sensor,SMIAPP_REG_U8_FLASH_STROBE_ADJUSTMENT , - strobe_adjustment); + rval =ccs_write (sensor,FLASH_STROBE_ADJUSTMENT , strobe_adjustment);if (rval <0 ) goto out; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_TFLASH_STROBE_WIDTH_HIGH_RS_CTRL , - strobe_width_high_rs); + rval =ccs_write (sensor,TFLASH_STROBE_WIDTH_HIGH_RS_CTRL , + strobe_width_high_rs);if (rval <0 ) goto out; - rval =smiapp_write (sensor,SMIAPP_REG_U16_TFLASH_STROBE_DELAY_RS_CTRL , - strobe_setup->strobe_delay); + rval =ccs_write (sensor,TFLASH_STROBE_DELAY_RS_CTRL , + strobe_setup->strobe_delay);if (rval <0 ) goto out; - rval =smiapp_write (sensor,SMIAPP_REG_U16_FLASH_STROBE_START_POINT , - strobe_setup->stobe_start_point); + rval =ccs_write (sensor,FLASH_STROBE_START_POINT , + strobe_setup->stobe_start_point);if (rval <0 ) goto out; - rval =smiapp_write (sensor,SMIAPP_REG_U8_FLASH_TRIGGER_RS , - strobe_setup->trigger); + rval =ccs_write (sensor,FLASH_TRIGGER_RS , strobe_setup->trigger); out: sensor->hwcfg->strobe_setup->trigger =0 ;
@@ -1349,8 +1319,7 @@ static int smiapp_power_on(struct device *dev) } } - rval =smiapp_write (sensor,SMIAPP_REG_U8_SOFTWARE_RESET , -SMIAPP_SOFTWARE_RESET ); + rval =ccs_write (sensor,SOFTWARE_RESET ,CCS_SOFTWARE_RESET_ON );if (rval <0 ) {dev_err (dev,"software reset failed\n" ); goto out_cci_addr_fail;
@@ -1364,45 +1333,42 @@ static int smiapp_power_on(struct device *dev) } } - rval =smiapp_write (sensor,SMIAPP_REG_U16_COMPRESSION_MODE , -SMIAPP_COMPRESSION_MODE_SIMPLE_PREDICTOR ); + rval =ccs_write (sensor,COMPRESSION_MODE , +CCS_COMPRESSION_MODE_DPCM_PCM_SIMPLE );if (rval) {dev_err (dev,"compression mode set failed\n" ); goto out_cci_addr_fail; } - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_EXTCLK_FREQUENCY_MHZ , - sensor->hwcfg->ext_clk / (1000000 / (1 <<8 ))); + rval =ccs_write (sensor,EXTCLK_FREQUENCY_MHZ , + sensor->hwcfg->ext_clk / (1000000 / (1 <<8 )));if (rval) {dev_err (dev,"extclk frequency set failed\n" ); goto out_cci_addr_fail; } - rval =smiapp_write (sensor,SMIAPP_REG_U8_CSI_LANE_MODE , - sensor->hwcfg->lanes -1 ); + rval =ccs_write (sensor,CSI_LANE_MODE , sensor->hwcfg->lanes -1 );if (rval) {dev_err (dev,"csi lane mode set failed\n" ); goto out_cci_addr_fail; } - rval =smiapp_write (sensor,SMIAPP_REG_U8_FAST_STANDBY_CTRL , -SMIAPP_FAST_STANDBY_CTRL_IMMEDIATE ); + rval =ccs_write (sensor,FAST_STANDBY_CTRL , +CCS_FAST_STANDBY_CTRL_FRAME_TRUNCATION );if (rval) {dev_err (dev,"fast standby set failed\n" ); goto out_cci_addr_fail; } - rval =smiapp_write (sensor,SMIAPP_REG_U8_CSI_SIGNALLING_MODE , - sensor->hwcfg->csi_signalling_mode); + rval =ccs_write (sensor,CSI_SIGNALING_MODE , + sensor->hwcfg->csi_signalling_mode);if (rval) {dev_err (dev,"csi signalling mode set failed\n" ); goto out_cci_addr_fail; }/* DPHY control done by sensor based on requested link rate */ - rval =smiapp_write (sensor,SMIAPP_REG_U8_DPHY_CTRL , -SMIAPP_DPHY_CTRL_UI ); + rval =ccs_write (sensor,PHY_CTRL ,CCS_PHY_CTRL_UI );if (rval <0 ) goto out_cci_addr_fail;
@@ -1439,9 +1405,7 @@ static int smiapp_power_off(struct device *dev)* will fail. So do a soft reset explicitly here. */ if (sensor->hwcfg->i2c_addr_alt) -smiapp_write (sensor, -SMIAPP_REG_U8_SOFTWARE_RESET , -SMIAPP_SOFTWARE_RESET ); +ccs_write (sensor,SOFTWARE_RESET ,CCS_SOFTWARE_RESET_ON );gpiod_set_value (sensor->xshutdown,0 );clk_disable_unprepare (sensor->ext_clk);
@@ -1464,9 +1428,9 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)mutex_lock (&sensor->mutex); - rval =smiapp_write (sensor,SMIAPP_REG_U16_CSI_DATA_FORMAT , - (sensor->csi_format->width <<8 ) | - sensor->csi_format->compressed); + rval =ccs_write (sensor,CSI_DATA_FORMAT , + (sensor->csi_format->width <<8 ) | + sensor->csi_format->compressed);if (rval) goto out;
@@ -1479,14 +1443,13 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor) (sensor->binning_horizontal <<4 ) | sensor->binning_vertical; - rval =smiapp_write ( - sensor,SMIAPP_REG_U8_BINNING_TYPE , binning_type); + rval =ccs_write (sensor,BINNING_TYPE , binning_type);if (rval <0 ) goto out; binning_mode =1 ; } - rval =smiapp_write (sensor,SMIAPP_REG_U8_BINNING_MODE , binning_mode); + rval =ccs_write (sensor,BINNING_MODE , binning_mode);if (rval <0 ) goto out;
@@ -1496,26 +1459,26 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor) goto out;/* Analog crop start coordinates */ - rval =smiapp_write (sensor,SMIAPP_REG_U16_X_ADDR_START , - sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].left); + rval =ccs_write (sensor,X_ADDR_START , + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].left);if (rval <0 ) goto out; - rval =smiapp_write (sensor,SMIAPP_REG_U16_Y_ADDR_START , - sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].top); + rval =ccs_write (sensor,Y_ADDR_START , + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].top);if (rval <0 ) goto out;/* Analog crop end coordinates */ - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_X_ADDR_END , + rval =ccs_write ( + sensor,X_ADDR_END , sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].left + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].width -1 );if (rval <0 ) goto out; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_Y_ADDR_END , + rval =ccs_write ( + sensor,Y_ADDR_END , sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].top + sensor->pixel_array->crop[SMIAPP_PA_PAD_SRC ].height -1 );if (rval <0 )
@@ -1529,26 +1492,26 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)/* Digital crop */ if (CCS_LIM (sensor,DIGITAL_CROP_CAPABILITY ) ==CCS_DIGITAL_CROP_CAPABILITY_INPUT_CROP ) { - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_DIGITAL_CROP_X_OFFSET , + rval =ccs_write ( + sensor,DIGITAL_CROP_X_OFFSET , sensor->scaler->crop[SMIAPP_PAD_SINK ].left);if (rval <0 ) goto out; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_DIGITAL_CROP_Y_OFFSET , + rval =ccs_write ( + sensor,DIGITAL_CROP_Y_OFFSET , sensor->scaler->crop[SMIAPP_PAD_SINK ].top);if (rval <0 ) goto out; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_WIDTH , + rval =ccs_write ( + sensor,DIGITAL_CROP_IMAGE_WIDTH , sensor->scaler->crop[SMIAPP_PAD_SINK ].width);if (rval <0 ) goto out; - rval =smiapp_write ( - sensor,SMIAPP_REG_U16_DIGITAL_CROP_IMAGE_HEIGHT , + rval =ccs_write ( + sensor,DIGITAL_CROP_IMAGE_HEIGHT , sensor->scaler->crop[SMIAPP_PAD_SINK ].height);if (rval <0 ) goto out;
@@ -1557,24 +1520,22 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)/* Scaling */ if (CCS_LIM (sensor,SCALING_CAPABILITY ) !=CCS_SCALING_CAPABILITY_NONE ) { - rval =smiapp_write (sensor,SMIAPP_REG_U16_SCALING_MODE , - sensor->scaling_mode); + rval =ccs_write (sensor,SCALING_MODE , sensor->scaling_mode);if (rval <0 ) goto out; - rval =smiapp_write (sensor,SMIAPP_REG_U16_SCALE_M , - sensor->scale_m); + rval =ccs_write (sensor,SCALE_M , sensor->scale_m);if (rval <0 ) goto out; }/* Output size from sensor */ - rval =smiapp_write (sensor,SMIAPP_REG_U16_X_OUTPUT_SIZE , - sensor->src->crop[SMIAPP_PAD_SRC ].width); + rval =ccs_write (sensor,X_OUTPUT_SIZE , + sensor->src->crop[SMIAPP_PAD_SRC ].width);if (rval <0 ) goto out; - rval =smiapp_write (sensor,SMIAPP_REG_U16_Y_OUTPUT_SIZE , - sensor->src->crop[SMIAPP_PAD_SRC ].height); + rval =ccs_write (sensor,Y_OUTPUT_SIZE , + sensor->src->crop[SMIAPP_PAD_SRC ].height);if (rval <0 ) goto out;
@@ -1594,8 +1555,7 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor) goto out; } - rval =smiapp_write (sensor,SMIAPP_REG_U8_MODE_SELECT , -SMIAPP_MODE_SELECT_STREAMING ); + rval =ccs_write (sensor,MODE_SELECT ,CCS_MODE_SELECT_STREAMING ); out:mutex_unlock (&sensor->mutex);
@@ -1609,8 +1569,7 @@ static int smiapp_stop_streaming(struct smiapp_sensor *sensor)int rval;mutex_lock (&sensor->mutex); - rval =smiapp_write (sensor,SMIAPP_REG_U8_MODE_SELECT , -SMIAPP_MODE_SELECT_SOFTWARE_STANDBY ); + rval =ccs_write (sensor,MODE_SELECT ,CCS_MODE_SELECT_SOFTWARE_STANDBY );if (rval) goto out;
@@ -1828,7 +1787,7 @@ static void smiapp_propagate(struct v4l2_subdev *subdev, sensor->scale_m =CCS_LIM (sensor,SCALER_N_MIN ); sensor->scaling_mode = -SMIAPP_SCALING_MODE_NONE ; +CCS_SCALING_MODE_NO_SCALING ; }else if (ssd == sensor->binner) { sensor->binning_horizontal =1 ; sensor->binning_vertical =1 ;
@@ -2063,7 +2022,7 @@ static void smiapp_set_compose_scaler(struct v4l2_subdev *subdev,struct smiapp_sensor *sensor =to_smiapp_sensor (subdev);u32 min, max, a, b, max_m;u32 scale_m =CCS_LIM (sensor,SCALER_N_MIN ); -int mode =SMIAPP_SCALING_MODE_HORIZONTAL ; +int mode =CCS_SCALING_MODE_HORIZONTAL ;u32 try[4 ];u32 ntry =0 ;unsigned int i;
@@ -2123,7 +2082,7 @@ static void smiapp_set_compose_scaler(struct v4l2_subdev *subdev,if (this > best) { scale_m = try[i]; - mode =SMIAPP_SCALING_MODE_HORIZONTAL ; + mode =CCS_SCALING_MODE_HORIZONTAL ; best = this; }
@@ -2494,26 +2453,24 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor) rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_MANUFACTURER_ID , &minfo->smia_manufacturer_id);if (!rval) - rval =smiapp_read_8only (sensor,SMIAPP_REG_U16_MODEL_ID , + rval =smiapp_read_8only (sensor,CCS_R_MODULE_MODEL_ID , &minfo->model_id);if (!rval) rval =smiapp_read_8only (sensor, -SMIAPP_REG_U8_REVISION_NUMBER_MAJOR , +CCS_R_MODULE_REVISION_NUMBER_MAJOR , &minfo->revision_number_major);if (!rval) rval =smiapp_read_8only (sensor, -SMIAPP_REG_U8_REVISION_NUMBER_MINOR , +CCS_R_MODULE_REVISION_NUMBER_MINOR , &minfo->revision_number_minor);if (!rval) - rval =smiapp_read_8only (sensor, -SMIAPP_REG_U8_MODULE_DATE_YEAR , + rval =smiapp_read_8only (sensor,CCS_R_MODULE_DATE_YEAR , &minfo->module_year);if (!rval) - rval =smiapp_read_8only (sensor, -SMIAPP_REG_U8_MODULE_DATE_MONTH , + rval =smiapp_read_8only (sensor,CCS_R_MODULE_DATE_MONTH , &minfo->module_month);if (!rval) - rval =smiapp_read_8only (sensor,SMIAPP_REG_U8_MODULE_DATE_DAY , + rval =smiapp_read_8only (sensor,CCS_R_MODULE_DATE_DAY , &minfo->module_day);/* Sensor info */
@@ -2522,19 +2479,19 @@ static int smiapp_identify_module(struct smiapp_sensor *sensor) &minfo->sensor_mipi_manufacturer_id);if (!rval && !minfo->sensor_mipi_manufacturer_id) rval =smiapp_read_8only (sensor, -SMIAPP_REG_U8_SENSOR_MANUFACTURER_ID , +CCS_R_SENSOR_MANUFACTURER_ID , &minfo->sensor_smia_manufacturer_id);if (!rval) rval =smiapp_read_8only (sensor, -SMIAPP_REG_U16_SENSOR_MODEL_ID , +CCS_R_SENSOR_MODEL_ID , &minfo->sensor_model_id);if (!rval) rval =smiapp_read_8only (sensor, -SMIAPP_REG_U8_SENSOR_REVISION_NUMBER , +CCS_R_SENSOR_REVISION_NUMBER , &minfo->sensor_revision_number);if (!rval) rval =smiapp_read_8only (sensor, -SMIAPP_REG_U8_SENSOR_FIRMWARE_VERSION , +CCS_R_SENSOR_FIRMWARE_VERSION , &minfo->sensor_firmware_version);/* SMIA */
@@ -2919,7 +2876,7 @@ static struct smiapp_hwconfig *smiapp_get_hwconfig(struct device *dev)switch (bus_cfg.bus_type) {case V4L2_MBUS_CSI2_DPHY : - hwcfg->csi_signalling_mode =SMIAPP_CSI_SIGNALLING_MODE_CSI2 ; + hwcfg->csi_signalling_mode =CCS_CSI_SIGNALING_MODE_CSI_2_DPHY ; hwcfg->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;break ;case V4L2_MBUS_CCP2 :
@@ -3095,8 +3052,9 @@ static int smiapp_probe(struct i2c_client *client)*/ if (sensor->hwcfg->module_board_orient ==SMIAPP_MODULE_BOARD_ORIENT_180 ) - sensor->hvflip_inv_mask =SMIAPP_IMAGE_ORIENTATION_HFLIP | -SMIAPP_IMAGE_ORIENTATION_VFLIP ; + sensor->hvflip_inv_mask = +CCS_IMAGE_ORIENTATION_HORIZONTAL_MIRROR | +CCS_IMAGE_ORIENTATION_VERTICAL_FLIP ; rval =smiapp_call_quirk (sensor, limits);if (rval) {
drivers/media/i2c/smiapp/smiapp.h +3 -1
@@ -15,6 +15,8 @@#include <media/v4l2-ctrls.h> #include <media/v4l2-subdev.h> +#include "ccs-regs.h" +#include "smiapp-pll.h" #include "smiapp-reg-defs.h" #include "smiapp-regs.h"
@@ -220,7 +222,7 @@ struct smiapp_sensor {struct gpio_desc *xshutdown;void *ccs_limits;u8 nbinning_subtypes; -struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES ]; +struct smiapp_binning_subtype binning_subtypes[CCS_LIM_BINNING_SUB_TYPE_MAX_N +1 ];u32 mbus_frame_fmts;const struct smiapp_csi_data_format *csi_format;const struct smiapp_csi_data_format *internal_csi_format;
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 7/106 smiapp: Read CCS limit values
In reply to Sakari AilusRead limit and capability values into a driver allocated buffer. This will later replace (most of) the existing SMIA limits.
--- drivers/media/i2c/smiapp/smiapp-core.c | 177 ++++++++++++++++++++++++- drivers/media/i2c/smiapp/smiapp.h | 4 + 2 files changed, 176 insertions(+), 5 deletions(-)
drivers/media/i2c/smiapp/smiapp-core.c +172 -5
@@ -28,6 +28,7 @@#include <media/v4l2-device.h> #include "ccs-limits.h" +#include "ccs-regs.h" #include "smiapp.h" #define SMIAPP_ALIGN_DIM (dim, flags) \
@@ -102,6 +103,164 @@ static int smiapp_read_all_smia_limits(struct smiapp_sensor *sensor)return 0 ; } +static void ccs_assign_limit (void *ptr,unsigned int width,u32 val) +{ +switch (width) { +case sizeof (u8): + *(u8 *)ptr = val; +break ; +case sizeof (u16): + *(u16 *)ptr = val; +break ; +case sizeof (u32): + *(u32 *)ptr = val; +break ; + } +} + +static int ccs_limit_ptr (struct smiapp_sensor *sensor,unsigned int limit, +unsigned int offset,void **__ptr) +{ +const struct ccs_limit *linfo; + +if (WARN_ON (limit >=CCS_L_LAST )) +return -EINVAL ; + + linfo = &ccs_limits[ccs_limit_offsets[limit].info]; + +if (WARN_ON (!sensor->ccs_limits) || +WARN_ON (offset +ccs_reg_width (linfo->reg) > + ccs_limit_offsets[limit +1 ].lim)) +return -EINVAL ; + + *__ptr = sensor->ccs_limits + ccs_limit_offsets[limit].lim + offset; + +return 0 ; +} + +void ccs_replace_limit (struct smiapp_sensor *sensor, +unsigned int limit,unsigned int offset,u32 val) +{ +struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); +const struct ccs_limit *linfo; +void *ptr; +int ret; + + ret =ccs_limit_ptr (sensor, limit, offset, &ptr); +if (ret) +return ; + + linfo = &ccs_limits[ccs_limit_offsets[limit].info]; + +dev_dbg (&client->dev,"quirk: 0x%8.8x \"%s\" %u = %d, 0x%x\n" , + linfo->reg, linfo->name, offset, val, val); + +ccs_assign_limit (ptr,ccs_reg_width (linfo->reg), val); +} + +static u32 ccs_get_limit (struct smiapp_sensor *sensor, +unsigned int limit,unsigned int offset) +{ +void *ptr; +int ret; + + ret =ccs_limit_ptr (sensor, limit, offset, &ptr); +if (ret) +return 0 ; + +switch (ccs_reg_width (ccs_limits[ccs_limit_offsets[limit].info].reg)) { +case sizeof (u8): +return *(u8 *)ptr; +case sizeof (u16): +return *(u16 *)ptr; +case sizeof (u32): +return *(u32 *)ptr; + } + +WARN_ON (1 ); + +return 0 ; +} + +#define CCS_LIM (sensor, limit) \ + ccs_get_limit(sensor, CCS_L_##limit, 0) + +#define CCS_LIM_AT (sensor, limit, offset) \ + ccs_get_limit(sensor, CCS_L_##limit, CCS_L_##limit##_OFFSET(offset)) + +static int ccs_read_all_limits (struct smiapp_sensor *sensor) +{ +struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd); +void *ptr, *alloc, *end; +unsigned int i, l; +int ret; + +kfree (sensor->ccs_limits); + sensor->ccs_limits =NULL ; + + alloc =kzalloc (ccs_limit_offsets[CCS_L_LAST ].lim,GFP_KERNEL ); +if (!alloc) +return -ENOMEM ; + + end = alloc + ccs_limit_offsets[CCS_L_LAST ].lim; + +for (i =0 , l =0 , ptr = alloc; ccs_limits[i].size; i++) { +u32 reg = ccs_limits[i].reg; +unsigned int width =ccs_reg_width (reg); +unsigned int j; + +if (l ==CCS_L_LAST ) { +dev_err (&client->dev, +"internal error --- end of limit array\n" ); + ret = -EINVAL ; + goto out_err; + } + +for (j =0 ; j < ccs_limits[i].size / width; + j++, reg += width, ptr += width) { +u32 val; + + ret =smiapp_read (sensor, reg, &val); +if (ret) + goto out_err; + +if (ptr + width > end) { +dev_err (&client->dev, +"internal error --- no room for regs\n" ); + ret = -EINVAL ; + goto out_err; + } + +ccs_assign_limit (ptr, width, val); + +dev_dbg (&client->dev,"0x%8.8x \"%s\" = %u, 0x%x\n" , + reg, ccs_limits[i].name, val, val); + } + +if (ccs_limits[i].flags &CCS_L_FL_SAME_REG ) +continue ; + + l++; + ptr = alloc + ccs_limit_offsets[l].lim; + } + +if (l !=CCS_L_LAST ) { +dev_err (&client->dev, +"internal error --- insufficient limits\n" ); + ret = -EINVAL ; + goto out_err; + } + + sensor->ccs_limits = alloc; + +return 0 ; + +out_err: +kfree (alloc); + +return ret; +} +static int smiapp_read_frame_fmt (struct smiapp_sensor *sensor) {struct i2c_client *client =v4l2_get_subdevdata (&sensor->src->sd);
@@ -2970,10 +3129,14 @@ static int smiapp_probe(struct i2c_client *client) goto out_power_off; } + rval =ccs_read_all_limits (sensor); +if (rval) + goto out_power_off; + rval =smiapp_read_frame_fmt (sensor);if (rval) { rval = -ENODEV ; - goto out_power_off; + goto out_free_ccs_limits; }/*
@@ -2997,7 +3160,7 @@ static int smiapp_probe(struct i2c_client *client) rval =smiapp_call_quirk (sensor, limits);if (rval) {dev_err (&client->dev,"limits quirks failed\n" ); - goto out_power_off; + goto out_free_ccs_limits; }if (SMIA_LIM (sensor,BINNING_CAPABILITY )) {
@@ -3007,7 +3170,7 @@ static int smiapp_probe(struct i2c_client *client) SMIAPP_REG_U8_BINNING_SUBTYPES, &val);if (rval <0 ) { rval = -ENODEV ; - goto out_power_off; + goto out_free_ccs_limits; } sensor->nbinning_subtypes =min_t (u8, val,SMIAPP_BINNING_SUBTYPES );
@@ -3017,7 +3180,7 @@ static int smiapp_probe(struct i2c_client *client) sensor, SMIAPP_REG_U8_BINNING_TYPE_n(i), &val);if (rval <0 ) { rval = -ENODEV ; - goto out_power_off; + goto out_free_ccs_limits; } sensor->binning_subtypes[i] = *(struct smiapp_binning_subtype *)&val;
@@ -3033,7 +3196,7 @@ static int smiapp_probe(struct i2c_client *client)if (device_create_file (&client->dev, &dev_attr_ident) !=0 ) {dev_err (&client->dev,"sysfs ident entry creation failed\n" ); rval = -ENOENT ; - goto out_power_off; + goto out_free_ccs_limits; } if (sensor->minfo.smiapp_version &&
@@ -3150,6 +3313,9 @@ static int smiapp_probe(struct i2c_client *client) out_cleanup:smiapp_cleanup (sensor); +out_free_ccs_limits: +kfree (sensor->ccs_limits); + out_power_off:smiapp_power_off (&client->dev);mutex_destroy (&sensor->mutex);
@@ -3176,6 +3342,7 @@ static int smiapp_remove(struct i2c_client *client) }smiapp_cleanup (sensor);mutex_destroy (&sensor->mutex); +kfree (sensor->ccs_limits);return 0 ; }
drivers/media/i2c/smiapp/smiapp.h +4 -0
@@ -228,6 +228,7 @@ struct smiapp_sensor {struct clk *ext_clk;struct gpio_desc *xshutdown;u32 limits[SMIAPP_LIMIT_LAST ]; +void *ccs_limits;u8 nbinning_subtypes;struct smiapp_binning_subtype binning_subtypes[SMIAPP_BINNING_SUBTYPES ];u32 mbus_frame_fmts;
@@ -281,4 +282,7 @@ struct smiapp_sensor {#define to_smiapp_sensor (_sd) \ (to_smiapp_subdev(_sd)->sensor) +void ccs_replace_limit (struct smiapp_sensor *sensor, +unsigned int limit,unsigned int offset,u32 val); +#endif /* __SMIAPP_PRIV_H_ */
Signature · 1 line
2.27.0
Sakari Ailus
maintainerPATCH v2 1/106 smiapp: Generate CCS register definitions and limits
In reply to Sakari AilusAdd register definitions of the MIPI CCS 1.1 standard.
The CCS driver makes extended use of device's capability registers that are dependent on CCS version. This involves having an in-memory data structure for limit and capability information, creating that data structure and accessing it.
The register definitions as well as the definitions of this data structure are generated from a text file using a Perl script. Do the generation here and so avoid making manual, error-prone changes to the several generated files.
Also add ccs-os.h header that contains Linux headers to be included.
--- drivers/media/i2c/smiapp/Makefile | 15 +- drivers/media/i2c/smiapp/ccs-os.h | 15 + drivers/media/i2c/smiapp/ccs-regs.txt | 1041 +++++++++++++++++++++++++ drivers/media/i2c/smiapp/mk-ccs-regs | 405 ++++++++++ 4 files changed, 1475 insertions(+), 1 deletion(-) create mode 100644 drivers/media/i2c/smiapp/ccs-os.h create mode 100644 drivers/media/i2c/smiapp/ccs-regs.txt create mode 100644 drivers/media/i2c/smiapp/mk-ccs-regs
drivers/media/i2c/smiapp/Makefile +14 -1
@@ -1,6 +1,19 @@ # SPDX-License-Identifier: GPL-2.0-only smiapp-objs += smiapp-core.o smiapp-regs.o \ - smiapp-quirk.o smiapp-limits.o + smiapp-quirk.o smiapp-limits.o \ + ccs-limits.o obj-$(CONFIG_VIDEO_SMIAPP) += smiapp.o ccflags-y += -I $(srctree)/drivers/media/i2c + +quiet_cmd_perlgen = PERL $(src)/mk-ccs-regs + cmd_perlgen = $(PERL) $(src)/mk-ccs-regs -e $(obj)/ccs-regs.h \ + -L $(obj)/ccs-limits.h -l $(obj)/ccs-limits.c \ + -c $(src)/ccs-regs.txt + +$(obj)/ccs-limits.c: $(src)/ccs-regs.txt + $(call cmd,perlgen) + +$(obj)/ccs-regs.h $(obj)/ccs-limits.h: $(obj)/ccs-limits.c + +clean-files: $(obj)/ccs-regs.h $(obj)/ccs-limits.h $(obj)/ccs-limits.c
drivers/media/i2c/smiapp/ccs-os.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright 2020 Intel Corporation */ + +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/limits.h> +#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/types.h> + +typedef struct device *printf_ctx ; +#define os_printf dev_dbg +#define os_calloc (size) kvcalloc(1, size, GFP_KERNEL) +#define os_free kvfree +#define align2 ALIGN
drivers/media/i2c/smiapp/ccs-regs.txt new file +1041 -0
1,041 lines not on this page · raw message
drivers/media/i2c/smiapp/mk-ccs-regs new file +405 -0
405 lines not on this page · raw message
Signature · 1 line
2.27.0
Rob Herring
maintainerRe: [PATCH v2 026/106] dt-bindings: mipi-ccs: Add bus-type for C-PHY support
In reply to Sakari AilusQuoted 11 lines · Sakari Ailus
The bus-type property is required for C-PHY support. Add it, including values for CCP2 and CSI-2 D-PHY.
Also require the bus-type property. Effectively all new sensors are MIPI D-PHY or C-PHY that cannot be told apart without the bus-type property.
Signed-off-by Sakari Ailus <[email protected]>--- .../devicetree/bindings/media/i2c/mipi-ccs.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)
My bot found errors running 'make dt_binding_check' on your patch:
Traceback (most recent call last):
File "/usr/local/bin/dt-extract-example", line 45, in <module>
binding = yaml.load(open(args.yamlfile, encoding='utf-8').read())
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/main.py", line 343, in load
return constructor.get_single_data()
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/constructor.py", line 111, in get_single_data
node = self.composer.get_single_node()
File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 773, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 852, in _ruamel_yaml.CParser._compose_sequence_node
File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.scanner.ScannerError: while scanning a plain scalar
in "<unicode string>", line 89, column 13
found a tab character that violates indentation
in "<unicode string>", line 90, column 1
make[1]: *** [Documentation/devicetree/bindings/Makefile:18: Documentation/devicetree/bindings/media/i2c/mipi-ccs.example.dts] Error 1 make[1]: *** Deleting file 'Documentation/devicetree/bindings/media/i2c/mipi-ccs.example.dts'
make[1]: *** Waiting for unfinished jobs...../Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml: while scanning a plain scalar
in "<unicode string>", line 89, column 13
found a tab character that violates indentation
in "<unicode string>", line 90, column 1
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml: ignoring, error parsing file
warning: no schema found in file: ./Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml
make: *** [Makefile:1366: dt_binding_check] Error 2
See https://patchwork.ozlabs.org/patch/1377845
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure dt-schema is up to date:
pip3 install git+https://github.com/devicetree-org/dt-schema.git@master --upgrade
Please check and re-submit.
Sakari Ailus
maintainerRe: [PATCH v2 026/106] dt-bindings: mipi-ccs: Add bus-type for C-PHY support
Hi Rob,
Quoted 54 lines · Rob Herring
Quoted 11 lines · Sakari Ailus
The bus-type property is required for C-PHY support. Add it, including values for CCP2 and CSI-2 D-PHY.
Also require the bus-type property. Effectively all new sensors are MIPI D-PHY or C-PHY that cannot be told apart without the bus-type property.
Signed-off-by Sakari Ailus <[email protected]>--- .../devicetree/bindings/media/i2c/mipi-ccs.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)My bot found errors running 'make
dt_binding_check' on your patch:Traceback (most recent call last):
File "/usr/local/bin/dt-extract-example", line 45, in <module>
binding =yaml.load(open(args.yamlfile, encoding='utf-8').read())
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/main.py", line 343, in load
returnconstructor.get_single_data()
File "/usr/local/lib/python3.8/dist-packages/ruamel/yaml/constructor.py", line 111, inget_single_data
node =self.composer.get_single_node()
File "_ruamel_yaml.pyx", line 706, in _ruamel_yaml.CParser.get_single_node
File "_ruamel_yaml.pyx", line 724, in _ruamel_yaml.CParser._compose_document
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 775, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 889, in _ruamel_yaml.CParser._compose_mapping_node
File "_ruamel_yaml.pyx", line 773, in _ruamel_yaml.CParser._compose_node
File "_ruamel_yaml.pyx", line 852, in _ruamel_yaml.CParser._compose_sequence_node
File "_ruamel_yaml.pyx", line 904, in _ruamel_yaml.CParser._parse_next_event
ruamel.yaml.scanner.ScannerError: while scanning a plain scalar
in "<unicode string>", line 89, column 13
found a tab character that violates indentation
in "<unicode string>", line 90, column 1
make[1]: *** [Documentation/devicetree/bindings/Makefile:18:Documentation/devicetree/bindings/media/i2c/mipi-ccs.example.dts] Error 1 make[1]: *** Deleting file 'Documentation/devicetree/bindings/media/i2c/mipi-ccs.example.dts'
make[1]: *** Waiting for unfinished jobs...../Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml: while scanning a plain scalar
in "<unicode string>", line 89, column 13
found a tab character that violates indentation
in "<unicode string>", line 90, column 1
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml: ignoring, error parsing file
warning: no schema found in file:./Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml
make: *** [Makefile:1366:dt_binding_check] Error 2
Quoted 8 lines
See https://patchwork.ozlabs.org/patch/1377845
If you already ran 'make
dt_binding_check' and didn't see the above error(s), then make sure dt-schema is up to date:pip3 install git+https://github.com/devicetree-org/dt-schema.git@master --upgrade
Please check and re-submit.
I tested this but somehow I managed to change it after testing it. :-)
I'll resend in a moment.
Signature · 3 lines
Kind regards, Sakari Ailus
Sakari Ailus
maintainerPATCH v3 26/106 dt-bindings: mipi-ccs: Add bus-type for C-PHY support
In reply to Rob HerringThe bus-type property is required for C-PHY support. Add it, including values for CCP2 and CSI-2 D-PHY.
Also require the bus-type property. Effectively all new sensors are MIPI D-PHY or C-PHY that cannot be told apart without the bus-type property.
--- .../devicetree/bindings/media/i2c/mipi-ccs.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml +9 -0
@@ -77,9 +77,17 @@ properties: data-lanes: minItems: 1 maxItems: 8 + bus-type: + description: The type of the data bus. + oneOf: + - const: 1 # CSI-2 C-PHY + - const: 3 # CCP2 + - const: 4 # CSI-2 D-PHY + required: - link-frequencies - data-lanes + - bus-type required: - compatible
@@ -112,6 +120,7 @@ examples: remote-endpoint = <&csi2a_ep>; link-frequencies = /bits/ 64 <199200000 210000000 499200000>; + bus-type = <4>; }; }; };
Signature · 1 line
2.27.0
Re: [PATCH v2 022/106] dt-bindings: nokia,smia: Remove nokia,nvm-size property
In reply to Sakari AilusQuoted 8 lines · Sakari Ailus
nokia,nvm-size property was removed from the bindings but it was left in the example. Remove it from the example, too.
Signed-off-by Sakari Ailus <[email protected]>--- Documentation/devicetree/bindings/media/i2c/nokia,smia.txt | 1 - 1 file changed, 1 deletion(-)
Re: [PATCH v2 023/106] dt-bindings: nokia,smia: Convert to YAML
In reply to Sakari AilusQuoted 4 lines · Sakari Ailus
Convert nokia,smia DT bindings to YAML.
Also add explicit license to bindings.
Quoted 9 lines
Signed-off-by Sakari Ailus <[email protected]>--- .../bindings/media/i2c/nokia,smia.txt | 67 ----------- .../bindings/media/i2c/nokia,smia.yaml | 106 ++++++++++++++++++ MAINTAINERS | 2 +- 3 files changed, 107 insertions(+), 68 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/i2c/nokia,smia.txt create mode 100644 Documentation/devicetree/bindings/media/i2c/nokia,smia.yaml
Re: [PATCH v2 025/106] dt-bindings: nokia,smia: Amend SMIA bindings with MIPI CCS support
In reply to Sakari AilusQuoted 11 lines · Sakari Ailus
Amend the existing SMIA bindings by adding MIPI CCS support, with separate compatible strings for CCS 1.0 and CCS 1.1. Rename the old bindings accordingly as CCS is the current standard.
Signed-off-by Sakari Ailus <[email protected]>--- .../i2c/{nokia,smia.yaml => mipi-ccs.yaml} | 23 ++++++++++++++----- MAINTAINERS | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) rename Documentation/devicetree/bindings/media/i2c/{nokia,smia.yaml => mipi-ccs.yaml} (81%)
Re: [PATCH v2 053/106] dt-bindings: mipi,ccs: Don't mention vana voltage
In reply to Sakari AilusQuoted 8 lines · Sakari Ailus
It was mentioned vana voltage is typically 2,8 volts. This is truly sensor dependent, and nowadays 2,8 volts is a lot.
Signed-off-by Sakari Ailus <[email protected]>--- Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [PATCH v2 054/106] dt-bindings: mipi,ccs: Add vcore and vio supplies
In reply to Sakari AilusQuoted 8 lines · Sakari Ailus
Vcore and vio supplies are also part of the spec and used by many sensors. Do not specify the voltages as they are generally sensor dependent.
Signed-off-by Sakari Ailus <[email protected]>--- Documentation/devicetree/bindings/media/i2c/mipi-ccs.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Re: [PATCH v3 026/106] dt-bindings: mipi-ccs: Add bus-type for C-PHY support
In reply to Sakari AilusQuoted 11 lines · Sakari Ailus
The bus-type property is required for C-PHY support. Add it, including values for CCP2 and CSI-2 D-PHY.
Also require the bus-type property. Effectively all new sensors are MIPI D-PHY or C-PHY that cannot be told apart without the bus-type property.
Signed-off-by Sakari Ailus <[email protected]>--- .../devicetree/bindings/media/i2c/mipi-ccs.yaml | 9 +++++++++ 1 file changed, 9 insertions(+)
Re: [PATCH v2 001/106] smiapp: Generate CCS register definitions and limits
In reply to Sakari AilusHi,
Em Wed, 7 Oct 2020 11:44:21 +0300
Sakari Ailus <[email protected]> escreveu:
Quoted 11 lines
Add register definitions of the MIPI CCS 1.1 standard.
The CCS driver makes extended use of device's capability registers that are dependent on CCS version. This involves having an in-memory data structure for limit and capability information, creating that data structure and accessing it.
The register definitions as well as the definitions of this data structure are generated from a text file using a Perl script. Do the generation here and so avoid making manual, error-prone changes to the several generated files.
I understand the reason behind using a perl script to parse some text file in order to generate register's definition files, but I can't see what's the sense of storing the perl script and such texts together with the Kernel building system, re-generating them every time.
I mean: register definitions is something that it is supposed to be stable, and nothing something that will change on every Kernel compilation.
How often are you expecting changes at ccs-regs.txt?
Quoted 1,508 lines
Also add
ccs-os.hheader that contains Linux headers to be included.Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/smiapp/Makefile | 15 +- drivers/media/i2c/smiapp/ccs-os.h | 15 + drivers/media/i2c/smiapp/ccs-regs.txt | 1041 +++++++++++++++++++++++++ drivers/media/i2c/smiapp/mk-ccs-regs | 405 ++++++++++ 4 files changed, 1475 insertions(+), 1 deletion(-) create mode 100644 drivers/media/i2c/smiapp/ccs-os.h create mode 100644 drivers/media/i2c/smiapp/ccs-regs.txt create mode 100644 drivers/media/i2c/smiapp/mk-ccs-regsdrivers/media/i2c/smiapp/Makefile +14
-1@@ -1,6 +1,19 @@ # SPDX-License-Identifier: GPL-2.0-only smiapp-objs += smiapp-core.o smiapp-regs.o \ - smiapp-quirk.o smiapp-limits.o + smiapp-quirk.o smiapp-limits.o \ + ccs-limits.o obj-$(CONFIG_VIDEO_SMIAPP) += smiapp.o ccflags-y += -I $(srctree)/drivers/media/i2c + +quiet_cmd_perlgen = PERL $(src)/mk-ccs-regs + cmd_perlgen = $(PERL) $(src)/mk-ccs-regs -e $(obj)/ccs-regs.h \ + -L $(obj)/ccs-limits.h -l $(obj)/ccs-limits.c \ + -c $(src)/ccs-regs.txt + +$(obj)/ccs-limits.c: $(src)/ccs-regs.txt + $(call cmd,perlgen) + +$(obj)/ccs-regs.h $(obj)/ccs-limits.h: $(obj)/ccs-limits.c + +clean-files: $(obj)/ccs-regs.h $(obj)/ccs-limits.h $(obj)/ccs-limits.cdrivers/media/i2c/smiapp/ccs-os.h new file +15
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright 2020 Intel Corporation */ + +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/limits.h> +#include <linux/mm.h> +#include <linux/slab.h> +#include <linux/types.h> + +typedef struct device *printf_ctx ; +#define os_printf dev_dbg +#define os_calloc (size) kvcalloc(1, size, GFP_KERNEL) +#define os_free kvfree +#define align2 ALIGNdrivers/media/i2c/smiapp/ccs-regs.txt new file +1041
-0@@ -0,0 +1,1041 @@ +# Copyright (C) 2019--2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause + +# register rflags +# - f field LSB MSB rflags +# - e enum value # after a field +# - e enum value [LSB MSB] +# - b bool bit +# - l arg name min max elsize [discontig...] +# +# rflags +# 8, 16, 32 register bits (default is 8) +# v1.1 defined in version 1.1 +# f formula +# float_ireal iReal or IEEE 754; 32 bits +# ireal unsigned iReal + +# general status registers +module_model_id 0x0000 16 +module_revision_number_major 0x0002 8 +frame_count 0x0005 8 +pixel_order 0x0006 8 +- e GRBG 0 +- e RGGB 1 +- e BGGR 2 +- e GBRG 3 +MIPI_CCS_version 0x0007 8 +- e v1_0 0x10 +- e v1_1 0x11 +- f major 4 7 +- f minor 0 3 +data_pedestal 0x0008 16 +module_manufacturer_id 0x000e 16 +module_revision_number_minor 0x0010 8 +module_date_year 0x0012 8 +module_date_month 0x0013 8 +module_date_day 0x0014 8 +module_date_phase 0x0015 8 +- f 0 2 +- e ts 0 +- e es 1 +- e cs 2 +- e mp 3 +sensor_model_id 0x0016 16 +sensor_revision_number 0x0018 8 +sensor_firmware_version 0x001a 8 +serial_number 0x001c 32 +sensor_manufacturer_id 0x0020 16 +sensor_revision_number_16 0x0022 16 + +# frame format description registers +frame_format_model_type 0x0040 8 +- e 2-byte 1 +- e 4-byte 2 +frame_format_model_subtype 0x0041 8 +- f rows 0 3 +- f columns 4 7 +frame_format_descriptor(n) 0x0042 16 f +- l n 0 14 2 +- f pixels 0 11 +- f pcode 12 15 +- e embedded 1 +- e dummy_pixel 2 +- e black_pixel 3 +- e dark_pixel 4 +- e visible_pixel 5 +- e manuf_specific_0 8 +- e manuf_specific_1 9 +- e manuf_specific_2 10 +- e manuf_specific_3 11 +- e manuf_specific_4 12 +- e manuf_specific_5 13 +- e manuf_specific_6 14 +frame_format_descriptor_4(n) 0x0060 32 f +- l n 0 7 4 +- f pixels 0 15 +- f pcode 28 31 +- e embedded 1 +- e dummy_pixel 2 +- e black_pixel 3 +- e dark_pixel 4 +- e visible_pixel 5 +- e manuf_specific_0 8 +- e manuf_specific_1 9 +- e manuf_specific_2 10 +- e manuf_specific_3 11 +- e manuf_specific_4 12 +- e manuf_specific_5 13 +- e manuf_specific_6 14 + +# analog gain description registers +analog_gain_capability 0x0080 16 +- e global 0 +- e alternate_global 2 +analog_gain_code_min 0x0084 16 +analog_gain_code_max 0x0086 16 +analog_gain_code_step 0x0088 16 +analog_gain_type 0x008a 16 +analog_gain_m0 0x008c 16 +analog_gain_c0 0x008e 16 +analog_gain_m1 0x0090 16 +analog_gain_c1 0x0092 16 +analog_linear_gain_min 0x0094 16 v1.1 +analog_linear_gain_max 0x0096 16 v1.1 +analog_linear_gain_step_size 0x0098 16 v1.1 +analog_exponential_gain_min 0x009a 16 v1.1 +analog_exponential_gain_max 0x009c 16 v1.1 +analog_exponential_gain_step_size 0x009e 16 v1.1 + +# data format description registers +data_format_model_type 0x00c0 8 +- e normal 1 +- e extended 2 +data_format_model_subtype 0x00c1 8 +- f rows 0 3 +- f columns 4 7 +data_format_descriptor(n) 0x00c2 16 f +- l n 0 15 2 +- f compressed 0 7 +- f uncompressed 8 15 + +# general set-up registers +mode_select 0x0100 8 +- e software_standby 0 +- e streaming 1 +image_orientation 0x0101 8 +- b horizontal_mirror 0 +- b vertical_flip 1 +software_reset 0x0103 8 +- e off 0 +- e on 1 +grouped_parameter_hold 0x0104 8 +mask_corrupted_frames 0x0105 8 +- e allow 0 +- e mask 1 +fast_standby_ctrl 0x0106 8 +- e complete_frames 0 +- e frame_truncation 1 +CCI_address_ctrl 0x0107 8 +2nd_CCI_if_ctrl 0x0108 8 +- b enable 0 +- b ack 1 +2nd_CCI_address_ctrl 0x0109 8 +CSI_channel_identifier 0x0110 8 +CSI_signaling_mode 0x0111 8 +- e csi_2_dphy 2 +- e csi_2_cphy 3 +CSI_data_format 0x0112 16 +CSI_lane_mode 0x0114 8 +DPCM_Frame_DT 0x011d 8 +Bottom_embedded_data_DT 0x011e 8 +Bottom_embedded_data_VC 0x011f 8 + +gain_mode 0x0120 8 +- e global 0 +- e alternate 1 +ADC_bit_depth 0x0121 8 +emb_data_ctrl 0x0122 v1.1 +- b raw8_packing_for_raw16 0 +- b raw10_packing_for_raw20 1 +- b raw12_packing_for_raw24 2 + +GPIO_TRIG_mode 0x0130 8 +extclk_frequency_mhz 0x0136 16 ireal +temp_sensor_ctrl 0x0138 8 +- b enable 0 +temp_sensor_mode 0x0139 8 +temp_sensor_output 0x013a 8 + +# integration time registers +fine_integration_time 0x0200 16 +coarse_integration_time 0x0202 16 + +# analog gain registers +analog_gain_code_global 0x0204 16 +analog_linear_gain_global 0x0206 16 v1.1 +analog_exponential_gain_global 0x0208 16 v1.1 + +# digital gain registers +digital_gain_global 0x020e 16 + +# hdr control registers +Short_analog_gain_global 0x0216 16 +Short_digital_gain_global 0x0218 16 + +HDR_mode 0x0220 8 +- b enabled 0 +- b separate_analog_gain 1 +- b upscaling 2 +- b reset_sync 3 +- b timing_mode 4 +- b exposure_ctrl_direct 5 +- b separate_digital_gain 6 +HDR_resolution_reduction 0x0221 8 +- f row 0 3 +- f column 4 7 +Exposure_ratio 0x0222 8 +HDR_internal_bit_depth 0x0223 8 +Direct_short_integration_time 0x0224 16 +Short_analog_linear_gain_global 0x0226 16 v1.1 +Short_analog_exponential_gain_global 0x0228 16 v1.1 + +# clock set-up registers +vt_pix_clk_div 0x0300 16 +vt_sys_clk_div 0x0302 16 +pre_pll_clk_div 0x0304 16 +#vt_pre_pll_clk_div 0x0304 16 +pll_multiplier 0x0306 16 +#vt_pll_multiplier 0x0306 16 +op_pix_clk_div 0x0308 16 +op_sys_clk_div 0x030a 16 +op_pre_pll_clk_div 0x030c 16 +op_pll_multiplier 0x031e 16 +pll_mode 0x0310 8 +- f 0 0 +- e single 0 +- e dual 1 +op_pix_clk_div_rev 0x0312 16 v1.1 +op_sys_clk_div_rev 0x0314 16 v1.1 + +# frame timing registers +frame_length_lines 0x0340 16 +line_length_pck 0x0342 16 + +# image size registers +x_addr_start 0x0344 16 +y_addr_start 0x0346 16 +x_addr_end 0x0348 16 +y_addr_end 0x034a 16 +x_output_size 0x034c 16 +y_output_size 0x034e 16 + +# timing mode registers +Frame_length_ctrl 0x0350 8 +- b automatic 0 +Timing_mode_ctrl 0x0352 8 +- b manual_readout 0 +- b delayed_exposure 1 +Start_readout_rs 0x0353 8 +- b manual_readout_start 0 +Frame_margin 0x0354 16 + +# sub-sampling registers +x_even_inc 0x0380 16 +x_odd_inc 0x0382 16 +y_even_inc 0x0384 16 +y_odd_inc 0x0386 16 + +# monochrome readout registers +monochrome_en 0x0390 v1.1 +- e enabled 0 + +# image scaling registers +Scaling_mode 0x0400 16 +- e no_scaling 0 +- e horizontal 1 +scale_m 0x0404 16 +scale_n 0x0406 16 +digital_crop_x_offset 0x0408 16 +digital_crop_y_offset 0x040a 16 +digital_crop_image_width 0x040c 16 +digital_crop_image_height 0x040e 16 + +# image compression registers +compression_mode 0x0500 16 +- e none 0 +- e dpcm_pcm_simple 1 + +# test pattern registers +test_pattern_mode 0x0600 16 +- e none 0 +- e solid_color 1 +- e color_bars 2 +- e fade_to_grey 3 +- e pn9 4 +- e color_tile 5 +test_data_red 0x0602 16 +test_data_greenR 0x0604 16 +test_data_blue 0x0606 16 +test_data_greenB 0x0608 16 +value_step_size_smooth 0x060a 8 +value_step_size_quantised 0x060b 8 + +# phy configuration registers +tclk_post 0x0800 8 +ths_prepare 0x0801 8 +ths_zero_min 0x0802 8 +ths_trail 0x0803 8 +tclk_trail_min 0x0804 8 +tclk_prepare 0x0805 8 +tclk_zero 0x0806 8 +tlpx 0x0807 8 +phy_ctrl 0x0808 8 +- e auto 0 +- e UI 1 +- e manual 2 +tclk_post_ex 0x080a 16 +ths_prepare_ex 0x080c 16 +ths_zero_min_ex 0x080e 16 +ths_trail_ex 0x0810 16 +tclk_trail_min_ex 0x0812 16 +tclk_prepare_ex 0x0814 16 +tclk_zero_ex 0x0816 16 +tlpx_ex 0x0818 16 + +# link rate register +requested_link_rate 0x0820 32 u16.16 + +# equalization control registers +DPHY_equalization_mode 0x0824 8 v1.1 +- b eq2 0 +PHY_equalization_ctrl 0x0825 8 v1.1 +- b enable 0 + +# d-phy preamble control registers +DPHY_preamble_ctrl 0x0826 8 v1.1 +- b enable 0 +DPHY_preamble_length 0x0826 8 v1.1 + +# d-phy spread spectrum control registers +PHY_SSC_ctrl 0x0828 8 v1.1 +- b enable 0 + +# manual lp control register +manual_LP_ctrl 0x0829 8 v1.1 +- b enable 0 + +# additional phy configuration registers +twakeup 0x082a v1.1 +tinit 0x082b v1.1 +ths_exit 0x082c v1.1 +ths_exit_ex 0x082e 16 v1.1 + +# phy calibration configuration registers +PHY_periodic_calibration_ctrl 0x0830 8 +- b frame_blanking 0 +PHY_periodic_calibration_interval 0x0831 8 +PHY_init_calibration_ctrl 0x0832 8 +- b stream_start 0 +DPHY_calibration_mode 0x0833 8 v1.1 +- b also_alternate 0 +CPHY_calibration_mode 0x0834 8 v1.1 +- e format_1 0 +- e format_2 1 +- e format_3 2 +t3_calpreamble_length 0x0835 8 v1.1 +t3_calpreamble_length_per 0x0836 8 v1.1 +t3_calaltseq_length 0x0837 8 v1.1 +t3_calaltseq_length_per 0x0838 8 v1.1 +FM2_init_seed 0x083a 16 v1.1 +t3_caludefseq_length 0x083c 16 v1.1 +t3_caludefseq_length_per 0x083e 16 v1.1 + +# c-phy manual control registers +TGR_Preamble_Length 0x0841 8 +- b preamable_prog_seq 7 +- f begin_preamble_length 0 5 +TGR_Post_Length 0x0842 8 +- f post_length 0 4 +TGR_Preamble_Prog_Sequence(n2) 0x0843 +- l n2 0 6 1 +- f symbol_n_1 3 5 +- f symbol_n 0 2 +t3_prepare 0x084e 16 +t3_lpx 0x0850 16 + +# alps control register +ALPS_ctrl 0x085a 8 +- b lvlp_dphy 0 +- b lvlp_cphy 1 +- b alp_cphy 2 + +# lrte control registers +TX_REG_CSI_EPD_EN_SSP_cphy 0x0860 16 +TX_REG_CSI_EPD_OP_SLP_cphy 0x0862 16 +TX_REG_CSI_EPD_EN_SSP_dphy 0x0864 16 +TX_REG_CSI_EPD_OP_SLP_dphy 0x0866 16 +TX_REG_CSI_EPD_MISC_OPTION_cphy 0x0868 v1.1 +TX_REG_CSI_EPD_MISC_OPTION_dphy 0x0869 v1.1 + +# scrambling control registers +Scrambling_ctrl 0x0870 +- b enabled 0 +- f 2 3 +- e 1_seed_cphy 0 +- e 4_seed_cphy 3 +lane_seed_value(seed, lane) 0x0872 16 +- l seed 0 3 0x10 +- l lane 0 7 0x2 + +# usl control registers +TX_USL_REV_ENTRY 0x08c0 16 v1.1 +TX_USL_REV_Clock_Counter 0x08c2 16 v1.1 +TX_USL_REV_LP_Counter 0x08c4 16 v1.1 +TX_USL_REV_Frame_Counter 0x08c6 16 v1.1 +TX_USL_REV_Chronological_Timer 0x08c8 16 v1.1 +TX_USL_FWD_ENTRY 0x08ca 16 v1.1 +TX_USL_GPIO 0x08cc 16 v1.1 +TX_USL_Operation 0x08ce 16 v1.1 +- b reset 0 +TX_USL_ALP_ctrl 0x08d0 16 v1.1 +- b clock_pause 0 +TX_USL_APP_BTA_ACK_TIMEOUT 0x08d2 16 v1.1 +TX_USL_SNS_BTA_ACK_TIMEOUT 0x08d2 16 v1.1 +USL_Clock_Mode_d_ctrl 0x08d2 v1.1 +- b cont_clock_standby 0 +- b cont_clock_vblank 1 +- b cont_clock_hblank 2 + +# binning configuration registers +binning_mode 0x0900 8 +binning_type 0x0901 8 +binning_weighting 0x0902 8 + +# data transfer interface registers +data_transfer_if_1_ctrl 0x0a00 8 +- b enable 0 +- b write 1 +- b clear_error 2 +data_transfer_if_1_status 0x0a01 8 +- b read_if_ready 0 +- b write_if_ready 1 +- b data_corrupted 2 +- b improper_if_usage 3 +data_transfer_if_1_page_select 0x0a02 8 +data_transfer_if_1_data(p) 0x0a04 8 f +- l p 0 63 1 + +# image processing and sensor correction configuration registers +shading_correction_en 0x0b00 8 +- b enable 0 +luminance_correction_level 0x0b01 8 +green_imbalance_filter_en 0x0b02 8 +- b enable 0 +mapped_defect_correct_en 0x0b05 8 +- b enable 0 +single_defect_correct_en 0x0b06 8 +- b enable 0 +dynamic_couplet_correct_en 0x0b08 8 +- b enable 0 +combined_defect_correct_en 0x0b0a 8 +- b enable 0 +module_specific_correction_en 0x0b0c 8 +- b enable 0 +dynamic_triplet_defect_correct_en 0x0b13 8 +- b enable 0 +NF_ctrl 0x0b15 8 +- b luma 0 +- b chroma 1 +- b combined 2 + +# optical black pixel readout registers +OB_readout_control 0x0b30 8 +- b enable 0 +- b interleaving 1 +OB_virtual_channel 0x0b31 8 +OB_DT 0x0b32 8 +OB_data_format 0x0b33 8 + +# color temperature feedback registers +color_temperature 0x0b8c 16 +absolute_gain_greenr 0x0b8e 16 +absolute_gain_red 0x0b90 16 +absolute_gain_blue 0x0b92 16 +absolute_gain_greenb 0x0b94 16 + +# cfa conversion registers +CFA_conversion_ctrl 0x0ba0 v1.1 +- b bayer_conversion_enable 0 + +# flash strobe and sa strobe control registers +flash_strobe_adjustment 0x0c12 8 +flash_strobe_start_point 0x0c14 16 +tflash_strobe_delay_rs_ctrl 0x0c16 16 +tflash_strobe_width_high_rs_ctrl 0x0c18 16 +flash_mode_rs 0x0c1a 8 +- b continuous 0 +- b truncate 1 +- b async 3 +flash_trigger_rs 0x0c1b 8 +flash_status 0x0c1c 8 +- b retimed 0 +sa_strobe_mode 0x0c1d 8 +- b continuous 0 +- b truncate 1 +- b async 3 +- b adjust_edge 4 +sa_strobe_start_point 0x0c1e 16 +tsa_strobe_delay_ctrl 0x0c20 16 +tsa_strobe_width_ctrl 0x0c22 16 +sa_strobe_trigger 0x0c24 8 +sa_strobe_status 0x0c25 8 +- b retimed 0 +tSA_strobe_re_delay_ctrl 0x0c30 16 +tSA_strobe_fe_delay_ctrl 0x0c32 16 + +# pdaf control registers +PDAF_ctrl 0x0d00 16 +- b enable 0 +- b processed 1 +- b interleaved 2 +- b visible_pdaf_correction 3 +PDAF_VC 0x0d02 8 +PDAF_DT 0x0d03 8 +pd_x_addr_start 0x0d04 16 +pd_y_addr_start 0x0d06 16 +pd_x_addr_end 0x0d08 16 +pd_y_addr_end 0x0d0a 16 + +# bracketing interface configuration registers +bracketing_LUT_ctrl 0x0e00 8 +bracketing_LUT_mode 0x0e01 8 +- b continue_streaming 0 +- b loop_mode 1 +bracketing_LUT_entry_ctrl 0x0e02 8 +bracketing_LUT_frame(n) 0x0e10 v1.1 f +- l n 0 0xef 1 + +# integration time and gain parameter limit registers +integration_time_capability 0x1000 16 +- b fine 0 +coarse_integration_time_min 0x1004 16 +coarse_integration_time_max_margin 0x1006 16 +fine_integration_time_min 0x1008 16 +fine_integration_time_max_margin 0x100a 16 + +# digital gain parameter limit registers +digital_gain_capability 0x1081 +- e none 0 +- e global 2 +digital_gain_min 0x1084 16 +digital_gain_max 0x1086 16 +digital_gain_step_size 0x1088 16 + +# data pedestal capability registers +Pedestal_capability 0x10e0 8 v1.1 + +# adc capability registers +ADC_capability 0x10f0 8 +- b bit_depth_ctrl 0 +ADC_bit_depth_capability 0x10f4 32 v1.1 + +# video timing parameter limit registers +min_ext_clk_freq_mhz 0x1100 32 float_ireal +max_ext_clk_freq_mhz 0x1104 32 float_ireal +min_pre_pll_clk_div 0x1108 16 +# min_vt_pre_pll_clk_div 0x1108 16 +max_pre_pll_clk_div 0x110a 16 +# max_vt_pre_pll_clk_div 0x110a 16 +min_pll_ip_clk_freq_mhz 0x110c 32 float_ireal +# min_vt_pll_ip_clk_freq_mhz 0x110c 32 float_ireal +max_pll_ip_clk_freq_mhz 0x1110 32 float_ireal +# max_vt_pll_ip_clk_freq_mhz 0x1110 32 float_ireal +min_pll_multiplier 0x1114 16 +# min_vt_pll_multiplier 0x1114 16 +max_pll_multiplier 0x1116 16 +# max_vt_pll_multiplier 0x1116 16 +min_pll_op_clk_freq_mhz 0x1118 32 float_ireal +max_pll_op_clk_freq_mhz 0x111c 32 float_ireal + +# video timing set-up capability registers +min_vt_sys_clk_div 0x1120 16 +max_vt_sys_clk_div 0x1122 16 +min_vt_sys_clk_freq_mhz 0x1124 32 float_ireal +max_vt_sys_clk_freq_mhz 0x1128 32 float_ireal +min_vt_pix_clk_freq_mhz 0x112c 32 float_ireal +max_vt_pix_clk_freq_mhz 0x1130 32 float_ireal +min_vt_pix_clk_div 0x1134 16 +max_vt_pix_clk_div 0x1136 16 +clock_calculation 0x1138 +- b lane_speed 0 +- b link_decoupled 1 +- b dual_pll_op_sys_ddr 2 +- b dual_pll_op_pix_ddr 3 +num_of_vt_lanes 0x1139 +num_of_op_lanes 0x113a +op_bits_per_lane 0x113b 8 v1.1 + +# frame timing parameter limits +min_frame_length_lines 0x1140 16 +max_frame_length_lines 0x1142 16 +min_line_length_pck 0x1144 16 +max_line_length_pck 0x1146 16 +min_line_blanking_pck 0x1148 16 +min_frame_blanking_lines 0x114a 16 +min_line_length_pck_step_size 0x114c +timing_mode_capability 0x114d +- b auto_frame_length 0 +- b rolling_shutter_manual_readout 2 +- b delayed_exposure_start 3 +- b manual_exposure_embedded_data 4 +frame_margin_max_value 0x114e 16 +frame_margin_min_value 0x1150 +gain_delay_type 0x1151 +- e fixed 0 +- e variable 1 + +# output clock set-up capability registers +min_op_sys_clk_div 0x1160 16 +max_op_sys_clk_div 0x1162 16 +min_op_sys_clk_freq_mhz 0x1164 32 float_ireal +max_op_sys_clk_freq_mhz 0x1168 32 float_ireal +min_op_pix_clk_div 0x116c 16 +max_op_pix_clk_div 0x116e 16 +min_op_pix_clk_freq_mhz 0x1170 32 float_ireal +max_op_pix_clk_freq_mhz 0x1174 32 float_ireal + +# image size parameter limit registers +x_addr_min 0x1180 16 +y_addr_min 0x1182 16 +x_addr_max 0x1184 16 +y_addr_max 0x1186 16 +min_x_output_size 0x1188 16 +min_y_output_size 0x118a 16 +max_x_output_size 0x118c 16 +max_y_output_size 0x118e 16 + +x_addr_start_div_constant 0x1190 v1.1 +y_addr_start_div_constant 0x1191 v1.1 +x_addr_end_div_constant 0x1192 v1.1 +y_addr_end_div_constant 0x1193 v1.1 +x_size_div 0x1194 v1.1 +y_size_div 0x1195 v1.1 +x_output_div 0x1196 v1.1 +y_output_div 0x1197 v1.1 +non_flexible_resolution_support 0x1198 v1.1 +- b new_pix_addr 0 +- b new_output_res 1 +- b output_crop_no_pad 2 +- b output_size_lane_dep 3 + +min_op_pre_pll_clk_div 0x11a0 16 +max_op_pre_pll_clk_div 0x11a2 16 +min_op_pll_ip_clk_freq_mhz 0x11a4 32 float_ireal +max_op_pll_ip_clk_freq_mhz 0x11a8 32 float_ireal +min_op_pll_multiplier 0x11ac 16 +max_op_pll_multiplier 0x11ae 16 +min_op_pll_op_clk_freq_mhz 0x11b0 32 float_ireal +max_op_pll_op_clk_freq_mhz 0x11b4 32 float_ireal +clock_tree_pll_capability 0x11b8 8 +- b dual_pll 0 +- b single_pll 1 +- b ext_divider 2 +- b flexible_op_pix_clk_div 3 +clock_capa_type_capability 0x11b9 v1.1 +- b ireal 0 + +# sub-sampling parameters limit registers +min_even_inc 0x11c0 16 +min_odd_inc 0x11c2 16 +max_even_inc 0x11c4 16 +max_odd_inc 0x11c6 16 +aux_subsamp_capability 0x11c8 v1.1 +- b factor_power_of_2 1 +aux_subsamp_mono_capability 0x11c9 v1.1 +- b factor_power_of_2 1 +monochrome_capability 0x11ca v1.1 +- e inc_odd 0 +- e inc_even 1 +pixel_readout_capability 0x11cb v1.1 +- e bayer 0 +- e monochrome 1 +- e bayer_and_mono 2 +min_even_inc_mono 0x11cc 16 v1.1 +max_even_inc_mono 0x11ce 16 v1.1 +min_odd_inc_mono 0x11d0 16 v1.1 +max_odd_inc_mono 0x11d2 16 v1.1 +min_even_inc_bc2 0x11d4 16 v1.1 +max_even_inc_bc2 0x11d6 16 v1.1 +min_odd_inc_bc2 0x11d8 16 v1.1 +max_odd_inc_bc2 0x11da 16 v1.1 +min_even_inc_mono_bc2 0x11dc 16 v1.1 +max_even_inc_mono_bc2 0x11de 16 v1.1 +min_odd_inc_mono_bc2 0x11f0 16 v1.1 +max_odd_inc_mono_bc2 0x11f2 16 v1.1 + +# image scaling limit parameters +scaling_capability 0x1200 16 +- e none 0 +- e horizontal 1 +- e reserved 2 +scaler_m_min 0x1204 16 +scaler_m_max 0x1206 16 +scaler_n_min 0x1208 16 +scaler_n_max 0x120a 16 +digital_crop_capability 0x120e +- e none 0 +- e input_crop 1 + +# hdr limit registers +hdr_capability_1 0x1210 +- b 2x2_binning 0 +- b combined_analog_gain 1 +- b separate_analog_gain 2 +- b upscaling 3 +- b reset_sync 4 +- b direct_short_exp_timing 5 +- b direct_short_exp_synthesis 6 +min_hdr_bit_depth 0x1211 +hdr_resolution_sub_types 0x1212 +hdr_resolution_sub_type(n) 0x1213 +- l n 0 1 1 +- f row 0 3 +- f column 4 7 +hdr_capability_2 0x121b +- b combined_digital_gain 0 +- b separate_digital_gain 1 +- b timing_mode 3 +- b synthesis_mode 4 +max_hdr_bit_depth 0x121c + +# usl capability register +usl_support_capability 0x1230 v1.1 +- b clock_tree 0 +- b rev_clock_tree 1 +- b rev_clock_calc 2 +usl_clock_mode_d_capability 0x1231 v1.1 +- b cont_clock_standby 0 +- b cont_clock_vblank 1 +- b cont_clock_hblank 2 +- b noncont_clock_standby 3 +- b noncont_clock_vblank 4 +- b noncont_clock_hblank 5 +min_op_sys_clk_div_rev 0x1234 v1.1 +max_op_sys_clk_div_rev 0x1236 v1.1 +min_op_pix_clk_div_rev 0x1238 v1.1 +max_op_pix_clk_div_rev 0x123a v1.1 +min_op_sys_clk_freq_rev_mhz 0x123c 32 v1.1 float_ireal +max_op_sys_clk_freq_rev_mhz 0x1240 32 v1.1 float_ireal +min_op_pix_clk_freq_rev_mhz 0x1244 32 v1.1 float_ireal +max_op_pix_clk_freq_rev_mhz 0x1248 32 v1.1 float_ireal +max_bitrate_rev_d_mode_mbps 0x124c 32 v1.1 ireal +max_symrate_rev_c_mode_msps 0x1250 32 v1.1 ireal + +# image compression capability registers +compression_capability 0x1300 +- b dpcm_pcm_simple 0 + +# test mode capability registers +test_mode_capability 0x1310 16 +- b solid_color 0 +- b color_bars 1 +- b fade_to_grey 2 +- b pn9 3 +- b color_tile 5 +pn9_data_format1 0x1312 +pn9_data_format2 0x1313 +pn9_data_format3 0x1314 +pn9_data_format4 0x1315 +pn9_misc_capability 0x1316 +- f num_pixels 0 2 +- b compression 3 +test_pattern_capability 0x1317 v1.1 +- b no_repeat 1 +pattern_size_div_m1 0x1318 v1.1 + +# fifo capability registers +fifo_support_capability 0x1502 +- e none 0 +- e derating 1 +- e derating_overrating 2 + +# csi-2 capability registers +phy_ctrl_capability 0x1600 +- b auto_phy_ctl 0 +- b ui_phy_ctl 1 +- b dphy_time_ui_reg_1_ctl 2 +- b dphy_time_ui_reg_2_ctl 3 +- b dphy_time_ctl 4 +- b dphy_ext_time_ui_reg_1_ctl 5 +- b dphy_ext_time_ui_reg_2_ctl 6 +- b dphy_ext_time_ctl 7 +csi_dphy_lane_mode_capability 0x1601 +- b 1_lane 0 +- b 2_lane 1 +- b 3_lane 2 +- b 4_lane 3 +- b 5_lane 4 +- b 6_lane 5 +- b 7_lane 6 +- b 8_lane 7 +csi_signaling_mode_capability 0x1602 +- b csi_dphy 2 +- b csi_cphy 3 +fast_standby_capability 0x1603 +- e no_frame_truncation 0 +- e frame_truncation 1 +csi_address_control_capability 0x1604 +- b cci_addr_change 0 +- b 2nd_cci_addr 1 +- b sw_changeable_2nd_cci_addr 2 +data_type_capability 0x1605 +- b dpcm_programmable 0 +- b bottom_embedded_dt_programmable 1 +- b bottom_embedded_vc_programmable 2 +- b ext_vc_range 3 +csi_cphy_lane_mode_capability 0x1606 +- b 1_lane 0 +- b 2_lane 1 +- b 3_lane 2 +- b 4_lane 3 +- b 5_lane 4 +- b 6_lane 5 +- b 7_lane 6 +- b 8_lane 7 +emb_data_capability 0x1607 v1.1 +- b two_bytes_per_raw16 0 +- b two_bytes_per_raw20 1 +- b two_bytes_per_raw24 2 +- b no_one_byte_per_raw16 3 +- b no_one_byte_per_raw20 4 +- b no_one_byte_per_raw24 5 +max_per_lane_bitrate_lane_d_mode_mbps(n) 0x1608 32 ireal +- l n 0 7 4 4,0x32 +temp_sensor_capability 0x1618 +- b supported 0 +- b CCS_format 1 +- b reset_0x80 2 +max_per_lane_bitrate_lane_c_mode_mbps(n) 0x161a 32 ireal +- l n 0 7 4 4,0x30 +dphy_equalization_capability 0x162b +- b equalization_ctrl 0 +- b eq1 1 +- b eq2 2 +cphy_equalization_capability 0x162c +- b equalization_ctrl 0 +dphy_preamble_capability 0x162d +- b preamble_seq_ctrl 0 +dphy_ssc_capability 0x162e +- b supported 0 +cphy_calibration_capability 0x162f +- b manual 0 +- b manual_streaming 1 +- b format_1_ctrl 2 +- b format_2_ctrl 3 +- b format_3_ctrl 4 +dphy_calibration_capability 0x1630 +- b manual 0 +- b manual_streaming 1 +- b alternate_seq 2 +phy_ctrl_capability_2 0x1631 +- b tgr_length 0 +- b tgr_preamble_prog_seq 1 +- b extra_cphy_manual_timing 2 +- b clock_based_manual_cdphy 3 +- b clock_based_manual_dphy 4 +- b clock_based_manual_cphy 5 +- b manual_lp_dphy 6 +- b manual_lp_cphy 7 +lrte_cphy_capability 0x1632 +- b pdq_short 0 +- b spacer_short 1 +- b pdq_long 2 +- b spacer_long 3 +- b spacer_no_pdq 4 +lrte_dphy_capability 0x1633 +- b pdq_short_opt1 0 +- b spacer_short_opt1 1 +- b pdq_long_opt1 2 +- b spacer_long_opt1 3 +- b spacer_short_opt2 4 +- b spacer_long_opt2 5 +- b spacer_no_pdq_opt1 6 +- b spacer_variable_opt2 7 +alps_capability_dphy 0x1634 +- e lvlp_not_supported 0 0x3 +- e lvlp_supported 1 0x3 +- e controllable_lvlp 2 0x3 +alps_capability_cphy 0x1635 +- e lvlp_not_supported 0 0x3 +- e lvlp_supported 1 0x3 +- e controllable_lvlp 2 0x3 +- e alp_not_supported 0xc 0xc +- e alp_supported 0xd 0xc +- e controllable_alp 0xe 0xc +scrambling_capability 0x1636 +- b scrambling_supported 0 +- f max_seeds_per_lane_c 1 2 +- e 1 0 +- e 4 3 +- f num_seed_regs 3 5 +- e 0 0 +- e 1 1 +- e 4 4 +- b num_seed_per_lane 6 +dphy_manual_constant 0x1637 +cphy_manual_constant 0x1638 +CSI2_interface_capability_misc 0x1639 v1.1 +- b eotp_short_pkt_opt2 0 +PHY_ctrl_capability_3 0x165c v1.1 +- b dphy_timing_not_multiple 0 +- b dphy_min_timing_value_1 1 +- b twakeup_supported 2 +- b tinit_supported 3 +- b ths_exit_supported 4 +- b cphy_timing_not_multiple 5 +- b cphy_min_timing_value_1 6 +dphy_sf 0x165d v1.1 +cphy_sf 0x165e v1.1 +- f twakeup 0 3 +- f tinit 4 7 +dphy_limits_1 0x165f v1.1 +- f ths_prepare 0 3 +- f ths_zero 4 7 +dphy_limits_2 0x1660 v1.1 +- f ths_trail 0 3 +- f tclk_trail_min 4 7 +dphy_limits_3 0x1661 v1.1 +- f tclk_prepare 0 3 +- f tclk_zero 4 7 +dphy_limits_4 0x1662 v1.1 +- f tclk_post 0 3 +- f tlpx 4 7 +dphy_limits_5 0x1663 v1.1 +- f ths_exit 0 3 +- f twakeup 4 7 +dphy_limits_6 0x1664 v1.1 +- f tinit 0 3 +cphy_limits_1 0x1665 v1.1 +- f t3_prepare_max 0 3 +- f t3_lpx_max 4 7 +cphy_limits_2 0x1666 v1.1 +- f ths_exit_max 0 3 +- f twakeup_max 4 7 +cphy_limits_3 0x1667 v1.1 +- f tinit_max 0 3 + +# binning capability registers +min_frame_length_lines_bin 0x1700 16 +max_frame_length_lines_bin 0x1702 16 +min_line_length_pck_bin 0x1704 16 +max_line_length_pck_bin 0x1706 16 +min_line_blanking_pck_bin 0x1708 16 +fine_integration_time_min_bin 0x170a 16 +fine_integration_time_max_margin_bin 0x170c 16 +binning_capability 0x1710 +- e unsupported 0 +- e binning_then_subsampling 1 +- e subsampling_then_binning 2 +binning_weighting_capability 0x1711 +- b averaged 0 +- b summed 1 +- b bayer_corrected 2 +- b module_specific_weight 3 +binning_sub_types 0x1712 +binning_sub_type(n) 0x1713 +- l n 0 63 1 +- f row 0 3 +- f column 4 7 +binning_weighting_mono_capability 0x1771 v1.1 +- b averaged 0 +- b summed 1 +- b bayer_corrected 2 +- b module_specific_weight 3 +binning_sub_types_mono 0x1772 v1.1 +binning_sub_type_mono(n) 0x1773 v1.1 f +- l n 0 63 1 + +# data transfer interface capability registers +data_transfer_if_capability 0x1800 +- b supported 0 +- b polling 2 + +# sensor correction capability registers +shading_correction_capability 0x1900 +- b color_shading 0 +- b luminance_correction 1 +green_imbalance_capability 0x1901 +- b supported 0 +module_specific_correction_capability 0x1903 +defect_correction_capability 0x1904 16 +- b mapped_defect 0 +- b dynamic_couplet 2 +- b dynamic_single 5 +- b combined_dynamic 8 +defect_correction_capability_2 0x1906 16 +- b dynamic_triplet 3 +nf_capability 0x1908 +- b luma 0 +- b chroma 1 +- b combined 2 + +# optical black readout capability registers +ob_readout_capability 0x1980 +- b controllable_readout 0 +- b visible_pixel_readout 1 +- b different_vc_readout 2 +- b different_dt_readout 3 +- b prog_data_format 4 + +# color feedback capability registers +color_feedback_capability 0x1987 +- b kelvin 0 +- b awb_gain 1 + +# cfa pattern capability registers +CFA_pattern_capability 0x1990 v1.1 +- e bayer 0 +- e monochrome 1 +- e 4x4_quad_bayer 2 +- e vendor_specific 3 +CFA_pattern_conversion_capability 0x1991 v1.1 +- b bayer 0 + +# timer capability registers +flash_mode_capability 0x1a02 +- b single_strobe 0 +sa_strobe_mode_capability 0x1a03 +- b fixed_width 0 +- b edge_ctrl 1 + +# soft reset capability registers +reset_max_delay 0x1a10 v1.1 +reset_min_time 0x1a11 v1.1 + +# pdaf capability registers +pdaf_capability_1 0x1b80 +- b supported 0 +- b processed_bottom_embedded 1 +- b processed_interleaved 2 +- b raw_bottom_embedded 3 +- b raw_interleaved 4 +- b visible_pdaf_correction 5 +- b vc_interleaving 6 +- b dt_interleaving 7 +pdaf_capability_2 0x1b81 +- b ROI 0 +- b after_digital_crop 1 +- b ctrl_retimed 2 + +# bracketing interface capability registers +bracketing_lut_capability_1 0x1c00 +- b coarse_integration 0 +- b global_analog_gain 1 +- b flash 4 +- b global_digital_gain 5 +- b alternate_global_analog_gain 6 +bracketing_lut_capability_2 0x1c01 +- b single_bracketing_mode 0 +- b looped_bracketing_mode 1 +bracketing_lut_size 0x1c02drivers/media/i2c/smiapp/mk-ccs-regs new file +395
-0@@ -0,0 +1,405 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2019--2020 Intel Corporation +# SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause + +use Getopt::Long qw(:config no_ignore_case); +use File::Basename; + +my $ccsregs = "ccs-regs.txt"; +my $header; +my $regarray; +my $limitc; +my $limith; +my $help; + +GetOptions("ccsregs|c=s" => \$ccsregs, + "header|e=s" => \$header, + "regarray|r=s" => \$regarray, + "limitc|l=s" => \$limitc, + "limith|L=s" => \$limith, + "help|h" => \$help) or die "can't parse options"; + +$help = 1 if ! defined $header || ! defined $limitc || ! defined $limith; + +if (defined $help) { + print <<EOH +$0 - Create CCS register definitions for C + +usage: $0 -c ccs-regs.txt -h header -r regarray -l limit-c -L limit-header + + -c ccs register file + -e header file name + -r register description array file name + -l limit and capability array file name + -L limit and capability header file name +EOH + ; + exit 0; +} + +open(my $R, "< $ccsregs") or die "can't open $ccsregs"; + +open(my $H, "> $header") or die "can't open $header"; +my $A; +if (defined $regarray) { + open($A, "> $regarray") or die "can't open $regarray"; +} +open(my $LC, "> $limitc") or die "can't open $limitc"; +open(my $LH, "> $limith") or die "can't open $limith"; + +my %this; + +sub is_limit_reg($) { + my $addr = hex $_[0]; + + return 0 if $addr < 0x40; # weed out status registers + return 0 if $addr >= 0x100 && $addr < 0xfff; # weed out configuration registers + + return 1; +} + +my $uc_header = basename uc $header; +$uc_header =~ s/[^A-Z0-9]/_/g; + +my $copyright = "/* Copyright (C) 2019--2020 Intel Corporation */\n"; +my $license = "SPDX-License-Identifier: GPL-2.0-only OR BSD-3-Clause"; + +for my $fh ($A, $LC) { + print $fh "// $license\n$copyright\n" if defined $fh; +} + +for my $fh ($H, $LH) { + print $fh "/* $license */\n$copyright\n"; +} + +print $H <<EOF +#ifndef __${uc_header}__ +#define __${uc_header}__ + +#define CCS_FL_BASE 16 +#define CCS_FL_16BIT (1U << CCS_FL_BASE) +#define CCS_FL_32BIT (1U << (CCS_FL_BASE + 1)) +#define CCS_FL_FLOAT_IREAL (1U << (CCS_FL_BASE + 2)) +#define CCS_FL_IREAL (1U << (CCS_FL_BASE + 3)) + +#define CCS_R_ADDR(r) ((r) & 0xffff) + +EOF + ; + +print $A <<EOF +#include <stdint.h> +#include <stdio.h> +#include "ccs-extra.h" +#include "ccs-regs.h" + +EOF + if defined $A; + +my $uc_limith = basename uc $limith; +$uc_limith =~ s/[^A-Z0-9]/_/g; + +print $LH <<EOF +#ifndef __${uc_limith}__ +#define __${uc_limith}__ + +#include "ccs-os.h" + +struct ccs_limit { + uint32_t reg; + uint16_t size; + uint16_t flags; + const char *name; +}; + +#define CCS_L_FL_SAME_REG (1U << 0) + +extern const struct ccs_limit ccs_limits[]; + +EOF + ; + +print $LC <<EOF +#include "ccs-limits.h" +#include "ccs-regs.h" + +const struct ccs_limit ccs_limits[] = { +EOF + ; + +my $limitcount = 0; +my $argdescs; +my $reglist = "const struct ccs_reg_desc ccs_reg_desc[] = {\n"; + +sub name_split($$) { + my ($name, $addr) = @_; + my $args; + + $name =~ /([^\(]+?)(\(.*)/; + ($name, $args) = ($1, $2); + $args = [split /,\s*/, $args]; + foreach my $t (@$args) { + $t =~ s/[\(\)]//g; + $t =~ s/\//\\\//g; + } + + return ($name, $addr, $args); +} + +sub tabconv($) { + $_ = shift; + + my @l = split "\n", $_; + + map { + s/ {8,8}/\t/g; + s/\t\K +//; + } @l; + + return (join "\n", @l) . "\n"; +} + +sub elem_size(@) { + my @flags = @_; + + return 2 if grep /^16$/, @flags; + return 4 if grep /^32$/, @flags; + return 1; +} + +sub arr_size($) { + my $this = $_[0]; + my $size = $this->{elsize}; + my $h = $this->{argparams}; + + foreach my $arg (@{$this->{args}}) { + my $apref = $h->{$arg}; + + $size *= $apref->{max} - $apref->{min} + 1; + } + + return $size; +} + +sub print_args($$$) { + my ($this, $postfix, $is_same_reg) = @_; + my ($args, $argparams, $name) = + ($this->{args}, $this->{argparams}, $this->{name}); + my $varname = "ccs_reg_arg_" . (lc $name) . $postfix; + my @mins; + my @sorted_args = @{$this->{sorted_args}}; + my $lim_arg; + my $size = arr_size($this); + + $argdescs .= "static const struct ccs_reg_arg " . $varname . "[] = {\n"; + + foreach my $sorted_arg (@sorted_args) { + push @mins, $argparams->{$sorted_arg}->{min}; + } + + foreach my $sorted_arg (@sorted_args) { + my $h = $argparams->{$sorted_arg}; + + $argdescs .= "\t{ \"$sorted_arg\", $h->{min}, $h->{max}, $h->{elsize} },\n"; + + $lim_arg .= defined $lim_arg ? ", $h->{min}" : "$h->{min}"; + } + + $argdescs .= "};\n\n"; + + $reglist .= "\t{ CCS_R_" . (uc $name) . "(" . (join ",", (@mins)) . + "), $size, sizeof($varname) / sizeof(*$varname)," . + " \"" . (lc $name) . "\", $varname },\n"; + + print $LC tabconv sprintf "\t{ CCS_R_" . (uc $name) . "($lim_arg), " . + $size . ", " . ($is_same_reg ? "CCS_L_FL_SAME_REG" : "0") . + ", \"$name" . (defined $this->{discontig} ? " $lim_arg" : "") . "\" },\n" + if is_limit_reg $this->{base_addr}; +} + +my $hdr_data; + +while (<$R>) { + chop; + s/^\s*//; + next if /^[#;]/ || /^$/; + if (s/^-\s*//) { + if (s/^b\s*//) { + my ($bit, $addr) = split /\t+/; + $bit = uc $bit; + $hdr_data .= sprintf "#define %-62s %s", "CCS_" . (uc ${this{name}}) ."_$bit", "(1U << $addr)\n"; + } elsif (s/^f\s*//) { + s/[,\.-]/_/g; + my @a = split /\s+/; + my ($msb, $lsb, $this_field) = reverse @a; + @a = ( { "name" => "SHIFT", "addr" => $lsb, "fmt" => "%uU", }, + { "name" => "MASK", "addr" => (1 << ($msb + 1)) - 1 - ((1 << $lsb) - 1), "fmt" => "0x%" . join(".", ($this{"elsize"} >> 2) x 2) . "x" } ); + $this{"field"} = $this_field; + foreach my $ar (@a) { + #print $ar->{fmt}."\n"; + $hdr_data .= sprintf "#define %-62s " . $ar->{"fmt"} . "\n", "CCS_" . (uc $this{"name"}) . (defined $this_field ? "_" . uc $this_field : "") . "_" . $ar->{"name"}, $ar->{"addr"} . "\n"; + } + } elsif (s/^e\s*//) { + s/[,\.-]/_/g; + my ($enum, $addr) = split /\s+/; + $enum = uc $enum; + $hdr_data .= sprintf "#define %-62s %s", "CCS_" . (uc ${this{name}}) . (defined $this{"field"} ? "_" . uc $this{"field"} : "") ."_$enum", $addr . ($addr =~ /0x/i ? "" : "U") . "\n"; + } elsif (s/^l\s*//) { + my ($arg, $min, $max, $elsize, @discontig) = split /\s+/; + my $size; + + foreach my $num ($min, $max) { + $num = hex $num if $num =~ /0x/i; + } + + $hdr_data .= sprintf "#define %-62s %s", "CCS_LIM_" . (uc ${this{name}} . "_MIN_$arg"), $min . ($min =~ /0x/i ? "" : "U") . "\n"; + $hdr_data .= sprintf "#define %-62s %s", "CCS_LIM_" . (uc ${this{name}} . "_MAX_$arg"), $max . ($max =~ /0x/i ? "" : "U") . "\n"; + + my $h = $this{argparams}; + + $h->{$arg} = { "min" => $min, + "max" => $max, + "elsize" => $elsize =~ /^0x/ ? hex $elsize : $elsize, + "discontig" => \@discontig }; + + $this{discontig} = $arg if @discontig; + + next if $#{$this{args}} + 1 != scalar keys %{$this{argparams}}; + + my $reg_formula = "($this{addr}"; + my $lim_formula; + + foreach my $arg (@{$this{args}}) { + my $d = $h->{$arg}->{discontig}; + my $times = $h->{$arg}->{elsize} != 1 ? + " * " . $h->{$arg}->{elsize} : ""; + + if (@$d) { + my ($lim, $offset) = split /,/, $d->[0]; + + $reg_formula .= " + (($arg) < $lim ? ($arg)$times : $offset + (($arg) - $lim)$times)"; + } else { + $reg_formula .= " + ($arg)$times"; + } + + $lim_formula .= (defined $lim_formula ? " + " : "") . "($arg)$times"; + } + + $reg_formula .= ")\n"; + $lim_formula =~ s/^\(([a-z0-9]+)\)$/$1/i; + + print $H tabconv sprintf("#define %-62s %s", "CCS_R_" . (uc $this{name}) . + $this{arglist}, $reg_formula); + + print $H tabconv $hdr_data; + undef $hdr_data; + + # Sort arguments in descending order by size + @{$this{sorted_args}} = sort { + $h->{$a}->{elsize} <= $h->{$b}->{elsize} + } @{$this{args}}; + + if (defined $this{discontig}) { + my $da = $this{argparams}->{$this{discontig}}; + my ($first_discontig) = split /,/, $da->{discontig}->[0]; + my $max = $da->{max}; + + $da->{max} = $first_discontig - 1; + print_args(\%this, "", 0); + + $da->{min} = $da->{max} + 1; + $da->{max} = $max; + print_args(\%this, $first_discontig, 1); + } else { + print_args(\%this, "", 0); + } + + next unless is_limit_reg $this{base_addr}; + + print $LH tabconv sprintf "#define %-63s%s\n", + "CCS_L_" . (uc $this{name}) . "_OFFSET(" . + (join ", ", @{$this{args}}) . ")", "($lim_formula)"; + } + + if (! @{$this{args}}) { + print $H tabconv($hdr_data); + undef $hdr_data; + } + + next; + } + + my ($name, $addr, @flags) = split /\t+/, $_; + my $args = []; + + my $sp; + + ($name, $addr, $args) = name_split($name, $addr) if /\(.*\)/; + + $name =~ s/[,\.-]/_/g; + + my $flagstring = ""; + my $size = elem_size(@flags); + $flagstring .= "| CCS_FL_16BIT " if $size eq "2"; + $flagstring .= "| CCS_FL_32BIT " if $size eq "4"; + $flagstring .= "| CCS_FL_FLOAT_IREAL " if grep /^float_ireal$/, @flags; + $flagstring .= "| CCS_FL_IREAL " if grep /^ireal$/, @flags; + $flagstring =~ s/^\| //; + $flagstring =~ s/ $//; + $flagstring = "($flagstring)" if $flagstring =~ /\|/; + my $base_addr = $addr; + $addr = "($addr | $flagstring)" if $flagstring ne ""; + + my $arglist = @$args ? "(" . (join ", ", @$args) . ")" : ""; + $hdr_data .= sprintf "#define %-62s %s\n", "CCS_R_" . (uc $name), $addr + if !@$args; + + $name =~ s/\(.*//; + + %this = ( name => $name, + addr => $addr, + base_addr => $base_addr, + argparams => {}, + args => $args, + arglist => $arglist, + elsize => $size, + ); + + if (!@$args) { + $reglist .= "\t{ CCS_R_" . (uc $name) . ", 1, 0, \"" . (lc $name) . "\", NULL },\n"; + print $H tabconv $hdr_data; + undef $hdr_data; + + print $LC tabconv sprintf "\t{ CCS_R_" . (uc $name) . ", " . + $this{elsize} . ", 0, \"$name\" },\n" + if is_limit_reg $this{base_addr}; + } + + print $LH tabconv sprintf "#define %-63s%s\n", + "CCS_L_" . (uc $this{name}), $limitcount++ + if is_limit_reg $this{base_addr}; +} + +if (defined $A) { + print $A $argdescs, $reglist; + + print $A "\t{ 0 }\n"; + + print $A "};\n"; +} + +print $H "\n#endif /* __${uc_header}__ */\n"; + +print $LH tabconv sprintf "#define %-63s%s\n", "CCS_L_LAST", $limitcount; +
drivers/media/i2c/smiapp/mk-ccs-regs line 405
Quoted 10 lines
drivers/media/i2c/smiapp/mk-ccs-regs new file +10
-0+print $LH "\n#endif /* __${uc_limith}__ */\n"; + +print $LC "\t{ 0 } /* Guardian */\n"; +print $LC "};\n"; + +close($R); +close($H); +close($A) if defined $A; +close($LC); +close($LH);
Thanks,
Mauro
Re: [PATCH v2 003/106] smiapp: Calculate CCS limit offsets and limit buffer size
In reply to Sakari AilusEm Wed, 7 Oct 2020 11:44:23 +0300
Sakari Ailus <[email protected]> escreveu:
Quoted 22 lines
Calculate the limit offsets and the size of the limit buffer. CCS limits are read into this buffer, and the offsets are helpful in accessing the information in it.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/smiapp/smiapp-core.c | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)drivers/media/i2c/smiapp/smiapp-core.c +1
-0@@ -27,6 +27,7 @@#include <media/v4l2-fwnode.h> #include <media/v4l2-device.h> +#include "ccs-limits.h" #include "smiapp.h" #define SMIAPP_ALIGN_DIM (dim, flags) \
drivers/media/i2c/smiapp/smiapp-core.c line 42
Quoted 8 lines
drivers/media/i2c/smiapp/smiapp-core.c +5
-0@@ -34,6 +35,11 @@ ? ALIGN((dim), 2) \ : (dim) & ~1) +struct ccs_limit_offset { +u16 lim; +u16 info; +} ccs_limit_offsets[CCS_L_LAST +1 ]; +
Hmm... that sounds weird.
As you're declaring the struct inside smiapp-core.c, this should be static...
Quoted 17 lines
drivers/media/i2c/smiapp/smiapp-core.c +9
-1/* * smiapp_module_idents - supported camera modules */ @@ -3166,7 +3172,39 @@ static struct i2c_driver smiapp_i2c_driver = { .id_table = smiapp_id_table, }; -module_i2c_driver (smiapp_i2c_driver); +static int smiapp_module_init (void ) +{ +unsigned int i, l; + +for (i =0 , l =0 ; ccs_limits[i].size && l <CCS_L_LAST ; i++) { +if (!(ccs_limits[i].flags &CCS_L_FL_SAME_REG )) { + ccs_limit_offsets[l +1 ].lim = + ALIGN(ccs_limit_offsets[l].lim + + ccs_limits[i].size,
drivers/media/i2c/smiapp/smiapp-core.c static struct i2c_driver smiapp_i2c_driver = { · line 3193
Quoted 10 lines
drivers/media/i2c/smiapp/smiapp-core.c +10
-0+ ccs_reg_width(ccs_limits[i + 1].reg)); + ccs_limit_offsets[l].info = i; + l++; + }else { + ccs_limit_offsets[l].lim += ccs_limits[i].size; + } + } + +if (WARN_ON (ccs_limits[i].size)) +return -EINVAL ;
... yet, this is the only place where this is used.
It sounds to me that you should move the var to be inside this function,
e. g. changing the above to:
struct ccs_limit_offset {
u16 lim;
u16 info;
};static int smiapp_module_init(void)
{
struct ccs_limit_offset ccs_limit_offsets[CCS_L_LAST + 1];
unsigned int i, l;Quoted 7 lines
drivers/media/i2c/smiapp/smiapp-core.c +7
-0+ +if (WARN_ON (l !=CCS_L_LAST )) +return -EINVAL ; + +return i2c_register_driver (THIS_MODULE , &smiapp_i2c_driver); +} +
drivers/media/i2c/smiapp/smiapp-core.c static struct i2c_driver smiapp_i2c_driver = { · line 3210
Quoted 10 lines
drivers/media/i2c/smiapp/smiapp-core.c +7
-0+static void smiapp_module_cleanup (void ) +{ +i2c_del_driver (&smiapp_i2c_driver); +} + +module_init (smiapp_module_init); +module_exit (smiapp_module_cleanup);MODULE_AUTHOR ("Sakari Ailus <[email protected]>" );MODULE_DESCRIPTION ("Generic SMIA/SMIA++ camera module driver" );
Thanks,
Mauro
Re: [PATCH v2 003/106] smiapp: Calculate CCS limit offsets and limit buffer size
Em Thu, 5 Nov 2020 08:43:38 +0100
Mauro Carvalho Chehab <[email protected]> escreveu:
Quoted 78 lines
Em Wed, 7 Oct 2020 11:44:23 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 22 lines
Calculate the limit offsets and the size of the limit buffer. CCS limits are read into this buffer, and the offsets are helpful in accessing the information in it.
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/smiapp/smiapp-core.c | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)drivers/media/i2c/smiapp/smiapp-core.c +1
-0@@ -27,6 +27,7 @@#include <media/v4l2-fwnode.h> #include <media/v4l2-device.h> +#include "ccs-limits.h" #include "smiapp.h" #define SMIAPP_ALIGN_DIM (dim, flags) \drivers/media/i2c/smiapp/smiapp-core.c line 42
Quoted 8 lines
drivers/media/i2c/smiapp/smiapp-core.c +5
-0@@ -34,6 +35,11 @@ ? ALIGN((dim), 2) \ : (dim) & ~1) +struct ccs_limit_offset { +u16 lim; +u16 info; +} ccs_limit_offsets[CCS_L_LAST +1 ]; +Hmm... that sounds weird.
As you're declaring the struct inside
smiapp-core.c, this should be static...Quoted 17 lines
drivers/media/i2c/smiapp/smiapp-core.c +9
-1/* * smiapp_module_idents - supported camera modules */ @@ -3166,7 +3172,39 @@ static struct i2c_driver smiapp_i2c_driver = { .id_table = smiapp_id_table, }; -module_i2c_driver (smiapp_i2c_driver); +static int smiapp_module_init (void ) +{ +unsigned int i, l; + +for (i =0 , l =0 ; ccs_limits[i].size && l <CCS_L_LAST ; i++) { +if (!(ccs_limits[i].flags &CCS_L_FL_SAME_REG )) { + ccs_limit_offsets[l +1 ].lim = + ALIGN(ccs_limit_offsets[l].lim + + ccs_limits[i].size,drivers/media/i2c/smiapp/smiapp-core.c static struct i2c_driver smiapp_i2c_driver = { · line 3193
Quoted 10 lines
drivers/media/i2c/smiapp/smiapp-core.c +10
-0+ ccs_reg_width(ccs_limits[i + 1].reg)); + ccs_limit_offsets[l].info = i; + l++; + }else { + ccs_limit_offsets[l].lim += ccs_limits[i].size; + } + } + +if (WARN_ON (ccs_limits[i].size)) +return -EINVAL ;... yet, this is the only place where this is used.
It sounds to me that you should move the var to be inside this function,
e. g. changing the above to:
struct ccs_limit_offset { u16 lim; u16 info; };
Quoted 4 lines
static int
smiapp_module_init(void){ struct ccs_limit_offset ccs_limit_offsets[CCS_L_LAST + 1]; unsigned int i, l;
Ok, it sounds that you start using this on patch 007/106.
So, it sounds that you should just need to add "static" to its definition.
Quoted 17 lines
Quoted 17 lines
drivers/media/i2c/smiapp/smiapp-core.c +14
-0+ +if (WARN_ON (l !=CCS_L_LAST )) +return -EINVAL ; + +return i2c_register_driver (THIS_MODULE , &smiapp_i2c_driver); +} + +static void smiapp_module_cleanup (void ) +{ +i2c_del_driver (&smiapp_i2c_driver); +} + +module_init (smiapp_module_init); +module_exit (smiapp_module_cleanup);
Quoted 7 lines
drivers/media/i2c/smiapp/smiapp-core.c static struct i2c_driver smiapp_i2c_driver = { · line 3210
Quoted 2 lines
drivers/media/i2c/smiapp/smiapp-core.c +0
-0MODULE_AUTHOR ("Sakari Ailus <[email protected]>" );MODULE_DESCRIPTION ("Generic SMIA/SMIA++ camera module driver" );Thanks,
Mauro
Thanks,
Mauro
Sakari Ailus
maintainerRe: [PATCH v2 001/106] smiapp: Generate CCS register definitions and limits
In reply to Mauro Carvalho ChehabHi Mauro,
Thank you for the review.
Quoted 23 lines · Mauro Carvalho Chehab
Hi,
Em Wed, 7 Oct 2020 11:44:21 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 11 lines
Add register definitions of the MIPI CCS 1.1 standard.
The CCS driver makes extended use of device's capability registers that are dependent on CCS version. This involves having an in-memory data structure for limit and capability information, creating that data structure and accessing it.
The register definitions as well as the definitions of this data structure are generated from a text file using a Perl script. Do the generation here and so avoid making manual, error-prone changes to the several generated files.
I understand the reason behind using a perl script to parse some text file in order to generate register's definition files, but I can't see what's the sense of storing the perl script and such texts together with the Kernel building system, re-generating them every time.
Quoted 5 lines
I mean: register definitions is something that it is supposed to be stable, and nothing something that will change on every Kernel compilation.
How often are you expecting changes at ccs-regs.txt?
When there's a new version of the standard, or a bug is found. At least. So not very often.
After pushing the set to a branch in my linuxtv.org tree, I also noticed that some architectures are built by kbuild bot without Perl interpreter being present. This suggests that Perl is not currently universally required for building the kernel albeit there seems to be some PowerPC hardware (?) related driver needing it to be built.
I was thinking of putting the files produced by the script into a new patch and leaving the script and the text file in the directory. The files would be rebuilt when a specific environment variable is set. This would in line with what crypto drivers are doing.
Signature · 3 lines
Kind regards, Sakari Ailus
Sakari Ailus
maintainerRe: [PATCH v2 003/106] smiapp: Calculate CCS limit offsets and limit buffer size
In reply to Mauro Carvalho ChehabHi Mauro,
Quoted 9 lines · Mauro Carvalho Chehab
Quoted 4 lines
static int
smiapp_module_init(void){ struct ccs_limit_offset ccs_limit_offsets[CCS_L_LAST + 1]; unsigned int i, l;Ok, it sounds that you start using this on patch 007/106.
So, it sounds that you should just need to add "static" to its definition.
Agreed, I'll add that for v3.
Signature · 1 line
Sakari Ailus
Re: [PATCH v2 001/106] smiapp: Generate CCS register definitions and limits
In reply to Sakari AilusEm Thu, 5 Nov 2020 10:01:05 +0200
Sakari Ailus <[email protected]> escreveu:
Quoted 28 lines
Hi Mauro,
Thank you for the review.
Quoted 23 lines · Mauro Carvalho Chehab
Hi,
Em Wed, 7 Oct 2020 11:44:21 +0300
Sakari Ailus <[email protected]> escreveu:Quoted 11 lines
Add register definitions of the MIPI CCS 1.1 standard.
The CCS driver makes extended use of device's capability registers that are dependent on CCS version. This involves having an in-memory data structure for limit and capability information, creating that data structure and accessing it.
The register definitions as well as the definitions of this data structure are generated from a text file using a Perl script. Do the generation here and so avoid making manual, error-prone changes to the several generated files.
I understand the reason behind using a perl script to parse some text file in order to generate register's definition files, but I can't see what's the sense of storing the perl script and such texts together with the Kernel building system, re-generating them every time.
Quoted 8 lines
Quoted 5 lines
I mean: register definitions is something that it is supposed to be stable, and nothing something that will change on every Kernel compilation.
How often are you expecting changes at ccs-regs.txt?
When there's a new version of the standard, or a bug is found. At least. So not very often.
So, it should likely take a couple of years before any changes on it.
Quoted 3 lines
After pushing the set to a branch in my linuxtv.org tree, I also noticed that some architectures are built by kbuild bot without Perl interpreter being present.
Well, kbuild bot is doing the wrong thing here: it means that it is not testing documentation - as building it requires perl ;-)
Quoted 3 lines
This suggests that Perl is not currently universally required for building the kernel albeit there seems to be some PowerPC hardware (?) related driver needing it to be built.
I doubt that Perl is a requirement for building the Kernel itself.
Adding such requirement could cause troubles on some embedded distros, like Yocto, OpenWrt, etc, whose have a distinct toolchain that needs to be compiled on some early step.
If this were something that would require dynamic changes on every single compilation, it would make sense to add such extra dependency, but this is not the case here.
Quoted 4 lines
I was thinking of putting the files produced by the script into a new patch and leaving the script and the text file in the directory. The files would be rebuilt when a specific environment variable is set. This would in line with what crypto drivers are doing.
I would, instead, place the script and instructions about how to use it inside Documentation/driver-api/media.
Thanks,
Mauro
Re: [PATCH v2 029/106] ccs: Remove the I²C ID table
In reply to Sakari AilusEm Wed, 7 Oct 2020 11:44:42 +0300
Sakari Ailus <[email protected]> escreveu:
Quoted 1 line
The I²C ID table is no longer needed; remove it.
Why not? Please provide more information.
In summary, please change the description in order to answer the following questions:
For OF-based drivers, removing I2C probing won't cause any harm, as the patch is keeping css_of_able, but wouldn't it affect other drivers that could, for example, be using ACPI, instead?
Or is this driver incompatible with other probing methods?
Quoted 24 lines
Signed-off-by Sakari Ailus <[email protected]>--- drivers/media/i2c/ccs/ccs-core.c | 7 ------- 1 file changed, 7 deletions(-)drivers/media/i2c/ccs/ccs-core.c +0
-6@@ -3244,12 +3244,6 @@ static const struct of_device_id ccs_of_table[] = { };MODULE_DEVICE_TABLE (of, ccs_of_table); -static const struct i2c_device_id ccs_id_table[] = { - {SMIAPP_NAME ,0 }, - { }, -}; -MODULE_DEVICE_TABLE (i2c, ccs_id_table); -static const struct dev_pm_ops ccs_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(ccs_suspend, ccs_resume)SET_RUNTIME_PM_OPS (ccs_power_off, ccs_power_on,NULL )
drivers/media/i2c/ccs/ccs-core.c static struct i2c_driver ccs_i2c_driver = { · line 3262
Quoted 7 lines
drivers/media/i2c/ccs/ccs-core.c +0
-1@@ -3263,7 +3257,6 @@ static struct i2c_driver ccs_i2c_driver = { }, .probe_new = ccs_probe, .remove = ccs_remove, - .id_table = ccs_id_table, };static int ccs_module_init (void )
Thanks,
Mauro