2 * linux/drivers/l3/l3-bit-sa1100.c
4 * Copyright (C) 2001 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This is a combined I2C and L3 bus driver.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/ioport.h>
15 #include <linux/delay.h>
16 #include <linux/slab.h>
17 #include <linux/init.h>
18 #include <linux/i2c.h>
19 #include <linux/i2c-algo-bit.h>
20 #include <linux/l3/algo-bit.h>
22 #include <asm/system.h>
23 #include <asm/hardware.h>
24 #include <asm/mach-types.h>
25 #include <asm/arch/assabet.h>
27 #define NAME "l3-bit-sa1100-gpio"
35 static int getsda(void *data
)
37 struct bit_data
*bits
= data
;
39 return GPLR
& bits
->sda
;
42 #ifdef CONFIG_I2C_BIT_SA1100_GPIO
43 static void i2c_setsda(void *data
, int state
)
45 struct bit_data
*bits
= data
;
48 local_irq_save(flags
);
55 local_irq_restore(flags
);
58 static void i2c_setscl(void *data
, int state
)
60 struct bit_data
*bits
= data
;
63 local_irq_save(flags
);
70 local_irq_restore(flags
);
73 static int i2c_getscl(void *data
)
75 struct bit_data
*bits
= data
;
77 return GPLR
& bits
->scl
;
80 static struct i2c_algo_bit_data i2c_bit_data
= {
90 static struct i2c_adapter i2c_adapter
= {
91 .algo_data
= &i2c_bit_data
,
94 #define LOCK &i2c_adapter.bus_lock
96 static int __init
i2c_init(struct bit_data
*bits
)
98 i2c_bit_data
.data
= bits
;
99 return i2c_bit_add_bus(&i2c_adapter
);
102 static void i2c_exit(void)
104 i2c_bit_del_bus(&i2c_adapter
);
108 static DECLARE_MUTEX(l3_lock
);
109 #define LOCK &l3_lock
110 #define i2c_init(bits) (0)
111 #define i2c_exit() do { } while (0)
114 #ifdef CONFIG_L3_BIT_SA1100_GPIO
116 * iPAQs need the clock line driven hard high and low.
118 static void l3_setscl(void *data
, int state
)
120 struct bit_data
*bits
= data
;
123 local_irq_save(flags
);
129 local_irq_restore(flags
);
132 static void l3_setsda(void *data
, int state
)
134 struct bit_data
*bits
= data
;
142 static void l3_setdir(void *data
, int in
)
144 struct bit_data
*bits
= data
;
147 local_irq_save(flags
);
152 local_irq_restore(flags
);
155 static void l3_setmode(void *data
, int state
)
157 struct bit_data
*bits
= data
;
160 GPSR
= bits
->l3_mode
;
162 GPCR
= bits
->l3_mode
;
165 static struct l3_algo_bit_data l3_bit_data
= {
169 .setmode
= l3_setmode
,
179 static struct l3_adapter l3_adapter
= {
180 .owner
= THIS_MODULE
,
182 .algo_data
= &l3_bit_data
,
186 static int __init
l3_init(struct bit_data
*bits
)
188 l3_bit_data
.data
= bits
;
189 return l3_bit_add_bus(&l3_adapter
);
192 static void __exit
l3_exit(void)
194 l3_bit_del_bus(&l3_adapter
);
197 #define l3_init(bits) (0)
198 #define l3_exit() do { } while (0)
201 static struct bit_data bit_data
;
203 static int __init
bus_init(void)
205 struct bit_data
*bit
= &bit_data
;
209 if (machine_is_assabet() || machine_is_pangolin()) {
210 bit
->sda
= GPIO_GPIO15
;
211 bit
->scl
= GPIO_GPIO18
;
212 bit
->l3_mode
= GPIO_GPIO17
;
215 if (machine_is_h3600() || machine_is_h3100()) {
216 bit
->sda
= GPIO_GPIO14
;
217 bit
->scl
= GPIO_GPIO16
;
218 bit
->l3_mode
= GPIO_GPIO15
;
221 if (machine_is_stork()) {
222 bit
->sda
= GPIO_GPIO15
;
223 bit
->scl
= GPIO_GPIO18
;
224 bit
->l3_mode
= GPIO_GPIO17
;
231 * Default level for L3 mode is low.
232 * We set SCL and SDA high (i2c idle state).
234 local_irq_save(flags
);
235 GPDR
&= ~(bit
->scl
| bit
->sda
);
236 GPCR
= bit
->l3_mode
| bit
->scl
| bit
->sda
;
237 GPDR
|= bit
->l3_mode
;
238 local_irq_restore(flags
);
240 if (machine_is_assabet()) {
242 * Release reset on UCB1300, ADI7171 and UDA1341. We
243 * need to do this here so that we can communicate on
246 ASSABET_BCR_set(ASSABET_BCR_CODEC_RST
);
248 ASSABET_BCR_clear(ASSABET_BCR_CODEC_RST
);
250 ASSABET_BCR_set(ASSABET_BCR_CODEC_RST
);
254 if (ret
== 0 && bit
->l3_mode
) {
263 static void __exit
bus_exit(void)
269 module_init(bus_init
);
270 module_exit(bus_exit
);