1*e01b6f76SAndroid Build Coastguard Worker /*
2*e01b6f76SAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project
3*e01b6f76SAndroid Build Coastguard Worker *
4*e01b6f76SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*e01b6f76SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*e01b6f76SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*e01b6f76SAndroid Build Coastguard Worker *
8*e01b6f76SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*e01b6f76SAndroid Build Coastguard Worker *
10*e01b6f76SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*e01b6f76SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*e01b6f76SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e01b6f76SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*e01b6f76SAndroid Build Coastguard Worker * limitations under the License.
15*e01b6f76SAndroid Build Coastguard Worker */
16*e01b6f76SAndroid Build Coastguard Worker
17*e01b6f76SAndroid Build Coastguard Worker #include <errno.h>
18*e01b6f76SAndroid Build Coastguard Worker #include <fcntl.h>
19*e01b6f76SAndroid Build Coastguard Worker #include <malloc.h>
20*e01b6f76SAndroid Build Coastguard Worker
21*e01b6f76SAndroid Build Coastguard Worker #include <cutils/native_handle.h>
22*e01b6f76SAndroid Build Coastguard Worker #include <log/log.h>
23*e01b6f76SAndroid Build Coastguard Worker
24*e01b6f76SAndroid Build Coastguard Worker #include <hardware/tv_input.h>
25*e01b6f76SAndroid Build Coastguard Worker
26*e01b6f76SAndroid Build Coastguard Worker /*****************************************************************************/
27*e01b6f76SAndroid Build Coastguard Worker
28*e01b6f76SAndroid Build Coastguard Worker typedef struct tv_input_private {
29*e01b6f76SAndroid Build Coastguard Worker tv_input_device_t device;
30*e01b6f76SAndroid Build Coastguard Worker
31*e01b6f76SAndroid Build Coastguard Worker // Callback related data
32*e01b6f76SAndroid Build Coastguard Worker const tv_input_callback_ops_t* callback;
33*e01b6f76SAndroid Build Coastguard Worker void* callback_data;
34*e01b6f76SAndroid Build Coastguard Worker } tv_input_private_t;
35*e01b6f76SAndroid Build Coastguard Worker
36*e01b6f76SAndroid Build Coastguard Worker static int tv_input_device_open(const struct hw_module_t* module,
37*e01b6f76SAndroid Build Coastguard Worker const char* name, struct hw_device_t** device);
38*e01b6f76SAndroid Build Coastguard Worker
39*e01b6f76SAndroid Build Coastguard Worker static struct hw_module_methods_t tv_input_module_methods = {
40*e01b6f76SAndroid Build Coastguard Worker .open = tv_input_device_open
41*e01b6f76SAndroid Build Coastguard Worker };
42*e01b6f76SAndroid Build Coastguard Worker
43*e01b6f76SAndroid Build Coastguard Worker tv_input_module_t HAL_MODULE_INFO_SYM = {
44*e01b6f76SAndroid Build Coastguard Worker .common = {
45*e01b6f76SAndroid Build Coastguard Worker .tag = HARDWARE_MODULE_TAG,
46*e01b6f76SAndroid Build Coastguard Worker .version_major = 0,
47*e01b6f76SAndroid Build Coastguard Worker .version_minor = 1,
48*e01b6f76SAndroid Build Coastguard Worker .id = TV_INPUT_HARDWARE_MODULE_ID,
49*e01b6f76SAndroid Build Coastguard Worker .name = "Sample TV input module",
50*e01b6f76SAndroid Build Coastguard Worker .author = "The Android Open Source Project",
51*e01b6f76SAndroid Build Coastguard Worker .methods = &tv_input_module_methods,
52*e01b6f76SAndroid Build Coastguard Worker }
53*e01b6f76SAndroid Build Coastguard Worker };
54*e01b6f76SAndroid Build Coastguard Worker
55*e01b6f76SAndroid Build Coastguard Worker /*****************************************************************************/
56*e01b6f76SAndroid Build Coastguard Worker
tv_input_initialize(struct tv_input_device * dev,const tv_input_callback_ops_t * callback,void * data)57*e01b6f76SAndroid Build Coastguard Worker static int tv_input_initialize(struct tv_input_device* dev,
58*e01b6f76SAndroid Build Coastguard Worker const tv_input_callback_ops_t* callback, void* data)
59*e01b6f76SAndroid Build Coastguard Worker {
60*e01b6f76SAndroid Build Coastguard Worker if (dev == NULL || callback == NULL) {
61*e01b6f76SAndroid Build Coastguard Worker return -EINVAL;
62*e01b6f76SAndroid Build Coastguard Worker }
63*e01b6f76SAndroid Build Coastguard Worker tv_input_private_t* priv = (tv_input_private_t*)dev;
64*e01b6f76SAndroid Build Coastguard Worker if (priv->callback != NULL) {
65*e01b6f76SAndroid Build Coastguard Worker return -EEXIST;
66*e01b6f76SAndroid Build Coastguard Worker }
67*e01b6f76SAndroid Build Coastguard Worker
68*e01b6f76SAndroid Build Coastguard Worker priv->callback = callback;
69*e01b6f76SAndroid Build Coastguard Worker priv->callback_data = data;
70*e01b6f76SAndroid Build Coastguard Worker
71*e01b6f76SAndroid Build Coastguard Worker return 0;
72*e01b6f76SAndroid Build Coastguard Worker }
73*e01b6f76SAndroid Build Coastguard Worker
tv_input_get_stream_configurations(const struct tv_input_device *,int,int *,const tv_stream_config_t **)74*e01b6f76SAndroid Build Coastguard Worker static int tv_input_get_stream_configurations(
75*e01b6f76SAndroid Build Coastguard Worker const struct tv_input_device*, int, int*, const tv_stream_config_t**)
76*e01b6f76SAndroid Build Coastguard Worker {
77*e01b6f76SAndroid Build Coastguard Worker return -EINVAL;
78*e01b6f76SAndroid Build Coastguard Worker }
79*e01b6f76SAndroid Build Coastguard Worker
tv_input_open_stream(struct tv_input_device *,int,tv_stream_t *)80*e01b6f76SAndroid Build Coastguard Worker static int tv_input_open_stream(struct tv_input_device*, int, tv_stream_t*)
81*e01b6f76SAndroid Build Coastguard Worker {
82*e01b6f76SAndroid Build Coastguard Worker return -EINVAL;
83*e01b6f76SAndroid Build Coastguard Worker }
84*e01b6f76SAndroid Build Coastguard Worker
tv_input_close_stream(struct tv_input_device *,int,int)85*e01b6f76SAndroid Build Coastguard Worker static int tv_input_close_stream(struct tv_input_device*, int, int)
86*e01b6f76SAndroid Build Coastguard Worker {
87*e01b6f76SAndroid Build Coastguard Worker return -EINVAL;
88*e01b6f76SAndroid Build Coastguard Worker }
89*e01b6f76SAndroid Build Coastguard Worker
tv_input_request_capture(struct tv_input_device *,int,int,buffer_handle_t,uint32_t)90*e01b6f76SAndroid Build Coastguard Worker static int tv_input_request_capture(
91*e01b6f76SAndroid Build Coastguard Worker struct tv_input_device*, int, int, buffer_handle_t, uint32_t)
92*e01b6f76SAndroid Build Coastguard Worker {
93*e01b6f76SAndroid Build Coastguard Worker return -EINVAL;
94*e01b6f76SAndroid Build Coastguard Worker }
95*e01b6f76SAndroid Build Coastguard Worker
tv_input_cancel_capture(struct tv_input_device *,int,int,uint32_t)96*e01b6f76SAndroid Build Coastguard Worker static int tv_input_cancel_capture(struct tv_input_device*, int, int, uint32_t)
97*e01b6f76SAndroid Build Coastguard Worker {
98*e01b6f76SAndroid Build Coastguard Worker return -EINVAL;
99*e01b6f76SAndroid Build Coastguard Worker }
100*e01b6f76SAndroid Build Coastguard Worker
101*e01b6f76SAndroid Build Coastguard Worker /*****************************************************************************/
102*e01b6f76SAndroid Build Coastguard Worker
tv_input_device_close(struct hw_device_t * dev)103*e01b6f76SAndroid Build Coastguard Worker static int tv_input_device_close(struct hw_device_t *dev)
104*e01b6f76SAndroid Build Coastguard Worker {
105*e01b6f76SAndroid Build Coastguard Worker tv_input_private_t* priv = (tv_input_private_t*)dev;
106*e01b6f76SAndroid Build Coastguard Worker if (priv) {
107*e01b6f76SAndroid Build Coastguard Worker free(priv);
108*e01b6f76SAndroid Build Coastguard Worker }
109*e01b6f76SAndroid Build Coastguard Worker return 0;
110*e01b6f76SAndroid Build Coastguard Worker }
111*e01b6f76SAndroid Build Coastguard Worker
112*e01b6f76SAndroid Build Coastguard Worker /*****************************************************************************/
113*e01b6f76SAndroid Build Coastguard Worker
tv_input_device_open(const struct hw_module_t * module,const char * name,struct hw_device_t ** device)114*e01b6f76SAndroid Build Coastguard Worker static int tv_input_device_open(const struct hw_module_t* module,
115*e01b6f76SAndroid Build Coastguard Worker const char* name, struct hw_device_t** device)
116*e01b6f76SAndroid Build Coastguard Worker {
117*e01b6f76SAndroid Build Coastguard Worker int status = -EINVAL;
118*e01b6f76SAndroid Build Coastguard Worker if (!strcmp(name, TV_INPUT_DEFAULT_DEVICE)) {
119*e01b6f76SAndroid Build Coastguard Worker tv_input_private_t* dev = (tv_input_private_t*)malloc(sizeof(*dev));
120*e01b6f76SAndroid Build Coastguard Worker
121*e01b6f76SAndroid Build Coastguard Worker /* initialize our state here */
122*e01b6f76SAndroid Build Coastguard Worker memset(dev, 0, sizeof(*dev));
123*e01b6f76SAndroid Build Coastguard Worker
124*e01b6f76SAndroid Build Coastguard Worker /* initialize the procs */
125*e01b6f76SAndroid Build Coastguard Worker dev->device.common.tag = HARDWARE_DEVICE_TAG;
126*e01b6f76SAndroid Build Coastguard Worker dev->device.common.version = TV_INPUT_DEVICE_API_VERSION_0_1;
127*e01b6f76SAndroid Build Coastguard Worker dev->device.common.module = const_cast<hw_module_t*>(module);
128*e01b6f76SAndroid Build Coastguard Worker dev->device.common.close = tv_input_device_close;
129*e01b6f76SAndroid Build Coastguard Worker
130*e01b6f76SAndroid Build Coastguard Worker dev->device.initialize = tv_input_initialize;
131*e01b6f76SAndroid Build Coastguard Worker dev->device.get_stream_configurations =
132*e01b6f76SAndroid Build Coastguard Worker tv_input_get_stream_configurations;
133*e01b6f76SAndroid Build Coastguard Worker dev->device.open_stream = tv_input_open_stream;
134*e01b6f76SAndroid Build Coastguard Worker dev->device.close_stream = tv_input_close_stream;
135*e01b6f76SAndroid Build Coastguard Worker dev->device.request_capture = tv_input_request_capture;
136*e01b6f76SAndroid Build Coastguard Worker dev->device.cancel_capture = tv_input_cancel_capture;
137*e01b6f76SAndroid Build Coastguard Worker
138*e01b6f76SAndroid Build Coastguard Worker *device = &dev->device.common;
139*e01b6f76SAndroid Build Coastguard Worker status = 0;
140*e01b6f76SAndroid Build Coastguard Worker }
141*e01b6f76SAndroid Build Coastguard Worker return status;
142*e01b6f76SAndroid Build Coastguard Worker }
143