Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _I8042_SPARCIO_H
0003 #define _I8042_SPARCIO_H
0004 
0005 #include <linux/of_device.h>
0006 
0007 #include <asm/io.h>
0008 #include <asm/oplib.h>
0009 #include <asm/prom.h>
0010 
0011 static int i8042_kbd_irq = -1;
0012 static int i8042_aux_irq = -1;
0013 #define I8042_KBD_IRQ i8042_kbd_irq
0014 #define I8042_AUX_IRQ i8042_aux_irq
0015 
0016 #define I8042_KBD_PHYS_DESC "sparcps2/serio0"
0017 #define I8042_AUX_PHYS_DESC "sparcps2/serio1"
0018 #define I8042_MUX_PHYS_DESC "sparcps2/serio%d"
0019 
0020 static void __iomem *kbd_iobase;
0021 
0022 #define I8042_COMMAND_REG   (kbd_iobase + 0x64UL)
0023 #define I8042_DATA_REG      (kbd_iobase + 0x60UL)
0024 
0025 static inline int i8042_read_data(void)
0026 {
0027     return readb(kbd_iobase + 0x60UL);
0028 }
0029 
0030 static inline int i8042_read_status(void)
0031 {
0032     return readb(kbd_iobase + 0x64UL);
0033 }
0034 
0035 static inline void i8042_write_data(int val)
0036 {
0037     writeb(val, kbd_iobase + 0x60UL);
0038 }
0039 
0040 static inline void i8042_write_command(int val)
0041 {
0042     writeb(val, kbd_iobase + 0x64UL);
0043 }
0044 
0045 #ifdef CONFIG_PCI
0046 
0047 static struct resource *kbd_res;
0048 
0049 #define OBP_PS2KBD_NAME1    "kb_ps2"
0050 #define OBP_PS2KBD_NAME2    "keyboard"
0051 #define OBP_PS2MS_NAME1     "kdmouse"
0052 #define OBP_PS2MS_NAME2     "mouse"
0053 
0054 static int sparc_i8042_probe(struct platform_device *op)
0055 {
0056     struct device_node *dp;
0057 
0058     for_each_child_of_node(op->dev.of_node, dp) {
0059         if (of_node_name_eq(dp, OBP_PS2KBD_NAME1) ||
0060             of_node_name_eq(dp, OBP_PS2KBD_NAME2)) {
0061             struct platform_device *kbd = of_find_device_by_node(dp);
0062             unsigned int irq = kbd->archdata.irqs[0];
0063             if (irq == 0xffffffff)
0064                 irq = op->archdata.irqs[0];
0065             i8042_kbd_irq = irq;
0066             kbd_iobase = of_ioremap(&kbd->resource[0],
0067                         0, 8, "kbd");
0068             kbd_res = &kbd->resource[0];
0069         } else if (of_node_name_eq(dp, OBP_PS2MS_NAME1) ||
0070                of_node_name_eq(dp, OBP_PS2MS_NAME2)) {
0071             struct platform_device *ms = of_find_device_by_node(dp);
0072             unsigned int irq = ms->archdata.irqs[0];
0073             if (irq == 0xffffffff)
0074                 irq = op->archdata.irqs[0];
0075             i8042_aux_irq = irq;
0076         }
0077     }
0078 
0079     return 0;
0080 }
0081 
0082 static int sparc_i8042_remove(struct platform_device *op)
0083 {
0084     of_iounmap(kbd_res, kbd_iobase, 8);
0085 
0086     return 0;
0087 }
0088 
0089 static const struct of_device_id sparc_i8042_match[] = {
0090     {
0091         .name = "8042",
0092     },
0093     {},
0094 };
0095 MODULE_DEVICE_TABLE(of, sparc_i8042_match);
0096 
0097 static struct platform_driver sparc_i8042_driver = {
0098     .driver = {
0099         .name = "i8042",
0100         .of_match_table = sparc_i8042_match,
0101     },
0102     .probe      = sparc_i8042_probe,
0103     .remove     = sparc_i8042_remove,
0104 };
0105 
0106 static int __init i8042_platform_init(void)
0107 {
0108     struct device_node *root = of_find_node_by_path("/");
0109     const char *name = of_get_property(root, "name", NULL);
0110 
0111     if (name && !strcmp(name, "SUNW,JavaStation-1")) {
0112         /* Hardcoded values for MrCoffee.  */
0113         i8042_kbd_irq = i8042_aux_irq = 13 | 0x20;
0114         kbd_iobase = ioremap(0x71300060, 8);
0115         if (!kbd_iobase)
0116             return -ENODEV;
0117     } else {
0118         int err = platform_driver_register(&sparc_i8042_driver);
0119         if (err)
0120             return err;
0121 
0122         if (i8042_kbd_irq == -1 ||
0123             i8042_aux_irq == -1) {
0124             if (kbd_iobase) {
0125                 of_iounmap(kbd_res, kbd_iobase, 8);
0126                 kbd_iobase = (void __iomem *) NULL;
0127             }
0128             return -ENODEV;
0129         }
0130     }
0131 
0132     i8042_reset = I8042_RESET_ALWAYS;
0133 
0134     return 0;
0135 }
0136 
0137 static inline void i8042_platform_exit(void)
0138 {
0139     struct device_node *root = of_find_node_by_path("/");
0140     const char *name = of_get_property(root, "name", NULL);
0141 
0142     if (!name || strcmp(name, "SUNW,JavaStation-1"))
0143         platform_driver_unregister(&sparc_i8042_driver);
0144 }
0145 
0146 #else /* !CONFIG_PCI */
0147 static int __init i8042_platform_init(void)
0148 {
0149     return -ENODEV;
0150 }
0151 
0152 static inline void i8042_platform_exit(void)
0153 {
0154 }
0155 #endif /* !CONFIG_PCI */
0156 
0157 #endif /* _I8042_SPARCIO_H */