hid: new driver for PicoLCD device
Subsystems (3)
Bruno Prémont
maintainerv2 cover hid: new driver for PicoLCD device
This series adds support for PicoLCD USB HID device adding support for the various features in different patches so each patch concentrates on a device class.
I implemented the patches so input support is required (this should make it easy to later on add support for other PicoLCD device that don't have the same feature set but share compatible HID reports.
This causes presence of a few #ifdef blocks to include support for the different feature sets when their matching device class has been selected.
Though to minimize the amount of such #ifs I put all code for a single class together and defined a few stubs in the #else part so global device initialization is not filled with #ifs.
I'm not sure which of the following approaches is better (I took the first one):
- Check for built-in or build-as-module class support with #if defined():
#if defined(CONFIG_..CLASS) || defined(CONFIG_..CLASS_MODULE)
- Add extra CONFIG_PICOLCD_$CLASS to Kconfig and let Kconfig get things correctly set having just simple
#ifdef CONFIG_PICOLCD_$CLASS in the code.
The series depends on my previous patch adding HID suspend support (I've not yet looked at improving it). The patch adding support for backlight class depends on backlight state as of 2.6.34-rc2.
All the rest should apply against 2.6.33 (unless I did oversee some detail).
Bruno
Bruno Prémont
maintainerPATCH v2 1/6 hid: new driver for PicoLCD device
Add basic driver for PicoLCD graphics device.
Initially support keypad with input device, operation mode switching and provide support for debugging communication via events file from debugfs.
--- Documentation/ABI/testing/sysfs-driver-hid-picolcd | 17 + drivers/hid/Kconfig | 18 + drivers/hid/Makefile | 1 + drivers/hid/hid-core.c | 2 + drivers/hid/hid-ids.h | 2 + drivers/hid/hid-picolcd.c | 1244 ++++++++++++++++++++ 6 files changed, 1284 insertions(+), 0 deletions(-)
Documentation/ABI/testing/sysfs-driver-hid-picolcd new file +17 -0
@@ -0,0 +1,17 @@ +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/operation_mode +Date: March 2010 +Contact: Bruno Prémont <[email protected]> +Description: Make it possible to switch the PicoLCD device between LCD + (firmware) and bootloader (flasher) operation modes. + + Reading: returns list of available modes is show, the active mode + being enclosed in brackets ('<' and '>') + + Writing: causes operation mode switch. Permitted values are + the non-active mode names listed when read, optionally followed + by a delay value expressed in ms. + + Note: when switching mode the current PicoLCD HID device gets + disconnected and reconnects after above delay (default value + is 5 seconds though this default should not be depended on). +
drivers/hid/Kconfig +18 -0
@@ -227,6 +227,24 @@ config HID_PETALYNX ---help--- Support for Petalynx Maxter remote control. +config HID_PICOLCD + tristate "PicoLCD (graphic version)" + depends on USB_HID + ---help--- + This provides support for Minibox PicoLCD devices, currently + only the graphical ones are supported. + + This includes support for the following device features: + - Keypad + - Switching between Firmware and Flash mode + Features that are not (yet) supported: + - Framebuffer for monochrome 256x64 display + - Backlight control + - Contrast control + - IR + - General purpose outputs + - EEProm / Flash access + config HID_SAMSUNG tristate "Samsung" if EMBEDDED depends on USB_HID
drivers/hid/Makefile +1 -0
@@ -36,6 +36,7 @@ obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o +obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o obj-$(CONFIG_HID_SONY) += hid-sony.o
drivers/hid/hid-core.c +2 -0
@@ -1330,6 +1330,8 @@ static const struct hid_device_id hid_blacklist[] = { { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER) }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR) }, + { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICOLCD_BOOTLOADER) }, { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) }, { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) }, { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
drivers/hid/hid-ids.h +2 -0
@@ -330,6 +330,8 @@#define USB_VENDOR_ID_MICROCHIP 0x04d8#define USB_DEVICE_ID_PICKIT1 0x0032#define USB_DEVICE_ID_PICKIT2 0x0033 +#define USB_DEVICE_ID_PICOLCD 0xc002 +#define USB_DEVICE_ID_PICOLCD_BOOTLOADER 0xf002#define USB_VENDOR_ID_MICROSOFT 0x045e#define USB_DEVICE_ID_SIDEWINDER_GV 0x003b
drivers/hid/hid-picolcd.c new file +1244 -0
1,244 lines not on this page · raw message
Signature · 1 line
1.6.4.4
drivers/hid/hid-picolcd.c line 79
Quoted 8 lines · Bruno Prémont
drivers/hid/hid-picolcd.c new file +8
-0+/* Input device +* +* The PicoLCD has an IR receiver header, a built-in keypad with 5 keys +* and header for 4x4 key matrix. The built-in keys are part of the matrix. +*/ +#define PICOLCD_KEYS 17 + +static const int def_keymap[PICOLCD_KEYS ] = {
def_keymap[] = {
...
};
#define PICOLCD_KEYS ARRAY_SIZE(def_keymap);
would be safe. Also unsigned short should cover it.
Quoted 102 lines
drivers/hid/hid-picolcd.c new file +102
-0+KEY_RESERVED ,/* none */ +KEY_BACK ,/* col 4 + row 1 */ +KEY_HOMEPAGE ,/* col 3 + row 1 */ +KEY_RESERVED ,/* col 2 + row 1 */ +KEY_RESERVED ,/* col 1 + row 1 */ +KEY_SCROLLUP ,/* col 4 + row 2 */ +KEY_OK ,/* col 3 + row 2 */ +KEY_SCROLLDOWN ,/* col 2 + row 2 */ +KEY_RESERVED ,/* col 1 + row 2 */ +KEY_RESERVED ,/* col 4 + row 3 */ +KEY_RESERVED ,/* col 3 + row 3 */ +KEY_RESERVED ,/* col 2 + row 3 */ +KEY_RESERVED ,/* col 1 + row 3 */ +KEY_RESERVED ,/* col 4 + row 4 */ +KEY_RESERVED ,/* col 3 + row 4 */ +KEY_RESERVED ,/* col 2 + row 4 */ + KEY_RESERVED, /* col 1 + row 4 */ +}; + +/* Description of in-progress IO operation, used for operations +* that trigger response from device */ +struct picolcd_pending { +struct hid_report *out_report; +struct hid_report *in_report; +int raw_size; +u8 raw_data[64 ]; +}; + +/* Per device data structure */ +struct picolcd_data { +struct hid_device *hdev; +#ifdef CONFIG_DEBUG_FS +int addr_sz; +#endif +u8 version[2 ]; +/* input stuff */ +u8 pressed_keys[2 ]; +struct input_dev *input_keys; +struct input_dev *input_cir; +int keycode[PICOLCD_KEYS ]; + +/* Housekeeping stuff */ +spinlock_t lock; +struct picolcd_pending *pending; +struct completion ready; +int status; +#define PICOLCD_BUSY 1 +#define PICOLCD_FAILED 4 +#define PICOLCD_BOOTLOADER 8 +}; + + +/* Find a given report */ +#define picolcd_in_report (id, dev) picolcd_report(id, dev, HID_INPUT_REPORT) +#define picolcd_out_report (id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT) + +static struct hid_report *picolcd_report (int id,struct hid_device *hdev,int dir) +{ +struct list_head *feature_report_list = &hdev->report_enum[dir].report_list; +struct hid_report *report =NULL ; + +list_for_each_entry (report, feature_report_list, list) { +if (report->id = id) +return report; + } +dev_warn (&hdev->dev,"No report with id 0x%x found\n" , id); +return NULL ; +} + +#ifdef CONFIG_DEBUG_FS +static void picolcd_debug_out_report (struct picolcd_data *data, +struct hid_device *hdev,struct hid_report *report); +#define usbhid_submit_report (a, b, c) \ + picolcd_debug_out_report(hid_get_drvdata(a), a, b); \ + usbhid_submit_report(a, b, c) +#endif + +/* Submit a report and wait for a reply from device - if device fades away +* or does not respond in time, return NULL */ +static struct picolcd_pending *picolcd_send_and_wait (struct hid_device *hdev, +int report_id,const u8 *raw_data,int size) +{ +struct picolcd_data *data =hid_get_drvdata (hdev); +struct picolcd_pending *work; +struct hid_report *report =picolcd_out_report (report_id, hdev); +unsigned long flags; +int status, i, j, k; + +if (!report) +return NULL ; + work =kzalloc (sizeof (*work),GFP_KERNEL ); +if (!work) +return NULL ; + + work->out_report = report; + work->in_report =NULL ; + work->raw_size =0 ; + +retry: +/* try to get lock and enqueue our job */ +spin_lock_irqsave (&data->lock, flags); + status = data->status;
drivers/hid/hid-picolcd.c line 191
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+if (data->pending || (status &PICOLCD_FAILED )) { +/* some job already pending, +* wait for it to complete and try again */ +spin_unlock_irqrestore (&data->lock, flags); +if (status &PICOLCD_FAILED ) { +kfree (work); +return NULL ; + } +wait_for_completion_interruptible_timeout (&data->ready,HZ *2 ); + goto retry;
Umm, can we do this with a mutex? Like you take a mutex and don't release till you are done talking to the device. So that other guy will wait on the mutex instead of waking up and rechecking condition.
drivers/hid/hid-picolcd.c line 202
Quoted 11 lines
drivers/hid/hid-picolcd.c new file +11
-0+ } + data->status |=PICOLCD_BUSY ; + data->pending = work; +for (i = k =0 ; i < report->maxfield; i++) +for (j =0 ; j < report->field[i]->report_count; j++) { +hid_set_field (report->field[i], j, k < size ? raw_data[k] :0 ); + k++; + } +usbhid_submit_report (data->hdev, report,USB_DIR_OUT ); +complete_all (&data->ready); +INIT_COMPLETION (data->ready);
Umm, what does this do, exactly?
Quoted 38 lines
drivers/hid/hid-picolcd.c new file +38
-0+spin_unlock_irqrestore (&data->lock, flags); +/* wait for our job to complete */ +wait_for_completion_interruptible_timeout (&data->ready,HZ *2 ); + +spin_lock_irqsave (&data->lock, flags); +if (data->pending = work) { + data->status &= ~PICOLCD_BUSY ; + data->pending =NULL ; +complete_all (&data->ready); +spin_unlock_irqrestore (&data->lock, flags); +return work; + }else { +spin_unlock_irqrestore (&data->lock, flags); +kfree (work); +return NULL ; + } +} + +/* +* input class device +*/ +static int picolcd_raw_keypad (struct hid_device *hdev, +struct hid_report *report,u8 *raw_data,int size) +{ +/* +* Keypad event +* First and second data bytes list currently pressed keys, +* 0x00 means no key and at most 2 keys may be pressed at same time +*/ +struct picolcd_data *data =hid_get_drvdata (hdev); +int i, j; + +/* determine newly pressed keys */ +for (i =0 ; i < size; i++) { +int key_code; +if (raw_data[i] =0 ) +continue ; +for (j =0 ; j <sizeof (data->pressed_keys); j++)
drivers/hid/hid-picolcd.c line 250
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+if (data->pressed_keys[j] = raw_data[i]) + goto key_already_down; +for (j =0 ; j <sizeof (data->pressed_keys); j++) +if (data->pressed_keys[j] =0 ) { + data->pressed_keys[j] = raw_data[i]; +break ; + } +input_event (data->input_keys,EV_MSC ,MSC_SCAN , raw_data[i]); +if (input_get_keycode (data->input_keys, raw_data[i], &key_code)) + key_code =KEY_UNKNOWN ;
Just get keycode directly from the driver's table, no need to jump through hoops here,
Quoted 79 lines
drivers/hid/hid-picolcd.c new file +79
-0+if (key_code !=KEY_UNKNOWN ) { +dbg_hid (PICOLCD_NAME " got key press for %u:%d" , raw_data[i], key_code); +input_report_key (data->input_keys, key_code,1 ); + } +input_sync (data->input_keys); +key_already_down: +continue ; + } + +/* determine newly released keys */ +for (j =0 ; j <sizeof (data->pressed_keys); j++) { +int key_code; +if (data->pressed_keys[j] =0 ) +continue ; +for (i =0 ; i < size; i++) +if (data->pressed_keys[j] = raw_data[i]) + goto key_still_down; +input_event (data->input_keys,EV_MSC ,MSC_SCAN , data->pressed_keys[j]); +if (input_get_keycode (data->input_keys, data->pressed_keys[j], &key_code)) + key_code =KEY_UNKNOWN ; +if (key_code !=KEY_UNKNOWN ) { +dbg_hid (PICOLCD_NAME " got key release for %u:%d" , data->pressed_keys[j], key_code); +input_report_key (data->input_keys, key_code,0 ); + } +input_sync (data->input_keys); + data->pressed_keys[j] =0 ; +key_still_down: +continue ; + } +return 1 ; +} + +static int picolcd_raw_cir (struct hid_device *hdev, +struct hid_report *report,u8 *raw_data,int size) +{ +/* Need understanding of CIR data format to implement ... */ +return 1 ; +} + + + +/* +* Reset our device and wait for answer to VERSION request +*/ +static int picolcd_reset (struct hid_device *hdev) +{ +struct picolcd_data *data =hid_get_drvdata (hdev); +struct hid_report *report =picolcd_out_report (REPORT_RESET , hdev); +struct picolcd_pending *verinfo; +unsigned long flags; + +if (!data || !report || report->maxfield !=1 ) +return -ENODEV ; + +spin_lock_irqsave (&data->lock, flags); +complete_all (&data->ready); +INIT_COMPLETION (data->ready); +if (hdev->product =USB_DEVICE_ID_PICOLCD_BOOTLOADER ) + data->status |=PICOLCD_BOOTLOADER ; + +/* perform the reset */ +hid_set_field (report->field[0 ],0 ,1 ); +usbhid_submit_report (hdev, report,USB_DIR_OUT ); +spin_unlock_irqrestore (&data->lock, flags); + + verinfo =picolcd_send_and_wait (hdev,REPORT_VERSION ,NULL ,0 ); +if (verinfo && verinfo->raw_size =2 ) { +if (data->status &PICOLCD_BOOTLOADER ) { +dev_info (&hdev->dev,"PicoLCD reset successful, bootloader version %d.%d\n" , + verinfo->raw_data[0 ], verinfo->raw_data[1 ]); + data->version[0 ] = verinfo->raw_data[0 ]; + data->version[1 ] = verinfo->raw_data[1 ]; + }else { +dev_info (&hdev->dev,"PicoLCD reset successful, firmware version %d.%d\n" , + verinfo->raw_data[1 ], verinfo->raw_data[0 ]); + data->version[0 ] = verinfo->raw_data[1 ]; + data->version[1 ] = verinfo->raw_data[0 ]; + } +kfree (verinfo);
drivers/hid/hid-picolcd.c line 339
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+ verinfo =NULL ; + }else if (verinfo) { +dev_err (&hdev->dev,"confused, got unexpected version response from PicoLCD after reset\n" ); +kfree (verinfo); + verinfo =NULL ; + }else { +dev_err (&hdev->dev,"no version response from PicoLCD after reset" ); +return -EBUSY ; + } +
I am pretty sure it could be written clearer instead of checking for verinfo several times...
if (!verinfo) {
dev_err(..);
return -EBUSY;
}
if (verinfo->raw_size = 2) {
...
} else {
dev_err(...)
}
kfree(verinfo);Quoted 695 lines
drivers/hid/hid-picolcd.c new file +695
-0+return 0 ; +} + +/* +* The "operation_mode" sysfs attribute +*/ +static ssize_t picolcd_operation_mode_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct picolcd_data *data =dev_get_drvdata (dev); + +if (data->status &PICOLCD_BOOTLOADER ) +return snprintf (buf,PAGE_SIZE ,"<bootloader> lcd\n" ); +else +return snprintf (buf,PAGE_SIZE ,"bootloader <lcd>\n" ); +} + +static ssize_t picolcd_operation_mode_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) +{ +struct picolcd_data *data =dev_get_drvdata (dev); +struct hid_report *report =NULL ; +size_t cnt = count; +int timeout =5000 ; +unsigned u; +unsigned long flags; + +if (cnt >=3 &&strncmp ("lcd" , buf,3 ) =0 ) { +if (data->status &PICOLCD_BOOTLOADER ) + report =picolcd_out_report (REPORT_EXIT_FLASHER , data->hdev); + buf +=3 ; + cnt -=3 ; + }else if (cnt >=10 &&strncmp ("bootloader" , buf,10 ) =0 ) { +if (!(data->status &PICOLCD_BOOTLOADER )) + report =picolcd_out_report (REPORT_EXIT_KEYBOARD , data->hdev); + buf +=10 ; + cnt -=10 ; + } +if (!report) +return -EINVAL ; + +while (cnt >0 && (*buf =' ' || *buf ='\t' )) { + buf++; + cnt--; + } +while (cnt >0 && (buf[cnt-1 ] ='\n' || buf[cnt-1 ] ='\r' )) + cnt--; +if (cnt >0 ) { +if (sscanf (buf,"%u" , &u) !=1 ) +return -EINVAL ; +if (u >30000 ) +return -EINVAL ; +else + timeout = u; + } + +spin_lock_irqsave (&data->lock, flags); +hid_set_field (report->field[0 ],0 , timeout &0xff ); +hid_set_field (report->field[0 ],1 , (timeout >>8 ) &0xff ); +usbhid_submit_report (data->hdev, report,USB_DIR_OUT ); +spin_unlock_irqrestore (&data->lock, flags); +return count; +} + +static DEVICE_ATTR(operation_mode, 0644, picolcd_operation_mode_show, + picolcd_operation_mode_store); + + +#ifdef CONFIG_DEBUG_FS +/* +* Helper code for HID report level dumping/debugging +*/ +static const char *error_codes[] = { +"success" ,"parameter missing" ,"data_missing" ,"block readonly" ,"block not erasable" , +"block too big" ,"section overflow" ,"invalid command length" ,"invalid data length" , +}; + +static void dump_buff_as_hex (char *dst,size_t dst_sz,const u8 *data, +const size_t data_len) +{ +int i, j; +for (i = j =0 ; i < data_len && j +3 < dst_sz; i++) { + dst[j++] = hex_asc[(data[i] >>4 ) &0x0f ]; + dst[j++] = hex_asc[data[i] &0x0f ]; + dst[j++] =' ' ; + } +if (j < dst_sz) { + dst[j--] ='\0' ; + dst[j] ='\n' ; + }else + dst[j] ='\0' ; +} + +static void picolcd_debug_out_report (struct picolcd_data *data, +struct hid_device *hdev,struct hid_report *report) +{ +u8 raw_data[70 ]; +int raw_size = (report->size >>3 ) +1 ; +char *buff; +#define BUFF_SZ 256 + +/* Avoid unnecessary overhead if debugfs is disabled */ +if (!hdev->debug_events) +return ; + + buff =kmalloc (BUFF_SZ ,GFP_ATOMIC ); +if (!buff) +return ; + +snprintf (buff,BUFF_SZ ,"\nout report %d (size %d) = " , + report->id, raw_size); +hid_debug_event (hdev, buff); +if (raw_size +5 >sizeof (raw_data)) { +hid_debug_event (hdev," TOO BIG\n" ); +return ; + }else { + raw_data[0 ] = report->id; +hid_output_report (report, raw_data); +dump_buff_as_hex (buff,BUFF_SZ , raw_data, raw_size); +hid_debug_event (hdev, buff); + } + +switch (report->id) { +case REPORT_LED_STATE : +/* 1 data byte with GPO state */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_LED_STATE" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tGPO state: 0x%02x\n" , raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_BRIGHTNESS : +/* 1 data byte with brightness */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_BRIGHTNESS" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tBrightness: 0x%02x\n" , raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_CONTRAST : +/* 1 data byte with contrast */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_CONTRAST" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tContrast: 0x%02x\n" , raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_RESET : +/* 2 data bytes with reset duration in ms */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_RESET" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tDuration: 0x%02x%02x (%dms)\n" , + raw_data[2 ], raw_data[1 ], raw_data[2 ] <<8 | raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_LCD_CMD : +/* 63 data bytes with LCD commands */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_LCD_CMD" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +/* TODO: format decoding */ +break ; +case REPORT_LCD_DATA : +/* 63 data bytes with LCD data */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_LCD_CMD" , report->id, raw_size-1 ); +/* TODO: format decoding */ +hid_debug_event (hdev, buff); +break ; +case REPORT_LCD_CMD_DATA : +/* 63 data bytes with LCD commands and data */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_LCD_CMD" , report->id, raw_size-1 ); +/* TODO: format decoding */ +hid_debug_event (hdev, buff); +break ; +case REPORT_EE_READ : +/* 3 data bytes with read area description */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_EE_READ" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x\n" , raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[3 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_EE_WRITE : +/* 3+1..20 data bytes with write area description */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_EE_WRITE" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x\n" , raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[3 ]); +hid_debug_event (hdev, buff); +if (raw_data[3 ] =0 ) { +snprintf (buff,BUFF_SZ ,"\tNo data\n" ); + }else if (raw_data[3 ] +4 <= raw_size) { +snprintf (buff,BUFF_SZ ,"\tData: " ); +hid_debug_event (hdev, buff); +dump_buff_as_hex (buff,BUFF_SZ , raw_data+4 , raw_data[3 ]); + }else { +snprintf (buff,BUFF_SZ ,"\tData overflowed\n" ); + } +hid_debug_event (hdev, buff); +break ; +case REPORT_ERASE_MEMORY : +case REPORT_BL_ERASE_MEMORY : +/* 3 data bytes with pointer inside erase block */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_ERASE_MEMORY" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +switch (data->addr_sz) { +case 2 : +snprintf (buff,BUFF_SZ ,"\tAddress inside 64 byte block: 0x%02x%02x\n" , + raw_data[2 ], raw_data[1 ]); +break ; +case 3 : +snprintf (buff,BUFF_SZ ,"\tAddress inside 64 byte block: 0x%02x%02x%02x\n" , + raw_data[3 ], raw_data[2 ], raw_data[1 ]); +break ; +default : +snprintf (buff,BUFF_SZ ,"\tNot supported\n" ); + } +hid_debug_event (hdev, buff); +break ; +case REPORT_READ_MEMORY : +case REPORT_BL_READ_MEMORY : +/* 4 data bytes with read area description */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_READ_MEMORY" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +switch (data->addr_sz) { +case 2 : +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x\n" , + raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[3 ]); +break ; +case 3 : +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x%02x\n" , + raw_data[3 ], raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[4 ]); +break ; +default : +snprintf (buff,BUFF_SZ ,"\tNot supported\n" ); + } +hid_debug_event (hdev, buff); +break ; +case REPORT_WRITE_MEMORY : +case REPORT_BL_WRITE_MEMORY : +/* 4+1..32 data bytes with write adrea description */ +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_WRITE_MEMORY" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +switch (data->addr_sz) { +case 2 : +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x\n" , + raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[3 ]); +hid_debug_event (hdev, buff); +if (raw_data[3 ] =0 ) { +snprintf (buff,BUFF_SZ ,"\tNo data\n" ); + }else if (raw_data[3 ] +4 <= raw_size) { +snprintf (buff,BUFF_SZ ,"\tData: " ); +hid_debug_event (hdev, buff); +dump_buff_as_hex (buff,BUFF_SZ , raw_data+4 , raw_data[3 ]); + }else { +snprintf (buff,BUFF_SZ ,"\tData overflowed\n" ); + } +break ; +case 3 : +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x%02x\n" , + raw_data[3 ], raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[4 ]); +hid_debug_event (hdev, buff); +if (raw_data[4 ] =0 ) { +snprintf (buff,BUFF_SZ ,"\tNo data\n" ); + }else if (raw_data[4 ] +5 <= raw_size) { +snprintf (buff,BUFF_SZ ,"\tData: " ); +hid_debug_event (hdev, buff); +dump_buff_as_hex (buff,BUFF_SZ , raw_data+5 , raw_data[4 ]); + }else { +snprintf (buff,BUFF_SZ ,"\tData overflowed\n" ); + } +break ; +default : +snprintf (buff,BUFF_SZ ,"\tNot supported\n" ); + } +hid_debug_event (hdev, buff); +break ; +case REPORT_SPLASH_RESTART : +/* TODO */ +break ; +case REPORT_EXIT_KEYBOARD : +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_EXIT_KEYBOARD" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tRestart delay: %dms (0x%02x%02x)\n" , + raw_data[1 ] | (raw_data[2 ] <<8 ), + raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_VERSION : +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_VERSION" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +break ; +case REPORT_DEVID : +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_DEVID" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +break ; +case REPORT_SPLASH_SIZE : +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_SPLASH_SIZE" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +break ; +case REPORT_HOOK_VERSION : +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_HOOK_VERSION" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +break ; +case REPORT_EXIT_FLASHER : +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"REPORT_VERSION" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tRestart delay: %dms (0x%02x%02x)\n" , + raw_data[1 ] | (raw_data[2 ] <<8 ), + raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +default : +snprintf (buff,BUFF_SZ ,"out report %s (%d, size=%d)\n" , +"<unknown>" , report->id, raw_size-1 ); +hid_debug_event (hdev, buff); +break ; + } +wake_up_interruptible (&hdev->debug_wait); +kfree (buff); +} + +static inline void picolcd_debug_raw_event (struct picolcd_data *data, +struct hid_device *hdev,struct hid_report *report, +u8 *raw_data,int size) +{ +char *buff; + +#define BUFF_SZ 256 +/* Avoid unnecessary overhead if debugfs is disabled */ +if (!hdev->debug_events) +return ; + + buff =kmalloc (BUFF_SZ ,GFP_ATOMIC ); +if (!buff) +return ; + +switch (report->id) { +case REPORT_ERROR_CODE : +/* 2 data bytes with affected report and error code */ +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_ERROR_CODE" , report->id, size-1 ); +hid_debug_event (hdev, buff); +if (raw_data[2 ] <ARRAY_SIZE (error_codes)) +snprintf (buff,BUFF_SZ ,"\tError code 0x%02x (%s) in reply to report 0x%02x\n" , + raw_data[2 ], error_codes[raw_data[2 ]], raw_data[1 ]); +else +snprintf (buff,BUFF_SZ ,"\tError code 0x%02x in reply to report 0x%02x\n" , + raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_KEY_STATE : +/* 2 data bytes with key state */ +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_KEY_STATE" , report->id, size-1 ); +hid_debug_event (hdev, buff); +if (raw_data[1 ] =0 ) +snprintf (buff,BUFF_SZ ,"\tNo key pressed\n" ); +else if (raw_data[2 ] =0 ) +snprintf (buff,BUFF_SZ ,"\tOne key pressed: 0x%02x (%d)\n" , + raw_data[1 ], raw_data[1 ]); +else +snprintf (buff,BUFF_SZ ,"\tTwo keys pressed: 0x%02x (%d), 0x%02x (%d)\n" , + raw_data[1 ], raw_data[1 ], raw_data[2 ], raw_data[2 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_IR_DATA : +/* Up to 20 byes of IR scancode data */ +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_IR_DATA" , report->id, size-1 ); +hid_debug_event (hdev, buff); +if (raw_data[1 ] =0 ) { +snprintf (buff,BUFF_SZ ,"\tUnexpectedly 0 data length\n" ); +hid_debug_event (hdev, buff); + }else if (raw_data[1 ] +1 <= size) { +snprintf (buff,BUFF_SZ ,"\tData length: %d\n\tIR Data: " , + raw_data[1 ]-1 ); +hid_debug_event (hdev, buff); +dump_buff_as_hex (buff,BUFF_SZ , raw_data+2 , raw_data[1 ]-1 ); +hid_debug_event (hdev, buff); + }else { +snprintf (buff,BUFF_SZ ,"\tOverflowing data length: %d\n" , + raw_data[1 ]-1 ); +hid_debug_event (hdev, buff); + } +break ; +case REPORT_EE_DATA : +/* Data buffer in response to REPORT_EE_READ or REPORT_EE_WRITE */ +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_EE_DATA" , report->id, size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x\n" , raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[3 ]); +hid_debug_event (hdev, buff); +if (raw_data[3 ] =0 ) { +snprintf (buff,BUFF_SZ ,"\tNo data\n" ); +hid_debug_event (hdev, buff); + }else if (raw_data[3 ] +4 <= size) { +snprintf (buff,BUFF_SZ ,"\tData: " ); +hid_debug_event (hdev, buff); +dump_buff_as_hex (buff,BUFF_SZ , raw_data+4 , raw_data[3 ]); +hid_debug_event (hdev, buff); + }else { +snprintf (buff,BUFF_SZ ,"\tData overflowed\n" ); +hid_debug_event (hdev, buff); + } +break ; +case REPORT_MEMORY : +/* Data buffer in response to REPORT_READ_MEMORY or REPORT_WRTIE_MEMORY */ +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_MEMORY" , report->id, size-1 ); +hid_debug_event (hdev, buff); +switch (data->addr_sz) { +case 2 : +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x\n" , + raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[3 ]); +hid_debug_event (hdev, buff); +if (raw_data[3 ] =0 ) { +snprintf (buff,BUFF_SZ ,"\tNo data\n" ); + }else if (raw_data[3 ] +4 <= size) { +snprintf (buff,BUFF_SZ ,"\tData: " ); +hid_debug_event (hdev, buff); +dump_buff_as_hex (buff,BUFF_SZ , raw_data+4 , raw_data[3 ]); + }else { +snprintf (buff,BUFF_SZ ,"\tData overflowed\n" ); + } +break ; +case 3 : +snprintf (buff,BUFF_SZ ,"\tData address: 0x%02x%02x%02x\n" , + raw_data[3 ], raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tData length: %d\n" , raw_data[4 ]); +hid_debug_event (hdev, buff); +if (raw_data[4 ] =0 ) { +snprintf (buff,BUFF_SZ ,"\tNo data\n" ); + }else if (raw_data[4 ] +5 <= size) { +snprintf (buff,BUFF_SZ ,"\tData: " ); +hid_debug_event (hdev, buff); +dump_buff_as_hex (buff,BUFF_SZ , raw_data+5 , raw_data[4 ]); + }else { +snprintf (buff,BUFF_SZ ,"\tData overflowed\n" ); + } +break ; +default : +snprintf (buff,BUFF_SZ ,"\tNot supported\n" ); + } +hid_debug_event (hdev, buff); +break ; +case REPORT_VERSION : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_VERSION" , report->id, size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tFirmware version: %d.%d\n" , + raw_data[2 ], raw_data[1 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_BL_ERASE_MEMORY : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_BL_ERASE_MEMORY" , report->id, size-1 ); +hid_debug_event (hdev, buff); +/* TODO */ +break ; +case REPORT_BL_READ_MEMORY : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_BL_READ_MEMORY" , report->id, size-1 ); +hid_debug_event (hdev, buff); +/* TODO */ +break ; +case REPORT_BL_WRITE_MEMORY : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_BL_WRITE_MEMORY" , report->id, size-1 ); +hid_debug_event (hdev, buff); +/* TODO */ +break ; +case REPORT_DEVID : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_DEVID" , report->id, size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tSerial: 0x%02x%02x%02x%02x\n" , + raw_data[1 ], raw_data[2 ], raw_data[3 ], raw_data[4 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tType: 0x%02x\n" , + raw_data[5 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_SPLASH_SIZE : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_SPLASH_SIZE" , report->id, size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tTotal splash space: %d\n" , + (raw_data[2 ] <<8 ) | raw_data[1 ]); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tUsed splash space: %d\n" , + (raw_data[4 ] <<8 ) | raw_data[3 ]); +hid_debug_event (hdev, buff); +break ; +case REPORT_HOOK_VERSION : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"REPORT_HOOK_VERSION" , report->id, size-1 ); +hid_debug_event (hdev, buff); +snprintf (buff,BUFF_SZ ,"\tFirmware version: %d.%d\n" , + raw_data[1 ], raw_data[2 ]); +hid_debug_event (hdev, buff); +break ; +default : +snprintf (buff,BUFF_SZ ,"report %s (%d, size=%d)\n" , +"<unknown>" , report->id, size-1 ); +hid_debug_event (hdev, buff); +break ; + } +wake_up_interruptible (&hdev->debug_wait); +kfree (buff); +} +#else +#define picolcd_debug_raw_event (data, hdev, report, raw_data, size) +#endif + +/* +* Handle raw report as sent by device +*/ +static int picolcd_raw_event (struct hid_device *hdev, +struct hid_report *report,u8 *raw_data,int size) +{ +struct picolcd_data *data =hid_get_drvdata (hdev); +unsigned long flags; +int ret =0 ; + +if (data =NULL ) +return 1 ; + +if (report->id =REPORT_KEY_STATE ) { +if (data->input_keys) + ret =picolcd_raw_keypad (hdev, report, raw_data+1 , size-1 ); + }else if (report->id =REPORT_IR_DATA ) { +if (data->input_cir) + ret =picolcd_raw_cir (hdev, report, raw_data+1 , size-1 ); + }else { +spin_lock_irqsave (&data->lock, flags); +/* +* We let the caller of picolcd_send_and_wait() check if the report +* we got is one of the expected ones or not. +*/ +if (data->pending) { +memcpy (data->pending->raw_data, raw_data+1 , size-1 ); + data->pending->raw_size = size-1 ; + data->pending->in_report = report; +complete_all (&data->ready); + } +spin_unlock_irqrestore (&data->lock, flags); + } + +picolcd_debug_raw_event (data, hdev, report, raw_data, size); +return 1 ; +} + +#ifdef CONFIG_PM +static int picolcd_suspend (struct hid_device *hdev) +{ +dbg_hid (PICOLCD_NAME " device ready for suspend\n" ); +return 0 ; +} + +static int picolcd_resume (struct hid_device *hdev) +{ +return 0 ; +} + +static int picolcd_reset_resume (struct hid_device *hdev) +{ +int ret; + ret =picolcd_reset (hdev); +if (ret) +dbg_hid (PICOLCD_NAME " resetting our device failed: %d\n" , ret); +return 0 ; +} +#endif + +/* initialize keypad input device */ +static inline int picolcd_init_keys (struct picolcd_data *data, +struct hid_report *report) +{ +struct hid_device *hdev = data->hdev; +struct input_dev *idev; +int error, i; + +if (!report) +return -ENODEV ; +if (report->maxfield !=1 || report->field[0 ]->report_count !=2 || + report->field[0 ]->report_size !=8 ) { +dev_err (&hdev->dev,"unsupported KEY_STATE report" ); +return -EINVAL ; + } + + idev =input_allocate_device (); +if (idev =NULL ) { +dev_err (&hdev->dev,"failed to allocate input device" ); +return -ENOMEM ; + } +input_set_drvdata (idev, hdev); +memcpy (data->keycode, def_keymap,sizeof (def_keymap)); + idev->name = hdev->name; + idev->phys = hdev->phys; + idev->uniq = hdev->uniq; + idev->id.bustype = hdev->bus; + idev->id.vendor = hdev->vendor; + idev->id.product = hdev->product; + idev->id.version = hdev->version; + idev->dev.parent = hdev->dev.parent; + idev->keycode = &data->keycode; + idev->keycodemax =PICOLCD_KEYS ; + idev->keycodesize =sizeof (int ); +input_set_capability (idev,EV_MSC ,MSC_SCAN ); +set_bit (EV_REP , idev->evbit); +for (i =0 ; i <PICOLCD_KEYS ; i++) { +int key = ((int *)idev->keycode)[i]; +if (key <KEY_MAX && key >=0 ) +input_set_capability (idev,EV_KEY , key); + } + error =input_register_device (idev); +if (error) { +dev_err (&hdev->dev,"error registering the input device" ); +input_free_device (idev); +return error; + } + data->input_keys = idev; +return 0 ; +} + +static void picolcd_exit_keys (struct picolcd_data *data) +{ +struct input_dev *idev = data->input_keys; + + data->input_keys =NULL ; +if (idev) +input_unregister_device (idev); +} + +/* initialize CIR input device */ +static inline int picolcd_init_cir (struct picolcd_data *data,struct hid_report *report) +{ +/* support not implemented yet */ +return 0 ; +} + +static void picolcd_exit_cir (struct picolcd_data *data) +{ +} + +static inline int picolcd_probe_lcd (struct hid_device *hdev,struct picolcd_data *data) +{ +struct picolcd_pending *verinfo; +struct hid_report *report; +int error; + + verinfo =picolcd_send_and_wait (hdev,REPORT_VERSION ,NULL ,0 ); +if (!verinfo || !verinfo->in_report) { +kfree (verinfo); +dev_err (&hdev->dev,"failed to query FW version of device\n" ); +return -ENODEV ; + }else if (verinfo->in_report->id =REPORT_VERSION && verinfo->raw_size =2 ) { +dev_info (&hdev->dev,"detected PicoLCD with firmware version %d.%d\n" , + verinfo->raw_data[0 ], verinfo->raw_data[1 ]); + data->version[0 ] = verinfo->raw_data[1 ]; + data->version[1 ] = verinfo->raw_data[0 ]; +if (data->version[0 ] !=0 && data->version[1 ] !=3 ) +dev_info (&hdev->dev,"Device with untested firmware revision, " +"please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n" , +dev_name (&hdev->dev));
drivers/hid/hid-picolcd.c line 1044
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+kfree (verinfo); + verinfo =NULL ; + }else { +dev_err (&hdev->dev,"unexpected version response from PicoLCD" +" (report=0x%02x, size=%d)\n" , + verinfo->in_report->id, verinfo->raw_size); +kfree (verinfo); + verinfo =NULL ; +return -ENODEV ; + }
Please consolidate freeing of acquired resources.
Quoted 45 lines
drivers/hid/hid-picolcd.c new file +44
-0+ +/* Setup keypad input device */ + error =picolcd_init_keys (data,picolcd_in_report (REPORT_KEY_STATE , hdev)); +if (error) + goto err; + +/* Setup CIR input device */ + error =picolcd_init_cir (data,picolcd_in_report (REPORT_IR_DATA , hdev)); +if (error) + goto err; + +#ifdef CONFIG_DEBUG_FS + report =picolcd_out_report (REPORT_READ_MEMORY , hdev); +if (report && report->maxfield =1 && report->field[0 ]->report_size =8 ) + data->addr_sz = report->field[0 ]->report_count -1 ; +else + data->addr_sz =-1 ; +#endif +return 0 ; +err: +picolcd_exit_cir (data); +picolcd_exit_keys (data); +return error; +} + +static inline int picolcd_probe_bootloader (struct hid_device *hdev,struct picolcd_data *data) +{ +struct picolcd_pending *verinfo; +struct hid_report *report; + + verinfo =picolcd_send_and_wait (hdev,REPORT_VERSION ,NULL ,0 ); +if (!verinfo || !verinfo->in_report) { +kfree (verinfo); +dev_err (&hdev->dev,"failed to query FW version of device\n" ); +return -ENODEV ; + }else if (verinfo->in_report->id =REPORT_VERSION && verinfo->raw_size =2 ) { +dev_info (&hdev->dev,"detected PicoLCD with bootloader version %d.%d\n" , + verinfo->raw_data[1 ], verinfo->raw_data[0 ]); + data->version[0 ] = verinfo->raw_data[1 ]; + data->version[1 ] = verinfo->raw_data[0 ]; +if (data->version[0 ] !=1 && data->version[1 ] !=0 ) +dev_info (&hdev->dev,"Device with untested bootloader revision, " +"please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n" , +dev_name (&hdev->dev));
drivers/hid/hid-picolcd.c line 1098
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+kfree (verinfo); + verinfo =NULL ; + }else { +dev_err (&hdev->dev,"unexpected version response from PicoLCD" +" (report=0x%02x, size=%d)\n" , + verinfo->in_report->id, verinfo->raw_size); +kfree (verinfo); + verinfo =NULL ; +return -ENODEV ; + }
Please consolidate freeing of acquired resources. Wait, I just saw afucntion like that... can we combine them somehow?
+
Quoted 50 lines
drivers/hid/hid-picolcd.c new file +50
-0+#ifdef CONFIG_DEBUG_FS + report =picolcd_out_report (REPORT_BL_READ_MEMORY , hdev); +if (report && report->maxfield =1 && report->field[0 ]->report_size =8 ) + data->addr_sz = report->field[0 ]->report_count -1 ; +else + data->addr_sz =-1 ; +#endif +return 0 ; +} + +static int picolcd_probe (struct hid_device *hdev, +const struct hid_device_id *id) +{ +struct picolcd_data *data; +int error = -ENOMEM ; + +dbg_hid (PICOLCD_NAME " hardware probe...\n" ); + +/* +* Let's allocate the picolcd data structure, set some reasonable +* defaults, and associate it with the device +*/ + data =kzalloc (sizeof (struct picolcd_data ),GFP_KERNEL ); +if (data =NULL ) { +dev_err (&hdev->dev,"can't allocate space for Minibox PicoLCD device data\n" ); + error = -ENOMEM ; + goto err_no_cleanup; + } + +spin_lock_init (&data->lock); +init_completion (&data->ready); + data->hdev = hdev; +if (hdev->product =USB_DEVICE_ID_PICOLCD_BOOTLOADER ) + data->status |=PICOLCD_BOOTLOADER ; +hid_set_drvdata (hdev, data); + +/* Parse the device reports and start it up */ + error =hid_parse (hdev); +if (error) { +dev_err (&hdev->dev,"device report parse failed\n" ); + goto err_cleanup_data; + } + +/* We don't use hidinput but hid_hw_start() fails if nothing is +* claimed. So spoof claimed input. */ + hdev->claimed =HID_CLAIMED_INPUT ; + error =hid_hw_start (hdev,0 ); + hdev->claimed =0 ; +if (error) { +dev_err (&hdev->dev,"hardware start failed\n" );
drivers/hid/hid-picolcd.c line 1159
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+ goto err_cleanup_data; + } + + error = hdev->ll_driver->open (hdev); +if (error) { +dev_err (&hdev->dev,"failed to open input interrupt pipe for key and IR events\n" ); + goto err_cleanup_hid_hw; + } + + error =sysfs_create_file (&(hdev->dev.kobj), &dev_attr_operation_mode.attr);
device_create_file?
Quoted 92 lines
drivers/hid/hid-picolcd.c new file +85
-0+if (error) { +dev_err (&hdev->dev,"failed to create sysfs attributes\n" ); + goto err_cleanup_hid_ll; + } + +if (data->status &PICOLCD_BOOTLOADER ) + error =picolcd_probe_bootloader (hdev, data); +else + error =picolcd_probe_lcd (hdev, data); +if (error) + goto err_cleanup_sysfs; + +dbg_hid (PICOLCD_NAME " activated and initialized\n" ); +return 0 ; + +err_cleanup_sysfs: +sysfs_remove_file (&(hdev->dev.kobj), &dev_attr_operation_mode.attr); +err_cleanup_hid_ll: + hdev->ll_driver->close (hdev); +err_cleanup_hid_hw: +hid_hw_stop (hdev); +err_cleanup_data: +kfree (data); +err_no_cleanup: +hid_set_drvdata (hdev,NULL ); + +return error; +} + +static void picolcd_remove (struct hid_device *hdev) +{ +struct picolcd_data *data =hid_get_drvdata (hdev); +unsigned long flags; + +dbg_hid (PICOLCD_NAME " hardware remove...\n" ); +spin_lock_irqsave (&data->lock, flags); + data->status |=PICOLCD_FAILED ; +spin_unlock_irqrestore (&data->lock, flags); + +sysfs_remove_file (&(hdev->dev.kobj), &dev_attr_operation_mode.attr); + hdev->ll_driver->close (hdev); +hid_hw_stop (hdev); + +/* Cleanup input */ +picolcd_exit_cir (data); +picolcd_exit_keys (data); + +/* Finally, clean up the picolcd data itself */ +kfree (data); +} + +static const struct hid_device_id picolcd_devices[] = { + {HID_USB_DEVICE (USB_VENDOR_ID_MICROCHIP ,USB_DEVICE_ID_PICOLCD ) }, + {HID_USB_DEVICE (USB_VENDOR_ID_MICROCHIP ,USB_DEVICE_ID_PICOLCD_BOOTLOADER ) }, + { } +}; +MODULE_DEVICE_TABLE (hid, picolcd_devices); + +static struct hid_driver picolcd_driver = { + .name ="hid-picolcd" , + .id_table = picolcd_devices, + .probe = picolcd_probe, + .remove = picolcd_remove, + .raw_event = picolcd_raw_event, +#ifdef CONFIG_PM + .suspend = picolcd_suspend, + .resume = picolcd_resume, + .reset_resume = picolcd_reset_resume, +#endif +}; + +static int __init picolcd_init (void ) +{ +return hid_register_driver (&picolcd_driver); +} + +static void __exit picolcd_exit(void) +{ +hid_unregister_driver (&picolcd_driver); +} + +module_init (picolcd_init); +module_exit (picolcd_exit); +MODULE_DESCRIPTION ("Minibox graphics PicoLCD Driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 6 lines
1.6.4.4 -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Dmitry
Bruno Prémont
maintainerQuoted 15 lines · On Sat, 20 March 2010 Dmitry Torokhov <[email protected]> wrote:
drivers/hid/hid-picolcd.c line 79
Quoted 8 lines · Bruno Prémont
drivers/hid/hid-picolcd.c new file +8
-0+/* Input device +* +* The PicoLCD has an IR receiver header, a built-in keypad with 5 keys +* and header for 4x4 key matrix. The built-in keys are part of the matrix. +*/ +#define PICOLCD_KEYS 17 + +static const int def_keymap[PICOLCD_KEYS ] = {def_keymap[] = {
...
};
#definePICOLCD_KEYSARRAY_SIZE(def_keymap);
Quoted 1 line
would be safe. Also unsigned short should cover it.
Ok
Quoted 117 lines
Quoted 102 lines
drivers/hid/hid-picolcd.c new file +102
-0+KEY_RESERVED ,/* none */ +KEY_BACK ,/* col 4 + row 1 */ +KEY_HOMEPAGE ,/* col 3 + row 1 */ +KEY_RESERVED ,/* col 2 + row 1 */ +KEY_RESERVED ,/* col 1 + row 1 */ +KEY_SCROLLUP ,/* col 4 + row 2 */ +KEY_OK ,/* col 3 + row 2 */ +KEY_SCROLLDOWN ,/* col 2 + row 2 */ +KEY_RESERVED ,/* col 1 + row 2 */ +KEY_RESERVED ,/* col 4 + row 3 */ +KEY_RESERVED ,/* col 3 + row 3 */ +KEY_RESERVED ,/* col 2 + row 3 */ +KEY_RESERVED ,/* col 1 + row 3 */ +KEY_RESERVED ,/* col 4 + row 4 */ +KEY_RESERVED ,/* col 3 + row 4 */ +KEY_RESERVED ,/* col 2 + row 4 */ + KEY_RESERVED, /* col 1 + row 4 */ +}; + +/* Description of in-progress IO operation, used for operations +* that trigger response from device */ +struct picolcd_pending { +struct hid_report *out_report; +struct hid_report *in_report; +int raw_size; +u8 raw_data[64 ]; +}; + +/* Per device data structure */ +struct picolcd_data { +struct hid_device *hdev; +#ifdef CONFIG_DEBUG_FS +int addr_sz; +#endif +u8 version[2 ]; +/* input stuff */ +u8 pressed_keys[2 ]; +struct input_dev *input_keys; +struct input_dev *input_cir; +int keycode[PICOLCD_KEYS ]; + +/* Housekeeping stuff */ +spinlock_t lock; +struct picolcd_pending *pending; +struct completion ready; +int status; +#define PICOLCD_BUSY 1 +#define PICOLCD_FAILED 4 +#define PICOLCD_BOOTLOADER 8 +}; + + +/* Find a given report */ +#define picolcd_in_report (id, dev) picolcd_report(id, dev, HID_INPUT_REPORT) +#define picolcd_out_report (id, dev) picolcd_report(id, dev, HID_OUTPUT_REPORT) + +static struct hid_report *picolcd_report (int id,struct hid_device *hdev,int dir) +{ +struct list_head *feature_report_list = &hdev->report_enum[dir].report_list; +struct hid_report *report =NULL ; + +list_for_each_entry (report, feature_report_list, list) { +if (report->id = id) +return report; + } +dev_warn (&hdev->dev,"No report with id 0x%x found\n" , id); +return NULL ; +} + +#ifdef CONFIG_DEBUG_FS +static void picolcd_debug_out_report (struct picolcd_data *data, +struct hid_device *hdev,struct hid_report *report); +#define usbhid_submit_report (a, b, c) \ + picolcd_debug_out_report(hid_get_drvdata(a), a, b); \ + usbhid_submit_report(a, b, c) +#endif + +/* Submit a report and wait for a reply from device - if device fades away +* or does not respond in time, return NULL */ +static struct picolcd_pending *picolcd_send_and_wait (struct hid_device *hdev, +int report_id,const u8 *raw_data,int size) +{ +struct picolcd_data *data =hid_get_drvdata (hdev); +struct picolcd_pending *work; +struct hid_report *report =picolcd_out_report (report_id, hdev); +unsigned long flags; +int status, i, j, k; + +if (!report) +return NULL ; + work =kzalloc (sizeof (*work),GFP_KERNEL ); +if (!work) +return NULL ; + + work->out_report = report; + work->in_report =NULL ; + work->raw_size =0 ; + +retry: +/* try to get lock and enqueue our job */ +spin_lock_irqsave (&data->lock, flags); + status = data->status;drivers/hid/hid-picolcd.c line 191
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+if (data->pending || (status &PICOLCD_FAILED )) { +/* some job already pending, +* wait for it to complete and try again */ +spin_unlock_irqrestore (&data->lock, flags); +if (status &PICOLCD_FAILED ) { +kfree (work); +return NULL ; + } +wait_for_completion_interruptible_timeout (&data->ready,HZ *2 ); + goto retry;Umm, can we do this with a mutex? Like you take a mutex and don't release till you are done talking to the device. So that other guy will wait on the mutex instead of waking up and rechecking condition.
Quoted 13 lines
drivers/hid/hid-picolcd.c line 202
Quoted 11 lines
drivers/hid/hid-picolcd.c new file +11
-0+ } + data->status |=PICOLCD_BUSY ; + data->pending = work; +for (i = k =0 ; i < report->maxfield; i++) +for (j =0 ; j < report->field[i]->report_count; j++) { +hid_set_field (report->field[i], j, k < size ? raw_data[k] :0 ); + k++; + } +usbhid_submit_report (data->hdev, report,USB_DIR_OUT ); +complete_all (&data->ready); +INIT_COMPLETION (data->ready);Umm, what does this do, exactly?
It wakes up anyone waiting on the completion and then resets the completion as otherwise any future attempt to wait on it would succeed immediately.
The complete_all() instead of just complete() comes from the reset() function. I can probably reduce it here.
Will check this combined with your mutex suggestion above.
Quoted 43 lines
Quoted 43 lines
drivers/hid/hid-picolcd.c new file +43
-0+spin_unlock_irqrestore (&data->lock, flags); +/* wait for our job to complete */ +wait_for_completion_interruptible_timeout (&data->ready,HZ *2 ); + +spin_lock_irqsave (&data->lock, flags); +if (data->pending = work) { + data->status &= ~PICOLCD_BUSY ; + data->pending =NULL ; +complete_all (&data->ready); +spin_unlock_irqrestore (&data->lock, flags); +return work; + }else { +spin_unlock_irqrestore (&data->lock, flags); +kfree (work); +return NULL ; + } +} + +/* +* input class device +*/ +static int picolcd_raw_keypad (struct hid_device *hdev, +struct hid_report *report,u8 *raw_data,int size) +{ +/* +* Keypad event +* First and second data bytes list currently pressed keys, +* 0x00 means no key and at most 2 keys may be pressed at same time +*/ +struct picolcd_data *data =hid_get_drvdata (hdev); +int i, j; + +/* determine newly pressed keys */ +for (i =0 ; i < size; i++) { +int key_code; +if (raw_data[i] =0 ) +continue ; +for (j =0 ; j <sizeof (data->pressed_keys); j++) +if (data->pressed_keys[j] = raw_data[i]) + goto key_already_down; +for (j =0 ; j <sizeof (data->pressed_keys); j++) +if (data->pressed_keys[j] =0 ) { + data->pressed_keys[j] = raw_data[i];
Quoted 8 lines
drivers/hid/hid-picolcd.c line 250
Quoted 5 lines
drivers/hid/hid-picolcd.c new file +5
-0+break ; + } +input_event (data->input_keys,EV_MSC ,MSC_SCAN , raw_data[i]); +if (input_get_keycode (data->input_keys, raw_data[i], &key_code)) + key_code =KEY_UNKNOWN ;Just get keycode directly from the driver's table, no need to jump through hoops here,
Ok
Quoted 93 lines
Quoted 79 lines
drivers/hid/hid-picolcd.c new file +79
-0+if (key_code !=KEY_UNKNOWN ) { +dbg_hid (PICOLCD_NAME " got key press for %u:%d" , raw_data[i], key_code); +input_report_key (data->input_keys, key_code,1 ); + } +input_sync (data->input_keys); +key_already_down: +continue ; + } + +/* determine newly released keys */ +for (j =0 ; j <sizeof (data->pressed_keys); j++) { +int key_code; +if (data->pressed_keys[j] =0 ) +continue ; +for (i =0 ; i < size; i++) +if (data->pressed_keys[j] = raw_data[i]) + goto key_still_down; +input_event (data->input_keys,EV_MSC ,MSC_SCAN , data->pressed_keys[j]); +if (input_get_keycode (data->input_keys, data->pressed_keys[j], &key_code)) + key_code =KEY_UNKNOWN ; +if (key_code !=KEY_UNKNOWN ) { +dbg_hid (PICOLCD_NAME " got key release for %u:%d" , data->pressed_keys[j], key_code); +input_report_key (data->input_keys, key_code,0 ); + } +input_sync (data->input_keys); + data->pressed_keys[j] =0 ; +key_still_down: +continue ; + } +return 1 ; +} + +static int picolcd_raw_cir (struct hid_device *hdev, +struct hid_report *report,u8 *raw_data,int size) +{ +/* Need understanding of CIR data format to implement ... */ +return 1 ; +} + + + +/* +* Reset our device and wait for answer to VERSION request +*/ +static int picolcd_reset (struct hid_device *hdev) +{ +struct picolcd_data *data =hid_get_drvdata (hdev); +struct hid_report *report =picolcd_out_report (REPORT_RESET , hdev); +struct picolcd_pending *verinfo; +unsigned long flags; + +if (!data || !report || report->maxfield !=1 ) +return -ENODEV ; + +spin_lock_irqsave (&data->lock, flags); +complete_all (&data->ready); +INIT_COMPLETION (data->ready); +if (hdev->product =USB_DEVICE_ID_PICOLCD_BOOTLOADER ) + data->status |=PICOLCD_BOOTLOADER ; + +/* perform the reset */ +hid_set_field (report->field[0 ],0 ,1 ); +usbhid_submit_report (hdev, report,USB_DIR_OUT ); +spin_unlock_irqrestore (&data->lock, flags); + + verinfo =picolcd_send_and_wait (hdev,REPORT_VERSION ,NULL ,0 ); +if (verinfo && verinfo->raw_size =2 ) { +if (data->status &PICOLCD_BOOTLOADER ) { +dev_info (&hdev->dev,"PicoLCD reset successful, bootloader version %d.%d\n" , + verinfo->raw_data[0 ], verinfo->raw_data[1 ]); + data->version[0 ] = verinfo->raw_data[0 ]; + data->version[1 ] = verinfo->raw_data[1 ]; + }else { +dev_info (&hdev->dev,"PicoLCD reset successful, firmware version %d.%d\n" , + verinfo->raw_data[1 ], verinfo->raw_data[0 ]); + data->version[0 ] = verinfo->raw_data[1 ]; + data->version[1 ] = verinfo->raw_data[0 ]; + } +kfree (verinfo);drivers/hid/hid-picolcd.c line 339
Quoted 10 lines
drivers/hid/hid-picolcd.c new file +10
-0+ verinfo =NULL ; + }else if (verinfo) { +dev_err (&hdev->dev,"confused, got unexpected version response from PicoLCD after reset\n" ); +kfree (verinfo); + verinfo =NULL ; + }else { +dev_err (&hdev->dev,"no version response from PicoLCD after reset" ); +return -EBUSY ; + } +I am pretty sure it could be written clearer instead of checking for verinfo several times...
Quoted 12 lines
if (!verinfo) {
dev_err(..);
return -EBUSY;
}
if (verinfo->raw_size = 2) {
...
} else {
dev_err(...)
}
kfree(verinfo);See below
Quoted 61 lines
Quoted 61 lines
drivers/hid/hid-picolcd.c new file +61
-0+return 0 ; +} + +/* +* The "operation_mode" sysfs attribute +*/ +static ssize_t picolcd_operation_mode_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct picolcd_data *data =dev_get_drvdata (dev); + +if (data->status &PICOLCD_BOOTLOADER ) +return snprintf (buf,PAGE_SIZE ,"<bootloader> lcd\n" ); +else +return snprintf (buf,PAGE_SIZE ,"bootloader <lcd>\n" ); +} + +static ssize_t picolcd_operation_mode_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) +{ +struct picolcd_data *data =dev_get_drvdata (dev); +struct hid_report *report =NULL ; +size_t cnt = count; +int timeout =5000 ; +unsigned u; +unsigned long flags; + +if (cnt >=3 &&strncmp ("lcd" , buf,3 ) =0 ) { +if (data->status &PICOLCD_BOOTLOADER ) + report =picolcd_out_report (REPORT_EXIT_FLASHER , data->hdev); + buf +=3 ; + cnt -=3 ; + }else if (cnt >=10 &&strncmp ("bootloader" , buf,10 ) =0 ) { +if (!(data->status &PICOLCD_BOOTLOADER )) + report =picolcd_out_report (REPORT_EXIT_KEYBOARD , data->hdev); + buf +=10 ; + cnt -=10 ; + } +if (!report) +return -EINVAL ; + +while (cnt >0 && (*buf =' ' || *buf ='\t' )) { + buf++; + cnt--; + } +while (cnt >0 && (buf[cnt-1 ] ='\n' || buf[cnt-1 ] ='\r' )) + cnt--; +if (cnt >0 ) { +if (sscanf (buf,"%u" , &u) !=1 ) +return -EINVAL ; +if (u >30000 ) +return -EINVAL ; +else + timeout = u; + } + +spin_lock_irqsave (&data->lock, flags); +hid_set_field (report->field[0 ],0 , timeout &0xff ); +hid_set_field (report->field[0 ],1 , (timeout >>8 ) &0xff ); +usbhid_submit_report (data->hdev, report,USB_DIR_OUT ); +spin_unlock_irqrestore (&data->lock, flags);
Quoted 8 lines
drivers/hid/hid-picolcd.c line 408
Quoted 8 lines
drivers/hid/hid-picolcd.c new file +8
-0+return count; +} + +static DEVICE_ATTR(operation_mode, 0644, picolcd_operation_mode_show, + picolcd_operation_mode_store); + + +#ifdef CONFIG_DEBUG_FS
... snip reports dumping to debugfs's events ...
Quoted 160 lines
Quoted 160 lines
drivers/hid/hid-picolcd.c new file +160
-0+#else +#define picolcd_debug_raw_event (data, hdev, report, raw_data, size) +#endif + +/* +* Handle raw report as sent by device +*/ +static int picolcd_raw_event (struct hid_device *hdev, +struct hid_report *report,u8 *raw_data,int size) +{ +struct picolcd_data *data =hid_get_drvdata (hdev); +unsigned long flags; +int ret =0 ; + +if (data =NULL ) +return 1 ; + +if (report->id =REPORT_KEY_STATE ) { +if (data->input_keys) + ret =picolcd_raw_keypad (hdev, report, raw_data+1 , size-1 ); + }else if (report->id =REPORT_IR_DATA ) { +if (data->input_cir) + ret =picolcd_raw_cir (hdev, report, raw_data+1 , size-1 ); + }else { +spin_lock_irqsave (&data->lock, flags); +/* +* We let the caller of picolcd_send_and_wait() check if the report +* we got is one of the expected ones or not. +*/ +if (data->pending) { +memcpy (data->pending->raw_data, raw_data+1 , size-1 ); + data->pending->raw_size = size-1 ; + data->pending->in_report = report; +complete_all (&data->ready); + } +spin_unlock_irqrestore (&data->lock, flags); + } + +picolcd_debug_raw_event (data, hdev, report, raw_data, size); +return 1 ; +} + +#ifdef CONFIG_PM +static int picolcd_suspend (struct hid_device *hdev) +{ +dbg_hid (PICOLCD_NAME " device ready for suspend\n" ); +return 0 ; +} + +static int picolcd_resume (struct hid_device *hdev) +{ +return 0 ; +} + +static int picolcd_reset_resume (struct hid_device *hdev) +{ +int ret; + ret =picolcd_reset (hdev); +if (ret) +dbg_hid (PICOLCD_NAME " resetting our device failed: %d\n" , ret); +return 0 ; +} +#endif + +/* initialize keypad input device */ +static inline int picolcd_init_keys (struct picolcd_data *data, +struct hid_report *report) +{ +struct hid_device *hdev = data->hdev; +struct input_dev *idev; +int error, i; + +if (!report) +return -ENODEV ; +if (report->maxfield !=1 || report->field[0 ]->report_count !=2 || + report->field[0 ]->report_size !=8 ) { +dev_err (&hdev->dev,"unsupported KEY_STATE report" ); +return -EINVAL ; + } + + idev =input_allocate_device (); +if (idev =NULL ) { +dev_err (&hdev->dev,"failed to allocate input device" ); +return -ENOMEM ; + } +input_set_drvdata (idev, hdev); +memcpy (data->keycode, def_keymap,sizeof (def_keymap)); + idev->name = hdev->name; + idev->phys = hdev->phys; + idev->uniq = hdev->uniq; + idev->id.bustype = hdev->bus; + idev->id.vendor = hdev->vendor; + idev->id.product = hdev->product; + idev->id.version = hdev->version; + idev->dev.parent = hdev->dev.parent; + idev->keycode = &data->keycode; + idev->keycodemax =PICOLCD_KEYS ; + idev->keycodesize =sizeof (int ); +input_set_capability (idev,EV_MSC ,MSC_SCAN ); +set_bit (EV_REP , idev->evbit); +for (i =0 ; i <PICOLCD_KEYS ; i++) { +int key = ((int *)idev->keycode)[i]; +if (key <KEY_MAX && key >=0 ) +input_set_capability (idev,EV_KEY , key); + } + error =input_register_device (idev); +if (error) { +dev_err (&hdev->dev,"error registering the input device" ); +input_free_device (idev); +return error; + } + data->input_keys = idev; +return 0 ; +} + +static void picolcd_exit_keys (struct picolcd_data *data) +{ +struct input_dev *idev = data->input_keys; + + data->input_keys =NULL ; +if (idev) +input_unregister_device (idev); +} + +/* initialize CIR input device */ +static inline int picolcd_init_cir (struct picolcd_data *data,struct hid_report *report) +{ +/* support not implemented yet */ +return 0 ; +} + +static void picolcd_exit_cir (struct picolcd_data *data) +{ +} + +static inline int picolcd_probe_lcd (struct hid_device *hdev,struct picolcd_data *data) +{ +struct picolcd_pending *verinfo; +struct hid_report *report; +int error; + + verinfo =picolcd_send_and_wait (hdev,REPORT_VERSION ,NULL ,0 ); +if (!verinfo || !verinfo->in_report) { +kfree (verinfo); +dev_err (&hdev->dev,"failed to query FW version of device\n" ); +return -ENODEV ; + }else if (verinfo->in_report->id =REPORT_VERSION && verinfo->raw_size =2 ) { +dev_info (&hdev->dev,"detected PicoLCD with firmware version %d.%d\n" , + verinfo->raw_data[0 ], verinfo->raw_data[1 ]); + data->version[0 ] = verinfo->raw_data[1 ]; + data->version[1 ] = verinfo->raw_data[0 ]; +if (data->version[0 ] !=0 && data->version[1 ] !=3 ) +dev_info (&hdev->dev,"Device with untested firmware revision, " +"please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n" , +dev_name (&hdev->dev)); +kfree (verinfo); + verinfo =NULL ; + }else { + dev_err(&hdev->dev, "unexpected version response from PicoLCD" + " (report=0x%02x, size=%d)\n",
Quoted 8 lines
drivers/hid/hid-picolcd.c line 1044
Quoted 5 lines
drivers/hid/hid-picolcd.c new file +5
-0+ verinfo->in_report->id, verinfo->raw_size); +kfree (verinfo); + verinfo =NULL ; +return -ENODEV ; + }Please consolidate freeing of acquired resources.
See below
Quoted 50 lines
Quoted 50 lines
drivers/hid/hid-picolcd.c new file +50
-0+ +/* Setup keypad input device */ + error =picolcd_init_keys (data,picolcd_in_report (REPORT_KEY_STATE , hdev)); +if (error) + goto err; + +/* Setup CIR input device */ + error =picolcd_init_cir (data,picolcd_in_report (REPORT_IR_DATA , hdev)); +if (error) + goto err; + +#ifdef CONFIG_DEBUG_FS + report =picolcd_out_report (REPORT_READ_MEMORY , hdev); +if (report && report->maxfield =1 && report->field[0 ]->report_size =8 ) + data->addr_sz = report->field[0 ]->report_count -1 ; +else + data->addr_sz =-1 ; +#endif +return 0 ; +err: +picolcd_exit_cir (data); +picolcd_exit_keys (data); +return error; +} + +static inline int picolcd_probe_bootloader (struct hid_device *hdev,struct picolcd_data *data) +{ +struct picolcd_pending *verinfo; +struct hid_report *report; + + verinfo =picolcd_send_and_wait (hdev,REPORT_VERSION ,NULL ,0 ); +if (!verinfo || !verinfo->in_report) { +kfree (verinfo); +dev_err (&hdev->dev,"failed to query FW version of device\n" ); +return -ENODEV ; + }else if (verinfo->in_report->id =REPORT_VERSION && verinfo->raw_size =2 ) { +dev_info (&hdev->dev,"detected PicoLCD with bootloader version %d.%d\n" , + verinfo->raw_data[1 ], verinfo->raw_data[0 ]); + data->version[0 ] = verinfo->raw_data[1 ]; + data->version[1 ] = verinfo->raw_data[0 ]; +if (data->version[0 ] !=1 && data->version[1 ] !=0 ) +dev_info (&hdev->dev,"Device with untested bootloader revision, " +"please submit /sys/kernel/debug/hid/%s/rdesc for this device.\n" , +dev_name (&hdev->dev)); +kfree (verinfo); + verinfo =NULL ; + }else { +dev_err (&hdev->dev,"unexpected version response from PicoLCD" +" (report=0x%02x, size=%d)\n" , + verinfo->in_report->id, verinfo->raw_size);
Quoted 8 lines
drivers/hid/hid-picolcd.c line 1044
Quoted 5 lines
drivers/hid/hid-picolcd.c new file +4
-0+kfree (verinfo); + verinfo =NULL ; +return -ENODEV ; + }Please consolidate freeing of acquired resources. Wait, I just saw afucntion like that... can we combine them somehow?
Yeah, there are 3 blocks of very similar code though the important difference is the operation mode (bootloader versus firmware). According to the behavior and what bootloader mode displays the version numbers are not in the same order for both cases.
The code distribution was looking worse some internal revisions ago as by then I did allocate verinfo->raw_data separately ...
Will try to extract version check to a function.
Quoted 55 lines
Quoted 55 lines
drivers/hid/hid-picolcd.c new file +55
-0+ +#ifdef CONFIG_DEBUG_FS + report =picolcd_out_report (REPORT_BL_READ_MEMORY , hdev); +if (report && report->maxfield =1 && report->field[0 ]->report_size =8 ) + data->addr_sz = report->field[0 ]->report_count -1 ; +else + data->addr_sz =-1 ; +#endif +return 0 ; +} + +static int picolcd_probe (struct hid_device *hdev, +const struct hid_device_id *id) +{ +struct picolcd_data *data; +int error = -ENOMEM ; + +dbg_hid (PICOLCD_NAME " hardware probe...\n" ); + +/* +* Let's allocate the picolcd data structure, set some reasonable +* defaults, and associate it with the device +*/ + data =kzalloc (sizeof (struct picolcd_data ),GFP_KERNEL ); +if (data =NULL ) { +dev_err (&hdev->dev,"can't allocate space for Minibox PicoLCD device data\n" ); + error = -ENOMEM ; + goto err_no_cleanup; + } + +spin_lock_init (&data->lock); +init_completion (&data->ready); + data->hdev = hdev; +if (hdev->product =USB_DEVICE_ID_PICOLCD_BOOTLOADER ) + data->status |=PICOLCD_BOOTLOADER ; +hid_set_drvdata (hdev, data); + +/* Parse the device reports and start it up */ + error =hid_parse (hdev); +if (error) { +dev_err (&hdev->dev,"device report parse failed\n" ); + goto err_cleanup_data; + } + +/* We don't use hidinput but hid_hw_start() fails if nothing is +* claimed. So spoof claimed input. */ + hdev->claimed =HID_CLAIMED_INPUT ; + error =hid_hw_start (hdev,0 ); + hdev->claimed =0 ; +if (error) { +dev_err (&hdev->dev,"hardware start failed\n" ); + goto err_cleanup_data; + } + + error = hdev->ll_driver->open (hdev);
Quoted 8 lines
drivers/hid/hid-picolcd.c line 1159
Quoted 6 lines
drivers/hid/hid-picolcd.c new file +6
-0+if (error) { +dev_err (&hdev->dev,"failed to open input interrupt pipe for key and IR events\n" ); + goto err_cleanup_hid_hw; + } + + error =sysfs_create_file (&(hdev->dev.kobj), &dev_attr_operation_mode.attr);
device_create_file?
Thanks for the pointer, will switch
Quoted 5 lines
drivers/hid/hid-picolcd.c line 1164
Quoted 5 lines
drivers/hid/hid-picolcd.c new file +5
-0+if (error) { +dev_err (&hdev->dev,"failed to create sysfs attributes\n" ); + goto err_cleanup_hid_ll; + } +
Thanks for your review,
Bruno
Quoted 10 lines · Bruno Prémont
Quoted 5 lines · On Sat, 20 March 2010 Dmitry Torokhov <[email protected]> wrote:
drivers/hid/hid-picolcd.c line 202
Quoted 3 lines
drivers/hid/hid-picolcd.c new file +3
-0+usbhid_submit_report (data->hdev, report,USB_DIR_OUT ); +complete_all (&data->ready); +INIT_COMPLETION (data->ready);Umm, what does this do, exactly?
It wakes up anyone waiting on the completion and then resets the completion as otherwise any future attempt to wait on it would succeed immediately.
You realize that if you re-initialize the completion right after signalling it there is a big chance the waiters will miss it (they do check completion->done flags that you reset right away.
In general completions are suited for something that happens once (a single request - allocated - processed - signalled) but not for repeating use.
Thanks.
Signature · 1 line
Dmitry
Bruno Prémont
maintainerQuoted 12 lines · On Sun, 21 March 2010 Dmitry Torokhov <[email protected]> wrote:
Quoted 10 lines · Bruno Prémont
Quoted 5 lines · On Sat, 20 March 2010 Dmitry Torokhov <[email protected]> wrote:
drivers/hid/hid-picolcd.c line 202
Quoted 3 lines
drivers/hid/hid-picolcd.c new file +3
-0+usbhid_submit_report (data->hdev, report,USB_DIR_OUT ); +complete_all (&data->ready); +INIT_COMPLETION (data->ready);Umm, what does this do, exactly?
It wakes up anyone waiting on the completion and then resets the completion as otherwise any future attempt to wait on it would succeed immediately.
Quoted 7 lines
You realize that if you re-initialize the completion right after signalling it there is a big chance the waiters will miss it (they do check
completion->doneflags that you reset right away.In general completions are suited for something that happens once (a single request - allocated - processed - signalled) but not for repeating use.
Would below approach be more correct?
- move the completion to struct picolcd_pending
so it meets the "happens once" requirement
- protect data->pending with a mutex
(though also use spinlock to prevent race between event which
signals the completion and picolcd_send_and_wait() around timeout)
- use the data->lock spinlock to protect multi-report requests from interleaving
In speudo-code this would be something like:
picolcd_send_and_wait(...)
{
struct picolcd_pending pending;
...
init_completion(&pending->ready);
aquire_mutex(data->mutex);
spin_lock_irqsave(&data->lock, flags);
... // prepare report
data->pending = &pending;
usbhid_submit_report(data->hdev, report, USB_DIR_OUT);
spin_unlock_irqrestore(&data->lock, flags);
wait_for_completion_interruptible_timeout(&pending->ready, HZ*2);
spin_lock_irqsave(&data->lock, flags);
if (data->pending = &pending)
data->pending = NULL;
spin_unlock_irqrestore(&data->lock, flags);
release_mutext(data->mutex);
...
}picolcd_raw_event(...)
{
...
spin_lock_irqsave(&data->lock, flags);
if (data->pending) {
// copy event data to pending
...
complete(&pending->ready);
}
spin_unlock_irqrestore(&data->lock, flags);
...
}In picolcd_remove() and picolcd_reset() I could then do something similar to picolcd_raw_event() to trigger completion with no data/error in order to skip timeout on the requester side.
Though how should I prevent races on hot-unplug?
Thanks,
Bruno
Quoted 14 lines · Bruno Prémont
Quoted 5 lines
Quoted 5 lines
drivers/hid/hid-picolcd.c new file +5
-0+ } + data->status |=PICOLCD_BUSY ; + data->pending = work; +for (i = k =0 ; i < report->maxfield; i++) +for (j =0 ; j < report->field[i]->report_count; j++) {Quoted 9 lines
drivers/hid/hid-picolcd.c line 202
Quoted 6 lines
drivers/hid/hid-picolcd.c new file +6
-0+hid_set_field (report->field[i], j, k < size ? raw_data[k] :0 ); + k++; + } +usbhid_submit_report (data->hdev, report,USB_DIR_OUT ); +complete_all (&data->ready); +INIT_COMPLETION (data->ready);Umm, what does this do, exactly?
Quoted 7 lines
It wakes up anyone waiting on the completion and then resets the completion as otherwise any future attempt to wait on it would succeed immediately.
The
complete_all()instead of justcomplete()comes from thereset()function. I can probably reduce it here.Will check this combined with your mutex suggestion above.
I am afraid this code is racy as is. You can't be sure that whoever has been waiting on the completion has been notified already between complete_all() and INIT_COMPLETION(), can you?
Thanks for the driver!
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Bruno Prémont
maintainerPATCH v2 2/6 hid: add framebuffer support to PicoLCD device
In reply to Bruno PrémontAdd framebuffer support to PicoLCD device with use of deferred-io.
Only changed areas of framebuffer get sent to device in order to save USB bandwidth and especially resources on PicoLCD device or allow higher refresh rate for a small area.
--- drivers/hid/Kconfig | 7 +- drivers/hid/hid-picolcd.c | 454 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 460 insertions(+), 1 deletions(-)
drivers/hid/Kconfig +6 -1
@@ -230,6 +230,11 @@ config HID_PETALYNX config HID_PICOLCD tristate "PicoLCD (graphic version)" depends on USB_HID + select FB_DEFERRED_IO if FB + select FB_SYS_FILLRECT if FB + select FB_SYS_COPYAREA if FB + select FB_SYS_IMAGEBLIT if FB + select FB_SYS_FOPS if FB ---help--- This provides support for Minibox PicoLCD devices, currently only the graphical ones are supported.
@@ -237,8 +242,8 @@ config HID_PICOLCD This includes support for the following device features: - Keypad - Switching between Firmware and Flash mode - Features that are not (yet) supported: - Framebuffer for monochrome 256x64 display + Features that are not (yet) supported: - Backlight control - Contrast control - IR
drivers/hid/hid-picolcd.c +454 -0
514 lines not on this page · raw message
Signature · 1 line
1.6.4.4
Re: [PATCH v2 2/6] hid: add framebuffer support to PicoLCD device
drivers/hid/hid-picolcd.c retry: · line 291
Quoted 3 lines · Bruno Prémont
drivers/hid/hid-picolcd.c +3
-0+static inline int picolcd_fb_send_tile (struct hid_device *hdev,int chip, +int tile) +{
You seemt o be fond of the 'inline; attribute ;) I don't think that a 40 lines function qualifies. Please lose inlines on functions that are not in .h files and are not stubs.
Signature · 1 line
Dmitry
Re: [PATCH v2 2/6] hid: add framebuffer support to PicoLCD device
In reply to Bruno PrémontHi Bruno,
Quoted 5 lines · Bruno Prémont
Add framebuffer support to PicoLCD device with use of deferred-io.
Only changed areas of framebuffer get sent to device in order to save USB bandwidth and especially resources on PicoLCD device or allow higher refresh rate for a small area.
Interesting work. One minor comment, defio doesn't currently guarantee that it is "changed areas". Just that it is "written" pages which typically equates to "changed" but does not guarantee this.
Quoted 6 lines
Signed-off-by Bruno Prémont <[email protected]>---
drivers/hid/Kconfig | 7 +-
drivers/hid/hid-picolcd.c | 454 +++++++++++++++++++++++++++++++++++++++++++++2 files changed, 460 insertions(+), 1 deletions(-)
It is customary for framebuffer drivers to live in drivers/video. This is the first one I've reviewed that is outside of it. Is there a good reason for this one to be outside of it? If so, could you put it in the comments.
Quoted 6 lines
drivers/hid/Kconfig +0
-0@@ -230,6 +230,11 @@ config HID_PETALYNX
Quoted 8 lines
config
HID_PICOLCD
tristate "PicoLCD (graphic version)"
depends onUSB_HID
+ selectFB_DEFERRED_IOif FB
+ selectFB_SYS_FILLRECTif FB
+ selectFB_SYS_COPYAREAif FB
+ selectFB_SYS_IMAGEBLITif FB
+ selectFB_SYS_FOPSif FB
I think all of that "if FB" stuff looks odd, it would disappear if it were in the right Kconfig.
drivers/hid/Kconfig
Quoted 5 lines
drivers/hid/Kconfig +5
-0+/* Framebuffer visual structures */ +static const struct fb_fix_screeninfo picolcdfb_fix = { + .id = PICOLCDFB_NAME, + .type = FB_TYPE_PACKED_PIXELS, + .visual = FB_VISUAL_MONO01,
Interesting choice. Out of curiosity, which fb client application are you testing/using this with?
Quoted 5 lines
+ /*
+ * Translate the XBM formatscreen_baseinto the format needed by the
+ * PicoLCD. See display layout above.
+ * Do this one tile after the other and push those tiles that changed.
+ */
I think screen_base is in standard fb format, which you've specified as MONO01 above. When you say, XBM format, in the above comment is it exactly the same?
Thanks,
jaya
Bruno Prémont
maintainerRe: [PATCH v2 2/6] hid: add framebuffer support to PicoLCD device
Quoted 9 lines · On Sun, 21 March 2010 Jaya Kumar <[email protected]> wrote:
Quoted 5 lines
Add framebuffer support to PicoLCD device with use of deferred-io.
Only changed areas of framebuffer get sent to device in order to save USB bandwidth and especially resources on PicoLCD device or allow higher refresh rate for a small area.
Interesting work. One minor comment, defio doesn't currently guarantee that it is "changed areas". Just that it is "written" pages which typically equates to "changed" but does not guarantee this.
When copying from framebuffer to shadow buffer I check if any given tile has changed and only send that tile to the device if it has effectively changed. So this check is done independently of defio. (though I have to force-fully transfer the whole framebuffer at probe or after reset - which is missing)
Quoted 10 lines
Quoted 5 lines
Signed-off-by Bruno Prémont <[email protected]>---
drivers/hid/Kconfig | 7 +-
drivers/hid/hid-picolcd.c | 454 +++++++++++++++++++++++++++++++++++++++++++++2 files changed, 460 insertions(+), 1 deletions(-)It is customary for framebuffer drivers to live in
drivers/video. This is the first one I've reviewed that is outside of it. Is there a good reason for this one to be outside of it? If so, could you put it in the comments.
I've kept all the pieces of PicoLCD driver together under hid, as it's a HID based device. Framebuffer is just one of its features and keeping pieces together makes it easier to handle.
Quoted 8 lines
Quoted 8 lines
drivers/hid/Kconfig +0
-0@@ -230,6 +230,11 @@ config HID_PETALYNXconfig
HID_PICOLCD
tristate "PicoLCD (graphic version)"
depends onUSB_HID
Quoted 8 lines
Quoted 5 lines
+ select
FB_DEFERRED_IOif FB
+ selectFB_SYS_FILLRECTif FB
+ selectFB_SYS_COPYAREAif FB
+ selectFB_SYS_IMAGEBLITif FB
+ selectFB_SYS_FOPSif FBI think all of that "if FB" stuff looks odd, it would disappear if it were in the right
Kconfig.
In the initial patch I did select FB as well though for v2 I decided to make all the dependencies of non-input features optional. For the FB case the various helper entries are needed, for the rest it's sufficient to have #ifdef's for their device class.
Another option would be to distribute the Kconfig entries over the various device class's Kconfig files though I don't think that would make things easier to understand...
Quoted 8 lines
drivers/hid/Kconfig
Quoted 5 lines
drivers/hid/Kconfig +5
-0+/* Framebuffer visual structures */ +static const struct fb_fix_screeninfo picolcdfb_fix = { + .id = PICOLCDFB_NAME, + .type = FB_TYPE_PACKED_PIXELS, + .visual = FB_VISUAL_MONO01,Interesting choice. Out of curiosity, which fb client application are you testing/using this with?
For now I've just been testing with manual read/write to /dev/fb. I've not yet played with fb applications.
I've had a look at fb applications, seems that none wants to play with individual bits, they all bail out requesting 8 or more bpp (some fail politely, others just exit/segfault and don't undo changes they did)
So I guess I will have to add support for translating 8bpp to device's 1bpp to be able to use any existing fb application and switching between 1bpp and 8bpp framebuffer...
Quoted 9 lines
Quoted 5 lines
+ /*
+ * Translate the XBM formatscreen_baseinto the format needed by the
+ * PicoLCD. See display layout above.
+ * Do this one tile after the other and push those tiles that changed.
+ */I think
screen_baseis in standard fb format, which you've specified as MONO01 above. When you say, XBM format, in the above comment is it exactly the same?
It should be the same (from what I read MONO01 versus MONO10 is just whether 0 or 1 is "black" or "white") and in combination with PACKED_PIXELS it makes 8 pixels per bytes.
Thanks for the review,
Bruno
Re: [PATCH v2 2/6] hid: add framebuffer support to PicoLCD device
Quoted 5 lines · Bruno Prémont
Quoted 5 lines
Quoted 4 lines
---
drivers/hid/Kconfig | 7 +-
drivers/hid/hid-picolcd.c | 454 +++++++++++++++++++++++++++++++++++++++++++++2 files changed, 460 insertions(+), 1 deletions(-)
Quoted 8 lines
Quoted 4 lines
It is customary for framebuffer drivers to live in
drivers/video. This is the first one I've reviewed that is outside of it. Is there a good reason for this one to be outside of it? If so, could you put it in the comments.I've kept all the pieces of PicoLCD driver together under hid, as it's a HID based device. Framebuffer is just one of its features and keeping pieces together makes it easier to handle.
I think it makes sense for a HID driver for this device to contain the framebuffer bits as well ... from user perspective, this seems to be HID device, with "extra" framebuffer display on it.
If framebuffer folks Ack the fb-related code, I am fine keeping it under drivers/hid.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Bruno Prémont
maintainerPATCH v2 3/6 hid: add backlight support to PicoLCD device
In reply to Bruno PrémontAdd backlight support to PicoLCD device.
Backlight support depends on backlight class and is only being compiled if backlight class has been selected.
--- drivers/hid/Kconfig | 2 +- drivers/hid/hid-picolcd.c | 134 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 2 deletions(-)
drivers/hid/Kconfig +1 -1
@@ -243,8 +243,8 @@ config HID_PICOLCD - Keypad - Switching between Firmware and Flash mode - Framebuffer for monochrome 256x64 display + - Backlight control (needs CONFIG_BACKLIGHT_CLASS_DEVICE) Features that are not (yet) supported: - - Backlight control - Contrast control - IR - General purpose outputs
drivers/hid/hid-picolcd.c +133 -1
202 lines not on this page · raw message
Signature · 1 line
1.6.4.4
Re: [PATCH v2 3/6] hid: add backlight support to PicoLCD device
Quoted 16 lines · Bruno Prémont
Add backlight support to PicoLCD device.
Backlight support depends on backlight class and is only being compiled if backlight class has been selected.
Signed-off-by Bruno Prémont <[email protected]>--- drivers/hid/Kconfig | 2 +- drivers/hid/hid-picolcd.c | 134 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 2 deletions(-)drivers/hid/Kconfig +0
-0
drivers/hid/Kconfig config HID_PICOLCD · line 246
Quoted 4 lines
drivers/hid/Kconfig +1
-0@@ -243,8 +243,8 @@ config HID_PICOLCD - Keypad - Switching between Firmware and Flash mode - Framebuffer for monochrome 256x64 display + - Backlight control (needs CONFIG_BACKLIGHT_CLASS_DEVICE)
Wouldn't it be better to have Kconfig rules actually resolve the dependency?
I don't see any issue with HID_PICOLCD directly selecting BACKLIGHT_CLASS_DEVICE. Or you can do a separate sub-option for that, if you really want to avoid the direct dependency of the whole driver.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Bruno Prémont
maintainerRe: [PATCH v2 3/6] hid: add backlight support to PicoLCD device
Quoted 26 lines · On Mon, 22 March 2010 Jiri Kosina <[email protected]> wrote:
Quoted 16 lines · Bruno Prémont
Add backlight support to PicoLCD device.
Backlight support depends on backlight class and is only being compiled if backlight class has been selected.
Signed-off-by Bruno Prémont <[email protected]>--- drivers/hid/Kconfig | 2 +- drivers/hid/hid-picolcd.c | 134 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 2 deletions(-)drivers/hid/Kconfig +0
-0drivers/hid/Kconfig config HID_PICOLCD · line 246
Quoted 4 lines
drivers/hid/Kconfig +1
-0@@ -243,8 +243,8 @@ config HID_PICOLCD - Keypad - Switching between Firmware and Flash mode - Framebuffer for monochrome 256x64 display + - Backlight control (needs CONFIG_BACKLIGHT_CLASS_DEVICE)Wouldn't it be better to have
Kconfigrules actually resolve the dependency?
Quoted 3 lines
I don't see any issue with
HID_PICOLCDdirectly selectingBACKLIGHT_CLASS_DEVICE. Or you can do a separate sub-option for that, if you really want to avoid the direct dependency of the whole driver.
I could select both BACKLIGHT_CLASS_DEVICE and LCD_CLASS_DEVICE (as well as their common parent -- same applies to FB) though for the LEDS_CLASS I would definitely rather go the path of a sub-option, by default the GPO pins operated with the LEDs are not connected to anything.
Thanks for the review,
Bruno
Bruno Prémont
maintainerPATCH v2 4/6 hid: add lcd support to PicoLCD device
In reply to Bruno PrémontAdd lcd support to PicoLCD device.
LCD support depends on lcd class and is only being compiled if lcd class has been selected.
--- drivers/hid/Kconfig | 2 +- drivers/hid/hid-picolcd.c | 108 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletions(-)
drivers/hid/Kconfig +1 -1
@@ -244,8 +244,8 @@ config HID_PICOLCD - Switching between Firmware and Flash mode - Framebuffer for monochrome 256x64 display - Backlight control (needs CONFIG_BACKLIGHT_CLASS_DEVICE) + - Contrast control (needs CONFIG_LCD_CLASS_DEVICE) Features that are not (yet) supported: - - Contrast control - IR - General purpose outputs - EEProm / Flash access
drivers/hid/hid-picolcd.c +108 -0
156 lines not on this page · raw message
Signature · 1 line
1.6.4.4
Bruno Prémont
maintainerPATCH v2 5/6 hid: add GPO (leds) support to PicoLCD device
In reply to Bruno PrémontAdd leds support to PicoLCD device to drive the GPO pins.
GPO support depends on leds class and is only being compiled if leds class has been selected.
--- drivers/hid/Kconfig | 6 +- drivers/hid/hid-picolcd.c | 163 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 3 deletions(-)
drivers/hid/Kconfig +3 -3
@@ -243,11 +243,11 @@ config HID_PICOLCD - Keypad - Switching between Firmware and Flash mode - Framebuffer for monochrome 256x64 display - - Backlight control (needs CONFIG_BACKLIGHT_CLASS_DEVICE) - - Contrast control (needs CONFIG_LCD_CLASS_DEVICE) + - Backlight control (needs CONFIG_BACKLIGHT_CLASS_DEVICE) + - Contrast control (needs CONFIG_LCD_CLASS_DEVICE) + - General purpose outputs (needs CONFIG_LEDS_CLASS) Features that are not (yet) supported: - IR - - General purpose outputs - EEProm / Flash access config HID_SAMSUNG
drivers/hid/hid-picolcd.c +163 -0
211 lines not on this page · raw message
Signature · 1 line
1.6.4.4
Bruno Prémont
maintainerPATCH v2 6/6 hid: add experimental access to PicoLCD device's EEPROM and FLASH
In reply to Bruno PrémontThe PicoLCD device has a small amount of EEPROM and also provides access to its FLASH where firmware and splash image are saved. In flasher mode FLASH access is the only active feature.
Give read/write access to both via debugfs files.
--- drivers/hid/Kconfig | 2 +- drivers/hid/hid-picolcd.c | 428 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 412 insertions(+), 18 deletions(-)
drivers/hid/Kconfig +1 -1
@@ -246,9 +246,9 @@ config HID_PICOLCD - Backlight control (needs CONFIG_BACKLIGHT_CLASS_DEVICE) - Contrast control (needs CONFIG_LCD_CLASS_DEVICE) - General purpose outputs (needs CONFIG_LEDS_CLASS) + - EEProm / Flash access (via debugfs) Features that are not (yet) supported: - IR - - EEProm / Flash access config HID_SAMSUNG tristate "Samsung" if EMBEDDED
drivers/hid/hid-picolcd.c +411 -17
478 lines not on this page · raw message
Signature · 1 line
1.6.4.4
Re: [PATCH v2 6/6] hid: add experimental access to PicoLCD device's EEPROM and FLASH
Quoted 6 lines · Bruno Prémont
The PicoLCD device has a small amount of EEPROM and also provides access to its FLASH where firmware and splash image are saved. In flasher mode FLASH access is the only active feature.
Give read/write access to both via debugfs files.
It looks you are allowing multiple users access to these files. What will happen if 2 processes try to write EEPROM at the same time?
drivers/hid/hid-picolcd.c static inline void picolcd_debug_raw_event(struct picolcd_data *data, · line 2031
Quoted 6 lines
drivers/hid/hid-picolcd.c +6
-0+ +static inline int picolcd_init_devfs (struct picolcd_data *data, +struct hid_report *eeprom_r,struct hid_report *eeprom_w, +struct hid_report *flash_r,struct hid_report *flash_w, +struct hid_report *reset) +{
I don't think this should be forced inline.
Thanks.
Signature · 1 line
Dmitry
Bruno Prémont
maintainerRe: [PATCH v2 6/6] hid: add experimental access to PicoLCD device's EEPROM and FLASH
Quoted 10 lines · On Sat, 20 March 2010 Dmitry Torokhov <[email protected]> wrote:
Quoted 6 lines · Bruno Prémont
The PicoLCD device has a small amount of EEPROM and also provides access to its FLASH where firmware and splash image are saved. In flasher mode FLASH access is the only active feature.
Give read/write access to both via debugfs files.
It looks you are allowing multiple users access to these files. What will happen if 2 processes try to write EEPROM at the same time?
Writes will be serialized by the wait for response from device with picolcd_send_and_wait() and it's up to userspace to repeat the reads/writes in order to get all the data they need if they requested more that the 20 bytes that can be transferred in a single HID report.
For flash access a concurrent write to same area can cause one of the writers to conflict with the other one as a write there is a sequence of operations which can interleave (e.g. A erases, A writes 1/2, B erases, B writes 1/2, A writes 2nd 1/2, B writes 2nd 1/2 which would fail).
A single-user open would be a nice work-around for this.
I would prefer to make erase operation explicitly visible to user so I don't have to do the erase behind the scenes.
I've not yet looked in the area of mtd/nand support if I can use their interface.
This is the big reason I did put both to debugfs, they (especially flash access) need to be made visible in a better way.
Quoted 8 lines
drivers/hid/hid-picolcd.c static inline void picolcd_debug_raw_event(struct picolcd_data *data, · line 2031
Quoted 6 lines
drivers/hid/hid-picolcd.c +6
-0+ +static inline int picolcd_init_devfs (struct picolcd_data *data, +struct hid_report *eeprom_r,struct hid_report *eeprom_w, +struct hid_report *flash_r,struct hid_report *flash_w, +struct hid_report *reset) +{I don't think this should be forced inline.
Ok, will drop most of the 'inline' keywords as you suggested already on one of the other patches.
Thanks for the review,
Bruno