summaryrefslogtreecommitdiff
path: root/nuttx/drivers
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-22 16:42:49 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-01-22 16:42:49 +0000
commit3d2ac1dd78fbec255823415ef5498d35056b7361 (patch)
treea8318c2dddbe4ecd66f431e93f8ac7e1fe5adabe /nuttx/drivers
parent0a55f2b9c3fcba71f872267bfeb635b8fc4b8cb7 (diff)
downloadpx4-nuttx-3d2ac1dd78fbec255823415ef5498d35056b7361.tar.gz
px4-nuttx-3d2ac1dd78fbec255823415ef5498d35056b7361.tar.bz2
px4-nuttx-3d2ac1dd78fbec255823415ef5498d35056b7361.zip
Create directory structures to support power-related devices
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4321 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers')
-rw-r--r--nuttx/drivers/Makefile4
-rw-r--r--nuttx/drivers/power/Make.defs (renamed from nuttx/drivers/pm/Make.defs)20
-rw-r--r--nuttx/drivers/power/max1704x.c208
-rw-r--r--nuttx/drivers/power/pm_activity.c (renamed from nuttx/drivers/pm/pm_activity.c)6
-rw-r--r--nuttx/drivers/power/pm_changestate.c (renamed from nuttx/drivers/pm/pm_changestate.c)8
-rw-r--r--nuttx/drivers/power/pm_checkstate.c (renamed from nuttx/drivers/pm/pm_checkstate.c)8
-rw-r--r--nuttx/drivers/power/pm_initialize.c (renamed from nuttx/drivers/pm/pm_initialize.c)8
-rw-r--r--nuttx/drivers/power/pm_internal.h (renamed from nuttx/drivers/pm/pm_internal.h)14
-rw-r--r--nuttx/drivers/power/pm_register.c (renamed from nuttx/drivers/pm/pm_register.c)8
-rw-r--r--nuttx/drivers/power/pm_update.c (renamed from nuttx/drivers/pm/pm_update.c)8
10 files changed, 254 insertions, 38 deletions
diff --git a/nuttx/drivers/Makefile b/nuttx/drivers/Makefile
index 4254acac0..9d804871e 100644
--- a/nuttx/drivers/Makefile
+++ b/nuttx/drivers/Makefile
@@ -1,7 +1,7 @@
############################################################################
# drivers/Makefile
#
-# Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@ include mmcsd/Make.defs
include mtd/Make.defs
include net/Make.defs
include pipes/Make.defs
-include pm/Make.defs
+include power/Make.defs
include sensors/Make.defs
include serial/Make.defs
include usbdev/Make.defs
diff --git a/nuttx/drivers/pm/Make.defs b/nuttx/drivers/power/Make.defs
index 6204973f5..91102c1e9 100644
--- a/nuttx/drivers/pm/Make.defs
+++ b/nuttx/drivers/power/Make.defs
@@ -1,8 +1,8 @@
############################################################################
-# drivers/pm/Make.defs
+# drivers/power/Make.defs
#
-# Copyright (C) 2011 Gregory Nutt. All rights reserved.
-# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+# Copyright (C) 2011-2012 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
@@ -41,10 +41,18 @@ ifeq ($(CONFIG_PM),y)
CSRCS += pm_activity.c pm_changestate.c pm_checkstate.c pm_initialize.c pm_register.c pm_update.c
+# Add I2C devices
+
+ifeq ($(CONFIG_I2C),y)
+ifeq ($(CONFIG_I2C_MAX1704X),y)
+CSRCS += max1704x.c
+endif
+endif
+
# Include power management in the build
-DEPPATH += --dep-path pm
-VPATH += :pm
-CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/pm}
+DEPPATH += --dep-path power
+VPATH += :power
+CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/power}
endif
diff --git a/nuttx/drivers/power/max1704x.c b/nuttx/drivers/power/max1704x.c
new file mode 100644
index 000000000..bba53478a
--- /dev/null
+++ b/nuttx/drivers/power/max1704x.c
@@ -0,0 +1,208 @@
+/****************************************************************************
+ * drivers/power/max1704x.c
+ * Character driver for the STMicroMAX1704x Temperature Sensor
+ *
+ * Copyright (C) 2012 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <errno.h>
+#include <debug.h>
+
+#if defined(CONFIG_I2C) && defined(CONFIG_I2C_MAX1704X)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private
+ ****************************************************************************/
+
+struct max1704x_dev_s
+{
+ FAR struct i2c_dev_s *i2c; /* I2C interface */
+ uint8_t addr; /* I2C address */
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+/* I2C Helpers */
+
+/* Character driver methods */
+
+static int max1704x_open(FAR struct file *filep);
+static int max1704x_close(FAR struct file *filep);
+static ssize_t max1704x_read(FAR struct file *, FAR char *, size_t);
+static ssize_t max1704x_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
+static int max1704x_ioctl(FAR struct file *filep,int cmd,unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_max1704xfopg =
+{
+ max1704x_open,
+ max1704x_close,
+ max1704x_read,
+ max1704x_write,
+ 0,
+ max1704x_ioctl
+#ifndef CONFIG_DISABLE_POLL
+ , 0
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+/****************************************************************************
+ * Name: max1704x_open
+ *
+ * Description:
+ * This function is called whenever theMAX1704x device is opened.
+ *
+ ****************************************************************************/
+
+static int max1704x_open(FAR struct file *filep)
+{
+ return OK;
+}
+
+/****************************************************************************
+ * Name: max1704x_close
+ *
+ * Description:
+ * This routine is called when theMAX1704x device is closed.
+ *
+ ****************************************************************************/
+
+static int max1704x_close(FAR struct file *filep)
+{
+ return OK;
+}
+
+/****************************************************************************
+ * Name: max1704x_read
+ ****************************************************************************/
+
+static ssize_t max1704x_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
+{
+ retrun 0;
+}
+
+/****************************************************************************
+ * Name: max1704x_write
+ ****************************************************************************/
+
+static ssize_t max1704x_write(FAR struct file *filep, FAR const char *buffer,
+ size_t buflen)
+{
+ return -EACCESS;
+}
+
+/****************************************************************************
+ * Name: max1704x_ioctl
+ ****************************************************************************/
+
+static int max1704x_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+ FAR struct inode *inode = filep->f_inode;
+ FAR struct max1704x_dev_s *priv = inode->i_private;
+ int ret = OK;
+
+ switch (cmd)
+ {
+ default:
+ i2cdbg("Unrecognized cmd: %d\n", cmd);
+ ret = -ENOTTY;
+ break;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: max1704x_register
+ *
+ * Description:
+ * Register theMAX1704x character device as 'devpath'
+ *
+ * Input Parameters:
+ * devpath - The full path to the driver to register. E.g., "/dev/temp0"
+ * i2c - An instance of the I2C interface to use to communicate with the MAX1704x
+ * addr - The I2C address of the MAX1704x.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int max1704x_register(FAR const char *devpath, FAR struct i2c_dev_s *i2c, uint8_t addr)
+{
+ FAR struct max1704x_dev_s *priv;
+ int ret;
+
+ /* Initialize theMAX1704x device structure */
+
+ priv = (FAR struct max1704x_dev_s *)kzalloc(sizeof(struct max1704x_dev_s));
+ if (!priv)
+ {
+ i2cdbg("Failed to allocate instance\n");
+ return -ENOMEM;
+ }
+
+ priv->i2c = i2c;
+ priv->addr = addr;
+
+ /* Register the character driver */
+
+ ret = register_driver(devpath, &g_max1704xfopg, 0555, priv);
+ if (ret < 0)
+ {
+ i2cdbg("Failed to register driver: %d\n", ret);
+ free(priv);
+ }
+ return ret;
+}
+#endif /* CONFIG_I2C && CONFIG_I2C_MAX1704X */
diff --git a/nuttx/drivers/pm/pm_activity.c b/nuttx/drivers/power/pm_activity.c
index dd908b949..8cef46684 100644
--- a/nuttx/drivers/pm/pm_activity.c
+++ b/nuttx/drivers/power/pm_activity.c
@@ -1,7 +1,7 @@
/****************************************************************************
- * drivers/pm/pm_activity.c
+ * drivers/power/pm_activity.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,7 @@
#include <nuttx/config.h>
-#include <nuttx/pm.h>
+#include <nuttx/power/pm.h>
#include <nuttx/clock.h>
#include <arch/irq.h>
diff --git a/nuttx/drivers/pm/pm_changestate.c b/nuttx/drivers/power/pm_changestate.c
index 50fa0640f..27d17ce88 100644
--- a/nuttx/drivers/pm/pm_changestate.c
+++ b/nuttx/drivers/power/pm_changestate.c
@@ -1,8 +1,8 @@
/****************************************************************************
- * drivers/pm/pm_changestate.c
+ * drivers/power/pm_changestate.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 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
@@ -39,7 +39,7 @@
#include <nuttx/config.h>
-#include <nuttx/pm.h>
+#include <nuttx/power/pm.h>
#include <arch/irq.h>
#include "pm_internal.h"
diff --git a/nuttx/drivers/pm/pm_checkstate.c b/nuttx/drivers/power/pm_checkstate.c
index 9ecff862e..9b0e1045e 100644
--- a/nuttx/drivers/pm/pm_checkstate.c
+++ b/nuttx/drivers/power/pm_checkstate.c
@@ -1,8 +1,8 @@
/****************************************************************************
- * drivers/pm/pm_checkstate.c
+ * drivers/power/pm_checkstate.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 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
@@ -39,7 +39,7 @@
#include <nuttx/config.h>
-#include <nuttx/pm.h>
+#include <nuttx/power/pm.h>
#include <nuttx/clock.h>
#include <arch/irq.h>
diff --git a/nuttx/drivers/pm/pm_initialize.c b/nuttx/drivers/power/pm_initialize.c
index 70cd8d7e6..9401fba9e 100644
--- a/nuttx/drivers/pm/pm_initialize.c
+++ b/nuttx/drivers/power/pm_initialize.c
@@ -1,8 +1,8 @@
/****************************************************************************
- * drivers/pm/pm_initialize.c
+ * drivers/power/pm_initialize.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 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
@@ -41,7 +41,7 @@
#include <semaphore.h>
-#include <nuttx/pm.h>
+#include <nuttx/power/pm.h>
#include "pm_internal.h"
diff --git a/nuttx/drivers/pm/pm_internal.h b/nuttx/drivers/power/pm_internal.h
index b3e610ba0..0ae4722da 100644
--- a/nuttx/drivers/pm/pm_internal.h
+++ b/nuttx/drivers/power/pm_internal.h
@@ -1,8 +1,8 @@
/****************************************************************************
- * drivers/pm/pm_internal.h
+ * drivers/power/pm_internal.h
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 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
@@ -33,8 +33,8 @@
*
****************************************************************************/
-#ifndef __DRIVERS_PM_PM_INTERNAL_H
-#define __DRIVERS_PM_PM_INTERNAL_H
+#ifndef __DRIVERS_POWER_PM_INTERNAL_H
+#define __DRIVERS_POWER_PM_INTERNAL_H
/****************************************************************************
* Included Files
@@ -45,7 +45,7 @@
#include <semaphore.h>
#include <queue.h>
-#include <nuttx/pm.h>
+#include <nuttx/power/pm.h>
#include <nuttx/wqueue.h>
#ifdef CONFIG_PM
@@ -207,4 +207,4 @@ EXTERN void pm_update(int16_t accum);
#endif
#endif /* CONFIG_PM */
-#endif /* #define __DRIVERS_PM_PM_INTERNAL_H */
+#endif /* #define __DRIVERS_POWER_PM_INTERNAL_H */
diff --git a/nuttx/drivers/pm/pm_register.c b/nuttx/drivers/power/pm_register.c
index 41d4bb836..19f94cb02 100644
--- a/nuttx/drivers/pm/pm_register.c
+++ b/nuttx/drivers/power/pm_register.c
@@ -1,8 +1,8 @@
/****************************************************************************
- * drivers/pm/pm_register.c
+ * drivers/power/pm_register.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 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
@@ -42,7 +42,7 @@
#include <queue.h>
#include <assert.h>
-#include <nuttx/pm.h>
+#include <nuttx/power/pm.h>
#include "pm_internal.h"
diff --git a/nuttx/drivers/pm/pm_update.c b/nuttx/drivers/power/pm_update.c
index 336bee5ef..ae5e1f840 100644
--- a/nuttx/drivers/pm/pm_update.c
+++ b/nuttx/drivers/power/pm_update.c
@@ -1,8 +1,8 @@
/****************************************************************************
- * drivers/pm/pm_update.c
+ * drivers/power/pm_update.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ * Copyright (C) 2011-2012 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
@@ -41,7 +41,7 @@
#include <assert.h>
-#include <nuttx/pm.h>
+#include <nuttx/power/pm.h>
#include <nuttx/wqueue.h>
#include "pm_internal.h"