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

Commit 72914edd authored by Figo Wang's avatar Figo Wang Committed by Stephen Boyd
Browse files

sensor: Add enable interface for G-sensor driver kxtj9



Enable file node is need by HAL layer to enable/disable sensor.
Add this interface allow HAL to control sensor power on/off state
by write into this node.

Signed-off-by: default avatarFigo Wang <figow@codeaurora.org>
Change-Id: I1755cfeccf8afb51f2664d36cfd27f4b22fa3d7d
parent 7a56dcfa
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ struct kxtj9_data {
	struct input_polled_dev *poll_dev;
#endif
	unsigned int last_poll_interval;
	bool	enable;
	u8 shift;
	u8 ctrl_reg1;
	u8 data_ctrl;
@@ -269,16 +270,19 @@ static int kxtj9_enable(struct kxtj9_data *tj9)
		}
	}

	tj9->enable = true;
	return 0;

fail:
	kxtj9_device_power_off(tj9);
	tj9->enable = false;
	return err;
}

static void kxtj9_disable(struct kxtj9_data *tj9)
{
	kxtj9_device_power_off(tj9);
	tj9->enable = false;
}

static int kxtj9_input_open(struct input_dev *input)
@@ -339,6 +343,49 @@ static int kxtj9_setup_input_device(struct kxtj9_data *tj9)
	return 0;
}

static ssize_t kxtj9_enable_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct kxtj9_data *tj9 = i2c_get_clientdata(client);

	return snprintf(buf, 4, "%d\n", tj9->enable);
}

static ssize_t kxtj9_enable_store(struct device *dev,
					struct device_attribute *attr,
					const char *buf, size_t count)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct kxtj9_data *tj9 = i2c_get_clientdata(client);
	struct input_dev *input_dev = tj9->input_dev;
	unsigned long data;
	int error;

	error = kstrtoul(buf, 10, &data);
	if (error)
		return error;
	mutex_lock(&input_dev->mutex);
	disable_irq(client->irq);

	if (data == 0)
		kxtj9_disable(tj9);
	else if (data == 1)
		kxtj9_enable(tj9);
	else {
		dev_err(&tj9->client->dev,
			"Invalid value of input, input=%ld\n", data);
	}

	enable_irq(client->irq);
	mutex_unlock(&input_dev->mutex);

	return count;
}

static DEVICE_ATTR(enable, S_IRUGO|S_IWUSR|S_IWGRP,
			kxtj9_enable_show, kxtj9_enable_store);

/*
 * When IRQ mode is selected, we need to provide an interface to allow the user
 * to change the output data rate of the part.  For consistency, we are using
@@ -396,6 +443,7 @@ static ssize_t kxtj9_set_poll(struct device *dev, struct device_attribute *attr,
static DEVICE_ATTR(poll, S_IRUGO|S_IWUSR, kxtj9_get_poll, kxtj9_set_poll);

static struct attribute *kxtj9_attributes[] = {
	&dev_attr_enable.attr,
	&dev_attr_poll.attr,
	NULL
};