mt76x2_pci.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/pci.h>
  19. #include "mt76x2.h"
  20. #include "mt76x2_trace.h"
  21. static const struct pci_device_id mt76pci_device_table[] = {
  22. { PCI_DEVICE(0x14c3, 0x7662) },
  23. { PCI_DEVICE(0x14c3, 0x7612) },
  24. { PCI_DEVICE(0x14c3, 0x7602) },
  25. { },
  26. };
  27. static int
  28. mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  29. {
  30. struct mt76x2_dev *dev;
  31. int ret;
  32. ret = pcim_enable_device(pdev);
  33. if (ret)
  34. return ret;
  35. ret = pcim_iomap_regions(pdev, BIT(0), pci_name(pdev));
  36. if (ret)
  37. return ret;
  38. pci_set_master(pdev);
  39. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  40. if (ret)
  41. return ret;
  42. dev = mt76x2_alloc_device(&pdev->dev);
  43. if (!dev)
  44. return -ENOMEM;
  45. mt76_mmio_init(&dev->mt76, pcim_iomap_table(pdev)[0]);
  46. dev->mt76.rev = mt76_rr(dev, MT_ASIC_VERSION);
  47. dev_info(dev->mt76.dev, "ASIC revision: %08x\n", dev->mt76.rev);
  48. ret = devm_request_irq(dev->mt76.dev, pdev->irq, mt76x2_irq_handler,
  49. IRQF_SHARED, KBUILD_MODNAME, dev);
  50. if (ret)
  51. goto error;
  52. ret = mt76x2_register_device(dev);
  53. if (ret)
  54. goto error;
  55. /* Fix up ASPM configuration */
  56. /* RG_SSUSB_G1_CDR_BIR_LTR = 0x9 */
  57. mt76_rmw_field(dev, 0x15a10, 0x1f << 16, 0x9);
  58. /* RG_SSUSB_G1_CDR_BIC_LTR = 0xf */
  59. mt76_rmw_field(dev, 0x15a0c, 0xf << 28, 0xf);
  60. /* RG_SSUSB_CDR_BR_PE1D = 0x3 */
  61. mt76_rmw_field(dev, 0x15c58, 0x3 << 6, 0x3);
  62. return 0;
  63. error:
  64. ieee80211_free_hw(mt76_hw(dev));
  65. return ret;
  66. }
  67. static void
  68. mt76pci_remove(struct pci_dev *pdev)
  69. {
  70. struct mt76_dev *mdev = pci_get_drvdata(pdev);
  71. struct mt76x2_dev *dev = container_of(mdev, struct mt76x2_dev, mt76);
  72. mt76_unregister_device(mdev);
  73. mt76x2_cleanup(dev);
  74. ieee80211_free_hw(mdev->hw);
  75. }
  76. MODULE_DEVICE_TABLE(pci, mt76pci_device_table);
  77. MODULE_FIRMWARE(MT7662_FIRMWARE);
  78. MODULE_FIRMWARE(MT7662_ROM_PATCH);
  79. MODULE_LICENSE("Dual BSD/GPL");
  80. static struct pci_driver mt76pci_driver = {
  81. .name = KBUILD_MODNAME,
  82. .id_table = mt76pci_device_table,
  83. .probe = mt76pci_probe,
  84. .remove = mt76pci_remove,
  85. };
  86. module_pci_driver(mt76pci_driver);