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