0005-ec-dell-mec5035-Replace-defines-with-enums.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From 318c411c827eb7b2a703d206b55ed357552ea25b Mon Sep 17 00:00:00 2001
  2. From: Nicholas Chin <nic.c3.14@gmail.com>
  3. Date: Tue, 28 May 2024 17:23:21 -0600
  4. Subject: [PATCH 05/18] ec/dell/mec5035: Replace defines with enums
  5. Instead of using defines for command IDs and argument values, use enums
  6. to provide more type safety. This also has the effect of moving the
  7. command IDs to a more central location instead of defines spread out
  8. throughout the header.
  9. Change-Id: I788531e8b70e79541213853f177326d217235ef2
  10. Signed-off-by: Nicholas Chin <nic.c3.14@gmail.com>
  11. Reviewed-on: https://review.coreboot.org/c/coreboot/+/82998
  12. Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
  13. Reviewed-by: Felix Singer <service+coreboot-gerrit@felixsinger.de>
  14. ---
  15. src/ec/dell/mec5035/mec5035.c | 10 +++++-----
  16. src/ec/dell/mec5035/mec5035.h | 20 ++++++++++++--------
  17. 2 files changed, 17 insertions(+), 13 deletions(-)
  18. diff --git a/src/ec/dell/mec5035/mec5035.c b/src/ec/dell/mec5035/mec5035.c
  19. index 68b6b2f7fb..dffbb7960c 100644
  20. --- a/src/ec/dell/mec5035/mec5035.c
  21. +++ b/src/ec/dell/mec5035/mec5035.c
  22. @@ -66,17 +66,17 @@ static enum cb_err write_mailbox_regs(const u8 *data, u8 start, u8 count)
  23. return CB_SUCCESS;
  24. }
  25. -static void ec_command(u8 cmd)
  26. +static void ec_command(enum mec5035_cmd cmd)
  27. {
  28. outb(0, MAILBOX_INDEX);
  29. - outb(cmd, MAILBOX_DATA);
  30. + outb((u8)cmd, MAILBOX_DATA);
  31. wait_ec();
  32. }
  33. -u8 mec5035_mouse_touchpad(u8 setting)
  34. +u8 mec5035_mouse_touchpad(enum ec_mouse_setting setting)
  35. {
  36. - u8 buf[15] = {0};
  37. - write_mailbox_regs(&setting, 2, 1);
  38. + u8 buf[15] = {(u8)setting};
  39. + write_mailbox_regs(buf, 2, 1);
  40. ec_command(CMD_MOUSE_TP);
  41. /* The vendor firmware reads 15 bytes starting at index 1, presumably
  42. to get some sort of return code. Though I don't know for sure if
  43. diff --git a/src/ec/dell/mec5035/mec5035.h b/src/ec/dell/mec5035/mec5035.h
  44. index fa15a9d621..32f791cb01 100644
  45. --- a/src/ec/dell/mec5035/mec5035.h
  46. +++ b/src/ec/dell/mec5035/mec5035.h
  47. @@ -7,16 +7,20 @@
  48. #define NUM_REGISTERS 32
  49. +enum mec5035_cmd {
  50. + CMD_MOUSE_TP = 0x1a,
  51. + CMD_RADIO_CTRL = 0x2b,
  52. + CMD_CPU_OK = 0xc2,
  53. +};
  54. +
  55. /* Touchpad (TP) and mouse related. The EC seems to
  56. default to 0 which results in the TP not working. */
  57. -#define CMD_MOUSE_TP 0x1a
  58. -#define SERIAL_MOUSE 0 /* Disable TP, force use of a serial mouse */
  59. -#define PS2_MOUSE 1 /* Disable TP when using a PS/2 mouse */
  60. -#define TP_PS2_MOUSE 2 /* Leave TP enabled when using a PS/2 mouse */
  61. -
  62. -#define CMD_CPU_OK 0xc2
  63. +enum ec_mouse_setting {
  64. + SERIAL_MOUSE = 0, /* Disable TP, force use of a serial mouse */
  65. + PS2_MOUSE, /* Disable TP when using a PS/2 mouse */
  66. + TP_PS2_MOUSE /* Leave TP enabled when using a PS/2 mouse */
  67. +};
  68. -#define CMD_RADIO_CTRL 0x2b
  69. #define RADIO_CTRL_NUM_ARGS 3
  70. enum ec_radio_dev {
  71. RADIO_WLAN = 0,
  72. @@ -29,7 +33,7 @@ enum ec_radio_state {
  73. RADIO_ON
  74. };
  75. -u8 mec5035_mouse_touchpad(u8 setting);
  76. +u8 mec5035_mouse_touchpad(enum ec_mouse_setting setting);
  77. void mec5035_cpu_ok(void);
  78. void mec5035_early_init(void);
  79. void mec5035_control_radio(enum ec_radio_dev device, enum ec_radio_state state);
  80. --
  81. 2.39.5