aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-wiimote-modules.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-06-15 09:32:45 -0400
committerJiri Kosina <jkosina@suse.cz>2013-06-27 05:57:49 -0400
commitb8e0fe31a7c8623741f91bc27f925220341fdf81 (patch)
tree9dd36399fd722510dfe06c46ca5c9a74850f979d /drivers/hid/hid-wiimote-modules.c
parent701ba533f6587aaf402a9bb732548503263d2b23 (diff)
HID: wiimote: support Nintendo Wii U Pro Controller
The Wii U Pro Controller is a new Nintendo remote device that looks very similar to the XBox controller. It has nearly the same features and uses the same protocol as the Wii Remote. We add a new wiimote extension device so the Pro Controller is properly detected and supported. The device reports MP support, which is odd and I couldn't get it working, yet. Hence, we disable MP registers for now. Further investigation is needed to see what extra capabilities are provided. There are some other unknown bits in the extension reports that I couldn't figure out what they do. You can use hidraw to access these if you're interested. We might want to hook up the "charging" and "USB" bits to the battery device so user-space can query whether it is currently charged via USB. Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-wiimote-modules.c')
-rw-r--r--drivers/hid/hid-wiimote-modules.c295
1 files changed, 295 insertions, 0 deletions
diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
index 68f67f08d5dc..2e7d644dba18 100644
--- a/drivers/hid/hid-wiimote-modules.c
+++ b/drivers/hid/hid-wiimote-modules.c
@@ -1540,6 +1540,300 @@ static const struct wiimod_ops wiimod_bboard = {
1540}; 1540};
1541 1541
1542/* 1542/*
1543 * Pro Controller
1544 * Released with the Wii U was the Nintendo Wii U Pro Controller. It does not
1545 * work together with the classic Wii, but only with the new Wii U. However, it
1546 * uses the same protocol and provides a builtin "classic controller pro"
1547 * extension, few standard buttons, a rumble motor, 4 LEDs and a battery.
1548 * We provide all these via a standard extension device as the device doesn't
1549 * feature an extension port.
1550 */
1551
1552enum wiimod_pro_keys {
1553 WIIMOD_PRO_KEY_A,
1554 WIIMOD_PRO_KEY_B,
1555 WIIMOD_PRO_KEY_X,
1556 WIIMOD_PRO_KEY_Y,
1557 WIIMOD_PRO_KEY_PLUS,
1558 WIIMOD_PRO_KEY_MINUS,
1559 WIIMOD_PRO_KEY_HOME,
1560 WIIMOD_PRO_KEY_LEFT,
1561 WIIMOD_PRO_KEY_RIGHT,
1562 WIIMOD_PRO_KEY_UP,
1563 WIIMOD_PRO_KEY_DOWN,
1564 WIIMOD_PRO_KEY_TL,
1565 WIIMOD_PRO_KEY_TR,
1566 WIIMOD_PRO_KEY_ZL,
1567 WIIMOD_PRO_KEY_ZR,
1568 WIIMOD_PRO_KEY_THUMBL,
1569 WIIMOD_PRO_KEY_THUMBR,
1570 WIIMOD_PRO_KEY_NUM,
1571};
1572
1573static const __u16 wiimod_pro_map[] = {
1574 BTN_EAST, /* WIIMOD_PRO_KEY_A */
1575 BTN_SOUTH, /* WIIMOD_PRO_KEY_B */
1576 BTN_NORTH, /* WIIMOD_PRO_KEY_X */
1577 BTN_WEST, /* WIIMOD_PRO_KEY_Y */
1578 BTN_START, /* WIIMOD_PRO_KEY_PLUS */
1579 BTN_SELECT, /* WIIMOD_PRO_KEY_MINUS */
1580 BTN_MODE, /* WIIMOD_PRO_KEY_HOME */
1581 BTN_DPAD_LEFT, /* WIIMOD_PRO_KEY_LEFT */
1582 BTN_DPAD_RIGHT, /* WIIMOD_PRO_KEY_RIGHT */
1583 BTN_DPAD_UP, /* WIIMOD_PRO_KEY_UP */
1584 BTN_DPAD_DOWN, /* WIIMOD_PRO_KEY_DOWN */
1585 BTN_TL, /* WIIMOD_PRO_KEY_TL */
1586 BTN_TR, /* WIIMOD_PRO_KEY_TR */
1587 BTN_TL2, /* WIIMOD_PRO_KEY_ZL */
1588 BTN_TR2, /* WIIMOD_PRO_KEY_ZR */
1589 BTN_THUMBL, /* WIIMOD_PRO_KEY_THUMBL */
1590 BTN_THUMBR, /* WIIMOD_PRO_KEY_THUMBR */
1591};
1592
1593static void wiimod_pro_in_ext(struct wiimote_data *wdata, const __u8 *ext)
1594{
1595 __s16 rx, ry, lx, ly;
1596
1597 /* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
1598 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1599 * 1 | LX <7:0> |
1600 * -----+-----------------------+-----------------------+
1601 * 2 | 0 0 0 0 | LX <11:8> |
1602 * -----+-----------------------+-----------------------+
1603 * 3 | RX <7:0> |
1604 * -----+-----------------------+-----------------------+
1605 * 4 | 0 0 0 0 | RX <11:8> |
1606 * -----+-----------------------+-----------------------+
1607 * 5 | LY <7:0> |
1608 * -----+-----------------------+-----------------------+
1609 * 6 | 0 0 0 0 | LY <11:8> |
1610 * -----+-----------------------+-----------------------+
1611 * 7 | RY <7:0> |
1612 * -----+-----------------------+-----------------------+
1613 * 8 | 0 0 0 0 | RY <11:8> |
1614 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1615 * 9 | BDR | BDD | BLT | B- | BH | B+ | BRT | 1 |
1616 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1617 * 10 | BZL | BB | BY | BA | BX | BZR | BDL | BDU |
1618 * -----+-----+-----+-----+-----+-----+-----+-----+-----+
1619 * 11 | 1 | BATTERY | USB |CHARG|LTHUM|RTHUM|
1620 * -----+-----+-----------------+-----------+-----+-----+
1621 * All buttons are low-active (0 if pressed)
1622 * RX and RY are right analog stick
1623 * LX and LY are left analog stick
1624 * BLT is left trigger, BRT is right trigger.
1625 * BDR, BDD, BDL, BDU form the D-Pad with right, down, left, up buttons
1626 * BZL is left Z button and BZR is right Z button
1627 * B-, BH, B+ are +, HOME and - buttons
1628 * BB, BY, BA, BX are A, B, X, Y buttons
1629 *
1630 * Bits marked as 0/1 are unknown and never changed during tests.
1631 *
1632 * Not entirely verified:
1633 * CHARG: 1 if uncharging, 0 if charging
1634 * USB: 1 if not connected, 0 if connected
1635 * BATTERY: battery capacity from 000 (empty) to 100 (full)
1636 */
1637
1638 lx = (ext[0] & 0xff) | ((ext[1] & 0x0f) << 8);
1639 rx = (ext[2] & 0xff) | ((ext[3] & 0x0f) << 8);
1640 ly = (ext[4] & 0xff) | ((ext[5] & 0x0f) << 8);
1641 ry = (ext[6] & 0xff) | ((ext[7] & 0x0f) << 8);
1642
1643 input_report_abs(wdata->extension.input, ABS_X, lx - 0x800);
1644 input_report_abs(wdata->extension.input, ABS_Y, ly - 0x800);
1645 input_report_abs(wdata->extension.input, ABS_RX, rx - 0x800);
1646 input_report_abs(wdata->extension.input, ABS_RY, ry - 0x800);
1647
1648 input_report_key(wdata->extension.input,
1649 wiimod_pro_map[WIIMOD_PRO_KEY_RIGHT],
1650 !(ext[8] & 0x80));
1651 input_report_key(wdata->extension.input,
1652 wiimod_pro_map[WIIMOD_PRO_KEY_DOWN],
1653 !(ext[8] & 0x40));
1654 input_report_key(wdata->extension.input,
1655 wiimod_pro_map[WIIMOD_PRO_KEY_TL],
1656 !(ext[8] & 0x20));
1657 input_report_key(wdata->extension.input,
1658 wiimod_pro_map[WIIMOD_PRO_KEY_MINUS],
1659 !(ext[8] & 0x10));
1660 input_report_key(wdata->extension.input,
1661 wiimod_pro_map[WIIMOD_PRO_KEY_HOME],
1662 !(ext[8] & 0x08));
1663 input_report_key(wdata->extension.input,
1664 wiimod_pro_map[WIIMOD_PRO_KEY_PLUS],
1665 !(ext[8] & 0x04));
1666 input_report_key(wdata->extension.input,
1667 wiimod_pro_map[WIIMOD_PRO_KEY_TR],
1668 !(ext[8] & 0x02));
1669
1670 input_report_key(wdata->extension.input,
1671 wiimod_pro_map[WIIMOD_PRO_KEY_ZL],
1672 !(ext[9] & 0x80));
1673 input_report_key(wdata->extension.input,
1674 wiimod_pro_map[WIIMOD_PRO_KEY_B],
1675 !(ext[9] & 0x40));
1676 input_report_key(wdata->extension.input,
1677 wiimod_pro_map[WIIMOD_PRO_KEY_Y],
1678 !(ext[9] & 0x20));
1679 input_report_key(wdata->extension.input,
1680 wiimod_pro_map[WIIMOD_PRO_KEY_A],
1681 !(ext[9] & 0x10));
1682 input_report_key(wdata->extension.input,
1683 wiimod_pro_map[WIIMOD_PRO_KEY_X],
1684 !(ext[9] & 0x08));
1685 input_report_key(wdata->extension.input,
1686 wiimod_pro_map[WIIMOD_PRO_KEY_ZR],
1687 !(ext[9] & 0x04));
1688 input_report_key(wdata->extension.input,
1689 wiimod_pro_map[WIIMOD_PRO_KEY_LEFT],
1690 !(ext[9] & 0x02));
1691 input_report_key(wdata->extension.input,
1692 wiimod_pro_map[WIIMOD_PRO_KEY_UP],
1693 !(ext[9] & 0x01));
1694
1695 input_report_key(wdata->extension.input,
1696 wiimod_pro_map[WIIMOD_PRO_KEY_THUMBL],
1697 !(ext[10] & 0x02));
1698 input_report_key(wdata->extension.input,
1699 wiimod_pro_map[WIIMOD_PRO_KEY_THUMBR],
1700 !(ext[10] & 0x01));
1701
1702 input_sync(wdata->extension.input);
1703}
1704
1705static int wiimod_pro_open(struct input_dev *dev)
1706{
1707 struct wiimote_data *wdata = input_get_drvdata(dev);
1708 unsigned long flags;
1709
1710 spin_lock_irqsave(&wdata->state.lock, flags);
1711 wdata->state.flags |= WIIPROTO_FLAG_EXT_USED;
1712 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1713 spin_unlock_irqrestore(&wdata->state.lock, flags);
1714
1715 return 0;
1716}
1717
1718static void wiimod_pro_close(struct input_dev *dev)
1719{
1720 struct wiimote_data *wdata = input_get_drvdata(dev);
1721 unsigned long flags;
1722
1723 spin_lock_irqsave(&wdata->state.lock, flags);
1724 wdata->state.flags &= ~WIIPROTO_FLAG_EXT_USED;
1725 wiiproto_req_drm(wdata, WIIPROTO_REQ_NULL);
1726 spin_unlock_irqrestore(&wdata->state.lock, flags);
1727}
1728
1729static int wiimod_pro_play(struct input_dev *dev, void *data,
1730 struct ff_effect *eff)
1731{
1732 struct wiimote_data *wdata = input_get_drvdata(dev);
1733 __u8 value;
1734 unsigned long flags;
1735
1736 /*
1737 * The wiimote supports only a single rumble motor so if any magnitude
1738 * is set to non-zero then we start the rumble motor. If both are set to
1739 * zero, we stop the rumble motor.
1740 */
1741
1742 if (eff->u.rumble.strong_magnitude || eff->u.rumble.weak_magnitude)
1743 value = 1;
1744 else
1745 value = 0;
1746
1747 spin_lock_irqsave(&wdata->state.lock, flags);
1748 wiiproto_req_rumble(wdata, value);
1749 spin_unlock_irqrestore(&wdata->state.lock, flags);
1750
1751 return 0;
1752}
1753
1754static int wiimod_pro_probe(const struct wiimod_ops *ops,
1755 struct wiimote_data *wdata)
1756{
1757 int ret, i;
1758
1759 wdata->extension.input = input_allocate_device();
1760 if (!wdata->extension.input)
1761 return -ENOMEM;
1762
1763 set_bit(FF_RUMBLE, wdata->extension.input->ffbit);
1764 input_set_drvdata(wdata->extension.input, wdata);
1765
1766 if (input_ff_create_memless(wdata->extension.input, NULL,
1767 wiimod_pro_play)) {
1768 ret = -ENOMEM;
1769 goto err_free;
1770 }
1771
1772 wdata->extension.input->open = wiimod_pro_open;
1773 wdata->extension.input->close = wiimod_pro_close;
1774 wdata->extension.input->dev.parent = &wdata->hdev->dev;
1775 wdata->extension.input->id.bustype = wdata->hdev->bus;
1776 wdata->extension.input->id.vendor = wdata->hdev->vendor;
1777 wdata->extension.input->id.product = wdata->hdev->product;
1778 wdata->extension.input->id.version = wdata->hdev->version;
1779 wdata->extension.input->name = WIIMOTE_NAME " Pro Controller";
1780
1781 set_bit(EV_KEY, wdata->extension.input->evbit);
1782 for (i = 0; i < WIIMOD_PRO_KEY_NUM; ++i)
1783 set_bit(wiimod_pro_map[i],
1784 wdata->extension.input->keybit);
1785
1786 set_bit(EV_ABS, wdata->extension.input->evbit);
1787 set_bit(ABS_X, wdata->extension.input->absbit);
1788 set_bit(ABS_Y, wdata->extension.input->absbit);
1789 set_bit(ABS_RX, wdata->extension.input->absbit);
1790 set_bit(ABS_RY, wdata->extension.input->absbit);
1791 input_set_abs_params(wdata->extension.input,
1792 ABS_X, -0x800, 0x800, 2, 4);
1793 input_set_abs_params(wdata->extension.input,
1794 ABS_Y, -0x800, 0x800, 2, 4);
1795 input_set_abs_params(wdata->extension.input,
1796 ABS_RX, -0x800, 0x800, 2, 4);
1797 input_set_abs_params(wdata->extension.input,
1798 ABS_RY, -0x800, 0x800, 2, 4);
1799
1800 ret = input_register_device(wdata->extension.input);
1801 if (ret)
1802 goto err_free;
1803
1804 return 0;
1805
1806err_free:
1807 input_free_device(wdata->extension.input);
1808 wdata->extension.input = NULL;
1809 return ret;
1810}
1811
1812static void wiimod_pro_remove(const struct wiimod_ops *ops,
1813 struct wiimote_data *wdata)
1814{
1815 unsigned long flags;
1816
1817 if (!wdata->extension.input)
1818 return;
1819
1820 spin_lock_irqsave(&wdata->state.lock, flags);
1821 wiiproto_req_rumble(wdata, 0);
1822 spin_unlock_irqrestore(&wdata->state.lock, flags);
1823
1824 input_unregister_device(wdata->extension.input);
1825 wdata->extension.input = NULL;
1826}
1827
1828static const struct wiimod_ops wiimod_pro = {
1829 .flags = WIIMOD_FLAG_EXT16,
1830 .arg = 0,
1831 .probe = wiimod_pro_probe,
1832 .remove = wiimod_pro_remove,
1833 .in_ext = wiimod_pro_in_ext,
1834};
1835
1836/*
1543 * Builtin Motion Plus 1837 * Builtin Motion Plus
1544 * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which 1838 * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which
1545 * disables polling for Motion-Plus. This should be set only for devices which 1839 * disables polling for Motion-Plus. This should be set only for devices which
@@ -1788,4 +2082,5 @@ const struct wiimod_ops *wiimod_ext_table[WIIMOTE_EXT_NUM] = {
1788 [WIIMOTE_EXT_NUNCHUK] = &wiimod_nunchuk, 2082 [WIIMOTE_EXT_NUNCHUK] = &wiimod_nunchuk,
1789 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic, 2083 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic,
1790 [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard, 2084 [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard,
2085 [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro,
1791}; 2086};