diff options
Diffstat (limited to 'drivers/net/can/m_can/m_can_pci.c')
-rw-r--r-- | drivers/net/can/m_can/m_can_pci.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/drivers/net/can/m_can/m_can_pci.c b/drivers/net/can/m_can/m_can_pci.c index 04010ee0407c..128808605c3f 100644 --- a/drivers/net/can/m_can/m_can_pci.c +++ b/drivers/net/can/m_can/m_can_pci.c @@ -22,26 +22,33 @@ #define CTL_CSR_INT_CTL_OFFSET 0x508 struct m_can_pci_priv { + struct m_can_classdev cdev; + void __iomem *base; }; +static inline struct m_can_pci_priv *cdev_to_priv(struct m_can_classdev *cdev) +{ + return container_of(cdev, struct m_can_pci_priv, cdev); +} + static u32 iomap_read_reg(struct m_can_classdev *cdev, int reg) { - struct m_can_pci_priv *priv = cdev->device_data; + struct m_can_pci_priv *priv = cdev_to_priv(cdev); return readl(priv->base + reg); } static u32 iomap_read_fifo(struct m_can_classdev *cdev, int offset) { - struct m_can_pci_priv *priv = cdev->device_data; + struct m_can_pci_priv *priv = cdev_to_priv(cdev); return readl(priv->base + offset); } static int iomap_write_reg(struct m_can_classdev *cdev, int reg, int val) { - struct m_can_pci_priv *priv = cdev->device_data; + struct m_can_pci_priv *priv = cdev_to_priv(cdev); writel(val, priv->base + reg); @@ -50,7 +57,7 @@ static int iomap_write_reg(struct m_can_classdev *cdev, int reg, int val) static int iomap_write_fifo(struct m_can_classdev *cdev, int offset, int val) { - struct m_can_pci_priv *priv = cdev->device_data; + struct m_can_pci_priv *priv = cdev_to_priv(cdev); writel(val, priv->base + offset); @@ -89,28 +96,26 @@ static int m_can_pci_probe(struct pci_dev *pci, const struct pci_device_id *id) return -ENOMEM; } - priv = devm_kzalloc(&pci->dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - mcan_class = m_can_class_allocate_dev(&pci->dev); + mcan_class = m_can_class_allocate_dev(&pci->dev, + sizeof(struct m_can_pci_priv)); if (!mcan_class) return -ENOMEM; + priv = cdev_to_priv(mcan_class); + priv->base = base; ret = pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_ALL_TYPES); if (ret < 0) return ret; - mcan_class->device_data = priv; mcan_class->dev = &pci->dev; mcan_class->net->irq = pci_irq_vector(pci, 0); mcan_class->pm_clock_support = 1; mcan_class->can.clock.freq = id->driver_data; mcan_class->ops = &m_can_pci_ops; - pci_set_drvdata(pci, mcan_class->net); + pci_set_drvdata(pci, mcan_class); ret = m_can_class_register(mcan_class); if (ret) @@ -133,9 +138,8 @@ err: static void m_can_pci_remove(struct pci_dev *pci) { - struct net_device *dev = pci_get_drvdata(pci); - struct m_can_classdev *mcan_class = netdev_priv(dev); - struct m_can_pci_priv *priv = mcan_class->device_data; + struct m_can_classdev *mcan_class = pci_get_drvdata(pci); + struct m_can_pci_priv *priv = cdev_to_priv(mcan_class); pm_runtime_forbid(&pci->dev); pm_runtime_get_noresume(&pci->dev); |