vfio_platform_calxedaxgmac.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * VFIO platform driver specialized for Calxeda xgmac reset
  3. * reset code is inherited from calxeda xgmac native driver
  4. *
  5. * Copyright 2010-2011 Calxeda, Inc.
  6. * Copyright (c) 2015 Linaro Ltd.
  7. * www.linaro.org
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms and conditions of the GNU General Public License,
  11. * version 2, as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/io.h>
  25. #include "vfio_platform_private.h"
  26. #define DRIVER_VERSION "0.1"
  27. #define DRIVER_AUTHOR "Eric Auger <eric.auger@linaro.org>"
  28. #define DRIVER_DESC "Reset support for Calxeda xgmac vfio platform device"
  29. /* XGMAC Register definitions */
  30. #define XGMAC_CONTROL 0x00000000 /* MAC Configuration */
  31. /* DMA Control and Status Registers */
  32. #define XGMAC_DMA_CONTROL 0x00000f18 /* Ctrl (Operational Mode) */
  33. #define XGMAC_DMA_INTR_ENA 0x00000f1c /* Interrupt Enable */
  34. /* DMA Control registe defines */
  35. #define DMA_CONTROL_ST 0x00002000 /* Start/Stop Transmission */
  36. #define DMA_CONTROL_SR 0x00000002 /* Start/Stop Receive */
  37. /* Common MAC defines */
  38. #define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */
  39. #define MAC_ENABLE_RX 0x00000004 /* Receiver Enable */
  40. static inline void xgmac_mac_disable(void __iomem *ioaddr)
  41. {
  42. u32 value = readl(ioaddr + XGMAC_DMA_CONTROL);
  43. value &= ~(DMA_CONTROL_ST | DMA_CONTROL_SR);
  44. writel(value, ioaddr + XGMAC_DMA_CONTROL);
  45. value = readl(ioaddr + XGMAC_CONTROL);
  46. value &= ~(MAC_ENABLE_TX | MAC_ENABLE_RX);
  47. writel(value, ioaddr + XGMAC_CONTROL);
  48. }
  49. int vfio_platform_calxedaxgmac_reset(struct vfio_platform_device *vdev)
  50. {
  51. struct vfio_platform_region *reg = &vdev->regions[0];
  52. if (!reg->ioaddr) {
  53. reg->ioaddr =
  54. ioremap_nocache(reg->addr, reg->size);
  55. if (!reg->ioaddr)
  56. return -ENOMEM;
  57. }
  58. /* disable IRQ */
  59. writel(0, reg->ioaddr + XGMAC_DMA_INTR_ENA);
  60. /* Disable the MAC core */
  61. xgmac_mac_disable(reg->ioaddr);
  62. return 0;
  63. }
  64. module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_reset);
  65. MODULE_VERSION(DRIVER_VERSION);
  66. MODULE_LICENSE("GPL v2");
  67. MODULE_AUTHOR(DRIVER_AUTHOR);
  68. MODULE_DESCRIPTION(DRIVER_DESC);