Skip to content

Commit d7cbe27

Browse files
nitinexclusivelyjwrdegoede
authored andcommitted
platform/x86: thinkpad_acpi: set keyboard language
This patch is to create sysfs entry for setting keyboard language using ASL method. Some thinkpads models like T580 , T590 , T15 Gen 1 etc. has "=", "(',")" numeric keys, which are not displaying correctly, when keyboard language is other than "english". This patch fixes this issue by setting keyboard language to ECFW. Signed-off-by: Nitin Joshi <njoshi1@lenovo.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20210125025916.180831-1-nitjoshi@gmail.com Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent aecb925 commit d7cbe27

2 files changed

Lines changed: 205 additions & 0 deletions

File tree

‎Documentation/admin-guide/laptops/thinkpad-acpi.rst‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ detailed description):
5151
- UWB enable and disable
5252
- LCD Shadow (PrivacyGuard) enable and disable
5353
- Lap mode sensor
54+
- Setting keyboard language
5455

5556
A compatibility table by model and feature is maintained on the web
5657
site, http://ibm-acpi.sf.net/. I appreciate any success or failure
@@ -1466,6 +1467,29 @@ Sysfs notes
14661467
rfkill controller switch "tpacpi_uwb_sw": refer to
14671468
Documentation/driver-api/rfkill.rst for details.
14681469

1470+
1471+
Setting keyboard language
1472+
-------------------
1473+
1474+
sysfs: keyboard_lang
1475+
1476+
This feature is used to set keyboard language to ECFW using ASL interface.
1477+
Fewer thinkpads models like T580 , T590 , T15 Gen 1 etc.. has "=", "(',
1478+
")" numeric keys, which are not displaying correctly, when keyboard language
1479+
is other than "english". This is because of default keyboard language in ECFW
1480+
is set as "english". Hence using this sysfs, user can set correct keyboard
1481+
language to ECFW and then these key's will work correctly .
1482+
1483+
Example of command to set keyboard language is mentioned below::
1484+
1485+
echo jp > /sys/devices/platform/thinkpad_acpi/keyboard_lang
1486+
1487+
Text corresponding to keyboard layout to be set in sysfs are : jp (Japan), be(Belgian),
1488+
cz(Czech), en(English), da(Danish), de(German), es(Spain) , et(Estonian),
1489+
fr(French) , fr-ch (French(Switzerland)), pl(Polish), sl(Slovenian), hu
1490+
(Hungarian), nl(Dutch), tr(Turkey), it(Italy), sv(Sweden), pt(portugese)
1491+
1492+
14691493
Adaptive keyboard
14701494
-----------------
14711495

‎drivers/platform/x86/thinkpad_acpi.c‎

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9983,6 +9983,183 @@ static struct ibm_struct proxsensor_driver_data = {
99839983
.exit = proxsensor_exit,
99849984
};
99859985

9986+
/*************************************************************************
9987+
* Keyboard language interface
9988+
*/
9989+
9990+
struct keyboard_lang_data {
9991+
const char *lang_str;
9992+
int lang_code;
9993+
};
9994+
9995+
/*
9996+
* When adding new entries to keyboard_lang_data, please check that
9997+
* the select_lang[] buffer in keyboard_lang_show() is still large enough.
9998+
*/
9999+
struct keyboard_lang_data keyboard_lang_data[] = {
10000+
{"en", 0},
10001+
{"be", 0x080c},
10002+
{"cz", 0x0405},
10003+
{"da", 0x0406},
10004+
{"de", 0x0c07},
10005+
{"es", 0x2c0a},
10006+
{"et", 0x0425},
10007+
{"fr", 0x040c},
10008+
{"fr-ch", 0x100c},
10009+
{"hu", 0x040e},
10010+
{"it", 0x0410},
10011+
{"jp", 0x0411},
10012+
{"nl", 0x0413},
10013+
{"nn", 0x0414},
10014+
{"pl", 0x0415},
10015+
{"pt", 0x0816},
10016+
{"sl", 0x041b},
10017+
{"sv", 0x081d},
10018+
{"tr", 0x041f},
10019+
};
10020+
10021+
static int set_keyboard_lang_command(int command)
10022+
{
10023+
acpi_handle sskl_handle;
10024+
int output;
10025+
10026+
if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "SSKL", &sskl_handle))) {
10027+
/* Platform doesn't support SSKL */
10028+
return -ENODEV;
10029+
}
10030+
10031+
if (!acpi_evalf(sskl_handle, &output, NULL, "dd", command))
10032+
return -EIO;
10033+
10034+
return 0;
10035+
}
10036+
10037+
static int get_keyboard_lang(int *output)
10038+
{
10039+
acpi_handle gskl_handle;
10040+
int kbd_lang;
10041+
10042+
if (ACPI_FAILURE(acpi_get_handle(hkey_handle, "GSKL", &gskl_handle))) {
10043+
/* Platform doesn't support GSKL */
10044+
return -ENODEV;
10045+
}
10046+
10047+
if (!acpi_evalf(gskl_handle, &kbd_lang, NULL, "dd", 0x02000000))
10048+
return -EIO;
10049+
10050+
*output = kbd_lang;
10051+
10052+
return 0;
10053+
}
10054+
10055+
/* sysfs keyboard language entry */
10056+
static ssize_t keyboard_lang_show(struct device *dev,
10057+
struct device_attribute *attr,
10058+
char *buf)
10059+
{
10060+
int output, err, i;
10061+
char select_lang[80] = "";
10062+
char lang[8] = "";
10063+
10064+
err = get_keyboard_lang(&output);
10065+
if (err)
10066+
return err;
10067+
10068+
for (i = 0; i < ARRAY_SIZE(keyboard_lang_data); i++) {
10069+
if (i)
10070+
strcat(select_lang, " ");
10071+
10072+
if (output == keyboard_lang_data[i].lang_code) {
10073+
strcat(lang, "[");
10074+
strcat(lang, keyboard_lang_data[i].lang_str);
10075+
strcat(lang, "]");
10076+
strcat(select_lang, lang);
10077+
} else {
10078+
strcat(select_lang, keyboard_lang_data[i].lang_str);
10079+
}
10080+
}
10081+
10082+
return sysfs_emit(buf, "%s\n", select_lang);
10083+
}
10084+
10085+
static ssize_t keyboard_lang_store(struct device *dev,
10086+
struct device_attribute *attr,
10087+
const char *buf, size_t count)
10088+
{
10089+
int err, i;
10090+
bool lang_found = false;
10091+
int lang_code = 0;
10092+
10093+
for (i = 0; i < ARRAY_SIZE(keyboard_lang_data); i++) {
10094+
if (sysfs_streq(buf, keyboard_lang_data[i].lang_str)) {
10095+
lang_code = keyboard_lang_data[i].lang_code;
10096+
lang_found = true;
10097+
break;
10098+
}
10099+
}
10100+
10101+
if (lang_found) {
10102+
lang_code = lang_code | 1 << 24;
10103+
10104+
/* Set language code */
10105+
err = set_keyboard_lang_command(lang_code);
10106+
if (err)
10107+
return err;
10108+
} else {
10109+
pr_err("Unknown Keyboard language. Ignoring\n");
10110+
return -EINVAL;
10111+
}
10112+
10113+
tpacpi_disclose_usertask(attr->attr.name,
10114+
"keyboard language is set to %s\n", buf);
10115+
10116+
sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "keyboard_lang");
10117+
10118+
return count;
10119+
}
10120+
10121+
static DEVICE_ATTR_RW(keyboard_lang);
10122+
10123+
static struct attribute *kbdlang_attributes[] = {
10124+
&dev_attr_keyboard_lang.attr,
10125+
NULL
10126+
};
10127+
10128+
static const struct attribute_group kbdlang_attr_group = {
10129+
.attrs = kbdlang_attributes,
10130+
};
10131+
10132+
static int tpacpi_kbdlang_init(struct ibm_init_struct *iibm)
10133+
{
10134+
int err, output;
10135+
10136+
err = get_keyboard_lang(&output);
10137+
/*
10138+
* If support isn't available (ENODEV) then don't return an error
10139+
* just don't create the sysfs group
10140+
*/
10141+
if (err == -ENODEV)
10142+
return 0;
10143+
10144+
if (err)
10145+
return err;
10146+
10147+
/* Platform supports this feature - create the sysfs file */
10148+
err = sysfs_create_group(&tpacpi_pdev->dev.kobj, &kbdlang_attr_group);
10149+
10150+
return err;
10151+
}
10152+
10153+
static void kbdlang_exit(void)
10154+
{
10155+
sysfs_remove_group(&tpacpi_pdev->dev.kobj, &kbdlang_attr_group);
10156+
}
10157+
10158+
static struct ibm_struct kbdlang_driver_data = {
10159+
.name = "kbdlang",
10160+
.exit = kbdlang_exit,
10161+
};
10162+
998610163
/****************************************************************************
998710164
****************************************************************************
998810165
*
@@ -10475,6 +10652,10 @@ static struct ibm_init_struct ibms_init[] __initdata = {
1047510652
.init = tpacpi_proxsensor_init,
1047610653
.data = &proxsensor_driver_data,
1047710654
},
10655+
{
10656+
.init = tpacpi_kbdlang_init,
10657+
.data = &kbdlang_driver_data,
10658+
},
1047810659
};
1047910660

1048010661
static int __init set_ibm_param(const char *val, const struct kernel_param *kp)

0 commit comments

Comments
 (0)