blob: cd18c09827ef1f601082740703017c1b0b5f169c [file] [log] [blame]
Sourav Poddar82843282012-10-01 16:31:22 +05301/*
2 * TI SMSC MFD Driver
3 *
4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Sourav Poddar <sourav.poddar@ti.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; GPL v2.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
Sourav Poddar82843282012-10-01 16:31:22 +053016#include <linux/slab.h>
17#include <linux/i2c.h>
18#include <linux/gpio.h>
19#include <linux/workqueue.h>
20#include <linux/irq.h>
21#include <linux/regmap.h>
22#include <linux/err.h>
23#include <linux/mfd/core.h>
24#include <linux/mfd/smsc.h>
25#include <linux/of_platform.h>
26
Krzysztof Kozlowski486212f2015-01-05 10:01:29 +010027static const struct regmap_config smsc_regmap_config = {
Sourav Poddar82843282012-10-01 16:31:22 +053028 .reg_bits = 8,
29 .val_bits = 8,
30 .max_register = SMSC_VEN_ID_H,
31 .cache_type = REGCACHE_RBTREE,
32};
33
34static int smsc_i2c_probe(struct i2c_client *i2c,
35 const struct i2c_device_id *id)
36{
37 struct smsc *smsc;
38 int devid, rev, venid_l, venid_h;
Markus Elfring53b34b82016-06-26 14:14:54 +020039 int ret;
Sourav Poddar82843282012-10-01 16:31:22 +053040
41 smsc = devm_kzalloc(&i2c->dev, sizeof(struct smsc),
42 GFP_KERNEL);
43 if (!smsc) {
44 dev_err(&i2c->dev, "smsc mfd driver memory allocation failed\n");
45 return -ENOMEM;
46 }
47
48 smsc->regmap = devm_regmap_init_i2c(i2c, &smsc_regmap_config);
Markus Elfring4dc03d02016-06-26 14:30:46 +020049 if (IS_ERR(smsc->regmap))
50 return PTR_ERR(smsc->regmap);
Sourav Poddar82843282012-10-01 16:31:22 +053051
52 i2c_set_clientdata(i2c, smsc);
53 smsc->dev = &i2c->dev;
54
55#ifdef CONFIG_OF
56 of_property_read_u32(i2c->dev.of_node, "clock", &smsc->clk);
57#endif
58
59 regmap_read(smsc->regmap, SMSC_DEV_ID, &devid);
60 regmap_read(smsc->regmap, SMSC_DEV_REV, &rev);
61 regmap_read(smsc->regmap, SMSC_VEN_ID_L, &venid_l);
62 regmap_read(smsc->regmap, SMSC_VEN_ID_H, &venid_h);
63
64 dev_info(&i2c->dev, "SMSCxxx devid: %02x rev: %02x venid: %02x\n",
65 devid, rev, (venid_h << 8) | venid_l);
66
67 ret = regmap_write(smsc->regmap, SMSC_CLK_CTRL, smsc->clk);
68 if (ret)
Markus Elfring4dc03d02016-06-26 14:30:46 +020069 return ret;
Sourav Poddar82843282012-10-01 16:31:22 +053070
71#ifdef CONFIG_OF
72 if (i2c->dev.of_node)
73 ret = of_platform_populate(i2c->dev.of_node,
74 NULL, NULL, &i2c->dev);
75#endif
76
Sourav Poddar82843282012-10-01 16:31:22 +053077 return ret;
78}
79
Sourav Poddar82843282012-10-01 16:31:22 +053080static const struct i2c_device_id smsc_i2c_id[] = {
81 { "smscece1099", 0},
82 {},
83};
84MODULE_DEVICE_TABLE(i2c, smsc_i2c_id);
85
86static struct i2c_driver smsc_i2c_driver = {
87 .driver = {
88 .name = "smsc",
Sourav Poddar82843282012-10-01 16:31:22 +053089 },
90 .probe = smsc_i2c_probe,
Sourav Poddar82843282012-10-01 16:31:22 +053091 .id_table = smsc_i2c_id,
92};
93
94module_i2c_driver(smsc_i2c_driver);
95
96MODULE_AUTHOR("Sourav Poddar <sourav.poddar@ti.com>");
97MODULE_DESCRIPTION("SMSC chip multi-function driver");
98MODULE_LICENSE("GPL v2");