| 1 | /* |
| 2 | * (C) Copyright 2007 OpenMoko, Inc. |
| 3 | * Author: Andy Green <andy@openmoko.com> |
| 4 | * |
| 5 | * s3c24xx-specific i2c used by, eg, GTA02 |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <qi.h> |
| 25 | #include <i2c-bitbang.h> |
| 26 | #include <ports-s3c24xx.h> |
| 27 | |
| 28 | static char i2c_read_sda_s3c24xx(void) |
| 29 | { |
| 30 | return (rGPEDAT & 0x8000) != 0; |
| 31 | } |
| 32 | |
| 33 | static void i2c_set_s3c24xx(char clock, char data) |
| 34 | { |
| 35 | if (clock) /* SCL <- input */ |
| 36 | rGPECON = (rGPECON & ~0x30000000); |
| 37 | else { /* SCL <- output 0 */ |
| 38 | rGPEDAT = (rGPEDAT & ~0x4000); |
| 39 | rGPECON = (rGPECON & ~0x30000000) | 0x10000000; |
| 40 | } |
| 41 | if (data) /* SDA <- input */ |
| 42 | rGPECON = (rGPECON & ~0xc0000000); |
| 43 | else { /* SDA <- output 0 */ |
| 44 | rGPEDAT = (rGPEDAT & ~0x8000); |
| 45 | rGPECON = (rGPECON & ~0xc0000000) | 0x40000000; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | static void i2c_close_s3c24xx(void) |
| 50 | { |
| 51 | /* set back to hardware I2C ready for Linux */ |
| 52 | rGPECON = (rGPECON & ~0xf0000000) | 0xa0000000; |
| 53 | } |
| 54 | |
| 55 | static void i2c_spin_s3c24xx(void) |
| 56 | { |
| 57 | int n; |
| 58 | |
| 59 | for (n = 0; n < 1000; n++) |
| 60 | rGPJDAT |= (1 << 5); |
| 61 | } |
| 62 | |
| 63 | struct i2c_bitbang bb_s3c24xx = { |
| 64 | .read_sda = i2c_read_sda_s3c24xx, |
| 65 | .set = i2c_set_s3c24xx, |
| 66 | .spin = i2c_spin_s3c24xx, |
| 67 | .close = i2c_close_s3c24xx, |
| 68 | }; |
| 69 | |