summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIliyan Malchev <malchev@google.com>2010-12-06 18:23:21 -0800
committerIliyan Malchev <malchev@google.com>2010-12-06 18:23:21 -0800
commit5b08d0855dbe1d291e1e3b7df1d3de9f8fdf9c7e (patch)
tree85ceba4c41b38f04340bdbdaf2a5b24dc14897be
parent8df654ec268e468cf5ee5736f576c9fdbe26c0c1 (diff)
parentd65dc80617985756a63f13c73e276a36d1f55d2d (diff)
Merge remote branch 'tegra/linux-tegra-2.6.36' into android-tegra-2.6.36
-rw-r--r--arch/arm/mach-tegra/board-ventana.c2
-rw-r--r--arch/arm/mach-tegra/cpu-tegra.c152
-rw-r--r--arch/arm/mach-tegra/tegra_i2s_audio.c7
-rw-r--r--arch/arm/mach-tegra/tegra_spdif_audio.c22
-rw-r--r--drivers/regulator/tps6586x-regulator.c33
-rw-r--r--drivers/usb/host/ehci-tegra.c12
-rw-r--r--drivers/video/tegra/host/dev.c21
-rw-r--r--drivers/video/tegra/host/nvhost_channel.c4
-rw-r--r--drivers/video/tegra/host/nvhost_intr.c17
9 files changed, 243 insertions, 27 deletions
diff --git a/arch/arm/mach-tegra/board-ventana.c b/arch/arm/mach-tegra/board-ventana.c
index 7c1dd3b769a9..f609c6c11418 100644
--- a/arch/arm/mach-tegra/board-ventana.c
+++ b/arch/arm/mach-tegra/board-ventana.c
@@ -181,7 +181,7 @@ static void ventana_i2c_init(void)
}
static struct gpio_keys_button ventana_keys[] = {
- [0] = GPIO_KEY(KEY_MENU, PQ0, 0),
+ [0] = GPIO_KEY(KEY_MENU, PQ3, 0),
[1] = GPIO_KEY(KEY_HOME, PQ1, 0),
[2] = GPIO_KEY(KEY_BACK, PQ2, 0),
[3] = GPIO_KEY(KEY_VOLUMEUP, PQ5, 0),
diff --git a/arch/arm/mach-tegra/cpu-tegra.c b/arch/arm/mach-tegra/cpu-tegra.c
index 035e1bc31462..1be794d015cf 100644
--- a/arch/arm/mach-tegra/cpu-tegra.c
+++ b/arch/arm/mach-tegra/cpu-tegra.c
@@ -29,6 +29,7 @@
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/suspend.h>
+#include <linux/debugfs.h>
#include <asm/smp_twd.h>
#include <asm/system.h>
@@ -36,7 +37,7 @@
#include <mach/hardware.h>
#include <mach/clk.h>
-/* Frequency table index must be sequential starting at 0 */
+/* Frequency table index must be sequential starting at 0 and frequencies must be ascending*/
static struct cpufreq_frequency_table freq_table[] = {
{ 0, 216000 },
{ 1, 312000 },
@@ -49,14 +50,27 @@ static struct cpufreq_frequency_table freq_table[] = {
{ 8, CPUFREQ_TABLE_END },
};
+/* CPU frequency is gradually lowered when throttling is enabled */
+#define THROTTLE_START_INDEX 2
+#define THROTTLE_END_INDEX 6
+#define THROTTLE_DELAY msecs_to_jiffies(2000)
+#define NO_DELAY msecs_to_jiffies(0)
+
#define NUM_CPUS 2
static struct clk *cpu_clk;
+static struct workqueue_struct *workqueue;
+
static unsigned long target_cpu_speed[NUM_CPUS];
static DEFINE_MUTEX(tegra_cpu_lock);
static bool is_suspended;
+static DEFINE_MUTEX(throttling_lock);
+static bool is_throttling;
+static struct delayed_work throttle_work;
+
+
int tegra_verify_speed(struct cpufreq_policy *policy)
{
return cpufreq_frequency_table_verify(policy, freq_table);
@@ -143,6 +157,8 @@ static int tegra_target(struct cpufreq_policy *policy,
{
int idx;
unsigned int freq;
+ unsigned int highest_speed;
+ unsigned int limit_when_throttling;
int ret = 0;
mutex_lock(&tegra_cpu_lock);
@@ -159,13 +175,137 @@ static int tegra_target(struct cpufreq_policy *policy,
target_cpu_speed[policy->cpu] = freq;
- ret = tegra_update_cpu_speed(tegra_cpu_highest_speed());
+ highest_speed = tegra_cpu_highest_speed();
+ /* Do not go above this frequency when throttling */
+ limit_when_throttling = freq_table[THROTTLE_START_INDEX].frequency;
+
+ if (is_throttling && highest_speed > limit_when_throttling) {
+ if (tegra_getspeed(0) < limit_when_throttling) {
+ ret = tegra_update_cpu_speed(limit_when_throttling);
+ goto out;
+ } else {
+ ret = -EBUSY;
+ goto out;
+ }
+ }
+
+ ret = tegra_update_cpu_speed(highest_speed);
out:
mutex_unlock(&tegra_cpu_lock);
return ret;
}
+static bool tegra_throttling_needed(unsigned long *rate)
+{
+ unsigned int current_freq = tegra_getspeed(0);
+ int i;
+
+ for (i = THROTTLE_END_INDEX; i >= THROTTLE_START_INDEX; i--) {
+ if (freq_table[i].frequency < current_freq) {
+ *rate = freq_table[i].frequency;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static void tegra_throttle_work_func(struct work_struct *work)
+{
+ unsigned long rate;
+
+ mutex_lock(&tegra_cpu_lock);
+
+ if (tegra_throttling_needed(&rate) && tegra_update_cpu_speed(rate) == 0) {
+ queue_delayed_work(workqueue, &throttle_work, THROTTLE_DELAY);
+ }
+
+ mutex_unlock(&tegra_cpu_lock);
+}
+
+/**
+ * tegra_throttling_enable
+ * This functions may sleep
+ */
+void tegra_throttling_enable(void)
+{
+ mutex_lock(&throttling_lock);
+
+ if (!is_throttling) {
+ is_throttling = true;
+ queue_delayed_work(workqueue, &throttle_work, NO_DELAY);
+ }
+
+ mutex_unlock(&throttling_lock);
+}
+EXPORT_SYMBOL_GPL(tegra_throttling_enable);
+
+/**
+ * tegra_throttling_disable
+ * This functions may sleep
+ */
+void tegra_throttling_disable(void)
+{
+ mutex_lock(&throttling_lock);
+
+ if (is_throttling) {
+ cancel_delayed_work_sync(&throttle_work);
+ is_throttling = false;
+ }
+
+ mutex_unlock(&throttling_lock);
+}
+EXPORT_SYMBOL_GPL(tegra_throttling_disable);
+
+#ifdef CONFIG_DEBUG_FS
+static int throttle_debug_set(void *data, u64 val)
+{
+ if (val) {
+ tegra_throttling_enable();
+ } else {
+ tegra_throttling_disable();
+ }
+
+ return 0;
+}
+static int throttle_debug_get(void *data, u64 *val)
+{
+ *val = (u64) is_throttling;
+ return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(throttle_fops, throttle_debug_get, throttle_debug_set, "%llu\n");
+
+static struct dentry *cpu_tegra_debugfs_root;
+
+static int __init tegra_cpu_debug_init(void)
+{
+ cpu_tegra_debugfs_root = debugfs_create_dir("cpu-tegra", 0);
+
+ if (!cpu_tegra_debugfs_root)
+ return -ENOMEM;
+
+ if (!debugfs_create_file("throttle", 0644, cpu_tegra_debugfs_root, NULL, &throttle_fops))
+ goto err_out;
+
+ return 0;
+
+err_out:
+ debugfs_remove_recursive(cpu_tegra_debugfs_root);
+ return -ENOMEM;
+
+}
+
+static void __exit tegra_cpu_debug_exit(void)
+{
+ debugfs_remove_recursive(cpu_tegra_debugfs_root);
+}
+
+late_initcall(tegra_cpu_debug_init);
+module_exit(tegra_cpu_debug_exit);
+#endif
+
static int tegra_pm_notify(struct notifier_block *nb, unsigned long event,
void *dummy)
{
@@ -207,8 +347,10 @@ static int tegra_cpu_init(struct cpufreq_policy *policy)
policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
cpumask_copy(policy->related_cpus, cpu_possible_mask);
- if (policy->cpu == 0)
+ if (policy->cpu == 0) {
+ INIT_DELAYED_WORK(&throttle_work, tegra_throttle_work_func);
register_pm_notifier(&tegra_cpu_pm_notifier);
+ }
return 0;
}
@@ -237,11 +379,15 @@ static struct cpufreq_driver tegra_cpufreq_driver = {
static int __init tegra_cpufreq_init(void)
{
+ workqueue = create_singlethread_workqueue("cpu-tegra");
+ if (!workqueue)
+ return -ENOMEM;
return cpufreq_register_driver(&tegra_cpufreq_driver);
}
static void __exit tegra_cpufreq_exit(void)
{
+ destroy_workqueue(workqueue);
cpufreq_unregister_driver(&tegra_cpufreq_driver);
}
diff --git a/arch/arm/mach-tegra/tegra_i2s_audio.c b/arch/arm/mach-tegra/tegra_i2s_audio.c
index 77fb3df0ec71..f3cd2c42278e 100644
--- a/arch/arm/mach-tegra/tegra_i2s_audio.c
+++ b/arch/arm/mach-tegra/tegra_i2s_audio.c
@@ -695,12 +695,17 @@ static void request_stop_nosync(struct audio_stream *as)
pr_debug("%s\n", __func__);
if (!as->stop) {
as->stop = true;
- wait_till_stopped(as);
+ if (pending_buffer_requests(as))
+ wait_till_stopped(as);
for (i = 0; i < as->num_bufs; i++) {
init_completion(&as->comp[i]);
complete(&as->comp[i]);
}
}
+ if (!tegra_dma_is_empty(as->dma_chan))
+ pr_err("%s: DMA not empty!\n", __func__);
+ /* Stop the DMA then dequeue anything that's in progress. */
+ tegra_dma_cancel(as->dma_chan);
as->active = false; /* applies to recording only */
pr_debug("%s: done\n", __func__);
}
diff --git a/arch/arm/mach-tegra/tegra_spdif_audio.c b/arch/arm/mach-tegra/tegra_spdif_audio.c
index 0848b1550dfe..6613d3d5edeb 100644
--- a/arch/arm/mach-tegra/tegra_spdif_audio.c
+++ b/arch/arm/mach-tegra/tegra_spdif_audio.c
@@ -460,12 +460,17 @@ static void request_stop_nosync(struct audio_stream *as)
pr_debug("%s\n", __func__);
if (!as->stop) {
as->stop = true;
- wait_till_stopped(as);
+ if (pending_buffer_requests(as))
+ wait_till_stopped(as);
for (i = 0; i < as->num_bufs; i++) {
init_completion(&as->comp[i]);
complete(&as->comp[i]);
}
}
+ if (!tegra_dma_is_empty(as->dma_chan))
+ pr_err("%s: DMA not empty!\n", __func__);
+ /* Stop the DMA then dequeue anything that's in progress. */
+ tegra_dma_cancel(as->dma_chan);
as->active = false; /* applies to recording only */
pr_debug("%s: done\n", __func__);
}
@@ -543,13 +548,9 @@ static void dma_tx_complete_callback(struct tegra_dma_req *req)
complete(&aos->comp[req_num]);
- if (stop_playback_if_necessary(aos)) {
- pr_debug("%s: done (stopped)\n", __func__);
- if (!completion_done(&aos->stop_completion)) {
- pr_debug("%s: signalling stop completion\n", __func__);
- complete(&aos->stop_completion);
- }
- return;
+ if (!pending_buffer_requests(aos)) {
+ pr_debug("%s: Playback underflow", __func__);
+ complete(&aos->stop_completion);
}
}
@@ -729,6 +730,8 @@ static long tegra_spdif_out_ioctl(struct file *file,
request_stop_nosync(aos);
pr_debug("%s: flushed\n", __func__);
}
+ if (stop_playback_if_necessary(aos))
+ pr_debug("%s: done (stopped)\n", __func__);
aos->stop = false;
break;
case TEGRA_AUDIO_OUT_SET_NUM_BUFS: {
@@ -752,6 +755,7 @@ static long tegra_spdif_out_ioctl(struct file *file,
if (rc < 0)
break;
aos->num_bufs = num;
+ sound_ops->setup(ads);
}
break;
case TEGRA_AUDIO_OUT_GET_NUM_BUFS:
@@ -806,6 +810,8 @@ static int tegra_spdif_out_release(struct inode *inode, struct file *file)
mutex_lock(&ads->out.lock);
ads->out.opened = 0;
request_stop_nosync(&ads->out);
+ if (stop_playback_if_necessary(&ads->out))
+ pr_debug("%s: done (stopped)\n", __func__);
allow_suspend(&ads->out);
mutex_unlock(&ads->out.lock);
pr_debug("%s: done\n", __func__);
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 51237fbb1bbb..6d20b0454a1d 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -231,8 +231,7 @@ static int tps6586x_dvm_voltages[] = {
};
#define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits, \
- ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
-{ \
+ ereg0, ebit0, ereg1, ebit1) \
.desc = { \
.name = "REG-" #_id, \
.ops = &tps6586x_regulator_##_ops, \
@@ -248,18 +247,26 @@ static int tps6586x_dvm_voltages[] = {
.enable_bit[0] = (ebit0), \
.enable_reg[1] = TPS6586X_SUPPLY##ereg1, \
.enable_bit[1] = (ebit1), \
- .voltages = tps6586x_##vdata##_voltages, \
-}
+ .voltages = tps6586x_##vdata##_voltages,
+
+#define TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \
+ .go_reg = TPS6586X_##goreg, \
+ .go_bit = (gobit),
#define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \
ereg0, ebit0, ereg1, ebit1) \
+{ \
TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits, \
- ereg0, ebit0, ereg1, ebit1, 0, 0)
+ ereg0, ebit0, ereg1, ebit1) \
+}
#define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \
ereg0, ebit0, ereg1, ebit1, goreg, gobit) \
+{ \
TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits, \
- ereg0, ebit0, ereg1, ebit1, goreg, gobit)
+ ereg0, ebit0, ereg1, ebit1) \
+ TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \
+}
static struct tps6586x_regulator tps6586x_regulator[] = {
TPS6586X_LDO(LDO_0, ldo, SUPPLYV1, 5, 3, ENC, 0, END, 0),
@@ -267,11 +274,11 @@ static struct tps6586x_regulator tps6586x_regulator[] = {
TPS6586X_LDO(LDO_5, ldo, SUPPLYV6, 0, 3, ENE, 6, ENE, 6),
TPS6586X_LDO(LDO_6, ldo, SUPPLYV3, 0, 3, ENC, 4, END, 4),
TPS6586X_LDO(LDO_7, ldo, SUPPLYV3, 3, 3, ENC, 5, END, 5),
- TPS6586X_LDO(LDO_8, ldo, SUPPLYV1, 5, 3, ENC, 6, END, 6),
+ TPS6586X_LDO(LDO_8, ldo, SUPPLYV2, 5, 3, ENC, 6, END, 6),
TPS6586X_LDO(LDO_9, ldo, SUPPLYV6, 3, 3, ENE, 7, ENE, 7),
- TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, ENE, 7, ENE, 7),
+ TPS6586X_LDO(LDO_RTC, ldo, SUPPLYV4, 3, 3, V4, 7, V4, 7),
TPS6586X_LDO(LDO_1, dvm, SUPPLYV1, 0, 5, ENC, 1, END, 1),
- TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 1, END, 1),
+ TPS6586X_LDO(SM_2, sm2, SUPPLYV2, 0, 5, ENC, 7, END, 7),
TPS6586X_DVM(LDO_2, dvm, LDO2BV1, 0, 5, ENA, 3, ENB, 3, VCC2, 6),
TPS6586X_DVM(LDO_4, ldo4, LDO4V1, 0, 5, ENC, 3, END, 3, VCC1, 6),
@@ -290,6 +297,10 @@ static inline int tps6586x_regulator_preinit(struct device *parent,
uint8_t val1, val2;
int ret;
+ if (ri->enable_reg[0] == ri->enable_reg[1] &&
+ ri->enable_bit[0] == ri->enable_bit[1])
+ return 0;
+
ret = tps6586x_read(parent, ri->enable_reg[0], &val1);
if (ret)
return ret;
@@ -298,14 +309,14 @@ static inline int tps6586x_regulator_preinit(struct device *parent,
if (ret)
return ret;
- if (!(val2 & ri->enable_bit[1]))
+ if (!(val2 & (1 << ri->enable_bit[1])))
return 0;
/*
* The regulator is on, but it's enabled with the bit we don't
* want to use, so we switch the enable bits
*/
- if (!(val1 & ri->enable_bit[0])) {
+ if (!(val1 & (1 << ri->enable_bit[0]))) {
ret = tps6586x_set_bits(parent, ri->enable_reg[0],
1 << ri->enable_bit[0]);
if (ret)
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 5cdad2531ba1..b02eabb5a61d 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -286,6 +286,18 @@ static int tegra_usb_resume(struct usb_hcd *hcd)
writel(val, &hw->port_status[0]);
udelay(10);
+ /* Program the field PTC in PORTSC based on the saved speed mode */
+ val = readl(&hw->port_status[0]);
+ val &= ~(TEGRA_USB_PORTSC1_PTC(~0));
+ if (context->port_speed == TEGRA_USB_PHY_PORT_HIGH)
+ val |= TEGRA_USB_PORTSC1_PTC(5);
+ else if (context->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL)
+ val |= TEGRA_USB_PORTSC1_PTC(6);
+ else if (context->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
+ val |= TEGRA_USB_PORTSC1_PTC(7);
+ writel(val, &hw->port_status[0]);
+ udelay(10);
+
/* Disable test mode by setting PTC field to NORMAL_OP */
val = readl(&hw->port_status[0]);
val &= ~(TEGRA_USB_PORTSC1_PTC(~0));
diff --git a/drivers/video/tegra/host/dev.c b/drivers/video/tegra/host/dev.c
index 42d268e7da59..20a4eda0fb53 100644
--- a/drivers/video/tegra/host/dev.c
+++ b/drivers/video/tegra/host/dev.c
@@ -30,6 +30,7 @@
#include <linux/platform_device.h>
#include <linux/uaccess.h>
#include <linux/file.h>
+#include <linux/clk.h>
#include <asm/io.h>
@@ -574,7 +575,6 @@ static void power_host(struct nvhost_module *mod, enum nvhost_power_action actio
if (action == NVHOST_POWER_ACTION_ON) {
nvhost_intr_configure(&dev->intr, clk_get_rate(mod->clk[0]));
- nvhost_syncpt_reset(&dev->syncpt);
}
else if (action == NVHOST_POWER_ACTION_OFF) {
int i;
@@ -713,6 +713,10 @@ static int __devinit nvhost_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, host);
+ clk_enable(host->mod.clk[0]);
+ nvhost_syncpt_reset(&host->syncpt);
+ clk_disable(host->mod.clk[0]);
+
nvhost_bus_register(host);
nvhost_debug_init(host);
@@ -738,13 +742,28 @@ static int nvhost_suspend(struct platform_device *pdev, pm_message_t state)
struct nvhost_master *host = platform_get_drvdata(pdev);
dev_info(&pdev->dev, "suspending\n");
nvhost_module_suspend(&host->mod);
+ clk_enable(host->mod.clk[0]);
+ nvhost_syncpt_save(&host->syncpt);
+ clk_disable(host->mod.clk[0]);
dev_info(&pdev->dev, "suspended\n");
return 0;
}
+static int nvhost_resume(struct platform_device *pdev)
+{
+ struct nvhost_master *host = platform_get_drvdata(pdev);
+ dev_info(&pdev->dev, "resuming\n");
+ clk_enable(host->mod.clk[0]);
+ nvhost_syncpt_reset(&host->syncpt);
+ clk_disable(host->mod.clk[0]);
+ dev_info(&pdev->dev, "resumed\n");
+ return 0;
+}
+
static struct platform_driver nvhost_driver = {
.remove = __exit_p(nvhost_remove),
.suspend = nvhost_suspend,
+ .resume = nvhost_resume,
.driver = {
.owner = THIS_MODULE,
.name = DRIVER_NAME
diff --git a/drivers/video/tegra/host/nvhost_channel.c b/drivers/video/tegra/host/nvhost_channel.c
index 80c0f877618e..40b67181c33d 100644
--- a/drivers/video/tegra/host/nvhost_channel.c
+++ b/drivers/video/tegra/host/nvhost_channel.c
@@ -214,6 +214,7 @@ static void power_3d(struct nvhost_module *mod, enum nvhost_power_action action)
struct nvhost_op_pair save;
struct nvhost_cpuinterrupt ctxsw;
u32 syncval;
+ void *ref;
syncval = nvhost_syncpt_incr_max(&ch->dev->syncpt,
NVSYNCPT_3D,
ch->cur_ctx->save_incrs);
@@ -232,10 +233,11 @@ static void power_3d(struct nvhost_module *mod, enum nvhost_power_action action)
nvhost_intr_add_action(&ch->dev->intr, NVSYNCPT_3D,
syncval,
NVHOST_INTR_ACTION_WAKEUP,
- &wq, NULL);
+ &wq, &ref);
wait_event(wq,
nvhost_syncpt_min_cmp(&ch->dev->syncpt,
NVSYNCPT_3D, syncval));
+ nvhost_intr_put_ref(&ch->dev->intr, ref);
nvhost_cdma_update(&ch->cdma);
}
mutex_unlock(&ch->submitlock);
diff --git a/drivers/video/tegra/host/nvhost_intr.c b/drivers/video/tegra/host/nvhost_intr.c
index 795736f58b86..848d8b1e84e0 100644
--- a/drivers/video/tegra/host/nvhost_intr.c
+++ b/drivers/video/tegra/host/nvhost_intr.c
@@ -418,9 +418,24 @@ void nvhost_intr_deinit(struct nvhost_intr *intr)
for (id = 0, syncpt = intr->syncpt;
id < NV_HOST1X_SYNCPT_NB_PTS;
- ++id, ++syncpt)
+ ++id, ++syncpt) {
+ struct nvhost_waitlist *waiter, *next;
+ list_for_each_entry_safe(waiter, next, &syncpt->wait_head, list) {
+ if (atomic_cmpxchg(&waiter->state, WLS_CANCELLED, WLS_HANDLED)
+ == WLS_CANCELLED) {
+ list_del(&waiter->list);
+ kref_put(&waiter->refcount, waiter_release);
+ }
+ }
+
+ if(!list_empty(&syncpt->wait_head)) { // output diagnostics
+ printk("%s id=%d\n",__func__,id);
+ BUG_ON(1);
+ }
+
if (syncpt->irq_requested)
free_irq(syncpt->irq, syncpt);
+ }
if (intr->host1x_isr_started) {
free_irq(intr->host1x_irq, intr);