staging: iio: adis16350 add _index attribute registration
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / mfd / max8998.c
blob73e6f5c4efc9c46ab8589ed5ad9bba5ee10e0bd7
1 /*
2 * max8698.c - mfd core driver for the Maxim 8998
4 * Copyright (C) 2009-2010 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Marek Szyprowski <m.szyprowski@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/i2c.h>
28 #include <linux/mutex.h>
29 #include <linux/mfd/core.h>
30 #include <linux/mfd/max8998.h>
31 #include <linux/mfd/max8998-private.h>
33 static struct mfd_cell max8998_devs[] = {
35 .name = "max8998-pmic",
39 static int max8998_i2c_device_read(struct max8998_dev *max8998, u8 reg, u8 *dest)
41 struct i2c_client *client = max8998->i2c_client;
42 int ret;
44 mutex_lock(&max8998->iolock);
45 ret = i2c_smbus_read_byte_data(client, reg);
46 mutex_unlock(&max8998->iolock);
47 if (ret < 0)
48 return ret;
50 ret &= 0xff;
51 *dest = ret;
52 return 0;
55 static int max8998_i2c_device_write(struct max8998_dev *max8998, u8 reg, u8 value)
57 struct i2c_client *client = max8998->i2c_client;
58 int ret;
60 mutex_lock(&max8998->iolock);
61 ret = i2c_smbus_write_byte_data(client, reg, value);
62 mutex_unlock(&max8998->iolock);
63 return ret;
66 static int max8998_i2c_device_update(struct max8998_dev *max8998, u8 reg,
67 u8 val, u8 mask)
69 struct i2c_client *client = max8998->i2c_client;
70 int ret;
72 mutex_lock(&max8998->iolock);
73 ret = i2c_smbus_read_byte_data(client, reg);
74 if (ret >= 0) {
75 u8 old_val = ret & 0xff;
76 u8 new_val = (val & mask) | (old_val & (~mask));
77 ret = i2c_smbus_write_byte_data(client, reg, new_val);
78 if (ret >= 0)
79 ret = 0;
81 mutex_unlock(&max8998->iolock);
82 return ret;
85 static int max8998_i2c_probe(struct i2c_client *i2c,
86 const struct i2c_device_id *id)
88 struct max8998_dev *max8998;
89 int ret = 0;
91 max8998 = kzalloc(sizeof(struct max8998_dev), GFP_KERNEL);
92 if (max8998 == NULL)
93 return -ENOMEM;
95 i2c_set_clientdata(i2c, max8998);
96 max8998->dev = &i2c->dev;
97 max8998->i2c_client = i2c;
98 max8998->dev_read = max8998_i2c_device_read;
99 max8998->dev_write = max8998_i2c_device_write;
100 max8998->dev_update = max8998_i2c_device_update;
101 mutex_init(&max8998->iolock);
103 ret = mfd_add_devices(max8998->dev, -1,
104 max8998_devs, ARRAY_SIZE(max8998_devs),
105 NULL, 0);
106 if (ret < 0)
107 goto err;
109 return ret;
111 err:
112 mfd_remove_devices(max8998->dev);
113 kfree(max8998);
114 return ret;
117 static int max8998_i2c_remove(struct i2c_client *i2c)
119 struct max8998_dev *max8998 = i2c_get_clientdata(i2c);
121 mfd_remove_devices(max8998->dev);
122 kfree(max8998);
124 return 0;
127 static const struct i2c_device_id max8998_i2c_id[] = {
128 { "max8998", 0 },
131 MODULE_DEVICE_TABLE(i2c, max8998_i2c_id);
133 static struct i2c_driver max8998_i2c_driver = {
134 .driver = {
135 .name = "max8998",
136 .owner = THIS_MODULE,
138 .probe = max8998_i2c_probe,
139 .remove = max8998_i2c_remove,
140 .id_table = max8998_i2c_id,
143 static int __init max8998_i2c_init(void)
145 return i2c_add_driver(&max8998_i2c_driver);
147 /* init early so consumer devices can complete system boot */
148 subsys_initcall(max8998_i2c_init);
150 static void __exit max8998_i2c_exit(void)
152 i2c_del_driver(&max8998_i2c_driver);
154 module_exit(max8998_i2c_exit);
156 MODULE_DESCRIPTION("MAXIM 8998 multi-function core driver");
157 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
158 MODULE_LICENSE("GPL");