|
@@ -105,6 +105,7 @@ static u8 mxc_w1_ds2_touch_bit(void *data, u8 bit)
|
|
static int mxc_w1_probe(struct platform_device *pdev)
|
|
static int mxc_w1_probe(struct platform_device *pdev)
|
|
{
|
|
{
|
|
struct mxc_w1_device *mdev;
|
|
struct mxc_w1_device *mdev;
|
|
|
|
+ unsigned long clkrate;
|
|
struct resource *res;
|
|
struct resource *res;
|
|
unsigned int clkdiv;
|
|
unsigned int clkdiv;
|
|
int err = 0;
|
|
int err = 0;
|
|
@@ -118,7 +119,16 @@ static int mxc_w1_probe(struct platform_device *pdev)
|
|
if (IS_ERR(mdev->clk))
|
|
if (IS_ERR(mdev->clk))
|
|
return PTR_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);
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
mdev->regs = devm_ioremap_resource(&pdev->dev, res);
|
|
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);
|
|
return PTR_ERR(mdev->regs);
|
|
|
|
|
|
clk_prepare_enable(mdev->clk);
|
|
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.data = mdev;
|
|
mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus;
|
|
mdev->bus_master.reset_bus = mxc_w1_ds2_reset_bus;
|