Skip to content
Snippets Groups Projects
Commit ede264ac authored by Gao Pan's avatar Gao Pan Committed by Jason Liu
Browse files

MLK-14982-1 imx8: lpi2c: add ipg clk for lpi2c driver


The lpi2c IP needs two clks: ipg clk and per clk. The old lpi2c
driver missed ipg clk. This patch adds ipg clk for lpi2c driver.

Signed-off-by: default avatarGao Pan <pandy.gao@nxp.com>
parent 63319d50
No related branches found
No related tags found
No related merge requests found
...@@ -107,7 +107,8 @@ enum lpi2c_imx_pincfg { ...@@ -107,7 +107,8 @@ enum lpi2c_imx_pincfg {
struct lpi2c_imx_struct { struct lpi2c_imx_struct {
struct i2c_adapter adapter; struct i2c_adapter adapter;
struct clk *clk; struct clk *clk_per;
struct clk *clk_ipg;
void __iomem *base; void __iomem *base;
__u8 *rx_buf; __u8 *rx_buf;
__u8 *tx_buf; __u8 *tx_buf;
...@@ -222,7 +223,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx) ...@@ -222,7 +223,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)
lpi2c_imx_set_mode(lpi2c_imx); lpi2c_imx_set_mode(lpi2c_imx);
clk_rate = clk_get_rate(lpi2c_imx->clk); clk_rate = clk_get_rate(lpi2c_imx->clk_per);
if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST) if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST)
filt = 0; filt = 0;
else else
...@@ -274,10 +275,16 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx) ...@@ -274,10 +275,16 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx)
unsigned int temp; unsigned int temp;
int ret; int ret;
ret = clk_enable(lpi2c_imx->clk); ret = clk_enable(lpi2c_imx->clk_ipg);
if (ret) if (ret)
return ret; return ret;
ret = clk_enable(lpi2c_imx->clk_per);
if (ret) {
clk_disable(lpi2c_imx->clk_ipg);
return ret;
}
temp = MCR_RST; temp = MCR_RST;
writel(temp, lpi2c_imx->base + LPI2C_MCR); writel(temp, lpi2c_imx->base + LPI2C_MCR);
writel(0, lpi2c_imx->base + LPI2C_MCR); writel(0, lpi2c_imx->base + LPI2C_MCR);
...@@ -293,7 +300,8 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx) ...@@ -293,7 +300,8 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx)
return 0; return 0;
clk_disable: clk_disable:
clk_disable(lpi2c_imx->clk); clk_disable(lpi2c_imx->clk_per);
clk_disable(lpi2c_imx->clk_ipg);
return ret; return ret;
} }
...@@ -306,7 +314,8 @@ static int lpi2c_imx_master_disable(struct lpi2c_imx_struct *lpi2c_imx) ...@@ -306,7 +314,8 @@ static int lpi2c_imx_master_disable(struct lpi2c_imx_struct *lpi2c_imx)
temp &= ~MCR_MEN; temp &= ~MCR_MEN;
writel(temp, lpi2c_imx->base + LPI2C_MCR); writel(temp, lpi2c_imx->base + LPI2C_MCR);
clk_disable(lpi2c_imx->clk); clk_disable(lpi2c_imx->clk_per);
clk_disable(lpi2c_imx->clk_ipg);
return 0; return 0;
} }
...@@ -581,10 +590,16 @@ static int lpi2c_imx_probe(struct platform_device *pdev) ...@@ -581,10 +590,16 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
strlcpy(lpi2c_imx->adapter.name, pdev->name, strlcpy(lpi2c_imx->adapter.name, pdev->name,
sizeof(lpi2c_imx->adapter.name)); sizeof(lpi2c_imx->adapter.name));
lpi2c_imx->clk = devm_clk_get(&pdev->dev, NULL); lpi2c_imx->clk_per = devm_clk_get(&pdev->dev, "per");
if (IS_ERR(lpi2c_imx->clk)) { if (IS_ERR(lpi2c_imx->clk_per)) {
dev_err(&pdev->dev, "can't get I2C peripheral clock\n"); dev_err(&pdev->dev, "can't get I2C peripheral clock\n");
return PTR_ERR(lpi2c_imx->clk); return PTR_ERR(lpi2c_imx->clk_per);
}
lpi2c_imx->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
if (IS_ERR(lpi2c_imx->clk_ipg)) {
dev_err(&pdev->dev, "can't get I2C ipg clock\n");
return PTR_ERR(lpi2c_imx->clk_ipg);
} }
ret = of_property_read_u32(pdev->dev.of_node, ret = of_property_read_u32(pdev->dev.of_node,
...@@ -602,9 +617,16 @@ static int lpi2c_imx_probe(struct platform_device *pdev) ...@@ -602,9 +617,16 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx); i2c_set_adapdata(&lpi2c_imx->adapter, lpi2c_imx);
platform_set_drvdata(pdev, lpi2c_imx); platform_set_drvdata(pdev, lpi2c_imx);
ret = clk_prepare_enable(lpi2c_imx->clk); ret = clk_prepare_enable(lpi2c_imx->clk_per);
if (ret) {
dev_err(&pdev->dev, "clk prepare enable failed %d\n", ret);
return ret;
}
ret = clk_prepare(lpi2c_imx->clk_ipg);
if (ret) { if (ret) {
dev_err(&pdev->dev, "clk enable failed %d\n", ret); clk_disable_unprepare(lpi2c_imx->clk_per);
dev_err(&pdev->dev, "clk prepare failed %d\n", ret);
return ret; return ret;
} }
...@@ -612,7 +634,7 @@ static int lpi2c_imx_probe(struct platform_device *pdev) ...@@ -612,7 +634,7 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
lpi2c_imx->txfifosize = 1 << (temp & 0x0f); lpi2c_imx->txfifosize = 1 << (temp & 0x0f);
lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f); lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f);
clk_disable(lpi2c_imx->clk); clk_disable(lpi2c_imx->clk_per);
ret = i2c_add_adapter(&lpi2c_imx->adapter); ret = i2c_add_adapter(&lpi2c_imx->adapter);
if (ret) if (ret)
...@@ -623,7 +645,8 @@ static int lpi2c_imx_probe(struct platform_device *pdev) ...@@ -623,7 +645,8 @@ static int lpi2c_imx_probe(struct platform_device *pdev)
return 0; return 0;
clk_unprepare: clk_unprepare:
clk_unprepare(lpi2c_imx->clk); clk_unprepare(lpi2c_imx->clk_ipg);
clk_unprepare(lpi2c_imx->clk_per);
return ret; return ret;
} }
...@@ -634,7 +657,8 @@ static int lpi2c_imx_remove(struct platform_device *pdev) ...@@ -634,7 +657,8 @@ static int lpi2c_imx_remove(struct platform_device *pdev)
i2c_del_adapter(&lpi2c_imx->adapter); i2c_del_adapter(&lpi2c_imx->adapter);
clk_unprepare(lpi2c_imx->clk); clk_unprepare(lpi2c_imx->clk_ipg);
clk_unprepare(lpi2c_imx->clk_per);
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment