/** * DOC: Overview * * Generic Interface (GENI) Serial Engine (SE) Wrapper driver is introduced * to manage GENI firmware based Qualcomm Universal Peripheral (QUP) Wrapper * controller. QUP Wrapper is designed to support various serial bus protocols * like UART, SPI, I2C, I3C, etc.
*/
/** * DOC: Hardware description * * GENI based QUP is a highly-flexible and programmable module for supporting * a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. A single * QUP module can provide upto 8 serial interfaces, using its internal * serial engines. The actual configuration is determined by the target * platform configuration. The protocol supported by each interface is * determined by the firmware loaded to the serial engine. Each SE consists * of a DMA Engine and GENI sub modules which enable serial engines to * support FIFO and DMA modes of operation. * * * +-----------------------------------------+ * |QUP Wrapper | * | +----------------------------+ | * --QUP & SE Clocks--> | Serial Engine N | +-IO------> * | | ... | | Interface * <---Clock Perf.----+ +----+-----------------------+ | | * State Interface | | Serial Engine 1 | | | * | | | | | * | | | | | * <--------AHB-------> | | | | * | | +----+ | * | | | | * | | | | * <------SE IRQ------+ +----------------------------+ | * | | * +-----------------------------------------+ * * Figure 1: GENI based QUP Wrapper * * The GENI submodules include primary and secondary sequencers which are * used to drive TX & RX operations. On serial interfaces that operate using * master-slave model, primary sequencer drives both TX & RX operations. On * serial interfaces that operate using peer-to-peer model, primary sequencer * drives TX operation and secondary sequencer drives RX operation.
*/
/** * DOC: Software description * * GENI SE Wrapper driver is structured into 2 parts: * * geni_wrapper represents QUP Wrapper controller. This part of the driver * manages QUP Wrapper information such as hardware version, clock * performance table that is common to all the internal serial engines. * * geni_se represents serial engine. This part of the driver manages serial * engine information such as clocks, containing QUP Wrapper, etc. This part * of driver also supports operations (eg. initialize the concerned serial * engine, select between FIFO and DMA mode of operation etc.) that are * common to all the serial engines and are independent of serial interfaces.
*/
#define MAX_CLK_PERF_LEVEL 32 #define MAX_CLKS 2
/** * struct geni_wrapper - Data structure to represent the QUP Wrapper Core * @dev: Device pointer of the QUP wrapper core * @base: Base address of this instance of QUP wrapper core * @clks: Handle to the primary & optional secondary AHB clocks * @num_clks: Count of clocks
*/ struct geni_wrapper { struct device *dev; void __iomem *base; struct clk_bulk_data clks[MAX_CLKS]; unsignedint num_clks;
};
/** * struct geni_se_desc - Data structure to represent the QUP Wrapper resources * @clks: Name of the primary & optional secondary AHB clocks * @num_clks: Count of clock names
*/ struct geni_se_desc { unsignedint num_clks; constchar * const *clks;
};
/** * geni_se_get_qup_hw_version() - Read the QUP wrapper Hardware version * @se: Pointer to the corresponding serial engine. * * Return: Hardware Version of the wrapper.
*/
u32 geni_se_get_qup_hw_version(struct geni_se *se)
{ struct geni_wrapper *wrapper = se->wrapper;
val = readl_relaxed(base + SE_IRQ_EN);
val |= GENI_M_IRQ_EN | GENI_S_IRQ_EN;
val |= DMA_TX_IRQ_EN | DMA_RX_IRQ_EN;
writel_relaxed(val, base + SE_IRQ_EN);
val = readl_relaxed(base + SE_GENI_DMA_MODE_EN);
val &= ~GENI_DMA_MODE_EN;
writel_relaxed(val, base + SE_GENI_DMA_MODE_EN);
val = readl_relaxed(base + GENI_CGC_CTRL);
val |= DEFAULT_CGC_EN;
writel_relaxed(val, base + GENI_CGC_CTRL);
val = readl_relaxed(base + SE_DMA_GENERAL_CFG);
val |= AHB_SEC_SLV_CLK_CGC_ON | DMA_AHB_SLV_CFG_ON;
val |= DMA_TX_CLK_CGC_ON | DMA_RX_CLK_CGC_ON;
writel_relaxed(val, base + SE_DMA_GENERAL_CFG);
writel_relaxed(DEFAULT_IO_OUTPUT_CTRL_MSK, base + GENI_OUTPUT_CTRL);
writel_relaxed(FORCE_DEFAULT, base + GENI_FORCE_DEFAULT_REG);
}
/** * geni_se_init() - Initialize the GENI serial engine * @se: Pointer to the concerned serial engine. * @rx_wm: Receive watermark, in units of FIFO words. * @rx_rfr: Ready-for-receive watermark, in units of FIFO words. * * This function is used to initialize the GENI serial engine, configure * receive watermark and ready-for-receive watermarks.
*/ void geni_se_init(struct geni_se *se, u32 rx_wm, u32 rx_rfr)
{
u32 val;
val = readl(se->base + SE_GSI_EVENT_EN);
val |= (DMA_RX_EVENT_EN | DMA_TX_EVENT_EN | GENI_M_EVENT_EN | GENI_S_EVENT_EN);
writel(val, se->base + SE_GSI_EVENT_EN);
}
/** * geni_se_select_mode() - Select the serial engine transfer mode * @se: Pointer to the concerned serial engine. * @mode: Transfer mode to be selected.
*/ void geni_se_select_mode(struct geni_se *se, enum geni_se_xfer_mode mode)
{
WARN_ON(mode != GENI_SE_FIFO && mode != GENI_SE_DMA && mode != GENI_GPI_DMA);
switch (mode) { case GENI_SE_FIFO:
geni_se_select_fifo_mode(se); break; case GENI_SE_DMA:
geni_se_select_dma_mode(se); break; case GENI_GPI_DMA:
geni_se_select_gpi_mode(se); break; case GENI_SE_INVALID: default: break;
}
}
EXPORT_SYMBOL_GPL(geni_se_select_mode);
#define NUM_PACKING_VECTORS 4 #define PACKING_START_SHIFT 5 #define PACKING_DIR_SHIFT 4 #define PACKING_LEN_SHIFT 1 #define PACKING_STOP_BIT BIT(0) #define PACKING_VECTOR_SHIFT 10 /** * geni_se_config_packing() - Packing configuration of the serial engine * @se: Pointer to the concerned serial engine * @bpw: Bits of data per transfer word. * @pack_words: Number of words per fifo element. * @msb_to_lsb: Transfer from MSB to LSB or vice-versa. * @tx_cfg: Flag to configure the TX Packing. * @rx_cfg: Flag to configure the RX Packing. * * This function is used to configure the packing rules for the current * transfer.
*/ void geni_se_config_packing(struct geni_se *se, int bpw, int pack_words, bool msb_to_lsb, bool tx_cfg, bool rx_cfg)
{
u32 cfg0, cfg1, cfg[NUM_PACKING_VECTORS] = {0}; int len; int temp_bpw = bpw; int idx_start = msb_to_lsb ? bpw - 1 : 0; int idx = idx_start; int idx_delta = msb_to_lsb ? -BITS_PER_BYTE : BITS_PER_BYTE; int ceil_bpw = ALIGN(bpw, BITS_PER_BYTE); int iter = (ceil_bpw * pack_words) / BITS_PER_BYTE; int i;
if (iter <= 0 || iter > NUM_PACKING_VECTORS) return;
for (i = 0; i < iter; i++) {
len = min_t(int, temp_bpw, BITS_PER_BYTE) - 1;
cfg[i] = idx << PACKING_START_SHIFT;
cfg[i] |= msb_to_lsb << PACKING_DIR_SHIFT;
cfg[i] |= len << PACKING_LEN_SHIFT;
/* * Number of protocol words in each FIFO entry * 0 - 4x8, four words in each entry, max word size of 8 bits * 1 - 2x16, two words in each entry, max word size of 16 bits * 2 - 1x32, one word in each entry, max word size of 32 bits * 3 - undefined
*/ if (pack_words || bpw == 32)
writel_relaxed(bpw / 16, se->base + SE_GENI_BYTE_GRAN);
}
EXPORT_SYMBOL_GPL(geni_se_config_packing);
/** * geni_se_resources_off() - Turn off resources associated with the serial * engine * @se: Pointer to the concerned serial engine. * * Return: 0 on success, standard Linux error codes on failure/error.
*/ int geni_se_resources_off(struct geni_se *se)
{ int ret;
if (has_acpi_companion(se->dev)) return 0;
ret = pinctrl_pm_select_sleep_state(se->dev); if (ret) return ret;
ret = clk_bulk_prepare_enable(wrapper->num_clks, wrapper->clks); if (ret) return ret;
ret = clk_prepare_enable(se->clk); if (ret)
clk_bulk_disable_unprepare(wrapper->num_clks, wrapper->clks); return ret;
}
/** * geni_se_resources_on() - Turn on resources associated with the serial * engine * @se: Pointer to the concerned serial engine. * * Return: 0 on success, standard Linux error codes on failure/error.
*/ int geni_se_resources_on(struct geni_se *se)
{ int ret;
if (has_acpi_companion(se->dev)) return 0;
ret = geni_se_clks_on(se); if (ret) return ret;
ret = pinctrl_pm_select_default_state(se->dev); if (ret)
geni_se_clks_off(se);
/** * geni_se_clk_tbl_get() - Get the clock table to program DFS * @se: Pointer to the concerned serial engine. * @tbl: Table in which the output is returned. * * This function is called by the protocol drivers to determine the different * clock frequencies supported by serial engine core clock. The protocol * drivers use the output to determine the clock frequency index to be * programmed into DFS. * * Return: number of valid performance levels in the table on success, * standard Linux error codes on failure.
*/ int geni_se_clk_tbl_get(struct geni_se *se, unsignedlong **tbl)
{ long freq = 0; int i;
if (se->clk_perf_tbl) {
*tbl = se->clk_perf_tbl; return se->num_clk_levels;
}
se->clk_perf_tbl = devm_kcalloc(se->dev, MAX_CLK_PERF_LEVEL, sizeof(*se->clk_perf_tbl),
GFP_KERNEL); if (!se->clk_perf_tbl) return -ENOMEM;
for (i = 0; i < MAX_CLK_PERF_LEVEL; i++) {
freq = clk_round_rate(se->clk, freq + 1); if (freq <= 0 ||
(i > 0 && freq == se->clk_perf_tbl[i - 1])) break;
se->clk_perf_tbl[i] = freq;
}
se->num_clk_levels = i;
*tbl = se->clk_perf_tbl; return se->num_clk_levels;
}
EXPORT_SYMBOL_GPL(geni_se_clk_tbl_get);
/** * geni_se_clk_freq_match() - Get the matching or closest SE clock frequency * @se: Pointer to the concerned serial engine. * @req_freq: Requested clock frequency. * @index: Index of the resultant frequency in the table. * @res_freq: Resultant frequency of the source clock. * @exact: Flag to indicate exact multiple requirement of the requested * frequency. * * This function is called by the protocol drivers to determine the best match * of the requested frequency as provided by the serial engine clock in order * to meet the performance requirements. * * If we return success: * - if @exact is true then @res_freq / <an_integer> == @req_freq * - if @exact is false then @res_freq / <an_integer> <= @req_freq * * Return: 0 on success, standard Linux error codes on failure.
*/ int geni_se_clk_freq_match(struct geni_se *se, unsignedlong req_freq, unsignedint *index, unsignedlong *res_freq, bool exact)
{ unsignedlong *tbl; int num_clk_levels; int i; unsignedlong best_delta; unsignedlong new_delta; unsignedint divider;
num_clk_levels = geni_se_clk_tbl_get(se, &tbl); if (num_clk_levels < 0) return num_clk_levels;
if (num_clk_levels == 0) return -EINVAL;
best_delta = ULONG_MAX; for (i = 0; i < num_clk_levels; i++) {
divider = DIV_ROUND_UP(tbl[i], req_freq);
new_delta = req_freq - tbl[i] / divider; if (new_delta < best_delta) { /* We have a new best! */
*index = i;
*res_freq = tbl[i];
/* If the new best is exact then we're done */ if (new_delta == 0) return 0;
/* Record how close we got */
best_delta = new_delta;
}
}
/** * geni_se_tx_init_dma() - Initiate TX DMA transfer on the serial engine * @se: Pointer to the concerned serial engine. * @iova: Mapped DMA address. * @len: Length of the TX buffer. * * This function is used to initiate DMA TX transfer.
*/ void geni_se_tx_init_dma(struct geni_se *se, dma_addr_t iova, size_t len)
{
u32 val;
/** * geni_se_tx_dma_prep() - Prepare the serial engine for TX DMA transfer * @se: Pointer to the concerned serial engine. * @buf: Pointer to the TX buffer. * @len: Length of the TX buffer. * @iova: Pointer to store the mapped DMA address. * * This function is used to prepare the buffers for DMA TX. * * Return: 0 on success, standard Linux error codes on failure.
*/ int geni_se_tx_dma_prep(struct geni_se *se, void *buf, size_t len,
dma_addr_t *iova)
{ struct geni_wrapper *wrapper = se->wrapper;
/** * geni_se_rx_init_dma() - Initiate RX DMA transfer on the serial engine * @se: Pointer to the concerned serial engine. * @iova: Mapped DMA address. * @len: Length of the RX buffer. * * This function is used to initiate DMA RX transfer.
*/ void geni_se_rx_init_dma(struct geni_se *se, dma_addr_t iova, size_t len)
{
u32 val;
val = GENI_SE_DMA_DONE_EN;
val |= GENI_SE_DMA_EOT_EN;
val |= GENI_SE_DMA_AHB_ERR_EN;
writel_relaxed(val, se->base + SE_DMA_RX_IRQ_EN_SET);
writel_relaxed(lower_32_bits(iova), se->base + SE_DMA_RX_PTR_L);
writel_relaxed(upper_32_bits(iova), se->base + SE_DMA_RX_PTR_H); /* RX does not have EOT buffer type bit. So just reset RX_ATTR */
writel_relaxed(0, se->base + SE_DMA_RX_ATTR);
writel(len, se->base + SE_DMA_RX_LEN);
}
EXPORT_SYMBOL_GPL(geni_se_rx_init_dma);
/** * geni_se_rx_dma_prep() - Prepare the serial engine for RX DMA transfer * @se: Pointer to the concerned serial engine. * @buf: Pointer to the RX buffer. * @len: Length of the RX buffer. * @iova: Pointer to store the mapped DMA address. * * This function is used to prepare the buffers for DMA RX. * * Return: 0 on success, standard Linux error codes on failure.
*/ int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len,
dma_addr_t *iova)
{ struct geni_wrapper *wrapper = se->wrapper;
/** * geni_se_tx_dma_unprep() - Unprepare the serial engine after TX DMA transfer * @se: Pointer to the concerned serial engine. * @iova: DMA address of the TX buffer. * @len: Length of the TX buffer. * * This function is used to unprepare the DMA buffers after DMA TX.
*/ void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len)
{ struct geni_wrapper *wrapper = se->wrapper;
if (!dma_mapping_error(wrapper->dev, iova))
dma_unmap_single(wrapper->dev, iova, len, DMA_TO_DEVICE);
}
EXPORT_SYMBOL_GPL(geni_se_tx_dma_unprep);
/** * geni_se_rx_dma_unprep() - Unprepare the serial engine after RX DMA transfer * @se: Pointer to the concerned serial engine. * @iova: DMA address of the RX buffer. * @len: Length of the RX buffer. * * This function is used to unprepare the DMA buffers after DMA RX.
*/ void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len)
{ struct geni_wrapper *wrapper = se->wrapper;
if (!dma_mapping_error(wrapper->dev, iova))
dma_unmap_single(wrapper->dev, iova, len, DMA_FROM_DEVICE);
}
EXPORT_SYMBOL_GPL(geni_se_rx_dma_unprep);
int geni_icc_get(struct geni_se *se, constchar *icc_ddr)
{ int i, err; constchar *icc_names[] = {"qup-core", "qup-config", icc_ddr};
if (has_acpi_companion(se->dev)) return 0;
for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) { if (!icc_names[i]) continue;
se->icc_paths[i].path = devm_of_icc_get(se->dev, icc_names[i]); if (IS_ERR(se->icc_paths[i].path)) goto err;
}
return 0;
err:
err = PTR_ERR(se->icc_paths[i].path); if (err != -EPROBE_DEFER)
dev_err_ratelimited(se->dev, "Failed to get ICC path '%s': %d\n",
icc_names[i], err); return err;
}
EXPORT_SYMBOL_GPL(geni_icc_get);
int geni_icc_set_bw(struct geni_se *se)
{ int i, ret;
for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) {
ret = icc_set_bw(se->icc_paths[i].path,
se->icc_paths[i].avg_bw, se->icc_paths[i].avg_bw); if (ret) {
dev_err_ratelimited(se->dev, "ICC BW voting failed on path '%s': %d\n",
icc_path_names[i], ret); return ret;
}
}
return 0;
}
EXPORT_SYMBOL_GPL(geni_icc_set_bw);
void geni_icc_set_tag(struct geni_se *se, u32 tag)
{ int i;
for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++)
icc_set_tag(se->icc_paths[i].path, tag);
}
EXPORT_SYMBOL_GPL(geni_icc_set_tag);
/* To do: Replace this by icc_bulk_enable once it's implemented in ICC core */ int geni_icc_enable(struct geni_se *se)
{ int i, ret;
for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) {
ret = icc_enable(se->icc_paths[i].path); if (ret) {
dev_err_ratelimited(se->dev, "ICC enable failed on path '%s': %d\n",
icc_path_names[i], ret); return ret;
}
}
return 0;
}
EXPORT_SYMBOL_GPL(geni_icc_enable);
int geni_icc_disable(struct geni_se *se)
{ int i, ret;
for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) {
ret = icc_disable(se->icc_paths[i].path); if (ret) {
dev_err_ratelimited(se->dev, "ICC disable failed on path '%s': %d\n",
icc_path_names[i], ret); return ret;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.