Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'pef2256-framer' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl

Linus Walleij says:

====================
Immutable tag for the PEF2256 framer

* tag 'pef2256-framer' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl:
MAINTAINERS: Add the Lantiq PEF2256 driver entry
pinctrl: Add support for the Lantic PEF2256 pinmux
net: wan: framer: Add support for the Lantiq PEF2256 framer
dt-bindings: net: Add the Lantiq PEF2256 E1/T1/J1 framer
net: wan: Add framer framework support
====================

Link: https://lore.kernel.org/all/CACRpkdYT1J7noFUhObFgfA60XQAfL4rb=knEmWS__TKKtCMh7Q@mail.gmail.com/
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+3098
+213
Documentation/devicetree/bindings/net/lantiq,pef2256.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/net/lantiq,pef2256.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Lantiq PEF2256 8 + 9 + maintainers: 10 + - Herve Codina <herve.codina@bootlin.com> 11 + 12 + description: 13 + The Lantiq PEF2256, also known as Infineon PEF2256 or FALC56, is a framer and 14 + line interface component designed to fulfill all required interfacing between 15 + an analog E1/T1/J1 line and the digital PCM system highway/H.100 bus. 16 + 17 + properties: 18 + compatible: 19 + items: 20 + - const: lantiq,pef2256 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + clocks: 26 + items: 27 + - description: Master Clock 28 + - description: System Clock Receive 29 + - description: System Clock Transmit 30 + 31 + clock-names: 32 + items: 33 + - const: mclk 34 + - const: sclkr 35 + - const: sclkx 36 + 37 + interrupts: 38 + maxItems: 1 39 + 40 + reset-gpios: 41 + description: 42 + GPIO used to reset the device. 43 + maxItems: 1 44 + 45 + pinctrl: 46 + $ref: /schemas/pinctrl/pinctrl.yaml# 47 + additionalProperties: false 48 + 49 + patternProperties: 50 + '-pins$': 51 + type: object 52 + $ref: /schemas/pinctrl/pinmux-node.yaml# 53 + additionalProperties: false 54 + 55 + properties: 56 + pins: 57 + enum: [ RPA, RPB, RPC, RPD, XPA, XPB, XPC, XPD ] 58 + 59 + function: 60 + enum: [ SYPR, RFM, RFMB, RSIGM, RSIG, DLR, FREEZE, RFSP, LOS, 61 + SYPX, XFMS, XSIG, TCLK, XMFB, XSIGM, DLX, XCLK, XLT, 62 + GPI, GPOH, GPOL ] 63 + 64 + required: 65 + - pins 66 + - function 67 + 68 + lantiq,data-rate-bps: 69 + enum: [2048000, 4096000, 8192000, 16384000] 70 + default: 2048000 71 + description: 72 + Data rate (bit per seconds) on the system highway. 73 + 74 + lantiq,clock-falling-edge: 75 + $ref: /schemas/types.yaml#/definitions/flag 76 + description: 77 + Data is sent on falling edge of the clock (and received on the rising 78 + edge). If 'clock-falling-edge' is not present, data is sent on the 79 + rising edge (and received on the falling edge). 80 + 81 + lantiq,channel-phase: 82 + $ref: /schemas/types.yaml#/definitions/uint32 83 + enum: [0, 1, 2, 3, 4, 5, 6, 7] 84 + default: 0 85 + description: | 86 + The pef2256 delivers a full frame (32 8-bit time-slots in E1 and 24 8-bit 87 + time-slots 8 8-bit signaling in E1/J1) every 125us. This lead to a data 88 + rate of 2048000 bit/s. When lantiq,data-rate-bps is more than 2048000 89 + bit/s, the data (all 32 8-bit) present in the frame are interleave with 90 + unused time-slots. The lantiq,channel-phase property allows to set the 91 + correct alignment of the interleave mechanism. 92 + For instance, suppose lantiq,data-rate-bps = 8192000 (ie 4*2048000), and 93 + lantiq,channel-phase = 2, the interleave schema with unused time-slots 94 + (nu) and used time-slots (XX) for TSi is 95 + nu nu XX nu nu nu XX nu nu nu XX nu 96 + <-- TSi --> <- TSi+1 -> <- TSi+2 -> 97 + With lantiq,data-rate-bps = 8192000, and lantiq,channel-phase = 1, the 98 + interleave schema is 99 + nu XX nu nu nu XX nu nu nu XX nu nu 100 + <-- TSi --> <- TSi+1 -> <- TSi+2 -> 101 + With lantiq,data-rate-bps = 4096000 (ie 2*2048000), and 102 + lantiq,channel-phase = 1, the interleave schema is 103 + nu XX nu XX nu XX 104 + <-- TSi --> <- TSi+1 -> <- TSi+2 -> 105 + 106 + patternProperties: 107 + '^codec(-([0-9]|[1-2][0-9]|3[0-1]))?$': 108 + type: object 109 + $ref: /schemas/sound/dai-common.yaml 110 + unevaluatedProperties: false 111 + description: 112 + Codec provided by the pef2256. This codec allows to use some of the PCM 113 + system highway time-slots as audio channels to transport audio data over 114 + the E1/T1/J1 lines. 115 + The time-slots used by the codec must be set and so, the properties 116 + 'dai-tdm-slot-num', 'dai-tdm-slot-width', 'dai-tdm-slot-tx-mask' and 117 + 'dai-tdm-slot-rx-mask' must be present in the sound card node for 118 + sub-nodes that involve the codec. The codec uses 8-bit time-slots. 119 + 'dai-tdm-tdm-slot-with' must be set to 8. 120 + The tx and rx masks define the pef2256 time-slots assigned to the codec. 121 + 122 + properties: 123 + compatible: 124 + const: lantiq,pef2256-codec 125 + 126 + '#sound-dai-cells': 127 + const: 0 128 + 129 + required: 130 + - compatible 131 + - '#sound-dai-cells' 132 + 133 + required: 134 + - compatible 135 + - reg 136 + - clocks 137 + - clock-names 138 + - interrupts 139 + 140 + additionalProperties: false 141 + 142 + examples: 143 + - | 144 + #include <dt-bindings/gpio/gpio.h> 145 + #include <dt-bindings/interrupt-controller/irq.h> 146 + 147 + pef2256: framer@2000000 { 148 + compatible = "lantiq,pef2256"; 149 + reg = <0x2000000 0x100>; 150 + interrupts = <8 IRQ_TYPE_LEVEL_LOW>; 151 + interrupt-parent = <&intc>; 152 + clocks = <&clk_mclk>, <&clk_sclkr>, <&clk_sclkx>; 153 + clock-names = "mclk", "sclkr", "sclkx"; 154 + reset-gpios = <&gpio 11 GPIO_ACTIVE_LOW>; 155 + lantiq,data-rate-bps = <4096000>; 156 + 157 + pinctrl { 158 + pef2256_rpa_sypr: rpa-pins { 159 + pins = "RPA"; 160 + function = "SYPR"; 161 + }; 162 + pef2256_xpa_sypx: xpa-pins { 163 + pins = "XPA"; 164 + function = "SYPX"; 165 + }; 166 + }; 167 + 168 + pef2256_codec0: codec-0 { 169 + compatible = "lantiq,pef2256-codec"; 170 + #sound-dai-cells = <0>; 171 + sound-name-prefix = "PEF2256_0"; 172 + }; 173 + 174 + pef2256_codec1: codec-1 { 175 + compatible = "lantiq,pef2256-codec"; 176 + #sound-dai-cells = <0>; 177 + sound-name-prefix = "PEF2256_1"; 178 + }; 179 + }; 180 + 181 + sound { 182 + compatible = "simple-audio-card"; 183 + #address-cells = <1>; 184 + #size-cells = <0>; 185 + simple-audio-card,dai-link@0 { /* CPU DAI1 - pef2256 codec 1 */ 186 + reg = <0>; 187 + cpu { 188 + sound-dai = <&cpu_dai1>; 189 + }; 190 + codec { 191 + sound-dai = <&pef2256_codec0>; 192 + dai-tdm-slot-num = <4>; 193 + dai-tdm-slot-width = <8>; 194 + /* TS 1, 2, 3, 4 */ 195 + dai-tdm-slot-tx-mask = <0 1 1 1 1>; 196 + dai-tdm-slot-rx-mask = <0 1 1 1 1>; 197 + }; 198 + }; 199 + simple-audio-card,dai-link@1 { /* CPU DAI2 - pef2256 codec 2 */ 200 + reg = <1>; 201 + cpu { 202 + sound-dai = <&cpu_dai2>; 203 + }; 204 + codec { 205 + sound-dai = <&pef2256_codec1>; 206 + dai-tdm-slot-num = <4>; 207 + dai-tdm-slot-width = <8>; 208 + /* TS 5, 6, 7, 8 */ 209 + dai-tdm-slot-tx-mask = <0 0 0 0 0 1 1 1 1>; 210 + dai-tdm-slot-rx-mask = <0 0 0 0 0 1 1 1 1>; 211 + }; 212 + }; 213 + };
+8
MAINTAINERS
··· 12013 12013 F: arch/mips/lantiq 12014 12014 F: drivers/soc/lantiq 12015 12015 12016 + LANTIQ PEF2256 DRIVER 12017 + M: Herve Codina <herve.codina@bootlin.com> 12018 + S: Maintained 12019 + F: Documentation/devicetree/bindings/net/lantiq,pef2256.yaml 12020 + F: drivers/net/wan/framer/pef2256/ 12021 + F: drivers/pinctrl/pinctrl-pef2256.c 12022 + F: include/linux/framer/pef2256.h 12023 + 12016 12024 LASI 53c700 driver for PARISC 12017 12025 M: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com> 12018 12026 L: linux-scsi@vger.kernel.org
+2
drivers/net/wan/Kconfig
··· 95 95 comment "X.25/LAPB support is disabled" 96 96 depends on HDLC && (LAPB!=m || HDLC!=m) && LAPB!=y 97 97 98 + source "drivers/net/wan/framer/Kconfig" 99 + 98 100 config PCI200SYN 99 101 tristate "Goramo PCI200SYN support" 100 102 depends on HDLC && PCI
+2
drivers/net/wan/Makefile
··· 14 14 obj-$(CONFIG_HDLC_PPP) += hdlc_ppp.o 15 15 obj-$(CONFIG_HDLC_X25) += hdlc_x25.o 16 16 17 + obj-y += framer/ 18 + 17 19 obj-$(CONFIG_FARSYNC) += farsync.o 18 20 19 21 obj-$(CONFIG_LAPBETHER) += lapbether.o
+42
drivers/net/wan/framer/Kconfig
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + # 3 + # FRAMER 4 + # 5 + 6 + menuconfig FRAMER 7 + tristate "Framer Subsystem" 8 + help 9 + A framer is a component in charge of an E1/T1 line interface. 10 + Connected usually to a TDM bus, it converts TDM frames to/from E1/T1 11 + frames. It also provides information related to the E1/T1 line. 12 + Used with HDLC, the network can be reached through the E1/T1 line. 13 + 14 + This framework is designed to provide a generic interface for framer 15 + devices present in the kernel. This layer will have the generic 16 + API by which framer drivers can create framer using the framer 17 + framework and framer users can obtain reference to the framer. 18 + All the users of this framework should select this config. 19 + 20 + if FRAMER 21 + 22 + config GENERIC_FRAMER 23 + bool 24 + 25 + config FRAMER_PEF2256 26 + tristate "Lantiq PEF2256" 27 + depends on OF 28 + depends on HAS_IOMEM 29 + select GENERIC_FRAMER 30 + select MFD_CORE 31 + select REGMAP_MMIO 32 + help 33 + Enable support for the Lantiq PEF2256 (FALC56) framer. 34 + The PEF2256 is a framer and line interface between analog E1/T1/J1 35 + line and a digital PCM bus. 36 + 37 + If unsure, say N. 38 + 39 + To compile this driver as a module, choose M here: the 40 + module will be called framer-pef2256. 41 + 42 + endif # FRAMER
+7
drivers/net/wan/framer/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # Makefile for the framer drivers. 4 + # 5 + 6 + obj-$(CONFIG_GENERIC_FRAMER) += framer-core.o 7 + obj-$(CONFIG_FRAMER_PEF2256) += pef2256/
+882
drivers/net/wan/framer/framer-core.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Generic Framer framework. 4 + * 5 + * Copyright 2023 CS GROUP France 6 + * 7 + * Author: Herve Codina <herve.codina@bootlin.com> 8 + */ 9 + 10 + #include <linux/device.h> 11 + #include <linux/framer/framer.h> 12 + #include <linux/framer/framer-provider.h> 13 + #include <linux/idr.h> 14 + #include <linux/module.h> 15 + #include <linux/notifier.h> 16 + #include <linux/of.h> 17 + #include <linux/pm_runtime.h> 18 + #include <linux/regulator/consumer.h> 19 + #include <linux/slab.h> 20 + 21 + static struct class *framer_class; 22 + static DEFINE_MUTEX(framer_provider_mutex); 23 + static LIST_HEAD(framer_provider_list); 24 + static DEFINE_IDA(framer_ida); 25 + 26 + #define dev_to_framer(a) (container_of((a), struct framer, dev)) 27 + 28 + int framer_pm_runtime_get(struct framer *framer) 29 + { 30 + int ret; 31 + 32 + if (!pm_runtime_enabled(&framer->dev)) 33 + return -EOPNOTSUPP; 34 + 35 + ret = pm_runtime_get(&framer->dev); 36 + if (ret < 0 && ret != -EINPROGRESS) 37 + pm_runtime_put_noidle(&framer->dev); 38 + 39 + return ret; 40 + } 41 + EXPORT_SYMBOL_GPL(framer_pm_runtime_get); 42 + 43 + int framer_pm_runtime_get_sync(struct framer *framer) 44 + { 45 + int ret; 46 + 47 + if (!pm_runtime_enabled(&framer->dev)) 48 + return -EOPNOTSUPP; 49 + 50 + ret = pm_runtime_get_sync(&framer->dev); 51 + if (ret < 0) 52 + pm_runtime_put_sync(&framer->dev); 53 + 54 + return ret; 55 + } 56 + EXPORT_SYMBOL_GPL(framer_pm_runtime_get_sync); 57 + 58 + int framer_pm_runtime_put(struct framer *framer) 59 + { 60 + if (!pm_runtime_enabled(&framer->dev)) 61 + return -EOPNOTSUPP; 62 + 63 + return pm_runtime_put(&framer->dev); 64 + } 65 + EXPORT_SYMBOL_GPL(framer_pm_runtime_put); 66 + 67 + int framer_pm_runtime_put_sync(struct framer *framer) 68 + { 69 + if (!pm_runtime_enabled(&framer->dev)) 70 + return -EOPNOTSUPP; 71 + 72 + return pm_runtime_put_sync(&framer->dev); 73 + } 74 + EXPORT_SYMBOL_GPL(framer_pm_runtime_put_sync); 75 + 76 + /** 77 + * framer_init - framer internal initialization before framer operation 78 + * @framer: the framer returned by framer_get() 79 + * 80 + * Used to allow framer's driver to perform framer internal initialization, 81 + * such as PLL block powering, clock initialization or anything that's 82 + * is required by the framer to perform the start of operation. 83 + * Must be called before framer_power_on(). 84 + * 85 + * Return: %0 if successful, a negative error code otherwise 86 + */ 87 + int framer_init(struct framer *framer) 88 + { 89 + bool start_polling = false; 90 + int ret; 91 + 92 + ret = framer_pm_runtime_get_sync(framer); 93 + if (ret < 0 && ret != -EOPNOTSUPP) 94 + return ret; 95 + ret = 0; /* Override possible ret == -EOPNOTSUPP */ 96 + 97 + mutex_lock(&framer->mutex); 98 + if (framer->power_count > framer->init_count) 99 + dev_warn(&framer->dev, "framer_power_on was called before framer init\n"); 100 + 101 + if (framer->init_count == 0) { 102 + if (framer->ops->init) { 103 + ret = framer->ops->init(framer); 104 + if (ret < 0) { 105 + dev_err(&framer->dev, "framer init failed --> %d\n", ret); 106 + goto out; 107 + } 108 + } 109 + if (framer->ops->flags & FRAMER_FLAG_POLL_STATUS) 110 + start_polling = true; 111 + } 112 + ++framer->init_count; 113 + 114 + out: 115 + mutex_unlock(&framer->mutex); 116 + 117 + if (!ret && start_polling) { 118 + ret = framer_get_status(framer, &framer->prev_status); 119 + if (ret < 0) { 120 + dev_warn(&framer->dev, "framer get status failed --> %d\n", ret); 121 + /* Will be retried on polling_work */ 122 + ret = 0; 123 + } 124 + queue_delayed_work(system_power_efficient_wq, &framer->polling_work, 1 * HZ); 125 + } 126 + 127 + framer_pm_runtime_put(framer); 128 + return ret; 129 + } 130 + EXPORT_SYMBOL_GPL(framer_init); 131 + 132 + /** 133 + * framer_exit - Framer internal un-initialization 134 + * @framer: the framer returned by framer_get() 135 + * 136 + * Must be called after framer_power_off(). 137 + */ 138 + int framer_exit(struct framer *framer) 139 + { 140 + int ret; 141 + 142 + ret = framer_pm_runtime_get_sync(framer); 143 + if (ret < 0 && ret != -EOPNOTSUPP) 144 + return ret; 145 + ret = 0; /* Override possible ret == -EOPNOTSUPP */ 146 + 147 + mutex_lock(&framer->mutex); 148 + --framer->init_count; 149 + if (framer->init_count == 0) { 150 + if (framer->ops->flags & FRAMER_FLAG_POLL_STATUS) { 151 + mutex_unlock(&framer->mutex); 152 + cancel_delayed_work_sync(&framer->polling_work); 153 + mutex_lock(&framer->mutex); 154 + } 155 + 156 + if (framer->ops->exit) 157 + framer->ops->exit(framer); 158 + } 159 + 160 + mutex_unlock(&framer->mutex); 161 + framer_pm_runtime_put(framer); 162 + return ret; 163 + } 164 + EXPORT_SYMBOL_GPL(framer_exit); 165 + 166 + /** 167 + * framer_power_on - Enable the framer and enter proper operation 168 + * @framer: the framer returned by framer_get() 169 + * 170 + * Must be called after framer_init(). 171 + * 172 + * Return: %0 if successful, a negative error code otherwise 173 + */ 174 + int framer_power_on(struct framer *framer) 175 + { 176 + int ret; 177 + 178 + if (framer->pwr) { 179 + ret = regulator_enable(framer->pwr); 180 + if (ret) 181 + return ret; 182 + } 183 + 184 + ret = framer_pm_runtime_get_sync(framer); 185 + if (ret < 0 && ret != -EOPNOTSUPP) 186 + goto err_pm_sync; 187 + 188 + mutex_lock(&framer->mutex); 189 + if (framer->power_count == 0 && framer->ops->power_on) { 190 + ret = framer->ops->power_on(framer); 191 + if (ret < 0) { 192 + dev_err(&framer->dev, "framer poweron failed --> %d\n", ret); 193 + goto err_pwr_on; 194 + } 195 + } 196 + ++framer->power_count; 197 + mutex_unlock(&framer->mutex); 198 + return 0; 199 + 200 + err_pwr_on: 201 + mutex_unlock(&framer->mutex); 202 + framer_pm_runtime_put_sync(framer); 203 + err_pm_sync: 204 + if (framer->pwr) 205 + regulator_disable(framer->pwr); 206 + return ret; 207 + } 208 + EXPORT_SYMBOL_GPL(framer_power_on); 209 + 210 + /** 211 + * framer_power_off - Disable the framer. 212 + * @framer: the framer returned by framer_get() 213 + * 214 + * Must be called before framer_exit(). 215 + * 216 + * Return: %0 if successful, a negative error code otherwise 217 + */ 218 + int framer_power_off(struct framer *framer) 219 + { 220 + int ret; 221 + 222 + mutex_lock(&framer->mutex); 223 + if (framer->power_count == 1 && framer->ops->power_off) { 224 + ret = framer->ops->power_off(framer); 225 + if (ret < 0) { 226 + dev_err(&framer->dev, "framer poweroff failed --> %d\n", ret); 227 + mutex_unlock(&framer->mutex); 228 + return ret; 229 + } 230 + } 231 + --framer->power_count; 232 + mutex_unlock(&framer->mutex); 233 + framer_pm_runtime_put(framer); 234 + 235 + if (framer->pwr) 236 + regulator_disable(framer->pwr); 237 + 238 + return 0; 239 + } 240 + EXPORT_SYMBOL_GPL(framer_power_off); 241 + 242 + /** 243 + * framer_get_status() - Gets the framer status 244 + * @framer: the framer returned by framer_get() 245 + * @status: the status to retrieve 246 + * 247 + * Used to get the framer status. framer_init() must have been called 248 + * on the framer. 249 + * 250 + * Return: %0 if successful, a negative error code otherwise 251 + */ 252 + int framer_get_status(struct framer *framer, struct framer_status *status) 253 + { 254 + int ret; 255 + 256 + if (!framer->ops->get_status) 257 + return -EOPNOTSUPP; 258 + 259 + /* Be sure to have known values (struct padding and future extensions) */ 260 + memset(status, 0, sizeof(*status)); 261 + 262 + mutex_lock(&framer->mutex); 263 + ret = framer->ops->get_status(framer, status); 264 + mutex_unlock(&framer->mutex); 265 + 266 + return ret; 267 + } 268 + EXPORT_SYMBOL_GPL(framer_get_status); 269 + 270 + /** 271 + * framer_set_config() - Sets the framer configuration 272 + * @framer: the framer returned by framer_get() 273 + * @config: the configuration to set 274 + * 275 + * Used to set the framer configuration. framer_init() must have been called 276 + * on the framer. 277 + * 278 + * Return: %0 if successful, a negative error code otherwise 279 + */ 280 + int framer_set_config(struct framer *framer, const struct framer_config *config) 281 + { 282 + int ret; 283 + 284 + if (!framer->ops->set_config) 285 + return -EOPNOTSUPP; 286 + 287 + mutex_lock(&framer->mutex); 288 + ret = framer->ops->set_config(framer, config); 289 + mutex_unlock(&framer->mutex); 290 + 291 + return ret; 292 + } 293 + EXPORT_SYMBOL_GPL(framer_set_config); 294 + 295 + /** 296 + * framer_get_config() - Gets the framer configuration 297 + * @framer: the framer returned by framer_get() 298 + * @config: the configuration to retrieve 299 + * 300 + * Used to get the framer configuration. framer_init() must have been called 301 + * on the framer. 302 + * 303 + * Return: %0 if successful, a negative error code otherwise 304 + */ 305 + int framer_get_config(struct framer *framer, struct framer_config *config) 306 + { 307 + int ret; 308 + 309 + if (!framer->ops->get_config) 310 + return -EOPNOTSUPP; 311 + 312 + mutex_lock(&framer->mutex); 313 + ret = framer->ops->get_config(framer, config); 314 + mutex_unlock(&framer->mutex); 315 + 316 + return ret; 317 + } 318 + EXPORT_SYMBOL_GPL(framer_get_config); 319 + 320 + static void framer_polling_work(struct work_struct *work) 321 + { 322 + struct framer *framer = container_of(work, struct framer, polling_work.work); 323 + struct framer_status status; 324 + int ret; 325 + 326 + ret = framer_get_status(framer, &status); 327 + if (ret) { 328 + dev_err(&framer->dev, "polling, get status failed (%d)\n", ret); 329 + goto end; 330 + } 331 + if (memcmp(&framer->prev_status, &status, sizeof(status))) { 332 + blocking_notifier_call_chain(&framer->notifier_list, 333 + FRAMER_EVENT_STATUS, NULL); 334 + memcpy(&framer->prev_status, &status, sizeof(status)); 335 + } 336 + 337 + end: 338 + /* Re-schedule task in 1 sec */ 339 + queue_delayed_work(system_power_efficient_wq, &framer->polling_work, 1 * HZ); 340 + } 341 + 342 + /** 343 + * framer_notifier_register() - Registers a notifier 344 + * @framer: the framer returned by framer_get() 345 + * @nb: the notifier block to register 346 + * 347 + * Used to register a notifier block on framer events. framer_init() must have 348 + * been called on the framer. 349 + * The available framer events are present in enum framer_events. 350 + * 351 + * Return: %0 if successful, a negative error code otherwise 352 + */ 353 + int framer_notifier_register(struct framer *framer, struct notifier_block *nb) 354 + { 355 + return blocking_notifier_chain_register(&framer->notifier_list, nb); 356 + } 357 + EXPORT_SYMBOL_GPL(framer_notifier_register); 358 + 359 + /** 360 + * framer_notifier_unregister() - Unregisters a notifier 361 + * @framer: the framer returned by framer_get() 362 + * @nb: the notifier block to unregister 363 + * 364 + * Used to unregister a notifier block. framer_init() must have 365 + * been called on the framer. 366 + * 367 + * Return: %0 if successful, a negative error code otherwise 368 + */ 369 + int framer_notifier_unregister(struct framer *framer, struct notifier_block *nb) 370 + { 371 + return blocking_notifier_chain_unregister(&framer->notifier_list, nb); 372 + } 373 + EXPORT_SYMBOL_GPL(framer_notifier_unregister); 374 + 375 + static struct framer_provider *framer_provider_of_lookup(const struct device_node *node) 376 + { 377 + struct framer_provider *framer_provider; 378 + 379 + list_for_each_entry(framer_provider, &framer_provider_list, list) { 380 + if (device_match_of_node(framer_provider->dev, node)) 381 + return framer_provider; 382 + } 383 + 384 + return ERR_PTR(-EPROBE_DEFER); 385 + } 386 + 387 + static struct framer *framer_of_get_from_provider(struct of_phandle_args *args) 388 + { 389 + struct framer_provider *framer_provider; 390 + struct framer *framer; 391 + 392 + mutex_lock(&framer_provider_mutex); 393 + framer_provider = framer_provider_of_lookup(args->np); 394 + if (IS_ERR(framer_provider) || !try_module_get(framer_provider->owner)) { 395 + framer = ERR_PTR(-EPROBE_DEFER); 396 + goto end; 397 + } 398 + 399 + framer = framer_provider->of_xlate(framer_provider->dev, args); 400 + 401 + module_put(framer_provider->owner); 402 + 403 + end: 404 + mutex_unlock(&framer_provider_mutex); 405 + 406 + return framer; 407 + } 408 + 409 + static struct framer *framer_of_get_byphandle(struct device_node *np, const char *propname, 410 + int index) 411 + { 412 + struct of_phandle_args args; 413 + struct framer *framer; 414 + int ret; 415 + 416 + ret = of_parse_phandle_with_optional_args(np, propname, "#framer-cells", index, &args); 417 + if (ret) 418 + return ERR_PTR(-ENODEV); 419 + 420 + if (!of_device_is_available(args.np)) { 421 + framer = ERR_PTR(-ENODEV); 422 + goto out_node_put; 423 + } 424 + 425 + framer = framer_of_get_from_provider(&args); 426 + 427 + out_node_put: 428 + of_node_put(args.np); 429 + 430 + return framer; 431 + } 432 + 433 + static struct framer *framer_of_get_byparent(struct device_node *np, int index) 434 + { 435 + struct of_phandle_args args; 436 + struct framer *framer; 437 + 438 + args.np = of_get_parent(np); 439 + args.args_count = 1; 440 + args.args[0] = index; 441 + 442 + while (args.np) { 443 + framer = framer_of_get_from_provider(&args); 444 + if (IS_ERR(framer) && PTR_ERR(framer) != -EPROBE_DEFER) { 445 + args.np = of_get_next_parent(args.np); 446 + continue; 447 + } 448 + of_node_put(args.np); 449 + return framer; 450 + } 451 + 452 + return ERR_PTR(-ENODEV); 453 + } 454 + 455 + /** 456 + * framer_get() - lookup and obtain a reference to a framer. 457 + * @dev: device that requests the framer 458 + * @con_id: name of the framer from device's point of view 459 + * 460 + * Returns the framer driver, after getting a refcount to it; or 461 + * -ENODEV if there is no such framer. The caller is responsible for 462 + * calling framer_put() to release that count. 463 + */ 464 + struct framer *framer_get(struct device *dev, const char *con_id) 465 + { 466 + struct framer *framer = ERR_PTR(-ENODEV); 467 + struct device_link *link; 468 + int ret; 469 + 470 + if (dev->of_node) { 471 + if (con_id) 472 + framer = framer_of_get_byphandle(dev->of_node, con_id, 0); 473 + else 474 + framer = framer_of_get_byparent(dev->of_node, 0); 475 + } 476 + 477 + if (IS_ERR(framer)) 478 + return framer; 479 + 480 + get_device(&framer->dev); 481 + 482 + if (!try_module_get(framer->ops->owner)) { 483 + ret = -EPROBE_DEFER; 484 + goto err_put_device; 485 + } 486 + 487 + link = device_link_add(dev, &framer->dev, DL_FLAG_STATELESS); 488 + if (!link) { 489 + dev_err(dev, "failed to create device_link to %s\n", dev_name(&framer->dev)); 490 + ret = -EPROBE_DEFER; 491 + goto err_module_put; 492 + } 493 + 494 + return framer; 495 + 496 + err_module_put: 497 + module_put(framer->ops->owner); 498 + err_put_device: 499 + put_device(&framer->dev); 500 + return ERR_PTR(ret); 501 + } 502 + EXPORT_SYMBOL_GPL(framer_get); 503 + 504 + /** 505 + * framer_put() - release the framer 506 + * @dev: device that wants to release this framer 507 + * @framer: the framer returned by framer_get() 508 + * 509 + * Releases a refcount the caller received from framer_get(). 510 + */ 511 + void framer_put(struct device *dev, struct framer *framer) 512 + { 513 + device_link_remove(dev, &framer->dev); 514 + 515 + module_put(framer->ops->owner); 516 + put_device(&framer->dev); 517 + } 518 + EXPORT_SYMBOL_GPL(framer_put); 519 + 520 + static void devm_framer_put(struct device *dev, void *res) 521 + { 522 + struct framer *framer = *(struct framer **)res; 523 + 524 + framer_put(dev, framer); 525 + } 526 + 527 + /** 528 + * devm_framer_get() - lookup and obtain a reference to a framer. 529 + * @dev: device that requests this framer 530 + * @con_id: name of the framer from device's point of view 531 + * 532 + * Gets the framer using framer_get(), and associates a device with it using 533 + * devres. On driver detach, framer_put() function is invoked on the devres 534 + * data, then, devres data is freed. 535 + */ 536 + struct framer *devm_framer_get(struct device *dev, const char *con_id) 537 + { 538 + struct framer **ptr, *framer; 539 + 540 + ptr = devres_alloc(devm_framer_put, sizeof(*ptr), GFP_KERNEL); 541 + if (!ptr) 542 + return ERR_PTR(-ENOMEM); 543 + 544 + framer = framer_get(dev, con_id); 545 + if (!IS_ERR(framer)) { 546 + *ptr = framer; 547 + devres_add(dev, ptr); 548 + } else { 549 + devres_free(ptr); 550 + return framer; 551 + } 552 + 553 + return framer; 554 + } 555 + EXPORT_SYMBOL_GPL(devm_framer_get); 556 + 557 + /** 558 + * devm_framer_optional_get() - lookup and obtain a reference to an optional 559 + * framer. 560 + * @dev: device that requests this framer 561 + * @con_id: name of the framer from device's point of view 562 + * 563 + * Same as devm_framer_get() except that if the framer does not exist, it is not 564 + * considered an error and -ENODEV will not be returned. Instead the NULL framer 565 + * is returned. 566 + */ 567 + struct framer *devm_framer_optional_get(struct device *dev, const char *con_id) 568 + { 569 + struct framer *framer = devm_framer_get(dev, con_id); 570 + 571 + if (PTR_ERR(framer) == -ENODEV) 572 + framer = NULL; 573 + 574 + return framer; 575 + } 576 + EXPORT_SYMBOL_GPL(devm_framer_optional_get); 577 + 578 + static void framer_notify_status_work(struct work_struct *work) 579 + { 580 + struct framer *framer = container_of(work, struct framer, notify_status_work); 581 + 582 + blocking_notifier_call_chain(&framer->notifier_list, FRAMER_EVENT_STATUS, NULL); 583 + } 584 + 585 + void framer_notify_status_change(struct framer *framer) 586 + { 587 + /* Can be called from atomic context -> just schedule a task to call 588 + * blocking notifiers 589 + */ 590 + queue_work(system_power_efficient_wq, &framer->notify_status_work); 591 + } 592 + EXPORT_SYMBOL_GPL(framer_notify_status_change); 593 + 594 + /** 595 + * framer_create() - create a new framer 596 + * @dev: device that is creating the new framer 597 + * @node: device node of the framer. default to dev->of_node. 598 + * @ops: function pointers for performing framer operations 599 + * 600 + * Called to create a framer using framer framework. 601 + */ 602 + struct framer *framer_create(struct device *dev, struct device_node *node, 603 + const struct framer_ops *ops) 604 + { 605 + struct framer *framer; 606 + int ret; 607 + int id; 608 + 609 + /* get_status() is mandatory if the provider ask for polling status */ 610 + if (WARN_ON((ops->flags & FRAMER_FLAG_POLL_STATUS) && !ops->get_status)) 611 + return ERR_PTR(-EINVAL); 612 + 613 + framer = kzalloc(sizeof(*framer), GFP_KERNEL); 614 + if (!framer) 615 + return ERR_PTR(-ENOMEM); 616 + 617 + id = ida_alloc(&framer_ida, GFP_KERNEL); 618 + if (id < 0) { 619 + dev_err(dev, "unable to get id\n"); 620 + ret = id; 621 + goto free_framer; 622 + } 623 + 624 + device_initialize(&framer->dev); 625 + mutex_init(&framer->mutex); 626 + INIT_WORK(&framer->notify_status_work, framer_notify_status_work); 627 + INIT_DELAYED_WORK(&framer->polling_work, framer_polling_work); 628 + BLOCKING_INIT_NOTIFIER_HEAD(&framer->notifier_list); 629 + 630 + framer->dev.class = framer_class; 631 + framer->dev.parent = dev; 632 + framer->dev.of_node = node ? node : dev->of_node; 633 + framer->id = id; 634 + framer->ops = ops; 635 + 636 + ret = dev_set_name(&framer->dev, "framer-%s.%d", dev_name(dev), id); 637 + if (ret) 638 + goto put_dev; 639 + 640 + /* framer-supply */ 641 + framer->pwr = regulator_get_optional(&framer->dev, "framer"); 642 + if (IS_ERR(framer->pwr)) { 643 + ret = PTR_ERR(framer->pwr); 644 + if (ret == -EPROBE_DEFER) 645 + goto put_dev; 646 + 647 + framer->pwr = NULL; 648 + } 649 + 650 + ret = device_add(&framer->dev); 651 + if (ret) 652 + goto put_dev; 653 + 654 + if (pm_runtime_enabled(dev)) { 655 + pm_runtime_enable(&framer->dev); 656 + pm_runtime_no_callbacks(&framer->dev); 657 + } 658 + 659 + return framer; 660 + 661 + put_dev: 662 + put_device(&framer->dev); /* calls framer_release() which frees resources */ 663 + return ERR_PTR(ret); 664 + 665 + free_framer: 666 + kfree(framer); 667 + return ERR_PTR(ret); 668 + } 669 + EXPORT_SYMBOL_GPL(framer_create); 670 + 671 + /** 672 + * framer_destroy() - destroy the framer 673 + * @framer: the framer to be destroyed 674 + * 675 + * Called to destroy the framer. 676 + */ 677 + void framer_destroy(struct framer *framer) 678 + { 679 + /* polling_work should already be stopped but if framer_exit() was not 680 + * called (bug), here it's the last time to do that ... 681 + */ 682 + cancel_delayed_work_sync(&framer->polling_work); 683 + cancel_work_sync(&framer->notify_status_work); 684 + pm_runtime_disable(&framer->dev); 685 + device_unregister(&framer->dev); /* calls framer_release() which frees resources */ 686 + } 687 + EXPORT_SYMBOL_GPL(framer_destroy); 688 + 689 + static void devm_framer_destroy(struct device *dev, void *res) 690 + { 691 + struct framer *framer = *(struct framer **)res; 692 + 693 + framer_destroy(framer); 694 + } 695 + 696 + /** 697 + * devm_framer_create() - create a new framer 698 + * @dev: device that is creating the new framer 699 + * @node: device node of the framer 700 + * @ops: function pointers for performing framer operations 701 + * 702 + * Creates a new framer device adding it to the framer class. 703 + * While at that, it also associates the device with the framer using devres. 704 + * On driver detach, release function is invoked on the devres data, 705 + * then, devres data is freed. 706 + */ 707 + struct framer *devm_framer_create(struct device *dev, struct device_node *node, 708 + const struct framer_ops *ops) 709 + { 710 + struct framer **ptr, *framer; 711 + 712 + ptr = devres_alloc(devm_framer_destroy, sizeof(*ptr), GFP_KERNEL); 713 + if (!ptr) 714 + return ERR_PTR(-ENOMEM); 715 + 716 + framer = framer_create(dev, node, ops); 717 + if (!IS_ERR(framer)) { 718 + *ptr = framer; 719 + devres_add(dev, ptr); 720 + } else { 721 + devres_free(ptr); 722 + } 723 + 724 + return framer; 725 + } 726 + EXPORT_SYMBOL_GPL(devm_framer_create); 727 + 728 + /** 729 + * framer_provider_simple_of_xlate() - returns the framer instance from framer provider 730 + * @dev: the framer provider device 731 + * @args: of_phandle_args (not used here) 732 + * 733 + * Intended to be used by framer provider for the common case where #framer-cells is 734 + * 0. For other cases where #framer-cells is greater than '0', the framer provider 735 + * should provide a custom of_xlate function that reads the *args* and returns 736 + * the appropriate framer. 737 + */ 738 + struct framer *framer_provider_simple_of_xlate(struct device *dev, struct of_phandle_args *args) 739 + { 740 + struct class_dev_iter iter; 741 + struct framer *framer; 742 + 743 + class_dev_iter_init(&iter, framer_class, NULL, NULL); 744 + while ((dev = class_dev_iter_next(&iter))) { 745 + framer = dev_to_framer(dev); 746 + if (args->np != framer->dev.of_node) 747 + continue; 748 + 749 + class_dev_iter_exit(&iter); 750 + return framer; 751 + } 752 + 753 + class_dev_iter_exit(&iter); 754 + return ERR_PTR(-ENODEV); 755 + } 756 + EXPORT_SYMBOL_GPL(framer_provider_simple_of_xlate); 757 + 758 + /** 759 + * __framer_provider_of_register() - create/register framer provider with the framework 760 + * @dev: struct device of the framer provider 761 + * @owner: the module owner containing of_xlate 762 + * @of_xlate: function pointer to obtain framer instance from framer provider 763 + * 764 + * Creates struct framer_provider from dev and of_xlate function pointer. 765 + * This is used in the case of dt boot for finding the framer instance from 766 + * framer provider. 767 + */ 768 + struct framer_provider * 769 + __framer_provider_of_register(struct device *dev, struct module *owner, 770 + struct framer *(*of_xlate)(struct device *dev, 771 + struct of_phandle_args *args)) 772 + { 773 + struct framer_provider *framer_provider; 774 + 775 + framer_provider = kzalloc(sizeof(*framer_provider), GFP_KERNEL); 776 + if (!framer_provider) 777 + return ERR_PTR(-ENOMEM); 778 + 779 + framer_provider->dev = dev; 780 + framer_provider->owner = owner; 781 + framer_provider->of_xlate = of_xlate; 782 + 783 + of_node_get(framer_provider->dev->of_node); 784 + 785 + mutex_lock(&framer_provider_mutex); 786 + list_add_tail(&framer_provider->list, &framer_provider_list); 787 + mutex_unlock(&framer_provider_mutex); 788 + 789 + return framer_provider; 790 + } 791 + EXPORT_SYMBOL_GPL(__framer_provider_of_register); 792 + 793 + /** 794 + * framer_provider_of_unregister() - unregister framer provider from the framework 795 + * @framer_provider: framer provider returned by framer_provider_of_register() 796 + * 797 + * Removes the framer_provider created using framer_provider_of_register(). 798 + */ 799 + void framer_provider_of_unregister(struct framer_provider *framer_provider) 800 + { 801 + mutex_lock(&framer_provider_mutex); 802 + list_del(&framer_provider->list); 803 + mutex_unlock(&framer_provider_mutex); 804 + 805 + of_node_put(framer_provider->dev->of_node); 806 + kfree(framer_provider); 807 + } 808 + EXPORT_SYMBOL_GPL(framer_provider_of_unregister); 809 + 810 + static void devm_framer_provider_of_unregister(struct device *dev, void *res) 811 + { 812 + struct framer_provider *framer_provider = *(struct framer_provider **)res; 813 + 814 + framer_provider_of_unregister(framer_provider); 815 + } 816 + 817 + /** 818 + * __devm_framer_provider_of_register() - create/register framer provider with 819 + * the framework 820 + * @dev: struct device of the framer provider 821 + * @owner: the module owner containing of_xlate 822 + * @of_xlate: function pointer to obtain framer instance from framer provider 823 + * 824 + * Creates struct framer_provider from dev and of_xlate function pointer. 825 + * This is used in the case of dt boot for finding the framer instance from 826 + * framer provider. While at that, it also associates the device with the 827 + * framer provider using devres. On driver detach, release function is invoked 828 + * on the devres data, then, devres data is freed. 829 + */ 830 + struct framer_provider * 831 + __devm_framer_provider_of_register(struct device *dev, struct module *owner, 832 + struct framer *(*of_xlate)(struct device *dev, 833 + struct of_phandle_args *args)) 834 + { 835 + struct framer_provider **ptr, *framer_provider; 836 + 837 + ptr = devres_alloc(devm_framer_provider_of_unregister, sizeof(*ptr), GFP_KERNEL); 838 + if (!ptr) 839 + return ERR_PTR(-ENOMEM); 840 + 841 + framer_provider = __framer_provider_of_register(dev, owner, of_xlate); 842 + if (!IS_ERR(framer_provider)) { 843 + *ptr = framer_provider; 844 + devres_add(dev, ptr); 845 + } else { 846 + devres_free(ptr); 847 + } 848 + 849 + return framer_provider; 850 + } 851 + EXPORT_SYMBOL_GPL(__devm_framer_provider_of_register); 852 + 853 + /** 854 + * framer_release() - release the framer 855 + * @dev: the dev member within framer 856 + * 857 + * When the last reference to the device is removed, it is called 858 + * from the embedded kobject as release method. 859 + */ 860 + static void framer_release(struct device *dev) 861 + { 862 + struct framer *framer; 863 + 864 + framer = dev_to_framer(dev); 865 + regulator_put(framer->pwr); 866 + ida_free(&framer_ida, framer->id); 867 + kfree(framer); 868 + } 869 + 870 + static int __init framer_core_init(void) 871 + { 872 + framer_class = class_create("framer"); 873 + if (IS_ERR(framer_class)) { 874 + pr_err("failed to create framer class (%pe)\n", framer_class); 875 + return PTR_ERR(framer_class); 876 + } 877 + 878 + framer_class->dev_release = framer_release; 879 + 880 + return 0; 881 + } 882 + device_initcall(framer_core_init);
+8
drivers/net/wan/framer/pef2256/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + # 3 + # Makefile for the pef2256 driver. 4 + # 5 + 6 + obj-$(CONFIG_FRAMER_PEF2256) += framer-pef2256.o 7 + 8 + framer-pef2256-objs := pef2256.o
+250
drivers/net/wan/framer/pef2256/pef2256-regs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * PEF2256 registers definition 4 + * 5 + * Copyright 2023 CS GROUP France 6 + * 7 + * Author: Herve Codina <herve.codina@bootlin.com> 8 + */ 9 + #ifndef __PEF2256_REGS_H__ 10 + #define __PEF2256_REGS_H__ 11 + 12 + #include "linux/bitfield.h" 13 + 14 + /* Command Register */ 15 + #define PEF2256_CMDR 0x02 16 + #define PEF2256_CMDR_RRES BIT(6) 17 + #define PEF2256_CMDR_XRES BIT(4) 18 + #define PEF2256_CMDR_SRES BIT(0) 19 + 20 + /* Interrupt Mask Register 0..5 */ 21 + #define PEF2256_IMR0 0x14 22 + #define PEF2256_IMR1 0x15 23 + #define PEF2256_IMR2 0x16 24 + #define PEF2256_IMR3 0x17 25 + #define PEF2256_IMR4 0x18 26 + #define PEF2256_IMR5 0x19 27 + 28 + /* Framer Mode Register 0 */ 29 + #define PEF2256_FMR0 0x1C 30 + #define PEF2256_FMR0_XC_MASK GENMASK(7, 6) 31 + #define PEF2256_FMR0_XC_NRZ FIELD_PREP_CONST(PEF2256_FMR0_XC_MASK, 0x0) 32 + #define PEF2256_FMR0_XC_CMI FIELD_PREP_CONST(PEF2256_FMR0_XC_MASK, 0x1) 33 + #define PEF2256_FMR0_XC_AMI FIELD_PREP_CONST(PEF2256_FMR0_XC_MASK, 0x2) 34 + #define PEF2256_FMR0_XC_HDB3 FIELD_PREP_CONST(PEF2256_FMR0_XC_MASK, 0x3) 35 + #define PEF2256_FMR0_RC_MASK GENMASK(5, 4) 36 + #define PEF2256_FMR0_RC_NRZ FIELD_PREP_CONST(PEF2256_FMR0_RC_MASK, 0x0) 37 + #define PEF2256_FMR0_RC_CMI FIELD_PREP_CONST(PEF2256_FMR0_RC_MASK, 0x1) 38 + #define PEF2256_FMR0_RC_AMI FIELD_PREP_CONST(PEF2256_FMR0_RC_MASK, 0x2) 39 + #define PEF2256_FMR0_RC_HDB3 FIELD_PREP_CONST(PEF2256_FMR0_RC_MASK, 0x3) 40 + 41 + /* Framer Mode Register 1 */ 42 + #define PEF2256_FMR1 0x1D 43 + #define PEF2256_FMR1_XFS BIT(3) 44 + #define PEF2256_FMR1_ECM BIT(2) 45 + /* SSD is defined on 2 bits. The other bit is on SIC1 register */ 46 + #define PEF2256_FMR1_SSD_MASK GENMASK(1, 1) 47 + #define PEF2256_FMR1_SSD_2048 FIELD_PREP_CONST(PEF2256_FMR1_SSD_MASK, 0x0) 48 + #define PEF2256_FMR1_SSD_4096 FIELD_PREP_CONST(PEF2256_FMR1_SSD_MASK, 0x1) 49 + #define PEF2256_FMR1_SSD_8192 FIELD_PREP_CONST(PEF2256_FMR1_SSD_MASK, 0x0) 50 + #define PEF2256_FMR1_SSD_16384 FIELD_PREP_CONST(PEF2256_FMR1_SSD_MASK, 0x1) 51 + 52 + /* Framer Mode Register 2 */ 53 + #define PEF2256_FMR2 0x1E 54 + #define PEF2256_FMR2_RFS_MASK GENMASK(7, 6) 55 + #define PEF2256_FMR2_RFS_DOUBLEFRAME FIELD_PREP_CONST(PEF2256_FMR2_RFS_MASK, 0x0) 56 + #define PEF2256_FMR2_RFS_CRC4_MULTIFRAME FIELD_PREP_CONST(PEF2256_FMR2_RFS_MASK, 0x2) 57 + #define PEF2256_FMR2_RFS_AUTO_MULTIFRAME FIELD_PREP_CONST(PEF2256_FMR2_RFS_MASK, 0x3) 58 + #define PEF2256_FMR2_AXRA BIT(1) 59 + 60 + /* Transmit Service Word */ 61 + #define PEF2256_XSW 0x20 62 + #define PEF2256_XSW_XSIS BIT(7) 63 + #define PEF2256_XSW_XTM BIT(6) 64 + #define PEF2256_XSW_XY_MASK GENMASK(5, 0) 65 + #define PEF2256_XSW_XY(_v) FIELD_PREP(PEF2256_XSW_XY_MASK, _v) 66 + 67 + /* Transmit Spare Bits */ 68 + #define PEF2256_XSP 0x21 69 + #define PEF2256_XSP_XSIF BIT(2) 70 + 71 + /* Transmit Control 0..1 */ 72 + #define PEF2256_XC0 0x22 73 + #define PEF2256_XC1 0x23 74 + 75 + /* Receive Control 0 */ 76 + #define PEF2256_RC0 0x24 77 + #define PEF2256_RC0_SWD BIT(7) 78 + #define PEF2256_RC0_ASY4 BIT(6) 79 + 80 + /* Receive Control 1 */ 81 + #define PEF2256_RC1 0x25 82 + 83 + /* Transmit Pulse Mask 0..1 */ 84 + #define PEF2256_XPM0 0x26 85 + #define PEF2256_XPM1 0x27 86 + 87 + /* Transmit Pulse Mask 2 */ 88 + #define PEF2256_XPM2 0x28 89 + #define PEF2256_XPM2_XLT BIT(6) 90 + 91 + /* Transparent Service Word Mask */ 92 + #define PEF2256_TSWM 0x29 93 + 94 + /* Line Interface Mode 0 */ 95 + #define PEF2256_LIM0 0x36 96 + #define PEF2256_2X_LIM0_BIT3 BIT(3) /* v2.x, described as a forced '1' bit */ 97 + #define PEF2256_LIM0_MAS BIT(0) 98 + 99 + /* Line Interface Mode 1 */ 100 + #define PEF2256_LIM1 0x37 101 + #define PEF2256_12_LIM1_RIL_MASK GENMASK(6, 4) 102 + #define PEF2256_12_LIM1_RIL_910 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x0) 103 + #define PEF2256_12_LIM1_RIL_740 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x1) 104 + #define PEF2256_12_LIM1_RIL_590 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x2) 105 + #define PEF2256_12_LIM1_RIL_420 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x3) 106 + #define PEF2256_12_LIM1_RIL_320 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x4) 107 + #define PEF2256_12_LIM1_RIL_210 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x5) 108 + #define PEF2256_12_LIM1_RIL_160 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x6) 109 + #define PEF2256_12_LIM1_RIL_100 FIELD_PREP_CONST(PEF2256_12_LIM1_RIL_MASK, 0x7) 110 + #define PEF2256_2X_LIM1_RIL_MASK GENMASK(6, 4) 111 + #define PEF2256_2X_LIM1_RIL_2250 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x0) 112 + #define PEF2256_2X_LIM1_RIL_1100 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x1) 113 + #define PEF2256_2X_LIM1_RIL_600 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x2) 114 + #define PEF2256_2X_LIM1_RIL_350 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x3) 115 + #define PEF2256_2X_LIM1_RIL_210 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x4) 116 + #define PEF2256_2X_LIM1_RIL_140 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x5) 117 + #define PEF2256_2X_LIM1_RIL_100 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x6) 118 + #define PEF2256_2X_LIM1_RIL_50 FIELD_PREP_CONST(PEF2256_2X_LIM1_RIL_MASK, 0x7) 119 + 120 + /* Pulse Count Detection */ 121 + #define PEF2256_PCD 0x38 122 + 123 + /* Pulse Count Recovery */ 124 + #define PEF2256_PCR 0x39 125 + 126 + /* Line Interface Mode 2 */ 127 + #define PEF2256_LIM2 0x3A 128 + #define PEF2256_LIM2_SLT_MASK GENMASK(5, 4) 129 + #define PEF2256_LIM2_SLT_THR55 FIELD_PREP_CONST(PEF2256_LIM2_SLT_MASK, 0x0) 130 + #define PEF2256_LIM2_SLT_THR67 FIELD_PREP_CONST(PEF2256_LIM2_SLT_MASK, 0x1) 131 + #define PEF2256_LIM2_SLT_THR50 FIELD_PREP_CONST(PEF2256_LIM2_SLT_MASK, 0x2) 132 + #define PEF2256_LIM2_SLT_THR45 FIELD_PREP_CONST(PEF2256_LIM2_SLT_MASK, 0x3) 133 + #define PEF2256_LIM2_ELT BIT(2) 134 + 135 + /* System Interface Control 1 */ 136 + #define PEF2256_SIC1 0x3E 137 + #define PEF2256_SIC1_SSC_MASK (BIT(7) | BIT(3)) 138 + #define PEF2256_SIC1_SSC_2048 (0) 139 + #define PEF2256_SIC1_SSC_4096 BIT(3) 140 + #define PEF2256_SIC1_SSC_8192 BIT(7) 141 + #define PEF2256_SIC1_SSC_16384 (BIT(7) | BIT(3)) 142 + /* SSD is defined on 2 bits. The other bit is on FMR1 register */ 143 + #define PEF2256_SIC1_SSD_MASK GENMASK(6, 6) 144 + #define PEF2256_SIC1_SSD_2048 FIELD_PREP_CONST(PEF2256_SIC1_SSD_MASK, 0x0) 145 + #define PEF2256_SIC1_SSD_4096 FIELD_PREP_CONST(PEF2256_SIC1_SSD_MASK, 0x0) 146 + #define PEF2256_SIC1_SSD_8192 FIELD_PREP_CONST(PEF2256_SIC1_SSD_MASK, 0x1) 147 + #define PEF2256_SIC1_SSD_16384 FIELD_PREP_CONST(PEF2256_SIC1_SSD_MASK, 0x1) 148 + #define PEF2256_SIC1_RBS_MASK GENMASK(5, 4) 149 + #define PEF2256_SIC1_RBS_2FRAMES FIELD_PREP_CONST(PEF2256_SIC1_RBS_MASK, 0x0) 150 + #define PEF2256_SIC1_RBS_1FRAME FIELD_PREP_CONST(PEF2256_SIC1_RBS_MASK, 0x1) 151 + #define PEF2256_SIC1_RBS_96BITS FIELD_PREP_CONST(PEF2256_SIC1_RBS_MASK, 0x2) 152 + #define PEF2256_SIC1_RBS_BYPASS FIELD_PREP_CONST(PEF2256_SIC1_RBS_MASK, 0x3) 153 + #define PEF2256_SIC1_XBS_MASK GENMASK(1, 0) 154 + #define PEF2256_SIC1_XBS_BYPASS FIELD_PREP_CONST(PEF2256_SIC1_XBS_MASK, 0x0) 155 + #define PEF2256_SIC1_XBS_1FRAME FIELD_PREP_CONST(PEF2256_SIC1_XBS_MASK, 0x1) 156 + #define PEF2256_SIC1_XBS_2FRAMES FIELD_PREP_CONST(PEF2256_SIC1_XBS_MASK, 0x2) 157 + #define PEF2256_SIC1_XBS_96BITS FIELD_PREP_CONST(PEF2256_SIC1_XBS_MASK, 0x3) 158 + 159 + /* System Interface Control 2 */ 160 + #define PEF2256_SIC2 0x3F 161 + #define PEF2256_SIC2_SICS_MASK GENMASK(3, 1) 162 + #define PEF2256_SIC2_SICS(_v) FIELD_PREP(PEF2256_SIC2_SICS_MASK, _v) 163 + 164 + /* System Interface Control 3 */ 165 + #define PEF2256_SIC3 0x40 166 + #define PEF2256_SIC3_RTRI BIT(5) 167 + #define PEF2256_SIC3_RESX BIT(3) 168 + #define PEF2256_SIC3_RESR BIT(2) 169 + 170 + /* Clock Mode Register 1 */ 171 + #define PEF2256_CMR1 0x44 172 + #define PEF2256_CMR1_RS_MASK GENMASK(5, 4) 173 + #define PEF2256_CMR1_RS_DPLL FIELD_PREP_CONST(PEF2256_CMR1_RS_MASK, 0x0) 174 + #define PEF2256_CMR1_RS_DPLL_LOS_HIGH FIELD_PREP_CONST(PEF2256_CMR1_RS_MASK, 0x1) 175 + #define PEF2256_CMR1_RS_DCOR_2048 FIELD_PREP_CONST(PEF2256_CMR1_RS_MASK, 0x2) 176 + #define PEF2256_CMR1_RS_DCOR_8192 FIELD_PREP_CONST(PEF2256_CMR1_RS_MASK, 0x3) 177 + #define PEF2256_CMR1_DCS BIT(3) 178 + 179 + /* Clock Mode Register 2 */ 180 + #define PEF2256_CMR2 0x45 181 + #define PEF2256_CMR2_DCOXC BIT(5) 182 + 183 + /* Global Configuration Register */ 184 + #define PEF2256_GCR 0x46 185 + #define PEF2256_GCR_SCI BIT(6) 186 + #define PEF2256_GCR_ECMC BIT(4) 187 + 188 + /* Port Configuration 5 */ 189 + #define PEF2256_PC5 0x84 190 + #define PEF2256_PC5_CRP BIT(0) 191 + 192 + /* Global Port Configuration 1 */ 193 + #define PEF2256_GPC1 0x85 194 + #define PEF2256_GPC1_CSFP_MASK GENMASK(7, 5) 195 + #define PEF2256_GPC1_CSFP_SEC_IN_HIGH FIELD_PREP_CONST(PEF2256_GPC1_CSFP_MASK, 0x0) 196 + #define PEF2256_GPC1_CSFP_SEC_OUT_HIGH FIELD_PREP_CONST(PEF2256_GPC1_CSFP_MASK, 0x1) 197 + #define PEF2256_GPC1_CSFP_FSC_OUT_HIGH FIELD_PREP_CONST(PEF2256_GPC1_CSFP_MASK, 0x2) 198 + #define PEF2256_GPC1_CSFP_FSC_OUT_LOW FIELD_PREP_CONST(PEF2256_GPC1_CSFP_MASK, 0x3) 199 + 200 + /* Port Configuration 6 */ 201 + #define PEF2256_PC6 0x86 202 + 203 + /* Global Counter Mode n=1..8 */ 204 + #define PEF2256_GCM(_n) (0x92 + (_n) - 1) 205 + #define PEF2256_GCM1 0x92 206 + #define PEF2256_GCM2 0x93 207 + #define PEF2256_GCM3 0x94 208 + #define PEF2256_GCM4 0x95 209 + #define PEF2256_GCM5 0x96 210 + #define PEF2256_GCM6 0x97 211 + #define PEF2256_GCM7 0x98 212 + #define PEF2256_GCM8 0x99 213 + 214 + /* Version Status Register */ 215 + #define PEF2256_VSTR 0x4A 216 + #define PEF2256_VSTR_VERSION_12 0x00 217 + #define PEF2256_VSTR_VERSION_21 0x10 218 + #define PEF2256_VSTR_VERSION_2x 0x05 219 + 220 + /* Framer Receive Status 0 */ 221 + #define PEF2256_FRS0 0x4C 222 + #define PEF2256_FRS0_LOS BIT(7) 223 + #define PEF2256_FRS0_AIS BIT(6) 224 + 225 + /* Interrupt Status Register 0..5 */ 226 + #define PEF2256_ISR(_n) (0x68 + (_n)) 227 + #define PEF2256_ISR0 0x68 228 + #define PEF2256_ISR1 0x69 229 + #define PEF2256_ISR2 0x6A 230 + #define PEF2256_ISR3 0x6B 231 + #define PEF2256_ISR4 0x6C 232 + #define PEF2256_ISR5 0x6D 233 + 234 + /* Global Interrupt Status */ 235 + #define PEF2256_GIS 0x6E 236 + #define PEF2256_GIS_ISR(_n) BIT(_n) 237 + 238 + /* Wafer Identification Register */ 239 + #define PEF2256_WID 0xEC 240 + #define PEF2256_12_WID_MASK GENMASK(1, 0) 241 + #define PEF2256_12_WID_VERSION_12 FIELD_PREP_CONST(PEF2256_12_WID_MASK, 0x3) 242 + #define PEF2256_2X_WID_MASK GENMASK(7, 6) 243 + #define PEF2256_2X_WID_VERSION_21 FIELD_PREP_CONST(PEF2256_2X_WID_MASK, 0x0) 244 + #define PEF2256_2X_WID_VERSION_22 FIELD_PREP_CONST(PEF2256_2X_WID_MASK, 0x1) 245 + 246 + /* IMR2/ISR2 Interrupts common bits */ 247 + #define PEF2256_INT2_AIS BIT(3) 248 + #define PEF2256_INT2_LOS BIT(2) 249 + 250 + #endif /* __PEF2256_REGS_H__ */
+880
drivers/net/wan/framer/pef2256/pef2256.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * PEF2256 also known as FALC56 driver 4 + * 5 + * Copyright 2023 CS GROUP France 6 + * 7 + * Author: Herve Codina <herve.codina@bootlin.com> 8 + */ 9 + 10 + #include <linux/framer/pef2256.h> 11 + #include <linux/clk.h> 12 + #include <linux/framer/framer-provider.h> 13 + #include <linux/gpio/consumer.h> 14 + #include <linux/interrupt.h> 15 + #include <linux/io.h> 16 + #include <linux/mfd/core.h> 17 + #include <linux/module.h> 18 + #include <linux/notifier.h> 19 + #include <linux/of.h> 20 + #include <linux/of_platform.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/regmap.h> 23 + #include <linux/slab.h> 24 + #include "pef2256-regs.h" 25 + 26 + enum pef2256_frame_type { 27 + PEF2256_FRAME_E1_DOUBLEFRAME, 28 + PEF2256_FRAME_E1_CRC4_MULTIFRAME, 29 + PEF2256_FRAME_E1_AUTO_MULTIFRAME, 30 + PEF2256_FRAME_T1J1_4FRAME, 31 + PEF2256_FRAME_T1J1_12FRAME, 32 + PEF2256_FRAME_T1J1_24FRAME, 33 + PEF2256_FRAME_T1J1_72FRAME, 34 + }; 35 + 36 + struct pef2256 { 37 + struct device *dev; 38 + struct regmap *regmap; 39 + enum pef2256_version version; 40 + struct clk *mclk; 41 + struct clk *sclkr; 42 + struct clk *sclkx; 43 + struct gpio_desc *reset_gpio; 44 + unsigned long sysclk_rate; 45 + u32 data_rate; 46 + bool is_tx_falling_edge; 47 + bool is_subordinate; 48 + enum pef2256_frame_type frame_type; 49 + u8 channel_phase; 50 + atomic_t carrier; 51 + struct framer *framer; 52 + }; 53 + 54 + static u8 pef2256_read8(struct pef2256 *pef2256, int offset) 55 + { 56 + int val; 57 + 58 + regmap_read(pef2256->regmap, offset, &val); 59 + return val; 60 + } 61 + 62 + static void pef2256_write8(struct pef2256 *pef2256, int offset, u8 val) 63 + { 64 + regmap_write(pef2256->regmap, offset, val); 65 + } 66 + 67 + static void pef2256_clrbits8(struct pef2256 *pef2256, int offset, u8 clr) 68 + { 69 + regmap_clear_bits(pef2256->regmap, offset, clr); 70 + } 71 + 72 + static void pef2256_setbits8(struct pef2256 *pef2256, int offset, u8 set) 73 + { 74 + regmap_set_bits(pef2256->regmap, offset, set); 75 + } 76 + 77 + static void pef2256_clrsetbits8(struct pef2256 *pef2256, int offset, u8 clr, u8 set) 78 + { 79 + regmap_update_bits(pef2256->regmap, offset, clr | set, set); 80 + } 81 + 82 + enum pef2256_version pef2256_get_version(struct pef2256 *pef2256) 83 + { 84 + enum pef2256_version version = PEF2256_VERSION_UNKNOWN; 85 + u8 vstr, wid; 86 + 87 + vstr = pef2256_read8(pef2256, PEF2256_VSTR); 88 + wid = pef2256_read8(pef2256, PEF2256_WID); 89 + 90 + switch (vstr) { 91 + case PEF2256_VSTR_VERSION_12: 92 + if ((wid & PEF2256_12_WID_MASK) == PEF2256_12_WID_VERSION_12) 93 + version = PEF2256_VERSION_1_2; 94 + break; 95 + case PEF2256_VSTR_VERSION_2x: 96 + switch (wid & PEF2256_2X_WID_MASK) { 97 + case PEF2256_2X_WID_VERSION_21: 98 + version = PEF2256_VERSION_2_1; 99 + break; 100 + case PEF2256_2X_WID_VERSION_22: 101 + version = PEF2256_VERSION_2_2; 102 + break; 103 + } 104 + break; 105 + case PEF2256_VSTR_VERSION_21: 106 + version = PEF2256_VERSION_2_1; 107 + break; 108 + } 109 + 110 + if (version == PEF2256_VERSION_UNKNOWN) 111 + dev_err(pef2256->dev, "Unknown version (0x%02x, 0x%02x)\n", vstr, wid); 112 + 113 + return version; 114 + } 115 + EXPORT_SYMBOL_GPL(pef2256_get_version); 116 + 117 + enum pef2256_gcm_config_item { 118 + PEF2256_GCM_CONFIG_1544000 = 0, 119 + PEF2256_GCM_CONFIG_2048000, 120 + PEF2256_GCM_CONFIG_8192000, 121 + PEF2256_GCM_CONFIG_10000000, 122 + PEF2256_GCM_CONFIG_12352000, 123 + PEF2256_GCM_CONFIG_16384000, 124 + }; 125 + 126 + struct pef2256_gcm_config { 127 + u8 gcm_12[6]; 128 + u8 gcm_2x[8]; 129 + }; 130 + 131 + static const struct pef2256_gcm_config pef2256_gcm_configs[] = { 132 + [PEF2256_GCM_CONFIG_1544000] = { 133 + .gcm_12 = {0xF0, 0x51, 0x00, 0x80, 0x00, 0x15}, 134 + .gcm_2x = {0x00, 0x15, 0x00, 0x08, 0x00, 0x3F, 0x9C, 0xDF}, 135 + }, 136 + [PEF2256_GCM_CONFIG_2048000] = { 137 + .gcm_12 = {0x00, 0x58, 0xD2, 0xC2, 0x00, 0x10}, 138 + .gcm_2x = {0x00, 0x18, 0xFB, 0x0B, 0x00, 0x2F, 0xDB, 0xDF}, 139 + }, 140 + [PEF2256_GCM_CONFIG_8192000] = { 141 + .gcm_12 = {0x00, 0x58, 0xD2, 0xC2, 0x03, 0x10}, 142 + .gcm_2x = {0x00, 0x18, 0xFB, 0x0B, 0x00, 0x0B, 0xDB, 0xDF}, 143 + }, 144 + [PEF2256_GCM_CONFIG_10000000] = { 145 + .gcm_12 = {0x90, 0x51, 0x81, 0x8F, 0x04, 0x10}, 146 + .gcm_2x = {0x40, 0x1B, 0x3D, 0x0A, 0x00, 0x07, 0xC9, 0xDC}, 147 + }, 148 + [PEF2256_GCM_CONFIG_12352000] = { 149 + .gcm_12 = {0xF0, 0x51, 0x00, 0x80, 0x07, 0x15}, 150 + .gcm_2x = {0x00, 0x19, 0x00, 0x08, 0x01, 0x0A, 0x98, 0xDA}, 151 + }, 152 + [PEF2256_GCM_CONFIG_16384000] = { 153 + .gcm_12 = {0x00, 0x58, 0xD2, 0xC2, 0x07, 0x10}, 154 + .gcm_2x = {0x00, 0x18, 0xFB, 0x0B, 0x01, 0x0B, 0xDB, 0xDF}, 155 + }, 156 + }; 157 + 158 + static int pef2256_setup_gcm(struct pef2256 *pef2256) 159 + { 160 + enum pef2256_gcm_config_item item; 161 + unsigned long mclk_rate; 162 + const u8 *gcm; 163 + int i, count; 164 + 165 + mclk_rate = clk_get_rate(pef2256->mclk); 166 + switch (mclk_rate) { 167 + case 1544000: 168 + item = PEF2256_GCM_CONFIG_1544000; 169 + break; 170 + case 2048000: 171 + item = PEF2256_GCM_CONFIG_2048000; 172 + break; 173 + case 8192000: 174 + item = PEF2256_GCM_CONFIG_8192000; 175 + break; 176 + case 10000000: 177 + item = PEF2256_GCM_CONFIG_10000000; 178 + break; 179 + case 12352000: 180 + item = PEF2256_GCM_CONFIG_12352000; 181 + break; 182 + case 16384000: 183 + item = PEF2256_GCM_CONFIG_16384000; 184 + break; 185 + default: 186 + dev_err(pef2256->dev, "Unsupported v2.x MCLK rate %lu\n", mclk_rate); 187 + return -EINVAL; 188 + } 189 + 190 + BUILD_BUG_ON(item >= ARRAY_SIZE(pef2256_gcm_configs)); 191 + 192 + if (pef2256->version == PEF2256_VERSION_1_2) { 193 + gcm = pef2256_gcm_configs[item].gcm_12; 194 + count = ARRAY_SIZE(pef2256_gcm_configs[item].gcm_12); 195 + } else { 196 + gcm = pef2256_gcm_configs[item].gcm_2x; 197 + count = ARRAY_SIZE(pef2256_gcm_configs[item].gcm_2x); 198 + } 199 + 200 + for (i = 0; i < count; i++) 201 + pef2256_write8(pef2256, PEF2256_GCM(i + 1), *(gcm + i)); 202 + 203 + return 0; 204 + } 205 + 206 + static int pef2256_setup_e1_line(struct pef2256 *pef2256) 207 + { 208 + u8 fmr1, fmr2; 209 + 210 + /* RCLK output : DPLL clock, DCO-X enabled, DCO-X internal ref clock */ 211 + pef2256_write8(pef2256, PEF2256_CMR1, 0x00); 212 + 213 + /* SCLKR selected, SCLKX selected, 214 + * receive synchro pulse sourced by SYPR, 215 + * transmit synchro pulse sourced by SYPX, 216 + * DCO-X center frequency enabled 217 + */ 218 + pef2256_write8(pef2256, PEF2256_CMR2, PEF2256_CMR2_DCOXC); 219 + 220 + if (pef2256->is_subordinate) { 221 + /* select RCLK source = 2M, disable switching from RCLK to SYNC */ 222 + pef2256_clrsetbits8(pef2256, PEF2256_CMR1, PEF2256_CMR1_RS_MASK, 223 + PEF2256_CMR1_RS_DCOR_2048 | PEF2256_CMR1_DCS); 224 + } 225 + 226 + /* slave mode, local loop off, mode short-haul 227 + * In v2.x, bit3 is a forced 1 bit in the datasheet -> Need to be set. 228 + */ 229 + if (pef2256->version == PEF2256_VERSION_1_2) 230 + pef2256_write8(pef2256, PEF2256_LIM0, 0x00); 231 + else 232 + pef2256_write8(pef2256, PEF2256_LIM0, PEF2256_2X_LIM0_BIT3); 233 + 234 + /* "master" mode */ 235 + if (!pef2256->is_subordinate) 236 + pef2256_setbits8(pef2256, PEF2256_LIM0, PEF2256_LIM0_MAS); 237 + 238 + /* analog interface selected, remote loop off */ 239 + pef2256_write8(pef2256, PEF2256_LIM1, 0x00); 240 + 241 + /* receive input threshold = 0,21V */ 242 + if (pef2256->version == PEF2256_VERSION_1_2) 243 + pef2256_clrsetbits8(pef2256, PEF2256_LIM1, PEF2256_12_LIM1_RIL_MASK, 244 + PEF2256_12_LIM1_RIL_210); 245 + else 246 + pef2256_clrsetbits8(pef2256, PEF2256_LIM1, PEF2256_2X_LIM1_RIL_MASK, 247 + PEF2256_2X_LIM1_RIL_210); 248 + 249 + /* transmit pulse mask, default value from datasheet 250 + * transmit line in normal operation 251 + */ 252 + if (pef2256->version == PEF2256_VERSION_1_2) 253 + pef2256_write8(pef2256, PEF2256_XPM0, 0x7B); 254 + else 255 + pef2256_write8(pef2256, PEF2256_XPM0, 0x9C); 256 + pef2256_write8(pef2256, PEF2256_XPM1, 0x03); 257 + pef2256_write8(pef2256, PEF2256_XPM2, 0x00); 258 + 259 + /* HDB3 coding, no alarm simulation */ 260 + pef2256_write8(pef2256, PEF2256_FMR0, PEF2256_FMR0_XC_HDB3 | PEF2256_FMR0_RC_HDB3); 261 + 262 + /* E1, frame format, 2 Mbit/s system data rate, no AIS 263 + * transmission to remote end or system interface, payload loop 264 + * off, transmit remote alarm on 265 + */ 266 + fmr1 = 0x00; 267 + fmr2 = PEF2256_FMR2_AXRA; 268 + switch (pef2256->frame_type) { 269 + case PEF2256_FRAME_E1_DOUBLEFRAME: 270 + fmr2 |= PEF2256_FMR2_RFS_DOUBLEFRAME; 271 + break; 272 + case PEF2256_FRAME_E1_CRC4_MULTIFRAME: 273 + fmr1 |= PEF2256_FMR1_XFS; 274 + fmr2 |= PEF2256_FMR2_RFS_CRC4_MULTIFRAME; 275 + break; 276 + case PEF2256_FRAME_E1_AUTO_MULTIFRAME: 277 + fmr1 |= PEF2256_FMR1_XFS; 278 + fmr2 |= PEF2256_FMR2_RFS_AUTO_MULTIFRAME; 279 + break; 280 + default: 281 + dev_err(pef2256->dev, "Unsupported frame type %d\n", pef2256->frame_type); 282 + return -EINVAL; 283 + } 284 + pef2256_clrsetbits8(pef2256, PEF2256_FMR1, PEF2256_FMR1_XFS, fmr1); 285 + pef2256_write8(pef2256, PEF2256_FMR2, fmr2); 286 + 287 + if (!pef2256->is_subordinate) { 288 + /* SEC input, active high */ 289 + pef2256_write8(pef2256, PEF2256_GPC1, PEF2256_GPC1_CSFP_SEC_IN_HIGH); 290 + } else { 291 + /* FSC output, active high */ 292 + pef2256_write8(pef2256, PEF2256_GPC1, PEF2256_GPC1_CSFP_FSC_OUT_HIGH); 293 + } 294 + 295 + /* SCLKR, SCLKX, RCLK configured to inputs, 296 + * XFMS active low, CLK1 and CLK2 pin configuration 297 + */ 298 + pef2256_write8(pef2256, PEF2256_PC5, 0x00); 299 + pef2256_write8(pef2256, PEF2256_PC6, 0x00); 300 + 301 + /* port RCLK is output */ 302 + pef2256_setbits8(pef2256, PEF2256_PC5, PEF2256_PC5_CRP); 303 + 304 + return 0; 305 + } 306 + 307 + static void pef2256_setup_e1_los(struct pef2256 *pef2256) 308 + { 309 + /* detection of LOS alarm = 176 pulses (ie (10 + 1) * 16) */ 310 + pef2256_write8(pef2256, PEF2256_PCD, 10); 311 + /* recovery of LOS alarm = 22 pulses (ie 21 + 1) */ 312 + pef2256_write8(pef2256, PEF2256_PCR, 21); 313 + /* E1 default for the receive slicer threshold */ 314 + pef2256_write8(pef2256, PEF2256_LIM2, PEF2256_LIM2_SLT_THR50); 315 + if (pef2256->is_subordinate) { 316 + /* Loop-timed */ 317 + pef2256_setbits8(pef2256, PEF2256_LIM2, PEF2256_LIM2_ELT); 318 + } 319 + } 320 + 321 + static int pef2256_setup_e1_system(struct pef2256 *pef2256) 322 + { 323 + u8 sic1, fmr1; 324 + 325 + /* 2.048 MHz system clocking rate, receive buffer 2 frames, transmit 326 + * buffer bypass, data sampled and transmitted on the falling edge of 327 + * SCLKR/X, automatic freeze signaling, data is active in the first 328 + * channel phase 329 + */ 330 + pef2256_write8(pef2256, PEF2256_SIC1, 0x00); 331 + pef2256_write8(pef2256, PEF2256_SIC2, 0x00); 332 + pef2256_write8(pef2256, PEF2256_SIC3, 0x00); 333 + 334 + if (pef2256->is_subordinate) { 335 + /* transmit buffer size = 2 frames, transparent mode */ 336 + pef2256_clrsetbits8(pef2256, PEF2256_SIC1, PEF2256_SIC1_XBS_MASK, 337 + PEF2256_SIC1_XBS_2FRAMES); 338 + } 339 + 340 + if (pef2256->version != PEF2256_VERSION_1_2) { 341 + /* during inactive channel phase switch RDO/RSIG into tri-state */ 342 + pef2256_setbits8(pef2256, PEF2256_SIC3, PEF2256_SIC3_RTRI); 343 + } 344 + 345 + if (pef2256->is_tx_falling_edge) { 346 + /* falling edge sync pulse transmit, rising edge sync pulse receive */ 347 + pef2256_clrsetbits8(pef2256, PEF2256_SIC3, PEF2256_SIC3_RESX, PEF2256_SIC3_RESR); 348 + } else { 349 + /* rising edge sync pulse transmit, falling edge sync pulse receive */ 350 + pef2256_clrsetbits8(pef2256, PEF2256_SIC3, PEF2256_SIC3_RESR, PEF2256_SIC3_RESX); 351 + } 352 + 353 + /* transmit offset counter (XCO10..0) = 4 */ 354 + pef2256_write8(pef2256, PEF2256_XC0, 0); 355 + pef2256_write8(pef2256, PEF2256_XC1, 4); 356 + /* receive offset counter (RCO10..0) = 4 */ 357 + pef2256_write8(pef2256, PEF2256_RC0, 0); 358 + pef2256_write8(pef2256, PEF2256_RC1, 4); 359 + 360 + /* system clock rate */ 361 + switch (pef2256->sysclk_rate) { 362 + case 2048000: 363 + sic1 = PEF2256_SIC1_SSC_2048; 364 + break; 365 + case 4096000: 366 + sic1 = PEF2256_SIC1_SSC_4096; 367 + break; 368 + case 8192000: 369 + sic1 = PEF2256_SIC1_SSC_8192; 370 + break; 371 + case 16384000: 372 + sic1 = PEF2256_SIC1_SSC_16384; 373 + break; 374 + default: 375 + dev_err(pef2256->dev, "Unsupported sysclk rate %lu\n", pef2256->sysclk_rate); 376 + return -EINVAL; 377 + } 378 + pef2256_clrsetbits8(pef2256, PEF2256_SIC1, PEF2256_SIC1_SSC_MASK, sic1); 379 + 380 + /* data clock rate */ 381 + switch (pef2256->data_rate) { 382 + case 2048000: 383 + fmr1 = PEF2256_FMR1_SSD_2048; 384 + sic1 = PEF2256_SIC1_SSD_2048; 385 + break; 386 + case 4096000: 387 + fmr1 = PEF2256_FMR1_SSD_4096; 388 + sic1 = PEF2256_SIC1_SSD_4096; 389 + break; 390 + case 8192000: 391 + fmr1 = PEF2256_FMR1_SSD_8192; 392 + sic1 = PEF2256_SIC1_SSD_8192; 393 + break; 394 + case 16384000: 395 + fmr1 = PEF2256_FMR1_SSD_16384; 396 + sic1 = PEF2256_SIC1_SSD_16384; 397 + break; 398 + default: 399 + dev_err(pef2256->dev, "Unsupported data rate %u\n", pef2256->data_rate); 400 + return -EINVAL; 401 + } 402 + pef2256_clrsetbits8(pef2256, PEF2256_FMR1, PEF2256_FMR1_SSD_MASK, fmr1); 403 + pef2256_clrsetbits8(pef2256, PEF2256_SIC1, PEF2256_SIC1_SSD_MASK, sic1); 404 + 405 + /* channel phase */ 406 + pef2256_clrsetbits8(pef2256, PEF2256_SIC2, PEF2256_SIC2_SICS_MASK, 407 + PEF2256_SIC2_SICS(pef2256->channel_phase)); 408 + 409 + return 0; 410 + } 411 + 412 + static void pef2256_setup_e1_signaling(struct pef2256 *pef2256) 413 + { 414 + /* All bits of the transmitted service word are cleared */ 415 + pef2256_write8(pef2256, PEF2256_XSW, PEF2256_XSW_XY(0x1F)); 416 + 417 + /* CAS disabled and clear spare bit values */ 418 + pef2256_write8(pef2256, PEF2256_XSP, 0x00); 419 + 420 + if (pef2256->is_subordinate) { 421 + /* transparent mode */ 422 + pef2256_setbits8(pef2256, PEF2256_XSW, PEF2256_XSW_XTM); 423 + } 424 + 425 + /* Si-Bit, Spare bit For International, FAS word */ 426 + pef2256_setbits8(pef2256, PEF2256_XSW, PEF2256_XSW_XSIS); 427 + pef2256_setbits8(pef2256, PEF2256_XSP, PEF2256_XSP_XSIF); 428 + 429 + /* no transparent mode active */ 430 + pef2256_write8(pef2256, PEF2256_TSWM, 0x00); 431 + } 432 + 433 + static void pef2256_setup_e1_errors(struct pef2256 *pef2256) 434 + { 435 + /* error counter latched every 1s */ 436 + pef2256_setbits8(pef2256, PEF2256_FMR1, PEF2256_FMR1_ECM); 437 + 438 + /* error counter mode COFA */ 439 + pef2256_setbits8(pef2256, PEF2256_GCR, PEF2256_GCR_ECMC); 440 + 441 + /* errors in service words have no influence */ 442 + pef2256_setbits8(pef2256, PEF2256_RC0, PEF2256_RC0_SWD); 443 + 444 + /* 4 consecutive incorrect FAS causes loss of sync */ 445 + pef2256_setbits8(pef2256, PEF2256_RC0, PEF2256_RC0_ASY4); 446 + } 447 + 448 + static int pef2256_setup_e1(struct pef2256 *pef2256) 449 + { 450 + int ret; 451 + 452 + /* Setup, Master clocking mode (GCM8..1) */ 453 + ret = pef2256_setup_gcm(pef2256); 454 + if (ret) 455 + return ret; 456 + 457 + /* Select E1 mode */ 458 + pef2256_write8(pef2256, PEF2256_FMR1, 0x00); 459 + 460 + /* internal second timer, power on */ 461 + pef2256_write8(pef2256, PEF2256_GCR, 0x00); 462 + 463 + /* Setup line interface */ 464 + ret = pef2256_setup_e1_line(pef2256); 465 + if (ret) 466 + return ret; 467 + 468 + /* Setup Loss-of-signal detection and recovery */ 469 + pef2256_setup_e1_los(pef2256); 470 + 471 + /* Setup system interface */ 472 + ret = pef2256_setup_e1_system(pef2256); 473 + if (ret) 474 + return ret; 475 + 476 + /* Setup signaling */ 477 + pef2256_setup_e1_signaling(pef2256); 478 + 479 + /* Setup errors counters and condition */ 480 + pef2256_setup_e1_errors(pef2256); 481 + 482 + /* status changed interrupt at both up and down */ 483 + pef2256_setbits8(pef2256, PEF2256_GCR, PEF2256_GCR_SCI); 484 + 485 + /* Clear any ISR2 pending interrupts and unmask needed interrupts */ 486 + pef2256_read8(pef2256, PEF2256_ISR2); 487 + pef2256_clrbits8(pef2256, PEF2256_IMR2, PEF2256_INT2_LOS | PEF2256_INT2_AIS); 488 + 489 + /* reset lines */ 490 + pef2256_write8(pef2256, PEF2256_CMDR, PEF2256_CMDR_RRES | PEF2256_CMDR_XRES); 491 + return 0; 492 + } 493 + 494 + static void pef2256_isr_default_handler(struct pef2256 *pef2256, u8 nbr, u8 isr) 495 + { 496 + dev_warn_ratelimited(pef2256->dev, "ISR%u: 0x%02x not handled\n", nbr, isr); 497 + } 498 + 499 + static bool pef2256_is_carrier_on(struct pef2256 *pef2256) 500 + { 501 + u8 frs0; 502 + 503 + frs0 = pef2256_read8(pef2256, PEF2256_FRS0); 504 + return !(frs0 & (PEF2256_FRS0_LOS | PEF2256_FRS0_AIS)); 505 + } 506 + 507 + static void pef2256_isr2_handler(struct pef2256 *pef2256, u8 nbr, u8 isr) 508 + { 509 + bool carrier; 510 + 511 + if (isr & (PEF2256_INT2_LOS | PEF2256_INT2_AIS)) { 512 + carrier = pef2256_is_carrier_on(pef2256); 513 + if (atomic_xchg(&pef2256->carrier, carrier) != carrier) 514 + framer_notify_status_change(pef2256->framer); 515 + } 516 + } 517 + 518 + static irqreturn_t pef2256_irq_handler(int irq, void *priv) 519 + { 520 + static void (*pef2256_isr_handler[])(struct pef2256 *, u8, u8) = { 521 + [0] = pef2256_isr_default_handler, 522 + [1] = pef2256_isr_default_handler, 523 + [2] = pef2256_isr2_handler, 524 + [3] = pef2256_isr_default_handler, 525 + [4] = pef2256_isr_default_handler, 526 + [5] = pef2256_isr_default_handler 527 + }; 528 + struct pef2256 *pef2256 = (struct pef2256 *)priv; 529 + u8 gis; 530 + u8 isr; 531 + u8 n; 532 + 533 + gis = pef2256_read8(pef2256, PEF2256_GIS); 534 + 535 + for (n = 0; n < ARRAY_SIZE(pef2256_isr_handler); n++) { 536 + if (gis & PEF2256_GIS_ISR(n)) { 537 + isr = pef2256_read8(pef2256, PEF2256_ISR(n)); 538 + pef2256_isr_handler[n](pef2256, n, isr); 539 + } 540 + } 541 + 542 + return IRQ_HANDLED; 543 + } 544 + 545 + static int pef2256_check_rates(struct pef2256 *pef2256, unsigned long sysclk_rate, 546 + unsigned long data_rate) 547 + { 548 + unsigned long rate; 549 + 550 + switch (sysclk_rate) { 551 + case 2048000: 552 + case 4096000: 553 + case 8192000: 554 + case 16384000: 555 + break; 556 + default: 557 + dev_err(pef2256->dev, "Unsupported system clock rate %lu\n", sysclk_rate); 558 + return -EINVAL; 559 + } 560 + 561 + for (rate = data_rate; rate <= data_rate * 4; rate *= 2) { 562 + if (rate == sysclk_rate) 563 + return 0; 564 + } 565 + dev_err(pef2256->dev, "Unsupported data rate %lu with system clock rate %lu\n", 566 + data_rate, sysclk_rate); 567 + return -EINVAL; 568 + } 569 + 570 + static int pef2556_of_parse(struct pef2256 *pef2256, struct device_node *np) 571 + { 572 + int ret; 573 + 574 + pef2256->data_rate = 2048000; 575 + ret = of_property_read_u32(np, "lantiq,data-rate-bps", &pef2256->data_rate); 576 + if (ret && ret != -EINVAL) { 577 + dev_err(pef2256->dev, "%pOF: failed to read lantiq,data-rate-bps\n", np); 578 + return ret; 579 + } 580 + 581 + ret = pef2256_check_rates(pef2256, pef2256->sysclk_rate, pef2256->data_rate); 582 + if (ret) 583 + return ret; 584 + 585 + pef2256->is_tx_falling_edge = of_property_read_bool(np, "lantiq,clock-falling-edge"); 586 + 587 + pef2256->channel_phase = 0; 588 + ret = of_property_read_u8(np, "lantiq,channel-phase", &pef2256->channel_phase); 589 + if (ret && ret != -EINVAL) { 590 + dev_err(pef2256->dev, "%pOF: failed to read lantiq,channel-phase\n", 591 + np); 592 + return ret; 593 + } 594 + if (pef2256->channel_phase >= pef2256->sysclk_rate / pef2256->data_rate) { 595 + dev_err(pef2256->dev, "%pOF: Invalid lantiq,channel-phase %u\n", 596 + np, pef2256->channel_phase); 597 + return -EINVAL; 598 + } 599 + 600 + return 0; 601 + } 602 + 603 + static const struct regmap_config pef2256_regmap_config = { 604 + .reg_bits = 32, 605 + .val_bits = 8, 606 + .max_register = 0xff, 607 + }; 608 + 609 + static const struct mfd_cell pef2256_devs[] = { 610 + { .name = "lantiq-pef2256-pinctrl", }, 611 + }; 612 + 613 + static int pef2256_add_audio_devices(struct pef2256 *pef2256) 614 + { 615 + const char *compatible = "lantiq,pef2256-codec"; 616 + struct mfd_cell *audio_devs; 617 + struct device_node *np; 618 + unsigned int count = 0; 619 + unsigned int i; 620 + int ret; 621 + 622 + for_each_available_child_of_node(pef2256->dev->of_node, np) { 623 + if (of_device_is_compatible(np, compatible)) 624 + count++; 625 + } 626 + 627 + if (!count) 628 + return 0; 629 + 630 + audio_devs = kcalloc(count, sizeof(*audio_devs), GFP_KERNEL); 631 + if (!audio_devs) 632 + return -ENOMEM; 633 + 634 + for (i = 0; i < count; i++) { 635 + audio_devs[i].name = "framer-codec"; 636 + audio_devs[i].of_compatible = compatible; 637 + audio_devs[i].id = i; 638 + } 639 + 640 + ret = mfd_add_devices(pef2256->dev, 0, audio_devs, count, NULL, 0, NULL); 641 + kfree(audio_devs); 642 + return ret; 643 + } 644 + 645 + static int pef2256_framer_get_status(struct framer *framer, struct framer_status *status) 646 + { 647 + struct pef2256 *pef2256 = framer_get_drvdata(framer); 648 + 649 + status->link_is_on = !!atomic_read(&pef2256->carrier); 650 + return 0; 651 + } 652 + 653 + static int pef2256_framer_set_config(struct framer *framer, const struct framer_config *config) 654 + { 655 + struct pef2256 *pef2256 = framer_get_drvdata(framer); 656 + 657 + if (config->iface != FRAMER_IFACE_E1) { 658 + dev_err(pef2256->dev, "Only E1 line is currently supported\n"); 659 + return -EOPNOTSUPP; 660 + } 661 + 662 + switch (config->clock_type) { 663 + case FRAMER_CLOCK_EXT: 664 + pef2256->is_subordinate = true; 665 + break; 666 + case FRAMER_CLOCK_INT: 667 + pef2256->is_subordinate = false; 668 + break; 669 + default: 670 + return -EINVAL; 671 + } 672 + 673 + /* Apply the new settings */ 674 + return pef2256_setup_e1(pef2256); 675 + } 676 + 677 + static int pef2256_framer_get_config(struct framer *framer, struct framer_config *config) 678 + { 679 + struct pef2256 *pef2256 = framer_get_drvdata(framer); 680 + 681 + config->iface = FRAMER_IFACE_E1; 682 + config->clock_type = pef2256->is_subordinate ? FRAMER_CLOCK_EXT : FRAMER_CLOCK_INT; 683 + config->line_clock_rate = 2048000; 684 + return 0; 685 + } 686 + 687 + static const struct framer_ops pef2256_framer_ops = { 688 + .owner = THIS_MODULE, 689 + .get_status = pef2256_framer_get_status, 690 + .get_config = pef2256_framer_get_config, 691 + .set_config = pef2256_framer_set_config, 692 + }; 693 + 694 + static int pef2256_probe(struct platform_device *pdev) 695 + { 696 + struct device_node *np = pdev->dev.of_node; 697 + unsigned long sclkr_rate, sclkx_rate; 698 + struct framer_provider *framer_provider; 699 + struct pef2256 *pef2256; 700 + const char *version_txt; 701 + void __iomem *iomem; 702 + int ret; 703 + int irq; 704 + 705 + pef2256 = devm_kzalloc(&pdev->dev, sizeof(*pef2256), GFP_KERNEL); 706 + if (!pef2256) 707 + return -ENOMEM; 708 + 709 + pef2256->dev = &pdev->dev; 710 + atomic_set(&pef2256->carrier, 0); 711 + 712 + pef2256->is_subordinate = true; 713 + pef2256->frame_type = PEF2256_FRAME_E1_DOUBLEFRAME; 714 + 715 + iomem = devm_platform_ioremap_resource(pdev, 0); 716 + if (IS_ERR(iomem)) 717 + return PTR_ERR(iomem); 718 + 719 + pef2256->regmap = devm_regmap_init_mmio(&pdev->dev, iomem, 720 + &pef2256_regmap_config); 721 + if (IS_ERR(pef2256->regmap)) { 722 + dev_err(&pdev->dev, "Failed to initialise Regmap (%ld)\n", 723 + PTR_ERR(pef2256->regmap)); 724 + return PTR_ERR(pef2256->regmap); 725 + } 726 + 727 + pef2256->mclk = devm_clk_get_enabled(&pdev->dev, "mclk"); 728 + if (IS_ERR(pef2256->mclk)) 729 + return PTR_ERR(pef2256->mclk); 730 + 731 + pef2256->sclkr = devm_clk_get_enabled(&pdev->dev, "sclkr"); 732 + if (IS_ERR(pef2256->sclkr)) 733 + return PTR_ERR(pef2256->sclkr); 734 + 735 + pef2256->sclkx = devm_clk_get_enabled(&pdev->dev, "sclkx"); 736 + if (IS_ERR(pef2256->sclkx)) 737 + return PTR_ERR(pef2256->sclkx); 738 + 739 + /* Both SCLKR (receive) and SCLKX (transmit) must have the same rate, 740 + * stored as sysclk_rate. 741 + * The exact value will be checked at pef2256_check_rates() 742 + */ 743 + sclkr_rate = clk_get_rate(pef2256->sclkr); 744 + sclkx_rate = clk_get_rate(pef2256->sclkx); 745 + if (sclkr_rate != sclkx_rate) { 746 + dev_err(pef2256->dev, "clk rate mismatch. sclkr %lu Hz, sclkx %lu Hz\n", 747 + sclkr_rate, sclkx_rate); 748 + return -EINVAL; 749 + } 750 + pef2256->sysclk_rate = sclkr_rate; 751 + 752 + /* Reset the component. The MCLK clock must be active during reset */ 753 + pef2256->reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); 754 + if (IS_ERR(pef2256->reset_gpio)) 755 + return PTR_ERR(pef2256->reset_gpio); 756 + if (pef2256->reset_gpio) { 757 + gpiod_set_value_cansleep(pef2256->reset_gpio, 1); 758 + usleep_range(10, 20); 759 + gpiod_set_value_cansleep(pef2256->reset_gpio, 0); 760 + usleep_range(10, 20); 761 + } 762 + 763 + pef2256->version = pef2256_get_version(pef2256); 764 + switch (pef2256->version) { 765 + case PEF2256_VERSION_1_2: 766 + version_txt = "1.2"; 767 + break; 768 + case PEF2256_VERSION_2_1: 769 + version_txt = "2.1"; 770 + break; 771 + case PEF2256_VERSION_2_2: 772 + version_txt = "2.2"; 773 + break; 774 + default: 775 + return -ENODEV; 776 + } 777 + dev_info(pef2256->dev, "Version %s detected\n", version_txt); 778 + 779 + ret = pef2556_of_parse(pef2256, np); 780 + if (ret) 781 + return ret; 782 + 783 + /* Create the framer. It can be used on interrupts */ 784 + pef2256->framer = devm_framer_create(pef2256->dev, NULL, &pef2256_framer_ops); 785 + if (IS_ERR(pef2256->framer)) 786 + return PTR_ERR(pef2256->framer); 787 + 788 + framer_set_drvdata(pef2256->framer, pef2256); 789 + 790 + /* Disable interrupts */ 791 + pef2256_write8(pef2256, PEF2256_IMR0, 0xff); 792 + pef2256_write8(pef2256, PEF2256_IMR1, 0xff); 793 + pef2256_write8(pef2256, PEF2256_IMR2, 0xff); 794 + pef2256_write8(pef2256, PEF2256_IMR3, 0xff); 795 + pef2256_write8(pef2256, PEF2256_IMR4, 0xff); 796 + pef2256_write8(pef2256, PEF2256_IMR5, 0xff); 797 + 798 + /* Clear any pending interrupts */ 799 + pef2256_read8(pef2256, PEF2256_ISR0); 800 + pef2256_read8(pef2256, PEF2256_ISR1); 801 + pef2256_read8(pef2256, PEF2256_ISR2); 802 + pef2256_read8(pef2256, PEF2256_ISR3); 803 + pef2256_read8(pef2256, PEF2256_ISR4); 804 + pef2256_read8(pef2256, PEF2256_ISR5); 805 + 806 + irq = platform_get_irq(pdev, 0); 807 + if (irq < 0) 808 + return irq; 809 + ret = devm_request_irq(pef2256->dev, irq, pef2256_irq_handler, 0, "pef2256", pef2256); 810 + if (ret < 0) 811 + return ret; 812 + 813 + platform_set_drvdata(pdev, pef2256); 814 + 815 + ret = mfd_add_devices(pef2256->dev, 0, pef2256_devs, 816 + ARRAY_SIZE(pef2256_devs), NULL, 0, NULL); 817 + if (ret) { 818 + dev_err(pef2256->dev, "add devices failed (%d)\n", ret); 819 + return ret; 820 + } 821 + 822 + ret = pef2256_setup_e1(pef2256); 823 + if (ret) 824 + return ret; 825 + 826 + framer_provider = devm_framer_provider_of_register(pef2256->dev, 827 + framer_provider_simple_of_xlate); 828 + if (IS_ERR(framer_provider)) 829 + return PTR_ERR(framer_provider); 830 + 831 + /* Add audio devices */ 832 + ret = pef2256_add_audio_devices(pef2256); 833 + if (ret < 0) { 834 + dev_err(pef2256->dev, "add audio devices failed (%d)\n", ret); 835 + return ret; 836 + } 837 + 838 + return 0; 839 + } 840 + 841 + static int pef2256_remove(struct platform_device *pdev) 842 + { 843 + struct pef2256 *pef2256 = platform_get_drvdata(pdev); 844 + 845 + /* Disable interrupts */ 846 + pef2256_write8(pef2256, PEF2256_IMR0, 0xff); 847 + pef2256_write8(pef2256, PEF2256_IMR1, 0xff); 848 + pef2256_write8(pef2256, PEF2256_IMR2, 0xff); 849 + pef2256_write8(pef2256, PEF2256_IMR3, 0xff); 850 + pef2256_write8(pef2256, PEF2256_IMR4, 0xff); 851 + pef2256_write8(pef2256, PEF2256_IMR5, 0xff); 852 + 853 + return 0; 854 + } 855 + 856 + static const struct of_device_id pef2256_id_table[] = { 857 + { .compatible = "lantiq,pef2256" }, 858 + {} /* sentinel */ 859 + }; 860 + MODULE_DEVICE_TABLE(of, pef2256_id_table); 861 + 862 + static struct platform_driver pef2256_driver = { 863 + .driver = { 864 + .name = "lantiq-pef2256", 865 + .of_match_table = pef2256_id_table, 866 + }, 867 + .probe = pef2256_probe, 868 + .remove = pef2256_remove, 869 + }; 870 + module_platform_driver(pef2256_driver); 871 + 872 + struct regmap *pef2256_get_regmap(struct pef2256 *pef2256) 873 + { 874 + return pef2256->regmap; 875 + } 876 + EXPORT_SYMBOL_GPL(pef2256_get_regmap); 877 + 878 + MODULE_AUTHOR("Herve Codina <herve.codina@bootlin.com>"); 879 + MODULE_DESCRIPTION("PEF2256 driver"); 880 + MODULE_LICENSE("GPL");
+15
drivers/pinctrl/Kconfig
··· 366 366 open drain configuration for the Palmas series devices like 367 367 TPS65913, TPS80036 etc. 368 368 369 + config PINCTRL_PEF2256 370 + tristate "Lantiq PEF2256 (FALC56) pin controller driver" 371 + depends on OF && FRAMER_PEF2256 372 + select PINMUX 373 + select PINCONF 374 + select GENERIC_PINCONF 375 + help 376 + This option enables the pin controller support for the Lantiq PEF2256 377 + framer, also known as FALC56. 378 + 379 + If unsure, say N. 380 + 381 + To compile this driver as a module, choose M here: the 382 + module will be called pinctrl-pef2256. 383 + 369 384 config PINCTRL_PIC32 370 385 bool "Microchip PIC32 pin controller driver" 371 386 depends on OF
+1
drivers/pinctrl/Makefile
··· 39 39 obj-$(CONFIG_PINCTRL_MLXBF3) += pinctrl-mlxbf3.o 40 40 obj-$(CONFIG_PINCTRL_OCELOT) += pinctrl-ocelot.o 41 41 obj-$(CONFIG_PINCTRL_PALMAS) += pinctrl-palmas.o 42 + obj-$(CONFIG_PINCTRL_PEF2256) += pinctrl-pef2256.o 42 43 obj-$(CONFIG_PINCTRL_PIC32) += pinctrl-pic32.o 43 44 obj-$(CONFIG_PINCTRL_PISTACHIO) += pinctrl-pistachio.o 44 45 obj-$(CONFIG_PINCTRL_RK805) += pinctrl-rk805.o
+358
drivers/pinctrl/pinctrl-pef2256.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * PEF2256 also known as FALC56 driver 4 + * 5 + * Copyright 2023 CS GROUP France 6 + * 7 + * Author: Herve Codina <herve.codina@bootlin.com> 8 + */ 9 + 10 + #include <linux/bitfield.h> 11 + #include <linux/framer/pef2256.h> 12 + #include <linux/module.h> 13 + #include <linux/of.h> 14 + #include <linux/pinctrl/pinctrl.h> 15 + #include <linux/pinctrl/pinconf-generic.h> 16 + #include <linux/pinctrl/pinmux.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/regmap.h> 19 + #include <linux/slab.h> 20 + 21 + /* Port Configuration 1..4 */ 22 + #define PEF2256_PC1 0x80 23 + #define PEF2256_PC2 0x81 24 + #define PEF2256_PC3 0x82 25 + #define PEF2256_PC4 0x83 26 + #define PEF2256_12_PC_RPC_MASK GENMASK(6, 4) 27 + #define PEF2256_12_PC_RPC_SYPR FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x0) 28 + #define PEF2256_12_PC_RPC_RFM FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x1) 29 + #define PEF2256_12_PC_RPC_RFMB FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x2) 30 + #define PEF2256_12_PC_RPC_RSIGM FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x3) 31 + #define PEF2256_12_PC_RPC_RSIG FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x4) 32 + #define PEF2256_12_PC_RPC_DLR FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x5) 33 + #define PEF2256_12_PC_RPC_FREEZE FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x6) 34 + #define PEF2256_12_PC_RPC_RFSP FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x7) 35 + #define PEF2256_12_PC_XPC_MASK GENMASK(4, 0) 36 + #define PEF2256_12_PC_XPC_SYPX FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x0) 37 + #define PEF2256_12_PC_XPC_XFMS FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x1) 38 + #define PEF2256_12_PC_XPC_XSIG FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x2) 39 + #define PEF2256_12_PC_XPC_TCLK FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x3) 40 + #define PEF2256_12_PC_XPC_XMFB FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x4) 41 + #define PEF2256_12_PC_XPC_XSIGM FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x5) 42 + #define PEF2256_12_PC_XPC_DLX FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x6) 43 + #define PEF2256_12_PC_XPC_XCLK FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x7) 44 + #define PEF2256_12_PC_XPC_XLT FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x8) 45 + #define PEF2256_2X_PC_RPC_MASK GENMASK(7, 4) 46 + #define PEF2256_2X_PC_RPC_SYPR FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x0) 47 + #define PEF2256_2X_PC_RPC_RFM FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x1) 48 + #define PEF2256_2X_PC_RPC_RFMB FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x2) 49 + #define PEF2256_2X_PC_RPC_RSIGM FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x3) 50 + #define PEF2256_2X_PC_RPC_RSIG FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x4) 51 + #define PEF2256_2X_PC_RPC_DLR FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x5) 52 + #define PEF2256_2X_PC_RPC_FREEZE FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x6) 53 + #define PEF2256_2X_PC_RPC_RFSP FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x7) 54 + #define PEF2256_2X_PC_RPC_GPI FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x9) 55 + #define PEF2256_2X_PC_RPC_GPOH FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0xa) 56 + #define PEF2256_2X_PC_RPC_GPOL FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0xb) 57 + #define PEF2256_2X_PC_RPC_LOS FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0xc) 58 + #define PEF2256_2X_PC_XPC_MASK GENMASK(3, 0) 59 + #define PEF2256_2X_PC_XPC_SYPX FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x0) 60 + #define PEF2256_2X_PC_XPC_XFMS FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x1) 61 + #define PEF2256_2X_PC_XPC_XSIG FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x2) 62 + #define PEF2256_2X_PC_XPC_TCLK FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x3) 63 + #define PEF2256_2X_PC_XPC_XMFB FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x4) 64 + #define PEF2256_2X_PC_XPC_XSIGM FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x5) 65 + #define PEF2256_2X_PC_XPC_DLX FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x6) 66 + #define PEF2256_2X_PC_XPC_XCLK FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x7) 67 + #define PEF2256_2X_PC_XPC_XLT FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x8) 68 + #define PEF2256_2X_PC_XPC_GPI FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x9) 69 + #define PEF2256_2X_PC_XPC_GPOH FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0xa) 70 + #define PEF2256_2X_PC_XPC_GPOL FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0xb) 71 + 72 + struct pef2256_pinreg_desc { 73 + int offset; 74 + u8 mask; 75 + }; 76 + 77 + struct pef2256_function_desc { 78 + const char *name; 79 + const char * const*groups; 80 + unsigned int ngroups; 81 + u8 func_val; 82 + }; 83 + 84 + struct pef2256_pinctrl { 85 + struct device *dev; 86 + struct regmap *regmap; 87 + enum pef2256_version version; 88 + struct pinctrl_desc pctrl_desc; 89 + const struct pef2256_function_desc *functions; 90 + unsigned int nfunctions; 91 + }; 92 + 93 + static int pef2256_get_groups_count(struct pinctrl_dev *pctldev) 94 + { 95 + struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev); 96 + 97 + /* We map 1 group <-> 1 pin */ 98 + return pef2256->pctrl_desc.npins; 99 + } 100 + 101 + static const char *pef2256_get_group_name(struct pinctrl_dev *pctldev, 102 + unsigned int selector) 103 + { 104 + struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev); 105 + 106 + /* We map 1 group <-> 1 pin */ 107 + return pef2256->pctrl_desc.pins[selector].name; 108 + } 109 + 110 + static int pef2256_get_group_pins(struct pinctrl_dev *pctldev, unsigned int selector, 111 + const unsigned int **pins, 112 + unsigned int *num_pins) 113 + { 114 + struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev); 115 + 116 + /* We map 1 group <-> 1 pin */ 117 + *pins = &pef2256->pctrl_desc.pins[selector].number; 118 + *num_pins = 1; 119 + 120 + return 0; 121 + } 122 + 123 + static const struct pinctrl_ops pef2256_pctlops = { 124 + .get_groups_count = pef2256_get_groups_count, 125 + .get_group_name = pef2256_get_group_name, 126 + .get_group_pins = pef2256_get_group_pins, 127 + .dt_node_to_map = pinconf_generic_dt_node_to_map_pin, 128 + .dt_free_map = pinconf_generic_dt_free_map, 129 + }; 130 + 131 + static int pef2256_get_functions_count(struct pinctrl_dev *pctldev) 132 + { 133 + struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev); 134 + 135 + return pef2256->nfunctions; 136 + } 137 + 138 + static const char *pef2256_get_function_name(struct pinctrl_dev *pctldev, 139 + unsigned int selector) 140 + { 141 + struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev); 142 + 143 + return pef2256->functions[selector].name; 144 + } 145 + 146 + static int pef2256_get_function_groups(struct pinctrl_dev *pctldev, unsigned int selector, 147 + const char * const **groups, 148 + unsigned * const num_groups) 149 + { 150 + struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev); 151 + 152 + *groups = pef2256->functions[selector].groups; 153 + *num_groups = pef2256->functions[selector].ngroups; 154 + return 0; 155 + } 156 + 157 + static int pef2256_set_mux(struct pinctrl_dev *pctldev, unsigned int func_selector, 158 + unsigned int group_selector) 159 + { 160 + struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev); 161 + const struct pef2256_pinreg_desc *pinreg_desc; 162 + u8 func_val; 163 + 164 + /* We map 1 group <-> 1 pin */ 165 + pinreg_desc = pef2256->pctrl_desc.pins[group_selector].drv_data; 166 + func_val = pef2256->functions[func_selector].func_val; 167 + 168 + return regmap_update_bits(pef2256->regmap, pinreg_desc->offset, 169 + pinreg_desc->mask, func_val); 170 + } 171 + 172 + static const struct pinmux_ops pef2256_pmxops = { 173 + .get_functions_count = pef2256_get_functions_count, 174 + .get_function_name = pef2256_get_function_name, 175 + .get_function_groups = pef2256_get_function_groups, 176 + .set_mux = pef2256_set_mux, 177 + }; 178 + 179 + #define PEF2256_PINCTRL_PIN(_number, _name, _offset, _mask) { \ 180 + .number = _number, \ 181 + .name = _name, \ 182 + .drv_data = &(struct pef2256_pinreg_desc) { \ 183 + .offset = _offset, \ 184 + .mask = _mask, \ 185 + }, \ 186 + } 187 + 188 + static const struct pinctrl_pin_desc pef2256_v12_pins[] = { 189 + PEF2256_PINCTRL_PIN(0, "RPA", PEF2256_PC1, PEF2256_12_PC_RPC_MASK), 190 + PEF2256_PINCTRL_PIN(1, "RPB", PEF2256_PC2, PEF2256_12_PC_RPC_MASK), 191 + PEF2256_PINCTRL_PIN(2, "RPC", PEF2256_PC3, PEF2256_12_PC_RPC_MASK), 192 + PEF2256_PINCTRL_PIN(3, "RPD", PEF2256_PC4, PEF2256_12_PC_RPC_MASK), 193 + PEF2256_PINCTRL_PIN(4, "XPA", PEF2256_PC1, PEF2256_12_PC_XPC_MASK), 194 + PEF2256_PINCTRL_PIN(5, "XPB", PEF2256_PC2, PEF2256_12_PC_XPC_MASK), 195 + PEF2256_PINCTRL_PIN(6, "XPC", PEF2256_PC3, PEF2256_12_PC_XPC_MASK), 196 + PEF2256_PINCTRL_PIN(7, "XPD", PEF2256_PC4, PEF2256_12_PC_XPC_MASK), 197 + }; 198 + 199 + static const struct pinctrl_pin_desc pef2256_v2x_pins[] = { 200 + PEF2256_PINCTRL_PIN(0, "RPA", PEF2256_PC1, PEF2256_2X_PC_RPC_MASK), 201 + PEF2256_PINCTRL_PIN(1, "RPB", PEF2256_PC2, PEF2256_2X_PC_RPC_MASK), 202 + PEF2256_PINCTRL_PIN(2, "RPC", PEF2256_PC3, PEF2256_2X_PC_RPC_MASK), 203 + PEF2256_PINCTRL_PIN(3, "RPD", PEF2256_PC4, PEF2256_2X_PC_RPC_MASK), 204 + PEF2256_PINCTRL_PIN(4, "XPA", PEF2256_PC1, PEF2256_2X_PC_XPC_MASK), 205 + PEF2256_PINCTRL_PIN(5, "XPB", PEF2256_PC2, PEF2256_2X_PC_XPC_MASK), 206 + PEF2256_PINCTRL_PIN(6, "XPC", PEF2256_PC3, PEF2256_2X_PC_XPC_MASK), 207 + PEF2256_PINCTRL_PIN(7, "XPD", PEF2256_PC4, PEF2256_2X_PC_XPC_MASK), 208 + }; 209 + 210 + static const char *const pef2256_rp_groups[] = { "RPA", "RPB", "RPC", "RPD" }; 211 + static const char *const pef2256_xp_groups[] = { "XPA", "XPB", "XPC", "XPD" }; 212 + static const char *const pef2256_all_groups[] = { "RPA", "RPB", "RPC", "RPD", 213 + "XPA", "XPB", "XPC", "XPD" }; 214 + 215 + #define PEF2256_FUNCTION(_name, _func_val, _groups) { \ 216 + .name = _name, \ 217 + .groups = _groups, \ 218 + .ngroups = ARRAY_SIZE(_groups), \ 219 + .func_val = _func_val, \ 220 + } 221 + 222 + static const struct pef2256_function_desc pef2256_v2x_functions[] = { 223 + PEF2256_FUNCTION("SYPR", PEF2256_2X_PC_RPC_SYPR, pef2256_rp_groups), 224 + PEF2256_FUNCTION("RFM", PEF2256_2X_PC_RPC_RFM, pef2256_rp_groups), 225 + PEF2256_FUNCTION("RFMB", PEF2256_2X_PC_RPC_RFMB, pef2256_rp_groups), 226 + PEF2256_FUNCTION("RSIGM", PEF2256_2X_PC_RPC_RSIGM, pef2256_rp_groups), 227 + PEF2256_FUNCTION("RSIG", PEF2256_2X_PC_RPC_RSIG, pef2256_rp_groups), 228 + PEF2256_FUNCTION("DLR", PEF2256_2X_PC_RPC_DLR, pef2256_rp_groups), 229 + PEF2256_FUNCTION("FREEZE", PEF2256_2X_PC_RPC_FREEZE, pef2256_rp_groups), 230 + PEF2256_FUNCTION("RFSP", PEF2256_2X_PC_RPC_RFSP, pef2256_rp_groups), 231 + PEF2256_FUNCTION("LOS", PEF2256_2X_PC_RPC_LOS, pef2256_rp_groups), 232 + 233 + PEF2256_FUNCTION("SYPX", PEF2256_2X_PC_XPC_SYPX, pef2256_xp_groups), 234 + PEF2256_FUNCTION("XFMS", PEF2256_2X_PC_XPC_XFMS, pef2256_xp_groups), 235 + PEF2256_FUNCTION("XSIG", PEF2256_2X_PC_XPC_XSIG, pef2256_xp_groups), 236 + PEF2256_FUNCTION("TCLK", PEF2256_2X_PC_XPC_TCLK, pef2256_xp_groups), 237 + PEF2256_FUNCTION("XMFB", PEF2256_2X_PC_XPC_XMFB, pef2256_xp_groups), 238 + PEF2256_FUNCTION("XSIGM", PEF2256_2X_PC_XPC_XSIGM, pef2256_xp_groups), 239 + PEF2256_FUNCTION("DLX", PEF2256_2X_PC_XPC_DLX, pef2256_xp_groups), 240 + PEF2256_FUNCTION("XCLK", PEF2256_2X_PC_XPC_XCLK, pef2256_xp_groups), 241 + PEF2256_FUNCTION("XLT", PEF2256_2X_PC_XPC_XLT, pef2256_xp_groups), 242 + 243 + PEF2256_FUNCTION("GPI", PEF2256_2X_PC_RPC_GPI | PEF2256_2X_PC_XPC_GPI, 244 + pef2256_all_groups), 245 + PEF2256_FUNCTION("GPOH", PEF2256_2X_PC_RPC_GPOH | PEF2256_2X_PC_XPC_GPOH, 246 + pef2256_all_groups), 247 + PEF2256_FUNCTION("GPOL", PEF2256_2X_PC_RPC_GPOL | PEF2256_2X_PC_XPC_GPOL, 248 + pef2256_all_groups), 249 + }; 250 + 251 + static const struct pef2256_function_desc pef2256_v12_functions[] = { 252 + PEF2256_FUNCTION("SYPR", PEF2256_12_PC_RPC_SYPR, pef2256_rp_groups), 253 + PEF2256_FUNCTION("RFM", PEF2256_12_PC_RPC_RFM, pef2256_rp_groups), 254 + PEF2256_FUNCTION("RFMB", PEF2256_12_PC_RPC_RFMB, pef2256_rp_groups), 255 + PEF2256_FUNCTION("RSIGM", PEF2256_12_PC_RPC_RSIGM, pef2256_rp_groups), 256 + PEF2256_FUNCTION("RSIG", PEF2256_12_PC_RPC_RSIG, pef2256_rp_groups), 257 + PEF2256_FUNCTION("DLR", PEF2256_12_PC_RPC_DLR, pef2256_rp_groups), 258 + PEF2256_FUNCTION("FREEZE", PEF2256_12_PC_RPC_FREEZE, pef2256_rp_groups), 259 + PEF2256_FUNCTION("RFSP", PEF2256_12_PC_RPC_RFSP, pef2256_rp_groups), 260 + 261 + PEF2256_FUNCTION("SYPX", PEF2256_12_PC_XPC_SYPX, pef2256_xp_groups), 262 + PEF2256_FUNCTION("XFMS", PEF2256_12_PC_XPC_XFMS, pef2256_xp_groups), 263 + PEF2256_FUNCTION("XSIG", PEF2256_12_PC_XPC_XSIG, pef2256_xp_groups), 264 + PEF2256_FUNCTION("TCLK", PEF2256_12_PC_XPC_TCLK, pef2256_xp_groups), 265 + PEF2256_FUNCTION("XMFB", PEF2256_12_PC_XPC_XMFB, pef2256_xp_groups), 266 + PEF2256_FUNCTION("XSIGM", PEF2256_12_PC_XPC_XSIGM, pef2256_xp_groups), 267 + PEF2256_FUNCTION("DLX", PEF2256_12_PC_XPC_DLX, pef2256_xp_groups), 268 + PEF2256_FUNCTION("XCLK", PEF2256_12_PC_XPC_XCLK, pef2256_xp_groups), 269 + PEF2256_FUNCTION("XLT", PEF2256_12_PC_XPC_XLT, pef2256_xp_groups), 270 + }; 271 + 272 + static int pef2256_register_pinctrl(struct pef2256_pinctrl *pef2256) 273 + { 274 + struct pinctrl_dev *pctrl; 275 + 276 + pef2256->pctrl_desc.name = dev_name(pef2256->dev); 277 + pef2256->pctrl_desc.owner = THIS_MODULE; 278 + pef2256->pctrl_desc.pctlops = &pef2256_pctlops; 279 + pef2256->pctrl_desc.pmxops = &pef2256_pmxops; 280 + if (pef2256->version == PEF2256_VERSION_1_2) { 281 + pef2256->pctrl_desc.pins = pef2256_v12_pins; 282 + pef2256->pctrl_desc.npins = ARRAY_SIZE(pef2256_v12_pins); 283 + pef2256->functions = pef2256_v12_functions; 284 + pef2256->nfunctions = ARRAY_SIZE(pef2256_v12_functions); 285 + } else { 286 + pef2256->pctrl_desc.pins = pef2256_v2x_pins; 287 + pef2256->pctrl_desc.npins = ARRAY_SIZE(pef2256_v2x_pins); 288 + pef2256->functions = pef2256_v2x_functions; 289 + pef2256->nfunctions = ARRAY_SIZE(pef2256_v2x_functions); 290 + } 291 + 292 + pctrl = devm_pinctrl_register(pef2256->dev, &pef2256->pctrl_desc, pef2256); 293 + if (IS_ERR(pctrl)) 294 + return dev_err_probe(pef2256->dev, PTR_ERR(pctrl), 295 + "pinctrl driver registration failed\n"); 296 + 297 + return 0; 298 + } 299 + 300 + static void pef2256_reset_pinmux(struct pef2256_pinctrl *pef2256) 301 + { 302 + u8 val; 303 + /* 304 + * Reset values cannot be used. 305 + * They define the SYPR/SYPX pin mux for all the RPx and XPx pins and 306 + * Only one pin can be muxed to SYPR and one pin can be muxed to SYPX. 307 + * Choose here an other reset value. 308 + */ 309 + if (pef2256->version == PEF2256_VERSION_1_2) 310 + val = PEF2256_12_PC_XPC_XCLK | PEF2256_12_PC_RPC_RFSP; 311 + else 312 + val = PEF2256_2X_PC_XPC_GPI | PEF2256_2X_PC_RPC_GPI; 313 + 314 + regmap_write(pef2256->regmap, PEF2256_PC1, val); 315 + regmap_write(pef2256->regmap, PEF2256_PC2, val); 316 + regmap_write(pef2256->regmap, PEF2256_PC3, val); 317 + regmap_write(pef2256->regmap, PEF2256_PC4, val); 318 + } 319 + 320 + static int pef2256_pinctrl_probe(struct platform_device *pdev) 321 + { 322 + struct pef2256_pinctrl *pef2256_pinctrl; 323 + struct pef2256 *pef2256; 324 + int ret; 325 + 326 + pef2256_pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pef2256_pinctrl), GFP_KERNEL); 327 + if (!pef2256_pinctrl) 328 + return -ENOMEM; 329 + 330 + device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent)); 331 + 332 + pef2256 = dev_get_drvdata(pdev->dev.parent); 333 + 334 + pef2256_pinctrl->dev = &pdev->dev; 335 + pef2256_pinctrl->regmap = pef2256_get_regmap(pef2256); 336 + pef2256_pinctrl->version = pef2256_get_version(pef2256); 337 + 338 + platform_set_drvdata(pdev, pef2256_pinctrl); 339 + 340 + pef2256_reset_pinmux(pef2256_pinctrl); 341 + ret = pef2256_register_pinctrl(pef2256_pinctrl); 342 + if (ret) 343 + return ret; 344 + 345 + return 0; 346 + } 347 + 348 + static struct platform_driver pef2256_pinctrl_driver = { 349 + .driver = { 350 + .name = "lantiq-pef2256-pinctrl", 351 + }, 352 + .probe = pef2256_pinctrl_probe, 353 + }; 354 + module_platform_driver(pef2256_pinctrl_driver); 355 + 356 + MODULE_AUTHOR("Herve Codina <herve.codina@bootlin.com>"); 357 + MODULE_DESCRIPTION("PEF2256 pin controller driver"); 358 + MODULE_LICENSE("GPL");
+194
include/linux/framer/framer-provider.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * Generic framer profider header file 4 + * 5 + * Copyright 2023 CS GROUP France 6 + * 7 + * Author: Herve Codina <herve.codina@bootlin.com> 8 + */ 9 + 10 + #ifndef __DRIVERS_PROVIDER_FRAMER_H 11 + #define __DRIVERS_PROVIDER_FRAMER_H 12 + 13 + #include <linux/export.h> 14 + #include <linux/framer/framer.h> 15 + #include <linux/types.h> 16 + 17 + #define FRAMER_FLAG_POLL_STATUS BIT(0) 18 + 19 + /** 20 + * struct framer_ops - set of function pointers for performing framer operations 21 + * @init: operation to be performed for initializing the framer 22 + * @exit: operation to be performed while exiting 23 + * @power_on: powering on the framer 24 + * @power_off: powering off the framer 25 + * @flags: OR-ed flags (FRAMER_FLAG_*) to ask for core functionality 26 + * - @FRAMER_FLAG_POLL_STATUS: 27 + * Ask the core to perform a polling to get the framer status and 28 + * notify consumers on change. 29 + * The framer should call @framer_notify_status_change() when it 30 + * detects a status change. This is usually done using interrupts. 31 + * If the framer cannot detect this change, it can ask the core for 32 + * a status polling. The core will call @get_status() periodically 33 + * and, on change detected, it will notify the consumer. 34 + * the @get_status() 35 + * @owner: the module owner containing the ops 36 + */ 37 + struct framer_ops { 38 + int (*init)(struct framer *framer); 39 + void (*exit)(struct framer *framer); 40 + int (*power_on)(struct framer *framer); 41 + int (*power_off)(struct framer *framer); 42 + 43 + /** 44 + * @get_status: 45 + * 46 + * Optional. 47 + * 48 + * Used to get the framer status. framer_init() must have 49 + * been called on the framer. 50 + * 51 + * Returns: 0 if successful, an negative error code otherwise 52 + */ 53 + int (*get_status)(struct framer *framer, struct framer_status *status); 54 + 55 + /** 56 + * @set_config: 57 + * 58 + * Optional. 59 + * 60 + * Used to set the framer configuration. framer_init() must have 61 + * been called on the framer. 62 + * 63 + * Returns: 0 if successful, an negative error code otherwise 64 + */ 65 + int (*set_config)(struct framer *framer, const struct framer_config *config); 66 + 67 + /** 68 + * @get_config: 69 + * 70 + * Optional. 71 + * 72 + * Used to get the framer configuration. framer_init() must have 73 + * been called on the framer. 74 + * 75 + * Returns: 0 if successful, an negative error code otherwise 76 + */ 77 + int (*get_config)(struct framer *framer, struct framer_config *config); 78 + 79 + u32 flags; 80 + struct module *owner; 81 + }; 82 + 83 + /** 84 + * struct framer_provider - represents the framer provider 85 + * @dev: framer provider device 86 + * @children: can be used to override the default (dev->of_node) child node 87 + * @owner: the module owner having of_xlate 88 + * @list: to maintain a linked list of framer providers 89 + * @of_xlate: function pointer to obtain framer instance from framer pointer 90 + */ 91 + struct framer_provider { 92 + struct device *dev; 93 + struct module *owner; 94 + struct list_head list; 95 + struct framer * (*of_xlate)(struct device *dev, 96 + struct of_phandle_args *args); 97 + }; 98 + 99 + static inline void framer_set_drvdata(struct framer *framer, void *data) 100 + { 101 + dev_set_drvdata(&framer->dev, data); 102 + } 103 + 104 + static inline void *framer_get_drvdata(struct framer *framer) 105 + { 106 + return dev_get_drvdata(&framer->dev); 107 + } 108 + 109 + #if IS_ENABLED(CONFIG_GENERIC_FRAMER) 110 + 111 + /* Create and destroy a framer */ 112 + struct framer *framer_create(struct device *dev, struct device_node *node, 113 + const struct framer_ops *ops); 114 + void framer_destroy(struct framer *framer); 115 + 116 + /* devm version */ 117 + struct framer *devm_framer_create(struct device *dev, struct device_node *node, 118 + const struct framer_ops *ops); 119 + 120 + struct framer *framer_provider_simple_of_xlate(struct device *dev, 121 + struct of_phandle_args *args); 122 + 123 + struct framer_provider * 124 + __framer_provider_of_register(struct device *dev, struct module *owner, 125 + struct framer *(*of_xlate)(struct device *dev, 126 + struct of_phandle_args *args)); 127 + 128 + void framer_provider_of_unregister(struct framer_provider *framer_provider); 129 + 130 + struct framer_provider * 131 + __devm_framer_provider_of_register(struct device *dev, struct module *owner, 132 + struct framer *(*of_xlate)(struct device *dev, 133 + struct of_phandle_args *args)); 134 + 135 + void framer_notify_status_change(struct framer *framer); 136 + 137 + #else /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */ 138 + 139 + static inline struct framer *framer_create(struct device *dev, struct device_node *node, 140 + const struct framer_ops *ops) 141 + { 142 + return ERR_PTR(-ENOSYS); 143 + } 144 + 145 + static inline void framer_destroy(struct framer *framer) 146 + { 147 + } 148 + 149 + /* devm version */ 150 + static inline struct framer *devm_framer_create(struct device *dev, struct device_node *node, 151 + const struct framer_ops *ops) 152 + { 153 + return ERR_PTR(-ENOSYS); 154 + } 155 + 156 + static inline struct framer *framer_provider_simple_of_xlate(struct device *dev, 157 + struct of_phandle_args *args) 158 + { 159 + return ERR_PTR(-ENOSYS); 160 + } 161 + 162 + static inline struct framer_provider * 163 + __framer_provider_of_register(struct device *dev, struct module *owner, 164 + struct framer *(*of_xlate)(struct device *dev, 165 + struct of_phandle_args *args)) 166 + { 167 + return ERR_PTR(-ENOSYS); 168 + } 169 + 170 + void framer_provider_of_unregister(struct framer_provider *framer_provider) 171 + { 172 + } 173 + 174 + static inline struct framer_provider * 175 + __devm_framer_provider_of_register(struct device *dev, struct module *owner, 176 + struct framer *(*of_xlate)(struct device *dev, 177 + struct of_phandle_args *args)) 178 + { 179 + return ERR_PTR(-ENOSYS); 180 + } 181 + 182 + void framer_notify_status_change(struct framer *framer) 183 + { 184 + } 185 + 186 + #endif /* IS_ENABLED(CONFIG_GENERIC_FRAMER) */ 187 + 188 + #define framer_provider_of_register(dev, xlate) \ 189 + __framer_provider_of_register((dev), THIS_MODULE, (xlate)) 190 + 191 + #define devm_framer_provider_of_register(dev, xlate) \ 192 + __devm_framer_provider_of_register((dev), THIS_MODULE, (xlate)) 193 + 194 + #endif /* __DRIVERS_PROVIDER_FRAMER_H */
+205
include/linux/framer/framer.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * Generic framer header file 4 + * 5 + * Copyright 2023 CS GROUP France 6 + * 7 + * Author: Herve Codina <herve.codina@bootlin.com> 8 + */ 9 + 10 + #ifndef __DRIVERS_FRAMER_H 11 + #define __DRIVERS_FRAMER_H 12 + 13 + #include <linux/err.h> 14 + #include <linux/mutex.h> 15 + #include <linux/notifier.h> 16 + #include <linux/of.h> 17 + #include <linux/device.h> 18 + #include <linux/workqueue.h> 19 + 20 + /** 21 + * enum framer_iface - Framer interface 22 + * @FRAMER_IFACE_E1: E1 interface 23 + * @FRAMER_IFACE_T1: T1 interface 24 + */ 25 + enum framer_iface { 26 + FRAMER_IFACE_E1, 27 + FRAMER_IFACE_T1, 28 + }; 29 + 30 + /** 31 + * enum framer_clock_type - Framer clock type 32 + * @FRAMER_CLOCK_EXT: External clock 33 + * @FRAMER_CLOCK_INT: Internal clock 34 + */ 35 + enum framer_clock_type { 36 + FRAMER_CLOCK_EXT, 37 + FRAMER_CLOCK_INT, 38 + }; 39 + 40 + /** 41 + * struct framer_config - Framer configuration 42 + * @iface: Framer line interface 43 + * @clock_type: Framer clock type 44 + * @line_clock_rate: Framer line clock rate 45 + */ 46 + struct framer_config { 47 + enum framer_iface iface; 48 + enum framer_clock_type clock_type; 49 + unsigned long line_clock_rate; 50 + }; 51 + 52 + /** 53 + * struct framer_status - Framer status 54 + * @link_is_on: Framer link state. true, the link is on, false, the link is off. 55 + */ 56 + struct framer_status { 57 + bool link_is_on; 58 + }; 59 + 60 + /** 61 + * enum framer_event - Event available for notification 62 + * @FRAMER_EVENT_STATUS: Event notified on framer_status changes 63 + */ 64 + enum framer_event { 65 + FRAMER_EVENT_STATUS, 66 + }; 67 + 68 + /** 69 + * struct framer - represents the framer device 70 + * @dev: framer device 71 + * @id: id of the framer device 72 + * @ops: function pointers for performing framer operations 73 + * @mutex: mutex to protect framer_ops 74 + * @init_count: used to protect when the framer is used by multiple consumers 75 + * @power_count: used to protect when the framer is used by multiple consumers 76 + * @pwr: power regulator associated with the framer 77 + * @notify_status_work: work structure used for status notifications 78 + * @notifier_list: notifier list used for notifications 79 + * @polling_work: delayed work structure used for the polling task 80 + * @prev_status: previous read status used by the polling task to detect changes 81 + */ 82 + struct framer { 83 + struct device dev; 84 + int id; 85 + const struct framer_ops *ops; 86 + struct mutex mutex; /* Protect framer */ 87 + int init_count; 88 + int power_count; 89 + struct regulator *pwr; 90 + struct work_struct notify_status_work; 91 + struct blocking_notifier_head notifier_list; 92 + struct delayed_work polling_work; 93 + struct framer_status prev_status; 94 + }; 95 + 96 + #if IS_ENABLED(CONFIG_GENERIC_FRAMER) 97 + int framer_pm_runtime_get(struct framer *framer); 98 + int framer_pm_runtime_get_sync(struct framer *framer); 99 + int framer_pm_runtime_put(struct framer *framer); 100 + int framer_pm_runtime_put_sync(struct framer *framer); 101 + int framer_init(struct framer *framer); 102 + int framer_exit(struct framer *framer); 103 + int framer_power_on(struct framer *framer); 104 + int framer_power_off(struct framer *framer); 105 + int framer_get_status(struct framer *framer, struct framer_status *status); 106 + int framer_get_config(struct framer *framer, struct framer_config *config); 107 + int framer_set_config(struct framer *framer, const struct framer_config *config); 108 + int framer_notifier_register(struct framer *framer, struct notifier_block *nb); 109 + int framer_notifier_unregister(struct framer *framer, struct notifier_block *nb); 110 + 111 + struct framer *framer_get(struct device *dev, const char *con_id); 112 + void framer_put(struct device *dev, struct framer *framer); 113 + 114 + struct framer *devm_framer_get(struct device *dev, const char *con_id); 115 + struct framer *devm_framer_optional_get(struct device *dev, const char *con_id); 116 + #else 117 + static inline int framer_pm_runtime_get(struct framer *framer) 118 + { 119 + return -ENOSYS; 120 + } 121 + 122 + static inline int framer_pm_runtime_get_sync(struct framer *framer) 123 + { 124 + return -ENOSYS; 125 + } 126 + 127 + static inline int framer_pm_runtime_put(struct framer *framer) 128 + { 129 + return -ENOSYS; 130 + } 131 + 132 + static inline int framer_pm_runtime_put_sync(struct framer *framer) 133 + { 134 + return -ENOSYS; 135 + } 136 + 137 + static inline int framer_init(struct framer *framer) 138 + { 139 + return -ENOSYS; 140 + } 141 + 142 + static inline int framer_exit(struct framer *framer) 143 + { 144 + return -ENOSYS; 145 + } 146 + 147 + static inline int framer_power_on(struct framer *framer) 148 + { 149 + return -ENOSYS; 150 + } 151 + 152 + static inline int framer_power_off(struct framer *framer) 153 + { 154 + return -ENOSYS; 155 + } 156 + 157 + static inline int framer_get_status(struct framer *framer, struct framer_status *status) 158 + { 159 + return -ENOSYS; 160 + } 161 + 162 + static inline int framer_get_config(struct framer *framer, struct framer_config *config) 163 + { 164 + return -ENOSYS; 165 + } 166 + 167 + static inline int framer_set_config(struct framer *framer, const struct framer_config *config) 168 + { 169 + return -ENOSYS; 170 + } 171 + 172 + static inline int framer_notifier_register(struct framer *framer, 173 + struct notifier_block *nb) 174 + { 175 + return -ENOSYS; 176 + } 177 + 178 + static inline int framer_notifier_unregister(struct framer *framer, 179 + struct notifier_block *nb) 180 + { 181 + return -ENOSYS; 182 + } 183 + 184 + struct framer *framer_get(struct device *dev, const char *con_id) 185 + { 186 + return ERR_PTR(-ENOSYS); 187 + } 188 + 189 + void framer_put(struct device *dev, struct framer *framer) 190 + { 191 + } 192 + 193 + static inline struct framer *devm_framer_get(struct device *dev, const char *con_id) 194 + { 195 + return ERR_PTR(-ENOSYS); 196 + } 197 + 198 + static inline struct framer *devm_framer_optional_get(struct device *dev, const char *con_id) 199 + { 200 + return NULL; 201 + } 202 + 203 + #endif 204 + 205 + #endif /* __DRIVERS_FRAMER_H */
+31
include/linux/framer/pef2256.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* 3 + * PEF2256 consumer API 4 + * 5 + * Copyright 2023 CS GROUP France 6 + * 7 + * Author: Herve Codina <herve.codina@bootlin.com> 8 + */ 9 + #ifndef __PEF2256_H__ 10 + #define __PEF2256_H__ 11 + 12 + #include <linux/types.h> 13 + 14 + struct pef2256; 15 + struct regmap; 16 + 17 + /* Retrieve the PEF2256 regmap */ 18 + struct regmap *pef2256_get_regmap(struct pef2256 *pef2256); 19 + 20 + /* PEF2256 hardware versions */ 21 + enum pef2256_version { 22 + PEF2256_VERSION_UNKNOWN, 23 + PEF2256_VERSION_1_2, 24 + PEF2256_VERSION_2_1, 25 + PEF2256_VERSION_2_2, 26 + }; 27 + 28 + /* Get the PEF2256 hardware version */ 29 + enum pef2256_version pef2256_get_version(struct pef2256 *pef2256); 30 + 31 + #endif /* __PEF2256_H__ */