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

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>

authored by

David Herrmann and committed by
Jiri Kosina
b8e0fe31 701ba533

+320
+23
drivers/hid/hid-wiimote-core.c
··· 452 452 return WIIMOTE_EXT_CLASSIC_CONTROLLER; 453 453 if (rmem[4] == 0x04 && rmem[5] == 0x02) 454 454 return WIIMOTE_EXT_BALANCE_BOARD; 455 + if (rmem[4] == 0x01 && rmem[5] == 0x20) 456 + return WIIMOTE_EXT_PRO_CONTROLLER; 455 457 456 458 return WIIMOTE_EXT_UNKNOWN; 457 459 } ··· 600 598 [WIIMOTE_DEV_BALANCE_BOARD] = (const __u8[]) { 601 599 WIIMOD_BATTERY, 602 600 WIIMOD_LED1, 601 + WIIMOD_NO_MP, 602 + WIIMOD_NULL, 603 + }, 604 + [WIIMOTE_DEV_PRO_CONTROLLER] = (const __u8[]) { 605 + WIIMOD_BATTERY, 606 + WIIMOD_LED1, 607 + WIIMOD_LED2, 608 + WIIMOD_LED3, 609 + WIIMOD_LED4, 603 610 WIIMOD_NO_MP, 604 611 WIIMOD_NULL, 605 612 }, ··· 796 785 [WIIMOTE_DEV_GEN10] = "Nintendo Wii Remote (Gen 1)", 797 786 [WIIMOTE_DEV_GEN20] = "Nintendo Wii Remote Plus (Gen 2)", 798 787 [WIIMOTE_DEV_BALANCE_BOARD] = "Nintendo Wii Balance Board", 788 + [WIIMOTE_DEV_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller", 799 789 }; 800 790 801 791 /* Try to guess the device type based on all collected information. We ··· 817 805 if (exttype == WIIMOTE_EXT_BALANCE_BOARD) { 818 806 devtype = WIIMOTE_DEV_BALANCE_BOARD; 819 807 goto done; 808 + } else if (exttype == WIIMOTE_EXT_PRO_CONTROLLER) { 809 + devtype = WIIMOTE_DEV_PRO_CONTROLLER; 810 + goto done; 820 811 } 821 812 822 813 if (!strcmp(name, "Nintendo RVL-CNT-01")) { ··· 830 815 goto done; 831 816 } else if (!strcmp(name, "Nintendo RVL-WBC-01")) { 832 817 devtype = WIIMOTE_DEV_BALANCE_BOARD; 818 + goto done; 819 + } else if (!strcmp(name, "Nintendo RVL-CNT-01-UC")) { 820 + devtype = WIIMOTE_DEV_PRO_CONTROLLER; 833 821 goto done; 834 822 } 835 823 ··· 1076 1058 [WIIMOTE_EXT_NUNCHUK] = "Nintendo Wii Nunchuk", 1077 1059 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = "Nintendo Wii Classic Controller", 1078 1060 [WIIMOTE_EXT_BALANCE_BOARD] = "Nintendo Wii Balance Board", 1061 + [WIIMOTE_EXT_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller", 1079 1062 }; 1080 1063 1081 1064 /* ··· 1661 1642 return sprintf(buf, "classic\n"); 1662 1643 case WIIMOTE_EXT_BALANCE_BOARD: 1663 1644 return sprintf(buf, "balanceboard\n"); 1645 + case WIIMOTE_EXT_PRO_CONTROLLER: 1646 + return sprintf(buf, "procontroller\n"); 1664 1647 case WIIMOTE_EXT_UNKNOWN: 1665 1648 /* fallthrough */ 1666 1649 default: ··· 1709 1688 return sprintf(buf, "gen20\n"); 1710 1689 case WIIMOTE_DEV_BALANCE_BOARD: 1711 1690 return sprintf(buf, "balanceboard\n"); 1691 + case WIIMOTE_DEV_PRO_CONTROLLER: 1692 + return sprintf(buf, "procontroller\n"); 1712 1693 case WIIMOTE_DEV_PENDING: 1713 1694 return sprintf(buf, "pending\n"); 1714 1695 case WIIMOTE_DEV_UNKNOWN:
+295
drivers/hid/hid-wiimote-modules.c
··· 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 + 1552 + enum 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 + 1573 + static 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 + 1593 + static 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 + 1705 + static 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 + 1718 + static 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 + 1729 + static 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 + 1754 + static 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 + 1806 + err_free: 1807 + input_free_device(wdata->extension.input); 1808 + wdata->extension.input = NULL; 1809 + return ret; 1810 + } 1811 + 1812 + static 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 + 1828 + static 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 1837 * Builtin Motion Plus 1544 1838 * This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which 1545 1839 * disables polling for Motion-Plus. This should be set only for devices which ··· 2082 1788 [WIIMOTE_EXT_NUNCHUK] = &wiimod_nunchuk, 2083 1789 [WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic, 2084 1790 [WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard, 1791 + [WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro, 2085 1792 };
+2
drivers/hid/hid-wiimote.h
··· 77 77 WIIMOTE_DEV_GEN10, 78 78 WIIMOTE_DEV_GEN20, 79 79 WIIMOTE_DEV_BALANCE_BOARD, 80 + WIIMOTE_DEV_PRO_CONTROLLER, 80 81 WIIMOTE_DEV_NUM, 81 82 }; 82 83 ··· 87 86 WIIMOTE_EXT_NUNCHUK, 88 87 WIIMOTE_EXT_CLASSIC_CONTROLLER, 89 88 WIIMOTE_EXT_BALANCE_BOARD, 89 + WIIMOTE_EXT_PRO_CONTROLLER, 90 90 WIIMOTE_EXT_NUM, 91 91 }; 92 92