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
|
/*
* Micrel KSZ8873
*
* Copyright (c) 2016 Pengutronix, Michael Grzeschik <m.grzeschik@pengutronix.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* http://www.opensource.org/licenses/gpl-license.html
* http://www.gnu.org/copyleft/gpl.html
*/
#include <linux/device.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/of_mdio.h>
#include <linux/phy.h>
#include <net/dsa.h>
#include <net/switchdev.h>
#include <linux/if_bridge.h>
#include "ksz_priv.h"
#include "ksz_spi.h"
static int ksz_spi_read(struct ksz_device *dev, u32 reg, u8 *data,
unsigned int len)
{
int i = 0;
for (i = 0; i < len; i++)
data[i] = (u8) mdiobus_read(dev->bus, 0, (reg + i) | MII_ADDR_SMI0);
return 0;
}
static int ksz_spi_write(struct ksz_device *dev, u32 reg, void *data,
unsigned int len)
{
int i = 0;
int ret = 0;
u8 *val = data;
for (i = 0; i < len; i++) {
ret = mdiobus_write(dev->bus, 0, (reg + i) | MII_ADDR_SMI0, val[i]);
if (ret < 0)
return ret;
}
return 0;
}
static const struct ksz_io_ops ksz8873_smi_ops = {
.read8 = ksz_spi_read8,
.read16 = ksz_spi_read16,
.read32 = ksz_spi_read32,
.write8 = ksz_spi_write8,
.write16 = ksz_spi_write16,
.write32 = ksz_spi_write32,
.get = ksz_spi_get,
.set = ksz_spi_set,
};
static int ksz8873_smi_probe(struct mdio_device *mdiodev)
{
struct ksz_device *dev;
int ret;
dev = ksz_switch_alloc(&mdiodev->dev, &ksz8873_smi_ops, mdiodev);
if (!dev)
return -EINVAL;
if (mdiodev->dev.platform_data)
dev->pdata = mdiodev->dev.platform_data;
dev->bus = mdiodev->bus;
ret = ksz8873_switch_register(dev);
/* Main DSA driver may not be started yet. */
if (ret)
return ret;
dev_set_drvdata(&mdiodev->dev, dev);
return 0;
}
static void ksz8873_smi_remove(struct mdio_device *mdiodev)
{
struct ksz_device *dev = dev_get_drvdata(&mdiodev->dev);
if (dev)
ksz_switch_remove(dev);
}
static const struct of_device_id ksz8873_dt_ids[] = {
{ .compatible = "micrel,ksz8873" },
{ .compatible = "micrel,ksz8863" },
{ },
};
MODULE_DEVICE_TABLE(of, ksz8873_dt_ids);
static struct mdio_driver ksz8873_driver = {
.probe = ksz8873_smi_probe,
.remove = ksz8873_smi_remove,
.mdiodrv.driver = {
.name = "ksz8873-switch",
.of_match_table = ksz8873_dt_ids,
},
};
mdio_module_driver(ksz8873_driver);
MODULE_AUTHOR("Michael Grzeschik <m.grzeschik@pengutronix.de>");
MODULE_DESCRIPTION("Micrel KSZ8873 SMI Switch driver");
MODULE_LICENSE("GPL v2");
|