Commit 8786b095 authored by Heiner Kallweit's avatar Heiner Kallweit Committed by Wolfram Sang

i2c: gpio: support write-only sda/scl w/o pull-up

There are slave devices that understand I2C but have read-only SDA and
SCL. Examples are FD650 7-segment LED controller and its derivatives.
Typical board designs don't even have a pull-up for both pins.
Handle the new attributes for write-only SDA and missing pull-up on
SDA/SCL.

For either pin the open-drain and has-no-pullup properties are
mutually-exclusive, what is documented in the DT property documentation.
We don't add an extra warning here because the open-drain properties
are marked deprecated anyway.
Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
[wsa: switched to device properties]
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 9dfee148
...@@ -317,6 +317,12 @@ static void i2c_gpio_get_properties(struct device *dev, ...@@ -317,6 +317,12 @@ static void i2c_gpio_get_properties(struct device *dev,
device_property_read_bool(dev, "i2c-gpio,scl-open-drain"); device_property_read_bool(dev, "i2c-gpio,scl-open-drain");
pdata->scl_is_output_only = pdata->scl_is_output_only =
device_property_read_bool(dev, "i2c-gpio,scl-output-only"); device_property_read_bool(dev, "i2c-gpio,scl-output-only");
pdata->sda_is_output_only =
device_property_read_bool(dev, "i2c-gpio,sda-output-only");
pdata->sda_has_no_pullup =
device_property_read_bool(dev, "i2c-gpio,sda-has-no-pullup");
pdata->scl_has_no_pullup =
device_property_read_bool(dev, "i2c-gpio,scl-has-no-pullup");
} }
static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, static struct gpio_desc *i2c_gpio_get_desc(struct device *dev,
...@@ -393,7 +399,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) ...@@ -393,7 +399,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
* handle them as we handle any other output. Else we enforce open * handle them as we handle any other output. Else we enforce open
* drain as this is required for an I2C bus. * drain as this is required for an I2C bus.
*/ */
if (pdata->sda_is_open_drain) if (pdata->sda_is_open_drain || pdata->sda_has_no_pullup)
gflags = GPIOD_OUT_HIGH; gflags = GPIOD_OUT_HIGH;
else else
gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; gflags = GPIOD_OUT_HIGH_OPEN_DRAIN;
...@@ -401,7 +407,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) ...@@ -401,7 +407,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
if (IS_ERR(priv->sda)) if (IS_ERR(priv->sda))
return PTR_ERR(priv->sda); return PTR_ERR(priv->sda);
if (pdata->scl_is_open_drain) if (pdata->scl_is_open_drain || pdata->scl_has_no_pullup)
gflags = GPIOD_OUT_HIGH; gflags = GPIOD_OUT_HIGH;
else else
gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; gflags = GPIOD_OUT_HIGH_OPEN_DRAIN;
...@@ -419,6 +425,7 @@ static int i2c_gpio_probe(struct platform_device *pdev) ...@@ -419,6 +425,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
if (!pdata->scl_is_output_only) if (!pdata->scl_is_output_only)
bit_data->getscl = i2c_gpio_getscl; bit_data->getscl = i2c_gpio_getscl;
if (!pdata->sda_is_output_only)
bit_data->getsda = i2c_gpio_getsda; bit_data->getsda = i2c_gpio_getsda;
if (pdata->udelay) if (pdata->udelay)
......
...@@ -16,16 +16,25 @@ ...@@ -16,16 +16,25 @@
* isn't actively driven high when setting the output value high. * isn't actively driven high when setting the output value high.
* gpio_get_value() must return the actual pin state even if the * gpio_get_value() must return the actual pin state even if the
* pin is configured as an output. * pin is configured as an output.
* @sda_is_output_only: SDA output drivers can't be turned off.
* This is for clients that can only read SDA/SCL.
* @sda_has_no_pullup: SDA is used in a non-compliant way and has no pull-up.
* Therefore disable open-drain.
* @scl_is_open_drain: SCL is set up as open drain. Same requirements * @scl_is_open_drain: SCL is set up as open drain. Same requirements
* as for sda_is_open_drain apply. * as for sda_is_open_drain apply.
* @scl_is_output_only: SCL output drivers cannot be turned off. * @scl_is_output_only: SCL output drivers cannot be turned off.
* @scl_has_no_pullup: SCL is used in a non-compliant way and has no pull-up.
* Therefore disable open-drain.
*/ */
struct i2c_gpio_platform_data { struct i2c_gpio_platform_data {
int udelay; int udelay;
int timeout; int timeout;
unsigned int sda_is_open_drain:1; unsigned int sda_is_open_drain:1;
unsigned int sda_is_output_only:1;
unsigned int sda_has_no_pullup:1;
unsigned int scl_is_open_drain:1; unsigned int scl_is_open_drain:1;
unsigned int scl_is_output_only:1; unsigned int scl_is_output_only:1;
unsigned int scl_has_no_pullup:1;
}; };
#endif /* _LINUX_I2C_GPIO_H */ #endif /* _LINUX_I2C_GPIO_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment