summaryrefslogtreecommitdiff
path: root/drivers/media/video/wmt_v4l2/sensors/flash/flash_gpio.c
blob: 7e29306dcdde1fba31a61b3549087a33c2d41201 (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
/*
 * ==========================================================================
 *
 *       Filename:  flash_gpio.c
 *
 *    Description:  wmt.camera.flash gpio:6
 *
 *        Version:  0.01
 *        Created:  2013年07月02日 15时00分12秒
 *
 *         Author:  smmei (), 
 *        Company:  
 *
 * ==========================================================================
 */

#include <linux/gpio.h>
#include <mach/wmt_env.h>
#include "../cmos-subdev.h"
#include "flash.h"

static int fl_gpio = -1;

static int flash_dev_set_mode(int mode)
{
	if (fl_gpio < 0)
		return -EINVAL;

	switch (mode) {
	case FLASH_MODE_OFF:
		gpio_direction_output(fl_gpio, 0);
		break;
	case FLASH_MODE_ON:
		gpio_direction_output(fl_gpio, 1);
		break;
	case FLASH_MODE_STROBE:
		gpio_direction_output(fl_gpio, 1);
		break;
	case FLASH_MODE_TORCH:
		gpio_direction_output(fl_gpio, 1);
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int parse_charger_param(void)
{
	char *dev_name = "gpio";
	char *env = "wmt.camera.flash";
	char s[64];
	size_t l = sizeof(s);
	int gpio;
	int rc;

	if (wmt_getsyspara(env, s, &l)) {
		//pr_err("read %s fail!\n", env);
		return -EINVAL;
	}

	if (strncmp(s, dev_name, strlen(dev_name))) {
		return -EINVAL;
	}

	rc = sscanf(s, "gpio:%d", &gpio);
	if (rc < 1) {
		pr_err("bad uboot env: %s\n", env);
		return -EINVAL;
	}

	rc = gpio_request(gpio, "flash gpio");
	if (rc) {
		pr_err("flash gpio(%d) request failed\n", gpio);
		return rc;
	}

	fl_gpio = gpio;
	printk("flash gpio%d register success\n", fl_gpio);
	return 0;
}

static int flash_dev_init(void)
{
	return parse_charger_param();
}

static void flash_dev_exit(void)
{
	if (fl_gpio >= 0) {
		gpio_free(fl_gpio);
		fl_gpio = -1;
	}
}

struct flash_dev flash_dev_gpio = {
	.name		= "gpio",
	.init		= flash_dev_init,
	.set_mode	= flash_dev_set_mode,
	.exit		= flash_dev_exit,
};