gpio: tegra: Remove unnecessary check
Subsystems (2)
PATCH 1/4 gpio: tegra: Remove unnecessary check
From: Thierry Reding <[email protected]>
of_device_get_match_data() can never return NULL, therefore the check for NULL values is unnecessary.
--- drivers/gpio/gpio-tegra.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpio/gpio-tegra.c +2 -9
@@ -566,7 +566,6 @@ static struct lock_class_key gpio_lock_class;static int tegra_gpio_probe (struct platform_device *pdev) { -const struct tegra_gpio_soc_config *config;struct tegra_gpio_info *tgi;struct resource *res;struct tegra_gpio_bank *bank;
@@ -575,17 +574,11 @@ static int tegra_gpio_probe(struct platform_device *pdev)int i;int j; - config =of_device_get_match_data (&pdev->dev); -if (!config) { -dev_err (&pdev->dev,"Error: No device match found\n" ); -return -ENODEV ; - } - tgi =devm_kzalloc (&pdev->dev,sizeof (*tgi),GFP_KERNEL );if (!tgi)return -ENODEV ; - tgi->soc = config; + tgi->soc =of_device_get_match_data (&pdev->dev); tgi->dev = &pdev->dev; ret =platform_irq_count (pdev);
@@ -625,7 +618,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)platform_set_drvdata (pdev, tgi); -if (config->debounce_supported) +if (tgi->soc->debounce_supported) tgi->gc.set_config = tegra_gpio_set_config; tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count *
Signature · 1 line
2.13.3
PATCH 2/4 gpio: tegra: Prefer kcalloc() over kzalloc() with multiplies
From: Thierry Reding <[email protected]>
Rather than manually compute the size of an array, pass the number and element size to kcalloc().
--- drivers/gpio/gpio-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-tegra.c +2 -2
@@ -621,10 +621,10 @@ static int tegra_gpio_probe(struct platform_device *pdev)if (tgi->soc->debounce_supported) tgi->gc.set_config = tegra_gpio_set_config; - tgi->bank_info =devm_kzalloc (&pdev->dev, tgi->bank_count * + tgi->bank_info =devm_kcalloc (&pdev->dev, tgi->bank_count,sizeof (*tgi->bank_info),GFP_KERNEL );if (!tgi->bank_info) -return -ENODEV ; +return -ENOMEM ; tgi->irq_domain = irq_domain_add_linear(pdev->dev.of_node, tgi->gc.ngpio,
Signature · 1 line
2.13.3
Re: [PATCH 2/4] gpio: tegra: Prefer kcalloc() over kzalloc() with multiplies
Quoted 18 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Rather than manually compute the size of an array, pass the number and element size to
kcalloc().Signed-off-by Thierry Reding <[email protected]>--- drivers/gpio/gpio-tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpio/gpio-tegra.c +0
-0@@ -621,10 +621,10 @@ static int tegra_gpio_probe(struct platform_device *pdev)if (tgi->soc->debounce_supported) tgi->gc.set_config = tegra_gpio_set_config;
drivers/gpio/gpio-tegra.c static int tegra_gpio_probe(struct platform_device *pdev) · line 630
Quoted 10 lines
drivers/gpio/gpio-tegra.c +2
-2- tgi->bank_info =devm_kzalloc (&pdev->dev, tgi->bank_count * + tgi->bank_info =devm_kcalloc (&pdev->dev, tgi->bank_count,sizeof (*tgi->bank_info),GFP_KERNEL );if (!tgi->bank_info) -return -ENODEV ; +return -ENOMEM ; tgi->irq_domain = irq_domain_add_linear(pdev->dev.of_node, tgi->gc.ngpio,
Cheers
Jon
Signature · 1 line
nvpublic
Re: [PATCH 2/4] gpio: tegra: Prefer kcalloc() over kzalloc() with multiplies
In reply to Thierry RedingQuoted 6 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Rather than manually compute the size of an array, pass the number and element size to
kcalloc().Signed-off-by Thierry Reding <[email protected]>
Patch applied with Jon's ACK.
Yours,
Linus Walleij
PATCH 3/4 gpio: tegra: Fix checkpatch warnings
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
Fix a couple of checkpatch warnings, such as complaints about bare unsigned being used (instead of unsigned int) and missing blank lines after declarations.
--- drivers/gpio/gpio-tegra.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
drivers/gpio/gpio-tegra.c +20 -12
@@ -138,12 +138,12 @@ static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio)tegra_gpio_mask_write (tgi,GPIO_MSK_CNF (tgi, gpio), gpio,0 ); } -static int tegra_gpio_request (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_request (struct gpio_chip *chip,unsigned int offset) {return pinctrl_request_gpio (offset); } -static void tegra_gpio_free (struct gpio_chip *chip,unsigned offset) +static void tegra_gpio_free (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);
@@ -151,14 +151,15 @@ static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset)tegra_gpio_disable (tgi, offset); } -static void tegra_gpio_set (struct gpio_chip *chip,unsigned offset,int value) +static void tegra_gpio_set (struct gpio_chip *chip,unsigned int offset, +int value) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);tegra_gpio_mask_write (tgi,GPIO_MSK_OUT (tgi, offset), offset, value); } -static int tegra_gpio_get (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_get (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);int bval =BIT (GPIO_BIT (offset));
@@ -170,7 +171,8 @@ static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)return !!(tegra_gpio_readl (tgi,GPIO_IN (tgi, offset)) & bval); } -static int tegra_gpio_direction_input (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_direction_input (struct gpio_chip *chip, +unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);
@@ -179,8 +181,9 @@ static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset)return 0 ; } -static int tegra_gpio_direction_output (struct gpio_chip *chip,unsigned offset, -int value) +static int tegra_gpio_direction_output (struct gpio_chip *chip, +unsigned int offset, +int value) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);
@@ -190,7 +193,8 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,return 0 ; } -static int tegra_gpio_get_direction (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_get_direction (struct gpio_chip *chip, +unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);u32 pin_mask =BIT (GPIO_BIT (offset));
@@ -250,7 +254,7 @@ static int tegra_gpio_set_config(struct gpio_chip *chip, unsigned int offset,return tegra_gpio_set_debounce (chip, offset, debounce); } -static int tegra_gpio_to_irq (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_to_irq (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);
@@ -413,7 +417,8 @@ static int tegra_gpio_resume(struct device *dev)struct tegra_gpio_bank *bank = &tgi->bank_info[b];for (p =0 ; p <ARRAY_SIZE (bank->oe); p++) { -unsigned int gpio = (b<<5 ) | (p<<3 ); +unsigned int gpio = (b <<5 ) | (p <<3 ); +tegra_gpio_writel (tgi, bank->cnf[p],GPIO_CNF (tgi, gpio));
@@ -452,7 +457,8 @@ static int tegra_gpio_suspend(struct device *dev)struct tegra_gpio_bank *bank = &tgi->bank_info[b];for (p =0 ; p <ARRAY_SIZE (bank->oe); p++) { -unsigned int gpio = (b<<5 ) | (p<<3 ); +unsigned int gpio = (b <<5 ) | (p <<3 ); + bank->cnf[p] =tegra_gpio_readl (tgi,GPIO_CNF (tgi, gpio)); bank->out[p] = tegra_gpio_readl(tgi,
@@ -513,6 +519,7 @@ static int dbg_gpio_show(struct seq_file *s, void *unused)for (i =0 ; i < tgi->bank_count; i++) {for (j =0 ; j <4 ; j++) {int gpio =tegra_gpio_compose (i, j,0 ); + seq_printf(s, "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", i, j,
@@ -542,7 +549,7 @@ static const struct file_operations debug_fops = {static void tegra_gpio_debuginit (struct tegra_gpio_info *tgi) { - (void )debugfs_create_file ("tegra_gpio" ,S_IRUGO , + (void )debugfs_create_file ("tegra_gpio" ,0444 ,NULL , tgi, &debug_fops); }
@@ -653,6 +660,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)for (i =0 ; i < tgi->bank_count; i++) {for (j =0 ; j <4 ; j++) {int gpio =tegra_gpio_compose (i, j,0 ); +tegra_gpio_writel (tgi,0x00 ,GPIO_INT_ENB (tgi, gpio)); } }
Signature · 1 line
2.13.3
Re: [PATCH 3/4] gpio: tegra: Fix checkpatch warnings
Quoted 128 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Fix a couple of checkpatch warnings, such as complaints about bare unsigned being used (instead of unsigned int) and missing blank lines after declarations.
Signed-off-by Thierry Reding <[email protected]>--- drivers/gpio/gpio-tegra.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)drivers/gpio/gpio-tegra.c +19
-12@@ -138,12 +138,12 @@ static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio)tegra_gpio_mask_write (tgi,GPIO_MSK_CNF (tgi, gpio), gpio,0 ); } -static int tegra_gpio_request (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_request (struct gpio_chip *chip,unsigned int offset) {return pinctrl_request_gpio (offset); } -static void tegra_gpio_free (struct gpio_chip *chip,unsigned offset) +static void tegra_gpio_free (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);@@ -151,14 +151,15 @@ static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset)tegra_gpio_disable (tgi, offset); } -static void tegra_gpio_set (struct gpio_chip *chip,unsigned offset,int value) +static void tegra_gpio_set (struct gpio_chip *chip,unsigned int offset, +int value) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);tegra_gpio_mask_write (tgi,GPIO_MSK_OUT (tgi, offset), offset, value); } -static int tegra_gpio_get (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_get (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);int bval =BIT (GPIO_BIT (offset));@@ -170,7 +171,8 @@ static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)return !!(tegra_gpio_readl (tgi,GPIO_IN (tgi, offset)) & bval); } -static int tegra_gpio_direction_input (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_direction_input (struct gpio_chip *chip, +unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);@@ -179,8 +181,9 @@ static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset)return 0 ; } -static int tegra_gpio_direction_output (struct gpio_chip *chip,unsigned offset, -int value) +static int tegra_gpio_direction_output (struct gpio_chip *chip, +unsigned int offset, +int value) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);@@ -190,7 +193,8 @@ static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,return 0 ; } -static int tegra_gpio_get_direction (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_get_direction (struct gpio_chip *chip, +unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);u32 pin_mask =BIT (GPIO_BIT (offset));@@ -250,7 +254,7 @@ static int tegra_gpio_set_config(struct gpio_chip *chip, unsigned int offset,return tegra_gpio_set_debounce (chip, offset, debounce); } -static int tegra_gpio_to_irq (struct gpio_chip *chip,unsigned offset) +static int tegra_gpio_to_irq (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip);@@ -413,7 +417,8 @@ static int tegra_gpio_resume(struct device *dev)struct tegra_gpio_bank *bank = &tgi->bank_info[b];for (p =0 ; p <ARRAY_SIZE (bank->oe); p++) { -unsigned int gpio = (b<<5 ) | (p<<3 ); +unsigned int gpio = (b <<5 ) | (p <<3 ); +tegra_gpio_writel (tgi, bank->cnf[p],GPIO_CNF (tgi, gpio));@@ -452,7 +457,8 @@ static int tegra_gpio_suspend(struct device *dev)struct tegra_gpio_bank *bank = &tgi->bank_info[b];for (p =0 ; p <ARRAY_SIZE (bank->oe); p++) { -unsigned int gpio = (b<<5 ) | (p<<3 ); +unsigned int gpio = (b <<5 ) | (p <<3 ); + bank->cnf[p] =tegra_gpio_readl (tgi,GPIO_CNF (tgi, gpio)); bank->out[p] = tegra_gpio_readl(tgi,@@ -513,6 +519,7 @@ static int dbg_gpio_show(struct seq_file *s, void *unused)for (i =0 ; i < tgi->bank_count; i++) {for (j =0 ; j <4 ; j++) {int gpio =tegra_gpio_compose (i, j,0 ); + seq_printf(s, "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", i, j,@@ -542,7 +549,7 @@ static const struct file_operations debug_fops = {static void tegra_gpio_debuginit (struct tegra_gpio_info *tgi) { - (void )debugfs_create_file ("tegra_gpio" ,S_IRUGO , + (void )debugfs_create_file ("tegra_gpio" ,0444 ,NULL , tgi, &debug_fops); }
drivers/gpio/gpio-tegra.c static int tegra_gpio_probe(struct platform_device *pdev) · line 666
Quoted 7 lines
drivers/gpio/gpio-tegra.c +1
-0@@ -653,6 +660,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)for (i =0 ; i < tgi->bank_count; i++) {for (j =0 ; j <4 ; j++) {int gpio =tegra_gpio_compose (i, j,0 ); +tegra_gpio_writel (tgi,0x00 ,GPIO_INT_ENB (tgi, gpio)); } }
Cheers
Jon
Signature · 1 line
nvpublic
Re: [PATCH 3/4] gpio: tegra: Fix checkpatch warnings
In reply to Thierry RedingQuoted 7 lines · Thierry Reding
From: Thierry Reding <[email protected]>
Fix a couple of checkpatch warnings, such as complaints about bare unsigned being used (instead of unsigned int) and missing blank lines after declarations.
Signed-off-by Thierry Reding <[email protected]>
Patch applied with Jon's ACK.
Yours,
Linus Walleij
PATCH 4/4 gpio: tegra: Use unsigned int where possible
In reply to Thierry RedingFrom: Thierry Reding <[email protected]>
In most of the cases, integers in this file can't be negative, so the type can be more restricted for clarity.
--- drivers/gpio/gpio-tegra.c | 57 ++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 33 deletions(-)
drivers/gpio/gpio-tegra.c +24 -33
@@ -67,8 +67,8 @@struct tegra_gpio_info ;struct tegra_gpio_bank { -int bank; -int irq; +unsigned int bank; +unsigned int irq;spinlock_t lvl_lock[4 ];spinlock_t dbc_lock[4 ];/* Lock for updating debounce count register */ #ifdef CONFIG_PM_SLEEP
@@ -112,13 +112,14 @@ static inline u32 tegra_gpio_readl(struct tegra_gpio_info *tgi, u32 reg)return __raw_readl (tgi->regs + reg); } -static int tegra_gpio_compose (int bank,int port,int bit) +static unsigned int tegra_gpio_compose (unsigned int bank,unsigned int port, +unsigned int bit) {return (bank <<5 ) | ((port &0x3 ) <<3 ) | (bit &0x7 ); }static void tegra_gpio_mask_write (struct tegra_gpio_info *tgi,u32 reg, -int gpio,int value) +unsigned int gpio,u32 value) {u32 val;
@@ -128,12 +129,12 @@ static void tegra_gpio_mask_write(struct tegra_gpio_info *tgi, u32 reg,tegra_gpio_writel (tgi, val, reg); } -static void tegra_gpio_enable (struct tegra_gpio_info *tgi,int gpio) +static void tegra_gpio_enable (struct tegra_gpio_info *tgi,unsigned int gpio) {tegra_gpio_mask_write (tgi,GPIO_MSK_CNF (tgi, gpio), gpio,1 ); } -static void tegra_gpio_disable (struct tegra_gpio_info *tgi,int gpio) +static void tegra_gpio_disable (struct tegra_gpio_info *tgi,unsigned int gpio) {tegra_gpio_mask_write (tgi,GPIO_MSK_CNF (tgi, gpio), gpio,0 ); }
@@ -162,7 +163,7 @@ static void tegra_gpio_set(struct gpio_chip *chip, unsigned int offset,static int tegra_gpio_get (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip); -int bval =BIT (GPIO_BIT (offset)); +unsigned int bval =BIT (GPIO_BIT (offset));/* If gpio is in output mode then read from the out value */ if (tegra_gpio_readl (tgi,GPIO_OE (tgi, offset)) & bval)
@@ -216,7 +217,7 @@ static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,struct tegra_gpio_bank *bank = &tgi->bank_info[GPIO_BANK (offset)];unsigned int debounce_ms =DIV_ROUND_UP (debounce,1000 );unsigned long flags; -int port; +unsigned int port;if (!debounce_ms) { tegra_gpio_mask_write(tgi, GPIO_MSK_DBC_EN(tgi, offset),
@@ -265,7 +266,7 @@ static void tegra_gpio_irq_ack(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;tegra_gpio_writel (tgi,1 <<GPIO_BIT (gpio),GPIO_INT_CLR (tgi, gpio)); }
@@ -274,7 +275,7 @@ static void tegra_gpio_irq_mask(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;tegra_gpio_mask_write (tgi,GPIO_MSK_INT_ENB (tgi, gpio), gpio,0 ); }
@@ -283,20 +284,18 @@ static void tegra_gpio_irq_unmask(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;tegra_gpio_mask_write (tgi,GPIO_MSK_INT_ENB (tgi, gpio), gpio,1 ); }static int tegra_gpio_irq_set_type (struct irq_data *d,unsigned int type) { -int gpio = d->hwirq; +unsigned int gpio = d->hwirq, port =GPIO_PORT (gpio), lvl_type;struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int port =GPIO_PORT (gpio); -int lvl_type; -int val;unsigned long flags; +u32 val;int ret;switch (type &IRQ_TYPE_SENSE_MASK ) {
@@ -327,7 +326,7 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) ret =gpiochip_lock_as_irq (&tgi->gc, gpio);if (ret) {dev_err (tgi->dev, -"unable to lock Tegra GPIO %d as IRQ\n" , gpio); +"unable to lock Tegra GPIO %u as IRQ\n" , gpio);return ret; }
@@ -355,17 +354,14 @@ static void tegra_gpio_irq_shutdown(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;gpiochip_unlock_as_irq (&tgi->gc, gpio); }static void tegra_gpio_irq_handler (struct irq_desc *desc) { -int port; -int pin; -int unmasked =0 ; -int gpio; +unsigned int unmasked =0 , port, pin, gpio;u32 lvl;unsigned long sta;struct irq_chip *chip =irq_desc_get_chip (desc);
@@ -408,8 +404,7 @@ static int tegra_gpio_resume(struct device *dev)struct platform_device *pdev =to_platform_device (dev);struct tegra_gpio_info *tgi =platform_get_drvdata (pdev);unsigned long flags; -int b; -int p; +unsigned int b, p;local_irq_save (flags);
@@ -449,8 +444,7 @@ static int tegra_gpio_suspend(struct device *dev)struct platform_device *pdev =to_platform_device (dev);struct tegra_gpio_info *tgi =platform_get_drvdata (pdev);unsigned long flags; -int b; -int p; +unsigned int b, p;local_irq_save (flags);for (b =0 ; b < tgi->bank_count; b++) {
@@ -489,7 +483,7 @@ static int tegra_gpio_suspend(struct device *dev)static int tegra_gpio_irq_set_wake (struct irq_data *d,unsigned int enable) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d); -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;u32 port, bit, mask; port =GPIO_PORT (gpio);
@@ -513,15 +507,14 @@ static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable)static int dbg_gpio_show (struct seq_file *s,void *unused) {struct tegra_gpio_info *tgi = s->private; -int i; -int j; +unsigned int i, j;for (i =0 ; i < tgi->bank_count; i++) {for (j =0 ; j <4 ; j++) { -int gpio =tegra_gpio_compose (i, j,0 ); +unsigned int gpio =tegra_gpio_compose (i, j,0 ); seq_printf(s, - "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", + "%u:%u %02x %02x %02x %02x %02x %02x %06x\n", i, j, tegra_gpio_readl(tgi, GPIO_CNF(tgi, gpio)), tegra_gpio_readl(tgi, GPIO_OE(tgi, gpio)),
@@ -576,10 +569,8 @@ static int tegra_gpio_probe(struct platform_device *pdev)struct tegra_gpio_info *tgi;struct resource *res;struct tegra_gpio_bank *bank; +unsigned int gpio, i, j;int ret; -int gpio; -int i; -int j; tgi =devm_kzalloc (&pdev->dev,sizeof (*tgi),GFP_KERNEL );if (!tgi)
Signature · 1 line
2.13.3
Re: [PATCH 4/4] gpio: tegra: Use unsigned int where possible
Quoted 196 lines · Thierry Reding
From: Thierry Reding <[email protected]>
In most of the cases, integers in this file can't be negative, so the type can be more restricted for clarity.
Signed-off-by Thierry Reding <[email protected]>--- drivers/gpio/gpio-tegra.c | 57 ++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 33 deletions(-)drivers/gpio/gpio-tegra.c +23
-30@@ -67,8 +67,8 @@struct tegra_gpio_info ;struct tegra_gpio_bank { -int bank; -int irq; +unsigned int bank; +unsigned int irq;spinlock_t lvl_lock[4 ];spinlock_t dbc_lock[4 ];/* Lock for updating debounce count register */ #ifdef CONFIG_PM_SLEEP @@ -112,13 +112,14 @@ static inline u32 tegra_gpio_readl(struct tegra_gpio_info *tgi, u32 reg)return __raw_readl (tgi->regs + reg); } -static int tegra_gpio_compose (int bank,int port,int bit) +static unsigned int tegra_gpio_compose (unsigned int bank,unsigned int port, +unsigned int bit) {return (bank <<5 ) | ((port &0x3 ) <<3 ) | (bit &0x7 ); }static void tegra_gpio_mask_write (struct tegra_gpio_info *tgi,u32 reg, -int gpio,int value) +unsigned int gpio,u32 value) {u32 val;@@ -128,12 +129,12 @@ static void tegra_gpio_mask_write(struct tegra_gpio_info *tgi, u32 reg,tegra_gpio_writel (tgi, val, reg); } -static void tegra_gpio_enable (struct tegra_gpio_info *tgi,int gpio) +static void tegra_gpio_enable (struct tegra_gpio_info *tgi,unsigned int gpio) {tegra_gpio_mask_write (tgi,GPIO_MSK_CNF (tgi, gpio), gpio,1 ); } -static void tegra_gpio_disable (struct tegra_gpio_info *tgi,int gpio) +static void tegra_gpio_disable (struct tegra_gpio_info *tgi,unsigned int gpio) {tegra_gpio_mask_write (tgi,GPIO_MSK_CNF (tgi, gpio), gpio,0 ); }@@ -162,7 +163,7 @@ static void tegra_gpio_set(struct gpio_chip *chip, unsigned int offset,static int tegra_gpio_get (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio_info *tgi =gpiochip_get_data (chip); -int bval =BIT (GPIO_BIT (offset)); +unsigned int bval =BIT (GPIO_BIT (offset));/* If gpio is in output mode then read from the out value */ if (tegra_gpio_readl (tgi,GPIO_OE (tgi, offset)) & bval)@@ -216,7 +217,7 @@ static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,struct tegra_gpio_bank *bank = &tgi->bank_info[GPIO_BANK (offset)];unsigned int debounce_ms =DIV_ROUND_UP (debounce,1000 );unsigned long flags; -int port; +unsigned int port;if (!debounce_ms) { tegra_gpio_mask_write(tgi, GPIO_MSK_DBC_EN(tgi, offset),@@ -265,7 +266,7 @@ static void tegra_gpio_irq_ack(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;tegra_gpio_writel (tgi,1 <<GPIO_BIT (gpio),GPIO_INT_CLR (tgi, gpio)); }@@ -274,7 +275,7 @@ static void tegra_gpio_irq_mask(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;tegra_gpio_mask_write (tgi,GPIO_MSK_INT_ENB (tgi, gpio), gpio,0 ); }@@ -283,20 +284,18 @@ static void tegra_gpio_irq_unmask(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;tegra_gpio_mask_write (tgi,GPIO_MSK_INT_ENB (tgi, gpio), gpio,1 ); }static int tegra_gpio_irq_set_type (struct irq_data *d,unsigned int type) { -int gpio = d->hwirq; +unsigned int gpio = d->hwirq, port =GPIO_PORT (gpio), lvl_type;struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int port =GPIO_PORT (gpio); -int lvl_type; -int val;unsigned long flags; +u32 val;int ret;switch (type &IRQ_TYPE_SENSE_MASK ) {@@ -327,7 +326,7 @@ static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) ret =gpiochip_lock_as_irq (&tgi->gc, gpio);if (ret) {dev_err (tgi->dev, -"unable to lock Tegra GPIO %d as IRQ\n" , gpio); +"unable to lock Tegra GPIO %u as IRQ\n" , gpio);return ret; }@@ -355,17 +354,14 @@ static void tegra_gpio_irq_shutdown(struct irq_data *d) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d);struct tegra_gpio_info *tgi = bank->tgi; -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;gpiochip_unlock_as_irq (&tgi->gc, gpio); }static void tegra_gpio_irq_handler (struct irq_desc *desc) { -int port; -int pin; -int unmasked =0 ; -int gpio; +unsigned int unmasked =0 , port, pin, gpio;u32 lvl;unsigned long sta;struct irq_chip *chip =irq_desc_get_chip (desc);@@ -408,8 +404,7 @@ static int tegra_gpio_resume(struct device *dev)struct platform_device *pdev =to_platform_device (dev);struct tegra_gpio_info *tgi =platform_get_drvdata (pdev);unsigned long flags; -int b; -int p; +unsigned int b, p;local_irq_save (flags);@@ -449,8 +444,7 @@ static int tegra_gpio_suspend(struct device *dev)struct platform_device *pdev =to_platform_device (dev);struct tegra_gpio_info *tgi =platform_get_drvdata (pdev);unsigned long flags; -int b; -int p; +unsigned int b, p;local_irq_save (flags);for (b =0 ; b < tgi->bank_count; b++) {@@ -489,7 +483,7 @@ static int tegra_gpio_suspend(struct device *dev)static int tegra_gpio_irq_set_wake (struct irq_data *d,unsigned int enable) {struct tegra_gpio_bank *bank =irq_data_get_irq_chip_data (d); -int gpio = d->hwirq; +unsigned int gpio = d->hwirq;u32 port, bit, mask; port =GPIO_PORT (gpio);@@ -513,15 +507,14 @@ static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable)static int dbg_gpio_show (struct seq_file *s,void *unused) {struct tegra_gpio_info *tgi = s->private; -int i; -int j; +unsigned int i, j;for (i =0 ; i < tgi->bank_count; i++) {for (j =0 ; j <4 ; j++) { -int gpio =tegra_gpio_compose (i, j,0 ); +unsigned int gpio =tegra_gpio_compose (i, j,0 ); seq_printf(s, - "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", + "%u:%u %02x %02x %02x %02x %02x %02x %06x\n", i, j, tegra_gpio_readl(tgi, GPIO_CNF(tgi, gpio)), tegra_gpio_readl(tgi, GPIO_OE(tgi, gpio)),@@ -576,10 +569,8 @@ static int tegra_gpio_probe(struct platform_device *pdev)struct tegra_gpio_info *tgi;
drivers/gpio/gpio-tegra.c static int tegra_gpio_probe(struct platform_device *pdev) · line 576
Quoted 10 lines
drivers/gpio/gpio-tegra.c +1
-3struct resource *res;struct tegra_gpio_bank *bank; +unsigned int gpio, i, j;int ret; -int gpio; -int i; -int j; tgi =devm_kzalloc (&pdev->dev,sizeof (*tgi),GFP_KERNEL );if (!tgi)
Cheers
Jon
Signature · 1 line
nvpublic
Quoted 42 lines · Thierry Reding
From: Thierry Reding <[email protected]>
of_device_get_match_data()can never return NULL, therefore the check for NULL values is unnecessary.Signed-off-by Thierry Reding <[email protected]>--- drivers/gpio/gpio-tegra.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)drivers/gpio/gpio-tegra.c +1
-8@@ -566,7 +566,6 @@ static struct lock_class_key gpio_lock_class;static int tegra_gpio_probe (struct platform_device *pdev) { -const struct tegra_gpio_soc_config *config;struct tegra_gpio_info *tgi;struct resource *res;struct tegra_gpio_bank *bank;@@ -575,17 +574,11 @@ static int tegra_gpio_probe(struct platform_device *pdev)int i;int j; - config =of_device_get_match_data (&pdev->dev); -if (!config) { -dev_err (&pdev->dev,"Error: No device match found\n" ); -return -ENODEV ; - } - tgi =devm_kzalloc (&pdev->dev,sizeof (*tgi),GFP_KERNEL );if (!tgi)return -ENODEV ; - tgi->soc = config; + tgi->soc =of_device_get_match_data (&pdev->dev); tgi->dev = &pdev->dev; ret =platform_irq_count (pdev);
drivers/gpio/gpio-tegra.c static int tegra_gpio_probe(struct platform_device *pdev) · line 624
Quoted 8 lines
drivers/gpio/gpio-tegra.c +1
-1@@ -625,7 +618,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)platform_set_drvdata (pdev, tgi); -if (config->debounce_supported) +if (tgi->soc->debounce_supported) tgi->gc.set_config = tegra_gpio_set_config; tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count *
Cheers
Jon
Signature · 1 line
nvpublic
Quoted 9 lines · Thierry Reding
From: Thierry Reding <[email protected]>
of_device_get_match_data()can never return NULL, therefore the check for NULL values is unnecessary.Signed-off-by Thierry Reding <[email protected]>--- drivers/gpio/gpio-tegra.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
Hi Linus,
any comments on this? I've got an updated series for the GPIO IRQ chip stuff and another set of patches for banked controller support, but I'd like to flush out all of these minor patches that are byproducts of the other work.
Thierry
Quoted 6 lines · Thierry Reding
From: Thierry Reding <[email protected]>
of_device_get_match_data()can never return NULL, therefore the check for NULL values is unnecessary.Signed-off-by Thierry Reding <[email protected]>
Patch applied with Jon's ACK.
Yours,
Linus Walleij