23 #include <linux/kernel.h>
24 #include <linux/errno.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
34 #define APPLE_VENDOR_ID 0x05AC
36 #define USB_REQ_GET_REPORT 0x01
37 #define USB_REQ_SET_REPORT 0x09
39 #define ACD_USB_TIMEOUT 250
41 #define ACD_USB_EDID 0x0302
42 #define ACD_USB_BRIGHTNESS 0x0310
44 #define ACD_BTN_NONE 0
45 #define ACD_BTN_BRIGHT_UP 3
46 #define ACD_BTN_BRIGHT_DOWN 4
48 #define ACD_URB_BUFFER_LEN 2
49 #define ACD_MSG_BUFFER_LEN 2
51 #define APPLEDISPLAY_DEVICE(prod) \
52 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
53 USB_DEVICE_ID_MATCH_INT_CLASS | \
54 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
55 .idVendor = APPLE_VENDOR_ID, \
56 .idProduct = (prod), \
57 .bInterfaceClass = USB_CLASS_HID, \
58 .bInterfaceProtocol = 0x00
88 static void appledisplay_complete(
struct urb *
urb)
102 "OVERFLOW with data length %d, actual length is %d\n",
108 dev_dbg(dev,
"%s - urb shuttingdown with status: %d\n",
112 dev_dbg(dev,
"%s - nonzero urb status received: %d/n",
131 spin_unlock_irqrestore(&pdata->
lock, flags);
136 dev_err(dev,
"%s - usb_submit_urb failed with result %d\n",
151 usb_sndctrlpipe(pdata->
udev, 0),
169 usb_rcvctrlpipe(pdata->
udev, 0),
184 .get_brightness = appledisplay_bl_get_brightness,
185 .update_status = appledisplay_bl_update_status,
194 retval = appledisplay_bl_get_brightness(pdata->
bd);
196 pdata->
bd->props.brightness =
retval;
208 struct usb_device *
udev = interface_to_usbdev(iface);
209 struct usb_host_interface *iface_desc;
211 int int_in_endpointAddr = 0;
217 iface_desc = iface->cur_altsetting;
218 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
219 endpoint = &iface_desc->endpoint[
i].desc;
220 if (!int_in_endpointAddr && usb_endpoint_is_int_in(endpoint)) {
226 if (!int_in_endpointAddr) {
227 dev_err(&iface->dev,
"Could not find int-in endpoint\n");
235 dev_err(&iface->dev,
"Out of memory\n");
249 "Allocating buffer for control messages failed\n");
257 dev_err(&iface->dev,
"Allocating URB failed\n");
266 dev_err(&iface->dev,
"Allocating URB buffer failed\n");
271 usb_fill_int_urb(pdata->
urb, udev,
272 usb_rcvintpipe(udev, int_in_endpointAddr),
277 dev_err(&iface->dev,
"Submitting URB failed\n");
282 snprintf(bl_name,
sizeof(bl_name),
"appledisplay%d",
286 props.max_brightness = 0xff;
288 &appledisplay_bl_data, &props);
289 if (IS_ERR(pdata->
bd)) {
290 dev_err(&iface->dev,
"Backlight registration failed\n");
291 retval = PTR_ERR(pdata->
bd);
296 brightness = appledisplay_bl_get_brightness(pdata->
bd);
298 if (brightness < 0) {
301 "Error while getting initial brightness: %d\n", retval);
309 usb_set_intfdata(iface, pdata);
324 if (pdata->
bd && !IS_ERR(pdata->
bd))
328 usb_set_intfdata(iface,
NULL);
333 static void appledisplay_disconnect(
struct usb_interface *iface)
351 static struct usb_driver appledisplay_driver = {
352 .name =
"appledisplay",
353 .probe = appledisplay_probe,
354 .disconnect = appledisplay_disconnect,
355 .id_table = appledisplay_table,
358 static int __init appledisplay_init(
void)
366 return usb_register(&appledisplay_driver);
369 static void __exit appledisplay_exit(
void)