MT6573 YuSu SPI Customer Document [1.0 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 SPI Customer Document

Version: Release date:

1.0 2011-02-18

© 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

MT6516 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

Revision

FO

1.0

Date

Author

2011-02-18

Cindy Zhang

MediaTek Confidential

Description Initial

© 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 16

LY

MT6516 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

3.2

Data Structure....................................................................................................................... 8 3.1.1 spi_transfer........................................................................................................... 8 3.1.2 spi_message ........................................................................................................ 9 3.1.3 spi_device ............................................................................................................ 9 3.1.4 mt6516_chip_conf .............................................................................................. 10 3.1.5 spi_board_info.................................................................................................... 11 Kernel Space Functions ..................................................................................................... 12 3.2.1 spi_setup ............................................................................................................ 12 3.2.2 spi_sync ............................................................................................................. 12 3.2.3 spi_message_init................................................................................................ 12 3.2.4 spi_message_add_tail........................................................................................ 13 3.2.5 spi_register_board_info...................................................................................... 13

Source code skeleton in Yusu .................................................................................................. 14 4.1 4.2

5

Architecture........................................................................................................................... 6 Procedure & Flow ................................................................................................................. 6

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

4

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

SPI Controller driver ........................................................................................................... 14 SPI device driver ................................................................................................................ 14

Build............................................................................................................................................. 16

FO

5.1 5.2

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

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 16

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

Lists of Tables and Figures

LY

MT6516 Chip Name Confidential B

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 16

LY

MT6516 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.32 and Android 2.2.

1.1.2

Hardware Environment

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

1.2

Functionality

The driver is used to transfer data between master and slave. The main functionality is (1) Connect the SPI device by SPI bus provided by Linux kernel. (2) Provide parameters setting for SPI device.

1.3

Hardware background

N/A.

1.4

Hardware Component used in this driver

FO

It’s part of MT6516 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 16

LY

MT6516 Chip Name Confidential B

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

SPI device Driver

SPI BUS ( Linux kernel core)

SPI device

SPI controller driver

Platform BUS

SPI controller

Note: 1) SPI controller is registered on platform bus. 2) SPI devices are registered on SPI bus.

2.2

Procedure & Flow

FO

In kernel space, SPI device driver is registered on SPI bus and calls the interfaces Linux kernel core provides. SPI controller driver is registered on platform bus and calls the interface of Linux kernel core.

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 16

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

MT6516 Chip Name Confidential B

SPI bus

SPI Device

spi_setup

spi_sync

SPI Controller

mt6516_spi_setup

mt6516_spi_transfer

FO

The details of SPI bus interfaces will be introduced in the following chapters.

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 16

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

MT6516 Chip Name Confidential B

The chapter includes data structure and functions.

3.1

Data Structure

3.1.1

spi_transfer

This is one of the most important data structures of Linux Kernel core. struct spi_transfer { const void *tx_buf; void *rx_buf; unsigned len; dma_addr_t dma_addr_t

tx_dma; rx_dma;

unsigned cs_change:1; u8 bits_per_word; u16 delay_usecs; u32 speed_hz; struct list_head transfer_list;

};

The most important members of this structure are: tx_buf, rx_buf, len, tx_dma, rx_dma and transfer_list. tx_buf and rx_buf: transfer buffers for SPI data transferring. If data are written to hardware, tx_buf should be set as the address of the data; otherwise it should be set as NULL. If data are read from hardware, rx_buf should be set as the address of data; otherwise it should be set as NULL. tx_dma and rx_dma: DMA transfer buffers for DMA transferring. transfer_list: A transfer list which is composed of transfers. Note: For mt6516, rx_buf and tx_buf should be the address by using kmalloc.

FO

For example: u8 *tx_buffer=(u8 *)kzalloc(256, GFP_KERNEL); for (i=0; icontroller_data; config->pause=1; spi->controller_data=config;

3.1.4

mt6516_chip_conf

This structure is defined in mt6516_spi.h. It is used to set the parameters of the device chip. struct mt6516_chip_conf { u32 setuptime; u32 holdtime; u32 high_time; u32 low_time; u32 cs_idletime; enum spi_cpol cpol; enum spi_cpha cpha; enum spi_mlsb tx_mlsb; enum spi_mlsb rx_mlsb; enum spi_transfer_mode com_mod; enum spi_pause_mode pause; enum spi_finish_intr finish_intr; };

The parameters can be set as the private data of the device. And the controller can get by using this private data.

FO

For example: struct spi_device *spi; struct mt6516_chip_conf *config; config = (struct mt6516_chip_conf *)spi->controller_data; config->pause=1; spi->controller_data=config; spi_setup(spi);

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 16

spi_board_info

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.1.5

LY

MT6516 Chip Name Confidential B

This structure is to define a chip for the devices. This information is very important, because the SPI controller will add the devices to SPI bus according to the board info. struct spi_board_info { char modalias[SPI_NAME_SIZE]; const void *platform_data; void *controller_data; int irq;

/* slower signaling on noisy or low voltage boards */ u32 max_speed_hz; u16 u16

bus_num; chip_select;

u8

mode;

};

modalias: To identify the device. It should be same as the name of the device. Otherwise, this device can’t be identified. bus_num: the bus number of this board will be connected to. chip_select: Chip select number when multi devices exist. For mt6516: This structure is defined in the mt6516_devs.c.

static struct spi_board_info spi_board_devs[] __initdata = { [0] = { .modalias = "spidev", .bus_num = 0, .chip_select = 0, .mode=SPI_MODE_3, }, };

FO

If another device is to be added, just add one member to spi_board_devs. But for mt6516, until now only one device is supported. modalias: the name of the device. It should be the same as the name of SPI device driver. So if the names are different, the device can’t be connected to SPI bus. bus_num: the bus number of the spi controller. For mt6516, this should be 0, because there is only one spi controller. chip_select: the chip select number of spi device. This also should be 0, because for mt6516, only one device is supported.

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 16

Kernel Space Functions

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.2

LY

MT6516 Chip Name Confidential B

3.2.1

spi_setup

Set SPI device parameters. Prototype

int spi_setup (struct spi_device *spi) Parameters

struct spi_device

spi

SPI device structure.

Return Value

controller_data; config->pause=1; spi->controller_data=config; spi_setup(spi);

3.2.2

spi_sync

Start SPI data transfers. Prototype

int spi_sync(struct spi_device *spi, struct spi_message *message) Parameters

Struct spi_device

spi

The SPI device

Struct spi_message

message

The message which will be transferred.

Return Value