[PATCH 1/1] Security : smack : Use kmem_cache for allocation and freeing of inode_smack

2014-10-14 Thread Rohit Kumar
From: Rohit rohit...@samsung.com

Use kmem_cache to allocate/free inode_smack since they are
alloced in high volumes making it a perfect case for kmem_cache.

Accounting of memory allocation is below :
 total   slacknet  count-alloc/freecaller
Before (with kzalloc)
1919872   719952  1919872  29998/0  
new_inode_smack+0x14
After (with kmem_cache)
12016800  1201680  30042/0  
new_inode_smack+0x18

Signed-off-by: Rohit rohit...@samsung.com
---
 security/smack/smack_lsm.c |   13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index d515ec2..58a5c92 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -53,6 +53,7 @@
 #define SMK_SENDING2
 
 LIST_HEAD(smk_ipv6_port_list);
+struct kmem_cache *smack_inode_cache;
 
 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
 static void smk_bu_mode(int mode, char *s)
@@ -240,7 +241,7 @@ struct inode_smack *new_inode_smack(struct smack_known *skp)
 {
struct inode_smack *isp;
 
-   isp = kzalloc(sizeof(struct inode_smack), GFP_NOFS);
+   isp = kmem_cache_zalloc(smack_inode_cache, GFP_NOFS);
if (isp == NULL)
return NULL;
 
@@ -767,7 +768,7 @@ static int smack_inode_alloc_security(struct inode *inode)
  */
 static void smack_inode_free_security(struct inode *inode)
 {
-   kfree(inode-i_security);
+   kmem_cache_free(smack_inode_cache, inode-i_security);
inode-i_security = NULL;
 }
 
@@ -4264,10 +4265,16 @@ static __init int smack_init(void)
if (!security_module_enable(smack_ops))
return 0;
 
+   smack_inode_cache = KMEM_CACHE(inode_smack, 0);
+   if (!smack_inode_cache)
+   return -ENOMEM;
+
tsp = new_task_smack(smack_known_floor, smack_known_floor,
GFP_KERNEL);
-   if (tsp == NULL)
+   if (tsp == NULL) {
+   kmem_cache_destroy(smack_inode_cache);
return -ENOMEM;
+   }
 
printk(KERN_INFO Smack:  Initializing.\n);
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] staging: ion: Fix error handling in ion_buffer_create

2015-09-29 Thread Rohit kumar
This patch fixes error handling case when buffer->pages allocation
fails. Also, it removes unreachable code of checking ret variable
although it is not updated.

Signed-off-by: Rohit kumar <rohit...@samsung.com>
---
 drivers/staging/android/ion/ion.c |   14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index 217aa53..af59e4a 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct 
ion_heap *heap,
"heap->ops->map_dma should return ERR_PTR on error"))
table = ERR_PTR(-EINVAL);
if (IS_ERR(table)) {
-   heap->ops->free(buffer);
-   kfree(buffer);
-   return ERR_CAST(table);
+   ret = -EINVAL;
+   goto err1;
}
+
buffer->sg_table = table;
if (ion_buffer_fault_user_mappings(buffer)) {
int num_pages = PAGE_ALIGN(buffer->size) / PAGE_SIZE;
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap 
*heap,
buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
if (!buffer->pages) {
ret = -ENOMEM;
-   goto err1;
+   goto err;
}
 
for_each_sg(table->sgl, sg, table->nents, i) {
@@ -235,9 +235,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap 
*heap,
for (j = 0; j < sg->length / PAGE_SIZE; j++)
buffer->pages[k++] = page++;
}
-
-   if (ret)
-   goto err;
}
 
buffer->dev = dev;
@@ -261,9 +258,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap 
*heap,
 
 err:
heap->ops->unmap_dma(heap, buffer);
-   heap->ops->free(buffer);
 err1:
-   vfree(buffer->pages);
+   heap->ops->free(buffer);
 err2:
kfree(buffer);
return ERR_PTR(ret);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCHv2 1/1] staging/ion: Add support to get ion handle from dma buf

2016-01-05 Thread Rohit kumar
Currently we can only import dma buf fd's to get ion_handle.
Adding support to import dma buf handles to support kernel
specific use cases.

An example use case is in linux platforms such as Tizen, in which
DRM-GEM is used for buffer management for graphics. It has gem_handle
corresponding to a buffer and uses gem_name for sharing the buffer
with other processes. However,it also uses dma_buf fd for 3d operations.
For wayland, there are multiple calls for gem_handle to dma_buf fd
conversion. So, we store dma_buf associated with buffer. But, there is
no api for getting ion_handle from dma_buf. This patch exposes api to
retrieve the ion handle from dma_buf for similar use cases. With this
patch, we can integrate ION within DRM-GEM for buffer management and
dma_buf sharing.

Signed-off-by: Rohit kumar <rohit...@samsung.com>
---
v2: Updated commit message with use case explanation, as suggested by
Laura Abbott<labb...@redhat.com>

 drivers/staging/android/ion/ion.c |   21 +++--
 drivers/staging/android/ion/ion.h |   20 
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index e237e9f..5509716 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1151,16 +1151,13 @@ int ion_share_dma_buf_fd(struct ion_client *client, 
struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_share_dma_buf_fd);
 
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf)
 {
-   struct dma_buf *dmabuf;
struct ion_buffer *buffer;
struct ion_handle *handle;
int ret;
 
-   dmabuf = dma_buf_get(fd);
-   if (IS_ERR(dmabuf))
-   return ERR_CAST(dmabuf);
/* if this memory came from ion */
 
if (dmabuf->ops != _buf_ops) {
@@ -1199,6 +1196,18 @@ end:
 }
 EXPORT_SYMBOL(ion_import_dma_buf);
 
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd)
+{
+   struct dma_buf *dmabuf;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf))
+   return ERR_CAST(dmabuf);
+
+   return ion_import_dma_buf(client, dmabuf);
+}
+EXPORT_SYMBOL(ion_import_dma_buf_fd);
+
 static int ion_sync_for_device(struct ion_client *client, int fd)
 {
struct dma_buf *dmabuf;
@@ -1306,7 +1315,7 @@ static long ion_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
{
struct ion_handle *handle;
 
-   handle = ion_import_dma_buf(client, data.fd.fd);
+   handle = ion_import_dma_buf_fd(client, data.fd.fd);
if (IS_ERR(handle))
ret = PTR_ERR(handle);
else
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index b860c5f..a1331fc 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -192,14 +192,26 @@ struct dma_buf *ion_share_dma_buf(struct ion_client 
*client,
 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
 
 /**
- * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
+ * ion_import_dma_buf() - get ion_handle from dma-buf
+ * @client:the client
+ * @dmabuf:the dma-buf
+ *
+ * Get the ion_buffer associated with the dma-buf and return the ion_handle.
+ * If no ion_handle exists for this buffer, return newly created ion_handle.
+ * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL)
+ */
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf);
+
+/**
+ * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get 
handle
  * @client:the client
  * @fd:the dma-buf fd
  *
- * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
- * import that fd and return a handle representing it.  If a dma-buf from
+ * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
+ * import that fd and return a handle representing it. If a dma-buf from
  * another exporter is passed in this function will return ERR_PTR(-EINVAL)
  */
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd);
 
 #endif /* _LINUX_ION_H */
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] staging/ion: Add support to get ion handle from dma buf

2016-01-05 Thread Rohit kumar
Currently we can only import dma buf fd's to get ion_handle.
Adding support to import dma buf handles to support kernel
specific use cases.

Signed-off-by: Rohit kumar <rohit...@samsung.com>
---
Currently, ION is the memory manager for graphics in android. However,
in other linux platforms such as Tizen, DRM-GEM is used for buffer 
management for graphics. It has gem_handle corresponding to a buffer
and uses gem_name for sharing the buffer with other processes. However,
it also uses dma_buf fd for 3d operations. For wayland, there are
multiple calls for gem_handle to dma_buf fd conversion. So, we store
dma_buf associated with buffer. But, there is no api for getting
ion_handle from dma_buf. This patch exposes api to retrieve the ion
handle from dma_buf for similar use cases. With this patch, we can
integrate ION within DRM-GEM for buffer management and dma_buf sharing.

 drivers/staging/android/ion/ion.c |   21 +++--
 drivers/staging/android/ion/ion.h |   20 
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index e237e9f..5509716 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -1151,16 +1151,13 @@ int ion_share_dma_buf_fd(struct ion_client *client, 
struct ion_handle *handle)
 }
 EXPORT_SYMBOL(ion_share_dma_buf_fd);
 
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd)
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf)
 {
-   struct dma_buf *dmabuf;
struct ion_buffer *buffer;
struct ion_handle *handle;
int ret;
 
-   dmabuf = dma_buf_get(fd);
-   if (IS_ERR(dmabuf))
-   return ERR_CAST(dmabuf);
/* if this memory came from ion */
 
if (dmabuf->ops != _buf_ops) {
@@ -1199,6 +1196,18 @@ end:
 }
 EXPORT_SYMBOL(ion_import_dma_buf);
 
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd)
+{
+   struct dma_buf *dmabuf;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf))
+   return ERR_CAST(dmabuf);
+
+   return ion_import_dma_buf(client, dmabuf);
+}
+EXPORT_SYMBOL(ion_import_dma_buf_fd);
+
 static int ion_sync_for_device(struct ion_client *client, int fd)
 {
struct dma_buf *dmabuf;
@@ -1306,7 +1315,7 @@ static long ion_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
{
struct ion_handle *handle;
 
-   handle = ion_import_dma_buf(client, data.fd.fd);
+   handle = ion_import_dma_buf_fd(client, data.fd.fd);
if (IS_ERR(handle))
ret = PTR_ERR(handle);
else
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index b860c5f..a1331fc 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -192,14 +192,26 @@ struct dma_buf *ion_share_dma_buf(struct ion_client 
*client,
 int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
 
 /**
- * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
+ * ion_import_dma_buf() - get ion_handle from dma-buf
+ * @client:the client
+ * @dmabuf:the dma-buf
+ *
+ * Get the ion_buffer associated with the dma-buf and return the ion_handle.
+ * If no ion_handle exists for this buffer, return newly created ion_handle.
+ * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL)
+ */
+struct ion_handle *ion_import_dma_buf(struct ion_client *client,
+ struct dma_buf *dmabuf);
+
+/**
+ * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get 
handle
  * @client:the client
  * @fd:the dma-buf fd
  *
- * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf,
- * import that fd and return a handle representing it.  If a dma-buf from
+ * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd,
+ * import that fd and return a handle representing it. If a dma-buf from
  * another exporter is passed in this function will return ERR_PTR(-EINVAL)
  */
-struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd);
+struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd);
 
 #endif /* _LINUX_ION_H */
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] remoteproc: Add APSS based Qualcomm ADSP PIL driver for SDM845

2018-05-13 Thread Rohit kumar
This adds Qualcomm ADSP PIL driver support for SDM845 with ADSP bootup
and shutdown operation handled from Application Processor SubSystem(APSS).

Signed-off-by: Rohit kumar <rohi...@codeaurora.org>
Signed-off-by: RajendraBabu Medisetti <rajendr...@codeaurora.org>
Signed-off-by: Krishnamurthy Renu <krishnamurthy.r...@codeaurora.org>
---
 .../devicetree/bindings/remoteproc/qcom,adsp.txt   |   1 +
 drivers/remoteproc/Makefile|   3 +-
 drivers/remoteproc/qcom_adsp_pil.c | 122 -
 drivers/remoteproc/qcom_adsp_pil.h |  86 ++
 drivers/remoteproc/qcom_adsp_pil_sdm845.c  | 304 +
 5 files changed, 454 insertions(+), 62 deletions(-)
 create mode 100644 drivers/remoteproc/qcom_adsp_pil.h
 create mode 100644 drivers/remoteproc/qcom_adsp_pil_sdm845.c

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
index 728e419..a9fe033 100644
--- a/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
@@ -10,6 +10,7 @@ on the Qualcomm ADSP Hexagon core.
"qcom,msm8974-adsp-pil"
"qcom,msm8996-adsp-pil"
"qcom,msm8996-slpi-pil"
+   "qcom,sdm845-apss-adsp-pil"
 
 - interrupts-extended:
Usage: required
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 02627ed..759831b 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -14,7 +14,8 @@ obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
 obj-$(CONFIG_WKUP_M3_RPROC)+= wkup_m3_rproc.o
 obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o
 obj-$(CONFIG_KEYSTONE_REMOTEPROC)  += keystone_remoteproc.o
-obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp_pil.o
+obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp.o
+qcom_adsp-objs += qcom_adsp_pil.o 
qcom_adsp_pil_sdm845.o
 obj-$(CONFIG_QCOM_RPROC_COMMON)+= qcom_common.o
 obj-$(CONFIG_QCOM_Q6V5_PIL)+= qcom_q6v5_pil.o
 obj-$(CONFIG_QCOM_SYSMON)  += qcom_sysmon.o
diff --git a/drivers/remoteproc/qcom_adsp_pil.c 
b/drivers/remoteproc/qcom_adsp_pil.c
index 89a86ce..9ab3698 100644
--- a/drivers/remoteproc/qcom_adsp_pil.c
+++ b/drivers/remoteproc/qcom_adsp_pil.c
@@ -1,5 +1,5 @@
 /*
- * Qualcomm ADSP/SLPI Peripheral Image Loader for MSM8974 and MSM8996
+ * Qualcomm ADSP/SLPI Peripheral Image Loader for MSM8974, MSM8996 and SDM845.
  *
  * Copyright (C) 2016 Linaro Ltd
  * Copyright (C) 2014 Sony Mobile Communications AB
@@ -22,7 +22,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -30,56 +29,8 @@
 #include 
 #include 
 
-#include "qcom_common.h"
 #include "remoteproc_internal.h"
-
-struct adsp_data {
-   int crash_reason_smem;
-   const char *firmware_name;
-   int pas_id;
-   bool has_aggre2_clk;
-
-   const char *ssr_name;
-   const char *sysmon_name;
-   int ssctl_id;
-};
-
-struct qcom_adsp {
-   struct device *dev;
-   struct rproc *rproc;
-
-   int wdog_irq;
-   int fatal_irq;
-   int ready_irq;
-   int handover_irq;
-   int stop_ack_irq;
-
-   struct qcom_smem_state *state;
-   unsigned stop_bit;
-
-   struct clk *xo;
-   struct clk *aggre2_clk;
-
-   struct regulator *cx_supply;
-   struct regulator *px_supply;
-
-   int pas_id;
-   int crash_reason_smem;
-   bool has_aggre2_clk;
-
-   struct completion start_done;
-   struct completion stop_done;
-
-   phys_addr_t mem_phys;
-   phys_addr_t mem_reloc;
-   void *mem_region;
-   size_t mem_size;
-
-   struct qcom_rproc_glink glink_subdev;
-   struct qcom_rproc_subdev smd_subdev;
-   struct qcom_rproc_ssr ssr_subdev;
-   struct qcom_sysmon *sysmon;
-};
+#include "qcom_adsp_pil.h"
 
 static int adsp_load(struct rproc *rproc, const struct firmware *fw)
 {
@@ -112,18 +63,32 @@ static int adsp_start(struct rproc *rproc)
if (ret)
goto disable_cx_supply;
 
-   ret = qcom_scm_pas_auth_and_reset(adsp->pas_id);
-   if (ret) {
-   dev_err(adsp->dev,
-   "failed to authenticate image and release reset\n");
-   goto disable_px_supply;
+   if (adsp->is_apss_controlled) {
+   ret = adsp->ops->bringup(adsp);
+   if (ret) {
+   dev_err(adsp->dev, "adsp bringup failed\n");
+   adsp->ops->bringdown(adsp);
+   goto disable_px_supply;
+   }
+   } else {
+   ret = qcom_scm_pas_auth_and_reset(adsp->pas_id);
+   if (ret) {
+ 

Re: [PATCH] remoteproc: Add APSS based Qualcomm ADSP PIL driver for SDM845

2018-05-23 Thread Rohit Kumar

Thanks Bjorn for reviewing.


On 5/23/2018 11:56 AM, Bjorn Andersson wrote:

On Sun 13 May 00:01 PDT 2018, Rohit kumar wrote:


--- a/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
@@ -10,6 +10,7 @@ on the Qualcomm ADSP Hexagon core.
"qcom,msm8974-adsp-pil"
"qcom,msm8996-adsp-pil"
"qcom,msm8996-slpi-pil"
+   "qcom,sdm845-apss-adsp-pil"

Afaict there's nothing in this binding that ties this to the apss, so I
don't think we should base the compatible on this. The differentiation
is PAS vs non-PAS; so let's start naming the PAS variants
"qcom,platform-subsystem-pas" and the non-PAS
"qcom,platform-subsystem-pil" instead.

I.e. please make this "qcom,sdm845-adsp-pil".

More importantly, any resources such as clocks or reset lines should
come from DT and as such you need to extend the binding quite a bit -
which I suggest you do by introducing a new binding document.
Sure. Will create new dt-binding document with clocks and reset driver 
info added for sdm845 PIL.


  
  - interrupts-extended:

Usage: required
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 02627ed..759831b 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -14,7 +14,8 @@ obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
  obj-$(CONFIG_WKUP_M3_RPROC)   += wkup_m3_rproc.o
  obj-$(CONFIG_DA8XX_REMOTEPROC)+= da8xx_remoteproc.o
  obj-$(CONFIG_KEYSTONE_REMOTEPROC) += keystone_remoteproc.o
-obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp_pil.o
+obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp.o
+qcom_adsp-objs += qcom_adsp_pil.o 
qcom_adsp_pil_sdm845.o
  obj-$(CONFIG_QCOM_RPROC_COMMON)   += qcom_common.o
  obj-$(CONFIG_QCOM_Q6V5_PIL)   += qcom_q6v5_pil.o
  obj-$(CONFIG_QCOM_SYSMON) += qcom_sysmon.o
diff --git a/drivers/remoteproc/qcom_adsp_pil.c 
b/drivers/remoteproc/qcom_adsp_pil.c

I get the feeling that the main reason for modifying this file is its
name, not that it reduces the complexity of the final solution. I
definitely think it's cleaner to have some structural duplication and
keep this driver handling the various PAS based remoteprocs.
The main intention was to re-use exisiting APIs in PAS based PIL driver 
as the major change was
w.r.t. start and stop of ADSP firmware. Load(), interrupt handling and 
few other APIs will be same

as done in exisiting PAS based PIL driver.

Please see the RFC series I posted reducing the duplication between the
various "Q6V5 drivers".
I went through the RFC. Our code will fit into the design. However, we 
will still have some amount of code
duplication between PAS and Non-PAS ADSP PIL driver. Will this be fine? 
Please suggest.
Will wait for your response whether to write complete new driver or 
reuse exisitng one.



[..]

diff --git a/drivers/remoteproc/qcom_adsp_pil.h 
b/drivers/remoteproc/qcom_adsp_pil.h

[..]

+static inline void update_bits(void *reg, u32 mask_val, u32 set_val, u32 shift)
+{
+   u32 reg_val = 0;
+
+   reg_val = ((readl(reg)) & ~mask_val) | ((set_val << shift) & mask_val);
+   writel(reg_val, reg);
+}
+
+static inline unsigned int read_bit(void *reg, u32 mask, int shift)
+{
+   return ((readl(reg) & mask) >> shift);
+}

I don't like these helper functions, their prototype is nonstandard and
makes it really hard to read all the calling code.

I would prefer if you just inline the operations directly, to make it
clearer what's going on in each case - if not then at least follow the
prototype of e.g. regmap_udpate_bits(), which people might be used to.
Sure. Will update these APIs to follow standard format used in regmap 
and other drivers.

+
+#endif
diff --git a/drivers/remoteproc/qcom_adsp_pil_sdm845.c 
b/drivers/remoteproc/qcom_adsp_pil_sdm845.c
new file mode 100644
index 000..7518385
--- /dev/null
+++ b/drivers/remoteproc/qcom_adsp_pil_sdm845.c
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Qualcomm APSS Based ADSP bootup/shutdown ops for SDM845.
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+
+#include "qcom_adsp_pil.h"
+
+/* set values */
+#define CLK_ENABLE 0x1
+#define CLK_DISABLE0x0

Just write 0 and 1 in the code, it saves future readers the trouble of
having to remember if these are special in any way.

OK.

+/* time out value */
+#define ACK_TIMEOUT20

This is currently given in the rather awkward unit of 5uS. As it's input
to what should have been a call to readl_poll_timeout() please express
it in micro seconds.

sure. will do that in next patch

+/* mask values */
+#define 

[PATCH] ASoC: qcom: add sdm845 sound card support

2018-06-18 Thread Rohit kumar
This patch adds sdm845 audio machine driver support.

Signed-off-by: Rohit kumar 
---
 .../devicetree/bindings/sound/qcom,sdm845.txt  |  87 
 sound/soc/qcom/Kconfig |   9 +
 sound/soc/qcom/Makefile|   2 +
 sound/soc/qcom/sdm845.c| 539 +
 4 files changed, 637 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt
 create mode 100644 sound/soc/qcom/sdm845.c

diff --git a/Documentation/devicetree/bindings/sound/qcom,sdm845.txt 
b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
new file mode 100644
index 000..fc0e98c
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
@@ -0,0 +1,87 @@
+* Qualcomm Technologies Inc. SDM845 ASoC sound card driver
+
+This binding describes the SDM845 sound card, which uses qdsp for audio.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be "qcom,sdm845-sndcard"
+
+- qcom,audio-routing:
+   Usage: Optional
+   Value type: 
+   Definition:  A list of the connections between audio components.
+ Each entry is a pair of strings, the first being the
+ connection's sink, the second being the connection's
+ source. Valid names could be power supplies, MicBias
+ of codec and the jacks on the board.
+
+- cdc-vdd-supply:
+   Usage: Optional
+   Value type: 
+   Definition: phandle of regulator supply required for codec vdd.
+
+= dailinks
+Each subnode of sndcard represents either a dailink, and subnodes of each
+dailinks would be cpu/codec/platform dais.
+
+- link-name:
+   Usage: required
+   Value type: 
+   Definition: User friendly name for dai link
+
+= CPU, PLATFORM, CODEC dais subnodes
+- cpu:
+   Usage: required
+   Value type: 
+   Definition: cpu dai sub-node
+
+- codec:
+   Usage: required
+   Value type: 
+   Definition: codec dai sub-node
+
+- platform:
+   Usage: opional
+   Value type: 
+   Definition: platform dai sub-node
+
+- sound-dai:
+   Usage: required
+   Value type: 
+   Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
+
+Example:
+
+audio {
+   compatible = "qcom,sdm845-sndcard";
+   qcom,model = "sdm845-snd-card";
+   pinctrl-names = "pri_active", "pri_sleep";
+   pinctrl-0 = <_mi2s_active _mi2s_ws_active>;
+   pinctrl-1 = <_mi2s_sleep _mi2s_ws_sleep>;
+
+   qcom,audio-routing = "PRI_MI2S_RX Audio Mixer", "Pri-mi2s-gpio";
+
+   cdc-vdd-supply = <_l14>;
+
+   fe@1 {
+   link-name = "MultiMedia1";
+   cpu {
+   sound-dai = < MSM_FRONTEND_DAI_MULTIMEDIA1>;
+   };
+   platform {
+   sound-dai = <>;
+   };
+   };
+
+   be@1 {
+   link-name = "PRI MI2S Playback";
+   cpu {
+   sound-dai = < PRIMARY_MI2S_RX>;
+   };
+
+   platform {
+   sound-dai = <>;
+   };
+   };
+};
diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 87838fa..09de50d 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -90,3 +90,12 @@ config SND_SOC_MSM8996
   Support for Qualcomm Technologies LPASS audio block in
   APQ8096 SoC-based systems.
   Say Y if you want to use audio device on this SoCs
+
+config SND_SOC_SDM845
+   tristate "SoC Machine driver for SDM845 boards"
+   depends on QCOM_APR
+   select SND_SOC_QDSP6
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SDM845 SoC-based systems.
+  Say Y if you want to use audio device on this SoCs
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 206945b..ac9609e 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
+snd-soc-sdm845-objs := sdm845.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
++obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
 
 #DSP lib
 obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
new file mode 100644
index 000..70d2611
--- /dev/null
+++ b/sound/soc/qcom/sdm845.c
@@ -0,0 +1,539 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

Re: [RFC PATCH 3/5] remoteproc: qcom: adsp: Use common q6v5 helpers

2018-06-01 Thread Rohit Kumar

Hi Bjorn,

Reviewed and validated PAS and non-PAS ADSP PIL on sdm845 with the changes.

Adding tag.


On 5/23/2018 10:50 AM, Bjorn Andersson wrote:

Migrate the Hexagon V5 PAS (ADSP) driver to using the newly extracted
helper functions. The use of the handover callback does introduce latent
disabling of proxy resources. But apart from this there should be no
change in functionality.

Signed-off-by: Bjorn Andersson 

Reviewed-and-tested-by: Rohit kumar 

---
  drivers/remoteproc/Kconfig |   1 +
  drivers/remoteproc/qcom_adsp_pil.c | 156 +
  2 files changed, 28 insertions(+), 129 deletions(-)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 63b79ea91a21..d51d155cf8bd 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -93,6 +93,7 @@ config QCOM_ADSP_PIL
depends on QCOM_SYSMON || QCOM_SYSMON=n
select MFD_SYSCON
select QCOM_MDT_LOADER



Thanks,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [RFC PATCH 0/5] Hexagon remoteproc spring cleaning

2018-06-01 Thread Rohit Kumar

Thanks Bjorn for the cleanup.

I validated PAS and Non- PAS ADSP PIL with the cleanup changes on SDM845.

Adding tag for ADSP PIL.

Reviewed-and-tested-by: Rohit kumar 

On 5/23/2018 10:50 AM, Bjorn Andersson wrote:

With the introduction of support for the non-MSA Hexagon WCSS driver from
Sricharan and the non-PAS ADSP driver from Rohit it makes sense to overhaul the
structure of the Qualcomm "Q6V5 drivers".

The first patch is from Sricharan's series and included here for completeness.
The second patch introduces a set of helper functions, based on the current
state of the qcom_q6v5_pil driver. The third and forth patch migrates the PAS
and the MSA drivers over to using these helpers. Finally a (completely)
reworked version of Sricharan's WCSS remoteproc driver is introduced.


With this in place I suggest that we rename qcom_adsp_pil.c to qcom_q6v5_pas.c,


I am making changes for non-PAS ADSP PIL by creating new file.
In case you plan to rename qcom_adsp_pil.c to qcom_q6v5_pas, please 
include that change with this.
Also, let me know the filename which we should keep it for non-PAS ADSP 
PIL driver.

qcom_q6v5_pil.c to qcom_q6v5_msa.c and depending on the details of the non-PAS
ADSP we could potentially combine that into a qcom_q6v5_pil.c - or we carry
them as separate files.
I tried comparing qcom_q6v5_pil.c with non-PAS ADSP pil driver. I don't 
think that we can combine
them as there are good amount of code differences. However, we can take 
a look into it once

I post non-PAS ADSP PIL.


Looking at the remaining non-essential parts of these drivers we have
memory-region handling and halt_axi handling. The prior is actively being
worked on and the latter should (if no better abstraction is presented) be
possible to just put in the new qcom_q6v5.c.



Thanks,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH] ASoC: qcom: apq8096: set card as device drvdata

2018-06-06 Thread Rohit kumar
snd_soc_card is retrieved as device drvdata during unbind().
Set it as drvdata during bind() to avoid memory corruption during
unbind().

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/apq8096.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/qcom/apq8096.c b/sound/soc/qcom/apq8096.c
index 561cd42..239b8cb 100644
--- a/sound/soc/qcom/apq8096.c
+++ b/sound/soc/qcom/apq8096.c
@@ -140,6 +140,7 @@ static int apq8096_bind(struct device *dev)
 
component_bind_all(dev, card);
card->dev = dev;
+   dev_set_drvdata(dev, card);
ret = apq8096_sbc_parse_of(card);
if (ret) {
dev_err(dev, "Error parsing OF data\n");
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [PATCH] ASoC: qcom: add sdm845 sound card support

2018-06-19 Thread Rohit Kumar

Thanks Srinivas for reviewing.


On 6/19/2018 2:16 PM, Srinivas Kandagatla wrote:

Thanks Rohit for the patch!

On 18/06/18 12:16, Rohit kumar wrote:

This patch adds sdm845 audio machine driver support.

Signed-off-by: Rohit kumar 
---
  .../devicetree/bindings/sound/qcom,sdm845.txt  |  87 
  sound/soc/qcom/Kconfig |   9 +
  sound/soc/qcom/Makefile    |   2 +
  sound/soc/qcom/sdm845.c    | 539 
+

  4 files changed, 637 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/sound/qcom,sdm845.txt


Split the bindings into a separate patch!


Sure, will do it in next spin.



  create mode 100644 sound/soc/qcom/sdm845.c

diff --git a/Documentation/devicetree/bindings/sound/qcom,sdm845.txt 
b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt

new file mode 100644
index 000..fc0e98c
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
@@ -0,0 +1,87 @@
+* Qualcomm Technologies Inc. SDM845 ASoC sound card driver
+
+This binding describes the SDM845 sound card, which uses qdsp for 
audio.



[..]

+
+- codec:
+    Usage: required
+    Value type: 
+    Definition: codec dai sub-node
+
+- platform:
+    Usage: opional


Optional


okay

+    Value type: 
+    Definition: platform dai sub-node
+
+- sound-dai:
+    Usage: required
+    Value type: 
+    Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
+
+Example:
+
+audio {
+    compatible = "qcom,sdm845-sndcard";
+    qcom,model = "sdm845-snd-card";
+    pinctrl-names = "pri_active", "pri_sleep";
+    pinctrl-0 = <_mi2s_active _mi2s_ws_active>;
+    pinctrl-1 = <_mi2s_sleep _mi2s_ws_sleep>;
+
+    qcom,audio-routing = "PRI_MI2S_RX Audio Mixer", "Pri-mi2s-gpio";
+
+    cdc-vdd-supply = <_l14>;
+
+    fe@1 {

Lets not use fe or be reference here, its just a link.

okay




+    link-name = "MultiMedia1";
+    cpu {
+    sound-dai = < MSM_FRONTEND_DAI_MULTIMEDIA1>;
+    };
+    platform {
+    sound-dai = <>;
+    };
asmdai has sound-cell specifier as 1, so this will dtc will throw 
warning for this.


have a look at how 8996 is done.


ok, sure



+    };
+
+    be@1 {


[..]

diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 206945b..ac9609e 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o

  snd-soc-storm-objs := storm.o
  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
  snd-soc-apq8096-objs := apq8096.o
+snd-soc-sdm845-objs := sdm845.o
    obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
  obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
++obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o


?? looks like typo here.


Right. Will update.



    #DSP lib
  obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
new file mode 100644
index 000..70d2611
--- /dev/null
+++ b/sound/soc/qcom/sdm845.c
@@ -0,0 +1,539 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 

[..]

+}
+
+static int sdm845_snd_startup(struct snd_pcm_substream *substream)
+{
+    unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS;
+    struct snd_soc_pcm_runtime *rtd = substream->private_data;
+    struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+
+    pr_debug("%s: dai_id: 0x%x\n", __func__, cpu_dai->id);
+    switch (cpu_dai->id) {
+    case PRIMARY_MI2S_RX:
+    case PRIMARY_MI2S_TX:
+    mutex_lock(_mi2s_res_lock);


Mutex and atomic variables looks redundant here.
Can you explain why do you need both?

Right. Only mutex is required here. I will make count as non-atomic.



...

+
+static int sdm845_sbc_parse_of(struct snd_soc_card *card)
+{
+    struct device *dev = card->dev;
+    struct snd_soc_dai_link *link;
+    struct device_node *np, *codec, *platform, *cpu, *node;
+    int ret, num_links;
+    struct sdm845_snd_data *data;
+
+    ret = snd_soc_of_parse_card_name(card, "qcom,model");
+    if (ret) {
+    dev_err(dev, "Error parsing card name: %d\n", ret);
+    return ret;
+    }
+
+    node = dev->of_node;
+
+    /* DAPM routes */
+    if (of_property_read_bool(node, "qcom,audio-routing")) {
+    ret = snd_soc_of_parse_audio_routing(card,
+    "qcom,audio-routing");
+    if (ret)
+    return ret;
+    }
+
+    /* Populate links */
+    num_links = of_get_child_count(node);
+
+    dev_info(dev, "Found %d child audio dai links..\n", num_links);


Looks unnessary!


Ok . Will remove it in next patchset.



+
+    link->platform_of_node = of_parse_phandle(platform,
+  

Re: [alsa-devel] [PATCH] ASoC: qcom: add sdm845 sound card support

2018-06-19 Thread Rohit Kumar

Thanks Vinod for reviewing.


On 6/19/2018 10:35 AM, Vinod wrote:

On 18-06-18, 16:46, Rohit kumar wrote:


+struct sdm845_snd_data {
+   struct snd_soc_card *card;
+   struct regulator *vdd_supply;
+   struct snd_soc_dai_link dai_link[];
+};
+
+static struct mutex pri_mi2s_res_lock;
+static struct mutex quat_tdm_res_lock;

any reason why the locks can't be part of sdm845_snd_data?
Also why do we need two locks ?

No specific reason, I will move it to sdm845_snd_data.
These locks are used to protect enable/disable of bit clocks. We have 
Primary MI2S RX/TX
and Quaternary TDM RX/TX interfaces. For primary mi2s rx/tx, we have 
single clock which is
synchronized with pri_mi2s_res_lock. For Quat TDM RX/TX, we are using 
quat_tdm_res_lock.

We need two locks as we are protecting two different resources.



+static atomic_t pri_mi2s_clk_count;
+static atomic_t quat_tdm_clk_count;

Any specific reason for using atomic variables?
Nothing as such. As we are using mutex to synchronize, we can make it 
non- atomic.

Will do it in next-spin.



+static unsigned int tdm_slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
+
+static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+   int ret = 0;
+   int channels, slot_width;
+
+   channels = params_channels(params);
+   if (channels < 1 || channels > 8) {

I though ch = 0 would be caught by framework and IIRC ASoC doesn't
support more than 8 channels


OK. Will check and remove.

+   pr_err("%s: invalid param channels %d\n",
+   __func__, channels);
+   return -EINVAL;
+   }
+
+   switch (params_format(params)) {
+   case SNDRV_PCM_FORMAT_S32_LE:
+   case SNDRV_PCM_FORMAT_S24_LE:
+   case SNDRV_PCM_FORMAT_S16_LE:
+   slot_width = 32;
+   break;
+   default:
+   pr_err("%s: invalid param format 0x%x\n",
+   __func__, params_format(params));

why not use dev_err, bonus you get device name printer with the logs :)


Sure. Will change it.

+static int sdm845_snd_startup(struct snd_pcm_substream *substream)
+{
+   unsigned int fmt = SND_SOC_DAIFMT_CBS_CFS;
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+
+   pr_debug("%s: dai_id: 0x%x\n", __func__, cpu_dai->id);

It is good for debug but not very useful here, so removing it would be
good


OK

+   switch (cpu_dai->id) {
+   case PRIMARY_MI2S_RX:
+   case PRIMARY_MI2S_TX:
+   mutex_lock(_mi2s_res_lock);
+   if (atomic_inc_return(_mi2s_clk_count) == 1) {
+   snd_soc_dai_set_sysclk(cpu_dai,
+   Q6AFE_LPASS_CLK_ID_MCLK_1,
+   DEFAULT_MCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+   snd_soc_dai_set_sysclk(cpu_dai,
+   Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
+   DEFAULT_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+   }
+   mutex_unlock(_mi2s_res_lock);

why do we need locking here? Can you please explain that.
So, we can have two usecases: one with primary mi2s rx and other with 
primary mi2s tx.
Lock is required to increment  pri_mi2s_clk_count and enable clock so 
that disable of one

usecase does not disable the clock.



+   snd_soc_dai_set_fmt(cpu_dai, fmt);
+   break;

empty line after break helps in readability


Sure. Will add that change.

+static int sdm845_sbc_parse_of(struct snd_soc_card *card)
+{
+   struct device *dev = card->dev;
+   struct snd_soc_dai_link *link;
+   struct device_node *np, *codec, *platform, *cpu, *node;
+   int ret, num_links;
+   struct sdm845_snd_data *data;
+
+   ret = snd_soc_of_parse_card_name(card, "qcom,model");
+   if (ret) {
+   dev_err(dev, "Error parsing card name: %d\n", ret);
+   return ret;
+   }
+
+   node = dev->of_node;
+
+   /* DAPM routes */
+   if (of_property_read_bool(node, "qcom,audio-routing")) {
+   ret = snd_soc_of_parse_audio_routing(card,
+   "qcom,audio-routing");
+   if (ret)
+   return ret;
+   }

so if we dont find audio-routing, then? we seems to continue..

Right. Its not mandatory to have qcom,audio-routing in device tree.

Regards,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [PATCH v7 16/24] ASoC: qdsp6: q6asm: Add support to audio stream apis

2018-05-04 Thread Rohit Kumar



On 5/1/2018 5:38 PM, Srinivas Kandagatla wrote:

+static int __q6asm_run(struct audio_client *ac, uint32_t flags,
+ uint32_t msw_ts, uint32_t lsw_ts, bool wait)
+{
+   struct asm_session_cmd_run_v2 *run;
+   struct apr_pkt *pkt;
+   int pkt_size, rc;
+   void *p;
+
+   pkt_size = APR_HDR_SIZE + sizeof(*run);
+   p = kzalloc(pkt_size, GFP_KERNEL);

Should be GFP_ATOMIC as this API is also called from interrupt context

+   if (!p)
+   return -ENOMEM;
+

[..]

+int q6asm_read(struct audio_client *ac)
+{
+   struct asm_data_cmd_read_v2 *read;
+   struct audio_port_data *port;
+   struct audio_buffer *ab;
+   struct apr_pkt *pkt;
+   int pkt_size;
+   int rc = 0;
+   void *p;
+
+   if (!(ac->io_mode & ASM_SYNC_IO_MODE))
+   return 0;
+
+   pkt_size = APR_HDR_SIZE + sizeof(*read);
+   p = kzalloc(pkt_size, GFP_KERNEL);

same here. GFP_ATOMIC

+   if (!p)
+   return -ENOMEM;

[..]

+int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
+  uint32_t lsw_ts, uint32_t flags)
+{
+   struct asm_data_cmd_write_v2 *write;
+   struct audio_port_data *port;
+   struct audio_buffer *ab;
+   struct apr_pkt *pkt;
+   int pkt_size;
+   int rc = 0;
+   void *p;
+
+   pkt_size = APR_HDR_SIZE + sizeof(*write);
+   p = kzalloc(pkt_size, GFP_KERNEL);

GFP_ATOMIC

+   if (!p)
+   return -ENOMEM;


Thanks,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [RESEND PATCH v2 12/15] ASoC: qcom: qdsp6: Add support to q6asm dai driver

2018-01-13 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6asm dai driver which configures Q6ASM streams
to pass pcm data.
Currently the driver only exposes 2 playback streams for hdmi playback
support, it can be easily extended to add all 8 streams.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig   |   6 +
  sound/soc/qcom/qdsp6/Makefile|   1 +
  sound/soc/qcom/qdsp6/q6asm-dai.c | 534 +++
  3 files changed, 541 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6asm-dai.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 003ce182691c..ecd1e4ba834d 100644
--- a/sound/soc/qcom/Kconfig

[..]

+static void event_handler(uint32_t opcode, uint32_t token,
+ uint32_t *payload, void *priv)
+{
+   struct q6asm_dai_rtd *prtd = priv;
+   struct snd_pcm_substream *substream = prtd->substream;
+
+   switch (opcode) {
+   case ASM_CLIENT_EVENT_CMD_RUN_DONE:
+   q6asm_write_nolock(prtd->audio_client,
+  prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+   break;
+   case ASM_CLIENT_EVENT_CMD_EOS_DONE:
+   prtd->state = STOPPED;
+   break;

Add support for V2 version of opcode to support latest adsp

+   case ASM_CLIENT_EVENT_DATA_WRITE_DONE: {
+   prtd->pcm_irq_pos += prtd->pcm_count;
+   snd_pcm_period_elapsed(substream);
+   if (prtd->state == RUNNING)
+   q6asm_write_nolock(prtd->audio_client,
+  prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+
+   break;
+   }
+   default:
+   break;
+   }
+}
+
+static int q6asm_dai_prepare(struct snd_pcm_substream *substream)
+{
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
+   struct q6asm_dai_rtd *prtd = runtime->private_data;
+   struct q6asm_dai_data *pdata;
+   int ret;
+
+   pdata = dev_get_drvdata(soc_prtd->platform->dev);
+   if (!pdata)
+   return -EINVAL;
+
+   if (!prtd || !prtd->audio_client) {
+   pr_err("%s: private data null or audio client freed\n",
+   __func__);
+   return -EINVAL;
+   }
+
+   prtd->pcm_count = snd_pcm_lib_period_bytes(substream);
+   prtd->pcm_irq_pos = 0;
+   /* rate and channels are sent to audio driver */
+   if (prtd->state) {
+   /* clear the previous setup if any  */
+   q6asm_cmd(prtd->audio_client, CMD_CLOSE);
+   q6asm_unmap_memory_regions(substream->stream,
+  prtd->audio_client);
+   q6routing_dereg_phy_stream(soc_prtd->dai_link->id,
+SNDRV_PCM_STREAM_PLAYBACK);
+   }
+
+   ret = q6asm_map_memory_regions(substream->stream, prtd->audio_client,
+  prtd->phys,
+  (prtd->pcm_size / prtd->periods),
+  prtd->periods);
+
+   if (ret < 0) {
+   pr_err("Audio Start: Buffer Allocation failed rc = %d\n",
+   ret);
+   return -ENOMEM;
+   }
+
+   ret = q6asm_open_write(prtd->audio_client, FORMAT_LINEAR_PCM,
+  prtd->bits_per_sample);
+   if (ret < 0) {
+   pr_err("%s: q6asm_open_write failed\n", __func__);
+   q6asm_audio_client_free(prtd->audio_client);
+   prtd->audio_client = NULL;
+   return -ENOMEM;
+   }
+
+   prtd->session_id = q6asm_get_session_id(prtd->audio_client);
+   ret = q6routing_reg_phy_stream(soc_prtd->dai_link->id, LEGACY_PCM_MODE,
+ prtd->session_id, substream->stream);
+   if (ret) {
+   pr_err("%s: stream reg failed ret:%d\n", __func__, ret);
+   return ret;
+   }
+
+   ret = q6asm_media_format_block_multi_ch_pcm(
+   prtd->audio_client, runtime->rate,
+   runtime->channels, !prtd->set_channel_map,
+   prtd->channel_map, prtd->bits_per_sample);
+   if (ret < 0)
+   pr_info("%s: CMD Format block failed\n", __func__);
+
+   prtd->state = RUNNING;
+
+   return 0;
+}
+
+static int q6asm_dai_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+   int ret = 0;
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct q6asm_dai_rtd *prtd = runtime->private_data;
+
+   switch (cmd) {
+   case SNDRV_PCM_TRIGGER_START:
+   ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
+   

Re: [alsa-devel] [RESEND PATCH v2 08/15] ASoC: qcom: q6asm: add support to audio stream apis

2018-01-13 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to open, write and media format commands
in the q6asm module.

[..]

+static int32_t q6asm_callback(struct apr_device *adev,
+ struct apr_client_data *data, int session_id)
+{
+   struct audio_client *ac;// = (struct audio_client *)priv;
+   uint32_t token;
+   uint32_t *payload;
+   uint32_t wakeup_flag = 1;
+   uint32_t client_event = 0;
+   struct q6asm *q6asm = dev_get_drvdata(>dev);
+
+   if (data == NULL)
+   return -EINVAL;
+
+   ac = q6asm_get_audio_client(q6asm, session_id);
+   if (!q6asm_is_valid_audio_client(ac))
+   return -EINVAL;
+
ac could get freed by q6asm_audio_client_free during the execution of 
q6asm_callback as they are running in different thread.

Add synchronization.

+   payload = data->payload;
+
+   if (data->opcode == APR_BASIC_RSP_RESULT) {
+   token = data->token;
+   switch (payload[0]) {
+   case ASM_SESSION_CMD_PAUSE:
+   client_event = ASM_CLIENT_EVENT_CMD_PAUSE_DONE;
+   break;
+   case ASM_SESSION_CMD_SUSPEND:
+   client_event = ASM_CLIENT_EVENT_CMD_SUSPEND_DONE;
+   break;
+   case ASM_DATA_CMD_EOS:
+   client_event = ASM_CLIENT_EVENT_CMD_EOS_DONE;
+   break;
+   break;
+   case ASM_STREAM_CMD_FLUSH:
+   client_event = ASM_CLIENT_EVENT_CMD_FLUSH_DONE;
+   break;
+   case ASM_SESSION_CMD_RUN_V2:
+   client_event = ASM_CLIENT_EVENT_CMD_RUN_DONE;
+   break;
+
+   case ASM_STREAM_CMD_FLUSH_READBUFS:
+   if (token != ac->session) {
+   dev_err(ac->dev, "session invalid\n");
+   return -EINVAL;
+   }
+   case ASM_STREAM_CMD_CLOSE:
+   client_event = ASM_CLIENT_EVENT_CMD_CLOSE_DONE;
+   break;
+   case ASM_STREAM_CMD_OPEN_WRITE_V3:
+   case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
+   if (payload[1] != 0) {
+   dev_err(ac->dev,
+   "cmd = 0x%x returned error = 0x%x\n",
+   payload[0], payload[1]);
+   if (wakeup_flag) {
+   ac->cmd_state = payload[1];
+   wake_up(>cmd_wait);
+   }
+   return 0;
+   }
+   break;
+   default:
+   dev_err(ac->dev, "command[0x%x] not expecting rsp\n",
+   payload[0]);
+   break;
+   }
+
+   if (ac->cmd_state && wakeup_flag) {
+   ac->cmd_state = 0;
+   wake_up(>cmd_wait);
+   }
+   if (ac->cb)
+   ac->cb(client_event, data->token,
+  data->payload, ac->priv);
+
+   return 0;
+   }
+
+   switch (data->opcode) {
+   case ASM_DATA_EVENT_WRITE_DONE_V2:{
+   struct audio_port_data *port =
+   >port[SNDRV_PCM_STREAM_PLAYBACK];
+
+   client_event = ASM_CLIENT_EVENT_DATA_WRITE_DONE;
+
+   if (ac->io_mode & SYNC_IO_MODE) {
+   dma_addr_t phys = port->buf[data->token].phys;
+
+   if (lower_32_bits(phys) != payload[0] ||
+   upper_32_bits(phys) != payload[1]) {
+   dev_err(ac->dev, "Expected addr %pa\n",
+   >buf[data->token].phys);
+   return -EINVAL;
+   }
+   token = data->token;
+   port->buf[token].used = 1;
+   }
+   break;
+   }
+   }
+   if (ac->cb)
+   ac->cb(client_event, data->token, data->payload, ac->priv);
+
+   return 0;
+}
+

[..]

+/**
+ * q6asm_media_format_block_multi_ch_pcm() - setup pcm configuration
+ *
+ * @ac: audio client pointer
+ * @rate: audio sample rate
+ * @channels: number of audio channels.
+ * @use_default_chmap: flag to use default ch map.
+ * @channel_map: channel map pointer
+ * @bits_per_sample: bits per sample
+ *
+ * Return: Will be an negative value on error or zero on success
+ */
+int 

Re: [alsa-devel] [RESEND PATCH v2 11/15] ASoC: qcom: qdsp6: Add support to q6afe dai driver

2018-02-07 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6afe backend dais driver.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig   |   5 +
  sound/soc/qcom/qdsp6/Makefile|   1 +
  sound/soc/qcom/qdsp6/q6afe-dai.c | 241 +++
  3 files changed, 247 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6afe-dai.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index dd8fb0cde614..003ce182691c 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -64,6 +64,10 @@ config SND_SOC_QDSP6_ROUTING
tristate
default n
  
+config SND_SOC_QDSP6_AFE_DAI

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
select SND_SOC_QDSP6_AFE
@@ -71,6 +75,7 @@ config SND_SOC_QDSP6
select SND_SOC_QDSP6_ASM
select SND_SOC_QDSP6_CORE
select SND_SOC_QDSP6_ROUTING
+   select SND_SOC_QDSP6_AFE_DAI
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index c1ad060a2341..bd8bd02bf09e 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
  obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
  obj-$(CONFIG_SND_SOC_QDSP6_ROUTING) += q6routing.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE_DAI) += q6afe-dai.o
diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c
new file mode 100644
index ..e9865c684bcb
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
@@ -0,0 +1,241 @@
+/* SPDX-License-Identifier: GPL-2.0
+* Copyright (c) 2011-2016, The Linux Foundation
+* Copyright (c) 2017, Linaro Limited
+*/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6afe.h"
+
+struct q6hdmi_dai_data {
+   struct q6afe_port *port;
+   struct q6afe_hdmi_cfg port_config;
+   bool is_port_started;
+};
+
+static int q6hdmi_format_put(struct snd_kcontrol *kcontrol,
+   struct snd_ctl_elem_value *ucontrol)
+{
+   struct q6hdmi_dai_data *dai_data = kcontrol->private_data;
+   int value = ucontrol->value.integer.value[0];
+
+   dai_data->port_config.datatype = value;



+
+static struct platform_driver q6afe_dai_driver = {
+   .probe  = q6afe_dai_dev_probe,
+   .remove = q6afe_dai_dev_remove,
+   .driver = {
+   .name = "q6afe_dai",
+   .owner = THIS_MODULE,
+   },
+};
+
+module_platform_driver(q6afe_dai_driver);

MODULE_LICENSE missing.


Re: [alsa-devel] [RESEND PATCH v2 09/15] ASoC: qcom: qdsp6: Add support to Q6CORE

2018-02-07 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to core apr service, which is used to query
status of other static and dynamic services on the dsp.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig|   5 +
  sound/soc/qcom/qdsp6/Makefile |   1 +
  sound/soc/qcom/qdsp6/q6core.c | 227 ++
  3 files changed, 233 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6core.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 7ebdb879a8a3..121b9c957024 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -56,11 +56,16 @@ config SND_SOC_QDSP6_ASM
tristate
default n
  
+config SND_SOC_QDSP6_CORE

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
select SND_SOC_QDSP6_AFE
select SND_SOC_QDSP6_ADM
select SND_SOC_QDSP6_ASM
+   select SND_SOC_QDSP6_CORE
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index 49dd3ccab27b..ad7f10691e54 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -1,3 +1,4 @@
  obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
  obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
+obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c
new file mode 100644
index ..d4e2dbc62489
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6core.c
@@ -0,0 +1,227 @@
+/* SPDX-License-Identifier: GPL-2.0
+* Copyright (c) 2017, Linaro Limited
+*/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

[..]

+
+   dev_set_drvdata(>dev, core);
+
+   core->adev = adev;
+   init_waitqueue_head(>wait);
+
+   do {
+   if (!q6core_is_adsp_ready(core)) {
+   dev_info(>dev, "ADSP Audio isn't ready\n");
+   } else {
+   dev_info(>dev, "ADSP Audio is ready\n");
+
If q6core_is_adsp_ready() return failure, then we should not call and 
ADSP API.

+   ret = q6core_get_svc_versions(core);
+   if (!ret)
+   q6core_add_static_services(core);
+
+   break;
+   }
+   } while (time_after(timeout, jiffies));
+
I think we should defer probe if q6core_is_adsp_ready() returns failure 
and timeouts.

+   return ret;
+}
+
+static int q6core_exit(struct apr_device *adev)
+{
+   return 0;
+}
+
+static const struct apr_device_id core_id[] = {
+   {"Q6CORE", APR_DOMAIN_ADSP, APR_SVC_ADSP_CORE, APR_CLIENT_AUDIO},
+   { },
+};
+
+static struct apr_driver qcom_q6core_driver = {
+   .probe = q6core_probe,
+   .remove = q6core_exit,
+   .callback = core_callback,
+   .id_table = core_id,
+   .driver = {
+  .name = "qcom-q6core",
+  },
+};
+
+module_apr_driver(qcom_q6core_driver);
+
+MODULE_AUTHOR("Srinivas Kandagatla 

Re: [alsa-devel] [PATCH v3 24/25] ASoC: qcom: apq8096: Add db820c machine driver

2018-02-22 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to DB820c machine driver.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig   |   8 +++
  sound/soc/qcom/apq8096.c | 173 +++
  2 files changed, 181 insertions(+)
  create mode 100644 sound/soc/qcom/apq8096.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 8c2d65e0a28e..fa4b575c086c 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -77,3 +77,11 @@ config SND_SOC_QDSP6
 This will enable sound soc platform specific
 audio drivers. This includes q6asm, q6adm,
 q6afe interfaces to DSP using apr.
+
+config SND_SOC_MSM8996
+   tristate "SoC Machine driver for MSM8996 and APQ8096 boards"
+   depends on QCOM_APR
+   select SND_SOC_QDSP6V2

should be select SND_SOC_QDSP6, V2 is not defined

+   default n
+   help
+To add support for SoC audio on MSM8996 and APQ8096 boards



Re: [alsa-devel] [PATCH v3 12/25] ASoC: qcom: qdsp6: Add support to Q6CORE

2018-02-19 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to core apr service, which is used to query
status of other static and dynamic services on the dsp.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig|   5 +
  sound/soc/qcom/qdsp6/Makefile |   1 +
  sound/soc/qcom/qdsp6/q6core.c | 235 ++
  sound/soc/qcom/qdsp6/q6core.h |   9 ++
  4 files changed, 250 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6core.c
  create mode 100644 sound/soc/qcom/qdsp6/q6core.h

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a14d960b8fe4..8c2d65e0a28e 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -60,6 +60,10 @@ config SND_SOC_QDSP6_ASM
tristate
default n
  
+config SND_SOC_QDSP6_CORE

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
depends on QCOM_APR && HAS_DMA
@@ -67,6 +71,7 @@ config SND_SOC_QDSP6
select SND_SOC_QDSP6_AFE
select SND_SOC_QDSP6_ADM
select SND_SOC_QDSP6_ASM
+   select SND_SOC_QDSP6_CORE
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index eea962315ab3..61f089bc0d25 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o
  obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
  obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
+obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c
new file mode 100644
index ..d4a3ff409a34
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6core.c
@@ -0,0 +1,235 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2017, The Linux Foundation
+ * Copyright (c) 2018, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6dsp-errno.h"
+
+#define ADSP_STATE_READY_TIMEOUT_MS3000
+#define Q6_READY_TIMEOUT_MS 100
+#define AVCS_CMD_ADSP_EVENT_GET_STATE  0x0001290C
+#define AVCS_CMDRSP_ADSP_EVENT_GET_STATE   0x0001290D
+#define AVCS_GET_VERSIONS   0x00012905
+#define AVCS_GET_VERSIONS_RSP   0x00012906
+
+struct avcs_svc_info {
+   uint32_t service_id;
+   uint32_t version;
+} __packed;
+
+struct q6core {
+   struct apr_device *adev;
+   wait_queue_head_t wait;
+   uint32_t avcs_state;
+   bool resp_received;
+   uint32_t num_services;
+   struct avcs_svc_info *svcs_info;
+};
+
+struct q6core *core;
+
+static int q6core_callback(struct apr_device *adev,
+struct apr_client_message *data)
+{
+   struct q6core *core = dev_get_drvdata(>dev);
+   struct aprv2_ibasic_rsp_result_t *result;
+
+   result = data->payload;
+   switch (data->opcode) {
+   case AVCS_GET_VERSIONS_RSP:
+   core->num_services = result->status;
+
+   core->svcs_info = kcalloc(core->num_services,
+ sizeof(*core->svcs_info),
+ GFP_ATOMIC);
+   if (!core->svcs_info)
+   return -ENOMEM;
+
+   /* svc info is after apr result */
+   memcpy(core->svcs_info, result + sizeof(*result),
+  core->num_services * sizeof(*core->svcs_info));
+
+   core->resp_received = true;
+   wake_up(>wait);
+
+   break;
+   case AVCS_CMDRSP_ADSP_EVENT_GET_STATE:
+   core->avcs_state = result->opcode;
+
+   core->resp_received = true;
+   wake_up(>wait);
+   break;
+   default:
+   dev_err(>dev, "Message id from adsp core svc: 0x%x\n",
+   data->opcode);
+   break;
+   }
+
+   return 0;
+}
+
+static int q6core_get_svc_versions(struct q6core *core)
+{
+   struct apr_device *adev = core->adev;
+   struct apr_hdr hdr = {0};
+   int rc;
+
+   hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
+ APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
+   hdr.pkt_size = APR_HDR_SIZE;
+   hdr.opcode = AVCS_GET_VERSIONS;
+
+   rc = apr_send_pkt(adev, );
+   if (rc < 0)
+   return rc;
+
+   rc = wait_event_timeout(core->wait, (core->resp_received),
+   msecs_to_jiffies(Q6_READY_TIMEOUT_MS));
+   if (rc > 0 && core->resp_received) {
+   core->resp_received = false;
+   return 0;
+   }
+
+   return rc;
+}
+
+static bool __q6core_is_adsp_ready(struct 

Re: [alsa-devel] [PATCH v3 14/25] ASoC: qcom: qdsp6: Add support to q6afe dai driver

2018-02-19 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6afe backend dais driver.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/qdsp6/Makefile|   2 +-
  sound/soc/qcom/qdsp6/q6afe-dai.c | 280 +++
  sound/soc/qcom/qdsp6/q6afe.h |   3 +
  3 files changed, 284 insertions(+), 1 deletion(-)
  create mode 100644 sound/soc/qcom/qdsp6/q6afe-dai.c

diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index 660afcab98fd..c7833842b878 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -1,5 +1,5 @@
  obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o
-obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o q6afe-dai.o

depmod: ERROR: Cycle detected: q6afe -> q6afe_dai -> q6afe
need to use like:
+qdsp6_afe-objs := q6afe.o q6afe-dai.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE) += qdsp6_afe.o
similarly for asm and adm

  obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o q6routing.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
  obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c
new file mode 100644
index ..f6a618e9db9e
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2016, The Linux Foundation
+ * Copyright (c) 2018, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6afe.h"
+
+struct q6afe_dai_data {
+   struct q6afe_port *port[AFE_PORT_MAX];
+   struct q6afe_port_config port_config[AFE_PORT_MAX];
+   bool is_port_started[AFE_PORT_MAX];
+};
+
+static int q6hdmi_format_put(struct snd_kcontrol *kcontrol,
+   struct snd_ctl_elem_value *ucontrol)
+{
+   struct q6afe_dai_data *dai_data = kcontrol->private_data;
+   int value = ucontrol->value.integer.value[0];
+
+   dai_data->port_config[AFE_PORT_HDMI_RX].hdmi.datatype = value;
+
+   return 0;
+}
+
+static int q6hdmi_format_get(struct snd_kcontrol *kcontrol,
+   struct snd_ctl_elem_value *ucontrol)
+{
+
+   struct q6afe_dai_data *dai_data = kcontrol->private_data;
+
+   ucontrol->value.integer.value[0] =
+   dai_data->port_config[AFE_PORT_HDMI_RX].hdmi.datatype;
+
+   return 0;
+}
+
+static const char * const hdmi_format[] = {
+   "LPCM",
+   "Compr"
+};
+
+static const struct soc_enum hdmi_config_enum[] = {
+   SOC_ENUM_SINGLE_EXT(2, hdmi_format),
+};
+
+static const struct snd_kcontrol_new q6afe_config_controls[] = {
+   SOC_ENUM_EXT("HDMI RX Format", hdmi_config_enum[0],
+q6hdmi_format_get,
+q6hdmi_format_put),
+};
+
+static int q6hdmi_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params,
+   struct snd_soc_dai *dai)
+{
+   struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
+   int channels = params_channels(params);
+   struct q6afe_hdmi_cfg *hdmi = _data->port_config[dai->id].hdmi;
+
+   hdmi->sample_rate = params_rate(params);
+   switch (params_format(params)) {
+   case SNDRV_PCM_FORMAT_S16_LE:
+   hdmi->bit_width = 16;
+   break;
+   case SNDRV_PCM_FORMAT_S24_LE:
+   hdmi->bit_width = 24;
+   break;
+   }
+
+   /*refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4*/
+   switch (channels) {
+   case 2:
+   hdmi->channel_allocation = 0;
+   break;
+   case 3:
+   hdmi->channel_allocation = 0x02;
+   break;
+   case 4:
+   hdmi->channel_allocation = 0x06;
+   break;
+   case 5:
+   hdmi->channel_allocation = 0x0A;
+   break;
+   case 6:
+   hdmi->channel_allocation = 0x0B;
+   break;
+   case 7:
+   hdmi->channel_allocation = 0x12;
+   break;
+   case 8:
+   hdmi->channel_allocation = 0x13;
+   break;
+   default:
+   dev_err(dai->dev, "invalid Channels = %u\n", channels);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int q6afe_dai_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
+
+   dai_data->is_port_started[dai->id] = false;
+
+   return 0;
+}
+
+static void q6afe_dai_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct q6afe_dai_data *dai_data 

Re: [alsa-devel] [PATCH v3 05/25] ASoC: qcom: qdsp6: Add support to Q6AFE

2018-02-19 Thread Rohit Kumar


On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to Q6AFE (Audio Front End) module on Q6DSP.

AFE module sits right at the other end of cpu where the codec/audio
devices are connected.

AFE provides abstraced interfaces to both hardware and virtual devices.
Each AFE tx/rx port can be configured to connect to one of the hardware
devices like codec, hdmi, slimbus, i2s and so on. AFE services include
starting, stopping, and if needed, any configurations of the ports.

Signed-off-by: Srinivas Kandagatla 
---
  include/dt-bindings/sound/qcom,q6afe.h |   9 +
  sound/soc/qcom/Kconfig |   5 +
  sound/soc/qcom/Makefile|   5 +
  sound/soc/qcom/qdsp6/Makefile  |   1 +
  sound/soc/qcom/qdsp6/q6afe.c   | 520 +
  sound/soc/qcom/qdsp6/q6afe.h   |  37 +++
  6 files changed, 577 insertions(+)
  create mode 100644 include/dt-bindings/sound/qcom,q6afe.h
  create mode 100644 sound/soc/qcom/qdsp6/q6afe.c
  create mode 100644 sound/soc/qcom/qdsp6/q6afe.h

diff --git a/include/dt-bindings/sound/qcom,q6afe.h 
b/include/dt-bindings/sound/qcom,q6afe.h
new file mode 100644
index ..b4d82cccdc86
--- /dev/null
+++ b/include/dt-bindings/sound/qcom,q6afe.h
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef __DT_BINDINGS_Q6_AFE_H__
+#define __DT_BINDINGS_Q6_AFE_H__
+
+/* Audio Front End (AFE) Ports */
+#define AFE_PORT_HDMI_RX   8
+
+#endif /* __DT_BINDINGS_Q6_AFE_H__ */
+
diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index b01f347b427d..caeaf8b1b561 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -48,10 +48,15 @@ config SND_SOC_QDSP6_COMMON
tristate
default n
  
+config SND_SOC_QDSP6_AFE

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
depends on QCOM_APR && HAS_DMA
select SND_SOC_QDSP6_COMMON
+   select SND_SOC_QDSP6_AFE
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index d5280355c24f..748f5e891dcf 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -13,6 +13,11 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o
  # Machine
  snd-soc-storm-objs := storm.o
  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
+snd-soc-msm8996-objs := apq8096.o
  

This needs to be moved out of this patch

  obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
+obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-msm8996.o
+
+#DSP lib
+obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index accebdb49306..9ec951e0833b 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -1 +1,2 @@
  obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c
new file mode 100644
index ..0a5af06bb50e
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6afe.c
@@ -0,0 +1,520 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2017, The Linux Foundation
+ * Copyright (c) 2018, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6dsp-errno.h"
+#include "q6afe.h"
+
+/* AFE CMDs */
+#define AFE_PORT_CMD_DEVICE_START  0x000100E5
+#define AFE_PORT_CMD_DEVICE_STOP   0x000100E6
+#define AFE_PORT_CMD_SET_PARAM_V2  0x000100EF
+#define AFE_PORT_CMDRSP_GET_PARAM_V2   0x00010106
+#define AFE_PARAM_ID_HDMI_CONFIG   0x00010210
+#define AFE_MODULE_AUDIO_DEV_INTERFACE 0x0001020C
+
+/* Port IDs */
+#define AFE_API_VERSION_HDMI_CONFIG0x1
+#define AFE_PORT_ID_MULTICHAN_HDMI_RX  0x100E
+#define TIMEOUT_MS 1000
+#define AFE_CMD_RESP_AVAIL 0
+#define AFE_CMD_RESP_NONE  1
+
+struct q6afe {
+   struct apr_device *apr;
+   struct device *dev;
+   int state;
+   int status;
+
+   struct mutex lock;
+   struct list_head port_list;
+   spinlock_t port_list_lock;
+   struct list_head node;
+   void *dai_data;
+};
+
+struct afe_port_cmd_device_start {
+   struct apr_hdr hdr;
+   u16 port_id;
+   u16 reserved;
+} __packed;
+
+struct afe_port_cmd_device_stop {
+   struct apr_hdr hdr;
+   u16 port_id;
+   u16 reserved;
+/* Reserved for 32-bit alignment. This field must be set to 0.*/
+} __packed;
+
+struct afe_port_param_data_v2 {
+   u32 module_id;
+   u32 param_id;
+   u16 param_size;
+   u16 reserved;
+} __packed;
+
+struct afe_port_cmd_set_param_v2 {
+   u16 port_id;
+   u16 payload_size;
+   u32 payload_address_lsw;

Re: [alsa-devel] [PATCH v3 15/25] ASoC: qcom: qdsp6: Add support to q6asm dai driver

2018-02-21 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6asm dai driver which configures Q6ASM streams
to pass pcm data.

Signed-off-by: Srinivas Kandagatla 

[..]

diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
new file mode 100644
index ..7c5e94b2ced4
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
@@ -0,0 +1,621 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2016, The Linux Foundation
+ * Copyright (c) 2017, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

[..]

+static struct snd_pcm_hw_constraint_list constraints_sample_rates = {
+   .count = ARRAY_SIZE(supported_sample_rates),
+   .list = supported_sample_rates,
+   .mask = 0,
+};
+
+static void event_handler(uint32_t opcode, uint32_t token,
+ uint32_t *payload, void *priv)
+{
+   struct q6asm_dai_rtd *prtd = priv;
+   struct snd_pcm_substream *substream = prtd->substream;
+
+   switch (opcode) {
+   case ASM_CLIENT_EVENT_CMD_RUN_DONE:

Need to add support for V2 version of opcodes

+   q6asm_write_async(prtd->audio_client,
+  prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+   break;
+   case ASM_CLIENT_EVENT_CMD_EOS_DONE:
+   prtd->state = Q6ASM_STREAM_STOPPED;
+   break;
+   case ASM_CLIENT_EVENT_DATA_WRITE_DONE: {
+   prtd->pcm

[..]

+
+static int q6asm_dai_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+   int ret = 0;
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct q6asm_dai_rtd *prtd = runtime->private_data;
+
+   switch (cmd) {
+   case SNDRV_PCM_TRIGGER_START:
+   ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
+   break;

below two cases can be combined with START if no change

+   case SNDRV_PCM_TRIGGER_RESUME:
+   case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+   ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
+   break;
+   case SNDRV_PCM_TRIGGER_STOP:
+   prtd->state = Q6ASM_STREAM_STOPPED;
+   ret = q6asm_cmd_nowait(prtd->audio_client, CMD_EOS);
+   break;
+   case SNDRV_PCM_TRIGGER_SUSPEND:
+   case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+   ret = q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE);
+   break;
+   default:
+   ret = -EINVAL;
+   break;
+   }
+
+   return ret;
+}
+
+static int q6asm_dai_open(struct snd_pcm_substream *substream)
+{
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = soc_prtd->cpu_dai;
+
+   struct q6asm_dai_rtd *prtd;
+   struct q6asm_dai_data *pdata;
+   struct device *dev = soc_prtd->platform->dev;
+   int ret = 0;
+   int stream_id;
+
+   stream_id = cpu_dai->driver->id;
+
+   pdata = q6asm_get_dai_data(dev);
+   if (!pdata) {
+   pr_err("Platform data not found ..\n");
+   return -EINVAL;
+   }
+
+   prtd = kzalloc(sizeof(struct q6asm_dai_rtd), GFP_KERNEL);
+   if (prtd == NULL)
+   return -ENOMEM;
+
+   prtd->substream = substream;
+   prtd->audio_client = q6asm_audio_client_alloc(dev,
+   (q6asm_cb)event_handler, prtd, stream_id);
+   if (!prtd->audio_client) {
+   pr_info("%s: Could not allocate memory\n", __func__);
+   kfree(prtd);
+   return -ENOMEM;
+   }
+
+// prtd->audio_client->dev = dev;

cleanup this

+
+   if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+   runtime->hw = q6asm_dai_hardware_playback;
+
+   ret = snd_pcm_hw_constraint_list(runtime, 0,
+   SNDRV_PCM_HW_PARAM_RATE,
+   _sample_rates);

[..]

+
+static int q6asm_dai_pcm_new(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_pcm_substream *substream;
+   struct of_phandle_args args;
+   struct device_node *node;
+   struct q6asm_dai_data *pdata;
+   struct snd_pcm *pcm = rtd->pcm;
+   struct device *dev;
+   int size, ret;
+
+   dev = rtd->platform->dev->parent;
+   node = dev->of_node;
+   pdata = q6asm_get_dai_data(rtd->platform->dev);
+
+   ret = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, );
+   if (ret < 0)
+   pdata->sid = -1;
+   else
+   pdata->sid = args.args[0];
+
+
+
iommus for sdm845 is 16bit value. we need to have sid_mask which is 0x1 
in sdm845. We need to mask sid with 0x1 to get proper sid.

pdata->sid &= 0x1;

+   substream = 

[PATCH v2 1/2] ASoC: qcom: dt-bindings: Add sdm845 machine bindings

2018-06-21 Thread Rohit kumar
Add devicetree bindings documentation file for SDM845 sound card.

Signed-off-by: Rohit kumar 
---
 .../devicetree/bindings/sound/qcom,sdm845.txt  | 82 ++
 1 file changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt

diff --git a/Documentation/devicetree/bindings/sound/qcom,sdm845.txt 
b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
new file mode 100644
index 000..68feb08
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
@@ -0,0 +1,82 @@
+* Qualcomm Technologies Inc. SDM845 ASoC sound card driver
+
+This binding describes the SDM845 sound card, which uses qdsp for audio.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be "qcom,sdm845-sndcard"
+
+- qcom,audio-routing:
+   Usage: Optional
+   Value type: 
+   Definition:  A list of the connections between audio components.
+ Each entry is a pair of strings, the first being the
+ connection's sink, the second being the connection's
+ source. Valid names could be power supplies, MicBias
+ of codec and the jacks on the board.
+
+- cdc-vdd-supply:
+   Usage: Optional
+   Value type: 
+   Definition: phandle of regulator supply required for codec vdd.
+
+= dailinks
+Each subnode of sndcard represents either a dailink, and subnodes of each
+dailinks would be cpu/codec/platform dais.
+
+- link-name:
+   Usage: required
+   Value type: 
+   Definition: User friendly name for dai link
+
+= CPU, PLATFORM, CODEC dais subnodes
+- cpu:
+   Usage: required
+   Value type: 
+   Definition: cpu dai sub-node
+
+- codec:
+   Usage: required
+   Value type: 
+   Definition: codec dai sub-node
+
+- platform:
+   Usage: Optional
+   Value type: 
+   Definition: platform dai sub-node
+
+- sound-dai:
+   Usage: required
+   Value type: 
+   Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
+
+Example:
+
+audio {
+   compatible = "qcom,sdm845-sndcard";
+   qcom,model = "sdm845-snd-card";
+   pinctrl-names = "default", "sleep";
+   pinctrl-0 = <_mi2s_active _mi2s_ws_active>;
+   pinctrl-1 = <_mi2s_sleep _mi2s_ws_sleep>;
+
+   cdc-vdd-supply = <_l14>;
+
+   mm1-dai-link {
+   link-name = "MultiMedia1";
+   cpu {
+   sound-dai = < MSM_FRONTEND_DAI_MULTIMEDIA1>;
+   };
+   };
+
+   pri-mi2s-dai-link {
+   link-name = "PRI MI2S Playback";
+   cpu {
+   sound-dai = < PRIMARY_MI2S_RX>;
+   };
+
+   platform {
+   sound-dai = <>;
+   };
+   };
+};
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v2 0/2] Add support for audio on SDM845 SoC

2018-06-21 Thread Rohit kumar
This provides initial patchset to support audio on
Qualcomm Techonologies Inc. SDM845 SoC. Currently, it supports
audio playback/capture over Primary MI2S and Quaternary
TDM ports.
Changes since v1:
Addressed comments posted by Vinod and Srinivas.

Rohit kumar (2):
  ASoC: qcom: dt-bindings: Add sdm845 machine bindings
  ASoC: qcom: add sdm845 sound card support

 .../devicetree/bindings/sound/qcom,sdm845.txt  |  82 
 sound/soc/qcom/Kconfig |   9 +
 sound/soc/qcom/Makefile|   2 +
 sound/soc/qcom/sdm845.c| 514 +
 4 files changed, 607 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt
 create mode 100644 sound/soc/qcom/sdm845.c

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v2 2/2] ASoC: qcom: add sdm845 sound card support

2018-06-21 Thread Rohit kumar
This patch adds sdm845 audio machine driver support.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Kconfig  |   9 +
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sdm845.c | 514 
 3 files changed, 525 insertions(+)
 create mode 100644 sound/soc/qcom/sdm845.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 87838fa..09de50d 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -90,3 +90,12 @@ config SND_SOC_MSM8996
   Support for Qualcomm Technologies LPASS audio block in
   APQ8096 SoC-based systems.
   Say Y if you want to use audio device on this SoCs
+
+config SND_SOC_SDM845
+   tristate "SoC Machine driver for SDM845 boards"
+   depends on QCOM_APR
+   select SND_SOC_QDSP6
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SDM845 SoC-based systems.
+  Say Y if you want to use audio device on this SoCs
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 206945b..07f097a 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
+snd-soc-sdm845-objs := sdm845.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
+obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
 
 #DSP lib
 obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
new file mode 100644
index 000..531af82
--- /dev/null
+++ b/sound/soc/qcom/sdm845.c
@@ -0,0 +1,514 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "qdsp6/q6afe.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  24576000
+#define DEFAULT_BCLK_RATE  1536000
+
+struct sdm845_snd_data {
+   struct snd_soc_card *card;
+   struct regulator *vdd_supply;
+   uint32_t pri_mi2s_clk_count;
+   uint32_t quat_tdm_clk_count;
+   struct snd_soc_dai_link dai_link[];
+};
+
+
+static unsigned int tdm_slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
+
+static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+   int ret = 0;
+   int channels, slot_width;
+
+   switch (params_format(params)) {
+   case SNDRV_PCM_FORMAT_S32_LE:
+   case SNDRV_PCM_FORMAT_S24_LE:
+   case SNDRV_PCM_FORMAT_S16_LE:
+   slot_width = 32;
+   break;
+   default:
+   dev_err(rtd->dev, "%s: invalid param format 0x%x\n",
+   __func__, params_format(params));
+   return -EINVAL;
+   }
+
+   channels = params_channels(params);
+   if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0x3,
+   channels, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
+   channels, tdm_slot_offset);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   } else {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0,
+   channels, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, channels,
+   tdm_slot_offset, 0, NULL);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   }
+end:
+   return ret;
+}
+
+static int sdm845_snd_hw_params(struct snd_pcm_substream *substream,
+ 

Re: [alsa-devel] [PATCH v2 2/2] ASoC: qcom: add sdm845 sound card support

2018-06-22 Thread Rohit Kumar




On 6/21/2018 8:39 PM, Srinivas Kandagatla wrote:



On 21/06/18 13:35, Vinod wrote:
And this one is generic DT parsing and seems quite similar to one in 
apq8096.c

Can we move these into a lib and use them instead of duplicating.
I totally agree with Vinod, We should probably come up with a library 
functions something like common.c so that we do not duplicate code.

This code is going be exactly same for most of the SoCs using qdsp.

Sure, I will add a new file, qcom_snd_common.c, which will have these 
common functions and will update apq8096 and sdm845 machine driver to use

APIs exposed by qcom_snd_common.c


thanks,
srini

___
Alsa-devel mailing list
alsa-de...@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel


Regards,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [PATCH v2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-08-03 Thread Rohit Kumar

Hello Bjorn,


Can you please let us know the suggest the file name and review the patch.


On 7/9/2018 11:29 AM, Rohit Kumar wrote:

Thanks Rob for reviewing.


On 7/7/2018 2:02 AM, Rob Herring wrote:

On Fri, Jun 29, 2018 at 02:50:53PM +0530, Rohit kumar wrote:

This adds APSS based ADSP PIL driver for QCOM SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 
---
Changes since v1:
- Used APIs from qcom_q6v5.c
- Use clock, reset and regmap driver APIs instead of
   directly writing into the LPASS registers.
- Created new file for non PAS ADSP PIL instead of extending
   existing ADSP PIL driver.
- cleanups as suggested by Bjorn and Rob.

  .../bindings/remoteproc/qcom,non-pas-adsp.txt  | 138 +

This should be a separate patch.


Ok. Will separate it in next spin.

drivers/remoteproc/Kconfig |  18 +
  drivers/remoteproc/Makefile    |   1 +
  drivers/remoteproc/qcom_nonpas_adsp_pil.c  | 667 
+

  4 files changed, 824 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt

  create mode 100644 drivers/remoteproc/qcom_nonpas_adsp_pil.c

diff --git 
a/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt

new file mode 100644
index 000..0581aaa
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt

@@ -0,0 +1,138 @@
+Qualcomm Technology Inc. Non PAS ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and 
boots firmware

+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+    Usage: required
+    Value type: 
+    Definition: must be one of:
+    "qcom,sdm845-apss-adsp-pil"

Didn't Bjorn say to drop the 'apss' part?


Yes, he had asked to rename compatible string for  existing PIL driver 
as "qcom,platform-subsystem-pas"
and non-pas pil driver as "qcom,platform-subsystem-pil". I wanted to 
get confirmation from Bjorn whether

we should rename the filename too.
@Bjorn, can you please suggest filename and compatible strings for the 
two drivers.

+
+- reg:
+    Usage: required
+    Value type: 
+    Definition: must specify the base address and size of the qdsp6ss
+
+- reg-names:
+    Usage: required
+    Value type: 
+    Definition: must be "qdsp6ss"
+


--
To unsubscribe from this list: send the line "unsubscribe 
linux-remoteproc" in

the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html


Thanks,
Rohit





Re: [PATCH v4 4/4] ASoC: qcom: add sdm845 sound card support

2018-08-01 Thread Rohit Kumar



On 8/1/2018 10:20 AM, Takashi Iwai wrote:

On Wed, 01 Aug 2018 05:46:48 +0200,
kbuild test robot wrote:

Hi Rohit,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on asoc/for-next]
[also build test WARNING on next-20180731]
[cannot apply to v4.18-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Rohit-kumar/Add-support-for-audio-on-SDM845-SoC/20180801-082203
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 
for-next
reproduce:
 # apt-get install sparse
 make ARCH=x86_64 allmodconfig
 make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)


sound/soc/qcom/sdm845.c:193:27: sparse: incorrect type in argument 2 (different 
base types) @@expected unsigned int [unsigned] val @@got restricted 
snd_unsigned int [unsigned] val @@

sound/soc/qcom/sdm845.c:193:27:expected unsigned int [unsigned] val
sound/soc/qcom/sdm845.c:193:27:got restricted snd_pcm_format_t [usertype] 


vim +193 sound/soc/qcom/sdm845.c

181 
182 static int sdm845_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
183 struct snd_pcm_hw_params *params)
184 {
185 struct snd_interval *rate = hw_param_interval(params,
186 SNDRV_PCM_HW_PARAM_RATE);
187 struct snd_interval *channels = hw_param_interval(params,
188 SNDRV_PCM_HW_PARAM_CHANNELS);
189 struct snd_mask *fmt = hw_param_mask(params, 
SNDRV_PCM_HW_PARAM_FORMAT);
190 
191 rate->min = rate->max = DEFAULT_SAMPLE_RATE_48K;
192 channels->min = channels->max = 2;
  > 193  snd_mask_set(fmt, SNDRV_PCM_FORMAT_S16_LE);

FYI, we have introduced a new helper, snd_mask_set_format(), just for
avoiding this sparse warning.  It's already in Mark's for-next tree.

Thanks Takashi for API suggestion. I will update in next spin.


thanks,

Takashi




[PATCH v5 1/4] ASoC: qcom: dt-bindings: Add sdm845 machine bindings

2018-08-01 Thread Rohit kumar
Add devicetree bindings documentation file for SDM845 sound card.

Reviewed-by: Rob Herring 
Signed-off-by: Rohit kumar 
---
 .../devicetree/bindings/sound/qcom,sdm845.txt  | 80 ++
 1 file changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt

diff --git a/Documentation/devicetree/bindings/sound/qcom,sdm845.txt 
b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
new file mode 100644
index 000..408c483
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
@@ -0,0 +1,80 @@
+* Qualcomm Technologies Inc. SDM845 ASoC sound card driver
+
+This binding describes the SDM845 sound card, which uses qdsp for audio.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be "qcom,sdm845-sndcard"
+
+- audio-routing:
+   Usage: Optional
+   Value type: 
+   Definition:  A list of the connections between audio components.
+ Each entry is a pair of strings, the first being the
+ connection's sink, the second being the connection's
+ source. Valid names could be power supplies, MicBias
+ of codec and the jacks on the board.
+
+- model:
+   Usage: required
+   Value type: 
+   Definition: The user-visible name of this sound card.
+
+= dailinks
+Each subnode of sndcard represents either a dailink, and subnodes of each
+dailinks would be cpu/codec/platform dais.
+
+- link-name:
+   Usage: required
+   Value type: 
+   Definition: User friendly name for dai link
+
+= CPU, PLATFORM, CODEC dais subnodes
+- cpu:
+   Usage: required
+   Value type: 
+   Definition: cpu dai sub-node
+
+- codec:
+   Usage: required
+   Value type: 
+   Definition: codec dai sub-node
+
+- platform:
+   Usage: Optional
+   Value type: 
+   Definition: platform dai sub-node
+
+- sound-dai:
+   Usage: required
+   Value type: 
+   Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
+
+Example:
+
+audio {
+   compatible = "qcom,sdm845-sndcard";
+   model = "sdm845-snd-card";
+   pinctrl-names = "default", "sleep";
+   pinctrl-0 = <_mi2s_active _mi2s_ws_active>;
+   pinctrl-1 = <_mi2s_sleep _mi2s_ws_sleep>;
+
+   mm1-dai-link {
+   link-name = "MultiMedia1";
+   cpu {
+   sound-dai = < MSM_FRONTEND_DAI_MULTIMEDIA1>;
+   };
+   };
+
+   pri-mi2s-dai-link {
+   link-name = "PRI MI2S Playback";
+   cpu {
+   sound-dai = < PRIMARY_MI2S_RX>;
+   };
+
+   platform {
+   sound-dai = <>;
+   };
+   };
+};
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v5 0/4] Add support for audio on SDM845 SoC

2018-08-01 Thread Rohit kumar
This provides initial patchset to support audio on
Qualcomm Techonologies Inc. SDM845 SoC. Currently, it supports
audio playback/capture over Primary MI2S and Quaternary
TDM ports.

Changes since v4:
- Used snd_mask_set_format() instead of snd_mask_set() to avoid sparse warning.

Rohit kumar (4):
  ASoC: qcom: dt-bindings: Add sdm845 machine bindings
  ASoC: dt-bindings: Update dt binding name for apq8096
  ASoC: qcom: Add support to parse common audio device nodes
  ASoC: qcom: add sdm845 sound card support

 .../devicetree/bindings/sound/qcom,apq8096.txt |  15 +-
 .../devicetree/bindings/sound/qcom,sdm845.txt  |  80 ++
 sound/soc/qcom/Kconfig |   8 +
 sound/soc/qcom/Makefile|   4 +-
 sound/soc/qcom/apq8096.c   | 111 +---
 sound/soc/qcom/common.c| 112 
 sound/soc/qcom/common.h|  12 +
 sound/soc/qcom/sdm845.c| 286 +
 8 files changed, 525 insertions(+), 103 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt
 create mode 100644 sound/soc/qcom/common.c
 create mode 100644 sound/soc/qcom/common.h
 create mode 100644 sound/soc/qcom/sdm845.c

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v5 3/4] ASoC: qcom: Add support to parse common audio device nodes

2018-08-01 Thread Rohit kumar
This adds support to parse cpu, platform and codec
device nodes and add them in dai-links. Also, update
apq8096 machine driver to use the common API.

Acked-by: Srinivas Kandagatla 
Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Makefile  |   2 +-
 sound/soc/qcom/apq8096.c | 111 +-
 sound/soc/qcom/common.c  | 112 +++
 sound/soc/qcom/common.h  |  12 +
 4 files changed, 136 insertions(+), 101 deletions(-)
 create mode 100644 sound/soc/qcom/common.c
 create mode 100644 sound/soc/qcom/common.h

diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 206945b..fefecc0 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += snd-soc-lpass-apq8016.o
 # Machine
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
-snd-soc-apq8096-objs := apq8096.o
+snd-soc-apq8096-objs := apq8096.o common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
diff --git a/sound/soc/qcom/apq8096.c b/sound/soc/qcom/apq8096.c
index a561562..1e4a90d 100644
--- a/sound/soc/qcom/apq8096.c
+++ b/sound/soc/qcom/apq8096.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include "common.h"
 
 static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  struct snd_pcm_hw_params *params)
@@ -24,109 +25,16 @@ static int apq8096_be_hw_params_fixup(struct 
snd_soc_pcm_runtime *rtd,
return 0;
 }
 
-static int apq8096_sbc_parse_of(struct snd_soc_card *card)
+static void apq8096_add_be_ops(struct snd_soc_card *card)
 {
-   struct device_node *np;
-   struct device_node *codec = NULL;
-   struct device_node *platform = NULL;
-   struct device_node *cpu = NULL;
-   struct device *dev = card->dev;
-   struct snd_soc_dai_link *link;
-   int ret, num_links;
-
-   ret = snd_soc_of_parse_card_name(card, "qcom,model");
-   if (ret) {
-   dev_err(dev, "Error parsing card name: %d\n", ret);
-   return ret;
-   }
-
-   /* DAPM routes */
-   if (of_property_read_bool(dev->of_node, "qcom,audio-routing")) {
-   ret = snd_soc_of_parse_audio_routing(card,
-   "qcom,audio-routing");
-   if (ret)
-   return ret;
-   }
-
-   /* Populate links */
-   num_links = of_get_child_count(dev->of_node);
-
-   /* Allocate the DAI link array */
-   card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
-   if (!card->dai_link)
-   return -ENOMEM;
+   struct snd_soc_dai_link *link = card->dai_link;
+   int i, num_links = card->num_links;
 
-   card->num_links = num_links;
-   link = card->dai_link;
-
-   for_each_child_of_node(dev->of_node, np) {
-   cpu = of_get_child_by_name(np, "cpu");
-   if (!cpu) {
-   dev_err(dev, "Can't find cpu DT node\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
-   if (!link->cpu_of_node) {
-   dev_err(card->dev, "error getting cpu phandle\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   ret = snd_soc_of_get_dai_name(cpu, >cpu_dai_name);
-   if (ret) {
-   dev_err(card->dev, "error getting cpu dai name\n");
-   goto err;
-   }
-
-   platform = of_get_child_by_name(np, "platform");
-   codec = of_get_child_by_name(np, "codec");
-   if (codec && platform) {
-   link->platform_of_node = of_parse_phandle(platform,
- "sound-dai",
-  0);
-   if (!link->platform_of_node) {
-   dev_err(card->dev, "platform dai not found\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
-   if (ret < 0) {
-   dev_err(card->dev, "codec dai not found\n");
-   goto err;
-   }
-   link->no_pcm = 1;
-   link->ignore_pmdown_time = 1;
+   for (i = 0; i < num_links; i++) {
+   if (link->

[PATCH v5 2/4] ASoC: dt-bindings: Update dt binding name for apq8096

2018-08-01 Thread Rohit kumar
Remove qcom prefix from machine driver dt bindings of
apq8096 SoC.

Acked-by: Srinivas Kandagatla 
Reviewed-by: Rob Herring 
Signed-off-by: Rohit kumar 
---
 Documentation/devicetree/bindings/sound/qcom,apq8096.txt | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/qcom,apq8096.txt 
b/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
index c7600a9..c814e86 100644
--- a/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
+++ b/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
@@ -7,7 +7,7 @@ This binding describes the APQ8096 sound card, which uses qdsp 
for audio.
Value type: 
Definition: must be "qcom,apq8096-sndcard"
 
-- qcom,audio-routing:
+- audio-routing:
Usage: Optional
Value type: 
Definition:  A list of the connections between audio components.
@@ -49,6 +49,12 @@ This binding describes the APQ8096 sound card, which uses 
qdsp for audio.
"DMIC1"
"DMIC2"
"DMIC3"
+
+- model:
+   Usage: required
+   Value type: 
+   Definition: The user-visible name of this sound card.
+
 = dailinks
 Each subnode of sndcard represents either a dailink, and subnodes of each
 dailinks would be cpu/codec/platform dais.
@@ -79,11 +85,16 @@ dailinks would be cpu/codec/platform dais.
Value type: 
Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
 
+Obsolete:
+   qcom,model: String for soundcard name (Use model instead)
+   qcom,audio-routing: A list of the connections between audio components.
+   (Use audio-routing instead)
+
 Example:
 
 audio {
compatible = "qcom,apq8096-sndcard";
-   qcom,model = "DB820c";
+   model = "DB820c";
 
mm1-dai-link {
link-name = "MultiMedia1";
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v5 4/4] ASoC: qcom: add sdm845 sound card support

2018-08-01 Thread Rohit kumar
This patch adds sdm845 audio machine driver support.

Acked-by: Srinivas Kandagatla 
Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Kconfig  |   8 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sdm845.c | 286 
 3 files changed, 296 insertions(+)
 create mode 100644 sound/soc/qcom/sdm845.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 87838fa..3507308 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -90,3 +90,11 @@ config SND_SOC_MSM8996
   Support for Qualcomm Technologies LPASS audio block in
   APQ8096 SoC-based systems.
   Say Y if you want to use audio device on this SoCs
+
+config SND_SOC_SDM845
+   tristate "SoC Machine driver for SDM845 boards"
+   select SND_SOC_QDSP6
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SDM845 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index fefecc0..f0e94d4 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o common.o
+snd-soc-sdm845-objs := sdm845.o common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
+obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
 
 #DSP lib
 obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
new file mode 100644
index 000..bf4ec4646
--- /dev/null
+++ b/sound/soc/qcom/sdm845.c
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "common.h"
+#include "qdsp6/q6afe.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  24576000
+#define DEFAULT_BCLK_RATE  12288000
+
+struct sdm845_snd_data {
+   struct snd_soc_card *card;
+   uint32_t pri_mi2s_clk_count;
+   uint32_t quat_tdm_clk_count;
+};
+
+static unsigned int tdm_slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
+
+static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+   int ret = 0;
+   int channels, slot_width;
+
+   switch (params_format(params)) {
+   case SNDRV_PCM_FORMAT_S16_LE:
+   slot_width = 32;
+   break;
+   default:
+   dev_err(rtd->dev, "%s: invalid param format 0x%x\n",
+   __func__, params_format(params));
+   return -EINVAL;
+   }
+
+   channels = params_channels(params);
+   if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0x3,
+   8, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
+   channels, tdm_slot_offset);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   } else {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0,
+   8, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, channels,
+   tdm_slot_offset, 0, NULL);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   }
+end:
+   return ret;
+}
+
+static int sdm845_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_d

[PATCH] ASoC: qcom: Fix unmet dependency warning for SND_SOC_SDM845

2018-08-02 Thread Rohit kumar
Add DEPENDS_ON QCOM_APR for SND_SOC_SDM845 to fix the
warning: unmet direct dependencies detected for
SND_SOC_QDSP6.

Reported-by: Stephen Rothwell 
Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 3507308..5f03312 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -93,6 +93,7 @@ config SND_SOC_MSM8996
 
 config SND_SOC_SDM845
tristate "SoC Machine driver for SDM845 boards"
+   depends on QCOM_APR
select SND_SOC_QDSP6
help
  To add support for audio on Qualcomm Technologies Inc.
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v4 3/4] ASoC: qcom: Add support to parse common audio device nodes

2018-07-30 Thread Rohit kumar
This adds support to parse cpu, platform and codec
device nodes and add them in dai-links. Also, update
apq8096 machine driver to use the common API.

Acked-by: Srinivas Kandagatla 
Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Makefile  |   2 +-
 sound/soc/qcom/apq8096.c | 111 +-
 sound/soc/qcom/common.c  | 112 +++
 sound/soc/qcom/common.h  |  12 +
 4 files changed, 136 insertions(+), 101 deletions(-)
 create mode 100644 sound/soc/qcom/common.c
 create mode 100644 sound/soc/qcom/common.h

diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 206945b..fefecc0 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += snd-soc-lpass-apq8016.o
 # Machine
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
-snd-soc-apq8096-objs := apq8096.o
+snd-soc-apq8096-objs := apq8096.o common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
diff --git a/sound/soc/qcom/apq8096.c b/sound/soc/qcom/apq8096.c
index a561562..1e4a90d 100644
--- a/sound/soc/qcom/apq8096.c
+++ b/sound/soc/qcom/apq8096.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include "common.h"
 
 static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  struct snd_pcm_hw_params *params)
@@ -24,109 +25,16 @@ static int apq8096_be_hw_params_fixup(struct 
snd_soc_pcm_runtime *rtd,
return 0;
 }
 
-static int apq8096_sbc_parse_of(struct snd_soc_card *card)
+static void apq8096_add_be_ops(struct snd_soc_card *card)
 {
-   struct device_node *np;
-   struct device_node *codec = NULL;
-   struct device_node *platform = NULL;
-   struct device_node *cpu = NULL;
-   struct device *dev = card->dev;
-   struct snd_soc_dai_link *link;
-   int ret, num_links;
-
-   ret = snd_soc_of_parse_card_name(card, "qcom,model");
-   if (ret) {
-   dev_err(dev, "Error parsing card name: %d\n", ret);
-   return ret;
-   }
-
-   /* DAPM routes */
-   if (of_property_read_bool(dev->of_node, "qcom,audio-routing")) {
-   ret = snd_soc_of_parse_audio_routing(card,
-   "qcom,audio-routing");
-   if (ret)
-   return ret;
-   }
-
-   /* Populate links */
-   num_links = of_get_child_count(dev->of_node);
-
-   /* Allocate the DAI link array */
-   card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
-   if (!card->dai_link)
-   return -ENOMEM;
+   struct snd_soc_dai_link *link = card->dai_link;
+   int i, num_links = card->num_links;
 
-   card->num_links = num_links;
-   link = card->dai_link;
-
-   for_each_child_of_node(dev->of_node, np) {
-   cpu = of_get_child_by_name(np, "cpu");
-   if (!cpu) {
-   dev_err(dev, "Can't find cpu DT node\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
-   if (!link->cpu_of_node) {
-   dev_err(card->dev, "error getting cpu phandle\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   ret = snd_soc_of_get_dai_name(cpu, >cpu_dai_name);
-   if (ret) {
-   dev_err(card->dev, "error getting cpu dai name\n");
-   goto err;
-   }
-
-   platform = of_get_child_by_name(np, "platform");
-   codec = of_get_child_by_name(np, "codec");
-   if (codec && platform) {
-   link->platform_of_node = of_parse_phandle(platform,
- "sound-dai",
-  0);
-   if (!link->platform_of_node) {
-   dev_err(card->dev, "platform dai not found\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
-   if (ret < 0) {
-   dev_err(card->dev, "codec dai not found\n");
-   goto err;
-   }
-   link->no_pcm = 1;
-   link->ignore_pmdown_time = 1;
+   for (i = 0; i < num_links; i++) {
+   if (link->

[PATCH v4 4/4] ASoC: qcom: add sdm845 sound card support

2018-07-30 Thread Rohit kumar
This patch adds sdm845 audio machine driver support.

Acked-by: Srinivas Kandagatla 
Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Kconfig  |   8 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sdm845.c | 286 
 3 files changed, 296 insertions(+)
 create mode 100644 sound/soc/qcom/sdm845.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 87838fa..3507308 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -90,3 +90,11 @@ config SND_SOC_MSM8996
   Support for Qualcomm Technologies LPASS audio block in
   APQ8096 SoC-based systems.
   Say Y if you want to use audio device on this SoCs
+
+config SND_SOC_SDM845
+   tristate "SoC Machine driver for SDM845 boards"
+   select SND_SOC_QDSP6
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SDM845 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index fefecc0..f0e94d4 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o common.o
+snd-soc-sdm845-objs := sdm845.o common.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
+obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
 
 #DSP lib
 obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
new file mode 100644
index 000..a4fbcf5
--- /dev/null
+++ b/sound/soc/qcom/sdm845.c
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "common.h"
+#include "qdsp6/q6afe.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  24576000
+#define DEFAULT_BCLK_RATE  12288000
+
+struct sdm845_snd_data {
+   struct snd_soc_card *card;
+   uint32_t pri_mi2s_clk_count;
+   uint32_t quat_tdm_clk_count;
+};
+
+static unsigned int tdm_slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
+
+static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+   int ret = 0;
+   int channels, slot_width;
+
+   switch (params_format(params)) {
+   case SNDRV_PCM_FORMAT_S16_LE:
+   slot_width = 32;
+   break;
+   default:
+   dev_err(rtd->dev, "%s: invalid param format 0x%x\n",
+   __func__, params_format(params));
+   return -EINVAL;
+   }
+
+   channels = params_channels(params);
+   if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0x3,
+   8, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
+   channels, tdm_slot_offset);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   } else {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0,
+   8, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, channels,
+   tdm_slot_offset, 0, NULL);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   }
+end:
+   return ret;
+}
+
+static int sdm845_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_d

[PATCH v4 2/4] ASoC: dt-bindings: Update dt binding name for apq8096

2018-07-30 Thread Rohit kumar
Remove qcom prefix from machine driver dt bindings of
apq8096 SoC.

Acked-by: Srinivas Kandagatla 
Signed-off-by: Rohit kumar 
---
 Documentation/devicetree/bindings/sound/qcom,apq8096.txt | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/qcom,apq8096.txt 
b/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
index c7600a9..c814e86 100644
--- a/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
+++ b/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
@@ -7,7 +7,7 @@ This binding describes the APQ8096 sound card, which uses qdsp 
for audio.
Value type: 
Definition: must be "qcom,apq8096-sndcard"
 
-- qcom,audio-routing:
+- audio-routing:
Usage: Optional
Value type: 
Definition:  A list of the connections between audio components.
@@ -49,6 +49,12 @@ This binding describes the APQ8096 sound card, which uses 
qdsp for audio.
"DMIC1"
"DMIC2"
"DMIC3"
+
+- model:
+   Usage: required
+   Value type: 
+   Definition: The user-visible name of this sound card.
+
 = dailinks
 Each subnode of sndcard represents either a dailink, and subnodes of each
 dailinks would be cpu/codec/platform dais.
@@ -79,11 +85,16 @@ dailinks would be cpu/codec/platform dais.
Value type: 
Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
 
+Obsolete:
+   qcom,model: String for soundcard name (Use model instead)
+   qcom,audio-routing: A list of the connections between audio components.
+   (Use audio-routing instead)
+
 Example:
 
 audio {
compatible = "qcom,apq8096-sndcard";
-   qcom,model = "DB820c";
+   model = "DB820c";
 
mm1-dai-link {
link-name = "MultiMedia1";
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v4 0/4] Add support for audio on SDM845 SoC

2018-07-30 Thread Rohit kumar
This provides initial patchset to support audio on
Qualcomm Techonologies Inc. SDM845 SoC. Currently, it supports
audio playback/capture over Primary MI2S and Quaternary
TDM ports.

Changes since v3:
- Added Module_license in common.c
- Merged apq8096.c machine driver change with common api patch
- Addressed comments by Srinivas, Mark and Vinod.

Rohit kumar (4):
  ASoC: qcom: dt-bindings: Add sdm845 machine bindings
  ASoC: dt-bindings: Update dt binding name for apq8096
  ASoC: qcom: Add support to parse common audio device nodes
  ASoC: qcom: add sdm845 sound card support

 .../devicetree/bindings/sound/qcom,apq8096.txt |  15 +-
 .../devicetree/bindings/sound/qcom,sdm845.txt  |  80 ++
 sound/soc/qcom/Kconfig |   8 +
 sound/soc/qcom/Makefile|   4 +-
 sound/soc/qcom/apq8096.c   | 111 +---
 sound/soc/qcom/common.c| 112 
 sound/soc/qcom/common.h|  12 +
 sound/soc/qcom/sdm845.c| 286 +
 8 files changed, 525 insertions(+), 103 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt
 create mode 100644 sound/soc/qcom/common.c
 create mode 100644 sound/soc/qcom/common.h
 create mode 100644 sound/soc/qcom/sdm845.c

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v4 1/4] ASoC: qcom: dt-bindings: Add sdm845 machine bindings

2018-07-30 Thread Rohit kumar
Add devicetree bindings documentation file for SDM845 sound card.

Signed-off-by: Rohit kumar 
---
 .../devicetree/bindings/sound/qcom,sdm845.txt  | 80 ++
 1 file changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt

diff --git a/Documentation/devicetree/bindings/sound/qcom,sdm845.txt 
b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
new file mode 100644
index 000..408c483
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
@@ -0,0 +1,80 @@
+* Qualcomm Technologies Inc. SDM845 ASoC sound card driver
+
+This binding describes the SDM845 sound card, which uses qdsp for audio.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be "qcom,sdm845-sndcard"
+
+- audio-routing:
+   Usage: Optional
+   Value type: 
+   Definition:  A list of the connections between audio components.
+ Each entry is a pair of strings, the first being the
+ connection's sink, the second being the connection's
+ source. Valid names could be power supplies, MicBias
+ of codec and the jacks on the board.
+
+- model:
+   Usage: required
+   Value type: 
+   Definition: The user-visible name of this sound card.
+
+= dailinks
+Each subnode of sndcard represents either a dailink, and subnodes of each
+dailinks would be cpu/codec/platform dais.
+
+- link-name:
+   Usage: required
+   Value type: 
+   Definition: User friendly name for dai link
+
+= CPU, PLATFORM, CODEC dais subnodes
+- cpu:
+   Usage: required
+   Value type: 
+   Definition: cpu dai sub-node
+
+- codec:
+   Usage: required
+   Value type: 
+   Definition: codec dai sub-node
+
+- platform:
+   Usage: Optional
+   Value type: 
+   Definition: platform dai sub-node
+
+- sound-dai:
+   Usage: required
+   Value type: 
+   Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
+
+Example:
+
+audio {
+   compatible = "qcom,sdm845-sndcard";
+   model = "sdm845-snd-card";
+   pinctrl-names = "default", "sleep";
+   pinctrl-0 = <_mi2s_active _mi2s_ws_active>;
+   pinctrl-1 = <_mi2s_sleep _mi2s_ws_sleep>;
+
+   mm1-dai-link {
+   link-name = "MultiMedia1";
+   cpu {
+   sound-dai = < MSM_FRONTEND_DAI_MULTIMEDIA1>;
+   };
+   };
+
+   pri-mi2s-dai-link {
+   link-name = "PRI MI2S Playback";
+   cpu {
+   sound-dai = < PRIMARY_MI2S_RX>;
+   };
+
+   platform {
+   sound-dai = <>;
+   };
+   };
+};
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH] ASoC: Fix UBSAN warning at snd_soc_get/put_volsw_sx()

2018-09-10 Thread Rohit kumar
In functions snd_soc_get_volsw_sx() or snd_soc_put_volsw_sx(),
if the result of (min + max) is negative, then fls() returns
signed integer with value as 32. This leads to signed integer
overflow as complete operation is considered as signed integer.

UBSAN: Undefined behaviour in sound/soc/soc-ops.c:382:50
signed integer overflow:
-2147483648 - 1 cannot be represented in type 'int'
Call trace:
[] __dump_stack lib/dump_stack.c:15 [inline]
[] dump_stack+0xec/0x158 lib/dump_stack.c:51
[] ubsan_epilogue+0x18/0x50 lib/ubsan.c:164
[] handle_overflow+0xf8/0x130 lib/ubsan.c:195
[] __ubsan_handle_sub_overflow+0x34/0x44 lib/ubsan.c:211
[] snd_soc_get_volsw_sx+0x1a8/0x1f8 sound/soc/soc-ops.c:382

Typecast the operation to unsigned int to fix the issue.

Signed-off-by: Rohit kumar 
---
 sound/soc/soc-ops.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 592efb3..f8e3190 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -373,7 +373,7 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
unsigned int rshift = mc->rshift;
int max = mc->max;
int min = mc->min;
-   unsigned int mask = (1 << (fls(min + max) - 1)) - 1;
+   unsigned int mask = ((unsigned int)(1 << (fls(min + max) - 1)) - 1);
unsigned int val;
int ret;
 
@@ -418,7 +418,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
unsigned int rshift = mc->rshift;
int max = mc->max;
int min = mc->min;
-   unsigned int mask = (1 << (fls(min + max) - 1)) - 1;
+   unsigned int mask = ((unsigned int)(1 << (fls(min + max) - 1)) - 1);
int err = 0;
unsigned int val, val_mask, val2 = 0;
 
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [PATCH v3 1/2] dt-binding: remoteproc: Add QTI ADSP PIL bindings

2018-09-10 Thread Rohit Kumar

Thanks Rob for reviewing.


On 9/11/2018 1:31 AM, Rob Herring wrote:

On Mon, Sep 03, 2018 at 05:22:39PM +0530, Rohit kumar wrote:

Add devicetree bindings documentation file for Qualcomm
Technolgies Inc ADSP Peripheral Image Loader.

Signed-off-by: Rohit kumar 
---
  .../bindings/remoteproc/qcom,adsp-pil.txt  | 123 +
  1 file changed, 123 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
new file mode 100644
index 000..f1c215a
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
@@ -0,0 +1,123 @@
+Qualcomm Technology Inc. ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and boots firmware
+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sdm845-adsp-pil"
+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: must specify the base address and size of the qdsp6ss 
register
+
+- interrupts-extended:
+   Usage: required
+   Value type: 
+   Definition: must list the watchdog, fatal IRQs ready, handover and
+   stop-ack IRQs
+
+- interrupt-names:
+   Usage: required
+   Value type: 
+   Definition: must be "wdog", "fatal", "ready", "handover", "stop-ack"
+
+- clocks:
+   Usage: required
+   Value type: 
+   Definition:  List of phandle and clock specifier pairs

How many clocks?


+
+- clock-names:
+   Usage: required
+   Value type: 
+   Definition: List of clock input name strings sorted in the same
+   order as the clocks property.

What are the names?


I will update these in next spin.

+
+- power-domains:
+   Usage: required
+   Value type: 
+   Definition: reference to cx power domain node.
+
+- resets:
+   Usage: required
+   Value type: 
+   Definition: reference to the reset-controller for the lpass

How many?


+
+- reset-names:
+Usage: required
+Value type: 
+Definition: must be "pdc_sync" and "cc_lpass"
+
+- qcom,halt-regs:
+   Usage: required
+   Value type: 
+   Definition: a phandle reference to a syscon representing TCSR followed
+   by the offset within syscon for lpass halt register.
+
+- memory-region:
+   Usage: required
+   Value type: 
+   Definition: reference to the reserved-memory for the ADSP
+
+- qcom,smem-states:
+   Usage: required
+   Value type: 
+   Definition: reference to the smem state for requesting the ADSP to
+   shut down
+
+- qcom,smem-state-names:
+   Usage: required
+   Value type: 
+   Definition: must be "stop"
+
+
+= SUBNODES
+The adsp node may have an subnode named "glink-edge" that describes the
+communication edge, channels and devices related to the ADSP.
+See ../soc/qcom/qcom,glink.txt for details on how to describe these.
+
+= EXAMPLE
+The following example describes the resources needed to boot control the
+ADSP, as it is found on SDM845 boards.
+   adsp-pil {
+   compatible = "qcom,sdm845-adsp-pil";
+
+   reg = <0x1730 0x40c>;
+
+   interrupts-extended = < 0 162 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 0 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 1 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 2 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 3 IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+   "handover", "stop-ack";
+
+   clocks = < RPMH_CXO_CLK>,
+   < GCC_LPASS_SWAY_CLK>,
+   < LPASS_AUDIO_WRAPPER_AON_CLK>,
+   < LPASS_Q6SS_AHBS_AON_CLK>,
+   < LPASS_Q6SS_AHBM_AON_CLK>,
+   < LPASS_QDSP6SS_XO_CLK>,
+   < LPASS_QDSP6SS_SLEEP_CLK>,
+   < LPASS_QDSP6SS_CORE_CLK>;
+   clock-names = "xo", "sway_cbcr", "lpass_aon",
+   "lpass_ahbs_aon_cbcr",
+   "lpass_ahbm_aon_cbcr", "qdsp6ss_xo",
+   "qdsp6ss_sleep", "qdsp6ss_core";
+
+   power-domains = < SDM845_CX>;
+
+   resets = <_reset PDC_AUDIO_SYNC_RESET>,
+<_reset AOSS_CC_LPASS_RESTART>;
+   

Re: [PATCH v3 2/2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-09-10 Thread Rohit Kumar

Thanks Bjorn for reviewing.


On 9/11/2018 12:01 AM, Bjorn Andersson wrote:

On Mon 03 Sep 04:52 PDT 2018, Rohit kumar wrote:


This adds Non PAS ADSP PIL driver for Qualcomm
Technologies Inc SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 

Thanks for the changes Rohit, this looks good.

Once we hear from DT maintainers that patch 1 can be applied I will
update the name of the file and driver as I apply it to match the naming
scheme I'm aiming for - no need for you to resend because of this.
Sure, I will just update dt-bindings with addressing some comments given 
by Rob.



---
  drivers/remoteproc/Kconfig |  14 ++
  drivers/remoteproc/Makefile|   1 +
  drivers/remoteproc/qcom_adsp_pil.c | 500 +
  3 files changed, 515 insertions(+)
  create mode 100644 drivers/remoteproc/qcom_adsp_pil.c

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index c98c0b2..445de2d 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -139,6 +139,20 @@ config QCOM_Q6V5_WCSS
  Say y here to support the Qualcomm Peripheral Image Loader for the
  Hexagon V5 based WCSS remote processors.
  
+config QCOM_ADSP_PIL

I will make this QCOM_Q6V5_ADSP

[..]

diff --git a/drivers/remoteproc/qcom_adsp_pil.c 
b/drivers/remoteproc/qcom_adsp_pil.c

Make this qcom_q6v5_adsp.c

[..]

+static struct platform_driver adsp_pil_driver = {
+   .probe = adsp_probe,
+   .remove = adsp_remove,
+   .driver = {
+   .name = "qcom_adsp_pil",

and this qcom_q6v5_adsp".


+   .of_match_table = adsp_of_match,
+   },
+};

Please let me know if you have any objections to this.

Naming looks fine.

Thanks,
Rohit

Regards,
Bjorn




[PATCH v4] dt-binding: remoteproc: Add QTI ADSP PIL bindings

2018-09-10 Thread Rohit kumar
Add devicetree bindings documentation file for Qualcomm
Technolgies Inc ADSP Peripheral Image Loader.

Signed-off-by: Rohit kumar 
---
Changes since v3:
Addressed comments given by Rob

 .../bindings/remoteproc/qcom,adsp-pil.txt  | 126 +
 1 file changed, 126 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
new file mode 100644
index 000..06558de
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
@@ -0,0 +1,126 @@
+Qualcomm Technology Inc. ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and boots firmware
+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sdm845-adsp-pil"
+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: must specify the base address and size of the qdsp6ss 
register
+
+- interrupts-extended:
+   Usage: required
+   Value type: 
+   Definition: must list the watchdog, fatal IRQs ready, handover and
+   stop-ack IRQs
+
+- interrupt-names:
+   Usage: required
+   Value type: 
+   Definition: must be "wdog", "fatal", "ready", "handover", "stop-ack"
+
+- clocks:
+   Usage: required
+   Value type: 
+   Definition:  List of 8 phandle and clock specifier pairs for the adsp.
+
+- clock-names:
+   Usage: required
+   Value type: 
+   Definition: List of clock input name strings sorted in the same
+   order as the clocks property. Definition must have
+   "xo", "sway_cbcr", "lpass_aon", "lpass_ahbs_aon_cbcr",
+   "lpass_ahbm_aon_cbcr", "qdsp6ss_xo", "qdsp6ss_sleep"
+   and "qdsp6ss_core".
+
+- power-domains:
+   Usage: required
+   Value type: 
+   Definition: reference to cx power domain node.
+
+- resets:
+   Usage: required
+   Value type: 
+   Definition: reference to the list of 2 reset-controller for the adsp.
+
+- reset-names:
+Usage: required
+Value type: 
+Definition: must be "pdc_sync" and "cc_lpass"
+
+- qcom,halt-regs:
+   Usage: required
+   Value type: 
+   Definition: a phandle reference to a syscon representing TCSR followed
+   by the offset within syscon for lpass halt register.
+
+- memory-region:
+   Usage: required
+   Value type: 
+   Definition: reference to the reserved-memory for the ADSP
+
+- qcom,smem-states:
+   Usage: required
+   Value type: 
+   Definition: reference to the smem state for requesting the ADSP to
+   shut down
+
+- qcom,smem-state-names:
+   Usage: required
+   Value type: 
+   Definition: must be "stop"
+
+
+= SUBNODES
+The adsp node may have an subnode named "glink-edge" that describes the
+communication edge, channels and devices related to the ADSP.
+See ../soc/qcom/qcom,glink.txt for details on how to describe these.
+
+= EXAMPLE
+The following example describes the resources needed to boot control the
+ADSP, as it is found on SDM845 boards.
+   adsp-pil {
+   compatible = "qcom,sdm845-adsp-pil";
+
+   reg = <0x1730 0x40c>;
+
+   interrupts-extended = < 0 162 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 0 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 1 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 2 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 3 IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+   "handover", "stop-ack";
+
+   clocks = < RPMH_CXO_CLK>,
+   < GCC_LPASS_SWAY_CLK>,
+   < LPASS_AUDIO_WRAPPER_AON_CLK>,
+   < LPASS_Q6SS_AHBS_AON_CLK>,
+   < LPASS_Q6SS_AHBM_AON_CLK>,
+   < LPASS_QDSP6SS_XO_CLK>,
+   < LPASS_QDSP6SS_SLEEP_CLK>,
+   < LPASS_QDSP6SS_CORE_CLK>;
+   clock-names = "xo", "sway_cbcr", "lpass_aon",
+   "lpass_ahbs_aon_cbcr",
+   "lpass_ahbm_aon_cbcr", "qdsp6ss_xo",
+   "qdsp6ss_sleep", "qdsp6ss_core";
+
+   power-domains = < SDM845_CX>;
+
+   

Re: [alsa-devel] [PATCH] ASoC: Fix UBSAN warning at snd_soc_get/put_volsw_sx()

2018-09-11 Thread Rohit Kumar

Thanks Takashi for reviewing.


On 9/10/2018 11:56 PM, Takashi Iwai wrote:

On Mon, 10 Sep 2018 19:33:56 +0200,
Rohit kumar wrote:

In functions snd_soc_get_volsw_sx() or snd_soc_put_volsw_sx(),
if the result of (min + max) is negative, then fls() returns
signed integer with value as 32. This leads to signed integer
overflow as complete operation is considered as signed integer.

UBSAN: Undefined behaviour in sound/soc/soc-ops.c:382:50
signed integer overflow:
-2147483648 - 1 cannot be represented in type 'int'
Call trace:
[] __dump_stack lib/dump_stack.c:15 [inline]
[] dump_stack+0xec/0x158 lib/dump_stack.c:51
[] ubsan_epilogue+0x18/0x50 lib/ubsan.c:164
[] handle_overflow+0xf8/0x130 lib/ubsan.c:195
[] __ubsan_handle_sub_overflow+0x34/0x44 lib/ubsan.c:211
[] snd_soc_get_volsw_sx+0x1a8/0x1f8 sound/soc/soc-ops.c:382

Typecast the operation to unsigned int to fix the issue.

Signed-off-by: Rohit kumar 
---
  sound/soc/soc-ops.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 592efb3..f8e3190 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -373,7 +373,7 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
unsigned int rshift = mc->rshift;
int max = mc->max;
int min = mc->min;
-   unsigned int mask = (1 << (fls(min + max) - 1)) - 1;
+   unsigned int mask = ((unsigned int)(1 << (fls(min + max) - 1)) - 1);

Cat it be simpler like below instead?
unsigned int mask = (1U << (fls(min + max) - 1)) - 1;


Yes, let me just update it.


thanks,

Takashi


unsigned int val;
int ret;
  
@@ -418,7 +418,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,

unsigned int rshift = mc->rshift;
int max = mc->max;
int min = mc->min;
-   unsigned int mask = (1 << (fls(min + max) - 1)) - 1;
+   unsigned int mask = ((unsigned int)(1 << (fls(min + max) - 1)) - 1);
int err = 0;
unsigned int val, val_mask, val2 = 0;
  
--

Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



___
Alsa-devel mailing list
alsa-de...@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

Thanks,
Rohit



[PATCH v2] ASoC: Fix UBSAN warning at snd_soc_get/put_volsw_sx()

2018-09-11 Thread Rohit kumar
In functions snd_soc_get_volsw_sx() or snd_soc_put_volsw_sx(),
if the result of (min + max) is negative, then fls() returns
signed integer with value as 32. This leads to signed integer
overflow as complete operation is considered as signed integer.

UBSAN: Undefined behaviour in sound/soc/soc-ops.c:382:50
signed integer overflow:
-2147483648 - 1 cannot be represented in type 'int'
Call trace:
[] __dump_stack lib/dump_stack.c:15 [inline]
[] dump_stack+0xec/0x158 lib/dump_stack.c:51
[] ubsan_epilogue+0x18/0x50 lib/ubsan.c:164
[] handle_overflow+0xf8/0x130 lib/ubsan.c:195
[] __ubsan_handle_sub_overflow+0x34/0x44 lib/ubsan.c:211
[] snd_soc_get_volsw_sx+0x1a8/0x1f8 sound/soc/soc-ops.c:382

Typecast the operation to unsigned int to fix the issue.

Signed-off-by: Rohit kumar 
---
Changes since v1:
Addressed comments given by Takashi.

 sound/soc/soc-ops.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 592efb3..f4dc3d4 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -373,7 +373,7 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol,
unsigned int rshift = mc->rshift;
int max = mc->max;
int min = mc->min;
-   unsigned int mask = (1 << (fls(min + max) - 1)) - 1;
+   unsigned int mask = (1U << (fls(min + max) - 1)) - 1;
unsigned int val;
int ret;
 
@@ -418,7 +418,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol,
unsigned int rshift = mc->rshift;
int max = mc->max;
int min = mc->min;
-   unsigned int mask = (1 << (fls(min + max) - 1)) - 1;
+   unsigned int mask = (1U << (fls(min + max) - 1)) - 1;
int err = 0;
unsigned int val, val_mask, val2 = 0;
 
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v3 0/5] Add support for audio on SDM845 SoC

2018-07-06 Thread Rohit kumar


This provides initial patchset to support audio on
Qualcomm Techonologies Inc. SDM845 SoC. Currently, it supports
audio playback/capture over Primary MI2S and Quaternary
TDM ports.
Changes since v2:
- Added new file to parse dai-links from device tree
  and use it in sdm845 and apq8096 machine driver.
- Removed qcom prefix from device tree properties as
  suggested by Robb.
- Updated apq8096 machine driver to use common APIs.

Rohit kumar (5):
  ASoC: qcom: dt-bindings: Add sdm845 machine bindings
  ASoC: qcom: Add support to parse common audio device nodes
  ASoC: qcom: add sdm845 sound card support
  ASoC: dt-bindings: Update dt binding name for apq8096
  ASoC: qcom: apq8096: Use common APIs to parse device nodes

 .../devicetree/bindings/sound/qcom,apq8096.txt |  15 +-
 .../devicetree/bindings/sound/qcom,sdm845.txt  |  80 +
 sound/soc/qcom/Kconfig |  14 +
 sound/soc/qcom/Makefile|   3 +
 sound/soc/qcom/apq8096.c   | 151 +---
 sound/soc/qcom/common.c| 150 
 sound/soc/qcom/common.h|  14 +
 sound/soc/qcom/sdm845.c| 390 +
 8 files changed, 674 insertions(+), 143 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt
 create mode 100644 sound/soc/qcom/common.c
 create mode 100644 sound/soc/qcom/common.h
 create mode 100644 sound/soc/qcom/sdm845.c

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v3 3/5] ASoC: qcom: add sdm845 sound card support

2018-07-06 Thread Rohit kumar
This patch adds sdm845 audio machine driver support.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Kconfig  |  10 ++
 sound/soc/qcom/Makefile |   2 +
 sound/soc/qcom/sdm845.c | 390 
 3 files changed, 402 insertions(+)
 create mode 100644 sound/soc/qcom/sdm845.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 0e364b4..cf55f0a 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -93,3 +93,13 @@ config SND_SOC_MSM8996
 
 config SND_SOC_QCOM_COMMON
tristate
+
+config SND_SOC_SDM845
+   tristate "SoC Machine driver for SDM845 boards"
+   select SND_SOC_QDSP6
+   select SND_SOC_QCOM_COMMON
+   default n
+   help
+ To add support for audio on Qualcomm Technologies Inc.
+ SDM845 SoC-based systems.
+ Say Y if you want to use audio device on this SoCs.
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 1bcdbee..c9699fb 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -14,10 +14,12 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o
 snd-soc-storm-objs := storm.o
 snd-soc-apq8016-sbc-objs := apq8016_sbc.o
 snd-soc-apq8096-objs := apq8096.o
+snd-soc-sdm845-objs := sdm845.o
 
 obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
+obj-$(CONFIG_SND_SOC_SDM845) += snd-soc-sdm845.o
 
 obj-$(CONFIG_SND_SOC_QCOM_COMMON) += common.o
 #DSP lib
diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
new file mode 100644
index 000..9ee3558
--- /dev/null
+++ b/sound/soc/qcom/sdm845.c
@@ -0,0 +1,390 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "common.h"
+#include "qdsp6/q6afe.h"
+
+#define DEFAULT_SAMPLE_RATE_48K48000
+#define DEFAULT_MCLK_RATE  24576000
+#define DEFAULT_BCLK_RATE  1536000
+
+struct sdm845_snd_data {
+   struct snd_soc_card *card;
+   struct regulator *vdd_supply;
+   uint32_t pri_mi2s_clk_count;
+   uint32_t quat_tdm_clk_count;
+};
+
+
+static unsigned int tdm_slot_offset[8] = {0, 4, 8, 12, 16, 20, 24, 28};
+
+static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+   int ret = 0;
+   int channels, slot_width;
+
+   switch (params_format(params)) {
+   case SNDRV_PCM_FORMAT_S32_LE:
+   case SNDRV_PCM_FORMAT_S24_LE:
+   case SNDRV_PCM_FORMAT_S16_LE:
+   slot_width = 32;
+   break;
+   default:
+   dev_err(rtd->dev, "%s: invalid param format 0x%x\n",
+   __func__, params_format(params));
+   return -EINVAL;
+   }
+
+   channels = params_channels(params);
+   if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0, 0x3,
+   channels, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, 0, NULL,
+   channels, tdm_slot_offset);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   } else {
+   ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0,
+   channels, slot_width);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set tdm slot, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+
+   ret = snd_soc_dai_set_channel_map(cpu_dai, channels,
+   tdm_slot_offset, 0, NULL);
+   if (ret < 0) {
+   dev_err(rtd->dev, "%s: failed to set channel map, 
err:%d\n",
+   __func__, ret);
+   goto end;
+   }
+   }
+end:
+   return ret;
+}
+
+static int sdm845_snd_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params)
+{
+   struct snd_soc_pcm_runtime *rtd = substream->private_data;

[PATCH v3 5/5] ASoC: qcom: apq8096: Use common APIs to parse device nodes

2018-07-06 Thread Rohit kumar
Use generic APIs exposed by common.c for parsing
dai link device tree nodes and adding slave components.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Kconfig   |   1 +
 sound/soc/qcom/apq8096.c | 151 ---
 2 files changed, 11 insertions(+), 141 deletions(-)

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index cf55f0a..2be9cee 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -86,6 +86,7 @@ config SND_SOC_MSM8996
tristate "SoC Machine driver for MSM8996 and APQ8096 boards"
depends on QCOM_APR
select SND_SOC_QDSP6
+   select SND_SOC_QCOM_COMMON
help
   Support for Qualcomm Technologies LPASS audio block in
   APQ8096 SoC-based systems.
diff --git a/sound/soc/qcom/apq8096.c b/sound/soc/qcom/apq8096.c
index cab8c4f..726fb73 100644
--- a/sound/soc/qcom/apq8096.c
+++ b/sound/soc/qcom/apq8096.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include "common.h"
 
 static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  struct snd_pcm_hw_params *params)
@@ -24,109 +25,16 @@ static int apq8096_be_hw_params_fixup(struct 
snd_soc_pcm_runtime *rtd,
return 0;
 }
 
-static int apq8096_sbc_parse_of(struct snd_soc_card *card)
+static void apq8096_add_be_ops(struct snd_soc_card *card)
 {
-   struct device_node *np;
-   struct device_node *codec = NULL;
-   struct device_node *platform = NULL;
-   struct device_node *cpu = NULL;
-   struct device *dev = card->dev;
-   struct snd_soc_dai_link *link;
-   int ret, num_links;
-
-   ret = snd_soc_of_parse_card_name(card, "qcom,model");
-   if (ret) {
-   dev_err(dev, "Error parsing card name: %d\n", ret);
-   return ret;
-   }
+   struct snd_soc_dai_link *link = card->dai_link;
+   int i, num_links = card->num_links;
 
-   /* DAPM routes */
-   if (of_property_read_bool(dev->of_node, "qcom,audio-routing")) {
-   ret = snd_soc_of_parse_audio_routing(card,
-   "qcom,audio-routing");
-   if (ret)
-   return ret;
-   }
-
-   /* Populate links */
-   num_links = of_get_child_count(dev->of_node);
-
-   /* Allocate the DAI link array */
-   card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
-   if (!card->dai_link)
-   return -ENOMEM;
-
-   card->num_links = num_links;
-   link = card->dai_link;
-
-   for_each_child_of_node(dev->of_node, np) {
-   cpu = of_get_child_by_name(np, "cpu");
-   if (!cpu) {
-   dev_err(dev, "Can't find cpu DT node\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
-   if (!link->cpu_of_node) {
-   dev_err(card->dev, "error getting cpu phandle\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   ret = snd_soc_of_get_dai_name(cpu, >cpu_dai_name);
-   if (ret) {
-   dev_err(card->dev, "error getting cpu dai name\n");
-   goto err;
-   }
-
-   platform = of_get_child_by_name(np, "platform");
-   codec = of_get_child_by_name(np, "codec");
-   if (codec && platform) {
-   link->platform_of_node = of_parse_phandle(platform,
- "sound-dai",
-  0);
-   if (!link->platform_of_node) {
-   dev_err(card->dev, "platform dai not found\n");
-   ret = -EINVAL;
-   goto err;
-   }
-
-   ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
-   if (ret < 0) {
-   dev_err(card->dev, "codec dai not found\n");
-   goto err;
-   }
-   link->no_pcm = 1;
-   link->ignore_pmdown_time = 1;
+   for (i = 0; i < num_links; i++) {
+   if (link->no_pcm == 1)
link->be_hw_params_fixup = apq8096_be_hw_params_fixup;
-   } else {
-   link->platform_of_node = link->cpu_of_node;
-   link->codec_dai_name = "snd-soc-dummy-dai";
-   link->codec_nam

[PATCH v3 1/5] ASoC: qcom: dt-bindings: Add sdm845 machine bindings

2018-07-06 Thread Rohit kumar
Add devicetree bindings documentation file for SDM845 sound card.

Signed-off-by: Rohit kumar 
---
 .../devicetree/bindings/sound/qcom,sdm845.txt  | 80 ++
 1 file changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt

diff --git a/Documentation/devicetree/bindings/sound/qcom,sdm845.txt 
b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
new file mode 100644
index 000..408c483
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
@@ -0,0 +1,80 @@
+* Qualcomm Technologies Inc. SDM845 ASoC sound card driver
+
+This binding describes the SDM845 sound card, which uses qdsp for audio.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be "qcom,sdm845-sndcard"
+
+- audio-routing:
+   Usage: Optional
+   Value type: 
+   Definition:  A list of the connections between audio components.
+ Each entry is a pair of strings, the first being the
+ connection's sink, the second being the connection's
+ source. Valid names could be power supplies, MicBias
+ of codec and the jacks on the board.
+
+- model:
+   Usage: required
+   Value type: 
+   Definition: The user-visible name of this sound card.
+
+= dailinks
+Each subnode of sndcard represents either a dailink, and subnodes of each
+dailinks would be cpu/codec/platform dais.
+
+- link-name:
+   Usage: required
+   Value type: 
+   Definition: User friendly name for dai link
+
+= CPU, PLATFORM, CODEC dais subnodes
+- cpu:
+   Usage: required
+   Value type: 
+   Definition: cpu dai sub-node
+
+- codec:
+   Usage: required
+   Value type: 
+   Definition: codec dai sub-node
+
+- platform:
+   Usage: Optional
+   Value type: 
+   Definition: platform dai sub-node
+
+- sound-dai:
+   Usage: required
+   Value type: 
+   Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
+
+Example:
+
+audio {
+   compatible = "qcom,sdm845-sndcard";
+   model = "sdm845-snd-card";
+   pinctrl-names = "default", "sleep";
+   pinctrl-0 = <_mi2s_active _mi2s_ws_active>;
+   pinctrl-1 = <_mi2s_sleep _mi2s_ws_sleep>;
+
+   mm1-dai-link {
+   link-name = "MultiMedia1";
+   cpu {
+   sound-dai = < MSM_FRONTEND_DAI_MULTIMEDIA1>;
+   };
+   };
+
+   pri-mi2s-dai-link {
+   link-name = "PRI MI2S Playback";
+   cpu {
+   sound-dai = < PRIMARY_MI2S_RX>;
+   };
+
+   platform {
+   sound-dai = <>;
+   };
+   };
+};
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v3 2/5] ASoC: qcom: Add support to parse common audio device nodes

2018-07-06 Thread Rohit kumar
This adds support to parse cpu, platform and codec
device nodes and add them in dai-links. Also, add
API to add slave components associated with machine
driver.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/Kconfig  |   3 +
 sound/soc/qcom/Makefile |   1 +
 sound/soc/qcom/common.c | 150 
 sound/soc/qcom/common.h |  14 +
 4 files changed, 168 insertions(+)
 create mode 100644 sound/soc/qcom/common.c
 create mode 100644 sound/soc/qcom/common.h

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 87838fa..0e364b4 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -90,3 +90,6 @@ config SND_SOC_MSM8996
   Support for Qualcomm Technologies LPASS audio block in
   APQ8096 SoC-based systems.
   Say Y if you want to use audio device on this SoCs
+
+config SND_SOC_QCOM_COMMON
+   tristate
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index 206945b..1bcdbee 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -19,5 +19,6 @@ obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
 obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
 obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-apq8096.o
 
+obj-$(CONFIG_SND_SOC_QCOM_COMMON) += common.o
 #DSP lib
 obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
new file mode 100644
index 000..be62fca
--- /dev/null
+++ b/sound/soc/qcom/common.c
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2018, Linaro Limited.
+// Copyright (c) 2018, The Linux Foundation. All rights reserved.
+
+#include "common.h"
+
+int qcom_snd_parse_of(struct snd_soc_card *card)
+{
+   struct device_node *np;
+   struct device_node *codec = NULL;
+   struct device_node *platform = NULL;
+   struct device_node *cpu = NULL;
+   struct device *dev = card->dev;
+   struct snd_soc_dai_link *link;
+   int ret, num_links;
+
+   ret = snd_soc_of_parse_card_name(card, "model");
+   if (ret) {
+   dev_err(dev, "Error parsing card name: %d\n", ret);
+   return ret;
+   }
+
+   /* DAPM routes */
+   if (of_property_read_bool(dev->of_node, "audio-routing")) {
+   ret = snd_soc_of_parse_audio_routing(card,
+   "audio-routing");
+   if (ret)
+   return ret;
+   }
+
+   /* Populate links */
+   num_links = of_get_child_count(dev->of_node);
+
+   /* Allocate the DAI link array */
+   card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
+   if (!card->dai_link)
+   return -ENOMEM;
+
+   card->num_links = num_links;
+   link = card->dai_link;
+   for_each_child_of_node(dev->of_node, np) {
+   cpu = of_get_child_by_name(np, "cpu");
+   if (!cpu) {
+   dev_err(dev, "Can't find cpu DT node\n");
+   ret = -EINVAL;
+   goto err;
+   }
+
+   link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
+   if (!link->cpu_of_node) {
+   dev_err(card->dev, "error getting cpu phandle\n");
+   ret = -EINVAL;
+   goto err;
+   }
+
+   ret = snd_soc_of_get_dai_name(cpu, >cpu_dai_name);
+   if (ret) {
+   dev_err(card->dev, "error getting cpu dai name\n");
+   goto err;
+   }
+
+   platform = of_get_child_by_name(np, "platform");
+   codec = of_get_child_by_name(np, "codec");
+   if (codec && platform) {
+   link->platform_of_node = of_parse_phandle(platform,
+   "sound-dai",
+   0);
+   if (!link->platform_of_node) {
+   dev_err(card->dev, "platform dai not found\n");
+   ret = -EINVAL;
+   goto err;
+   }
+
+   ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
+   if (ret < 0) {
+   dev_err(card->dev, "codec dai not found\n");
+   goto err;
+   }
+   link->no_pcm = 1;
+   link->ignore_pmdown_time = 1;
+   } else {
+   link->platform_of_node = link->cpu_of_node;
+   link->codec_dai_name = "snd-soc-dummy-dai";
+   link->codec_name = "snd-soc-du

[PATCH v3 4/5] ASoC: dt-bindings: Update dt binding name for apq8096

2018-07-06 Thread Rohit kumar
Remove qcom prefix from machine driver dt bindings of
apq8096 SoC.

Signed-off-by: Rohit kumar 
---
 Documentation/devicetree/bindings/sound/qcom,apq8096.txt | 15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/qcom,apq8096.txt 
b/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
index c7600a9..c814e86 100644
--- a/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
+++ b/Documentation/devicetree/bindings/sound/qcom,apq8096.txt
@@ -7,7 +7,7 @@ This binding describes the APQ8096 sound card, which uses qdsp 
for audio.
Value type: 
Definition: must be "qcom,apq8096-sndcard"
 
-- qcom,audio-routing:
+- audio-routing:
Usage: Optional
Value type: 
Definition:  A list of the connections between audio components.
@@ -49,6 +49,12 @@ This binding describes the APQ8096 sound card, which uses 
qdsp for audio.
"DMIC1"
"DMIC2"
"DMIC3"
+
+- model:
+   Usage: required
+   Value type: 
+   Definition: The user-visible name of this sound card.
+
 = dailinks
 Each subnode of sndcard represents either a dailink, and subnodes of each
 dailinks would be cpu/codec/platform dais.
@@ -79,11 +85,16 @@ dailinks would be cpu/codec/platform dais.
Value type: 
Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
 
+Obsolete:
+   qcom,model: String for soundcard name (Use model instead)
+   qcom,audio-routing: A list of the connections between audio components.
+   (Use audio-routing instead)
+
 Example:
 
 audio {
compatible = "qcom,apq8096-sndcard";
-   qcom,model = "DB820c";
+   model = "DB820c";
 
mm1-dai-link {
link-name = "MultiMedia1";
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [PATCH v3 3/5] ASoC: qcom: add sdm845 sound card support

2018-07-09 Thread Rohit Kumar

Thanks Vinod for reviewing.


On 7/9/2018 1:18 PM, Vinod wrote:

On 06-07-18, 15:13, Rohit kumar wrote:


+static void sdm845_init_supplies(struct device *dev)
+{
+   struct snd_soc_card *card = dev_get_drvdata(dev);
+   struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card);
+
+   data->vdd_supply = regulator_get(dev, "cdc-vdd");
+   if (IS_ERR(data->vdd_supply)) {
+   dev_err(dev, "Unable to get regulator supplies\n");
+   data->vdd_supply = NULL;
+   return;
+   }
+
+   if (regulator_enable(data->vdd_supply))
+   dev_err(dev, "Unable to enable vdd supply\n");
+}
+
+static void sdm845_deinit_supplies(struct device *dev)
+{
+   struct snd_soc_card *card = dev_get_drvdata(dev);
+   struct sdm845_snd_data *data = snd_soc_card_get_drvdata(card);
+
+   if (!data->vdd_supply)
+   return;
+
+   regulator_disable(data->vdd_supply);
+   regulator_put(data->vdd_supply);
+}

these two can be made generic, cant we make these common when we have
supplies present?


Actually we  need to move it to codec driver as suggested by Rob in v2 
patchset.

I will remove this in next spin.


+static int sdm845_bind(struct device *dev)
+{
+   struct snd_soc_card *card;
+   struct sdm845_snd_data *data;
+   int ret;
+
+   card = kzalloc(sizeof(*card), GFP_KERNEL);
+   if (!card)
+   return -ENOMEM;
+
+   /* Allocate the private data */
+   data = kzalloc(sizeof(*data), GFP_KERNEL);
+   if (!data)
+   return -ENOMEM;
+
+   ret = component_bind_all(dev, card);
+   if (ret) {
+   dev_err(dev, "Audio components bind failed: %d\n", ret);
+   goto bind_fail;
+   }
+
+   dev_set_drvdata(dev, card);
+   card->dev = dev;
+   ret = qcom_snd_parse_of(card);
+   if (ret) {
+   dev_err(dev, "Error parsing OF data\n");
+   goto parse_dt_fail;
+   }
+
+   data->card = card;
+   snd_soc_card_set_drvdata(card, data);
+
+   sdm845_add_be_ops(card);
+
+   sdm845_init_supplies(dev);
+
+   ret = snd_soc_register_card(card);
+   if (ret) {
+   dev_err(dev, "Sound card registration failed\n");
+   goto register_card_fail;
+   }
+   return ret;
+
+register_card_fail:
+   sdm845_deinit_supplies(dev);
+   kfree(card->dai_link);
+parse_dt_fail:
+   component_unbind_all(dev, card);
+bind_fail:
+   kfree(data);
+   kfree(card);
+   return ret;
+}

I would make a case for this to be moved into common too :)


There are few platform specific APIs and structs here like struct 
sdm845_snd_data,
sdm845_add_be_ops() which needs to be initialized and assigned before 
soundcard
registration. Moving this complete API to common will restrict it. 
Please suggest.


--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [PATCH v2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-07-09 Thread Rohit Kumar

Thanks Rob for reviewing.


On 7/7/2018 2:02 AM, Rob Herring wrote:

On Fri, Jun 29, 2018 at 02:50:53PM +0530, Rohit kumar wrote:

This adds APSS based ADSP PIL driver for QCOM SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 
---
Changes since v1:
- Used APIs from qcom_q6v5.c
- Use clock, reset and regmap driver APIs instead of
   directly writing into the LPASS registers.
- Created new file for non PAS ADSP PIL instead of extending
   existing ADSP PIL driver.
- cleanups as suggested by Bjorn and Rob.

  .../bindings/remoteproc/qcom,non-pas-adsp.txt  | 138 +

This should be a separate patch.


Ok. Will separate it in next spin.

  drivers/remoteproc/Kconfig |  18 +
  drivers/remoteproc/Makefile|   1 +
  drivers/remoteproc/qcom_nonpas_adsp_pil.c  | 667 +
  4 files changed, 824 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
  create mode 100644 drivers/remoteproc/qcom_nonpas_adsp_pil.c

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
new file mode 100644
index 000..0581aaa
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
@@ -0,0 +1,138 @@
+Qualcomm Technology Inc. Non PAS ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and boots firmware
+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sdm845-apss-adsp-pil"

Didn't Bjorn say to drop the 'apss' part?


Yes, he had asked to rename compatible string for  existing PIL driver 
as "qcom,platform-subsystem-pas"
and non-pas pil driver as "qcom,platform-subsystem-pil". I wanted to get 
confirmation from Bjorn whether

we should rename the filename too.
@Bjorn, can you please suggest filename and compatible strings for the 
two drivers.

+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: must specify the base address and size of the qdsp6ss
+
+- reg-names:
+   Usage: required
+   Value type: 
+   Definition: must be "qdsp6ss"
+


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


Thanks,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [PATCH v4 07/24] ASoC: qdsp6: q6afe: Add q6afe driver

2018-03-13 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to Q6AFE (Audio Front End) module on Q6DSP.


[..]

+   if (res->status) {
+   dev_err(afe->dev, "cmd = 0x%x returned error = 0x%x\n",
+   res->opcode, res->status);
+   }
+   switch (res->opcode) {
+   case AFE_PORT_CMD_SET_PARAM_V2:
+   case AFE_PORT_CMD_DEVICE_STOP:
+   case AFE_PORT_CMD_DEVICE_START:


case AFE_SVC_CMD_SET_PARAM: needs to be added

+   port = afe_find_port(afe, data->token);
+   if (port) {
+   port->result = *res;
+   wake_up(>wait);
+   }

[..]

+
+static int q6afe_port_set_param_v2(struct q6afe_port *port, void *data,
+  int param_id, int psize)
+{
+   struct apr_hdr *hdr;
+   struct afe_port_cmd_set_param_v2 *param;
+   struct afe_port_param_data_v2 *pdata;
+   struct q6afe *afe = port->afe;
+   u16 port_id = port->id;
+   int ret;
+
+   hdr = data;
+   param = data + sizeof(*hdr);
+   pdata = data + sizeof(*hdr) + sizeof(*param);
+
+   hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
+ APR_HDR_LEN(APR_HDR_SIZE),
+ APR_PKT_VER);
+   hdr->pkt_size = sizeof(*hdr) + sizeof(*param) +
+   sizeof(*pdata) + psize;
+   hdr->src_port = 0;
+   hdr->dest_port = 0;
+   hdr->token = port->token;
+   hdr->opcode = AFE_PORT_CMD_SET_PARAM_V2;
+   param->port_id = port_id;
+   param->payload_size = sizeof(*pdata) + psize;
+   param->payload_address_lsw = 0x00;
+   param->payload_address_msw = 0x00;
+   param->mem_map_handle = 0x00;
+   pdata->module_id = AFE_MODULE_AUDIO_DEV_INTERFACE;
+   pdata->param_id = param_id;
+   pdata->param_size = psize;
+
+   ret = afe_apr_send_pkt(afe, data, port);
+   if (ret)
+   dev_err(afe->dev, "AFE enable for port 0x%x failed %d\n",


we should add %s to distinguish different functions with similar error 
logs. Also, q6afe_port_set_param_v2() can be called for different 
purpose.  AFE enable for port 0x%x failed is suitable only for port 
start failure. Error message needs to be updated here.



+  port_id, ret);
+
+
+   return ret;
+}
+


Re: [alsa-devel] [PATCH v4 15/24] ASoC: qdsp6: q6core: Add q6core driver

2018-03-13 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

[..]

+static int q6core_get_svc_versions(struct q6core *core)
+{
+   struct apr_device *adev = core->adev;
+   struct apr_hdr hdr = {0};
+   int rc;
+
+   core->get_version_supported = true;


core->get_version_supported should be set to true only after we get proper 
response from adsp in callback(). In case,we get wrong response from adsp, memory for 
g_core->svc_version
 will not get allocated and there will be NULL pointer dereference in  
q6core_get_svc_api_info() in below statement
+   } else if (g_core->get_version_supported) {
+   for (i = 0; i < g_core->svc_version->num_services; i++) {
 


+   hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
+ APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
+   hdr.pkt_size = APR_HDR_SIZE;
+   hdr.opcode = AVCS_GET_VERSIONS;
+
+   rc = apr_send_pkt(adev, );
+   if (rc < 0)
+   return rc;
+


Re: [alsa-devel] [PATCH v3 19/25] ASoC: qcom: q6afe: add support to MI2S ports

2018-03-07 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

Signed-off-by: Srinivas Kandagatla 
---
  include/dt-bindings/sound/qcom,q6afe.h |  10 +++
  sound/soc/qcom/qdsp6/q6afe.c   | 111 +
  sound/soc/qcom/qdsp6/q6afe.h   |  10 +++
  3 files changed, 131 insertions(+)

diff --git a/include/dt-bindings/sound/qcom,q6afe.h 
b/include/dt-bindings/sound/qcom,q6afe.h
index e9004ee39f72..3cd862262369 100644
--- a/include/dt-bindings/sound/qcom,q6afe.h
+++ b/include/dt-bindings/sound/qcom,q6afe.h
@@ -16,6 +16,16 @@
  #define SLIMBUS_4_TX24
  #define SLIMBUS_5_RX25
  #define SLIMBUS_5_TX26
+#define QUATERNARY_MI2S_RX 34
+#define QUATERNARY_MI2S_TX 35
+#define SECONDARY_MI2S_RX  36
+#define SECONDARY_MI2S_TX  37
+#define TERTIARY_MI2S_RX   38
+#define TERTIARY_MI2S_TX   39
+#define PRIMARY_MI2S_RX40
+#define PRIMARY_MI2S_TX41
Can we assign ids to Primary, secondary, tertiary and quaternary MI2S 
ports in sequence starting with Primary.

+#define SECONDARY_PCM_RX   42
+#define SECONDARY_PCM_TX   43

Why only SECONDARY_PCM_RX ? This is not required for MI2S right?

  #define SLIMBUS_6_RX45
  #define SLIMBUS_6_TX46


[..]


Re: [alsa-devel] [PATCH v4 02/24] soc: qcom: Add APR bus driver

2018-03-14 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 


[..]

+struct bus_type aprbus_type = {
+   .name   = "aprbus",
+   .match  = apr_device_match,
+   .probe  = apr_device_probe,
+   .remove = apr_device_remove,
+   .force_dma  = true,


There is no need of force_dma now as machine driver is not child of apr. 
Please remove it.

+};
+EXPORT_SYMBOL_GPL(aprbus_type);
+





Re: [alsa-devel] [PATCH v4 14/24] ASoC: qdsp6: q6asm: Add support to audio stream apis

2018-04-09 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla <srinivas.kandaga...@linaro.org>

This patch adds support to open, write and media format commands
in the q6asm module.

Signed-off-by: Srinivas Kandagatla <srinivas.kandaga...@linaro.org>

Reviewed-and-Tested-by: Rohit kumar <rohi...@codeaurora.org>

---
  sound/soc/qcom/qdsp6/q6asm.c | 744 ++-
  sound/soc/qcom/qdsp6/q6asm.h |  49 +++
  2 files changed, 792 insertions(+), 1 deletion(-)

diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index 8a2ca2ff9ce8..ddbf526358bd 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -9,6 +9,8 @@
  #include 
  #include 
  #include 
+#include 
+#include 
  #include 
  #include 
  #include 
@@ -17,10 +19,36 @@
  #include "q6dsp-errno.h"
  #include "q6dsp-common.h"
  
+#define ASM_STREAM_CMD_CLOSE			0x00010BCD

+#define ASM_STREAM_CMD_FLUSH   0x00010BCE
+#define ASM_SESSION_CMD_PAUSE  0x00010BD3
+#define ASM_DATA_CMD_EOS   0x00010BDB
+#define ASM_DEFAULT_POPP_TOPOLOGY  0x00010BE4

Use NULL topology instead of default topology.
#define ASM_NULL_POPP_TOPOLOGY 0x00010C68

+#define ASM_STREAM_CMD_FLUSH_READBUFS  0x00010C09
+#define ASM_STREAM_CMD_SET_ENCDEC_PARAM0x00010C10

[..]

+   q6asm_add_hdr(ac, , sizeof(open), true, ac->stream_id);
+
+   open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V3;
+   open.mode_flags = 0x00;
+   open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
+
+   /* source endpoint : matrix */
+   open.sink_endpointype = ASM_END_POINT_DEVICE_MATRIX;
+   open.bits_per_sample = bits_per_sample;
+   open.postprocopo_id = ASM_DEFAULT_POPP_TOPOLOGY;

 open.postprocopo_id = ASM_NULL_POPP_TOPOLOGY;

+
+   switch (format) {
+   case FORMAT_LINEAR_PCM:
+   open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
+   break;
+   default:
+   dev_err(ac->dev, "Invalid format 0x%x\n", format);
+   return -EINVAL;
+   }
+
+   rc = q6asm_ac_send_cmd_sync(ac, );
+   if (rc < 0)
+   return rc;
+
+   ac->io_mode |= ASM_TUN_WRITE_IO_MODE;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(q6asm_open_write);


[PATCH v2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-06-29 Thread Rohit kumar
This adds APSS based ADSP PIL driver for QCOM SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 
---
Changes since v1:
- Used APIs from qcom_q6v5.c
- Use clock, reset and regmap driver APIs instead of 
  directly writing into the LPASS registers.
- Created new file for non PAS ADSP PIL instead of extending
  existing ADSP PIL driver.
- cleanups as suggested by Bjorn and Rob.

 .../bindings/remoteproc/qcom,non-pas-adsp.txt  | 138 +
 drivers/remoteproc/Kconfig |  18 +
 drivers/remoteproc/Makefile|   1 +
 drivers/remoteproc/qcom_nonpas_adsp_pil.c  | 667 +
 4 files changed, 824 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
 create mode 100644 drivers/remoteproc/qcom_nonpas_adsp_pil.c

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
new file mode 100644
index 000..0581aaa
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
@@ -0,0 +1,138 @@
+Qualcomm Technology Inc. Non PAS ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and boots firmware
+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sdm845-apss-adsp-pil"
+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: must specify the base address and size of the qdsp6ss
+
+- reg-names:
+   Usage: required
+   Value type: 
+   Definition: must be "qdsp6ss"
+
+- interrupts-extended:
+   Usage: required
+   Value type: 
+   Definition: must list the watchdog, fatal IRQs ready, handover and
+   stop-ack IRQs
+
+- interrupt-names:
+   Usage: required
+   Value type: 
+   Definition: must be "wdog", "fatal", "ready", "handover", "stop-ack"
+
+- clocks:
+   Usage: required
+   Value type: 
+   Definition:  List of phandle and clock specifier pairs
+
+- clock-names:
+   Usage: required
+   Value type: 
+   Definition: List of clock input name strings sorted in the same
+   order as the clocks property.
+
+- resets:
+   Usage: required
+   Value type: 
+   Definition: reference to the reset-controller for the lpass
+
+- reset-names:
+Usage: required
+Value type: 
+Definition: must be "pdc_sync" and "cc_lpass"
+
+- qcom,halt-regs:
+   Usage: required
+   Value type: 
+   Definition: a phandle reference to a syscon representing TCSR followed
+   by the offset within syscon for lpass halt register.
+
+- cx-supply:
+   Usage: required
+   Value type: 
+   Definition: reference to the regulator to be held on behalf of the
+   booting Hexagon core
+
+- px-supply:
+   Usage: optional
+   Value type: 
+   Definition: reference to the px regulator to be held on behalf of the
+   booting Hexagon core
+
+- memory-region:
+   Usage: required
+   Value type: 
+   Definition: reference to the reserved-memory for the ADSP
+
+- qcom,smem-states:
+   Usage: required
+   Value type: 
+   Definition: reference to the smem state for requesting the ADSP to
+   shut down
+
+- qcom,smem-state-names:
+   Usage: required
+   Value type: 
+   Definition: must be "stop"
+
+
+= SUBNODES
+The adsp node may have an subnode named either "smd-edge" or "glink-edge" that
+describes the communication edge, channels and devices related to the ADSP.
+See ../soc/qcom/qcom,smd.txt and ../soc/qcom/qcom,glink.txt for details on how
+to describe these.
+
+
+= EXAMPLE
+The following example describes the resources needed to boot control the
+ADSP, as it is found on SDM845 boards.
+   adsp-pil {
+   compatible = "qcom,sdm845-apss-adsp-pil";
+
+   reg = <0x1730 0x40c>;
+   reg-names = "qdsp6ss";
+
+   interrupts-extended = < 0 162 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 0 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 1 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 2 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 3 IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+   "handover", "stop-ack";
+
+   clocks = <_rpmh RPMH_CXO_CLK>,
+

Re: [alsa-devel] [PATCH v2 1/2] ASoC: qcom: dt-bindings: Add sdm845 machine bindings

2018-06-28 Thread Rohit Kumar

Thanks Rob for reviewing.


On 6/26/2018 12:47 AM, Rob Herring wrote:

On Thu, Jun 21, 2018 at 04:23:18PM +0530, Rohit kumar wrote:

Add devicetree bindings documentation file for SDM845 sound card.

Signed-off-by: Rohit kumar 
---
  .../devicetree/bindings/sound/qcom,sdm845.txt  | 82 ++
  1 file changed, 82 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/sound/qcom,sdm845.txt

diff --git a/Documentation/devicetree/bindings/sound/qcom,sdm845.txt 
b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
new file mode 100644
index 000..68feb08
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/qcom,sdm845.txt
@@ -0,0 +1,82 @@
+* Qualcomm Technologies Inc. SDM845 ASoC sound card driver
+
+This binding describes the SDM845 sound card, which uses qdsp for audio.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be "qcom,sdm845-sndcard"
+
+- qcom,audio-routing:

Use just 'audio-routing'.


This is same which is being followed in apq8096 machine driver. As all 
qcom machine drivers will
mostly follow the same design, Vinod asked to pull out the APIs in 
common file - https://patchwork.kernel.org/patch/10479625/ .
Same is for qcom,model. I will add missing documentation for it in the 
next patchset.



+   Usage: Optional
+   Value type: 
+   Definition:  A list of the connections between audio components.
+ Each entry is a pair of strings, the first being the
+ connection's sink, the second being the connection's
+ source. Valid names could be power supplies, MicBias
+ of codec and the jacks on the board.
+
+- cdc-vdd-supply:
+   Usage: Optional
+   Value type: 
+   Definition: phandle of regulator supply required for codec vdd.

The codec supply should be in the codec node.


Sure. Will add this in codec driver.

+
+= dailinks
+Each subnode of sndcard represents either a dailink, and subnodes of each
+dailinks would be cpu/codec/platform dais.
+
+- link-name:
+   Usage: required
+   Value type: 
+   Definition: User friendly name for dai link
+
+= CPU, PLATFORM, CODEC dais subnodes
+- cpu:
+   Usage: required
+   Value type: 
+   Definition: cpu dai sub-node
+
+- codec:
+   Usage: required
+   Value type: 
+   Definition: codec dai sub-node
+
+- platform:
+   Usage: Optional
+   Value type: 
+   Definition: platform dai sub-node
+
+- sound-dai:
+   Usage: required
+   Value type: 
+   Definition: dai phandle/s and port of CPU/CODEC/PLATFORM node.
+
+Example:
+
+audio {
+   compatible = "qcom,sdm845-sndcard";
+   qcom,model = "sdm845-snd-card";

Not documented. Just use 'model'.


+   pinctrl-names = "default", "sleep";
+   pinctrl-0 = <_mi2s_active _mi2s_ws_active>;
+   pinctrl-1 = <_mi2s_sleep _mi2s_ws_sleep>;
+
+   cdc-vdd-supply = <_l14>;
+
+   mm1-dai-link {
+   link-name = "MultiMedia1";
+   cpu {
+   sound-dai = < MSM_FRONTEND_DAI_MULTIMEDIA1>;
+   };
+   };
+
+   pri-mi2s-dai-link {
+   link-name = "PRI MI2S Playback";
+   cpu {
+   sound-dai = < PRIMARY_MI2S_RX>;
+   };
+
+   platform {
+   sound-dai = <>;
+   };
+   };
+};
--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.


___
Alsa-devel mailing list
alsa-de...@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel


Regards,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH] ASoC: qdsp6: q6afe: Fix wrong MI2S SD line mask

2018-11-01 Thread Rohit kumar
SD line mask for MI2S starts from BIT 0 instead of BIT 1.
Fix all bit mask for MI2S SD lines.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/qdsp6/q6afe.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c
index 000775b..829b5e987 100644
--- a/sound/soc/qcom/qdsp6/q6afe.c
+++ b/sound/soc/qcom/qdsp6/q6afe.c
@@ -49,14 +49,14 @@
 #define AFE_PORT_I2S_SD1   0x2
 #define AFE_PORT_I2S_SD2   0x3
 #define AFE_PORT_I2S_SD3   0x4
-#define AFE_PORT_I2S_SD0_MASK  BIT(0x1)
-#define AFE_PORT_I2S_SD1_MASK  BIT(0x2)
-#define AFE_PORT_I2S_SD2_MASK  BIT(0x3)
-#define AFE_PORT_I2S_SD3_MASK  BIT(0x4)
-#define AFE_PORT_I2S_SD0_1_MASKGENMASK(2, 1)
-#define AFE_PORT_I2S_SD2_3_MASKGENMASK(4, 3)
-#define AFE_PORT_I2S_SD0_1_2_MASK  GENMASK(3, 1)
-#define AFE_PORT_I2S_SD0_1_2_3_MASKGENMASK(4, 1)
+#define AFE_PORT_I2S_SD0_MASK  BIT(0x0)
+#define AFE_PORT_I2S_SD1_MASK  BIT(0x1)
+#define AFE_PORT_I2S_SD2_MASK  BIT(0x2)
+#define AFE_PORT_I2S_SD3_MASK  BIT(0x3)
+#define AFE_PORT_I2S_SD0_1_MASKGENMASK(1, 0)
+#define AFE_PORT_I2S_SD2_3_MASKGENMASK(3, 2)
+#define AFE_PORT_I2S_SD0_1_2_MASK  GENMASK(2, 0)
+#define AFE_PORT_I2S_SD0_1_2_3_MASKGENMASK(3, 0)
 #define AFE_PORT_I2S_QUAD010x5
 #define AFE_PORT_I2S_QUAD230x6
 #define AFE_PORT_I2S_6CHS  0x7
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH] ASoC: core: Invoke pcm_new() for all DAI-link

2018-11-01 Thread Rohit kumar
Remove no_pcm check to invoke pcm_new() for backend dai-links
too. This fixes crash in hdmi codec driver during hdmi_codec_startup()
while accessing chmap_info struct. chmap_info struct memory is
allocated in pcm_new() of hdmi codec driver which is not invoked
in case of DPCM when hdmi codec driver is part of backend dai-link.

Below is the crash stack:

[   61.635493] Unable to handle kernel NULL pointer dereference at virtual 
address 0018
..
[   61.96]   CM = 0, WnR = 1
[   61.669778] user pgtable: 4k pages, 39-bit VAs, pgd = ffc0d6633000
[   61.676526] [0018] *pgd=000153fc8003, *pud=000153fc8003, 
*pmd=
[   61.685793] Internal error: Oops: 9646 [#1] PREEMPT SMP
[   61.722955] CPU: 7 PID: 2238 Comm: aplay Not tainted 4.14.72 #21
..
[   61.740269] PC is at hdmi_codec_startup+0x124/0x164
[   61.745308] LR is at hdmi_codec_startup+0xe4/0x164

Signed-off-by: Rohit kumar 
---
 sound/soc/soc-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 6ddcf12..abdc460 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1467,7 +1467,7 @@ static int soc_link_dai_pcm_new(struct snd_soc_dai 
**dais, int num_dais,
for (i = 0; i < num_dais; ++i) {
struct snd_soc_dai_driver *drv = dais[i]->driver;
 
-   if (!rtd->dai_link->no_pcm && drv->pcm_new)
+   if (drv->pcm_new)
ret = drv->pcm_new(rtd, dais[i]);
if (ret < 0) {
dev_err(dais[i]->dev,
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [PATCH] ASoC: core: Invoke pcm_new() for all DAI-link

2018-11-02 Thread Rohit Kumar



On 11/2/2018 1:12 PM, Takashi Iwai wrote:

On Thu, 01 Nov 2018 13:38:49 +0100,
Rohit kumar wrote:

Remove no_pcm check to invoke pcm_new() for backend dai-links
too. This fixes crash in hdmi codec driver during hdmi_codec_startup()
while accessing chmap_info struct. chmap_info struct memory is
allocated in pcm_new() of hdmi codec driver which is not invoked
in case of DPCM when hdmi codec driver is part of backend dai-link.

Below is the crash stack:

[   61.635493] Unable to handle kernel NULL pointer dereference at virtual 
address 0018
..
[   61.96]   CM = 0, WnR = 1
[   61.669778] user pgtable: 4k pages, 39-bit VAs, pgd = ffc0d6633000
[   61.676526] [0018] *pgd=000153fc8003, *pud=000153fc8003, 
*pmd=
[   61.685793] Internal error: Oops: 9646 [#1] PREEMPT SMP
[   61.722955] CPU: 7 PID: 2238 Comm: aplay Not tainted 4.14.72 #21
..
[   61.740269] PC is at hdmi_codec_startup+0x124/0x164
[   61.745308] LR is at hdmi_codec_startup+0xe4/0x164

Signed-off-by: Rohit kumar 

Did you check whether all drivers have no side-effect by this change?
The hdmi-codec isn't the only driver that has pcm_new ops, so we have
to make sure that such a fundamental change wouldn't bring any
regressions.


Below are the drivers calling pcm_new() other than hdmi codec driver.
sound/soc/meson/axg-frddr.c
sound/soc/meson/axg-toddr.c
These two drivers are frontend DAI drivers and should not be impacted
because of this.

Other than this, pcm_new() is called from sound/soc/stm/stm32_sai_sub.c
I could not get much info about this driver. However, it is just adding
kcontrols in pcm_new() which uses internal private structs in get()/put().
Olivier Moysan can too confirm on this.

Thanks,
Rohit

thanks,

Takashi


--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member
of the Code Aurora Forum, hosted by the Linux Foundation.



Re: [alsa-devel] [PATCH] ASoC: core: Invoke pcm_new() for all DAI-link

2018-11-05 Thread Rohit Kumar

Hello Arnaud,


On 11/5/2018 4:43 PM, Arnaud Pouliquen wrote:

Hello Rohit,

On 11/2/18 1:06 PM, Rohit Kumar wrote:

On 11/2/2018 1:12 PM, Takashi Iwai wrote:

On Thu, 01 Nov 2018 13:38:49 +0100,
Rohit kumar wrote:

Remove no_pcm check to invoke pcm_new() for backend dai-links
too. This fixes crash in hdmi codec driver during hdmi_codec_startup()
while accessing chmap_info struct. chmap_info struct memory is
allocated in pcm_new() of hdmi codec driver which is not invoked
in case of DPCM when hdmi codec driver is part of backend dai-link.

Below is the crash stack:

[   61.635493] Unable to handle kernel NULL pointer dereference at
virtual address 0018
..
[   61.96]   CM = 0, WnR = 1
[   61.669778] user pgtable: 4k pages, 39-bit VAs, pgd =
ffc0d6633000
[   61.676526] [0018] *pgd=000153fc8003,
*pud=000153fc8003, *pmd=
[   61.685793] Internal error: Oops: 9646 [#1] PREEMPT SMP
[   61.722955] CPU: 7 PID: 2238 Comm: aplay Not tainted 4.14.72 #21
..
[   61.740269] PC is at hdmi_codec_startup+0x124/0x164
[   61.745308] LR is at hdmi_codec_startup+0xe4/0x164

Signed-off-by: Rohit kumar 

Did you check whether all drivers have no side-effect by this change?
The hdmi-codec isn't the only driver that has pcm_new ops, so we have
to make sure that such a fundamental change wouldn't bring any
regressions.


Below are the drivers calling pcm_new() other than hdmi codec driver.
sound/soc/meson/axg-frddr.c
sound/soc/meson/axg-toddr.c
These two drivers are frontend DAI drivers and should not be impacted
because of this.

Other than this, pcm_new() is called from sound/soc/stm/stm32_sai_sub.c
I could not get much info about this driver. However, it is just adding
kcontrols in pcm_new() which uses internal private structs in get()/put().
Olivier Moysan can too confirm on this.

First, i'm answering  for Olivier: no regression identified for the SAI
driver, it is not a DPCM driver.

Then i have a concern about the call of pcm_new for a no-PCM backend.
Does it make sense? In DPCM concept, the backend is not linked to the
PCM device...

Instead, I would suggest that you add protection in HDMI_codec on
chmap_info pointer.

The drawback would be that the control is no more available...do you
need it?

I don't need chmap_info, but ELD kcontrol is also defined in pcm_new() which
we need. We should probably update the driver to make it compatible with
DPCM. Any suggestions?

Regards
Arnaud


Thanks,
Rohit

thanks,

Takashi

Thanks,
Rohit

--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member
of the Code Aurora Forum, hosted by the Linux Foundation.



[PATCH] ASoC: qcom: Set dai_link id to each dai_link

2018-11-08 Thread Rohit kumar
Frontend dai_link id is used for closing ADM sessions.
During concurrent usecase when one session is closed,
it closes other ADM session associated with other usecase
too. Dai_link->id should always point to Frontend dai id.
Set cpu_dai id as dai_link id to fix the issue.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/common.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
index eb1b9da..4715527 100644
--- a/sound/soc/qcom/common.c
+++ b/sound/soc/qcom/common.c
@@ -13,6 +13,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
struct device_node *cpu = NULL;
struct device *dev = card->dev;
struct snd_soc_dai_link *link;
+   struct of_phandle_args args;
int ret, num_links;
 
ret = snd_soc_of_parse_card_name(card, "model");
@@ -47,12 +48,14 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
goto err;
}
 
-   link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
-   if (!link->cpu_of_node) {
+   ret = of_parse_phandle_with_args(cpu, "sound-dai",
+   "#sound-dai-cells", 0, );
+   if (ret) {
dev_err(card->dev, "error getting cpu phandle\n");
-   ret = -EINVAL;
goto err;
}
+   link->cpu_of_node = args.np;
+   link->id = args.args[0];
 
ret = snd_soc_of_get_dai_name(cpu, >cpu_dai_name);
if (ret) {
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH 0/2] ASoC: SDM845: Update MI2S and TDM configuration

2018-11-15 Thread Rohit kumar
Update bit clock rate, slot width for TDM and MI2S
interfaces. Also add support for secondary MI2S TX
interface in SDM845 machine driver.

Rohit kumar (2):
  ASoC: sdm845: Update slot_width for Quaternary TDM port
  ASoC: sdm845: Add support for Secondary MI2S interface

 sound/soc/qcom/sdm845.c | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH 1/2] ASoC: sdm845: Update slot_width for Quaternary TDM port

2018-11-15 Thread Rohit kumar
Change slot_width for quaternary TDM port to 16 and
update bclk rate for TDM and MI2S interfaces
accordingly.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/sdm845.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
index 8d0cdff..84e6ee7 100644
--- a/sound/soc/qcom/sdm845.c
+++ b/sound/soc/qcom/sdm845.c
@@ -13,7 +13,8 @@
 
 #define DEFAULT_SAMPLE_RATE_48K48000
 #define DEFAULT_MCLK_RATE  24576000
-#define DEFAULT_BCLK_RATE  12288000
+#define TDM_BCLK_RATE  6144000
+#define MI2S_BCLK_RATE 1536000
 
 struct sdm845_snd_data {
struct snd_soc_card *card;
@@ -33,7 +34,7 @@ static int sdm845_tdm_snd_hw_params(struct snd_pcm_substream 
*substream,
 
switch (params_format(params)) {
case SNDRV_PCM_FORMAT_S16_LE:
-   slot_width = 32;
+   slot_width = 16;
break;
default:
dev_err(rtd->dev, "%s: invalid param format 0x%x\n",
@@ -115,7 +116,7 @@ static int sdm845_snd_startup(struct snd_pcm_substream 
*substream)
DEFAULT_MCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
snd_soc_dai_set_sysclk(cpu_dai,
Q6AFE_LPASS_CLK_ID_PRI_MI2S_IBIT,
-   DEFAULT_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+   MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
}
snd_soc_dai_set_fmt(cpu_dai, fmt);
break;
@@ -125,7 +126,7 @@ static int sdm845_snd_startup(struct snd_pcm_substream 
*substream)
if (++(data->quat_tdm_clk_count) == 1) {
snd_soc_dai_set_sysclk(cpu_dai,
Q6AFE_LPASS_CLK_ID_QUAD_TDM_IBIT,
-   DEFAULT_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
+   TDM_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);
}
break;
 
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH 2/2] ASoC: sdm845: Add support for Secondary MI2S interface

2018-11-15 Thread Rohit kumar
Add support to configure bit clock for secondary MI2S
TX interface.

Signed-off-by: Rohit kumar 
---
 sound/soc/qcom/sdm845.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
index 84e6ee7..58593db 100644
--- a/sound/soc/qcom/sdm845.c
+++ b/sound/soc/qcom/sdm845.c
@@ -19,6 +19,7 @@
 struct sdm845_snd_data {
struct snd_soc_card *card;
uint32_t pri_mi2s_clk_count;
+   uint32_t sec_mi2s_clk_count;
uint32_t quat_tdm_clk_count;
 };
 
@@ -121,6 +122,15 @@ static int sdm845_snd_startup(struct snd_pcm_substream 
*substream)
snd_soc_dai_set_fmt(cpu_dai, fmt);
break;
 
+   case SECONDARY_MI2S_TX:
+   if (++(data->sec_mi2s_clk_count) == 1) {
+   snd_soc_dai_set_sysclk(cpu_dai,
+   Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
+   MI2S_BCLK_RATE, SNDRV_PCM_STREAM_CAPTURE);
+   }
+   snd_soc_dai_set_fmt(cpu_dai, fmt);
+   break;
+
case QUATERNARY_TDM_RX_0:
case QUATERNARY_TDM_TX_0:
if (++(data->quat_tdm_clk_count) == 1) {
@@ -157,6 +167,14 @@ static void  sdm845_snd_shutdown(struct snd_pcm_substream 
*substream)
};
break;
 
+   case SECONDARY_MI2S_TX:
+   if (--(data->sec_mi2s_clk_count) == 0) {
+   snd_soc_dai_set_sysclk(cpu_dai,
+   Q6AFE_LPASS_CLK_ID_SEC_MI2S_IBIT,
+   0, SNDRV_PCM_STREAM_CAPTURE);
+   }
+   break;
+
case QUATERNARY_TDM_RX_0:
case QUATERNARY_TDM_TX_0:
if (--(data->quat_tdm_clk_count) == 0) {
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [PATCH 2/2] ASoC: qdsp6: q6afe-dai: Fix the dai widgets

2018-11-06 Thread Rohit Kumar

Thanks Srinivas for the fix.


On 11/6/2018 5:08 PM, Srinivas Kandagatla wrote:

For some reason the dapm widgets are incorrectly defined from the start,
Not sure how we ended up with such thing. Fix them now!

Without this fix the backend dais are always powered up even if there
is no active stream.

Reported-by: Jimmy Cheng-Yi Chiang 
Reported-by: Rohit kumar 

Tested-by: Rohit kumar 

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/qdsp6/q6afe-dai.c | 208 +++
  1 file changed, 104 insertions(+), 104 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c
index 60ff4a2d3577..8f6c8fc073a9 100644
--- a/sound/soc/qcom/qdsp6/q6afe-dai.c
+++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
@@ -1112,204 +1112,204 @@ static int q6afe_of_xlate_dai_name(struct 
snd_soc_component *component,
  }
  
  static const struct snd_soc_dapm_widget q6afe_dai_widgets[] = {

-   SND_SOC_DAPM_AIF_OUT("HDMI_RX", "HDMI Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SLIMBUS_0_RX", "Slimbus Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SLIMBUS_1_RX", "Slimbus1 Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SLIMBUS_2_RX", "Slimbus2 Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SLIMBUS_3_RX", "Slimbus3 Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SLIMBUS_4_RX", "Slimbus4 Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SLIMBUS_5_RX", "Slimbus5 Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SLIMBUS_6_RX", "Slimbus6 Playback", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SLIMBUS_0_TX", "Slimbus Capture", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SLIMBUS_1_TX", "Slimbus1 Capture", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SLIMBUS_2_TX", "Slimbus2 Capture", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SLIMBUS_3_TX", "Slimbus3 Capture", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SLIMBUS_4_TX", "Slimbus4 Capture", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SLIMBUS_5_TX", "Slimbus5 Capture", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SLIMBUS_6_TX", "Slimbus6 Capture", 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("QUAT_MI2S_RX", "Quaternary MI2S Playback",
+   SND_SOC_DAPM_AIF_IN("HDMI_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("SLIMBUS_0_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("SLIMBUS_1_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("SLIMBUS_2_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("SLIMBUS_3_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("SLIMBUS_4_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("SLIMBUS_5_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("SLIMBUS_6_RX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_OUT("SLIMBUS_0_TX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_OUT("SLIMBUS_1_TX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_OUT("SLIMBUS_2_TX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_OUT("SLIMBUS_3_TX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_OUT("SLIMBUS_4_TX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_OUT("SLIMBUS_5_TX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_OUT("SLIMBUS_6_TX", NULL, 0, 0, 0, 0),
+   SND_SOC_DAPM_AIF_IN("QUAT_MI2S_RX", NULL,
0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("QUAT_MI2S_TX", "Quaternary MI2S Capture",
+   SND_SOC_DAPM_AIF_OUT("QUAT_MI2S_TX", NULL,
0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("TERT_MI2S_RX", "Tertiary MI2S Playback",
+   SND_SOC_DAPM_AIF_IN("TERT_MI2S_RX", NULL,
0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("TERT_MI2S_TX", "Tertiary MI2S Capture",
+   SND_SOC_DAPM_AIF_OUT("TERT_MI2S_TX", NULL,
0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SEC_MI2S_RX", "Secondary MI2S Playback",
+   SND_SOC_DAPM_AIF_IN("SEC_MI2S_RX", NULL,
 0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_IN("SEC_MI2S_TX", "Secondary MI2S Capture",
+   SND_SOC_DAPM_AIF_OUT("SEC_MI2S_TX", NULL,
0, 0, 0, 0),
-   SND_SOC_DAPM_AIF_OUT("SEC_MI2S_RX_SD1",
+   SND_SOC_DAPM_AIF_IN("SEC_MI2S_RX_SD1",
"Secondary MI2S Playback SD1",
0, 0, 0, 0),
-   SND_S

Re: [PATCH v2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-08-30 Thread Rohit Kumar

Thanks Bjorn for reviewing the patch.


On 8/28/2018 11:39 AM, Bjorn Andersson wrote:

On Fri 29 Jun 02:20 PDT 2018, Rohit kumar wrote:


This adds APSS based ADSP PIL driver for QCOM SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).


Hi Rohit,

I've submitted a patch that renames the PAS based adsp driver, please
rebase your patch upon this.


Sure.

Signed-off-by: Rohit kumar 
---
Changes since v1:
- Used APIs from qcom_q6v5.c
- Use clock, reset and regmap driver APIs instead of
   directly writing into the LPASS registers.
- Created new file for non PAS ADSP PIL instead of extending
   existing ADSP PIL driver.
- cleanups as suggested by Bjorn and Rob.

  .../bindings/remoteproc/qcom,non-pas-adsp.txt  | 138 +
  drivers/remoteproc/Kconfig |  18 +
  drivers/remoteproc/Makefile|   1 +
  drivers/remoteproc/qcom_nonpas_adsp_pil.c  | 667 +
  4 files changed, 824 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
  create mode 100644 drivers/remoteproc/qcom_nonpas_adsp_pil.c

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt
new file mode 100644
index 000..0581aaa
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,non-pas-adsp.txt

qcom,adsp-pil.txt


@@ -0,0 +1,138 @@
+Qualcomm Technology Inc. Non PAS ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and boots firmware
+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sdm845-apss-adsp-pil"

"qcom,sdm845-adsp-pil"


ok

+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: must specify the base address and size of the qdsp6ss
+
+- reg-names:
+   Usage: required
+   Value type: 
+   Definition: must be "qdsp6ss"

No need for reg-names when we have a single reg.


ok

+
+- interrupts-extended:
+   Usage: required
+   Value type: 
+   Definition: must list the watchdog, fatal IRQs ready, handover and
+   stop-ack IRQs
+

[..]

+
+= EXAMPLE
+The following example describes the resources needed to boot control the
+ADSP, as it is found on SDM845 boards.
+   adsp-pil {
+   compatible = "qcom,sdm845-apss-adsp-pil";
+
+   reg = <0x1730 0x40c>;
+   reg-names = "qdsp6ss";
+
+   interrupts-extended = < 0 162 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 0 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 1 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 2 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 3 IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+   "handover", "stop-ack";
+
+   clocks = <_rpmh RPMH_CXO_CLK>,
+   < GCC_LPASS_SWAY_CLK>,
+   < LPASS_AUDIO_WRAPPER_AON_CLK>,
+   < LPASS_Q6SS_AHBS_AON_CLK>,
+   < LPASS_Q6SS_AHBM_AON_CLK>,
+   < LPASS_QDSP6SS_XO_CLK>,
+   < LPASS_QDSP6SS_SLEEP_CLK>,
+   < LPASS_QDSP6SS_CORE_CLK>;
+   clock-names = "xo", "sway_cbcr", "lpass_aon",
+   "lpass_ahbs_aon_cbcr",
+   "lpass_ahbm_aon_cbcr", "qdsp6ss_xo",
+   "qdsp6ss_sleep", "qdsp6ss_core";
+
+   cx-supply = <_s9_level>;

If this is a corner you should use the power-domain reference to the
appropriate rpmhpd resource.


ok, will update it in next patchset

+
+   resets = <_reset PDC_AUDIO_SYNC_RESET>,
+<_reset AOSS_CC_LPASS_RESTART>;
+   reset-names = "pdc_sync", "cc_lpass";
+
+   qcom,halt-regs = <_mutex_regs 0x22000>;
+
+   memory-region = <_adsp_mem>;
+
+   qcom,smem-states = <_smp2p_out 0>;
+   qcom,smem-state-names = "stop";
+   };
diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 0dde375..9de0a53 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -100,6 +100,24 @@ config QCOM_ADSP_PIL
  Say y here to support the TrustZone based Peripherial Image Loader
  for the Qualcomm ADSP remote processors.
  
+config QCOM_NON_PAS_ADSP_PIL

QCOM_ADSP_

Re: [PATCH] remoteproc: qcom: Rename Hexagon v5 PAS driver

2018-08-30 Thread Rohit Kumar

Thanks Bjorn for posting the patch.


On 8/28/2018 10:42 AM, Bjorn Andersson wrote:

The Hexagon v5 ADSP driver is used for more than only the ADSP and
there's an upcoming non-PAS ADSP PIL for SDM845, so rename the driver to
qcom_q6v5_pas in order to better suite this.

Cc: Rohit kumar 
Signed-off-by: Bjorn Andersson 
---
  drivers/remoteproc/Kconfig| 22 +--
  drivers/remoteproc/Makefile   |  2 +-
  .../{qcom_adsp_pil.c => qcom_q6v5_pas.c}  |  4 ++--
  3 files changed, 14 insertions(+), 14 deletions(-)
  rename drivers/remoteproc/{qcom_adsp_pil.c => qcom_q6v5_pas.c} (98%)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 052d4dd347f9..c98c0b2a2237 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -84,8 +84,16 @@ config KEYSTONE_REMOTEPROC
  It's safe to say N here if you're not interested in the Keystone
  DSPs or just want to use a bare minimum kernel.
  
-config QCOM_ADSP_PIL

-   tristate "Qualcomm ADSP Peripheral Image Loader"
+config QCOM_RPROC_COMMON
+   tristate
+
+config QCOM_Q6V5_COMMON
+   tristate
+   depends on ARCH_QCOM
+   depends on QCOM_SMEM
+
+config QCOM_Q6V5_PAS
+   tristate "Qualcomm Hexagon v5 Peripheral Authentication Service support"
depends on OF && ARCH_QCOM
depends on QCOM_SMEM
depends on RPMSG_QCOM_SMD || (COMPILE_TEST && RPMSG_QCOM_SMD=n)
@@ -98,15 +106,7 @@ config QCOM_ADSP_PIL
select QCOM_SCM
help
  Say y here to support the TrustZone based Peripherial Image Loader
- for the Qualcomm ADSP remote processors.
-
-config QCOM_RPROC_COMMON
-   tristate
-
-config QCOM_Q6V5_COMMON
-   tristate
-   depends on ARCH_QCOM
-   depends on QCOM_SMEM
+ for the Qualcomm Hexagon v5 based remote processors.
  
  config QCOM_Q6V5_PIL

tristate "Qualcomm Hexagon V5 Peripherial Image Loader"
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 03332fa7e2ee..eb86c8ba5a87 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -14,9 +14,9 @@ obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
  obj-$(CONFIG_WKUP_M3_RPROC)   += wkup_m3_rproc.o
  obj-$(CONFIG_DA8XX_REMOTEPROC)+= da8xx_remoteproc.o
  obj-$(CONFIG_KEYSTONE_REMOTEPROC) += keystone_remoteproc.o
-obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp_pil.o
  obj-$(CONFIG_QCOM_RPROC_COMMON)   += qcom_common.o
  obj-$(CONFIG_QCOM_Q6V5_COMMON)+= qcom_q6v5.o
+obj-$(CONFIG_QCOM_Q6V5_PAS)+= qcom_q6v5_pas.o
  obj-$(CONFIG_QCOM_Q6V5_PIL)   += qcom_q6v5_pil.o
  obj-$(CONFIG_QCOM_Q6V5_WCSS)  += qcom_q6v5_wcss.o
  obj-$(CONFIG_QCOM_SYSMON) += qcom_sysmon.o
diff --git a/drivers/remoteproc/qcom_adsp_pil.c 
b/drivers/remoteproc/qcom_q6v5_pas.c
similarity index 98%
rename from drivers/remoteproc/qcom_adsp_pil.c
rename to drivers/remoteproc/qcom_q6v5_pas.c
index d4339a6da616..2478ef3cd519 100644
--- a/drivers/remoteproc/qcom_adsp_pil.c
+++ b/drivers/remoteproc/qcom_q6v5_pas.c
@@ -364,11 +364,11 @@ static struct platform_driver adsp_driver = {
.probe = adsp_probe,
.remove = adsp_remove,
.driver = {
-   .name = "qcom_adsp_pil",
+   .name = "qcom_q6v5_pas",
.of_match_table = adsp_of_match,
},
  };
  
  module_platform_driver(adsp_driver);

-MODULE_DESCRIPTION("Qualcomm MSM8974/MSM8996 ADSP Peripherial Image Loader");
+MODULE_DESCRIPTION("Qualcomm Hexagon v5 Peripheral Authentication Service 
driver");


Probable, we should make similar change at header comment.
 * Qualcomm ADSP/SLPI Peripheral Image Loader for MSM8974 and MSM8996
 *


  MODULE_LICENSE("GPL v2");




[PATCH v3 0/2] Add ADSP PIL driver for SDM845

2018-09-03 Thread Rohit kumar
This provides initial patchset for ADSP PIL driver for SDM845.

Changes since v2:
Separated dt-bindings documentation into separate patch.
Used clk_bulk APIs for adsp clocks.
Used power domain API and use reference to rpmhd resource.
Renamed qcom_nonpas_adsp_pil.c to qcom_adsp_pil.c
Removed smd as sdm845 does not support smd.
Removed px_supply and aggre2_clk for sdm845 as they are not required.
Removed reg-names as there is only one register.

This patch is dependent on the rpmh powerdomain driver 
https://lkml.org/lkml/2018/6/27/7
and renaming of Hexagon v5 PAS driver https://lkml.org/lkml/2018/8/28/129 .

Rohit kumar (2):
  dt-binding: remoteproc: Add QTI ADSP PIL bindings
  remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

 .../bindings/remoteproc/qcom,adsp-pil.txt  | 123 +
 drivers/remoteproc/Kconfig |  14 +
 drivers/remoteproc/Makefile|   1 +
 drivers/remoteproc/qcom_adsp_pil.c | 500 +
 4 files changed, 638 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
 create mode 100644 drivers/remoteproc/qcom_adsp_pil.c

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH v3 2/2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-09-03 Thread Rohit kumar
This adds Non PAS ADSP PIL driver for Qualcomm
Technologies Inc SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 
---
 drivers/remoteproc/Kconfig |  14 ++
 drivers/remoteproc/Makefile|   1 +
 drivers/remoteproc/qcom_adsp_pil.c | 500 +
 3 files changed, 515 insertions(+)
 create mode 100644 drivers/remoteproc/qcom_adsp_pil.c

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index c98c0b2..445de2d 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -139,6 +139,20 @@ config QCOM_Q6V5_WCSS
  Say y here to support the Qualcomm Peripheral Image Loader for the
  Hexagon V5 based WCSS remote processors.
 
+config QCOM_ADSP_PIL
+   tristate "Qualcomm Technology Inc ADSP Peripheral Image Loader"
+   depends on OF && ARCH_QCOM
+   depends on QCOM_SMEM
+   depends on RPMSG_QCOM_GLINK_SMEM || RPMSG_QCOM_GLINK_SMEM=n
+   depends on QCOM_SYSMON || QCOM_SYSMON=n
+   select MFD_SYSCON
+   select QCOM_MDT_LOADER
+   select QCOM_Q6V5_COMMON
+   select QCOM_RPROC_COMMON
+   help
+ Say y here to support the Peripherial Image Loader
+ for the Qualcomm Technology Inc. ADSP remote processors.
+
 config QCOM_SYSMON
tristate "Qualcomm sysmon driver"
depends on RPMSG
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index eb86c8b..1258519 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_QCOM_Q6V5_COMMON)+= qcom_q6v5.o
 obj-$(CONFIG_QCOM_Q6V5_PAS)+= qcom_q6v5_pas.o
 obj-$(CONFIG_QCOM_Q6V5_PIL)+= qcom_q6v5_pil.o
 obj-$(CONFIG_QCOM_Q6V5_WCSS)   += qcom_q6v5_wcss.o
+obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp_pil.o
 obj-$(CONFIG_QCOM_SYSMON)  += qcom_sysmon.o
 obj-$(CONFIG_QCOM_WCNSS_PIL)   += qcom_wcnss_pil.o
 qcom_wcnss_pil-y   += qcom_wcnss.o
diff --git a/drivers/remoteproc/qcom_adsp_pil.c 
b/drivers/remoteproc/qcom_adsp_pil.c
new file mode 100644
index 000..977e804
--- /dev/null
+++ b/drivers/remoteproc/qcom_adsp_pil.c
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Qualcomm Technology Inc. ADSP Peripheral Image Loader for SDM845.
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qcom_common.h"
+#include "qcom_q6v5.h"
+#include "remoteproc_internal.h"
+
+/* time out value */
+#define ACK_TIMEOUT1000
+#define BOOT_FSM_TIMEOUT   1
+/* mask values */
+#define EVB_MASK   GENMASK(27, 4)
+/*QDSP6SS register offsets*/
+#define RST_EVB_REG0x10
+#define CORE_START_REG 0x400
+#define BOOT_CMD_REG   0x404
+#define BOOT_STATUS_REG0x408
+#define RET_CFG_REG0x1C
+/*TCSR register offsets*/
+#define LPASS_MASTER_IDLE_REG  0x8
+#define LPASS_HALTACK_REG  0x4
+#define LPASS_PWR_ON_REG   0x10
+#define LPASS_HALTREQ_REG  0x0
+
+/* list of clocks required by ADSP PIL */
+static const char * const adsp_clk_id[] = {
+   "sway_cbcr", "lpass_aon", "lpass_ahbs_aon_cbcr", "lpass_ahbm_aon_cbcr",
+   "qdsp6ss_xo", "qdsp6ss_sleep", "qdsp6ss_core",
+};
+
+struct adsp_pil_data {
+   int crash_reason_smem;
+   const char *firmware_name;
+
+   const char *ssr_name;
+   const char *sysmon_name;
+   int ssctl_id;
+};
+
+struct qcom_adsp {
+   struct device *dev;
+   struct rproc *rproc;
+
+   struct qcom_q6v5 q6v5;
+
+   struct clk *xo;
+
+   int num_clks;
+   struct clk_bulk_data *clks;
+
+   void __iomem *qdsp6ss_base;
+
+   struct reset_control *pdc_sync_reset;
+   struct reset_control *cc_lpass_restart;
+
+   struct regmap *halt_map;
+   unsigned int  halt_lpass;
+
+   int crash_reason_smem;
+
+   struct completion start_done;
+   struct completion stop_done;
+
+   phys_addr_t mem_phys;
+   phys_addr_t mem_reloc;
+   void *mem_region;
+   size_t mem_size;
+
+   struct qcom_rproc_glink glink_subdev;
+   struct qcom_rproc_ssr ssr_subdev;
+   struct qcom_sysmon *sysmon;
+};
+
+static int qcom_adsp_shutdown(struct qcom_adsp *adsp)
+{
+   unsigned long timeout;
+   unsigned int val;
+   int ret;
+
+   /* Reset the retention logic */
+   val = readl(adsp->qdsp6ss_base + RET_CFG_REG);
+

[PATCH v3 1/2] dt-binding: remoteproc: Add QTI ADSP PIL bindings

2018-09-03 Thread Rohit kumar
Add devicetree bindings documentation file for Qualcomm
Technolgies Inc ADSP Peripheral Image Loader.

Signed-off-by: Rohit kumar 
---
 .../bindings/remoteproc/qcom,adsp-pil.txt  | 123 +
 1 file changed, 123 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
new file mode 100644
index 000..f1c215a
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
@@ -0,0 +1,123 @@
+Qualcomm Technology Inc. ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and boots firmware
+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sdm845-adsp-pil"
+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: must specify the base address and size of the qdsp6ss 
register
+
+- interrupts-extended:
+   Usage: required
+   Value type: 
+   Definition: must list the watchdog, fatal IRQs ready, handover and
+   stop-ack IRQs
+
+- interrupt-names:
+   Usage: required
+   Value type: 
+   Definition: must be "wdog", "fatal", "ready", "handover", "stop-ack"
+
+- clocks:
+   Usage: required
+   Value type: 
+   Definition:  List of phandle and clock specifier pairs
+
+- clock-names:
+   Usage: required
+   Value type: 
+   Definition: List of clock input name strings sorted in the same
+   order as the clocks property.
+
+- power-domains:
+   Usage: required
+   Value type: 
+   Definition: reference to cx power domain node.
+
+- resets:
+   Usage: required
+   Value type: 
+   Definition: reference to the reset-controller for the lpass
+
+- reset-names:
+Usage: required
+Value type: 
+Definition: must be "pdc_sync" and "cc_lpass"
+
+- qcom,halt-regs:
+   Usage: required
+   Value type: 
+   Definition: a phandle reference to a syscon representing TCSR followed
+   by the offset within syscon for lpass halt register.
+
+- memory-region:
+   Usage: required
+   Value type: 
+   Definition: reference to the reserved-memory for the ADSP
+
+- qcom,smem-states:
+   Usage: required
+   Value type: 
+   Definition: reference to the smem state for requesting the ADSP to
+   shut down
+
+- qcom,smem-state-names:
+   Usage: required
+   Value type: 
+   Definition: must be "stop"
+
+
+= SUBNODES
+The adsp node may have an subnode named "glink-edge" that describes the
+communication edge, channels and devices related to the ADSP.
+See ../soc/qcom/qcom,glink.txt for details on how to describe these.
+
+= EXAMPLE
+The following example describes the resources needed to boot control the
+ADSP, as it is found on SDM845 boards.
+   adsp-pil {
+   compatible = "qcom,sdm845-adsp-pil";
+
+   reg = <0x1730 0x40c>;
+
+   interrupts-extended = < 0 162 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 0 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 1 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 2 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 3 IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+   "handover", "stop-ack";
+
+   clocks = < RPMH_CXO_CLK>,
+   < GCC_LPASS_SWAY_CLK>,
+   < LPASS_AUDIO_WRAPPER_AON_CLK>,
+   < LPASS_Q6SS_AHBS_AON_CLK>,
+   < LPASS_Q6SS_AHBM_AON_CLK>,
+   < LPASS_QDSP6SS_XO_CLK>,
+   < LPASS_QDSP6SS_SLEEP_CLK>,
+   < LPASS_QDSP6SS_CORE_CLK>;
+   clock-names = "xo", "sway_cbcr", "lpass_aon",
+   "lpass_ahbs_aon_cbcr",
+   "lpass_ahbm_aon_cbcr", "qdsp6ss_xo",
+   "qdsp6ss_sleep", "qdsp6ss_core";
+
+   power-domains = < SDM845_CX>;
+
+   resets = <_reset PDC_AUDIO_SYNC_RESET>,
+<_reset AOSS_CC_LPASS_RESTART>;
+   reset-names = "pdc_sync", "cc_lpass";
+
+   qcom,halt-regs = <_mutex_regs 0x22000>;
+
+   memory-region = <_adsp_mem>;
+
+   qcom,smem-states = <_smp2p_out 0>;
+   qcom,smem-state-names = "stop";
+   };
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [PATCH v3 2/2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-09-24 Thread Rohit Kumar




On 9/24/2018 12:19 PM, Rohit Kumar wrote:

Thanks Sibi for reviewing.


On 9/22/2018 1:11 AM, Sibi Sankar wrote:

Hi Rohit,

On 2018-09-03 17:22, Rohit kumar wrote:

This adds Non PAS ADSP PIL driver for Qualcomm
Technologies Inc SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 
---



...


Also I see the following warns on stopping the adsp remoteproc, 
couldn't root cause it though:


It should be issue in Q6 drivers. I will check and update q6 drivers. 
Thanks for reporting.




Checked this warning. This is a core driver issue fixed with 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/base/core.c?h=next-20180924=2ec16150179888b81717d1d3ce84e634f4736af2 


 device_del+0x84/0x29c
 platform_device_del+0x2c/0x88
 platform_device_unregister+0x1c/0x30
 of_platform_device_destroy+0x98/0xa8
 device_for_each_child+0x54/0xa4
 of_platform_depopulate+0x38/0x54
 q6asm_remove+0x1c/0x2c
 apr_device_remove+0x38/0x70
 device_release_driver_internal+0x124/0x1c8
 device_release_driver+0x24/0x30
 bus_remove_device+0xcc/0xe4
 device_del+0x1f8/0x29c
 device_unregister+0x1c/0x30
 apr_remove_device+0x1c/0x2c
 device_for_each_child+0x54/0xa4
 apr_remove+0x28/0x34
 rpmsg_dev_remove+0x48/0x70
 device_release_driver_internal+0x124/0x1c8
 device_release_driver+0x24/0x30
 bus_remove_device+0xcc/0xe4
 device_del+0x1f8/0x29c
 device_unregister+0x1c/0x30
 qcom_glink_remove_device+0x1c/0x2c
 device_for_each_child+0x54/0xa4
 qcom_glink_native_remove+0x54/0x15c
 qcom_glink_smem_unregister+0x1c/0x30
 glink_subdev_stop+0x1c/0x2c [qcom_common]
 rproc_stop+0x40/0xc0
 rproc_shutdown+0x6c/0xc0
 rproc_del+0x28/0xa0
 adsp_remove+0x20/0x5c [qcom_adsp_pil]
 platform_drv_remove+0x28/0x50
 device_release_driver_internal+0x124/0x1c8
 driver_detach+0x44/0x80
 bus_remove_driver+0x78/0x9c
 driver_unregister+0x34/0x54
 platform_driver_unregister+0x1c/0x28
 cleanup_module+0x14/0x6bc [qcom_adsp_pil]
 SyS_delete_module+0x1c4/0x214



Thanks,
Rohit

Thanks


Re: [PATCH v3 2/2] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-09-24 Thread Rohit Kumar

Thanks Sibi for reviewing.


On 9/22/2018 1:11 AM, Sibi Sankar wrote:

Hi Rohit,

On 2018-09-03 17:22, Rohit kumar wrote:

This adds Non PAS ADSP PIL driver for Qualcomm
Technologies Inc SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 
---



+    select QCOM_MDT_LOADER
+    select QCOM_Q6V5_COMMON
+    select QCOM_RPROC_COMMON
+    help
+  Say y here to support the Peripherial Image Loader


replace Peripherial/Peripheral.


sure



+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+


The headers should be in alphabetical order.



ok, will do



+    struct reset_control *pdc_sync_reset;
+    struct reset_control *cc_lpass_restart;
+
+    struct regmap *halt_map;
+    unsigned int  halt_lpass;


remove the double spaces above.


ok



+    if (ret || val)
+    goto reset;
+
+    regmap_write(adsp->halt_map,
+    adsp->halt_lpass + LPASS_HALTREQ_REG, 1);
+
+    /*  Wait for halt ACK from QDSP6 */


Minor nit, please remove the double spaces in the comment above.


ok



+    timeout = jiffies + msecs_to_jiffies(ACK_TIMEOUT);
+    for (;;) {
+    ret = regmap_read(adsp->halt_map,
+    adsp->halt_lpass + LPASS_HALTACK_REG, );
+    if (ret || val || time_after(jiffies, timeout))
+    break;
+
+    udelay(1000);


According to Documentation/timers/timers-howto.txt please use 
usleep_range()

when the delay range is between(10us - 20ms).


okay, will update in next spin.



+    }
+
+    ret = regmap_read(adsp->halt_map,
+    adsp->halt_lpass + LPASS_MASTER_IDLE_REG, );



+    /* wait after asserting subsystem restart from AOSS */
+    udelay(200);


ditto


ok



+
+    /* Clear the halt request for the AXIM and AHBM for Q6 */
+    regmap_write(adsp->halt_map, adsp->halt_lpass + 
LPASS_HALTREQ_REG, 0);

+
+    /* De-assert the LPASS PDC Reset */
+    reset_control_deassert(adsp->pdc_sync_reset);
+    /* Remove the LPASS reset */
+    reset_control_deassert(adsp->cc_lpass_restart);
+    /* wait after de-asserting subsystem restart from AOSS */
+    udelay(200);


ditto


+
+    return 0;
+}



+static int adsp_start(struct rproc *rproc)
+{
+    struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
+    int ret;
+    unsigned int val;
+
+    qcom_q6v5_prepare(>q6v5);
+
+    ret = clk_prepare_enable(adsp->xo);
+    if (ret)
+    return ret;


please call qcom_q6v5_unprepare on clk_prepare_enable failure to 
disable_irqs




sure, will do that

+
+    dev_pm_genpd_set_performance_state(adsp->dev, INT_MAX);
+    ret = pm_runtime_get_sync(adsp->dev);
+    if (ret)
+    goto disable_xo_clk;
+



+static int adsp_init_reset(struct qcom_adsp *adsp)
+{
+    adsp->pdc_sync_reset = devm_reset_control_get_exclusive(adsp->dev,
+    "pdc_sync");
+    if (IS_ERR(adsp->pdc_sync_reset)) {
+    dev_err(adsp->dev, "failed to acquire pdc_sync reset\n");
+    return PTR_ERR(adsp->pdc_sync_reset);
+    }


Bjorn, should we return EPROBE_DEFER here since PDC global reset 
controller can be a module?




devm_reset_control_get_exclusive itself returns EPROBE_DEFER until PDC 
reset driver is probed.

return PTR_ERR(adsp->pdc_sync_reset) handles this case.


+
+    adsp->cc_lpass_restart = 
devm_reset_control_get_exclusive(adsp->dev,

+    "cc_lpass");
+    if (IS_ERR(adsp->cc_lpass_restart)) {
+    dev_err(adsp->dev, "failed to acquire cc_lpass restart\n");
+    return PTR_ERR(adsp->cc_lpass_restart);
+    }
+
+    return 0;



+static int adsp_remove(struct platform_device *pdev)
+{
+    struct qcom_adsp *adsp = platform_get_drvdata(pdev);
+
+    rproc_del(adsp->rproc);
+
+    qcom_remove_glink_subdev(adsp->rproc, >glink_subdev);
+    qcom_remove_sysmon_subdev(adsp->sysmon);
+    qcom_remove_ssr_subdev(adsp->rproc, >ssr_subdev);
+    rproc_free(adsp->rproc);
+    pm_runtime_disable(adsp->dev);
+


rmmod of the driver resulted in the following kernel panic:
having a pm_runtime_disable after rproc_free seems to be the cause of 
the kernel panic.

Please call pm_runtime_disable before rproc_free.



Thanks for pointing out, will update.

do_raw_spin_lock+0x28/0x118
__raw_spin_lock_irq+0x30/0x3c
__pm_runtime_disable+0x28/0xf4
adsp_remove+0x4c/0x5c [qcom_adsp_pil]
platform_drv_remove+0x28/0x50
device_release_driver_internal+0x124/0x1c8
driver_detach+0x44/0x80
bus_remove_driver+0x78/0x9c
driver_unregister+0x34/0x54
platform_driver_unregister+0x1c/0x28
cleanup_module+0x14/0x6bc [qcom_adsp_pil]
SyS_delete_module+0x1c4/0x214


+    return 0;
+}
+
+static const struct adsp_pil_data adsp_resource_

[PATCH v4] remoteproc: qcom: Introduce Non-PAS ADSP PIL driver

2018-09-24 Thread Rohit kumar
This adds Non PAS ADSP PIL driver for Qualcomm
Technologies Inc SoCs.
Added initial support for SDM845 with ADSP bootup and
shutdown operation handled from Application Processor
SubSystem(APSS).

Signed-off-by: Rohit kumar 
---
Changes since v3:
Addressed comments posted by Sibi

This patch is dependent on the rpmh powerdomain driver 
https://lkml.org/lkml/2018/6/27/7
and renaming of Hexagon v5 PAS driver 
https://patchwork.kernel.org/patch/10601119/ .

 drivers/remoteproc/Kconfig |  14 ++
 drivers/remoteproc/Makefile|   1 +
 drivers/remoteproc/qcom_adsp_pil.c | 502 +
 3 files changed, 517 insertions(+)
 create mode 100644 drivers/remoteproc/qcom_adsp_pil.c

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 8894935..f554669 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -140,6 +140,20 @@ config QCOM_Q6V5_WCSS
  Say y here to support the Qualcomm Peripheral Image Loader for the
  Hexagon V5 based WCSS remote processors.
 
+config QCOM_ADSP_PIL
+   tristate "Qualcomm Technology Inc ADSP Peripheral Image Loader"
+   depends on OF && ARCH_QCOM
+   depends on QCOM_SMEM
+   depends on RPMSG_QCOM_GLINK_SMEM || RPMSG_QCOM_GLINK_SMEM=n
+   depends on QCOM_SYSMON || QCOM_SYSMON=n
+   select MFD_SYSCON
+   select QCOM_MDT_LOADER
+   select QCOM_Q6V5_COMMON
+   select QCOM_RPROC_COMMON
+   help
+ Say y here to support the Peripheral Image Loader
+ for the Qualcomm Technology Inc. ADSP remote processors.
+
 config QCOM_SYSMON
tristate "Qualcomm sysmon driver"
depends on RPMSG
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 050f41a..0e1b89c 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_QCOM_Q6V5_COMMON)+= qcom_q6v5.o
 obj-$(CONFIG_QCOM_Q6V5_MSS)+= qcom_q6v5_mss.o
 obj-$(CONFIG_QCOM_Q6V5_PAS)+= qcom_q6v5_pas.o
 obj-$(CONFIG_QCOM_Q6V5_WCSS)   += qcom_q6v5_wcss.o
+obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp_pil.o
 obj-$(CONFIG_QCOM_SYSMON)  += qcom_sysmon.o
 obj-$(CONFIG_QCOM_WCNSS_PIL)   += qcom_wcnss_pil.o
 qcom_wcnss_pil-y   += qcom_wcnss.o
diff --git a/drivers/remoteproc/qcom_adsp_pil.c 
b/drivers/remoteproc/qcom_adsp_pil.c
new file mode 100644
index 000..f2f5e56
--- /dev/null
+++ b/drivers/remoteproc/qcom_adsp_pil.c
@@ -0,0 +1,502 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Qualcomm Technology Inc. ADSP Peripheral Image Loader for SDM845.
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "qcom_common.h"
+#include "qcom_q6v5.h"
+#include "remoteproc_internal.h"
+
+/* time out value */
+#define ACK_TIMEOUT1000
+#define BOOT_FSM_TIMEOUT   1
+/* mask values */
+#define EVB_MASK   GENMASK(27, 4)
+/*QDSP6SS register offsets*/
+#define RST_EVB_REG0x10
+#define CORE_START_REG 0x400
+#define BOOT_CMD_REG   0x404
+#define BOOT_STATUS_REG0x408
+#define RET_CFG_REG0x1C
+/*TCSR register offsets*/
+#define LPASS_MASTER_IDLE_REG  0x8
+#define LPASS_HALTACK_REG  0x4
+#define LPASS_PWR_ON_REG   0x10
+#define LPASS_HALTREQ_REG  0x0
+
+/* list of clocks required by ADSP PIL */
+static const char * const adsp_clk_id[] = {
+   "sway_cbcr", "lpass_aon", "lpass_ahbs_aon_cbcr", "lpass_ahbm_aon_cbcr",
+   "qdsp6ss_xo", "qdsp6ss_sleep", "qdsp6ss_core",
+};
+
+struct adsp_pil_data {
+   int crash_reason_smem;
+   const char *firmware_name;
+
+   const char *ssr_name;
+   const char *sysmon_name;
+   int ssctl_id;
+};
+
+struct qcom_adsp {
+   struct device *dev;
+   struct rproc *rproc;
+
+   struct qcom_q6v5 q6v5;
+
+   struct clk *xo;
+
+   int num_clks;
+   struct clk_bulk_data *clks;
+
+   void __iomem *qdsp6ss_base;
+
+   struct reset_control *pdc_sync_reset;
+   struct reset_control *cc_lpass_restart;
+
+   struct regmap *halt_map;
+   unsigned int halt_lpass;
+
+   int crash_reason_smem;
+
+   struct completion start_done;
+   struct completion stop_done;
+
+   phys_addr_t mem_phys;
+   phys_addr_t mem_reloc;
+   void *mem_region;
+   size_t mem_size;
+
+   struct qcom_rproc_glink glink_subdev;
+   struct qcom_rproc_ssr ssr_subdev;
+   struct qcom_sysmon *sysmon;
+};

[PATCH 1/2] dt-binding: remoteproc: Remove lpass_aon clock from adsp pil clock list

2018-11-29 Thread Rohit kumar
LPASS_Audio_Wrapper_AON clock is on by default. Remove
it from lpass clock list to avoid voting for it.

Signed-off-by: Rohit kumar 
---
 Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
index a842a78..66af2c3 100644
--- a/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
@@ -35,7 +35,7 @@ on the Qualcomm Technology Inc. ADSP Hexagon core.
Value type: 
Definition: List of clock input name strings sorted in the same
order as the clocks property. Definition must have
-   "xo", "sway_cbcr", "lpass_aon", "lpass_ahbs_aon_cbcr",
+   "xo", "sway_cbcr", "lpass_ahbs_aon_cbcr",
"lpass_ahbm_aon_cbcr", "qdsp6ss_xo", "qdsp6ss_sleep"
and "qdsp6ss_core".
 
@@ -100,13 +100,12 @@ ADSP, as it is found on SDM845 boards.
 
clocks = < RPMH_CXO_CLK>,
< GCC_LPASS_SWAY_CLK>,
-   < LPASS_AUDIO_WRAPPER_AON_CLK>,
< LPASS_Q6SS_AHBS_AON_CLK>,
< LPASS_Q6SS_AHBM_AON_CLK>,
< LPASS_QDSP6SS_XO_CLK>,
< LPASS_QDSP6SS_SLEEP_CLK>,
< LPASS_QDSP6SS_CORE_CLK>;
-   clock-names = "xo", "sway_cbcr", "lpass_aon",
+   clock-names = "xo", "sway_cbcr",
"lpass_ahbs_aon_cbcr",
"lpass_ahbm_aon_cbcr", "qdsp6ss_xo",
"qdsp6ss_sleep", "qdsp6ss_core";
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH 2/2] remoteproc: q6v5_adsp: Remove voting for lpass_aon clock

2018-11-29 Thread Rohit kumar
Lpass_aon clock is on by default. Remove it from lpass
clock list to avoid voting for it.

Signed-off-by: Rohit kumar 
---
 drivers/remoteproc/qcom_q6v5_adsp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/remoteproc/qcom_q6v5_adsp.c 
b/drivers/remoteproc/qcom_q6v5_adsp.c
index 79374d1..4829173 100644
--- a/drivers/remoteproc/qcom_q6v5_adsp.c
+++ b/drivers/remoteproc/qcom_q6v5_adsp.c
@@ -48,7 +48,7 @@
 
 /* list of clocks required by ADSP PIL */
 static const char * const adsp_clk_id[] = {
-   "sway_cbcr", "lpass_aon", "lpass_ahbs_aon_cbcr", "lpass_ahbm_aon_cbcr",
+   "sway_cbcr", "lpass_ahbs_aon_cbcr", "lpass_ahbm_aon_cbcr",
"qdsp6ss_xo", "qdsp6ss_sleep", "qdsp6ss_core",
 };
 
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH 0/2] qcom_adsp_pil: Remove voting for lpass_aon clock

2018-11-29 Thread Rohit kumar
LPASS Audio Wrapper AON clock is on by default. Remove
voting for it.

Rohit kumar (2):
  dt-binding: remoteproc: Remove lpass_aon clock from adsp pil clock
list
  remoteproc: q6v5_adsp: Remove voting for lpass_aon clock

 Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt | 5 ++---
 drivers/remoteproc/qcom_q6v5_adsp.c| 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [alsa-devel] [PATCH 2/2] ASoC: max98927: Add reset-gpio support

2018-09-12 Thread Rohit Kumar




On 9/12/2018 5:49 PM, Cheng-Yi Chiang wrote:

Toggle reset line in max98927_i2c_probe.
Use a list to store max98927 instances so we do not toggle reset line
again if more than one instances share the same reset line.

Signed-off-by: Cheng-Yi Chiang 

Reviewed-and-tested-by: Rohit kumar 


---
  sound/soc/codecs/max98927.c | 78 +
  sound/soc/codecs/max98927.h |  2 ++
  2 files changed, 80 insertions(+)

diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index 941712058a8f5..789b27cdfd9e0 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -11,6 +11,7 @@
   */
  
  #include 

+#include 
  #include 
  #include 
  #include 
@@ -24,6 +25,11 @@
  #include 
  #include "max98927.h"
  
+#define MAX98927_MIN_RESET_US 1

+#define MAX98927_RELEASE_RESET_DELAY_US 500
+
+static LIST_HEAD(reset_list);
+
  static struct reg_default max98927_reg[] = {
{MAX98927_R0001_INT_RAW1,  0x00},
{MAX98927_R0002_INT_RAW2,  0x00},
@@ -877,6 +883,54 @@ static void max98927_slot_config(struct i2c_client *i2c,
max98927->i_l_slot = 1;
  }
  
+static int max98927_i2c_toggle_reset(struct device *dev,

+struct max98927_priv *max98927)
+{
+   /*
+* If we do not have reset gpio, assume platform firmware
+* controls the regulator and toggles it for us.
+*/
+   if (!max98927->reset_gpio)
+   return 0;
+
+   gpiod_set_value_cansleep(max98927->reset_gpio, 1);
+
+   /*
+* We need to wait a bit before we are allowed to release reset GPIO.
+*/
+   usleep_range(MAX98927_MIN_RESET_US, MAX98927_MIN_RESET_US + 5);
+
+   gpiod_set_value_cansleep(max98927->reset_gpio, 0);
+
+   /*
+* We need to wait a bit before I2C communication is available.
+*/
+   usleep_range(MAX98927_RELEASE_RESET_DELAY_US,
+MAX98927_RELEASE_RESET_DELAY_US + 5);
+
+   /*
+* Release reset GPIO because we are not going to use it.
+*/
+   devm_gpiod_put(dev, max98927->reset_gpio);
+
+   return 0;
+}
+
+static bool max98927_is_first_to_reset(struct max98927_priv *max98927)
+{
+   struct max98927_priv *p;
+
+   if (!max98927->reset_gpio)
+   return false;
+
+   list_for_each_entry(p, _list, list) {
+   if (max98927->reset_gpio == p->reset_gpio)
+   return false;
+   }
+
+   return true;
+}
+
  static int max98927_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id)
  {
@@ -904,6 +958,28 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
} else
max98927->interleave_mode = 0;
  
+	/* Gets optional GPIO for reset line. */

+   max98927->reset_gpio = devm_gpiod_get_optional(
+   >dev, "reset", GPIOD_OUT_LOW);
+   if (IS_ERR(max98927->reset_gpio)) {
+   ret = PTR_ERR(max98927->reset_gpio);
+   dev_err(>dev, "error getting reset gpio: %d\n", ret);
+   return ret;
+   }
+
+   /*
+* Only toggle reset line for the first instance when the
+* reset line is shared among instances. For example,
+* left and right amplifier share the same reset line, and
+* we should only toggle the reset line once.
+*/
+   if (max98927_is_first_to_reset(max98927)) {
+   dev_info(>dev, "%s: toggle reset line\n", __func__);
+   ret = max98927_i2c_toggle_reset(>dev, max98927);
+   if (ret)
+   return ret;
+   }
+
/* regmap initialization */
max98927->regmap
= devm_regmap_init_i2c(i2c, _regmap);
@@ -934,6 +1010,8 @@ static int max98927_i2c_probe(struct i2c_client *i2c,
if (ret < 0)
dev_err(>dev, "Failed to register component: %d\n", ret);
  
+	list_add(>list, _list);

+
return ret;
  }
  
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h

index 538992a238b28..d48f61f6c3ba5 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -275,5 +275,7 @@ struct max98927_priv {
unsigned int master;
unsigned int digital_gain;
bool tdm_mode;
+   struct gpio_desc *reset_gpio;
+   struct list_head list;
  };
  #endif




Re: [alsa-devel] [PATCH v4 14/14] ASoC: qcom: common: move be_hw_fixup to common

2018-09-18 Thread Rohit Kumar

Hello Srinivas,


We will add support for vi feedback usecase in sdm845 machine driver 
where we have to support 4 channel tx data for a particular backend. We 
should probably keep be_hw_params_fixup in respective machine driver for 
now to support such requirement.



Thanks,

Rohit


On 9/17/2018 6:27 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

be_hw_fixup for qdsp is common across mutiple qcom machine drivers,
so move it to common file and remove the redundant code.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/apq8096.c | 15 ---
  sound/soc/qcom/common.c  | 17 +
  sound/soc/qcom/sdm845.c  | 22 ++
  3 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/sound/soc/qcom/apq8096.c b/sound/soc/qcom/apq8096.c
index daad43f..9cb26aee 100644
--- a/sound/soc/qcom/apq8096.c
+++ b/sound/soc/qcom/apq8096.c
@@ -20,20 +20,6 @@ struct apq8096_card_data {
bool jack_setup;
  };
  
-static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,

- struct snd_pcm_hw_params *params)
-{
-   struct snd_interval *rate = hw_param_interval(params,
-   SNDRV_PCM_HW_PARAM_RATE);
-   struct snd_interval *channels = hw_param_interval(params,
-   SNDRV_PCM_HW_PARAM_CHANNELS);
-
-   rate->min = rate->max = 48000;
-   channels->min = channels->max = 2;
-
-   return 0;
-}
-
  static int msm_snd_hw_params(struct snd_pcm_substream *substream,
 struct snd_pcm_hw_params *params)
  {
@@ -139,7 +125,6 @@ static void apq8096_add_be_ops(struct snd_soc_card *card)
  
  	for (i = 0; i < num_links; i++) {

if (link->no_pcm == 1) {
-   link->be_hw_params_fixup = apq8096_be_hw_params_fixup;
link->init = apq8096_init;
link->ops = _ops;
}
diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
index eb1b9da..ce8e759 100644
--- a/sound/soc/qcom/common.c
+++ b/sound/soc/qcom/common.c
@@ -3,8 +3,24 @@
  // Copyright (c) 2018, The Linux Foundation. All rights reserved.
  
  #include 

+#include 
  #include "common.h"
  
+static int qcom_snd_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,

+  struct snd_pcm_hw_params *params)
+{
+   struct snd_interval *rate = hw_param_interval(params,
+   SNDRV_PCM_HW_PARAM_RATE);
+   struct snd_interval *channels = hw_param_interval(params,
+   SNDRV_PCM_HW_PARAM_CHANNELS);
+
+   rate->min = rate->max = 48000;
+   channels->min = channels->max = 2;
+   params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
+
+   return 0;
+}
+
  int qcom_snd_parse_of(struct snd_soc_card *card)
  {
struct device_node *np;
@@ -79,6 +95,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
}
link->no_pcm = 1;
link->ignore_pmdown_time = 1;
+   link->be_hw_params_fixup = qcom_snd_be_hw_params_fixup;
} else {
link->platform_of_node = link->cpu_of_node;
link->codec_dai_name = "snd-soc-dummy-dai";
diff --git a/sound/soc/qcom/sdm845.c b/sound/soc/qcom/sdm845.c
index 2a781d8..87e150c 100644
--- a/sound/soc/qcom/sdm845.c
+++ b/sound/soc/qcom/sdm845.c
@@ -11,7 +11,6 @@
  #include "common.h"
  #include "qdsp6/q6afe.h"
  
-#define DEFAULT_SAMPLE_RATE_48K		48000

  #define DEFAULT_MCLK_RATE 24576000
  #define DEFAULT_BCLK_RATE 12288000
  
@@ -177,32 +176,15 @@ static struct snd_soc_ops sdm845_be_ops = {

.shutdown = sdm845_snd_shutdown,
  };
  
-static int sdm845_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,

-   struct snd_pcm_hw_params *params)
-{
-   struct snd_interval *rate = hw_param_interval(params,
-   SNDRV_PCM_HW_PARAM_RATE);
-   struct snd_interval *channels = hw_param_interval(params,
-   SNDRV_PCM_HW_PARAM_CHANNELS);
-   struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
-
-   rate->min = rate->max = DEFAULT_SAMPLE_RATE_48K;
-   channels->min = channels->max = 2;
-   snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
-
-   return 0;
-}
-
  static void sdm845_add_be_ops(struct snd_soc_card *card)
  {
struct snd_soc_dai_link *link = card->dai_link;
int i, num_links = card->num_links;
  
  	for (i = 0; i < num_links; i++) {

-   if (link->no_pcm == 1) {
+   if (link->no_pcm == 1)
link->ops = _be_ops;
-   link->be_hw_params_fixup = sdm845_be_hw_params_fixup;
-   }
+
link++;
}
 

[PATCH] ASoC: q6afe: dt-bindings: Update input range for qcom,sd-lines

2018-09-19 Thread Rohit kumar
Input to qcom,sd-lines should be between 0 and 3 instead of
1 to 4 as 0 corresponds to BIT(0) which is MI2S_SD0 line.
Bit 1 to 3 corresponds to SD1 to SD3 lines respectively.
Updated documentation for the same.

Signed-off-by: Rohit kumar 
---
 Documentation/devicetree/bindings/sound/qcom,q6afe.txt | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Documentation/devicetree/bindings/sound/qcom,q6afe.txt 
b/Documentation/devicetree/bindings/sound/qcom,q6afe.txt
index a817940..d74888b 100644
--- a/Documentation/devicetree/bindings/sound/qcom,q6afe.txt
+++ b/Documentation/devicetree/bindings/sound/qcom,q6afe.txt
@@ -49,7 +49,7 @@ configuration of each dai. Must contain the following 
properties.
Usage: required for mi2s interface
Value type: 
Definition: Must be list of serial data lines used by this dai.
-   should be one or more of the 1-4 sd lines.
+   should be one or more of the 0-3 sd lines.
 
  - qcom,tdm-sync-mode:
Usage: required for tdm interface
@@ -137,42 +137,42 @@ q6afe@4 {
 
prim-mi2s-rx@16 {
reg = <16>;
-   qcom,sd-lines = <1 3>;
+   qcom,sd-lines = <0 2>;
};
 
prim-mi2s-tx@17 {
reg = <17>;
-   qcom,sd-lines = <2>;
+   qcom,sd-lines = <1>;
};
 
sec-mi2s-rx@18 {
reg = <18>;
-   qcom,sd-lines = <1 4>;
+   qcom,sd-lines = <0 3>;
};
 
sec-mi2s-tx@19 {
reg = <19>;
-   qcom,sd-lines = <2>;
+   qcom,sd-lines = <1>;
};
 
tert-mi2s-rx@20 {
reg = <20>;
-   qcom,sd-lines = <2 4>;
+   qcom,sd-lines = <1 3>;
};
 
tert-mi2s-tx@21 {
reg = <21>;
-   qcom,sd-lines = <1>;
+   qcom,sd-lines = <0>;
};
 
quat-mi2s-rx@22 {
reg = <22>;
-   qcom,sd-lines = <1>;
+   qcom,sd-lines = <0>;
};
 
quat-mi2s-tx@23 {
reg = <23>;
-   qcom,sd-lines = <2>;
+   qcom,sd-lines = <1>;
};
};
 };
-- 
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



Re: [PATCH v4] dt-binding: remoteproc: Add QTI ADSP PIL bindings

2018-09-17 Thread Rohit Kumar

Hello Rob,

Can you please review this patch and let me know if there is any concern 
with this patch.



On 9/11/2018 9:24 AM, Rohit kumar wrote:

Add devicetree bindings documentation file for Qualcomm
Technolgies Inc ADSP Peripheral Image Loader.

Signed-off-by: Rohit kumar 
---
Changes since v3:
Addressed comments given by Rob

  .../bindings/remoteproc/qcom,adsp-pil.txt  | 126 +
  1 file changed, 126 insertions(+)
  create mode 100644 
Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
new file mode 100644
index 000..06558de
--- /dev/null
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp-pil.txt
@@ -0,0 +1,126 @@
+Qualcomm Technology Inc. ADSP Peripheral Image Loader
+
+This document defines the binding for a component that loads and boots firmware
+on the Qualcomm Technology Inc. ADSP Hexagon core.
+
+- compatible:
+   Usage: required
+   Value type: 
+   Definition: must be one of:
+   "qcom,sdm845-adsp-pil"
+
+- reg:
+   Usage: required
+   Value type: 
+   Definition: must specify the base address and size of the qdsp6ss 
register
+
+- interrupts-extended:
+   Usage: required
+   Value type: 
+   Definition: must list the watchdog, fatal IRQs ready, handover and
+   stop-ack IRQs
+
+- interrupt-names:
+   Usage: required
+   Value type: 
+   Definition: must be "wdog", "fatal", "ready", "handover", "stop-ack"
+
+- clocks:
+   Usage: required
+   Value type: 
+   Definition:  List of 8 phandle and clock specifier pairs for the adsp.
+
+- clock-names:
+   Usage: required
+   Value type: 
+   Definition: List of clock input name strings sorted in the same
+   order as the clocks property. Definition must have
+   "xo", "sway_cbcr", "lpass_aon", "lpass_ahbs_aon_cbcr",
+   "lpass_ahbm_aon_cbcr", "qdsp6ss_xo", "qdsp6ss_sleep"
+   and "qdsp6ss_core".
+
+- power-domains:
+   Usage: required
+   Value type: 
+   Definition: reference to cx power domain node.
+
+- resets:
+   Usage: required
+   Value type: 
+   Definition: reference to the list of 2 reset-controller for the adsp.
+
+- reset-names:
+Usage: required
+Value type: 
+Definition: must be "pdc_sync" and "cc_lpass"
+
+- qcom,halt-regs:
+   Usage: required
+   Value type: 
+   Definition: a phandle reference to a syscon representing TCSR followed
+   by the offset within syscon for lpass halt register.
+
+- memory-region:
+   Usage: required
+   Value type: 
+   Definition: reference to the reserved-memory for the ADSP
+
+- qcom,smem-states:
+   Usage: required
+   Value type: 
+   Definition: reference to the smem state for requesting the ADSP to
+   shut down
+
+- qcom,smem-state-names:
+   Usage: required
+   Value type: 
+   Definition: must be "stop"
+
+
+= SUBNODES
+The adsp node may have an subnode named "glink-edge" that describes the
+communication edge, channels and devices related to the ADSP.
+See ../soc/qcom/qcom,glink.txt for details on how to describe these.
+
+= EXAMPLE
+The following example describes the resources needed to boot control the
+ADSP, as it is found on SDM845 boards.
+   adsp-pil {
+   compatible = "qcom,sdm845-adsp-pil";
+
+   reg = <0x1730 0x40c>;
+
+   interrupts-extended = < 0 162 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 0 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 1 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 2 IRQ_TYPE_EDGE_RISING>,
+   <_smp2p_in 3 IRQ_TYPE_EDGE_RISING>;
+   interrupt-names = "wdog", "fatal", "ready",
+   "handover", "stop-ack";
+
+   clocks = < RPMH_CXO_CLK>,
+   < GCC_LPASS_SWAY_CLK>,
+   < LPASS_AUDIO_WRAPPER_AON_CLK>,
+   < LPASS_Q6SS_AHBS_AON_CLK>,
+   < LPASS_Q6SS_AHBM_AON_CLK>,
+   < LPASS_QDSP6SS_XO_CLK>,
+   < LPASS_QDSP6SS_SLEEP_CLK>,
+   < LPASS_QDSP6SS_CORE_CLK>;
+   clock-names = "xo", "sway_cbcr", "lpass_aon",
+   "lpass_ahbs_aon_cbcr",
+   "lpass_ahbm_aon_cbcr", "qdsp6ss_xo

Re: [alsa-devel] [PATCH v4 02/24] soc: qcom: Add APR bus driver

2018-03-14 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 


[..]

+struct bus_type aprbus_type = {
+   .name   = "aprbus",
+   .match  = apr_device_match,
+   .probe  = apr_device_probe,
+   .remove = apr_device_remove,
+   .force_dma  = true,


There is no need of force_dma now as machine driver is not child of apr. 
Please remove it.

+};
+EXPORT_SYMBOL_GPL(aprbus_type);
+





Re: [alsa-devel] [PATCH v4 07/24] ASoC: qdsp6: q6afe: Add q6afe driver

2018-03-13 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to Q6AFE (Audio Front End) module on Q6DSP.


[..]

+   if (res->status) {
+   dev_err(afe->dev, "cmd = 0x%x returned error = 0x%x\n",
+   res->opcode, res->status);
+   }
+   switch (res->opcode) {
+   case AFE_PORT_CMD_SET_PARAM_V2:
+   case AFE_PORT_CMD_DEVICE_STOP:
+   case AFE_PORT_CMD_DEVICE_START:


case AFE_SVC_CMD_SET_PARAM: needs to be added

+   port = afe_find_port(afe, data->token);
+   if (port) {
+   port->result = *res;
+   wake_up(>wait);
+   }

[..]

+
+static int q6afe_port_set_param_v2(struct q6afe_port *port, void *data,
+  int param_id, int psize)
+{
+   struct apr_hdr *hdr;
+   struct afe_port_cmd_set_param_v2 *param;
+   struct afe_port_param_data_v2 *pdata;
+   struct q6afe *afe = port->afe;
+   u16 port_id = port->id;
+   int ret;
+
+   hdr = data;
+   param = data + sizeof(*hdr);
+   pdata = data + sizeof(*hdr) + sizeof(*param);
+
+   hdr->hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
+ APR_HDR_LEN(APR_HDR_SIZE),
+ APR_PKT_VER);
+   hdr->pkt_size = sizeof(*hdr) + sizeof(*param) +
+   sizeof(*pdata) + psize;
+   hdr->src_port = 0;
+   hdr->dest_port = 0;
+   hdr->token = port->token;
+   hdr->opcode = AFE_PORT_CMD_SET_PARAM_V2;
+   param->port_id = port_id;
+   param->payload_size = sizeof(*pdata) + psize;
+   param->payload_address_lsw = 0x00;
+   param->payload_address_msw = 0x00;
+   param->mem_map_handle = 0x00;
+   pdata->module_id = AFE_MODULE_AUDIO_DEV_INTERFACE;
+   pdata->param_id = param_id;
+   pdata->param_size = psize;
+
+   ret = afe_apr_send_pkt(afe, data, port);
+   if (ret)
+   dev_err(afe->dev, "AFE enable for port 0x%x failed %d\n",


we should add %s to distinguish different functions with similar error 
logs. Also, q6afe_port_set_param_v2() can be called for different 
purpose.  AFE enable for port 0x%x failed is suitable only for port 
start failure. Error message needs to be updated here.



+  port_id, ret);
+
+
+   return ret;
+}
+


Re: [alsa-devel] [PATCH v4 15/24] ASoC: qdsp6: q6core: Add q6core driver

2018-03-13 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

[..]

+static int q6core_get_svc_versions(struct q6core *core)
+{
+   struct apr_device *adev = core->adev;
+   struct apr_hdr hdr = {0};
+   int rc;
+
+   core->get_version_supported = true;


core->get_version_supported should be set to true only after we get proper 
response from adsp in callback(). In case,we get wrong response from adsp, memory for 
g_core->svc_version
 will not get allocated and there will be NULL pointer dereference in  
q6core_get_svc_api_info() in below statement
+   } else if (g_core->get_version_supported) {
+   for (i = 0; i < g_core->svc_version->num_services; i++) {
 


+   hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
+ APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
+   hdr.pkt_size = APR_HDR_SIZE;
+   hdr.opcode = AVCS_GET_VERSIONS;
+
+   rc = apr_send_pkt(adev, );
+   if (rc < 0)
+   return rc;
+


Re: [alsa-devel] [PATCH v3 15/25] ASoC: qcom: qdsp6: Add support to q6asm dai driver

2018-02-21 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6asm dai driver which configures Q6ASM streams
to pass pcm data.

Signed-off-by: Srinivas Kandagatla 

[..]

diff --git a/sound/soc/qcom/qdsp6/q6asm-dai.c b/sound/soc/qcom/qdsp6/q6asm-dai.c
new file mode 100644
index ..7c5e94b2ced4
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6asm-dai.c
@@ -0,0 +1,621 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2016, The Linux Foundation
+ * Copyright (c) 2017, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

[..]

+static struct snd_pcm_hw_constraint_list constraints_sample_rates = {
+   .count = ARRAY_SIZE(supported_sample_rates),
+   .list = supported_sample_rates,
+   .mask = 0,
+};
+
+static void event_handler(uint32_t opcode, uint32_t token,
+ uint32_t *payload, void *priv)
+{
+   struct q6asm_dai_rtd *prtd = priv;
+   struct snd_pcm_substream *substream = prtd->substream;
+
+   switch (opcode) {
+   case ASM_CLIENT_EVENT_CMD_RUN_DONE:

Need to add support for V2 version of opcodes

+   q6asm_write_async(prtd->audio_client,
+  prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+   break;
+   case ASM_CLIENT_EVENT_CMD_EOS_DONE:
+   prtd->state = Q6ASM_STREAM_STOPPED;
+   break;
+   case ASM_CLIENT_EVENT_DATA_WRITE_DONE: {
+   prtd->pcm

[..]

+
+static int q6asm_dai_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+   int ret = 0;
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct q6asm_dai_rtd *prtd = runtime->private_data;
+
+   switch (cmd) {
+   case SNDRV_PCM_TRIGGER_START:
+   ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
+   break;

below two cases can be combined with START if no change

+   case SNDRV_PCM_TRIGGER_RESUME:
+   case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+   ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
+   break;
+   case SNDRV_PCM_TRIGGER_STOP:
+   prtd->state = Q6ASM_STREAM_STOPPED;
+   ret = q6asm_cmd_nowait(prtd->audio_client, CMD_EOS);
+   break;
+   case SNDRV_PCM_TRIGGER_SUSPEND:
+   case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+   ret = q6asm_cmd_nowait(prtd->audio_client, CMD_PAUSE);
+   break;
+   default:
+   ret = -EINVAL;
+   break;
+   }
+
+   return ret;
+}
+
+static int q6asm_dai_open(struct snd_pcm_substream *substream)
+{
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
+   struct snd_soc_dai *cpu_dai = soc_prtd->cpu_dai;
+
+   struct q6asm_dai_rtd *prtd;
+   struct q6asm_dai_data *pdata;
+   struct device *dev = soc_prtd->platform->dev;
+   int ret = 0;
+   int stream_id;
+
+   stream_id = cpu_dai->driver->id;
+
+   pdata = q6asm_get_dai_data(dev);
+   if (!pdata) {
+   pr_err("Platform data not found ..\n");
+   return -EINVAL;
+   }
+
+   prtd = kzalloc(sizeof(struct q6asm_dai_rtd), GFP_KERNEL);
+   if (prtd == NULL)
+   return -ENOMEM;
+
+   prtd->substream = substream;
+   prtd->audio_client = q6asm_audio_client_alloc(dev,
+   (q6asm_cb)event_handler, prtd, stream_id);
+   if (!prtd->audio_client) {
+   pr_info("%s: Could not allocate memory\n", __func__);
+   kfree(prtd);
+   return -ENOMEM;
+   }
+
+// prtd->audio_client->dev = dev;

cleanup this

+
+   if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+   runtime->hw = q6asm_dai_hardware_playback;
+
+   ret = snd_pcm_hw_constraint_list(runtime, 0,
+   SNDRV_PCM_HW_PARAM_RATE,
+   _sample_rates);

[..]

+
+static int q6asm_dai_pcm_new(struct snd_soc_pcm_runtime *rtd)
+{
+   struct snd_pcm_substream *substream;
+   struct of_phandle_args args;
+   struct device_node *node;
+   struct q6asm_dai_data *pdata;
+   struct snd_pcm *pcm = rtd->pcm;
+   struct device *dev;
+   int size, ret;
+
+   dev = rtd->platform->dev->parent;
+   node = dev->of_node;
+   pdata = q6asm_get_dai_data(rtd->platform->dev);
+
+   ret = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, );
+   if (ret < 0)
+   pdata->sid = -1;
+   else
+   pdata->sid = args.args[0];
+
+
+
iommus for sdm845 is 16bit value. we need to have sid_mask which is 0x1 
in sdm845. We need to mask sid with 0x1 to get proper sid.

pdata->sid &= 0x1;

+   substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
+   size = 

Re: [alsa-devel] [PATCH v3 24/25] ASoC: qcom: apq8096: Add db820c machine driver

2018-02-22 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to DB820c machine driver.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig   |   8 +++
  sound/soc/qcom/apq8096.c | 173 +++
  2 files changed, 181 insertions(+)
  create mode 100644 sound/soc/qcom/apq8096.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 8c2d65e0a28e..fa4b575c086c 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -77,3 +77,11 @@ config SND_SOC_QDSP6
 This will enable sound soc platform specific
 audio drivers. This includes q6asm, q6adm,
 q6afe interfaces to DSP using apr.
+
+config SND_SOC_MSM8996
+   tristate "SoC Machine driver for MSM8996 and APQ8096 boards"
+   depends on QCOM_APR
+   select SND_SOC_QDSP6V2

should be select SND_SOC_QDSP6, V2 is not defined

+   default n
+   help
+To add support for SoC audio on MSM8996 and APQ8096 boards



Re: [alsa-devel] [PATCH v7 16/24] ASoC: qdsp6: q6asm: Add support to audio stream apis

2018-05-04 Thread Rohit Kumar



On 5/1/2018 5:38 PM, Srinivas Kandagatla wrote:

+static int __q6asm_run(struct audio_client *ac, uint32_t flags,
+ uint32_t msw_ts, uint32_t lsw_ts, bool wait)
+{
+   struct asm_session_cmd_run_v2 *run;
+   struct apr_pkt *pkt;
+   int pkt_size, rc;
+   void *p;
+
+   pkt_size = APR_HDR_SIZE + sizeof(*run);
+   p = kzalloc(pkt_size, GFP_KERNEL);

Should be GFP_ATOMIC as this API is also called from interrupt context

+   if (!p)
+   return -ENOMEM;
+

[..]

+int q6asm_read(struct audio_client *ac)
+{
+   struct asm_data_cmd_read_v2 *read;
+   struct audio_port_data *port;
+   struct audio_buffer *ab;
+   struct apr_pkt *pkt;
+   int pkt_size;
+   int rc = 0;
+   void *p;
+
+   if (!(ac->io_mode & ASM_SYNC_IO_MODE))
+   return 0;
+
+   pkt_size = APR_HDR_SIZE + sizeof(*read);
+   p = kzalloc(pkt_size, GFP_KERNEL);

same here. GFP_ATOMIC

+   if (!p)
+   return -ENOMEM;

[..]

+int q6asm_write_async(struct audio_client *ac, uint32_t len, uint32_t msw_ts,
+  uint32_t lsw_ts, uint32_t flags)
+{
+   struct asm_data_cmd_write_v2 *write;
+   struct audio_port_data *port;
+   struct audio_buffer *ab;
+   struct apr_pkt *pkt;
+   int pkt_size;
+   int rc = 0;
+   void *p;
+
+   pkt_size = APR_HDR_SIZE + sizeof(*write);
+   p = kzalloc(pkt_size, GFP_KERNEL);

GFP_ATOMIC

+   if (!p)
+   return -ENOMEM;


Thanks,
Rohit

--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.,
is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.



[PATCH] remoteproc: Add APSS based Qualcomm ADSP PIL driver for SDM845

2018-05-13 Thread Rohit kumar
This adds Qualcomm ADSP PIL driver support for SDM845 with ADSP bootup
and shutdown operation handled from Application Processor SubSystem(APSS).

Signed-off-by: Rohit kumar 
Signed-off-by: RajendraBabu Medisetti 
Signed-off-by: Krishnamurthy Renu 
---
 .../devicetree/bindings/remoteproc/qcom,adsp.txt   |   1 +
 drivers/remoteproc/Makefile|   3 +-
 drivers/remoteproc/qcom_adsp_pil.c | 122 -
 drivers/remoteproc/qcom_adsp_pil.h |  86 ++
 drivers/remoteproc/qcom_adsp_pil_sdm845.c  | 304 +
 5 files changed, 454 insertions(+), 62 deletions(-)
 create mode 100644 drivers/remoteproc/qcom_adsp_pil.h
 create mode 100644 drivers/remoteproc/qcom_adsp_pil_sdm845.c

diff --git a/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt 
b/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
index 728e419..a9fe033 100644
--- a/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
+++ b/Documentation/devicetree/bindings/remoteproc/qcom,adsp.txt
@@ -10,6 +10,7 @@ on the Qualcomm ADSP Hexagon core.
"qcom,msm8974-adsp-pil"
"qcom,msm8996-adsp-pil"
"qcom,msm8996-slpi-pil"
+   "qcom,sdm845-apss-adsp-pil"
 
 - interrupts-extended:
Usage: required
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 02627ed..759831b 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -14,7 +14,8 @@ obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
 obj-$(CONFIG_WKUP_M3_RPROC)+= wkup_m3_rproc.o
 obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o
 obj-$(CONFIG_KEYSTONE_REMOTEPROC)  += keystone_remoteproc.o
-obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp_pil.o
+obj-$(CONFIG_QCOM_ADSP_PIL)+= qcom_adsp.o
+qcom_adsp-objs += qcom_adsp_pil.o 
qcom_adsp_pil_sdm845.o
 obj-$(CONFIG_QCOM_RPROC_COMMON)+= qcom_common.o
 obj-$(CONFIG_QCOM_Q6V5_PIL)+= qcom_q6v5_pil.o
 obj-$(CONFIG_QCOM_SYSMON)  += qcom_sysmon.o
diff --git a/drivers/remoteproc/qcom_adsp_pil.c 
b/drivers/remoteproc/qcom_adsp_pil.c
index 89a86ce..9ab3698 100644
--- a/drivers/remoteproc/qcom_adsp_pil.c
+++ b/drivers/remoteproc/qcom_adsp_pil.c
@@ -1,5 +1,5 @@
 /*
- * Qualcomm ADSP/SLPI Peripheral Image Loader for MSM8974 and MSM8996
+ * Qualcomm ADSP/SLPI Peripheral Image Loader for MSM8974, MSM8996 and SDM845.
  *
  * Copyright (C) 2016 Linaro Ltd
  * Copyright (C) 2014 Sony Mobile Communications AB
@@ -22,7 +22,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -30,56 +29,8 @@
 #include 
 #include 
 
-#include "qcom_common.h"
 #include "remoteproc_internal.h"
-
-struct adsp_data {
-   int crash_reason_smem;
-   const char *firmware_name;
-   int pas_id;
-   bool has_aggre2_clk;
-
-   const char *ssr_name;
-   const char *sysmon_name;
-   int ssctl_id;
-};
-
-struct qcom_adsp {
-   struct device *dev;
-   struct rproc *rproc;
-
-   int wdog_irq;
-   int fatal_irq;
-   int ready_irq;
-   int handover_irq;
-   int stop_ack_irq;
-
-   struct qcom_smem_state *state;
-   unsigned stop_bit;
-
-   struct clk *xo;
-   struct clk *aggre2_clk;
-
-   struct regulator *cx_supply;
-   struct regulator *px_supply;
-
-   int pas_id;
-   int crash_reason_smem;
-   bool has_aggre2_clk;
-
-   struct completion start_done;
-   struct completion stop_done;
-
-   phys_addr_t mem_phys;
-   phys_addr_t mem_reloc;
-   void *mem_region;
-   size_t mem_size;
-
-   struct qcom_rproc_glink glink_subdev;
-   struct qcom_rproc_subdev smd_subdev;
-   struct qcom_rproc_ssr ssr_subdev;
-   struct qcom_sysmon *sysmon;
-};
+#include "qcom_adsp_pil.h"
 
 static int adsp_load(struct rproc *rproc, const struct firmware *fw)
 {
@@ -112,18 +63,32 @@ static int adsp_start(struct rproc *rproc)
if (ret)
goto disable_cx_supply;
 
-   ret = qcom_scm_pas_auth_and_reset(adsp->pas_id);
-   if (ret) {
-   dev_err(adsp->dev,
-   "failed to authenticate image and release reset\n");
-   goto disable_px_supply;
+   if (adsp->is_apss_controlled) {
+   ret = adsp->ops->bringup(adsp);
+   if (ret) {
+   dev_err(adsp->dev, "adsp bringup failed\n");
+   adsp->ops->bringdown(adsp);
+   goto disable_px_supply;
+   }
+   } else {
+   ret = qcom_scm_pas_auth_and_reset(adsp->pas_id);
+   if (ret) {
+   dev_err(adsp->dev,
+   "failed to authenticate image and release 
reset

Re: [alsa-devel] [PATCH v4 14/24] ASoC: qdsp6: q6asm: Add support to audio stream apis

2018-04-09 Thread Rohit Kumar



On 3/10/2018 7:54 AM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to open, write and media format commands
in the q6asm module.

Signed-off-by: Srinivas Kandagatla 

Reviewed-and-Tested-by: Rohit kumar 

---
  sound/soc/qcom/qdsp6/q6asm.c | 744 ++-
  sound/soc/qcom/qdsp6/q6asm.h |  49 +++
  2 files changed, 792 insertions(+), 1 deletion(-)

diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index 8a2ca2ff9ce8..ddbf526358bd 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -9,6 +9,8 @@
  #include 
  #include 
  #include 
+#include 
+#include 
  #include 
  #include 
  #include 
@@ -17,10 +19,36 @@
  #include "q6dsp-errno.h"
  #include "q6dsp-common.h"
  
+#define ASM_STREAM_CMD_CLOSE			0x00010BCD

+#define ASM_STREAM_CMD_FLUSH   0x00010BCE
+#define ASM_SESSION_CMD_PAUSE  0x00010BD3
+#define ASM_DATA_CMD_EOS   0x00010BDB
+#define ASM_DEFAULT_POPP_TOPOLOGY  0x00010BE4

Use NULL topology instead of default topology.
#define ASM_NULL_POPP_TOPOLOGY 0x00010C68

+#define ASM_STREAM_CMD_FLUSH_READBUFS  0x00010C09
+#define ASM_STREAM_CMD_SET_ENCDEC_PARAM0x00010C10

[..]

+   q6asm_add_hdr(ac, , sizeof(open), true, ac->stream_id);
+
+   open.hdr.opcode = ASM_STREAM_CMD_OPEN_WRITE_V3;
+   open.mode_flags = 0x00;
+   open.mode_flags |= ASM_LEGACY_STREAM_SESSION;
+
+   /* source endpoint : matrix */
+   open.sink_endpointype = ASM_END_POINT_DEVICE_MATRIX;
+   open.bits_per_sample = bits_per_sample;
+   open.postprocopo_id = ASM_DEFAULT_POPP_TOPOLOGY;

 open.postprocopo_id = ASM_NULL_POPP_TOPOLOGY;

+
+   switch (format) {
+   case FORMAT_LINEAR_PCM:
+   open.dec_fmt_id = ASM_MEDIA_FMT_MULTI_CHANNEL_PCM_V2;
+   break;
+   default:
+   dev_err(ac->dev, "Invalid format 0x%x\n", format);
+   return -EINVAL;
+   }
+
+   rc = q6asm_ac_send_cmd_sync(ac, );
+   if (rc < 0)
+   return rc;
+
+   ac->io_mode |= ASM_TUN_WRITE_IO_MODE;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(q6asm_open_write);


Re: [alsa-devel] [PATCH v3 19/25] ASoC: qcom: q6afe: add support to MI2S ports

2018-03-07 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

Signed-off-by: Srinivas Kandagatla 
---
  include/dt-bindings/sound/qcom,q6afe.h |  10 +++
  sound/soc/qcom/qdsp6/q6afe.c   | 111 +
  sound/soc/qcom/qdsp6/q6afe.h   |  10 +++
  3 files changed, 131 insertions(+)

diff --git a/include/dt-bindings/sound/qcom,q6afe.h 
b/include/dt-bindings/sound/qcom,q6afe.h
index e9004ee39f72..3cd862262369 100644
--- a/include/dt-bindings/sound/qcom,q6afe.h
+++ b/include/dt-bindings/sound/qcom,q6afe.h
@@ -16,6 +16,16 @@
  #define SLIMBUS_4_TX24
  #define SLIMBUS_5_RX25
  #define SLIMBUS_5_TX26
+#define QUATERNARY_MI2S_RX 34
+#define QUATERNARY_MI2S_TX 35
+#define SECONDARY_MI2S_RX  36
+#define SECONDARY_MI2S_TX  37
+#define TERTIARY_MI2S_RX   38
+#define TERTIARY_MI2S_TX   39
+#define PRIMARY_MI2S_RX40
+#define PRIMARY_MI2S_TX41
Can we assign ids to Primary, secondary, tertiary and quaternary MI2S 
ports in sequence starting with Primary.

+#define SECONDARY_PCM_RX   42
+#define SECONDARY_PCM_TX   43

Why only SECONDARY_PCM_RX ? This is not required for MI2S right?

  #define SLIMBUS_6_RX45
  #define SLIMBUS_6_TX46


[..]


Re: [alsa-devel] [RESEND PATCH v2 08/15] ASoC: qcom: q6asm: add support to audio stream apis

2018-01-13 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to open, write and media format commands
in the q6asm module.

[..]

+static int32_t q6asm_callback(struct apr_device *adev,
+ struct apr_client_data *data, int session_id)
+{
+   struct audio_client *ac;// = (struct audio_client *)priv;
+   uint32_t token;
+   uint32_t *payload;
+   uint32_t wakeup_flag = 1;
+   uint32_t client_event = 0;
+   struct q6asm *q6asm = dev_get_drvdata(>dev);
+
+   if (data == NULL)
+   return -EINVAL;
+
+   ac = q6asm_get_audio_client(q6asm, session_id);
+   if (!q6asm_is_valid_audio_client(ac))
+   return -EINVAL;
+
ac could get freed by q6asm_audio_client_free during the execution of 
q6asm_callback as they are running in different thread.

Add synchronization.

+   payload = data->payload;
+
+   if (data->opcode == APR_BASIC_RSP_RESULT) {
+   token = data->token;
+   switch (payload[0]) {
+   case ASM_SESSION_CMD_PAUSE:
+   client_event = ASM_CLIENT_EVENT_CMD_PAUSE_DONE;
+   break;
+   case ASM_SESSION_CMD_SUSPEND:
+   client_event = ASM_CLIENT_EVENT_CMD_SUSPEND_DONE;
+   break;
+   case ASM_DATA_CMD_EOS:
+   client_event = ASM_CLIENT_EVENT_CMD_EOS_DONE;
+   break;
+   break;
+   case ASM_STREAM_CMD_FLUSH:
+   client_event = ASM_CLIENT_EVENT_CMD_FLUSH_DONE;
+   break;
+   case ASM_SESSION_CMD_RUN_V2:
+   client_event = ASM_CLIENT_EVENT_CMD_RUN_DONE;
+   break;
+
+   case ASM_STREAM_CMD_FLUSH_READBUFS:
+   if (token != ac->session) {
+   dev_err(ac->dev, "session invalid\n");
+   return -EINVAL;
+   }
+   case ASM_STREAM_CMD_CLOSE:
+   client_event = ASM_CLIENT_EVENT_CMD_CLOSE_DONE;
+   break;
+   case ASM_STREAM_CMD_OPEN_WRITE_V3:
+   case ASM_DATA_CMD_MEDIA_FMT_UPDATE_V2:
+   if (payload[1] != 0) {
+   dev_err(ac->dev,
+   "cmd = 0x%x returned error = 0x%x\n",
+   payload[0], payload[1]);
+   if (wakeup_flag) {
+   ac->cmd_state = payload[1];
+   wake_up(>cmd_wait);
+   }
+   return 0;
+   }
+   break;
+   default:
+   dev_err(ac->dev, "command[0x%x] not expecting rsp\n",
+   payload[0]);
+   break;
+   }
+
+   if (ac->cmd_state && wakeup_flag) {
+   ac->cmd_state = 0;
+   wake_up(>cmd_wait);
+   }
+   if (ac->cb)
+   ac->cb(client_event, data->token,
+  data->payload, ac->priv);
+
+   return 0;
+   }
+
+   switch (data->opcode) {
+   case ASM_DATA_EVENT_WRITE_DONE_V2:{
+   struct audio_port_data *port =
+   >port[SNDRV_PCM_STREAM_PLAYBACK];
+
+   client_event = ASM_CLIENT_EVENT_DATA_WRITE_DONE;
+
+   if (ac->io_mode & SYNC_IO_MODE) {
+   dma_addr_t phys = port->buf[data->token].phys;
+
+   if (lower_32_bits(phys) != payload[0] ||
+   upper_32_bits(phys) != payload[1]) {
+   dev_err(ac->dev, "Expected addr %pa\n",
+   >buf[data->token].phys);
+   return -EINVAL;
+   }
+   token = data->token;
+   port->buf[token].used = 1;
+   }
+   break;
+   }
+   }
+   if (ac->cb)
+   ac->cb(client_event, data->token, data->payload, ac->priv);
+
+   return 0;
+}
+

[..]

+/**
+ * q6asm_media_format_block_multi_ch_pcm() - setup pcm configuration
+ *
+ * @ac: audio client pointer
+ * @rate: audio sample rate
+ * @channels: number of audio channels.
+ * @use_default_chmap: flag to use default ch map.
+ * @channel_map: channel map pointer
+ * @bits_per_sample: bits per sample
+ *
+ * Return: Will be an negative value on error or zero on success
+ */
+int q6asm_media_format_block_multi_ch_pcm(struct audio_client *ac,

Re: [alsa-devel] [RESEND PATCH v2 12/15] ASoC: qcom: qdsp6: Add support to q6asm dai driver

2018-01-13 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6asm dai driver which configures Q6ASM streams
to pass pcm data.
Currently the driver only exposes 2 playback streams for hdmi playback
support, it can be easily extended to add all 8 streams.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig   |   6 +
  sound/soc/qcom/qdsp6/Makefile|   1 +
  sound/soc/qcom/qdsp6/q6asm-dai.c | 534 +++
  3 files changed, 541 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6asm-dai.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 003ce182691c..ecd1e4ba834d 100644
--- a/sound/soc/qcom/Kconfig

[..]

+static void event_handler(uint32_t opcode, uint32_t token,
+ uint32_t *payload, void *priv)
+{
+   struct q6asm_dai_rtd *prtd = priv;
+   struct snd_pcm_substream *substream = prtd->substream;
+
+   switch (opcode) {
+   case ASM_CLIENT_EVENT_CMD_RUN_DONE:
+   q6asm_write_nolock(prtd->audio_client,
+  prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+   break;
+   case ASM_CLIENT_EVENT_CMD_EOS_DONE:
+   prtd->state = STOPPED;
+   break;

Add support for V2 version of opcode to support latest adsp

+   case ASM_CLIENT_EVENT_DATA_WRITE_DONE: {
+   prtd->pcm_irq_pos += prtd->pcm_count;
+   snd_pcm_period_elapsed(substream);
+   if (prtd->state == RUNNING)
+   q6asm_write_nolock(prtd->audio_client,
+  prtd->pcm_count, 0, 0, NO_TIMESTAMP);
+
+   break;
+   }
+   default:
+   break;
+   }
+}
+
+static int q6asm_dai_prepare(struct snd_pcm_substream *substream)
+{
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct snd_soc_pcm_runtime *soc_prtd = substream->private_data;
+   struct q6asm_dai_rtd *prtd = runtime->private_data;
+   struct q6asm_dai_data *pdata;
+   int ret;
+
+   pdata = dev_get_drvdata(soc_prtd->platform->dev);
+   if (!pdata)
+   return -EINVAL;
+
+   if (!prtd || !prtd->audio_client) {
+   pr_err("%s: private data null or audio client freed\n",
+   __func__);
+   return -EINVAL;
+   }
+
+   prtd->pcm_count = snd_pcm_lib_period_bytes(substream);
+   prtd->pcm_irq_pos = 0;
+   /* rate and channels are sent to audio driver */
+   if (prtd->state) {
+   /* clear the previous setup if any  */
+   q6asm_cmd(prtd->audio_client, CMD_CLOSE);
+   q6asm_unmap_memory_regions(substream->stream,
+  prtd->audio_client);
+   q6routing_dereg_phy_stream(soc_prtd->dai_link->id,
+SNDRV_PCM_STREAM_PLAYBACK);
+   }
+
+   ret = q6asm_map_memory_regions(substream->stream, prtd->audio_client,
+  prtd->phys,
+  (prtd->pcm_size / prtd->periods),
+  prtd->periods);
+
+   if (ret < 0) {
+   pr_err("Audio Start: Buffer Allocation failed rc = %d\n",
+   ret);
+   return -ENOMEM;
+   }
+
+   ret = q6asm_open_write(prtd->audio_client, FORMAT_LINEAR_PCM,
+  prtd->bits_per_sample);
+   if (ret < 0) {
+   pr_err("%s: q6asm_open_write failed\n", __func__);
+   q6asm_audio_client_free(prtd->audio_client);
+   prtd->audio_client = NULL;
+   return -ENOMEM;
+   }
+
+   prtd->session_id = q6asm_get_session_id(prtd->audio_client);
+   ret = q6routing_reg_phy_stream(soc_prtd->dai_link->id, LEGACY_PCM_MODE,
+ prtd->session_id, substream->stream);
+   if (ret) {
+   pr_err("%s: stream reg failed ret:%d\n", __func__, ret);
+   return ret;
+   }
+
+   ret = q6asm_media_format_block_multi_ch_pcm(
+   prtd->audio_client, runtime->rate,
+   runtime->channels, !prtd->set_channel_map,
+   prtd->channel_map, prtd->bits_per_sample);
+   if (ret < 0)
+   pr_info("%s: CMD Format block failed\n", __func__);
+
+   prtd->state = RUNNING;
+
+   return 0;
+}
+
+static int q6asm_dai_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+   int ret = 0;
+   struct snd_pcm_runtime *runtime = substream->runtime;
+   struct q6asm_dai_rtd *prtd = runtime->private_data;
+
+   switch (cmd) {
+   case SNDRV_PCM_TRIGGER_START:
+   ret = q6asm_run_nowait(prtd->audio_client, 0, 0, 0);
+   break;
+   case SNDRV_PCM_TRIGGER_RESUME:
+ 

Re: [alsa-devel] [PATCH v3 05/25] ASoC: qcom: qdsp6: Add support to Q6AFE

2018-02-19 Thread Rohit Kumar


On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to Q6AFE (Audio Front End) module on Q6DSP.

AFE module sits right at the other end of cpu where the codec/audio
devices are connected.

AFE provides abstraced interfaces to both hardware and virtual devices.
Each AFE tx/rx port can be configured to connect to one of the hardware
devices like codec, hdmi, slimbus, i2s and so on. AFE services include
starting, stopping, and if needed, any configurations of the ports.

Signed-off-by: Srinivas Kandagatla 
---
  include/dt-bindings/sound/qcom,q6afe.h |   9 +
  sound/soc/qcom/Kconfig |   5 +
  sound/soc/qcom/Makefile|   5 +
  sound/soc/qcom/qdsp6/Makefile  |   1 +
  sound/soc/qcom/qdsp6/q6afe.c   | 520 +
  sound/soc/qcom/qdsp6/q6afe.h   |  37 +++
  6 files changed, 577 insertions(+)
  create mode 100644 include/dt-bindings/sound/qcom,q6afe.h
  create mode 100644 sound/soc/qcom/qdsp6/q6afe.c
  create mode 100644 sound/soc/qcom/qdsp6/q6afe.h

diff --git a/include/dt-bindings/sound/qcom,q6afe.h 
b/include/dt-bindings/sound/qcom,q6afe.h
new file mode 100644
index ..b4d82cccdc86
--- /dev/null
+++ b/include/dt-bindings/sound/qcom,q6afe.h
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef __DT_BINDINGS_Q6_AFE_H__
+#define __DT_BINDINGS_Q6_AFE_H__
+
+/* Audio Front End (AFE) Ports */
+#define AFE_PORT_HDMI_RX   8
+
+#endif /* __DT_BINDINGS_Q6_AFE_H__ */
+
diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index b01f347b427d..caeaf8b1b561 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -48,10 +48,15 @@ config SND_SOC_QDSP6_COMMON
tristate
default n
  
+config SND_SOC_QDSP6_AFE

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
depends on QCOM_APR && HAS_DMA
select SND_SOC_QDSP6_COMMON
+   select SND_SOC_QDSP6_AFE
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile
index d5280355c24f..748f5e891dcf 100644
--- a/sound/soc/qcom/Makefile
+++ b/sound/soc/qcom/Makefile
@@ -13,6 +13,11 @@ obj-$(CONFIG_SND_SOC_LPASS_APQ8016) += 
snd-soc-lpass-apq8016.o
  # Machine
  snd-soc-storm-objs := storm.o
  snd-soc-apq8016-sbc-objs := apq8016_sbc.o
+snd-soc-msm8996-objs := apq8096.o
  

This needs to be moved out of this patch

  obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o
  obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o
+obj-$(CONFIG_SND_SOC_MSM8996) += snd-soc-msm8996.o
+
+#DSP lib
+obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index accebdb49306..9ec951e0833b 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -1 +1,2 @@
  obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c
new file mode 100644
index ..0a5af06bb50e
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6afe.c
@@ -0,0 +1,520 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2017, The Linux Foundation
+ * Copyright (c) 2018, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6dsp-errno.h"
+#include "q6afe.h"
+
+/* AFE CMDs */
+#define AFE_PORT_CMD_DEVICE_START  0x000100E5
+#define AFE_PORT_CMD_DEVICE_STOP   0x000100E6
+#define AFE_PORT_CMD_SET_PARAM_V2  0x000100EF
+#define AFE_PORT_CMDRSP_GET_PARAM_V2   0x00010106
+#define AFE_PARAM_ID_HDMI_CONFIG   0x00010210
+#define AFE_MODULE_AUDIO_DEV_INTERFACE 0x0001020C
+
+/* Port IDs */
+#define AFE_API_VERSION_HDMI_CONFIG0x1
+#define AFE_PORT_ID_MULTICHAN_HDMI_RX  0x100E
+#define TIMEOUT_MS 1000
+#define AFE_CMD_RESP_AVAIL 0
+#define AFE_CMD_RESP_NONE  1
+
+struct q6afe {
+   struct apr_device *apr;
+   struct device *dev;
+   int state;
+   int status;
+
+   struct mutex lock;
+   struct list_head port_list;
+   spinlock_t port_list_lock;
+   struct list_head node;
+   void *dai_data;
+};
+
+struct afe_port_cmd_device_start {
+   struct apr_hdr hdr;
+   u16 port_id;
+   u16 reserved;
+} __packed;
+
+struct afe_port_cmd_device_stop {
+   struct apr_hdr hdr;
+   u16 port_id;
+   u16 reserved;
+/* Reserved for 32-bit alignment. This field must be set to 0.*/
+} __packed;
+
+struct afe_port_param_data_v2 {
+   u32 module_id;
+   u32 param_id;
+   u16 param_size;
+   u16 reserved;
+} __packed;
+
+struct afe_port_cmd_set_param_v2 {
+   u16 port_id;
+   u16 payload_size;
+   u32 payload_address_lsw;
+   u32 payload_address_msw;
+   u32 mem_map_handle;
+} 

Re: [alsa-devel] [PATCH v3 14/25] ASoC: qcom: qdsp6: Add support to q6afe dai driver

2018-02-19 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6afe backend dais driver.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/qdsp6/Makefile|   2 +-
  sound/soc/qcom/qdsp6/q6afe-dai.c | 280 +++
  sound/soc/qcom/qdsp6/q6afe.h |   3 +
  3 files changed, 284 insertions(+), 1 deletion(-)
  create mode 100644 sound/soc/qcom/qdsp6/q6afe-dai.c

diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index 660afcab98fd..c7833842b878 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -1,5 +1,5 @@
  obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o
-obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o q6afe-dai.o

depmod: ERROR: Cycle detected: q6afe -> q6afe_dai -> q6afe
need to use like:
+qdsp6_afe-objs := q6afe.o q6afe-dai.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE) += qdsp6_afe.o
similarly for asm and adm

  obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o q6routing.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
  obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c
new file mode 100644
index ..f6a618e9db9e
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2016, The Linux Foundation
+ * Copyright (c) 2018, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6afe.h"
+
+struct q6afe_dai_data {
+   struct q6afe_port *port[AFE_PORT_MAX];
+   struct q6afe_port_config port_config[AFE_PORT_MAX];
+   bool is_port_started[AFE_PORT_MAX];
+};
+
+static int q6hdmi_format_put(struct snd_kcontrol *kcontrol,
+   struct snd_ctl_elem_value *ucontrol)
+{
+   struct q6afe_dai_data *dai_data = kcontrol->private_data;
+   int value = ucontrol->value.integer.value[0];
+
+   dai_data->port_config[AFE_PORT_HDMI_RX].hdmi.datatype = value;
+
+   return 0;
+}
+
+static int q6hdmi_format_get(struct snd_kcontrol *kcontrol,
+   struct snd_ctl_elem_value *ucontrol)
+{
+
+   struct q6afe_dai_data *dai_data = kcontrol->private_data;
+
+   ucontrol->value.integer.value[0] =
+   dai_data->port_config[AFE_PORT_HDMI_RX].hdmi.datatype;
+
+   return 0;
+}
+
+static const char * const hdmi_format[] = {
+   "LPCM",
+   "Compr"
+};
+
+static const struct soc_enum hdmi_config_enum[] = {
+   SOC_ENUM_SINGLE_EXT(2, hdmi_format),
+};
+
+static const struct snd_kcontrol_new q6afe_config_controls[] = {
+   SOC_ENUM_EXT("HDMI RX Format", hdmi_config_enum[0],
+q6hdmi_format_get,
+q6hdmi_format_put),
+};
+
+static int q6hdmi_hw_params(struct snd_pcm_substream *substream,
+   struct snd_pcm_hw_params *params,
+   struct snd_soc_dai *dai)
+{
+   struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
+   int channels = params_channels(params);
+   struct q6afe_hdmi_cfg *hdmi = _data->port_config[dai->id].hdmi;
+
+   hdmi->sample_rate = params_rate(params);
+   switch (params_format(params)) {
+   case SNDRV_PCM_FORMAT_S16_LE:
+   hdmi->bit_width = 16;
+   break;
+   case SNDRV_PCM_FORMAT_S24_LE:
+   hdmi->bit_width = 24;
+   break;
+   }
+
+   /*refer to HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4*/
+   switch (channels) {
+   case 2:
+   hdmi->channel_allocation = 0;
+   break;
+   case 3:
+   hdmi->channel_allocation = 0x02;
+   break;
+   case 4:
+   hdmi->channel_allocation = 0x06;
+   break;
+   case 5:
+   hdmi->channel_allocation = 0x0A;
+   break;
+   case 6:
+   hdmi->channel_allocation = 0x0B;
+   break;
+   case 7:
+   hdmi->channel_allocation = 0x12;
+   break;
+   case 8:
+   hdmi->channel_allocation = 0x13;
+   break;
+   default:
+   dev_err(dai->dev, "invalid Channels = %u\n", channels);
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int q6afe_dai_startup(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
+
+   dai_data->is_port_started[dai->id] = false;
+
+   return 0;
+}
+
+static void q6afe_dai_shutdown(struct snd_pcm_substream *substream,
+   struct snd_soc_dai *dai)
+{
+   struct q6afe_dai_data *dai_data = q6afe_get_dai_data(dai->dev);
+   int rc;
+
+   rc = 

Re: [alsa-devel] [PATCH v3 12/25] ASoC: qcom: qdsp6: Add support to Q6CORE

2018-02-19 Thread Rohit Kumar



On 2/13/2018 10:28 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to core apr service, which is used to query
status of other static and dynamic services on the dsp.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig|   5 +
  sound/soc/qcom/qdsp6/Makefile |   1 +
  sound/soc/qcom/qdsp6/q6core.c | 235 ++
  sound/soc/qcom/qdsp6/q6core.h |   9 ++
  4 files changed, 250 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6core.c
  create mode 100644 sound/soc/qcom/qdsp6/q6core.h

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index a14d960b8fe4..8c2d65e0a28e 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -60,6 +60,10 @@ config SND_SOC_QDSP6_ASM
tristate
default n
  
+config SND_SOC_QDSP6_CORE

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
depends on QCOM_APR && HAS_DMA
@@ -67,6 +71,7 @@ config SND_SOC_QDSP6
select SND_SOC_QDSP6_AFE
select SND_SOC_QDSP6_ADM
select SND_SOC_QDSP6_ASM
+   select SND_SOC_QDSP6_CORE
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index eea962315ab3..61f089bc0d25 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_COMMON) += q6dsp-common.o
  obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
  obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
+obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c
new file mode 100644
index ..d4a3ff409a34
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6core.c
@@ -0,0 +1,235 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2011-2017, The Linux Foundation
+ * Copyright (c) 2018, Linaro Limited
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6dsp-errno.h"
+
+#define ADSP_STATE_READY_TIMEOUT_MS3000
+#define Q6_READY_TIMEOUT_MS 100
+#define AVCS_CMD_ADSP_EVENT_GET_STATE  0x0001290C
+#define AVCS_CMDRSP_ADSP_EVENT_GET_STATE   0x0001290D
+#define AVCS_GET_VERSIONS   0x00012905
+#define AVCS_GET_VERSIONS_RSP   0x00012906
+
+struct avcs_svc_info {
+   uint32_t service_id;
+   uint32_t version;
+} __packed;
+
+struct q6core {
+   struct apr_device *adev;
+   wait_queue_head_t wait;
+   uint32_t avcs_state;
+   bool resp_received;
+   uint32_t num_services;
+   struct avcs_svc_info *svcs_info;
+};
+
+struct q6core *core;
+
+static int q6core_callback(struct apr_device *adev,
+struct apr_client_message *data)
+{
+   struct q6core *core = dev_get_drvdata(>dev);
+   struct aprv2_ibasic_rsp_result_t *result;
+
+   result = data->payload;
+   switch (data->opcode) {
+   case AVCS_GET_VERSIONS_RSP:
+   core->num_services = result->status;
+
+   core->svcs_info = kcalloc(core->num_services,
+ sizeof(*core->svcs_info),
+ GFP_ATOMIC);
+   if (!core->svcs_info)
+   return -ENOMEM;
+
+   /* svc info is after apr result */
+   memcpy(core->svcs_info, result + sizeof(*result),
+  core->num_services * sizeof(*core->svcs_info));
+
+   core->resp_received = true;
+   wake_up(>wait);
+
+   break;
+   case AVCS_CMDRSP_ADSP_EVENT_GET_STATE:
+   core->avcs_state = result->opcode;
+
+   core->resp_received = true;
+   wake_up(>wait);
+   break;
+   default:
+   dev_err(>dev, "Message id from adsp core svc: 0x%x\n",
+   data->opcode);
+   break;
+   }
+
+   return 0;
+}
+
+static int q6core_get_svc_versions(struct q6core *core)
+{
+   struct apr_device *adev = core->adev;
+   struct apr_hdr hdr = {0};
+   int rc;
+
+   hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
+ APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
+   hdr.pkt_size = APR_HDR_SIZE;
+   hdr.opcode = AVCS_GET_VERSIONS;
+
+   rc = apr_send_pkt(adev, );
+   if (rc < 0)
+   return rc;
+
+   rc = wait_event_timeout(core->wait, (core->resp_received),
+   msecs_to_jiffies(Q6_READY_TIMEOUT_MS));
+   if (rc > 0 && core->resp_received) {
+   core->resp_received = false;
+   return 0;
+   }
+
+   return rc;
+}
+
+static bool __q6core_is_adsp_ready(struct q6core *core)
+{
+   struct apr_device *adev = core->adev;
+ 

Re: [alsa-devel] [RESEND PATCH v2 11/15] ASoC: qcom: qdsp6: Add support to q6afe dai driver

2018-02-07 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to q6afe backend dais driver.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig   |   5 +
  sound/soc/qcom/qdsp6/Makefile|   1 +
  sound/soc/qcom/qdsp6/q6afe-dai.c | 241 +++
  3 files changed, 247 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6afe-dai.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index dd8fb0cde614..003ce182691c 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -64,6 +64,10 @@ config SND_SOC_QDSP6_ROUTING
tristate
default n
  
+config SND_SOC_QDSP6_AFE_DAI

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
select SND_SOC_QDSP6_AFE
@@ -71,6 +75,7 @@ config SND_SOC_QDSP6
select SND_SOC_QDSP6_ASM
select SND_SOC_QDSP6_CORE
select SND_SOC_QDSP6_ROUTING
+   select SND_SOC_QDSP6_AFE_DAI
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index c1ad060a2341..bd8bd02bf09e 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
  obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
  obj-$(CONFIG_SND_SOC_QDSP6_ROUTING) += q6routing.o
+obj-$(CONFIG_SND_SOC_QDSP6_AFE_DAI) += q6afe-dai.o
diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c
new file mode 100644
index ..e9865c684bcb
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6afe-dai.c
@@ -0,0 +1,241 @@
+/* SPDX-License-Identifier: GPL-2.0
+* Copyright (c) 2011-2016, The Linux Foundation
+* Copyright (c) 2017, Linaro Limited
+*/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "q6afe.h"
+
+struct q6hdmi_dai_data {
+   struct q6afe_port *port;
+   struct q6afe_hdmi_cfg port_config;
+   bool is_port_started;
+};
+
+static int q6hdmi_format_put(struct snd_kcontrol *kcontrol,
+   struct snd_ctl_elem_value *ucontrol)
+{
+   struct q6hdmi_dai_data *dai_data = kcontrol->private_data;
+   int value = ucontrol->value.integer.value[0];
+
+   dai_data->port_config.datatype = value;



+
+static struct platform_driver q6afe_dai_driver = {
+   .probe  = q6afe_dai_dev_probe,
+   .remove = q6afe_dai_dev_remove,
+   .driver = {
+   .name = "q6afe_dai",
+   .owner = THIS_MODULE,
+   },
+};
+
+module_platform_driver(q6afe_dai_driver);

MODULE_LICENSE missing.


Re: [alsa-devel] [RESEND PATCH v2 09/15] ASoC: qcom: qdsp6: Add support to Q6CORE

2018-02-07 Thread Rohit Kumar



On 12/14/2017 11:03 PM, srinivas.kandaga...@linaro.org wrote:

From: Srinivas Kandagatla 

This patch adds support to core apr service, which is used to query
status of other static and dynamic services on the dsp.

Signed-off-by: Srinivas Kandagatla 
---
  sound/soc/qcom/Kconfig|   5 +
  sound/soc/qcom/qdsp6/Makefile |   1 +
  sound/soc/qcom/qdsp6/q6core.c | 227 ++
  3 files changed, 233 insertions(+)
  create mode 100644 sound/soc/qcom/qdsp6/q6core.c

diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 7ebdb879a8a3..121b9c957024 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -56,11 +56,16 @@ config SND_SOC_QDSP6_ASM
tristate
default n
  
+config SND_SOC_QDSP6_CORE

+   tristate
+   default n
+
  config SND_SOC_QDSP6
tristate "SoC ALSA audio driver for QDSP6"
select SND_SOC_QDSP6_AFE
select SND_SOC_QDSP6_ADM
select SND_SOC_QDSP6_ASM
+   select SND_SOC_QDSP6_CORE
help
 To add support for MSM QDSP6 Soc Audio.
 This will enable sound soc platform specific
diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile
index 49dd3ccab27b..ad7f10691e54 100644
--- a/sound/soc/qcom/qdsp6/Makefile
+++ b/sound/soc/qcom/qdsp6/Makefile
@@ -1,3 +1,4 @@
  obj-$(CONFIG_SND_SOC_QDSP6_AFE) += q6afe.o
  obj-$(CONFIG_SND_SOC_QDSP6_ADM) += q6adm.o
  obj-$(CONFIG_SND_SOC_QDSP6_ASM) += q6asm.o
+obj-$(CONFIG_SND_SOC_QDSP6_CORE) += q6core.o
diff --git a/sound/soc/qcom/qdsp6/q6core.c b/sound/soc/qcom/qdsp6/q6core.c
new file mode 100644
index ..d4e2dbc62489
--- /dev/null
+++ b/sound/soc/qcom/qdsp6/q6core.c
@@ -0,0 +1,227 @@
+/* SPDX-License-Identifier: GPL-2.0
+* Copyright (c) 2017, Linaro Limited
+*/
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

[..]

+
+   dev_set_drvdata(>dev, core);
+
+   core->adev = adev;
+   init_waitqueue_head(>wait);
+
+   do {
+   if (!q6core_is_adsp_ready(core)) {
+   dev_info(>dev, "ADSP Audio isn't ready\n");
+   } else {
+   dev_info(>dev, "ADSP Audio is ready\n");
+
If q6core_is_adsp_ready() return failure, then we should not call and 
ADSP API.

+   ret = q6core_get_svc_versions(core);
+   if (!ret)
+   q6core_add_static_services(core);
+
+   break;
+   }
+   } while (time_after(timeout, jiffies));
+
I think we should defer probe if q6core_is_adsp_ready() returns failure 
and timeouts.

+   return ret;
+}
+
+static int q6core_exit(struct apr_device *adev)
+{
+   return 0;
+}
+
+static const struct apr_device_id core_id[] = {
+   {"Q6CORE", APR_DOMAIN_ADSP, APR_SVC_ADSP_CORE, APR_CLIENT_AUDIO},
+   { },
+};
+
+static struct apr_driver qcom_q6core_driver = {
+   .probe = q6core_probe,
+   .remove = q6core_exit,
+   .callback = core_callback,
+   .id_table = core_id,
+   .driver = {
+  .name = "qcom-q6core",
+  },
+};
+
+module_apr_driver(qcom_q6core_driver);
+
+MODULE_AUTHOR("Srinivas Kandagatla 



  1   2   3   >