Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 13 | #include <linux/module.h> /* Just for modules */ |
| 14 | #include <linux/kernel.h> /* Only for KERN_INFO */ |
| 15 | #include <linux/err.h> /* Error macros */ |
| 16 | #include <linux/list.h> /* Linked list */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 17 | #include <linux/cdev.h> |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 18 | #include <linux/init.h> /* Needed for the macros */ |
| 19 | #include <linux/io.h> /* IO macros */ |
| 20 | #include <linux/device.h> /* Device drivers need this */ |
| 21 | #include <linux/sched.h> /* Externally defined globals */ |
| 22 | #include <linux/pm_runtime.h> /* Runtime power management */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 23 | #include <linux/fs.h> |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 24 | #include <linux/uaccess.h> /* copy_to_user */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 25 | #include <linux/slab.h> /* kfree, kzalloc */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 26 | #include <linux/ioport.h> /* XXX_ mem_region */ |
| 27 | #include <linux/dma-mapping.h> /* dma_XXX */ |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 28 | #include <linux/dmapool.h> /* DMA pools */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 29 | #include <linux/delay.h> /* msleep */ |
| 30 | #include <linux/platform_device.h> |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 31 | #include <linux/clk.h> |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 32 | #include <linux/poll.h> /* poll() file op */ |
| 33 | #include <linux/wait.h> /* wait() macros, sleeping */ |
| 34 | #include <linux/tspp.h> /* tspp functions */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 35 | #include <linux/bitops.h> /* BIT() macro */ |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 36 | #include <linux/regulator/consumer.h> |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 37 | #include <mach/sps.h> /* BAM stuff */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 38 | #include <mach/gpio.h> |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 39 | #include <linux/wakelock.h> /* Locking functions */ |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 40 | #include <linux/timer.h> /* Timer services */ |
| 41 | #include <linux/jiffies.h> /* Jiffies counter */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 42 | #include <mach/dma.h> |
| 43 | #include <mach/msm_tspp.h> |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 44 | #include <mach/rpm-regulator-smd.h> |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 45 | #include <linux/debugfs.h> |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 46 | #include <linux/of.h> |
| 47 | #include <linux/of_gpio.h> |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 48 | #include <linux/string.h> |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * General defines |
| 52 | */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 53 | #define TSPP_TSIF_INSTANCES 2 |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 54 | #define TSPP_GPIOS_PER_TSIF 4 |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 55 | #define TSPP_FILTER_TABLES 3 |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 56 | #define TSPP_MAX_DEVICES 1 |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 57 | #define TSPP_NUM_CHANNELS 16 |
| 58 | #define TSPP_NUM_PRIORITIES 16 |
| 59 | #define TSPP_NUM_KEYS 8 |
| 60 | #define INVALID_CHANNEL 0xFFFFFFFF |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * BAM descriptor FIFO size (in number of descriptors). |
| 64 | * Max number of descriptors allowed by SPS which is 8K-1. |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 65 | */ |
Hamad Kadmany | 2402035 | 2013-05-22 12:54:18 +0300 | [diff] [blame] | 66 | #define TSPP_SPS_DESCRIPTOR_COUNT (8 * 1024 - 1) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 67 | #define TSPP_PACKET_LENGTH 188 |
| 68 | #define TSPP_MIN_BUFFER_SIZE (TSPP_PACKET_LENGTH) |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 69 | |
| 70 | /* Max descriptor buffer size allowed by SPS */ |
| 71 | #define TSPP_MAX_BUFFER_SIZE (32 * 1024 - 1) |
| 72 | |
| 73 | /* |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 74 | * Returns whether to use DMA pool for TSPP output buffers. |
| 75 | * For buffers smaller than page size, using DMA pool |
| 76 | * provides better memory utilization as dma_alloc_coherent |
| 77 | * allocates minimum of page size. |
| 78 | */ |
| 79 | #define TSPP_USE_DMA_POOL(buff_size) ((buff_size) < PAGE_SIZE) |
| 80 | |
| 81 | /* |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 82 | * Max allowed TSPP buffers/descriptors. |
| 83 | * If SPS desc FIFO holds X descriptors, we can queue up to X-1 descriptors. |
| 84 | */ |
| 85 | #define TSPP_NUM_BUFFERS (TSPP_SPS_DESCRIPTOR_COUNT - 1) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 86 | #define TSPP_TSIF_DEFAULT_TIME_LIMIT 60 |
| 87 | #define SPS_DESCRIPTOR_SIZE 8 |
| 88 | #define MIN_ACCEPTABLE_BUFFER_COUNT 2 |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 89 | #define TSPP_DEBUG(msg...) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * TSIF register offsets |
| 93 | */ |
| 94 | #define TSIF_STS_CTL_OFF (0x0) |
| 95 | #define TSIF_TIME_LIMIT_OFF (0x4) |
| 96 | #define TSIF_CLK_REF_OFF (0x8) |
| 97 | #define TSIF_LPBK_FLAGS_OFF (0xc) |
| 98 | #define TSIF_LPBK_DATA_OFF (0x10) |
| 99 | #define TSIF_TEST_CTL_OFF (0x14) |
| 100 | #define TSIF_TEST_MODE_OFF (0x18) |
| 101 | #define TSIF_TEST_RESET_OFF (0x1c) |
| 102 | #define TSIF_TEST_EXPORT_OFF (0x20) |
| 103 | #define TSIF_TEST_CURRENT_OFF (0x24) |
| 104 | |
| 105 | #define TSIF_DATA_PORT_OFF (0x100) |
| 106 | |
| 107 | /* bits for TSIF_STS_CTL register */ |
| 108 | #define TSIF_STS_CTL_EN_IRQ BIT(28) |
| 109 | #define TSIF_STS_CTL_PACK_AVAIL BIT(27) |
| 110 | #define TSIF_STS_CTL_1ST_PACKET BIT(26) |
| 111 | #define TSIF_STS_CTL_OVERFLOW BIT(25) |
| 112 | #define TSIF_STS_CTL_LOST_SYNC BIT(24) |
| 113 | #define TSIF_STS_CTL_TIMEOUT BIT(23) |
| 114 | #define TSIF_STS_CTL_INV_SYNC BIT(21) |
| 115 | #define TSIF_STS_CTL_INV_NULL BIT(20) |
| 116 | #define TSIF_STS_CTL_INV_ERROR BIT(19) |
| 117 | #define TSIF_STS_CTL_INV_ENABLE BIT(18) |
| 118 | #define TSIF_STS_CTL_INV_DATA BIT(17) |
| 119 | #define TSIF_STS_CTL_INV_CLOCK BIT(16) |
| 120 | #define TSIF_STS_CTL_SPARE BIT(15) |
| 121 | #define TSIF_STS_CTL_EN_NULL BIT(11) |
| 122 | #define TSIF_STS_CTL_EN_ERROR BIT(10) |
| 123 | #define TSIF_STS_CTL_LAST_BIT BIT(9) |
| 124 | #define TSIF_STS_CTL_EN_TIME_LIM BIT(8) |
| 125 | #define TSIF_STS_CTL_EN_TCR BIT(7) |
| 126 | #define TSIF_STS_CTL_TEST_MODE BIT(6) |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 127 | #define TSIF_STS_CTL_MODE_2 BIT(5) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 128 | #define TSIF_STS_CTL_EN_DM BIT(4) |
| 129 | #define TSIF_STS_CTL_STOP BIT(3) |
| 130 | #define TSIF_STS_CTL_START BIT(0) |
| 131 | |
| 132 | /* |
| 133 | * TSPP register offsets |
| 134 | */ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 135 | #define TSPP_RST 0x00 |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 136 | #define TSPP_CLK_CONTROL 0x04 |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 137 | #define TSPP_CONFIG 0x08 |
| 138 | #define TSPP_CONTROL 0x0C |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 139 | #define TSPP_PS_DISABLE 0x10 |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 140 | #define TSPP_MSG_IRQ_STATUS 0x14 |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 141 | #define TSPP_MSG_IRQ_MASK 0x18 |
| 142 | #define TSPP_IRQ_STATUS 0x1C |
| 143 | #define TSPP_IRQ_MASK 0x20 |
| 144 | #define TSPP_IRQ_CLEAR 0x24 |
| 145 | #define TSPP_PIPE_ERROR_STATUS(_n) (0x28 + (_n << 2)) |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 146 | #define TSPP_STATUS 0x68 |
| 147 | #define TSPP_CURR_TSP_HEADER 0x6C |
| 148 | #define TSPP_CURR_PID_FILTER 0x70 |
| 149 | #define TSPP_SYSTEM_KEY(_n) (0x74 + (_n << 2)) |
| 150 | #define TSPP_CBC_INIT_VAL(_n) (0x94 + (_n << 2)) |
| 151 | #define TSPP_DATA_KEY_RESET 0x9C |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 152 | #define TSPP_KEY_VALID 0xA0 |
| 153 | #define TSPP_KEY_ERROR 0xA4 |
| 154 | #define TSPP_TEST_CTRL 0xA8 |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 155 | #define TSPP_VERSION 0xAC |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 156 | #define TSPP_GENERICS 0xB0 |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 157 | #define TSPP_NOP 0xB4 |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * Register bit definitions |
| 161 | */ |
| 162 | /* TSPP_RST */ |
| 163 | #define TSPP_RST_RESET BIT(0) |
| 164 | |
| 165 | /* TSPP_CLK_CONTROL */ |
| 166 | #define TSPP_CLK_CONTROL_FORCE_CRYPTO BIT(9) |
| 167 | #define TSPP_CLK_CONTROL_FORCE_PES_PL BIT(8) |
| 168 | #define TSPP_CLK_CONTROL_FORCE_PES_AF BIT(7) |
| 169 | #define TSPP_CLK_CONTROL_FORCE_RAW_CTRL BIT(6) |
| 170 | #define TSPP_CLK_CONTROL_FORCE_PERF_CNT BIT(5) |
| 171 | #define TSPP_CLK_CONTROL_FORCE_CTX_SEARCH BIT(4) |
| 172 | #define TSPP_CLK_CONTROL_FORCE_TSP_PROC BIT(3) |
| 173 | #define TSPP_CLK_CONTROL_FORCE_CONS_AHB2MEM BIT(2) |
| 174 | #define TSPP_CLK_CONTROL_FORCE_TS_AHB2MEM BIT(1) |
| 175 | #define TSPP_CLK_CONTROL_SET_CLKON BIT(0) |
| 176 | |
| 177 | /* TSPP_CONFIG */ |
| 178 | #define TSPP_CONFIG_SET_PACKET_LENGTH(_a, _b) (_a = (_a & 0xF0) | \ |
| 179 | ((_b & 0xF) << 8)) |
| 180 | #define TSPP_CONFIG_GET_PACKET_LENGTH(_a) ((_a >> 8) & 0xF) |
| 181 | #define TSPP_CONFIG_DUP_WITH_DISC_EN BIT(7) |
| 182 | #define TSPP_CONFIG_PES_SYNC_ERROR_MASK BIT(6) |
| 183 | #define TSPP_CONFIG_PS_LEN_ERR_MASK BIT(5) |
| 184 | #define TSPP_CONFIG_PS_CONT_ERR_UNSP_MASK BIT(4) |
| 185 | #define TSPP_CONFIG_PS_CONT_ERR_MASK BIT(3) |
| 186 | #define TSPP_CONFIG_PS_DUP_TSP_MASK BIT(2) |
| 187 | #define TSPP_CONFIG_TSP_ERR_IND_MASK BIT(1) |
| 188 | #define TSPP_CONFIG_TSP_SYNC_ERR_MASK BIT(0) |
| 189 | |
| 190 | /* TSPP_CONTROL */ |
| 191 | #define TSPP_CONTROL_PID_FILTER_LOCK BIT(5) |
| 192 | #define TSPP_CONTROL_FORCE_KEY_CALC BIT(4) |
| 193 | #define TSPP_CONTROL_TSP_CONS_SRC_DIS BIT(3) |
| 194 | #define TSPP_CONTROL_TSP_TSIF1_SRC_DIS BIT(2) |
| 195 | #define TSPP_CONTROL_TSP_TSIF0_SRC_DIS BIT(1) |
| 196 | #define TSPP_CONTROL_PERF_COUNT_INIT BIT(0) |
| 197 | |
| 198 | /* TSPP_MSG_IRQ_STATUS + TSPP_MSG_IRQ_MASK */ |
| 199 | #define TSPP_MSG_TSPP_IRQ BIT(2) |
| 200 | #define TSPP_MSG_TSIF_1_IRQ BIT(1) |
| 201 | #define TSPP_MSG_TSIF_0_IRQ BIT(0) |
| 202 | |
| 203 | /* TSPP_IRQ_STATUS + TSPP_IRQ_MASK + TSPP_IRQ_CLEAR */ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 204 | #define TSPP_IRQ_STATUS_TSP_RD_CMPL BIT(19) |
| 205 | #define TSPP_IRQ_STATUS_KEY_ERROR BIT(18) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 206 | #define TSPP_IRQ_STATUS_KEY_SWITCHED_BAD BIT(17) |
| 207 | #define TSPP_IRQ_STATUS_KEY_SWITCHED BIT(16) |
| 208 | #define TSPP_IRQ_STATUS_PS_BROKEN(_n) BIT((_n)) |
| 209 | |
| 210 | /* TSPP_PIPE_ERROR_STATUS */ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 211 | #define TSPP_PIPE_PES_SYNC_ERROR BIT(3) |
| 212 | #define TSPP_PIPE_PS_LENGTH_ERROR BIT(2) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 213 | #define TSPP_PIPE_PS_CONTINUITY_ERROR BIT(1) |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 214 | #define TSPP_PIP_PS_LOST_START BIT(0) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 215 | |
| 216 | /* TSPP_STATUS */ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 217 | #define TSPP_STATUS_TSP_PKT_AVAIL BIT(10) |
| 218 | #define TSPP_STATUS_TSIF1_DM_REQ BIT(6) |
| 219 | #define TSPP_STATUS_TSIF0_DM_REQ BIT(2) |
| 220 | #define TSPP_CURR_FILTER_TABLE BIT(0) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 221 | |
| 222 | /* TSPP_GENERICS */ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 223 | #define TSPP_GENERICS_CRYPTO_GEN BIT(12) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 224 | #define TSPP_GENERICS_MAX_CONS_PIPES BIT(7) |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 225 | #define TSPP_GENERICS_MAX_PIPES BIT(2) |
| 226 | #define TSPP_GENERICS_TSIF_1_GEN BIT(1) |
| 227 | #define TSPP_GENERICS_TSIF_0_GEN BIT(0) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * TSPP memory regions |
| 231 | */ |
| 232 | #define TSPP_PID_FILTER_TABLE0 0x800 |
| 233 | #define TSPP_PID_FILTER_TABLE1 0x880 |
| 234 | #define TSPP_PID_FILTER_TABLE2 0x900 |
| 235 | #define TSPP_GLOBAL_PERFORMANCE 0x980 /* see tspp_global_performance */ |
| 236 | #define TSPP_PIPE_CONTEXT 0x990 /* see tspp_pipe_context */ |
| 237 | #define TSPP_PIPE_PERFORMANCE 0x998 /* see tspp_pipe_performance */ |
| 238 | #define TSPP_TSP_BUFF_WORD(_n) (0xC10 + (_n << 2)) |
| 239 | #define TSPP_DATA_KEY 0xCD0 |
| 240 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 241 | struct debugfs_entry { |
| 242 | const char *name; |
| 243 | mode_t mode; |
| 244 | int offset; |
| 245 | }; |
| 246 | |
| 247 | static const struct debugfs_entry debugfs_tsif_regs[] = { |
| 248 | {"sts_ctl", S_IRUGO | S_IWUSR, TSIF_STS_CTL_OFF}, |
| 249 | {"time_limit", S_IRUGO | S_IWUSR, TSIF_TIME_LIMIT_OFF}, |
| 250 | {"clk_ref", S_IRUGO | S_IWUSR, TSIF_CLK_REF_OFF}, |
| 251 | {"lpbk_flags", S_IRUGO | S_IWUSR, TSIF_LPBK_FLAGS_OFF}, |
| 252 | {"lpbk_data", S_IRUGO | S_IWUSR, TSIF_LPBK_DATA_OFF}, |
| 253 | {"test_ctl", S_IRUGO | S_IWUSR, TSIF_TEST_CTL_OFF}, |
| 254 | {"test_mode", S_IRUGO | S_IWUSR, TSIF_TEST_MODE_OFF}, |
| 255 | {"test_reset", S_IWUSR, TSIF_TEST_RESET_OFF}, |
| 256 | {"test_export", S_IRUGO | S_IWUSR, TSIF_TEST_EXPORT_OFF}, |
| 257 | {"test_current", S_IRUGO, TSIF_TEST_CURRENT_OFF}, |
| 258 | {"data_port", S_IRUSR, TSIF_DATA_PORT_OFF}, |
| 259 | }; |
| 260 | |
| 261 | static const struct debugfs_entry debugfs_tspp_regs[] = { |
| 262 | {"rst", S_IRUGO | S_IWUSR, TSPP_RST}, |
| 263 | {"clk_control", S_IRUGO | S_IWUSR, TSPP_CLK_CONTROL}, |
| 264 | {"config", S_IRUGO | S_IWUSR, TSPP_CONFIG}, |
| 265 | {"control", S_IRUGO | S_IWUSR, TSPP_CONTROL}, |
| 266 | {"ps_disable", S_IRUGO | S_IWUSR, TSPP_PS_DISABLE}, |
| 267 | {"msg_irq_status", S_IRUGO | S_IWUSR, TSPP_MSG_IRQ_STATUS}, |
| 268 | {"msg_irq_mask", S_IRUGO | S_IWUSR, TSPP_MSG_IRQ_MASK}, |
| 269 | {"irq_status", S_IRUGO | S_IWUSR, TSPP_IRQ_STATUS}, |
| 270 | {"irq_mask", S_IRUGO | S_IWUSR, TSPP_IRQ_MASK}, |
| 271 | {"irq_clear", S_IRUGO | S_IWUSR, TSPP_IRQ_CLEAR}, |
| 272 | /* {"pipe_error_status",S_IRUGO | S_IWUSR, TSPP_PIPE_ERROR_STATUS}, */ |
| 273 | {"status", S_IRUGO | S_IWUSR, TSPP_STATUS}, |
| 274 | {"curr_tsp_header", S_IRUGO | S_IWUSR, TSPP_CURR_TSP_HEADER}, |
| 275 | {"curr_pid_filter", S_IRUGO | S_IWUSR, TSPP_CURR_PID_FILTER}, |
| 276 | /* {"system_key", S_IRUGO | S_IWUSR, TSPP_SYSTEM_KEY}, */ |
| 277 | /* {"cbc_init_val", S_IRUGO | S_IWUSR, TSPP_CBC_INIT_VAL}, */ |
| 278 | {"data_key_reset", S_IRUGO | S_IWUSR, TSPP_DATA_KEY_RESET}, |
| 279 | {"key_valid", S_IRUGO | S_IWUSR, TSPP_KEY_VALID}, |
| 280 | {"key_error", S_IRUGO | S_IWUSR, TSPP_KEY_ERROR}, |
| 281 | {"test_ctrl", S_IRUGO | S_IWUSR, TSPP_TEST_CTRL}, |
| 282 | {"version", S_IRUGO | S_IWUSR, TSPP_VERSION}, |
| 283 | {"generics", S_IRUGO | S_IWUSR, TSPP_GENERICS}, |
| 284 | {"pid_filter_table0", S_IRUGO | S_IWUSR, TSPP_PID_FILTER_TABLE0}, |
| 285 | {"pid_filter_table1", S_IRUGO | S_IWUSR, TSPP_PID_FILTER_TABLE1}, |
| 286 | {"pid_filter_table2", S_IRUGO | S_IWUSR, TSPP_PID_FILTER_TABLE2}, |
| 287 | {"global_performance", S_IRUGO | S_IWUSR, TSPP_GLOBAL_PERFORMANCE}, |
| 288 | {"pipe_context", S_IRUGO | S_IWUSR, TSPP_PIPE_CONTEXT}, |
| 289 | {"pipe_performance", S_IRUGO | S_IWUSR, TSPP_PIPE_PERFORMANCE}, |
| 290 | {"data_key", S_IRUGO | S_IWUSR, TSPP_DATA_KEY} |
| 291 | }; |
| 292 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 293 | struct tspp_pid_filter { |
| 294 | u32 filter; /* see FILTER_ macros */ |
| 295 | u32 config; /* see FILTER_ macros */ |
| 296 | }; |
| 297 | |
| 298 | /* tsp_info */ |
| 299 | #define FILTER_HEADER_ERROR_MASK BIT(7) |
| 300 | #define FILTER_TRANS_END_DISABLE BIT(6) |
| 301 | #define FILTER_DEC_ON_ERROR_EN BIT(5) |
| 302 | #define FILTER_DECRYPT BIT(4) |
| 303 | #define FILTER_HAS_ENCRYPTION(_p) (_p->config & FILTER_DECRYPT) |
| 304 | #define FILTER_GET_PIPE_NUMBER0(_p) (_p->config & 0xF) |
| 305 | #define FILTER_SET_PIPE_NUMBER0(_p, _b) (_p->config = \ |
| 306 | (_p->config & ~0xF) | (_b & 0xF)) |
| 307 | #define FILTER_GET_PIPE_PROCESS0(_p) ((_p->filter >> 30) & 0x3) |
| 308 | #define FILTER_SET_PIPE_PROCESS0(_p, _b) (_p->filter = \ |
| 309 | (_p->filter & ~(0x3<<30)) | ((_b & 0x3) << 30)) |
| 310 | #define FILTER_GET_PIPE_PID(_p) ((_p->filter >> 13) & 0x1FFF) |
| 311 | #define FILTER_SET_PIPE_PID(_p, _b) (_p->filter = \ |
| 312 | (_p->filter & ~(0x1FFF<<13)) | ((_b & 0x1FFF) << 13)) |
| 313 | #define FILTER_GET_PID_MASK(_p) (_p->filter & 0x1FFF) |
| 314 | #define FILTER_SET_PID_MASK(_p, _b) (_p->filter = \ |
| 315 | (_p->filter & ~0x1FFF) | (_b & 0x1FFF)) |
| 316 | #define FILTER_GET_PIPE_PROCESS1(_p) ((_p->config >> 30) & 0x3) |
| 317 | #define FILTER_SET_PIPE_PROCESS1(_p, _b) (_p->config = \ |
| 318 | (_p->config & ~(0x3<<30)) | ((_b & 0x3) << 30)) |
| 319 | #define FILTER_GET_KEY_NUMBER(_p) ((_p->config >> 8) & 0x7) |
| 320 | #define FILTER_SET_KEY_NUMBER(_p, _b) (_p->config = \ |
| 321 | (_p->config & ~(0x7<<8)) | ((_b & 0x7) << 8)) |
| 322 | |
| 323 | struct tspp_global_performance_regs { |
| 324 | u32 tsp_total; |
| 325 | u32 tsp_ignored; |
| 326 | u32 tsp_error; |
| 327 | u32 tsp_sync; |
| 328 | }; |
| 329 | |
| 330 | struct tspp_pipe_context_regs { |
| 331 | u16 pes_bytes_left; |
| 332 | u16 count; |
| 333 | u32 tsif_suffix; |
| 334 | } __packed; |
| 335 | #define CONTEXT_GET_STATE(_a) (_a & 0x3) |
| 336 | #define CONTEXT_UNSPEC_LENGTH BIT(11) |
| 337 | #define CONTEXT_GET_CONT_COUNT(_a) ((_a >> 12) & 0xF) |
| 338 | |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 339 | #define MSEC_TO_JIFFIES(msec) ((msec) * HZ / 1000) |
| 340 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 341 | struct tspp_pipe_performance_regs { |
| 342 | u32 tsp_total; |
| 343 | u32 ps_duplicate_tsp; |
| 344 | u32 tsp_no_payload; |
| 345 | u32 tsp_broken_ps; |
| 346 | u32 ps_total_num; |
| 347 | u32 ps_continuity_error; |
| 348 | u32 ps_length_error; |
| 349 | u32 pes_sync_error; |
| 350 | }; |
| 351 | |
| 352 | struct tspp_tsif_device { |
| 353 | void __iomem *base; |
| 354 | u32 time_limit; |
| 355 | u32 ref_count; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 356 | enum tspp_tsif_mode mode; |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 357 | int clock_inverse; |
| 358 | int data_inverse; |
| 359 | int sync_inverse; |
| 360 | int enable_inverse; |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 361 | u32 tsif_irq; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 362 | |
| 363 | /* debugfs */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 364 | struct dentry *dent_tsif; |
| 365 | struct dentry *debugfs_tsif_regs[ARRAY_SIZE(debugfs_tsif_regs)]; |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 366 | u32 stat_rx; |
| 367 | u32 stat_overflow; |
| 368 | u32 stat_lost_sync; |
| 369 | u32 stat_timeout; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | enum tspp_buf_state { |
| 373 | TSPP_BUF_STATE_EMPTY, /* buffer has been allocated, but not waiting */ |
| 374 | TSPP_BUF_STATE_WAITING, /* buffer is waiting to be filled */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 375 | TSPP_BUF_STATE_DATA, /* buffer is not empty and can be read */ |
| 376 | TSPP_BUF_STATE_LOCKED /* buffer is being read by a client */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | struct tspp_mem_buffer { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 380 | struct tspp_mem_buffer *next; |
| 381 | struct sps_mem_buffer sps; |
| 382 | struct tspp_data_descriptor desc; /* buffer descriptor for kernel api */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 383 | enum tspp_buf_state state; |
| 384 | size_t filled; /* how much data this buffer is holding */ |
| 385 | int read_index; /* where to start reading data from */ |
| 386 | }; |
| 387 | |
| 388 | /* this represents each char device 'channel' */ |
| 389 | struct tspp_channel { |
| 390 | struct cdev cdev; |
| 391 | struct device *dd; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 392 | struct tspp_device *pdev; /* can use container_of instead? */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 393 | struct sps_pipe *pipe; |
| 394 | struct sps_connect config; |
| 395 | struct sps_register_event event; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 396 | struct tspp_mem_buffer *data; /* list of buffers */ |
| 397 | struct tspp_mem_buffer *read; /* first buffer ready to be read */ |
| 398 | struct tspp_mem_buffer *waiting; /* first outstanding transfer */ |
| 399 | struct tspp_mem_buffer *locked; /* buffer currently being read */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 400 | wait_queue_head_t in_queue; /* set when data is received */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 401 | u32 id; /* channel id (0-15) */ |
| 402 | int used; /* is this channel in use? */ |
| 403 | int key; /* which encryption key index is used */ |
| 404 | u32 buffer_size; /* size of the sps transfer buffers */ |
| 405 | u32 max_buffers; /* how many buffers should be allocated */ |
| 406 | u32 buffer_count; /* how many buffers are actually allocated */ |
| 407 | u32 filter_count; /* how many filters have been added to this channel */ |
| 408 | u32 int_freq; /* generate interrupts every x descriptors */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 409 | enum tspp_source src; |
| 410 | enum tspp_mode mode; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 411 | tspp_notifier *notifier; /* used only with kernel api */ |
| 412 | void *notify_data; /* data to be passed with the notifier */ |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 413 | u32 expiration_period_ms; /* notification on partially filled buffers */ |
| 414 | struct timer_list expiration_timer; |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 415 | struct dma_pool *dma_pool; |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 416 | tspp_memfree *memfree; /* user defined memory free function */ |
| 417 | void *user_info; /* user cookie passed to memory alloc/free function */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | struct tspp_pid_filter_table { |
| 421 | struct tspp_pid_filter filter[TSPP_NUM_PRIORITIES]; |
| 422 | }; |
| 423 | |
| 424 | struct tspp_key_entry { |
| 425 | u32 even_lsb; |
| 426 | u32 even_msb; |
| 427 | u32 odd_lsb; |
| 428 | u32 odd_msb; |
| 429 | }; |
| 430 | |
| 431 | struct tspp_key_table { |
| 432 | struct tspp_key_entry entry[TSPP_NUM_KEYS]; |
| 433 | }; |
| 434 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 435 | /* this represents the actual hardware device */ |
| 436 | struct tspp_device { |
| 437 | struct list_head devlist; /* list of all devices */ |
| 438 | struct platform_device *pdev; |
| 439 | void __iomem *base; |
| 440 | unsigned int tspp_irq; |
| 441 | unsigned int bam_irq; |
| 442 | u32 bam_handle; |
| 443 | struct sps_bam_props bam_props; |
| 444 | struct wake_lock wake_lock; |
| 445 | spinlock_t spinlock; |
| 446 | struct tasklet_struct tlet; |
| 447 | struct tspp_tsif_device tsif[TSPP_TSIF_INSTANCES]; |
| 448 | /* clocks */ |
| 449 | struct clk *tsif_pclk; |
| 450 | struct clk *tsif_ref_clk; |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 451 | /* regulators */ |
| 452 | struct regulator *tsif_vreg; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 453 | /* data */ |
| 454 | struct tspp_pid_filter_table *filters[TSPP_FILTER_TABLES]; |
| 455 | struct tspp_channel channels[TSPP_NUM_CHANNELS]; |
| 456 | struct tspp_key_table *tspp_key_table; |
| 457 | struct tspp_global_performance_regs *tspp_global_performance; |
| 458 | struct tspp_pipe_context_regs *tspp_pipe_context; |
| 459 | struct tspp_pipe_performance_regs *tspp_pipe_performance; |
| 460 | |
| 461 | struct dentry *dent; |
| 462 | struct dentry *debugfs_regs[ARRAY_SIZE(debugfs_tspp_regs)]; |
| 463 | }; |
| 464 | |
| 465 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 466 | static struct class *tspp_class; |
| 467 | static int tspp_key_entry; |
| 468 | static dev_t tspp_minor; /* next minor number to assign */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 469 | |
| 470 | static LIST_HEAD(tspp_devices); |
| 471 | |
| 472 | /* forward declarations */ |
| 473 | static ssize_t tspp_read(struct file *, char __user *, size_t, loff_t *); |
| 474 | static ssize_t tspp_open(struct inode *inode, struct file *filp); |
| 475 | static unsigned int tspp_poll(struct file *filp, struct poll_table_struct *p); |
| 476 | static ssize_t tspp_release(struct inode *inode, struct file *filp); |
| 477 | static long tspp_ioctl(struct file *, unsigned int, unsigned long); |
| 478 | |
| 479 | /* file operations */ |
| 480 | static const struct file_operations tspp_fops = { |
| 481 | .owner = THIS_MODULE, |
| 482 | .read = tspp_read, |
| 483 | .open = tspp_open, |
| 484 | .poll = tspp_poll, |
| 485 | .release = tspp_release, |
| 486 | .unlocked_ioctl = tspp_ioctl, |
| 487 | }; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 488 | |
| 489 | /*** IRQ ***/ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 490 | static irqreturn_t tspp_isr(int irq, void *dev) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 491 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 492 | struct tspp_device *device = dev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 493 | u32 status, mask; |
| 494 | u32 data; |
| 495 | |
| 496 | status = readl_relaxed(device->base + TSPP_IRQ_STATUS); |
| 497 | mask = readl_relaxed(device->base + TSPP_IRQ_MASK); |
| 498 | status &= mask; |
| 499 | |
| 500 | if (!status) { |
| 501 | dev_warn(&device->pdev->dev, "Spurious interrupt"); |
| 502 | return IRQ_NONE; |
| 503 | } |
| 504 | |
| 505 | /* if (status & TSPP_IRQ_STATUS_TSP_RD_CMPL) */ |
| 506 | |
| 507 | if (status & TSPP_IRQ_STATUS_KEY_ERROR) { |
| 508 | /* read the key error info */ |
| 509 | data = readl_relaxed(device->base + TSPP_KEY_ERROR); |
| 510 | dev_info(&device->pdev->dev, "key error 0x%x", data); |
| 511 | } |
| 512 | if (status & TSPP_IRQ_STATUS_KEY_SWITCHED_BAD) { |
| 513 | data = readl_relaxed(device->base + TSPP_KEY_VALID); |
| 514 | dev_info(&device->pdev->dev, "key invalidated: 0x%x", data); |
| 515 | } |
| 516 | if (status & TSPP_IRQ_STATUS_KEY_SWITCHED) |
| 517 | dev_info(&device->pdev->dev, "key switched"); |
| 518 | |
| 519 | if (status & 0xffff) |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 520 | dev_info(&device->pdev->dev, "broken pipe %i", status & 0xffff); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 521 | |
| 522 | writel_relaxed(status, device->base + TSPP_IRQ_CLEAR); |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 523 | |
| 524 | /* |
| 525 | * Before returning IRQ_HANDLED to the generic interrupt handling |
| 526 | * framework need to make sure all operations including clearing of |
| 527 | * interrupt status registers in the hardware is performed. |
| 528 | * Thus a barrier after clearing the interrupt status register |
| 529 | * is required to guarantee that the interrupt status register has |
| 530 | * really been cleared by the time we return from this handler. |
| 531 | */ |
| 532 | wmb(); |
| 533 | return IRQ_HANDLED; |
| 534 | } |
| 535 | |
| 536 | static irqreturn_t tsif_isr(int irq, void *dev) |
| 537 | { |
| 538 | struct tspp_tsif_device *tsif_device = dev; |
| 539 | u32 sts_ctl = ioread32(tsif_device->base + TSIF_STS_CTL_OFF); |
| 540 | |
| 541 | if (!(sts_ctl & (TSIF_STS_CTL_PACK_AVAIL | |
| 542 | TSIF_STS_CTL_OVERFLOW | |
| 543 | TSIF_STS_CTL_LOST_SYNC | |
| 544 | TSIF_STS_CTL_TIMEOUT))) |
| 545 | return IRQ_NONE; |
| 546 | |
| 547 | if (sts_ctl & TSIF_STS_CTL_OVERFLOW) |
| 548 | tsif_device->stat_overflow++; |
| 549 | |
| 550 | if (sts_ctl & TSIF_STS_CTL_LOST_SYNC) |
| 551 | tsif_device->stat_lost_sync++; |
| 552 | |
| 553 | if (sts_ctl & TSIF_STS_CTL_TIMEOUT) |
| 554 | tsif_device->stat_timeout++; |
| 555 | |
| 556 | iowrite32(sts_ctl, tsif_device->base + TSIF_STS_CTL_OFF); |
| 557 | |
| 558 | /* |
| 559 | * Before returning IRQ_HANDLED to the generic interrupt handling |
| 560 | * framework need to make sure all operations including clearing of |
| 561 | * interrupt status registers in the hardware is performed. |
| 562 | * Thus a barrier after clearing the interrupt status register |
| 563 | * is required to guarantee that the interrupt status register has |
| 564 | * really been cleared by the time we return from this handler. |
| 565 | */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 566 | wmb(); |
| 567 | return IRQ_HANDLED; |
| 568 | } |
| 569 | |
| 570 | /*** callbacks ***/ |
| 571 | static void tspp_sps_complete_cb(struct sps_event_notify *notify) |
| 572 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 573 | struct tspp_device *pdev = notify->user; |
| 574 | tasklet_schedule(&pdev->tlet); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 577 | static void tspp_expiration_timer(unsigned long data) |
| 578 | { |
| 579 | struct tspp_device *pdev = (struct tspp_device *)data; |
| 580 | |
| 581 | if (pdev) |
| 582 | tasklet_schedule(&pdev->tlet); |
| 583 | } |
| 584 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 585 | /*** tasklet ***/ |
| 586 | static void tspp_sps_complete_tlet(unsigned long data) |
| 587 | { |
| 588 | int i; |
| 589 | int complete; |
| 590 | unsigned long flags; |
| 591 | struct sps_iovec iovec; |
| 592 | struct tspp_channel *channel; |
| 593 | struct tspp_device *device = (struct tspp_device *)data; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 594 | spin_lock_irqsave(&device->spinlock, flags); |
| 595 | |
| 596 | for (i = 0; i < TSPP_NUM_CHANNELS; i++) { |
| 597 | complete = 0; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 598 | channel = &device->channels[i]; |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 599 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 600 | if (!channel->used || !channel->waiting) |
| 601 | continue; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 602 | |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 603 | /* stop the expiration timer */ |
| 604 | if (channel->expiration_period_ms) |
| 605 | del_timer(&channel->expiration_timer); |
| 606 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 607 | /* get completions */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 608 | while (channel->waiting->state == TSPP_BUF_STATE_WAITING) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 609 | if (sps_get_iovec(channel->pipe, &iovec) != 0) { |
| 610 | pr_err("tspp: Error in iovec on channel %i", |
| 611 | channel->id); |
| 612 | break; |
| 613 | } |
| 614 | if (iovec.size == 0) |
| 615 | break; |
| 616 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 617 | if (iovec.addr != channel->waiting->sps.phys_base) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 618 | pr_err("tspp: buffer mismatch 0x%08x", |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 619 | channel->waiting->sps.phys_base); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 620 | |
| 621 | complete = 1; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 622 | channel->waiting->state = TSPP_BUF_STATE_DATA; |
| 623 | channel->waiting->filled = iovec.size; |
| 624 | channel->waiting->read_index = 0; |
| 625 | |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 626 | if (channel->src == TSPP_SOURCE_TSIF0) |
| 627 | device->tsif[0].stat_rx++; |
| 628 | else if (channel->src == TSPP_SOURCE_TSIF1) |
| 629 | device->tsif[1].stat_rx++; |
| 630 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 631 | /* update the pointers */ |
| 632 | channel->waiting = channel->waiting->next; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 635 | /* wake any waiting processes */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 636 | if (complete) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 637 | wake_up_interruptible(&channel->in_queue); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 638 | |
| 639 | /* call notifiers */ |
| 640 | if (channel->notifier) |
| 641 | channel->notifier(channel->id, |
| 642 | channel->notify_data); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 643 | } |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 644 | |
| 645 | /* restart expiration timer */ |
| 646 | if (channel->expiration_period_ms) |
| 647 | mod_timer(&channel->expiration_timer, |
| 648 | jiffies + |
| 649 | MSEC_TO_JIFFIES( |
| 650 | channel->expiration_period_ms)); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | spin_unlock_irqrestore(&device->spinlock, flags); |
| 654 | } |
| 655 | |
| 656 | /*** GPIO functions ***/ |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 657 | static int tspp_gpios_disable(const struct tspp_tsif_device *tsif_device, |
| 658 | const struct msm_gpio *table, |
| 659 | int size) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 660 | { |
| 661 | int rc = 0; |
| 662 | int i; |
| 663 | const struct msm_gpio *g; |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 664 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 665 | for (i = size-1; i >= 0; i--) { |
| 666 | int tmp; |
| 667 | g = table + i; |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 668 | |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 669 | /* don't use sync GPIO when not working in mode 2 */ |
| 670 | if ((tsif_device->mode != TSPP_TSIF_MODE_2) && |
| 671 | (strnstr(g->label, "sync", strlen(g->label)) != NULL)) |
| 672 | continue; |
| 673 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 674 | tmp = gpio_tlmm_config(GPIO_CFG(GPIO_PIN(g->gpio_cfg), |
| 675 | 0, GPIO_CFG_INPUT, GPIO_CFG_PULL_DOWN, GPIO_CFG_2MA), |
| 676 | GPIO_CFG_DISABLE); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 677 | if (tmp) { |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 678 | pr_err("tspp_gpios_disable(0x%08x, GPIO_CFG_DISABLE) <%s> failed: %d\n", |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 679 | g->gpio_cfg, g->label ?: "?", rc); |
| 680 | pr_err("tspp: pin %d func %d dir %d pull %d drvstr %d\n", |
| 681 | GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg), |
| 682 | GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg), |
| 683 | GPIO_DRVSTR(g->gpio_cfg)); |
| 684 | if (!rc) |
| 685 | rc = tmp; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | return rc; |
| 690 | } |
| 691 | |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 692 | static int tspp_gpios_enable(const struct tspp_tsif_device *tsif_device, |
| 693 | const struct msm_gpio *table, |
| 694 | int size) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 695 | { |
| 696 | int rc; |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 697 | int i; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 698 | const struct msm_gpio *g; |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 699 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 700 | for (i = 0; i < size; i++) { |
| 701 | g = table + i; |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 702 | |
| 703 | /* don't use sync GPIO when not working in mode 2 */ |
| 704 | if ((tsif_device->mode != TSPP_TSIF_MODE_2) && |
| 705 | (strnstr(g->label, "sync", strlen(g->label)) != NULL)) |
| 706 | continue; |
| 707 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 708 | rc = gpio_tlmm_config(g->gpio_cfg, GPIO_CFG_ENABLE); |
| 709 | if (rc) { |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 710 | pr_err("tspp: gpio_tlmm_config(0x%08x, GPIO_CFG_ENABLE) <%s> failed: %d\n", |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 711 | g->gpio_cfg, g->label ?: "?", rc); |
| 712 | pr_err("tspp: pin %d func %d dir %d pull %d drvstr %d\n", |
| 713 | GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg), |
| 714 | GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg), |
| 715 | GPIO_DRVSTR(g->gpio_cfg)); |
| 716 | goto err; |
| 717 | } |
| 718 | } |
| 719 | return 0; |
| 720 | err: |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 721 | tspp_gpios_disable(tsif_device, table, i); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 722 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 723 | return rc; |
| 724 | } |
| 725 | |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 726 | |
| 727 | static int tspp_config_gpios(struct tspp_device *device, |
| 728 | enum tspp_source source, |
| 729 | int enable) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 730 | { |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 731 | const struct msm_gpio *table; |
| 732 | struct msm_tspp_platform_data *pdata = device->pdev->dev.platform_data; |
| 733 | int num_gpios = (pdata->num_gpios / TSPP_TSIF_INSTANCES); |
| 734 | int i = 0; |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 735 | |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 736 | if (num_gpios != TSPP_GPIOS_PER_TSIF) { |
| 737 | pr_err("tspp %s: unexpected number of GPIOs %d, expected %d\n", |
| 738 | __func__, num_gpios, TSPP_GPIOS_PER_TSIF); |
| 739 | return -EINVAL; |
| 740 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 741 | |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 742 | /* |
| 743 | * Note: this code assumes that the GPIO definitions in the |
| 744 | * pdata->gpios table are according to the TSIF instance number, |
| 745 | * i.e., that TSIF0 GPIOs are defined first, then TSIF1 GPIOs etc. |
| 746 | */ |
| 747 | switch (source) { |
| 748 | case TSPP_SOURCE_TSIF0: |
| 749 | i = 0; |
| 750 | break; |
| 751 | case TSPP_SOURCE_TSIF1: |
| 752 | i = 1; |
| 753 | break; |
| 754 | default: |
| 755 | pr_err("tspp %s: invalid source\n", __func__); |
| 756 | return -EINVAL; |
| 757 | } |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 758 | |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 759 | table = pdata->gpios + (i * num_gpios); |
| 760 | if (enable) |
| 761 | return tspp_gpios_enable(&device->tsif[i], table, num_gpios); |
| 762 | else |
| 763 | return tspp_gpios_disable(&device->tsif[i], table, num_gpios); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 766 | /*** Clock functions ***/ |
| 767 | static int tspp_clock_start(struct tspp_device *device) |
| 768 | { |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 769 | int rc; |
| 770 | |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 771 | if (device == NULL) { |
| 772 | pr_err("tspp: Can't start clocks, invalid device\n"); |
| 773 | return -EINVAL; |
| 774 | } |
| 775 | |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 776 | if (device->tsif_vreg) { |
| 777 | rc = regulator_set_voltage(device->tsif_vreg, |
| 778 | RPM_REGULATOR_CORNER_SUPER_TURBO, |
| 779 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 780 | if (rc) { |
| 781 | pr_err("Unable to set CX voltage.\n"); |
| 782 | return rc; |
| 783 | } |
| 784 | } |
| 785 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 786 | if (device->tsif_pclk && clk_prepare_enable(device->tsif_pclk) != 0) { |
| 787 | pr_err("tspp: Can't start pclk"); |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 788 | |
| 789 | if (device->tsif_vreg) { |
| 790 | regulator_set_voltage(device->tsif_vreg, |
| 791 | RPM_REGULATOR_CORNER_SVS_SOC, |
| 792 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 793 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 794 | return -EBUSY; |
| 795 | } |
| 796 | |
| 797 | if (device->tsif_ref_clk && |
| 798 | clk_prepare_enable(device->tsif_ref_clk) != 0) { |
| 799 | pr_err("tspp: Can't start ref clk"); |
| 800 | clk_disable_unprepare(device->tsif_pclk); |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 801 | if (device->tsif_vreg) { |
| 802 | regulator_set_voltage(device->tsif_vreg, |
| 803 | RPM_REGULATOR_CORNER_SVS_SOC, |
| 804 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 805 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 806 | return -EBUSY; |
| 807 | } |
| 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static void tspp_clock_stop(struct tspp_device *device) |
| 813 | { |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 814 | int rc; |
| 815 | |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 816 | if (device == NULL) { |
| 817 | pr_err("tspp: Can't stop clocks, invalid device\n"); |
| 818 | return; |
| 819 | } |
| 820 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 821 | if (device->tsif_pclk) |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 822 | clk_disable_unprepare(device->tsif_pclk); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 823 | |
| 824 | if (device->tsif_ref_clk) |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 825 | clk_disable_unprepare(device->tsif_ref_clk); |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 826 | |
| 827 | if (device->tsif_vreg) { |
| 828 | rc = regulator_set_voltage(device->tsif_vreg, |
| 829 | RPM_REGULATOR_CORNER_SVS_SOC, |
| 830 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 831 | if (rc) |
| 832 | pr_err("Unable to set CX voltage.\n"); |
| 833 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 834 | } |
| 835 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 836 | /*** TSIF functions ***/ |
| 837 | static int tspp_start_tsif(struct tspp_tsif_device *tsif_device) |
| 838 | { |
| 839 | int start_hardware = 0; |
| 840 | u32 ctl; |
| 841 | |
| 842 | if (tsif_device->ref_count == 0) { |
| 843 | start_hardware = 1; |
| 844 | } else if (tsif_device->ref_count > 0) { |
| 845 | ctl = readl_relaxed(tsif_device->base + TSIF_STS_CTL_OFF); |
| 846 | if ((ctl & TSIF_STS_CTL_START) != 1) { |
| 847 | /* this hardware should already be running */ |
| 848 | pr_warn("tspp: tsif hw not started but ref count > 0"); |
| 849 | start_hardware = 1; |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | if (start_hardware) { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 854 | ctl = TSIF_STS_CTL_EN_IRQ | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 855 | TSIF_STS_CTL_EN_DM; |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 856 | |
| 857 | if (tsif_device->clock_inverse) |
| 858 | ctl |= TSIF_STS_CTL_INV_CLOCK; |
| 859 | |
| 860 | if (tsif_device->data_inverse) |
| 861 | ctl |= TSIF_STS_CTL_INV_DATA; |
| 862 | |
| 863 | if (tsif_device->sync_inverse) |
| 864 | ctl |= TSIF_STS_CTL_INV_SYNC; |
| 865 | |
| 866 | if (tsif_device->enable_inverse) |
| 867 | ctl |= TSIF_STS_CTL_INV_ENABLE; |
| 868 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 869 | switch (tsif_device->mode) { |
| 870 | case TSPP_TSIF_MODE_LOOPBACK: |
| 871 | ctl |= TSIF_STS_CTL_EN_NULL | |
| 872 | TSIF_STS_CTL_EN_ERROR | |
| 873 | TSIF_STS_CTL_TEST_MODE; |
| 874 | break; |
| 875 | case TSPP_TSIF_MODE_1: |
| 876 | ctl |= TSIF_STS_CTL_EN_TIME_LIM | |
| 877 | TSIF_STS_CTL_EN_TCR; |
| 878 | break; |
| 879 | case TSPP_TSIF_MODE_2: |
| 880 | ctl |= TSIF_STS_CTL_EN_TIME_LIM | |
| 881 | TSIF_STS_CTL_EN_TCR | |
| 882 | TSIF_STS_CTL_MODE_2; |
| 883 | break; |
| 884 | default: |
| 885 | pr_warn("tspp: unknown tsif mode 0x%x", |
| 886 | tsif_device->mode); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 887 | } |
| 888 | writel_relaxed(ctl, tsif_device->base + TSIF_STS_CTL_OFF); |
| 889 | writel_relaxed(tsif_device->time_limit, |
| 890 | tsif_device->base + TSIF_TIME_LIMIT_OFF); |
| 891 | wmb(); |
| 892 | writel_relaxed(ctl | TSIF_STS_CTL_START, |
| 893 | tsif_device->base + TSIF_STS_CTL_OFF); |
| 894 | wmb(); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 895 | } |
| 896 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 897 | ctl = readl_relaxed(tsif_device->base + TSIF_STS_CTL_OFF); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 898 | tsif_device->ref_count++; |
| 899 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 900 | return (ctl & TSIF_STS_CTL_START) ? 0 : -EBUSY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | static void tspp_stop_tsif(struct tspp_tsif_device *tsif_device) |
| 904 | { |
| 905 | if (tsif_device->ref_count == 0) |
| 906 | return; |
| 907 | |
| 908 | tsif_device->ref_count--; |
| 909 | |
| 910 | if (tsif_device->ref_count == 0) { |
| 911 | writel_relaxed(TSIF_STS_CTL_STOP, |
| 912 | tsif_device->base + TSIF_STS_CTL_OFF); |
| 913 | wmb(); |
| 914 | } |
| 915 | } |
| 916 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 917 | /*** local TSPP functions ***/ |
| 918 | static int tspp_channels_in_use(struct tspp_device *pdev) |
| 919 | { |
| 920 | int i; |
| 921 | int count = 0; |
| 922 | for (i = 0; i < TSPP_NUM_CHANNELS; i++) |
| 923 | count += (pdev->channels[i].used ? 1 : 0); |
| 924 | |
| 925 | return count; |
| 926 | } |
| 927 | |
| 928 | static struct tspp_device *tspp_find_by_id(int id) |
| 929 | { |
| 930 | struct tspp_device *dev; |
| 931 | list_for_each_entry(dev, &tspp_devices, devlist) { |
| 932 | if (dev->pdev->id == id) |
| 933 | return dev; |
| 934 | } |
| 935 | return NULL; |
| 936 | } |
| 937 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 938 | static int tspp_get_key_entry(void) |
| 939 | { |
| 940 | int i; |
| 941 | for (i = 0; i < TSPP_NUM_KEYS; i++) { |
| 942 | if (!(tspp_key_entry & (1 << i))) { |
| 943 | tspp_key_entry |= (1 << i); |
| 944 | return i; |
| 945 | } |
| 946 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 947 | return 1 < TSPP_NUM_KEYS; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | static void tspp_free_key_entry(int entry) |
| 951 | { |
| 952 | if (entry > TSPP_NUM_KEYS) { |
| 953 | pr_err("tspp_free_key_entry: index out of bounds"); |
| 954 | return; |
| 955 | } |
| 956 | |
| 957 | tspp_key_entry &= ~(1 << entry); |
| 958 | } |
| 959 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 960 | static int tspp_alloc_buffer(u32 channel_id, struct tspp_data_descriptor *desc, |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 961 | u32 size, struct dma_pool *dma_pool, tspp_allocator *alloc, void *user) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 962 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 963 | if (size < TSPP_MIN_BUFFER_SIZE || |
| 964 | size > TSPP_MAX_BUFFER_SIZE) { |
| 965 | pr_err("tspp: bad buffer size %i", size); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 966 | return -ENOMEM; |
| 967 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 968 | |
| 969 | if (alloc) { |
| 970 | TSPP_DEBUG("tspp using alloc function"); |
| 971 | desc->virt_base = alloc(channel_id, size, |
| 972 | &desc->phys_base, user); |
| 973 | } else { |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 974 | if (!dma_pool) |
| 975 | desc->virt_base = dma_alloc_coherent(NULL, size, |
| 976 | &desc->phys_base, GFP_KERNEL); |
| 977 | else |
| 978 | desc->virt_base = dma_pool_alloc(dma_pool, GFP_KERNEL, |
| 979 | &desc->phys_base); |
| 980 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 981 | if (desc->virt_base == 0) { |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 982 | pr_err("tspp: dma buffer allocation failed %i\n", size); |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 983 | return -ENOMEM; |
| 984 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | desc->size = size; |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | static int tspp_queue_buffer(struct tspp_channel *channel, |
| 992 | struct tspp_mem_buffer *buffer) |
| 993 | { |
| 994 | int rc; |
| 995 | u32 flags = 0; |
| 996 | |
| 997 | /* make sure the interrupt frequency is valid */ |
| 998 | if (channel->int_freq < 1) |
| 999 | channel->int_freq = 1; |
| 1000 | |
| 1001 | /* generate interrupt according to requested frequency */ |
| 1002 | if (buffer->desc.id % channel->int_freq == channel->int_freq-1) |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1003 | flags = SPS_IOVEC_FLAG_INT; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1004 | |
| 1005 | /* start the transfer */ |
| 1006 | rc = sps_transfer_one(channel->pipe, |
| 1007 | buffer->sps.phys_base, |
| 1008 | buffer->sps.size, |
| 1009 | channel->pdev, |
| 1010 | flags); |
| 1011 | if (rc < 0) |
| 1012 | return rc; |
| 1013 | |
| 1014 | buffer->state = TSPP_BUF_STATE_WAITING; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | static int tspp_global_reset(struct tspp_device *pdev) |
| 1020 | { |
| 1021 | u32 i, val; |
| 1022 | |
| 1023 | /* stop all TSIFs */ |
| 1024 | for (i = 0; i < TSPP_TSIF_INSTANCES; i++) { |
| 1025 | pdev->tsif[i].ref_count = 1; /* allows stopping hw */ |
| 1026 | tspp_stop_tsif(&pdev->tsif[i]); /* will reset ref_count to 0 */ |
| 1027 | pdev->tsif[i].time_limit = TSPP_TSIF_DEFAULT_TIME_LIMIT; |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1028 | pdev->tsif[i].clock_inverse = 0; |
| 1029 | pdev->tsif[i].data_inverse = 0; |
| 1030 | pdev->tsif[i].sync_inverse = 0; |
| 1031 | pdev->tsif[i].enable_inverse = 0; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1032 | } |
| 1033 | writel_relaxed(TSPP_RST_RESET, pdev->base + TSPP_RST); |
| 1034 | wmb(); |
| 1035 | |
| 1036 | /* BAM */ |
| 1037 | if (sps_device_reset(pdev->bam_handle) != 0) { |
| 1038 | pr_err("tspp: error resetting bam"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1039 | return -EBUSY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /* TSPP tables */ |
| 1043 | for (i = 0; i < TSPP_FILTER_TABLES; i++) |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1044 | memset(pdev->filters[i], |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1045 | 0, sizeof(struct tspp_pid_filter_table)); |
| 1046 | |
| 1047 | /* disable all filters */ |
| 1048 | val = (2 << TSPP_NUM_CHANNELS) - 1; |
| 1049 | writel_relaxed(val, pdev->base + TSPP_PS_DISABLE); |
| 1050 | |
| 1051 | /* TSPP registers */ |
| 1052 | val = readl_relaxed(pdev->base + TSPP_CONTROL); |
| 1053 | writel_relaxed(val | TSPP_CLK_CONTROL_FORCE_PERF_CNT, |
| 1054 | pdev->base + TSPP_CONTROL); |
| 1055 | wmb(); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1056 | memset(pdev->tspp_global_performance, 0, |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1057 | sizeof(struct tspp_global_performance_regs)); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1058 | memset(pdev->tspp_pipe_context, 0, |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1059 | sizeof(struct tspp_pipe_context_regs)); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1060 | memset(pdev->tspp_pipe_performance, 0, |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1061 | sizeof(struct tspp_pipe_performance_regs)); |
| 1062 | wmb(); |
| 1063 | writel_relaxed(val & ~TSPP_CLK_CONTROL_FORCE_PERF_CNT, |
| 1064 | pdev->base + TSPP_CONTROL); |
| 1065 | wmb(); |
| 1066 | |
| 1067 | val = readl_relaxed(pdev->base + TSPP_CONFIG); |
| 1068 | val &= ~(TSPP_CONFIG_PS_LEN_ERR_MASK | |
| 1069 | TSPP_CONFIG_PS_CONT_ERR_UNSP_MASK | |
| 1070 | TSPP_CONFIG_PS_CONT_ERR_MASK); |
| 1071 | TSPP_CONFIG_SET_PACKET_LENGTH(val, TSPP_PACKET_LENGTH); |
| 1072 | writel_relaxed(val, pdev->base + TSPP_CONFIG); |
Hamad Kadmany | 6bac783 | 2012-12-20 18:30:40 +0200 | [diff] [blame] | 1073 | writel_relaxed(0x0007ffff, pdev->base + TSPP_IRQ_MASK); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1074 | writel_relaxed(0x000fffff, pdev->base + TSPP_IRQ_CLEAR); |
| 1075 | writel_relaxed(0, pdev->base + TSPP_RST); |
| 1076 | wmb(); |
| 1077 | |
| 1078 | tspp_key_entry = 0; |
| 1079 | |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1083 | static int tspp_select_source(u32 dev, u32 channel_id, |
| 1084 | struct tspp_select_source *src) |
| 1085 | { |
| 1086 | /* make sure the requested src id is in bounds */ |
| 1087 | if (src->source > TSPP_SOURCE_MEM) { |
| 1088 | pr_err("tspp source out of bounds"); |
| 1089 | return -EINVAL; |
| 1090 | } |
| 1091 | |
| 1092 | /* open the stream */ |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1093 | tspp_open_stream(dev, channel_id, src); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1094 | |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
| 1098 | static int tspp_set_iv(struct tspp_channel *channel, struct tspp_iv *iv) |
| 1099 | { |
| 1100 | struct tspp_device *pdev = channel->pdev; |
| 1101 | |
| 1102 | writel_relaxed(iv->data[0], pdev->base + TSPP_CBC_INIT_VAL(0)); |
| 1103 | writel_relaxed(iv->data[1], pdev->base + TSPP_CBC_INIT_VAL(1)); |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static int tspp_set_system_keys(struct tspp_channel *channel, |
| 1108 | struct tspp_system_keys *keys) |
| 1109 | { |
| 1110 | int i; |
| 1111 | struct tspp_device *pdev = channel->pdev; |
| 1112 | |
| 1113 | for (i = 0; i < TSPP_NUM_SYSTEM_KEYS; i++) |
| 1114 | writel_relaxed(keys->data[i], pdev->base + TSPP_SYSTEM_KEY(i)); |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | static int tspp_channel_init(struct tspp_channel *channel, |
| 1120 | struct tspp_device *pdev) |
| 1121 | { |
| 1122 | channel->cdev.owner = THIS_MODULE; |
| 1123 | cdev_init(&channel->cdev, &tspp_fops); |
| 1124 | channel->pdev = pdev; |
| 1125 | channel->data = NULL; |
| 1126 | channel->read = NULL; |
| 1127 | channel->waiting = NULL; |
| 1128 | channel->locked = NULL; |
| 1129 | channel->id = MINOR(tspp_minor); |
| 1130 | channel->used = 0; |
| 1131 | channel->buffer_size = TSPP_MIN_BUFFER_SIZE; |
| 1132 | channel->max_buffers = TSPP_NUM_BUFFERS; |
| 1133 | channel->buffer_count = 0; |
| 1134 | channel->filter_count = 0; |
| 1135 | channel->int_freq = 1; |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1136 | channel->src = TSPP_SOURCE_NONE; |
| 1137 | channel->mode = TSPP_MODE_DISABLED; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1138 | channel->notifier = NULL; |
| 1139 | channel->notify_data = NULL; |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1140 | channel->expiration_period_ms = 0; |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1141 | channel->memfree = NULL; |
| 1142 | channel->user_info = NULL; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1143 | init_waitqueue_head(&channel->in_queue); |
| 1144 | |
| 1145 | if (cdev_add(&channel->cdev, tspp_minor++, 1) != 0) { |
| 1146 | pr_err("tspp: cdev_add failed"); |
| 1147 | return -EBUSY; |
| 1148 | } |
| 1149 | |
| 1150 | channel->dd = device_create(tspp_class, NULL, channel->cdev.dev, |
| 1151 | channel, "tspp%02d", channel->id); |
| 1152 | if (IS_ERR(channel->dd)) { |
| 1153 | pr_err("tspp: device_create failed: %i", |
| 1154 | (int)PTR_ERR(channel->dd)); |
| 1155 | cdev_del(&channel->cdev); |
| 1156 | return -EBUSY; |
| 1157 | } |
| 1158 | |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
| 1162 | static int tspp_set_buffer_size(struct tspp_channel *channel, |
| 1163 | struct tspp_buffer *buf) |
| 1164 | { |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1165 | if (channel->buffer_count > 0) { |
| 1166 | pr_err("tspp: cannot set buffer size - buffers already allocated\n"); |
| 1167 | return -EPERM; |
| 1168 | } |
| 1169 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1170 | if (buf->size < TSPP_MIN_BUFFER_SIZE) |
| 1171 | channel->buffer_size = TSPP_MIN_BUFFER_SIZE; |
| 1172 | else if (buf->size > TSPP_MAX_BUFFER_SIZE) |
| 1173 | channel->buffer_size = TSPP_MAX_BUFFER_SIZE; |
| 1174 | else |
| 1175 | channel->buffer_size = buf->size; |
| 1176 | |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | static void tspp_set_tsif_mode(struct tspp_channel *channel, |
| 1181 | enum tspp_tsif_mode mode) |
| 1182 | { |
| 1183 | int index; |
| 1184 | |
| 1185 | switch (channel->src) { |
| 1186 | case TSPP_SOURCE_TSIF0: |
| 1187 | index = 0; |
| 1188 | break; |
| 1189 | case TSPP_SOURCE_TSIF1: |
| 1190 | index = 1; |
| 1191 | break; |
| 1192 | default: |
| 1193 | pr_warn("tspp: can't set mode for non-tsif source %d", |
| 1194 | channel->src); |
| 1195 | return; |
| 1196 | } |
| 1197 | channel->pdev->tsif[index].mode = mode; |
| 1198 | } |
| 1199 | |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1200 | static void tspp_set_signal_inversion(struct tspp_channel *channel, |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1201 | int clock_inverse, int data_inverse, |
| 1202 | int sync_inverse, int enable_inverse) |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1203 | { |
| 1204 | int index; |
| 1205 | |
| 1206 | switch (channel->src) { |
| 1207 | case TSPP_SOURCE_TSIF0: |
| 1208 | index = 0; |
| 1209 | break; |
| 1210 | case TSPP_SOURCE_TSIF1: |
| 1211 | index = 1; |
| 1212 | break; |
| 1213 | default: |
| 1214 | return; |
| 1215 | } |
| 1216 | channel->pdev->tsif[index].clock_inverse = clock_inverse; |
| 1217 | channel->pdev->tsif[index].data_inverse = data_inverse; |
| 1218 | channel->pdev->tsif[index].sync_inverse = sync_inverse; |
| 1219 | channel->pdev->tsif[index].enable_inverse = enable_inverse; |
| 1220 | } |
| 1221 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1222 | static int tspp_is_buffer_size_aligned(u32 size, enum tspp_mode mode) |
| 1223 | { |
| 1224 | u32 alignment; |
| 1225 | |
| 1226 | switch (mode) { |
| 1227 | case TSPP_MODE_RAW: |
| 1228 | /* must be a multiple of 192 */ |
| 1229 | alignment = (TSPP_PACKET_LENGTH + 4); |
| 1230 | if (size % alignment) |
| 1231 | return 0; |
| 1232 | return 1; |
| 1233 | |
| 1234 | case TSPP_MODE_RAW_NO_SUFFIX: |
| 1235 | /* must be a multiple of 188 */ |
| 1236 | alignment = TSPP_PACKET_LENGTH; |
| 1237 | if (size % alignment) |
| 1238 | return 0; |
| 1239 | return 1; |
| 1240 | |
| 1241 | case TSPP_MODE_DISABLED: |
| 1242 | case TSPP_MODE_PES: |
| 1243 | default: |
| 1244 | /* no alignment requirement */ |
| 1245 | return 1; |
| 1246 | } |
| 1247 | |
| 1248 | } |
| 1249 | |
| 1250 | static u32 tspp_align_buffer_size_by_mode(u32 size, enum tspp_mode mode) |
| 1251 | { |
| 1252 | u32 new_size; |
| 1253 | u32 alignment; |
| 1254 | |
| 1255 | switch (mode) { |
| 1256 | case TSPP_MODE_RAW: |
| 1257 | /* must be a multiple of 192 */ |
| 1258 | alignment = (TSPP_PACKET_LENGTH + 4); |
| 1259 | break; |
| 1260 | |
| 1261 | case TSPP_MODE_RAW_NO_SUFFIX: |
| 1262 | /* must be a multiple of 188 */ |
| 1263 | alignment = TSPP_PACKET_LENGTH; |
| 1264 | break; |
| 1265 | |
| 1266 | case TSPP_MODE_DISABLED: |
| 1267 | case TSPP_MODE_PES: |
| 1268 | default: |
| 1269 | /* no alignment requirement - give the user what he asks for */ |
| 1270 | alignment = 1; |
| 1271 | break; |
| 1272 | } |
| 1273 | /* align up */ |
| 1274 | new_size = (((size + alignment - 1) / alignment) * alignment); |
| 1275 | return new_size; |
| 1276 | } |
| 1277 | |
| 1278 | static void tspp_destroy_buffers(u32 channel_id, struct tspp_channel *channel) |
| 1279 | { |
| 1280 | int i; |
| 1281 | struct tspp_mem_buffer *pbuf, *temp; |
| 1282 | |
| 1283 | pbuf = channel->data; |
| 1284 | for (i = 0; i < channel->buffer_count; i++) { |
| 1285 | if (pbuf->desc.phys_base) { |
| 1286 | if (channel->memfree) { |
| 1287 | channel->memfree(channel_id, |
| 1288 | pbuf->desc.size, |
| 1289 | pbuf->desc.virt_base, |
| 1290 | pbuf->desc.phys_base, |
| 1291 | channel->user_info); |
| 1292 | } else { |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 1293 | if (!channel->dma_pool) |
| 1294 | dma_free_coherent(NULL, |
| 1295 | pbuf->desc.size, |
| 1296 | pbuf->desc.virt_base, |
| 1297 | pbuf->desc.phys_base); |
| 1298 | else |
| 1299 | dma_pool_free(channel->dma_pool, |
| 1300 | pbuf->desc.virt_base, |
| 1301 | pbuf->desc.phys_base); |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1302 | } |
| 1303 | pbuf->desc.phys_base = 0; |
| 1304 | } |
| 1305 | pbuf->desc.virt_base = 0; |
| 1306 | pbuf->state = TSPP_BUF_STATE_EMPTY; |
| 1307 | temp = pbuf; |
| 1308 | pbuf = pbuf->next; |
| 1309 | kfree(temp); |
| 1310 | } |
| 1311 | } |
| 1312 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1313 | /*** TSPP API functions ***/ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1314 | |
| 1315 | /** |
| 1316 | * tspp_open_stream - open a TSPP stream for use. |
| 1317 | * |
| 1318 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1319 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 1320 | * @source: stream source parameters. |
| 1321 | * |
| 1322 | * Return error status |
| 1323 | * |
| 1324 | */ |
| 1325 | int tspp_open_stream(u32 dev, u32 channel_id, |
| 1326 | struct tspp_select_source *source) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1327 | { |
| 1328 | u32 val; |
| 1329 | struct tspp_device *pdev; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1330 | struct tspp_channel *channel; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1331 | |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1332 | TSPP_DEBUG("tspp_open_stream %i %i %i %i", |
| 1333 | dev, channel_id, source->source, source->mode); |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1334 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1335 | if (dev >= TSPP_MAX_DEVICES) { |
| 1336 | pr_err("tspp: device id out of range"); |
| 1337 | return -ENODEV; |
| 1338 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1339 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1340 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 1341 | pr_err("tspp: channel id out of range"); |
| 1342 | return -ECHRNG; |
| 1343 | } |
| 1344 | |
| 1345 | pdev = tspp_find_by_id(dev); |
| 1346 | if (!pdev) { |
| 1347 | pr_err("tspp_str: can't find device %i", dev); |
| 1348 | return -ENODEV; |
| 1349 | } |
| 1350 | channel = &pdev->channels[channel_id]; |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1351 | channel->src = source->source; |
| 1352 | tspp_set_tsif_mode(channel, source->mode); |
| 1353 | tspp_set_signal_inversion(channel, source->clk_inverse, |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1354 | source->data_inverse, source->sync_inverse, |
| 1355 | source->enable_inverse); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1356 | |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1357 | switch (source->source) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1358 | case TSPP_SOURCE_TSIF0: |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 1359 | if (tspp_config_gpios(pdev, channel->src, 1) != 0) { |
| 1360 | pr_err("tspp: error enabling tsif0 GPIOs\n"); |
| 1361 | return -EBUSY; |
| 1362 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1363 | /* make sure TSIF0 is running & enabled */ |
| 1364 | if (tspp_start_tsif(&pdev->tsif[0]) != 0) { |
| 1365 | pr_err("tspp: error starting tsif0"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1366 | return -EBUSY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1367 | } |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 1368 | if (pdev->tsif[0].ref_count == 1) { |
| 1369 | val = readl_relaxed(pdev->base + TSPP_CONTROL); |
| 1370 | writel_relaxed(val & ~TSPP_CONTROL_TSP_TSIF0_SRC_DIS, |
| 1371 | pdev->base + TSPP_CONTROL); |
| 1372 | wmb(); |
| 1373 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1374 | break; |
| 1375 | case TSPP_SOURCE_TSIF1: |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 1376 | if (tspp_config_gpios(pdev, channel->src, 1) != 0) { |
| 1377 | pr_err("tspp: error enabling tsif1 GPIOs\n"); |
| 1378 | return -EBUSY; |
| 1379 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1380 | /* make sure TSIF1 is running & enabled */ |
| 1381 | if (tspp_start_tsif(&pdev->tsif[1]) != 0) { |
| 1382 | pr_err("tspp: error starting tsif1"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1383 | return -EBUSY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1384 | } |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 1385 | if (pdev->tsif[1].ref_count == 1) { |
| 1386 | val = readl_relaxed(pdev->base + TSPP_CONTROL); |
| 1387 | writel_relaxed(val & ~TSPP_CONTROL_TSP_TSIF1_SRC_DIS, |
| 1388 | pdev->base + TSPP_CONTROL); |
| 1389 | wmb(); |
| 1390 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1391 | break; |
| 1392 | case TSPP_SOURCE_MEM: |
| 1393 | break; |
| 1394 | default: |
Hamad Kadmany | 92705b3 | 2012-10-23 14:15:41 +0200 | [diff] [blame] | 1395 | pr_err("tspp: channel %i invalid source %i", |
| 1396 | channel->id, source->source); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1397 | return -EBUSY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1400 | return 0; |
| 1401 | } |
| 1402 | EXPORT_SYMBOL(tspp_open_stream); |
| 1403 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1404 | /** |
| 1405 | * tspp_close_stream - close a TSPP stream. |
| 1406 | * |
| 1407 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1408 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 1409 | * |
| 1410 | * Return error status |
| 1411 | * |
| 1412 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1413 | int tspp_close_stream(u32 dev, u32 channel_id) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1414 | { |
| 1415 | u32 val; |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 1416 | u32 prev_ref_count; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1417 | struct tspp_device *pdev; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1418 | struct tspp_channel *channel; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1419 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1420 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 1421 | pr_err("tspp: channel id out of range"); |
| 1422 | return -ECHRNG; |
| 1423 | } |
| 1424 | pdev = tspp_find_by_id(dev); |
| 1425 | if (!pdev) { |
| 1426 | pr_err("tspp_cs: can't find device %i", dev); |
| 1427 | return -EBUSY; |
| 1428 | } |
| 1429 | channel = &pdev->channels[channel_id]; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1430 | |
| 1431 | switch (channel->src) { |
| 1432 | case TSPP_SOURCE_TSIF0: |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 1433 | prev_ref_count = pdev->tsif[0].ref_count; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1434 | tspp_stop_tsif(&pdev->tsif[0]); |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 1435 | if (tspp_config_gpios(pdev, channel->src, 0) != 0) |
| 1436 | pr_err("tspp: error disabling tsif0 GPIOs\n"); |
| 1437 | |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 1438 | if (prev_ref_count == 1) { |
| 1439 | val = readl_relaxed(pdev->base + TSPP_CONTROL); |
| 1440 | writel_relaxed(val | TSPP_CONTROL_TSP_TSIF0_SRC_DIS, |
| 1441 | pdev->base + TSPP_CONTROL); |
| 1442 | wmb(); |
| 1443 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1444 | break; |
| 1445 | case TSPP_SOURCE_TSIF1: |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 1446 | prev_ref_count = pdev->tsif[1].ref_count; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1447 | tspp_stop_tsif(&pdev->tsif[1]); |
Liron Kuch | 275c0b3 | 2013-02-10 15:19:32 +0200 | [diff] [blame] | 1448 | if (tspp_config_gpios(pdev, channel->src, 0) != 0) |
| 1449 | pr_err("tspp: error disabling tsif0 GPIOs\n"); |
| 1450 | |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 1451 | if (prev_ref_count == 1) { |
| 1452 | val = readl_relaxed(pdev->base + TSPP_CONTROL); |
| 1453 | writel_relaxed(val | TSPP_CONTROL_TSP_TSIF1_SRC_DIS, |
| 1454 | pdev->base + TSPP_CONTROL); |
| 1455 | wmb(); |
| 1456 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1457 | break; |
| 1458 | case TSPP_SOURCE_MEM: |
| 1459 | break; |
| 1460 | case TSPP_SOURCE_NONE: |
| 1461 | break; |
| 1462 | } |
| 1463 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1464 | channel->src = TSPP_SOURCE_NONE; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1465 | return 0; |
| 1466 | } |
| 1467 | EXPORT_SYMBOL(tspp_close_stream); |
| 1468 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1469 | /** |
| 1470 | * tspp_open_channel - open a TSPP channel. |
| 1471 | * |
| 1472 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1473 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 1474 | * |
| 1475 | * Return error status |
| 1476 | * |
| 1477 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1478 | int tspp_open_channel(u32 dev, u32 channel_id) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1479 | { |
| 1480 | int rc = 0; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1481 | struct sps_connect *config; |
| 1482 | struct sps_register_event *event; |
| 1483 | struct tspp_channel *channel; |
| 1484 | struct tspp_device *pdev; |
| 1485 | |
| 1486 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 1487 | pr_err("tspp: channel id out of range"); |
| 1488 | return -ECHRNG; |
| 1489 | } |
| 1490 | pdev = tspp_find_by_id(dev); |
| 1491 | if (!pdev) { |
| 1492 | pr_err("tspp_oc: can't find device %i", dev); |
| 1493 | return -ENODEV; |
| 1494 | } |
| 1495 | channel = &pdev->channels[channel_id]; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1496 | |
| 1497 | if (channel->used) { |
| 1498 | pr_err("tspp channel already in use"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1499 | return -EBUSY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1500 | } |
| 1501 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1502 | config = &channel->config; |
| 1503 | event = &channel->event; |
| 1504 | |
| 1505 | /* start the clocks if needed */ |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 1506 | if (tspp_channels_in_use(pdev) == 0) { |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 1507 | rc = tspp_clock_start(pdev); |
| 1508 | if (rc) |
| 1509 | return rc; |
| 1510 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1511 | wake_lock(&pdev->wake_lock); |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 1512 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1513 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1514 | /* mark it as used */ |
| 1515 | channel->used = 1; |
| 1516 | |
| 1517 | /* start the bam */ |
| 1518 | channel->pipe = sps_alloc_endpoint(); |
| 1519 | if (channel->pipe == 0) { |
| 1520 | pr_err("tspp: error allocating endpoint"); |
| 1521 | rc = -ENOMEM; |
| 1522 | goto err_sps_alloc; |
| 1523 | } |
| 1524 | |
| 1525 | /* get default configuration */ |
| 1526 | sps_get_config(channel->pipe, config); |
| 1527 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1528 | config->source = pdev->bam_handle; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1529 | config->destination = SPS_DEV_HANDLE_MEM; |
| 1530 | config->mode = SPS_MODE_SRC; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1531 | config->options = |
| 1532 | SPS_O_AUTO_ENABLE | /* connection is auto-enabled */ |
| 1533 | SPS_O_STREAMING | /* streaming mode */ |
| 1534 | SPS_O_DESC_DONE | /* interrupt on end of descriptor */ |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1535 | SPS_O_ACK_TRANSFERS | /* must use sps_get_iovec() */ |
| 1536 | SPS_O_HYBRID; /* Read actual descriptors in sps_get_iovec() */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1537 | config->src_pipe_index = channel->id; |
| 1538 | config->desc.size = |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1539 | TSPP_SPS_DESCRIPTOR_COUNT * SPS_DESCRIPTOR_SIZE; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1540 | config->desc.base = dma_alloc_coherent(NULL, |
| 1541 | config->desc.size, |
| 1542 | &config->desc.phys_base, |
| 1543 | GFP_KERNEL); |
| 1544 | if (config->desc.base == 0) { |
| 1545 | pr_err("tspp: error allocating sps descriptors"); |
| 1546 | rc = -ENOMEM; |
| 1547 | goto err_desc_alloc; |
| 1548 | } |
| 1549 | |
| 1550 | memset(config->desc.base, 0, config->desc.size); |
| 1551 | |
| 1552 | rc = sps_connect(channel->pipe, config); |
| 1553 | if (rc) { |
| 1554 | pr_err("tspp: error connecting bam"); |
| 1555 | goto err_connect; |
| 1556 | } |
| 1557 | |
| 1558 | event->mode = SPS_TRIGGER_CALLBACK; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1559 | event->options = SPS_O_DESC_DONE; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1560 | event->callback = tspp_sps_complete_cb; |
| 1561 | event->xfer_done = NULL; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1562 | event->user = pdev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1563 | |
| 1564 | rc = sps_register_event(channel->pipe, event); |
| 1565 | if (rc) { |
| 1566 | pr_err("tspp: error registering event"); |
| 1567 | goto err_event; |
| 1568 | } |
| 1569 | |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1570 | init_timer(&channel->expiration_timer); |
| 1571 | channel->expiration_timer.function = tspp_expiration_timer; |
| 1572 | channel->expiration_timer.data = (unsigned long)pdev; |
| 1573 | channel->expiration_timer.expires = 0xffffffffL; |
| 1574 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1575 | rc = pm_runtime_get(&pdev->pdev->dev); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1576 | if (rc < 0) { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1577 | dev_err(&pdev->pdev->dev, |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1578 | "Runtime PM: Unable to wake up tspp device, rc = %d", |
| 1579 | rc); |
| 1580 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1581 | return 0; |
| 1582 | |
| 1583 | err_event: |
| 1584 | sps_disconnect(channel->pipe); |
| 1585 | err_connect: |
| 1586 | dma_free_coherent(NULL, config->desc.size, config->desc.base, |
| 1587 | config->desc.phys_base); |
| 1588 | err_desc_alloc: |
| 1589 | sps_free_endpoint(channel->pipe); |
| 1590 | err_sps_alloc: |
| 1591 | return rc; |
| 1592 | } |
| 1593 | EXPORT_SYMBOL(tspp_open_channel); |
| 1594 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1595 | /** |
| 1596 | * tspp_close_channel - close a TSPP channel. |
| 1597 | * |
| 1598 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1599 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 1600 | * |
| 1601 | * Return error status |
| 1602 | * |
| 1603 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1604 | int tspp_close_channel(u32 dev, u32 channel_id) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1605 | { |
| 1606 | int i; |
| 1607 | int id; |
Liron Kuch | 4ed3bf6 | 2013-03-28 09:44:42 +0200 | [diff] [blame] | 1608 | int table_idx; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1609 | u32 val; |
Liron Kuch | e0acb41 | 2013-04-21 13:16:45 +0300 | [diff] [blame] | 1610 | unsigned long flags; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1611 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1612 | struct sps_connect *config; |
| 1613 | struct tspp_device *pdev; |
| 1614 | struct tspp_channel *channel; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1615 | |
| 1616 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 1617 | pr_err("tspp: channel id out of range"); |
| 1618 | return -ECHRNG; |
| 1619 | } |
| 1620 | pdev = tspp_find_by_id(dev); |
| 1621 | if (!pdev) { |
| 1622 | pr_err("tspp_close: can't find device %i", dev); |
| 1623 | return -ENODEV; |
| 1624 | } |
| 1625 | channel = &pdev->channels[channel_id]; |
| 1626 | |
| 1627 | /* if the channel is not used, we are done */ |
| 1628 | if (!channel->used) |
| 1629 | return 0; |
| 1630 | |
Liron Kuch | e0acb41 | 2013-04-21 13:16:45 +0300 | [diff] [blame] | 1631 | /* |
| 1632 | * Need to protect access to used and waiting fields, as they are |
| 1633 | * used by the tasklet which is invoked from interrupt context |
| 1634 | */ |
| 1635 | spin_lock_irqsave(&pdev->spinlock, flags); |
| 1636 | channel->used = 0; |
| 1637 | channel->waiting = NULL; |
| 1638 | spin_unlock_irqrestore(&pdev->spinlock, flags); |
| 1639 | |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1640 | if (channel->expiration_period_ms) |
| 1641 | del_timer(&channel->expiration_timer); |
| 1642 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1643 | channel->notifier = NULL; |
| 1644 | channel->notify_data = NULL; |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 1645 | channel->expiration_period_ms = 0; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1646 | |
| 1647 | config = &channel->config; |
| 1648 | pdev = channel->pdev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1649 | |
| 1650 | /* disable pipe (channel) */ |
| 1651 | val = readl_relaxed(pdev->base + TSPP_PS_DISABLE); |
| 1652 | writel_relaxed(val | channel->id, pdev->base + TSPP_PS_DISABLE); |
| 1653 | wmb(); |
| 1654 | |
| 1655 | /* unregister all filters for this channel */ |
Liron Kuch | 4ed3bf6 | 2013-03-28 09:44:42 +0200 | [diff] [blame] | 1656 | for (table_idx = 0; table_idx < TSPP_FILTER_TABLES; table_idx++) { |
| 1657 | for (i = 0; i < TSPP_NUM_PRIORITIES; i++) { |
| 1658 | struct tspp_pid_filter *filter = |
| 1659 | &pdev->filters[table_idx]->filter[i]; |
| 1660 | id = FILTER_GET_PIPE_NUMBER0(filter); |
| 1661 | if (id == channel->id) { |
| 1662 | if (FILTER_HAS_ENCRYPTION(filter)) |
| 1663 | tspp_free_key_entry( |
| 1664 | FILTER_GET_KEY_NUMBER(filter)); |
| 1665 | filter->config = 0; |
| 1666 | filter->filter = 0; |
| 1667 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | channel->filter_count = 0; |
| 1671 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1672 | /* disconnect the bam */ |
| 1673 | if (sps_disconnect(channel->pipe) != 0) |
| 1674 | pr_warn("tspp: Error freeing sps endpoint (%i)", channel->id); |
| 1675 | |
| 1676 | /* destroy the buffers */ |
| 1677 | dma_free_coherent(NULL, config->desc.size, config->desc.base, |
| 1678 | config->desc.phys_base); |
| 1679 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1680 | tspp_destroy_buffers(channel_id, channel); |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 1681 | if (channel->dma_pool) { |
| 1682 | dma_pool_destroy(channel->dma_pool); |
| 1683 | channel->dma_pool = NULL; |
| 1684 | } |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1685 | |
| 1686 | channel->src = TSPP_SOURCE_NONE; |
| 1687 | channel->mode = TSPP_MODE_DISABLED; |
| 1688 | channel->memfree = NULL; |
| 1689 | channel->user_info = NULL; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1690 | channel->buffer_count = 0; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1691 | channel->data = NULL; |
| 1692 | channel->read = NULL; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1693 | channel->locked = NULL; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1694 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 1695 | if (tspp_channels_in_use(pdev) == 0) { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1696 | wake_unlock(&pdev->wake_lock); |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 1697 | tspp_clock_stop(pdev); |
| 1698 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1699 | |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 1700 | pm_runtime_put(&pdev->pdev->dev); |
| 1701 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1702 | return 0; |
| 1703 | } |
| 1704 | EXPORT_SYMBOL(tspp_close_channel); |
| 1705 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1706 | /** |
Hamad Kadmany | 6d2a9c7 | 2013-01-31 14:49:20 +0200 | [diff] [blame] | 1707 | * tspp_get_ref_clk_counter - return the TSIF clock reference (TCR) counter. |
| 1708 | * |
| 1709 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1710 | * @source: The TSIF source from which the counter should be read |
| 1711 | * @tcr_counter: the value of TCR counter |
| 1712 | * |
| 1713 | * Return error status |
| 1714 | * |
| 1715 | * TCR increments at a rate equal to 27 MHz/256 = 105.47 kHz. |
| 1716 | * If source is neither TSIF 0 or TSIF1 0 is returned. |
| 1717 | */ |
| 1718 | int tspp_get_ref_clk_counter(u32 dev, enum tspp_source source, u32 *tcr_counter) |
| 1719 | { |
| 1720 | struct tspp_device *pdev; |
| 1721 | struct tspp_tsif_device *tsif_device; |
| 1722 | |
| 1723 | if (!tcr_counter) |
| 1724 | return -EINVAL; |
| 1725 | |
| 1726 | pdev = tspp_find_by_id(dev); |
| 1727 | if (!pdev) { |
| 1728 | pr_err("tspp_get_ref_clk_counter: can't find device %i\n", dev); |
| 1729 | return -ENODEV; |
| 1730 | } |
| 1731 | |
| 1732 | switch (source) { |
| 1733 | case TSPP_SOURCE_TSIF0: |
| 1734 | tsif_device = &pdev->tsif[0]; |
| 1735 | break; |
| 1736 | |
| 1737 | case TSPP_SOURCE_TSIF1: |
| 1738 | tsif_device = &pdev->tsif[1]; |
| 1739 | break; |
| 1740 | |
| 1741 | default: |
| 1742 | tsif_device = NULL; |
| 1743 | break; |
| 1744 | } |
| 1745 | |
| 1746 | if (tsif_device && tsif_device->ref_count) |
| 1747 | *tcr_counter = ioread32(tsif_device->base + TSIF_CLK_REF_OFF); |
| 1748 | else |
| 1749 | *tcr_counter = 0; |
| 1750 | |
| 1751 | return 0; |
| 1752 | } |
| 1753 | EXPORT_SYMBOL(tspp_get_ref_clk_counter); |
| 1754 | |
| 1755 | /** |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1756 | * tspp_add_filter - add a TSPP filter to a channel. |
| 1757 | * |
| 1758 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1759 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 1760 | * @filter: TSPP filter parameters |
| 1761 | * |
| 1762 | * Return error status |
| 1763 | * |
| 1764 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1765 | int tspp_add_filter(u32 dev, u32 channel_id, |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1766 | struct tspp_filter *filter) |
| 1767 | { |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1768 | int i, rc; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1769 | int other_channel; |
| 1770 | int entry; |
| 1771 | u32 val, pid, enabled; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1772 | struct tspp_device *pdev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1773 | struct tspp_pid_filter p; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1774 | struct tspp_channel *channel; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1775 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1776 | TSPP_DEBUG("tspp: add filter"); |
| 1777 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 1778 | pr_err("tspp: channel id out of range"); |
| 1779 | return -ECHRNG; |
| 1780 | } |
| 1781 | pdev = tspp_find_by_id(dev); |
| 1782 | if (!pdev) { |
| 1783 | pr_err("tspp_add: can't find device %i", dev); |
| 1784 | return -ENODEV; |
| 1785 | } |
| 1786 | |
| 1787 | channel = &pdev->channels[channel_id]; |
| 1788 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1789 | if (filter->source > TSPP_SOURCE_MEM) { |
| 1790 | pr_err("tspp invalid source"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1791 | return -ENOSR; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | if (filter->priority >= TSPP_NUM_PRIORITIES) { |
| 1795 | pr_err("tspp invalid source"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1796 | return -ENOSR; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1797 | } |
| 1798 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1799 | channel->mode = filter->mode; |
| 1800 | /* |
| 1801 | * if buffers are already allocated, verify they fulfil |
| 1802 | * the alignment requirements. |
| 1803 | */ |
| 1804 | if ((channel->buffer_count > 0) && |
| 1805 | (!tspp_is_buffer_size_aligned(channel->buffer_size, channel->mode))) |
| 1806 | pr_warn("tspp: buffers allocated with incorrect alignment\n"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1807 | |
| 1808 | if (filter->mode == TSPP_MODE_PES) { |
| 1809 | for (i = 0; i < TSPP_NUM_PRIORITIES; i++) { |
| 1810 | struct tspp_pid_filter *tspp_filter = |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1811 | &pdev->filters[channel->src]->filter[i]; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1812 | pid = FILTER_GET_PIPE_PID((tspp_filter)); |
| 1813 | enabled = FILTER_GET_PIPE_PROCESS0(tspp_filter); |
| 1814 | if (enabled && (pid == filter->pid)) { |
| 1815 | other_channel = |
| 1816 | FILTER_GET_PIPE_NUMBER0(tspp_filter); |
| 1817 | pr_err("tspp: pid 0x%x already in use by channel %i", |
| 1818 | filter->pid, other_channel); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1819 | return -EBADSLT; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | /* make sure this priority is not already in use */ |
| 1825 | enabled = FILTER_GET_PIPE_PROCESS0( |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1826 | (&(pdev->filters[channel->src]->filter[filter->priority]))); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1827 | if (enabled) { |
| 1828 | pr_err("tspp: filter priority %i source %i is already enabled\n", |
| 1829 | filter->priority, channel->src); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1830 | return -ENOSR; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | if (channel->mode == TSPP_MODE_PES) { |
| 1834 | /* if we are already processing in PES mode, disable pipe |
| 1835 | (channel) and filter to be updated */ |
| 1836 | val = readl_relaxed(pdev->base + TSPP_PS_DISABLE); |
| 1837 | writel_relaxed(val | (1 << channel->id), |
| 1838 | pdev->base + TSPP_PS_DISABLE); |
| 1839 | wmb(); |
| 1840 | } |
| 1841 | |
| 1842 | /* update entry */ |
| 1843 | p.filter = 0; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1844 | p.config = FILTER_TRANS_END_DISABLE; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1845 | FILTER_SET_PIPE_PROCESS0((&p), filter->mode); |
| 1846 | FILTER_SET_PIPE_PID((&p), filter->pid); |
| 1847 | FILTER_SET_PID_MASK((&p), filter->mask); |
| 1848 | FILTER_SET_PIPE_NUMBER0((&p), channel->id); |
| 1849 | FILTER_SET_PIPE_PROCESS1((&p), TSPP_MODE_DISABLED); |
| 1850 | if (filter->decrypt) { |
| 1851 | entry = tspp_get_key_entry(); |
| 1852 | if (entry == -1) { |
| 1853 | pr_err("tspp: no more keys available!"); |
| 1854 | } else { |
| 1855 | p.config |= FILTER_DECRYPT; |
| 1856 | FILTER_SET_KEY_NUMBER((&p), entry); |
| 1857 | } |
| 1858 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1859 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1860 | pdev->filters[channel->src]-> |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1861 | filter[filter->priority].config = p.config; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1862 | pdev->filters[channel->src]-> |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1863 | filter[filter->priority].filter = p.filter; |
| 1864 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1865 | /* |
| 1866 | * allocate buffers if needed (i.e. if user did has not already called |
| 1867 | * tspp_allocate_buffers() explicitly). |
| 1868 | */ |
| 1869 | if (channel->buffer_count == 0) { |
| 1870 | channel->buffer_size = |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 1871 | tspp_align_buffer_size_by_mode(channel->buffer_size, |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1872 | channel->mode); |
| 1873 | rc = tspp_allocate_buffers(dev, channel->id, |
| 1874 | channel->max_buffers, |
| 1875 | channel->buffer_size, |
| 1876 | channel->int_freq, NULL, NULL, NULL); |
| 1877 | if (rc != 0) { |
| 1878 | pr_err("tspp: tspp_allocate_buffers failed\n"); |
| 1879 | return rc; |
| 1880 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1881 | } |
| 1882 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1883 | /* reenable pipe */ |
| 1884 | val = readl_relaxed(pdev->base + TSPP_PS_DISABLE); |
| 1885 | writel_relaxed(val & ~(1 << channel->id), pdev->base + TSPP_PS_DISABLE); |
| 1886 | wmb(); |
| 1887 | val = readl_relaxed(pdev->base + TSPP_PS_DISABLE); |
| 1888 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1889 | channel->filter_count++; |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | EXPORT_SYMBOL(tspp_add_filter); |
| 1894 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1895 | /** |
| 1896 | * tspp_remove_filter - remove a TSPP filter from a channel. |
| 1897 | * |
| 1898 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1899 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 1900 | * @filter: TSPP filter parameters |
| 1901 | * |
| 1902 | * Return error status |
| 1903 | * |
| 1904 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1905 | int tspp_remove_filter(u32 dev, u32 channel_id, |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1906 | struct tspp_filter *filter) |
| 1907 | { |
| 1908 | int entry; |
| 1909 | u32 val; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1910 | struct tspp_device *pdev; |
| 1911 | int src; |
| 1912 | struct tspp_pid_filter *tspp_filter; |
| 1913 | struct tspp_channel *channel; |
| 1914 | |
| 1915 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 1916 | pr_err("tspp: channel id out of range"); |
| 1917 | return -ECHRNG; |
| 1918 | } |
| 1919 | pdev = tspp_find_by_id(dev); |
| 1920 | if (!pdev) { |
| 1921 | pr_err("tspp_remove: can't find device %i", dev); |
| 1922 | return -ENODEV; |
| 1923 | } |
| 1924 | channel = &pdev->channels[channel_id]; |
| 1925 | |
| 1926 | src = channel->src; |
| 1927 | tspp_filter = &(pdev->filters[src]->filter[filter->priority]); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1928 | |
| 1929 | /* disable pipe (channel) */ |
| 1930 | val = readl_relaxed(pdev->base + TSPP_PS_DISABLE); |
| 1931 | writel_relaxed(val | channel->id, pdev->base + TSPP_PS_DISABLE); |
| 1932 | wmb(); |
| 1933 | |
| 1934 | /* update data keys */ |
| 1935 | if (tspp_filter->config & FILTER_DECRYPT) { |
| 1936 | entry = FILTER_GET_KEY_NUMBER(tspp_filter); |
| 1937 | tspp_free_key_entry(entry); |
| 1938 | } |
| 1939 | |
| 1940 | /* update pid table */ |
| 1941 | tspp_filter->config = 0; |
| 1942 | tspp_filter->filter = 0; |
| 1943 | |
| 1944 | channel->filter_count--; |
| 1945 | |
| 1946 | /* reenable pipe */ |
| 1947 | val = readl_relaxed(pdev->base + TSPP_PS_DISABLE); |
| 1948 | writel_relaxed(val & ~(1 << channel->id), |
| 1949 | pdev->base + TSPP_PS_DISABLE); |
| 1950 | wmb(); |
| 1951 | val = readl_relaxed(pdev->base + TSPP_PS_DISABLE); |
| 1952 | |
| 1953 | return 0; |
| 1954 | } |
| 1955 | EXPORT_SYMBOL(tspp_remove_filter); |
| 1956 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 1957 | /** |
| 1958 | * tspp_set_key - set TSPP key in key table. |
| 1959 | * |
| 1960 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 1961 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 1962 | * @key: TSPP key parameters |
| 1963 | * |
| 1964 | * Return error status |
| 1965 | * |
| 1966 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1967 | int tspp_set_key(u32 dev, u32 channel_id, struct tspp_key *key) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1968 | { |
| 1969 | int i; |
| 1970 | int id; |
| 1971 | int key_index; |
| 1972 | int data; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1973 | struct tspp_channel *channel; |
| 1974 | struct tspp_device *pdev; |
| 1975 | |
| 1976 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 1977 | pr_err("tspp: channel id out of range"); |
| 1978 | return -ECHRNG; |
| 1979 | } |
| 1980 | pdev = tspp_find_by_id(dev); |
| 1981 | if (!pdev) { |
| 1982 | pr_err("tspp_set: can't find device %i", dev); |
| 1983 | return -ENODEV; |
| 1984 | } |
| 1985 | channel = &pdev->channels[channel_id]; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1986 | |
| 1987 | /* read the key index used by this channel */ |
| 1988 | for (i = 0; i < TSPP_NUM_PRIORITIES; i++) { |
| 1989 | struct tspp_pid_filter *tspp_filter = |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 1990 | &(pdev->filters[channel->src]->filter[i]); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 1991 | id = FILTER_GET_PIPE_NUMBER0(tspp_filter); |
| 1992 | if (id == channel->id) { |
| 1993 | if (FILTER_HAS_ENCRYPTION(tspp_filter)) { |
| 1994 | key_index = FILTER_GET_KEY_NUMBER(tspp_filter); |
| 1995 | break; |
| 1996 | } |
| 1997 | } |
| 1998 | } |
| 1999 | if (i == TSPP_NUM_PRIORITIES) { |
| 2000 | pr_err("tspp: no encryption on this channel"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2001 | return -ENOKEY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | if (key->parity == TSPP_KEY_PARITY_EVEN) { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2005 | pdev->tspp_key_table->entry[key_index].even_lsb = key->lsb; |
| 2006 | pdev->tspp_key_table->entry[key_index].even_msb = key->msb; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2007 | } else { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2008 | pdev->tspp_key_table->entry[key_index].odd_lsb = key->lsb; |
| 2009 | pdev->tspp_key_table->entry[key_index].odd_msb = key->msb; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2010 | } |
| 2011 | data = readl_relaxed(channel->pdev->base + TSPP_KEY_VALID); |
| 2012 | |
| 2013 | return 0; |
| 2014 | } |
| 2015 | EXPORT_SYMBOL(tspp_set_key); |
| 2016 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2017 | /** |
| 2018 | * tspp_register_notification - register TSPP channel notification function. |
| 2019 | * |
| 2020 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 2021 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 2022 | * @pNotify: notification function |
| 2023 | * @userdata: user data to pass to notification function |
| 2024 | * @timer_ms: notification for partially filled buffers |
| 2025 | * |
| 2026 | * Return error status |
| 2027 | * |
| 2028 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2029 | int tspp_register_notification(u32 dev, u32 channel_id, |
| 2030 | tspp_notifier *pNotify, void *userdata, u32 timer_ms) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2031 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2032 | struct tspp_channel *channel; |
| 2033 | struct tspp_device *pdev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2034 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2035 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 2036 | pr_err("tspp: channel id out of range"); |
| 2037 | return -ECHRNG; |
| 2038 | } |
| 2039 | pdev = tspp_find_by_id(dev); |
| 2040 | if (!pdev) { |
| 2041 | pr_err("tspp_reg: can't find device %i", dev); |
| 2042 | return -ENODEV; |
| 2043 | } |
| 2044 | channel = &pdev->channels[channel_id]; |
| 2045 | channel->notifier = pNotify; |
| 2046 | channel->notify_data = userdata; |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 2047 | channel->expiration_period_ms = timer_ms; |
| 2048 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2049 | return 0; |
| 2050 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2051 | EXPORT_SYMBOL(tspp_register_notification); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2052 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2053 | /** |
| 2054 | * tspp_unregister_notification - unregister TSPP channel notification function. |
| 2055 | * |
| 2056 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 2057 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 2058 | * |
| 2059 | * Return error status |
| 2060 | * |
| 2061 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2062 | int tspp_unregister_notification(u32 dev, u32 channel_id) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2063 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2064 | struct tspp_channel *channel; |
| 2065 | struct tspp_device *pdev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2066 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2067 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 2068 | pr_err("tspp: channel id out of range"); |
| 2069 | return -ECHRNG; |
| 2070 | } |
| 2071 | pdev = tspp_find_by_id(dev); |
| 2072 | if (!pdev) { |
| 2073 | pr_err("tspp_unreg: can't find device %i", dev); |
| 2074 | return -ENODEV; |
| 2075 | } |
| 2076 | channel = &pdev->channels[channel_id]; |
| 2077 | channel->notifier = NULL; |
| 2078 | channel->notify_data = 0; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2079 | return 0; |
| 2080 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2081 | EXPORT_SYMBOL(tspp_unregister_notification); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2082 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2083 | /** |
| 2084 | * tspp_get_buffer - get TSPP data buffer. |
| 2085 | * |
| 2086 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 2087 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 2088 | * |
| 2089 | * Return error status |
| 2090 | * |
| 2091 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2092 | const struct tspp_data_descriptor *tspp_get_buffer(u32 dev, u32 channel_id) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2093 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2094 | struct tspp_mem_buffer *buffer; |
| 2095 | struct tspp_channel *channel; |
| 2096 | struct tspp_device *pdev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2097 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2098 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 2099 | pr_err("tspp: channel id out of range"); |
| 2100 | return NULL; |
| 2101 | } |
| 2102 | pdev = tspp_find_by_id(dev); |
| 2103 | if (!pdev) { |
| 2104 | pr_err("tspp_get: can't find device %i", dev); |
| 2105 | return NULL; |
| 2106 | } |
| 2107 | channel = &pdev->channels[channel_id]; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2108 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2109 | if (!channel->read) { |
| 2110 | pr_warn("tspp: no buffer to get on channel %i!", |
| 2111 | channel->id); |
| 2112 | return NULL; |
| 2113 | } |
| 2114 | |
| 2115 | buffer = channel->read; |
| 2116 | /* see if we have any buffers ready to read */ |
| 2117 | if (buffer->state != TSPP_BUF_STATE_DATA) |
| 2118 | return 0; |
| 2119 | |
| 2120 | if (buffer->state == TSPP_BUF_STATE_DATA) { |
| 2121 | /* mark the buffer as busy */ |
| 2122 | buffer->state = TSPP_BUF_STATE_LOCKED; |
| 2123 | |
| 2124 | /* increment the pointer along the list */ |
| 2125 | channel->read = channel->read->next; |
| 2126 | } |
| 2127 | |
| 2128 | return &buffer->desc; |
| 2129 | } |
| 2130 | EXPORT_SYMBOL(tspp_get_buffer); |
| 2131 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2132 | /** |
| 2133 | * tspp_release_buffer - release TSPP data buffer back to TSPP. |
| 2134 | * |
| 2135 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 2136 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 2137 | * @descriptor_id: buffer descriptor ID |
| 2138 | * |
| 2139 | * Return error status |
| 2140 | * |
| 2141 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2142 | int tspp_release_buffer(u32 dev, u32 channel_id, u32 descriptor_id) |
| 2143 | { |
| 2144 | int i, found = 0; |
| 2145 | struct tspp_mem_buffer *buffer; |
| 2146 | struct tspp_channel *channel; |
| 2147 | struct tspp_device *pdev; |
| 2148 | |
| 2149 | if (channel_id >= TSPP_NUM_CHANNELS) { |
| 2150 | pr_err("tspp: channel id out of range"); |
| 2151 | return -ECHRNG; |
| 2152 | } |
| 2153 | pdev = tspp_find_by_id(dev); |
| 2154 | if (!pdev) { |
| 2155 | pr_err("tspp: can't find device %i", dev); |
| 2156 | return -ENODEV; |
| 2157 | } |
| 2158 | channel = &pdev->channels[channel_id]; |
| 2159 | |
| 2160 | if (descriptor_id > channel->buffer_count) |
| 2161 | pr_warn("tspp: desc id looks weird 0x%08x", descriptor_id); |
| 2162 | |
| 2163 | /* find the correct descriptor */ |
| 2164 | buffer = channel->locked; |
| 2165 | for (i = 0; i < channel->buffer_count; i++) { |
| 2166 | if (buffer->desc.id == descriptor_id) { |
| 2167 | found = 1; |
| 2168 | break; |
| 2169 | } |
| 2170 | buffer = buffer->next; |
| 2171 | } |
| 2172 | channel->locked = channel->locked->next; |
| 2173 | |
| 2174 | if (!found) { |
| 2175 | pr_err("tspp: cant find desc %i", descriptor_id); |
| 2176 | return -EINVAL; |
| 2177 | } |
| 2178 | |
| 2179 | /* make sure the buffer is in the expected state */ |
| 2180 | if (buffer->state != TSPP_BUF_STATE_LOCKED) { |
| 2181 | pr_err("tspp: buffer %i not locked", descriptor_id); |
| 2182 | return -EINVAL; |
| 2183 | } |
| 2184 | /* unlock the buffer and requeue it */ |
| 2185 | buffer->state = TSPP_BUF_STATE_WAITING; |
| 2186 | |
| 2187 | if (tspp_queue_buffer(channel, buffer)) |
| 2188 | pr_warn("tspp: can't requeue buffer"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2189 | return 0; |
| 2190 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2191 | EXPORT_SYMBOL(tspp_release_buffer); |
| 2192 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2193 | /** |
| 2194 | * tspp_allocate_buffers - allocate TSPP data buffers. |
| 2195 | * |
| 2196 | * @dev: TSPP device (up to TSPP_MAX_DEVICES) |
| 2197 | * @channel_id: Channel ID number (up to TSPP_NUM_CHANNELS) |
| 2198 | * @count: number of buffers to allocate |
| 2199 | * @size: size of each buffer to allocate |
| 2200 | * @int_freq: interrupt frequency |
| 2201 | * @alloc: user defined memory allocator function. Pass NULL for default. |
| 2202 | * @memfree: user defined memory free function. Pass NULL for default. |
| 2203 | * @user: user data to pass to the memory allocator/free function |
| 2204 | * |
| 2205 | * Return error status |
| 2206 | * |
| 2207 | * The user can optionally call this function explicitly to allocate the TSPP |
| 2208 | * data buffers. Alternatively, if the user did not call this function, it |
| 2209 | * is called implicitly by tspp_add_filter(). |
| 2210 | */ |
| 2211 | int tspp_allocate_buffers(u32 dev, u32 channel_id, u32 count, u32 size, |
| 2212 | u32 int_freq, tspp_allocator *alloc, |
| 2213 | tspp_memfree *memfree, void *user) |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2214 | { |
| 2215 | struct tspp_channel *channel; |
| 2216 | struct tspp_device *pdev; |
| 2217 | struct tspp_mem_buffer *last = NULL; |
| 2218 | |
| 2219 | TSPP_DEBUG("tspp_allocate_buffers"); |
| 2220 | |
| 2221 | if (channel_id >= TSPP_NUM_CHANNELS) { |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2222 | pr_err("%s: channel id out of range", __func__); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2223 | return -ECHRNG; |
| 2224 | } |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2225 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2226 | pdev = tspp_find_by_id(dev); |
| 2227 | if (!pdev) { |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2228 | pr_err("%s: can't find device %i", __func__, dev); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2229 | return -ENODEV; |
| 2230 | } |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2231 | |
| 2232 | if (count < MIN_ACCEPTABLE_BUFFER_COUNT) { |
| 2233 | pr_err("%s: tspp requires a minimum of %i buffers\n", |
| 2234 | __func__, MIN_ACCEPTABLE_BUFFER_COUNT); |
| 2235 | return -EINVAL; |
| 2236 | } |
| 2237 | |
Hamad Kadmany | 2402035 | 2013-05-22 12:54:18 +0300 | [diff] [blame] | 2238 | if (count > TSPP_NUM_BUFFERS) { |
| 2239 | pr_err("%s: tspp requires a maximum of %i buffers\n", |
| 2240 | __func__, TSPP_NUM_BUFFERS); |
| 2241 | return -EINVAL; |
| 2242 | } |
| 2243 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2244 | channel = &pdev->channels[channel_id]; |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 2245 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2246 | /* allow buffer allocation only if there was no previous buffer |
| 2247 | * allocation for this channel. |
| 2248 | */ |
| 2249 | if (channel->buffer_count > 0) { |
| 2250 | pr_err("%s: buffers already allocated for channel %u", |
| 2251 | __func__, channel_id); |
| 2252 | return -EINVAL; |
| 2253 | } |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2254 | |
| 2255 | channel->max_buffers = count; |
| 2256 | |
| 2257 | /* set up interrupt frequency */ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2258 | if (int_freq > channel->max_buffers) { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2259 | int_freq = channel->max_buffers; |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2260 | pr_warn("%s: setting interrupt frequency to %u\n", |
| 2261 | __func__, int_freq); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2262 | } |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2263 | channel->int_freq = int_freq; |
| 2264 | /* |
| 2265 | * it is the responsibility of the caller to tspp_allocate_buffers(), |
| 2266 | * whether it's the user or the driver, to make sure the size parameter |
| 2267 | * is compatible to the channel mode. |
| 2268 | */ |
| 2269 | channel->buffer_size = size; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2270 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2271 | /* save user defined memory free function for later use */ |
| 2272 | channel->memfree = memfree; |
| 2273 | channel->user_info = user; |
| 2274 | |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 2275 | /* |
| 2276 | * For small buffers, create a DMA pool so that memory |
| 2277 | * is not wasted through dma_alloc_coherent. |
| 2278 | */ |
| 2279 | if (TSPP_USE_DMA_POOL(channel->buffer_size)) { |
| 2280 | channel->dma_pool = dma_pool_create("tspp", |
| 2281 | NULL, channel->buffer_size, 0, 0); |
| 2282 | if (!channel->dma_pool) { |
| 2283 | pr_err("%s: Can't allocate memory pool\n", __func__); |
| 2284 | return -ENOMEM; |
| 2285 | } |
| 2286 | } else { |
| 2287 | channel->dma_pool = NULL; |
| 2288 | } |
| 2289 | |
| 2290 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2291 | for (channel->buffer_count = 0; |
| 2292 | channel->buffer_count < channel->max_buffers; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2293 | channel->buffer_count++) { |
| 2294 | |
| 2295 | /* allocate the descriptor */ |
| 2296 | struct tspp_mem_buffer *desc = (struct tspp_mem_buffer *) |
| 2297 | kmalloc(sizeof(struct tspp_mem_buffer), GFP_KERNEL); |
| 2298 | if (!desc) { |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2299 | pr_warn("%s: Can't allocate desc %i", |
| 2300 | __func__, channel->buffer_count); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2301 | break; |
| 2302 | } |
| 2303 | |
| 2304 | desc->desc.id = channel->buffer_count; |
| 2305 | /* allocate the buffer */ |
| 2306 | if (tspp_alloc_buffer(channel_id, &desc->desc, |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 2307 | channel->buffer_size, channel->dma_pool, |
| 2308 | alloc, user) != 0) { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2309 | kfree(desc); |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2310 | pr_warn("%s: Can't allocate buffer %i", |
| 2311 | __func__, channel->buffer_count); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2312 | break; |
| 2313 | } |
| 2314 | |
| 2315 | /* add the descriptor to the list */ |
| 2316 | desc->filled = 0; |
| 2317 | desc->read_index = 0; |
| 2318 | if (!channel->data) { |
| 2319 | channel->data = desc; |
| 2320 | desc->next = channel->data; |
| 2321 | } else { |
| 2322 | last->next = desc; |
| 2323 | } |
| 2324 | last = desc; |
| 2325 | desc->next = channel->data; |
| 2326 | |
| 2327 | /* prepare the sps descriptor */ |
| 2328 | desc->sps.phys_base = desc->desc.phys_base; |
| 2329 | desc->sps.base = desc->desc.virt_base; |
| 2330 | desc->sps.size = desc->desc.size; |
| 2331 | |
| 2332 | /* start the transfer */ |
| 2333 | if (tspp_queue_buffer(channel, desc)) |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2334 | pr_err("%s: can't queue buffer %i", |
| 2335 | __func__, desc->desc.id); |
| 2336 | } |
| 2337 | |
| 2338 | if (channel->buffer_count < channel->max_buffers) { |
| 2339 | /* |
| 2340 | * we failed to allocate the requested number of buffers. |
| 2341 | * we don't allow a partial success, so need to clean up here. |
| 2342 | */ |
| 2343 | tspp_destroy_buffers(channel_id, channel); |
| 2344 | channel->buffer_count = 0; |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 2345 | |
| 2346 | if (channel->dma_pool) { |
| 2347 | dma_pool_destroy(channel->dma_pool); |
| 2348 | channel->dma_pool = NULL; |
| 2349 | } |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2350 | return -ENOMEM; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | channel->waiting = channel->data; |
| 2354 | channel->read = channel->data; |
| 2355 | channel->locked = channel->data; |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2356 | |
Hamad Kadmany | 81cee05 | 2012-11-29 14:15:57 +0200 | [diff] [blame] | 2357 | /* Now that buffers are scheduled to HW, kick data expiration timer */ |
| 2358 | if (channel->expiration_period_ms) |
| 2359 | mod_timer(&channel->expiration_timer, |
| 2360 | jiffies + |
| 2361 | MSEC_TO_JIFFIES( |
| 2362 | channel->expiration_period_ms)); |
| 2363 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2364 | return 0; |
| 2365 | } |
| 2366 | EXPORT_SYMBOL(tspp_allocate_buffers); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2367 | |
| 2368 | /*** File Operations ***/ |
| 2369 | static ssize_t tspp_open(struct inode *inode, struct file *filp) |
| 2370 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2371 | u32 dev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2372 | struct tspp_channel *channel; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2373 | |
| 2374 | TSPP_DEBUG("tspp_open"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2375 | channel = container_of(inode->i_cdev, struct tspp_channel, cdev); |
| 2376 | filp->private_data = channel; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2377 | dev = channel->pdev->pdev->id; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2378 | |
| 2379 | /* if this channel is already in use, quit */ |
| 2380 | if (channel->used) { |
| 2381 | pr_err("tspp channel %i already in use", |
| 2382 | MINOR(channel->cdev.dev)); |
| 2383 | return -EACCES; |
| 2384 | } |
| 2385 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2386 | if (tspp_open_channel(dev, channel->id) != 0) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2387 | pr_err("tspp: error opening channel"); |
| 2388 | return -EACCES; |
| 2389 | } |
| 2390 | |
| 2391 | return 0; |
| 2392 | } |
| 2393 | |
| 2394 | static unsigned int tspp_poll(struct file *filp, struct poll_table_struct *p) |
| 2395 | { |
| 2396 | unsigned long flags; |
| 2397 | unsigned int mask = 0; |
| 2398 | struct tspp_channel *channel; |
| 2399 | channel = filp->private_data; |
| 2400 | |
| 2401 | /* register the wait queue for this channel */ |
| 2402 | poll_wait(filp, &channel->in_queue, p); |
| 2403 | |
| 2404 | spin_lock_irqsave(&channel->pdev->spinlock, flags); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2405 | if (channel->read && |
| 2406 | channel->read->state == TSPP_BUF_STATE_DATA) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2407 | mask = POLLIN | POLLRDNORM; |
| 2408 | |
| 2409 | spin_unlock_irqrestore(&channel->pdev->spinlock, flags); |
| 2410 | |
| 2411 | return mask; |
| 2412 | } |
| 2413 | |
| 2414 | static ssize_t tspp_release(struct inode *inode, struct file *filp) |
| 2415 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2416 | struct tspp_channel *channel = filp->private_data; |
| 2417 | u32 dev = channel->pdev->pdev->id; |
| 2418 | TSPP_DEBUG("tspp_release"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2419 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2420 | tspp_close_channel(dev, channel->id); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2421 | |
| 2422 | return 0; |
| 2423 | } |
| 2424 | |
| 2425 | static ssize_t tspp_read(struct file *filp, char __user *buf, size_t count, |
| 2426 | loff_t *f_pos) |
| 2427 | { |
| 2428 | size_t size = 0; |
| 2429 | size_t transferred = 0; |
| 2430 | struct tspp_channel *channel; |
| 2431 | struct tspp_mem_buffer *buffer; |
| 2432 | channel = filp->private_data; |
| 2433 | |
| 2434 | TSPP_DEBUG("tspp_read"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2435 | |
| 2436 | while (!channel->read) { |
| 2437 | if (filp->f_flags & O_NONBLOCK) { |
| 2438 | pr_warn("tspp: no buffer on channel %i!", |
| 2439 | channel->id); |
| 2440 | return -EAGAIN; |
| 2441 | } |
| 2442 | /* go to sleep if there is nothing to read */ |
| 2443 | if (wait_event_interruptible(channel->in_queue, |
| 2444 | (channel->read != NULL))) { |
| 2445 | pr_err("tspp: rude awakening\n"); |
| 2446 | return -ERESTARTSYS; |
| 2447 | } |
| 2448 | } |
| 2449 | |
| 2450 | buffer = channel->read; |
| 2451 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2452 | /* see if we have any buffers ready to read */ |
| 2453 | while (buffer->state != TSPP_BUF_STATE_DATA) { |
| 2454 | if (filp->f_flags & O_NONBLOCK) { |
| 2455 | pr_warn("tspp: nothing to read on channel %i!", |
| 2456 | channel->id); |
| 2457 | return -EAGAIN; |
| 2458 | } |
| 2459 | /* go to sleep if there is nothing to read */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2460 | if (wait_event_interruptible(channel->in_queue, |
| 2461 | (buffer->state == TSPP_BUF_STATE_DATA))) { |
| 2462 | pr_err("tspp: rude awakening\n"); |
| 2463 | return -ERESTARTSYS; |
| 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | while (buffer->state == TSPP_BUF_STATE_DATA) { |
| 2468 | size = min(count, buffer->filled); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2469 | if (size == 0) |
| 2470 | break; |
| 2471 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2472 | if (copy_to_user(buf, buffer->desc.virt_base + |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2473 | buffer->read_index, size)) { |
| 2474 | pr_err("tspp: error copying to user buffer"); |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2475 | return -EBUSY; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2476 | } |
| 2477 | buf += size; |
| 2478 | count -= size; |
| 2479 | transferred += size; |
| 2480 | buffer->read_index += size; |
| 2481 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2482 | /* |
| 2483 | * after reading the end of the buffer, requeue it, |
| 2484 | * and set up for reading the next one |
| 2485 | */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2486 | if (buffer->read_index == buffer->filled) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2487 | buffer->state = TSPP_BUF_STATE_WAITING; |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 2488 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2489 | if (tspp_queue_buffer(channel, buffer)) |
| 2490 | pr_err("tspp: can't submit transfer"); |
Hamad Kadmany | 090709b | 2013-01-06 12:08:13 +0200 | [diff] [blame] | 2491 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2492 | channel->locked = channel->read; |
| 2493 | channel->read = channel->read->next; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | return transferred; |
| 2498 | } |
| 2499 | |
| 2500 | static long tspp_ioctl(struct file *filp, |
| 2501 | unsigned int param0, unsigned long param1) |
| 2502 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2503 | u32 dev; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2504 | int rc = -1; |
| 2505 | struct tspp_channel *channel; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2506 | struct tspp_select_source ss; |
| 2507 | struct tspp_filter f; |
| 2508 | struct tspp_key k; |
| 2509 | struct tspp_iv iv; |
| 2510 | struct tspp_system_keys sk; |
| 2511 | struct tspp_buffer b; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2512 | channel = filp->private_data; |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2513 | dev = channel->pdev->pdev->id; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2514 | |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 2515 | if ((param0 != TSPP_IOCTL_CLOSE_STREAM) && !param1) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2516 | return -EINVAL; |
| 2517 | |
| 2518 | switch (param0) { |
| 2519 | case TSPP_IOCTL_SELECT_SOURCE: |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2520 | if (!access_ok(VERIFY_READ, param1, |
| 2521 | sizeof(struct tspp_select_source))) { |
| 2522 | return -EBUSY; |
| 2523 | } |
| 2524 | if (__copy_from_user(&ss, (void *)param1, |
| 2525 | sizeof(struct tspp_select_source)) == 0) |
| 2526 | rc = tspp_select_source(dev, channel->id, &ss); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2527 | break; |
| 2528 | case TSPP_IOCTL_ADD_FILTER: |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2529 | if (!access_ok(VERIFY_READ, param1, |
| 2530 | sizeof(struct tspp_filter))) { |
| 2531 | return -ENOSR; |
| 2532 | } |
| 2533 | if (__copy_from_user(&f, (void *)param1, |
| 2534 | sizeof(struct tspp_filter)) == 0) |
| 2535 | rc = tspp_add_filter(dev, channel->id, &f); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2536 | break; |
| 2537 | case TSPP_IOCTL_REMOVE_FILTER: |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2538 | if (!access_ok(VERIFY_READ, param1, |
| 2539 | sizeof(struct tspp_filter))) { |
| 2540 | return -EBUSY; |
| 2541 | } |
| 2542 | if (__copy_from_user(&f, (void *)param1, |
| 2543 | sizeof(struct tspp_filter)) == 0) |
| 2544 | rc = tspp_remove_filter(dev, channel->id, &f); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2545 | break; |
| 2546 | case TSPP_IOCTL_SET_KEY: |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2547 | if (!access_ok(VERIFY_READ, param1, |
| 2548 | sizeof(struct tspp_key))) { |
| 2549 | return -EBUSY; |
| 2550 | } |
| 2551 | if (__copy_from_user(&k, (void *)param1, |
| 2552 | sizeof(struct tspp_key)) == 0) |
| 2553 | rc = tspp_set_key(dev, channel->id, &k); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2554 | break; |
| 2555 | case TSPP_IOCTL_SET_IV: |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2556 | if (!access_ok(VERIFY_READ, param1, |
| 2557 | sizeof(struct tspp_iv))) { |
| 2558 | return -EBUSY; |
| 2559 | } |
| 2560 | if (__copy_from_user(&iv, (void *)param1, |
| 2561 | sizeof(struct tspp_iv)) == 0) |
| 2562 | rc = tspp_set_iv(channel, &iv); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2563 | break; |
| 2564 | case TSPP_IOCTL_SET_SYSTEM_KEYS: |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2565 | if (!access_ok(VERIFY_READ, param1, |
| 2566 | sizeof(struct tspp_system_keys))) { |
| 2567 | return -EINVAL; |
| 2568 | } |
| 2569 | if (__copy_from_user(&sk, (void *)param1, |
| 2570 | sizeof(struct tspp_system_keys)) == 0) |
| 2571 | rc = tspp_set_system_keys(channel, &sk); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2572 | break; |
| 2573 | case TSPP_IOCTL_BUFFER_SIZE: |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2574 | if (!access_ok(VERIFY_READ, param1, |
| 2575 | sizeof(struct tspp_buffer))) { |
| 2576 | rc = -EINVAL; |
| 2577 | } |
| 2578 | if (__copy_from_user(&b, (void *)param1, |
| 2579 | sizeof(struct tspp_buffer)) == 0) |
| 2580 | rc = tspp_set_buffer_size(channel, &b); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2581 | break; |
Liron Kuch | a7b49ae | 2013-02-14 16:26:38 +0200 | [diff] [blame] | 2582 | case TSPP_IOCTL_CLOSE_STREAM: |
| 2583 | rc = tspp_close_stream(dev, channel->id); |
| 2584 | break; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2585 | default: |
| 2586 | pr_err("tspp: Unknown ioctl %i", param0); |
| 2587 | } |
| 2588 | |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2589 | /* |
| 2590 | * normalize the return code in case one of the subfunctions does |
| 2591 | * something weird |
| 2592 | */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2593 | if (rc != 0) |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2594 | rc = -ENOIOCTLCMD; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2595 | |
| 2596 | return rc; |
| 2597 | } |
| 2598 | |
| 2599 | /*** debugfs ***/ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2600 | static int debugfs_iomem_x32_set(void *data, u64 val) |
| 2601 | { |
| 2602 | writel_relaxed(val, data); |
| 2603 | wmb(); |
| 2604 | return 0; |
| 2605 | } |
| 2606 | |
| 2607 | static int debugfs_iomem_x32_get(void *data, u64 *val) |
| 2608 | { |
| 2609 | *val = readl_relaxed(data); |
| 2610 | return 0; |
| 2611 | } |
| 2612 | |
| 2613 | DEFINE_SIMPLE_ATTRIBUTE(fops_iomem_x32, debugfs_iomem_x32_get, |
| 2614 | debugfs_iomem_x32_set, "0x%08llx"); |
| 2615 | |
| 2616 | static void tsif_debugfs_init(struct tspp_tsif_device *tsif_device, |
| 2617 | int instance) |
| 2618 | { |
| 2619 | char name[10]; |
| 2620 | snprintf(name, 10, "tsif%i", instance); |
| 2621 | tsif_device->dent_tsif = debugfs_create_dir( |
| 2622 | name, NULL); |
| 2623 | if (tsif_device->dent_tsif) { |
| 2624 | int i; |
| 2625 | void __iomem *base = tsif_device->base; |
| 2626 | for (i = 0; i < ARRAY_SIZE(debugfs_tsif_regs); i++) { |
| 2627 | tsif_device->debugfs_tsif_regs[i] = |
| 2628 | debugfs_create_file( |
| 2629 | debugfs_tsif_regs[i].name, |
| 2630 | debugfs_tsif_regs[i].mode, |
| 2631 | tsif_device->dent_tsif, |
| 2632 | base + debugfs_tsif_regs[i].offset, |
| 2633 | &fops_iomem_x32); |
| 2634 | } |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 2635 | |
| 2636 | debugfs_create_u32( |
| 2637 | "stat_rx_chunks", |
Hamad Kadmany | a1dde82 | 2013-03-28 08:23:26 +0200 | [diff] [blame] | 2638 | S_IRUGO | S_IWUSR | S_IWGRP, |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 2639 | tsif_device->dent_tsif, |
| 2640 | &tsif_device->stat_rx); |
| 2641 | |
| 2642 | debugfs_create_u32( |
| 2643 | "stat_overflow", |
Hamad Kadmany | a1dde82 | 2013-03-28 08:23:26 +0200 | [diff] [blame] | 2644 | S_IRUGO | S_IWUSR | S_IWGRP, |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 2645 | tsif_device->dent_tsif, |
| 2646 | &tsif_device->stat_overflow); |
| 2647 | |
| 2648 | debugfs_create_u32( |
| 2649 | "stat_lost_sync", |
Hamad Kadmany | a1dde82 | 2013-03-28 08:23:26 +0200 | [diff] [blame] | 2650 | S_IRUGO | S_IWUSR | S_IWGRP, |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 2651 | tsif_device->dent_tsif, |
| 2652 | &tsif_device->stat_lost_sync); |
| 2653 | |
| 2654 | debugfs_create_u32( |
| 2655 | "stat_timeout", |
Hamad Kadmany | a1dde82 | 2013-03-28 08:23:26 +0200 | [diff] [blame] | 2656 | S_IRUGO | S_IWUSR | S_IWGRP, |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 2657 | tsif_device->dent_tsif, |
| 2658 | &tsif_device->stat_timeout); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | static void tsif_debugfs_exit(struct tspp_tsif_device *tsif_device) |
| 2663 | { |
| 2664 | if (tsif_device->dent_tsif) { |
| 2665 | int i; |
| 2666 | debugfs_remove_recursive(tsif_device->dent_tsif); |
| 2667 | tsif_device->dent_tsif = NULL; |
| 2668 | for (i = 0; i < ARRAY_SIZE(debugfs_tsif_regs); i++) |
| 2669 | tsif_device->debugfs_tsif_regs[i] = NULL; |
| 2670 | } |
| 2671 | } |
| 2672 | |
| 2673 | static void tspp_debugfs_init(struct tspp_device *device, int instance) |
| 2674 | { |
| 2675 | char name[10]; |
| 2676 | snprintf(name, 10, "tspp%i", instance); |
| 2677 | device->dent = debugfs_create_dir( |
| 2678 | name, NULL); |
| 2679 | if (device->dent) { |
| 2680 | int i; |
| 2681 | void __iomem *base = device->base; |
| 2682 | for (i = 0; i < ARRAY_SIZE(debugfs_tspp_regs); i++) { |
| 2683 | device->debugfs_regs[i] = |
| 2684 | debugfs_create_file( |
| 2685 | debugfs_tspp_regs[i].name, |
| 2686 | debugfs_tspp_regs[i].mode, |
| 2687 | device->dent, |
| 2688 | base + debugfs_tspp_regs[i].offset, |
| 2689 | &fops_iomem_x32); |
| 2690 | } |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | static void tspp_debugfs_exit(struct tspp_device *device) |
| 2695 | { |
| 2696 | if (device->dent) { |
| 2697 | int i; |
| 2698 | debugfs_remove_recursive(device->dent); |
| 2699 | device->dent = NULL; |
| 2700 | for (i = 0; i < ARRAY_SIZE(debugfs_tspp_regs); i++) |
| 2701 | device->debugfs_regs[i] = NULL; |
| 2702 | } |
| 2703 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2704 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2705 | /* copy device-tree data to platfrom data struct */ |
| 2706 | static __devinit struct msm_tspp_platform_data * |
| 2707 | msm_tspp_dt_to_pdata(struct platform_device *pdev) |
| 2708 | { |
| 2709 | struct device_node *node = pdev->dev.of_node; |
| 2710 | struct msm_tspp_platform_data *data; |
| 2711 | struct msm_gpio *gpios; |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 2712 | struct property *prop; |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2713 | int i, rc; |
| 2714 | int gpio; |
| 2715 | u32 gpio_func; |
| 2716 | |
| 2717 | /* Note: memory allocated by devm_kzalloc is freed automatically */ |
| 2718 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
| 2719 | if (!data) { |
| 2720 | pr_err("tspp: Unable to allocate platform data\n"); |
| 2721 | return NULL; |
| 2722 | } |
| 2723 | rc = of_property_read_string(node, "qcom,tsif-pclk", &data->tsif_pclk); |
| 2724 | if (rc) { |
| 2725 | pr_err("tspp: Could not find tsif-pclk property, err = %d\n", |
| 2726 | rc); |
| 2727 | return NULL; |
| 2728 | } |
| 2729 | rc = of_property_read_string(node, "qcom,tsif-ref-clk", |
| 2730 | &data->tsif_ref_clk); |
| 2731 | if (rc) { |
| 2732 | pr_err("tspp: Could not find tsif-ref-clk property, err = %d\n", |
| 2733 | rc); |
| 2734 | return NULL; |
| 2735 | } |
| 2736 | |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 2737 | data->tsif_vreg_present = 0; |
| 2738 | prop = of_find_property(node, "vdd_cx-supply", NULL); |
| 2739 | if (prop) |
| 2740 | data->tsif_vreg_present = 1; |
| 2741 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2742 | data->num_gpios = of_gpio_count(node); |
| 2743 | if (data->num_gpios == 0) { |
| 2744 | pr_err("tspp: Could not find GPIO definitions\n"); |
| 2745 | return NULL; |
| 2746 | } |
| 2747 | gpios = devm_kzalloc(&pdev->dev, |
| 2748 | (data->num_gpios * sizeof(struct msm_gpio)), |
| 2749 | GFP_KERNEL); |
| 2750 | if (!gpios) { |
| 2751 | pr_err("tspp: Unable to allocate memory for GPIOs table\n"); |
| 2752 | return NULL; |
| 2753 | } |
| 2754 | /* Assuming GPIO FUNC property is the same for all GPIOs */ |
| 2755 | if (of_property_read_u32(node, "qcom,gpios-func", &gpio_func)) { |
| 2756 | pr_err("tspp: Could not find gpios-func property\n"); |
| 2757 | return NULL; |
| 2758 | } |
| 2759 | for (i = 0; i < data->num_gpios; i++) { |
| 2760 | gpio = of_get_gpio(node, i); |
| 2761 | gpios[i].gpio_cfg = GPIO_CFG(gpio, gpio_func, |
| 2762 | GPIO_CFG_INPUT, |
| 2763 | GPIO_CFG_PULL_DOWN, |
| 2764 | GPIO_CFG_2MA); |
| 2765 | rc = of_property_read_string_index(node, "qcom,gpio-names", |
| 2766 | i, &gpios[i].label); |
| 2767 | if (rc) |
| 2768 | pr_warn("tspp: Could not find gpio-names property\n"); |
| 2769 | } |
| 2770 | |
| 2771 | data->gpios = gpios; |
| 2772 | |
| 2773 | return data; |
| 2774 | } |
| 2775 | |
| 2776 | static int msm_tspp_map_irqs(struct platform_device *pdev, |
| 2777 | struct tspp_device *device) |
| 2778 | { |
| 2779 | int rc; |
| 2780 | int i; |
| 2781 | |
| 2782 | /* get IRQ numbers from platform information */ |
| 2783 | |
| 2784 | /* map TSPP IRQ */ |
| 2785 | rc = platform_get_irq_byname(pdev, "TSIF_TSPP_IRQ"); |
| 2786 | if (rc > 0) { |
| 2787 | device->tspp_irq = rc; |
| 2788 | rc = request_irq(device->tspp_irq, tspp_isr, IRQF_SHARED, |
| 2789 | dev_name(&pdev->dev), device); |
| 2790 | if (rc) { |
| 2791 | dev_err(&pdev->dev, |
| 2792 | "failed to request TSPP IRQ %d : %d", |
| 2793 | device->tspp_irq, rc); |
| 2794 | device->tspp_irq = 0; |
| 2795 | return -EINVAL; |
| 2796 | } |
| 2797 | } else { |
| 2798 | dev_err(&pdev->dev, "failed to get TSPP IRQ"); |
| 2799 | return -EINVAL; |
| 2800 | } |
| 2801 | |
| 2802 | /* map TSIF IRQs */ |
| 2803 | rc = platform_get_irq_byname(pdev, "TSIF0_IRQ"); |
| 2804 | if (rc > 0) { |
| 2805 | device->tsif[0].tsif_irq = rc; |
| 2806 | } else { |
| 2807 | dev_err(&pdev->dev, "failed to get TSIF0 IRQ"); |
| 2808 | return -EINVAL; |
| 2809 | } |
| 2810 | |
| 2811 | rc = platform_get_irq_byname(pdev, "TSIF1_IRQ"); |
| 2812 | if (rc > 0) { |
| 2813 | device->tsif[1].tsif_irq = rc; |
| 2814 | } else { |
| 2815 | dev_err(&pdev->dev, "failed to get TSIF1 IRQ"); |
| 2816 | return -EINVAL; |
| 2817 | } |
| 2818 | |
| 2819 | for (i = 0; i < TSPP_TSIF_INSTANCES; i++) { |
| 2820 | rc = request_irq(device->tsif[i].tsif_irq, |
| 2821 | tsif_isr, IRQF_SHARED, |
| 2822 | dev_name(&pdev->dev), &device->tsif[i]); |
| 2823 | if (rc) { |
| 2824 | dev_warn(&pdev->dev, "failed to request TSIF%d IRQ: %d", |
| 2825 | i, rc); |
| 2826 | device->tsif[i].tsif_irq = 0; |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | /* map BAM IRQ */ |
| 2831 | rc = platform_get_irq_byname(pdev, "TSIF_BAM_IRQ"); |
| 2832 | if (rc > 0) { |
| 2833 | device->bam_irq = rc; |
| 2834 | } else { |
| 2835 | dev_err(&pdev->dev, "failed to get TSPP BAM IRQ"); |
| 2836 | return -EINVAL; |
| 2837 | } |
| 2838 | |
| 2839 | return 0; |
| 2840 | } |
| 2841 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2842 | static int __devinit msm_tspp_probe(struct platform_device *pdev) |
| 2843 | { |
| 2844 | int rc = -ENODEV; |
| 2845 | u32 version; |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2846 | u32 i, j; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2847 | struct msm_tspp_platform_data *data; |
| 2848 | struct tspp_device *device; |
| 2849 | struct resource *mem_tsif0; |
| 2850 | struct resource *mem_tsif1; |
| 2851 | struct resource *mem_tspp; |
| 2852 | struct resource *mem_bam; |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 2853 | struct tspp_channel *channel; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2854 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2855 | if (pdev->dev.of_node) { |
| 2856 | /* get information from device tree */ |
| 2857 | data = msm_tspp_dt_to_pdata(pdev); |
| 2858 | /* get device ID */ |
| 2859 | rc = of_property_read_u32(pdev->dev.of_node, |
| 2860 | "cell-index", &pdev->id); |
| 2861 | if (rc) |
| 2862 | pdev->id = -1; |
| 2863 | |
| 2864 | pdev->dev.platform_data = data; |
| 2865 | } else { |
| 2866 | /* must have platform data */ |
| 2867 | data = pdev->dev.platform_data; |
| 2868 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2869 | if (!data) { |
| 2870 | pr_err("tspp: Platform data not available"); |
| 2871 | rc = -EINVAL; |
| 2872 | goto out; |
| 2873 | } |
| 2874 | |
| 2875 | /* check for valid device id */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 2876 | if ((pdev->id < 0) || (pdev->id >= TSPP_MAX_DEVICES)) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2877 | pr_err("tspp: Invalid device ID %d", pdev->id); |
| 2878 | rc = -EINVAL; |
| 2879 | goto out; |
| 2880 | } |
| 2881 | |
| 2882 | /* OK, we will use this device */ |
| 2883 | device = kzalloc(sizeof(struct tspp_device), GFP_KERNEL); |
| 2884 | if (!device) { |
| 2885 | pr_err("tspp: Failed to allocate memory for device"); |
| 2886 | rc = -ENOMEM; |
| 2887 | goto out; |
| 2888 | } |
| 2889 | |
| 2890 | /* set up references */ |
| 2891 | device->pdev = pdev; |
| 2892 | platform_set_drvdata(pdev, device); |
| 2893 | |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 2894 | /* map regulators */ |
| 2895 | if (data->tsif_vreg_present) { |
| 2896 | device->tsif_vreg = devm_regulator_get(&pdev->dev, "vdd_cx"); |
| 2897 | if (IS_ERR(device->tsif_vreg)) { |
| 2898 | rc = PTR_ERR(device->tsif_vreg); |
| 2899 | device->tsif_vreg = NULL; |
| 2900 | goto err_regultaor; |
| 2901 | } |
| 2902 | |
| 2903 | /* Set an initial voltage and enable the regulator */ |
| 2904 | rc = regulator_set_voltage(device->tsif_vreg, |
| 2905 | RPM_REGULATOR_CORNER_SVS_SOC, |
| 2906 | RPM_REGULATOR_CORNER_SUPER_TURBO); |
| 2907 | if (rc) { |
| 2908 | dev_err(&pdev->dev, "Unable to set CX voltage.\n"); |
| 2909 | goto err_regultaor; |
| 2910 | } |
| 2911 | |
| 2912 | rc = regulator_enable(device->tsif_vreg); |
| 2913 | if (rc) { |
| 2914 | dev_err(&pdev->dev, "Unable to enable CX regulator.\n"); |
| 2915 | goto err_regultaor; |
| 2916 | } |
| 2917 | } |
| 2918 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2919 | /* map clocks */ |
| 2920 | if (data->tsif_pclk) { |
Joel Nider | b9662ca | 2012-06-10 14:21:11 +0300 | [diff] [blame] | 2921 | device->tsif_pclk = clk_get(&pdev->dev, data->tsif_pclk); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2922 | if (IS_ERR(device->tsif_pclk)) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2923 | rc = PTR_ERR(device->tsif_pclk); |
| 2924 | device->tsif_pclk = NULL; |
| 2925 | goto err_pclock; |
| 2926 | } |
| 2927 | } |
| 2928 | if (data->tsif_ref_clk) { |
Joel Nider | b9662ca | 2012-06-10 14:21:11 +0300 | [diff] [blame] | 2929 | device->tsif_ref_clk = clk_get(&pdev->dev, data->tsif_ref_clk); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2930 | if (IS_ERR(device->tsif_ref_clk)) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2931 | rc = PTR_ERR(device->tsif_ref_clk); |
| 2932 | device->tsif_ref_clk = NULL; |
| 2933 | goto err_refclock; |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | /* map I/O memory */ |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2938 | mem_tsif0 = platform_get_resource_byname(pdev, |
| 2939 | IORESOURCE_MEM, "MSM_TSIF0_PHYS"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2940 | if (!mem_tsif0) { |
| 2941 | pr_err("tspp: Missing tsif0 MEM resource"); |
| 2942 | rc = -ENXIO; |
| 2943 | goto err_res_tsif0; |
| 2944 | } |
| 2945 | device->tsif[0].base = ioremap(mem_tsif0->start, |
| 2946 | resource_size(mem_tsif0)); |
| 2947 | if (!device->tsif[0].base) { |
| 2948 | pr_err("tspp: ioremap failed"); |
| 2949 | goto err_map_tsif0; |
| 2950 | } |
| 2951 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2952 | mem_tsif1 = platform_get_resource_byname(pdev, |
| 2953 | IORESOURCE_MEM, "MSM_TSIF1_PHYS"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2954 | if (!mem_tsif1) { |
| 2955 | dev_err(&pdev->dev, "Missing tsif1 MEM resource"); |
| 2956 | rc = -ENXIO; |
| 2957 | goto err_res_tsif1; |
| 2958 | } |
| 2959 | device->tsif[1].base = ioremap(mem_tsif1->start, |
| 2960 | resource_size(mem_tsif1)); |
| 2961 | if (!device->tsif[1].base) { |
| 2962 | dev_err(&pdev->dev, "ioremap failed"); |
| 2963 | goto err_map_tsif1; |
| 2964 | } |
| 2965 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2966 | mem_tspp = platform_get_resource_byname(pdev, |
| 2967 | IORESOURCE_MEM, "MSM_TSPP_PHYS"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2968 | if (!mem_tspp) { |
| 2969 | dev_err(&pdev->dev, "Missing MEM resource"); |
| 2970 | rc = -ENXIO; |
| 2971 | goto err_res_dev; |
| 2972 | } |
| 2973 | device->base = ioremap(mem_tspp->start, resource_size(mem_tspp)); |
| 2974 | if (!device->base) { |
| 2975 | dev_err(&pdev->dev, "ioremap failed"); |
| 2976 | goto err_map_dev; |
| 2977 | } |
| 2978 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2979 | mem_bam = platform_get_resource_byname(pdev, |
| 2980 | IORESOURCE_MEM, "MSM_TSPP_BAM_PHYS"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2981 | if (!mem_bam) { |
| 2982 | pr_err("tspp: Missing bam MEM resource"); |
| 2983 | rc = -ENXIO; |
| 2984 | goto err_res_bam; |
| 2985 | } |
| 2986 | memset(&device->bam_props, 0, sizeof(device->bam_props)); |
| 2987 | device->bam_props.phys_addr = mem_bam->start; |
| 2988 | device->bam_props.virt_addr = ioremap(mem_bam->start, |
| 2989 | resource_size(mem_bam)); |
| 2990 | if (!device->bam_props.virt_addr) { |
| 2991 | dev_err(&pdev->dev, "ioremap failed"); |
| 2992 | goto err_map_bam; |
| 2993 | } |
| 2994 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 2995 | if (msm_tspp_map_irqs(pdev, device)) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2996 | goto err_irq; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2997 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 2998 | /* power management */ |
| 2999 | pm_runtime_set_active(&pdev->dev); |
| 3000 | pm_runtime_enable(&pdev->dev); |
| 3001 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3002 | tspp_debugfs_init(device, 0); |
| 3003 | |
| 3004 | for (i = 0; i < TSPP_TSIF_INSTANCES; i++) |
| 3005 | tsif_debugfs_init(&device->tsif[i], i); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3006 | |
| 3007 | wake_lock_init(&device->wake_lock, WAKE_LOCK_SUSPEND, |
| 3008 | dev_name(&pdev->dev)); |
| 3009 | |
| 3010 | /* set up pointers to ram-based 'registers' */ |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3011 | device->filters[0] = device->base + TSPP_PID_FILTER_TABLE0; |
| 3012 | device->filters[1] = device->base + TSPP_PID_FILTER_TABLE1; |
| 3013 | device->filters[2] = device->base + TSPP_PID_FILTER_TABLE2; |
| 3014 | device->tspp_key_table = device->base + TSPP_DATA_KEY; |
| 3015 | device->tspp_global_performance = |
| 3016 | device->base + TSPP_GLOBAL_PERFORMANCE; |
| 3017 | device->tspp_pipe_context = |
| 3018 | device->base + TSPP_PIPE_CONTEXT; |
| 3019 | device->tspp_pipe_performance = |
| 3020 | device->base + TSPP_PIPE_PERFORMANCE; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3021 | |
| 3022 | device->bam_props.summing_threshold = 0x10; |
| 3023 | device->bam_props.irq = device->bam_irq; |
| 3024 | device->bam_props.manage = SPS_BAM_MGR_LOCAL; |
| 3025 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3026 | if (tspp_clock_start(device) != 0) { |
| 3027 | dev_err(&pdev->dev, "Can't start clocks"); |
| 3028 | goto err_clock; |
| 3029 | } |
| 3030 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3031 | if (sps_register_bam_device(&device->bam_props, |
| 3032 | &device->bam_handle) != 0) { |
| 3033 | pr_err("tspp: failed to register bam"); |
| 3034 | goto err_bam; |
| 3035 | } |
| 3036 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3037 | spin_lock_init(&device->spinlock); |
| 3038 | tasklet_init(&device->tlet, tspp_sps_complete_tlet, |
| 3039 | (unsigned long)device); |
| 3040 | |
| 3041 | /* initialize everything to a known state */ |
| 3042 | tspp_global_reset(device); |
| 3043 | |
| 3044 | version = readl_relaxed(device->base + TSPP_VERSION); |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3045 | /* |
| 3046 | * TSPP version can be bits [7:0] or alternatively, |
| 3047 | * TSPP major version is bits [31:28]. |
| 3048 | */ |
| 3049 | if ((version != 0x1) && (((version >> 28) & 0xF) != 0x1)) |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3050 | pr_warn("tspp: unrecognized hw version=%i", version); |
| 3051 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3052 | /* initialize the channels */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3053 | for (i = 0; i < TSPP_NUM_CHANNELS; i++) { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3054 | if (tspp_channel_init(&(device->channels[i]), device) != 0) { |
| 3055 | pr_err("tspp_channel_init failed"); |
| 3056 | goto err_channel; |
| 3057 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3058 | } |
| 3059 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3060 | /* stop the clocks for power savings */ |
| 3061 | tspp_clock_stop(device); |
| 3062 | |
| 3063 | /* everything is ok, so add the device to the list */ |
| 3064 | list_add_tail(&(device->devlist), &tspp_devices); |
| 3065 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3066 | return 0; |
| 3067 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3068 | err_channel: |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3069 | /* un-initialize channels */ |
Liron Kuch | 72b7855 | 2012-10-30 17:47:50 +0200 | [diff] [blame] | 3070 | for (j = 0; j < i; j++) { |
| 3071 | channel = &(device->channels[i]); |
| 3072 | device_destroy(tspp_class, channel->cdev.dev); |
| 3073 | cdev_del(&channel->cdev); |
| 3074 | } |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3075 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3076 | sps_deregister_bam_device(device->bam_handle); |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3077 | err_clock: |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3078 | err_bam: |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3079 | tspp_debugfs_exit(device); |
| 3080 | for (i = 0; i < TSPP_TSIF_INSTANCES; i++) |
| 3081 | tsif_debugfs_exit(&device->tsif[i]); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3082 | err_irq: |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3083 | for (i = 0; i < TSPP_TSIF_INSTANCES; i++) { |
| 3084 | if (device->tsif[i].tsif_irq) |
| 3085 | free_irq(device->tsif[i].tsif_irq, &device->tsif[i]); |
| 3086 | } |
| 3087 | if (device->tspp_irq) |
| 3088 | free_irq(device->tspp_irq, device); |
| 3089 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3090 | iounmap(device->bam_props.virt_addr); |
| 3091 | err_map_bam: |
| 3092 | err_res_bam: |
| 3093 | iounmap(device->base); |
| 3094 | err_map_dev: |
| 3095 | err_res_dev: |
| 3096 | iounmap(device->tsif[1].base); |
| 3097 | err_map_tsif1: |
| 3098 | err_res_tsif1: |
| 3099 | iounmap(device->tsif[0].base); |
| 3100 | err_map_tsif0: |
| 3101 | err_res_tsif0: |
| 3102 | if (device->tsif_ref_clk) |
| 3103 | clk_put(device->tsif_ref_clk); |
| 3104 | err_refclock: |
| 3105 | if (device->tsif_pclk) |
| 3106 | clk_put(device->tsif_pclk); |
| 3107 | err_pclock: |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 3108 | if (device->tsif_vreg) |
| 3109 | regulator_disable(device->tsif_vreg); |
| 3110 | err_regultaor: |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3111 | kfree(device); |
| 3112 | |
| 3113 | out: |
| 3114 | return rc; |
| 3115 | } |
| 3116 | |
| 3117 | static int __devexit msm_tspp_remove(struct platform_device *pdev) |
| 3118 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3119 | struct tspp_channel *channel; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3120 | u32 i; |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 3121 | int rc; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3122 | |
| 3123 | struct tspp_device *device = platform_get_drvdata(pdev); |
| 3124 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3125 | /* free the buffers, and delete the channels */ |
| 3126 | for (i = 0; i < TSPP_NUM_CHANNELS; i++) { |
| 3127 | channel = &device->channels[i]; |
| 3128 | tspp_close_channel(device->pdev->id, i); |
| 3129 | device_destroy(tspp_class, channel->cdev.dev); |
| 3130 | cdev_del(&channel->cdev); |
| 3131 | } |
| 3132 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3133 | /* de-registering BAM device requires clocks */ |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 3134 | rc = tspp_clock_start(device); |
| 3135 | if (rc == 0) { |
| 3136 | sps_deregister_bam_device(device->bam_handle); |
| 3137 | tspp_clock_stop(device); |
| 3138 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3139 | |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 3140 | for (i = 0; i < TSPP_TSIF_INSTANCES; i++) { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3141 | tsif_debugfs_exit(&device->tsif[i]); |
Hamad Kadmany | 44307d3 | 2012-11-25 09:49:51 +0200 | [diff] [blame] | 3142 | if (device->tsif[i].tsif_irq) |
| 3143 | free_irq(device->tsif[i].tsif_irq, &device->tsif[i]); |
| 3144 | } |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3145 | |
| 3146 | wake_lock_destroy(&device->wake_lock); |
| 3147 | free_irq(device->tspp_irq, device); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3148 | |
| 3149 | iounmap(device->bam_props.virt_addr); |
| 3150 | iounmap(device->base); |
| 3151 | for (i = 0; i < TSPP_TSIF_INSTANCES; i++) |
| 3152 | iounmap(device->tsif[i].base); |
| 3153 | |
| 3154 | if (device->tsif_ref_clk) |
| 3155 | clk_put(device->tsif_ref_clk); |
| 3156 | |
| 3157 | if (device->tsif_pclk) |
| 3158 | clk_put(device->tsif_pclk); |
| 3159 | |
Vikram Mulukutla | e9ca54b | 2013-04-19 11:08:42 -0700 | [diff] [blame] | 3160 | if (device->tsif_vreg) |
| 3161 | regulator_disable(device->tsif_vreg); |
| 3162 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3163 | pm_runtime_disable(&pdev->dev); |
Liron Kuch | 605cc12 | 2013-02-21 14:25:57 +0200 | [diff] [blame] | 3164 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3165 | kfree(device); |
| 3166 | |
| 3167 | return 0; |
| 3168 | } |
| 3169 | |
| 3170 | /*** power management ***/ |
| 3171 | |
| 3172 | static int tspp_runtime_suspend(struct device *dev) |
| 3173 | { |
| 3174 | dev_dbg(dev, "pm_runtime: suspending..."); |
| 3175 | return 0; |
| 3176 | } |
| 3177 | |
| 3178 | static int tspp_runtime_resume(struct device *dev) |
| 3179 | { |
| 3180 | dev_dbg(dev, "pm_runtime: resuming..."); |
| 3181 | return 0; |
| 3182 | } |
| 3183 | |
| 3184 | static const struct dev_pm_ops tspp_dev_pm_ops = { |
| 3185 | .runtime_suspend = tspp_runtime_suspend, |
| 3186 | .runtime_resume = tspp_runtime_resume, |
| 3187 | }; |
| 3188 | |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3189 | static struct of_device_id msm_match_table[] = { |
| 3190 | {.compatible = "qcom,msm_tspp"}, |
| 3191 | {} |
| 3192 | }; |
| 3193 | |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3194 | static struct platform_driver msm_tspp_driver = { |
| 3195 | .probe = msm_tspp_probe, |
| 3196 | .remove = __exit_p(msm_tspp_remove), |
| 3197 | .driver = { |
| 3198 | .name = "msm_tspp", |
| 3199 | .pm = &tspp_dev_pm_ops, |
Liron Kuch | 5933992 | 2013-01-01 18:29:47 +0200 | [diff] [blame] | 3200 | .of_match_table = msm_match_table, |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3201 | }, |
| 3202 | }; |
| 3203 | |
| 3204 | |
| 3205 | static int __init mod_init(void) |
| 3206 | { |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3207 | int rc; |
| 3208 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3209 | /* make the char devs (channels) */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3210 | rc = alloc_chrdev_region(&tspp_minor, 0, TSPP_NUM_CHANNELS, "tspp"); |
| 3211 | if (rc) { |
| 3212 | pr_err("tspp: alloc_chrdev_region failed: %d", rc); |
| 3213 | goto err_devrgn; |
| 3214 | } |
| 3215 | |
| 3216 | tspp_class = class_create(THIS_MODULE, "tspp"); |
| 3217 | if (IS_ERR(tspp_class)) { |
| 3218 | rc = PTR_ERR(tspp_class); |
| 3219 | pr_err("tspp: Error creating class: %d", rc); |
| 3220 | goto err_class; |
| 3221 | } |
| 3222 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3223 | /* register the driver, and check hardware */ |
| 3224 | rc = platform_driver_register(&msm_tspp_driver); |
| 3225 | if (rc) { |
| 3226 | pr_err("tspp: platform_driver_register failed: %d", rc); |
| 3227 | goto err_register; |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | return 0; |
| 3231 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3232 | err_register: |
| 3233 | class_destroy(tspp_class); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3234 | err_class: |
| 3235 | unregister_chrdev_region(0, TSPP_NUM_CHANNELS); |
| 3236 | err_devrgn: |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3237 | return rc; |
| 3238 | } |
| 3239 | |
| 3240 | static void __exit mod_exit(void) |
| 3241 | { |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3242 | /* delete low level driver */ |
| 3243 | platform_driver_unregister(&msm_tspp_driver); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3244 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3245 | /* delete upper layer interface */ |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3246 | class_destroy(tspp_class); |
| 3247 | unregister_chrdev_region(0, TSPP_NUM_CHANNELS); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | module_init(mod_init); |
| 3251 | module_exit(mod_exit); |
| 3252 | |
Joel Nider | 435ad8e | 2011-12-14 16:53:30 +0200 | [diff] [blame] | 3253 | MODULE_DESCRIPTION("TSPP platform device and char dev"); |
Joel Nider | 5556a85 | 2011-10-16 10:52:13 +0200 | [diff] [blame] | 3254 | MODULE_LICENSE("GPL v2"); |