Commit 00453419 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'siox/for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux

Pull siox updates from Uwe Kleine-König:
 "This reworks how siox device registration works yielding a saner API.

  This allows us to simplify the gpio bus driver using two new devm
  functions"

* tag 'siox/for-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux:
  siox: bus-gpio: Simplify using devm_siox_* functions
  siox: Provide a devm variant of siox_master_register()
  siox: Provide a devm variant of siox_master_alloc()
  siox: Don't pass the reference on a master in siox_master_register()
parents 85a79128 db418d5f
...@@ -91,63 +91,42 @@ static int siox_gpio_probe(struct platform_device *pdev) ...@@ -91,63 +91,42 @@ static int siox_gpio_probe(struct platform_device *pdev)
int ret; int ret;
struct siox_master *smaster; struct siox_master *smaster;
smaster = siox_master_alloc(&pdev->dev, sizeof(*ddata)); smaster = devm_siox_master_alloc(dev, sizeof(*ddata));
if (!smaster) { if (!smaster)
dev_err(dev, "failed to allocate siox master\n"); return dev_err_probe(dev, -ENOMEM,
return -ENOMEM; "failed to allocate siox master\n");
}
platform_set_drvdata(pdev, smaster); platform_set_drvdata(pdev, smaster);
ddata = siox_master_get_devdata(smaster); ddata = siox_master_get_devdata(smaster);
ddata->din = devm_gpiod_get(dev, "din", GPIOD_IN); ddata->din = devm_gpiod_get(dev, "din", GPIOD_IN);
if (IS_ERR(ddata->din)) { if (IS_ERR(ddata->din))
ret = dev_err_probe(dev, PTR_ERR(ddata->din), return dev_err_probe(dev, PTR_ERR(ddata->din),
"Failed to get din GPIO\n"); "Failed to get din GPIO\n");
goto err;
}
ddata->dout = devm_gpiod_get(dev, "dout", GPIOD_OUT_LOW); ddata->dout = devm_gpiod_get(dev, "dout", GPIOD_OUT_LOW);
if (IS_ERR(ddata->dout)) { if (IS_ERR(ddata->dout))
ret = dev_err_probe(dev, PTR_ERR(ddata->dout), return dev_err_probe(dev, PTR_ERR(ddata->dout),
"Failed to get dout GPIO\n"); "Failed to get dout GPIO\n");
goto err;
}
ddata->dclk = devm_gpiod_get(dev, "dclk", GPIOD_OUT_LOW); ddata->dclk = devm_gpiod_get(dev, "dclk", GPIOD_OUT_LOW);
if (IS_ERR(ddata->dclk)) { if (IS_ERR(ddata->dclk))
ret = dev_err_probe(dev, PTR_ERR(ddata->dclk), return dev_err_probe(dev, PTR_ERR(ddata->dclk),
"Failed to get dclk GPIO\n"); "Failed to get dclk GPIO\n");
goto err;
}
ddata->dld = devm_gpiod_get(dev, "dld", GPIOD_OUT_LOW); ddata->dld = devm_gpiod_get(dev, "dld", GPIOD_OUT_LOW);
if (IS_ERR(ddata->dld)) { if (IS_ERR(ddata->dld))
ret = dev_err_probe(dev, PTR_ERR(ddata->dld), return dev_err_probe(dev, PTR_ERR(ddata->dld),
"Failed to get dld GPIO\n"); "Failed to get dld GPIO\n");
goto err;
}
smaster->pushpull = siox_gpio_pushpull; smaster->pushpull = siox_gpio_pushpull;
/* XXX: determine automatically like spi does */ /* XXX: determine automatically like spi does */
smaster->busno = 0; smaster->busno = 0;
ret = siox_master_register(smaster); ret = devm_siox_master_register(dev, smaster);
if (ret) { if (ret)
dev_err_probe(dev, ret, return dev_err_probe(dev, ret,
"Failed to register siox master\n"); "Failed to register siox master\n");
err:
siox_master_put(smaster);
}
return ret;
}
static int siox_gpio_remove(struct platform_device *pdev)
{
struct siox_master *master = platform_get_drvdata(pdev);
siox_master_unregister(master);
return 0; return 0;
} }
...@@ -160,7 +139,6 @@ MODULE_DEVICE_TABLE(of, siox_gpio_dt_ids); ...@@ -160,7 +139,6 @@ MODULE_DEVICE_TABLE(of, siox_gpio_dt_ids);
static struct platform_driver siox_gpio_driver = { static struct platform_driver siox_gpio_driver = {
.probe = siox_gpio_probe, .probe = siox_gpio_probe,
.remove = siox_gpio_remove,
.driver = { .driver = {
.name = DRIVER_NAME, .name = DRIVER_NAME,
......
...@@ -707,6 +707,31 @@ struct siox_master *siox_master_alloc(struct device *dev, ...@@ -707,6 +707,31 @@ struct siox_master *siox_master_alloc(struct device *dev,
} }
EXPORT_SYMBOL_GPL(siox_master_alloc); EXPORT_SYMBOL_GPL(siox_master_alloc);
static void devm_siox_master_put(void *data)
{
struct siox_master *smaster = data;
siox_master_put(smaster);
}
struct siox_master *devm_siox_master_alloc(struct device *dev,
size_t size)
{
struct siox_master *smaster;
int ret;
smaster = siox_master_alloc(dev, size);
if (!smaster)
return NULL;
ret = devm_add_action_or_reset(dev, devm_siox_master_put, smaster);
if (ret)
return NULL;
return smaster;
}
EXPORT_SYMBOL_GPL(devm_siox_master_alloc);
int siox_master_register(struct siox_master *smaster) int siox_master_register(struct siox_master *smaster)
{ {
int ret; int ret;
...@@ -717,6 +742,8 @@ int siox_master_register(struct siox_master *smaster) ...@@ -717,6 +742,8 @@ int siox_master_register(struct siox_master *smaster)
if (!smaster->pushpull) if (!smaster->pushpull)
return -EINVAL; return -EINVAL;
get_device(&smaster->dev);
dev_set_name(&smaster->dev, "siox-%d", smaster->busno); dev_set_name(&smaster->dev, "siox-%d", smaster->busno);
mutex_init(&smaster->lock); mutex_init(&smaster->lock);
...@@ -768,6 +795,25 @@ void siox_master_unregister(struct siox_master *smaster) ...@@ -768,6 +795,25 @@ void siox_master_unregister(struct siox_master *smaster)
} }
EXPORT_SYMBOL_GPL(siox_master_unregister); EXPORT_SYMBOL_GPL(siox_master_unregister);
static void devm_siox_master_unregister(void *data)
{
struct siox_master *smaster = data;
siox_master_unregister(smaster);
}
int devm_siox_master_register(struct device *dev, struct siox_master *smaster)
{
int ret;
ret = siox_master_register(smaster);
if (ret)
return ret;
return devm_add_action_or_reset(dev, devm_siox_master_unregister, smaster);
}
EXPORT_SYMBOL_GPL(devm_siox_master_register);
static struct siox_device *siox_device_add(struct siox_master *smaster, static struct siox_device *siox_device_add(struct siox_master *smaster,
const char *type, size_t inbytes, const char *type, size_t inbytes,
size_t outbytes, u8 statustype) size_t outbytes, u8 statustype)
......
...@@ -45,5 +45,9 @@ static inline void siox_master_put(struct siox_master *smaster) ...@@ -45,5 +45,9 @@ static inline void siox_master_put(struct siox_master *smaster)
put_device(&smaster->dev); put_device(&smaster->dev);
} }
struct siox_master *devm_siox_master_alloc(struct device *dev, size_t size);
int siox_master_register(struct siox_master *smaster); int siox_master_register(struct siox_master *smaster);
void siox_master_unregister(struct siox_master *smaster); void siox_master_unregister(struct siox_master *smaster);
int devm_siox_master_register(struct device *dev, struct siox_master *smaster);
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