Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c10673f authored by Todd Poynor's avatar Todd Poynor Committed by Ruchi Kandoi
Browse files

w1: ds2482: Manage SLPZ pin sleep state



Place SLPZ pin in sleep state at system suspend time if a GPIO is
provided by board platform data.

Change-Id: I93c61fa0ae474e968e0f909209c9bfcaafe3dd2c
Signed-off-by: default avatarTodd Poynor <toddpoynor@google.com>
parent b094216b
Loading
Loading
Loading
Loading
+46 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/platform_data/ds2482.h>
#include <asm/delay.h>

#include "../w1.h"
@@ -84,7 +86,8 @@ static const u8 ds2482_chan_rd[8] =
static int ds2482_probe(struct i2c_client *client,
			const struct i2c_device_id *id);
static int ds2482_remove(struct i2c_client *client);

static int ds2482_suspend(struct device *dev);
static int ds2482_resume(struct device *dev);

/**
 * Driver data (common to all clients)
@@ -94,10 +97,16 @@ static const struct i2c_device_id ds2482_id[] = {
	{ }
};

static const struct dev_pm_ops ds2482_pm_ops = {
	.suspend = ds2482_suspend,
	.resume = ds2482_resume,
};

static struct i2c_driver ds2482_driver = {
	.driver = {
		.owner	= THIS_MODULE,
		.name	= "ds2482",
		.pm = &ds2482_pm_ops,
	},
	.probe		= ds2482_probe,
	.remove		= ds2482_remove,
@@ -119,6 +128,7 @@ struct ds2482_w1_chan {
struct ds2482_data {
	struct i2c_client	*client;
	struct mutex		access_lock;
	int			slpz_gpio;

	/* 1-wire interface(s) */
	int			w1_count;	/* 1 or 8 */
@@ -444,11 +454,31 @@ static u8 ds2482_w1_set_pullup(void *data, int delay)
	return retval;
}

static int ds2482_suspend(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct ds2482_data *data = i2c_get_clientdata(client);

	if (data->slpz_gpio >= 0)
		gpio_set_value(data->slpz_gpio, 0);
	return 0;
}

static int ds2482_resume(struct device *dev)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct ds2482_data *data = i2c_get_clientdata(client);

	if (data->slpz_gpio >= 0)
		gpio_set_value(data->slpz_gpio, 1);
	return 0;
}

static int ds2482_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
	struct ds2482_data *data;
	struct ds2482_platform_data *pdata;
	int err = -ENODEV;
	int temp1;
	int idx;
@@ -515,6 +545,16 @@ static int ds2482_probe(struct i2c_client *client,
		}
	}

	pdata = client->dev.platform_data;
	data->slpz_gpio = pdata ? pdata->slpz_gpio : -1;

	if (data->slpz_gpio >= 0) {
		err = gpio_request_one(data->slpz_gpio, GPIOF_OUT_INIT_HIGH,
				       "ds2482.slpz");
		if (err < 0)
			goto exit_w1_remove;
	}

	return 0;

exit_w1_remove:
@@ -539,6 +579,11 @@ static int ds2482_remove(struct i2c_client *client)
			w1_remove_master_device(&data->w1_ch[idx].w1_bm);
	}

	if (data->slpz_gpio >= 0) {
		gpio_set_value(data->slpz_gpio, 0);
		gpio_free(data->slpz_gpio);
	}

	/* Free the memory */
	kfree(data);
	return 0;
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 Google, Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef __PLATFORM_DATA_DS2482__
#define __PLATFORM_DATA_DS2482__

struct ds2482_platform_data {
	int		slpz_gpio;
};

#endif /* __PLATFORM_DATA_DS2482__ */