Skip to content

Commit 0259567

Browse files
Dmitry Torokhovgregkh
authored andcommitted
[PATCH] Input: convert konicawc to dynamic input_dev allocation
Input: convert konicawc to dynamic input_dev allocation This is required for input_dev sysfs integration Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent c7f7a56 commit 0259567

File tree

1 file changed

+61
-28
lines changed

1 file changed

+61
-28
lines changed

drivers/usb/media/konicawc.c

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct konicawc {
119119
int yplanesz; /* Number of bytes in the Y plane */
120120
unsigned int buttonsts:1;
121121
#ifdef CONFIG_INPUT
122-
struct input_dev input;
122+
struct input_dev *input;
123123
char input_physname[64];
124124
#endif
125125
};
@@ -218,6 +218,57 @@ static void konicawc_adjust_picture(struct uvd *uvd)
218218
konicawc_camera_on(uvd);
219219
}
220220

221+
#ifdef CONFIG_INPUT
222+
223+
static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev)
224+
{
225+
struct input_dev *input_dev;
226+
227+
usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
228+
strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
229+
230+
cam->input = input_dev = input_allocate_device();
231+
if (!input_dev) {
232+
warn("Not enough memory for camera's input device\n");
233+
return;
234+
}
235+
236+
input_dev->name = "Konicawc snapshot button";
237+
input_dev->phys = cam->input_physname;
238+
usb_to_input_id(dev, &input_dev->id);
239+
input_dev->cdev.dev = &dev->dev;
240+
241+
input_dev->evbit[0] = BIT(EV_KEY);
242+
input_dev->keybit[LONG(BTN_0)] = BIT(BTN_0);
243+
244+
input_dev->private = cam;
245+
246+
input_register_device(cam->input);
247+
}
248+
249+
static void konicawc_unregister_input(struct konicawc *cam)
250+
{
251+
if (cam->input) {
252+
input_unregister_device(cam->input);
253+
cam->input = NULL;
254+
}
255+
}
256+
257+
static void konicawc_report_buttonstat(struct konicawc *cam)
258+
{
259+
if (cam->input) {
260+
input_report_key(cam->input, BTN_0, cam->buttonsts);
261+
input_sync(cam->input);
262+
}
263+
}
264+
265+
#else
266+
267+
static inline void konicawc_register_input(struct konicawc *cam, struct usb_device *dev) { }
268+
static inline void konicawc_unregister_input(struct konicawc *cam) { }
269+
static inline void konicawc_report_buttonstat(struct konicawc *cam) { }
270+
271+
#endif /* CONFIG_INPUT */
221272

222273
static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct urb *stsurb)
223274
{
@@ -273,10 +324,7 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
273324
if(button != cam->buttonsts) {
274325
DEBUG(2, "button: %sclicked", button ? "" : "un");
275326
cam->buttonsts = button;
276-
#ifdef CONFIG_INPUT
277-
input_report_key(&cam->input, BTN_0, cam->buttonsts);
278-
input_sync(&cam->input);
279-
#endif
327+
konicawc_report_buttonstat(cam);
280328
}
281329

282330
if(sts == 0x01) { /* drop frame */
@@ -645,9 +693,9 @@ static int konicawc_set_video_mode(struct uvd *uvd, struct video_window *vw)
645693
RingQueue_Flush(&uvd->dp);
646694
cam->lastframe = -2;
647695
if(uvd->curframe != -1) {
648-
uvd->frame[uvd->curframe].curline = 0;
649-
uvd->frame[uvd->curframe].seqRead_Length = 0;
650-
uvd->frame[uvd->curframe].seqRead_Index = 0;
696+
uvd->frame[uvd->curframe].curline = 0;
697+
uvd->frame[uvd->curframe].seqRead_Length = 0;
698+
uvd->frame[uvd->curframe].seqRead_Index = 0;
651699
}
652700

653701
konicawc_start_data(uvd);
@@ -718,7 +766,6 @@ static void konicawc_configure_video(struct uvd *uvd)
718766
DEBUG(1, "setting initial values");
719767
}
720768

721-
722769
static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id *devid)
723770
{
724771
struct usb_device *dev = interface_to_usbdev(intf);
@@ -839,21 +886,8 @@ static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id
839886
err("usbvideo_RegisterVideoDevice() failed.");
840887
uvd = NULL;
841888
}
842-
#ifdef CONFIG_INPUT
843-
/* Register input device for button */
844-
memset(&cam->input, 0, sizeof(struct input_dev));
845-
cam->input.name = "Konicawc snapshot button";
846-
cam->input.private = cam;
847-
cam->input.evbit[0] = BIT(EV_KEY);
848-
cam->input.keybit[LONG(BTN_0)] = BIT(BTN_0);
849-
usb_to_input_id(dev, &cam->input.id);
850-
input_register_device(&cam->input);
851-
852-
usb_make_path(dev, cam->input_physname, 56);
853-
strcat(cam->input_physname, "/input0");
854-
cam->input.phys = cam->input_physname;
855-
info("konicawc: %s on %s\n", cam->input.name, cam->input.phys);
856-
#endif
889+
890+
konicawc_register_input(cam, dev);
857891
}
858892

859893
if (uvd) {
@@ -869,10 +903,9 @@ static void konicawc_free_uvd(struct uvd *uvd)
869903
int i;
870904
struct konicawc *cam = (struct konicawc *)uvd->user_data;
871905

872-
#ifdef CONFIG_INPUT
873-
input_unregister_device(&cam->input);
874-
#endif
875-
for (i=0; i < USBVIDEO_NUMSBUF; i++) {
906+
konicawc_unregister_input(cam);
907+
908+
for (i = 0; i < USBVIDEO_NUMSBUF; i++) {
876909
usb_free_urb(cam->sts_urb[i]);
877910
cam->sts_urb[i] = NULL;
878911
}

0 commit comments

Comments
 (0)