mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
arm64/imx9: Add LPI2C driver
This commit is contained in:
@@ -94,6 +94,7 @@ config ARCH_CHIP_IMX8
|
||||
config ARCH_CHIP_IMX9
|
||||
bool "NXP i.MX9 Platform (ARMv8.2a)"
|
||||
select ARCH_HAVE_ADDRENV
|
||||
select ARCH_HAVE_I2CRESET
|
||||
select ARCH_HAVE_IRQTRIGGER
|
||||
select ARCH_NEED_ADDRENV_MAPPING
|
||||
---help---
|
||||
|
||||
@@ -218,8 +218,257 @@ config IMX9_GPIO_IRQ
|
||||
bool "GPIO Interrupt Support"
|
||||
default n
|
||||
|
||||
config IMX9_LPI2C
|
||||
bool "LPI2C support"
|
||||
default n
|
||||
|
||||
config IMX9_PLL
|
||||
bool "PLL setup support (WIP)"
|
||||
default n
|
||||
|
||||
menu "LPI2C Peripherals"
|
||||
|
||||
menuconfig IMX9_LPI2C1
|
||||
bool "LPI2C1"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C1
|
||||
|
||||
config IMX9_LPI2C1_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C1_DMA
|
||||
bool "Enable DMA for I2C1"
|
||||
default n
|
||||
depends on IMX9_LPI2C_DMA
|
||||
|
||||
config IMX9_LPI2C1_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C1_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C1
|
||||
|
||||
menuconfig IMX9_LPI2C2
|
||||
bool "LPI2C2"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C2
|
||||
|
||||
config IMX9_LPI2C2_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C2_DMA
|
||||
bool "Enable DMA for I2C2"
|
||||
default n
|
||||
depends on IMX9_LPI2C_DMA
|
||||
|
||||
config IMX9_LPI2C2_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C2_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C2
|
||||
|
||||
menuconfig IMX9_LPI2C3
|
||||
bool "LPI2C3"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C3
|
||||
|
||||
config IMX9_LPI2C3_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C3_DMA
|
||||
bool "Enable DMA for I2C3"
|
||||
default n
|
||||
depends on IMX9_LPI2C_DMA
|
||||
|
||||
config IMX9_LPI2C3_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C3_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C3
|
||||
|
||||
menuconfig IMX9_LPI2C4
|
||||
bool "LPI2C4"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C4
|
||||
|
||||
config IMX9_LPI2C4_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C4_DMA
|
||||
bool "Enable DMA for I2C4"
|
||||
default n
|
||||
depends on IMX9_LPI2C_DMA
|
||||
|
||||
config IMX9_LPI2C4_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C4_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C4
|
||||
|
||||
menuconfig IMX9_LPI2C5
|
||||
bool "LPI2C5"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C5
|
||||
|
||||
config IMX9_LPI2C5_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C5_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C5_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C5
|
||||
|
||||
menuconfig IMX9_LPI2C6
|
||||
bool "LPI2C6"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C6
|
||||
|
||||
config IMX9_LPI2C6_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C6_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C6_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C6
|
||||
|
||||
menuconfig IMX9_LPI2C7
|
||||
bool "LPI2C7"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C7
|
||||
|
||||
config IMX9_LPI2C7_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C7_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C7_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C7
|
||||
|
||||
menuconfig IMX9_LPI2C8
|
||||
bool "LPI2C8"
|
||||
default n
|
||||
select IMX9_LPI2C
|
||||
|
||||
if IMX9_LPI2C8
|
||||
|
||||
config IMX9_LPI2C8_BUSYIDLE
|
||||
int "Bus idle timeout period in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C8_FILTSCL
|
||||
int "I2C master digital glitch filters for SCL input in clock cycles"
|
||||
default 0
|
||||
|
||||
config IMX9_LPI2C8_FILTSDA
|
||||
int "I2C master digital glitch filters for SDA input in clock cycles"
|
||||
default 0
|
||||
|
||||
endif # IMX9_LPI2C8
|
||||
|
||||
endmenu # LPI2C Peripherals
|
||||
menu "LPI2C Configuration"
|
||||
depends on IMX9_LPI2C
|
||||
|
||||
config IMX9_LPI2C_DMA
|
||||
bool "I2C DMA Support"
|
||||
default n
|
||||
depends on IMX9_LPI2C && IMX9_EDMA && !I2C_POLLED
|
||||
---help---
|
||||
This option enables the DMA for I2C transfers.
|
||||
Note: The user can define CONFIG_I2C_DMAPRIO: a custom priority value
|
||||
for the I2C dma streams, else the default priority level is set to
|
||||
medium.
|
||||
|
||||
config IMX9_LPI2C_DMA_MAXMSG
|
||||
int "Maximum number messages that will be DMAed"
|
||||
default 8
|
||||
depends on IMX9_LPI2C_DMA
|
||||
---help---
|
||||
This option set the mumber of mesg that can be in a transfer.
|
||||
It is used to allocate space for the 16 bit LPI2C commands
|
||||
that will be DMA-ed to the LPI2C device.
|
||||
|
||||
config IMX9_LPI2C_DYNTIMEO
|
||||
bool "Use dynamic timeouts"
|
||||
default n
|
||||
depends on IMX9_LPI2C
|
||||
|
||||
config IMX9_LPI2C_DYNTIMEO_USECPERBYTE
|
||||
int "Timeout Microseconds per Byte"
|
||||
default 500
|
||||
depends on IMX9_LPI2C_DYNTIMEO
|
||||
|
||||
config IMX9_LPI2C_DYNTIMEO_STARTSTOP
|
||||
int "Timeout for Start/Stop (Milliseconds)"
|
||||
default 1000
|
||||
depends on IMX9_LPI2C_DYNTIMEO
|
||||
|
||||
config IMX9_LPI2C_TIMEOSEC
|
||||
int "Timeout seconds"
|
||||
default 0
|
||||
depends on IMX9_LPI2C
|
||||
|
||||
config IMX9_LPI2C_TIMEOMS
|
||||
int "Timeout Milliseconds"
|
||||
default 500
|
||||
depends on IMX9_LPI2C && !IMX9_LPI2C_DYNTIMEO
|
||||
|
||||
config IMX9_LPI2C_TIMEOTICKS
|
||||
int "Timeout for Done and Stop (ticks)"
|
||||
default 500
|
||||
depends on IMX9_LPI2C && !IMX9_LPI2C_DYNTIMEO
|
||||
|
||||
endmenu # LPI2C Configuration
|
||||
|
||||
endif # ARCH_CHIP_IMX9
|
||||
|
||||
@@ -46,3 +46,7 @@ endif
|
||||
ifeq ($(CONFIG_IMX9_USBDEV),y)
|
||||
CHIP_CSRCS += imx9_usbdev.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_IMX9_LPI2C),y)
|
||||
CHIP_CSRCS += imx9_lpi2c.c
|
||||
endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
* arch/arm64/src/imx9/imx9_lpi2c.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_ARM64_SRC_IMX9_IMX9_LPI2C_H
|
||||
#define __ARCH_ARM64_SRC_IMX9_IMX9_LPI2C_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: imx9_i2cbus_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the selected I2C port. And return a unique instance of struct
|
||||
* struct i2c_master_s. This function may be called to obtain multiple
|
||||
* instances of the interface, each of which may be set up with a
|
||||
* different frequency and slave address.
|
||||
*
|
||||
* Input Parameters:
|
||||
* Port number (for hardware that has multiple I2C interfaces)
|
||||
*
|
||||
* Returned Value:
|
||||
* Valid I2C device structure reference on success; a NULL on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct i2c_master_s *imx9_i2cbus_initialize(int port);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: imx9_i2cbus_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* De-initialize the selected I2C port, and power down the device.
|
||||
*
|
||||
* Input Parameters:
|
||||
* Device structure as returned by the imx9_i2cbus_initialize()
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success, ERROR when internal reference count mismatch or dev
|
||||
* points to invalid hardware device.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int imx9_i2cbus_uninitialize(struct i2c_master_s *dev);
|
||||
|
||||
#endif /* __ARCH_ARM64_SRC_IMX9_IMX9_LPI2C_H */
|
||||
@@ -28,9 +28,14 @@ CONFIG_FS_PROCFS=y
|
||||
CONFIG_FS_ROMFS=y
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2C_RESET=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=8192
|
||||
CONFIG_IMX9_FLEXIO1_PWM=y
|
||||
CONFIG_IMX9_GPIO_IRQ=y
|
||||
CONFIG_IMX9_LPI2C1=y
|
||||
CONFIG_IMX9_LPI2C_DYNTIMEO=y
|
||||
CONFIG_IMX9_LPI2C_DYNTIMEO_STARTSTOP=10
|
||||
CONFIG_IMX9_TPM3_PWM=y
|
||||
CONFIG_IMX9_TPM3_PWM_CHMUX=0x00000003
|
||||
CONFIG_IMX9_UART1=y
|
||||
@@ -60,6 +65,7 @@ CONFIG_START_MONTH=3
|
||||
CONFIG_START_YEAR=2022
|
||||
CONFIG_SYMTAB_ORDEREDBYNAME=y
|
||||
CONFIG_SYSTEM_CDCACM=y
|
||||
CONFIG_SYSTEM_I2CTOOL=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_SYSTEM=y
|
||||
CONFIG_SYSTEM_TIME64=y
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define IOMUX_LPI2C_DEFAULT (IOMUXC_PAD_OD_ENABLE | IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X6)
|
||||
|
||||
/* FLEXIO to PWM pin muxings */
|
||||
|
||||
/* EVK signals
|
||||
@@ -49,6 +51,16 @@
|
||||
|
||||
#define TPM3_PWM3_MUX IOMUX_CFG(IOMUXC_PAD_GPIO_IO24_TPM3_CH3, IOMUXC_PAD_FSEL_SFAST | IOMUXC_PAD_DSE_X6, 0)
|
||||
|
||||
/* LPI2Cs */
|
||||
|
||||
#define MUX_LPI2C1_SCL IOMUX_CFG(IOMUXC_PAD_I2C1_SCL_LPI2C1_SCL, IOMUX_LPI2C_DEFAULT, IOMUXC_MUX_SION_ON)
|
||||
#define MUX_LPI2C1_SDA IOMUX_CFG(IOMUXC_PAD_I2C1_SDA_LPI2C1_SDA, IOMUX_LPI2C_DEFAULT, IOMUXC_MUX_SION_ON)
|
||||
|
||||
/* I2C reset functionality */
|
||||
|
||||
#define GPIO_LPI2C1_SCL_RESET (GPIO_PORT1 | GPIO_PIN0 | GPIO_OUTPUT | GPIO_OUTPUT_ONE)
|
||||
#define GPIO_LPI2C1_SDA_RESET (GPIO_PORT1 | GPIO_PIN1 | GPIO_OUTPUT | GPIO_OUTPUT_ONE)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
@@ -30,4 +30,8 @@ ifeq ($(CONFIG_PWM),y)
|
||||
CSRCS += imx9_pwm.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_IMX9_LPI2C),y)
|
||||
CSRCS += imx9_i2c.c
|
||||
endif
|
||||
|
||||
include $(TOPDIR)/boards/Board.mk
|
||||
|
||||
@@ -67,5 +67,17 @@ int imx9_bringup(void);
|
||||
int imx9_pwm_setup(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: imx9_i2c_setup
|
||||
*
|
||||
* Description:
|
||||
* Initialize I2C devices and driver
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_I2C_DRIVER)
|
||||
int imx9_i2c_initialize(void);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARDS_ARM64_IMX9_IMX93_EVK_SRC_IMX93_EVK_H */
|
||||
|
||||
@@ -23,8 +23,11 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/board.h>
|
||||
|
||||
#include "imx93-evk.h"
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -67,6 +67,16 @@ int imx9_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_I2C_DRIVER)
|
||||
/* Configure I2C peripheral interfaces */
|
||||
|
||||
ret = imx9_i2c_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize I2C driver: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
UNUSED(ret);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
* boards/arm64/imx9/imx93-evk/src/imx9_i2c.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
#include "imx9_lpi2c.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_i2c_init
|
||||
*
|
||||
* Description:
|
||||
* Configure the I2C driver.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; A negated errno value is returned
|
||||
* to indicate the nature of any failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int imx9_i2c_initialize(void)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
#ifdef CONFIG_IMX9_LPI2C1
|
||||
struct i2c_master_s *i2c;
|
||||
|
||||
i2c = imx9_i2cbus_initialize(1);
|
||||
if (i2c == NULL)
|
||||
{
|
||||
i2cerr("ERROR: Failed to init I2C0 interface\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_I2C_DRIVER
|
||||
ret = i2c_register(i2c, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
i2cerr("ERROR: Failed to register I2C0 driver: %d\n", ret);
|
||||
imx9_i2cbus_uninitialize(i2c);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
Reference in New Issue
Block a user