Skip to content

Commit a99a9f0

Browse files
ivecerakuba-moo
authored andcommitted
dpll: zl3073x: Read DPLL types and pin properties from system firmware
Add 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). Signed-off-by: Ivan Vecera <ivecera@redhat.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Link: https://patch.msgid.link/20250704182202.1641943-8-ivecera@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b7d907d commit a99a9f0

File tree

5 files changed

+437
-1
lines changed

5 files changed

+437
-1
lines changed

drivers/dpll/zl3073x/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
obj-$(CONFIG_ZL3073X) += zl3073x.o
4-
zl3073x-objs := core.o devlink.o
4+
zl3073x-objs := core.o devlink.o prop.o
55

66
obj-$(CONFIG_ZL3073X_I2C) += zl3073x_i2c.o
77
zl3073x_i2c-objs := i2c.o

drivers/dpll/zl3073x/core.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,47 @@ const struct regmap_config zl3073x_regmap_config = {
128128
};
129129
EXPORT_SYMBOL_NS_GPL(zl3073x_regmap_config, "ZL3073X");
130130

131+
/**
132+
* zl3073x_ref_freq_factorize - factorize given frequency
133+
* @freq: input frequency
134+
* @base: base frequency
135+
* @mult: multiplier
136+
*
137+
* Checks if the given frequency can be factorized using one of the
138+
* supported base frequencies. If so the base frequency and multiplier
139+
* are stored into appropriate parameters if they are not NULL.
140+
*
141+
* Return: 0 on success, -EINVAL if the frequency cannot be factorized
142+
*/
143+
int
144+
zl3073x_ref_freq_factorize(u32 freq, u16 *base, u16 *mult)
145+
{
146+
static const u16 base_freqs[] = {
147+
1, 2, 4, 5, 8, 10, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125,
148+
128, 160, 200, 250, 256, 320, 400, 500, 625, 640, 800, 1000,
149+
1250, 1280, 1600, 2000, 2500, 3125, 3200, 4000, 5000, 6250,
150+
6400, 8000, 10000, 12500, 15625, 16000, 20000, 25000, 31250,
151+
32000, 40000, 50000, 62500,
152+
};
153+
u32 div;
154+
int i;
155+
156+
for (i = 0; i < ARRAY_SIZE(base_freqs); i++) {
157+
div = freq / base_freqs[i];
158+
159+
if (div <= U16_MAX && (freq % base_freqs[i]) == 0) {
160+
if (base)
161+
*base = base_freqs[i];
162+
if (mult)
163+
*mult = div;
164+
165+
return 0;
166+
}
167+
}
168+
169+
return -EINVAL;
170+
}
171+
131172
static bool
132173
zl3073x_check_reg(struct zl3073x_dev *zldev, unsigned int reg, size_t size)
133174
{

drivers/dpll/zl3073x/core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct regmap;
1414
/*
1515
* Hardware limits for ZL3073x chip family
1616
*/
17+
#define ZL3073X_MAX_CHANNELS 5
1718
#define ZL3073X_NUM_REFS 10
1819
#define ZL3073X_NUM_OUTS 10
1920
#define ZL3073X_NUM_SYNTHS 5
@@ -107,6 +108,12 @@ int zl3073x_write_u16(struct zl3073x_dev *zldev, unsigned int reg, u16 val);
107108
int zl3073x_write_u32(struct zl3073x_dev *zldev, unsigned int reg, u32 val);
108109
int zl3073x_write_u48(struct zl3073x_dev *zldev, unsigned int reg, u64 val);
109110

111+
/*****************
112+
* Misc operations
113+
*****************/
114+
115+
int zl3073x_ref_freq_factorize(u32 freq, u16 *base, u16 *mult);
116+
110117
static inline bool
111118
zl3073x_is_n_pin(u8 id)
112119
{

0 commit comments

Comments
 (0)