Skip to content

Commit be144ee

Browse files
Samsagaxgroeck
authored andcommitted
hwmon: (oxp-sensors) Add tt_toggle attribute on supported boards
OneXPlayer boards from the last generation (both for OneXPlayer and AOK ZOE brands) have a toggle in the EC to switch the "Turbo/Silent" button into a different keyboard event. Add a means to use that "Turbo button takeover" function and expose it to userspace in a custom sysfs `tt_toggle` attribute. It can be read to take the current state. Write 1|0 to activate the function. The specific keycode is dependent on the board but can be checked by running `evtest` utility. Newer BIOS on the OneXPlayer added this function aside from string changes. Add a board enum to differentiate it from the old OneXplayer Mini AMD BIOS. Currently known supported boards: - AOK ZOE A1 - OneXPlayer Mini AMD (only newer BIOS version supported) - OneXPlayer Mini Pro Signed-off-by: Joaquín Ignacio Aramendía <samsagax@gmail.com> Link: https://lore.kernel.org/r/20230611143332.40590-2-samsagax@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent fbb5a7f commit be144ee

2 files changed

Lines changed: 150 additions & 1 deletion

File tree

Documentation/hwmon/oxp-sensors.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ out the EC registers and values to write to since the EC layout and model is
1919
different. Aya Neo devices preceding the AIR may not be supportable as the EC
2020
model is different and do not appear to have manual control capabilities.
2121

22+
Some models have a toggle for changing the behaviour of the "Turbo/Silent"
23+
button of the device. It will change the key event that it triggers with
24+
a flip of the `tt_toggle` attribute. See below for boards that support this
25+
function.
26+
2227
Supported devices
2328
-----------------
2429

@@ -33,6 +38,11 @@ Currently the driver supports the following handhelds:
3338
- OneXPlayer mini AMD
3439
- OneXPlayer mini AMD PRO
3540

41+
"Turbo/Silent" button behaviour toggle is only supported on:
42+
- AOK ZOE A1
43+
- OneXPlayer mini AMD (only with updated alpha BIOS)
44+
- OneXPlayer mini AMD PRO
45+
3646
Sysfs entries
3747
-------------
3848

@@ -49,3 +59,10 @@ pwm1
4959
Read Write. Read this attribute to see current duty cycle in the range [0-255].
5060
When pwm1_enable is set to "1" (manual) write any value in the range [0-255]
5161
to set fan speed.
62+
63+
tt_toggle
64+
Read Write. Read this attribute to check the status of the turbo/silent
65+
button behaviour function. Write "1" to activate the switch and "0" to
66+
deactivate it. The specific keycodes and behaviour is specific to the device
67+
both with this function on and off. This attribute is attached to the platform
68+
driver and not to the hwmon driver (/sys/devices/platform/oxp-platform/tt_toggle)

drivers/hwmon/oxp-sensors.c

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,29 @@ enum oxp_board {
4747
aya_neo_air_pro,
4848
aya_neo_geek,
4949
oxp_mini_amd,
50+
oxp_mini_amd_a07,
5051
oxp_mini_amd_pro,
5152
};
5253

5354
static enum oxp_board board;
5455

56+
/* Fan reading and PWM */
5557
#define OXP_SENSOR_FAN_REG 0x76 /* Fan reading is 2 registers long */
5658
#define OXP_SENSOR_PWM_ENABLE_REG 0x4A /* PWM enable is 1 register long */
5759
#define OXP_SENSOR_PWM_REG 0x4B /* PWM reading is 1 register long */
5860

61+
/* Turbo button takeover function
62+
* Older boards have different values and EC registers
63+
* for the same function
64+
*/
65+
#define OXP_OLD_TURBO_SWITCH_REG 0x1E
66+
#define OXP_OLD_TURBO_TAKE_VAL 0x01
67+
#define OXP_OLD_TURBO_RETURN_VAL 0x00
68+
69+
#define OXP_TURBO_SWITCH_REG 0xF1
70+
#define OXP_TURBO_TAKE_VAL 0x40
71+
#define OXP_TURBO_RETURN_VAL 0x00
72+
5973
static const struct dmi_system_id dmi_table[] = {
6074
{
6175
.matches = {
@@ -104,7 +118,7 @@ static const struct dmi_system_id dmi_table[] = {
104118
DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"),
105119
DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER mini A07"),
106120
},
107-
.driver_data = (void *)oxp_mini_amd,
121+
.driver_data = (void *)oxp_mini_amd_a07,
108122
},
109123
{
110124
.matches = {
@@ -156,6 +170,102 @@ static int write_to_ec(u8 reg, u8 value)
156170
return ret;
157171
}
158172

173+
/* Turbo button toggle functions */
174+
static int tt_toggle_enable(void)
175+
{
176+
u8 reg;
177+
u8 val;
178+
179+
switch (board) {
180+
case oxp_mini_amd_a07:
181+
reg = OXP_OLD_TURBO_SWITCH_REG;
182+
val = OXP_OLD_TURBO_TAKE_VAL;
183+
break;
184+
case oxp_mini_amd_pro:
185+
case aok_zoe_a1:
186+
reg = OXP_TURBO_SWITCH_REG;
187+
val = OXP_TURBO_TAKE_VAL;
188+
break;
189+
default:
190+
return -EINVAL;
191+
}
192+
return write_to_ec(reg, val);
193+
}
194+
195+
static int tt_toggle_disable(void)
196+
{
197+
u8 reg;
198+
u8 val;
199+
200+
switch (board) {
201+
case oxp_mini_amd_a07:
202+
reg = OXP_OLD_TURBO_SWITCH_REG;
203+
val = OXP_OLD_TURBO_RETURN_VAL;
204+
break;
205+
case oxp_mini_amd_pro:
206+
case aok_zoe_a1:
207+
reg = OXP_TURBO_SWITCH_REG;
208+
val = OXP_TURBO_RETURN_VAL;
209+
break;
210+
default:
211+
return -EINVAL;
212+
}
213+
return write_to_ec(reg, val);
214+
}
215+
216+
/* Callbacks for turbo toggle attribute */
217+
static ssize_t tt_toggle_store(struct device *dev,
218+
struct device_attribute *attr, const char *buf,
219+
size_t count)
220+
{
221+
int rval;
222+
bool value;
223+
224+
rval = kstrtobool(buf, &value);
225+
if (rval)
226+
return rval;
227+
228+
if (value) {
229+
rval = tt_toggle_enable();
230+
if (rval)
231+
return rval;
232+
} else {
233+
rval = tt_toggle_disable();
234+
if (rval)
235+
return rval;
236+
}
237+
return count;
238+
}
239+
240+
static ssize_t tt_toggle_show(struct device *dev,
241+
struct device_attribute *attr, char *buf)
242+
{
243+
int retval;
244+
u8 reg;
245+
long val;
246+
247+
switch (board) {
248+
case oxp_mini_amd_a07:
249+
reg = OXP_OLD_TURBO_SWITCH_REG;
250+
break;
251+
case oxp_mini_amd_pro:
252+
case aok_zoe_a1:
253+
reg = OXP_TURBO_SWITCH_REG;
254+
break;
255+
default:
256+
return -EINVAL;
257+
}
258+
259+
retval = read_from_ec(reg, 1, &val);
260+
if (retval)
261+
return retval;
262+
263+
return sysfs_emit(buf, "%d\n", !!val);
264+
}
265+
266+
static DEVICE_ATTR_RW(tt_toggle);
267+
268+
/* PWM enable/disable functions */
159269
static int oxp_pwm_enable(void)
160270
{
161271
return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, 0x01);
@@ -206,6 +316,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
206316
case aya_neo_air_pro:
207317
case aya_neo_geek:
208318
case oxp_mini_amd:
319+
case oxp_mini_amd_a07:
209320
*val = (*val * 255) / 100;
210321
break;
211322
case oxp_mini_amd_pro:
@@ -247,6 +358,7 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
247358
case aya_neo_air_pro:
248359
case aya_neo_geek:
249360
case oxp_mini_amd:
361+
case oxp_mini_amd_a07:
250362
val = (val * 100) / 255;
251363
break;
252364
case aok_zoe_a1:
@@ -274,6 +386,13 @@ static const struct hwmon_channel_info * const oxp_platform_sensors[] = {
274386
NULL,
275387
};
276388

389+
static struct attribute *oxp_ec_attrs[] = {
390+
&dev_attr_tt_toggle.attr,
391+
NULL
392+
};
393+
394+
ATTRIBUTE_GROUPS(oxp_ec);
395+
277396
static const struct hwmon_ops oxp_ec_hwmon_ops = {
278397
.is_visible = oxp_ec_hwmon_is_visible,
279398
.read = oxp_platform_read,
@@ -291,6 +410,7 @@ static int oxp_platform_probe(struct platform_device *pdev)
291410
const struct dmi_system_id *dmi_entry;
292411
struct device *dev = &pdev->dev;
293412
struct device *hwdev;
413+
int ret;
294414

295415
/*
296416
* Have to check for AMD processor here because DMI strings are the
@@ -305,6 +425,18 @@ static int oxp_platform_probe(struct platform_device *pdev)
305425

306426
board = (enum oxp_board)(unsigned long)dmi_entry->driver_data;
307427

428+
switch (board) {
429+
case aok_zoe_a1:
430+
case oxp_mini_amd_a07:
431+
case oxp_mini_amd_pro:
432+
ret = devm_device_add_groups(dev, oxp_ec_groups);
433+
if (ret)
434+
return ret;
435+
break;
436+
default:
437+
break;
438+
}
439+
308440
hwdev = devm_hwmon_device_register_with_info(dev, "oxpec", NULL,
309441
&oxp_ec_chip_info, NULL);
310442

0 commit comments

Comments
 (0)