From patchwork Sat Dec 1 19:07:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Guedes X-Patchwork-Id: 1829651 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 77841DF264 for ; Sat, 1 Dec 2012 19:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752761Ab2LATHm (ORCPT ); Sat, 1 Dec 2012 14:07:42 -0500 Received: from mail-vb0-f46.google.com ([209.85.212.46]:42104 "EHLO mail-vb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752297Ab2LATHl (ORCPT ); Sat, 1 Dec 2012 14:07:41 -0500 Received: by mail-vb0-f46.google.com with SMTP id b13so497377vby.19 for ; Sat, 01 Dec 2012 11:07:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=VhGJ3kgz5UYHUZFsTht1sDiuHqXr0jfPM+/3nFSsf5M=; b=Q3Vf5ZvYuFGB26etHnupxGKxojRcB20Q4td2tkygR300n6dxxiPsiRdnDGlMwFFlH/ NE4o2pHCrL4rZaN86X4OAoLqS9u0LvfRR+G/hR0rHupi30j2g3XZXJwYhcjwrVEv0APi AUf3UjzlfsQ2MyU1zGNn8IuqeVLnR7elj9oBwOTj3TBTPR49EsZvIHedGNgnSp3GUtm3 JkG7n5a/3c+eCUr80X9EaBYyioPXFmcAJthAuvcj8czst60FXrhvKknQ1/G2UqiYGNGP ZC3mHZmdRePy15s+YXrmPnehKe4cr70OLlPyK6gwswkM33cMi1Fobfh3fkyROe8Jw8mZ EMoQ== Received: by 10.52.17.244 with SMTP id r20mr3916976vdd.29.1354388860693; Sat, 01 Dec 2012 11:07:40 -0800 (PST) Received: from localhost.localdomain ([177.134.152.163]) by mx.google.com with ESMTPS id g5sm2912702vez.6.2012.12.01.11.07.38 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 01 Dec 2012 11:07:39 -0800 (PST) From: Andre Guedes To: linux-input@vger.kernel.org Cc: dh.herrmann@googlemail.com Subject: [RFC v2 1/4] HID: Add generic handler for LED input events Date: Sat, 1 Dec 2012 16:07:18 -0300 Message-Id: <1354388841-23854-2-git-send-email-andre.guedes@openbossa.org> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1354388841-23854-1-git-send-email-andre.guedes@openbossa.org> References: <1354388841-23854-1-git-send-email-andre.guedes@openbossa.org> X-Gm-Message-State: ALoCoQkAgYuxQ4wJyX81CGVVO4O/7jvIaFxReauDMakIxH0QggwwKPwHBkvV1bUEvHJ4MVlux81+ Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This patch adds the helper hidinput_led_output_report to handle LED input events. This helper implements a generic handler for LED input events. It basically sets the proper field, builds the output report and call hid_output_raw_report callback to send the raw report to the device. Signed-off-by: Andre Guedes --- drivers/hid/hid-input.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/hid.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 21b196c..957f510 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1300,3 +1300,54 @@ void hidinput_disconnect(struct hid_device *hid) } EXPORT_SYMBOL_GPL(hidinput_disconnect); +/* + * hidinput_led_output_report - Generic handler for LED input events + * + * @hid: hid device + * @code: input event code + * @value: input event value + * + * This function implements a generic handler for LED input events. It + * sets the proper LED field, builds the output report and sends it to + * device. + * + * This helper relies on device's .hid_output_raw_report() to send + * reports to the device. + */ +int hidinput_led_output_report(struct hid_device *hid, unsigned int code, + int value) +{ + int offset; + struct hid_field *field; + struct hid_report *report; + u8 *buf; + int len; + int ret; + + if (!hid->hid_output_raw_report) + return -ENOTSUPP; + + offset = hidinput_find_field(hid, EV_LED, code, &field); + if (offset == -1) + return -ENOENT; + + hid_set_field(field, offset, value); + + report = field->report; + + len = ((report->size - 1) >> 3) + 1 + (report->id > 0); + + buf = kzalloc(len, GFP_ATOMIC); + if (!buf) + return -ENOMEM; + + hid_output_report(report, buf); + + ret = hid->hid_output_raw_report(hid, buf, len, HID_OUTPUT_REPORT); + + kfree(buf); + + return ret; +} +EXPORT_SYMBOL_GPL(hidinput_led_output_report); + diff --git a/include/linux/hid.h b/include/linux/hid.h index d2c42dd..bd02df3 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -701,6 +701,8 @@ extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct h extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report); extern int hidinput_connect(struct hid_device *hid, unsigned int force); extern void hidinput_disconnect(struct hid_device *); +extern int hidinput_led_output_report(struct hid_device *hid, + unsigned int code, int value); int hid_set_field(struct hid_field *, unsigned, __s32); int hid_input_report(struct hid_device *, int type, u8 *, int, int);