1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
// SPDX-License-Identifier: GPL-2.0+
/*
Copyright (c) 2016 Broadcom Corporation
All Rights Reserved
*/
/*
* Created on: June 2017
* Author: dima.mamut@broadcom.com
*/
/*
* MDIO driver for BCM96846 6856 and 6878
*/
#include "os_dep.h"
#include "mdio_drv_impl5.h"
#include "dt_access.h"
static uintptr_t mdio_base;
static uintptr_t pMdioMasterSelect;
static int mdio_probe(dt_device_t *pdev)
{
int ret;
mdio_base = dt_dev_remap_resource(pdev, 0);
if (IS_ERR(mdio_base))
{
ret = PTR_ERR(mdio_base);
mdio_base = NULL;
dev_err(&pdev->dev, "Missing mdio_base entry\n");
goto Exit;
}
pMdioMasterSelect = dt_dev_remap_resource(pdev, 1);
if (IS_ERR(pMdioMasterSelect))
{
ret = PTR_ERR(pMdioMasterSelect);
pMdioMasterSelect = NULL;
dev_err(&pdev->dev, "Missing MdioMasterSelect entry\n");
goto Exit;
}
dev_dbg(&pdev->dev, "mdio_base=0x%lx\n", mdio_base);
dev_dbg(&pdev->dev, "pMdioMasterSelect=0x%lx\n", pMdioMasterSelect);
dev_info(&pdev->dev, "registered\n");
return 0;
Exit:
return ret;
}
#ifdef __UBOOT__
static const struct udevice_id mdio_ids[] = {
#if defined(CONFIG_BCM63146) || defined(CONFIG_BCM4912)
{ .compatible = "brcm,mdio-sf2" }, //FIXME! redirect mdio-sf2 to mdio5 for now
#else
{ .compatible = "brcm,mdio5" },
#endif
{ /* end of list */ },
};
U_BOOT_DRIVER(brcm_mdio) = {
.name = "brcm-mdio",
.id = UCLASS_MISC,
.of_match = mdio_ids,
.probe = mdio_probe,
};
#else
static const struct of_device_id of_platform_table[] = {
{ .compatible = "brcm,mdio5" },
{ /* end of list */ },
};
static struct platform_driver of_platform_driver = {
.driver = {
.name = "brcm-mdio",
.of_match_table = of_platform_table,
},
.probe = mdio_probe,
};
module_platform_driver(of_platform_driver);
#endif
#define MDIO_CMD (void *)mdio_base
static DEFINE_SPINLOCK(mdio_access);
static void mdio_cfg_type(mdio_type_t type)
{
#if defined(CONFIG_BCM63146) || defined(CONFIG_BCM4912)
if (type != MDIO_INT)
#else
if (type == MDIO_INT)
#endif
*(uint32_t *)pMdioMasterSelect = 0;
else
*(uint32_t *)pMdioMasterSelect = 1;
}
int32_t mdio_read_c22_register(mdio_type_t type, uint32_t addr, uint32_t reg, uint16_t *val)
{
int ret = MDIO_OK;
spin_lock_bh(&mdio_access);
mdio_cfg_type(type);
ret = mdio_cmd_read_22(MDIO_CMD, addr, reg, val);
spin_unlock_bh(&mdio_access);
return ret;
}
EXPORT_SYMBOL(mdio_read_c22_register);
int32_t mdio_write_c22_register(mdio_type_t type, uint32_t addr, uint32_t reg, uint16_t val)
{
int ret = MDIO_OK;
spin_lock_bh(&mdio_access);
mdio_cfg_type(type);
ret = mdio_cmd_write_22(MDIO_CMD, addr, reg, val);
spin_unlock_bh(&mdio_access);
return ret;
}
EXPORT_SYMBOL(mdio_write_c22_register);
int32_t mdio_read_c45_register(mdio_type_t type, uint32_t addr, uint32_t dev, uint16_t reg, uint16_t *val)
{
int ret = MDIO_OK;
spin_lock_bh(&mdio_access);
mdio_cfg_type(type);
ret = mdio_cmd_read_45(MDIO_CMD, addr, dev, reg, val);
spin_unlock_bh(&mdio_access);
return ret;
}
EXPORT_SYMBOL(mdio_read_c45_register);
int32_t mdio_write_c45_register(mdio_type_t type, uint32_t addr, uint32_t dev, uint16_t reg, uint16_t val)
{
int ret = MDIO_OK;
spin_lock_bh(&mdio_access);
mdio_cfg_type(type);
ret = mdio_cmd_write_45(MDIO_CMD, addr, dev, reg, val);
spin_unlock_bh(&mdio_access);
return ret;
}
EXPORT_SYMBOL(mdio_write_c45_register);
|