Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Nick Dyer and committed by
Dmitry Torokhov
1c0276d5 6544a1df

+26 -42
+26 -42
drivers/input/touchscreen/atmel_mxt_ts.c
··· 113 113 #define MXT_T9_DETECT (1 << 7) 114 114 115 115 struct t9_range { 116 - u16 x; 117 - u16 y; 116 + __le16 x; 117 + __le16 y; 118 118 } __packed; 119 119 120 120 /* MXT_TOUCH_MULTI_T9 orient */ ··· 216 216 unsigned int irq; 217 217 unsigned int max_x; 218 218 unsigned int max_y; 219 + bool xy_switch; 219 220 bool in_bootloader; 220 221 u16 mem_size; 221 222 u8 t100_aux_ampl; ··· 1666 1665 if (error) 1667 1666 return error; 1668 1667 1669 - le16_to_cpus(&range.x); 1670 - le16_to_cpus(&range.y); 1668 + data->max_x = get_unaligned_le16(&range.x); 1669 + data->max_y = get_unaligned_le16(&range.y); 1671 1670 1672 1671 error = __mxt_read_reg(client, 1673 1672 object->start_address + MXT_T9_ORIENT, ··· 1675 1674 if (error) 1676 1675 return error; 1677 1676 1678 - /* Handle default values */ 1679 - if (range.x == 0) 1680 - range.x = 1023; 1681 - 1682 - if (range.y == 0) 1683 - range.y = 1023; 1684 - 1685 - if (orient & MXT_T9_ORIENT_SWITCH) { 1686 - data->max_x = range.y; 1687 - data->max_y = range.x; 1688 - } else { 1689 - data->max_x = range.x; 1690 - data->max_y = range.y; 1691 - } 1692 - 1693 - dev_dbg(&client->dev, 1694 - "Touchscreen size X%uY%u\n", data->max_x, data->max_y); 1677 + data->xy_switch = orient & MXT_T9_ORIENT_SWITCH; 1695 1678 1696 1679 return 0; 1697 1680 } ··· 1693 1708 if (!object) 1694 1709 return -EINVAL; 1695 1710 1711 + /* read touchscreen dimensions */ 1696 1712 error = __mxt_read_reg(client, 1697 1713 object->start_address + MXT_T100_XRANGE, 1698 1714 sizeof(range_x), &range_x); 1699 1715 if (error) 1700 1716 return error; 1701 1717 1702 - le16_to_cpus(&range_x); 1718 + data->max_x = get_unaligned_le16(&range_x); 1703 1719 1704 1720 error = __mxt_read_reg(client, 1705 1721 object->start_address + MXT_T100_YRANGE, ··· 1708 1722 if (error) 1709 1723 return error; 1710 1724 1711 - le16_to_cpus(&range_y); 1725 + data->max_y = get_unaligned_le16(&range_y); 1712 1726 1727 + /* read orientation config */ 1713 1728 error = __mxt_read_reg(client, 1714 1729 object->start_address + MXT_T100_CFG1, 1715 1730 1, &cfg); 1716 1731 if (error) 1717 1732 return error; 1718 1733 1734 + data->xy_switch = cfg & MXT_T100_CFG_SWITCHXY; 1735 + 1736 + /* allocate aux bytes */ 1719 1737 error = __mxt_read_reg(client, 1720 1738 object->start_address + MXT_T100_TCHAUX, 1721 1739 1, &tchaux); 1722 1740 if (error) 1723 1741 return error; 1724 1742 1725 - /* Handle default values */ 1726 - if (range_x == 0) 1727 - range_x = 1023; 1728 - 1729 - if (range_y == 0) 1730 - range_y = 1023; 1731 - 1732 - if (cfg & MXT_T100_CFG_SWITCHXY) { 1733 - data->max_x = range_y; 1734 - data->max_y = range_x; 1735 - } else { 1736 - data->max_x = range_x; 1737 - data->max_y = range_y; 1738 - } 1739 - 1740 - /* allocate aux bytes */ 1741 1743 aux = 6; 1742 1744 1743 1745 if (tchaux & MXT_T100_TCHAUX_VECT) ··· 1740 1766 dev_dbg(&client->dev, 1741 1767 "T100 aux mappings vect:%u ampl:%u area:%u\n", 1742 1768 data->t100_aux_vect, data->t100_aux_ampl, data->t100_aux_area); 1743 - 1744 - dev_info(&client->dev, 1745 - "T100 Touchscreen size X%uY%u\n", data->max_x, data->max_y); 1746 1769 1747 1770 return 0; 1748 1771 } ··· 1799 1828 return -EINVAL; 1800 1829 } 1801 1830 1831 + /* Handle default values and orientation switch */ 1832 + if (data->max_x == 0) 1833 + data->max_x = 1023; 1834 + 1835 + if (data->max_y == 0) 1836 + data->max_y = 1023; 1837 + 1838 + if (data->xy_switch) 1839 + swap(data->max_x, data->max_y); 1840 + 1841 + dev_info(dev, "Touchscreen size X%uY%u\n", data->max_x, data->max_y); 1842 + 1843 + /* Register input device */ 1802 1844 input_dev = input_allocate_device(); 1803 1845 if (!input_dev) { 1804 1846 dev_err(dev, "Failed to allocate memory\n");