Use the newly introduced NVEC_CALL to cleanup the various nvec
command strings in the nvec driver.

Signed-off-by: Marc Dietrich <[email protected]>
---
 drivers/staging/nvec/nvec.c       |   39 +++++++++++++++--------------
 drivers/staging/nvec/nvec.h       |   49 ++++++++++++++++++++++++++++++++++++-
 drivers/staging/nvec/nvec_kbd.c   |   31 ++++++++++++-----------
 drivers/staging/nvec/nvec_leds.c  |    5 +---
 drivers/staging/nvec/nvec_power.c |   12 ++++-----
 drivers/staging/nvec/nvec_ps2.c   |   25 ++++++-------------
 6 files changed, 98 insertions(+), 63 deletions(-)

diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index a2d65f0..dd8b317 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -73,10 +73,6 @@ enum nvec_msg_category  {
        NVEC_MSG_TX,
 };
 
-static const unsigned char EC_DISABLE_EVENT_REPORTING[3] = "\x04\x00\x00";
-static const unsigned char EC_ENABLE_EVENT_REPORTING[3]  = "\x04\x00\x01";
-static const unsigned char EC_GET_FIRMWARE_VERSION[2]    = "\x07\x15";
-
 static struct nvec_chip *nvec_power_handle;
 
 static struct mfd_cell nvec_devices[] = {
@@ -711,8 +707,11 @@ static void nvec_disable_i2c_slave(struct nvec_chip *nvec)
 
 static void nvec_power_off(void)
 {
-       nvec_write_async(nvec_power_handle, EC_DISABLE_EVENT_REPORTING, 3);
-       nvec_write_async(nvec_power_handle, "\x04\x01", 2);
+       /* disable event reporting */
+       NVEC_CALL(nvec_power_handle, SLEEP, GLOBAL_EVENTS, NVEC_DISABLE);
+
+       /* AP power down */
+       NVEC_CALL(nvec_power_handle, SLEEP, AP_PWR_DOWN);
 }
 
 static int __devinit tegra_nvec_probe(struct platform_device *pdev)
@@ -818,8 +817,7 @@ static int __devinit tegra_nvec_probe(struct 
platform_device *pdev)
 
 
        /* enable event reporting */
-       nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING,
-                        sizeof(EC_ENABLE_EVENT_REPORTING));
+       NVEC_CALL(nvec, SLEEP, GLOBAL_EVENTS, NVEC_ENABLE);
 
        nvec->nvec_status_notifier.notifier_call = nvec_status_notifier;
        nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0);
@@ -828,9 +826,7 @@ static int __devinit tegra_nvec_probe(struct 
platform_device *pdev)
        pm_power_off = nvec_power_off;
 
        /* Get Firmware Version */
-       msg = nvec_write_sync(nvec, EC_GET_FIRMWARE_VERSION,
-               sizeof(EC_GET_FIRMWARE_VERSION));
-
+       msg = NVEC_SYNC_CALL(nvec, CNTL, READ_FW_VER);
        if (msg) {
                dev_warn(nvec->dev, "ec firmware version %02x.%02x.%02x / 
%02x\n",
                        msg->data[4], msg->data[5], msg->data[6], msg->data[7]);
@@ -843,14 +839,14 @@ static int __devinit tegra_nvec_probe(struct 
platform_device *pdev)
        if (ret)
                dev_err(nvec->dev, "error adding subdevices\n");
 
-       /* unmute speakers? */
-       nvec_write_async(nvec, "\x0d\x10\x59\x95", 4);
+       /* unmute speaker amplifier */
+       NVEC_CALL(nvec, OEM0, 10h, 0x59, 0x95);
 
        /* enable lid switch event */
-       nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x02\x00", 7);
+       NVEC_CALL(nvec, SYS, CNF_EVENT_REPORTING, NVEC_ENABLE, 0, 0, 0x02, 0);
 
        /* enable power button event */
-       nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x80\x00", 7);
+       NVEC_CALL(nvec, SYS, CNF_EVENT_REPORTING, NVEC_ENABLE, 0, 0, 0x80, 0);
 
        return 0;
 }
@@ -859,7 +855,9 @@ static int __devexit tegra_nvec_remove(struct 
platform_device *pdev)
 {
        struct nvec_chip *nvec = platform_get_drvdata(pdev);
 
-       nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3);
+       /* disable global event reporting */
+       NVEC_CALL(nvec, SLEEP, GLOBAL_EVENTS, NVEC_DISABLE);
+
        mfd_remove_devices(nvec->dev);
        destroy_workqueue(nvec->wq);
 
@@ -876,9 +874,9 @@ static int nvec_suspend(struct device *dev)
        dev_dbg(nvec->dev, "suspending\n");
 
        /* keep these sync or you'll break suspend */
-       msg = nvec_write_sync(nvec, EC_DISABLE_EVENT_REPORTING, 3);
+       msg = NVEC_SYNC_CALL(nvec, SLEEP, GLOBAL_EVENTS, NVEC_DISABLE);
        nvec_msg_free(nvec, msg);
-       msg = nvec_write_sync(nvec, "\x04\x02", 2);
+       msg = NVEC_SYNC_CALL(nvec, SLEEP, AP_SUSPEND);
        nvec_msg_free(nvec, msg);
 
        nvec_disable_i2c_slave(nvec);
@@ -892,8 +890,11 @@ static int nvec_resume(struct device *dev)
        struct nvec_chip *nvec = platform_get_drvdata(pdev);
 
        dev_dbg(nvec->dev, "resuming\n");
+
        tegra_init_i2c_slave(nvec);
-       nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING, 3);
+
+       /* enable global event reporting */
+       NVEC_CALL(nvec, SLEEP, GLOBAL_EVENTS, NVEC_ENABLE);
 
        return 0;
 }
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index 3c56875..ae5e574 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -59,6 +59,8 @@ enum nvec_event_size {
  * enum nvec_msg_type - The type of a message
  * @NVEC_SYS: A system request/response
  * @NVEC_BAT: A battery request/response
+ * @NVEC_GPIO: A gpio request/response
+ * @NVEC_SLEEP: A sleep request/response
  * @NVEC_KBD: A keyboard request/response
  * @NVEC_PS2: A mouse request/response
  * @NVEC_CNTL: A EC control request/response
@@ -71,13 +73,58 @@ enum nvec_event_size {
 enum nvec_msg_type {
        NVEC_SYS = 1,
        NVEC_BAT,
-       NVEC_KBD = 5,
+       NVEC_GPIO,
+       NVEC_SLEEP,
+       NVEC_KBD,
        NVEC_PS2,
        NVEC_CNTL,
+       NVEC_OEM0 = 0x0d,
        NVEC_KB_EVT = 0x80,
        NVEC_PS2_EVT,
 };
 
+enum nvec_bool {
+       NVEC_DISABLE,
+       NVEC_ENABLE,
+};
+
+enum nvec_sys_subcmd {
+       NVEC_SYS_GET_SYSTEM_STATUS,
+       NVEC_SYS_CNF_EVENT_REPORTING,
+       NVEC_SYS_ACK_SYSTEM_STATUS,
+       NVEC_SYS_CNF_WAKE = 0xfd,
+};
+
+enum nvec_sleep_subcmd {
+       NVEC_SLEEP_GLOBAL_EVENTS,
+       NVEC_SLEEP_AP_PWR_DOWN,
+       NVEC_SLEEP_AP_SUSPEND,
+};
+
+enum nvec_cntl_subcmd {
+       NVEC_CNTL_READ_FW_VER = 0x15,
+};
+
+enum nvec_kbd_subcmd {
+       NVEC_KBD_CNF_WAKE = 3,
+       NVEC_KBD_CNF_WAKE_KEY_REPORTING,
+       NVEC_KBD_SET_LEDS = 0xed,
+       NVEC_KBD_KBD_ENABLE = 0xf4,
+};
+
+enum nvec_ps2_subcmd {
+       NVEC_PS2_SEND_CMD = 1,
+       NVEC_PS2_RECEIVE,
+       NVEC_PS2_AUTO_RECEIVE,
+       NVEC_PS2_CANCEL_AUTO_RECEIVE = 4,
+       NVEC_PS2_PS2_ENABLE = 0xf4,
+       NVEC_PS2_PS2_DISABLE,
+};
+
+enum nvec_oem0_subcmd {
+       NVEC_OEM0_10h = 0x10,
+};
+
 /* construct a nvec command string */
 #define NVEC_CMD_STR(type, subtype, payload...)                \
        { NVEC_##type, NVEC_##type##_##subtype, payload }
diff --git a/drivers/staging/nvec/nvec_kbd.c b/drivers/staging/nvec/nvec_kbd.c
index 36ef6a6..d1dd10e 100644
--- a/drivers/staging/nvec/nvec_kbd.c
+++ b/drivers/staging/nvec/nvec_kbd.c
@@ -21,10 +21,6 @@
 #include "nvec-keytable.h"
 #include "nvec.h"
 
-#define ACK_KBD_EVENT {'\x05', '\xed', '\x01'}
-
-static const char led_on[3] = "\x05\xed\x07";
-static const char led_off[3] = "\x05\xed\x00";
 static unsigned char keycodes[ARRAY_SIZE(code_tab_102us)
                              + ARRAY_SIZE(extcode_tab_us102)];
 
@@ -42,9 +38,11 @@ static void nvec_kbd_toggle_led(void)
        keys_dev.caps_lock = !keys_dev.caps_lock;
 
        if (keys_dev.caps_lock)
-               nvec_write_async(keys_dev.nvec, led_on, sizeof(led_on));
+               /* FIXME: should be BIT(0) only */
+               NVEC_CALL(keys_dev.nvec, KBD, SET_LEDS,
+                               (BIT(0) | BIT(1) | BIT(2)));
        else
-               nvec_write_async(keys_dev.nvec, led_off, sizeof(led_off));
+               NVEC_CALL(keys_dev.nvec, KBD, SET_LEDS, 0);
 }
 
 static int nvec_keys_notifier(struct notifier_block *nb,
@@ -82,7 +80,7 @@ static int nvec_keys_notifier(struct notifier_block *nb,
 static int nvec_kbd_event(struct input_dev *dev, unsigned int type,
                          unsigned int code, int value)
 {
-       unsigned char buf[] = ACK_KBD_EVENT;
+       unsigned char buf[] = NVEC_CMD_STR(KBD, SET_LEDS, 0);
        struct nvec_chip *nvec = keys_dev.nvec;
 
        if (type == EV_REP)
@@ -137,20 +135,21 @@ static int __devinit nvec_kbd_probe(struct 
platform_device *pdev)
        keys_dev.nvec = nvec;
        nvec_register_notifier(nvec, &keys_dev.notifier, 0);
 
-       /* Enable keyboard */
-       nvec_write_async(nvec, "\x05\xf4", 2);
-
-       /* keyboard reset? */
-       nvec_write_async(nvec, "\x05\x03\x01\x01", 4);
-       nvec_write_async(nvec, "\x05\x04\x01", 3);
-       nvec_write_async(nvec, "\x06\x01\xff\x03", 4);
+       /* enable keyboard */
+       NVEC_CALL(nvec, KBD, KBD_ENABLE);
+       /* enable keyboard wake on special keys */
+       NVEC_CALL(nvec, KBD, CNF_WAKE, NVEC_ENABLE, BIT(1));
+       /* enable keyboard wake key reporting */
+       NVEC_CALL(nvec, KBD, CNF_WAKE_KEY_REPORTING, NVEC_ENABLE);
+       /* ps/2 mouse reset */
+       NVEC_CALL(nvec, PS2, SEND_CMD, 0xff, 0x03);
 /*     FIXME
        wait until keyboard reset is finished
        or until we have a sync write */
        mdelay(1000);
 
-       /* Disable caps lock LED */
-       nvec_write_async(nvec, led_off, sizeof(led_off));
+       /* switch off all LEDs */
+       NVEC_CALL(nvec, KBD, SET_LEDS, 0);
 
        return 0;
 
diff --git a/drivers/staging/nvec/nvec_leds.c b/drivers/staging/nvec/nvec_leds.c
index 53cb571..6796d75 100644
--- a/drivers/staging/nvec/nvec_leds.c
+++ b/drivers/staging/nvec/nvec_leds.c
@@ -21,8 +21,6 @@
 #define to_nvec_led(led_cdev) \
        container_of(led_cdev, struct nvec_led, cdev)
 
-#define NVEC_LED_REQ {'\x0d', '\x10', '\x45', '\x10', '\x00'}
-
 #define NVEC_LED_MAX 8
 
 struct nvec_led {
@@ -34,13 +32,12 @@ static void nvec_led_brightness_set(struct led_classdev 
*led_cdev,
                                    enum led_brightness value)
 {
        struct nvec_led *led = to_nvec_led(led_cdev);
-       unsigned char buf[] = NVEC_LED_REQ;
+       unsigned char buf[] = { NVEC_OEM0, 0x10, 0x45, 0x10, 0 };
        buf[4] = value;
 
        nvec_write_async(led->nvec, buf, sizeof(buf));
 
        led->cdev.brightness = value;
-
 }
 
 static int __devinit nvec_led_probe(struct platform_device *pdev)
diff --git a/drivers/staging/nvec/nvec_power.c 
b/drivers/staging/nvec/nvec_power.c
index 063f6d5..96c4635 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -111,7 +111,7 @@ static const int bat_init[] = {
 static void get_bat_mfg_data(struct nvec_power *power)
 {
        int i;
-       char buf[] = { '\x02', '\x00' };
+       char buf[] = { NVEC_BAT, 0 };
 
        for (i = 0; i < ARRAY_SIZE(bat_init); i++) {
                buf[1] = bat_init[i];
@@ -348,20 +348,20 @@ static int const bat_iter[] = {
 
 static void nvec_power_poll(struct work_struct *work)
 {
-       char buf[] = { '\x01', '\x00' };
+       char buf[] = { NVEC_SYS, 0 };
        struct nvec_power *power = container_of(work, struct nvec_power,
                                                poller.work);
 
        if (counter >= ARRAY_SIZE(bat_iter))
                counter = 0;
 
-/* AC status via sys req */
+       /* AC status via sys req */
        nvec_write_async(power->nvec, buf, 2);
        msleep(100);
 
-/* select a battery request function via round robin
-   doing it all at once seems to overload the power supply */
-       buf[0] = '\x02';        /* battery */
+       /* select a battery request function via round robin
+          doing it all at once seems to overload the power supply */
+       buf[0] = NVEC_BAT;
        buf[1] = bat_iter[counter++];
        nvec_write_async(power->nvec, buf, 2);
 
diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c
index 8b66cc0..f6582d6 100644
--- a/drivers/staging/nvec/nvec_ps2.c
+++ b/drivers/staging/nvec/nvec_ps2.c
@@ -21,9 +21,7 @@
 
 #include "nvec.h"
 
-#define START_STREAMING        {'\x06', '\x03', '\x06'}
-#define STOP_STREAMING {'\x06', '\x04'}
-#define SEND_COMMAND   {'\x06', '\x01', '\xf4', '\x01'}
+#define PACKET_SIZE 6
 
 #ifdef NVEC_PS2_DEBUG
 #define NVEC_PHD(str, buf, len) \
@@ -33,8 +31,6 @@
 #define NVEC_PHD(str, buf, len)
 #endif
 
-static const unsigned char MOUSE_RESET[] = {'\x06', '\x01', '\xff', '\x03'};
-
 struct nvec_ps2 {
        struct serio *ser_dev;
        struct notifier_block notifier;
@@ -45,19 +41,17 @@ static struct nvec_ps2 ps2_dev;
 
 static int ps2_startstreaming(struct serio *ser_dev)
 {
-       unsigned char buf[] = START_STREAMING;
-       return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
+       return NVEC_CALL(ps2_dev.nvec, PS2, AUTO_RECEIVE, PACKET_SIZE);
 }
 
 static void ps2_stopstreaming(struct serio *ser_dev)
 {
-       unsigned char buf[] = STOP_STREAMING;
-       nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
+       NVEC_CALL(ps2_dev.nvec, PS2, CANCEL_AUTO_RECEIVE);
 }
 
 static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd)
 {
-       unsigned char buf[] = SEND_COMMAND;
+       unsigned char buf[] = NVEC_CMD_STR(PS2, SEND_CMD, 0, 1);
 
        buf[2] = cmd & 0xff;
 
@@ -118,7 +112,7 @@ static int __devinit nvec_mouse_probe(struct 
platform_device *pdev)
        serio_register_port(ser_dev);
 
        /* mouse reset */
-       nvec_write_async(nvec, MOUSE_RESET, 4);
+       NVEC_CALL(ps2_dev.nvec, PS2, SEND_CMD, 0xff, 0x03);
 
        return 0;
 }
@@ -129,11 +123,8 @@ static int nvec_mouse_suspend(struct device *dev)
        struct platform_device *pdev = to_platform_device(dev);
        struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
 
-       /* disable mouse */
-       nvec_write_async(nvec, "\x06\xf4", 2);
-
-       /* send cancel autoreceive */
-       nvec_write_async(nvec, "\x06\x04", 2);
+       NVEC_CALL(nvec, PS2, PS2_DISABLE);
+       NVEC_CALL(nvec, PS2, CANCEL_AUTO_RECEIVE);
 
        return 0;
 }
@@ -146,7 +137,7 @@ static int nvec_mouse_resume(struct device *dev)
        ps2_startstreaming(ps2_dev.ser_dev);
 
        /* enable mouse */
-       nvec_write_async(nvec, "\x06\xf5", 2);
+       NVEC_CALL(nvec, PS2, PS2_ENABLE);
 
        return 0;
 }
-- 
1.7.9.5

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Reply via email to