aboutsummaryrefslogtreecommitdiffstats
path: root/src/chmtx.c
Commit message (Expand)AuthorAgeFilesLines
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@649 35acf78f-673a-0410-...gdisirio2009-01-201-11/+22
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@619 35acf78f-673a-0410-...gdisirio2009-01-111-9/+9
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@495 35acf78f-673a-0410-...gdisirio2008-11-031-1/+1
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@474 35acf78f-673a-0410-...gdisirio2008-10-171-2/+6
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@430 35acf78f-673a-0410-...gdisirio2008-09-111-14/+16
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@426 35acf78f-673a-0410-...gdisirio2008-09-061-3/+2
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@359 35acf78f-673a-0410-...gdisirio2008-07-261-6/+4
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@346 35acf78f-673a-0410-...gdisirio2008-07-221-243/+260
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@225 35acf78f-673a-0410-...gdisirio2008-03-121-3/+3
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@215 35acf78f-673a-0410-...gdisirio2008-03-051-5/+5
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@212 35acf78f-673a-0410-...gdisirio2008-03-031-3/+3
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@170 35acf78f-673a-0410-...gdisirio2008-01-081-3/+11
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@165 35acf78f-673a-0410-...gdisirio2008-01-071-3/+6
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@159 35acf78f-673a-0410-...gdisirio2007-12-231-17/+3
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@157 35acf78f-673a-0410-...gdisirio2007-12-221-1/+1
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@156 35acf78f-673a-0410-...gdisirio2007-12-221-3/+31
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@155 35acf78f-673a-0410-...gdisirio2007-12-221-30/+4
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@152 35acf78f-673a-0410-...gdisirio2007-12-201-2/+9
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@151 35acf78f-673a-0410-...gdisirio2007-12-191-12/+0
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@142 35acf78f-673a-0410-...gdisirio2007-12-171-6/+6
* git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@141 35acf78f-673a-0410-...gdisirio2007-12-161-0/+249
olor: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * Copyright (C) 2007 Nicolas Thill <nico@openwrt.org>
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <linux/device.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include <linux/types.h>
#include <linux/cdev.h>
#include <gpio.h>

#define DRVNAME "ar7_gpio"
#define LONGNAME "TI AR7 GPIOs Driver"

MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
MODULE_DESCRIPTION(LONGNAME);
MODULE_LICENSE("GPL");

static int ar7_gpio_major;

static ssize_t ar7_gpio_write(struct file *file, const char __user *buf,
	size_t len, loff_t *ppos)
{
	int pin = iminor(file->f_dentry->d_inode);
	size_t i;

	for (i = 0; i < len; ++i) {
		char c;
		if (get_user(c, buf + i))
			return -EFAULT;
		switch (c) {
		case '0':
			gpio_set_value(pin, 0);
			break;
		case '1':
			gpio_set_value(pin, 1);
			break;
		case 'd':
		case 'D':
			ar7_gpio_disable(pin);
			break;
		case 'e':
		case 'E':
			ar7_gpio_enable(pin);
			break;
		case 'i':
		case 'I':
		case '<':
			gpio_direction_input(pin);
			break;
		case 'o':
		case 'O':
		case '>':
			gpio_direction_output(pin, 0);
			break;
		default:
			return -EINVAL;
		}
	}

	return len;
}

static ssize_t ar7_gpio_read(struct file *file, char __user *buf,
	size_t len, loff_t *ppos)
{
	int pin = iminor(file->f_dentry->d_inode);
	int value;

	value = gpio_get_value(pin);
	if (put_user(value ? '1' : '0', buf))
		return -EFAULT;

	return 1;
}

static int ar7_gpio_open(struct inode *inode, struct file *file)
{
	int m = iminor(inode);

	if (m >= (ar7_is_titan() ? TITAN_GPIO_MAX : AR7_GPIO_MAX))
		return -EINVAL;

	return nonseekable_open(inode, file);
}

static int ar7_gpio_release(struct inode *inode, struct file *file)
{
	return 0;
}