// SPDX-License-Identifier: GPL-2.0-only /* * Driver for ISSI IS31FL32xx family of I2C LED controllers * * Copyright 2015 Allworx Corp. * * Datasheets: * http://www.issi.com/US/product-analog-fxled-driver.shtml * http://www.si-en.com/product.asp?parentid=890 */ #include <linux/device.h> #include <linux/i2c.h> #include <linux/kernel.h> #include <linux/leds.h> #include <linux/module.h> #include <linux/of.h> /* Used to indicate a device has no such register */ #define IS31FL32XX_REG_NONE … /* Software Shutdown bit in Shutdown Register */ #define IS31FL32XX_SHUTDOWN_SSD_ENABLE … #define IS31FL32XX_SHUTDOWN_SSD_DISABLE … /* IS31FL3216 has a number of unique registers */ #define IS31FL3216_CONFIG_REG … #define IS31FL3216_LIGHTING_EFFECT_REG … #define IS31FL3216_CHANNEL_CONFIG_REG … /* Software Shutdown bit in 3216 Config Register */ #define IS31FL3216_CONFIG_SSD_ENABLE … #define IS31FL3216_CONFIG_SSD_DISABLE … struct is31fl32xx_priv; struct is31fl32xx_led_data { … }; struct is31fl32xx_priv { … }; /** * struct is31fl32xx_chipdef - chip-specific attributes * @channels : Number of LED channels * @shutdown_reg : address of Shutdown register (optional) * @pwm_update_reg : address of PWM Update register * @global_control_reg : address of Global Control register (optional) * @reset_reg : address of Reset register (optional) * @pwm_register_base : address of first PWM register * @pwm_registers_reversed: : true if PWM registers count down instead of up * @led_control_register_base : address of first LED control register (optional) * @enable_bits_per_led_control_register: number of LEDs enable bits in each * @reset_func : pointer to reset function * @sw_shutdown_func : pointer to software shutdown function * * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE * indicates that this chip has no such register. * * If non-NULL, @reset_func will be called during probing to set all * necessary registers to a known initialization state. This is needed * for chips that do not have a @reset_reg. * * @enable_bits_per_led_control_register must be >=1 if * @led_control_register_base != %IS31FL32XX_REG_NONE. */ struct is31fl32xx_chipdef { … }; static const struct is31fl32xx_chipdef is31fl3236_cdef = …; static const struct is31fl32xx_chipdef is31fl3235_cdef = …; static const struct is31fl32xx_chipdef is31fl3218_cdef = …; static int is31fl3216_reset(struct is31fl32xx_priv *priv); static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, bool enable); static const struct is31fl32xx_chipdef is31fl3216_cdef = …; static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val) { … } /* * Custom reset function for IS31FL3216 because it does not have a RESET * register the way that the other IS31FL32xx chips do. We don't bother * writing the GPIO and animation registers, because the registers we * do write ensure those will have no effect. */ static int is31fl3216_reset(struct is31fl32xx_priv *priv) { … } /* * Custom Software-Shutdown function for IS31FL3216 because it does not have * a SHUTDOWN register the way that the other IS31FL32xx chips do. * We don't bother doing a read/modify/write on the CONFIG register because * we only ever use a value of '0' for the other fields in that register. */ static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv, bool enable) { … } /* * NOTE: A mutex is not needed in this function because: * - All referenced data is read-only after probe() * - The I2C core has a mutex on to protect the bus * - There are no read/modify/write operations * - Intervening operations between the write of the PWM register * and the Update register are harmless. * * Example: * PWM_REG_1 write 16 * UPDATE_REG write 0 * PWM_REG_2 write 128 * UPDATE_REG write 0 * vs: * PWM_REG_1 write 16 * PWM_REG_2 write 128 * UPDATE_REG write 0 * UPDATE_REG write 0 * are equivalent. Poking the Update register merely applies all PWM * register writes up to that point. */ static int is31fl32xx_brightness_set(struct led_classdev *led_cdev, enum led_brightness brightness) { … } static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv) { … } static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv, bool enable) { … } static int is31fl32xx_init_regs(struct is31fl32xx_priv *priv) { … } static int is31fl32xx_parse_child_dt(const struct device *dev, const struct device_node *child, struct is31fl32xx_led_data *led_data) { … } static struct is31fl32xx_led_data *is31fl32xx_find_led_data( struct is31fl32xx_priv *priv, u8 channel) { … } static int is31fl32xx_parse_dt(struct device *dev, struct is31fl32xx_priv *priv) { … } static const struct of_device_id of_is31fl32xx_match[] = …; MODULE_DEVICE_TABLE(of, of_is31fl32xx_match); static int is31fl32xx_probe(struct i2c_client *client) { … } static void is31fl32xx_remove(struct i2c_client *client) { … } /* * i2c-core (and modalias) requires that id_table be properly filled, * even though it is not used for DeviceTree based instantiation. */ static const struct i2c_device_id is31fl32xx_id[] = …; MODULE_DEVICE_TABLE(i2c, is31fl32xx_id); static struct i2c_driver is31fl32xx_driver = …; module_i2c_driver(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;