Skip to content

Commit f2d8bb8

Browse files
committed
i2c: qcom-geni: add desc struct to prepare support for I2C Master Hub variant
Bugzilla: https://bugzilla.redhat.com/2164495 commit 14d02fb Author: Neil Armstrong <neil.armstrong@linaro.org> Date: Tue Nov 29 15:47:05 2022 +0100 i2c: qcom-geni: add desc struct to prepare support for I2C Master Hub variant The I2C Master Hub is a stripped down version of the GENI Serial Engine QUP Wrapper Controller but only supporting I2C serial engines without DMA support. Those I2C serial engines variants have some requirements: - a separate "core" clock - doesn't support DMA, thus no memory interconnect path - fixed FIFO size not discoverable in the HW_PARAM_0 register Add a desc struct specifying all those requirements which will be used in a next change when adding the I2C Master Hub serial engine compatible. Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org> Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org> Signed-off-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
1 parent e7dada0 commit f2d8bb8

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

drivers/i2c/busses/i2c-qcom-geni.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct geni_i2c_dev {
8888
int cur_wr;
8989
int cur_rd;
9090
spinlock_t lock;
91+
struct clk *core_clk;
9192
u32 clk_freq_out;
9293
const struct geni_i2c_clk_fld *clk_fld;
9394
int suspended;
@@ -100,6 +101,13 @@ struct geni_i2c_dev {
100101
bool abort_done;
101102
};
102103

104+
struct geni_i2c_desc {
105+
bool has_core_clk;
106+
char *icc_ddr;
107+
bool no_dma_support;
108+
unsigned int tx_fifo_depth;
109+
};
110+
103111
struct geni_i2c_err_log {
104112
int err;
105113
const char *msg;
@@ -763,6 +771,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
763771
u32 proto, tx_depth, fifo_disable;
764772
int ret;
765773
struct device *dev = &pdev->dev;
774+
const struct geni_i2c_desc *desc = NULL;
766775

767776
gi2c = devm_kzalloc(dev, sizeof(*gi2c), GFP_KERNEL);
768777
if (!gi2c)
@@ -775,6 +784,14 @@ static int geni_i2c_probe(struct platform_device *pdev)
775784
if (IS_ERR(gi2c->se.base))
776785
return PTR_ERR(gi2c->se.base);
777786

787+
desc = device_get_match_data(&pdev->dev);
788+
789+
if (desc && desc->has_core_clk) {
790+
gi2c->core_clk = devm_clk_get(dev, "core");
791+
if (IS_ERR(gi2c->core_clk))
792+
return PTR_ERR(gi2c->core_clk);
793+
}
794+
778795
gi2c->se.clk = devm_clk_get(dev, "se");
779796
if (IS_ERR(gi2c->se.clk) && !has_acpi_companion(dev))
780797
return PTR_ERR(gi2c->se.clk);
@@ -818,7 +835,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
818835
gi2c->adap.dev.of_node = dev->of_node;
819836
strlcpy(gi2c->adap.name, "Geni-I2C", sizeof(gi2c->adap.name));
820837

821-
ret = geni_icc_get(&gi2c->se, "qup-memory");
838+
ret = geni_icc_get(&gi2c->se, desc ? desc->icc_ddr : "qup-memory");
822839
if (ret)
823840
return ret;
824841
/*
@@ -828,12 +845,17 @@ static int geni_i2c_probe(struct platform_device *pdev)
828845
*/
829846
gi2c->se.icc_paths[GENI_TO_CORE].avg_bw = GENI_DEFAULT_BW;
830847
gi2c->se.icc_paths[CPU_TO_GENI].avg_bw = GENI_DEFAULT_BW;
831-
gi2c->se.icc_paths[GENI_TO_DDR].avg_bw = Bps_to_icc(gi2c->clk_freq_out);
848+
if (!desc || desc->icc_ddr)
849+
gi2c->se.icc_paths[GENI_TO_DDR].avg_bw = Bps_to_icc(gi2c->clk_freq_out);
832850

833851
ret = geni_icc_set_bw(&gi2c->se);
834852
if (ret)
835853
return ret;
836854

855+
ret = clk_prepare_enable(gi2c->core_clk);
856+
if (ret)
857+
return ret;
858+
837859
ret = geni_se_resources_on(&gi2c->se);
838860
if (ret) {
839861
dev_err(dev, "Error turning on resources %d\n", ret);
@@ -843,10 +865,15 @@ static int geni_i2c_probe(struct platform_device *pdev)
843865
if (proto != GENI_SE_I2C) {
844866
dev_err(dev, "Invalid proto %d\n", proto);
845867
geni_se_resources_off(&gi2c->se);
868+
clk_disable_unprepare(gi2c->core_clk);
846869
return -ENXIO;
847870
}
848871

849-
fifo_disable = readl_relaxed(gi2c->se.base + GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE;
872+
if (desc && desc->no_dma_support)
873+
fifo_disable = false;
874+
else
875+
fifo_disable = readl_relaxed(gi2c->se.base + GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE;
876+
850877
if (fifo_disable) {
851878
/* FIFO is disabled, so we can only use GPI DMA */
852879
gi2c->gpi_mode = true;
@@ -858,6 +885,16 @@ static int geni_i2c_probe(struct platform_device *pdev)
858885
} else {
859886
gi2c->gpi_mode = false;
860887
tx_depth = geni_se_get_tx_fifo_depth(&gi2c->se);
888+
889+
/* I2C Master Hub Serial Elements doesn't have the HW_PARAM_0 register */
890+
if (!tx_depth && desc)
891+
tx_depth = desc->tx_fifo_depth;
892+
893+
if (!tx_depth) {
894+
dev_err(dev, "Invalid TX FIFO depth\n");
895+
return -EINVAL;
896+
}
897+
861898
gi2c->tx_wm = tx_depth - 1;
862899
geni_se_init(&gi2c->se, gi2c->tx_wm, tx_depth);
863900
geni_se_config_packing(&gi2c->se, BITS_PER_BYTE,
@@ -866,6 +903,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
866903
dev_dbg(dev, "i2c fifo/se-dma mode. fifo depth:%d\n", tx_depth);
867904
}
868905

906+
clk_disable_unprepare(gi2c->core_clk);
869907
ret = geni_se_resources_off(&gi2c->se);
870908
if (ret) {
871909
dev_err(dev, "Error turning off resources %d\n", ret);
@@ -931,6 +969,8 @@ static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev)
931969
gi2c->suspended = 1;
932970
}
933971

972+
clk_disable_unprepare(gi2c->core_clk);
973+
934974
return geni_icc_disable(&gi2c->se);
935975
}
936976

@@ -943,6 +983,10 @@ static int __maybe_unused geni_i2c_runtime_resume(struct device *dev)
943983
if (ret)
944984
return ret;
945985

986+
ret = clk_prepare_enable(gi2c->core_clk);
987+
if (ret)
988+
return ret;
989+
946990
ret = geni_se_resources_on(&gi2c->se);
947991
if (ret)
948992
return ret;

0 commit comments

Comments
 (0)