summaryrefstree
path: root/kernel/drivers/gps/sec_gps_bcm4752.c
blob: 6c6a0dd2496331a1f0e50315c5746e4e553cddab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <linux/init.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>

#include <plat/gpio-cfg.h>
#include <linux/module.h>

#include <linux/sec_sysfs.h>
#include <mach/exynos-pm.h>

static struct device *gps_dev;
static unsigned int gps_pwr_on = 0;
static struct notifier_block lpa_nb_gps;

int check_gps_op(void)
{
	/* This pin is high when gps is working */
	int gps_is_running = gpio_get_value(gps_pwr_on);

	pr_debug("LPA : check_gps_op(%d)\n", gps_is_running);

	return gps_is_running;
}
EXPORT_SYMBOL(check_gps_op);

#ifdef CONFIG_CPU_IDLE
static int exynos_gps_lp_event(struct notifier_block *nb, unsigned long event, void *data)
{
	int ret = NOTIFY_DONE;
	
	switch (event) {
	case LPA_PREPARE:
	case LPC_PREPARE:
		if (check_gps_op()) {
			pr_debug("exynos_gps_lp_event : event=%lu\n",event);
			ret = notifier_from_errno(-EBUSY);
		}
		break;
	case LPA_ENTER:
		break;
	case LPA_EXIT:
		break;
	}
	
	return ret;
}
#endif

static int __init gps_bcm4752_init(void)
{
	int ret = 0;
	const char *gps_node = "samsung,exynos-bcm4752";

	struct device_node *root_node = NULL;

	gps_dev = sec_device_create(NULL, "gps");
	BUG_ON(!gps_dev);

	root_node = of_find_compatible_node(NULL, NULL, gps_node);
	if (!root_node) {
		WARN(1, "failed to get device node of bcm4752\n");
		ret = -ENODEV;
		goto err_sec_device_create;
	}


	gps_pwr_on = of_get_gpio(root_node, 0);
	if (!gpio_is_valid(gps_pwr_on)) {
		WARN(1, "Invalied gpio pin : %d\n", gps_pwr_on);
		ret = -ENODEV;
		goto err_sec_device_create;
	}

	if (gpio_request(gps_pwr_on, "GPS_PWR_EN")) {
		WARN(1, "fail to request gpio(GPS_PWR_EN)\n");
		ret = -ENODEV;
		goto err_sec_device_create;
	}
	gpio_direction_output(gps_pwr_on, 0);
	gpio_export(gps_pwr_on, 1);
	gpio_export_link(gps_dev, "GPS_PWR_EN", gps_pwr_on);

#ifdef CONFIG_CPU_IDLE
	lpa_nb_gps.notifier_call = exynos_gps_lp_event;
	lpa_nb_gps.next = NULL;
	lpa_nb_gps.priority = 0;
	
	ret = exynos_pm_register_notifier(&lpa_nb_gps);
	if (ret) {
		dev_err(gps_dev, "failed to register low power mode notifier\n");
		return ret;
	}
#endif


	return 0;

err_sec_device_create:
	sec_device_destroy(gps_dev->devt);
	return ret;
}

device_initcall(gps_bcm4752_init);