Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 1 | /* |
| 2 | * pm.c - Common OMAP2+ power management-related code |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2010 Nokia Corporation |
| 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/kernel.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/err.h> |
| 16 | |
| 17 | #include <plat/omap-pm.h> |
| 18 | #include <plat/omap_device.h> |
| 19 | #include <plat/common.h> |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 20 | #include <plat/voltage.h> |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 21 | |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 22 | #include "powerdomain.h" |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 23 | #include "clockdomain.h" |
Thara Gopinath | 0c0a5d6 | 2010-05-29 22:02:23 +0530 | [diff] [blame] | 24 | #include "pm.h" |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 25 | |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 26 | static struct omap_device_pm_latency *pm_lats; |
| 27 | |
| 28 | static struct device *mpu_dev; |
Thara Gopinath | b3294e2 | 2010-09-01 13:44:53 +0530 | [diff] [blame] | 29 | static struct device *iva_dev; |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 30 | static struct device *l3_dev; |
Thara Gopinath | b3294e2 | 2010-09-01 13:44:53 +0530 | [diff] [blame] | 31 | static struct device *dsp_dev; |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 32 | |
| 33 | struct device *omap2_get_mpuss_device(void) |
| 34 | { |
| 35 | WARN_ON_ONCE(!mpu_dev); |
| 36 | return mpu_dev; |
| 37 | } |
| 38 | |
Thara Gopinath | b3294e2 | 2010-09-01 13:44:53 +0530 | [diff] [blame] | 39 | struct device *omap2_get_iva_device(void) |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 40 | { |
Thara Gopinath | b3294e2 | 2010-09-01 13:44:53 +0530 | [diff] [blame] | 41 | WARN_ON_ONCE(!iva_dev); |
| 42 | return iva_dev; |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | struct device *omap2_get_l3_device(void) |
| 46 | { |
| 47 | WARN_ON_ONCE(!l3_dev); |
| 48 | return l3_dev; |
| 49 | } |
| 50 | |
Thara Gopinath | b3294e2 | 2010-09-01 13:44:53 +0530 | [diff] [blame] | 51 | struct device *omap4_get_dsp_device(void) |
| 52 | { |
| 53 | WARN_ON_ONCE(!dsp_dev); |
| 54 | return dsp_dev; |
| 55 | } |
| 56 | EXPORT_SYMBOL(omap4_get_dsp_device); |
| 57 | |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 58 | /* static int _init_omap_device(struct omap_hwmod *oh, void *user) */ |
| 59 | static int _init_omap_device(char *name, struct device **new_dev) |
| 60 | { |
| 61 | struct omap_hwmod *oh; |
| 62 | struct omap_device *od; |
| 63 | |
| 64 | oh = omap_hwmod_lookup(name); |
| 65 | if (WARN(!oh, "%s: could not find omap_hwmod for %s\n", |
| 66 | __func__, name)) |
| 67 | return -ENODEV; |
| 68 | |
| 69 | od = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false); |
| 70 | if (WARN(IS_ERR(od), "%s: could not build omap_device for %s\n", |
| 71 | __func__, name)) |
| 72 | return -ENODEV; |
| 73 | |
| 74 | *new_dev = &od->pdev.dev; |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Build omap_devices for processors and bus. |
| 81 | */ |
| 82 | static void omap2_init_processor_devices(void) |
| 83 | { |
| 84 | _init_omap_device("mpu", &mpu_dev); |
Thara Gopinath | b3294e2 | 2010-09-01 13:44:53 +0530 | [diff] [blame] | 85 | _init_omap_device("iva", &iva_dev); |
Benoit Cousson | cbf2766 | 2010-08-05 15:22:35 +0200 | [diff] [blame] | 86 | if (cpu_is_omap44xx()) { |
| 87 | _init_omap_device("l3_main_1", &l3_dev); |
Thara Gopinath | b3294e2 | 2010-09-01 13:44:53 +0530 | [diff] [blame] | 88 | _init_omap_device("dsp", &dsp_dev); |
Benoit Cousson | cbf2766 | 2010-08-05 15:22:35 +0200 | [diff] [blame] | 89 | } else { |
| 90 | _init_omap_device("l3_main", &l3_dev); |
| 91 | } |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 94 | /* Types of sleep_switch used in omap_set_pwrdm_state */ |
| 95 | #define FORCEWAKEUP_SWITCH 0 |
| 96 | #define LOWPOWERSTATE_SWITCH 1 |
| 97 | |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 98 | /* |
| 99 | * This sets pwrdm state (other than mpu & core. Currently only ON & |
Rajendra Nayak | 33de32b | 2010-12-21 22:37:28 -0700 | [diff] [blame] | 100 | * RET are supported. |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 101 | */ |
| 102 | int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state) |
| 103 | { |
| 104 | u32 cur_state; |
| 105 | int sleep_switch = 0; |
| 106 | int ret = 0; |
| 107 | |
| 108 | if (pwrdm == NULL || IS_ERR(pwrdm)) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | while (!(pwrdm->pwrsts & (1 << state))) { |
| 112 | if (state == PWRDM_POWER_OFF) |
| 113 | return ret; |
| 114 | state--; |
| 115 | } |
| 116 | |
| 117 | cur_state = pwrdm_read_next_pwrst(pwrdm); |
| 118 | if (cur_state == state) |
| 119 | return ret; |
| 120 | |
| 121 | if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) { |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 122 | if ((pwrdm_read_pwrst(pwrdm) > state) && |
| 123 | (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) { |
| 124 | sleep_switch = LOWPOWERSTATE_SWITCH; |
| 125 | } else { |
| 126 | omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]); |
| 127 | pwrdm_wait_transition(pwrdm); |
| 128 | sleep_switch = FORCEWAKEUP_SWITCH; |
| 129 | } |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | ret = pwrdm_set_next_pwrst(pwrdm, state); |
| 133 | if (ret) { |
| 134 | printk(KERN_ERR "Unable to set state of powerdomain: %s\n", |
| 135 | pwrdm->name); |
| 136 | goto err; |
| 137 | } |
| 138 | |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 139 | switch (sleep_switch) { |
| 140 | case FORCEWAKEUP_SWITCH: |
Rajendra Nayak | 33de32b | 2010-12-21 22:37:28 -0700 | [diff] [blame] | 141 | if (pwrdm->pwrdm_clkdms[0]->flags & CLKDM_CAN_ENABLE_AUTO) |
| 142 | omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]); |
| 143 | else |
| 144 | omap2_clkdm_sleep(pwrdm->pwrdm_clkdms[0]); |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 145 | break; |
| 146 | case LOWPOWERSTATE_SWITCH: |
| 147 | pwrdm_set_lowpwrstchange(pwrdm); |
| 148 | break; |
| 149 | default: |
| 150 | return ret; |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 151 | } |
| 152 | |
Rajendra Nayak | 71a488d | 2010-12-21 22:37:27 -0700 | [diff] [blame] | 153 | pwrdm_wait_transition(pwrdm); |
| 154 | pwrdm_state_switch(pwrdm); |
Santosh Shilimkar | eb6a2c7 | 2010-09-15 01:04:01 +0530 | [diff] [blame] | 155 | err: |
| 156 | return ret; |
| 157 | } |
| 158 | |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 159 | static int __init omap2_common_pm_init(void) |
| 160 | { |
| 161 | omap2_init_processor_devices(); |
| 162 | omap_pm_if_init(); |
| 163 | |
| 164 | return 0; |
| 165 | } |
Thara Gopinath | 1cbbe37 | 2010-12-20 21:17:21 +0530 | [diff] [blame] | 166 | postcore_initcall(omap2_common_pm_init); |
Kevin Hilman | 6f88e9b | 2010-07-26 16:34:31 -0600 | [diff] [blame] | 167 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 168 | static int __init omap2_common_pm_late_init(void) |
| 169 | { |
Thara Gopinath | fbc319f | 2010-12-10 22:51:05 +0530 | [diff] [blame^] | 170 | /* Init the OMAP TWL parameters */ |
| 171 | omap3_twl_init(); |
| 172 | /* Init the voltage layer */ |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 173 | omap_voltage_late_init(); |
Thara Gopinath | fbc319f | 2010-12-10 22:51:05 +0530 | [diff] [blame^] | 174 | /* Smartreflex device init */ |
Thara Gopinath | 0c0a5d6 | 2010-05-29 22:02:23 +0530 | [diff] [blame] | 175 | omap_devinit_smartreflex(); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | late_initcall(omap2_common_pm_late_init); |