2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
i2c: Bitbanging I2C bus driver using the GPIO API
This is a very simple bitbanging I2C bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
I2C controller, additional I2C busses, or testing purposes.
To use, include something similar to the following in the
board-specific setup code:
#include <linux/i2c-gpio.h>
static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin = GPIO_PIN_FOO,
.scl_pin = GPIO_PIN_BAR,
};
static struct platform_device i2c_gpio_device = {
.name = "i2c-gpio",
.id = 0,
.dev = {
.platform_data = &i2c_gpio_data,
},
};
Register this platform_device, set up the I2C pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 05:26:34 +08:00
|
|
|
/*
|
|
|
|
* i2c-gpio interface to platform code
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Atmel Corporation
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_I2C_GPIO_H
|
|
|
|
#define _LINUX_I2C_GPIO_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio
|
|
|
|
* @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz
|
|
|
|
* @timeout: clock stretching timeout in jiffies. If the slave keeps
|
|
|
|
* SCL low for longer than this, the transfer will time out.
|
|
|
|
* @sda_is_open_drain: SDA is configured as open drain, i.e. the pin
|
|
|
|
* isn't actively driven high when setting the output value high.
|
|
|
|
* gpio_get_value() must return the actual pin state even if the
|
|
|
|
* pin is configured as an output.
|
|
|
|
* @scl_is_open_drain: SCL is set up as open drain. Same requirements
|
|
|
|
* as for sda_is_open_drain apply.
|
|
|
|
* @scl_is_output_only: SCL output drivers cannot be turned off.
|
|
|
|
*/
|
|
|
|
struct i2c_gpio_platform_data {
|
|
|
|
int udelay;
|
|
|
|
int timeout;
|
|
|
|
unsigned int sda_is_open_drain:1;
|
|
|
|
unsigned int scl_is_open_drain:1;
|
|
|
|
unsigned int scl_is_output_only:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _LINUX_I2C_GPIO_H */
|