• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * TPS68470 chip Parent driver
4  *
5  * Copyright (C) 2017 Intel Corporation
6  *
7  * Authors:
8  *	Rajmohan Mani <rajmohan.mani@intel.com>
9  *	Tianshu Qiu <tian.shu.qiu@intel.com>
10  *	Jian Xu Zheng <jian.xu.zheng@intel.com>
11  *	Yuning Pu <yuning.pu@intel.com>
12  */
13 
14 #include <linux/acpi.h>
15 #include <linux/delay.h>
16 #include <linux/i2c.h>
17 #include <linux/init.h>
18 #include <linux/mfd/core.h>
19 #include <linux/mfd/tps68470.h>
20 #include <linux/regmap.h>
21 
22 static const struct mfd_cell tps68470s[] = {
23 	{ .name = "tps68470-gpio" },
24 	{ .name = "tps68470_pmic_opregion" },
25 };
26 
27 static const struct regmap_config tps68470_regmap_config = {
28 	.reg_bits = 8,
29 	.val_bits = 8,
30 	.max_register = TPS68470_REG_MAX,
31 };
32 
tps68470_chip_init(struct device * dev,struct regmap * regmap)33 static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
34 {
35 	unsigned int version;
36 	int ret;
37 
38 	/* Force software reset */
39 	ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
40 	if (ret)
41 		return ret;
42 
43 	ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
44 	if (ret) {
45 		dev_err(dev, "Failed to read revision register: %d\n", ret);
46 		return ret;
47 	}
48 
49 	dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
50 
51 	return 0;
52 }
53 
tps68470_probe(struct i2c_client * client)54 static int tps68470_probe(struct i2c_client *client)
55 {
56 	struct device *dev = &client->dev;
57 	struct regmap *regmap;
58 	int ret;
59 
60 	regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
61 	if (IS_ERR(regmap)) {
62 		dev_err(dev, "devm_regmap_init_i2c Error %ld\n",
63 			PTR_ERR(regmap));
64 		return PTR_ERR(regmap);
65 	}
66 
67 	i2c_set_clientdata(client, regmap);
68 
69 	ret = tps68470_chip_init(dev, regmap);
70 	if (ret < 0) {
71 		dev_err(dev, "TPS68470 Init Error %d\n", ret);
72 		return ret;
73 	}
74 
75 	ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s,
76 			      ARRAY_SIZE(tps68470s), NULL, 0, NULL);
77 	if (ret < 0) {
78 		dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret);
79 		return ret;
80 	}
81 
82 	return 0;
83 }
84 
85 static const struct acpi_device_id tps68470_acpi_ids[] = {
86 	{"INT3472"},
87 	{},
88 };
89 
90 static struct i2c_driver tps68470_driver = {
91 	.driver = {
92 		   .name = "tps68470",
93 		   .acpi_match_table = tps68470_acpi_ids,
94 	},
95 	.probe_new = tps68470_probe,
96 };
97 builtin_i2c_driver(tps68470_driver);
98