static SIMPLE_DEV_PM_OPS(ks8851_pm_ops, ks8851_suspend, ks8851_resume);
-static int ks8851_probe(struct spi_device *spi)
+static int ks8851_probe_common(struct net_device *netdev, struct device *dev,
+ int msg_en)
{
- struct device *dev = &spi->dev;
- struct ks8851_net_spi *kss;
- struct net_device *netdev;
- struct ks8851_net *ks;
- int ret;
+ struct ks8851_net *ks = netdev_priv(netdev);
unsigned cider;
int gpio;
-
- netdev = devm_alloc_etherdev(dev, sizeof(struct ks8851_net_spi));
- if (!netdev)
- return -ENOMEM;
-
- spi->bits_per_word = 8;
-
- ks = netdev_priv(netdev);
- kss = to_ks8851_spi(ks);
+ int ret;
ks->netdev = netdev;
- kss->spidev = spi;
ks->tx_space = 6144;
gpio = of_get_named_gpio_flags(dev->of_node, "reset-gpios", 0, NULL);
gpio_set_value(gpio, 1);
}
- mutex_init(&kss->lock);
spin_lock_init(&ks->statelock);
- INIT_WORK(&kss->tx_work, ks8851_tx_work);
INIT_WORK(&ks->rxctrl_work, ks8851_rxctrl_work);
- /* initialise pre-made spi transfer messages */
-
- spi_message_init(&kss->spi_msg1);
- spi_message_add_tail(&kss->spi_xfer1, &kss->spi_msg1);
-
- spi_message_init(&kss->spi_msg2);
- spi_message_add_tail(&kss->spi_xfer2[0], &kss->spi_msg2);
- spi_message_add_tail(&kss->spi_xfer2[1], &kss->spi_msg2);
-
/* setup EEPROM state */
-
ks->eeprom.data = ks;
ks->eeprom.width = PCI_EEPROM_WIDTH_93C46;
ks->eeprom.register_read = ks8851_eeprom_regread;
ks->mii.mdio_read = ks8851_phy_read;
ks->mii.mdio_write = ks8851_phy_write;
- dev_info(dev, "message enable is %d\n", msg_enable);
+ dev_info(dev, "message enable is %d\n", msg_en);
/* set the default message enable */
- ks->msg_enable = netif_msg_init(msg_enable, (NETIF_MSG_DRV |
- NETIF_MSG_PROBE |
- NETIF_MSG_LINK));
+ ks->msg_enable = netif_msg_init(msg_en, NETIF_MSG_DRV |
+ NETIF_MSG_PROBE |
+ NETIF_MSG_LINK);
skb_queue_head_init(&ks->txq);
netif_carrier_off(ks->netdev);
netdev->if_port = IF_PORT_100BASET;
netdev->netdev_ops = &ks8851_netdev_ops;
- netdev->irq = spi->irq;
/* issue a global soft reset to reset the device. */
ks8851_soft_reset(ks, GRR_GSR);
return ret;
}
-static int ks8851_remove(struct spi_device *spi)
+static int ks8851_remove_common(struct device *dev)
{
- struct device *dev = &spi->dev;
- struct ks8851_net *priv;
-
- priv = dev_get_drvdata(dev);
+ struct ks8851_net *priv = dev_get_drvdata(dev);
if (netif_msg_drv(priv))
dev_info(dev, "remove\n");
return 0;
}
+static int ks8851_probe(struct spi_device *spi)
+{
+ struct device *dev = &spi->dev;
+ struct ks8851_net_spi *kss;
+ struct net_device *netdev;
+ struct ks8851_net *ks;
+
+ netdev = devm_alloc_etherdev(dev, sizeof(struct ks8851_net_spi));
+ if (!netdev)
+ return -ENOMEM;
+
+ spi->bits_per_word = 8;
+
+ ks = netdev_priv(netdev);
+ kss = to_ks8851_spi(ks);
+
+ kss->spidev = spi;
+ mutex_init(&kss->lock);
+ INIT_WORK(&kss->tx_work, ks8851_tx_work);
+
+ /* initialise pre-made spi transfer messages */
+ spi_message_init(&kss->spi_msg1);
+ spi_message_add_tail(&kss->spi_xfer1, &kss->spi_msg1);
+
+ spi_message_init(&kss->spi_msg2);
+ spi_message_add_tail(&kss->spi_xfer2[0], &kss->spi_msg2);
+ spi_message_add_tail(&kss->spi_xfer2[1], &kss->spi_msg2);
+
+ netdev->irq = spi->irq;
+
+ return ks8851_probe_common(netdev, dev, msg_enable);
+}
+
+static int ks8851_remove(struct spi_device *spi)
+{
+ return ks8851_remove_common(&spi->dev);
+}
+
static const struct of_device_id ks8851_match_table[] = {
{ .compatible = "micrel,ks8851" },
{ }