/* * EZ-USB specific functions used by some of the USB to Serial drivers. * * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 as published by the Free Software Foundation. */ #include #include #include #include #include #include #include struct ezusb_fx_type { /* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */ unsigned short cpucs_reg; unsigned short max_internal_adress; }; static const struct ezusb_fx_type ezusb_fx1 = { .cpucs_reg = 0x7F92, .max_internal_adress = 0x1B3F, }; /* Commands for writing to memory */ #define WRITE_INT_RAM 0xA0 #define WRITE_EXT_RAM 0xA3 static int ezusb_writememory(struct usb_device *dev, int address, unsigned char *data, int length, __u8 request) { int result; unsigned char *transfer_buffer; if (!dev) return -ENODEV; transfer_buffer = kmemdup(data, length, GFP_KERNEL); if (!transfer_buffer) { dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n", __func__, length); return -ENOMEM; } result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, address, 0, transfer_buffer, length, 3000); kfree(transfer_buffer); return result; } static int ezusb_set_reset(struct usb_device *dev, unsigned short cpucs_reg, unsigned char reset_bit) { int response = ezusb_writememory(dev, cpucs_reg, &reset_bit, 1, WRITE_INT_RAM); if (response < 0) dev_err(&dev->dev, "%s-%d failed: %d\n", __func__, reset_bit, response); return response; } int ezusb_fx1_set_reset(struct usb_device *dev, unsigned char reset_bit) { return ezusb_set_reset(dev, ezusb_fx1.cpucs_reg, reset_bit); } EXPORT_SYMBOL_GPL(ezusb_fx1_set_reset); static int ezusb_ihex_firmware_download(struct usb_device *dev, struct ezusb_fx_type fx, const char *firmware_path) { int ret = -ENOENT; const struct firmware *firmware = NULL; const struct ihex_binrec *record; if (request_ihex_firmware(&firmware, firmware_path, &dev->dev)) { dev_err(&dev->dev, "%s - request \"%s\" failed\n", __func__, firmware_path); goto out; } ret = ezusb_set_reset(dev, fx.cpucs_reg, 0); if (ret < 0) goto out; record = (const struct ihex_binrec *)firmware->data; for (; record; record = ihex_next_binrec(record)) { if (be32_to_cpu(record->addr) > fx.max_internal_adress) { ret = ezusb_writememory(dev, be32_to_cpu(record->addr), (unsigned char *)record->data, be16_to_cpu(record->len), WRITE_EXT_RAM); if (ret < 0) { dev_err(&dev->dev, "%s - ezusb_writememory " "failed writing internal memory " "(%d %04X %p %d)\n", __func__, ret, be32_to_cpu(record->addr), record->data, be16_to_cpu(record->len)); goto out; } } } ret = ezusb_set_reset(dev, fx.cpucs_reg, 1); if (ret < 0) goto out; record = (const struct ihex_binrec *)firmware->data; for (; record; record = ihex_next_binrec(record)) { if (be32_to_cpu(record->addr) <= fx.max_internal_adress) { ret = ezusb_writememory(dev, be32_to_cpu(record->addr), (unsigned char *)record->data, be16_to_cpu(record->len), WRITE_INT_RAM); if (ret < 0) { dev_err(&dev->dev, "%s - ezusb_writememory " "failed writing external memory " "(%d %04X %p %d)\n", __func__, ret, be32_to_cpu(record->addr), record->data, be16_to_cpu(record->len)); goto out; } } } ret = ezusb_set_reset(dev, fx.cpucs_reg, 0); out: release_firmware(firmware); return ret; } int ezusb_fx1_ihex_firmware_download(struct usb_device *dev, const char *firmware_path) { return ezusb_ihex_firmware_download(dev, ezusb_fx1, firmware_path); } EXPORT_SYMBOL_GPL(ezusb_fx1_ihex_firmware_download); #if 0 /* * Once someone one needs these fx2 functions, uncomment them * and add them to ezusb.h and all should be good. */ static struct ezusb_fx_type ezusb_fx2 = { .cpucs_reg = 0xE600, .max_internal_adress = 0x3FFF, }; int ezusb_fx2_set_reset(struct usb_device *dev, unsigned char reset_bit) { return ezusb_set_reset(dev, ezusb_fx2.cpucs_reg, reset_bit); } EXPORT_SYMBOL_GPL(ezusb_fx2_set_reset); int ezusb_fx2_ihex_firmware_download(struct usb_device *dev, const char *firmware_path) { return ezusb_ihex_firmware_download(dev, ezusb_fx2, firmware_path); } EXPORT_SYMBOL_GPL(ezusb_fx2_ihex_firmware_download); #endif MODULE_LICENSE("GPL"); t();'>mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-02-01 11:52:27 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-01 11:52:27 -0800
commit6d04dfc8966019b8b0977b2cb942351f13d2b178 (patch)
tree2d4f239c1daff620704b77a992c1e70ce1ce6b08 /drivers/usb/chipidea/bits.h
parent2883aaea363f7a897ff06d2e6c73ae7aae285bcb (diff)
parent06425c308b92eaf60767bc71d359f4cbc7a561f8 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Pull networking fixes from David Miller: 1) Fix handling of interrupt status in stmmac driver. Just because we have masked the event from generating interrupts, doesn't mean the bit won't still be set in the interrupt status register. From Alexey Brodkin. 2) Fix DMA API debugging splats in gianfar driver, from Arseny Solokha. 3) Fix off-by-one error in __ip6_append_data(), from Vlad Yasevich. 4) cls_flow does not match on icmpv6 codes properly, from Simon Horman. 5) Initial MAC address can be set incorrectly in some scenerios, from Ivan Vecera. 6) Packet header pointer arithmetic fix in ip6_tnl_parse_tlv_end_lim(), from Dan Carpenter. 7) Fix divide by zero in __tcp_select_window(), from Eric Dumazet. 8) Fix crash in iwlwifi when unregistering thermal zone, from Jens Axboe. 9) Check for DMA mapping errors in starfire driver, from Alexey Khoroshilov. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: (31 commits) tcp: fix 0 divide in __tcp_select_window() ipv6: pointer math error in ip6_tnl_parse_tlv_enc_lim() net: fix ndo_features_check/ndo_fix_features comment ordering net/sched: matchall: Fix configuration race be2net: fix initial MAC setting ipv6: fix flow labels when the traffic class is non-0 net: thunderx: avoid dereferencing xcv when NULL net/sched: cls_flower: Correct matching on ICMPv6 code ipv6: Paritially checksum full MTU frames net/mlx4_core: Avoid command timeouts during VF driver device shutdown gianfar: synchronize DMA API usage by free_skb_rx_queue w/ gfar_new_page net: ethtool: add support for 2500BaseT and 5000BaseT link modes can: bcm: fix hrtimer/tasklet termination in bcm op removal net: adaptec: starfire: add checks for dma mapping errors net: phy: micrel: KSZ8795 do not set SUPPORTED_[Asym_]Pause can: Fix kernel panic at security_sock_rcv_skb net: macb: Fix 64 bit addressing support for GEM stmmac: Discard masked flags in interrupt status register net/mlx5e: Check ets capability before ets query FW command net/mlx5e: Fix update of hash function/key via ethtool ...
Diffstat (limited to 'drivers/usb/chipidea/bits.h')