]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/plat-omap/dsp/dsp_ctl_core.c
8207441096b282725cf1dda5a9fce5cb732b1f0f
[linux-2.6-omap-h63xx.git] / arch / arm / plat-omap / dsp / dsp_ctl_core.c
1 /*
2  * linux/arch/arm/mach-omap/dsp/dsp_ctl_core.c
3  *
4  * OMAP DSP control devices core driver
5  *
6  * Copyright (C) 2004,2005 Nokia Corporation
7  *
8  * Written by Toshihiro Kobayashi <toshihiro.kobayashi@nokia.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  * 2005/07/26:  DSP Gateway version 3.3
25  */
26
27 #include <linux/module.h>
28 #include <linux/major.h>
29 #include <linux/fs.h>
30 #include <linux/device.h>
31 #include <linux/init.h>
32 #include <asm/arch/dsp.h>
33 #include "hardware_dsp.h"
34
35 #define CTL_MINOR       0
36 #define MEM_MINOR       1
37 #define TWCH_MINOR      2
38 #define ERR_MINOR       3
39
40 static struct class *dsp_ctl_class;
41 extern struct file_operations dsp_ctl_fops,
42                               dsp_mem_fops,
43                               dsp_twch_fops,
44                               dsp_err_fops;
45
46 static int dsp_ctl_core_open(struct inode *inode, struct file *file)
47 {
48         switch (iminor(inode)) {
49         case CTL_MINOR:
50                 file->f_op = &dsp_ctl_fops;
51                 break;
52         case MEM_MINOR:
53                 file->f_op = &dsp_mem_fops;
54                 break;
55         case TWCH_MINOR:
56                 file->f_op = &dsp_twch_fops;
57                 break;
58         case ERR_MINOR:
59                 file->f_op = &dsp_err_fops;
60                 break;
61         default:
62                 return -ENXIO;
63         }
64         if (file->f_op && file->f_op->open)
65                 return file->f_op->open(inode, file);
66         return 0;
67 }
68
69 static struct file_operations dsp_ctl_core_fops = {
70         .owner = THIS_MODULE,
71         .open  = dsp_ctl_core_open,
72 };
73
74 static const struct dev_list {
75         unsigned int    minor;
76         char            *devname;
77         umode_t         mode;
78 } dev_list[] = {
79         {CTL_MINOR,  "dspctl",  S_IRUSR | S_IWUSR},
80         {MEM_MINOR,  "dspmem",  S_IRUSR | S_IWUSR | S_IRGRP},
81         {TWCH_MINOR, "dsptwch", S_IRUSR | S_IWUSR | S_IRGRP},
82         {ERR_MINOR,  "dsperr",  S_IRUSR | S_IRGRP},
83 };
84
85 int __init dsp_ctl_core_init(void)
86 {
87         int retval;
88         int i;
89         struct class_device *cdev;
90
91         retval = register_chrdev(OMAP_DSP_CTL_MAJOR, "dspctl",
92                                  &dsp_ctl_core_fops);
93         if (retval < 0) {
94                 printk(KERN_ERR
95                        "omapdsp: failed to register dspctl device: %d\n",
96                        retval);
97                 return retval;
98         }
99
100         dsp_ctl_class = class_create(THIS_MODULE, "dspctl");
101         for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
102                 cdev = class_device_create(dsp_ctl_class, NULL,
103                                     MKDEV(OMAP_DSP_CTL_MAJOR,
104                                           dev_list[i].minor),
105                                     NULL, dev_list[i].devname);
106         }
107
108         return 0;
109 }
110
111 void dsp_ctl_core_exit(void)
112 {
113         int i;
114
115         for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
116                 class_device_destroy(dsp_ctl_class,
117                                      MKDEV(OMAP_DSP_CTL_MAJOR,
118                                            dev_list[i].minor));
119         }
120         class_destroy(dsp_ctl_class);
121
122         unregister_chrdev(OMAP_DSP_CTL_MAJOR, "dspctl");
123 }