tgpio_imx6q.c
16.4 KB
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
/**
@file tgpio_imx6.c
@date 2013/7/22
@author 오재경 freefrug@falinux.com FALinux.Co.,Ltd.
@brief gpio 를 드라이버없이 mmap를 이용하여 제어한다.
Ver 0.7.0 iMX6 포함, GP0테스트 진행
Ver 0.6.0 am3874 포함, GP0테스트 완료
Ver 0.5.0 s5pv210 포함, 테스트 완료
pull-up, pull-dn 설정변경
Ver 0.4.0 tmmap.c 를 사용하지 않고 famap.c 를 사용하는것으로 수정
Ver 0.3.0 ixp420 테스트 완료
Ver 0.2.1 s3c6410, pxa270 테스트 완료
Ver 0.2.0 pxa270 완료
pxa255 완료(테스트 안됨)
Ver 0.1.0 s3c6410 완료
s3c2440 완료(테스트 안됨)
@modify
@todo 다음과 같은 MCU 들도 지원하여야 한다.
..
@bug
@remark
@warning
*/
//----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#include <util.h>
#include <famap.h>
#include <tgpio.h>
#include <tgpio_imx6q.h>
#include <tgpio_imx6q-iomux.h>
extern mcu_gpio_fops_t *get_gpio_fops( void );
static mcu_gpio_fops_t *mgpio = NULL;
/// imx6 gpio base
static imx6_gpio_register_t imx6_gpio_register[MCU_iMX6_GPIO_GRP_CNT] = {
[0] = { .phys = MCU_iMX6_GPIO1_PHYS, },
[1] = { .phys = MCU_iMX6_GPIO2_PHYS, },
[2] = { .phys = MCU_iMX6_GPIO3_PHYS, },
[3] = { .phys = MCU_iMX6_GPIO4_PHYS, },
[4] = { .phys = MCU_iMX6_GPIO5_PHYS, },
[5] = { .phys = MCU_iMX6_GPIO6_PHYS, },
[6] = { .phys = MCU_iMX6_GPIO7_PHYS, },
};
#define WRITE_MUX_CTRL( val, reg ) *(volatile unsigned long *)( reg ) = (val)
#define WRITE_SEL_INPUT( val, reg ) *(volatile unsigned long *)( reg ) = (val)
#define WRITE_PAD_CTRL( val, reg ) *(volatile unsigned long *)( reg ) = (val)
static void imx6_gpio_output( char grp, int gp_nr, int gp_val );
//------------------------------------------------------------------------------
/** @brief configures a single pad in the iomuxer
@param mmap_base
@param pad
*///----------------------------------------------------------------------------
static int mxc_iomux_v3_setup_pad( unsigned long base, iomux_v3_cfg_t pad )
{
u32 mux_ctrl_ofs = (pad & MUX_CTRL_OFS_MASK ) >> MUX_CTRL_OFS_SHIFT ;
u32 mux_mode = (pad & MUX_MODE_MASK ) >> MUX_MODE_SHIFT ;
u32 sel_input_ofs = (pad & MUX_SEL_INPUT_OFS_MASK) >> MUX_SEL_INPUT_OFS_SHIFT;
u32 sel_input = (pad & MUX_SEL_INPUT_MASK ) >> MUX_SEL_INPUT_SHIFT ;
u32 pad_ctrl_ofs = (pad & MUX_PAD_CTRL_OFS_MASK ) >> MUX_PAD_CTRL_OFS_SHIFT ;
u32 pad_ctrl = (pad & MUX_PAD_CTRL_MASK ) >> MUX_PAD_CTRL_SHIFT ;
if (mux_ctrl_ofs)
WRITE_MUX_CTRL(mux_mode, base + mux_ctrl_ofs);
if (sel_input_ofs)
WRITE_SEL_INPUT(sel_input, base + sel_input_ofs);
if (!(pad_ctrl & NO_PAD_CTRL) && pad_ctrl_ofs)
WRITE_PAD_CTRL(pad_ctrl, base + pad_ctrl_ofs);
return 0;
}
// group : gpio1 ... gpio7
static iomux_v3_cfg_t imx6q_gpio_pads[7][32] = {
['1'-'1'] = {
MX6Q_PAD_GPIO_0__GPIO_1_0,
MX6Q_PAD_GPIO_1__GPIO_1_1,
MX6Q_PAD_GPIO_2__GPIO_1_2,
MX6Q_PAD_GPIO_3__GPIO_1_3,
MX6Q_PAD_GPIO_4__GPIO_1_4,
MX6Q_PAD_GPIO_5__GPIO_1_5,
MX6Q_PAD_GPIO_6__GPIO_1_6,
MX6Q_PAD_GPIO_7__GPIO_1_7,
MX6Q_PAD_GPIO_8__GPIO_1_8,
MX6Q_PAD_GPIO_9__GPIO_1_9,
M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_SD3_DAT4__GPIO_7_1,
MX6Q_PAD_SD3_CMD__GPIO_7_2,
MX6Q_PAD_SD3_CLK__GPIO_7_3,
MX6Q_PAD_SD3_DAT0__GPIO_7_4,
MX6Q_PAD_SD3_DAT1__GPIO_7_5,
MX6Q_PAD_SD3_DAT2__GPIO_7_6,
MX6Q_PAD_SD3_DAT3__GPIO_7_7,
MX6Q_PAD_SD3_RST__GPIO_7_8,
MX6Q_PAD_SD4_CMD__GPIO_7_9,
MX6Q_PAD_SD4_CLK__GPIO_7_10,
MX6Q_PAD_GPIO_16__GPIO_7_11,
MX6Q_PAD_GPIO_17__GPIO_7_12,
MX6Q_PAD_GPIO_18__GPIO_7_13,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
}
};
//static mmap_alloc_t map_iomux; /// mmap 관리 구조체
//static unsigned long iomux_base = 0;
//------------------------------------------------------------------------------
/** @brief configures a single pad in the iomuxer
@param mmap_base
@param pad
*///----------------------------------------------------------------------------
static int mxc_iomux_setup_gpio( unsigned long iomux_base, char grp, int gp_nr, gpio_pulled_t pull_up )
{
iomux_v3_cfg_t pad;
//if ( 0 == iomux_base )
//{
// iomux_base = (unsigned long)fa_mmap_alloc( &map_iomux, MX6Q_IOMUXC_BASE_ADDR, MX6Q_IOMUXC_SIZE );
//}
if ( ( '1' <= grp ) && ( grp <= '7' ) )
{
pad = imx6q_gpio_pads[ grp-'1'][ gp_nr%32 ];
if ( 0 != pad )
{
switch( pull_up )
{
case GPIO_PULL_UP : pad &= ~NO_PAD_CTRL; pad |= PAD_CTL_PUS_47K_UP; break;
case GPIO_PULL_DN : pad &= ~NO_PAD_CTRL; pad |= PAD_CTL_PUS_100K_DOWN; break;
default : break;
}
mxc_iomux_v3_setup_pad( iomux_base, pad );
}
else goto err_exit;
}
else goto err_exit;
return 0;
err_exit:
printf( " iMX6 iomux error : invalid gpio [%c-%d]\n", grp, gp_nr );
return -1;
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio 번호가 정확한지 확인한다.
@param grp 0~3
@param gp_nr gp_nr 번호
*///----------------------------------------------------------------------------
static int imx6_valid_gpio( char grp, int gp_nr )
{
grp -= '1';
if ( grp >= MCU_iMX6_GPIO_GRP_CNT )
{
printf( " gpio error : invalid gp_grp [%d (0~%d)]\n", grp+1, MCU_iMX6_GPIO_GRP_CNT );
return -1;
}
if ( gp_nr >= 32 )
{
printf( " gpio error : invalid gp_nr [%d (0~31)]\n", gp_nr );
return -1;
}
return 0;
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio 입력 포트 주소를 얻는다.
@param grp 0~3
@param gp_nr gp_nr 번호
*///----------------------------------------------------------------------------
static unsigned long imx6_get_dat_port ( char grp, int gp_nr )
{
imx6_gpio_register_t *gp = (imx6_gpio_register_t *)(mgpio->private) + (grp - '1');
if ( 0 > imx6_valid_gpio( grp, gp_nr ) ) return 0;
return gp->mmap_base + MCU_iMX6_GPIO_DAT_OFS;
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio 입력 설정
@param grp '1'~'7'
@param gp_nr gp_nr 0..31
@param pull_up pull_up
*///----------------------------------------------------------------------------
static void imx6_gpio_dir_input( char grp, int gp_nr, gpio_pulled_t pull_up )
{
imx6_gpio_register_t *gp = (imx6_gpio_register_t *)(mgpio->private) + (grp - '1');
if ( 0 > imx6_valid_gpio( grp, gp_nr ) ) return;
// iomux
mxc_iomux_setup_gpio( gp->mmap_base, grp, gp_nr, pull_up );
// gpio dir input
iMX6_GPIO_DIRPORT( gp->mmap_base ) &= ~(1<<gp_nr); // input
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio 출력 설정
@param grp '1'~'7'
@param gp_nr gp_nr 0..31
@param gp_val gpio 초기 출력값
*///----------------------------------------------------------------------------
static void imx6_gpio_dir_output( char grp, int gp_nr, int gp_val )
{
imx6_gpio_register_t *gp = (imx6_gpio_register_t *)(mgpio->private) + (grp - '1');
if ( 0 > imx6_valid_gpio( grp, gp_nr ) ) return;
// iomux
mxc_iomux_setup_gpio( gp->mmap_base, grp, gp_nr, GPIO_PULL_NONE );
// gpio dir output
iMX6_GPIO_DIRPORT( gp->mmap_base ) |= (1<<gp_nr); // output
imx6_gpio_output( grp, gp_nr, gp_val );
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio 입력
@param grp '1'~'7'
@param gp_nr gp_nr 0..31
*///----------------------------------------------------------------------------
static int imx6_gpio_input( char grp, int gp_nr )
{
imx6_gpio_register_t *gp = (imx6_gpio_register_t *)(mgpio->private) + (grp - '1');
unsigned long rval;
if ( 0 > imx6_valid_gpio( grp, gp_nr ) ) return -1;
rval = iMX6_GPIO_DATPORT( gp->mmap_base );
return ( rval & (1<<gp_nr) ) ? 1:0;
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio 출력
@param grp '1'~'7'
@param gp_nr gp_nr 0..31
@param gpio_val gpio 초기 출력값
*///----------------------------------------------------------------------------
static void imx6_gpio_output( char grp, int gp_nr, int gp_val )
{
imx6_gpio_register_t *gp = (imx6_gpio_register_t *)(mgpio->private) + (grp - '1');
unsigned long rval;
if ( 0 > imx6_valid_gpio( grp, gp_nr ) ) return;
// gpio data out
{
rval = iMX6_GPIO_DATPORT( gp->mmap_base );
rval &= ~(1<<gp_nr);
rval |= (gp_val&0x1) << gp_nr;
iMX6_GPIO_DATPORT( gp->mmap_base ) = rval;
}
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio close() 함수
*///----------------------------------------------------------------------------
static void imx6_gpio_close( void )
{
int lp;
imx6_gpio_register_t *gp = (imx6_gpio_register_t *)mgpio->private;
for( lp=0; lp<MCU_iMX6_GPIO_GRP_CNT; lp++, gp++ )
{
fa_mmap_free( &gp->map_gpio );
}
// iomux 해제
if ( mgpio->mmap_base )
{
fa_mmap_free( &mgpio->map_info );
mgpio->mmap_base = 0;
}
}
//------------------------------------------------------------------------------
/** @brief imx6 gpio 초기화
@param mcu_nr mcu 번호
*///----------------------------------------------------------------------------
void imx6_gpio_open( int mcu_nr )
{
mgpio = get_gpio_fops();
mgpio->mcu_nr = mcu_nr;
// pin mux mmap
mgpio->mmap_base = (unsigned long)fa_mmap_alloc( &mgpio->map_info, MX6Q_IOMUXC_BASE_ADDR, MX6Q_IOMUXC_SIZE );
// gpio mmap
{
int lp;
imx6_gpio_register_t *gp = imx6_gpio_register;
for( lp=0; lp<MCU_iMX6_GPIO_GRP_CNT; lp++, gp++ )
{
gp->mmap_base = (unsigned long)fa_mmap_alloc( &gp->map_gpio, gp->phys, MCU_iMX6_GPIO_PHYS_SIZE );
}
}
mgpio->close = imx6_gpio_close ;
mgpio->dir_input = imx6_gpio_dir_input ;
mgpio->dir_output = imx6_gpio_dir_output;
mgpio->input = imx6_gpio_input ;
mgpio->output = imx6_gpio_output ;
mgpio->get_input_port = imx6_get_dat_port ;
mgpio->get_output_port = imx6_get_dat_port ;
mgpio->private = (void *)imx6_gpio_register;
}