Skip to content

Commit

Permalink
[PATCH] i2c: Race fix for i2c-mpc.c
Browse files Browse the repository at this point in the history
i2c: Race fix for i2c-mpc.c

The problem was that the clock speed and driver data is
initialized after the i2c adapter was added. This caused
the i2c bus to start working at a wrong speed. (Mostly
noticable on the second bus on mpc5200)

With this patch we've tried to keep the i2c adapter
working perfectly all the time it is included in the system.
Initialize before added, Remove garbage after deleleted.

Submitted-by: Asier Llano Palacios
Signed-off-by: Sylvain Munaut <[email protected]>
Signed-off-by: Kumar Gala <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
smunaut authored and gregkh committed Jun 22, 2005
1 parent d68a861 commit 7f02d56
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/i2c/busses/i2c-mpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ static int __devinit mpc_i2c_probe(struct ocp_device *ocp)
} else
i2c->irq = 0;

mpc_i2c_setclock(i2c);
ocp_set_drvdata(ocp, i2c);

i2c->adap = mpc_ops;
i2c_set_adapdata(&i2c->adap, i2c);

Expand All @@ -341,8 +344,6 @@ static int __devinit mpc_i2c_probe(struct ocp_device *ocp)
goto fail_add;
}

mpc_i2c_setclock(i2c);
ocp_set_drvdata(ocp, i2c);
return result;

fail_add:
Expand All @@ -358,8 +359,8 @@ static int __devinit mpc_i2c_probe(struct ocp_device *ocp)
static void __devexit mpc_i2c_remove(struct ocp_device *ocp)
{
struct mpc_i2c *i2c = ocp_get_drvdata(ocp);
ocp_set_drvdata(ocp, NULL);
i2c_del_adapter(&i2c->adap);
ocp_set_drvdata(ocp, NULL);

if (ocp->def->irq != OCP_IRQ_NA)
free_irq(i2c->irq, i2c);
Expand Down Expand Up @@ -430,6 +431,9 @@ static int fsl_i2c_probe(struct device *device)
goto fail_irq;
}

mpc_i2c_setclock(i2c);
dev_set_drvdata(device, i2c);

i2c->adap = mpc_ops;
i2c_set_adapdata(&i2c->adap, i2c);
i2c->adap.dev.parent = &pdev->dev;
Expand All @@ -438,8 +442,6 @@ static int fsl_i2c_probe(struct device *device)
goto fail_add;
}

mpc_i2c_setclock(i2c);
dev_set_drvdata(device, i2c);
return result;

fail_add:
Expand All @@ -456,8 +458,8 @@ static int fsl_i2c_remove(struct device *device)
{
struct mpc_i2c *i2c = dev_get_drvdata(device);

dev_set_drvdata(device, NULL);
i2c_del_adapter(&i2c->adap);
dev_set_drvdata(device, NULL);

if (i2c->irq != 0)
free_irq(i2c->irq, i2c);
Expand Down

0 comments on commit 7f02d56

Please sign in to comment.