1 // SPDX-License-Identifier: GPL-2.0-only
3 * Shared library for Kinetic's ExpressWire protocol.
4 * This protocol works by pulsing the ExpressWire IC's control GPIO.
5 * ktd2692 and ktd2801 are known to use this protocol.
8 #include <linux/bits.h>
9 #include <linux/delay.h>
10 #include <linux/export.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/types.h>
14 #include <linux/leds-expresswire.h>
16 void expresswire_power_off(struct expresswire_common_props
*props
)
18 gpiod_set_value_cansleep(props
->ctrl_gpio
, 0);
19 usleep_range(props
->timing
.poweroff_us
, props
->timing
.poweroff_us
* 2);
21 EXPORT_SYMBOL_NS_GPL(expresswire_power_off
, EXPRESSWIRE
);
23 void expresswire_enable(struct expresswire_common_props
*props
)
25 gpiod_set_value(props
->ctrl_gpio
, 1);
26 udelay(props
->timing
.detect_delay_us
);
27 gpiod_set_value(props
->ctrl_gpio
, 0);
28 udelay(props
->timing
.detect_us
);
29 gpiod_set_value(props
->ctrl_gpio
, 1);
31 EXPORT_SYMBOL_NS_GPL(expresswire_enable
, EXPRESSWIRE
);
33 void expresswire_start(struct expresswire_common_props
*props
)
35 gpiod_set_value(props
->ctrl_gpio
, 1);
36 udelay(props
->timing
.data_start_us
);
38 EXPORT_SYMBOL_NS_GPL(expresswire_start
, EXPRESSWIRE
);
40 void expresswire_end(struct expresswire_common_props
*props
)
42 gpiod_set_value(props
->ctrl_gpio
, 0);
43 udelay(props
->timing
.end_of_data_low_us
);
44 gpiod_set_value(props
->ctrl_gpio
, 1);
45 udelay(props
->timing
.end_of_data_high_us
);
47 EXPORT_SYMBOL_NS_GPL(expresswire_end
, EXPRESSWIRE
);
49 void expresswire_set_bit(struct expresswire_common_props
*props
, bool bit
)
52 gpiod_set_value(props
->ctrl_gpio
, 0);
53 udelay(props
->timing
.short_bitset_us
);
54 gpiod_set_value(props
->ctrl_gpio
, 1);
55 udelay(props
->timing
.long_bitset_us
);
57 gpiod_set_value(props
->ctrl_gpio
, 0);
58 udelay(props
->timing
.long_bitset_us
);
59 gpiod_set_value(props
->ctrl_gpio
, 1);
60 udelay(props
->timing
.short_bitset_us
);
63 EXPORT_SYMBOL_NS_GPL(expresswire_set_bit
, EXPRESSWIRE
);
65 void expresswire_write_u8(struct expresswire_common_props
*props
, u8 val
)
67 expresswire_start(props
);
68 for (int i
= 7; i
>= 0; i
--)
69 expresswire_set_bit(props
, val
& BIT(i
));
70 expresswire_end(props
);
72 EXPORT_SYMBOL_NS_GPL(expresswire_write_u8
, EXPRESSWIRE
);