2005-04-17 02:20:36 +04:00
# ifndef _I8042_SPARCIO_H
# define _I8042_SPARCIO_H
2008-08-12 01:30:53 +04:00
# include <linux/of_device.h>
2005-04-17 02:20:36 +04:00
# include <asm/io.h>
# include <asm/oplib.h>
2006-06-30 02:42:29 +04:00
# include <asm/prom.h>
2005-04-17 02:20:36 +04:00
static int i8042_kbd_irq = - 1 ;
static int i8042_aux_irq = - 1 ;
# define I8042_KBD_IRQ i8042_kbd_irq
# define I8042_AUX_IRQ i8042_aux_irq
# define I8042_KBD_PHYS_DESC "sparcps2 / serio0"
# define I8042_AUX_PHYS_DESC "sparcps2 / serio1"
# define I8042_MUX_PHYS_DESC "sparcps2 / serio%d"
static void __iomem * kbd_iobase ;
2006-12-29 08:01:32 +03:00
static struct resource * kbd_res ;
2005-04-17 02:20:36 +04:00
# define I8042_COMMAND_REG (kbd_iobase + 0x64UL)
# define I8042_DATA_REG (kbd_iobase + 0x60UL)
static inline int i8042_read_data ( void )
{
return readb ( kbd_iobase + 0x60UL ) ;
}
static inline int i8042_read_status ( void )
{
return readb ( kbd_iobase + 0x64UL ) ;
}
static inline void i8042_write_data ( int val )
{
writeb ( val , kbd_iobase + 0x60UL ) ;
}
static inline void i8042_write_command ( int val )
{
writeb ( val , kbd_iobase + 0x64UL ) ;
}
2008-08-06 13:43:24 +04:00
# ifdef CONFIG_PCI
2005-04-17 02:20:36 +04:00
# define OBP_PS2KBD_NAME1 "kb_ps2"
# define OBP_PS2KBD_NAME2 "keyboard"
# define OBP_PS2MS_NAME1 "kdmouse"
# define OBP_PS2MS_NAME2 "mouse"
2012-11-24 09:38:25 +04:00
static int sparc_i8042_probe ( struct platform_device * op )
2006-06-30 02:42:29 +04:00
{
2010-04-14 03:12:29 +04:00
struct device_node * dp = op - > dev . of_node ;
2006-06-30 02:42:29 +04:00
dp = dp - > child ;
while ( dp ) {
if ( ! strcmp ( dp - > name , OBP_PS2KBD_NAME1 ) | |
! strcmp ( dp - > name , OBP_PS2KBD_NAME2 ) ) {
2010-08-06 19:25:50 +04:00
struct platform_device * kbd = of_find_device_by_node ( dp ) ;
2010-06-18 21:09:58 +04:00
unsigned int irq = kbd - > archdata . irqs [ 0 ] ;
2006-06-30 02:42:29 +04:00
if ( irq = = 0xffffffff )
2010-06-18 21:09:58 +04:00
irq = op - > archdata . irqs [ 0 ] ;
2006-06-30 02:42:29 +04:00
i8042_kbd_irq = irq ;
kbd_iobase = of_ioremap ( & kbd - > resource [ 0 ] ,
0 , 8 , " kbd " ) ;
2006-12-29 08:01:32 +03:00
kbd_res = & kbd - > resource [ 0 ] ;
2006-06-30 02:42:29 +04:00
} else if ( ! strcmp ( dp - > name , OBP_PS2MS_NAME1 ) | |
! strcmp ( dp - > name , OBP_PS2MS_NAME2 ) ) {
2010-08-06 19:25:50 +04:00
struct platform_device * ms = of_find_device_by_node ( dp ) ;
2010-06-18 21:09:58 +04:00
unsigned int irq = ms - > archdata . irqs [ 0 ] ;
2006-06-30 02:42:29 +04:00
if ( irq = = 0xffffffff )
2010-06-18 21:09:58 +04:00
irq = op - > archdata . irqs [ 0 ] ;
2006-06-30 02:42:29 +04:00
i8042_aux_irq = irq ;
}
dp = dp - > sibling ;
}
return 0 ;
}
2012-11-24 09:50:47 +04:00
static int sparc_i8042_remove ( struct platform_device * op )
2006-06-30 02:42:29 +04:00
{
2006-12-29 08:01:32 +03:00
of_iounmap ( kbd_res , kbd_iobase , 8 ) ;
2006-06-30 02:42:29 +04:00
return 0 ;
}
2008-08-31 12:23:17 +04:00
static const struct of_device_id sparc_i8042_match [ ] = {
2006-06-30 02:42:29 +04:00
{
. name = " 8042 " ,
} ,
{ } ,
} ;
2006-07-03 11:24:21 +04:00
MODULE_DEVICE_TABLE ( of , sparc_i8042_match ) ;
2006-06-30 02:42:29 +04:00
2011-02-23 06:01:33 +03:00
static struct platform_driver sparc_i8042_driver = {
2010-04-14 03:13:02 +04:00
. driver = {
. name = " i8042 " ,
. owner = THIS_MODULE ,
. of_match_table = sparc_i8042_match ,
} ,
2006-06-30 02:42:29 +04:00
. probe = sparc_i8042_probe ,
2012-11-24 09:27:39 +04:00
. remove = sparc_i8042_remove ,
2006-06-30 02:42:29 +04:00
} ;
2005-09-04 10:41:38 +04:00
static int __init i8042_platform_init ( void )
2005-04-17 02:20:36 +04:00
{
2006-06-30 02:42:29 +04:00
struct device_node * root = of_find_node_by_path ( " / " ) ;
2005-04-17 02:20:36 +04:00
2006-06-30 02:42:29 +04:00
if ( ! strcmp ( root - > name , " SUNW,JavaStation-1 " ) ) {
2005-04-17 02:20:36 +04:00
/* Hardcoded values for MrCoffee. */
i8042_kbd_irq = i8042_aux_irq = 13 | 0x20 ;
kbd_iobase = ioremap ( 0x71300060 , 8 ) ;
if ( ! kbd_iobase )
2005-09-04 10:41:38 +04:00
return - ENODEV ;
2005-04-17 02:20:36 +04:00
} else {
2011-02-23 06:01:33 +03:00
int err = platform_driver_register ( & sparc_i8042_driver ) ;
2006-06-30 02:42:29 +04:00
if ( err )
return err ;
2005-04-17 02:20:36 +04:00
if ( i8042_kbd_irq = = - 1 | |
i8042_aux_irq = = - 1 ) {
2006-06-30 02:42:29 +04:00
if ( kbd_iobase ) {
2006-12-29 08:01:32 +03:00
of_iounmap ( kbd_res , kbd_iobase , 8 ) ;
2006-06-30 02:42:29 +04:00
kbd_iobase = ( void __iomem * ) NULL ;
}
2005-09-04 10:41:38 +04:00
return - ENODEV ;
2005-04-17 02:20:36 +04:00
}
}
i8042_reset = 1 ;
return 0 ;
}
static inline void i8042_platform_exit ( void )
{
2006-06-30 02:42:29 +04:00
struct device_node * root = of_find_node_by_path ( " / " ) ;
if ( strcmp ( root - > name , " SUNW,JavaStation-1 " ) )
2011-02-23 06:01:33 +03:00
platform_driver_unregister ( & sparc_i8042_driver ) ;
2005-04-17 02:20:36 +04:00
}
2008-08-06 13:43:24 +04:00
# else /* !CONFIG_PCI */
static int __init i8042_platform_init ( void )
{
return - ENODEV ;
}
static inline void i8042_platform_exit ( void )
{
}
# endif /* !CONFIG_PCI */
2005-04-17 02:20:36 +04:00
# endif /* _I8042_SPARCIO_H */