mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 12:42:02 +00:00
4e57d1425c
'type' is an enum, thus cast of pointer on 64-bit compile test with W=1 causes: wm831x-spi.c:36:10: error: cast to smaller integer type 'enum wm831x_parent' from 'const void *' [-Werror,-Wvoid-pointer-to-enum-cast] Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20230810095849.123321-8-krzysztof.kozlowski@linaro.org Signed-off-by: Lee Jones <lee@kernel.org>
120 lines
2.6 KiB
C
120 lines
2.6 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* wm831x-spi.c -- SPI access for Wolfson WM831x PMICs
|
|
*
|
|
* Copyright 2009,2010 Wolfson Microelectronics PLC.
|
|
*
|
|
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/spi/spi.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/mfd/wm831x/core.h>
|
|
|
|
static int wm831x_spi_probe(struct spi_device *spi)
|
|
{
|
|
struct wm831x_pdata *pdata = dev_get_platdata(&spi->dev);
|
|
const struct spi_device_id *id = spi_get_device_id(spi);
|
|
const struct of_device_id *of_id;
|
|
struct wm831x *wm831x;
|
|
enum wm831x_parent type;
|
|
int ret;
|
|
|
|
if (spi->dev.of_node) {
|
|
of_id = of_match_device(wm831x_of_match, &spi->dev);
|
|
if (!of_id) {
|
|
dev_err(&spi->dev, "Failed to match device\n");
|
|
return -ENODEV;
|
|
}
|
|
type = (uintptr_t)of_id->data;
|
|
} else {
|
|
type = (enum wm831x_parent)id->driver_data;
|
|
}
|
|
|
|
wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
|
|
if (wm831x == NULL)
|
|
return -ENOMEM;
|
|
|
|
spi->mode = SPI_MODE_0;
|
|
|
|
spi_set_drvdata(spi, wm831x);
|
|
wm831x->dev = &spi->dev;
|
|
wm831x->type = type;
|
|
|
|
wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
|
|
if (IS_ERR(wm831x->regmap)) {
|
|
ret = PTR_ERR(wm831x->regmap);
|
|
dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
|
|
ret);
|
|
return ret;
|
|
}
|
|
|
|
if (pdata)
|
|
memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
|
|
|
|
return wm831x_device_init(wm831x, spi->irq);
|
|
}
|
|
|
|
static int wm831x_spi_suspend(struct device *dev)
|
|
{
|
|
struct wm831x *wm831x = dev_get_drvdata(dev);
|
|
|
|
return wm831x_device_suspend(wm831x);
|
|
}
|
|
|
|
static int wm831x_spi_poweroff(struct device *dev)
|
|
{
|
|
struct wm831x *wm831x = dev_get_drvdata(dev);
|
|
|
|
wm831x_device_shutdown(wm831x);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct dev_pm_ops wm831x_spi_pm = {
|
|
.freeze = wm831x_spi_suspend,
|
|
.suspend = wm831x_spi_suspend,
|
|
.poweroff = wm831x_spi_poweroff,
|
|
};
|
|
|
|
static const struct spi_device_id wm831x_spi_ids[] = {
|
|
{ "wm8310", WM8310 },
|
|
{ "wm8311", WM8311 },
|
|
{ "wm8312", WM8312 },
|
|
{ "wm8320", WM8320 },
|
|
{ "wm8321", WM8321 },
|
|
{ "wm8325", WM8325 },
|
|
{ "wm8326", WM8326 },
|
|
{ },
|
|
};
|
|
|
|
static struct spi_driver wm831x_spi_driver = {
|
|
.driver = {
|
|
.name = "wm831x",
|
|
.pm = &wm831x_spi_pm,
|
|
.of_match_table = of_match_ptr(wm831x_of_match),
|
|
.suppress_bind_attrs = true,
|
|
},
|
|
.id_table = wm831x_spi_ids,
|
|
.probe = wm831x_spi_probe,
|
|
};
|
|
|
|
static int __init wm831x_spi_init(void)
|
|
{
|
|
int ret;
|
|
|
|
ret = spi_register_driver(&wm831x_spi_driver);
|
|
if (ret != 0)
|
|
pr_err("Failed to register WM831x SPI driver: %d\n", ret);
|
|
|
|
return 0;
|
|
}
|
|
subsys_initcall(wm831x_spi_init);
|