⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftdi-elan.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      wait:if (ftdi->disconnected > 0) {                return -ENODEV;        } else {                int command_size;                mutex_lock(&ftdi->u132_lock);                command_size = ftdi->command_next - ftdi->command_head;                if (command_size < COMMAND_SIZE) {                        struct u132_command *command = &ftdi->command[                                COMMAND_MASK & ftdi->command_next];                        command->header = 0x00 | (cPCIcfgwr & 0x0F);                        command->length = 0x04;                        command->address = addressofs;                        command->width = 0x00 | (width & 0x0F);                        command->follows = 4;                        command->value = data;                        command->buffer = &command->value;                        ftdi->command_next += 1;                        ftdi_elan_kick_command_queue(ftdi);                        mutex_unlock(&ftdi->u132_lock);                        return 0;                } else {                        mutex_unlock(&ftdi->u132_lock);                        msleep(100);                        goto wait;                }        }}static int ftdi_elan_write_pcimem(struct usb_ftdi *ftdi, int mem_offset,        u8 width, u32 data){        u8 addressofs = mem_offset / 4;      wait:if (ftdi->disconnected > 0) {                return -ENODEV;        } else {                int command_size;                mutex_lock(&ftdi->u132_lock);                command_size = ftdi->command_next - ftdi->command_head;                if (command_size < COMMAND_SIZE) {                        struct u132_command *command = &ftdi->command[                                COMMAND_MASK & ftdi->command_next];                        command->header = 0x00 | (cPCImemwr & 0x0F);                        command->length = 0x04;                        command->address = addressofs;                        command->width = 0x00 | (width & 0x0F);                        command->follows = 4;                        command->value = data;                        command->buffer = &command->value;                        ftdi->command_next += 1;                        ftdi_elan_kick_command_queue(ftdi);                        mutex_unlock(&ftdi->u132_lock);                        return 0;                } else {                        mutex_unlock(&ftdi->u132_lock);                        msleep(100);                        goto wait;                }        }}int usb_ftdi_elan_write_pcimem(struct platform_device *pdev, int mem_offset,        u8 width, u32 data){        struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);        return ftdi_elan_write_pcimem(ftdi, mem_offset, width, data);}EXPORT_SYMBOL_GPL(usb_ftdi_elan_write_pcimem);static int ftdi_elan_read_reg(struct usb_ftdi *ftdi, u32 *data){      wait:if (ftdi->disconnected > 0) {                return -ENODEV;        } else {                int command_size;                int respond_size;                mutex_lock(&ftdi->u132_lock);                command_size = ftdi->command_next - ftdi->command_head;                respond_size = ftdi->respond_next - ftdi->respond_head;                if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)                        {                        struct u132_command *command = &ftdi->command[                                COMMAND_MASK & ftdi->command_next];                        struct u132_respond *respond = &ftdi->respond[                                RESPOND_MASK & ftdi->respond_next];                        int result = -ENODEV;                        respond->result = &result;                        respond->header = command->header = 0x00 | cPCIu132rd;                        command->length = 0x04;                        respond->address = command->address = cU132cmd_status;                        command->width = 0x00;                        command->follows = 0;                        command->value = 0;                        command->buffer = NULL;                        respond->value = data;                        init_completion(&respond->wait_completion);                        ftdi->command_next += 1;                        ftdi->respond_next += 1;                        ftdi_elan_kick_command_queue(ftdi);                        mutex_unlock(&ftdi->u132_lock);                        wait_for_completion(&respond->wait_completion);                        return result;                } else {                        mutex_unlock(&ftdi->u132_lock);                        msleep(100);                        goto wait;                }        }}static int ftdi_elan_read_config(struct usb_ftdi *ftdi, int config_offset,        u8 width, u32 *data){        u8 addressofs = config_offset / 4;      wait:if (ftdi->disconnected > 0) {                return -ENODEV;        } else {                int command_size;                int respond_size;                mutex_lock(&ftdi->u132_lock);                command_size = ftdi->command_next - ftdi->command_head;                respond_size = ftdi->respond_next - ftdi->respond_head;                if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)                        {                        struct u132_command *command = &ftdi->command[                                COMMAND_MASK & ftdi->command_next];                        struct u132_respond *respond = &ftdi->respond[                                RESPOND_MASK & ftdi->respond_next];                        int result = -ENODEV;                        respond->result = &result;                        respond->header = command->header = 0x00 | (cPCIcfgrd &                                0x0F);                        command->length = 0x04;                        respond->address = command->address = addressofs;                        command->width = 0x00 | (width & 0x0F);                        command->follows = 0;                        command->value = 0;                        command->buffer = NULL;                        respond->value = data;                        init_completion(&respond->wait_completion);                        ftdi->command_next += 1;                        ftdi->respond_next += 1;                        ftdi_elan_kick_command_queue(ftdi);                        mutex_unlock(&ftdi->u132_lock);                        wait_for_completion(&respond->wait_completion);                        return result;                } else {                        mutex_unlock(&ftdi->u132_lock);                        msleep(100);                        goto wait;                }        }}static int ftdi_elan_read_pcimem(struct usb_ftdi *ftdi, int mem_offset,        u8 width, u32 *data){        u8 addressofs = mem_offset / 4;      wait:if (ftdi->disconnected > 0) {                return -ENODEV;        } else {                int command_size;                int respond_size;                mutex_lock(&ftdi->u132_lock);                command_size = ftdi->command_next - ftdi->command_head;                respond_size = ftdi->respond_next - ftdi->respond_head;                if (command_size < COMMAND_SIZE && respond_size < RESPOND_SIZE)                        {                        struct u132_command *command = &ftdi->command[                                COMMAND_MASK & ftdi->command_next];                        struct u132_respond *respond = &ftdi->respond[                                RESPOND_MASK & ftdi->respond_next];                        int result = -ENODEV;                        respond->result = &result;                        respond->header = command->header = 0x00 | (cPCImemrd &                                0x0F);                        command->length = 0x04;                        respond->address = command->address = addressofs;                        command->width = 0x00 | (width & 0x0F);                        command->follows = 0;                        command->value = 0;                        command->buffer = NULL;                        respond->value = data;                        init_completion(&respond->wait_completion);                        ftdi->command_next += 1;                        ftdi->respond_next += 1;                        ftdi_elan_kick_command_queue(ftdi);                        mutex_unlock(&ftdi->u132_lock);                        wait_for_completion(&respond->wait_completion);                        return result;                } else {                        mutex_unlock(&ftdi->u132_lock);                        msleep(100);                        goto wait;                }        }}int usb_ftdi_elan_read_pcimem(struct platform_device *pdev, int mem_offset,        u8 width, u32 *data){        struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);        if (ftdi->initialized == 0) {                return -ENODEV;        } else                return ftdi_elan_read_pcimem(ftdi, mem_offset, width, data);}EXPORT_SYMBOL_GPL(usb_ftdi_elan_read_pcimem);static int ftdi_elan_edset_setup(struct usb_ftdi *ftdi, u8 ed_number,        void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,        void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,        int toggle_bits, int error_count, int condition_code, int repeat_number,         int halted, int skipped, int actual, int non_null)){        u8 ed = ed_number - 1;      wait:if (ftdi->disconnected > 0) {                return -ENODEV;        } else if (ftdi->initialized == 0) {                return -ENODEV;        } else {                int command_size;                mutex_lock(&ftdi->u132_lock);                command_size = ftdi->command_next - ftdi->command_head;                if (command_size < COMMAND_SIZE) {                        struct u132_target *target = &ftdi->target[ed];                        struct u132_command *command = &ftdi->command[                                COMMAND_MASK & ftdi->command_next];                        command->header = 0x80 | (ed << 5);                        command->length = 0x8007;                        command->address = (toggle_bits << 6) | (ep_number << 2)                                | (address << 0);                        command->width = usb_maxpacket(urb->dev, urb->pipe,                                usb_pipeout(urb->pipe));                        command->follows = 8;                        command->value = 0;                        command->buffer = urb->setup_packet;                        target->callback = callback;                        target->endp = endp;                        target->urb = urb;                        target->active = 1;                        ftdi->command_next += 1;                        ftdi_elan_kick_command_queue(ftdi);                        mutex_unlock(&ftdi->u132_lock);                        return 0;                } else {                        mutex_unlock(&ftdi->u132_lock);                        msleep(100);                        goto wait;                }        }}int usb_ftdi_elan_edset_setup(struct platform_device *pdev, u8 ed_number,        void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,        void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,        int toggle_bits, int error_count, int condition_code, int repeat_number,         int halted, int skipped, int actual, int non_null)){        struct usb_ftdi *ftdi = platform_device_to_usb_ftdi(pdev);        return ftdi_elan_edset_setup(ftdi, ed_number, endp, urb, address,                ep_number, toggle_bits, callback);}EXPORT_SYMBOL_GPL(usb_ftdi_elan_edset_setup);static int ftdi_elan_edset_input(struct usb_ftdi *ftdi, u8 ed_number,        void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,        void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,        int toggle_bits, int error_count, int condition_code, int repeat_number,         int halted, int skipped, int actual, int non_null)){        u8 ed = ed_number - 1;      wait:if (ftdi->disconnected > 0) {                return -ENODEV;        } else if (ftdi->initialized == 0) {                return -ENODEV;        } else {                int command_size;                mutex_lock(&ftdi->u132_lock);                command_size = ftdi->command_next - ftdi->command_head;                if (command_size < COMMAND_SIZE) {                        struct u132_target *target = &ftdi->target[ed];                        struct u132_command *command = &ftdi->command[                                COMMAND_MASK & ftdi->command_next];                        int remaining_length = urb->transfer_buffer_length -                                urb->actual_length;                        command->header = 0x82 | (ed << 5);                        if (remaining_length == 0) {                                command->length = 0x0000;                        } else if (remaining_length > 1024) {                                command->length = 0x8000 | 1023;                        } else                                command->length = 0x8000 | (remaining_length -                                        1);                        command->address = (toggle_bits << 6) | (ep_number << 2)                                | (address << 0);                        command->width = usb_maxpacket(urb->dev, urb->pipe,                                usb_pipeout(urb->pipe));                        command->follows = 0;                        command->value = 0;                        command->buffer = NULL;                        target->callback = callback;                        target->endp = endp;                        target->urb = urb;                        target->active = 1;                        ftdi->command_next += 1;                        ftdi_elan_kick_command_queue(ftdi);                        mutex_unlock(&ftdi->u132_lock);                        return 0;                } else {                        mutex_unlock(&ftdi->u132_lock);                        msleep(100);                        goto wait;                }        }}int usb_ftdi_elan_edset_input(struct platform_device *pdev, u8 ed_number,        void *endp, struct urb *urb, u8 address, u8 ep_number, u8 toggle_bits,        void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,        int toggle_bits, int error_count, int condition_code,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -