2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Sky Nexus Register Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Brian Waite
|
|
|
|
*
|
|
|
|
* This driver allows reading the Nexus register
|
|
|
|
* It exports the /proc/sky_chassis_id and also
|
|
|
|
* /proc/sky_slot_id pseudo-file for status information.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/hdpu_features.h>
|
2005-10-29 12:07:23 -06:00
|
|
|
#include <linux/platform_device.h>
|
2007-10-02 14:30:09 -06:00
|
|
|
#include <linux/seq_file.h>
|
2007-10-02 14:30:06 -06:00
|
|
|
#include <asm/io.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
static int hdpu_nexus_probe(struct platform_device *pdev);
|
|
|
|
static int hdpu_nexus_remove(struct platform_device *pdev);
|
2007-10-02 14:30:09 -06:00
|
|
|
static int hdpu_slot_id_open(struct inode *inode, struct file *file);
|
|
|
|
static int hdpu_slot_id_read(struct seq_file *seq, void *offset);
|
|
|
|
static int hdpu_chassis_id_open(struct inode *inode, struct file *file);
|
|
|
|
static int hdpu_chassis_id_read(struct seq_file *seq, void *offset);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static struct proc_dir_entry *hdpu_slot_id;
|
|
|
|
static struct proc_dir_entry *hdpu_chassis_id;
|
|
|
|
static int slot_id = -1;
|
|
|
|
static int chassis_id = -1;
|
|
|
|
|
2007-10-02 14:30:09 -06:00
|
|
|
static const struct file_operations proc_slot_id = {
|
|
|
|
.open = hdpu_slot_id_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct file_operations proc_chassis_id = {
|
|
|
|
.open = hdpu_chassis_id_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
static struct platform_driver hdpu_nexus_driver = {
|
2005-04-16 16:20:36 -06:00
|
|
|
.probe = hdpu_nexus_probe,
|
|
|
|
.remove = hdpu_nexus_remove,
|
2005-11-09 15:32:44 -07:00
|
|
|
.driver = {
|
|
|
|
.name = HDPU_NEXUS_NAME,
|
2008-04-15 15:34:33 -06:00
|
|
|
.owner = THIS_MODULE,
|
2005-11-09 15:32:44 -07:00
|
|
|
},
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2007-10-02 14:30:09 -06:00
|
|
|
static int hdpu_slot_id_open(struct inode *inode, struct file *file)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-10-02 14:30:09 -06:00
|
|
|
return single_open(file, hdpu_slot_id_read, NULL);
|
|
|
|
}
|
2007-10-02 14:30:05 -06:00
|
|
|
|
2007-10-02 14:30:09 -06:00
|
|
|
static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
|
|
|
|
{
|
|
|
|
seq_printf(seq, "%d\n", slot_id);
|
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-10-02 14:30:09 -06:00
|
|
|
static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2007-10-02 14:30:09 -06:00
|
|
|
return single_open(file, hdpu_chassis_id_read, NULL);
|
|
|
|
}
|
2007-10-02 14:30:05 -06:00
|
|
|
|
2007-10-02 14:30:09 -06:00
|
|
|
static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
|
|
|
|
{
|
|
|
|
seq_printf(seq, "%d\n", chassis_id);
|
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
static int hdpu_nexus_probe(struct platform_device *pdev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
struct resource *res;
|
2007-10-02 14:30:05 -06:00
|
|
|
int *nexus_id_addr;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2007-10-02 14:30:06 -06:00
|
|
|
if (!res) {
|
|
|
|
printk(KERN_ERR "sky_nexus: "
|
|
|
|
"Invalid memory resource.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2007-10-02 14:30:05 -06:00
|
|
|
nexus_id_addr = ioremap(res->start,
|
|
|
|
(unsigned long)(res->end - res->start));
|
2005-04-16 16:20:36 -06:00
|
|
|
if (nexus_id_addr) {
|
|
|
|
slot_id = (*nexus_id_addr >> 8) & 0x1f;
|
|
|
|
chassis_id = *nexus_id_addr & 0xff;
|
|
|
|
iounmap(nexus_id_addr);
|
2007-10-02 14:30:05 -06:00
|
|
|
} else {
|
2007-10-02 14:30:06 -06:00
|
|
|
printk(KERN_ERR "sky_nexus: Could not map slot id\n");
|
2007-10-02 14:30:05 -06:00
|
|
|
}
|
|
|
|
|
2008-04-29 02:02:35 -06:00
|
|
|
hdpu_slot_id = proc_create("sky_slot_id", 0666, NULL, &proc_slot_id);
|
|
|
|
if (!hdpu_slot_id) {
|
2007-10-02 14:30:07 -06:00
|
|
|
printk(KERN_WARNING "sky_nexus: "
|
|
|
|
"Unable to create proc dir entry: sky_slot_id\n");
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-04-29 02:02:35 -06:00
|
|
|
hdpu_chassis_id = proc_create("sky_chassis_id", 0666, NULL,
|
|
|
|
&proc_chassis_id);
|
2008-04-29 02:01:44 -06:00
|
|
|
if (!hdpu_chassis_id)
|
2007-10-02 14:30:07 -06:00
|
|
|
printk(KERN_WARNING "sky_nexus: "
|
|
|
|
"Unable to create proc dir entry: sky_chassis_id\n");
|
2007-10-02 14:30:05 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-09 15:32:44 -07:00
|
|
|
static int hdpu_nexus_remove(struct platform_device *pdev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
slot_id = -1;
|
|
|
|
chassis_id = -1;
|
2007-10-02 14:30:05 -06:00
|
|
|
|
2008-04-29 02:01:44 -06:00
|
|
|
remove_proc_entry("sky_slot_id", NULL);
|
|
|
|
remove_proc_entry("sky_chassis_id", NULL);
|
2007-10-02 14:30:05 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
hdpu_slot_id = 0;
|
|
|
|
hdpu_chassis_id = 0;
|
2007-10-02 14:30:05 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init nexus_init(void)
|
|
|
|
{
|
2007-10-02 14:30:05 -06:00
|
|
|
return platform_driver_register(&hdpu_nexus_driver);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit nexus_exit(void)
|
|
|
|
{
|
2005-11-09 15:32:44 -07:00
|
|
|
platform_driver_unregister(&hdpu_nexus_driver);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(nexus_init);
|
|
|
|
module_exit(nexus_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Brian Waite");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-15 15:34:33 -06:00
|
|
|
MODULE_ALIAS("platform:" HDPU_NEXUS_NAME);
|