s5pc110: compiler warning removed
[kernel/u-boot.git] / drivers / video / s5p-spi.c
1 #include <common.h>
2 #include <asm/arch/gpio.h>
3 #include "s5p-spi.h"
4
5
6 static void cs_low(struct spi_platform_data *spi)
7 {
8         gpio_set_value(spi->cs_bank, spi->cs_num, 0);
9 }
10
11 static void cs_high(struct spi_platform_data *spi)
12 {
13         gpio_set_value(spi->cs_bank, spi->cs_num, 1);
14 }
15
16 static void clk_low(struct spi_platform_data *spi)
17 {
18         gpio_set_value(spi->clk_bank, spi->clk_num, 0);
19 }
20
21 static void clk_high(struct spi_platform_data *spi)
22 {
23         gpio_set_value(spi->clk_bank, spi->clk_num, 1);
24 }
25
26 static void si_low(struct spi_platform_data *spi)
27 {
28         gpio_set_value(spi->si_bank, spi->si_num, 0);
29 }
30
31 static void si_high(struct spi_platform_data *spi)
32 {
33         gpio_set_value(spi->si_bank, spi->si_num, 1);
34 }
35
36 /*
37 static char so_read(struct spi_platform_data *spi)
38 {
39         return gpio_get_value(spi->so_bank, spi->so_num);
40 }
41 */
42
43 void spi_write_byte(struct spi_platform_data *spi, unsigned char address, unsigned char command)
44 {
45         int     j;
46         unsigned short data;
47         unsigned char DELAY = 1;
48
49         data = (address << 8) + command;
50
51         cs_high(spi);
52         si_high(spi);
53         clk_high(spi);
54         udelay(DELAY);
55
56         cs_low(spi);
57         udelay(DELAY);
58
59         for (j = PACKET_LEN; j >= 0; j--) {
60                 clk_low(spi);
61
62                 /* data high or low */
63                 if ((data >> j) & 0x1)
64                         si_high(spi);
65                 else
66                         si_low(spi);
67
68                 udelay(DELAY);
69
70                 clk_high(spi);
71                 udelay(DELAY);
72         }
73
74         cs_high(spi);
75         udelay(DELAY);
76 }
77
78 #ifdef UNUSED_FUNCTIONS
79 unsigned char spi_read_byte(struct spi_platform_data *spi, unsigned char select, unsigned char address)
80 {
81         int     j;
82         static unsigned int first = 1;
83         unsigned char DELAY = 1;
84         unsigned short data = 0;
85         char command = 0;
86
87         data = (select << 8) + address;
88
89         cs_high(spi);
90         si_high(spi);
91         clk_high(spi);
92         udelay(DELAY);
93
94         clk_low(spi);
95         udelay(DELAY);
96
97         for (j = PACKET_LEN + 8; j >= 0; j--) {
98
99                 if (j > 7) {
100                         clk_low(spi);
101
102                         /* data high or low */
103                         if ((data >> (j - 8)) & 0x1)
104                                 si_high(spi);
105                         else
106                                 si_low(spi);
107
108                         udelay(DELAY);
109                         clk_high(spi);
110                 } else {
111                         if (first) {
112                                 gpio_cfg_pin(spi->so_bank, spi->so_num, GPIO_INPUT);
113                                 first = 0;
114                         }
115
116                         clk_low(spi);
117
118                         if (so_read(spi) & 0x1)
119                                 command |= 1 << j;
120                         else
121                                 command |= 0 << j;
122
123                         udelay(DELAY);
124                         clk_high(spi);
125                 }
126
127                 udelay(DELAY);
128         }
129
130         cs_high(spi);
131         udelay(DELAY);
132
133         gpio_cfg_pin(spi->so_bank, spi->so_num, GPIO_OUTPUT);
134
135         return command;
136 }
137 #endif