Lines Matching +full:rx +full:- +full:watermark
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
10 #include <linux/dma-mapping.h>
17 #include <linux/soc/qcom/geni-se.h>
31 * GENI based QUP is a highly-flexible and programmable module for supporting
41 * +-----------------------------------------+
43 * | +----------------------------+ |
44 * --QUP & SE Clocks--> | Serial Engine N | +-IO------>
46 * <---Clock Perf.----+ +----+-----------------------+ | |
50 * <--------AHB-------> | | | |
51 * | | +----+ |
54 * <------SE IRQ------+ +----------------------------+ |
56 * +-----------------------------------------+
61 * used to drive TX & RX operations. On serial interfaces that operate using
62 * master-slave model, primary sequencer drives both TX & RX operations. On
63 * serial interfaces that operate using peer-to-peer model, primary sequencer
64 * drives TX operation and secondary sequencer drives RX operation.
87 * struct geni_wrapper - Data structure to represent the QUP Wrapper Core
102 * struct geni_se_desc - Data structure to represent the QUP Wrapper resources
111 static const char * const icc_path_names[] = {"qup-core", "qup-config",
112 "qup-memory"};
191 * geni_se_get_qup_hw_version() - Read the QUP wrapper Hardware version
198 struct geni_wrapper *wrapper = se->wrapper; in geni_se_get_qup_hw_version()
200 return readl_relaxed(wrapper->base + QUP_HW_VER_REG); in geni_se_get_qup_hw_version()
239 writel_relaxed(0, se->base + SE_GSI_EVENT_EN); in geni_se_irq_clear()
240 writel_relaxed(0xffffffff, se->base + SE_GENI_M_IRQ_CLEAR); in geni_se_irq_clear()
241 writel_relaxed(0xffffffff, se->base + SE_GENI_S_IRQ_CLEAR); in geni_se_irq_clear()
242 writel_relaxed(0xffffffff, se->base + SE_DMA_TX_IRQ_CLR); in geni_se_irq_clear()
243 writel_relaxed(0xffffffff, se->base + SE_DMA_RX_IRQ_CLR); in geni_se_irq_clear()
244 writel_relaxed(0xffffffff, se->base + SE_IRQ_EN); in geni_se_irq_clear()
248 * geni_se_init() - Initialize the GENI serial engine
250 * @rx_wm: Receive watermark, in units of FIFO words.
251 * @rx_rfr: Ready-for-receive watermark, in units of FIFO words.
254 * receive watermark and ready-for-receive watermarks.
261 geni_se_io_init(se->base); in geni_se_init()
262 geni_se_io_set_mode(se->base); in geni_se_init()
264 writel_relaxed(rx_wm, se->base + SE_GENI_RX_WATERMARK_REG); in geni_se_init()
265 writel_relaxed(rx_rfr, se->base + SE_GENI_RX_RFR_WATERMARK_REG); in geni_se_init()
267 val = readl_relaxed(se->base + SE_GENI_M_IRQ_EN); in geni_se_init()
269 writel_relaxed(val, se->base + SE_GENI_M_IRQ_EN); in geni_se_init()
271 val = readl_relaxed(se->base + SE_GENI_S_IRQ_EN); in geni_se_init()
273 writel_relaxed(val, se->base + SE_GENI_S_IRQ_EN); in geni_se_init()
286 /* Non-UART use only primary sequencer so dont bother about S_IRQ */ in geni_se_select_fifo_mode()
287 val_old = val = readl_relaxed(se->base + SE_GENI_M_IRQ_EN); in geni_se_select_fifo_mode()
291 writel_relaxed(val, se->base + SE_GENI_M_IRQ_EN); in geni_se_select_fifo_mode()
294 val_old = val = readl_relaxed(se->base + SE_GENI_DMA_MODE_EN); in geni_se_select_fifo_mode()
297 writel_relaxed(val, se->base + SE_GENI_DMA_MODE_EN); in geni_se_select_fifo_mode()
309 /* Non-UART use only primary sequencer so dont bother about S_IRQ */ in geni_se_select_dma_mode()
310 val_old = val = readl_relaxed(se->base + SE_GENI_M_IRQ_EN); in geni_se_select_dma_mode()
314 writel_relaxed(val, se->base + SE_GENI_M_IRQ_EN); in geni_se_select_dma_mode()
317 val_old = val = readl_relaxed(se->base + SE_GENI_DMA_MODE_EN); in geni_se_select_dma_mode()
320 writel_relaxed(val, se->base + SE_GENI_DMA_MODE_EN); in geni_se_select_dma_mode()
329 writel(0, se->base + SE_IRQ_EN); in geni_se_select_gpi_mode()
331 val = readl(se->base + SE_GENI_M_IRQ_EN); in geni_se_select_gpi_mode()
334 writel(val, se->base + SE_GENI_M_IRQ_EN); in geni_se_select_gpi_mode()
336 writel(GENI_DMA_MODE_EN, se->base + SE_GENI_DMA_MODE_EN); in geni_se_select_gpi_mode()
338 val = readl(se->base + SE_GSI_EVENT_EN); in geni_se_select_gpi_mode()
340 writel(val, se->base + SE_GSI_EVENT_EN); in geni_se_select_gpi_mode()
344 * geni_se_select_mode() - Select the serial engine transfer mode
372 * GENI FIFO packing is highly configurable. TX/RX packing/unpacking consist
375 * TX FIFO and in GENI_RX_PACKING_CFG0 and GENI_RX_PACKING_CFG1 for RX FIFO.
376 * Refer to below examples for detailed bit-field description.
380 * +-----------+-------+-------+-------+-------+
382 * +-----------+-------+-------+-------+-------+
387 * +-----------+-------+-------+-------+-------+
391 * +-----------+-------+-------+-------+-------+
393 * +-----------+-------+-------+-------+-------+
398 * +-----------+-------+-------+-------+-------+
402 * +-----------+-------+-------+-------+-------+
404 * +-----------+-------+-------+-------+-------+
409 * +-----------+-------+-------+-------+-------+
420 * geni_se_config_packing() - Packing configuration of the serial engine
424 * @msb_to_lsb: Transfer from MSB to LSB or vice-versa.
426 * @rx_cfg: Flag to configure the RX Packing.
437 int idx_start = msb_to_lsb ? bpw - 1 : 0; in geni_se_config_packing()
439 int idx_delta = msb_to_lsb ? -BITS_PER_BYTE : BITS_PER_BYTE; in geni_se_config_packing()
448 len = min_t(int, temp_bpw, BITS_PER_BYTE) - 1; in geni_se_config_packing()
458 temp_bpw = temp_bpw - BITS_PER_BYTE; in geni_se_config_packing()
461 cfg[iter - 1] |= PACKING_STOP_BIT; in geni_se_config_packing()
466 writel_relaxed(cfg0, se->base + SE_GENI_TX_PACKING_CFG0); in geni_se_config_packing()
467 writel_relaxed(cfg1, se->base + SE_GENI_TX_PACKING_CFG1); in geni_se_config_packing()
470 writel_relaxed(cfg0, se->base + SE_GENI_RX_PACKING_CFG0); in geni_se_config_packing()
471 writel_relaxed(cfg1, se->base + SE_GENI_RX_PACKING_CFG1); in geni_se_config_packing()
476 * 0 - 4x8, four words in each entry, max word size of 8 bits in geni_se_config_packing()
477 * 1 - 2x16, two words in each entry, max word size of 16 bits in geni_se_config_packing()
478 * 2 - 1x32, one word in each entry, max word size of 32 bits in geni_se_config_packing()
479 * 3 - undefined in geni_se_config_packing()
482 writel_relaxed(bpw / 16, se->base + SE_GENI_BYTE_GRAN); in geni_se_config_packing()
488 struct geni_wrapper *wrapper = se->wrapper; in geni_se_clks_off()
490 clk_disable_unprepare(se->clk); in geni_se_clks_off()
491 clk_bulk_disable_unprepare(wrapper->num_clks, wrapper->clks); in geni_se_clks_off()
495 * geni_se_resources_off() - Turn off resources associated with the serial
505 if (has_acpi_companion(se->dev)) in geni_se_resources_off()
508 ret = pinctrl_pm_select_sleep_state(se->dev); in geni_se_resources_off()
520 struct geni_wrapper *wrapper = se->wrapper; in geni_se_clks_on()
522 ret = clk_bulk_prepare_enable(wrapper->num_clks, wrapper->clks); in geni_se_clks_on()
526 ret = clk_prepare_enable(se->clk); in geni_se_clks_on()
528 clk_bulk_disable_unprepare(wrapper->num_clks, wrapper->clks); in geni_se_clks_on()
533 * geni_se_resources_on() - Turn on resources associated with the serial
543 if (has_acpi_companion(se->dev)) in geni_se_resources_on()
550 ret = pinctrl_pm_select_default_state(se->dev); in geni_se_resources_on()
559 * geni_se_clk_tbl_get() - Get the clock table to program DFS
576 if (se->clk_perf_tbl) { in geni_se_clk_tbl_get()
577 *tbl = se->clk_perf_tbl; in geni_se_clk_tbl_get()
578 return se->num_clk_levels; in geni_se_clk_tbl_get()
581 se->clk_perf_tbl = devm_kcalloc(se->dev, MAX_CLK_PERF_LEVEL, in geni_se_clk_tbl_get()
582 sizeof(*se->clk_perf_tbl), in geni_se_clk_tbl_get()
584 if (!se->clk_perf_tbl) in geni_se_clk_tbl_get()
585 return -ENOMEM; in geni_se_clk_tbl_get()
588 freq = clk_round_rate(se->clk, freq + 1); in geni_se_clk_tbl_get()
590 (i > 0 && freq == se->clk_perf_tbl[i - 1])) in geni_se_clk_tbl_get()
592 se->clk_perf_tbl[i] = freq; in geni_se_clk_tbl_get()
594 se->num_clk_levels = i; in geni_se_clk_tbl_get()
595 *tbl = se->clk_perf_tbl; in geni_se_clk_tbl_get()
596 return se->num_clk_levels; in geni_se_clk_tbl_get()
601 * geni_se_clk_freq_match() - Get the matching or closest SE clock frequency
614 * - if @exact is true then @res_freq / <an_integer> == @req_freq
615 * - if @exact is false then @res_freq / <an_integer> <= @req_freq
635 return -EINVAL; in geni_se_clk_freq_match()
640 new_delta = req_freq - tbl[i] / divider; in geni_se_clk_freq_match()
656 return -EINVAL; in geni_se_clk_freq_match()
668 * geni_se_tx_init_dma() - Initiate TX DMA transfer on the serial engine
682 writel_relaxed(val, se->base + SE_DMA_TX_IRQ_EN_SET); in geni_se_tx_init_dma()
683 writel_relaxed(lower_32_bits(iova), se->base + SE_DMA_TX_PTR_L); in geni_se_tx_init_dma()
684 writel_relaxed(upper_32_bits(iova), se->base + SE_DMA_TX_PTR_H); in geni_se_tx_init_dma()
685 writel_relaxed(GENI_SE_DMA_EOT_BUF, se->base + SE_DMA_TX_ATTR); in geni_se_tx_init_dma()
686 writel(len, se->base + SE_DMA_TX_LEN); in geni_se_tx_init_dma()
691 * geni_se_tx_dma_prep() - Prepare the serial engine for TX DMA transfer
704 struct geni_wrapper *wrapper = se->wrapper; in geni_se_tx_dma_prep()
707 return -EINVAL; in geni_se_tx_dma_prep()
709 *iova = dma_map_single(wrapper->dev, buf, len, DMA_TO_DEVICE); in geni_se_tx_dma_prep()
710 if (dma_mapping_error(wrapper->dev, *iova)) in geni_se_tx_dma_prep()
711 return -EIO; in geni_se_tx_dma_prep()
719 * geni_se_rx_init_dma() - Initiate RX DMA transfer on the serial engine
722 * @len: Length of the RX buffer.
724 * This function is used to initiate DMA RX transfer.
733 writel_relaxed(val, se->base + SE_DMA_RX_IRQ_EN_SET); in geni_se_rx_init_dma()
734 writel_relaxed(lower_32_bits(iova), se->base + SE_DMA_RX_PTR_L); in geni_se_rx_init_dma()
735 writel_relaxed(upper_32_bits(iova), se->base + SE_DMA_RX_PTR_H); in geni_se_rx_init_dma()
736 /* RX does not have EOT buffer type bit. So just reset RX_ATTR */ in geni_se_rx_init_dma()
737 writel_relaxed(0, se->base + SE_DMA_RX_ATTR); in geni_se_rx_init_dma()
738 writel(len, se->base + SE_DMA_RX_LEN); in geni_se_rx_init_dma()
743 * geni_se_rx_dma_prep() - Prepare the serial engine for RX DMA transfer
745 * @buf: Pointer to the RX buffer.
746 * @len: Length of the RX buffer.
749 * This function is used to prepare the buffers for DMA RX.
756 struct geni_wrapper *wrapper = se->wrapper; in geni_se_rx_dma_prep()
759 return -EINVAL; in geni_se_rx_dma_prep()
761 *iova = dma_map_single(wrapper->dev, buf, len, DMA_FROM_DEVICE); in geni_se_rx_dma_prep()
762 if (dma_mapping_error(wrapper->dev, *iova)) in geni_se_rx_dma_prep()
763 return -EIO; in geni_se_rx_dma_prep()
771 * geni_se_tx_dma_unprep() - Unprepare the serial engine after TX DMA transfer
780 struct geni_wrapper *wrapper = se->wrapper; in geni_se_tx_dma_unprep()
782 if (!dma_mapping_error(wrapper->dev, iova)) in geni_se_tx_dma_unprep()
783 dma_unmap_single(wrapper->dev, iova, len, DMA_TO_DEVICE); in geni_se_tx_dma_unprep()
788 * geni_se_rx_dma_unprep() - Unprepare the serial engine after RX DMA transfer
790 * @iova: DMA address of the RX buffer.
791 * @len: Length of the RX buffer.
793 * This function is used to unprepare the DMA buffers after DMA RX.
797 struct geni_wrapper *wrapper = se->wrapper; in geni_se_rx_dma_unprep()
799 if (!dma_mapping_error(wrapper->dev, iova)) in geni_se_rx_dma_unprep()
800 dma_unmap_single(wrapper->dev, iova, len, DMA_FROM_DEVICE); in geni_se_rx_dma_unprep()
807 const char *icc_names[] = {"qup-core", "qup-config", icc_ddr}; in geni_icc_get()
809 if (has_acpi_companion(se->dev)) in geni_icc_get()
812 for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) { in geni_icc_get()
816 se->icc_paths[i].path = devm_of_icc_get(se->dev, icc_names[i]); in geni_icc_get()
817 if (IS_ERR(se->icc_paths[i].path)) in geni_icc_get()
824 err = PTR_ERR(se->icc_paths[i].path); in geni_icc_get()
825 if (err != -EPROBE_DEFER) in geni_icc_get()
826 dev_err_ratelimited(se->dev, "Failed to get ICC path '%s': %d\n", in geni_icc_get()
837 for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) { in geni_icc_set_bw()
838 ret = icc_set_bw(se->icc_paths[i].path, in geni_icc_set_bw()
839 se->icc_paths[i].avg_bw, se->icc_paths[i].avg_bw); in geni_icc_set_bw()
841 dev_err_ratelimited(se->dev, "ICC BW voting failed on path '%s': %d\n", in geni_icc_set_bw()
855 for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) in geni_icc_set_tag()
856 icc_set_tag(se->icc_paths[i].path, tag); in geni_icc_set_tag()
865 for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) { in geni_icc_enable()
866 ret = icc_enable(se->icc_paths[i].path); in geni_icc_enable()
868 dev_err_ratelimited(se->dev, "ICC enable failed on path '%s': %d\n", in geni_icc_enable()
882 for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) { in geni_icc_disable()
883 ret = icc_disable(se->icc_paths[i].path); in geni_icc_disable()
885 dev_err_ratelimited(se->dev, "ICC disable failed on path '%s': %d\n", in geni_icc_disable()
897 struct device *dev = &pdev->dev; in geni_se_probe()
903 return -ENOMEM; in geni_se_probe()
905 wrapper->dev = dev; in geni_se_probe()
906 wrapper->base = devm_platform_ioremap_resource(pdev, 0); in geni_se_probe()
907 if (IS_ERR(wrapper->base)) in geni_se_probe()
908 return PTR_ERR(wrapper->base); in geni_se_probe()
910 if (!has_acpi_companion(&pdev->dev)) { in geni_se_probe()
914 desc = device_get_match_data(&pdev->dev); in geni_se_probe()
916 return -EINVAL; in geni_se_probe()
918 wrapper->num_clks = min_t(unsigned int, desc->num_clks, MAX_CLKS); in geni_se_probe()
920 for (i = 0; i < wrapper->num_clks; ++i) in geni_se_probe()
921 wrapper->clks[i].id = desc->clks[i]; in geni_se_probe()
923 ret = of_count_phandle_with_args(dev->of_node, "clocks", "#clock-cells"); in geni_se_probe()
925 dev_err(dev, "invalid clocks property at %pOF\n", dev->of_node); in geni_se_probe()
929 if (ret < wrapper->num_clks) { in geni_se_probe()
931 dev->of_node, wrapper->num_clks); in geni_se_probe()
932 return -EINVAL; in geni_se_probe()
935 ret = devm_clk_bulk_get(dev, wrapper->num_clks, wrapper->clks); in geni_se_probe()
948 "m-ahb",
949 "s-ahb",
958 "s-ahb",
967 { .compatible = "qcom,geni-se-qup", .data = &qup_desc },
968 { .compatible = "qcom,geni-se-i2c-master-hub", .data = &i2c_master_hub_desc },