#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
+#include <linux/io.h>
#include <linux/ioport.h>
+#include <linux/mutex.h>
#include <linux/nsc_gpio.h>
#include <linux/platform_device.h>
#include <asm/uaccess.h>
-#include <asm/io.h>
#define DEVNAME "pc8736x_gpio"
module_param(major, int, 0);
MODULE_PARM_DESC(major, "Major device number");
-static DEFINE_SPINLOCK(pc8736x_gpio_config_lock);
+static DEFINE_MUTEX(pc8736x_gpio_config_lock);
static unsigned pc8736x_gpio_base;
+static u8 pc8736x_gpio_shadow[4];
#define SIO_BASE1 0x2E /* 1st command-reg to check */
#define SIO_BASE2 0x4E /* alt command-reg to check */
u32 func_slct)
{
u32 config, new_config;
- unsigned long flags;
- spin_lock_irqsave(&pc8736x_gpio_config_lock, flags);
+ mutex_lock(&pc8736x_gpio_config_lock);
device_select(SIO_GPIO_UNIT);
select_pin(index);
new_config = (config & mask) | bits;
superio_outb(func_slct, new_config);
- spin_unlock_irqrestore(&pc8736x_gpio_config_lock, flags);
+ mutex_unlock(&pc8736x_gpio_config_lock);
return config;
}
val = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_IN);
dev_dbg(&pdev->dev, "wrote %x, read: %x\n", curval, val);
+ pc8736x_gpio_shadow[port] = val;
}
static void pc8736x_gpio_set_high(unsigned index)
pc8736x_gpio_set(index, 0);
}
-static int pc8736x_gpio_current(unsigned index)
+static int pc8736x_gpio_current(unsigned minor)
{
- dev_warn(&pdev->dev, "pc8736x_gpio_current unimplemented\n");
- return 0;
+ int port, bit;
+ minor &= 0x1f;
+ port = minor >> 3;
+ bit = minor & 7;
+ return ((pc8736x_gpio_shadow[port] >> bit) & 0x01);
}
static void pc8736x_gpio_change(unsigned index)
{
- pc8736x_gpio_set(index, !pc8736x_gpio_get(index));
+ pc8736x_gpio_set(index, !pc8736x_gpio_current(index));
}
-extern void nsc_gpio_dump(unsigned iminor);
-
static struct nsc_gpio_ops pc8736x_access = {
.owner = THIS_MODULE,
.gpio_config = pc8736x_gpio_configure,
.read = nsc_gpio_read,
};
+static void __init pc8736x_init_shadow(void)
+{
+ int port;
+
+ /* read the current values driven on the GPIO signals */
+ for (port = 0; port < 4; ++port)
+ pc8736x_gpio_shadow[port]
+ = inb_p(pc8736x_gpio_base + port_offset[port]
+ + PORT_OUT);
+
+}
+
static int __init pc8736x_gpio_init(void)
{
int rc = 0;
dev_err(&pdev->dev, "no device found\n");
goto undo_platform_dev_add;
}
+ pc8736x_access.dev = &pdev->dev;
/* Verify that chip and it's GPIO unit are both enabled.
My BIOS does this, so I take minimum action here
unregister_chrdev(major, DEVNAME);
}
+EXPORT_SYMBOL(pc8736x_access);
+
module_init(pc8736x_gpio_init);
module_exit(pc8736x_gpio_cleanup);