Lines Matching +full:led +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
3 * LED driver for WM831x status LEDs
38 static void wm831x_status_set(struct wm831x_status *led) in wm831x_status_set() argument
42 mutex_lock(&led->mutex); in wm831x_status_set()
44 led->reg_val &= ~(WM831X_LED_SRC_MASK | WM831X_LED_MODE_MASK | in wm831x_status_set()
47 spin_lock_irqsave(&led->value_lock, flags); in wm831x_status_set()
49 led->reg_val |= led->src << WM831X_LED_SRC_SHIFT; in wm831x_status_set()
50 if (led->blink) { in wm831x_status_set()
51 led->reg_val |= 2 << WM831X_LED_MODE_SHIFT; in wm831x_status_set()
52 led->reg_val |= led->blink_time << WM831X_LED_DUR_SHIFT; in wm831x_status_set()
53 led->reg_val |= led->blink_cyc; in wm831x_status_set()
55 if (led->brightness != LED_OFF) in wm831x_status_set()
56 led->reg_val |= 1 << WM831X_LED_MODE_SHIFT; in wm831x_status_set()
59 spin_unlock_irqrestore(&led->value_lock, flags); in wm831x_status_set()
61 wm831x_reg_write(led->wm831x, led->reg, led->reg_val); in wm831x_status_set()
63 mutex_unlock(&led->mutex); in wm831x_status_set()
69 struct wm831x_status *led = to_wm831x_status(led_cdev); in wm831x_status_brightness_set() local
72 spin_lock_irqsave(&led->value_lock, flags); in wm831x_status_brightness_set()
73 led->brightness = value; in wm831x_status_brightness_set()
75 led->blink = 0; in wm831x_status_brightness_set()
76 spin_unlock_irqrestore(&led->value_lock, flags); in wm831x_status_brightness_set()
77 wm831x_status_set(led); in wm831x_status_brightness_set()
86 struct wm831x_status *led = to_wm831x_status(led_cdev); in wm831x_status_blink_set() local
96 spin_lock_irqsave(&led->value_lock, flags); in wm831x_status_blink_set()
102 led->blink_time = 0; in wm831x_status_blink_set()
105 led->blink_time = 1; in wm831x_status_blink_set()
108 led->blink_time = 2; in wm831x_status_blink_set()
113 led->blink_time = 3; in wm831x_status_blink_set()
116 ret = -EINVAL; in wm831x_status_blink_set()
123 led->blink_cyc = 0; in wm831x_status_blink_set()
126 led->blink_cyc = 1; in wm831x_status_blink_set()
129 led->blink_cyc = 2; in wm831x_status_blink_set()
132 led->blink_cyc = 3; in wm831x_status_blink_set()
135 ret = -EINVAL; in wm831x_status_blink_set()
141 led->blink = 1; in wm831x_status_blink_set()
143 led->blink = 0; in wm831x_status_blink_set()
145 spin_unlock_irqrestore(&led->value_lock, flags); in wm831x_status_blink_set()
146 wm831x_status_set(led); in wm831x_status_blink_set()
162 struct wm831x_status *led = to_wm831x_status(led_cdev); in wm831x_status_src_show() local
166 mutex_lock(&led->mutex); in wm831x_status_src_show()
169 if (i == led->src) in wm831x_status_src_show()
174 mutex_unlock(&led->mutex); in wm831x_status_src_show()
186 struct wm831x_status *led = to_wm831x_status(led_cdev); in wm831x_status_src_store() local
191 mutex_lock(&led->mutex); in wm831x_status_src_store()
192 led->src = i; in wm831x_status_src_store()
193 mutex_unlock(&led->mutex); in wm831x_status_src_store()
194 wm831x_status_set(led); in wm831x_status_src_store()
210 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); in wm831x_status_probe()
215 int id = pdev->id % ARRAY_SIZE(chip_pdata->status); in wm831x_status_probe()
220 dev_err(&pdev->dev, "No register resource\n"); in wm831x_status_probe()
221 return -EINVAL; in wm831x_status_probe()
224 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_status), in wm831x_status_probe()
227 return -ENOMEM; in wm831x_status_probe()
229 drvdata->wm831x = wm831x; in wm831x_status_probe()
230 drvdata->reg = res->start; in wm831x_status_probe()
232 if (dev_get_platdata(wm831x->dev)) in wm831x_status_probe()
233 chip_pdata = dev_get_platdata(wm831x->dev); in wm831x_status_probe()
238 if (chip_pdata && chip_pdata->status[id]) in wm831x_status_probe()
239 memcpy(&pdata, chip_pdata->status[id], sizeof(pdata)); in wm831x_status_probe()
241 pdata.name = dev_name(&pdev->dev); in wm831x_status_probe()
243 mutex_init(&drvdata->mutex); in wm831x_status_probe()
244 spin_lock_init(&drvdata->value_lock); in wm831x_status_probe()
248 drvdata->reg_val = wm831x_reg_read(wm831x, drvdata->reg); in wm831x_status_probe()
250 if (drvdata->reg_val & WM831X_LED_MODE_MASK) in wm831x_status_probe()
251 drvdata->brightness = LED_FULL; in wm831x_status_probe()
253 drvdata->brightness = LED_OFF; in wm831x_status_probe()
259 drvdata->src = drvdata->reg_val; in wm831x_status_probe()
260 drvdata->src &= WM831X_LED_SRC_MASK; in wm831x_status_probe()
261 drvdata->src >>= WM831X_LED_SRC_SHIFT; in wm831x_status_probe()
263 drvdata->src = pdata.default_src - 1; in wm831x_status_probe()
266 drvdata->cdev.name = pdata.name; in wm831x_status_probe()
267 drvdata->cdev.default_trigger = pdata.default_trigger; in wm831x_status_probe()
268 drvdata->cdev.brightness_set_blocking = wm831x_status_brightness_set; in wm831x_status_probe()
269 drvdata->cdev.blink_set = wm831x_status_blink_set; in wm831x_status_probe()
270 drvdata->cdev.groups = wm831x_status_groups; in wm831x_status_probe()
272 ret = led_classdev_register(wm831x->dev, &drvdata->cdev); in wm831x_status_probe()
274 dev_err(&pdev->dev, "Failed to register LED: %d\n", ret); in wm831x_status_probe()
287 led_classdev_unregister(&drvdata->cdev); in wm831x_status_remove()
294 .name = "wm831x-status",
303 MODULE_DESCRIPTION("WM831x status LED driver");
305 MODULE_ALIAS("platform:wm831x-status");