summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Bouyack <mbouyack@google.com>2021-09-17 13:42:08 -0700
committerAndrew Evans <andrewevans@google.com>2022-03-09 15:04:45 -0800
commit42a3601e450f00564c1a64cd5e49d449169f7407 (patch)
treee639cc087ccef3bc59eb689c18dffe75322a4100
parent1869ae2d1bb8c63663bb11e3d41735994ab2545b (diff)
downloadrotary-encoders-42a3601e450f00564c1a64cd5e49d449169f7407.tar.gz
Fully disable RSB on suspend
Previously we were just setting the "power down" bit. This puts RSB into a very low power state, but is reportedly not as efficient as disabling the part entirely. Signed-off-by: Matthew Bouyack <mbouyack@google.com> Bug: 192268197 Change-Id: I0a9c167d595ffa8cbe3db99a0d8c0c475ddd4c17
-rw-r--r--ots_pat9126/pat9126.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/ots_pat9126/pat9126.c b/ots_pat9126/pat9126.c
index e751cf4..fc9f635 100644
--- a/ots_pat9126/pat9126.c
+++ b/ots_pat9126/pat9126.c
@@ -300,6 +300,43 @@ int pat9126_enable_mot(struct i2c_client *client)
return 0;
}
+int pat9126_enable_mot_write_protected(struct i2c_client *client) {
+ int result;
+
+ pat9126_write_verified(client, PIXART_PAT9126_WRITE_PROTECT_REG,
+ PIXART_PAT9126_DISABLE_WRITE_PROTECT);
+
+ result = pat9126_enable_mot(client);
+
+ pat9126_write_verified(client, PIXART_PAT9126_WRITE_PROTECT_REG,
+ PIXART_PAT9126_ENABLE_WRITE_PROTECT);
+
+ if (result) {
+ pr_err("[PAT9126] %s: failed to enable sensor\n", __func__);
+ }
+
+ return result;
+}
+
+int pat9126_disable_mot_write_protected(struct i2c_client *client) {
+ int result;
+
+ pat9126_write_verified(client, PIXART_PAT9126_WRITE_PROTECT_REG,
+ PIXART_PAT9126_DISABLE_WRITE_PROTECT);
+
+ result = pat9126_disable_mot(client,
+ PIXART_PAT9126_SLEEP_MODE_DETECT_FREQ_DEFAULT);
+
+ pat9126_write_verified(client, PIXART_PAT9126_WRITE_PROTECT_REG,
+ PIXART_PAT9126_ENABLE_WRITE_PROTECT);
+
+ if (result) {
+ pr_err("[PAT9126] %s: failed to disable sensor\n", __func__);
+ }
+
+ return result;
+}
+
/* Read motion */
void pat9126_read_motion(struct i2c_client *client, int16_t *dx16, int16_t *dy16)
{
@@ -604,7 +641,6 @@ static void pat9126_complete_resume(struct work_struct *work) {
struct delayed_work *dw = to_delayed_work(work);
struct pixart_pat9126_data *data =
container_of(dw, struct pixart_pat9126_data, resume_work);
- struct device *dev = &data->client->dev;
mutex_lock(&data->mtx);
@@ -620,8 +656,7 @@ static void pat9126_complete_resume(struct work_struct *work) {
goto end_complete_resume;
}
- pat9126_pd_write(dev, 0);
- delay(3); // To ensure accuracy, datasheet recommends 3ms delay here
+ pat9126_enable_mot_write_protected(data->client);
data->state = PAT9126_STATE_ON;
enable_irq(data->client->irq);
@@ -840,7 +875,7 @@ static int pat9126_display_suspend(struct device *dev)
}
disable_irq(data->client->irq);
- pat9126_pd_write(dev, 1);
+ pat9126_disable_mot_write_protected(data->client);
end_suspend:
data->state = PAT9126_STATE_OFF;