]>
Commit | Line | Data |
---|---|---|
cfbc6190 MC |
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> | |
081bab21 | 18 | #include <linux/power/bq27xxx_battery.h> |
cfbc6190 | 19 | |
de0d6dbd AD |
20 | #include <linux/w1.h> |
21 | ||
22 | #define W1_FAMILY_BQ27000 0x01 | |
cfbc6190 MC |
23 | |
24 | #define HDQ_CMD_READ (0) | |
25 | #define HDQ_CMD_WRITE (1<<7) | |
26 | ||
27 | static int F_ID; | |
50fa2951 AD |
28 | module_param(F_ID, int, S_IRUSR); |
29 | MODULE_PARM_DESC(F_ID, "1-wire slave FID for BQ device"); | |
cfbc6190 | 30 | |
9f3519d2 | 31 | static int w1_bq27000_read(struct device *dev, unsigned int reg) |
cfbc6190 MC |
32 | { |
33 | u8 val; | |
9f3519d2 | 34 | struct w1_slave *sl = container_of(dev->parent, struct w1_slave, dev); |
cfbc6190 | 35 | |
b02f8bed | 36 | mutex_lock(&sl->master->bus_mutex); |
cfbc6190 MC |
37 | w1_write_8(sl->master, HDQ_CMD_READ | reg); |
38 | val = w1_read_8(sl->master); | |
b02f8bed | 39 | mutex_unlock(&sl->master->bus_mutex); |
cfbc6190 MC |
40 | |
41 | return val; | |
42 | } | |
9f3519d2 | 43 | |
081bab21 | 44 | static struct bq27xxx_platform_data bq27000_battery_info = { |
9f3519d2 N |
45 | .read = w1_bq27000_read, |
46 | .name = "bq27000-battery", | |
424cfde4 | 47 | .chip = BQ27000, |
9f3519d2 | 48 | }; |
cfbc6190 MC |
49 | |
50 | static int w1_bq27000_add_slave(struct w1_slave *sl) | |
51 | { | |
52 | int ret; | |
cfbc6190 MC |
53 | struct platform_device *pdev; |
54 | ||
9f3519d2 | 55 | pdev = platform_device_alloc("bq27000-battery", -1); |
cfbc6190 MC |
56 | if (!pdev) { |
57 | ret = -ENOMEM; | |
58 | return ret; | |
59 | } | |
9f3519d2 N |
60 | ret = platform_device_add_data(pdev, |
61 | &bq27000_battery_info, | |
62 | sizeof(bq27000_battery_info)); | |
0ece1bbf WY |
63 | if (ret) |
64 | goto pdev_add_failed; | |
cfbc6190 MC |
65 | pdev->dev.parent = &sl->dev; |
66 | ||
67 | ret = platform_device_add(pdev); | |
68 | if (ret) | |
69 | goto pdev_add_failed; | |
70 | ||
71 | dev_set_drvdata(&sl->dev, pdev); | |
72 | ||
73 | goto success; | |
74 | ||
75 | pdev_add_failed: | |
0ece1bbf | 76 | platform_device_put(pdev); |
cfbc6190 MC |
77 | success: |
78 | return ret; | |
79 | } | |
80 | ||
81 | static void w1_bq27000_remove_slave(struct w1_slave *sl) | |
82 | { | |
83 | struct platform_device *pdev = dev_get_drvdata(&sl->dev); | |
84 | ||
85 | platform_device_unregister(pdev); | |
86 | } | |
87 | ||
88 | static struct w1_family_ops w1_bq27000_fops = { | |
89 | .add_slave = w1_bq27000_add_slave, | |
90 | .remove_slave = w1_bq27000_remove_slave, | |
91 | }; | |
92 | ||
93 | static struct w1_family w1_bq27000_family = { | |
4b7e4f82 | 94 | .fid = W1_FAMILY_BQ27000, |
cfbc6190 MC |
95 | .fops = &w1_bq27000_fops, |
96 | }; | |
97 | ||
98 | static int __init w1_bq27000_init(void) | |
99 | { | |
100 | if (F_ID) | |
101 | w1_bq27000_family.fid = F_ID; | |
102 | ||
103 | return w1_register_family(&w1_bq27000_family); | |
104 | } | |
105 | ||
106 | static void __exit w1_bq27000_exit(void) | |
107 | { | |
108 | w1_unregister_family(&w1_bq27000_family); | |
109 | } | |
110 | ||
cfbc6190 MC |
111 | module_init(w1_bq27000_init); |
112 | module_exit(w1_bq27000_exit); | |
113 | ||
cfbc6190 MC |
114 | MODULE_AUTHOR("Texas Instruments Ltd"); |
115 | MODULE_DESCRIPTION("HDQ/1-wire slave driver bq27000 battery monitor chip"); | |
50fa2951 AD |
116 | MODULE_LICENSE("GPL"); |
117 | MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_BQ27000)); |