musb_cppi41.c (e10c5b0c773efb8643ee89d387d310584ca30830) | musb_cppi41.c (297d7fe9e439473800ab1f2f853b4b5f8c888500) |
---|---|
1#include <linux/device.h> 2#include <linux/dma-mapping.h> 3#include <linux/dmaengine.h> 4#include <linux/sizes.h> 5#include <linux/platform_device.h> 6#include <linux/of.h> 7 8#include "cppi_dma.h" --- 16 unchanged lines hidden (view full) --- 25#define USB_TDOWN 0xd8 26 27#define MUSB_DMA_NUM_CHANNELS 15 28 29#define DA8XX_USB_MODE 0x10 30#define DA8XX_USB_AUTOREQ 0x14 31#define DA8XX_USB_TEARDOWN 0x1c 32 | 1#include <linux/device.h> 2#include <linux/dma-mapping.h> 3#include <linux/dmaengine.h> 4#include <linux/sizes.h> 5#include <linux/platform_device.h> 6#include <linux/of.h> 7 8#include "cppi_dma.h" --- 16 unchanged lines hidden (view full) --- 25#define USB_TDOWN 0xd8 26 27#define MUSB_DMA_NUM_CHANNELS 15 28 29#define DA8XX_USB_MODE 0x10 30#define DA8XX_USB_AUTOREQ 0x14 31#define DA8XX_USB_TEARDOWN 0x1c 32 |
33#define DA8XX_DMA_NUM_CHANNELS 4 34 |
|
33struct cppi41_dma_controller { 34 struct dma_controller controller; | 35struct cppi41_dma_controller { 36 struct dma_controller controller; |
35 struct cppi41_dma_channel rx_channel[MUSB_DMA_NUM_CHANNELS]; 36 struct cppi41_dma_channel tx_channel[MUSB_DMA_NUM_CHANNELS]; | 37 struct cppi41_dma_channel *rx_channel; 38 struct cppi41_dma_channel *tx_channel; |
37 struct hrtimer early_tx; 38 struct list_head early_tx_list; 39 u32 rx_mode; 40 u32 tx_mode; 41 u32 auto_req; 42 43 u32 tdown_reg; 44 u32 autoreq_reg; 45 46 void (*set_dma_mode)(struct cppi41_dma_channel *cppi41_channel, 47 unsigned int mode); | 39 struct hrtimer early_tx; 40 struct list_head early_tx_list; 41 u32 rx_mode; 42 u32 tx_mode; 43 u32 auto_req; 44 45 u32 tdown_reg; 46 u32 autoreq_reg; 47 48 void (*set_dma_mode)(struct cppi41_dma_channel *cppi41_channel, 49 unsigned int mode); |
50 u8 num_channels; |
|
48}; 49 50static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel) 51{ 52 u16 csr; 53 u8 toggle; 54 55 if (cppi41_channel->is_tx) --- 422 unchanged lines hidden (view full) --- 478static struct dma_channel *cppi41_dma_channel_allocate(struct dma_controller *c, 479 struct musb_hw_ep *hw_ep, u8 is_tx) 480{ 481 struct cppi41_dma_controller *controller = container_of(c, 482 struct cppi41_dma_controller, controller); 483 struct cppi41_dma_channel *cppi41_channel = NULL; 484 u8 ch_num = hw_ep->epnum - 1; 485 | 51}; 52 53static void save_rx_toggle(struct cppi41_dma_channel *cppi41_channel) 54{ 55 u16 csr; 56 u8 toggle; 57 58 if (cppi41_channel->is_tx) --- 422 unchanged lines hidden (view full) --- 481static struct dma_channel *cppi41_dma_channel_allocate(struct dma_controller *c, 482 struct musb_hw_ep *hw_ep, u8 is_tx) 483{ 484 struct cppi41_dma_controller *controller = container_of(c, 485 struct cppi41_dma_controller, controller); 486 struct cppi41_dma_channel *cppi41_channel = NULL; 487 u8 ch_num = hw_ep->epnum - 1; 488 |
486 if (ch_num >= MUSB_DMA_NUM_CHANNELS) | 489 if (ch_num >= controller->num_channels) |
487 return NULL; 488 489 if (is_tx) 490 cppi41_channel = &controller->tx_channel[ch_num]; 491 else 492 cppi41_channel = &controller->rx_channel[ch_num]; 493 494 if (!cppi41_channel->dc) --- 143 unchanged lines hidden (view full) --- 638 return 0; 639} 640 641static void cppi41_release_all_dma_chans(struct cppi41_dma_controller *ctrl) 642{ 643 struct dma_chan *dc; 644 int i; 645 | 490 return NULL; 491 492 if (is_tx) 493 cppi41_channel = &controller->tx_channel[ch_num]; 494 else 495 cppi41_channel = &controller->rx_channel[ch_num]; 496 497 if (!cppi41_channel->dc) --- 143 unchanged lines hidden (view full) --- 641 return 0; 642} 643 644static void cppi41_release_all_dma_chans(struct cppi41_dma_controller *ctrl) 645{ 646 struct dma_chan *dc; 647 int i; 648 |
646 for (i = 0; i < MUSB_DMA_NUM_CHANNELS; i++) { | 649 for (i = 0; i < ctrl->num_channels; i++) { |
647 dc = ctrl->tx_channel[i].dc; 648 if (dc) 649 dma_release_channel(dc); 650 dc = ctrl->rx_channel[i].dc; 651 if (dc) 652 dma_release_channel(dc); 653 } 654} --- 35 unchanged lines hidden (view full) --- 690 dev_err(dev, "Wrong dmatype %s\n", str); 691 goto err; 692 } 693 ret = kstrtouint(str + 2, 0, &port); 694 if (ret) 695 goto err; 696 697 ret = -EINVAL; | 650 dc = ctrl->tx_channel[i].dc; 651 if (dc) 652 dma_release_channel(dc); 653 dc = ctrl->rx_channel[i].dc; 654 if (dc) 655 dma_release_channel(dc); 656 } 657} --- 35 unchanged lines hidden (view full) --- 693 dev_err(dev, "Wrong dmatype %s\n", str); 694 goto err; 695 } 696 ret = kstrtouint(str + 2, 0, &port); 697 if (ret) 698 goto err; 699 700 ret = -EINVAL; |
698 if (port > MUSB_DMA_NUM_CHANNELS || !port) | 701 if (port > controller->num_channels || !port) |
699 goto err; 700 if (is_tx) 701 cppi41_channel = &controller->tx_channel[port - 1]; 702 else 703 cppi41_channel = &controller->rx_channel[port - 1]; 704 705 cppi41_channel->controller = controller; 706 cppi41_channel->port_num = port; --- 24 unchanged lines hidden (view full) --- 731 732void cppi41_dma_controller_destroy(struct dma_controller *c) 733{ 734 struct cppi41_dma_controller *controller = container_of(c, 735 struct cppi41_dma_controller, controller); 736 737 hrtimer_cancel(&controller->early_tx); 738 cppi41_dma_controller_stop(controller); | 702 goto err; 703 if (is_tx) 704 cppi41_channel = &controller->tx_channel[port - 1]; 705 else 706 cppi41_channel = &controller->rx_channel[port - 1]; 707 708 cppi41_channel->controller = controller; 709 cppi41_channel->port_num = port; --- 24 unchanged lines hidden (view full) --- 734 735void cppi41_dma_controller_destroy(struct dma_controller *c) 736{ 737 struct cppi41_dma_controller *controller = container_of(c, 738 struct cppi41_dma_controller, controller); 739 740 hrtimer_cancel(&controller->early_tx); 741 cppi41_dma_controller_stop(controller); |
742 kfree(controller->rx_channel); 743 kfree(controller->tx_channel); |
|
739 kfree(controller); 740} 741EXPORT_SYMBOL_GPL(cppi41_dma_controller_destroy); 742 743struct dma_controller * 744cppi41_dma_controller_create(struct musb *musb, void __iomem *base) 745{ 746 struct cppi41_dma_controller *controller; | 744 kfree(controller); 745} 746EXPORT_SYMBOL_GPL(cppi41_dma_controller_destroy); 747 748struct dma_controller * 749cppi41_dma_controller_create(struct musb *musb, void __iomem *base) 750{ 751 struct cppi41_dma_controller *controller; |
752 int channel_size; |
|
747 int ret = 0; 748 749 if (!musb->controller->parent->of_node) { 750 dev_err(musb->controller, "Need DT for the DMA engine.\n"); 751 return NULL; 752 } 753 754 controller = kzalloc(sizeof(*controller), GFP_KERNEL); --- 10 unchanged lines hidden (view full) --- 765 controller->controller.channel_abort = cppi41_dma_channel_abort; 766 controller->controller.is_compatible = cppi41_is_compatible; 767 controller->controller.musb = musb; 768 769 if (musb->io.quirks & MUSB_DA8XX) { 770 controller->tdown_reg = DA8XX_USB_TEARDOWN; 771 controller->autoreq_reg = DA8XX_USB_AUTOREQ; 772 controller->set_dma_mode = da8xx_set_dma_mode; | 753 int ret = 0; 754 755 if (!musb->controller->parent->of_node) { 756 dev_err(musb->controller, "Need DT for the DMA engine.\n"); 757 return NULL; 758 } 759 760 controller = kzalloc(sizeof(*controller), GFP_KERNEL); --- 10 unchanged lines hidden (view full) --- 771 controller->controller.channel_abort = cppi41_dma_channel_abort; 772 controller->controller.is_compatible = cppi41_is_compatible; 773 controller->controller.musb = musb; 774 775 if (musb->io.quirks & MUSB_DA8XX) { 776 controller->tdown_reg = DA8XX_USB_TEARDOWN; 777 controller->autoreq_reg = DA8XX_USB_AUTOREQ; 778 controller->set_dma_mode = da8xx_set_dma_mode; |
779 controller->num_channels = DA8XX_DMA_NUM_CHANNELS; |
|
773 } else { 774 controller->tdown_reg = USB_TDOWN; 775 controller->autoreq_reg = USB_CTRL_AUTOREQ; 776 controller->set_dma_mode = cppi41_set_dma_mode; | 780 } else { 781 controller->tdown_reg = USB_TDOWN; 782 controller->autoreq_reg = USB_CTRL_AUTOREQ; 783 controller->set_dma_mode = cppi41_set_dma_mode; |
784 controller->num_channels = MUSB_DMA_NUM_CHANNELS; |
|
777 } 778 | 785 } 786 |
787 channel_size = controller->num_channels * 788 sizeof(struct cppi41_dma_channel); 789 controller->rx_channel = kzalloc(channel_size, GFP_KERNEL); 790 if (!controller->rx_channel) 791 goto rx_channel_alloc_fail; 792 controller->tx_channel = kzalloc(channel_size, GFP_KERNEL); 793 if (!controller->tx_channel) 794 goto tx_channel_alloc_fail; 795 |
|
779 ret = cppi41_dma_controller_start(controller); 780 if (ret) 781 goto plat_get_fail; 782 return &controller->controller; 783 784plat_get_fail: | 796 ret = cppi41_dma_controller_start(controller); 797 if (ret) 798 goto plat_get_fail; 799 return &controller->controller; 800 801plat_get_fail: |
802 kfree(controller->tx_channel); 803tx_channel_alloc_fail: 804 kfree(controller->rx_channel); 805rx_channel_alloc_fail: |
|
785 kfree(controller); 786kzalloc_fail: 787 if (ret == -EPROBE_DEFER) 788 return ERR_PTR(ret); 789 return NULL; 790} 791EXPORT_SYMBOL_GPL(cppi41_dma_controller_create); | 806 kfree(controller); 807kzalloc_fail: 808 if (ret == -EPROBE_DEFER) 809 return ERR_PTR(ret); 810 return NULL; 811} 812EXPORT_SYMBOL_GPL(cppi41_dma_controller_create); |