aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-09-29 04:31:34 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-10-12 23:37:37 -0400
commit65308c46b760bb2ccb043b47bb5f053dbb8d11b5 (patch)
treeb1207bb74c3c8e04ac0dbe856b0b449011d7d19a
parente8b17b5b3f30252b5470dbbf54bc251ddc7fac17 (diff)
spi/topcliff: cleanups for style and conciseness
This patch makes multiple cleanups to the new topcliff pch spi driver including, but not limited to, - removing superfluous brackets around variables - open coding functions that are only used once - removing unnecessary line breaks - removing unused functions - simplifying the interrupt enable/disable code - remove unnecessary (void *) casts. - remove b_mem_fail from pch_spi_set_tx to code it more cleanly - shorten dev_dbg() messages for conciseness and readability More cleanups are still needed in this driver. In particular, - the driver filename should be changed to spi_topcliff_pch.c - many of the dev_dbg() lines should be trimmed (particularly the ones on unconditional code paths). - I suspect that the locking model not correct. I'd like to know what drivers' critical regions are, and how they are protected. - get_resources and release_resources probably should be open coded in .probe and .release respectively. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
-rw-r--r--drivers/spi/spi_topcliff_pch.c502
1 files changed, 138 insertions, 364 deletions
diff --git a/drivers/spi/spi_topcliff_pch.c b/drivers/spi/spi_topcliff_pch.c
index 58b183f6eec..97746232741 100644
--- a/drivers/spi/spi_topcliff_pch.c
+++ b/drivers/spi/spi_topcliff_pch.c
@@ -1,8 +1,6 @@
1/* 1/*
2 * SPI bus driver for the Topcliff PCH used by Intel SoCs 2 * SPI bus driver for the Topcliff PCH used by Intel SoCs
3 */ 3 *
4
5/*
6 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. 4 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
7 * 5 *
8 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
@@ -19,6 +17,7 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20 */ 18 */
21 19
20#include <linux/delay.h>
22#include <linux/pci.h> 21#include <linux/pci.h>
23#include <linux/wait.h> 22#include <linux/wait.h>
24#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
@@ -45,17 +44,7 @@
45 44
46#define PCH_RX_THOLD 7 45#define PCH_RX_THOLD 7
47#define PCH_RX_THOLD_MAX 15 46#define PCH_RX_THOLD_MAX 15
48#define PCH_RX 1
49#define PCH_TX 2
50
51/* various interrupts */
52#define PCH_TFI 0x1
53#define PCH_RFI 0x2
54#define PCH_FI 0x4
55#define PCH_ORI 0x8
56#define PCH_MDFI 0x10
57 47
58#define PCH_ALL (PCH_TFI|PCH_RFI|PCH_FI|PCH_ORI|PCH_MDFI)
59#define PCH_MAX_BAUDRATE 5000000 48#define PCH_MAX_BAUDRATE 5000000
60#define PCH_MAX_FIFO_DEPTH 16 49#define PCH_MAX_FIFO_DEPTH 16
61 50
@@ -86,6 +75,8 @@
86#define SPSR_FI_BIT (1 << 2) 75#define SPSR_FI_BIT (1 << 2)
87#define SPBRR_SIZE_BIT (1 << 10) 76#define SPBRR_SIZE_BIT (1 << 10)
88 77
78#define PCH_ALL (SPCR_TFIE_BIT|SPCR_RFIE_BIT|SPCR_FIE_BIT|SPCR_ORIE_BIT|SPCR_MDFIE_BIT)
79
89#define SPCR_RFIC_FIELD 20 80#define SPCR_RFIC_FIELD 20
90#define SPCR_TFIC_FIELD 16 81#define SPCR_TFIC_FIELD 16
91 82
@@ -176,16 +167,6 @@ static struct pci_device_id pch_spi_pcidev_id[] = {
176 {0,} 167 {0,}
177}; 168};
178 169
179static inline void pch_set_bitmsk(u32 *var, u32 bitmask)
180{
181 *var |= bitmask;
182}
183
184static inline void pch_clr_bitmsk(u32 *var, u32 bitmask)
185{
186 *var &= (~(bitmask));
187}
188
189/** 170/**
190 * pch_spi_writereg() - Performs register writes 171 * pch_spi_writereg() - Performs register writes
191 * @master: Pointer to struct spi_master. 172 * @master: Pointer to struct spi_master.
@@ -194,9 +175,7 @@ static inline void pch_clr_bitmsk(u32 *var, u32 bitmask)
194 */ 175 */
195static inline void pch_spi_writereg(struct spi_master *master, int idx, u32 val) 176static inline void pch_spi_writereg(struct spi_master *master, int idx, u32 val)
196{ 177{
197
198 struct pch_spi_data *data = spi_master_get_devdata(master); 178 struct pch_spi_data *data = spi_master_get_devdata(master);
199
200 iowrite32(val, (data->io_remap_addr + idx)); 179 iowrite32(val, (data->io_remap_addr + idx));
201} 180}
202 181
@@ -208,19 +187,9 @@ static inline void pch_spi_writereg(struct spi_master *master, int idx, u32 val)
208static inline u32 pch_spi_readreg(struct spi_master *master, int idx) 187static inline u32 pch_spi_readreg(struct spi_master *master, int idx)
209{ 188{
210 struct pch_spi_data *data = spi_master_get_devdata(master); 189 struct pch_spi_data *data = spi_master_get_devdata(master);
211
212 return ioread32(data->io_remap_addr + idx); 190 return ioread32(data->io_remap_addr + idx);
213} 191}
214 192
215/* ope==true:Set bit, ope==false:Clear bit */
216static inline void pch_spi_setclr_bit(u32 *val, u32 pos, bool ope)
217{
218 if (ope)
219 *val |= pos;
220 else
221 *val &= (~(pos));
222}
223
224static inline void pch_spi_setclr_reg(struct spi_master *master, int idx, 193static inline void pch_spi_setclr_reg(struct spi_master *master, int idx,
225 u32 set, u32 clr) 194 u32 set, u32 clr)
226{ 195{
@@ -229,7 +198,6 @@ static inline void pch_spi_setclr_reg(struct spi_master *master, int idx,
229 pch_spi_writereg(master, idx, tmp); 198 pch_spi_writereg(master, idx, tmp);
230} 199}
231 200
232
233static void pch_spi_set_master_mode(struct spi_master *master) 201static void pch_spi_set_master_mode(struct spi_master *master)
234{ 202{
235 pch_spi_setclr_reg(master, PCH_SPCR, SPCR_MSTR_BIT, 0); 203 pch_spi_setclr_reg(master, PCH_SPCR, SPCR_MSTR_BIT, 0);
@@ -245,35 +213,6 @@ static void pch_spi_clear_fifo(struct spi_master *master)
245 pch_spi_setclr_reg(master, PCH_SPCR, 0, SPCR_FICLR_BIT); 213 pch_spi_setclr_reg(master, PCH_SPCR, 0, SPCR_FICLR_BIT);
246} 214}
247 215
248/**
249 * ch_spi_disable_interrupts() - Disables specified interrupts
250 * @master: Pointer to struct spi_master.
251 * @interrupt: Interrups to be enabled.
252 */
253static void pch_spi_disable_interrupts(struct spi_master *master, u8 interrupt)
254{
255 u32 clr_flags = 0;
256
257 if (interrupt & PCH_RFI)
258 clr_flags |= SPCR_RFIE_BIT;
259
260 if (interrupt & PCH_TFI)
261 clr_flags |= SPCR_TFIE_BIT;
262
263 if (interrupt & PCH_FI)
264 clr_flags |= SPCR_FIE_BIT;
265
266 if (interrupt & PCH_ORI)
267 clr_flags |= SPCR_ORIE_BIT;
268
269 if (interrupt & PCH_MDFI)
270 clr_flags |= SPCR_MDFIE_BIT;
271
272 pch_spi_setclr_reg(master, PCH_SPCR, 0, clr_flags);
273
274 dev_dbg(&master->dev, "%s clearing bits =%x\n", __func__, clr_flags);
275}
276
277static void pch_spi_handler_sub(struct pch_spi_data *data, u32 reg_spsr_val, 216static void pch_spi_handler_sub(struct pch_spi_data *data, u32 reg_spsr_val,
278 void __iomem *io_remap_addr) 217 void __iomem *io_remap_addr)
279{ 218{
@@ -309,9 +248,7 @@ static void pch_spi_handler_sub(struct pch_spi_data *data, u32 reg_spsr_val,
309 /* disable RFI if not needed */ 248 /* disable RFI if not needed */
310 if ((bpw_len - rx_index) <= PCH_MAX_FIFO_DEPTH) { 249 if ((bpw_len - rx_index) <= PCH_MAX_FIFO_DEPTH) {
311 reg_spcr_val = ioread32(io_remap_addr + PCH_SPCR); 250 reg_spcr_val = ioread32(io_remap_addr + PCH_SPCR);
312 251 reg_spcr_val &= ~SPCR_RFIE_BIT; /* disable RFI */
313 /* disable RFI */
314 pch_clr_bitmsk(&reg_spcr_val, SPCR_RFIE_BIT);
315 252
316 /* reset rx threshold */ 253 /* reset rx threshold */
317 reg_spcr_val &= MASK_RFIC_SPCR_BITS; 254 reg_spcr_val &= MASK_RFIC_SPCR_BITS;
@@ -329,7 +266,8 @@ static void pch_spi_handler_sub(struct pch_spi_data *data, u32 reg_spsr_val,
329 /* if transfer complete interrupt */ 266 /* if transfer complete interrupt */
330 if (reg_spsr_val & SPSR_FI_BIT) { 267 if (reg_spsr_val & SPSR_FI_BIT) {
331 /* disable FI & RFI interrupts */ 268 /* disable FI & RFI interrupts */
332 pch_spi_disable_interrupts(data->master, PCH_FI | PCH_RFI); 269 pch_spi_setclr_reg(data->master, PCH_SPCR, 0,
270 SPCR_FIE_BIT | SPCR_TFIE_BIT);
333 271
334 /* transfer is completed;inform pch_spi_process_messages */ 272 /* transfer is completed;inform pch_spi_process_messages */
335 data->transfer_complete = true; 273 data->transfer_complete = true;
@@ -337,7 +275,6 @@ static void pch_spi_handler_sub(struct pch_spi_data *data, u32 reg_spsr_val,
337 } 275 }
338} 276}
339 277
340
341/** 278/**
342 * pch_spi_handler() - Interrupt handler 279 * pch_spi_handler() - Interrupt handler
343 * @irq: The interrupt number. 280 * @irq: The interrupt number.
@@ -350,7 +287,6 @@ static irqreturn_t pch_spi_handler(int irq, void *dev_id)
350 void __iomem *spsr; 287 void __iomem *spsr;
351 void __iomem *io_remap_addr; 288 void __iomem *io_remap_addr;
352 irqreturn_t ret = IRQ_NONE; 289 irqreturn_t ret = IRQ_NONE;
353
354 struct pch_spi_board_data *board_dat = dev_id; 290 struct pch_spi_board_data *board_dat = dev_id;
355 291
356</