Commit 275ac74629c4d8ec430d7edecb16d936f46a47c5

Authored by Clifton Barnes
Committed by Linus Torvalds
1 parent 963bb10101

w1: add Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC support

Add support for the Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC.

It was suggested to combine this functionality with the current ds2782
driver.  Unfortunately, I'm unable to commit the time to refactoring this
driver to that extent and I don't have a platform with the ds2782 part to
validate that there are no regression issues by adding this functionality.

[akpm@linux-foundation.org: use min_t()]
Signed-off-by: Clifton Barnes <cabarnes@indesign-llc.com>
Tested-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Cc: Ryan Mallon <ryan@bluewatersys.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 8 changed files with 1222 additions and 0 deletions Inline Diff

drivers/power/Kconfig
1 menuconfig POWER_SUPPLY 1 menuconfig POWER_SUPPLY
2 tristate "Power supply class support" 2 tristate "Power supply class support"
3 help 3 help
4 Say Y here to enable power supply class support. This allows 4 Say Y here to enable power supply class support. This allows
5 power supply (batteries, AC, USB) monitoring by userspace 5 power supply (batteries, AC, USB) monitoring by userspace
6 via sysfs and uevent (if available) and/or APM kernel interface 6 via sysfs and uevent (if available) and/or APM kernel interface
7 (if selected below). 7 (if selected below).
8 8
9 if POWER_SUPPLY 9 if POWER_SUPPLY
10 10
11 config POWER_SUPPLY_DEBUG 11 config POWER_SUPPLY_DEBUG
12 bool "Power supply debug" 12 bool "Power supply debug"
13 help 13 help
14 Say Y here to enable debugging messages for power supply class 14 Say Y here to enable debugging messages for power supply class
15 and drivers. 15 and drivers.
16 16
17 config PDA_POWER 17 config PDA_POWER
18 tristate "Generic PDA/phone power driver" 18 tristate "Generic PDA/phone power driver"
19 depends on !S390 19 depends on !S390
20 help 20 help
21 Say Y here to enable generic power driver for PDAs and phones with 21 Say Y here to enable generic power driver for PDAs and phones with
22 one or two external power supplies (AC/USB) connected to main and 22 one or two external power supplies (AC/USB) connected to main and
23 backup batteries, and optional builtin charger. 23 backup batteries, and optional builtin charger.
24 24
25 config APM_POWER 25 config APM_POWER
26 tristate "APM emulation for class batteries" 26 tristate "APM emulation for class batteries"
27 depends on APM_EMULATION 27 depends on APM_EMULATION
28 help 28 help
29 Say Y here to enable support APM status emulation using 29 Say Y here to enable support APM status emulation using
30 battery class devices. 30 battery class devices.
31 31
32 config MAX8925_POWER 32 config MAX8925_POWER
33 tristate "MAX8925 battery charger support" 33 tristate "MAX8925 battery charger support"
34 depends on MFD_MAX8925 34 depends on MFD_MAX8925
35 help 35 help
36 Say Y here to enable support for the battery charger in the Maxim 36 Say Y here to enable support for the battery charger in the Maxim
37 MAX8925 PMIC. 37 MAX8925 PMIC.
38 38
39 config WM831X_BACKUP 39 config WM831X_BACKUP
40 tristate "WM831X backup battery charger support" 40 tristate "WM831X backup battery charger support"
41 depends on MFD_WM831X 41 depends on MFD_WM831X
42 help 42 help
43 Say Y here to enable support for the backup battery charger 43 Say Y here to enable support for the backup battery charger
44 in the Wolfson Microelectronics WM831x PMICs. 44 in the Wolfson Microelectronics WM831x PMICs.
45 45
46 config WM831X_POWER 46 config WM831X_POWER
47 tristate "WM831X PMU support" 47 tristate "WM831X PMU support"
48 depends on MFD_WM831X 48 depends on MFD_WM831X
49 help 49 help
50 Say Y here to enable support for the power management unit 50 Say Y here to enable support for the power management unit
51 provided by Wolfson Microelectronics WM831x PMICs. 51 provided by Wolfson Microelectronics WM831x PMICs.
52 52
53 config WM8350_POWER 53 config WM8350_POWER
54 tristate "WM8350 PMU support" 54 tristate "WM8350 PMU support"
55 depends on MFD_WM8350 55 depends on MFD_WM8350
56 help 56 help
57 Say Y here to enable support for the power management unit 57 Say Y here to enable support for the power management unit
58 provided by the Wolfson Microelectronics WM8350 PMIC. 58 provided by the Wolfson Microelectronics WM8350 PMIC.
59 59
60 config TEST_POWER 60 config TEST_POWER
61 tristate "Test power driver" 61 tristate "Test power driver"
62 help 62 help
63 This driver is used for testing. It's safe to say M here. 63 This driver is used for testing. It's safe to say M here.
64 64
65 config BATTERY_DS2760 65 config BATTERY_DS2760
66 tristate "DS2760 battery driver (HP iPAQ & others)" 66 tristate "DS2760 battery driver (HP iPAQ & others)"
67 depends on W1 && W1_SLAVE_DS2760 67 depends on W1 && W1_SLAVE_DS2760
68 help 68 help
69 Say Y here to enable support for batteries with ds2760 chip. 69 Say Y here to enable support for batteries with ds2760 chip.
70 70
71 config BATTERY_DS2780
72 tristate "DS2780 battery driver"
73 select W1
74 select W1_SLAVE_DS2780
75 help
76 Say Y here to enable support for batteries with ds2780 chip.
77
71 config BATTERY_DS2782 78 config BATTERY_DS2782
72 tristate "DS2782/DS2786 standalone gas-gauge" 79 tristate "DS2782/DS2786 standalone gas-gauge"
73 depends on I2C 80 depends on I2C
74 help 81 help
75 Say Y here to enable support for the DS2782/DS2786 standalone battery 82 Say Y here to enable support for the DS2782/DS2786 standalone battery
76 gas-gauge. 83 gas-gauge.
77 84
78 config BATTERY_PMU 85 config BATTERY_PMU
79 tristate "Apple PMU battery" 86 tristate "Apple PMU battery"
80 depends on PPC32 && ADB_PMU 87 depends on PPC32 && ADB_PMU
81 help 88 help
82 Say Y here to expose battery information on Apple machines 89 Say Y here to expose battery information on Apple machines
83 through the generic battery class. 90 through the generic battery class.
84 91
85 config BATTERY_OLPC 92 config BATTERY_OLPC
86 tristate "One Laptop Per Child battery" 93 tristate "One Laptop Per Child battery"
87 depends on X86_32 && OLPC 94 depends on X86_32 && OLPC
88 help 95 help
89 Say Y to enable support for the battery on the OLPC laptop. 96 Say Y to enable support for the battery on the OLPC laptop.
90 97
91 config BATTERY_TOSA 98 config BATTERY_TOSA
92 tristate "Sharp SL-6000 (tosa) battery" 99 tristate "Sharp SL-6000 (tosa) battery"
93 depends on MACH_TOSA && MFD_TC6393XB && TOUCHSCREEN_WM97XX 100 depends on MACH_TOSA && MFD_TC6393XB && TOUCHSCREEN_WM97XX
94 help 101 help
95 Say Y to enable support for the battery on the Sharp Zaurus 102 Say Y to enable support for the battery on the Sharp Zaurus
96 SL-6000 (tosa) models. 103 SL-6000 (tosa) models.
97 104
98 config BATTERY_COLLIE 105 config BATTERY_COLLIE
99 tristate "Sharp SL-5500 (collie) battery" 106 tristate "Sharp SL-5500 (collie) battery"
100 depends on SA1100_COLLIE && MCP_UCB1200 107 depends on SA1100_COLLIE && MCP_UCB1200
101 help 108 help
102 Say Y to enable support for the battery on the Sharp Zaurus 109 Say Y to enable support for the battery on the Sharp Zaurus
103 SL-5500 (collie) models. 110 SL-5500 (collie) models.
104 111
105 config BATTERY_WM97XX 112 config BATTERY_WM97XX
106 bool "WM97xx generic battery driver" 113 bool "WM97xx generic battery driver"
107 depends on TOUCHSCREEN_WM97XX=y 114 depends on TOUCHSCREEN_WM97XX=y
108 help 115 help
109 Say Y to enable support for battery measured by WM97xx aux port. 116 Say Y to enable support for battery measured by WM97xx aux port.
110 117
111 config BATTERY_BQ20Z75 118 config BATTERY_BQ20Z75
112 tristate "TI BQ20z75 gas gauge" 119 tristate "TI BQ20z75 gas gauge"
113 depends on I2C 120 depends on I2C
114 help 121 help
115 Say Y to include support for TI BQ20z75 SBS-compliant 122 Say Y to include support for TI BQ20z75 SBS-compliant
116 gas gauge and protection IC. 123 gas gauge and protection IC.
117 124
118 config BATTERY_BQ27x00 125 config BATTERY_BQ27x00
119 tristate "BQ27x00 battery driver" 126 tristate "BQ27x00 battery driver"
120 help 127 help
121 Say Y here to enable support for batteries with BQ27x00 (I2C/HDQ) chips. 128 Say Y here to enable support for batteries with BQ27x00 (I2C/HDQ) chips.
122 129
123 config BATTERY_BQ27X00_I2C 130 config BATTERY_BQ27X00_I2C
124 bool "BQ27200/BQ27500 support" 131 bool "BQ27200/BQ27500 support"
125 depends on BATTERY_BQ27x00 132 depends on BATTERY_BQ27x00
126 depends on I2C 133 depends on I2C
127 default y 134 default y
128 help 135 help
129 Say Y here to enable support for batteries with BQ27x00 (I2C) chips. 136 Say Y here to enable support for batteries with BQ27x00 (I2C) chips.
130 137
131 config BATTERY_BQ27X00_PLATFORM 138 config BATTERY_BQ27X00_PLATFORM
132 bool "BQ27000 support" 139 bool "BQ27000 support"
133 depends on BATTERY_BQ27x00 140 depends on BATTERY_BQ27x00
134 default y 141 default y
135 help 142 help
136 Say Y here to enable support for batteries with BQ27000 (HDQ) chips. 143 Say Y here to enable support for batteries with BQ27000 (HDQ) chips.
137 144
138 config BATTERY_DA9030 145 config BATTERY_DA9030
139 tristate "DA9030 battery driver" 146 tristate "DA9030 battery driver"
140 depends on PMIC_DA903X 147 depends on PMIC_DA903X
141 help 148 help
142 Say Y here to enable support for batteries charger integrated into 149 Say Y here to enable support for batteries charger integrated into
143 DA9030 PMIC. 150 DA9030 PMIC.
144 151
145 config BATTERY_MAX17040 152 config BATTERY_MAX17040
146 tristate "Maxim MAX17040 Fuel Gauge" 153 tristate "Maxim MAX17040 Fuel Gauge"
147 depends on I2C 154 depends on I2C
148 help 155 help
149 MAX17040 is fuel-gauge systems for lithium-ion (Li+) batteries 156 MAX17040 is fuel-gauge systems for lithium-ion (Li+) batteries
150 in handheld and portable equipment. The MAX17040 is configured 157 in handheld and portable equipment. The MAX17040 is configured
151 to operate with a single lithium cell 158 to operate with a single lithium cell
152 159
153 config BATTERY_MAX17042 160 config BATTERY_MAX17042
154 tristate "Maxim MAX17042/8997/8966 Fuel Gauge" 161 tristate "Maxim MAX17042/8997/8966 Fuel Gauge"
155 depends on I2C 162 depends on I2C
156 help 163 help
157 MAX17042 is fuel-gauge systems for lithium-ion (Li+) batteries 164 MAX17042 is fuel-gauge systems for lithium-ion (Li+) batteries
158 in handheld and portable equipment. The MAX17042 is configured 165 in handheld and portable equipment. The MAX17042 is configured
159 to operate with a single lithium cell. MAX8997 and MAX8966 are 166 to operate with a single lithium cell. MAX8997 and MAX8966 are
160 multi-function devices that include fuel gauages that are compatible 167 multi-function devices that include fuel gauages that are compatible
161 with MAX17042. 168 with MAX17042.
162 169
163 config BATTERY_Z2 170 config BATTERY_Z2
164 tristate "Z2 battery driver" 171 tristate "Z2 battery driver"
165 depends on I2C && MACH_ZIPIT2 172 depends on I2C && MACH_ZIPIT2
166 help 173 help
167 Say Y to include support for the battery on the Zipit Z2. 174 Say Y to include support for the battery on the Zipit Z2.
168 175
169 config BATTERY_S3C_ADC 176 config BATTERY_S3C_ADC
170 tristate "Battery driver for Samsung ADC based monitoring" 177 tristate "Battery driver for Samsung ADC based monitoring"
171 depends on S3C_ADC 178 depends on S3C_ADC
172 help 179 help
173 Say Y here to enable support for iPAQ h1930/h1940/rx1950 battery 180 Say Y here to enable support for iPAQ h1930/h1940/rx1950 battery
174 181
175 config CHARGER_PCF50633 182 config CHARGER_PCF50633
176 tristate "NXP PCF50633 MBC" 183 tristate "NXP PCF50633 MBC"
177 depends on MFD_PCF50633 184 depends on MFD_PCF50633
178 help 185 help
179 Say Y to include support for NXP PCF50633 Main Battery Charger. 186 Say Y to include support for NXP PCF50633 Main Battery Charger.
180 187
181 config BATTERY_JZ4740 188 config BATTERY_JZ4740
182 tristate "Ingenic JZ4740 battery" 189 tristate "Ingenic JZ4740 battery"
183 depends on MACH_JZ4740 190 depends on MACH_JZ4740
184 depends on MFD_JZ4740_ADC 191 depends on MFD_JZ4740_ADC
185 help 192 help
186 Say Y to enable support for the battery on Ingenic JZ4740 based 193 Say Y to enable support for the battery on Ingenic JZ4740 based
187 boards. 194 boards.
188 195
189 This driver can be build as a module. If so, the module will be 196 This driver can be build as a module. If so, the module will be
190 called jz4740-battery. 197 called jz4740-battery.
191 198
192 config BATTERY_INTEL_MID 199 config BATTERY_INTEL_MID
193 tristate "Battery driver for Intel MID platforms" 200 tristate "Battery driver for Intel MID platforms"
194 depends on INTEL_SCU_IPC && SPI 201 depends on INTEL_SCU_IPC && SPI
195 help 202 help
196 Say Y here to enable the battery driver on Intel MID 203 Say Y here to enable the battery driver on Intel MID
197 platforms. 204 platforms.
198 205
199 config CHARGER_ISP1704 206 config CHARGER_ISP1704
200 tristate "ISP1704 USB Charger Detection" 207 tristate "ISP1704 USB Charger Detection"
201 depends on USB_OTG_UTILS 208 depends on USB_OTG_UTILS
202 help 209 help
203 Say Y to enable support for USB Charger Detection with 210 Say Y to enable support for USB Charger Detection with
204 ISP1707/ISP1704 USB transceivers. 211 ISP1707/ISP1704 USB transceivers.
205 212
206 config CHARGER_TWL4030 213 config CHARGER_TWL4030
207 tristate "OMAP TWL4030 BCI charger driver" 214 tristate "OMAP TWL4030 BCI charger driver"
208 depends on TWL4030_CORE 215 depends on TWL4030_CORE
209 help 216 help
210 Say Y here to enable support for TWL4030 Battery Charge Interface. 217 Say Y here to enable support for TWL4030 Battery Charge Interface.
211 218
212 config CHARGER_GPIO 219 config CHARGER_GPIO
213 tristate "GPIO charger" 220 tristate "GPIO charger"
214 depends on GPIOLIB 221 depends on GPIOLIB
215 help 222 help
216 Say Y to include support for chargers which report their online status 223 Say Y to include support for chargers which report their online status
217 through a GPIO pin. 224 through a GPIO pin.
218 225
219 This driver can be build as a module. If so, the module will be 226 This driver can be build as a module. If so, the module will be
220 called gpio-charger. 227 called gpio-charger.
221 228
222 endif # POWER_SUPPLY 229 endif # POWER_SUPPLY
223 230
drivers/power/Makefile
1 ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG 1 ccflags-$(CONFIG_POWER_SUPPLY_DEBUG) := -DDEBUG
2 2
3 power_supply-y := power_supply_core.o 3 power_supply-y := power_supply_core.o
4 power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o 4 power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o
5 power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o 5 power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o
6 6
7 obj-$(CONFIG_POWER_SUPPLY) += power_supply.o 7 obj-$(CONFIG_POWER_SUPPLY) += power_supply.o
8 8
9 obj-$(CONFIG_PDA_POWER) += pda_power.o 9 obj-$(CONFIG_PDA_POWER) += pda_power.o
10 obj-$(CONFIG_APM_POWER) += apm_power.o 10 obj-$(CONFIG_APM_POWER) += apm_power.o
11 obj-$(CONFIG_MAX8925_POWER) += max8925_power.o 11 obj-$(CONFIG_MAX8925_POWER) += max8925_power.o
12 obj-$(CONFIG_WM831X_BACKUP) += wm831x_backup.o 12 obj-$(CONFIG_WM831X_BACKUP) += wm831x_backup.o
13 obj-$(CONFIG_WM831X_POWER) += wm831x_power.o 13 obj-$(CONFIG_WM831X_POWER) += wm831x_power.o
14 obj-$(CONFIG_WM8350_POWER) += wm8350_power.o 14 obj-$(CONFIG_WM8350_POWER) += wm8350_power.o
15 obj-$(CONFIG_TEST_POWER) += test_power.o 15 obj-$(CONFIG_TEST_POWER) += test_power.o
16 16
17 obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o 17 obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o
18 obj-$(CONFIG_BATTERY_DS2780) += ds2780_battery.o
18 obj-$(CONFIG_BATTERY_DS2782) += ds2782_battery.o 19 obj-$(CONFIG_BATTERY_DS2782) += ds2782_battery.o
19 obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o 20 obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
20 obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o 21 obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o
21 obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o 22 obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o
22 obj-$(CONFIG_BATTERY_COLLIE) += collie_battery.o 23 obj-$(CONFIG_BATTERY_COLLIE) += collie_battery.o
23 obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o 24 obj-$(CONFIG_BATTERY_WM97XX) += wm97xx_battery.o
24 obj-$(CONFIG_BATTERY_BQ20Z75) += bq20z75.o 25 obj-$(CONFIG_BATTERY_BQ20Z75) += bq20z75.o
25 obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o 26 obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o
26 obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o 27 obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o
27 obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o 28 obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o
28 obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o 29 obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o
29 obj-$(CONFIG_BATTERY_Z2) += z2_battery.o 30 obj-$(CONFIG_BATTERY_Z2) += z2_battery.o
30 obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o 31 obj-$(CONFIG_BATTERY_S3C_ADC) += s3c_adc_battery.o
31 obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o 32 obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
32 obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o 33 obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o
33 obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o 34 obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o
34 obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o 35 obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o
35 obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o 36 obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
36 obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o 37 obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o
37 38
drivers/power/ds2780_battery.c
File was created 1 /*
2 * 1-wire client/driver for the Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC
3 *
4 * Copyright (C) 2010 Indesign, LLC
5 *
6 * Author: Clifton Barnes <cabarnes@indesign-llc.com>
7 *
8 * Based on ds2760_battery and ds2782_battery drivers
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/param.h>
19 #include <linux/pm.h>
20 #include <linux/platform_device.h>
21 #include <linux/power_supply.h>
22 #include <linux/idr.h>
23
24 #include "../w1/w1.h"
25 #include "../w1/slaves/w1_ds2780.h"
26
27 /* Current unit measurement in uA for a 1 milli-ohm sense resistor */
28 #define DS2780_CURRENT_UNITS 1563
29 /* Charge unit measurement in uAh for a 1 milli-ohm sense resistor */
30 #define DS2780_CHARGE_UNITS 6250
31 /* Number of bytes in user EEPROM space */
32 #define DS2780_USER_EEPROM_SIZE (DS2780_EEPROM_BLOCK0_END - \
33 DS2780_EEPROM_BLOCK0_START + 1)
34 /* Number of bytes in parameter EEPROM space */
35 #define DS2780_PARAM_EEPROM_SIZE (DS2780_EEPROM_BLOCK1_END - \
36 DS2780_EEPROM_BLOCK1_START + 1)
37
38 struct ds2780_device_info {
39 struct device *dev;
40 struct power_supply bat;
41 struct device *w1_dev;
42 };
43
44 enum current_types {
45 CURRENT_NOW,
46 CURRENT_AVG,
47 };
48
49 static const char model[] = "DS2780";
50 static const char manufacturer[] = "Maxim/Dallas";
51
52 static inline struct ds2780_device_info *to_ds2780_device_info(
53 struct power_supply *psy)
54 {
55 return container_of(psy, struct ds2780_device_info, bat);
56 }
57
58 static inline struct power_supply *to_power_supply(struct device *dev)
59 {
60 return dev_get_drvdata(dev);
61 }
62
63 static inline int ds2780_read8(struct device *dev, u8 *val, int addr)
64 {
65 return w1_ds2780_io(dev, val, addr, sizeof(u8), 0);
66 }
67
68 static int ds2780_read16(struct device *dev, s16 *val, int addr)
69 {
70 int ret;
71 u8 raw[2];
72
73 ret = w1_ds2780_io(dev, raw, addr, sizeof(u8) * 2, 0);
74 if (ret < 0)
75 return ret;
76
77 *val = (raw[0] << 8) | raw[1];
78
79 return 0;
80 }
81
82 static inline int ds2780_read_block(struct device *dev, u8 *val, int addr,
83 size_t count)
84 {
85 return w1_ds2780_io(dev, val, addr, count, 0);
86 }
87
88 static inline int ds2780_write(struct device *dev, u8 *val, int addr,
89 size_t count)
90 {
91 return w1_ds2780_io(dev, val, addr, count, 1);
92 }
93
94 static inline int ds2780_store_eeprom(struct device *dev, int addr)
95 {
96 return w1_ds2780_eeprom_cmd(dev, addr, W1_DS2780_COPY_DATA);
97 }
98
99 static inline int ds2780_recall_eeprom(struct device *dev, int addr)
100 {
101 return w1_ds2780_eeprom_cmd(dev, addr, W1_DS2780_RECALL_DATA);
102 }
103
104 static int ds2780_save_eeprom(struct ds2780_device_info *dev_info, int reg)
105 {
106 int ret;
107
108 ret = ds2780_store_eeprom(dev_info->w1_dev, reg);
109 if (ret < 0)
110 return ret;
111
112 ret = ds2780_recall_eeprom(dev_info->w1_dev, reg);
113 if (ret < 0)
114 return ret;
115
116 return 0;
117 }
118
119 /* Set sense resistor value in mhos */
120 static int ds2780_set_sense_register(struct ds2780_device_info *dev_info,
121 u8 conductance)
122 {
123 int ret;
124
125 ret = ds2780_write(dev_info->w1_dev, &conductance,
126 DS2780_RSNSP_REG, sizeof(u8));
127 if (ret < 0)
128 return ret;
129
130 return ds2780_save_eeprom(dev_info, DS2780_RSNSP_REG);
131 }
132
133 /* Get RSGAIN value from 0 to 1.999 in steps of 0.001 */
134 static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info,
135 u16 *rsgain)
136 {
137 return ds2780_read16(dev_info->w1_dev, rsgain, DS2780_RSGAIN_MSB_REG);
138 }
139
140 /* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
141 static int ds2780_set_rsgain_register(struct ds2780_device_info *dev_info,
142 u16 rsgain)
143 {
144 int ret;
145 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
146
147 ret = ds2780_write(dev_info->w1_dev, raw,
148 DS2780_RSGAIN_MSB_REG, sizeof(u8) * 2);
149 if (ret < 0)
150 return ret;
151
152 return ds2780_save_eeprom(dev_info, DS2780_RSGAIN_MSB_REG);
153 }
154
155 static int ds2780_get_voltage(struct ds2780_device_info *dev_info,
156 int *voltage_uV)
157 {
158 int ret;
159 s16 voltage_raw;
160
161 /*
162 * The voltage value is located in 10 bits across the voltage MSB
163 * and LSB registers in two's compliment form
164 * Sign bit of the voltage value is in bit 7 of the voltage MSB register
165 * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the
166 * voltage MSB register
167 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
168 * voltage LSB register
169 */
170 ret = ds2780_read16(dev_info->w1_dev, &voltage_raw,
171 DS2780_VOLT_MSB_REG);
172 if (ret < 0)
173 return ret;
174
175 /*
176 * DS2780 reports voltage in units of 4.88mV, but the battery class
177 * reports in units of uV, so convert by multiplying by 4880.
178 */
179 *voltage_uV = (voltage_raw / 32) * 4880;
180 return 0;
181 }
182
183 static int ds2780_get_temperature(struct ds2780_device_info *dev_info,
184 int *temperature)
185 {
186 int ret;
187 s16 temperature_raw;
188
189 /*
190 * The temperature value is located in 10 bits across the temperature
191 * MSB and LSB registers in two's compliment form
192 * Sign bit of the temperature value is in bit 7 of the temperature
193 * MSB register
194 * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the
195 * temperature MSB register
196 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
197 * temperature LSB register
198 */
199 ret = ds2780_read16(dev_info->w1_dev, &temperature_raw,
200 DS2780_TEMP_MSB_REG);
201 if (ret < 0)
202 return ret;
203
204 /*
205 * Temperature is measured in units of 0.125 degrees celcius, the
206 * power_supply class measures temperature in tenths of degrees
207 * celsius. The temperature value is stored as a 10 bit number, plus
208 * sign in the upper bits of a 16 bit register.
209 */
210 *temperature = ((temperature_raw / 32) * 125) / 100;
211 return 0;
212 }
213
214 static int ds2780_get_current(struct ds2780_device_info *dev_info,
215 enum current_types type, int *current_uA)
216 {
217 int ret, sense_res;
218 s16 current_raw;
219 u8 sense_res_raw, reg_msb;
220
221 /*
222 * The units of measurement for current are dependent on the value of
223 * the sense resistor.
224 */
225 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG);
226 if (ret < 0)
227 return ret;
228
229 if (sense_res_raw == 0) {
230 dev_err(dev_info->dev, "sense resistor value is 0\n");
231 return -ENXIO;
232 }
233 sense_res = 1000 / sense_res_raw;
234
235 if (type == CURRENT_NOW)
236 reg_msb = DS2780_CURRENT_MSB_REG;
237 else if (type == CURRENT_AVG)
238 reg_msb = DS2780_IAVG_MSB_REG;
239 else
240 return -EINVAL;
241
242 /*
243 * The current value is located in 16 bits across the current MSB
244 * and LSB registers in two's compliment form
245 * Sign bit of the current value is in bit 7 of the current MSB register
246 * Bits 14 - 8 of the current value are in bits 6 - 0 of the current
247 * MSB register
248 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
249 * LSB register
250 */
251 ret = ds2780_read16(dev_info->w1_dev, &current_raw, reg_msb);
252 if (ret < 0)
253 return ret;
254
255 *current_uA = current_raw * (DS2780_CURRENT_UNITS / sense_res);
256 return 0;
257 }
258
259 static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info,
260 int *accumulated_current)
261 {
262 int ret, sense_res;
263 s16 current_raw;
264 u8 sense_res_raw;
265
266 /*
267 * The units of measurement for accumulated current are dependent on
268 * the value of the sense resistor.
269 */
270 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG);
271 if (ret < 0)
272 return ret;
273
274 if (sense_res_raw == 0) {
275 dev_err(dev_info->dev, "sense resistor value is 0\n");
276 return -ENXIO;
277 }
278 sense_res = 1000 / sense_res_raw;
279
280 /*
281 * The ACR value is located in 16 bits across the ACR MSB and
282 * LSB registers
283 * Bits 15 - 8 of the ACR value are in bits 7 - 0 of the ACR
284 * MSB register
285 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
286 * LSB register
287 */
288 ret = ds2780_read16(dev_info->w1_dev, &current_raw, DS2780_ACR_MSB_REG);
289 if (ret < 0)
290 return ret;
291
292 *accumulated_current = current_raw * (DS2780_CHARGE_UNITS / sense_res);
293 return 0;
294 }
295
296 static int ds2780_get_capacity(struct ds2780_device_info *dev_info,
297 int *capacity)
298 {
299 int ret;
300 u8 raw;
301
302 ret = ds2780_read8(dev_info->w1_dev, &raw, DS2780_RARC_REG);
303 if (ret < 0)
304 return ret;
305
306 *capacity = raw;
307 return raw;
308 }
309
310 static int ds2780_get_status(struct ds2780_device_info *dev_info, int *status)
311 {
312 int ret, current_uA, capacity;
313
314 ret = ds2780_get_current(dev_info, CURRENT_NOW, &current_uA);
315 if (ret < 0)
316 return ret;
317
318 ret = ds2780_get_capacity(dev_info, &capacity);
319 if (ret < 0)
320 return ret;
321
322 if (capacity == 100)
323 *status = POWER_SUPPLY_STATUS_FULL;
324 else if (current_uA == 0)
325 *status = POWER_SUPPLY_STATUS_NOT_CHARGING;
326 else if (current_uA < 0)
327 *status = POWER_SUPPLY_STATUS_DISCHARGING;
328 else
329 *status = POWER_SUPPLY_STATUS_CHARGING;
330
331 return 0;
332 }
333
334 static int ds2780_get_charge_now(struct ds2780_device_info *dev_info,
335 int *charge_now)
336 {
337 int ret;
338 u16 charge_raw;
339
340 /*
341 * The RAAC value is located in 16 bits across the RAAC MSB and
342 * LSB registers
343 * Bits 15 - 8 of the RAAC value are in bits 7 - 0 of the RAAC
344 * MSB register
345 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
346 * LSB register
347 */
348 ret = ds2780_read16(dev_info->w1_dev, &charge_raw, DS2780_RAAC_MSB_REG);
349 if (ret < 0)
350 return ret;
351
352 *charge_now = charge_raw * 1600;
353 return 0;
354 }
355
356 static int ds2780_get_control_register(struct ds2780_device_info *dev_info,
357 u8 *control_reg)
358 {
359 return ds2780_read8(dev_info->w1_dev, control_reg, DS2780_CONTROL_REG);
360 }
361
362 static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
363 u8 control_reg)
364 {
365 int ret;
366
367 ret = ds2780_write(dev_info->w1_dev, &control_reg,
368 DS2780_CONTROL_REG, sizeof(u8));
369 if (ret < 0)
370 return ret;
371
372 return ds2780_save_eeprom(dev_info, DS2780_CONTROL_REG);
373 }
374
375 static int ds2780_battery_get_property(struct power_supply *psy,
376 enum power_supply_property psp,
377 union power_supply_propval *val)
378 {
379 int ret = 0;
380 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
381
382 switch (psp) {
383 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
384 ret = ds2780_get_voltage(dev_info, &val->intval);
385 break;
386
387 case POWER_SUPPLY_PROP_TEMP:
388 ret = ds2780_get_temperature(dev_info, &val->intval);
389 break;
390
391 case POWER_SUPPLY_PROP_MODEL_NAME:
392 val->strval = model;
393 break;
394
395 case POWER_SUPPLY_PROP_MANUFACTURER:
396 val->strval = manufacturer;
397 break;
398
399 case POWER_SUPPLY_PROP_CURRENT_NOW:
400 ret = ds2780_get_current(dev_info, CURRENT_NOW, &val->intval);
401 break;
402
403 case POWER_SUPPLY_PROP_CURRENT_AVG:
404 ret = ds2780_get_current(dev_info, CURRENT_AVG, &val->intval);
405 break;
406
407 case POWER_SUPPLY_PROP_STATUS:
408 ret = ds2780_get_status(dev_info, &val->intval);
409 break;
410
411 case POWER_SUPPLY_PROP_CAPACITY:
412 ret = ds2780_get_capacity(dev_info, &val->intval);
413 break;
414
415 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
416 ret = ds2780_get_accumulated_current(dev_info, &val->intval);
417 break;
418
419 case POWER_SUPPLY_PROP_CHARGE_NOW:
420 ret = ds2780_get_charge_now(dev_info, &val->intval);
421 break;
422
423 default:
424 ret = -EINVAL;
425 }
426
427 return ret;
428 }
429
430 static enum power_supply_property ds2780_battery_props[] = {
431 POWER_SUPPLY_PROP_STATUS,
432 POWER_SUPPLY_PROP_VOLTAGE_NOW,
433 POWER_SUPPLY_PROP_TEMP,
434 POWER_SUPPLY_PROP_MODEL_NAME,
435 POWER_SUPPLY_PROP_MANUFACTURER,
436 POWER_SUPPLY_PROP_CURRENT_NOW,
437 POWER_SUPPLY_PROP_CURRENT_AVG,
438 POWER_SUPPLY_PROP_CAPACITY,
439 POWER_SUPPLY_PROP_CHARGE_COUNTER,
440 POWER_SUPPLY_PROP_CHARGE_NOW,
441 };
442
443 static ssize_t ds2780_get_pmod_enabled(struct device *dev,
444 struct device_attribute *attr,
445 char *buf)
446 {
447 int ret;
448 u8 control_reg;
449 struct power_supply *psy = to_power_supply(dev);
450 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
451
452 /* Get power mode */
453 ret = ds2780_get_control_register(dev_info, &control_reg);
454 if (ret < 0)
455 return ret;
456
457 return sprintf(buf, "%d\n",
458 !!(control_reg & DS2780_CONTROL_REG_PMOD));
459 }
460
461 static ssize_t ds2780_set_pmod_enabled(struct device *dev,
462 struct device_attribute *attr,
463 const char *buf,
464 size_t count)
465 {
466 int ret;
467 u8 control_reg, new_setting;
468 struct power_supply *psy = to_power_supply(dev);
469 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
470
471 /* Set power mode */
472 ret = ds2780_get_control_register(dev_info, &control_reg);
473 if (ret < 0)
474 return ret;
475
476 ret = kstrtou8(buf, 0, &new_setting);
477 if (ret < 0)
478 return ret;
479
480 if ((new_setting != 0) && (new_setting != 1)) {
481 dev_err(dev_info->dev, "Invalid pmod setting (0 or 1)\n");
482 return -EINVAL;
483 }
484
485 if (new_setting)
486 control_reg |= DS2780_CONTROL_REG_PMOD;
487 else
488 control_reg &= ~DS2780_CONTROL_REG_PMOD;
489
490 ret = ds2780_set_control_register(dev_info, control_reg);
491 if (ret < 0)
492 return ret;
493
494 return count;
495 }
496
497 static ssize_t ds2780_get_sense_resistor_value(struct device *dev,
498 struct device_attribute *attr,
499 char *buf)
500 {
501 int ret;
502 u8 sense_resistor;
503 struct power_supply *psy = to_power_supply(dev);
504 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
505
506 ret = ds2780_read8(dev_info->w1_dev, &sense_resistor, DS2780_RSNSP_REG);
507 if (ret < 0)
508 return ret;
509
510 ret = sprintf(buf, "%d\n", sense_resistor);
511 return ret;
512 }
513
514 static ssize_t ds2780_set_sense_resistor_value(struct device *dev,
515 struct device_attribute *attr,
516 const char *buf,
517 size_t count)
518 {
519 int ret;
520 u8 new_setting;
521 struct power_supply *psy = to_power_supply(dev);
522 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
523
524 ret = kstrtou8(buf, 0, &new_setting);
525 if (ret < 0)
526 return ret;
527
528 ret = ds2780_set_sense_register(dev_info, new_setting);
529 if (ret < 0)
530 return ret;
531
532 return count;
533 }
534
535 static ssize_t ds2780_get_rsgain_setting(struct device *dev,
536 struct device_attribute *attr,
537 char *buf)
538 {
539 int ret;
540 u16 rsgain;
541 struct power_supply *psy = to_power_supply(dev);
542 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
543
544 ret = ds2780_get_rsgain_register(dev_info, &rsgain);
545 if (ret < 0)
546 return ret;
547
548 return sprintf(buf, "%d\n", rsgain);
549 }
550
551 static ssize_t ds2780_set_rsgain_setting(struct device *dev,
552 struct device_attribute *attr,
553 const char *buf,
554 size_t count)
555 {
556 int ret;
557 u16 new_setting;
558 struct power_supply *psy = to_power_supply(dev);
559 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
560
561 ret = kstrtou16(buf, 0, &new_setting);
562 if (ret < 0)
563 return ret;
564
565 /* Gain can only be from 0 to 1.999 in steps of .001 */
566 if (new_setting > 1999) {
567 dev_err(dev_info->dev, "Invalid rsgain setting (0 - 1999)\n");
568 return -EINVAL;
569 }
570
571 ret = ds2780_set_rsgain_register(dev_info, new_setting);
572 if (ret < 0)
573 return ret;
574
575 return count;
576 }
577
578 static ssize_t ds2780_get_pio_pin(struct device *dev,
579 struct device_attribute *attr,
580 char *buf)
581 {
582 int ret;
583 u8 sfr;
584 struct power_supply *psy = to_power_supply(dev);
585 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
586
587 ret = ds2780_read8(dev_info->w1_dev, &sfr, DS2780_SFR_REG);
588 if (ret < 0)
589 return ret;
590
591 ret = sprintf(buf, "%d\n", sfr & DS2780_SFR_REG_PIOSC);
592 return ret;
593 }
594
595 static ssize_t ds2780_set_pio_pin(struct device *dev,
596 struct device_attribute *attr,
597 const char *buf,
598 size_t count)
599 {
600 int ret;
601 u8 new_setting;
602 struct power_supply *psy = to_power_supply(dev);
603 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
604
605 ret = kstrtou8(buf, 0, &new_setting);
606 if (ret < 0)
607 return ret;
608
609 if ((new_setting != 0) && (new_setting != 1)) {
610 dev_err(dev_info->dev, "Invalid pio_pin setting (0 or 1)\n");
611 return -EINVAL;
612 }
613
614 ret = ds2780_write(dev_info->w1_dev, &new_setting,
615 DS2780_SFR_REG, sizeof(u8));
616 if (ret < 0)
617 return ret;
618
619 return count;
620 }
621
622 static ssize_t ds2780_read_param_eeprom_bin(struct file *filp,
623 struct kobject *kobj,
624 struct bin_attribute *bin_attr,
625 char *buf, loff_t off, size_t count)
626 {
627 struct device *dev = container_of(kobj, struct device, kobj);
628 struct power_supply *psy = to_power_supply(dev);
629 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
630
631 count = min_t(loff_t, count,
632 DS2780_EEPROM_BLOCK1_END -
633 DS2780_EEPROM_BLOCK1_START + 1 - off);
634
635 return ds2780_read_block(dev_info->w1_dev, buf,
636 DS2780_EEPROM_BLOCK1_START + off, count);
637 }
638
639 static ssize_t ds2780_write_param_eeprom_bin(struct file *filp,
640 struct kobject *kobj,
641 struct bin_attribute *bin_attr,
642 char *buf, loff_t off, size_t count)
643 {
644 struct device *dev = container_of(kobj, struct device, kobj);
645 struct power_supply *psy = to_power_supply(dev);
646 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
647 int ret;
648
649 count = min_t(loff_t, count,
650 DS2780_EEPROM_BLOCK1_END -
651 DS2780_EEPROM_BLOCK1_START + 1 - off);
652
653 ret = ds2780_write(dev_info->w1_dev, buf,
654 DS2780_EEPROM_BLOCK1_START + off, count);
655 if (ret < 0)
656 return ret;
657
658 ret = ds2780_save_eeprom(dev_info, DS2780_EEPROM_BLOCK1_START);
659 if (ret < 0)
660 return ret;
661
662 return count;
663 }
664
665 static struct bin_attribute ds2780_param_eeprom_bin_attr = {
666 .attr = {
667 .name = "param_eeprom",
668 .mode = S_IRUGO | S_IWUSR,
669 },
670 .size = DS2780_EEPROM_BLOCK1_END - DS2780_EEPROM_BLOCK1_START + 1,
671 .read = ds2780_read_param_eeprom_bin,
672 .write = ds2780_write_param_eeprom_bin,
673 };
674
675 static ssize_t ds2780_read_user_eeprom_bin(struct file *filp,
676 struct kobject *kobj,
677 struct bin_attribute *bin_attr,
678 char *buf, loff_t off, size_t count)
679 {
680 struct device *dev = container_of(kobj, struct device, kobj);
681 struct power_supply *psy = to_power_supply(dev);
682 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
683
684 count = min_t(loff_t, count,
685 DS2780_EEPROM_BLOCK0_END -
686 DS2780_EEPROM_BLOCK0_START + 1 - off);
687
688 return ds2780_read_block(dev_info->w1_dev, buf,
689 DS2780_EEPROM_BLOCK0_START + off, count);
690
691 }
692
693 static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
694 struct kobject *kobj,
695 struct bin_attribute *bin_attr,
696 char *buf, loff_t off, size_t count)
697 {
698 struct device *dev = container_of(kobj, struct device, kobj);
699 struct power_supply *psy = to_power_supply(dev);
700 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
701 int ret;
702
703 count = min_t(loff_t, count,
704 DS2780_EEPROM_BLOCK0_END -
705 DS2780_EEPROM_BLOCK0_START + 1 - off);
706
707 ret = ds2780_write(dev_info->w1_dev, buf,
708 DS2780_EEPROM_BLOCK0_START + off, count);
709 if (ret < 0)
710 return ret;
711
712 ret = ds2780_save_eeprom(dev_info, DS2780_EEPROM_BLOCK0_START);
713 if (ret < 0)
714 return ret;
715
716 return count;
717 }
718
719 static struct bin_attribute ds2780_user_eeprom_bin_attr = {
720 .attr = {
721 .name = "user_eeprom",
722 .mode = S_IRUGO | S_IWUSR,
723 },
724 .size = DS2780_EEPROM_BLOCK0_END - DS2780_EEPROM_BLOCK0_START + 1,
725 .read = ds2780_read_user_eeprom_bin,
726 .write = ds2780_write_user_eeprom_bin,
727 };
728
729 static DEVICE_ATTR(pmod_enabled, S_IRUGO | S_IWUSR, ds2780_get_pmod_enabled,
730 ds2780_set_pmod_enabled);
731 static DEVICE_ATTR(sense_resistor_value, S_IRUGO | S_IWUSR,
732 ds2780_get_sense_resistor_value, ds2780_set_sense_resistor_value);
733 static DEVICE_ATTR(rsgain_setting, S_IRUGO | S_IWUSR, ds2780_get_rsgain_setting,
734 ds2780_set_rsgain_setting);
735 static DEVICE_ATTR(pio_pin, S_IRUGO | S_IWUSR, ds2780_get_pio_pin,
736 ds2780_set_pio_pin);
737
738
739 static struct attribute *ds2780_attributes[] = {
740 &dev_attr_pmod_enabled.attr,
741 &dev_attr_sense_resistor_value.attr,
742 &dev_attr_rsgain_setting.attr,
743 &dev_attr_pio_pin.attr,
744 NULL
745 };
746
747 static const struct attribute_group ds2780_attr_group = {
748 .attrs = ds2780_attributes,
749 };
750
751 static int __devinit ds2780_battery_probe(struct platform_device *pdev)
752 {
753 int ret = 0;
754 struct ds2780_device_info *dev_info;
755
756 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
757 if (!dev_info) {
758 ret = -ENOMEM;
759 goto fail;
760 }
761
762 platform_set_drvdata(pdev, dev_info);
763
764 dev_info->dev = &pdev->dev;
765 dev_info->w1_dev = pdev->dev.parent;
766 dev_info->bat.name = dev_name(&pdev->dev);
767 dev_info->bat.type = POWER_SUPPLY_TYPE_BATTERY;
768 dev_info->bat.properties = ds2780_battery_props;
769 dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props);
770 dev_info->bat.get_property = ds2780_battery_get_property;
771
772 ret = power_supply_register(&pdev->dev, &dev_info->bat);
773 if (ret) {
774 dev_err(dev_info->dev, "failed to register battery\n");
775 goto fail_free_info;
776 }
777
778 ret = sysfs_create_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
779 if (ret) {
780 dev_err(dev_info->dev, "failed to create sysfs group\n");
781 goto fail_unregister;
782 }
783
784 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
785 &ds2780_param_eeprom_bin_attr);
786 if (ret) {
787 dev_err(dev_info->dev,
788 "failed to create param eeprom bin file");
789 goto fail_remove_group;
790 }
791
792 ret = sysfs_create_bin_file(&dev_info->bat.dev->kobj,
793 &ds2780_user_eeprom_bin_attr);
794 if (ret) {
795 dev_err(dev_info->dev,
796 "failed to create user eeprom bin file");
797 goto fail_remove_bin_file;
798 }
799
800 return 0;
801
802 fail_remove_bin_file:
803 sysfs_remove_bin_file(&dev_info->bat.dev->kobj,
804 &ds2780_param_eeprom_bin_attr);
805 fail_remove_group:
806 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
807 fail_unregister:
808 power_supply_unregister(&dev_info->bat);
809 fail_free_info:
810 kfree(dev_info);
811 fail:
812 return ret;
813 }
814
815 static int __devexit ds2780_battery_remove(struct platform_device *pdev)
816 {
817 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev);
818
819 /* remove attributes */
820 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
821
822 power_supply_unregister(&dev_info->bat);
823
824 kfree(dev_info);
825 return 0;
826 }
827
828 MODULE_ALIAS("platform:ds2780-battery");
829
830 static struct platform_driver ds2780_battery_driver = {
831 .driver = {
832 .name = "ds2780-battery",
833 },
834 .probe = ds2780_battery_probe,
835 .remove = ds2780_battery_remove,
836 };
837
838 static int __init ds2780_battery_init(void)
839 {
840 return platform_driver_register(&ds2780_battery_driver);
841 }
842
843 static void __exit ds2780_battery_exit(void)
844 {
845 platform_driver_unregister(&ds2780_battery_driver);
846 }
847
848 module_init(ds2780_battery_init);
849 module_exit(ds2780_battery_exit);
850
851 MODULE_LICENSE("GPL");
852 MODULE_AUTHOR("Clifton Barnes <cabarnes@indesign-llc.com>");
853 MODULE_DESCRIPTION("Maxim/Dallas DS2780 Stand-Alone Fuel Gauage IC driver");
854
drivers/w1/slaves/Kconfig
1 # 1 #
2 # 1-wire slaves configuration 2 # 1-wire slaves configuration
3 # 3 #
4 4
5 menu "1-wire Slaves" 5 menu "1-wire Slaves"
6 6
7 config W1_SLAVE_THERM 7 config W1_SLAVE_THERM
8 tristate "Thermal family implementation" 8 tristate "Thermal family implementation"
9 help 9 help
10 Say Y here if you want to connect 1-wire thermal sensors to your 10 Say Y here if you want to connect 1-wire thermal sensors to your
11 wire. 11 wire.
12 12
13 config W1_SLAVE_SMEM 13 config W1_SLAVE_SMEM
14 tristate "Simple 64bit memory family implementation" 14 tristate "Simple 64bit memory family implementation"
15 help 15 help
16 Say Y here if you want to connect 1-wire 16 Say Y here if you want to connect 1-wire
17 simple 64bit memory rom(ds2401/ds2411/ds1990*) to your wire. 17 simple 64bit memory rom(ds2401/ds2411/ds1990*) to your wire.
18 18
19 config W1_SLAVE_DS2408 19 config W1_SLAVE_DS2408
20 tristate "8-Channel Addressable Switch (IO Expander) 0x29 family support (DS2408)" 20 tristate "8-Channel Addressable Switch (IO Expander) 0x29 family support (DS2408)"
21 help 21 help
22 Say Y here if you want to use a 1-wire 22 Say Y here if you want to use a 1-wire
23 23
24 DS2408 8-Channel Addressable Switch device support 24 DS2408 8-Channel Addressable Switch device support
25 25
26 config W1_SLAVE_DS2423 26 config W1_SLAVE_DS2423
27 tristate "Counter 1-wire device (DS2423)" 27 tristate "Counter 1-wire device (DS2423)"
28 select CRC16 28 select CRC16
29 help 29 help
30 If you enable this you can read the counter values available 30 If you enable this you can read the counter values available
31 in the DS2423 chipset from the w1_slave file under the 31 in the DS2423 chipset from the w1_slave file under the
32 sys file system. 32 sys file system.
33 33
34 Say Y here if you want to use a 1-wire 34 Say Y here if you want to use a 1-wire
35 counter family device (DS2423). 35 counter family device (DS2423).
36 36
37 config W1_SLAVE_DS2431 37 config W1_SLAVE_DS2431
38 tristate "1kb EEPROM family support (DS2431)" 38 tristate "1kb EEPROM family support (DS2431)"
39 help 39 help
40 Say Y here if you want to use a 1-wire 40 Say Y here if you want to use a 1-wire
41 1kb EEPROM family device (DS2431) 41 1kb EEPROM family device (DS2431)
42 42
43 config W1_SLAVE_DS2433 43 config W1_SLAVE_DS2433
44 tristate "4kb EEPROM family support (DS2433)" 44 tristate "4kb EEPROM family support (DS2433)"
45 help 45 help
46 Say Y here if you want to use a 1-wire 46 Say Y here if you want to use a 1-wire
47 4kb EEPROM family device (DS2433). 47 4kb EEPROM family device (DS2433).
48 48
49 config W1_SLAVE_DS2433_CRC 49 config W1_SLAVE_DS2433_CRC
50 bool "Protect DS2433 data with a CRC16" 50 bool "Protect DS2433 data with a CRC16"
51 depends on W1_SLAVE_DS2433 51 depends on W1_SLAVE_DS2433
52 select CRC16 52 select CRC16
53 help 53 help
54 Say Y here to protect DS2433 data with a CRC16. 54 Say Y here to protect DS2433 data with a CRC16.
55 Each block has 30 bytes of data and a two byte CRC16. 55 Each block has 30 bytes of data and a two byte CRC16.
56 Full block writes are only allowed if the CRC is valid. 56 Full block writes are only allowed if the CRC is valid.
57 57
58 config W1_SLAVE_DS2760 58 config W1_SLAVE_DS2760
59 tristate "Dallas 2760 battery monitor chip (HP iPAQ & others)" 59 tristate "Dallas 2760 battery monitor chip (HP iPAQ & others)"
60 depends on W1 60 depends on W1
61 help 61 help
62 If you enable this you will have the DS2760 battery monitor 62 If you enable this you will have the DS2760 battery monitor
63 chip support. 63 chip support.
64 64
65 The battery monitor chip is used in many batteries/devices 65 The battery monitor chip is used in many batteries/devices
66 as the one who is responsible for charging/discharging/monitoring 66 as the one who is responsible for charging/discharging/monitoring
67 Li+ batteries. 67 Li+ batteries.
68 68
69 If you are unsure, say N. 69 If you are unsure, say N.
70 70
71 config W1_SLAVE_DS2780
72 tristate "Dallas 2780 battery monitor chip"
73 depends on W1
74 help
75 If you enable this you will have the DS2780 battery monitor
76 chip support.
77
78 The battery monitor chip is used in many batteries/devices
79 as the one who is responsible for charging/discharging/monitoring
80 Li+ batteries.
81
82 If you are unsure, say N.
83
71 config W1_SLAVE_BQ27000 84 config W1_SLAVE_BQ27000
72 tristate "BQ27000 slave support" 85 tristate "BQ27000 slave support"
73 depends on W1 86 depends on W1
74 help 87 help
75 Say Y here if you want to use a hdq 88 Say Y here if you want to use a hdq
76 bq27000 slave support. 89 bq27000 slave support.
77 90
78 endmenu 91 endmenu
79 92
drivers/w1/slaves/Makefile
1 # 1 #
2 # Makefile for the Dallas's 1-wire slaves. 2 # Makefile for the Dallas's 1-wire slaves.
3 # 3 #
4 4
5 obj-$(CONFIG_W1_SLAVE_THERM) += w1_therm.o 5 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_DS2408) += w1_ds2408.o 7 obj-$(CONFIG_W1_SLAVE_DS2408) += w1_ds2408.o
8 obj-$(CONFIG_W1_SLAVE_DS2423) += w1_ds2423.o 8 obj-$(CONFIG_W1_SLAVE_DS2423) += w1_ds2423.o
9 obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o 9 obj-$(CONFIG_W1_SLAVE_DS2431) += w1_ds2431.o
10 obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o 10 obj-$(CONFIG_W1_SLAVE_DS2433) += w1_ds2433.o
11 obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o 11 obj-$(CONFIG_W1_SLAVE_DS2760) += w1_ds2760.o
12 obj-$(CONFIG_W1_SLAVE_DS2780) += w1_ds2780.o
12 obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o 13 obj-$(CONFIG_W1_SLAVE_BQ27000) += w1_bq27000.o
13 14
drivers/w1/slaves/w1_ds2780.c
File was created 1 /*
2 * 1-Wire implementation for the ds2780 chip
3 *
4 * Copyright (C) 2010 Indesign, LLC
5 *
6 * Author: Clifton Barnes <cabarnes@indesign-llc.com>
7 *
8 * Based on w1-ds2760 driver
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/device.h>
19 #include <linux/types.h>
20 #include <linux/platform_device.h>
21 #include <linux/mutex.h>
22 #include <linux/idr.h>
23
24 #include "../w1.h"
25 #include "../w1_int.h"
26 #include "../w1_family.h"
27 #include "w1_ds2780.h"
28
29 int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
30 int io)
31 {
32 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
33
34 if (!dev)
35 return -ENODEV;
36
37 mutex_lock(&sl->master->mutex);
38
39 if (addr > DS2780_DATA_SIZE || addr < 0) {
40 count = 0;
41 goto out;
42 }
43 count = min_t(int, count, DS2780_DATA_SIZE - addr);
44
45 if (w1_reset_select_slave(sl) == 0) {
46 if (io) {
47 w1_write_8(sl->master, W1_DS2780_WRITE_DATA);
48 w1_write_8(sl->master, addr);
49 w1_write_block(sl->master, buf, count);
50 /* XXX w1_write_block returns void, not n_written */
51 } else {
52 w1_write_8(sl->master, W1_DS2780_READ_DATA);
53 w1_write_8(sl->master, addr);
54 count = w1_read_block(sl->master, buf, count);
55 }
56 }
57
58 out:
59 mutex_unlock(&sl->master->mutex);
60
61 return count;
62 }
63 EXPORT_SYMBOL(w1_ds2780_io);
64
65 int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd)
66 {
67 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
68
69 if (!dev)
70 return -EINVAL;
71
72 mutex_lock(&sl->master->mutex);
73
74 if (w1_reset_select_slave(sl) == 0) {
75 w1_write_8(sl->master, cmd);
76 w1_write_8(sl->master, addr);
77 }
78
79 mutex_unlock(&sl->master->mutex);
80 return 0;
81 }
82 EXPORT_SYMBOL(w1_ds2780_eeprom_cmd);
83
84 static ssize_t w1_ds2780_read_bin(struct file *filp,
85 struct kobject *kobj,
86 struct bin_attribute *bin_attr,
87 char *buf, loff_t off, size_t count)
88 {
89 struct device *dev = container_of(kobj, struct device, kobj);
90 return w1_ds2780_io(dev, buf, off, count, 0);
91 }
92
93 static struct bin_attribute w1_ds2780_bin_attr = {
94 .attr = {
95 .name = "w1_slave",
96 .mode = S_IRUGO,
97 },
98 .size = DS2780_DATA_SIZE,
99 .read = w1_ds2780_read_bin,
100 };
101
102 static DEFINE_IDR(bat_idr);
103 static DEFINE_MUTEX(bat_idr_lock);
104
105 static int new_bat_id(void)
106 {
107 int ret;
108
109 while (1) {
110 int id;
111
112 ret = idr_pre_get(&bat_idr, GFP_KERNEL);
113 if (ret == 0)
114 return -ENOMEM;
115
116 mutex_lock(&bat_idr_lock);
117 ret = idr_get_new(&bat_idr, NULL, &id);
118 mutex_unlock(&bat_idr_lock);
119
120 if (ret == 0) {
121 ret = id & MAX_ID_MASK;
122 break;
123 } else if (ret == -EAGAIN) {
124 continue;
125 } else {
126 break;
127 }
128 }
129
130 return ret;
131 }
132
133 static void release_bat_id(int id)
134 {
135 mutex_lock(&bat_idr_lock);
136 idr_remove(&bat_idr, id);
137 mutex_unlock(&bat_idr_lock);
138 }
139
140 static int w1_ds2780_add_slave(struct w1_slave *sl)
141 {
142 int ret;
143 int id;
144 struct platform_device *pdev;
145
146 id = new_bat_id();
147 if (id < 0) {
148 ret = id;
149 goto noid;
150 }
151
152 pdev = platform_device_alloc("ds2780-battery", id);
153 if (!pdev) {
154 ret = -ENOMEM;
155 goto pdev_alloc_failed;
156 }
157 pdev->dev.parent = &sl->dev;
158
159 ret = platform_device_add(pdev);
160 if (ret)
161 goto pdev_add_failed;
162
163 ret = sysfs_create_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr);
164 if (ret)
165 goto bin_attr_failed;
166
167 dev_set_drvdata(&sl->dev, pdev);
168
169 return 0;
170
171 bin_attr_failed:
172 pdev_add_failed:
173 platform_device_unregister(pdev);
174 pdev_alloc_failed:
175 release_bat_id(id);
176 noid:
177 return ret;
178 }
179
180 static void w1_ds2780_remove_slave(struct w1_slave *sl)
181 {
182 struct platform_device *pdev = dev_get_drvdata(&sl->dev);
183 int id = pdev->id;
184
185 platform_device_unregister(pdev);
186 release_bat_id(id);
187 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr);
188 }
189
190 static struct w1_family_ops w1_ds2780_fops = {
191 .add_slave = w1_ds2780_add_slave,
192 .remove_slave = w1_ds2780_remove_slave,
193 };
194
195 static struct w1_family w1_ds2780_family = {
196 .fid = W1_FAMILY_DS2780,
197 .fops = &w1_ds2780_fops,
198 };
199
200 static int __init w1_ds2780_init(void)
201 {
202 idr_init(&bat_idr);
203 return w1_register_family(&w1_ds2780_family);
204 }
205
206 static void __exit w1_ds2780_exit(void)
207 {
208 w1_unregister_family(&w1_ds2780_family);
209 idr_destroy(&bat_idr);
210 }
211
212 module_init(w1_ds2780_init);
213 module_exit(w1_ds2780_exit);
214
215 MODULE_LICENSE("GPL");
216 MODULE_AUTHOR("Clifton Barnes <cabarnes@indesign-llc.com>");
217 MODULE_DESCRIPTION("1-wire Driver for Maxim/Dallas DS2780 Stand-Alone Fuel Gauge IC");
218
drivers/w1/slaves/w1_ds2780.h
File was created 1 /*
2 * 1-Wire implementation for the ds2780 chip
3 *
4 * Copyright (C) 2010 Indesign, LLC
5 *
6 * Author: Clifton Barnes <cabarnes@indesign-llc.com>
7 *
8 * Based on w1-ds2760 driver
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16 #ifndef _W1_DS2780_H
17 #define _W1_DS2780_H
18
19 /* Function commands */
20 #define W1_DS2780_READ_DATA 0x69
21 #define W1_DS2780_WRITE_DATA 0x6C
22 #define W1_DS2780_COPY_DATA 0x48
23 #define W1_DS2780_RECALL_DATA 0xB8
24 #define W1_DS2780_LOCK 0x6A
25
26 /* Register map */
27 /* Register 0x00 Reserved */
28 #define DS2780_STATUS_REG 0x01
29 #define DS2780_RAAC_MSB_REG 0x02
30 #define DS2780_RAAC_LSB_REG 0x03
31 #define DS2780_RSAC_MSB_REG 0x04
32 #define DS2780_RSAC_LSB_REG 0x05
33 #define DS2780_RARC_REG 0x06
34 #define DS2780_RSRC_REG 0x07
35 #define DS2780_IAVG_MSB_REG 0x08
36 #define DS2780_IAVG_LSB_REG 0x09
37 #define DS2780_TEMP_MSB_REG 0x0A
38 #define DS2780_TEMP_LSB_REG 0x0B
39 #define DS2780_VOLT_MSB_REG 0x0C
40 #define DS2780_VOLT_LSB_REG 0x0D
41 #define DS2780_CURRENT_MSB_REG 0x0E
42 #define DS2780_CURRENT_LSB_REG 0x0F
43 #define DS2780_ACR_MSB_REG 0x10
44 #define DS2780_ACR_LSB_REG 0x11
45 #define DS2780_ACRL_MSB_REG 0x12
46 #define DS2780_ACRL_LSB_REG 0x13
47 #define DS2780_AS_REG 0x14
48 #define DS2780_SFR_REG 0x15
49 #define DS2780_FULL_MSB_REG 0x16
50 #define DS2780_FULL_LSB_REG 0x17
51 #define DS2780_AE_MSB_REG 0x18
52 #define DS2780_AE_LSB_REG 0x19
53 #define DS2780_SE_MSB_REG 0x1A
54 #define DS2780_SE_LSB_REG 0x1B
55 /* Register 0x1C - 0x1E Reserved */
56 #define DS2780_EEPROM_REG 0x1F
57 #define DS2780_EEPROM_BLOCK0_START 0x20
58 /* Register 0x20 - 0x2F User EEPROM */
59 #define DS2780_EEPROM_BLOCK0_END 0x2F
60 /* Register 0x30 - 0x5F Reserved */
61 #define DS2780_EEPROM_BLOCK1_START 0x60
62 #define DS2780_CONTROL_REG 0x60
63 #define DS2780_AB_REG 0x61
64 #define DS2780_AC_MSB_REG 0x62
65 #define DS2780_AC_LSB_REG 0x63
66 #define DS2780_VCHG_REG 0x64
67 #define DS2780_IMIN_REG 0x65
68 #define DS2780_VAE_REG 0x66
69 #define DS2780_IAE_REG 0x67
70 #define DS2780_AE_40_REG 0x68
71 #define DS2780_RSNSP_REG 0x69
72 #define DS2780_FULL_40_MSB_REG 0x6A
73 #define DS2780_FULL_40_LSB_REG 0x6B
74 #define DS2780_FULL_3040_SLOPE_REG 0x6C
75 #define DS2780_FULL_2030_SLOPE_REG 0x6D
76 #define DS2780_FULL_1020_SLOPE_REG 0x6E
77 #define DS2780_FULL_0010_SLOPE_REG 0x6F
78 #define DS2780_AE_3040_SLOPE_REG 0x70
79 #define DS2780_AE_2030_SLOPE_REG 0x71
80 #define DS2780_AE_1020_SLOPE_REG 0x72
81 #define DS2780_AE_0010_SLOPE_REG 0x73
82 #define DS2780_SE_3040_SLOPE_REG 0x74
83 #define DS2780_SE_2030_SLOPE_REG 0x75
84 #define DS2780_SE_1020_SLOPE_REG 0x76
85 #define DS2780_SE_0010_SLOPE_REG 0x77
86 #define DS2780_RSGAIN_MSB_REG 0x78
87 #define DS2780_RSGAIN_LSB_REG 0x79
88 #define DS2780_RSTC_REG 0x7A
89 #define DS2780_FRSGAIN_MSB_REG 0x7B
90 #define DS2780_FRSGAIN_LSB_REG 0x7C
91 #define DS2780_EEPROM_BLOCK1_END 0x7C
92 /* Register 0x7D - 0xFF Reserved */
93
94 /* Number of valid register addresses */
95 #define DS2780_DATA_SIZE 0x80
96
97 /* Status register bits */
98 #define DS2780_STATUS_REG_CHGTF (1 << 7)
99 #define DS2780_STATUS_REG_AEF (1 << 6)
100 #define DS2780_STATUS_REG_SEF (1 << 5)
101 #define DS2780_STATUS_REG_LEARNF (1 << 4)
102 /* Bit 3 Reserved */
103 #define DS2780_STATUS_REG_UVF (1 << 2)
104 #define DS2780_STATUS_REG_PORF (1 << 1)
105 /* Bit 0 Reserved */
106
107 /* Control register bits */
108 /* Bit 7 Reserved */
109 #define DS2780_CONTROL_REG_UVEN (1 << 6)
110 #define DS2780_CONTROL_REG_PMOD (1 << 5)
111 #define DS2780_CONTROL_REG_RNAOP (1 << 4)
112 /* Bit 0 - 3 Reserved */
113
114 /* Special feature register bits */
115 /* Bit 1 - 7 Reserved */
116 #define DS2780_SFR_REG_PIOSC (1 << 0)
117
118 /* EEPROM register bits */
119 #define DS2780_EEPROM_REG_EEC (1 << 7)
120 #define DS2780_EEPROM_REG_LOCK (1 << 6)
121 /* Bit 2 - 6 Reserved */
122 #define DS2780_EEPROM_REG_BL1 (1 << 1)
123 #define DS2780_EEPROM_REG_BL0 (1 << 0)
124
125 extern int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
126 int io);
127 extern int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd);
128
129 #endif /* !_W1_DS2780_H */
130
drivers/w1/w1_family.h
1 /* 1 /*
2 * w1_family.h 2 * w1_family.h
3 * 3 *
4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> 4 * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
5 * 5 *
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22 #ifndef __W1_FAMILY_H 22 #ifndef __W1_FAMILY_H
23 #define __W1_FAMILY_H 23 #define __W1_FAMILY_H
24 24
25 #include <linux/types.h> 25 #include <linux/types.h>
26 #include <linux/device.h> 26 #include <linux/device.h>
27 #include <asm/atomic.h> 27 #include <asm/atomic.h>
28 28
29 #define W1_FAMILY_DEFAULT 0 29 #define W1_FAMILY_DEFAULT 0
30 #define W1_FAMILY_SMEM_01 0x01 30 #define W1_FAMILY_SMEM_01 0x01
31 #define W1_FAMILY_SMEM_81 0x81 31 #define W1_FAMILY_SMEM_81 0x81
32 #define W1_THERM_DS18S20 0x10 32 #define W1_THERM_DS18S20 0x10
33 #define W1_COUNTER_DS2423 0x1D 33 #define W1_COUNTER_DS2423 0x1D
34 #define W1_THERM_DS1822 0x22 34 #define W1_THERM_DS1822 0x22
35 #define W1_EEPROM_DS2433 0x23 35 #define W1_EEPROM_DS2433 0x23
36 #define W1_THERM_DS18B20 0x28 36 #define W1_THERM_DS18B20 0x28
37 #define W1_FAMILY_DS2408 0x29 37 #define W1_FAMILY_DS2408 0x29
38 #define W1_EEPROM_DS2431 0x2D 38 #define W1_EEPROM_DS2431 0x2D
39 #define W1_FAMILY_DS2760 0x30 39 #define W1_FAMILY_DS2760 0x30
40 #define W1_FAMILY_DS2780 0x32
40 41
41 #define MAXNAMELEN 32 42 #define MAXNAMELEN 32
42 43
43 struct w1_slave; 44 struct w1_slave;
44 45
45 struct w1_family_ops 46 struct w1_family_ops
46 { 47 {
47 int (* add_slave)(struct w1_slave *); 48 int (* add_slave)(struct w1_slave *);
48 void (* remove_slave)(struct w1_slave *); 49 void (* remove_slave)(struct w1_slave *);
49 }; 50 };
50 51
51 struct w1_family 52 struct w1_family
52 { 53 {
53 struct list_head family_entry; 54 struct list_head family_entry;
54 u8 fid; 55 u8 fid;
55 56
56 struct w1_family_ops *fops; 57 struct w1_family_ops *fops;
57 58
58 atomic_t refcnt; 59 atomic_t refcnt;
59 }; 60 };
60 61
61 extern spinlock_t w1_flock; 62 extern spinlock_t w1_flock;
62 63
63 void w1_family_put(struct w1_family *); 64 void w1_family_put(struct w1_family *);
64 void __w1_family_get(struct w1_family *); 65 void __w1_family_get(struct w1_family *);
65 struct w1_family * w1_family_registered(u8); 66 struct w1_family * w1_family_registered(u8);
66 void w1_unregister_family(struct w1_family *); 67 void w1_unregister_family(struct w1_family *);
67 int w1_register_family(struct w1_family *); 68 int w1_register_family(struct w1_family *);
68 69
69 #endif /* __W1_FAMILY_H */ 70 #endif /* __W1_FAMILY_H */
70 71