Lines Matching defs:ccp
90 static int ccp_get_errno(struct ccp_device *ccp)
92 switch (ccp->buffer[0]) {
103 hid_dbg(ccp->hdev, "unknown device response error: %d", ccp->buffer[0]);
108 /* send command, check for error in response, response in ccp->buffer */
109 static int send_usb_cmd(struct ccp_device *ccp, u8 command, u8 byte1, u8 byte2, u8 byte3)
114 memset(ccp->buffer, 0x00, OUT_BUFFER_SIZE);
115 ccp->buffer[0] = command;
116 ccp->buffer[1] = byte1;
117 ccp->buffer[2] = byte2;
118 ccp->buffer[3] = byte3;
120 reinit_completion(&ccp->wait_input_report);
122 ret = hid_hw_output_report(ccp->hdev, ccp->buffer, OUT_BUFFER_SIZE);
126 t = wait_for_completion_timeout(&ccp->wait_input_report, msecs_to_jiffies(REQ_TIMEOUT));
130 return ccp_get_errno(ccp);
135 struct ccp_device *ccp = hid_get_drvdata(hdev);
138 if (completion_done(&ccp->wait_input_report))
141 memcpy(ccp->buffer, data, min(IN_BUFFER_SIZE, size));
142 complete(&ccp->wait_input_report);
148 static int get_data(struct ccp_device *ccp, int command, int channel, bool two_byte_data)
152 mutex_lock(&ccp->mutex);
154 ret = send_usb_cmd(ccp, command, channel, 0, 0);
158 ret = ccp->buffer[1];
160 ret = (ret << 8) + ccp->buffer[2];
163 mutex_unlock(&ccp->mutex);
167 static int set_pwm(struct ccp_device *ccp, int channel, long val)
177 mutex_lock(&ccp->mutex);
179 ret = send_usb_cmd(ccp, CTL_SET_FAN_FPWM, channel, val, 0);
181 ccp->target[channel] = -ENODATA;
183 mutex_unlock(&ccp->mutex);
187 static int set_target(struct ccp_device *ccp, int channel, long val)
192 ccp->target[channel] = val;
194 mutex_lock(&ccp->mutex);
195 ret = send_usb_cmd(ccp, CTL_SET_FAN_TARGET, channel, val >> 8, val);
197 mutex_unlock(&ccp->mutex);
204 struct ccp_device *ccp = dev_get_drvdata(dev);
210 *str = ccp->fan_label[channel];
226 struct ccp_device *ccp = dev_get_drvdata(dev);
233 ret = get_data(ccp, CTL_GET_TMP, channel, true);
245 ret = get_data(ccp, CTL_GET_FAN_RPM, channel, true);
253 if (ccp->target[channel] < 0)
255 *val = ccp->target[channel];
264 ret = get_data(ccp, CTL_GET_FAN_PWM, channel, false);
276 ret = get_data(ccp, CTL_GET_VOLT, channel, true);
295 struct ccp_device *ccp = dev_get_drvdata(dev);
301 return set_pwm(ccp, channel, val);
309 return set_target(ccp, channel, val);
324 const struct ccp_device *ccp = data;
328 if (!test_bit(channel, ccp->temp_cnct))
341 if (!test_bit(channel, ccp->fan_cnct))
356 if (!test_bit(channel, ccp->fan_cnct))
427 static int get_fan_cnct(struct ccp_device *ccp)
433 ret = send_usb_cmd(ccp, CTL_GET_FAN_CNCT, 0, 0, 0);
438 mode = ccp->buffer[channel + 1];
442 set_bit(channel, ccp->fan_cnct);
443 ccp->target[channel] = -ENODATA;
447 scnprintf(ccp->fan_label[channel], LABEL_LENGTH,
451 scnprintf(ccp->fan_label[channel], LABEL_LENGTH,
455 scnprintf(ccp->fan_label[channel], LABEL_LENGTH,
465 static int get_temp_cnct(struct ccp_device *ccp)
471 ret = send_usb_cmd(ccp, CTL_GET_TMP_CNCT, 0, 0, 0);
476 mode = ccp->buffer[channel + 1];
480 set_bit(channel, ccp->temp_cnct);
488 struct ccp_device *ccp;
491 ccp = devm_kzalloc(&hdev->dev, sizeof(*ccp), GFP_KERNEL);
492 if (!ccp)
495 ccp->buffer = devm_kmalloc(&hdev->dev, OUT_BUFFER_SIZE, GFP_KERNEL);
496 if (!ccp->buffer)
511 ccp->hdev = hdev;
512 hid_set_drvdata(hdev, ccp);
513 mutex_init(&ccp->mutex);
514 init_completion(&ccp->wait_input_report);
519 ret = get_temp_cnct(ccp);
523 ret = get_fan_cnct(ccp);
526 ccp->hwmon_dev = hwmon_device_register_with_info(&hdev->dev, "corsaircpro",
527 ccp, &ccp_chip_info, 0);
528 if (IS_ERR(ccp->hwmon_dev)) {
529 ret = PTR_ERR(ccp->hwmon_dev);
544 struct ccp_device *ccp = hid_get_drvdata(hdev);
546 hwmon_device_unregister(ccp->hwmon_dev);