Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b8e0fe3

Browse files
David HerrmannJiri Kosina
authored andcommitted
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 <[email protected]>
1 parent 701ba53 commit b8e0fe3

File tree

3 files changed

+320
-0
lines changed

3 files changed

+320
-0
lines changed

drivers/hid/hid-wiimote-core.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ static __u8 wiimote_cmd_read_ext(struct wiimote_data *wdata, __u8 *rmem)
452452
return WIIMOTE_EXT_CLASSIC_CONTROLLER;
453453
if (rmem[4] == 0x04 && rmem[5] == 0x02)
454454
return WIIMOTE_EXT_BALANCE_BOARD;
455+
if (rmem[4] == 0x01 && rmem[5] == 0x20)
456+
return WIIMOTE_EXT_PRO_CONTROLLER;
455457

456458
return WIIMOTE_EXT_UNKNOWN;
457459
}
@@ -601,6 +603,15 @@ static const __u8 * const wiimote_devtype_mods[WIIMOTE_DEV_NUM] = {
601603
WIIMOD_NO_MP,
602604
WIIMOD_NULL,
603605
},
606+
[WIIMOTE_DEV_PRO_CONTROLLER] = (const __u8[]) {
607+
WIIMOD_BATTERY,
608+
WIIMOD_LED1,
609+
WIIMOD_LED2,
610+
WIIMOD_LED3,
611+
WIIMOD_LED4,
612+
WIIMOD_NO_MP,
613+
WIIMOD_NULL,
614+
},
604615
};
605616

606617
static void wiimote_modules_load(struct wiimote_data *wdata,
@@ -785,6 +796,7 @@ static const char *wiimote_devtype_names[WIIMOTE_DEV_NUM] = {
785796
[WIIMOTE_DEV_GEN10] = "Nintendo Wii Remote (Gen 1)",
786797
[WIIMOTE_DEV_GEN20] = "Nintendo Wii Remote Plus (Gen 2)",
787798
[WIIMOTE_DEV_BALANCE_BOARD] = "Nintendo Wii Balance Board",
799+
[WIIMOTE_DEV_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller",
788800
};
789801

790802
/* Try to guess the device type based on all collected information. We
@@ -805,6 +817,9 @@ static void wiimote_init_set_type(struct wiimote_data *wdata,
805817
if (exttype == WIIMOTE_EXT_BALANCE_BOARD) {
806818
devtype = WIIMOTE_DEV_BALANCE_BOARD;
807819
goto done;
820+
} else if (exttype == WIIMOTE_EXT_PRO_CONTROLLER) {
821+
devtype = WIIMOTE_DEV_PRO_CONTROLLER;
822+
goto done;
808823
}
809824

810825
if (!strcmp(name, "Nintendo RVL-CNT-01")) {
@@ -816,6 +831,9 @@ static void wiimote_init_set_type(struct wiimote_data *wdata,
816831
} else if (!strcmp(name, "Nintendo RVL-WBC-01")) {
817832
devtype = WIIMOTE_DEV_BALANCE_BOARD;
818833
goto done;
834+
} else if (!strcmp(name, "Nintendo RVL-CNT-01-UC")) {
835+
devtype = WIIMOTE_DEV_PRO_CONTROLLER;
836+
goto done;
819837
}
820838

821839
if (vendor == USB_VENDOR_ID_NINTENDO) {
@@ -1058,6 +1076,7 @@ static const char *wiimote_exttype_names[WIIMOTE_EXT_NUM] = {
10581076
[WIIMOTE_EXT_NUNCHUK] = "Nintendo Wii Nunchuk",
10591077
[WIIMOTE_EXT_CLASSIC_CONTROLLER] = "Nintendo Wii Classic Controller",
10601078
[WIIMOTE_EXT_BALANCE_BOARD] = "Nintendo Wii Balance Board",
1079+
[WIIMOTE_EXT_PRO_CONTROLLER] = "Nintendo Wii U Pro Controller",
10611080
};
10621081

10631082
/*
@@ -1642,6 +1661,8 @@ static ssize_t wiimote_ext_show(struct device *dev,
16421661
return sprintf(buf, "classic\n");
16431662
case WIIMOTE_EXT_BALANCE_BOARD:
16441663
return sprintf(buf, "balanceboard\n");
1664+
case WIIMOTE_EXT_PRO_CONTROLLER:
1665+
return sprintf(buf, "procontroller\n");
16451666
case WIIMOTE_EXT_UNKNOWN:
16461667
/* fallthrough */
16471668
default:
@@ -1688,6 +1709,8 @@ static ssize_t wiimote_dev_show(struct device *dev,
16881709
return sprintf(buf, "gen20\n");
16891710
case WIIMOTE_DEV_BALANCE_BOARD:
16901711
return sprintf(buf, "balanceboard\n");
1712+
case WIIMOTE_DEV_PRO_CONTROLLER:
1713+
return sprintf(buf, "procontroller\n");
16911714
case WIIMOTE_DEV_PENDING:
16921715
return sprintf(buf, "pending\n");
16931716
case WIIMOTE_DEV_UNKNOWN:

drivers/hid/hid-wiimote-modules.c

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,300 @@ static const struct wiimod_ops wiimod_bboard = {
15391539
.in_ext = wiimod_bboard_in_ext,
15401540
};
15411541

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+
15421836
/*
15431837
* Builtin Motion Plus
15441838
* This module simply sets the WIIPROTO_FLAG_BUILTIN_MP protocol flag which
@@ -1788,4 +2082,5 @@ const struct wiimod_ops *wiimod_ext_table[WIIMOTE_EXT_NUM] = {
17882082
[WIIMOTE_EXT_NUNCHUK] = &wiimod_nunchuk,
17892083
[WIIMOTE_EXT_CLASSIC_CONTROLLER] = &wiimod_classic,
17902084
[WIIMOTE_EXT_BALANCE_BOARD] = &wiimod_bboard,
2085+
[WIIMOTE_EXT_PRO_CONTROLLER] = &wiimod_pro,
17912086
};

0 commit comments

Comments
 (0)