/* * Driver for the Diolan DLN-2 USB-GPIO adapter * * Copyright (c) 2014 Intel Corporation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, version 2. */ #include #include #include #include #include #include #include #include #include #include #include #define DLN2_GPIO_ID 0x01 #define DLN2_GPIO_GET_PIN_COUNT DLN2_CMD(0x01, DLN2_GPIO_ID) #define DLN2_GPIO_SET_DEBOUNCE DLN2_CMD(0x04, DLN2_GPIO_ID) #define DLN2_GPIO_GET_DEBOUNCE DLN2_CMD(0x05, DLN2_GPIO_ID) #define DLN2_GPIO_PORT_GET_VAL DLN2_CMD(0x06, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_GET_VAL DLN2_CMD(0x0B, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_SET_OUT_VAL DLN2_CMD(0x0C, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_GET_OUT_VAL DLN2_CMD(0x0D, DLN2_GPIO_ID) #define DLN2_GPIO_CONDITION_MET_EV DLN2_CMD(0x0F, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_ENABLE DLN2_CMD(0x10, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_DISABLE DLN2_CMD(0x11, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_SET_DIRECTION DLN2_CMD(0x13, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_GET_DIRECTION DLN2_CMD(0x14, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_SET_EVENT_CFG DLN2_CMD(0x1E, DLN2_GPIO_ID) #define DLN2_GPIO_PIN_GET_EVENT_CFG DLN2_CMD(0x1F, DLN2_GPIO_ID) #define DLN2_GPIO_EVENT_NONE 0 #define DLN2_GPIO_EVENT_CHANGE 1 #define DLN2_GPIO_EVENT_LVL_HIGH 2 #define DLN2_GPIO_EVENT_LVL_LOW 3 #define DLN2_GPIO_EVENT_CHANGE_RISING 0x11 #define DLN2_GPIO_EVENT_CHANGE_FALLING 0x21 #define DLN2_GPIO_EVENT_MASK 0x0F #define DLN2_GPIO_MAX_PINS 32 struct dln2_gpio { struct platform_device *pdev; struct gpio_chip gpio; /* * Cache pin direction to save us one transfer, since the hardware has * separate commands to read the in and out values. */ DECLARE_BITMAP(output_enabled, DLN2_GPIO_MAX_PINS); /* active IRQs - not synced to hardware */ DECLARE_BITMAP(unmasked_irqs, DLN2_GPIO_MAX_PINS); /* active IRQS - synced to hardware */ DECLARE_BITMAP(enabled_irqs, DLN2_GPIO_MAX_PINS); int irq_type[DLN2_GPIO_MAX_PINS]; struct mutex irq_lock; }; struct dln2_gpio_pin { __le16 pin; }; struct dln2_gpio_pin_val { __le16 pin __packed; u8 value; }; static int dln2_gpio_get_pin_count(struct platform_device *pdev) { int ret; __le16 count; int len = sizeof(count); ret = dln2_transfer_rx(pdev, DLN2_GPIO_GET_PIN_COUNT, &count, &len); if (ret < 0) return ret; if (len < sizeof(count)) return -EPROTO; return le16_to_cpu(count); } static int dln2_gpio_pin_cmd(struct dln2_gpio *dln2, int cmd, unsigned pin) { struct dln2_gpio_pin req = { .pin = cpu_to_le16(pin), }; return dln2_transfer_tx(dln2->pdev, cmd, &req, sizeof(req)); } static int dln2_gpio_pin_val(struct dln2_gpio *dln2, int cmd, unsigned int pin) { int ret; struct dln2_gpio_pin req = { .pin = cpu_to_le16(pin), }; struct dln2_gpio_pin_val rsp; int len = sizeof(rsp); ret = dln2_transfer(dln2->pdev, cmd, &req, sizeof(req), &rsp, &len); if (ret < 0) return ret; if (len < sizeof(rsp) || req.pin != rsp.pin) return -EPROTO; return rsp.value; } static int dln2_gpio_pin_get_in_val(struct dln2_gpio *dln2, unsigned int pin) { int ret; ret = dln2_gpio_pin_val(dln2, DLN2_GPIO_PIN_GET_VAL, pin); if (ret < 0) return ret; return !!ret; } static int dln2_gpio_pin_get_out_val(struct dln2_gpio *dln2, unsigned int pin) { int ret; ret = dln2_gpio_pin_val(dln2, DLN2_GPIO_PIN_GET_OUT_VAL, pin); if (ret < 0) return ret; return !!ret; } static int dln2_gpio_pin_set_out_val(struct dln2_gpio *dln2, unsigned int pin, int value) { struct dln2_gpio_pin_val req = { .pin = cpu_to_le16(pin),
Project Name: Compass4nfv
Repo name: compass4nfv
Project Category: Integration and testing
Lifecycle State: Proposal approved
Primary Contact: Weidong shao(weidong.shao@huawei.com)
Project Lead: Weidong shao
Jira Project Name: Compass4nfv
Jira Project Prefix: COMPASS
mailing list tag [COMPASS]
Committers:
Weidong shao (weidong.shao@huawei.com)
Prakash Ramchandran (Prakash.Ramchandran@huawei.com)
Justin chi (chigang@huawei.com)
Iben Rodrigues (iben.rodriguez@spirent.com)
Tim Rozet (trozet@redhat.com)
Chenshuai (chenshuai@huawei.com)
Ashlee Young (ashlee@onosfw.com)
Link to TSC approval: http://ircbot.wl.linuxfoundation.org/meetings/opnfv-meeting/2015/opnfv