]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-jammy-kernel.git] / drivers / vfio / platform / reset / vfio_platform_calxedaxgmac.c
CommitLineData
9952f691 1// SPDX-License-Identifier: GPL-2.0-only
713cc334
EA
2/*
3 * VFIO platform driver specialized for Calxeda xgmac reset
4 * reset code is inherited from calxeda xgmac native driver
5 *
6 * Copyright 2010-2011 Calxeda, Inc.
7 * Copyright (c) 2015 Linaro Ltd.
8 * www.linaro.org
713cc334
EA
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/io.h>
15
3c8d7ef8 16#include "../vfio_platform_private.h"
713cc334
EA
17
18#define DRIVER_VERSION "0.1"
19#define DRIVER_AUTHOR "Eric Auger <eric.auger@linaro.org>"
20#define DRIVER_DESC "Reset support for Calxeda xgmac vfio platform device"
21
713cc334
EA
22/* XGMAC Register definitions */
23#define XGMAC_CONTROL 0x00000000 /* MAC Configuration */
24
25/* DMA Control and Status Registers */
26#define XGMAC_DMA_CONTROL 0x00000f18 /* Ctrl (Operational Mode) */
27#define XGMAC_DMA_INTR_ENA 0x00000f1c /* Interrupt Enable */
28
29/* DMA Control registe defines */
30#define DMA_CONTROL_ST 0x00002000 /* Start/Stop Transmission */
31#define DMA_CONTROL_SR 0x00000002 /* Start/Stop Receive */
32
33/* Common MAC defines */
34#define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */
35#define MAC_ENABLE_RX 0x00000004 /* Receiver Enable */
36
37static inline void xgmac_mac_disable(void __iomem *ioaddr)
38{
39 u32 value = readl(ioaddr + XGMAC_DMA_CONTROL);
40
41 value &= ~(DMA_CONTROL_ST | DMA_CONTROL_SR);
42 writel(value, ioaddr + XGMAC_DMA_CONTROL);
43
44 value = readl(ioaddr + XGMAC_CONTROL);
45 value &= ~(MAC_ENABLE_TX | MAC_ENABLE_RX);
46 writel(value, ioaddr + XGMAC_CONTROL);
47}
48
2e062856 49static int vfio_platform_calxedaxgmac_reset(struct vfio_platform_device *vdev)
713cc334 50{
daac3bbe 51 struct vfio_platform_region *reg = &vdev->regions[0];
713cc334 52
daac3bbe
EA
53 if (!reg->ioaddr) {
54 reg->ioaddr =
55 ioremap_nocache(reg->addr, reg->size);
56 if (!reg->ioaddr)
713cc334
EA
57 return -ENOMEM;
58 }
59
60 /* disable IRQ */
daac3bbe 61 writel(0, reg->ioaddr + XGMAC_DMA_INTR_ENA);
713cc334
EA
62
63 /* Disable the MAC core */
daac3bbe 64 xgmac_mac_disable(reg->ioaddr);
713cc334
EA
65
66 return 0;
67}
713cc334 68
680742f6
EA
69module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_reset);
70
713cc334
EA
71MODULE_VERSION(DRIVER_VERSION);
72MODULE_LICENSE("GPL v2");
73MODULE_AUTHOR(DRIVER_AUTHOR);
74MODULE_DESCRIPTION(DRIVER_DESC);