GPS: Add gpio controller driver for brcm 4750
authorprabhu.annabathula <prabhu.annabathula@motorola.com>
Fri, 18 Jun 2010 22:47:20 +0000 (17:47 -0500)
committerColin Cross <ccross@android.com>
Wed, 6 Oct 2010 23:33:10 +0000 (16:33 -0700)
driver provides ioctls for broadcom gps guci library to set gps
reset and standby lines for brcm 4750 chip

Signed-off-by: prabhu.annabathula <prabhu.annabathula@motorola.com>
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/gps-gpio-brcm4750.c [new file with mode: 0755]
include/linux/gps-gpio-brcm4750.h [new file with mode: 0755]

index 3b32cb25de934d8ffb29b10d6b953d639aa39aa5..6bde1ef6586334a1e59893453e4c6ad2df144538 100644 (file)
@@ -460,6 +460,12 @@ config APANIC_PLABEL
         If your platform uses a different flash partition label for storing
         crashdumps, enter it here.
 
+config GPS_GPIO_BRCM4750
+       bool "Enable gpio controller for GPS brcm 4750"
+       default y
+       ---help---
+       Adds GPIO controller driver for GPS Broadcom 4750 chipset
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
index 7a9d824005087d02a8d496da89d870c7509892a9..5695c1b35ef41d5167e3cbb420dd3f82e042c08e 100644 (file)
@@ -44,3 +44,4 @@ obj-$(CONFIG_SENSORS_AK8975)  += akm8975.o
 obj-$(CONFIG_SENSORS_KXTF9)    += kxtf9.o
 obj-$(CONFIG_SENSORS_MAX9635)  += max9635.o
 obj-$(CONFIG_SENSORS_L3G4200D) += l3g4200d.o
+obj-$(CONFIG_GPS_GPIO_BRCM4750)        += gps-gpio-brcm4750.o
diff --git a/drivers/misc/gps-gpio-brcm4750.c b/drivers/misc/gps-gpio-brcm4750.c
new file mode 100755 (executable)
index 0000000..0b53bad
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2010 Motorola, Inc.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307, USA
+ */
+
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/gpio.h>
+#include <linux/gps-gpio-brcm4750.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
+
+struct gps_gpio_brcm4750_platform_data *gps_gpio_data;
+
+static int gps_brcm4750_ioctl(struct inode *inode,
+               struct file *filp, unsigned int cmd, unsigned long arg)
+{
+       unsigned int gpio_val;
+
+       if (cmd <= 0)
+               return -EINVAL;
+
+       if (copy_from_user((void *) &gpio_val, (void *) arg,
+                               sizeof(int)))
+               return -EFAULT;
+
+       if (!(gpio_val == 0 || gpio_val == 1))
+               return -EINVAL;
+
+       switch (cmd) {
+       case IOC_GPS_GPIO_RESET:
+               pr_info("%s: Setting gps gpio reset pin: %d\n",
+                __func__, gpio_val);
+               if (gps_gpio_data->set_reset_gpio)
+                       gps_gpio_data->set_reset_gpio(gpio_val);
+               break;
+       case IOC_GPS_GPIO_STANDBY:
+               pr_info("%s: Setting gps gpio standby pin to: %d\n",
+                       __func__, gpio_val);
+               if (gps_gpio_data->set_standby_gpio)
+                       gps_gpio_data->set_standby_gpio(gpio_val);
+               break;
+       default:
+               pr_info("%s: Invalid GPS GPIO IOCTL command\n", __func__);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static const struct file_operations gps_brcm4750_fops = {
+       .owner          = THIS_MODULE,
+       .ioctl          = gps_brcm4750_ioctl,
+};
+
+static struct miscdevice gps_gpio_miscdev = {
+       .minor  = MISC_DYNAMIC_MINOR,
+       .name   = GPS_GPIO_DRIVER_NAME,
+       .fops   = &gps_brcm4750_fops,
+};
+
+static int gps_gpio_brcm4750_probe(struct platform_device *pdev)
+{
+       gps_gpio_data = pdev->dev.platform_data;
+       if (misc_register(&gps_gpio_miscdev)) {
+               pr_info("%s: gps_brcm4750 misc_register failed\n", __func__);
+               return -1;
+       }
+       return 0;
+}
+
+static int gps_gpio_brcm4750_remove(struct platform_device *pdev)
+{
+       if (gps_gpio_data->free_gpio)
+               gps_gpio_data->free_gpio();
+       return 0;
+}
+
+static struct platform_driver gps_gpio_brcm4750_driver = {
+       .probe          = gps_gpio_brcm4750_probe,
+       .remove         = gps_gpio_brcm4750_remove,
+       .driver         = {
+               .name           = GPS_GPIO_DRIVER_NAME,
+               .owner          = THIS_MODULE,
+       },
+};
+
+static int __init gps_gpio_brcm4750_init(void)
+{
+       return platform_driver_register(&gps_gpio_brcm4750_driver);
+}
+
+static void __exit gps_gpio_brcm4750_exit(void)
+{
+       platform_driver_unregister(&gps_gpio_brcm4750_driver);
+}
+
+module_init(gps_gpio_brcm4750_init);
+module_exit(gps_gpio_brcm4750_exit);
+
+MODULE_AUTHOR("Motorola");
+MODULE_DESCRIPTION("GPS GPIO Controller for BRCM 4750");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/gps-gpio-brcm4750.h b/include/linux/gps-gpio-brcm4750.h
new file mode 100755 (executable)
index 0000000..d534ab7
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2010 Motorola, Inc.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307, USA
+ */
+
+#ifndef _GPS_GPIO_BRCM4750_H_
+#define _GPS_GPIO_BRCM4750_H_
+
+#include <linux/ioctl.h>
+
+#define GPS_GPIO_DRIVER_NAME "gps_brcm4750"
+
+#define GPS_GPIO_IOCTL_BASE    'w'
+
+#define IOC_GPS_GPIO_RESET       _IOW(GPS_GPIO_IOCTL_BASE, 0x0, int)
+#define IOC_GPS_GPIO_STANDBY     _IOW(GPS_GPIO_IOCTL_BASE, 0x1, int)
+
+#ifdef __KERNEL__
+struct gps_gpio_brcm4750_platform_data {
+      void (*set_reset_gpio)(unsigned int gpio_val);
+      void (*set_standby_gpio)(unsigned int gpio_val);
+      void (*free_gpio)(void);
+} __attribute__ ((packed));
+
+#endif  /* __KERNEL__ */
+#endif  /* _GPS_GPIO_BRCM4750_H_ */