i2c: cleanup i2c_register_adapter() by refactoring recovery init
Move recovery init to a seperate function to let have i2c_register_adapter() less lines and to avoid goto and a label. Refactor string handling there for consistency and to save some bytes. Signed-off-by: Wolfram Sang <wsa-dev@sang-engineering.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
This commit is contained in:
parent
ce0dffafd4
commit
d3b11d8380
|
@ -666,6 +666,47 @@ int i2c_recover_bus(struct i2c_adapter *adap)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(i2c_recover_bus);
|
EXPORT_SYMBOL_GPL(i2c_recover_bus);
|
||||||
|
|
||||||
|
static void i2c_init_recovery(struct i2c_adapter *adap)
|
||||||
|
{
|
||||||
|
struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
|
||||||
|
char *err_str;
|
||||||
|
|
||||||
|
if (!bri)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!bri->recover_bus) {
|
||||||
|
err_str = "no recover_bus() found";
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generic GPIO recovery */
|
||||||
|
if (bri->recover_bus == i2c_generic_gpio_recovery) {
|
||||||
|
if (!gpio_is_valid(bri->scl_gpio)) {
|
||||||
|
err_str = "invalid SCL gpio";
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gpio_is_valid(bri->sda_gpio))
|
||||||
|
bri->get_sda = get_sda_gpio_value;
|
||||||
|
else
|
||||||
|
bri->get_sda = NULL;
|
||||||
|
|
||||||
|
bri->get_scl = get_scl_gpio_value;
|
||||||
|
bri->set_scl = set_scl_gpio_value;
|
||||||
|
} else if (bri->recover_bus == i2c_generic_scl_recovery) {
|
||||||
|
/* Generic SCL recovery */
|
||||||
|
if (!bri->set_scl || !bri->get_scl) {
|
||||||
|
err_str = "no {get|set}_scl() found";
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
err:
|
||||||
|
dev_err(&adap->dev, "Not using recovery: %s\n", err_str);
|
||||||
|
adap->bus_recovery_info = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int i2c_device_probe(struct device *dev)
|
static int i2c_device_probe(struct device *dev)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = i2c_verify_client(dev);
|
struct i2c_client *client = i2c_verify_client(dev);
|
||||||
|
@ -1610,41 +1651,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
|
||||||
"Failed to create compatibility class link\n");
|
"Failed to create compatibility class link\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* bus recovery specific initialization */
|
i2c_init_recovery(adap);
|
||||||
if (adap->bus_recovery_info) {
|
|
||||||
struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
|
|
||||||
|
|
||||||
if (!bri->recover_bus) {
|
|
||||||
dev_err(&adap->dev, "No recover_bus() found, not using recovery\n");
|
|
||||||
adap->bus_recovery_info = NULL;
|
|
||||||
goto exit_recovery;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generic GPIO recovery */
|
|
||||||
if (bri->recover_bus == i2c_generic_gpio_recovery) {
|
|
||||||
if (!gpio_is_valid(bri->scl_gpio)) {
|
|
||||||
dev_err(&adap->dev, "Invalid SCL gpio, not using recovery\n");
|
|
||||||
adap->bus_recovery_info = NULL;
|
|
||||||
goto exit_recovery;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gpio_is_valid(bri->sda_gpio))
|
|
||||||
bri->get_sda = get_sda_gpio_value;
|
|
||||||
else
|
|
||||||
bri->get_sda = NULL;
|
|
||||||
|
|
||||||
bri->get_scl = get_scl_gpio_value;
|
|
||||||
bri->set_scl = set_scl_gpio_value;
|
|
||||||
} else if (bri->recover_bus == i2c_generic_scl_recovery) {
|
|
||||||
/* Generic SCL recovery */
|
|
||||||
if (!bri->set_scl || !bri->get_scl) {
|
|
||||||
dev_err(&adap->dev, "No {get|set}_scl() found, not using recovery\n");
|
|
||||||
adap->bus_recovery_info = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit_recovery:
|
|
||||||
/* create pre-declared device nodes */
|
/* create pre-declared device nodes */
|
||||||
of_i2c_register_devices(adap);
|
of_i2c_register_devices(adap);
|
||||||
acpi_i2c_register_devices(adap);
|
acpi_i2c_register_devices(adap);
|
||||||
|
|
Loading…
Reference in New Issue