Skip to content

Commit 89c2670

Browse files
nbd168desmondc9
authored andcommitted
kernel: move ubnt ledbar driver to a separate package
Simplifies the tree by removing a non-upstream kernel patch and related kconfig symbols. Signed-off-by: Felix Fietkau <[email protected]>
1 parent 9928ed9 commit 89c2670

File tree

6 files changed

+94
-60
lines changed

6 files changed

+94
-60
lines changed

package/kernel/ubnt-ledbar/Makefile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Copyright (C) 2008-2010 OpenWrt.org
3+
#
4+
# This is free software, licensed under the GNU General Public License v2.
5+
# See /LICENSE for more information.
6+
#
7+
8+
include $(TOPDIR)/rules.mk
9+
include $(INCLUDE_DIR)/kernel.mk
10+
11+
PKG_NAME:=ubnt-ledbar
12+
PKG_RELEASE:=1
13+
PKG_LICENSE:=GPL-2.0
14+
15+
include $(INCLUDE_DIR)/package.mk
16+
17+
define KernelPackage/leds-ubnt-ledbar
18+
SUBMENU:=LED modules
19+
TITLE:=Ubiquiti UniFi 6 LR LED support
20+
FILES:= \
21+
$(PKG_BUILD_DIR)/leds-ubnt-ledbar.ko
22+
AUTOLOAD:=$(call AutoProbe,leds-ubnt-ledbar,1)
23+
DEPENDS:=+kmod-i2c-core
24+
endef
25+
26+
define KernelPackage/leds-ubnt-ledbar/description
27+
LED support for some Ubiquiti UniFi access points.
28+
endef
29+
30+
define Build/Compile
31+
$(KERNEL_MAKE) M="$(PKG_BUILD_DIR)" modules
32+
endef
33+
34+
$(eval $(call KernelPackage,leds-ubnt-ledbar))
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
obj-m := leds-ubnt-ledbar.o

target/linux/mediatek/files/drivers/leds/leds-ubnt-ledbar.c package/kernel/ubnt-ledbar/src/leds-ubnt-ledbar.c

+59-14
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,43 @@
2626
#define UBNT_LEDBAR_MAX_BRIGHTNESS 0xff
2727

2828
#define UBNT_LEDBAR_TRANSACTION_LENGTH 8
29-
#define UBNT_LEDBAR_TRANSACTION_SUCCESS 0xaa
29+
#define UBNT_LEDBAR_TRANSACTION_SUCCESS (char) 0xaa
3030

3131
#define UBNT_LEDBAR_TRANSACTION_BLUE_IDX 2
3232
#define UBNT_LEDBAR_TRANSACTION_GREEN_IDX 3
3333
#define UBNT_LEDBAR_TRANSACTION_RED_IDX 4
34+
#define UBNT_LEDBAR_TRANSACTION_LED_COUNT_IDX 6
3435

3536
struct ubnt_ledbar {
3637
struct mutex lock;
38+
u32 led_count;
3739
struct i2c_client *client;
3840
struct led_classdev led_red;
3941
struct led_classdev led_green;
4042
struct led_classdev led_blue;
4143
struct gpio_desc *enable_gpio;
44+
struct gpio_desc *reset_gpio;
4245
};
4346

44-
static int ubnt_ledbar_perform_transaction(struct ubnt_ledbar *ledbar,
45-
char *transaction)
47+
static void ubnt_ledbar_perform_transaction(struct ubnt_ledbar *ledbar,
48+
const char *transaction, int len,
49+
char *result, int result_len)
4650
{
47-
int ret;
4851
int i;
4952

50-
for (i = 0; i < UBNT_LEDBAR_TRANSACTION_LENGTH; i++)
53+
for (i = 0; i < len; i++)
5154
i2c_smbus_write_byte(ledbar->client, transaction[i]);
5255

53-
return i2c_smbus_read_byte(ledbar->client);
56+
for (i = 0; i < result_len; i++)
57+
result[i] = i2c_smbus_read_byte(ledbar->client);
5458
}
5559

5660
static int ubnt_ledbar_apply_state(struct ubnt_ledbar *ledbar)
5761
{
5862
char setup_msg[UBNT_LEDBAR_TRANSACTION_LENGTH] = {0x40, 0x10, 0x00, 0x00,
5963
0x00, 0x00, 0x00, 0x11};
6064
char led_msg[UBNT_LEDBAR_TRANSACTION_LENGTH] = {0x40, 0x00, 0x00, 0x00,
61-
0x00, 0x00, 0x01, 0x00};
65+
0x00, 0x00, 0x00, 0x00};
6266
char i2c_response;
6367
int ret = 0;
6468

@@ -67,34 +71,63 @@ static int ubnt_ledbar_apply_state(struct ubnt_ledbar *ledbar)
6771
led_msg[UBNT_LEDBAR_TRANSACTION_BLUE_IDX] = ledbar->led_blue.brightness;
6872
led_msg[UBNT_LEDBAR_TRANSACTION_GREEN_IDX] = ledbar->led_green.brightness;
6973
led_msg[UBNT_LEDBAR_TRANSACTION_RED_IDX] = ledbar->led_red.brightness;
74+
led_msg[UBNT_LEDBAR_TRANSACTION_LED_COUNT_IDX] = ledbar->led_count;
7075

71-
gpiod_set_raw_value(ledbar->enable_gpio, 1);
76+
gpiod_set_value(ledbar->enable_gpio, 1);
7277

7378
msleep(10);
7479

75-
i2c_response = ubnt_ledbar_perform_transaction(ledbar, setup_msg);
80+
ubnt_ledbar_perform_transaction(ledbar, setup_msg, sizeof(setup_msg), &i2c_response, sizeof(i2c_response));
7681
if (i2c_response != UBNT_LEDBAR_TRANSACTION_SUCCESS) {
77-
dev_err(&ledbar->client->dev, "Error initializing LED transaction: %02x\n", ret);
82+
dev_err(&ledbar->client->dev, "Error initializing LED transaction: %02hhx\n", i2c_response);
7883
ret = -EINVAL;
7984
goto out_gpio;
8085
}
8186

82-
i2c_response = ubnt_ledbar_perform_transaction(ledbar, led_msg);
87+
ubnt_ledbar_perform_transaction(ledbar, led_msg, sizeof(led_msg), &i2c_response, sizeof(i2c_response));
8388
if (i2c_response != UBNT_LEDBAR_TRANSACTION_SUCCESS) {
84-
dev_err(&ledbar->client->dev, "Failed LED transaction: %02x\n", ret);
89+
dev_err(&ledbar->client->dev, "Failed LED transaction: %02hhx\n", i2c_response);
8590
ret = -EINVAL;
8691
goto out_gpio;
8792
}
8893

8994
msleep(10);
9095
out_gpio:
91-
gpiod_set_raw_value(ledbar->enable_gpio, 0);
96+
gpiod_set_value(ledbar->enable_gpio, 0);
9297

9398
mutex_unlock(&ledbar->lock);
9499

95100
return ret;
96101
}
97102

103+
static void ubnt_ledbar_reset(struct ubnt_ledbar *ledbar)
104+
{
105+
static const char init_msg[16] = {0x02, 0x81, 0xfd, 0x7e,
106+
0x00, 0x00, 0x00, 0x00,
107+
0x00, 0x00, 0x00, 0x00,
108+
0x00, 0x00, 0x00, 0x00};
109+
char init_response[4];
110+
111+
if (!ledbar->reset_gpio)
112+
return;
113+
114+
mutex_lock(&ledbar->lock);
115+
116+
gpiod_set_value(ledbar->reset_gpio, 1);
117+
msleep(10);
118+
gpiod_set_value(ledbar->reset_gpio, 0);
119+
120+
msleep(10);
121+
122+
gpiod_set_value(ledbar->enable_gpio, 1);
123+
msleep(10);
124+
ubnt_ledbar_perform_transaction(ledbar, init_msg, sizeof(init_msg), init_response, sizeof(init_response));
125+
msleep(10);
126+
gpiod_set_value(ledbar->enable_gpio, 0);
127+
128+
mutex_unlock(&ledbar->lock);
129+
}
130+
98131
#define UBNT_LEDBAR_CONTROL_RGBS(name) \
99132
static int ubnt_ledbar_set_##name##_brightness(struct led_classdev *led_cdev,\
100133
enum led_brightness value) \
@@ -153,14 +186,26 @@ static int ubnt_ledbar_probe(struct i2c_client *client,
153186
return ret;
154187
}
155188

156-
gpiod_direction_output(ledbar->enable_gpio, 0);
189+
ledbar->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW);
190+
191+
if (IS_ERR(ledbar->reset_gpio)) {
192+
ret = PTR_ERR(ledbar->reset_gpio);
193+
dev_err(&client->dev, "Failed to get reset gpio: %d\n", ret);
194+
return ret;
195+
}
196+
197+
ledbar->led_count = 1;
198+
of_property_read_u32(np, "led-count", &ledbar->led_count);
157199

158200
ledbar->client = client;
159201

160202
mutex_init(&ledbar->lock);
161203

162204
i2c_set_clientdata(client, ledbar);
163205

206+
// Reset and initialize the MCU
207+
ubnt_ledbar_reset(ledbar);
208+
164209
ledbar->led_red.brightness_set_blocking = ubnt_ledbar_set_red_brightness;
165210
ubnt_ledbar_init_led(of_get_child_by_name(np, "red"), ledbar, &ledbar->led_red);
166211

target/linux/mediatek/filogic/config-5.15

-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ CONFIG_IRQ_TIME_ACCOUNTING=y
197197
CONFIG_IRQ_WORK=y
198198
CONFIG_JBD2=y
199199
CONFIG_JUMP_LABEL=y
200-
# CONFIG_LEDS_UBNT_LEDBAR is not set
201200
CONFIG_LIBFDT=y
202201
CONFIG_LOCK_DEBUGGING_SUPPORT=y
203202
CONFIG_LOCK_SPIN_ON_OWNER=y

target/linux/mediatek/modules.mk

-16
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,3 @@ define KernelPackage/sdhci-mtk
3838
endef
3939

4040
$(eval $(call KernelPackage,sdhci-mtk))
41-
42-
define KernelPackage/leds-ubnt-ledbar
43-
SUBMENU:=LED modules
44-
TITLE:=Ubiquiti UniFi 6 LR LED support
45-
KCONFIG:=CONFIG_LEDS_UBNT_LEDBAR
46-
FILES:= \
47-
$(LINUX_DIR)/drivers/leds/leds-ubnt-ledbar.ko
48-
AUTOLOAD:=$(call AutoProbe,leds-ubnt-ledbar,1)
49-
DEPENDS:=@TARGET_mediatek_mt7622 +kmod-i2c-core
50-
endef
51-
52-
define KernelPackage/leds-ubnt-ledbar/description
53-
LED support for Ubiquiti UniFi 6 LR
54-
endef
55-
56-
$(eval $(call KernelPackage,leds-ubnt-ledbar))

target/linux/mediatek/patches-5.15/800-ubnt-ledbar-driver.patch

-29
This file was deleted.

0 commit comments

Comments
 (0)