コード例 #1
0
static ssize_t valve_sc_store_autobuttons(struct device *dev,
					  struct device_attribute *attr,
					  const char *buf, size_t count)
{
	int ret;
	struct valve_sc_device *sc = dev_get_drvdata(dev);
	struct hid_device *hdev = to_hid_device(dev);

	if (strncmp(buf, "on", 2) == 0)
		sc->autobuttons = true;
	else if (strncmp(buf, "off", 3) == 0)
		sc->autobuttons = false;
	else
		return -EINVAL;

	if (sc->connected) {
		u8 feature;
		if (sc->autobuttons)
			feature = SC_FEATURE_ENABLE_AUTO_BUTTONS;
		else
			feature = SC_FEATURE_DISABLE_AUTO_BUTTONS;

		ret = valve_sc_send_request(sc, feature,
					    NULL, 0,
					    NULL, NULL);
		if (ret < 0)
			hid_warn(hdev, "Error while setting autobuttons: %d\n", -ret);
	}
	return count;
}
コード例 #2
0
ファイル: rmi_hid.c プロジェクト: thypon/bowser-kernel
/*
 * rmi_set_page - Set RMI page
 * @xport: The pointer to the rmi_transport_device struct
 * @page: The new page address.
 *
 * RMI devices have 16-bit addressing, but some of the physical
 * implementations (like SMBus) only have 8-bit addressing. So RMI implements
 * a page address at 0xff of every page so we can reliable page addresses
 * every 256 registers.
 *
 * The page_mutex lock must be held when this function is entered.
 *
 * Returns zero on success, non-zero on failure.
 */
static int rmi_set_page(struct rmi_transport_device *xport, u8 page)
{
        struct hid_device *hdev = to_hid_device(xport->dev);
        struct rmi_hid_data *data = xport->data;
        int retval;

        if (COMMS_DEBUG(data))
                dev_dbg(&hdev->dev, "writes output report: %*ph\n",
			data->output_report_size, data->writeReport);

        xport->info.tx_count++;
        xport->info.tx_bytes += data->output_report_size;

	data->writeReport[RMI_HID_REPORT_ID] = RMI_WRITE_REPORT_ID;
	data->writeReport[RMI_HID_WRITE_OUTPUT_COUNT] = 1;
	data->writeReport[RMI_HID_WRITE_OUTPUT_ADDR] = 0xFF;
	data->writeReport[RMI_HID_WRITE_OUTPUT_DATA] = page;

        retval = rmi_hid_write_report(hdev, data->writeReport,
			data->output_report_size);
        if (retval != data->output_report_size) {
                xport->info.tx_errs++;
                dev_err(&hdev->dev,
                        "%s: set page failed: %d.", __func__, retval);
                return retval;
        }

        data->page = page;
        return 0;
}
コード例 #3
0
static ssize_t valve_sc_store_orientation(struct device *dev,
				          struct device_attribute *attr,
				          const char *buf, size_t count)
{
	int ret;
	struct valve_sc_device *sc = dev_get_drvdata(dev);
	struct hid_device *hdev = to_hid_device(dev);
	u8 params[3];

	if (strncmp(buf, "on", 2) == 0)
		sc->orientation = SC_SETTINGS_ORIENTATION_ACCEL |
				  SC_SETTINGS_ORIENTATION_GYRO;
	else if (strncmp(buf, "off", 3) == 0)
		sc->orientation = 0;
	else
		return -EINVAL;

	if (sc->connected) {
		params[0] = SC_SETTINGS_ORIENTATION;
		params[1] = sc->orientation;
		params[2] = 0;
		ret = valve_sc_send_request(sc, SC_FEATURE_SETTINGS,
					    params, sizeof(params),
					    NULL, NULL);
		if (ret < 0)
			hid_warn(hdev, "Error while setting automouse: %d\n", -ret);
	}
	return count;
}
コード例 #4
0
static ssize_t valve_sc_store_automouse(struct device *dev,
				        struct device_attribute *attr,
				        const char *buf, size_t count)
{
	int ret;
	struct valve_sc_device *sc = dev_get_drvdata(dev);
	struct hid_device *hdev = to_hid_device(dev);
	u8 params[3];

	if (strncmp(buf, "on", 2) == 0)
		sc->automouse = true;
	else if (strncmp(buf, "off", 3) == 0)
		sc->automouse = false;
	else
		return -EINVAL;

	if (sc->connected) {
		params[0] = SC_SETTINGS_AUTOMOUSE;
		if (sc->automouse)
			params[1] = SC_SETTINGS_AUTOMOUSE_ON;
		else
			params[1] = SC_SETTINGS_AUTOMOUSE_OFF;
		params[2] = 0;
		ret = valve_sc_send_request(sc, SC_FEATURE_SETTINGS,
					    params, sizeof(params),
					    NULL, NULL);
		if (ret < 0)
			hid_warn(hdev, "Error while setting automouse: %d\n", -ret);
	}
	return count;
}
コード例 #5
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static ssize_t attr_select_right_show_tpkbd(struct device *dev,
		struct device_attribute *attr,
		char *buf)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);

	return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right);
}
コード例 #6
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static ssize_t attr_fn_lock_show_cptkbd(struct device *dev,
		struct device_attribute *attr,
		char *buf)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);

	return snprintf(buf, PAGE_SIZE, "%u\n", cptkbd_data->fn_lock);
}
コード例 #7
0
ファイル: rmi_hid.c プロジェクト: thypon/bowser-kernel
static void rmi_hid_reset_work(struct work_struct *work)
{
	struct rmi_hid_data * hdata = container_of(work, struct rmi_hid_data,
						reset_work);
	struct rmi_transport_device * xport = hdata->xport;

        struct hid_device *hdev = to_hid_device(xport->dev);
	rmi_hid_set_mode(hdev, RMI_HID_MODE_ATTN_REPORTS);
}
コード例 #8
0
ファイル: hid-multitouch.c プロジェクト: forgivemyheart/linux
static ssize_t mt_show_quirks(struct device *dev,
			   struct device_attribute *attr,
			   char *buf)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct mt_device *td = hid_get_drvdata(hdev);

	return sprintf(buf, "%u\n", td->mtclass.quirks);
}
コード例 #9
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static enum led_brightness lenovo_led_brightness_get_tpkbd(
			struct led_classdev *led_cdev)
{
	struct device *dev = led_cdev->dev->parent;
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
	int led_nr = 0;

	if (led_cdev == &data_pointer->led_micmute)
		led_nr = 1;

	return data_pointer->led_state & (1 << led_nr)
				? LED_FULL
				: LED_OFF;
}
コード例 #10
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static ssize_t attr_sensitivity_store_cptkbd(struct device *dev,
		struct device_attribute *attr,
		const char *buf,
		size_t count)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
	int value;

	if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
		return -EINVAL;

	cptkbd_data->sensitivity = value;
	lenovo_features_set_cptkbd(hdev);

	return count;
}
コード例 #11
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static ssize_t attr_press_speed_store_tpkbd(struct device *dev,
		struct device_attribute *attr,
		const char *buf,
		size_t count)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
	int value;

	if (kstrtoint(buf, 10, &value) || value < 1 || value > 255)
		return -EINVAL;

	data_pointer->press_speed = value;
	lenovo_features_set_tpkbd(hdev);

	return count;
}
コード例 #12
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static ssize_t attr_select_right_store_tpkbd(struct device *dev,
		struct device_attribute *attr,
		const char *buf,
		size_t count)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
	int value;

	if (kstrtoint(buf, 10, &value))
		return -EINVAL;
	if (value < 0 || value > 1)
		return -EINVAL;

	data_pointer->select_right = value;
	lenovo_features_set_tpkbd(hdev);

	return count;
}
コード例 #13
0
ファイル: hid-multitouch.c プロジェクト: forgivemyheart/linux
static ssize_t mt_set_quirks(struct device *dev,
			  struct device_attribute *attr,
			  const char *buf, size_t count)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct mt_device *td = hid_get_drvdata(hdev);

	unsigned long val;

	if (kstrtoul(buf, 0, &val))
		return -EINVAL;

	td->mtclass.quirks = val;

	if (td->cc_index < 0)
		td->mtclass.quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;

	return count;
}
コード例 #14
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static ssize_t attr_fn_lock_store_cptkbd(struct device *dev,
		struct device_attribute *attr,
		const char *buf,
		size_t count)
{
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev);
	int value;

	if (kstrtoint(buf, 10, &value))
		return -EINVAL;
	if (value < 0 || value > 1)
		return -EINVAL;

	cptkbd_data->fn_lock = !!value;
	lenovo_features_set_cptkbd(hdev);

	return count;
}
コード例 #15
0
ファイル: rmi_hid.c プロジェクト: thypon/bowser-kernel
static int rmi_hid_write_block(struct rmi_transport_device *xport, u16 addr,
			       const void *buf, const int len)
{
        struct hid_device *hdev = to_hid_device(xport->dev);
	struct rmi_hid_data *data = xport->data;
	int ret;

	mutex_lock(&data->page_mutex);

	if (RMI_HID_PAGE(addr) != data->page) {
		ret = rmi_set_page(xport, RMI_HID_PAGE(addr));
		if (ret < 0)
			goto exit;
	}

	if (COMMS_DEBUG(data)) {
		ret = copy_to_debug_buf(&hdev->dev, data, (u8 *) buf, len);
		if (!ret)
			dev_dbg(&hdev->dev, "writes %d bytes at %#06x:%s\n",
				len, addr, data->debug_buf);
	}

	xport->info.tx_count++;
	xport->info.tx_bytes += len;

	data->writeReport[RMI_HID_REPORT_ID] = RMI_WRITE_REPORT_ID;
	data->writeReport[RMI_HID_WRITE_OUTPUT_COUNT] = len;
	data->writeReport[RMI_HID_WRITE_OUTPUT_ADDR] = addr & 0xFF;
	data->writeReport[RMI_HID_WRITE_OUTPUT_ADDR + 1] = (addr >> 8) & 0xFF;
	memcpy(&data->writeReport[RMI_HID_WRITE_OUTPUT_DATA], buf, len);

	ret = rmi_hid_write_report(hdev, data->writeReport,
					data->output_report_size);
	if (ret != data->output_report_size) {
		dev_err(&hdev->dev, "failed to send output report (%d)\n", ret);
		goto exit;
	}

exit:
	mutex_unlock(&data->page_mutex);
	return ret;
}
コード例 #16
0
ファイル: hid-lenovo.c プロジェクト: 1888/linux
static void lenovo_led_brightness_set_tpkbd(struct led_classdev *led_cdev,
			enum led_brightness value)
{
	struct device *dev = led_cdev->dev->parent;
	struct hid_device *hdev = to_hid_device(dev);
	struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev);
	struct hid_report *report;
	int led_nr = 0;

	if (led_cdev == &data_pointer->led_micmute)
		led_nr = 1;

	if (value == LED_OFF)
		data_pointer->led_state &= ~(1 << led_nr);
	else
		data_pointer->led_state |= 1 << led_nr;

	report = hdev->report_enum[HID_OUTPUT_REPORT].report_id_hash[3];
	report->field[0]->value[0] = (data_pointer->led_state >> 0) & 1;
	report->field[0]->value[1] = (data_pointer->led_state >> 1) & 1;
	hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
}
コード例 #17
0
ファイル: rmi_hid.c プロジェクト: thypon/bowser-kernel
static int rmi_hid_read_block(struct rmi_transport_device *xport, u16 addr,
			      void *buf, const int len)
{
        struct hid_device *hdev = to_hid_device(xport->dev);
	struct rmi_hid_data *data = xport->data;
	int ret;
	int bytes_read;
	int bytes_needed;
	int retries;
	int read_input_count;

	mutex_lock(&data->page_mutex);

	if (RMI_HID_PAGE(addr) != data->page) {
		ret = rmi_set_page(xport, RMI_HID_PAGE(addr));
		if (ret < 0)
			goto exit;
	}

	for (retries = 5; retries > 0; retries--) {
		data->writeReport[RMI_HID_REPORT_ID] = RMI_READ_ADDR_REPORT_ID;
		data->writeReport[1] = 0; /* old 1 byte read count */
		data->writeReport[RMI_HID_READ_OUTPUT_ADDR] = addr & 0xFF;
		data->writeReport[RMI_HID_READ_OUTPUT_ADDR + 1] = (addr >> 8) & 0xFF;
		data->writeReport[RMI_HID_READ_OUTPUT_COUNT] = len  & 0xFF;
		data->writeReport[RMI_HID_READ_OUTPUT_COUNT + 1] = (len >> 8) & 0xFF;

		if (COMMS_DEBUG(data)) {
			ret = copy_to_debug_buf(&hdev->dev, data, data->writeReport, len);
			if (!ret)
				dev_dbg(&hdev->dev, "wrote %d bytes at %#06x:%s\n",
					len, addr, data->debug_buf);
		}

		set_bit(RMI_HID_READ_REQUEST_PENDING, &data->flags);

		ret = rmi_hid_write_report(hdev, data->writeReport,
						data->output_report_size);
		if (ret != data->output_report_size) {
			clear_bit(RMI_HID_READ_REQUEST_PENDING, &data->flags);
			dev_err(&hdev->dev,
				"failed to write request output report (%d)\n", ret);
			goto exit;
		}

		bytes_read = 0;
		bytes_needed = len;
		while (bytes_read < len) {
			if (!wait_event_timeout(data->wait, 
					test_bit(RMI_HID_READ_DATA_PENDING, &data->flags),
					msecs_to_jiffies(1000)))
			{
					dev_info(&hdev->dev, "%s: timeout elapsed\n", __func__);
					ret = -ENODATA;
					break;
			} else {
				if (data->readReport[RMI_HID_REPORT_ID]
						!= RMI_READ_DATA_REPORT_ID)
				{
					ret = -ENODATA;
					dev_err(&hdev->dev,
						"%s: Expected data report, but got"
						" report id %d instead", __func__,
						data->readReport[RMI_HID_REPORT_ID]);
					goto exit;
				}

				read_input_count = data->readReport[RMI_HID_READ_INPUT_COUNT];
				memcpy(buf + bytes_read,
					&data->readReport[RMI_HID_READ_INPUT_DATA],
					read_input_count < bytes_needed 
					? read_input_count : bytes_needed);

				if (COMMS_DEBUG(data)) {
					ret = copy_to_debug_buf(&hdev->dev, data,
							(u8 *) buf + bytes_read,
							read_input_count);
					if (!ret)
						dev_dbg(&hdev->dev, "read %d bytes at %#06x:%s\n",
							read_input_count, addr,
							data->debug_buf);
				}
				bytes_read += read_input_count;
				bytes_needed -= read_input_count;
				clear_bit(RMI_HID_READ_DATA_PENDING, &data->flags);
			}
		}

		if (bytes_read == len)
			break;
	}

	if (bytes_read == len) {
		xport->info.rx_count++;
		xport->info.rx_bytes += len;
		ret = len;
	}

exit:
	clear_bit(RMI_HID_READ_REQUEST_PENDING, &data->flags);
	mutex_unlock(&data->page_mutex);
	return ret;
}
コード例 #18
0
ファイル: rmi_hid.c プロジェクト: thypon/bowser-kernel
static void rmi_hid_post_reset(struct rmi_transport_device *xport)
{
        struct hid_device *hdev = to_hid_device(xport->dev);
	rmi_hid_set_mode(hdev, RMI_HID_MODE_ATTN_REPORTS);
}