diff options
| -rw-r--r-- | drivers/soc/tegra/pmc.c | 485 | ||||
| -rw-r--r-- | include/soc/tegra/pmc.h | 1 |
2 files changed, 425 insertions, 61 deletions
diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c index 08966c26d65c..bb173456bbff 100644 --- a/drivers/soc/tegra/pmc.c +++ b/drivers/soc/tegra/pmc.c | |||
| @@ -31,10 +31,13 @@ | |||
| 31 | #include <linux/iopoll.h> | 31 | #include <linux/iopoll.h> |
| 32 | #include <linux/of.h> | 32 | #include <linux/of.h> |
| 33 | #include <linux/of_address.h> | 33 | #include <linux/of_address.h> |
| 34 | #include <linux/of_platform.h> | ||
| 34 | #include <linux/platform_device.h> | 35 | #include <linux/platform_device.h> |
| 36 | #include <linux/pm_domain.h> | ||
| 35 | #include <linux/reboot.h> | 37 | #include <linux/reboot.h> |
| 36 | #include <linux/reset.h> | 38 | #include <linux/reset.h> |
| 37 | #include <linux/seq_file.h> | 39 | #include <linux/seq_file.h> |
| 40 | #include <linux/slab.h> | ||
| 38 | #include <linux/spinlock.h> | 41 | #include <linux/spinlock.h> |
| 39 | 42 | ||
| 40 | #include <soc/tegra/common.h> | 43 | #include <soc/tegra/common.h> |
| @@ -102,6 +105,16 @@ | |||
| 102 | 105 | ||
| 103 | #define GPU_RG_CNTRL 0x2d4 | 106 | #define GPU_RG_CNTRL 0x2d4 |
| 104 | 107 | ||
| 108 | struct tegra_powergate { | ||
| 109 | struct generic_pm_domain genpd; | ||
| 110 | struct tegra_pmc *pmc; | ||
| 111 | unsigned int id; | ||
| 112 | struct clk **clks; | ||
| 113 | unsigned int num_clks; | ||
| 114 | struct reset_control **resets; | ||
| 115 | unsigned int num_resets; | ||
| 116 | }; | ||
| 117 | |||
| 105 | struct tegra_pmc_soc { | 118 | struct tegra_pmc_soc { |
| 106 | unsigned int num_powergates; | 119 | unsigned int num_powergates; |
| 107 | const char *const *powergates; | 120 | const char *const *powergates; |
| @@ -132,6 +145,7 @@ struct tegra_pmc_soc { | |||
| 132 | * @cpu_pwr_good_en: CPU power good signal is enabled | 145 | * @cpu_pwr_good_en: CPU power good signal is enabled |
| 133 | * @lp0_vec_phys: physical base address of the LP0 warm boot code | 146 | * @lp0_vec_phys: physical base address of the LP0 warm boot code |
| 134 | * @lp0_vec_size: size of the LP0 warm boot code | 147 | * @lp0_vec_size: size of the LP0 warm boot code |
| 148 | * @powergates_available: Bitmap of available power gates | ||
| 135 | * @powergates_lock: mutex for power gate register access | 149 | * @powergates_lock: mutex for power gate register access |
| 136 | */ | 150 | */ |
| 137 | struct tegra_pmc { | 151 | struct tegra_pmc { |
| @@ -156,6 +170,7 @@ struct tegra_pmc { | |||
| 156 | bool cpu_pwr_good_en; | 170 | bool cpu_pwr_good_en; |
| 157 | u32 lp0_vec_phys; | 171 | u32 lp0_vec_phys; |
| 158 | u32 lp0_vec_size; | 172 | u32 lp0_vec_size; |
| 173 | DECLARE_BITMAP(powergates_available, TEGRA_POWERGATE_MAX); | ||
| 159 | 174 | ||
| 160 | struct mutex powergates_lock; | 175 | struct mutex powergates_lock; |
| 161 | }; | 176 | }; |
| @@ -165,6 +180,12 @@ static struct tegra_pmc *pmc = &(struct tegra_pmc) { | |||
| 165 | .suspend_mode = TEGRA_SUSPEND_NONE, | 180 | .suspend_mode = TEGRA_SUSPEND_NONE, |
| 166 | }; | 181 | }; |
| 167 | 182 | ||
| 183 | static inline struct tegra_powergate * | ||
| 184 | to_powergate(struct generic_pm_domain *domain) | ||
| 185 | { | ||
| 186 | return container_of(domain, struct tegra_powergate, genpd); | ||
| 187 | } | ||
| 188 | |||
| 168 | static u32 tegra_pmc_readl(unsigned long offset) | 189 | static u32 tegra_pmc_readl(unsigned long offset) |
| 169 | { | 190 | { |
| 170 | return readl(pmc->base + offset); | 191 | return readl(pmc->base + offset); |
| @@ -188,6 +209,31 @@ static inline bool tegra_powergate_is_valid(int id) | |||
| 188 | return (pmc->soc && pmc->soc->powergates[id]); | 209 | return (pmc->soc && pmc->soc->powergates[id]); |
| 189 | } | 210 | } |
| 190 | 211 | ||
| 212 | static inline bool tegra_powergate_is_available(int id) | ||
| 213 | { | ||
| 214 | return test_bit(id, pmc->powergates_available); | ||
| 215 | } | ||
| 216 | |||
| 217 | static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name) | ||
| 218 | { | ||
| 219 | unsigned int i; | ||
| 220 | |||
| 221 | if (!pmc || !pmc->soc || !name) | ||
| 222 | return -EINVAL; | ||
| 223 | |||
| 224 | for (i = 0; i < pmc->soc->num_powergates; i++) { | ||
| 225 | if (!tegra_powergate_is_valid(i)) | ||
| 226 | continue; | ||
| 227 | |||
| 228 | if (!strcmp(name, pmc->soc->powergates[i])) | ||
| 229 | return i; | ||
| 230 | } | ||
| 231 | |||
| 232 | dev_err(pmc->dev, "powergate %s not found\n", name); | ||
| 233 | |||
| 234 | return -ENODEV; | ||
| 235 | } | ||
| 236 | |||
| 191 | /** | 237 | /** |
| 192 | * tegra_powergate_set() - set the state of a partition | 238 | * tegra_powergate_set() - set the state of a partition |
| 193 | * @id: partition ID | 239 | * @id: partition ID |
| @@ -218,13 +264,219 @@ static int tegra_powergate_set(unsigned int id, bool new_state) | |||
| 218 | return err; | 264 | return err; |
| 219 | } | 265 | } |
| 220 | 266 | ||
| 267 | static int __tegra_powergate_remove_clamping(unsigned int id) | ||
| 268 | { | ||
| 269 | u32 mask; | ||
| 270 | |||
| 271 | mutex_lock(&pmc->powergates_lock); | ||
| 272 | |||
| 273 | /* | ||
| 274 | * On Tegra124 and later, the clamps for the GPU are controlled by a | ||
| 275 | * separate register (with different semantics). | ||
| 276 | */ | ||
| 277 | if (id == TEGRA_POWERGATE_3D) { | ||
| 278 | if (pmc->soc->has_gpu_clamps) { | ||
| 279 | tegra_pmc_writel(0, GPU_RG_CNTRL); | ||
| 280 | goto out; | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | /* | ||
| 285 | * Tegra 2 has a bug where PCIE and VDE clamping masks are | ||
| 286 | * swapped relatively to the partition ids | ||
| 287 | */ | ||
| 288 | if (id == TEGRA_POWERGATE_VDEC) | ||
| 289 | mask = (1 << TEGRA_POWERGATE_PCIE); | ||
| 290 | else if (id == TEGRA_POWERGATE_PCIE) | ||
| 291 | mask = (1 << TEGRA_POWERGATE_VDEC); | ||
| 292 | else | ||
| 293 | mask = (1 << id); | ||
| 294 | |||
| 295 | tegra_pmc_writel(mask, REMOVE_CLAMPING); | ||
| 296 | |||
| 297 | out: | ||
| 298 | mutex_unlock(&pmc->powergates_lock); | ||
| 299 | |||
| 300 | return 0; | ||
| 301 | } | ||
| 302 | |||
| 303 | static void tegra_powergate_disable_clocks(struct tegra_powergate *pg) | ||
| 304 | { | ||
| 305 | unsigned int i; | ||
| 306 | |||
| 307 | for (i = 0; i < pg->num_clks; i++) | ||
| 308 | clk_disable_unprepare(pg->clks[i]); | ||
| 309 | } | ||
| 310 | |||
| 311 | static int tegra_powergate_enable_clocks(struct tegra_powergate *pg) | ||
| 312 | { | ||
| 313 | unsigned int i; | ||
| 314 | int err; | ||
| 315 | |||
| 316 | for (i = 0; i < pg->num_clks; i++) { | ||
| 317 | err = clk_prepare_enable(pg->clks[i]); | ||
| 318 | if (err) | ||
| 319 | goto out; | ||
| 320 | } | ||
| 321 | |||
| 322 | return 0; | ||
| 323 | |||
| 324 | out: | ||
| 325 | while (i--) | ||
| 326 | clk_disable_unprepare(pg->clks[i]); | ||
| 327 | |||
| 328 | return err; | ||
| 329 | } | ||
| 330 | |||
| 331 | static int tegra_powergate_reset_assert(struct tegra_powergate *pg) | ||
| 332 | { | ||
| 333 | unsigned int i; | ||
| 334 | int err; | ||
| 335 | |||
| 336 | for (i = 0; i < pg->num_resets; i++) { | ||
| 337 | err = reset_control_assert(pg->resets[i]); | ||
| 338 | if (err) | ||
| 339 | return err; | ||
| 340 | } | ||
| 341 | |||
| 342 | return 0; | ||
| 343 | } | ||
| 344 | |||
| 345 | static int tegra_powergate_reset_deassert(struct tegra_powergate *pg) | ||
| 346 | { | ||
| 347 | unsigned int i; | ||
| 348 | int err; | ||
| 349 | |||
| 350 | for (i = 0; i < pg->num_resets; i++) { | ||
| 351 | err = reset_control_deassert(pg->resets[i]); | ||
| 352 | if (err) | ||
| 353 | return err; | ||
| 354 | } | ||
| 355 | |||
| 356 | return 0; | ||
| 357 | } | ||
| 358 | |||
| 359 | static int tegra_powergate_power_up(struct tegra_powergate *pg, | ||
| 360 | bool disable_clocks) | ||
| 361 | { | ||
| 362 | int err; | ||
| 363 | |||
| 364 | err = tegra_powergate_reset_assert(pg); | ||
| 365 | if (err) | ||
| 366 | return err; | ||
| 367 | |||
| 368 | usleep_range(10, 20); | ||
| 369 | |||
| 370 | err = tegra_powergate_set(pg->id, true); | ||
| 371 | if (err < 0) | ||
| 372 | return err; | ||
| 373 | |||
| 374 | usleep_range(10, 20); | ||
| 375 | |||
| 376 | err = tegra_powergate_enable_clocks(pg); | ||
| 377 | if (err) | ||
| 378 | goto disable_clks; | ||
| 379 | |||
| 380 | usleep_range(10, 20); | ||
| 381 | |||
| 382 | err = __tegra_powergate_remove_clamping(pg->id); | ||
| 383 | if (err) | ||
| 384 | goto disable_clks; | ||
| 385 | |||
| 386 | usleep_range(10, 20); | ||
| 387 | |||
| 388 | err = tegra_powergate_reset_deassert(pg); | ||
| 389 | if (err) | ||
| 390 | goto powergate_off; | ||
| 391 | |||
| 392 | usleep_range(10, 20); | ||
| 393 | |||
| 394 | if (disable_clocks) | ||
| 395 | tegra_powergate_disable_clocks(pg); | ||
| 396 | |||
| 397 | return 0; | ||
| 398 | |||
| 399 | disable_clks: | ||
| 400 | tegra_powergate_disable_clocks(pg); | ||
| 401 | usleep_range(10, 20); | ||
| 402 | powergate_off: | ||
| 403 | tegra_powergate_set(pg->id, false); | ||
| 404 | |||
| 405 | return err; | ||
| 406 | } | ||
| 407 | |||
| 408 | static int tegra_powergate_power_down(struct tegra_powergate *pg) | ||
| 409 | { | ||
| 410 | int err; | ||
| 411 | |||
| 412 | err = tegra_powergate_enable_clocks(pg); | ||
| 413 | if (err) | ||
| 414 | return err; | ||
| 415 | |||
| 416 | usleep_range(10, 20); | ||
| 417 | |||
| 418 | err = tegra_powergate_reset_assert(pg); | ||
| 419 | if (err) | ||
| 420 | goto disable_clks; | ||
| 421 | |||
| 422 | usleep_range(10, 20); | ||
| 423 | |||
| 424 | tegra_powergate_disable_clocks(pg); | ||
| 425 | |||
| 426 | usleep_range(10, 20); | ||
| 427 | |||
| 428 | err = tegra_powergate_set(pg->id, false); | ||
| 429 | if (err) | ||
| 430 | goto assert_resets; | ||
| 431 | |||
| 432 | return 0; | ||
| 433 | |||
| 434 | assert_resets: | ||
| 435 | tegra_powergate_enable_clocks(pg); | ||
| 436 | usleep_range(10, 20); | ||
| 437 | tegra_powergate_reset_deassert(pg); | ||
| 438 | usleep_range(10, 20); | ||
| 439 | disable_clks: | ||
| 440 | tegra_powergate_disable_clocks(pg); | ||
| 441 | |||
| 442 | return err; | ||
| 443 | } | ||
| 444 | |||
| 445 | static int tegra_genpd_power_on(struct generic_pm_domain *domain) | ||
| 446 | { | ||
| 447 | struct tegra_powergate *pg = to_powergate(domain); | ||
| 448 | struct tegra_pmc *pmc = pg->pmc; | ||
| 449 | int err; | ||
| 450 | |||
| 451 | err = tegra_powergate_power_up(pg, true); | ||
| 452 | if (err) | ||
| 453 | dev_err(pmc->dev, "failed to turn on PM domain %s: %d\n", | ||
| 454 | pg->genpd.name, err); | ||
| 455 | |||
| 456 | return err; | ||
| 457 | } | ||
| 458 | |||
| 459 | static int tegra_genpd_power_off(struct generic_pm_domain *domain) | ||
| 460 | { | ||
| 461 | struct tegra_powergate *pg = to_powergate(domain); | ||
| 462 | struct tegra_pmc *pmc = pg->pmc; | ||
| 463 | int err; | ||
| 464 | |||
| 465 | err = tegra_powergate_power_down(pg); | ||
| 466 | if (err) | ||
| 467 | dev_err(pmc->dev, "failed to turn off PM domain %s: %d\n", | ||
| 468 | pg->genpd.name, err); | ||
| 469 | |||
| 470 | return err; | ||
| 471 | } | ||
| 472 | |||
| 221 | /** | 473 | /** |
| 222 | * tegra_powergate_power_on() - power on partition | 474 | * tegra_powergate_power_on() - power on partition |
| 223 | * @id: partition ID | 475 | * @id: partition ID |
| 224 | */ | 476 | */ |
| 225 | int tegra_powergate_power_on(unsigned int id) | 477 | int tegra_powergate_power_on(unsigned int id) |
| 226 | { | 478 | { |
| 227 | if (!tegra_powergate_is_valid(id)) | 479 | if (!tegra_powergate_is_available(id)) |
| 228 | return -EINVAL; | 480 | return -EINVAL; |
| 229 | 481 | ||
| 230 | return tegra_powergate_set(id, true); | 482 | return tegra_powergate_set(id, true); |
| @@ -236,7 +488,7 @@ int tegra_powergate_power_on(unsigned int id) | |||
| 236 | */ | 488 | */ |
| 237 | int tegra_powergate_power_off(unsigned int id) | 489 | int tegra_powergate_power_off(unsigned int id) |
| 238 | { | 490 | { |
| 239 | if (!tegra_powergate_is_valid(id)) | 491 | if (!tegra_powergate_is_available(id)) |
| 240 | return -EINVAL; | 492 | return -EINVAL; |
| 241 | 493 | ||
| 242 | return tegra_powergate_set(id, false); | 494 | return tegra_powergate_set(id, false); |
| @@ -267,41 +519,10 @@ int tegra_powergate_is_powered(unsigned int id) | |||
| 267 | */ | 519 | */ |
| 268 | int tegra_powergate_remove_clamping(unsigned int id) | 520 | int tegra_powergate_remove_clamping(unsigned int id) |
| 269 | { | 521 | { |
| 270 | u32 mask; | 522 | if (!tegra_powergate_is_available(id)) |
| 271 | |||
| 272 | if (!tegra_powergate_is_valid(id)) | ||
| 273 | return -EINVAL; | 523 | return -EINVAL; |
| 274 | 524 | ||
| 275 | mutex_lock(&pmc->powergates_lock); | 525 | return __tegra_powergate_remove_clamping(id); |
| 276 | |||
| 277 | /* | ||
| 278 | * On Tegra124 and later, the clamps for the GPU are controlled by a | ||
| 279 | * separate register (with different semantics). | ||
| 280 | */ | ||
| 281 | if (id == TEGRA_POWERGATE_3D) { | ||
| 282 | if (pmc->soc->has_gpu_clamps) { | ||
| 283 | tegra_pmc_writel(0, GPU_RG_CNTRL); | ||
| 284 | goto out; | ||
| 285 | } | ||
| 286 | } | ||
| 287 | |||
| 288 | /* | ||
| 289 | * Tegra 2 has a bug where PCIE and VDE clamping masks are | ||
| 290 | * swapped relatively to the partition ids | ||
| 291 | */ | ||
| 292 | if (id == TEGRA_POWERGATE_VDEC) | ||
| 293 | mask = (1 << TEGRA_POWERGATE_PCIE); | ||
| 294 | else if (id == TEGRA_POWERGATE_PCIE) | ||
| 295 | mask = (1 << TEGRA_POWERGATE_VDEC); | ||
| 296 | else | ||
| 297 | mask = (1 << id); | ||
| 298 | |||
| 299 | tegra_pmc_writel(mask, REMOVE_CLAMPING); | ||
| 300 | |||
| 301 | out: | ||
| 302 | mutex_unlock(&pmc->powergates_lock); | ||
| 303 | |||
| 304 | return 0; | ||
| 305 | } | 526 | } |
| 306 | EXPORT_SYMBOL(tegra_powergate_remove_clamping); | 527 | EXPORT_SYMBOL(tegra_powergate_remove_clamping); |
| 307 | 528 | ||
| @@ -316,35 +537,20 @@ EXPORT_SYMBOL(tegra_powergate_remove_clamping); | |||
| 316 | int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk, | 537 | int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk, |
| 317 | struct reset_control *rst) | 538 | struct reset_control *rst) |
| 318 | { | 539 | { |
| 319 | int ret; | 540 | struct tegra_powergate pg; |
| 320 | 541 | int err; | |
| 321 | reset_control_assert(rst); | ||
| 322 | |||
| 323 | ret = tegra_powergate_power_on(id); | ||
| 324 | if (ret) | ||
| 325 | goto err_power; | ||
| 326 | |||
| 327 | ret = clk_prepare_enable(clk); | ||
| 328 | if (ret) | ||
| 329 | goto err_clk; | ||
| 330 | |||
| 331 | usleep_range(10, 20); | ||
| 332 | 542 | ||
| 333 | ret = tegra_powergate_remove_clamping(id); | 543 | pg.id = id; |
| 334 | if (ret) | 544 | pg.clks = &clk; |
| 335 | goto err_clamp; | 545 | pg.num_clks = 1; |
| 546 | pg.resets = &rst; | ||
| 547 | pg.num_resets = 1; | ||
| 336 | 548 | ||
| 337 | usleep_range(10, 20); | 549 | err = tegra_powergate_power_up(&pg, false); |
| 338 | reset_control_deassert(rst); | 550 | if (err) |
| 339 | 551 | pr_err("failed to turn on partition %d: %d\n", id, err); | |
| 340 | return 0; | ||
| 341 | 552 | ||
| 342 | err_clamp: | 553 | return err; |
| 343 | clk_disable_unprepare(clk); | ||
| 344 | err_clk: | ||
| 345 | tegra_powergate_power_off(id); | ||
| 346 | err_power: | ||
| 347 | return ret; | ||
| 348 | } | 554 | } |
| 349 | EXPORT_SYMBOL(tegra_powergate_sequence_power_up); | 555 | EXPORT_SYMBOL(tegra_powergate_sequence_power_up); |
| 350 | 556 | ||
| @@ -486,6 +692,155 @@ static int tegra_powergate_debugfs_init(void) | |||
| 486 | return 0; | 692 | return 0; |
| 487 | } | 693 | } |
| 488 | 694 | ||
| 695 | static int tegra_powergate_of_get_clks(struct tegra_powergate *pg, | ||
| 696 | struct device_node *np) | ||
| 697 | { | ||
| 698 | struct clk *clk; | ||
| 699 | unsigned int i, count; | ||
| 700 | int err; | ||
| 701 | |||
| 702 | count = of_count_phandle_with_args(np, "clocks", "#clock-cells"); | ||
| 703 | if (count == 0) | ||
| 704 | return -ENODEV; | ||
| 705 | |||
| 706 | pg->clks = kcalloc(count, sizeof(clk), GFP_KERNEL); | ||
| 707 | if (!pg->clks) | ||
| 708 | return -ENOMEM; | ||
| 709 | |||
| 710 | for (i = 0; i < count; i++) { | ||
| 711 | pg->clks[i] = of_clk_get(np, i); | ||
| 712 | if (IS_ERR(pg->clks[i])) { | ||
| 713 | err = PTR_ERR(pg->clks[i]); | ||
| 714 | goto err; | ||
| 715 | } | ||
| 716 | } | ||
| 717 | |||
| 718 | pg->num_clks = count; | ||
| 719 | |||
| 720 | return 0; | ||
| 721 | |||
| 722 | err: | ||
| 723 | while (i--) | ||
| 724 | clk_put(pg->clks[i]); | ||
| 725 | kfree(pg->clks); | ||
| 726 | |||
| 727 | return err; | ||
| 728 | } | ||
| 729 | |||
| 730 | static int tegra_powergate_of_get_resets(struct tegra_powergate *pg, | ||
| 731 | struct device_node *np) | ||
| 732 | { | ||
| 733 | struct reset_control *rst; | ||
| 734 | unsigned int i, count; | ||
| 735 | int err; | ||
| 736 | |||
| 737 | count = of_count_phandle_with_args(np, "resets", "#reset-cells"); | ||
| 738 | if (count == 0) | ||
| 739 | return -ENODEV; | ||
| 740 | |||
| 741 | pg->resets = kcalloc(count, sizeof(rst), GFP_KERNEL); | ||
| 742 | if (!pg->resets) | ||
| 743 | return -ENOMEM; | ||
| 744 | |||
| 745 | for (i = 0; i < count; i++) { | ||
| 746 | pg->resets[i] = of_reset_control_get_by_index(np, i); | ||
| 747 | if (IS_ERR(pg->resets[i])) { | ||
| 748 | err = PTR_ERR(pg->resets[i]); | ||
| 749 | goto error; | ||
| 750 | } | ||
| 751 | } | ||
| 752 | |||
| 753 | pg->num_resets = count; | ||
| 754 | |||
| 755 | return 0; | ||
| 756 | |||
| 757 | error: | ||
| 758 | while (i--) | ||
| 759 | reset_control_put(pg->resets[i]); | ||
| 760 | kfree(pg->resets); | ||
| 761 | |||
| 762 | return err; | ||
| 763 | } | ||
| 764 | |||
| 765 | static void tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np) | ||
| 766 | { | ||
| 767 | struct tegra_powergate *pg; | ||
| 768 | bool off; | ||
| 769 | int id; | ||
| 770 | |||
| 771 | pg = kzalloc(sizeof(*pg), GFP_KERNEL); | ||
| 772 | if (!pg) | ||
| 773 | goto error; | ||
| 774 | |||
| 775 | id = tegra_powergate_lookup(pmc, np->name); | ||
| 776 | if (id < 0) | ||
| 777 | goto free_mem; | ||
| 778 | |||
| 779 | /* | ||
| 780 | * Clear the bit for this powergate so it cannot be managed | ||
| 781 | * directly via the legacy APIs for controlling powergates. | ||
| 782 | */ | ||
| 783 | clear_bit(id, pmc->powergates_available); | ||
| 784 | |||
| 785 | pg->id = id; | ||
| 786 | pg->genpd.name = np->name; | ||
| 787 | pg->genpd.power_off = tegra_genpd_power_off; | ||
| 788 | pg->genpd.power_on = tegra_genpd_power_on; | ||
| 789 | pg->pmc = pmc; | ||
| 790 | |||
| 791 | if (tegra_powergate_of_get_clks(pg, np)) | ||
| 792 | goto set_available; | ||
| 793 | |||
| 794 | if (tegra_powergate_of_get_resets(pg, np)) | ||
| 795 | goto remove_clks; | ||
| 796 | |||
| 797 | off = !tegra_powergate_is_powered(pg->id); | ||
| 798 | |||
| 799 | pm_genpd_init(&pg->genpd, NULL, off); | ||
| 800 | |||
| 801 | if (of_genpd_add_provider_simple(np, &pg->genpd)) | ||
| 802 | goto remove_resets; | ||
| 803 | |||
| 804 | dev_dbg(pmc->dev, "added power domain %s\n", pg->genpd.name); | ||
| 805 | |||
| 806 | return; | ||
| 807 | |||
| 808 | remove_resets: | ||
| 809 | while (pg->num_resets--) | ||
| 810 | reset_control_put(pg->resets[pg->num_resets]); | ||
| 811 | kfree(pg->resets); | ||
| 812 | |||
| 813 | remove_clks: | ||
| 814 | while (pg->num_clks--) | ||
| 815 | clk_put(pg->clks[pg->num_clks]); | ||
| 816 | kfree(pg->clks); | ||
| 817 | |||
| 818 | set_available: | ||
| 819 | set_bit(id, pmc->powergates_available); | ||
| 820 | |||
| 821 | free_mem: | ||
| 822 | kfree(pg); | ||
| 823 | |||
| 824 | error: | ||
| 825 | dev_err(pmc->dev, "failed to create power domain for %s\n", np->name); | ||
| 826 | } | ||
| 827 | |||
| 828 | static void tegra_powergate_init(struct tegra_pmc *pmc) | ||
| 829 | { | ||
| 830 | struct device_node *np, *child; | ||
| 831 | |||
| 832 | np = of_get_child_by_name(pmc->dev->of_node, "powergates"); | ||
| 833 | if (!np) | ||
| 834 | return; | ||
| 835 | |||
| 836 | for_each_child_of_node(np, child) { | ||
| 837 | tegra_powergate_add(pmc, child); | ||
| 838 | of_node_put(child); | ||
| 839 | } | ||
| 840 | |||
| 841 | of_node_put(np); | ||
| 842 | } | ||
| 843 | |||
| 489 | static int tegra_io_rail_prepare(unsigned int id, unsigned long *request, | 844 | static int tegra_io_rail_prepare(unsigned int id, unsigned long *request, |
| 490 | unsigned long *status, unsigned int *bit) | 845 | unsigned long *status, unsigned int *bit) |
| 491 | { | 846 | { |
| @@ -887,6 +1242,8 @@ static int tegra_pmc_probe(struct platform_device *pdev) | |||
| 887 | return err; | 1242 | return err; |
| 888 | } | 1243 | } |
| 889 | 1244 | ||
| 1245 | tegra_powergate_init(pmc); | ||
| 1246 | |||
| 890 | mutex_lock(&pmc->powergates_lock); | 1247 | mutex_lock(&pmc->powergates_lock); |
| 891 | iounmap(pmc->base); | 1248 | iounmap(pmc->base); |
| 892 | pmc->base = base; | 1249 | pmc->base = base; |
| @@ -1120,6 +1477,7 @@ static int __init tegra_pmc_early_init(void) | |||
| 1120 | const struct of_device_id *match; | 1477 | const struct of_device_id *match; |
| 1121 | struct device_node *np; | 1478 | struct device_node *np; |
| 1122 | struct resource regs; | 1479 | struct resource regs; |
| 1480 | unsigned int i; | ||
| 1123 | bool invert; | 1481 | bool invert; |
| 1124 | u32 value; | 1482 | u32 value; |
| 1125 | 1483 | ||
| @@ -1169,6 +1527,11 @@ static int __init tegra_pmc_early_init(void) | |||
| 1169 | return -ENXIO; | 1527 | return -ENXIO; |
| 1170 | } | 1528 | } |
| 1171 | 1529 | ||
| 1530 | /* Create a bit-map of the available and valid partitions */ | ||
| 1531 | for (i = 0; i < pmc->soc->num_powergates; i++) | ||
| 1532 | if (pmc->soc->powergates[i]) | ||
| 1533 | set_bit(i, pmc->powergates_available); | ||
| 1534 | |||
| 1172 | mutex_init(&pmc->powergates_lock); | 1535 | mutex_init(&pmc->powergates_lock); |
| 1173 | 1536 | ||
| 1174 | /* | 1537 | /* |
diff --git a/include/soc/tegra/pmc.h b/include/soc/tegra/pmc.h index 07e332dd44fb..e9e53473a63e 100644 --- a/include/soc/tegra/pmc.h +++ b/include/soc/tegra/pmc.h | |||
| @@ -72,6 +72,7 @@ int tegra_pmc_cpu_remove_clamping(unsigned int cpuid); | |||
| 72 | #define TEGRA_POWERGATE_AUD 27 | 72 | #define TEGRA_POWERGATE_AUD 27 |
| 73 | #define TEGRA_POWERGATE_DFD 28 | 73 | #define TEGRA_POWERGATE_DFD 28 |
| 74 | #define TEGRA_POWERGATE_VE2 29 | 74 | #define TEGRA_POWERGATE_VE2 29 |
| 75 | #define TEGRA_POWERGATE_MAX TEGRA_POWERGATE_VE2 | ||
| 75 | 76 | ||
| 76 | #define TEGRA_POWERGATE_3D0 TEGRA_POWERGATE_3D | 77 | #define TEGRA_POWERGATE_3D0 TEGRA_POWERGATE_3D |
| 77 | 78 | ||
