]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/i2c/busses/scx200_i2c.c
Merge remote-tracking branches 'spi/fix/au1550', 'spi/fix/cadence', 'spi/fix/omap2...
[mirror_ubuntu-artful-kernel.git] / drivers / i2c / busses / scx200_i2c.c
CommitLineData
f30c2269 1/* linux/drivers/i2c/busses/scx200_i2c.c
1da177e4
LT
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
401e72b5
JC
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
1da177e4
LT
26#include <linux/module.h>
27#include <linux/errno.h>
28#include <linux/kernel.h>
1da177e4
LT
29#include <linux/i2c.h>
30#include <linux/i2c-algo-bit.h>
21782180 31#include <linux/io.h>
1da177e4
LT
32
33#include <linux/scx200_gpio.h>
34
1da177e4
LT
35MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
36MODULE_DESCRIPTION("NatSemi SCx200 I2C Driver");
37MODULE_LICENSE("GPL");
38
39static int scl = CONFIG_SCx200_I2C_SCL;
40static int sda = CONFIG_SCx200_I2C_SDA;
41
42module_param(scl, int, 0);
43MODULE_PARM_DESC(scl, "GPIO line for SCL");
44module_param(sda, int, 0);
45MODULE_PARM_DESC(sda, "GPIO line for SDA");
46
47static void scx200_i2c_setscl(void *data, int state)
48{
49 scx200_gpio_set(scl, state);
50}
51
52static void scx200_i2c_setsda(void *data, int state)
53{
54 scx200_gpio_set(sda, state);
55}
56
57static int scx200_i2c_getscl(void *data)
58{
59 return scx200_gpio_get(scl);
60}
61
62static int scx200_i2c_getsda(void *data)
63{
64 return scx200_gpio_get(sda);
65}
66
67/* ------------------------------------------------------------------------
68 * Encapsulate the above functions in the correct operations structure.
69 * This is only done when more than one hardware adapter is supported.
70 */
71
72static struct i2c_algo_bit_data scx200_i2c_data = {
a0d9c63d
JD
73 .setsda = scx200_i2c_setsda,
74 .setscl = scx200_i2c_setscl,
75 .getsda = scx200_i2c_getsda,
76 .getscl = scx200_i2c_getscl,
77 .udelay = 10,
082a4cf8 78 .timeout = HZ,
1da177e4
LT
79};
80
81static struct i2c_adapter scx200_i2c_ops = {
82 .owner = THIS_MODULE,
4a029abe 83 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
1da177e4
LT
84 .algo_data = &scx200_i2c_data,
85 .name = "NatSemi SCx200 I2C",
86};
87
88static int scx200_i2c_init(void)
89{
401e72b5 90 pr_debug("NatSemi SCx200 I2C Driver\n");
1da177e4
LT
91
92 if (!scx200_gpio_present()) {
401e72b5 93 pr_err("no SCx200 gpio pins available\n");
1da177e4
LT
94 return -ENODEV;
95 }
96
401e72b5 97 pr_debug("SCL=GPIO%02u, SDA=GPIO%02u\n", scl, sda);
1da177e4
LT
98
99 if (scl == -1 || sda == -1 || scl == sda) {
401e72b5 100 pr_err("scl and sda must be specified\n");
1da177e4
LT
101 return -EINVAL;
102 }
103
104 /* Configure GPIOs as open collector outputs */
105 scx200_gpio_configure(scl, ~2, 5);
106 scx200_gpio_configure(sda, ~2, 5);
107
108 if (i2c_bit_add_bus(&scx200_i2c_ops) < 0) {
401e72b5 109 pr_err("adapter %s registration failed\n", scx200_i2c_ops.name);
1da177e4
LT
110 return -ENODEV;
111 }
112
113 return 0;
114}
115
116static void scx200_i2c_cleanup(void)
117{
3269711b 118 i2c_del_adapter(&scx200_i2c_ops);
1da177e4
LT
119}
120
121module_init(scx200_i2c_init);
122module_exit(scx200_i2c_cleanup);
123
124/*
125 Local variables:
126 compile-command: "make -k -C ../.. SUBDIRS=drivers/i2c modules"
127 c-basic-offset: 8
128 End:
129*/