aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/slaves/w1_bq27000.c
diff options
context:
space:
mode:
authorMadhusudhan Chikkature <madhu.cr@ti.com>2008-11-12 16:27:11 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-11-12 20:17:18 -0500
commitcfbc619033d3a2eee8f7aa9314e21b96cf34d399 (patch)
tree6b089a99602859245ab10075a882a1d698cc119e /drivers/w1/slaves/w1_bq27000.c
parent9f2bc79f7dd04adda1fc3be510c9b3d436f846c7 (diff)
hdq: bQ27000 HDQ Slave Interface Driver
Provide the BQ27000 slave interface driver. Signed-off-by: Madhusudhan Chikkature<madhu.cr@ti.com> Acked-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/w1/slaves/w1_bq27000.c')
-rw-r--r--drivers/w1/slaves/w1_bq27000.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/drivers/w1/slaves/w1_bq27000.c b/drivers/w1/slaves/w1_bq27000.c
new file mode 100644
index 000000000000..8f4c91f6c680
--- /dev/null
+++ b/drivers/w1/slaves/w1_bq27000.c
@@ -0,0 +1,123 @@
1/*
2 * drivers/w1/slaves/w1_bq27000.c
3 *
4 * Copyright (C) 2007 Texas Instruments, Inc.
5 *
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/device.h>
15#include <linux/types.h>
16#include <linux/platform_device.h>
17#include <linux/mutex.h>
18
19#include "../w1.h"
20#include "../w1_int.h"
21#include "../w1_family.h"
22
23#define HDQ_CMD_READ (0)
24#define HDQ_CMD_WRITE (1<<7)
25
26static int F_ID;
27
28void w1_bq27000_write(struct device *dev, u8 buf, u8 reg)
29{
30 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
31
32 if (!dev) {
33 pr_info("Could not obtain slave dev ptr\n");
34 return;
35 }
36
37 w1_write_8(sl->master, HDQ_CMD_WRITE | reg);
38 w1_write_8(sl->master, buf);
39}
40EXPORT_SYMBOL(w1_bq27000_write);
41
42int w1_bq27000_read(struct device *dev, u8 reg)
43{
44 u8 val;
45 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
46
47 if (!dev)
48 return 0;
49
50 w1_write_8(sl->master, HDQ_CMD_READ | reg);
51 val = w1_read_8(sl->master);
52
53 return val;
54}
55EXPORT_SYMBOL(w1_bq27000_read);
56
57static int w1_bq27000_add_slave(struct w1_slave *sl)
58{
59 int ret;
60 int id = 1;
61 struct platform_device *pdev;
62
63 pdev = platform_device_alloc("bq27000-battery", id);
64 if (!pdev) {
65 ret = -ENOMEM;
66 return ret;
67 }
68 pdev->dev.parent = &sl->dev;
69
70 ret = platform_device_add(pdev);
71 if (ret)
72 goto pdev_add_failed;
73
74 dev_set_drvdata(&sl->dev, pdev);
75
76 goto success;
77
78pdev_add_failed:
79 platform_device_unregister(pdev);
80success:
81 return ret;
82}
83
84static void w1_bq27000_remove_slave(struct w1_slave *sl)
85{
86 struct platform_device *pdev = dev_get_drvdata(&sl->dev);
87
88 platform_device_unregister(pdev);
89}
90
91static struct w1_family_ops w1_bq27000_fops = {
92 .add_slave = w1_bq27000_add_slave,
93 .remove_slave = w1_bq27000_remove_slave,
94};
95
96static struct w1_family w1_bq27000_family = {
97 .fid = 1,
98 .fops = &w1_bq27000_fops,
99};
100
101static int __init w1_bq27000_init(void)
102{
103 if (F_ID)
104 w1_bq27000_family.fid = F_ID;
105
106 return w1_register_family(&w1_bq27000_family);
107}
108
109static void __exit w1_bq27000_exit(void)
110{
111 w1_unregister_family(&w1_bq27000_family);
112}
113
114
115module_init(w1_bq27000_init);
116module_exit(w1_bq27000_exit);
117
118module_param(F_ID, int, S_IRUSR);
119MODULE_PARM_DESC(F_ID, "1-wire slave FID for BQ device");
120
121MODULE_LICENSE("GPL");
122MODULE_AUTHOR("Texas Instruments Ltd");
123MODULE_DESCRIPTION("HDQ/1-wire slave driver bq27000 battery monitor chip");