can: fix setting mcp251x bit timing on open

Signed-off-by: Christian Pellegrin <chripell@fsfe.org>
Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Christian Pellegrin 2009-11-17 06:20:44 +00:00 committed by David S. Miller
parent 9a4e328eb2
commit 615534bc49

View file

@ -594,13 +594,7 @@ static int mcp251x_do_set_bittiming(struct net_device *net)
static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv, static int mcp251x_setup(struct net_device *net, struct mcp251x_priv *priv,
struct spi_device *spi) struct spi_device *spi)
{ {
int ret; mcp251x_do_set_bittiming(net);
ret = open_candev(net);
if (ret) {
dev_err(&spi->dev, "unable to set initial baudrate!\n");
return ret;
}
/* Enable RX0->RX1 buffer roll over and disable filters */ /* Enable RX0->RX1 buffer roll over and disable filters */
mcp251x_write_bits(spi, RXBCTRL(0), mcp251x_write_bits(spi, RXBCTRL(0),
@ -671,6 +665,12 @@ static int mcp251x_open(struct net_device *net)
struct mcp251x_platform_data *pdata = spi->dev.platform_data; struct mcp251x_platform_data *pdata = spi->dev.platform_data;
int ret; int ret;
ret = open_candev(net);
if (ret) {
dev_err(&spi->dev, "unable to set initial baudrate!\n");
return ret;
}
if (pdata->transceiver_enable) if (pdata->transceiver_enable)
pdata->transceiver_enable(1); pdata->transceiver_enable(1);
@ -684,6 +684,7 @@ static int mcp251x_open(struct net_device *net)
dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq); dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq);
if (pdata->transceiver_enable) if (pdata->transceiver_enable)
pdata->transceiver_enable(0); pdata->transceiver_enable(0);
close_candev(net);
return ret; return ret;
} }
@ -692,8 +693,10 @@ static int mcp251x_open(struct net_device *net)
ret = mcp251x_setup(net, priv, spi); ret = mcp251x_setup(net, priv, spi);
if (ret) { if (ret) {
free_irq(spi->irq, net); free_irq(spi->irq, net);
mcp251x_hw_sleep(spi);
if (pdata->transceiver_enable) if (pdata->transceiver_enable)
pdata->transceiver_enable(0); pdata->transceiver_enable(0);
close_candev(net);
return ret; return ret;
} }
mcp251x_set_normal_mode(spi); mcp251x_set_normal_mode(spi);
@ -956,7 +959,6 @@ static int __devinit mcp251x_can_probe(struct spi_device *spi)
priv->can.bittiming_const = &mcp251x_bittiming_const; priv->can.bittiming_const = &mcp251x_bittiming_const;
priv->can.do_set_mode = mcp251x_do_set_mode; priv->can.do_set_mode = mcp251x_do_set_mode;
priv->can.clock.freq = pdata->oscillator_frequency / 2; priv->can.clock.freq = pdata->oscillator_frequency / 2;
priv->can.do_set_bittiming = mcp251x_do_set_bittiming;
priv->net = net; priv->net = net;
dev_set_drvdata(&spi->dev, priv); dev_set_drvdata(&spi->dev, priv);