summaryrefslogtreecommitdiff
path: root/packages/linux/linux-rp-2.6.24/tosa/0047-tc6393xb-use-bitmasks-instead-of-bit-field-structs.patch
blob: 54e88253d1586aff3825058a07dc5c386313e53d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
From c18b8e34c39ec0d395988318e6651076a748d6bd Mon Sep 17 00:00:00 2001
From: Dmitry Baryshkov <dbaryshkov@gmail.com>
Date: Tue, 12 Feb 2008 04:40:54 +0300
Subject: [PATCH 47/64] tc6393xb: use bitmasks instead of bit-field structs

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
---
 drivers/mfd/tc6393xb.c       |  162 ++++++++++++++++++++++++-----------------
 include/linux/mfd/tc6393xb.h |   63 +++-------------
 2 files changed, 107 insertions(+), 118 deletions(-)

diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index dfae61d..1a394e4 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -24,6 +24,31 @@
 #include <linux/mfd/tmio.h>
 #include <linux/mfd/tc6393xb.h>
 
+#define TC6393XB_FER_USBEN		BIT(0)	/* USB host enable */
+#define TC6393XB_FER_LCDCVEN		BIT(1)	/* polysilicon TFT enable */
+#define TC6393XB_FER_SLCDEN		BIT(2)	/* SLCD enable */
+
+enum pincontrol {
+	opendrain	= 0,
+	tristate	= 1,
+	pushpull	= 2,
+	/* reserved	= 3, */
+};
+
+#define TC6393XB_MCR_RDY_MASK		(3 << 0)
+#define TC6393XB_MCR_RDY_OPENDRAIN	(0 << 0)
+#define TC6393XB_MCR_RDY_TRISTATE	(1 << 0)
+#define TC6393XB_MCR_RDY_PUSHPULL	(2 << 0)
+#define TC6393XB_MCR_RDY_UNK		BIT(2)
+#define TC6393XB_MCR_RDY_EN		BIT(3)
+#define TC6393XB_MCR_INT_MASK		(3 << 4)
+#define TC6393XB_MCR_INT_OPENDRAIN	(0 << 4)
+#define TC6393XB_MCR_INT_TRISTATE	(1 << 4)
+#define TC6393XB_MCR_INT_PUSHPULL	(2 << 4)
+#define TC6393XB_MCR_INT_UNK		BIT(6)
+#define TC6393XB_MCR_INT_EN		BIT(7)
+/* bits 8 - 16 are unknown */
+
 struct tc6393xb_scr {
 	u8 x00[8];
 	u8	revid;		/* 0x08 Revision ID			*/
@@ -74,8 +99,8 @@ struct tc6393xb {
 	spinlock_t			lock; /* protects RMW cycles */
 
 	struct {
-		union tc6393xb_scr_fer	fer;
-		union tc6393xb_scr_ccr	ccr;
+		u8			fer;
+		u16			ccr;
 		u8			gpi_bcr[4];
 	} suspend_state;
 
@@ -90,13 +115,13 @@ static int tc6393xb_mmc_enable(struct platform_device *mmc) {
 	struct platform_device		*dev	= to_platform_device(mmc->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr = tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
+	u16				ccr;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.ck32ken = 1;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr |= TC6393XB_CCR_CK32K;
+	iowrite16(ccr, &scr->ccr);
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
 	return 0;
@@ -106,13 +131,13 @@ static int tc6393xb_mmc_disable(struct platform_device *mmc) {
 	struct platform_device		*dev	= to_platform_device(mmc->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
+	u16				ccr;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.ck32ken = 0;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr &= ~TC6393XB_CCR_CK32K;
+	iowrite16(ccr, &scr->ccr);
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
 	return 0;
@@ -148,14 +173,17 @@ int tc6393xb_lcd_set_power(struct platform_device *fb, bool on)
 	struct platform_device		*dev	= to_platform_device(fb->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_fer		fer;
+	u8				fer;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	fer.raw	= ioread8(&scr->fer);
-	fer.bits.slcden = on ? 1 : 0;
-	iowrite8(fer.raw, &scr->fer);
+	fer = ioread8(&scr->fer);
+	if (on)
+		fer |= TC6393XB_FER_SLCDEN;
+	else
+		fer &= ~TC6393XB_FER_SLCDEN;
+	iowrite8(fer, &scr->fer);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -181,19 +209,19 @@ static int tc6393xb_ohci_disable(struct platform_device *ohci)
 	struct platform_device		*dev	= to_platform_device(ohci->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
-	union tc6393xb_scr_fer		fer;
+	u16				ccr;
+	u8				fer;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	fer.raw = ioread8(&scr->fer);
-	fer.bits.usben = 0;
-	iowrite8(fer.raw, &scr->fer);
+	fer = ioread8(&scr->fer);
+	fer &= ~TC6393XB_FER_USBEN;
+	iowrite8(fer, &scr->fer);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.usbcken = 0;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr &= ~TC6393XB_CCR_USBCK;
+	iowrite16(ccr, &scr->ccr);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -205,19 +233,19 @@ static int tc6393xb_ohci_enable(struct platform_device *ohci)
 	struct platform_device		*dev	= to_platform_device(ohci->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
-	union tc6393xb_scr_fer		fer;
+	u16				ccr;
+	u8				fer;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.usbcken = 1;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr |= TC6393XB_CCR_USBCK;
+	iowrite16(ccr, &scr->ccr);
 
-	fer.raw = ioread8(&scr->fer);
-	fer.bits.usben = 1;
-	iowrite8(fer.raw, &scr->fer);
+	fer = ioread8(&scr->fer);
+	fer |= TC6393XB_FER_USBEN;
+	iowrite8(fer, &scr->fer);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -229,14 +257,14 @@ static int tc6393xb_ohci_suspend(struct platform_device *ohci)
 	struct platform_device		*dev	= to_platform_device(ohci->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
+	u16				ccr;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.usbcken = 0;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr &= ~TC6393XB_CCR_USBCK;
+	iowrite16(ccr, &scr->ccr);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -248,14 +276,14 @@ static int tc6393xb_ohci_resume(struct platform_device *ohci)
 	struct platform_device		*dev	= to_platform_device(ohci->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
+	u16				ccr;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.usbcken = 1;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr |= TC6393XB_CCR_USBCK;
+	iowrite16(ccr, &scr->ccr);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -267,8 +295,8 @@ static int tc6393xb_fb_disable(struct platform_device *fb)
 	struct platform_device		*dev	= to_platform_device(fb->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
-	union tc6393xb_scr_fer		fer;
+	u16				ccr;
+	u8				fer;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
@@ -276,14 +304,13 @@ static int tc6393xb_fb_disable(struct platform_device *fb)
 	/*
 	 * FIXME: is this correct or it should be moved to other _disable?
 	 */
-	fer.raw	= ioread8(&scr->fer);
-	fer.bits.slcden = 0;
-/*	fer.bits.lcdcven = 0; */
-	iowrite8(fer.raw, &scr->fer);
+	fer = ioread8(&scr->fer);
+	fer &= ~TC6393XB_FER_SLCDEN;
+	iowrite8(fer, &scr->fer);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.mclksel = disable;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr = (ccr & ~TC6393XB_CCR_MCLK_MASK) | TC6393XB_CCR_MCLK_OFF;
+	iowrite16(ccr, &scr->ccr);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -295,14 +322,14 @@ static int tc6393xb_fb_enable(struct platform_device *fb)
 	struct platform_device		*dev	= to_platform_device(fb->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
+	u16				ccr;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.mclksel = m48MHz;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr = (ccr & ~TC6393XB_CCR_MCLK_MASK) | TC6393XB_CCR_MCLK_48;
+	iowrite16(ccr, &scr->ccr);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -314,14 +341,14 @@ static int tc6393xb_fb_suspend(struct platform_device *fb)
 	struct platform_device		*dev	= to_platform_device(fb->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
+	u16				ccr;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.mclksel = disable;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr = (ccr & ~TC6393XB_CCR_MCLK_MASK) | TC6393XB_CCR_MCLK_OFF;
+	iowrite16(ccr, &scr->ccr);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -333,14 +360,14 @@ static int tc6393xb_fb_resume(struct platform_device *fb)
 	struct platform_device		*dev	= to_platform_device(fb->dev.parent);
 	struct tc6393xb			*tc6393xb = platform_get_drvdata(dev);
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
-	union tc6393xb_scr_ccr		ccr;
+	u16				ccr;
 	unsigned long			flags;
 
 	spin_lock_irqsave(&tc6393xb->lock, flags);
 
-	ccr.raw = ioread16(&scr->ccr);
-	ccr.bits.mclksel = m48MHz;
-	iowrite16(ccr.raw, &scr->ccr);
+	ccr = ioread16(&scr->ccr);
+	ccr = (ccr & ~TC6393XB_CCR_MCLK_MASK) | TC6393XB_CCR_MCLK_48;
+	iowrite16(ccr, &scr->ccr);
 
 	spin_unlock_irqrestore(&tc6393xb->lock, flags);
 
@@ -592,14 +619,15 @@ static int tc6393xb_hw_init(struct platform_device *dev, int resume)
 	struct tc6393xb_scr __iomem	*scr	= tc6393xb->scr;
 	int				i;
 
-	iowrite8(resume ?
-		tc6393xb->suspend_state.fer.raw :
-		0,				&scr->fer);
+	iowrite8(resume ? tc6393xb->suspend_state.fer : 0,
+						&scr->fer);
 	iowrite16(tcpd->scr_pll2cr,		&scr->pll2cr);
 	iowrite16(resume?
-		tc6393xb->suspend_state.ccr.raw :
-		tcpd->scr_ccr.raw,		&scr->ccr);
-	iowrite16(tcpd->scr_mcr.raw,		&scr->mcr);
+		tc6393xb->suspend_state.ccr :
+		tcpd->scr_ccr,		&scr->ccr);
+	iowrite16(TC6393XB_MCR_RDY_OPENDRAIN | TC6393XB_MCR_RDY_UNK | TC6393XB_MCR_RDY_EN |
+		  TC6393XB_MCR_INT_OPENDRAIN | TC6393XB_MCR_INT_UNK | TC6393XB_MCR_INT_EN |
+		  BIT(15),		&scr->mcr);
 	iowrite16(tcpd->scr_gper,		&scr->gper);
 	iowrite8(0,				&scr->irr);
 	iowrite8(0xbf,				&scr->imr);
@@ -730,8 +758,8 @@ static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state)
 	int i;
 
 
-	tc6393xb->suspend_state.ccr.raw		= ioread16(&scr->ccr);
-	tc6393xb->suspend_state.fer.raw		= ioread8(&scr->fer);
+	tc6393xb->suspend_state.ccr		= ioread16(&scr->ccr);
+	tc6393xb->suspend_state.fer		= ioread8(&scr->fer);
 	for (i = 0; i < 4; i++)
 		tc6393xb->suspend_state.gpi_bcr[i] =
 			ioread8(scr->gpi_bcr + i);
diff --git a/include/linux/mfd/tc6393xb.h b/include/linux/mfd/tc6393xb.h
index e699294..2c69f63 100644
--- a/include/linux/mfd/tc6393xb.h
+++ b/include/linux/mfd/tc6393xb.h
@@ -20,60 +20,21 @@
 #include <linux/mfd-core.h>
 #include <linux/mfd/tmio.h>
 
-union tc6393xb_scr_fer {
-	u8		raw;
-struct {
-	unsigned	usben:1;	/* D0	USB enable		*/
-	unsigned	lcdcven:1;	/* D1	polysylicon TFT enable	*/
-	unsigned	slcden:1;	/* D2	SLCD enable		*/
-} __attribute__ ((packed)) bits;
-} __attribute__ ((packed));
-
-union tc6393xb_scr_ccr {
-	u16		raw;
-struct {
-	unsigned	ck32ken:1;	/* D0	SD host clock enable	*/
-	unsigned	usbcken:1;	/* D1	USB host clock enable	*/
-	unsigned	x00:2;
-	unsigned	sharp:1;	/* D4	??? set in Sharp's code	*/
-	unsigned	x01:3;
-	enum {				disable	= 0,
-					m12MHz	= 1,
-					m24MHz	= 2,
-					m48MHz	= 3,
-	}		mclksel:3;	/* D10-D8  LCD controller clock	*/
-	unsigned	x02:1;
-	enum {				h24MHz	= 0,
-					h48MHz	= 1,
-	}		hclksel:2;	/* D13-D12 host bus clock	*/
-	unsigned	x03:2;
-} __attribute__ ((packed)) bits;
-} __attribute__ ((packed));
-
-enum pincontrol {
-	opendrain	= 0,
-	tristate	= 1,
-	pushpull	= 2,
-	/* reserved	= 3, */
-};
-
-union tc6393xb_scr_mcr {
-	u16		raw;
-struct {
-	enum pincontrol	rdyst:2;	/* D1-D0   HRDY control		*/
-	unsigned	x00:1;
-	unsigned	aren:1;		/* D3	   HRDY pull up resistance cut off */
-	enum pincontrol	intst:2;	/* D5-D4   #HINT control	*/
-	unsigned	x01:1;
-	unsigned	aien:1;		/* D7      #HINT pull up resitance cut off */
-	unsigned	x02:8;
-} __attribute__ ((packed)) bits;
-} __attribute__ ((packed));
+#define TC6393XB_CCR_CK32K	BIT(0)
+#define TC6393XB_CCR_USBCK	BIT(1)
+#define TC6393XB_CCR_UNK1	BIT(4)
+#define TC6393XB_CCR_MCLK_MASK	(7 << 8)
+#define TC6393XB_CCR_MCLK_OFF	(0 << 8)
+#define TC6393XB_CCR_MCLK_12	(1 << 8)
+#define TC6393XB_CCR_MCLK_24	(2 << 8)
+#define TC6393XB_CCR_MCLK_48	(3 << 8)
+#define TC6393XB_CCR_HCLK_MASK	(3 << 12)
+#define TC6393XB_CCR_HCLK_24	(0 << 12)
+#define TC6393XB_CCR_HCLK_48	(1 << 12)
 
 struct tc6393xb_platform_data {
 	u16	scr_pll2cr;	/* PLL2 Control */
-	union tc6393xb_scr_ccr	scr_ccr;	/* Clock Control */
-	union tc6393xb_scr_mcr	scr_mcr;	/* Mode Control */
+	u16	scr_ccr;	/* Clock Control */
 	u16	scr_gper;	/* GP Enable */
 	u32	scr_gpo_doecr;	/* GPO Data OE Control */
 	u32	scr_gpo_dsr;	/* GPO Data Set */
-- 
1.5.3.8