blob: 189efaea054cba87e1b485ad9273ebcd6439938a [file] [log] [blame]
Rajmohan Mani9bbf6a12017-07-28 17:30:24 -07001/*
2 * TPS68470 chip Parent driver
3 *
4 * Copyright (C) 2017 Intel Corporation
5 *
6 * Authors:
7 * Rajmohan Mani <rajmohan.mani@intel.com>
8 * Tianshu Qiu <tian.shu.qiu@intel.com>
9 * Jian Xu Zheng <jian.xu.zheng@intel.com>
10 * Yuning Pu <yuning.pu@intel.com>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation version 2.
15 *
16 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
17 * kind, whether express or implied; without even the implied warranty
18 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */
21
22#include <linux/acpi.h>
23#include <linux/delay.h>
24#include <linux/i2c.h>
25#include <linux/init.h>
26#include <linux/mfd/core.h>
27#include <linux/mfd/tps68470.h>
28#include <linux/regmap.h>
29
30static const struct mfd_cell tps68470s[] = {
31 { .name = "tps68470-gpio" },
32 { .name = "tps68470_pmic_opregion" },
33};
34
35static const struct regmap_config tps68470_regmap_config = {
36 .reg_bits = 8,
37 .val_bits = 8,
38 .max_register = TPS68470_REG_MAX,
39};
40
41static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
42{
43 unsigned int version;
44 int ret;
45
46 /* Force software reset */
47 ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
48 if (ret)
49 return ret;
50
51 ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
52 if (ret) {
53 dev_err(dev, "Failed to read revision register: %d\n", ret);
54 return ret;
55 }
56
57 dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
58
59 return 0;
60}
61
62static int tps68470_probe(struct i2c_client *client)
63{
64 struct device *dev = &client->dev;
65 struct regmap *regmap;
66 int ret;
67
68 regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
69 if (IS_ERR(regmap)) {
70 dev_err(dev, "devm_regmap_init_i2c Error %ld\n",
71 PTR_ERR(regmap));
72 return PTR_ERR(regmap);
73 }
74
75 i2c_set_clientdata(client, regmap);
76
77 ret = tps68470_chip_init(dev, regmap);
78 if (ret < 0) {
79 dev_err(dev, "TPS68470 Init Error %d\n", ret);
80 return ret;
81 }
82
83 ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s,
84 ARRAY_SIZE(tps68470s), NULL, 0, NULL);
85 if (ret < 0) {
86 dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret);
87 return ret;
88 }
89
90 return 0;
91}
92
93static const struct acpi_device_id tps68470_acpi_ids[] = {
94 {"INT3472"},
95 {},
96};
97MODULE_DEVICE_TABLE(acpi, tps68470_acpi_ids);
98
99static struct i2c_driver tps68470_driver = {
100 .driver = {
101 .name = "tps68470",
102 .acpi_match_table = tps68470_acpi_ids,
103 },
104 .probe_new = tps68470_probe,
105};
106builtin_i2c_driver(tps68470_driver);