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

Commit 2580d48d authored by Yimin Peng's avatar Yimin Peng
Browse files

spmi: pmic_arb: add virtio spmi driver for VM platforms



The virtio spmi-pmic frontend driver communicates with its
backend to support pmic clients virtualization.

Change-Id: I937e6ecf76dd4962654fd8b92209ff971b8f4227
Signed-off-by: default avatarYimin Peng <yiminp@codeaurora.org>
parent bacc0533
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
QTI Virtio SPMI controller (Virtio PMIC Arbiter)

The Virtio SPMI PMIC Arbiter is a frontend proxy based on backend virtio device.

Required properties:
- compatible : should be "qcom,viospmi-pmic-arb".
- #address-cells : must be set to 2
- #size-cells : must be set to 0
- interrupt-controller : boolean indicator that the PMIC arbiter is an interrupt controller
- #interrupt-cells :  must be set to 4. Interrupts are specified as a 4-tuple:
    cell 1: slave ID for the requested interrupt (0-15)
    cell 2: peripheral ID for requested interrupt (0-255)
    cell 3: the requested peripheral interrupt (0-7)
    cell 4: interrupt flags indicating level-sense information, as defined in
            dt-bindings/interrupt-controller/irq.h

Example Virtio PMIC-Arbiter:

     spmi_bus: qcom,spmi {
         compatible = "qcom,viospmi-pmic-arb";
         interrupt-names = "periph_irq";
         interrupts = <GIC_SPI 481 IRQ_TYPE_NONE>;
         qcom,ee = <0>;
         #address-cells = <2>;
         #size-cells = <0>;
         interrupt-controller;
         #interrupt-cells = <4>;
         cell-index = <0>;
     };

     viospmi: virtio-spmi@c440000 {
         compatible = "virtio,mmio";
         #address-cells = <1>;
         #size-cells = <1>;
         reg = <0xc440000 0x1100>;
         interrupts = <GIC_SPI 100 IRQ_TYPE_NONE>;
         status = "okay";
     };
+10 −0
Original line number Diff line number Diff line
@@ -34,6 +34,16 @@ config SPMI_MSM_PMIC_ARB_DEBUG
	  Inc. (QTI) MSM family processors.  This feature is available on chips
	  with PMIC arbiter version 5 and above.

config VIOSPMI_MSM_PMIC_ARB
	tristate "QTI Virtio SPMI Controller (Virtio PMIC Arbiter)"
	select IRQ_DOMAIN
	depends on ARCH_QCOM || COMPILE_TEST
	depends on HAS_IOMEM
	depends on VIRTIO
	default ARCH_QCOM
	help
	  This is virtio SPMI frontend driver for QTI MSM virtual platform.

source "drivers/spmi/simulator/Kconfig"

endif
+1 −0
Original line number Diff line number Diff line
@@ -5,4 +5,5 @@ obj-$(CONFIG_SPMI) += spmi.o

obj-$(CONFIG_SPMI_MSM_PMIC_ARB)	+= spmi-pmic-arb.o
obj-$(CONFIG_SPMI_MSM_PMIC_ARB_DEBUG)	+= spmi-pmic-arb-debug.o
obj-$(CONFIG_VIOSPMI_MSM_PMIC_ARB)    += viospmi-pmic-arb.o
obj-y	+= simulator/
+976 −0

File added.

Preview size limit exceeded, changes collapsed.

+77 −0
Original line number Diff line number Diff line
/* Copyright (c) 2019, 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.
 */

#ifndef _LINUX_VIRTIO_SPMI_H
#define _LINUX_VIRTIO_SPMI_H

#include <linux/types.h>
#include <linux/virtio_ids.h>
#include <linux/virtio_config.h>
#include <linux/virtio_types.h>

/* Feature bits */
#define VIRTIO_SPMI_F_INT	1	/* Support interrupt */

#define VM_MAX_PERIPHS 512

/* Configuration layout */
struct virtio_spmi_config {
	__u16 ppid_allowed[VM_MAX_PERIPHS];
} __packed;

struct payload_cmd {
	__virtio32 data[2];
};

struct payload_irq {
	__virtio32 ppid;
	__virtio32 val;
};

union payload_data {
	struct payload_cmd cmdd;
	struct payload_irq irqd;
};

struct virtio_spmi_msg {
	__virtio32 type;
	__virtio32 len;
	__virtio32 res;
	union {
		__virtio32 cmd;
		__virtio32 cnt;
	} u;
	union payload_data payload[];
};

/* Virtio SPMI message type */
enum vio_spmi_msg_type {
	VIO_SPMI_BUS_WRITE = 0,
	VIO_SPMI_BUS_READ = 1,
	VIO_ACC_ENABLE_WR = 2,
	VIO_ACC_ENABLE_RD = 3,
	VIO_IRQ_CLEAR = 4,
	VIO_IRQ_STATUS = 5,
};

/* Virtio SPMI message type */
enum vio_spmi_msg_res {
	VIO_SPMI_DONE = 0,
	VIO_SPMI_ERR = 1,
};

/* payload fix size and one payload_data size */
#define MSG_FIX_SZ (sizeof(struct virtio_spmi_msg))
#define PER_PLD_SZ (sizeof(union payload_data))
#define MSG_SZ(x)  (MSG_FIX_SZ + ((PER_PLD_SZ) * (x)))

#endif /* _LINUX_VIRTIO_SPMI_H */
Loading