wm831x-spi.c 5.3 KB
Newer Older
M
Mark Brown 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * 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>
17
#include <linux/pm.h>
M
Mark Brown 已提交
18
#include <linux/spi/spi.h>
19 20
#include <linux/regmap.h>
#include <linux/err.h>
M
Mark Brown 已提交
21 22 23 24 25 26 27

#include <linux/mfd/wm831x/core.h>

static int __devinit wm831x_spi_probe(struct spi_device *spi)
{
	struct wm831x *wm831x;
	enum wm831x_parent type;
28
	int ret;
M
Mark Brown 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42

	/* 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;
M
Mark Brown 已提交
43 44
	else if (strcmp(spi->modalias, "wm8326") == 0)
		type = WM8326;
M
Mark Brown 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58
	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;
59 60 61 62 63 64 65 66 67

	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;
	}
M
Mark Brown 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80

	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;
}

81
static int wm831x_spi_suspend(struct device *dev)
M
Mark Brown 已提交
82
{
83
	struct wm831x *wm831x = dev_get_drvdata(dev);
M
Mark Brown 已提交
84 85 86 87

	return wm831x_device_suspend(wm831x);
}

88 89 90 91 92
static const struct dev_pm_ops wm831x_spi_pm = {
	.freeze = wm831x_spi_suspend,
	.suspend = wm831x_spi_suspend,
};

M
Mark Brown 已提交
93 94 95 96 97
static struct spi_driver wm8310_spi_driver = {
	.driver = {
		.name	= "wm8310",
		.bus	= &spi_bus_type,
		.owner	= THIS_MODULE,
98
		.pm	= &wm831x_spi_pm,
M
Mark Brown 已提交
99 100 101 102 103 104 105 106 107 108
	},
	.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,
109
		.pm	= &wm831x_spi_pm,
M
Mark Brown 已提交
110 111 112 113 114 115 116 117 118 119
	},
	.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,
120
		.pm	= &wm831x_spi_pm,
M
Mark Brown 已提交
121 122 123 124 125 126 127 128 129 130
	},
	.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,
131
		.pm	= &wm831x_spi_pm,
M
Mark Brown 已提交
132 133 134 135 136 137 138 139 140 141
	},
	.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,
142
		.pm	= &wm831x_spi_pm,
M
Mark Brown 已提交
143 144 145 146 147 148 149 150 151 152
	},
	.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,
153
		.pm	= &wm831x_spi_pm,
M
Mark Brown 已提交
154 155 156 157 158
	},
	.probe		= wm831x_spi_probe,
	.remove		= __devexit_p(wm831x_spi_remove),
};

M
Mark Brown 已提交
159 160 161 162 163
static struct spi_driver wm8326_spi_driver = {
	.driver = {
		.name	= "wm8326",
		.bus	= &spi_bus_type,
		.owner	= THIS_MODULE,
164
		.pm	= &wm831x_spi_pm,
M
Mark Brown 已提交
165 166 167 168 169
	},
	.probe		= wm831x_spi_probe,
	.remove		= __devexit_p(wm831x_spi_remove),
};

M
Mark Brown 已提交
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
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);

M
Mark Brown 已提交
198 199 200 201
	ret = spi_register_driver(&wm8326_spi_driver);
	if (ret != 0)
		pr_err("Failed to register WM8326 SPI driver: %d\n", ret);

M
Mark Brown 已提交
202 203 204 205 206 207
	return 0;
}
subsys_initcall(wm831x_spi_init);

static void __exit wm831x_spi_exit(void)
{
M
Mark Brown 已提交
208
	spi_unregister_driver(&wm8326_spi_driver);
M
Mark Brown 已提交
209 210 211 212 213 214 215 216 217 218 219 220
	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");