1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Marvell 88E6xxx Switch Global 2 Registers support
5 * Copyright (c) 2008 Marvell Semiconductor
7 * Copyright (c) 2016-2017 Savoir-faire Linux Inc.
8 * Vivien Didelot <vivien.didelot@savoirfairelinux.com>
11 #include <linux/bitfield.h>
12 #include <linux/interrupt.h>
13 #include <linux/irqdomain.h>
16 #include "global1.h" /* for MV88E6XXX_G1_STS_IRQ_DEVICE */
19 int mv88e6xxx_g2_read(struct mv88e6xxx_chip
*chip
, int reg
, u16
*val
)
21 return mv88e6xxx_read(chip
, chip
->info
->global2_addr
, reg
, val
);
24 int mv88e6xxx_g2_write(struct mv88e6xxx_chip
*chip
, int reg
, u16 val
)
26 return mv88e6xxx_write(chip
, chip
->info
->global2_addr
, reg
, val
);
29 int mv88e6xxx_g2_wait_bit(struct mv88e6xxx_chip
*chip
, int reg
, int
32 return mv88e6xxx_wait_bit(chip
, chip
->info
->global2_addr
, reg
,
36 /* Offset 0x00: Interrupt Source Register */
38 static int mv88e6xxx_g2_int_source(struct mv88e6xxx_chip
*chip
, u16
*src
)
40 /* Read (and clear most of) the Interrupt Source bits */
41 return mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_INT_SRC
, src
);
44 /* Offset 0x01: Interrupt Mask Register */
46 static int mv88e6xxx_g2_int_mask(struct mv88e6xxx_chip
*chip
, u16 mask
)
48 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_INT_MASK
, mask
);
51 /* Offset 0x02: Management Enable 2x */
53 static int mv88e6xxx_g2_mgmt_enable_2x(struct mv88e6xxx_chip
*chip
, u16 en2x
)
55 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_MGMT_EN_2X
, en2x
);
58 /* Offset 0x03: Management Enable 0x */
60 static int mv88e6xxx_g2_mgmt_enable_0x(struct mv88e6xxx_chip
*chip
, u16 en0x
)
62 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_MGMT_EN_0X
, en0x
);
65 /* Offset 0x05: Switch Management Register */
67 static int mv88e6xxx_g2_switch_mgmt_rsvd2cpu(struct mv88e6xxx_chip
*chip
,
73 err
= mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_SWITCH_MGMT
, &val
);
78 val
|= MV88E6XXX_G2_SWITCH_MGMT_RSVD2CPU
;
80 val
&= ~MV88E6XXX_G2_SWITCH_MGMT_RSVD2CPU
;
82 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_SWITCH_MGMT
, val
);
85 int mv88e6185_g2_mgmt_rsvd2cpu(struct mv88e6xxx_chip
*chip
)
89 /* Consider the frames with reserved multicast destination
90 * addresses matching 01:80:c2:00:00:0x as MGMT.
92 err
= mv88e6xxx_g2_mgmt_enable_0x(chip
, 0xffff);
96 return mv88e6xxx_g2_switch_mgmt_rsvd2cpu(chip
, true);
99 int mv88e6352_g2_mgmt_rsvd2cpu(struct mv88e6xxx_chip
*chip
)
103 /* Consider the frames with reserved multicast destination
104 * addresses matching 01:80:c2:00:00:2x as MGMT.
106 err
= mv88e6xxx_g2_mgmt_enable_2x(chip
, 0xffff);
110 return mv88e6185_g2_mgmt_rsvd2cpu(chip
);
113 /* Offset 0x06: Device Mapping Table register */
115 int mv88e6xxx_g2_device_mapping_write(struct mv88e6xxx_chip
*chip
, int target
,
118 u16 val
= (target
<< 8) | (port
& 0x1f);
119 /* Modern chips use 5 bits to define a device mapping port,
120 * but bit 4 is reserved on older chips, so it is safe to use.
123 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_DEVICE_MAPPING
,
124 MV88E6XXX_G2_DEVICE_MAPPING_UPDATE
| val
);
127 /* Offset 0x07: Trunk Mask Table register */
129 int mv88e6xxx_g2_trunk_mask_write(struct mv88e6xxx_chip
*chip
, int num
,
132 u16 val
= (num
<< 12) | (mask
& mv88e6xxx_port_mask(chip
));
135 val
|= MV88E6XXX_G2_TRUNK_MASK_HASH
;
137 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_TRUNK_MASK
,
138 MV88E6XXX_G2_TRUNK_MASK_UPDATE
| val
);
141 /* Offset 0x08: Trunk Mapping Table register */
143 int mv88e6xxx_g2_trunk_mapping_write(struct mv88e6xxx_chip
*chip
, int id
,
146 const u16 port_mask
= BIT(mv88e6xxx_num_ports(chip
)) - 1;
147 u16 val
= (id
<< 11) | (map
& port_mask
);
149 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_TRUNK_MAPPING
,
150 MV88E6XXX_G2_TRUNK_MAPPING_UPDATE
| val
);
153 int mv88e6xxx_g2_trunk_clear(struct mv88e6xxx_chip
*chip
)
155 const u16 port_mask
= BIT(mv88e6xxx_num_ports(chip
)) - 1;
158 /* Clear all eight possible Trunk Mask vectors */
159 for (i
= 0; i
< 8; ++i
) {
160 err
= mv88e6xxx_g2_trunk_mask_write(chip
, i
, false, port_mask
);
165 /* Clear all sixteen possible Trunk ID routing vectors */
166 for (i
= 0; i
< 16; ++i
) {
167 err
= mv88e6xxx_g2_trunk_mapping_write(chip
, i
, 0);
175 /* Offset 0x09: Ingress Rate Command register
176 * Offset 0x0A: Ingress Rate Data register
179 static int mv88e6xxx_g2_irl_wait(struct mv88e6xxx_chip
*chip
)
181 int bit
= __bf_shf(MV88E6XXX_G2_IRL_CMD_BUSY
);
183 return mv88e6xxx_g2_wait_bit(chip
, MV88E6XXX_G2_IRL_CMD
, bit
, 0);
186 static int mv88e6xxx_g2_irl_op(struct mv88e6xxx_chip
*chip
, u16 op
, int port
,
191 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_IRL_CMD
,
192 MV88E6XXX_G2_IRL_CMD_BUSY
| op
| (port
<< 8) |
197 return mv88e6xxx_g2_irl_wait(chip
);
200 int mv88e6352_g2_irl_init_all(struct mv88e6xxx_chip
*chip
, int port
)
202 return mv88e6xxx_g2_irl_op(chip
, MV88E6352_G2_IRL_CMD_OP_INIT_ALL
, port
,
206 int mv88e6390_g2_irl_init_all(struct mv88e6xxx_chip
*chip
, int port
)
208 return mv88e6xxx_g2_irl_op(chip
, MV88E6390_G2_IRL_CMD_OP_INIT_ALL
, port
,
212 /* Offset 0x0B: Cross-chip Port VLAN (Addr) Register
213 * Offset 0x0C: Cross-chip Port VLAN Data Register
216 static int mv88e6xxx_g2_pvt_op_wait(struct mv88e6xxx_chip
*chip
)
218 int bit
= __bf_shf(MV88E6XXX_G2_PVT_ADDR_BUSY
);
220 return mv88e6xxx_g2_wait_bit(chip
, MV88E6XXX_G2_PVT_ADDR
, bit
, 0);
223 static int mv88e6xxx_g2_pvt_op(struct mv88e6xxx_chip
*chip
, int src_dev
,
224 int src_port
, u16 op
)
228 /* 9-bit Cross-chip PVT pointer: with MV88E6XXX_G2_MISC_5_BIT_PORT
229 * cleared, source device is 5-bit, source port is 4-bit.
231 op
|= MV88E6XXX_G2_PVT_ADDR_BUSY
;
232 op
|= (src_dev
& 0x1f) << 4;
233 op
|= (src_port
& 0xf);
235 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_PVT_ADDR
, op
);
239 return mv88e6xxx_g2_pvt_op_wait(chip
);
242 int mv88e6xxx_g2_pvt_read(struct mv88e6xxx_chip
*chip
, int src_dev
,
243 int src_port
, u16
*data
)
247 err
= mv88e6xxx_g2_pvt_op_wait(chip
);
251 err
= mv88e6xxx_g2_pvt_op(chip
, src_dev
, src_port
,
252 MV88E6XXX_G2_PVT_ADDR_OP_READ
);
256 return mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_PVT_DATA
, data
);
259 int mv88e6xxx_g2_pvt_write(struct mv88e6xxx_chip
*chip
, int src_dev
,
260 int src_port
, u16 data
)
264 err
= mv88e6xxx_g2_pvt_op_wait(chip
);
268 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_PVT_DATA
, data
);
272 return mv88e6xxx_g2_pvt_op(chip
, src_dev
, src_port
,
273 MV88E6XXX_G2_PVT_ADDR_OP_WRITE_PVLAN
);
276 /* Offset 0x0D: Switch MAC/WoL/WoF register */
278 static int mv88e6xxx_g2_switch_mac_write(struct mv88e6xxx_chip
*chip
,
279 unsigned int pointer
, u8 data
)
281 u16 val
= (pointer
<< 8) | data
;
283 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_SWITCH_MAC
,
284 MV88E6XXX_G2_SWITCH_MAC_UPDATE
| val
);
287 int mv88e6xxx_g2_set_switch_mac(struct mv88e6xxx_chip
*chip
, u8
*addr
)
291 for (i
= 0; i
< 6; i
++) {
292 err
= mv88e6xxx_g2_switch_mac_write(chip
, i
, addr
[i
]);
300 /* Offset 0x0E: ATU Statistics */
302 int mv88e6xxx_g2_atu_stats_set(struct mv88e6xxx_chip
*chip
, u16 kind
, u16 bin
)
304 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_ATU_STATS
,
308 int mv88e6xxx_g2_atu_stats_get(struct mv88e6xxx_chip
*chip
, u16
*stats
)
310 return mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_ATU_STATS
, stats
);
313 /* Offset 0x0F: Priority Override Table */
315 static int mv88e6xxx_g2_pot_write(struct mv88e6xxx_chip
*chip
, int pointer
,
318 u16 val
= (pointer
<< 8) | (data
& 0x7);
320 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_PRIO_OVERRIDE
,
321 MV88E6XXX_G2_PRIO_OVERRIDE_UPDATE
| val
);
324 int mv88e6xxx_g2_pot_clear(struct mv88e6xxx_chip
*chip
)
328 /* Clear all sixteen possible Priority Override entries */
329 for (i
= 0; i
< 16; i
++) {
330 err
= mv88e6xxx_g2_pot_write(chip
, i
, 0);
338 /* Offset 0x14: EEPROM Command
339 * Offset 0x15: EEPROM Data (for 16-bit data access)
340 * Offset 0x15: EEPROM Addr (for 8-bit data access)
343 int mv88e6xxx_g2_eeprom_wait(struct mv88e6xxx_chip
*chip
)
345 int bit
= __bf_shf(MV88E6XXX_G2_EEPROM_CMD_BUSY
);
348 err
= mv88e6xxx_g2_wait_bit(chip
, MV88E6XXX_G2_EEPROM_CMD
, bit
, 0);
352 bit
= __bf_shf(MV88E6XXX_G2_EEPROM_CMD_RUNNING
);
354 return mv88e6xxx_g2_wait_bit(chip
, MV88E6XXX_G2_EEPROM_CMD
, bit
, 0);
357 static int mv88e6xxx_g2_eeprom_cmd(struct mv88e6xxx_chip
*chip
, u16 cmd
)
361 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_EEPROM_CMD
,
362 MV88E6XXX_G2_EEPROM_CMD_BUSY
| cmd
);
366 return mv88e6xxx_g2_eeprom_wait(chip
);
369 static int mv88e6xxx_g2_eeprom_read8(struct mv88e6xxx_chip
*chip
,
372 u16 cmd
= MV88E6XXX_G2_EEPROM_CMD_OP_READ
;
375 err
= mv88e6xxx_g2_eeprom_wait(chip
);
379 err
= mv88e6xxx_g2_write(chip
, MV88E6390_G2_EEPROM_ADDR
, addr
);
383 err
= mv88e6xxx_g2_eeprom_cmd(chip
, cmd
);
387 err
= mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_EEPROM_CMD
, &cmd
);
396 static int mv88e6xxx_g2_eeprom_write8(struct mv88e6xxx_chip
*chip
,
399 u16 cmd
= MV88E6XXX_G2_EEPROM_CMD_OP_WRITE
|
400 MV88E6XXX_G2_EEPROM_CMD_WRITE_EN
;
403 err
= mv88e6xxx_g2_eeprom_wait(chip
);
407 err
= mv88e6xxx_g2_write(chip
, MV88E6390_G2_EEPROM_ADDR
, addr
);
411 return mv88e6xxx_g2_eeprom_cmd(chip
, cmd
| data
);
414 static int mv88e6xxx_g2_eeprom_read16(struct mv88e6xxx_chip
*chip
,
417 u16 cmd
= MV88E6XXX_G2_EEPROM_CMD_OP_READ
| addr
;
420 err
= mv88e6xxx_g2_eeprom_wait(chip
);
424 err
= mv88e6xxx_g2_eeprom_cmd(chip
, cmd
);
428 return mv88e6xxx_g2_read(chip
, MV88E6352_G2_EEPROM_DATA
, data
);
431 static int mv88e6xxx_g2_eeprom_write16(struct mv88e6xxx_chip
*chip
,
434 u16 cmd
= MV88E6XXX_G2_EEPROM_CMD_OP_WRITE
| addr
;
437 err
= mv88e6xxx_g2_eeprom_wait(chip
);
441 err
= mv88e6xxx_g2_write(chip
, MV88E6352_G2_EEPROM_DATA
, data
);
445 return mv88e6xxx_g2_eeprom_cmd(chip
, cmd
);
448 int mv88e6xxx_g2_get_eeprom8(struct mv88e6xxx_chip
*chip
,
449 struct ethtool_eeprom
*eeprom
, u8
*data
)
451 unsigned int offset
= eeprom
->offset
;
452 unsigned int len
= eeprom
->len
;
458 err
= mv88e6xxx_g2_eeprom_read8(chip
, offset
, data
);
471 int mv88e6xxx_g2_set_eeprom8(struct mv88e6xxx_chip
*chip
,
472 struct ethtool_eeprom
*eeprom
, u8
*data
)
474 unsigned int offset
= eeprom
->offset
;
475 unsigned int len
= eeprom
->len
;
481 err
= mv88e6xxx_g2_eeprom_write8(chip
, offset
, *data
);
494 int mv88e6xxx_g2_get_eeprom16(struct mv88e6xxx_chip
*chip
,
495 struct ethtool_eeprom
*eeprom
, u8
*data
)
497 unsigned int offset
= eeprom
->offset
;
498 unsigned int len
= eeprom
->len
;
505 err
= mv88e6xxx_g2_eeprom_read16(chip
, offset
>> 1, &val
);
509 *data
++ = (val
>> 8) & 0xff;
517 err
= mv88e6xxx_g2_eeprom_read16(chip
, offset
>> 1, &val
);
521 *data
++ = val
& 0xff;
522 *data
++ = (val
>> 8) & 0xff;
530 err
= mv88e6xxx_g2_eeprom_read16(chip
, offset
>> 1, &val
);
534 *data
++ = val
& 0xff;
544 int mv88e6xxx_g2_set_eeprom16(struct mv88e6xxx_chip
*chip
,
545 struct ethtool_eeprom
*eeprom
, u8
*data
)
547 unsigned int offset
= eeprom
->offset
;
548 unsigned int len
= eeprom
->len
;
552 /* Ensure the RO WriteEn bit is set */
553 err
= mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_EEPROM_CMD
, &val
);
557 if (!(val
& MV88E6XXX_G2_EEPROM_CMD_WRITE_EN
))
563 err
= mv88e6xxx_g2_eeprom_read16(chip
, offset
>> 1, &val
);
567 val
= (*data
++ << 8) | (val
& 0xff);
569 err
= mv88e6xxx_g2_eeprom_write16(chip
, offset
>> 1, val
);
582 err
= mv88e6xxx_g2_eeprom_write16(chip
, offset
>> 1, val
);
592 err
= mv88e6xxx_g2_eeprom_read16(chip
, offset
>> 1, &val
);
596 val
= (val
& 0xff00) | *data
++;
598 err
= mv88e6xxx_g2_eeprom_write16(chip
, offset
>> 1, val
);
610 /* Offset 0x18: SMI PHY Command Register
611 * Offset 0x19: SMI PHY Data Register
614 static int mv88e6xxx_g2_smi_phy_wait(struct mv88e6xxx_chip
*chip
)
616 int bit
= __bf_shf(MV88E6XXX_G2_SMI_PHY_CMD_BUSY
);
618 return mv88e6xxx_g2_wait_bit(chip
, MV88E6XXX_G2_SMI_PHY_CMD
, bit
, 0);
621 static int mv88e6xxx_g2_smi_phy_cmd(struct mv88e6xxx_chip
*chip
, u16 cmd
)
625 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_SMI_PHY_CMD
,
626 MV88E6XXX_G2_SMI_PHY_CMD_BUSY
| cmd
);
630 return mv88e6xxx_g2_smi_phy_wait(chip
);
633 static int mv88e6xxx_g2_smi_phy_access(struct mv88e6xxx_chip
*chip
,
634 bool external
, bool c45
, u16 op
, int dev
,
640 cmd
|= MV88E6390_G2_SMI_PHY_CMD_FUNC_EXTERNAL
;
642 cmd
|= MV88E6390_G2_SMI_PHY_CMD_FUNC_INTERNAL
; /* empty mask */
645 cmd
|= MV88E6XXX_G2_SMI_PHY_CMD_MODE_45
; /* empty mask */
647 cmd
|= MV88E6XXX_G2_SMI_PHY_CMD_MODE_22
;
649 dev
<<= __bf_shf(MV88E6XXX_G2_SMI_PHY_CMD_DEV_ADDR_MASK
);
650 cmd
|= dev
& MV88E6XXX_G2_SMI_PHY_CMD_DEV_ADDR_MASK
;
651 cmd
|= reg
& MV88E6XXX_G2_SMI_PHY_CMD_REG_ADDR_MASK
;
653 return mv88e6xxx_g2_smi_phy_cmd(chip
, cmd
);
656 static int mv88e6xxx_g2_smi_phy_access_c22(struct mv88e6xxx_chip
*chip
,
657 bool external
, u16 op
, int dev
,
660 return mv88e6xxx_g2_smi_phy_access(chip
, external
, false, op
, dev
, reg
);
663 /* IEEE 802.3 Clause 22 Read Data Register */
664 static int mv88e6xxx_g2_smi_phy_read_data_c22(struct mv88e6xxx_chip
*chip
,
665 bool external
, int dev
, int reg
,
668 u16 op
= MV88E6XXX_G2_SMI_PHY_CMD_OP_22_READ_DATA
;
671 err
= mv88e6xxx_g2_smi_phy_wait(chip
);
675 err
= mv88e6xxx_g2_smi_phy_access_c22(chip
, external
, op
, dev
, reg
);
679 return mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_SMI_PHY_DATA
, data
);
682 /* IEEE 802.3 Clause 22 Write Data Register */
683 static int mv88e6xxx_g2_smi_phy_write_data_c22(struct mv88e6xxx_chip
*chip
,
684 bool external
, int dev
, int reg
,
687 u16 op
= MV88E6XXX_G2_SMI_PHY_CMD_OP_22_WRITE_DATA
;
690 err
= mv88e6xxx_g2_smi_phy_wait(chip
);
694 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_SMI_PHY_DATA
, data
);
698 return mv88e6xxx_g2_smi_phy_access_c22(chip
, external
, op
, dev
, reg
);
701 static int mv88e6xxx_g2_smi_phy_access_c45(struct mv88e6xxx_chip
*chip
,
702 bool external
, u16 op
, int port
,
705 return mv88e6xxx_g2_smi_phy_access(chip
, external
, true, op
, port
, dev
);
708 /* IEEE 802.3 Clause 45 Write Address Register */
709 static int mv88e6xxx_g2_smi_phy_write_addr_c45(struct mv88e6xxx_chip
*chip
,
710 bool external
, int port
, int dev
,
713 u16 op
= MV88E6XXX_G2_SMI_PHY_CMD_OP_45_WRITE_ADDR
;
716 err
= mv88e6xxx_g2_smi_phy_wait(chip
);
720 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_SMI_PHY_DATA
, addr
);
724 return mv88e6xxx_g2_smi_phy_access_c45(chip
, external
, op
, port
, dev
);
727 /* IEEE 802.3 Clause 45 Read Data Register */
728 static int mv88e6xxx_g2_smi_phy_read_data_c45(struct mv88e6xxx_chip
*chip
,
729 bool external
, int port
, int dev
,
732 u16 op
= MV88E6XXX_G2_SMI_PHY_CMD_OP_45_READ_DATA
;
735 err
= mv88e6xxx_g2_smi_phy_access_c45(chip
, external
, op
, port
, dev
);
739 return mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_SMI_PHY_DATA
, data
);
742 static int _mv88e6xxx_g2_smi_phy_read_c45(struct mv88e6xxx_chip
*chip
,
743 bool external
, int port
, int devad
,
748 err
= mv88e6xxx_g2_smi_phy_write_addr_c45(chip
, external
, port
, devad
,
753 return mv88e6xxx_g2_smi_phy_read_data_c45(chip
, external
, port
, devad
,
757 /* IEEE 802.3 Clause 45 Write Data Register */
758 static int mv88e6xxx_g2_smi_phy_write_data_c45(struct mv88e6xxx_chip
*chip
,
759 bool external
, int port
, int dev
,
762 u16 op
= MV88E6XXX_G2_SMI_PHY_CMD_OP_45_WRITE_DATA
;
765 err
= mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_SMI_PHY_DATA
, data
);
769 return mv88e6xxx_g2_smi_phy_access_c45(chip
, external
, op
, port
, dev
);
772 static int _mv88e6xxx_g2_smi_phy_write_c45(struct mv88e6xxx_chip
*chip
,
773 bool external
, int port
, int devad
,
778 err
= mv88e6xxx_g2_smi_phy_write_addr_c45(chip
, external
, port
, devad
,
783 return mv88e6xxx_g2_smi_phy_write_data_c45(chip
, external
, port
, devad
,
787 int mv88e6xxx_g2_smi_phy_read_c22(struct mv88e6xxx_chip
*chip
,
789 int addr
, int reg
, u16
*val
)
791 struct mv88e6xxx_mdio_bus
*mdio_bus
= bus
->priv
;
792 bool external
= mdio_bus
->external
;
794 return mv88e6xxx_g2_smi_phy_read_data_c22(chip
, external
, addr
, reg
,
798 int mv88e6xxx_g2_smi_phy_read_c45(struct mv88e6xxx_chip
*chip
,
799 struct mii_bus
*bus
, int addr
, int devad
,
802 struct mv88e6xxx_mdio_bus
*mdio_bus
= bus
->priv
;
803 bool external
= mdio_bus
->external
;
805 return _mv88e6xxx_g2_smi_phy_read_c45(chip
, external
, addr
, devad
, reg
,
809 int mv88e6xxx_g2_smi_phy_write_c22(struct mv88e6xxx_chip
*chip
,
810 struct mii_bus
*bus
, int addr
, int reg
,
813 struct mv88e6xxx_mdio_bus
*mdio_bus
= bus
->priv
;
814 bool external
= mdio_bus
->external
;
816 return mv88e6xxx_g2_smi_phy_write_data_c22(chip
, external
, addr
, reg
,
820 int mv88e6xxx_g2_smi_phy_write_c45(struct mv88e6xxx_chip
*chip
,
821 struct mii_bus
*bus
, int addr
, int devad
,
824 struct mv88e6xxx_mdio_bus
*mdio_bus
= bus
->priv
;
825 bool external
= mdio_bus
->external
;
827 return _mv88e6xxx_g2_smi_phy_write_c45(chip
, external
, addr
, devad
, reg
,
831 /* Offset 0x1B: Watchdog Control */
832 static int mv88e6097_watchdog_action(struct mv88e6xxx_chip
*chip
, int irq
)
836 mv88e6xxx_g2_read(chip
, MV88E6352_G2_WDOG_CTL
, ®
);
838 dev_info(chip
->dev
, "Watchdog event: 0x%04x", reg
);
843 static void mv88e6097_watchdog_free(struct mv88e6xxx_chip
*chip
)
847 mv88e6xxx_g2_read(chip
, MV88E6352_G2_WDOG_CTL
, ®
);
849 reg
&= ~(MV88E6352_G2_WDOG_CTL_EGRESS_ENABLE
|
850 MV88E6352_G2_WDOG_CTL_QC_ENABLE
);
852 mv88e6xxx_g2_write(chip
, MV88E6352_G2_WDOG_CTL
, reg
);
855 static int mv88e6097_watchdog_setup(struct mv88e6xxx_chip
*chip
)
857 return mv88e6xxx_g2_write(chip
, MV88E6352_G2_WDOG_CTL
,
858 MV88E6352_G2_WDOG_CTL_EGRESS_ENABLE
|
859 MV88E6352_G2_WDOG_CTL_QC_ENABLE
|
860 MV88E6352_G2_WDOG_CTL_SWRESET
);
863 const struct mv88e6xxx_irq_ops mv88e6097_watchdog_ops
= {
864 .irq_action
= mv88e6097_watchdog_action
,
865 .irq_setup
= mv88e6097_watchdog_setup
,
866 .irq_free
= mv88e6097_watchdog_free
,
869 static void mv88e6250_watchdog_free(struct mv88e6xxx_chip
*chip
)
873 mv88e6xxx_g2_read(chip
, MV88E6250_G2_WDOG_CTL
, ®
);
875 reg
&= ~(MV88E6250_G2_WDOG_CTL_EGRESS_ENABLE
|
876 MV88E6250_G2_WDOG_CTL_QC_ENABLE
);
878 mv88e6xxx_g2_write(chip
, MV88E6250_G2_WDOG_CTL
, reg
);
881 static int mv88e6250_watchdog_setup(struct mv88e6xxx_chip
*chip
)
883 return mv88e6xxx_g2_write(chip
, MV88E6250_G2_WDOG_CTL
,
884 MV88E6250_G2_WDOG_CTL_EGRESS_ENABLE
|
885 MV88E6250_G2_WDOG_CTL_QC_ENABLE
|
886 MV88E6250_G2_WDOG_CTL_SWRESET
);
889 const struct mv88e6xxx_irq_ops mv88e6250_watchdog_ops
= {
890 .irq_action
= mv88e6097_watchdog_action
,
891 .irq_setup
= mv88e6250_watchdog_setup
,
892 .irq_free
= mv88e6250_watchdog_free
,
895 static int mv88e6390_watchdog_setup(struct mv88e6xxx_chip
*chip
)
897 return mv88e6xxx_g2_write(chip
, MV88E6390_G2_WDOG_CTL
,
898 MV88E6390_G2_WDOG_CTL_UPDATE
|
899 MV88E6390_G2_WDOG_CTL_PTR_INT_ENABLE
|
900 MV88E6390_G2_WDOG_CTL_CUT_THROUGH
|
901 MV88E6390_G2_WDOG_CTL_QUEUE_CONTROLLER
|
902 MV88E6390_G2_WDOG_CTL_EGRESS
|
903 MV88E6390_G2_WDOG_CTL_FORCE_IRQ
);
906 static int mv88e6390_watchdog_action(struct mv88e6xxx_chip
*chip
, int irq
)
910 mv88e6xxx_g2_write(chip
, MV88E6390_G2_WDOG_CTL
,
911 MV88E6390_G2_WDOG_CTL_PTR_EVENT
);
912 mv88e6xxx_g2_read(chip
, MV88E6390_G2_WDOG_CTL
, ®
);
914 dev_info(chip
->dev
, "Watchdog event: 0x%04x",
915 reg
& MV88E6390_G2_WDOG_CTL_DATA_MASK
);
917 mv88e6xxx_g2_write(chip
, MV88E6390_G2_WDOG_CTL
,
918 MV88E6390_G2_WDOG_CTL_PTR_HISTORY
);
919 mv88e6xxx_g2_read(chip
, MV88E6390_G2_WDOG_CTL
, ®
);
921 dev_info(chip
->dev
, "Watchdog history: 0x%04x",
922 reg
& MV88E6390_G2_WDOG_CTL_DATA_MASK
);
924 /* Trigger a software reset to try to recover the switch */
925 if (chip
->info
->ops
->reset
)
926 chip
->info
->ops
->reset(chip
);
928 mv88e6390_watchdog_setup(chip
);
933 static void mv88e6390_watchdog_free(struct mv88e6xxx_chip
*chip
)
935 mv88e6xxx_g2_write(chip
, MV88E6390_G2_WDOG_CTL
,
936 MV88E6390_G2_WDOG_CTL_UPDATE
|
937 MV88E6390_G2_WDOG_CTL_PTR_INT_ENABLE
);
940 const struct mv88e6xxx_irq_ops mv88e6390_watchdog_ops
= {
941 .irq_action
= mv88e6390_watchdog_action
,
942 .irq_setup
= mv88e6390_watchdog_setup
,
943 .irq_free
= mv88e6390_watchdog_free
,
946 static int mv88e6393x_watchdog_action(struct mv88e6xxx_chip
*chip
, int irq
)
948 mv88e6390_watchdog_action(chip
, irq
);
950 /* Fix for clearing the force WD event bit.
951 * Unreleased erratum on mv88e6393x.
953 mv88e6xxx_g2_write(chip
, MV88E6390_G2_WDOG_CTL
,
954 MV88E6390_G2_WDOG_CTL_UPDATE
|
955 MV88E6390_G2_WDOG_CTL_PTR_EVENT
);
960 const struct mv88e6xxx_irq_ops mv88e6393x_watchdog_ops
= {
961 .irq_action
= mv88e6393x_watchdog_action
,
962 .irq_setup
= mv88e6390_watchdog_setup
,
963 .irq_free
= mv88e6390_watchdog_free
,
966 static irqreturn_t
mv88e6xxx_g2_watchdog_thread_fn(int irq
, void *dev_id
)
968 struct mv88e6xxx_chip
*chip
= dev_id
;
969 irqreturn_t ret
= IRQ_NONE
;
971 mv88e6xxx_reg_lock(chip
);
972 if (chip
->info
->ops
->watchdog_ops
->irq_action
)
973 ret
= chip
->info
->ops
->watchdog_ops
->irq_action(chip
, irq
);
974 mv88e6xxx_reg_unlock(chip
);
979 static void mv88e6xxx_g2_watchdog_free(struct mv88e6xxx_chip
*chip
)
981 mv88e6xxx_reg_lock(chip
);
982 if (chip
->info
->ops
->watchdog_ops
->irq_free
)
983 chip
->info
->ops
->watchdog_ops
->irq_free(chip
);
984 mv88e6xxx_reg_unlock(chip
);
986 free_irq(chip
->watchdog_irq
, chip
);
987 irq_dispose_mapping(chip
->watchdog_irq
);
990 static int mv88e6xxx_g2_watchdog_setup(struct mv88e6xxx_chip
*chip
)
994 chip
->watchdog_irq
= irq_find_mapping(chip
->g2_irq
.domain
,
995 MV88E6XXX_G2_INT_SOURCE_WATCHDOG
);
996 if (chip
->watchdog_irq
< 0)
997 return chip
->watchdog_irq
;
999 snprintf(chip
->watchdog_irq_name
, sizeof(chip
->watchdog_irq_name
),
1000 "mv88e6xxx-%s-watchdog", dev_name(chip
->dev
));
1002 err
= request_threaded_irq(chip
->watchdog_irq
, NULL
,
1003 mv88e6xxx_g2_watchdog_thread_fn
,
1004 IRQF_ONESHOT
| IRQF_TRIGGER_FALLING
,
1005 chip
->watchdog_irq_name
, chip
);
1009 mv88e6xxx_reg_lock(chip
);
1010 if (chip
->info
->ops
->watchdog_ops
->irq_setup
)
1011 err
= chip
->info
->ops
->watchdog_ops
->irq_setup(chip
);
1012 mv88e6xxx_reg_unlock(chip
);
1017 /* Offset 0x1D: Misc Register */
1019 static int mv88e6xxx_g2_misc_5_bit_port(struct mv88e6xxx_chip
*chip
,
1025 err
= mv88e6xxx_g2_read(chip
, MV88E6XXX_G2_MISC
, &val
);
1030 val
|= MV88E6XXX_G2_MISC_5_BIT_PORT
;
1032 val
&= ~MV88E6XXX_G2_MISC_5_BIT_PORT
;
1034 return mv88e6xxx_g2_write(chip
, MV88E6XXX_G2_MISC
, val
);
1037 int mv88e6xxx_g2_misc_4_bit_port(struct mv88e6xxx_chip
*chip
)
1039 return mv88e6xxx_g2_misc_5_bit_port(chip
, false);
1042 static void mv88e6xxx_g2_irq_mask(struct irq_data
*d
)
1044 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
1045 unsigned int n
= d
->hwirq
;
1047 chip
->g2_irq
.masked
|= (1 << n
);
1050 static void mv88e6xxx_g2_irq_unmask(struct irq_data
*d
)
1052 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
1053 unsigned int n
= d
->hwirq
;
1055 chip
->g2_irq
.masked
&= ~(1 << n
);
1058 static irqreturn_t
mv88e6xxx_g2_irq_thread_fn(int irq
, void *dev_id
)
1060 struct mv88e6xxx_chip
*chip
= dev_id
;
1061 unsigned int nhandled
= 0;
1062 unsigned int sub_irq
;
1067 mv88e6xxx_reg_lock(chip
);
1068 err
= mv88e6xxx_g2_int_source(chip
, ®
);
1069 mv88e6xxx_reg_unlock(chip
);
1073 for (n
= 0; n
< 16; ++n
) {
1074 if (reg
& (1 << n
)) {
1075 sub_irq
= irq_find_mapping(chip
->g2_irq
.domain
, n
);
1076 handle_nested_irq(sub_irq
);
1081 return (nhandled
> 0 ? IRQ_HANDLED
: IRQ_NONE
);
1084 static void mv88e6xxx_g2_irq_bus_lock(struct irq_data
*d
)
1086 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
1088 mv88e6xxx_reg_lock(chip
);
1091 static void mv88e6xxx_g2_irq_bus_sync_unlock(struct irq_data
*d
)
1093 struct mv88e6xxx_chip
*chip
= irq_data_get_irq_chip_data(d
);
1096 err
= mv88e6xxx_g2_int_mask(chip
, ~chip
->g2_irq
.masked
);
1098 dev_err(chip
->dev
, "failed to mask interrupts\n");
1100 mv88e6xxx_reg_unlock(chip
);
1103 static const struct irq_chip mv88e6xxx_g2_irq_chip
= {
1104 .name
= "mv88e6xxx-g2",
1105 .irq_mask
= mv88e6xxx_g2_irq_mask
,
1106 .irq_unmask
= mv88e6xxx_g2_irq_unmask
,
1107 .irq_bus_lock
= mv88e6xxx_g2_irq_bus_lock
,
1108 .irq_bus_sync_unlock
= mv88e6xxx_g2_irq_bus_sync_unlock
,
1111 static int mv88e6xxx_g2_irq_domain_map(struct irq_domain
*d
,
1113 irq_hw_number_t hwirq
)
1115 struct mv88e6xxx_chip
*chip
= d
->host_data
;
1117 irq_set_chip_data(irq
, d
->host_data
);
1118 irq_set_chip_and_handler(irq
, &chip
->g2_irq
.chip
, handle_level_irq
);
1119 irq_set_noprobe(irq
);
1124 static const struct irq_domain_ops mv88e6xxx_g2_irq_domain_ops
= {
1125 .map
= mv88e6xxx_g2_irq_domain_map
,
1126 .xlate
= irq_domain_xlate_twocell
,
1129 void mv88e6xxx_g2_irq_free(struct mv88e6xxx_chip
*chip
)
1133 mv88e6xxx_g2_watchdog_free(chip
);
1135 free_irq(chip
->device_irq
, chip
);
1136 irq_dispose_mapping(chip
->device_irq
);
1138 for (irq
= 0; irq
< 16; irq
++) {
1139 virq
= irq_find_mapping(chip
->g2_irq
.domain
, irq
);
1140 irq_dispose_mapping(virq
);
1143 irq_domain_remove(chip
->g2_irq
.domain
);
1146 int mv88e6xxx_g2_irq_setup(struct mv88e6xxx_chip
*chip
)
1150 chip
->g2_irq
.masked
= ~0;
1151 mv88e6xxx_reg_lock(chip
);
1152 err
= mv88e6xxx_g2_int_mask(chip
, ~chip
->g2_irq
.masked
);
1153 mv88e6xxx_reg_unlock(chip
);
1157 chip
->g2_irq
.domain
= irq_domain_add_simple(
1158 chip
->dev
->of_node
, 16, 0, &mv88e6xxx_g2_irq_domain_ops
, chip
);
1159 if (!chip
->g2_irq
.domain
)
1162 for (irq
= 0; irq
< 16; irq
++)
1163 irq_create_mapping(chip
->g2_irq
.domain
, irq
);
1165 chip
->g2_irq
.chip
= mv88e6xxx_g2_irq_chip
;
1167 chip
->device_irq
= irq_find_mapping(chip
->g1_irq
.domain
,
1168 MV88E6XXX_G1_STS_IRQ_DEVICE
);
1169 if (chip
->device_irq
< 0) {
1170 err
= chip
->device_irq
;
1174 snprintf(chip
->device_irq_name
, sizeof(chip
->device_irq_name
),
1175 "mv88e6xxx-%s-g2", dev_name(chip
->dev
));
1177 err
= request_threaded_irq(chip
->device_irq
, NULL
,
1178 mv88e6xxx_g2_irq_thread_fn
,
1179 IRQF_ONESHOT
, chip
->device_irq_name
, chip
);
1183 return mv88e6xxx_g2_watchdog_setup(chip
);
1186 for (irq
= 0; irq
< 16; irq
++) {
1187 virq
= irq_find_mapping(chip
->g2_irq
.domain
, irq
);
1188 irq_dispose_mapping(virq
);
1191 irq_domain_remove(chip
->g2_irq
.domain
);
1196 int mv88e6xxx_g2_irq_mdio_setup(struct mv88e6xxx_chip
*chip
,
1197 struct mii_bus
*bus
)
1199 int phy_start
= chip
->info
->internal_phys_offset
;
1200 int phy_end
= chip
->info
->internal_phys_offset
+
1201 chip
->info
->num_internal_phys
;
1204 for (phy
= phy_start
; phy
< phy_end
; phy
++) {
1205 irq
= irq_find_mapping(chip
->g2_irq
.domain
, phy
);
1209 bus
->irq
[chip
->info
->phy_base_addr
+ phy
] = irq
;
1214 void mv88e6xxx_g2_irq_mdio_free(struct mv88e6xxx_chip
*chip
,
1215 struct mii_bus
*bus
)