xref: /openbmc/linux/drivers/media/rc/keymaps/rc-cec.c (revision f09f9f93)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Keytable for the CEC remote control
3  *
4  * This keymap is unusual in that it can't be built as a module,
5  * instead it is registered directly in rc-main.c if CONFIG_MEDIA_CEC_RC
6  * is set. This is because it can be called from drm_dp_cec_set_edid() via
7  * cec_register_adapter() in an asynchronous context, and it is not
8  * allowed to use request_module() to load rc-cec.ko in that case.
9  *
10  * Since this keymap is only used if CONFIG_MEDIA_CEC_RC is set, we
11  * just compile this keymap into the rc-core module and never as a
12  * separate module.
13  *
14  * Copyright (c) 2015 by Kamil Debski
15  */
16 
17 #include <media/rc-map.h>
18 #include <linux/module.h>
19 
20 /*
21  * CEC Spec "High-Definition Multimedia Interface Specification" can be obtained
22  * here: http://xtreamerdev.googlecode.com/files/CEC_Specs.pdf
23  * The list of control codes is listed in Table 27: User Control Codes p. 95
24  */
25 
26 static struct rc_map_table cec[] = {
27 	{ 0x00, KEY_OK },
28 	{ 0x01, KEY_UP },
29 	{ 0x02, KEY_DOWN },
30 	{ 0x03, KEY_LEFT },
31 	{ 0x04, KEY_RIGHT },
32 	{ 0x05, KEY_RIGHT_UP },
33 	{ 0x06, KEY_RIGHT_DOWN },
34 	{ 0x07, KEY_LEFT_UP },
35 	{ 0x08, KEY_LEFT_DOWN },
36 	{ 0x09, KEY_ROOT_MENU }, /* CEC Spec: Device Root Menu - see Note 2 */
37 	/*
38 	 * Note 2: This is the initial display that a device shows. It is
39 	 * device-dependent and can be, for example, a contents menu, setup
40 	 * menu, favorite menu or other menu. The actual menu displayed
41 	 * may also depend on the device's current state.
42 	 */
43 	{ 0x0a, KEY_SETUP },
44 	{ 0x0b, KEY_MENU }, /* CEC Spec: Contents Menu */
45 	{ 0x0c, KEY_FAVORITES }, /* CEC Spec: Favorite Menu */
46 	{ 0x0d, KEY_EXIT },
47 	/* 0x0e-0x0f: Reserved */
48 	{ 0x10, KEY_MEDIA_TOP_MENU },
49 	{ 0x11, KEY_CONTEXT_MENU },
50 	/* 0x12-0x1c: Reserved */
51 	{ 0x1d, KEY_DIGITS }, /* CEC Spec: select/toggle a Number Entry Mode */
52 	{ 0x1e, KEY_NUMERIC_11 },
53 	{ 0x1f, KEY_NUMERIC_12 },
54 	/* 0x20-0x29: Keys 0 to 9 */
55 	{ 0x20, KEY_NUMERIC_0 },
56 	{ 0x21, KEY_NUMERIC_1 },
57 	{ 0x22, KEY_NUMERIC_2 },
58 	{ 0x23, KEY_NUMERIC_3 },
59 	{ 0x24, KEY_NUMERIC_4 },
60 	{ 0x25, KEY_NUMERIC_5 },
61 	{ 0x26, KEY_NUMERIC_6 },
62 	{ 0x27, KEY_NUMERIC_7 },
63 	{ 0x28, KEY_NUMERIC_8 },
64 	{ 0x29, KEY_NUMERIC_9 },
65 	{ 0x2a, KEY_DOT },
66 	{ 0x2b, KEY_ENTER },
67 	{ 0x2c, KEY_CLEAR },
68 	/* 0x2d-0x2e: Reserved */
69 	{ 0x2f, KEY_NEXT_FAVORITE }, /* CEC Spec: Next Favorite */
70 	{ 0x30, KEY_CHANNELUP },
71 	{ 0x31, KEY_CHANNELDOWN },
72 	{ 0x32, KEY_PREVIOUS }, /* CEC Spec: Previous Channel */
73 	{ 0x33, KEY_SOUND }, /* CEC Spec: Sound Select */
74 	{ 0x34, KEY_VIDEO }, /* 0x34: CEC Spec: Input Select */
75 	{ 0x35, KEY_INFO }, /* CEC Spec: Display Information */
76 	{ 0x36, KEY_HELP },
77 	{ 0x37, KEY_PAGEUP },
78 	{ 0x38, KEY_PAGEDOWN },
79 	/* 0x39-0x3f: Reserved */
80 	{ 0x40, KEY_POWER },
81 	{ 0x41, KEY_VOLUMEUP },
82 	{ 0x42, KEY_VOLUMEDOWN },
83 	{ 0x43, KEY_MUTE },
84 	{ 0x44, KEY_PLAYCD },
85 	{ 0x45, KEY_STOPCD },
86 	{ 0x46, KEY_PAUSECD },
87 	{ 0x47, KEY_RECORD },
88 	{ 0x48, KEY_REWIND },
89 	{ 0x49, KEY_FASTFORWARD },
90 	{ 0x4a, KEY_EJECTCD }, /* CEC Spec: Eject */
91 	{ 0x4b, KEY_FORWARD },
92 	{ 0x4c, KEY_BACK },
93 	{ 0x4d, KEY_STOP_RECORD }, /* CEC Spec: Stop-Record */
94 	{ 0x4e, KEY_PAUSE_RECORD }, /* CEC Spec: Pause-Record */
95 	/* 0x4f: Reserved */
96 	{ 0x50, KEY_ANGLE },
97 	{ 0x51, KEY_TV2 },
98 	{ 0x52, KEY_VOD }, /* CEC Spec: Video on Demand */
99 	{ 0x53, KEY_EPG },
100 	{ 0x54, KEY_TIME }, /* CEC Spec: Timer */
101 	{ 0x55, KEY_CONFIG },
102 	/*
103 	 * The following codes are hard to implement at this moment, as they
104 	 * carry an additional additional argument. Most likely changes to RC
105 	 * framework are necessary.
106 	 * For now they are interpreted by the CEC framework as non keycodes
107 	 * and are passed as messages enabling user application to parse them.
108 	 */
109 	/* 0x56: CEC Spec: Select Broadcast Type */
110 	/* 0x57: CEC Spec: Select Sound presentation */
111 	{ 0x58, KEY_AUDIO_DESC }, /* CEC 2.0 and up */
112 	{ 0x59, KEY_WWW }, /* CEC 2.0 and up */
113 	{ 0x5a, KEY_3D_MODE }, /* CEC 2.0 and up */
114 	/* 0x5b-0x5f: Reserved */
115 	{ 0x60, KEY_PLAYCD }, /* CEC Spec: Play Function */
116 	{ 0x6005, KEY_FASTFORWARD },
117 	{ 0x6006, KEY_FASTFORWARD },
118 	{ 0x6007, KEY_FASTFORWARD },
119 	{ 0x6015, KEY_SLOW },
120 	{ 0x6016, KEY_SLOW },
121 	{ 0x6017, KEY_SLOW },
122 	{ 0x6009, KEY_FASTREVERSE },
123 	{ 0x600a, KEY_FASTREVERSE },
124 	{ 0x600b, KEY_FASTREVERSE },
125 	{ 0x6019, KEY_SLOWREVERSE },
126 	{ 0x601a, KEY_SLOWREVERSE },
127 	{ 0x601b, KEY_SLOWREVERSE },
128 	{ 0x6020, KEY_REWIND },
129 	{ 0x6024, KEY_PLAYCD },
130 	{ 0x6025, KEY_PAUSECD },
131 	{ 0x61, KEY_PLAYPAUSE }, /* CEC Spec: Pause-Play Function */
132 	{ 0x62, KEY_RECORD }, /* Spec: Record Function */
133 	{ 0x63, KEY_PAUSE_RECORD }, /* CEC Spec: Pause-Record Function */
134 	{ 0x64, KEY_STOPCD }, /* CEC Spec: Stop Function */
135 	{ 0x65, KEY_MUTE }, /* CEC Spec: Mute Function */
136 	{ 0x66, KEY_UNMUTE }, /* CEC Spec: Restore the volume */
137 	/*
138 	 * The following codes are hard to implement at this moment, as they
139 	 * carry an additional additional argument. Most likely changes to RC
140 	 * framework are necessary.
141 	 * For now they are interpreted by the CEC framework as non keycodes
142 	 * and are passed as messages enabling user application to parse them.
143 	 */
144 	/* 0x67: CEC Spec: Tune Function */
145 	/* 0x68: CEC Spec: Seleect Media Function */
146 	/* 0x69: CEC Spec: Select A/V Input Function */
147 	/* 0x6a: CEC Spec: Select Audio Input Function */
148 	{ 0x6b, KEY_POWER }, /* CEC Spec: Power Toggle Function */
149 	{ 0x6c, KEY_SLEEP }, /* CEC Spec: Power Off Function */
150 	{ 0x6d, KEY_WAKEUP }, /* CEC Spec: Power On Function */
151 	/* 0x6e-0x70: Reserved */
152 	{ 0x71, KEY_BLUE }, /* CEC Spec: F1 (Blue) */
153 	{ 0x72, KEY_RED }, /* CEC Spec: F2 (Red) */
154 	{ 0x73, KEY_GREEN }, /* CEC Spec: F3 (Green) */
155 	{ 0x74, KEY_YELLOW }, /* CEC Spec: F4 (Yellow) */
156 	{ 0x75, KEY_F5 },
157 	{ 0x76, KEY_DATA }, /* CEC Spec: Data - see Note 3 */
158 	/*
159 	 * Note 3: This is used, for example, to enter or leave a digital TV
160 	 * data broadcast application.
161 	 */
162 	/* 0x77-0xff: Reserved */
163 };
164 
165 struct rc_map_list cec_map = {
166 	.map = {
167 		.scan		= cec,
168 		.size		= ARRAY_SIZE(cec),
169 		.rc_proto	= RC_PROTO_CEC,
170 		.name		= RC_MAP_CEC,
171 	}
172 };
173