Add Microchip ZL3073x support (part 1)
Subsystems (8)
Ivan Vecera
maintainerv7 cover Add Microchip ZL3073x support (part 1)
Add support for Microchip Azurite DPLL/PTP/SyncE chip family that provides DPLL and PTP functionality. This series bring first part that adds the common MFD driver that provides an access to the bus that can be either I2C or SPI.
The next part of the series is bringing the DPLL driver that will covers DPLL functionality. Another series will bring PTP driver and flashing capability via devlink in the MFD driver will follow soon.
Testing was done by myself and by Prathosh Satish on Microchip EDS2 development board with ZL30732 DPLL chip connected over I2C bus.
Patch breakdown
===============
Patch 1 - Common DT schema for DPLL device and pin
Patch 2 - DT bindings for microchip,zl3073* devices
Patch 3 - Basic support for I2C, SPI and regmap configuration Patch 4 - Devlink device registration and info
Patch 5 - Helpers for reading and writing register mailboxes Patch 6 - Fetch invariant register values used by DPLL/PTP sub-drivers Patch 7 - Clock ID generation for DPLL driver
Patch 8 - Register/create DPLL device cells
---v6->v7:
* pass channel number using platform data instead of mfd_cell->id v5->v6:
* fixed devlink info firmware version to be running instead of fixed
* added documentation for devlink info versionsv4->v5:
* fixed DT patches description
* dropped mailbox API
* added type-safe register access functions
* added an ability to protect multi-op accessesv3->v4:
* fixed shortcomings in DT patches
* completely reworked register access
* removed a need to manage locking during mailbox accesses by callers
* regcache switched to maple
* dev_err_probe() in probe path
* static mfd cells during sub-devices registrationv1->v3:
* dropped macros for generating register access functions
* register access functions are provided in <linux/mfd/zl3073x_regs.h>
* fixed DT descriptions and compatible wildcard usage
* reworked regmap locking
- regmap uses implicit locking
- mailbox registers are additionally protected by extra mutex
* fixed regmap virtual address range
* added regmap rbtree cache (only for page selector now)
* dropped patches for exporting strnchrnul and for supporting mfg file this will be maybe added later
Ivan Vecera (8):
dt-bindings: dpll: Add DPLL device and pin
dt-bindings: dpll: Add support for Microchip Azurite chip family
mfd: Add Microchip ZL3073x support
mfd: zl3073x: Add support for devlink device info
mfd: zl3073x: Protect operations requiring multiple register accesses
mfd: zl3073x: Fetch invariants during probe
mfd: zl3073x: Add clock_id field
mfd: zl3073x: Register DPLL sub-device during init
.../devicetree/bindings/dpll/dpll-device.yaml | 76 ++ .../devicetree/bindings/dpll/dpll-pin.yaml | 45 + .../bindings/dpll/microchip,zl30731.yaml | 115 +++ Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/zl3073x.rst | 37 + MAINTAINERS | 11 + drivers/mfd/Kconfig | 32 + drivers/mfd/Makefile | 5 + drivers/mfd/zl3073x-core.c | 875 ++++++++++++++++++ drivers/mfd/zl3073x-i2c.c | 68 ++ drivers/mfd/zl3073x-regs.h | 54 ++ drivers/mfd/zl3073x-spi.c | 68 ++ drivers/mfd/zl3073x.h | 31 + include/linux/mfd/zl3073x-regs.h | 88 ++ include/linux/mfd/zl3073x.h | 202 ++++ 15 files changed, 1708 insertions(+) create mode 100644 Documentation/devicetree/bindings/dpll/dpll-device.yaml create mode 100644 Documentation/devicetree/bindings/dpll/dpll-pin.yaml create mode 100644 Documentation/devicetree/bindings/dpll/microchip,zl30731.yaml create mode 100644 Documentation/networking/devlink/zl3073x.rst create mode 100644 drivers/mfd/zl3073x-core.c create mode 100644 drivers/mfd/zl3073x-i2c.c create mode 100644 drivers/mfd/zl3073x-regs.h create mode 100644 drivers/mfd/zl3073x-spi.c create mode 100644 drivers/mfd/zl3073x.h create mode 100644 include/linux/mfd/zl3073x-regs.h create mode 100644 include/linux/mfd/zl3073x.h
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 1/8 dt-bindings: dpll: Add DPLL device and pin
Add a common DT schema for DPLL device and its associated pins. The DPLL (device phase-locked loop) is a device used for precise clock synchronization in networking and telecom hardware.
The device includes one or more DPLLs (channels) and one or more physical input/output pins.
Each DPLL channel is used either to provide a pulse-per-clock signal or to drive an Ethernet equipment clock.
The input and output pins have the following properties:
* label: specifies board label
* connection type: specifies its usage depending on wiring
* list of supported or allowed frequencies: depending on how the pin is connected and where)
* embedded sync capability: indicates whether the pin supports this
---v5->v6:
* no changev4->v5:
* removed compilation output from the descriptionv3->v4:
* dropped $Ref from dpll-pin reg property
* added maxItems to dpll-pin reg property
* fixed paragraph in dpll-pin desc
* dpll-pin type property renamed to connection-type v1->v3:
* rewritten description for both device and pin
* dropped num-dplls property
* supported-frequencies property renamed to supported-frequencies-hz
--- .../devicetree/bindings/dpll/dpll-device.yaml | 76 +++++++++++++++++++ .../devicetree/bindings/dpll/dpll-pin.yaml | 45 +++++++++++ MAINTAINERS | 2 + 3 files changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/dpll/dpll-device.yaml create mode 100644 Documentation/devicetree/bindings/dpll/dpll-pin.yaml
Documentation/devicetree/bindings/dpll/dpll-device.yaml new file +76 -0
@@ -0,0 +1,76 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/dpll/dpll-device.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Digital Phase-Locked Loop (DPLL) Device + +maintainers: + - Ivan Vecera <[email protected]> + +description: + Digital Phase-Locked Loop (DPLL) device is used for precise clock + synchronization in networking and telecom hardware. The device can + have one or more channels (DPLLs) and one or more physical input and + output pins. Each DPLL channel can either produce pulse-per-clock signal + or drive ethernet equipment clock. The type of each channel can be + indicated by dpll-types property. + +properties: + $nodename: + pattern: "^dpll(@.*)?$" + + "#address-cells": + const: 0 + + "#size-cells": + const: 0 + + dpll-types: + description: List of DPLL channel types, one per DPLL instance. + $ref: /schemas/types.yaml#/definitions/non-unique-string-array + items: + enum: [pps, eec] + + input-pins: + type: object + description: DPLL input pins + unevaluatedProperties: false + + properties: + "#address-cells": + const: 1 + "#size-cells": + const: 0 + + patternProperties: + "^pin@[0-9a-f]+$": + $ref: /schemas/dpll/dpll-pin.yaml + unevaluatedProperties: false + + required: + - "#address-cells" + - "#size-cells" + + output-pins: + type: object + description: DPLL output pins + unevaluatedProperties: false + + properties: + "#address-cells": + const: 1 + "#size-cells": + const: 0 + + patternProperties: + "^pin@[0-9]+$": + $ref: /schemas/dpll/dpll-pin.yaml + unevaluatedProperties: false + + required: + - "#address-cells" + - "#size-cells" + +additionalProperties: true
Documentation/devicetree/bindings/dpll/dpll-pin.yaml new file +45 -0
45 lines not on this page · raw message
MAINTAINERS +2 -0
@@ -7195,6 +7195,8 @@ M: Arkadiusz Kubalewski <[email protected]> M: Jiri Pirko <[email protected]> L: [email protected] S: Supported +F: Documentation/devicetree/bindings/dpll/dpll-device.yaml +F: Documentation/devicetree/bindings/dpll/dpll-pin.yaml F: Documentation/driver-api/dpll.rst F: drivers/dpll/* F: include/linux/dpll.h
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 2/8 dt-bindings: dpll: Add support for Microchip Azurite chip family
In reply to Ivan VeceraAdd DT bindings for Microchip Azurite DPLL chip family. These chips provide up to 5 independent DPLL channels, 10 differential or single-ended inputs and 10 differential or 20 single-ended outputs. They can be connected via I2C or SPI busses.
---v5->v6:
* no changev4->v5:
* removed compilation output from the description v3->v4:
* fixed $Id
* dpll-pin type property renamed to connection type v1->v3:
* single file for both i2c & spi
* 5 compatibles for all supported chips from the family
--- .../bindings/dpll/microchip,zl30731.yaml | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Documentation/devicetree/bindings/dpll/microchip,zl30731.yaml
Documentation/devicetree/bindings/dpll/microchip,zl30731.yaml new file +115 -0
@@ -0,0 +1,115 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/dpll/microchip,zl30731.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip Azurite DPLL device + +maintainers: + - Ivan Vecera <[email protected]> + +description: + Microchip Azurite DPLL (ZL3073x) is a family of DPLL devices that + provides up to 5 independent DPLL channels, up to 10 differential or + single-ended inputs and 10 differential or 20 single-ended outputs. + These devices support both I2C and SPI interfaces. + +properties: + compatible: + enum: + - microchip,zl30731 + - microchip,zl30732 + - microchip,zl30733 + - microchip,zl30734 + - microchip,zl30735 + + reg: + maxItems: 1 + +required: + - compatible + - reg + +allOf: + - $ref: /schemas/dpll/dpll-device.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + dpll@70 { + compatible = "microchip,zl30732"; + reg = <0x70>; + dpll-types = "pps", "eec"; + + input-pins { + #address-cells = <1>; + #size-cells = <0>; + + pin@0 { /* REF0P */ + reg = <0>; + connection-type = "ext"; + label = "Input 0"; + supported-frequencies-hz = /bits/ 64 <1 1000>; + }; + }; + + output-pins { + #address-cells = <1>; + #size-cells = <0>; + + pin@3 { /* OUT1N */ + reg = <3>; + connection-type = "gnss"; + esync-control; + label = "Output 1"; + supported-frequencies-hz = /bits/ 64 <1 10000>; + }; + }; + }; + }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + dpll@70 { + compatible = "microchip,zl30731"; + reg = <0x70>; + spi-max-frequency = <12500000>; + + dpll-types = "pps"; + + input-pins { + #address-cells = <1>; + #size-cells = <0>; + + pin@0 { /* REF0P */ + reg = <0>; + connection-type = "ext"; + label = "Input 0"; + supported-frequencies-hz = /bits/ 64 <1 1000>; + }; + }; + + output-pins { + #address-cells = <1>; + #size-cells = <0>; + + pin@3 { /* OUT1N */ + reg = <3>; + connection-type = "gnss"; + esync-control; + label = "Output 1"; + supported-frequencies-hz = /bits/ 64 <1 10000>; + }; + }; + }; + }; +...
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 3/8 mfd: Add Microchip ZL3073x support
In reply to Ivan VeceraAdd base MFD driver for Microchip Azurite ZL3073x chip family. These chips provide DPLL and PHC (PTP) functionality and can be connected over I2C or SPI bus.
The MFD driver handles basic communication and synchronization over the bus, as well as common functionality that are used by the DPLL driver (part 2) and by the PTP driver (to be added later).
The chip family has the following characteristics:
* up to 5 separate DPLL units (channels)
* 5 synthesizers
* 10 input pins (references)
* 10 outputs
* 20 output pins (output pin pair shares one output)
* Each reference and output can operate in either differential or single-ended mode (differential mode uses 2 pins)
* Each output is connected to one of the synthesizers
* Each synthesizer is driven by one of the DPLL unit
The device uses 7-bit addresses and 8-bits values. It exposes 8-, 16-, 32- and 48-bits registers in address range <0x000,0x77F>. Due to 7bit addressing, the range is organized into pages of 128 bytes, with each page containing a page selector register at address 0x7F. For reading/writing multi-byte registers, the device supports bulk transfers.
---v5->v6:
* fixed condition for writing 48bit register valuev4->v5:
* added type-safe register access functions
* register definition macros moved to include/linux/mfd/zl3073x-regs.h
* register definition used only by MFD moved to drivers/mfd/zl3073x-regs.h
v3->v4:
* zl3073x_regs.h moved to drivers/mfd/
* maple as regcache
* added and used general helper to read 16bit registers
* removed mailbox mutex for now
* removed parentheses in zl3073x_is_volatile_reg()
* used dev_err_probe() in probe path
* dropped <linux/device.h> inclusion
* dropped unneccessary i2c_set_clientdata() and spi_set_drvdata()
v2->v3:
* added chip_info with valid chip ids and num of DPLLs for compatibles
* regmap is using implicit locking
* mailbox registers requires extra mutex to be held
* added helpers to access registers
* report device firmware and config version using dev_dbg
* fixed regmap ranges
* enabled rbtree regcache for page selector
v1->v2:
* fixed header issues
* removed usage of of_match_ptr
* added check for devm_mutex_init
* removed commas after sentinels
* removed variable initialization in zl3073x_i2c_probe()
* moved device tables closer to their users
* renamed zl3073x_dev_alloc() to zl3073x_devm_alloc()
* removed empty zl3073x_dev_exit()
* spidev renamed to spi
* squashed together with device DT bindings
* used dev_err_probe() instead of dev_err() during probe
* added some function documentation
DT bindings:
* spliced to separate files for i2c and spi
* fixed property order in DT bindings' examples
* added description
--- MAINTAINERS | 9 + drivers/mfd/Kconfig | 30 ++ drivers/mfd/Makefile | 5 + drivers/mfd/zl3073x-core.c | 472 +++++++++++++++++++++++++++++++ drivers/mfd/zl3073x-i2c.c | 66 +++++ drivers/mfd/zl3073x-regs.h | 17 ++ drivers/mfd/zl3073x-spi.c | 66 +++++ drivers/mfd/zl3073x.h | 31 ++ include/linux/mfd/zl3073x-regs.h | 66 +++++ include/linux/mfd/zl3073x.h | 35 +++ 10 files changed, 797 insertions(+) create mode 100644 drivers/mfd/zl3073x-core.c create mode 100644 drivers/mfd/zl3073x-i2c.c create mode 100644 drivers/mfd/zl3073x-regs.h create mode 100644 drivers/mfd/zl3073x-spi.c create mode 100644 drivers/mfd/zl3073x.h create mode 100644 include/linux/mfd/zl3073x-regs.h create mode 100644 include/linux/mfd/zl3073x.h
MAINTAINERS +9 -0
@@ -16052,6 +16052,15 @@ L: [email protected] S: Supported F: drivers/net/wireless/microchip/ +MICROCHIP ZL3073X DRIVER +M: Ivan Vecera <[email protected]> +M: Prathosh Satish <[email protected]> +L: [email protected] +S: Supported +F: Documentation/devicetree/bindings/dpll/microchip,zl30731.yaml +F: drivers/mfd/zl3073x* +F: include/linux/mfd/zl3073x.h + MICROSEMI MIPS SOCS M: Alexandre Belloni <[email protected]> M: [email protected]
drivers/mfd/Kconfig +30 -0
@@ -2422,5 +2422,35 @@ config MFD_UPBOARD_FPGA To compile this driver as a module, choose M here: the module will be called upboard-fpga. +config MFD_ZL3073X_CORE + tristate + select MFD_CORE + +config MFD_ZL3073X_I2C + tristate "Microchip Azurite DPLL/PTP/SyncE with I2C" + depends on I2C + select MFD_ZL3073X_CORE + select REGMAP_I2C + help + Say Y here if you want to build I2C support for the Microchip + Azurite DPLL/PTP/SyncE chip family. + + To compile this driver as a module, choose M here: the module + will be called zl3073x_i2c and you will also get zl3073x for + the core module. + +config MFD_ZL3073X_SPI + tristate "Microchip Azurite DPLL/PTP/SyncE with SPI" + depends on SPI + select MFD_ZL3073X_CORE + select REGMAP_SPI + help + Say Y here if you want to build SPI support for the Microchip + Azurite DPLL/PTP/SyncE chip family. + + To compile this driver as a module, choose M here: the module + will be called zl3073x_spi and you will also get zl3073x for + the core module. + endmenu endif
drivers/mfd/Makefile +5 -0
@@ -290,3 +290,8 @@ obj-$(CONFIG_MFD_RSMU_I2C) += rsmu_i2c.o rsmu_core.o obj-$(CONFIG_MFD_RSMU_SPI) += rsmu_spi.o rsmu_core.o obj-$(CONFIG_MFD_UPBOARD_FPGA) += upboard-fpga.o + +zl3073x-y := zl3073x-core.o +obj-$(CONFIG_MFD_ZL3073X_CORE) += zl3073x.o +obj-$(CONFIG_MFD_ZL3073X_I2C) += zl3073x-i2c.o +obj-$(CONFIG_MFD_ZL3073X_SPI) += zl3073x-spi.o
drivers/mfd/zl3073x-core.c new file +472 -0
472 lines not on this page · raw message
drivers/mfd/zl3073x-i2c.c new file +66 -0
66 lines not on this page · raw message
drivers/mfd/zl3073x-regs.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ZL3073X_REGS_H +#define __ZL3073X_REGS_H + +#include <linux/mfd/zl3073x-regs.h> + +/************************** +* Register Page 0, General +**************************/ + +#define ZL_REG_ID ZL_REG(0, 0x01, 2) +#define ZL_REG_REVISION ZL_REG(0, 0x03, 2) +#define ZL_REG_FW_VER ZL_REG(0, 0x05, 2) +#define ZL_REG_CUSTOM_CONFIG_VER ZL_REG(0, 0x07, 4) + +#endif /* __ZL3073X_REGS_H */
drivers/mfd/zl3073x-spi.c new file +66 -0
66 lines not on this page · raw message
drivers/mfd/zl3073x.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ZL3073X_CORE_H +#define __ZL3073X_CORE_H + +struct device ; +struct regmap_config ; +struct zl3073x_dev ; + +enum zl3073x_chip_type { +ZL30731 , +ZL30732 , +ZL30733 , +ZL30734 , +ZL30735 , +}; + +struct zl3073x_chip_info { +const u16 *ids; +size_t num_ids; +int num_channels; +}; + +extern const struct zl3073x_chip_info zl3073x_chip_info[]; + +struct zl3073x_dev *zl3073x_devm_alloc (struct device *dev); +void zl3073x_dev_init_regmap_config (struct regmap_config *regmap_cfg); +int zl3073x_dev_probe (struct zl3073x_dev *zldev, +const struct zl3073x_chip_info *chip_info); + +#endif /* __ZL3073X_CORE_H */
include/linux/mfd/zl3073x-regs.h new file +66 -0
66 lines not on this page · raw message
include/linux/mfd/zl3073x.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __LINUX_MFD_ZL3073X_H +#define __LINUX_MFD_ZL3073X_H + +#include <linux/types.h> + +struct device ; +struct regmap ; + +/** +* struct zl3073x_dev - zl3073x device +* @dev: pointer to device +* @regmap: regmap to access device registers +*/ +struct zl3073x_dev { +struct device *dev; +struct regmap *regmap; +}; + +/********************** +* Registers operations +**********************/ + +int zl3073x_poll_zero_u8 (struct zl3073x_dev *zldev,unsigned int reg,u8 mask); +int zl3073x_read_u8 (struct zl3073x_dev *zldev,unsigned int reg,u8 *val); +int zl3073x_read_u16 (struct zl3073x_dev *zldev,unsigned int reg,u16 *val); +int zl3073x_read_u32 (struct zl3073x_dev *zldev,unsigned int reg,u32 *val); +int zl3073x_read_u48 (struct zl3073x_dev *zldev,unsigned int reg,u64 *val); +int zl3073x_write_u8 (struct zl3073x_dev *zldev,unsigned int reg,u8 val); +int zl3073x_write_u16 (struct zl3073x_dev *zldev,unsigned int reg,u16 val); +int zl3073x_write_u32 (struct zl3073x_dev *zldev,unsigned int reg,u32 val); +int zl3073x_write_u48 (struct zl3073x_dev *zldev,unsigned int reg,u64 val); + +#endif /* __LINUX_MFD_ZL3073X_H */
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 4/8 mfd: zl3073x: Add support for devlink device info
In reply to Ivan VeceraUse devlink_alloc() to allocate zl3073x_dev structure, register the device as a devlink device, and add devlink callback to provide device info.
---v5->v6:
* fixed devlink info firmware version to be running instead of fixed
* added documentation for devlink info versions
v4->v5:
* use new register access helpers
v3->v4:
* pass error code from devm_add_action_or_reset() call
v2->v3:
* merged devlink device allocation, registration and device info callback
v1->v2:
* dependency on NET moved to MFD_ZL3073X_CORE in Kconfig
* devlink register managed way
--- Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/zl3073x.rst | 37 +++++++ drivers/mfd/Kconfig | 2 + drivers/mfd/zl3073x-core.c | 108 ++++++++++++++++++- 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 Documentation/networking/devlink/zl3073x.rst
Documentation/networking/devlink/index.rst +1 -0
@@ -98,3 +98,4 @@ parameters, info versions, and other features it supports. iosm octeontx2 sfc + zl3073x
Documentation/networking/devlink/zl3073x.rst new file +37 -0
@@ -0,0 +1,37 @@ +.. SPDX-License-Identifier: GPL-2.0 + +======================= +zl3073x devlink support +======================= + +This document describes the devlink features implemented by the ``zl3073x`` +device driver. + +Info versions +============= + +The ``zl3073x`` driver reports the following versions + +.. list-table:: devlink info versions implemented + :widths: 5 5 5 90 + + * - Name + - Type + - Example + - Description + * - ``asic.id`` + - fixed + - 1E94 + - Chip identification number + * - ``asic.rev`` + - fixed + - 300 + - Chip revision number + * - ``fw`` + - running + - 7006 + - Firmware version number + * - ``cfg.custom_ver`` + - running + - 1.3.0.1 + - Device configuration version customized by OEM
drivers/mfd/Kconfig +2 -0
@@ -2424,6 +2424,8 @@ config MFD_UPBOARD_FPGA config MFD_ZL3073X_CORE tristate + depends on NET + select NET_DEVLINK select MFD_CORE config MFD_ZL3073X_I2C
drivers/mfd/zl3073x-core.c +106 -2
149 lines not on this page · raw message
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 5/8 mfd: zl3073x: Protect operations requiring multiple register accesses
In reply to Ivan VeceraRegisters located on page 10 and above are called mailbox-type registers. Each page represents a mailbox and is used to read from and write to configuration of a specific object (DPLL, output, reference or synth).
Each mailbox page contains a mask register, which selects an index of the target object to interact with and a semaphore register, which indicates the requested operation.
The remaining registers within the page are latch registers, which are populated by the firmware during read operations or by the driver prior to write operations.
Operations with these registers requires multiple register reads, writes and polls and all of them need to be done atomically.
So add multiop_lock mutex to protect such operations and check the mutex is held by the caller when it's accessing registers from page 10 and above.
---v5->v6:
* no changev4->v5:
* dropped mailbox API and replaced by an ability to protect multi-op accessesv3->v4:
* completely reworked mailbox accessv1->v3:
* dropped ZL3073X_MB_OP macro usage
--- drivers/mfd/zl3073x-core.c | 14 ++++++++++++++ include/linux/mfd/zl3073x.h | 3 +++ 2 files changed, 17 insertions(+)
drivers/mfd/zl3073x-core.c +14 -0
@@ -121,6 +121,12 @@ static const struct regmap_config zl3073x_regmap_config = {static bool zl3073x_check_reg (struct zl3073x_dev *zldev,unsigned int reg,size_t size) { +/* Check that multiop lock is held when accessing registers +* from page 10 and above. +*/ +if (ZL_REG_PAGE (reg) >=10 ) +lockdep_assert_held (&zldev->multiop_lock); +/* Check the index is in valid range for indexed register */ if (ZL_REG_OFFSET (reg) >ZL_REG_MAX_OFFSET (reg)) { dev_err(zldev->dev, "Index out of range for reg 0x%04lx\n",
@@ -557,6 +563,14 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev,FIELD_GET (GENMASK (15 ,8 ), cfg_ver), FIELD_GET(GENMASK(7, 0), cfg_ver)); +/* Initialize mutex for operations where multiple reads, writes +* and/or polls are required to be done atomically. +*/ + rc =devm_mutex_init (zldev->dev, &zldev->multiop_lock); +if (rc) +return dev_err_probe (zldev->dev, rc, +"Failed to initialize mutex\n" ); +/* Register the device as devlink device */ devlink =priv_to_devlink (zldev);devlink_register (devlink);
include/linux/mfd/zl3073x.h +3 -0
@@ -3,6 +3,7 @@#ifndef __LINUX_MFD_ZL3073X_H#define __LINUX_MFD_ZL3073X_H +#include <linux/mutex.h> #include <linux/types.h> struct device ;
@@ -12,10 +13,12 @@ struct regmap;* struct zl3073x_dev - zl3073x device * @dev: pointer to device * @regmap: regmap to access device registers +* @multiop_lock: to serialize multiple register operations */ struct zl3073x_dev {struct device *dev;struct regmap *regmap; +struct mutex multiop_lock; };/**********************
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 6/8 mfd: zl3073x: Fetch invariants during probe
In reply to Ivan VeceraSeveral configuration parameters will remain constant at runtime, so we can load them during probe to avoid excessive reads from the hardware.
These parameters will be frequently accessed by the DPLL sub-device driver (in follow-up series), and later by the PHC/PTP sub-device driver.
Read the following parameters from the device during probe and store them for later use:
* frequencies of the synthesizers and their associated DPLL channels
* enablement and type (single-ended or differential) of input pins
* associated synthesizers, signal format, and enablement status of outputs
---v6->v7:
* export zl3073x_mb_op() - will be used immediatelly in part2 v5->v6:
* no changev4->v5:
* updated to use new register APIv3->v4:
* adjusted for new mailbox APIv2->v3:
* dropped usage of macros for generating helper functions v1->v2:
* fixed and added inline documentation
--- drivers/mfd/zl3073x-core.c | 251 +++++++++++++++++++++++++++++++ drivers/mfd/zl3073x-regs.h | 37 +++++ include/linux/mfd/zl3073x-regs.h | 22 +++ include/linux/mfd/zl3073x.h | 153 +++++++++++++++++++ 4 files changed, 463 insertions(+)
drivers/mfd/zl3073x-core.c +251 -0
@@ -6,6 +6,7 @@#include <linux/dev_printk.h> #include <linux/device.h> #include <linux/export.h> +#include <linux/math64.h> #include <linux/mfd/zl3073x.h> #include <linux/module.h> #include <linux/netlink.h>
@@ -504,6 +505,251 @@ void zl3073x_dev_init_regmap_config(struct regmap_config *regmap_cfg) }EXPORT_SYMBOL_NS_GPL (zl3073x_dev_init_regmap_config,"ZL3073X" ); +int zl3073x_mb_op (struct zl3073x_dev *zldev,unsigned int op_reg,u8 op_val, +unsigned int mask_reg,u16 mask_val) +{ +int rc; + +/* Set mask for the operation */ + rc =zl3073x_write_u16 (zldev, mask_reg, mask_val); +if (rc) +return rc; + +/* Trigger the operation */ + rc =zl3073x_write_u8 (zldev, op_reg, op_val); +if (rc) +return rc; + +/* Wait for the operation to actually finish */ +return zl3073x_poll_zero_u8 (zldev, op_reg, op_val); +} +EXPORT_SYMBOL_NS_GPL (zl3073x_mb_op,"ZL3073X" ); + +/** +* zl3073x_input_state_fetch - get input state +* @zldev: pointer to zl3073x_dev structure +* @index: input pin index to fetch state for +* +* Function fetches information for the given input reference that are +* invariant and stores them for later use. +* +* Return: 0 on success, <0 on error +*/ +static int +zl3073x_input_state_fetch (struct zl3073x_dev *zldev,u8 index) +{ +struct zl3073x_input *input; +u8 ref_config; +int rc; + + input = &zldev->input[index]; + +/* If the input is differential then the configuration for N-pin +* reference is ignored and P-pin config is used for both. +*/ +if (zl3073x_is_n_pin (index) && +zl3073x_input_is_diff (zldev, index -1 )) { + input->enabled =zl3073x_input_is_enabled (zldev, index -1 ); + input->diff = true; + +return 0 ; + } + +guard (mutex)(&zldev->multiop_lock); + +/* Read reference configuration */ + rc =zl3073x_mb_op (zldev,ZL_REG_REF_MB_SEM ,ZL_REF_MB_SEM_RD , +ZL_REG_REF_MB_MASK ,BIT (index)); +if (rc) +return rc; + +/* Read ref_config register */ + rc =zl3073x_read_u8 (zldev,ZL_REG_REF_CONFIG , &ref_config); +if (rc) +return rc; + + input->enabled =FIELD_GET (ZL_REF_CONFIG_ENABLE , ref_config); + input->diff =FIELD_GET (ZL_REF_CONFIG_DIFF_EN , ref_config); + +dev_dbg (zldev->dev,"INPUT%u is %s and configured as %s\n" , index, + input->enabled ?"enabled" :"disabled" , + input->diff ?"differential" :"single-ended" ); + +return rc; +} + +/** +* zl3073x_output_state_fetch - get output state +* @zldev: pointer to zl3073x_dev structure +* @index: output index to fetch state for +* +* Function fetches information for the given output (not output pin) +* that are invariant and stores them for later use. +* +* Return: 0 on success, <0 on error +*/ +static int +zl3073x_output_state_fetch (struct zl3073x_dev *zldev,u8 index) +{ +struct zl3073x_output *output; +u8 output_ctrl, output_mode; +int rc; + + output = &zldev->output[index]; + +/* Read output configuration */ + rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_CTRL (index), &output_ctrl); +if (rc) +return rc; + +/* Store info about output enablement and synthesizer the output +* is connected to. +*/ + output->enabled =FIELD_GET (ZL_OUTPUT_CTRL_EN , output_ctrl); + output->synth =FIELD_GET (ZL_OUTPUT_CTRL_SYNTH_SEL , output_ctrl); + +dev_dbg (zldev->dev,"OUTPUT%u is %s, connected to SYNTH%u\n" , + index, output->enabled ?"enabled" :"disabled" , output->synth); + +guard (mutex)(&zldev->multiop_lock); + +/* Read output configuration */ + rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , +ZL_REG_OUTPUT_MB_MASK ,BIT (index)); +if (rc) +return rc; + +/* Read output_mode */ + rc =zl3073x_read_u8 (zldev,ZL_REG_OUTPUT_MODE , &output_mode); +if (rc) +return rc; + +/* Extract and store output signal format */ + output->signal_format =FIELD_GET (ZL_OUTPUT_MODE_SIGNAL_FORMAT , + output_mode); + +dev_dbg (zldev->dev,"OUTPUT%u has signal format 0x%02x\n" , index, + output->signal_format); + +return rc; +} + +/** +* zl3073x_synth_state_fetch - get synth state +* @zldev: pointer to zl3073x_dev structure +* @index: synth index to fetch state for +* +* Function fetches information for the given synthesizer that are +* invariant and stores them for later use. +* +* Return: 0 on success, <0 on error +*/ +static int +zl3073x_synth_state_fetch (struct zl3073x_dev *zldev,u8 index) +{ +u16 base, num, denom; +u8 synth_ctrl; +u32 mult; +int rc; + +/* Read synth control register */ + rc =zl3073x_read_u8 (zldev,ZL_REG_SYNTH_CTRL (index), &synth_ctrl); +if (rc) +return rc; + +/* Extract and store DPLL channel the synth is driven by */ + zldev->synth[index].dpll =FIELD_GET (ZL_SYNTH_CTRL_DPLL_SEL , + synth_ctrl); + +dev_dbg (zldev->dev,"SYNTH%u is connected to DPLL%u\n" , index, + zldev->synth[index].dpll); + +guard (mutex)(&zldev->multiop_lock); + +/* Read synth configuration */ + rc =zl3073x_mb_op (zldev,ZL_REG_SYNTH_MB_SEM ,ZL_SYNTH_MB_SEM_RD , +ZL_REG_SYNTH_MB_MASK ,BIT (index)); +if (rc) +return rc; + +/* The output frequency is determined by the following formula: +* base * multiplier * numerator / denominator +* +* Read registers with these values +*/ + rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_BASE , &base); +if (rc) +return rc; + + rc =zl3073x_read_u32 (zldev,ZL_REG_SYNTH_FREQ_MULT , &mult); +if (rc) +return rc; + + rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_M , &num); +if (rc) +return rc; + + rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_N , &denom); +if (rc) +return rc; + +/* Check denominator for zero to avoid div by 0 */ +if (!denom) { +dev_err (zldev->dev, +"Zero divisor for SYNTH%u retrieved from device\n" , + index); +return -EINVAL ; + } + +/* Compute and store synth frequency */ + zldev->synth[index].freq =mul_u64_u32_div (mul_u32_u32 (base, mult), + num, denom); + +dev_dbg (zldev->dev,"SYNTH%u frequency: %llu Hz\n" , index, + zldev->synth[index].freq); + +return rc; +} + +static int +zl3073x_dev_state_fetch (struct zl3073x_dev *zldev) +{ +int rc; +u8 i; + +for (i =0 ; i <ZL3073X_NUM_INPUTS ; i++) { + rc =zl3073x_input_state_fetch (zldev, i); +if (rc) { +dev_err (zldev->dev, +"Failed to fetch input state: %pe\n" , +ERR_PTR (rc)); +return rc; + } + } + +for (i =0 ; i <ZL3073X_NUM_SYNTHS ; i++) { + rc =zl3073x_synth_state_fetch (zldev, i); +if (rc) { +dev_err (zldev->dev, +"Failed to fetch synth state: %pe\n" , +ERR_PTR (rc)); +return rc; + } + } + +for (i =0 ; i <ZL3073X_NUM_OUTPUTS ; i++) { + rc =zl3073x_output_state_fetch (zldev, i); +if (rc) { +dev_err (zldev->dev, +"Failed to fetch output state: %pe\n" , +ERR_PTR (rc)); +return rc; + } + } + +return rc; +} +static void zl3073x_devlink_unregister (void *ptr) {devlink_unregister (ptr);
@@ -571,6 +817,11 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev,return dev_err_probe (zldev->dev, rc,"Failed to initialize mutex\n" ); +/* Fetch device state */ + rc =zl3073x_dev_state_fetch (zldev); +if (rc) +return rc; +/* Register the device as devlink device */ devlink =priv_to_devlink (zldev);devlink_register (devlink);
drivers/mfd/zl3073x-regs.h +37 -0
@@ -14,4 +14,41 @@#define ZL_REG_FW_VER ZL_REG(0, 0x05, 2)#define ZL_REG_CUSTOM_CONFIG_VER ZL_REG(0, 0x07, 4) +/*********************************** +* Register Page 9, Synth and Output +***********************************/ + +#define ZL_REG_SYNTH_CTRL (_idx) \ + ZL_REG_IDX(_idx, 9, 0x00, 1, ZL3073X_NUM_SYNTHS, 1) +#define ZL_SYNTH_CTRL_EN BIT(0) +#define ZL_SYNTH_CTRL_DPLL_SEL GENMASK(6, 4) + +#define ZL_REG_OUTPUT_CTRL (_idx) \ + ZL_REG_IDX(_idx, 9, 0x28, 1, ZL3073X_NUM_OUTPUTS, 1) +#define ZL_OUTPUT_CTRL_EN BIT(0) +#define ZL_OUTPUT_CTRL_SYNTH_SEL GENMASK(6, 4) + +/******************************* +* Register Page 10, Ref Mailbox +*******************************/ + +#define ZL_REG_REF_CONFIG ZL_REG(10, 0x0d, 1) +#define ZL_REF_CONFIG_ENABLE BIT(0) +#define ZL_REF_CONFIG_DIFF_EN BIT(2) + +/********************************* +* Register Page 13, Synth Mailbox +*********************************/ + +#define ZL_REG_SYNTH_MB_MASK ZL_REG(13, 0x02, 2) + +#define ZL_REG_SYNTH_MB_SEM ZL_REG(13, 0x04, 1) +#define ZL_SYNTH_MB_SEM_WR BIT(0) +#define ZL_SYNTH_MB_SEM_RD BIT(1) + +#define ZL_REG_SYNTH_FREQ_BASE ZL_REG(13, 0x06, 2) +#define ZL_REG_SYNTH_FREQ_MULT ZL_REG(13, 0x08, 4) +#define ZL_REG_SYNTH_FREQ_M ZL_REG(13, 0x0c, 2) +#define ZL_REG_SYNTH_FREQ_N ZL_REG(13, 0x0e, 2) +#endif /* __ZL3073X_REGS_H */
include/linux/mfd/zl3073x-regs.h +22 -0
@@ -63,4 +63,26 @@#define ZL_REG (_page, _offset, _size) \ ZL_REG_IDX(0, _page, _offset, _size, 1, 0) +/******************************* +* Register Page 10, Ref Mailbox +*******************************/ + +#define ZL_REG_REF_MB_MASK ZL_REG(10, 0x02, 2) + +#define ZL_REG_REF_MB_SEM ZL_REG(10, 0x04, 1) +#define ZL_REF_MB_SEM_WR BIT(0) +#define ZL_REF_MB_SEM_RD BIT(1) + +/********************************** +* Register Page 14, Output Mailbox +**********************************/ +#define ZL_REG_OUTPUT_MB_MASK ZL_REG(14, 0x02, 2) + +#define ZL_REG_OUTPUT_MB_SEM ZL_REG(14, 0x04, 1) +#define ZL_OUTPUT_MB_SEM_WR BIT(0) +#define ZL_OUTPUT_MB_SEM_RD BIT(1) + +#define ZL_REG_OUTPUT_MODE ZL_REG(14, 0x05, 1) +#define ZL_OUTPUT_MODE_SIGNAL_FORMAT GENMASK(7, 4) +#endif /* __LINUX_MFD_ZL3073X_REGS_H */
include/linux/mfd/zl3073x.h +153 -0
179 lines not on this page · raw message
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 7/8 mfd: zl3073x: Add clock_id field
In reply to Ivan VeceraAdd .clock_id to zl3073x_dev structure that will be used by later commits introducing DPLL driver. The clock ID is required for DPLL device registration.
To generate this ID, use chip ID read during device initialization. In case where multiple zl3073x based chips are present, the chip ID is shifted and lower bits are filled by an unique value - using the I2C device address for I2C connections and the chip-select value for SPI connections.
v5->v6:
* no change
--- drivers/mfd/zl3073x-core.c | 6 +++++- drivers/mfd/zl3073x-i2c.c | 4 +++- drivers/mfd/zl3073x-spi.c | 4 +++- drivers/mfd/zl3073x.h | 2 +- include/linux/mfd/zl3073x.h | 2 ++ 5 files changed, 14 insertions(+), 4 deletions(-)
drivers/mfd/zl3073x-core.c +5 -1
@@ -759,13 +759,14 @@ static void zl3073x_devlink_unregister(void *ptr)* zl3073x_dev_probe - initialize zl3073x device * @zldev: pointer to zl3073x device * @chip_info: chip info based on compatible +* @dev_id: device ID to be used as part of clock ID * * Common initialization of zl3073x device structure. * * Returns: 0 on success, <0 on error */ int zl3073x_dev_probe (struct zl3073x_dev *zldev, -const struct zl3073x_chip_info *chip_info) +const struct zl3073x_chip_info *chip_info,u8 dev_id) {u16 id, revision, fw_ver;struct devlink *devlink;
@@ -809,6 +810,9 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev,FIELD_GET (GENMASK (15 ,8 ), cfg_ver), FIELD_GET(GENMASK(7, 0), cfg_ver)); +/* Use chip ID and given dev ID as clock ID */ + zldev->clock_id = ((u64 )id <<8 ) | dev_id; +/* Initialize mutex for operations where multiple reads, writes * and/or polls are required to be done atomically. */
drivers/mfd/zl3073x-i2c.c +3 -1
@@ -27,7 +27,9 @@ static int zl3073x_i2c_probe(struct i2c_client *client)return PTR_ERR (zldev->regmap); } -return zl3073x_dev_probe (zldev,i2c_get_match_data (client)); +/* Initialize device and use I2C address as dev ID */ +return zl3073x_dev_probe (zldev,i2c_get_match_data (client), + client->addr); }static const struct i2c_device_id zl3073x_i2c_id[] = {
drivers/mfd/zl3073x-spi.c +3 -1
@@ -27,7 +27,9 @@ static int zl3073x_spi_probe(struct spi_device *spi)return PTR_ERR (zldev->regmap); } -return zl3073x_dev_probe (zldev,spi_get_device_match_data (spi)); +/* Initialize device and use SPI chip select value as dev ID */ +return zl3073x_dev_probe (zldev,spi_get_device_match_data (spi), +spi_get_chipselect (spi,0 )); }static const struct spi_device_id zl3073x_spi_id[] = {
drivers/mfd/zl3073x.h +1 -1
@@ -26,6 +26,6 @@ extern const struct zl3073x_chip_info zl3073x_chip_info[];struct zl3073x_dev *zl3073x_devm_alloc (struct device *dev);void zl3073x_dev_init_regmap_config (struct regmap_config *regmap_cfg);int zl3073x_dev_probe (struct zl3073x_dev *zldev, -const struct zl3073x_chip_info *chip_info); +const struct zl3073x_chip_info *chip_info,u8 dev_id);#endif /* __ZL3073X_CORE_H */
include/linux/mfd/zl3073x.h +2 -0
@@ -53,6 +53,7 @@ struct zl3073x_synth {* @dev: pointer to device * @regmap: regmap to access device registers * @multiop_lock: to serialize multiple register operations +* @clock_id: clock id of the device * @input: array of inputs' invariants * @output: array of outputs' invariants * @synth: array of synthesizers' invariants
@@ -61,6 +62,7 @@ struct zl3073x_dev {struct device *dev;struct regmap *regmap;struct mutex multiop_lock; +u64 clock_id;/* Invariants */ struct zl3073x_input input[ZL3073X_NUM_INPUTS ];
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v7 8/8 mfd: zl3073x: Register DPLL sub-device during init
In reply to Ivan VeceraRegister DPLL sub-devices to expose the functionality provided by ZL3073x chip family. Each sub-device represents one of the available DPLL channels.
---v6->v7:
* use platform data to pass the channel to usev4->v6:
* no changev3->v4:
* use static mfd cells
--- drivers/mfd/zl3073x-core.c | 30 ++++++++++++++++++++++++++++++ include/linux/mfd/zl3073x.h | 9 +++++++++ 2 files changed, 39 insertions(+)
drivers/mfd/zl3073x-core.c +30 -0
@@ -7,6 +7,7 @@#include <linux/device.h> #include <linux/export.h> #include <linux/math64.h> +#include <linux/mfd/core.h> #include <linux/mfd/zl3073x.h> #include <linux/module.h> #include <linux/netlink.h>
@@ -755,6 +756,26 @@ static void zl3073x_devlink_unregister(void *ptr)devlink_unregister (ptr); } +static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +}; + +#define ZL3073X_CELL (_name, _channel) \ + MFD_CELL_BASIC(_name, NULL, &zl3073x_pdata[_channel], \ + sizeof(struct zl3073x_pdata), 0) + +static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +/** * zl3073x_dev_probe - initialize zl3073x device * @zldev: pointer to zl3073x device
@@ -826,6 +847,15 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev,if (rc)return rc; +/* Add DPLL sub-device cell for each DPLL channel */ + rc =devm_mfd_add_devices (zldev->dev,PLATFORM_DEVID_AUTO , zl3073x_devs, + chip_info->num_channels,NULL ,0 ,NULL ); +if (rc) { +dev_err_probe (zldev->dev, rc, +"Failed to add DPLL sub-device\n" ); +return rc; + } +/* Register the device as devlink device */ devlink =priv_to_devlink (zldev);devlink_register (devlink);
include/linux/mfd/zl3073x.h +9 -0
@@ -12,6 +12,7 @@ struct regmap;/* * Hardware limits for ZL3073x chip family */ +#define ZL3073X_MAX_CHANNELS 5#define ZL3073X_NUM_INPUTS 10#define ZL3073X_NUM_OUTPUTS 10#define ZL3073X_NUM_SYNTHS 5
@@ -48,6 +49,14 @@ struct zl3073x_synth {u8 dpll; }; +/** +* struct zl3073x_pdata - zl3073x sub-device platform data +* @channel: channel to use +*/ +struct zl3073x_pdata { +u8 channel; +}; +/** * struct zl3073x_dev - zl3073x device * @dev: pointer to device
Signature · 1 line
2.49.0
Re: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 4 lines · Ivan Vecera
Register DPLL sub-devices to expose the functionality provided by ZL3073x chip family. Each sub-device represents one of the available DPLL channels.
...
include/linux/mfd/zl3073x.h struct zl3073x_synth { · line 58
Quoted 7 lines
include/linux/mfd/zl3073x.h +7
-0+/** +* struct zl3073x_pdata - zl3073x sub-device platform data +* @channel: channel to use +*/ +struct zl3073x_pdata { +u8 channel; +};
You can also use software nodes (via device properties).
But since the current solution doesn't require any additional files or something like that, I don't care much.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
In reply to Ivan VeceraQuoted 4 lines · Ivan Vecera
Register DPLL sub-devices to expose the functionality provided by ZL3073x chip family. Each sub-device represents one of the available DPLL channels.
...
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};
drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5
Btw, wouldn't be better to keep the above lists synchronised like
1. Make ZL3073X_CELL() to use indexed variant
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
--
With Best Regards,
Andy Shevchenko
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 30 lines · Andy Shevchenko
Quoted 4 lines · Ivan Vecera
Register DPLL sub-devices to expose the functionality provided by ZL3073x chip family. Each sub-device represents one of the available DPLL channels.
...
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variant
Quoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
static const struct mfd_cell zl3073x_devs[] = {
ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0
ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0
ZL3073X_CELL("zl3073x-dpll", 1), // ...
ZL3073X_CELL("zl3073x-phc", 1),
ZL3073X_CELL("zl3073x-dpll", 2),
ZL3073X_CELL("zl3073x-phc", 2),
ZL3073X_CELL("zl3073x-dpll", 3),
ZL3073X_CELL("zl3073x-phc", 3),
ZL3073X_CELL("zl3073x-dpll", 4),
ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4
};Ivan
Re: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = {
ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0
ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0
ZL3073X_CELL("zl3073x-dpll", 1), // ...
ZL3073X_CELL("zl3073x-phc", 1),
ZL3073X_CELL("zl3073x-dpll", 2),
ZL3073X_CELL("zl3073x-phc", 2),
ZL3073X_CELL("zl3073x-dpll", 3),
ZL3073X_CELL("zl3073x-phc", 3),
ZL3073X_CELL("zl3073x-dpll", 4),
ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4
};Ah, this is very important piece. Then I mean only this kind of change
enum {
// this or whatever meaningful names
..._CH_0 0
..._CH_1 1
...
};static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = {
{ .channel = ..._CH_0, },
...
};static const struct mfd_cell zl3073x_devs[] = {
ZL3073X_CELL("zl3073x-dpll", ..._CH_0),
ZL3073X_CELL("zl3073x-phc", ..._CH_0),
...
};Signature · 2 lines
With Best Regards, Andy Shevchenko
Lee Jones
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };
Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = {
ZL3073X_CELL("zl3073x-dpll", ..._CH_0),
ZL3073X_CELL("zl3073x-phc", ..._CH_0),
...
};This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Signature · 1 line
Lee Jones [李琼斯]
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 79 lines · Lee Jones
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };
Quoted 3 lines
This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
For that, there have to be two IDAs, one for DPLLs and one for PHCs... The approach in my second reply in this thread is simpler and taken in v8.
<cite>
+#define ZL3073X_PDATA(_channel) \
+ (&(const struct zl3073x_pdata) { \
+ .channel = _channel, \
+ })
+
+#define ZL3073X_CELL(_name, _channel) \
+ MFD_CELL_BASIC(_name, NULL, ZL3073X_PDATA(_channel), \
+ sizeof(struct zl3073x_pdata), 0)
+
+static const struct mfd_cell zl3073x_devs[] = {
+ ZL3073X_CELL("zl3073x-dpll", 0),
+ ZL3073X_CELL("zl3073x-dpll", 1),
+ ZL3073X_CELL("zl3073x-dpll", 2),
+ ZL3073X_CELL("zl3073x-dpll", 3),
+ ZL3073X_CELL("zl3073x-dpll", 4),
+};
</cite>
Lee, WDYT?
Thanks,
Ivan
Lee Jones
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 80 lines · Ivan Vecera
Quoted 79 lines · Lee Jones
Quoted 76 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };
Quoted 5 lines
Quoted 3 lines
This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
Quoted 27 lines
The approach in my second reply in this thread is simpler and taken in v8.
<cite>
drivers/mfd/zl3073x-core.c +16
-0+#define ZL3073X_PDATA (_channel) \ + (&(const struct zl3073x_pdata) { \ + .channel = _channel, \ + }) + +#define ZL3073X_CELL (_name, _channel) \ + MFD_CELL_BASIC(_name, NULL, ZL3073X_PDATA(_channel), \ + sizeof(struct zl3073x_pdata), 0) + +static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +};</cite>
Lee, WDYT?
Thanks,
Ivan
Signature · 1 line
Lee Jones [李琼斯]
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 86 lines · Lee Jones
Quoted 84 lines · Ivan Vecera
Quoted 82 lines · Lee Jones
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
(quoted diff) +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { + { .channel = 0, }, + { .channel = 1, }, + { .channel = 2, }, + { .channel = 3, }, + { .channel = 4, }, +};Review
Quoted 10 lines
(quoted diff) +8
-0+static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Quoted 7 lines
Quoted 1 line
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
I will try to explain this in more detail... This MFD driver handles chip family ZL3073x where the x == number of DPLL channels and can be from <1, 5>.
The driver creates 'x' DPLL sub-devices during probe and has to pass channel number that should this sub-device use. Here can be used IDA in DPLL sub-driver:
e.g. ida_alloc_max(zldev->channels, zldev->max_channels, GFP_KERNEL);
This way the DPLL sub-device get its own unique channel ID to use.
The situation is getting more complicated with PHC sub-devices because the chip can provide UP TO 'x' PHC sub-devices depending on HW configuration. To handle this the MFD driver has to check this HW config for particular channel if it is capable to provide PHC functionality.
E.g. ZL30735 chip has 5 channels, in this case the MFD driver should create 5 DPLL sub-devices. And then lets say channel 0, 2 and 4 are PHC capable. Then the MFD driver should create 3 PHC sub-devices and pass 0, 2 resp. 4 for them.
In that case IDA cannot be simply used as the allocation is not sequential.
So yes, for DPLL sub-devices IDA could be used but for the PHCs another approach (platform data) has to be used.
There could be a hacky way to use IDA for PHCs: MFD would create PHC sub-devices for all channels and PHC sub-driver would check the channel config during probe and if the channel is not capable then returns -ENODEV. But I don't think this is good idea to create MFD cells this way.
Thanks for advices.
Ivan
Quoted 28 lines
Quoted 27 lines
The approach in my second reply in this thread is simpler and taken in v8.
<cite>
(quoted diff) +16
-0+#define ZL3073X_PDATA(_channel) \ + (&(const struct zl3073x_pdata) { \ + .channel = _channel, \ + }) + +#define ZL3073X_CELL(_name, _channel) \ + MFD_CELL_BASIC(_name, NULL, ZL3073X_PDATA(_channel), \ + sizeof(struct zl3073x_pdata), 0) + +static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +};</cite>
Lee, WDYT?
Thanks,
Ivan
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 129 lines · Ivan Vecera
Quoted 87 lines · Lee Jones
Quoted 85 lines · Ivan Vecera
Quoted 83 lines · Lee Jones
Quoted 72 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 37 lines
Quoted 23 lines
Quoted 8 lines
+static const struct
zl3073x_pdata
zl3073x_pdata[ZL3073X_MAX_CHANNELS] = {
+ { .channel = 0, },
+ { .channel = 1, },
+ { .channel = 2, },
+ { .channel = 3, },
+ { .channel = 4, },(quoted diff) +1
-0+};Review
Quoted 10 lines
(quoted diff) +8
-0+static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Quoted 14 lines
Just a note that after introduction of PHC sub-driver the array will look like:
static const structmfd_cellzl3073x_devs[] = {ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0ZL3073X_CELL("zl3073x-dpll", 1), // ...ZL3073X_CELL("zl3073x-phc", 1),ZL3073X_CELL("zl3073x-dpll", 2),ZL3073X_CELL("zl3073x-phc", 2),ZL3073X_CELL("zl3073x-dpll", 3),ZL3073X_CELL("zl3073x-phc", 3),ZL3073X_CELL("zl3073x-dpll", 4),ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum {
// this or whatever meaningful names
..._CH_0 0
..._CH_1 1
...
};static const struct
zl3073x_pdatazl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, },
...
};Quoted 5 lines
static const struct
mfd_cellzl3073x_devs[] = {
ZL3073X_CELL("zl3073x-dpll", ..._CH_0),
ZL3073X_CELL("zl3073x-phc", ..._CH_0),
...
};This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Quoted 7 lines
Quoted 1 line
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
I will try to explain this in more detail... This MFD driver handles chip family ZL3073x where the x == number of DPLL channels and can be from <1, 5>.
The driver creates 'x' DPLL sub-devices during probe and has to pass channel number that should this sub-device use. Here can be used IDA in DPLL sub-driver:
e.g.ida_alloc_max(zldev->channels, zldev->max_channels, GFP_KERNEL);This way the DPLL sub-device get its own unique channel ID to use.
The situation is getting more complicated with PHC sub-devices because the chip can provide UP TO 'x' PHC sub-devices depending on HW configuration. To handle this the MFD driver has to check this HW config for particular channel if it is capable to provide PHC functionality.
E.g. ZL30735 chip has 5 channels, in this case the MFD driver should create 5 DPLL sub-devices. And then lets say channel 0, 2 and 4 are PHC capable. Then the MFD driver should create 3 PHC sub-devices and pass 0, 2 resp. 4 for them.
In that case IDA cannot be simply used as the allocation is not sequential.
So yes, for DPLL sub-devices IDA could be used but for the PHCs another approach (platform data) has to be used.
There could be a hacky way to use IDA for PHCs: MFD would create PHC sub-devices for all channels and PHC sub-driver would check the channel config during probe and if the channel is not capable then returns
-ENODEV. But I don't think this is good idea to create MFD cells this way.
Quoted 3 lines
Thanks for advices.
Ivan
Lee, any comment? What about my proposal in v8?
Thanks,
Ivan
Lee Jones
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
In reply to Ivan VeceraQuoted 111 lines · Ivan Vecera
Quoted 86 lines · Lee Jones
Quoted 84 lines · Ivan Vecera
Quoted 82 lines · Lee Jones
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
(quoted diff) +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { + { .channel = 0, }, + { .channel = 1, }, + { .channel = 2, }, + { .channel = 3, }, + { .channel = 4, }, +};Review
Quoted 10 lines
(quoted diff) +8
-0+static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Quoted 7 lines
Quoted 1 line
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
I will try to explain this in more detail... This MFD driver handles chip family ZL3073x where the x == number of DPLL channels and can be from <1, 5>.
The driver creates 'x' DPLL sub-devices during probe and has to pass channel number that should this sub-device use. Here can be used IDA in DPLL sub-driver:
e.g.ida_alloc_max(zldev->channels, zldev->max_channels, GFP_KERNEL);This way the DPLL sub-device get its own unique channel ID to use.
The situation is getting more complicated with PHC sub-devices because the chip can provide UP TO 'x' PHC sub-devices depending on HW configuration. To handle this the MFD driver has to check this HW config for particular channel if it is capable to provide PHC functionality.
Quoted 4 lines
E.g. ZL30735 chip has 5 channels, in this case the MFD driver should create 5 DPLL sub-devices. And then lets say channel 0, 2 and 4 are PHC capable. Then the MFD driver should create 3 PHC sub-devices and pass 0, 2 resp. 4 for them.
Where is the code that determines which channels are PHC capable?
Signature · 1 line
Lee Jones [李琼斯]
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 113 lines · Lee Jones
Quoted 111 lines · Ivan Vecera
Quoted 86 lines · Lee Jones
Quoted 84 lines · Ivan Vecera
Quoted 82 lines · Lee Jones
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
(quoted diff) +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { + { .channel = 0, }, + { .channel = 1, }, + { .channel = 2, }, + { .channel = 3, }, + { .channel = 4, }, +};Review
Quoted 10 lines
(quoted diff) +8
-0+static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Quoted 7 lines
Quoted 1 line
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
I will try to explain this in more detail... This MFD driver handles chip family ZL3073x where the x == number of DPLL channels and can be from <1, 5>.
The driver creates 'x' DPLL sub-devices during probe and has to pass channel number that should this sub-device use. Here can be used IDA in DPLL sub-driver:
e.g.ida_alloc_max(zldev->channels, zldev->max_channels, GFP_KERNEL);This way the DPLL sub-device get its own unique channel ID to use.
The situation is getting more complicated with PHC sub-devices because the chip can provide UP TO 'x' PHC sub-devices depending on HW configuration. To handle this the MFD driver has to check this HW config for particular channel if it is capable to provide PHC functionality.
Quoted 6 lines
Quoted 4 lines
E.g. ZL30735 chip has 5 channels, in this case the MFD driver should create 5 DPLL sub-devices. And then lets say channel 0, 2 and 4 are PHC capable. Then the MFD driver should create 3 PHC sub-devices and pass 0, 2 resp. 4 for them.
Where is the code that determines which channels are PHC capable?
It is not included in this series and will be added once the PTP driver will be added. But the code looks like:
for (i = 0; i < ZL3073X_MAX_CHANNELS; i++) {
if (channel_is_in_nco_mode(..., i)) {
struct mfd_cell phc_dev = ZL3073X_CELL("zl3073x-phc", i);
rc = devm_mfd_add_devices(zldev->dev,
PLATFORM_DEVID_AUTO, &phc_dev,
1, NULL, 0, NULL);
...
}
}Thanks,
Ivan
Lee Jones
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 126 lines · Ivan Vecera
Quoted 113 lines · Lee Jones
Quoted 111 lines · Ivan Vecera
Quoted 86 lines · Lee Jones
Quoted 84 lines · Ivan Vecera
Quoted 82 lines · Lee Jones
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
(quoted diff) +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { + { .channel = 0, }, + { .channel = 1, }, + { .channel = 2, }, + { .channel = 3, }, + { .channel = 4, }, +};Review
Quoted 10 lines
(quoted diff) +8
-0+static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Quoted 7 lines
Quoted 1 line
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
I will try to explain this in more detail... This MFD driver handles chip family ZL3073x where the x == number of DPLL channels and can be from <1, 5>.
The driver creates 'x' DPLL sub-devices during probe and has to pass channel number that should this sub-device use. Here can be used IDA in DPLL sub-driver:
e.g.ida_alloc_max(zldev->channels, zldev->max_channels, GFP_KERNEL);This way the DPLL sub-device get its own unique channel ID to use.
The situation is getting more complicated with PHC sub-devices because the chip can provide UP TO 'x' PHC sub-devices depending on HW configuration. To handle this the MFD driver has to check this HW config for particular channel if it is capable to provide PHC functionality.
Quoted 6 lines
Quoted 4 lines
E.g. ZL30735 chip has 5 channels, in this case the MFD driver should create 5 DPLL sub-devices. And then lets say channel 0, 2 and 4 are PHC capable. Then the MFD driver should create 3 PHC sub-devices and pass 0, 2 resp. 4 for them.
Where is the code that determines which channels are PHC capable?
It is not included in this series and will be added once the PTP driver will be added. But the code looks like:
Quoted 9 lines
for (i = 0; i < ZL3073X_MAX_CHANNELS; i++) {
if (channel_is_in_nco_mode(..., i)) {
struct mfd_cell phc_dev = ZL3073X_CELL("zl3073x-phc", i);
rc = devm_mfd_add_devices(zldev->dev,
PLATFORM_DEVID_AUTO, &phc_dev,
1, NULL, 0, NULL);
...
}
}It's the channel_is_in_nco_mode() code I wanted to see.
What if you register all PHC devices, then bomb out if !channel_is_in_nco_mode()? Presumably this can / should also live in the PHC driver as well?
Signature · 1 line
Lee Jones [李琼斯]
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 138 lines · Lee Jones
Quoted 126 lines · Ivan Vecera
Quoted 113 lines · Lee Jones
Quoted 111 lines · Ivan Vecera
Quoted 86 lines · Lee Jones
Quoted 84 lines · Ivan Vecera
Quoted 82 lines · Lee Jones
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
(quoted diff) +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { + { .channel = 0, }, + { .channel = 1, }, + { .channel = 2, }, + { .channel = 3, }, + { .channel = 4, }, +};Review
Quoted 10 lines
(quoted diff) +8
-0+static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Quoted 7 lines
Quoted 1 line
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
I will try to explain this in more detail... This MFD driver handles chip family ZL3073x where the x == number of DPLL channels and can be from <1, 5>.
The driver creates 'x' DPLL sub-devices during probe and has to pass channel number that should this sub-device use. Here can be used IDA in DPLL sub-driver:
e.g.ida_alloc_max(zldev->channels, zldev->max_channels, GFP_KERNEL);This way the DPLL sub-device get its own unique channel ID to use.
The situation is getting more complicated with PHC sub-devices because the chip can provide UP TO 'x' PHC sub-devices depending on HW configuration. To handle this the MFD driver has to check this HW config for particular channel if it is capable to provide PHC functionality.
Quoted 6 lines
Quoted 4 lines
E.g. ZL30735 chip has 5 channels, in this case the MFD driver should create 5 DPLL sub-devices. And then lets say channel 0, 2 and 4 are PHC capable. Then the MFD driver should create 3 PHC sub-devices and pass 0, 2 resp. 4 for them.
Where is the code that determines which channels are PHC capable?
It is not included in this series and will be added once the PTP driver will be added. But the code looks like:
Quoted 9 lines
for (i = 0; i < ZL3073X_MAX_CHANNELS; i++) { if (channel_is_in_nco_mode(..., i)) { struct mfd_cell phc_dev = ZL3073X_CELL("zl3073x-phc", i); rc = devm_mfd_add_devices(zldev->dev, PLATFORM_DEVID_AUTO, &phc_dev, 1, NULL, 0, NULL); ... } }
Quoted 1 line
It's the
channel_is_in_nco_mode()code I wanted to see.
The function is like this:
static bool zl3073x_chan_in_nco_mode(struct zl3073x_dev *zldev, u8 ch)
{
u8 mode, mode_refsel;
int rc;
rc = zl3073x_read_u8(zlptp->mfd,
ZL_REG_DPLL_MODE_REFSEL(ch), &mode_refsel);
if (rc)
return false;
mode = FIELD_GET(ZL_DPLL_MODE_REFSEL_MODE, mode_refsel);
return (mode == ZL_DPLL_MODE_REFSEL_MODE_NCO);
}Quoted 3 lines
What if you register all PHC devices, then bomb out if !channel_is_in_nco_mode()? Presumably this can / should also live in the PHC driver as well?
Yes, we can register PHC sub-dev for all channels disregard to channel mode. The PHC driver checks for the mode and return -ENODEV when it is different from NCO. But in this case the user will see PHC platform devices under /sys/bus/platform/device and some of them won't have driver bound (they will look like some kind of phantom devices). I'm not sure if this is OK and not confusing.
Thanks for an opinion.
Ivan
Lee Jones
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 162 lines · Ivan Vecera
Quoted 138 lines · Lee Jones
Quoted 126 lines · Ivan Vecera
Quoted 113 lines · Lee Jones
Quoted 111 lines · Ivan Vecera
Quoted 86 lines · Lee Jones
Quoted 84 lines · Ivan Vecera
Quoted 82 lines · Lee Jones
Quoted 71 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 38 lines
Quoted 22 lines
Quoted 7 lines
(quoted diff) +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { + { .channel = 0, }, + { .channel = 1, }, + { .channel = 2, }, + { .channel = 3, }, + { .channel = 4, }, +};Review
Quoted 10 lines
(quoted diff) +8
-0+static const struct mfd_cell zl3073x_devs[] = { + ZL3073X_CELL("zl3073x-dpll", 0), + ZL3073X_CELL("zl3073x-dpll", 1), + ZL3073X_CELL("zl3073x-dpll", 2), + ZL3073X_CELL("zl3073x-dpll", 3), + ZL3073X_CELL("zl3073x-dpll", 4), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
1. Make
ZL3073X_CELL()to use indexed variantQuoted 7 lines
[idx] = ...
2. Define the channel numbers
and use them in both data structures.
...
WDYM?
Quoted 3 lines
OTOH, I'm not sure why we even need this. If this is going to be sequential, can't we make a core to decide which cell will be given which id?
Just a note that after introduction of PHC sub-driver the array will look like:
Quoted 12 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", 0), // DPLL sub-dev for chan 0 ZL3073X_CELL("zl3073x-phc", 0), // PHC sub-dev for chan 0 ZL3073X_CELL("zl3073x-dpll", 1), // ... ZL3073X_CELL("zl3073x-phc", 1), ZL3073X_CELL("zl3073x-dpll", 2), ZL3073X_CELL("zl3073x-phc", 2), ZL3073X_CELL("zl3073x-dpll", 3), ZL3073X_CELL("zl3073x-phc", 3), ZL3073X_CELL("zl3073x-dpll", 4), ZL3073X_CELL("zl3073x-phc", 4), // PHC sub-dev for chan 4 };Ah, this is very important piece. Then I mean only this kind of change
enum { // this or whatever meaningful names ..._CH_0 0 ..._CH_1 1 ... };static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS] = { { .channel = ..._CH_0, }, ... };Quoted 5 lines
static const struct mfd_cell zl3073x_devs[] = { ZL3073X_CELL("zl3073x-dpll", ..._CH_0), ZL3073X_CELL("zl3073x-phc", ..._CH_0), ... };This is getting hectic. All for a sequential enumeration. Seeing as there are no other differentiations, why not use IDA in the child instead?
Quoted 7 lines
Quoted 1 line
For that, there have to be two IDAs, one for DPLLs and one for PHCs...
Sorry, can you explain a bit more. Why is this a problem?
The IDA API is very simple.
Much better than building your own bespoke MACROs.
I will try to explain this in more detail... This MFD driver handles chip family ZL3073x where the x == number of DPLL channels and can be from <1, 5>.
The driver creates 'x' DPLL sub-devices during probe and has to pass channel number that should this sub-device use. Here can be used IDA in DPLL sub-driver:
e.g.ida_alloc_max(zldev->channels, zldev->max_channels, GFP_KERNEL);This way the DPLL sub-device get its own unique channel ID to use.
The situation is getting more complicated with PHC sub-devices because the chip can provide UP TO 'x' PHC sub-devices depending on HW configuration. To handle this the MFD driver has to check this HW config for particular channel if it is capable to provide PHC functionality.
Quoted 6 lines
Quoted 4 lines
E.g. ZL30735 chip has 5 channels, in this case the MFD driver should create 5 DPLL sub-devices. And then lets say channel 0, 2 and 4 are PHC capable. Then the MFD driver should create 3 PHC sub-devices and pass 0, 2 resp. 4 for them.
Where is the code that determines which channels are PHC capable?
It is not included in this series and will be added once the PTP driver will be added. But the code looks like:
Quoted 9 lines
for (i = 0; i < ZL3073X_MAX_CHANNELS; i++) { if (channel_is_in_nco_mode(..., i)) { struct mfd_cell phc_dev = ZL3073X_CELL("zl3073x-phc", i); rc = devm_mfd_add_devices(zldev->dev, PLATFORM_DEVID_AUTO, &phc_dev, 1, NULL, 0, NULL); ... } }Quoted 1 line
It's the
channel_is_in_nco_mode()code I wanted to see.The function is like this:
static bool
zl3073x_chan_in_nco_mode(struct zl3073x_dev *zldev, u8 ch){ u8 mode, mode_refsel; int rc; rc = zl3073x_read_u8(zlptp->mfd, ZL_REG_DPLL_MODE_REFSEL(ch), &mode_refsel); if (rc) return false; mode = FIELD_GET(ZL_DPLL_MODE_REFSEL_MODE, mode_refsel); return (mode == ZL_DPLL_MODE_REFSEL_MODE_NCO); }Quoted 3 lines
What if you register all PHC devices, then bomb out if !channel_is_in_nco_mode()? Presumably this can / should also live in the PHC driver as well?
Quoted 6 lines
Yes, we can register PHC sub-dev for all channels disregard to channel mode. The PHC driver checks for the mode and return
-ENODEVwhen it is different from NCO. But in this case the user will see PHC platform devices under/sys/bus/platform/deviceand some of them won't have driver bound (they will look like some kind of phantom devices). I'm not sure if this is OK and not confusing.
There will be plenty of devices which do not successfully probe for one reason or another. This is all that these 'phantom devices' will indicate.
Signature · 1 line
Lee Jones [李琼斯]
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
In reply to Andy ShevchenkoQuoted 28 lines · Andy Shevchenko
Quoted 4 lines · Ivan Vecera
Register DPLL sub-devices to expose the functionality provided by ZL3073x chip family. Each sub-device represents one of the available DPLL channels.
...
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
Quoted 8 lines
1. Make
ZL3073X_CELL()to use indexed variant[idx] = ...
2. Define the channel numbers
and use them in both data structures.
It could be possible to drop zl3073x_pdata array and modify ZL3073X_CELL this way:
#define ZL3073X_CHANNEL(_channel) \
&(const struct zl3073x_pdata) { .channel = _channel }#define ZL3073X_CELL(_name, _channel) \
MFD_CELL_BASIC(_name, NULL, ZL3073X_CHANNEL(_channel), \
sizeof(struct zl3073x_pdata), 0)WDYT?
Ivan
Re: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 31 lines
Quoted 20 lines
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
Quoted 8 lines
1. Make
ZL3073X_CELL()to use indexed variant[idx] = ...
2. Define the channel numbers
and use them in both data structures.
It could be possible to drop
zl3073x_pdataarray and modifyZL3073X_CELLthis way:
Quoted 8 lines
#define ZL3073X_CHANNEL(_channel) \ &(const struct zl3073x_pdata) { .channel = _channel }#define ZL3073X_CELL(_name, _channel) \ MFD_CELL_BASIC(_name, NULL, ZL3073X_CHANNEL(_channel), \ sizeof(struct zl3073x_pdata), 0)WDYT?
Fine with me as it looks not ugly and addresses my point.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ivan Vecera
maintainerRe: [PATCH net-next v7 8/8] mfd: zl3073x: Register DPLL sub-device during init
Quoted 40 lines · Andy Shevchenko
Quoted 2 lines · Ivan Vecera
Quoted 1 line · Andy Shevchenko
On Wed, May 7, 2025 at 3:45 PM Ivan Vecera <[email protected]> wrote:
...
Quoted 34 lines
Quoted 20 lines
Quoted 7 lines
drivers/mfd/zl3073x-core.c +7
-0+static const struct zl3073x_pdata zl3073x_pdata[ZL3073X_MAX_CHANNELS ] = { + { .channel =0 , }, + { .channel =1 , }, + { .channel =2 , }, + { .channel =3 , }, + { .channel =4 , }, +};drivers/mfd/zl3073x-core.c static void zl3073x_devlink_unregister(void *ptr)
Quoted 10 lines
drivers/mfd/zl3073x-core.c +8
-0+static const struct mfd_cell zl3073x_devs[] = { +ZL3073X_CELL ("zl3073x-dpll" ,0 ), +ZL3073X_CELL ("zl3073x-dpll" ,1 ), +ZL3073X_CELL ("zl3073x-dpll" ,2 ), +ZL3073X_CELL ("zl3073x-dpll" ,3 ), +ZL3073X_CELL ("zl3073x-dpll" ,4 ), +}; +#define ZL3073X_MAX_CHANNELS 5Btw, wouldn't be better to keep the above lists synchronised like
Quoted 8 lines
1. Make
ZL3073X_CELL()to use indexed variant[idx] = ...
2. Define the channel numbers
and use them in both data structures.
It could be possible to drop
zl3073x_pdataarray and modifyZL3073X_CELLthis way:#define ZL3073X_CHANNEL(_channel) \ &(const struct zl3073x_pdata) { .channel = _channel }
Quoted 8 lines
Quoted 5 lines
#define ZL3073X_CELL(_name, _channel) \ MFD_CELL_BASIC(_name, NULL, ZL3073X_CHANNEL(_channel), \ sizeof(struct zl3073x_pdata), 0)WDYT?
Fine with me as it looks not ugly and addresses my point.
Will submit v8 shortly..
Thanks for review and advice.
Ivan