da73c1d3b8981bc225b8f5e2813ece333a7e7642
[openwrt/staging/wigyori.git] /
1 From 47b930d0dd437af927145dba50a2e2ea1ba97c67 Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Tue, 6 Feb 2024 18:31:12 +0100
4 Subject: [PATCH 09/10] net: phy: qcom: generalize some qca808x LED functions
5
6 Generalize some qca808x LED functions in preparation for qca807x LED
7 support.
8
9 The LED implementation of qca808x and qca807x is the same but qca807x
10 supports also Fiber port and have different hw control bits for Fiber
11 port. To limit code duplication introduce micro functions that takes reg
12 instead of LED index to tweak all the supported LED modes.
13
14 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 ---
17 drivers/net/phy/qcom/qca808x.c | 38 +++-----------------
18 drivers/net/phy/qcom/qcom-phy-lib.c | 54 +++++++++++++++++++++++++++++
19 drivers/net/phy/qcom/qcom.h | 7 ++++
20 3 files changed, 65 insertions(+), 34 deletions(-)
21
22 --- a/drivers/net/phy/qcom/qca808x.c
23 +++ b/drivers/net/phy/qcom/qca808x.c
24 @@ -437,9 +437,7 @@ static int qca808x_led_hw_control_enable
25 return -EINVAL;
26
27 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
28 -
29 - return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg,
30 - QCA808X_LED_FORCE_EN);
31 + return qca808x_led_reg_hw_control_enable(phydev, reg);
32 }
33
34 static int qca808x_led_hw_is_supported(struct phy_device *phydev, u8 index,
35 @@ -480,16 +478,12 @@ static int qca808x_led_hw_control_set(st
36 static bool qca808x_led_hw_control_status(struct phy_device *phydev, u8 index)
37 {
38 u16 reg;
39 - int val;
40
41 if (index > 2)
42 return false;
43
44 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
45 -
46 - val = phy_read_mmd(phydev, MDIO_MMD_AN, reg);
47 -
48 - return !(val & QCA808X_LED_FORCE_EN);
49 + return qca808x_led_reg_hw_control_status(phydev, reg);
50 }
51
52 static int qca808x_led_hw_control_get(struct phy_device *phydev, u8 index,
53 @@ -557,44 +551,20 @@ static int qca808x_led_brightness_set(st
54 }
55
56 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
57 -
58 - return phy_modify_mmd(phydev, MDIO_MMD_AN, reg,
59 - QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK,
60 - QCA808X_LED_FORCE_EN | (value ? QCA808X_LED_FORCE_ON :
61 - QCA808X_LED_FORCE_OFF));
62 + return qca808x_led_reg_brightness_set(phydev, reg, value);
63 }
64
65 static int qca808x_led_blink_set(struct phy_device *phydev, u8 index,
66 unsigned long *delay_on,
67 unsigned long *delay_off)
68 {
69 - int ret;
70 u16 reg;
71
72 if (index > 2)
73 return -EINVAL;
74
75 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
76 -
77 - /* Set blink to 50% off, 50% on at 4Hz by default */
78 - ret = phy_modify_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_LED_GLOBAL,
79 - QCA808X_LED_BLINK_FREQ_MASK | QCA808X_LED_BLINK_DUTY_MASK,
80 - QCA808X_LED_BLINK_FREQ_4HZ | QCA808X_LED_BLINK_DUTY_50_50);
81 - if (ret)
82 - return ret;
83 -
84 - /* We use BLINK_1 for normal blinking */
85 - ret = phy_modify_mmd(phydev, MDIO_MMD_AN, reg,
86 - QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK,
87 - QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_BLINK_1);
88 - if (ret)
89 - return ret;
90 -
91 - /* We set blink to 4Hz, aka 250ms */
92 - *delay_on = 250 / 2;
93 - *delay_off = 250 / 2;
94 -
95 - return 0;
96 + return qca808x_led_reg_blink_set(phydev, reg, delay_on, delay_off);
97 }
98
99 static int qca808x_led_polarity_set(struct phy_device *phydev, int index,
100 --- a/drivers/net/phy/qcom/qcom-phy-lib.c
101 +++ b/drivers/net/phy/qcom/qcom-phy-lib.c
102 @@ -620,3 +620,57 @@ int qca808x_cable_test_get_status(struct
103 return 0;
104 }
105 EXPORT_SYMBOL_GPL(qca808x_cable_test_get_status);
106 +
107 +int qca808x_led_reg_hw_control_enable(struct phy_device *phydev, u16 reg)
108 +{
109 + return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg,
110 + QCA808X_LED_FORCE_EN);
111 +}
112 +EXPORT_SYMBOL_GPL(qca808x_led_reg_hw_control_enable);
113 +
114 +bool qca808x_led_reg_hw_control_status(struct phy_device *phydev, u16 reg)
115 +{
116 + int val;
117 +
118 + val = phy_read_mmd(phydev, MDIO_MMD_AN, reg);
119 + return !(val & QCA808X_LED_FORCE_EN);
120 +}
121 +EXPORT_SYMBOL_GPL(qca808x_led_reg_hw_control_status);
122 +
123 +int qca808x_led_reg_brightness_set(struct phy_device *phydev,
124 + u16 reg, enum led_brightness value)
125 +{
126 + return phy_modify_mmd(phydev, MDIO_MMD_AN, reg,
127 + QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK,
128 + QCA808X_LED_FORCE_EN | (value ? QCA808X_LED_FORCE_ON :
129 + QCA808X_LED_FORCE_OFF));
130 +}
131 +EXPORT_SYMBOL_GPL(qca808x_led_reg_brightness_set);
132 +
133 +int qca808x_led_reg_blink_set(struct phy_device *phydev, u16 reg,
134 + unsigned long *delay_on,
135 + unsigned long *delay_off)
136 +{
137 + int ret;
138 +
139 + /* Set blink to 50% off, 50% on at 4Hz by default */
140 + ret = phy_modify_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_LED_GLOBAL,
141 + QCA808X_LED_BLINK_FREQ_MASK | QCA808X_LED_BLINK_DUTY_MASK,
142 + QCA808X_LED_BLINK_FREQ_4HZ | QCA808X_LED_BLINK_DUTY_50_50);
143 + if (ret)
144 + return ret;
145 +
146 + /* We use BLINK_1 for normal blinking */
147 + ret = phy_modify_mmd(phydev, MDIO_MMD_AN, reg,
148 + QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK,
149 + QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_BLINK_1);
150 + if (ret)
151 + return ret;
152 +
153 + /* We set blink to 4Hz, aka 250ms */
154 + *delay_on = 250 / 2;
155 + *delay_off = 250 / 2;
156 +
157 + return 0;
158 +}
159 +EXPORT_SYMBOL_GPL(qca808x_led_reg_blink_set);
160 --- a/drivers/net/phy/qcom/qcom.h
161 +++ b/drivers/net/phy/qcom/qcom.h
162 @@ -234,3 +234,10 @@ int at803x_cdt_start(struct phy_device *
163 int at803x_cdt_wait_for_completion(struct phy_device *phydev,
164 u32 cdt_en);
165 int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished);
166 +int qca808x_led_reg_hw_control_enable(struct phy_device *phydev, u16 reg);
167 +bool qca808x_led_reg_hw_control_status(struct phy_device *phydev, u16 reg);
168 +int qca808x_led_reg_brightness_set(struct phy_device *phydev,
169 + u16 reg, enum led_brightness value);
170 +int qca808x_led_reg_blink_set(struct phy_device *phydev, u16 reg,
171 + unsigned long *delay_on,
172 + unsigned long *delay_off);