Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP4 Power Management Routines |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments, Inc. |
| 5 | * Rajendra Nayak <rnayak@ti.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/pm.h> |
| 13 | #include <linux/suspend.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/list.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/slab.h> |
| 18 | |
Tony Lindgren | 4e65331 | 2011-11-10 22:45:17 +0100 | [diff] [blame] | 19 | #include "common.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 20 | #include "powerdomain.h" |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 21 | |
| 22 | struct power_state { |
| 23 | struct powerdomain *pwrdm; |
| 24 | u32 next_state; |
| 25 | #ifdef CONFIG_SUSPEND |
| 26 | u32 saved_state; |
| 27 | #endif |
| 28 | struct list_head node; |
| 29 | }; |
| 30 | |
| 31 | static LIST_HEAD(pwrst_list); |
| 32 | |
| 33 | #ifdef CONFIG_SUSPEND |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 34 | static int omap4_pm_suspend(void) |
| 35 | { |
| 36 | do_wfi(); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int omap4_pm_enter(suspend_state_t suspend_state) |
| 41 | { |
| 42 | int ret = 0; |
| 43 | |
| 44 | switch (suspend_state) { |
| 45 | case PM_SUSPEND_STANDBY: |
| 46 | case PM_SUSPEND_MEM: |
| 47 | ret = omap4_pm_suspend(); |
| 48 | break; |
| 49 | default: |
| 50 | ret = -EINVAL; |
| 51 | } |
| 52 | |
| 53 | return ret; |
| 54 | } |
| 55 | |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 56 | static int omap4_pm_begin(suspend_state_t state) |
| 57 | { |
Jean Pihet | c166381 | 2010-12-09 18:39:58 +0100 | [diff] [blame] | 58 | disable_hlt(); |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static void omap4_pm_end(void) |
| 63 | { |
Jean Pihet | c166381 | 2010-12-09 18:39:58 +0100 | [diff] [blame] | 64 | enable_hlt(); |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 68 | static const struct platform_suspend_ops omap_pm_ops = { |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 69 | .begin = omap4_pm_begin, |
| 70 | .end = omap4_pm_end, |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 71 | .enter = omap4_pm_enter, |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 72 | .valid = suspend_valid_only_mem, |
| 73 | }; |
| 74 | #endif /* CONFIG_SUSPEND */ |
| 75 | |
| 76 | static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused) |
| 77 | { |
| 78 | struct power_state *pwrst; |
| 79 | |
| 80 | if (!pwrdm->pwrsts) |
| 81 | return 0; |
| 82 | |
| 83 | pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC); |
| 84 | if (!pwrst) |
| 85 | return -ENOMEM; |
| 86 | pwrst->pwrdm = pwrdm; |
| 87 | pwrst->next_state = PWRDM_POWER_ON; |
| 88 | list_add(&pwrst->node, &pwrst_list); |
| 89 | |
| 90 | return pwrdm_set_next_pwrst(pwrst->pwrdm, pwrst->next_state); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * omap4_pm_init - Init routine for OMAP4 PM |
| 95 | * |
| 96 | * Initializes all powerdomain and clockdomain target states |
| 97 | * and all PRCM settings. |
| 98 | */ |
| 99 | static int __init omap4_pm_init(void) |
| 100 | { |
| 101 | int ret; |
Santosh Shilimkar | 12f2782 | 2011-03-08 18:24:30 +0530 | [diff] [blame^] | 102 | struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm; |
| 103 | struct clockdomain *ducati_clkdm, *l3_2_clkdm, *l4_per_clkdm; |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 104 | |
| 105 | if (!cpu_is_omap44xx()) |
| 106 | return -ENODEV; |
| 107 | |
| 108 | pr_err("Power Management for TI OMAP4.\n"); |
| 109 | |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 110 | ret = pwrdm_for_each(pwrdms_setup, NULL); |
| 111 | if (ret) { |
| 112 | pr_err("Failed to setup powerdomains\n"); |
| 113 | goto err2; |
| 114 | } |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 115 | |
Santosh Shilimkar | 12f2782 | 2011-03-08 18:24:30 +0530 | [diff] [blame^] | 116 | /* |
| 117 | * The dynamic dependency between MPUSS -> MEMIF and |
| 118 | * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as |
| 119 | * expected. The hardware recommendation is to enable static |
| 120 | * dependencies for these to avoid system lock ups or random crashes. |
| 121 | */ |
| 122 | mpuss_clkdm = clkdm_lookup("mpuss_clkdm"); |
| 123 | emif_clkdm = clkdm_lookup("l3_emif_clkdm"); |
| 124 | l3_1_clkdm = clkdm_lookup("l3_1_clkdm"); |
| 125 | l3_2_clkdm = clkdm_lookup("l3_2_clkdm"); |
| 126 | l4_per_clkdm = clkdm_lookup("l4_per_clkdm"); |
| 127 | ducati_clkdm = clkdm_lookup("ducati_clkdm"); |
| 128 | if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) || |
| 129 | (!l3_2_clkdm) || (!ducati_clkdm) || (!l4_per_clkdm)) |
| 130 | goto err2; |
| 131 | |
| 132 | ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm); |
| 133 | ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm); |
| 134 | ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm); |
| 135 | ret |= clkdm_add_wkdep(mpuss_clkdm, l4_per_clkdm); |
| 136 | ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm); |
| 137 | ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm); |
| 138 | if (ret) { |
| 139 | pr_err("Failed to add MPUSS -> L3/EMIF/L4PER, DUCATI -> L3 " |
| 140 | "wakeup dependency\n"); |
| 141 | goto err2; |
| 142 | } |
| 143 | |
Rajendra Nayak | 5643aeb | 2010-08-02 13:18:18 +0300 | [diff] [blame] | 144 | #ifdef CONFIG_SUSPEND |
| 145 | suspend_set_ops(&omap_pm_ops); |
| 146 | #endif /* CONFIG_SUSPEND */ |
| 147 | |
| 148 | err2: |
| 149 | return ret; |
| 150 | } |
| 151 | late_initcall(omap4_pm_init); |