aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/wm831x-core.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2010-10-19 17:57:56 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2010-10-28 18:30:24 -0400
commite5b486841d572c5ac83c798f82f4f67cbbac5320 (patch)
tree162b0c3f058fb461515a06614711a717d6807bb8 /drivers/mfd/wm831x-core.c
parent00969f23dae70f62d7ce3f7abbbfb6d09ef92739 (diff)
mfd: Factor out WM831x I2C I/O from the core driver
In preparation for the addition of SPI support for the WM831x move the I2C specific code into a separate file with a separate Kconfig option so the I2C support can be excluded from the build. Also update the 1133-EV1 PMIC module support for SMDK6410 to use the new symbol. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/wm831x-core.c')
-rw-r--r--drivers/mfd/wm831x-core.c138
1 files changed, 4 insertions, 134 deletions
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c
index ad36579bc815..7d2563fc15c6 100644
--- a/drivers/mfd/wm831x-core.c
+++ b/drivers/mfd/wm831x-core.c
@@ -14,7 +14,6 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/i2c.h>
18#include <linux/bcd.h> 17#include <linux/bcd.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/mfd/core.h> 19#include <linux/mfd/core.h>
@@ -90,15 +89,6 @@ int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
90}; 89};
91EXPORT_SYMBOL_GPL(wm831x_isinkv_values); 90EXPORT_SYMBOL_GPL(wm831x_isinkv_values);
92 91
93enum wm831x_parent {
94 WM8310 = 0x8310,
95 WM8311 = 0x8311,
96 WM8312 = 0x8312,
97 WM8320 = 0x8320,
98 WM8321 = 0x8321,
99 WM8325 = 0x8325,
100};
101
102static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg) 92static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
103{ 93{
104 if (!wm831x->locked) 94 if (!wm831x->locked)
@@ -1447,7 +1437,7 @@ static struct mfd_cell backlight_devs[] = {
1447/* 1437/*
1448 * Instantiate the generic non-control parts of the device. 1438 * Instantiate the generic non-control parts of the device.
1449 */ 1439 */
1450static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) 1440int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
1451{ 1441{
1452 struct wm831x_pdata *pdata = wm831x->dev->platform_data; 1442 struct wm831x_pdata *pdata = wm831x->dev->platform_data;
1453 int rev; 1443 int rev;
@@ -1673,7 +1663,7 @@ err:
1673 return ret; 1663 return ret;
1674} 1664}
1675 1665
1676static void wm831x_device_exit(struct wm831x *wm831x) 1666void wm831x_device_exit(struct wm831x *wm831x)
1677{ 1667{
1678 wm831x_otp_exit(wm831x); 1668 wm831x_otp_exit(wm831x);
1679 mfd_remove_devices(wm831x->dev); 1669 mfd_remove_devices(wm831x->dev);
@@ -1683,7 +1673,7 @@ static void wm831x_device_exit(struct wm831x *wm831x)
1683 kfree(wm831x); 1673 kfree(wm831x);
1684} 1674}
1685 1675
1686static int wm831x_device_suspend(struct wm831x *wm831x) 1676int wm831x_device_suspend(struct wm831x *wm831x)
1687{ 1677{
1688 int reg, mask; 1678 int reg, mask;
1689 1679
@@ -1719,126 +1709,6 @@ static int wm831x_device_suspend(struct wm831x *wm831x)
1719 return 0; 1709 return 0;
1720} 1710}
1721 1711
1722static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg, 1712MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
1723 int bytes, void *dest)
1724{
1725 struct i2c_client *i2c = wm831x->control_data;
1726 int ret;
1727 u16 r = cpu_to_be16(reg);
1728
1729 ret = i2c_master_send(i2c, (unsigned char *)&r, 2);
1730 if (ret < 0)
1731 return ret;
1732 if (ret != 2)
1733 return -EIO;
1734
1735 ret = i2c_master_recv(i2c, dest, bytes);
1736 if (ret < 0)
1737 return ret;
1738 if (ret != bytes)
1739 return -EIO;
1740 return 0;
1741}
1742
1743/* Currently we allocate the write buffer on the stack; this is OK for
1744 * small writes - if we need to do large writes this will need to be
1745 * revised.
1746 */
1747static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg,
1748 int bytes, void *src)
1749{
1750 struct i2c_client *i2c = wm831x->control_data;
1751 unsigned char msg[bytes + 2];
1752 int ret;
1753
1754 reg = cpu_to_be16(reg);
1755 memcpy(&msg[0], &reg, 2);
1756 memcpy(&msg[2], src, bytes);
1757
1758 ret = i2c_master_send(i2c, msg, bytes + 2);
1759 if (ret < 0)
1760 return ret;
1761 if (ret < bytes + 2)
1762 return -EIO;
1763
1764 return 0;
1765}
1766
1767static int wm831x_i2c_probe(struct i2c_client *i2c,
1768 const struct i2c_device_id *id)
1769{
1770 struct wm831x *wm831x;
1771
1772 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
1773 if (wm831x == NULL)
1774 return -ENOMEM;
1775
1776 i2c_set_clientdata(i2c, wm831x);
1777 wm831x->dev = &i2c->dev;
1778 wm831x->control_data = i2c;
1779 wm831x->read_dev = wm831x_i2c_read_device;
1780 wm831x->write_dev = wm831x_i2c_write_device;
1781
1782 return wm831x_device_init(wm831x, id->driver_data, i2c->irq);
1783}
1784
1785static int wm831x_i2c_remove(struct i2c_client *i2c)
1786{
1787 struct wm831x *wm831x = i2c_get_clientdata(i2c);
1788
1789 wm831x_device_exit(wm831x);
1790
1791 return 0;
1792}
1793
1794static int wm831x_i2c_suspend(struct i2c_client *i2c, pm_message_t mesg)
1795{
1796 struct wm831x *wm831x = i2c_get_clientdata(i2c);
1797
1798 return wm831x_device_suspend(wm831x);
1799}
1800
1801static const struct i2c_device_id wm831x_i2c_id[] = {
1802 { "wm8310", WM8310 },
1803 { "wm8311", WM8311 },
1804 { "wm8312", WM8312 },
1805 { "wm8320", WM8320 },
1806 { "wm8321", WM8321 },
1807 { "wm8325", WM8325 },
1808 { }
1809};
1810MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
1811
1812
1813static struct i2c_driver wm831x_i2c_driver = {
1814 .driver = {
1815 .name = "wm831x",
1816 .owner = THIS_MODULE,
1817 },
1818 .probe = wm831x_i2c_probe,
1819 .remove = wm831x_i2c_remove,
1820 .suspend = wm831x_i2c_suspend,
1821 .id_table = wm831x_i2c_id,
1822};
1823
1824static int __init wm831x_i2c_init(void)
1825{
1826 int ret;
1827
1828 ret = i2c_add_driver(&wm831x_i2c_driver);
1829 if (ret != 0)
1830 pr_err("Failed to register wm831x I2C driver: %d\n", ret);
1831
1832 return ret;
1833}
1834subsys_initcall(wm831x_i2c_init);
1835
1836static void __exit wm831x_i2c_exit(void)
1837{
1838 i2c_del_driver(&wm831x_i2c_driver);
1839}
1840module_exit(wm831x_i2c_exit);
1841
1842MODULE_DESCRIPTION("I2C support for the WM831X AudioPlus PMIC");
1843MODULE_LICENSE("GPL"); 1713MODULE_LICENSE("GPL");
1844MODULE_AUTHOR("Mark Brown"); 1714MODULE_AUTHOR("Mark Brown");