aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2010-02-09 15:41:38 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-03-03 19:42:56 -0500
commitef97e4ef156500eb1c26de57354ad685f0b6127b (patch)
treea228adaf0b7eab7507bdc2e71222d67d5bec311d
parentdcff74ce8b458792c1628ad9f3803fc648f94e11 (diff)
Staging: dt3155: fix coding style issues in dt3155_io.c
This fixes up the sparse and coding style issues found in the dt3155_io.c file. No code is changed, only formatting and removing unused code. Cc: Scott Smedley <ss@aao.gov.au> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/dt3155/dt3155_io.c333
1 files changed, 136 insertions, 197 deletions
diff --git a/drivers/staging/dt3155/dt3155_io.c b/drivers/staging/dt3155/dt3155_io.c
index 236d3ea0f9fb..1c15604f4313 100644
--- a/drivers/staging/dt3155/dt3155_io.c
+++ b/drivers/staging/dt3155/dt3155_io.c
@@ -1,236 +1,175 @@
1/* 1/*
2 * Copyright 1996,2002,2005 Gregory D. Hager, Alfred A. Rizzi, Noah J. Cowan,
3 * Jason Lapenta, Scott Smedley
4 *
5 * This file is part of the DT3155 Device Driver.
6 *
7 * The DT3155 Device Driver is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * The DT3155 Device Driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 * Public License for more details.
16 */
2 17
3Copyright 1996,2002,2005 Gregory D. Hager, Alfred A. Rizzi, Noah J. Cowan, 18/*
4 Jason Lapenta, Scott Smedley 19 * This file provides some basic register io routines. It is modified from
5 20 * demo code provided by Data Translations.
6This file is part of the DT3155 Device Driver. 21 */
7
8The DT3155 Device Driver is free software; you can redistribute it
9and/or modify it under the terms of the GNU General Public License as
10published by the Free Software Foundation; either version 2 of the
11License, or (at your option) any later version.
12
13The DT3155 Device Driver is distributed in the hope that it will be
14useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with the DT3155 Device Driver; if not, write to the Free
20Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21MA 02111-1307 USA
22
23
24-- Changes --
25
26 Date Programmer Description of changes made
27 -------------------------------------------------------------------
28 10-Oct-2001 SS port to 2.4 kernel.
29 24-Jul-2002 SS GPL licence.
30 26-Jul-2002 SS Bug fix: timing logic was wrong.
31 08-Aug-2005 SS port to 2.6 kernel.
32
33*/
34
35/* This file provides some basic register io routines. It is modified
36 from demo code provided by Data Translations. */
37
38#ifdef __KERNEL__
39#include <asm/delay.h>
40#endif
41
42#if 0
43#include <sys/param.h>
44#include <sys/time.h>
45#include <unistd.h>
46#endif
47 22
23#include <linux/delay.h>
48#include "dt3155.h" 24#include "dt3155.h"
49#include "dt3155_io.h" 25#include "dt3155_io.h"
50#include "dt3155_drv.h" 26#include "dt3155_drv.h"
51 27
52#ifndef __KERNEL__
53#include <stdio.h>
54#endif
55
56 28
57/****** local copies of board's 32 bit registers ******/ 29/****** local copies of board's 32 bit registers ******/
58u64 even_dma_start_r; /* bit 0 should always be 0 */ 30u64 even_dma_start_r; /* bit 0 should always be 0 */
59u64 odd_dma_start_r; /* .. */ 31u64 odd_dma_start_r; /* .. */
60u64 even_dma_stride_r; /* bits 0&1 should always be 0 */ 32u64 even_dma_stride_r; /* bits 0&1 should always be 0 */
61u64 odd_dma_stride_r; /* .. */ 33u64 odd_dma_stride_r; /* .. */
62u64 even_pixel_fmt_r; 34u64 even_pixel_fmt_r;
63u64 odd_pixel_fmt_r; 35u64 odd_pixel_fmt_r;
64 36
65FIFO_TRIGGER_R fifo_trigger_r; 37FIFO_TRIGGER_R fifo_trigger_r;
66XFER_MODE_R xfer_mode_r; 38XFER_MODE_R xfer_mode_r;
67CSR1_R csr1_r; 39CSR1_R csr1_r;
68RETRY_WAIT_CNT_R retry_wait_cnt_r; 40RETRY_WAIT_CNT_R retry_wait_cnt_r;
69INT_CSR_R int_csr_r; 41INT_CSR_R int_csr_r;
70 42
71u64 even_fld_mask_r; 43u64 even_fld_mask_r;
72u64 odd_fld_mask_r; 44u64 odd_fld_mask_r;
73 45
74MASK_LENGTH_R mask_length_r; 46MASK_LENGTH_R mask_length_r;
75FIFO_FLAG_CNT_R fifo_flag_cnt_r; 47FIFO_FLAG_CNT_R fifo_flag_cnt_r;
76IIC_CLK_DUR_R iic_clk_dur_r; 48IIC_CLK_DUR_R iic_clk_dur_r;
77IIC_CSR1_R iic_csr1_r; 49IIC_CSR1_R iic_csr1_r;
78IIC_CSR2_R iic_csr2_r; 50IIC_CSR2_R iic_csr2_r;
79DMA_UPPER_LMT_R even_dma_upper_lmt_r; 51DMA_UPPER_LMT_R even_dma_upper_lmt_r;
80DMA_UPPER_LMT_R odd_dma_upper_lmt_r; 52DMA_UPPER_LMT_R odd_dma_upper_lmt_r;
81 53
82 54
83 55
84/******** local copies of board's 8 bit I2C registers ******/ 56/******** local copies of board's 8 bit I2C registers ******/
85I2C_CSR2 i2c_csr2; 57I2C_CSR2 i2c_csr2;
86I2C_EVEN_CSR i2c_even_csr; 58I2C_EVEN_CSR i2c_even_csr;
87I2C_ODD_CSR i2c_odd_csr; 59I2C_ODD_CSR i2c_odd_csr;
88I2C_CONFIG i2c_config; 60I2C_CONFIG i2c_config;
89u8 i2c_dt_id; 61u8 i2c_dt_id;
90u8 i2c_x_clip_start; 62u8 i2c_x_clip_start;
91u8 i2c_y_clip_start; 63u8 i2c_y_clip_start;
92u8 i2c_x_clip_end; 64u8 i2c_x_clip_end;
93u8 i2c_y_clip_end; 65u8 i2c_y_clip_end;
94u8 i2c_ad_addr; 66u8 i2c_ad_addr;
95u8 i2c_ad_lut; 67u8 i2c_ad_lut;
96I2C_AD_CMD i2c_ad_cmd; 68I2C_AD_CMD i2c_ad_cmd;
97u8 i2c_dig_out; 69u8 i2c_dig_out;
98u8 i2c_pm_lut_addr; 70u8 i2c_pm_lut_addr;
99u8 i2c_pm_lut_data; 71u8 i2c_pm_lut_data;
100
101
102// return the time difference (in microseconds) b/w <a> & <b>.
103long elapsed2 (const struct timeval *pStart, const struct timeval *pEnd)
104{
105 long i = (pEnd->tv_sec - pStart->tv_sec) * 1000000;
106 i += pEnd->tv_usec - pStart->tv_usec;
107 return i;
108}
109 72
110/*********************************************************************** 73/*
111 wait_ibsyclr() 74 * wait_ibsyclr()
112 75 *
113 This function handles read/write timing and r/w timeout error 76 * This function handles read/write timing and r/w timeout error
114 77 *
115 Returns TRUE if NEW_CYCLE clears 78 * Returns TRUE if NEW_CYCLE clears
116 Returns FALSE if NEW_CYCLE doesn't clear in roughly 3 msecs, 79 * Returns FALSE if NEW_CYCLE doesn't clear in roughly 3 msecs, otherwise
117 otherwise returns 0 80 * returns 0
118 81 */
119***********************************************************************/ 82static int wait_ibsyclr(u8 *lpReg)
120int wait_ibsyclr(u8 * lpReg)
121{ 83{
122 /* wait 100 microseconds */ 84 /* wait 100 microseconds */
123 85 udelay(100L);
124#ifdef __KERNEL__ 86 /* __delay(loops_per_sec/10000); */
125 udelay(100L); 87 if (iic_csr2_r.fld.NEW_CYCLE) {
126 /* __delay(loops_per_sec/10000); */ 88 /* if NEW_CYCLE didn't clear */
127 if (iic_csr2_r.fld.NEW_CYCLE ) 89 /* TIMEOUT ERROR */
128 { /* if NEW_CYCLE didn't clear */ 90 dt3155_errno = DT_ERR_I2C_TIMEOUT;
129 /* TIMEOUT ERROR */ 91 return FALSE;
130 dt3155_errno = DT_ERR_I2C_TIMEOUT; 92 } else
131 return FALSE; 93 return TRUE; /* no error */
132 }
133 else
134 return TRUE; /* no error */
135#else
136 struct timeval StartTime;
137 struct timeval EndTime;
138
139 const int to_3ms = 3000; /* time out of 3ms = 3000us */
140
141 gettimeofday( &StartTime, NULL );
142 do {
143 /* get new iic_csr2 value: */
144 ReadMReg((lpReg + IIC_CSR2), iic_csr2_r.reg);
145 gettimeofday( &EndTime, NULL );
146 }
147 while ((elapsed2(&StartTime, &EndTime) < to_3ms) && iic_csr2_r.fld.NEW_CYCLE);
148
149 if (iic_csr2_r.fld.NEW_CYCLE )
150 { /* if NEW_CYCLE didn't clear */
151 printf("Timed out waiting for NEW_CYCLE to clear!");
152 return FALSE;
153 }
154 else
155 return TRUE; /* no error */
156#endif
157} 94}
158 95
159/*********************************************************************** 96/*
160 WriteI2C() 97 * WriteI2C()
161 98 *
162 This function handles writing to 8-bit DT3155 registers 99 * This function handles writing to 8-bit DT3155 registers
163 100 *
164 1st parameter is pointer to 32-bit register base address 101 * 1st parameter is pointer to 32-bit register base address
165 2nd parameter is reg. index; 102 * 2nd parameter is reg. index;
166 3rd is value to be written 103 * 3rd is value to be written
167 104 *
168 Returns TRUE - Successful completion 105 * Returns TRUE - Successful completion
169 FALSE - Timeout error - cycle did not complete! 106 * FALSE - Timeout error - cycle did not complete!
170***********************************************************************/ 107 */
171int WriteI2C (u8 * lpReg, u_short wIregIndex, u8 byVal) 108int WriteI2C(u8 *lpReg, u_short wIregIndex, u8 byVal)
172{ 109{
173 int writestat; /* status for return */ 110 int writestat; /* status for return */
174
175 /* read 32 bit IIC_CSR2 register data into union */
176 111
177 ReadMReg((lpReg + IIC_CSR2), iic_csr2_r.reg); 112 /* read 32 bit IIC_CSR2 register data into union */
178 113
179 iic_csr2_r.fld.DIR_RD = 0; /* for write operation */ 114 ReadMReg((lpReg + IIC_CSR2), iic_csr2_r.reg);
180 iic_csr2_r.fld.DIR_ADDR = wIregIndex; /* I2C address of I2C register: */
181 iic_csr2_r.fld.DIR_WR_DATA = byVal; /* 8 bit data to be written to I2C reg */
182 iic_csr2_r.fld.NEW_CYCLE = 1; /* will start a direct I2C cycle: */
183 115
184 /* xfer union data into 32 bit IIC_CSR2 register */ 116 /* for write operation */
117 iic_csr2_r.fld.DIR_RD = 0;
118 /* I2C address of I2C register: */
119 iic_csr2_r.fld.DIR_ADDR = wIregIndex;
120 /* 8 bit data to be written to I2C reg */
121 iic_csr2_r.fld.DIR_WR_DATA = byVal;
122 /* will start a direct I2C cycle: */
123 iic_csr2_r.fld.NEW_CYCLE = 1;
185 124
186 WriteMReg((lpReg + IIC_CSR2), iic_csr2_r.reg); 125 /* xfer union data into 32 bit IIC_CSR2 register */
126 WriteMReg((lpReg + IIC_CSR2), iic_csr2_r.reg);
187 127
188 /* wait for IIC cycle to finish */ 128 /* wait for IIC cycle to finish */
189 129 writestat = wait_ibsyclr(lpReg);
190 writestat = wait_ibsyclr( lpReg ); 130 return writestat;
191 return writestat; /* return with status */
192} 131}
193 132
194/*********************************************************************** 133/*
195 ReadI2C() 134 * ReadI2C()
196 135 *
197 This function handles reading from 8-bit DT3155 registers 136 * This function handles reading from 8-bit DT3155 registers
198 137 *
199 1st parameter is pointer to 32-bit register base address 138 * 1st parameter is pointer to 32-bit register base address
200 2nd parameter is reg. index; 139 * 2nd parameter is reg. index;
201 3rd is adrs of value to be read 140 * 3rd is adrs of value to be read
202 141 *
203 Returns TRUE - Successful completion 142 * Returns TRUE - Successful completion
204 FALSE - Timeout error - cycle did not complete! 143 * FALSE - Timeout error - cycle did not complete!
205***********************************************************************/ 144 */
206int ReadI2C (u8 * lpReg, u_short wIregIndex, u8 * byVal) 145int ReadI2C(u8 *lpReg, u_short wIregIndex, u8 *byVal)
207{ 146{
208 int writestat; /* status for return */ 147 int writestat; /* status for return */
209 148
210 /* read 32 bit IIC_CSR2 register data into union */ 149 /* read 32 bit IIC_CSR2 register data into union */
211 ReadMReg((lpReg + IIC_CSR2), iic_csr2_r.reg); 150 ReadMReg((lpReg + IIC_CSR2), iic_csr2_r.reg);
212 151
213 /* for read operation */ 152 /* for read operation */
214 iic_csr2_r.fld.DIR_RD = 1; 153 iic_csr2_r.fld.DIR_RD = 1;
215 154
216 /* I2C address of I2C register: */ 155 /* I2C address of I2C register: */
217 iic_csr2_r.fld.DIR_ADDR = wIregIndex; 156 iic_csr2_r.fld.DIR_ADDR = wIregIndex;
218 157
219 /* will start a direct I2C cycle: */ 158 /* will start a direct I2C cycle: */
220 iic_csr2_r.fld.NEW_CYCLE = 1; 159 iic_csr2_r.fld.NEW_CYCLE = 1;
221 160
222 /* xfer union's data into 32 bit IIC_CSR2 register */ 161 /* xfer union's data into 32 bit IIC_CSR2 register */
223 WriteMReg((lpReg + IIC_CSR2), iic_csr2_r.reg); 162 WriteMReg((lpReg + IIC_CSR2), iic_csr2_r.reg);
224 163
225 /* wait for IIC cycle to finish */ 164 /* wait for IIC cycle to finish */
226 writestat = wait_ibsyclr(lpReg); 165 writestat = wait_ibsyclr(lpReg);
227 166
228 /* Next 2 commands read 32 bit IIC_CSR1 register's data into union */ 167 /* Next 2 commands read 32 bit IIC_CSR1 register's data into union */
229 /* first read data is in IIC_CSR1 */ 168 /* first read data is in IIC_CSR1 */
230 ReadMReg((lpReg + IIC_CSR1), iic_csr1_r.reg); 169 ReadMReg((lpReg + IIC_CSR1), iic_csr1_r.reg);
231 170
232 /* now get data u8 out of register */ 171 /* now get data u8 out of register */
233 *byVal = (u8) iic_csr1_r.fld.RD_DATA; 172 *byVal = (u8) iic_csr1_r.fld.RD_DATA;
234 173
235 return writestat; /* return with status */ 174 return writestat;
236} 175}