grpyhon-led-module: Add ability to read back color

To aid remote debugging we want to be able to
read back the set color on the RGB LED. This commit
implements this functionality.
This commit is contained in:
Markus Gothe 2021-10-01 18:14:22 +02:00
parent bd8dd65766
commit 924b54d8d3

View file

@ -43,10 +43,15 @@
static ssize_t get_led_color(struct device *dev,
struct device_attribute *attr, char *buf)
{
/* [ln] todo: dummy implementation */
int len;
struct sk9822_leds *sk9822 = dev_get_drvdata(dev);
len = scnprintf(buf, PAGE_SIZE, "%d\n", 123);
if (IS_ERR(sk9822)) {
printk(KERN_ERR "Platform get drvdata returned NULL\n");
return -EIO;
}
len = scnprintf(buf, PAGE_SIZE, "%02x%02x%02x\n", sk9822->led_colors[0].r, sk9822->led_colors[0].g, sk9822->led_colors[0].b);
if (len <= 0) {
dev_err(dev, "sk9822: Invalid sprintf len: %d\n", len);
return -EIO;