MCP2221_ALT_F_NOT_GPIOD = 0xEF,
 };
 
+/* MCP GPIO direction encoding */
+enum {
+       MCP2221_DIR_OUT = 0x00,
+       MCP2221_DIR_IN = 0x01,
+};
+
+#define MCP_NGPIO      4
+
+/* MCP GPIO set command layout */
+struct mcp_set_gpio {
+       u8 cmd;
+       u8 dummy;
+       struct {
+               u8 change_value;
+               u8 value;
+               u8 change_direction;
+               u8 direction;
+       } gpio[MCP_NGPIO];
+} __packed;
+
+/* MCP GPIO get command layout */
+struct mcp_get_gpio {
+       u8 cmd;
+       u8 dummy;
+       struct {
+               u8 direction;
+               u8 value;
+       } gpio[MCP_NGPIO];
+} __packed;
+
 /*
  * There is no way to distinguish responses. Therefore next command
  * is sent only after response to previous has been received. Mutex
 
        mcp->txbuf[0] = MCP2221_GPIO_GET;
 
-       mcp->gp_idx = (offset + 1) * 2;
+       mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].value);
 
        mutex_lock(&mcp->lock);
        ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1);
        memset(mcp->txbuf, 0, 18);
        mcp->txbuf[0] = MCP2221_GPIO_SET;
 
-       mcp->gp_idx = ((offset + 1) * 4) - 1;
+       mcp->gp_idx = offsetof(struct mcp_set_gpio, gpio[offset].value);
 
        mcp->txbuf[mcp->gp_idx - 1] = 1;
        mcp->txbuf[mcp->gp_idx] = !!value;
        memset(mcp->txbuf, 0, 18);
        mcp->txbuf[0] = MCP2221_GPIO_SET;
 
-       mcp->gp_idx = (offset + 1) * 5;
+       mcp->gp_idx = offsetof(struct mcp_set_gpio, gpio[offset].direction);
 
        mcp->txbuf[mcp->gp_idx - 1] = 1;
        mcp->txbuf[mcp->gp_idx] = val;
        struct mcp2221 *mcp = gpiochip_get_data(gc);
 
        mutex_lock(&mcp->lock);
-       ret = mcp_gpio_dir_set(mcp, offset, 0);
+       ret = mcp_gpio_dir_set(mcp, offset, MCP2221_DIR_IN);
        mutex_unlock(&mcp->lock);
 
        return ret;
        struct mcp2221 *mcp = gpiochip_get_data(gc);
 
        mutex_lock(&mcp->lock);
-       ret = mcp_gpio_dir_set(mcp, offset, 1);
+       ret = mcp_gpio_dir_set(mcp, offset, MCP2221_DIR_OUT);
        mutex_unlock(&mcp->lock);
 
        /* Can't configure as output, bailout early */
 
        mcp->txbuf[0] = MCP2221_GPIO_GET;
 
-       mcp->gp_idx = (offset + 1) * 2;
+       mcp->gp_idx = offsetof(struct mcp_get_gpio, gpio[offset].direction);
 
        mutex_lock(&mcp->lock);
        ret = mcp_send_data_req_status(mcp, mcp->txbuf, 1);
        if (ret)
                return ret;
 
-       if (mcp->gpio_dir)
+       if (mcp->gpio_dir == MCP2221_DIR_IN)
                return GPIO_LINE_DIRECTION_IN;
 
        return GPIO_LINE_DIRECTION_OUT;
                                mcp->status = -ENOENT;
                        } else {
                                mcp->status = !!data[mcp->gp_idx];
-                               mcp->gpio_dir = !!data[mcp->gp_idx + 1];
+                               mcp->gpio_dir = data[mcp->gp_idx + 1];
                        }
                        break;
                default:
        mcp->gc->get_direction = mcp_gpio_get_direction;
        mcp->gc->set = mcp_gpio_set;
        mcp->gc->get = mcp_gpio_get;
-       mcp->gc->ngpio = 4;
+       mcp->gc->ngpio = MCP_NGPIO;
        mcp->gc->base = -1;
        mcp->gc->can_sleep = 1;
        mcp->gc->parent = &hdev->dev;