Blame view

drivers/mfd/mc13xxx-i2c.c 2.61 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
2
3
4
  /*
   * Copyright 2009-2010 Creative Product Design
   * Marc Reilly marc@cpdesign.com.au
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
5
6
7
8
9
   */
  
  #include <linux/slab.h>
  #include <linux/module.h>
  #include <linux/platform_device.h>
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <linux/mfd/core.h>
  #include <linux/mfd/mc13xxx.h>
  #include <linux/of.h>
  #include <linux/of_device.h>
  #include <linux/of_gpio.h>
  #include <linux/i2c.h>
  #include <linux/err.h>
  
  #include "mc13xxx.h"
  
  static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
  	{
  		.name = "mc13892",
cd0f34b08   Uwe Kleine-König   mfd: mc13xxx: Cha...
23
  		.driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
24
  	}, {
0312e024d   Uwe Kleine-König   mfd: mc13xxx: Add...
25
26
  		.name = "mc34708",
  		.driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
27
28
29
30
31
32
33
34
35
  	}, {
  		/* sentinel */
  	}
  };
  MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
  
  static const struct of_device_id mc13xxx_dt_ids[] = {
  	{
  		.compatible = "fsl,mc13892",
cd0f34b08   Uwe Kleine-König   mfd: mc13xxx: Cha...
36
  		.data = &mc13xxx_variant_mc13892,
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
37
  	}, {
0312e024d   Uwe Kleine-König   mfd: mc13xxx: Add...
38
39
  		.compatible = "fsl,mc34708",
  		.data = &mc13xxx_variant_mc34708,
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
40
41
42
43
44
  	}, {
  		/* sentinel */
  	}
  };
  MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
18dd21ab1   Krzysztof Kozlowski   mfd: mc13xxx: i2c...
45
  static const struct regmap_config mc13xxx_regmap_i2c_config = {
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
46
47
48
49
50
51
52
53
54
55
56
  	.reg_bits = 8,
  	.val_bits = 24,
  
  	.max_register = MC13XXX_NUMREGS,
  
  	.cache_type = REGCACHE_NONE,
  };
  
  static int mc13xxx_i2c_probe(struct i2c_client *client,
  		const struct i2c_device_id *id)
  {
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
57
  	struct mc13xxx *mc13xxx;
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
58
  	int ret;
e7c706b1e   Axel Lin   mfd: Use devm_* A...
59
  	mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
60
61
62
63
  	if (!mc13xxx)
  		return -ENOMEM;
  
  	dev_set_drvdata(&client->dev, mc13xxx);
db9ef449a   Alexander Shiyan   mfd: mc13xxx: Sim...
64
  	mc13xxx->irq = client->irq;
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
65

e7c706b1e   Axel Lin   mfd: Use devm_* A...
66
67
  	mc13xxx->regmap = devm_regmap_init_i2c(client,
  					       &mc13xxx_regmap_i2c_config);
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
68
69
  	if (IS_ERR(mc13xxx->regmap)) {
  		ret = PTR_ERR(mc13xxx->regmap);
db9ef449a   Alexander Shiyan   mfd: mc13xxx: Sim...
70
71
  		dev_err(&client->dev, "Failed to initialize regmap: %d
  ", ret);
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
72
73
  		return ret;
  	}
cd0f34b08   Uwe Kleine-König   mfd: mc13xxx: Cha...
74
75
76
77
78
79
80
  	if (client->dev.of_node) {
  		const struct of_device_id *of_id =
  			of_match_device(mc13xxx_dt_ids, &client->dev);
  		mc13xxx->variant = of_id->data;
  	} else {
  		mc13xxx->variant = (void *)id->driver_data;
  	}
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
81

db9ef449a   Alexander Shiyan   mfd: mc13xxx: Sim...
82
  	return mc13xxx_common_init(&client->dev);
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
83
  }
4740f73fe   Bill Pemberton   mfd: remove use o...
84
  static int mc13xxx_i2c_remove(struct i2c_client *client)
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
85
  {
db9ef449a   Alexander Shiyan   mfd: mc13xxx: Sim...
86
  	return mc13xxx_common_exit(&client->dev);
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
87
88
89
90
91
  }
  
  static struct i2c_driver mc13xxx_i2c_driver = {
  	.id_table = mc13xxx_i2c_device_id,
  	.driver = {
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
92
93
94
95
  		.name = "mc13xxx",
  		.of_match_table = mc13xxx_dt_ids,
  	},
  	.probe = mc13xxx_i2c_probe,
84449216b   Bill Pemberton   mfd: remove use o...
96
  	.remove = mc13xxx_i2c_remove,
df3df6469   Marc Reilly   mfd: Add mc13xxx ...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  };
  
  static int __init mc13xxx_i2c_init(void)
  {
  	return i2c_add_driver(&mc13xxx_i2c_driver);
  }
  subsys_initcall(mc13xxx_i2c_init);
  
  static void __exit mc13xxx_i2c_exit(void)
  {
  	i2c_del_driver(&mc13xxx_i2c_driver);
  }
  module_exit(mc13xxx_i2c_exit);
  
  MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
  MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
  MODULE_LICENSE("GPL v2");