18c2ecf20Sopenharmony_ci===============================================
28c2ecf20Sopenharmony_ciDriver documentation for yealink usb-p1k phones
38c2ecf20Sopenharmony_ci===============================================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciStatus
68c2ecf20Sopenharmony_ci======
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciThe p1k is a relatively cheap usb 1.1 phone with:
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci  - keyboard		full support, yealink.ko / input event API
118c2ecf20Sopenharmony_ci  - LCD			full support, yealink.ko / sysfs API
128c2ecf20Sopenharmony_ci  - LED			full support, yealink.ko / sysfs API
138c2ecf20Sopenharmony_ci  - dialtone		full support, yealink.ko / sysfs API
148c2ecf20Sopenharmony_ci  - ringtone		full support, yealink.ko / sysfs API
158c2ecf20Sopenharmony_ci  - audio playback   	full support, snd_usb_audio.ko / alsa API
168c2ecf20Sopenharmony_ci  - audio record     	full support, snd_usb_audio.ko / alsa API
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciFor vendor documentation see http://www.yealink.com
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cikeyboard features
228c2ecf20Sopenharmony_ci=================
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciThe current mapping in the kernel is provided by the map_p1k_to_key
258c2ecf20Sopenharmony_cifunction::
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci   Physical USB-P1K button layout	input events
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci              up			     up
318c2ecf20Sopenharmony_ci        IN           OUT		left,	right
328c2ecf20Sopenharmony_ci             down			    down
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci      pickup   C    hangup		enter, backspace, escape
358c2ecf20Sopenharmony_ci        1      2      3			1, 2, 3
368c2ecf20Sopenharmony_ci        4      5      6			4, 5, 6,
378c2ecf20Sopenharmony_ci        7      8      9			7, 8, 9,
388c2ecf20Sopenharmony_ci        *      0      #			*, 0, #,
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ciThe "up" and "down" keys, are symbolised by arrows on the button.
418c2ecf20Sopenharmony_ciThe "pickup" and "hangup" keys are symbolised by a green and red phone
428c2ecf20Sopenharmony_cion the button.
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciLCD features
468c2ecf20Sopenharmony_ci============
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciThe LCD is divided and organised as a 3 line display::
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci    |[]   [][]   [][]   [][]   in   |[][]
518c2ecf20Sopenharmony_ci    |[] M [][] D [][] : [][]   out  |[][]
528c2ecf20Sopenharmony_ci                              store
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci    NEW REP         SU MO TU WE TH FR SA
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci    [] [] [] [] [] [] [] [] [] [] [] []
578c2ecf20Sopenharmony_ci    [] [] [] [] [] [] [] [] [] [] [] []
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci  Line 1  Format (see below)	: 18.e8.M8.88...188
618c2ecf20Sopenharmony_ci	  Icon names		:   M  D  :  IN OUT STORE
628c2ecf20Sopenharmony_ci  Line 2  Format		: .........
638c2ecf20Sopenharmony_ci	  Icon name		: NEW REP SU MO TU WE TH FR SA
648c2ecf20Sopenharmony_ci  Line 3  Format		: 888888888888
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciFormat description:
688c2ecf20Sopenharmony_ci  From a userspace perspective the world is separated into "digits" and "icons".
698c2ecf20Sopenharmony_ci  A digit can have a character set, an icon can only be ON or OFF.
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci  Format specifier::
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci    '8' :  Generic 7 segment digit with individual addressable segments
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci    Reduced capability 7 segment digit, when segments are hard wired together.
768c2ecf20Sopenharmony_ci    '1' : 2 segments digit only able to produce a 1.
778c2ecf20Sopenharmony_ci    'e' : Most significant day of the month digit,
788c2ecf20Sopenharmony_ci          able to produce at least 1 2 3.
798c2ecf20Sopenharmony_ci    'M' : Most significant minute digit,
808c2ecf20Sopenharmony_ci          able to produce at least 0 1 2 3 4 5.
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci    Icons or pictograms:
838c2ecf20Sopenharmony_ci    '.' : For example like AM, PM, SU, a 'dot' .. or other single segment
848c2ecf20Sopenharmony_ci	  elements.
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ciDriver usage
888c2ecf20Sopenharmony_ci============
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ciFor userland the following interfaces are available using the sysfs interface::
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci  /sys/.../
938c2ecf20Sopenharmony_ci           line1	Read/Write, lcd line1
948c2ecf20Sopenharmony_ci           line2	Read/Write, lcd line2
958c2ecf20Sopenharmony_ci           line3	Read/Write, lcd line3
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	   get_icons    Read, returns a set of available icons.
988c2ecf20Sopenharmony_ci	   hide_icon    Write, hide the element by writing the icon name.
998c2ecf20Sopenharmony_ci	   show_icon    Write, display the element by writing the icon name.
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	   map_seg7	Read/Write, the 7 segments char set, common for all
1028c2ecf20Sopenharmony_ci			yealink phones. (see map_to_7segment.h)
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	   ringtone	Write, upload binary representation of a ringtone,
1058c2ecf20Sopenharmony_ci			see yealink.c. status EXPERIMENTAL due to potential
1068c2ecf20Sopenharmony_ci			races between async. and sync usb calls.
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cilineX
1108c2ecf20Sopenharmony_ci~~~~~
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ciReading /sys/../lineX will return the format string with its current value.
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci  Example::
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci    cat ./line3
1178c2ecf20Sopenharmony_ci    888888888888
1188c2ecf20Sopenharmony_ci    Linux Rocks!
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ciWriting to /sys/../lineX will set the corresponding LCD line.
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci - Excess characters are ignored.
1238c2ecf20Sopenharmony_ci - If less characters are written than allowed, the remaining digits are
1248c2ecf20Sopenharmony_ci   unchanged.
1258c2ecf20Sopenharmony_ci - The tab '\t'and '\n' char does not overwrite the original content.
1268c2ecf20Sopenharmony_ci - Writing a space to an icon will always hide its content.
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci  Example::
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci    date +"%m.%e.%k:%M"  | sed 's/^0/ /' > ./line1
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci  Will update the LCD with the current date & time.
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ciget_icons
1368c2ecf20Sopenharmony_ci~~~~~~~~~
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ciReading will return all available icon names and its current settings::
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci  cat ./get_icons
1418c2ecf20Sopenharmony_ci  on M
1428c2ecf20Sopenharmony_ci  on D
1438c2ecf20Sopenharmony_ci  on :
1448c2ecf20Sopenharmony_ci     IN
1458c2ecf20Sopenharmony_ci     OUT
1468c2ecf20Sopenharmony_ci     STORE
1478c2ecf20Sopenharmony_ci     NEW
1488c2ecf20Sopenharmony_ci     REP
1498c2ecf20Sopenharmony_ci     SU
1508c2ecf20Sopenharmony_ci     MO
1518c2ecf20Sopenharmony_ci     TU
1528c2ecf20Sopenharmony_ci     WE
1538c2ecf20Sopenharmony_ci     TH
1548c2ecf20Sopenharmony_ci     FR
1558c2ecf20Sopenharmony_ci     SA
1568c2ecf20Sopenharmony_ci     LED
1578c2ecf20Sopenharmony_ci     DIALTONE
1588c2ecf20Sopenharmony_ci     RINGTONE
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cishow/hide icons
1628c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciWriting to these files will update the state of the icon.
1658c2ecf20Sopenharmony_ciOnly one icon at a time can be updated.
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ciIf an icon is also on a ./lineX the corresponding value is
1688c2ecf20Sopenharmony_ciupdated with the first letter of the icon.
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci  Example - light up the store icon::
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci    echo -n "STORE" > ./show_icon
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci    cat ./line1
1758c2ecf20Sopenharmony_ci    18.e8.M8.88...188
1768c2ecf20Sopenharmony_ci		  S
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci  Example - sound the ringtone for 10 seconds::
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci    echo -n RINGTONE > /sys/..../show_icon
1818c2ecf20Sopenharmony_ci    sleep 10
1828c2ecf20Sopenharmony_ci    echo -n RINGTONE > /sys/..../hide_icon
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ciSound features
1868c2ecf20Sopenharmony_ci==============
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ciSound is supported by the ALSA driver: snd_usb_audio
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ciOne 16-bit channel with sample and playback rates of 8000 Hz is the practical
1918c2ecf20Sopenharmony_cilimit of the device.
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci  Example - recording test::
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci    arecord -v -d 10 -r 8000 -f S16_LE -t wav  foobar.wav
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci  Example - playback test::
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci    aplay foobar.wav
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ciTroubleshooting
2038c2ecf20Sopenharmony_ci===============
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci:Q: Module yealink compiled and installed without any problem but phone
2068c2ecf20Sopenharmony_ci    is not initialized and does not react to any actions.
2078c2ecf20Sopenharmony_ci:A: If you see something like:
2088c2ecf20Sopenharmony_ci    hiddev0: USB HID v1.00 Device [Yealink Network Technology Ltd. VOIP USB Phone
2098c2ecf20Sopenharmony_ci    in dmesg, it means that the hid driver has grabbed the device first. Try to
2108c2ecf20Sopenharmony_ci    load module yealink before any other usb hid driver. Please see the
2118c2ecf20Sopenharmony_ci    instructions provided by your distribution on module configuration.
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci:Q: Phone is working now (displays version and accepts keypad input) but I can't
2148c2ecf20Sopenharmony_ci    find the sysfs files.
2158c2ecf20Sopenharmony_ci:A: The sysfs files are located on the particular usb endpoint. On most
2168c2ecf20Sopenharmony_ci    distributions you can do: "find /sys/ -name get_icons" for a hint.
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ciCredits & Acknowledgments
2208c2ecf20Sopenharmony_ci=========================
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci  - Olivier Vandorpe, for starting the usbb2k-api project doing much of
2238c2ecf20Sopenharmony_ci    the reverse engineering.
2248c2ecf20Sopenharmony_ci  - Martin Diehl, for pointing out how to handle USB memory allocation.
2258c2ecf20Sopenharmony_ci  - Dmitry Torokhov, for the numerous code reviews and suggestions.
226