Skip to contentSkip to conversation

w1: mxc_w1: Remove unused field "clkdiv" from private structure

PATCH In review Alexander Shiyan 3 participants 7 messages Nov 29, 2013 – Nov 30, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 w1: mxc_w1: Remove unused field "clkdiv" from private structure

Private field "clkdiv" is not used outside "probe", so there are no reason to keep it in driver.

---
 drivers/w1/masters/mxc_w1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/w1/masters/mxc_w1.c +3 -3
index 15c7251..5de3ca9 100644
@@ -46,7 +46,6 @@
 
 struct mxc_w1_device {
 	void __iomem *regs;
-	unsigned int clkdiv;
 	struct clk *clk;
 	struct w1_bus_master bus_master;
 };
@@ -107,6 +106,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 {
 	struct mxc_w1_device *mdev;
 	struct resource *res;
+	unsigned int clkdiv;
 	int err = 0;
 
 	mdev = devm_kzalloc(&pdev->dev, sizeof(struct mxc_w1_device),
@@ -118,7 +118,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev->clk))
 		return PTR_ERR(mdev->clk);
 
-	mdev->clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1;
+	clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	mdev->regs = devm_ioremap_resource(&pdev->dev, res);
@@ -126,7 +126,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 		return PTR_ERR(mdev->regs);
 
 	clk_prepare_enable(mdev->clk);
-	__raw_writeb(mdev->clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER);
+	__raw_writeb(clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER);
 
 	mdev->bus_master.data = mdev;
 	mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus;
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 2/3 w1: mxc_w1: Add warning for base frequency calculation

Base frequency should be as close as possible to 1 MHz. This patch adds warnings when clock is unreliable, according to i.MX datasheet.

---
 drivers/w1/masters/mxc_w1.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/w1/masters/mxc_w1.c +12 -2
index 5de3ca9..953168c 100644
@@ -105,6 +105,7 @@ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit)
 static int mxc_w1_probe(struct platform_device *pdev)
 {
 	struct mxc_w1_device *mdev;
+	unsigned long clkrate;
 	struct resource *res;
 	unsigned int clkdiv;
 	int err = 0;
@@ -118,7 +119,16 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev->clk))
 		return PTR_ERR(mdev->clk);
 
-	clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1;
+	clkrate = clk_get_rate(mdev->clk);
+	if (clkrate < 10000000)
+		dev_warn(&pdev->dev,
+			 "Low clock frequency causes improper function\n");
+
+	clkdiv = DIV_ROUND_CLOSEST(clkrate, 1000000);
+	clkrate /= clkdiv;
+	if ((clkrate < 980000) || (clkrate > 1020000))
+		dev_warn(&pdev->dev,
+			 "Incorrect time base frequency %lu Hz\n", clkrate);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	mdev->regs = devm_ioremap_resource(&pdev->dev, res);
@@ -126,7 +136,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 		return PTR_ERR(mdev->regs);
 
 	clk_prepare_enable(mdev->clk);
-	__raw_writeb(clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER);
+	__raw_writeb(clkdiv - 1, mdev->regs + MXC_W1_TIME_DIVIDER);
 
 	mdev->bus_master.data = mdev;
 	mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus;
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH 3/3 w1: mxc_w1: Check the clk_prepare_enable() return value

In reply to Alexander Shiyan
---
 drivers/w1/masters/mxc_w1.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/w1/masters/mxc_w1.c +9 -6
index 953168c..1e5d94c 100644
@@ -108,7 +108,7 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	unsigned long clkrate;
 	struct resource *res;
 	unsigned int clkdiv;
-	int err = 0;
+	int err;
 
 	mdev = devm_kzalloc(&pdev->dev, sizeof(struct mxc_w1_device),
 			    GFP_KERNEL);
@@ -135,20 +135,23 @@ static int mxc_w1_probe(struct platform_device *pdev)
 	if (IS_ERR(mdev->regs))
 		return PTR_ERR(mdev->regs);
 
-	clk_prepare_enable(mdev->clk);
+	err = clk_prepare_enable(mdev->clk);
+	if (err)
+		return err;
+
 	__raw_writeb(clkdiv - 1, mdev->regs + MXC_W1_TIME_DIVIDER);
 
 	mdev->bus_master.data = mdev;
 	mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus;
 	mdev->bus_master.touch_bit = mxc_w1_ds2_touch_bit;
 
-	err = w1_add_master_device(&mdev->bus_master);
+	platform_set_drvdata(pdev, mdev);
 
+	err = w1_add_master_device(&mdev->bus_master);
 	if (err)
-		return err;
+		clk_disable_unprepare(mdev->clk);
 
-	platform_set_drvdata(pdev, mdev);
-	return 0;
+	return err;
 }
 
 /*
Signature · 1 line
1.8.3.2
#3 lore raw
In reply to Alexander Shiyan
Quoted 2 lines · Alexander Shiyan

Private field "clkdiv" is not used outside "probe", so there are no reason to keep it in driver.

Where's the corresponding clk_disable_unprepare()?

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
#4 lore raw
Quoted 5 lines · Alexander Shiyan
Quoted 2 lines

Private field "clkdiv" is not used outside "probe", so there are no reason to keep it in driver.

Where's the corresponding clk_disable_unprepare()?

I do not see any relation "clk_disable_unprepare" with this patch.

---
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�

#5 lore raw
Quoted 7 lines · Alexander Shiyan
Quoted 5 lines · Alexander Shiyan
Quoted 2 lines

Private field "clkdiv" is not used outside "probe", so there are no reason to keep it in driver.

Where's the corresponding clk_disable_unprepare()?

I do not see any relation "clk_disable_unprepare" with this patch.

Yes right, sorry for the noise.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |