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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
|
/******************************************************************************
* mt_gpio_base.c - MTKLinux GPIO Device Driver
*
* Copyright 2008-2009 MediaTek Co.,Ltd.
*
* DESCRIPTION:
* This file provid the other drivers GPIO relative functions
*
******************************************************************************/
#include <mach/sync_write.h>
//#include <mach/mt_reg_base.h>
#include <mach/mt_typedefs.h>
#include <mach/mt_gpio.h>
#include <mach/mt_gpio_core.h>
#include <mach/mt_gpio_base.h>
//autogen
#include <mach/gpio_cfg.h>
#ifdef CONFIG_OF
#include <linux/of_address.h>
#endif
//unsigned long GPIO_COUNT=0;
//unsigned long uart_base;
//#define GPIO_BRINGUP 1
long gpio_pull_select_unsupport[MAX_GPIO_PIN]={0};
long gpio_pullen_unsupport[MAX_GPIO_PIN]={0};
long gpio_smt_unsupport[MAX_GPIO_PIN]={0};
struct mt_gpio_vbase gpio_vbase;
int mt6306_set_gpio_out(unsigned long pin, unsigned long output)
{
GPIOERR("denali not support\n");
}
int mt6306_set_gpio_dir(unsigned long pin, unsigned long dir)
{
GPIOERR("denali not support\n");
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_dir_base(unsigned long pin, unsigned long dir)
{
unsigned long bit;
unsigned long reg;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if (dir >= GPIO_DIR_MAX)
return -ERINVAL;
//GPIOERR("before pin:%ld, dir:%ld\n",pin,dir);
//pos = pin / MAX_GPIO_REG_BITS;
bit = DIR_offset[pin].offset;
//GPIOERR("before2 pin[%ld],addr=%lx,(%p,%p)\n",pin,DIR_addr[pin].addr,GPIO_BASE,(GPIO_BASE+DIR_addr[pin].addr));
#ifdef GPIO_BRINGUP
reg = GPIO_RD32(DIR_addr[pin].addr);
if (dir == GPIO_DIR_IN)
reg &= (~(1<<bit));
else
reg |= (1 << bit);
GPIO_WR32(DIR_addr[pin].addr,reg);
#else
if (dir == GPIO_DIR_IN)
GPIO_SET_BITS((1L << bit), DIR_addr[pin].addr+8);
else
GPIO_SET_BITS((1L << bit), DIR_addr[pin].addr+4);
#endif
// GPIOERR("%s:pin:%ld, dir:%ld, value:0x%x\n",__func__, pin, dir, GPIO_RD32(DIR_addr[pin].addr));
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_dir_base(unsigned long pin)
{
unsigned long bit;
unsigned long reg;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
bit = DIR_offset[pin].offset;
reg = GPIO_RD32(DIR_addr[pin].addr);
return (((reg & (1L << bit)) != 0)? 1: 0);
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_pull_enable_base(unsigned long pin, unsigned long enable)
{
unsigned long reg=0;
unsigned long bit=0;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
#ifdef GPIO_BRINGUP
bit = PULLEN_offset[pin].offset;
if(PULLEN_offset[pin].offset == -1){
return GPIO_PULL_EN_UNSUPPORTED;
}
else{
reg = GPIO_RD32(PULLEN_addr[pin].addr);
if (enable == GPIO_PULL_DISABLE)
reg &= (~(1<<bit));
else
reg |= (1 << bit);
}
GPIO_WR32(PULLEN_addr[pin].addr, reg);
#else
if(PULLEN_offset[pin].offset == -1){
gpio_pullen_unsupport[pin]=-1;
return GPIO_PULL_EN_UNSUPPORTED;
}
else{
if (enable == GPIO_PULL_DISABLE)
GPIO_SET_BITS((1L << (PULLEN_offset[pin].offset)), PULLEN_addr[pin].addr + 8);
else
GPIO_SET_BITS((1L << (PULLEN_offset[pin].offset)), PULLEN_addr[pin].addr + 4);
}
#endif
//GPIOERR("%s:pin:%ld, enable:%ld, value:0x%x\n",__func__, pin, enable, GPIO_RD32(PULLEN_addr[pin].addr));
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_pull_enable_base(unsigned long pin)
{
unsigned long data;
u32 bit=0;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if(PULLEN_offset[pin].offset == -1 && pupd_offset[pin].offset==-1){
return GPIO_PULL_EN_UNSUPPORTED;
}
if(PULLEN_offset[pin].offset != -1){
bit = PULLEN_offset[pin].offset;
data = GPIO_RD32(PULLEN_addr[pin].addr);
return (((data & (1L << bit)) != 0)? 1: 0);
}else{
bit = pupd_offset[pin].offset;
data = GPIO_RD32(pupd_addr[pin].addr);
return (((data & (0x7 << bit)) != 0)? 1: 0);
}
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_smt_base(unsigned long pin, unsigned long enable)
{
//unsigned long flags;
unsigned long reg=0;
unsigned long bit=0;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
#ifdef GPIO_BRINGUP
if(SMT_offset[pin].offset == -1){
return GPIO_SMT_UNSUPPORTED;
}
else{
bit = SMT_offset[pin].offset;
reg = GPIO_RD32(SMT_addr[pin].addr);
if (enable == GPIO_SMT_DISABLE)
reg &= (~(1<<bit));
else
reg |= (1 << bit);
}
//printk("SMT addr(%x),value(%x)\n",SMT_addr[pin].addr,GPIO_RD32(SMT_addr[pin].addr));
GPIO_WR32(SMT_addr[pin].addr, reg);
#else
if(SMT_offset[pin].offset == -1){
gpio_smt_unsupport[pin]=-1;
return GPIO_SMT_UNSUPPORTED;
}
else{
if (enable == GPIO_SMT_DISABLE)
GPIO_SET_BITS((1L << (SMT_offset[pin].offset)), SMT_addr[pin].addr + 8);
else
GPIO_SET_BITS((1L << (SMT_offset[pin].offset)), SMT_addr[pin].addr + 4);
}
#endif
//GPIOERR("%s:pin:%ld, enable:%ld, value:0x%x\n",__func__, pin, enable, GPIO_RD32(SMT_addr[pin].addr));
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_smt_base(unsigned long pin)
{
unsigned long data;
unsigned long bit =0;
bit = SMT_offset[pin].offset;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if(SMT_offset[pin].offset == -1){
return GPIO_SMT_UNSUPPORTED;
}
else{
data = GPIO_RD32(SMT_addr[pin].addr);
return (((data & (1L << bit)) != 0)? 1: 0);
}
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_ies_base(unsigned long pin, unsigned long enable)
{
//unsigned long flags;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if(IES_offset[pin].offset == -1){
return GPIO_IES_UNSUPPORTED;
}
else{
if (enable == GPIO_IES_DISABLE)
GPIO_SET_BITS((1L << (IES_offset[pin].offset)), IES_addr[pin].addr + 8);
else
GPIO_SET_BITS((1L << (IES_offset[pin].offset)), IES_addr[pin].addr + 4);
}
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_ies_base(unsigned long pin)
{
unsigned long data;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if(IES_offset[pin].offset == -1){
return GPIO_IES_UNSUPPORTED;
}
else{
data = GPIO_RD32(IES_addr[pin].addr);
return (((data & (1L << (IES_offset[pin].offset))) != 0)? 1: 0);
}
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_pull_select_base(unsigned long pin, unsigned long select)
{
//unsigned long flags;
unsigned long reg=0;
unsigned long bit = 0;
u32 mask = (1L << 4) - 1;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
#ifdef GPIO_BRINGUP
if((PULL_offset[pin].offset == -1) &&(pupd_offset[pin].offset == -1)) {
return GPIO_PULL_UNSUPPORTED;
}
if(pin>=160 && pin <=165){
bit =pupd_offset[pin].offset;//special spec in pupd reg different form pullsel
reg = GPIO_RD32(pupd_addr[pin].addr);
if (select == GPIO_PULL_UP)//0x2 pull up
{
reg &= (~(mask << bit));
reg |= (0x2 << bit);
}
else //0x6 pull down
{
reg &= (~(mask << bit));
reg |= (0x6 << bit);
}
//printk("fwq pullset pin=%d,3.............\n",pin);
GPIO_WR32(pupd_addr[pin].addr, reg);
return RSUCCESS;
}
//printk("fwq pullset pin=%d,select(%d)\n",pin,select);
if(PULL_offset[pin].offset != -1){
bit = PULL_offset[pin].offset;
reg = GPIO_RD32(PULL_addr[pin].addr);
if (select == GPIO_PULL_DOWN)
reg &= (~(1<<bit));
else
reg |= (1 << bit);
//printk("fwq pullset pin=%d,2.............\n",pin);
GPIO_WR32(PULL_addr[pin].addr, reg);
}
else {
bit =pupd_offset[pin].offset+2;//special spec in pupd reg different form pullsel
reg = GPIO_RD32(pupd_addr[pin].addr);
if (select == GPIO_PULL_UP)
reg &= (~(1<<bit));
else
reg |= (1 << bit);
//printk("fwq pullset pin=%d,3.............\n",pin);
GPIO_WR32(pupd_addr[pin].addr, reg);
}
#else
if((PULL_offset[pin].offset == -1) &&(pupd_offset[pin].offset == -1)) {
gpio_pull_select_unsupport[pin]=-1;
return GPIO_PULL_UNSUPPORTED;
}
//printk("fwq pullset pin=%ld,1.............\n",pin);
if(pin>=160 && pin <=165){
//GPIOERR("fwq11 pupd pin[%ld],addr=%lx,(%p,%p)\n",pin,pupd_addr[pin].addr,GPIO_BASE,(GPIO_BASE+pupd_addr[pin].addr));
if (select == GPIO_PULL_UP)//0x2 pull up
{
//reg &= (~(mask << bit));
//reg |= (0x2 << bit);
GPIO_SET_BITS((2L << (pupd_offset[pin].offset)), pupd_addr[pin].addr + 4);
}
else //0x6 pull down
{
//reg &= (~(mask << bit));
//reg |= (0x6 << bit);
GPIO_SET_BITS((6L << (pupd_offset[pin].offset)), pupd_addr[pin].addr + 4);
}
return RSUCCESS;
}
//printk("fwq pullset pin=%ld,2.............\n",pin);
//printk("fwq pullset pin=%d,select(%d)\n",pin,select);
if(PULL_offset[pin].offset != -1){
//GPIOERR("fwq22 PULL pin[%ld],addr=%lx,(%p,%p)\n",pin,PULL_addr[pin].addr,GPIO_BASE,(GPIO_BASE+PULL_addr[pin].addr));
bit = PULL_offset[pin].offset;
//reg = GPIO_RD32(PULL_addr[pin].addr);
if (select == GPIO_PULL_DOWN)
GPIO_SET_BITS((1L << bit), PULL_addr[pin].addr + 8);
else
GPIO_SET_BITS((1L << bit), PULL_addr[pin].addr + 4);
//printk("fwq pullset pin=%d,2.............\n",pin);
}
else {
//GPIOERR("fwq33.2 pupd pin[%ld],addr=%lx,(%p,%p)\n",pin,pupd_addr[pin].addr,GPIO_BASE,(GPIO_BASE+pupd_addr[pin].addr));
bit =pupd_offset[pin].offset+2;//special spec in pupd reg different form pullsel
//reg = GPIO_RD32(pupd_addr[pin].addr);
if (select == GPIO_PULL_UP)
GPIO_SET_BITS((1L << (bit)), pupd_addr[pin].addr + 8);
else
GPIO_SET_BITS((1L << (bit)), pupd_addr[pin].addr + 4);
}
#endif
// GPIOERR("%s:pin:%ld, select:%ld, value:0x%x\n",__func__, pin, select, GPIO_RD32(PULL_addr[pin].addr));
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_pull_select_base(unsigned long pin)
{
unsigned long data;
unsigned long bit = 0;
u32 mask = (1L << 4) - 1;
if(pin>=160 && pin <=165){
bit =pupd_offset[pin].offset;
data = GPIO_RD32(pupd_addr[pin].addr);
return (((((data >> bit) & mask)==0x2))? 1: 0);//0x2 pull up
}
if((PULL_offset[pin].offset == -1) && (pupd_offset[pin].offset == -1)){
return GPIO_PULL_UNSUPPORTED;
}
else if(PULL_offset[pin].offset == -1){
data = GPIO_RD32(pupd_addr[pin].addr);
return (((data & (1L << (pupd_offset[pin].offset+2))) != 0)? 0: 1);
}
else{
data = GPIO_RD32(PULL_addr[pin].addr);
return (((data & (1L << (PULL_offset[pin].offset))) != 0)? 1: 0);
}
#if 0
unsigned long data;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if((PULL_offset[pin].offset == -1) ){
return GPIO_PULL_UNSUPPORTED;
}
else{
data = GPIO_RD32(PULL_addr[pin].addr);
return (((data & (1L << (PULL_offset[pin].offset))) != 0)? 1: 0);
}
#endif
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_inversion_base(unsigned long pin, unsigned long enable)
{/*FIX-ME
*/
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_inversion_base(unsigned long pin)
{/*FIX-ME*/
return 0;//FIX-ME
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_out_base(unsigned long pin, unsigned long output)
{
unsigned long bit;
unsigned long reg=0;
//struct mt_gpio_obj *obj = gpio_obj;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if (output >= GPIO_OUT_MAX)
return -ERINVAL;
// GPIOERR("before pin:%ld, output:%ld\n",pin,output);
bit = DATAOUT_offset[pin].offset;
#ifdef GPIO_BRINGUP
reg = GPIO_RD32(DATAOUT_addr[pin].addr);
GPIOERR("before2 pin[%ld],addr=%lx\n",pin,DATAOUT_addr[pin].addr);
if (output == GPIO_OUT_ZERO)
reg &= (~(1<<bit));
else
reg |= (1 << bit);
GPIO_WR32(DATAOUT_addr[pin].addr,reg);
#else
if (output == GPIO_OUT_ZERO)
GPIO_SET_BITS((1L << bit), DATAOUT_addr[pin].addr+8);
else
GPIO_SET_BITS((1L << bit), DATAOUT_addr[pin].addr+4);
#endif
//GPIOERR("%s:pin:%ld, output:%ld, value:0x%x\n",__func__, pin, output, GPIO_RD32(DATAOUT_addr[pin].addr));
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_out_base(unsigned long pin)
{
unsigned long bit;
unsigned long reg;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
bit = DATAOUT_offset[pin].offset;
reg = GPIO_RD32(DATAOUT_addr[pin].addr);
return (((reg & (1L << bit)) != 0)? 1: 0);
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_in_base(unsigned long pin)
{
unsigned long bit;
unsigned long reg;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
bit = DIN_offset[pin].offset;
reg = GPIO_RD32(DIN_addr[pin].addr);
return (((reg & (1L << bit)) != 0)? 1: 0);
}
/*---------------------------------------------------------------------------*/
int mt_set_gpio_mode_base(unsigned long pin, unsigned long mode)
{
unsigned long bit;
unsigned long reg;
unsigned long mask = (1L << GPIO_MODE_BITS) - 1;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
if (mode >= GPIO_MODE_MAX)
return -ERINVAL;
//pos = pin / MAX_GPIO_MODE_PER_REG;
bit = MODE_offset[pin].offset;
GPIOERR("modebefore1 set pin[%ld],addr=%lx,(%p,%p)\n",pin,MODE_addr[pin].addr,GPIO_BASE,(GPIO_BASE+MODE_addr[pin].addr));
//#ifdef GPIO_BRINGUP
#if 1
mode = mode & mask;
//printk("fwq pin=%d,mode=%d, offset=%d\n",pin,mode,bit);
reg = GPIO_RD32(MODE_addr[pin].addr);
//printk("fwq pin=%d,beforereg[%x]=%x\n",pin,MODE_addr[pin].addr,reg);
reg &= (~(mask << bit));
//printk("fwq pin=%d,clr=%x\n",pin,~(mask << (GPIO_MODE_BITS*bit)));
reg |= (mode << bit);
//printk("fwq pin=%d,reg[%x]=%x\n",pin,MODE_addr[pin].addr,reg);
GPIO_WR32( MODE_addr[pin].addr,reg);
//printk("fwq pin=%d,moderead=%x\n",pin,GPIO_RD32(MODE_addr[pin].addr));
#else
if(0==mode)
GPIO_SET_BITS((mask << bit), MODE_addr[pin].addr+8);
else{
//GPIO_SET_BITS((mask << bit), MODE_addr[pin].addr+8);
GPIO_SET_BITS((mode << bit), MODE_addr[pin].addr+4);
}
#endif
GPIOERR("%s:pin:%ld, mode:%ld, value:0x%x\n",__func__, pin, mode, GPIO_RD32(MODE_addr[pin].addr));
return RSUCCESS;
}
/*---------------------------------------------------------------------------*/
int mt_get_gpio_mode_base(unsigned long pin)
{
unsigned long bit;
unsigned long reg;
unsigned long mask = (1L << GPIO_MODE_BITS) - 1;
//struct mt_gpio_obj *obj = gpio_obj;
if (pin >= MAX_GPIO_PIN)
return -ERINVAL;
bit = MODE_offset[pin].offset;
// printf("fwqread bit=%d,offset=%d",bit,MODE_offset[pin].offset);
//reg = GPIO_RD32(&obj->reg->mode[pos].val);
reg = GPIO_RD32(MODE_addr[pin].addr);
// printf("fwqread pin=%d,moderead=%x, bit=%d\n",pin,GPIO_RD32(MODE_addr[pin].addr),bit);
return ((reg >> bit) & mask);
}
/*---------------------------------------------------------------------------*/
void get_gpio_vbase(struct device_node *node)
{
/* compatible with HAL */
if(!(gpio_vbase.gpio_regs)) {
gpio_vbase.gpio_regs = of_iomap(node, 0);
if(!gpio_vbase.gpio_regs) {
GPIOERR("GPIO base addr is NULL\n");
return;
}
//gpio_reg = (GPIO_REGS*)(GPIO_BASE);
GPIOERR("GPIO base add is 0x%p\n",gpio_vbase.gpio_regs);
}
GPIOERR("GPIO base addr is 0x%p, %s\n",gpio_vbase.gpio_regs, __func__);
}
/*-----------------------User need GPIO APIs before GPIO probe------------------*/
extern struct device_node *get_gpio_np(void);
static int __init get_gpio_vbase_early(void)
{
//void __iomem *gpio_base = NULL;
struct device_node *np_gpio = NULL;
gpio_vbase.gpio_regs = NULL;
np_gpio = get_gpio_np();
/* Setup IO addresses */
gpio_vbase.gpio_regs = of_iomap(np_gpio, 0);
if(!gpio_vbase.gpio_regs) {
GPIOERR("GPIO base addr is NULL\n");
return 0;
}
//gpio_reg = (GPIO_REGS*)(GPIO_BASE);
GPIOERR("GPIO base addr is 0x%p, %s\n",gpio_vbase.gpio_regs, __func__);
return 0;
}
postcore_initcall(get_gpio_vbase_early);
/*---------------------------------------------------------------------------*/
void get_io_cfg_vbase(void)
{
/* compatible with HAL */
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
#ifdef CONFIG_PM
/*---------------------------------------------------------------------------*/
void mt_gpio_suspend(void)
{
/* compatible with HAL */
}
/*---------------------------------------------------------------------------*/
void mt_gpio_resume(void)
{
/* compatible with HAL */
}
/*---------------------------------------------------------------------------*/
#endif /*CONFIG_PM*/
/*---------------------------------------------------------------------------*/
|