2 * Copyright (C) 2010 Motorola, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #include <linux/device.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
22 #include <linux/usb.h>
23 #include <linux/workqueue.h>
24 #include <linux/switch.h>
25 #include <linux/spi/cpcap.h>
29 #define MOT_SEMU 0x0001
30 #define MOT_IR_REMOTE 0x0002
31 #define MOT_AUDIO_JACK 0x0004
33 #define AUDIO_JACK_STATUS_REPORT 0x3E
35 static struct switch_dev sdev;
39 unsigned long audio_cable_inserted;
40 struct work_struct work;
43 static void audio_jack_status_work(struct work_struct *work)
45 struct motorola_sc *sc = container_of(work, struct motorola_sc, work);
47 cpcap_accy_whisper_spdif_set_state(sc->audio_cable_inserted);
50 static int mot_rawevent(struct hid_device *hdev, struct hid_report *report,
53 struct motorola_sc *sc = hid_get_drvdata(hdev);
55 dbg_hid("%s\n", __func__);
57 if (sc->quirks & MOT_AUDIO_JACK) {
58 if (data[0] == AUDIO_JACK_STATUS_REPORT) {
59 sc->audio_cable_inserted = data[1];
60 schedule_work(&sc->work);
68 static int mot_probe(struct hid_device *hdev, const struct hid_device_id *id)
71 unsigned long quirks = id->driver_data;
72 struct motorola_sc *sc;
73 unsigned int connect_mask = 0;
75 dbg_hid("%s %d\n", __func__, __LINE__);
77 sc = kzalloc(sizeof(*sc), GFP_KERNEL);
79 dev_err(&hdev->dev, "can't alloc motorola descriptor\n");
84 hid_set_drvdata(hdev, sc);
86 ret = hid_parse(hdev);
88 dev_err(&hdev->dev, "parse failed\n");
92 if (quirks & MOT_SEMU)
93 connect_mask |= HID_CONNECT_HIDRAW;
94 if (quirks & MOT_IR_REMOTE)
95 connect_mask |= (HID_CONNECT_HIDINPUT |
96 HID_CONNECT_HIDINPUT_FORCE);
97 if (quirks & MOT_AUDIO_JACK)
98 INIT_WORK(&sc->work, audio_jack_status_work);
100 ret = hid_hw_start(hdev, connect_mask);
102 dev_err(&hdev->dev, "hw start failed\n");
103 goto err_free_cancel;
106 switch_set_state(&sdev, 1);
108 dbg_hid("%s %d\n", __func__, __LINE__);
112 cancel_work_sync(&sc->work);
118 static void mot_remove(struct hid_device *hdev)
120 struct motorola_sc *sc = hid_get_drvdata(hdev);
122 dbg_hid("%s\n", __func__);
124 cancel_work_sync(&sc->work);
126 switch_set_state(&sdev, 0);
129 kfree(hid_get_drvdata(hdev));
132 static const struct hid_device_id mot_devices[] = {
133 { HID_USB_DEVICE(USB_VENDOR_ID_MOTOROLA, USB_DEVICE_ID_HD_DOCK),
134 .driver_data = MOT_SEMU | MOT_IR_REMOTE | MOT_AUDIO_JACK },
137 MODULE_DEVICE_TABLE(hid, mot_devices);
139 static const struct hid_report_id mot_reports[] = {
140 { HID_INPUT_REPORT },
144 static struct hid_driver motorola_driver = {
146 .id_table = mot_devices,
148 .remove = mot_remove,
149 .raw_event = mot_rawevent,
150 .report_table = mot_reports,
153 static int motorola_init(void)
157 dbg_hid("Registering MOT HID driver\n");
159 ret = hid_register_driver(&motorola_driver);
161 printk(KERN_ERR "Can't register Motorola driver\n");
163 sdev.name = "whisper_hid";
164 switch_dev_register(&sdev);
169 static void motorola_exit(void)
171 switch_dev_unregister(&sdev);
172 hid_unregister_driver(&motorola_driver);
175 module_init(motorola_init);
176 module_exit(motorola_exit);
177 MODULE_LICENSE("GPL");