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

Commit c6e59bda authored by Kevin Hilman's avatar Kevin Hilman
Browse files

Merge tag 'qcom-soc-for-4.3-rc2' of git://codeaurora.org/quic/kernel/agross-msm into next/late

Qualcomm ARM Based SoC Updates for 4.3-rc2

* Fix errant private access in SMEM
* Fix use of correct remote processor ID in SMD transactions
* Correct SMD fBLOCKREADINTR handling

* tag 'qcom-soc-for-4.3-rc2' of git://codeaurora.org/quic/kernel/agross-msm:
  soc: qcom: smd: Correct fBLOCKREADINTR handling
  soc: qcom: smd: Use correct remote processor ID
  soc: qcom: smem: Fix errant private access
  devicetree: soc: Add Qualcomm SMD based RPM DT binding
  soc: qcom: Driver for the Qualcomm RPM over SMD
  soc: qcom: Add Shared Memory Driver
  soc: qcom: Add device tree binding for Shared Memory Device
  drivers: qcom: Select QCOM_SCM unconditionally for QCOM_PM
  soc: qcom: Add Shared Memory Manager driver
parents 312146b5 208487a8
Loading
Loading
Loading
Loading
+117 −0
Original line number Diff line number Diff line
Qualcomm Resource Power Manager (RPM) over SMD

This driver is used to interface with the Resource Power Manager (RPM) found in
various Qualcomm platforms. The RPM allows each component in the system to vote
for state of the system resources, such as clocks, regulators and bus
frequencies.

- compatible:
	Usage: required
	Value type: <string>
	Definition: must be one of:
		    "qcom,rpm-msm8974"

- qcom,smd-channels:
	Usage: required
	Value type: <stringlist>
	Definition: Shared Memory channel used for communication with the RPM

= SUBDEVICES

The RPM exposes resources to its subnodes. The below bindings specify the set
of valid subnodes that can operate on these resources.

== Regulators

Regulator nodes are identified by their compatible:

- compatible:
	Usage: required
	Value type: <string>
	Definition: must be one of:
		    "qcom,rpm-pm8841-regulators"
		    "qcom,rpm-pm8941-regulators"

- vdd_s1-supply:
- vdd_s2-supply:
- vdd_s3-supply:
- vdd_s4-supply:
- vdd_s5-supply:
- vdd_s6-supply:
- vdd_s7-supply:
- vdd_s8-supply:
	Usage: optional (pm8841 only)
	Value type: <phandle>
	Definition: reference to regulator supplying the input pin, as
		    described in the data sheet

- vdd_s1-supply:
- vdd_s2-supply:
- vdd_s3-supply:
- vdd_l1_l3-supply:
- vdd_l2_lvs1_2_3-supply:
- vdd_l4_l11-supply:
- vdd_l5_l7-supply:
- vdd_l6_l12_l14_l15-supply:
- vdd_l8_l16_l18_l19-supply:
- vdd_l9_l10_l17_l22-supply:
- vdd_l13_l20_l23_l24-supply:
- vdd_l21-supply:
- vin_5vs-supply:
	Usage: optional (pm8941 only)
	Value type: <phandle>
	Definition: reference to regulator supplying the input pin, as
		    described in the data sheet

The regulator node houses sub-nodes for each regulator within the device. Each
sub-node is identified using the node's name, with valid values listed for each
of the pmics below.

pm8841:
	s1, s2, s3, s4, s5, s6, s7, s8

pm8941:
	s1, s2, s3, s4, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13,
	l14, l15, l16, l17, l18, l19, l20, l21, l22, l23, l24, lvs1, lvs2,
	lvs3, 5vs1, 5vs2

The content of each sub-node is defined by the standard binding for regulators -
see regulator.txt.

= EXAMPLE

	smd {
		compatible = "qcom,smd";

		rpm {
			interrupts = <0 168 1>;
			qcom,ipc = <&apcs 8 0>;
			qcom,smd-edge = <15>;

			rpm_requests {
				compatible = "qcom,rpm-msm8974";
				qcom,smd-channels = "rpm_requests";

				pm8941-regulators {
					compatible = "qcom,rpm-pm8941-regulators";
					vdd_l13_l20_l23_l24-supply = <&pm8941_boost>;

					pm8941_s3: s3 {
						regulator-min-microvolt = <1800000>;
						regulator-max-microvolt = <1800000>;
					};

					pm8941_boost: s4 {
						regulator-min-microvolt = <5000000>;
						regulator-max-microvolt = <5000000>;
					};

					pm8941_l20: l20 {
						regulator-min-microvolt = <2950000>;
						regulator-max-microvolt = <2950000>;
					};
				};
			};
		};
	};
+85 −0
Original line number Diff line number Diff line
Qualcomm Shared Memory Driver (SMD) binding

This binding describes the Qualcomm Shared Memory Driver, a fifo based
communication channel for sending data between the various subsystems in
Qualcomm platforms.

- compatible:
	Usage: required
	Value type: <stringlist>
	Definition: must be "qcom,smd"

= EDGES

Each subnode of the SMD node represents a remote subsystem or a remote
processor of some sort - or in SMD language an "edge". The name of the edges
are not important.
The edge is described by the following properties:

- interrupts:
	Usage: required
	Value type: <prop-encoded-array>
	Definition: should specify the IRQ used by the remote processor to
		    signal this processor about communication related updates

- qcom,ipc:
	Usage: required
	Value type: <prop-encoded-array>
	Definition: three entries specifying the outgoing ipc bit used for
		    signaling the remote processor:
		    - phandle to a syscon node representing the apcs registers
		    - u32 representing offset to the register within the syscon
		    - u32 representing the ipc bit within the register

- qcom,smd-edge:
	Usage: required
	Value type: <u32>
	Definition: the identifier of the remote processor in the smd channel
		    allocation table

- qcom,remote-pid:
	Usage: optional
	Value type: <u32>
	Definition: the identifier for the remote processor as known by the rest
		    of the system.

= SMD DEVICES

In turn, subnodes of the "edges" represent devices tied to SMD channels on that
"edge". The names of the devices are not important. The properties of these
nodes are defined by the individual bindings for the SMD devices - but must
contain the following property:

- qcom,smd-channels:
	Usage: required
	Value type: <stringlist>
	Definition: a list of channels tied to this device, used for matching
		    the device to channels

= EXAMPLE

The following example represents a smd node, with one edge representing the
"rpm" subsystem. For the "rpm" subsystem we have a device tied to the
"rpm_request" channel.

	apcs: syscon@f9011000 {
		compatible = "syscon";
		reg = <0xf9011000 0x1000>;
	};

	smd {
		compatible = "qcom,smd";

		rpm {
			interrupts = <0 168 1>;
			qcom,ipc = <&apcs 8 0>;
			qcom,smd-edge = <15>;

			rpm_requests {
				compatible = "qcom,rpm-msm8974";
				qcom,smd-channels = "rpm_requests";

				...
			};
		};
	};
+31 −0
Original line number Diff line number Diff line
@@ -13,7 +13,38 @@ config QCOM_GSBI
config QCOM_PM
	bool "Qualcomm Power Management"
	depends on ARCH_QCOM && !ARM64
	select QCOM_SCM
	help
	  QCOM Platform specific power driver to manage cores and L2 low power
	  modes. It interface with various system drivers to put the cores in
	  low power modes.

config QCOM_SMD
	tristate "Qualcomm Shared Memory Driver (SMD)"
	depends on QCOM_SMEM
	help
	  Say y here to enable support for the Qualcomm Shared Memory Driver
	  providing communication channels to remote processors in Qualcomm
	  platforms.

config QCOM_SMD_RPM
	tristate "Qualcomm Resource Power Manager (RPM) over SMD"
	depends on QCOM_SMD && OF
	help
	  If you say yes to this option, support will be included for the
	  Resource Power Manager system found in the Qualcomm 8974 based
	  devices.

	  This is required to access many regulators, clocks and bus
	  frequencies controlled by the RPM on these devices.

	  Say M here if you want to include support for the Qualcomm RPM as a
	  module. This will build a module called "qcom-smd-rpm".

config QCOM_SMEM
	tristate "Qualcomm Shared Memory Manager (SMEM)"
	depends on ARCH_QCOM
	help
	  Say y here to enable support for the Qualcomm Shared Memory Manager.
	  The driver provides an interface to items in a heap shared among all
	  processors in a Qualcomm platform.
+3 −0
Original line number Diff line number Diff line
obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
obj-$(CONFIG_QCOM_PM)	+=	spm.o
obj-$(CONFIG_QCOM_SMD) +=	smd.o
obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
obj-$(CONFIG_QCOM_SMEM) +=	smem.o
+244 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2015, Sony Mobile Communications AB.
 * Copyright (c) 2012-2013, 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
 * only version 2 as published by the Free Software Foundation.
 *
 * 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.
 */

#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/io.h>
#include <linux/interrupt.h>

#include <linux/soc/qcom/smd.h>
#include <linux/soc/qcom/smd-rpm.h>

#define RPM_REQUEST_TIMEOUT     (5 * HZ)

/**
 * struct qcom_smd_rpm - state of the rpm device driver
 * @rpm_channel:	reference to the smd channel
 * @ack:		completion for acks
 * @lock:		mutual exclusion around the send/complete pair
 * @ack_status:		result of the rpm request
 */
struct qcom_smd_rpm {
	struct qcom_smd_channel *rpm_channel;

	struct completion ack;
	struct mutex lock;
	int ack_status;
};

/**
 * struct qcom_rpm_header - header for all rpm requests and responses
 * @service_type:	identifier of the service
 * @length:		length of the payload
 */
struct qcom_rpm_header {
	u32 service_type;
	u32 length;
};

/**
 * struct qcom_rpm_request - request message to the rpm
 * @msg_id:	identifier of the outgoing message
 * @flags:	active/sleep state flags
 * @type:	resource type
 * @id:		resource id
 * @data_len:	length of the payload following this header
 */
struct qcom_rpm_request {
	u32 msg_id;
	u32 flags;
	u32 type;
	u32 id;
	u32 data_len;
};

/**
 * struct qcom_rpm_message - response message from the rpm
 * @msg_type:	indicator of the type of message
 * @length:	the size of this message, including the message header
 * @msg_id:	message id
 * @message:	textual message from the rpm
 *
 * Multiple of these messages can be stacked in an rpm message.
 */
struct qcom_rpm_message {
	u32 msg_type;
	u32 length;
	union {
		u32 msg_id;
		u8 message[0];
	};
};

#define RPM_SERVICE_TYPE_REQUEST	0x00716572 /* "req\0" */

#define RPM_MSG_TYPE_ERR		0x00727265 /* "err\0" */
#define RPM_MSG_TYPE_MSG_ID		0x2367736d /* "msg#" */

/**
 * qcom_rpm_smd_write - write @buf to @type:@id
 * @rpm:	rpm handle
 * @type:	resource type
 * @id:		resource identifier
 * @buf:	the data to be written
 * @count:	number of bytes in @buf
 */
int qcom_rpm_smd_write(struct qcom_smd_rpm *rpm,
		       int state,
		       u32 type, u32 id,
		       void *buf,
		       size_t count)
{
	static unsigned msg_id = 1;
	int left;
	int ret;

	struct {
		struct qcom_rpm_header hdr;
		struct qcom_rpm_request req;
		u8 payload[count];
	} pkt;

	/* SMD packets to the RPM may not exceed 256 bytes */
	if (WARN_ON(sizeof(pkt) >= 256))
		return -EINVAL;

	mutex_lock(&rpm->lock);

	pkt.hdr.service_type = RPM_SERVICE_TYPE_REQUEST;
	pkt.hdr.length = sizeof(struct qcom_rpm_request) + count;

	pkt.req.msg_id = msg_id++;
	pkt.req.flags = BIT(state);
	pkt.req.type = type;
	pkt.req.id = id;
	pkt.req.data_len = count;
	memcpy(pkt.payload, buf, count);

	ret = qcom_smd_send(rpm->rpm_channel, &pkt, sizeof(pkt));
	if (ret)
		goto out;

	left = wait_for_completion_timeout(&rpm->ack, RPM_REQUEST_TIMEOUT);
	if (!left)
		ret = -ETIMEDOUT;
	else
		ret = rpm->ack_status;

out:
	mutex_unlock(&rpm->lock);
	return ret;
}
EXPORT_SYMBOL(qcom_rpm_smd_write);

static int qcom_smd_rpm_callback(struct qcom_smd_device *qsdev,
				 const void *data,
				 size_t count)
{
	const struct qcom_rpm_header *hdr = data;
	const struct qcom_rpm_message *msg;
	struct qcom_smd_rpm *rpm = dev_get_drvdata(&qsdev->dev);
	const u8 *buf = data + sizeof(struct qcom_rpm_header);
	const u8 *end = buf + hdr->length;
	char msgbuf[32];
	int status = 0;
	u32 len;

	if (hdr->service_type != RPM_SERVICE_TYPE_REQUEST ||
	    hdr->length < sizeof(struct qcom_rpm_message)) {
		dev_err(&qsdev->dev, "invalid request\n");
		return 0;
	}

	while (buf < end) {
		msg = (struct qcom_rpm_message *)buf;
		switch (msg->msg_type) {
		case RPM_MSG_TYPE_MSG_ID:
			break;
		case RPM_MSG_TYPE_ERR:
			len = min_t(u32, ALIGN(msg->length, 4), sizeof(msgbuf));
			memcpy_fromio(msgbuf, msg->message, len);
			msgbuf[len - 1] = 0;

			if (!strcmp(msgbuf, "resource does not exist"))
				status = -ENXIO;
			else
				status = -EINVAL;
			break;
		}

		buf = PTR_ALIGN(buf + 2 * sizeof(u32) + msg->length, 4);
	}

	rpm->ack_status = status;
	complete(&rpm->ack);
	return 0;
}

static int qcom_smd_rpm_probe(struct qcom_smd_device *sdev)
{
	struct qcom_smd_rpm *rpm;

	rpm = devm_kzalloc(&sdev->dev, sizeof(*rpm), GFP_KERNEL);
	if (!rpm)
		return -ENOMEM;

	mutex_init(&rpm->lock);
	init_completion(&rpm->ack);

	rpm->rpm_channel = sdev->channel;

	dev_set_drvdata(&sdev->dev, rpm);

	return of_platform_populate(sdev->dev.of_node, NULL, NULL, &sdev->dev);
}

static void qcom_smd_rpm_remove(struct qcom_smd_device *sdev)
{
	of_platform_depopulate(&sdev->dev);
}

static const struct of_device_id qcom_smd_rpm_of_match[] = {
	{ .compatible = "qcom,rpm-msm8974" },
	{}
};
MODULE_DEVICE_TABLE(of, qcom_smd_rpm_of_match);

static struct qcom_smd_driver qcom_smd_rpm_driver = {
	.probe = qcom_smd_rpm_probe,
	.remove = qcom_smd_rpm_remove,
	.callback = qcom_smd_rpm_callback,
	.driver  = {
		.name  = "qcom_smd_rpm",
		.owner = THIS_MODULE,
		.of_match_table = qcom_smd_rpm_of_match,
	},
};

static int __init qcom_smd_rpm_init(void)
{
	return qcom_smd_driver_register(&qcom_smd_rpm_driver);
}
arch_initcall(qcom_smd_rpm_init);

static void __exit qcom_smd_rpm_exit(void)
{
	qcom_smd_driver_unregister(&qcom_smd_rpm_driver);
}
module_exit(qcom_smd_rpm_exit);

MODULE_AUTHOR("Bjorn Andersson <bjorn.andersson@sonymobile.com>");
MODULE_DESCRIPTION("Qualcomm SMD backed RPM driver");
MODULE_LICENSE("GPL v2");
Loading