Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: tegra: Get rid of all file scoped global variables

Move the file scoped multiple global variable from Tegra GPIO
driver to the structure and make this as gpiochip data which
can be referred from GPIO chip callbacks.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Laxman Dewangan and committed by
Linus Walleij
b546be0d 804f5680

+198 -152
+198 -152
drivers/gpio/gpio-tegra.c
··· 35 35 #define GPIO_PORT(x) (((x) >> 3) & 0x3) 36 36 #define GPIO_BIT(x) ((x) & 0x7) 37 37 38 - #define GPIO_REG(x) (GPIO_BANK(x) * tegra_gpio_bank_stride + \ 38 + #define GPIO_REG(tgi, x) (GPIO_BANK(x) * tgi->soc->bank_stride + \ 39 39 GPIO_PORT(x) * 4) 40 40 41 - #define GPIO_CNF(x) (GPIO_REG(x) + 0x00) 42 - #define GPIO_OE(x) (GPIO_REG(x) + 0x10) 43 - #define GPIO_OUT(x) (GPIO_REG(x) + 0X20) 44 - #define GPIO_IN(x) (GPIO_REG(x) + 0x30) 45 - #define GPIO_INT_STA(x) (GPIO_REG(x) + 0x40) 46 - #define GPIO_INT_ENB(x) (GPIO_REG(x) + 0x50) 47 - #define GPIO_INT_LVL(x) (GPIO_REG(x) + 0x60) 48 - #define GPIO_INT_CLR(x) (GPIO_REG(x) + 0x70) 41 + #define GPIO_CNF(t, x) (GPIO_REG(t, x) + 0x00) 42 + #define GPIO_OE(t, x) (GPIO_REG(t, x) + 0x10) 43 + #define GPIO_OUT(t, x) (GPIO_REG(t, x) + 0X20) 44 + #define GPIO_IN(t, x) (GPIO_REG(t, x) + 0x30) 45 + #define GPIO_INT_STA(t, x) (GPIO_REG(t, x) + 0x40) 46 + #define GPIO_INT_ENB(t, x) (GPIO_REG(t, x) + 0x50) 47 + #define GPIO_INT_LVL(t, x) (GPIO_REG(t, x) + 0x60) 48 + #define GPIO_INT_CLR(t, x) (GPIO_REG(t, x) + 0x70) 49 49 50 - #define GPIO_MSK_CNF(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x00) 51 - #define GPIO_MSK_OE(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x10) 52 - #define GPIO_MSK_OUT(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0X20) 53 - #define GPIO_MSK_INT_STA(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x40) 54 - #define GPIO_MSK_INT_ENB(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x50) 55 - #define GPIO_MSK_INT_LVL(x) (GPIO_REG(x) + tegra_gpio_upper_offset + 0x60) 50 + #define GPIO_MSK_CNF(t, x) (GPIO_REG(t, x) + t->soc->upper_offset + 0x00) 51 + #define GPIO_MSK_OE(t, x) (GPIO_REG(t, x) + t->soc->upper_offset + 0x10) 52 + #define GPIO_MSK_OUT(t, x) (GPIO_REG(t, x) + t->soc->upper_offset + 0X20) 53 + #define GPIO_MSK_INT_STA(t, x) (GPIO_REG(t, x) + t->soc->upper_offset + 0x40) 54 + #define GPIO_MSK_INT_ENB(t, x) (GPIO_REG(t, x) + t->soc->upper_offset + 0x50) 55 + #define GPIO_MSK_INT_LVL(t, x) (GPIO_REG(t, x) + t->soc->upper_offset + 0x60) 56 56 57 57 #define GPIO_INT_LVL_MASK 0x010101 58 58 #define GPIO_INT_LVL_EDGE_RISING 0x000101 ··· 60 60 #define GPIO_INT_LVL_EDGE_BOTH 0x010100 61 61 #define GPIO_INT_LVL_LEVEL_HIGH 0x000001 62 62 #define GPIO_INT_LVL_LEVEL_LOW 0x000000 63 + 64 + struct tegra_gpio_info; 63 65 64 66 struct tegra_gpio_bank { 65 67 int bank; ··· 75 73 u32 int_lvl[4]; 76 74 u32 wake_enb[4]; 77 75 #endif 76 + struct tegra_gpio_info *tgi; 78 77 }; 79 78 80 79 struct tegra_gpio_soc_config { ··· 83 80 u32 upper_offset; 84 81 }; 85 82 86 - static struct device *dev; 87 - static struct irq_domain *irq_domain; 88 - static void __iomem *regs; 89 - static u32 tegra_gpio_bank_count; 90 - static u32 tegra_gpio_bank_stride; 91 - static u32 tegra_gpio_upper_offset; 92 - static struct tegra_gpio_bank *tegra_gpio_banks; 83 + struct tegra_gpio_info { 84 + struct device *dev; 85 + void __iomem *regs; 86 + struct irq_domain *irq_domain; 87 + struct tegra_gpio_bank *bank_info; 88 + const struct tegra_gpio_soc_config *soc; 89 + struct gpio_chip gc; 90 + struct irq_chip ic; 91 + struct lock_class_key lock_class; 92 + u32 bank_count; 93 + }; 93 94 94 - static inline void tegra_gpio_writel(u32 val, u32 reg) 95 + static inline void tegra_gpio_writel(struct tegra_gpio_info *tgi, 96 + u32 val, u32 reg) 95 97 { 96 - __raw_writel(val, regs + reg); 98 + __raw_writel(val, tgi->regs + reg); 97 99 } 98 100 99 - static inline u32 tegra_gpio_readl(u32 reg) 101 + static inline u32 tegra_gpio_readl(struct tegra_gpio_info *tgi, u32 reg) 100 102 { 101 - return __raw_readl(regs + reg); 103 + return __raw_readl(tgi->regs + reg); 102 104 } 103 105 104 106 static int tegra_gpio_compose(int bank, int port, int bit) ··· 111 103 return (bank << 5) | ((port & 0x3) << 3) | (bit & 0x7); 112 104 } 113 105 114 - static void tegra_gpio_mask_write(u32 reg, int gpio, int value) 106 + static void tegra_gpio_mask_write(struct tegra_gpio_info *tgi, u32 reg, 107 + int gpio, int value) 115 108 { 116 109 u32 val; 117 110 118 111 val = 0x100 << GPIO_BIT(gpio); 119 112 if (value) 120 113 val |= 1 << GPIO_BIT(gpio); 121 - tegra_gpio_writel(val, reg); 114 + tegra_gpio_writel(tgi, val, reg); 122 115 } 123 116 124 - static void tegra_gpio_enable(int gpio) 117 + static void tegra_gpio_enable(struct tegra_gpio_info *tgi, int gpio) 125 118 { 126 - tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1); 119 + tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 1); 127 120 } 128 121 129 - static void tegra_gpio_disable(int gpio) 122 + static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio) 130 123 { 131 - tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 0); 124 + tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 0); 132 125 } 133 126 134 127 static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset) ··· 139 130 140 131 static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset) 141 132 { 133 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 134 + 142 135 pinctrl_free_gpio(offset); 143 - tegra_gpio_disable(offset); 136 + tegra_gpio_disable(tgi, offset); 144 137 } 145 138 146 139 static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 147 140 { 148 - tegra_gpio_mask_write(GPIO_MSK_OUT(offset), offset, value); 141 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 142 + 143 + tegra_gpio_mask_write(tgi, GPIO_MSK_OUT(tgi, offset), offset, value); 149 144 } 150 145 151 146 static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset) 152 147 { 153 - /* If gpio is in output mode then read from the out value */ 154 - if ((tegra_gpio_readl(GPIO_OE(offset)) >> GPIO_BIT(offset)) & 1) 155 - return (tegra_gpio_readl(GPIO_OUT(offset)) >> 156 - GPIO_BIT(offset)) & 0x1; 148 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 149 + int bval = BIT(GPIO_BIT(offset)); 157 150 158 - return (tegra_gpio_readl(GPIO_IN(offset)) >> GPIO_BIT(offset)) & 0x1; 151 + /* If gpio is in output mode then read from the out value */ 152 + if (tegra_gpio_readl(tgi, GPIO_OE(tgi, offset)) & bval) 153 + return !!(tegra_gpio_readl(tgi, GPIO_OUT(tgi, offset)) & bval); 154 + 155 + return !!(tegra_gpio_readl(tgi, GPIO_IN(tgi, offset)) & bval); 159 156 } 160 157 161 158 static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 162 159 { 163 - tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0); 164 - tegra_gpio_enable(offset); 160 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 161 + 162 + tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, offset), offset, 0); 163 + tegra_gpio_enable(tgi, offset); 165 164 return 0; 166 165 } 167 166 168 167 static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 169 168 int value) 170 169 { 170 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 171 + 171 172 tegra_gpio_set(chip, offset, value); 172 - tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1); 173 - tegra_gpio_enable(offset); 173 + tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, offset), offset, 1); 174 + tegra_gpio_enable(tgi, offset); 174 175 return 0; 175 176 } 176 177 177 178 static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 178 179 { 179 - return irq_find_mapping(irq_domain, offset); 180 - } 180 + struct tegra_gpio_info *tgi = gpiochip_get_data(chip); 181 181 182 - static struct gpio_chip tegra_gpio_chip = { 183 - .label = "tegra-gpio", 184 - .request = tegra_gpio_request, 185 - .free = tegra_gpio_free, 186 - .direction_input = tegra_gpio_direction_input, 187 - .get = tegra_gpio_get, 188 - .direction_output = tegra_gpio_direction_output, 189 - .set = tegra_gpio_set, 190 - .to_irq = tegra_gpio_to_irq, 191 - .base = 0, 192 - }; 182 + return irq_find_mapping(tgi->irq_domain, offset); 183 + } 193 184 194 185 static void tegra_gpio_irq_ack(struct irq_data *d) 195 186 { 187 + struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 188 + struct tegra_gpio_info *tgi = bank->tgi; 196 189 int gpio = d->hwirq; 197 190 198 - tegra_gpio_writel(1 << GPIO_BIT(gpio), GPIO_INT_CLR(gpio)); 191 + tegra_gpio_writel(tgi, 1 << GPIO_BIT(gpio), GPIO_INT_CLR(tgi, gpio)); 199 192 } 200 193 201 194 static void tegra_gpio_irq_mask(struct irq_data *d) 202 195 { 196 + struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 197 + struct tegra_gpio_info *tgi = bank->tgi; 203 198 int gpio = d->hwirq; 204 199 205 - tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 0); 200 + tegra_gpio_mask_write(tgi, GPIO_MSK_INT_ENB(tgi, gpio), gpio, 0); 206 201 } 207 202 208 203 static void tegra_gpio_irq_unmask(struct irq_data *d) 209 204 { 205 + struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 206 + struct tegra_gpio_info *tgi = bank->tgi; 210 207 int gpio = d->hwirq; 211 208 212 - tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 1); 209 + tegra_gpio_mask_write(tgi, GPIO_MSK_INT_ENB(tgi, gpio), gpio, 1); 213 210 } 214 211 215 212 static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type) 216 213 { 217 214 int gpio = d->hwirq; 218 215 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 216 + struct tegra_gpio_info *tgi = bank->tgi; 219 217 int port = GPIO_PORT(gpio); 220 218 int lvl_type; 221 219 int val; ··· 254 238 return -EINVAL; 255 239 } 256 240 257 - ret = gpiochip_lock_as_irq(&tegra_gpio_chip, gpio); 241 + ret = gpiochip_lock_as_irq(&tgi->gc, gpio); 258 242 if (ret) { 259 - dev_err(dev, "unable to lock Tegra GPIO %d as IRQ\n", gpio); 243 + dev_err(tgi->dev, 244 + "unable to lock Tegra GPIO %d as IRQ\n", gpio); 260 245 return ret; 261 246 } 262 247 263 248 spin_lock_irqsave(&bank->lvl_lock[port], flags); 264 249 265 - val = tegra_gpio_readl(GPIO_INT_LVL(gpio)); 250 + val = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio)); 266 251 val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio)); 267 252 val |= lvl_type << GPIO_BIT(gpio); 268 - tegra_gpio_writel(val, GPIO_INT_LVL(gpio)); 253 + tegra_gpio_writel(tgi, val, GPIO_INT_LVL(tgi, gpio)); 269 254 270 255 spin_unlock_irqrestore(&bank->lvl_lock[port], flags); 271 256 272 - tegra_gpio_mask_write(GPIO_MSK_OE(gpio), gpio, 0); 273 - tegra_gpio_enable(gpio); 257 + tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, gpio), gpio, 0); 258 + tegra_gpio_enable(tgi, gpio); 274 259 275 260 if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) 276 261 irq_set_handler_locked(d, handle_level_irq); ··· 283 266 284 267 static void tegra_gpio_irq_shutdown(struct irq_data *d) 285 268 { 269 + struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d); 270 + struct tegra_gpio_info *tgi = bank->tgi; 286 271 int gpio = d->hwirq; 287 272 288 - gpiochip_unlock_as_irq(&tegra_gpio_chip, gpio); 273 + gpiochip_unlock_as_irq(&tgi->gc, gpio); 289 274 } 290 275 291 276 static void tegra_gpio_irq_handler(struct irq_desc *desc) ··· 295 276 int port; 296 277 int pin; 297 278 int unmasked = 0; 279 + int gpio; 280 + u32 lvl; 281 + unsigned long sta; 298 282 struct irq_chip *chip = irq_desc_get_chip(desc); 299 283 struct tegra_gpio_bank *bank = irq_desc_get_handler_data(desc); 284 + struct tegra_gpio_info *tgi = bank->tgi; 300 285 301 286 chained_irq_enter(chip, desc); 302 287 303 288 for (port = 0; port < 4; port++) { 304 - int gpio = tegra_gpio_compose(bank->bank, port, 0); 305 - unsigned long sta = tegra_gpio_readl(GPIO_INT_STA(gpio)) & 306 - tegra_gpio_readl(GPIO_INT_ENB(gpio)); 307 - u32 lvl = tegra_gpio_readl(GPIO_INT_LVL(gpio)); 289 + gpio = tegra_gpio_compose(bank->bank, port, 0); 290 + sta = tegra_gpio_readl(tgi, GPIO_INT_STA(tgi, gpio)) & 291 + tegra_gpio_readl(tgi, GPIO_INT_ENB(tgi, gpio)); 292 + lvl = tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio)); 308 293 309 294 for_each_set_bit(pin, &sta, 8) { 310 - tegra_gpio_writel(1 << pin, GPIO_INT_CLR(gpio)); 295 + tegra_gpio_writel(tgi, 1 << pin, 296 + GPIO_INT_CLR(tgi, gpio)); 311 297 312 298 /* if gpio is edge triggered, clear condition 313 299 * before executing the handler so that we don't ··· 335 311 #ifdef CONFIG_PM_SLEEP 336 312 static int tegra_gpio_resume(struct device *dev) 337 313 { 314 + struct platform_device *pdev = to_platform_device(dev); 315 + struct tegra_gpio_info *tgi = platform_get_drvdata(pdev); 338 316 unsigned long flags; 339 317 int b; 340 318 int p; 341 319 342 320 local_irq_save(flags); 343 321 344 - for (b = 0; b < tegra_gpio_bank_count; b++) { 345 - struct tegra_gpio_bank *bank = &tegra_gpio_banks[b]; 322 + for (b = 0; b < tgi->bank_count; b++) { 323 + struct tegra_gpio_bank *bank = &tgi->bank_info[b]; 346 324 347 325 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { 348 326 unsigned int gpio = (b<<5) | (p<<3); 349 - tegra_gpio_writel(bank->cnf[p], GPIO_CNF(gpio)); 350 - tegra_gpio_writel(bank->out[p], GPIO_OUT(gpio)); 351 - tegra_gpio_writel(bank->oe[p], GPIO_OE(gpio)); 352 - tegra_gpio_writel(bank->int_lvl[p], GPIO_INT_LVL(gpio)); 353 - tegra_gpio_writel(bank->int_enb[p], GPIO_INT_ENB(gpio)); 327 + tegra_gpio_writel(tgi, bank->cnf[p], 328 + GPIO_CNF(tgi, gpio)); 329 + tegra_gpio_writel(tgi, bank->out[p], 330 + GPIO_OUT(tgi, gpio)); 331 + tegra_gpio_writel(tgi, bank->oe[p], 332 + GPIO_OE(tgi, gpio)); 333 + tegra_gpio_writel(tgi, bank->int_lvl[p], 334 + GPIO_INT_LVL(tgi, gpio)); 335 + tegra_gpio_writel(tgi, bank->int_enb[p], 336 + GPIO_INT_ENB(tgi, gpio)); 354 337 } 355 338 } 356 339 ··· 367 336 368 337 static int tegra_gpio_suspend(struct device *dev) 369 338 { 339 + struct platform_device *pdev = to_platform_device(dev); 340 + struct tegra_gpio_info *tgi = platform_get_drvdata(pdev); 370 341 unsigned long flags; 371 342 int b; 372 343 int p; 373 344 374 345 local_irq_save(flags); 375 - for (b = 0; b < tegra_gpio_bank_count; b++) { 376 - struct tegra_gpio_bank *bank = &tegra_gpio_banks[b]; 346 + for (b = 0; b < tgi->bank_count; b++) { 347 + struct tegra_gpio_bank *bank = &tgi->bank_info[b]; 377 348 378 349 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) { 379 350 unsigned int gpio = (b<<5) | (p<<3); 380 - bank->cnf[p] = tegra_gpio_readl(GPIO_CNF(gpio)); 381 - bank->out[p] = tegra_gpio_readl(GPIO_OUT(gpio)); 382 - bank->oe[p] = tegra_gpio_readl(GPIO_OE(gpio)); 383 - bank->int_enb[p] = tegra_gpio_readl(GPIO_INT_ENB(gpio)); 384 - bank->int_lvl[p] = tegra_gpio_readl(GPIO_INT_LVL(gpio)); 351 + bank->cnf[p] = tegra_gpio_readl(tgi, 352 + GPIO_CNF(tgi, gpio)); 353 + bank->out[p] = tegra_gpio_readl(tgi, 354 + GPIO_OUT(tgi, gpio)); 355 + bank->oe[p] = tegra_gpio_readl(tgi, 356 + GPIO_OE(tgi, gpio)); 357 + bank->int_enb[p] = tegra_gpio_readl(tgi, 358 + GPIO_INT_ENB(tgi, gpio)); 359 + bank->int_lvl[p] = tegra_gpio_readl(tgi, 360 + GPIO_INT_LVL(tgi, gpio)); 385 361 386 362 /* Enable gpio irq for wake up source */ 387 - tegra_gpio_writel(bank->wake_enb[p], 388 - GPIO_INT_ENB(gpio)); 363 + tegra_gpio_writel(tgi, bank->wake_enb[p], 364 + GPIO_INT_ENB(tgi, gpio)); 389 365 } 390 366 } 391 367 local_irq_restore(flags); ··· 425 387 426 388 static int dbg_gpio_show(struct seq_file *s, void *unused) 427 389 { 390 + struct tegra_gpio_info *tgi = s->private; 428 391 int i; 429 392 int j; 430 393 431 - for (i = 0; i < tegra_gpio_bank_count; i++) { 394 + for (i = 0; i < tgi->bank_count; i++) { 432 395 for (j = 0; j < 4; j++) { 433 396 int gpio = tegra_gpio_compose(i, j, 0); 434 397 seq_printf(s, 435 398 "%d:%d %02x %02x %02x %02x %02x %02x %06x\n", 436 399 i, j, 437 - tegra_gpio_readl(GPIO_CNF(gpio)), 438 - tegra_gpio_readl(GPIO_OE(gpio)), 439 - tegra_gpio_readl(GPIO_OUT(gpio)), 440 - tegra_gpio_readl(GPIO_IN(gpio)), 441 - tegra_gpio_readl(GPIO_INT_STA(gpio)), 442 - tegra_gpio_readl(GPIO_INT_ENB(gpio)), 443 - tegra_gpio_readl(GPIO_INT_LVL(gpio))); 400 + tegra_gpio_readl(tgi, GPIO_CNF(tgi, gpio)), 401 + tegra_gpio_readl(tgi, GPIO_OE(tgi, gpio)), 402 + tegra_gpio_readl(tgi, GPIO_OUT(tgi, gpio)), 403 + tegra_gpio_readl(tgi, GPIO_IN(tgi, gpio)), 404 + tegra_gpio_readl(tgi, GPIO_INT_STA(tgi, gpio)), 405 + tegra_gpio_readl(tgi, GPIO_INT_ENB(tgi, gpio)), 406 + tegra_gpio_readl(tgi, GPIO_INT_LVL(tgi, gpio))); 444 407 } 445 408 } 446 409 return 0; ··· 449 410 450 411 static int dbg_gpio_open(struct inode *inode, struct file *file) 451 412 { 452 - return single_open(file, dbg_gpio_show, &inode->i_private); 413 + return single_open(file, dbg_gpio_show, inode->i_private); 453 414 } 454 415 455 416 static const struct file_operations debug_fops = { ··· 459 420 .release = single_release, 460 421 }; 461 422 462 - static void tegra_gpio_debuginit(void) 423 + static void tegra_gpio_debuginit(struct tegra_gpio_info *tgi) 463 424 { 464 425 (void) debugfs_create_file("tegra_gpio", S_IRUGO, 465 - NULL, NULL, &debug_fops); 426 + NULL, tgi, &debug_fops); 466 427 } 467 428 468 429 #else 469 430 470 - static inline void tegra_gpio_debuginit(void) 431 + static inline void tegra_gpio_debuginit(struct tegra_gpio_info *tgi) 471 432 { 472 433 } 473 434 474 435 #endif 475 - 476 - static struct irq_chip tegra_gpio_irq_chip = { 477 - .name = "GPIO", 478 - .irq_ack = tegra_gpio_irq_ack, 479 - .irq_mask = tegra_gpio_irq_mask, 480 - .irq_unmask = tegra_gpio_irq_unmask, 481 - .irq_set_type = tegra_gpio_irq_set_type, 482 - .irq_shutdown = tegra_gpio_irq_shutdown, 483 - #ifdef CONFIG_PM_SLEEP 484 - .irq_set_wake = tegra_gpio_irq_set_wake, 485 - #endif 486 - }; 487 436 488 437 static const struct dev_pm_ops tegra_gpio_pm_ops = { 489 438 SET_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume) 490 439 }; 491 440 492 - /* This lock class tells lockdep that GPIO irqs are in a different 493 - * category than their parents, so it won't report false recursion. 494 - */ 495 - static struct lock_class_key gpio_lock_class; 496 - 497 441 static int tegra_gpio_probe(struct platform_device *pdev) 498 442 { 499 443 const struct tegra_gpio_soc_config *config; 444 + struct tegra_gpio_info *tgi; 500 445 struct resource *res; 501 446 struct tegra_gpio_bank *bank; 502 447 int ret; ··· 488 465 int i; 489 466 int j; 490 467 491 - dev = &pdev->dev; 492 - 493 468 config = of_device_get_match_data(&pdev->dev); 494 469 if (!config) { 495 470 dev_err(&pdev->dev, "Error: No device match found\n"); 496 471 return -ENODEV; 497 472 } 498 473 499 - tegra_gpio_bank_stride = config->bank_stride; 500 - tegra_gpio_upper_offset = config->upper_offset; 474 + tgi = devm_kzalloc(&pdev->dev, sizeof(*tgi), GFP_KERNEL); 475 + if (!tgi) 476 + return -ENODEV; 477 + 478 + tgi->soc = config; 479 + tgi->dev = &pdev->dev; 501 480 502 481 for (;;) { 503 - res = platform_get_resource(pdev, IORESOURCE_IRQ, tegra_gpio_bank_count); 482 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 483 + tgi->bank_count); 504 484 if (!res) 505 485 break; 506 - tegra_gpio_bank_count++; 486 + tgi->bank_count++; 507 487 } 508 - if (!tegra_gpio_bank_count) { 488 + if (!tgi->bank_count) { 509 489 dev_err(&pdev->dev, "Missing IRQ resource\n"); 510 490 return -ENODEV; 511 491 } 512 492 513 - tegra_gpio_chip.ngpio = tegra_gpio_bank_count * 32; 493 + tgi->gc.label = "tegra-gpio"; 494 + tgi->gc.request = tegra_gpio_request; 495 + tgi->gc.free = tegra_gpio_free; 496 + tgi->gc.direction_input = tegra_gpio_direction_input; 497 + tgi->gc.get = tegra_gpio_get; 498 + tgi->gc.direction_output = tegra_gpio_direction_output; 499 + tgi->gc.set = tegra_gpio_set; 500 + tgi->gc.to_irq = tegra_gpio_to_irq; 501 + tgi->gc.base = 0; 502 + tgi->gc.ngpio = tgi->bank_count * 32; 503 + tgi->gc.parent = &pdev->dev; 504 + tgi->gc.of_node = pdev->dev.of_node; 514 505 515 - tegra_gpio_banks = devm_kzalloc(&pdev->dev, 516 - tegra_gpio_bank_count * sizeof(*tegra_gpio_banks), 517 - GFP_KERNEL); 518 - if (!tegra_gpio_banks) 506 + tgi->ic.name = "GPIO"; 507 + tgi->ic.irq_ack = tegra_gpio_irq_ack; 508 + tgi->ic.irq_mask = tegra_gpio_irq_mask; 509 + tgi->ic.irq_unmask = tegra_gpio_irq_unmask; 510 + tgi->ic.irq_set_type = tegra_gpio_irq_set_type; 511 + tgi->ic.irq_shutdown = tegra_gpio_irq_shutdown; 512 + #ifdef CONFIG_PM_SLEEP 513 + tgi->ic.irq_set_wake = tegra_gpio_irq_set_wake; 514 + #endif 515 + 516 + platform_set_drvdata(pdev, tgi); 517 + 518 + tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count * 519 + sizeof(*tgi->bank_info), GFP_KERNEL); 520 + if (!tgi->bank_info) 519 521 return -ENODEV; 520 522 521 - irq_domain = irq_domain_add_linear(pdev->dev.of_node, 522 - tegra_gpio_chip.ngpio, 523 - &irq_domain_simple_ops, NULL); 524 - if (!irq_domain) 523 + tgi->irq_domain = irq_domain_add_linear(pdev->dev.of_node, 524 + tgi->gc.ngpio, 525 + &irq_domain_simple_ops, NULL); 526 + if (!tgi->irq_domain) 525 527 return -ENODEV; 526 528 527 - for (i = 0; i < tegra_gpio_bank_count; i++) { 529 + for (i = 0; i < tgi->bank_count; i++) { 528 530 res = platform_get_resource(pdev, IORESOURCE_IRQ, i); 529 531 if (!res) { 530 532 dev_err(&pdev->dev, "Missing IRQ resource\n"); 531 533 return -ENODEV; 532 534 } 533 535 534 - bank = &tegra_gpio_banks[i]; 536 + bank = &tgi->bank_info[i]; 535 537 bank->bank = i; 536 538 bank->irq = res->start; 539 + bank->tgi = tgi; 537 540 } 538 541 539 542 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 540 - regs = devm_ioremap_resource(&pdev->dev, res); 541 - if (IS_ERR(regs)) 542 - return PTR_ERR(regs); 543 + tgi->regs = devm_ioremap_resource(&pdev->dev, res); 544 + if (IS_ERR(tgi->regs)) 545 + return PTR_ERR(tgi->regs); 543 546 544 - for (i = 0; i < tegra_gpio_bank_count; i++) { 547 + for (i = 0; i < tgi->bank_count; i++) { 545 548 for (j = 0; j < 4; j++) { 546 549 int gpio = tegra_gpio_compose(i, j, 0); 547 - tegra_gpio_writel(0x00, GPIO_INT_ENB(gpio)); 550 + tegra_gpio_writel(tgi, 0x00, GPIO_INT_ENB(tgi, gpio)); 548 551 } 549 552 } 550 553 551 - tegra_gpio_chip.of_node = pdev->dev.of_node; 552 - 553 - ret = devm_gpiochip_add_data(&pdev->dev, &tegra_gpio_chip, NULL); 554 + ret = devm_gpiochip_add_data(&pdev->dev, &tgi->gc, tgi); 554 555 if (ret < 0) { 555 - irq_domain_remove(irq_domain); 556 + irq_domain_remove(tgi->irq_domain); 556 557 return ret; 557 558 } 558 559 559 - for (gpio = 0; gpio < tegra_gpio_chip.ngpio; gpio++) { 560 - int irq = irq_create_mapping(irq_domain, gpio); 560 + for (gpio = 0; gpio < tgi->gc.ngpio; gpio++) { 561 + int irq = irq_create_mapping(tgi->irq_domain, gpio); 561 562 /* No validity check; all Tegra GPIOs are valid IRQs */ 562 563 563 - bank = &tegra_gpio_banks[GPIO_BANK(gpio)]; 564 + bank = &tgi->bank_info[GPIO_BANK(gpio)]; 564 565 565 - irq_set_lockdep_class(irq, &gpio_lock_class); 566 + irq_set_lockdep_class(irq, &tgi->lock_class); 566 567 irq_set_chip_data(irq, bank); 567 - irq_set_chip_and_handler(irq, &tegra_gpio_irq_chip, 568 - handle_simple_irq); 568 + irq_set_chip_and_handler(irq, &tgi->ic, handle_simple_irq); 569 569 } 570 570 571 - for (i = 0; i < tegra_gpio_bank_count; i++) { 572 - bank = &tegra_gpio_banks[i]; 571 + for (i = 0; i < tgi->bank_count; i++) { 572 + bank = &tgi->bank_info[i]; 573 573 574 574 irq_set_chained_handler_and_data(bank->irq, 575 575 tegra_gpio_irq_handler, bank); ··· 601 555 spin_lock_init(&bank->lvl_lock[j]); 602 556 } 603 557 604 - tegra_gpio_debuginit(); 558 + tegra_gpio_debuginit(tgi); 605 559 606 560 return 0; 607 561 }