diff --git a/board/netmodule/imx8_nmhw23/Makefile b/board/netmodule/imx8_nmhw23/Makefile index 19b143802d..6f4b383fb2 100644 --- a/board/netmodule/imx8_nmhw23/Makefile +++ b/board/netmodule/imx8_nmhw23/Makefile @@ -9,3 +9,4 @@ obj-y += imx8_nmhw23.o obj-$(CONFIG_SPL_BUILD) += spl.o obj-y += ../nm-common/bdparser.o ../nm-common/board_descriptor.o +obj-y += ../nm-common/da9063.o diff --git a/board/netmodule/nm-common/da9063.c b/board/netmodule/nm-common/da9063.c index 69e2a1d0fd..14c9188e9a 100644 --- a/board/netmodule/nm-common/da9063.c +++ b/board/netmodule/nm-common/da9063.c @@ -3,7 +3,7 @@ * * Dialog DA9063 PMIC * - * Copyright (C) 2018-2019 NetModule AG - http://www.netmodule.com/ + * Copyright (C) 2021 NetModule AG - http://www.netmodule.com/ * * SPDX-License-Identifier: GPL-2.0+ */ @@ -13,82 +13,69 @@ #include #include "da9063.h" +#include "asm/mach-imx/sci/types.h" +#include "asm/mach-imx/sci/ipc.h" +#include "asm/mach-imx/sci/svc/misc/api.h" +#include "asm/arch-imx8/MX8_mu.h" +#define SCU_MU_ADDR 0x5D1C0000 -static int da9063_i2c_bus = 0; -static int bus_claimed = 0; +static sc_ipc_t ipc; +static bool initialized = false; - -static int switch_i2c_bus(void) +void da9063_init(void) { - int old_bus; - - old_bus = i2c_get_bus_num(); - if (old_bus != da9063_i2c_bus) { - i2c_set_bus_num(da9063_i2c_bus); + sc_err_t err = sc_ipc_open(&ipc, SCU_MU_ADDR); + if (err != SC_ERR_NONE) { + printf("Could not initialize IPC with SCU, err: %d\n", err); + return; } - - bus_claimed++; - - return old_bus; -} - -static void revert_i2c_bus(int bus) -{ - if (da9063_i2c_bus != bus) { - i2c_set_bus_num(bus); - } - - bus_claimed--; -} - - -void da9063_init(int i2c_bus) -{ - da9063_i2c_bus = i2c_bus; -} - -int da9063_claim_i2c_bus(void) -{ - return switch_i2c_bus(); -} - -void da9063_release_i2c_bus(int bus) -{ - revert_i2c_bus(bus); + initialized = true; } int da9063_get_reg(uint32_t reg, uint8_t* val) { - int ret; - uint8_t temp; + sc_err_t ret; + uint8_t read = 1; + uint32_t param1; + uint32_t data = 0; + uint32_t data_len = 1; /* Argument check */ if ((reg >= 0x200) || (val==0)) { return -1; } - /* State check. Has bus been claimed */ - if (bus_claimed == 0) { + /* State check. Is RPC initialized */ + if (!initialized) { return -2; } *val = 0; - if (reg < 0x100) { - ret = i2c_read(CONFIG_PMIC_I2C_ADDR+0, reg & 0xFF, 1, &temp, 1); - } else { - ret = i2c_read(CONFIG_PMIC_I2C_ADDR+1, reg & 0xFF, 1, &temp, 1); + if (reg < 0x100) + param1 = CONFIG_PMIC_I2C_ADDR | reg << 8 | read << 16; + else + param1 = (CONFIG_PMIC_I2C_ADDR + 1) | reg << 8 | read << 16; + + ret = sc_misc_board_ioctl(ipc, ¶m1, &data, &data_len); + + if (ret != SC_ERR_NONE) { + printf("IPC failed with error: %d\n", ret); + return -3; } - if (ret == 0) - *val = temp; - - return ret; + *val = data; + return 0; } int da9063_set_reg(uint32_t reg, uint8_t val) { - int ret; + sc_err_t ret; + uint8_t read = 0; + uint32_t param1 = CONFIG_PMIC_I2C_ADDR | reg << 8 | read << 16; + uint32_t data = val; + uint32_t data_len = 1; + /* Argument check */ if (reg >= 0x200) { @@ -96,45 +83,20 @@ int da9063_set_reg(uint32_t reg, uint8_t val) } /* State check. Has bus been claimed */ - if (bus_claimed == 0) { + if (!initialized) { return -2; } - if (reg < 0x100) { - ret = i2c_write(CONFIG_PMIC_I2C_ADDR+0, reg & 0xFF, 1, &val, 1); - } else { - ret = i2c_write(CONFIG_PMIC_I2C_ADDR+1, reg & 0xFF, 1, &val, 1); + if (reg < 0x100) + param1 = CONFIG_PMIC_I2C_ADDR | reg << 8 | read << 16; + else + param1 = (CONFIG_PMIC_I2C_ADDR + 1) | reg << 8 | read << 16; + + ret = sc_misc_board_ioctl(ipc, ¶m1, &data, &data_len); + + if (ret != SC_ERR_NONE) { + printf("IPC failed with error: %d\n", ret); + return -3; } - - if (ret != 0) - puts("da9063 write error\n"); - - return ret; + return 0; } - -void da9063_set_gpio(unsigned bit, int state) -{ - int pmic_reg; - int ret; - uint8_t bitmask; - uint8_t reg = 0x00; - - if (bit <= 7) { - pmic_reg = PMIC_REG_GPIO_MODE0_7; - bitmask = 1U << (bit-0); - } - else { - pmic_reg = PMIC_REG_GPIO_MODE8_15; - bitmask = 1U << (bit-8); - } - - ret = da9063_get_reg(pmic_reg, ®); - - if (ret == 0) { - if (state) reg |= bitmask; - else reg &= ~bitmask; - - (void)da9063_set_reg(pmic_reg, reg); - } -} - diff --git a/board/netmodule/nm-common/da9063.h b/board/netmodule/nm-common/da9063.h index dd922ef37c..b566ce0414 100644 --- a/board/netmodule/nm-common/da9063.h +++ b/board/netmodule/nm-common/da9063.h @@ -3,7 +3,7 @@ * * Dialog DA9063 PMIC * - * Copyright (C) 2018-2019 NetModule AG - http://www.netmodule.com/ + * Copyright (C) 2021 NetModule AG - http://www.netmodule.com/ * * SPDX-License-Identifier: GPL-2.0+ */ @@ -88,16 +88,10 @@ #define PMIC_REG_CONFIG_ID 0x184 /* OTP Config ID */ -extern void da9063_init(int i2c_bus); - -extern int da9063_claim_i2c_bus(void); -extern void da9063_release_i2c_bus(int bus); +extern void da9063_init(void); extern int da9063_get_reg(uint32_t reg, uint8_t* val); extern int da9063_set_reg(uint32_t reg, uint8_t val); -extern void da9063_set_gpio(unsigned bit, int state); - - #endif /* DA9063_H */