Move SMPS driver to drivers/power (and header to include/nuttx/power). Rename debug to IOCTLs to more general power naming; create a separate file to coordinate power-related IOCTL commands.

This commit is contained in:
Gregory Nutt 2017-07-23 07:35:09 -06:00
parent a9a236fea5
commit 4be064d19a
8 changed files with 156 additions and 74 deletions

View file

@ -97,10 +97,6 @@ ifeq ($(CONFIG_PWM),y)
CSRCS += pwm.c
endif
ifeq ($(CONFIG_SMPS),y)
CSRCS += smps.c
endif
ifeq ($(CONFIG_DEV_URANDOM),y)
ifneq ($(CONFIG_DEV_URANDOM_ARCH),y)
CSRCS += dev_urandom.c

View file

@ -232,6 +232,44 @@ config PM_SLEEPENTER_COUNT
endif # PM
menuconfig DRIVERS_SMPS
bool "Switched-Mode Power Supply (SMPS)"
default n
---help---
Enables building of an SMPS upper half driver.
if DRIVERS_SMPS
config SMPS_HAVE_OUTPUT_VOLTAGE
bool "Have Output Voltage"
default n
config SMPS_HAVE_OUTPUT_CURRENT
bool "Have Output Current"
default n
config SMPS_HAVE_OUTPUT_POWER
bool "Have Output Power"
default n
config SMPS_HAVE_INPUT_VOLTAGE
bool "Have Input Voltage"
default n
config SMPS_HAVE_INPUT_CURRENT
bool "Have Input Current"
default n
config SMPS_HAVE_INPUT_POWER
bool "Have Input Power"
default n
config SMPS_HAVE_EFFICIENCY
bool "Have Power Efficiency"
default n
endif
menuconfig POWER
bool "Power Management Support"
default n

View file

@ -52,6 +52,18 @@ POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$
endif
# Add switched-mode power supply support
ifeq ($(CONFIG_DRIVERS_SMPS),y)
CSRCS += smps.c
POWER_DEPPATH := --dep-path power
POWER_VPATH := :power
POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)power}
endif
# Add battery charger drivers
ifeq ($(CONFIG_BATTERY_CHARGER),y)
@ -70,7 +82,7 @@ endif
endif
# Include battery suport in the build
# Include power support in the build
POWER_DEPPATH := --dep-path power
POWER_VPATH := :power

View file

@ -1,5 +1,5 @@
/****************************************************************************
* drivers/smps.c
* drivers/power/smps.c
* Upper-half, character driver for SMPS (switched-mode power supply)
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
@ -51,7 +51,7 @@
#include <nuttx/arch.h>
#include <nuttx/semaphore.h>
#include <nuttx/fs/fs.h>
#include <nuttx/drivers/smps.h>
#include <nuttx/power/smps.h>
#include <nuttx/irq.h>
@ -233,7 +233,7 @@ static int smps_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
switch (cmd)
{
case SMPSIOC_START:
case PWRIOC_START:
{
/* TODO: sanity checking:
* - absolute limits
@ -244,34 +244,34 @@ static int smps_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = dev->ops->start(dev);
if (ret != OK)
{
smpserr("ERROR: SMPSC_START failed %d\n", ret);
pwrerr("ERROR: SMPSC_START failed %d\n", ret);
}
break;
}
case SMPSIOC_STOP:
case PWRIOC_STOP:
{
ret = dev->ops->stop(dev);
if (ret != OK)
{
smpserr("ERROR: SMPSC_STOP failed %d\n", ret);
pwrerr("ERROR: SMPSC_STOP failed %d\n", ret);
}
break;
}
case SMPSIOC_SET_MODE:
case PWRIOC_SET_MODE:
{
uint8_t mode = ((uint8_t)arg);
ret = dev->ops->mode_set(dev, mode);
if (ret != OK)
{
smpserr("ERROR: SMPSC_SET_MODE failed %d\n", ret);
pwrerr("ERROR: SMPSC_SET_MODE failed %d\n", ret);
}
break;
}
case SMPSIOC_SET_LIMITS:
case PWRIOC_SET_LIMITS:
{
FAR struct smps_limits_s *limits =
(FAR struct smps_limits_s *)((uintptr_t)arg);
@ -281,12 +281,12 @@ static int smps_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = dev->ops->limits_set(dev, limits);
if (ret != OK)
{
smpserr("ERROR: SMPSC_SET_LIMITS failed %d\n", ret);
pwrerr("ERROR: SMPSC_SET_LIMITS failed %d\n", ret);
}
break;
}
case SMPSIOC_GET_STATE:
case PWRIOC_GET_STATE:
{
FAR struct smps_state_s *state =
(FAR struct smps_state_s *)((uintptr_t)arg);
@ -294,48 +294,48 @@ static int smps_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = dev->ops->state_get(dev, state);
if (ret != OK)
{
smpserr("ERROR: SMPSC_GET_STATE failed %d\n", ret);
pwrerr("ERROR: SMPSC_GET_STATE failed %d\n", ret);
}
break;
}
case SMPSIOC_SET_FAULT:
case PWRIOC_SET_FAULT:
{
uint8_t fault = ((uint8_t)arg);
ret = dev->ops->fault_set(dev, fault);
if (ret != OK)
{
smpserr("ERROR: SMPSC_SET_FAULT failed %d\n", ret);
pwrerr("ERROR: SMPSC_SET_FAULT failed %d\n", ret);
}
break;
}
case SMPSIOC_GET_FAULT:
case PWRIOC_GET_FAULT:
{
uint8_t *fault = ((uint8_t*)arg);
ret = dev->ops->fault_get(dev, fault);
if (ret != OK)
{
smpserr("ERROR: SMPSC_GET_FAULT failed %d\n", ret);
pwrerr("ERROR: SMPSC_GET_FAULT failed %d\n", ret);
}
break;
}
case SMPSIOC_CLEAN_FAULT:
case PWRIOC_CLEAN_FAULT:
{
uint8_t fault = ((uint8_t)arg);
ret = dev->ops->fault_clean(dev, fault);
if (ret != OK)
{
smpserr("ERROR: SMPSC_CLEAN_FAULT failed %d\n", ret);
pwrerr("ERROR: SMPSC_CLEAN_FAULT failed %d\n", ret);
}
break;
}
case SMPSIOC_SET_PARAMS:
case PWRIOC_SET_PARAMS:
{
FAR struct smps_params_s *params =
(FAR struct smps_params_s *)((uintptr_t)arg);
@ -346,14 +346,14 @@ static int smps_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = dev->ops->params_set(dev, params);
if (ret != OK)
{
smpserr("ERROR: SMPSC_SET_PARAMS failed %d\n", ret);
pwrerr("ERROR: SMPSC_SET_PARAMS failed %d\n", ret);
}
break;
}
default:
{
smpsinfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
pwrinfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
ret = dev->ops->ioctl(dev, cmd, arg);
break;
}

View file

@ -89,6 +89,7 @@
#define _CLIOCBASE (0x2400) /* Contactless modules ioctl commands */
#define _USBCBASE (0x2500) /* USB-C controller ioctl commands */
#define _MAC802154BASE (0x2600) /* 802.15.4 MAC ioctl commands */
#define _PWRBASE (0x2700) /* Power-related ioctl commands */
/* boardctl() commands share the same number space */
@ -428,6 +429,11 @@
#define _MAC802154IOCVALID(c) (_IOC_TYPE(c)==_MAC802154BASE)
#define _MAC802154IOC(nr) _IOC(_MAC802154BASE,nr)
/* Power-Related IOCTLs *****************************************************/
#define _PWRIOCVALID(c) (_IOC_TYPE(c)==_SMPS_BASE)
#define _PWRIOC(nr) _IOC(_PWRBASE,nr)
/* boardctl() command definitions *******************************************/
#define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE)

View file

@ -48,6 +48,11 @@
* Pre-processor Definitions
****************************************************************************/
/* All battery-related IOCTL commands must be defined in this header file
* in order to assure that every IOCTL command is unique and will not be
* aliased.
*/
#define BATIOC_STATE _BATIOC(0x0001)
#define BATIOC_HEALTH _BATIOC(0x0002)
#define BATIOC_ONLINE _BATIOC(0x0003)

View file

@ -0,0 +1,66 @@
/****************************************************************************
* include/nuttx/power/power_ioctl.h
* NuttX Power-Related IOCTLs definitions
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 NuttX 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_NUTTX_POWER_POWER_IOCTL_H
#define __INCLUDE_NUTTX_POWER_POWER_IOCTL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* All power-related IOCTL commands must be defined in this header file
* in order to assure that every IOCTL command is unique and will not be
* aliased.
*/
#define PWRIOC_START _PWRIOC(1)
#define PWRIOC_STOP _PWRIOC(2)
#define PWRIOC_SET_MODE _PWRIOC(3)
#define PWRIOC_SET_LIMITS _PWRIOC(4)
#define PWRIOC_GET_STATE _PWRIOC(5)
#define PWRIOC_GET_FAULT _PWRIOC(6)
#define PWRIOC_SET_FAULT _PWRIOC(7)
#define PWRIOC_CLEAN_FAULT _PWRIOC(8)
#define PWRIOC_SET_PARAMS _PWRIOC(9)
#endif /* __INCLUDE_NUTTX_POWER_POWER_IOCTL_H */

View file

@ -1,5 +1,5 @@
/****************************************************************************
* include/nuttx/drivers/smps.h
* include/nuttx/power/smps.h
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Mateusz Szafoni <raiden00@railab.me>
@ -33,8 +33,8 @@
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_DRIVERS_SMPS_H
#define __INCLUDE_NUTTX_DRIVERS_SMPS_H
#ifndef __INCLUDE_NUTTX_DRIVERS_POWER_H
#define __INCLUDE_NUTTX_DRIVERS_POWER_H
/*
* The SMPS (switched-mode power supply) driver is split into two parts:
@ -56,55 +56,14 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/power/power_ioctl.h>
#ifdef CONFIG_SMPS
#ifdef CONFIG_DRIVERS_SMPS
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* REVISIT: move to fs/ioctl.h ? */
/* General ioctl definitions ************************************************/
#define _SMPSBASE (0x2700) /* SMPS ioctl commands */
/* SMPS IOCTLs **************************************************************/
#define _SMPSIOCVALID(c) (_IOC_TYPE(c)==_SMPS_BASE)
#define _SMPSIOC(nr) _IOC(_SMPSBASE,nr)
/* Ioctl Commands ************************************************************/
#define SMPSIOC_START _SMPSIOC(1)
#define SMPSIOC_STOP _SMPSIOC(2)
#define SMPSIOC_SET_MODE _SMPSIOC(3)
#define SMPSIOC_SET_LIMITS _SMPSIOC(4)
#define SMPSIOC_GET_STATE _SMPSIOC(5)
#define SMPSIOC_GET_FAULT _SMPSIOC(6)
#define SMPSIOC_SET_FAULT _SMPSIOC(7)
#define SMPSIOC_CLEAN_FAULT _SMPSIOC(8)
#define SMPSIOC_SET_PARAMS _SMPSIOC(9)
#ifdef CONFIG_DEBUG_SMPS_ERROR
# define smpserr(format, ...) _err(format, ##__VA_ARGS__)
#else
# define smpserr(x...)
#endif
#ifdef CONFIG_DEBUG_SMPS_WARN
# define smpswarn(format, ...) _warn(format, ##__VA_ARGS__)
#else
# define smpswarn(x...)
#endif
#ifdef CONFIG_DEBUG_SMPS_INFO
# define smpsinfo(format, ...) _info(format, ##__VA_ARGS__)
#else
# define smpsinfo(x...)
#endif
/****************************************************************************
* Public Types
****************************************************************************/
@ -331,5 +290,5 @@ int smps_register(FAR const char *path, FAR struct smps_dev_s *dev,
}
#endif
#endif /* CONFIG_SMPS */
#endif /* __INCLUDE_NUTTX_DRIVERS_SMPS_H */
#endif /* CONFIG_DRIVERS_SMPS */
#endif /* __INCLUDE_NUTTX_DRIVERS_POWER_H */