diff options
author | Alexander Shiyan <shc_work@mail.ru> | 2013-11-29 06:39:29 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-12-09 01:41:48 -0500 |
commit | 71531f55a83dcb79b89287f6b11fb2e4eb496d4d (patch) | |
tree | 0bc285ba536bc15dc5d425b0de27e2a0a3607f3b /drivers/w1 | |
parent | a0822637258b9e6132de669ac16dfe445c78e932 (diff) |
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.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r-- | drivers/w1/masters/mxc_w1.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c index 5de3ca9b0fb9..953168c63392 100644 --- a/drivers/w1/masters/mxc_w1.c +++ b/drivers/w1/masters/mxc_w1.c | |||
@@ -105,6 +105,7 @@ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit) | |||
105 | static int mxc_w1_probe(struct platform_device *pdev) | 105 | static int mxc_w1_probe(struct platform_device *pdev) |
106 | { | 106 | { |
107 | struct mxc_w1_device *mdev; | 107 | struct mxc_w1_device *mdev; |
108 | unsigned long clkrate; | ||
108 | struct resource *res; | 109 | struct resource *res; |
109 | unsigned int clkdiv; | 110 | unsigned int clkdiv; |
110 | int err = 0; | 111 | int err = 0; |
@@ -118,7 +119,16 @@ static int mxc_w1_probe(struct platform_device *pdev) | |||
118 | if (IS_ERR(mdev->clk)) | 119 | if (IS_ERR(mdev->clk)) |
119 | return PTR_ERR(mdev->clk); | 120 | return PTR_ERR(mdev->clk); |
120 | 121 | ||
121 | clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1; | 122 | clkrate = clk_get_rate(mdev->clk); |
123 | if (clkrate < 10000000) | ||
124 | dev_warn(&pdev->dev, | ||
125 | "Low clock frequency causes improper function\n"); | ||
126 | |||
127 | clkdiv = DIV_ROUND_CLOSEST(clkrate, 1000000); | ||
128 | clkrate /= clkdiv; | ||
129 | if ((clkrate < 980000) || (clkrate > 1020000)) | ||
130 | dev_warn(&pdev->dev, | ||
131 | "Incorrect time base frequency %lu Hz\n", clkrate); | ||
122 | 132 | ||
123 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 133 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
124 | mdev->regs = devm_ioremap_resource(&pdev->dev, res); | 134 | mdev->regs = devm_ioremap_resource(&pdev->dev, res); |
@@ -126,7 +136,7 @@ static int mxc_w1_probe(struct platform_device *pdev) | |||
126 | return PTR_ERR(mdev->regs); | 136 | return PTR_ERR(mdev->regs); |
127 | 137 | ||
128 | clk_prepare_enable(mdev->clk); | 138 | clk_prepare_enable(mdev->clk); |
129 | __raw_writeb(clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER); | 139 | __raw_writeb(clkdiv - 1, mdev->regs + MXC_W1_TIME_DIVIDER); |
130 | 140 | ||
131 | mdev->bus_master.data = mdev; | 141 | mdev->bus_master.data = mdev; |
132 | mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus; | 142 | mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus; |