xref: /linux/drivers/dpll/zl3073x/i2c.c (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include <linux/dev_printk.h>
4 #include <linux/err.h>
5 #include <linux/i2c.h>
6 #include <linux/module.h>
7 #include <linux/regmap.h>
8 
9 #include "core.h"
10 
zl3073x_i2c_probe(struct i2c_client * client)11 static int zl3073x_i2c_probe(struct i2c_client *client)
12 {
13 	struct device *dev = &client->dev;
14 	struct zl3073x_dev *zldev;
15 
16 	zldev = zl3073x_devm_alloc(dev);
17 	if (IS_ERR(zldev))
18 		return PTR_ERR(zldev);
19 
20 	zldev->regmap = devm_regmap_init_i2c(client, &zl3073x_regmap_config);
21 	if (IS_ERR(zldev->regmap))
22 		return dev_err_probe(dev, PTR_ERR(zldev->regmap),
23 				     "Failed to initialize regmap\n");
24 
25 	return zl3073x_dev_probe(zldev, i2c_get_match_data(client));
26 }
27 
28 static const struct i2c_device_id zl3073x_i2c_id[] = {
29 	{
30 		.name = "zl30731",
31 		.driver_data = (kernel_ulong_t)&zl30731_chip_info,
32 	},
33 	{
34 		.name = "zl30732",
35 		.driver_data = (kernel_ulong_t)&zl30732_chip_info,
36 	},
37 	{
38 		.name = "zl30733",
39 		.driver_data = (kernel_ulong_t)&zl30733_chip_info,
40 	},
41 	{
42 		.name = "zl30734",
43 		.driver_data = (kernel_ulong_t)&zl30734_chip_info,
44 	},
45 	{
46 		.name = "zl30735",
47 		.driver_data = (kernel_ulong_t)&zl30735_chip_info,
48 	},
49 	{ /* sentinel */ }
50 };
51 MODULE_DEVICE_TABLE(i2c, zl3073x_i2c_id);
52 
53 static const struct of_device_id zl3073x_i2c_of_match[] = {
54 	{ .compatible = "microchip,zl30731", .data = &zl30731_chip_info },
55 	{ .compatible = "microchip,zl30732", .data = &zl30732_chip_info },
56 	{ .compatible = "microchip,zl30733", .data = &zl30733_chip_info },
57 	{ .compatible = "microchip,zl30734", .data = &zl30734_chip_info },
58 	{ .compatible = "microchip,zl30735", .data = &zl30735_chip_info },
59 	{ /* sentinel */ }
60 };
61 MODULE_DEVICE_TABLE(of, zl3073x_i2c_of_match);
62 
63 static struct i2c_driver zl3073x_i2c_driver = {
64 	.driver = {
65 		.name = "zl3073x-i2c",
66 		.of_match_table = zl3073x_i2c_of_match,
67 	},
68 	.probe = zl3073x_i2c_probe,
69 	.id_table = zl3073x_i2c_id,
70 };
71 module_i2c_driver(zl3073x_i2c_driver);
72 
73 MODULE_AUTHOR("Ivan Vecera <ivecera@redhat.com>");
74 MODULE_DESCRIPTION("Microchip ZL3073x I2C driver");
75 MODULE_IMPORT_NS("ZL3073X");
76 MODULE_LICENSE("GPL");
77