md: move compat_ioctl handling into md.c
[linux-2.6/next.git] / drivers / w1 / slaves / w1_bq27000.c
blob8f4c91f6c680e0e8285176985125fd4fbb4ed7a9
1 /*
2 * drivers/w1/slaves/w1_bq27000.c
4 * Copyright (C) 2007 Texas Instruments, Inc.
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.
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>
19 #include "../w1.h"
20 #include "../w1_int.h"
21 #include "../w1_family.h"
23 #define HDQ_CMD_READ (0)
24 #define HDQ_CMD_WRITE (1<<7)
26 static int F_ID;
28 void w1_bq27000_write(struct device *dev, u8 buf, u8 reg)
30 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
32 if (!dev) {
33 pr_info("Could not obtain slave dev ptr\n");
34 return;
37 w1_write_8(sl->master, HDQ_CMD_WRITE | reg);
38 w1_write_8(sl->master, buf);
40 EXPORT_SYMBOL(w1_bq27000_write);
42 int w1_bq27000_read(struct device *dev, u8 reg)
44 u8 val;
45 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
47 if (!dev)
48 return 0;
50 w1_write_8(sl->master, HDQ_CMD_READ | reg);
51 val = w1_read_8(sl->master);
53 return val;
55 EXPORT_SYMBOL(w1_bq27000_read);
57 static int w1_bq27000_add_slave(struct w1_slave *sl)
59 int ret;
60 int id = 1;
61 struct platform_device *pdev;
63 pdev = platform_device_alloc("bq27000-battery", id);
64 if (!pdev) {
65 ret = -ENOMEM;
66 return ret;
68 pdev->dev.parent = &sl->dev;
70 ret = platform_device_add(pdev);
71 if (ret)
72 goto pdev_add_failed;
74 dev_set_drvdata(&sl->dev, pdev);
76 goto success;
78 pdev_add_failed:
79 platform_device_unregister(pdev);
80 success:
81 return ret;
84 static void w1_bq27000_remove_slave(struct w1_slave *sl)
86 struct platform_device *pdev = dev_get_drvdata(&sl->dev);
88 platform_device_unregister(pdev);
91 static struct w1_family_ops w1_bq27000_fops = {
92 .add_slave = w1_bq27000_add_slave,
93 .remove_slave = w1_bq27000_remove_slave,
96 static struct w1_family w1_bq27000_family = {
97 .fid = 1,
98 .fops = &w1_bq27000_fops,
101 static int __init w1_bq27000_init(void)
103 if (F_ID)
104 w1_bq27000_family.fid = F_ID;
106 return w1_register_family(&w1_bq27000_family);
109 static void __exit w1_bq27000_exit(void)
111 w1_unregister_family(&w1_bq27000_family);
115 module_init(w1_bq27000_init);
116 module_exit(w1_bq27000_exit);
118 module_param(F_ID, int, S_IRUSR);
119 MODULE_PARM_DESC(F_ID, "1-wire slave FID for BQ device");
121 MODULE_LICENSE("GPL");
122 MODULE_AUTHOR("Texas Instruments Ltd");
123 MODULE_DESCRIPTION("HDQ/1-wire slave driver bq27000 battery monitor chip");