Skip to content

Commit

Permalink
os/drivers: add support for NDP120 mic drivers
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Akkabathula <[email protected]>
  • Loading branch information
abhishek-samsung authored and Taejun-Kwon committed Aug 8, 2024
1 parent ec4927a commit edf8460
Show file tree
Hide file tree
Showing 14 changed files with 2,454 additions and 0 deletions.
3 changes: 3 additions & 0 deletions os/Directories.mk
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,6 @@ KERNDEPDIRS += se
endif
CLEANDIRS += se

ifeq ($(CONFIG_NDP120),y)
CONTEXTDIRS += drivers
endif
4 changes: 4 additions & 0 deletions os/board/rtl8730e/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ endif
ifeq ($(CONFIG_LCD_ST7701SN), y)
CSRCS += rtl8730e_mipi_lcdc.c
endif

ifeq ($(CONFIG_AUDIO_NDP120),y)
CSRCS += rtl8730e_ndp120.c
endif
7 changes: 7 additions & 0 deletions os/board/rtl8730e/src/rtl8730e_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@ void board_initialize(void)
#ifdef CONFIG_AUDIO_ALC1019
rtl8730e_alc1019_initialize(0);
#endif

#ifdef CONFIG_AUDIO_NDP120
if (rtl8730e_ndp120_initialize(0) != 0) {
lldbg("NDP120 initialization failed\n");
}
#endif

IPC_MSG_STRUCT ipc_msg_loguart;

ipc_msg_loguart.msg_type = IPC_USER_POINT;
Expand Down
184 changes: 184 additions & 0 deletions os/board/rtl8730e/src/rtl8730e_ndp120.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/****************************************************************************
*
* Copyright 2023 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/

#include <tinyara/config.h>

#include <stdbool.h>
#include <stdio.h>
#include <debug.h>
#include <assert.h>
#include <errno.h>

#include <tinyara/irq.h>
#include <tinyara/audio/ndp120.h>
#include <tinyara/gpio.h>
#include "gpio_irq_api.h"
#include <tinyara/audio/ndp120.h>

#include "objects.h"
#include "PinNames.h"
#include "gpio_api.h"

#ifdef CONFIG_AUDIO_NDP120

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define NDP120_AVAILABLE_MINOR_MIN 0
#define NDP120_AVAILABLE_MINOR_MAX 25

/* spi config */
#define NDP120_SPI_PORT 0
#define NDP120_SPI_FREQ 12000000
#define NDP120_SPI_BPW 8
#define NDP120_SPI_CS 0
#define NDP120_SPI_MODE SPIDEV_MODE0

/****************************************************************************
* Private Types
****************************************************************************/
struct rtl8730e_ndp120_audioinfo_s {
struct ndp120_lower_s lower;
ndp120_handler_t handler;
gpio_irq_t data_ready;
};

/****************************************************************************
* Private Data
****************************************************************************/
static struct rtl8730e_ndp120_audioinfo_s g_ndp120info = {
.lower = {
.spi_config = {
.bpw = NDP120_SPI_BPW,
.freq = NDP120_SPI_FREQ,
.cs = NDP120_SPI_CS,
.mode = NDP120_SPI_MODE,
},
},

.handler = NULL,
};

/****************************************************************************
* Private Functions
****************************************************************************/

static void rtl8730e_ndp120_irq_handler(uint32_t id, gpio_irq_event event)
{
/* we are using level based interrupt trigger here,
* so, we have to disable this particular gpio interrupt
* until we finish this particular interrupt related work
* in the HPWORK thread
*/
gpio_irq_disable(&g_ndp120info.data_ready);

if (g_ndp120info.handler != NULL) {
g_ndp120info.handler(id);
} else {
gpio_irq_enable(&g_ndp120info.data_ready);
}
}

static void rtl8730e_ndp120_enable_irq(bool enable)
{
if (enable) {
gpio_irq_enable(&g_ndp120info.data_ready);
} else {
gpio_irq_disable(&g_ndp120info.data_ready);
}
}

static void rtl8730e_ndp120_irq_attach(ndp120_handler_t handler, FAR char *arg)
{
g_ndp120info.handler = handler;
gpio_irq_init(&g_ndp120info.data_ready, PA_23, rtl8730e_ndp120_irq_handler, arg);
gpio_irq_set(&g_ndp120info.data_ready, IRQ_FALL_RISE, 1);
gpio_irq_enable(&g_ndp120info.data_ready);
}

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: rtl8730e_ndp120_initialize
*
* Description:
* This function is called by platform-specific, setup logic to configure
* and register the NDP120 device. This function will register the driver
* as /dev/ndp120[x] where x is determined by the minor device number.
*
* Input Parameters:
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int rtl8730e_ndp120_initialize(int minor)
{
FAR struct audio_lowerhalf_s *ndp120;
static bool initialized = false;
char devname[12];
int ret;

audvdbg("minor %d\n", minor);
DEBUGASSERT(minor >= NDP120_AVAILABLE_MINOR_MIN && minor <= NDP120_AVAILABLE_MINOR_MAX);

/* Have we already initialized? Since we never uninitialize we must prevent
* multiple initializations. This is necessary, for example, when the
* touchscreen example is used as a built-in application in NSH and can be
* called numerous time. It will attempt to initialize each time.
*/

if (!initialized) {

g_ndp120info.lower.attach = rtl8730e_ndp120_irq_attach;
g_ndp120info.lower.irq_enable = rtl8730e_ndp120_enable_irq;

/* currently spi 0 is only attached to AI SoC, so no
* need to change the spi config as we are dealing with
* only 1 slave, if we add more slaves, parameters below
* should be set always before the transfers and must be
* passed to lower level using spi_config in ndp120_lower_s.
*/
FAR struct spi_dev_s *spi = up_spiinitialize(NDP120_SPI_PORT);

SPI_SETMODE(spi, NDP120_SPI_MODE);
SPI_SETFREQUENCY(spi, NDP120_SPI_FREQ);
SPI_SETBITS(spi, NDP120_SPI_BPW);

ndp120 = ndp120_lowerhalf_initialize(spi, &g_ndp120info.lower);
if (ndp120 == NULL) {
return ERROR;
}

snprintf(devname, sizeof(devname), "pcmC%uD%u%c", minor, 0, 'c');
ret = audio_register(devname, ndp120);

initialized = true;
}

return ret;
}
#endif
4 changes: 4 additions & 0 deletions os/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ if DRIVERS_VIDEO
source drivers/video/Kconfig
endif # DRIVERS_VIDEO

menu "AI SoC devices"
source drivers/ai-soc/Kconfig
endmenu

source drivers/lcd/Kconfig

menuconfig BCH
Expand Down
13 changes: 13 additions & 0 deletions os/drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ endif

include analog$(DELIM)Make.defs
include audio$(DELIM)Make.defs
include ai-soc$(DELIM)Make.defs
include bch$(DELIM)Make.defs
include bluetooth$(DELIM)Make.defs
include compression$(DELIM)Make.defs
Expand Down Expand Up @@ -172,6 +173,18 @@ $(BIN): $(OBJS)

depend: .depend

ifeq ($(CONFIG_NDP120),y)
context:
$(eval DEST_DIR = $(TOPDIR)/../tools/fs/contents-smartfs/rtl8730e/base-files/ndp120)
@if [ -e $(DEST_DIR) ]; then \
rm -rf $(DEST_DIR); \
echo "Deleted ndp120 folder from fs"; \
fi
@mkdir -p $(DEST_DIR)
@cp $(TOPDIR)/drivers/ai-soc/ndp120/binaries/* $(TOPDIR)/../tools/fs/contents-smartfs/rtl8730e/base-files/ndp120
@echo "NPD120 f/w files copied for generating fs image"
endif

clean:
$(call DELFILE, $(BIN))
$(call CLEAN)
Expand Down
10 changes: 10 additions & 0 deletions os/drivers/ai-soc/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# For a description of the syntax of this configuration file,
# see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt

config NDP120
bool "NDP120 AI soc support"
default n
depends on SPI
---help---
Select to enable support for the NDP120 AI soc
39 changes: 39 additions & 0 deletions os/drivers/ai-soc/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
##########################################################################
#
# Copyright 2023 Samsung Electronics All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
############################################################################

ifeq ($(CONFIG_NDP120),y)
CSRCS += ndp120_api.c
CSRCS += checksum.c
CSRCS += syntiant_ndp.c
CSRCS += syntiant_ndp115.c
CSRCS += syntiant_ndp120.c
CSRCS += syntiant_ndp120_config.c
CSRCS += syntiant_ndp120_config_misc.c
CSRCS += syntiant_ndp120_mailbox.c
CSRCS += syntiant_ndp120_ph.c
CSRCS += syntiant_ndp_error.c
CSRCS += syntiant_package.c
CSRCS += syntiant_portability.c

CFLAGS += -I $(TOPDIR)/drivers/ai-soc/ndp120/include -DEXCLUDE_SYNTIANT_CORE_1
endif

# Include Audio driver support

DEPPATH += --dep-path ai-soc --dep-path ai-soc/ndp120/src
VPATH += :ai-soc :ai-soc/ndp120/src
Loading

0 comments on commit edf8460

Please sign in to comment.