xref: /linux/drivers/net/dsa/motorcomm/mdio_bus.h (revision 4b8fbb875a5411ff81a937245af8d4361b8a7ce4)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (c) 2026 David Yang
4  */
5 
6 #ifndef _YT_MDIO_BUS_H
7 #define _YT_MDIO_BUS_H
8 
9 #include <linux/bitfield.h>
10 #include <linux/bits.h>
11 #include <linux/of.h>
12 
13 #define YT921X_EXT_MBUS_OP		0x6a000
14 #define YT921X_INT_MBUS_OP		0xf0000
15 #define  YT921X_MBUS_OP_START			BIT(0)
16 #define YT921X_EXT_MBUS_CTRL		0x6a004
17 #define YT921X_INT_MBUS_CTRL		0xf0004
18 #define  YT921X_MBUS_CTRL_PORT_M		GENMASK(25, 21)
19 #define   YT921X_MBUS_CTRL_PORT(x)			FIELD_PREP(YT921X_MBUS_CTRL_PORT_M, (x))
20 #define  YT921X_MBUS_CTRL_REG_M			GENMASK(20, 16)
21 #define   YT921X_MBUS_CTRL_REG(x)			FIELD_PREP(YT921X_MBUS_CTRL_REG_M, (x))
22 #define  YT921X_MBUS_CTRL_TYPE_M		GENMASK(11, 8)  /* wild guess */
23 #define   YT921X_MBUS_CTRL_TYPE(x)			FIELD_PREP(YT921X_MBUS_CTRL_TYPE_M, (x))
24 #define   YT921X_MBUS_CTRL_TYPE_C22			YT921X_MBUS_CTRL_TYPE(4)
25 #define  YT921X_MBUS_CTRL_OP_M			GENMASK(3, 2)  /* wild guess */
26 #define   YT921X_MBUS_CTRL_OP(x)			FIELD_PREP(YT921X_MBUS_CTRL_OP_M, (x))
27 #define   YT921X_MBUS_CTRL_WRITE			YT921X_MBUS_CTRL_OP(1)
28 #define   YT921X_MBUS_CTRL_READ				YT921X_MBUS_CTRL_OP(2)
29 #define YT921X_EXT_MBUS_DOUT		0x6a008
30 #define YT921X_INT_MBUS_DOUT		0xf0008
31 #define YT921X_EXT_MBUS_DIN		0x6a00c
32 #define YT921X_INT_MBUS_DIN		0xf000c
33 
34 struct yt921x_priv;
35 
36 int yt921x_intif_read(struct yt921x_priv *priv, int port, int reg, u16 *valp);
37 int yt921x_intif_write(struct yt921x_priv *priv, int port, int reg, u16 val);
38 int yt921x_intif_modify_changed(struct yt921x_priv *priv, int port, int reg,
39 				u16 mask, u16 val);
40 
41 static inline int
42 yt921x_intif_modify(struct yt921x_priv *priv, int port, int reg, u16 mask,
43 		    u16 val)
44 {
45 	int res;
46 
47 	res = yt921x_intif_modify_changed(priv, port, reg, mask, val);
48 	return res >= 0 ? 0 : res;
49 }
50 
51 int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp);
52 int yt921x_mbus_ext_init(struct yt921x_priv *priv, struct device_node *mnp);
53 
54 #endif
55