diff options
author | Dudley Du <dudl@cypress.com> | 2015-01-18 01:18:14 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-01-18 03:10:33 -0500 |
commit | daceed1e8e57ce8ca57f5602296f2b8bc2f1c3e5 (patch) | |
tree | e2480bcaab50538395d5a76b603ac321223d3969 /drivers/input | |
parent | 6499d390a166c28fdd94eb6c71b309adb15ae826 (diff) |
Input: cyapa - add gen5 trackpad force re-calibrate function support
Add force re-calibrate function support for gen5 trackpad device, it can be
used through sysfs calibrate interface.
Signed-off-by: Dudley Du <dudl@cypress.com>
Tested-by: Jeremiah Mahler <jmmahler@gmail.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/mouse/cyapa_gen5.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c index 7c6e3393fef1..ced2a2c641cc 100644 --- a/drivers/input/mouse/cyapa_gen5.c +++ b/drivers/input/mouse/cyapa_gen5.c | |||
@@ -1715,6 +1715,70 @@ static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa) | |||
1715 | return 0; | 1715 | return 0; |
1716 | } | 1716 | } |
1717 | 1717 | ||
1718 | static int cyapa_gen5_calibrate_pwcs(struct cyapa *cyapa, | ||
1719 | u8 calibrate_sensing_mode_type) | ||
1720 | { | ||
1721 | struct gen5_app_cmd_head *app_cmd_head; | ||
1722 | u8 cmd[8]; | ||
1723 | u8 resp_data[6]; | ||
1724 | int resp_len; | ||
1725 | int error; | ||
1726 | |||
1727 | /* Try to dump all buffered data before doing command. */ | ||
1728 | cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); | ||
1729 | |||
1730 | memset(cmd, 0, sizeof(cmd)); | ||
1731 | app_cmd_head = (struct gen5_app_cmd_head *)cmd; | ||
1732 | put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &app_cmd_head->addr); | ||
1733 | put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length); | ||
1734 | app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; | ||
1735 | app_cmd_head->cmd_code = GEN5_CMD_CALIBRATE; | ||
1736 | app_cmd_head->parameter_data[0] = calibrate_sensing_mode_type; | ||
1737 | resp_len = sizeof(resp_data); | ||
1738 | error = cyapa_i2c_pip_cmd_irq_sync(cyapa, | ||
1739 | cmd, sizeof(cmd), | ||
1740 | resp_data, &resp_len, | ||
1741 | 5000, cyapa_gen5_sort_tsg_pip_app_resp_data, true); | ||
1742 | if (error || !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_CALIBRATE) || | ||
1743 | !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) | ||
1744 | return error < 0 ? error : -EAGAIN; | ||
1745 | |||
1746 | return 0; | ||
1747 | } | ||
1748 | |||
1749 | static ssize_t cyapa_gen5_do_calibrate(struct device *dev, | ||
1750 | struct device_attribute *attr, | ||
1751 | const char *buf, size_t count) | ||
1752 | { | ||
1753 | struct cyapa *cyapa = dev_get_drvdata(dev); | ||
1754 | int error, calibrate_error; | ||
1755 | |||
1756 | /* 1. Suspend Scanning*/ | ||
1757 | error = cyapa_gen5_suspend_scanning(cyapa); | ||
1758 | if (error) | ||
1759 | return error; | ||
1760 | |||
1761 | /* 2. Do mutual capacitance fine calibrate. */ | ||
1762 | calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa, | ||
1763 | CYAPA_SENSING_MODE_MUTUAL_CAP_FINE); | ||
1764 | if (calibrate_error) | ||
1765 | goto resume_scanning; | ||
1766 | |||
1767 | /* 3. Do self capacitance calibrate. */ | ||
1768 | calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa, | ||
1769 | CYAPA_SENSING_MODE_SELF_CAP); | ||
1770 | if (calibrate_error) | ||
1771 | goto resume_scanning; | ||
1772 | |||
1773 | resume_scanning: | ||
1774 | /* 4. Resume Scanning*/ | ||
1775 | error = cyapa_gen5_resume_scanning(cyapa); | ||
1776 | if (error || calibrate_error) | ||
1777 | return error ? error : calibrate_error; | ||
1778 | |||
1779 | return count; | ||
1780 | } | ||
1781 | |||
1718 | static s32 twos_complement_to_s32(s32 value, int num_bits) | 1782 | static s32 twos_complement_to_s32(s32 value, int num_bits) |
1719 | { | 1783 | { |
1720 | if (value >> (num_bits - 1)) | 1784 | if (value >> (num_bits - 1)) |
@@ -2696,6 +2760,7 @@ const struct cyapa_dev_ops cyapa_gen5_ops = { | |||
2696 | .bl_deactivate = cyapa_gen5_bl_deactivate, | 2760 | .bl_deactivate = cyapa_gen5_bl_deactivate, |
2697 | 2761 | ||
2698 | .show_baseline = cyapa_gen5_show_baseline, | 2762 | .show_baseline = cyapa_gen5_show_baseline, |
2763 | .calibrate_store = cyapa_gen5_do_calibrate, | ||
2699 | 2764 | ||
2700 | .initialize = cyapa_gen5_initialize, | 2765 | .initialize = cyapa_gen5_initialize, |
2701 | 2766 | ||