Skip to content

Commit

Permalink
i2c: designware: Add support for an interface clock
Browse files Browse the repository at this point in the history
The Synopsys I2C Controller has an interface clock, but most SoCs hide
this away. However, on some SoCs you need to explicitly enable the
interface clock in order to access the registers. Therefore, add
support for an optional interface clock.

Signed-off-by: Phil Edworthy <[email protected]>
Signed-off-by: Gareth Williams <[email protected]>
Acked-by: Wolfram Sang <[email protected]>
Acked-by: Jarkko Nikula <[email protected]>
Tested-by: Jarkko Nikula <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
Phil Edworthy authored and Wolfram Sang committed Mar 20, 2019
1 parent bdfdf4b commit c62ebb3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
18 changes: 16 additions & 2 deletions drivers/i2c/busses/i2c-designware-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,27 @@ unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev)

int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare)
{
int ret;

if (IS_ERR(dev->clk))
return PTR_ERR(dev->clk);

if (prepare)
return clk_prepare_enable(dev->clk);
if (prepare) {
/* Optional interface clock */
ret = clk_prepare_enable(dev->pclk);
if (ret)
return ret;

ret = clk_prepare_enable(dev->clk);
if (ret)
clk_disable_unprepare(dev->pclk);

return ret;
}

clk_disable_unprepare(dev->clk);
clk_disable_unprepare(dev->pclk);

return 0;
}
EXPORT_SYMBOL_GPL(i2c_dw_prepare_clk);
Expand Down
2 changes: 2 additions & 0 deletions drivers/i2c/busses/i2c-designware-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
* @base: IO registers pointer
* @cmd_complete: tx completion indicator
* @clk: input reference clock
* @pclk: clock required to access the registers
* @slave: represent an I2C slave device
* @cmd_err: run time hadware error code
* @msgs: points to an array of messages currently being transferred
Expand Down Expand Up @@ -227,6 +228,7 @@ struct dw_i2c_dev {
void __iomem *ext;
struct completion cmd_complete;
struct clk *clk;
struct clk *pclk;
struct reset_control *rst;
struct i2c_client *slave;
u32 (*get_clk_rate_khz) (struct dw_i2c_dev *dev);
Expand Down
5 changes: 5 additions & 0 deletions drivers/i2c/busses/i2c-designware-platdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
else
i2c_dw_configure_master(dev);

/* Optional interface clock */
dev->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
if (IS_ERR(dev->pclk))
return PTR_ERR(dev->pclk);

dev->clk = devm_clk_get(&pdev->dev, NULL);
if (!i2c_dw_prepare_clk(dev, true)) {
u64 clk_khz;
Expand Down

0 comments on commit c62ebb3

Please sign in to comment.