MT6573 Yusu GPIO Customer Document [1.2 ed.]


238 94 451KB

English Pages 28 Year 2011

Report DMCA / Copyright

DOWNLOAD PDF FILE

MT6573 Yusu GPIO Customer Document [1.2 ed.]

  • Commentary
  • https://github.com/luckasfb/Development_Documents
  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

LY M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Yusu GPIO Customer Document

Version: Release date:

1.1 2011-4-22

© 2008 - 2011 MediaTek Inc. This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

FO

Specifications are subject to change without notice.

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Document Revision History

Date

Author

1.0

2010-04-29

MingHsien Hsieh

Initial Draft

1.1

2010-07-06

MingHsien Hsieh

Modify customization

1.2

2011-04-22

Cindy Zhang

FO

Revision

MediaTek Confidential

Description

Modify for mt6573

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 2 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Table of Contents

Document Revision History .................................................................................................................. 2 Table of Contents................................................................................................................................... 3 1

Introduction................................................................................................................................... 5 1.1

1.2 1.3 1.4

2

Design............................................................................................................................................ 6 2.1 2.2

3

Software/Hardware Environment.......................................................................................... 5 1.1.1 Software Environment .......................................................................................... 5 1.1.2 Hardware Environment......................................................................................... 5 Functionality.......................................................................................................................... 5 Hardware background .......................................................................................................... 5 Hardware Component used in this driver ............................................................................. 5 Architecture........................................................................................................................... 6 Procedure & Flow ................................................................................................................. 6

Interface......................................................................................................................................... 8 3.1

FO

3.2 3.3

Data Structure....................................................................................................................... 8 3.1.1 GPIO_PIN ............................................................................................................ 8 3.1.2 GPIO_MODE...................................................................................................... 12 3.1.3 GPIO_DIR .......................................................................................................... 13 3.1.4 GPIO_PULLEN .................................................................................................. 13 3.1.5 GPIO_PULL ....................................................................................................... 13 3.1.6 GPIO_INVERSION............................................................................................. 13 3.1.7 GPIO_OUT......................................................................................................... 14 3.1.8 GPIO_CLKOUT.................................................................................................. 14 3.1.9 GPIO_CLKSRC.................................................................................................. 14 Error Code .......................................................................................................................... 15 Kernel Space Functions ..................................................................................................... 15 3.3.1 mt_set_gpio_dir.................................................................................................. 15 3.3.2 mt_get_gpio_dir.................................................................................................. 15 3.3.3 mt_set_gpio_pull_enable ................................................................................... 15 3.3.4 mt_get_gpio_pull_enable ................................................................................... 16 3.3.5 mt_set_gpio_pull_select..................................................................................... 16 3.3.6 mt_get_gpio_pull_select .................................................................................... 16 3.3.7 mt_set_gpio_inversion ....................................................................................... 16 3.3.8 mt_get_gpio_inversion ....................................................................................... 17 3.3.9 mt_set_gpio_out................................................................................................. 17 3.3.10 mt_get_gpio_out................................................................................................. 17 3.3.11 mt_get_gpio_in................................................................................................... 18 3.3.12 mt_set_gpio_mode............................................................................................. 18 3.3.13 mt_get_gpio_mode............................................................................................. 18 3.3.14 mt_set_clock_output .......................................................................................... 18 3.3.15 mt_get_gpio_clock ............................................................................................. 19

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 3 of 28

User Space Functions ........................................................................................................ 19 3.4.1 open.................................................................................................................... 19 3.4.2 close ................................................................................................................... 19 3.4.3 ioctl ..................................................................................................................... 19

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

3.4

LY

MTXXXX Chip Name Confidential B

4

Customization............................................................................................................................. 23 4.1 4.2

5

GPIO default value ............................................................................................................. 23 GPIO usage ........................................................................................................................ 27

Build............................................................................................................................................. 28 5.1 5.2

Source Code Structure & File Description.......................................................................... 28 Build Option ........................................................................................................................ 28

Lists of Tables and Figures Error! No table of figures entries found.

FO

錯誤! 找不到圖表目錄。

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 4 of 28

LY

MTXXXX Chip Name Confidential B

Introduction

1.1

Software/Hardware Environment

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

1

1.1.1

Software Environment

Driver discussed in this document is designed based on Linux Kernel 2.6.35 and Android 2.1.

1.1.2

Hardware Environment

Driver discussed in this document can run on the devices with MT6573.

1.2

Functionality

The driver is used for configure general purpose input/output pin. The main functionality is (1) Configure the GPIO pins as default value in the booting phase (2) Provide interface to other module for chaning GPIO pin functions when system is running

1.3

Hardware background

N/A.

1.4

Hardware Component used in this driver

FO

It’s part of MT6573 chip.

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 5 of 28

Design

2.1

Architecture

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

2

LY

MTXXXX Chip Name Confidential B

libft

libmeta_gpio

/dev/mtgpio

GPS Driver BT Driver

MT6573 GPIO Driver

WiFi Driver FM Driver

GPIO driver provides two interfaces: (1) kernel space : other driver could invoke the function provided by GPIO driver (2) user space : user space program could operate GPIO by sending IOCTL to /dev/mtgpio

2.2

Procedure & Flow

FO

In kernel space, other driver modules only call GPIO function to operate GPIO. The function will be described in the next chapter. In user space, the calling sequence should be same as follows:

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 6 of 28

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

LY

MTXXXX Chip Name Confidential B

FO

The detail of GPIO IOCTL code will be described in the next chapter

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 7 of 28

Interface

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

3

LY

MTXXXX Chip Name Confidential B

The chapter includes data structure & error code

3.1

Data Structure

3.1.1

GPIO_PIN

The enumeration of all GPIO pins in MT6573. It will be used in each gpio driver. typedef enum GPIO_PIN { GPIO_UNSUPPORTED = -1,

FO

GPIO0, GPIO1, GPIO2, GPIO3, GPIO4, GPIO5, GPIO6, GPIO7, GPIO8, GPIO9, GPIO10, GPIO11, GPIO12, GPIO13, GPIO14, GPIO15, GPIO16, GPIO17, GPIO18, GPIO19, GPIO20, GPIO21, GPIO22, GPIO23, GPIO24, GPIO25, GPIO26, GPIO27, GPIO28, GPIO29, GPIO30,

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 8 of 28

LY

MTXXXX Chip Name Confidential B

FO

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

GPIO31, GPIO32, GPIO33, GPIO34, GPIO35, GPIO36, GPIO37, GPIO38, GPIO39, GPIO40, GPIO41, GPIO42, GPIO43, GPIO44, GPIO45, GPIO46, GPIO47, GPIO48, GPIO49, GPIO50, GPIO51, GPIO52, GPIO53, GPIO54, GPIO55, GPIO56, GPIO57, GPIO58, GPIO59, GPIO60, GPIO61, GPIO62, GPIO63, GPIO64, GPIO65, GPIO66, GPIO67, GPIO68, GPIO69, GPIO70, GPIO71, GPIO72, GPIO73, GPIO74, GPIO75, GPIO76,

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 9 of 28

LY

MTXXXX Chip Name Confidential B

FO

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

GPIO77, GPIO78, GPIO79, GPIO80, GPIO81, GPIO82, GPIO83, GPIO84, GPIO85, GPIO86, GPIO87, GPIO88, GPIO89, GPIO90, GPIO91, GPIO92, GPIO93, GPIO94, GPIO95, GPIO96, GPIO97, GPIO98, GPIO99, GPIO100, GPIO101, GPIO102, GPIO103, GPIO104, GPIO105, GPIO106, GPIO107, GPIO108, GPIO109, GPIO110, GPIO111, GPIO112, GPIO113, GPIO114, GPIO115, GPIO116, GPIO117, GPIO118, GPIO119, GPIO120, GPIO121, GPIO122,

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 10 of 28

LY

MTXXXX Chip Name Confidential B

FO

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

GPIO123, GPIO124, GPIO125, GPIO126, GPIO127, GPIO128, GPIO129, GPIO130, GPIO131, GPIO132, GPIO133, GPIO134, GPIO135, GPIO136, GPIO137, GPIO138, GPIO139, GPIO140, GPIO141, GPIO142, GPIO143, GPIO144, GPIO145, GPIO146, GPIO147, GPIO148, GPIO149, GPIO150, GPIO151, GPIO152, GPIO153, GPIO154, GPIO155, GPIO156, GPIO157, GPIO158, GPIO159, GPIO160, GPIO161, GPIO162, GPIO163, GPIO164, GPIO165, GPIO166, GPIO167, GPIO168,

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 11 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

GPIO169, GPIO170, GPIO171, GPIO172, GPIO173, GPIO174, GPIO175, GPIO176, GPIO177, GPIO178, GPIO179, GPIO180, GPIO181, GPIO182, GPIO183, GPIO184, GPIO185, GPIO186, GPIO187, GPIO188, GPIO189, GPIO190, GPIO191, GPIO192, GPIO193, GPIO194, GPIO195, GPIO196, GPIO197, GPIO198, GPIO199, GPIO200, GPIO201, GPIO202,

GPIO_MAX }GPIO_PIN;

3.1.2

GPIO_MODE

FO

Each GPIO pin supports four mode, 0 is always GPIO mode. Please refer to data sheet if you are interested in the detail of GPIO mode in each GPIO typedef enum { GPIO_MODE_GPIO = 0, GPIO_MODE_00 = 0, GPIO_MODE_01 = 1, GPIO_MODE_02 = 2, MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 12 of 28

3, 4, 5, 6, 7,

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

GPIO_MODE_03 = GPIO_MODE_04 = GPIO_MODE_05 = GPIO_MODE_06 = GPIO_MODE_07 = GPIO_MODE_MAX, GPIO_MODE_DEFAULT } GPIO_MODE;

LY

MTXXXX Chip Name Confidential B

3.1.3

= GPIO_MODE_01,

GPIO_DIR

In GPIO mode, each GPIO pin could be configured as input or output. typedef enum { GPIO_DIR_IN = 0, GPIO_DIR_OUT = 1, GPIO_DIR_DEFAULT = GPIO_DIR_IN, } GPIO_DIR;

3.1.4

GPIO_PULLEN

Each GPIO pin could be configured as pull enable or pull disable. It depends on the device connecting to the GPIO pin. typedef enum { GPIO_PULL_DISABLE = 0, GPIO_PULL_ENABLE = 1, GPIO_PULL_EN_DEFAULT = GPIO_PULL_ENABLE, } GPIO_PULL_EN;

3.1.5

GPIO_PULL

After one GPIO pin is configured as pull enable, it could be configured as pull-up or pull-down. It depends on the device connecting to the GPIO pin. typedef enum { GPIO_PULL_DOWN = 0, GPIO_PULL_UP = 1, GPIO_PULL_DEFAULT = GPIO_PULL_DOWN } GPIO_PULL;

3.1.6

GPIO_INVERSION

FO

The GPIO data could be inverted or un-invered. typedef enum { GPIO_DATA_UNINV = 0, GPIO_DATA_INV = 1, GPIO_DATA_INV_DEFAULT = GPIO_DATA_UNINV MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 13 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

} GPIO_INVERSION;

3.1.7

GPIO_OUT

After one gpio pin is configured as output pin, the output value could be configured as high (one) or low (zero). typedef enum { GPIO_OUT_ZERO = 0, GPIO_OUT_ONE = 1, GPIO_OUT_DEFAULT = GPIO_OUT_ZERO, GPIO_DATA_OUT_DEFAULT = GPIO_OUT_ZERO, /*compatible with DCT*/ } GPIO_OUT;

3.1.8

GPIO_CLKOUT

There are seven clock output sources inside the chip. typedef enum { CLK_OUT_UNSUPPORTED = -1, CLK_OUT0, CLK_OUT1, CLK_OUT2, CLK_OUT3, CLK_OUT4, CLK_OUT5, CLK_OUT6, CLK_OUT7,

CLK_MAX } GPIO_CLKOUT;

3.1.9

GPIO_CLKSRC

Each clock output source could be configured as the following clock mode typedef enum CLK_SRC { CLK_SRC_UNSUPPORTED = -1,

FO

CLK_SRC_F32K, CLK_SRC_FWCDMA, CLK_SRC_FGSM, CLK_SRC_GDSP, CLK_SRC_SYSSLK, CLK_SRC_GEMIX2, CLK_SRC_GX32W, CLK_SRC_X16W_MCLK,

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 14 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

CLK_SRC_GMDMCU, CLK_SRC_MAX } GPIO_CLKSRC;

3.2

Error Code

#define #define #define #define #define #define #define

3.3

RSUCCESS EEXCESSPINNO EBADDIR EBADINOUTVAL EBADPULLSELECT EEXCESSCLKOUT EBADCLKSRC

0 1 2 3 10 11 12

/*success*/ /*exceed maximum pin number*/ /*bad direction*/ /*bad output value*/ /*BAD pull select*/ /*BAD clock output number*/ /*BAD clock output source*/

Kernel Space Functions

3.3.1

mt_set_gpio_dir

Set GPIO direction Prototype

s32 mt_set_gpio_dir(u32 u4Pin, u32 u4Dir) Parameters in

u4Pin

The GPIO pin number

in

u4Dir

The GPIO direction, please refer to GPIO_DIR

Return Value

0: success; Otherwise: error

3.3.2

mt_get_gpio_dir

Get GPIO direction Prototype

s32 mt_get_gpio_dir(u32 u4Pin) Parameters in

u4Pin

The GPIO pin number

Return Value

>=0: GPIO direction, please refer to GPIO_DIR Otherwise: error

3.3.3

mt_set_gpio_pull_enable

Set GPIO pull enable Prototype

FO

s32 mt_set_gpio_pull_enable(u32 u4Pin, u8 bPullEn) Parameters

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 15 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Prototype in

u4Pin

The GPIO pin number

in

bPullEn

The GPIO pull enable, please refer to GPIO_PULLEN

Return Value

0: success; Otherwise: error

3.3.4

mt_get_gpio_pull_enable

Get GPIO pull enable Prototype

s32 mt_get_gpio_pull_enable (u32 u4Pin) Parameters in

u4Pin

The GPIO pin number

Return Value

>=0: GPIO pull enable, please refer to GPIO_PULLEN Otherwise: error

3.3.5

mt_set_gpio_pull_select

Set GPIO pull select mode Prototype

s32 mt_set_gpio_pull_select(u32 u4Pin, u8 uPullSel) Parameters in

u4Pin

The GPIO pin number

in

uPullSel

The GPIO pull enable, please refer to GPIO_PULL

Return Value

0: success; Otherwise: error

3.3.6

mt_get_gpio_pull_select

Get GPIO pull select mode Prototype

s32 mt_get_gpio_pull_select (u32 u4Pin) Parameters in

u4Pin

The GPIO pin number

Return Value

>=0: GPIO pull enable, please refer to GPIO_PULL Otherwise: error

FO

3.3.7

mt_set_gpio_inversion

Set GPIO data inversion mode MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 16 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Prototype s32 mt_set_gpio_inversion(u32 u4Pin, u8 uInvEn) Parameters in

u4Pin

The GPIO pin number

in

uInvEn

The GPIO pull enable, please refer to GPIO_INVERSION

Return Value

0: success; Otherwise: error

3.3.8

mt_get_gpio_inversion

Get GPIO data inversion mode Prototype

s32 mt_get_gpio_inversion (u32 u4Pin) Parameters in

u4Pin

The GPIO pin number

Return Value

>=0: GPIO pull enable, please refer to GPIO_INVERSION Otherwise: error

3.3.9

mt_set_gpio_out

Set GPIO output value Prototype

s32 mt_set_gpio_out(u32 u4Pin, u32 u4PinOut) Parameters in

u4Pin

The GPIO pin number

in

u4PinOut

The GPIO output value, please refer to GPIO_OUT

Return Value

0: success; Otherwise: error

3.3.10 mt_get_gpio_out Get GPIO output value Prototype

s32 mt_get_gpio_out (u32 u4Pin) Parameters in

u4Pin

The GPIO pin number

Return Value

FO

>=0: GPIO pull enable, please refer to GPIO_OUT Otherwise: error

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 17 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

3.3.11 mt_get_gpio_in Get the value of GPIO input Prototype

s32 mt_get_gpio_in (u32 u4Pin) Parameters in

u4Pin

The GPIO pin number

Return Value

0: input value is low 1: input value is high Otherwise: error

3.3.12 mt_set_gpio_mode Set GPIO mode Prototype

s32 mt_set_gpio_mode(u32 u4Pin, u32 u4Mode) Parameters in

u4Pin

The GPIO pin number

in

u4Mode

The GPIO mode, please refer to GPIO_MODE

Return Value

0: success; Otherwise: error

3.3.13 mt_get_gpio_mode Get GPIO mode Prototype

s32 mt_get_gpio_mode (u32 u4Pin) Parameters in

u4Pin

The GPIO pin number

Return Value

>=0: GPIO mode value, please refer to GPIO_MODE Otherwise: error

3.3.14 mt_set_clock_output Set clock output sources Prototype

s32 mt_set_clock_output(u32 u4ClkOut, u32 u4Src) Parameters in

u4ClkOut

The number of clock output, please refer to GPIO_CLKOUT

in

u4Src

The clock output source, please refer to GPIO_CLKSRC

FO

Return Value

0: success; Otherwise: error

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 18 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

3.3.15 mt_get_gpio_clock Get clock output sources Prototype

s32 mt_get_gpio_mode (u32 u4ClkOut) Parameters in

u4ClkOut

The number of clock output, please refer to GPIO_CLKOUT

Return Value

>=0: the clock output source, please refer to GPIO_CLKSRC Otherwise: error

3.4

User Space Functions

3.4.1

open

Prototype (provided in linux system) Int open(const char* name, int flags) Parameters in

name

Please fill “/dev/mtgpio” to open device

in

flags

Please fill O_RDWR to open device

Return Value

>=0: file descriptor -1: error, please check errno for error code

3.4.2

close

Prototype (provided in linux system) Int close(int fd) Parameters In

fd

File descriptor

Return Value

0: result -1: error, please check errno for error code

3.4.3

ioctl

Prototype (provided in linux system)

int ioctl(int fd, int command, unsigned long arg) Parameters fd

File descriptor

in

command

IOCTL command

in/out

arg

The command argument, it could be input or output

FO

in

Return Value MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 19 of 28

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Prototype (provided in linux system)

LY

MTXXXX Chip Name Confidential B

The return value depends on IOCTL command The supported IOCTL command is: GPIO_IOCQMODE

Description

Query GPIO mode

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0 ~ 3: GPIO mode, please refer to GPIO_MODE Otherwise:error

Cmd

GPIO_IOCTMODE0

Description

Set GPIO mode as mode 0

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: the operation succeeds; Otherwise: error

Cmd

GPIO_IOCTMODE1

Description

Set GPIO mode as mode 1

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCTMODE2

Description

Set GPIO mode as mode 2

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCTMODE3

Description

Set GPIO mode as mode 3

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCQDIR

Description

Query GPIO direction

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0 ~ 1: GPIO direction, please refer to GPIO_DIR Otherwise: the operation fails

Cmd

GPIO_IOCSDIRIN

Description

Set GPIO direction as input

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCSDIROUT

Description

Set GPIO direction as output

Arg

GPIO pin number, please refer to GPIO_PIN

FO

Cmd

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 20 of 28

GPIO_IOCQMODE

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Cmd

LY

MTXXXX Chip Name Confidential B

0: success Otherwise: error

Cmd

GPIO_IOCQPULLEN

Description

Query GPIO pull enable

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0 ~ 1: pull disable/enable, please refer to GPIO_PULLEN Otherwise: error

Cmd

GPIO_IOCQPULLENABLE

Description

Enable GPIO pull

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCQPULLDISABLE

Description

Disable GPIO pull

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCQPULL

Description

Query GPIO pull selection

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0 ~ 1: pull down / pull up, please refer to GPIO_PULLSEL Otherwise: error

Cmd

GPIO_IOCSPULLDOWN

Description

Set GPIO pull selection as pull-down

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCSPULLUP

Description

Set GPIO pull selection as pull-up

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCQINV

Description

Query GPIO data inversion

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0 ~ 1: data un-inversion/inversion, please refer to GPIO_INVERSION Otherwise: error

Cmd

GPIO_IOCSINVENABLE

Description

Enable GPIO data inversion

Arg

GPIO pin number, please refer to GPIO_PIN

FO

Return

Return

0: success Otherwise: error

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 21 of 28

GPIO_IOCQMODE

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

Cmd

LY

MTXXXX Chip Name Confidential B

GPIO_IOCSINVDISABLE

Description

Disable GPIO data inversion

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCQDATAIN

Description

Query the value of GPIO input

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: the input is low (0) 1: the input is high (1) Otherwise: error

Cmd

GPIO_IOCQDATAOUT

Description

Query the value of GPIO output

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: the output is low (0) 1: the output is high (1) Otherwise: error

Cmd

GPIO_IOCSDATALOW

Description

The GPIO output value as low

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

Cmd

GPIO_IOCSDATAHIGH

Description

The GPIO output value as high

Arg

GPIO pin number, please refer to GPIO_PIN

Return

0: success Otherwise: error

FO

Cmd

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 22 of 28

Customization

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

4

LY

MTXXXX Chip Name Confidential B

The GPIO customization is combined with DCT (Driver Customization Tool). Please also refer to the document. In the following sections, we will briefly introduce the related function

4.1

DCT

DCT will generate the default value of each GPIO pin. Please refer to DCT document for customizing GPIO list using DCT.

4.2

GPIO Protection

DCT will generate the default value of each GPIO pin. However, not all default value of each GPIO pin should be flushed to register during booting phase. For protecting the default value in hardware, protection mechanism is designed. Those mechanisms are provided in board specific file, which locates at alps\mtk\src\custom\${BOARD}\kernel\core\board.c. The main functions for protection are listed as follows: (1) mt6573_init_machine static void __init mt6573_init_machine(void) { : mt6573_init_gpio(); mt_gpio_checkpoint_save(); mt6573_init_pinmux(); mt_gpio_checkpoint_compare(); } The four functions are the central idea of protection: (a) Apply the DCT setting to GPIO register (b) Save current snapshot of GPIO register (c) Apply the manual setting to GPIO register. The manual setting is generally a copy of DCT setting. The only difference is the manual setting is created manually instead of DCT setting. (d) Check if the current snapshot is the same as the one saved in (b). If DCT setting is the same as manual setting, nothing will happen. Otherwise, a kernel warning might be fired. (2) mt6573_init_gpio: apply the setting generated by DCT to GPIO register (3) mt6573_init_pinmux: apply the manual setting to GPIO register Please see follow for different strategy:

4.2.1

No protection (this mechanism is used in current source code)

FO

For disable the protection, please modify mt6573_init_gpio as follows: static void __init mt6573_init_gpio(void) { mt_gpio_unlock_init(1); mt_gpio_set_default(); MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 23 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

} With the modification, all of the GPIO pins will be the same as the one generated by DCT. This is the convenient way to apply GPIO setting generated by DCT. Please make sure the setting you defined in DCT is correct or something will go wrong.

4.2.2

Coarse Protection (this mechanism is not used anymore,it only used by 6516)

FO

All of the GPIO pins are locked by default. This means the DCT setting will not be flushed to GPIO register unless the GPIO pin is unlocked. Please see the following example to apply coarse protection: (1) Enable the compile option for consistency check: In alps\kernel\arch\arm\mach-mt6573\include\mach\mt6573_gpio.h, define the compile option: GPIO_INIT_DEBUG to check the consistency. If the manual setting and DCT setting are different, a kernel warning will be triggered (2) Define manual setting. Generally, only the GPIO pin which is not connected is defined in the list. typedef struct { unsigned int no : 16; unsigned int mode : 2; unsigned int pullsel: 1; unsigned int din : 1; unsigned int dout : 1; unsigned int pullen : 1; unsigned int dir : 1; unsigned int dinv : 1; unsigned int _align : 8; } GPIO_CFG; /*===================================================================*/ GPIO_CFG items[] = { /* PIN, M, P, I, O, E, D, V, X*/ { 1, 1, 0, 0, 0, 0, 0, 0, 0}, { 17, 1, 0, 0, 0, 1, 0, 0, 0}, { 18, 1, 0, 0, 0, 1, 0, 0, 0}, }; /*===================================================================*/ (3) Implement mt6573_init_pinmux to apply manual setting, each GPIO attribute defined in the above manual setting will be flushed to GPIO registers. static void __init mt6573_init_pinmux(void) { #if defined(GPIO_INIT_DEBUG) || defined(GPIO_INIT_PINMUX) int idx, num = sizeof(items)/sizeof(items[0]); GPIO_CFG *pin; for (idx = 0; idx < num; idx++) { pin = &items[idx]; mt_set_gpio_mode(pin->no, pin->mode); mt_set_gpio_pull_enable(pin->no, pin->pullen); MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 24 of 28

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

mt_set_gpio_pull_select(pin->no, pin->pullsel); mt_set_gpio_inversion(pin->no, pin->dinv); mt_set_gpio_out(pin->no, pin->dout); mt_set_gpio_dir(pin->no, pin->dir);

LY

MTXXXX Chip Name Confidential B

} #endif } (4) Implement mt6573_init_gpio to apply DCT setting. First, all of the GPIO pins are locked. Second, the GPIO pins are unlocked according to the manual setting table. static void __init mt6573_init_gpio(void) { int idx, num = sizeof(items)/sizeof(items[0]); mt_gpio_unlock_init(0); for (idx = 0; idx < num; idx++) mt_gpio_unlock_pin(items[idx].no, GPIO_CONF_ALL); mt_gpio_unlock_dump(); mt_gpio_set_default();

} If the DCT setting and manual setting differs, a kernel warning will be triggered. And, the difference will be dumped.

4.2.3

Fine Protection (this mechanism is not used anymore )

FO

All of the GPIO pins are locked by default. This means the DCT setting will not be flushed to GPIO register unless the GPIO pin is unlocked. The difference between coarse protection and fine protection is fine protection will protect each GPIO attribute. Please see the following example: (1) Enable the compile option for consistency check: In alps\kernel\arch\arm\mach-mt6573\include\mach\mt6573_gpio.h, define the compile option: GPIO_INIT_DEBUG to check the consistency. If the manual setting and DCT setting are different, a kernel warning will be triggered (2) Implement mt6573_init_pinmux to apply manual setting. In this function, each attribute of GPIO pin could be defined separately. static void __init mt6573_init_pinmux(void) { #if defined(GPIO_INIT_DEBUG) || defined(GPIO_INIT_PINMUX) /* Keypad */ mt_set_gpio_mode(23, 1); //KROW5 mt_set_gpio_mode(28, 1); //KCOL5 mt_set_gpio_mode(71, 1); //KCOL7 mt_set_gpio_mode(72, 1); //KCOL6 mt_set_gpio_mode(73, 1); //KROW7 mt_set_gpio_mode(74, 1); //KROW6 mt_set_gpio_mode(87, 1); //KCOL0 mt_set_gpio_mode(88, 1); //KCOL1 mt_set_gpio_mode(89, 1); //KCOL2 MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 25 of 28

LY

MTXXXX Chip Name Confidential B

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

mt_set_gpio_mode(90, 1); //KCOL3 mt_set_gpio_mode(91, 1); //KCOL4 mt_set_gpio_mode(110, 1); //KROW0 mt_set_gpio_mode(111, 1); //KROW1 mt_set_gpio_mode(112, 1); //KROW2 mt_set_gpio_mode(113, 1); //KROW3 mt_set_gpio_mode(114, 1); //KROW4 #endif } (3) Implement mt6573_init_gpio to apply DCT setting. First, all of the GPIO pins are locked. Second, a unlock table should be defined to unlock GPIO pin. The attribute of GPIO pin could be unlocked separately. typedef enum { GPIO_CONF_DIR = 0x0001, GPIO_CONF_PULLEN = 0x0002, GPIO_CONF_PULLSEL = 0x0004, GPIO_CONF_DINV = 0x0008, GPIO_CONF_DOUT = 0x0010, GPIO_CONF_DIN = 0x0020, GPIO_CONF_MODE = 0x0040, GPIO_CONF_CLKOUT = 0x0080, GPIO_CONF_ALL = 0x00FF, } GPIO_CONF; static void __init mt6573_init_gpio(void) { int idx; typedef struct { int pin; u32 conf; } GPIO_UNLOCK; GPIO_UNLOCK items[] = { /*COL*/ {GPIO0, GPIO_CONF_MODE }, }; mt_gpio_unlock_init(0); for (idx = 0; idx < sizeof(items)/sizeof(items[0]); idx++) mt_gpio_unlock_pin(items[idx].pin, items[idx].conf); mt_gpio_unlock_dump(); mt_gpio_set_default();

FO

} If the DCT setting and manual setting differs, a kernel warning will be triggered. And, the difference will be dumped.

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 26 of 28

GPIO usage

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

4.3

LY

MTXXXX Chip Name Confidential B

FO

The DCT also generates a unified name used by each module. Hence, each module could use the undified name to access GPIO APIs.

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 27 of 28

LY

MTXXXX Chip Name Confidential B

Build

5.1

Source Code Structure & File Description

M R ED yu IA .li@ T E tin K C no O mo NF bil ID e.c EN om T I US AL EO N

5

Describe your source code structure along with its file description as follows: File

Description

alps\mtk\src\custom\${BOARD}\kernel\dct\dct\ cust_gpio_usage.h

The header file of GPIO usage. It provides unified name used by each driver module

cust_gpio_boot.h

The header file of GPIO default value.

alps\mtk\src\custom\${BOARD}\kernel\core\ board.c

The entry point for apply GPIO setting generated by DCT

aps\kernel\arch\arm\mach-mt6573\include\ mt6573_gpio.h

The header file of GPIO API and its related data structure

alps\kernel\arch\arm\mach-mt6573\ mt6573_gpio.c

5.2

The implementation of GPIO API.

Build Option

FO

By default, the GPIO driver must be included in the SW load or other modules could not operate GPIO.

MediaTek Confidential

© 2010 - 2011 MediaTek Inc.

This document contains information that is proprietary to MediaTek Inc. Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.

Page 28 of 28