platform: add iot2050 platform support
This patch introuduce iot2050 platform support, it is the port from meta-iot2050 layer. Based on original patch by Le Jin. Signed-off-by: Le Jin <le.jin@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Ivan Mikhaylov <ivan.mikhaylov@siemens.com>
This commit is contained in:
committed by
Tom Ingleby
parent
0c44a7291b
commit
a9f0ff22e8
@@ -68,6 +68,7 @@ typedef enum {
|
|||||||
MRAA_ADLINK_LEC_AL_AI = 23, /**< Adlink LEC-AL*/
|
MRAA_ADLINK_LEC_AL_AI = 23, /**< Adlink LEC-AL*/
|
||||||
MRAA_UPXTREME = 24, /**< The UPXTREME Board */
|
MRAA_UPXTREME = 24, /**< The UPXTREME Board */
|
||||||
MRAA_INTEL_ILK = 25, /**< Intel Learning Kit */
|
MRAA_INTEL_ILK = 25, /**< Intel Learning Kit */
|
||||||
|
MRAA_SIEMENS_IOT2050 = 26, /**< Siemens IOT2050 board */
|
||||||
// USB platform extenders start at 256
|
// USB platform extenders start at 256
|
||||||
MRAA_FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
|
MRAA_FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ typedef enum {
|
|||||||
MTK_OMEGA2 = 18, /**< MT7688 based Onion Omega2 board */
|
MTK_OMEGA2 = 18, /**< MT7688 based Onion Omega2 board */
|
||||||
IEI_TANK = 19, /**< IEI Tank System*/
|
IEI_TANK = 19, /**< IEI Tank System*/
|
||||||
INTEL_UPXTREME = 24, /**< The UPXTREME Board */
|
INTEL_UPXTREME = 24, /**< The UPXTREME Board */
|
||||||
|
SIEMENS_IOT2050 = 26, /**< Siemens IOT2050 board */
|
||||||
|
|
||||||
FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
|
FTDI_FT4222 = 256, /**< FTDI FT4222 USB to i2c bridge */
|
||||||
|
|
||||||
|
|||||||
40
include/arm/siemens/iot2050.h
Normal file
40
include/arm/siemens/iot2050.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Author: Le Jin <le.jin@siemens.com>
|
||||||
|
* Copyright (c) Siemens AG, 2019
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "mraa_internal.h"
|
||||||
|
|
||||||
|
#define PLATFORM_NAME "SIMATIC IOT2050"
|
||||||
|
#define MRAA_IOT2050_PINCOUNT (20)
|
||||||
|
|
||||||
|
mraa_board_t *
|
||||||
|
mraa_siemens_iot2050();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
97
include/arm/siemens/platform.h
Normal file
97
include/arm/siemens/platform.h
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Author: Le Jin <le.jin@siemens.com>
|
||||||
|
* Copyright (c) Siemens AG, 2019
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef _PLATFORM_H_
|
||||||
|
#define _PLATFORM_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
typedef struct {
|
||||||
|
bool (*init)(void);
|
||||||
|
void (*deinit)(void);
|
||||||
|
void (*select_func)(uint8_t group, uint16_t pinIndex, uint8_t func);
|
||||||
|
void (*select_input)(uint8_t group, uint16_t pinIndex);
|
||||||
|
void (*select_output)(uint8_t group, uint16_t pinIndex);
|
||||||
|
void (*select_inout)(uint8_t group, uint16_t pinIndex);
|
||||||
|
void (*select_hiz)(uint8_t group, uint16_t pinIndex);
|
||||||
|
void (*select_pull_up)(uint8_t group, uint16_t pinIndex);
|
||||||
|
void (*select_pull_down)(uint8_t group, uint16_t pinIndex);
|
||||||
|
void (*select_pull_disable)(uint8_t group, uint16_t pinIndex);
|
||||||
|
uint32_t (*get_raw_reg_value)(uint8_t group, uint16_t pinIndex);
|
||||||
|
void (*set_raw_reg_value)(uint8_t group, uint16_t pinIndex, uint32_t value);
|
||||||
|
void (*dump_info)(uint8_t group, uint16_t pinIndex);
|
||||||
|
} pin_mux_ops_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
bool initialized;
|
||||||
|
pin_mux_ops_t ops;
|
||||||
|
} pin_mux_interface_t;
|
||||||
|
|
||||||
|
#define VOID_INTERFACE_CALL(instance, function) \
|
||||||
|
do {\
|
||||||
|
if((instance) && ((pin_mux_interface_t *)instance)->ops.function) \
|
||||||
|
((pin_mux_interface_t *)instance)->ops.function(); \
|
||||||
|
}while(0)
|
||||||
|
|
||||||
|
#define VOID_INTERFACE_CALL_WITH_ARGS(instance, function, ...) \
|
||||||
|
do {\
|
||||||
|
if((instance) && ((pin_mux_interface_t *)instance)->ops.function) \
|
||||||
|
((pin_mux_interface_t *)instance)->ops.function(__VA_ARGS__); \
|
||||||
|
}while(0)
|
||||||
|
|
||||||
|
#define INTERFACE_CALL_WITH_ARGS(instance, retType, defaultRetValue, function, ...) \
|
||||||
|
( \
|
||||||
|
{ \
|
||||||
|
retType ret = defaultRetValue; \
|
||||||
|
if((instance) && ((pin_mux_interface_t *)instance)->ops.function) \
|
||||||
|
ret = ((pin_mux_interface_t *)instance)->ops.function(__VA_ARGS__); \
|
||||||
|
ret; \
|
||||||
|
} \
|
||||||
|
)
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define DEBUG_PRINT(...) do{}while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *platfrom_pinmux_get_instance(char *platform);
|
||||||
|
#define platform_pinmux_release_instance(instance) VOID_INTERFACE_CALL(instance, deinit)
|
||||||
|
#define platform_pinmux_select_func(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_func, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_select_input(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_input, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_select_output(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_output, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_select_inout(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_inout, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_select_hiz(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_hiz, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_select_pull_up(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_pull_up, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_select_pull_down(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_pull_down, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_select_pull_disable(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, select_pull_disable, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_get_raw_reg_value(instance, ...) INTERFACE_CALL_WITH_ARGS(instance, uint32_t, -1, get_raw_reg_value, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_set_raw_reg_value(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, set_raw_reg_value, __VA_ARGS__)
|
||||||
|
#define platform_pinmux_dump_info(instance, ...) VOID_INTERFACE_CALL_WITH_ARGS(instance, dump_info, __VA_ARGS__)
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
34
include/arm/siemens/platform_iot2050.h
Normal file
34
include/arm/siemens/platform_iot2050.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Author: Le Jin <le.jin@siemens.com>
|
||||||
|
* Copyright (c) Siemens AG, 2019
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#ifndef _PLATFORM_IOT2050_H_
|
||||||
|
#define _PLATFORM_IOT2050_H_
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
#include "arm/siemens/platform.h"
|
||||||
|
pin_mux_interface_t *iot2050_pinmux_get_instance(void);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -109,6 +109,9 @@ set (mraa_LIB_ARM_SRCS_NOAUTO
|
|||||||
${PROJECT_SOURCE_DIR}/src/arm/de_nano_soc.c
|
${PROJECT_SOURCE_DIR}/src/arm/de_nano_soc.c
|
||||||
${PROJECT_SOURCE_DIR}/src/arm/rockpi4.c
|
${PROJECT_SOURCE_DIR}/src/arm/rockpi4.c
|
||||||
${PROJECT_SOURCE_DIR}/src/arm/adlink_ipi.c
|
${PROJECT_SOURCE_DIR}/src/arm/adlink_ipi.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/arm/siemens/iot2050.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/arm/siemens/platform.c
|
||||||
|
${PROJECT_SOURCE_DIR}/src/arm/siemens/platform_iot2050.c
|
||||||
)
|
)
|
||||||
|
|
||||||
set (mraa_LIB_MIPS_SRCS_NOAUTO
|
set (mraa_LIB_MIPS_SRCS_NOAUTO
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "arm/phyboard.h"
|
#include "arm/phyboard.h"
|
||||||
#include "arm/raspberry_pi.h"
|
#include "arm/raspberry_pi.h"
|
||||||
#include "arm/adlink_ipi.h"
|
#include "arm/adlink_ipi.h"
|
||||||
|
#include "arm/siemens/iot2050.h"
|
||||||
#include "mraa_internal.h"
|
#include "mraa_internal.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -98,6 +99,8 @@ mraa_arm_platform()
|
|||||||
platform_type = MRAA_RASPBERRY_PI;
|
platform_type = MRAA_RASPBERRY_PI;
|
||||||
else if (mraa_file_contains("/proc/device-tree/model", "ADLINK ARM, LEC-PX30"))
|
else if (mraa_file_contains("/proc/device-tree/model", "ADLINK ARM, LEC-PX30"))
|
||||||
platform_type = MRAA_ADLINK_IPI;
|
platform_type = MRAA_ADLINK_IPI;
|
||||||
|
else if (mraa_file_contains("/proc/device-tree/model", "SIMATIC IOT2050"))
|
||||||
|
platform_type = MRAA_SIEMENS_IOT2050;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (platform_type) {
|
switch (platform_type) {
|
||||||
@@ -124,6 +127,8 @@ mraa_arm_platform()
|
|||||||
break;
|
break;
|
||||||
case MRAA_ADLINK_IPI:
|
case MRAA_ADLINK_IPI:
|
||||||
plat = mraa_adlink_ipi();
|
plat = mraa_adlink_ipi();
|
||||||
|
case MRAA_SIEMENS_IOT2050:
|
||||||
|
plat = mraa_siemens_iot2050();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
plat = NULL;
|
plat = NULL;
|
||||||
|
|||||||
1237
src/arm/siemens/iot2050.c
Normal file
1237
src/arm/siemens/iot2050.c
Normal file
File diff suppressed because it is too large
Load Diff
41
src/arm/siemens/platform.c
Normal file
41
src/arm/siemens/platform.c
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Author: Le Jin <le.jin@siemens.com>
|
||||||
|
* Copyright (c) Siemens AG, 2019
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include <string.h>
|
||||||
|
#include "arm/siemens/platform.h"
|
||||||
|
#include "arm/siemens/platform_iot2050.h"
|
||||||
|
|
||||||
|
void *
|
||||||
|
platfrom_pinmux_get_instance(char *platform)
|
||||||
|
{
|
||||||
|
pin_mux_interface_t *instance = NULL;
|
||||||
|
if(!strcmp(platform, "iot2050")) {
|
||||||
|
instance = iot2050_pinmux_get_instance();
|
||||||
|
}
|
||||||
|
if((instance) && (instance->initialized == false) && (instance->ops.init)) {
|
||||||
|
return instance->ops.init()?instance:NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
367
src/arm/siemens/platform_iot2050.c
Normal file
367
src/arm/siemens/platform_iot2050.c
Normal file
@@ -0,0 +1,367 @@
|
|||||||
|
/*
|
||||||
|
* Author: Le Jin <le.jin@siemens.com>
|
||||||
|
* Copyright (c) Siemens AG, 2019
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include "arm/siemens/platform_iot2050.h"
|
||||||
|
|
||||||
|
enum{
|
||||||
|
GROUP_MAIN_DOMAIN = 0,
|
||||||
|
GROUP_WAKUP_DOMAIN,
|
||||||
|
MAX_GROUP_NUMBER
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
pin_mux_interface_t super;
|
||||||
|
int mem_fd;
|
||||||
|
volatile uint32_t *pin_mux_reg_base[MAX_GROUP_NUMBER];
|
||||||
|
volatile void *map_address[MAX_GROUP_NUMBER];
|
||||||
|
} iot2050_pin_mux_handler_t;
|
||||||
|
|
||||||
|
static bool iot2050_pinmux_init(void);
|
||||||
|
static void iot2050_pinmux_deinit(void);
|
||||||
|
static void iot2050_pinmux_select_func(uint8_t group, uint16_t pin_index, uint8_t func);
|
||||||
|
static void iot2050_pinmux_select_input(uint8_t group, uint16_t pin_index);
|
||||||
|
static void iot2050_pinmux_select_output(uint8_t group, uint16_t pin_index);
|
||||||
|
static void iot2050_pinmux_select_inout(uint8_t group, uint16_t pin_index);
|
||||||
|
static void iot2050_pinmux_select_hiz(uint8_t group, uint16_t pin_index);
|
||||||
|
static void iot2050_pinmux_select_pull_up(uint8_t group, uint16_t pin_index);
|
||||||
|
static void iot2050_pinmux_select_pull_down(uint8_t group, uint16_t pin_index);
|
||||||
|
static void iot2050_pinmux_select_pull_disable(uint8_t group, uint16_t pin_index);
|
||||||
|
static uint32_t iot2050_pinmux_get_raw_reg_value(uint8_t group, uint16_t pin_index);
|
||||||
|
static void iot2050_pinmux_set_raw_reg_value(uint8_t group, uint16_t pin_index, uint32_t value);
|
||||||
|
static void iot2050_pinmux_dump_info(uint8_t group, uint16_t pin_index);
|
||||||
|
|
||||||
|
#define MAIN_PINMUX_REG_NUM (195)
|
||||||
|
#define MAIN_PINMUX_REG_LENGTH (MAIN_PINMUX_REG_NUM<<2)
|
||||||
|
#define MAIN_PINMUX_REG_PHY_BASE_ADDRESS (0x0011c000)
|
||||||
|
|
||||||
|
#define WAKUP_PINMUX_REG_NUM (70)
|
||||||
|
#define WAKUP_PINMUX_REG_LENGTH (WAKUP_PINMUX_REG_NUM<<2)
|
||||||
|
#define WAKUP_PINMUX_REG_PHY_BASE_ADDRESS (0x4301c000)
|
||||||
|
|
||||||
|
#define PAGE_SIZE 4096UL
|
||||||
|
#define PAGE_MASK (PAGE_SIZE - 1)
|
||||||
|
|
||||||
|
#define REG_MUXMODE_POS (0)
|
||||||
|
#define REG_MUXMODE_MASK (0x0F << REG_MUXMODE_POS)
|
||||||
|
#define REG_MUXMODE_GET(reg) ((reg & REG_MUXMODE_MASK) >> REG_MUXMODE_POS)
|
||||||
|
#define REG_MUXMODE(mode) ((mode << REG_MUXMODE_POS) & REG_MUXMODE_MASK)
|
||||||
|
|
||||||
|
#define REG_PULL_ENABLE_POS (16)
|
||||||
|
#define REG_PULL_ENABLE_MASK (0x01 << REG_PULL_ENABLE_POS)
|
||||||
|
#define REG_PULL_ENABLE_GET(reg) ((reg & REG_PULL_ENABLE_MASK) >> REG_PULL_ENABLE_POS)
|
||||||
|
#define REG_PULL_ENABLE (0x00 << REG_PULL_ENABLE_POS)
|
||||||
|
#define REG_PULL_DISABLE (0x01 << REG_PULL_ENABLE_POS)
|
||||||
|
#define REG_PULL_IS_ENABLED(reg) (!REG_PULL_ENABLE_GET(reg))
|
||||||
|
#define REG_PULL_IS_DISABLED(reg) (!REG_PULL_IS_ENABLED(reg))
|
||||||
|
|
||||||
|
#define REG_PULL_SELECT_POS (17)
|
||||||
|
#define REG_PULL_SELECT_MASK (0x01 << REG_PULL_SELECT_POS)
|
||||||
|
#define REG_PULL_SELECT_GET(reg) ((reg & REG_PULL_SELECT_MASK) >> REG_PULL_SELECT_POS)
|
||||||
|
#define REG_PULL_UP (0x01 << REG_PULL_SELECT_POS)
|
||||||
|
#define REG_PULL_DOWN (0x00 << REG_PULL_SELECT_POS)
|
||||||
|
#define REG_PULL_IS_UP(reg) (REG_PULL_SELECT_GET(reg))
|
||||||
|
#define REG_PULL_IS_DOWN(reg) (!REG_PULL_IS_UP(reg))
|
||||||
|
|
||||||
|
#define REG_INPUT_ENABLE_POS (18)
|
||||||
|
#define REG_INPUT_ENABLE_MASK (0x01 << REG_INPUT_ENABLE_POS)
|
||||||
|
#define REG_INPUT_ENABLE_GET(reg) ((reg & REG_INPUT_ENABLE_MASK) >> REG_INPUT_ENABLE_POS)
|
||||||
|
#define REG_INPUT_ENABLE (0x01 << REG_INPUT_ENABLE_POS)
|
||||||
|
#define REG_INPUT_DISABLE (0x00 << REG_INPUT_ENABLE_POS)
|
||||||
|
#define REG_INPUT_IS_ENABLED(reg) (REG_INPUT_ENABLE_GET(reg))
|
||||||
|
#define REG_INPUT_IS_DISABLED(reg) (!REG_INPUT_IS_ENABLED(reg))
|
||||||
|
|
||||||
|
#define REG_OUTPUT_ENABLE_POS (21)
|
||||||
|
#define REG_OUTPUT_ENABLE_MASK (0x01 << REG_OUTPUT_ENABLE_POS)
|
||||||
|
#define REG_OUTPUT_ENABLE_GET(reg) ((reg & REG_OUTPUT_ENABLE_MASK) >> REG_OUTPUT_ENABLE_POS)
|
||||||
|
#define REG_OUTPUT_ENABLE (0x00 << REG_OUTPUT_ENABLE_POS)
|
||||||
|
#define REG_OUTPUT_DISABLE (0x01 << REG_OUTPUT_ENABLE_POS)
|
||||||
|
#define REG_OUTPUT_IS_ENABLED(reg) (!REG_OUTPUT_ENABLE_GET(reg))
|
||||||
|
#define REG_OUTPUT_IS_DISABLED(reg) (!REG_OUTPUT_IS_ENABLED(reg))
|
||||||
|
|
||||||
|
#define REG_UPDATE(address, mask, value) (*address = ((*address) & (~mask)) | (value))
|
||||||
|
#define GROUP_IS_VALID(group) (group < MAX_GROUP_NUMBER)
|
||||||
|
|
||||||
|
#define PIN_OUTPUT (PULL_DISABLE)
|
||||||
|
#define PIN_OUTPUT_PULLUP (PULL_UP)
|
||||||
|
#define PIN_OUTPUT_PULLDOWN 0
|
||||||
|
#define PIN_INPUT (INPUT_EN | PULL_DISABLE)
|
||||||
|
#define PIN_INPUT_PULLUP (INPUT_EN | PULL_UP)
|
||||||
|
#define PIN_INPUT_PULLDOWN (INPUT_EN)
|
||||||
|
|
||||||
|
static iot2050_pin_mux_handler_t iot2050_pin_mux_handler = {
|
||||||
|
.super = {
|
||||||
|
.initialized = false,
|
||||||
|
.ops = {
|
||||||
|
.init = iot2050_pinmux_init,
|
||||||
|
.deinit = iot2050_pinmux_deinit,
|
||||||
|
.select_func = iot2050_pinmux_select_func,
|
||||||
|
.select_input = iot2050_pinmux_select_input,
|
||||||
|
.select_output = iot2050_pinmux_select_output,
|
||||||
|
.select_inout = iot2050_pinmux_select_inout,
|
||||||
|
.select_hiz = iot2050_pinmux_select_hiz,
|
||||||
|
.select_pull_up = iot2050_pinmux_select_pull_up,
|
||||||
|
.select_pull_down = iot2050_pinmux_select_pull_down,
|
||||||
|
.select_pull_disable = iot2050_pinmux_select_pull_disable,
|
||||||
|
.get_raw_reg_value = iot2050_pinmux_get_raw_reg_value,
|
||||||
|
.set_raw_reg_value = iot2050_pinmux_set_raw_reg_value,
|
||||||
|
.dump_info = iot2050_pinmux_dump_info
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.mem_fd = -1,
|
||||||
|
.map_address[GROUP_MAIN_DOMAIN] = MAP_FAILED,
|
||||||
|
.map_address[GROUP_WAKUP_DOMAIN] = MAP_FAILED,
|
||||||
|
.pin_mux_reg_base[GROUP_MAIN_DOMAIN] = MAP_FAILED,
|
||||||
|
.pin_mux_reg_base[GROUP_WAKUP_DOMAIN] = MAP_FAILED
|
||||||
|
};
|
||||||
|
|
||||||
|
pin_mux_interface_t*
|
||||||
|
iot2050_pinmux_get_instance(void)
|
||||||
|
{
|
||||||
|
return (pin_mux_interface_t *)&iot2050_pin_mux_handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
iot2050_pinmux_init(void)
|
||||||
|
{
|
||||||
|
uint32_t pageMask = sysconf(_SC_PAGE_SIZE) - 1;
|
||||||
|
|
||||||
|
/* Open memory */
|
||||||
|
DEBUG_PRINT("Open device\n");
|
||||||
|
if((iot2050_pin_mux_handler.mem_fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) {
|
||||||
|
DEBUG_PRINT("Open device: %s\n", strerror(errno));
|
||||||
|
goto _FATAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Map */
|
||||||
|
DEBUG_PRINT("Map main mux register base\n");
|
||||||
|
iot2050_pin_mux_handler.map_address[GROUP_MAIN_DOMAIN] = mmap(0, MAIN_PINMUX_REG_LENGTH,
|
||||||
|
PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||||
|
iot2050_pin_mux_handler.mem_fd,
|
||||||
|
MAIN_PINMUX_REG_PHY_BASE_ADDRESS & ~pageMask);
|
||||||
|
if(iot2050_pin_mux_handler.map_address[GROUP_MAIN_DOMAIN] == MAP_FAILED) {
|
||||||
|
DEBUG_PRINT("Pinmux main domain map failed: %s\n", strerror(errno));
|
||||||
|
goto _FATAL;
|
||||||
|
}
|
||||||
|
iot2050_pin_mux_handler.pin_mux_reg_base[GROUP_MAIN_DOMAIN] = iot2050_pin_mux_handler.map_address[GROUP_MAIN_DOMAIN] +
|
||||||
|
(MAIN_PINMUX_REG_PHY_BASE_ADDRESS & pageMask);
|
||||||
|
DEBUG_PRINT("\tPage address: %p\n", iot2050_pin_mux_handler.map_address[GROUP_MAIN_DOMAIN]);
|
||||||
|
DEBUG_PRINT("\tIn-page Offset: %x\n", MAIN_PINMUX_REG_PHY_BASE_ADDRESS & pageMask);
|
||||||
|
DEBUG_PRINT("\tReg address: %p\n", iot2050_pin_mux_handler.pin_mux_reg_base[GROUP_MAIN_DOMAIN]);
|
||||||
|
DEBUG_PRINT("Map wakup mux register base\n");
|
||||||
|
iot2050_pin_mux_handler.map_address[GROUP_WAKUP_DOMAIN] = mmap(0, WAKUP_PINMUX_REG_LENGTH,
|
||||||
|
PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||||
|
iot2050_pin_mux_handler.mem_fd,
|
||||||
|
WAKUP_PINMUX_REG_PHY_BASE_ADDRESS & ~pageMask);
|
||||||
|
if(iot2050_pin_mux_handler.map_address[GROUP_WAKUP_DOMAIN] == MAP_FAILED) {
|
||||||
|
DEBUG_PRINT("Pinmux wakup domain map failed: %s\n", strerror(errno));
|
||||||
|
goto _FATAL;
|
||||||
|
}
|
||||||
|
iot2050_pin_mux_handler.pin_mux_reg_base[GROUP_WAKUP_DOMAIN] = iot2050_pin_mux_handler.map_address[GROUP_WAKUP_DOMAIN] +
|
||||||
|
(WAKUP_PINMUX_REG_PHY_BASE_ADDRESS & pageMask);
|
||||||
|
DEBUG_PRINT("\tPage address: %p\n", iot2050_pin_mux_handler.map_address[GROUP_WAKUP_DOMAIN]);
|
||||||
|
DEBUG_PRINT("\tIn-page Offset: %x\n", WAKUP_PINMUX_REG_PHY_BASE_ADDRESS & pageMask);
|
||||||
|
DEBUG_PRINT("\tReg address: %p\n", iot2050_pin_mux_handler.pin_mux_reg_base[GROUP_WAKUP_DOMAIN]);
|
||||||
|
iot2050_pin_mux_handler.super.initialized = true;
|
||||||
|
return true;
|
||||||
|
_FATAL:
|
||||||
|
iot2050_pinmux_deinit();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_deinit(void)
|
||||||
|
{
|
||||||
|
if(iot2050_pin_mux_handler.mem_fd > 0)
|
||||||
|
close(iot2050_pin_mux_handler.mem_fd);
|
||||||
|
iot2050_pin_mux_handler.mem_fd = -1;
|
||||||
|
if(iot2050_pin_mux_handler.map_address[GROUP_MAIN_DOMAIN] != MAP_FAILED)
|
||||||
|
munmap((void *)iot2050_pin_mux_handler.map_address[GROUP_MAIN_DOMAIN], MAIN_PINMUX_REG_LENGTH);
|
||||||
|
iot2050_pin_mux_handler.map_address[GROUP_MAIN_DOMAIN] = MAP_FAILED;
|
||||||
|
iot2050_pin_mux_handler.pin_mux_reg_base[GROUP_MAIN_DOMAIN] = MAP_FAILED;
|
||||||
|
|
||||||
|
if(iot2050_pin_mux_handler.map_address[GROUP_WAKUP_DOMAIN] != MAP_FAILED)
|
||||||
|
munmap((void *)iot2050_pin_mux_handler.map_address[GROUP_WAKUP_DOMAIN], WAKUP_PINMUX_REG_LENGTH);
|
||||||
|
iot2050_pin_mux_handler.map_address[GROUP_WAKUP_DOMAIN] = MAP_FAILED;
|
||||||
|
iot2050_pin_mux_handler.pin_mux_reg_base[GROUP_WAKUP_DOMAIN] = MAP_FAILED;
|
||||||
|
iot2050_pin_mux_handler.super.initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_func(uint8_t group, uint16_t pin_index, uint8_t func) {
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_MUXMODE_MASK, REG_MUXMODE(func));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_input(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_INPUT_ENABLE_MASK, REG_INPUT_ENABLE);
|
||||||
|
REG_UPDATE(reg, REG_OUTPUT_ENABLE_MASK, REG_OUTPUT_DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_output(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_INPUT_ENABLE_MASK, REG_INPUT_DISABLE);
|
||||||
|
REG_UPDATE(reg, REG_OUTPUT_ENABLE_MASK, REG_OUTPUT_ENABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_inout(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_INPUT_ENABLE_MASK, REG_INPUT_ENABLE);
|
||||||
|
REG_UPDATE(reg, REG_OUTPUT_ENABLE_MASK, REG_OUTPUT_ENABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_hiz(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_INPUT_ENABLE_MASK, REG_INPUT_DISABLE);
|
||||||
|
REG_UPDATE(reg, REG_OUTPUT_ENABLE_MASK, REG_OUTPUT_DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_pull_up(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_PULL_ENABLE_MASK, REG_PULL_ENABLE);
|
||||||
|
REG_UPDATE(reg, REG_PULL_SELECT_MASK, REG_PULL_UP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_pull_down(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_PULL_ENABLE_MASK, REG_PULL_ENABLE);
|
||||||
|
REG_UPDATE(reg, REG_PULL_SELECT_MASK, REG_PULL_DOWN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_select_pull_disable(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
REG_UPDATE(reg, REG_PULL_ENABLE_MASK, REG_PULL_DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t
|
||||||
|
iot2050_pinmux_get_raw_reg_value(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
return *reg;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_set_raw_reg_value(uint8_t group, uint16_t pin_index, uint32_t value)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
*reg = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
iot2050_pinmux_dump_info(uint8_t group, uint16_t pin_index)
|
||||||
|
{
|
||||||
|
volatile uint32_t *reg;
|
||||||
|
|
||||||
|
if(GROUP_IS_VALID(group)) {
|
||||||
|
reg = iot2050_pin_mux_handler.pin_mux_reg_base[group] + pin_index;
|
||||||
|
fprintf(stderr, "PinmuxReg Domain %s, Index %d, Raw 0x%08x\n",
|
||||||
|
group?"Wakup":"Main",
|
||||||
|
pin_index,
|
||||||
|
iot2050_pinmux_get_raw_reg_value(group, pin_index));
|
||||||
|
if(REG_INPUT_IS_ENABLED(*reg)) {
|
||||||
|
fprintf(stderr, "\tInput: enabled\n");
|
||||||
|
}
|
||||||
|
else if(REG_OUTPUT_IS_ENABLED(*reg)) {
|
||||||
|
fprintf(stderr, "\tOutput: enabled\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "\tOutput: Hiz\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(REG_PULL_IS_ENABLED(*reg)) {
|
||||||
|
if(REG_PULL_IS_UP(*reg)) {
|
||||||
|
fprintf(stderr, "\tPull Status: up\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "\tPull Status: down\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fprintf(stderr, "\tPull Status: disabled\n");
|
||||||
|
}
|
||||||
|
fprintf(stderr, "\tMode: %d\n", REG_MUXMODE_GET(*reg));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user