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

Commit 61893669 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "misc: qpnp-misc: add support for clients to read register from misc device"

parents 12f32689 045b1fba
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -128,6 +128,47 @@ static bool __misc_irqs_available(struct qpnp_misc_dev *dev)
	return 1;
}

int qpnp_misc_read_reg(struct device_node *node, u16 addr, u8 *val)
{
	struct qpnp_misc_dev *mdev = NULL;
	struct qpnp_misc_dev *mdev_found = NULL;
	int rc;
	u8 temp;

	if (IS_ERR_OR_NULL(node)) {
		pr_err("Invalid device node pointer\n");
		return -EINVAL;
	}

	mutex_lock(&qpnp_misc_dev_list_mutex);
	list_for_each_entry(mdev, &qpnp_misc_dev_list, list) {
		if (mdev->dev->of_node == node) {
			mdev_found = mdev;
			break;
		}
	}
	mutex_unlock(&qpnp_misc_dev_list_mutex);

	if (!mdev_found) {
		/*
		 * No MISC device was found. This API should only
		 * be called by drivers which have specified the
		 * misc phandle in their device tree node.
		 */
		pr_err("no probed misc device found\n");
		return -EPROBE_DEFER;
	}

	rc = qpnp_read_byte(mdev->spmi, addr, &temp);
	if (rc < 0) {
		dev_err(mdev->dev, "Failed to read addr %x, rc=%d\n", addr, rc);
		return rc;
	}

	*val = temp;
	return 0;
}

int qpnp_misc_irqs_available(struct device *consumer_dev)
{
	struct device_node *misc_node = NULL;
+20 −2
Original line number Diff line number Diff line
/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2014, 2017, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -29,8 +29,26 @@
 */

int qpnp_misc_irqs_available(struct device *consumer_dev);

/**
 * qpnp_misc_read_reg - read register from misc device
 *
 * @node: device node pointer
 * @address: address offset in misc peripheral to be read
 * @val: data read from register
 *
 * This function returns zero if reading the MISC register succeeds.
 *
 */

int qpnp_misc_read_reg(struct device_node *node, u16 addr, u8 *val);
#else
static int qpnp_misc_irqs_available(struct device *consumer_dev)
static inline int qpnp_misc_irqs_available(struct device *consumer_dev)
{
	return 0;
}
static inline int qpnp_misc_read_reg(struct device_node *node, u16 addr,
					u8 *val)
{
	return 0;
}