Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2011 |
| 3 | * |
| 4 | * Author: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> |
| 5 | * License terms: GNU General Public License (GPL) version 2 |
| 6 | */ |
| 7 | #include <linux/platform_device.h> |
| 8 | #include <linux/usb/musb.h> |
Linus Walleij | fc5070b | 2011-06-27 18:19:30 +0200 | [diff] [blame] | 9 | #include <linux/dma-mapping.h> |
Arnd Bergmann | db298da | 2012-08-24 15:19:33 +0200 | [diff] [blame] | 10 | #include <linux/platform_data/usb-musb-ux500.h> |
Linus Walleij | 865fab6 | 2012-10-18 14:20:16 +0200 | [diff] [blame] | 11 | #include <linux/platform_data/dma-ste-dma40.h> |
| 12 | |
Linus Walleij | 174e779 | 2013-03-19 15:41:55 +0100 | [diff] [blame] | 13 | #include "db8500-regs.h" |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 14 | |
| 15 | #define MUSB_DMA40_RX_CH { \ |
| 16 | .mode = STEDMA40_MODE_LOGICAL, \ |
Lee Jones | 98b68ab | 2013-05-15 10:51:53 +0100 | [diff] [blame] | 17 | .dir = DMA_DEV_TO_MEM, \ |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | #define MUSB_DMA40_TX_CH { \ |
| 21 | .mode = STEDMA40_MODE_LOGICAL, \ |
Lee Jones | 98b68ab | 2013-05-15 10:51:53 +0100 | [diff] [blame] | 22 | .dir = DMA_MEM_TO_DEV, \ |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame] | 25 | static struct stedma40_chan_cfg musb_dma_rx_ch[UX500_MUSB_DMA_NUM_RX_TX_CHANNELS] |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 26 | = { |
| 27 | MUSB_DMA40_RX_CH, |
| 28 | MUSB_DMA40_RX_CH, |
| 29 | MUSB_DMA40_RX_CH, |
| 30 | MUSB_DMA40_RX_CH, |
| 31 | MUSB_DMA40_RX_CH, |
| 32 | MUSB_DMA40_RX_CH, |
| 33 | MUSB_DMA40_RX_CH, |
| 34 | MUSB_DMA40_RX_CH |
| 35 | }; |
| 36 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame] | 37 | static struct stedma40_chan_cfg musb_dma_tx_ch[UX500_MUSB_DMA_NUM_RX_TX_CHANNELS] |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 38 | = { |
| 39 | MUSB_DMA40_TX_CH, |
| 40 | MUSB_DMA40_TX_CH, |
| 41 | MUSB_DMA40_TX_CH, |
| 42 | MUSB_DMA40_TX_CH, |
| 43 | MUSB_DMA40_TX_CH, |
| 44 | MUSB_DMA40_TX_CH, |
| 45 | MUSB_DMA40_TX_CH, |
| 46 | MUSB_DMA40_TX_CH, |
| 47 | }; |
| 48 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame] | 49 | static void *ux500_dma_rx_param_array[UX500_MUSB_DMA_NUM_RX_TX_CHANNELS] = { |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 50 | &musb_dma_rx_ch[0], |
| 51 | &musb_dma_rx_ch[1], |
| 52 | &musb_dma_rx_ch[2], |
| 53 | &musb_dma_rx_ch[3], |
| 54 | &musb_dma_rx_ch[4], |
| 55 | &musb_dma_rx_ch[5], |
| 56 | &musb_dma_rx_ch[6], |
| 57 | &musb_dma_rx_ch[7] |
| 58 | }; |
| 59 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame] | 60 | static void *ux500_dma_tx_param_array[UX500_MUSB_DMA_NUM_RX_TX_CHANNELS] = { |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 61 | &musb_dma_tx_ch[0], |
| 62 | &musb_dma_tx_ch[1], |
| 63 | &musb_dma_tx_ch[2], |
| 64 | &musb_dma_tx_ch[3], |
| 65 | &musb_dma_tx_ch[4], |
| 66 | &musb_dma_tx_ch[5], |
| 67 | &musb_dma_tx_ch[6], |
| 68 | &musb_dma_tx_ch[7] |
| 69 | }; |
| 70 | |
| 71 | static struct ux500_musb_board_data musb_board_data = { |
| 72 | .dma_rx_param_array = ux500_dma_rx_param_array, |
| 73 | .dma_tx_param_array = ux500_dma_tx_param_array, |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 74 | .dma_filter = stedma40_filter, |
| 75 | }; |
| 76 | |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 77 | static struct musb_hdrc_platform_data musb_platform_data = { |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 78 | .mode = MUSB_OTG, |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 79 | .board_data = &musb_board_data, |
| 80 | }; |
| 81 | |
| 82 | static struct resource usb_resources[] = { |
| 83 | [0] = { |
| 84 | .name = "usb-mem", |
| 85 | .flags = IORESOURCE_MEM, |
| 86 | }, |
| 87 | |
| 88 | [1] = { |
| 89 | .name = "mc", /* hard-coded in musb */ |
| 90 | .flags = IORESOURCE_IRQ, |
| 91 | }, |
| 92 | }; |
| 93 | |
| 94 | struct platform_device ux500_musb_device = { |
| 95 | .name = "musb-ux500", |
| 96 | .id = 0, |
| 97 | .dev = { |
| 98 | .platform_data = &musb_platform_data, |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 99 | .coherent_dma_mask = DMA_BIT_MASK(32), |
| 100 | }, |
| 101 | .num_resources = ARRAY_SIZE(usb_resources), |
| 102 | .resource = usb_resources, |
| 103 | }; |
| 104 | |
Lee Jones | 26955c07d | 2013-05-03 15:31:56 +0100 | [diff] [blame] | 105 | static inline void ux500_usb_dma_update_rx_ch_config(int *dev_type) |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 106 | { |
| 107 | u32 idx; |
| 108 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame] | 109 | for (idx = 0; idx < UX500_MUSB_DMA_NUM_RX_TX_CHANNELS; idx++) |
Lee Jones | 26955c07d | 2013-05-03 15:31:56 +0100 | [diff] [blame] | 110 | musb_dma_rx_ch[idx].dev_type = dev_type[idx]; |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Lee Jones | 26955c07d | 2013-05-03 15:31:56 +0100 | [diff] [blame] | 113 | static inline void ux500_usb_dma_update_tx_ch_config(int *dev_type) |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 114 | { |
| 115 | u32 idx; |
| 116 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame] | 117 | for (idx = 0; idx < UX500_MUSB_DMA_NUM_RX_TX_CHANNELS; idx++) |
Lee Jones | 26955c07d | 2013-05-03 15:31:56 +0100 | [diff] [blame] | 118 | musb_dma_tx_ch[idx].dev_type = dev_type[idx]; |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Lee Jones | 1840342 | 2012-02-06 11:22:21 -0800 | [diff] [blame] | 121 | void ux500_add_usb(struct device *parent, resource_size_t base, int irq, |
| 122 | int *dma_rx_cfg, int *dma_tx_cfg) |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 123 | { |
| 124 | ux500_musb_device.resource[0].start = base; |
| 125 | ux500_musb_device.resource[0].end = base + SZ_64K - 1; |
| 126 | ux500_musb_device.resource[1].start = irq; |
| 127 | ux500_musb_device.resource[1].end = irq; |
| 128 | |
| 129 | ux500_usb_dma_update_rx_ch_config(dma_rx_cfg); |
| 130 | ux500_usb_dma_update_tx_ch_config(dma_tx_cfg); |
| 131 | |
Lee Jones | b024a0c | 2012-02-06 11:22:25 -0800 | [diff] [blame] | 132 | ux500_musb_device.dev.parent = parent; |
| 133 | |
Mian Yousaf Kaukab | 07f201d | 2011-01-21 17:59:56 +0100 | [diff] [blame] | 134 | platform_device_register(&ux500_musb_device); |
| 135 | } |