diff options
author | Madhusudhan Chikkature <madhu.cr@ti.com> | 2008-11-12 16:27:11 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-11-12 20:17:18 -0500 |
commit | cfbc619033d3a2eee8f7aa9314e21b96cf34d399 (patch) | |
tree | 6b089a99602859245ab10075a882a1d698cc119e /drivers/w1 | |
parent | 9f2bc79f7dd04adda1fc3be510c9b3d436f846c7 (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')
-rw-r--r-- | drivers/w1/slaves/Kconfig | 7 | ||||
-rw-r--r-- | drivers/w1/slaves/Makefile | 2 | ||||
-rw-r--r-- | drivers/w1/slaves/w1_bq27000.c | 123 |
3 files changed, 131 insertions, 1 deletions
diff --git a/drivers/w1/slaves/Kconfig b/drivers/w1/slaves/Kconfig index 3df29a122f84..8d0b1fb1e52e 100644 --- a/drivers/w1/slaves/Kconfig +++ b/drivers/w1/slaves/Kconfig | |||
@@ -44,4 +44,11 @@ config W1_SLAVE_DS2760 | |||
44 | 44 | ||
45 | If you are unsure, say N. | 45 | If you are unsure, say N. |
46 | 46 | ||
47 | config W1_SLAVE_BQ27000 | ||
48 | tristate "BQ27000 slave support" | ||
49 | depends on W1 | ||
50 | help | ||
51 | Say Y here if you want to use a hdq | ||
52 | bq27000 slave support. | ||
53 | |||
47 | endmenu | 54 | endmenu |
diff --git a/drivers/w1/slaves/Makefile b/drivers/w1/slaves/Makefile index a8eb7524df1d..990f400b6d22 100644 --- a/drivers/w1/slaves/Makefile +++ b/drivers/w1/slaves/Makefile | |||
@@ -6,4 +6,4 @@ obj-$(CONFIG_W1_SLAVE_THERM) += w1_therm.o | |||
6 | obj-$(CONFIG_W1_SLAVE_SMEM) += w1_smem.o | 6 | obj-$(CONFIG_W1_SLAVE_SMEM) += w1_smem.o |
7 | obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o | 7 | obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o |
8 | obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o | 8 | obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o |
9 | 9 | obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o | |
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 | |||
26 | static int F_ID; | ||
27 | |||
28 | void 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 | } | ||
40 | EXPORT_SYMBOL(w1_bq27000_write); | ||
41 | |||
42 | int 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 | } | ||
55 | EXPORT_SYMBOL(w1_bq27000_read); | ||
56 | |||
57 | static 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 | |||
78 | pdev_add_failed: | ||
79 | platform_device_unregister(pdev); | ||
80 | success: | ||
81 | return ret; | ||
82 | } | ||
83 | |||
84 | static 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 | |||
91 | static struct w1_family_ops w1_bq27000_fops = { | ||
92 | .add_slave = w1_bq27000_add_slave, | ||
93 | .remove_slave = w1_bq27000_remove_slave, | ||
94 | }; | ||
95 | |||
96 | static struct w1_family w1_bq27000_family = { | ||
97 | .fid = 1, | ||
98 | .fops = &w1_bq27000_fops, | ||
99 | }; | ||
100 | |||
101 | static 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 | |||
109 | static void __exit w1_bq27000_exit(void) | ||
110 | { | ||
111 | w1_unregister_family(&w1_bq27000_family); | ||
112 | } | ||
113 | |||
114 | |||
115 | module_init(w1_bq27000_init); | ||
116 | module_exit(w1_bq27000_exit); | ||
117 | |||
118 | module_param(F_ID, int, S_IRUSR); | ||
119 | MODULE_PARM_DESC(F_ID, "1-wire slave FID for BQ device"); | ||
120 | |||
121 | MODULE_LICENSE("GPL"); | ||
122 | MODULE_AUTHOR("Texas Instruments Ltd"); | ||
123 | MODULE_DESCRIPTION("HDQ/1-wire slave driver bq27000 battery monitor chip"); | ||