2 * Base driver for Maxim MAX8831
4 * Copyright (c) 2008-2012, NVIDIA Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/i2c.h>
24 #include <linux/mfd/max8831.h>
25 #include <linux/slab.h>
26 #include <linux/regmap.h>
27 #include <linux/err.h>
28 #include <linux/mfd/core.h>
30 enum chips { max8831 };
32 static const struct i2c_device_id max8831_id[] = {
33 { "max8831", max8831 },
36 MODULE_DEVICE_TABLE(i2c, max8831_id);
38 static const struct regmap_config max8831_regmap_config = {
44 static struct mfd_cell max8831_mfd_cells[] = {
46 .name = "max8831_led_bl",
47 .id = MAX8831_ID_LED1,
50 .name = "max8831_led_bl",
51 .id = MAX8831_ID_LED2,
54 .name = "max8831_led_bl",
55 .id = MAX8831_ID_LED3,
58 .name = "max8831_led_bl",
59 .id = MAX8831_ID_LED4,
62 .name = "max8831_led_bl",
63 .id = MAX8831_ID_LED5,
66 .name = "max8831_display_bl",
67 .id = MAX8831_BL_LEDS,
71 static int max8831_probe(struct i2c_client *client,
72 const struct i2c_device_id *id)
74 struct max8831_platform_data *pdata = client->dev.platform_data;
75 struct max8831_chip *chip;
76 struct max8831_subdev_info *subdev;
80 chip = devm_kzalloc(&client->dev,
81 sizeof(struct max8831_chip), GFP_KERNEL);
85 chip->client = client;
86 chip->dev = &client->dev;
88 i2c_set_clientdata(client, chip);
90 chip->regmap = devm_regmap_init_i2c(client, &max8831_regmap_config);
91 if (IS_ERR(chip->regmap)) {
92 ret = PTR_ERR(chip->regmap);
93 dev_err(&client->dev, "regmap init failed: %d\n", ret);
97 for (i = 0; i < pdata->num_subdevs; i++) {
98 subdev = &pdata->subdevs[i];
99 max8831_mfd_cells[subdev->id].platform_data =
100 subdev->platform_data;
101 max8831_mfd_cells[subdev->id].pdata_size = subdev->pdata_size;
104 ret = mfd_add_devices(chip->dev, 0,
105 max8831_mfd_cells, ARRAY_SIZE(max8831_mfd_cells),
113 mfd_remove_devices(chip->dev);
117 static int max8831_remove(struct i2c_client *client)
119 struct max8831_chip *chip = i2c_get_clientdata(client);
120 mfd_remove_devices(chip->dev);
124 static struct i2c_driver max8831_driver = {
127 .owner = THIS_MODULE,
129 .probe = max8831_probe,
130 .remove = max8831_remove,
131 .id_table = max8831_id,
133 module_i2c_driver(max8831_driver);
135 MODULE_AUTHOR("Chaitanya Bandi<bandik@nvidia.com>");
136 MODULE_DESCRIPTION("MAX8831 MFD driver");
137 MODULE_LICENSE("GPL v2");