mirror of
https://github.com/torvalds/linux.git
synced 2024-12-02 17:11:33 +00:00
a0386bba70
The value returned by an spi driver's remove function is mostly ignored. (Only an error message is printed if the value is non-zero that the error is ignored.) So change the prototype of the remove function to return no value. This way driver authors are not tempted to assume that passing an error to the upper layer is a good idea. All drivers are adapted accordingly. There is no intended change of behaviour, all callbacks were prepared to return 0 before. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Acked-by: Marc Kleine-Budde <mkl@pengutronix.de> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Acked-by: Jérôme Pouiller <jerome.pouiller@silabs.com> Acked-by: Miquel Raynal <miquel.raynal@bootlin.com> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Claudius Heine <ch@denx.de> Acked-by: Stefan Schmidt <stefan@datenfreihafen.org> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # For MMC Acked-by: Marcus Folkesson <marcus.folkesson@gmail.com> Acked-by: Łukasz Stelmach <l.stelmach@samsung.com> Acked-by: Lee Jones <lee.jones@linaro.org> Link: https://lore.kernel.org/r/20220123175201.34839-6-u.kleine-koenig@pengutronix.de Signed-off-by: Mark Brown <broonie@kernel.org>
151 lines
3.3 KiB
C
151 lines
3.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* lis3lv02d_spi - SPI glue layer for lis3lv02d
|
|
*
|
|
* Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/err.h>
|
|
#include <linux/input.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/workqueue.h>
|
|
#include <linux/spi/spi.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_platform.h>
|
|
#include <linux/of_device.h>
|
|
|
|
#include "lis3lv02d.h"
|
|
|
|
#define DRV_NAME "lis3lv02d_spi"
|
|
#define LIS3_SPI_READ 0x80
|
|
|
|
static int lis3_spi_read(struct lis3lv02d *lis3, int reg, u8 *v)
|
|
{
|
|
struct spi_device *spi = lis3->bus_priv;
|
|
int ret = spi_w8r8(spi, reg | LIS3_SPI_READ);
|
|
if (ret < 0)
|
|
return -EINVAL;
|
|
|
|
*v = (u8) ret;
|
|
return 0;
|
|
}
|
|
|
|
static int lis3_spi_write(struct lis3lv02d *lis3, int reg, u8 val)
|
|
{
|
|
u8 tmp[2] = { reg, val };
|
|
struct spi_device *spi = lis3->bus_priv;
|
|
return spi_write(spi, tmp, sizeof(tmp));
|
|
}
|
|
|
|
static int lis3_spi_init(struct lis3lv02d *lis3)
|
|
{
|
|
u8 reg;
|
|
int ret;
|
|
|
|
/* power up the device */
|
|
ret = lis3->read(lis3, CTRL_REG1, ®);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
reg |= CTRL1_PD0 | CTRL1_Xen | CTRL1_Yen | CTRL1_Zen;
|
|
return lis3->write(lis3, CTRL_REG1, reg);
|
|
}
|
|
|
|
static union axis_conversion lis3lv02d_axis_normal =
|
|
{ .as_array = { 1, 2, 3 } };
|
|
|
|
#ifdef CONFIG_OF
|
|
static const struct of_device_id lis302dl_spi_dt_ids[] = {
|
|
{ .compatible = "st,lis302dl-spi" },
|
|
{}
|
|
};
|
|
MODULE_DEVICE_TABLE(of, lis302dl_spi_dt_ids);
|
|
#endif
|
|
|
|
static int lis302dl_spi_probe(struct spi_device *spi)
|
|
{
|
|
int ret;
|
|
|
|
spi->bits_per_word = 8;
|
|
spi->mode = SPI_MODE_0;
|
|
ret = spi_setup(spi);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
lis3_dev.bus_priv = spi;
|
|
lis3_dev.init = lis3_spi_init;
|
|
lis3_dev.read = lis3_spi_read;
|
|
lis3_dev.write = lis3_spi_write;
|
|
lis3_dev.irq = spi->irq;
|
|
lis3_dev.ac = lis3lv02d_axis_normal;
|
|
lis3_dev.pdata = spi->dev.platform_data;
|
|
|
|
#ifdef CONFIG_OF
|
|
if (of_match_device(lis302dl_spi_dt_ids, &spi->dev)) {
|
|
lis3_dev.of_node = spi->dev.of_node;
|
|
ret = lis3lv02d_init_dt(&lis3_dev);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
#endif
|
|
spi_set_drvdata(spi, &lis3_dev);
|
|
|
|
return lis3lv02d_init_device(&lis3_dev);
|
|
}
|
|
|
|
static void lis302dl_spi_remove(struct spi_device *spi)
|
|
{
|
|
struct lis3lv02d *lis3 = spi_get_drvdata(spi);
|
|
lis3lv02d_joystick_disable(lis3);
|
|
lis3lv02d_poweroff(lis3);
|
|
|
|
lis3lv02d_remove_fs(&lis3_dev);
|
|
}
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
static int lis3lv02d_spi_suspend(struct device *dev)
|
|
{
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
struct lis3lv02d *lis3 = spi_get_drvdata(spi);
|
|
|
|
if (!lis3->pdata || !lis3->pdata->wakeup_flags)
|
|
lis3lv02d_poweroff(&lis3_dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int lis3lv02d_spi_resume(struct device *dev)
|
|
{
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
struct lis3lv02d *lis3 = spi_get_drvdata(spi);
|
|
|
|
if (!lis3->pdata || !lis3->pdata->wakeup_flags)
|
|
lis3lv02d_poweron(lis3);
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
static SIMPLE_DEV_PM_OPS(lis3lv02d_spi_pm, lis3lv02d_spi_suspend,
|
|
lis3lv02d_spi_resume);
|
|
|
|
static struct spi_driver lis302dl_spi_driver = {
|
|
.driver = {
|
|
.name = DRV_NAME,
|
|
.pm = &lis3lv02d_spi_pm,
|
|
.of_match_table = of_match_ptr(lis302dl_spi_dt_ids),
|
|
},
|
|
.probe = lis302dl_spi_probe,
|
|
.remove = lis302dl_spi_remove,
|
|
};
|
|
|
|
module_spi_driver(lis302dl_spi_driver);
|
|
|
|
MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
|
|
MODULE_DESCRIPTION("lis3lv02d SPI glue layer");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("spi:" DRV_NAME);
|