Re: [PATCH 2/4] gpio: qcom-smsm: Add driver for Qualcomm SMSM

2015-09-08 Thread Linus Walleij
On Thu, Aug 27, 2015 at 7:37 PM, Bjorn Andersson
 wrote:

> This driver exposed the Qualcomm Shared Memory State Machine bits as
> GPIOs to the system.
>
> Signed-off-by: Bjorn Andersson 
(...)
> +/*
> + * This driver implements the Qualcomm Shared Memory State Machine, a 
> mechanism
> + * for communicating single bit state information to remote processors.
> + *
> + * The implementation is based on two sections of shared memory; the first
> + * holding the state bits and the second holding a matrix of subscription 
> bits.
> + *
> + * The state bits are structured in entries of 32 bits, each belonging to one
> + * system in the SoC. The entry belonging to the local system is considered
> + * read-write, while the rest should be considered read-only.
> + *
> + * The subscription matrix consists of N bitmaps per entry, denoting interest
> + * in updates of the entry for each of the N hosts. Upon updating a state bit
> + * each host's subscription bitmap should be queried and the remote system
> + * should be interrupted if they request so.
> + *
> + * The subscription matrix is laid out in entry-major order:
> + * entry0: [host0 ... hostN]
> + * .
> + * .
> + * entryM: [host0 ... hostN]
> + *
> + * A third, optional, shared memory region might contain information 
> regarding
> + * the number of entries in the state bitmap as well as number of columns in
> + * the subscription matrix.
> + */

This does seem like a real bad fit to GPIO for me, sorry.

IMO this is drivers/soc/qcom, using regmap and possibly
regmap IRQs-material.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] gpio: qcom-smsm: Add driver for Qualcomm SMSM

2015-08-27 Thread Bjorn Andersson
This driver exposed the Qualcomm Shared Memory State Machine bits as
GPIOs to the system.

Signed-off-by: Bjorn Andersson 
---
 drivers/gpio/gpio-qcom-smsm.c | 631 ++
 1 file changed, 631 insertions(+)
 create mode 100644 drivers/gpio/gpio-qcom-smsm.c

diff --git a/drivers/gpio/gpio-qcom-smsm.c b/drivers/gpio/gpio-qcom-smsm.c
new file mode 100644
index ..4b3f28c469b6
--- /dev/null
+++ b/drivers/gpio/gpio-qcom-smsm.c
@@ -0,0 +1,631 @@
+/*
+ * Copyright (c) 2015, Sony Mobile Communications Inc.
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * This driver implements the Qualcomm Shared Memory State Machine, a mechanism
+ * for communicating single bit state information to remote processors.
+ *
+ * The implementation is based on two sections of shared memory; the first
+ * holding the state bits and the second holding a matrix of subscription bits.
+ *
+ * The state bits are structured in entries of 32 bits, each belonging to one
+ * system in the SoC. The entry belonging to the local system is considered
+ * read-write, while the rest should be considered read-only.
+ *
+ * The subscription matrix consists of N bitmaps per entry, denoting interest
+ * in updates of the entry for each of the N hosts. Upon updating a state bit
+ * each host's subscription bitmap should be queried and the remote system
+ * should be interrupted if they request so.
+ *
+ * The subscription matrix is laid out in entry-major order:
+ * entry0: [host0 ... hostN]
+ * .
+ * .
+ * entryM: [host0 ... hostN]
+ *
+ * A third, optional, shared memory region might contain information regarding
+ * the number of entries in the state bitmap as well as number of columns in
+ * the subscription matrix.
+ */
+
+/*
+ * Shared memory identifiers, used to acquire handles to respective memory
+ * region.
+ */
+#define SMEM_SMSM_SHARED_STATE 85
+#define SMEM_SMSM_CPU_INTR_MASK333
+#define SMEM_SMSM_SIZE_INFO419
+
+/*
+ * Default sizes, in case SMEM_SMSM_SIZE_INFO is not found.
+ */
+#define SMSM_DEFAULT_NUM_ENTRIES   8
+#define SMSM_DEFAULT_NUM_HOSTS 3
+
+struct smsm_entry;
+struct smsm_host;
+
+/**
+ * struct qcom_smsm - smsm driver context
+ * @dev:   smsm device pointer
+ * @local_host:column in the subscription matrix representing this 
system
+ * @num_hosts: number of columns in the subscription matrix
+ * @num_entries: number of entries in the state map and rows in the 
subscription
+ * matrix
+ * @local_state: pointer to the local processor's state bits
+ * @subscription: pointer to local processor's row in subscription matrix
+ * @chip:  gpio_chip for interfacing the state bits
+ * @entries:   context for each of the entries
+ * @hosts: context for each of the hosts
+ */
+struct qcom_smsm {
+   struct device *dev;
+
+   u32 local_host;
+
+   u32 num_hosts;
+   u32 num_entries;
+
+   u32 *local_state;
+   u32 *subscription;
+   struct gpio_chip chip;
+
+   struct smsm_entry *entries;
+   struct smsm_host *hosts;
+};
+
+/**
+ * struct smsm_entry - per remote processor entry context
+ * @smsm:  back-reference to driver context
+ * @domain:IRQ domain for this entry, if representing a remote system
+ * @irq_enabled: bitmap of which state bits IRQs are enabled
+ * @irq_rising:bitmap tracking if rising bits should be propagated
+ * @irq_falling: bitmap tracking if falling bits should be propagated
+ * @last_value:snapshot of state bits last time the interrupts where 
propagated
+ * @remote_state: pointer to this entry's state bits
+ * @subscription: pointer to a row in the subscription matrix representing this
+ * entry
+ */
+struct smsm_entry {
+   struct qcom_smsm *smsm;
+
+   struct irq_domain *domain;
+   DECLARE_BITMAP(irq_enabled, 32);
+   DECLARE_BITMAP(irq_rising, 32);
+   DECLARE_BITMAP(irq_falling, 32);
+   u32 last_value;
+
+   u32 *remote_state;
+   u32 *subscription;
+};
+
+/**
+ * struct smsm_host - representation of a remote host
+ * @ipc_regmap:regmap for outgoing interrupt
+ * @ipc_offset:offset in @ipc_regmap for outgoing interrupt
+ * @ipc_bit:   bit in @ipc_regmap + @ipc_offset for outgoing interrupt
+ */
+struct smsm_host {
+   struct regmap *ipc_regmap;
+   int ipc_offset;
+