Skip to content

Commit 14d02fb

Browse files
superna9999wsakernel
authored andcommitted
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 <[email protected]> Reviewed-by: Konrad Dybcio <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent f4aba01 commit 14d02fb

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;
@@ -764,6 +772,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
764772
u32 proto, tx_depth, fifo_disable;
765773
int ret;
766774
struct device *dev = &pdev->dev;
775+
const struct geni_i2c_desc *desc = NULL;
767776

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

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

822-
ret = geni_icc_get(&gi2c->se, "qup-memory");
839+
ret = geni_icc_get(&gi2c->se, desc ? desc->icc_ddr : "qup-memory");
823840
if (ret)
824841
return ret;
825842
/*
@@ -829,12 +846,17 @@ static int geni_i2c_probe(struct platform_device *pdev)
829846
*/
830847
gi2c->se.icc_paths[GENI_TO_CORE].avg_bw = GENI_DEFAULT_BW;
831848
gi2c->se.icc_paths[CPU_TO_GENI].avg_bw = GENI_DEFAULT_BW;
832-
gi2c->se.icc_paths[GENI_TO_DDR].avg_bw = Bps_to_icc(gi2c->clk_freq_out);
849+
if (!desc || desc->icc_ddr)
850+
gi2c->se.icc_paths[GENI_TO_DDR].avg_bw = Bps_to_icc(gi2c->clk_freq_out);
833851

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

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

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

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

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

@@ -944,6 +984,10 @@ static int __maybe_unused geni_i2c_runtime_resume(struct device *dev)
944984
if (ret)
945985
return ret;
946986

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

0 commit comments

Comments
 (0)