Merged in alinjerpelea/nuttx (pull request #915)

arch: arm: cxd56xx: I2C, SPISD, Charger and Gauge

* arch: arm: cxd56xx: add I2C character driver

    for testing purposes, we use the CXD56_I2C_DRIVER to register the
    /dev/i2c[] character devices.

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* configs: spresense: use I2C character driver

    We should use the CXD56_I2C_DRIVER to register the /dev/i2c[]
    character devices.

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* arch: arm: cxd56xx: add battery gauge driver

    add battery gauge driver for cxd56xx chip

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* arch: arm: cxd56xx: add charger driver

    add charger driver for cxd56xx chip

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* arch:arm: cxd56xx: add SPI SDCard configuration

    Add SPI SDCARD functionality configuration

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* configs: spresense: enable gauge driver

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

* configs: spresense: enable charger driver

    enable charger driver on spresense board

    Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Alin Jerpelea 2019-06-25 12:06:47 +00:00 committed by Gregory Nutt
parent aa7a6825d0
commit bfda93d66b
16 changed files with 1817 additions and 8 deletions

View File

@ -0,0 +1,115 @@
/****************************************************************************
* include/arch/chip/battery_ioctl.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_ARCH_CHIP_BATTERY_IOCTL_H
#define __INCLUDE_ARCH_CHIP_BATTERY_IOCTL_H
#include <nuttx/fs/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* ioctl commands */
#define BATIOC_GET_CHGVOLTAGE _BATIOC(0x0010)
#define BATIOC_GET_CHGCURRENT _BATIOC(0x0012)
#define BATIOC_GET_RECHARGEVOL _BATIOC(0x0013)
#define BATIOC_SET_RECHARGEVOL _BATIOC(0x0014)
#define BATIOC_GET_COMPCURRENT _BATIOC(0x0015)
#define BATIOC_SET_COMPCURRENT _BATIOC(0x0016)
#define BATIOC_GET_TEMPTABLE _BATIOC(0x0017)
#define BATIOC_SET_TEMPTABLE _BATIOC(0x0018)
#define BATIOC_GET_CURRENT _BATIOC(0x0019)
#define BATIOC_GET_VOLTAGE _BATIOC(0x001a)
#define BATIOC_MONITOR_ENABLE _BATIOC(0x0030)
#define BATIOC_MONITOR_STATUS _BATIOC(0x0031)
#define BATIOC_MONITOR_SET _BATIOC(0x0032)
#define BATIOC_MONITOR_GET _BATIOC(0x0033)
#define BATIOC_DEBUG _BATIOC(0x00db)
/****************************************************************************
* Public Types
****************************************************************************/
struct battery_temp_table_s
{
int T60; /* 60 degree C */
int T45; /* 45 degree C */
int T10; /* 10 degree C */
int T00; /* 0 degree C */
};
struct bat_monitor_enable_s
{
int on;
int interval;
int threshold_volt;
int threshold_current;
};
struct bat_monitor_status_s
{
int run;
int index;
int latest;
int totalwatt;
int totaltime;
};
struct bat_monitor_set_s
{
int clearbuf;
int clearsum;
};
struct bat_monitor_rec_s
{
uint16_t index;
uint16_t timestamp;
uint16_t voltage;
int16_t current;
};
struct bat_monitor_log_s
{
FAR struct bat_monitor_rec_s *rec;
int index;
int size;
};
#endif /* __INCLUDE_ARCH_CHIP_BATTERY_IOCTL_H */

View File

@ -152,6 +152,7 @@ comment "Power Management Options"
menuconfig CXD56_PM
bool "Power Management"
default y
select POWER
if CXD56_PM
@ -161,6 +162,49 @@ config CXD56_PM_PROCFS
---help---
Enable the power domain status or the clock frequency monitor.
config CXD56_GAUGE
bool "CXD5247 battery gauge"
default n
select BATTERY_GAUGE
---help---
Enable battery gauge driver.
This is not a lower half of power driver, but compatible with NuttX gauge driver.
if CXD56_GAUGE
config CXD56_GAUGE_DEBUG
bool "Battery Gauge Debug"
default n
---help---
Enable battery driver debug messages and debug IO command.
endif
config CXD56_CHARGER
bool "CXD5247 battery charger"
default n
select BATTERY_CHARGER
---help---
Enable battery charger driver.
This is not a lower half of power driver, but compatible with NuttX charger driver.
if CXD56_CHARGER
config CXD56_CHARGER_TEMP_PRECISE
bool "Precise Temperature"
default y
---help---
Get temperature precisely. If this option is enabled, driver calculate precisely
from register value to degrees Celsius.
This option requires libm.
config CXD56_CHARGER_DEBUG
bool "Battery Charger Debug"
default n
---help---
Enable battery charger driver debug messages.
endif
endif # CXD56_PM
comment "Peripheral Support"
@ -396,6 +440,15 @@ endif # CXD56_I2C1
config CXD56_I2C2
bool "I2C2"
config CXD56_I2C_DRIVER
bool "I2C character driver"
default n
select I2C_DRIVER
---help---
Build in support for a character driver at /dev/i2c[N] that may be
used to perform I2C bus transfers from applications. The intent of
this driver is to support I2C testing. It is not suitable for use
in any real driver application.
endif
config CXD56_USBDEV
@ -1097,5 +1150,21 @@ config CXD56_SDIO_ENABLE_MULTIFUNCTION
Support multi-function with SDIO interfaced peripheral other than SD Card.
endif # SDIO Configuration
menuconfig CXD56_SPISD
bool "SPI SD Card"
default n
select MMCSD_SPI
if CXD56_SPISD
config CXD56_SPISD_SLOT_NO
int "SPI SD Card Slot Number"
default 0
---help---
Select spi sd card slot number.
endif # SPISD Configuration
endmenu
endmenu

View File

@ -144,6 +144,14 @@ ifeq ($(CONFIG_CXD56_PWM),y)
CHIP_CSRCS += cxd56_pwm.c
endif
ifeq ($(CONFIG_CXD56_GAUGE),y)
CHIP_CSRCS += cxd56_gauge.c
endif
ifeq ($(CONFIG_CXD56_CHARGER),y)
CHIP_CSRCS += cxd56_charger.c
endif
ifeq ($(CONFIG_CXD56_SCU),y)
CHIP_CSRCS += cxd56_scu.c cxd56_scufifo.c
ifeq ($(CONFIG_CXD56_ADC),y)
@ -154,7 +162,6 @@ CHIP_CSRCS += cxd56_udmac.c
endif
endif
ifeq ($(CONFIG_CXD56_TIMER),y)
CHIP_CSRCS += cxd56_timer.c
endif

View File

@ -0,0 +1,688 @@
/****************************************************************************
* arch/arm/src/cxd56xx/cxd56_charger.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* CXD5247GF is Li-Ion Battery Charger with Power-Path Management.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <debug.h>
#include <math.h>
#include <nuttx/kmalloc.h>
#include <nuttx/power/battery_charger.h>
#include <nuttx/power/battery_ioctl.h>
#include <arch/chip/battery_ioctl.h>
#include "cxd56_pmic.h"
#ifdef CONFIG_CXD56_CHARGER
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Debug ********************************************************************/
#ifdef CONFIG_CXD56_CHARGER_DEBUG
#define baterr(fmt, ...) logerr(fmt, ## __VA_ARGS__)
#define batdbg(fmt, ...) logdebug(fmt, ## __VA_ARGS__)
#else
#define baterr(fmt, ...)
#define batdbg(fmt, ...)
#endif
/* Configuration */
#undef USE_FLOAT_CONVERSION
#ifdef CONFIG_CXD56_CHARGER_TEMP_PRECISE
#if !defined(CONFIG_LIBM) && !defined(CONFIG_LIBM_NEWLIB)
# error Temperature conversion in float requires math library.
#endif
#define USE_FLOAT_CONVERSION 1
#endif
/****************************************************************************
* Private Types
****************************************************************************/
struct charger_dev_s
{
sem_t batsem;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static int charger_get_status(FAR enum battery_charger_status_e *status);
static int charger_get_health(FAR enum battery_charger_health_e *health);
static int charger_online(FAR bool *online);
static int charger_get_temptable(FAR struct battery_temp_table_s *table);
static int charger_set_temptable(FAR struct battery_temp_table_s *table);
static int charger_open(FAR struct file *filep);
static int charger_close(FAR struct file *filep);
static ssize_t charger_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t charger_write(FAR struct file *filep,
FAR const char *buffer, size_t buflen);
static int charger_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
/****************************************************************************
* Private Data
****************************************************************************/
static const struct file_operations g_chargerops =
{
charger_open, /* open */
charger_close, /* close */
charger_read, /* read */
charger_write, /* write */
0, /* seek */
charger_ioctl /* ioctl */
#ifndef CONFIG_DISABLE_POLL
, NULL /* poll */
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
, NULL /* unlink */
#endif
};
static struct charger_dev_s g_chargerdev;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: charger_therm2temp
*
* Description:
* Convert temperature register value to degrees Celsius.
*
****************************************************************************/
static int charger_therm2temp(int val)
{
#ifdef USE_FLOAT_CONVERSION
float f1;
float f2;
float f3;
float f4;
float f5;
float f6;
f1 = (float)val;
f2 = f1 / 4096.f;
f3 = f2 * 100.f / (1.f - f2);
f4 = f3 / 100.f;
f5 = logf(f4);
f6 = 1.f / (f5 / 4250.f + 1.f / 298.f) - 273.f;
return (int)f6;
#else
static short T[29] = /* -40,-35,..-20,-15,..,95,100 */
{ 4020, 3986, 3939, 3877, 3759, 3691, 3562, 3405, 3222, 3015, /* -40,.. */
2787, 2545, 2296, 2048, 1808, 1582, 1374, 1186, 1020, 874, /* 10,.. */
747, 639 , 546, 467, 400, 343, 295, 254, 220
}; /* 60,..,100 */
int i;
int t0 = -45;
int t1 = -40;
int tt = -45;
for (i = 0; i < 29; i++)
{
if (val > T[i])
{
break;
}
t0 += 5;
t1 += 5;
}
if (i > 0)
{
int diff = T[i - 1] - T[i];
tt = t1 - (val - T[i]) * 5 / diff; /* interpolation : not accurate */
}
return tt;
#endif
}
/****************************************************************************
* Name: charger_get_status
****************************************************************************/
static int charger_get_status(FAR enum battery_charger_status_e *status)
{
uint8_t state;
int ret;
if (status == NULL)
{
return -EINVAL;
}
*status = BATTERY_UNKNOWN;
ret = cxd56_pmic_getchargestate(&state);
if (ret < 0)
{
return -EIO;
}
switch (state)
{
/* Is there some fault in the battery? */
case PMIC_STAT_BAT_UNUSUAL:
*status = BATTERY_FAULT;
break;
/* Is the charging done? */
case PMIC_STAT_CHG_COMPLETE:
*status = BATTERY_FULL;
break;
/* Is the charging in progress? */
case PMIC_STAT_GB_QCKCHARGE:
case PMIC_STAT_GB_LOWCHARGE:
case PMIC_STAT_GB_HIGHCHARGE:
*status = BATTERY_CHARGING;
break;
/* Is the charging ready? */
case PMIC_STAT_CHG_STOP:
*status = BATTERY_DISCHARGING;
break;
default:
_info("Charge state %d\n", state);
*status = BATTERY_IDLE;
break;
}
return OK;
}
/****************************************************************************
* Name: charger_get_health
****************************************************************************/
static int charger_get_health(FAR enum battery_charger_health_e *health)
{
FAR struct pmic_gauge_s gauge;
uint8_t state;
int temp;
int ret;
if (health == NULL)
{
return -EINVAL;
}
*health = BATTERY_HEALTH_UNKNOWN;
ret = cxd56_pmic_get_gauge(&gauge);
if (ret < 0)
{
return -EIO;
}
ret = cxd56_pmic_getchargestate(&state);
if (ret < 0)
{
return -EIO;
}
/* Convert register value to degrees Celsius */
temp = charger_therm2temp(gauge.temp);
if (temp < 10)
{
*health = BATTERY_HEALTH_COLD;
}
else if (temp > 60)
{
*health = BATTERY_HEALTH_OVERHEAT;
}
else
{
*health = BATTERY_HEALTH_GOOD;
}
return OK;
}
/****************************************************************************
* Name: charger_online
****************************************************************************/
static int charger_online(FAR bool *online)
{
if (online == NULL)
{
return -EINVAL;
}
*online = true;
return OK;
}
/****************************************************************************
* Name: charger_get_current
****************************************************************************/
static int charger_get_current(FAR int *current)
{
FAR struct pmic_gauge_s gauge;
int ret;
ASSERT(current);
*current = 0;
ret = cxd56_pmic_get_gauge(&gauge);
if (ret < 0)
{
return -EIO;
}
/* (Register value - 800h) / Current detection resistor (0.1 ohm) * 0.02929 */
#ifdef USE_FLOAT_CONVERSION
*current = (gauge.current - 0x800) / 0.1f * 0.02929f;
#else
*current = (gauge.current - 0x800) * 2929 / 10000;
#endif
return OK;
}
/****************************************************************************
* Name: charger_get_voltage
****************************************************************************/
static int charger_get_voltage(FAR int *voltage)
{
FAR struct pmic_gauge_s gauge;
int ret;
ASSERT(voltage);
*voltage = 0;
ret = cxd56_pmic_get_gauge(&gauge);
if (ret < 0)
{
return -EIO;
}
#ifdef USE_FLOAT_CONVERSION
*voltage = gauge.voltage * 1.12f;
#else
*voltage = gauge.voltage * 112 / 100;
#endif
return OK;
}
/****************************************************************************
* Name: charger_get_temptable
****************************************************************************/
static int charger_get_temptable(FAR struct battery_temp_table_s *table)
{
struct pmic_temp_table_s buf;
int ret;
ret = cxd56_pmic_gettemptable(&buf);
if (ret < 0)
{
return -EIO;
}
table->T60 = buf.T60;
table->T45 = buf.T45;
table->T10 = buf.T10;
table->T00 = buf.T00;
return OK;
}
/****************************************************************************
* Name: charger_set_temptable
****************************************************************************/
static int charger_set_temptable(FAR struct battery_temp_table_s *table)
{
struct pmic_temp_table_s buf;
buf.T60 = table->T60;
buf.T45 = table->T45;
buf.T10 = table->T10;
buf.T00 = table->T00;
return cxd56_pmic_settemptable(&buf);
}
/****************************************************************************
* Name: charger_open
*
* Description:
* This function is called whenever the battery device is opened.
*
****************************************************************************/
static int charger_open(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: charger_close
*
* Description:
* This routine is called when the battery device is closed.
*
****************************************************************************/
static int charger_close(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: charger_read
****************************************************************************/
static ssize_t charger_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
/* Return nothing read */
return 0;
}
/****************************************************************************
* Name: charger_write
****************************************************************************/
static ssize_t charger_write(FAR struct file *filep,
FAR const char *buffer, size_t buflen)
{
/* Return nothing written */
return 0;
}
/****************************************************************************
* Name: charger_ioctl
****************************************************************************/
static int charger_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct charger_dev_s *priv = inode->i_private;
int ret = -ENOTTY;
sem_wait(&priv->batsem);
switch (cmd)
{
case BATIOC_STATE:
{
FAR enum battery_charger_status_e *status =
(FAR enum battery_charger_status_e *)(uintptr_t)arg;
ret = charger_get_status(status);
}
break;
case BATIOC_HEALTH:
{
FAR enum battery_charger_health_e *health =
(FAR enum battery_charger_health_e *)(uintptr_t)arg;
ret = charger_get_health(health);
}
break;
case BATIOC_ONLINE:
{
FAR bool *online = (FAR bool *)(uintptr_t)arg;
ret = charger_online(online);
}
break;
case BATIOC_VOLTAGE:
{
FAR int *voltage = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_setchargevol(*voltage);
}
break;
case BATIOC_CURRENT:
{
/* Not supported */
ret = OK;
}
break;
case BATIOC_INPUT_CURRENT:
{
FAR int *current = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_setchargecurrent(*current);
}
break;
case BATIOC_GET_CHGVOLTAGE:
{
FAR int *voltage = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_getchargevol(voltage);
}
break;
case BATIOC_GET_CHGCURRENT:
{
FAR int *current = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_getchargecurrent(current);
}
break;
case BATIOC_GET_RECHARGEVOL:
{
FAR int *voltage = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_getrechargevol(voltage);
}
break;
case BATIOC_SET_RECHARGEVOL:
{
FAR int *voltage = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_setrechargevol(*voltage);
}
break;
case BATIOC_GET_COMPCURRENT:
{
FAR int *current = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_getchargecompcurrent(current);
}
break;
case BATIOC_GET_TEMPTABLE:
{
FAR struct battery_temp_table_s *table =
(FAR struct battery_temp_table_s *)(uintptr_t)arg;
ret = charger_get_temptable(table);
}
break;
case BATIOC_SET_TEMPTABLE:
{
FAR struct battery_temp_table_s *table =
(FAR struct battery_temp_table_s *)(uintptr_t)arg;
ret = charger_set_temptable(table);
}
break;
case BATIOC_SET_COMPCURRENT:
{
FAR int *current = (FAR int *)(uintptr_t)arg;
ret = cxd56_pmic_setchargecompcurrent(*current);
}
break;
case BATIOC_GET_CURRENT:
{
FAR int *curr = (FAR int *)(uintptr_t)arg;
if (curr)
{
ret = charger_get_current(curr);
}
else
{
set_errno(EINVAL);
ret = -1;
}
}
break;
case BATIOC_GET_VOLTAGE:
{
FAR int *vol = (FAR int *)(uintptr_t)arg;
if (vol)
{
ret = charger_get_voltage(vol);
}
else
{
set_errno(EINVAL);
ret = -1;
}
}
break;
default:
ret = -ENOTTY;
break;
}
sem_post(&priv->batsem);
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: cxd56_charger_initialize
*
* Description:
* Initialize the CXD5247 battery charger driver.
*
* Input Parameters:
* devpath - Device file path
*
* Returned Value:
* Return 0 on success. Otherwise, return a negated errno.
*
****************************************************************************/
int cxd56_charger_initialize(FAR const char *devpath)
{
FAR struct charger_dev_s *priv = &g_chargerdev;
int ret;
/* Initialize the CXD5247 device structure */
sem_init(&priv->batsem, 0, 1);
/* Register battery driver */
ret = register_driver(devpath, &g_chargerops, 0666, priv);
if (ret < 0)
{
_err("ERROR: register_driver failed: %d\n", ret);
return -EFAULT;
}
return OK;
}
/****************************************************************************
* Name: cxd56_charger_uninitialize
*
* Description:
* Uninitialize the CXD5247 battery charger driver.
*
* Input Parameters:
* devpath - Device file path
*
* Returned Value:
* Return 0 on success. Otherwise, return a negated errno.
*
****************************************************************************/
int cxd56_charger_uninitialize(FAR const char *devpath)
{
(void) unregister_driver(devpath);
return OK;
}
#endif /* CONFIG_CXD56_CHARGER */

View File

@ -0,0 +1,44 @@
/****************************************************************************
* arch/arm/src/cxd56xx/cxd56_charger.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __SRC_CXD56_CHARGER_H
#define __SRC_CXD56_CHARGER_H
/* initialize function */
int cxd56_charger_initialize(FAR const char *devpath);
int cxd56_charger_uninitialize(FAR const char *devpath);
#endif /* __SRC_CXD56_CHARGER_H */

View File

@ -0,0 +1,440 @@
/****************************************************************************
* arch/arm/src/cxd56xx/cxd56_gauge.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* CXD5247GF is Li-Ion Battery Charger with Power-Path Management.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <debug.h>
#include <math.h>
#include <nuttx/kmalloc.h>
#include <nuttx/power/battery_gauge.h>
#include <nuttx/power/battery_ioctl.h>
#include <arch/chip/battery_ioctl.h>
#include "cxd56_pmic.h"
#ifdef CONFIG_CXD56_GAUGE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Debug ********************************************************************/
#ifdef CONFIG_CXD56_GAUGE_DEBUG
#define baterr(fmt, ...) logerr(fmt, ## __VA_ARGS__)
#define batdbg(fmt, ...) logdebug(fmt, ## __VA_ARGS__)
#else
#define baterr(fmt, ...)
#define batdbg(fmt, ...)
#endif
/****************************************************************************
* Private Types
****************************************************************************/
struct bat_gauge_dev_s
{
sem_t batsem;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
static int gauge_open(FAR struct file *filep);
static int gauge_close(FAR struct file *filep);
static ssize_t gauge_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t gauge_write(FAR struct file *filep,
FAR const char *buffer, size_t buflen);
static int gauge_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
/****************************************************************************
* Private Data
****************************************************************************/
static const struct file_operations g_gaugeops =
{
gauge_open, /* open */
gauge_close, /* close */
gauge_read, /* read */
gauge_write, /* write */
0, /* seek */
gauge_ioctl /* ioctl */
#ifndef CONFIG_DISABLE_POLL
, NULL /* poll */
#endif
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
, NULL /* unlink */
#endif
};
static struct bat_gauge_dev_s g_gaugedev;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: gauge_get_status
****************************************************************************/
static int gauge_get_status(FAR enum battery_gauge_status_e *status)
{
uint8_t state;
int ret;
if (status == NULL)
{
return -EINVAL;
}
*status = BATTERY_UNKNOWN;
ret = cxd56_pmic_getchargestate(&state);
if (ret < 0)
{
return -EIO;
}
switch (state)
{
/* Is the charging done? */
case PMIC_STAT_CHG_COMPLETE:
*status = BATTERY_FULL;
break;
/* Is the charging in progress? */
case PMIC_STAT_GB_QCKCHARGE:
case PMIC_STAT_GB_LOWCHARGE:
case PMIC_STAT_GB_HIGHCHARGE:
*status = BATTERY_CHARGING;
break;
/* Is the discharging */
case PMIC_STAT_CHG_STOP:
*status = BATTERY_DISCHARGING;
break;
default:
_info("Charge state %d\n", state);
*status = BATTERY_IDLE;
break;
}
return OK;
}
/****************************************************************************
* Name: gauge_get_vol
****************************************************************************/
static int gauge_get_vol(FAR b16_t *voltage)
{
struct pmic_gauge_s gauge;
int ret;
if (voltage == NULL)
{
return -EINVAL;
}
*voltage = 0;
ret = cxd56_pmic_get_gauge(&gauge);
if (ret < 0)
{
return -EIO;
}
*voltage = gauge.voltage * 112 / 100;
return OK;
}
/****************************************************************************
* Name: gauge_get_capacity
****************************************************************************/
static int gauge_get_capacity(FAR b16_t *capacity)
{
b16_t vol;
int lower;
int upper;
int ret;
if (capacity == NULL)
{
return -EINVAL;
}
/* Get current battery voltage and upper/lower limit settings from PMIC. */
ret = gauge_get_vol(&vol);
if (ret < 0)
{
return -EIO;
}
ret = cxd56_pmic_getchargevol(&upper);
if (ret < 0)
{
return -EIO;
}
ret = cxd56_pmic_getlowervol(&lower);
if (ret < 0)
{
return -EIO;
}
/* Calculate capacity (0-100%)
* Actually, battery voltage possible to be under lower limit voltage.
*
* NOTE: This logic is tentative, linear from lower to upper. But it
* depends on the battery. Thus, user should be apply a voltage
* characteristic for capacity calculation if you want to more accuracy.
*/
if (vol > lower)
{
upper -= lower;
vol -= lower;
*capacity = (vol * 100) / upper;
}
else
{
*capacity = 0;
}
return OK;
}
/****************************************************************************
* Name: gauge_online
****************************************************************************/
static int gauge_online(FAR bool *online)
{
if (online == NULL)
{
return -EINVAL;
}
*online = true;
return OK;
}
/****************************************************************************
* Name: gauge_open
*
* Description:
* This function is called whenever the battery device is opened.
*
****************************************************************************/
static int gauge_open(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: gauge_close
*
* Description:
* This routine is called when the battery device is closed.
*
****************************************************************************/
static int gauge_close(FAR struct file *filep)
{
return OK;
}
/****************************************************************************
* Name: gauge_read
****************************************************************************/
static ssize_t gauge_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
/* Return nothing read */
return 0;
}
/****************************************************************************
* Name: gauge_write
****************************************************************************/
static ssize_t gauge_write(FAR struct file *filep,
FAR const char *buffer, size_t buflen)
{
/* Return nothing written */
return 0;
}
/****************************************************************************
* Name: gauge_ioctl
****************************************************************************/
static int gauge_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct bat_gauge_dev_s *priv = inode->i_private;
int ret = -ENOTTY;
sem_wait(&priv->batsem);
switch (cmd)
{
case BATIOC_STATE:
{
FAR enum battery_gauge_status_e *status =
(FAR enum battery_gauge_status_e *)(uintptr_t)arg;
ret = gauge_get_status(status);
}
break;
case BATIOC_VOLTAGE:
{
FAR b16_t *voltage = (FAR b16_t *)(uintptr_t)arg;
ret = gauge_get_vol(voltage);
}
break;
case BATIOC_CAPACITY:
{
FAR b16_t *capacity = (FAR b16_t *)(uintptr_t)arg;
ret = gauge_get_capacity(capacity);
}
break;
case BATIOC_ONLINE:
{
FAR bool *online = (FAR bool *)(uintptr_t)arg;
ret = gauge_online(online);
}
break;
default:
ret = -ENOTTY;
break;
}
sem_post(&priv->batsem);
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: cxd56_gauge_initialize
*
* Description:
* Initialize the CXD5247 battery driver.
*
* Input Parameters:
* devpath - Device file path
*
* Returned Value:
* Return 0 on success. Otherwise, return a negated errno.
*
****************************************************************************/
int cxd56_gauge_initialize(FAR const char *devpath)
{
FAR struct bat_gauge_dev_s *priv = &g_gaugedev;
int ret;
/* Initialize the CXD5247 device structure */
sem_init(&priv->batsem, 0, 1);
/* Register battery driver */
ret = register_driver(devpath, &g_gaugeops, 0666, priv);
if (ret < 0)
{
_err("ERROR: register_driver failed: %d\n", ret);
return -EFAULT;
}
return OK;
}
/****************************************************************************
* Name: cxd56_gauge_uninitialize
*
* Description:
* Uninitialize the CXD5247 battery driver.
*
* Input Parameters:
* devpath - Device file path
*
* Returned Value:
* Return 0 on success. Otherwise, return a negated errno.
*
****************************************************************************/
int cxd56_gauge_uninitialize(FAR const char *devpath)
{
(void) unregister_driver(devpath);
return OK;
}
#endif /* CONFIG_CXD56_GAUGE */

View File

@ -0,0 +1,44 @@
/***************************************************************************
* arch/arm/src/cxd56xx/cxd56_gauge.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __SRC_CXD56_GAUGE_H
#define __SRC_CXD56_GAUGE_H
/* initialize function */
int cxd56_gauge_initialize(FAR const char *devpath);
int cxd56_gauge_uninitialize(FAR const char *devpath);
#endif /* __SRC_CXD56_GAUGE_H */

View File

@ -48,6 +48,8 @@
#include "cxd56_clock.h"
#include "cxd56_power.h"
#include "cxd56_flash.h"
#include "cxd56_gauge.h"
#include "cxd56_charger.h"
#include "cxd56_gs2200m.h"
#include "cxd56_i2cdev.h"
#include "cxd56_bmi160.h"

View File

@ -0,0 +1,94 @@
/****************************************************************************
* configs/spresense/include/cxd56_charger.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __BOARD_COMMON_INCLUDE_CXD56_CHARGER_H
#define __BOARD_COMMON_INCLUDE_CXD56_CHARGER_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_charger_initialize
*
* Description:
* Initialize battery charger driver
*
****************************************************************************/
int board_charger_initialize(FAR const char *devpath);
/****************************************************************************
* Name: board_charger_uninitialize
*
* Description:
* Uninitialize battery charger driver
*
****************************************************************************/
int board_charger_uninitialize(FAR const char *devpath);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARD_COMMON_INCLUDE_CXD56_CHARGER_H */

View File

@ -0,0 +1,94 @@
/****************************************************************************
* configs/spresense/include/cxd56_gauge.h
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __BOARD_COMMON_INCLUDE_CXD56_GAUGE_H
#define __BOARD_COMMON_INCLUDE_CXD56_GAUGE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_gauge_initialize
*
* Description:
* Initialize battery gauge driver
*
****************************************************************************/
int board_gauge_initialize(FAR const char *devpath);
/****************************************************************************
* Name: board_gauge_uninitialize
*
* Description:
* Uninitialize battery gauge driver
*
****************************************************************************/
int board_gauge_uninitialize(FAR const char *devpath);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARD_COMMON_INCLUDE_CXD56_GAUGE_H */

View File

@ -73,7 +73,7 @@ extern "C"
*
****************************************************************************/
#ifdef CONFIG_SYSTEM_I2CTOOL
#ifdef CONFIG_CXD56_I2C_DRIVER
int board_i2cdev_initialize(int bus);
#endif

View File

@ -84,6 +84,14 @@ ifeq ($(CONFIG_CXD56_SDIO),y)
CSRCS += cxd56_sdcard.c
endif
ifeq ($(CONFIG_CXD56_GAUGE),y)
CSRCS += cxd56_gauge.c
endif
ifeq ($(CONFIG_CXD56_CHARGER),y)
CSRCS += cxd56_charger.c
endif
ifeq ($(CONFIG_USBMSC),y)
CSRCS += cxd56_usbmsc.c
endif
@ -100,7 +108,7 @@ ifeq ($(CONFIG_SENSORS_BMI160_I2C),y)
CSRCS += cxd56_bmi160_i2c.c
endif
ifeq ($(CONFIG_SYSTEM_I2CTOOL),y)
ifeq ($(CONFIG_CXD56_I2C_DRIVER),y)
CSRCS += cxd56_i2cdev.c
endif

View File

@ -229,7 +229,7 @@ int cxd56_bringup(void)
}
#endif
#ifdef CONFIG_SYSTEM_I2CTOOL
#ifdef CONFIG_CXD56_I2C_DRIVER
#ifdef CONFIG_CXD56_I2C0
ret = board_i2cdev_initialize(0);
if (ret < 0)

View File

@ -0,0 +1,104 @@
/****************************************************************************
* configs/spresense/src/cxd56_charger.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <stdio.h>
#include <errno.h>
#include "cxd56_charger.h"
#if defined(CONFIG_CXD56_CHARGER)
static int g_chargerinitialized = 0;
/****************************************************************************
* Name: board_charger_initialize
*
* Description:
* Initialize and register battery charger driver
*
****************************************************************************/
int board_charger_initialize(FAR const char *devpath, FAR int16_t *gaugemeter)
{
int ret;
if (!g_chargerinitialized)
{
ret = cxd56_charger_initialize(devpath);
if (ret < 0)
{
_err("ERROR: Failed to initialize charger.\n");
return -ENODEV;
}
g_chargerinitialized = 1;
}
return OK;
}
/****************************************************************************
* Name: board_charger_uninitialize
*
* Description:
* Uninitialize and unregister battery charger driver
*
****************************************************************************/
int board_charger_uninitialize(FAR const char *devpath)
{
int ret;
if (g_chargerinitialized)
{
ret = cxd56_charger_uninitialize(devpath);
if (ret)
{
_err("ERROR: Failed to finalize charger.\n");
return -ENODEV;
}
g_chargerinitialized = 0;
}
return OK;
}
#endif

View File

@ -0,0 +1,104 @@
/****************************************************************************
* configs/spresense/src/cxd56_gauge.c
*
* Copyright 2018 Sony Semiconductor Solutions Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <stdio.h>
#include <errno.h>
#include "cxd56_gauge.h"
#if defined(CONFIG_CXD56_GAUGE)
static int g_gaugeinitialized = 0;
/****************************************************************************
* Name: board_gauge_initialize
*
* Description:
* Initialize and register battery gauge driver
*
****************************************************************************/
int board_gauge_initialize(FAR const char *devpath, FAR int16_t *gaugemeter)
{
int ret;
if (!g_gaugeinitialized)
{
ret = cxd56_gauge_initialize(devpath);
if (ret < 0)
{
_err("ERROR: Failed to initialize gauge.\n");
return -ENODEV;
}
g_gaugeinitialized = 1;
}
return OK;
}
/****************************************************************************
* Name: board_gauge_uninitialize
*
* Description:
* Uninitialize and unregister battery gauge driver
*
****************************************************************************/
int board_gauge_uninitialize(FAR const char *devpath)
{
int ret;
if (g_gaugeinitialized)
{
ret = cxd56_gauge_uninitialize(devpath);
if (ret)
{
_err("ERROR: Failed to finalize gauge.\n");
return -ENODEV;
}
g_gaugeinitialized = 0;
}
return OK;
}
#endif

View File

@ -45,8 +45,6 @@
#include "cxd56_i2c.h"
#if defined(CONFIG_CXD56_I2C) && defined(CONFIG_I2C_DRIVER)
/****************************************************************************
* Name: board_i2cdev_initialize
*
@ -79,5 +77,3 @@ int board_i2cdev_initialize(int port)
return ret;
}
#endif