1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2025-04-21 12:27:27 +03:00

Add ar7-2.6 port (marked as broken for now).

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@6600 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
ejka
2007-03-18 09:40:51 +00:00
parent 865cfde1ef
commit 8c72b797b4
33 changed files with 5058 additions and 0 deletions

View File

@@ -0,0 +1,160 @@
/*
* linux/drivers/char/ar7_gpio.c
*
* Copyright (C) 2007 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 <asm/uaccess.h>
#include <asm/io.h>
#include <linux/types.h>
#include <linux/cdev.h>
#include <asm/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 = 0;
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);
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_GPIO_MAX)
return -EINVAL;
return nonseekable_open(inode, file);
}
static int ar7_gpio_release(struct inode *inode, struct file *file)
{
return 0;
}
static const struct file_operations ar7_gpio_fops = {
.owner = THIS_MODULE,
.write = ar7_gpio_write,
.read = ar7_gpio_read,
.open = ar7_gpio_open,
.release = ar7_gpio_release,
.llseek = no_llseek,
};
static struct platform_device *ar7_gpio_device;
static int __init ar7_gpio_init(void)
{
int rc;
ar7_gpio_device = platform_device_alloc(DRVNAME, -1);
if (!ar7_gpio_device)
return -ENOMEM;
rc = platform_device_add(ar7_gpio_device);
if (rc < 0)
goto out_put;
rc = register_chrdev(ar7_gpio_major, DRVNAME, &ar7_gpio_fops);
if (rc < 0)
goto out_put;
ar7_gpio_major = rc;
goto out;
out_put:
platform_device_put(ar7_gpio_device);
out:
return rc;
}
static void __exit ar7_gpio_exit(void)
{
unregister_chrdev(ar7_gpio_major, DRVNAME);
platform_device_unregister(ar7_gpio_device);
}
module_init(ar7_gpio_init);
module_exit(ar7_gpio_exit);

View File

@@ -0,0 +1,332 @@
/*
* linux/drivers/char/ar7_wdt.c
*
* Copyright (C) 2007 OpenWrt.org
* Copyright (c) 2005 Enrik Berkhan <Enrik.Berkhan@akk.org>
*
* Some code taken from:
* National Semiconductor SCx200 Watchdog support
* Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
*
* 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/module.h>
#include <linux/moduleparam.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/watchdog.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
#include <linux/fs.h>
#include <linux/ioport.h>
#include <asm/addrspace.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/ar7/ar7.h>
#define DRVNAME "ar7_wdt"
#define LONGNAME "TI AR7 Watchdog Timer"
MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
MODULE_DESCRIPTION(LONGNAME);
MODULE_LICENSE("GPL");
MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
static int margin = 60;
module_param(margin, int, 0);
MODULE_PARM_DESC(margin, "Watchdog margin in seconds");
static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
typedef struct {
u32 kick_lock;
u32 kick;
u32 change_lock;
u32 change ;
u32 disable_lock;
u32 disable;
u32 prescale_lock;
u32 prescale;
} ar7_wdt_t;
static struct semaphore open_semaphore;
static unsigned expect_close;
/* XXX correct? assumed to be sysfreq/2. get this dynamically ... */
#define vbus_freq (ar7_bus_freq() / 2)
/* XXX currently fixed, allows max margin ~68.72 secs */
#define prescale_value 0xFFFF
static void ar7_wdt_kick(u32 value)
{
volatile ar7_wdt_t *ar7_wdt = (ar7_wdt_t *)ioremap(AR7_REGS_WDT, sizeof(ar7_wdt_t));
ar7_wdt->kick_lock = 0x5555;
if ((ar7_wdt->kick_lock & 3) == 1) {
ar7_wdt->kick_lock = 0xAAAA;
if ((ar7_wdt->kick_lock & 3) == 3) {
ar7_wdt->kick = value;
return;
}
}
printk(KERN_ERR DRVNAME ": failed to unlock WDT kick reg\n");
}
static void ar7_wdt_prescale(u32 value)
{
volatile ar7_wdt_t *ar7_wdt = (ar7_wdt_t *)ioremap(AR7_REGS_WDT, sizeof(ar7_wdt_t));
ar7_wdt->prescale_lock = 0x5A5A;
if ((ar7_wdt->prescale_lock & 3) == 1) {
ar7_wdt->prescale_lock = 0xA5A5;
if ((ar7_wdt->prescale_lock & 3) == 3) {
ar7_wdt->prescale = value;
return;
}
}
printk(KERN_ERR DRVNAME ": failed to unlock WDT prescale reg\n");
}
static void ar7_wdt_change(u32 value)
{
volatile ar7_wdt_t *ar7_wdt = (ar7_wdt_t *)ioremap(AR7_REGS_WDT, sizeof(ar7_wdt_t));
ar7_wdt->change_lock = 0x6666;
if ((ar7_wdt->change_lock & 3) == 1) {
ar7_wdt->change_lock = 0xBBBB;
if ((ar7_wdt->change_lock & 3) == 3) {
ar7_wdt->change = value;
return;
}
}
printk(KERN_ERR DRVNAME ": failed to unlock WDT change reg\n");
}
static void ar7_wdt_disable(u32 value)
{
volatile ar7_wdt_t *ar7_wdt = (ar7_wdt_t *)ioremap(AR7_REGS_WDT, sizeof(ar7_wdt_t));
ar7_wdt->disable_lock = 0x7777;
if ((ar7_wdt->disable_lock & 3) == 1) {
ar7_wdt->disable_lock = 0xCCCC;
if ((ar7_wdt->disable_lock & 3) == 2) {
ar7_wdt->disable_lock = 0xDDDD;
if ((ar7_wdt->disable_lock & 3) == 3) {
ar7_wdt->disable = value;
return;
}
}
}
printk(KERN_ERR DRVNAME ": failed to unlock WDT disable reg\n");
}
static void ar7_wdt_update_margin(int new_margin)
{
u32 change;
change = new_margin * (vbus_freq / prescale_value);
if (change < 1) change = 1;
if (change > 0xFFFF) change = 0xFFFF;
ar7_wdt_change(change);
margin = change * prescale_value / vbus_freq;
printk(KERN_INFO DRVNAME
": timer margin %d seconds (prescale %d, change %d, freq %d)\n",
margin, prescale_value, change, vbus_freq);
}
static void ar7_wdt_enable_wdt(void)
{
printk(KERN_DEBUG DRVNAME ": enabling watchdog timer\n");
ar7_wdt_disable(1);
ar7_wdt_kick(1);
}
static void ar7_wdt_disable_wdt(void)
{
printk(KERN_DEBUG DRVNAME ": disabling watchdog timer\n");
ar7_wdt_disable(0);
}
static int ar7_wdt_open(struct inode *inode, struct file *file)
{
/* only allow one at a time */
if (down_trylock(&open_semaphore))
return -EBUSY;
ar7_wdt_enable_wdt();
expect_close = 0;
return 0;
}
static int ar7_wdt_release(struct inode *inode, struct file *file)
{
if (!expect_close) {
printk(KERN_WARNING DRVNAME ": watchdog device closed unexpectedly, will not disable the watchdog timer\n");
} else if (!nowayout) {
ar7_wdt_disable_wdt();
}
up(&open_semaphore);
return 0;
}
static int ar7_wdt_notify_sys(struct notifier_block *this,
unsigned long code, void *unused)
{
if (code == SYS_HALT || code == SYS_POWER_OFF)
if (!nowayout)
ar7_wdt_disable_wdt();
return NOTIFY_DONE;
}
static struct notifier_block ar7_wdt_notifier =
{
.notifier_call = ar7_wdt_notify_sys
};
static ssize_t ar7_wdt_write(struct file *file, const char *data,
size_t len, loff_t *ppos)
{
if (ppos != &file->f_pos)
return -ESPIPE;
/* check for a magic close character */
if (len) {
size_t i;
ar7_wdt_kick(1);
expect_close = 0;
for (i = 0; i < len; ++i) {
char c;
if (get_user(c, data+i))
return -EFAULT;
if (c == 'V')
expect_close = 1;
}
}
return len;
}
static int ar7_wdt_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
static struct watchdog_info ident = {
.identity = LONGNAME,
.firmware_version = 1,
.options = (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING),
};
int new_margin;
switch (cmd) {
default:
return -ENOTTY;
case WDIOC_GETSUPPORT:
if(copy_to_user((struct watchdog_info *)arg, &ident,
sizeof(ident)))
return -EFAULT;
return 0;
case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS:
if (put_user(0, (int *)arg))
return -EFAULT;
return 0;
case WDIOC_KEEPALIVE:
ar7_wdt_kick(1);
return 0;
case WDIOC_SETTIMEOUT:
if (get_user(new_margin, (int *)arg))
return -EFAULT;
if (new_margin < 1)
return -EINVAL;
ar7_wdt_update_margin(new_margin);
ar7_wdt_kick(1);
case WDIOC_GETTIMEOUT:
if (put_user(margin, (int *)arg))
return -EFAULT;
return 0;
}
}
static struct file_operations ar7_wdt_fops = {
.owner = THIS_MODULE,
.write = ar7_wdt_write,
.ioctl = ar7_wdt_ioctl,
.open = ar7_wdt_open,
.release = ar7_wdt_release,
};
static struct miscdevice ar7_wdt_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &ar7_wdt_fops,
};
static int __init ar7_wdt_init(void)
{
int rc;
if (!request_mem_region(AR7_REGS_WDT, sizeof(ar7_wdt_t), LONGNAME)) {
printk(KERN_WARNING DRVNAME ": watchdog I/O region busy\n");
return -EBUSY;
}
ar7_wdt_disable_wdt();
ar7_wdt_prescale(prescale_value);
ar7_wdt_update_margin(margin);
sema_init(&open_semaphore, 1);
rc = misc_register(&ar7_wdt_miscdev);
if (rc) {
printk(KERN_ERR DRVNAME ": unable to register misc device\n");
goto out_alloc;
}
rc = register_reboot_notifier(&ar7_wdt_notifier);
if (rc) {
printk(KERN_ERR DRVNAME ": unable to register reboot notifier\n");
goto out_register;
}
goto out;
out_register:
misc_deregister(&ar7_wdt_miscdev);
out_alloc:
release_mem_region(AR7_REGS_WDT, sizeof(ar7_wdt_t));
out:
return rc;
}
static void __exit ar7_wdt_cleanup(void)
{
unregister_reboot_notifier(&ar7_wdt_notifier);
misc_deregister(&ar7_wdt_miscdev);
release_mem_region(AR7_REGS_WDT, sizeof(ar7_wdt_t));
}
module_init(ar7_wdt_init);
module_exit(ar7_wdt_cleanup);

View File

@@ -0,0 +1,132 @@
/*
* linux/drivers/leds/leds-ar7.c
*
* Copyright (C) 2007 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/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/leds.h>
#include <linux/err.h>
#include <asm/io.h>
#include <asm/gpio.h>
#define DRVNAME "ar7-leds"
#define LONGNAME "TI AR7 LEDs driver"
MODULE_AUTHOR("Nicolas Thill <nico@openwrt.org>");
MODULE_DESCRIPTION(LONGNAME);
MODULE_LICENSE("GPL");
static void ar7_status_led_set(struct led_classdev *pled,
enum led_brightness value)
{
gpio_set_value(AR7_GPIO_BIT_STATUS_LED, value ? 0 : 1);
}
static struct led_classdev ar7_status_led = {
.name = "ar7:status",
.brightness_set = ar7_status_led_set,
};
#ifdef CONFIG_PM
static int ar7_leds_suspend(struct platform_device *dev,
pm_message_t state)
{
led_classdev_suspend(&ar7_status_led);
return 0;
}
static int ar7_leds_resume(struct platform_device *dev)
{
led_classdev_resume(&ar7_status_led);
return 0;
}
#else /* CONFIG_PM */
#define ar7_leds_suspend NULL
#define ar7_leds_resume NULL
#endif /* CONFIG_PM */
static int ar7_leds_probe(struct platform_device *pdev)
{
int rc;
rc = led_classdev_register(&pdev->dev, &ar7_status_led);
if (rc < 0 )
goto out;
ar7_gpio_enable(AR7_GPIO_BIT_STATUS_LED);
gpio_direction_output(AR7_GPIO_BIT_STATUS_LED);
out:
return rc;
}
static int ar7_leds_remove(struct platform_device *pdev)
{
led_classdev_unregister(&ar7_status_led);
return 0;
}
static struct platform_device *ar7_leds_device;
static struct platform_driver ar7_leds_driver = {
.probe = ar7_leds_probe,
.remove = ar7_leds_remove,
.suspend = ar7_leds_suspend,
.resume = ar7_leds_resume,
.driver = {
.name = DRVNAME,
},
};
static int __init ar7_leds_init(void)
{
int rc;
ar7_leds_device = platform_device_alloc(DRVNAME, -1);
if (!ar7_leds_device)
return -ENOMEM;
rc = platform_device_add(ar7_leds_device);
if (rc < 0)
goto out_put;
rc = platform_driver_register(&ar7_leds_driver);
if (rc < 0)
goto out_put;
goto out;
out_put:
platform_device_put(ar7_leds_device);
out:
return rc;
}
static void __exit ar7_leds_exit(void)
{
platform_driver_unregister(&ar7_leds_driver);
platform_device_unregister(ar7_leds_device);
}
module_init(ar7_leds_init);
module_exit(ar7_leds_exit);

View File

@@ -0,0 +1,139 @@
/*
* $Id$
*
* Copyright (C) 2007 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
*
* TI AR7 flash partition table.
* Based on ar7 map by Felix Fietkau.
*
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/bootmem.h>
#include <linux/squashfs_fs.h>
struct ar7_bin_rec {
unsigned int checksum;
unsigned int length;
unsigned int address;
};
static struct mtd_partition ar7_parts[5];
static int create_mtd_partitions(struct mtd_info *master,
struct mtd_partition **pparts,
unsigned long origin)
{
char sig[8];
struct ar7_bin_rec header;
unsigned int offset, new_offset, len;
struct squashfs_super_block sb;
unsigned int block_size = 0x10000, pre_size = 0x10000,
post_size = 0, root_offset = 0xe0000;
unsigned int p = 3;
printk("Parsing AR7 partition map...\n");
ar7_parts[0].name = "loader";
ar7_parts[0].offset = 0;
ar7_parts[0].size = block_size;
ar7_parts[0].mask_flags = MTD_WRITEABLE;
ar7_parts[1].name = "config";
ar7_parts[1].size = block_size;
ar7_parts[1].mask_flags = 0;
master->read(master, block_size, 8, &len, sig);
if (strncmp(sig, "TIENV0.8", 8)) {
ar7_parts[1].offset = master->size - block_size;
post_size = block_size;
} else {
ar7_parts[1].offset = block_size;
pre_size = block_size * 2;
}
ar7_parts[2].name = "linux";
ar7_parts[2].offset = pre_size;
ar7_parts[2].size = master->size - block_size * 2;
ar7_parts[2].mask_flags = 0;
offset = pre_size;
master->read(master, offset, sizeof(header), &len, (u_char *)&header);
if (header.checksum != 0xfeedfa42) {
printk("Unknown magic: %08x\n", header.checksum);
} else {
while (header.length) {
offset += sizeof(header) + header.length;
master->read(master, offset, sizeof(header),
&len, (u_char *)&header);
}
root_offset = offset + sizeof(header) + 4;
}
ar7_parts[p].name = "rootfs";
ar7_parts[p].offset = root_offset;
ar7_parts[p].size = master->size - root_offset - post_size;
ar7_parts[p++].mask_flags = 0;
master->read(master, root_offset, sizeof(sb), &len, (u_char *)&sb);
if (sb.s_magic == SQUASHFS_MAGIC) {
printk("Squashfs detected (size %Ld)\n", sb.bytes_used);
new_offset = root_offset + sb.bytes_used;
if ((new_offset % master->erasesize) > 0)
new_offset += master->erasesize -
(new_offset % master->erasesize);
ar7_parts[p].name = "rootfs_data";
ar7_parts[p].offset = new_offset;
ar7_parts[p].size = master->size - new_offset - post_size;
ar7_parts[p - 1].size -= ar7_parts[p].size;
ar7_parts[p - 1].mask_flags |= MTD_WRITEABLE;
ar7_parts[p++].mask_flags = 0;
} else {
printk("Squashfs not found. Moving rootfs partition to next erase block\n");
if ((root_offset % master->erasesize) > 0)
root_offset += master->erasesize -
(root_offset % master->erasesize);
ar7_parts[p].offset = root_offset;
ar7_parts[p].size = master->size - root_offset - post_size;
}
*pparts = ar7_parts;
return p;
}
static struct mtd_part_parser ar7_parser = {
.owner = THIS_MODULE,
.parse_fn = create_mtd_partitions,
.name = "ar7part",
};
static int __init ar7_parser_init(void)
{
return register_mtd_parser(&ar7_parser);
}
module_init(ar7_parser_init);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Felix Fietkau, Eugene Konev");
MODULE_DESCRIPTION("MTD partitioning for TI AR7");

File diff suppressed because it is too large Load Diff