summaryrefslogtreecommitdiff
path: root/drivers/mfd/max8831.c
blob: 18f2042a866efb7c9ec2a41d097364782bbb3df6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * Base driver for Maxim MAX8831
 *
 * Copyright (c) 2008-2012, NVIDIA Corporation.
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/mfd/max8831.h>
#include <linux/slab.h>
#include <linux/regmap.h>
#include <linux/err.h>
#include <linux/mfd/core.h>

enum chips { max8831 };

static const struct i2c_device_id max8831_id[] = {
	{ "max8831", max8831 },
	{},
};
MODULE_DEVICE_TABLE(i2c, max8831_id);

static const struct regmap_config max8831_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = 0x3A,
};

static struct mfd_cell max8831_mfd_cells[] = {
	[MAX8831_ID_LED1] = {
		.name = "max8831_led_bl",
		.id = MAX8831_ID_LED1,
	},
	[MAX8831_ID_LED2] = {
		.name = "max8831_led_bl",
		.id = MAX8831_ID_LED2,
	},
	[MAX8831_ID_LED3] = {
		.name = "max8831_led_bl",
		.id = MAX8831_ID_LED3,
	},
	[MAX8831_ID_LED4] = {
		.name = "max8831_led_bl",
		.id = MAX8831_ID_LED4,
	},
	[MAX8831_ID_LED5] = {
		.name = "max8831_led_bl",
		.id = MAX8831_ID_LED5,
	},
	[MAX8831_BL_LEDS] = {
		.name = "max8831_display_bl",
		.id = MAX8831_BL_LEDS,
	},
};

static int max8831_probe(struct i2c_client *client,
	const struct i2c_device_id *id)
{
	struct max8831_platform_data *pdata = client->dev.platform_data;
	struct max8831_chip *chip;
	struct max8831_subdev_info *subdev;
	int ret;
	int i;

	chip = devm_kzalloc(&client->dev,
				sizeof(struct max8831_chip), GFP_KERNEL);
	if (chip == NULL)
		return -ENOMEM;

	chip->client = client;
	chip->dev = &client->dev;

	i2c_set_clientdata(client, chip);

	chip->regmap = devm_regmap_init_i2c(client, &max8831_regmap_config);
	if (IS_ERR(chip->regmap)) {
		ret = PTR_ERR(chip->regmap);
		dev_err(&client->dev, "regmap init failed: %d\n", ret);
		return ret;
	}

	for (i = 0; i < pdata->num_subdevs; i++) {
		subdev = &pdata->subdevs[i];
		max8831_mfd_cells[subdev->id].platform_data =
							subdev->platform_data;
		max8831_mfd_cells[subdev->id].pdata_size = subdev->pdata_size;
	}

	ret = mfd_add_devices(chip->dev, 0,
		      max8831_mfd_cells, ARRAY_SIZE(max8831_mfd_cells),
		      NULL, 0, NULL);
	if (ret < 0)
		goto failed;

	return 0;

failed:
	mfd_remove_devices(chip->dev);
	return ret;
}

static int max8831_remove(struct i2c_client *client)
{
	struct max8831_chip *chip = i2c_get_clientdata(client);
	mfd_remove_devices(chip->dev);
	return 0;
}

static struct i2c_driver max8831_driver = {
	.driver = {
		.name	= "max8831",
		.owner	= THIS_MODULE,
	},
	.probe	= max8831_probe,
	.remove	= max8831_remove,
	.id_table = max8831_id,
};
module_i2c_driver(max8831_driver);

MODULE_AUTHOR("Chaitanya Bandi<bandik@nvidia.com>");
MODULE_DESCRIPTION("MAX8831 MFD driver");
MODULE_LICENSE("GPL v2");