From patchwork Tue Mar 28 09:26:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 75931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2085606vqo; Tue, 28 Mar 2023 02:40:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZjSu1Fil4f8v0avXpT2DLSnPbkdt9JT6AY3ol4mRDoiT3OgwAVW7Ttjgh73SYUB63/3mSc X-Received: by 2002:a62:6245:0:b0:627:eb0a:56e9 with SMTP id w66-20020a626245000000b00627eb0a56e9mr13988506pfb.29.1679996412815; Tue, 28 Mar 2023 02:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679996412; cv=none; d=google.com; s=arc-20160816; b=ZCsZTfwQZd86q+ayIRbMZirZsFN+f3DrEItIshprNgD+WPafWAacepjeLJOpXywJDG 9vf7e01Kw31QoSqxwHxAV1SQ02tDhrEvrOuQNTYbvpK+t+o9xmXOI6Xt6VPnCBACPANx +Omm0cgs+5sBnff0B47PlF1QkvVjbVpXSN5Tr9mu2/Z9hLKSSRRgpDeeeofJ8b7UT+L9 sjsFkEeAsP3hMI8rMm5th0a/N+YRmS/dUc5YfS9XjED9efLnHbGJ91RqKz8Ev5wmr8gs ltKE6bkByJAmYggvSqUNkkQ054XXhZbIblKTLvlMZI2i2R6BxaRhi+UlgCl54c3oWTmE lu4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MAWR4i2sMqlJ6Qjq/NdgY/qVX5I1Q348DjDJYW4rUis=; b=QA0pkJcSWar4OMPhrLO+Iu4mvpjB8ci6oW6T94zduLW8EOgm5k3bPC4ZMBPmlAjEMp 57PmzUoHeIl8XuQK4h3/0RT8bIRWYvj6NG97ty2BfUFg46ScUBTvg59jNBBnD4Z4VrOv mEw/keNtRDzYOO0CXFJjmCJH+PgfGYUmWyolNgPghNWmJqt7oVWYJSnA7AfHjhFFFrCT jQPQfpMOX3MpM6tfM5N0ZxtoEVsOwkoAkd0TWZjxyHj0UcXmqrhrlMMSsXk8bZcym+8v Azu4AYLJgzjx4slEU7vmR1hzY0XfBjTPDM9MuROJKqFjid9WB8eu3sy6uEGmsDg3yq4f rTlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XZVABxqe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a630004000000b005030a59a80bsi30442143pga.178.2023.03.28.02.40.00; Tue, 28 Mar 2023 02:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XZVABxqe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231956AbjC1J1A (ORCPT + 99 others); Tue, 28 Mar 2023 05:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230419AbjC1J05 (ORCPT ); Tue, 28 Mar 2023 05:26:57 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAA3C59F1; Tue, 28 Mar 2023 02:26:55 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id E02471BF20C; Tue, 28 Mar 2023 09:26:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1679995614; 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=MAWR4i2sMqlJ6Qjq/NdgY/qVX5I1Q348DjDJYW4rUis=; b=XZVABxqeXn7B7xAo34rxSqsP9ZK4+3sKXObRTgb8NqcZDZdubKjbA9cqe4cbF8KDysyDuq rkfCOX+W0Jg/q0xmrtJCXtID4651VSSWLEnhiDvxsaj60hUV4yifcD8jTLL6fD12eQpR2e SIEuA2LQfOmfW2RQFemaZgON7rsA12klX925xGo7pPp2LNO380YNk8ZAR6BZZ80Dtiuc+H gJUBMP6tdaOwwmKOhIvMHUdQ5jvYCUoniprbaA9IWMcE+jAVFbW+bKrDMGB4wjiukIvl+r bRsC4uMKRv9iXcPCloCM2lRphFKazgXAy0YGTxHOx6zK+fF+B27wBgu6LmDl7w== From: Herve Codina To: Herve Codina , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v5 1/5] dt-bindings: mfd: Add the Lantiq PEF2256 E1/T1/J1 framer Date: Tue, 28 Mar 2023 11:26:41 +0200 Message-Id: <20230328092645.634375-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328092645.634375-1-herve.codina@bootlin.com> References: <20230328092645.634375-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761603918478077843?= X-GMAIL-MSGID: =?utf-8?q?1761603918478077843?= The Lantiq PEF2256 is a framer and line interface component designed to fulfill all required interfacing between an analog E1/T1/J1 line and the digital PCM system highway/H.100 bus. Signed-off-by: Herve Codina Reviewed-by: Krzysztof Kozlowski --- .../bindings/mfd/lantiq,pef2256.yaml | 267 ++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/lantiq,pef2256.yaml diff --git a/Documentation/devicetree/bindings/mfd/lantiq,pef2256.yaml b/Documentation/devicetree/bindings/mfd/lantiq,pef2256.yaml new file mode 100644 index 000000000000..7bc29e93cbc6 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/lantiq,pef2256.yaml @@ -0,0 +1,267 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/lantiq,pef2256.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Lantiq PEF2256 + +maintainers: + - Herve Codina + +description: + The Lantiq PEF2256, also known as Infineon PEF2256 or FALC56, is a framer and + line interface component designed to fulfill all required interfacing between + an analog E1/T1/J1 line and the digital PCM system highway/H.100 bus. + +properties: + compatible: + items: + - const: lantiq,pef2256 + - const: simple-mfd + + reg: + maxItems: 1 + + clocks: + items: + - description: Master clock + - description: Receive System Clock + - description: Transmit System Clock + + clock-names: + items: + - const: mclk + - const: sclkr + - const: sclkx + + interrupts: + maxItems: 1 + + reset-gpios: + description: + GPIO used to reset the device. + maxItems: 1 + + pinctrl: + $ref: /schemas/pinctrl/pinctrl.yaml# + additionalProperties: false + + patternProperties: + '-pins$': + type: object + $ref: /schemas/pinctrl/pincfg-node.yaml# + additionalProperties: false + + properties: + pins: + enum: [ RPA, RPB, RPC, RPD, XPA, XPB, XPC, XPD ] + + function: + enum: [ SYPR, RFM, RFMB, RSIGM, RSIG, DLR, FREEZE, RFSP, LOS, + SYPX, XFMS, XSIG, TCLK, XMFB, XSIGM, DLX, XCLK, XLT, + GPI, GPOH, GPOL ] + + required: + - pins + - function + + lantiq,line-interface: + $ref: /schemas/types.yaml#/definitions/string + enum: [e1, t1j1] + default: e1 + description: | + The line interface type + - e1: E1 line + - t1j1: T1/J1 line + + lantiq,frame-format: + $ref: /schemas/types.yaml#/definitions/string + description: + The line interface frame format. + + lantiq,data-rate-bps: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [2048000, 4096000, 8192000, 16384000] + default: 2048000 + description: + Data rate (bit per seconds) on the system highway. + + lantiq,clock-falling-edge: + $ref: /schemas/types.yaml#/definitions/flag + description: + Data is sent on falling edge of the clock (and received on the rising + edge). If 'clock-falling-edge' is not present, data is sent on the + rising edge (and received on the falling edge). + + lantiq,channel-phase: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3, 4, 5, 6, 7] + default: 0 + description: + The pef2256 delivers a full frame (32 8bit time-slots in E1 and 24 8bit + time-slots 8 8bit signaling in E1/J1) every 125us. This lead to a data + rate of 2048000 bit/s. When lantiq,data-rate-bps is more than 2048000 + bit/s, the data (all 32 8bit) present in the frame are interleave with + unused time-slots. The lantiq,channel-phase property allows to set the + correct alignment of the interleave mechanism. + For instance, suppose lantiq,data-rate-bps = 8192000 (ie 4*2048000), and + lantiq,channel-phase = 2, the interleave schema with unused time-slots + (nu) and used time-slots (XX) for TSi is + nu nu XX nu nu nu XX nu nu nu XX nu + <-- TSi --> <- TSi+1 -> <- TSi+2 -> + With lantiq,data-rate-bps = 8192000, and lantiq,channel-phase = 1, the + interleave schema is + nu XX nu nu nu XX nu nu nu XX nu nu + <-- TSi --> <- TSi+1 -> <- TSi+2 -> + With lantiq,data-rate-bps = 4096000 (ie 2*2048000), and + lantiq,channel-phase = 1, the interleave schema is + nu XX nu XX nu XX + <-- TSi --> <- TSi+1 -> <- TSi+2 -> + + lantiq,subordinate: + $ref: /schemas/types.yaml#/definitions/flag + description: + If present, the pef2256 works in subordinate mode. In this mode it + synchronizes on line interface clock signals. Otherwise, it synchronizes + on internal clocks. + +patternProperties: + '^codec(-([0-9]|[1-2][0-9]|3[0-1]))?$': + type: object + $ref: /schemas/sound/dai-common.yaml + unevaluatedProperties: false + description: + Codec provided by the pef2256. This codec allows to use some of the PCM + system highway time-slots as audio channels to transport audio data over + the E1/T1/J1 lines. + The time-slots used by the codec must be set and so, the properties + 'dai-tdm-slot-num', 'dai-tdm-slot-width', 'dai-tdm-slot-tx-mask' and + 'dai-tdm-slot-rx-mask' must be present in the sound card node for + sub-nodes that involve the codec. The codec uses 8bit time-slots. + 'dai-tdm-tdm-slot-with' must be set to 8. + The tx and rx masks define the pef2256 time-slots assigned to the codec. + + properties: + compatible: + const: lantiq,pef2256-codec + + '#sound-dai-cells': + const: 0 + + required: + - compatible + - '#sound-dai-cells' + +required: + - compatible + - reg + - clocks + - clock-names + - interrupts + +allOf: + - if: + properties: + lantiq,line-interface: + contains: + const: e1 + then: + properties: + lantiq,frame-format: + enum: [doubleframe, crc4-multiframe, auto-multiframe] + default: doubleframe + description: | + The E1 line interface frame format + - doubleframe: Doubleframe format + - crc4-multiframe: CRC4 multiframe format + - auto-multiframe: CRC4 multiframe format with interworking + capabilities (ITU-T G.706 Annex B) + + else: + # T1/J1 line + properties: + lantiq,frame-format: + enum: [4frame, 12frame, 24frame, 72frame] + default: 12frame + description: | + The T1/J1 line interface frame format + - 4frame: 4-frame multiframe format (F4) + - 12frame: 12-frame multiframe format (F12, D3/4) + - 24frame: 24-frame multiframe format (ESF) + - 72frame: 72-frame multiframe format (F72, remote switch mode) + +additionalProperties: false + +examples: + - | + #include + #include + + framer@2000000 { + compatible = "lantiq,pef2256", "simple-mfd"; + reg = <0x2000000 0x100>; + interrupts = <8 IRQ_TYPE_LEVEL_LOW>; + interrupt-parent = <&intc>; + clocks = <&clk_mclk>, <&clk_sclkr>, <&clk_sclkx>; + clock-names = "mclk", "sclkr", "sclkx"; + reset-gpios = <&gpio 11 GPIO_ACTIVE_LOW>; + lantiq,data-rate-bps = <4096000>; + + pinctrl { + pef2256_rpa_sypr: rpa-pins { + pins = "RPA"; + function = "SYPR"; + }; + pef2256_xpa_sypx: xpa-pins { + pins = "XPA"; + function = "SYPX"; + }; + }; + + pef2256_codec0: codec-0 { + compatible = "lantiq,pef2256-codec"; + #sound-dai-cells = <0>; + sound-name-prefix = "PEF2256_0"; + }; + + pef2256_codec1: codec-1 { + compatible = "lantiq,pef2256-codec"; + #sound-dai-cells = <0>; + sound-name-prefix = "PEF2256_1"; + }; + }; + + sound { + compatible = "simple-audio-card"; + #address-cells = <1>; + #size-cells = <0>; + simple-audio-card,dai-link@0 { /* CPU DAI1 - pef2256 codec 1 */ + reg = <0>; + cpu { + sound-dai = <&cpu_dai1>; + }; + codec { + sound-dai = <&pef2256_codec0>; + dai-tdm-slot-num = <4>; + dai-tdm-slot-width = <8>; + /* TS 1, 2, 3, 4 */ + dai-tdm-slot-tx-mask = <0 1 1 1 1>; + dai-tdm-slot-rx-mask = <0 1 1 1 1>; + }; + }; + simple-audio-card,dai-link@1 { /* CPU DAI2 - pef2256 codec 2 */ + reg = <1>; + cpu { + sound-dai = <&cpu_dai2>; + }; + codec { + sound-dai = <&pef2256_codec1>; + dai-tdm-slot-num = <4>; + dai-tdm-slot-width = <8>; + /* TS 5, 6, 7, 8 */ + dai-tdm-slot-tx-mask = <0 0 0 0 0 1 1 1 1>; + dai-tdm-slot-rx-mask = <0 0 0 0 0 1 1 1 1>; + }; + }; + }; From patchwork Tue Mar 28 09:26:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 75929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2084878vqo; Tue, 28 Mar 2023 02:38:31 -0700 (PDT) X-Google-Smtp-Source: AKy350a+RYrmXgtuWOX8rnrlD2yHsS2tWXOFjNJ5AZZhUG0SQpbLluG+TxLzBbMBu/QrNnHT7yO9 X-Received: by 2002:a17:902:f985:b0:1a1:d24f:a5f6 with SMTP id ky5-20020a170902f98500b001a1d24fa5f6mr13829564plb.46.1679996311352; Tue, 28 Mar 2023 02:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679996311; cv=none; d=google.com; s=arc-20160816; b=B1TwetppZlZ5rsnklaSrmQGNUheuAezwAotZR/grTbTSEf1GyrxmtZrlk5mhr+V6yk 9rqYjmLaor2RCZOYZ+a6T39wegdI0N60JhoTsl6+/06xznr9Cea8PtKnsNgGjOdMM1np 2lRYjJqYyfLu4qUgtp+P9pZQwYkBXEZBq0BkaRDRmQ07mlBp8PvV/vt3Okv+s4FFemUL nQQ8CEB5J4qtq0Pz890bhOGYbMYLBv0Z6ptvUfkieUGbYSo5e4GXglvqReXjw9EKOPhV 2FAuV9KECUwvp61dFidtOs3pg4Lcx/8gwwKTeEXQVXbeXZGasBaTDUcRs0CXRTxG2kKN S8gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+ABK5Vp6RyIlUdjzICcj9w28lG46EOSEidi4EpLJjAo=; b=dmycdjyEb/D2m3PncaoEQks8rUM607wVIlD43e8ovobPlWcFyCTQgF9XyN5WWMFZOv 9vNctcl78iXsxPg4P69BvnvfP6ja7qzZebl49gjF6CFh5Vc8iKe990xJr6MRgnWWoi49 Fgl/3ABhR99RuXm5DMzcQg2y4zCF3+Kl4VKN2ZQN/nmqknQnEUMxJR9CBRxIR0pvKZUx UwcMvCbjSyuuMm53uClrbFOJEH18y/ci7QqVQazCTRTd9BZP04PiKQVMeCdLUk0AOHzr 6E72IRAh6TFTvsCXljaAoXpMzju/QULV+ieIcL30a/i07BmVqv6Zfr+MNv2m5Hy0DKVg D6JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CxFG66Nt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kx3-20020a170902f94300b001a1d9808392si19011472plb.465.2023.03.28.02.38.18; Tue, 28 Mar 2023 02:38:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CxFG66Nt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232571AbjC1J1L (ORCPT + 99 others); Tue, 28 Mar 2023 05:27:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232329AbjC1J1D (ORCPT ); Tue, 28 Mar 2023 05:27:03 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 400873594; Tue, 28 Mar 2023 02:26:57 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 781A01BF20E; Tue, 28 Mar 2023 09:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1679995615; 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=+ABK5Vp6RyIlUdjzICcj9w28lG46EOSEidi4EpLJjAo=; b=CxFG66NtS4ORQWAHIKA/eyFY9sGVlCX9JnG4Z98ehYD+rZBl6TB1uCcrbLI5QogVGAdJ/f xIlQB35yfLa9JwMW1w45H9UnTlvjtZEmGEuvaELkaRyW59eaagusIrt0HiUlc1LuKjwX68 DxQEAt8DiJnksqjsGCfChabodAoZ5Z+W/RcEZEbZmXMaiU530+ANFTLt1+04i3e2GMB4HL GyNzovCm1P0ECRX+VN4vNADd8WEK5+l942v6ayBt1QdC34FmqdTbJQnFOgk/ZKsvhqDutZ 8ldFcPZgOEdaQapnSeO4aib4+jk5hd0QfNvoAMaJL1mRCEsCXC2WOBrSgj39MQ== From: Herve Codina To: Herve Codina , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v5 2/5] mfd: Add support for the Lantiq PEF2256 framer Date: Tue, 28 Mar 2023 11:26:42 +0200 Message-Id: <20230328092645.634375-3-herve.codina@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328092645.634375-1-herve.codina@bootlin.com> References: <20230328092645.634375-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761603812324671184?= X-GMAIL-MSGID: =?utf-8?q?1761603812324671184?= The Lantiq PEF2256 is a framer and line interface component designed to fulfill all required interfacing between an analog E1/T1/J1 line and the digital PCM system highway/H.100 bus. Signed-off-by: Herve Codina --- drivers/mfd/Kconfig | 17 + drivers/mfd/Makefile | 1 + drivers/mfd/pef2256.c | 1355 +++++++++++++++++++++++++++++++++++ include/linux/mfd/pef2256.h | 28 + 4 files changed, 1401 insertions(+) create mode 100644 drivers/mfd/pef2256.c create mode 100644 include/linux/mfd/pef2256.h diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index fcc141e067b9..74c3750d21e4 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1063,6 +1063,23 @@ config PCF50633_GPIO Say yes here if you want to include support GPIO for pins on the PCF50633 chip. +config MFD_PEF2256 + tristate "Lantiq PEF2256 (FALC56) framer" + depends on OF + select PINCTRL + select PINMUX + select GENERIC_PINCONF + help + This option enables support for the Lantiq PEF2256 framer, also known + as FALC56. This framer and its line interface component is designed + to fulfill all required interfacing between analog E1/T1/J1 lines and + the digital PCM system highway. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called pef2256. + config MFD_PM8XXX tristate "Qualcomm PM8xxx PMIC chips driver" depends on (ARM || HEXAGON || COMPILE_TEST) diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 2f6c89d1e277..b2bb6e6a141c 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -195,6 +195,7 @@ obj-$(CONFIG_MFD_SI476X_CORE) += si476x-core.o obj-$(CONFIG_MFD_CS5535) += cs5535-mfd.o obj-$(CONFIG_MFD_OMAP_USB_HOST) += omap-usb-host.o omap-usb-tll.o +obj-$(CONFIG_MFD_PEF2256) += pef2256.o obj-$(CONFIG_MFD_PM8XXX) += qcom-pm8xxx.o ssbi.o obj-$(CONFIG_MFD_QCOM_RPM) += qcom_rpm.o obj-$(CONFIG_MFD_SPMI_PMIC) += qcom-spmi-pmic.o diff --git a/drivers/mfd/pef2256.c b/drivers/mfd/pef2256.c new file mode 100644 index 000000000000..1a3896c2edcf --- /dev/null +++ b/drivers/mfd/pef2256.c @@ -0,0 +1,1355 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PEF2256 also known as FALC56 driver + * + * Copyright 2023 CS GROUP France + * + * Author: Herve Codina + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PEF2256_CMDR 0x02 /* Command Register */ +#define PEF2256_CMDR_RRES BIT(6) +#define PEF2256_CMDR_XRES BIT(4) +#define PEF2256_CMDR_SRES BIT(0) +#define PEF2256_IMR0 0x14 /* Interrupt Mask Register 0 */ +#define PEF2256_IMR1 0x15 /* Interrupt Mask Register 1 */ +#define PEF2256_IMR2 0x16 /* Interrupt Mask Register 2 */ +#define PEF2256_IMR3 0x17 /* Interrupt Mask Register 3 */ +#define PEF2256_IMR4 0x18 /* Interrupt Mask Register 4 */ +#define PEF2256_IMR5 0x19 /* Interrupt Mask Register 5 */ +#define PEF2256_FMR0 0x1C /* Framer Mode Register 0 */ +#define PEF2256_FMR0_XC_MASK (0x3 << 6) +#define PEF2256_FMR0_XC_NRZ (0x0 << 6) +#define PEF2256_FMR0_XC_CMI (0x1 << 6) +#define PEF2256_FMR0_XC_AMI (0x2 << 6) +#define PEF2256_FMR0_XC_HDB3 (0x3 << 6) +#define PEF2256_FMR0_RC_MASK (0x3 << 4) +#define PEF2256_FMR0_RC_NRZ (0x0 << 4) +#define PEF2256_FMR0_RC_CMI (0x1 << 4) +#define PEF2256_FMR0_RC_AMI (0x2 << 4) +#define PEF2256_FMR0_RC_HDB3 (0x3 << 4) +#define PEF2256_FMR1 0x1D /* Framer Mode Register 1 */ +#define PEF2256_FMR1_XFS BIT(3) +#define PEF2256_FMR1_ECM BIT(2) +/* SSD is defined on 2 bits. The other bit is on SIC1 register */ +#define PEF2256_FMR1_SSD_MASK BIT(1) +#define PEF2256_FMR1_SSD_2048 0 +#define PEF2256_FMR1_SSD_4096 BIT(1) +#define PEF2256_FMR1_SSD_8192 0 +#define PEF2256_FMR1_SSD_16384 BIT(1) +#define PEF2256_FMR2 0x1E /* Framer Mode Register 2 */ +#define PEF2256_FMR2_RFS_MASK (0x3 << 6) +#define PEF2256_FMR2_RFS_DOUBLEFRAME (0x0 << 6) +#define PEF2256_FMR2_RFS_CRC4_MULTIFRAME (0x2 << 6) +#define PEF2256_FMR2_RFS_AUTO_MULTIFRAME (0x3 << 6) +#define PEF2256_FMR2_AXRA BIT(1) +#define PEF2256_LOOP 0x1F /* Channel Loop-Back */ +#define PEF2256_XSW 0x20 /* Transmit Service Word */ +#define PEF2256_XSW_XSIS BIT(7) +#define PEF2256_XSW_XTM BIT(6) +#define PEF2256_XSW_XY_MASK (0x1f << 0) +#define PEF2256_XSW_XY(_v) ((_v) & 0x1f) +#define PEF2256_XSP 0x21 /* Transmit Spare Bits */ +#define PEF2256_XSP_XSIF BIT(2) +#define PEF2256_XC0 0x22 /* Transmit Control 0 */ +#define PEF2256_XC1 0x23 /* Transmit Control 1 */ +#define PEF2256_RC0 0x24 /* Receive Control 0 */ +#define PEF2256_RC0_SWD BIT(7) +#define PEF2256_RC0_ASY4 BIT(6) +#define PEF2256_RC1 0x25 /* Receive Control 1 */ +#define PEF2256_XPM0 0x26 /* Transmit Pulse Mask 0 */ +#define PEF2256_XPM1 0x27 /* Transmit Pulse Mask 1 */ +#define PEF2256_XPM2 0x28 /* Transmit Pulse Mask 2 */ +#define PEF2256_XPM2_XLT BIT(6) +#define PEF2256_TSWM 0x29 /* Transparent Service Word Mask */ +#define PEF2256_LIM0 0x36 /* Line Interface Mode 0 */ +#define PEF2256_2X_LIM0_BIT3 BIT(3) /* v2.x, described as a forced '1' bit */ +#define PEF2256_LIM0_MAS BIT(0) +#define PEF2256_LIM1 0x37 /* Line Interface Mode 1 */ +#define PEF2256_12_LIM1_RIL_MASK (0x7 << 4) +#define PEF2256_12_LIM1_RIL_910 (0x0 << 4) +#define PEF2256_12_LIM1_RIL_740 (0x1 << 4) +#define PEF2256_12_LIM1_RIL_590 (0x2 << 4) +#define PEF2256_12_LIM1_RIL_420 (0x3 << 4) +#define PEF2256_12_LIM1_RIL_320 (0x4 << 4) +#define PEF2256_12_LIM1_RIL_210 (0x5 << 4) +#define PEF2256_12_LIM1_RIL_160 (0x6 << 4) +#define PEF2256_12_LIM1_RIL_100 (0x7 << 4) +#define PEF2256_2X_LIM1_RIL_MASK (0x7 << 4) +#define PEF2256_2X_LIM1_RIL_2250 (0x0 << 4) +#define PEF2256_2X_LIM1_RIL_1100 (0x1 << 4) +#define PEF2256_2X_LIM1_RIL_600 (0x2 << 4) +#define PEF2256_2X_LIM1_RIL_350 (0x3 << 4) +#define PEF2256_2X_LIM1_RIL_210 (0x4 << 4) +#define PEF2256_2X_LIM1_RIL_140 (0x5 << 4) +#define PEF2256_2X_LIM1_RIL_100 (0x6 << 4) +#define PEF2256_2X_LIM1_RIL_50 (0x7 << 4) +#define PEF2256_PCD 0x38 /* Pulse Count Detection */ +#define PEF2256_PCR 0x39 /* Pulse Count Recovery */ +#define PEF2256_LIM2 0x3A /* Line Interface Mode 2 */ +#define PEF2256_LIM2_SLT_MASK (0x3 << 4) +#define PEF2256_LIM2_SLT_THR55 (0x0 << 4) +#define PEF2256_LIM2_SLT_THR67 (0x1 << 4) +#define PEF2256_LIM2_SLT_THR50 (0x2 << 4) +#define PEF2256_LIM2_SLT_THR45 (0x3 << 4) +#define PEF2256_LIM2_ELT BIT(2) +#define PEF2256_SIC1 0x3E /* System Interface Control 1 */ +#define PEF2256_SIC1_SSC_MASK (BIT(7) | BIT(3)) +#define PEF2256_SIC1_SSC_2048 (0) +#define PEF2256_SIC1_SSC_4096 BIT(3) +#define PEF2256_SIC1_SSC_8192 BIT(7) +#define PEF2256_SIC1_SSC_16384 (BIT(7) | BIT(3)) +/* SSD is defined on 2 bits. The other bit is on FMR1 register */ +#define PEF2256_SIC1_SSD_MASK BIT(6) +#define PEF2256_SIC1_SSD_2048 0 +#define PEF2256_SIC1_SSD_4096 0 +#define PEF2256_SIC1_SSD_8192 BIT(6) +#define PEF2256_SIC1_SSD_16384 BIT(6) +#define PEF2256_SIC1_RBS_MASK (0x3 << 4) +#define PEF2256_SIC1_RBS_2FRAMES (0x0 << 4) +#define PEF2256_SIC1_RBS_1FRAME (0x1 << 4) +#define PEF2256_SIC1_RBS_96BITS (0x2 << 4) +#define PEF2256_SIC1_RBS_BYPASS (0x3 << 4) +#define PEF2256_SIC1_XBS_MASK (0x3 << 0) +#define PEF2256_SIC1_XBS_BYPASS (0x0 << 0) +#define PEF2256_SIC1_XBS_1FRAME (0x1 << 0) +#define PEF2256_SIC1_XBS_2FRAMES (0x2 << 0) +#define PEF2256_SIC1_XBS_96BITS (0x3 << 0) +#define PEF2256_SIC2 0x3F /* System Interface Control 2 */ +#define PEF2256_SIC2_SICS_MASK (0x7 << 1) +#define PEF2256_SIC2_SICS(_v) ((_v) << 1) +#define PEF2256_SIC3 0x40 /* System Interface Control 3 */ +#define PEF2256_SIC3_RTRI BIT(5) +#define PEF2256_SIC3_RESX BIT(3) +#define PEF2256_SIC3_RESR BIT(2) +#define PEF2256_CMR1 0x44 /* Clock Mode Register 1 */ +#define PEF2256_CMR1_RS_MASK (0x3 << 4) +#define PEF2256_CMR1_RS_DPLL (0x0 << 4) +#define PEF2256_CMR1_RS_DPLL_LOS_HIGH (0x1 << 4) +#define PEF2256_CMR1_RS_DCOR_2048 (0x2 << 4) +#define PEF2256_CMR1_RS_DCOR_8192 (0x3 << 4) +#define PEF2256_CMR1_DCS BIT(3) +#define PEF2256_CMR2 0x45 /* Clock Mode Register 2 */ +#define PEF2256_CMR2_DCOXC BIT(5) +#define PEF2256_GCR 0x46 /* Global Configuration Register */ +#define PEF2256_GCR_SCI BIT(6) +#define PEF2256_GCR_ECMC BIT(4) +#define PEF2256_PC1 0x80 /* Port Configuration 1 */ +#define PEF2256_PC2 0x81 /* Port Configuration 2 */ +#define PEF2256_PC3 0x82 /* Port Configuration 3 */ +#define PEF2256_PC4 0x83 /* Port Configuration 4 */ +#define PEF2256_12_PC_RPC_MASK (0x7 << 4) +#define PEF2256_12_PC_RPC_SYPR (0x0 << 4) +#define PEF2256_12_PC_RPC_RFM (0x1 << 4) +#define PEF2256_12_PC_RPC_RFMB (0x2 << 4) +#define PEF2256_12_PC_RPC_RSIGM (0x3 << 4) +#define PEF2256_12_PC_RPC_RSIG (0x4 << 4) +#define PEF2256_12_PC_RPC_DLR (0x5 << 4) +#define PEF2256_12_PC_RPC_FREEZE (0x6 << 4) +#define PEF2256_12_PC_RPC_RFSP (0x7 << 4) +#define PEF2256_12_PC_XPC_MASK (0xf << 0) +#define PEF2256_12_PC_XPC_SYPX (0x0 << 0) +#define PEF2256_12_PC_XPC_XFMS (0x1 << 0) +#define PEF2256_12_PC_XPC_XSIG (0x2 << 0) +#define PEF2256_12_PC_XPC_TCLK (0x3 << 0) +#define PEF2256_12_PC_XPC_XMFB (0x4 << 0) +#define PEF2256_12_PC_XPC_XSIGM (0x5 << 0) +#define PEF2256_12_PC_XPC_DLX (0x6 << 0) +#define PEF2256_12_PC_XPC_XCLK (0x7 << 0) +#define PEF2256_12_PC_XPC_XLT (0x8 << 0) +#define PEF2256_2X_PC_RPC_MASK (0xf << 4) +#define PEF2256_2X_PC_RPC_SYPR (0x0 << 4) +#define PEF2256_2X_PC_RPC_RFM (0x1 << 4) +#define PEF2256_2X_PC_RPC_RFMB (0x2 << 4) +#define PEF2256_2X_PC_RPC_RSIGM (0x3 << 4) +#define PEF2256_2X_PC_RPC_RSIG (0x4 << 4) +#define PEF2256_2X_PC_RPC_DLR (0x5 << 4) +#define PEF2256_2X_PC_RPC_FREEZE (0x6 << 4) +#define PEF2256_2X_PC_RPC_RFSP (0x7 << 4) +#define PEF2256_2X_PC_RPC_GPI (0x9 << 4) +#define PEF2256_2X_PC_RPC_GPOH (0xa << 4) +#define PEF2256_2X_PC_RPC_GPOL (0xb << 4) +#define PEF2256_2X_PC_RPC_LOS (0xc << 4) +#define PEF2256_2X_PC_XPC_MASK (0xf << 0) +#define PEF2256_2X_PC_XPC_SYPX (0x0 << 0) +#define PEF2256_2X_PC_XPC_XFMS (0x1 << 0) +#define PEF2256_2X_PC_XPC_XSIG (0x2 << 0) +#define PEF2256_2X_PC_XPC_TCLK (0x3 << 0) +#define PEF2256_2X_PC_XPC_XMFB (0x4 << 0) +#define PEF2256_2X_PC_XPC_XSIGM (0x5 << 0) +#define PEF2256_2X_PC_XPC_DLX (0x6 << 0) +#define PEF2256_2X_PC_XPC_XCLK (0x7 << 0) +#define PEF2256_2X_PC_XPC_XLT (0x8 << 0) +#define PEF2256_2X_PC_XPC_GPI (0x9 << 0) +#define PEF2256_2X_PC_XPC_GPOH (0xa << 0) +#define PEF2256_2X_PC_XPC_GPOL (0xb << 0) +#define PEF2256_PC5 0x84 /* Port Configuration 5 */ +#define PEF2256_PC5_CRP BIT(0) +#define PEF2256_GPC1 0x85 /* Global Port Configuration 1 */ +#define PEF2256_GPC1_CSFP_MASK (0x3 << 5) +#define PEF2256_GPC1_CSFP_SEC_IN_HIGH (0x0 << 5) +#define PEF2256_GPC1_CSFP_SEC_OUT_HIGH (0x1 << 5) +#define PEF2256_GPC1_CSFP_FSC_OUT_HIGH (0x2 << 5) +#define PEF2256_GPC1_CSFP_FSC_OUT_LOW (0x3 << 5) +#define PEF2256_PC6 0x86 /* Port Configuration 6 */ +#define PEF2256_GCM(_n) (0x92 + (_n) - 1) /* Global Counter Mode n=1..8 */ +#define PEF2256_GCM1 0x92 /* Global Counter Mode 1 */ +#define PEF2256_GCM2 0x93 /* Global Counter Mode 2 */ +#define PEF2256_GCM3 0x94 /* Global Counter Mode 3 */ +#define PEF2256_GCM4 0x95 /* Global Counter Mode 4 */ +#define PEF2256_GCM5 0x96 /* Global Counter Mode 5 */ +#define PEF2256_GCM6 0x97 /* Global Counter Mode 6 */ +#define PEF2256_GCM7 0x98 /* Global Counter Mode 7 */ +#define PEF2256_GCM8 0x99 /* Global Counter Mode 8 */ + +#define PEF2256_VSTR 0x4A /* Version Status Register */ +#define PEF2256_VSTR_VERSION_12 0x00 +#define PEF2256_VSTR_VERSION_21 0x10 +#define PEF2256_VSTR_VERSION_2x 0x05 +#define PEF2256_FRS0 0x4C /* Framer Receive Status 0 */ +#define PEF2256_FRS0_LOS BIT(7) +#define PEF2256_FRS0_AIS BIT(6) +#define PEF2256_ISR(_n) (0x68 + (_n)) /* Interrupt Status Register (n=0..5) */ +#define PEF2256_ISR0 0x68 /* Interrupt Status Register 0 */ +#define PEF2256_ISR1 0x69 /* Interrupt Status Register 1 */ +#define PEF2256_ISR2 0x6A /* Interrupt Status Register 2 */ +#define PEF2256_ISR3 0x6B /* Interrupt Status Register 3 */ +#define PEF2256_ISR4 0x6C /* Interrupt Status Register 4 */ +#define PEF2256_ISR5 0x6D /* Interrupt Status Register 5 */ +#define PEF2256_GIS 0x6E /* Global Interrupt Status */ +#define PEF2256_GIS_ISR(_n) (1 << (_n)) +#define PEF2256_WID 0xEC /* Wafer Identification Register */ +#define PEF2256_12_WID_MASK 0x03 +#define PEF2256_12_WID_VERSION_12 0x03 +#define PEF2256_2X_WID_MASK 0xc0 +#define PEF2256_2X_WID_VERSION_21 0x00 +#define PEF2256_2X_WID_VERSION_22 0x40 + +/* IMR2/ISR2 Interrupts */ +#define PEF2256_INT2_AIS BIT(3) +#define PEF2256_INT2_LOS BIT(2) + +enum pef2256_version { + PEF2256_VERSION_UNKNOWN, + PEF2256_VERSION_1_2, + PEF2256_VERSION_2_1, + PEF2256_VERSION_2_2, +}; + +enum pef2256_frame_type { + PEF2256_FRAME_E1_DOUBLEFRAME, + PEF2256_FRAME_E1_CRC4_MULTIFRAME, + PEF2256_FRAME_E1_AUTO_MULTIFRAME, + PEF2256_FRAME_T1J1_4FRAME, + PEF2256_FRAME_T1J1_12FRAME, + PEF2256_FRAME_T1J1_24FRAME, + PEF2256_FRAME_T1J1_72FRAME, +}; + +struct pef2256_pinreg_desc { + int offset; + u8 mask; +}; + +struct pef2256_function_desc { + const char *name; + const char * const*groups; + unsigned int ngroups; + u8 func_val; +}; + +struct pef2256 { + struct device *dev; + void *__iomem regs; + enum pef2256_version version; + struct clk *mclk; + struct clk *sclkr; + struct clk *sclkx; + struct gpio_desc *reset_gpio; + struct { + struct pinctrl_desc pctrl_desc; + const struct pef2256_function_desc *functions; + unsigned int nfunctions; + } pinctrl; + bool is_e1; + unsigned long sysclk_rate; + u32 data_rate; + bool is_tx_falling_edge; + bool is_subordinate; + enum pef2256_frame_type frame_type; + u8 channel_phase; + atomic_t carrier; + struct atomic_notifier_head event_notifier_list; +}; + +static inline u8 pef2256_read8(struct pef2256 *pef2256, int offset) +{ + return ioread8(pef2256->regs + offset); +} + +static inline void pef2256_write8(struct pef2256 *pef2256, int offset, u8 val) +{ + iowrite8(val, pef2256->regs + offset); +} + +static inline void pef2256_clrbits8(struct pef2256 *pef2256, int offset, u8 clr) +{ + pef2256_write8(pef2256, offset, pef2256_read8(pef2256, offset) & ~clr); +} + +static inline void pef2256_setbits8(struct pef2256 *pef2256, int offset, u8 set) +{ + pef2256_write8(pef2256, offset, pef2256_read8(pef2256, offset) | set); +} + + +static inline void pef2256_clrsetbits8(struct pef2256 *pef2256, int offset, u8 clr, u8 set) +{ + u8 v; + + v = pef2256_read8(pef2256, offset); + v &= ~clr; + v |= set; + pef2256_write8(pef2256, offset, v); +} + +static enum pef2256_version pef2256_get_version(struct pef2256 *pef2256) +{ + enum pef2256_version version = PEF2256_VERSION_UNKNOWN; + const char *version_txt; + u8 vstr, wid; + + vstr = pef2256_read8(pef2256, PEF2256_VSTR); + wid = pef2256_read8(pef2256, PEF2256_WID); + + switch (vstr) { + case PEF2256_VSTR_VERSION_12: + if ((wid & PEF2256_12_WID_MASK) == PEF2256_12_WID_VERSION_12) { + version_txt = "1.2"; + version = PEF2256_VERSION_1_2; + } + break; + case PEF2256_VSTR_VERSION_2x: + switch (wid & PEF2256_2X_WID_MASK) { + case PEF2256_2X_WID_VERSION_21: + version_txt = "2.1 (2.x)"; + version = PEF2256_VERSION_2_1; + break; + case PEF2256_2X_WID_VERSION_22: + version_txt = "2.2 (2.x)"; + version = PEF2256_VERSION_2_2; + break; + } + break; + case PEF2256_VSTR_VERSION_21: + version_txt = "2.1"; + version = PEF2256_VERSION_2_1; + break; + } + + if (version == PEF2256_VERSION_UNKNOWN) + dev_err(pef2256->dev, "Unknown version (0x%02x, 0x%02x)\n", vstr, wid); + else + dev_info(pef2256->dev, "Version %s detected\n", version_txt); + + return version; +} + +enum pef2256_gcm_config_item { + PEF2256_GCM_CONFIG_1544000 = 0, + PEF2256_GCM_CONFIG_2048000, + PEF2256_GCM_CONFIG_8192000, + PEF2256_GCM_CONFIG_10000000, + PEF2256_GCM_CONFIG_12352000, + PEF2256_GCM_CONFIG_16384000, +}; + +struct pef2256_gcm_config { + u8 gcm_12[6]; + u8 gcm_2x[8]; +}; + +static const struct pef2256_gcm_config pef2256_gcm_configs[] = { + [PEF2256_GCM_CONFIG_1544000] = { + .gcm_12 = {0xF0, 0x51, 0x00, 0x80, 0x00, 0x15}, + .gcm_2x = {0x00, 0x15, 0x00, 0x08, 0x00, 0x3F, 0x9C, 0xDF}, + }, + [PEF2256_GCM_CONFIG_2048000] = { + .gcm_12 = {0x00, 0x58, 0xD2, 0xC2, 0x00, 0x10}, + .gcm_2x = {0x00, 0x18, 0xFB, 0x0B, 0x00, 0x2F, 0xDB, 0xDF}, + }, + [PEF2256_GCM_CONFIG_8192000] = { + .gcm_12 = {0x00, 0x58, 0xD2, 0xC2, 0x03, 0x10}, + .gcm_2x = {0x00, 0x18, 0xFB, 0x0B, 0x00, 0x0B, 0xDB, 0xDF}, + }, + [PEF2256_GCM_CONFIG_10000000] = { + .gcm_12 = {0x90, 0x51, 0x81, 0x8F, 0x04, 0x10}, + .gcm_2x = {0x40, 0x1B, 0x3D, 0x0A, 0x00, 0x07, 0xC9, 0xDC}, + }, + [PEF2256_GCM_CONFIG_12352000] = { + .gcm_12 = {0xF0, 0x51, 0x00, 0x80, 0x07, 0x15}, + .gcm_2x = {0x00, 0x19, 0x00, 0x08, 0x01, 0x0A, 0x98, 0xDA}, + }, + [PEF2256_GCM_CONFIG_16384000] = { + .gcm_12 = {0x00, 0x58, 0xD2, 0xC2, 0x07, 0x10}, + .gcm_2x = {0x00, 0x18, 0xFB, 0x0B, 0x01, 0x0B, 0xDB, 0xDF}, + }, +}; + +static int pef2256_setup_gcm(struct pef2256 *pef2256) +{ + enum pef2256_gcm_config_item item; + unsigned long mclk_rate; + const u8 *gcm; + int i, count; + + mclk_rate = clk_get_rate(pef2256->mclk); + switch (mclk_rate) { + case 1544000: + item = PEF2256_GCM_CONFIG_1544000; + break; + case 2048000: + item = PEF2256_GCM_CONFIG_2048000; + break; + case 8192000: + item = PEF2256_GCM_CONFIG_8192000; + break; + case 10000000: + item = PEF2256_GCM_CONFIG_10000000; + break; + case 12352000: + item = PEF2256_GCM_CONFIG_12352000; + break; + case 16384000: + item = PEF2256_GCM_CONFIG_16384000; + break; + default: + dev_err(pef2256->dev, "Unsupported v2.x MCLK rate %lu\n", mclk_rate); + return -EINVAL; + } + + BUILD_BUG_ON(item >= ARRAY_SIZE(pef2256_gcm_configs)); + + if (pef2256->version == PEF2256_VERSION_1_2) { + gcm = pef2256_gcm_configs[item].gcm_12; + count = ARRAY_SIZE(pef2256_gcm_configs[item].gcm_12); + } else { + gcm = pef2256_gcm_configs[item].gcm_2x; + count = ARRAY_SIZE(pef2256_gcm_configs[item].gcm_2x); + } + + for (i = 0; i < count; i++) + pef2256_write8(pef2256, PEF2256_GCM(i+1), *(gcm + i)); + + return 0; +} + +static int pef2256_setup_e1(struct pef2256 *pef2256) +{ + u8 fmr1, fmr2, sic1; + int ret; + + /* Basic setup, Master clocking mode (GCM8..1) */ + ret = pef2256_setup_gcm(pef2256); + if (ret) + return ret; + + /* RCLK output : DPLL clock, DCO-X enabled, DCO-X internal ref clock */ + pef2256_write8(pef2256, PEF2256_CMR1, 0x00); + + /* + * SCLKR selected, SCLKX selected, + * receive synchro pulse sourced by SYPR, + * transmit synchro pulse sourced by SYPX + */ + pef2256_write8(pef2256, PEF2256_CMR2, 0x00); + + /* NRZ coding, no alarm simulation */ + pef2256_write8(pef2256, PEF2256_FMR0, 0x00); + + /* + * E1, frame format, 2 Mbit/s system data rate, no AIS + * transmission to remote end or system interface, payload loop + * off, transmit remote alarm on + */ + fmr1 = 0x00; + fmr2 = PEF2256_FMR2_AXRA; + switch (pef2256->frame_type) { + case PEF2256_FRAME_E1_DOUBLEFRAME: + fmr2 |= PEF2256_FMR2_RFS_DOUBLEFRAME; + break; + case PEF2256_FRAME_E1_CRC4_MULTIFRAME: + fmr1 |= PEF2256_FMR1_XFS; + fmr2 |= PEF2256_FMR2_RFS_CRC4_MULTIFRAME; + break; + case PEF2256_FRAME_E1_AUTO_MULTIFRAME: + fmr1 |= PEF2256_FMR1_XFS; + fmr2 |= PEF2256_FMR2_RFS_AUTO_MULTIFRAME; + break; + default: + dev_err(pef2256->dev, "Unsupported frame type %d\n", pef2256->frame_type); + return -EINVAL; + } + pef2256_write8(pef2256, PEF2256_FMR1, fmr1); + pef2256_write8(pef2256, PEF2256_FMR2, fmr2); + + /* E1 default for the receive slicer threshold */ + pef2256_write8(pef2256, PEF2256_LIM2, PEF2256_LIM2_SLT_THR50); + if (!pef2256->is_subordinate) { + /* SEC input, active high */ + pef2256_write8(pef2256, PEF2256_GPC1, PEF2256_GPC1_CSFP_SEC_IN_HIGH); + } else { + /* Loop-timed */ + pef2256_setbits8(pef2256, PEF2256_LIM2, PEF2256_LIM2_ELT); + /* FSC output, active high */ + pef2256_write8(pef2256, PEF2256_GPC1, PEF2256_GPC1_CSFP_FSC_OUT_HIGH); + } + + /* internal second timer, power on */ + pef2256_write8(pef2256, PEF2256_GCR, 0x00); + + /* + * slave mode, local loop off, mode short-haul + * In v2.x, bit3 is a forced 1 bit in the datasheet -> Need to be set. + */ + if (pef2256->version == PEF2256_VERSION_1_2) + pef2256_write8(pef2256, PEF2256_LIM0, 0x00); + else + pef2256_write8(pef2256, PEF2256_LIM0, PEF2256_2X_LIM0_BIT3); + + /* analog interface selected, remote loop off */ + pef2256_write8(pef2256, PEF2256_LIM1, 0x00); + + /* + * SCLKR, SCLKX, RCLK configured to inputs, + * XFMS active low, CLK1 and CLK2 pin configuration + */ + pef2256_write8(pef2256, PEF2256_PC5, 0x00); + pef2256_write8(pef2256, PEF2256_PC6, 0x00); + + /* + * 2.048 MHz system clocking rate, receive buffer 2 frames, transmit + * buffer bypass, data sampled and transmitted on the falling edge of + * SCLKR/X, automatic freeze signaling, data is active in the first + * channel phase + */ + pef2256_write8(pef2256, PEF2256_SIC1, 0x00); + pef2256_write8(pef2256, PEF2256_SIC2, 0x00); + pef2256_write8(pef2256, PEF2256_SIC3, 0x00); + + /* channel loop-back and single frame mode are disabled */ + pef2256_write8(pef2256, PEF2256_LOOP, 0x00); + + /* all bits of the transmitted service word are cleared */ + pef2256_write8(pef2256, PEF2256_XSW, PEF2256_XSW_XY(0x1F)); + /* CAS disabled and clear spare bit values */ + pef2256_write8(pef2256, PEF2256_XSP, 0x00); + + /* no transparent mode active */ + pef2256_write8(pef2256, PEF2256_TSWM, 0x00); + + /* + * the transmit clock offset is cleared + * the transmit time slot offset is cleared + */ + pef2256_write8(pef2256, PEF2256_XC0, 0x00); + + /* Keep default value for the transmit offset */ + pef2256_write8(pef2256, PEF2256_XC1, 0x9C); + + /* + * transmit pulse mask, default value from datasheet + * transmitter in tristate mode + */ + if (pef2256->version == PEF2256_VERSION_1_2) + pef2256_write8(pef2256, PEF2256_XPM0, 0x7B); + else + pef2256_write8(pef2256, PEF2256_XPM0, 0x9C); + pef2256_write8(pef2256, PEF2256_XPM1, 0x03); + pef2256_write8(pef2256, PEF2256_XPM2, PEF2256_XPM2_XLT | 0x00); + + /* "master" mode */ + if (!pef2256->is_subordinate) + pef2256_setbits8(pef2256, PEF2256_LIM0, PEF2256_LIM0_MAS); + + /* transmit line in normal operation */ + pef2256_clrbits8(pef2256, PEF2256_XPM2, PEF2256_XPM2_XLT); + + /* receive input threshold = 0,21V */ + if (pef2256->version == PEF2256_VERSION_1_2) + pef2256_clrsetbits8(pef2256, PEF2256_LIM1, PEF2256_12_LIM1_RIL_MASK, + PEF2256_12_LIM1_RIL_210); + else + pef2256_clrsetbits8(pef2256, PEF2256_LIM1, PEF2256_2X_LIM1_RIL_MASK, + PEF2256_2X_LIM1_RIL_210); + + /* transmit line coding = HDB3 */ + pef2256_clrsetbits8(pef2256, PEF2256_FMR0, PEF2256_FMR0_XC_MASK, PEF2256_FMR0_XC_HDB3); + + /* receive line coding = HDB3 */ + pef2256_clrsetbits8(pef2256, PEF2256_FMR0, PEF2256_FMR0_RC_MASK, PEF2256_FMR0_RC_HDB3); + + /* detection of LOS alarm = 176 pulses (ie (10 + 1) * 16) */ + pef2256_write8(pef2256, PEF2256_PCD, 10); + + /* recovery of LOS alarm = 22 pulses (ie 21 + 1) */ + pef2256_write8(pef2256, PEF2256_PCR, 21); + + /* DCO-X center frequency enabled */ + pef2256_setbits8(pef2256, PEF2256_CMR2, PEF2256_CMR2_DCOXC); + + if (pef2256->is_subordinate) { + /* select RCLK source = 2M, disable switching from RCLK to SYNC */ + pef2256_clrsetbits8(pef2256, PEF2256_CMR1, PEF2256_CMR1_RS_MASK, + PEF2256_CMR1_RS_DCOR_2048); + pef2256_setbits8(pef2256, PEF2256_CMR1, PEF2256_CMR1_DCS); + + /* transmit buffer size = 2 frames, transparent mode */ + pef2256_clrsetbits8(pef2256, PEF2256_SIC1, PEF2256_SIC1_XBS_MASK, + PEF2256_SIC1_XBS_2FRAMES); + pef2256_setbits8(pef2256, PEF2256_XSW, PEF2256_XSW_XTM); + } + + if (pef2256->version != PEF2256_VERSION_1_2) { + /* during inactive channel phase switch RDO/RSIG into tri-state */ + pef2256_setbits8(pef2256, PEF2256_SIC3, PEF2256_SIC3_RTRI); + } + + if (pef2256->is_tx_falling_edge) { + /* falling edge sync pulse transmit, rising edge sync pulse receive */ + pef2256_clrsetbits8(pef2256, PEF2256_SIC3, PEF2256_SIC3_RESX, PEF2256_SIC3_RESR); + } else { + /* rising edge sync pulse transmit, falling edge sync pulse receive */ + pef2256_clrsetbits8(pef2256, PEF2256_SIC3, PEF2256_SIC3_RESR, PEF2256_SIC3_RESX); + } + + /* transmit offset counter (XCO10..0) = 4 */ + pef2256_write8(pef2256, PEF2256_XC0, 0); + pef2256_write8(pef2256, PEF2256_XC1, 4); + /* receive offset counter (RCO10..0) = 4 */ + pef2256_write8(pef2256, PEF2256_RC0, 0); + pef2256_write8(pef2256, PEF2256_RC1, 4); + + /* system clock rate */ + switch (pef2256->sysclk_rate) { + case 2048000: + sic1 = PEF2256_SIC1_SSC_2048; + break; + case 4096000: + sic1 = PEF2256_SIC1_SSC_4096; + break; + case 8192000: + sic1 = PEF2256_SIC1_SSC_8192; + break; + case 16384000: + sic1 = PEF2256_SIC1_SSC_16384; + break; + default: + dev_err(pef2256->dev, "Unsupported sysclk rate %lu\n", pef2256->sysclk_rate); + return -EINVAL; + } + pef2256_clrsetbits8(pef2256, PEF2256_SIC1, PEF2256_SIC1_SSC_MASK, sic1); + + /* data clock rate */ + switch (pef2256->data_rate) { + case 2048000: + fmr1 = PEF2256_FMR1_SSD_2048; + sic1 = PEF2256_SIC1_SSD_2048; + break; + case 4096000: + fmr1 = PEF2256_FMR1_SSD_4096; + sic1 = PEF2256_SIC1_SSD_4096; + break; + case 8192000: + fmr1 = PEF2256_FMR1_SSD_8192; + sic1 = PEF2256_SIC1_SSD_8192; + break; + case 16384000: + fmr1 = PEF2256_FMR1_SSD_16384; + sic1 = PEF2256_SIC1_SSD_16384; + break; + default: + dev_err(pef2256->dev, "Unsupported data rate %u\n", pef2256->data_rate); + return -EINVAL; + } + pef2256_clrsetbits8(pef2256, PEF2256_FMR1, PEF2256_FMR1_SSD_MASK, fmr1); + pef2256_clrsetbits8(pef2256, PEF2256_SIC1, PEF2256_SIC1_SSD_MASK, sic1); + + /* channel phase */ + pef2256_clrsetbits8(pef2256, PEF2256_SIC2, PEF2256_SIC2_SICS_MASK, + PEF2256_SIC2_SICS(pef2256->channel_phase)); + + /* error counter latched every 1s */ + pef2256_setbits8(pef2256, PEF2256_FMR1, PEF2256_FMR1_ECM); + /* error counter mode COFA */ + pef2256_setbits8(pef2256, PEF2256_GCR, PEF2256_GCR_ECMC); + /* errors in service words have no influence */ + pef2256_setbits8(pef2256, PEF2256_RC0, PEF2256_RC0_SWD); + /* 4 consecutive incorrect FAS causes loss of sync */ + pef2256_setbits8(pef2256, PEF2256_RC0, PEF2256_RC0_ASY4); + /* Si-Bit, Spare bit For International, FAS word */ + pef2256_setbits8(pef2256, PEF2256_XSW, PEF2256_XSW_XSIS); + pef2256_setbits8(pef2256, PEF2256_XSP, PEF2256_XSP_XSIF); + + /* port RCLK is output */ + pef2256_setbits8(pef2256, PEF2256_PC5, PEF2256_PC5_CRP); + /* status changed interrupt at both up and down */ + pef2256_setbits8(pef2256, PEF2256_GCR, PEF2256_GCR_SCI); + + /* Clear any ISR2 pending interrupts and unmask needed interrupts */ + pef2256_read8(pef2256, PEF2256_ISR2); + pef2256_clrbits8(pef2256, PEF2256_IMR2, PEF2256_INT2_LOS | PEF2256_INT2_AIS); + + /* reset lines */ + pef2256_write8(pef2256, PEF2256_CMDR, PEF2256_CMDR_RRES | PEF2256_CMDR_XRES); + return 0; +} + +static int pef2256_setup(struct pef2256 *pef2256) +{ + if (pef2256->is_e1) + return pef2256_setup_e1(pef2256); + + dev_err(pef2256->dev, "Only E1 line is currently supported\n"); + return -EOPNOTSUPP; +} + + + +static void pef2256_isr_default_handler(struct pef2256 *pef2256, u8 nbr, u8 isr) +{ + dev_warn(pef2256->dev, "ISR%u: 0x%02x not handled\n", nbr, isr); +} + +static bool pef2256_is_carrier_on(struct pef2256 *pef2256) +{ + u8 frs0; + + frs0 = pef2256_read8(pef2256, PEF2256_FRS0); + return !(frs0 & (PEF2256_FRS0_LOS | PEF2256_FRS0_AIS)); +} + +static void pef2256_isr2_handler(struct pef2256 *pef2256, u8 nbr, u8 isr) +{ + bool carrier; + + if (isr & (PEF2256_INT2_LOS | PEF2256_INT2_AIS)) { + carrier = pef2256_is_carrier_on(pef2256); + if (atomic_xchg(&pef2256->carrier, carrier) != carrier) + atomic_notifier_call_chain(&pef2256->event_notifier_list, + PEF2256_EVENT_CARRIER, NULL); + } +} + +static irqreturn_t pef2256_irq_handler(int irq, void *priv) +{ + void (*pef2256_isr_handler[])(struct pef2256 *, u8, u8) = { + [0] = pef2256_isr_default_handler, + [1] = pef2256_isr_default_handler, + [2] = pef2256_isr2_handler, + [3] = pef2256_isr_default_handler, + [4] = pef2256_isr_default_handler, + [5] = pef2256_isr_default_handler + }; + struct pef2256 *pef2256 = (struct pef2256 *)priv; + u8 gis; + u8 isr; + u8 n; + + gis = pef2256_read8(pef2256, PEF2256_GIS); + + for (n = 0; n < ARRAY_SIZE(pef2256_isr_handler) ; n++) { + if (gis & PEF2256_GIS_ISR(n)) { + isr = pef2256_read8(pef2256, PEF2256_ISR(n)); + pef2256_isr_handler[n](pef2256, n, isr); + } + } + + return IRQ_HANDLED; +} + +static int pef2256_check_rates(struct pef2256 *pef2256, unsigned long sysclk_rate, + unsigned long data_rate) +{ + unsigned long rate; + + switch (sysclk_rate) { + case 2048000: + case 4096000: + case 8192000: + case 16384000: + break; + default: + dev_err(pef2256->dev, "Unsupported system clock rate %lu\n", sysclk_rate); + return -EINVAL; + } + + for (rate = data_rate; rate <= data_rate * 4; rate *= 2) { + if (rate == sysclk_rate) + return 0; + } + dev_err(pef2256->dev, "Unsupported data rate %lu with system clock rate %lu\n", + data_rate, sysclk_rate); + return -EINVAL; +} + +static int pef2556_of_parse(struct pef2256 *pef2256, struct device_node *np) +{ + const char *str; + int ret; + + str = "e1"; + ret = of_property_read_string(np, "lantiq,line-interface", &str); + if (ret && ret != -EINVAL) { + dev_err(pef2256->dev, "%pOF: failed to read lantiq,line-interface\n", + np); + return ret; + } + if (!strcmp(str, "e1")) { + pef2256->is_e1 = true; + } else if (!strcmp(str, "t1j1")) { + pef2256->is_e1 = false; + } else { + dev_err(pef2256->dev, "%pOF: Invalid lantiq,line-interface (%s)\n", + np, str); + return -EINVAL; + } + dev_dbg(pef2256->dev, "config: %s line\n", pef2256->is_e1 ? "E1" : "T1/J1"); + + pef2256->data_rate = 2048000; + ret = of_property_read_u32(np, "lantiq,data-rate-bps", &pef2256->data_rate); + if (ret && ret != -EINVAL) { + dev_err(pef2256->dev, "%pOF: failed to read lantiq,data-rate-bps\n", np); + return ret; + } + dev_dbg(pef2256->dev, "config: data rate %u bps\n", pef2256->data_rate); + + ret = pef2256_check_rates(pef2256, pef2256->sysclk_rate, pef2256->data_rate); + if (ret) + return ret; + + pef2256->is_tx_falling_edge = of_property_read_bool(np, "lantiq,clock-falling-edge"); + dev_dbg(pef2256->dev, "config: tx on %s edge\n", + pef2256->is_tx_falling_edge ? "falling" : "rising"); + + pef2256->is_subordinate = of_property_read_bool(np, "lantiq,subordinate"); + dev_dbg(pef2256->dev, "config: subordinate %s\n", + pef2256->is_subordinate ? "on" : "off"); + + str = pef2256->is_e1 ? "doubleframe" : "12frame"; + ret = of_property_read_string(np, "lantiq,frame-format", &str); + if (ret && ret != -EINVAL) { + dev_err(pef2256->dev, "%pOF: failed to read lantiq,frame-format\n", + np); + return ret; + } + if (pef2256->is_e1) { + if (!strcmp(str, "doubleframe")) { + pef2256->frame_type = PEF2256_FRAME_E1_DOUBLEFRAME; + } else if (!strcmp(str, "crc4-multiframe")) { + pef2256->frame_type = PEF2256_FRAME_E1_CRC4_MULTIFRAME; + } else if (!strcmp(str, "auto-multiframe")) { + pef2256->frame_type = PEF2256_FRAME_E1_AUTO_MULTIFRAME; + } else { + dev_err(pef2256->dev, "%pOF: Invalid lantiq,frame-format (%s)\n", + np, str); + return -EINVAL; + } + } else { + if (!strcmp(str, "4frame")) { + pef2256->frame_type = PEF2256_FRAME_T1J1_4FRAME; + } else if (!strcmp(str, "12frame")) { + pef2256->frame_type = PEF2256_FRAME_T1J1_12FRAME; + } else if (!strcmp(str, "24frame")) { + pef2256->frame_type = PEF2256_FRAME_T1J1_24FRAME; + } else if (!strcmp(str, "72frame")) { + pef2256->frame_type = PEF2256_FRAME_T1J1_72FRAME; + } else { + dev_err(pef2256->dev, "%pOF: Invalid lantiq,frame-format (%s)\n", + np, str); + return -EINVAL; + } + } + dev_dbg(pef2256->dev, "config: frame type %d\n", pef2256->frame_type); + + pef2256->channel_phase = 0; + ret = of_property_read_u8(np, "lantiq,channel-phase", &pef2256->channel_phase); + if (ret && ret != -EINVAL) { + dev_err(pef2256->dev, "%pOF: failed to read lantiq,channel-phase\n", + np); + return ret; + } + if (pef2256->channel_phase >= pef2256->sysclk_rate / pef2256->data_rate) { + dev_err(pef2256->dev, "%pOF: Invalid lantiq,channel-phase %u\n", + np, pef2256->channel_phase); + return -EINVAL; + } + dev_dbg(pef2256->dev, "config: channel phase %u\n", pef2256->channel_phase); + + return 0; +} + +static int pef2256_get_groups_count(struct pinctrl_dev *pctldev) +{ + struct pef2256 *pef2256 = pinctrl_dev_get_drvdata(pctldev); + + /* We map 1 group <-> 1 pin */ + return pef2256->pinctrl.pctrl_desc.npins; +} + +static const char *pef2256_get_group_name(struct pinctrl_dev *pctldev, + unsigned int selector) +{ + struct pef2256 *pef2256 = pinctrl_dev_get_drvdata(pctldev); + + /* We map 1 group <-> 1 pin */ + return pef2256->pinctrl.pctrl_desc.pins[selector].name; +} + +static int pef2256_get_group_pins(struct pinctrl_dev *pctldev, unsigned int selector, + const unsigned int **pins, + unsigned int *num_pins) +{ + struct pef2256 *pef2256 = pinctrl_dev_get_drvdata(pctldev); + + /* We map 1 group <-> 1 pin */ + *pins = &pef2256->pinctrl.pctrl_desc.pins[selector].number; + *num_pins = 1; + + return 0; +} + +static const struct pinctrl_ops pef2256_pctlops = { + .get_groups_count = pef2256_get_groups_count, + .get_group_name = pef2256_get_group_name, + .get_group_pins = pef2256_get_group_pins, + .dt_node_to_map = pinconf_generic_dt_node_to_map_pin, + .dt_free_map = pinconf_generic_dt_free_map, +}; + +static int pef2256_get_functions_count(struct pinctrl_dev *pctldev) +{ + struct pef2256 *pef2256 = pinctrl_dev_get_drvdata(pctldev); + + return pef2256->pinctrl.nfunctions; +} + +static const char *pef2256_get_function_name(struct pinctrl_dev *pctldev, + unsigned int selector) +{ + struct pef2256 *pef2256 = pinctrl_dev_get_drvdata(pctldev); + + return pef2256->pinctrl.functions[selector].name; +} + + +static int pef2256_get_function_groups(struct pinctrl_dev *pctldev, unsigned int selector, + const char * const **groups, + unsigned * const num_groups) +{ + struct pef2256 *pef2256 = pinctrl_dev_get_drvdata(pctldev); + + *groups = pef2256->pinctrl.functions[selector].groups; + *num_groups = pef2256->pinctrl.functions[selector].ngroups; + return 0; +} + +static int pef2256_set_mux(struct pinctrl_dev *pctldev, unsigned int func_selector, + unsigned int group_selector) +{ + struct pef2256 *pef2256 = pinctrl_dev_get_drvdata(pctldev); + const struct pef2256_pinreg_desc *pinreg_desc; + u8 func_val; + + dev_dbg(pef2256->dev, "set %s to %s function\n", + pef2256->pinctrl.pctrl_desc.pins[group_selector].name, + pef2256->pinctrl.functions[func_selector].name); + + /* We map 1 group <-> 1 pin */ + pinreg_desc = pef2256->pinctrl.pctrl_desc.pins[group_selector].drv_data; + func_val = pef2256->pinctrl.functions[func_selector].func_val; + + pef2256_clrsetbits8(pef2256, pinreg_desc->offset, pinreg_desc->mask, + func_val & pinreg_desc->mask); + + return 0; +} + +static const struct pinmux_ops pef2256_pmxops = { + .get_functions_count = pef2256_get_functions_count, + .get_function_name = pef2256_get_function_name, + .get_function_groups = pef2256_get_function_groups, + .set_mux = pef2256_set_mux, +}; + +#define PEF2256_PINCTRL_PIN(_number, _name, _offset, _mask) { \ + .number = _number, \ + .name = _name, \ + .drv_data = &(struct pef2256_pinreg_desc) { \ + .offset = _offset, \ + .mask = _mask, \ + }, \ +} + +static const struct pinctrl_pin_desc pef2256_v12_pins[] = { + PEF2256_PINCTRL_PIN(0, "RPA", PEF2256_PC1, PEF2256_12_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(1, "RPB", PEF2256_PC2, PEF2256_12_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(2, "RPC", PEF2256_PC3, PEF2256_12_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(3, "RPD", PEF2256_PC4, PEF2256_12_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(4, "XPA", PEF2256_PC1, PEF2256_12_PC_XPC_MASK), + PEF2256_PINCTRL_PIN(5, "XPB", PEF2256_PC2, PEF2256_12_PC_XPC_MASK), + PEF2256_PINCTRL_PIN(6, "XPC", PEF2256_PC3, PEF2256_12_PC_XPC_MASK), + PEF2256_PINCTRL_PIN(7, "XPD", PEF2256_PC4, PEF2256_12_PC_XPC_MASK), +}; + +static const struct pinctrl_pin_desc pef2256_v2x_pins[] = { + PEF2256_PINCTRL_PIN(0, "RPA", PEF2256_PC1, PEF2256_2X_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(1, "RPB", PEF2256_PC2, PEF2256_2X_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(2, "RPC", PEF2256_PC3, PEF2256_2X_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(3, "RPD", PEF2256_PC4, PEF2256_2X_PC_RPC_MASK), + PEF2256_PINCTRL_PIN(4, "XPA", PEF2256_PC1, PEF2256_2X_PC_XPC_MASK), + PEF2256_PINCTRL_PIN(5, "XPB", PEF2256_PC2, PEF2256_2X_PC_XPC_MASK), + PEF2256_PINCTRL_PIN(6, "XPC", PEF2256_PC3, PEF2256_2X_PC_XPC_MASK), + PEF2256_PINCTRL_PIN(7, "XPD", PEF2256_PC4, PEF2256_2X_PC_XPC_MASK), +}; + +static const char *const pef2256_rp_groups[] = { "RPA", "RPB", "RPC", "RPD" }; +static const char *const pef2256_xp_groups[] = { "XPA", "XPB", "XPC", "XPD" }; +static const char *const pef2256_all_groups[] = { "RPA", "RPB", "RPC", "RPD", + "XPA", "XPB", "XPC", "XPD" }; + +#define PEF2256_FUNCTION(_name, _func_val, _groups) { \ + .name = _name, \ + .groups = _groups, \ + .ngroups = ARRAY_SIZE(_groups), \ + .func_val = _func_val, \ +} + +static const struct pef2256_function_desc pef2256_v2x_functions[] = { + PEF2256_FUNCTION("SYPR", PEF2256_2X_PC_RPC_SYPR, pef2256_rp_groups), + PEF2256_FUNCTION("RFM", PEF2256_2X_PC_RPC_RFM, pef2256_rp_groups), + PEF2256_FUNCTION("RFMB", PEF2256_2X_PC_RPC_RFMB, pef2256_rp_groups), + PEF2256_FUNCTION("RSIGM", PEF2256_2X_PC_RPC_RSIGM, pef2256_rp_groups), + PEF2256_FUNCTION("RSIG", PEF2256_2X_PC_RPC_RSIG, pef2256_rp_groups), + PEF2256_FUNCTION("DLR", PEF2256_2X_PC_RPC_DLR, pef2256_rp_groups), + PEF2256_FUNCTION("FREEZE", PEF2256_2X_PC_RPC_FREEZE, pef2256_rp_groups), + PEF2256_FUNCTION("RFSP", PEF2256_2X_PC_RPC_RFSP, pef2256_rp_groups), + PEF2256_FUNCTION("LOS", PEF2256_2X_PC_RPC_LOS, pef2256_rp_groups), + + PEF2256_FUNCTION("SYPX", PEF2256_2X_PC_XPC_SYPX, pef2256_xp_groups), + PEF2256_FUNCTION("XFMS", PEF2256_2X_PC_XPC_XFMS, pef2256_xp_groups), + PEF2256_FUNCTION("XSIG", PEF2256_2X_PC_XPC_XSIG, pef2256_xp_groups), + PEF2256_FUNCTION("TCLK", PEF2256_2X_PC_XPC_TCLK, pef2256_xp_groups), + PEF2256_FUNCTION("XMFB", PEF2256_2X_PC_XPC_XMFB, pef2256_xp_groups), + PEF2256_FUNCTION("XSIGM", PEF2256_2X_PC_XPC_XSIGM, pef2256_xp_groups), + PEF2256_FUNCTION("DLX", PEF2256_2X_PC_XPC_DLX, pef2256_xp_groups), + PEF2256_FUNCTION("XCLK", PEF2256_2X_PC_XPC_XCLK, pef2256_xp_groups), + PEF2256_FUNCTION("XLT", PEF2256_2X_PC_XPC_XLT, pef2256_xp_groups), + + PEF2256_FUNCTION("GPI", PEF2256_2X_PC_RPC_GPI | PEF2256_2X_PC_XPC_GPI, + pef2256_all_groups), + PEF2256_FUNCTION("GPOH", PEF2256_2X_PC_RPC_GPOH | PEF2256_2X_PC_XPC_GPOH, + pef2256_all_groups), + PEF2256_FUNCTION("GPOL", PEF2256_2X_PC_RPC_GPOL | PEF2256_2X_PC_XPC_GPOL, + pef2256_all_groups), +}; + +static const struct pef2256_function_desc pef2256_v12_functions[] = { + PEF2256_FUNCTION("SYPR", PEF2256_12_PC_RPC_SYPR, pef2256_rp_groups), + PEF2256_FUNCTION("RFM", PEF2256_12_PC_RPC_RFM, pef2256_rp_groups), + PEF2256_FUNCTION("RFMB", PEF2256_12_PC_RPC_RFMB, pef2256_rp_groups), + PEF2256_FUNCTION("RSIGM", PEF2256_12_PC_RPC_RSIGM, pef2256_rp_groups), + PEF2256_FUNCTION("RSIG", PEF2256_12_PC_RPC_RSIG, pef2256_rp_groups), + PEF2256_FUNCTION("DLR", PEF2256_12_PC_RPC_DLR, pef2256_rp_groups), + PEF2256_FUNCTION("FREEZE", PEF2256_12_PC_RPC_FREEZE, pef2256_rp_groups), + PEF2256_FUNCTION("RFSP", PEF2256_12_PC_RPC_RFSP, pef2256_rp_groups), + + PEF2256_FUNCTION("SYPX", PEF2256_12_PC_XPC_SYPX, pef2256_xp_groups), + PEF2256_FUNCTION("XFMS", PEF2256_12_PC_XPC_XFMS, pef2256_xp_groups), + PEF2256_FUNCTION("XSIG", PEF2256_12_PC_XPC_XSIG, pef2256_xp_groups), + PEF2256_FUNCTION("TCLK", PEF2256_12_PC_XPC_TCLK, pef2256_xp_groups), + PEF2256_FUNCTION("XMFB", PEF2256_12_PC_XPC_XMFB, pef2256_xp_groups), + PEF2256_FUNCTION("XSIGM", PEF2256_12_PC_XPC_XSIGM, pef2256_xp_groups), + PEF2256_FUNCTION("DLX", PEF2256_12_PC_XPC_DLX, pef2256_xp_groups), + PEF2256_FUNCTION("XCLK", PEF2256_12_PC_XPC_XCLK, pef2256_xp_groups), + PEF2256_FUNCTION("XLT", PEF2256_12_PC_XPC_XLT, pef2256_xp_groups), +}; + + +static int pef2256_register_pinctrl(struct pef2256 *pef2256) +{ + struct pinctrl_dev *pctrl; + + pef2256->pinctrl.pctrl_desc.name = dev_name(pef2256->dev); + pef2256->pinctrl.pctrl_desc.owner = THIS_MODULE; + pef2256->pinctrl.pctrl_desc.pctlops = &pef2256_pctlops; + pef2256->pinctrl.pctrl_desc.pmxops = &pef2256_pmxops; + if (pef2256->version == PEF2256_VERSION_1_2) { + pef2256->pinctrl.pctrl_desc.pins = pef2256_v12_pins; + pef2256->pinctrl.pctrl_desc.npins = ARRAY_SIZE(pef2256_v12_pins); + pef2256->pinctrl.functions = pef2256_v12_functions; + pef2256->pinctrl.nfunctions = ARRAY_SIZE(pef2256_v12_functions); + } else { + pef2256->pinctrl.pctrl_desc.pins = pef2256_v2x_pins; + pef2256->pinctrl.pctrl_desc.npins = ARRAY_SIZE(pef2256_v2x_pins); + pef2256->pinctrl.functions = pef2256_v2x_functions; + pef2256->pinctrl.nfunctions = ARRAY_SIZE(pef2256_v2x_functions); + } + + pctrl = devm_pinctrl_register(pef2256->dev, &pef2256->pinctrl.pctrl_desc, pef2256); + if (IS_ERR(pctrl)) { + dev_err(pef2256->dev, "pinctrl driver registration failed\n"); + return PTR_ERR(pctrl); + } + + return 0; +} + +static void pef2256_reset_pinmux(struct pef2256 *pef2256) +{ + u8 val; + /* + * Reset values cannot be used. + * They define the SYPR/SYPX pin mux for all the RPx and XPx pins and + * Only one pin can be muxed to SYPR and one pin can be muxed to SYPX. + * Choose here an other reset value. + */ + if (pef2256->version == PEF2256_VERSION_1_2) + val = PEF2256_12_PC_XPC_XCLK | PEF2256_12_PC_RPC_RFSP; + else + val = PEF2256_2X_PC_XPC_GPI | PEF2256_2X_PC_RPC_GPI; + + pef2256_write8(pef2256, PEF2256_PC1, val); + pef2256_write8(pef2256, PEF2256_PC2, val); + pef2256_write8(pef2256, PEF2256_PC3, val); + pef2256_write8(pef2256, PEF2256_PC4, val); +} + +static ssize_t subordinate_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct pef2256 *pef2256 = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%d\n", pef2256->is_subordinate); +} + +static ssize_t subordinate_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pef2256 *pef2256 = dev_get_drvdata(dev); + int ret; + + if (strtobool(buf, &pef2256->is_subordinate) < 0) + return -EINVAL; + + ret = pef2256_setup(pef2256); + if (ret) + return ret; + + return count; +} + +static DEVICE_ATTR_RW(subordinate); + +static const struct attribute_group pef2256_attribute_group = { + .attrs = (struct attribute *[]) { + &dev_attr_subordinate.attr, + NULL, + }, +}; + +static int pef2256_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + unsigned long sclkr_rate, sclkx_rate; + struct pef2256 *pef2256; + int ret; + int irq; + + pef2256 = devm_kzalloc(&pdev->dev, sizeof(*pef2256), GFP_KERNEL); + if (!pef2256) + return -ENOMEM; + + pef2256->dev = &pdev->dev; + ATOMIC_INIT_NOTIFIER_HEAD(&pef2256->event_notifier_list); + + pef2256->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(pef2256->regs)) + return PTR_ERR(pef2256->regs); + + pef2256->mclk = devm_clk_get_enabled(&pdev->dev, "mclk"); + if (IS_ERR(pef2256->mclk)) + return PTR_ERR(pef2256->mclk); + dev_dbg(pef2256->dev, "mclk %lu Hz\n", clk_get_rate(pef2256->mclk)); + + pef2256->sclkr = devm_clk_get_enabled(&pdev->dev, "sclkr"); + if (IS_ERR(pef2256->sclkr)) + return PTR_ERR(pef2256->sclkr); + + pef2256->sclkx = devm_clk_get_enabled(&pdev->dev, "sclkx"); + if (IS_ERR(pef2256->sclkx)) + return PTR_ERR(pef2256->sclkx); + + /* + * Both SCLKR (receive) and SCLKX (transmit) must have the same rate, + * stored as sysclk_rate. + * The exact value will be checked at pef2256_check_rates() + */ + sclkr_rate = clk_get_rate(pef2256->sclkr); + sclkx_rate = clk_get_rate(pef2256->sclkx); + dev_dbg(pef2256->dev, "sclkr %lu Hz\n", sclkr_rate); + dev_dbg(pef2256->dev, "sclkx %lu Hz\n", sclkx_rate); + if (sclkr_rate != sclkx_rate) { + dev_err(pef2256->dev, "clk rate mismatch. sclkr %lu Hz, sclkx %lu Hz\n", + sclkr_rate, sclkx_rate); + return -EINVAL; + } + pef2256->sysclk_rate = sclkr_rate; + + /* Reset the component. The MCLK clock must be active during reset */ + pef2256->reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(pef2256->reset_gpio)) + return PTR_ERR(pef2256->reset_gpio); + if (pef2256->reset_gpio) { + gpiod_set_value_cansleep(pef2256->reset_gpio, 1); + udelay(10); + gpiod_set_value_cansleep(pef2256->reset_gpio, 0); + udelay(10); + } + + pef2256->version = pef2256_get_version(pef2256); + if (pef2256->version == PEF2256_VERSION_UNKNOWN) + return -ENODEV; + + ret = pef2556_of_parse(pef2256, np); + if (ret) + return ret; + + /* Disable interrupts */ + pef2256_write8(pef2256, PEF2256_IMR0, 0xff); + pef2256_write8(pef2256, PEF2256_IMR1, 0xff); + pef2256_write8(pef2256, PEF2256_IMR2, 0xff); + pef2256_write8(pef2256, PEF2256_IMR3, 0xff); + pef2256_write8(pef2256, PEF2256_IMR4, 0xff); + pef2256_write8(pef2256, PEF2256_IMR5, 0xff); + + /* Clear any pending interrupts */ + pef2256_read8(pef2256, PEF2256_ISR0); + pef2256_read8(pef2256, PEF2256_ISR1); + pef2256_read8(pef2256, PEF2256_ISR2); + pef2256_read8(pef2256, PEF2256_ISR3); + pef2256_read8(pef2256, PEF2256_ISR4); + pef2256_read8(pef2256, PEF2256_ISR5); + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; + ret = devm_request_irq(pef2256->dev, irq, pef2256_irq_handler, 0, "pef2256", pef2256); + if (ret < 0) + return ret; + + pef2256_reset_pinmux(pef2256); + ret = pef2256_register_pinctrl(pef2256); + if (ret) + return ret; + + /* + * We are going to reset the E1 lines during setup() call and the ISR2 + * interrupt used to detect the carrier state changed is masked. + * It is time to initialize our internal carrier state flag. + */ + atomic_set(&pef2256->carrier, 0); + + ret = pef2256_setup(pef2256); + if (ret) + return ret; + + platform_set_drvdata(pdev, pef2256); + + ret = sysfs_create_group(&pef2256->dev->kobj, &pef2256_attribute_group); + if (ret < 0) { + dev_err(pef2256->dev, "sysfs registration failed (%d)\n", ret); + platform_set_drvdata(pdev, NULL); + return ret; + } + + ret = devm_of_platform_populate(pef2256->dev); + if (ret < 0) { + dev_err(pef2256->dev, "platform populate failed (%d)\n", ret); + platform_set_drvdata(pdev, NULL); + return ret; + } + + return 0; +} + +static int pef2256_remove(struct platform_device *pdev) +{ + struct pef2256 *pef2256 = platform_get_drvdata(pdev); + + /* Disable interrupts */ + pef2256_write8(pef2256, PEF2256_IMR0, 0xff); + pef2256_write8(pef2256, PEF2256_IMR1, 0xff); + pef2256_write8(pef2256, PEF2256_IMR2, 0xff); + pef2256_write8(pef2256, PEF2256_IMR3, 0xff); + pef2256_write8(pef2256, PEF2256_IMR4, 0xff); + pef2256_write8(pef2256, PEF2256_IMR5, 0xff); + + sysfs_remove_group(&pef2256->dev->kobj, &pef2256_attribute_group); + + return 0; +} + +static const struct of_device_id pef2256_id_table[] = { + { .compatible = "lantiq,pef2256" }, + {} /* sentinel */ +}; +MODULE_DEVICE_TABLE(of, pef2256_id_table); + +static struct platform_driver pef2256_driver = { + .driver = { + .name = "lantiq-pef2256", + .of_match_table = pef2256_id_table, + }, + .probe = pef2256_probe, + .remove = pef2256_remove, +}; +module_platform_driver(pef2256_driver); + +int pef2256_register_event_notifier(struct pef2256 *pef2256, struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&pef2256->event_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(pef2256_register_event_notifier); + +int pef2256_unregister_event_notifier(struct pef2256 *pef2256, struct notifier_block *nb) +{ + return atomic_notifier_chain_unregister(&pef2256->event_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(pef2256_unregister_event_notifier); + +bool pef2256_get_carrier(struct pef2256 *pef2256) +{ + return !!atomic_read(&pef2256->carrier); +} +EXPORT_SYMBOL_GPL(pef2256_get_carrier); + +MODULE_AUTHOR("Herve Codina "); +MODULE_DESCRIPTION("PEF2256 driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/pef2256.h b/include/linux/mfd/pef2256.h new file mode 100644 index 000000000000..0c0afcefa3ef --- /dev/null +++ b/include/linux/mfd/pef2256.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * PEF2256 management + * + * Copyright 2023 CS GROUP France + * + * Author: Herve Codina + */ +#ifndef __PEF2256_H__ +#define __PEF2256_H__ + +#include + +struct pef2256; +struct notifier_block; + +enum pef2256_event { + PEF2256_EVENT_CARRIER, /* Carrier state changed */ +}; + +/* The nb.notifier_call function registered must not sleep */ +int pef2256_register_event_notifier(struct pef2256 *pef2256, struct notifier_block *nb); +int pef2256_unregister_event_notifier(struct pef2256 *pef2256, struct notifier_block *nb); + +/* Retrieve carrier state. true: carrier on, false: carrier off */ +bool pef2256_get_carrier(struct pef2256 *pef2256); + +#endif /* __PEF2256_H__ */ From patchwork Tue Mar 28 09:26:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 75925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2080376vqo; Tue, 28 Mar 2023 02:27:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Y29lHepfFlR8Qt+0IxOmIxR/yjVdoN8SLj6hH9TEM8j6tFRtM232Hg270plt/3s6IssQJf X-Received: by 2002:a17:90b:4f4b:b0:234:b8cb:512b with SMTP id pj11-20020a17090b4f4b00b00234b8cb512bmr16540230pjb.30.1679995665157; Tue, 28 Mar 2023 02:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679995665; cv=none; d=google.com; s=arc-20160816; b=VivuChtg2HTQcg2oqeqYmRPt0NGQ/n/YChO2ERwqxcpu2tN8jqD6rTVcIGko/q8oQM loUiecL/r2RlXJTzspDijHjV03dAX9ui6TV6a9bfa7uaT5RgpYrz7LIbZgUWNVZaMW1S hTJjquibJlyOF03OeEai7ad/A50Yjx1wC0+2VKNKk/mhEjxQudNUfqq2a27C02v8z9b+ DQHbhhcNFwe6wbOC7VdkRGchp7isrw4TjQVIAtGt8cshxMRWXm5cyUpSNS4TQHCmQhem Mfz7Jrvpy/lFfLfjxRi+LFiW64xAftSrt6NzLZNpTFr5v2MWCpEy6AQV2oSjgS3GK98d ZwNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ljp6n86BBDdKFokTOsmxWo1ozVvBJ/tB3FyqHD6++5I=; b=fNFVTt7/ZDOLCeAZMhxkbW6glUSNB7kOPsEN9UJpA1c2pIgJhW38RIyeKJ6akM9O5t 1oIPjM8dE72kpF8zrN5NIa2UAVVZiJOp6qFG0Iqbi/fIo553uTs6ovvHp9LMbC2C7Skk ga87tVH3xu5P6mXcz3nnwhFu1J2wlEyquaohQ+MKevpyD1OILkzq42WAk53oI85MQFWM iapHFxGYWBX2/MdNoSIe7NpzKrX3ynEbE55EZWrQZJmc/EcPMGdqsp4UEsOauwF6aP14 MwOkBLlnqdwc43jQ97ciHqOYBxkReDP1Cqq8B7lhWI7FaH21dmN77XWbolpd2l1YP16a ZFmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="MMe/U0mB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h11-20020a17090acf0b00b002406d55224fsi6513495pju.178.2023.03.28.02.27.33; Tue, 28 Mar 2023 02:27:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="MMe/U0mB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232400AbjC1J1E (ORCPT + 99 others); Tue, 28 Mar 2023 05:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbjC1J07 (ORCPT ); Tue, 28 Mar 2023 05:26:59 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F375FC6; Tue, 28 Mar 2023 02:26:58 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 090561BF209; Tue, 28 Mar 2023 09:26:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1679995617; 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=ljp6n86BBDdKFokTOsmxWo1ozVvBJ/tB3FyqHD6++5I=; b=MMe/U0mBt/OXx51JoieXSTGNsCN5fWAzM855VuqKQmzt//FwMUXVjMVMtVzu98EblOGcgf M5DG7qWloq4dQCs0iYd8rs0ad1QXYmR498DSFphLPMzb1POFTjqAvdsXzJ5l4qhAJwyke3 Tp1Yt0e8cdJ9pBdhjqlN4KVdkO7fs8J/iwfbnTERf8+CAiF2PqSkz+aT+fOZ0Eazt7YN5f KYq1Yht7GaBCrCm1DuG8a0hqqVaOE9v1mtK/E+1XJkfv+YVIdrp5Drq44R6BwHLdHsNiM2 TQg9MTdR9QkujKp6x58NDktIXG+UN5qO9HkCmFMAmx6WTyjnbVmGJHhO2l/idg== From: Herve Codina To: Herve Codina , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v5 3/5] Documentation: sysfs: Document the Lantiq PEF2256 sysfs entry Date: Tue, 28 Mar 2023 11:26:43 +0200 Message-Id: <20230328092645.634375-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328092645.634375-1-herve.codina@bootlin.com> References: <20230328092645.634375-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761603134419442960?= X-GMAIL-MSGID: =?utf-8?q?1761603134419442960?= Document the "subordinate" sysfs attribute exposed by the PEF2256 driver. Signed-off-by: Herve Codina --- .../ABI/testing/sysfs-bus-platform-devices-pef2256 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-platform-devices-pef2256 diff --git a/Documentation/ABI/testing/sysfs-bus-platform-devices-pef2256 b/Documentation/ABI/testing/sysfs-bus-platform-devices-pef2256 new file mode 100644 index 000000000000..95ba1ae55daf --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-platform-devices-pef2256 @@ -0,0 +1,12 @@ +What: /sys/bus/platform/devices/*.pef2256/subordinate +KernelVersion: 6.4 +Contact: Herve Codina +Description: + (RW) Controls whether the PEF2256 works as subordinate or main + device mode. + + - 0: main device mode + - 1: subordinate mode + + In subordinate device mode it synchronizes on line interface + clock signals. Otherwise, it synchronizes on internal clocks. From patchwork Tue Mar 28 09:26:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 75938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2087366vqo; Tue, 28 Mar 2023 02:44:51 -0700 (PDT) X-Google-Smtp-Source: AKy350bxI+rVvPOi2ezG1N9hliKHFHco/ry4ciuYIeaiAALWyqqIimpeou/gs+V1K9kqG1BIh/mw X-Received: by 2002:a05:6402:1105:b0:502:2599:43ea with SMTP id u5-20020a056402110500b00502259943eamr12038534edv.31.1679996691616; Tue, 28 Mar 2023 02:44:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679996691; cv=none; d=google.com; s=arc-20160816; b=Ns1jlbx04TZz7+NcEpm6Ad45dFGEQWDvz5p4zfIrumO5bYUb9cJkjfUNnVQUCuBg3h v7wtprJYStLEVa+nYSv4JX27K/qF5OMk5dNu/QP1+uh+duVpShCR07tEzxO3kkDMWcNz ohwG1HfsaG7gDPsrd0oXs0kYRbJx3lmPlGU8Sten1It08D5zGTEp+KbvAhAem5+1q8P7 bQqGp5APTPM3zNPGgnn4eyVyFFxrcTOqHbk14em8GBG6mnXemNc+tl2i7rCgdvlFMOEo uFlJtokUkr07Evd7zSDIMjyC+ZrqweJR9nZqTjMfRqIdyEtcfvqwZPfuPbff1/PSZsh6 iwTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=K24exBI98wXweQY7y30IYJ2xBsXGSBR6A9KtmS/sjh8=; b=mOn4GkQq2lbJiVxUEKOjjTL+m5Z5zr1AdpYRaTJiIQkODYVSt51TrC7QS1t0NMyTWb BMS7U4oOjRMoG6sWD0UxSGX8JudJE+cduYyPyRBlM3kY9JxcNO+TatXmje2GiY93dVGe +atqPo0jvbm7uAhrNHpfzV8woRINyydbuCSxDfsKxZGmudKqFO+jecTBcSj1gWwDsYS4 FUVB6hOwHNKH81Ln1FPujc/86PPY8jxcpbA6YZv4jA6r9wHsox6B2JBwbNpix991qNMx 0mfuu1QkBILJ82ykjY0qSyZFBlhQnc9QffIfIuHq19khut7MEQ9AkkaqMbhtfp6R5g8G tOlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ZCwG5T6l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a056402345000b004fb5795b7e4si27844934edc.416.2023.03.28.02.44.28; Tue, 28 Mar 2023 02:44:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ZCwG5T6l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbjC1J1J (ORCPT + 99 others); Tue, 28 Mar 2023 05:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232289AbjC1J1C (ORCPT ); Tue, 28 Mar 2023 05:27:02 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 234095FF9; Tue, 28 Mar 2023 02:27:00 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 691891BF20A; Tue, 28 Mar 2023 09:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1679995618; 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=K24exBI98wXweQY7y30IYJ2xBsXGSBR6A9KtmS/sjh8=; b=ZCwG5T6ldREnpQ/+pLuc/js+x6FE/3XfHDl8DhmpB6rnxNQEXUaeqkfsKuGQy0u3+cXjYx JT5SBt7wOOjkNcf+tEIpRZ1Ix1hiBpFlYt7rM2hv/y7G1fEWk3sb3dcWAPdgwtEygn9kNu uwfvqwCABzqWtwRiux8WQjfN+0BSSrhlFWiBdpCb8gtjlA5OD6uiKFbGTwCZlfuu+Z6klz wyPIqLs6Cmvv63iPqsyUuhlmceHwuLf9aH3RvVwwt6F7j0nwtNCprmxoVqRlCycBhkJW9W fX6XFANVPe4YTOyhOyTkGav1mdlHORpq4dd2A5b0YJwHzUFguOHJa7eyjRdE5A== From: Herve Codina To: Herve Codina , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v5 4/5] ASoC: codecs: Add support for the Lantiq PEF2256 codec Date: Tue, 28 Mar 2023 11:26:44 +0200 Message-Id: <20230328092645.634375-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328092645.634375-1-herve.codina@bootlin.com> References: <20230328092645.634375-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761604211243589556?= X-GMAIL-MSGID: =?utf-8?q?1761604211243589556?= The Lantiq PEF2256 is a framer and line interface component designed to fulfill all required interfacing between an analog E1/T1/J1 line and the digital PCM system highway/H.100 bus. The codec support allows to use some of the PCM system highway time-slots as audio channels to transport audio data over the E1/T1/J1 lines. It provides also line carrier detection events reported through the ALSA jack detection feature. Signed-off-by: Herve Codina --- sound/soc/codecs/Kconfig | 14 ++ sound/soc/codecs/Makefile | 2 + sound/soc/codecs/pef2256-codec.c | 390 +++++++++++++++++++++++++++++++ 3 files changed, 406 insertions(+) create mode 100644 sound/soc/codecs/pef2256-codec.c diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 0be061953e9a..4f78da914fc7 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -168,6 +168,7 @@ config SND_SOC_ALL_CODECS imply SND_SOC_PCM512x_I2C imply SND_SOC_PCM512x_SPI imply SND_SOC_PEB2466 + imply SND_SOC_PEF2256 imply SND_SOC_RK3328 imply SND_SOC_RK817 imply SND_SOC_RT274 @@ -1252,6 +1253,19 @@ config SND_SOC_PEB2466 To compile this driver as a module, choose M here: the module will be called snd-soc-peb2466. +config SND_SOC_PEF2256 + tristate "Lantiq PEF2256 codec" + depends on MFD_PEF2256 + help + Enable support for the Lantiq PEF2256 (FALC56) codec. + The PEF2256 is a framer and line interface between analog E1/T1/J1 + line and a digital PCM bus. + This codec allows to use some of the time slots available on the + PEF2256 PCM bus to transport some audio data. + + To compile this driver as a module, choose M here: the module + will be called snd-soc-pef2256. + config SND_SOC_RK3328 tristate "Rockchip RK3328 audio CODEC" select REGMAP_MMIO diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 20b388b77f1f..11bd66d46f7b 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -188,6 +188,7 @@ snd-soc-pcm512x-objs := pcm512x.o snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o snd-soc-pcm512x-spi-objs := pcm512x-spi.o snd-soc-peb2466-objs := peb2466.o +snd-soc-pef2256-objs := pef2256-codec.o snd-soc-rk3328-objs := rk3328_codec.o snd-soc-rk817-objs := rk817_codec.o snd-soc-rl6231-objs := rl6231.o @@ -551,6 +552,7 @@ obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o obj-$(CONFIG_SND_SOC_PEB2466) += snd-soc-peb2466.o +obj-$(CONFIG_SND_SOC_PEF2256) += snd-soc-pef2256.o obj-$(CONFIG_SND_SOC_RK3328) += snd-soc-rk3328.o obj-$(CONFIG_SND_SOC_RK817) += snd-soc-rk817.o obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o diff --git a/sound/soc/codecs/pef2256-codec.c b/sound/soc/codecs/pef2256-codec.c new file mode 100644 index 000000000000..d87fdc771a30 --- /dev/null +++ b/sound/soc/codecs/pef2256-codec.c @@ -0,0 +1,390 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// pef2256.c -- Lantiq PEF2256 ALSA SoC driver +// +// Copyright 2023 CS GROUP France +// +// Author: Herve Codina + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PEF2256_NB_CHANNEL 32 +#define PEF2256_JACK_MASK (SND_JACK_LINEIN | SND_JACK_LINEOUT) + +struct pef2256_codec { + struct pef2256 *pef2256; + struct device *dev; + struct snd_soc_jack jack; + struct notifier_block nb; + struct work_struct carrier_work; + int max_chan_playback; + int max_chan_capture; +}; + +static int pef2256_dai_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, + unsigned int rx_mask, int slots, int width) +{ + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(dai->component); + + switch (width) { + case 0: + /* Not set -> default 8 */ + case 8: + break; + default: + dev_err(dai->dev, "tdm slot width %d not supported\n", width); + return -EINVAL; + } + + pef2256->max_chan_playback = hweight32(tx_mask); + if (pef2256->max_chan_playback > PEF2256_NB_CHANNEL) { + dev_err(dai->dev, "too much tx slots defined (mask = 0x%x) support max %d\n", + tx_mask, PEF2256_NB_CHANNEL); + return -EINVAL; + } + + pef2256->max_chan_capture = hweight32(rx_mask); + if (pef2256->max_chan_capture > PEF2256_NB_CHANNEL) { + dev_err(dai->dev, "too much rx slots defined (mask = 0x%x) support max %d\n", + rx_mask, PEF2256_NB_CHANNEL); + return -EINVAL; + } + + return 0; +} + +/* + * The constraints for format/channel is to match with the number of 8bit + * time-slots available. + */ +static int pef2256_dai_hw_rule_channels_by_format(struct snd_soc_dai *dai, + struct snd_pcm_hw_params *params, + unsigned int nb_ts) +{ + struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); + snd_pcm_format_t format = params_format(params); + struct snd_interval ch = {0}; + + switch (snd_pcm_format_physical_width(format)) { + case 8: + ch.max = nb_ts; + break; + case 16: + ch.max = nb_ts/2; + break; + case 32: + ch.max = nb_ts/4; + break; + case 64: + ch.max = nb_ts/8; + break; + default: + dev_err(dai->dev, "format physical width %u not supported\n", + snd_pcm_format_physical_width(format)); + return -EINVAL; + } + + ch.min = ch.max ? 1 : 0; + + return snd_interval_refine(c, &ch); +} + +static int pef2256_dai_hw_rule_playback_channels_by_format(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_soc_dai *dai = rule->private; + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(dai->component); + + return pef2256_dai_hw_rule_channels_by_format(dai, params, pef2256->max_chan_playback); +} + +static int pef2256_dai_hw_rule_capture_channels_by_format(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_soc_dai *dai = rule->private; + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(dai->component); + + return pef2256_dai_hw_rule_channels_by_format(dai, params, pef2256->max_chan_capture); +} + +static int pef2256_dai_hw_rule_format_by_channels(struct snd_soc_dai *dai, + struct snd_pcm_hw_params *params, + unsigned int nb_ts) +{ + struct snd_mask *f_old = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); + unsigned int channels = params_channels(params); + unsigned int slot_width; + struct snd_mask f_new; + unsigned int i; + + if (!channels || channels > nb_ts) { + dev_err(dai->dev, "channels %u not supported\n", nb_ts); + return -EINVAL; + } + + slot_width = (nb_ts / channels) * 8; + + snd_mask_none(&f_new); + for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) { + if (snd_mask_test(f_old, i)) { + if (snd_pcm_format_physical_width(i) <= slot_width) + snd_mask_set(&f_new, i); + } + } + + return snd_mask_refine(f_old, &f_new); +} + +static int pef2256_dai_hw_rule_playback_format_by_channels(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_soc_dai *dai = rule->private; + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(dai->component); + + return pef2256_dai_hw_rule_format_by_channels(dai, params, pef2256->max_chan_playback); +} + +static int pef2256_dai_hw_rule_capture_format_by_channels(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_soc_dai *dai = rule->private; + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(dai->component); + + return pef2256_dai_hw_rule_format_by_channels(dai, params, pef2256->max_chan_capture); +} + +static u64 pef2256_formats(u8 nb_ts) +{ + u64 formats; + unsigned int chan_width; + unsigned int format_width; + int i; + + if (!nb_ts) + return 0; + + formats = 0; + chan_width = nb_ts * 8; + for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) { + /* Support physical width multiple of 8bit */ + format_width = snd_pcm_format_physical_width(i); + if (format_width == 0 || format_width % 8) + continue; + + /* + * And support physical width that can fit N times in the + * channel + */ + if (format_width > chan_width || chan_width % format_width) + continue; + + formats |= (1ULL << i); + } + return formats; +} + +static int pef2256_dai_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(dai->component); + snd_pcm_hw_rule_func_t hw_rule_channels_by_format; + snd_pcm_hw_rule_func_t hw_rule_format_by_channels; + unsigned int frame_bits; + u64 format; + int ret; + + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + format = pef2256_formats(pef2256->max_chan_capture); + hw_rule_channels_by_format = pef2256_dai_hw_rule_capture_channels_by_format; + hw_rule_format_by_channels = pef2256_dai_hw_rule_capture_format_by_channels; + frame_bits = pef2256->max_chan_capture * 8; + } else { + format = pef2256_formats(pef2256->max_chan_playback); + hw_rule_channels_by_format = pef2256_dai_hw_rule_playback_channels_by_format; + hw_rule_format_by_channels = pef2256_dai_hw_rule_playback_format_by_channels; + frame_bits = pef2256->max_chan_playback * 8; + } + + ret = snd_pcm_hw_constraint_mask64(substream->runtime, + SNDRV_PCM_HW_PARAM_FORMAT, format); + if (ret) { + dev_err(dai->dev, "Failed to add format constraint (%d)\n", ret); + return ret; + } + + ret = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, + hw_rule_channels_by_format, dai, + SNDRV_PCM_HW_PARAM_FORMAT, -1); + if (ret) { + dev_err(dai->dev, "Failed to add channels rule (%d)\n", ret); + return ret; + } + + ret = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, + hw_rule_format_by_channels, dai, + SNDRV_PCM_HW_PARAM_CHANNELS, -1); + if (ret) { + dev_err(dai->dev, "Failed to add format rule (%d)\n", ret); + return ret; + } + + ret = snd_pcm_hw_constraint_single(substream->runtime, + SNDRV_PCM_HW_PARAM_FRAME_BITS, + frame_bits); + if (ret < 0) { + dev_err(dai->dev, "Failed to add frame_bits constraint (%d)\n", ret); + return ret; + } + + return 0; +} + +static u64 pef2256_dai_formats[] = { + SND_SOC_POSSIBLE_DAIFMT_DSP_B, +}; + +static const struct snd_soc_dai_ops pef2256_dai_ops = { + .startup = pef2256_dai_startup, + .set_tdm_slot = pef2256_dai_set_tdm_slot, + .auto_selectable_formats = pef2256_dai_formats, + .num_auto_selectable_formats = ARRAY_SIZE(pef2256_dai_formats), +}; + +static struct snd_soc_dai_driver pef2256_dai_driver = { + .name = "pef2256", + .playback = { + .stream_name = "Playback", + .channels_min = 1, + .channels_max = PEF2256_NB_CHANNEL, + .rates = SNDRV_PCM_RATE_8000, + .formats = U64_MAX, /* Will be refined on DAI .startup() */ + }, + .capture = { + .stream_name = "Capture", + .channels_min = 1, + .channels_max = PEF2256_NB_CHANNEL, + .rates = SNDRV_PCM_RATE_8000, + .formats = U64_MAX, /* Will be refined on DAI .startup() */ + }, + .ops = &pef2256_dai_ops, +}; + +static void pef2256_carrier_work(struct work_struct *work) +{ + struct pef2256_codec *pef2256 = container_of(work, struct pef2256_codec, carrier_work); + int status; + + status = pef2256_get_carrier(pef2256->pef2256) ? PEF2256_JACK_MASK : 0; + snd_soc_jack_report(&pef2256->jack, status, PEF2256_JACK_MASK); +} + +static int pef2256_carrier_notifier(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct pef2256_codec *pef2256 = container_of(nb, struct pef2256_codec, nb); + + switch (action) { + case PEF2256_EVENT_CARRIER: + queue_work(system_power_efficient_wq, &pef2256->carrier_work); + break; + default: + return NOTIFY_DONE; + } + + return NOTIFY_OK; +} + +static int pef2256_component_probe(struct snd_soc_component *component) +{ + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(component); + char *name; + int ret; + + INIT_WORK(&pef2256->carrier_work, pef2256_carrier_work); + + name = "carrier"; + if (component->name_prefix) { + name = kasprintf(GFP_KERNEL, "%s carrier", component->name_prefix); + if (!name) + return -ENOMEM; + } + + ret = snd_soc_card_jack_new(component->card, name, PEF2256_JACK_MASK, &pef2256->jack); + if (component->name_prefix) + kfree(name); /* A copy is done by snd_soc_card_jack_new */ + if (ret) { + dev_err(component->dev, "Cannot create jack\n"); + return ret; + } + + pef2256->nb.notifier_call = pef2256_carrier_notifier; + ret = pef2256_register_event_notifier(pef2256->pef2256, &pef2256->nb); + if (ret) { + dev_err(component->dev, "Cannot register event notifier\n"); + return ret; + } + + /* Queue work to set the initial value */ + queue_work(system_power_efficient_wq, &pef2256->carrier_work); + + return 0; +} + +static void pef2256_component_remove(struct snd_soc_component *component) +{ + struct pef2256_codec *pef2256 = snd_soc_component_get_drvdata(component); + + pef2256_unregister_event_notifier(pef2256->pef2256, &pef2256->nb); + cancel_work_sync(&pef2256->carrier_work); +} + +static const struct snd_soc_component_driver pef2256_component_driver = { + .probe = pef2256_component_probe, + .remove = pef2256_component_remove, + .endianness = 1, +}; + +static int pef2256_codec_probe(struct platform_device *pdev) +{ + struct pef2256_codec *pef2256; + + pef2256 = devm_kzalloc(&pdev->dev, sizeof(*pef2256), GFP_KERNEL); + if (!pef2256) + return -ENOMEM; + + pef2256->dev = &pdev->dev; + pef2256->pef2256 = dev_get_drvdata(pef2256->dev->parent); + + platform_set_drvdata(pdev, pef2256); + + return devm_snd_soc_register_component(&pdev->dev, &pef2256_component_driver, + &pef2256_dai_driver, 1); +} + +static const struct of_device_id pef2256_codec_of_match[] = { + { .compatible = "lantiq,pef2256-codec" }, + {} /* sentinel */ +}; +MODULE_DEVICE_TABLE(of, pef2256_codec_of_match); + +static struct platform_driver pef2256_codec_driver = { + .driver = { + .name = "lantiq-pef2256-codec", + .of_match_table = pef2256_codec_of_match, + }, + .probe = pef2256_codec_probe, +}; +module_platform_driver(pef2256_codec_driver); + +MODULE_AUTHOR("Herve Codina "); +MODULE_DESCRIPTION("PEF2256 ALSA SoC driver"); +MODULE_LICENSE("GPL"); From patchwork Tue Mar 28 09:26:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 75933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2085902vqo; Tue, 28 Mar 2023 02:40:58 -0700 (PDT) X-Google-Smtp-Source: AK7set/mZqh4gmAr4fM8gs9ZHC7MSpHMxnvN9FfqrbWHTQgxfbr/EEReD//5OS4QXHIhjA9y0Ylu X-Received: by 2002:a05:6a20:3a9c:b0:d9:77f7:d62e with SMTP id d28-20020a056a203a9c00b000d977f7d62emr12295269pzh.36.1679996458537; Tue, 28 Mar 2023 02:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679996458; cv=none; d=google.com; s=arc-20160816; b=nS/yyaaepWi+tjWZ7BVm+kMSoozLJK586m7dq43kIg0QME0f+Aa8Ue6Arg00k61b8M KIv+a8W2doxJuxEI5K58TqPA1kMDEpcXy8+NFuE7VuljXNIoGftN0rrrciv4I1+G60qL +szn6iVxuioOhXe0LceN2crDrY+gAtu3km0YRPPIAhuMThiYBw6OVKEVgRYwsvpfX2rn v7+6zvnPWDHiZsw4TtjMeOxnxJ02YwDhFie7RjoVNHWW+yTZg4thQz4/iIoV4F25yg0C iI/pOsR54viaMzXJXDbQ6AQ6DSRqL3fvwdUnqiDIZyt7SGAUH0epLdoPD0AklymZJJfE sdLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NZF5AfOr6NqUrKibPpIKyfVUE8v0dg0CjG97i8h7gyg=; b=d693hyjGuFbdOyhFqrIVOb70DO92STZNq3DKU4SniYxx1V39VWuY9fgvGt0PAetKnA /Ai2yDpe4ktuzqLhVHSNfaOImf2SjMThJND7mAqpmMAO/SEu7NmTeFJgxPktI38IaXkr 91RHTXyLF5OkIAGWqkNlnkxpg7BReHMJEenu0HFsYVQGz8Yb67Jal0JvcfkTkD8pxKpt sDLZ6TDDVD0p3V+bI3Ag9DAvrJGRit+hqlYQl50RUApQfil1rInkRiHDDKVIqA51RLW5 muQDZ8TTBqO3b/TM6tt64UPnhuR/KonKbZSSadC1TEWBY854Quy8lA7NPPEoD576zgaF Ck9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=iqIkJ85n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a191-20020a621ac8000000b00624de0ad130si10193471pfa.276.2023.03.28.02.40.46; Tue, 28 Mar 2023 02:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=iqIkJ85n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232572AbjC1J1P (ORCPT + 99 others); Tue, 28 Mar 2023 05:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232452AbjC1J1H (ORCPT ); Tue, 28 Mar 2023 05:27:07 -0400 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD4C619E; Tue, 28 Mar 2023 02:27:01 -0700 (PDT) Received: (Authenticated sender: herve.codina@bootlin.com) by mail.gandi.net (Postfix) with ESMTPA id 0DF9A1BF20F; Tue, 28 Mar 2023 09:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1679995620; 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=NZF5AfOr6NqUrKibPpIKyfVUE8v0dg0CjG97i8h7gyg=; b=iqIkJ85nmrquXK9GjThpibaxr08Y4csHtpKqnr3ywQ1soYxs94hbEorxeDY1LGPI81RPrZ l3kaHeygZfEuLjZ1oaZGE+11DlZsw5tbCXKfzXhZdRTL6IAoXNQzxJWxkm8iB0RANZwOkE EM5w7StJ0zmk5uTfx41jjWqSGneu1CRpv12UPchrWbOdPZEhH9YCyUqCR0k5T6HaP+yZXH i/McCFK54as/LhbFmJ41e4Ha+sVnDav+jyqIjut90Z9xOmauEtaTofAhyRBnds2KFXKkzV yGm0ikHoHnttkZjpuSoQNDwdljIfo45XJ75VPb6usIxPgRldUmjMrFJVgrNLBQ== From: Herve Codina To: Herve Codina , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v5 5/5] MAINTAINERS: Add the Lantiq PEF2256 driver entry Date: Tue, 28 Mar 2023 11:26:45 +0200 Message-Id: <20230328092645.634375-6-herve.codina@bootlin.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230328092645.634375-1-herve.codina@bootlin.com> References: <20230328092645.634375-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761603966750871880?= X-GMAIL-MSGID: =?utf-8?q?1761603966750871880?= After contributing the driver, add myself as the maintainer for the Lantiq PEF2256 driver. Signed-off-by: Herve Codina --- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index fcb69242cd19..a17c85648f6f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11651,6 +11651,15 @@ S: Maintained F: arch/mips/lantiq F: drivers/soc/lantiq +LANTIQ PEF2256 DRIVER +M: Herve Codina +S: Maintained +F: Documentation/ABI/testing/sysfs-bus-platform-devices-pef2256 +F: Documentation/devicetree/bindings/mfd/lantiq,pef2256.yaml +F: drivers/mfd/pef2256.c +F: include/linux/mfd/pef2256.h +F: sound/soc/codecs/pef2256-codec.c + LASI 53c700 driver for PARISC M: "James E.J. Bottomley" L: linux-scsi@vger.kernel.org