^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * leds-ns2.c - Driver for the Network Space v2 (and parents) dual-GPIO LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2010 LaCie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Simon Guinot <sguinot@lacie.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Based on leds-gpio.c by Raphael Assenat <raph@8d.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "leds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) enum ns2_led_modes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) NS_V2_LED_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) NS_V2_LED_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) NS_V2_LED_SATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * If the size of this structure or types of its members is changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * the filling of array modval in function ns2_led_register must be changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct ns2_led_modval {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) u32 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u32 cmd_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) u32 slow_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * The Network Space v2 dual-GPIO LED is wired to a CPLD. Three different LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * modes are available: off, on and SATA activity blinking. The LED modes are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * controlled through two GPIOs (command and slow): each combination of values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * for the command/slow GPIOs corresponds to a LED mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ns2_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct led_classdev cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct gpio_desc *cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct gpio_desc *slow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) bool can_sleep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned char sata; /* True when SATA mode active. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) rwlock_t rw_lock; /* Lock GPIOs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int num_modes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct ns2_led_modval *modval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) int cmd_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int slow_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) cmd_level = gpiod_get_value_cansleep(led->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) slow_level = gpiod_get_value_cansleep(led->slow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) for (i = 0; i < led->num_modes; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (cmd_level == led->modval[i].cmd_level &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) slow_level == led->modval[i].slow_level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) *mode = led->modval[i].mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) for (i = 0; i < led->num_modes; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (mode == led->modval[i].mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (i == led->num_modes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) write_lock_irqsave(&led->rw_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!led->can_sleep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) gpiod_set_value(led->cmd, led->modval[i].cmd_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) gpiod_set_value(led->slow, led->modval[i].slow_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) goto exit_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) gpiod_set_value_cansleep(led->cmd, led->modval[i].cmd_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) gpiod_set_value_cansleep(led->slow, led->modval[i].slow_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) exit_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) write_unlock_irqrestore(&led->rw_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void ns2_led_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) enum ns2_led_modes mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (value == LED_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) mode = NS_V2_LED_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) else if (led->sata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) mode = NS_V2_LED_SATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) mode = NS_V2_LED_ON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ns2_led_set_mode(led, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int ns2_led_set_blocking(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ns2_led_set(led_cdev, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static ssize_t ns2_led_sata_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) const char *buff, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct led_classdev *led_cdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned long enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ret = kstrtoul(buff, 10, &enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) enable = !!enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (led->sata == enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) led->sata = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (!led_get_brightness(led_cdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ns2_led_set_mode(led, NS_V2_LED_SATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ns2_led_set_mode(led, NS_V2_LED_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static ssize_t ns2_led_sata_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct led_classdev *led_cdev = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return sprintf(buf, "%d\n", led->sata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static struct attribute *ns2_led_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) &dev_attr_sata.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ATTRIBUTE_GROUPS(ns2_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int ns2_led_register(struct device *dev, struct fwnode_handle *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct ns2_led *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct led_init_data init_data = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct ns2_led_modval *modval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) enum ns2_led_modes mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int nmodes, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) led->cmd = devm_fwnode_gpiod_get_index(dev, node, "cmd", 0, GPIOD_ASIS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) fwnode_get_name(node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (IS_ERR(led->cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return PTR_ERR(led->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) led->slow = devm_fwnode_gpiod_get_index(dev, node, "slow", 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) GPIOD_ASIS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) fwnode_get_name(node));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (IS_ERR(led->slow))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return PTR_ERR(led->slow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ret = fwnode_property_count_u32(node, "modes-map");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (ret < 0 || ret % 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) dev_err(dev, "Missing or malformed modes-map for %pfw\n", node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) nmodes = ret / 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) modval = devm_kcalloc(dev, nmodes, sizeof(*modval), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (!modval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) fwnode_property_read_u32_array(node, "modes-map", (void *)modval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) nmodes * 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) rwlock_init(&led->rw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) led->cdev.blink_set = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) led->cdev.flags |= LED_CORE_SUSPENDRESUME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) led->cdev.groups = ns2_led_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) led->can_sleep = gpiod_cansleep(led->cmd) || gpiod_cansleep(led->slow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (led->can_sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) led->cdev.brightness_set_blocking = ns2_led_set_blocking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) led->cdev.brightness_set = ns2_led_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) led->num_modes = nmodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) led->modval = modval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ret = ns2_led_get_mode(led, &mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* Set LED initial state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) init_data.fwnode = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dev_err(dev, "Failed to register LED for node %pfw\n", node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int ns2_led_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct fwnode_handle *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct ns2_led *leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) count = device_get_child_node_count(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) leds = devm_kzalloc(dev, array_size(sizeof(*leds), count), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (!leds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) device_for_each_child_node(dev, child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ret = ns2_led_register(dev, child, leds++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) fwnode_handle_put(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static const struct of_device_id of_ns2_leds_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) { .compatible = "lacie,ns2-leds", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) MODULE_DEVICE_TABLE(of, of_ns2_leds_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static struct platform_driver ns2_led_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .probe = ns2_led_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) .name = "leds-ns2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .of_match_table = of_ns2_leds_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) module_platform_driver(ns2_led_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) MODULE_DESCRIPTION("Network Space v2 LED driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) MODULE_ALIAS("platform:leds-ns2");