Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * wm831x-spi.c -- SPI access for Wolfson WM831x PMICs |
| 3 | * |
| 4 | * Copyright 2009,2010 Wolfson Microelectronics PLC. |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
Mark Brown | 87d1906 | 2011-02-01 11:46:12 +0000 | [diff] [blame] | 17 | #include <linux/pm.h> |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 18 | #include <linux/spi/spi.h> |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 19 | #include <linux/regmap.h> |
| 20 | #include <linux/err.h> |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 21 | |
| 22 | #include <linux/mfd/wm831x/core.h> |
| 23 | |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 24 | static int __devinit wm831x_spi_probe(struct spi_device *spi) |
| 25 | { |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 26 | const struct spi_device_id *id = spi_get_device_id(spi); |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 27 | struct wm831x *wm831x; |
| 28 | enum wm831x_parent type; |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 29 | int ret; |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 30 | |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 31 | type = (enum wm831x_parent)id->driver_data; |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 32 | |
Mark Brown | d48cbb7 | 2011-10-25 14:47:40 +0200 | [diff] [blame] | 33 | wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL); |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 34 | if (wm831x == NULL) |
| 35 | return -ENOMEM; |
| 36 | |
| 37 | spi->bits_per_word = 16; |
| 38 | spi->mode = SPI_MODE_0; |
| 39 | |
| 40 | dev_set_drvdata(&spi->dev, wm831x); |
| 41 | wm831x->dev = &spi->dev; |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 42 | |
Mark Brown | 130a703 | 2012-01-30 20:08:06 +0000 | [diff] [blame] | 43 | wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config); |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 44 | if (IS_ERR(wm831x->regmap)) { |
| 45 | ret = PTR_ERR(wm831x->regmap); |
| 46 | dev_err(wm831x->dev, "Failed to allocate register map: %d\n", |
| 47 | ret); |
Mark Brown | 1df5981 | 2011-06-10 19:28:10 +0100 | [diff] [blame] | 48 | return ret; |
| 49 | } |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 50 | |
| 51 | return wm831x_device_init(wm831x, type, spi->irq); |
| 52 | } |
| 53 | |
| 54 | static int __devexit wm831x_spi_remove(struct spi_device *spi) |
| 55 | { |
| 56 | struct wm831x *wm831x = dev_get_drvdata(&spi->dev); |
| 57 | |
| 58 | wm831x_device_exit(wm831x); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Mark Brown | 87d1906 | 2011-02-01 11:46:12 +0000 | [diff] [blame] | 63 | static int wm831x_spi_suspend(struct device *dev) |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 64 | { |
Mark Brown | 87d1906 | 2011-02-01 11:46:12 +0000 | [diff] [blame] | 65 | struct wm831x *wm831x = dev_get_drvdata(dev); |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 66 | |
| 67 | return wm831x_device_suspend(wm831x); |
| 68 | } |
| 69 | |
Mark Brown | 523d9cf | 2011-09-15 18:54:53 +0200 | [diff] [blame] | 70 | static void wm831x_spi_shutdown(struct spi_device *spi) |
| 71 | { |
| 72 | struct wm831x *wm831x = dev_get_drvdata(&spi->dev); |
| 73 | |
| 74 | wm831x_device_shutdown(wm831x); |
| 75 | } |
| 76 | |
Mark Brown | 87d1906 | 2011-02-01 11:46:12 +0000 | [diff] [blame] | 77 | static const struct dev_pm_ops wm831x_spi_pm = { |
| 78 | .freeze = wm831x_spi_suspend, |
| 79 | .suspend = wm831x_spi_suspend, |
| 80 | }; |
| 81 | |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 82 | static const struct spi_device_id wm831x_spi_ids[] = { |
| 83 | { "wm8310", WM8310 }, |
| 84 | { "wm8311", WM8311 }, |
| 85 | { "wm8312", WM8312 }, |
| 86 | { "wm8320", WM8320 }, |
| 87 | { "wm8321", WM8321 }, |
| 88 | { "wm8325", WM8325 }, |
| 89 | { "wm8326", WM8326 }, |
| 90 | { }, |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 91 | }; |
Hai Dong | fe2afaa | 2012-02-24 16:03:00 -0600 | [diff] [blame] | 92 | MODULE_DEVICE_TABLE(spi, wm831x_spi_ids); |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 93 | |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 94 | static struct spi_driver wm831x_spi_driver = { |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 95 | .driver = { |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 96 | .name = "wm831x", |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 97 | .owner = THIS_MODULE, |
Mark Brown | 87d1906 | 2011-02-01 11:46:12 +0000 | [diff] [blame] | 98 | .pm = &wm831x_spi_pm, |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 99 | }, |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 100 | .id_table = wm831x_spi_ids, |
Mark Brown | 412dc11 | 2010-11-24 18:01:41 +0000 | [diff] [blame] | 101 | .probe = wm831x_spi_probe, |
| 102 | .remove = __devexit_p(wm831x_spi_remove), |
Mark Brown | 523d9cf | 2011-09-15 18:54:53 +0200 | [diff] [blame] | 103 | .shutdown = wm831x_spi_shutdown, |
Mark Brown | 412dc11 | 2010-11-24 18:01:41 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 106 | static int __init wm831x_spi_init(void) |
| 107 | { |
| 108 | int ret; |
| 109 | |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 110 | ret = spi_register_driver(&wm831x_spi_driver); |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 111 | if (ret != 0) |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 112 | pr_err("Failed to register WM831x SPI driver: %d\n", ret); |
Mark Brown | 412dc11 | 2010-11-24 18:01:41 +0000 | [diff] [blame] | 113 | |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | subsys_initcall(wm831x_spi_init); |
| 117 | |
| 118 | static void __exit wm831x_spi_exit(void) |
| 119 | { |
Mark Brown | 5570c2f | 2011-07-24 11:44:19 +0100 | [diff] [blame] | 120 | spi_unregister_driver(&wm831x_spi_driver); |
Mark Brown | 2aa13b9 | 2010-10-20 00:00:11 +0200 | [diff] [blame] | 121 | } |
| 122 | module_exit(wm831x_spi_exit); |
| 123 | |
| 124 | MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs"); |
| 125 | MODULE_LICENSE("GPL"); |
| 126 | MODULE_AUTHOR("Mark Brown"); |