| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This file is part of wl18xx | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2011 Texas Instruments | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * version 2 as published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, but | 
					
						
							|  |  |  |  * WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | 
					
						
							|  |  |  |  * 02110-1301 USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../wlcore/wlcore.h"
 | 
					
						
							|  |  |  | #include "../wlcore/io.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "io.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | int wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val) | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	u32 tmp; | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (WARN_ON(addr % 2)) | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((addr % 4) == 0) { | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 		ret = wlcore_read32(wl, addr, &tmp); | 
					
						
							|  |  |  | 		if (ret < 0) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 		tmp = (tmp & 0xffff0000) | val; | 
					
						
							| 
									
										
										
										
											2012-06-20 00:48:23 +03:00
										 |  |  | 		ret = wlcore_write32(wl, addr, tmp); | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 		ret = wlcore_read32(wl, addr - 2, &tmp); | 
					
						
							|  |  |  | 		if (ret < 0) | 
					
						
							|  |  |  | 			goto out; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 		tmp = (tmp & 0xffff) | (val << 16); | 
					
						
							| 
									
										
										
										
											2012-06-20 00:48:23 +03:00
										 |  |  | 		ret = wlcore_write32(wl, addr - 2, tmp); | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | out: | 
					
						
							|  |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | int wl18xx_top_reg_read(struct wl1271 *wl, int addr, u16 *out) | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-07-08 17:41:22 +03:00
										 |  |  | 	u32 val = 0; | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (WARN_ON(addr % 2)) | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((addr % 4) == 0) { | 
					
						
							|  |  |  | 		/* address is 4-bytes aligned */ | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 		ret = wlcore_read32(wl, addr, &val); | 
					
						
							|  |  |  | 		if (ret >= 0 && out) | 
					
						
							|  |  |  | 			*out = val & 0xffff; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 		ret = wlcore_read32(wl, addr - 2, &val); | 
					
						
							|  |  |  | 		if (ret >= 0 && out) | 
					
						
							|  |  |  | 			*out = (val & 0xffff0000) >> 16; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-18 15:50:21 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							| 
									
										
										
										
											2012-05-10 12:13:41 +03:00
										 |  |  | } |