tizen 2.4 release
[kernel/u-boot-tm1.git] / drivers / video / sc8825fb / sprdfb_spi.c
1 /*\r
2  * Copyright (C) 2012 Spreadtrum Communications Inc.\r
3  *\r
4  * This software is licensed under the terms of the GNU General Public\r
5  * License version 2, as published by the Free Software Foundation, and\r
6  * may be copied, distributed, and modified under those terms.\r
7  *\r
8  * This program is distributed in the hope that it will be useful,\r
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
11  * GNU General Public License for more details.\r
12  */\r
13 #include <common.h>\r
14 #include <asm/arch/sci_types.h>\r
15 #include <asm/arch/tiger_lcd.h>\r
16 #include <asm/arch/sc8825_spi.h>\r
17 \r
18 #include "sprdfb.h"\r
19 \r
20 \r
21  SPI_INIT_PARM spi_int_parm[] =\r
22  {\r
23         {\r
24          TX_POS_EDGE,\r
25          RX_NEG_EDGE,\r
26          TX_RX_MSB,\r
27          RX_TX_MODE,\r
28          NO_SWITCH,\r
29          MASTER_MODE,\r
30          0x0,\r
31          0x0,\r
32          0xF0, //clk_div:(n+1)*2\r
33          0x0, //data_width.0-32bits per word; n-nbits per word\r
34          0x0,\r
35          SPI_TX_FIFO_DEPTH - 1,\r
36          0x0,\r
37          SPI_RX_FIFO_DEPTH - 1\r
38          },  //for spi_lcm test\r
39         //{TX_POS_EDGE,RX_NEG_EDGE,TX_RX_LSB,RX_TX_MODE,NO_SWITCH,SLAVE_MODE,0x0,0x0,0xF0,0x0,0x0,SPI_TX_FIFO_DEPTH - 1,0x0,SPI_RX_FIFO_DEPTH - 1},\r
40  };\r
41 \r
42 \r
43  /**---------------------------------------------------------------------------*\r
44  **                 SPI Interface for LCM test case  depend on spi_drv.c      *\r
45  **---------------------------------------------------------------------------*/\r
46 //CASE1: \r
47 // --------------------------------------------------------------------------- //\r
48 //  Description:   configure the start byte\r
49 //      Global resource dependence: \r
50 //  Author:         lichd\r
51 //  Note  : LCM test code \r
52 // --------------------------------------------------------------------------- //\r
53 \r
54 static void DISPC_SpiWriteCmd(uint32_t cmd)\r
55 {\r
56         SPI_SetDatawidth(8);\r
57         SPI_SetCsLow(0, FALSE);\r
58         {\r
59                 uint32_t i=0;\r
60                 for(i=0; i<1000; i++);\r
61         }\r
62 \r
63         SPI_SetCsLow(0, TRUE);\r
64         SPI_SetCd( 0 );\r
65 \r
66         // Write a data identical with buswidth\r
67         SPI_WriteData( cmd, 1, 0);\r
68 \r
69 }\r
70 \r
71 static void DISPC_SpiWriteData(uint32_t data)\r
72 {\r
73         SPI_SetDatawidth(8);\r
74 \r
75         SPI_SetCd( 1 );\r
76 \r
77         // Write a data identical with buswidth\r
78         SPI_WriteData( data, 1, 0);\r
79 \r
80 }\r
81 \r
82 static void SPI_Read( uint32_t* data)\r
83 {\r
84         uint32_t lcm_id=0;\r
85 \r
86         SPI_SetDatawidth(8);\r
87 \r
88         //Read data 16bits\r
89         lcm_id = SPI_ReadData(1, 0);  //unit of buswidth\r
90         {\r
91                 uint32_t i=0;\r
92                 for(i=0; i<1000; i++);\r
93         }\r
94         SPI_SetCsLow(0, FALSE);\r
95 \r
96         *data = lcm_id;\r
97 }\r
98 \r
99 void SPI_PinCfg( void )\r
100 {\r
101         /*enable access the spi reg*/\r
102         *((volatile uint32 *)(0x4b000008)) |= BIT_1;\r
103         *((volatile uint32 *)(0x4b0000c0)) |= BIT_0;\r
104 /*\r
105         //select spi0_2\r
106         CHIP_REG_SET (PIN_LCD_D6_REG, (PIN_FPD_EN | PIN_FUNC_1 | PIN_O_EN)); //SPI0_2_CD\r
107         CHIP_REG_SET (PIN_LCD_RDN_REG, (PIN_FPD_EN | PIN_FUNC_1 | PIN_I_EN)); //SPI0_2_DI\r
108         CHIP_REG_SET (PIN_LCD_WRN_REG, (PIN_FPD_EN | PIN_FUNC_1 | PIN_O_EN)); //SPI0_2_DO\r
109         CHIP_REG_SET (PIN_LCD_CD_REG, (PIN_FPD_EN | PIN_FUNC_1 | PIN_O_EN)); //SPI0_2_CLK\r
110         CHIP_REG_SET (PIN_LCD_CSN0_REG, (PIN_FPD_EN | PIN_FUNC_1 | PIN_O_EN)); //SPI0_2_CS0\r
111 */\r
112 #if 0\r
113         TB_REG_OR(GEN0, (1 << 13));\r
114 \r
115         //select spi0_1\r
116         TB_REG_SET (PIN_LCD_D0_REG, (PIN_DS_2 | PIN_FUNC_1 )); //SPI0_1_DI\r
117         TB_REG_SET (PIN_LCD_D1_REG, (PIN_DS_2 | PIN_FUNC_1 )); //SPI0_1_DO\r
118         TB_REG_SET (PIN_LCD_D2_REG, (PIN_DS_2 | PIN_FUNC_1 )); //SPI0_1_CLK     \r
119         TB_REG_SET (PIN_LCD_D3_REG, (PIN_DS_2 | PIN_FUNC_1 )); //SPI0_1_CS0    \r
120         TB_REG_SET (PIN_LCD_D4_REG, (PIN_DS_2 | PIN_FUNC_1 )); //SPI0_1_CS1       \r
121         TB_REG_SET (PIN_LCD_D5_REG, (PIN_DS_2 | PIN_FUNC_1 )); //SPI0_1_CD \r
122 \r
123         // \r
124         TB_REG_AND(PIN_CTL_REG, ~(BIT_29|BIT_30));\r
125         TB_REG_OR(PIN_CTL_REG, (1<<29));\r
126 #endif\r
127 }\r
128 \r
129 BOOLEAN sprdfb_spi_init(struct sprdfb_device *dev)\r
130 {\r
131         SPI_Enable(SPI_USED_ID, TRUE);\r
132         SPI_Init( spi_int_parm);\r
133 \r
134         SPI_ClkSetting( SPI_USED_ID, SPICLK_SEL_192M, 0);\r
135         SPI_SetDatawidth(8);\r
136         return TRUE;\r
137 }\r
138 \r
139 BOOLEAN sprdfb_spi_uninit(struct sprdfb_device *dev)\r
140 {\r
141         return TRUE;\r
142 }\r
143 \r
144 struct ops_spi sprdfb_spi_ops = {\r
145         .spi_send_cmd = DISPC_SpiWriteCmd,\r
146         .spi_send_data = DISPC_SpiWriteData,\r
147         .spi_read = SPI_Read,\r
148 };\r
149 \r
150 \r