From nobody Tue Oct 7 23:11:00 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E3622DEA9E for ; Fri, 4 Jul 2025 18:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751653411; cv=none; b=H9g3Jp7BKhBq94m8fBxN0ioRNgxKmxrgFcZBJcElalyfZSG9Jv8LZa6H6WNzK1qvirqIMQ49Lvfx4xbTQruBwI3oqvboBIpyL0RTC+R0Y+kw801dsoAarJwYtQjt8QbznsUSOGa8UJAeez/m6xV7UZP7y8u8qeTb8+d/IlCG6Pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751653411; c=relaxed/simple; bh=2qUAK9hWsELU+MEZVNFBW1PyQPndZBtbZBM9v4va+k8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eZSC9G87yUc/uj6VC1lRQ/miiNKC+7EYNR7k7PCRDcF6U1eTKxtQm96a5nPrpqofnWkgBPSV9klVT3MN7qnBkNkjX73toyvZR2oNFdAqa344P8B5jOH4Fd8utB0bpeD5NV/Z+CvDfc3RyrgiwVNfuvBxhelY/oSU9e4I39fmQZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KQ8hirm8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KQ8hirm8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751653408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l/gQaGHDTzFAN8IkvilyPck90PGB3vVPj2V/E3+JViU=; b=KQ8hirm8ReG5RB4CgOpw6pqQfbOUYD/Zf21NTLefKxn5t6cBoW57OGT9rvzIppYrbOJqZL Onq7WHsDarlMzaSRK55JkB4/57fZaiGwQIOSmgwWAhUBpfQ5FTMfbZEy13KBczESWiexWb bxbQ50HPsac9AnZMcb/8w0g583rrwKs= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-78-mv5NMiWWM96VXli0lWfmhw-1; Fri, 04 Jul 2025 14:23:25 -0400 X-MC-Unique: mv5NMiWWM96VXli0lWfmhw-1 X-Mimecast-MFC-AGG-ID: mv5NMiWWM96VXli0lWfmhw_1751653403 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2CC9618002E4; Fri, 4 Jul 2025 18:23:23 +0000 (UTC) Received: from p16v.redhat.com (unknown [10.45.226.37]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5220E19560A7; Fri, 4 Jul 2025 18:23:15 +0000 (UTC) From: Ivan Vecera To: Jiri Pirko , netdev@vger.kernel.org Cc: Vadim Fedorenko , Arkadiusz Kubalewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Prathosh Satish , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Jason Gunthorpe , Shannon Nelson , Dave Jiang , Jonathan Cameron , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Michal Schmidt , Petr Oros Subject: [PATCH net-next v13 09/12] dpll: zl3073x: Implement input pin selection in manual mode Date: Fri, 4 Jul 2025 20:21:59 +0200 Message-ID: <20250704182202.1641943-10-ivecera@redhat.com> In-Reply-To: <20250704182202.1641943-1-ivecera@redhat.com> References: <20250704182202.1641943-1-ivecera@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" Implement 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). Signed-off-by: Ivan Vecera --- drivers/dpll/zl3073x/dpll.c | 118 ++++++++++++++++++++++++++++++++++++ drivers/dpll/zl3073x/prop.c | 9 ++- 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/drivers/dpll/zl3073x/dpll.c b/drivers/dpll/zl3073x/dpll.c index d1656095b4d3f..70c452a877ef4 100644 --- a/drivers/dpll/zl3073x/dpll.c +++ b/drivers/dpll/zl3073x/dpll.c @@ -132,6 +132,81 @@ zl3073x_dpll_selected_ref_get(struct zl3073x_dpll *zld= pll, u8 *ref) return 0; } =20 +/** + * 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 =3D zldpll->dev; + u8 mode, mode_refsel; + int rc; + + mode =3D zldpll->refsel_mode; + + switch (mode) { + case ZL_DPLL_MODE_REFSEL_MODE_REFLOCK: + /* Manual mode with ref selected */ + if (ref =3D=3D 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 =3D ZL_DPLL_MODE_REFSEL_MODE_HOLDOVER; + break; + default: + /* Switch to freerun */ + mode =3D ZL_DPLL_MODE_REFSEL_MODE_FREERUN; + break; + } + /* Keep selected reference */ + ref =3D zldpll->forced_ref; + } else if (ref =3D=3D 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 =3D=3D ZL3073X_DPLL_REF_NONE) + /* No register update - keep current mode */ + return 0; + + /* Switch to reflock mode and update ref selection */ + mode =3D 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 =3D FIELD_PREP(ZL_DPLL_MODE_REFSEL_MODE, mode) | + FIELD_PREP(ZL_DPLL_MODE_REFSEL_REF, ref); + + /* Update dpll_mode_refsel register */ + rc =3D 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 =3D mode; + zldpll->forced_ref =3D 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); } =20 +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 =3D dpll_priv; + struct zl3073x_dpll_pin *pin =3D 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 =3D=3D DPLL_PIN_STATE_CONNECTED) { + /* Choose the pin as new selected reference */ + new_ref =3D zl3073x_input_pin_ref_get(pin->id); + } else if (state =3D=3D DPLL_PIN_STATE_DISCONNECTED) { + /* No reference */ + new_ref =3D ZL3073X_DPLL_REF_NONE; + } else { + NL_SET_ERR_MSG_MOD(extack, + "Invalid pin state for manual mode"); + return -EINVAL; + } + + rc =3D 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 =3D -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, v= oid *dpll_priv, static const struct dpll_pin_ops zl3073x_dpll_input_pin_ops =3D { .direction_get =3D zl3073x_dpll_pin_direction_get, .state_on_dpll_get =3D zl3073x_dpll_input_pin_state_on_dpll_get, + .state_on_dpll_set =3D zl3073x_dpll_input_pin_state_on_dpll_set, }; =20 static const struct dpll_pin_ops zl3073x_dpll_output_pin_ops =3D { diff --git a/drivers/dpll/zl3073x/prop.c b/drivers/dpll/zl3073x/prop.c index bc8b78cfb5ae0..c3224e78cbf01 100644 --- a/drivers/dpll/zl3073x/prop.c +++ b/drivers/dpll/zl3073x/prop.c @@ -201,11 +201,14 @@ struct zl3073x_pin_props *zl3073x_pin_props_get(struc= t zl3073x_dev *zldev, if (!props) return ERR_PTR(-ENOMEM); =20 - /* Set default pin type */ - if (dir =3D=3D DPLL_PIN_DIRECTION_INPUT) + /* Set default pin type and capabilities */ + if (dir =3D=3D DPLL_PIN_DIRECTION_INPUT) { props->dpll_props.type =3D DPLL_PIN_TYPE_EXT; - else + props->dpll_props.capabilities =3D + DPLL_PIN_CAPABILITIES_STATE_CAN_CHANGE; + } else { props->dpll_props.type =3D DPLL_PIN_TYPE_GNSS; + } =20 props->dpll_props.phase_range.min =3D S32_MIN; props->dpll_props.phase_range.max =3D S32_MAX; --=20 2.49.0