* [PATCH V7 4/7] spi: spi-geni-qcom: Add interconnect support
From: Akash Asthana @ 2020-05-26 12:54 UTC (permalink / raw)
To: gregkh, agross, bjorn.andersson, wsa, broonie, mark.rutland,
robh+dt
Cc: linux-i2c, linux-spi, devicetree, swboyd, mgautam, linux-arm-msm,
linux-serial, mka, dianders, msavaliy, evgreen, Akash Asthana
In-Reply-To: <1590497690-29035-1-git-send-email-akashast@codeaurora.org>
Get the interconnect paths for SPI based Serial Engine device
and vote according to the current bus speed of the driver.
Signed-off-by: Akash Asthana <akashast@codeaurora.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in V2:
- As per Bjorn's comment, removed se == NULL check from geni_spi_icc_get
- As per Bjorn's comment, removed code to set se->icc_path* to NULL in failure
- As per Bjorn's comment, introduced and using devm_of_icc_get API for getting
path handle
- As per Matthias comment, added error handling for icc_set_bw call
Changes in V3:
- As per Matthias's comment, use helper ICC function from geni-se driver.
Changes in V4:
- Move peak_bw guess as twice of avg_bw if nothing mentioned explicitly
to ICC core.
Changes in V5:
- Use icc_enable/disable in power on/off call.
- Save some non-zero avg/peak value to ICC core by calling geni_icc_set_bw
from probe so that when resume/icc_enable is called NOC are running at
some non-zero value. No need to call icc_disable after BW vote because
device will resume and suspend before probe return and will leave ICC in
disabled state.
Changes in V6:
- No change
Changes in V7:
- As per Matthias's comment removed usage of peak_bw variable because we don't
have explicit peak requirement, we were voting peak = avg and this can be
tracked using single variable for avg bw.
drivers/spi/spi-geni-qcom.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
index c397242..2ace5c5 100644
--- a/drivers/spi/spi-geni-qcom.c
+++ b/drivers/spi/spi-geni-qcom.c
@@ -234,6 +234,12 @@ static int setup_fifo_params(struct spi_device *spi_slv,
return ret;
}
+ /* Set BW quota for CPU as driver supports FIFO mode only. */
+ se->icc_paths[CPU_TO_GENI].avg_bw = Bps_to_icc(mas->cur_speed_hz);
+ ret = geni_icc_set_bw(se);
+ if (ret)
+ return ret;
+
clk_sel = idx & CLK_SEL_MSK;
m_clk_cfg = (div << CLK_DIV_SHFT) | SER_CLK_EN;
spi_setup_word_len(mas, spi_slv->mode, spi_slv->bits_per_word);
@@ -578,6 +584,17 @@ static int spi_geni_probe(struct platform_device *pdev)
spin_lock_init(&mas->lock);
pm_runtime_enable(dev);
+ ret = geni_icc_get(&mas->se, NULL);
+ if (ret)
+ goto spi_geni_probe_runtime_disable;
+ /* Set the bus quota to a reasonable value for register access */
+ mas->se.icc_paths[GENI_TO_CORE].avg_bw = Bps_to_icc(CORE_2X_50_MHZ);
+ mas->se.icc_paths[CPU_TO_GENI].avg_bw = GENI_DEFAULT_BW;
+
+ ret = geni_icc_set_bw(&mas->se);
+ if (ret)
+ goto spi_geni_probe_runtime_disable;
+
ret = spi_geni_init(mas);
if (ret)
goto spi_geni_probe_runtime_disable;
@@ -616,14 +633,24 @@ static int __maybe_unused spi_geni_runtime_suspend(struct device *dev)
{
struct spi_master *spi = dev_get_drvdata(dev);
struct spi_geni_master *mas = spi_master_get_devdata(spi);
+ int ret;
+
+ ret = geni_se_resources_off(&mas->se);
+ if (ret)
+ return ret;
- return geni_se_resources_off(&mas->se);
+ return geni_icc_disable(&mas->se);
}
static int __maybe_unused spi_geni_runtime_resume(struct device *dev)
{
struct spi_master *spi = dev_get_drvdata(dev);
struct spi_geni_master *mas = spi_master_get_devdata(spi);
+ int ret;
+
+ ret = geni_icc_enable(&mas->se);
+ if (ret)
+ return ret;
return geni_se_resources_on(&mas->se);
}
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
^ permalink raw reply related
* [PATCH V7 2/7] soc: qcom-geni-se: Add interconnect support to fix earlycon crash
From: Akash Asthana @ 2020-05-26 12:54 UTC (permalink / raw)
To: gregkh, agross, bjorn.andersson, wsa, broonie, mark.rutland,
robh+dt
Cc: linux-i2c, linux-spi, devicetree, swboyd, mgautam, linux-arm-msm,
linux-serial, mka, dianders, msavaliy, evgreen, Akash Asthana
In-Reply-To: <1590497690-29035-1-git-send-email-akashast@codeaurora.org>
QUP core clock is shared among all the SE drivers present on particular
QUP wrapper, the system will reset(unclocked access) if earlycon used after
QUP core clock is put to 0 from other SE drivers before real console comes
up.
As earlycon can't vote for it's QUP core need, to fix this add ICC
support to common/QUP wrapper driver and put vote for QUP core from
probe on behalf of earlycon and remove vote during earlycon exit call.
Signed-off-by: Akash Asthana <akashast@codeaurora.org>
Reported-by: Matthias Kaehlcke <mka@chromium.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
---
Change in V3:
- Add geni_remove_earlycon_icc_vote API that will be used by earlycon
exit function to remove ICC vote for earlyconsole.
- Remove suspend/resume hook for geni-se driver as we are no longer
removing earlyconsole ICC vote from system suspend, we are removing
from earlycon exit.
Change in V4:
- As per Matthias comment make 'earlycon_wrapper' as static structure.
Changes in V5:
- Vote for core path only after checking whether "qcom_geni" earlycon is
actually present or not by traversing over structure "console_drivers".
Changes in V6:
- As per Matthias's comment removed NULL check for console_drivers global
struct, added NULL check for earlycon_wrapper in _remove_earlycon_icc_vote
API
- Addressed nitpicks from Andy.
Changes in V7:
- As per Matthias's comment removed usage of peak_bw variable because we don't
have explicit peak requirement, we were voting peak = avg and this can be
tracked using single variable for avg bw.
- As per Matthias's comment improved print log.
drivers/soc/qcom/qcom-geni-se.c | 68 +++++++++++++++++++++++++++++++++++
drivers/tty/serial/qcom_geni_serial.c | 7 ++++
include/linux/qcom-geni-se.h | 2 ++
3 files changed, 77 insertions(+)
diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
index 950e347..e2a0ba2 100644
--- a/drivers/soc/qcom/qcom-geni-se.c
+++ b/drivers/soc/qcom/qcom-geni-se.c
@@ -3,6 +3,7 @@
#include <linux/acpi.h>
#include <linux/clk.h>
+#include <linux/console.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
#include <linux/io.h>
@@ -90,11 +91,14 @@ struct geni_wrapper {
struct device *dev;
void __iomem *base;
struct clk_bulk_data ahb_clks[NUM_AHB_CLKS];
+ struct geni_icc_path to_core;
};
static const char * const icc_path_names[] = {"qup-core", "qup-config",
"qup-memory"};
+static struct geni_wrapper *earlycon_wrapper;
+
#define QUP_HW_VER_REG 0x4
/* Common SE registers */
@@ -802,11 +806,38 @@ int geni_icc_disable(struct geni_se *se)
}
EXPORT_SYMBOL(geni_icc_disable);
+void geni_remove_earlycon_icc_vote(void)
+{
+ struct geni_wrapper *wrapper;
+ struct device_node *parent;
+ struct device_node *child;
+
+ if (!earlycon_wrapper)
+ return;
+
+ wrapper = earlycon_wrapper;
+ parent = of_get_next_parent(wrapper->dev->of_node);
+ for_each_child_of_node(parent, child) {
+ if (!of_device_is_compatible(child, "qcom,geni-se-qup"))
+ continue;
+ wrapper = platform_get_drvdata(of_find_device_by_node(child));
+ icc_put(wrapper->to_core.path);
+ wrapper->to_core.path = NULL;
+
+ }
+ of_node_put(parent);
+
+ earlycon_wrapper = NULL;
+}
+EXPORT_SYMBOL(geni_remove_earlycon_icc_vote);
+
static int geni_se_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
struct geni_wrapper *wrapper;
+ struct console __maybe_unused *bcon;
+ bool __maybe_unused has_earlycon = false;
int ret;
wrapper = devm_kzalloc(dev, sizeof(*wrapper), GFP_KERNEL);
@@ -829,6 +860,43 @@ static int geni_se_probe(struct platform_device *pdev)
}
}
+#ifdef CONFIG_SERIAL_EARLYCON
+ for_each_console(bcon) {
+ if (!strcmp(bcon->name, "qcom_geni")) {
+ has_earlycon = true;
+ break;
+ }
+ }
+ if (!has_earlycon)
+ goto exit;
+
+ wrapper->to_core.path = devm_of_icc_get(dev, "qup-core");
+ if (IS_ERR(wrapper->to_core.path))
+ return PTR_ERR(wrapper->to_core.path);
+ /*
+ * Put minmal BW request on core clocks on behalf of early console.
+ * The vote will be removed earlycon exit function.
+ *
+ * Note: We are putting vote on each QUP wrapper instead only to which
+ * earlycon is connected because QUP core clock of different wrapper
+ * share same voltage domain. If core1 is put to 0, then core2 will
+ * also run at 0, if not voted. Default ICC vote will be removed ASA
+ * we touch any of the core clock.
+ * core1 = core2 = max(core1, core2)
+ */
+ ret = icc_set_bw(wrapper->to_core.path, GENI_DEFAULT_BW,
+ GENI_DEFAULT_BW);
+ if (ret) {
+ dev_err(&pdev->dev, "%s: ICC BW voting failed for core: %d\n",
+ __func__, ret);
+ return ret;
+ }
+
+ if (of_get_compatible_child(pdev->dev.of_node, "qcom,geni-debug-uart"))
+ earlycon_wrapper = wrapper;
+ of_node_put(pdev->dev.of_node);
+#endif
+exit:
dev_set_drvdata(dev, wrapper);
dev_dbg(dev, "GENI SE Driver probed\n");
return devm_of_platform_populate(dev);
diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
index 6bace1c..a2b1b6d 100644
--- a/drivers/tty/serial/qcom_geni_serial.c
+++ b/drivers/tty/serial/qcom_geni_serial.c
@@ -1120,6 +1120,12 @@ static inline void qcom_geni_serial_enable_early_read(struct geni_se *se,
struct console *con) { }
#endif
+static int qcom_geni_serial_earlycon_exit(struct console *con)
+{
+ geni_remove_earlycon_icc_vote();
+ return 0;
+}
+
static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
const char *opt)
{
@@ -1165,6 +1171,7 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
writel(stop_bit_len, uport->membase + SE_UART_TX_STOP_BIT_LEN);
dev->con->write = qcom_geni_serial_earlycon_write;
+ dev->con->exit = qcom_geni_serial_earlycon_exit;
dev->con->setup = NULL;
qcom_geni_serial_enable_early_read(&se, dev->con);
diff --git a/include/linux/qcom-geni-se.h b/include/linux/qcom-geni-se.h
index 80dbc01..743dd97 100644
--- a/include/linux/qcom-geni-se.h
+++ b/include/linux/qcom-geni-se.h
@@ -454,5 +454,7 @@ int geni_icc_set_bw(struct geni_se *se);
int geni_icc_enable(struct geni_se *se);
int geni_icc_disable(struct geni_se *se);
+
+void geni_remove_earlycon_icc_vote(void);
#endif
#endif
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
^ permalink raw reply related
* [PATCH V7 3/7] i2c: i2c-qcom-geni: Add interconnect support
From: Akash Asthana @ 2020-05-26 12:54 UTC (permalink / raw)
To: gregkh, agross, bjorn.andersson, wsa, broonie, mark.rutland,
robh+dt
Cc: linux-i2c, linux-spi, devicetree, swboyd, mgautam, linux-arm-msm,
linux-serial, mka, dianders, msavaliy, evgreen, Akash Asthana
In-Reply-To: <1590497690-29035-1-git-send-email-akashast@codeaurora.org>
Get the interconnect paths for I2C based Serial Engine device
and vote according to the bus speed of the driver.
Signed-off-by: Akash Asthana <akashast@codeaurora.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in V2:
- As per Bjorn's comment, removed se == NULL check from geni_i2c_icc_get
- As per Bjorn's comment, removed code to set se->icc_path* to NULL in failure
- As per Bjorn's comment, introduced and using devm_of_icc_get API for getting
path handle
- As per Matthias comment, added error handling for icc_set_bw call
Changes in V3:
- As per Matthias comment, use common library APIs defined in geni-se
driver for ICC functionality.
Changes in V4:
- Move peak_bw guess as twice of avg_bw if nothing mentioned explicitly
to ICC core.
Changes in V5:
- Use icc_enable/disable in power on/off call.
Changes in V6:
- No changes
Changes in V7:
- As per Matthias's comment removed usage of peak_bw variable because we don't
have explicit peak requirement, we were voting peak = avg and this can be
tracked using single variable for avg bw.
drivers/i2c/busses/i2c-qcom-geni.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index 18d1e4f..32b2a99 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -557,6 +557,22 @@ static int geni_i2c_probe(struct platform_device *pdev)
gi2c->adap.dev.of_node = dev->of_node;
strlcpy(gi2c->adap.name, "Geni-I2C", sizeof(gi2c->adap.name));
+ ret = geni_icc_get(&gi2c->se, "qup-memory");
+ if (ret)
+ return ret;
+ /*
+ * Set the bus quota for core and cpu to a reasonable value for
+ * register access.
+ * Set quota for DDR based on bus speed.
+ */
+ gi2c->se.icc_paths[GENI_TO_CORE].avg_bw = GENI_DEFAULT_BW;
+ gi2c->se.icc_paths[CPU_TO_GENI].avg_bw = GENI_DEFAULT_BW;
+ gi2c->se.icc_paths[GENI_TO_DDR].avg_bw = Bps_to_icc(gi2c->clk_freq_out);
+
+ ret = geni_icc_set_bw(&gi2c->se);
+ if (ret)
+ return ret;
+
ret = geni_se_resources_on(&gi2c->se);
if (ret) {
dev_err(dev, "Error turning on resources %d\n", ret);
@@ -579,6 +595,10 @@ static int geni_i2c_probe(struct platform_device *pdev)
return ret;
}
+ ret = geni_icc_disable(&gi2c->se);
+ if (ret)
+ return ret;
+
dev_dbg(dev, "i2c fifo/se-dma mode. fifo depth:%d\n", tx_depth);
gi2c->suspended = 1;
@@ -623,7 +643,7 @@ static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev)
gi2c->suspended = 1;
}
- return 0;
+ return geni_icc_disable(&gi2c->se);
}
static int __maybe_unused geni_i2c_runtime_resume(struct device *dev)
@@ -631,6 +651,10 @@ static int __maybe_unused geni_i2c_runtime_resume(struct device *dev)
int ret;
struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
+ ret = geni_icc_enable(&gi2c->se);
+ if (ret)
+ return ret;
+
ret = geni_se_resources_on(&gi2c->se);
if (ret)
return ret;
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
^ permalink raw reply related
* [PATCH V7 1/7] soc: qcom: geni: Support for ICC voting
From: Akash Asthana @ 2020-05-26 12:54 UTC (permalink / raw)
To: gregkh, agross, bjorn.andersson, wsa, broonie, mark.rutland,
robh+dt
Cc: linux-i2c, linux-spi, devicetree, swboyd, mgautam, linux-arm-msm,
linux-serial, mka, dianders, msavaliy, evgreen, Akash Asthana
In-Reply-To: <1590497690-29035-1-git-send-email-akashast@codeaurora.org>
Add necessary macros and structure variables to support ICC BW
voting from individual SE drivers.
Signed-off-by: Akash Asthana <akashast@codeaurora.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in V2:
- As per Bjorn's comment dropped enums for ICC paths, given the three
paths individual members
Changes in V3:
- Add geni_icc_get, geni_icc_vote_on and geni_icc_vote_off as helper API.
- Add geni_icc_path structure in common header
Changes in V4:
- As per Bjorn's comment print error message in geni_icc_get if return
value is not -EPROBE_DEFER.
- As per Bjorn's comment remove NULL on path before calling icc_set_bw
API.
- As per Bjorn's comment drop __func__ print.
- As per Matthias's comment, make ICC path a array instead of individual
member entry in geni_se struct.
Changes in V5:
- As per Matthias's comment defined enums for ICC paths.
- Integrate icc_enable/disable with power on/off call for driver.
- As per Matthias's comment added icc_path_names array to print icc path name
in failure case.
- As per Georgi's suggestion assume peak_bw = avg_bw if not mentioned.
Changes in V6:
- Addressed nitpicks from Matthias.
Changes in V7:
- As per Matthias's comment removed usage of peak_bw variable because we don't
have explicit peak requirement, we were voting peak = avg and this can be
tracked using single variable for avg bw.
- As per Matthias's comment improved print log.
Note: I have ignored below check patch suggestion because it was throwing
compilation error as 'icc_ddr' is not compile time comstant.
WARNING: char * array declaration might be better as static const
- FILE: drivers/soc/qcom/qcom-geni-se.c:726:
- const char *icc_names[] = {"qup-core", "qup-config", icc_ddr};
drivers/soc/qcom/qcom-geni-se.c | 82 +++++++++++++++++++++++++++++++++++++++++
include/linux/qcom-geni-se.h | 38 +++++++++++++++++++
2 files changed, 120 insertions(+)
diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
index 7d622ea..950e347 100644
--- a/drivers/soc/qcom/qcom-geni-se.c
+++ b/drivers/soc/qcom/qcom-geni-se.c
@@ -92,6 +92,9 @@ struct geni_wrapper {
struct clk_bulk_data ahb_clks[NUM_AHB_CLKS];
};
+static const char * const icc_path_names[] = {"qup-core", "qup-config",
+ "qup-memory"};
+
#define QUP_HW_VER_REG 0x4
/* Common SE registers */
@@ -720,6 +723,85 @@ void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len)
}
EXPORT_SYMBOL(geni_se_rx_dma_unprep);
+int geni_icc_get(struct geni_se *se, const char *icc_ddr)
+{
+ int i, err;
+ const char *icc_names[] = {"qup-core", "qup-config", icc_ddr};
+
+ 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(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(geni_icc_set_bw);
+
+/* 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(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;
+ }
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(geni_icc_disable);
+
static int geni_se_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
diff --git a/include/linux/qcom-geni-se.h b/include/linux/qcom-geni-se.h
index dd46494..80dbc01 100644
--- a/include/linux/qcom-geni-se.h
+++ b/include/linux/qcom-geni-se.h
@@ -6,6 +6,8 @@
#ifndef _LINUX_QCOM_GENI_SE
#define _LINUX_QCOM_GENI_SE
+#include <linux/interconnect.h>
+
/* Transfer mode supported by GENI Serial Engines */
enum geni_se_xfer_mode {
GENI_SE_INVALID,
@@ -25,6 +27,17 @@ enum geni_se_protocol_type {
struct geni_wrapper;
struct clk;
+enum geni_icc_path_index {
+ GENI_TO_CORE,
+ CPU_TO_GENI,
+ GENI_TO_DDR
+};
+
+struct geni_icc_path {
+ struct icc_path *path;
+ unsigned int avg_bw;
+};
+
/**
* struct geni_se - GENI Serial Engine
* @base: Base Address of the Serial Engine's register block
@@ -33,6 +46,7 @@ struct clk;
* @clk: Handle to the core serial engine clock
* @num_clk_levels: Number of valid clock levels in clk_perf_tbl
* @clk_perf_tbl: Table of clock frequency input to serial engine clock
+ * @icc_paths: Array of ICC paths for SE
*/
struct geni_se {
void __iomem *base;
@@ -41,6 +55,7 @@ struct geni_se {
struct clk *clk;
unsigned int num_clk_levels;
unsigned long *clk_perf_tbl;
+ struct geni_icc_path icc_paths[3];
};
/* Common SE registers */
@@ -229,6 +244,21 @@ struct geni_se {
#define GENI_SE_VERSION_MINOR(ver) ((ver & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT)
#define GENI_SE_VERSION_STEP(ver) (ver & HW_VER_STEP_MASK)
+/*
+ * Define bandwidth thresholds that cause the underlying Core 2X interconnect
+ * clock to run at the named frequency. These baseline values are recommended
+ * by the hardware team, and are not dynamically scaled with GENI bandwidth
+ * beyond basic on/off.
+ */
+#define CORE_2X_19_2_MHZ 960
+#define CORE_2X_50_MHZ 2500
+#define CORE_2X_100_MHZ 5000
+#define CORE_2X_150_MHZ 7500
+#define CORE_2X_200_MHZ 10000
+#define CORE_2X_236_MHZ 16383
+
+#define GENI_DEFAULT_BW Bps_to_icc(1000)
+
#if IS_ENABLED(CONFIG_QCOM_GENI_SE)
u32 geni_se_get_qup_hw_version(struct geni_se *se);
@@ -416,5 +446,13 @@ int geni_se_rx_dma_prep(struct geni_se *se, void *buf, size_t len,
void geni_se_tx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len);
+
+int geni_icc_get(struct geni_se *se, const char *icc_ddr);
+
+int geni_icc_set_bw(struct geni_se *se);
+
+int geni_icc_enable(struct geni_se *se);
+
+int geni_icc_disable(struct geni_se *se);
#endif
#endif
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
^ permalink raw reply related
* [PATCH V7 0/7] Add interconnect support to QSPI and QUP drivers
From: Akash Asthana @ 2020-05-26 12:54 UTC (permalink / raw)
To: gregkh, agross, bjorn.andersson, wsa, broonie, mark.rutland,
robh+dt
Cc: linux-i2c, linux-spi, devicetree, swboyd, mgautam, linux-arm-msm,
linux-serial, mka, dianders, msavaliy, evgreen, Akash Asthana
This patch series is based on tag "next-20200525" of linux-next tree.
dt-binding patch for QUP drivers.
- https://patchwork.kernel.org/patch/11534149/ [Convert QUP bindings
to YAML and add ICC, pin swap doc]
High level design:
- QUP wrapper/common driver.
Vote for QUP core on behalf of earlycon from probe.
Remove BW vote during earlycon exit call
- SERIAL driver.
Vote only for CPU/CORE path because driver is in FIFO mode only
Vote/unvote from qcom_geni_serial_pm func.
Bump up the CPU vote from set_termios call based on real time need
- I2C driver.
Vote for CORE/CPU/DDR path
Vote/unvote from runtime resume/suspend callback
As bus speed for I2C is fixed from probe itself no need for bump up.
- SPI QUP driver.
Vote only for CPU/CORE path because driver is in FIFO mode only
Vote/unvote from runtime resume/suspend callback
Bump up CPU vote based on real time need per transfer.
- QSPI driver.
Vote only for CPU path
Vote/unvote from runtime resume/suspend callback
Bump up CPU vote based on real time need per transfer.
Changes in V2:
- Add devm_of_icc_get() API interconnect core.
- Add ICC support to common driver to fix earlyconsole crash.
Changes in V3:
- Define common ICC APIs in geni-se driver and use it across geni based
I2C,SPI and UART driver.
Changes in V4:
- Add a patch to ICC core to scale peak requirement
as twice of average if it is not mentioned explicilty.
Changes in V5:
- As per Georgi's suggestion removed patch from ICC core for assuming
peak_bw as twice of average when it's not mentioned, instead assume it
equall to avg_bw and keep this assumption in ICC client itself.
- As per Matthias suggestion use enum for GENI QUP ICC paths.
Changes in V6:
- No Major change
Changes in V7:
- As per Matthias's comment removed usage of peak_bw variable because we don't
have explicit peak requirement, we were voting peak = avg and this can be
tracked using single variable for avg bw.
- As per Matthias's comment improved print log.
Akash Asthana (7):
soc: qcom: geni: Support for ICC voting
soc: qcom-geni-se: Add interconnect support to fix earlycon crash
i2c: i2c-qcom-geni: Add interconnect support
spi: spi-geni-qcom: Add interconnect support
tty: serial: qcom_geni_serial: Add interconnect support
spi: spi-qcom-qspi: Add interconnect support
arm64: dts: sc7180: Add interconnect for QUP and QSPI
arch/arm64/boot/dts/qcom/sc7180.dtsi | 127 ++++++++++++++++++++++++++++
drivers/i2c/busses/i2c-qcom-geni.c | 26 +++++-
drivers/soc/qcom/qcom-geni-se.c | 150 ++++++++++++++++++++++++++++++++++
drivers/spi/spi-geni-qcom.c | 29 ++++++-
drivers/spi/spi-qcom-qspi.c | 57 ++++++++++++-
drivers/tty/serial/qcom_geni_serial.c | 38 ++++++++-
include/linux/qcom-geni-se.h | 40 +++++++++
7 files changed, 461 insertions(+), 6 deletions(-)
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
^ permalink raw reply
* Re: [PATCH V6 1/7] soc: qcom: geni: Support for ICC voting
From: Akash Asthana @ 2020-05-26 12:41 UTC (permalink / raw)
To: Matthias Kaehlcke
Cc: gregkh, agross, bjorn.andersson, wsa, broonie, mark.rutland,
robh+dt, linux-i2c, linux-spi, devicetree, swboyd, mgautam,
linux-arm-msm, linux-serial, dianders, msavaliy, evgreen
In-Reply-To: <20200521155009.GA4525@google.com>
Hi Matthias,
On 5/21/2020 9:20 PM, Matthias Kaehlcke wrote:
> Hi Akash,
>
> On Thu, May 21, 2020 at 01:59:18PM +0530, Akash Asthana wrote:
>> Add necessary macros and structure variables to support ICC BW
>> voting from individual SE drivers.
>>
>> Signed-off-by: Akash Asthana <akashast@codeaurora.org>
>> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
>> ---
>> Changes in V2:
>> - As per Bjorn's comment dropped enums for ICC paths, given the three
>> paths individual members
>>
>> Changes in V3:
>> - Add geni_icc_get, geni_icc_vote_on and geni_icc_vote_off as helper API.
>> - Add geni_icc_path structure in common header
>>
>> Changes in V4:
>> - As per Bjorn's comment print error message in geni_icc_get if return
>> value is not -EPROBE_DEFER.
>> - As per Bjorn's comment remove NULL on path before calling icc_set_bw
>> API.
>> - As per Bjorn's comment drop __func__ print.
>> - As per Matthias's comment, make ICC path a array instead of individual
>> member entry in geni_se struct.
>>
>> Changes in V5:
>> - As per Matthias's comment defined enums for ICC paths.
>> - Integrate icc_enable/disable with power on/off call for driver.
>> - As per Matthias's comment added icc_path_names array to print icc path name
>> in failure case.
>> - As per Georgi's suggestion assume peak_bw = avg_bw if not mentioned.
>>
>> Changes in V6:
>> - Addressed nitpicks from Matthias.
>>
>> Note: I have ignored below check patch suggestion because it was throwing
>> compilation error as 'icc_ddr' is not compile time comstant.
>>
>> WARNING: char * array declaration might be better as static const
>> - FILE: drivers/soc/qcom/qcom-geni-se.c:726:
>> - const char *icc_names[] = {"qup-core", "qup-config", icc_ddr};
>>
>> drivers/soc/qcom/qcom-geni-se.c | 92 +++++++++++++++++++++++++++++++++++++++++
>> include/linux/qcom-geni-se.h | 42 +++++++++++++++++++
>> 2 files changed, 134 insertions(+)
>>
>> diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
>> index 7d622ea..0b2526d 100644
>> --- a/drivers/soc/qcom/qcom-geni-se.c
>> +++ b/drivers/soc/qcom/qcom-geni-se.c
>> @@ -92,6 +92,9 @@ struct geni_wrapper {
>> struct clk_bulk_data ahb_clks[NUM_AHB_CLKS];
>> };
>>
>> +static const char * const icc_path_names[] = {"qup-core", "qup-config",
>> + "qup-memory"};
>> +
>> #define QUP_HW_VER_REG 0x4
>>
>> /* Common SE registers */
>> @@ -720,6 +723,95 @@ void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len)
>> }
>> EXPORT_SYMBOL(geni_se_rx_dma_unprep);
>>
>> +int geni_icc_get(struct geni_se *se, const char *icc_ddr)
>> +{
>> + int i, err;
>> + const char *icc_names[] = {"qup-core", "qup-config", icc_ddr};
>> +
>> + 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",
> That's still an odd format, especially the colon before the error code. My
> suggestion was "... path 'qup-core': 42" i.e. "... path '%s': %d".
Sorry about it, I will correct this everywhere.
> I don't want to stall the series on nits though, if there is no need for
> a respin for other reasons this can be also fixed with a patch after this
> has landed.
>
> I'm still not overly convinced about having two bandwidth values for what
> might happen in the future (or not). Typically unused functions or struct
> members that are added just in case tend to be rejected, since they can be
> added when the need actually arises. Anyway, as long as maintainers are
> happy with it I won't object.
Okay, I am removing peak_bw variable and tracking BW request just with
avg_bw, if need I will add this back in future.
Thanks for reviewing
regards,
Akash
>
> Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
>
>
>
>
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,\na Linux Foundation Collaborative Project
^ permalink raw reply
* RE: [PATCH 1/2] hwmon: pwm-fan: Add profile support and add remove module support
From: Sandipan Patra @ 2020-05-26 12:08 UTC (permalink / raw)
To: Guenter Roeck, Thierry Reding, Jonathan Hunter,
u.kleine-koenig@pengutronix.de, kamil@wypas.org,
jdelvare@suse.com, robh+dt@kernel.org
Cc: Bibek Basu, Bitan Biswas, linux-pwm@vger.kernel.org,
linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org
In-Reply-To: <53619c02-8c0f-3eec-cccc-16e779b8c425@roeck-us.net>
Hi,
> -----Original Message-----
> From: Guenter Roeck <groeck7@gmail.com> On Behalf Of Guenter Roeck
> Sent: Tuesday, May 26, 2020 5:12 PM
> To: Sandipan Patra <spatra@nvidia.com>; Thierry Reding
> <treding@nvidia.com>; Jonathan Hunter <jonathanh@nvidia.com>; u.kleine-
> koenig@pengutronix.de; kamil@wypas.org; jdelvare@suse.com;
> robh+dt@kernel.org
> Cc: Bibek Basu <bbasu@nvidia.com>; Bitan Biswas <bbiswas@nvidia.com>;
> linux-pwm@vger.kernel.org; linux-hwmon@vger.kernel.org;
> devicetree@vger.kernel.org; linux-tegra@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: Re: [PATCH 1/2] hwmon: pwm-fan: Add profile support and add remove
> module support
>
> External email: Use caution opening links or attachments
>
>
> On 5/25/20 10:06 PM, Sandipan Patra wrote:
> > This change has 2 parts:
> > 1. Add support for profiles mode settings.
> > This allows different fan settings for trip point temp/hyst/pwm.
> > T194 has multiple fan-profiles support.
> >
> > 2. Add pwm-fan remove support. This is essential since the config is
> > tristate capable.
> >
> > Signed-off-by: Sandipan Patra <spatra@nvidia.com>
> > ---
> > drivers/hwmon/pwm-fan.c | 112
> > ++++++++++++++++++++++++++++++++++++++++++------
> > 1 file changed, 100 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index
> > 30b7b3e..26db589 100644
> > --- a/drivers/hwmon/pwm-fan.c
> > +++ b/drivers/hwmon/pwm-fan.c
>
> [ ... ]
>
> >
> > +static int pwm_fan_remove(struct platform_device *pdev) {
> > + struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev);
> > + struct pwm_args args;
> > +
> > + if (!ctx)
> > + return -EINVAL;
> > +
> > + if (IS_ENABLED(CONFIG_THERMAL))
> > + thermal_cooling_device_unregister(ctx->cdev);
> > +
> > + pwm_get_args(ctx->pwm, &args);
> > + pwm_config(ctx->pwm, 0, args.period);
> > + pwm_disable(ctx->pwm);
> > +
> > + return 0;
> > +}
> > +
>
> I don't think you actually tested this. I would suggest to make yourself familiar
> with 'devm' functions and their use, and then resubmit.
>
Thanks Guenter.
I missed to mention about devm while unregistering the cooling device.
That would definitely cause a mistake in code. I am noting it for further patch.
For a better clarity, I will push next version of this patch to handle only multiple profiles support.
"remove fan module" will be supported by a separate patch altogether.
Thanks & Regards,
Sandipan
> Thanks,
> Guenter
^ permalink raw reply
* Re: [Patch 2/2] media: ti-vpe: Add the VIP driver
From: Hans Verkuil @ 2020-05-26 11:48 UTC (permalink / raw)
To: Benoit Parrot, Rob Herring
Cc: linux-media, devicetree, linux-kernel, Nikhil Devshatwar
In-Reply-To: <20200522225412.29440-3-bparrot@ti.com>
On 23/05/2020 00:54, Benoit Parrot wrote:
> VIP stands for Video Input Port, it can be found on devices such as
> DRA7xx and provides a parallel interface to a video source such as
> a sensor or TV decoder. Each VIP can support two inputs (slices) and
> a SoC can be configured with a variable number of VIP's.
> Each slice can supports two ports each connected to its own
> sub-device.
>
> Signed-off-by: Benoit Parrot <bparrot@ti.com>
> Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
> ---
> drivers/media/platform/Kconfig | 13 +
> drivers/media/platform/ti-vpe/Makefile | 2 +
> drivers/media/platform/ti-vpe/vip.c | 4158 ++++++++++++++++++++++++
> drivers/media/platform/ti-vpe/vip.h | 724 +++++
> 4 files changed, 4897 insertions(+)
> create mode 100644 drivers/media/platform/ti-vpe/vip.c
> create mode 100644 drivers/media/platform/ti-vpe/vip.h
>
> diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
> index c57ee78fa99d..f4100a1aad58 100644
> --- a/drivers/media/platform/Kconfig
> +++ b/drivers/media/platform/Kconfig
> @@ -168,6 +168,19 @@ config VIDEO_TI_CAL
> In TI Technical Reference Manual this module is referred as
> Camera Interface Subsystem (CAMSS).
>
> +config VIDEO_TI_VIP
> + tristate "TI Video Input Port"
> + default n
> + depends on VIDEO_DEV && VIDEO_V4L2 && SOC_DRA7XX
> + depends on HAS_DMA
> + select VIDEOBUF2_DMA_CONTIG
> + select VIDEO_TI_VPDMA
> + select VIDEO_TI_SC
> + select VIDEO_TI_CSC
> + help
> + Driver support for VIP module on certain TI SoC's
> + VIP = Video Input Port.
> +
> endif # V4L_PLATFORM_DRIVERS
>
> menuconfig V4L_MEM2MEM_DRIVERS
> diff --git a/drivers/media/platform/ti-vpe/Makefile b/drivers/media/platform/ti-vpe/Makefile
> index 886ac5ec073f..cdbecadf7191 100644
> --- a/drivers/media/platform/ti-vpe/Makefile
> +++ b/drivers/media/platform/ti-vpe/Makefile
> @@ -3,11 +3,13 @@ obj-$(CONFIG_VIDEO_TI_VPE) += ti-vpe.o
> obj-$(CONFIG_VIDEO_TI_VPDMA) += ti-vpdma.o
> obj-$(CONFIG_VIDEO_TI_SC) += ti-sc.o
> obj-$(CONFIG_VIDEO_TI_CSC) += ti-csc.o
> +obj-$(CONFIG_VIDEO_TI_VIP) += ti-vip.o
>
> ti-vpe-y := vpe.o
> ti-vpdma-y := vpdma.o
> ti-sc-y := sc.o
> ti-csc-y := csc.o
> +ti-vip-y := vip.o
>
> ccflags-$(CONFIG_VIDEO_TI_VPE_DEBUG) += -DDEBUG
>
> diff --git a/drivers/media/platform/ti-vpe/vip.c b/drivers/media/platform/ti-vpe/vip.c
> new file mode 100644
> index 000000000000..307b01851a14
> --- /dev/null
> +++ b/drivers/media/platform/ti-vpe/vip.c
> @@ -0,0 +1,4158 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * TI VIP capture driver
> + *
> + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
> + * David Griego, <dagriego@biglakesoftware.com>
> + * Dale Farnsworth, <dale@farnsworth.org>
> + * Nikhil Devshatwar, <nikhil.nd@ti.com>
> + * Benoit Parrot, <bparrot@ti.com>
> + */
> +
> +#include <linux/clk.h>
> +#include <linux/delay.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/module.h>
> +#include <linux/workqueue.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/sched.h>
> +#include <linux/mfd/syscon.h>
> +#include <linux/regmap.h>
> +
> +#include <linux/pinctrl/consumer.h>
> +#include <linux/of_device.h>
> +#include <linux/of_graph.h>
> +
> +#include "vip.h"
> +
> +#define VIP_MODULE_NAME "vip"
> +
> +static int debug;
> +module_param(debug, int, 0644);
> +MODULE_PARM_DESC(debug, "debug level (0-8)");
> +
> +/*
> + * Minimum and maximum frame sizes
> + */
> +#define MIN_W 128
> +#define MIN_H 128
> +#define MAX_W 2048
> +#define MAX_H 1536
> +
> +/*
> + * Required alignments
> + */
> +#define S_ALIGN 0 /* multiple of 1 */
> +#define H_ALIGN 1 /* multiple of 2 */
> +#define W_ALIGN 1 /* multiple of 2 */
> +#define L_ALIGN 7 /* multiple of 128, line stride, 16 bytes */
> +
> +/*
> + * Need a descriptor entry for each of up to 15 outputs,
> + * and up to 2 control transfers.
> + */
> +#define VIP_DESC_LIST_SIZE (17 * sizeof(struct vpdma_dtd))
> +
> +#define vip_dbg(level, dev, fmt, arg...) \
> + v4l2_dbg(level, debug, dev, fmt, ##arg)
> +#define vip_err(dev, fmt, arg...) \
> + v4l2_err(dev, fmt, ##arg)
> +#define vip_warn(dev, fmt, arg...) \
> + v4l2_err(dev, fmt, ##arg)
> +#define vip_info(dev, fmt, arg...) \
> + v4l2_info(dev, fmt, ##arg)
These defines are just aliases. Any reason for not just using v4l2_info etc.?
> +
> +#define CTRL_CORE_SMA_SW_1 0x534
> +/*
> + * The srce_info structure contains per-srce data.
> + */
> +struct vip_srce_info {
> + u8 base_channel; /* the VPDMA channel nummber */
> + u8 vb_index; /* input frame f, f-1, f-2 index */
> + u8 vb_part; /* identifies section of co-planar formats */
> +};
> +
> +#define VIP_VPDMA_FIFO_SIZE 2
> +#define VIP_DROPQ_SIZE 3
> +
> +/*
> + * Define indices into the srce_info tables
> + */
> +
> +#define VIP_SRCE_MULT_PORT 0
> +#define VIP_SRCE_MULT_ANC 1
> +#define VIP_SRCE_LUMA 2
> +#define VIP_SRCE_CHROMA 3
> +#define VIP_SRCE_RGB 4
> +
> +static struct vip_srce_info srce_info[5] = {
> + [VIP_SRCE_MULT_PORT] = {
> + .base_channel = VIP1_CHAN_NUM_MULT_PORT_A_SRC0,
> + .vb_index = 0,
> + .vb_part = VIP_CHROMA,
> + },
> + [VIP_SRCE_MULT_ANC] = {
> + .base_channel = VIP1_CHAN_NUM_MULT_ANC_A_SRC0,
> + .vb_index = 0,
> + .vb_part = VIP_LUMA,
> + },
> + [VIP_SRCE_LUMA] = {
> + .base_channel = VIP1_CHAN_NUM_PORT_A_LUMA,
> + .vb_index = 1,
> + .vb_part = VIP_LUMA,
> + },
> + [VIP_SRCE_CHROMA] = {
> + .base_channel = VIP1_CHAN_NUM_PORT_A_CHROMA,
> + .vb_index = 1,
> + .vb_part = VIP_CHROMA,
> + },
> + [VIP_SRCE_RGB] = {
> + .base_channel = VIP1_CHAN_NUM_PORT_A_RGB,
> + .vb_part = VIP_LUMA,
> + },
> +};
> +
> +static struct vip_fmt vip_formats[VIP_MAX_ACTIVE_FMT] = {
> + {
> + .fourcc = V4L2_PIX_FMT_NV12,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
Colorspace information should come from the subdev (sensor or video receiver).
You really don't know what the colorspace is here.
> + .coplanar = 1,
> + .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_Y420],
> + &vpdma_yuv_fmts[VPDMA_DATA_FMT_C420],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_UYVY,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_CBY422],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_YUYV,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_YCB422],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_VYUY,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_CRY422],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_YVYU,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_yuv_fmts[VPDMA_DATA_FMT_YCR422],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_RGB24,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_rgb_fmts[VPDMA_DATA_FMT_RGB24],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_RGB32,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_rgb_fmts[VPDMA_DATA_FMT_ARGB32],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_BGR24,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_rgb_fmts[VPDMA_DATA_FMT_BGR24],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_BGR32,
> + .code = MEDIA_BUS_FMT_UYVY8_2X8,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_rgb_fmts[VPDMA_DATA_FMT_ABGR32],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_RGB24,
> + .code = MEDIA_BUS_FMT_RGB888_1X24,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_rgb_fmts[VPDMA_DATA_FMT_RGB24],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_RGB32,
> + .code = MEDIA_BUS_FMT_ARGB8888_1X32,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_rgb_fmts[VPDMA_DATA_FMT_ARGB32],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_SBGGR8,
> + .code = MEDIA_BUS_FMT_SBGGR8_1X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
SMPTE 170M for a Bayer format? That can't be right. But as mentioned above,
this should come from the subdev.
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_raw_fmts[VPDMA_DATA_FMT_RAW8],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_SGBRG8,
> + .code = MEDIA_BUS_FMT_SGBRG8_1X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_raw_fmts[VPDMA_DATA_FMT_RAW8],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_SGRBG8,
> + .code = MEDIA_BUS_FMT_SGRBG8_1X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_raw_fmts[VPDMA_DATA_FMT_RAW8],
> + },
> + },
> + {
> + .fourcc = V4L2_PIX_FMT_SRGGB8,
> + .code = MEDIA_BUS_FMT_SRGGB8_1X8,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_raw_fmts[VPDMA_DATA_FMT_RAW8],
> + },
> + },
> + {
> + /* V4L2 currently only defines one 16 bit variant */
> + .fourcc = V4L2_PIX_FMT_SBGGR16,
> + .code = MEDIA_BUS_FMT_SBGGR16_1X16,
> + .colorspace = V4L2_COLORSPACE_SMPTE170M,
> + .coplanar = 0,
> + .vpdma_fmt = { &vpdma_raw_fmts[VPDMA_DATA_FMT_RAW16],
> + },
> + },
> +};
> +
> +/* initialize v4l2_format_info member in vip_formats array */
> +static void vip_init_format_info(struct device *dev)
> +{
> + struct vip_fmt *fmt;
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(vip_formats); i++) {
> + fmt = &vip_formats[i];
> + fmt->finfo = v4l2_format_info(fmt->fourcc);
> + }
> +}
> +
> +/* Print Four-character-code (FOURCC) */
> +static char *fourcc_to_str(u32 fmt)
> +{
> + static char code[5];
> +
> + code[0] = (unsigned char)(fmt & 0xff);
> + code[1] = (unsigned char)((fmt >> 8) & 0xff);
> + code[2] = (unsigned char)((fmt >> 16) & 0xff);
> + code[3] = (unsigned char)((fmt >> 24) & 0xff);
> + code[4] = '\0';
> +
> + return code;
> +}
> +
> +/*
> + * Find our format description corresponding to the passed v4l2_format
> + */
> +
> +static struct vip_fmt *find_port_format_by_pix(struct vip_port *port,
> + u32 pixelformat)
> +{
> + struct vip_fmt *fmt;
> + unsigned int k;
> +
> + for (k = 0; k < port->num_active_fmt; k++) {
> + fmt = port->active_fmt[k];
> + if (fmt->fourcc == pixelformat)
> + return fmt;
> + }
> +
> + return NULL;
> +}
> +
> +static struct vip_fmt *find_port_format_by_code(struct vip_port *port,
> + u32 code)
> +{
> + struct vip_fmt *fmt;
> + unsigned int k;
> +
> + for (k = 0; k < port->num_active_fmt; k++) {
> + fmt = port->active_fmt[k];
> + if (fmt->code == code)
> + return fmt;
> + }
> +
> + return NULL;
> +}
> +
> +static int vip_find_pad(struct v4l2_subdev *sd, int direction)
> +{
> + unsigned int pad;
> +
> + if (sd->entity.num_pads <= 1)
> + return 0;
> +
> + for (pad = 0; pad < sd->entity.num_pads; pad++)
> + if (sd->entity.pads[pad].flags & direction)
> + return pad;
> +
> + return -EINVAL;
> +}
> +
> +inline struct vip_port *notifier_to_vip_port(struct v4l2_async_notifier *n)
> +{
> + return container_of(n, struct vip_port, notifier);
> +}
> +
> +static bool vip_is_mbuscode_yuv(u32 code)
> +{
> + return ((code & 0xFF00) == 0x2000);
Use lower-case hex.
> +}
> +
> +static bool vip_is_mbuscode_rgb(u32 code)
> +{
> + return ((code & 0xFF00) == 0x1000);
> +}
> +
> +static bool vip_is_mbuscode_raw(u32 code)
> +{
> + return ((code & 0xFF00) == 0x3000);
> +}
> +
> +/*
> + * This is not an accurate conversion but it is only used to
> + * assess if color conversion is needed.
> + */
> +static u32 vip_mbus_code_to_fourcc(u32 code)
> +{
> + if (vip_is_mbuscode_rgb(code))
> + return V4L2_PIX_FMT_RGB24;
> +
> + if (vip_is_mbuscode_yuv(code))
> + return V4L2_PIX_FMT_UYVY;
> +
> + return V4L2_PIX_FMT_SBGGR8;
> +}
> +
> +static enum vip_csc_state
> +vip_csc_direction(u32 src_code, const struct v4l2_format_info *dfinfo)
> +{
> + if (vip_is_mbuscode_yuv(src_code) && v4l2_is_format_rgb(dfinfo))
> + return VIP_CSC_Y2R;
> + else if (vip_is_mbuscode_rgb(src_code) && v4l2_is_format_yuv(dfinfo))
> + return VIP_CSC_R2Y;
> + else
> + return VIP_CSC_NA;
> +}
> +
> +/*
> + * port flag bits
> + */
> +#define FLAG_FRAME_1D BIT(0)
> +#define FLAG_EVEN_LINE_SKIP BIT(1)
> +#define FLAG_ODD_LINE_SKIP BIT(2)
> +#define FLAG_MODE_TILED BIT(3)
> +#define FLAG_INTERLACED BIT(4)
> +#define FLAG_MULTIPLEXED BIT(5)
> +#define FLAG_MULT_PORT BIT(6)
> +#define FLAG_MULT_ANC BIT(7)
> +
> +/*
> + * Function prototype declarations
> + */
> +static int alloc_port(struct vip_dev *, int, const char *);
> +static void free_port(struct vip_port *);
> +static int vip_setup_parser(struct vip_port *port);
> +static int vip_setup_scaler(struct vip_stream *stream);
> +static void vip_enable_parser(struct vip_port *port, bool on);
> +static void vip_reset_parser(struct vip_port *port, bool on);
> +static void vip_parser_stop_imm(struct vip_port *port, bool on);
> +static void stop_dma(struct vip_stream *stream, bool clear_list);
> +static int vip_load_vpdma_list_fifo(struct vip_stream *stream);
> +static inline bool is_scaler_available(struct vip_port *port);
> +static inline bool allocate_scaler(struct vip_port *port);
> +static inline void free_scaler(struct vip_port *port);
> +static bool is_csc_available(struct vip_port *port);
> +static bool allocate_csc(struct vip_port *port,
> + enum vip_csc_state csc_direction);
> +static void free_csc(struct vip_port *port);
> +
> +#define reg_read(dev, offset) ioread32(dev->base + offset)
> +#define reg_write(dev, offset, val) iowrite32(val, dev->base + offset)
> +
> +/*
> + * Insert a masked field into a 32-bit field
> + */
> +static void insert_field(u32 *valp, u32 field, u32 mask, int shift)
> +{
> + u32 val = *valp;
> +
> + val &= ~(mask << shift);
> + val |= (field & mask) << shift;
> + *valp = val;
> +}
> +
> +/*
> + * DMA address/data block for the shadow registers
> + */
> +struct vip_mmr_adb {
> + struct vpdma_adb_hdr sc_hdr0;
> + u32 sc_regs0[7];
> + u32 sc_pad0[1];
> + struct vpdma_adb_hdr sc_hdr8;
> + u32 sc_regs8[6];
> + u32 sc_pad8[2];
> + struct vpdma_adb_hdr sc_hdr17;
> + u32 sc_regs17[9];
> + u32 sc_pad17[3];
> + struct vpdma_adb_hdr csc_hdr;
> + u32 csc_regs[6];
> + u32 csc_pad[2];
> +};
> +
> +#define GET_OFFSET_TOP(port, obj, reg) \
> + ((obj)->res->start - port->dev->res->start + reg)
> +
> +#define VIP_SET_MMR_ADB_HDR(port, hdr, regs, offset_a) \
> + VPDMA_SET_MMR_ADB_HDR(port->mmr_adb, vip_mmr_adb, hdr, regs, offset_a)
> +
> +/*
> + * Set the headers for all of the address/data block structures.
> + */
> +static void init_adb_hdrs(struct vip_port *port)
> +{
> + VIP_SET_MMR_ADB_HDR(port, sc_hdr0, sc_regs0,
> + GET_OFFSET_TOP(port, port->dev->sc, CFG_SC0));
> + VIP_SET_MMR_ADB_HDR(port, sc_hdr8, sc_regs8,
> + GET_OFFSET_TOP(port, port->dev->sc, CFG_SC8));
> + VIP_SET_MMR_ADB_HDR(port, sc_hdr17, sc_regs17,
> + GET_OFFSET_TOP(port, port->dev->sc, CFG_SC17));
> + VIP_SET_MMR_ADB_HDR(port, csc_hdr, csc_regs,
> + GET_OFFSET_TOP(port, port->dev->csc, CSC_CSC00));
> +
> +};
> +
> +/*
> + * These represent the module resets bit for slice 1
> + * Upon detecting slice2 we simply left shift by 1
> + */
> +#define VIP_DP_RST BIT(16)
> +#define VIP_PARSER_RST BIT(18)
> +#define VIP_CSC_RST BIT(20)
> +#define VIP_SC_RST BIT(22)
> +#define VIP_DS0_RST BIT(25)
> +#define VIP_DS1_RST BIT(27)
> +
> +static void vip_module_reset(struct vip_dev *dev, uint32_t module, bool on)
> +{
> + u32 val = 0;
> +
> + val = reg_read(dev, VIP_CLK_RESET);
> +
> + if (dev->slice_id == VIP_SLICE2)
> + module <<= 1;
> +
> + if (on)
> + val |= module;
> + else
> + val &= ~module;
> +
> + reg_write(dev, VIP_CLK_RESET, val);
> +}
> +
> +/*
> + * Enable or disable the VIP clocks
> + */
> +static void vip_set_clock_enable(struct vip_dev *dev, bool on)
> +{
> + u32 val = 0;
> +
> + val = reg_read(dev, VIP_CLK_ENABLE);
> + if (on) {
> + val |= VIP_VPDMA_CLK_ENABLE;
> + if (dev->slice_id == VIP_SLICE1)
> + val |= VIP_VIP1_DATA_PATH_CLK_ENABLE;
> + else
> + val |= VIP_VIP2_DATA_PATH_CLK_ENABLE;
> + } else {
> + if (dev->slice_id == VIP_SLICE1)
> + val &= ~VIP_VIP1_DATA_PATH_CLK_ENABLE;
> + else
> + val &= ~VIP_VIP2_DATA_PATH_CLK_ENABLE;
> +
> + /* Both VIP are disabled then shutdown VPDMA also */
> + if (!(val & (VIP_VIP1_DATA_PATH_CLK_ENABLE |
> + VIP_VIP2_DATA_PATH_CLK_ENABLE)))
> + val = 0;
> + }
> +
> + reg_write(dev, VIP_CLK_ENABLE, val);
> +}
> +
> +/* This helper function is used to enable the clock early on to
> + * enable vpdma firmware loading before the slice device are created
> + */
> +static void vip_shared_set_clock_enable(struct vip_shared *shared, bool on)
> +{
> + u32 val = 0;
> +
> + if (on)
> + val = VIP_VIP1_DATA_PATH_CLK_ENABLE | VIP_VPDMA_CLK_ENABLE;
> +
> + reg_write(shared, VIP_CLK_ENABLE, val);
> +}
> +
> +static void vip_top_reset(struct vip_dev *dev)
> +{
> + u32 val = 0;
> +
> + val = reg_read(dev, VIP_CLK_RESET);
> +
> + if (dev->slice_id == VIP_SLICE1)
> + insert_field(&val, 1, VIP_DATA_PATH_CLK_RESET_MASK,
> + VIP_VIP1_DATA_PATH_RESET_SHIFT);
> + else
> + insert_field(&val, 1, VIP_DATA_PATH_CLK_RESET_MASK,
> + VIP_VIP2_DATA_PATH_RESET_SHIFT);
> +
> + reg_write(dev, VIP_CLK_RESET, val);
> +
> + usleep_range(200, 250);
> +
> + val = reg_read(dev, VIP_CLK_RESET);
> +
> + if (dev->slice_id == VIP_SLICE1)
> + insert_field(&val, 0, VIP_DATA_PATH_CLK_RESET_MASK,
> + VIP_VIP1_DATA_PATH_RESET_SHIFT);
> + else
> + insert_field(&val, 0, VIP_DATA_PATH_CLK_RESET_MASK,
> + VIP_VIP2_DATA_PATH_RESET_SHIFT);
> + reg_write(dev, VIP_CLK_RESET, val);
> +}
> +
> +static void vip_top_vpdma_reset(struct vip_shared *shared)
> +{
> + u32 val;
> +
> + val = reg_read(shared, VIP_CLK_RESET);
> + insert_field(&val, 1, VIP_VPDMA_CLK_RESET_MASK,
> + VIP_VPDMA_CLK_RESET_SHIFT);
> + reg_write(shared, VIP_CLK_RESET, val);
> +
> + usleep_range(200, 250);
> +
> + val = reg_read(shared, VIP_CLK_RESET);
> + insert_field(&val, 0, VIP_VPDMA_CLK_RESET_MASK,
> + VIP_VPDMA_CLK_RESET_SHIFT);
> + reg_write(shared, VIP_CLK_RESET, val);
> +}
> +
> +static void vip_set_pclk_invert(struct vip_port *port)
> +{
> + struct vip_clk_polarity *pclk = port->dev->pclk_pol;
> + u32 index;
> +
> + /*
> + * When the VIP parser is configured to so that the pixel clock
> + * is to be sampled at falling edge, the pixel clock needs to be
> + * inverted before it is given to the VIP module. This is done
> + * by setting a bit in the CTRL_CORE_SMA_SW1 register.
> + */
> +
> + index = 2 * port->dev->slice_id + port->port_id;
> + vip_dbg(3, port, "%s: slice%d:port%d -> index: %d\n", __func__,
> + port->dev->slice_id, port->port_id, index);
> +
> + if (pclk->rm_pol)
> + regmap_update_bits(pclk->rm_pol,
> + pclk->rm_offset,
> + pclk->rm_bit_field[index],
> + pclk->rm_bit_field[index]);
> +}
> +
> +static void vip_clr_pclk_invert(struct vip_port *port)
> +{
> + struct vip_clk_polarity *pclk = port->dev->pclk_pol;
> + u32 index;
> +
> + index = 2 * port->dev->slice_id + port->port_id;
> + vip_dbg(3, port, "%s: slice%d:port%d -> index: %d\n", __func__,
> + port->dev->slice_id, port->port_id, index);
> +
> + if (pclk->rm_pol)
> + regmap_update_bits(pclk->rm_pol, pclk->rm_offset,
> + pclk->rm_bit_field[index], 0);
> +}
> +
> +#define VIP_PARSER_PORT(p) (VIP_PARSER_PORTA_0 + (p * 0x8U))
> +#define VIP_PARSER_EXTRA_PORT(p) (VIP_PARSER_PORTA_1 + (p * 0x8U))
> +#define VIP_PARSER_CROP_H_PORT(p) (VIP_PARSER_PORTA_EXTRA4 + (p * 0x10U))
> +#define VIP_PARSER_CROP_V_PORT(p) (VIP_PARSER_PORTA_EXTRA5 + (p * 0x10U))
> +#define VIP_PARSER_STOP_IMM_PORT(p) (VIP_PARSER_PORTA_EXTRA6 + (p * 0x4U))
> +
> +static void vip_set_data_interface(struct vip_port *port,
> + enum data_interface_modes mode)
> +{
> + u32 val = 0;
> +
> + insert_field(&val, mode, VIP_DATA_INTERFACE_MODE_MASK,
> + VIP_DATA_INTERFACE_MODE_SHFT);
> +
> + reg_write(port->dev->parser, VIP_PARSER_MAIN_CFG, val);
> +}
> +
> +static void vip_set_slice_path(struct vip_dev *dev,
> + enum data_path_select data_path, u32 path_val)
> +{
> + u32 val = 0;
> + int data_path_reg;
> +
> + vip_dbg(3, dev, "%s:\n", __func__);
> +
> + data_path_reg = VIP_VIP1_DATA_PATH_SELECT + 4 * dev->slice_id;
> +
> + switch (data_path) {
> + case ALL_FIELDS_DATA_SELECT:
> + val |= path_val;
> + break;
> + case VIP_CSC_SRC_DATA_SELECT:
> + insert_field(&val, path_val, VIP_CSC_SRC_SELECT_MASK,
> + VIP_CSC_SRC_SELECT_SHFT);
> + break;
> + case VIP_SC_SRC_DATA_SELECT:
> + insert_field(&val, path_val, VIP_SC_SRC_SELECT_MASK,
> + VIP_SC_SRC_SELECT_SHFT);
> + break;
> + case VIP_RGB_SRC_DATA_SELECT:
> + val |= (path_val) ? VIP_RGB_SRC_SELECT : 0;
> + break;
> + case VIP_RGB_OUT_LO_DATA_SELECT:
> + val |= (path_val) ? VIP_RGB_OUT_LO_SRC_SELECT : 0;
> + break;
> + case VIP_RGB_OUT_HI_DATA_SELECT:
> + val |= (path_val) ? VIP_RGB_OUT_HI_SRC_SELECT : 0;
> + break;
> + case VIP_CHR_DS_1_SRC_DATA_SELECT:
> + insert_field(&val, path_val, VIP_DS1_SRC_SELECT_MASK,
> + VIP_DS1_SRC_SELECT_SHFT);
> + break;
> + case VIP_CHR_DS_2_SRC_DATA_SELECT:
> + insert_field(&val, path_val, VIP_DS2_SRC_SELECT_MASK,
> + VIP_DS2_SRC_SELECT_SHFT);
> + break;
> + case VIP_MULTI_CHANNEL_DATA_SELECT:
> + val |= (path_val) ? VIP_MULTI_CHANNEL_SELECT : 0;
> + break;
> + case VIP_CHR_DS_1_DATA_BYPASS:
> + val |= (path_val) ? VIP_DS1_BYPASS : 0;
> + break;
> + case VIP_CHR_DS_2_DATA_BYPASS:
> + val |= (path_val) ? VIP_DS2_BYPASS : 0;
> + break;
> + default:
> + vip_err(dev, "%s: data_path 0x%x is not valid\n",
> + __func__, data_path);
> + return;
> + }
> + insert_field(&val, data_path, VIP_DATAPATH_SELECT_MASK,
> + VIP_DATAPATH_SELECT_SHFT);
> + reg_write(dev, data_path_reg, val);
> + vip_dbg(3, dev, "%s: DATA_PATH_SELECT(%08X): %08X\n", __func__,
> + data_path_reg, reg_read(dev, data_path_reg));
> +}
> +
> +/*
> + * Return the vip_stream structure for a given struct file
> + */
> +static inline struct vip_stream *file2stream(struct file *file)
> +{
> + return video_drvdata(file);
> +}
> +
> +/*
> + * Append a destination descriptor to the current descriptor list,
> + * setting up dma to the given srce.
> + */
> +static int add_out_dtd(struct vip_stream *stream, int srce_type)
> +{
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + struct vip_srce_info *sinfo = &srce_info[srce_type];
> + struct v4l2_rect *c_rect = &port->c_rect;
> + struct vip_fmt *fmt = port->fmt;
> + int channel, plane = 0;
> + int max_width, max_height;
> + dma_addr_t dma_addr;
> + u32 flags;
> + u32 width = stream->width;
> +
> + channel = sinfo->base_channel;
> +
> + switch (srce_type) {
> + case VIP_SRCE_MULT_PORT:
> + case VIP_SRCE_MULT_ANC:
> + if (port->port_id == VIP_PORTB)
> + channel += VIP_CHAN_MULT_PORTB_OFFSET;
> + channel += stream->stream_id;
> + flags = 0;
> + break;
> + case VIP_SRCE_CHROMA:
> + plane = 1;
> + /* fallthrough */
> + case VIP_SRCE_LUMA:
> + if (port->port_id == VIP_PORTB) {
> + if (port->scaler && !port->fmt->coplanar)
> + /*
> + * In this case Port A Chroma channel
> + * is used to carry Port B scaled YUV422
> + */
> + channel += 1;
> + else
> + channel += VIP_CHAN_YUV_PORTB_OFFSET;
> + }
> + flags = port->flags;
> + break;
> + case VIP_SRCE_RGB:
> + if ((port->port_id == VIP_PORTB) ||
> + ((port->port_id == VIP_PORTA) &&
> + (port->csc == VIP_CSC_NA) &&
> + v4l2_is_format_rgb(port->fmt->finfo)))
> + /*
> + * RGB sensor only connect to Y_LO
> + * channel i.e. port B channel.
> + */
> + channel += VIP_CHAN_RGB_PORTB_OFFSET;
> + flags = port->flags;
> + break;
> + default:
> + vip_err(stream, "%s: srce_type 0x%x is not valid\n",
> + __func__, srce_type);
> + return -1;
> + }
> +
> + if (dev->slice_id == VIP_SLICE2)
> + channel += VIP_CHAN_VIP2_OFFSET;
> +
> + /* This is just for initialization purposes.
> + * The actual dma_addr will be configured in vpdma_update_dma_addr
> + */
> + dma_addr = 0;
> +
> + if (port->fmt->vpdma_fmt[0] == &vpdma_raw_fmts[VPDMA_DATA_FMT_RAW8]) {
> + /*
> + * Special case since we are faking a YUV422 16bit format
> + * to have the vpdma perform the needed byte swap
> + * we need to adjust the pixel width accordingly
> + * otherwise the parser will attempt to collect more pixels
> + * then available and the vpdma transfer will exceed the
> + * allocated frame buffer.
> + */
> + width >>= 1;
> + vip_dbg(1, stream, "%s: 8 bit raw detected, adjusting width to %d\n",
> + __func__, width);
> + }
> +
> + /*
> + * Use VPDMA_MAX_SIZE1 or VPDMA_MAX_SIZE2 register for slice0/1
> + */
> +
> + if (dev->slice_id == VIP_SLICE1) {
> + vpdma_set_max_size(dev->shared->vpdma, VPDMA_MAX_SIZE1,
> + width, stream->height);
> +
> + max_width = MAX_OUT_WIDTH_REG1;
> + max_height = MAX_OUT_HEIGHT_REG1;
> + } else {
> + vpdma_set_max_size(dev->shared->vpdma, VPDMA_MAX_SIZE2,
> + width, stream->height);
> +
> + max_width = MAX_OUT_WIDTH_REG2;
> + max_height = MAX_OUT_HEIGHT_REG2;
> + }
> +
> + /*
> + * Mark this channel to be cleared while cleaning up resources
> + * This will make sure that an abort descriptor for this channel
> + * would be submitted to VPDMA causing any ongoing transaction to be
> + * aborted and cleanup the VPDMA FSM for this channel
> + */
> + stream->vpdma_channels[channel] = 1;
> +
> + vpdma_rawchan_add_out_dtd(&stream->desc_list, c_rect->width,
> + stream->bytesperline, c_rect,
> + fmt->vpdma_fmt[plane], dma_addr,
> + max_width, max_height, channel, flags);
> +
> + return 0;
> +}
> +
> +/*
> + * add_stream_dtds - prepares and starts DMA for pending transfers
> + */
> +static void add_stream_dtds(struct vip_stream *stream)
> +{
> + struct vip_port *port = stream->port;
> + int srce_type;
> +
> + if (port->flags & FLAG_MULT_PORT)
> + srce_type = VIP_SRCE_MULT_PORT;
> + else if (port->flags & FLAG_MULT_ANC)
> + srce_type = VIP_SRCE_MULT_ANC;
> + else if (v4l2_is_format_rgb(port->fmt->finfo))
> + srce_type = VIP_SRCE_RGB;
> + else
> + srce_type = VIP_SRCE_LUMA;
> +
> + add_out_dtd(stream, srce_type);
> +
> + if (srce_type == VIP_SRCE_LUMA && port->fmt->coplanar)
> + add_out_dtd(stream, VIP_SRCE_CHROMA);
> +}
> +
> +#define PARSER_IRQ_MASK (VIP_PORTA_OUTPUT_FIFO_YUV | \
> + VIP_PORTB_OUTPUT_FIFO_YUV)
> +
> +static void enable_irqs(struct vip_dev *dev, int irq_num, int list_num)
> +{
> + struct vip_parser_data *parser = dev->parser;
> + u32 reg_addr = VIP_INT0_ENABLE0_SET +
> + VIP_INTC_INTX_OFFSET * irq_num;
> + u32 irq_val = (1 << (list_num * 2)) |
> + (VIP_VIP1_PARSER_INT << (irq_num * 1));
> +
> + /* Enable Parser Interrupt */
> + reg_write(parser, VIP_PARSER_FIQ_MASK, ~PARSER_IRQ_MASK);
> +
> + reg_write(dev->shared, reg_addr, irq_val);
> +
> + vpdma_enable_list_complete_irq(dev->shared->vpdma,
> + irq_num, list_num, true);
> +}
> +
> +static void disable_irqs(struct vip_dev *dev, int irq_num, int list_num)
> +{
> + struct vip_parser_data *parser = dev->parser;
> + u32 reg_addr = VIP_INT0_ENABLE0_CLR +
> + VIP_INTC_INTX_OFFSET * irq_num;
> + u32 irq_val = (1 << (list_num * 2)) |
> + (VIP_VIP1_PARSER_INT << (irq_num * 1));
> +
> + /* Disable all Parser Interrupt */
> + reg_write(parser, VIP_PARSER_FIQ_MASK, 0xffffffff);
> +
> + reg_write(dev->shared, reg_addr, irq_val);
> +
> + vpdma_enable_list_complete_irq(dev->shared->vpdma,
> + irq_num, list_num, false);
> +}
> +
> +static void clear_irqs(struct vip_dev *dev, int irq_num, int list_num)
> +{
> + struct vip_parser_data *parser = dev->parser;
> + u32 reg_addr = VIP_INT0_STATUS0_CLR +
> + VIP_INTC_INTX_OFFSET * irq_num;
> + u32 irq_val = (1 << (list_num * 2)) |
> + (VIP_VIP1_PARSER_INT << (irq_num * 1));
> +
> + /* Clear all Parser Interrupt */
> + reg_write(parser, VIP_PARSER_FIQ_CLR, 0xffffffff);
> + reg_write(parser, VIP_PARSER_FIQ_CLR, 0x0);
> +
> + reg_write(dev->shared, reg_addr, irq_val);
> +
> + vpdma_clear_list_stat(dev->shared->vpdma, irq_num, dev->slice_id);
> +}
> +
> +static void populate_desc_list(struct vip_stream *stream)
> +{
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + unsigned int list_length;
> +
> + stream->desc_next = stream->desc_list.buf.addr;
> + add_stream_dtds(stream);
> +
> + list_length = stream->desc_next - stream->desc_list.buf.addr;
> + vpdma_map_desc_buf(dev->shared->vpdma, &stream->desc_list.buf);
> +}
> +
> +/*
> + * start_dma - adds descriptors to the dma list and submits them.
> + * Should be called after a new vb is queued and on a vpdma list
> + * completion interrupt.
> + */
> +static void start_dma(struct vip_stream *stream, struct vip_buffer *buf)
> +{
> + struct vip_dev *dev = stream->port->dev;
> + struct vpdma_data *vpdma = dev->shared->vpdma;
> + int list_num = stream->list_num;
> + dma_addr_t dma_addr;
> + int drop_data;
> +
> + if (vpdma_list_busy(vpdma, list_num)) {
> + vip_err(stream, "vpdma list busy, cannot post\n");
> + return; /* nothing to do */
> + }
> +
> + if (buf) {
> + dma_addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
> + drop_data = 0;
> + vip_dbg(4, stream, "%s: vb2 buf idx:%d, dma_addr:%pad\n",
> + __func__, buf->vb.vb2_buf.index, &dma_addr);
> + } else {
> + dma_addr = 0;
> + drop_data = 1;
> + vip_dbg(4, stream, "%s: dropped\n", __func__);
> + }
> +
> + vpdma_update_dma_addr(dev->shared->vpdma, &stream->desc_list,
> + dma_addr, stream->write_desc, drop_data, 0);
> +
> + if (stream->port->fmt->coplanar) {
> + dma_addr += stream->bytesperline * stream->height;
> + vpdma_update_dma_addr(dev->shared->vpdma, &stream->desc_list,
> + dma_addr, stream->write_desc + 1,
> + drop_data, 1);
> + }
> +
> + vpdma_submit_descs(dev->shared->vpdma,
> + &stream->desc_list, stream->list_num);
> +}
> +
> +static void vip_schedule_next_buffer(struct vip_stream *stream)
> +{
> + struct vip_dev *dev = stream->port->dev;
> + struct vip_buffer *buf;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&dev->slock, flags);
> + if (list_empty(&stream->vidq)) {
> + vip_dbg(4, stream, "Dropping frame\n");
> + if (list_empty(&stream->dropq)) {
> + vip_err(stream, "No dropq buffer left!");
> + spin_unlock_irqrestore(&dev->slock, flags);
> + return;
> + }
> + buf = list_entry(stream->dropq.next,
> + struct vip_buffer, list);
> +
> + buf->drop = true;
> + list_move_tail(&buf->list, &stream->post_bufs);
> + buf = NULL;
> + } else {
> + buf = list_entry(stream->vidq.next,
> + struct vip_buffer, list);
> + buf->drop = false;
> + list_move_tail(&buf->list, &stream->post_bufs);
> + vip_dbg(4, stream, "added next buffer\n");
> + }
> +
> + spin_unlock_irqrestore(&dev->slock, flags);
> + start_dma(stream, buf);
> +}
> +
> +static void vip_process_buffer_complete(struct vip_stream *stream)
> +{
> + struct vip_dev *dev = stream->port->dev;
> + struct vip_buffer *buf;
> + struct vb2_v4l2_buffer *vb = NULL;
> + unsigned long flags, fld;
> +
> + buf = list_first_entry(&stream->post_bufs, struct vip_buffer, list);
> +
> + if (stream->port->flags & FLAG_INTERLACED) {
> + vpdma_unmap_desc_buf(dev->shared->vpdma,
> + &stream->desc_list.buf);
> +
> + fld = dtd_get_field(stream->write_desc);
> + stream->field = fld ? V4L2_FIELD_BOTTOM : V4L2_FIELD_TOP;
> +
> + vpdma_map_desc_buf(dev->shared->vpdma, &stream->desc_list.buf);
> + }
> +
> + if (buf) {
> + vip_dbg(4, stream, "vip buffer complete 0x%x, 0x%x\n",
> + (unsigned int)buf, buf->drop);
> +
> + vb = &buf->vb;
> + vb->field = stream->field;
> + vb->sequence = stream->sequence;
> + vb->vb2_buf.timestamp = ktime_get_ns();
> +
> + if (buf->drop) {
> + spin_lock_irqsave(&dev->slock, flags);
> + list_move_tail(&buf->list, &stream->dropq);
> + spin_unlock_irqrestore(&dev->slock, flags);
> + } else {
> + spin_lock_irqsave(&dev->slock, flags);
> + list_del(&buf->list);
> + spin_unlock_irqrestore(&dev->slock, flags);
> + vb2_buffer_done(&vb->vb2_buf, VB2_BUF_STATE_DONE);
> + }
> + } else {
> + vip_err(stream, "%s: buf is null!!!\n", __func__);
> + return;
> + }
> +
> + stream->sequence++;
> +}
> +
> +static int vip_reset_vpdma(struct vip_stream *stream)
> +{
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + struct vip_buffer *buf;
> + unsigned long flags;
> +
> + stop_dma(stream, false);
> +
> + spin_lock_irqsave(&dev->slock, flags);
> + /* requeue all active buffers in the opposite order */
> + while (!list_empty(&stream->post_bufs)) {
> + buf = list_last_entry(&stream->post_bufs,
> + struct vip_buffer, list);
> + list_del(&buf->list);
> + if (buf->drop == 1) {
> + list_add_tail(&buf->list, &stream->dropq);
> + vip_dbg(4, stream, "requeueing drop buffer on dropq\n");
> + } else {
> + list_add(&buf->list, &stream->vidq);
> + vip_dbg(4, stream, "requeueing vb2 buf idx:%d on vidq\n",
> + buf->vb.vb2_buf.index);
> + }
> + }
> + spin_unlock_irqrestore(&dev->slock, flags);
> +
> + /* Make sure the desc_list is unmapped */
> + vpdma_unmap_desc_buf(dev->shared->vpdma, &stream->desc_list.buf);
> +
> + return 0;
> +}
> +
> +static void vip_overflow_recovery_work(struct work_struct *work)
This function requires some additional comments about when it should
be called and what it does. Recovery is always tricky, and so it is
worthwhile spending additional time on commenting it.
> +{
> + struct vip_stream *stream = container_of(work, struct vip_stream,
> + recovery_work);
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> +
> + vip_err(stream, "%s: Port %c\n", __func__,
> + port->port_id == VIP_PORTA ? 'A' : 'B');
> +
> + disable_irqs(dev, dev->slice_id, stream->list_num);
> + clear_irqs(dev, dev->slice_id, stream->list_num);
> +
> + /* 1. Set VIP_XTRA6_PORT_A[31:16] YUV_SRCNUM_STOP_IMMEDIATELY */
> + /* 2. Set VIP_XTRA6_PORT_A[15:0] ANC_SRCNUM_STOP_IMMEDIATELY */
> + vip_parser_stop_imm(port, 1);
> +
> + /* 3. Clear VIP_PORT_A[8] ENABLE */
> + /*
> + * 4. Set VIP_PORT_A[7] CLR_ASYNC_FIFO_RD
> + * Set VIP_PORT_A[6] CLR_ASYNC_FIFO_WR
> + */
> + vip_enable_parser(port, false);
> +
> + /* 5. Set VIP_PORT_A[23] SW_RESET */
> + vip_reset_parser(port, 1);
> +
> + /*
> + * 6. Reset other VIP modules
> + * For each module used downstream of VIP_PARSER, write 1 to the
> + * bit location of the VIP_CLKC_RST register which is connected
> + * to VIP_PARSER
> + */
> + vip_module_reset(dev, VIP_DP_RST, true);
> +
> + usleep_range(200, 250);
> +
> + /*
> + * 7. Abort VPDMA channels
> + * Write to list attribute to stop list 0
> + * Write to list address register location of abort list
> + * Write to list attribute register list 0 and size of abort list
> + */
> + vip_reset_vpdma(stream);
> +
> + /* 8. Clear VIP_PORT_A[23] SW_RESET */
> + vip_reset_parser(port, 0);
> +
> + /*
> + * 9. Un-reset other VIP modules
> + * For each module used downstream of VIP_PARSER, write 0 to
> + * the bit location of the VIP_CLKC_RST register which is
> + * connected to VIP_PARSER
> + */
> + vip_module_reset(dev, VIP_DP_RST, false);
> +
> + /* 10. (Delay) */
> + /* 11. SC coeff downloaded (if VIP_SCALER is being used) */
> + vip_setup_scaler(stream);
> +
> + /* 12. (Delay) */
> + /* the above are not needed here yet */
> +
> + populate_desc_list(stream);
> + stream->num_recovery++;
> + if (stream->num_recovery < 5) {
> + /* Reload the vpdma */
> + vip_load_vpdma_list_fifo(stream);
> +
> + enable_irqs(dev, dev->slice_id, stream->list_num);
> + vip_schedule_next_buffer(stream);
> +
> + /* 13. Clear VIP_XTRA6_PORT_A[31:16] YUV_SRCNUM_STOP_IMM */
> + /* 14. Clear VIP_XTRA6_PORT_A[15:0] ANC_SRCNUM_STOP_IMM */
> +
> + vip_parser_stop_imm(port, 0);
> +
> + /* 15. Set VIP_PORT_A[8] ENABLE */
> + /*
> + * 16. Clear VIP_PORT_A[7] CLR_ASYNC_FIFO_RD
> + * Clear VIP_PORT_A[6] CLR_ASYNC_FIFO_WR
> + */
> + vip_enable_parser(port, true);
> + } else {
> + vip_err(stream, "%s: num_recovery limit exceeded leaving disabled\n",
> + __func__);
> + }
> +}
> +
> +static void handle_parser_irqs(struct vip_dev *dev)
> +{
> + struct vip_parser_data *parser = dev->parser;
> + struct vip_port *porta = dev->ports[VIP_PORTA];
> + struct vip_port *portb = dev->ports[VIP_PORTB];
> + struct vip_stream *stream = NULL;
> + u32 irq_stat = reg_read(parser, VIP_PARSER_FIQ_STATUS);
> + int i;
> +
> + vip_dbg(3, dev, "%s: FIQ_STATUS: 0x%08x\n", __func__, irq_stat);
> +
> + /* Clear all Parser Interrupt */
> + reg_write(parser, VIP_PARSER_FIQ_CLR, irq_stat);
> + reg_write(parser, VIP_PARSER_FIQ_CLR, 0x0);
> +
> + if (irq_stat & VIP_PORTA_VDET)
> + vip_dbg(3, dev, "VIP_PORTA_VDET\n");
> + if (irq_stat & VIP_PORTB_VDET)
> + vip_dbg(3, dev, "VIP_PORTB_VDET\n");
> + if (irq_stat & VIP_PORTA_ASYNC_FIFO_OF)
> + vip_err(dev, "VIP_PORTA_ASYNC_FIFO_OF\n");
> + if (irq_stat & VIP_PORTB_ASYNC_FIFO_OF)
> + vip_err(dev, "VIP_PORTB_ASYNC_FIFO_OF\n");
> + if (irq_stat & VIP_PORTA_OUTPUT_FIFO_YUV)
> + vip_err(dev, "VIP_PORTA_OUTPUT_FIFO_YUV\n");
> + if (irq_stat & VIP_PORTA_OUTPUT_FIFO_ANC)
> + vip_err(dev, "VIP_PORTA_OUTPUT_FIFO_ANC\n");
> + if (irq_stat & VIP_PORTB_OUTPUT_FIFO_YUV)
> + vip_err(dev, "VIP_PORTB_OUTPUT_FIFO_YUV\n");
> + if (irq_stat & VIP_PORTB_OUTPUT_FIFO_ANC)
> + vip_err(dev, "VIP_PORTB_OUTPUT_FIFO_ANC\n");
> + if (irq_stat & VIP_PORTA_CONN)
> + vip_dbg(3, dev, "VIP_PORTA_CONN\n");
> + if (irq_stat & VIP_PORTA_DISCONN)
> + vip_dbg(3, dev, "VIP_PORTA_DISCONN\n");
> + if (irq_stat & VIP_PORTB_CONN)
> + vip_dbg(3, dev, "VIP_PORTB_CONN\n");
> + if (irq_stat & VIP_PORTB_DISCONN)
> + vip_dbg(3, dev, "VIP_PORTB_DISCONN\n");
> + if (irq_stat & VIP_PORTA_SRC0_SIZE)
> + vip_dbg(3, dev, "VIP_PORTA_SRC0_SIZE\n");
> + if (irq_stat & VIP_PORTB_SRC0_SIZE)
> + vip_dbg(3, dev, "VIP_PORTB_SRC0_SIZE\n");
> + if (irq_stat & VIP_PORTA_YUV_PROTO_VIOLATION)
> + vip_dbg(3, dev, "VIP_PORTA_YUV_PROTO_VIOLATION\n");
> + if (irq_stat & VIP_PORTA_ANC_PROTO_VIOLATION)
> + vip_dbg(3, dev, "VIP_PORTA_ANC_PROTO_VIOLATION\n");
> + if (irq_stat & VIP_PORTB_YUV_PROTO_VIOLATION)
> + vip_dbg(3, dev, "VIP_PORTB_YUV_PROTO_VIOLATION\n");
> + if (irq_stat & VIP_PORTB_ANC_PROTO_VIOLATION)
> + vip_dbg(3, dev, "VIP_PORTB_ANC_PROTO_VIOLATION\n");
> + if (irq_stat & VIP_PORTA_CFG_DISABLE_COMPLETE)
> + vip_dbg(3, dev, "VIP_PORTA_CFG_DISABLE_COMPLETE\n");
> + if (irq_stat & VIP_PORTB_CFG_DISABLE_COMPLETE)
> + vip_dbg(3, dev, "VIP_PORTB_CFG_DISABLE_COMPLETE\n");
> +
> + if (irq_stat & (VIP_PORTA_ASYNC_FIFO_OF |
> + VIP_PORTA_OUTPUT_FIFO_YUV |
> + VIP_PORTA_OUTPUT_FIFO_ANC)) {
> + for (i = 0; i < VIP_CAP_STREAMS_PER_PORT; i++) {
> + if (porta->cap_streams[i] &&
> + porta->cap_streams[i]->port->port_id ==
> + porta->port_id) {
> + stream = porta->cap_streams[i];
> + break;
> + }
> + }
> + if (stream) {
> + disable_irqs(dev, dev->slice_id,
> + stream->list_num);
> + schedule_work(&stream->recovery_work);
> + return;
> + }
> + }
> + if (irq_stat & (VIP_PORTB_ASYNC_FIFO_OF |
> + VIP_PORTB_OUTPUT_FIFO_YUV |
> + VIP_PORTB_OUTPUT_FIFO_ANC)) {
> + for (i = 0; i < VIP_CAP_STREAMS_PER_PORT; i++) {
> + if (portb->cap_streams[i] &&
> + portb->cap_streams[i]->port->port_id ==
> + portb->port_id) {
> + stream = portb->cap_streams[i];
> + break;
> + }
> + }
> + if (stream) {
> + disable_irqs(dev, dev->slice_id,
> + stream->list_num);
> + schedule_work(&stream->recovery_work);
> + return;
> + }
> + }
> +}
> +
> +static irqreturn_t vip_irq(int irq_vip, void *data)
> +{
> + struct vip_dev *dev = (struct vip_dev *)data;
> + struct vpdma_data *vpdma;
> + struct vip_stream *stream;
> + int list_num;
> + int irq_num = dev->slice_id;
> + u32 irqst, irqst_saved, reg_addr;
> +
> + if (!dev->shared)
> + return IRQ_HANDLED;
> +
> + vpdma = dev->shared->vpdma;
> + reg_addr = VIP_INT0_STATUS0 +
> + VIP_INTC_INTX_OFFSET * irq_num;
> + irqst_saved = reg_read(dev->shared, reg_addr);
> + irqst = irqst_saved;
> +
> + vip_dbg(8, dev, "IRQ %d VIP_INT%d_STATUS0 0x%x\n",
> + irq_vip, irq_num, irqst);
> + if (irqst) {
> + if (irqst & (VIP_VIP1_PARSER_INT << (irq_num * 1))) {
> + irqst &= ~(VIP_VIP1_PARSER_INT << (irq_num * 1));
> + handle_parser_irqs(dev);
> + }
> +
> + for (list_num = 0; irqst && (list_num < 8); list_num++) {
> + /* Check for LIST_COMPLETE IRQ */
> + if (!(irqst & (1 << list_num * 2)))
> + continue;
> +
> + vip_dbg(8, dev, "IRQ %d: handling LIST%d_COMPLETE\n",
> + irq_num, list_num);
> +
> + stream = vpdma_hwlist_get_priv(vpdma, list_num);
> + if (!stream || stream->list_num != list_num) {
> + vip_err(dev, "IRQ occurred for unused list");
> + continue;
> + }
> +
> + vpdma_clear_list_stat(vpdma, irq_num, list_num);
> +
> + vip_process_buffer_complete(stream);
> +
> + vip_schedule_next_buffer(stream);
> +
> + irqst &= ~((1 << list_num * 2));
> + }
> + }
> +
> + /* Acknowledge that we are done with all interrupts */
> + reg_write(dev->shared, VIP_INTC_E0I, 1 << irq_num);
> +
> + /* Clear handled events from status register */
> + reg_addr = VIP_INT0_STATUS0_CLR +
> + VIP_INTC_INTX_OFFSET * irq_num;
> + reg_write(dev->shared, reg_addr, irqst_saved);
> +
> + return IRQ_HANDLED;
> +}
> +
> +/*
> + * video ioctls
> + */
> +static int vip_querycap(struct file *file, void *priv,
> + struct v4l2_capability *cap)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> +
> + strscpy(cap->driver, VIP_MODULE_NAME, sizeof(cap->driver));
> + strscpy(cap->card, VIP_MODULE_NAME, sizeof(cap->card));
> +
> + snprintf(cap->bus_info, sizeof(cap->bus_info),
> + "platform:%s:%s:stream%1d", dev->shared->name, port->name,
> + stream->stream_id);
> + return 0;
> +}
> +
> +static int vip_enuminput(struct file *file, void *priv,
> + struct v4l2_input *inp)
> +{
> + struct vip_stream *stream = file2stream(file);
> +
> + if (inp->index)
> + return -EINVAL;
> +
> + inp->type = V4L2_INPUT_TYPE_CAMERA;
> + inp->std = stream->vfd->tvnorms;
> + snprintf(inp->name, sizeof(inp->name), "camera %u", stream->vfd->num);
> +
> + return 0;
> +}
> +
> +static int vip_g_input(struct file *file, void *priv, unsigned int *i)
> +{
> + *i = 0;
> + return 0;
> +}
> +
> +static int vip_s_input(struct file *file, void *priv, unsigned int i)
> +{
> + if (i != 0)
> + return -EINVAL;
> + return 0;
> +}
> +
> +static int vip_querystd(struct file *file, void *fh, v4l2_std_id *std)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> +
> + *std = stream->vfd->tvnorms;
> + v4l2_subdev_call(port->subdev, video, querystd, std);
> + vip_dbg(1, stream, "querystd: 0x%lx\n", (unsigned long)*std);
> + return 0;
> +}
> +
> +static int vip_g_std(struct file *file, void *fh, v4l2_std_id *std)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> +
> + *std = stream->vfd->tvnorms;
> + v4l2_subdev_call(port->subdev, video, g_std_output, std);
g_std_output? Shouldn't this just be g_std? The g_std_output op is for
video transmitters.
> + vip_dbg(1, stream, "g_std: 0x%lx\n", (unsigned long)*std);
> +
> + return 0;
> +}
> +
> +static int vip_s_std(struct file *file, void *fh, v4l2_std_id std)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> +
> + vip_dbg(1, stream, "s_std: 0x%lx\n", (unsigned long)std);
> +
> + if (!(std & stream->vfd->tvnorms)) {
> + vip_dbg(1, stream, "s_std after check: 0x%lx\n",
> + (unsigned long)std);
> + return -EINVAL;
> + }
> +
> + v4l2_subdev_call(port->subdev, video, s_std_output, std);
Ditto.
> + return 0;
> +}
> +
> +static int vip_enum_fmt_vid_cap(struct file *file, void *priv,
> + struct v4l2_fmtdesc *f)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> + struct vip_fmt *fmt;
> +
> + vip_dbg(3, stream, "enum_fmt index:%d\n", f->index);
> + if (f->index >= port->num_active_fmt)
> + return -EINVAL;
> +
> + fmt = port->active_fmt[f->index];
> +
> + f->pixelformat = fmt->fourcc;
> + f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
No need to set the type field.
> + vip_dbg(3, stream, "enum_fmt fourcc:%s\n",
> + fourcc_to_str(f->pixelformat));
Excessive debugging.
> +
> + return 0;
> +}
> +
> +static int vip_enum_framesizes(struct file *file, void *priv,
> + struct v4l2_frmsizeenum *f)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> + struct vip_fmt *fmt;
> + struct v4l2_subdev_frame_size_enum fse;
> + int ret;
> +
> + fmt = find_port_format_by_pix(port, f->pixel_format);
> + if (!fmt)
> + return -EINVAL;
> +
> + fse.index = f->index;
> + fse.pad = port->source_pad;
> + fse.code = fmt->code;
> + fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> + ret = v4l2_subdev_call(port->subdev, pad, enum_frame_size, NULL, &fse);
> + if (ret == -ENOIOCTLCMD && !f->index) {
> + /*
> + * if subdev does not support enum_frame_size
> + * then use get_fmt
I don't think that's right. If the subdev doesn't support this, then
this ioctl should be disabled altogether. Typically this ioctl is only
valid for sensor subdevs, not for video receivers.
Use v4l2_subdev_has_op() and v4l2_disable_ioctl().
> + */
> + struct v4l2_subdev_format format = {
> + .which = V4L2_SUBDEV_FORMAT_ACTIVE,
> + .pad = port->source_pad,
> + };
> + ret = v4l2_subdev_call(port->subdev, pad, get_fmt, NULL,
> + &format);
> + if (ret)
> + return ret;
> +
> + fse.max_width = format.format.width;
> + fse.max_height = format.format.height;
> + } else if (ret) {
> + return -EINVAL;
> + }
> +
> + vip_dbg(1, stream, "%s: index: %d code: %x W:[%d,%d] H:[%d,%d]\n",
> + __func__, fse.index, fse.code, fse.min_width, fse.max_width,
> + fse.min_height, fse.max_height);
> +
> + f->type = V4L2_FRMSIZE_TYPE_DISCRETE;
> + f->discrete.width = fse.max_width;
> + f->discrete.height = fse.max_height;
> +
> + return 0;
> +}
> +
> +static int vip_enum_frameintervals(struct file *file, void *priv,
> + struct v4l2_frmivalenum *f)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> + struct vip_fmt *fmt;
> + struct v4l2_subdev_frame_interval_enum fie = {
> + .index = f->index,
> + .width = f->width,
> + .height = f->height,
> + .which = V4L2_SUBDEV_FORMAT_ACTIVE,
> + };
> + int ret;
> +
> + fmt = find_port_format_by_pix(port, f->pixel_format);
> + if (!fmt)
> + return -EINVAL;
> +
> + fie.code = fmt->code;
> + ret = v4l2_subdev_call(port->subdev, pad, enum_frame_interval,
> + NULL, &fie);
> + if (ret)
> + return ret;
> + f->type = V4L2_FRMIVAL_TYPE_DISCRETE;
> + f->discrete = fie.interval;
Same here: disable this ioctl if the subdev doesn't support enum_frame_interval.
> +
> + return 0;
> +}
> +
> +static int vip_g_parm(struct file *file, void *priv,
> + struct v4l2_streamparm *parm)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> +
> + return v4l2_g_parm_cap(stream->vfd, port->subdev, parm);
> +}
> +
> +static int vip_s_parm(struct file *file, void *priv,
> + struct v4l2_streamparm *parm)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> +
> + return v4l2_s_parm_cap(stream->vfd, port->subdev, parm);
Same here: typically this is not supported for video receivers.
> +}
> +
> +static int vip_calc_format_size(struct vip_port *port,
> + struct vip_fmt *fmt,
> + struct v4l2_format *f)
> +{
> + enum v4l2_field *field;
> + unsigned int stride;
> +
> + if (!fmt) {
> + vip_dbg(2, port,
> + "no vip_fmt format provided!\n");
> + return -EINVAL;
> + }
> +
> + field = &f->fmt.pix.field;
> + if (*field == V4L2_FIELD_ANY)
> + *field = V4L2_FIELD_NONE;
> + else if (V4L2_FIELD_NONE != *field && V4L2_FIELD_ALTERNATE != *field)
> + return -EINVAL;
> +
> + v4l_bound_align_image(&f->fmt.pix.width, MIN_W, MAX_W, W_ALIGN,
> + &f->fmt.pix.height, MIN_H, MAX_H, H_ALIGN,
> + S_ALIGN);
> +
> + stride = f->fmt.pix.width * (fmt->vpdma_fmt[0]->depth >> 3);
> + if (stride > f->fmt.pix.bytesperline)
> + f->fmt.pix.bytesperline = stride;
> +
> + f->fmt.pix.bytesperline = clamp_t(u32, f->fmt.pix.bytesperline,
> + stride, VPDMA_MAX_STRIDE);
> + f->fmt.pix.bytesperline = ALIGN(f->fmt.pix.bytesperline,
> + VPDMA_STRIDE_ALIGN);
> +
> + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
> + if (fmt->coplanar) {
> + f->fmt.pix.sizeimage += f->fmt.pix.height *
> + f->fmt.pix.bytesperline *
> + fmt->vpdma_fmt[VIP_CHROMA]->depth >> 3;
> + }
> +
> + f->fmt.pix.colorspace = fmt->colorspace;
> + f->fmt.pix.priv = 0;
No need to set this.
> +
> + vip_dbg(3, port, "calc_format_size: fourcc:%s size: %dx%d bpl:%d img_size:%d\n",
> + fourcc_to_str(f->fmt.pix.pixelformat),
> + f->fmt.pix.width, f->fmt.pix.height,
> + f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
> +
> + return 0;
> +}
> +
> +static inline bool vip_is_size_dma_aligned(u32 bpp, u32 width)
> +{
> + return ((width * bpp) == ALIGN(width * bpp, VPDMA_STRIDE_ALIGN));
> +}
> +
> +static int vip_try_fmt_vid_cap(struct file *file, void *priv,
> + struct v4l2_format *f)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> + struct v4l2_subdev_frame_size_enum fse;
> + struct vip_fmt *fmt;
> + u32 best_width, best_height, largest_width, largest_height;
> + int ret, found;
> + enum vip_csc_state csc_direction;
> +
> + vip_dbg(3, stream, "try_fmt fourcc:%s size: %dx%d\n",
> + fourcc_to_str(f->fmt.pix.pixelformat),
> + f->fmt.pix.width, f->fmt.pix.height);
> +
> + fmt = find_port_format_by_pix(port, f->fmt.pix.pixelformat);
> + if (!fmt) {
> + vip_dbg(2, stream,
> + "Fourcc format (0x%08x) not found.\n",
> + f->fmt.pix.pixelformat);
> +
> + /* Just get the first one enumerated */
> + fmt = port->active_fmt[0];
> + f->fmt.pix.pixelformat = fmt->fourcc;
> + }
> +
> + csc_direction = vip_csc_direction(fmt->code, fmt->finfo);
> + if (csc_direction != VIP_CSC_NA) {
> + if (!is_csc_available(port)) {
> + vip_dbg(2, stream,
> + "CSC not available for Fourcc format (0x%08x).\n",
> + f->fmt.pix.pixelformat);
> +
> + /* Just get the first one enumerated */
> + fmt = port->active_fmt[0];
> + f->fmt.pix.pixelformat = fmt->fourcc;
> + /* re-evaluate the csc_direction here */
> + csc_direction = vip_csc_direction(fmt->code,
> + fmt->finfo);
> + } else {
> + vip_dbg(3, stream, "CSC active on Port %c: going %s\n",
> + port->port_id == VIP_PORTA ? 'A' : 'B',
> + (csc_direction == VIP_CSC_Y2R) ? "Y2R" : "R2Y");
> + }
> + }
> +
> + /*
> + * Given that sensors might support multiple mbus code we need
> + * to use the one that matches the requested pixel format
> + */
> + port->try_mbus_framefmt = port->mbus_framefmt;
> + port->try_mbus_framefmt.code = fmt->code;
> +
> + /* check for/find a valid width/height */
> + ret = 0;
> + found = false;
> + best_width = 0;
> + best_height = 0;
> + largest_width = 0;
> + largest_height = 0;
> + fse.pad = port->source_pad;
> + fse.code = fmt->code;
> + fse.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> + for (fse.index = 0; ; fse.index++) {
> + u32 bpp = fmt->vpdma_fmt[0]->depth >> 3;
> +
> + ret = v4l2_subdev_call(port->subdev, pad,
> + enum_frame_size, NULL, &fse);
> + if (ret == -ENOIOCTLCMD) {
> + /*
> + * if subdev does not support enum_frame_size
> + * then just try to set_fmt directly
> + */
> + struct v4l2_subdev_format format = {
> + .which = V4L2_SUBDEV_FORMAT_TRY,
> + };
> + struct v4l2_subdev_pad_config *pad_cfg;
> +
> + pad_cfg = v4l2_subdev_alloc_pad_config(port->subdev);
> + if (!pad_cfg)
> + return -ENOMEM;
> +
> + v4l2_fill_mbus_format(&format.format, &f->fmt.pix,
> + fmt->code);
> + ret = v4l2_subdev_call(port->subdev, pad, set_fmt,
> + pad_cfg, &format);
> + if (ret)
> + /* here regardless of the reason we give up */
> + break;
> +
> + if (f->fmt.pix.width == format.format.width &&
> + f->fmt.pix.height == format.format.height) {
> + found = true;
> + vip_dbg(3, stream, "try_fmt loop:%d found direct match: %dx%d\n",
> + fse.index, format.format.width,
> + format.format.height);
> + }
> + largest_width = format.format.width;
> + largest_height = format.format.height;
> + best_width = format.format.width;
> + best_height = format.format.height;
> +
> + v4l2_subdev_free_pad_config(pad_cfg);
> + break;
> +
> + } else if (ret) {
> + break;
> + }
> +
> + vip_dbg(3, stream, "try_fmt loop:%d fourcc:%s size: %dx%d\n",
> + fse.index, fourcc_to_str(f->fmt.pix.pixelformat),
> + fse.max_width, fse.max_height);
> +
> + if (!vip_is_size_dma_aligned(bpp, fse.max_width))
> + continue;
> +
> + if ((fse.max_width >= largest_width) &&
> + (fse.max_height >= largest_height)) {
> + vip_dbg(3, stream, "try_fmt loop:%d found new larger: %dx%d\n",
> + fse.index, fse.max_width, fse.max_height);
> + largest_width = fse.max_width;
> + largest_height = fse.max_height;
> + }
> +
> + if ((fse.max_width >= f->fmt.pix.width) &&
> + (fse.max_height >= f->fmt.pix.height)) {
> + vip_dbg(3, stream, "try_fmt loop:%d found at least larger: %dx%d\n",
> + fse.index, fse.max_width, fse.max_height);
> +
> + if (!best_width ||
> + ((abs(best_width - f->fmt.pix.width) >=
> + abs(fse.max_width - f->fmt.pix.width)) &&
> + (abs(best_height - f->fmt.pix.height) >=
> + abs(fse.max_height - f->fmt.pix.height)))) {
> + best_width = fse.max_width;
> + best_height = fse.max_height;
> + vip_dbg(3, stream, "try_fmt loop:%d found new best: %dx%d\n",
> + fse.index, fse.max_width,
> + fse.max_height);
> + }
> + }
> +
> + if ((f->fmt.pix.width == fse.max_width) &&
> + (f->fmt.pix.height == fse.max_height)) {
> + found = true;
> + vip_dbg(3, stream, "try_fmt loop:%d found direct match: %dx%d\n",
> + fse.index, fse.max_width,
> + fse.max_height);
> + break;
> + }
> +
> + if ((f->fmt.pix.width >= fse.min_width) &&
> + (f->fmt.pix.width <= fse.max_width) &&
> + (f->fmt.pix.height >= fse.min_height) &&
> + (f->fmt.pix.height <= fse.max_height)) {
> + found = true;
> + vip_dbg(3, stream, "try_fmt loop:%d found direct range match: %dx%d\n",
> + fse.index, fse.max_width,
> + fse.max_height);
> + break;
> + }
> + }
> +
> + if (found) {
> + port->try_mbus_framefmt.width = f->fmt.pix.width;
> + port->try_mbus_framefmt.height = f->fmt.pix.height;
> + /* No need to check for scaling */
> + goto calc_size;
> + } else if (largest_width && f->fmt.pix.width > largest_width) {
> + port->try_mbus_framefmt.width = largest_width;
> + port->try_mbus_framefmt.height = largest_height;
> + } else if (best_width) {
> + port->try_mbus_framefmt.width = best_width;
> + port->try_mbus_framefmt.height = best_height;
> + } else {
> + /* use existing values as default */
> + }
> +
> + vip_dbg(3, stream, "try_fmt best subdev size: %dx%d\n",
> + port->try_mbus_framefmt.width,
> + port->try_mbus_framefmt.height);
> +
> + if (is_scaler_available(port) &&
> + csc_direction != VIP_CSC_Y2R &&
> + !vip_is_mbuscode_raw(fmt->code) &&
> + f->fmt.pix.height <= port->try_mbus_framefmt.height &&
> + port->try_mbus_framefmt.height <= SC_MAX_PIXEL_HEIGHT &&
> + port->try_mbus_framefmt.width <= SC_MAX_PIXEL_WIDTH) {
> + /*
> + * Scaler is only accessible if the dst colorspace is YUV.
> + * As the input to the scaler must be in YUV mode only.
> + *
> + * Scaling up is allowed only horizontally.
> + */
> + unsigned int hratio, vratio, width_align, height_align;
> + u32 bpp = fmt->vpdma_fmt[0]->depth >> 3;
> +
> + vip_dbg(3, stream, "Scaler active on Port %c: requesting %dx%d\n",
> + port->port_id == VIP_PORTA ? 'A' : 'B',
> + f->fmt.pix.width, f->fmt.pix.height);
> +
> + /* Just make sure everything is properly aligned */
> + width_align = ALIGN(f->fmt.pix.width * bpp, VPDMA_STRIDE_ALIGN);
> + width_align /= bpp;
> + height_align = ALIGN(f->fmt.pix.height, 2);
> +
> + f->fmt.pix.width = width_align;
> + f->fmt.pix.height = height_align;
> +
> + hratio = f->fmt.pix.width * 1000 /
> + port->try_mbus_framefmt.width;
> + vratio = f->fmt.pix.height * 1000 /
> + port->try_mbus_framefmt.height;
> + if (hratio < 125) {
> + f->fmt.pix.width = port->try_mbus_framefmt.width / 8;
> + vip_dbg(3, stream, "Horizontal scaling ratio out of range adjusting -> %d\n",
> + f->fmt.pix.width);
> + }
> +
> + if (vratio < 188) {
> + f->fmt.pix.height = port->try_mbus_framefmt.height / 4;
> + vip_dbg(3, stream, "Vertical scaling ratio out of range adjusting -> %d\n",
> + f->fmt.pix.height);
> + }
> + vip_dbg(3, stream, "Scaler: got %dx%d\n",
> + f->fmt.pix.width, f->fmt.pix.height);
> + } else {
> + /* use existing values as default */
> + f->fmt.pix.width = port->try_mbus_framefmt.width;
> + f->fmt.pix.height = port->try_mbus_framefmt.height;
> + }
> +
> +calc_size:
> + /* That we have a fmt calculate imagesize and bytesperline */
> + return vip_calc_format_size(port, fmt, f);
> +}
> +
> +static int vip_g_fmt_vid_cap(struct file *file, void *priv,
> + struct v4l2_format *f)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> + struct vip_fmt *fmt = port->fmt;
> +
> + /* Use last known values or defaults */
> + f->fmt.pix.width = stream->width;
> + f->fmt.pix.height = stream->height;
> + f->fmt.pix.pixelformat = port->fmt->fourcc;
> + f->fmt.pix.field = stream->sup_field;
> + f->fmt.pix.colorspace = port->fmt->colorspace;
> + f->fmt.pix.bytesperline = stream->bytesperline;
> + f->fmt.pix.sizeimage = stream->sizeimage;
> +
> + vip_dbg(3, stream,
> + "g_fmt fourcc:%s code: %04x size: %dx%d bpl:%d img_size:%d\n",
> + fourcc_to_str(f->fmt.pix.pixelformat),
> + fmt->code,
> + f->fmt.pix.width, f->fmt.pix.height,
> + f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
> + vip_dbg(3, stream, "g_fmt vpdma data type: 0x%02X\n",
> + port->fmt->vpdma_fmt[0]->data_type);
> +
> + return 0;
> +}
> +
> +static int vip_s_fmt_vid_cap(struct file *file, void *priv,
> + struct v4l2_format *f)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct vip_port *port = stream->port;
> + struct v4l2_subdev_format sfmt;
> + struct v4l2_mbus_framefmt *mf;
> + enum vip_csc_state csc_direction;
> + int ret;
> +
> + vip_dbg(3, stream, "s_fmt input fourcc:%s size: %dx%d bpl:%d img_size:%d\n",
> + fourcc_to_str(f->fmt.pix.pixelformat),
> + f->fmt.pix.width, f->fmt.pix.height,
> + f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
> +
> + ret = vip_try_fmt_vid_cap(file, priv, f);
> + if (ret)
> + return ret;
> +
> + vip_dbg(3, stream, "s_fmt try_fmt fourcc:%s size: %dx%d bpl:%d img_size:%d\n",
> + fourcc_to_str(f->fmt.pix.pixelformat),
> + f->fmt.pix.width, f->fmt.pix.height,
> + f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
> +
> + if (vb2_is_busy(&stream->vb_vidq)) {
> + vip_err(stream, "%s queue busy\n", __func__);
> + return -EBUSY;
> + }
> +
> + /*
> + * Check if we need the scaler or not
> + *
> + * Since on previous S_FMT call the scaler might have been
> + * allocated if it is not needed in this instance we will
> + * attempt to free it just in case.
> + *
> + * free_scaler() is harmless unless the current port
> + * allocated it.
> + */
> + if (f->fmt.pix.width == port->try_mbus_framefmt.width &&
> + f->fmt.pix.height == port->try_mbus_framefmt.height)
> + free_scaler(port);
> + else
> + allocate_scaler(port);
> +
> + port->fmt = find_port_format_by_pix(port,
> + f->fmt.pix.pixelformat);
> + stream->width = f->fmt.pix.width;
> + stream->height = f->fmt.pix.height;
> + stream->bytesperline = f->fmt.pix.bytesperline;
> + stream->sizeimage = f->fmt.pix.sizeimage;
> + stream->sup_field = f->fmt.pix.field;
> + stream->field = f->fmt.pix.field;
> +
> + port->c_rect.left = 0;
> + port->c_rect.top = 0;
> + port->c_rect.width = stream->width;
> + port->c_rect.height = stream->height;
> +
> + /*
> + * Check if we need the csc unit or not
> + *
> + * Since on previous S_FMT call, the csc might have been
> + * allocated if it is not needed in this instance we will
> + * attempt to free it just in case.
> + *
> + * free_csc() is harmless unless the current port
> + * allocated it.
> + */
> + csc_direction = vip_csc_direction(port->fmt->code, port->fmt->finfo);
> + if (csc_direction == VIP_CSC_NA)
> + free_csc(port);
> + else
> + allocate_csc(port, csc_direction);
> +
> + if (stream->sup_field == V4L2_FIELD_ALTERNATE)
> + port->flags |= FLAG_INTERLACED;
> + else
> + port->flags &= ~FLAG_INTERLACED;
> +
> + vip_dbg(3, stream, "s_fmt fourcc:%s size: %dx%d bpl:%d img_size:%d\n",
> + fourcc_to_str(f->fmt.pix.pixelformat),
> + f->fmt.pix.width, f->fmt.pix.height,
> + f->fmt.pix.bytesperline, f->fmt.pix.sizeimage);
> +
> + mf = &sfmt.format;
> + v4l2_fill_mbus_format(mf, &f->fmt.pix, port->fmt->code);
> + /* Make sure to use the subdev size found in the try_fmt */
> + mf->width = port->try_mbus_framefmt.width;
> + mf->height = port->try_mbus_framefmt.height;
> +
> + vip_dbg(3, stream, "s_fmt pix_to_mbus mbus_code: %04X size: %dx%d\n",
> + mf->code,
> + mf->width, mf->height);
> +
> + sfmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> + sfmt.pad = port->source_pad;
> + ret = v4l2_subdev_call(port->subdev, pad, set_fmt, NULL, &sfmt);
> + if (ret) {
> + vip_dbg(1, stream, "set_fmt failed in subdev\n");
> + return ret;
> + }
> +
> + /* Save it */
> + port->mbus_framefmt = *mf;
> +
> + vip_dbg(3, stream, "s_fmt subdev fmt mbus_code: %04X size: %dx%d\n",
> + port->mbus_framefmt.code,
> + port->mbus_framefmt.width, port->mbus_framefmt.height);
> + vip_dbg(3, stream, "s_fmt vpdma data type: 0x%02X\n",
> + port->fmt->vpdma_fmt[0]->data_type);
> +
> + return 0;
> +}
> +
> +/*
> + * Does the exact opposite of set_fmt_params
> + * It makes sure the DataPath register is sane after tear down
> + */
> +static void unset_fmt_params(struct vip_stream *stream)
> +{
> + struct vip_dev *dev = stream->port->dev;
> + struct vip_port *port = stream->port;
> +
> + stream->sequence = 0;
> + if (stream->port->flags & FLAG_INTERLACED)
> + stream->field = V4L2_FIELD_TOP;
> +
> + if (port->csc == VIP_CSC_Y2R) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev, VIP_CSC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_RGB_SRC_DATA_SELECT, 0);
> + } else {
> + vip_set_slice_path(dev, VIP_CSC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + }
> + /* We are done */
> + return;
> + } else if (port->csc == VIP_CSC_R2Y) {
> + if (port->scaler && port->fmt->coplanar) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_SC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + }
> + } else if (port->scaler) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_SC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + }
> + } else if (port->fmt->coplanar) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + }
> + } else {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + }
> + }
> + /* We are done */
> + return;
> + } else if (v4l2_is_format_rgb(port->fmt->finfo)) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + }
> + /* We are done */
> + return;
> + }
> +
> + if (port->scaler && port->fmt->coplanar) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + } else {
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_2_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + }
> + } else if (port->scaler) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + } else {
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_2_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_CHR_DS_2_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + }
> + } else if (port->fmt->coplanar) {
> + if (port->port_id == VIP_PORTA) {
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + } else {
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_2_SRC_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_CHR_DS_2_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + }
> + } else {
> + /*
> + * We undo all data path setting except for the multi
> + * stream case.
> + * Because we cannot disrupt other on-going capture if only
> + * one stream is terminated the other might still be going
> + */
> + vip_set_slice_path(dev, VIP_MULTI_CHANNEL_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + }
> +}
> +
> +/*
> + * Set the registers that are modified when the video format changes.
> + */
> +static void set_fmt_params(struct vip_stream *stream)
> +{
Hmm, this is a *very* long function. Perhaps this could be split up a bit,
or reorganized?
> + struct vip_dev *dev = stream->port->dev;
> + struct vip_port *port = stream->port;
> +
> + stream->sequence = 0;
> + if (stream->port->flags & FLAG_INTERLACED)
> + stream->field = V4L2_FIELD_TOP;
> +
> + if (port->csc == VIP_CSC_Y2R) {
> + port->flags &= ~FLAG_MULT_PORT;
> + /* Set alpha component in background color */
> + vpdma_set_bg_color(dev->shared->vpdma,
> + (struct vpdma_data_format *)
> + port->fmt->vpdma_fmt[0],
> + 0xff);
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: YUV422
> + * Output: Y_UP/UV_UP: RGB
> + * CSC_SRC_SELECT = 1
> + * RGB_OUT_HI_SELECT = 1
> + * RGB_SRC_SELECT = 1
> + * MULTI_CHANNEL_SELECT = 0
It's a bit pointless to comment what the register values should be when you
set them in the code below. I'd drop that part, it will make the code
shorter.
> + */
> + vip_set_slice_path(dev, VIP_CSC_SRC_DATA_SELECT, 1);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
For readability purposes I think it is better to keep this on one line. Same for
the other vip_set_slice_path calls.
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_RGB_SRC_DATA_SELECT, 1);
> + } else {
> + /*
> + * Input B: YUV422
> + * Output: Y_UP/UV_UP: RGB
> + * CSC_SRC_SELECT = 2
> + * RGB_OUT_LO_SELECT = 1
> + * MULTI_CHANNEL_SELECT = 0
> + */
> + vip_set_slice_path(dev, VIP_CSC_SRC_DATA_SELECT, 2);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 1);
> + }
> + /* We are done */
> + return;
> + } else if (port->csc == VIP_CSC_R2Y) {
> + port->flags &= ~FLAG_MULT_PORT;
> + if (port->scaler && port->fmt->coplanar) {
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: RGB
> + * Output: Y_UP/UV_UP: Scaled YUV420
> + * CSC_SRC_SELECT = 4
> + * SC_SRC_SELECT = 1
> + * CHR_DS_1_SRC_SELECT = 1
> + * CHR_DS_1_BYPASS = 0
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 4);
> + vip_set_slice_path(dev,
> + VIP_SC_SRC_DATA_SELECT, 1);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 1);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + } else {
> + vip_err(stream, "RGB sensor can only be on Port A\n");
> + }
> + } else if (port->scaler) {
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: RGB
> + * Output: Y_UP: Scaled YUV422
> + * CSC_SRC_SELECT = 4
> + * SC_SRC_SELECT = 1
> + * CHR_DS_1_SRC_SELECT = 1
> + * CHR_DS_1_BYPASS = 1
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 4);
> + vip_set_slice_path(dev,
> + VIP_SC_SRC_DATA_SELECT, 1);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 1);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 1);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + } else {
> + vip_err(stream, "RGB sensor can only be on Port A\n");
> + }
> + } else if (port->fmt->coplanar) {
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: RGB
> + * Output: Y_UP/UV_UP: YUV420
> + * CSC_SRC_SELECT = 4
> + * CHR_DS_1_SRC_SELECT = 2
> + * CHR_DS_1_BYPASS = 0
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 4);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 2);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + } else {
> + vip_err(stream, "RGB sensor can only be on Port A\n");
> + }
> + } else {
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: RGB
> + * Output: Y_UP/UV_UP: YUV420
> + * CSC_SRC_SELECT = 4
> + * CHR_DS_1_SRC_SELECT = 2
> + * CHR_DS_1_BYPASS = 1
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev,
> + VIP_CSC_SRC_DATA_SELECT, 4);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + 2);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_DATA_BYPASS, 1);
> + vip_set_slice_path(dev,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + 0);
> + } else {
> + vip_err(stream, "RGB sensor can only be on Port A\n");
> + }
> + }
> + /* We are done */
> + return;
> + } else if (v4l2_is_format_rgb(port->fmt->finfo)) {
> + port->flags &= ~FLAG_MULT_PORT;
> + /* Set alpha component in background color */
> + vpdma_set_bg_color(dev->shared->vpdma,
> + (struct vpdma_data_format *)
> + port->fmt->vpdma_fmt[0],
> + 0xff);
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: RGB
> + * Output: Y_LO/UV_LO: RGB
> + * RGB_OUT_LO_SELECT = 1
> + * MULTI_CHANNEL_SELECT = 1
> + */
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 1);
> + } else {
> + vip_err(stream, "RGB sensor can only be on Port A\n");
> + }
> + /* We are done */
> + return;
> + }
> +
> + if (port->scaler && port->fmt->coplanar) {
> + port->flags &= ~FLAG_MULT_PORT;
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: YUV422
> + * Output: Y_UP/UV_UP: Scaled YUV420
> + * SC_SRC_SELECT = 2
> + * CHR_DS_1_SRC_SELECT = 1
> + * CHR_DS_1_BYPASS = 0
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 2);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + } else {
> + /*
> + * Input B: YUV422
> + * Output: Y_LO/UV_LO: Scaled YUV420
> + * SC_SRC_SELECT = 3
> + * CHR_DS_2_SRC_SELECT = 1
> + * RGB_OUT_LO_SELECT = 0
> + * MULTI_CHANNEL_SELECT = 0
> + */
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 3);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_2_SRC_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + }
> + } else if (port->scaler) {
> + port->flags &= ~FLAG_MULT_PORT;
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: YUV422
> + * Output: Y_UP: Scaled YUV422
> + * SC_SRC_SELECT = 2
> + * CHR_DS_1_SRC_SELECT = 1
> + * CHR_DS_1_BYPASS = 1
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 2);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 1);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + } else {
> + /*
> + * Input B: YUV422
> + * Output: UV_UP: Scaled YUV422
> + * SC_SRC_SELECT = 3
> + * CHR_DS_2_SRC_SELECT = 1
> + * CHR_DS_1_BYPASS = 1
> + * CHR_DS_2_BYPASS = 1
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev, VIP_SC_SRC_DATA_SELECT, 3);
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_2_SRC_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 1);
> + vip_set_slice_path(dev, VIP_CHR_DS_2_DATA_BYPASS, 1);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + }
> + } else if (port->fmt->coplanar) {
> + port->flags &= ~FLAG_MULT_PORT;
> + if (port->port_id == VIP_PORTA) {
> + /*
> + * Input A: YUV422
> + * Output: Y_UP/UV_UP: YUV420
> + * CHR_DS_1_SRC_SELECT = 3
> + * CHR_DS_1_BYPASS = 0
> + * RGB_OUT_HI_SELECT = 0
> + */
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_1_SRC_DATA_SELECT, 3);
> + vip_set_slice_path(dev, VIP_CHR_DS_1_DATA_BYPASS, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_HI_DATA_SELECT, 0);
> + } else {
> + /*
> + * Input B: YUV422
> + * Output: Y_LO/UV_LO: YUV420
> + * CHR_DS_2_SRC_SELECT = 4
> + * CHR_DS_2_BYPASS = 0
> + * RGB_OUT_LO_SELECT = 0
> + * MULTI_CHANNEL_SELECT = 0
> + */
> + vip_set_slice_path(dev,
> + VIP_CHR_DS_2_SRC_DATA_SELECT, 4);
> + vip_set_slice_path(dev, VIP_CHR_DS_2_DATA_BYPASS, 0);
> + vip_set_slice_path(dev,
> + VIP_MULTI_CHANNEL_DATA_SELECT, 0);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + }
> + } else {
> + port->flags |= FLAG_MULT_PORT;
> + /*
> + * Input A/B: YUV422
> + * Output: Y_LO: YUV422 - UV_LO: YUV422
> + * MULTI_CHANNEL_SELECT = 1
> + * RGB_OUT_LO_SELECT = 0
> + */
> + vip_set_slice_path(dev, VIP_MULTI_CHANNEL_DATA_SELECT, 1);
> + vip_set_slice_path(dev, VIP_RGB_OUT_LO_DATA_SELECT, 0);
> + }
> +}
> +
> +static int vip_g_selection(struct file *file, void *fh,
> + struct v4l2_selection *s)
> +{
> + struct vip_stream *stream = file2stream(file);
> +
> + if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
> + return -EINVAL;
> +
> + switch (s->target) {
> + case V4L2_SEL_TGT_COMPOSE_DEFAULT:
> + case V4L2_SEL_TGT_COMPOSE_BOUNDS:
> + case V4L2_SEL_TGT_CROP_BOUNDS:
> + case V4L2_SEL_TGT_CROP_DEFAULT:
> + s->r.left = 0;
> + s->r.top = 0;
> + s->r.width = stream->width;
> + s->r.height = stream->height;
> + return 0;
> +
> + case V4L2_SEL_TGT_COMPOSE:
> + case V4L2_SEL_TGT_CROP:
> + s->r = stream->port->c_rect;
> + return 0;
> + }
> +
> + return -EINVAL;
> +}
> +
> +static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
> +{
> + if (a->left < b->left || a->top < b->top)
> + return 0;
> + if (a->left + a->width > b->left + b->width)
> + return 0;
> + if (a->top + a->height > b->top + b->height)
> + return 0;
> +
> + return 1;
> +}
There are helper functions in include/media/v4l2-rect.h, it would make
sense to add this one to that header.
> +
> +static int vip_s_selection(struct file *file, void *fh,
> + struct v4l2_selection *s)
> +{
> + struct vip_stream *stream = file2stream(file);
> + struct v4l2_rect r = s->r;
> +
> + if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
> + return -EINVAL;
> +
> + switch (s->target) {
> + case V4L2_SEL_TGT_COMPOSE:
> + case V4L2_SEL_TGT_CROP:
Why both crop and compose when it is the same c_rect? That makes no sense.
> + v4l_bound_align_image(&r.width, 0, stream->width, 0,
> + &r.height, 0, stream->height, 0, 0);
> +
> + r.left = clamp_t(unsigned int, r.left, 0,
> + stream->width - r.width);
> + r.top = clamp_t(unsigned int, r.top, 0,
> + stream->height - r.height);
> +
> + if (s->flags & V4L2_SEL_FLAG_LE &&
> + !enclosed_rectangle(&r, &s->r))
> + return -ERANGE;
> +
> + if (s->flags & V4L2_SEL_FLAG_GE &&
> + !enclosed_rectangle(&s->r, &r))
> + return -ERANGE;
> +
> + s->r = r;
> + stream->port->c_rect = r;
> +
> + vip_dbg(1, stream, "cropped (%d,%d)/%dx%d of %dx%d\n",
> + r.left, r.top, r.width, r.height,
> + stream->width, stream->height);
> +
> + s->r = stream->port->c_rect;
> + return 0;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static long vip_ioctl_default(struct file *file, void *fh, bool valid_prio,
> + unsigned int cmd, void *arg)
> +{
> + struct vip_stream *stream = file2stream(file);
> +
> + if (!valid_prio) {
> + vip_err(stream, "%s device busy\n", __func__);
> + return -EBUSY;
> + }
> +
> + switch (cmd) {
> + default:
> + return -ENOTTY;
> + }
> +}
Huh?
> +
> +static const struct v4l2_ioctl_ops vip_ioctl_ops = {
> + .vidioc_querycap = vip_querycap,
> + .vidioc_enum_input = vip_enuminput,
> + .vidioc_g_input = vip_g_input,
> + .vidioc_s_input = vip_s_input,
> +
> + .vidioc_querystd = vip_querystd,
> + .vidioc_g_std = vip_g_std,
> + .vidioc_s_std = vip_s_std,
> +
> + .vidioc_enum_fmt_vid_cap = vip_enum_fmt_vid_cap,
> + .vidioc_g_fmt_vid_cap = vip_g_fmt_vid_cap,
> + .vidioc_try_fmt_vid_cap = vip_try_fmt_vid_cap,
> + .vidioc_s_fmt_vid_cap = vip_s_fmt_vid_cap,
> +
> + .vidioc_enum_frameintervals = vip_enum_frameintervals,
> + .vidioc_enum_framesizes = vip_enum_framesizes,
> + .vidioc_s_parm = vip_s_parm,
> + .vidioc_g_parm = vip_g_parm,
> + .vidioc_g_selection = vip_g_selection,
> + .vidioc_s_selection = vip_s_selection,
> + .vidioc_reqbufs = vb2_ioctl_reqbufs,
> + .vidioc_create_bufs = vb2_ioctl_create_bufs,
> + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
> + .vidioc_querybuf = vb2_ioctl_querybuf,
> + .vidioc_qbuf = vb2_ioctl_qbuf,
> + .vidioc_dqbuf = vb2_ioctl_dqbuf,
> + .vidioc_expbuf = vb2_ioctl_expbuf,
> +
> + .vidioc_streamon = vb2_ioctl_streamon,
> + .vidioc_streamoff = vb2_ioctl_streamoff,
> + .vidioc_log_status = v4l2_ctrl_log_status,
> + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
> + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
> + .vidioc_default = vip_ioctl_default,
> +};
> +
> +/*
> + * Videobuf operations
> + */
> +static int vip_queue_setup(struct vb2_queue *vq,
> + unsigned int *nbuffers, unsigned int *nplanes,
> + unsigned int sizes[], struct device *alloc_devs[])
> +{
> + struct vip_stream *stream = vb2_get_drv_priv(vq);
> + unsigned int size = stream->sizeimage;
> +
> + if (vq->num_buffers + *nbuffers < 3)
> + *nbuffers = 3 - vq->num_buffers;
> +
> + if (*nplanes) {
> + if (sizes[0] < size)
> + return -EINVAL;
> + size = sizes[0];
> + }
> +
> + *nplanes = 1;
> + sizes[0] = size;
> +
> + vip_dbg(1, stream, "get %d buffer(s) of size %d each.\n",
> + *nbuffers, sizes[0]);
> +
> + return 0;
> +}
> +
> +static int vip_buf_prepare(struct vb2_buffer *vb)
> +{
> + struct vip_stream *stream = vb2_get_drv_priv(vb->vb2_queue);
> +
> + if (vb2_plane_size(vb, 0) < stream->sizeimage) {
> + vip_dbg(1, stream,
> + "%s data will not fit into plane (%lu < %lu)\n",
> + __func__, vb2_plane_size(vb, 0),
> + (long)stream->sizeimage);
> + return -EINVAL;
> + }
> +
> + vb2_set_plane_payload(vb, 0, stream->sizeimage);
> +
> + return 0;
> +}
> +
> +static void vip_buf_queue(struct vb2_buffer *vb)
> +{
> + struct vip_stream *stream = vb2_get_drv_priv(vb->vb2_queue);
> + struct vip_dev *dev = stream->port->dev;
> + struct vip_buffer *buf = container_of(vb, struct vip_buffer,
> + vb.vb2_buf);
> + unsigned long flags;
> +
> + spin_lock_irqsave(&dev->slock, flags);
> + list_add_tail(&buf->list, &stream->vidq);
> + spin_unlock_irqrestore(&dev->slock, flags);
> +}
> +
> +static int vip_setup_scaler(struct vip_stream *stream)
> +{
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + struct sc_data *sc = dev->sc;
> + struct csc_data *csc = dev->csc;
> + struct vpdma_data *vpdma = dev->shared->vpdma;
> + struct vip_mmr_adb *mmr_adb = port->mmr_adb.addr;
> + int list_num = stream->list_num;
> + int timeout = 500;
> + struct v4l2_format dst_f;
> + struct v4l2_format src_f;
> +
> + memset(&src_f, 0, sizeof(src_f));
> + src_f.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> + v4l2_fill_pix_format(&src_f.fmt.pix, &port->mbus_framefmt);
> + src_f.fmt.pix.pixelformat = vip_mbus_code_to_fourcc(port->fmt->code);
> +
> + dst_f = src_f;
> + dst_f.fmt.pix.pixelformat = port->fmt->fourcc;
> + dst_f.fmt.pix.width = stream->width;
> + dst_f.fmt.pix.height = stream->height;
> +
> + /* if scaler not associated with this port then skip */
> + if (port->scaler) {
> + sc_set_hs_coeffs(sc, port->sc_coeff_h.addr,
> + port->mbus_framefmt.width,
> + port->c_rect.width);
> + sc_set_vs_coeffs(sc, port->sc_coeff_v.addr,
> + port->mbus_framefmt.height,
> + port->c_rect.height);
> + sc_config_scaler(sc, &mmr_adb->sc_regs0[0],
> + &mmr_adb->sc_regs8[0], &mmr_adb->sc_regs17[0],
> + port->mbus_framefmt.width,
> + port->mbus_framefmt.height,
> + port->c_rect.width,
> + port->c_rect.height);
> + port->load_mmrs = true;
> + }
> +
> + /* if csc not associated with this port then skip */
> + if (port->csc) {
> + csc_set_coeff(csc, &mmr_adb->csc_regs[0],
> + &src_f, &dst_f);
> +
> + port->load_mmrs = true;
> + }
> +
> + /* If coeff are already loaded then skip */
> + if (!sc->load_coeff_v && !sc->load_coeff_h && !port->load_mmrs)
> + return 0;
> +
> + if (vpdma_list_busy(vpdma, list_num)) {
> + vip_dbg(3, stream, "%s: List %d is busy\n",
> + __func__, list_num);
> + }
> +
> + /* Make sure we start with a clean list */
> + vpdma_reset_desc_list(&stream->desc_list);
> +
> + /* config descriptors */
> + if (port->load_mmrs) {
> + vpdma_map_desc_buf(vpdma, &port->mmr_adb);
> + vpdma_add_cfd_adb(&stream->desc_list, CFD_MMR_CLIENT,
> + &port->mmr_adb);
> +
> + port->load_mmrs = false;
> + vip_dbg(3, stream, "Added mmr_adb config desc\n");
> + }
> +
> + if (sc->loaded_coeff_h != port->sc_coeff_h.dma_addr ||
> + sc->load_coeff_h) {
> + vpdma_map_desc_buf(vpdma, &port->sc_coeff_h);
> + vpdma_add_cfd_block(&stream->desc_list,
> + VIP_SLICE1_CFD_SC_CLIENT + dev->slice_id,
> + &port->sc_coeff_h, 0);
> +
> + sc->loaded_coeff_h = port->sc_coeff_h.dma_addr;
> + sc->load_coeff_h = false;
> + vip_dbg(3, stream, "Added sc_coeff_h config desc\n");
> + }
> +
> + if (sc->loaded_coeff_v != port->sc_coeff_v.dma_addr ||
> + sc->load_coeff_v) {
> + vpdma_map_desc_buf(vpdma, &port->sc_coeff_v);
> + vpdma_add_cfd_block(&stream->desc_list,
> + VIP_SLICE1_CFD_SC_CLIENT + dev->slice_id,
> + &port->sc_coeff_v, SC_COEF_SRAM_SIZE >> 4);
> +
> + sc->loaded_coeff_v = port->sc_coeff_v.dma_addr;
> + sc->load_coeff_v = false;
> + vip_dbg(3, stream, "Added sc_coeff_v config desc\n");
> + }
> + vip_dbg(3, stream, "CFD_SC_CLIENT %d slice_id: %d\n",
> + VIP_SLICE1_CFD_SC_CLIENT + dev->slice_id, dev->slice_id);
> +
> + vpdma_map_desc_buf(vpdma, &stream->desc_list.buf);
> + vip_dbg(3, stream, "Submitting desc on list# %d\n", list_num);
> + vpdma_submit_descs(vpdma, &stream->desc_list, list_num);
> +
> + while (vpdma_list_busy(vpdma, list_num) && timeout--)
> + usleep_range(1000, 1100);
> +
> + vpdma_unmap_desc_buf(dev->shared->vpdma, &port->mmr_adb);
> + vpdma_unmap_desc_buf(dev->shared->vpdma, &port->sc_coeff_h);
> + vpdma_unmap_desc_buf(dev->shared->vpdma, &port->sc_coeff_v);
> + vpdma_unmap_desc_buf(dev->shared->vpdma, &stream->desc_list.buf);
> +
> + vpdma_reset_desc_list(&stream->desc_list);
> +
> + if (timeout <= 0) {
> + vip_err(stream, "Timed out setting up scaler through VPDMA list\n");
> + return -EBUSY;
> + }
> +
> + return 0;
> +}
> +
> +static int vip_load_vpdma_list_fifo(struct vip_stream *stream)
> +{
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + struct vpdma_data *vpdma = dev->shared->vpdma;
> + int list_num = stream->list_num;
> + struct vip_buffer *buf;
> + unsigned long flags;
> + int timeout, i;
> +
> + if (vpdma_list_busy(dev->shared->vpdma, stream->list_num))
> + return -EBUSY;
> +
> + for (i = 0; i < VIP_VPDMA_FIFO_SIZE; i++) {
> + spin_lock_irqsave(&dev->slock, flags);
> + if (list_empty(&stream->vidq)) {
> + vip_err(stream, "No buffer left!");
> + spin_unlock_irqrestore(&dev->slock, flags);
> + return -EINVAL;
> + }
> +
> + buf = list_entry(stream->vidq.next,
> + struct vip_buffer, list);
> + buf->drop = false;
> +
> + list_move_tail(&buf->list, &stream->post_bufs);
> + spin_unlock_irqrestore(&dev->slock, flags);
> +
> + vip_dbg(2, stream, "%s: start_dma vb2 buf idx:%d\n",
> + __func__, buf->vb.vb2_buf.index);
> + start_dma(stream, buf);
> +
> + timeout = 500;
> + while (vpdma_list_busy(vpdma, list_num) && timeout--)
> + usleep_range(1000, 1100);
> +
> + if (timeout <= 0) {
> + vip_err(stream, "Timed out loading VPDMA list fifo\n");
> + return -EBUSY;
> + }
> + }
> + return 0;
> +}
> +
> +static int vip_start_streaming(struct vb2_queue *vq, unsigned int count)
> +{
> + struct vip_stream *stream = vb2_get_drv_priv(vq);
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + int ret;
> +
> + vip_setup_scaler(stream);
> +
> + /*
> + * Make sure the scaler is configured before the datapath is
> + * enabled. The scaler can only load the coefficient
> + * parameters when it is idle. If the scaler path is enabled
> + * and video data is being received then the VPDMA transfer will
> + * stall indefinetely.
> + */
> + set_fmt_params(stream);
> + vip_setup_parser(port);
> +
> + if (port->subdev) {
> + ret = v4l2_subdev_call(port->subdev, video, s_stream, 1);
> + if (ret < 0 && ret != -ENOIOCTLCMD) {
> + vip_dbg(1, stream, "stream on failed in subdev\n");
On error, all pending buffers need to be returned to vb2 with
vb2_buffer_done and state VB2_BUF_STATE_QUEUED.
> + return ret;
> + }
> + }
> +
> + stream->sequence = 0;
> + if (stream->port->flags & FLAG_INTERLACED)
> + stream->field = V4L2_FIELD_TOP;
> + populate_desc_list(stream);
> +
> + ret = vip_load_vpdma_list_fifo(stream);
> + if (ret)
> + return ret;
> +
> + stream->num_recovery = 0;
> +
> + clear_irqs(dev, dev->slice_id, stream->list_num);
> + enable_irqs(dev, dev->slice_id, stream->list_num);
> + vip_schedule_next_buffer(stream);
> + vip_parser_stop_imm(port, false);
> + vip_enable_parser(port, true);
> +
> + return 0;
> +}
> +
> +/*
> + * Abort streaming and wait for last buffer
> + */
> +static void vip_stop_streaming(struct vb2_queue *vq)
> +{
> + struct vip_stream *stream = vb2_get_drv_priv(vq);
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + struct vip_buffer *buf;
> + int ret;
> +
> + vip_dbg(2, stream, "%s:\n", __func__);
> +
> + vip_parser_stop_imm(port, true);
> + vip_enable_parser(port, false);
> + unset_fmt_params(stream);
> +
> + disable_irqs(dev, dev->slice_id, stream->list_num);
> + clear_irqs(dev, dev->slice_id, stream->list_num);
> +
> + if (port->subdev) {
> + ret = v4l2_subdev_call(port->subdev, video, s_stream, 0);
> + if (ret < 0 && ret != -ENOIOCTLCMD)
> + vip_dbg(1, stream, "stream on failed in subdev\n");
> + }
> +
> + stop_dma(stream, true);
> +
> + /* release all active buffers */
> + while (!list_empty(&stream->post_bufs)) {
> + buf = list_entry(stream->post_bufs.next,
> + struct vip_buffer, list);
> + list_del(&buf->list);
> + if (buf->drop == 1)
> + list_add_tail(&buf->list, &stream->dropq);
> + else
> + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
> + }
> + while (!list_empty(&stream->vidq)) {
> + buf = list_entry(stream->vidq.next, struct vip_buffer, list);
> + list_del(&buf->list);
> + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
> + }
> +
> + if (!vb2_is_streaming(vq))
> + return;
> +
> + vpdma_unmap_desc_buf(dev->shared->vpdma, &stream->desc_list.buf);
> + vpdma_reset_desc_list(&stream->desc_list);
> +}
> +
> +static const struct vb2_ops vip_video_qops = {
> + .queue_setup = vip_queue_setup,
> + .buf_prepare = vip_buf_prepare,
> + .buf_queue = vip_buf_queue,
> + .start_streaming = vip_start_streaming,
> + .stop_streaming = vip_stop_streaming,
> + .wait_prepare = vb2_ops_wait_prepare,
> + .wait_finish = vb2_ops_wait_finish,
> +};
> +
> +/*
> + * File operations
> + */
> +
> +static int vip_init_dev(struct vip_dev *dev)
> +{
> + if (dev->num_ports != 0)
> + goto done;
> +
> + vip_set_clock_enable(dev, 1);
> + vip_module_reset(dev, VIP_SC_RST, false);
> + vip_module_reset(dev, VIP_CSC_RST, false);
> +done:
> + dev->num_ports++;
> +
> + return 0;
> +}
> +
> +static inline bool is_scaler_available(struct vip_port *port)
> +{
> + if (port->endpoint.bus_type == V4L2_MBUS_PARALLEL)
> + if (port->dev->sc_assigned == VIP_NOT_ASSIGNED ||
> + port->dev->sc_assigned == port->port_id)
> + return true;
> + return false;
> +}
> +
> +static inline bool allocate_scaler(struct vip_port *port)
> +{
> + if (is_scaler_available(port)) {
> + if (port->dev->sc_assigned == VIP_NOT_ASSIGNED ||
> + port->dev->sc_assigned == port->port_id) {
> + port->dev->sc_assigned = port->port_id;
> + port->scaler = true;
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +static inline void free_scaler(struct vip_port *port)
> +{
> + if (port->dev->sc_assigned == port->port_id) {
> + port->dev->sc_assigned = VIP_NOT_ASSIGNED;
> + port->scaler = false;
> + }
> +}
> +
> +static bool is_csc_available(struct vip_port *port)
> +{
> + if (port->endpoint.bus_type == V4L2_MBUS_PARALLEL)
> + if (port->dev->csc_assigned == VIP_NOT_ASSIGNED ||
> + port->dev->csc_assigned == port->port_id)
> + return true;
> + return false;
> +}
> +
> +static bool allocate_csc(struct vip_port *port,
> + enum vip_csc_state csc_direction)
> +{
> + /* Is CSC needed? */
> + if (csc_direction != VIP_CSC_NA) {
> + if (is_csc_available(port)) {
> + port->dev->csc_assigned = port->port_id;
> + port->csc = csc_direction;
> + vip_dbg(1, port, "%s: csc allocated: dir: %d\n",
> + __func__, csc_direction);
> + return true;
> + }
> + }
> + return false;
> +}
> +
> +static void free_csc(struct vip_port *port)
> +{
> + if (port->dev->csc_assigned == port->port_id) {
> + port->dev->csc_assigned = VIP_NOT_ASSIGNED;
> + port->csc = VIP_CSC_NA;
> + vip_dbg(1, port, "%s: csc freed\n",
> + __func__);
> + }
> +}
> +
> +static int vip_init_port(struct vip_port *port)
> +{
> + int ret;
> + struct vip_fmt *fmt;
> + struct v4l2_subdev_format sd_fmt;
> + struct v4l2_mbus_framefmt *mbus_fmt = &sd_fmt.format;
> +
> + if (port->num_streams != 0)
> + goto done;
> +
> + ret = vip_init_dev(port->dev);
> + if (ret)
> + goto done;
> +
> + /* Get subdevice current frame format */
> + sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> + sd_fmt.pad = port->source_pad;
> + ret = v4l2_subdev_call(port->subdev, pad, get_fmt, NULL, &sd_fmt);
> + if (ret)
> + vip_dbg(1, port, "init_port get_fmt failed in subdev: (%d)\n",
> + ret);
> +
> + /* try to find one that matches */
> + fmt = find_port_format_by_code(port, mbus_fmt->code);
> + if (!fmt) {
> + vip_dbg(1, port, "subdev default mbus_fmt %04x is not matched.\n",
> + mbus_fmt->code);
> + /* if all else fails just pick the first one */
> + fmt = port->active_fmt[0];
> +
> + mbus_fmt->code = fmt->code;
> + sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> + sd_fmt.pad = port->source_pad;
> + ret = v4l2_subdev_call(port->subdev, pad, set_fmt,
> + NULL, &sd_fmt);
> + if (ret)
> + vip_dbg(1, port, "init_port set_fmt failed in subdev: (%d)\n",
> + ret);
> + }
> +
> + /* Assign current format */
> + port->fmt = fmt;
> + port->mbus_framefmt = *mbus_fmt;
> +
> + vip_dbg(3, port, "%s: g_mbus_fmt subdev mbus_code: %04X fourcc:%s size: %dx%d\n",
> + __func__, fmt->code,
> + fourcc_to_str(fmt->fourcc),
> + mbus_fmt->width, mbus_fmt->height);
> +
> + if (mbus_fmt->field == V4L2_FIELD_ALTERNATE)
> + port->flags |= FLAG_INTERLACED;
> + else
> + port->flags &= ~FLAG_INTERLACED;
> +
> + port->c_rect.left = 0;
> + port->c_rect.top = 0;
> + port->c_rect.width = mbus_fmt->width;
> + port->c_rect.height = mbus_fmt->height;
> +
> + ret = vpdma_alloc_desc_buf(&port->sc_coeff_h, SC_COEF_SRAM_SIZE);
> + if (ret != 0)
> + return ret;
> +
> + ret = vpdma_alloc_desc_buf(&port->sc_coeff_v, SC_COEF_SRAM_SIZE);
> + if (ret != 0)
> + goto free_sc_h;
> +
> + ret = vpdma_alloc_desc_buf(&port->mmr_adb, sizeof(struct vip_mmr_adb));
> + if (ret != 0)
> + goto free_sc_v;
> +
> + init_adb_hdrs(port);
> +
> + vip_enable_parser(port, false);
> +done:
> + port->num_streams++;
> + return 0;
> +
> +free_sc_v:
> + vpdma_free_desc_buf(&port->sc_coeff_v);
> +free_sc_h:
> + vpdma_free_desc_buf(&port->sc_coeff_h);
> + return ret;
> +}
> +
> +static int vip_init_stream(struct vip_stream *stream)
> +{
> + struct vip_port *port = stream->port;
> + struct vip_fmt *fmt;
> + struct v4l2_mbus_framefmt *mbus_fmt;
> + struct v4l2_format f;
> + int ret;
> +
> + ret = vip_init_port(port);
> + if (ret != 0)
> + return ret;
> +
> + fmt = port->fmt;
> + mbus_fmt = &port->mbus_framefmt;
> +
> + memset(&f, 0, sizeof(f));
> +
> + /* Properly calculate the sizeimage and bytesperline values. */
> + v4l2_fill_pix_format(&f.fmt.pix, mbus_fmt);
> + f.fmt.pix.pixelformat = fmt->fourcc;
> + ret = vip_calc_format_size(port, fmt, &f);
> + if (ret)
> + return ret;
> +
> + stream->width = f.fmt.pix.width;
> + stream->height = f.fmt.pix.height;
> + stream->sup_field = f.fmt.pix.field;
> + stream->field = f.fmt.pix.field;
> + stream->bytesperline = f.fmt.pix.bytesperline;
> + stream->sizeimage = f.fmt.pix.sizeimage;
> +
> + vip_dbg(3, stream, "init_stream fourcc:%s size: %dx%d bpl:%d img_size:%d\n",
> + fourcc_to_str(f.fmt.pix.pixelformat),
> + f.fmt.pix.width, f.fmt.pix.height,
> + f.fmt.pix.bytesperline, f.fmt.pix.sizeimage);
> + vip_dbg(3, stream, "init_stream vpdma data type: 0x%02X\n",
> + port->fmt->vpdma_fmt[0]->data_type);
> +
> + ret = vpdma_create_desc_list(&stream->desc_list, VIP_DESC_LIST_SIZE,
> + VPDMA_LIST_TYPE_NORMAL);
> +
> + if (ret != 0)
> + return ret;
> +
> + stream->write_desc = (struct vpdma_dtd *)stream->desc_list.buf.addr
> + + 15;
> +
> + vip_dbg(1, stream, "%s: stream instance %pa\n",
> + __func__, &stream);
> +
> + return 0;
> +}
> +
> +static void vip_release_dev(struct vip_dev *dev)
> +{
> + /*
> + * On last close, disable clocks to conserve power
> + */
> +
> + if (--dev->num_ports == 0) {
> + /* reset the scaler module */
> + vip_module_reset(dev, VIP_SC_RST, true);
> + vip_module_reset(dev, VIP_CSC_RST, true);
> + vip_set_clock_enable(dev, 0);
> + }
> +}
> +
> +static int vip_set_crop_parser(struct vip_port *port)
> +{
> + struct vip_dev *dev = port->dev;
> + struct vip_parser_data *parser = dev->parser;
> + u32 hcrop = 0, vcrop = 0;
> + u32 width = port->mbus_framefmt.width;
> +
> + if (port->fmt->vpdma_fmt[0] == &vpdma_raw_fmts[VPDMA_DATA_FMT_RAW8]) {
> + /*
> + * Special case since we are faking a YUV422 16bit format
> + * to have the vpdma perform the needed byte swap
> + * we need to adjust the pixel width accordingly
> + * otherwise the parser will attempt to collect more pixels
> + * then available and the vpdma transfer will exceed the
> + * allocated frame buffer.
> + */
> + width >>= 1;
> + vip_dbg(1, port, "%s: 8 bit raw detected, adjusting width to %d\n",
> + __func__, width);
> + }
> +
> + /*
> + * Set Parser Crop parameters to source size otherwise
> + * scaler and colorspace converter will yield garbage.
> + */
> + hcrop = VIP_ACT_BYPASS;
> + insert_field(&hcrop, 0, VIP_ACT_SKIP_NUMPIX_MASK,
> + VIP_ACT_SKIP_NUMPIX_SHFT);
> + insert_field(&hcrop, width,
> + VIP_ACT_USE_NUMPIX_MASK, VIP_ACT_USE_NUMPIX_SHFT);
> + reg_write(parser, VIP_PARSER_CROP_H_PORT(port->port_id), hcrop);
> +
> + insert_field(&vcrop, 0, VIP_ACT_SKIP_NUMLINES_MASK,
> + VIP_ACT_SKIP_NUMLINES_SHFT);
> + insert_field(&vcrop, port->mbus_framefmt.height,
> + VIP_ACT_USE_NUMLINES_MASK, VIP_ACT_USE_NUMLINES_SHFT);
> + reg_write(parser, VIP_PARSER_CROP_V_PORT(port->port_id), vcrop);
> +
> + return 0;
> +}
> +
> +static int vip_setup_parser(struct vip_port *port)
> +{
> + struct vip_dev *dev = port->dev;
> + struct vip_parser_data *parser = dev->parser;
> + struct v4l2_fwnode_endpoint *endpoint = &port->endpoint;
> + struct vip_bt656_bus *bt656_ep = &port->bt656_endpoint;
> + int iface, sync_type;
> + u32 flags = 0, config0;
> +
> + /* Reset the port */
> + vip_reset_parser(port, true);
> + usleep_range(200, 250);
> + vip_reset_parser(port, false);
> +
> + config0 = reg_read(parser, VIP_PARSER_PORT(port->port_id));
> +
> + switch (endpoint->bus.parallel.bus_width) {
> + case 24:
> + iface = SINGLE_24B_INTERFACE;
> + break;
> + case 16:
> + iface = SINGLE_16B_INTERFACE;
> + break;
> + case 8:
> + default:
> + iface = DUAL_8B_INTERFACE;
> + }
> +
> + if (endpoint->bus_type == V4L2_MBUS_BT656) {
> + flags = endpoint->bus.parallel.flags;
> +
> + /*
> + * Ideally, this should come from subdev
> + * port->fmt can be anything once CSC is enabled
> + */
> + if (vip_is_mbuscode_rgb(port->fmt->code)) {
> + sync_type = EMBEDDED_SYNC_SINGLE_RGB_OR_YUV444;
> + } else {
> + switch (bt656_ep->num_channels) {
> + case 4:
> + sync_type = EMBEDDED_SYNC_4X_MULTIPLEXED_YUV422;
> + break;
> + case 2:
> + sync_type = EMBEDDED_SYNC_2X_MULTIPLEXED_YUV422;
> + break;
> + case 1:
> + sync_type = EMBEDDED_SYNC_SINGLE_YUV422;
> + break;
> + default:
> + sync_type =
> + EMBEDDED_SYNC_LINE_MULTIPLEXED_YUV422;
> + }
> + if (bt656_ep->pixmux == 0)
> + sync_type =
> + EMBEDDED_SYNC_LINE_MULTIPLEXED_YUV422;
> + }
> +
> + } else if (endpoint->bus_type == V4L2_MBUS_PARALLEL) {
> + flags = endpoint->bus.parallel.flags;
> +
> + if (vip_is_mbuscode_rgb(port->fmt->code))
> + sync_type = DISCRETE_SYNC_SINGLE_RGB_24B;
> + else
> + sync_type = DISCRETE_SYNC_SINGLE_YUV422;
> +
> + if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
> + config0 |= VIP_HSYNC_POLARITY;
> + else if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
> + config0 &= ~VIP_HSYNC_POLARITY;
> +
> + if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
> + config0 |= VIP_VSYNC_POLARITY;
> + else if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
> + config0 &= ~VIP_VSYNC_POLARITY;
> +
> + config0 &= ~VIP_USE_ACTVID_HSYNC_ONLY;
> + config0 |= VIP_ACTVID_POLARITY;
> + config0 |= VIP_DISCRETE_BASIC_MODE;
> +
> + } else {
> + vip_err(port, "Device doesn't support CSI2");
> + return -EINVAL;
> + }
> +
> + if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING) {
> + vip_set_pclk_invert(port);
> + config0 |= VIP_PIXCLK_EDGE_POLARITY;
> + } else {
> + vip_clr_pclk_invert(port);
> + config0 &= ~VIP_PIXCLK_EDGE_POLARITY;
> + }
> +
> + config0 |= ((sync_type & VIP_SYNC_TYPE_MASK) << VIP_SYNC_TYPE_SHFT);
> +
> + reg_write(parser, VIP_PARSER_PORT(port->port_id), config0);
> +
> + vip_set_data_interface(port, iface);
> + vip_set_crop_parser(port);
> +
> + return 0;
> +}
> +
> +static void vip_enable_parser(struct vip_port *port, bool on)
> +{
> + u32 config0;
> + struct vip_dev *dev = port->dev;
> + struct vip_parser_data *parser = dev->parser;
> +
> + config0 = reg_read(parser, VIP_PARSER_PORT(port->port_id));
> +
> + if (on) {
> + config0 |= VIP_PORT_ENABLE;
> + config0 &= ~(VIP_ASYNC_FIFO_RD | VIP_ASYNC_FIFO_WR);
> + } else {
> + config0 &= ~VIP_PORT_ENABLE;
> + config0 |= (VIP_ASYNC_FIFO_RD | VIP_ASYNC_FIFO_WR);
> + }
> + reg_write(parser, VIP_PARSER_PORT(port->port_id), config0);
> +}
> +
> +static void vip_reset_parser(struct vip_port *port, bool on)
> +{
> + u32 config0;
> + struct vip_dev *dev = port->dev;
> + struct vip_parser_data *parser = dev->parser;
> +
> + config0 = reg_read(parser, VIP_PARSER_PORT(port->port_id));
> +
> + if (on)
> + config0 |= VIP_SW_RESET;
> + else
> + config0 &= ~VIP_SW_RESET;
> +
> + reg_write(parser, VIP_PARSER_PORT(port->port_id), config0);
> +}
> +
> +static void vip_parser_stop_imm(struct vip_port *port, bool on)
> +{
> + u32 config0;
> + struct vip_dev *dev = port->dev;
> + struct vip_parser_data *parser = dev->parser;
> +
> + config0 = reg_read(parser, VIP_PARSER_STOP_IMM_PORT(port->port_id));
> +
> + if (on)
> + config0 = 0xffffffff;
> + else
> + config0 = 0;
> +
> + reg_write(parser, VIP_PARSER_STOP_IMM_PORT(port->port_id), config0);
> +}
> +
> +static void vip_release_stream(struct vip_stream *stream)
> +{
> + struct vip_dev *dev = stream->port->dev;
> +
> + vip_dbg(1, stream, "%s: stream instance %pa\n",
> + __func__, &stream);
> +
> + vpdma_unmap_desc_buf(dev->shared->vpdma, &stream->desc_list.buf);
> + vpdma_free_desc_buf(&stream->desc_list.buf);
> + vpdma_free_desc_list(&stream->desc_list);
> +}
> +
> +static void vip_release_port(struct vip_port *port)
> +{
> + vip_dbg(1, port, "%s: port instance %pa\n",
> + __func__, &port);
> +
> + vpdma_free_desc_buf(&port->mmr_adb);
> + vpdma_free_desc_buf(&port->sc_coeff_h);
> + vpdma_free_desc_buf(&port->sc_coeff_v);
> +}
> +
> +static void stop_dma(struct vip_stream *stream, bool clear_list)
> +{
> + struct vip_dev *dev = stream->port->dev;
> + int ch, size = 0;
> +
> + /* Create a list of channels to be cleared */
> + for (ch = 0; ch < VPDMA_MAX_CHANNELS; ch++) {
> + if (stream->vpdma_channels[ch] == 1) {
> + stream->vpdma_channels_to_abort[size++] = ch;
> + vip_dbg(2, stream, "Clear channel no: %d\n", ch);
> + }
> + }
> +
> + /* Clear all the used channels for the list */
> + vpdma_list_cleanup(dev->shared->vpdma, stream->list_num,
> + stream->vpdma_channels_to_abort, size);
> +
> + if (clear_list)
> + for (ch = 0; ch < VPDMA_MAX_CHANNELS; ch++)
> + stream->vpdma_channels[ch] = 0;
> +}
> +
> +static int vip_open(struct file *file)
> +{
> + struct vip_stream *stream = video_drvdata(file);
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + int ret = 0;
> +
> + vip_dbg(2, stream, "%s\n", __func__);
> +
> + mutex_lock(&dev->mutex);
> +
> + ret = v4l2_fh_open(file);
> + if (ret) {
> + vip_err(stream, "v4l2_fh_open failed\n");
> + goto unlock;
> + }
> +
> + /*
> + * If this is the first open file.
> + * Then initialize hw module.
> + */
> + if (!v4l2_fh_is_singular_file(file))
> + goto unlock;
> +
> + if (vip_init_stream(stream))
> + ret = -ENODEV;
> +unlock:
> + mutex_unlock(&dev->mutex);
> + return ret;
> +}
> +
> +static int vip_release(struct file *file)
> +{
> + struct vip_stream *stream = video_drvdata(file);
> + struct vip_port *port = stream->port;
> + struct vip_dev *dev = port->dev;
> + bool fh_singular;
> + int ret;
> +
> + vip_dbg(2, stream, "%s\n", __func__);
> +
> + mutex_lock(&dev->mutex);
> +
> + /* Save the singular status before we call the clean-up helper */
> + fh_singular = v4l2_fh_is_singular_file(file);
> +
> + /* the release helper will cleanup any on-going streaming */
> + ret = _vb2_fop_release(file, NULL);
> +
> + free_csc(port);
> + free_scaler(port);
> +
> + /*
> + * If this is the last open file.
> + * Then de-initialize hw module.
> + */
> + if (fh_singular) {
> + vip_release_stream(stream);
> +
> + if (--port->num_streams == 0) {
> + vip_release_port(port);
> + vip_release_dev(port->dev);
> + }
> + }
> +
> + mutex_unlock(&dev->mutex);
> +
> + return ret;
> +}
> +
> +static const struct v4l2_file_operations vip_fops = {
> + .owner = THIS_MODULE,
> + .open = vip_open,
> + .release = vip_release,
> + .read = vb2_fop_read,
> + .poll = vb2_fop_poll,
> + .unlocked_ioctl = video_ioctl2,
> + .mmap = vb2_fop_mmap,
> +};
> +
> +static struct video_device vip_videodev = {
> + .name = VIP_MODULE_NAME,
> + .fops = &vip_fops,
> + .ioctl_ops = &vip_ioctl_ops,
> + .minor = -1,
> + .release = video_device_release,
> + .tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
> + .device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE |
> + V4L2_CAP_READWRITE,
> +};
> +
> +static int alloc_stream(struct vip_port *port, int stream_id, int vfl_type)
> +{
> + struct vip_stream *stream;
> + struct vip_dev *dev = port->dev;
> + struct vb2_queue *q;
> + struct video_device *vfd;
> + struct vip_buffer *buf;
> + struct list_head *pos, *tmp;
> + int ret, i;
> +
> + stream = kzalloc(sizeof(*stream), GFP_KERNEL);
> + if (!stream)
> + return -ENOMEM;
> +
> + stream->port = port;
> + stream->stream_id = stream_id;
> + stream->vfl_type = vfl_type;
> + port->cap_streams[stream_id] = stream;
> +
> + snprintf(stream->name, sizeof(stream->name), "%s-%d",
> + port->name, stream_id);
> +
> + stream->list_num = vpdma_hwlist_alloc(dev->shared->vpdma, stream);
> + if (stream->list_num < 0) {
> + vip_err(stream, "Could not get VPDMA hwlist");
> + ret = -ENODEV;
> + goto do_free_stream;
> + }
> +
> + INIT_LIST_HEAD(&stream->post_bufs);
> +
> + /*
> + * Initialize queue
> + */
> + q = &stream->vb_vidq;
> + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
> + q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
> + q->drv_priv = stream;
> + q->buf_struct_size = sizeof(struct vip_buffer);
> + q->ops = &vip_video_qops;
> + q->mem_ops = &vb2_dma_contig_memops;
> + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
> + q->lock = &dev->mutex;
> + q->min_buffers_needed = 3;
> + q->dev = dev->v4l2_dev->dev;
> +
> + ret = vb2_queue_init(q);
> + if (ret)
> + goto do_free_hwlist;
> +
> + INIT_WORK(&stream->recovery_work, vip_overflow_recovery_work);
> +
> + INIT_LIST_HEAD(&stream->vidq);
> +
> + /* Allocate/populate Drop queue entries */
> + INIT_LIST_HEAD(&stream->dropq);
> + for (i = 0; i < VIP_DROPQ_SIZE; i++) {
> + buf = kzalloc(sizeof(*buf), GFP_ATOMIC);
> + if (!buf) {
> + ret = -ENOMEM;
> + goto do_free_dropq;
> + }
> + buf->drop = true;
> + list_add(&buf->list, &stream->dropq);
> + }
> +
> + vfd = video_device_alloc();
> + if (!vfd)
> + goto do_free_dropq;
> + *vfd = vip_videodev;
> + vfd->v4l2_dev = dev->v4l2_dev;
> + vfd->queue = q;
> +
> + vfd->lock = &dev->mutex;
> + video_set_drvdata(vfd, stream);
> +
> + ret = video_register_device(vfd, vfl_type, -1);
> + if (ret) {
> + vip_err(stream, "Failed to register video device\n");
> + goto do_free_vfd;
> + }
> +
> + stream->vfd = vfd;
Shouldn't this be done before the call to video_register_device()?
> +
> + vip_info(stream, "device registered as %s\n",
> + video_device_node_name(vfd));
> + return 0;
> +
> +do_free_vfd:
> + video_device_release(vfd);
> +do_free_dropq:
> + list_for_each_safe(pos, tmp, &stream->dropq) {
> + buf = list_entry(pos,
> + struct vip_buffer, list);
> + vip_dbg(1, dev, "dropq buffer\n");
> + list_del(pos);
> + kfree(buf);
> + }
> +do_free_hwlist:
> + vpdma_hwlist_release(dev->shared->vpdma, stream->list_num);
> +do_free_stream:
> + kfree(stream);
> + return ret;
> +}
> +
> +static void free_stream(struct vip_stream *stream)
> +{
> + struct vip_dev *dev;
> + struct vip_buffer *buf;
> + struct list_head *pos, *q;
> +
> + if (!stream)
> + return;
> +
> + dev = stream->port->dev;
> + /* Free up the Drop queue */
> + list_for_each_safe(pos, q, &stream->dropq) {
> + buf = list_entry(pos,
> + struct vip_buffer, list);
> + vip_dbg(1, stream, "dropq buffer\n");
> + list_del(pos);
> + kfree(buf);
> + }
> +
> + video_unregister_device(stream->vfd);
> + vpdma_hwlist_release(dev->shared->vpdma, stream->list_num);
> + stream->port->cap_streams[stream->stream_id] = NULL;
> + kfree(stream);
> +}
> +
> +static int get_subdev_active_format(struct vip_port *port,
> + struct v4l2_subdev *subdev)
> +{
> + struct vip_fmt *fmt;
> + struct v4l2_subdev_mbus_code_enum mbus_code;
> + int ret = 0;
> + unsigned int k, i, j;
> + enum vip_csc_state csc;
> +
> + /* Enumerate sub device formats and enable all matching local formats */
> + port->num_active_fmt = 0;
> + for (k = 0, i = 0; (ret != -EINVAL); k++) {
> + memset(&mbus_code, 0, sizeof(mbus_code));
> + mbus_code.index = k;
> + mbus_code.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> + ret = v4l2_subdev_call(subdev, pad, enum_mbus_code,
> + NULL, &mbus_code);
> + if (ret)
> + continue;
> +
> + vip_dbg(2, port,
> + "subdev %s: code: %04x idx: %d\n",
> + subdev->name, mbus_code.code, k);
> +
> + for (j = 0; j < ARRAY_SIZE(vip_formats); j++) {
> + fmt = &vip_formats[j];
> + if (mbus_code.code != fmt->code)
> + continue;
> +
> + /*
> + * When the port is configured for BT656
> + * then none of the downstream unit can be used.
> + * So here we need to skip all format requiring
> + * either CSC or CHR_DS
> + */
> + csc = vip_csc_direction(fmt->code, fmt->finfo);
> + if (port->endpoint.bus_type == V4L2_MBUS_BT656 &&
> + (csc != VIP_CSC_NA || fmt->coplanar))
> + continue;
> +
> + port->active_fmt[i] = fmt;
> + vip_dbg(2, port,
> + "matched fourcc: %s: code: %04x idx: %d\n",
> + fourcc_to_str(fmt->fourcc), fmt->code, i);
> + port->num_active_fmt = ++i;
> + }
> + }
> +
> + if (i == 0) {
> + vip_err(port, "No suitable format reported by subdev %s\n",
> + subdev->name);
> + return -EINVAL;
> + }
> + return 0;
> +}
> +
> +static int alloc_port(struct vip_dev *dev, int id, const char *name)
> +{
> + struct vip_port *port;
> +
> + if (dev->ports[id])
> + return -EINVAL;
> +
> + port = devm_kzalloc(&dev->pdev->dev, sizeof(*port), GFP_KERNEL);
> + if (!port)
> + return -ENOMEM;
> +
> + dev->ports[id] = port;
> + port->dev = dev;
> + port->port_id = id;
> + port->name = name;
> + port->num_streams = 0;
> + return 0;
> +}
> +
> +static void free_port(struct vip_port *port)
> +{
> + if (!port)
> + return;
> +
> + v4l2_async_notifier_unregister(&port->notifier);
> + v4l2_async_notifier_cleanup(&port->notifier);
> + free_stream(port->cap_streams[0]);
> +}
> +
> +static int get_field(u32 value, u32 mask, int shift)
> +{
> + return (value & (mask << shift)) >> shift;
> +}
> +
> +static int vip_probe_complete(struct platform_device *pdev);
> +static void vip_vpdma_fw_cb(struct platform_device *pdev)
> +{
> + dev_info(&pdev->dev, "VPDMA firmware loaded\n");
> +
> + if (pdev->dev.of_node)
> + vip_probe_complete(pdev);
> +}
> +
> +static int vip_create_streams(struct vip_port *port,
> + struct v4l2_subdev *subdev)
> +{
> + struct v4l2_fwnode_bus_parallel *bus;
> + struct vip_bt656_bus *bt656_ep;
> + int i;
> +
> + for (i = 0; i < VIP_CAP_STREAMS_PER_PORT; i++)
> + free_stream(port->cap_streams[i]);
> +
> + if (get_subdev_active_format(port, subdev))
> + return -ENODEV;
> +
> + port->subdev = subdev;
> +
> + if (port->endpoint.bus_type == V4L2_MBUS_PARALLEL) {
> + port->flags |= FLAG_MULT_PORT;
> + port->num_streams_configured = 1;
> + alloc_stream(port, 0, VFL_TYPE_VIDEO);
> + } else if (port->endpoint.bus_type == V4L2_MBUS_BT656) {
> + port->flags |= FLAG_MULT_PORT;
> + bus = &port->endpoint.bus.parallel;
> + bt656_ep = &port->bt656_endpoint;
> + port->num_streams_configured = bt656_ep->num_channels;
> + for (i = 0; i < bt656_ep->num_channels; i++) {
> + if (bt656_ep->channels[i] >= 16)
> + continue;
> + alloc_stream(port, bt656_ep->channels[i],
> + VFL_TYPE_VIDEO);
> + }
> + }
> + return 0;
> +}
> +
> +static int vip_async_bound(struct v4l2_async_notifier *notifier,
> + struct v4l2_subdev *subdev,
> + struct v4l2_async_subdev *asd)
> +{
> + struct vip_port *port = notifier_to_vip_port(notifier);
> + int ret;
> +
> + vip_dbg(1, port, "%s\n", __func__);
> +
> + if (port->subdev) {
> + vip_info(port, "Rejecting subdev %s (Already set!!)",
> + subdev->name);
> + return 0;
> + }
> +
> + vip_info(port, "Port %c: Using subdev %s for capture\n",
> + port->port_id == VIP_PORTA ? 'A' : 'B', subdev->name);
> +
> + ret = vip_find_pad(subdev, MEDIA_PAD_FL_SOURCE);
> + if (ret < 0)
> + return ret;
> + port->source_pad = ret;
> + vip_dbg(1, port, "subdev source_pad: %d\n", port->source_pad);
> +
> + ret = vip_create_streams(port, subdev);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> +
> +static int vip_async_complete(struct v4l2_async_notifier *notifier)
> +{
> + struct vip_port *port = notifier_to_vip_port(notifier);
> +
> + vip_dbg(1, port, "%s\n", __func__);
> + return 0;
> +}
> +
> +static const struct v4l2_async_notifier_operations vip_async_ops = {
> + .bound = vip_async_bound,
> + .complete = vip_async_complete,
> +};
> +
> +static struct fwnode_handle *
> +fwnode_graph_get_next_endpoint_by_regs(const struct fwnode_handle *fwnode,
> + int port_reg, int reg)
> +{
> + return of_fwnode_handle(of_graph_get_endpoint_by_regs(to_of_node(fwnode),
> + port_reg, reg));
> +}
> +
> +static int vip_register_subdev_notif(struct vip_port *port,
> + struct fwnode_handle *ep)
> +{
> + struct v4l2_async_notifier *notifier = &port->notifier;
> + struct vip_dev *dev = port->dev;
> + struct fwnode_handle *subdev;
> + struct v4l2_fwnode_endpoint *vep;
> + struct vip_bt656_bus *bt656_vep;
> + struct v4l2_async_subdev *asd;
> + int ret, rval;
> +
> + vep = &port->endpoint;
> + bt656_vep = &port->bt656_endpoint;
> +
> + subdev = fwnode_graph_get_remote_port_parent(ep);
> + if (!subdev) {
> + vip_dbg(3, port, "can't get remote parent\n");
> + return -EINVAL;
> + }
> +
> + ret = v4l2_fwnode_endpoint_parse(ep, vep);
> + if (ret) {
> + vip_dbg(3, port, "Failed to parse endpoint:\n");
> + fwnode_handle_put(subdev);
> + return -EINVAL;
> + }
> +
> + if (vep->bus_type == V4L2_MBUS_BT656) {
> + if (fwnode_property_present(ep, "ti,vip-pixel-mux"))
> + bt656_vep->pixmux = 1;
> + else
> + bt656_vep->pixmux = 0;
> + vip_dbg(3, port, "ti,vip-pixel-mux %u\n", bt656_vep->pixmux);
> +
> + bt656_vep->num_channels = 0;
> + rval = fwnode_property_read_u8_array(ep, "ti,vip-channels",
> + NULL, 0);
> + if (rval > 0) {
> + bt656_vep->num_channels =
> + min_t(int, ARRAY_SIZE(bt656_vep->channels),
> + rval);
> +
> + fwnode_property_read_u8_array(ep, "ti,vip-channels",
> + bt656_vep->channels,
> + bt656_vep->num_channels);
> + } else {
> + /* channels is not specified then assume 1 channel */
> + bt656_vep->num_channels = 1;
> + bt656_vep->channels[0] = 0;
> + }
> +
> + vip_dbg(3, port, "ti,vip-channels %u\n",
> + bt656_vep->num_channels);
> +
> + if (bt656_vep->pixmux &&
> + (bt656_vep->num_channels != 1 ||
> + bt656_vep->num_channels != 2 ||
> + bt656_vep->num_channels != 4)) {
> + vip_warn(port,
> + "ti,vip-pixel-mux is set but number of channels is not 1, 2 or 4: (%u), disabling ti,vip-pixel-mux.\n",
> + bt656_vep->num_channels);
> + bt656_vep->pixmux = 0;
> + }
> + }
> +
> + v4l2_async_notifier_init(notifier);
> +
> + asd = v4l2_async_notifier_add_fwnode_subdev(notifier, subdev,
> + sizeof(*asd));
> + if (IS_ERR(asd)) {
> + vip_dbg(1, port, "Error adding asd\n");
> + fwnode_handle_put(subdev);
> + v4l2_async_notifier_cleanup(notifier);
> + return -EINVAL;
> + }
> +
> + notifier->ops = &vip_async_ops;
> + ret = v4l2_async_notifier_register(dev->v4l2_dev, notifier);
> + if (ret) {
> + vip_dbg(1, port, "Error registering async notifier\n");
> + v4l2_async_notifier_cleanup(notifier);
> + ret = -EINVAL;
> + }
> +
> + return ret;
> +}
> +
> +static int vip_endpoint_scan(struct platform_device *pdev)
> +{
> + struct device_node *parent = pdev->dev.of_node;
> + struct device_node *ep = NULL;
> + int count = 0, p;
> +
> + for (p = 0; p < (VIP_NUM_PORTS * VIP_NUM_SLICES); p++) {
> + ep = of_graph_get_endpoint_by_regs(parent, p, 0);
> + if (!ep)
> + continue;
> +
> + count++;
> + of_node_put(ep);
> + }
> +
> + return count;
> +}
> +
> +static const char *vip_parse_fwnode_label(struct fwnode_handle *fwnode)
> +{
> + const char *label = NULL;
> + int ret;
> +
> + if (!fwnode)
> + return NULL;
> +
> + ret = fwnode_property_read_string(fwnode, "label", &label);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + return label;
> +}
> +
> +static int vip_get_clk_polarity(struct platform_device *pdev,
> + struct vip_clk_polarity *pol)
> +{
> + struct device_node *parent = pdev->dev.of_node;
> + struct of_phandle_args args;
> + int ret, i;
> +
> + if (!pol || !parent ||
> + !of_property_read_bool(parent, "ti,vip-clk-polarity"))
> + return -EINVAL;
> +
> + pol->rm_pol = syscon_regmap_lookup_by_phandle(parent,
> + "ti,vip-clk-polarity");
> + if (IS_ERR(pol->rm_pol)) {
> + dev_err(&pdev->dev, "failed to get ti,vip-clk-polarity regmap\n");
> + return PTR_ERR(pol->rm_pol);
> + }
> +
> + ret = of_parse_phandle_with_fixed_args(parent, "ti,vip-clk-polarity",
> + 5, 0, &args);
> + if (ret) {
> + dev_err(&pdev->dev, "failed to parse ti,vip-clk-polarity\n");
> + return ret;
> + }
> +
> + pol->rm_offset = args.args[0];
> +
> + for (i = 0; i < ARRAY_SIZE(pol->rm_bit_field); i++)
> + pol->rm_bit_field[i] = args.args[i + 1];
> +
> + return 0;
> +}
> +
> +static int vip_probe_complete(struct platform_device *pdev)
> +{
> + struct vip_shared *shared = platform_get_drvdata(pdev);
> + struct vip_clk_polarity *pol;
> + struct vip_port *port;
> + struct vip_dev *dev;
> + struct device_node *parent = pdev->dev.of_node;
> + struct fwnode_handle *ep, *port_node;
> + const char *port_name;
> + int ret, slice_id, port_id, p;
> +
> + pol = devm_kzalloc(&pdev->dev, sizeof(*pol), GFP_KERNEL);
> + if (!pol)
> + return -ENOMEM;
> +
> + ret = vip_get_clk_polarity(pdev, pol);
> + if (ret)
> + return ret;
> +
> + for (p = 0; p < (VIP_NUM_PORTS * VIP_NUM_SLICES); p++) {
> + ep = fwnode_graph_get_next_endpoint_by_regs(of_fwnode_handle(parent),
> + p, 0);
> + if (!ep)
> + continue;
> +
> + port_node = fwnode_get_parent(ep);
> + if (!port_node) {
> + dev_err(&pdev->dev, "can't get port of ep(%s)\n",
> + ep->ops->get_name(ep));
> + fwnode_handle_put(ep);
> + return -EINVAL;
> + }
> +
> + port_name = vip_parse_fwnode_label(port_node);
> + if (IS_ERR_OR_NULL(port_name)) {
> + dev_err(&pdev->dev, "can't get label of port(%s)\n",
> + port_node->ops->get_name(port_node));
> + fwnode_handle_put(ep);
> + fwnode_handle_put(port_node);
> + return PTR_ERR(port_name);
> + }
> +
> + switch (p) {
> + case 0:
> + slice_id = VIP_SLICE1; port_id = VIP_PORTA;
> + break;
> + case 1:
> + slice_id = VIP_SLICE1; port_id = VIP_PORTB;
> + break;
> + case 2:
> + slice_id = VIP_SLICE2; port_id = VIP_PORTA;
> + break;
> + case 3:
> + slice_id = VIP_SLICE2; port_id = VIP_PORTB;
> + break;
> + default:
> + dev_err(&pdev->dev, "Unknown port reg=<%d>\n", p);
> + continue;
> + }
> +
> + ret = alloc_port(shared->devs[slice_id], port_id, port_name);
> + if (ret < 0)
> + continue;
> +
> + dev = shared->devs[slice_id];
> + dev->pclk_pol = pol;
> + port = dev->ports[port_id];
> +
> + vip_register_subdev_notif(port, ep);
> + fwnode_handle_put(ep);
> + fwnode_handle_put(port_node);
> + }
> + return 0;
> +}
> +
> +static int vip_probe_slice(struct platform_device *pdev, int slice)
> +{
> + struct vip_shared *shared = platform_get_drvdata(pdev);
> + struct vip_dev *dev;
> + struct vip_parser_data *parser;
> + int ret;
> +
> + dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
> + if (!dev)
> + return -ENOMEM;
> +
> + snprintf(dev->name, sizeof(dev->name), "%ss%d", shared->name, slice);
> +
> + dev->irq = platform_get_irq(pdev, slice);
> + if (dev->irq < 0)
> + return dev->irq;
> +
> + ret = devm_request_irq(&pdev->dev, dev->irq, vip_irq,
> + 0, dev->name, dev);
> + if (ret < 0)
> + return -ENOMEM;
> +
> + spin_lock_init(&dev->slock);
> + mutex_init(&dev->mutex);
> +
> + dev->slice_id = slice;
> + dev->pdev = pdev;
> + dev->res = shared->res;
> + dev->base = shared->base;
> + dev->v4l2_dev = &shared->v4l2_dev;
> +
> + dev->shared = shared;
> + shared->devs[slice] = dev;
> +
> + vip_top_reset(dev);
> + vip_set_slice_path(dev, VIP_MULTI_CHANNEL_DATA_SELECT, 1);
> +
> + parser = devm_kzalloc(&pdev->dev, sizeof(*dev->parser), GFP_KERNEL);
> + if (!parser)
> + return PTR_ERR(parser);
> +
> + parser->res = platform_get_resource_byname(pdev,
> + IORESOURCE_MEM,
> + (slice == 0) ?
> + "parser0" :
> + "parser1");
> + parser->base = devm_ioremap_resource(&pdev->dev, parser->res);
> + if (IS_ERR(parser->base))
> + return PTR_ERR(parser->base);
> +
> + parser->pdev = pdev;
> + dev->parser = parser;
> +
> + dev->sc_assigned = VIP_NOT_ASSIGNED;
> + dev->sc = sc_create(pdev, (slice == 0) ? "sc0" : "sc1");
> + if (IS_ERR(dev->sc))
> + return PTR_ERR(dev->sc);
> +
> + dev->csc_assigned = VIP_NOT_ASSIGNED;
> + dev->csc = csc_create(pdev, (slice == 0) ? "csc0" : "csc1");
> + if (IS_ERR(dev->sc))
> + return PTR_ERR(dev->sc);
> +
> + return 0;
> +}
> +
> +static int vip_probe(struct platform_device *pdev)
> +{
> + struct vip_shared *shared;
> + struct pinctrl *pinctrl;
> + int ret, slice = VIP_SLICE1;
> + u32 tmp, pid;
> + const char *instance_name;
> + struct fwnode_handle *fwnode;
> +
> + fwnode = of_fwnode_handle(pdev->dev.of_node);
> + if (!fwnode)
> + return -ENODEV;
> +
> + instance_name = vip_parse_fwnode_label(fwnode);
> + if (IS_ERR_OR_NULL(instance_name))
> + return PTR_ERR(instance_name);
> +
> + /* If there are no endpoint defined there is nothing to do */
> + if (!vip_endpoint_scan(pdev))
> + return -ENODEV;
> +
> + ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> + if (ret) {
> + dev_err(&pdev->dev,
> + "32-bit consistent DMA enable failed\n");
> + return ret;
> + }
> +
> + shared = devm_kzalloc(&pdev->dev, sizeof(*shared), GFP_KERNEL);
> + if (!shared)
> + return -ENOMEM;
> +
> + shared->res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vip");
> + shared->base = devm_ioremap_resource(&pdev->dev, shared->res);
> + if (IS_ERR(shared->base))
> + return PTR_ERR(shared->base);
> +
> + shared->name = instance_name;
> +
> + vip_init_format_info(&pdev->dev);
> +
> + pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
> +
> + pm_runtime_enable(&pdev->dev);
> +
> + ret = pm_runtime_get_sync(&pdev->dev);
> + if (ret)
> + goto err_runtime_disable;
> +
> + /* Make sure H/W module has the right functionality */
> + pid = reg_read(shared, VIP_PID);
> + tmp = get_field(pid, VIP_PID_FUNC_MASK, VIP_PID_FUNC_SHIFT);
> +
> + if (tmp != VIP_PID_FUNC) {
> + dev_info(&pdev->dev, "vip: unexpected PID function: 0x%x\n",
> + tmp);
> + ret = -ENODEV;
> + goto err_runtime_put;
> + }
> +
> + ret = v4l2_device_register(&pdev->dev, &shared->v4l2_dev);
> + if (ret)
> + goto err_runtime_put;
> +
> + /* enable clocks, so the firmware will load properly */
> + vip_shared_set_clock_enable(shared, 1);
> + vip_top_vpdma_reset(shared);
> +
> + platform_set_drvdata(pdev, shared);
> +
> + v4l2_ctrl_handler_init(&shared->ctrl_handler, 11);
> + shared->v4l2_dev.ctrl_handler = &shared->ctrl_handler;
> +
> + for (slice = VIP_SLICE1; slice < VIP_NUM_SLICES; slice++) {
> + ret = vip_probe_slice(pdev, slice);
> + if (ret) {
> + dev_err(&pdev->dev, "Creating slice failed");
> + goto err_dev_unreg;
> + }
> + }
> +
> + shared->vpdma = &shared->vpdma_data;
> + ret = vpdma_create(pdev, shared->vpdma, vip_vpdma_fw_cb);
> + if (ret) {
> + dev_err(&pdev->dev, "Creating VPDMA failed");
> + goto err_dev_unreg;
> + }
> +
> + return 0;
> +
> +err_dev_unreg:
> + v4l2_ctrl_handler_free(&shared->ctrl_handler);
> + v4l2_device_unregister(&shared->v4l2_dev);
> +err_runtime_put:
> + pm_runtime_put_sync(&pdev->dev);
> +err_runtime_disable:
> + pm_runtime_disable(&pdev->dev);
> +
> + return ret;
> +}
> +
> +static int vip_remove(struct platform_device *pdev)
> +{
> + struct vip_shared *shared = platform_get_drvdata(pdev);
> + struct vip_dev *dev;
> + int slice;
> +
> + for (slice = 0; slice < VIP_NUM_SLICES; slice++) {
> + dev = shared->devs[slice];
> + if (!dev)
> + continue;
> +
> + free_port(dev->ports[VIP_PORTA]);
> + free_port(dev->ports[VIP_PORTB]);
> + }
> +
> + v4l2_ctrl_handler_free(&shared->ctrl_handler);
> +
> + pm_runtime_put_sync(&pdev->dev);
> + pm_runtime_disable(&pdev->dev);
> +
> + return 0;
> +}
> +
> +static const struct of_device_id vip_of_match[] = {
> + {
> + .compatible = "ti,dra7-vip",
> + },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, vip_of_match);
> +
> +static struct platform_driver vip_pdrv = {
> + .probe = vip_probe,
> + .remove = vip_remove,
> + .driver = {
> + .name = VIP_MODULE_NAME,
> + .of_match_table = vip_of_match,
> + },
> +};
> +
> +module_platform_driver(vip_pdrv);
> +
> +MODULE_DESCRIPTION("TI VIP driver");
> +MODULE_AUTHOR("Texas Instruments");
> +MODULE_LICENSE("GPL v2");
> diff --git a/drivers/media/platform/ti-vpe/vip.h b/drivers/media/platform/ti-vpe/vip.h
> new file mode 100644
> index 000000000000..f078a16a85b7
> --- /dev/null
> +++ b/drivers/media/platform/ti-vpe/vip.h
> @@ -0,0 +1,724 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/*
> + * TI VIP capture driver
> + *
> + * Copyright (C) 2018 Texas Instruments Incorpated - http://www.ti.com/
> + * David Griego, <dagriego@biglakesoftware.com>
> + * Dale Farnsworth, <dale@farnsworth.org>
> + * Nikhil Devshatwar, <nikhil.nd@ti.com>
> + * Benoit Parrot, <bparrot@ti.com>
> + */
> +
> +#ifndef __TI_VIP_H
> +#define __TI_VIP_H
> +
> +#include <linux/videodev2.h>
> +#include <media/v4l2-ctrls.h>
> +#include <media/v4l2-device.h>
> +#include <media/v4l2-event.h>
> +#include <media/v4l2-ioctl.h>
> +#include <media/videobuf2-core.h>
> +#include <media/videobuf2-dma-contig.h>
> +#include <media/videobuf2-memops.h>
> +#include <media/v4l2-fwnode.h>
> +
> +#include "vpdma.h"
> +#include "vpdma_priv.h"
> +#include "sc.h"
> +#include "csc.h"
> +
> +#define VIP_SLICE1 0
> +#define VIP_SLICE2 1
> +#define VIP_NUM_SLICES 2
> +
> +/*
> + * Additionnal client identifiers used for VPDMA configuration descriptors
> + */
> +#define VIP_SLICE1_CFD_SC_CLIENT 7
> +#define VIP_SLICE2_CFD_SC_CLIENT 8
> +
> +#define VIP_PORTA 0
> +#define VIP_PORTB 1
> +#define VIP_NUM_PORTS 2
> +
> +#define VIP_MAX_PLANES 2
> +#define VIP_LUMA 0
> +#define VIP_CHROMA 1
> +
> +#define VIP_CAP_STREAMS_PER_PORT 16
> +#define VIP_VBI_STREAMS_PER_PORT 16
> +
> +#define VIP_MAX_SUBDEV 5
> +/*
> + * This value needs to be at least as large as the number of entry in
> + * vip_formats[].
> + * When vip_formats[] is modified make sure to adjust this value also.
> + */
> +#define VIP_MAX_ACTIVE_FMT 16
> +/*
> + * Colorspace conversion unit can be in one of 3 modes:
> + * NA - Not Available on this port
> + * Y2R - Needed for YUV to RGB on this port
> + * R2Y - Needed for RGB to YUV on this port
> + */
> +enum vip_csc_state {
> + VIP_CSC_NA = 0,
> + VIP_CSC_Y2R,
> + VIP_CSC_R2Y,
> +};
> +
> +/* buffer for one video frame */
> +struct vip_buffer {
> + /* common v4l buffer stuff */
> + struct vb2_v4l2_buffer vb;
> + struct list_head list;
> + bool drop;
> +};
> +
> +/*
> + * struct vip_fmt - VIP media bus format information
> + * @fourcc: V4L2 pixel format FCC identifier
> + * @code: V4L2 media bus format code
> + * @colorspace: V4L2 colorspace identifier
> + * @coplanar: 1 if unpacked Luma and Chroma, 0 otherwise (packed/interleaved)
> + * @vpdma_fmt: VPDMA data format per plane.
> + * @finfo: Cache v4l2_format_info for associated fourcc
> + */
> +struct vip_fmt {
> + u32 fourcc;
> + u32 code;
> + u32 colorspace;
> + u8 coplanar;
> + const struct vpdma_data_format *vpdma_fmt[VIP_MAX_PLANES];
> + const struct v4l2_format_info *finfo;
> +};
> +
> +/*
> + * The vip_parser_data structures contains the memory mapped
> + * info to access the parser registers.
> + */
> +struct vip_parser_data {
> + void __iomem *base;
> + struct resource *res;
> +
> + struct platform_device *pdev;
> +};
> +
> +/*
> + * The vip_shared structure contains data that is shared by both
> + * the VIP1 and VIP2 slices.
> + */
> +struct vip_shared {
> + struct list_head list;
> + struct resource *res;
> + void __iomem *base;
> + struct vpdma_data vpdma_data;
> + struct vpdma_data *vpdma;
> + struct v4l2_device v4l2_dev;
> + struct vip_dev *devs[VIP_NUM_SLICES];
> + struct v4l2_ctrl_handler ctrl_handler;
> + const char *name;
> +};
> +
> +/*
> + * The vip_bt656_bus structure contains vip specific bt656 bus data.
> + */
> +struct vip_bt656_bus {
> + unsigned char num_channels;
> + unsigned char pixmux;
> + unsigned char channels[16];
> +};
> +
> +/*
> + * The vip_clk_polarity structure contains the regmap, offset and bit field
> + * definitions to control each port clock polarity.
> + */
> +struct vip_clk_polarity {
> + struct regmap *rm_pol;
> + u32 rm_offset;
> + u32 rm_bit_field[4];
> +};
> +/*
> + * There are two vip_dev structure, one for each vip slice: VIP1 & VIP2.
> + */
> +struct vip_dev {
> + struct v4l2_device *v4l2_dev;
> + struct platform_device *pdev;
> + struct vip_shared *shared;
> + struct resource *res;
> + struct vip_clk_polarity *pclk_pol;
> + int slice_id;
> + int num_ports; /* count of open ports */
> + struct mutex mutex;
> + spinlock_t slock;
> +
> + int irq;
> + void __iomem *base;
> +
> + struct vip_port *ports[VIP_NUM_PORTS];
> +
> + char name[16];
> + /* parser data handle */
> + struct vip_parser_data *parser;
> + /* scaler data handle */
> + struct sc_data *sc;
> + /* scaler port assignation */
> + int sc_assigned;
> + /* csc data handle */
> + struct csc_data *csc;
> + /* csc port assignation */
> + int csc_assigned;
> +};
> +
> +/*
> + * There are two vip_port structures for each vip_dev, one for port A
> + * and one for port B.
> + */
> +struct vip_port {
> + struct vip_dev *dev;
> + int port_id;
> +
> + unsigned int flags;
> + struct v4l2_rect c_rect; /* crop rectangle */
> + struct v4l2_mbus_framefmt mbus_framefmt;
> + struct v4l2_mbus_framefmt try_mbus_framefmt;
> +
> + const char *name;
> + struct vip_fmt *fmt; /* current format info */
> + /* Number of channels/streams configured */
> + int num_streams_configured;
> + int num_streams; /* count of open streams */
> + struct vip_stream *cap_streams[VIP_CAP_STREAMS_PER_PORT];
> +
> + struct v4l2_async_notifier notifier;
> + struct v4l2_subdev *subdev;
> + struct v4l2_fwnode_endpoint endpoint;
> + struct vip_bt656_bus bt656_endpoint;
> + unsigned int source_pad;
> + struct vip_fmt *active_fmt[VIP_MAX_ACTIVE_FMT];
> + int num_active_fmt;
> + /* have new shadow reg values */
> + bool load_mmrs;
> + /* shadow reg addr/data block */
> + struct vpdma_buf mmr_adb;
> + /* h coeff buffer */
> + struct vpdma_buf sc_coeff_h;
> + /* v coeff buffer */
> + struct vpdma_buf sc_coeff_v;
> + /* Show if scaler resource is available on this port */
> + bool scaler;
> + /* Show the csc resource state on this port */
> + enum vip_csc_state csc;
> +};
> +
> +/*
> + * When handling multiplexed video, there can be multiple streams for each
> + * port. The vip_stream structure holds per-stream data.
> + */
> +struct vip_stream {
> + struct video_device *vfd;
> + struct vip_port *port;
> + int stream_id;
> + int list_num;
> + int vfl_type;
> + char name[16];
> + struct work_struct recovery_work;
> + int num_recovery;
> + enum v4l2_field field; /* current field */
> + unsigned int sequence; /* current frame/field seq */
> + enum v4l2_field sup_field; /* supported field value */
> + unsigned int width; /* frame width */
> + unsigned int height; /* frame height */
> + unsigned int bytesperline; /* bytes per line in memory */
> + unsigned int sizeimage; /* image size in memory */
> + struct list_head vidq; /* incoming vip_bufs queue */
> + struct list_head dropq; /* drop vip_bufs queue */
> + struct list_head post_bufs; /* vip_bufs to be DMAed */
> + /* Maintain a list of used channels - Needed for VPDMA cleanup */
> + int vpdma_channels[VPDMA_MAX_CHANNELS];
> + int vpdma_channels_to_abort[VPDMA_MAX_CHANNELS];
> + struct vpdma_desc_list desc_list; /* DMA descriptor list */
> + struct vpdma_dtd *write_desc;
> + /* next unused desc_list addr */
> + void *desc_next;
> + struct vb2_queue vb_vidq;
> +};
> +
> +/*
> + * VIP Enumerations
> + */
> +enum data_path_select {
> + ALL_FIELDS_DATA_SELECT = 0,
> + VIP_CSC_SRC_DATA_SELECT,
> + VIP_SC_SRC_DATA_SELECT,
> + VIP_RGB_SRC_DATA_SELECT,
> + VIP_RGB_OUT_LO_DATA_SELECT,
> + VIP_RGB_OUT_HI_DATA_SELECT,
> + VIP_CHR_DS_1_SRC_DATA_SELECT,
> + VIP_CHR_DS_2_SRC_DATA_SELECT,
> + VIP_MULTI_CHANNEL_DATA_SELECT,
> + VIP_CHR_DS_1_DATA_BYPASS,
> + VIP_CHR_DS_2_DATA_BYPASS,
> +};
> +
> +
> +enum data_interface_modes {
> + SINGLE_24B_INTERFACE = 0,
> + SINGLE_16B_INTERFACE = 1,
> + DUAL_8B_INTERFACE = 2,
> +};
> +
> +enum sync_types {
> + EMBEDDED_SYNC_SINGLE_YUV422 = 0,
> + EMBEDDED_SYNC_2X_MULTIPLEXED_YUV422 = 1,
> + EMBEDDED_SYNC_4X_MULTIPLEXED_YUV422 = 2,
> + EMBEDDED_SYNC_LINE_MULTIPLEXED_YUV422 = 3,
> + DISCRETE_SYNC_SINGLE_YUV422 = 4,
> + EMBEDDED_SYNC_SINGLE_RGB_OR_YUV444 = 5,
> + DISCRETE_SYNC_SINGLE_RGB_24B = 10,
> +};
> +
> +#define VIP_NOT_ASSIGNED -1
> +
> +/*
> + * Register offsets and field selectors
> + */
> +#define VIP_PID_FUNC 0xf02
> +
> +#define VIP_PID 0x0000
> +#define VIP_PID_MINOR_MASK 0x3f
> +#define VIP_PID_MINOR_SHIFT 0
> +#define VIP_PID_CUSTOM_MASK 0x03
> +#define VIP_PID_CUSTOM_SHIFT 6
> +#define VIP_PID_MAJOR_MASK 0x07
> +#define VIP_PID_MAJOR_SHIFT 8
> +#define VIP_PID_RTL_MASK 0x1f
> +#define VIP_PID_RTL_SHIFT 11
> +#define VIP_PID_FUNC_MASK 0xfff
> +#define VIP_PID_FUNC_SHIFT 16
> +#define VIP_PID_SCHEME_MASK 0x03
> +#define VIP_PID_SCHEME_SHIFT 30
> +
> +#define VIP_SYSCONFIG 0x0010
> +#define VIP_SYSCONFIG_IDLE_MASK 0x03
> +#define VIP_SYSCONFIG_IDLE_SHIFT 2
> +#define VIP_SYSCONFIG_STANDBY_MASK 0x03
> +#define VIP_SYSCONFIG_STANDBY_SHIFT 4
> +#define VIP_FORCE_IDLE_MODE 0
> +#define VIP_NO_IDLE_MODE 1
> +#define VIP_SMART_IDLE_MODE 2
> +#define VIP_SMART_IDLE_WAKEUP_MODE 3
> +#define VIP_FORCE_STANDBY_MODE 0
> +#define VIP_NO_STANDBY_MODE 1
> +#define VIP_SMART_STANDBY_MODE 2
> +#define VIP_SMART_STANDBY_WAKEUP_MODE 3
> +
> +#define VIP_INTC_INTX_OFFSET 0x0020
> +
> +#define VIP_INT0_STATUS0_RAW_SET 0x0020
> +#define VIP_INT0_STATUS0_RAW VIP_INT0_STATUS0_RAW_SET
> +#define VIP_INT0_STATUS0_CLR 0x0028
> +#define VIP_INT0_STATUS0 VIP_INT0_STATUS0_CLR
> +#define VIP_INT0_ENABLE0_SET 0x0030
> +#define VIP_INT0_ENABLE0 VIP_INT0_ENABLE0_SET
> +#define VIP_INT0_ENABLE0_CLR 0x0038
> +#define VIP_INT0_LIST0_COMPLETE BIT(0)
> +#define VIP_INT0_LIST0_NOTIFY BIT(1)
> +#define VIP_INT0_LIST1_COMPLETE BIT(2)
> +#define VIP_INT0_LIST1_NOTIFY BIT(3)
> +#define VIP_INT0_LIST2_COMPLETE BIT(4)
> +#define VIP_INT0_LIST2_NOTIFY BIT(5)
> +#define VIP_INT0_LIST3_COMPLETE BIT(6)
> +#define VIP_INT0_LIST3_NOTIFY BIT(7)
> +#define VIP_INT0_LIST4_COMPLETE BIT(8)
> +#define VIP_INT0_LIST4_NOTIFY BIT(9)
> +#define VIP_INT0_LIST5_COMPLETE BIT(10)
> +#define VIP_INT0_LIST5_NOTIFY BIT(11)
> +#define VIP_INT0_LIST6_COMPLETE BIT(12)
> +#define VIP_INT0_LIST6_NOTIFY BIT(13)
> +#define VIP_INT0_LIST7_COMPLETE BIT(14)
> +#define VIP_INT0_LIST7_NOTIFY BIT(15)
> +#define VIP_INT0_DESCRIPTOR BIT(16)
> +#define VIP_VIP1_PARSER_INT BIT(20)
> +#define VIP_VIP2_PARSER_INT BIT(21)
> +
> +#define VIP_INT0_STATUS1_RAW_SET 0x0024
> +#define VIP_INT0_STATUS1_RAW VIP_INT0_STATUS0_RAW_SET
> +#define VIP_INT0_STATUS1_CLR 0x002c
> +#define VIP_INT0_STATUS1 VIP_INT0_STATUS0_CLR
> +#define VIP_INT0_ENABLE1_SET 0x0034
> +#define VIP_INT0_ENABLE1 VIP_INT0_ENABLE0_SET
> +#define VIP_INT0_ENABLE1_CLR 0x003c
> +#define VIP_INT0_ENABLE1_STAT 0x004c
> +#define VIP_INT0_CHANNEL_GROUP0 BIT(0)
> +#define VIP_INT0_CHANNEL_GROUP1 BIT(1)
> +#define VIP_INT0_CHANNEL_GROUP2 BIT(2)
> +#define VIP_INT0_CHANNEL_GROUP3 BIT(3)
> +#define VIP_INT0_CHANNEL_GROUP4 BIT(4)
> +#define VIP_INT0_CHANNEL_GROUP5 BIT(5)
> +#define VIP_INT0_CLIENT BIT(7)
> +#define VIP_VIP1_DS1_UV_ERROR_INT BIT(22)
> +#define VIP_VIP1_DS2_UV_ERROR_INT BIT(23)
> +#define VIP_VIP2_DS1_UV_ERROR_INT BIT(24)
> +#define VIP_VIP2_DS2_UV_ERROR_INT BIT(25)
> +
> +#define VIP_INTC_E0I 0x00a0
> +
> +#define VIP_CLK_ENABLE 0x0100
> +#define VIP_VPDMA_CLK_ENABLE BIT(0)
> +#define VIP_VIP1_DATA_PATH_CLK_ENABLE BIT(16)
> +#define VIP_VIP2_DATA_PATH_CLK_ENABLE BIT(17)
> +
> +#define VIP_CLK_RESET 0x0104
> +#define VIP_VPDMA_RESET BIT(0)
> +#define VIP_VPDMA_CLK_RESET_MASK 0x1
> +#define VIP_VPDMA_CLK_RESET_SHIFT 0
> +#define VIP_DATA_PATH_CLK_RESET_MASK 0x1
> +#define VIP_VIP1_DATA_PATH_RESET_SHIFT 16
> +#define VIP_VIP2_DATA_PATH_RESET_SHIFT 17
> +#define VIP_VIP1_DATA_PATH_RESET BIT(16)
> +#define VIP_VIP2_DATA_PATH_RESET BIT(17)
> +#define VIP_VIP1_PARSER_RESET BIT(18)
> +#define VIP_VIP2_PARSER_RESET BIT(19)
> +#define VIP_VIP1_CSC_RESET BIT(20)
> +#define VIP_VIP2_CSC_RESET BIT(21)
> +#define VIP_VIP1_SC_RESET BIT(22)
> +#define VIP_VIP2_SC_RESET BIT(23)
> +#define VIP_VIP1_DS1_RESET BIT(25)
> +#define VIP_VIP2_DS1_RESET BIT(26)
> +#define VIP_VIP1_DS2_RESET BIT(27)
> +#define VIP_VIP2_DS2_RESET BIT(28)
> +#define VIP_MAIN_RESET BIT(31)
> +
> +#define VIP_VIP1_DATA_PATH_SELECT 0x010c
> +#define VIP_VIP2_DATA_PATH_SELECT 0x0110
> +#define VIP_CSC_SRC_SELECT_MASK 0x07
> +#define VIP_CSC_SRC_SELECT_SHFT 0
> +#define VIP_SC_SRC_SELECT_MASK 0x07
> +#define VIP_SC_SRC_SELECT_SHFT 3
> +#define VIP_RGB_SRC_SELECT BIT(6)
> +#define VIP_RGB_OUT_LO_SRC_SELECT BIT(7)
> +#define VIP_RGB_OUT_HI_SRC_SELECT BIT(8)
> +#define VIP_DS1_SRC_SELECT_MASK 0x07
> +#define VIP_DS1_SRC_SELECT_SHFT 9
> +#define VIP_DS2_SRC_SELECT_MASK 0x07
> +#define VIP_DS2_SRC_SELECT_SHFT 12
> +#define VIP_MULTI_CHANNEL_SELECT BIT(15)
> +#define VIP_DS1_BYPASS BIT(16)
> +#define VIP_DS2_BYPASS BIT(17)
> +#define VIP_TESTPORT_B_SELECT BIT(26)
> +#define VIP_TESTPORT_A_SELECT BIT(27)
> +#define VIP_DATAPATH_SELECT_MASK 0x0f
> +#define VIP_DATAPATH_SELECT_SHFT 28
> +
> +#define VIP1_PARSER_REG_OFFSET 0x5500
> +#define VIP2_PARSER_REG_OFFSET 0x5a00
> +
> +#define VIP_PARSER_MAIN_CFG 0x0000
> +#define VIP_DATA_INTERFACE_MODE_MASK 0x03
> +#define VIP_DATA_INTERFACE_MODE_SHFT 0
> +#define VIP_CLIP_BLANK BIT(4)
> +#define VIP_CLIP_ACTIVE BIT(5)
> +
> +#define VIP_PARSER_PORTA_0 0x0004
> +#define VIP_PARSER_PORTB_0 0x000c
> +#define VIP_SYNC_TYPE_MASK 0x0f
> +#define VIP_SYNC_TYPE_SHFT 0
> +#define VIP_CTRL_CHANNEL_SEL_MASK 0x03
> +#define VIP_CTRL_CHANNEL_SEL_SHFT 4
> +#define VIP_ASYNC_FIFO_WR BIT(6)
> +#define VIP_ASYNC_FIFO_RD BIT(7)
> +#define VIP_PORT_ENABLE BIT(8)
> +#define VIP_FID_POLARITY BIT(9)
> +#define VIP_PIXCLK_EDGE_POLARITY BIT(10)
> +#define VIP_HSYNC_POLARITY BIT(11)
> +#define VIP_VSYNC_POLARITY BIT(12)
> +#define VIP_ACTVID_POLARITY BIT(13)
> +#define VIP_FID_DETECT_MODE BIT(14)
> +#define VIP_USE_ACTVID_HSYNC_ONLY BIT(15)
> +#define VIP_FID_SKEW_PRECOUNT_MASK 0x3f
> +#define VIP_FID_SKEW_PRECOUNT_SHFT 16
> +#define VIP_DISCRETE_BASIC_MODE BIT(22)
> +#define VIP_SW_RESET BIT(23)
> +#define VIP_FID_SKEW_POSTCOUNT_MASK 0x3f
> +#define VIP_FID_SKEW_POSTCOUNT_SHFT 24
> +#define VIP_ANALYZER_2X4X_SRCNUM_POS BIT(30)
> +#define VIP_ANALYZER_FVH_ERR_COR_EN BIT(31)
> +
> +#define VIP_PARSER_PORTA_1 0x0008
> +#define VIP_PARSER_PORTB_1 0x0010
> +#define VIP_SRC0_NUMLINES_MASK 0x0fff
> +#define VIP_SRC0_NUMLINES_SHFT 0
> +#define VIP_ANC_CHAN_SEL_8B_MASK 0x03
> +#define VIP_ANC_CHAN_SEL_8B_SHFT 13
> +#define VIP_SRC0_NUMPIX_MASK 0x0fff
> +#define VIP_SRC0_NUMPIX_SHFT 16
> +#define VIP_REPACK_SEL_MASK 0x07
> +#define VIP_REPACK_SEL_SHFT 28
> +
> +#define VIP_PARSER_FIQ_MASK 0x0014
> +#define VIP_PARSER_FIQ_CLR 0x0018
> +#define VIP_PARSER_FIQ_STATUS 0x001c
> +#define VIP_PORTA_VDET BIT(0)
> +#define VIP_PORTB_VDET BIT(1)
> +#define VIP_PORTA_ASYNC_FIFO_OF BIT(2)
> +#define VIP_PORTB_ASYNC_FIFO_OF BIT(3)
> +#define VIP_PORTA_OUTPUT_FIFO_YUV BIT(4)
> +#define VIP_PORTA_OUTPUT_FIFO_ANC BIT(6)
> +#define VIP_PORTB_OUTPUT_FIFO_YUV BIT(7)
> +#define VIP_PORTB_OUTPUT_FIFO_ANC BIT(9)
> +#define VIP_PORTA_CONN BIT(10)
> +#define VIP_PORTA_DISCONN BIT(11)
> +#define VIP_PORTB_CONN BIT(12)
> +#define VIP_PORTB_DISCONN BIT(13)
> +#define VIP_PORTA_SRC0_SIZE BIT(14)
> +#define VIP_PORTB_SRC0_SIZE BIT(15)
> +#define VIP_PORTA_YUV_PROTO_VIOLATION BIT(16)
> +#define VIP_PORTA_ANC_PROTO_VIOLATION BIT(17)
> +#define VIP_PORTB_YUV_PROTO_VIOLATION BIT(18)
> +#define VIP_PORTB_ANC_PROTO_VIOLATION BIT(19)
> +#define VIP_PORTA_CFG_DISABLE_COMPLETE BIT(20)
> +#define VIP_PORTB_CFG_DISABLE_COMPLETE BIT(21)
> +
> +#define VIP_PARSER_PORTA_SOURCE_FID 0x0020
> +#define VIP_PARSER_PORTA_ENCODER_FID 0x0024
> +#define VIP_PARSER_PORTB_SOURCE_FID 0x0028
> +#define VIP_PARSER_PORTB_ENCODER_FID 0x002c
> +
> +#define VIP_PARSER_PORTA_SRC0_SIZE 0x0030
> +#define VIP_PARSER_PORTB_SRC0_SIZE 0x0070
> +#define VIP_SOURCE_HEIGHT_MASK 0x0fff
> +#define VIP_SOURCE_HEIGHT_SHFT 0
> +#define VIP_SOURCE_WIDTH_MASK 0x0fff
> +#define VIP_SOURCE_WIDTH_SHFT 16
> +
> +#define VIP_PARSER_PORTA_VDET_VEC 0x00b0
> +#define VIP_PARSER_PORTB_VDET_VEC 0x00b4
> +
> +#define VIP_PARSER_PORTA_EXTRA2 0x00b8
> +#define VIP_PARSER_PORTB_EXTRA2 0x00c8
> +#define VIP_ANC_SKIP_NUMPIX_MASK 0x0fff
> +#define VIP_ANC_SKIP_NUMPIX_SHFT 0
> +#define VIP_ANC_BYPASS BIT(15)
> +#define VIP_ANC_USE_NUMPIX_MASK 0x0fff
> +#define VIP_ANC_USE_NUMPIX_SHFT 16
> +#define VIP_ANC_TARGET_SRCNUM_MASK 0x0f
> +#define VIP_ANC_TARGET_SRCNUM_SHFT 28
> +
> +#define VIP_PARSER_PORTA_EXTRA3 0x00bc
> +#define VIP_PARSER_PORTB_EXTRA3 0x00cc
> +#define VIP_ANC_SKIP_NUMLINES_MASK 0x0fff
> +#define VIP_ANC_SKIP_NUMLINES_SHFT 0
> +#define VIP_ANC_USE_NUMLINES_MASK 0x0fff
> +#define VIP_ANC_USE_NUMLINES_SHFT 16
> +
> +#define VIP_PARSER_PORTA_EXTRA4 0x00c0
> +#define VIP_PARSER_PORTB_EXTRA4 0x00d0
> +#define VIP_ACT_SKIP_NUMPIX_MASK 0x0fff
> +#define VIP_ACT_SKIP_NUMPIX_SHFT 0
> +#define VIP_ACT_BYPASS BIT(15)
> +#define VIP_ACT_USE_NUMPIX_MASK 0x0fff
> +#define VIP_ACT_USE_NUMPIX_SHFT 16
> +#define VIP_ACT_TARGET_SRCNUM_MASK 0x0f
> +#define VIP_ACT_TARGET_SRCNUM_SHFT 28
> +
> +#define VIP_PARSER_PORTA_EXTRA5 0x00c4
> +#define VIP_PARSER_PORTB_EXTRA5 0x00d4
> +#define VIP_ACT_SKIP_NUMLINES_MASK 0x0fff
> +#define VIP_ACT_SKIP_NUMLINES_SHFT 0
> +#define VIP_ACT_USE_NUMLINES_MASK 0x0fff
> +#define VIP_ACT_USE_NUMLINES_SHFT 16
> +
> +#define VIP_PARSER_PORTA_EXTRA6 0x00d8
> +#define VIP_PARSER_PORTB_EXTRA6 0x00dc
> +#define VIP_ANC_SRCNUM_STOP_IMM_SHFT 0
> +#define VIP_YUV_SRCNUM_STOP_IMM_SHFT 16
> +
> +#define VIP_CSC_CSC00 0x0200
> +#define VIP_CSC_A0_MASK 0x1fff
> +#define VIP_CSC_A0_SHFT 0
> +#define VIP_CSC_B0_MASK 0x1fff
> +#define VIP_CSC_B0_SHFT 16
> +
> +#define VIP_CSC_CSC01 0x0204
> +#define VIP_CSC_C0_MASK 0x1fff
> +#define VIP_CSC_C0_SHFT 0
> +#define VIP_CSC_A1_MASK 0x1fff
> +#define VIP_CSC_A1_SHFT 16
> +
> +#define VIP_CSC_CSC02 0x0208
> +#define VIP_CSC_B1_MASK 0x1fff
> +#define VIP_CSC_B1_SHFT 0
> +#define VIP_CSC_C1_MASK 0x1fff
> +#define VIP_CSC_C1_SHFT 16
> +
> +#define VIP_CSC_CSC03 0x020c
> +#define VIP_CSC_A2_MASK 0x1fff
> +#define VIP_CSC_A2_SHFT 0
> +#define VIP_CSC_B2_MASK 0x1fff
> +#define VIP_CSC_B2_SHFT 16
> +
> +#define VIP_CSC_CSC04 0x0210
> +#define VIP_CSC_C2_MASK 0x1fff
> +#define VIP_CSC_C2_SHFT 0
> +#define VIP_CSC_D0_MASK 0x0fff
> +#define VIP_CSC_D0_SHFT 16
> +
> +#define VIP_CSC_CSC05 0x0214
> +#define VIP_CSC_D1_MASK 0x0fff
> +#define VIP_CSC_D1_SHFT 0
> +#define VIP_CSC_D2_MASK 0x0fff
> +#define VIP_CSC_D2_SHFT 16
> +#define VIP_CSC_BYPASS BIT(28)
> +
> +#define VIP_SC_MP_SC0 0x0300
> +#define VIP_INTERLACE_O BIT(0)
> +#define VIP_LINEAR BIT(1)
> +#define VIP_SC_BYPASS BIT(2)
> +#define VIP_INVT_FID BIT(3)
> +#define VIP_USE_RAV BIT(4)
> +#define VIP_ENABLE_EV BIT(5)
> +#define VIP_AUTH_HS BIT(6)
> +#define VIP_DCM_2X BIT(7)
> +#define VIP_DCM_4X BIT(8)
> +#define VIP_HP_BYPASS BIT(9)
> +#define VIP_INTERLACE_I BIT(10)
> +#define VIP_ENABLE_SIN2_VER_INTP BIT(11)
> +#define VIP_Y_PK_EN BIT(14)
> +#define VIP_TRIM BIT(15)
> +#define VIP_SELFGEN_FID BIT(16)
> +
> +#define VIP_SC_MP_SC1 0x0304
> +#define VIP_ROW_ACC_INC_MASK 0x07ffffff
> +#define VIP_ROW_ACC_INC_SHFT 0
> +
> +#define VIP_SC_MP_SC2 0x0308
> +#define VIP_ROW_ACC_OFFSET_MASK 0x0fffffff
> +#define VIP_ROW_ACC_OFFSET_SHFT 0
> +
> +#define VIP_SC_MP_SC3 0x030c
> +#define VIP_ROW_ACC_OFFSET_B_MASK 0x0fffffff
> +#define VIP_ROW_ACC_OFFSET_B_SHFT 0
> +
> +#define VIP_SC_MP_SC4 0x0310
> +#define VIP_TAR_H_MASK 0x07ff
> +#define VIP_TAR_H_SHFT 0
> +#define VIP_TAR_W_MASK 0x07ff
> +#define VIP_TAR_W_SHFT 12
> +#define VIP_LIN_ACC_INC_U_MASK 0x07
> +#define VIP_LIN_ACC_INC_U_SHFT 24
> +#define VIP_NLIN_ACC_INIT_U_MASK 0x07
> +#define VIP_NLIN_ACC_INIT_U_SHFT 28
> +
> +#define VIP_SC_MP_SC5 0x0314
> +#define VIP_SRC_H_MASK 0x03ff
> +#define VIP_SRC_H_SHFT 0
> +#define VIP_SRC_W_MASK 0x07ff
> +#define VIP_SRC_W_SHFT 12
> +#define VIP_NLIN_ACC_INC_U_MASK 0x07
> +#define VIP_NLIN_ACC_INC_U_SHFT 24
> +
> +#define VIP_SC_MP_SC6 0x0318
> +#define VIP_ROW_ACC_INIT_RAV_MASK 0x03ff
> +#define VIP_ROW_ACC_INIT_RAV_SHFT 0
> +#define VIP_ROW_ACC_INIT_RAV_B_MASK 0x03ff
> +#define VIP_ROW_ACC_INIT_RAV_B_SHFT 10
> +
> +#define VIP_SC_MP_SC8 0x0320
> +#define VIP_NLIN_LEFT_MASK 0x07ff
> +#define VIP_NLIN_LEFT_SHFT 0
> +#define VIP_NLIN_RIGHT_MASK 0x07ff
> +#define VIP_NLIN_RIGHT_SHFT 12
> +
> +#define VIP_SC_MP_SC9 0x0324
> +#define VIP_LIN_ACC_INC VIP_SC_MP_SC9
> +
> +#define VIP_SC_MP_SC10 0x0328
> +#define VIP_NLIN_ACC_INIT VIP_SC_MP_SC10
> +
> +#define VIP_SC_MP_SC11 0x032c
> +#define VIP_NLIN_ACC_INC VIP_SC_MP_SC11
> +
> +#define VIP_SC_MP_SC12 0x0330
> +#define VIP_COL_ACC_OFFSET_MASK 0x01ffffff
> +#define VIP_COL_ACC_OFFSET_SHFT 0
> +
> +#define VIP_SC_MP_SC13 0x0334
> +#define VIP_SC_FACTOR_RAV_MASK 0x03ff
> +#define VIP_SC_FACTOR_RAV_SHFT 0
> +#define VIP_CHROMA_INTP_THR_MASK 0x03ff
> +#define VIP_CHROMA_INTP_THR_SHFT 12
> +#define VIP_DELTA_CHROMA_THR_MASK 0x0f
> +#define VIP_DELTA_CHROMA_THR_SHFT 24
> +
> +#define VIP_SC_MP_SC17 0x0344
> +#define VIP_EV_THR_MASK 0x03ff
> +#define VIP_EV_THR_SHFT 12
> +#define VIP_DELTA_LUMA_THR_MASK 0x0f
> +#define VIP_DELTA_LUMA_THR_SHFT 24
> +#define VIP_DELTA_EV_THR_MASK 0x0f
> +#define VIP_DELTA_EV_THR_SHFT 28
> +
> +#define VIP_SC_MP_SC18 0x0348
> +#define VIP_HS_FACTOR_MASK 0x03ff
> +#define VIP_HS_FACTOR_SHFT 0
> +#define VIP_CONF_DEFAULT_MASK 0x01ff
> +#define VIP_CONF_DEFAULT_SHFT 16
> +
> +#define VIP_SC_MP_SC19 0x034c
> +#define VIP_HPF_COEFF0_MASK 0xff
> +#define VIP_HPF_COEFF0_SHFT 0
> +#define VIP_HPF_COEFF1_MASK 0xff
> +#define VIP_HPF_COEFF1_SHFT 8
> +#define VIP_HPF_COEFF2_MASK 0xff
> +#define VIP_HPF_COEFF2_SHFT 16
> +#define VIP_HPF_COEFF3_MASK 0xff
> +#define VIP_HPF_COEFF3_SHFT 23
> +
> +#define VIP_SC_MP_SC20 0x0350
> +#define VIP_HPF_COEFF4_MASK 0xff
> +#define VIP_HPF_COEFF4_SHFT 0
> +#define VIP_HPF_COEFF5_MASK 0xff
> +#define VIP_HPF_COEFF5_SHFT 8
> +#define VIP_HPF_NORM_SHFT_MASK 0x07
> +#define VIP_HPF_NORM_SHFT_SHFT 16
> +#define VIP_NL_LIMIT_MASK 0x1ff
> +#define VIP_NL_LIMIT_SHFT 20
> +
> +#define VIP_SC_MP_SC21 0x0354
> +#define VIP_NL_LO_THR_MASK 0x01ff
> +#define VIP_NL_LO_THR_SHFT 0
> +#define VIP_NL_LO_SLOPE_MASK 0xff
> +#define VIP_NL_LO_SLOPE_SHFT 16
> +
> +#define VIP_SC_MP_SC22 0x0358
> +#define VIP_NL_HI_THR_MASK 0x01ff
> +#define VIP_NL_HI_THR_SHFT 0
> +#define VIP_NL_HI_SLOPE_SH_MASK 0x07
> +#define VIP_NL_HI_SLOPE_SH_SHFT 16
> +
> +#define VIP_SC_MP_SC23 0x035c
> +#define VIP_GRADIENT_THR_MASK 0x07ff
> +#define VIP_GRADIENT_THR_SHFT 0
> +#define VIP_GRADIENT_THR_RANGE_MASK 0x0f
> +#define VIP_GRADIENT_THR_RANGE_SHFT 12
> +#define VIP_MIN_GY_THR_MASK 0xff
> +#define VIP_MIN_GY_THR_SHFT 16
> +#define VIP_MIN_GY_THR_RANGE_MASK 0x0f
> +#define VIP_MIN_GY_THR_RANGE_SHFT 28
> +
> +#define VIP_SC_MP_SC24 0x0360
> +#define VIP_ORG_H_MASK 0x07ff
> +#define VIP_ORG_H_SHFT 0
> +#define VIP_ORG_W_MASK 0x07ff
> +#define VIP_ORG_W_SHFT 16
> +
> +#define VIP_SC_MP_SC25 0x0364
> +#define VIP_OFF_H_MASK 0x07ff
> +#define VIP_OFF_H_SHFT 0
> +#define VIP_OFF_W_MASK 0x07ff
> +#define VIP_OFF_W_SHFT 16
> +
> +#define VIP_VPDMA_REG_OFFSET 0xd000
> +
> +#endif
>
Regards,
Hans
^ permalink raw reply
* Re: [PATCH 1/2] hwmon: pwm-fan: Add profile support and add remove module support
From: Guenter Roeck @ 2020-05-26 11:45 UTC (permalink / raw)
To: Sandipan Patra, Uwe Kleine-König
Cc: Thierry Reding, Jonathan Hunter, kamil@wypas.org,
jdelvare@suse.com, robh+dt@kernel.org, Bibek Basu, Bitan Biswas,
linux-pwm@vger.kernel.org, linux-hwmon@vger.kernel.org,
devicetree@vger.kernel.org, linux-tegra@vger.kernel.org,
linux-kernel@vger.kernel.org
In-Reply-To: <BYAPR12MB30140CD3D7C7263594FD4F30ADB00@BYAPR12MB3014.namprd12.prod.outlook.com>
On 5/26/20 2:05 AM, Sandipan Patra wrote:
> Hi Uwe,
>
>
>
>> -----Original Message-----
>> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>> Sent: Tuesday, May 26, 2020 12:35 PM
>> To: Sandipan Patra <spatra@nvidia.com>
>> Cc: Thierry Reding <treding@nvidia.com>; Jonathan Hunter
>> <jonathanh@nvidia.com>; kamil@wypas.org; jdelvare@suse.com; linux@roeck-
>> us.net; robh+dt@kernel.org; Bibek Basu <bbasu@nvidia.com>; Bitan Biswas
>> <bbiswas@nvidia.com>; linux-pwm@vger.kernel.org; linux-
>> hwmon@vger.kernel.org; devicetree@vger.kernel.org; linux-
>> tegra@vger.kernel.org; linux-kernel@vger.kernel.org
>> Subject: Re: [PATCH 1/2] hwmon: pwm-fan: Add profile support and add remove
>> module support
>>
>> External email: Use caution opening links or attachments
>>
>>
>> On Tue, May 26, 2020 at 10:36:04AM +0530, Sandipan Patra wrote:
>>> This change has 2 parts:
>>> 1. Add support for profiles mode settings.
>>> This allows different fan settings for trip point temp/hyst/pwm.
>>> T194 has multiple fan-profiles support.
>>>
>>> 2. Add pwm-fan remove support. This is essential since the config is
>>> tristate capable.
>>
>> These two are orthogonal, aren't they? So they belong in two patches.
>>
>> You have to expand the binding documentation.
>>
>>> Signed-off-by: Sandipan Patra <spatra@nvidia.com>
>>> ---
>>> drivers/hwmon/pwm-fan.c | 112
>>> ++++++++++++++++++++++++++++++++++++++++++------
>>> 1 file changed, 100 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index
>>> 30b7b3e..26db589 100644
>>> --- a/drivers/hwmon/pwm-fan.c
>>> +++ b/drivers/hwmon/pwm-fan.c
>>> @@ -3,8 +3,10 @@
>>> * pwm-fan.c - Hwmon driver for fans connected to PWM lines.
>>> *
>>> * Copyright (c) 2014 Samsung Electronics Co., Ltd.
>>> + * Copyright (c) 2020, NVIDIA Corporation.
>>> *
>>> * Author: Kamil Debski <k.debski@samsung.com>
>>> + * Author: Sandipan Patra <spatra@nvidia.com>
>>> */
>>>
>>> #include <linux/hwmon.h>
>>> @@ -21,6 +23,8 @@
>>> #include <linux/timer.h>
>>>
>>> #define MAX_PWM 255
>>> +/* Based on OF max device tree node name length */
>>> +#define MAX_PROFILE_NAME_LENGTH 31
>>>
>>> struct pwm_fan_ctx {
>>> struct mutex lock;
>>> @@ -38,6 +42,12 @@ struct pwm_fan_ctx {
>>> unsigned int pwm_fan_state;
>>> unsigned int pwm_fan_max_state;
>>> unsigned int *pwm_fan_cooling_levels;
>>> +
>>> + unsigned int pwm_fan_profiles;
>>> + const char **fan_profile_names;
>>> + unsigned int **fan_profile_cooling_levels;
>>> + unsigned int fan_current_profile;
>>> +
>>> struct thermal_cooling_device *cdev; };
>>>
>>> @@ -227,28 +237,86 @@ static int pwm_fan_of_get_cooling_data(struct
>> device *dev,
>>> struct pwm_fan_ctx *ctx) {
>>> struct device_node *np = dev->of_node;
>>> + struct device_node *base_profile = NULL;
>>> + struct device_node *profile_np = NULL;
>>> + const char *default_profile = NULL;
>>> int num, i, ret;
>>>
>>> - if (!of_find_property(np, "cooling-levels", NULL))
>>> - return 0;
>>> + num = of_property_count_u32_elems(np, "cooling-levels");
>>> + if (num <= 0) {
>>> + base_profile = of_get_child_by_name(np, "profiles");
>>> + if (!base_profile) {
>>> + dev_err(dev, "Wrong Data\n");
>>> + return -EINVAL;
>>> + }
>>> + }
>>> +
>>> + if (base_profile) {
>>> + ctx->pwm_fan_profiles =
>>> + of_get_available_child_count(base_profile);
>>> +
>>> + if (ctx->pwm_fan_profiles <= 0) {
>>> + dev_err(dev, "Profiles used but not defined\n");
>>> + return -EINVAL;
>>> + }
>>>
>>> - ret = of_property_count_u32_elems(np, "cooling-levels");
>>> - if (ret <= 0) {
>>> - dev_err(dev, "Wrong data!\n");
>>> - return ret ? : -EINVAL;
>>> + ctx->fan_profile_names = devm_kzalloc(dev,
>>> + sizeof(const char *) * ctx->pwm_fan_profiles,
>>> + GFP_KERNEL);
>>> + ctx->fan_profile_cooling_levels = devm_kzalloc(dev,
>>> + sizeof(int *) * ctx->pwm_fan_profiles,
>>> + GFP_KERNEL);
>>> +
>>> + if (!ctx->fan_profile_names
>>> + || !ctx->fan_profile_cooling_levels)
>>> + return -ENOMEM;
>>> +
>>> + ctx->fan_current_profile = 0;
>>> + i = 0;
>>> + for_each_available_child_of_node(base_profile, profile_np) {
>>> + num = of_property_count_u32_elems(profile_np,
>>> + "cooling-levels");
>>> + if (num <= 0) {
>>> + dev_err(dev, "No data in cooling-levels inside profile
>> node!\n");
>>> + return -EINVAL;
>>> + }
>>> +
>>> + of_property_read_string(profile_np, "name",
>>> + &ctx->fan_profile_names[i]);
>>> + if (default_profile &&
>>> + !strncmp(default_profile,
>>> + ctx->fan_profile_names[i],
>>> + MAX_PROFILE_NAME_LENGTH))
>>> + ctx->fan_current_profile = i;
>>> +
>>> + ctx->fan_profile_cooling_levels[i] =
>>> + devm_kzalloc(dev, sizeof(int) * num,
>>> + GFP_KERNEL);
>>> + if (!ctx->fan_profile_cooling_levels[i])
>>> + return -ENOMEM;
>>> +
>>> + of_property_read_u32_array(profile_np, "cooling-levels",
>>> + ctx->fan_profile_cooling_levels[i], num);
>>> + i++;
>>> + }
>>> }
>>>
>>> - num = ret;
>>> ctx->pwm_fan_cooling_levels = devm_kcalloc(dev, num, sizeof(u32),
>>> GFP_KERNEL);
>>> if (!ctx->pwm_fan_cooling_levels)
>>> return -ENOMEM;
>>>
>>> - ret = of_property_read_u32_array(np, "cooling-levels",
>>> - ctx->pwm_fan_cooling_levels, num);
>>> - if (ret) {
>>> - dev_err(dev, "Property 'cooling-levels' cannot be read!\n");
>>> - return ret;
>>> + if (base_profile) {
>>> + memcpy(ctx->pwm_fan_cooling_levels,
>>> + ctx->fan_profile_cooling_levels[ctx->fan_current_profile],
>>> + num);
>>> + } else {
>>> + ret = of_property_read_u32_array(np, "cooling-levels",
>>> + ctx->pwm_fan_cooling_levels, num);
>>> + if (ret) {
>>> + dev_err(dev, "Property 'cooling-levels' cannot be read!\n");
>>> + return -EINVAL;
>>> + }
>>> }
>>>
>>> for (i = 0; i < num; i++) {
>>> @@ -390,6 +458,25 @@ static int pwm_fan_probe(struct platform_device
>> *pdev)
>>> return 0;
>>> }
>>>
>>> +static int pwm_fan_remove(struct platform_device *pdev) {
>>> + struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev);
>>> + struct pwm_args args;
>>> +
>>> + if (!ctx)
>>> + return -EINVAL;
>>> +
>>> + if (IS_ENABLED(CONFIG_THERMAL))
>>> + thermal_cooling_device_unregister(ctx->cdev);
>>> +
>>> + pwm_get_args(ctx->pwm, &args);
>>> + pwm_config(ctx->pwm, 0, args.period);
>>> + pwm_disable(ctx->pwm);
>>
>> What is what you really here? Is it only that the PWM stops oscillating, or is it
>> crucial that the output goes to its inactive level?
>>
>> (The intended semantic of pwm_disable includes that the output goes low, but
>> not all implementations enforce this.)
>>
>> Also please don't introduce new users of pwm_config() and pwm_disable() use
>> pwm_apply() instead.
>>
>> I wonder if this unregistration is "safe". When the driver is in use I'd expect that
>> the hwmon device doesn't go away and so the devm unregistration callback that
>> belongs to
>> devm_hwmon_device_register_with_groups() blocks. But at this time the PWM
>> is already stopped and so the device stops functioning earlier.
>>
>> Best regards
>> Uwe
>>
>
> Thanks for reviewing the changes.
>
> I see that pwm_fan_shutdown() which has got merged recently, can also be used for
> module remove functionality. May be it will need a little bit of tweak in the code.
> However I should have not made both multiple profiles support and fan remove functionality on
> same patch.
>
Pointing out explicitly:
ret = devm_add_action_or_reset(dev, pwm_fan_pwm_disable, ctx);
cdev = devm_thermal_of_cooling_device_register(dev, ...)
Guenter
^ permalink raw reply
* Re: [PATCH v7 2/4] usb: dwc3: qcom: Add interconnect support in dwc3 driver
From: Felipe Balbi @ 2020-05-26 11:43 UTC (permalink / raw)
To: Georgi Djakov, Sandeep Maheswaram (Temp), Bjorn Andersson
Cc: Matthias Kaehlcke, Andy Gross, Greg Kroah-Hartman, Rob Herring,
Mark Rutland, Stephen Boyd, Doug Anderson, linux-arm-msm,
linux-usb, devicetree, linux-kernel, Manu Gautam,
Chandana Kishori Chiluveru, Viresh Kumar
In-Reply-To: <0723aee9-9ea4-dab5-e083-3cf3858a8f96@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 889 bytes --]
Hi,
Georgi Djakov <georgi.djakov@linaro.org> writes:
> On 26.05.20 14:04, Sandeep Maheswaram (Temp) wrote:
>> Hi Felipe,
>>
>> Please let me know how to go forward with this patch
(don't top-post!)
> Please just add a patch to fix the allmodconfig error. Felipe has
> suggested to introduce a separate patch which exports the
> device_is_bound() function. This export should precede the addition
> of interconnect support.
>
> Also regarding the "depends on INTERCONNECT || !INTERCONNECT" change,
> no "depends on" would be needed, as we just made the interconnect
> framework bool.
y'all have lost the current merge window, I guess. I'm not sure Greg
will take last minute changes to drivers base and I have already sent
him my pull request for v5.8. On the plus side, this gives you the
chance to run hundreds of randbuilds with your patches.
--
balbi
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply
* Re: [PATCH 1/2] hwmon: pwm-fan: Add profile support and add remove module support
From: Guenter Roeck @ 2020-05-26 11:42 UTC (permalink / raw)
To: Sandipan Patra, treding, jonathanh, u.kleine-koenig, kamil,
jdelvare, robh+dt
Cc: bbasu, bbiswas, linux-pwm, linux-hwmon, devicetree, linux-tegra,
linux-kernel
In-Reply-To: <1590469565-14953-1-git-send-email-spatra@nvidia.com>
On 5/25/20 10:06 PM, Sandipan Patra wrote:
> This change has 2 parts:
> 1. Add support for profiles mode settings.
> This allows different fan settings for trip point temp/hyst/pwm.
> T194 has multiple fan-profiles support.
>
> 2. Add pwm-fan remove support. This is essential since the config is
> tristate capable.
>
> Signed-off-by: Sandipan Patra <spatra@nvidia.com>
> ---
> drivers/hwmon/pwm-fan.c | 112 ++++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 100 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 30b7b3e..26db589 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
[ ... ]
>
> +static int pwm_fan_remove(struct platform_device *pdev)
> +{
> + struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev);
> + struct pwm_args args;
> +
> + if (!ctx)
> + return -EINVAL;
> +
> + if (IS_ENABLED(CONFIG_THERMAL))
> + thermal_cooling_device_unregister(ctx->cdev);
> +
> + pwm_get_args(ctx->pwm, &args);
> + pwm_config(ctx->pwm, 0, args.period);
> + pwm_disable(ctx->pwm);
> +
> + return 0;
> +}
> +
I don't think you actually tested this. I would suggest to make
yourself familiar with 'devm' functions and their use, and
then resubmit.
Thanks,
Guenter
^ permalink raw reply
* Re: [PATCH 1/2] arm64: dts: Add a device tree for the Librem5 phone
From: Daniel Baluta @ 2020-05-26 11:39 UTC (permalink / raw)
To: Martin Kepplinger
Cc: Rob Herring, kernel, Shawn Guo, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, dl-linux-imx, mchehab,
Anson Huang, Guido Günther, Angus Ainslie (Purism),
Linux Kernel Mailing List, Devicetree List, linux-arm-kernel
In-Reply-To: <20200514155737.12160-1-martin.kepplinger@puri.sm>
On Thu, May 14, 2020 at 7:02 PM Martin Kepplinger
<martin.kepplinger@puri.sm> wrote:
>
> From: "Angus Ainslie (Purism)" <angus@akkea.ca>
>
> Add a devicetree description for the Librem 5 phone. The early batches
> that have been sold are supported as well as the mass-produced device
> available later this year, see https://puri.sm/products/librem-5/
>
> This boots to a working console with working WWAN modem, wifi usdhc,
> IMU sensor device, proximity sensor, haptic motor, gpio keys, GNSS and LEDs.
>
> Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca>
> Signed-off-by: Guido Günther <agx@sigxcpu.org>
For audio related part:
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
^ permalink raw reply
* Re: [PATCH v7 2/4] usb: dwc3: qcom: Add interconnect support in dwc3 driver
From: Georgi Djakov @ 2020-05-26 11:34 UTC (permalink / raw)
To: Sandeep Maheswaram (Temp), Bjorn Andersson, Felipe Balbi
Cc: Matthias Kaehlcke, Andy Gross, Greg Kroah-Hartman, Rob Herring,
Mark Rutland, Stephen Boyd, Doug Anderson, linux-arm-msm,
linux-usb, devicetree, linux-kernel, Manu Gautam,
Chandana Kishori Chiluveru, Viresh Kumar
In-Reply-To: <b20775ba-7870-b0ca-7c65-d72a08fdacb2@codeaurora.org>
On 26.05.20 14:04, Sandeep Maheswaram (Temp) wrote:
> Hi Felipe,
>
> Please let me know how to go forward with this patch
>
Hi Sandeep,
Please just add a patch to fix the allmodconfig error. Felipe has
suggested to introduce a separate patch which exports the
device_is_bound() function. This export should precede the addition
of interconnect support.
Also regarding the "depends on INTERCONNECT || !INTERCONNECT" change,
no "depends on" would be needed, as we just made the interconnect
framework bool.
Thanks,
Georgi
> Regards
>
> Sandeep
>
> On 5/19/2020 12:05 AM, Bjorn Andersson wrote:
>> On Thu 14 May 23:29 PDT 2020, Felipe Balbi wrote:
>>
>>> Hi,
>>>
>>> Georgi Djakov <georgi.djakov@linaro.org> writes:
>>>>>>>>> Sandeep Maheswaram <sanm@codeaurora.org> writes:
>>>>>>>>>> +static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
>>>>>>>>>> +{
>>>>>>>>>> + struct device *dev = qcom->dev;
>>>>>>>>>> + int ret;
>>>>>>>>>> +
>>>>>>>>>> + if (!device_is_bound(&qcom->dwc3->dev))
>>>>>>>>>> + return -EPROBE_DEFER;
>>>>>>>>> this breaks allmodconfig. I'm dropping this series from my
>>>>>>>>> queue for
>>>>>>>>> this merge window.
>>>>>>>> Sorry, I meant this patch ;-)
>>>>>>> I guess that's due to INTERCONNECT being a module. There is
>>>>>>> currently a
>>>>>> I believe it's because of this:
>>>>>> ERROR: modpost: "device_is_bound" [drivers/usb/dwc3/dwc3-qcom.ko]
>>>>>> undefined!
>>>>>>
>>>>>>> discussion about this with Viresh and Georgi in response to another
>>>>>>> automated build failure. Viresh suggests changing
>>>>>>> CONFIG_INTERCONNECT
>>>>>>> from tristate to bool, which seems sensible to me given that
>>>>>>> interconnect
>>>>>>> is a core subsystem.
>>>>>> The problem you are talking about would arise when INTERCONNECT=m and
>>>>>> USB_DWC3_QCOM=y and it definitely exists here and could be
>>>>>> triggered with
>>>>>> randconfig build. So i suggest to squash also the diff below.
>>>>>>
>>>>>> Thanks,
>>>>>> Georgi
>>>>>>
>>>>>> ---8<---
>>>>>> diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
>>>>>> index 206caa0ea1c6..6661788b1a76 100644
>>>>>> --- a/drivers/usb/dwc3/Kconfig
>>>>>> +++ b/drivers/usb/dwc3/Kconfig
>>>>>> @@ -129,6 +129,7 @@ config USB_DWC3_QCOM
>>>>>> tristate "Qualcomm Platform"
>>>>>> depends on ARCH_QCOM || COMPILE_TEST
>>>>>> depends on EXTCON || !EXTCON
>>>>>> + depends on INTERCONNECT || !INTERCONNECT
>>>>> I would prefer to see a patch adding EXPORT_SYMBOL_GPL() to
>>>>> device_is_bound()
>>>> Agree, but just to clarify, that these are two separate issues that
>>>> need to
>>>> be fixed. The device_is_bound() is the first one and USB_DWC3_QCOM=y
>>>> combined
>>>> with INTERCONNECT=m is the second one.
>>> If INTERCONNECT=m, QCOM3 shouldn't be y. I think the following is
>>> enough:
>>>
>>> depends on INTERCONNECT=y || INTERCONNECT=USB_DWC3_QCOM
>>>
>> This misses the case where INTERCONNECT=n and USB_DWC3_QCOM=[ym] which
>> I don't see a reason for breaking.
>>
>> But if only INTERCONNECT where a bool, then we don't need to specify a
>> depends on, because it will either be there, or the stubs will.
>> We've come to this conclusion in a lot of different frameworks and I
>> don't see why we should do this differently with INTERCONNECT.
>>
>> Regards,
>> Bjorn
>
^ permalink raw reply
* Re: [PATCH v3 3/5] drm: panel: Add Xingbangda XBD599 panel (ST7703 controller)
From: Linus Walleij @ 2020-05-26 11:32 UTC (permalink / raw)
To: Ondrej Jirman
Cc: linux-sunxi, Thierry Reding, Sam Ravnborg, David Airlie,
Daniel Vetter, Rob Herring, Maxime Ripard, Chen-Yu Tsai,
Icenowy Zheng, open list:DRM PANEL DRIVERS,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
linux-kernel@vger.kernel.org, Linux ARM, Samuel Holland,
Martijn Braam, Luca Weiss, Bhushan Shah
In-Reply-To: <20200513212451.1919013-4-megous@megous.com>
Hi Ondrej,
I see you took over this driver submission from
Icenowy.
On Wed, May 13, 2020 at 11:24 PM Ondrej Jirman <megous@megous.com> wrote:
> From: Icenowy Zheng <icenowy@aosc.io>
>
> Xingbangda XBD599 is a 5.99" 720x1440 MIPI-DSI IPS LCD panel made by
> Xingbangda, which is used on PinePhone final assembled phones.
>
> It is based on Sitronix ST7703 LCD controller.
>
> Add support for it.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
> Signed-off-by: Ondrej Jirman <megous@megous.com>
(...)
> create mode 100644 drivers/gpu/drm/panel/panel-sitronix-st7703.c
Nice!
> + /*
> + * Init sequence was supplied by the panel vendor.
> + */
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETEXTC,
> + 0xF1, 0x12, 0x83);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETMIPI,
> + 0x33, 0x81, 0x05, 0xF9, 0x0E, 0x0E, 0x20, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x25,
> + 0x00, 0x91, 0x0a, 0x00, 0x00, 0x02, 0x4F, 0x11,
> + 0x00, 0x00, 0x37);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETPOWER_EXT,
> + 0x25, 0x22, 0x20, 0x03);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETRGBIF,
> + 0x10, 0x10, 0x05, 0x05, 0x03, 0xFF, 0x00, 0x00,
> + 0x00, 0x00);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETSCR,
> + 0x73, 0x73, 0x50, 0x50, 0x00, 0xC0, 0x08, 0x70,
> + 0x00);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETVDC, 0x4E);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETPANEL, 0x0B);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETCYC, 0x80);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETDISP, 0xF0, 0x12, 0xF0);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETEQ,
> + 0x00, 0x00, 0x0B, 0x0B, 0x10, 0x10, 0x00, 0x00,
> + 0x00, 0x00, 0xFF, 0x00, 0xC0, 0x10);
> + dsi_dcs_write_seq(dsi, 0xC6, 0x01, 0x00, 0xFF, 0xFF, 0x00);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETPOWER,
> + 0x74, 0x00, 0x32, 0x32, 0x77, 0xF1, 0xFF, 0xFF,
> + 0xCC, 0xCC, 0x77, 0x77);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETBGP, 0x07, 0x07);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETVCOM, 0x2C, 0x2C);
> + dsi_dcs_write_seq(dsi, 0xBF, 0x02, 0x11, 0x00);
> +
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETGIP1,
> + 0x82, 0x10, 0x06, 0x05, 0xA2, 0x0A, 0xA5, 0x12,
> + 0x31, 0x23, 0x37, 0x83, 0x04, 0xBC, 0x27, 0x38,
> + 0x0C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0C, 0x00,
> + 0x03, 0x00, 0x00, 0x00, 0x75, 0x75, 0x31, 0x88,
> + 0x88, 0x88, 0x88, 0x88, 0x88, 0x13, 0x88, 0x64,
> + 0x64, 0x20, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
> + 0x02, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETGIP2,
> + 0x02, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x02, 0x46, 0x02, 0x88,
> + 0x88, 0x88, 0x88, 0x88, 0x88, 0x64, 0x88, 0x13,
> + 0x57, 0x13, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
> + 0x75, 0x88, 0x23, 0x14, 0x00, 0x00, 0x02, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0A,
> + 0xA5, 0x00, 0x00, 0x00, 0x00);
> + dsi_dcs_write_seq(dsi, ST7703_CMD_SETGAMMA,
> + 0x00, 0x09, 0x0D, 0x23, 0x27, 0x3C, 0x41, 0x35,
> + 0x07, 0x0D, 0x0E, 0x12, 0x13, 0x10, 0x12, 0x12,
> + 0x18, 0x00, 0x09, 0x0D, 0x23, 0x27, 0x3C, 0x41,
> + 0x35, 0x07, 0x0D, 0x0E, 0x12, 0x13, 0x10, 0x12,
> + 0x12, 0x18);
> + msleep(20);
This stuff is really hard or impossible to understand without the
datasheet.
In my previous review I wrote:
It appears that the Himax HX8363 is using the same display controller
if you look at the datasheet:
http://www.datasheet-pdf.com/PDF/HX8369-A-Datasheet-Himax-729024
There you find an explanation to some of the commands.
That means, try to get rid of as much of the magic bytes as you can
and use proper #defines. I know it takes some work but the result
is so much more useful and readable.
Further I wrote:
You should definately insert code to read the MTP bytes:
0xDA manufacturer
0xDB driver version
0xDC LCD module/driver
And print these, se e.g. my newly added NT35510 driver or
the Sony ACX424AKP driver.
So please do that.
Yours,
Linus Walleij
^ permalink raw reply
* Re: [PATCH v3 2/5] dt-bindings: panel: Add binding for Xingbangda XBD599 panel
From: Linus Walleij @ 2020-05-26 11:22 UTC (permalink / raw)
To: Ondrej Jirman
Cc: linux-sunxi, Thierry Reding, Sam Ravnborg, David Airlie,
Daniel Vetter, Rob Herring, Maxime Ripard, Chen-Yu Tsai,
Icenowy Zheng, open list:DRM PANEL DRIVERS,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
linux-kernel@vger.kernel.org, Linux ARM, Samuel Holland,
Martijn Braam, Luca Weiss, Bhushan Shah
In-Reply-To: <20200513212451.1919013-3-megous@megous.com>
On Wed, May 13, 2020 at 11:24 PM Ondrej Jirman <megous@megous.com> wrote:
> From: Icenowy Zheng <icenowy@aosc.io>
>
> Xingbangda XBD599 is a 5.99" 720x1440 MIPI-DSI LCD panel. It is based on
> Sitronix ST7703 LCD controller.
>
> Add its device tree binding.
>
> Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
> Signed-off-by: Ondrej Jirman <megous@megous.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply
* Re: [PATCH v7 2/4] usb: dwc3: qcom: Add interconnect support in dwc3 driver
From: Sandeep Maheswaram (Temp) @ 2020-05-26 11:04 UTC (permalink / raw)
To: Bjorn Andersson, Felipe Balbi
Cc: Georgi Djakov, Matthias Kaehlcke, Andy Gross, Greg Kroah-Hartman,
Rob Herring, Mark Rutland, Stephen Boyd, Doug Anderson,
linux-arm-msm, linux-usb, devicetree, linux-kernel, Manu Gautam,
Chandana Kishori Chiluveru, Viresh Kumar
In-Reply-To: <20200518183512.GE2165@builder.lan>
Hi Felipe,
Please let me know how to go forward with this patch
Regards
Sandeep
On 5/19/2020 12:05 AM, Bjorn Andersson wrote:
> On Thu 14 May 23:29 PDT 2020, Felipe Balbi wrote:
>
>> Hi,
>>
>> Georgi Djakov <georgi.djakov@linaro.org> writes:
>>>>>>>> Sandeep Maheswaram <sanm@codeaurora.org> writes:
>>>>>>>>> +static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
>>>>>>>>> +{
>>>>>>>>> + struct device *dev = qcom->dev;
>>>>>>>>> + int ret;
>>>>>>>>> +
>>>>>>>>> + if (!device_is_bound(&qcom->dwc3->dev))
>>>>>>>>> + return -EPROBE_DEFER;
>>>>>>>> this breaks allmodconfig. I'm dropping this series from my queue for
>>>>>>>> this merge window.
>>>>>>> Sorry, I meant this patch ;-)
>>>>>> I guess that's due to INTERCONNECT being a module. There is currently a
>>>>> I believe it's because of this:
>>>>> ERROR: modpost: "device_is_bound" [drivers/usb/dwc3/dwc3-qcom.ko] undefined!
>>>>>
>>>>>> discussion about this with Viresh and Georgi in response to another
>>>>>> automated build failure. Viresh suggests changing CONFIG_INTERCONNECT
>>>>>> from tristate to bool, which seems sensible to me given that interconnect
>>>>>> is a core subsystem.
>>>>> The problem you are talking about would arise when INTERCONNECT=m and
>>>>> USB_DWC3_QCOM=y and it definitely exists here and could be triggered with
>>>>> randconfig build. So i suggest to squash also the diff below.
>>>>>
>>>>> Thanks,
>>>>> Georgi
>>>>>
>>>>> ---8<---
>>>>> diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
>>>>> index 206caa0ea1c6..6661788b1a76 100644
>>>>> --- a/drivers/usb/dwc3/Kconfig
>>>>> +++ b/drivers/usb/dwc3/Kconfig
>>>>> @@ -129,6 +129,7 @@ config USB_DWC3_QCOM
>>>>> tristate "Qualcomm Platform"
>>>>> depends on ARCH_QCOM || COMPILE_TEST
>>>>> depends on EXTCON || !EXTCON
>>>>> + depends on INTERCONNECT || !INTERCONNECT
>>>> I would prefer to see a patch adding EXPORT_SYMBOL_GPL() to device_is_bound()
>>> Agree, but just to clarify, that these are two separate issues that need to
>>> be fixed. The device_is_bound() is the first one and USB_DWC3_QCOM=y combined
>>> with INTERCONNECT=m is the second one.
>> If INTERCONNECT=m, QCOM3 shouldn't be y. I think the following is
>> enough:
>>
>> depends on INTERCONNECT=y || INTERCONNECT=USB_DWC3_QCOM
>>
> This misses the case where INTERCONNECT=n and USB_DWC3_QCOM=[ym] which
> I don't see a reason for breaking.
>
> But if only INTERCONNECT where a bool, then we don't need to specify a
> depends on, because it will either be there, or the stubs will.
> We've come to this conclusion in a lot of different frameworks and I
> don't see why we should do this differently with INTERCONNECT.
>
> Regards,
> Bjorn
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
^ permalink raw reply
* Re: [PATCH v2 6/6] dt-bindings: drm: bridge: adi,adv7511.txt: convert to yaml
From: Geert Uytterhoeven @ 2020-05-26 10:39 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Ricardo Cañuelo, Collabora Kernel ML,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
Linux ARM, Geert Uytterhoeven, Rob Herring, Wei Xu
In-Reply-To: <20200526101158.GA5903@pendragon.ideasonboard.com>
Hi Laurent,
On Tue, May 26, 2020 at 12:12 PM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
> On Tue, May 26, 2020 at 09:03:09AM +0200, Geert Uytterhoeven wrote:
> > On Tue, May 26, 2020 at 3:44 AM Laurent Pinchart wrote:
> > > On Mon, May 25, 2020 at 09:43:35AM +0200, Ricardo Cañuelo wrote:
> > > > On jue 14-05-2020 18:22:39, Laurent Pinchart wrote:
> > > > > > If we want to be more strict and require the definition of all the
> > > > > > supplies, there will be many more DTs changes in the series, and I'm not
> > > > > > sure I'll be able to do that in a reasonable amount of time. I'm looking
> > > > > > at them and it's not always clear which regulators to use or if they are
> > > > > > even defined.
> > > > >
> > > > > We can decouple the two though (I think). The bindings should reflect
> > > > > what we consider right, and the dts files could be fixed on top.
> > > >
> > > > Do you have a suggestion on how to do this? If we decouple the two
> > > > tasks most of the work would be searching for DTs to fix and finding a
> > > > way to fix each one of them, and unless I do this _before_ the binding
> > > > conversion I'll get a lot of dtbs_check errors.
> > >
> > > Rob should answer this question as it will be his decision, but I've
> > > personally never considered non-compliant DT sources to be an obstacle
> > > to bindings conversion to YAML. The DT sources should be fixed, but I
> > > don't see it as a prerequisite (although it's a good practice).
> >
> > I do my best to avoid introducing regressions when the binding conversions
> > go upstream.
>
> Please note that we're not talking about runtime regressions, as drivers
> are not updated. It's "only" dtbs_check that would produce new errors.
Exactly. I was talking about "make dtbs_check" regressions, too.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply
* Re: [PATCH 4/4] i2c: stm32f7: Add SMBus-specific protocols support
From: Alain Volmat @ 2020-05-26 10:39 UTC (permalink / raw)
To: Wolfram Sang
Cc: Benjamin Tissoires, robh+dt, mark.rutland, pierre-yves.mordret,
mcoquelin.stm32, alexandre.torgue, linux-i2c, devicetree,
linux-stm32, linux-arm-kernel, linux-kernel, fabrice.gasnier
In-Reply-To: <20200523110140.GD3459@ninjato>
On Sat, May 23, 2020 at 01:01:40PM +0200, Wolfram Sang wrote:
>
> > +static int stm32f7_i2c_reg_client(struct i2c_client *client)
> > +{
> > + struct stm32f7_i2c_dev *i2c_dev = i2c_get_adapdata(client->adapter);
> > + int ret;
> > +
> > + if (client->flags & I2C_CLIENT_HOST_NOTIFY) {
> > + /* Only enable on the first device registration */
> > + if (atomic_inc_return(&i2c_dev->host_notify_cnt) == 1) {
> > + ret = stm32f7_i2c_enable_smbus_host(i2c_dev);
> > + if (ret) {
> > + dev_err(i2c_dev->dev,
> > + "failed to enable SMBus host notify (%d)\n",
> > + ret);
> > + return ret;
> > + }
> > + }
> > + }
> > +
> > + return 0;
> > +}
>
> So, as mentioned in the other review, I'd like to evaluate other
> possibilities for the above:
>
> - One option is to enable it globally in probe(). Then you lose the
> possibility to have a device at address 0x08.
I'd prefer avoid this solution to not lose the address 0x08.
> - Enable it in probe() only if there is a generic binding "host-notify".
Do you mean having the adapter walk through childs node and see if at least
one of them have the host-notify property ? This mean that such solution
wouldn't work for device relying on platform data rather than DT nodes.
> - Let the core scan for a device with HOST_NOTIFY when registering an
> adapter and then call back into the driver somehow?
You mean at adapter registration time only ? Not device probing time ?
At probing time, we could have the core (i2c_device_probe) check for the flag
HOST_NOTIFY and if setted call a dedicated host-notify reg callback ?
>
> Other ideas?
>
^ permalink raw reply
* Re: [PATCH v5 6/8] drm/panel: Add ilitek ili9341 panel driver
From: Noralf Trønnes @ 2020-05-26 10:38 UTC (permalink / raw)
To: dillon min, Andy Shevchenko
Cc: Linus Walleij, Mark Brown, devicetree, linux-arm Mailing List,
Linux Kernel Mailing List, linux-spi, linux-stm32, dri-devel,
linux-clk, Sam Ravnborg
In-Reply-To: <CAL9mu0+jmcivC6zAXxK0-oXy3n44pAU1QGD7BDq=CT2D7twROQ@mail.gmail.com>
Den 26.05.2020 11.08, skrev dillon min:
> Hi Andy,
>
> Thanks for input.
>
> On Tue, May 26, 2020 at 3:46 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
>>
>> On Mon, May 25, 2020 at 6:46 AM <dillon.minfei@gmail.com> wrote:
>>>
>>> From: dillon min <dillon.minfei@gmail.com>
>>>
>>> This driver combine tiny/ili9341.c mipi_dbi_interface driver
>>> with mipi_dpi_interface driver, can support ili9341 with serial
>>> mode or parallel rgb interface mode by register configuration.
>>
>> Noralf told once that this driver should be unified with mi0283qt.c.
>>
>> So, what should we do here?
>>
>> --
>> With Best Regards,
>> Andy Shevchenko
>
> from sam's suggestion, we can't setup two drivers to support one panel
> in the tree. so, i copy the mipi dbi part from tiny/ili9341.c. to this driver
> from register settings and dts binding is keep the same to tiny/ili9341.c.
>
> so, in my opinion if tiny/ili9341.c is unified with mi0283qt.c, this
> driver should be
> too.
>
There's a discussion about MIPI DBI panels here:
MIPI DSI, DBI, and tinydrm drivers
https://lists.freedesktop.org/archives/dri-devel/2020-May/267031.html
Noralf.
> thanks.
>
> best regards,
>
> Dillon,
>
^ permalink raw reply
* Re: [PATCH 3/4] dt-bindings: i2c-stm32: add SMBus Alert bindings
From: Alain Volmat @ 2020-05-26 10:31 UTC (permalink / raw)
To: wsa@kernel.org
Cc: Rob Herring, mark.rutland@arm.com, Pierre Yves MORDRET,
mcoquelin.stm32@gmail.com, Alexandre TORGUE,
linux-i2c@vger.kernel.org, devicetree@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Fabrice GASNIER
In-Reply-To: <20200523103601.GA3459@ninjato>
On Sat, May 23, 2020 at 10:36:01AM +0000, wsa@kernel.org wrote:
>
> > > > + st,smbus-alert:
> > > > + description: Enable the SMBus Alert feature
> > > > + $ref: /schemas/types.yaml#/definitions/flag
> > > > +
> > >
> > > We already have smbus_alert interrupt. Can't you just check for this in
> > > the slave nodes and enable if found?
> >
> > My understanding reading the code (smbalert_probe within i2c-smbus.c, of_i2c_setup_smbus_alert called when
> > registering an adapter within i2c-core-smbus.c) is that smbus_alert refers to an interrupt on the
> > adapter side. That is an interrupt that would be triggered when the adapter is receiving an smbus_alert
> > message.
> > In our case (stm32f7), we do not have specific interrupt for that purpose. The interrupt triggered when
> > an SMBUS Alert is received (by the adapter) is the same interrupt as for other reasons and we check
> > within the irq handler within stm32f7 the reason before calling i2c_handle_smbus_alert if the status
> > register indicated an SMBUS Alert.
> > So my understanding is that we cannot rely on the mechanism of naming an interrupt smbus_alert.
> > Did I misunderstood something ?
>
> I just wonder what is bad about specifying the same interrupt twice in
> the interrupt properties? You could then check in probe if "smbus_alert"
> is populated and if it matches the main irq.
>
Here's my understanding of the current implementation.
During the adapter registration, the function of_i2c_setup_smbus_alert is called
and if a interrupt is named "smbus_alert" in the adapter node, a new device
"smbus_alert" will be created. This will leads to smbalert_probe to be called,
and a request_irq will be done with the irq value read from the adapter node.
This means that we will have both our handle (the handler of the main irq
of the stm32 i2c driver) and the smbus_alert handler on the same irq. Leading
to smbus_alert being called everytime there is a irq (most of the time not
smbus_alert related) coming from the stm32_i2c. (since this is our main irq).
So to me this approach can't work. I'd understand if the smbus_alert property
was on the client node in the same way as it is done for host-notify however
that's not the case.
This is why I was proposing to have our own st,smbus-alert property to decide
to enable or not the smbus_alert. In our case, we cannot rely on the mechanism
done by of_i2c_setup_smbus_alert since for us, smbus_alert irq is just one
case of all the other stm32 i2c irq. (this is the same irq, and we check after
by reading the interrupt status register).
^ permalink raw reply
* Re: [PATCH 1/4] i2c: smbus: add core function handling SMBus host-notify
From: Alain Volmat @ 2020-05-26 10:23 UTC (permalink / raw)
To: Wolfram Sang
Cc: Benjamin Tissoires, robh+dt@kernel.org, mark.rutland@arm.com,
Pierre Yves MORDRET, mcoquelin.stm32@gmail.com, Alexandre TORGUE,
linux-i2c@vger.kernel.org, devicetree@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Fabrice GASNIER
In-Reply-To: <20200523104624.GB3459@ninjato>
On Sat, May 23, 2020 at 10:46:25AM +0000, Wolfram Sang wrote:
>
> Adding Benjamin who mainly implemented this.
>
> On Tue, May 05, 2020 at 07:51:08AM +0200, Alain Volmat wrote:
> > SMBus Host-Notify protocol, from the adapter point of view
> > consist of receiving a message from a client, including the
> > client address and some other data.
> >
> > It can be simply handled by creating a new slave device
> > and registering a callback performing the parsing of the
> > message received from the client.
> >
> > This commit introduces two new core functions
> > * i2c_new_smbus_host_notify_device
> > * i2c_free_smbus_host_notify_device
> > that take care of registration of the new slave device and
> > callback and will call i2c_handle_smbus_host_notify once a
> > Host-Notify event is received.
>
> Yay, cool idea to use the slave interface. I like it a lot!
>
> > +static int i2c_smbus_host_notify_cb(struct i2c_client *client,
> > + enum i2c_slave_event event, u8 *val)
> > +{
> > + struct i2c_smbus_host_notify_status *status = client->dev.platform_data;
> > + int ret;
> > +
> > + switch (event) {
> > + case I2C_SLAVE_WRITE_REQUESTED:
> > + status->notify_start = true;
> > + break;
> > + case I2C_SLAVE_WRITE_RECEIVED:
> > + /* We only retrieve the first byte received (addr)
> > + * since there is currently no way to retrieve the data
> > + * parameter from the client.
>
> Maybe s/no way/no support/ ? I still wonder if we couldn't add it
> somehow. Once we find a device which needs this, of course.
Indeed. Such support can be added later on once such device is found. For the
time being I will state "no support"
>
> > + */
> > + if (!status->notify_start)
> > + break;
> > + status->addr = *val;
> > + status->notify_start = false;
> > + break;
> > + case I2C_SLAVE_STOP:
>
> What about setting 'notify_start' to false here as well? In the case of
> an incomplete write?
Ok. I will check that notify_start is false before calling host_notify
(since otherwise it will call i2c_handle_smbus_host_notify with a bad addr
value) and reset notify_start to false if it is still true.
>
> > + ret = i2c_handle_smbus_host_notify(client->adapter,
> > + status->addr);
> > + if (ret < 0) {
> > + dev_warn(&client->adapter->dev, "failed to handle host_notify (%d)\n",
> > + ret);
>
> I think we should rather add such error strings to the core if we think
> they are needed. I am not convinced they are, though.
Agreed, this error can be removed.
>
> > + return ret;
> > + }
> > + break;
> > + default:
> > + /* Only handle necessary events */
> > + break;
> > + }
> > +
> > + return 0;
> > +}
> > +
>
> Rest of the code looks good. Maybe we should compile all this only when
> I2C_SLAVE is enabled?
>
Yes, I will enclose that around I2C_SLAVE support check.
^ permalink raw reply
* Re: [PATCH v2 00/91] drm/vc4: Support BCM2711 Display Pipelin
From: Maxime Ripard @ 2020-05-26 10:20 UTC (permalink / raw)
To: Jian-Hong Pan
Cc: Nicolas Saenz Julienne, Eric Anholt, dri-devel, linux-rpi-kernel,
bcm-kernel-feedback-list, linux-arm-kernel, Linux Kernel,
devicetree, linux-clk, linux-i2c, Linux Upstreaming Team
In-Reply-To: <CAPpJ_ed9TMJjN8xS1_3saf5obQhULJSLNgQSAFxgiWM2QX9A7Q@mail.gmail.com>
Hi,
On Mon, May 11, 2020 at 11:12:05AM +0800, Jian-Hong Pan wrote:
> Jian-Hong Pan <jian-hong@endlessm.com> 於 2020年5月8日 週五 下午2:20寫道:
> >
> > Maxime Ripard <maxime@cerno.tech> 於 2020年5月8日 週五 上午1:22寫道:
> > >
> > > On Mon, May 04, 2020 at 02:35:08PM +0800, Jian-Hong Pan wrote:
> > > > Maxime Ripard <maxime@cerno.tech> 於 2020年4月29日 週三 上午12:21寫道:
> > > > >
> > > > > Hi,
> > > > >
> > > > > On Mon, Apr 27, 2020 at 03:23:42PM +0800, Jian-Hong Pan wrote:
> > > > > > Hi Maxime,
> > > > > >
> > > > > > Thanks for your V2 patch series! I'm testing it.
> > > > > >
> > > > > > This patch series is applied upon mainline kernel 5.7-rc2 cleanly and built.
> > > > > > System can boot into console text mode, but no graphic UI.
> > > > > >
> > > > > > Get the error in vc5_hdmi_phy_init(), and full dmesg is at [1]:
> > > > > >
> > > > > > [ 5.587543] vc4_hdmi fef00700.hdmi: Unknown register ID 46
> > > > > > [ 5.587700] debugfs: Directory 'fef00700.hdmi' with parent 'vc4-hdmi' already present!
> > > > > > [ 5.588070] vc4_hdmi fef00700.hdmi: vc4-hdmi-hifi <-> fef00700.hdmi mapping ok
> > > > > > [ 5.588076] vc4_hdmi fef00700.hdmi: ASoC: no DMI vendor name!
> > > > > > [ 5.588263] vc4-drm gpu: bound fef00700.hdmi (ops vc4_hdmi_ops)
> > > > > > [ 5.588299] vc4_hdmi fef05700.hdmi: Unknown register ID 46
> > > > > > [ 5.588373] debugfs: Directory 'vc4-hdmi' with parent 'asoc' already present!
> > > > > > [ 5.588673] vc4_hdmi fef05700.hdmi: vc4-hdmi-hifi <-> fef05700.hdmi mapping ok
> > > > > > [ 5.588677] vc4_hdmi fef05700.hdmi: ASoC: no DMI vendor name!
> > > > > > [ 5.588809] vc4-drm gpu: bound fef05700.hdmi (ops vc4_hdmi_ops)
> > > > > > [ 5.588854] vc4-drm gpu: bound fe806000.vec (ops vc4_vec_ops)
> > > > > > [ 5.588897] vc4-drm gpu: bound fe004000.txp (ops vc4_txp_ops)
> > > > > > [ 5.588934] vc4-drm gpu: bound fe400000.hvs (ops vc4_hvs_ops)
> > > > > > [ 5.588990] vc4-drm gpu: bound fe206000.pixelvalve (ops vc4_crtc_ops)
> > > > > > [ 5.589030] vc4-drm gpu: bound fe207000.pixelvalve (ops vc4_crtc_ops)
> > > > > > [ 5.589074] vc4-drm gpu: bound fe20a000.pixelvalve (ops vc4_crtc_ops)
> > > > > > [ 5.589106] vc4-drm gpu: bound fe216000.pixelvalve (ops vc4_crtc_ops)
> > > > > > [ 5.589145] vc4-drm gpu: bound fec12000.pixelvalve (ops vc4_crtc_ops)
> > > > > > [ 5.589294] checking generic (3e513000 6d8c00) vs hw (0 ffffffffffffffff)
> > > > > > [ 5.589297] fb0: switching to vc4drmfb from simple
> > > > > > [ 5.589433] Console: switching to colour dummy device 80x25
> > > > > > [ 5.589481] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
> > > > > > [ 5.589816] [drm] Initialized vc4 0.0.0 20140616 for gpu on minor 0
> > > > > > [ 5.601079] ------------[ cut here ]------------
> > > > > > [ 5.601095] WARNING: CPU: 2 PID: 127 at drivers/gpu/drm/vc4/vc4_hdmi_phy.c:413 vc5_hdmi_phy_init+0x7ac/0x2078
> > > > > > [ 5.601097] Modules linked in:
> > > > > > [ 5.601103] CPU: 2 PID: 127 Comm: kworker/2:1 Not tainted 5.7.0-rc2-00091-ga181df59a930 #7
> > > > > > [ 5.601105] Hardware name: Raspberry Pi 4 Model B (DT)
> > > > > > [ 5.601112] Workqueue: events deferred_probe_work_func
> > > > > > [ 5.601116] pstate: 20000005 (nzCv daif -PAN -UAO)
> > > > > > [ 5.601119] pc : vc5_hdmi_phy_init+0x7ac/0x2078
> > > > > > [ 5.601123] lr : vc4_hdmi_encoder_enable+0x1b8/0x1ac0
> > > > > > [ 5.601124] sp : ffff80001217b410
> > > > > > [ 5.601126] x29: ffff80001217b410 x28: ffff0000ec6370f0
> > > > > > [ 5.601129] x27: ffff0000f650d400 x26: 000000008a500000
> > > > > > [ 5.601132] x25: ffff8000113b4ac0 x24: 0000000000002060
> > > > > > [ 5.601135] x23: 000000000a500000 x22: 0000000000000300
> > > > > > [ 5.601137] x21: 0000000008d9ee20 x20: ffff0000ec535080
> > > > > > [ 5.601140] x19: 000000010989e7c0 x18: 0000000000000000
> > > > > > [ 5.601142] x17: 0000000000000001 x16: 0000000000005207
> > > > > > [ 5.601145] x15: 00004932ad293c92 x14: 0000000000000137
> > > > > > [ 5.601147] x13: ffff800010015000 x12: 0000000000000001
> > > > > > [ 5.601150] x11: 0000000000000001 x10: 0000000000000000
> > > > > > [ 5.601152] x9 : 0000000000000000 x8 : ffff800010015038
> > > > > > [ 5.601154] x7 : 0000000000000001 x6 : ffff80001217b368
> > > > > > [ 5.601157] x5 : 0000000000000000 x4 : 000000000000004c
> > > > > > [ 5.601159] x3 : 0000000000000000 x2 : ffff8000113b4ac0
> > > > > > [ 5.601162] x1 : ffff8000120c5f44 x0 : 00000000dc8984ff
> > > > > > [ 5.601164] Call trace:
> > > > > > [ 5.601169] vc5_hdmi_phy_init+0x7ac/0x2078
> > > > > > [ 5.601172] vc4_hdmi_encoder_enable+0x1b8/0x1ac0
> > > > > > [ 5.601176] drm_atomic_helper_commit_modeset_enables+0x224/0x248
> > > > > > [ 5.601179] vc4_atomic_complete_commit+0x400/0x558
> > > > > > [ 5.601182] vc4_atomic_commit+0x1e0/0x200
> > > > > > [ 5.601185] drm_atomic_commit+0x4c/0x60
> > > > > > [ 5.601190] drm_client_modeset_commit_atomic.isra.0+0x17c/0x238
> > > > > > [ 5.601192] drm_client_modeset_commit_locked+0x5c/0x198
> > > > > > [ 5.601195] drm_client_modeset_commit+0x30/0x58
> > > > > > [ 5.601201] drm_fb_helper_restore_fbdev_mode_unlocked+0x78/0xe0
> > > > > > [ 5.601204] drm_fb_helper_set_par+0x30/0x68
> > > > > > [ 5.601208] fbcon_init+0x3d4/0x598
> > > > > > [ 5.601212] visual_init+0xb0/0x108
> > > > > > [ 5.601214] do_bind_con_driver+0x1d0/0x3a8
> > > > > > [ 5.601217] do_take_over_console+0x144/0x208
> > > > > > [ 5.601219] do_fbcon_takeover+0x68/0xd8
> > > > > > [ 5.601222] fbcon_fb_registered+0x100/0x118
> > > > > > [ 5.601226] register_framebuffer+0x1f4/0x338
> > > > > > [ 5.601229] __drm_fb_helper_initial_config_and_unlock+0x2f8/0x4a0
> > > > > > [ 5.601232] drm_fbdev_client_hotplug+0xd4/0x1b0
> > > > > > [ 5.601235] drm_fbdev_generic_setup+0xb0/0x130
> > > > > > [ 5.601238] vc4_drm_bind+0x184/0x1a0
> > > > > > [ 5.601241] try_to_bring_up_master+0x168/0x1c8
> > > > > > [ 5.601244] __component_add+0xa4/0x170
> > > > > > [ 5.601246] component_add+0x14/0x20
> > > > > > [ 5.601248] vc4_vec_dev_probe+0x20/0x30
> > > > > > [ 5.601252] platform_drv_probe+0x54/0xa8
> > > > > > [ 5.601254] really_probe+0xd8/0x320
> > > > > > [ 5.601256] driver_probe_device+0x58/0xf0
> > > > > > [ 5.601258] __device_attach_driver+0x84/0xc8
> > > > > > [ 5.601263] bus_for_each_drv+0x78/0xc8
> > > > > > [ 5.601265] __device_attach+0xe4/0x140
> > > > > > [ 5.601267] device_initial_probe+0x14/0x20
> > > > > > [ 5.601269] bus_probe_device+0x9c/0xa8
> > > > > > [ 5.601271] deferred_probe_work_func+0x74/0xb0
> > > > > > [ 5.601276] process_one_work+0x1bc/0x338
> > > > > > [ 5.601279] worker_thread+0x1f8/0x428
> > > > > > [ 5.601282] kthread+0x138/0x158
> > > > > > [ 5.601286] ret_from_fork+0x10/0x1c
> > > > > > [ 5.601288] ---[ end trace cfba0996218c3f3d ]---
> > > > >
> > > > > Thanks for testing!
> > > > >
> > > > > Do you have a bit more details regarding your setup? Was it connected to an
> > > > > external display?
> > > >
> > > > Yes, the HDMI cable is connected to HDMI0 port on RPi 4.
> > > >
> > > > > If so, do you know the resolution it was trying to setup?
> > > >
> > > > According to the log, I think it is 1920x1080:
> > > > Apr 27 15:37:25 endless gdm-Xorg-:0[1960]: (II) modeset(0): Output
> > > > HDMI-1 connected
> > > > Apr 27 15:37:25 endless gdm-Xorg-:0[1960]: (II) modeset(0): Output
> > > > HDMI-2 disconnected
> > > > Apr 27 15:37:25 endless gdm-Xorg-:0[1960]: (II) modeset(0): Output
> > > > Composite-1 disconnected
> > > > Apr 27 15:37:25 endless gdm-Xorg-:0[1960]: (II) modeset(0): Using
> > > > exact sizes for initial modes
> > > > Apr 27 15:37:25 endless gdm-Xorg-:0[1960]: (II) modeset(0): Output
> > > > HDMI-1 using initial mode 1920x1080 +0+0
> > > >
> > > > https://gist.github.com/starnight/45e1468bfa0426a54d2fb4a9269cfb94
> > >
> > > It looks to be fairly standard then, and I'm testing on the same resolution so
> > > it should be alright.
> > >
> > > Given from your log, it looks like you're running as arm64 though, while I stuck
> > > with arm32, so it could be the explanation.
> >
> > Yes, I build it as arm64.
> >
> > > Can you share your config.txt and .config so that I can try to reproduce it
> > > here?
> >
> > Here is the config
> > https://gist.github.com/starnight/320b757441b6769c36160704b401c98b
>
> Here is the only one line in config.txt:
> enable_uart=1
>
> Actually, we make the Raspberry Pi's firmware bring up U-Boot, then
> U-Boot boots kernel.
I gave it a try with U-Boot with my latest work and couldn't reproduce it, so it
seems that I fixed it along the way
Maxime
^ permalink raw reply
* Re: [PATCH v2 6/6] dt-bindings: drm: bridge: adi,adv7511.txt: convert to yaml
From: Laurent Pinchart @ 2020-05-26 10:11 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Ricardo Cañuelo, Collabora Kernel ML,
open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
Linux ARM, Geert Uytterhoeven, Rob Herring, Wei Xu
In-Reply-To: <CAMuHMdXinhY13us9rt9h7EvrT_8zhnQg6tmOBtA0nEQ=1G1O7Q@mail.gmail.com>
Hi Geert,
On Tue, May 26, 2020 at 09:03:09AM +0200, Geert Uytterhoeven wrote:
> On Tue, May 26, 2020 at 3:44 AM Laurent Pinchart wrote:
> > On Mon, May 25, 2020 at 09:43:35AM +0200, Ricardo Cañuelo wrote:
> > > On jue 14-05-2020 18:22:39, Laurent Pinchart wrote:
> > > > > If we want to be more strict and require the definition of all the
> > > > > supplies, there will be many more DTs changes in the series, and I'm not
> > > > > sure I'll be able to do that in a reasonable amount of time. I'm looking
> > > > > at them and it's not always clear which regulators to use or if they are
> > > > > even defined.
> > > >
> > > > We can decouple the two though (I think). The bindings should reflect
> > > > what we consider right, and the dts files could be fixed on top.
> > >
> > > Do you have a suggestion on how to do this? If we decouple the two
> > > tasks most of the work would be searching for DTs to fix and finding a
> > > way to fix each one of them, and unless I do this _before_ the binding
> > > conversion I'll get a lot of dtbs_check errors.
> >
> > Rob should answer this question as it will be his decision, but I've
> > personally never considered non-compliant DT sources to be an obstacle
> > to bindings conversion to YAML. The DT sources should be fixed, but I
> > don't see it as a prerequisite (although it's a good practice).
>
> I do my best to avoid introducing regressions when the binding conversions
> go upstream.
Please note that we're not talking about runtime regressions, as drivers
are not updated. It's "only" dtbs_check that would produce new errors.
> FTR, hence patches 1-3 are already in v5.7-rc7.
--
Regards,
Laurent Pinchart
^ permalink raw reply
* Re: [PATCH v3 05/10] media: i2c: imx290: Add configurable link frequency and pixel rate
From: Sakari Ailus @ 2020-05-26 9:58 UTC (permalink / raw)
To: Andrey Konovalov
Cc: mchehab, manivannan.sadhasivam, linux-media, linux-kernel,
devicetree, linux-arm-kernel, c.barrett, a.brela, peter.griffin
In-Reply-To: <91992bdb-deb1-0355-e61f-78c38a68f6d1@linaro.org>
Hi Andrey,
On Tue, May 26, 2020 at 12:27:17PM +0300, Andrey Konovalov wrote:
> Hi Sakari,
>
> Thank you for the review!
You're welcome!
>
> On 26.05.2020 12:12, Sakari Ailus wrote:
> > Hi Andrey,
> >
> > On Sun, May 24, 2020 at 10:25:00PM +0300, Andrey Konovalov wrote:
> > > From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > >
> > > IMX290 operates with multiple link frequency and pixel rate combinations.
> > > The initial driver used a single setting for both but since we now have
> > > the lane count support in place, let's add configurable link frequency
> > > and pixel rate.
> > >
> > > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
> > > Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
> > > ---
> > > drivers/media/i2c/imx290.c | 100 ++++++++++++++++++++++++-------------
> > > 1 file changed, 66 insertions(+), 34 deletions(-)
> > >
> > > diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
> > > index a361c9ac8bd5..e800557cf423 100644
> > > --- a/drivers/media/i2c/imx290.c
> > > +++ b/drivers/media/i2c/imx290.c
> > > @@ -38,8 +38,6 @@
> > > #define IMX290_HMAX_2_720 0x19C8
> > > #define IMX290_HMAX_4_720 0x0CE4
> > > -#define IMX290_DEFAULT_LINK_FREQ 445500000
> > > -
> > > static const char * const imx290_supply_name[] = {
> > > "vdda",
> > > "vddd",
> > > @@ -56,8 +54,6 @@ struct imx290_regval {
> > > struct imx290_mode {
> > > u32 width;
> > > u32 height;
> > > - u32 pixel_rate;
> > > - u32 link_freq_index;
> > > const struct imx290_regval *data;
> > > u32 data_size;
> > > @@ -248,8 +244,13 @@ static const struct imx290_regval imx290_10bit_settings[] = {
> > > };
> > > /* supported link frequencies */
> > > -static const s64 imx290_link_freq[] = {
> > > - IMX290_DEFAULT_LINK_FREQ,
> > > +static const s64 imx290_link_freq_2lanes[] = {
> > > + 891000000, /* 1920x1080 - 2 lane */
> > > + 594000000, /* 1280x720 - 2 lane */
> > > +};
> > > +static const s64 imx290_link_freq_4lanes[] = {
> > > + 445500000, /* 1920x1080 - 4 lane */
> > > + 297000000, /* 1280x720 - 4 lane */
> > > };
> > > /* Mode configs */
> > > @@ -259,16 +260,12 @@ static const struct imx290_mode imx290_modes[] = {
> > > .height = 1080,
> > > .data = imx290_1080p_settings,
> > > .data_size = ARRAY_SIZE(imx290_1080p_settings),
> > > - .pixel_rate = 178200000,
> > > - .link_freq_index = 0,
> > > },
> > > {
> > > .width = 1280,
> > > .height = 720,
> > > .data = imx290_720p_settings,
> > > .data_size = ARRAY_SIZE(imx290_720p_settings),
> > > - .pixel_rate = 178200000,
> > > - .link_freq_index = 0,
> > > },
> > > };
> > > @@ -442,6 +439,32 @@ static int imx290_get_fmt(struct v4l2_subdev *sd,
> > > return 0;
> > > }
> > > +static u8 imx290_get_link_freq_index(struct imx290 *imx290)
> > > +{
> > > + const struct imx290_mode *cur_mode = imx290->current_mode;
> > > +
> > > + return (cur_mode->width == 1920) ? 0 : 1;
> >
> > Could you use (imx290->current_mode - imx290_modes) / sizeof(*imx290_modes)
> > or something like that? It'd have fewer chances of breaking if new modes
> > are added.
> >
> > > +}
> > > +
> > > +static s64 imx290_get_link_freq(struct imx290 *imx290)
> > > +{
> > > + u8 index = imx290_get_link_freq_index(imx290);
> > > +
> > > + if (imx290->nlanes == 4)
> > > + return imx290_link_freq_4lanes[index];
> > > + else
> > > + return imx290_link_freq_2lanes[index];
> >
> > Or even better: store the link frequencies to the modes themselves. They
> > are a property of the modes after all.
>
> Then we will get two sets (for 2 lanes and for 4 lanes) of two modes (1080p and 720p), right?
Correct.
>
> > > +}
> > > +
> > > +static u64 imx290_calc_pixel_rate(struct imx290 *imx290)
> > > +{
> > > + s64 link_freq = imx290_get_link_freq(imx290);
> > > + u8 nlanes = imx290->nlanes;
> > > +
> > > + /* pixel rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
> > > + return (link_freq * 2 * nlanes / 10);
> > > +}
> > > +
> > > static int imx290_set_fmt(struct v4l2_subdev *sd,
> > > struct v4l2_subdev_pad_config *cfg,
> > > struct v4l2_subdev_format *fmt)
> > > @@ -475,10 +498,14 @@ static int imx290_set_fmt(struct v4l2_subdev *sd,
> > > format = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
> > > } else {
> > > format = &imx290->current_format;
> > > - __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index);
> > > - __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate, mode->pixel_rate);
> > > -
> > > imx290->current_mode = mode;
> > > +
> > > + if (imx290->link_freq)
> > > + __v4l2_ctrl_s_ctrl(imx290->link_freq,
> > > + imx290_get_link_freq_index(imx290));
> > > + if (imx290->pixel_rate)
> > > + __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate,
> > > + imx290_calc_pixel_rate(imx290));
> > > }
> > > *format = fmt->format;
> > > @@ -502,12 +529,11 @@ static int imx290_entity_init_cfg(struct v4l2_subdev *subdev,
> > > return 0;
> > > }
> > > -static int imx290_write_current_format(struct imx290 *imx290,
> > > - struct v4l2_mbus_framefmt *format)
> > > +static int imx290_write_current_format(struct imx290 *imx290)
> > > {
> > > int ret;
> > > - switch (format->code) {
> > > + switch (imx290->current_format.code) {
> > > case MEDIA_BUS_FMT_SRGGB10_1X10:
> > > ret = imx290_set_register_array(imx290, imx290_10bit_settings,
> > > ARRAY_SIZE(
> > > @@ -558,8 +584,8 @@ static int imx290_start_streaming(struct imx290 *imx290)
> > > return ret;
> > > }
> > > - /* Set current frame format */
> > > - ret = imx290_write_current_format(imx290, &imx290->current_format);
> > > + /* Apply the register values related to current frame format */
> > > + ret = imx290_write_current_format(imx290);
> > > if (ret < 0) {
> > > dev_err(imx290->dev, "Could not set frame format\n");
> > > return ret;
> > > @@ -821,12 +847,6 @@ static int imx290_probe(struct i2c_client *client)
> > > goto free_err;
> > > }
> > > - if (imx290->ep.link_frequencies[0] != IMX290_DEFAULT_LINK_FREQ) {
> >
> > This check needs to be modified to correspond to the driver's new
> > capabilities, not removed.
>
> Agreed.
> Do I understand correct that as the driver uses two link frequencies
> for a given number of lanes now, it must check that *the both* frequencies
> (for the given number of lanes) are listed in the device tree node?
Yes. The smiapp driver does this, for example.
--
Sakari Ailus
^ permalink raw reply
* Re: [PATCH v4 2/6] dt-bindings: interrupt-controller: Add Loongson HTVEC
From: Marc Zyngier @ 2020-05-26 9:53 UTC (permalink / raw)
To: Jiaxun Yang
Cc: Rob Herring, Thomas Gleixner, Jason Cooper, Huacai Chen,
linux-kernel, devicetree, linux-mips
In-Reply-To: <20200526172653.0a19f375@halation.net.flygoat.com>
On 2020-05-26 10:26, Jiaxun Yang wrote:
> On Mon, 25 May 2020 11:12:26 +0100
> Marc Zyngier <maz@kernel.org> wrote:
>
>> On Sat, 16 May 2020 09:29:02 +0100,
>> Jiaxun Yang <jiaxun.yang@flygoat.com> wrote:
>> >
>> > Add binding for Loongson-3 HyperTransport Interrupt Vector
>> > Controller.
>> >
>> > Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>> > --
>> > v4: Drop ref, '|', add additionalProperties, fix example
>>
>> Rob, do you have any input on this?
>
> Oops, looks like I was in-reply into wrong patch topic for this patch,
> should I resend this series into correct thread?
No, this series is fine as it is. TBH, your practice of sending
a series in reply to the previous version is not that useful
(I personally find it very annoying).
It would also be a big improvement if you sent a cover letter
with your patches (using --cover-letter when generating the patches).
I'll wait for Rob to comment on this patch as well as patch #4.
Thanks,
M.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox