2010-10-19 16:00:11 -06: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>
|
2011-02-01 04:46:12 -07:00
|
|
|
#include <linux/pm.h>
|
2010-10-19 16:00:11 -06:00
|
|
|
#include <linux/spi/spi.h>
|
2011-06-10 12:28:10 -06:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/err.h>
|
2010-10-19 16:00:11 -06:00
|
|
|
|
|
|
|
#include <linux/mfd/wm831x/core.h>
|
|
|
|
|
|
|
|
static int __devinit wm831x_spi_probe(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct wm831x *wm831x;
|
|
|
|
enum wm831x_parent type;
|
2011-06-10 12:28:10 -06:00
|
|
|
int ret;
|
2010-10-19 16:00:11 -06:00
|
|
|
|
|
|
|
/* Currently SPI support for ID tables is unmerged, we're faking it */
|
|
|
|
if (strcmp(spi->modalias, "wm8310") == 0)
|
|
|
|
type = WM8310;
|
|
|
|
else if (strcmp(spi->modalias, "wm8311") == 0)
|
|
|
|
type = WM8311;
|
|
|
|
else if (strcmp(spi->modalias, "wm8312") == 0)
|
|
|
|
type = WM8312;
|
|
|
|
else if (strcmp(spi->modalias, "wm8320") == 0)
|
|
|
|
type = WM8320;
|
|
|
|
else if (strcmp(spi->modalias, "wm8321") == 0)
|
|
|
|
type = WM8321;
|
|
|
|
else if (strcmp(spi->modalias, "wm8325") == 0)
|
|
|
|
type = WM8325;
|
2010-11-24 11:01:41 -07:00
|
|
|
else if (strcmp(spi->modalias, "wm8326") == 0)
|
|
|
|
type = WM8326;
|
2010-10-19 16:00:11 -06:00
|
|
|
else {
|
|
|
|
dev_err(&spi->dev, "Unknown device type\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
|
|
|
|
if (wm831x == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spi->bits_per_word = 16;
|
|
|
|
spi->mode = SPI_MODE_0;
|
|
|
|
|
|
|
|
dev_set_drvdata(&spi->dev, wm831x);
|
|
|
|
wm831x->dev = &spi->dev;
|
2011-06-10 12:28:10 -06:00
|
|
|
|
|
|
|
wm831x->regmap = regmap_init_spi(wm831x->dev, &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);
|
|
|
|
kfree(wm831x);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-10-19 16:00:11 -06:00
|
|
|
|
|
|
|
return wm831x_device_init(wm831x, type, spi->irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit wm831x_spi_remove(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct wm831x *wm831x = dev_get_drvdata(&spi->dev);
|
|
|
|
|
|
|
|
wm831x_device_exit(wm831x);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-01 04:46:12 -07:00
|
|
|
static int wm831x_spi_suspend(struct device *dev)
|
2010-10-19 16:00:11 -06:00
|
|
|
{
|
2011-02-01 04:46:12 -07:00
|
|
|
struct wm831x *wm831x = dev_get_drvdata(dev);
|
2010-10-19 16:00:11 -06:00
|
|
|
|
|
|
|
return wm831x_device_suspend(wm831x);
|
|
|
|
}
|
|
|
|
|
2011-02-01 04:46:12 -07:00
|
|
|
static const struct dev_pm_ops wm831x_spi_pm = {
|
|
|
|
.freeze = wm831x_spi_suspend,
|
|
|
|
.suspend = wm831x_spi_suspend,
|
|
|
|
};
|
|
|
|
|
2010-10-19 16:00:11 -06:00
|
|
|
static struct spi_driver wm8310_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm8310",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-02-01 04:46:12 -07:00
|
|
|
.pm = &wm831x_spi_pm,
|
2010-10-19 16:00:11 -06:00
|
|
|
},
|
|
|
|
.probe = wm831x_spi_probe,
|
|
|
|
.remove = __devexit_p(wm831x_spi_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_driver wm8311_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm8311",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-02-01 04:46:12 -07:00
|
|
|
.pm = &wm831x_spi_pm,
|
2010-10-19 16:00:11 -06:00
|
|
|
},
|
|
|
|
.probe = wm831x_spi_probe,
|
|
|
|
.remove = __devexit_p(wm831x_spi_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_driver wm8312_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm8312",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-02-01 04:46:12 -07:00
|
|
|
.pm = &wm831x_spi_pm,
|
2010-10-19 16:00:11 -06:00
|
|
|
},
|
|
|
|
.probe = wm831x_spi_probe,
|
|
|
|
.remove = __devexit_p(wm831x_spi_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_driver wm8320_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm8320",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-02-01 04:46:12 -07:00
|
|
|
.pm = &wm831x_spi_pm,
|
2010-10-19 16:00:11 -06:00
|
|
|
},
|
|
|
|
.probe = wm831x_spi_probe,
|
|
|
|
.remove = __devexit_p(wm831x_spi_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_driver wm8321_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm8321",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-02-01 04:46:12 -07:00
|
|
|
.pm = &wm831x_spi_pm,
|
2010-10-19 16:00:11 -06:00
|
|
|
},
|
|
|
|
.probe = wm831x_spi_probe,
|
|
|
|
.remove = __devexit_p(wm831x_spi_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct spi_driver wm8325_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm8325",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-02-01 04:46:12 -07:00
|
|
|
.pm = &wm831x_spi_pm,
|
2010-10-19 16:00:11 -06:00
|
|
|
},
|
|
|
|
.probe = wm831x_spi_probe,
|
|
|
|
.remove = __devexit_p(wm831x_spi_remove),
|
|
|
|
};
|
|
|
|
|
2010-11-24 11:01:41 -07:00
|
|
|
static struct spi_driver wm8326_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm8326",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-02-01 04:46:12 -07:00
|
|
|
.pm = &wm831x_spi_pm,
|
2010-11-24 11:01:41 -07:00
|
|
|
},
|
|
|
|
.probe = wm831x_spi_probe,
|
|
|
|
.remove = __devexit_p(wm831x_spi_remove),
|
|
|
|
};
|
|
|
|
|
2010-10-19 16:00:11 -06:00
|
|
|
static int __init wm831x_spi_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = spi_register_driver(&wm8310_spi_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register WM8310 SPI driver: %d\n", ret);
|
|
|
|
|
|
|
|
ret = spi_register_driver(&wm8311_spi_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register WM8311 SPI driver: %d\n", ret);
|
|
|
|
|
|
|
|
ret = spi_register_driver(&wm8312_spi_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register WM8312 SPI driver: %d\n", ret);
|
|
|
|
|
|
|
|
ret = spi_register_driver(&wm8320_spi_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register WM8320 SPI driver: %d\n", ret);
|
|
|
|
|
|
|
|
ret = spi_register_driver(&wm8321_spi_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register WM8321 SPI driver: %d\n", ret);
|
|
|
|
|
|
|
|
ret = spi_register_driver(&wm8325_spi_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register WM8325 SPI driver: %d\n", ret);
|
|
|
|
|
2010-11-24 11:01:41 -07:00
|
|
|
ret = spi_register_driver(&wm8326_spi_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
pr_err("Failed to register WM8326 SPI driver: %d\n", ret);
|
|
|
|
|
2010-10-19 16:00:11 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
subsys_initcall(wm831x_spi_init);
|
|
|
|
|
|
|
|
static void __exit wm831x_spi_exit(void)
|
|
|
|
{
|
2010-11-24 11:01:41 -07:00
|
|
|
spi_unregister_driver(&wm8326_spi_driver);
|
2010-10-19 16:00:11 -06:00
|
|
|
spi_unregister_driver(&wm8325_spi_driver);
|
|
|
|
spi_unregister_driver(&wm8321_spi_driver);
|
|
|
|
spi_unregister_driver(&wm8320_spi_driver);
|
|
|
|
spi_unregister_driver(&wm8312_spi_driver);
|
|
|
|
spi_unregister_driver(&wm8311_spi_driver);
|
|
|
|
spi_unregister_driver(&wm8310_spi_driver);
|
|
|
|
}
|
|
|
|
module_exit(wm831x_spi_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Mark Brown");
|