dp83848.c 3.76 KB
Newer Older
1
2
3
/*
 * Driver for the Texas Instruments DP83848 PHY
 *
4
 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/module.h>
#include <linux/phy.h>

19
#define TI_DP83848C_PHY_ID		0x20005ca0
20
#define TI_DP83620_PHY_ID		0x20005ce0
21
#define NS_DP83848C_PHY_ID		0x20005c90
22
#define TLK10X_PHY_ID			0x2000a210
23
#define TI_DP83822_PHY_ID		0x2000a240
24
25

/* Registers */
26
27
#define DP83848_MICR			0x11 /* MII Interrupt Control Register */
#define DP83848_MISR			0x12 /* MII Interrupt Status Register */
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

/* MICR Register Fields */
#define DP83848_MICR_INT_OE		BIT(0) /* Interrupt Output Enable */
#define DP83848_MICR_INTEN		BIT(1) /* Interrupt Enable */

/* MISR Register Fields */
#define DP83848_MISR_RHF_INT_EN		BIT(0) /* Receive Error Counter */
#define DP83848_MISR_FHF_INT_EN		BIT(1) /* False Carrier Counter */
#define DP83848_MISR_ANC_INT_EN		BIT(2) /* Auto-negotiation complete */
#define DP83848_MISR_DUP_INT_EN		BIT(3) /* Duplex Status */
#define DP83848_MISR_SPD_INT_EN		BIT(4) /* Speed status */
#define DP83848_MISR_LINK_INT_EN	BIT(5) /* Link status */
#define DP83848_MISR_ED_INT_EN		BIT(6) /* Energy detect */
#define DP83848_MISR_LQM_INT_EN		BIT(7) /* Link Quality Monitor */

43
44
45
46
47
48
#define DP83848_INT_EN_MASK		\
	(DP83848_MISR_ANC_INT_EN |	\
	 DP83848_MISR_DUP_INT_EN |	\
	 DP83848_MISR_SPD_INT_EN |	\
	 DP83848_MISR_LINK_INT_EN)

49
50
51
52
53
54
55
56
57
static int dp83848_ack_interrupt(struct phy_device *phydev)
{
	int err = phy_read(phydev, DP83848_MISR);

	return err < 0 ? err : 0;
}

static int dp83848_config_intr(struct phy_device *phydev)
{
58
59
60
61
62
	int control, ret;

	control = phy_read(phydev, DP83848_MICR);
	if (control < 0)
		return control;
63
64

	if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
65
66
		control |= DP83848_MICR_INT_OE;
		control |= DP83848_MICR_INTEN;
67

68
69
70
71
72
		ret = phy_write(phydev, DP83848_MISR, DP83848_INT_EN_MASK);
		if (ret < 0)
			return ret;
	} else {
		control &= ~DP83848_MICR_INTEN;
73
74
	}

75
	return phy_write(phydev, DP83848_MICR, control);
76
77
78
}

static struct mdio_device_id __maybe_unused dp83848_tbl[] = {
79
80
	{ TI_DP83848C_PHY_ID, 0xfffffff0 },
	{ NS_DP83848C_PHY_ID, 0xfffffff0 },
81
	{ TI_DP83620_PHY_ID, 0xfffffff0 },
82
	{ TLK10X_PHY_ID, 0xfffffff0 },
83
	{ TI_DP83822_PHY_ID, 0xfffffff0 },
84
85
86
87
	{ }
};
MODULE_DEVICE_TABLE(mdio, dp83848_tbl);

88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#define DP83848_PHY_DRIVER(_id, _name)				\
	{							\
		.phy_id		= _id,				\
		.phy_id_mask	= 0xfffffff0,			\
		.name		= _name,			\
		.features	= PHY_BASIC_FEATURES,		\
		.flags		= PHY_HAS_INTERRUPT,		\
								\
		.soft_reset	= genphy_soft_reset,		\
		.config_init	= genphy_config_init,		\
		.suspend	= genphy_suspend,		\
		.resume		= genphy_resume,		\
		.config_aneg	= genphy_config_aneg,		\
		.read_status	= genphy_read_status,		\
								\
		/* IRQ related */				\
		.ack_interrupt	= dp83848_ack_interrupt,	\
		.config_intr	= dp83848_config_intr,		\
	}
107

108
static struct phy_driver dp83848_driver[] = {
109
	DP83848_PHY_DRIVER(TI_DP83848C_PHY_ID, "TI DP83848C 10/100 Mbps PHY"),
110
	DP83848_PHY_DRIVER(NS_DP83848C_PHY_ID, "NS DP83848C 10/100 Mbps PHY"),
111
	DP83848_PHY_DRIVER(TI_DP83620_PHY_ID, "TI DP83620 10/100 Mbps PHY"),
112
	DP83848_PHY_DRIVER(TLK10X_PHY_ID, "TI TLK10X 10/100 Mbps PHY"),
113
	DP83848_PHY_DRIVER(TI_DP83822_PHY_ID, "TI DP83822 10/100 Mbps PHY"),
114
115
116
117
118
119
};
module_phy_driver(dp83848_driver);

MODULE_DESCRIPTION("Texas Instruments DP83848 PHY driver");
MODULE_AUTHOR("Andrew F. Davis <afd@ti.com");
MODULE_LICENSE("GPL");