2 * drivers/net/phy/gw16083.c
4 * Driver for GW16083 Ventana Ethernet Expansion Mezzanine
8 * Copyright (c) 2014 Tim Harvey <tharvey@gateworks.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
18 * The GW16083 interfaces with a Ventana baseboard via the PCIe bus, an i2c
19 * bus (i2c2), and a couple of GPIO's. On the PCIe bus is an i210 GigE with
20 * its MAC connected to Port4 of a Marvell MV88E6176 7-port GigE switch via
21 * MDIO and RGMII. Ports 0-3 are standard copper RJ45 but Ports 5 and 6
22 * connect to Marvell MV88E1111 dual-mode Copper/Fiber PHY's over SGMII and
23 * MDIO. The PHY's have both an RG45 for copper and an SFP module.
26 #include <linux/kernel.h>
27 #include <linux/string.h>
28 #include <linux/errno.h>
29 #include <linux/unistd.h>
30 #include <linux/i2c.h>
31 #include <linux/interrupt.h>
32 #include <linux/init.h>
33 #include <linux/delay.h>
34 #include <linux/device.h>
35 #include <linux/netdevice.h>
36 #include <linux/etherdevice.h>
37 #include <linux/skbuff.h>
38 #include <linux/spinlock.h>
40 #include <linux/module.h>
41 #include <linux/mii.h>
42 #include <linux/ethtool.h>
43 #include <linux/phy.h>
44 #include <linux/marvell_phy.h>
45 #include <linux/of_platform.h>
49 #include <linux/uaccess.h>
53 #undef FAIL_ON_CHECKSUM_ERR /* fail to configure SFP if checksum bad */
54 #define PORT_POWER_CONTROL /* ports can be enabled/disabled via sysfs */
55 #define PORT_MODE_CONTROL /* ports 5/6 can have SFP/RJ45 mode forced */
57 MODULE_DESCRIPTION("GW16083 driver");
58 MODULE_AUTHOR("Tim Harvey");
59 MODULE_LICENSE("GPL");
61 struct mv88e1111_port_state {
72 struct mv88e1111_priv {
73 struct phy_device *phydev;
74 struct i2c_client *client;
75 struct mv88e1111_port_state port5;
76 struct mv88e1111_port_state port6;
77 struct kobject *sysfs_kobj;
85 static struct i2c_client *gw16083_client = NULL;
87 static int gw16083_read_port_sfp(struct i2c_client *client,
88 struct mv88e1111_port_state *state);
90 /* read switch port register from port0-6 */
91 u16 read_switch_port(struct phy_device *pdev, int port, u8 regaddr)
93 return pdev->bus->read(pdev->bus, MV_BASE + port, regaddr);
96 /* write switch port register to port0-6 */
97 int write_switch_port(struct phy_device *pdev, int port, u8 regaddr, u16 val)
99 return pdev->bus->write(pdev->bus, MV_BASE + port, regaddr, val);
103 * read_switch_port_phy - write a register for a specific port on 88E6176
104 * The 88E6176 PHY registers must be accessed thorugh the Global2 address
105 * using the SMI_PHY_COMMAND_REG and SMI_PHY_DATA_REG.
107 int read_switch_port_phy(struct phy_device *pdev, int port, u8 regaddr)
112 dev_dbg(&pdev->dev, "read_phy: port%d reg=0x%02x\n", port, regaddr);
113 reg = SMIBUSY | SMIMODE22 | SMIOP_READ;
114 reg |= port << DEVADDR;
115 reg |= regaddr << REGADDR;
116 pdev->bus->write(pdev->bus, MV_GLOBAL2, MV_SMI_PHY_COMMAND, reg);
117 for (i = 0; i < 10; i++) {
118 reg = pdev->bus->read(pdev->bus, MV_GLOBAL2,
120 if (!(reg & (1<<15)))
127 reg = pdev->bus->read(pdev->bus, MV_GLOBAL2, MV_SMI_PHY_DATA);
132 * write_switch_port_phy - write a register for a specific port on 88E6176
133 * The 88E6176 PHY registers must be accessed thorugh the Global2 address
134 * using the SMI_PHY_COMMAND_REG and SMI_PHY_DATA_REG.
136 int write_switch_port_phy(struct phy_device *pdev, int port, u8 addr, u16 reg)
140 dev_dbg(&pdev->dev, "write_phy: port%d reg=0x%02x val=0x%04x\n", port,
142 pdev->bus->write(pdev->bus, MV_GLOBAL2, MV_SMI_PHY_DATA, reg);
143 reg = SMIBUSY | SMIMODE22 | SMIOP_WRITE;
144 reg |= port << DEVADDR;
145 reg |= addr << REGADDR;
146 pdev->bus->write(pdev->bus, MV_GLOBAL2, MV_SMI_PHY_COMMAND, reg);
147 for (i = 0; i < 10; i++) {
148 reg = pdev->bus->read(pdev->bus, MV_GLOBAL2,
150 if (!(reg & (1<<15)))
161 /* read a scratch register from switch */
162 inline u8 read_switch_scratch(struct phy_device *pdev, u8 reg)
164 pdev->bus->write(pdev->bus, MV_GLOBAL2, MV_SCRATCH_MISC, (reg << 8));
165 return pdev->bus->read(pdev->bus, MV_GLOBAL2, MV_SCRATCH_MISC) & 0xff;
168 /* write a scratch register to switch */
169 inline void write_switch_scratch(struct phy_device *pdev, u8 reg, u8 val)
171 pdev->bus->write(pdev->bus, MV_GLOBAL2, MV_SCRATCH_MISC,
172 (1 << 15) | (reg << 8) | val);
175 /* enable or disable an SFP's TXEN signal */
176 static int enable_sfp_txen(struct phy_device *pdev, int port, bool enable)
181 if (port != 5 && port != 6)
184 /* GPIO[2:1] output low to enable TXEN */
185 bit = (port == 5) ? 1 : 2;
186 gpio = read_switch_scratch(pdev, MV_GPIO_DATA);
191 write_switch_scratch(pdev, MV_GPIO_DATA, gpio);
192 dev_info(&pdev->dev, "Port%d: SFP TX %s\n", port, enable ?
193 "enabled" : "disabled");
197 /* configure mv88e1111 port for copper or serdes
198 * For Copper we set auto link/duplex/speed detection
199 * For SerDes/Fiber we force 1000mbps link up and auto-neg duplex
201 static int config_mv88e1111_port_sfp(struct phy_device *pdev, int port,
206 if (port != 5 && port != 6)
209 dev_dbg(&pdev->dev, "%s: Port%d %s\n", __func__, port,
210 sfp ? "SFP" : "copper");
212 enable_sfp_txen(pdev, port, 1);
214 /* configure MV88E6176 Physical Control Port Register */
216 "Port%d: SFP: force 1000mbps link up "
217 "(auto-negotiate duplex)\n",
219 reg = read_switch_port(pdev, port, MV_PORT_PHYS_CONTROL);
220 reg &= ~0x3f; /* clear 5-0 */
221 reg |= (1 << 4) | (1 << 5); /* force link up */
222 reg |= 2; /* force 1000mbps */
223 write_switch_port(pdev, port, MV_PORT_PHYS_CONTROL, reg);
224 reg = read_switch_port(pdev, port, MV_PORT_PHYS_CONTROL);
229 enable_sfp_txen(pdev, port, 0);
231 /* configure MV88E6176 Physical Control Port Register */
233 "Port%d: Copper: set auto-neg link/duplex/speed\n",
235 reg = read_switch_port(pdev, port, MV_PORT_PHYS_CONTROL);
236 reg &= ~0x3f; /* clear 5-0 */
237 reg |= 3; /* speed not forced */
238 write_switch_port(pdev, port, MV_PORT_PHYS_CONTROL, reg);
239 reg = read_switch_port(pdev, port, MV_PORT_PHYS_CONTROL);
241 dev_dbg(&pdev->dev, "%s: Port%d %s PORT_PHYS_CONTROL=0x%04x\n",
242 __func__, port, sfp ? "SFP" : "copper",
243 read_switch_port(pdev, port, MV_PORT_PHYS_CONTROL));
248 #if defined(PORT_POWER_CONTROL)
249 static int enable_switch_port(struct phy_device *pdev, int port, bool enable)
251 struct mv88e1111_priv *priv = dev_get_drvdata(&pdev->dev);
255 dev_info(&priv->client->dev, "Port%d: %s\n", port,
256 enable ? "normal operation" : "power down");
257 reg = read_switch_port_phy(pdev, port, MV_PHY_CONTROL);
259 reg &= ~(1 << 11); /* Normal Operation */
261 reg |= (1 << 11); /* power down */
262 write_switch_port_phy(pdev, port, MV_PHY_CONTROL, reg);
264 reg = read_switch_port_phy(pdev, port, MV_PHY_CONTROL1);
266 reg &= ~(1 << 2); /* Normal Operation */
268 reg |= (1 << 2); /* power down */
269 write_switch_port_phy(pdev, port, MV_PHY_CONTROL1, reg);
279 struct mv88e1111_port_state *get_port_state(struct mv88e1111_priv *priv,
290 * get MV88E6176 port number for a specific GW16083 port name
291 * The GW16083 ports as shown on the silkscreen are not mapped according to
292 * the MV88E6176 ports numbers.
294 static int gw16083_get_port(const char* name)
297 int map[] = { 3, 2, 1, 0, 5, 6 };
299 if (strncasecmp(name, "ETHERNET", 8) != 0 || strlen(name) != 9)
307 static ssize_t port_show(struct device *dev, struct device_attribute *attr,
310 struct mv88e1111_priv *priv = dev_get_drvdata(dev);
314 if (sscanf(attr->attr.name, "port%d", &port) != 1)
316 if (port < 0 || port > 6)
318 reg = read_switch_port_phy(priv->phydev, port, MV_PHY_CONTROL);
319 return sprintf(buf, "%s\n", (reg & (1 << 11)) ? "disabled" : "enabled");
322 #if defined(PORT_POWER_CONTROL)
323 static ssize_t port_store(struct device *dev, struct device_attribute *attr,
324 const char *buf, size_t count)
326 struct mv88e1111_priv *priv = dev_get_drvdata(dev);
330 port = gw16083_get_port(attr->attr.name);
333 if (sscanf(buf, "%d", &val) != 1)
335 enable_switch_port(priv->phydev, port, val ? 1 : 0);
339 static DEVICE_ATTR(ethernet1, S_IWUSR | S_IRUGO, port_show, port_store);
340 static DEVICE_ATTR(ethernet2, S_IWUSR | S_IRUGO, port_show, port_store);
341 static DEVICE_ATTR(ethernet3, S_IWUSR | S_IRUGO, port_show, port_store);
342 static DEVICE_ATTR(ethernet4, S_IWUSR | S_IRUGO, port_show, port_store);
343 static DEVICE_ATTR(ethernet5, S_IWUSR | S_IRUGO, port_show, port_store);
344 static DEVICE_ATTR(ethernet6, S_IWUSR | S_IRUGO, port_show, port_store);
346 static DEVICE_ATTR(ethernet1, S_IRUGO, port_show, NULL);
347 static DEVICE_ATTR(ethernet2, S_IRUGO, port_show, NULL);
348 static DEVICE_ATTR(ethernet3, S_IRUGO, port_show, NULL);
349 static DEVICE_ATTR(ethernet4, S_IRUGO, port_show, NULL);
350 static DEVICE_ATTR(ethernet5, S_IRUGO, port_show, NULL);
351 static DEVICE_ATTR(ethernet6, S_IRUGO, port_show, NULL);
354 static ssize_t portsfp_show(struct device *dev, struct device_attribute *attr,
357 struct mv88e1111_priv *priv = dev_get_drvdata(dev);
358 struct mv88e1111_port_state *state;
360 state = get_port_state(priv, gw16083_get_port(attr->attr.name));
364 if (!state->sfp_present)
367 return sprintf(buf, "%s\n", state->sfp_id);
370 static ssize_t portmode_show(struct device *dev, struct device_attribute *attr,
373 struct mv88e1111_priv *priv = dev_get_drvdata(dev);
374 struct mv88e1111_port_state *state;
376 state = get_port_state(priv, gw16083_get_port(attr->attr.name));
380 return sprintf(buf, "%s\n", state->serdes ? "SFP" : "RJ45");
382 static DEVICE_ATTR(ethernet5_sfp, S_IRUGO, portsfp_show, NULL);
383 static DEVICE_ATTR(ethernet6_sfp, S_IRUGO, portsfp_show, NULL);
385 #ifdef PORT_MODE_CONTROL
386 static ssize_t portmode_store(struct device *dev, struct device_attribute *attr,
387 const char *buf, size_t count)
389 struct mv88e1111_priv *priv = dev_get_drvdata(dev);
390 struct mv88e1111_port_state *state;
394 port = gw16083_get_port(attr->attr.name);
395 state = get_port_state(priv, port);
399 reg = read_switch_port_phy(priv->phydev, port, MII_M1111_PHY_EXT_SR);
400 if (strcasecmp(buf, "auto") == 0) {
401 reg &= ~(1<<15); /* enable auto-selection */
402 dev_info(&priv->client->dev, "Port%d: enable auto-selection\n",
404 } else if (strcasecmp(buf, "RJ45") == 0) {
405 reg |= (1<<15); /* disable auto-selection */
406 reg |= 0xb; /* RGMII to Copper */
407 config_mv88e1111_port_sfp(priv->phydev, port, 0);
408 dev_info(&priv->client->dev, "Port%d: select RJ45\n", port);
409 } else if (strcasecmp(buf, "SFP") == 0) {
410 reg |= (1<<15); /* disable auto-selection */
411 reg |= 0x3; /* RGMII to Fiber */
412 config_mv88e1111_port_sfp(priv->phydev, port, 1);
413 dev_info(&priv->client->dev, "Port%d: select SFP\n", port);
415 write_switch_port_phy(priv->phydev, port, MII_M1111_PHY_EXT_SR, reg);
420 static DEVICE_ATTR(ethernet5_mode, S_IWUSR | S_IRUGO, portmode_show,
422 static DEVICE_ATTR(ethernet6_mode, S_IWUSR | S_IRUGO, portmode_show,
425 static DEVICE_ATTR(ethernet5_mode, S_IRUGO, portmode_show, NULL);
426 static DEVICE_ATTR(ethernet6_mode, S_IRUGO, portmode_show, NULL);
435 mv88e6176_config_init(struct phy_device *pdev)
437 dev_dbg(&pdev->dev, "%s\n", __func__);
438 pdev->state = PHY_RUNNING;
443 /* check MV88E1111 PHY status and MV88E6176 GPIO */
445 mv88e6176_read_status(struct phy_device *pdev)
447 struct mv88e1111_priv *priv = dev_get_drvdata(&pdev->dev);
448 struct mv88e1111_port_state *state;
449 bool serdes, sfp_present, sfp_signal;
454 dev_dbg(&pdev->dev, "%s", __func__);
455 gpio = read_switch_scratch(pdev, MV_GPIO_DATA);
456 for (port = 5; port < 7; port++) {
457 serdes = (read_switch_port_phy(pdev, port, MII_M1111_PHY_EXT_SR)
459 dev_dbg(&pdev->dev, "%s: Port%d GPIO:0x%02x SerDes:%d\n",
460 __func__, port, gpio, serdes);
463 state = &priv->port5;
464 sfp_present = !((gpio >> 5) & 1);
465 sfp_signal = !((gpio >> 6) & 1);
468 state = &priv->port6;
469 sfp_present = !((gpio >> 3) & 1);
470 sfp_signal = !((gpio >> 4) & 1);
475 * on sfp_detect read/verify SFP MSA and set sfp_compat
476 * on sfp_signal issue link down?
477 * on serdes auto-select
479 if (state->sfp_present != sfp_present) {
480 state->sfp_present = sfp_present;
481 dev_info(&pdev->dev, "Port%d: SFP %s\n",
482 port, sfp_present ? "inserted" : "removed");
483 if (state->sfp_present) {
484 if (gw16083_read_port_sfp(priv->client, state))
485 state->sfp_compat = false;
487 state->sfp_compat = true;
488 /* trigger a re-select/enable below */
489 state->serdes = !serdes;
490 pdev->state = PHY_RUNNING;
492 state->sfp_compat = false;
493 state->sfp_enabled = false;
494 pdev->state = PHY_NOLINK;
497 if (state->sfp_signal != sfp_signal) {
498 state->sfp_signal = sfp_signal;
499 dev_info(&pdev->dev, "Port%d: SFP signal %s\n",
500 port, sfp_signal ? "detected" : "lost");
502 if (state->serdes != serdes) {
503 state->serdes = serdes;
504 dev_info(&pdev->dev, "Port%d: %s auto-selected\n",
505 port, serdes ? "SERDES" : "copper");
508 * if auto-selection has switched to copper
512 config_mv88e1111_port_sfp(pdev, port, 0);
513 state->sfp_enabled = false;
517 /* if compatible SFP module and not yet enabled then enable */
518 if (state->sfp_compat && state->sfp_signal &&
521 if (!config_mv88e1111_port_sfp(pdev, port, 1))
522 state->sfp_enabled = true;
530 mv88e6176_config_aneg(struct phy_device *pdev)
532 dev_dbg(&pdev->dev, "%s", __func__);
537 mv88e6176_remove(struct phy_device *pdev)
539 dev_dbg(&pdev->dev, "%s", __func__);
541 device_remove_file(&pdev->dev, &dev_attr_ethernet1);
542 device_remove_file(&pdev->dev, &dev_attr_ethernet2);
543 device_remove_file(&pdev->dev, &dev_attr_ethernet3);
544 device_remove_file(&pdev->dev, &dev_attr_ethernet4);
545 device_remove_file(&pdev->dev, &dev_attr_ethernet5);
546 device_remove_file(&pdev->dev, &dev_attr_ethernet6);
547 device_remove_file(&pdev->dev, &dev_attr_ethernet5_sfp);
548 device_remove_file(&pdev->dev, &dev_attr_ethernet6_sfp);
549 device_remove_file(&pdev->dev, &dev_attr_ethernet5_mode);
550 device_remove_file(&pdev->dev, &dev_attr_ethernet6_mode);
551 sysfs_remove_link(kernel_kobj, "gw16083");
555 mv88e6176_probe(struct phy_device *pdev)
560 struct mv88e1111_priv *priv;
562 dev_dbg(&pdev->dev, "%s: addr=0x%02x bus=%s:%s gw16083_client=%p\n",
563 __func__, pdev->addr, pdev->bus->name, pdev->bus->id,
566 /* In single-chip addressing mode the MV88E6176 shows up on 0x10-0x16 */
567 if (pdev->addr != MV_BASE)
570 /* i2c driver needs to be loaded first */
574 /* gw16083 has MV88E1676 hanging off of i210 mdio bus */
575 if (strcmp(pdev->bus->name, "igb_enet_mii_bus") != 0)
578 //dev_info(&pdev->dev, "Detected");
579 dev_info(&gw16083_client->dev, "%s: MV88E6176 7-port switch detected",
583 * port5/6 config: MV88E1111 PHY
584 * Register 20: PHY Control Register
585 * R20_7: add delay to RX_CLK for RXD
586 * R20_1: add delay to TX_CLK for TXD
587 * Register 24: LED Control Register
589 * Pulse stretch 170 to 340 ms
590 * Register 0: Control Register
593 for (port = 5; port < 7; port++) {
594 #ifndef RGMII_DELAY_ON_PHY
595 write_switch_port(pdev, port, MV_PORT_PHYS_CONTROL, 0xC003);
598 id = read_switch_port_phy(pdev, port,
599 MII_M1111_PHY_IDENT0) << 16;
600 id |= read_switch_port_phy(pdev, port, MII_M1111_PHY_IDENT1);
601 if ((id & MII_M1111_PHY_ID_MASK) != MII_M1111_PHY_ID) {
602 dev_err(&gw16083_client->dev,
603 "Port%d: No MV88E1111 PHY detected", port);
608 #ifdef RGMII_DELAY_ON_PHY
609 /* phy rx/tx delay */
610 reg = read_switch_port_phy(pdev, port, MII_M1111_PHY_EXT_CR);
611 reg |= (1<<1) | (1<<7);
612 write_switch_port_phy(pdev, port, MII_M1111_PHY_EXT_CR, reg);
615 write_switch_port_phy(pdev, port, MII_M1111_PHY_LED_CONTROL,
616 MII_M1111_PHY_LED_PULSE_STR);
618 reg = read_switch_port_phy(pdev, port, MII_M1111_PHY_CONTROL);
619 reg |= MII_M1111_PHY_CONTROL_RESET;
620 write_switch_port_phy(pdev, port, MII_M1111_PHY_CONTROL, reg);
621 dev_info(&gw16083_client->dev,
622 "Port%d MV88E111 PHY configured\n", port);
626 * GPIO Configuration:
627 * GPIO1: FIB5_TXEN# (output)
628 * GPIO2: FIB6_TXEN# (output)
629 * GPIO3: FIB6_PRES# (input)
630 * GPIO4: FIB6_LOS (input)
631 * GPIO5: FIB5_PRES# (input)
632 * GPIO6: FIB5_LOS (input)
634 write_switch_scratch(pdev, MV_GPIO_DATA, 0x06); /* GPIO[2:1] out hi */
635 write_switch_scratch(pdev, MV_GPIO_DIR, 0x78); /* GPIO[6:3] inp */
637 pdev->irq = PHY_POLL;
639 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
642 memset(priv, 0, sizeof(*priv));
644 priv->client = gw16083_client;
645 priv->port5.port = 5;
646 priv->port6.port = 6;
647 dev_set_drvdata(&pdev->dev, priv);
649 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet1);
650 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet2);
651 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet3);
652 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet4);
653 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet5);
654 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet6);
655 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet5_sfp);
656 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet6_sfp);
657 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet5_mode);
658 ret |= device_create_file(&pdev->dev, &dev_attr_ethernet6_mode);
661 dev_err(&pdev->dev, "Failed creating attrs\n");
663 /* Add a nice symlink to the real device */
664 ret = sysfs_create_link(kernel_kobj, &pdev->dev.kobj, "gw16083");
666 dev_dbg(&pdev->dev, "initial state: GPIO=0x%02x "
667 "Port5_serdes=%d Port6_serdes=%d\n",
668 read_switch_scratch(pdev, MV_GPIO_DATA),
669 (read_switch_port_phy(pdev, 5, MII_M1111_PHY_EXT_SR)
671 (read_switch_port_phy(pdev, 6, MII_M1111_PHY_EXT_SR)
677 static struct phy_driver mv88e6176_phy_driver = {
679 .phy_id = MV_IDENT_VALUE,
680 .phy_id_mask = MV_IDENT_MASK,
681 .features = PHY_BASIC_FEATURES,
682 .probe = &mv88e6176_probe,
683 .remove = &mv88e6176_remove,
684 .config_init = &mv88e6176_config_init,
685 .config_aneg = &mv88e6176_config_aneg,
686 .read_status = &mv88e6176_read_status,
687 .driver = { .owner = THIS_MODULE },
696 /* Basic ID fields */
719 /* extended id fields */
727 u8 sff8472_compliance;
730 /* Vendor specific ID fields */
752 const char* id_names[] = {
760 /* Flags for SFP modules compatible with ETH up to 1Gb */
772 #define STRING_APPEND(str, src) \
773 strncat(str, src, sizeof(src)); \
774 for (i = 1; i < sizeof(str); i++) \
775 if (str[i-1] == ' ' && str[i] == ' ') \
778 static int gw16083_read_port_sfp(struct i2c_client *client,
779 struct mv88e1111_port_state *state)
783 struct sfp_flags *eth_flags;
787 struct sfp_msa *sfp_msa = (struct sfp_msa *)data;
788 int port = state->port;
789 union i2c_smbus_data d;
791 dev_dbg(&client->dev, "%s Port%d\n", __func__, port);
792 if (!i2c_check_functionality(client->adapter,
793 I2C_FUNC_SMBUS_READ_I2C_BLOCK))
795 d.byte = (port == 5) ? 1 : 2;
796 if (i2c_smbus_xfer(client->adapter, GW16083_I2C_ADDR_PCA9543,
797 client->flags, I2C_SMBUS_WRITE, 0,
798 I2C_SMBUS_BYTE_DATA, &d) < 0)
800 dev_err(&client->dev,
801 "Port%d: failed writing PCA9543 register\n", port);
805 /* read all 256 bytes of SFP EEPROM */
806 for (i = 0; i < sizeof(data); i += I2C_SMBUS_BLOCK_MAX) {
807 d.block[0] = I2C_SMBUS_BLOCK_MAX;
808 if (i2c_smbus_xfer(client->adapter, GW16083_I2C_ADDR_SFP1,
809 client->flags, I2C_SMBUS_READ, i,
810 I2C_SMBUS_I2C_BLOCK_DATA, &d) < 0)
812 dev_err(&client->dev,
813 "Port%d: failed reading SFP data\n", port);
816 memcpy(data + i, d.block + 1, I2C_SMBUS_BLOCK_MAX);
819 /* Validate checksums */
820 for (crc = 0, i = 0; i < 63; i++)
822 if (crc != sfp_msa->cc_base) {
823 dev_err(&client->dev, "Port%d: "
824 "Checksum failure for Base ID fields: 0x%02x\n", port,
826 #ifdef FAIL_ON_CHECKSUM_ERR
830 for (crc = 0, i = 64; i < 95; i++)
832 if (crc != sfp_msa->cc_ext) {
833 dev_err(&client->dev, "Port%d: "
834 "Checksum failure for Extended ID fields: 0x%02x\n",
836 #ifdef FAIL_ON_CHECKSUM_ERR
840 state->sfp_id[0] = 0;
841 for (i = 0; id_names[i]; i++) {
842 if (sfp_msa->identifier == i) {
843 sprintf(state->sfp_id, "%s: ", id_names[i]);
847 STRING_APPEND(state->sfp_id, sfp_msa->vendor_oui);
848 STRING_APPEND(state->sfp_id, sfp_msa->vendor_name);
849 STRING_APPEND(state->sfp_id, sfp_msa->vendor_pn);
850 STRING_APPEND(state->sfp_id, sfp_msa->vendor_rev);
851 STRING_APPEND(state->sfp_id, sfp_msa->vendor_sn);
852 dev_info(&client->dev, "Port%d: %s\n", port, state->sfp_id);
854 if ((sfp_msa->identifier != GBIC) &&
855 (sfp_msa->identifier != SFF) &&
856 (sfp_msa->identifier != SFP))
858 dev_err(&client->dev, "Port%d: Unknown module identifier: %d\n",
859 port, sfp_msa->identifier);
864 eth_flags = (struct sfp_flags *)(sfp_msa->transceiver + 3);
865 if (eth_flags->e1000_base_sx) {
866 str = "1000Base-SX (Fiber)";
867 } else if (eth_flags->e1000_base_lx) {
868 str = "1000Base-LX (Fiber)";
869 } else if (eth_flags->e1000_base_t) {
870 str = "1000Base-T (Copper)";
871 } else if (eth_flags->e100_base_fx) {
872 str = "100Base-FX (Fiber) - not supported";
875 str = "Unknown/Unsupported media type";
879 dev_err(&client->dev, "Port%d: %s (0x%02x)\n", port, str,
880 sfp_msa->transceiver[3]);
882 dev_info(&client->dev, "Port%d: %s (0x%02x)\n", port, str,
883 sfp_msa->transceiver[3]);
888 static int gw16083_probe(struct i2c_client *client,
889 const struct i2c_device_id *id)
893 dev_info(&client->dev, "GW16083 Ethernet Expansion Mezzanine\n");
894 if (gw16083_client) {
895 dev_err(&client->dev, "client already registered\n");
898 gw16083_client = client;
900 ret = phy_driver_register(&mv88e6176_phy_driver);
902 dev_err(&client->dev,
903 "failed to register mv88e6176 phy driver: %d\n", ret);
907 static int gw16083_remove(struct i2c_client *client)
909 dev_dbg(&client->dev, "%s\n", __func__);
911 phy_driver_unregister(&mv88e6176_phy_driver);
912 gw16083_client = NULL;
916 static const struct of_device_id gw16083_dt_ids[] = {
917 { .compatible = "gateworks,gw16083", },
921 MODULE_DEVICE_TABLE(of, gw16083_dt_ids);
923 static const struct i2c_device_id gw16083_id[] = {
927 MODULE_DEVICE_TABLE(i2c, gw16083_id);
929 static struct i2c_driver gw16083_driver = {
932 .of_match_table = gw16083_dt_ids,
934 .probe = gw16083_probe,
935 .remove = gw16083_remove,
936 .id_table = gw16083_id,
939 static int __init mv88e6176_init(void)
941 return i2c_add_driver(&gw16083_driver);
944 static void __exit mv88e6176_exit(void)
946 i2c_del_driver(&gw16083_driver);
949 module_init(mv88e6176_init);
950 module_exit(mv88e6176_exit);