| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ledtrig-gio.c - LED Trigger Based on GPIO events |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2009 Felipe Balbi <me@felipebalbi.com> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | 6 | */ |
|---|
| 10 | 7 | |
|---|
| 11 | 8 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 102 | 99 | gpio_data->inverted = inverted; |
|---|
| 103 | 100 | |
|---|
| 104 | 101 | /* After inverting, we need to update the LED. */ |
|---|
| 105 | | - gpio_trig_irq(0, led); |
|---|
| 102 | + if (gpio_is_valid(gpio_data->gpio)) |
|---|
| 103 | + gpio_trig_irq(0, led); |
|---|
| 106 | 104 | |
|---|
| 107 | 105 | return n; |
|---|
| 108 | 106 | } |
|---|
| .. | .. |
|---|
| 134 | 132 | if (gpio_data->gpio == gpio) |
|---|
| 135 | 133 | return n; |
|---|
| 136 | 134 | |
|---|
| 137 | | - if (!gpio) { |
|---|
| 138 | | - if (gpio_data->gpio != 0) |
|---|
| 135 | + if (!gpio_is_valid(gpio)) { |
|---|
| 136 | + if (gpio_is_valid(gpio_data->gpio)) |
|---|
| 139 | 137 | free_irq(gpio_to_irq(gpio_data->gpio), led); |
|---|
| 140 | | - gpio_data->gpio = 0; |
|---|
| 138 | + gpio_data->gpio = gpio; |
|---|
| 141 | 139 | return n; |
|---|
| 142 | 140 | } |
|---|
| 143 | 141 | |
|---|
| .. | .. |
|---|
| 147 | 145 | if (ret) { |
|---|
| 148 | 146 | dev_err(dev, "request_irq failed with error %d\n", ret); |
|---|
| 149 | 147 | } else { |
|---|
| 150 | | - if (gpio_data->gpio != 0) |
|---|
| 148 | + if (gpio_is_valid(gpio_data->gpio)) |
|---|
| 151 | 149 | free_irq(gpio_to_irq(gpio_data->gpio), led); |
|---|
| 152 | 150 | gpio_data->gpio = gpio; |
|---|
| 153 | 151 | /* After changing the GPIO, we need to update the LED. */ |
|---|
| .. | .. |
|---|
| 175 | 173 | return -ENOMEM; |
|---|
| 176 | 174 | |
|---|
| 177 | 175 | gpio_data->led = led; |
|---|
| 176 | + gpio_data->gpio = -ENOENT; |
|---|
| 177 | + |
|---|
| 178 | 178 | led_set_trigger_data(led, gpio_data); |
|---|
| 179 | 179 | |
|---|
| 180 | 180 | return 0; |
|---|
| .. | .. |
|---|
| 184 | 184 | { |
|---|
| 185 | 185 | struct gpio_trig_data *gpio_data = led_get_trigger_data(led); |
|---|
| 186 | 186 | |
|---|
| 187 | | - if (gpio_data->gpio != 0) |
|---|
| 187 | + if (gpio_is_valid(gpio_data->gpio)) |
|---|
| 188 | 188 | free_irq(gpio_to_irq(gpio_data->gpio), led); |
|---|
| 189 | 189 | kfree(gpio_data); |
|---|
| 190 | 190 | } |
|---|