From: <z7...@us...> - 2007-03-18 23:34:39
|
Revision: 922 http://svn.sourceforge.net/hackndev/?rev=922&view=rev Author: z72ka Date: 2007-03-18 12:54:45 -0700 (Sun, 18 Mar 2007) Log Message: ----------- palmz72: Clearing unused files Removed Paths: ------------- linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed-ng.c linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed.c linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/palmz72_ac97.c Deleted: linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed-ng.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed-ng.c 2007-03-18 19:46:37 UTC (rev 921) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed-ng.c 2007-03-18 19:54:45 UTC (rev 922) @@ -1,175 +0,0 @@ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/proc_fs.h> - -#include <linux/interrupt.h> -#include <asm/irq.h> -#include <asm/mach/arch.h> -#include <asm/mach/map.h> -#include <asm/mach-types.h> -#include <asm/hardware.h> -#include <linux/sched.h> -#include <linux/workqueue.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/irqs.h> -#include <asm/uaccess.h> - -#include <linux/debugfs.h> -#include <linux/seq_file.h> - -#define PROCFS_NAME "gpio" -#define DEBUGFS_NAME "gpio" - -static struct proc_dir_entry *proc_intf; -static struct dentry *debugfs_intf; - -#define PROCFS_MAX_SIZE 20 - -static char procfs_buffer[PROCFS_MAX_SIZE]; -static unsigned long procfs_buffer_size = 0; - -#define GPIO_TEST(reg, gp) (reg(gp) & GPIO_bit(gp)) -static int dfs_show(struct seq_file *s, void *_) -{ - int i,afn; - seq_printf(s, "GPIO lines status:\n"); - - for(i=0;i<121;i++) { - afn = (GAFR(i) & (0x3 << (((i) & 0xf)*2))) >> (((i) & 0xf)*2); - seq_printf(s, "%s%d: %s %s %s %s %lx\n", - i<10?"0":"", - i, - GPIO_TEST(GPLR, i)?"*":" ", - GPIO_TEST(GPDR, i)?"->":"<-", - GPIO_TEST(GRER, i)?"_/":" ", - GPIO_TEST(GFER, i)?"\\_":" ", - afn); - - } - - return 0; -} - -static int dfs_open(struct inode *inode, struct file *file) -{ - return single_open(file, dfs_show, inode->u.generic_ip); -} - -static struct file_operations debug_fops = { - .open = dfs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static void gpio_set(int id, int on) -{ - do { - if (on) - GPSR(id) = GPIO_bit(id); - else - GPCR(id) = GPIO_bit(id); - } while (0); -} - -void set_afn(int gpio, int fn) -{ - int gafr; - gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2)); - GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2)); -} - -void handle_request() -{ - char *p = NULL; - unsigned long id = simple_strtoul(procfs_buffer+2, &p, 10); - switch(procfs_buffer[0]) { - case 'L': - gpio_set(id, 1); - printk(KERN_ERR "GPIOed: GPIO %lu set high\n", id); - break; - case 'l': - gpio_set(id, 0); - printk(KERN_ERR "GPIOed: GPIO %lu set low\n", id); - break; - case 'd': - GPDR(id) &= ~(GPIO_bit(id)); - break; - case 'D': - GPDR(id) |= GPIO_bit(id); - break; - case '0': - set_afn(id, 0); - break; - case '1': - set_afn(id, 1); - break; - case '2': - set_afn(id, 2); - break; - default: - printk(KERN_ERR "GPIOed: Unknown request\n"); - break; - } -} - - -int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data) -{ - procfs_buffer_size = count; - if (procfs_buffer_size > PROCFS_MAX_SIZE ) { - procfs_buffer_size = PROCFS_MAX_SIZE; - } - - /* write data to the buffer */ - if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { - return -EFAULT; - } - - handle_request(); - - return procfs_buffer_size; -} - - -static int __init gpioed_init(void) -{ - proc_intf = create_proc_entry(PROCFS_NAME, 0644, NULL); - if (proc_intf == NULL) { - remove_proc_entry(PROCFS_NAME, &proc_root); - printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME); - return -ENOMEM; - } - - /*proc_intf->read_proc = procfile_read;*/ - proc_intf->write_proc = procfile_write; - proc_intf->owner = THIS_MODULE; - proc_intf->mode = S_IFREG | S_IRUGO; - proc_intf->uid = 0; - proc_intf->gid = 0; - proc_intf->size = 37; - - debugfs_intf = debugfs_create_file(DEBUGFS_NAME, S_IRUGO, NULL, NULL, &debug_fops); - - printk(KERN_INFO "/proc/%s created\n", PROCFS_NAME); - - return 0; -} - -static void __exit gpioed_exit(void) -{ - debugfs_remove(debugfs_intf); - remove_proc_entry(PROCFS_NAME, &proc_root); - printk(KERN_INFO "/proc/%s removed\n", PROCFS_NAME); -} - - -/*** Some more stuff ***/ -module_init(gpioed_init); -module_exit(gpioed_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Vladimir \"Farcaller\" Pouzanov <far...@gm...>"); -MODULE_DESCRIPTION("GPIO editor for PXA26x, second edition"); - Deleted: linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed.c 2007-03-18 19:46:37 UTC (rev 921) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/gpioed.c 2007-03-18 19:54:45 UTC (rev 922) @@ -1,226 +0,0 @@ -/*** Basic includes ***/ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/proc_fs.h> - -#include <linux/interrupt.h> -#include <asm/irq.h> -#include <asm/mach/arch.h> -#include <asm/mach/map.h> -#include <asm/mach-types.h> -#include <asm/hardware.h> -#include <linux/sched.h> -#include <linux/workqueue.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/irqs.h> -#include <asm/uaccess.h> - -/*** GPIO macros ***/ -#define GET_PALMT3_GPIO(gpio) \ - (GPLR(GPIO_NR_PALMT3_ ## gpio) & GPIO_bit(GPIO_NR_PALMT3_ ## gpio)) - -#define SET_PALMT3_GPIO(gpio, setp) \ - do { \ - if (setp) \ - GPSR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - else \ - GPCR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - } while (0) - -#define SET_PALMT3_GPIO_N(gpio, setp) \ - do { \ - if (setp) \ - GPCR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - else \ - GPSR(GPIO_NR_PALMT3_ ## gpio) = GPIO_bit(GPIO_NR_PALMT3_ ## gpio); \ - } while (0) - -#define GET_GPIO_REG(reg,gpio) (GP##reg(gpio) & GPIO_bit(gpio)) -#define GET_GPIO(gpio) GET_GPIO_REG(LR, gpio) - -/*** /proc interface ***/ -static struct proc_dir_entry *proc_intf; -#define procfs_name "gpioed" -#define PROCFS_MAX_SIZE 20 - -static char procfs_buffer[PROCFS_MAX_SIZE]; -static unsigned long procfs_buffer_size = 0; - -int procfile_read(char *buffer, char **buffer_location, off_t offset, int buffer_length, int *eof, void *data) -{ - int ret; - - if (offset > 0) { - /* we have finished to read, return 0 */ - ret = 0; - } else { - /* fill the buffer, return the buffer size */ - ret = sprintf(buffer, "HelloWorld!\n"); - } - return ret; -} - -void handle_request(void); - -int procfile_write(struct file *file, const char *buffer, unsigned long count, void *data) -{ - procfs_buffer_size = count; - if (procfs_buffer_size > PROCFS_MAX_SIZE ) { - procfs_buffer_size = PROCFS_MAX_SIZE; - } - - /* write data to the buffer */ - if ( copy_from_user(procfs_buffer, buffer, procfs_buffer_size) ) { - return -EFAULT; - } - - handle_request(); - - return procfs_buffer_size; -} - -/*** IRQ (GPIO) handling ***/ -static struct workqueue_struct *my_workqueue; -#define MY_WORK_QUEUE_NAME "GPIOed" - -static void handle_gpio(void* irq) -{ - int gpn = (int)irq; - printk(KERN_ERR "*** GPIO *** %d *** is *** %s ***\n", gpn, GET_GPIO(gpn) ? "high" : "low "); -} - -irqreturn_t gpio_irq(int irq, void *dev_id, struct pt_regs *regs) -{ - static int initialised = 0; - static struct work_struct task; - - if (initialised == 0) { - INIT_WORK(&task, handle_gpio, dev_id); - initialised = 1; - } else { - PREPARE_WORK(&task, handle_gpio, dev_id); - } - - queue_work(my_workqueue, &task); - - return IRQ_HANDLED; -} - -/*** GPIO R/W ***/ -static int gpio_get(int id) -{ - return GET_GPIO(id); -} - -static void gpio_set(int id, int on) -{ - do { - if (on) - GPSR(id) = GPIO_bit(id); - else - GPCR(id) = GPIO_bit(id); - } while (0); -} - -static int gpio_watch(int x) -{ - int ret; - ret = request_irq (IRQ_GPIO(x), gpio_irq, SA_SAMPLE_RANDOM, "test_handler", (void*)x); - set_irq_type (IRQ_GPIO(x), IRQT_BOTHEDGE); - if(ret!=0) { - printk(KERN_ERR "GPIOed: failed to register for GPIO %d\n", x); - return 1; - } else { - printk(KERN_ERR "GPIOed: Registered GPIO %d\n", x); - return 0; - } -} - -/*** Request handler ***/ -void handle_request() -{ - char *p = NULL; - unsigned long base = 10; - unsigned long id; - - if((procfs_buffer[0] == 'P') || (procfs_buffer[0] == 'V')) - base = 16; - id = simple_strtoul(procfs_buffer+2, &p, base); - switch(procfs_buffer[0]) { - case 'r': - printk(KERN_ERR "GPIOed: GPIO %lu is %s\n", id, gpio_get(id)?"high":"low "); - break; - case 's': - gpio_watch(id); - break; - case 'h': - gpio_set(id, 1); - printk(KERN_ERR "GPIOed: GPIO %lu set high\n", id); - break; - case 'l': - gpio_set(id, 0); - printk(KERN_ERR "GPIOed: GPIO %lu set low\n", id); - break; - case 'd': - printk(KERN_ERR "GPIOed: GPIO %lu is %s\n", id, GET_GPIO_REG(DR,id)?"output":"input"); - break; - - case 'P': - printk(KERN_ERR "GPIOed: P-V for 0x%x is 0x%x\n", id, (unsigned int)phys_to_virt(id)); - break; - case 'V': - printk(KERN_ERR "GPIOed: V-P for 0x%x is 0x%x\n", id, (unsigned int)virt_to_phys(id)); - break; - case 'D': - base = *((unsigned int*)id); - printk(KERN_ERR "GPIOed: 0x%x = 0x%x\n", id, base); - break; - default: - printk(KERN_ERR "GPIOed: Unknown request\n"); - break; - } -} - -/*** init&exit ***/ -static int __init gpioed_init(void) -{ - my_workqueue = create_workqueue(MY_WORK_QUEUE_NAME); - - proc_intf = create_proc_entry(procfs_name, 0644, NULL); - if (proc_intf == NULL) { - remove_proc_entry(procfs_name, &proc_root); - printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", - procfs_name); - return -ENOMEM; - } - - proc_intf->read_proc = procfile_read; - proc_intf->write_proc = procfile_write; - proc_intf->owner = THIS_MODULE; - proc_intf->mode = S_IFREG | S_IRUGO; - proc_intf->uid = 0; - proc_intf->gid = 0; - proc_intf->size = 37; - - printk(KERN_INFO "/proc/%s created\n", procfs_name); - - return 0; -} - -static void __exit gpioed_exit(void) -{ - destroy_workqueue(my_workqueue); - remove_proc_entry(procfs_name, &proc_root); - printk(KERN_INFO "/proc/%s removed\n", procfs_name); -} - - -/*** Some more stuff ***/ -module_init(gpioed_init); -module_exit(gpioed_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Vladimir \"Farcaller\" Pouzanov <far...@gm...>"); -MODULE_DESCRIPTION("GPIO editor for PXA26x"); - Deleted: linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/palmz72_ac97.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/palmz72_ac97.c 2007-03-18 19:46:37 UTC (rev 921) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmz72/palmz72_ac97.c 2007-03-18 19:54:45 UTC (rev 922) @@ -1,594 +0,0 @@ -/************************************************************************ - * linux/arch/arm/mach-pxa/palmz72/palmz72_ac97.c * - * * - * Touchscreen/battery driver for Palm Zire 72 WM9712 AC97 codec * - * Author: Jan Herman <2h...@se...> * - * Based on palmld_ac97.c code from Alex Osborne * - * * - ************************************************************************/ - - -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/moduleparam.h> -#include <linux/init.h> -#include <linux/interrupt.h> -#include <linux/input.h> -#include <linux/device.h> -#include <linux/workqueue.h> -#include <linux/battery.h> - -#include <asm/apm.h> -#include <asm/delay.h> -#include <asm/mach-types.h> -#include <asm/mach/arch.h> -#include <asm/mach/map.h> -#include <asm/arch/hardware.h> -#include <asm/arch/pxa-regs.h> -#include <asm/arch/irqs.h> - -#include <sound/driver.h> -#include <sound/core.h> -#include <sound/pcm.h> -#include <sound/initval.h> -#include <sound/ac97_codec.h> -#include <asm/arch/palmz72-ac97.h> -#include <asm/arch/palmz72-gpio.h> -#include <asm/arch/palmz72-init.h> - - -#define X_AXIS_MAX 3900 -#define X_AXIS_MIN 350 -#define Y_AXIS_MAX 3750 -#define Y_AXIS_MIN 320 -#define PRESSURE_MIN 0 -#define PRESSURE_MAX 300 - -#define DIG2_INIT 0x0001 /* initial value for digitiser2 reg */ - -#define DEFAULT_PRESSURE_TRESHOLD 47200 /* default pressure treshold for pen up/down */ -#define DEFAULT_X_AXIS_FUZZ 5 /* default x axis noise treshold */ -#define DEFAULT_Y_AXIS_FUZZ 40 /* default y axis noise treshold */ -#define PRESSURE_FUZZ 4 /* default pressure noise treshold */ - -#define palmz72_ac97_WORK_QUEUE_NAME "palmz72_ac97_workqueue" - - -/********************* - * Module parameters * - *********************/ - -static int ptrsh = DEFAULT_PRESSURE_TRESHOLD; -module_param(ptrsh, int, 0); -MODULE_PARM_DESC(ptrsh, "pressure treshold for pen up/down"); - -static int dbglvl = 0; // debug disabled -module_param(dbglvl, int, 0); -MODULE_PARM_DESC(dbglvl, "debug level (0 is disabled)"); - -static int xdjtrsh = DEFAULT_X_AXIS_FUZZ; -module_param(xdjtrsh, int, 0); -MODULE_PARM_DESC(xdjtrsh, "treshold for x axis jitter"); - -static int ydjtrsh = DEFAULT_Y_AXIS_FUZZ; -module_param(ydjtrsh, int, 0); -MODULE_PARM_DESC(ydjtrsh, "treshold for y axis jitter"); - - -static DECLARE_MUTEX_LOCKED(queue_sem); -static DECLARE_MUTEX(digitiser_sem); -static DECLARE_MUTEX(battery_update_mutex); - -static struct workqueue_struct *palmz72_ac97_workqueue; -static struct work_struct palmz72_ac97_irq_task; - -struct input_dev *palmz72_ac97_input; -struct device *palmz72_ac97_dev; - -static ac97_t *ac97; - -static int battery_registered = 0; -static unsigned long last_battery_update = 0; -static int current_voltage; -static int previous_voltage; -static u16 d2base; - -/************** - * ac97 codec * - **************/ - -void wm97xx_gpio_func(int gpio, int func) -{ - int GEn; - GEn = ac97->bus->ops->read(ac97, 0x56); - if(func) - GEn |= gpio; - else - GEn &= ~gpio; - ac97->bus->ops->write(ac97, 0x56, GEn); -} - - -void wm97xx_gpio_mode(int gpio, int config, int polarity, int sticky, int wakeup) -{ - int GCn, GPn, GSn, GWn; - GCn = ac97->bus->ops->read(ac97, 0x4c); - GPn = ac97->bus->ops->read(ac97, 0x4e); - GSn = ac97->bus->ops->read(ac97, 0x50); - GWn = ac97->bus->ops->read(ac97, 0x52); - - if(config) - GCn |= gpio; - else - GCn &= ~gpio; - - if(polarity) - GPn |= gpio; - else - GPn &= ~gpio; - - if(sticky) - GSn |= gpio; - else - GSn &= ~gpio; - - if(wakeup) - GWn |= gpio; - else - GWn &= ~gpio; - - ac97->bus->ops->write(ac97, 0x4c, GCn); - ac97->bus->ops->write(ac97, 0x4e, GPn); - ac97->bus->ops->write(ac97, 0x50, GSn); - ac97->bus->ops->write(ac97, 0x52, GWn); -} - - -static void wm97xx_set_digitiser_power(int value) -{ - ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2base | value); -} - -static int palmz72_ac97_take_reading(int adcsel) -{ - - int timeout = 15; - u16 r76 = 0; - u16 r7a; - - r76 |= adcsel; // set ADCSEL (ADC source) - r76 |= WM97XX_DELAY(3); // set settling time delay - r76 &= ~(1<<11); // COO = 0 (single measurement) - r76 &= ~(1<<10); // CTC = 0 (polling mode) - r76 |= (1<<15); // initiate measurement (POLL) - - ac97->bus->ops->write(ac97, 0x76, r76); - - // wait settling time - udelay ((3 * AC97_LINK_FRAME) + 167); - - // wait for POLL to go low - while((ac97->bus->ops->read(ac97, 0x76) & 0x8000) && timeout){ - udelay(AC97_LINK_FRAME); - timeout--; - } - - if (timeout == 0){ - printk("palmz72_ac97: discarding reading due to POLL wait timout on 0x76\n"); - return 0; - } - - r7a = ac97->bus->ops->read(ac97, 0x7a); - - if ((r7a & WM97XX_ADCSEL_MASK) != adcsel){ - printk("palmz72_ac97: discarding reading -> wrong ADC source\n"); - return 0; - } - - return (int) r7a; - -} - - -static void palmz72_ac97_pendown(void) -{ - int xread, yread, pressure; - int valid_coords=0, btn_pressed = 0; - - /* take readings until the pen goes up */ - do { - /* take readings */ - xread = palmz72_ac97_take_reading(WM97XX_ADCSEL_X); - yread = palmz72_ac97_take_reading(WM97XX_ADCSEL_Y); - pressure = palmz72_ac97_take_reading(WM97XX_ADCSEL_PRES); - - // printk("Pressure is %d:\n", pressure); - - valid_coords = (xread & 0xfff) && (yread & 0xfff) && (pressure & 0xfff); - - if(valid_coords && (pressure < ptrsh)) { - btn_pressed = 1; - input_report_key(palmz72_ac97_input, BTN_TOUCH, 1); - input_report_abs(palmz72_ac97_input, ABS_X, xread & 0xfff); - input_report_abs(palmz72_ac97_input, ABS_Y, yread & 0xfff); - input_report_abs(palmz72_ac97_input, ABS_PRESSURE, pressure & 0xfff); - input_sync(palmz72_ac97_input); - - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(HZ/100); - set_current_state(TASK_RUNNING); - } - } while( valid_coords ); - - - if (btn_pressed) { - input_report_key(palmz72_ac97_input, BTN_TOUCH, 0); - input_report_abs(palmz72_ac97_input, ABS_X, 0); - input_report_abs(palmz72_ac97_input, ABS_Y, 0); - input_report_abs(palmz72_ac97_input, ABS_PRESSURE, 0); - input_sync(palmz72_ac97_input); - } - -} - - -static void palmz72_ac97_irq_work(void *data) -{ - u16 levels; - u16 polarity; - - levels = ac97->bus->ops->read(ac97, 0x54); - polarity = ac97->bus->ops->read(ac97, 0x4e); - - if(polarity & levels & WM97XX_GPIO_13) { - /* power up digitiser: */ - down(&digitiser_sem); - wm97xx_set_digitiser_power(WM97XX_PRP_DET_DIG); - - palmz72_ac97_pendown(); - - /* power down digitiser to conserve power */ - wm97xx_set_digitiser_power(WM97XX_PRP_DET); - ac97->bus->ops->write(ac97, 0x4e, polarity & ~WM97XX_GPIO_13); - up(&digitiser_sem); - } - else { - ac97->bus->ops->write(ac97, 0x4e, polarity | WM97XX_GPIO_13); - } - - ac97->bus->ops->write(ac97, 0x54, levels & ~WM97XX_GPIO_13); - - udelay(1); - up(&queue_sem); - enable_irq(IRQ_GPIO_PALMZ72_WM9712_IRQ); -} - - -static irqreturn_t palmz72_ac97_irq_handler(int irq, void *dev_id, struct pt_regs *regs) -{ - if (down_trylock(&queue_sem) == 0){ - disable_irq(IRQ_GPIO_PALMZ72_WM9712_IRQ); - queue_work(palmz72_ac97_workqueue, &palmz72_ac97_irq_task); - } - - return IRQ_HANDLED; -} - -static int suspended = 0; - -static int palmz72_ac97_suspend(struct device *dev, pm_message_t state) -{ - suspended = 1; - return 0; -} - - -static int palmz72_ac97_resume(struct device* dev) -{ - u16 d2 = DIG2_INIT; - - ac97 = to_ac97_t(dev); - - /* reset levels */ - ac97->bus->ops->write(ac97, 0x54, 0); - - /* disable digitiser to save power, enable pen-down detect */ - d2 |= WM97XX_PRP_DET; - d2base = d2; - ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2base); - - /* enable interrupts on codec's gpio 2 (connected to cpu gpio 27) */ - wm97xx_gpio_mode(WM97XX_GPIO_2, WM97XX_GPIO_OUT, WM97XX_GPIO_POL_HIGH, - WM97XX_GPIO_NOTSTICKY, WM97XX_GPIO_NOWAKE); - wm97xx_gpio_func(WM97XX_GPIO_2, 0); - - /* enable pen detect interrupt */ - wm97xx_gpio_mode(WM97XX_GPIO_13, WM97XX_GPIO_OUT, WM97XX_GPIO_POL_HIGH, - WM97XX_GPIO_STICKY, WM97XX_GPIO_WAKE); - - /* setup work queue */ - palmz72_ac97_workqueue = create_workqueue(palmz72_ac97_WORK_QUEUE_NAME); - INIT_WORK(&palmz72_ac97_irq_task, palmz72_ac97_irq_work, dev); - - up(&queue_sem); - return 0; -} - - - - -/*********** - * Battery * - ***********/ - - -void palmz72_battery_read_adc(int force) -{ - u16 vread; - - if(!force && ((last_battery_update + 10 *HZ) > jiffies)) - return; - - if(down_trylock(&battery_update_mutex)) - return; - - down(&digitiser_sem); - wm97xx_set_digitiser_power(WM97XX_PRP_DET_DIG); - vread = palmz72_ac97_take_reading(WM97XX_ADCSEL_BMON); - wm97xx_set_digitiser_power(WM97XX_PRP_DET); - up(&digitiser_sem); - - previous_voltage = current_voltage; - current_voltage = vread & 0xfff; - last_battery_update = jiffies; - - up(&battery_update_mutex); -} - - -int palmz72_battery_min_voltage(struct battery *b) -{ - return PALMZ72_BAT_MIN_VOLTAGE; -} - - -int palmz72_battery_max_voltage(struct battery *b) -{ - return PALMZ72_BAT_MAX_VOLTAGE; /* mV */ -} - -/* - This formula is based on battery life of my battery 1100mAh. Original battery in Zire72 is Li-On 920mAh - V_batt = ADCSEL_BMON * 1,889 + 767,8 [mV] -*/ - -int palmz72_battery_get_voltage(struct battery *b) -{ - if (battery_registered){ - palmz72_battery_read_adc(0); - //printk("Battery [mV]: %d\n", current_voltage * 1889/1000 + 7678/10 ); - return current_voltage * 1889/1000 + 7678/10; - } - else{ - printk("palmz72_battery: cannot get voltage -> battery driver unregistered\n"); - return 0; - } -} - - -int palmz72_battery_get_status(struct battery *b) -{ - int ac_connected = GET_GPIO(GPIO_NR_PALMZ72_POWER_DETECT); - int usb_connected = !GET_GPIO(GPIO_NR_PALMZ72_USB_DETECT); - - if (current_voltage <= 0) - return BATTERY_STATUS_UNKNOWN; - - if (ac_connected || usb_connected){ - if ( ( current_voltage > previous_voltage ) || (current_voltage <= PALMZ72_BAT_MAX_VOLTAGE) ) - return BATTERY_STATUS_CHARGING; - return BATTERY_STATUS_NOT_CHARGING; - } - else - return BATTERY_STATUS_DISCHARGING; -} - - -struct battery palmz72_battery = { - .name = "palmz72_battery", - .id = "battery0", - .get_min_voltage = palmz72_battery_min_voltage, - .get_max_voltage = palmz72_battery_max_voltage, - .get_voltage = palmz72_battery_get_voltage, - .get_status = palmz72_battery_get_status, -}; - - -static int __init palmz72_ac97_probe(struct device *dev) -{ - int err; - u16 d2 = DIG2_INIT; - - if(!machine_is_palmz72()) - return -ENODEV; - - ac97 = to_ac97_t(dev); - - set_irq_type(IRQ_GPIO_PALMZ72_WM9712_IRQ, IRQT_RISING); - - err = request_irq(IRQ_GPIO_PALMZ72_WM9712_IRQ, palmz72_ac97_irq_handler, - SA_INTERRUPT, "WM9712 pendown IRQ", dev); - - if(err) { - printk(KERN_ERR "palmz72_ac97_probe: cannot request pen down IRQ\n"); - return -1; - } - - /* reset levels */ - ac97->bus->ops->write(ac97, 0x54, 0); - - /* disable digitiser to save power, enable pen-down detect */ - d2 |= WM97XX_PRP_DET; - d2base = d2; - ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2base); - - /* enable interrupts on codec's gpio 2 (connected to cpu gpio 27) */ - wm97xx_gpio_mode(WM97XX_GPIO_2, WM97XX_GPIO_OUT, WM97XX_GPIO_POL_HIGH, - WM97XX_GPIO_NOTSTICKY, WM97XX_GPIO_NOWAKE); - wm97xx_gpio_func(WM97XX_GPIO_2, 0); - - /* enable pen detect interrupt */ - wm97xx_gpio_mode(WM97XX_GPIO_13, WM97XX_GPIO_OUT, WM97XX_GPIO_POL_HIGH, - WM97XX_GPIO_STICKY, WM97XX_GPIO_WAKE); - - /* turn off irq gpio inverting */ - ac97->bus->ops->write(ac97, 0x58, ac97->bus->ops->read(ac97, 0x58)&~1); - - /* turn on the digitiser and pen down detector */ - ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2base | WM97XX_PRP_DETW); - - /* setup the input device */ - palmz72_ac97_input = input_allocate_device(); - if (palmz72_ac97_input == NULL){ - printk ("palmz72_ac97_probe: cannot allocate input device\n"); - return -ENOMEM; - } - - palmz72_ac97_input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); - - palmz72_ac97_input->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); - input_set_abs_params(palmz72_ac97_input, ABS_X, X_AXIS_MIN, X_AXIS_MAX, xdjtrsh, 0); - input_set_abs_params(palmz72_ac97_input, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, ydjtrsh, 0); - input_set_abs_params(palmz72_ac97_input, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, PRESSURE_FUZZ, 0); - - palmz72_ac97_input->name = "palmz72 touchscreen"; - palmz72_ac97_input->dev = dev; - palmz72_ac97_input->id.bustype = BUS_HOST; - input_register_device(palmz72_ac97_input); - - /* register battery */ - - if(battery_class_register(&palmz72_battery)) { - printk(KERN_ERR "palmz72_ac97_probe: could not register battery class\n"); - } - else{ - battery_registered = 1; - } - - /* setup work queue */ - palmz72_ac97_workqueue = create_workqueue(palmz72_ac97_WORK_QUEUE_NAME); - INIT_WORK(&palmz72_ac97_irq_task, palmz72_ac97_irq_work, dev); - - up(&queue_sem); - return 0; -} - -static int palmz72_ac_is_connected (void){ - /* when charger is plugged in and USB is not connected, then status is ONLINE */ - int ret = (!(GET_GPIO(GPIO_NR_PALMZ72_USB_PULLUP)) && !(GET_GPIO(GPIO_NR_PALMZ72_USB_DETECT)));; - if (ret) - ret = 1; - else - ret = 0; - - return ret; -} - -/******* - * APM * - *******/ - -static void palmz72_apm_get_power_status(struct apm_power_info *info) -{ - int min, max, curr, percent; - - curr = palmz72_battery_get_voltage(NULL); - min = palmz72_battery_min_voltage(NULL); - max = palmz72_battery_max_voltage(NULL); - - curr = curr - min; - if (curr < 0) curr = 0; - max = max - min; - - percent = curr*100/max; - - info->battery_life = percent; - - info->ac_line_status = palmz72_ac_is_connected() ? APM_AC_ONLINE : APM_AC_OFFLINE; - - if (info->ac_line_status) { - info->battery_status = APM_BATTERY_STATUS_CHARGING; - } else { - if (percent > 50) - info->battery_status = APM_BATTERY_STATUS_HIGH; - else if (percent < 5) - info->battery_status = APM_BATTERY_STATUS_CRITICAL; - else - info->battery_status = APM_BATTERY_STATUS_LOW; - } - - info->time = percent * PALMZ72_MAX_LIFE_MINS/100; - info->units = APM_UNITS_MINS; -} - -typedef void (*apm_get_power_status_t)(struct apm_power_info*); - -int set_apm_get_power_status(apm_get_power_status_t t) -{ - apm_get_power_status = t; - - return 0; -} - - -/* end of APM implementing */ - -static int palmz72_ac97_remove (struct device *dev) -{ - battery_class_unregister(&palmz72_battery); - ac97 = NULL; - input_unregister_device(palmz72_ac97_input); - return 0; -} - - -static struct device_driver palmz72_ac97_driver = { - .name = "palmz72_ac97 (WM9712)", - .bus = &ac97_bus_type, - .owner = THIS_MODULE, - .probe = palmz72_ac97_probe, - .remove = palmz72_ac97_remove, - -#ifdef CONFIG_PM - .suspend = palmz72_ac97_suspend, - .resume = palmz72_ac97_resume, -#endif -}; - - -static int __init palmz72_ac97_init(void) -{ - driver_register(&palmz72_ac97_driver); - -/* register battery to APM layer */ - -#ifdef CONFIG_PM - apm_get_power_status = palmz72_apm_get_power_status; - return 0; -#endif - -} - - -static void __exit palmz72_ac97_exit(void) -{ - driver_unregister(&palmz72_ac97_driver); -} - - -module_init(palmz72_ac97_init); -module_exit(palmz72_ac97_exit); - -MODULE_AUTHOR ("Jan Herman <2h...@se...>"); -MODULE_DESCRIPTION ("WM9712 AC97 codec support for PalmOne Zire 72"); -MODULE_LICENSE ("GPL"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |