summaryrefslogtreecommitdiff
path: root/drivers/media/video/wmt_v4l2/sensors/cmos-subdev.c
blob: 9cbd1d36bfcbdf039749edb946db071aeef5165c (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * linux/drivers/media/video/wmt_v4l2/cmos/cmos-dev.c
 * WonderMedia v4l cmos device driver
 *
 * Copyright c 2010  WonderMedia  Technologies, Inc.
 *
 * This program is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 2 of the License, or 
 * (at your option) any later version.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#include <linux/module.h>
#include <linux/videodev2.h>

#include "cmos-subdev.h"
#include "../wmt-vid.h"

void cmos_init_8bit_addr(uint8_t *array_addr, size_t array_size, uint8_t i2c_addr)
{
	uint32_t addr, data;
	int i;

	for(i=0;i<array_size;i+=2)
	{
		addr = array_addr[i];
		data = array_addr[i+1];
		wmt_vid_i2c_write(i2c_addr,addr,data);
	}
}
EXPORT_SYMBOL(cmos_init_8bit_addr);

void cmos_init_16bit_addr(uint32_t *array_addr, size_t array_size, uint32_t i2c_addr)
{
	unsigned int addr,data,i;

	for(i=0;i<array_size;i+=2)
	{
		addr = array_addr[i];
		data = array_addr[i+1];
		wmt_vid_i2c_write16addr(i2c_addr,addr,data);
	}
}
EXPORT_SYMBOL(cmos_init_16bit_addr);

void cmos_init_16bit_addr_16bit_data(uint32_t *array_addr, size_t array_size, uint32_t i2c_addr)
{
	unsigned int addr,data,i;

	for(i=0;i<array_size;i+=2)
	{
		addr = array_addr[i];
		data = array_addr[i+1];
		wmt_vid_i2c_write16data(i2c_addr,addr,data);
	}
}
EXPORT_SYMBOL(cmos_init_16bit_addr_16bit_data);

static LIST_HEAD(__cmos_subdev_list);

int cmos_register_sudbdev(struct cmos_subdev *sd)
{
	printk(KERN_INFO "register cmos: %s\n", sd->name);
	list_add_tail(&sd->list, &__cmos_subdev_list);
	return 0;
}
EXPORT_SYMBOL(cmos_register_sudbdev);

void cmos_unregister_subdev(struct cmos_subdev *sd)
{
	printk(KERN_INFO "unregister cmos: %s\n", sd->name);
	list_del(&sd->list);
}
EXPORT_SYMBOL(cmos_unregister_subdev);

struct cmos_subdev *cmos_subdev_get_by_try(void)
{
	struct cmos_subdev *sd;
	struct list_head *node, *next;

	list_for_each_safe(node, next, &__cmos_subdev_list) {
		sd = container_of(node, struct cmos_subdev, list);
		if (!cmos_subdev_call(sd, identify)) {
			return sd;
		}
	}
	return NULL;
}

// below init all cmos

extern struct cmos_subdev nmi;
extern struct cmos_subdev gc0307, gc0308, gc0309, gc0311, gc0329, gc0328, gc2015, gc2035,gc2155;
extern struct cmos_subdev ov2640, ov2643, ov2659, ov3640, ov3660, ov5640,ov7675,ov9740;
extern struct cmos_subdev hi704, hi253,hi257;
extern struct cmos_subdev siv121d,siv120d, sid130b;
extern struct cmos_subdev sp0838, sp0718,sp0a19, sp2518;
extern struct cmos_subdev bf3a03, bf3920,bf3703;
extern struct cmos_subdev s5k5ca;
extern struct cmos_subdev nt99141;

static struct cmos_subdev *devices[] = {
	&nmi,
	/* SuperPix */
	&sp0718, &sp0a19,&sp2518, &sp0838,
	/* Seti */
	&siv121d,&siv120d, &sid130b,
	/* Hynix */
	&hi253,&hi257,
	/* Galaxyc */
	&gc0307,&gc0308, &gc0309, &gc0328, &gc0329, &gc2035,&gc2155,
	/* OminiVision */
	&ov2659, &ov5640,&ov7675,&ov9740,&ov2643,
	/*BYD*/
	&bf3a03,&bf3920,&bf3703,
	/* Samsung */
	&s5k5ca,
	/*Novatek*/
	&nt99141,
	NULL,
};

int cmos_subdev_init(void)
{
	int ret = 0;
	struct cmos_subdev **sd = &devices[0];

	while (*sd) {
		ret = cmos_register_sudbdev(*sd);
		if (ret) {
			break;
		}
		sd++;
	}

	return ret;
}

void cmos_subdev_exit(void)
{
	struct cmos_subdev **sd = &devices[0];

	while (*sd) {
		cmos_unregister_subdev(*sd);
		sd++;
	}
}