diff options
author | Balaji Rao <balajirrao@openmoko.org> | 2009-02-22 04:40:03 +0000 |
---|---|---|
committer | Andy Green <agreen@octopus.localdomain> | 2009-02-22 04:40:03 +0000 |
commit | 5a7732b94a6ddea17c60c53529813a658a2ee7e1 (patch) | |
tree | e3ee4c510844f4a6ea3f1522bf2ba3c195a62abb /drivers | |
parent | 98c80a0a2edabfbffab978ed863097ab629a4aab (diff) |
gta02_use_new_fiq_and_hdq_stuff.patch
Signed-off-by: Balaji Rao <balajirrao@openmoko.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/leds/leds-neo1973-vibrator.c | 60 | ||||
-rw-r--r-- | drivers/power/Kconfig | 8 | ||||
-rw-r--r-- | drivers/power/Makefile | 1 | ||||
-rw-r--r-- | drivers/power/gta02_hdq.c | 292 |
4 files changed, 50 insertions, 311 deletions
diff --git a/drivers/leds/leds-neo1973-vibrator.c b/drivers/leds/leds-neo1973-vibrator.c index 95086078503..e35872b4f4b 100644 --- a/drivers/leds/leds-neo1973-vibrator.c +++ b/drivers/leds/leds-neo1973-vibrator.c @@ -22,21 +22,57 @@ #include <plat/pwm.h> #include <mach/gta01.h> #include <plat/regs-timer.h> +#include <linux/neo1973_vibrator.h> -#ifdef CONFIG_MACH_NEO1973_GTA02 -#include <mach/fiq_ipc_gta02.h> -#endif #include <asm/plat-s3c24xx/neo1973.h> #define COUNTER 64 -struct neo1973_vib_priv { +enum hdq_bitbang_states { + HDQB_IDLE = 0, + HDQB_TX_BREAK, + HDQB_TX_BREAK_RECOVERY, + HDQB_ADS_CALC, + HDQB_ADS_LOW, + HDQB_ADS_HIGH, + HDQB_WAIT_RX, + HDQB_DATA_RX_LOW, + HDQB_DATA_RX_HIGH, + HDQB_WAIT_TX, +}; + +static struct neo1973_vib_priv { struct led_classdev cdev; unsigned int gpio; spinlock_t lock; unsigned int has_pwm; struct s3c2410_pwm pwm; -}; + + unsigned long vib_gpio_pin; /* which pin to meddle with */ + u8 vib_pwm; /* 0 = OFF -- will ensure GPIO deasserted and stop FIQ */ + u8 vib_pwm_latched; + u32 fiq_count; + + struct neo1973_vib_platform_data *pdata; +} neo1973_vib_priv; + +int neo1973_vibrator_fiq_handler(void) +{ + neo1973_vib_priv.fiq_count++; + + if (neo1973_vib_priv.vib_pwm_latched || neo1973_vib_priv.vib_pwm) { /* not idle */ + if (((u8)neo1973_vib_priv.fiq_count) == neo1973_vib_priv.vib_pwm_latched) + neo1973_gpb_setpin(neo1973_vib_priv.vib_gpio_pin, 0); + if (((u8)neo1973_vib_priv.fiq_count) == 0) { + neo1973_vib_priv.vib_pwm_latched = neo1973_vib_priv.vib_pwm; + if (neo1973_vib_priv.vib_pwm_latched) + neo1973_gpb_setpin(neo1973_vib_priv.vib_gpio_pin, 1); + } + + return 1; + } + return 0; +} static void neo1973_vib_vib_set(struct led_classdev *led_cdev, enum led_brightness value) @@ -48,8 +84,8 @@ static void neo1973_vib_vib_set(struct led_classdev *led_cdev, #ifdef CONFIG_MACH_NEO1973_GTA02 if (machine_is_neo1973_gta02()) { /* use FIQ to control GPIO */ - fiq_ipc.vib_pwm = value; /* set it for FIQ */ - fiq_kick(); /* start up FIQs if not already going */ + neo1973_vib_priv.vib_pwm = value; /* set it for FIQ */ + neo1973_vib_priv.pdata->kick_fiq(); /* start up FIQs if not already going */ return; } #endif @@ -103,6 +139,7 @@ static int neo1973_vib_init_hw(struct neo1973_vib_priv *vp) static int neo1973_vib_suspend(struct platform_device *dev, pm_message_t state) { led_classdev_suspend(&neo1973_vib_led.cdev); + neo1973_vib_priv.pdata->disable_fiq(); return 0; } @@ -114,6 +151,7 @@ static int neo1973_vib_resume(struct platform_device *dev) neo1973_vib_init_hw(vp); led_classdev_resume(&neo1973_vib_led.cdev); + neo1973_vib_priv.pdata->enable_fiq(); return 0; } @@ -132,6 +170,8 @@ static int __init neo1973_vib_probe(struct platform_device *pdev) return -EIO; neo1973_vib_led.gpio = r->start; + + neo1973_vib_priv.pdata = pdev->dev.platform_data; platform_set_drvdata(pdev, &neo1973_vib_led); #ifdef CONFIG_MACH_NEO1973_GTA02 @@ -139,8 +179,8 @@ static int __init neo1973_vib_probe(struct platform_device *pdev) neo1973_gpb_setpin(neo1973_vib_led.gpio, 0); /* off */ s3c2410_gpio_cfgpin(neo1973_vib_led.gpio, S3C2410_GPIO_OUTPUT); /* safe, kmalloc'd copy needed for FIQ ISR */ - fiq_ipc.vib_gpio_pin = neo1973_vib_led.gpio; - fiq_ipc.vib_pwm = 0; /* off */ + neo1973_vib_priv.vib_gpio_pin = neo1973_vib_led.gpio; + neo1973_vib_priv.vib_pwm = 0; /* off */ goto configured; } #endif @@ -167,7 +207,7 @@ static int neo1973_vib_remove(struct platform_device *pdev) { #ifdef CONFIG_MACH_NEO1973_GTA02 if (machine_is_neo1973_gta02()) /* use FIQ to control GPIO */ - fiq_ipc.vib_pwm = 0; /* off */ + neo1973_vib_priv.vib_pwm = 0; /* off */ /* would only need kick if already off so no kick needed */ #endif diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 13d5b832065..b5332f714cd 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -93,14 +93,6 @@ config BATTERY_BQ27000_HDQ help Say Y to enable support for the battery on the Neo Freerunner -config GTA02_HDQ - tristate "Neo Freerunner HDQ" - depends on MACH_NEO1973_GTA02 && FIQ && S3C2440_C_FIQ - help - Say Y to enable support for communicating with an HDQ battery - on the Neo Freerunner. You probably want to select - at least BATTERY_BQ27000_HDQ as well - config HDQ_GPIO_BITBANG bool "Generic gpio based HDQ bitbang" help diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 5c421a40afe..cabf53b7472 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -31,5 +31,4 @@ obj-$(CONFIG_BATTERY_PALMTX) += palmtx_battery.o obj-$(CONFIG_BATTERY_BQ27000_HDQ) += bq27000_battery.o obj-$(CONFIG_BATTERY_GTA01) += gta01_battery.o -obj-$(CONFIG_GTA02_HDQ) += gta02_hdq.o obj-$(CONFIG_HDQ_GPIO_BITBANG) += hdq.o diff --git a/drivers/power/gta02_hdq.c b/drivers/power/gta02_hdq.c deleted file mode 100644 index d51f4c9f55a..00000000000 --- a/drivers/power/gta02_hdq.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - * HDQ driver for the FIC Neo1973 GTA02 GSM phone - * - * (C) 2006-2007 by Openmoko, Inc. - * Author: Andy Green <andy@openmoko.com> - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - */ - -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/delay.h> -#include <linux/platform_device.h> -#include <mach/hardware.h> -#include <linux/gta02_hdq.h> -#include <asm/mach-types.h> -#include <mach/gta02.h> -#include <mach/fiq_ipc_gta02.h> - - - -#define HDQ_READ 0 -#define HDQ_WRITE 0x80 - -static int fiq_busy(void) -{ - int request = (volatile u8)fiq_ipc.hdq_request_ctr; - int transact = (volatile u8)fiq_ipc.hdq_transaction_ctr; - - return (request != transact); -} - -int gta02hdq_initialized(void) -{ - return fiq_ipc.hdq_probed; -} -EXPORT_SYMBOL_GPL(gta02hdq_initialized); - -int gta02hdq_read(int address) -{ - int count_sleeps = 5; - int ret = -ETIME; - - if (!fiq_ipc.hdq_probed) - return -EINVAL; - - mutex_lock(&fiq_ipc.hdq_lock); - - fiq_ipc.hdq_error = 0; - fiq_ipc.hdq_ads = address | HDQ_READ; - fiq_ipc.hdq_request_ctr++; - fiq_kick(); - /* - * FIQ takes care of it while we block our calling process - * But we're not spinning -- other processes run normally while - * we wait for the result - */ - while (count_sleeps--) { - msleep(10); /* valid transaction always completes in < 10ms */ - - if (fiq_busy()) - continue; - - if (fiq_ipc.hdq_error) - goto done; /* didn't see a response in good time */ - - ret = fiq_ipc.hdq_rx_data; - goto done; - } - -done: - mutex_unlock(&fiq_ipc.hdq_lock); - return ret; -} -EXPORT_SYMBOL_GPL(gta02hdq_read); - -int gta02hdq_write(int address, u8 data) -{ - int count_sleeps = 5; - int ret = -ETIME; - - if (!fiq_ipc.hdq_probed) - return -EINVAL; - - mutex_lock(&fiq_ipc.hdq_lock); - - fiq_ipc.hdq_error = 0; - fiq_ipc.hdq_ads = address | HDQ_WRITE; - fiq_ipc.hdq_tx_data = data; - fiq_ipc.hdq_request_ctr++; - fiq_kick(); - /* - * FIQ takes care of it while we block our calling process - * But we're not spinning -- other processes run normally while - * we wait for the result - */ - while (count_sleeps--) { - msleep(10); /* valid transaction always completes in < 10ms */ - - if (fiq_busy()) - continue; /* something bad with FIQ */ - - if (fiq_ipc.hdq_error) - goto done; /* didn't see a response in good time */ - - ret = 0; - goto done; - } - -done: - mutex_unlock(&fiq_ipc.hdq_lock); - return ret; -} -EXPORT_SYMBOL_GPL(gta02hdq_write); - -/* sysfs */ - -static ssize_t hdq_sysfs_dump(struct device *dev, struct device_attribute *attr, - char *buf) -{ - int n; - int v; - u8 u8a[128]; /* whole address space for HDQ */ - char *end = buf; - - if (!fiq_ipc.hdq_probed) - return -EINVAL; - - /* the dump does not take care about 16 bit regs, because at this - * bus level we don't know about the chip details - */ - for (n = 0; n < sizeof(u8a); n++) { - v = gta02hdq_read(n); - if (v < 0) - goto bail; - u8a[n] = v; - } - - for (n = 0; n < sizeof(u8a); n += 16) { - hex_dump_to_buffer(u8a + n, sizeof(u8a), 16, 1, end, 4096, 0); - end += strlen(end); - *end++ = '\n'; - *end = '\0'; - } - return (end - buf); - -bail: - return sprintf(buf, "ERROR %d\n", v); -} - -/* you write by <address> <data>, eg, "34 128" */ - -#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0) - -static ssize_t hdq_sysfs_write(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - const char *end = buf + count; - int address = atoi(buf); - - if (!fiq_ipc.hdq_probed) - return -EINVAL; - - while ((buf != end) && (*buf != ' ')) - buf++; - if (buf >= end) - return 0; - while ((buf < end) && (*buf == ' ')) - buf++; - if (buf >= end) - return 0; - - gta02hdq_write(address, atoi(buf)); - - return count; -} - -static DEVICE_ATTR(dump, 0400, hdq_sysfs_dump, NULL); -static DEVICE_ATTR(write, 0600, NULL, hdq_sysfs_write); - -static struct attribute *gta02hdq_sysfs_entries[] = { - &dev_attr_dump.attr, - &dev_attr_write.attr, - NULL -}; - -static struct attribute_group gta02hdq_attr_group = { - .name = "hdq", - .attrs = gta02hdq_sysfs_entries, -}; - - -#ifdef CONFIG_PM -static int gta02hdq_suspend(struct platform_device *pdev, pm_message_t state) -{ - /* after 18s of this, the battery monitor will also go to sleep */ - s3c2410_gpio_setpin(fiq_ipc.hdq_gpio_pin, 0); - s3c2410_gpio_cfgpin(fiq_ipc.hdq_gpio_pin, S3C2410_GPIO_OUTPUT); - return 0; -} - -static int gta02hdq_resume(struct platform_device *pdev) -{ - s3c2410_gpio_setpin(fiq_ipc.hdq_gpio_pin, 1); - s3c2410_gpio_cfgpin(fiq_ipc.hdq_gpio_pin, S3C2410_GPIO_OUTPUT); - return 0; -} -#endif - -static int __init gta02hdq_probe(struct platform_device *pdev) -{ - struct resource *r = platform_get_resource(pdev, 0, 0); - int ret; - struct gta02_hdq_platform_data *pdata = pdev->dev.platform_data; - - if (!machine_is_neo1973_gta02()) - return -EIO; - - if (!r) - return -EINVAL; - - if (!fiq_ready) { - printk(KERN_ERR "hdq probe fails on fiq not ready\n"); - return -EINVAL; - } - - platform_set_drvdata(pdev, NULL); - - mutex_init(&fiq_ipc.hdq_lock); - - /* set our HDQ comms pin from the platform data */ - fiq_ipc.hdq_gpio_pin = r->start; - - s3c2410_gpio_setpin(fiq_ipc.hdq_gpio_pin, 1); - s3c2410_gpio_cfgpin(fiq_ipc.hdq_gpio_pin, S3C2410_GPIO_OUTPUT); - - ret = sysfs_create_group(&pdev->dev.kobj, >a02hdq_attr_group); - if (ret) - return ret; - - fiq_ipc.hdq_probed = 1; /* we are ready to do stuff now */ - - /* - * if wanted, users can defer registration of devices - * that depend on HDQ until after we register, and can use our - * device as parent so suspend-resume ordering is correct - */ - if (pdata->attach_child_devices) - (pdata->attach_child_devices)(&pdev->dev); - - return 0; -} - -static int gta02hdq_remove(struct platform_device *pdev) -{ - sysfs_remove_group(&pdev->dev.kobj, >a02hdq_attr_group); - return 0; -} - -static struct platform_driver gta02hdq_driver = { - .probe = gta02hdq_probe, - .remove = gta02hdq_remove, -#ifdef CONFIG_PM - .suspend = gta02hdq_suspend, - .resume = gta02hdq_resume, -#endif - .driver = { - .name = "gta02-hdq", - }, -}; - -static int __init gta02hdq_init(void) -{ - return platform_driver_register(>a02hdq_driver); -} - -static void __exit gta02hdq_exit(void) -{ - platform_driver_unregister(>a02hdq_driver); -} - -module_init(gta02hdq_init); -module_exit(gta02hdq_exit); - -MODULE_AUTHOR("Andy Green <andy@openmoko.com>"); -MODULE_DESCRIPTION("GTA02 HDQ driver"); -MODULE_LICENSE("GPL"); |