2010-10-20 06:00:11 +08:00
|
|
|
/*
|
|
|
|
* wm831x-spi.c -- SPI access for Wolfson WM831x PMICs
|
|
|
|
*
|
|
|
|
* Copyright 2009,2010 Wolfson Microelectronics PLC.
|
|
|
|
*
|
|
|
|
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2017-03-17 18:05:18 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2011-02-01 19:46:12 +08:00
|
|
|
#include <linux/pm.h>
|
2010-10-20 06:00:11 +08:00
|
|
|
#include <linux/spi/spi.h>
|
2011-06-11 02:28:10 +08:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/err.h>
|
2010-10-20 06:00:11 +08:00
|
|
|
|
|
|
|
#include <linux/mfd/wm831x/core.h>
|
|
|
|
|
2012-11-20 02:23:04 +08:00
|
|
|
static int wm831x_spi_probe(struct spi_device *spi)
|
2010-10-20 06:00:11 +08:00
|
|
|
{
|
2017-03-17 18:05:18 +08:00
|
|
|
struct wm831x_pdata *pdata = dev_get_platdata(&spi->dev);
|
2011-07-24 18:44:19 +08:00
|
|
|
const struct spi_device_id *id = spi_get_device_id(spi);
|
2017-03-17 18:05:18 +08:00
|
|
|
const struct of_device_id *of_id;
|
2010-10-20 06:00:11 +08:00
|
|
|
struct wm831x *wm831x;
|
|
|
|
enum wm831x_parent type;
|
2011-06-11 02:28:10 +08:00
|
|
|
int ret;
|
2010-10-20 06:00:11 +08:00
|
|
|
|
2017-03-17 18:05:18 +08:00
|
|
|
if (spi->dev.of_node) {
|
|
|
|
of_id = of_match_device(wm831x_of_match, &spi->dev);
|
2017-05-24 17:18:52 +08:00
|
|
|
if (!of_id) {
|
|
|
|
dev_err(&spi->dev, "Failed to match device\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2017-03-17 18:05:18 +08:00
|
|
|
type = (enum wm831x_parent)of_id->data;
|
|
|
|
} else {
|
|
|
|
type = (enum wm831x_parent)id->driver_data;
|
|
|
|
}
|
2010-10-20 06:00:11 +08:00
|
|
|
|
2011-10-25 20:47:40 +08:00
|
|
|
wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
|
2010-10-20 06:00:11 +08:00
|
|
|
if (wm831x == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spi->mode = SPI_MODE_0;
|
|
|
|
|
2013-04-06 14:42:48 +08:00
|
|
|
spi_set_drvdata(spi, wm831x);
|
2010-10-20 06:00:11 +08:00
|
|
|
wm831x->dev = &spi->dev;
|
2017-03-17 18:05:18 +08:00
|
|
|
wm831x->type = type;
|
2011-06-11 02:28:10 +08:00
|
|
|
|
2012-01-31 04:08:06 +08:00
|
|
|
wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
|
2011-06-11 02:28:10 +08:00
|
|
|
if (IS_ERR(wm831x->regmap)) {
|
|
|
|
ret = PTR_ERR(wm831x->regmap);
|
|
|
|
dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-10-20 06:00:11 +08:00
|
|
|
|
2017-03-17 18:05:18 +08:00
|
|
|
if (pdata)
|
|
|
|
memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
|
|
|
|
|
|
|
|
return wm831x_device_init(wm831x, spi->irq);
|
2010-10-20 06:00:11 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:01 +08:00
|
|
|
static int wm831x_spi_remove(struct spi_device *spi)
|
2010-10-20 06:00:11 +08:00
|
|
|
{
|
2013-04-06 14:42:48 +08:00
|
|
|
struct wm831x *wm831x = spi_get_drvdata(spi);
|
2010-10-20 06:00:11 +08:00
|
|
|
|
|
|
|
wm831x_device_exit(wm831x);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-01 19:46:12 +08:00
|
|
|
static int wm831x_spi_suspend(struct device *dev)
|
2010-10-20 06:00:11 +08:00
|
|
|
{
|
2011-02-01 19:46:12 +08:00
|
|
|
struct wm831x *wm831x = dev_get_drvdata(dev);
|
2010-10-20 06:00:11 +08:00
|
|
|
|
|
|
|
return wm831x_device_suspend(wm831x);
|
|
|
|
}
|
|
|
|
|
2013-11-09 02:51:25 +08:00
|
|
|
static int wm831x_spi_poweroff(struct device *dev)
|
2011-09-16 00:54:53 +08:00
|
|
|
{
|
2013-11-09 02:51:25 +08:00
|
|
|
struct wm831x *wm831x = dev_get_drvdata(dev);
|
2011-09-16 00:54:53 +08:00
|
|
|
|
|
|
|
wm831x_device_shutdown(wm831x);
|
2013-11-09 02:51:25 +08:00
|
|
|
|
|
|
|
return 0;
|
2011-09-16 00:54:53 +08:00
|
|
|
}
|
|
|
|
|
2011-02-01 19:46:12 +08:00
|
|
|
static const struct dev_pm_ops wm831x_spi_pm = {
|
|
|
|
.freeze = wm831x_spi_suspend,
|
|
|
|
.suspend = wm831x_spi_suspend,
|
2013-11-09 02:51:25 +08:00
|
|
|
.poweroff = wm831x_spi_poweroff,
|
2011-02-01 19:46:12 +08:00
|
|
|
};
|
|
|
|
|
2011-07-24 18:44:19 +08:00
|
|
|
static const struct spi_device_id wm831x_spi_ids[] = {
|
|
|
|
{ "wm8310", WM8310 },
|
|
|
|
{ "wm8311", WM8311 },
|
|
|
|
{ "wm8312", WM8312 },
|
|
|
|
{ "wm8320", WM8320 },
|
|
|
|
{ "wm8321", WM8321 },
|
|
|
|
{ "wm8325", WM8325 },
|
|
|
|
{ "wm8326", WM8326 },
|
|
|
|
{ },
|
2010-10-20 06:00:11 +08:00
|
|
|
};
|
2012-02-25 06:03:00 +08:00
|
|
|
MODULE_DEVICE_TABLE(spi, wm831x_spi_ids);
|
2010-10-20 06:00:11 +08:00
|
|
|
|
2011-07-24 18:44:19 +08:00
|
|
|
static struct spi_driver wm831x_spi_driver = {
|
2010-10-20 06:00:11 +08:00
|
|
|
.driver = {
|
2011-07-24 18:44:19 +08:00
|
|
|
.name = "wm831x",
|
2011-02-01 19:46:12 +08:00
|
|
|
.pm = &wm831x_spi_pm,
|
2017-03-17 18:05:18 +08:00
|
|
|
.of_match_table = of_match_ptr(wm831x_of_match),
|
2010-11-25 02:01:41 +08:00
|
|
|
},
|
2011-07-24 18:44:19 +08:00
|
|
|
.id_table = wm831x_spi_ids,
|
2010-11-25 02:01:41 +08:00
|
|
|
.probe = wm831x_spi_probe,
|
2012-11-20 02:20:24 +08:00
|
|
|
.remove = wm831x_spi_remove,
|
2010-11-25 02:01:41 +08:00
|
|
|
};
|
|
|
|
|
2010-10-20 06:00:11 +08:00
|
|
|
static int __init wm831x_spi_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-07-24 18:44:19 +08:00
|
|
|
ret = spi_register_driver(&wm831x_spi_driver);
|
2010-11-25 02:01:41 +08:00
|
|
|
if (ret != 0)
|
2011-07-24 18:44:19 +08:00
|
|
|
pr_err("Failed to register WM831x SPI driver: %d\n", ret);
|
2010-11-25 02:01:41 +08:00
|
|
|
|
2010-10-20 06:00:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
subsys_initcall(wm831x_spi_init);
|
|
|
|
|
|
|
|
static void __exit wm831x_spi_exit(void)
|
|
|
|
{
|
2011-07-24 18:44:19 +08:00
|
|
|
spi_unregister_driver(&wm831x_spi_driver);
|
2010-10-20 06:00:11 +08:00
|
|
|
}
|
|
|
|
module_exit(wm831x_spi_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Mark Brown");
|