i2c-atr and FPDLink
Subsystems (6)
Tomi Valkeinen
maintainerv14 cover i2c-atr and FPDLink
Hi,
v13 can be found from:
https://lore.kernel.org/all/[email protected]/
In this version I opted to keep the main patches unchanged and make the new changes as additional patches. The reason is that the main patches have been reviewed and have been out there for quite a while, and the fixes & improvements are much clearer this way.
Tomi
Luca Ceresoli (1):
i2c: add I2C Address Translator (ATR) support
Tomi Valkeinen (17):
dt-bindings: i2c: Add I2C Address Translator (ATR)
dt-bindings: media: add TI DS90UB913 FPD-Link III Serializer
dt-bindings: media: add TI DS90UB953 FPD-Link III Serializer
dt-bindings: media: add TI DS90UB960 FPD-Link III Deserializer
media: i2c: add DS90UB960 driver
media: i2c: add DS90UB913 driver
media: i2c: add DS90UB953 driver
media: i2c: ds90ub960: Fix use of UB960_SR_FWD_CTL1
media: i2c: ds90ub9xx: Add COMMON_CLK kconfig dependency
media: i2c: ds90ub9xx: Select GPIOLIB rather than OF_GPIO
media: i2c: ds90ub960: Configure CSI-2 continuous clock
media: i2c: ds90ub953: Use v4l2_fwnode_endpoint_parse()
media: i2c: ds90ub913: Use v4l2_fwnode_endpoint_parse()
media: i2c: ds90ub953: Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK
media: i2c: ds90ub960: Allow FPD-Link async mode
media: i2c: ds90ub953: Restructure clkout management
media: i2c: ds90ub953: Support non-sync mode
.../devicetree/bindings/i2c/i2c-atr.yaml | 34 + .../bindings/media/i2c/ti,ds90ub913.yaml | 133 + .../bindings/media/i2c/ti,ds90ub953.yaml | 134 + .../bindings/media/i2c/ti,ds90ub960.yaml | 427 ++ Documentation/i2c/i2c-address-translators.rst | 96 + Documentation/i2c/index.rst | 1 + MAINTAINERS | 16 + drivers/i2c/Kconfig | 9 + drivers/i2c/Makefile | 1 + drivers/i2c/i2c-atr.c | 710 +++ drivers/media/i2c/Kconfig | 47 + drivers/media/i2c/Makefile | 3 + drivers/media/i2c/ds90ub913.c | 914 ++++ drivers/media/i2c/ds90ub953.c | 1434 ++++++ drivers/media/i2c/ds90ub960.c | 4058 +++++++++++++++++ include/linux/i2c-atr.h | 116 + include/media/i2c/ds90ub9xx.h | 22 + 17 files changed, 8155 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-atr.yaml create mode 100644 Documentation/devicetree/bindings/media/i2c/ti,ds90ub913.yaml create mode 100644 Documentation/devicetree/bindings/media/i2c/ti,ds90ub953.yaml create mode 100644 Documentation/devicetree/bindings/media/i2c/ti,ds90ub960.yaml create mode 100644 Documentation/i2c/i2c-address-translators.rst create mode 100644 drivers/i2c/i2c-atr.c create mode 100644 drivers/media/i2c/ds90ub913.c create mode 100644 drivers/media/i2c/ds90ub953.c create mode 100644 drivers/media/i2c/ds90ub960.c create mode 100644 include/linux/i2c-atr.h create mode 100644 include/media/i2c/ds90ub9xx.h
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 1/18 dt-bindings: i2c: Add I2C Address Translator (ATR)
Add bindings for I2C Address Translator. Only one property is added, 'i2c-alias-pool', which can be used in the bindings for the device that supports ATR.
--- .../devicetree/bindings/i2c/i2c-atr.yaml | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-atr.yaml
Documentation/devicetree/bindings/i2c/i2c-atr.yaml new file +34 -0
@@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/i2c-atr.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common i2c address translator properties + +maintainers: + - Tomi Valkeinen <[email protected]> + +description: + An I2C Address Translator (ATR) is a device with an I2C slave parent + ("upstream") port and N I2C master child ("downstream") ports, and + forwards transactions from upstream to the appropriate downstream port + with a modified slave address. The address used on the parent bus is + called the "alias" and is (potentially) different from the physical + slave address of the child bus. Address translation is done by the + hardware. + +properties: + i2c-alias-pool: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: + I2C alias pool is a pool of I2C addresses on the main I2C bus that can be + used to access the remote peripherals on the serializer's I2C bus. The + addresses must be available, not used by any other peripheral. Each + remote peripheral is assigned an alias from the pool, and transactions to + that address will be forwarded to the remote peripheral, with the address + translated to the remote peripheral's real address. This property is not + needed if there are no I2C addressable remote peripherals. + +additionalProperties: true +...
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 2/18 i2c: add I2C Address Translator (ATR) support
In reply to Tomi ValkeinenFrom: Luca Ceresoli <[email protected]>
An ATR is a device that looks similar to an i2c-mux: it has an I2C slave "upstream" port and N master "downstream" ports, and forwards transactions from upstream to the appropriate downstream port. But it is different in that the forwarded transaction has a different slave address. The address used on the upstream bus is called the "alias" and is (potentially) different from the physical slave address of the downstream chip.
Add a helper file (just like i2c-mux.c for a mux or switch) to allow implementing ATR features in a device driver. The helper takes care or adapter creation/destruction and translates addresses at each transaction.
--- Documentation/i2c/i2c-address-translators.rst | 96 +++ Documentation/i2c/index.rst | 1 + MAINTAINERS | 8 + drivers/i2c/Kconfig | 9 + drivers/i2c/Makefile | 1 + drivers/i2c/i2c-atr.c | 710 ++++++++++++++++++ include/linux/i2c-atr.h | 116 +++ 7 files changed, 941 insertions(+) create mode 100644 Documentation/i2c/i2c-address-translators.rst create mode 100644 drivers/i2c/i2c-atr.c create mode 100644 include/linux/i2c-atr.h
Documentation/i2c/i2c-address-translators.rst new file +96 -0
@@ -0,0 +1,96 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================= +I2C Address Translators +======================= + +Author: Luca Ceresoli <[email protected]> +Author: Tomi Valkeinen <[email protected]> + +Description +----------- + +An I2C Address Translator (ATR) is a device with an I2C slave parent +("upstream") port and N I2C master child ("downstream") ports, and +forwards transactions from upstream to the appropriate downstream port +with a modified slave address. The address used on the parent bus is +called the "alias" and is (potentially) different from the physical +slave address of the child bus. Address translation is done by the +hardware. + +An ATR looks similar to an i2c-mux except: + - the address on the parent and child busses can be different + - there is normally no need to select the child port; the alias used on the + parent bus implies it + +The ATR functionality can be provided by a chip with many other features. +The kernel i2c-atr provides a helper to implement an ATR within a driver. + +The ATR creates a new I2C "child" adapter on each child bus. Adding +devices on the child bus ends up in invoking the driver code to select +an available alias. Maintaining an appropriate pool of available aliases +and picking one for each new device is up to the driver implementer. The +ATR maintains a table of currently assigned alias and uses it to modify +all I2C transactions directed to devices on the child buses. + +A typical example follows. + +Topology:: + + Slave X @ 0x10 + .-----. | + .-----. | |---+---- B + | CPU |--A--| ATR | + `-----' | |---+---- C + `-----' | + Slave Y @ 0x10 + +Alias table: + +A, B and C are three physical I2C busses, electrically independent from +each other. The ATR receives the transactions initiated on bus A and +propagates them on bus B or bus C or none depending on the device address +in the transaction and based on the alias table. + +Alias table: + +.. table:: + + =============== ===== + Client Alias + =============== ===== + X (bus B, 0x10) 0x20 + Y (bus C, 0x10) 0x30 + =============== ===== + +Transaction: + + - Slave X driver requests a transaction (on adapter B), slave address 0x10 + - ATR driver finds slave X is on bus B and has alias 0x20, rewrites + messages with address 0x20, forwards to adapter A + - Physical I2C transaction on bus A, slave address 0x20 + - ATR chip detects transaction on address 0x20, finds it in table, + propagates transaction on bus B with address translated to 0x10, + keeps clock streched on bus A waiting for reply + - Slave X chip (on bus B) detects transaction at its own physical + address 0x10 and replies normally + - ATR chip stops clock stretching and forwards reply on bus A, + with address translated back to 0x20 + - ATR driver receives the reply, rewrites messages with address 0x10 + as they were initially + - Slave X driver gets back the msgs[], with reply and address 0x10 + +Usage: + + 1. In the driver (typically in the probe function) add an ATR by + calling i2c_atr_new() passing attach/detach callbacks + 2. When the attach callback is called pick an appropriate alias, + configure it in the chip and return the chosen alias in the + alias_id parameter + 3. When the detach callback is called, deconfigure the alias from + the chip and put the alias back in the pool for later usage + +I2C ATR functions and data structures +------------------------------------- + +.. kernel-doc:: include/linux/i2c-atr.h
Documentation/i2c/index.rst +1 -0
@@ -18,6 +18,7 @@ Introduction i2c-topology muxes/i2c-mux-gpio i2c-sysfs + i2c-address-translators Writing device drivers ======================
MAINTAINERS +8 -0
@@ -9559,6 +9559,14 @@ L: [email protected] S: Maintained F: drivers/i2c/i2c-core-acpi.c +I2C ADDRESS TRANSLATOR (ATR) +M: Tomi Valkeinen <[email protected]> +R: Luca Ceresoli <[email protected]> +L: [email protected] +S: Maintained +F: drivers/i2c/i2c-atr.c +F: include/linux/i2c-atr.h + I2C CONTROLLER DRIVER FOR NVIDIA GPU M: Ajay Gupta <[email protected]> L: [email protected]
drivers/i2c/Kconfig +9 -0
@@ -71,6 +71,15 @@ config I2C_MUX source "drivers/i2c/muxes/Kconfig" +config I2C_ATR + tristate "I2C Address Translator (ATR) support" + help + Enable support for I2C Address Translator (ATR) chips. + + An ATR allows accessing multiple I2C busses from a single + physical bus via address translation instead of bus selection as + i2c-muxes do. + config I2C_HELPER_AUTO bool "Autoselect pertinent helper modules" default y
drivers/i2c/Makefile +1 -0
@@ -13,6 +13,7 @@ i2c-core-$(CONFIG_OF) += i2c-core-of.o obj-$(CONFIG_I2C_SMBUS) += i2c-smbus.o obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o obj-$(CONFIG_I2C_MUX) += i2c-mux.o +obj-$(CONFIG_I2C_ATR) += i2c-atr.o obj-y += algos/ busses/ muxes/ obj-$(CONFIG_I2C_STUB) += i2c-stub.o obj-$(CONFIG_I2C_SLAVE_EEPROM) += i2c-slave-eeprom.o
drivers/i2c/i2c-atr.c new file +710 -0
710 lines not on this page · raw message
include/linux/i2c-atr.h new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 3/18 dt-bindings: media: add TI DS90UB913 FPD-Link III Serializer
In reply to Tomi ValkeinenAdd DT bindings for TI DS90UB913 FPD-Link III Serializer.
--- .../bindings/media/i2c/ti,ds90ub913.yaml | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ti,ds90ub913.yaml
Documentation/devicetree/bindings/media/i2c/ti,ds90ub913.yaml new file +133 -0
@@ -0,0 +1,133 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/ti,ds90ub913.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments DS90UB913 FPD-Link III Serializer + +maintainers: + - Tomi Valkeinen <[email protected]> + +description: + The TI DS90UB913 is an FPD-Link III video serializer for parallel video. + +properties: + compatible: + enum: + - ti,ds90ub913a-q1 + + '#gpio-cells': + const: 2 + description: + First cell is the GPO pin number, second cell is the flags. The GPO pin + number must be in range of [0, 3]. Note that GPOs 2 and 3 are not + available in external oscillator mode. + + gpio-controller: true + + clocks: + maxItems: 1 + description: + Reference clock connected to the CLKIN pin. + + clock-names: + items: + - const: clkin + + '#clock-cells': + const: 0 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: Parallel input port + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + required: + - pclk-sample + + port@1: + $ref: /schemas/graph.yaml#/properties/port + unevaluatedProperties: false + description: FPD-Link III output port + + required: + - port@0 + - port@1 + + i2c: + $ref: /schemas/i2c/i2c-controller.yaml# + unevaluatedProperties: false + +required: + - compatible + - '#gpio-cells' + - gpio-controller + - '#clock-cells' + - ports + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + serializer { + compatible = "ti,ds90ub913a-q1"; + + gpio-controller; + #gpio-cells = <2>; + + clocks = <&clk_cam_48M>; + clock-names = "clkin"; + + #clock-cells = <0>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + ub913_in: endpoint { + remote-endpoint = <&sensor_out>; + pclk-sample = <1>; + }; + }; + + port@1 { + reg = <1>; + endpoint { + remote-endpoint = <&deser_fpd_in>; + }; + }; + }; + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + sensor@48 { + compatible = "aptina,mt9v111"; + reg = <0x48>; + + clocks = <&fixed_clock>; + + port { + sensor_out: endpoint { + remote-endpoint = <&ub913_in>; + }; + }; + }; + }; + }; +...
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 4/18 dt-bindings: media: add TI DS90UB953 FPD-Link III Serializer
In reply to Tomi ValkeinenAdd DT bindings for TI DS90UB953 FPD-Link III Serializer.
--- .../bindings/media/i2c/ti,ds90ub953.yaml | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ti,ds90ub953.yaml
Documentation/devicetree/bindings/media/i2c/ti,ds90ub953.yaml new file +134 -0
@@ -0,0 +1,134 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/ti,ds90ub953.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments DS90UB953 FPD-Link III Serializer + +maintainers: + - Tomi Valkeinen <[email protected]> + +description: + The TI DS90UB953 is an FPD-Link III video serializer for MIPI CSI-2. + +properties: + compatible: + enum: + - ti,ds90ub953-q1 + - ti,ds90ub971-q1 + + '#gpio-cells': + const: 2 + description: + First cell is the GPIO pin number, second cell is the flags. The GPIO pin + number must be in range of [0, 3]. + + gpio-controller: true + + clocks: + maxItems: 1 + description: + Reference clock connected to the CLKIN pin. + + clock-names: + items: + - const: clkin + + '#clock-cells': + const: 0 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: CSI-2 input port + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + required: + - data-lanes + + port@1: + $ref: /schemas/graph.yaml#/properties/port + unevaluatedProperties: false + description: FPD-Link III output port + + required: + - port@0 + - port@1 + + i2c: + $ref: /schemas/i2c/i2c-controller.yaml# + unevaluatedProperties: false + +required: + - compatible + - '#gpio-cells' + - gpio-controller + - '#clock-cells' + - ports + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + serializer { + compatible = "ti,ds90ub953-q1"; + + gpio-controller; + #gpio-cells = <2>; + + #clock-cells = <0>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + ub953_in: endpoint { + clock-lanes = <0>; + data-lanes = <1 2 3 4>; + remote-endpoint = <&sensor_out>; + }; + }; + + port@1 { + reg = <1>; + endpoint { + remote-endpoint = <&deser_fpd_in>; + }; + }; + }; + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + sensor@1a { + compatible = "sony,imx274"; + reg = <0x1a>; + + reset-gpios = <&serializer 0 GPIO_ACTIVE_LOW>; + + clocks = <&serializer>; + clock-names = "inck"; + + port { + sensor_out: endpoint { + remote-endpoint = <&ub953_in>; + }; + }; + }; + }; + }; +...
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 5/18 dt-bindings: media: add TI DS90UB960 FPD-Link III Deserializer
In reply to Tomi ValkeinenAdd DT bindings for TI DS90UB960 FPD-Link III Deserializer.
--- .../bindings/media/i2c/ti,ds90ub960.yaml | 427 ++++++++++++++++++ 1 file changed, 427 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ti,ds90ub960.yaml
Documentation/devicetree/bindings/media/i2c/ti,ds90ub960.yaml new file +427 -0
@@ -0,0 +1,427 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/ti,ds90ub960.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments DS90UB9XX Family FPD-Link Deserializer Hubs + +maintainers: + - Tomi Valkeinen <[email protected]> + +description: + The TI DS90UB9XX devices are FPD-Link video deserializers with I2C and GPIO + forwarding. + +allOf: + - $ref: /schemas/i2c/i2c-atr.yaml# + +properties: + compatible: + enum: + - ti,ds90ub960-q1 + - ti,ds90ub9702-q1 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + description: + Reference clock connected to the REFCLK pin. + + clock-names: + items: + - const: refclk + + powerdown-gpios: + maxItems: 1 + description: + Specifier for the GPIO connected to the PDB pin. + + i2c-alias-pool: + minItems: 1 + maxItems: 32 + + links: + type: object + additionalProperties: false + + properties: + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + ti,manual-strobe: + type: boolean + description: + Enable manual strobe position and EQ level + + patternProperties: + '^link@[0-3]$': + type: object + additionalProperties: false + properties: + reg: + description: The link number + maxItems: 1 + + i2c-alias: + description: + The I2C address used for the serializer. Transactions to this + address on the I2C bus where the deserializer resides are + forwarded to the serializer. + + ti,rx-mode: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: + - 0 # RAW10 + - 1 # RAW12 HF + - 2 # RAW12 LF + - 3 # CSI2 SYNC + - 4 # CSI2 NON-SYNC + description: + FPD-Link Input Mode. This should reflect the hardware and the + default mode of the connected device. + + ti,cdr-mode: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: + - 0 # FPD-Link III + - 1 # FPD-Link IV + description: + FPD-Link CDR Mode. This should reflect the hardware and the + default mode of the connected device. + + ti,strobe-pos: + $ref: /schemas/types.yaml#/definitions/int32 + minimum: -13 + maximum: 13 + description: Manual strobe position + + ti,eq-level: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 14 + description: Manual EQ level + + serializer: + type: object + description: FPD-Link Serializer node + + required: + - reg + - i2c-alias + - ti,rx-mode + - serializer + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: FPD-Link input 0 + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + description: + Endpoint for FPD-Link port. If the RX mode for this port is RAW, + hsync-active and vsync-active must be defined. + + port@1: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: FPD-Link input 1 + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + description: + Endpoint for FPD-Link port. If the RX mode for this port is RAW, + hsync-active and vsync-active must be defined. + + port@2: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: FPD-Link input 2 + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + description: + Endpoint for FPD-Link port. If the RX mode for this port is RAW, + hsync-active and vsync-active must be defined. + + port@3: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: FPD-Link input 3 + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + description: + Endpoint for FPD-Link port. If the RX mode for this port is RAW, + hsync-active and vsync-active must be defined. + + port@4: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: CSI-2 Output 0 + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + properties: + data-lanes: + minItems: 1 + maxItems: 4 + link-frequencies: + maxItems: 1 + + required: + - data-lanes + - link-frequencies + + port@5: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: CSI-2 Output 1 + + properties: + endpoint: + $ref: /schemas/media/video-interfaces.yaml# + unevaluatedProperties: false + + properties: + data-lanes: + minItems: 1 + maxItems: 4 + link-frequencies: + maxItems: 1 + + required: + - data-lanes + - link-frequencies + + required: + - port@0 + - port@1 + - port@2 + - port@3 + - port@4 + - port@5 + +required: + - compatible + - reg + - clocks + - clock-names + - ports + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + + i2c { + clock-frequency = <400000>; + #address-cells = <1>; + #size-cells = <0>; + + deser@3d { + compatible = "ti,ds90ub960-q1"; + reg = <0x3d>; + + clock-names = "refclk"; + clocks = <&fixed_clock>; + + powerdown-gpios = <&pca9555 7 GPIO_ACTIVE_LOW>; + + i2c-alias-pool = <0x4a 0x4b 0x4c 0x4d 0x4e 0x4f>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* Port 0, Camera 0 */ + port@0 { + reg = <0>; + + ub960_fpd3_1_in: endpoint { + remote-endpoint = <&ub953_1_out>; + }; + }; + + /* Port 1, Camera 1 */ + port@1 { + reg = <1>; + + ub960_fpd3_2_in: endpoint { + remote-endpoint = <&ub913_2_out>; + hsync-active = <0>; + vsync-active = <1>; + }; + }; + + /* Port 2, unconnected */ + port@2 { + reg = <2>; + }; + + /* Port 3, unconnected */ + port@3 { + reg = <3>; + }; + + /* Port 4, CSI-2 TX */ + port@4 { + reg = <4>; + ds90ub960_0_csi_out: endpoint { + data-lanes = <1 2 3 4>; + link-frequencies = /bits/ 64 <800000000>; + remote-endpoint = <&csi2_phy0>; + }; + }; + + /* Port 5, unconnected */ + port@5 { + reg = <5>; + }; + }; + + links { + #address-cells = <1>; + #size-cells = <0>; + + /* Link 0 has DS90UB953 serializer and IMX274 sensor */ + + link@0 { + reg = <0>; + i2c-alias = <0x44>; + + ti,rx-mode = <3>; + + serializer1: serializer { + compatible = "ti,ds90ub953-q1"; + + gpio-controller; + #gpio-cells = <2>; + + #clock-cells = <0>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + ub953_1_in: endpoint { + data-lanes = <1 2 3 4>; + remote-endpoint = <&sensor_1_out>; + }; + }; + + port@1 { + reg = <1>; + + ub953_1_out: endpoint { + remote-endpoint = <&ub960_fpd3_1_in>; + }; + }; + }; + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + sensor@1a { + compatible = "sony,imx274"; + reg = <0x1a>; + + reset-gpios = <&serializer1 0 GPIO_ACTIVE_LOW>; + + port { + sensor_1_out: endpoint { + remote-endpoint = <&ub953_1_in>; + }; + }; + }; + }; + }; + }; /* End of link@0 */ + + /* Link 1 has DS90UB913 serializer and MT9V111 sensor */ + + link@1 { + reg = <1>; + i2c-alias = <0x45>; + + ti,rx-mode = <0>; + + serializer2: serializer { + compatible = "ti,ds90ub913a-q1"; + + gpio-controller; + #gpio-cells = <2>; + + clocks = <&clk_cam_48M>; + clock-names = "clkin"; + + #clock-cells = <0>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + ub913_2_in: endpoint { + remote-endpoint = <&sensor_2_out>; + pclk-sample = <1>; + }; + }; + + port@1 { + reg = <1>; + + ub913_2_out: endpoint { + remote-endpoint = <&ub960_fpd3_2_in>; + }; + }; + }; + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + sensor@48 { + compatible = "aptina,mt9v111"; + reg = <0x48>; + + clocks = <&serializer2>; + + port { + sensor_2_out: endpoint { + remote-endpoint = <&ub913_2_in>; + }; + }; + }; + }; + }; + }; /* End of link@1 */ + }; + }; + }; +...
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 6/18 media: i2c: add DS90UB960 driver
In reply to Tomi ValkeinenAdd driver for TI DS90UB960 FPD-Link III Deserializer.
--- MAINTAINERS | 8 + drivers/media/i2c/Kconfig | 21 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ds90ub960.c | 4049 +++++++++++++++++++++++++++++++++ include/media/i2c/ds90ub9xx.h | 22 + 5 files changed, 4101 insertions(+) create mode 100644 drivers/media/i2c/ds90ub960.c create mode 100644 include/media/i2c/ds90ub9xx.h
MAINTAINERS +8 -0
@@ -20929,6 +20929,14 @@ F: drivers/misc/tifm* F: drivers/mmc/host/tifm_sd.c F: include/linux/tifm.h +TI FPD-LINK DRIVERS +M: Tomi Valkeinen <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/media/i2c/ti,ds90* +F: drivers/media/i2c/ds90* +F: include/media/i2c/ds90* + TI KEYSTONE MULTICORE NAVIGATOR DRIVERS M: Nishanth Menon <[email protected]> M: Santosh Shilimkar <[email protected]>
drivers/media/i2c/Kconfig +21 -0
@@ -1611,4 +1611,25 @@ config VIDEO_THS7303 endmenu +# +# Video serializers and deserializers (e.g. FPD-Link) +# + +menu "Video serializers and deserializers" + +config VIDEO_DS90UB960 + tristate "TI FPD-Link III/IV Deserializers" + depends on OF && I2C && VIDEO_DEV + select I2C_ATR + select MEDIA_CONTROLLER + select OF_GPIO + select REGMAP_I2C + select V4L2_FWNODE + select VIDEO_V4L2_SUBDEV_API + help + Device driver for the Texas Instruments DS90UB960 + FPD-Link III Deserializer and DS90UB9702 FPD-Link IV Deserializer. + +endmenu + endif # VIDEO_DEV
drivers/media/i2c/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_VIDEO_CS3308) += cs3308.o obj-$(CONFIG_VIDEO_CS5345) += cs5345.o obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o obj-$(CONFIG_VIDEO_CX25840) += cx25840/ +obj-$(CONFIG_VIDEO_DS90UB960) += ds90ub960.o obj-$(CONFIG_VIDEO_DW9714) += dw9714.o obj-$(CONFIG_VIDEO_DW9768) += dw9768.o obj-$(CONFIG_VIDEO_DW9807_VCM) += dw9807-vcm.o
drivers/media/i2c/ds90ub960.c new file +4049 -0
2,954 lines not on this page · raw message
include/media/i2c/ds90ub9xx.h new file +22 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Tomi Valkeinen
maintainerPATCH v14 7/18 media: i2c: add DS90UB913 driver
In reply to Tomi ValkeinenAdd driver for TI DS90UB913 FPD-Link III Serializer.
--- drivers/media/i2c/Kconfig | 13 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ds90ub913.c | 906 ++++++++++++++++++++++++++++++++++ 3 files changed, 920 insertions(+) create mode 100644 drivers/media/i2c/ds90ub913.c
drivers/media/i2c/Kconfig +13 -0
@@ -1617,6 +1617,19 @@ endmenu menu "Video serializers and deserializers" +config VIDEO_DS90UB913 + tristate "TI DS90UB913 FPD-Link III Serializer" + depends on OF && I2C && VIDEO_DEV + select I2C_ATR + select MEDIA_CONTROLLER + select OF_GPIO + select REGMAP_I2C + select V4L2_FWNODE + select VIDEO_V4L2_SUBDEV_API + help + Device driver for the Texas Instruments DS90UB913 + FPD-Link III Serializer. + config VIDEO_DS90UB960 tristate "TI FPD-Link III/IV Deserializers" depends on OF && I2C && VIDEO_DEV
drivers/media/i2c/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_VIDEO_CS3308) += cs3308.o obj-$(CONFIG_VIDEO_CS5345) += cs5345.o obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o obj-$(CONFIG_VIDEO_CX25840) += cx25840/ +obj-$(CONFIG_VIDEO_DS90UB913) += ds90ub913.o obj-$(CONFIG_VIDEO_DS90UB960) += ds90ub960.o obj-$(CONFIG_VIDEO_DW9714) += dw9714.o obj-$(CONFIG_VIDEO_DW9768) += dw9768.o
drivers/media/i2c/ds90ub913.c new file +906 -0
906 lines not on this page · raw message
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 8/18 media: i2c: add DS90UB953 driver
In reply to Tomi ValkeinenAdd driver for TI DS90UB953 FPD-Link III Serializer.
--- drivers/media/i2c/Kconfig | 13 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/ds90ub953.c | 1400 +++++++++++++++++++++++++++++++++ 3 files changed, 1414 insertions(+) create mode 100644 drivers/media/i2c/ds90ub953.c
drivers/media/i2c/Kconfig +13 -0
@@ -1630,6 +1630,19 @@ config VIDEO_DS90UB913 Device driver for the Texas Instruments DS90UB913 FPD-Link III Serializer. +config VIDEO_DS90UB953 + tristate "TI FPD-Link III/IV CSI-2 Serializers" + depends on OF && I2C && VIDEO_DEV + select I2C_ATR + select MEDIA_CONTROLLER + select OF_GPIO + select REGMAP_I2C + select V4L2_FWNODE + select VIDEO_V4L2_SUBDEV_API + help + Device driver for the Texas Instruments DS90UB953 + FPD-Link III Serializer and DS90UB971 FPD-Link IV Serializer. + config VIDEO_DS90UB960 tristate "TI FPD-Link III/IV Deserializers" depends on OF && I2C && VIDEO_DEV
drivers/media/i2c/Makefile +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_VIDEO_CS5345) += cs5345.o obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o obj-$(CONFIG_VIDEO_CX25840) += cx25840/ obj-$(CONFIG_VIDEO_DS90UB913) += ds90ub913.o +obj-$(CONFIG_VIDEO_DS90UB953) += ds90ub953.o obj-$(CONFIG_VIDEO_DS90UB960) += ds90ub960.o obj-$(CONFIG_VIDEO_DW9714) += dw9714.o obj-$(CONFIG_VIDEO_DW9768) += dw9768.o
drivers/media/i2c/ds90ub953.c new file +1400 -0
1,400 lines not on this page · raw message
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 9/18 media: i2c: ds90ub960: Fix use of UB960_SR_FWD_CTL1
In reply to Tomi ValkeinenThe driver does not update the forwarding bits in the UB960_SR_FWD_CTL1 register for ports that won't be used. This might leave port forwardings enabled for unused ports, which might cause issues.
Fix this by making sure all the port forwardings are disabled by default, and only enable the ones that are used.
--- drivers/media/i2c/ds90ub960.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/media/i2c/ds90ub960.c +10 -8
@@ -2330,7 +2330,8 @@ static int ub960_enable_rx_port(struct ub960_data *priv, unsigned int nport)dev_dbg (dev,"enable RX port %u\n" , nport);/* Enable forwarding */ -return ub960_update_bits (priv,UB960_SR_FWD_CTL1 ,BIT (4 + nport),0 ); +return ub960_update_bits (priv,UB960_SR_FWD_CTL1 , +UB960_SR_FWD_CTL1_PORT_DIS (nport),0 ); }static void ub960_disable_rx_port (struct ub960_data *priv,unsigned int nport)
@@ -2340,8 +2341,9 @@ static void ub960_disable_rx_port(struct ub960_data *priv, unsigned int nport)dev_dbg (dev,"disable RX port %u\n" , nport);/* Disable forwarding */ -ub960_update_bits (priv,UB960_SR_FWD_CTL1 ,BIT (4 + nport), -BIT (4 + nport)); +ub960_update_bits (priv,UB960_SR_FWD_CTL1 , +UB960_SR_FWD_CTL1_PORT_DIS (nport), +UB960_SR_FWD_CTL1_PORT_DIS (nport)); }/*
@@ -2467,7 +2469,11 @@ static int ub960_configure_ports_for_streaming(struct ub960_data *priv,/* Configure RX ports */ - fwd_ctl =0 ; +/* +* Keep all port forwardings disabled by default. Forwarding will be +* enabled in ub960_enable_rx_port. +*/ + fwd_ctl =GENMASK (7 ,4 );for (nport =0 ; nport < priv->hw_data->num_rxports; nport++) {struct ub960_rxport *rxport = priv->rxports[nport];
@@ -2515,10 +2521,6 @@ static int ub960_configure_ports_for_streaming(struct ub960_data *priv,break ; } -/* Forwarding */ - - fwd_ctl |=BIT (4 + nport);/* forward disable */ -if (rx_data[nport].tx_port ==1 ) fwd_ctl |=BIT (nport);/* forward to TX1 */ else
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 10/18 media: i2c: ds90ub9xx: Add COMMON_CLK kconfig dependency
In reply to Tomi ValkeinenFix missing COMMON_CLK dependency:
ERROR: modpost: "__clk_get_name" [drivers/media/i2c/ds90ub913.ko] undefined!
ERROR: modpost: "devm_clk_hw_register_fixed_factor" [drivers/media/i2c/ds90ub913.ko] undefined!
ERROR: modpost: "of_clk_hw_simple_get" [drivers/media/i2c/ds90ub913.ko] undefined!
ERROR: modpost: "devm_of_clk_add_hw_provider" [drivers/media/i2c/ds90ub913.ko] undefined!
--- drivers/media/i2c/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/i2c/Kconfig +3 -3
@@ -1619,7 +1619,7 @@ menu "Video serializers and deserializers" config VIDEO_DS90UB913 tristate "TI DS90UB913 FPD-Link III Serializer" - depends on OF && I2C && VIDEO_DEV + depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER select OF_GPIO
@@ -1632,7 +1632,7 @@ config VIDEO_DS90UB913 config VIDEO_DS90UB953 tristate "TI FPD-Link III/IV CSI-2 Serializers" - depends on OF && I2C && VIDEO_DEV + depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER select OF_GPIO
@@ -1645,7 +1645,7 @@ config VIDEO_DS90UB953 config VIDEO_DS90UB960 tristate "TI FPD-Link III/IV Deserializers" - depends on OF && I2C && VIDEO_DEV + depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER select OF_GPIO
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 11/18 media: i2c: ds90ub9xx: Select GPIOLIB rather than OF_GPIO
In reply to Tomi ValkeinenSelect GPIOLIB rather than OF_GPIO, as the drivers use gpiolib functionality, but no of_gpio (directly).
--- drivers/media/i2c/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/i2c/Kconfig +3 -3
@@ -1622,7 +1622,7 @@ config VIDEO_DS90UB913 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_API
@@ -1635,7 +1635,7 @@ config VIDEO_DS90UB953 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_API
@@ -1648,7 +1648,7 @@ config VIDEO_DS90UB960 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_API
Signature · 1 line
2.34.1
Re: [PATCH v14 11/18] media: i2c: ds90ub9xx: Select GPIOLIB rather than OF_GPIO
Quoted 2 lines · Tomi Valkeinen
Select GPIOLIB rather than
OF_GPIO, as the drivers use gpiolib functionality, but noof_gpio(directly).
This is useful change, but has to be folded in the original code. We do not want even a trace of newly added OF_GPIO.
Quoted 39 lines
Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/media/i2c/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/media/i2c/Kconfig +3
-3@@ -1622,7 +1622,7 @@ config VIDEO_DS90UB913 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_API@@ -1635,7 +1635,7 @@ config VIDEO_DS90UB953 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_API@@ -1648,7 +1648,7 @@ config VIDEO_DS90UB960 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_APISignature · 1 line
2.34.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerRe: [PATCH v14 11/18] media: i2c: ds90ub9xx: Select GPIOLIB rather than OF_GPIO
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Tomi Valkeinen
Select GPIOLIB rather than
OF_GPIO, as the drivers use gpiolib functionality, but noof_gpio(directly).This is useful change, but has to be folded in the original code. We do not want even a trace of newly added
OF_GPIO.
Yes, I think the first three new patches should be squashed:
media: i2c: ds90ub960: Fix use of UB960_SR_FWD_CTL1
media: i2c: ds90ub9xx: Add COMMON_CLK kconfig dependency
media: i2c: ds90ub9xx: Select GPIOLIB rather than OF_GPIO
The rest... Thinking about it now, I should have perhaps left them out, as they're not fixing issues, and perhaps they just confuse the merging process.
Tomi
Quoted 42 lines
Reviewed-by Andy Shevchenko <[email protected]>Quoted 39 lines
Signed-off-by Tomi Valkeinen <[email protected]>--- drivers/media/i2c/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/media/i2c/Kconfig +3
-3@@ -1622,7 +1622,7 @@ config VIDEO_DS90UB913 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_API@@ -1635,7 +1635,7 @@ config VIDEO_DS90UB953 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_API@@ -1648,7 +1648,7 @@ config VIDEO_DS90UB960 depends on OF && I2C && VIDEO_DEV && COMMON_CLK select I2C_ATR select MEDIA_CONTROLLER - select OF_GPIO + select GPIOLIB select REGMAP_I2C select V4L2_FWNODE select VIDEO_V4L2_SUBDEV_APISignature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 12/18 media: i2c: ds90ub960: Configure CSI-2 continuous clock
In reply to Tomi ValkeinenUse 'clock-noncontinuous' from DT to configure the continuous/non-continuous clock setting for the TX ports.
--- drivers/media/i2c/ds90ub960.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/i2c/ds90ub960.c +8 -0
@@ -149,6 +149,7 @@#define UB960_TR_CSI_CTL 0x33#define UB960_TR_CSI_CTL_CSI_CAL_EN BIT(6) +#define UB960_TR_CSI_CTL_CSI_CONTS_CLOCK BIT(1)#define UB960_TR_CSI_CTL_CSI_ENABLE BIT(0)#define UB960_TR_CSI_CTL2 0x34
@@ -485,6 +486,7 @@ struct ub960_txport {u8 nport;/* TX port number, and index in priv->txport[] */ u32 num_data_lanes; +bool non_continous_clk; };struct ub960_data {
@@ -1133,6 +1135,9 @@ static int ub960_parse_dt_txport(struct ub960_data *priv, goto err_free_txport; } + txport->non_continous_clk = vep.bus.mipi_csi2.flags & +V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK ; + txport->num_data_lanes = vep.bus.mipi_csi2.num_data_lanes;if (vep.nr_of_link_frequencies !=1 ) {
@@ -1744,6 +1749,9 @@ static void ub960_init_tx_port(struct ub960_data *priv, csi_ctl |= (4 - txport->num_data_lanes) <<4 ; +if (!txport->non_continous_clk) + csi_ctl |=UB960_TR_CSI_CTL_CSI_CONTS_CLOCK ; +ub960_txport_write (priv, nport,UB960_TR_CSI_CTL , csi_ctl); }
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 13/18 media: i2c: ds90ub953: Use v4l2_fwnode_endpoint_parse()
In reply to Tomi ValkeinenUse v4l2_fwnode_endpoint_parse() to parse the sink endpoint parameters.
--- drivers/media/i2c/ds90ub953.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/media/i2c/ds90ub953.c +13 -6
@@ -25,6 +25,8 @@#include <media/i2c/ds90ub9xx.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-event.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-mediabus.h> #include <media/v4l2-subdev.h> #define UB953_PAD_SINK 0
@@ -1111,7 +1113,9 @@ static const struct regmap_config ub953_regmap_config = {static int ub953_parse_dt (struct ub953_data *priv) {struct device *dev = &priv->client->dev; +struct v4l2_fwnode_endpoint vep = {};struct fwnode_handle *ep_fwnode; +unsigned char nlanes;int ret; ep_fwnode = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev),
@@ -1119,19 +1123,22 @@ static int ub953_parse_dt(struct ub953_data *priv)if (!ep_fwnode)return dev_err_probe (dev, -ENOENT ,"no endpoint found\n" ); - ret =fwnode_property_count_u32 (ep_fwnode,"data-lanes" ); + vep.bus_type =V4L2_MBUS_CSI2_DPHY ; + ret =v4l2_fwnode_endpoint_parse (ep_fwnode, &vep);fwnode_handle_put (ep_fwnode); -if (ret <0 ) +if (ret)return dev_err_probe (dev, ret, -"failed to parse property 'data-lanes'\n" ); +"failed to parse sink endpoint data\n" ); + + nlanes = vep.bus.mipi_csi2.num_data_lanes; -if (ret !=1 && ret !=2 && ret !=4 ) +if (nlanes !=1 && nlanes !=2 && nlanes !=4 )return dev_err_probe (dev, -EINVAL , -"bad number of data-lanes: %d\n" , ret); +"bad number of data-lanes: %d\n" , nlanes); - priv->num_data_lanes = ret; + priv->num_data_lanes = nlanes;return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH v14 13/18] media: i2c: ds90ub953: Use v4l2_fwnode_endpoint_parse()
drivers/media/i2c/ds90ub953.c static int ub953_parse_dt(struct ub953_data *priv) · line 1135
Quoted 4 lines · Tomi Valkeinen
Use
v4l2_fwnode_endpoint_parse()to parse the sink endpoint parameters.drivers/media/i2c/ds90ub953.c +1
-0+ nlanes = vep.bus.mipi_csi2.num_data_lanes;
I would also drop this blank line now.
drivers/media/i2c/ds90ub953.c static int ub953_parse_dt(struct ub953_data *priv) · line 1137
Quoted 2 lines
drivers/media/i2c/ds90ub953.c +1
-1-if (ret !=1 && ret !=2 && ret !=4 ) +if (nlanes !=1 && nlanes !=2 && nlanes !=4 )
Isn't the following cleaner?
if (!is_power_of_2(nlanes) || nlanes > 4)
Quoted 3 lines
drivers/media/i2c/ds90ub953.c +1
-1return dev_err_probe (dev, -EINVAL , -"bad number of data-lanes: %d\n" , ret); +"bad number of data-lanes: %d\n" , nlanes);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerRe: [PATCH v14 13/18] media: i2c: ds90ub953: Use v4l2_fwnode_endpoint_parse()
Quoted 7 lines · Andy Shevchenko
drivers/media/i2c/ds90ub953.c static int ub953_parse_dt(struct ub953_data *priv) · line 1135
Quoted 4 lines · Tomi Valkeinen
Use
v4l2_fwnode_endpoint_parse()to parse the sink endpoint parameters.drivers/media/i2c/ds90ub953.c +1
-0+ nlanes = vep.bus.mipi_csi2.num_data_lanes;I would also drop this blank line now.
Ok.
Quoted 6 lines
drivers/media/i2c/ds90ub953.c static int ub953_parse_dt(struct ub953_data *priv) · line 1137
Quoted 2 lines
drivers/media/i2c/ds90ub953.c +1
-1-if (ret !=1 && ret !=2 && ret !=4 ) +if (nlanes !=1 && nlanes !=2 && nlanes !=4 )Isn't the following cleaner?
if (!is_power_of_2(nlanes) || nlanes > 4)
No, I don't think so... The current one is more human-readable.
Quoted 4 lines
drivers/media/i2c/ds90ub953.c static int ub953_parse_dt(struct ub953_data *priv) · line 1139
Quoted 3 lines
return dev_err_probe(dev,
-EINVAL,drivers/media/i2c/ds90ub953.c +1
-1- "bad number of data-lanes: %d\n", ret); + "bad number of data-lanes: %d\n", nlanes);
Tomi
Tomi Valkeinen
maintainerPATCH v14 14/18 media: i2c: ds90ub913: Use v4l2_fwnode_endpoint_parse()
In reply to Tomi ValkeinenUse v4l2_fwnode_endpoint_parse() to parse the sink endpoint parameters.
--- drivers/media/i2c/ds90ub913.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/media/i2c/ds90ub913.c +20 -12
@@ -21,6 +21,8 @@#include <linux/regmap.h> #include <media/i2c/ds90ub9xx.h> +#include <media/v4l2-fwnode.h> +#include <media/v4l2-mediabus.h> #include <media/v4l2-subdev.h> #define UB913_PAD_SINK 0
@@ -83,7 +85,7 @@ struct ub913_data {struct ds90ub9xx_platform_data *plat_data; -u32 pclk_polarity; +u32 pclk_polarity_rising; };static inline struct ub913_data *sd_to_ub913 (struct v4l2_subdev *sd)
@@ -675,25 +677,31 @@ static int ub913_add_i2c_adapter(struct ub913_data *priv)static int ub913_parse_dt (struct ub913_data *priv) {struct device *dev = &priv->client->dev; +struct v4l2_fwnode_endpoint vep = {};struct fwnode_handle *ep_fwnode;int ret; ep_fwnode =fwnode_graph_get_endpoint_by_id (dev_fwnode (dev),UB913_PAD_SINK ,0 ,0 ); -if (!ep_fwnode) { -dev_err_probe (dev, -ENOENT ,"No sink endpoint\n" ); -return -ENOENT ; - } +if (!ep_fwnode) +return dev_err_probe (dev, -ENOENT ,"No sink endpoint\n" ); - ret =fwnode_property_read_u32 (ep_fwnode,"pclk-sample" , - &priv->pclk_polarity); + vep.bus_type =V4L2_MBUS_PARALLEL ; + ret =v4l2_fwnode_endpoint_parse (ep_fwnode, &vep);fwnode_handle_put (ep_fwnode); -if (ret) { -dev_err_probe (dev, ret,"failed to parse 'pclk-sample'\n" ); -return ret; - } +if (ret) +return dev_err_probe (dev, ret, +"failed to parse sink endpoint data\n" ); + +if (vep.bus.parallel.flags &V4L2_MBUS_PCLK_SAMPLE_RISING ) + priv->pclk_polarity_rising = true; +else if (vep.bus.parallel.flags &V4L2_MBUS_PCLK_SAMPLE_FALLING ) + priv->pclk_polarity_rising = false; +else +return dev_err_probe (dev, -EINVAL , +"bad value for 'pclk-sample'\n" );return 0 ; }
@@ -726,7 +734,7 @@ static int ub913_hw_init(struct ub913_data *priv)ub913_read (priv,UB913_REG_GENERAL_CFG , &v); v &= ~UB913_REG_GENERAL_CFG_PCLK_RISING ; - v |= priv->pclk_polarity ?UB913_REG_GENERAL_CFG_PCLK_RISING :0 ; + v |= priv->pclk_polarity_rising ?UB913_REG_GENERAL_CFG_PCLK_RISING :0 ;ub913_write (priv,UB913_REG_GENERAL_CFG , v);return 0 ;
Signature · 1 line
2.34.1
Tomi Valkeinen
maintainerPATCH v14 15/18 media: i2c: ds90ub953: Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK
In reply to Tomi ValkeinenHandle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK flag to configure the CSI-2 RX continuous/non-continuous clock register.
--- drivers/media/i2c/ds90ub953.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/i2c/ds90ub953.c +5 -1
@@ -138,6 +138,7 @@ struct ub953_data {struct regmap *regmap;u32 num_data_lanes; +bool non_cont_clk;struct gpio_chip gpio_chip;
@@ -1140,6 +1141,9 @@ static int ub953_parse_dt(struct ub953_data *priv) priv->num_data_lanes = nlanes; + priv->non_cont_clk = vep.bus.mipi_csi2.flags & +V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK ; +return 0 ; }
@@ -1202,7 +1206,7 @@ static int ub953_hw_init(struct ub953_data *priv)return dev_err_probe (dev, ret,"i2c init failed\n" );ub953_write (priv,UB953_REG_GENERAL_CFG , -UB953_REG_GENERAL_CFG_CONT_CLK | + (priv->non_cont_clk ?0 :UB953_REG_GENERAL_CFG_CONT_CLK ) | ((priv->num_data_lanes -1 ) <<UB953_REG_GENERAL_CFG_CSI_LANE_SEL_SHIFT ) |UB953_REG_GENERAL_CFG_CRC_TX_GEN_ENABLE );
Signature · 1 line
2.34.1
Re: [PATCH v14 15/18] media: i2c: ds90ub953: Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK
Quoted 2 lines · Tomi Valkeinen
Handle
V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCKflag to configure the CSI-2 RX continuous/non-continuous clock register.
...
Quoted 1 line
struct regmap *regmap;
I forgot if we discussed this along with i2c_client *client nearby. Since I reviewed Hans' patches the pure struct device *dev (instead of *client) might make more sense, despite being duplicative with regmap associated device.
drivers/media/i2c/ds90ub953.c struct ub953_data { · line 143
Quoted 4 lines
drivers/media/i2c/ds90ub953.c +1
-0u32 num_data_lanes; +bool non_cont_clk;struct gpio_chip gpio_chip;
And also try to place this as a first member and see (by using bloat-o-meter, for example) if it saves bytes.
I'm wondering if we have tools like pahole but which suggests the better layout based on the code generation... Maybe something along with clang?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerRe: [PATCH v14 15/18] media: i2c: ds90ub953: Handle V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK
Quoted 15 lines · Andy Shevchenko
Quoted 2 lines · Tomi Valkeinen
Handle
V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCKflag to configure the CSI-2 RX continuous/non-continuous clock register....
Quoted 1 line
struct regmap *regmap;
I forgot if we discussed this along with
i2c_client*client nearby. Since I reviewed Hans' patches the pure struct device *dev (instead of *client) might make more sense, despite being duplicative with regmap associated device.Quoted 3 lines
u32
num_data_lanes;drivers/media/i2c/ds90ub953.c +1
-0+bool non_cont_clk;
Quoted 7 lines
Quoted 1 line
struct
gpio_chipgpio_chip;And also try to place this as a first member and see (by using bloat-o-meter, for example) if it saves bytes.
I'm wondering if we have tools like pahole but which suggests the better layout based on the code generation... Maybe something along with clang?
Isn't all this a bit on the side of pointless micro-optimizations? We're talking about possibly saving a few tens of bytes in a struct that's likely allocated a few times, by possibly messing up the (cosmetic) grouping and ordering of the fields in the struct?
If there's a common rule-of-thumb wrt. struct members that everyone should follow, I'm good with that and can change this accordingly. But just trying to hunt for a field order that happens to save a few bytes here... It doesn't sound like time well spent.
If things were perfect, this would be something the compiler would optimize, presuming the field ordering in the struct doesn't matter.
Tomi
Tomi Valkeinen
maintainerPATCH v14 16/18 media: i2c: ds90ub960: Allow FPD-Link async mode
In reply to Tomi ValkeinenAllow using FPD-Link in async mode. The driver handles it correctly, but the mode was blocked at probe time as there wasn't HW to test this with. Now the mode has been tested, and it works.
--- drivers/media/i2c/ds90ub960.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/i2c/ds90ub960.c +0 -1
@@ -3240,7 +3240,6 @@ ub960_parse_dt_rxport_link_properties(struct ub960_data *priv,switch (rx_mode) {case RXPORT_MODE_RAW12_HF :case RXPORT_MODE_RAW12_LF : -case RXPORT_MODE_CSI2_ASYNC :dev_err (dev,"rx%u: unsupported 'ti,rx-mode' %u\n" , nport, rx_mode);return -EINVAL ;
Signature · 1 line
2.34.1
Re: [PATCH v14 16/18] media: i2c: ds90ub960: Allow FPD-Link async mode
Quoted 3 lines · Tomi Valkeinen
Allow using FPD-Link in async mode. The driver handles it correctly, but the mode was blocked at probe time as there wasn't HW to test this with. Now the mode has been tested, and it works.
Looks good, but I assume you will incorporate this into the original code.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerRe: [PATCH v14 16/18] media: i2c: ds90ub960: Allow FPD-Link async mode
Quoted 6 lines · Andy Shevchenko
Quoted 3 lines · Tomi Valkeinen
Allow using FPD-Link in async mode. The driver handles it correctly, but the mode was blocked at probe time as there wasn't HW to test this with. Now the mode has been tested, and it works.
Looks good, but I assume you will incorporate this into the original code.
Perhaps, but to be honest, I just want to get the basic set merged, as it's been circulating for so many years. So, as I mentioned in the earlier email, it was perhaps a mistake to include these additional changes...
If the reviews for the new commits are quick and easy, I can squash them and send a v15. But if there's anything that needs more discussions, I'd like to leave the rest for later.
Tomi
Tomi Valkeinen
maintainerPATCH v14 17/18 media: i2c: ds90ub953: Restructure clkout management
In reply to Tomi ValkeinenSeparate clkout calculations and register writes into two functions:ub953_calc_clkout_params and ub953_write_clkout_regs, and add a struct ub953_clkout_data that is used to store the clkout parameters.
This simplifies the clkout management.
--- drivers/media/i2c/ds90ub953.c | 135 ++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 65 deletions(-)
drivers/media/i2c/ds90ub953.c +70 -65
@@ -131,6 +131,13 @@ struct ub953_hw_data {bool is_ub971; }; +struct ub953_clkout_data { +u32 hs_div; +u32 m; +u32 n; +unsigned long rate; +}; +struct ub953_data {const struct ub953_hw_data *hw_data;
@@ -906,6 +913,58 @@ static unsigned long ub953_calc_clkout_ub971(struct ub953_data *priv,return res; } +static void ub953_calc_clkout_params (struct ub953_data *priv, +unsigned long target_rate, +struct ub953_clkout_data *clkout_data) +{ +struct device *dev = &priv->client->dev; +unsigned long clkout_rate; +u64 fc_rate; + + fc_rate =ub953_get_fc_rate (priv); + +if (priv->hw_data->is_ub971) { +u8 m, n; + + clkout_rate =ub953_calc_clkout_ub971 (priv, target_rate, + fc_rate, &m, &n); + + clkout_data->m = m; + clkout_data->n = n; + +dev_dbg (dev,"%s %llu * %u / (8 * %u) = %lu (requested %lu)" , + __func__, fc_rate, m, n, clkout_rate, target_rate); + }else { +u8 hs_div, m, n; + + clkout_rate =ub953_calc_clkout_ub953 (priv, target_rate, + fc_rate, &hs_div, &m, &n); + + clkout_data->hs_div = hs_div; + clkout_data->m = m; + clkout_data->n = n; + +dev_dbg (dev,"%s %llu / %u * %u / %u = %lu (requested %lu)" , + __func__, fc_rate, hs_div, m, n, clkout_rate, + target_rate); + } + + clkout_data->rate = clkout_rate; +} + +static void ub953_write_clkout_regs (struct ub953_data *priv, +struct ub953_clkout_data *clkout_data) +{ +if (priv->hw_data->is_ub971) { +ub953_write (priv,UB953_REG_CLKOUT_CTRL0 , clkout_data->m); +ub953_write (priv,UB953_REG_CLKOUT_CTRL1 , clkout_data->n); + }else { +ub953_write (priv,UB953_REG_CLKOUT_CTRL0 , + (__ffs (clkout_data->hs_div) <<5 ) | clkout_data->m); +ub953_write (priv,UB953_REG_CLKOUT_CTRL1 , clkout_data->n); + } +} +static unsigned long ub953_clkout_recalc_rate (struct clk_hw *hw,unsigned long parent_rate) {
@@ -965,52 +1024,25 @@ static long ub953_clkout_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { struct ub953_data *priv = container_of(hw, struct ub953_data, clkout_clk_hw); -struct device *dev = &priv->client->dev; -unsigned long res; -u64 fc_rate; -u8 hs_div, m, n; - - fc_rate =ub953_get_fc_rate (priv); +struct ub953_clkout_data clkout_data; -if (priv->hw_data->is_ub971) { - res =ub953_calc_clkout_ub971 (priv, rate, fc_rate, &m, &n); +ub953_calc_clkout_params (priv, rate, &clkout_data); -dev_dbg (dev,"%s %llu * %u / (8 * %u) = %lu (requested %lu)" , - __func__, fc_rate, m, n, res, rate); - }else { - res =ub953_calc_clkout_ub953 (priv, rate, fc_rate, &hs_div, &m, &n); - -dev_dbg (dev,"%s %llu / %u * %u / %u = %lu (requested %lu)" , - __func__, fc_rate, hs_div, m, n, res, rate); - } - -return res; +return clkout_data.rate; }static int ub953_clkout_set_rate (struct clk_hw *hw,unsigned long rate,unsigned long parent_rate) { struct ub953_data *priv = container_of(hw, struct ub953_data, clkout_clk_hw); -u64 fc_rate; -u8 hs_div, m, n; -unsigned long res; +struct ub953_clkout_data clkout_data; - fc_rate =ub953_get_fc_rate (priv); - -if (priv->hw_data->is_ub971) { - res =ub953_calc_clkout_ub971 (priv, rate, fc_rate, &m, &n); - -ub953_write (priv,UB953_REG_CLKOUT_CTRL0 , m); -ub953_write (priv,UB953_REG_CLKOUT_CTRL1 , n); - }else { - res =ub953_calc_clkout_ub953 (priv, rate, fc_rate, &hs_div, &m, &n); +ub953_calc_clkout_params (priv, rate, &clkout_data); -ub953_write (priv,UB953_REG_CLKOUT_CTRL0 , (__ffs (hs_div) <<5 ) | m); -ub953_write (priv,UB953_REG_CLKOUT_CTRL1 , n); - } +dev_dbg (&priv->client->dev,"%s %lu (requested %lu)\n" , __func__, + clkout_data.rate, rate); -dev_dbg (&priv->client->dev,"%s %lu (requested %lu)\n" , __func__, res, - rate); +ub953_write_clkout_regs (priv, &clkout_data);return 0 ; }
@@ -1021,32 +1053,6 @@ static const struct clk_ops ub953_clkout_ops = { .set_rate = ub953_clkout_set_rate, }; -static void ub953_init_clkout_ub953 (struct ub953_data *priv) -{ -u64 fc_rate; -u8 hs_div, m, n; - - fc_rate =ub953_get_fc_rate (priv); - -ub953_calc_clkout_ub953 (priv,25000000 , fc_rate, &hs_div, &m, &n); - -ub953_write (priv,UB953_REG_CLKOUT_CTRL0 , (__ffs (hs_div) <<5 ) | m); -ub953_write (priv,UB953_REG_CLKOUT_CTRL1 , n); -} - -static void ub953_init_clkout_ub971 (struct ub953_data *priv) -{ -u64 fc_rate; -u8 m, n; - - fc_rate =ub953_get_fc_rate (priv); - -ub953_calc_clkout_ub971 (priv,25000000 , fc_rate, &m, &n); - -ub953_write (priv,UB953_REG_CLKOUT_CTRL0 , m); -ub953_write (priv,UB953_REG_CLKOUT_CTRL1 , n); -} -static int ub953_register_clkout (struct ub953_data *priv) {struct device *dev = &priv->client->dev;
@@ -1055,16 +1061,15 @@ static int ub953_register_clkout(struct ub953_data *priv) priv->hw_data->model, dev_name(dev)), .ops = &ub953_clkout_ops, }; +struct ub953_clkout_data clkout_data;int ret;if (!init.name)return -ENOMEM ;/* Initialize clkout to 25MHz by default */ -if (priv->hw_data->is_ub971) -ub953_init_clkout_ub971 (priv); -else -ub953_init_clkout_ub953 (priv); +ub953_calc_clkout_params (priv,25000000 , &clkout_data); +ub953_write_clkout_regs (priv, &clkout_data); priv->clkout_clk_hw.init = &init;
Signature · 1 line
2.34.1
Re: [PATCH v14 17/18] media: i2c: ds90ub953: Restructure clkout management
Quoted 3 lines · Tomi Valkeinen
Separate clkout calculations and register writes into two functions:
ub953_calc_clkout_paramsandub953_write_clkout_regs, and add a structub953_clkout_datathat is used to store the clkout parameters.
...
drivers/media/i2c/ds90ub953.c struct ub953_hw_data { · line 137
Quoted 4 lines
drivers/media/i2c/ds90ub953.c +4
-0+struct ub953_clkout_data { +u32 hs_div; +u32 m; +u32 n;
Please, use struxt u32_fract instead of m/n.
Quoted 2 lines
drivers/media/i2c/ds90ub953.c +2
-0+unsigned long rate; +};
...
drivers/media/i2c/ds90ub953.c static unsigned long ub953_calc_clkout_ub971(struct ub953_data *priv, · line 927
Quoted 12 lines
drivers/media/i2c/ds90ub953.c +12
-0+static void ub953_calc_clkout_params (struct ub953_data *priv, +unsigned long target_rate, +struct ub953_clkout_data *clkout_data) +{ +struct device *dev = &priv->client->dev; +unsigned long clkout_rate; +u64 fc_rate; + + fc_rate =ub953_get_fc_rate (priv); + +if (priv->hw_data->is_ub971) { +u8 m, n;
Ditto. struct u8_fract; (But probably needs to be added into math.h. I'll Ack/Rb such a patch when one appears.
drivers/media/i2c/ds90ub953.c static unsigned long ub953_calc_clkout_ub971(struct ub953_data *priv, · line 930
Quoted 2 lines
drivers/media/i2c/ds90ub953.c +2
-0+ clkout_rate =ub953_calc_clkout_ub971 (priv, target_rate, + fc_rate, &m, &n);
Can be also parameter to that function.
drivers/media/i2c/ds90ub953.c static unsigned long ub953_calc_clkout_ub971(struct ub953_data *priv, · line 938
Quoted 7 lines
drivers/media/i2c/ds90ub953.c +7
-0+ clkout_data->m = m; + clkout_data->n = n; + +dev_dbg (dev,"%s %llu * %u / (8 * %u) = %lu (requested %lu)" , + __func__, fc_rate, m, n, clkout_rate, target_rate); + }else { +u8 hs_div, m, n;
Yeah, and so on...
Quoted 14 lines
drivers/media/i2c/ds90ub953.c +14
-0+ clkout_rate =ub953_calc_clkout_ub953 (priv, target_rate, + fc_rate, &hs_div, &m, &n); + + clkout_data->hs_div = hs_div; + clkout_data->m = m; + clkout_data->n = n; + +dev_dbg (dev,"%s %llu / %u * %u / %u = %lu (requested %lu)" , + __func__, fc_rate, hs_div, m, n, clkout_rate, + target_rate); + } + + clkout_data->rate = clkout_rate; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 1/1 math.h: Introduce struct u8_fract and struct s8_fract
Seems there going to be users for these data types, besides quite likely existing users that may benifit from them.
--- include/linux/math.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/math.h +2 -0
@@ -112,6 +112,8 @@ struct type##_fract { \ __##type numerator; \ __##type denominator; \ }; +__STRUCT_FRACT(s8) +__STRUCT_FRACT(u8) __STRUCT_FRACT(s16) __STRUCT_FRACT(u16) __STRUCT_FRACT(s32)
Signature · 1 line
2.40.0.1.gaa8946217a0b
Tomi Valkeinen
maintainerRe: [PATCH v14 17/18] media: i2c: ds90ub953: Restructure clkout management
In reply to Andy ShevchenkoQuoted 5 lines · Andy Shevchenko
Quoted 3 lines · Tomi Valkeinen
Separate clkout calculations and register writes into two functions:
ub953_calc_clkout_paramsandub953_write_clkout_regs, and add a structub953_clkout_datathat is used to store the clkout parameters.
Quoted 8 lines
...
drivers/media/i2c/ds90ub953.c struct ub953_hw_data { · line 137
Quoted 4 lines
drivers/media/i2c/ds90ub953.c +4
-0+struct ub953_clkout_data { +u32 hs_div; +u32 m; +u32 n;Please, use struxt
u32_fractinstead of m/n.
I'm not sure how that helps. The documentation talks about m and n. Using different terms will make it more difficult to compare the code and the docs.
Tomi
Re: [PATCH v14 17/18] media: i2c: ds90ub953: Restructure clkout management
Quoted 5 lines · Tomi Valkeinen
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Tomi Valkeinen
Separate clkout calculations and register writes into two functions:
ub953_calc_clkout_paramsandub953_write_clkout_regs, and add a structub953_clkout_datathat is used to store the clkout parameters.
...
Quoted 10 lines
Quoted 6 lines
drivers/media/i2c/ds90ub953.c struct ub953_hw_data { · line 137
Quoted 4 lines
drivers/media/i2c/ds90ub953.c +4
-0+struct ub953_clkout_data { +u32 hs_div; +u32 m; +u32 n;Please, use struxt
u32_fractinstead of m/n.I'm not sure how that helps. The documentation talks about m and n. Using different terms will make it more difficult to compare the code and the docs.
You can always add a comment.
(For example in drivers/clk/clk-fractional-divider.c our documentation also
says about m/n, but most of the people understands that this is about fractional divider and actually with properly spelled parameters it will help others who are not experts in the CLK hardware.)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerRe: [PATCH v14 17/18] media: i2c: ds90ub953: Restructure clkout management
Quoted 20 lines · Andy Shevchenko
Quoted 5 lines · Tomi Valkeinen
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Tomi Valkeinen
Separate clkout calculations and register writes into two functions:
ub953_calc_clkout_paramsandub953_write_clkout_regs, and add a structub953_clkout_datathat is used to store the clkout parameters....
Quoted 10 lines
Quoted 6 lines
drivers/media/i2c/ds90ub953.c struct ub953_hw_data { · line 137
Quoted 4 lines
drivers/media/i2c/ds90ub953.c +4
-0+struct ub953_clkout_data { +u32 hs_div; +u32 m; +u32 n;Please, use struxt
u32_fractinstead of m/n.I'm not sure how that helps. The documentation talks about m and n. Using different terms will make it more difficult to compare the code and the docs.
Quoted 6 lines
You can always add a comment.
(For example in
drivers/clk/clk-fractional-divider.cour documentation also
says about m/n, but most of the people understands that this is about fractional divider and actually with properly spelled parameters it will help others who are not experts in the CLK hardware.)
Yes, I would agree with you if this was a generic piece of code, but I don't see the reasoning as valid as this is specific to a piece of hardware. Here, I think, matching the code to the HW documentation is more important than possibly making the code more understandable to people who are not familiar with the HW.
Especially as for non-English people seeing "numerator" and "denominator" might require a check to figure out which one is which, whereas m and n are (I would guess) a bit more universal (or maybe it's just me).
Tomi
Re: [PATCH v14 17/18] media: i2c: ds90ub953: Restructure clkout management
Quoted 4 lines · Tomi Valkeinen
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Tomi Valkeinen
Quoted 1 line · Andy Shevchenko
On Fri, Jun 16, 2023 at 04:59:21PM +0300, Tomi Valkeinen wrote:
...
Quoted 24 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
drivers/media/i2c/ds90ub953.c struct ub953_hw_data { · line 137
Quoted 4 lines
drivers/media/i2c/ds90ub953.c +4
-0+struct ub953_clkout_data { +u32 hs_div; +u32 m; +u32 n;Please, use struxt
u32_fractinstead of m/n.I'm not sure how that helps. The documentation talks about m and n. Using different terms will make it more difficult to compare the code and the docs.
Quoted 6 lines
You can always add a comment.
(For example in
drivers/clk/clk-fractional-divider.cour documentation also
says about m/n, but most of the people understands that this is about fractional divider and actually with properly spelled parameters it will help others who are not experts in the CLK hardware.)Yes, I would agree with you if this was a generic piece of code, but I don't see the reasoning as valid as this is specific to a piece of hardware. Here, I think, matching the code to the HW documentation is more important than possibly making the code more understandable to people who are not familiar with the HW.
Quoted 3 lines
Especially as for non-English people seeing "numerator" and "denominator" might require a check to figure out which one is which, whereas m and n are (I would guess) a bit more universal (or maybe it's just me).
I think for unprepared user the English plain words are simpler, or maybe it's just me.
At least we have a strong disagreement here, seems :-)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerPATCH v14 18/18 media: i2c: ds90ub953: Support non-sync mode
In reply to Tomi ValkeinenAdd support for FPD-Link non-sync mode with external clock. The only thing that needs to be added is the calculation for the clkout.
--- drivers/media/i2c/ds90ub953.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
drivers/media/i2c/ds90ub953.c +26 -8
@@ -143,6 +143,7 @@ struct ub953_data {struct i2c_client *client;struct regmap *regmap; +struct clk *clkin;u32 num_data_lanes;bool non_cont_clk;
@@ -842,15 +843,21 @@ static int ub953_i2c_master_init(struct ub953_data *priv)static u64 ub953_get_fc_rate (struct ub953_data *priv) { -if (priv->mode !=UB953_MODE_SYNC ) { +switch (priv->mode) { +case UB953_MODE_SYNC : +if (priv->hw_data->is_ub971) +return priv->plat_data->bc_rate *160ull ; +else +return priv->plat_data->bc_rate /2 *160ull ; + +case UB953_MODE_NONSYNC_EXT : +/* CLKIN_DIV = 1 always */ +return clk_get_rate (priv->clkin) *80ull ; + +default :/* Not supported */ return 0 ; } - -if (priv->hw_data->is_ub971) -return priv->plat_data->bc_rate *160ull ; -else -return priv->plat_data->bc_rate /2 *160ull ; } static unsigned long ub953_calc_clkout_ub953(struct ub953_data *priv,
@@ -1189,9 +1196,15 @@ static int ub953_hw_init(struct ub953_data *priv)dev_dbg (dev,"mode from %s: %#x\n" , mode_override ?"reg" :"strap" , priv->mode); -if (priv->mode !=UB953_MODE_SYNC ) +if (priv->mode !=UB953_MODE_SYNC && + priv->mode !=UB953_MODE_NONSYNC_EXT )return dev_err_probe (dev, -ENODEV , -"Only synchronous mode supported\n" ); +"Unsupported mode selected: %d\n" , + priv->mode); + +if (priv->mode ==UB953_MODE_NONSYNC_EXT && !priv->clkin) +return dev_err_probe (dev, -EINVAL , +"clkin required for non-sync ext mode\n" ); ret =ub953_read (priv,UB953_REG_REV_MASK_ID , &v);if (ret)
@@ -1319,6 +1332,11 @@ static int ub953_probe(struct i2c_client *client) goto err_mutex_destroy; } + priv->clkin =devm_clk_get_optional (dev,"clkin" ); +if (IS_ERR (priv->clkin)) +return dev_err_probe (dev,PTR_ERR (priv->clkin), +"failed to parse 'clkin'\n" ); + ret =ub953_parse_dt (priv);if (ret) goto err_mutex_destroy;
Signature · 1 line
2.34.1
Re: [PATCH v14 18/18] media: i2c: ds90ub953: Support non-sync mode
Quoted 2 lines · Tomi Valkeinen
Add support for FPD-Link non-sync mode with external clock. The only thing that needs to be added is the calculation for the clkout.
...
drivers/media/i2c/ds90ub953.c static int ub953_i2c_master_init(struct ub953_data *priv) · line 851
Quoted 6 lines
drivers/media/i2c/ds90ub953.c +6
-0+switch (priv->mode) { +case UB953_MODE_SYNC : +if (priv->hw_data->is_ub971) +return priv->plat_data->bc_rate *160ull ; +else +return priv->plat_data->bc_rate /2 *160ull ;
Redundant 'else'.
Do I understand correctly you don't want to fallthrough because it will give ±160 in the rate (depending if it's even or odd)?
Quoted 8 lines
drivers/media/i2c/ds90ub953.c +5
-0+case UB953_MODE_NONSYNC_EXT : +/* CLKIN_DIV = 1 always */ +return clk_get_rate (priv->clkin) *80ull ; + +default :/* Not supported */ return 0 ; }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerRe: [PATCH v14 18/18] media: i2c: ds90ub953: Support non-sync mode
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Tomi Valkeinen
Add support for FPD-Link non-sync mode with external clock. The only thing that needs to be added is the calculation for the clkout.
...
Quoted 8 lines
drivers/media/i2c/ds90ub953.c static int ub953_i2c_master_init(struct ub953_data *priv) · line 851
Quoted 6 lines
drivers/media/i2c/ds90ub953.c +6
-0+switch (priv->mode) { +case UB953_MODE_SYNC : +if (priv->hw_data->is_ub971) +return priv->plat_data->bc_rate *160ull ; +else +return priv->plat_data->bc_rate /2 *160ull ;Redundant 'else'.
True, but I like the symmetry in:
if (foo)
return 123; else return 321;
Quoted 2 lines
Do I understand correctly you don't want to fallthrough because it will give ±160 in the rate (depending if it's even or odd)?
Sorry, can you clarify? Fallthrough to what?
Quoted 9 lines
Quoted 8 lines
drivers/media/i2c/ds90ub953.c +5
-0+case UB953_MODE_NONSYNC_EXT : +/* CLKIN_DIV = 1 always */ +return clk_get_rate (priv->clkin) *80ull ; + +default :/* Not supported */ return 0 ; }
Re: [PATCH v14 18/18] media: i2c: ds90ub953: Support non-sync mode
Quoted 4 lines · Tomi Valkeinen
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Tomi Valkeinen
Add support for FPD-Link non-sync mode with external clock. The only thing that needs to be added is the calculation for the clkout.
...
Quoted 9 lines
Quoted 8 lines
drivers/media/i2c/ds90ub953.c static int ub953_i2c_master_init(struct ub953_data *priv) · line 851
Quoted 6 lines
drivers/media/i2c/ds90ub953.c +6
-0+switch (priv->mode) { +case UB953_MODE_SYNC : +if (priv->hw_data->is_ub971) +return priv->plat_data->bc_rate *160ull ; +else +return priv->plat_data->bc_rate /2 *160ull ;Redundant 'else'.
Quoted 6 lines
True, but I like the symmetry in:
if (foo)
return 123; else return 321;
At the same time it will be symmetry with other switch-case(s). That's why the question about fallthrough below.
Quoted 4 lines
Quoted 2 lines
Do I understand correctly you don't want to fallthrough because it will give ±160 in the rate (depending if it's even or odd)?
Sorry, can you clarify? Fallthrough to what?
To the below case since '/ 2 * 160 ~= *80'. Why ~ because it might give off-by-one error due to even/odd input.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/media/i2c/ds90ub953.c +3
-0+case UB953_MODE_NONSYNC_EXT : +/* CLKIN_DIV = 1 always */ +return clk_get_rate (priv->clkin) *80ull ;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Tomi Valkeinen
maintainerRe: [PATCH v14 18/18] media: i2c: ds90ub953: Support non-sync mode
Quoted 27 lines · Andy Shevchenko
Quoted 4 lines · Tomi Valkeinen
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Tomi Valkeinen
Add support for FPD-Link non-sync mode with external clock. The only thing that needs to be added is the calculation for the clkout.
...
Quoted 9 lines
Quoted 8 lines
drivers/media/i2c/ds90ub953.c static int ub953_i2c_master_init(struct ub953_data *priv) · line 851
Quoted 6 lines
drivers/media/i2c/ds90ub953.c +6
-0+switch (priv->mode) { +case UB953_MODE_SYNC : +if (priv->hw_data->is_ub971) +return priv->plat_data->bc_rate *160ull ; +else +return priv->plat_data->bc_rate /2 *160ull ;Redundant 'else'.
Quoted 6 lines
True, but I like the symmetry in:
if (foo)
return 123; else return 321;At the same time it will be symmetry with other switch-case(s). That's why the question about fallthrough below.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Do I understand correctly you don't want to fallthrough because it will give ±160 in the rate (depending if it's even or odd)?
Sorry, can you clarify? Fallthrough to what?
To the below case since '/ 2 * 160 ~= *80'. Why ~ because it might give off-by-one error due to even/odd input.
The below case is different. "priv->plat_data->bc_rate" vs "clk_get_rate(priv->clkin)".
As to the order of the calculation (/ 2 * 160 versus * 160 / 2), generally speaking, I have never figured out what are the correct ways to calculate clock rates.
I wrote "x / 2 * 160" as that's what the documentation gives (there's a hardware /2 divider in non-ub971 chips, followed by a 160 multiplier). But does the documentation presume that the calculation is done precisely, not in integers? If so, "x * 160 / 2" would be better (but then, do we need to round?). Or does the /2 hardware divider basically actually work as a an integer division, in case "x / 2 * 160" is the correct one.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
drivers/media/i2c/ds90ub953.c static int ub953_i2c_master_init(struct ub953_data *priv) · line 855
Quoted 3 lines
drivers/media/i2c/ds90ub953.c +3
-0+case UB953_MODE_NONSYNC_EXT : +/* CLKIN_DIV = 1 always */ +return clk_get_rate (priv->clkin) *80ull ;
Tomi