Skip to content

Commit

Permalink
PM/devfreq: Do not switch governors from sysfs when device is suspended
Browse files Browse the repository at this point in the history
There is a possibility to switch the governors from sysfs even when the
device is in suspended state. This can cause a NOC error at times when
trying to access the device's monitor registers in a suspended state. This
change fixes this issue. Introduce a variable dev_suspended to know if
the device is in suspended state or not. Check if the device is suspended
before switching the governor from sysfs.

Change-Id: I15055aa51daa35272be4667e5bafb8ccd7933098
Signed-off-by: Rama Aparna Mallavarapu <aparnam@codeaurora.org>
  • Loading branch information
Rama Aparna Mallavarapu authored and linckandrea committed Dec 21, 2024
1 parent 9796cbd commit 989ed3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
21 changes: 17 additions & 4 deletions drivers/devfreq/devfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
devfreq->last_status.current_frequency = profile->initial_freq;
devfreq->data = data;
devfreq->nb.notifier_call = devfreq_notifier_call;
devfreq->dev_suspended = false;

if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
mutex_unlock(&devfreq->lock);
Expand Down Expand Up @@ -789,12 +790,16 @@ int devfreq_suspend_device(struct devfreq *devfreq)
if (!devfreq)
return -EINVAL;

if (!devfreq->governor)
mutex_lock(&devfreq->event_lock);
if (!devfreq->governor || devfreq->dev_suspended) {
mutex_unlock(&devfreq->event_lock);
return 0;
}

mutex_lock(&devfreq->event_lock);
ret = devfreq->governor->event_handler(devfreq,
DEVFREQ_GOV_SUSPEND, NULL);
if (!ret)
devfreq->dev_suspended = true;
mutex_unlock(&devfreq->event_lock);
return ret;
}
Expand All @@ -815,12 +820,16 @@ int devfreq_resume_device(struct devfreq *devfreq)
if (!devfreq)
return -EINVAL;

if (!devfreq->governor)
mutex_lock(&devfreq->event_lock);
if (!devfreq->governor) {
mutex_unlock(&devfreq->event_lock);
return 0;
}

mutex_lock(&devfreq->event_lock);
ret = devfreq->governor->event_handler(devfreq,
DEVFREQ_GOV_RESUME, NULL);
if (!ret)
devfreq->dev_suspended = false;
mutex_unlock(&devfreq->event_lock);
return ret;
}
Expand Down Expand Up @@ -983,6 +992,10 @@ static ssize_t governor_store(struct device *dev, struct device_attribute *attr,
}

mutex_lock(&df->event_lock);
if (df->dev_suspended) {
ret = -EINVAL;
goto gov_stop_out;
}
if (df->governor) {
ret = df->governor->event_handler(df, DEVFREQ_GOV_STOP, NULL);
if (ret) {
Expand Down
1 change: 1 addition & 0 deletions include/linux/devfreq.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ struct devfreq {
unsigned long last_stat_updated;

struct srcu_notifier_head transition_notifier_list;
bool dev_suspended;
};

struct devfreq_freqs {
Expand Down

0 comments on commit 989ed3f

Please sign in to comment.