Skip to content

Commit 2cb8126

Browse files
committed
Merge tag 'gpio-updates-for-v5.6-part1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into devel
gpio updates for v5.6 - improvements in the gpio-pca953x driver - use platform_irq_count() in gpio-mvebu and gpio-bcm-kona - remove unneeded MODULE_VERSION() usage in the gpio directory - irq-related improvements in gpio-tegra driver - several improvements for the core subsystem code: fix confusing indentation, fix int type casting, unduplicate code in several places
2 parents 227caae + 2a2cabd commit 2cb8126

File tree

9 files changed

+56
-47
lines changed

9 files changed

+56
-47
lines changed

drivers/gpio/gpio-bcm-kona.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/io.h>
2020
#include <linux/gpio/driver.h>
2121
#include <linux/of_device.h>
22-
#include <linux/of_irq.h>
2322
#include <linux/init.h>
2423
#include <linux/irqdomain.h>
2524
#include <linux/irqchip/chained_irq.h>
@@ -586,11 +585,18 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
586585

587586
kona_gpio->gpio_chip = template_chip;
588587
chip = &kona_gpio->gpio_chip;
589-
kona_gpio->num_bank = of_irq_count(dev->of_node);
590-
if (kona_gpio->num_bank == 0) {
588+
ret = platform_irq_count(pdev);
589+
if (!ret) {
591590
dev_err(dev, "Couldn't determine # GPIO banks\n");
592591
return -ENOENT;
592+
} else if (ret < 0) {
593+
if (ret != -EPROBE_DEFER)
594+
dev_err(dev, "Couldn't determine GPIO banks: (%pe)\n",
595+
ERR_PTR(ret));
596+
return ret;
593597
}
598+
kona_gpio->num_bank = ret;
599+
594600
if (kona_gpio->num_bank > GPIO_MAX_BANK_NUM) {
595601
dev_err(dev, "Too many GPIO banks configured (max=%d)\n",
596602
GPIO_MAX_BANK_NUM);

drivers/gpio/gpio-mvebu.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include <linux/irqdomain.h>
4747
#include <linux/mfd/syscon.h>
4848
#include <linux/of_device.h>
49-
#include <linux/of_irq.h>
5049
#include <linux/pinctrl/consumer.h>
5150
#include <linux/platform_device.h>
5251
#include <linux/pwm.h>
@@ -1102,7 +1101,11 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
11021101
soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
11031102

11041103
/* Some gpio controllers do not provide irq support */
1105-
have_irqs = of_irq_count(np) != 0;
1104+
err = platform_irq_count(pdev);
1105+
if (err < 0)
1106+
return err;
1107+
1108+
have_irqs = err != 0;
11061109

11071110
mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip),
11081111
GFP_KERNEL);

drivers/gpio/gpio-pca953x.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)
770770

771771
ret = devm_request_threaded_irq(&client->dev, client->irq,
772772
NULL, pca953x_irq_handler,
773-
IRQF_TRIGGER_LOW | IRQF_ONESHOT |
774-
IRQF_SHARED,
773+
IRQF_ONESHOT | IRQF_SHARED,
775774
dev_name(&client->dev), chip);
776775
if (ret) {
777776
dev_err(&client->dev, "failed to request irq %d\n",
@@ -861,8 +860,6 @@ static int device_pca957x_init(struct pca953x_chip *chip, u32 invert)
861860
return ret;
862861
}
863862

864-
static const struct of_device_id pca953x_dt_ids[];
865-
866863
static int pca953x_probe(struct i2c_client *client,
867864
const struct i2c_device_id *i2c_id)
868865
{

drivers/gpio/gpio-sama5d2-piobu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ static struct platform_driver sama5d2_piobu_driver = {
244244

245245
module_platform_driver(sama5d2_piobu_driver);
246246

247-
MODULE_VERSION("1.0");
248247
MODULE_LICENSE("GPL v2");
249248
MODULE_DESCRIPTION("SAMA5D2 PIOBU controller driver");
250249
MODULE_AUTHOR("Andrei Stefanescu <[email protected]>");

drivers/gpio/gpio-tb10x.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,3 @@ static struct platform_driver tb10x_gpio_driver = {
243243
module_platform_driver(tb10x_gpio_driver);
244244
MODULE_LICENSE("GPL");
245245
MODULE_DESCRIPTION("tb10x gpio.");
246-
MODULE_VERSION("0.0.1");

drivers/gpio/gpio-tegra.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ struct tegra_gpio_info {
9696
static inline void tegra_gpio_writel(struct tegra_gpio_info *tgi,
9797
u32 val, u32 reg)
9898
{
99-
__raw_writel(val, tgi->regs + reg);
99+
writel_relaxed(val, tgi->regs + reg);
100100
}
101101

102102
static inline u32 tegra_gpio_readl(struct tegra_gpio_info *tgi, u32 reg)
103103
{
104-
return __raw_readl(tgi->regs + reg);
104+
return readl_relaxed(tgi->regs + reg);
105105
}
106106

107107
static unsigned int tegra_gpio_compose(unsigned int bank, unsigned int port,
@@ -416,11 +416,8 @@ static void tegra_gpio_irq_handler(struct irq_desc *desc)
416416
static int tegra_gpio_resume(struct device *dev)
417417
{
418418
struct tegra_gpio_info *tgi = dev_get_drvdata(dev);
419-
unsigned long flags;
420419
unsigned int b, p;
421420

422-
local_irq_save(flags);
423-
424421
for (b = 0; b < tgi->bank_count; b++) {
425422
struct tegra_gpio_bank *bank = &tgi->bank_info[b];
426423

@@ -448,17 +445,14 @@ static int tegra_gpio_resume(struct device *dev)
448445
}
449446
}
450447

451-
local_irq_restore(flags);
452448
return 0;
453449
}
454450

455451
static int tegra_gpio_suspend(struct device *dev)
456452
{
457453
struct tegra_gpio_info *tgi = dev_get_drvdata(dev);
458-
unsigned long flags;
459454
unsigned int b, p;
460455

461-
local_irq_save(flags);
462456
for (b = 0; b < tgi->bank_count; b++) {
463457
struct tegra_gpio_bank *bank = &tgi->bank_info[b];
464458

@@ -488,7 +482,7 @@ static int tegra_gpio_suspend(struct device *dev)
488482
GPIO_INT_ENB(tgi, gpio));
489483
}
490484
}
491-
local_irq_restore(flags);
485+
492486
return 0;
493487
}
494488

@@ -497,6 +491,11 @@ static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable)
497491
struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
498492
unsigned int gpio = d->hwirq;
499493
u32 port, bit, mask;
494+
int err;
495+
496+
err = irq_set_irq_wake(bank->irq, enable);
497+
if (err)
498+
return err;
500499

501500
port = GPIO_PORT(gpio);
502501
bit = GPIO_BIT(gpio);
@@ -507,7 +506,7 @@ static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable)
507506
else
508507
bank->wake_enb[port] &= ~mask;
509508

510-
return irq_set_irq_wake(bank->irq, enable);
509+
return 0;
511510
}
512511
#endif
513512

@@ -557,7 +556,7 @@ static inline void tegra_gpio_debuginit(struct tegra_gpio_info *tgi)
557556
#endif
558557

559558
static const struct dev_pm_ops tegra_gpio_pm_ops = {
560-
SET_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume)
559+
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume)
561560
};
562561

563562
static int tegra_gpio_probe(struct platform_device *pdev)

drivers/gpio/gpiolib.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ EXPORT_SYMBOL_GPL(gpio_to_desc);
140140
* in the given chip for the specified hardware number.
141141
*/
142142
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip,
143-
u16 hwnum)
143+
unsigned int hwnum)
144144
{
145145
struct gpio_device *gdev = chip->gpiodev;
146146

@@ -669,14 +669,13 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
669669
/* Request each GPIO */
670670
for (i = 0; i < handlereq.lines; i++) {
671671
u32 offset = handlereq.lineoffsets[i];
672-
struct gpio_desc *desc;
672+
struct gpio_desc *desc = gpiochip_get_desc(gdev->chip, offset);
673673

674-
if (offset >= gdev->ngpio) {
675-
ret = -EINVAL;
674+
if (IS_ERR(desc)) {
675+
ret = PTR_ERR(desc);
676676
goto out_free_descs;
677677
}
678678

679-
desc = &gdev->descs[offset];
680679
ret = gpiod_request(desc, lh->label);
681680
if (ret)
682681
goto out_free_descs;
@@ -1001,8 +1000,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
10011000
lflags = eventreq.handleflags;
10021001
eflags = eventreq.eventflags;
10031002

1004-
if (offset >= gdev->ngpio)
1005-
return -EINVAL;
1003+
desc = gpiochip_get_desc(gdev->chip, offset);
1004+
if (IS_ERR(desc))
1005+
return PTR_ERR(desc);
10061006

10071007
/* Return an error if a unknown flag is set */
10081008
if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
@@ -1040,7 +1040,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
10401040
}
10411041
}
10421042

1043-
desc = &gdev->descs[offset];
10441043
ret = gpiod_request(desc, le->label);
10451044
if (ret)
10461045
goto out_free_label;
@@ -1167,10 +1166,11 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
11671166

11681167
if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
11691168
return -EFAULT;
1170-
if (lineinfo.line_offset >= gdev->ngpio)
1171-
return -EINVAL;
11721169

1173-
desc = &gdev->descs[lineinfo.line_offset];
1170+
desc = gpiochip_get_desc(chip, lineinfo.line_offset);
1171+
if (IS_ERR(desc))
1172+
return PTR_ERR(desc);
1173+
11741174
if (desc->name) {
11751175
strncpy(lineinfo.name, desc->name,
11761176
sizeof(lineinfo.name));
@@ -1435,7 +1435,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
14351435

14361436
if (chip->ngpio > FASTPATH_NGPIO)
14371437
chip_warn(chip, "line cnt %u is greater than fast path cnt %u\n",
1438-
chip->ngpio, FASTPATH_NGPIO);
1438+
chip->ngpio, FASTPATH_NGPIO);
14391439

14401440
gdev->label = kstrdup_const(chip->label ?: "unknown", GFP_KERNEL);
14411441
if (!gdev->label) {
@@ -2977,7 +2977,8 @@ EXPORT_SYMBOL_GPL(gpiochip_is_requested);
29772977
* A pointer to the GPIO descriptor, or an ERR_PTR()-encoded negative error
29782978
* code on failure.
29792979
*/
2980-
struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
2980+
struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip,
2981+
unsigned int hwnum,
29812982
const char *label,
29822983
enum gpio_lookup_flags lflags,
29832984
enum gpiod_flags dflags)
@@ -3029,7 +3030,16 @@ EXPORT_SYMBOL_GPL(gpiochip_free_own_desc);
30293030
* rely on gpio_request() having been called beforehand.
30303031
*/
30313032

3032-
static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
3033+
static int gpio_do_set_config(struct gpio_chip *gc, unsigned int offset,
3034+
enum pin_config_param mode)
3035+
{
3036+
if (!gc->set_config)
3037+
return -ENOTSUPP;
3038+
3039+
return gc->set_config(gc, offset, mode);
3040+
}
3041+
3042+
static int gpio_set_config(struct gpio_chip *gc, unsigned int offset,
30333043
enum pin_config_param mode)
30343044
{
30353045
unsigned long config;
@@ -3047,7 +3057,7 @@ static int gpio_set_config(struct gpio_chip *gc, unsigned offset,
30473057
}
30483058

30493059
config = PIN_CONF_PACKED(mode, arg);
3050-
return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP;
3060+
return gpio_do_set_config(gc, offset, mode);
30513061
}
30523062

30533063
static int gpio_set_bias(struct gpio_chip *chip, struct gpio_desc *desc)
@@ -3281,15 +3291,9 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
32813291

32823292
VALIDATE_DESC(desc);
32833293
chip = desc->gdev->chip;
3284-
if (!chip->set || !chip->set_config) {
3285-
gpiod_dbg(desc,
3286-
"%s: missing set() or set_config() operations\n",
3287-
__func__);
3288-
return -ENOTSUPP;
3289-
}
32903294

32913295
config = pinconf_to_config_packed(PIN_CONFIG_INPUT_DEBOUNCE, debounce);
3292-
return chip->set_config(chip, gpio_chip_hwgpio(desc), config);
3296+
return gpio_do_set_config(chip, gpio_chip_hwgpio(desc), config);
32933297
}
32943298
EXPORT_SYMBOL_GPL(gpiod_set_debounce);
32953299

@@ -3323,7 +3327,7 @@ int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
33233327
packed = pinconf_to_config_packed(PIN_CONFIG_PERSIST_STATE,
33243328
!transitory);
33253329
gpio = gpio_chip_hwgpio(desc);
3326-
rc = chip->set_config(chip, gpio, packed);
3330+
rc = gpio_do_set_config(chip, gpio, packed);
33273331
if (rc == -ENOTSUPP) {
33283332
dev_dbg(&desc->gdev->dev, "Persistence not supported for GPIO %d\n",
33293333
gpio);

drivers/gpio/gpiolib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ struct gpio_array {
8080
unsigned long invert_mask[];
8181
};
8282

83-
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip, u16 hwnum);
83+
struct gpio_desc *gpiochip_get_desc(struct gpio_chip *chip,
84+
unsigned int hwnum);
8485
int gpiod_get_array_value_complex(bool raw, bool can_sleep,
8586
unsigned int array_size,
8687
struct gpio_desc **desc_array,

include/linux/gpio/driver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip)
715715

716716
#endif /* CONFIG_PINCTRL */
717717

718-
struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
718+
struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip,
719+
unsigned int hwnum,
719720
const char *label,
720721
enum gpio_lookup_flags lflags,
721722
enum gpiod_flags dflags);

0 commit comments

Comments
 (0)