| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) ST-Ericsson AB 2010 | 
 | 3 |  * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com | 
 | 4 |  * Author:  Daniel Martensson / Daniel.Martensson@stericsson.com | 
 | 5 |  * License terms: GNU General Public License (GPL) version 2. | 
 | 6 |  */ | 
 | 7 |  | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 8 | #include <linux/init.h> | 
 | 9 | #include <linux/module.h> | 
 | 10 | #include <linux/device.h> | 
 | 11 | #include <linux/platform_device.h> | 
 | 12 | #include <linux/string.h> | 
 | 13 | #include <linux/workqueue.h> | 
 | 14 | #include <linux/completion.h> | 
 | 15 | #include <linux/list.h> | 
 | 16 | #include <linux/interrupt.h> | 
 | 17 | #include <linux/dma-mapping.h> | 
 | 18 | #include <linux/delay.h> | 
 | 19 | #include <linux/sched.h> | 
 | 20 | #include <linux/debugfs.h> | 
 | 21 | #include <linux/if_arp.h> | 
 | 22 | #include <net/caif/caif_layer.h> | 
 | 23 | #include <net/caif/caif_spi.h> | 
 | 24 |  | 
 | 25 | #ifndef CONFIG_CAIF_SPI_SYNC | 
 | 26 | #define FLAVOR "Flavour: Vanilla.\n" | 
 | 27 | #else | 
 | 28 | #define FLAVOR "Flavour: Master CMD&LEN at start.\n" | 
 | 29 | #endif /* CONFIG_CAIF_SPI_SYNC */ | 
 | 30 |  | 
 | 31 | MODULE_LICENSE("GPL"); | 
 | 32 | MODULE_AUTHOR("Daniel Martensson<daniel.martensson@stericsson.com>"); | 
 | 33 | MODULE_DESCRIPTION("CAIF SPI driver"); | 
 | 34 |  | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 35 | /* Returns the number of padding bytes for alignment. */ | 
 | 36 | #define PAD_POW2(x, pow) ((((x)&((pow)-1))==0) ? 0 : (((pow)-((x)&((pow)-1))))) | 
 | 37 |  | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 38 | static int spi_loop; | 
 | 39 | module_param(spi_loop, bool, S_IRUGO); | 
 | 40 | MODULE_PARM_DESC(spi_loop, "SPI running in loopback mode."); | 
 | 41 |  | 
 | 42 | /* SPI frame alignment. */ | 
 | 43 | module_param(spi_frm_align, int, S_IRUGO); | 
 | 44 | MODULE_PARM_DESC(spi_frm_align, "SPI frame alignment."); | 
 | 45 |  | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 46 | /* | 
 | 47 |  * SPI padding options. | 
 | 48 |  * Warning: must be a base of 2 (& operation used) and can not be zero ! | 
 | 49 |  */ | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 50 | module_param(spi_up_head_align, int, S_IRUGO); | 
 | 51 | MODULE_PARM_DESC(spi_up_head_align, "SPI uplink head alignment."); | 
 | 52 |  | 
 | 53 | module_param(spi_up_tail_align, int, S_IRUGO); | 
 | 54 | MODULE_PARM_DESC(spi_up_tail_align, "SPI uplink tail alignment."); | 
 | 55 |  | 
 | 56 | module_param(spi_down_head_align, int, S_IRUGO); | 
 | 57 | MODULE_PARM_DESC(spi_down_head_align, "SPI downlink head alignment."); | 
 | 58 |  | 
 | 59 | module_param(spi_down_tail_align, int, S_IRUGO); | 
 | 60 | MODULE_PARM_DESC(spi_down_tail_align, "SPI downlink tail alignment."); | 
 | 61 |  | 
 | 62 | #ifdef CONFIG_ARM | 
 | 63 | #define BYTE_HEX_FMT "%02X" | 
 | 64 | #else | 
 | 65 | #define BYTE_HEX_FMT "%02hhX" | 
 | 66 | #endif | 
 | 67 |  | 
 | 68 | #define SPI_MAX_PAYLOAD_SIZE 4096 | 
 | 69 | /* | 
 | 70 |  * Threshold values for the SPI packet queue. Flowcontrol will be asserted | 
 | 71 |  * when the number of packets exceeds HIGH_WATER_MARK. It will not be | 
 | 72 |  * deasserted before the number of packets drops below LOW_WATER_MARK. | 
 | 73 |  */ | 
 | 74 | #define LOW_WATER_MARK   100 | 
 | 75 | #define HIGH_WATER_MARK  (LOW_WATER_MARK*5) | 
 | 76 |  | 
 | 77 | #ifdef CONFIG_UML | 
 | 78 |  | 
 | 79 | /* | 
 | 80 |  * We sometimes use UML for debugging, but it cannot handle | 
 | 81 |  * dma_alloc_coherent so we have to wrap it. | 
 | 82 |  */ | 
 | 83 | static inline void *dma_alloc(dma_addr_t *daddr) | 
 | 84 | { | 
 | 85 | 	return kmalloc(SPI_DMA_BUF_LEN, GFP_KERNEL); | 
 | 86 | } | 
 | 87 |  | 
 | 88 | static inline void dma_free(void *cpu_addr, dma_addr_t handle) | 
 | 89 | { | 
 | 90 | 	kfree(cpu_addr); | 
 | 91 | } | 
 | 92 |  | 
 | 93 | #else | 
 | 94 |  | 
 | 95 | static inline void *dma_alloc(dma_addr_t *daddr) | 
 | 96 | { | 
 | 97 | 	return dma_alloc_coherent(NULL, SPI_DMA_BUF_LEN, daddr, | 
 | 98 | 				GFP_KERNEL); | 
 | 99 | } | 
 | 100 |  | 
 | 101 | static inline void dma_free(void *cpu_addr, dma_addr_t handle) | 
 | 102 | { | 
 | 103 | 	dma_free_coherent(NULL, SPI_DMA_BUF_LEN, cpu_addr, handle); | 
 | 104 | } | 
 | 105 | #endif	/* CONFIG_UML */ | 
 | 106 |  | 
 | 107 | #ifdef CONFIG_DEBUG_FS | 
 | 108 |  | 
 | 109 | #define DEBUGFS_BUF_SIZE	4096 | 
 | 110 |  | 
 | 111 | static struct dentry *dbgfs_root; | 
 | 112 |  | 
 | 113 | static inline void driver_debugfs_create(void) | 
 | 114 | { | 
 | 115 | 	dbgfs_root = debugfs_create_dir(cfspi_spi_driver.driver.name, NULL); | 
 | 116 | } | 
 | 117 |  | 
 | 118 | static inline void driver_debugfs_remove(void) | 
 | 119 | { | 
 | 120 | 	debugfs_remove(dbgfs_root); | 
 | 121 | } | 
 | 122 |  | 
 | 123 | static inline void dev_debugfs_rem(struct cfspi *cfspi) | 
 | 124 | { | 
 | 125 | 	debugfs_remove(cfspi->dbgfs_frame); | 
 | 126 | 	debugfs_remove(cfspi->dbgfs_state); | 
 | 127 | 	debugfs_remove(cfspi->dbgfs_dir); | 
 | 128 | } | 
 | 129 |  | 
 | 130 | static int dbgfs_open(struct inode *inode, struct file *file) | 
 | 131 | { | 
 | 132 | 	file->private_data = inode->i_private; | 
 | 133 | 	return 0; | 
 | 134 | } | 
 | 135 |  | 
 | 136 | static ssize_t dbgfs_state(struct file *file, char __user *user_buf, | 
 | 137 | 			   size_t count, loff_t *ppos) | 
 | 138 | { | 
 | 139 | 	char *buf; | 
 | 140 | 	int len = 0; | 
 | 141 | 	ssize_t size; | 
| Joe Perches | cb8b6a9 | 2010-07-12 10:50:05 +0000 | [diff] [blame] | 142 | 	struct cfspi *cfspi = file->private_data; | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 143 |  | 
 | 144 | 	buf = kzalloc(DEBUGFS_BUF_SIZE, GFP_KERNEL); | 
 | 145 | 	if (!buf) | 
 | 146 | 		return 0; | 
 | 147 |  | 
 | 148 | 	/* Print out debug information. */ | 
 | 149 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 150 | 			"CAIF SPI debug information:\n"); | 
 | 151 |  | 
 | 152 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), FLAVOR); | 
 | 153 |  | 
 | 154 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 155 | 			"STATE: %d\n", cfspi->dbg_state); | 
 | 156 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 157 | 			"Previous CMD: 0x%x\n", cfspi->pcmd); | 
 | 158 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 159 | 			"Current CMD: 0x%x\n", cfspi->cmd); | 
 | 160 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 161 | 			"Previous TX len: %d\n", cfspi->tx_ppck_len); | 
 | 162 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 163 | 			"Previous RX len: %d\n", cfspi->rx_ppck_len); | 
 | 164 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 165 | 			"Current TX len: %d\n", cfspi->tx_cpck_len); | 
 | 166 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 167 | 			"Current RX len: %d\n", cfspi->rx_cpck_len); | 
 | 168 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 169 | 			"Next TX len: %d\n", cfspi->tx_npck_len); | 
 | 170 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 171 | 			"Next RX len: %d\n", cfspi->rx_npck_len); | 
 | 172 |  | 
| Dan Carpenter | 7b7b0b9 | 2010-07-25 21:23:59 +0000 | [diff] [blame] | 173 | 	if (len > DEBUGFS_BUF_SIZE) | 
 | 174 | 		len = DEBUGFS_BUF_SIZE; | 
 | 175 |  | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 176 | 	size = simple_read_from_buffer(user_buf, count, ppos, buf, len); | 
 | 177 | 	kfree(buf); | 
 | 178 |  | 
 | 179 | 	return size; | 
 | 180 | } | 
 | 181 |  | 
 | 182 | static ssize_t print_frame(char *buf, size_t size, char *frm, | 
 | 183 | 			   size_t count, size_t cut) | 
 | 184 | { | 
 | 185 | 	int len = 0; | 
 | 186 | 	int i; | 
 | 187 | 	for (i = 0; i < count; i++) { | 
 | 188 | 		len += snprintf((buf + len), (size - len), | 
 | 189 | 					"[0x" BYTE_HEX_FMT "]", | 
 | 190 | 					frm[i]); | 
 | 191 | 		if ((i == cut) && (count > (cut * 2))) { | 
 | 192 | 			/* Fast forward. */ | 
 | 193 | 			i = count - cut; | 
 | 194 | 			len += snprintf((buf + len), (size - len), | 
 | 195 | 					"--- %u bytes skipped ---\n", | 
 | 196 | 					(int)(count - (cut * 2))); | 
 | 197 | 		} | 
 | 198 |  | 
 | 199 | 		if ((!(i % 10)) && i) { | 
 | 200 | 			len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 201 | 					"\n"); | 
 | 202 | 		} | 
 | 203 | 	} | 
 | 204 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), "\n"); | 
 | 205 | 	return len; | 
 | 206 | } | 
 | 207 |  | 
 | 208 | static ssize_t dbgfs_frame(struct file *file, char __user *user_buf, | 
 | 209 | 			   size_t count, loff_t *ppos) | 
 | 210 | { | 
 | 211 | 	char *buf; | 
 | 212 | 	int len = 0; | 
 | 213 | 	ssize_t size; | 
 | 214 | 	struct cfspi *cfspi; | 
 | 215 |  | 
| Joe Perches | cb8b6a9 | 2010-07-12 10:50:05 +0000 | [diff] [blame] | 216 | 	cfspi = file->private_data; | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 217 | 	buf = kzalloc(DEBUGFS_BUF_SIZE, GFP_KERNEL); | 
 | 218 | 	if (!buf) | 
 | 219 | 		return 0; | 
 | 220 |  | 
 | 221 | 	/* Print out debug information. */ | 
 | 222 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 223 | 			"Current frame:\n"); | 
 | 224 |  | 
 | 225 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 226 | 			"Tx data (Len: %d):\n", cfspi->tx_cpck_len); | 
 | 227 |  | 
 | 228 | 	len += print_frame((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 229 | 			   cfspi->xfer.va_tx, | 
 | 230 | 			   (cfspi->tx_cpck_len + SPI_CMD_SZ), 100); | 
 | 231 |  | 
 | 232 | 	len += snprintf((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 233 | 			"Rx data (Len: %d):\n", cfspi->rx_cpck_len); | 
 | 234 |  | 
 | 235 | 	len += print_frame((buf + len), (DEBUGFS_BUF_SIZE - len), | 
 | 236 | 			   cfspi->xfer.va_rx, | 
 | 237 | 			   (cfspi->rx_cpck_len + SPI_CMD_SZ), 100); | 
 | 238 |  | 
 | 239 | 	size = simple_read_from_buffer(user_buf, count, ppos, buf, len); | 
 | 240 | 	kfree(buf); | 
 | 241 |  | 
 | 242 | 	return size; | 
 | 243 | } | 
 | 244 |  | 
 | 245 | static const struct file_operations dbgfs_state_fops = { | 
 | 246 | 	.open = dbgfs_open, | 
 | 247 | 	.read = dbgfs_state, | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 248 | 	.owner = THIS_MODULE | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 249 | }; | 
 | 250 |  | 
 | 251 | static const struct file_operations dbgfs_frame_fops = { | 
 | 252 | 	.open = dbgfs_open, | 
 | 253 | 	.read = dbgfs_frame, | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 254 | 	.owner = THIS_MODULE | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 255 | }; | 
 | 256 |  | 
 | 257 | static inline void dev_debugfs_add(struct cfspi *cfspi) | 
 | 258 | { | 
 | 259 | 	cfspi->dbgfs_dir = debugfs_create_dir(cfspi->pdev->name, dbgfs_root); | 
 | 260 | 	cfspi->dbgfs_state = debugfs_create_file("state", S_IRUGO, | 
 | 261 | 						 cfspi->dbgfs_dir, cfspi, | 
 | 262 | 						 &dbgfs_state_fops); | 
 | 263 | 	cfspi->dbgfs_frame = debugfs_create_file("frame", S_IRUGO, | 
 | 264 | 						 cfspi->dbgfs_dir, cfspi, | 
 | 265 | 						 &dbgfs_frame_fops); | 
 | 266 | } | 
 | 267 |  | 
 | 268 | inline void cfspi_dbg_state(struct cfspi *cfspi, int state) | 
 | 269 | { | 
 | 270 | 	cfspi->dbg_state = state; | 
 | 271 | }; | 
 | 272 | #else | 
 | 273 |  | 
 | 274 | static inline void driver_debugfs_create(void) | 
 | 275 | { | 
 | 276 | } | 
 | 277 |  | 
 | 278 | static inline void driver_debugfs_remove(void) | 
 | 279 | { | 
 | 280 | } | 
 | 281 |  | 
 | 282 | static inline void dev_debugfs_add(struct cfspi *cfspi) | 
 | 283 | { | 
 | 284 | } | 
 | 285 |  | 
 | 286 | static inline void dev_debugfs_rem(struct cfspi *cfspi) | 
 | 287 | { | 
 | 288 | } | 
 | 289 |  | 
 | 290 | inline void cfspi_dbg_state(struct cfspi *cfspi, int state) | 
 | 291 | { | 
 | 292 | } | 
 | 293 | #endif				/* CONFIG_DEBUG_FS */ | 
 | 294 |  | 
 | 295 | static LIST_HEAD(cfspi_list); | 
 | 296 | static spinlock_t cfspi_list_lock; | 
 | 297 |  | 
 | 298 | /* SPI uplink head alignment. */ | 
 | 299 | static ssize_t show_up_head_align(struct device_driver *driver, char *buf) | 
 | 300 | { | 
 | 301 | 	return sprintf(buf, "%d\n", spi_up_head_align); | 
 | 302 | } | 
 | 303 |  | 
 | 304 | static DRIVER_ATTR(up_head_align, S_IRUSR, show_up_head_align, NULL); | 
 | 305 |  | 
 | 306 | /* SPI uplink tail alignment. */ | 
 | 307 | static ssize_t show_up_tail_align(struct device_driver *driver, char *buf) | 
 | 308 | { | 
 | 309 | 	return sprintf(buf, "%d\n", spi_up_tail_align); | 
 | 310 | } | 
 | 311 |  | 
 | 312 | static DRIVER_ATTR(up_tail_align, S_IRUSR, show_up_tail_align, NULL); | 
 | 313 |  | 
 | 314 | /* SPI downlink head alignment. */ | 
 | 315 | static ssize_t show_down_head_align(struct device_driver *driver, char *buf) | 
 | 316 | { | 
 | 317 | 	return sprintf(buf, "%d\n", spi_down_head_align); | 
 | 318 | } | 
 | 319 |  | 
 | 320 | static DRIVER_ATTR(down_head_align, S_IRUSR, show_down_head_align, NULL); | 
 | 321 |  | 
 | 322 | /* SPI downlink tail alignment. */ | 
 | 323 | static ssize_t show_down_tail_align(struct device_driver *driver, char *buf) | 
 | 324 | { | 
 | 325 | 	return sprintf(buf, "%d\n", spi_down_tail_align); | 
 | 326 | } | 
 | 327 |  | 
 | 328 | static DRIVER_ATTR(down_tail_align, S_IRUSR, show_down_tail_align, NULL); | 
 | 329 |  | 
 | 330 | /* SPI frame alignment. */ | 
 | 331 | static ssize_t show_frame_align(struct device_driver *driver, char *buf) | 
 | 332 | { | 
 | 333 | 	return sprintf(buf, "%d\n", spi_frm_align); | 
 | 334 | } | 
 | 335 |  | 
 | 336 | static DRIVER_ATTR(frame_align, S_IRUSR, show_frame_align, NULL); | 
 | 337 |  | 
 | 338 | int cfspi_xmitfrm(struct cfspi *cfspi, u8 *buf, size_t len) | 
 | 339 | { | 
 | 340 | 	u8 *dst = buf; | 
 | 341 | 	caif_assert(buf); | 
 | 342 |  | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 343 | 	if (cfspi->slave && !cfspi->slave_talked) | 
 | 344 | 		cfspi->slave_talked = true; | 
 | 345 |  | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 346 | 	do { | 
 | 347 | 		struct sk_buff *skb; | 
 | 348 | 		struct caif_payload_info *info; | 
 | 349 | 		int spad = 0; | 
 | 350 | 		int epad; | 
 | 351 |  | 
 | 352 | 		skb = skb_dequeue(&cfspi->chead); | 
 | 353 | 		if (!skb) | 
 | 354 | 			break; | 
 | 355 |  | 
 | 356 | 		/* | 
 | 357 | 		 * Calculate length of frame including SPI padding. | 
 | 358 | 		 * The payload position is found in the control buffer. | 
 | 359 | 		 */ | 
 | 360 | 		info = (struct caif_payload_info *)&skb->cb; | 
 | 361 |  | 
 | 362 | 		/* | 
 | 363 | 		 * Compute head offset i.e. number of bytes to add to | 
 | 364 | 		 * get the start of the payload aligned. | 
 | 365 | 		 */ | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 366 | 		if (spi_up_head_align > 1) { | 
 | 367 | 			spad = 1 + PAD_POW2((info->hdr_len + 1), spi_up_head_align); | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 368 | 			*dst = (u8)(spad - 1); | 
 | 369 | 			dst += spad; | 
 | 370 | 		} | 
 | 371 |  | 
 | 372 | 		/* Copy in CAIF frame. */ | 
 | 373 | 		skb_copy_bits(skb, 0, dst, skb->len); | 
 | 374 | 		dst += skb->len; | 
 | 375 | 		cfspi->ndev->stats.tx_packets++; | 
 | 376 | 		cfspi->ndev->stats.tx_bytes += skb->len; | 
 | 377 |  | 
 | 378 | 		/* | 
 | 379 | 		 * Compute tail offset i.e. number of bytes to add to | 
 | 380 | 		 * get the complete CAIF frame aligned. | 
 | 381 | 		 */ | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 382 | 		epad = PAD_POW2((skb->len + spad), spi_up_tail_align); | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 383 | 		dst += epad; | 
 | 384 |  | 
 | 385 | 		dev_kfree_skb(skb); | 
 | 386 |  | 
 | 387 | 	} while ((dst - buf) < len); | 
 | 388 |  | 
 | 389 | 	return dst - buf; | 
 | 390 | } | 
 | 391 |  | 
 | 392 | int cfspi_xmitlen(struct cfspi *cfspi) | 
 | 393 | { | 
 | 394 | 	struct sk_buff *skb = NULL; | 
 | 395 | 	int frm_len = 0; | 
 | 396 | 	int pkts = 0; | 
 | 397 |  | 
 | 398 | 	/* | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 399 | 	 * Decommit previously committed frames. | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 400 | 	 * skb_queue_splice_tail(&cfspi->chead,&cfspi->qhead) | 
 | 401 | 	 */ | 
 | 402 | 	while (skb_peek(&cfspi->chead)) { | 
 | 403 | 		skb = skb_dequeue_tail(&cfspi->chead); | 
 | 404 | 		skb_queue_head(&cfspi->qhead, skb); | 
 | 405 | 	} | 
 | 406 |  | 
 | 407 | 	do { | 
 | 408 | 		struct caif_payload_info *info = NULL; | 
 | 409 | 		int spad = 0; | 
 | 410 | 		int epad = 0; | 
 | 411 |  | 
 | 412 | 		skb = skb_dequeue(&cfspi->qhead); | 
 | 413 | 		if (!skb) | 
 | 414 | 			break; | 
 | 415 |  | 
 | 416 | 		/* | 
 | 417 | 		 * Calculate length of frame including SPI padding. | 
 | 418 | 		 * The payload position is found in the control buffer. | 
 | 419 | 		 */ | 
 | 420 | 		info = (struct caif_payload_info *)&skb->cb; | 
 | 421 |  | 
 | 422 | 		/* | 
 | 423 | 		 * Compute head offset i.e. number of bytes to add to | 
 | 424 | 		 * get the start of the payload aligned. | 
 | 425 | 		 */ | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 426 | 		if (spi_up_head_align > 1) | 
 | 427 | 			spad = 1 + PAD_POW2((info->hdr_len + 1), spi_up_head_align); | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 428 |  | 
 | 429 | 		/* | 
 | 430 | 		 * Compute tail offset i.e. number of bytes to add to | 
 | 431 | 		 * get the complete CAIF frame aligned. | 
 | 432 | 		 */ | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 433 | 		epad = PAD_POW2((skb->len + spad), spi_up_tail_align); | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 434 |  | 
 | 435 | 		if ((skb->len + spad + epad + frm_len) <= CAIF_MAX_SPI_FRAME) { | 
 | 436 | 			skb_queue_tail(&cfspi->chead, skb); | 
 | 437 | 			pkts++; | 
 | 438 | 			frm_len += skb->len + spad + epad; | 
 | 439 | 		} else { | 
 | 440 | 			/* Put back packet. */ | 
 | 441 | 			skb_queue_head(&cfspi->qhead, skb); | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 442 | 			break; | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 443 | 		} | 
 | 444 | 	} while (pkts <= CAIF_MAX_SPI_PKTS); | 
 | 445 |  | 
 | 446 | 	/* | 
 | 447 | 	 * Send flow on if previously sent flow off | 
 | 448 | 	 * and now go below the low water mark | 
 | 449 | 	 */ | 
 | 450 | 	if (cfspi->flow_off_sent && cfspi->qhead.qlen < cfspi->qd_low_mark && | 
 | 451 | 		cfspi->cfdev.flowctrl) { | 
 | 452 | 		cfspi->flow_off_sent = 0; | 
 | 453 | 		cfspi->cfdev.flowctrl(cfspi->ndev, 1); | 
 | 454 | 	} | 
 | 455 |  | 
 | 456 | 	return frm_len; | 
 | 457 | } | 
 | 458 |  | 
 | 459 | static void cfspi_ss_cb(bool assert, struct cfspi_ifc *ifc) | 
 | 460 | { | 
 | 461 | 	struct cfspi *cfspi = (struct cfspi *)ifc->priv; | 
 | 462 |  | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 463 | 	/* | 
 | 464 | 	 * The slave device is the master on the link. Interrupts before the | 
 | 465 | 	 * slave has transmitted are considered spurious. | 
 | 466 | 	 */ | 
 | 467 | 	if (cfspi->slave && !cfspi->slave_talked) { | 
 | 468 | 		printk(KERN_WARNING "CFSPI: Spurious SS interrupt.\n"); | 
 | 469 | 		return; | 
 | 470 | 	} | 
 | 471 |  | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 472 | 	if (!in_interrupt()) | 
 | 473 | 		spin_lock(&cfspi->lock); | 
 | 474 | 	if (assert) { | 
 | 475 | 		set_bit(SPI_SS_ON, &cfspi->state); | 
 | 476 | 		set_bit(SPI_XFER, &cfspi->state); | 
 | 477 | 	} else { | 
 | 478 | 		set_bit(SPI_SS_OFF, &cfspi->state); | 
 | 479 | 	} | 
 | 480 | 	if (!in_interrupt()) | 
 | 481 | 		spin_unlock(&cfspi->lock); | 
 | 482 |  | 
 | 483 | 	/* Wake up the xfer thread. */ | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 484 | 	if (assert) | 
 | 485 | 		wake_up_interruptible(&cfspi->wait); | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 486 | } | 
 | 487 |  | 
 | 488 | static void cfspi_xfer_done_cb(struct cfspi_ifc *ifc) | 
 | 489 | { | 
 | 490 | 	struct cfspi *cfspi = (struct cfspi *)ifc->priv; | 
 | 491 |  | 
 | 492 | 	/* Transfer done, complete work queue */ | 
 | 493 | 	complete(&cfspi->comp); | 
 | 494 | } | 
 | 495 |  | 
 | 496 | static int cfspi_xmit(struct sk_buff *skb, struct net_device *dev) | 
 | 497 | { | 
 | 498 | 	struct cfspi *cfspi = NULL; | 
 | 499 | 	unsigned long flags; | 
 | 500 | 	if (!dev) | 
 | 501 | 		return -EINVAL; | 
 | 502 |  | 
 | 503 | 	cfspi = netdev_priv(dev); | 
 | 504 |  | 
 | 505 | 	skb_queue_tail(&cfspi->qhead, skb); | 
 | 506 |  | 
 | 507 | 	spin_lock_irqsave(&cfspi->lock, flags); | 
 | 508 | 	if (!test_and_set_bit(SPI_XFER, &cfspi->state)) { | 
 | 509 | 		/* Wake up xfer thread. */ | 
 | 510 | 		wake_up_interruptible(&cfspi->wait); | 
 | 511 | 	} | 
 | 512 | 	spin_unlock_irqrestore(&cfspi->lock, flags); | 
 | 513 |  | 
 | 514 | 	/* Send flow off if number of bytes is above high water mark */ | 
 | 515 | 	if (!cfspi->flow_off_sent && | 
 | 516 | 		cfspi->qhead.qlen > cfspi->qd_high_mark && | 
 | 517 | 		cfspi->cfdev.flowctrl) { | 
 | 518 | 		cfspi->flow_off_sent = 1; | 
 | 519 | 		cfspi->cfdev.flowctrl(cfspi->ndev, 0); | 
 | 520 | 	} | 
 | 521 |  | 
 | 522 | 	return 0; | 
 | 523 | } | 
 | 524 |  | 
 | 525 | int cfspi_rxfrm(struct cfspi *cfspi, u8 *buf, size_t len) | 
 | 526 | { | 
 | 527 | 	u8 *src = buf; | 
 | 528 |  | 
 | 529 | 	caif_assert(buf != NULL); | 
 | 530 |  | 
 | 531 | 	do { | 
 | 532 | 		int res; | 
 | 533 | 		struct sk_buff *skb = NULL; | 
 | 534 | 		int spad = 0; | 
 | 535 | 		int epad = 0; | 
 | 536 | 		u8 *dst = NULL; | 
 | 537 | 		int pkt_len = 0; | 
 | 538 |  | 
 | 539 | 		/* | 
 | 540 | 		 * Compute head offset i.e. number of bytes added to | 
 | 541 | 		 * get the start of the payload aligned. | 
 | 542 | 		 */ | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 543 | 		if (spi_down_head_align > 1) { | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 544 | 			spad = 1 + *src; | 
 | 545 | 			src += spad; | 
 | 546 | 		} | 
 | 547 |  | 
 | 548 | 		/* Read length of CAIF frame (little endian). */ | 
 | 549 | 		pkt_len = *src; | 
 | 550 | 		pkt_len |= ((*(src+1)) << 8) & 0xFF00; | 
 | 551 | 		pkt_len += 2;	/* Add FCS fields. */ | 
 | 552 |  | 
 | 553 | 		/* Get a suitable caif packet and copy in data. */ | 
 | 554 |  | 
 | 555 | 		skb = netdev_alloc_skb(cfspi->ndev, pkt_len + 1); | 
 | 556 | 		caif_assert(skb != NULL); | 
 | 557 |  | 
 | 558 | 		dst = skb_put(skb, pkt_len); | 
 | 559 | 		memcpy(dst, src, pkt_len); | 
 | 560 | 		src += pkt_len; | 
 | 561 |  | 
 | 562 | 		skb->protocol = htons(ETH_P_CAIF); | 
 | 563 | 		skb_reset_mac_header(skb); | 
 | 564 | 		skb->dev = cfspi->ndev; | 
 | 565 |  | 
 | 566 | 		/* | 
 | 567 | 		 * Push received packet up the stack. | 
 | 568 | 		 */ | 
 | 569 | 		if (!spi_loop) | 
 | 570 | 			res = netif_rx_ni(skb); | 
 | 571 | 		else | 
 | 572 | 			res = cfspi_xmit(skb, cfspi->ndev); | 
 | 573 |  | 
 | 574 | 		if (!res) { | 
 | 575 | 			cfspi->ndev->stats.rx_packets++; | 
 | 576 | 			cfspi->ndev->stats.rx_bytes += pkt_len; | 
 | 577 | 		} else | 
 | 578 | 			cfspi->ndev->stats.rx_dropped++; | 
 | 579 |  | 
 | 580 | 		/* | 
 | 581 | 		 * Compute tail offset i.e. number of bytes added to | 
 | 582 | 		 * get the complete CAIF frame aligned. | 
 | 583 | 		 */ | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 584 | 		epad = PAD_POW2((pkt_len + spad), spi_down_tail_align); | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 585 | 		src += epad; | 
 | 586 | 	} while ((src - buf) < len); | 
 | 587 |  | 
 | 588 | 	return src - buf; | 
 | 589 | } | 
 | 590 |  | 
 | 591 | static int cfspi_open(struct net_device *dev) | 
 | 592 | { | 
 | 593 | 	netif_wake_queue(dev); | 
 | 594 | 	return 0; | 
 | 595 | } | 
 | 596 |  | 
 | 597 | static int cfspi_close(struct net_device *dev) | 
 | 598 | { | 
 | 599 | 	netif_stop_queue(dev); | 
 | 600 | 	return 0; | 
 | 601 | } | 
 | 602 | static const struct net_device_ops cfspi_ops = { | 
 | 603 | 	.ndo_open = cfspi_open, | 
 | 604 | 	.ndo_stop = cfspi_close, | 
 | 605 | 	.ndo_start_xmit = cfspi_xmit | 
 | 606 | }; | 
 | 607 |  | 
 | 608 | static void cfspi_setup(struct net_device *dev) | 
 | 609 | { | 
 | 610 | 	struct cfspi *cfspi = netdev_priv(dev); | 
 | 611 | 	dev->features = 0; | 
 | 612 | 	dev->netdev_ops = &cfspi_ops; | 
 | 613 | 	dev->type = ARPHRD_CAIF; | 
 | 614 | 	dev->flags = IFF_NOARP | IFF_POINTOPOINT; | 
 | 615 | 	dev->tx_queue_len = 0; | 
 | 616 | 	dev->mtu = SPI_MAX_PAYLOAD_SIZE; | 
 | 617 | 	dev->destructor = free_netdev; | 
 | 618 | 	skb_queue_head_init(&cfspi->qhead); | 
 | 619 | 	skb_queue_head_init(&cfspi->chead); | 
 | 620 | 	cfspi->cfdev.link_select = CAIF_LINK_HIGH_BANDW; | 
 | 621 | 	cfspi->cfdev.use_frag = false; | 
 | 622 | 	cfspi->cfdev.use_stx = false; | 
 | 623 | 	cfspi->cfdev.use_fcs = false; | 
 | 624 | 	cfspi->ndev = dev; | 
 | 625 | } | 
 | 626 |  | 
 | 627 | int cfspi_spi_probe(struct platform_device *pdev) | 
 | 628 | { | 
 | 629 | 	struct cfspi *cfspi = NULL; | 
 | 630 | 	struct net_device *ndev; | 
 | 631 | 	struct cfspi_dev *dev; | 
 | 632 | 	int res; | 
 | 633 | 	dev = (struct cfspi_dev *)pdev->dev.platform_data; | 
 | 634 |  | 
 | 635 | 	ndev = alloc_netdev(sizeof(struct cfspi), | 
 | 636 | 			"cfspi%d", cfspi_setup); | 
| Vasiliy Kulikov | 8ea9122 | 2010-11-18 10:35:58 -0800 | [diff] [blame] | 637 | 	if (!ndev) | 
 | 638 | 		return -ENOMEM; | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 639 |  | 
 | 640 | 	cfspi = netdev_priv(ndev); | 
 | 641 | 	netif_stop_queue(ndev); | 
 | 642 | 	cfspi->ndev = ndev; | 
 | 643 | 	cfspi->pdev = pdev; | 
 | 644 |  | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 645 | 	/* Set flow info. */ | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 646 | 	cfspi->flow_off_sent = 0; | 
 | 647 | 	cfspi->qd_low_mark = LOW_WATER_MARK; | 
 | 648 | 	cfspi->qd_high_mark = HIGH_WATER_MARK; | 
 | 649 |  | 
| Sjur Brændeland | 2c24a5d | 2010-11-01 11:52:48 +0000 | [diff] [blame] | 650 | 	/* Set slave info. */ | 
 | 651 | 	if (!strncmp(cfspi_spi_driver.driver.name, "cfspi_sspi", 10)) { | 
 | 652 | 		cfspi->slave = true; | 
 | 653 | 		cfspi->slave_talked = false; | 
 | 654 | 	} else { | 
 | 655 | 		cfspi->slave = false; | 
 | 656 | 		cfspi->slave_talked = false; | 
 | 657 | 	} | 
 | 658 |  | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 659 | 	/* Assign the SPI device. */ | 
 | 660 | 	cfspi->dev = dev; | 
 | 661 | 	/* Assign the device ifc to this SPI interface. */ | 
 | 662 | 	dev->ifc = &cfspi->ifc; | 
 | 663 |  | 
 | 664 | 	/* Allocate DMA buffers. */ | 
 | 665 | 	cfspi->xfer.va_tx = dma_alloc(&cfspi->xfer.pa_tx); | 
 | 666 | 	if (!cfspi->xfer.va_tx) { | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 667 | 		res = -ENODEV; | 
 | 668 | 		goto err_dma_alloc_tx; | 
 | 669 | 	} | 
 | 670 |  | 
 | 671 | 	cfspi->xfer.va_rx = dma_alloc(&cfspi->xfer.pa_rx); | 
 | 672 |  | 
 | 673 | 	if (!cfspi->xfer.va_rx) { | 
| Sjur Braendeland | 529d6da | 2010-06-29 00:08:21 -0700 | [diff] [blame] | 674 | 		res = -ENODEV; | 
 | 675 | 		goto err_dma_alloc_rx; | 
 | 676 | 	} | 
 | 677 |  | 
 | 678 | 	/* Initialize the work queue. */ | 
 | 679 | 	INIT_WORK(&cfspi->work, cfspi_xfer); | 
 | 680 |  | 
 | 681 | 	/* Initialize spin locks. */ | 
 | 682 | 	spin_lock_init(&cfspi->lock); | 
 | 683 |  | 
 | 684 | 	/* Initialize flow control state. */ | 
 | 685 | 	cfspi->flow_stop = false; | 
 | 686 |  | 
 | 687 | 	/* Initialize wait queue. */ | 
 | 688 | 	init_waitqueue_head(&cfspi->wait); | 
 | 689 |  | 
 | 690 | 	/* Create work thread. */ | 
 | 691 | 	cfspi->wq = create_singlethread_workqueue(dev->name); | 
 | 692 | 	if (!cfspi->wq) { | 
 | 693 | 		printk(KERN_WARNING "CFSPI: failed to create work queue.\n"); | 
 | 694 | 		res = -ENODEV; | 
 | 695 | 		goto err_create_wq; | 
 | 696 | 	} | 
 | 697 |  | 
 | 698 | 	/* Initialize work queue. */ | 
 | 699 | 	init_completion(&cfspi->comp); | 
 | 700 |  | 
 | 701 | 	/* Create debugfs entries. */ | 
 | 702 | 	dev_debugfs_add(cfspi); | 
 | 703 |  | 
 | 704 | 	/* Set up the ifc. */ | 
 | 705 | 	cfspi->ifc.ss_cb = cfspi_ss_cb; | 
 | 706 | 	cfspi->ifc.xfer_done_cb = cfspi_xfer_done_cb; | 
 | 707 | 	cfspi->ifc.priv = cfspi; | 
 | 708 |  | 
 | 709 | 	/* Add CAIF SPI device to list. */ | 
 | 710 | 	spin_lock(&cfspi_list_lock); | 
 | 711 | 	list_add_tail(&cfspi->list, &cfspi_list); | 
 | 712 | 	spin_unlock(&cfspi_list_lock); | 
 | 713 |  | 
 | 714 | 	/* Schedule the work queue. */ | 
 | 715 | 	queue_work(cfspi->wq, &cfspi->work); | 
 | 716 |  | 
 | 717 | 	/* Register network device. */ | 
 | 718 | 	res = register_netdev(ndev); | 
 | 719 | 	if (res) { | 
 | 720 | 		printk(KERN_ERR "CFSPI: Reg. error: %d.\n", res); | 
 | 721 | 		goto err_net_reg; | 
 | 722 | 	} | 
 | 723 | 	return res; | 
 | 724 |  | 
 | 725 |  err_net_reg: | 
 | 726 | 	dev_debugfs_rem(cfspi); | 
 | 727 | 	set_bit(SPI_TERMINATE, &cfspi->state); | 
 | 728 | 	wake_up_interruptible(&cfspi->wait); | 
 | 729 | 	destroy_workqueue(cfspi->wq); | 
 | 730 |  err_create_wq: | 
 | 731 | 	dma_free(cfspi->xfer.va_rx, cfspi->xfer.pa_rx); | 
 | 732 |  err_dma_alloc_rx: | 
 | 733 | 	dma_free(cfspi->xfer.va_tx, cfspi->xfer.pa_tx); | 
 | 734 |  err_dma_alloc_tx: | 
 | 735 | 	free_netdev(ndev); | 
 | 736 |  | 
 | 737 | 	return res; | 
 | 738 | } | 
 | 739 |  | 
 | 740 | int cfspi_spi_remove(struct platform_device *pdev) | 
 | 741 | { | 
 | 742 | 	struct list_head *list_node; | 
 | 743 | 	struct list_head *n; | 
 | 744 | 	struct cfspi *cfspi = NULL; | 
 | 745 | 	struct cfspi_dev *dev; | 
 | 746 |  | 
 | 747 | 	dev = (struct cfspi_dev *)pdev->dev.platform_data; | 
 | 748 | 	spin_lock(&cfspi_list_lock); | 
 | 749 | 	list_for_each_safe(list_node, n, &cfspi_list) { | 
 | 750 | 		cfspi = list_entry(list_node, struct cfspi, list); | 
 | 751 | 		/* Find the corresponding device. */ | 
 | 752 | 		if (cfspi->dev == dev) { | 
 | 753 | 			/* Remove from list. */ | 
 | 754 | 			list_del(list_node); | 
 | 755 | 			/* Free DMA buffers. */ | 
 | 756 | 			dma_free(cfspi->xfer.va_rx, cfspi->xfer.pa_rx); | 
 | 757 | 			dma_free(cfspi->xfer.va_tx, cfspi->xfer.pa_tx); | 
 | 758 | 			set_bit(SPI_TERMINATE, &cfspi->state); | 
 | 759 | 			wake_up_interruptible(&cfspi->wait); | 
 | 760 | 			destroy_workqueue(cfspi->wq); | 
 | 761 | 			/* Destroy debugfs directory and files. */ | 
 | 762 | 			dev_debugfs_rem(cfspi); | 
 | 763 | 			unregister_netdev(cfspi->ndev); | 
 | 764 | 			spin_unlock(&cfspi_list_lock); | 
 | 765 | 			return 0; | 
 | 766 | 		} | 
 | 767 | 	} | 
 | 768 | 	spin_unlock(&cfspi_list_lock); | 
 | 769 | 	return -ENODEV; | 
 | 770 | } | 
 | 771 |  | 
 | 772 | static void __exit cfspi_exit_module(void) | 
 | 773 | { | 
 | 774 | 	struct list_head *list_node; | 
 | 775 | 	struct list_head *n; | 
 | 776 | 	struct cfspi *cfspi = NULL; | 
 | 777 |  | 
 | 778 | 	list_for_each_safe(list_node, n, &cfspi_list) { | 
 | 779 | 		cfspi = list_entry(list_node, struct cfspi, list); | 
 | 780 | 		platform_device_unregister(cfspi->pdev); | 
 | 781 | 	} | 
 | 782 |  | 
 | 783 | 	/* Destroy sysfs files. */ | 
 | 784 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 785 | 			   &driver_attr_up_head_align); | 
 | 786 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 787 | 			   &driver_attr_up_tail_align); | 
 | 788 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 789 | 			   &driver_attr_down_head_align); | 
 | 790 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 791 | 			   &driver_attr_down_tail_align); | 
 | 792 | 	driver_remove_file(&cfspi_spi_driver.driver, &driver_attr_frame_align); | 
 | 793 | 	/* Unregister platform driver. */ | 
 | 794 | 	platform_driver_unregister(&cfspi_spi_driver); | 
 | 795 | 	/* Destroy debugfs root directory. */ | 
 | 796 | 	driver_debugfs_remove(); | 
 | 797 | } | 
 | 798 |  | 
 | 799 | static int __init cfspi_init_module(void) | 
 | 800 | { | 
 | 801 | 	int result; | 
 | 802 |  | 
 | 803 | 	/* Initialize spin lock. */ | 
 | 804 | 	spin_lock_init(&cfspi_list_lock); | 
 | 805 |  | 
 | 806 | 	/* Register platform driver. */ | 
 | 807 | 	result = platform_driver_register(&cfspi_spi_driver); | 
 | 808 | 	if (result) { | 
 | 809 | 		printk(KERN_ERR "Could not register platform SPI driver.\n"); | 
 | 810 | 		goto err_dev_register; | 
 | 811 | 	} | 
 | 812 |  | 
 | 813 | 	/* Create sysfs files. */ | 
 | 814 | 	result = | 
 | 815 | 	    driver_create_file(&cfspi_spi_driver.driver, | 
 | 816 | 			       &driver_attr_up_head_align); | 
 | 817 | 	if (result) { | 
 | 818 | 		printk(KERN_ERR "Sysfs creation failed 1.\n"); | 
 | 819 | 		goto err_create_up_head_align; | 
 | 820 | 	} | 
 | 821 |  | 
 | 822 | 	result = | 
 | 823 | 	    driver_create_file(&cfspi_spi_driver.driver, | 
 | 824 | 			       &driver_attr_up_tail_align); | 
 | 825 | 	if (result) { | 
 | 826 | 		printk(KERN_ERR "Sysfs creation failed 2.\n"); | 
 | 827 | 		goto err_create_up_tail_align; | 
 | 828 | 	} | 
 | 829 |  | 
 | 830 | 	result = | 
 | 831 | 	    driver_create_file(&cfspi_spi_driver.driver, | 
 | 832 | 			       &driver_attr_down_head_align); | 
 | 833 | 	if (result) { | 
 | 834 | 		printk(KERN_ERR "Sysfs creation failed 3.\n"); | 
 | 835 | 		goto err_create_down_head_align; | 
 | 836 | 	} | 
 | 837 |  | 
 | 838 | 	result = | 
 | 839 | 	    driver_create_file(&cfspi_spi_driver.driver, | 
 | 840 | 			       &driver_attr_down_tail_align); | 
 | 841 | 	if (result) { | 
 | 842 | 		printk(KERN_ERR "Sysfs creation failed 4.\n"); | 
 | 843 | 		goto err_create_down_tail_align; | 
 | 844 | 	} | 
 | 845 |  | 
 | 846 | 	result = | 
 | 847 | 	    driver_create_file(&cfspi_spi_driver.driver, | 
 | 848 | 			       &driver_attr_frame_align); | 
 | 849 | 	if (result) { | 
 | 850 | 		printk(KERN_ERR "Sysfs creation failed 5.\n"); | 
 | 851 | 		goto err_create_frame_align; | 
 | 852 | 	} | 
 | 853 | 	driver_debugfs_create(); | 
 | 854 | 	return result; | 
 | 855 |  | 
 | 856 |  err_create_frame_align: | 
 | 857 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 858 | 			   &driver_attr_down_tail_align); | 
 | 859 |  err_create_down_tail_align: | 
 | 860 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 861 | 			   &driver_attr_down_head_align); | 
 | 862 |  err_create_down_head_align: | 
 | 863 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 864 | 			   &driver_attr_up_tail_align); | 
 | 865 |  err_create_up_tail_align: | 
 | 866 | 	driver_remove_file(&cfspi_spi_driver.driver, | 
 | 867 | 			   &driver_attr_up_head_align); | 
 | 868 |  err_create_up_head_align: | 
 | 869 |  err_dev_register: | 
 | 870 | 	return result; | 
 | 871 | } | 
 | 872 |  | 
 | 873 | module_init(cfspi_init_module); | 
 | 874 | module_exit(cfspi_exit_module); |