⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdspi.c

📁 Samsung LCD驱动(SPI接口)
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/ctype.h>#include <linux/mm.h>#include <linux/init.h>#include <linux/delay.h>#include <asm/system.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/uaccess.h>#include "regs-pxa.h"//#include "lcdspi.h"#define DEBUG#ifdef DEBUG	#define DEBUG_LCDSPI		1#else	#define DEBUG_LCDSPI		0#endif#define Samsung_22#define KERN_LEVEL		KERN_INFO	/* refer to kernel.h*/#if DEBUG_LCDSPI	#define DPRINTK(fmt, args...)	printk(KERN_LEVEL "<%s:%d> %s : " fmt "\n", __FILE__, __LINE__ , __FUNCTION__, ## args)#else	#define DPRINTK(fmt, args...)#endif#define SHOW_FUNCTION_ENTRY	DPRINTK("Begin >>>\n")#define SHOW_FUNCTION_EXIT	DPRINTK("      <<< End\n")#if defined(CONFIG_LCD_LG)	#define DEVICE_ID	(0x1C | 1)//#elif defined(CONFIG_LCD_TRULY)#else	#define DEVICE_ID	(0x10)#endif#define RS_INDEX_REGISTER	0#define RS_CONTROL_REGISTER	1#define RW_WRITE		0#define RW_READ			1#define START_BYTE(rs, rw)	((DEVICE_ID<<2) | (rs<<1) | rw)#define HW_START_FRAME		(GPCR2 |= GPIO_bit(83)); udelay(2)	//GPIO_bit(83)== 0x00080000#define HW_STOP_FRAME		(GPSR2 |= GPIO_bit(83)); udelay(2) //GPIO_bit(83)== 0x00080000#define HW_SPI_TX_BUSY		((SSP3_SSSR) & 0x10)#define HW_SPI_RX_BUSY		0#define HW_SPI_FIFO_NOT_EMPTY	((SSP3_SSSR) & 0x08)/*********************************************************************** Function:         ssp3_init* Description:      initialize SSP3** Input:            none* Output:           none* Return:           0:success* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-5-31       V1.0      XZC           Create**********************************************************************/static int ssp3_init(void){	SHOW_FUNCTION_ENTRY;	/* Set GPIO */	//SSP_TXD & SSP_SFRM & SSP_CLK are output	GPDR2 |= (GPIO_bit(81) | GPIO_bit(83) | GPIO_bit(52));	//SSP_RXD is input	GPDR2 &= ~GPIO_bit(82);	//SSP port is function 1	GAFR2_U &= ~(GPIO_81_AF3 | GPIO_83_AF3 | GPIO_83_AF3);	//2 INIT Option 1: SSPSFRM3 can be driven manually by GPIO or automatically by SSP	GAFR2_U |= (GPIO_81_AF1_SSPTXD3 | GPIO_82_AF1_SSPRXD3);	//GAFR2_U |= (GPIO_81_AF1_SSPTXD3 | GPIO_82_AF1_SSPRXD3 | GPIO_83_AF1_SSPSFRM3);	GAFR1_U &= ~GPIO_52_AF3;	GAFR1_U |= GPIO_52_AF2_SSPCLK3;	GPSR2 |= GPIO_bit(83);	//select on-chip clock	SSP3_SSCR0 &= ~SPI_ECS;	//2 INIT Option 2: SPI bit rate	//SPI bit rate = SSPCLK/SCR+1	//SSP3_SSCR0 |= SPI_SCR(2);	SSP3_SSCR0 |= SPI_SCR(4095);	//choose spi frame format	SSP3_SSCR0 |= SPI_FRF(0);	//spi	//2 INIT Option 3: SPI data width	//select spi data width, 8	SSP3_SSCR0 &= ~SPI_EDSS;	SSP3_SSCR0 |= SPI_DSS(7);	//2 INIT Option 4: SSPCLK idle mode and phase against SSPSFRM	//SSP3_SSCR1 &= ~SPI_SPO;	//SSP3_SSCR1 &= ~SPI_SPH;	SSP3_SSCR1 |= SPI_SPO;	SSP3_SSCR1 |= SPI_SPH;	SSP3_SSCR1 &= ~SPI_MWDS;	//8-bit command word is transmitted,microwire protocol	SSP3_SSCR1 |= SPI_TFT(2);	//transmit FIFO threshold	SSP3_SSCR1 |= SPI_RFT(7);	//receive FIFO threshold	//set loopback mode	SSP3_SSCR1 &= ~SPI_LBM;	//disable transmit/receive interupt	SSP3_SSCR1 &= ~SPI_TIE;	SSP3_SSCR1 &= ~SPI_RIE;	//disable DMA	//SSP3_SSCR1 &= ~SPI_RSRE;	//SSP3_SSCR1 &= ~SPI_TSRE;	//2 INIT Option 5: end of transfer data state, 0 = low, 1 = last value<bit 0>	//SSP3_SSPSP &= ~SPI_ETDS;	SSP3_SSPSP |= SPI_ETDS;	//2 INIT Option 6: Invert Frame Signal	SSP3_SSCR1 &= ~SPI_IFS;	//SSP3_SSCR1 |= SPI_IFS;	SHOW_FUNCTION_EXIT;	return 0;}/*********************************************************************** Function:         ssp3_enable* Description:      enable SSP3** Input:            none* Output:           none* Return:           0:success* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-08-05       V1.0      XZC           Create* 2004-08-05       V1.1      XZC           Add call of ssp3_init**********************************************************************/void ssp3_enable(void){	SHOW_FUNCTION_ENTRY;	//if (0 == SSP3_SSCR0)	if (!(SSP3_SSCR0 & SPI_SSE))		ssp3_init();	//enable SPI	SSP3_SSCR0 |= SPI_SSE;	//clock enable	CKEN |= CKEN4_SSP3;//	DPRINTK("SSP3_SSCR0 = 0x%x\n", SSP3_SSCR0);//	DPRINTK("SSP3_SSCR1 = 0x%x\n", SSP3_SSCR1);	SHOW_FUNCTION_EXIT;}/*********************************************************************** Function:         ssp3_enable* Description:      disable SSP3** Input:            none* Output:           none* Return:           0:success* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-08-05       V1.0      XZC           Create**********************************************************************/void ssp3_disable(void){	SHOW_FUNCTION_ENTRY;	//disable SPI	SSP3_SSCR0 &= ~SPI_SSE;	//clock disable	CKEN &= ~CKEN4_SSP3;	SHOW_FUNCTION_EXIT;}/*********************************************************************** Function:         spi_transaction* Description:      implement SPI protocol for transaction** Input:            p_data - pointer to source data*                   count - count of source data* Output:           none* Return:           0:success* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-5-31       V1.0      XZC           Create**********************************************************************/static int spi_transaction(unsigned char *p_data, unsigned short count){	unsigned short i;	unsigned char temp;	HW_START_FRAME;	while (HW_SPI_TX_BUSY) { udelay(2); }	for (i = 0; i < count; i++)	{		temp = p_data[i];		SSP3_SSDR = temp;		printk("%02x is transmitted, ", temp);		udelay(2);		while (HW_SPI_TX_BUSY) { udelay(2); }		while (HW_SPI_RX_BUSY) { udelay(2); }		temp = (unsigned char)SSP3_SSDR;		printk("%02x is received\n", temp);		udelay(2);		if (i != 0)		{			p_data[i] = temp;		}		udelay(20);	}	while (HW_SPI_FIFO_NOT_EMPTY) // make sure getting latest data	{		temp = (unsigned char)SSP3_SSDR;		printk("%02x is received in HW_SPI_FIFO_NOT_EMPTY\n", temp);		for (i = 0; i < (count - 1); i++)		{			p_data[i] = p_data[i+1];		}		p_data[count-1] = temp;		udelay(20);	}	HW_STOP_FRAME;	udelay(20);	return 0;}/*********************************************************************** Function:         spi_select_register* Description:      operation of selecting register** Input:            index - index of target register* Output:           none* Return:           data in the register* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-5-31       V1.0      XZC           Create**********************************************************************/void spi_select_register(unsigned short index){	unsigned char bytes[3]={0,0,0};	bytes[0] = START_BYTE(RS_INDEX_REGISTER, RW_WRITE);	// = 0x74	bytes[1] = (unsigned char)(index>>8);	bytes[2] = (unsigned char)index;	spi_transaction(bytes,3);}/*********************************************************************** Function:         spi_read_register* Description:      read data from LCD register** Input:            index - index of target register* Output:           none* Return:           data in the register* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-5-31       V1.0      XZC           Create**********************************************************************/unsigned short spi_read_register(unsigned short index){	unsigned short data = 0;	unsigned char bytes[4] = {0,0,0,0};	/* select register */	spi_select_register(index);	/* receive data */	bytes[0] = START_BYTE(RS_CONTROL_REGISTER, RW_READ);	// = 0x77	spi_transaction(bytes,4);	data = (bytes[2]<<8) | bytes[3];	return data;}/*********************************************************************** Function:         spi_write_register* Description:      write data to LCD register** Input:            index - index of target register*                   data - data to write into register* Output:           none* Return:           none* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-5-31       V1.0      XZC           Create**********************************************************************/void spi_write_register(unsigned short index, unsigned short data){	unsigned char bytes[3] = {0,0,0};	/* select register */	spi_select_register(index);	/* send data */	bytes[0] = START_BYTE(RS_CONTROL_REGISTER, RW_WRITE);	// = 0x76	bytes[1] = (unsigned char)(data>>8);	bytes[2] = (unsigned char)data;	spi_transaction(bytes,3);}/*********************************************************************** Function:         spi_write_gram* Description:      write data to LCD GRAM** Input:            data - data to write into GRAM* Output:           none* Return:           none* Others:           none* Modify Date    Version    Author        Modification* -----------------------------------------------* 2004-5-31       V1.0      XZC           Create**********************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -