Skip to content

Commit be4e119

Browse files
jbeptxdavem330
authored andcommitted
net: dsa: LAN9303: add I2C managed mode support
In this mode the switch device and the internal phys will be managed via I2C interface. The MDIO interface is still supported, but for the (emulated) CPU port only. Signed-off-by: Juergen Borleis <[email protected]> CC: [email protected] CC: [email protected] CC: [email protected] Acked-by: Rob Herring <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a129259 commit be4e119

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
SMSC/MicroChip LAN9303 three port ethernet switch
2+
-------------------------------------------------
3+
4+
Required properties:
5+
6+
- compatible: should be "smsc,lan9303-i2c"
7+
8+
Optional properties:
9+
10+
- reset-gpios: GPIO to be used to reset the whole device
11+
- reset-duration: reset duration in milliseconds, defaults to 200 ms
12+
13+
Subnodes:
14+
15+
The integrated switch subnode should be specified according to the binding
16+
described in dsa/dsa.txt. The CPU port of this switch is always port 0.
17+
18+
Note: always use 'reg = <0/1/2>;' for the three DSA ports, even if the device is
19+
configured to use 1/2/3 instead. This hardware configuration will be
20+
auto-detected and mapped accordingly.
21+
22+
Example:
23+
24+
I2C managed mode:
25+
26+
master: masterdevice@X {
27+
status = "okay";
28+
29+
fixed-link { /* RMII fixed link to LAN9303 */
30+
speed = <100>;
31+
full-duplex;
32+
};
33+
};
34+
35+
switch: switch@a {
36+
compatible = "smsc,lan9303-i2c";
37+
reg = <0xa>;
38+
status = "okay";
39+
reset-gpios = <&gpio7 6 GPIO_ACTIVE_LOW>;
40+
reset-duration = <200>;
41+
42+
ports {
43+
#address-cells = <1>;
44+
#size-cells = <0>;
45+
46+
port@0 { /* RMII fixed link to master */
47+
reg = <0>;
48+
label = "cpu";
49+
ethernet = <&master>;
50+
};
51+
52+
port@1 { /* external port 1 */
53+
reg = <1>;
54+
label = "lan1;
55+
};
56+
57+
port@2 { /* external port 2 */
58+
reg = <2>;
59+
label = "lan2";
60+
};
61+
};
62+
};

drivers/net/dsa/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,20 @@ config NET_DSA_MT7530
5050
This enables support for the Mediatek MT7530 Ethernet switch
5151
chip.
5252

53+
config NET_DSA_SMSC_LAN9303
54+
tristate
55+
select NET_DSA_TAG_LAN9303
56+
---help---
57+
This enables support for the SMSC/Microchip LAN9303 3 port ethernet
58+
switch chips.
59+
60+
config NET_DSA_SMSC_LAN9303_I2C
61+
tristate "SMSC/Microchip LAN9303 3-ports 10/100 ethernet switch in I2C managed mode"
62+
depends on NET_DSA
63+
select NET_DSA_SMSC_LAN9303
64+
select REGMAP_I2C
65+
---help---
66+
Enable access functions if the SMSC/Microchip LAN9303 is configured
67+
for I2C managed mode.
68+
5369
endmenu

drivers/net/dsa/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ obj-$(CONFIG_NET_DSA_BCM_SF2) += bcm-sf2.o
33
bcm-sf2-objs := bcm_sf2.o bcm_sf2_cfp.o
44
obj-$(CONFIG_NET_DSA_QCA8K) += qca8k.o
55
obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o
6+
obj-$(CONFIG_NET_DSA_SMSC_LAN9303) += lan9303-core.o
7+
obj-$(CONFIG_NET_DSA_SMSC_LAN9303_I2C) += lan9303_i2c.o
68
obj-y += b53/
79
obj-y += mv88e6xxx/
810
obj-$(CONFIG_NET_DSA_LOOP) += dsa_loop.o dsa_loop_bdinfo.o

drivers/net/dsa/lan9303_i2c.c

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (C) 2017 Pengutronix, Juergen Borleis <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
*/
14+
#include <linux/kernel.h>
15+
#include <linux/module.h>
16+
#include <linux/i2c.h>
17+
#include <linux/of.h>
18+
19+
#include "lan9303.h"
20+
21+
struct lan9303_i2c {
22+
struct i2c_client *device;
23+
struct lan9303 chip;
24+
};
25+
26+
static const struct regmap_config lan9303_i2c_regmap_config = {
27+
.reg_bits = 8,
28+
.val_bits = 32,
29+
.reg_stride = 1,
30+
.can_multi_write = true,
31+
.max_register = 0x0ff, /* address bits 0..1 are not used */
32+
.reg_format_endian = REGMAP_ENDIAN_LITTLE,
33+
34+
.volatile_table = &lan9303_register_set,
35+
.wr_table = &lan9303_register_set,
36+
.rd_table = &lan9303_register_set,
37+
38+
.cache_type = REGCACHE_NONE,
39+
};
40+
41+
static int lan9303_i2c_probe(struct i2c_client *client,
42+
const struct i2c_device_id *id)
43+
{
44+
struct lan9303_i2c *sw_dev;
45+
int ret;
46+
47+
sw_dev = devm_kzalloc(&client->dev, sizeof(struct lan9303_i2c),
48+
GFP_KERNEL);
49+
if (!sw_dev)
50+
return -ENOMEM;
51+
52+
sw_dev->chip.regmap = devm_regmap_init_i2c(client,
53+
&lan9303_i2c_regmap_config);
54+
if (IS_ERR(sw_dev->chip.regmap)) {
55+
ret = PTR_ERR(sw_dev->chip.regmap);
56+
dev_err(&client->dev, "Failed to allocate register map: %d\n",
57+
ret);
58+
return ret;
59+
}
60+
61+
/* link forward and backward */
62+
sw_dev->device = client;
63+
i2c_set_clientdata(client, sw_dev);
64+
sw_dev->chip.dev = &client->dev;
65+
66+
ret = lan9303_probe(&sw_dev->chip, client->dev.of_node);
67+
if (ret != 0)
68+
return ret;
69+
70+
dev_info(&client->dev, "LAN9303 I2C driver loaded successfully\n");
71+
72+
return 0;
73+
}
74+
75+
static int lan9303_i2c_remove(struct i2c_client *client)
76+
{
77+
struct lan9303_i2c *sw_dev;
78+
79+
sw_dev = i2c_get_clientdata(client);
80+
if (!sw_dev)
81+
return -ENODEV;
82+
83+
return lan9303_remove(&sw_dev->chip);
84+
}
85+
86+
/*-------------------------------------------------------------------------*/
87+
88+
static const struct i2c_device_id lan9303_i2c_id[] = {
89+
{ "lan9303", 0 },
90+
{ /* sentinel */ }
91+
};
92+
MODULE_DEVICE_TABLE(i2c, lan9303_i2c_id);
93+
94+
static const struct of_device_id lan9303_i2c_of_match[] = {
95+
{ .compatible = "smsc,lan9303-i2c", },
96+
{ /* sentinel */ },
97+
};
98+
MODULE_DEVICE_TABLE(of, lan9303_i2c_of_match);
99+
100+
static struct i2c_driver lan9303_i2c_driver = {
101+
.driver = {
102+
.name = "LAN9303_I2C",
103+
.of_match_table = of_match_ptr(lan9303_i2c_of_match),
104+
},
105+
.probe = lan9303_i2c_probe,
106+
.remove = lan9303_i2c_remove,
107+
.id_table = lan9303_i2c_id,
108+
};
109+
module_i2c_driver(lan9303_i2c_driver);
110+
111+
MODULE_AUTHOR("Juergen Borleis <[email protected]>");
112+
MODULE_DESCRIPTION("Driver for SMSC/Microchip LAN9303 three port ethernet switch in I2C managed mode");
113+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)