Commit c0f7b25a authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: move alloc_device common code in mt76_alloc_device

Move mt76x{0,2} alloc_device common code in mt76_alloc_device and
remove duplicated code
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent f1906fb2
...@@ -269,7 +269,9 @@ mt76_check_sband(struct mt76_dev *dev, int band) ...@@ -269,7 +269,9 @@ mt76_check_sband(struct mt76_dev *dev, int band)
} }
struct mt76_dev * struct mt76_dev *
mt76_alloc_device(unsigned int size, const struct ieee80211_ops *ops) mt76_alloc_device(struct device *pdev, unsigned int size,
const struct ieee80211_ops *ops,
const struct mt76_driver_ops *drv_ops)
{ {
struct ieee80211_hw *hw; struct ieee80211_hw *hw;
struct mt76_dev *dev; struct mt76_dev *dev;
...@@ -280,6 +282,9 @@ mt76_alloc_device(unsigned int size, const struct ieee80211_ops *ops) ...@@ -280,6 +282,9 @@ mt76_alloc_device(unsigned int size, const struct ieee80211_ops *ops)
dev = hw->priv; dev = hw->priv;
dev->hw = hw; dev->hw = hw;
dev->dev = pdev;
dev->drv = drv_ops;
spin_lock_init(&dev->rx_lock); spin_lock_init(&dev->rx_lock);
spin_lock_init(&dev->lock); spin_lock_init(&dev->lock);
spin_lock_init(&dev->cc_lock); spin_lock_init(&dev->cc_lock);
......
...@@ -585,8 +585,9 @@ mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c) ...@@ -585,8 +585,9 @@ mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c)
return &msband->chan[idx]; return &msband->chan[idx];
} }
struct mt76_dev *mt76_alloc_device(unsigned int size, struct mt76_dev *mt76_alloc_device(struct device *pdev, unsigned int size,
const struct ieee80211_ops *ops); const struct ieee80211_ops *ops,
const struct mt76_driver_ops *drv_ops);
int mt76_register_device(struct mt76_dev *dev, bool vht, int mt76_register_device(struct mt76_dev *dev, bool vht,
struct ieee80211_rate *rates, int n_rates); struct ieee80211_rate *rates, int n_rates);
void mt76_unregister_device(struct mt76_dev *dev); void mt76_unregister_device(struct mt76_dev *dev);
......
...@@ -270,13 +270,10 @@ mt76x0_alloc_device(struct device *pdev, ...@@ -270,13 +270,10 @@ mt76x0_alloc_device(struct device *pdev,
struct mt76x02_dev *dev; struct mt76x02_dev *dev;
struct mt76_dev *mdev; struct mt76_dev *mdev;
mdev = mt76_alloc_device(sizeof(*dev), ops); mdev = mt76_alloc_device(pdev, sizeof(*dev), ops, drv_ops);
if (!mdev) if (!mdev)
return NULL; return NULL;
mdev->dev = pdev;
mdev->drv = drv_ops;
dev = container_of(mdev, struct mt76x02_dev, mt76); dev = container_of(mdev, struct mt76x02_dev, mt76);
mutex_init(&dev->phy_mutex); mutex_init(&dev->phy_mutex);
......
...@@ -329,13 +329,12 @@ struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev) ...@@ -329,13 +329,12 @@ struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev)
struct mt76x02_dev *dev; struct mt76x02_dev *dev;
struct mt76_dev *mdev; struct mt76_dev *mdev;
mdev = mt76_alloc_device(sizeof(*dev), &mt76x2_ops); mdev = mt76_alloc_device(pdev, sizeof(*dev), &mt76x2_ops,
&drv_ops);
if (!mdev) if (!mdev)
return NULL; return NULL;
dev = container_of(mdev, struct mt76x02_dev, mt76); dev = container_of(mdev, struct mt76x02_dev, mt76);
mdev->dev = pdev;
mdev->drv = &drv_ops;
return dev; return dev;
} }
......
...@@ -147,13 +147,12 @@ struct mt76x02_dev *mt76x2u_alloc_device(struct device *pdev) ...@@ -147,13 +147,12 @@ struct mt76x02_dev *mt76x2u_alloc_device(struct device *pdev)
struct mt76x02_dev *dev; struct mt76x02_dev *dev;
struct mt76_dev *mdev; struct mt76_dev *mdev;
mdev = mt76_alloc_device(sizeof(*dev), &mt76x2u_ops); mdev = mt76_alloc_device(pdev, sizeof(*dev), &mt76x2u_ops,
&drv_ops);
if (!mdev) if (!mdev)
return NULL; return NULL;
dev = container_of(mdev, struct mt76x02_dev, mt76); dev = container_of(mdev, struct mt76x02_dev, mt76);
mdev->dev = pdev;
mdev->drv = &drv_ops;
return dev; return dev;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment