SIOX changes for 6.9-rc1

These patches rework how siox device registration works yielding a saner
 API. This allows to simplify the gpio bus driver using two new devm
 functions.
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCgAdFiEEP4GsaTp6HlmJrf7Tj4D7WH0S/k4FAmX8oqQACgkQj4D7WH0S
 /k661AgAtM/ogAWHB/ksURNPWx4JpHB+7rAFYSD0BMsQyv/79PFJwc0gAPQuAnOB
 AV653OR15C5UZYIpfNzzO4OIzl5s0fQ1IkJMTywSr5xw0lNQy258OFgLgp1s/3JW
 fwOtfA6epcrLatjmAI/9jU1CXtq0QdPcmyPtOw66CiaQULP2/Ok1/gD7LfUMIqFK
 /Wmv6nWfKPrVzq7PzAdzB6fxYsPG6tIMkXSZTa9KT/0TgJnxNFfT4w7fx4zdFAoh
 1Wza50T3nwe68ko2Dvou1zkEWMf2algjqwvS/X7NESDvX+p6P1u9YyBFIde8TEiv
 SK7SW+tapRo36Qmoy7NDZK3gVPyJJA==
 =keL/
 -----END PGP SIGNATURE-----

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()
This commit is contained in:
Linus Torvalds 2024-03-21 15:18:18 -07:00
commit 0045341957
3 changed files with 70 additions and 42 deletions

View File

@ -91,63 +91,42 @@ static int siox_gpio_probe(struct platform_device *pdev)
int ret;
struct siox_master *smaster;
smaster = siox_master_alloc(&pdev->dev, sizeof(*ddata));
if (!smaster) {
dev_err(dev, "failed to allocate siox master\n");
return -ENOMEM;
}
smaster = devm_siox_master_alloc(dev, sizeof(*ddata));
if (!smaster)
return dev_err_probe(dev, -ENOMEM,
"failed to allocate siox master\n");
platform_set_drvdata(pdev, smaster);
ddata = siox_master_get_devdata(smaster);
ddata->din = devm_gpiod_get(dev, "din", GPIOD_IN);
if (IS_ERR(ddata->din)) {
ret = dev_err_probe(dev, PTR_ERR(ddata->din),
"Failed to get din GPIO\n");
goto err;
}
if (IS_ERR(ddata->din))
return dev_err_probe(dev, PTR_ERR(ddata->din),
"Failed to get din GPIO\n");
ddata->dout = devm_gpiod_get(dev, "dout", GPIOD_OUT_LOW);
if (IS_ERR(ddata->dout)) {
ret = dev_err_probe(dev, PTR_ERR(ddata->dout),
"Failed to get dout GPIO\n");
goto err;
}
if (IS_ERR(ddata->dout))
return dev_err_probe(dev, PTR_ERR(ddata->dout),
"Failed to get dout GPIO\n");
ddata->dclk = devm_gpiod_get(dev, "dclk", GPIOD_OUT_LOW);
if (IS_ERR(ddata->dclk)) {
ret = dev_err_probe(dev, PTR_ERR(ddata->dclk),
"Failed to get dclk GPIO\n");
goto err;
}
if (IS_ERR(ddata->dclk))
return dev_err_probe(dev, PTR_ERR(ddata->dclk),
"Failed to get dclk GPIO\n");
ddata->dld = devm_gpiod_get(dev, "dld", GPIOD_OUT_LOW);
if (IS_ERR(ddata->dld)) {
ret = dev_err_probe(dev, PTR_ERR(ddata->dld),
"Failed to get dld GPIO\n");
goto err;
}
if (IS_ERR(ddata->dld))
return dev_err_probe(dev, PTR_ERR(ddata->dld),
"Failed to get dld GPIO\n");
smaster->pushpull = siox_gpio_pushpull;
/* XXX: determine automatically like spi does */
smaster->busno = 0;
ret = siox_master_register(smaster);
if (ret) {
dev_err_probe(dev, ret,
"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);
ret = devm_siox_master_register(dev, smaster);
if (ret)
return dev_err_probe(dev, ret,
"Failed to register siox master\n");
return 0;
}
@ -160,7 +139,6 @@ MODULE_DEVICE_TABLE(of, siox_gpio_dt_ids);
static struct platform_driver siox_gpio_driver = {
.probe = siox_gpio_probe,
.remove = siox_gpio_remove,
.driver = {
.name = DRIVER_NAME,

View File

@ -707,6 +707,31 @@ struct siox_master *siox_master_alloc(struct device *dev,
}
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 ret;
@ -717,6 +742,8 @@ int siox_master_register(struct siox_master *smaster)
if (!smaster->pushpull)
return -EINVAL;
get_device(&smaster->dev);
dev_set_name(&smaster->dev, "siox-%d", smaster->busno);
mutex_init(&smaster->lock);
@ -768,6 +795,25 @@ void siox_master_unregister(struct siox_master *smaster)
}
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,
const char *type, size_t inbytes,
size_t outbytes, u8 statustype)

View File

@ -45,5 +45,9 @@ static inline void siox_master_put(struct siox_master *smaster)
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);
void siox_master_unregister(struct siox_master *smaster);
int devm_siox_master_register(struct device *dev, struct siox_master *smaster);