Lines Matching +full:geni +full:- +full:se +full:- +full:qup

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>
22 * Generic Interface (GENI) Serial Engine (SE) Wrapper driver is introduced
23 * to manage GENI firmware based Qualcomm Universal Peripheral (QUP) Wrapper
24 * controller. QUP Wrapper is designed to support various serial bus protocols
31 * GENI based QUP is a highly-flexible and programmable module for supporting
33 * QUP module can provide upto 8 serial interfaces, using its internal
36 * determined by the firmware loaded to the serial engine. Each SE consists
37 * of a DMA Engine and GENI sub modules which enable serial engines to
41 * +-----------------------------------------+
42 * |QUP Wrapper |
43 * | +----------------------------+ |
44 * --QUP & SE Clocks--> | Serial Engine N | +-IO------>
46 * <---Clock Perf.----+ +----+-----------------------+ | |
50 * <--------AHB-------> | | | |
51 * | | +----+ |
54 * <------SE IRQ------+ +----------------------------+ |
56 * +-----------------------------------------+
58 * Figure 1: GENI based QUP Wrapper
60 * The GENI submodules include primary and secondary sequencers which are
62 * master-slave model, primary sequencer drives both TX & RX operations. On
63 * serial interfaces that operate using peer-to-peer model, primary sequencer
70 * GENI SE Wrapper driver is structured into 2 parts:
72 * geni_wrapper represents QUP Wrapper controller. This part of the driver
73 * manages QUP Wrapper information such as hardware version, clock
77 * engine information such as clocks, containing QUP Wrapper, etc. This part
87 * struct geni_wrapper - Data structure to represent the QUP Wrapper Core
88 * @dev: Device pointer of the QUP wrapper core
89 * @base: Base address of this instance of 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"};
116 /* Common SE registers */
191 * geni_se_get_qup_hw_version() - Read the QUP wrapper Hardware version
192 * @se: Pointer to the corresponding serial engine.
196 u32 geni_se_get_qup_hw_version(struct geni_se *se) in geni_se_get_qup_hw_version() argument
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()
237 static void geni_se_irq_clear(struct geni_se *se) in geni_se_irq_clear() argument
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
249 * @se: Pointer to the concerned serial engine.
251 * @rx_rfr: Ready-for-receive watermark, in units of FIFO words.
253 * This function is used to initialize the GENI serial engine, configure
254 * receive watermark and ready-for-receive watermarks.
256 void geni_se_init(struct geni_se *se, u32 rx_wm, u32 rx_rfr) in geni_se_init() argument
260 geni_se_irq_clear(se); in geni_se_init()
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()
277 static void geni_se_select_fifo_mode(struct geni_se *se) in geni_se_select_fifo_mode() argument
279 u32 proto = geni_se_read_proto(se); in geni_se_select_fifo_mode()
282 geni_se_irq_clear(se); in geni_se_select_fifo_mode()
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()
300 static void geni_se_select_dma_mode(struct geni_se *se) in geni_se_select_dma_mode() argument
302 u32 proto = geni_se_read_proto(se); in geni_se_select_dma_mode()
305 geni_se_irq_clear(se); in geni_se_select_dma_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()
323 static void geni_se_select_gpi_mode(struct geni_se *se) in geni_se_select_gpi_mode() argument
327 geni_se_irq_clear(se); in geni_se_select_gpi_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
345 * @se: Pointer to the concerned serial engine.
348 void geni_se_select_mode(struct geni_se *se, enum geni_se_xfer_mode mode) in geni_se_select_mode() argument
354 geni_se_select_fifo_mode(se); in geni_se_select_mode()
357 geni_se_select_dma_mode(se); in geni_se_select_mode()
360 geni_se_select_gpi_mode(se); in geni_se_select_mode()
372 * GENI FIFO packing is highly configurable. TX/RX packing/unpacking consist
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
421 * @se: Pointer to the concerned serial engine
424 * @msb_to_lsb: Transfer from MSB to LSB or vice-versa.
431 void geni_se_config_packing(struct geni_se *se, int bpw, int pack_words, in geni_se_config_packing() argument
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()
486 static void geni_se_clks_off(struct geni_se *se) in geni_se_clks_off() argument
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
497 * @se: Pointer to the concerned serial engine.
501 int geni_se_resources_off(struct geni_se *se) in geni_se_resources_off() argument
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()
512 geni_se_clks_off(se); in geni_se_resources_off()
517 static int geni_se_clks_on(struct geni_se *se) in geni_se_clks_on() argument
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
535 * @se: Pointer to the concerned serial engine.
539 int geni_se_resources_on(struct geni_se *se) in geni_se_resources_on() argument
543 if (has_acpi_companion(se->dev)) in geni_se_resources_on()
546 ret = geni_se_clks_on(se); in geni_se_resources_on()
550 ret = pinctrl_pm_select_default_state(se->dev); in geni_se_resources_on()
552 geni_se_clks_off(se); in geni_se_resources_on()
559 * geni_se_clk_tbl_get() - Get the clock table to program DFS
560 * @se: Pointer to the concerned serial engine.
571 int geni_se_clk_tbl_get(struct geni_se *se, unsigned long **tbl) in geni_se_clk_tbl_get() argument
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
602 * @se: Pointer to the concerned serial engine.
614 * - if @exact is true then @res_freq / <an_integer> == @req_freq
615 * - if @exact is false then @res_freq / <an_integer> <= @req_freq
619 int geni_se_clk_freq_match(struct geni_se *se, unsigned long req_freq, in geni_se_clk_freq_match() argument
630 num_clk_levels = geni_se_clk_tbl_get(se, &tbl); in geni_se_clk_freq_match()
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
669 * @se: Pointer to the concerned serial engine.
675 void geni_se_tx_init_dma(struct geni_se *se, dma_addr_t iova, size_t len) in geni_se_tx_init_dma() argument
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
692 * @se: Pointer to the concerned serial engine.
701 int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len, in geni_se_tx_dma_prep() argument
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()
713 geni_se_tx_init_dma(se, *iova, len); in geni_se_tx_dma_prep()
719 * geni_se_rx_init_dma() - Initiate RX DMA transfer on the serial engine
720 * @se: Pointer to the concerned serial engine.
726 void geni_se_rx_init_dma(struct geni_se *se, dma_addr_t iova, size_t len) in geni_se_rx_init_dma() argument
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()
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
744 * @se: Pointer to the concerned serial engine.
753 int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len, in geni_se_rx_dma_prep() argument
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()
765 geni_se_rx_init_dma(se, *iova, len); in geni_se_rx_dma_prep()
771 * geni_se_tx_dma_unprep() - Unprepare the serial engine after TX DMA transfer
772 * @se: Pointer to the concerned serial engine.
778 void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len) in geni_se_tx_dma_unprep() argument
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
789 * @se: Pointer to the concerned serial engine.
795 void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len) in geni_se_rx_dma_unprep() argument
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()
804 int geni_icc_get(struct geni_se *se, const char *icc_ddr) in geni_icc_get() argument
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()
833 int geni_icc_set_bw(struct geni_se *se) in geni_icc_set_bw() argument
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()
851 void geni_icc_set_tag(struct geni_se *se, u32 tag) in geni_icc_set_tag() argument
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()
861 int geni_icc_enable(struct geni_se *se) in geni_icc_enable() argument
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()
878 int geni_icc_disable(struct geni_se *se) in geni_icc_disable() argument
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()
943 dev_dbg(dev, "GENI SE Driver probed\n"); 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 },
982 MODULE_DESCRIPTION("GENI Serial Engine Driver");