Blame view
drivers/mfd/wm831x-spi.c
2.89 KB
2aa13b9e8
|
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> |
87d1906df
|
17 |
#include <linux/pm.h> |
2aa13b9e8
|
18 |
#include <linux/spi/spi.h> |
1df5981b8
|
19 20 |
#include <linux/regmap.h> #include <linux/err.h> |
2aa13b9e8
|
21 22 |
#include <linux/mfd/wm831x/core.h> |
2aa13b9e8
|
23 24 |
static int __devinit wm831x_spi_probe(struct spi_device *spi) { |
5570c2f70
|
25 |
const struct spi_device_id *id = spi_get_device_id(spi); |
2aa13b9e8
|
26 27 |
struct wm831x *wm831x; enum wm831x_parent type; |
1df5981b8
|
28 |
int ret; |
2aa13b9e8
|
29 |
|
5570c2f70
|
30 |
type = (enum wm831x_parent)id->driver_data; |
2aa13b9e8
|
31 32 33 34 35 36 37 38 39 40 |
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; |
1df5981b8
|
41 |
|
5570c2f70
|
42 |
wm831x->regmap = regmap_init_spi(spi, &wm831x_regmap_config); |
1df5981b8
|
43 44 45 46 47 48 49 50 |
if (IS_ERR(wm831x->regmap)) { ret = PTR_ERR(wm831x->regmap); dev_err(wm831x->dev, "Failed to allocate register map: %d ", ret); kfree(wm831x); return ret; } |
2aa13b9e8
|
51 52 53 54 55 56 57 58 59 60 61 62 |
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; } |
87d1906df
|
63 |
static int wm831x_spi_suspend(struct device *dev) |
2aa13b9e8
|
64 |
{ |
87d1906df
|
65 |
struct wm831x *wm831x = dev_get_drvdata(dev); |
2aa13b9e8
|
66 67 68 |
return wm831x_device_suspend(wm831x); } |
523d9cfbb
|
69 70 71 72 73 74 |
static void wm831x_spi_shutdown(struct spi_device *spi) { struct wm831x *wm831x = dev_get_drvdata(&spi->dev); wm831x_device_shutdown(wm831x); } |
87d1906df
|
75 76 77 78 |
static const struct dev_pm_ops wm831x_spi_pm = { .freeze = wm831x_spi_suspend, .suspend = wm831x_spi_suspend, }; |
5570c2f70
|
79 80 81 82 83 84 85 86 87 |
static const struct spi_device_id wm831x_spi_ids[] = { { "wm8310", WM8310 }, { "wm8311", WM8311 }, { "wm8312", WM8312 }, { "wm8320", WM8320 }, { "wm8321", WM8321 }, { "wm8325", WM8325 }, { "wm8326", WM8326 }, { }, |
2aa13b9e8
|
88 |
}; |
5570c2f70
|
89 |
MODULE_DEVICE_TABLE(spi, wm831x_spi_id); |
2aa13b9e8
|
90 |
|
5570c2f70
|
91 |
static struct spi_driver wm831x_spi_driver = { |
2aa13b9e8
|
92 |
.driver = { |
5570c2f70
|
93 |
.name = "wm831x", |
412dc11d3
|
94 95 |
.bus = &spi_bus_type, .owner = THIS_MODULE, |
87d1906df
|
96 |
.pm = &wm831x_spi_pm, |
412dc11d3
|
97 |
}, |
5570c2f70
|
98 |
.id_table = wm831x_spi_ids, |
412dc11d3
|
99 100 |
.probe = wm831x_spi_probe, .remove = __devexit_p(wm831x_spi_remove), |
523d9cfbb
|
101 |
.shutdown = wm831x_spi_shutdown, |
412dc11d3
|
102 |
}; |
2aa13b9e8
|
103 104 105 |
static int __init wm831x_spi_init(void) { int ret; |
5570c2f70
|
106 |
ret = spi_register_driver(&wm831x_spi_driver); |
412dc11d3
|
107 |
if (ret != 0) |
5570c2f70
|
108 109 |
pr_err("Failed to register WM831x SPI driver: %d ", ret); |
412dc11d3
|
110 |
|
2aa13b9e8
|
111 112 113 114 115 116 |
return 0; } subsys_initcall(wm831x_spi_init); static void __exit wm831x_spi_exit(void) { |
5570c2f70
|
117 |
spi_unregister_driver(&wm831x_spi_driver); |
2aa13b9e8
|
118 119 120 121 122 123 |
} module_exit(wm831x_spi_exit); MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Mark Brown"); |