Add Microchip ZL3073x support (part 1)
Subsystems (7)
Ivan Vecera
maintainerv13 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 core functionality and basic DPLL support.
The next part of the series will bring additional DPLL functionality like eSync support, phase offset and frequency offset reporting and phase adjustments.
Testing was done by myself and by Prathosh Satish on Microchip EDS2 development board with ZL30732 DPLL chip connected over I2C bus.
---
Changelog:
v13:
* added support for u64 devlink parameters
* added support for generic devlink parameter 'clock_id'
* several patches squashed into one per @jpirko's advice
* renamed devlink version 'cfg.custom_ver' to 'custom_cfg'
* per discussion with @jpirko, the clock_id is now generated randomly and user have an option to change it via devlink
* implemented devlink reload to apply clock_id change
v12:
* Using 'return dev_err_probe()'
* Separate zl3073x_chip_info structures instead of array
* Use mul_u64_u32_div() to compute input reference frequency to avoid potential overflow
* Removed superfluous check in zl3073x_dpll_output_pin_frequency_set()
v11:
* Fixed uninitialized 'rc' in error-path in patch 9
v10:
* Usage of str_enabled_disabled() where possible.
v9:
After discussion with Jakub Kicinski we agreed that it would be better to implement whole functionality in a single driver without touching MFD sub-system. Besides touching multiple sub-systems by single device there are also some technical issues that are easier resolvable in a single driver. Additionally the firmware flashing functionality would bring more than 1000 lines of code with previous approach to the MFD driver - it is not something the MFD maintainers would like to see.
Ivan Vecera (12):
dt-bindings: dpll: Add DPLL device and pin
dt-bindings: dpll: Add support for Microchip Azurite chip family
devlink: Add support for u64 parameters
devlink: Add new "clock_id" generic device param
dpll: Add basic Microchip ZL3073x support
dpll: zl3073x: Fetch invariants during probe
dpll: zl3073x: Read DPLL types and pin properties from system firmware
dpll: zl3073x: Register DPLL devices and pins
dpll: zl3073x: Implement input pin selection in manual mode
dpll: zl3073x: Add support to get/set priority on input pins
dpll: zl3073x: Implement input pin state setting in automatic mode
dpll: zl3073x: Add support to get/set frequency on pins
.../devicetree/bindings/dpll/dpll-device.yaml | 76 + .../devicetree/bindings/dpll/dpll-pin.yaml | 45 + .../bindings/dpll/microchip,zl30731.yaml | 115 ++ .../networking/devlink/devlink-params.rst | 3 + Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/zl3073x.rst | 51 + MAINTAINERS | 10 + drivers/Kconfig | 4 +- drivers/dpll/Kconfig | 6 + drivers/dpll/Makefile | 2 + drivers/dpll/zl3073x/Kconfig | 36 + drivers/dpll/zl3073x/Makefile | 10 + drivers/dpll/zl3073x/core.c | 859 ++++++++++ drivers/dpll/zl3073x/core.h | 367 ++++ drivers/dpll/zl3073x/devlink.c | 259 +++ drivers/dpll/zl3073x/devlink.h | 12 + drivers/dpll/zl3073x/dpll.c | 1504 +++++++++++++++++ drivers/dpll/zl3073x/dpll.h | 42 + drivers/dpll/zl3073x/i2c.c | 76 + drivers/dpll/zl3073x/prop.c | 358 ++++ drivers/dpll/zl3073x/prop.h | 34 + drivers/dpll/zl3073x/regs.h | 208 +++ drivers/dpll/zl3073x/spi.c | 76 + include/net/devlink.h | 6 + net/devlink/param.c | 15 + 25 files changed, 4173 insertions(+), 2 deletions(-) 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/dpll/zl3073x/Kconfig create mode 100644 drivers/dpll/zl3073x/Makefile create mode 100644 drivers/dpll/zl3073x/core.c create mode 100644 drivers/dpll/zl3073x/core.h create mode 100644 drivers/dpll/zl3073x/devlink.c create mode 100644 drivers/dpll/zl3073x/devlink.h create mode 100644 drivers/dpll/zl3073x/dpll.c create mode 100644 drivers/dpll/zl3073x/dpll.h create mode 100644 drivers/dpll/zl3073x/i2c.c create mode 100644 drivers/dpll/zl3073x/prop.c create mode 100644 drivers/dpll/zl3073x/prop.h create mode 100644 drivers/dpll/zl3073x/regs.h create mode 100644 drivers/dpll/zl3073x/spi.c
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 1/12 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
--- .../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
@@ -7324,6 +7324,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 v13 2/12 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.
--- .../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 v13 3/12 devlink: Add support for u64 parameters
In reply to Ivan VeceraOnly 8, 16 and 32-bit integers are supported for numeric devlink parameters. The subsequent patch adds support for DPLL clock ID that is defined as 64-bit number. Add support for u64 parameter type.
--- include/net/devlink.h | 2 ++ net/devlink/param.c | 10 ++++++++++ 2 files changed, 12 insertions(+)
include/net/devlink.h +2 -0
@@ -423,6 +423,7 @@ enum devlink_param_type {DEVLINK_PARAM_TYPE_U8 =DEVLINK_VAR_ATTR_TYPE_U8 ,DEVLINK_PARAM_TYPE_U16 =DEVLINK_VAR_ATTR_TYPE_U16 ,DEVLINK_PARAM_TYPE_U32 =DEVLINK_VAR_ATTR_TYPE_U32 , +DEVLINK_PARAM_TYPE_U64 =DEVLINK_VAR_ATTR_TYPE_U64 ,DEVLINK_PARAM_TYPE_STRING =DEVLINK_VAR_ATTR_TYPE_STRING , DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG, };
@@ -431,6 +432,7 @@ union devlink_param_value {u8 vu8;u16 vu16;u32 vu32; +u64 vu64;char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];bool vbool; };
net/devlink/param.c +10 -0
@@ -200,6 +200,11 @@ devlink_nl_param_value_fill_one(struct sk_buff *msg,if (nla_put_u32 (msg,DEVLINK_ATTR_PARAM_VALUE_DATA , val.vu32)) goto value_nest_cancel;break ; +case DEVLINK_PARAM_TYPE_U64 : +if (devlink_nl_put_u64 (msg,DEVLINK_ATTR_PARAM_VALUE_DATA , + val.vu64)) + goto value_nest_cancel; +break ;case DEVLINK_PARAM_TYPE_STRING :if (nla_put_string (msg,DEVLINK_ATTR_PARAM_VALUE_DATA , val.vstr))
@@ -434,6 +439,11 @@ devlink_param_value_get_from_info(const struct devlink_param *param,return -EINVAL ; value->vu32 =nla_get_u32 (param_data);break ; +case DEVLINK_PARAM_TYPE_U64 : +if (nla_len (param_data) !=sizeof (u64)) +return -EINVAL ; + value->vu64 =nla_get_u64 (param_data); +break ;case DEVLINK_PARAM_TYPE_STRING : len =strnlen (nla_data (param_data),nla_len (param_data)); if (len == nla_len(param_data) ||
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 4/12 devlink: Add new "clock_id" generic device param
In reply to Ivan VeceraAdd a new device generic parameter to specify clock ID that should be used by the device for registering DPLL devices and pins.
--- Documentation/networking/devlink/devlink-params.rst | 3 +++ include/net/devlink.h | 4 ++++ net/devlink/param.c | 5 +++++ 3 files changed, 12 insertions(+)
Documentation/networking/devlink/devlink-params.rst +3 -0
@@ -140,3 +140,6 @@ own name. * - ``enable_phc`` - Boolean - Enable PHC (PTP Hardware Clock) functionality in the device. + * - ``clock_id`` + - u64 + - Clock ID used by the device for registering DPLL devices and pins.
include/net/devlink.h +4 -0
@@ -523,6 +523,7 @@ enum devlink_param_generic_id {DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE ,DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE ,DEVLINK_PARAM_GENERIC_ID_ENABLE_PHC , +DEVLINK_PARAM_GENERIC_ID_CLOCK_ID ,/* add new param generic ids above here*/ __DEVLINK_PARAM_GENERIC_ID_MAX,
@@ -584,6 +585,9 @@ enum devlink_param_generic_id {#define DEVLINK_PARAM_GENERIC_ENABLE_PHC_NAME "enable_phc"#define DEVLINK_PARAM_GENERIC_ENABLE_PHC_TYPE DEVLINK_PARAM_TYPE_BOOL +#define DEVLINK_PARAM_GENERIC_CLOCK_ID_NAME "clock_id" +#define DEVLINK_PARAM_GENERIC_CLOCK_ID_TYPE DEVLINK_PARAM_TYPE_U64 +#define DEVLINK_PARAM_GENERIC (_id, _cmodes, _get, _set, _validate) \ { \ .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
net/devlink/param.c +5 -0
@@ -97,6 +97,11 @@ static const struct devlink_param devlink_param_generic[] = { .name = DEVLINK_PARAM_GENERIC_ENABLE_PHC_NAME, .type = DEVLINK_PARAM_GENERIC_ENABLE_PHC_TYPE, }, + { + .id = DEVLINK_PARAM_GENERIC_ID_CLOCK_ID, + .name = DEVLINK_PARAM_GENERIC_CLOCK_ID_NAME, + .type = DEVLINK_PARAM_GENERIC_CLOCK_ID_TYPE, + }, };static int devlink_param_generic_verify (const struct devlink_param *param)
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 5/12 dpll: Add basic Microchip ZL3073x support
In reply to Ivan VeceraMicrochip Azurite ZL3073x represents chip family providing DPLL and optionally PHC (PTP) functionality. The chips can be connected be connected over I2C or SPI bus.
They have 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.
Add basic functionality to access device registers, probe functionality both I2C and SPI cases and add devlink support to provide info and to set clock ID parameter.
---
v13:
* squashed patches 4, 5 & 7
* extended Kconfig description
* renamed "cfg.custom_ver" to "custom_cfg"
* initial clock_id is generated randomly
* added support for devlink clock_id parameter
--- Documentation/networking/devlink/index.rst | 1 + Documentation/networking/devlink/zl3073x.rst | 51 ++ MAINTAINERS | 8 + drivers/Kconfig | 4 +- drivers/dpll/Kconfig | 6 + drivers/dpll/Makefile | 2 + drivers/dpll/zl3073x/Kconfig | 38 ++ drivers/dpll/zl3073x/Makefile | 10 + drivers/dpll/zl3073x/core.c | 465 +++++++++++++++++++ drivers/dpll/zl3073x/core.h | 57 +++ drivers/dpll/zl3073x/devlink.c | 242 ++++++++++ drivers/dpll/zl3073x/devlink.h | 12 + drivers/dpll/zl3073x/i2c.c | 76 +++ drivers/dpll/zl3073x/regs.h | 75 +++ drivers/dpll/zl3073x/spi.c | 76 +++ 15 files changed, 1121 insertions(+), 2 deletions(-) create mode 100644 Documentation/networking/devlink/zl3073x.rst create mode 100644 drivers/dpll/zl3073x/Kconfig create mode 100644 drivers/dpll/zl3073x/Makefile create mode 100644 drivers/dpll/zl3073x/core.c create mode 100644 drivers/dpll/zl3073x/core.h create mode 100644 drivers/dpll/zl3073x/devlink.c create mode 100644 drivers/dpll/zl3073x/devlink.h create mode 100644 drivers/dpll/zl3073x/i2c.c create mode 100644 drivers/dpll/zl3073x/regs.h create mode 100644 drivers/dpll/zl3073x/spi.c
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 +51 -0
51 lines not on this page · raw message
MAINTAINERS +8 -0
@@ -16479,6 +16479,14 @@ 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/dpll/zl3073x/ + MICROSEMI MIPS SOCS M: Alexandre Belloni <[email protected]> M: [email protected]
drivers/Kconfig +2 -2
@@ -77,6 +77,8 @@ source "drivers/pps/Kconfig" source "drivers/ptp/Kconfig" +source "drivers/dpll/Kconfig" + source "drivers/pinctrl/Kconfig" source "drivers/gpio/Kconfig"
@@ -245,6 +247,4 @@ source "drivers/hte/Kconfig" source "drivers/cdx/Kconfig" -source "drivers/dpll/Kconfig" - endmenu
drivers/dpll/Kconfig +6 -0
@@ -3,5 +3,11 @@ # Generic DPLL drivers configuration # +menu "DPLL device support" + config DPLL bool + +source "drivers/dpll/zl3073x/Kconfig" + +endmenu
drivers/dpll/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-$(CONFIG_DPLL) += dpll.o dpll-y += dpll_core.o dpll-y += dpll_netlink.o dpll-y += dpll_nl.o + +obj-$(CONFIG_ZL3073X) += zl3073x/
drivers/dpll/zl3073x/Kconfig new file +38 -0
@@ -0,0 +1,38 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config ZL3073X + tristate "Microchip Azurite DPLL/PTP/SyncE devices" + depends on NET + select DPLL + select NET_DEVLINK + help + This driver supports Microchip Azurite family DPLL/PTP/SyncE + devices that support up to 5 independent DPLL channels, + 10 input pins and up to 20 output pins. + + To compile this driver as a module, choose M here. The module + will be called zl3073x. + +config ZL3073X_I2C + tristate "I2C bus implementation for Microchip Azurite devices" + depends on I2C && ZL3073X + select REGMAP_I2C + default m + help + This is I2C bus implementation for Microchip Azurite DPLL/PTP/SyncE + devices. + + To compile this driver as a module, choose M here: the module will + be called zl3073x_i2c. + +config ZL3073X_SPI + tristate "SPI bus implementation for Microchip Azurite devices" + depends on SPI && ZL3073X + select REGMAP_SPI + default m + help + This is SPI bus implementation for Microchip Azurite DPLL/PTP/SyncE + devices. + + To compile this driver as a module, choose M here: the module will + be called zl3073x_spi.
drivers/dpll/zl3073x/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_ZL3073X) += zl3073x.o +zl3073x-objs := core.o devlink.o + +obj-$(CONFIG_ZL3073X_I2C) += zl3073x_i2c.o +zl3073x_i2c-objs := i2c.o + +obj-$(CONFIG_ZL3073X_SPI) += zl3073x_spi.o +zl3073x_spi-objs := spi.o
drivers/dpll/zl3073x/core.c new file +465 -0
465 lines not on this page · raw message
drivers/dpll/zl3073x/core.h new file +57 -0
57 lines not on this page · raw message
drivers/dpll/zl3073x/devlink.c new file +242 -0
242 lines not on this page · raw message
drivers/dpll/zl3073x/devlink.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ZL3073X_DEVLINK_H +#define _ZL3073X_DEVLINK_H + +struct zl3073x_dev ; + +struct zl3073x_dev *zl3073x_devm_alloc (struct device *dev); + +int zl3073x_devlink_register (struct zl3073x_dev *zldev); + +#endif /* _ZL3073X_DEVLINK_H */
drivers/dpll/zl3073x/i2c.c new file +76 -0
76 lines not on this page · raw message
drivers/dpll/zl3073x/regs.h new file +75 -0
75 lines not on this page · raw message
drivers/dpll/zl3073x/spi.c new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 6/12 dpll: 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.
Read the following parameters from the device during probe and store them for later use:
* enablement status and frequencies of the synthesizers and their associated DPLL channels
* enablement status and type (single-ended or differential) of input pins
* associated synthesizers, signal format, and enablement status of outputs
--- drivers/dpll/zl3073x/core.c | 249 +++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/core.h | 286 ++++++++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/regs.h | 65 ++++++++ 3 files changed, 600 insertions(+)
drivers/dpll/zl3073x/core.c +249 -0
@@ -6,10 +6,12 @@#include <linux/dev_printk.h> #include <linux/device.h> #include <linux/export.h> +#include <linux/math64.h> #include <linux/module.h> #include <linux/netlink.h> #include <linux/regmap.h> #include <linux/sprintf.h> +#include <linux/string_choices.h> #include <linux/unaligned.h> #include <net/devlink.h>
@@ -383,6 +385,248 @@ int zl3073x_poll_zero_u8(struct zl3073x_dev *zldev, unsigned int reg, u8 mask) ZL_POLL_SLEEP_US, ZL_POLL_TIMEOUT_US); } +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); +} + +/** +* zl3073x_ref_state_fetch - get input reference state +* @zldev: pointer to zl3073x_dev structure +* @index: input reference 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_ref_state_fetch (struct zl3073x_dev *zldev,u8 index) +{ +struct zl3073x_ref *input = &zldev->ref[index]; +u8 ref_config; +int rc; + +/* 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_ref_is_diff (zldev, index -1 )) { + input->enabled =zl3073x_ref_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,"REF%u is %s and configured as %s\n" , index, +str_enabled_disabled (input->enabled), + input->diff ?"differential" :"single-ended" ); + +return rc; +} + +/** +* zl3073x_out_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_out_state_fetch (struct zl3073x_dev *zldev,u8 index) +{ +struct zl3073x_out *out = &zldev->out[index]; +u8 output_ctrl, output_mode; +int rc; + +/* 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. +*/ + out->enabled =FIELD_GET (ZL_OUTPUT_CTRL_EN , output_ctrl); + out->synth =FIELD_GET (ZL_OUTPUT_CTRL_SYNTH_SEL , output_ctrl); + +dev_dbg (zldev->dev,"OUT%u is %s and connected to SYNTH%u\n" , index, +str_enabled_disabled (out->enabled), out->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 */ + out->signal_format =FIELD_GET (ZL_OUTPUT_MODE_SIGNAL_FORMAT , + output_mode); + +dev_dbg (zldev->dev,"OUT%u has signal format 0x%02x\n" , index, + out->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) +{ +struct zl3073x_synth *synth = &zldev->synth[index]; +u16 base, m, n; +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; + +/* Store info about synth enablement and DPLL channel the synth is +* driven by. +*/ + synth->enabled =FIELD_GET (ZL_SYNTH_CTRL_EN , synth_ctrl); + synth->dpll =FIELD_GET (ZL_SYNTH_CTRL_DPLL_SEL , synth_ctrl); + +dev_dbg (zldev->dev,"SYNTH%u is %s and driven by DPLL%u\n" , index, +str_enabled_disabled (synth->enabled), synth->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 , &m); +if (rc) +return rc; + + rc =zl3073x_read_u16 (zldev,ZL_REG_SYNTH_FREQ_N , &n); +if (rc) +return rc; + +/* Check denominator for zero to avoid div by 0 */ +if (!n) { +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 =div_u64 (mul_u32_u32 (base * m, mult), n); + +dev_dbg (zldev->dev,"SYNTH%u frequency: %u 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_REFS ; i++) { + rc =zl3073x_ref_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_OUTS ; i++) { + rc =zl3073x_out_state_fetch (zldev, i); +if (rc) { +dev_err (zldev->dev, +"Failed to fetch output state: %pe\n" , +ERR_PTR (rc)); +return rc; + } + } + +return rc; +} +/** * zl3073x_dev_probe - initialize zl3073x device * @zldev: pointer to zl3073x device
@@ -450,6 +694,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 devlink instance and parameters */ rc =zl3073x_devlink_register (zldev);if (rc)
drivers/dpll/zl3073x/core.h +286 -0
317 lines not on this page · raw message
drivers/dpll/zl3073x/regs.h +65 -0
69 lines not on this page · raw message
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 7/12 dpll: zl3073x: Read DPLL types and pin properties from system firmware
In reply to Ivan VeceraAdd support for reading of DPLL types and optional pin properties from the system firmware (DT, ACPI...).
The DPLL types are stored in property 'dpll-types' as string array and possible values 'pps' and 'eec' are mapped to DPLL enums DPLL_TYPE_PPS and DPLL_TYPE_EEC.
The pin properties are stored under 'input-pins' and 'output-pins' sub-nodes and the following ones are supported:
* reg
integer that specifies pin index
* label
string that is used by driver as board label
* connection-type
string that indicates pin connection type
* supported-frequencies-hz
array of u64 values what frequencies are supported / allowed for given pin with respect to hardware wiring
Do not blindly trust system firmware and filter out frequencies that cannot be configured/represented in device (input frequencies have to be factorized by one of the base frequencies and output frequencies have to divide configured synthesizer frequency).
--- drivers/dpll/zl3073x/Makefile | 2 +- drivers/dpll/zl3073x/core.c | 41 ++++ drivers/dpll/zl3073x/core.h | 7 + drivers/dpll/zl3073x/prop.c | 354 ++++++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/prop.h | 34 ++++ 5 files changed, 437 insertions(+), 1 deletion(-) create mode 100644 drivers/dpll/zl3073x/prop.c create mode 100644 drivers/dpll/zl3073x/prop.h
drivers/dpll/zl3073x/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ZL3073X) += zl3073x.o -zl3073x-objs := core.o devlink.o +zl3073x-objs := core.o devlink.o prop.o obj-$(CONFIG_ZL3073X_I2C) += zl3073x_i2c.o zl3073x_i2c-objs := i2c.o
drivers/dpll/zl3073x/core.c +41 -0
47 lines not on this page · raw message
drivers/dpll/zl3073x/core.h +7 -0
@@ -14,6 +14,7 @@ struct regmap;/* * Hardware limits for ZL3073x chip family */ +#define ZL3073X_MAX_CHANNELS 5#define ZL3073X_NUM_REFS 10#define ZL3073X_NUM_OUTS 10#define ZL3073X_NUM_SYNTHS 5
@@ -107,6 +108,12 @@ 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); +/***************** +* Misc operations +*****************/ + +int zl3073x_ref_freq_factorize (u32 freq,u16 *base,u16 *mult); +static inline bool zl3073x_is_n_pin (u8 id) {
drivers/dpll/zl3073x/prop.c new file +354 -0
354 lines not on this page · raw message
drivers/dpll/zl3073x/prop.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ZL3073X_PROP_H +#define _ZL3073X_PROP_H + +#include <linux/dpll.h> + +#include "core.h" + +struct fwnode_handle ; + +/** +* struct zl3073x_pin_props - pin properties +* @fwnode: pin firmware node +* @dpll_props: DPLL core pin properties +* @package_label: pin package label +* @esync_control: embedded sync support +*/ +struct zl3073x_pin_props { +struct fwnode_handle *fwnode; +struct dpll_pin_properties dpll_props; +char package_label[8 ]; +bool esync_control; +}; + +enum dpll_type zl3073x_prop_dpll_type_get (struct zl3073x_dev *zldev,u8 index); + +struct zl3073x_pin_props *zl3073x_pin_props_get (struct zl3073x_dev *zldev, +enum dpll_pin_direction dir, +u8 index); + +void zl3073x_pin_props_put (struct zl3073x_pin_props *props); + +#endif /* _ZL3073X_PROP_H */
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 8/12 dpll: zl3073x: Register DPLL devices and pins
In reply to Ivan VeceraEnumerate all available DPLL channels and registers a DPLL device for each of them. Check all input references and outputs and register DPLL pins for them.
Number of registered DPLL pins depends on configuration of references and outputs. If the reference or output is configured as differential one then only one DPLL pin is registered. Both references and outputs can be also disabled from firmware configuration and in this case no DPLL pins are registered.
All registrable references are registered to all available DPLL devices with exception of DPLLs that are configured in NCO (numerically controlled oscillator) mode. In this mode DPLL channel acts as PHC and cannot be locked to any reference.
Device outputs are connected to one of synthesizers and each synthesizer is driven by some DPLL channel. So output pins belonging to given output are registered to DPLL device that drives associated synthesizer.
Finally add kworker task to monitor async changes on all DPLL channels and input pins and to notify about them DPLL core. Output pins are not monitored as their parameters are not changed asynchronously by the device.
---
v13:
* re-register DPLLs and pins during devlink reload
--- drivers/dpll/zl3073x/Makefile | 2 +- drivers/dpll/zl3073x/core.c | 104 ++++ drivers/dpll/zl3073x/core.h | 17 + drivers/dpll/zl3073x/devlink.c | 17 + drivers/dpll/zl3073x/dpll.c | 917 +++++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/dpll.h | 42 ++ drivers/dpll/zl3073x/regs.h | 58 +++ 7 files changed, 1156 insertions(+), 1 deletion(-) create mode 100644 drivers/dpll/zl3073x/dpll.c create mode 100644 drivers/dpll/zl3073x/dpll.h
drivers/dpll/zl3073x/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_ZL3073X) += zl3073x.o -zl3073x-objs := core.o devlink.o prop.o +zl3073x-objs := core.o devlink.o dpll.o prop.o obj-$(CONFIG_ZL3073X_I2C) += zl3073x_i2c.o zl3073x_i2c-objs := i2c.o
drivers/dpll/zl3073x/core.c +104 -0
122 lines not on this page · raw message
drivers/dpll/zl3073x/core.h +17 -0
@@ -3,6 +3,8 @@#ifndef _ZL3073X_CORE_H#define _ZL3073X_CORE_H +#include <linux/kthread.h> +#include <linux/list.h> #include <linux/mutex.h> #include <linux/types.h>
@@ -10,6 +12,7 @@struct device ;struct regmap ; +struct zl3073x_dpll ;/* * Hardware limits for ZL3073x chip family
@@ -18,6 +21,10 @@ struct regmap;#define ZL3073X_NUM_REFS 10#define ZL3073X_NUM_OUTS 10#define ZL3073X_NUM_SYNTHS 5 +#define ZL3073X_NUM_INPUT_PINS ZL3073X_NUM_REFS +#define ZL3073X_NUM_OUTPUT_PINS (ZL3073X_NUM_OUTS * 2) +#define ZL3073X_NUM_PINS (ZL3073X_NUM_INPUT_PINS + \ + ZL3073X_NUM_OUTPUT_PINS)/** * struct zl3073x_ref - input reference invariant info
@@ -62,6 +69,9 @@ struct zl3073x_synth {* @ref: array of input references' invariants * @out: array of outs' invariants * @synth: array of synths' invariants +* @dplls: list of DPLLs +* @kworker: thread for periodic work +* @work: periodic work */ struct zl3073x_dev {struct device *dev;
@@ -73,6 +83,13 @@ struct zl3073x_dev {struct zl3073x_ref ref[ZL3073X_NUM_REFS ];struct zl3073x_out out[ZL3073X_NUM_OUTS ];struct zl3073x_synth synth[ZL3073X_NUM_SYNTHS ]; + +/* DPLL channels */ +struct list_head dplls; + +/* Monitor */ +struct kthread_worker *kworker; +struct kthread_delayed_work work; };struct zl3073x_chip_info {
drivers/dpll/zl3073x/devlink.c +17 -0
@@ -8,6 +8,7 @@#include "core.h" #include "devlink.h" +#include "dpll.h" #include "regs.h" /**
@@ -84,9 +85,16 @@ zl3073x_devlink_reload_down(struct devlink *devlink, bool netns_change,enum devlink_reload_limit limit, struct netlink_ext_ack *extack) { + struct zl3073x_dev *zldev = devlink_priv(devlink); +struct zl3073x_dpll *zldpll; +if (action !=DEVLINK_RELOAD_ACTION_DRIVER_REINIT )return -EOPNOTSUPP ; +/* Unregister all DPLLs */ +list_for_each_entry (zldpll, &zldev->dplls, list) +zl3073x_dpll_unregister (zldpll); +return 0 ; }
@@ -99,6 +107,7 @@ zl3073x_devlink_reload_up(struct devlink *devlink, {struct zl3073x_dev *zldev =devlink_priv (devlink);union devlink_param_value val; +struct zl3073x_dpll *zldpll;int rc;if (action !=DEVLINK_RELOAD_ACTION_DRIVER_REINIT )
@@ -116,6 +125,14 @@ zl3073x_devlink_reload_up(struct devlink *devlink, zldev->clock_id = val.vu64; } +/* Re-register all DPLLs */ +list_for_each_entry (zldpll, &zldev->dplls, list) { + rc =zl3073x_dpll_register (zldpll); +if (rc) +dev_warn (zldev->dev, +"Failed to re-register DPLL%u\n" , zldpll->id); + } + *actions_performed =BIT (DEVLINK_RELOAD_ACTION_DRIVER_REINIT );return 0 ;
drivers/dpll/zl3073x/dpll.c new file +917 -0
917 lines not on this page · raw message
drivers/dpll/zl3073x/dpll.h new file +42 -0
42 lines not on this page · raw message
drivers/dpll/zl3073x/regs.h +58 -0
76 lines not on this page · raw message
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 9/12 dpll: zl3073x: Implement input pin selection in manual mode
In reply to Ivan VeceraImplement input pin state setting if the DPLL is running in manual mode. The driver indicates manual mode if the DPLL mode is one of ref-lock, forced-holdover, freerun.
Use these modes to implement input pin state change between connected and disconnected states. When the user set the particular pin as connected the driver marks this input pin as forced reference and switches the DPLL mode to ref-lock. When the use set the pin as disconnected the driver switches the DPLL to freerun or forced holdover mode. The switch to holdover mode is done if the DPLL has holdover capability (e.g is currently locked with holdover acquired).
--- drivers/dpll/zl3073x/dpll.c | 118 ++++++++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/prop.c | 9 ++- 2 files changed, 124 insertions(+), 3 deletions(-)
drivers/dpll/zl3073x/dpll.c +118 -0
@@ -132,6 +132,81 @@ zl3073x_dpll_selected_ref_get(struct zl3073x_dpll *zldpll, u8 *ref)return 0 ; } +/** +* zl3073x_dpll_selected_ref_set - select reference in manual mode +* @zldpll: pointer to zl3073x_dpll +* @ref: input reference to be selected +* +* Selects the given reference for the DPLL channel it should be +* locked to. +* +* Return: 0 on success, <0 on error +*/ +static int +zl3073x_dpll_selected_ref_set (struct zl3073x_dpll *zldpll,u8 ref) +{ +struct zl3073x_dev *zldev = zldpll->dev; +u8 mode, mode_refsel; +int rc; + + mode = zldpll->refsel_mode; + +switch (mode) { +case ZL_DPLL_MODE_REFSEL_MODE_REFLOCK : +/* Manual mode with ref selected */ +if (ref ==ZL3073X_DPLL_REF_NONE ) { +switch (zldpll->lock_status) { +case DPLL_LOCK_STATUS_LOCKED_HO_ACQ : +case DPLL_LOCK_STATUS_HOLDOVER : +/* Switch to forced holdover */ + mode =ZL_DPLL_MODE_REFSEL_MODE_HOLDOVER ; +break ; +default : +/* Switch to freerun */ + mode =ZL_DPLL_MODE_REFSEL_MODE_FREERUN ; +break ; + } +/* Keep selected reference */ + ref = zldpll->forced_ref; + }else if (ref == zldpll->forced_ref) { +/* No register update - same mode and same ref */ +return 0 ; + } +break ; +case ZL_DPLL_MODE_REFSEL_MODE_FREERUN : +case ZL_DPLL_MODE_REFSEL_MODE_HOLDOVER : +/* Manual mode without no ref */ +if (ref ==ZL3073X_DPLL_REF_NONE ) +/* No register update - keep current mode */ +return 0 ; + +/* Switch to reflock mode and update ref selection */ + mode =ZL_DPLL_MODE_REFSEL_MODE_REFLOCK ; +break ; +default : +/* For other modes like automatic or NCO ref cannot be selected +* manually +*/ +return -EOPNOTSUPP ; + } + +/* Build mode_refsel value */ + mode_refsel =FIELD_PREP (ZL_DPLL_MODE_REFSEL_MODE , mode) | +FIELD_PREP (ZL_DPLL_MODE_REFSEL_REF , ref); + +/* Update dpll_mode_refsel register */ + rc =zl3073x_write_u8 (zldev,ZL_REG_DPLL_MODE_REFSEL (zldpll->id), + mode_refsel); +if (rc) +return rc; + +/* Store new mode and forced reference */ + zldpll->refsel_mode = mode; + zldpll->forced_ref = ref; + +return rc; +} +/** * zl3073x_dpll_connected_ref_get - get currently connected reference * @zldpll: pointer to zl3073x_dpll
@@ -283,6 +358,48 @@ zl3073x_dpll_input_pin_state_on_dpll_get(const struct dpll_pin *dpll_pin,return zl3073x_dpll_ref_state_get (pin, state); } +static int +zl3073x_dpll_input_pin_state_on_dpll_set (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv, +enum dpll_pin_state state, +struct netlink_ext_ack *extack) +{ +struct zl3073x_dpll *zldpll = dpll_priv; +struct zl3073x_dpll_pin *pin = pin_priv; +u8 new_ref; +int rc; + +switch (zldpll->refsel_mode) { +case ZL_DPLL_MODE_REFSEL_MODE_REFLOCK : +case ZL_DPLL_MODE_REFSEL_MODE_FREERUN : +case ZL_DPLL_MODE_REFSEL_MODE_HOLDOVER : +if (state ==DPLL_PIN_STATE_CONNECTED ) { +/* Choose the pin as new selected reference */ + new_ref =zl3073x_input_pin_ref_get (pin->id); + }else if (state ==DPLL_PIN_STATE_DISCONNECTED ) { +/* No reference */ + new_ref =ZL3073X_DPLL_REF_NONE ; + }else { +NL_SET_ERR_MSG_MOD (extack, +"Invalid pin state for manual mode" ); +return -EINVAL ; + } + + rc =zl3073x_dpll_selected_ref_set (zldpll, new_ref); +break ; +default : +/* In other modes we cannot change input reference */ +NL_SET_ERR_MSG (extack, +"Pin state cannot be changed in current mode" ); + rc = -EOPNOTSUPP ; +break ; + } + +return rc; +} + static int zl3073x_dpll_output_pin_state_on_dpll_get(const struct dpll_pin *dpll_pin, void *pin_priv,
@@ -377,6 +494,7 @@ zl3073x_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,static const struct dpll_pin_ops zl3073x_dpll_input_pin_ops = { .direction_get = zl3073x_dpll_pin_direction_get, .state_on_dpll_get = zl3073x_dpll_input_pin_state_on_dpll_get, + .state_on_dpll_set = zl3073x_dpll_input_pin_state_on_dpll_set, };static const struct dpll_pin_ops zl3073x_dpll_output_pin_ops = {
drivers/dpll/zl3073x/prop.c +6 -3
@@ -201,11 +201,14 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev,if (!props)return ERR_PTR (-ENOMEM ); -/* Set default pin type */ -if (dir ==DPLL_PIN_DIRECTION_INPUT ) +/* Set default pin type and capabilities */ +if (dir ==DPLL_PIN_DIRECTION_INPUT ) { props->dpll_props.type =DPLL_PIN_TYPE_EXT ; -else + props->dpll_props.capabilities = +DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; + }else { props->dpll_props.type =DPLL_PIN_TYPE_GNSS ; + } props->dpll_props.phase_range.min =S32_MIN ; props->dpll_props.phase_range.max =S32_MAX ;
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 10/12 dpll: zl3073x: Add support to get/set priority on input pins
In reply to Ivan VeceraAdd support for getting and setting input pin priority. Implement required callbacks and set appropriate capability for input pins. Although the pin priority make sense only if the DPLL is running in automatic mode we have to expose this capability unconditionally because input pins (references) are shared between all DPLLs where one of them can run in automatic mode while the other one not.
--- drivers/dpll/zl3073x/dpll.c | 88 +++++++++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/prop.c | 1 + 2 files changed, 89 insertions(+)
drivers/dpll/zl3073x/dpll.c +88 -0
@@ -287,6 +287,56 @@ zl3073x_dpll_ref_prio_get(struct zl3073x_dpll_pin *pin, u8 *prio)return rc; } +/** +* zl3073x_dpll_ref_prio_set - set priority for given input pin +* @pin: pointer to pin +* @prio: place to store priority +* +* Sets priority for the given input pin. +* +* Return: 0 on success, <0 on error +*/ +static int +zl3073x_dpll_ref_prio_set (struct zl3073x_dpll_pin *pin,u8 prio) +{ +struct zl3073x_dpll *zldpll = pin->dpll; +struct zl3073x_dev *zldev = zldpll->dev; +u8 ref, ref_prio; +int rc; + +guard (mutex)(&zldev->multiop_lock); + +/* Read DPLL configuration into mailbox */ + rc =zl3073x_mb_op (zldev,ZL_REG_DPLL_MB_SEM ,ZL_DPLL_MB_SEM_RD , +ZL_REG_DPLL_MB_MASK ,BIT (zldpll->id)); +if (rc) +return rc; + +/* Read reference priority - one value shared between P&N pins */ + ref =zl3073x_input_pin_ref_get (pin->id); + rc =zl3073x_read_u8 (zldev,ZL_REG_DPLL_REF_PRIO (ref /2 ), &ref_prio); +if (rc) +return rc; + +/* Update nibble according pin type */ +if (zl3073x_dpll_is_p_pin (pin)) { + ref_prio &= ~ZL_DPLL_REF_PRIO_REF_P ; + ref_prio |=FIELD_PREP (ZL_DPLL_REF_PRIO_REF_P , prio); + }else { + ref_prio &= ~ZL_DPLL_REF_PRIO_REF_N ; + ref_prio |=FIELD_PREP (ZL_DPLL_REF_PRIO_REF_N , prio); + } + +/* Update reference priority */ + rc =zl3073x_write_u8 (zldev,ZL_REG_DPLL_REF_PRIO (ref /2 ), ref_prio); +if (rc) +return rc; + +/* Commit configuration */ +return zl3073x_mb_op (zldev,ZL_REG_DPLL_MB_SEM ,ZL_DPLL_MB_SEM_WR , +ZL_REG_DPLL_MB_MASK ,BIT (zldpll->id)); +} +/** * zl3073x_dpll_ref_state_get - get status for given input pin * @pin: pointer to pin
@@ -400,6 +450,42 @@ zl3073x_dpll_input_pin_state_on_dpll_set(const struct dpll_pin *dpll_pin,return rc; } +static int +zl3073x_dpll_input_pin_prio_get (const struct dpll_pin *dpll_pin,void *pin_priv, +const struct dpll_device *dpll,void *dpll_priv, +u32 *prio,struct netlink_ext_ack *extack) +{ +struct zl3073x_dpll_pin *pin = pin_priv; + + *prio = pin->prio; + +return 0 ; +} + +static int +zl3073x_dpll_input_pin_prio_set (const struct dpll_pin *dpll_pin,void *pin_priv, +const struct dpll_device *dpll,void *dpll_priv, +u32 prio,struct netlink_ext_ack *extack) +{ +struct zl3073x_dpll_pin *pin = pin_priv; +int rc; + +if (prio >ZL_DPLL_REF_PRIO_MAX ) +return -EINVAL ; + +/* If the pin is selectable then update HW registers */ +if (pin->selectable) { + rc =zl3073x_dpll_ref_prio_set (pin, prio); +if (rc) +return rc; + } + +/* Save priority */ + pin->prio = prio; + +return 0 ; +} + static int zl3073x_dpll_output_pin_state_on_dpll_get(const struct dpll_pin *dpll_pin, void *pin_priv,
@@ -493,6 +579,8 @@ zl3073x_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,static const struct dpll_pin_ops zl3073x_dpll_input_pin_ops = { .direction_get = zl3073x_dpll_pin_direction_get, + .prio_get = zl3073x_dpll_input_pin_prio_get, + .prio_set = zl3073x_dpll_input_pin_prio_set, .state_on_dpll_get = zl3073x_dpll_input_pin_state_on_dpll_get, .state_on_dpll_set = zl3073x_dpll_input_pin_state_on_dpll_set, };
drivers/dpll/zl3073x/prop.c +1 -0
@@ -205,6 +205,7 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struct zl3073x_dev *zldev,if (dir ==DPLL_PIN_DIRECTION_INPUT ) { props->dpll_props.type =DPLL_PIN_TYPE_EXT ; props->dpll_props.capabilities = +DPLL_PIN_CAPABILITIES_PRIORITY_CAN_CHANGE |DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE ; }else { props->dpll_props.type =DPLL_PIN_TYPE_GNSS ;
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 11/12 dpll: zl3073x: Implement input pin state setting in automatic mode
In reply to Ivan VeceraImplement input pin state setting when the DPLL is running in automatic mode. Unlike manual mode, the DPLL mode switching is not used here and the implementation uses special priority value (15) to make the given pin non-selectable.
When the user sets state of the pin as disconnected the driver internally sets its priority in HW to 15 that prevents the DPLL to choose this input pin. Conversely, if the pin status is set to selectable, the driver sets the pin priority in HW to the original saved value.
--- drivers/dpll/zl3073x/dpll.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/dpll/zl3073x/dpll.c +32 -0
@@ -439,6 +439,38 @@ zl3073x_dpll_input_pin_state_on_dpll_set(const struct dpll_pin *dpll_pin, rc =zl3073x_dpll_selected_ref_set (zldpll, new_ref);break ; + +case ZL_DPLL_MODE_REFSEL_MODE_AUTO : +if (state ==DPLL_PIN_STATE_SELECTABLE ) { +if (pin->selectable) +return 0 ;/* Pin is already selectable */ + +/* Restore pin priority in HW */ + rc =zl3073x_dpll_ref_prio_set (pin, pin->prio); +if (rc) +return rc; + +/* Mark pin as selectable */ + pin->selectable = true; + }else if (state ==DPLL_PIN_STATE_DISCONNECTED ) { +if (!pin->selectable) +return 0 ;/* Pin is already disconnected */ + +/* Set pin priority to none in HW */ + rc =zl3073x_dpll_ref_prio_set (pin, +ZL_DPLL_REF_PRIO_NONE ); +if (rc) +return rc; + +/* Mark pin as non-selectable */ + pin->selectable = false; + }else { +NL_SET_ERR_MSG (extack, +"Invalid pin state for automatic mode" ); +return -EINVAL ; + } +break ; +default :/* In other modes we cannot change input reference */ NL_SET_ERR_MSG(extack,
Signature · 1 line
2.49.0
Ivan Vecera
maintainerPATCH v13 12/12 dpll: zl3073x: Add support to get/set frequency on pins
In reply to Ivan VeceraAdd support to get/set frequency on pins. The frequency for input pins (references) is computed in the device according this formula:
freq = base_freq * multiplier * (nominator / denominator)
where the base_freq comes from the list of supported base frequencies and other parameters are arbitrary numbers. All these parameters are 16-bit unsigned integers.
The frequency for output pin is determined by the frequency of synthesizer the output pin is connected to and divisor of the output to which is the given pin belongs. The resulting frequency of the P-pin and the N-pin from this output pair depends on the signal format of this output pair.
The device supports so-called N-divided signal formats where for the N-pin there is an additional divisor. The frequencies for both pins from such output pair are computed:
P-pin-freq = synth_freq / output_div
N-pin-freq = synth_freq / output_div / n_div
For other signal-format types both P and N pin have the same frequency based only synth frequency and output divisor.
Implement output pin callbacks to get and set frequency. The frequency setting for the output non-N-divided signal format is simple as we have to compute just new output divisor. For N-divided formats it is more complex because by changing of output divisor we change frequency for both P and N pins. In this case if we are changing frequency for P-pin we have to compute also new N-divisor for N-pin to keep its current frequency. From this and the above it follows that the frequency of the N-pin cannot be higher than the frequency of the P-pin and the callback must take this limitation into account.
---
v13:
* squashed patch 14
--- drivers/dpll/zl3073x/dpll.c | 349 ++++++++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/regs.h | 10 ++ 2 files changed, 359 insertions(+)
drivers/dpll/zl3073x/dpll.c +349 -0
@@ -8,6 +8,7 @@#include <linux/dpll.h> #include <linux/err.h> #include <linux/kthread.h> +#include <linux/math64.h> #include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/netlink.h>
@@ -84,6 +85,127 @@ zl3073x_dpll_pin_direction_get(const struct dpll_pin *dpll_pin, void *pin_priv,return 0 ; } +/** +* zl3073x_dpll_input_ref_frequency_get - get input reference frequency +* @zldpll: pointer to zl3073x_dpll +* @ref_id: reference id +* @frequency: pointer to variable to store frequency +* +* Reads frequency of given input reference. +* +* Return: 0 on success, <0 on error +*/ +static int +zl3073x_dpll_input_ref_frequency_get (struct zl3073x_dpll *zldpll,u8 ref_id, +u32 *frequency) +{ +struct zl3073x_dev *zldev = zldpll->dev; +u16 base, mult, num, denom; +int rc; + +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 (ref_id)); +if (rc) +return rc; + +/* Read registers to compute resulting frequency */ + rc =zl3073x_read_u16 (zldev,ZL_REG_REF_FREQ_BASE , &base); +if (rc) +return rc; + rc =zl3073x_read_u16 (zldev,ZL_REG_REF_FREQ_MULT , &mult); +if (rc) +return rc; + rc =zl3073x_read_u16 (zldev,ZL_REG_REF_RATIO_M , &num); +if (rc) +return rc; + rc =zl3073x_read_u16 (zldev,ZL_REG_REF_RATIO_N , &denom); +if (rc) +return rc; + +/* Sanity check that HW has not returned zero denominator */ +if (!denom) { +dev_err (zldev->dev, +"Zero divisor for ref %u frequency got from device\n" , + ref_id); +return -EINVAL ; + } + +/* Compute the frequency */ + *frequency =mul_u64_u32_div (base * mult, num, denom); + +return rc; +} + +static int +zl3073x_dpll_input_pin_frequency_get (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 *frequency, +struct netlink_ext_ack *extack) +{ +struct zl3073x_dpll *zldpll = dpll_priv; +struct zl3073x_dpll_pin *pin = pin_priv; +u32 ref_freq; +u8 ref; +int rc; + +/* Read and return ref frequency */ + ref =zl3073x_input_pin_ref_get (pin->id); + rc =zl3073x_dpll_input_ref_frequency_get (zldpll, ref, &ref_freq); +if (!rc) + *frequency = ref_freq; + +return rc; +} + +static int +zl3073x_dpll_input_pin_frequency_set (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 frequency, +struct netlink_ext_ack *extack) +{ +struct zl3073x_dpll *zldpll = dpll_priv; +struct zl3073x_dev *zldev = zldpll->dev; +struct zl3073x_dpll_pin *pin = pin_priv; +u16 base, mult; +u8 ref; +int rc; + +/* Get base frequency and multiplier for the requested frequency */ + rc =zl3073x_ref_freq_factorize (frequency, &base, &mult); +if (rc) +return rc; + +guard (mutex)(&zldev->multiop_lock); + +/* Load reference configuration */ + ref =zl3073x_input_pin_ref_get (pin->id); + rc =zl3073x_mb_op (zldev,ZL_REG_REF_MB_SEM ,ZL_REF_MB_SEM_RD , +ZL_REG_REF_MB_MASK ,BIT (ref)); + +/* Update base frequency, multiplier, numerator & denominator */ + rc =zl3073x_write_u16 (zldev,ZL_REG_REF_FREQ_BASE , base); +if (rc) +return rc; + rc =zl3073x_write_u16 (zldev,ZL_REG_REF_FREQ_MULT , mult); +if (rc) +return rc; + rc =zl3073x_write_u16 (zldev,ZL_REG_REF_RATIO_M ,1 ); +if (rc) +return rc; + rc =zl3073x_write_u16 (zldev,ZL_REG_REF_RATIO_N ,1 ); +if (rc) +return rc; + +/* Commit reference configuration */ +return zl3073x_mb_op (zldev,ZL_REG_REF_MB_SEM ,ZL_REF_MB_SEM_WR , +ZL_REG_REF_MB_MASK ,BIT (ref)); +} +/** * zl3073x_dpll_selected_ref_get - get currently selected reference * @zldpll: pointer to zl3073x_dpll
@@ -518,6 +640,229 @@ zl3073x_dpll_input_pin_prio_set(const struct dpll_pin *dpll_pin, void *pin_priv,return 0 ; } +static int +zl3073x_dpll_output_pin_frequency_get (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 *frequency, +struct netlink_ext_ack *extack) +{ +struct zl3073x_dpll *zldpll = dpll_priv; +struct zl3073x_dev *zldev = zldpll->dev; +struct zl3073x_dpll_pin *pin = pin_priv; +struct device *dev = zldev->dev; +u8 out, signal_format, synth; +u32 output_div, synth_freq; +int rc; + + out =zl3073x_output_pin_out_get (pin->id); + synth =zl3073x_out_synth_get (zldev, out); + synth_freq =zl3073x_synth_freq_get (zldev, synth); + +guard (mutex)(&zldev->multiop_lock); + +/* Read output configuration into mailbox */ + rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , +ZL_REG_OUTPUT_MB_MASK ,BIT (out)); +if (rc) +return rc; + + rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_DIV , &output_div); +if (rc) +return rc; + +/* Check output divisor for zero */ +if (!output_div) { +dev_err (dev,"Zero divisor for output %u got from device\n" , + out); +return -EINVAL ; + } + +/* Read used signal format for the given output */ + signal_format =zl3073x_out_signal_format_get (zldev, out); + +switch (signal_format) { +case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV : +case ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV : +/* In case of divided format we have to distiguish between +* given output pin type. +*/ +if (zl3073x_dpll_is_p_pin (pin)) { +/* For P-pin the resulting frequency is computed as +* simple division of synth frequency and output +* divisor. +*/ + *frequency = synth_freq / output_div; + }else { +/* For N-pin we have to divide additionally by +* divisor stored in esync_period output mailbox +* register that is used as N-pin divisor for these +* modes. +*/ +u32 ndiv; + + rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , + &ndiv); +if (rc) +return rc; + +/* Check N-pin divisor for zero */ +if (!ndiv) { +dev_err (dev, +"Zero N-pin divisor for output %u got from device\n" , + out); +return -EINVAL ; + } + +/* Compute final divisor for N-pin */ + *frequency = synth_freq / output_div / ndiv; + } +break ; +default : +/* In other modes the resulting frequency is computed as +* division of synth frequency and output divisor. +*/ + *frequency = synth_freq / output_div; +break ; + } + +return rc; +} + +static int +zl3073x_dpll_output_pin_frequency_set (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 frequency, +struct netlink_ext_ack *extack) +{ +struct zl3073x_dpll *zldpll = dpll_priv; +struct zl3073x_dev *zldev = zldpll->dev; +struct zl3073x_dpll_pin *pin = pin_priv; +struct device *dev = zldev->dev; +u32 output_n_freq, output_p_freq; +u8 out, signal_format, synth; +u32 cur_div, new_div, ndiv; +u32 synth_freq; +int rc; + + out =zl3073x_output_pin_out_get (pin->id); + synth =zl3073x_out_synth_get (zldev, out); + synth_freq =zl3073x_synth_freq_get (zldev, synth); + new_div = synth_freq / (u32 )frequency; + +/* Get used signal format for the given output */ + signal_format =zl3073x_out_signal_format_get (zldev, out); + +guard (mutex)(&zldev->multiop_lock); + +/* Load output configuration */ + rc =zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_RD , +ZL_REG_OUTPUT_MB_MASK ,BIT (out)); +if (rc) +return rc; + +/* Check signal format */ +if (signal_format !=ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV && + signal_format !=ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV ) { +/* For non N-divided signal formats the frequency is computed +* as division of synth frequency and output divisor. +*/ + rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_DIV , new_div); +if (rc) +return rc; + +/* For 50/50 duty cycle the divisor is equal to width */ + rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_WIDTH , new_div); +if (rc) +return rc; + +/* Commit output configuration */ +return zl3073x_mb_op (zldev, +ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_WR , +ZL_REG_OUTPUT_MB_MASK ,BIT (out)); + } + +/* For N-divided signal format get current divisor */ + rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_DIV , &cur_div); +if (rc) +return rc; + +/* Check output divisor for zero */ +if (!cur_div) { +dev_err (dev,"Zero divisor for output %u got from device\n" , + out); +return -EINVAL ; + } + +/* Get N-pin divisor (shares the same register with esync */ + rc =zl3073x_read_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , &ndiv); +if (rc) +return rc; + +/* Check N-pin divisor for zero */ +if (!ndiv) { +dev_err (dev, +"Zero N-pin divisor for output %u got from device\n" , + out); +return -EINVAL ; + } + +/* Compute current output frequency for P-pin */ + output_p_freq = synth_freq / cur_div; + +/* Compute current N-pin frequency */ + output_n_freq = output_p_freq / ndiv; + +if (zl3073x_dpll_is_p_pin (pin)) { +/* We are going to change output frequency for P-pin but +* if the requested frequency is less than current N-pin +* frequency then indicate a failure as we are not able +* to compute N-pin divisor to keep its frequency unchanged. +*/ +if (frequency <= output_n_freq) +return -EINVAL ; + +/* Update the output divisor */ + rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_DIV , new_div); +if (rc) +return rc; + +/* For 50/50 duty cycle the divisor is equal to width */ + rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_WIDTH , new_div); +if (rc) +return rc; + +/* Compute new divisor for N-pin */ + ndiv = (u32 )frequency / output_n_freq; + }else { +/* We are going to change frequency of N-pin but if +* the requested freq is greater or equal than freq of P-pin +* in the output pair we cannot compute divisor for the N-pin. +* In this case indicate a failure. +*/ +if (output_p_freq <= frequency) +return -EINVAL ; + +/* Compute new divisor for N-pin */ + ndiv = output_p_freq / (u32 )frequency; + } + +/* Update divisor for the N-pin */ + rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_ESYNC_PERIOD , ndiv); +if (rc) +return rc; + +/* For 50/50 duty cycle the divisor is equal to width */ + rc =zl3073x_write_u32 (zldev,ZL_REG_OUTPUT_ESYNC_WIDTH , ndiv); +if (rc) +return rc; + +/* Commit output configuration */ +return zl3073x_mb_op (zldev,ZL_REG_OUTPUT_MB_SEM ,ZL_OUTPUT_MB_SEM_WR , +ZL_REG_OUTPUT_MB_MASK ,BIT (out)); +} + static int zl3073x_dpll_output_pin_state_on_dpll_get(const struct dpll_pin *dpll_pin, void *pin_priv,
@@ -611,6 +956,8 @@ zl3073x_dpll_mode_get(const struct dpll_device *dpll, void *dpll_priv,static const struct dpll_pin_ops zl3073x_dpll_input_pin_ops = { .direction_get = zl3073x_dpll_pin_direction_get, + .frequency_get = zl3073x_dpll_input_pin_frequency_get, + .frequency_set = zl3073x_dpll_input_pin_frequency_set, .prio_get = zl3073x_dpll_input_pin_prio_get, .prio_set = zl3073x_dpll_input_pin_prio_set, .state_on_dpll_get = zl3073x_dpll_input_pin_state_on_dpll_get,
@@ -619,6 +966,8 @@ static const struct dpll_pin_ops zl3073x_dpll_input_pin_ops = {static const struct dpll_pin_ops zl3073x_dpll_output_pin_ops = { .direction_get = zl3073x_dpll_pin_direction_get, + .frequency_get = zl3073x_dpll_output_pin_frequency_get, + .frequency_set = zl3073x_dpll_output_pin_frequency_set, .state_on_dpll_get = zl3073x_dpll_output_pin_state_on_dpll_get, };
drivers/dpll/zl3073x/regs.h +10 -0
@@ -137,6 +137,11 @@#define ZL_REF_MB_SEM_WR BIT(0)#define ZL_REF_MB_SEM_RD BIT(1) +#define ZL_REG_REF_FREQ_BASE ZL_REG(10, 0x05, 2) +#define ZL_REG_REF_FREQ_MULT ZL_REG(10, 0x07, 2) +#define ZL_REG_REF_RATIO_M ZL_REG(10, 0x09, 2) +#define ZL_REG_REF_RATIO_N ZL_REG(10, 0x0b, 2) +#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)
@@ -195,4 +200,9 @@#define ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV 12#define ZL_OUTPUT_MODE_SIGNAL_FORMAT_2_NDIV_INV 15 +#define ZL_REG_OUTPUT_DIV ZL_REG(14, 0x0c, 4) +#define ZL_REG_OUTPUT_WIDTH ZL_REG(14, 0x10, 4) +#define ZL_REG_OUTPUT_ESYNC_PERIOD ZL_REG(14, 0x14, 4) +#define ZL_REG_OUTPUT_ESYNC_WIDTH ZL_REG(14, 0x18, 4) +#endif /* _ZL3073X_REGS_H */
Signature · 1 line
2.49.0
Jiri Pirko
maintainerRe: [PATCH net-next v13 12/12] dpll: zl3073x: Add support to get/set frequency on pins
Fri, Jul 04, 2025 at 08:22:02PM +0200, [email protected] wrote:
[...]
drivers/dpll/zl3073x/dpll.c zl3073x_dpll_pin_direction_get(const struct dpll_pin *dpll_pin, void *pin_priv, · line 169
Quoted 6 lines
drivers/dpll/zl3073x/dpll.c +6
-0+static int +zl3073x_dpll_input_pin_frequency_set (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 frequency, +struct netlink_ext_ack *extack)
Unrelated to this patch, but ny idea why we don't implement "FREQUENCY_CAN_CHANGE" capability. I think we are missing it.
Ivan Vecera
maintainerRe: [PATCH net-next v13 12/12] dpll: zl3073x: Add support to get/set frequency on pins
Quoted 4 lines · Jiri Pirko
Fri, Jul 04, 2025 at 08:22:02PM +0200, [email protected] wrote:
[...]
Quoted 10 lines
drivers/dpll/zl3073x/dpll.c zl3073x_dpll_pin_direction_get(const struct dpll_pin *dpll_pin, void *pin_priv, · line 169
Quoted 6 lines
drivers/dpll/zl3073x/dpll.c +6
-0+static int +zl3073x_dpll_input_pin_frequency_set (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 frequency, +struct netlink_ext_ack *extack)Unrelated to this patch, but ny idea why we don't implement "
FREQUENCY_CAN_CHANGE" capability. I think we are missing it.
Interesting question... from the driver API it is not necessary as the DPLL core can deduce FREQUENCY_CAN_CHANGE from existence of pin_frequency_set() callback and also if the pin reports empty or single item supported-frequencies list.
Ivan
Jiri Pirko
maintainerRe: [PATCH net-next v13 12/12] dpll: zl3073x: Add support to get/set frequency on pins
Quoted 17 lines · Mon, Jul 07, 2025 at 11:46:54AM +0200, [email protected] wrote:
Quoted 4 lines · Jiri Pirko
Fri, Jul 04, 2025 at 08:22:02PM +0200, [email protected] wrote:
[...]
Quoted 10 lines
drivers/dpll/zl3073x/dpll.c zl3073x_dpll_pin_direction_get(const struct dpll_pin *dpll_pin, void *pin_priv, · line 169
Quoted 6 lines
drivers/dpll/zl3073x/dpll.c +6
-0+static int +zl3073x_dpll_input_pin_frequency_set (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 frequency, +struct netlink_ext_ack *extack)Unrelated to this patch, but ny idea why we don't implement "
FREQUENCY_CAN_CHANGE" capability. I think we are missing it.
Quoted 4 lines
Interesting question... from the driver API it is not necessary as the DPLL core can deduce
FREQUENCY_CAN_CHANGEfrom existence ofpin_frequency_set()callback and also if the pin reports empty or single item supported-frequencies list.
Yep, the same applies to the rest of the set function. You may always check the setter it present. I don't recollect why we have capabilities like we have them.
Quoted 3 lines
Ivan
Vadim Fedorenko
maintainerRe: [PATCH net-next v13 12/12] dpll: zl3073x: Add support to get/set frequency on pins
In reply to Jiri PirkoQuoted 4 lines · Jiri Pirko
Fri, Jul 04, 2025 at 08:22:02PM +0200, [email protected] wrote:
[...]
Quoted 10 lines
drivers/dpll/zl3073x/dpll.c zl3073x_dpll_pin_direction_get(const struct dpll_pin *dpll_pin, void *pin_priv, · line 169
Quoted 6 lines
drivers/dpll/zl3073x/dpll.c +6
-0+static int +zl3073x_dpll_input_pin_frequency_set (const struct dpll_pin *dpll_pin, +void *pin_priv, +const struct dpll_device *dpll, +void *dpll_priv,u64 frequency, +struct netlink_ext_ack *extack)Unrelated to this patch, but ny idea why we don't implement "
FREQUENCY_CAN_CHANGE" capability. I think we are missing it.
Do you mean that some DPLLs may implement fixed frequency pins and we have to signal it back to user-space?
Ivan Vecera
maintainerRe: [PATCH net-next v13 12/12] dpll: zl3073x: Add support to get/set frequency on pins
Quoted 15 lines · Vadim Fedorenko
Quoted 4 lines · Jiri Pirko
Fri, Jul 04, 2025 at 08:22:02PM +0200, [email protected] wrote:
[...]
Quoted 10 lines
drivers/dpll/zl3073x/dpll.c zl3073x_dpll_pin_direction_get(const struct dpll_pin *dpll_pin, void *pin_priv, · line 169
Quoted 6 lines
drivers/dpll/zl3073x/dpll.c +6
-0+static int +zl3073x_dpll_input_pin_frequency_set (const struct dpll_pin *dpll_pin, + void *pin_priv, + const struct dpll_device *dpll, + void *dpll_priv, u64 frequency, + struct netlink_ext_ack *extack)Unrelated to this patch, but ny idea why we don't implement "
FREQUENCY_CAN_CHANGE" capability. I think we are missing it.
Quoted 3 lines
Do you mean that some DPLLs may implement fixed frequency pins and we have to signal it back to user-space?
I think this is not necessary... user-space know this if the supported frequency list is empty or has only single frequency.
Ivan
Jiri Pirko
maintainerQuoted 8 lines · Fri, Jul 04, 2025 at 08:21:50PM +0200, [email protected] wrote:
Add support for Microchip Azurite DPLL/PTP/SyncE chip family that provides DPLL and PTP functionality. This series bring first part that adds the core functionality and basic DPLL support.
The next part of the series will bring additional DPLL functionality like eSync support, phase offset and frequency offset reporting and phase adjustments.
Quoted 8 lines
Testing was done by myself and by Prathosh Satish on Microchip EDS2 development board with ZL30732 DPLL chip connected over I2C bus.
---
Changelog:
v13:
* added support for u64 devlink parameters
* added support for generic devlink parameter 'clock_id'
When do you plan to add the code which gets the clock_id from the devicetree? I'm asking as I believe that should be the default. getrandom/param_set is fallback.
Ivan Vecera
maintainerQuoted 18 lines · Jiri Pirko
Quoted 8 lines · Fri, Jul 04, 2025 at 08:21:50PM +0200, [email protected] wrote:
Add support for Microchip Azurite DPLL/PTP/SyncE chip family that provides DPLL and PTP functionality. This series bring first part that adds the core functionality and basic DPLL support.
The next part of the series will bring additional DPLL functionality like eSync support, phase offset and frequency offset reporting and phase adjustments.
Quoted 8 lines
Testing was done by myself and by Prathosh Satish on Microchip EDS2 development board with ZL30732 DPLL chip connected over I2C bus.
---
Changelog:
v13:
* added support for u64 devlink parameters
* added support for generic devlink parameter 'clock_id'
Quoted 4 lines
When do you plan to add the code which gets the
clock_idfrom the devicetree? I'm asking as I believe that should be the default. getrandom/param_set is fallback.
This requires change to DPLL device DT schema (patch 1). I have asked Krzystof about this change in [1] but I didn't receive any answer so I went this way. Anyway eventual support for clock-id reading from DT is very easy and can be implemented later.
Thanks,
Ivan
Quoted 45 lines · Fri, Jul 04, 2025 at 08:21:50PM +0200, [email protected] wrote:
Add support for Microchip Azurite DPLL/PTP/SyncE chip family that provides DPLL and PTP functionality. This series bring first part that adds the core functionality and basic DPLL support.
The next part of the series will bring additional DPLL functionality like eSync support, phase offset and frequency offset reporting and phase adjustments.
Testing was done by myself and by Prathosh Satish on Microchip EDS2 development board with ZL30732 DPLL chip connected over I2C bus.
---
Changelog:
v13:
* added support for u64 devlink parameters
* added support for generic devlink parameter 'clock_id'
* several patches squashed into one per @jpirko's advice
* renamed devlink version 'cfg.custom_ver' to 'custom_cfg'
* per discussion with @jpirko, theclock_idis now generated randomly and user have an option to change it via devlink
* implemented devlink reload to applyclock_idchangev12:
* Using 'returndev_err_probe()'
* Separatezl3073x_chip_infostructures instead of array
* Usemul_u64_u32_div()to compute input reference frequency to avoid potential overflow
* Removed superfluous check inzl3073x_dpll_output_pin_frequency_set()v11:
* Fixed uninitialized 'rc' in error-path in patch 9v10:
* Usage ofstr_enabled_disabled()where possible.v9:
After discussion with Jakub Kicinski we agreed that it would be better to implement whole functionality in a single driver without touching MFD sub-system. Besides touching multiple sub-systems by single device there are also some technical issues that are easier resolvable in a single driver. Additionally the firmware flashing functionality would bring more than 1000 lines of code with previous approach to the MFD driver - it is not something the MFD maintainers would like to see.
Quoted 13 lines
Ivan Vecera (12):
dt-bindings: dpll: Add DPLL device and pin
dt-bindings: dpll: Add support for Microchip Azurite chip family
devlink: Add support for u64 parameters
devlink: Add new "clock_id" generic device param
dpll: Add basic Microchip ZL3073x support
dpll: zl3073x: Fetch invariants during probe
dpll: zl3073x: Read DPLL types and pin properties from system firmware
dpll: zl3073x: Register DPLL devices and pins
dpll: zl3073x: Implement input pin selection in manual mode
dpll: zl3073x: Add support to get/set priority on input pins
dpll: zl3073x: Implement input pin state setting in automatic mode
dpll: zl3073x: Add support to get/set frequency on pins
For the DPLL related code:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Fri, 4 Jul 2025 20:21:50 +0200 you wrote:
Add support for Microchip Azurite DPLL/PTP/SyncE chip family that provides DPLL and PTP functionality. This series bring first part that adds the core functionality and basic DPLL support.
The next part of the series will bring additional DPLL functionality like eSync support, phase offset and frequency offset reporting and phase adjustments.
[...]
Here is the summary with links:
- [net-next,v13,01/12] dt-bindings: dpll: Add DPLL device and pin
https://git.kernel.org/netdev/net-next/c/0afcee10dda1 - [net-next,v13,02/12] dt-bindings: dpll: Add support for Microchip Azurite chip family https://git.kernel.org/netdev/net-next/c/9f149c5d6dbe - [net-next,v13,03/12] devlink: Add support for u64 parameters https://git.kernel.org/netdev/net-next/c/c0ef14469591 - [net-next,v13,04/12] devlink: Add new "clock_id" generic device param https://git.kernel.org/netdev/net-next/c/de9ccf2296ac - [net-next,v13,05/12] dpll: Add basic Microchip ZL3073x support https://git.kernel.org/netdev/net-next/c/2df8e64e01c1 - [net-next,v13,06/12] dpll: zl3073x: Fetch invariants during probe https://git.kernel.org/netdev/net-next/c/b7d907d1f84a - [net-next,v13,07/12] dpll: zl3073x: Read DPLL types and pin properties from system firmware https://git.kernel.org/netdev/net-next/c/a99a9f0ebdaa - [net-next,v13,08/12] dpll: zl3073x: Register DPLL devices and pins https://git.kernel.org/netdev/net-next/c/75a71ecc2412 - [net-next,v13,09/12] dpll: zl3073x: Implement input pin selection in manual mode https://git.kernel.org/netdev/net-next/c/9686c8b01676 - [net-next,v13,10/12] dpll: zl3073x: Add support to get/set priority on input pins https://git.kernel.org/netdev/net-next/c/12ba92f0a6de - [net-next,v13,11/12] dpll: zl3073x: Implement input pin state setting in automatic mode https://git.kernel.org/netdev/net-next/c/bf33c93c1a16 - [net-next,v13,12/12] dpll: zl3073x: Add support to get/set frequency on pins https://git.kernel.org/netdev/net-next/c/ce26d7ca50a5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html