diff options
| author | Nick Dyer <nick.dyer@itdev.co.uk> | 2016-01-10 21:29:34 -0500 |
|---|---|---|
| committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2016-01-11 20:48:57 -0500 |
| commit | 1c0276d56737bd29b6d960611b625710c5cda080 (patch) | |
| tree | 6cc3f493f529acb7f89f420a8cd0362ed0a23715 /drivers/input | |
| parent | 6544a1df11c48c8413071aac3316792e4678fbfb (diff) | |
Input: atmel_mxt_ts - improve touchscreen size/orientation handling
Both T100 and T9 handle range and orientation in a similar fashion.
Reduce duplication between the two implementations.
Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
| -rw-r--r-- | drivers/input/touchscreen/atmel_mxt_ts.c | 68 |
1 files changed, 26 insertions, 42 deletions
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index c5622058c22b..4a1d218f883b 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c | |||
| @@ -113,8 +113,8 @@ struct t7_config { | |||
| 113 | #define MXT_T9_DETECT (1 << 7) | 113 | #define MXT_T9_DETECT (1 << 7) |
| 114 | 114 | ||
| 115 | struct t9_range { | 115 | struct t9_range { |
| 116 | u16 x; | 116 | __le16 x; |
| 117 | u16 y; | 117 | __le16 y; |
| 118 | } __packed; | 118 | } __packed; |
| 119 | 119 | ||
| 120 | /* MXT_TOUCH_MULTI_T9 orient */ | 120 | /* MXT_TOUCH_MULTI_T9 orient */ |
| @@ -216,6 +216,7 @@ struct mxt_data { | |||
| 216 | unsigned int irq; | 216 | unsigned int irq; |
| 217 | unsigned int max_x; | 217 | unsigned int max_x; |
| 218 | unsigned int max_y; | 218 | unsigned int max_y; |
| 219 | bool xy_switch; | ||
| 219 | bool in_bootloader; | 220 | bool in_bootloader; |
| 220 | u16 mem_size; | 221 | u16 mem_size; |
| 221 | u8 t100_aux_ampl; | 222 | u8 t100_aux_ampl; |
| @@ -1665,8 +1666,8 @@ static int mxt_read_t9_resolution(struct mxt_data *data) | |||
| 1665 | if (error) | 1666 | if (error) |
| 1666 | return error; | 1667 | return error; |
| 1667 | 1668 | ||
| 1668 | le16_to_cpus(&range.x); | 1669 | data->max_x = get_unaligned_le16(&range.x); |
| 1669 | le16_to_cpus(&range.y); | 1670 | data->max_y = get_unaligned_le16(&range.y); |
| 1670 | 1671 | ||
| 1671 | error = __mxt_read_reg(client, | 1672 | error = __mxt_read_reg(client, |
| 1672 | object->start_address + MXT_T9_ORIENT, | 1673 | object->start_address + MXT_T9_ORIENT, |
| @@ -1674,23 +1675,7 @@ static int mxt_read_t9_resolution(struct mxt_data *data) | |||
| 1674 | if (error) | 1675 | if (error) |
| 1675 | return error; | 1676 | return error; |
| 1676 | 1677 | ||
| 1677 | /* Handle default values */ | 1678 | data->xy_switch = orient & MXT_T9_ORIENT_SWITCH; |
| 1678 | if (range.x == 0) | ||
| 1679 | range.x = 1023; | ||
| 1680 | |||
| 1681 | if (range.y == 0) | ||
| 1682 | range.y = 1023; | ||
| 1683 | |||
| 1684 | if (orient & MXT_T9_ORIENT_SWITCH) { | ||
| 1685 | data->max_x = range.y; | ||
| 1686 | data->max_y = range.x; | ||
| 1687 | } else { | ||
| 1688 | data->max_x = range.x; | ||
| 1689 | data->max_y = range.y; | ||
| 1690 | } | ||
| 1691 | |||
| 1692 | dev_dbg(&client->dev, | ||
| 1693 | "Touchscreen size X%uY%u\n", data->max_x, data->max_y); | ||
| 1694 | 1679 | ||
| 1695 | return 0; | 1680 | return 0; |
| 1696 | } | 1681 | } |
| @@ -1708,13 +1693,14 @@ static int mxt_read_t100_config(struct mxt_data *data) | |||
| 1708 | if (!object) | 1693 | if (!object) |
| 1709 | return -EINVAL; | 1694 | return -EINVAL; |
| 1710 | 1695 | ||
| 1696 | /* read touchscreen dimensions */ | ||
| 1711 | error = __mxt_read_reg(client, | 1697 | error = __mxt_read_reg(client, |
| 1712 | object->start_address + MXT_T100_XRANGE, | 1698 | object->start_address + MXT_T100_XRANGE, |
| 1713 | sizeof(range_x), &range_x); | 1699 | sizeof(range_x), &range_x); |
| 1714 | if (error) | 1700 | if (error) |
| 1715 | return error; | 1701 | return error; |
| 1716 | 1702 | ||
| 1717 | le16_to_cpus(&range_x); | 1703 | data->max_x = get_unaligned_le16(&range_x); |
| 1718 | 1704 | ||
| 1719 | error = __mxt_read_reg(client, | 1705 | error = __mxt_read_reg(client, |
| 1720 | object->start_address + MXT_T100_YRANGE, | 1706 | object->start_address + MXT_T100_YRANGE, |
| @@ -1722,36 +1708,24 @@ static int mxt_read_t100_config(struct mxt_data *data) | |||
| 1722 | if (error) | 1708 | if (error) |
| 1723 | return error; | 1709 | return error; |
| 1724 | 1710 | ||
| 1725 | le16_to_cpus(&range_y); | 1711 | data->max_y = get_unaligned_le16(&range_y); |
| 1726 | 1712 | ||
| 1713 | /* read orientation config */ | ||
| 1727 | error = __mxt_read_reg(client, | 1714 | error = __mxt_read_reg(client, |
| 1728 | object->start_address + MXT_T100_CFG1, | 1715 | object->start_address + MXT_T100_CFG1, |
| 1729 | 1, &cfg); | 1716 | 1, &cfg); |
| 1730 | if (error) | 1717 | if (error) |
| 1731 | return error; | 1718 | return error; |
| 1732 | 1719 | ||
| 1720 | data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY; | ||
| 1721 | |||
| 1722 | /* allocate aux bytes */ | ||
| 1733 | error = __mxt_read_reg(client, | 1723 | error = __mxt_read_reg(client, |
| 1734 | object->start_address + MXT_T100_TCHAUX, | 1724 | object->start_address + MXT_T100_TCHAUX, |
| 1735 | 1, &tchaux); | 1725 | 1, &tchaux); |
| 1736 | if (error) | 1726 | if (error) |
| 1737 | return error; | 1727 | return error; |
| 1738 | 1728 | ||
| 1739 | /* Handle default values */ | ||
| 1740 | if (range_x == 0) | ||
| 1741 | range_x = 1023; | ||
| 1742 | |||
| 1743 | if (range_y == 0) | ||
| 1744 | range_y = 1023; | ||
| 1745 | |||
| 1746 | if (cfg & MXT_T100_CFG_SWITCHXY) { | ||
| 1747 | data->max_x = range_y; | ||
| 1748 | data->max_y = range_x; | ||
| 1749 | } else { | ||
| 1750 | data->max_x = range_x; | ||
| 1751 | data->max_y = range_y; | ||
| 1752 | } | ||
| 1753 | |||
| 1754 | /* allocate aux bytes */ | ||
| 1755 | aux = 6; | 1729 | aux = 6; |
| 1756 | 1730 | ||
| 1757 | if (tchaux & MXT_T100_TCHAUX_VECT) | 1731 | if (tchaux & MXT_T100_TCHAUX_VECT) |
| @@ -1767,9 +1741,6 @@ static int mxt_read_t100_config(struct mxt_data *data) | |||
| 1767 | "T100 aux mappings vect:%u ampl:%u area:%u\n", | 1741 | "T100 aux mappings vect:%u ampl:%u area:%u\n", |
| 1768 | data->t100_aux_vect, data->t100_aux_ampl, data->t100_aux_area); | 1742 | data->t100_aux_vect, data->t100_aux_ampl, data->t100_aux_area); |
| 1769 | 1743 | ||
| 1770 | dev_info(&client->dev, | ||
| 1771 | "T100 Touchscreen size X%uY%u\n", data->max_x, data->max_y); | ||
| 1772 | |||
| 1773 | return 0; | 1744 | return 0; |
| 1774 | } | 1745 | } |
| 1775 | 1746 | ||
| @@ -1828,6 +1799,19 @@ static int mxt_initialize_input_device(struct mxt_data *data) | |||
| 1828 | return -EINVAL; | 1799 | return -EINVAL; |
| 1829 | } | 1800 | } |
| 1830 | 1801 | ||
| 1802 | /* Handle default values and orientation switch */ | ||
| 1803 | if (data->max_x == 0) | ||
| 1804 | data->max_x = 1023; | ||
| 1805 | |||
| 1806 | if (data->max_y == 0) | ||
| 1807 | data->max_y = 1023; | ||
| 1808 | |||
| 1809 | if (data->xy_switch) | ||
| 1810 | swap(data->max_x, data->max_y); | ||
| 1811 | |||
| 1812 | dev_info(dev, "Touchscreen size X%uY%u\n", data->max_x, data->max_y); | ||
| 1813 | |||
| 1814 | /* Register input device */ | ||
| 1831 | input_dev = input_allocate_device(); | 1815 | input_dev = input_allocate_device(); |
| 1832 | if (!input_dev) { | 1816 | if (!input_dev) { |
| 1833 | dev_err(dev, "Failed to allocate memory\n"); | 1817 | dev_err(dev, "Failed to allocate memory\n"); |
