OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [i2c/] [scx200_i2c.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* linux/drivers/i2c/scx200_i2c.c
2
 
3
   Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
4
 
5
   National Semiconductor SCx200 I2C bus on GPIO pins
6
 
7
   Based on i2c-velleman.c Copyright (C) 1995-96, 2000 Simon G. Vogl
8
 
9
   This program is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 2 of the License, or
12
   (at your option) any later version.
13
 
14
   This program is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
 
19
   You should have received a copy of the GNU General Public License
20
   along with this program; if not, write to the Free Software
21
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
*/
23
 
24
#include <linux/config.h>
25
#include <linux/module.h>
26
#include <linux/errno.h>
27
#include <linux/kernel.h>
28
#include <linux/init.h>
29
#include <linux/i2c.h>
30
#include <linux/i2c-algo-bit.h>
31
#include <asm/io.h>
32
 
33
#include <linux/scx200_gpio.h>
34
 
35
#define NAME "scx200_i2c"
36
 
37
MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
38
MODULE_DESCRIPTION("NatSemi SCx200 I2C Driver");
39
MODULE_LICENSE("GPL");
40
 
41
MODULE_PARM(scl, "i");
42
MODULE_PARM_DESC(scl, "GPIO line for SCL");
43
MODULE_PARM(sda, "i");
44
MODULE_PARM_DESC(sda, "GPIO line for SDA");
45
 
46
static int scl = CONFIG_SCx200_I2C_SCL;
47
static int sda = CONFIG_SCx200_I2C_SDA;
48
 
49
static void scx200_i2c_setscl(void *data, int state)
50
{
51
        scx200_gpio_set(scl, state);
52
}
53
 
54
static void scx200_i2c_setsda(void *data, int state)
55
{
56
        scx200_gpio_set(sda, state);
57
}
58
 
59
static int scx200_i2c_getscl(void *data)
60
{
61
        return scx200_gpio_get(scl);
62
}
63
 
64
static int scx200_i2c_getsda(void *data)
65
{
66
        return scx200_gpio_get(sda);
67
}
68
 
69
static int scx200_i2c_reg(struct i2c_client *client)
70
{
71
        return 0;
72
}
73
 
74
static int scx200_i2c_unreg(struct i2c_client *client)
75
{
76
        return 0;
77
}
78
 
79
static void scx200_i2c_inc_use(struct i2c_adapter *adap)
80
{
81
        MOD_INC_USE_COUNT;
82
}
83
 
84
static void scx200_i2c_dec_use(struct i2c_adapter *adap)
85
{
86
        MOD_DEC_USE_COUNT;
87
}
88
 
89
/* ------------------------------------------------------------------------
90
 * Encapsulate the above functions in the correct operations structure.
91
 * This is only done when more than one hardware adapter is supported.
92
 */
93
 
94
static struct i2c_algo_bit_data scx200_i2c_data = {
95
        NULL,
96
        scx200_i2c_setsda,
97
        scx200_i2c_setscl,
98
        scx200_i2c_getsda,
99
        scx200_i2c_getscl,
100
        10, 10, 100,            /* waits, timeout */
101
};
102
 
103
static struct i2c_adapter scx200_i2c_ops = {
104
        .name              = "NatSemi SCx200 I2C",
105
        .id                = I2C_HW_B_VELLE,
106
        .algo_data         = &scx200_i2c_data,
107
        .inc_use           = scx200_i2c_inc_use,
108
        .dec_use           = scx200_i2c_dec_use,
109
        .client_register   = scx200_i2c_reg,
110
        .client_unregister = scx200_i2c_unreg,
111
};
112
 
113
int scx200_i2c_init(void)
114
{
115
        printk(KERN_DEBUG NAME ": NatSemi SCx200 I2C Driver\n");
116
 
117
        if (!scx200_gpio_present()) {
118
                printk(KERN_ERR NAME ": no SCx200 gpio pins available\n");
119
                return -ENODEV;
120
        }
121
 
122
        printk(KERN_DEBUG NAME ": SCL=GPIO%02u, SDA=GPIO%02u\n",
123
               scl, sda);
124
 
125
        if (scl == -1 || sda == -1 || scl == sda) {
126
                printk(KERN_ERR NAME ": scl and sda must be specified\n");
127
                return -EINVAL;
128
        }
129
 
130
        /* Configure GPIOs as open collector outputs */
131
        scx200_gpio_configure(scl, ~2, 5);
132
        scx200_gpio_configure(sda, ~2, 5);
133
 
134
        if (i2c_bit_add_bus(&scx200_i2c_ops) < 0) {
135
                printk(KERN_ERR NAME ": adapter %s registration failed\n",
136
                       scx200_i2c_ops.name);
137
                return -ENODEV;
138
        }
139
 
140
        return 0;
141
}
142
 
143
void scx200_i2c_cleanup(void)
144
{
145
        i2c_bit_del_bus(&scx200_i2c_ops);
146
}
147
 
148
module_init(scx200_i2c_init);
149
module_exit(scx200_i2c_cleanup);
150
 
151
/*
152
    Local variables:
153
        compile-command: "make -k -C ../.. SUBDIRS=drivers/i2c modules"
154
        c-basic-offset: 8
155
    End:
156
*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.