arch: cxd56xx: Add host interface driver

Add host interface driver which supports I2C or SPI slave feature.
This commit is contained in:
SPRESENSE
2021-05-19 18:00:25 +09:00
committed by Alin Jerpelea
parent 5a7a118320
commit db9c94962b
7 changed files with 990 additions and 0 deletions
+136
View File
@@ -0,0 +1,136 @@
/****************************************************************************
* arch/arm/include/cxd56xx/hostif.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you 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.
*
****************************************************************************/
#ifndef __ARCH_ARM_INCLUDE_CXD56XX_HOSTIF_H
#define __ARCH_ARM_INCLUDE_CXD56XX_HOSTIF_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Host interface maximum number of buffers */
#define MAX_BUFFER_NUM 32
/* Host interface buffer attributes */
#define HOSTIF_BUFF_ATTR_ADDR_OFFSET(n) (((n) & 0x3) << 4)
/* 2 to the power of n */
#define HOSTIF_BUFF_ATTR_FIXLEN (0 << 2) /* fixed length */
#define HOSTIF_BUFF_ATTR_VARLEN (1 << 2) /* variable length */
#define HOSTIF_BUFF_ATTR_WRITE (0 << 1) /* from target to host */
#define HOSTIF_BUFF_ATTR_READ (1 << 1) /* from host to target */
/****************************************************************************
* Public Types
****************************************************************************/
/* Common buffer configuration */
struct hostif_buff_s
{
uint16_t size;
uint16_t flag;
};
/* I2C buffer configuration */
struct hostif_i2cconf_s
{
int address; /* slave address */
struct hostif_buff_s buff[MAX_BUFFER_NUM];
};
/* SPI buffer configuration */
struct hostif_spiconf_s
{
struct hostif_buff_s buff[MAX_BUFFER_NUM];
};
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: hostif_i2cinitialize
*
* Description:
* Initialize the host interface for I2C slave
*
* Input Parameter:
* config - pointer to I2C buffer configuration
*
* Returned Value:
* Return 0 on success. Otherwise, return a negated errno.
*
****************************************************************************/
int hostif_i2cinitialize(FAR struct hostif_i2cconf_s *config);
/****************************************************************************
* Name: hostif_spiinitialize
*
* Description:
* Initialize the host interface for SPI slave
*
* Input Parameter:
* config - pointer to SPI buffer configuration
*
* Returned Value:
* Return 0 on success. Otherwise, return a negated errno.
*
****************************************************************************/
int hostif_spiinitialize(FAR struct hostif_spiconf_s *config);
/****************************************************************************
* Name: hostif_uninitialize
*
* Description:
* Uninitialize the host interface
*
* Returned Value:
* Return 0 on success. Otherwise, return a negated errno.
*
****************************************************************************/
int hostif_uninitialize(void);
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_INCLUDE_CXD56XX_HOSTIF_H */
+39
View File
@@ -1093,6 +1093,45 @@ config CXD56_CISIF
default n
---help---
CMOS image sensor interface for cx5602 chip
config CXD56_HOSTIF
bool "Host interface"
default n
---help---
Host interface supports I2C or SPI slave feature.
config CXD56_HOSTIF_DEBUG
bool "Host interface Debug Features"
default n
depends on CXD56_HOSTIF
---help---
Enable host interface device debug features.
if CXD56_HOSTIF_DEBUG
config CXD56_HOSTIF_DEBUG_ERROR
bool "Host interface Error Output"
default n
depends on DEBUG_ERROR
---help---
Enable host interface error output to SYSLOG.
config CXD56_HOSTIF_DEBUG_WARN
bool "Host interface Warnings Output"
default n
depends on DEBUG_WARN
---help---
Enable host interface warning output to SYSLOG.
config CXD56_HOSTIF_DEBUG_INFO
bool "Host interface Informational Output"
default n
depends on DEBUG_INFO
---help---
Enable host interface informational output to SYSLOG.
endif # CXD56_HOSTIF_DEBUG
endmenu
comment "Storage Options"
+4
View File
@@ -201,3 +201,7 @@ endif
ifeq ($(CONFIG_CXD56_BACKUPLOG),y)
CHIP_CSRCS += cxd56_backuplog.c
endif
ifeq ($(CONFIG_CXD56_HOSTIF),y)
CHIP_CSRCS += cxd56_hostif.c
endif
+176
View File
@@ -2291,6 +2291,182 @@ uint32_t cxd56_get_img_vsync_baseclock(void)
}
}
static int cxd56_hostif_clock_ctrl(uint32_t block, uint32_t intr, int on)
{
uint32_t val;
uint32_t stat;
int retry = 10000;
putreg32(0xffffffff, CXD56_TOPREG_CRG_INT_CLR0);
val = getreg32(CXD56_TOPREG_SYSIOP_CKEN);
if (on)
{
if ((val & block) == block)
{
/* Already clock on */
return OK;
}
putreg32(val | block, CXD56_TOPREG_SYSIOP_CKEN);
}
else
{
if ((val & block) == 0)
{
/* Already clock off */
return OK;
}
putreg32(val & ~block, CXD56_TOPREG_SYSIOP_CKEN);
}
do
{
stat = getreg32(CXD56_TOPREG_CRG_INT_STAT_RAW0);
busy_wait(1000);
}
while (retry-- && !(stat & intr));
putreg32(0xffffffff, CXD56_TOPREG_CRG_INT_CLR0);
return (retry) ? OK : -ETIMEDOUT;
}
int cxd56_hostif_clock_enable(void)
{
int ret = OK;
uint32_t mask;
uint32_t intr;
/* Enable HOSTIF IRAM/DRAM & general RAM memory power. */
putreg32((0x3 << 24) | 0xf, CXD56_TOPREG_HOSTIFC_RAMMODE_SEL);
do_power_control();
mask = CKEN_HOSSPI | CKEN_HOSI2C | CKEN_HOSTIFC_SEQ | CKEN_BRG_HOST |
CKEN_I2CS | CKEN_PCLK_HOSTIFC | CKEN_PCLK_UART0 | CKEN_UART0;
if (getreg32(CXD56_TOPREG_SYSIOP_CKEN) & mask)
{
/* Already enabled */
return ret;
}
putreg32(0, CXD56_TOPREG_CKDIV_HOSTIFC);
putreg32(0, CXD56_TOPREG_CKSEL_SYSIOP);
mask = CKEN_HOSSPI | CKEN_HOSI2C | CKEN_BRG_HOST |
CKEN_I2CS | CKEN_PCLK_HOSTIFC;
intr = CRG_CK_BRG_HOST | CRG_CK_I2CS | CRG_CK_PCLK_HOSTIFC;
ret = cxd56_hostif_clock_ctrl(mask, intr, 1);
if (ret < 0)
{
return ret;
}
ret = cxd56_hostif_clock_ctrl(mask, intr, 0);
if (ret < 0)
{
return ret;
}
modifyreg32(CXD56_TOPREG_SWRESET_BUS, 0, XRST_HOSTIFC);
ret = cxd56_hostif_clock_ctrl(mask, intr, 1);
return ret;
}
int cxd56_hostif_clock_disable(void)
{
int ret = OK;
uint32_t mask;
uint32_t intr;
mask = CKEN_HOSSPI | CKEN_HOSI2C | CKEN_HOSTIFC_SEQ | CKEN_BRG_HOST |
CKEN_I2CS | CKEN_PCLK_HOSTIFC | CKEN_PCLK_UART0 | CKEN_UART0;
if (0 == (getreg32(CXD56_TOPREG_SYSIOP_CKEN) & mask))
{
/* Already disabled */
return ret;
}
mask = CKEN_HOSSPI | CKEN_HOSI2C | CKEN_BRG_HOST |
CKEN_I2CS | CKEN_PCLK_HOSTIFC;
intr = CRG_CK_BRG_HOST | CRG_CK_I2CS | CRG_CK_PCLK_HOSTIFC;
ret = cxd56_hostif_clock_ctrl(mask, intr, 0);
if (ret < 0)
{
return ret;
}
modifyreg32(CXD56_TOPREG_SWRESET_BUS, XRST_HOSTIFC, 0);
/* Disable HOSTIF IRAM/DRAM & general RAM memory power. */
putreg32(0x3, CXD56_TOPREG_HOSTIFC_RAMMODE_SEL);
do_power_control();
return ret;
}
int cxd56_hostseq_clock_enable(void)
{
int ret = OK;
if (getreg32(CXD56_TOPREG_SYSIOP_CKEN) & CKEN_HOSTIFC_SEQ)
{
/* Already enabled */
return ret;
}
ret = cxd56_hostif_clock_ctrl(CKEN_HOSTIFC_SEQ, CRG_CK_HOSTIFC_SEQ, 1);
if (ret < 0)
{
return ret;
}
ret = cxd56_hostif_clock_ctrl(CKEN_HOSTIFC_SEQ, CRG_CK_HOSTIFC_SEQ, 0);
if (ret < 0)
{
return ret;
}
modifyreg32(CXD56_TOPREG_SWRESET_BUS, 0, XRST_HOSTIFC_ISOP);
ret = cxd56_hostif_clock_ctrl(CKEN_HOSTIFC_SEQ, CRG_CK_HOSTIFC_SEQ, 1);
return ret;
}
int cxd56_hostseq_clock_disable(void)
{
int ret = OK;
if (0 == (getreg32(CXD56_TOPREG_SYSIOP_CKEN) & CKEN_HOSTIFC_SEQ))
{
/* Already disabled */
return ret;
}
modifyreg32(CXD56_TOPREG_SWRESET_BUS, XRST_HOSTIFC_ISOP, 0);
ret = cxd56_hostif_clock_ctrl(CKEN_HOSTIFC_SEQ, CRG_CK_HOSTIFC_SEQ, 0);
return ret;
}
int up_pmramctrl(int cmd, uintptr_t addr, size_t size)
{
int startidx;
+40
View File
@@ -684,6 +684,46 @@ uint32_t cxd56_get_img_vsync_baseclock(void);
uint32_t cxd56_get_appsmp_baseclock(void);
/****************************************************************************
* Name: cxd56_hostif_clock_enable
*
* Description:
* Enable clock of the hostif block
*
****************************************************************************/
int cxd56_hostif_clock_enable(void);
/****************************************************************************
* Name: cxd56_hostif_clock_disable
*
* Description:
* Disable clock of the hostif block
*
****************************************************************************/
int cxd56_hostif_clock_disable(void);
/****************************************************************************
* Name: cxd56_hostseq_clock_enable
*
* Description:
* Enable clock of the hostif sequencer block
*
****************************************************************************/
int cxd56_hostseq_clock_enable(void);
/****************************************************************************
* Name: cxd56_hostseq_clock_disable
*
* Description:
* Disable clock of the hostif sequencer block
*
****************************************************************************/
int cxd56_hostseq_clock_disable(void);
#undef EXTERN
#if defined(__cplusplus)
}
File diff suppressed because it is too large Load Diff
+1
View File
@@ -32,6 +32,7 @@
#define CXD56_PROTO_HOTSLEEP 8
#define CXD56_PROTO_IMAGE 9
#define CXD56_PROTO_PM 10 /* Power manager */
#define CXD56_PROTO_HOSTIF 11
#define CXD56_PROTO_SYSCTL 12
#define CXD56_PROTO_GNSS 13
#define CXD56_PROTO_SIG 15 /* Inter-CPU Comm signal */