3 * drivers/char/vrc4173.c
5 * BRIEF MODULE DESCRIPTION
6 * NEC VRC4173 driver for NEC VR4122/VR4131.
9 * yyuasa@mvista.com or source@mvista.com
11 * Copyright 2001,2002 MontaVista Software Inc.
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/init.h>
34 #include <linux/module.h>
35 #include <linux/interrupt.h>
36 #include <linux/irq.h>
37 #include <linux/pci.h>
38 #include <linux/types.h>
40 #include <asm/vr41xx/vr41xx.h>
41 #include <asm/vr41xx/vrc4173.h>
43 MODULE_DESCRIPTION("NEC VRC4173 driver for NEC VR4122/4131");
44 MODULE_AUTHOR("Yoichi Yuasa <yyuasa@mvista.com>");
45 MODULE_LICENSE("GPL");
47 #define VRC4173_CMUCLKMSK 0x040
48 #define VRC4173_CMUSRST 0x042
50 #define VRC4173_SELECTREG 0x09e
52 #define VRC4173_SYSINT1REG 0x060
53 #define VRC4173_MSYSINT1REG 0x06c
55 static struct pci_device_id vrc4173_table[] = {
56 {PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_VRC4173, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
60 unsigned long vrc4173_io_offset = 0;
62 EXPORT_SYMBOL(vrc4173_io_offset);
64 static u16 vrc4173_cmuclkmsk;
65 static int vrc4173_initialized;
67 void vrc4173_clock_supply(u16 mask)
69 if (vrc4173_initialized) {
70 vrc4173_cmuclkmsk |= mask;
71 vrc4173_outw(vrc4173_cmuclkmsk, VRC4173_CMUCLKMSK);
75 void vrc4173_clock_mask(u16 mask)
77 if (vrc4173_initialized) {
78 vrc4173_cmuclkmsk &= ~mask;
79 vrc4173_outw(vrc4173_cmuclkmsk, VRC4173_CMUCLKMSK);
83 static inline void vrc4173_cmu_init(void)
85 vrc4173_cmuclkmsk = vrc4173_inw(VRC4173_CMUCLKMSK);
88 EXPORT_SYMBOL(vrc4173_clock_supply);
89 EXPORT_SYMBOL(vrc4173_clock_mask);
91 void vrc4173_select_function(int func)
95 if (vrc4173_initialized) {
96 val = vrc4173_inw(VRC4173_SELECTREG);
104 case TOUCHPANEL_SELECT:
120 vrc4173_outw(val, VRC4173_SELECTREG);
124 EXPORT_SYMBOL(vrc4173_select_function);
126 static void enable_vrc4173_irq(unsigned int irq)
130 val = vrc4173_inw(VRC4173_MSYSINT1REG);
131 val |= (u16)1 << (irq - VRC4173_IRQ_BASE);
132 vrc4173_outw(val, VRC4173_MSYSINT1REG);
135 static void disable_vrc4173_irq(unsigned int irq)
139 val = vrc4173_inw(VRC4173_MSYSINT1REG);
140 val &= ~((u16)1 << (irq - VRC4173_IRQ_BASE));
141 vrc4173_outw(val, VRC4173_MSYSINT1REG);
144 static unsigned int startup_vrc4173_irq(unsigned int irq)
146 enable_vrc4173_irq(irq);
147 return 0; /* never anything pending */
150 #define shutdown_vrc4173_irq disable_vrc4173_irq
151 #define ack_vrc4173_irq disable_vrc4173_irq
153 static void end_vrc4173_irq(unsigned int irq)
155 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
156 enable_vrc4173_irq(irq);
159 static struct hw_interrupt_type vrc4173_irq_type = {
162 shutdown_vrc4173_irq,
170 static int vrc4173_get_irq_number(int irq)
175 status = vrc4173_inw(VRC4173_SYSINT1REG);
176 mask = vrc4173_inw(VRC4173_MSYSINT1REG);
180 for (i = 0; i < 16; i++)
181 if (status & (0x0001 << i))
182 return VRC4173_IRQ_BASE + i;
188 static inline void vrc4173_icu_init(int cascade_irq)
192 if (cascade_irq < GIU_IRQ(0) || cascade_irq > GIU_IRQ(15))
195 vrc4173_outw(0, VRC4173_MSYSINT1REG);
197 vr41xx_set_irq_trigger(GIU_IRQ_TO_PIN(cascade_irq), TRIGGER_LEVEL, SIGNAL_THROUGH);
198 vr41xx_set_irq_level(GIU_IRQ_TO_PIN(cascade_irq), LEVEL_LOW);
200 for (i = VRC4173_IRQ_BASE; i <= VRC4173_IRQ_LAST; i++)
201 irq_desc[i].handler = &vrc4173_irq_type;
204 static int __devinit vrc4173_probe(struct pci_dev *pdev,
205 const struct pci_device_id *ent)
207 unsigned long start, flags;
210 if ((err = pci_enable_device(pdev)) < 0) {
211 printk(KERN_ERR "vrc4173: failed to enable device -- err=%d\n", err);
215 pci_set_master(pdev);
217 start = pci_resource_start(pdev, 0);
219 printk(KERN_ERR "vrc4173:No PCI I/O resources, aborting\n");
223 if (!start || (((flags = pci_resource_flags(pdev, 0)) & IORESOURCE_IO) == 0)) {
224 printk(KERN_ERR "vrc4173: No PCI I/O resources, aborting\n");
228 if ((err = pci_request_regions(pdev, "NEC VRC4173")) < 0) {
229 printk(KERN_ERR "vrc4173: PCI resources are busy, aborting\n");
233 set_vrc4173_io_offset(start);
237 vrc4173_icu_init(pdev->irq);
239 if ((err = vr41xx_cascade_irq(pdev->irq, vrc4173_get_irq_number)) < 0) {
241 "vrc4173: IRQ resource %d is busy, aborting\n", pdev->irq);
246 "NEC VRC4173 at 0x%#08lx, IRQ is cascaded to %d\n", start, pdev->irq);
251 static struct pci_driver vrc4173_driver = {
252 .name = "NEC VRC4173",
253 .probe = vrc4173_probe,
255 .id_table = vrc4173_table,
258 static int __devinit vrc4173_init(void)
262 if ((err = pci_module_init(&vrc4173_driver)) < 0)
265 vrc4173_initialized = 1;
270 static void __devexit vrc4173_exit(void)
272 vrc4173_initialized = 0;
274 pci_unregister_driver(&vrc4173_driver);
277 module_init(vrc4173_init);
278 module_exit(vrc4173_exit);