.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2016, BayLibre, SAS. All rights reserved. |
---|
3 | 4 | * Author: Neil Armstrong <narmstrong@baylibre.com> |
---|
.. | .. |
---|
8 | 9 | * The handling of the 4-bit chips (SX1501/SX1504/SX1507) is untested. |
---|
9 | 10 | * |
---|
10 | 11 | * Author: Gregory Bean <gbean@codeaurora.org> |
---|
11 | | - * |
---|
12 | | - * This program is free software; you can redistribute it and/or modify |
---|
13 | | - * it under the terms of the GNU General Public License version 2 and |
---|
14 | | - * only version 2 as published by the Free Software Foundation. |
---|
15 | | - * |
---|
16 | | - * This program is distributed in the hope that it will be useful, |
---|
17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | | - * GNU General Public License for more details. |
---|
20 | 12 | */ |
---|
21 | 13 | |
---|
22 | 14 | #include <linux/regmap.h> |
---|
.. | .. |
---|
399 | 391 | int ret; |
---|
400 | 392 | |
---|
401 | 393 | if (sx150x_pin_is_oscio(pctl, offset)) |
---|
402 | | - return false; |
---|
| 394 | + return GPIO_LINE_DIRECTION_OUT; |
---|
403 | 395 | |
---|
404 | 396 | ret = regmap_read(pctl->regmap, pctl->data->reg_dir, &value); |
---|
405 | 397 | if (ret < 0) |
---|
406 | 398 | return ret; |
---|
407 | 399 | |
---|
408 | | - return !!(value & BIT(offset)); |
---|
| 400 | + if (value & BIT(offset)) |
---|
| 401 | + return GPIO_LINE_DIRECTION_IN; |
---|
| 402 | + |
---|
| 403 | + return GPIO_LINE_DIRECTION_OUT; |
---|
409 | 404 | } |
---|
410 | 405 | |
---|
411 | 406 | static int sx150x_gpio_get(struct gpio_chip *chip, unsigned int offset) |
---|
.. | .. |
---|
448 | 443 | sx150x_gpio_oscio_set(pctl, value); |
---|
449 | 444 | else |
---|
450 | 445 | __sx150x_gpio_set(pctl, offset, value); |
---|
451 | | - |
---|
452 | 446 | } |
---|
453 | 447 | |
---|
454 | 448 | static void sx150x_gpio_set_multiple(struct gpio_chip *chip, |
---|
.. | .. |
---|
695 | 689 | if (ret < 0) |
---|
696 | 690 | return ret; |
---|
697 | 691 | |
---|
698 | | - if (ret) |
---|
| 692 | + if (ret == GPIO_LINE_DIRECTION_IN) |
---|
699 | 693 | return -EINVAL; |
---|
700 | 694 | |
---|
701 | 695 | ret = sx150x_gpio_get(&pctl->gpio, pin); |
---|
.. | .. |
---|
993 | 987 | /* |
---|
994 | 988 | * In order to mask the differences between 16 and 8 bit expander |
---|
995 | 989 | * devices we set up a sligthly ficticious regmap that pretends to be |
---|
996 | | - * a set of 32-bit (to accomodate RegSenseLow/RegSenseHigh |
---|
| 990 | + * a set of 32-bit (to accommodate RegSenseLow/RegSenseHigh |
---|
997 | 991 | * pair/quartet) registers and transparently reconstructs those |
---|
998 | 992 | * registers via multiple I2C/SMBus reads |
---|
999 | 993 | * |
---|
.. | .. |
---|
1159 | 1153 | return ret; |
---|
1160 | 1154 | } |
---|
1161 | 1155 | |
---|
1162 | | - ret = pinctrl_enable(pctl->pctldev); |
---|
1163 | | - if (ret) { |
---|
1164 | | - dev_err(dev, "Failed to enable pinctrl device\n"); |
---|
1165 | | - return ret; |
---|
1166 | | - } |
---|
1167 | | - |
---|
1168 | 1156 | /* Register GPIO controller */ |
---|
1169 | 1157 | pctl->gpio.base = -1; |
---|
1170 | 1158 | pctl->gpio.ngpio = pctl->data->npins; |
---|
.. | .. |
---|
1192 | 1180 | if (pctl->data->model != SX150X_789) |
---|
1193 | 1181 | pctl->gpio.set_multiple = sx150x_gpio_set_multiple; |
---|
1194 | 1182 | |
---|
1195 | | - ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl); |
---|
1196 | | - if (ret) |
---|
1197 | | - return ret; |
---|
1198 | | - |
---|
1199 | | - ret = gpiochip_add_pin_range(&pctl->gpio, dev_name(dev), |
---|
1200 | | - 0, 0, pctl->data->npins); |
---|
1201 | | - if (ret) |
---|
1202 | | - return ret; |
---|
1203 | | - |
---|
1204 | 1183 | /* Add Interrupt support if an irq is specified */ |
---|
1205 | 1184 | if (client->irq > 0) { |
---|
| 1185 | + struct gpio_irq_chip *girq; |
---|
| 1186 | + |
---|
1206 | 1187 | pctl->irq_chip.irq_mask = sx150x_irq_mask; |
---|
1207 | 1188 | pctl->irq_chip.irq_unmask = sx150x_irq_unmask; |
---|
1208 | 1189 | pctl->irq_chip.irq_set_type = sx150x_irq_set_type; |
---|
.. | .. |
---|
1218 | 1199 | |
---|
1219 | 1200 | /* |
---|
1220 | 1201 | * Because sx150x_irq_threaded_fn invokes all of the |
---|
1221 | | - * nested interrrupt handlers via handle_nested_irq, |
---|
1222 | | - * any "handler" passed to gpiochip_irqchip_add() |
---|
| 1202 | + * nested interrupt handlers via handle_nested_irq, |
---|
| 1203 | + * any "handler" assigned to struct gpio_irq_chip |
---|
1223 | 1204 | * below is going to be ignored, so the choice of the |
---|
1224 | 1205 | * function does not matter that much. |
---|
1225 | 1206 | * |
---|
.. | .. |
---|
1227 | 1208 | * plus it will be instantly noticeable if it is ever |
---|
1228 | 1209 | * called (should not happen) |
---|
1229 | 1210 | */ |
---|
1230 | | - ret = gpiochip_irqchip_add_nested(&pctl->gpio, |
---|
1231 | | - &pctl->irq_chip, 0, |
---|
1232 | | - handle_bad_irq, IRQ_TYPE_NONE); |
---|
1233 | | - if (ret) { |
---|
1234 | | - dev_err(dev, "could not connect irqchip to gpiochip\n"); |
---|
1235 | | - return ret; |
---|
1236 | | - } |
---|
| 1211 | + girq = &pctl->gpio.irq; |
---|
| 1212 | + girq->chip = &pctl->irq_chip; |
---|
| 1213 | + /* This will let us handle the parent IRQ in the driver */ |
---|
| 1214 | + girq->parent_handler = NULL; |
---|
| 1215 | + girq->num_parents = 0; |
---|
| 1216 | + girq->parents = NULL; |
---|
| 1217 | + girq->default_type = IRQ_TYPE_NONE; |
---|
| 1218 | + girq->handler = handle_bad_irq; |
---|
| 1219 | + girq->threaded = true; |
---|
1237 | 1220 | |
---|
1238 | 1221 | ret = devm_request_threaded_irq(dev, client->irq, NULL, |
---|
1239 | 1222 | sx150x_irq_thread_fn, |
---|
.. | .. |
---|
1242 | 1225 | pctl->irq_chip.name, pctl); |
---|
1243 | 1226 | if (ret < 0) |
---|
1244 | 1227 | return ret; |
---|
1245 | | - |
---|
1246 | | - gpiochip_set_nested_irqchip(&pctl->gpio, |
---|
1247 | | - &pctl->irq_chip, |
---|
1248 | | - client->irq); |
---|
1249 | 1228 | } |
---|
1250 | 1229 | |
---|
| 1230 | + ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl); |
---|
| 1231 | + if (ret) |
---|
| 1232 | + return ret; |
---|
| 1233 | + |
---|
| 1234 | + /* |
---|
| 1235 | + * Pin control functions need to be enabled AFTER registering the |
---|
| 1236 | + * GPIO chip because sx150x_pinconf_set() calls |
---|
| 1237 | + * sx150x_gpio_direction_output(). |
---|
| 1238 | + */ |
---|
| 1239 | + ret = pinctrl_enable(pctl->pctldev); |
---|
| 1240 | + if (ret) { |
---|
| 1241 | + dev_err(dev, "Failed to enable pinctrl device\n"); |
---|
| 1242 | + return ret; |
---|
| 1243 | + } |
---|
| 1244 | + |
---|
| 1245 | + ret = gpiochip_add_pin_range(&pctl->gpio, dev_name(dev), |
---|
| 1246 | + 0, 0, pctl->data->npins); |
---|
| 1247 | + if (ret) |
---|
| 1248 | + return ret; |
---|
| 1249 | + |
---|
1251 | 1250 | return 0; |
---|
1252 | 1251 | } |
---|
1253 | 1252 | |
---|