// SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2019 Christian Mauderer <[email protected]> /* * The driver supports controllers with a very simple SPI protocol: * - one LED is controlled by a single byte on MOSI * - the value of the byte gives the brightness between two values (lowest to * highest) * - no return value is necessary (no MISO signal) * * The value for minimum and maximum brightness depends on the device * (compatible string). * * Supported devices: * - "ubnt,acb-spi-led": Microcontroller (SONiX 8F26E611LA) based device used * for example in Ubiquiti airCube ISP. Reverse engineered protocol for this * controller: * * Higher two bits set a mode. Lower six bits are a parameter. * * Mode: 00 -> set brightness between 0x00 (min) and 0x3F (max) * * Mode: 01 -> pulsing pattern (min -> max -> min) with an interval. From * some tests, the period is about (50ms + 102ms * parameter). There is a * slightly different pattern starting from 0x10 (longer gap between the * pulses) but the time still follows that calculation. * * Mode: 10 -> same as 01 but with only a ramp from min to max. Again a * slight jump in the pattern at 0x10. * * Mode: 11 -> blinking (off -> 25% -> off -> 25% -> ...) with a period of * (105ms * parameter) * NOTE: This driver currently only supports mode 00. */ #include <linux/leds.h> #include <linux/mod_devicetable.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/property.h> #include <linux/spi/spi.h> #include <uapi/linux/uleds.h> struct spi_byte_chipdef { … }; struct spi_byte_led { … }; static const struct spi_byte_chipdef ubnt_acb_spi_led_cdef = …; static int spi_byte_brightness_set_blocking(struct led_classdev *dev, enum led_brightness brightness) { … } static int spi_byte_probe(struct spi_device *spi) { … } static const struct of_device_id spi_byte_dt_ids[] = …; MODULE_DEVICE_TABLE(of, spi_byte_dt_ids); static struct spi_driver spi_byte_driver = …; module_spi_driver(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; MODULE_ALIAS(…) …;