Root/qiboot/src/cpu/s3c6410/i2c-bitbang-s3c6410.c

1/*
2 * (C) Copyright 2007 OpenMoko, Inc.
3 * Author: Andy Green <andy@openmoko.com>
4 *
5 * s3c6410-specific i2c
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 <s3c6410.h>
27
28static char i2c_read_sda_s3c6410(void)
29{
30    return !!(__REG(GPBDAT) & (1 << 6));
31}
32
33static void i2c_set_s3c6410(char clock, char data)
34{
35    if (clock) /* SCL <- input */
36        __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (5 * 4)));
37    else { /* SCL <- output 0 */
38        __REG(GPBDAT) = (__REG(GPBDAT) & ~(1 << 5));
39        __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (5 * 4))) | (1 << (5 * 4));
40    }
41    if (data) /* SDA <- input */
42        __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (6 * 4)));
43    else { /* SDA <- output 0 */
44        __REG(GPBDAT) = (__REG(GPBDAT) & ~(1 << 6));
45        __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (6 * 4))) | (1 << (6 * 4));
46    }
47}
48
49static void i2c_close_s3c6410(void)
50{
51    /* set back to hardware I2C ready for Linux */
52    __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (5 * 4))) | (2 << (5 * 4));
53    __REG(GPBCON) = (__REG(GPBCON) & ~(3 << (6 * 4))) | (2 << (6 * 4));
54}
55
56static void i2c_spin_s3c6410(void)
57{
58    int n;
59
60    for (n = 0; n < 1000; n++)
61        __REG(GPBDAT) = __REG(GPBDAT);
62}
63
64struct i2c_bitbang bb_s3c6410 = {
65    .read_sda = i2c_read_sda_s3c6410,
66    .set = i2c_set_s3c6410,
67    .spin = i2c_spin_s3c6410,
68    .close = i2c_close_s3c6410,
69};
70

Archive Download this file



interactive