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
6 Generalize some qca808x LED functions in preparation for qca807x LED
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.
14 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
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(-)
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
27 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
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);
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)
44 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
46 - val = phy_read_mmd(phydev, MDIO_MMD_AN, reg);
48 - return !(val & QCA808X_LED_FORCE_EN);
49 + return qca808x_led_reg_hw_control_status(phydev, reg);
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
56 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
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);
65 static int qca808x_led_blink_set(struct phy_device *phydev, u8 index,
66 unsigned long *delay_on,
67 unsigned long *delay_off)
75 reg = QCA808X_MMD7_LED_FORCE_CTRL(index);
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);
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);
91 - /* We set blink to 4Hz, aka 250ms */
92 - *delay_on = 250 / 2;
93 - *delay_off = 250 / 2;
96 + return qca808x_led_reg_blink_set(phydev, reg, delay_on, delay_off);
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
105 EXPORT_SYMBOL_GPL(qca808x_cable_test_get_status);
107 +int qca808x_led_reg_hw_control_enable(struct phy_device *phydev, u16 reg)
109 + return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg,
110 + QCA808X_LED_FORCE_EN);
112 +EXPORT_SYMBOL_GPL(qca808x_led_reg_hw_control_enable);
114 +bool qca808x_led_reg_hw_control_status(struct phy_device *phydev, u16 reg)
118 + val = phy_read_mmd(phydev, MDIO_MMD_AN, reg);
119 + return !(val & QCA808X_LED_FORCE_EN);
121 +EXPORT_SYMBOL_GPL(qca808x_led_reg_hw_control_status);
123 +int qca808x_led_reg_brightness_set(struct phy_device *phydev,
124 + u16 reg, enum led_brightness value)
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));
131 +EXPORT_SYMBOL_GPL(qca808x_led_reg_brightness_set);
133 +int qca808x_led_reg_blink_set(struct phy_device *phydev, u16 reg,
134 + unsigned long *delay_on,
135 + unsigned long *delay_off)
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);
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);
153 + /* We set blink to 4Hz, aka 250ms */
154 + *delay_on = 250 / 2;
155 + *delay_off = 250 / 2;
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,
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);