Lines Matching +full:rclk +full:-

1 // SPDX-License-Identifier: GPL-2.0
12 #include <linux/framer/framer-provider.h>
24 #include "pef2256-regs.h"
58 regmap_read(pef2256->regmap, offset, &val); in pef2256_read8()
64 regmap_write(pef2256->regmap, offset, val); in pef2256_write8()
69 regmap_clear_bits(pef2256->regmap, offset, clr); in pef2256_clrbits8()
74 regmap_set_bits(pef2256->regmap, offset, set); in pef2256_setbits8()
79 regmap_update_bits(pef2256->regmap, offset, clr | set, set); in pef2256_clrsetbits8()
111 dev_err(pef2256->dev, "Unknown version (0x%02x, 0x%02x)\n", vstr, wid); in pef2256_get_version()
165 mclk_rate = clk_get_rate(pef2256->mclk); in pef2256_setup_gcm()
186 dev_err(pef2256->dev, "Unsupported v2.x MCLK rate %lu\n", mclk_rate); in pef2256_setup_gcm()
187 return -EINVAL; in pef2256_setup_gcm()
192 if (pef2256->version == PEF2256_VERSION_1_2) { in pef2256_setup_gcm()
210 /* RCLK output : DPLL clock, DCO-X enabled, DCO-X internal ref clock */ in pef2256_setup_e1_line()
216 * DCO-X center frequency enabled in pef2256_setup_e1_line()
220 if (pef2256->is_subordinate) { in pef2256_setup_e1_line()
221 /* select RCLK source = 2M, disable switching from RCLK to SYNC */ in pef2256_setup_e1_line()
226 /* slave mode, local loop off, mode short-haul in pef2256_setup_e1_line()
227 * In v2.x, bit3 is a forced 1 bit in the datasheet -> Need to be set. in pef2256_setup_e1_line()
229 if (pef2256->version == PEF2256_VERSION_1_2) in pef2256_setup_e1_line()
235 if (!pef2256->is_subordinate) in pef2256_setup_e1_line()
242 if (pef2256->version == PEF2256_VERSION_1_2) in pef2256_setup_e1_line()
252 if (pef2256->version == PEF2256_VERSION_1_2) in pef2256_setup_e1_line()
268 switch (pef2256->frame_type) { in pef2256_setup_e1_line()
281 dev_err(pef2256->dev, "Unsupported frame type %d\n", pef2256->frame_type); in pef2256_setup_e1_line()
282 return -EINVAL; in pef2256_setup_e1_line()
287 if (!pef2256->is_subordinate) { in pef2256_setup_e1_line()
295 /* SCLKR, SCLKX, RCLK configured to inputs, in pef2256_setup_e1_line()
301 /* port RCLK is output */ in pef2256_setup_e1_line()
315 if (pef2256->is_subordinate) { in pef2256_setup_e1_los()
316 /* Loop-timed */ in pef2256_setup_e1_los()
334 if (pef2256->is_subordinate) { in pef2256_setup_e1_system()
340 if (pef2256->version != PEF2256_VERSION_1_2) { in pef2256_setup_e1_system()
341 /* during inactive channel phase switch RDO/RSIG into tri-state */ in pef2256_setup_e1_system()
345 if (pef2256->is_tx_falling_edge) { in pef2256_setup_e1_system()
361 switch (pef2256->sysclk_rate) { in pef2256_setup_e1_system()
375 dev_err(pef2256->dev, "Unsupported sysclk rate %lu\n", pef2256->sysclk_rate); in pef2256_setup_e1_system()
376 return -EINVAL; in pef2256_setup_e1_system()
381 switch (pef2256->data_rate) { in pef2256_setup_e1_system()
399 dev_err(pef2256->dev, "Unsupported data rate %u\n", pef2256->data_rate); in pef2256_setup_e1_system()
400 return -EINVAL; in pef2256_setup_e1_system()
407 PEF2256_SIC2_SICS(pef2256->channel_phase)); in pef2256_setup_e1_system()
420 if (pef2256->is_subordinate) { in pef2256_setup_e1_signaling()
425 /* Si-Bit, Spare bit For International, FAS word */ in pef2256_setup_e1_signaling()
468 /* Setup Loss-of-signal detection and recovery */ in pef2256_setup_e1()
496 dev_warn_ratelimited(pef2256->dev, "ISR%u: 0x%02x not handled\n", nbr, isr); in pef2256_isr_default_handler()
513 if (atomic_xchg(&pef2256->carrier, carrier) != carrier) in pef2256_isr2_handler()
514 framer_notify_status_change(pef2256->framer); in pef2256_isr2_handler()
557 dev_err(pef2256->dev, "Unsupported system clock rate %lu\n", sysclk_rate); in pef2256_check_rates()
558 return -EINVAL; in pef2256_check_rates()
565 dev_err(pef2256->dev, "Unsupported data rate %lu with system clock rate %lu\n", in pef2256_check_rates()
567 return -EINVAL; in pef2256_check_rates()
574 pef2256->data_rate = 2048000; in pef2556_of_parse()
575 ret = of_property_read_u32(np, "lantiq,data-rate-bps", &pef2256->data_rate); in pef2556_of_parse()
576 if (ret && ret != -EINVAL) { in pef2556_of_parse()
577 dev_err(pef2256->dev, "%pOF: failed to read lantiq,data-rate-bps\n", np); in pef2556_of_parse()
581 ret = pef2256_check_rates(pef2256, pef2256->sysclk_rate, pef2256->data_rate); in pef2556_of_parse()
585 pef2256->is_tx_falling_edge = of_property_read_bool(np, "lantiq,clock-falling-edge"); in pef2556_of_parse()
587 pef2256->channel_phase = 0; in pef2556_of_parse()
588 ret = of_property_read_u8(np, "lantiq,channel-phase", &pef2256->channel_phase); in pef2556_of_parse()
589 if (ret && ret != -EINVAL) { in pef2556_of_parse()
590 dev_err(pef2256->dev, "%pOF: failed to read lantiq,channel-phase\n", in pef2556_of_parse()
594 if (pef2256->channel_phase >= pef2256->sysclk_rate / pef2256->data_rate) { in pef2556_of_parse()
595 dev_err(pef2256->dev, "%pOF: Invalid lantiq,channel-phase %u\n", in pef2556_of_parse()
596 np, pef2256->channel_phase); in pef2556_of_parse()
597 return -EINVAL; in pef2556_of_parse()
610 { .name = "lantiq-pef2256-pinctrl", },
615 const char *compatible = "lantiq,pef2256-codec"; in pef2256_add_audio_devices()
622 for_each_available_child_of_node(pef2256->dev->of_node, np) { in pef2256_add_audio_devices()
632 return -ENOMEM; in pef2256_add_audio_devices()
635 audio_devs[i].name = "framer-codec"; in pef2256_add_audio_devices()
640 ret = mfd_add_devices(pef2256->dev, 0, audio_devs, count, NULL, 0, NULL); in pef2256_add_audio_devices()
649 status->link_is_on = !!atomic_read(&pef2256->carrier); in pef2256_framer_get_status()
657 if (config->iface != FRAMER_IFACE_E1) { in pef2256_framer_set_config()
658 dev_err(pef2256->dev, "Only E1 line is currently supported\n"); in pef2256_framer_set_config()
659 return -EOPNOTSUPP; in pef2256_framer_set_config()
662 switch (config->clock_type) { in pef2256_framer_set_config()
664 pef2256->is_subordinate = true; in pef2256_framer_set_config()
667 pef2256->is_subordinate = false; in pef2256_framer_set_config()
670 return -EINVAL; in pef2256_framer_set_config()
681 config->iface = FRAMER_IFACE_E1; in pef2256_framer_get_config()
682 config->clock_type = pef2256->is_subordinate ? FRAMER_CLOCK_EXT : FRAMER_CLOCK_INT; in pef2256_framer_get_config()
683 config->line_clock_rate = 2048000; in pef2256_framer_get_config()
696 struct device_node *np = pdev->dev.of_node; in pef2256_probe()
705 pef2256 = devm_kzalloc(&pdev->dev, sizeof(*pef2256), GFP_KERNEL); in pef2256_probe()
707 return -ENOMEM; in pef2256_probe()
709 pef2256->dev = &pdev->dev; in pef2256_probe()
710 atomic_set(&pef2256->carrier, 0); in pef2256_probe()
712 pef2256->is_subordinate = true; in pef2256_probe()
713 pef2256->frame_type = PEF2256_FRAME_E1_DOUBLEFRAME; in pef2256_probe()
719 pef2256->regmap = devm_regmap_init_mmio(&pdev->dev, iomem, in pef2256_probe()
721 if (IS_ERR(pef2256->regmap)) { in pef2256_probe()
722 dev_err(&pdev->dev, "Failed to initialise Regmap (%ld)\n", in pef2256_probe()
723 PTR_ERR(pef2256->regmap)); in pef2256_probe()
724 return PTR_ERR(pef2256->regmap); in pef2256_probe()
727 pef2256->mclk = devm_clk_get_enabled(&pdev->dev, "mclk"); in pef2256_probe()
728 if (IS_ERR(pef2256->mclk)) in pef2256_probe()
729 return PTR_ERR(pef2256->mclk); in pef2256_probe()
731 pef2256->sclkr = devm_clk_get_enabled(&pdev->dev, "sclkr"); in pef2256_probe()
732 if (IS_ERR(pef2256->sclkr)) in pef2256_probe()
733 return PTR_ERR(pef2256->sclkr); in pef2256_probe()
735 pef2256->sclkx = devm_clk_get_enabled(&pdev->dev, "sclkx"); in pef2256_probe()
736 if (IS_ERR(pef2256->sclkx)) in pef2256_probe()
737 return PTR_ERR(pef2256->sclkx); in pef2256_probe()
743 sclkr_rate = clk_get_rate(pef2256->sclkr); in pef2256_probe()
744 sclkx_rate = clk_get_rate(pef2256->sclkx); in pef2256_probe()
746 dev_err(pef2256->dev, "clk rate mismatch. sclkr %lu Hz, sclkx %lu Hz\n", in pef2256_probe()
748 return -EINVAL; in pef2256_probe()
750 pef2256->sysclk_rate = sclkr_rate; in pef2256_probe()
753 pef2256->reset_gpio = devm_gpiod_get_optional(&pdev->dev, "reset", GPIOD_OUT_LOW); in pef2256_probe()
754 if (IS_ERR(pef2256->reset_gpio)) in pef2256_probe()
755 return PTR_ERR(pef2256->reset_gpio); in pef2256_probe()
756 if (pef2256->reset_gpio) { in pef2256_probe()
757 gpiod_set_value_cansleep(pef2256->reset_gpio, 1); in pef2256_probe()
759 gpiod_set_value_cansleep(pef2256->reset_gpio, 0); in pef2256_probe()
763 pef2256->version = pef2256_get_version(pef2256); in pef2256_probe()
764 switch (pef2256->version) { in pef2256_probe()
775 return -ENODEV; in pef2256_probe()
777 dev_info(pef2256->dev, "Version %s detected\n", version_txt); in pef2256_probe()
784 pef2256->framer = devm_framer_create(pef2256->dev, NULL, &pef2256_framer_ops); in pef2256_probe()
785 if (IS_ERR(pef2256->framer)) in pef2256_probe()
786 return PTR_ERR(pef2256->framer); in pef2256_probe()
788 framer_set_drvdata(pef2256->framer, pef2256); in pef2256_probe()
809 ret = devm_request_irq(pef2256->dev, irq, pef2256_irq_handler, 0, "pef2256", pef2256); in pef2256_probe()
815 ret = mfd_add_devices(pef2256->dev, 0, pef2256_devs, in pef2256_probe()
818 dev_err(pef2256->dev, "add devices failed (%d)\n", ret); in pef2256_probe()
826 framer_provider = devm_framer_provider_of_register(pef2256->dev, in pef2256_probe()
834 dev_err(pef2256->dev, "add audio devices failed (%d)\n", ret); in pef2256_probe()
862 .name = "lantiq-pef2256",
872 return pef2256->regmap; in pef2256_get_regmap()