/* * drivers/leds/leds-mlxcpld.c * Copyright (c) 2016 Mellanox Technologies. All rights reserved. * Copyright (c) 2016 Vadim Pasternak <[email protected]> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the names of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <linux/acpi.h> #include <linux/device.h> #include <linux/dmi.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/io.h> #include <linux/leds.h> #include <linux/module.h> #include <linux/mod_devicetable.h> #include <linux/platform_device.h> #include <linux/slab.h> #define MLXPLAT_CPLD_LPC_REG_BASE_ADRR … /* Color codes for LEDs */ #define MLXCPLD_LED_OFFSET_HALF … #define MLXCPLD_LED_OFFSET_FULL … #define MLXCPLD_LED_IS_OFF … #define MLXCPLD_LED_RED_STATIC_ON … #define MLXCPLD_LED_RED_BLINK_HALF … #define MLXCPLD_LED_RED_BLINK_FULL … #define MLXCPLD_LED_GREEN_STATIC_ON … #define MLXCPLD_LED_GREEN_BLINK_HALF … #define MLXCPLD_LED_GREEN_BLINK_FULL … #define MLXCPLD_LED_BLINK_3HZ … #define MLXCPLD_LED_BLINK_6HZ … /** * struct mlxcpld_param - LED access parameters: * @offset: offset for LED access in CPLD device * @mask: mask for LED access in CPLD device * @base_color: base color code for LED **/ struct mlxcpld_param { … }; /** * struct mlxcpld_led_priv - LED private data: * @cdev: LED class device instance * @param: LED CPLD access parameters **/ struct mlxcpld_led_priv { … }; #define cdev_to_priv(c) … /** * struct mlxcpld_led_profile - system LED profile (defined per system class): * @offset: offset for LED access in CPLD device * @mask: mask for LED access in CPLD device * @base_color: base color code * @brightness: default brightness setting (on/off) * @name: LED name **/ struct mlxcpld_led_profile { … }; /** * struct mlxcpld_led_pdata - system LED private data * @pdev: platform device pointer * @pled: LED class device instance * @profile: system configuration profile * @num_led_instances: number of LED instances * @lock: device access lock **/ struct mlxcpld_led_pdata { … }; static struct mlxcpld_led_pdata *mlxcpld_led; /* Default profile fit the next Mellanox systems: * "msx6710", "msx6720", "msb7700", "msn2700", "msx1410", * "msn2410", "msb7800", "msn2740" */ static struct mlxcpld_led_profile mlxcpld_led_default_profile[] = …; /* Profile fit the Mellanox systems based on "msn2100" */ static struct mlxcpld_led_profile mlxcpld_led_msn2100_profile[] = …; enum mlxcpld_led_platform_types { … }; static const char *mlx_product_names[] = …; static enum mlxcpld_led_platform_types mlxcpld_led_platform_check_sys_type(void) { … } static void mlxcpld_led_bus_access_func(u16 base, u8 offset, u8 rw_flag, u8 *data) { … } static void mlxcpld_led_store_hw(u8 mask, u8 off, u8 vset) { … } static void mlxcpld_led_brightness_set(struct led_classdev *led, enum led_brightness value) { … } static int mlxcpld_led_blink_set(struct led_classdev *led, unsigned long *delay_on, unsigned long *delay_off) { … } static int mlxcpld_led_config(struct device *dev, struct mlxcpld_led_pdata *cpld) { … } static int __init mlxcpld_led_probe(struct platform_device *pdev) { … } static struct platform_driver mlxcpld_led_driver = …; static int __init mlxcpld_led_init(void) { … } static void __exit mlxcpld_led_exit(void) { … } module_init(…) …; module_exit(mlxcpld_led_exit); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; MODULE_ALIAS(…) …;