blob: d2123c428320c1990d51bdcb1151ff3294ed79cf (
plain)
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
|
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-11-26 GuEe-GUI first version
*/
#include "dwmac-platform.h"
rt_err_t dwmac_platform_register(struct rt_platform_device *pdev,
const struct dwmac_config *config)
{
rt_err_t err;
struct rt_device *dev = &pdev->parent;
struct dwmac_eth *eth = rt_calloc(1, sizeof(*eth));
if (!eth)
{
return -RT_ENOMEM;
}
eth->dev = dev;
eth->config = config;
eth->irq = rt_dm_dev_get_irq(dev, 0);
eth->mac_base = rt_dm_dev_iomap(dev, 0);
if (!eth->mac_base)
{
err = -RT_EIO;
goto _fail;
}
#ifdef RT_USING_OFW
if (rt_ofw_get_mac_addr(dev->ofw_node, eth->mac))
#endif
{
ethernet_random_addr(ð->parent, eth->mac);
}
dev->user_data = eth;
if ((err = dwmac_probe(eth)))
{
goto _fail_unmap;
}
return RT_EOK;
_fail_unmap:
dev->user_data = RT_NULL;
rt_iounmap(eth->mac_base);
_fail:
rt_free(eth);
return err;
}
rt_err_t dwmac_platform_remove(struct rt_platform_device *pdev)
{
struct dwmac_eth *eth = pdev->parent.user_data;
if (!eth)
{
return RT_EOK;
}
dwmac_remove(eth);
rt_iounmap(eth->mac_base);
rt_free(eth);
pdev->parent.user_data = RT_NULL;
return RT_EOK;
}
|