[aadk-commits] dbailey: uClinux/trunk r88 - /uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/...

aadk-commits at lists.digium.com aadk-commits at lists.digium.com
Wed Dec 27 13:08:45 MST 2006


Author: dbailey
Date: Wed Dec 27 14:08:44 2006
New Revision: 88

URL: http://svn.digium.com/view/aadk?view=rev&rev=88
Log:
Adding simple configuration switch driver to read config switch on Blackfin Port G

Added:
    uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c   (with props)
    uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h   (with props)
Modified:
    uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/Makefile

Modified: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/Makefile
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/Makefile?view=diff&rev=88&r1=87&r2=88
==============================================================================
--- uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/Makefile (original)
+++ uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/Makefile Wed Dec 27 14:08:44 2006
@@ -4,5 +4,6 @@
 EXTRA_CFLAGS += -Idrivers/zaptel
 obj-$(CONFIG_ZAPTEL) += zaptel.o
 obj-$(CONFIG_SX00I) += sx00i.o
+obj-$(CONFIG_SX00I) += sx00i_cfgswx.o
 obj-$(CONFIG_ZTDUMMY) += ztdummy.o
 obj-$(CONFIG_WCTDM24XXP) += wctdm24xxp.o

Added: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c?view=auto&rev=88
==============================================================================
--- uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c (added)
+++ uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c Wed Dec 27 14:08:44 2006
@@ -1,0 +1,233 @@
+/*
+ * Sx00i Appliance Configuration Change Switch Reader
+ *
+ * Written by Doug Bailey <dbailey at digium.com>
+ *
+ * Copyright (C) 2006, Digium, Inc.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/interrupt.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/sched.h>
+#include <linux/proc_fs.h>
+#include <linux/cdev.h>
+
+#include <asm/blackfin.h>
+#include <asm/cacheflush.h>
+#include <asm/irq.h>
+
+/* Uncomment to enable VPM support */
+/*#define VPM_SUPPORT */
+
+#include "sx00i_cfgswx.h"
+
+#ifdef LINUX26
+#include <linux/moduleparam.h>
+#endif
+
+#define SSYNC __builtin_bfin_ssync()
+
+/*  Configuration switch resides on 10th bit of PORT G Register */
+#define CFG_SWX_BIT		(1 << 9)
+
+/*** Static Prototypes **/
+static int sx00_cfgswx_ioctl(struct inode * p_inode, struct file * p_file, unsigned int cmd, unsigned long arg);
+static ssize_t sx00_cfgswx_read(struct file * p_file, char __user * buffer, size_t buf_size, loff_t * offset);
+
+static inline int sx00_cfgswx_get_config_switch_state(void);
+
+struct cfg_swx_dev {
+
+	spinlock_t	reglock;
+	struct cdev	cdev;
+};
+
+struct file_operations cfg_swx_fops =  {
+	.owner	= THIS_MODULE,
+	.read	= sx00_cfgswx_read,
+	.ioctl	= sx00_cfgswx_ioctl,
+};
+
+struct cfg_swx_dev cfg_swx;
+
+
+/* Access to the registers within the Blackfin
+ *	SSYNC guarantees that order of accesses to the blackfin io registers is maintained 
+ */
+static inline void sx00_setctl(unsigned int addr, unsigned int val)
+{
+	*((volatile unsigned short *)(addr)) = val;
+	SSYNC;
+}
+
+static inline unsigned int sx00_getctl(unsigned int addr)
+{
+	return (*((volatile unsigned short *)(addr)));
+}
+
+/*
+ * ioctl call - Only command is to return the switch state 
+ */
+static int sx00_cfgswx_ioctl(struct inode * p_inode, struct file * p_file, unsigned int cmd, unsigned long arg)
+{
+	switch (cmd) {
+	case SX00_IOCTL_GET_CFG_SWX:
+		return sx00_cfgswx_get_config_switch_state();
+	default:
+		return -ENOTTY;
+	}
+	return 0;
+}
+
+/*
+ *	simple read that returns a single byte that is the switch state
+ */
+static ssize_t sx00_cfgswx_read(struct file * p_file, char __user * buffer, size_t buf_size, loff_t * offset)
+{
+	unsigned char swx_state;
+	
+	swx_state	= (unsigned char)(sx00_cfgswx_get_config_switch_state());
+	/* If I have room for the data and can copy it to user space */
+	if(0 < buf_size && !copy_to_user(buffer, &swx_state, 1)) {
+		return 1;  /* I read 1 byte of data */
+	} else {
+		return -EINVAL;  /* bad call */
+	}
+} 
+
+
+/* 
+ * Configure the PORT G control registers to allow for access to the 
+ * Configuration Reset switch input.
+ *
+ */
+static void sx00_setup_config_switch(int enable)
+{
+	unsigned int portg_data;
+	unsigned long flags;
+
+	/* No interrupts while I am writing registers */
+	spin_lock_irqsave(&cfg_swx.reglock, flags);
+
+	portg_data = sx00_getctl(PORTG_FER) & ~CFG_SWX_BIT;;
+	sx00_setctl(PORTG_FER, portg_data);
+	__builtin_bfin_ssync();
+
+	portg_data = sx00_getctl(PORTGIO_DIR) & ~CFG_SWX_BIT;
+	sx00_setctl(PORTGIO_DIR, portg_data);	
+	__builtin_bfin_ssync();
+
+	portg_data = sx00_getctl(PORTGIO_INEN);
+	if(enable) {
+		portg_data |= CFG_SWX_BIT;
+	} else {
+		portg_data &= ~CFG_SWX_BIT;
+	} 
+	sx00_setctl(PORTGIO_INEN, portg_data);
+	__builtin_bfin_ssync();
+
+	spin_unlock_irqrestore(&cfg_swx.reglock, flags);
+
+	return;
+}
+
+/* 
+ * 	Returns the state of the switch.  
+ * 	0 if not active, 1 if active
+ */
+static inline int sx00_cfgswx_get_config_switch_state(void)
+{
+	unsigned int val;
+
+	val  = sx00_getctl(PORTGIO_SET);
+	return 	(val & (CFG_SWX_BIT)) ? 0 : 1; 
+}
+
+/*
+ * 	Proc filesystem read function 
+ *		Allows the switch state to be read via a /proc call
+ */
+static int sx00_cfgswx_proc_read_swx(char * buf, char ** start, off_t offset, int count, int * eof, void * data)
+{
+	int switch_state, len; 
+
+	switch_state = sx00_cfgswx_get_config_switch_state();
+	len = sprintf(buf, "CFGSWX=%d\n", switch_state);
+	*eof	= 1;
+
+	return len;
+}
+
+/* 
+ * 	Module Initialization 
+ */
+static int __init sx00_cfgswx_init(void)
+{
+	int devno, err; 
+
+	devno = MKDEV(ZT_MAJOR, 240);
+	printk("Installing device %s -- Major %d, Minor %d\n", CFG_SWX_DEV_FNAME, MAJOR(devno), MINOR(devno));
+
+	cdev_init(&cfg_swx.cdev, &cfg_swx_fops);
+	cfg_swx.cdev.owner	= THIS_MODULE;
+	cfg_swx.cdev.ops 	= &cfg_swx_fops;
+	err = cdev_add(&cfg_swx.cdev, devno, 1);
+	if (err) {
+		printk("CFGSWX Error loading %s device: (%d)\n", CFG_SWX_DEV_FNAME, err);
+	}
+
+	spin_lock_init(&cfg_swx.reglock);
+	sx00_setup_config_switch(1);
+
+#ifdef CONFIG_PROC_FS
+	create_proc_read_entry(CFG_SWX_PROC_FNAME, 0, NULL, sx00_cfgswx_proc_read_swx, NULL);
+#endif
+	return 0;
+}
+/* 
+ * 	Module level cleanup
+ */
+static void __exit sx00_cfgswx_cleanup(void)
+{
+	/* Turn off the Config switch input **/
+	sx00_setup_config_switch(0);
+	/* detach from the OS */
+	remove_proc_entry(CFG_SWX_PROC_FNAME, NULL);
+	cdev_del(&cfg_swx.cdev);
+	return;
+}
+
+MODULE_DESCRIPTION("Sx00I Configuration Switch Driver");
+MODULE_AUTHOR("Doug Bailey <dbailey at digium.com>");
+#ifdef MODULE_LICENSE
+MODULE_LICENSE("GPL");
+#endif
+
+module_init(sx00_cfgswx_init);
+module_exit(sx00_cfgswx_cleanup);
+
+
+

Propchange: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h?view=auto&rev=88
==============================================================================
--- uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h (added)
+++ uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h Wed Dec 27 14:08:44 2006
@@ -1,0 +1,41 @@
+/*
+ * Zapata Telephony Interface
+ *
+ * Written by Doug Bailey <dbailey at digium.com>
+ *
+ * Copyright (C) 2006 Digium, Inc.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+#ifndef _SX00I_CFGSWX_H
+#define _SX00I_CFGSWX_H
+
+#ifdef STANDALONE_ZAPATA
+#include "zaptel.h"
+#else
+#include <zaptel/zaptel.h>
+#endif
+
+/* IOCTL Call Definition */
+#define SX00_IOCTL_GET_CFG_SWX	_IOR (ZT_CODE, 1, int)
+
+#define CFG_SWX_PROC_FNAME	"cfgswx"
+#define CFG_SWX_DEV_FNAME	"cfgswx"
+
+#endif /* _SX00I_CFGSWX_H */

Propchange: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uClinux/trunk/uClinux-dist/linux-2.6.x/drivers/zaptel/sx00i_cfgswx.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain



More information about the aadk-commits mailing list