aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorMichal Marek <mmarek@suse.cz>2010-08-04 08:05:07 -0400
committerMichal Marek <mmarek@suse.cz>2010-08-04 08:05:07 -0400
commit7a996d3ab150bb0e1b71fa182f70199a703efdd1 (patch)
tree96a36947d90c9b96580899abd38cb3b70cd9d40b /drivers/misc
parent7cf3d73b4360e91b14326632ab1aeda4cb26308d (diff)
parent9fe6206f400646a2322096b56c59891d530e8d51 (diff)
Merge commit 'v2.6.35' into kbuild/kconfig
Conflicts: scripts/kconfig/Makefile
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/Kconfig67
-rw-r--r--drivers/misc/Makefile5
-rw-r--r--drivers/misc/ad525x_dpot-i2c.c134
-rw-r--r--drivers/misc/ad525x_dpot-spi.c172
-rw-r--r--drivers/misc/ad525x_dpot.c1016
-rw-r--r--drivers/misc/ad525x_dpot.h202
-rw-r--r--drivers/misc/atmel-ssc.c1
-rw-r--r--drivers/misc/atmel_pwm.c1
-rw-r--r--drivers/misc/atmel_tclib.c1
-rw-r--r--drivers/misc/c2port/core.c9
-rw-r--r--drivers/misc/cb710/core.c2
-rw-r--r--drivers/misc/cb710/debug.c1
-rw-r--r--drivers/misc/cs5535-mfgpt.c3
-rw-r--r--drivers/misc/ds1682.c7
-rw-r--r--drivers/misc/eeprom/at24.c67
-rw-r--r--drivers/misc/eeprom/at25.c7
-rw-r--r--drivers/misc/eeprom/eeprom.c39
-rw-r--r--drivers/misc/eeprom/eeprom_93cx6.c39
-rw-r--r--drivers/misc/eeprom/max6875.c54
-rw-r--r--drivers/misc/enclosure.c1
-rw-r--r--drivers/misc/ep93xx_pwm.c1
-rw-r--r--drivers/misc/hdpuftrs/Makefile1
-rw-r--r--drivers/misc/hdpuftrs/hdpu_cpustate.c256
-rw-r--r--drivers/misc/hdpuftrs/hdpu_nexus.c149
-rw-r--r--drivers/misc/hpilo.c1
-rw-r--r--drivers/misc/ibmasm/command.c1
-rw-r--r--drivers/misc/ibmasm/event.c1
-rw-r--r--drivers/misc/ibmasm/ibmasmfs.c1
-rw-r--r--drivers/misc/ibmasm/module.c1
-rw-r--r--drivers/misc/ics932s401.c1
-rw-r--r--drivers/misc/ioc4.c1
-rw-r--r--drivers/misc/iwmc3200top/debugfs.c1
-rw-r--r--drivers/misc/iwmc3200top/fw-download.c51
-rw-r--r--drivers/misc/iwmc3200top/iwmc3200top.h4
-rw-r--r--drivers/misc/iwmc3200top/log.c1
-rw-r--r--drivers/misc/iwmc3200top/log.h31
-rw-r--r--drivers/misc/iwmc3200top/main.c62
-rw-r--r--drivers/misc/kgdbts.c6
-rw-r--r--drivers/misc/lkdtm.c493
-rw-r--r--drivers/misc/phantom.c14
-rw-r--r--drivers/misc/sgi-gru/grutables.h15
-rw-r--r--drivers/misc/sgi-xp/xpc_main.c1
-rw-r--r--drivers/misc/sgi-xp/xpc_partition.c1
-rw-r--r--drivers/misc/sgi-xp/xpc_sn2.c1
-rw-r--r--drivers/misc/sgi-xp/xpc_uv.c1
-rw-r--r--drivers/misc/sgi-xp/xpnet.c3
-rw-r--r--drivers/misc/tifm_core.c1
-rw-r--r--drivers/misc/tsl2550.c473
-rw-r--r--drivers/misc/vmware_balloon.c844
49 files changed, 3064 insertions, 1181 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index e3551d20464f..26386a92f5aa 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -14,11 +14,17 @@ menuconfig MISC_DEVICES
14if MISC_DEVICES 14if MISC_DEVICES
15 15
16config AD525X_DPOT 16config AD525X_DPOT
17 tristate "Analog Devices AD525x Digital Potentiometers" 17 tristate "Analog Devices Digital Potentiometers"
18 depends on I2C && SYSFS 18 depends on (I2C || SPI) && SYSFS
19 help 19 help
20 If you say yes here, you get support for the Analog Devices 20 If you say yes here, you get support for the Analog Devices
21 AD5258, AD5259, AD5251, AD5252, AD5253, AD5254 and AD5255 21 AD5258, AD5259, AD5251, AD5252, AD5253, AD5254, AD5255
22 AD5160, AD5161, AD5162, AD5165, AD5200, AD5201, AD5203,
23 AD5204, AD5206, AD5207, AD5231, AD5232, AD5233, AD5235,
24 AD5260, AD5262, AD5263, AD5290, AD5291, AD5292, AD5293,
25 AD7376, AD8400, AD8402, AD8403, ADN2850, AD5241, AD5242,
26 AD5243, AD5245, AD5246, AD5247, AD5248, AD5280, AD5282,
27 ADN2860, AD5273, AD5171, AD5170, AD5172, AD5173
22 digital potentiometer chips. 28 digital potentiometer chips.
23 29
24 See Documentation/misc-devices/ad525x_dpot.txt for the 30 See Documentation/misc-devices/ad525x_dpot.txt for the
@@ -27,6 +33,26 @@ config AD525X_DPOT
27 This driver can also be built as a module. If so, the module 33 This driver can also be built as a module. If so, the module
28 will be called ad525x_dpot. 34 will be called ad525x_dpot.
29 35
36config AD525X_DPOT_I2C
37 tristate "support I2C bus connection"
38 depends on AD525X_DPOT && I2C
39 help
40 Say Y here if you have a digital potentiometers hooked to an I2C bus.
41
42 To compile this driver as a module, choose M here: the
43 module will be called ad525x_dpot-i2c.
44
45config AD525X_DPOT_SPI
46 tristate "support SPI bus connection"
47 depends on AD525X_DPOT && SPI_MASTER
48 help
49 Say Y here if you have a digital potentiometers hooked to an SPI bus.
50
51 If unsure, say N (but it's safe to say "Y").
52
53 To compile this driver as a module, choose M here: the
54 module will be called ad525x_dpot-spi.
55
30config ATMEL_PWM 56config ATMEL_PWM
31 tristate "Atmel AT32/AT91 PWM support" 57 tristate "Atmel AT32/AT91 PWM support"
32 depends on AVR32 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9 58 depends on AVR32 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9
@@ -212,6 +238,15 @@ config CS5535_MFGPT_DEFAULT_IRQ
212 want to use a different IRQ by default. This is here for 238 want to use a different IRQ by default. This is here for
213 architectures to set as necessary. 239 architectures to set as necessary.
214 240
241config CS5535_CLOCK_EVENT_SRC
242 tristate "CS5535/CS5536 high-res timer (MFGPT) events"
243 depends on GENERIC_TIME && GENERIC_CLOCKEVENTS && CS5535_MFGPT
244 help
245 This driver provides a clock event source based on the MFGPT
246 timer(s) in the CS5535 and CS5536 companion chips.
247 MFGPTs have a better resolution and max interval than the
248 generic PIT, and are suitable for use as high-res timers.
249
215config HP_ILO 250config HP_ILO
216 tristate "Channel interface driver for HP iLO/iLO2 processor" 251 tristate "Channel interface driver for HP iLO/iLO2 processor"
217 depends on PCI 252 depends on PCI
@@ -259,6 +294,16 @@ config ISL29003
259 This driver can also be built as a module. If so, the module 294 This driver can also be built as a module. If so, the module
260 will be called isl29003. 295 will be called isl29003.
261 296
297config SENSORS_TSL2550
298 tristate "Taos TSL2550 ambient light sensor"
299 depends on I2C && SYSFS
300 help
301 If you say yes here you get support for the Taos TSL2550
302 ambient light sensor.
303
304 This driver can also be built as a module. If so, the module
305 will be called tsl2550.
306
262config EP93XX_PWM 307config EP93XX_PWM
263 tristate "EP93xx PWM support" 308 tristate "EP93xx PWM support"
264 depends on ARCH_EP93XX 309 depends on ARCH_EP93XX
@@ -292,6 +337,22 @@ config TI_DAC7512
292 This driver can also be built as a module. If so, the module 337 This driver can also be built as a module. If so, the module
293 will be calles ti_dac7512. 338 will be calles ti_dac7512.
294 339
340config VMWARE_BALLOON
341 tristate "VMware Balloon Driver"
342 depends on X86
343 help
344 This is VMware physical memory management driver which acts
345 like a "balloon" that can be inflated to reclaim physical pages
346 by reserving them in the guest and invalidating them in the
347 monitor, freeing up the underlying machine pages so they can
348 be allocated to other guests. The balloon can also be deflated
349 to allow the guest to use more physical memory.
350
351 If unsure, say N.
352
353 To compile this driver as a module, choose M here: the
354 module will be called vmware_balloon.
355
295source "drivers/misc/c2port/Kconfig" 356source "drivers/misc/c2port/Kconfig"
296source "drivers/misc/eeprom/Kconfig" 357source "drivers/misc/eeprom/Kconfig"
297source "drivers/misc/cb710/Kconfig" 358source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 049ff2482f30..6ed06a19474a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -3,8 +3,9 @@
3# 3#
4 4
5obj-$(CONFIG_IBM_ASM) += ibmasm/ 5obj-$(CONFIG_IBM_ASM) += ibmasm/
6obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/
7obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o 6obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o
7obj-$(CONFIG_AD525X_DPOT_I2C) += ad525x_dpot-i2c.o
8obj-$(CONFIG_AD525X_DPOT_SPI) += ad525x_dpot-spi.o
8obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o 9obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
9obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o 10obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
10obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o 11obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
@@ -21,6 +22,7 @@ obj-$(CONFIG_SGI_GRU) += sgi-gru/
21obj-$(CONFIG_CS5535_MFGPT) += cs5535-mfgpt.o 22obj-$(CONFIG_CS5535_MFGPT) += cs5535-mfgpt.o
22obj-$(CONFIG_HP_ILO) += hpilo.o 23obj-$(CONFIG_HP_ILO) += hpilo.o
23obj-$(CONFIG_ISL29003) += isl29003.o 24obj-$(CONFIG_ISL29003) += isl29003.o
25obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o
24obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o 26obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o
25obj-$(CONFIG_DS1682) += ds1682.o 27obj-$(CONFIG_DS1682) += ds1682.o
26obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o 28obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o
@@ -28,3 +30,4 @@ obj-$(CONFIG_C2PORT) += c2port/
28obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/ 30obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/
29obj-y += eeprom/ 31obj-y += eeprom/
30obj-y += cb710/ 32obj-y += cb710/
33obj-$(CONFIG_VMWARE_BALLOON) += vmware_balloon.o
diff --git a/drivers/misc/ad525x_dpot-i2c.c b/drivers/misc/ad525x_dpot-i2c.c
new file mode 100644
index 000000000000..374352af7979
--- /dev/null
+++ b/drivers/misc/ad525x_dpot-i2c.c
@@ -0,0 +1,134 @@
1/*
2 * Driver for the Analog Devices digital potentiometers (I2C bus)
3 *
4 * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/i2c.h>
10#include <linux/module.h>
11
12#include "ad525x_dpot.h"
13
14/* ------------------------------------------------------------------------- */
15/* I2C bus functions */
16static int write_d8(void *client, u8 val)
17{
18 return i2c_smbus_write_byte(client, val);
19}
20
21static int write_r8d8(void *client, u8 reg, u8 val)
22{
23 return i2c_smbus_write_byte_data(client, reg, val);
24}
25
26static int write_r8d16(void *client, u8 reg, u16 val)
27{
28 return i2c_smbus_write_word_data(client, reg, val);
29}
30
31static int read_d8(void *client)
32{
33 return i2c_smbus_read_byte(client);
34}
35
36static int read_r8d8(void *client, u8 reg)
37{
38 return i2c_smbus_read_byte_data(client, reg);
39}
40
41static int read_r8d16(void *client, u8 reg)
42{
43 return i2c_smbus_read_word_data(client, reg);
44}
45
46static const struct ad_dpot_bus_ops bops = {
47 .read_d8 = read_d8,
48 .read_r8d8 = read_r8d8,
49 .read_r8d16 = read_r8d16,
50 .write_d8 = write_d8,
51 .write_r8d8 = write_r8d8,
52 .write_r8d16 = write_r8d16,
53};
54
55static int __devinit ad_dpot_i2c_probe(struct i2c_client *client,
56 const struct i2c_device_id *id)
57{
58 struct ad_dpot_bus_data bdata = {
59 .client = client,
60 .bops = &bops,
61 };
62
63 struct ad_dpot_id dpot_id = {
64 .name = (char *) &id->name,
65 .devid = id->driver_data,
66 };
67
68 if (!i2c_check_functionality(client->adapter,
69 I2C_FUNC_SMBUS_WORD_DATA)) {
70 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
71 return -EIO;
72 }
73
74 return ad_dpot_probe(&client->dev, &bdata, &dpot_id);
75}
76
77static int __devexit ad_dpot_i2c_remove(struct i2c_client *client)
78{
79 return ad_dpot_remove(&client->dev);
80}
81
82static const struct i2c_device_id ad_dpot_id[] = {
83 {"ad5258", AD5258_ID},
84 {"ad5259", AD5259_ID},
85 {"ad5251", AD5251_ID},
86 {"ad5252", AD5252_ID},
87 {"ad5253", AD5253_ID},
88 {"ad5254", AD5254_ID},
89 {"ad5255", AD5255_ID},
90 {"ad5241", AD5241_ID},
91 {"ad5242", AD5242_ID},
92 {"ad5243", AD5243_ID},
93 {"ad5245", AD5245_ID},
94 {"ad5246", AD5246_ID},
95 {"ad5247", AD5247_ID},
96 {"ad5248", AD5248_ID},
97 {"ad5280", AD5280_ID},
98 {"ad5282", AD5282_ID},
99 {"adn2860", ADN2860_ID},
100 {"ad5273", AD5273_ID},
101 {"ad5171", AD5171_ID},
102 {"ad5170", AD5170_ID},
103 {"ad5172", AD5172_ID},
104 {"ad5173", AD5173_ID},
105 {}
106};
107MODULE_DEVICE_TABLE(i2c, ad_dpot_id);
108
109static struct i2c_driver ad_dpot_i2c_driver = {
110 .driver = {
111 .name = "ad_dpot",
112 .owner = THIS_MODULE,
113 },
114 .probe = ad_dpot_i2c_probe,
115 .remove = __devexit_p(ad_dpot_i2c_remove),
116 .id_table = ad_dpot_id,
117};
118
119static int __init ad_dpot_i2c_init(void)
120{
121 return i2c_add_driver(&ad_dpot_i2c_driver);
122}
123module_init(ad_dpot_i2c_init);
124
125static void __exit ad_dpot_i2c_exit(void)
126{
127 i2c_del_driver(&ad_dpot_i2c_driver);
128}
129module_exit(ad_dpot_i2c_exit);
130
131MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
132MODULE_DESCRIPTION("digital potentiometer I2C bus driver");
133MODULE_LICENSE("GPL");
134MODULE_ALIAS("i2c:ad_dpot");
diff --git a/drivers/misc/ad525x_dpot-spi.c b/drivers/misc/ad525x_dpot-spi.c
new file mode 100644
index 000000000000..b8c6df9c8437
--- /dev/null
+++ b/drivers/misc/ad525x_dpot-spi.c
@@ -0,0 +1,172 @@
1/*
2 * Driver for the Analog Devices digital potentiometers (SPI bus)
3 *
4 * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/spi/spi.h>
10#include <linux/module.h>
11
12#include "ad525x_dpot.h"
13
14static const struct ad_dpot_id ad_dpot_spi_devlist[] = {
15 {.name = "ad5160", .devid = AD5160_ID},
16 {.name = "ad5161", .devid = AD5161_ID},
17 {.name = "ad5162", .devid = AD5162_ID},
18 {.name = "ad5165", .devid = AD5165_ID},
19 {.name = "ad5200", .devid = AD5200_ID},
20 {.name = "ad5201", .devid = AD5201_ID},
21 {.name = "ad5203", .devid = AD5203_ID},
22 {.name = "ad5204", .devid = AD5204_ID},
23 {.name = "ad5206", .devid = AD5206_ID},
24 {.name = "ad5207", .devid = AD5207_ID},
25 {.name = "ad5231", .devid = AD5231_ID},
26 {.name = "ad5232", .devid = AD5232_ID},
27 {.name = "ad5233", .devid = AD5233_ID},
28 {.name = "ad5235", .devid = AD5235_ID},
29 {.name = "ad5260", .devid = AD5260_ID},
30 {.name = "ad5262", .devid = AD5262_ID},
31 {.name = "ad5263", .devid = AD5263_ID},
32 {.name = "ad5290", .devid = AD5290_ID},
33 {.name = "ad5291", .devid = AD5291_ID},
34 {.name = "ad5292", .devid = AD5292_ID},
35 {.name = "ad5293", .devid = AD5293_ID},
36 {.name = "ad7376", .devid = AD7376_ID},
37 {.name = "ad8400", .devid = AD8400_ID},
38 {.name = "ad8402", .devid = AD8402_ID},
39 {.name = "ad8403", .devid = AD8403_ID},
40 {.name = "adn2850", .devid = ADN2850_ID},
41 {}
42};
43
44/* ------------------------------------------------------------------------- */
45
46/* SPI bus functions */
47static int write8(void *client, u8 val)
48{
49 u8 data = val;
50 return spi_write(client, &data, 1);
51}
52
53static int write16(void *client, u8 reg, u8 val)
54{
55 u8 data[2] = {reg, val};
56 return spi_write(client, data, 1);
57}
58
59static int write24(void *client, u8 reg, u16 val)
60{
61 u8 data[3] = {reg, val >> 8, val};
62 return spi_write(client, data, 1);
63}
64
65static int read8(void *client)
66{
67 int ret;
68 u8 data;
69 ret = spi_read(client, &data, 1);
70 if (ret < 0)
71 return ret;
72
73 return data;
74}
75
76static int read16(void *client, u8 reg)
77{
78 int ret;
79 u8 buf_rx[2];
80
81 write16(client, reg, 0);
82 ret = spi_read(client, buf_rx, 2);
83 if (ret < 0)
84 return ret;
85
86 return (buf_rx[0] << 8) | buf_rx[1];
87}
88
89static int read24(void *client, u8 reg)
90{
91 int ret;
92 u8 buf_rx[3];
93
94 write24(client, reg, 0);
95 ret = spi_read(client, buf_rx, 3);
96 if (ret < 0)
97 return ret;
98
99 return (buf_rx[1] << 8) | buf_rx[2];
100}
101
102static const struct ad_dpot_bus_ops bops = {
103 .read_d8 = read8,
104 .read_r8d8 = read16,
105 .read_r8d16 = read24,
106 .write_d8 = write8,
107 .write_r8d8 = write16,
108 .write_r8d16 = write24,
109};
110
111static const struct ad_dpot_id *dpot_match_id(const struct ad_dpot_id *id,
112 char *name)
113{
114 while (id->name && id->name[0]) {
115 if (strcmp(name, id->name) == 0)
116 return id;
117 id++;
118 }
119 return NULL;
120}
121
122static int __devinit ad_dpot_spi_probe(struct spi_device *spi)
123{
124 char *name = spi->dev.platform_data;
125 const struct ad_dpot_id *dpot_id;
126
127 struct ad_dpot_bus_data bdata = {
128 .client = spi,
129 .bops = &bops,
130 };
131
132 dpot_id = dpot_match_id(ad_dpot_spi_devlist, name);
133
134 if (dpot_id == NULL) {
135 dev_err(&spi->dev, "%s not in supported device list", name);
136 return -ENODEV;
137 }
138
139 return ad_dpot_probe(&spi->dev, &bdata, dpot_id);
140}
141
142static int __devexit ad_dpot_spi_remove(struct spi_device *spi)
143{
144 return ad_dpot_remove(&spi->dev);
145}
146
147static struct spi_driver ad_dpot_spi_driver = {
148 .driver = {
149 .name = "ad_dpot",
150 .bus = &spi_bus_type,
151 .owner = THIS_MODULE,
152 },
153 .probe = ad_dpot_spi_probe,
154 .remove = __devexit_p(ad_dpot_spi_remove),
155};
156
157static int __init ad_dpot_spi_init(void)
158{
159 return spi_register_driver(&ad_dpot_spi_driver);
160}
161module_init(ad_dpot_spi_init);
162
163static void __exit ad_dpot_spi_exit(void)
164{
165 spi_unregister_driver(&ad_dpot_spi_driver);
166}
167module_exit(ad_dpot_spi_exit);
168
169MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
170MODULE_DESCRIPTION("digital potentiometer SPI bus driver");
171MODULE_LICENSE("GPL");
172MODULE_ALIAS("spi:ad_dpot");
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c
index 30a59f2bacd2..5e6fa8449e8b 100644
--- a/drivers/misc/ad525x_dpot.c
+++ b/drivers/misc/ad525x_dpot.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * ad525x_dpot: Driver for the Analog Devices AD525x digital potentiometers 2 * ad525x_dpot: Driver for the Analog Devices digital potentiometers
3 * Copyright (c) 2009 Analog Devices, Inc. 3 * Copyright (c) 2009-2010 Analog Devices, Inc.
4 * Author: Michael Hennerich <hennerich@blackfin.uclinux.org> 4 * Author: Michael Hennerich <hennerich@blackfin.uclinux.org>
5 * 5 *
6 * DEVID #Wipers #Positions Resistor Options (kOhm) 6 * DEVID #Wipers #Positions Resistor Options (kOhm)
@@ -11,6 +11,47 @@
11 * AD5255 3 512 25, 250 11 * AD5255 3 512 25, 250
12 * AD5253 4 64 1, 10, 50, 100 12 * AD5253 4 64 1, 10, 50, 100
13 * AD5254 4 256 1, 10, 50, 100 13 * AD5254 4 256 1, 10, 50, 100
14 * AD5160 1 256 5, 10, 50, 100
15 * AD5161 1 256 5, 10, 50, 100
16 * AD5162 2 256 2.5, 10, 50, 100
17 * AD5165 1 256 100
18 * AD5200 1 256 10, 50
19 * AD5201 1 33 10, 50
20 * AD5203 4 64 10, 100
21 * AD5204 4 256 10, 50, 100
22 * AD5206 6 256 10, 50, 100
23 * AD5207 2 256 10, 50, 100
24 * AD5231 1 1024 10, 50, 100
25 * AD5232 2 256 10, 50, 100
26 * AD5233 4 64 10, 50, 100
27 * AD5235 2 1024 25, 250
28 * AD5260 1 256 20, 50, 200
29 * AD5262 2 256 20, 50, 200
30 * AD5263 4 256 20, 50, 200
31 * AD5290 1 256 10, 50, 100
32 * AD5291 1 256 20
33 * AD5292 1 1024 20
34 * AD5293 1 1024 20
35 * AD7376 1 128 10, 50, 100, 1M
36 * AD8400 1 256 1, 10, 50, 100
37 * AD8402 2 256 1, 10, 50, 100
38 * AD8403 4 256 1, 10, 50, 100
39 * ADN2850 3 512 25, 250
40 * AD5241 1 256 10, 100, 1M
41 * AD5246 1 128 5, 10, 50, 100
42 * AD5247 1 128 5, 10, 50, 100
43 * AD5245 1 256 5, 10, 50, 100
44 * AD5243 2 256 2.5, 10, 50, 100
45 * AD5248 2 256 2.5, 10, 50, 100
46 * AD5242 2 256 20, 50, 200
47 * AD5280 1 256 20, 50, 200
48 * AD5282 2 256 20, 50, 200
49 * ADN2860 3 512 25, 250
50 * AD5273 1 64 1, 10, 50, 100 (OTP)
51 * AD5171 1 64 5, 10, 50, 100 (OTP)
52 * AD5170 1 256 2.5, 10, 50, 100 (OTP)
53 * AD5172 2 256 2.5, 10, 50, 100 (OTP)
54 * AD5173 2 256 2.5, 10, 50, 100 (OTP)
14 * 55 *
15 * See Documentation/misc-devices/ad525x_dpot.txt for more info. 56 * See Documentation/misc-devices/ad525x_dpot.txt for more info.
16 * 57 *
@@ -28,77 +69,283 @@
28#include <linux/device.h> 69#include <linux/device.h>
29#include <linux/kernel.h> 70#include <linux/kernel.h>
30#include <linux/init.h> 71#include <linux/init.h>
31#include <linux/slab.h>
32#include <linux/i2c.h>
33#include <linux/delay.h> 72#include <linux/delay.h>
73#include <linux/slab.h>
34 74
35#define DRIVER_NAME "ad525x_dpot" 75#define DRIVER_VERSION "0.2"
36#define DRIVER_VERSION "0.1"
37
38enum dpot_devid {
39 AD5258_ID,
40 AD5259_ID,
41 AD5251_ID,
42 AD5252_ID,
43 AD5253_ID,
44 AD5254_ID,
45 AD5255_ID,
46};
47 76
48#define AD5258_MAX_POSITION 64 77#include "ad525x_dpot.h"
49#define AD5259_MAX_POSITION 256
50#define AD5251_MAX_POSITION 64
51#define AD5252_MAX_POSITION 256
52#define AD5253_MAX_POSITION 64
53#define AD5254_MAX_POSITION 256
54#define AD5255_MAX_POSITION 512
55
56#define AD525X_RDAC0 0
57#define AD525X_RDAC1 1
58#define AD525X_RDAC2 2
59#define AD525X_RDAC3 3
60
61#define AD525X_REG_TOL 0x18
62#define AD525X_TOL_RDAC0 (AD525X_REG_TOL | AD525X_RDAC0)
63#define AD525X_TOL_RDAC1 (AD525X_REG_TOL | AD525X_RDAC1)
64#define AD525X_TOL_RDAC2 (AD525X_REG_TOL | AD525X_RDAC2)
65#define AD525X_TOL_RDAC3 (AD525X_REG_TOL | AD525X_RDAC3)
66
67/* RDAC-to-EEPROM Interface Commands */
68#define AD525X_I2C_RDAC (0x00 << 5)
69#define AD525X_I2C_EEPROM (0x01 << 5)
70#define AD525X_I2C_CMD (0x80)
71
72#define AD525X_DEC_ALL_6DB (AD525X_I2C_CMD | (0x4 << 3))
73#define AD525X_INC_ALL_6DB (AD525X_I2C_CMD | (0x9 << 3))
74#define AD525X_DEC_ALL (AD525X_I2C_CMD | (0x6 << 3))
75#define AD525X_INC_ALL (AD525X_I2C_CMD | (0xB << 3))
76
77static s32 ad525x_read(struct i2c_client *client, u8 reg);
78static s32 ad525x_write(struct i2c_client *client, u8 reg, u8 value);
79 78
80/* 79/*
81 * Client data (each client gets its own) 80 * Client data (each client gets its own)
82 */ 81 */
83 82
84struct dpot_data { 83struct dpot_data {
84 struct ad_dpot_bus_data bdata;
85 struct mutex update_lock; 85 struct mutex update_lock;
86 unsigned rdac_mask; 86 unsigned rdac_mask;
87 unsigned max_pos; 87 unsigned max_pos;
88 unsigned devid; 88 unsigned long devid;
89 unsigned uid;
90 unsigned feat;
91 unsigned wipers;
92 u16 rdac_cache[MAX_RDACS];
93 DECLARE_BITMAP(otp_en_mask, MAX_RDACS);
89}; 94};
90 95
96static inline int dpot_read_d8(struct dpot_data *dpot)
97{
98 return dpot->bdata.bops->read_d8(dpot->bdata.client);
99}
100
101static inline int dpot_read_r8d8(struct dpot_data *dpot, u8 reg)
102{
103 return dpot->bdata.bops->read_r8d8(dpot->bdata.client, reg);
104}
105
106static inline int dpot_read_r8d16(struct dpot_data *dpot, u8 reg)
107{
108 return dpot->bdata.bops->read_r8d16(dpot->bdata.client, reg);
109}
110
111static inline int dpot_write_d8(struct dpot_data *dpot, u8 val)
112{
113 return dpot->bdata.bops->write_d8(dpot->bdata.client, val);
114}
115
116static inline int dpot_write_r8d8(struct dpot_data *dpot, u8 reg, u16 val)
117{
118 return dpot->bdata.bops->write_r8d8(dpot->bdata.client, reg, val);
119}
120
121static inline int dpot_write_r8d16(struct dpot_data *dpot, u8 reg, u16 val)
122{
123 return dpot->bdata.bops->write_r8d16(dpot->bdata.client, reg, val);
124}
125
126static s32 dpot_read_spi(struct dpot_data *dpot, u8 reg)
127{
128 unsigned ctrl = 0;
129
130 if (!(reg & (DPOT_ADDR_EEPROM | DPOT_ADDR_CMD))) {
131
132 if (dpot->feat & F_RDACS_WONLY)
133 return dpot->rdac_cache[reg & DPOT_RDAC_MASK];
134
135 if (dpot->uid == DPOT_UID(AD5291_ID) ||
136 dpot->uid == DPOT_UID(AD5292_ID) ||
137 dpot->uid == DPOT_UID(AD5293_ID))
138 return dpot_read_r8d8(dpot,
139 DPOT_AD5291_READ_RDAC << 2);
140
141 ctrl = DPOT_SPI_READ_RDAC;
142 } else if (reg & DPOT_ADDR_EEPROM) {
143 ctrl = DPOT_SPI_READ_EEPROM;
144 }
145
146 if (dpot->feat & F_SPI_16BIT)
147 return dpot_read_r8d8(dpot, ctrl);
148 else if (dpot->feat & F_SPI_24BIT)
149 return dpot_read_r8d16(dpot, ctrl);
150
151 return -EFAULT;
152}
153
154static s32 dpot_read_i2c(struct dpot_data *dpot, u8 reg)
155{
156 unsigned ctrl = 0;
157 switch (dpot->uid) {
158 case DPOT_UID(AD5246_ID):
159 case DPOT_UID(AD5247_ID):
160 return dpot_read_d8(dpot);
161 case DPOT_UID(AD5245_ID):
162 case DPOT_UID(AD5241_ID):
163 case DPOT_UID(AD5242_ID):
164 case DPOT_UID(AD5243_ID):
165 case DPOT_UID(AD5248_ID):
166 case DPOT_UID(AD5280_ID):
167 case DPOT_UID(AD5282_ID):
168 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
169 0 : DPOT_AD5291_RDAC_AB;
170 return dpot_read_r8d8(dpot, ctrl);
171 case DPOT_UID(AD5170_ID):
172 case DPOT_UID(AD5171_ID):
173 case DPOT_UID(AD5273_ID):
174 return dpot_read_d8(dpot);
175 case DPOT_UID(AD5172_ID):
176 case DPOT_UID(AD5173_ID):
177 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
178 0 : DPOT_AD5272_3_A0;
179 return dpot_read_r8d8(dpot, ctrl);
180 default:
181 if ((reg & DPOT_REG_TOL) || (dpot->max_pos > 256))
182 return dpot_read_r8d16(dpot, (reg & 0xF8) |
183 ((reg & 0x7) << 1));
184 else
185 return dpot_read_r8d8(dpot, reg);
186 }
187}
188
189static s32 dpot_read(struct dpot_data *dpot, u8 reg)
190{
191 if (dpot->feat & F_SPI)
192 return dpot_read_spi(dpot, reg);
193 else
194 return dpot_read_i2c(dpot, reg);
195}
196
197static s32 dpot_write_spi(struct dpot_data *dpot, u8 reg, u16 value)
198{
199 unsigned val = 0;
200
201 if (!(reg & (DPOT_ADDR_EEPROM | DPOT_ADDR_CMD))) {
202 if (dpot->feat & F_RDACS_WONLY)
203 dpot->rdac_cache[reg & DPOT_RDAC_MASK] = value;
204
205 if (dpot->feat & F_AD_APPDATA) {
206 if (dpot->feat & F_SPI_8BIT) {
207 val = ((reg & DPOT_RDAC_MASK) <<
208 DPOT_MAX_POS(dpot->devid)) |
209 value;
210 return dpot_write_d8(dpot, val);
211 } else if (dpot->feat & F_SPI_16BIT) {
212 val = ((reg & DPOT_RDAC_MASK) <<
213 DPOT_MAX_POS(dpot->devid)) |
214 value;
215 return dpot_write_r8d8(dpot, val >> 8,
216 val & 0xFF);
217 } else
218 BUG();
219 } else {
220 if (dpot->uid == DPOT_UID(AD5291_ID) ||
221 dpot->uid == DPOT_UID(AD5292_ID) ||
222 dpot->uid == DPOT_UID(AD5293_ID))
223 return dpot_write_r8d8(dpot,
224 (DPOT_AD5291_RDAC << 2) |
225 (value >> 8), value & 0xFF);
226
227 val = DPOT_SPI_RDAC | (reg & DPOT_RDAC_MASK);
228 }
229 } else if (reg & DPOT_ADDR_EEPROM) {
230 val = DPOT_SPI_EEPROM | (reg & DPOT_RDAC_MASK);
231 } else if (reg & DPOT_ADDR_CMD) {
232 switch (reg) {
233 case DPOT_DEC_ALL_6DB:
234 val = DPOT_SPI_DEC_ALL_6DB;
235 break;
236 case DPOT_INC_ALL_6DB:
237 val = DPOT_SPI_INC_ALL_6DB;
238 break;
239 case DPOT_DEC_ALL:
240 val = DPOT_SPI_DEC_ALL;
241 break;
242 case DPOT_INC_ALL:
243 val = DPOT_SPI_INC_ALL;
244 break;
245 }
246 } else
247 BUG();
248
249 if (dpot->feat & F_SPI_16BIT)
250 return dpot_write_r8d8(dpot, val, value);
251 else if (dpot->feat & F_SPI_24BIT)
252 return dpot_write_r8d16(dpot, val, value);
253
254 return -EFAULT;
255}
256
257static s32 dpot_write_i2c(struct dpot_data *dpot, u8 reg, u16 value)
258{
259 /* Only write the instruction byte for certain commands */
260 unsigned tmp = 0, ctrl = 0;
261
262 switch (dpot->uid) {
263 case DPOT_UID(AD5246_ID):
264 case DPOT_UID(AD5247_ID):
265 return dpot_write_d8(dpot, value);
266 break;
267
268 case DPOT_UID(AD5245_ID):
269 case DPOT_UID(AD5241_ID):
270 case DPOT_UID(AD5242_ID):
271 case DPOT_UID(AD5243_ID):
272 case DPOT_UID(AD5248_ID):
273 case DPOT_UID(AD5280_ID):
274 case DPOT_UID(AD5282_ID):
275 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
276 0 : DPOT_AD5291_RDAC_AB;
277 return dpot_write_r8d8(dpot, ctrl, value);
278 break;
279 case DPOT_UID(AD5171_ID):
280 case DPOT_UID(AD5273_ID):
281 if (reg & DPOT_ADDR_OTP) {
282 tmp = dpot_read_d8(dpot);
283 if (tmp >> 6) /* Ready to Program? */
284 return -EFAULT;
285 ctrl = DPOT_AD5273_FUSE;
286 }
287 return dpot_write_r8d8(dpot, ctrl, value);
288 break;
289 case DPOT_UID(AD5172_ID):
290 case DPOT_UID(AD5173_ID):
291 ctrl = ((reg & DPOT_RDAC_MASK) == DPOT_RDAC0) ?
292 0 : DPOT_AD5272_3_A0;
293 if (reg & DPOT_ADDR_OTP) {
294 tmp = dpot_read_r8d16(dpot, ctrl);
295 if (tmp >> 14) /* Ready to Program? */
296 return -EFAULT;
297 ctrl |= DPOT_AD5270_2_3_FUSE;
298 }
299 return dpot_write_r8d8(dpot, ctrl, value);
300 break;
301 case DPOT_UID(AD5170_ID):
302 if (reg & DPOT_ADDR_OTP) {
303 tmp = dpot_read_r8d16(dpot, tmp);
304 if (tmp >> 14) /* Ready to Program? */
305 return -EFAULT;
306 ctrl = DPOT_AD5270_2_3_FUSE;
307 }
308 return dpot_write_r8d8(dpot, ctrl, value);
309 break;
310 default:
311 if (reg & DPOT_ADDR_CMD)
312 return dpot_write_d8(dpot, reg);
313
314 if (dpot->max_pos > 256)
315 return dpot_write_r8d16(dpot, (reg & 0xF8) |
316 ((reg & 0x7) << 1), value);
317 else
318 /* All other registers require instruction + data bytes */
319 return dpot_write_r8d8(dpot, reg, value);
320 }
321}
322
323
324static s32 dpot_write(struct dpot_data *dpot, u8 reg, u16 value)
325{
326 if (dpot->feat & F_SPI)
327 return dpot_write_spi(dpot, reg, value);
328 else
329 return dpot_write_i2c(dpot, reg, value);
330}
331
91/* sysfs functions */ 332/* sysfs functions */
92 333
93static ssize_t sysfs_show_reg(struct device *dev, 334static ssize_t sysfs_show_reg(struct device *dev,
94 struct device_attribute *attr, char *buf, u32 reg) 335 struct device_attribute *attr,
336 char *buf, u32 reg)
95{ 337{
96 struct i2c_client *client = to_i2c_client(dev); 338 struct dpot_data *data = dev_get_drvdata(dev);
97 struct dpot_data *data = i2c_get_clientdata(client);
98 s32 value; 339 s32 value;
99 340
341 if (reg & DPOT_ADDR_OTP_EN)
342 return sprintf(buf, "%s\n",
343 test_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask) ?
344 "enabled" : "disabled");
345
346
100 mutex_lock(&data->update_lock); 347 mutex_lock(&data->update_lock);
101 value = ad525x_read(client, reg); 348 value = dpot_read(data, reg);
102 mutex_unlock(&data->update_lock); 349 mutex_unlock(&data->update_lock);
103 350
104 if (value < 0) 351 if (value < 0)
@@ -111,7 +358,7 @@ static ssize_t sysfs_show_reg(struct device *dev,
111 * datasheet (Rev. A) for more details. 358 * datasheet (Rev. A) for more details.
112 */ 359 */
113 360
114 if (reg & AD525X_REG_TOL) 361 if (reg & DPOT_REG_TOL)
115 return sprintf(buf, "0x%04x\n", value & 0xFFFF); 362 return sprintf(buf, "0x%04x\n", value & 0xFFFF);
116 else 363 else
117 return sprintf(buf, "%u\n", value & data->rdac_mask); 364 return sprintf(buf, "%u\n", value & data->rdac_mask);
@@ -121,11 +368,23 @@ static ssize_t sysfs_set_reg(struct device *dev,
121 struct device_attribute *attr, 368 struct device_attribute *attr,
122 const char *buf, size_t count, u32 reg) 369 const char *buf, size_t count, u32 reg)
123{ 370{
124 struct i2c_client *client = to_i2c_client(dev); 371 struct dpot_data *data = dev_get_drvdata(dev);
125 struct dpot_data *data = i2c_get_clientdata(client);
126 unsigned long value; 372 unsigned long value;
127 int err; 373 int err;
128 374
375 if (reg & DPOT_ADDR_OTP_EN) {
376 if (!strncmp(buf, "enabled", sizeof("enabled")))
377 set_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask);
378 else
379 clear_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask);
380
381 return count;
382 }
383
384 if ((reg & DPOT_ADDR_OTP) &&
385 !test_bit(DPOT_RDAC_MASK & reg, data->otp_en_mask))
386 return -EPERM;
387
129 err = strict_strtoul(buf, 10, &value); 388 err = strict_strtoul(buf, 10, &value);
130 if (err) 389 if (err)
131 return err; 390 return err;
@@ -134,9 +393,11 @@ static ssize_t sysfs_set_reg(struct device *dev,
134 value = data->rdac_mask; 393 value = data->rdac_mask;
135 394
136 mutex_lock(&data->update_lock); 395 mutex_lock(&data->update_lock);
137 ad525x_write(client, reg, value); 396 dpot_write(data, reg, value);
138 if (reg & AD525X_I2C_EEPROM) 397 if (reg & DPOT_ADDR_EEPROM)
139 msleep(26); /* Sleep while the EEPROM updates */ 398 msleep(26); /* Sleep while the EEPROM updates */
399 else if (reg & DPOT_ADDR_OTP)
400 msleep(400); /* Sleep while the OTP updates */
140 mutex_unlock(&data->update_lock); 401 mutex_unlock(&data->update_lock);
141 402
142 return count; 403 return count;
@@ -146,11 +407,10 @@ static ssize_t sysfs_do_cmd(struct device *dev,
146 struct device_attribute *attr, 407 struct device_attribute *attr,
147 const char *buf, size_t count, u32 reg) 408 const char *buf, size_t count, u32 reg)
148{ 409{
149 struct i2c_client *client = to_i2c_client(dev); 410 struct dpot_data *data = dev_get_drvdata(dev);
150 struct dpot_data *data = i2c_get_clientdata(client);
151 411
152 mutex_lock(&data->update_lock); 412 mutex_lock(&data->update_lock);
153 ad525x_write(client, reg, 0); 413 dpot_write(data, reg, 0);
154 mutex_unlock(&data->update_lock); 414 mutex_unlock(&data->update_lock);
155 415
156 return count; 416 return count;
@@ -158,244 +418,131 @@ static ssize_t sysfs_do_cmd(struct device *dev,
158 418
159/* ------------------------------------------------------------------------- */ 419/* ------------------------------------------------------------------------- */
160 420
161static ssize_t show_rdac0(struct device *dev, 421#define DPOT_DEVICE_SHOW(_name, _reg) static ssize_t \
162 struct device_attribute *attr, char *buf) 422show_##_name(struct device *dev, \
163{ 423 struct device_attribute *attr, char *buf) \
164 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC0); 424{ \
165} 425 return sysfs_show_reg(dev, attr, buf, _reg); \
166 426}
167static ssize_t set_rdac0(struct device *dev, 427
168 struct device_attribute *attr, 428#define DPOT_DEVICE_SET(_name, _reg) static ssize_t \
169 const char *buf, size_t count) 429set_##_name(struct device *dev, \
170{ 430 struct device_attribute *attr, \
171 return sysfs_set_reg(dev, attr, buf, count, 431 const char *buf, size_t count) \
172 AD525X_I2C_RDAC | AD525X_RDAC0); 432{ \
173} 433 return sysfs_set_reg(dev, attr, buf, count, _reg); \
174 434}
175static DEVICE_ATTR(rdac0, S_IWUSR | S_IRUGO, show_rdac0, set_rdac0); 435
176 436#define DPOT_DEVICE_SHOW_SET(name, reg) \
177static ssize_t show_eeprom0(struct device *dev, 437DPOT_DEVICE_SHOW(name, reg) \
178 struct device_attribute *attr, char *buf) 438DPOT_DEVICE_SET(name, reg) \
179{ 439static DEVICE_ATTR(name, S_IWUSR | S_IRUGO, show_##name, set_##name);
180 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC0); 440
181} 441#define DPOT_DEVICE_SHOW_ONLY(name, reg) \
182 442DPOT_DEVICE_SHOW(name, reg) \
183static ssize_t set_eeprom0(struct device *dev, 443static DEVICE_ATTR(name, S_IWUSR | S_IRUGO, show_##name, NULL);
184 struct device_attribute *attr, 444
185 const char *buf, size_t count) 445DPOT_DEVICE_SHOW_SET(rdac0, DPOT_ADDR_RDAC | DPOT_RDAC0);
186{ 446DPOT_DEVICE_SHOW_SET(eeprom0, DPOT_ADDR_EEPROM | DPOT_RDAC0);
187 return sysfs_set_reg(dev, attr, buf, count, 447DPOT_DEVICE_SHOW_ONLY(tolerance0, DPOT_ADDR_EEPROM | DPOT_TOL_RDAC0);
188 AD525X_I2C_EEPROM | AD525X_RDAC0); 448DPOT_DEVICE_SHOW_SET(otp0, DPOT_ADDR_OTP | DPOT_RDAC0);
189} 449DPOT_DEVICE_SHOW_SET(otp0en, DPOT_ADDR_OTP_EN | DPOT_RDAC0);
190 450
191static DEVICE_ATTR(eeprom0, S_IWUSR | S_IRUGO, show_eeprom0, set_eeprom0); 451DPOT_DEVICE_SHOW_SET(rdac1, DPOT_ADDR_RDAC | DPOT_RDAC1);
192 452DPOT_DEVICE_SHOW_SET(eeprom1, DPOT_ADDR_EEPROM | DPOT_RDAC1);
193static ssize_t show_tolerance0(struct device *dev, 453DPOT_DEVICE_SHOW_ONLY(tolerance1, DPOT_ADDR_EEPROM | DPOT_TOL_RDAC1);
194 struct device_attribute *attr, char *buf) 454DPOT_DEVICE_SHOW_SET(otp1, DPOT_ADDR_OTP | DPOT_RDAC1);
195{ 455DPOT_DEVICE_SHOW_SET(otp1en, DPOT_ADDR_OTP_EN | DPOT_RDAC1);
196 return sysfs_show_reg(dev, attr, buf, 456
197 AD525X_I2C_EEPROM | AD525X_TOL_RDAC0); 457DPOT_DEVICE_SHOW_SET(rdac2, DPOT_ADDR_RDAC | DPOT_RDAC2);
198} 458DPOT_DEVICE_SHOW_SET(eeprom2, DPOT_ADDR_EEPROM | DPOT_RDAC2);
199 459DPOT_DEVICE_SHOW_ONLY(tolerance2, DPOT_ADDR_EEPROM | DPOT_TOL_RDAC2);
200static DEVICE_ATTR(tolerance0, S_IRUGO, show_tolerance0, NULL); 460DPOT_DEVICE_SHOW_SET(otp2, DPOT_ADDR_OTP | DPOT_RDAC2);
201 461DPOT_DEVICE_SHOW_SET(otp2en, DPOT_ADDR_OTP_EN | DPOT_RDAC2);
202/* ------------------------------------------------------------------------- */ 462
203 463DPOT_DEVICE_SHOW_SET(rdac3, DPOT_ADDR_RDAC | DPOT_RDAC3);
204static ssize_t show_rdac1(struct device *dev, 464DPOT_DEVICE_SHOW_SET(eeprom3, DPOT_ADDR_EEPROM | DPOT_RDAC3);
205 struct device_attribute *attr, char *buf) 465DPOT_DEVICE_SHOW_ONLY(tolerance3, DPOT_ADDR_EEPROM | DPOT_TOL_RDAC3);
206{ 466DPOT_DEVICE_SHOW_SET(otp3, DPOT_ADDR_OTP | DPOT_RDAC3);
207 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC1); 467DPOT_DEVICE_SHOW_SET(otp3en, DPOT_ADDR_OTP_EN | DPOT_RDAC3);
208} 468
209 469DPOT_DEVICE_SHOW_SET(rdac4, DPOT_ADDR_RDAC | DPOT_RDAC4);
210static ssize_t set_rdac1(struct device *dev, 470DPOT_DEVICE_SHOW_SET(eeprom4, DPOT_ADDR_EEPROM | DPOT_RDAC4);
211 struct device_attribute *attr, 471DPOT_DEVICE_SHOW_ONLY(tolerance4, DPOT_ADDR_EEPROM | DPOT_TOL_RDAC4);
212 const char *buf, size_t count) 472DPOT_DEVICE_SHOW_SET(otp4, DPOT_ADDR_OTP | DPOT_RDAC4);
213{ 473DPOT_DEVICE_SHOW_SET(otp4en, DPOT_ADDR_OTP_EN | DPOT_RDAC4);
214 return sysfs_set_reg(dev, attr, buf, count, 474
215 AD525X_I2C_RDAC | AD525X_RDAC1); 475DPOT_DEVICE_SHOW_SET(rdac5, DPOT_ADDR_RDAC | DPOT_RDAC5);
216} 476DPOT_DEVICE_SHOW_SET(eeprom5, DPOT_ADDR_EEPROM | DPOT_RDAC5);
217 477DPOT_DEVICE_SHOW_ONLY(tolerance5, DPOT_ADDR_EEPROM | DPOT_TOL_RDAC5);
218static DEVICE_ATTR(rdac1, S_IWUSR | S_IRUGO, show_rdac1, set_rdac1); 478DPOT_DEVICE_SHOW_SET(otp5, DPOT_ADDR_OTP | DPOT_RDAC5);
219 479DPOT_DEVICE_SHOW_SET(otp5en, DPOT_ADDR_OTP_EN | DPOT_RDAC5);
220static ssize_t show_eeprom1(struct device *dev, 480
221 struct device_attribute *attr, char *buf) 481static const struct attribute *dpot_attrib_wipers[] = {
222{ 482 &dev_attr_rdac0.attr,
223 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC1); 483 &dev_attr_rdac1.attr,
224} 484 &dev_attr_rdac2.attr,
225 485 &dev_attr_rdac3.attr,
226static ssize_t set_eeprom1(struct device *dev, 486 &dev_attr_rdac4.attr,
227 struct device_attribute *attr, 487 &dev_attr_rdac5.attr,
228 const char *buf, size_t count) 488 NULL
229{ 489};
230 return sysfs_set_reg(dev, attr, buf, count,
231 AD525X_I2C_EEPROM | AD525X_RDAC1);
232}
233
234static DEVICE_ATTR(eeprom1, S_IWUSR | S_IRUGO, show_eeprom1, set_eeprom1);
235
236static ssize_t show_tolerance1(struct device *dev,
237 struct device_attribute *attr, char *buf)
238{
239 return sysfs_show_reg(dev, attr, buf,
240 AD525X_I2C_EEPROM | AD525X_TOL_RDAC1);
241}
242
243static DEVICE_ATTR(tolerance1, S_IRUGO, show_tolerance1, NULL);
244
245/* ------------------------------------------------------------------------- */
246
247static ssize_t show_rdac2(struct device *dev,
248 struct device_attribute *attr, char *buf)
249{
250 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC2);
251}
252
253static ssize_t set_rdac2(struct device *dev,
254 struct device_attribute *attr,
255 const char *buf, size_t count)
256{
257 return sysfs_set_reg(dev, attr, buf, count,
258 AD525X_I2C_RDAC | AD525X_RDAC2);
259}
260
261static DEVICE_ATTR(rdac2, S_IWUSR | S_IRUGO, show_rdac2, set_rdac2);
262
263static ssize_t show_eeprom2(struct device *dev,
264 struct device_attribute *attr, char *buf)
265{
266 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC2);
267}
268
269static ssize_t set_eeprom2(struct device *dev,
270 struct device_attribute *attr,
271 const char *buf, size_t count)
272{
273 return sysfs_set_reg(dev, attr, buf, count,
274 AD525X_I2C_EEPROM | AD525X_RDAC2);
275}
276
277static DEVICE_ATTR(eeprom2, S_IWUSR | S_IRUGO, show_eeprom2, set_eeprom2);
278
279static ssize_t show_tolerance2(struct device *dev,
280 struct device_attribute *attr, char *buf)
281{
282 return sysfs_show_reg(dev, attr, buf,
283 AD525X_I2C_EEPROM | AD525X_TOL_RDAC2);
284}
285
286static DEVICE_ATTR(tolerance2, S_IRUGO, show_tolerance2, NULL);
287
288/* ------------------------------------------------------------------------- */
289
290static ssize_t show_rdac3(struct device *dev,
291 struct device_attribute *attr, char *buf)
292{
293 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_RDAC | AD525X_RDAC3);
294}
295
296static ssize_t set_rdac3(struct device *dev,
297 struct device_attribute *attr,
298 const char *buf, size_t count)
299{
300 return sysfs_set_reg(dev, attr, buf, count,
301 AD525X_I2C_RDAC | AD525X_RDAC3);
302}
303
304static DEVICE_ATTR(rdac3, S_IWUSR | S_IRUGO, show_rdac3, set_rdac3);
305
306static ssize_t show_eeprom3(struct device *dev,
307 struct device_attribute *attr, char *buf)
308{
309 return sysfs_show_reg(dev, attr, buf, AD525X_I2C_EEPROM | AD525X_RDAC3);
310}
311
312static ssize_t set_eeprom3(struct device *dev,
313 struct device_attribute *attr,
314 const char *buf, size_t count)
315{
316 return sysfs_set_reg(dev, attr, buf, count,
317 AD525X_I2C_EEPROM | AD525X_RDAC3);
318}
319 490
320static DEVICE_ATTR(eeprom3, S_IWUSR | S_IRUGO, show_eeprom3, set_eeprom3); 491static const struct attribute *dpot_attrib_eeprom[] = {
492 &dev_attr_eeprom0.attr,
493 &dev_attr_eeprom1.attr,
494 &dev_attr_eeprom2.attr,
495 &dev_attr_eeprom3.attr,
496 &dev_attr_eeprom4.attr,
497 &dev_attr_eeprom5.attr,
498 NULL
499};
321 500
322static ssize_t show_tolerance3(struct device *dev, 501static const struct attribute *dpot_attrib_otp[] = {
323 struct device_attribute *attr, char *buf) 502 &dev_attr_otp0.attr,
324{ 503 &dev_attr_otp1.attr,
325 return sysfs_show_reg(dev, attr, buf, 504 &dev_attr_otp2.attr,
326 AD525X_I2C_EEPROM | AD525X_TOL_RDAC3); 505 &dev_attr_otp3.attr,
327} 506 &dev_attr_otp4.attr,
507 &dev_attr_otp5.attr,
508 NULL
509};
328 510
329static DEVICE_ATTR(tolerance3, S_IRUGO, show_tolerance3, NULL); 511static const struct attribute *dpot_attrib_otp_en[] = {
330 512 &dev_attr_otp0en.attr,
331static struct attribute *ad525x_attributes_wipers[4][4] = { 513 &dev_attr_otp1en.attr,
332 { 514 &dev_attr_otp2en.attr,
333 &dev_attr_rdac0.attr, 515 &dev_attr_otp3en.attr,
334 &dev_attr_eeprom0.attr, 516 &dev_attr_otp4en.attr,
335 &dev_attr_tolerance0.attr, 517 &dev_attr_otp5en.attr,
336 NULL 518 NULL
337 }, {
338 &dev_attr_rdac1.attr,
339 &dev_attr_eeprom1.attr,
340 &dev_attr_tolerance1.attr,
341 NULL
342 }, {
343 &dev_attr_rdac2.attr,
344 &dev_attr_eeprom2.attr,
345 &dev_attr_tolerance2.attr,
346 NULL
347 }, {
348 &dev_attr_rdac3.attr,
349 &dev_attr_eeprom3.attr,
350 &dev_attr_tolerance3.attr,
351 NULL
352 }
353}; 519};
354 520
355static const struct attribute_group ad525x_group_wipers[] = { 521static const struct attribute *dpot_attrib_tolerance[] = {
356 {.attrs = ad525x_attributes_wipers[AD525X_RDAC0]}, 522 &dev_attr_tolerance0.attr,
357 {.attrs = ad525x_attributes_wipers[AD525X_RDAC1]}, 523 &dev_attr_tolerance1.attr,
358 {.attrs = ad525x_attributes_wipers[AD525X_RDAC2]}, 524 &dev_attr_tolerance2.attr,
359 {.attrs = ad525x_attributes_wipers[AD525X_RDAC3]}, 525 &dev_attr_tolerance3.attr,
526 &dev_attr_tolerance4.attr,
527 &dev_attr_tolerance5.attr,
528 NULL
360}; 529};
361 530
362/* ------------------------------------------------------------------------- */ 531/* ------------------------------------------------------------------------- */
363 532
364static ssize_t set_inc_all(struct device *dev, 533#define DPOT_DEVICE_DO_CMD(_name, _cmd) static ssize_t \
365 struct device_attribute *attr, 534set_##_name(struct device *dev, \
366 const char *buf, size_t count) 535 struct device_attribute *attr, \
367{ 536 const char *buf, size_t count) \
368 return sysfs_do_cmd(dev, attr, buf, count, AD525X_INC_ALL); 537{ \
369} 538 return sysfs_do_cmd(dev, attr, buf, count, _cmd); \
539} \
540static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, NULL, set_##_name);
370 541
371static DEVICE_ATTR(inc_all, S_IWUSR, NULL, set_inc_all); 542DPOT_DEVICE_DO_CMD(inc_all, DPOT_INC_ALL);
372 543DPOT_DEVICE_DO_CMD(dec_all, DPOT_DEC_ALL);
373static ssize_t set_dec_all(struct device *dev, 544DPOT_DEVICE_DO_CMD(inc_all_6db, DPOT_INC_ALL_6DB);
374 struct device_attribute *attr, 545DPOT_DEVICE_DO_CMD(dec_all_6db, DPOT_DEC_ALL_6DB);
375 const char *buf, size_t count)
376{
377 return sysfs_do_cmd(dev, attr, buf, count, AD525X_DEC_ALL);
378}
379
380static DEVICE_ATTR(dec_all, S_IWUSR, NULL, set_dec_all);
381
382static ssize_t set_inc_all_6db(struct device *dev,
383 struct device_attribute *attr,
384 const char *buf, size_t count)
385{
386 return sysfs_do_cmd(dev, attr, buf, count, AD525X_INC_ALL_6DB);
387}
388
389static DEVICE_ATTR(inc_all_6db, S_IWUSR, NULL, set_inc_all_6db);
390
391static ssize_t set_dec_all_6db(struct device *dev,
392 struct device_attribute *attr,
393 const char *buf, size_t count)
394{
395 return sysfs_do_cmd(dev, attr, buf, count, AD525X_DEC_ALL_6DB);
396}
397
398static DEVICE_ATTR(dec_all_6db, S_IWUSR, NULL, set_dec_all_6db);
399 546
400static struct attribute *ad525x_attributes_commands[] = { 547static struct attribute *ad525x_attributes_commands[] = {
401 &dev_attr_inc_all.attr, 548 &dev_attr_inc_all.attr,
@@ -409,74 +556,56 @@ static const struct attribute_group ad525x_group_commands = {
409 .attrs = ad525x_attributes_commands, 556 .attrs = ad525x_attributes_commands,
410}; 557};
411 558
412/* ------------------------------------------------------------------------- */ 559__devinit int ad_dpot_add_files(struct device *dev,
413 560 unsigned features, unsigned rdac)
414/* i2c device functions */ 561{
562 int err = sysfs_create_file(&dev->kobj,
563 dpot_attrib_wipers[rdac]);
564 if (features & F_CMD_EEP)
565 err |= sysfs_create_file(&dev->kobj,
566 dpot_attrib_eeprom[rdac]);
567 if (features & F_CMD_TOL)
568 err |= sysfs_create_file(&dev->kobj,
569 dpot_attrib_tolerance[rdac]);
570 if (features & F_CMD_OTP) {
571 err |= sysfs_create_file(&dev->kobj,
572 dpot_attrib_otp_en[rdac]);
573 err |= sysfs_create_file(&dev->kobj,
574 dpot_attrib_otp[rdac]);
575 }
415 576
416/** 577 if (err)
417 * ad525x_read - return the value contained in the specified register 578 dev_err(dev, "failed to register sysfs hooks for RDAC%d\n",
418 * on the AD5258 device. 579 rdac);
419 * @client: value returned from i2c_new_device()
420 * @reg: the register to read
421 *
422 * If the tolerance register is specified, 2 bytes are returned.
423 * Otherwise, 1 byte is returned. A negative value indicates an error
424 * occurred while reading the register.
425 */
426static s32 ad525x_read(struct i2c_client *client, u8 reg)
427{
428 struct dpot_data *data = i2c_get_clientdata(client);
429 580
430 if ((reg & AD525X_REG_TOL) || (data->max_pos > 256)) 581 return err;
431 return i2c_smbus_read_word_data(client, (reg & 0xF8) |
432 ((reg & 0x7) << 1));
433 else
434 return i2c_smbus_read_byte_data(client, reg);
435} 582}
436 583
437/** 584inline void ad_dpot_remove_files(struct device *dev,
438 * ad525x_write - store the given value in the specified register on 585 unsigned features, unsigned rdac)
439 * the AD5258 device. 586{
440 * @client: value returned from i2c_new_device() 587 sysfs_remove_file(&dev->kobj,
441 * @reg: the register to write 588 dpot_attrib_wipers[rdac]);
442 * @value: the byte to store in the register 589 if (features & F_CMD_EEP)
443 * 590 sysfs_remove_file(&dev->kobj,
444 * For certain instructions that do not require a data byte, "NULL" 591 dpot_attrib_eeprom[rdac]);
445 * should be specified for the "value" parameter. These instructions 592 if (features & F_CMD_TOL)
446 * include NOP, RESTORE_FROM_EEPROM, and STORE_TO_EEPROM. 593 sysfs_remove_file(&dev->kobj,
447 * 594 dpot_attrib_tolerance[rdac]);
448 * A negative return value indicates an error occurred while reading 595 if (features & F_CMD_OTP) {
449 * the register. 596 sysfs_remove_file(&dev->kobj,
450 */ 597 dpot_attrib_otp_en[rdac]);
451static s32 ad525x_write(struct i2c_client *client, u8 reg, u8 value) 598 sysfs_remove_file(&dev->kobj,
452{ 599 dpot_attrib_otp[rdac]);
453 struct dpot_data *data = i2c_get_clientdata(client); 600 }
454
455 /* Only write the instruction byte for certain commands */
456 if (reg & AD525X_I2C_CMD)
457 return i2c_smbus_write_byte(client, reg);
458
459 if (data->max_pos > 256)
460 return i2c_smbus_write_word_data(client, (reg & 0xF8) |
461 ((reg & 0x7) << 1), value);
462 else
463 /* All other registers require instruction + data bytes */
464 return i2c_smbus_write_byte_data(client, reg, value);
465} 601}
466 602
467static int ad525x_probe(struct i2c_client *client, 603__devinit int ad_dpot_probe(struct device *dev,
468 const struct i2c_device_id *id) 604 struct ad_dpot_bus_data *bdata, const struct ad_dpot_id *id)
469{ 605{
470 struct device *dev = &client->dev;
471 struct dpot_data *data;
472 int err = 0;
473 606
474 dev_dbg(dev, "%s\n", __func__); 607 struct dpot_data *data;
475 608 int i, err = 0;
476 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) {
477 dev_err(dev, "missing I2C functionality for this driver\n");
478 goto exit;
479 }
480 609
481 data = kzalloc(sizeof(struct dpot_data), GFP_KERNEL); 610 data = kzalloc(sizeof(struct dpot_data), GFP_KERNEL);
482 if (!data) { 611 if (!data) {
@@ -484,183 +613,74 @@ static int ad525x_probe(struct i2c_client *client,
484 goto exit; 613 goto exit;
485 } 614 }
486 615
487 i2c_set_clientdata(client, data); 616 dev_set_drvdata(dev, data);
488 mutex_init(&data->update_lock); 617 mutex_init(&data->update_lock);
489 618
490 switch (id->driver_data) { 619 data->bdata = *bdata;
491 case AD5258_ID: 620 data->devid = id->devid;
492 data->max_pos = AD5258_MAX_POSITION; 621
493 err = sysfs_create_group(&dev->kobj, 622 data->max_pos = 1 << DPOT_MAX_POS(data->devid);
494 &ad525x_group_wipers[AD525X_RDAC0]); 623 data->rdac_mask = data->max_pos - 1;
495 break; 624 data->feat = DPOT_FEAT(data->devid);
496 case AD5259_ID: 625 data->uid = DPOT_UID(data->devid);
497 data->max_pos = AD5259_MAX_POSITION; 626 data->wipers = DPOT_WIPERS(data->devid);
498 err = sysfs_create_group(&dev->kobj, 627
499 &ad525x_group_wipers[AD525X_RDAC0]); 628 for (i = DPOT_RDAC0; i < MAX_RDACS; i++)
500 break; 629 if (data->wipers & (1 << i)) {
501 case AD5251_ID: 630 err = ad_dpot_add_files(dev, data->feat, i);
502 data->max_pos = AD5251_MAX_POSITION; 631 if (err)
503 err = sysfs_create_group(&dev->kobj, 632 goto exit_remove_files;
504 &ad525x_group_wipers[AD525X_RDAC1]); 633 /* power-up midscale */
505 err |= sysfs_create_group(&dev->kobj, 634 if (data->feat & F_RDACS_WONLY)
506 &ad525x_group_wipers[AD525X_RDAC3]); 635 data->rdac_cache[i] = data->max_pos / 2;
507 err |= sysfs_create_group(&dev->kobj, &ad525x_group_commands); 636 }
508 break; 637
509 case AD5252_ID: 638 if (data->feat & F_CMD_INC)
510 data->max_pos = AD5252_MAX_POSITION; 639 err = sysfs_create_group(&dev->kobj, &ad525x_group_commands);
511 err = sysfs_create_group(&dev->kobj,
512 &ad525x_group_wipers[AD525X_RDAC1]);
513 err |= sysfs_create_group(&dev->kobj,
514 &ad525x_group_wipers[AD525X_RDAC3]);
515 err |= sysfs_create_group(&dev->kobj, &ad525x_group_commands);
516 break;
517 case AD5253_ID:
518 data->max_pos = AD5253_MAX_POSITION;
519 err = sysfs_create_group(&dev->kobj,
520 &ad525x_group_wipers[AD525X_RDAC0]);
521 err |= sysfs_create_group(&dev->kobj,
522 &ad525x_group_wipers[AD525X_RDAC1]);
523 err |= sysfs_create_group(&dev->kobj,
524 &ad525x_group_wipers[AD525X_RDAC2]);
525 err |= sysfs_create_group(&dev->kobj,
526 &ad525x_group_wipers[AD525X_RDAC3]);
527 err |= sysfs_create_group(&dev->kobj, &ad525x_group_commands);
528 break;
529 case AD5254_ID:
530 data->max_pos = AD5254_MAX_POSITION;
531 err = sysfs_create_group(&dev->kobj,
532 &ad525x_group_wipers[AD525X_RDAC0]);
533 err |= sysfs_create_group(&dev->kobj,
534 &ad525x_group_wipers[AD525X_RDAC1]);
535 err |= sysfs_create_group(&dev->kobj,
536 &ad525x_group_wipers[AD525X_RDAC2]);
537 err |= sysfs_create_group(&dev->kobj,
538 &ad525x_group_wipers[AD525X_RDAC3]);
539 err |= sysfs_create_group(&dev->kobj, &ad525x_group_commands);
540 break;
541 case AD5255_ID:
542 data->max_pos = AD5255_MAX_POSITION;
543 err = sysfs_create_group(&dev->kobj,
544 &ad525x_group_wipers[AD525X_RDAC0]);
545 err |= sysfs_create_group(&dev->kobj,
546 &ad525x_group_wipers[AD525X_RDAC1]);
547 err |= sysfs_create_group(&dev->kobj,
548 &ad525x_group_wipers[AD525X_RDAC2]);
549 err |= sysfs_create_group(&dev->kobj, &ad525x_group_commands);
550 break;
551 default:
552 err = -ENODEV;
553 goto exit_free;
554 }
555 640
556 if (err) { 641 if (err) {
557 dev_err(dev, "failed to register sysfs hooks\n"); 642 dev_err(dev, "failed to register sysfs hooks\n");
558 goto exit_free; 643 goto exit_free;
559 } 644 }
560 645
561 data->devid = id->driver_data;
562 data->rdac_mask = data->max_pos - 1;
563
564 dev_info(dev, "%s %d-Position Digital Potentiometer registered\n", 646 dev_info(dev, "%s %d-Position Digital Potentiometer registered\n",
565 id->name, data->max_pos); 647 id->name, data->max_pos);
566 648
567 return 0; 649 return 0;
568 650
651exit_remove_files:
652 for (i = DPOT_RDAC0; i < MAX_RDACS; i++)
653 if (data->wipers & (1 << i))
654 ad_dpot_remove_files(dev, data->feat, i);
655
569exit_free: 656exit_free:
570 kfree(data); 657 kfree(data);
571 i2c_set_clientdata(client, NULL); 658 dev_set_drvdata(dev, NULL);
572exit: 659exit:
573 dev_err(dev, "failed to create client\n"); 660 dev_err(dev, "failed to create client for %s ID 0x%lX\n",
661 id->name, id->devid);
574 return err; 662 return err;
575} 663}
664EXPORT_SYMBOL(ad_dpot_probe);
576 665
577static int __devexit ad525x_remove(struct i2c_client *client) 666__devexit int ad_dpot_remove(struct device *dev)
578{ 667{
579 struct dpot_data *data = i2c_get_clientdata(client); 668 struct dpot_data *data = dev_get_drvdata(dev);
580 struct device *dev = &client->dev; 669 int i;
581 670
582 switch (data->devid) { 671 for (i = DPOT_RDAC0; i < MAX_RDACS; i++)
583 case AD5258_ID: 672 if (data->wipers & (1 << i))
584 case AD5259_ID: 673 ad_dpot_remove_files(dev, data->feat, i);
585 sysfs_remove_group(&dev->kobj,
586 &ad525x_group_wipers[AD525X_RDAC0]);
587 break;
588 case AD5251_ID:
589 case AD5252_ID:
590 sysfs_remove_group(&dev->kobj,
591 &ad525x_group_wipers[AD525X_RDAC1]);
592 sysfs_remove_group(&dev->kobj,
593 &ad525x_group_wipers[AD525X_RDAC3]);
594 sysfs_remove_group(&dev->kobj, &ad525x_group_commands);
595 break;
596 case AD5253_ID:
597 case AD5254_ID:
598 sysfs_remove_group(&dev->kobj,
599 &ad525x_group_wipers[AD525X_RDAC0]);
600 sysfs_remove_group(&dev->kobj,
601 &ad525x_group_wipers[AD525X_RDAC1]);
602 sysfs_remove_group(&dev->kobj,
603 &ad525x_group_wipers[AD525X_RDAC2]);
604 sysfs_remove_group(&dev->kobj,
605 &ad525x_group_wipers[AD525X_RDAC3]);
606 sysfs_remove_group(&dev->kobj, &ad525x_group_commands);
607 break;
608 case AD5255_ID:
609 sysfs_remove_group(&dev->kobj,
610 &ad525x_group_wipers[AD525X_RDAC0]);
611 sysfs_remove_group(&dev->kobj,
612 &ad525x_group_wipers[AD525X_RDAC1]);
613 sysfs_remove_group(&dev->kobj,
614 &ad525x_group_wipers[AD525X_RDAC2]);
615 sysfs_remove_group(&dev->kobj, &ad525x_group_commands);
616 break;
617 }
618 674
619 i2c_set_clientdata(client, NULL);
620 kfree(data); 675 kfree(data);
621 676
622 return 0; 677 return 0;
623} 678}
679EXPORT_SYMBOL(ad_dpot_remove);
624 680
625static const struct i2c_device_id ad525x_idtable[] = {
626 {"ad5258", AD5258_ID},
627 {"ad5259", AD5259_ID},
628 {"ad5251", AD5251_ID},
629 {"ad5252", AD5252_ID},
630 {"ad5253", AD5253_ID},
631 {"ad5254", AD5254_ID},
632 {"ad5255", AD5255_ID},
633 {}
634};
635
636MODULE_DEVICE_TABLE(i2c, ad525x_idtable);
637
638static struct i2c_driver ad525x_driver = {
639 .driver = {
640 .owner = THIS_MODULE,
641 .name = DRIVER_NAME,
642 },
643 .id_table = ad525x_idtable,
644 .probe = ad525x_probe,
645 .remove = __devexit_p(ad525x_remove),
646};
647
648static int __init ad525x_init(void)
649{
650 return i2c_add_driver(&ad525x_driver);
651}
652
653module_init(ad525x_init);
654
655static void __exit ad525x_exit(void)
656{
657 i2c_del_driver(&ad525x_driver);
658}
659
660module_exit(ad525x_exit);
661 681
662MODULE_AUTHOR("Chris Verges <chrisv@cyberswitching.com>, " 682MODULE_AUTHOR("Chris Verges <chrisv@cyberswitching.com>, "
663 "Michael Hennerich <hennerich@blackfin.uclinux.org>, "); 683 "Michael Hennerich <hennerich@blackfin.uclinux.org>");
664MODULE_DESCRIPTION("AD5258/9 digital potentiometer driver"); 684MODULE_DESCRIPTION("Digital potentiometer driver");
665MODULE_LICENSE("GPL"); 685MODULE_LICENSE("GPL");
666MODULE_VERSION(DRIVER_VERSION); 686MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/misc/ad525x_dpot.h b/drivers/misc/ad525x_dpot.h
new file mode 100644
index 000000000000..78b89fd2e2fd
--- /dev/null
+++ b/drivers/misc/ad525x_dpot.h
@@ -0,0 +1,202 @@
1/*
2 * Driver for the Analog Devices digital potentiometers
3 *
4 * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef _AD_DPOT_H_
10#define _AD_DPOT_H_
11
12#include <linux/types.h>
13
14#define DPOT_CONF(features, wipers, max_pos, uid) \
15 (((features) << 18) | (((wipers) & 0xFF) << 10) | \
16 ((max_pos & 0xF) << 6) | (uid & 0x3F))
17
18#define DPOT_UID(conf) (conf & 0x3F)
19#define DPOT_MAX_POS(conf) ((conf >> 6) & 0xF)
20#define DPOT_WIPERS(conf) ((conf >> 10) & 0xFF)
21#define DPOT_FEAT(conf) (conf >> 18)
22
23#define BRDAC0 (1 << 0)
24#define BRDAC1 (1 << 1)
25#define BRDAC2 (1 << 2)
26#define BRDAC3 (1 << 3)
27#define BRDAC4 (1 << 4)
28#define BRDAC5 (1 << 5)
29#define MAX_RDACS 6
30
31#define F_CMD_INC (1 << 0) /* Features INC/DEC ALL, 6dB */
32#define F_CMD_EEP (1 << 1) /* Features EEPROM */
33#define F_CMD_OTP (1 << 2) /* Features OTP */
34#define F_CMD_TOL (1 << 3) /* RDACS feature Tolerance REG */
35#define F_RDACS_RW (1 << 4) /* RDACS are Read/Write */
36#define F_RDACS_WONLY (1 << 5) /* RDACS are Write only */
37#define F_AD_APPDATA (1 << 6) /* RDAC Address append to data */
38#define F_SPI_8BIT (1 << 7) /* All SPI XFERS are 8-bit */
39#define F_SPI_16BIT (1 << 8) /* All SPI XFERS are 16-bit */
40#define F_SPI_24BIT (1 << 9) /* All SPI XFERS are 24-bit */
41
42#define F_RDACS_RW_TOL (F_RDACS_RW | F_CMD_EEP | F_CMD_TOL)
43#define F_RDACS_RW_EEP (F_RDACS_RW | F_CMD_EEP)
44#define F_SPI (F_SPI_8BIT | F_SPI_16BIT | F_SPI_24BIT)
45
46enum dpot_devid {
47 AD5258_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 6, 0), /* I2C */
48 AD5259_ID = DPOT_CONF(F_RDACS_RW_TOL, BRDAC0, 8, 1),
49 AD5251_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
50 BRDAC0 | BRDAC3, 6, 2),
51 AD5252_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
52 BRDAC0 | BRDAC3, 8, 3),
53 AD5253_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
54 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 4),
55 AD5254_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
56 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 5),
57 AD5255_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
58 BRDAC0 | BRDAC1 | BRDAC2, 9, 6),
59 AD5160_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
60 BRDAC0, 8, 7), /* SPI */
61 AD5161_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
62 BRDAC0, 8, 8),
63 AD5162_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
64 BRDAC0 | BRDAC1, 8, 9),
65 AD5165_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
66 BRDAC0, 8, 10),
67 AD5200_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
68 BRDAC0, 8, 11),
69 AD5201_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
70 BRDAC0, 5, 12),
71 AD5203_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
72 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 13),
73 AD5204_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
74 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 14),
75 AD5206_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
76 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3 | BRDAC4 | BRDAC5,
77 8, 15),
78 AD5207_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
79 BRDAC0 | BRDAC1, 8, 16),
80 AD5231_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
81 BRDAC0, 10, 17),
82 AD5232_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
83 BRDAC0 | BRDAC1, 8, 18),
84 AD5233_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_16BIT,
85 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 6, 19),
86 AD5235_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
87 BRDAC0 | BRDAC1, 10, 20),
88 AD5260_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
89 BRDAC0, 8, 21),
90 AD5262_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
91 BRDAC0 | BRDAC1, 8, 22),
92 AD5263_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
93 BRDAC0 | BRDAC1 | BRDAC2 | BRDAC3, 8, 23),
94 AD5290_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
95 BRDAC0, 8, 24),
96 AD5291_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 8, 25),
97 AD5292_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 26),
98 AD5293_ID = DPOT_CONF(F_RDACS_RW | F_SPI_16BIT, BRDAC0, 10, 27),
99 AD7376_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
100 BRDAC0, 7, 28),
101 AD8400_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_8BIT,
102 BRDAC0, 8, 29),
103 AD8402_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
104 BRDAC0 | BRDAC1, 8, 30),
105 AD8403_ID = DPOT_CONF(F_RDACS_WONLY | F_AD_APPDATA | F_SPI_16BIT,
106 BRDAC0 | BRDAC1 | BRDAC2, 8, 31),
107 ADN2850_ID = DPOT_CONF(F_RDACS_RW_EEP | F_CMD_INC | F_SPI_24BIT,
108 BRDAC0 | BRDAC1, 10, 32),
109 AD5241_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 33),
110 AD5242_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 34),
111 AD5243_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 35),
112 AD5245_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 36),
113 AD5246_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 37),
114 AD5247_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 7, 38),
115 AD5248_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 39),
116 AD5280_ID = DPOT_CONF(F_RDACS_RW, BRDAC0, 8, 40),
117 AD5282_ID = DPOT_CONF(F_RDACS_RW, BRDAC0 | BRDAC1, 8, 41),
118 ADN2860_ID = DPOT_CONF(F_RDACS_RW_TOL | F_CMD_INC,
119 BRDAC0 | BRDAC1 | BRDAC2, 9, 42),
120 AD5273_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 6, 43),
121 AD5171_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 6, 44),
122 AD5170_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0, 8, 45),
123 AD5172_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0 | BRDAC1, 8, 46),
124 AD5173_ID = DPOT_CONF(F_RDACS_RW | F_CMD_OTP, BRDAC0 | BRDAC1, 8, 47),
125};
126
127#define DPOT_RDAC0 0
128#define DPOT_RDAC1 1
129#define DPOT_RDAC2 2
130#define DPOT_RDAC3 3
131#define DPOT_RDAC4 4
132#define DPOT_RDAC5 5
133
134#define DPOT_RDAC_MASK 0x1F
135
136#define DPOT_REG_TOL 0x18
137#define DPOT_TOL_RDAC0 (DPOT_REG_TOL | DPOT_RDAC0)
138#define DPOT_TOL_RDAC1 (DPOT_REG_TOL | DPOT_RDAC1)
139#define DPOT_TOL_RDAC2 (DPOT_REG_TOL | DPOT_RDAC2)
140#define DPOT_TOL_RDAC3 (DPOT_REG_TOL | DPOT_RDAC3)
141#define DPOT_TOL_RDAC4 (DPOT_REG_TOL | DPOT_RDAC4)
142#define DPOT_TOL_RDAC5 (DPOT_REG_TOL | DPOT_RDAC5)
143
144/* RDAC-to-EEPROM Interface Commands */
145#define DPOT_ADDR_RDAC (0x0 << 5)
146#define DPOT_ADDR_EEPROM (0x1 << 5)
147#define DPOT_ADDR_OTP (0x1 << 6)
148#define DPOT_ADDR_CMD (0x1 << 7)
149#define DPOT_ADDR_OTP_EN (0x1 << 9)
150
151#define DPOT_DEC_ALL_6DB (DPOT_ADDR_CMD | (0x4 << 3))
152#define DPOT_INC_ALL_6DB (DPOT_ADDR_CMD | (0x9 << 3))
153#define DPOT_DEC_ALL (DPOT_ADDR_CMD | (0x6 << 3))
154#define DPOT_INC_ALL (DPOT_ADDR_CMD | (0xB << 3))
155
156#define DPOT_SPI_RDAC 0xB0
157#define DPOT_SPI_EEPROM 0x30
158#define DPOT_SPI_READ_RDAC 0xA0
159#define DPOT_SPI_READ_EEPROM 0x90
160#define DPOT_SPI_DEC_ALL_6DB 0x50
161#define DPOT_SPI_INC_ALL_6DB 0xD0
162#define DPOT_SPI_DEC_ALL 0x70
163#define DPOT_SPI_INC_ALL 0xF0
164
165/* AD5291/2/3 use special commands */
166#define DPOT_AD5291_RDAC 0x01
167#define DPOT_AD5291_READ_RDAC 0x02
168
169/* AD524x use special commands */
170#define DPOT_AD5291_RDAC_AB 0x80
171
172#define DPOT_AD5273_FUSE 0x80
173#define DPOT_AD5270_2_3_FUSE 0x20
174#define DPOT_AD5270_2_3_OW 0x08
175#define DPOT_AD5272_3_A0 0x08
176#define DPOT_AD5270_2FUSE 0x80
177
178struct dpot_data;
179
180struct ad_dpot_bus_ops {
181 int (*read_d8) (void *client);
182 int (*read_r8d8) (void *client, u8 reg);
183 int (*read_r8d16) (void *client, u8 reg);
184 int (*write_d8) (void *client, u8 val);
185 int (*write_r8d8) (void *client, u8 reg, u8 val);
186 int (*write_r8d16) (void *client, u8 reg, u16 val);
187};
188
189struct ad_dpot_bus_data {
190 void *client;
191 const struct ad_dpot_bus_ops *bops;
192};
193
194struct ad_dpot_id {
195 char *name;
196 unsigned long devid;
197};
198
199int ad_dpot_probe(struct device *dev, struct ad_dpot_bus_data *bdata, const struct ad_dpot_id *id);
200int ad_dpot_remove(struct device *dev);
201
202#endif
diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
index 558bf3f2c276..4afffe610f99 100644
--- a/drivers/misc/atmel-ssc.c
+++ b/drivers/misc/atmel-ssc.c
@@ -15,6 +15,7 @@
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/atmel-ssc.h> 17#include <linux/atmel-ssc.h>
18#include <linux/slab.h>
18 19
19/* Serialize access to ssc_list and user count */ 20/* Serialize access to ssc_list and user count */
20static DEFINE_SPINLOCK(user_lock); 21static DEFINE_SPINLOCK(user_lock);
diff --git a/drivers/misc/atmel_pwm.c b/drivers/misc/atmel_pwm.c
index 6aa5294dfec4..0f3fb4f03bdf 100644
--- a/drivers/misc/atmel_pwm.c
+++ b/drivers/misc/atmel_pwm.c
@@ -1,6 +1,7 @@
1#include <linux/module.h> 1#include <linux/module.h>
2#include <linux/clk.h> 2#include <linux/clk.h>
3#include <linux/err.h> 3#include <linux/err.h>
4#include <linux/slab.h>
4#include <linux/io.h> 5#include <linux/io.h>
5#include <linux/interrupt.h> 6#include <linux/interrupt.h>
6#include <linux/platform_device.h> 7#include <linux/platform_device.h>
diff --git a/drivers/misc/atmel_tclib.c b/drivers/misc/atmel_tclib.c
index 05dc8a31f280..3891124001f2 100644
--- a/drivers/misc/atmel_tclib.c
+++ b/drivers/misc/atmel_tclib.c
@@ -6,6 +6,7 @@
6#include <linux/ioport.h> 6#include <linux/ioport.h>
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/platform_device.h> 8#include <linux/platform_device.h>
9#include <linux/slab.h>
9 10
10/* Number of bytes to reserve for the iomem resource */ 11/* Number of bytes to reserve for the iomem resource */
11#define ATMEL_TC_IOMEM_SIZE 256 12#define ATMEL_TC_IOMEM_SIZE 256
diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
index b5346b4db91a..19fc7c1cb428 100644
--- a/drivers/misc/c2port/core.c
+++ b/drivers/misc/c2port/core.c
@@ -20,6 +20,7 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/idr.h> 21#include <linux/idr.h>
22#include <linux/sched.h> 22#include <linux/sched.h>
23#include <linux/slab.h>
23 24
24#include <linux/c2port.h> 25#include <linux/c2port.h>
25 26
@@ -706,7 +707,7 @@ static ssize_t __c2port_read_flash_data(struct c2port_device *dev,
706 return nread; 707 return nread;
707} 708}
708 709
709static ssize_t c2port_read_flash_data(struct kobject *kobj, 710static ssize_t c2port_read_flash_data(struct file *filp, struct kobject *kobj,
710 struct bin_attribute *attr, 711 struct bin_attribute *attr,
711 char *buffer, loff_t offset, size_t count) 712 char *buffer, loff_t offset, size_t count)
712{ 713{
@@ -823,7 +824,7 @@ static ssize_t __c2port_write_flash_data(struct c2port_device *dev,
823 return nwrite; 824 return nwrite;
824} 825}
825 826
826static ssize_t c2port_write_flash_data(struct kobject *kobj, 827static ssize_t c2port_write_flash_data(struct file *filp, struct kobject *kobj,
827 struct bin_attribute *attr, 828 struct bin_attribute *attr,
828 char *buffer, loff_t offset, size_t count) 829 char *buffer, loff_t offset, size_t count)
829{ 830{
@@ -912,8 +913,8 @@ struct c2port_device *c2port_device_register(char *name,
912 913
913 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev, 914 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
914 "c2port%d", id); 915 "c2port%d", id);
915 if (unlikely(!c2dev->dev)) { 916 if (unlikely(IS_ERR(c2dev->dev))) {
916 ret = -ENOMEM; 917 ret = PTR_ERR(c2dev->dev);
917 goto error_device_create; 918 goto error_device_create;
918 } 919 }
919 dev_set_drvdata(c2dev->dev, c2dev); 920 dev_set_drvdata(c2dev->dev, c2dev);
diff --git a/drivers/misc/cb710/core.c b/drivers/misc/cb710/core.c
index b14eab0f2ba5..efec4139c3f6 100644
--- a/drivers/misc/cb710/core.c
+++ b/drivers/misc/cb710/core.c
@@ -9,11 +9,11 @@
9 */ 9 */
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/pci.h> 12#include <linux/pci.h>
14#include <linux/spinlock.h> 13#include <linux/spinlock.h>
15#include <linux/idr.h> 14#include <linux/idr.h>
16#include <linux/cb710.h> 15#include <linux/cb710.h>
16#include <linux/gfp.h>
17 17
18static DEFINE_IDA(cb710_ida); 18static DEFINE_IDA(cb710_ida);
19static DEFINE_SPINLOCK(cb710_ida_lock); 19static DEFINE_SPINLOCK(cb710_ida_lock);
diff --git a/drivers/misc/cb710/debug.c b/drivers/misc/cb710/debug.c
index 02358d086e03..fcb3b8e30c52 100644
--- a/drivers/misc/cb710/debug.c
+++ b/drivers/misc/cb710/debug.c
@@ -10,7 +10,6 @@
10#include <linux/cb710.h> 10#include <linux/cb710.h>
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h>
14 13
15#define CB710_REG_COUNT 0x80 14#define CB710_REG_COUNT 0x80
16 15
diff --git a/drivers/misc/cs5535-mfgpt.c b/drivers/misc/cs5535-mfgpt.c
index 8110460558ff..2d44b3300104 100644
--- a/drivers/misc/cs5535-mfgpt.c
+++ b/drivers/misc/cs5535-mfgpt.c
@@ -18,6 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/cs5535.h> 20#include <linux/cs5535.h>
21#include <linux/slab.h>
21 22
22#define DRV_NAME "cs5535-mfgpt" 23#define DRV_NAME "cs5535-mfgpt"
23#define MFGPT_BAR 2 24#define MFGPT_BAR 2
@@ -365,6 +366,6 @@ static int __init cs5535_mfgpt_init(void)
365 366
366module_init(cs5535_mfgpt_init); 367module_init(cs5535_mfgpt_init);
367 368
368MODULE_AUTHOR("Andres Salomon <dilinger@collabora.co.uk>"); 369MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
369MODULE_DESCRIPTION("CS5535/CS5536 MFGPT timer driver"); 370MODULE_DESCRIPTION("CS5535/CS5536 MFGPT timer driver");
370MODULE_LICENSE("GPL"); 371MODULE_LICENSE("GPL");
diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c
index f3ee4a1abb77..a513f0aa6432 100644
--- a/drivers/misc/ds1682.c
+++ b/drivers/misc/ds1682.c
@@ -33,7 +33,6 @@
33 33
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/slab.h>
37#include <linux/i2c.h> 36#include <linux/i2c.h>
38#include <linux/string.h> 37#include <linux/string.h>
39#include <linux/list.h> 38#include <linux/list.h>
@@ -141,7 +140,8 @@ static const struct attribute_group ds1682_group = {
141/* 140/*
142 * User data attribute 141 * User data attribute
143 */ 142 */
144static ssize_t ds1682_eeprom_read(struct kobject *kobj, struct bin_attribute *attr, 143static ssize_t ds1682_eeprom_read(struct file *filp, struct kobject *kobj,
144 struct bin_attribute *attr,
145 char *buf, loff_t off, size_t count) 145 char *buf, loff_t off, size_t count)
146{ 146{
147 struct i2c_client *client = kobj_to_i2c_client(kobj); 147 struct i2c_client *client = kobj_to_i2c_client(kobj);
@@ -164,7 +164,8 @@ static ssize_t ds1682_eeprom_read(struct kobject *kobj, struct bin_attribute *at
164 return count; 164 return count;
165} 165}
166 166
167static ssize_t ds1682_eeprom_write(struct kobject *kobj, struct bin_attribute *attr, 167static ssize_t ds1682_eeprom_write(struct file *filp, struct kobject *kobj,
168 struct bin_attribute *attr,
168 char *buf, loff_t off, size_t count) 169 char *buf, loff_t off, size_t count)
169{ 170{
170 struct i2c_client *client = kobj_to_i2c_client(kobj); 171 struct i2c_client *client = kobj_to_i2c_client(kobj);
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 2cb2736d65aa..559b0b3c16c3 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -54,7 +54,7 @@
54struct at24_data { 54struct at24_data {
55 struct at24_platform_data chip; 55 struct at24_platform_data chip;
56 struct memory_accessor macc; 56 struct memory_accessor macc;
57 bool use_smbus; 57 int use_smbus;
58 58
59 /* 59 /*
60 * Lock protects against activities from other Linux tasks, 60 * Lock protects against activities from other Linux tasks,
@@ -184,11 +184,19 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
184 if (count > io_limit) 184 if (count > io_limit)
185 count = io_limit; 185 count = io_limit;
186 186
187 if (at24->use_smbus) { 187 switch (at24->use_smbus) {
188 case I2C_SMBUS_I2C_BLOCK_DATA:
188 /* Smaller eeproms can work given some SMBus extension calls */ 189 /* Smaller eeproms can work given some SMBus extension calls */
189 if (count > I2C_SMBUS_BLOCK_MAX) 190 if (count > I2C_SMBUS_BLOCK_MAX)
190 count = I2C_SMBUS_BLOCK_MAX; 191 count = I2C_SMBUS_BLOCK_MAX;
191 } else { 192 break;
193 case I2C_SMBUS_WORD_DATA:
194 count = 2;
195 break;
196 case I2C_SMBUS_BYTE_DATA:
197 count = 1;
198 break;
199 default:
192 /* 200 /*
193 * When we have a better choice than SMBus calls, use a 201 * When we have a better choice than SMBus calls, use a
194 * combined I2C message. Write address; then read up to 202 * combined I2C message. Write address; then read up to
@@ -219,10 +227,27 @@ static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
219 timeout = jiffies + msecs_to_jiffies(write_timeout); 227 timeout = jiffies + msecs_to_jiffies(write_timeout);
220 do { 228 do {
221 read_time = jiffies; 229 read_time = jiffies;
222 if (at24->use_smbus) { 230 switch (at24->use_smbus) {
231 case I2C_SMBUS_I2C_BLOCK_DATA:
223 status = i2c_smbus_read_i2c_block_data(client, offset, 232 status = i2c_smbus_read_i2c_block_data(client, offset,
224 count, buf); 233 count, buf);
225 } else { 234 break;
235 case I2C_SMBUS_WORD_DATA:
236 status = i2c_smbus_read_word_data(client, offset);
237 if (status >= 0) {
238 buf[0] = status & 0xff;
239 buf[1] = status >> 8;
240 status = count;
241 }
242 break;
243 case I2C_SMBUS_BYTE_DATA:
244 status = i2c_smbus_read_byte_data(client, offset);
245 if (status >= 0) {
246 buf[0] = status;
247 status = count;
248 }
249 break;
250 default:
226 status = i2c_transfer(client->adapter, msg, 2); 251 status = i2c_transfer(client->adapter, msg, 2);
227 if (status == 2) 252 if (status == 2)
228 status = count; 253 status = count;
@@ -274,7 +299,8 @@ static ssize_t at24_read(struct at24_data *at24,
274 return retval; 299 return retval;
275} 300}
276 301
277static ssize_t at24_bin_read(struct kobject *kobj, struct bin_attribute *attr, 302static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj,
303 struct bin_attribute *attr,
278 char *buf, loff_t off, size_t count) 304 char *buf, loff_t off, size_t count)
279{ 305{
280 struct at24_data *at24; 306 struct at24_data *at24;
@@ -395,7 +421,8 @@ static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off,
395 return retval; 421 return retval;
396} 422}
397 423
398static ssize_t at24_bin_write(struct kobject *kobj, struct bin_attribute *attr, 424static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj,
425 struct bin_attribute *attr,
399 char *buf, loff_t off, size_t count) 426 char *buf, loff_t off, size_t count)
400{ 427{
401 struct at24_data *at24; 428 struct at24_data *at24;
@@ -434,7 +461,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
434{ 461{
435 struct at24_platform_data chip; 462 struct at24_platform_data chip;
436 bool writable; 463 bool writable;
437 bool use_smbus = false; 464 int use_smbus = 0;
438 struct at24_data *at24; 465 struct at24_data *at24;
439 int err; 466 int err;
440 unsigned i, num_addresses; 467 unsigned i, num_addresses;
@@ -475,12 +502,19 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
475 err = -EPFNOSUPPORT; 502 err = -EPFNOSUPPORT;
476 goto err_out; 503 goto err_out;
477 } 504 }
478 if (!i2c_check_functionality(client->adapter, 505 if (i2c_check_functionality(client->adapter,
479 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 506 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
507 use_smbus = I2C_SMBUS_I2C_BLOCK_DATA;
508 } else if (i2c_check_functionality(client->adapter,
509 I2C_FUNC_SMBUS_READ_WORD_DATA)) {
510 use_smbus = I2C_SMBUS_WORD_DATA;
511 } else if (i2c_check_functionality(client->adapter,
512 I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
513 use_smbus = I2C_SMBUS_BYTE_DATA;
514 } else {
480 err = -EPFNOSUPPORT; 515 err = -EPFNOSUPPORT;
481 goto err_out; 516 goto err_out;
482 } 517 }
483 use_smbus = true;
484 } 518 }
485 519
486 if (chip.flags & AT24_FLAG_TAKE8ADDR) 520 if (chip.flags & AT24_FLAG_TAKE8ADDR)
@@ -505,6 +539,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
505 * Export the EEPROM bytes through sysfs, since that's convenient. 539 * Export the EEPROM bytes through sysfs, since that's convenient.
506 * By default, only root should see the data (maybe passwords etc) 540 * By default, only root should see the data (maybe passwords etc)
507 */ 541 */
542 sysfs_bin_attr_init(&at24->bin);
508 at24->bin.attr.name = "eeprom"; 543 at24->bin.attr.name = "eeprom";
509 at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; 544 at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR;
510 at24->bin.read = at24_bin_read; 545 at24->bin.read = at24_bin_read;
@@ -565,11 +600,16 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
565 dev_info(&client->dev, "%zu byte %s EEPROM %s\n", 600 dev_info(&client->dev, "%zu byte %s EEPROM %s\n",
566 at24->bin.size, client->name, 601 at24->bin.size, client->name,
567 writable ? "(writable)" : "(read-only)"); 602 writable ? "(writable)" : "(read-only)");
603 if (use_smbus == I2C_SMBUS_WORD_DATA ||
604 use_smbus == I2C_SMBUS_BYTE_DATA) {
605 dev_notice(&client->dev, "Falling back to %s reads, "
606 "performance will suffer\n", use_smbus ==
607 I2C_SMBUS_WORD_DATA ? "word" : "byte");
608 }
568 dev_dbg(&client->dev, 609 dev_dbg(&client->dev,
569 "page_size %d, num_addresses %d, write_max %d%s\n", 610 "page_size %d, num_addresses %d, write_max %d, use_smbus %d\n",
570 chip.page_size, num_addresses, 611 chip.page_size, num_addresses,
571 at24->write_max, 612 at24->write_max, use_smbus);
572 use_smbus ? ", use_smbus" : "");
573 613
574 /* export data to kernel code */ 614 /* export data to kernel code */
575 if (chip.setup) 615 if (chip.setup)
@@ -603,7 +643,6 @@ static int __devexit at24_remove(struct i2c_client *client)
603 643
604 kfree(at24->writebuf); 644 kfree(at24->writebuf);
605 kfree(at24); 645 kfree(at24);
606 i2c_set_clientdata(client, NULL);
607 return 0; 646 return 0;
608} 647}
609 648
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index d902d81dde39..c627e4174ccd 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -126,7 +126,8 @@ at25_ee_read(
126} 126}
127 127
128static ssize_t 128static ssize_t
129at25_bin_read(struct kobject *kobj, struct bin_attribute *bin_attr, 129at25_bin_read(struct file *filp, struct kobject *kobj,
130 struct bin_attribute *bin_attr,
130 char *buf, loff_t off, size_t count) 131 char *buf, loff_t off, size_t count)
131{ 132{
132 struct device *dev; 133 struct device *dev;
@@ -253,7 +254,8 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
253} 254}
254 255
255static ssize_t 256static ssize_t
256at25_bin_write(struct kobject *kobj, struct bin_attribute *bin_attr, 257at25_bin_write(struct file *filp, struct kobject *kobj,
258 struct bin_attribute *bin_attr,
257 char *buf, loff_t off, size_t count) 259 char *buf, loff_t off, size_t count)
258{ 260{
259 struct device *dev; 261 struct device *dev;
@@ -347,6 +349,7 @@ static int at25_probe(struct spi_device *spi)
347 * that's sensitive for read and/or write, like ethernet addresses, 349 * that's sensitive for read and/or write, like ethernet addresses,
348 * security codes, board-specific manufacturing calibrations, etc. 350 * security codes, board-specific manufacturing calibrations, etc.
349 */ 351 */
352 sysfs_bin_attr_init(&at25->bin);
350 at25->bin.attr.name = "eeprom"; 353 at25->bin.attr.name = "eeprom";
351 at25->bin.attr.mode = S_IRUSR; 354 at25->bin.attr.mode = S_IRUSR;
352 at25->bin.read = at25_bin_read; 355 at25->bin.read = at25_bin_read;
diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
index f939ebc2507c..45060ddc4e59 100644
--- a/drivers/misc/eeprom/eeprom.c
+++ b/drivers/misc/eeprom/eeprom.c
@@ -1,24 +1,20 @@
1/* 1/*
2 Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and 2 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
3 Philip Edelbrock <phil@netroedge.com> 3 * Philip Edelbrock <phil@netroedge.com>
4 Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> 4 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
5 Copyright (C) 2003 IBM Corp. 5 * Copyright (C) 2003 IBM Corp.
6 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> 6 * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 */
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22 18
23#include <linux/kernel.h> 19#include <linux/kernel.h>
24#include <linux/init.h> 20#include <linux/init.h>
@@ -85,7 +81,8 @@ exit:
85 mutex_unlock(&data->update_lock); 81 mutex_unlock(&data->update_lock);
86} 82}
87 83
88static ssize_t eeprom_read(struct kobject *kobj, struct bin_attribute *bin_attr, 84static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
85 struct bin_attribute *bin_attr,
89 char *buf, loff_t off, size_t count) 86 char *buf, loff_t off, size_t count)
90{ 87{
91 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); 88 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj));
diff --git a/drivers/misc/eeprom/eeprom_93cx6.c b/drivers/misc/eeprom/eeprom_93cx6.c
index 15b1780025c8..7b33de95c4bf 100644
--- a/drivers/misc/eeprom/eeprom_93cx6.c
+++ b/drivers/misc/eeprom/eeprom_93cx6.c
@@ -1,27 +1,20 @@
1/* 1/*
2 Copyright (C) 2004 - 2006 rt2x00 SourceForge Project 2 * Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com> 3 * <http://rt2x00.serialmonkey.com>
4 4 *
5 This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 * the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 * (at your option) any later version.
9 9 *
10 This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 * GNU General Public License for more details.
14 14 *
15 You should have received a copy of the GNU General Public License 15 * Module: eeprom_93cx6
16 along with this program; if not, write to the 16 * Abstract: EEPROM reader routines for 93cx6 chipsets.
17 Free Software Foundation, Inc., 17 * Supported chipsets: 93c46 & 93c66.
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 Module: eeprom_93cx6
23 Abstract: EEPROM reader routines for 93cx6 chipsets.
24 Supported chipsets: 93c46 & 93c66.
25 */ 18 */
26 19
27#include <linux/kernel.h> 20#include <linux/kernel.h>
diff --git a/drivers/misc/eeprom/max6875.c b/drivers/misc/eeprom/max6875.c
index 5a6b2bce8ad5..5653a3ce0517 100644
--- a/drivers/misc/eeprom/max6875.c
+++ b/drivers/misc/eeprom/max6875.c
@@ -1,30 +1,30 @@
1/* 1/*
2 max6875.c - driver for MAX6874/MAX6875 2 * max6875.c - driver for MAX6874/MAX6875
3 3 *
4 Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com> 4 * Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
5 5 *
6 Based on eeprom.c 6 * Based on eeprom.c
7 7 *
8 The MAX6875 has a bank of registers and two banks of EEPROM. 8 * The MAX6875 has a bank of registers and two banks of EEPROM.
9 Address ranges are defined as follows: 9 * Address ranges are defined as follows:
10 * 0x0000 - 0x0046 = configuration registers 10 * * 0x0000 - 0x0046 = configuration registers
11 * 0x8000 - 0x8046 = configuration EEPROM 11 * * 0x8000 - 0x8046 = configuration EEPROM
12 * 0x8100 - 0x82FF = user EEPROM 12 * * 0x8100 - 0x82FF = user EEPROM
13 13 *
14 This driver makes the user EEPROM available for read. 14 * This driver makes the user EEPROM available for read.
15 15 *
16 The registers & config EEPROM should be accessed via i2c-dev. 16 * The registers & config EEPROM should be accessed via i2c-dev.
17 17 *
18 The MAX6875 ignores the lowest address bit, so each chip responds to 18 * The MAX6875 ignores the lowest address bit, so each chip responds to
19 two addresses - 0x50/0x51 and 0x52/0x53. 19 * two addresses - 0x50/0x51 and 0x52/0x53.
20 20 *
21 Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read 21 * Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read
22 address, so this driver is destructive if loaded for the wrong EEPROM chip. 22 * address, so this driver is destructive if loaded for the wrong EEPROM chip.
23 23 *
24 This program is free software; you can redistribute it and/or modify 24 * This program is free software; you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by 25 * it under the terms of the GNU General Public License as published by
26 the Free Software Foundation; version 2 of the License. 26 * the Free Software Foundation; version 2 of the License.
27*/ 27 */
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/init.h> 30#include <linux/init.h>
@@ -107,7 +107,7 @@ exit_up:
107 mutex_unlock(&data->update_lock); 107 mutex_unlock(&data->update_lock);
108} 108}
109 109
110static ssize_t max6875_read(struct kobject *kobj, 110static ssize_t max6875_read(struct file *filp, struct kobject *kobj,
111 struct bin_attribute *bin_attr, 111 struct bin_attribute *bin_attr,
112 char *buf, loff_t off, size_t count) 112 char *buf, loff_t off, size_t count)
113{ 113{
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 1eac626e710a..48c84a58163e 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -27,6 +27,7 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/slab.h>
30 31
31static LIST_HEAD(container_list); 32static LIST_HEAD(container_list);
32static DEFINE_MUTEX(container_list_lock); 33static DEFINE_MUTEX(container_list_lock);
diff --git a/drivers/misc/ep93xx_pwm.c b/drivers/misc/ep93xx_pwm.c
index ba4694169d79..46b3439673e9 100644
--- a/drivers/misc/ep93xx_pwm.c
+++ b/drivers/misc/ep93xx_pwm.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/slab.h>
22#include <linux/clk.h> 23#include <linux/clk.h>
23#include <linux/err.h> 24#include <linux/err.h>
24#include <linux/io.h> 25#include <linux/io.h>
diff --git a/drivers/misc/hdpuftrs/Makefile b/drivers/misc/hdpuftrs/Makefile
deleted file mode 100644
index ac74ae679230..000000000000
--- a/drivers/misc/hdpuftrs/Makefile
+++ /dev/null
@@ -1 +0,0 @@
1obj-$(CONFIG_HDPU_FEATURES) := hdpu_cpustate.o hdpu_nexus.o
diff --git a/drivers/misc/hdpuftrs/hdpu_cpustate.c b/drivers/misc/hdpuftrs/hdpu_cpustate.c
deleted file mode 100644
index 176fe4e09d3f..000000000000
--- a/drivers/misc/hdpuftrs/hdpu_cpustate.c
+++ /dev/null
@@ -1,256 +0,0 @@
1/*
2 * Sky CPU State Driver
3 *
4 * Copyright (C) 2002 Brian Waite
5 *
6 * This driver allows use of the CPU state bits
7 * It exports the /dev/sky_cpustate and also
8 * /proc/sky_cpustate pseudo-file for status information.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/spinlock.h>
20#include <linux/smp_lock.h>
21#include <linux/miscdevice.h>
22#include <linux/proc_fs.h>
23#include <linux/hdpu_features.h>
24#include <linux/platform_device.h>
25#include <asm/uaccess.h>
26#include <linux/seq_file.h>
27#include <asm/io.h>
28
29#define SKY_CPUSTATE_VERSION "1.1"
30
31static int hdpu_cpustate_probe(struct platform_device *pdev);
32static int hdpu_cpustate_remove(struct platform_device *pdev);
33
34static unsigned char cpustate_get_state(void);
35static int cpustate_proc_open(struct inode *inode, struct file *file);
36static int cpustate_proc_read(struct seq_file *seq, void *offset);
37
38static struct cpustate_t cpustate;
39
40static const struct file_operations proc_cpustate = {
41 .open = cpustate_proc_open,
42 .read = seq_read,
43 .llseek = seq_lseek,
44 .release = single_release,
45 .owner = THIS_MODULE,
46};
47
48static int cpustate_proc_open(struct inode *inode, struct file *file)
49{
50 return single_open(file, cpustate_proc_read, NULL);
51}
52
53static int cpustate_proc_read(struct seq_file *seq, void *offset)
54{
55 seq_printf(seq, "CPU State: %04x\n", cpustate_get_state());
56 return 0;
57}
58
59static int cpustate_get_ref(int excl)
60{
61
62 int retval = -EBUSY;
63
64 spin_lock(&cpustate.lock);
65
66 if (cpustate.excl)
67 goto out_busy;
68
69 if (excl) {
70 if (cpustate.open_count)
71 goto out_busy;
72 cpustate.excl = 1;
73 }
74
75 cpustate.open_count++;
76 retval = 0;
77
78 out_busy:
79 spin_unlock(&cpustate.lock);
80 return retval;
81}
82
83static int cpustate_free_ref(void)
84{
85
86 spin_lock(&cpustate.lock);
87
88 cpustate.excl = 0;
89 cpustate.open_count--;
90
91 spin_unlock(&cpustate.lock);
92 return 0;
93}
94
95static unsigned char cpustate_get_state(void)
96{
97
98 return cpustate.cached_val;
99}
100
101static void cpustate_set_state(unsigned char new_state)
102{
103 unsigned int state = (new_state << 21);
104
105#ifdef DEBUG_CPUSTATE
106 printk("CPUSTATE -> 0x%x\n", new_state);
107#endif
108 spin_lock(&cpustate.lock);
109 cpustate.cached_val = new_state;
110 writel((0xff << 21), cpustate.clr_addr);
111 writel(state, cpustate.set_addr);
112 spin_unlock(&cpustate.lock);
113}
114
115/*
116 * Now all the various file operations that we export.
117 */
118
119static ssize_t cpustate_read(struct file *file, char *buf,
120 size_t count, loff_t * ppos)
121{
122 unsigned char data;
123
124 if (count < 0)
125 return -EFAULT;
126 if (count == 0)
127 return 0;
128
129 data = cpustate_get_state();
130 if (copy_to_user(buf, &data, sizeof(unsigned char)))
131 return -EFAULT;
132 return sizeof(unsigned char);
133}
134
135static ssize_t cpustate_write(struct file *file, const char *buf,
136 size_t count, loff_t * ppos)
137{
138 unsigned char data;
139
140 if (count < 0)
141 return -EFAULT;
142
143 if (count == 0)
144 return 0;
145
146 if (copy_from_user((unsigned char *)&data, buf, sizeof(unsigned char)))
147 return -EFAULT;
148
149 cpustate_set_state(data);
150 return sizeof(unsigned char);
151}
152
153static int cpustate_open(struct inode *inode, struct file *file)
154{
155 int ret;
156
157 lock_kernel();
158 ret = cpustate_get_ref((file->f_flags & O_EXCL));
159 unlock_kernel();
160
161 return ret;
162}
163
164static int cpustate_release(struct inode *inode, struct file *file)
165{
166 return cpustate_free_ref();
167}
168
169static struct platform_driver hdpu_cpustate_driver = {
170 .probe = hdpu_cpustate_probe,
171 .remove = hdpu_cpustate_remove,
172 .driver = {
173 .name = HDPU_CPUSTATE_NAME,
174 .owner = THIS_MODULE,
175 },
176};
177
178/*
179 * The various file operations we support.
180 */
181static const struct file_operations cpustate_fops = {
182 .owner = THIS_MODULE,
183 .open = cpustate_open,
184 .release = cpustate_release,
185 .read = cpustate_read,
186 .write = cpustate_write,
187 .llseek = no_llseek,
188};
189
190static struct miscdevice cpustate_dev = {
191 .minor = MISC_DYNAMIC_MINOR,
192 .name = "sky_cpustate",
193 .fops = &cpustate_fops,
194};
195
196static int hdpu_cpustate_probe(struct platform_device *pdev)
197{
198 struct resource *res;
199 struct proc_dir_entry *proc_de;
200 int ret;
201
202 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
203 if (!res) {
204 printk(KERN_ERR "sky_cpustate: "
205 "Invalid memory resource.\n");
206 return -EINVAL;
207 }
208 cpustate.set_addr = (unsigned long *)res->start;
209 cpustate.clr_addr = (unsigned long *)res->end - 1;
210
211 ret = misc_register(&cpustate_dev);
212 if (ret) {
213 printk(KERN_WARNING "sky_cpustate: "
214 "Unable to register misc device.\n");
215 cpustate.set_addr = NULL;
216 cpustate.clr_addr = NULL;
217 return ret;
218 }
219
220 proc_de = proc_create("sky_cpustate", 0666, NULL, &proc_cpustate);
221 if (!proc_de) {
222 printk(KERN_WARNING "sky_cpustate: "
223 "Unable to create proc entry\n");
224 }
225
226 printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n");
227 return 0;
228}
229
230static int hdpu_cpustate_remove(struct platform_device *pdev)
231{
232 cpustate.set_addr = NULL;
233 cpustate.clr_addr = NULL;
234
235 remove_proc_entry("sky_cpustate", NULL);
236 misc_deregister(&cpustate_dev);
237
238 return 0;
239}
240
241static int __init cpustate_init(void)
242{
243 return platform_driver_register(&hdpu_cpustate_driver);
244}
245
246static void __exit cpustate_exit(void)
247{
248 platform_driver_unregister(&hdpu_cpustate_driver);
249}
250
251module_init(cpustate_init);
252module_exit(cpustate_exit);
253
254MODULE_AUTHOR("Brian Waite");
255MODULE_LICENSE("GPL");
256MODULE_ALIAS("platform:" HDPU_CPUSTATE_NAME);
diff --git a/drivers/misc/hdpuftrs/hdpu_nexus.c b/drivers/misc/hdpuftrs/hdpu_nexus.c
deleted file mode 100644
index ce39fa54949b..000000000000
--- a/drivers/misc/hdpuftrs/hdpu_nexus.c
+++ /dev/null
@@ -1,149 +0,0 @@
1/*
2 * Sky Nexus Register Driver
3 *
4 * Copyright (C) 2002 Brian Waite
5 *
6 * This driver allows reading the Nexus register
7 * It exports the /proc/sky_chassis_id and also
8 * /proc/sky_slot_id pseudo-file for status information.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/proc_fs.h>
20#include <linux/hdpu_features.h>
21#include <linux/platform_device.h>
22#include <linux/seq_file.h>
23#include <asm/io.h>
24
25static int hdpu_nexus_probe(struct platform_device *pdev);
26static int hdpu_nexus_remove(struct platform_device *pdev);
27static int hdpu_slot_id_open(struct inode *inode, struct file *file);
28static int hdpu_slot_id_read(struct seq_file *seq, void *offset);
29static int hdpu_chassis_id_open(struct inode *inode, struct file *file);
30static int hdpu_chassis_id_read(struct seq_file *seq, void *offset);
31
32static struct proc_dir_entry *hdpu_slot_id;
33static struct proc_dir_entry *hdpu_chassis_id;
34static int slot_id = -1;
35static int chassis_id = -1;
36
37static const struct file_operations proc_slot_id = {
38 .open = hdpu_slot_id_open,
39 .read = seq_read,
40 .llseek = seq_lseek,
41 .release = single_release,
42 .owner = THIS_MODULE,
43};
44
45static const struct file_operations proc_chassis_id = {
46 .open = hdpu_chassis_id_open,
47 .read = seq_read,
48 .llseek = seq_lseek,
49 .release = single_release,
50 .owner = THIS_MODULE,
51};
52
53static struct platform_driver hdpu_nexus_driver = {
54 .probe = hdpu_nexus_probe,
55 .remove = hdpu_nexus_remove,
56 .driver = {
57 .name = HDPU_NEXUS_NAME,
58 .owner = THIS_MODULE,
59 },
60};
61
62static int hdpu_slot_id_open(struct inode *inode, struct file *file)
63{
64 return single_open(file, hdpu_slot_id_read, NULL);
65}
66
67static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
68{
69 seq_printf(seq, "%d\n", slot_id);
70 return 0;
71}
72
73static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
74{
75 return single_open(file, hdpu_chassis_id_read, NULL);
76}
77
78static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
79{
80 seq_printf(seq, "%d\n", chassis_id);
81 return 0;
82}
83
84static int hdpu_nexus_probe(struct platform_device *pdev)
85{
86 struct resource *res;
87 int *nexus_id_addr;
88
89 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90 if (!res) {
91 printk(KERN_ERR "sky_nexus: "
92 "Invalid memory resource.\n");
93 return -EINVAL;
94 }
95 nexus_id_addr = ioremap(res->start,
96 (unsigned long)(res->end - res->start));
97 if (nexus_id_addr) {
98 slot_id = (*nexus_id_addr >> 8) & 0x1f;
99 chassis_id = *nexus_id_addr & 0xff;
100 iounmap(nexus_id_addr);
101 } else {
102 printk(KERN_ERR "sky_nexus: Could not map slot id\n");
103 }
104
105 hdpu_slot_id = proc_create("sky_slot_id", 0666, NULL, &proc_slot_id);
106 if (!hdpu_slot_id) {
107 printk(KERN_WARNING "sky_nexus: "
108 "Unable to create proc dir entry: sky_slot_id\n");
109 }
110
111 hdpu_chassis_id = proc_create("sky_chassis_id", 0666, NULL,
112 &proc_chassis_id);
113 if (!hdpu_chassis_id)
114 printk(KERN_WARNING "sky_nexus: "
115 "Unable to create proc dir entry: sky_chassis_id\n");
116
117 return 0;
118}
119
120static int hdpu_nexus_remove(struct platform_device *pdev)
121{
122 slot_id = -1;
123 chassis_id = -1;
124
125 remove_proc_entry("sky_slot_id", NULL);
126 remove_proc_entry("sky_chassis_id", NULL);
127
128 hdpu_slot_id = 0;
129 hdpu_chassis_id = 0;
130
131 return 0;
132}
133
134static int __init nexus_init(void)
135{
136 return platform_driver_register(&hdpu_nexus_driver);
137}
138
139static void __exit nexus_exit(void)
140{
141 platform_driver_unregister(&hdpu_nexus_driver);
142}
143
144module_init(nexus_init);
145module_exit(nexus_exit);
146
147MODULE_AUTHOR("Brian Waite");
148MODULE_LICENSE("GPL");
149MODULE_ALIAS("platform:" HDPU_NEXUS_NAME);
diff --git a/drivers/misc/hpilo.c b/drivers/misc/hpilo.c
index a92a3a742b43..98ad0120aa9b 100644
--- a/drivers/misc/hpilo.c
+++ b/drivers/misc/hpilo.c
@@ -25,6 +25,7 @@
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/wait.h> 26#include <linux/wait.h>
27#include <linux/poll.h> 27#include <linux/poll.h>
28#include <linux/slab.h>
28#include "hpilo.h" 29#include "hpilo.h"
29 30
30static struct class *ilo_class; 31static struct class *ilo_class;
diff --git a/drivers/misc/ibmasm/command.c b/drivers/misc/ibmasm/command.c
index e2031739aa29..5c766b4fb238 100644
--- a/drivers/misc/ibmasm/command.c
+++ b/drivers/misc/ibmasm/command.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/slab.h>
26#include "ibmasm.h" 27#include "ibmasm.h"
27#include "lowlevel.h" 28#include "lowlevel.h"
28 29
diff --git a/drivers/misc/ibmasm/event.c b/drivers/misc/ibmasm/event.c
index 572d41ffc186..76bfda1ffaa9 100644
--- a/drivers/misc/ibmasm/event.c
+++ b/drivers/misc/ibmasm/event.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/slab.h>
26#include "ibmasm.h" 27#include "ibmasm.h"
27#include "lowlevel.h" 28#include "lowlevel.h"
28 29
diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index aecf40ecb3a4..8844a3f45381 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -75,6 +75,7 @@
75 75
76#include <linux/fs.h> 76#include <linux/fs.h>
77#include <linux/pagemap.h> 77#include <linux/pagemap.h>
78#include <linux/slab.h>
78#include <asm/uaccess.h> 79#include <asm/uaccess.h>
79#include <asm/io.h> 80#include <asm/io.h>
80#include "ibmasm.h" 81#include "ibmasm.h"
diff --git a/drivers/misc/ibmasm/module.c b/drivers/misc/ibmasm/module.c
index dc14b0b9cbfa..a234d965243b 100644
--- a/drivers/misc/ibmasm/module.c
+++ b/drivers/misc/ibmasm/module.c
@@ -52,6 +52,7 @@
52 52
53#include <linux/pci.h> 53#include <linux/pci.h>
54#include <linux/init.h> 54#include <linux/init.h>
55#include <linux/slab.h>
55#include "ibmasm.h" 56#include "ibmasm.h"
56#include "lowlevel.h" 57#include "lowlevel.h"
57#include "remote.h" 58#include "remote.h"
diff --git a/drivers/misc/ics932s401.c b/drivers/misc/ics932s401.c
index 395a4ea64e9c..152e9d93eecb 100644
--- a/drivers/misc/ics932s401.c
+++ b/drivers/misc/ics932s401.c
@@ -26,6 +26,7 @@
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/log2.h> 28#include <linux/log2.h>
29#include <linux/slab.h>
29 30
30/* Addresses to scan */ 31/* Addresses to scan */
31static const unsigned short normal_i2c[] = { 0x69, I2C_CLIENT_END }; 32static const unsigned short normal_i2c[] = { 0x69, I2C_CLIENT_END };
diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index 09dcb699e667..193206602d88 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -30,6 +30,7 @@
30#include <linux/pci.h> 30#include <linux/pci.h>
31#include <linux/ioc4.h> 31#include <linux/ioc4.h>
32#include <linux/ktime.h> 32#include <linux/ktime.h>
33#include <linux/slab.h>
33#include <linux/mutex.h> 34#include <linux/mutex.h>
34#include <linux/time.h> 35#include <linux/time.h>
35#include <asm/io.h> 36#include <asm/io.h>
diff --git a/drivers/misc/iwmc3200top/debugfs.c b/drivers/misc/iwmc3200top/debugfs.c
index 0c8ea0a1c8a3..e9eda471f6e0 100644
--- a/drivers/misc/iwmc3200top/debugfs.c
+++ b/drivers/misc/iwmc3200top/debugfs.c
@@ -25,6 +25,7 @@
25 */ 25 */
26 26
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/slab.h>
28#include <linux/string.h> 29#include <linux/string.h>
29#include <linux/ctype.h> 30#include <linux/ctype.h>
30#include <linux/mmc/sdio_func.h> 31#include <linux/mmc/sdio_func.h>
diff --git a/drivers/misc/iwmc3200top/fw-download.c b/drivers/misc/iwmc3200top/fw-download.c
index 50d431e469f5..e27afde6e99f 100644
--- a/drivers/misc/iwmc3200top/fw-download.c
+++ b/drivers/misc/iwmc3200top/fw-download.c
@@ -26,6 +26,7 @@
26 26
27#include <linux/firmware.h> 27#include <linux/firmware.h>
28#include <linux/mmc/sdio_func.h> 28#include <linux/mmc/sdio_func.h>
29#include <linux/slab.h>
29#include <asm/unaligned.h> 30#include <asm/unaligned.h>
30 31
31#include "iwmc3200top.h" 32#include "iwmc3200top.h"
@@ -43,15 +44,14 @@ static int iwmct_fw_parser_init(struct iwmct_priv *priv, const u8 *file,
43 struct iwmct_parser *parser = &priv->parser; 44 struct iwmct_parser *parser = &priv->parser;
44 struct iwmct_fw_hdr *fw_hdr = &parser->versions; 45 struct iwmct_fw_hdr *fw_hdr = &parser->versions;
45 46
46 LOG_INFOEX(priv, INIT, "-->\n"); 47 LOG_TRACE(priv, FW_DOWNLOAD, "-->\n");
47 48
48 LOG_INFO(priv, FW_DOWNLOAD, "file_size=%zd\n", file_size); 49 LOG_INFO(priv, FW_DOWNLOAD, "file_size=%zd\n", file_size);
49 50
50 parser->file = file; 51 parser->file = file;
51 parser->file_size = file_size; 52 parser->file_size = file_size;
52 parser->cur_pos = 0; 53 parser->cur_pos = 0;
53 parser->buf = NULL; 54 parser->entry_point = 0;
54
55 parser->buf = kzalloc(block_size, GFP_KERNEL); 55 parser->buf = kzalloc(block_size, GFP_KERNEL);
56 if (!parser->buf) { 56 if (!parser->buf) {
57 LOG_ERROR(priv, FW_DOWNLOAD, "kzalloc error\n"); 57 LOG_ERROR(priv, FW_DOWNLOAD, "kzalloc error\n");
@@ -70,7 +70,7 @@ static int iwmct_fw_parser_init(struct iwmct_priv *priv, const u8 *file,
70 70
71 parser->cur_pos += sizeof(struct iwmct_fw_hdr); 71 parser->cur_pos += sizeof(struct iwmct_fw_hdr);
72 72
73 LOG_INFOEX(priv, INIT, "<--\n"); 73 LOG_TRACE(priv, FW_DOWNLOAD, "<--\n");
74 return 0; 74 return 0;
75} 75}
76 76
@@ -113,7 +113,7 @@ static int iwmct_parse_next_section(struct iwmct_priv *priv, const u8 **p_sec,
113 struct iwmct_dbg *dbg = &priv->dbg; 113 struct iwmct_dbg *dbg = &priv->dbg;
114 struct iwmct_fw_sec_hdr *sec_hdr; 114 struct iwmct_fw_sec_hdr *sec_hdr;
115 115
116 LOG_INFOEX(priv, INIT, "-->\n"); 116 LOG_TRACE(priv, FW_DOWNLOAD, "-->\n");
117 117
118 while (parser->cur_pos + sizeof(struct iwmct_fw_sec_hdr) 118 while (parser->cur_pos + sizeof(struct iwmct_fw_sec_hdr)
119 <= parser->file_size) { 119 <= parser->file_size) {
@@ -152,7 +152,7 @@ static int iwmct_parse_next_section(struct iwmct_priv *priv, const u8 **p_sec,
152 "finished with section cur_pos=%zd\n", parser->cur_pos); 152 "finished with section cur_pos=%zd\n", parser->cur_pos);
153 } 153 }
154 154
155 LOG_INFOEX(priv, INIT, "<--\n"); 155 LOG_TRACE(priv, INIT, "<--\n");
156 return 0; 156 return 0;
157} 157}
158 158
@@ -167,7 +167,7 @@ static int iwmct_download_section(struct iwmct_priv *priv, const u8 *p_sec,
167 int ret = 0; 167 int ret = 0;
168 u32 cmd = 0; 168 u32 cmd = 0;
169 169
170 LOG_INFOEX(priv, INIT, "-->\n"); 170 LOG_TRACE(priv, FW_DOWNLOAD, "-->\n");
171 LOG_INFO(priv, FW_DOWNLOAD, "Download address 0x%x size 0x%zx\n", 171 LOG_INFO(priv, FW_DOWNLOAD, "Download address 0x%x size 0x%zx\n",
172 addr, sec_size); 172 addr, sec_size);
173 173
@@ -229,7 +229,7 @@ static int iwmct_download_section(struct iwmct_priv *priv, const u8 *p_sec,
229 hdr->cmd = cpu_to_le32(cmd); 229 hdr->cmd = cpu_to_le32(cmd);
230 /* send it down */ 230 /* send it down */
231 /* TODO: add more proper sending and error checking */ 231 /* TODO: add more proper sending and error checking */
232 ret = iwmct_tx(priv, 0, parser->buf, trans_size); 232 ret = iwmct_tx(priv, parser->buf, trans_size);
233 if (ret != 0) { 233 if (ret != 0) {
234 LOG_INFO(priv, FW_DOWNLOAD, 234 LOG_INFO(priv, FW_DOWNLOAD,
235 "iwmct_tx returned %d\n", ret); 235 "iwmct_tx returned %d\n", ret);
@@ -251,7 +251,7 @@ static int iwmct_download_section(struct iwmct_priv *priv, const u8 *p_sec,
251 if (sent < sec_size) 251 if (sent < sec_size)
252 ret = -EINVAL; 252 ret = -EINVAL;
253exit: 253exit:
254 LOG_INFOEX(priv, INIT, "<--\n"); 254 LOG_TRACE(priv, FW_DOWNLOAD, "<--\n");
255 return ret; 255 return ret;
256} 256}
257 257
@@ -262,7 +262,7 @@ static int iwmct_kick_fw(struct iwmct_priv *priv, bool jump)
262 int ret; 262 int ret;
263 u32 cmd; 263 u32 cmd;
264 264
265 LOG_INFOEX(priv, INIT, "-->\n"); 265 LOG_TRACE(priv, FW_DOWNLOAD, "-->\n");
266 266
267 memset(parser->buf, 0, parser->buf_size); 267 memset(parser->buf, 0, parser->buf_size);
268 cmd = IWMC_CMD_SIGNATURE << CMD_HDR_SIGNATURE_POS; 268 cmd = IWMC_CMD_SIGNATURE << CMD_HDR_SIGNATURE_POS;
@@ -281,11 +281,11 @@ static int iwmct_kick_fw(struct iwmct_priv *priv, bool jump)
281 LOG_HEXDUMP(FW_DOWNLOAD, parser->buf, sizeof(*hdr)); 281 LOG_HEXDUMP(FW_DOWNLOAD, parser->buf, sizeof(*hdr));
282 /* send it down */ 282 /* send it down */
283 /* TODO: add more proper sending and error checking */ 283 /* TODO: add more proper sending and error checking */
284 ret = iwmct_tx(priv, 0, parser->buf, IWMC_SDIO_BLK_SIZE); 284 ret = iwmct_tx(priv, parser->buf, IWMC_SDIO_BLK_SIZE);
285 if (ret) 285 if (ret)
286 LOG_INFO(priv, FW_DOWNLOAD, "iwmct_tx returned %d", ret); 286 LOG_INFO(priv, FW_DOWNLOAD, "iwmct_tx returned %d", ret);
287 287
288 LOG_INFOEX(priv, INIT, "<--\n"); 288 LOG_TRACE(priv, FW_DOWNLOAD, "<--\n");
289 return 0; 289 return 0;
290} 290}
291 291
@@ -298,8 +298,16 @@ int iwmct_fw_load(struct iwmct_priv *priv)
298 __le32 addr; 298 __le32 addr;
299 int ret; 299 int ret;
300 300
301 /* clear parser struct */ 301
302 memset(&priv->parser, 0, sizeof(struct iwmct_parser)); 302 LOG_INFO(priv, FW_DOWNLOAD, "barker download request 0x%x is:\n",
303 priv->barker);
304 LOG_INFO(priv, FW_DOWNLOAD, "******* Top FW %s requested ********\n",
305 (priv->barker & BARKER_DNLOAD_TOP_MSK) ? "was" : "not");
306 LOG_INFO(priv, FW_DOWNLOAD, "******* GPS FW %s requested ********\n",
307 (priv->barker & BARKER_DNLOAD_GPS_MSK) ? "was" : "not");
308 LOG_INFO(priv, FW_DOWNLOAD, "******* BT FW %s requested ********\n",
309 (priv->barker & BARKER_DNLOAD_BT_MSK) ? "was" : "not");
310
303 311
304 /* get the firmware */ 312 /* get the firmware */
305 ret = request_firmware(&raw, fw_name, &priv->func->dev); 313 ret = request_firmware(&raw, fw_name, &priv->func->dev);
@@ -317,6 +325,7 @@ int iwmct_fw_load(struct iwmct_priv *priv)
317 325
318 LOG_INFO(priv, FW_DOWNLOAD, "Read firmware '%s'\n", fw_name); 326 LOG_INFO(priv, FW_DOWNLOAD, "Read firmware '%s'\n", fw_name);
319 327
328 /* clear parser struct */
320 ret = iwmct_fw_parser_init(priv, raw->data, raw->size, priv->trans_len); 329 ret = iwmct_fw_parser_init(priv, raw->data, raw->size, priv->trans_len);
321 if (ret < 0) { 330 if (ret < 0) {
322 LOG_ERROR(priv, FW_DOWNLOAD, 331 LOG_ERROR(priv, FW_DOWNLOAD,
@@ -324,7 +333,6 @@ int iwmct_fw_load(struct iwmct_priv *priv)
324 goto exit; 333 goto exit;
325 } 334 }
326 335
327 /* checksum */
328 if (!iwmct_checksum(priv)) { 336 if (!iwmct_checksum(priv)) {
329 LOG_ERROR(priv, FW_DOWNLOAD, "checksum error\n"); 337 LOG_ERROR(priv, FW_DOWNLOAD, "checksum error\n");
330 ret = -EINVAL; 338 ret = -EINVAL;
@@ -333,23 +341,18 @@ int iwmct_fw_load(struct iwmct_priv *priv)
333 341
334 /* download firmware to device */ 342 /* download firmware to device */
335 while (iwmct_parse_next_section(priv, &pdata, &len, &addr)) { 343 while (iwmct_parse_next_section(priv, &pdata, &len, &addr)) {
336 if (iwmct_download_section(priv, pdata, len, addr)) { 344 ret = iwmct_download_section(priv, pdata, len, addr);
345 if (ret) {
337 LOG_ERROR(priv, FW_DOWNLOAD, 346 LOG_ERROR(priv, FW_DOWNLOAD,
338 "%s download section failed\n", fw_name); 347 "%s download section failed\n", fw_name);
339 ret = -EIO;
340 goto exit; 348 goto exit;
341 } 349 }
342 } 350 }
343 351
344 iwmct_kick_fw(priv, !!(priv->barker & BARKER_DNLOAD_JUMP_MSK)); 352 ret = iwmct_kick_fw(priv, !!(priv->barker & BARKER_DNLOAD_JUMP_MSK));
345 353
346exit: 354exit:
347 kfree(priv->parser.buf); 355 kfree(priv->parser.buf);
348 356 release_firmware(raw);
349 if (raw)
350 release_firmware(raw);
351
352 raw = NULL;
353
354 return ret; 357 return ret;
355} 358}
diff --git a/drivers/misc/iwmc3200top/iwmc3200top.h b/drivers/misc/iwmc3200top/iwmc3200top.h
index 43bd510e1872..740ff0738ea8 100644
--- a/drivers/misc/iwmc3200top/iwmc3200top.h
+++ b/drivers/misc/iwmc3200top/iwmc3200top.h
@@ -196,9 +196,7 @@ struct iwmct_priv {
196 struct list_head read_req_list; 196 struct list_head read_req_list;
197}; 197};
198 198
199extern int iwmct_tx(struct iwmct_priv *priv, unsigned int addr, 199extern int iwmct_tx(struct iwmct_priv *priv, void *src, int count);
200 void *src, int count);
201
202extern int iwmct_fw_load(struct iwmct_priv *priv); 200extern int iwmct_fw_load(struct iwmct_priv *priv);
203 201
204extern void iwmct_dbg_init_params(struct iwmct_priv *drv); 202extern void iwmct_dbg_init_params(struct iwmct_priv *drv);
diff --git a/drivers/misc/iwmc3200top/log.c b/drivers/misc/iwmc3200top/log.c
index d569279698f6..a36a55a49cac 100644
--- a/drivers/misc/iwmc3200top/log.c
+++ b/drivers/misc/iwmc3200top/log.c
@@ -26,6 +26,7 @@
26 26
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/mmc/sdio_func.h> 28#include <linux/mmc/sdio_func.h>
29#include <linux/slab.h>
29#include <linux/ctype.h> 30#include <linux/ctype.h>
30#include "fw-msg.h" 31#include "fw-msg.h"
31#include "iwmc3200top.h" 32#include "iwmc3200top.h"
diff --git a/drivers/misc/iwmc3200top/log.h b/drivers/misc/iwmc3200top/log.h
index aba8121f978c..4434bb16cea7 100644
--- a/drivers/misc/iwmc3200top/log.h
+++ b/drivers/misc/iwmc3200top/log.h
@@ -37,13 +37,26 @@
37#define LOG_SEV_INFO 3 37#define LOG_SEV_INFO 3
38#define LOG_SEV_INFOEX 4 38#define LOG_SEV_INFOEX 4
39 39
40#define LOG_SEV_FILTER_ALL \ 40/* Log levels not defined for FW */
41 (BIT(LOG_SEV_CRITICAL) | \ 41#define LOG_SEV_TRACE 5
42 BIT(LOG_SEV_ERROR) | \ 42#define LOG_SEV_DUMP 6
43 BIT(LOG_SEV_WARNING) | \ 43
44 BIT(LOG_SEV_INFO) | \ 44#define LOG_SEV_FW_FILTER_ALL \
45 (BIT(LOG_SEV_CRITICAL) | \
46 BIT(LOG_SEV_ERROR) | \
47 BIT(LOG_SEV_WARNING) | \
48 BIT(LOG_SEV_INFO) | \
45 BIT(LOG_SEV_INFOEX)) 49 BIT(LOG_SEV_INFOEX))
46 50
51#define LOG_SEV_FILTER_ALL \
52 (BIT(LOG_SEV_CRITICAL) | \
53 BIT(LOG_SEV_ERROR) | \
54 BIT(LOG_SEV_WARNING) | \
55 BIT(LOG_SEV_INFO) | \
56 BIT(LOG_SEV_INFOEX) | \
57 BIT(LOG_SEV_TRACE) | \
58 BIT(LOG_SEV_DUMP))
59
47/* log source */ 60/* log source */
48#define LOG_SRC_INIT 0 61#define LOG_SRC_INIT 0
49#define LOG_SRC_DEBUGFS 1 62#define LOG_SRC_DEBUGFS 1
@@ -104,16 +117,16 @@ do { \
104 __func__, __LINE__, ##args); \ 117 __func__, __LINE__, ##args); \
105} while (0) 118} while (0)
106 119
107#define LOG_INFOEX(priv, src, fmt, args...) \ 120#define LOG_TRACE(priv, src, fmt, args...) \
108do { \ 121do { \
109 if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_INFOEX)) \ 122 if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_TRACE)) \
110 dev_dbg(priv2dev(priv), "%s %d: " fmt, \ 123 dev_dbg(priv2dev(priv), "%s %d: " fmt, \
111 __func__, __LINE__, ##args); \ 124 __func__, __LINE__, ##args); \
112} while (0) 125} while (0)
113 126
114#define LOG_HEXDUMP(src, ptr, len) \ 127#define LOG_HEXDUMP(src, ptr, len) \
115do { \ 128do { \
116 if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_INFOEX)) \ 129 if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_DUMP)) \
117 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, \ 130 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, \
118 16, 1, ptr, len, false); \ 131 16, 1, ptr, len, false); \
119} while (0) 132} while (0)
@@ -142,7 +155,7 @@ ssize_t store_iwmct_log_level_fw(struct device *d,
142#define LOG_ERROR(priv, src, fmt, args...) 155#define LOG_ERROR(priv, src, fmt, args...)
143#define LOG_WARNING(priv, src, fmt, args...) 156#define LOG_WARNING(priv, src, fmt, args...)
144#define LOG_INFO(priv, src, fmt, args...) 157#define LOG_INFO(priv, src, fmt, args...)
145#define LOG_INFOEX(priv, src, fmt, args...) 158#define LOG_TRACE(priv, src, fmt, args...)
146#define LOG_HEXDUMP(src, ptr, len) 159#define LOG_HEXDUMP(src, ptr, len)
147 160
148static inline void iwmct_log_top_message(struct iwmct_priv *priv, 161static inline void iwmct_log_top_message(struct iwmct_priv *priv,
diff --git a/drivers/misc/iwmc3200top/main.c b/drivers/misc/iwmc3200top/main.c
index fafcaa481d74..c73cef2c3c5e 100644
--- a/drivers/misc/iwmc3200top/main.c
+++ b/drivers/misc/iwmc3200top/main.c
@@ -25,6 +25,7 @@
25 */ 25 */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/slab.h>
28#include <linux/init.h> 29#include <linux/init.h>
29#include <linux/kernel.h> 30#include <linux/kernel.h>
30#include <linux/debugfs.h> 31#include <linux/debugfs.h>
@@ -49,6 +50,20 @@ MODULE_LICENSE("GPL");
49MODULE_AUTHOR(DRIVER_COPYRIGHT); 50MODULE_AUTHOR(DRIVER_COPYRIGHT);
50MODULE_FIRMWARE(FW_NAME(FW_API_VER)); 51MODULE_FIRMWARE(FW_NAME(FW_API_VER));
51 52
53
54static inline int __iwmct_tx(struct iwmct_priv *priv, void *src, int count)
55{
56 return sdio_memcpy_toio(priv->func, IWMC_SDIO_DATA_ADDR, src, count);
57
58}
59int iwmct_tx(struct iwmct_priv *priv, void *src, int count)
60{
61 int ret;
62 sdio_claim_host(priv->func);
63 ret = __iwmct_tx(priv, src, count);
64 sdio_release_host(priv->func);
65 return ret;
66}
52/* 67/*
53 * This workers main task is to wait for OP_OPR_ALIVE 68 * This workers main task is to wait for OP_OPR_ALIVE
54 * from TOP FW until ALIVE_MSG_TIMOUT timeout is elapsed. 69 * from TOP FW until ALIVE_MSG_TIMOUT timeout is elapsed.
@@ -66,7 +81,7 @@ static void iwmct_rescan_worker(struct work_struct *ws)
66 81
67 ret = bus_rescan_devices(priv->func->dev.bus); 82 ret = bus_rescan_devices(priv->func->dev.bus);
68 if (ret < 0) 83 if (ret < 0)
69 LOG_INFO(priv, FW_DOWNLOAD, "bus_rescan_devices FAILED!!!\n"); 84 LOG_INFO(priv, INIT, "bus_rescan_devices FAILED!!!\n");
70} 85}
71 86
72static void op_top_message(struct iwmct_priv *priv, struct top_msg *msg) 87static void op_top_message(struct iwmct_priv *priv, struct top_msg *msg)
@@ -137,7 +152,7 @@ int iwmct_send_hcmd(struct iwmct_priv *priv, u8 *cmd, u16 len)
137 int ret; 152 int ret;
138 u8 *buf; 153 u8 *buf;
139 154
140 LOG_INFOEX(priv, FW_MSG, "Sending hcmd:\n"); 155 LOG_TRACE(priv, FW_MSG, "Sending hcmd:\n");
141 156
142 /* add padding to 256 for IWMC */ 157 /* add padding to 256 for IWMC */
143 ((struct top_msg *)cmd)->hdr.flags |= CMD_FLAG_PADDING_256; 158 ((struct top_msg *)cmd)->hdr.flags |= CMD_FLAG_PADDING_256;
@@ -158,27 +173,12 @@ int iwmct_send_hcmd(struct iwmct_priv *priv, u8 *cmd, u16 len)
158 } 173 }
159 174
160 memcpy(buf, cmd, len); 175 memcpy(buf, cmd, len);
161 176 ret = iwmct_tx(priv, buf, FW_HCMD_BLOCK_SIZE);
162 sdio_claim_host(priv->func);
163 ret = sdio_memcpy_toio(priv->func, IWMC_SDIO_DATA_ADDR, buf,
164 FW_HCMD_BLOCK_SIZE);
165 sdio_release_host(priv->func);
166 177
167 kfree(buf); 178 kfree(buf);
168 return ret; 179 return ret;
169} 180}
170 181
171int iwmct_tx(struct iwmct_priv *priv, unsigned int addr,
172 void *src, int count)
173{
174 int ret;
175
176 sdio_claim_host(priv->func);
177 ret = sdio_memcpy_toio(priv->func, addr, src, count);
178 sdio_release_host(priv->func);
179
180 return ret;
181}
182 182
183static void iwmct_irq_read_worker(struct work_struct *ws) 183static void iwmct_irq_read_worker(struct work_struct *ws)
184{ 184{
@@ -192,7 +192,7 @@ static void iwmct_irq_read_worker(struct work_struct *ws)
192 192
193 priv = container_of(ws, struct iwmct_priv, isr_worker); 193 priv = container_of(ws, struct iwmct_priv, isr_worker);
194 194
195 LOG_INFO(priv, IRQ, "enter iwmct_irq_read_worker %p\n", ws); 195 LOG_TRACE(priv, IRQ, "enter iwmct_irq_read_worker %p\n", ws);
196 196
197 /* --------------------- Handshake with device -------------------- */ 197 /* --------------------- Handshake with device -------------------- */
198 sdio_claim_host(priv->func); 198 sdio_claim_host(priv->func);
@@ -273,8 +273,7 @@ static void iwmct_irq_read_worker(struct work_struct *ws)
273 273
274 if (barker & BARKER_DNLOAD_SYNC_MSK) { 274 if (barker & BARKER_DNLOAD_SYNC_MSK) {
275 /* Send the same barker back */ 275 /* Send the same barker back */
276 ret = sdio_memcpy_toio(priv->func, IWMC_SDIO_DATA_ADDR, 276 ret = __iwmct_tx(priv, buf, iosize);
277 buf, iosize);
278 if (ret) { 277 if (ret) {
279 LOG_ERROR(priv, IRQ, 278 LOG_ERROR(priv, IRQ,
280 "error %d echoing barker\n", ret); 279 "error %d echoing barker\n", ret);
@@ -292,15 +291,6 @@ static void iwmct_irq_read_worker(struct work_struct *ws)
292 291
293 sdio_release_host(priv->func); 292 sdio_release_host(priv->func);
294 293
295
296 LOG_INFO(priv, IRQ, "barker download request 0x%x is:\n", priv->barker);
297 LOG_INFO(priv, IRQ, "******* Top FW %s requested ********\n",
298 (priv->barker & BARKER_DNLOAD_TOP_MSK) ? "was" : "not");
299 LOG_INFO(priv, IRQ, "******* GPS FW %s requested ********\n",
300 (priv->barker & BARKER_DNLOAD_GPS_MSK) ? "was" : "not");
301 LOG_INFO(priv, IRQ, "******* BT FW %s requested ********\n",
302 (priv->barker & BARKER_DNLOAD_BT_MSK) ? "was" : "not");
303
304 if (priv->dbg.fw_download) 294 if (priv->dbg.fw_download)
305 iwmct_fw_load(priv); 295 iwmct_fw_load(priv);
306 else 296 else
@@ -312,7 +302,7 @@ exit_release:
312 sdio_release_host(priv->func); 302 sdio_release_host(priv->func);
313exit: 303exit:
314 kfree(buf); 304 kfree(buf);
315 LOG_INFO(priv, IRQ, "exit iwmct_irq_read_worker\n"); 305 LOG_TRACE(priv, IRQ, "exit iwmct_irq_read_worker\n");
316} 306}
317 307
318static void iwmct_irq(struct sdio_func *func) 308static void iwmct_irq(struct sdio_func *func)
@@ -325,12 +315,12 @@ static void iwmct_irq(struct sdio_func *func)
325 315
326 priv = sdio_get_drvdata(func); 316 priv = sdio_get_drvdata(func);
327 317
328 LOG_INFO(priv, IRQ, "enter iwmct_irq\n"); 318 LOG_TRACE(priv, IRQ, "enter iwmct_irq\n");
329 319
330 /* read the function's status register */ 320 /* read the function's status register */
331 val = sdio_readb(func, IWMC_SDIO_INTR_STATUS_ADDR, &ret); 321 val = sdio_readb(func, IWMC_SDIO_INTR_STATUS_ADDR, &ret);
332 322
333 LOG_INFO(priv, IRQ, "iir value = %d, ret=%d\n", val, ret); 323 LOG_TRACE(priv, IRQ, "iir value = %d, ret=%d\n", val, ret);
334 324
335 if (!val) { 325 if (!val) {
336 LOG_ERROR(priv, IRQ, "iir = 0, exiting ISR\n"); 326 LOG_ERROR(priv, IRQ, "iir = 0, exiting ISR\n");
@@ -372,7 +362,7 @@ static void iwmct_irq(struct sdio_func *func)
372 362
373 queue_work(priv->wq, &priv->isr_worker); 363 queue_work(priv->wq, &priv->isr_worker);
374 364
375 LOG_INFO(priv, IRQ, "exit iwmct_irq\n"); 365 LOG_TRACE(priv, IRQ, "exit iwmct_irq\n");
376 366
377 return; 367 return;
378 368
@@ -608,8 +598,6 @@ static void iwmct_remove(struct sdio_func *func)
608 struct iwmct_work_struct *read_req; 598 struct iwmct_work_struct *read_req;
609 struct iwmct_priv *priv = sdio_get_drvdata(func); 599 struct iwmct_priv *priv = sdio_get_drvdata(func);
610 600
611 priv = sdio_get_drvdata(func);
612
613 LOG_INFO(priv, INIT, "enter\n"); 601 LOG_INFO(priv, INIT, "enter\n");
614 602
615 sdio_claim_host(func); 603 sdio_claim_host(func);
@@ -660,7 +648,7 @@ static int __init iwmct_init(void)
660 648
661 /* Default log filter settings */ 649 /* Default log filter settings */
662 iwmct_log_set_filter(LOG_SRC_ALL, LOG_SEV_FILTER_RUNTIME); 650 iwmct_log_set_filter(LOG_SRC_ALL, LOG_SEV_FILTER_RUNTIME);
663 iwmct_log_set_filter(LOG_SRC_FW_MSG, LOG_SEV_FILTER_ALL); 651 iwmct_log_set_filter(LOG_SRC_FW_MSG, LOG_SEV_FW_FILTER_ALL);
664 iwmct_log_set_fw_filter(LOG_SRC_ALL, FW_LOG_SEV_FILTER_RUNTIME); 652 iwmct_log_set_fw_filter(LOG_SRC_ALL, FW_LOG_SEV_FILTER_RUNTIME);
665 653
666 rc = sdio_register_driver(&iwmct_driver); 654 rc = sdio_register_driver(&iwmct_driver);
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index fcb6ec1af173..72450237a0f4 100644
--- a/drivers/misc/kgdbts.c
+++ b/drivers/misc/kgdbts.c
@@ -295,6 +295,10 @@ static int check_and_rewind_pc(char *put_str, char *arg)
295 /* On x86 a breakpoint stop requires it to be decremented */ 295 /* On x86 a breakpoint stop requires it to be decremented */
296 if (addr + 1 == kgdbts_regs.ip) 296 if (addr + 1 == kgdbts_regs.ip)
297 offset = -1; 297 offset = -1;
298#elif defined(CONFIG_SUPERH)
299 /* On SUPERH a breakpoint stop requires it to be decremented */
300 if (addr + 2 == kgdbts_regs.pc)
301 offset = -2;
298#endif 302#endif
299 if (strcmp(arg, "silent") && 303 if (strcmp(arg, "silent") &&
300 instruction_pointer(&kgdbts_regs) + offset != addr) { 304 instruction_pointer(&kgdbts_regs) + offset != addr) {
@@ -305,6 +309,8 @@ static int check_and_rewind_pc(char *put_str, char *arg)
305#ifdef CONFIG_X86 309#ifdef CONFIG_X86
306 /* On x86 adjust the instruction pointer if needed */ 310 /* On x86 adjust the instruction pointer if needed */
307 kgdbts_regs.ip += offset; 311 kgdbts_regs.ip += offset;
312#elif defined(CONFIG_SUPERH)
313 kgdbts_regs.pc += offset;
308#endif 314#endif
309 return 0; 315 return 0;
310} 316}
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 3648b23d5c92..5bfb2a2041b8 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -26,21 +26,9 @@
26 * It is adapted from the Linux Kernel Dump Test Tool by 26 * It is adapted from the Linux Kernel Dump Test Tool by
27 * Fernando Luis Vazquez Cao <http://lkdtt.sourceforge.net> 27 * Fernando Luis Vazquez Cao <http://lkdtt.sourceforge.net>
28 * 28 *
29 * Usage : insmod lkdtm.ko [recur_count={>0}] cpoint_name=<> cpoint_type=<> 29 * Debugfs support added by Simon Kagstrom <simon.kagstrom@netinsight.net>
30 * [cpoint_count={>0}]
31 * 30 *
32 * recur_count : Recursion level for the stack overflow test. Default is 10. 31 * See Documentation/fault-injection/provoke-crashes.txt for instructions
33 *
34 * cpoint_name : Crash point where the kernel is to be crashed. It can be
35 * one of INT_HARDWARE_ENTRY, INT_HW_IRQ_EN, INT_TASKLET_ENTRY,
36 * FS_DEVRW, MEM_SWAPOUT, TIMERADD, SCSI_DISPATCH_CMD,
37 * IDE_CORE_CP
38 *
39 * cpoint_type : Indicates the action to be taken on hitting the crash point.
40 * It can be one of PANIC, BUG, EXCEPTION, LOOP, OVERFLOW
41 *
42 * cpoint_count : Indicates the number of times the crash point is to be hit
43 * to trigger an action. The default is 10.
44 */ 32 */
45 33
46#include <linux/kernel.h> 34#include <linux/kernel.h>
@@ -52,14 +40,14 @@
52#include <linux/init.h> 40#include <linux/init.h>
53#include <linux/interrupt.h> 41#include <linux/interrupt.h>
54#include <linux/hrtimer.h> 42#include <linux/hrtimer.h>
43#include <linux/slab.h>
55#include <scsi/scsi_cmnd.h> 44#include <scsi/scsi_cmnd.h>
45#include <linux/debugfs.h>
56 46
57#ifdef CONFIG_IDE 47#ifdef CONFIG_IDE
58#include <linux/ide.h> 48#include <linux/ide.h>
59#endif 49#endif
60 50
61#define NUM_CPOINTS 8
62#define NUM_CPOINT_TYPES 5
63#define DEFAULT_COUNT 10 51#define DEFAULT_COUNT 10
64#define REC_NUM_DEFAULT 10 52#define REC_NUM_DEFAULT 10
65 53
@@ -72,7 +60,8 @@ enum cname {
72 MEM_SWAPOUT, 60 MEM_SWAPOUT,
73 TIMERADD, 61 TIMERADD,
74 SCSI_DISPATCH_CMD, 62 SCSI_DISPATCH_CMD,
75 IDE_CORE_CP 63 IDE_CORE_CP,
64 DIRECT,
76}; 65};
77 66
78enum ctype { 67enum ctype {
@@ -81,7 +70,14 @@ enum ctype {
81 BUG, 70 BUG,
82 EXCEPTION, 71 EXCEPTION,
83 LOOP, 72 LOOP,
84 OVERFLOW 73 OVERFLOW,
74 CORRUPT_STACK,
75 UNALIGNED_LOAD_STORE_WRITE,
76 OVERWRITE_ALLOCATION,
77 WRITE_AFTER_FREE,
78 SOFTLOCKUP,
79 HARDLOCKUP,
80 HUNG_TASK,
85}; 81};
86 82
87static char* cp_name[] = { 83static char* cp_name[] = {
@@ -92,7 +88,8 @@ static char* cp_name[] = {
92 "MEM_SWAPOUT", 88 "MEM_SWAPOUT",
93 "TIMERADD", 89 "TIMERADD",
94 "SCSI_DISPATCH_CMD", 90 "SCSI_DISPATCH_CMD",
95 "IDE_CORE_CP" 91 "IDE_CORE_CP",
92 "DIRECT",
96}; 93};
97 94
98static char* cp_type[] = { 95static char* cp_type[] = {
@@ -100,7 +97,14 @@ static char* cp_type[] = {
100 "BUG", 97 "BUG",
101 "EXCEPTION", 98 "EXCEPTION",
102 "LOOP", 99 "LOOP",
103 "OVERFLOW" 100 "OVERFLOW",
101 "CORRUPT_STACK",
102 "UNALIGNED_LOAD_STORE_WRITE",
103 "OVERWRITE_ALLOCATION",
104 "WRITE_AFTER_FREE",
105 "SOFTLOCKUP",
106 "HARDLOCKUP",
107 "HUNG_TASK",
104}; 108};
105 109
106static struct jprobe lkdtm; 110static struct jprobe lkdtm;
@@ -193,34 +197,66 @@ int jp_generic_ide_ioctl(ide_drive_t *drive, struct file *file,
193} 197}
194#endif 198#endif
195 199
200/* Return the crashpoint number or NONE if the name is invalid */
201static enum ctype parse_cp_type(const char *what, size_t count)
202{
203 int i;
204
205 for (i = 0; i < ARRAY_SIZE(cp_type); i++) {
206 if (!strcmp(what, cp_type[i]))
207 return i + 1;
208 }
209
210 return NONE;
211}
212
213static const char *cp_type_to_str(enum ctype type)
214{
215 if (type == NONE || type < 0 || type > ARRAY_SIZE(cp_type))
216 return "None";
217
218 return cp_type[type - 1];
219}
220
221static const char *cp_name_to_str(enum cname name)
222{
223 if (name == INVALID || name < 0 || name > ARRAY_SIZE(cp_name))
224 return "INVALID";
225
226 return cp_name[name - 1];
227}
228
229
196static int lkdtm_parse_commandline(void) 230static int lkdtm_parse_commandline(void)
197{ 231{
198 int i; 232 int i;
199 233
200 if (cpoint_name == NULL || cpoint_type == NULL || 234 if (cpoint_count < 1 || recur_count < 1)
201 cpoint_count < 1 || recur_count < 1)
202 return -EINVAL; 235 return -EINVAL;
203 236
204 for (i = 0; i < NUM_CPOINTS; ++i) { 237 count = cpoint_count;
238
239 /* No special parameters */
240 if (!cpoint_type && !cpoint_name)
241 return 0;
242
243 /* Neither or both of these need to be set */
244 if (!cpoint_type || !cpoint_name)
245 return -EINVAL;
246
247 cptype = parse_cp_type(cpoint_type, strlen(cpoint_type));
248 if (cptype == NONE)
249 return -EINVAL;
250
251 for (i = 0; i < ARRAY_SIZE(cp_name); i++) {
205 if (!strcmp(cpoint_name, cp_name[i])) { 252 if (!strcmp(cpoint_name, cp_name[i])) {
206 cpoint = i + 1; 253 cpoint = i + 1;
207 break; 254 return 0;
208 }
209 }
210
211 for (i = 0; i < NUM_CPOINT_TYPES; ++i) {
212 if (!strcmp(cpoint_type, cp_type[i])) {
213 cptype = i + 1;
214 break;
215 } 255 }
216 } 256 }
217 257
218 if (cpoint == INVALID || cptype == NONE) 258 /* Could not find a valid crash point */
219 return -EINVAL; 259 return -EINVAL;
220
221 count = cpoint_count;
222
223 return 0;
224} 260}
225 261
226static int recursive_loop(int a) 262static int recursive_loop(int a)
@@ -235,53 +271,106 @@ static int recursive_loop(int a)
235 return recursive_loop(a); 271 return recursive_loop(a);
236} 272}
237 273
238void lkdtm_handler(void) 274static void lkdtm_do_action(enum ctype which)
275{
276 switch (which) {
277 case PANIC:
278 panic("dumptest");
279 break;
280 case BUG:
281 BUG();
282 break;
283 case EXCEPTION:
284 *((int *) 0) = 0;
285 break;
286 case LOOP:
287 for (;;)
288 ;
289 break;
290 case OVERFLOW:
291 (void) recursive_loop(0);
292 break;
293 case CORRUPT_STACK: {
294 volatile u32 data[8];
295 volatile u32 *p = data;
296
297 p[12] = 0x12345678;
298 break;
299 }
300 case UNALIGNED_LOAD_STORE_WRITE: {
301 static u8 data[5] __attribute__((aligned(4))) = {1, 2,
302 3, 4, 5};
303 u32 *p;
304 u32 val = 0x12345678;
305
306 p = (u32 *)(data + 1);
307 if (*p == 0)
308 val = 0x87654321;
309 *p = val;
310 break;
311 }
312 case OVERWRITE_ALLOCATION: {
313 size_t len = 1020;
314 u32 *data = kmalloc(len, GFP_KERNEL);
315
316 data[1024 / sizeof(u32)] = 0x12345678;
317 kfree(data);
318 break;
319 }
320 case WRITE_AFTER_FREE: {
321 size_t len = 1024;
322 u32 *data = kmalloc(len, GFP_KERNEL);
323
324 kfree(data);
325 schedule();
326 memset(data, 0x78, len);
327 break;
328 }
329 case SOFTLOCKUP:
330 preempt_disable();
331 for (;;)
332 cpu_relax();
333 break;
334 case HARDLOCKUP:
335 local_irq_disable();
336 for (;;)
337 cpu_relax();
338 break;
339 case HUNG_TASK:
340 set_current_state(TASK_UNINTERRUPTIBLE);
341 schedule();
342 break;
343 case NONE:
344 default:
345 break;
346 }
347
348}
349
350static void lkdtm_handler(void)
239{ 351{
240 printk(KERN_INFO "lkdtm : Crash point %s of type %s hit\n", 352 count--;
241 cpoint_name, cpoint_type); 353 printk(KERN_INFO "lkdtm: Crash point %s of type %s hit, trigger in %d rounds\n",
242 --count; 354 cp_name_to_str(cpoint), cp_type_to_str(cptype), count);
243 355
244 if (count == 0) { 356 if (count == 0) {
245 switch (cptype) { 357 lkdtm_do_action(cptype);
246 case NONE:
247 break;
248 case PANIC:
249 printk(KERN_INFO "lkdtm : PANIC\n");
250 panic("dumptest");
251 break;
252 case BUG:
253 printk(KERN_INFO "lkdtm : BUG\n");
254 BUG();
255 break;
256 case EXCEPTION:
257 printk(KERN_INFO "lkdtm : EXCEPTION\n");
258 *((int *) 0) = 0;
259 break;
260 case LOOP:
261 printk(KERN_INFO "lkdtm : LOOP\n");
262 for (;;);
263 break;
264 case OVERFLOW:
265 printk(KERN_INFO "lkdtm : OVERFLOW\n");
266 (void) recursive_loop(0);
267 break;
268 default:
269 break;
270 }
271 count = cpoint_count; 358 count = cpoint_count;
272 } 359 }
273} 360}
274 361
275static int __init lkdtm_module_init(void) 362static int lkdtm_register_cpoint(enum cname which)
276{ 363{
277 int ret; 364 int ret;
278 365
279 if (lkdtm_parse_commandline() == -EINVAL) { 366 cpoint = INVALID;
280 printk(KERN_INFO "lkdtm : Invalid command\n"); 367 if (lkdtm.entry != NULL)
281 return -EINVAL; 368 unregister_jprobe(&lkdtm);
282 }
283 369
284 switch (cpoint) { 370 switch (which) {
371 case DIRECT:
372 lkdtm_do_action(cptype);
373 return 0;
285 case INT_HARDWARE_ENTRY: 374 case INT_HARDWARE_ENTRY:
286 lkdtm.kp.symbol_name = "do_IRQ"; 375 lkdtm.kp.symbol_name = "do_IRQ";
287 lkdtm.entry = (kprobe_opcode_t*) jp_do_irq; 376 lkdtm.entry = (kprobe_opcode_t*) jp_do_irq;
@@ -315,28 +404,268 @@ static int __init lkdtm_module_init(void)
315 lkdtm.kp.symbol_name = "generic_ide_ioctl"; 404 lkdtm.kp.symbol_name = "generic_ide_ioctl";
316 lkdtm.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl; 405 lkdtm.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl;
317#else 406#else
318 printk(KERN_INFO "lkdtm : Crash point not available\n"); 407 printk(KERN_INFO "lkdtm: Crash point not available\n");
408 return -EINVAL;
319#endif 409#endif
320 break; 410 break;
321 default: 411 default:
322 printk(KERN_INFO "lkdtm : Invalid Crash Point\n"); 412 printk(KERN_INFO "lkdtm: Invalid Crash Point\n");
323 break; 413 return -EINVAL;
324 } 414 }
325 415
416 cpoint = which;
326 if ((ret = register_jprobe(&lkdtm)) < 0) { 417 if ((ret = register_jprobe(&lkdtm)) < 0) {
327 printk(KERN_INFO "lkdtm : Couldn't register jprobe\n"); 418 printk(KERN_INFO "lkdtm: Couldn't register jprobe\n");
328 return ret; 419 cpoint = INVALID;
420 }
421
422 return ret;
423}
424
425static ssize_t do_register_entry(enum cname which, struct file *f,
426 const char __user *user_buf, size_t count, loff_t *off)
427{
428 char *buf;
429 int err;
430
431 if (count >= PAGE_SIZE)
432 return -EINVAL;
433
434 buf = (char *)__get_free_page(GFP_KERNEL);
435 if (!buf)
436 return -ENOMEM;
437 if (copy_from_user(buf, user_buf, count)) {
438 free_page((unsigned long) buf);
439 return -EFAULT;
440 }
441 /* NULL-terminate and remove enter */
442 buf[count] = '\0';
443 strim(buf);
444
445 cptype = parse_cp_type(buf, count);
446 free_page((unsigned long) buf);
447
448 if (cptype == NONE)
449 return -EINVAL;
450
451 err = lkdtm_register_cpoint(which);
452 if (err < 0)
453 return err;
454
455 *off += count;
456
457 return count;
458}
459
460/* Generic read callback that just prints out the available crash types */
461static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
462 size_t count, loff_t *off)
463{
464 char *buf;
465 int i, n, out;
466
467 buf = (char *)__get_free_page(GFP_KERNEL);
468
469 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
470 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
471 n += snprintf(buf + n, PAGE_SIZE - n, "%s\n", cp_type[i]);
472 buf[n] = '\0';
473
474 out = simple_read_from_buffer(user_buf, count, off,
475 buf, n);
476 free_page((unsigned long) buf);
477
478 return out;
479}
480
481static int lkdtm_debugfs_open(struct inode *inode, struct file *file)
482{
483 return 0;
484}
485
486
487static ssize_t int_hardware_entry(struct file *f, const char __user *buf,
488 size_t count, loff_t *off)
489{
490 return do_register_entry(INT_HARDWARE_ENTRY, f, buf, count, off);
491}
492
493static ssize_t int_hw_irq_en(struct file *f, const char __user *buf,
494 size_t count, loff_t *off)
495{
496 return do_register_entry(INT_HW_IRQ_EN, f, buf, count, off);
497}
498
499static ssize_t int_tasklet_entry(struct file *f, const char __user *buf,
500 size_t count, loff_t *off)
501{
502 return do_register_entry(INT_TASKLET_ENTRY, f, buf, count, off);
503}
504
505static ssize_t fs_devrw_entry(struct file *f, const char __user *buf,
506 size_t count, loff_t *off)
507{
508 return do_register_entry(FS_DEVRW, f, buf, count, off);
509}
510
511static ssize_t mem_swapout_entry(struct file *f, const char __user *buf,
512 size_t count, loff_t *off)
513{
514 return do_register_entry(MEM_SWAPOUT, f, buf, count, off);
515}
516
517static ssize_t timeradd_entry(struct file *f, const char __user *buf,
518 size_t count, loff_t *off)
519{
520 return do_register_entry(TIMERADD, f, buf, count, off);
521}
522
523static ssize_t scsi_dispatch_cmd_entry(struct file *f,
524 const char __user *buf, size_t count, loff_t *off)
525{
526 return do_register_entry(SCSI_DISPATCH_CMD, f, buf, count, off);
527}
528
529static ssize_t ide_core_cp_entry(struct file *f, const char __user *buf,
530 size_t count, loff_t *off)
531{
532 return do_register_entry(IDE_CORE_CP, f, buf, count, off);
533}
534
535/* Special entry to just crash directly. Available without KPROBEs */
536static ssize_t direct_entry(struct file *f, const char __user *user_buf,
537 size_t count, loff_t *off)
538{
539 enum ctype type;
540 char *buf;
541
542 if (count >= PAGE_SIZE)
543 return -EINVAL;
544 if (count < 1)
545 return -EINVAL;
546
547 buf = (char *)__get_free_page(GFP_KERNEL);
548 if (!buf)
549 return -ENOMEM;
550 if (copy_from_user(buf, user_buf, count)) {
551 free_page((unsigned long) buf);
552 return -EFAULT;
553 }
554 /* NULL-terminate and remove enter */
555 buf[count] = '\0';
556 strim(buf);
557
558 type = parse_cp_type(buf, count);
559 free_page((unsigned long) buf);
560 if (type == NONE)
561 return -EINVAL;
562
563 printk(KERN_INFO "lkdtm: Performing direct entry %s\n",
564 cp_type_to_str(type));
565 lkdtm_do_action(type);
566 *off += count;
567
568 return count;
569}
570
571struct crash_entry {
572 const char *name;
573 const struct file_operations fops;
574};
575
576static const struct crash_entry crash_entries[] = {
577 {"DIRECT", {.read = lkdtm_debugfs_read,
578 .open = lkdtm_debugfs_open,
579 .write = direct_entry} },
580 {"INT_HARDWARE_ENTRY", {.read = lkdtm_debugfs_read,
581 .open = lkdtm_debugfs_open,
582 .write = int_hardware_entry} },
583 {"INT_HW_IRQ_EN", {.read = lkdtm_debugfs_read,
584 .open = lkdtm_debugfs_open,
585 .write = int_hw_irq_en} },
586 {"INT_TASKLET_ENTRY", {.read = lkdtm_debugfs_read,
587 .open = lkdtm_debugfs_open,
588 .write = int_tasklet_entry} },
589 {"FS_DEVRW", {.read = lkdtm_debugfs_read,
590 .open = lkdtm_debugfs_open,
591 .write = fs_devrw_entry} },
592 {"MEM_SWAPOUT", {.read = lkdtm_debugfs_read,
593 .open = lkdtm_debugfs_open,
594 .write = mem_swapout_entry} },
595 {"TIMERADD", {.read = lkdtm_debugfs_read,
596 .open = lkdtm_debugfs_open,
597 .write = timeradd_entry} },
598 {"SCSI_DISPATCH_CMD", {.read = lkdtm_debugfs_read,
599 .open = lkdtm_debugfs_open,
600 .write = scsi_dispatch_cmd_entry} },
601 {"IDE_CORE_CP", {.read = lkdtm_debugfs_read,
602 .open = lkdtm_debugfs_open,
603 .write = ide_core_cp_entry} },
604};
605
606static struct dentry *lkdtm_debugfs_root;
607
608static int __init lkdtm_module_init(void)
609{
610 int ret = -EINVAL;
611 int n_debugfs_entries = 1; /* Assume only the direct entry */
612 int i;
613
614 /* Register debugfs interface */
615 lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL);
616 if (!lkdtm_debugfs_root) {
617 printk(KERN_ERR "lkdtm: creating root dir failed\n");
618 return -ENODEV;
619 }
620
621#ifdef CONFIG_KPROBES
622 n_debugfs_entries = ARRAY_SIZE(crash_entries);
623#endif
624
625 for (i = 0; i < n_debugfs_entries; i++) {
626 const struct crash_entry *cur = &crash_entries[i];
627 struct dentry *de;
628
629 de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root,
630 NULL, &cur->fops);
631 if (de == NULL) {
632 printk(KERN_ERR "lkdtm: could not create %s\n",
633 cur->name);
634 goto out_err;
635 }
636 }
637
638 if (lkdtm_parse_commandline() == -EINVAL) {
639 printk(KERN_INFO "lkdtm: Invalid command\n");
640 goto out_err;
641 }
642
643 if (cpoint != INVALID && cptype != NONE) {
644 ret = lkdtm_register_cpoint(cpoint);
645 if (ret < 0) {
646 printk(KERN_INFO "lkdtm: Invalid crash point %d\n",
647 cpoint);
648 goto out_err;
649 }
650 printk(KERN_INFO "lkdtm: Crash point %s of type %s registered\n",
651 cpoint_name, cpoint_type);
652 } else {
653 printk(KERN_INFO "lkdtm: No crash points registered, enable through debugfs\n");
329 } 654 }
330 655
331 printk(KERN_INFO "lkdtm : Crash point %s of type %s registered\n",
332 cpoint_name, cpoint_type);
333 return 0; 656 return 0;
657
658out_err:
659 debugfs_remove_recursive(lkdtm_debugfs_root);
660 return ret;
334} 661}
335 662
336static void __exit lkdtm_module_exit(void) 663static void __exit lkdtm_module_exit(void)
337{ 664{
338 unregister_jprobe(&lkdtm); 665 debugfs_remove_recursive(lkdtm_debugfs_root);
339 printk(KERN_INFO "lkdtm : Crash point unregistered\n"); 666
667 unregister_jprobe(&lkdtm);
668 printk(KERN_INFO "lkdtm: Crash point unregistered\n");
340} 669}
341 670
342module_init(lkdtm_module_init); 671module_init(lkdtm_module_init);
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 04c27266f567..75ee0d3f6f45 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -21,6 +21,7 @@
21#include <linux/poll.h> 21#include <linux/poll.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/cdev.h> 23#include <linux/cdev.h>
24#include <linux/slab.h>
24#include <linux/phantom.h> 25#include <linux/phantom.h>
25#include <linux/sched.h> 26#include <linux/sched.h>
26#include <linux/smp_lock.h> 27#include <linux/smp_lock.h>
@@ -497,12 +498,7 @@ static struct pci_driver phantom_pci_driver = {
497 .resume = phantom_resume 498 .resume = phantom_resume
498}; 499};
499 500
500static ssize_t phantom_show_version(struct class *cls, char *buf) 501static CLASS_ATTR_STRING(version, 0444, PHANTOM_VERSION);
501{
502 return sprintf(buf, PHANTOM_VERSION "\n");
503}
504
505static CLASS_ATTR(version, 0444, phantom_show_version, NULL);
506 502
507static int __init phantom_init(void) 503static int __init phantom_init(void)
508{ 504{
@@ -515,7 +511,7 @@ static int __init phantom_init(void)
515 printk(KERN_ERR "phantom: can't register phantom class\n"); 511 printk(KERN_ERR "phantom: can't register phantom class\n");
516 goto err; 512 goto err;
517 } 513 }
518 retval = class_create_file(phantom_class, &class_attr_version); 514 retval = class_create_file(phantom_class, &class_attr_version.attr);
519 if (retval) { 515 if (retval) {
520 printk(KERN_ERR "phantom: can't create sysfs version file\n"); 516 printk(KERN_ERR "phantom: can't create sysfs version file\n");
521 goto err_class; 517 goto err_class;
@@ -541,7 +537,7 @@ static int __init phantom_init(void)
541err_unchr: 537err_unchr:
542 unregister_chrdev_region(dev, PHANTOM_MAX_MINORS); 538 unregister_chrdev_region(dev, PHANTOM_MAX_MINORS);
543err_attr: 539err_attr:
544 class_remove_file(phantom_class, &class_attr_version); 540 class_remove_file(phantom_class, &class_attr_version.attr);
545err_class: 541err_class:
546 class_destroy(phantom_class); 542 class_destroy(phantom_class);
547err: 543err:
@@ -554,7 +550,7 @@ static void __exit phantom_exit(void)
554 550
555 unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS); 551 unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS);
556 552
557 class_remove_file(phantom_class, &class_attr_version); 553 class_remove_file(phantom_class, &class_attr_version.attr);
558 class_destroy(phantom_class); 554 class_destroy(phantom_class);
559 555
560 pr_debug("phantom: module successfully removed\n"); 556 pr_debug("phantom: module successfully removed\n");
diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
index 02a77b8b8eef..7a8b9068ea03 100644
--- a/drivers/misc/sgi-gru/grutables.h
+++ b/drivers/misc/sgi-gru/grutables.h
@@ -516,8 +516,7 @@ struct gru_blade_state {
516 516
517/* Scan all active GRUs in a GRU bitmap */ 517/* Scan all active GRUs in a GRU bitmap */
518#define for_each_gru_in_bitmap(gid, map) \ 518#define for_each_gru_in_bitmap(gid, map) \
519 for ((gid) = find_first_bit((map), GRU_MAX_GRUS); (gid) < GRU_MAX_GRUS;\ 519 for_each_set_bit((gid), (map), GRU_MAX_GRUS)
520 (gid)++, (gid) = find_next_bit((map), GRU_MAX_GRUS, (gid)))
521 520
522/* Scan all active GRUs on a specific blade */ 521/* Scan all active GRUs on a specific blade */
523#define for_each_gru_on_blade(gru, nid, i) \ 522#define for_each_gru_on_blade(gru, nid, i) \
@@ -536,23 +535,17 @@ struct gru_blade_state {
536 535
537/* Scan each CBR whose bit is set in a TFM (or copy of) */ 536/* Scan each CBR whose bit is set in a TFM (or copy of) */
538#define for_each_cbr_in_tfm(i, map) \ 537#define for_each_cbr_in_tfm(i, map) \
539 for ((i) = find_first_bit(map, GRU_NUM_CBE); \ 538 for_each_set_bit((i), (map), GRU_NUM_CBE)
540 (i) < GRU_NUM_CBE; \
541 (i)++, (i) = find_next_bit(map, GRU_NUM_CBE, i))
542 539
543/* Scan each CBR in a CBR bitmap. Note: multiple CBRs in an allocation unit */ 540/* Scan each CBR in a CBR bitmap. Note: multiple CBRs in an allocation unit */
544#define for_each_cbr_in_allocation_map(i, map, k) \ 541#define for_each_cbr_in_allocation_map(i, map, k) \
545 for ((k) = find_first_bit(map, GRU_CBR_AU); (k) < GRU_CBR_AU; \ 542 for_each_set_bit((k), (map), GRU_CBR_AU) \
546 (k) = find_next_bit(map, GRU_CBR_AU, (k) + 1)) \
547 for ((i) = (k)*GRU_CBR_AU_SIZE; \ 543 for ((i) = (k)*GRU_CBR_AU_SIZE; \
548 (i) < ((k) + 1) * GRU_CBR_AU_SIZE; (i)++) 544 (i) < ((k) + 1) * GRU_CBR_AU_SIZE; (i)++)
549 545
550/* Scan each DSR in a DSR bitmap. Note: multiple DSRs in an allocation unit */ 546/* Scan each DSR in a DSR bitmap. Note: multiple DSRs in an allocation unit */
551#define for_each_dsr_in_allocation_map(i, map, k) \ 547#define for_each_dsr_in_allocation_map(i, map, k) \
552 for ((k) = find_first_bit((const unsigned long *)map, GRU_DSR_AU);\ 548 for_each_set_bit((k), (const unsigned long *)(map), GRU_DSR_AU) \
553 (k) < GRU_DSR_AU; \
554 (k) = find_next_bit((const unsigned long *)map, \
555 GRU_DSR_AU, (k) + 1)) \
556 for ((i) = (k) * GRU_DSR_AU_CL; \ 549 for ((i) = (k) * GRU_DSR_AU_CL; \
557 (i) < ((k) + 1) * GRU_DSR_AU_CL; (i)++) 550 (i) < ((k) + 1) * GRU_DSR_AU_CL; (i)++)
558 551
diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
index 832ed4c88cf7..8d082b46426b 100644
--- a/drivers/misc/sgi-xp/xpc_main.c
+++ b/drivers/misc/sgi-xp/xpc_main.c
@@ -44,6 +44,7 @@
44 */ 44 */
45 45
46#include <linux/module.h> 46#include <linux/module.h>
47#include <linux/slab.h>
47#include <linux/sysctl.h> 48#include <linux/sysctl.h>
48#include <linux/device.h> 49#include <linux/device.h>
49#include <linux/delay.h> 50#include <linux/delay.h>
diff --git a/drivers/misc/sgi-xp/xpc_partition.c b/drivers/misc/sgi-xp/xpc_partition.c
index 9a6268c89fdd..d551f09ccb79 100644
--- a/drivers/misc/sgi-xp/xpc_partition.c
+++ b/drivers/misc/sgi-xp/xpc_partition.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/device.h> 18#include <linux/device.h>
19#include <linux/hardirq.h> 19#include <linux/hardirq.h>
20#include <linux/slab.h>
20#include "xpc.h" 21#include "xpc.h"
21#include <asm/uv/uv_hub.h> 22#include <asm/uv/uv_hub.h>
22 23
diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
index 8b70e03f939f..7d71c04fc938 100644
--- a/drivers/misc/sgi-xp/xpc_sn2.c
+++ b/drivers/misc/sgi-xp/xpc_sn2.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/slab.h>
17#include <asm/uncached.h> 18#include <asm/uncached.h>
18#include <asm/sn/mspec.h> 19#include <asm/sn/mspec.h>
19#include <asm/sn/sn_sal.h> 20#include <asm/sn/sn_sal.h>
diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
index 8725d5e8ab0c..1f59ee2226ca 100644
--- a/drivers/misc/sgi-xp/xpc_uv.c
+++ b/drivers/misc/sgi-xp/xpc_uv.c
@@ -19,6 +19,7 @@
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/slab.h>
22#include <asm/uv/uv_hub.h> 23#include <asm/uv/uv_hub.h>
23#if defined CONFIG_X86_64 24#if defined CONFIG_X86_64
24#include <asm/uv/bios.h> 25#include <asm/uv/bios.h>
diff --git a/drivers/misc/sgi-xp/xpnet.c b/drivers/misc/sgi-xp/xpnet.c
index 16f0abda1423..ee5109a3cd98 100644
--- a/drivers/misc/sgi-xp/xpnet.c
+++ b/drivers/misc/sgi-xp/xpnet.c
@@ -20,6 +20,7 @@
20 * 20 *
21 */ 21 */
22 22
23#include <linux/slab.h>
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/netdevice.h> 25#include <linux/netdevice.h>
25#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
@@ -475,7 +476,7 @@ xpnet_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
475 476
476 if (skb->data[0] == 0xff) { 477 if (skb->data[0] == 0xff) {
477 /* we are being asked to broadcast to all partitions */ 478 /* we are being asked to broadcast to all partitions */
478 for_each_bit(dest_partid, xpnet_broadcast_partitions, 479 for_each_set_bit(dest_partid, xpnet_broadcast_partitions,
479 xp_max_npartitions) { 480 xp_max_npartitions) {
480 481
481 xpnet_send(skb, queued_msg, start_addr, end_addr, 482 xpnet_send(skb, queued_msg, start_addr, end_addr,
diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c
index 98bcba521da2..5f6852dff40b 100644
--- a/drivers/misc/tifm_core.c
+++ b/drivers/misc/tifm_core.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/tifm.h> 12#include <linux/tifm.h>
13#include <linux/slab.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/idr.h> 15#include <linux/idr.h>
15 16
diff --git a/drivers/misc/tsl2550.c b/drivers/misc/tsl2550.c
new file mode 100644
index 000000000000..483ae5f7f68e
--- /dev/null
+++ b/drivers/misc/tsl2550.c
@@ -0,0 +1,473 @@
1/*
2 * tsl2550.c - Linux kernel modules for ambient light sensor
3 *
4 * Copyright (C) 2007 Rodolfo Giometti <giometti@linux.it>
5 * Copyright (C) 2007 Eurotech S.p.A. <info@eurotech.it>
6 *
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
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
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
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/i2c.h>
26#include <linux/mutex.h>
27
28#define TSL2550_DRV_NAME "tsl2550"
29#define DRIVER_VERSION "1.2"
30
31/*
32 * Defines
33 */
34
35#define TSL2550_POWER_DOWN 0x00
36#define TSL2550_POWER_UP 0x03
37#define TSL2550_STANDARD_RANGE 0x18
38#define TSL2550_EXTENDED_RANGE 0x1d
39#define TSL2550_READ_ADC0 0x43
40#define TSL2550_READ_ADC1 0x83
41
42/*
43 * Structs
44 */
45
46struct tsl2550_data {
47 struct i2c_client *client;
48 struct mutex update_lock;
49
50 unsigned int power_state:1;
51 unsigned int operating_mode:1;
52};
53
54/*
55 * Global data
56 */
57
58static const u8 TSL2550_MODE_RANGE[2] = {
59 TSL2550_STANDARD_RANGE, TSL2550_EXTENDED_RANGE,
60};
61
62/*
63 * Management functions
64 */
65
66static int tsl2550_set_operating_mode(struct i2c_client *client, int mode)
67{
68 struct tsl2550_data *data = i2c_get_clientdata(client);
69
70 int ret = i2c_smbus_write_byte(client, TSL2550_MODE_RANGE[mode]);
71
72 data->operating_mode = mode;
73
74 return ret;
75}
76
77static int tsl2550_set_power_state(struct i2c_client *client, int state)
78{
79 struct tsl2550_data *data = i2c_get_clientdata(client);
80 int ret;
81
82 if (state == 0)
83 ret = i2c_smbus_write_byte(client, TSL2550_POWER_DOWN);
84 else {
85 ret = i2c_smbus_write_byte(client, TSL2550_POWER_UP);
86
87 /* On power up we should reset operating mode also... */
88 tsl2550_set_operating_mode(client, data->operating_mode);
89 }
90
91 data->power_state = state;
92
93 return ret;
94}
95
96static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd)
97{
98 int ret;
99
100 ret = i2c_smbus_read_byte_data(client, cmd);
101 if (ret < 0)
102 return ret;
103 if (!(ret & 0x80))
104 return -EAGAIN;
105 return ret & 0x7f; /* remove the "valid" bit */
106}
107
108/*
109 * LUX calculation
110 */
111
112#define TSL2550_MAX_LUX 1846
113
114static const u8 ratio_lut[] = {
115 100, 100, 100, 100, 100, 100, 100, 100,
116 100, 100, 100, 100, 100, 100, 99, 99,
117 99, 99, 99, 99, 99, 99, 99, 99,
118 99, 99, 99, 98, 98, 98, 98, 98,
119 98, 98, 97, 97, 97, 97, 97, 96,
120 96, 96, 96, 95, 95, 95, 94, 94,
121 93, 93, 93, 92, 92, 91, 91, 90,
122 89, 89, 88, 87, 87, 86, 85, 84,
123 83, 82, 81, 80, 79, 78, 77, 75,
124 74, 73, 71, 69, 68, 66, 64, 62,
125 60, 58, 56, 54, 52, 49, 47, 44,
126 42, 41, 40, 40, 39, 39, 38, 38,
127 37, 37, 37, 36, 36, 36, 35, 35,
128 35, 35, 34, 34, 34, 34, 33, 33,
129 33, 33, 32, 32, 32, 32, 32, 31,
130 31, 31, 31, 31, 30, 30, 30, 30,
131 30,
132};
133
134static const u16 count_lut[] = {
135 0, 1, 2, 3, 4, 5, 6, 7,
136 8, 9, 10, 11, 12, 13, 14, 15,
137 16, 18, 20, 22, 24, 26, 28, 30,
138 32, 34, 36, 38, 40, 42, 44, 46,
139 49, 53, 57, 61, 65, 69, 73, 77,
140 81, 85, 89, 93, 97, 101, 105, 109,
141 115, 123, 131, 139, 147, 155, 163, 171,
142 179, 187, 195, 203, 211, 219, 227, 235,
143 247, 263, 279, 295, 311, 327, 343, 359,
144 375, 391, 407, 423, 439, 455, 471, 487,
145 511, 543, 575, 607, 639, 671, 703, 735,
146 767, 799, 831, 863, 895, 927, 959, 991,
147 1039, 1103, 1167, 1231, 1295, 1359, 1423, 1487,
148 1551, 1615, 1679, 1743, 1807, 1871, 1935, 1999,
149 2095, 2223, 2351, 2479, 2607, 2735, 2863, 2991,
150 3119, 3247, 3375, 3503, 3631, 3759, 3887, 4015,
151};
152
153/*
154 * This function is described into Taos TSL2550 Designer's Notebook
155 * pages 2, 3.
156 */
157static int tsl2550_calculate_lux(u8 ch0, u8 ch1)
158{
159 unsigned int lux;
160
161 /* Look up count from channel values */
162 u16 c0 = count_lut[ch0];
163 u16 c1 = count_lut[ch1];
164
165 /*
166 * Calculate ratio.
167 * Note: the "128" is a scaling factor
168 */
169 u8 r = 128;
170
171 /* Avoid division by 0 and count 1 cannot be greater than count 0 */
172 if (c1 <= c0)
173 if (c0) {
174 r = c1 * 128 / c0;
175
176 /* Calculate LUX */
177 lux = ((c0 - c1) * ratio_lut[r]) / 256;
178 } else
179 lux = 0;
180 else
181 return -EAGAIN;
182
183 /* LUX range check */
184 return lux > TSL2550_MAX_LUX ? TSL2550_MAX_LUX : lux;
185}
186
187/*
188 * SysFS support
189 */
190
191static ssize_t tsl2550_show_power_state(struct device *dev,
192 struct device_attribute *attr, char *buf)
193{
194 struct tsl2550_data *data = i2c_get_clientdata(to_i2c_client(dev));
195
196 return sprintf(buf, "%u\n", data->power_state);
197}
198
199static ssize_t tsl2550_store_power_state(struct device *dev,
200 struct device_attribute *attr, const char *buf, size_t count)
201{
202 struct i2c_client *client = to_i2c_client(dev);
203 struct tsl2550_data *data = i2c_get_clientdata(client);
204 unsigned long val = simple_strtoul(buf, NULL, 10);
205 int ret;
206
207 if (val < 0 || val > 1)
208 return -EINVAL;
209
210 mutex_lock(&data->update_lock);
211 ret = tsl2550_set_power_state(client, val);
212 mutex_unlock(&data->update_lock);
213
214 if (ret < 0)
215 return ret;
216
217 return count;
218}
219
220static DEVICE_ATTR(power_state, S_IWUSR | S_IRUGO,
221 tsl2550_show_power_state, tsl2550_store_power_state);
222
223static ssize_t tsl2550_show_operating_mode(struct device *dev,
224 struct device_attribute *attr, char *buf)
225{
226 struct tsl2550_data *data = i2c_get_clientdata(to_i2c_client(dev));
227
228 return sprintf(buf, "%u\n", data->operating_mode);
229}
230
231static ssize_t tsl2550_store_operating_mode(struct device *dev,
232 struct device_attribute *attr, const char *buf, size_t count)
233{
234 struct i2c_client *client = to_i2c_client(dev);
235 struct tsl2550_data *data = i2c_get_clientdata(client);
236 unsigned long val = simple_strtoul(buf, NULL, 10);
237 int ret;
238
239 if (val < 0 || val > 1)
240 return -EINVAL;
241
242 if (data->power_state == 0)
243 return -EBUSY;
244
245 mutex_lock(&data->update_lock);
246 ret = tsl2550_set_operating_mode(client, val);
247 mutex_unlock(&data->update_lock);
248
249 if (ret < 0)
250 return ret;
251
252 return count;
253}
254
255static DEVICE_ATTR(operating_mode, S_IWUSR | S_IRUGO,
256 tsl2550_show_operating_mode, tsl2550_store_operating_mode);
257
258static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf)
259{
260 struct tsl2550_data *data = i2c_get_clientdata(client);
261 u8 ch0, ch1;
262 int ret;
263
264 ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC0);
265 if (ret < 0)
266 return ret;
267 ch0 = ret;
268
269 ret = tsl2550_get_adc_value(client, TSL2550_READ_ADC1);
270 if (ret < 0)
271 return ret;
272 ch1 = ret;
273
274 /* Do the job */
275 ret = tsl2550_calculate_lux(ch0, ch1);
276 if (ret < 0)
277 return ret;
278 if (data->operating_mode == 1)
279 ret *= 5;
280
281 return sprintf(buf, "%d\n", ret);
282}
283
284static ssize_t tsl2550_show_lux1_input(struct device *dev,
285 struct device_attribute *attr, char *buf)
286{
287 struct i2c_client *client = to_i2c_client(dev);
288 struct tsl2550_data *data = i2c_get_clientdata(client);
289 int ret;
290
291 /* No LUX data if not operational */
292 if (!data->power_state)
293 return -EBUSY;
294
295 mutex_lock(&data->update_lock);
296 ret = __tsl2550_show_lux(client, buf);
297 mutex_unlock(&data->update_lock);
298
299 return ret;
300}
301
302static DEVICE_ATTR(lux1_input, S_IRUGO,
303 tsl2550_show_lux1_input, NULL);
304
305static struct attribute *tsl2550_attributes[] = {
306 &dev_attr_power_state.attr,
307 &dev_attr_operating_mode.attr,
308 &dev_attr_lux1_input.attr,
309 NULL
310};
311
312static const struct attribute_group tsl2550_attr_group = {
313 .attrs = tsl2550_attributes,
314};
315
316/*
317 * Initialization function
318 */
319
320static int tsl2550_init_client(struct i2c_client *client)
321{
322 struct tsl2550_data *data = i2c_get_clientdata(client);
323 int err;
324
325 /*
326 * Probe the chip. To do so we try to power up the device and then to
327 * read back the 0x03 code
328 */
329 err = i2c_smbus_read_byte_data(client, TSL2550_POWER_UP);
330 if (err < 0)
331 return err;
332 if (err != TSL2550_POWER_UP)
333 return -ENODEV;
334 data->power_state = 1;
335
336 /* Set the default operating mode */
337 err = i2c_smbus_write_byte(client,
338 TSL2550_MODE_RANGE[data->operating_mode]);
339 if (err < 0)
340 return err;
341
342 return 0;
343}
344
345/*
346 * I2C init/probing/exit functions
347 */
348
349static struct i2c_driver tsl2550_driver;
350static int __devinit tsl2550_probe(struct i2c_client *client,
351 const struct i2c_device_id *id)
352{
353 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
354 struct tsl2550_data *data;
355 int *opmode, err = 0;
356
357 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE
358 | I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
359 err = -EIO;
360 goto exit;
361 }
362
363 data = kzalloc(sizeof(struct tsl2550_data), GFP_KERNEL);
364 if (!data) {
365 err = -ENOMEM;
366 goto exit;
367 }
368 data->client = client;
369 i2c_set_clientdata(client, data);
370
371 /* Check platform data */
372 opmode = client->dev.platform_data;
373 if (opmode) {
374 if (*opmode < 0 || *opmode > 1) {
375 dev_err(&client->dev, "invalid operating_mode (%d)\n",
376 *opmode);
377 err = -EINVAL;
378 goto exit_kfree;
379 }
380 data->operating_mode = *opmode;
381 } else
382 data->operating_mode = 0; /* default mode is standard */
383 dev_info(&client->dev, "%s operating mode\n",
384 data->operating_mode ? "extended" : "standard");
385
386 mutex_init(&data->update_lock);
387
388 /* Initialize the TSL2550 chip */
389 err = tsl2550_init_client(client);
390 if (err)
391 goto exit_kfree;
392
393 /* Register sysfs hooks */
394 err = sysfs_create_group(&client->dev.kobj, &tsl2550_attr_group);
395 if (err)
396 goto exit_kfree;
397
398 dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);
399
400 return 0;
401
402exit_kfree:
403 kfree(data);
404exit:
405 return err;
406}
407
408static int __devexit tsl2550_remove(struct i2c_client *client)
409{
410 sysfs_remove_group(&client->dev.kobj, &tsl2550_attr_group);
411
412 /* Power down the device */
413 tsl2550_set_power_state(client, 0);
414
415 kfree(i2c_get_clientdata(client));
416
417 return 0;
418}
419
420#ifdef CONFIG_PM
421
422static int tsl2550_suspend(struct i2c_client *client, pm_message_t mesg)
423{
424 return tsl2550_set_power_state(client, 0);
425}
426
427static int tsl2550_resume(struct i2c_client *client)
428{
429 return tsl2550_set_power_state(client, 1);
430}
431
432#else
433
434#define tsl2550_suspend NULL
435#define tsl2550_resume NULL
436
437#endif /* CONFIG_PM */
438
439static const struct i2c_device_id tsl2550_id[] = {
440 { "tsl2550", 0 },
441 { }
442};
443MODULE_DEVICE_TABLE(i2c, tsl2550_id);
444
445static struct i2c_driver tsl2550_driver = {
446 .driver = {
447 .name = TSL2550_DRV_NAME,
448 .owner = THIS_MODULE,
449 },
450 .suspend = tsl2550_suspend,
451 .resume = tsl2550_resume,
452 .probe = tsl2550_probe,
453 .remove = __devexit_p(tsl2550_remove),
454 .id_table = tsl2550_id,
455};
456
457static int __init tsl2550_init(void)
458{
459 return i2c_add_driver(&tsl2550_driver);
460}
461
462static void __exit tsl2550_exit(void)
463{
464 i2c_del_driver(&tsl2550_driver);
465}
466
467MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
468MODULE_DESCRIPTION("TSL2550 ambient light sensor driver");
469MODULE_LICENSE("GPL");
470MODULE_VERSION(DRIVER_VERSION);
471
472module_init(tsl2550_init);
473module_exit(tsl2550_exit);
diff --git a/drivers/misc/vmware_balloon.c b/drivers/misc/vmware_balloon.c
new file mode 100644
index 000000000000..2a1e804a71aa
--- /dev/null
+++ b/drivers/misc/vmware_balloon.c
@@ -0,0 +1,844 @@
1/*
2 * VMware Balloon driver.
3 *
4 * Copyright (C) 2000-2010, VMware, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Maintained by: Dmitry Torokhov <dtor@vmware.com>
21 */
22
23/*
24 * This is VMware physical memory management driver for Linux. The driver
25 * acts like a "balloon" that can be inflated to reclaim physical pages by
26 * reserving them in the guest and invalidating them in the monitor,
27 * freeing up the underlying machine pages so they can be allocated to
28 * other guests. The balloon can also be deflated to allow the guest to
29 * use more physical memory. Higher level policies can control the sizes
30 * of balloons in VMs in order to manage physical memory resources.
31 */
32
33//#define DEBUG
34#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35
36#include <linux/types.h>
37#include <linux/kernel.h>
38#include <linux/mm.h>
39#include <linux/sched.h>
40#include <linux/module.h>
41#include <linux/workqueue.h>
42#include <linux/debugfs.h>
43#include <linux/seq_file.h>
44#include <asm/hypervisor.h>
45
46MODULE_AUTHOR("VMware, Inc.");
47MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
48MODULE_VERSION("1.2.1.1-k");
49MODULE_ALIAS("dmi:*:svnVMware*:*");
50MODULE_ALIAS("vmware_vmmemctl");
51MODULE_LICENSE("GPL");
52
53/*
54 * Various constants controlling rate of inflaint/deflating balloon,
55 * measured in pages.
56 */
57
58/*
59 * Rate of allocating memory when there is no memory pressure
60 * (driver performs non-sleeping allocations).
61 */
62#define VMW_BALLOON_NOSLEEP_ALLOC_MAX 16384U
63
64/*
65 * Rates of memory allocaton when guest experiences memory pressure
66 * (driver performs sleeping allocations).
67 */
68#define VMW_BALLOON_RATE_ALLOC_MIN 512U
69#define VMW_BALLOON_RATE_ALLOC_MAX 2048U
70#define VMW_BALLOON_RATE_ALLOC_INC 16U
71
72/*
73 * Rates for releasing pages while deflating balloon.
74 */
75#define VMW_BALLOON_RATE_FREE_MIN 512U
76#define VMW_BALLOON_RATE_FREE_MAX 16384U
77#define VMW_BALLOON_RATE_FREE_INC 16U
78
79/*
80 * When guest is under memory pressure, use a reduced page allocation
81 * rate for next several cycles.
82 */
83#define VMW_BALLOON_SLOW_CYCLES 4
84
85/*
86 * Use __GFP_HIGHMEM to allow pages from HIGHMEM zone. We don't
87 * allow wait (__GFP_WAIT) for NOSLEEP page allocations. Use
88 * __GFP_NOWARN, to suppress page allocation failure warnings.
89 */
90#define VMW_PAGE_ALLOC_NOSLEEP (__GFP_HIGHMEM|__GFP_NOWARN)
91
92/*
93 * Use GFP_HIGHUSER when executing in a separate kernel thread
94 * context and allocation can sleep. This is less stressful to
95 * the guest memory system, since it allows the thread to block
96 * while memory is reclaimed, and won't take pages from emergency
97 * low-memory pools.
98 */
99#define VMW_PAGE_ALLOC_CANSLEEP (GFP_HIGHUSER)
100
101/* Maximum number of page allocations without yielding processor */
102#define VMW_BALLOON_YIELD_THRESHOLD 1024
103
104/* Maximum number of refused pages we accumulate during inflation cycle */
105#define VMW_BALLOON_MAX_REFUSED 16
106
107/*
108 * Hypervisor communication port definitions.
109 */
110#define VMW_BALLOON_HV_PORT 0x5670
111#define VMW_BALLOON_HV_MAGIC 0x456c6d6f
112#define VMW_BALLOON_PROTOCOL_VERSION 2
113#define VMW_BALLOON_GUEST_ID 1 /* Linux */
114
115#define VMW_BALLOON_CMD_START 0
116#define VMW_BALLOON_CMD_GET_TARGET 1
117#define VMW_BALLOON_CMD_LOCK 2
118#define VMW_BALLOON_CMD_UNLOCK 3
119#define VMW_BALLOON_CMD_GUEST_ID 4
120
121/* error codes */
122#define VMW_BALLOON_SUCCESS 0
123#define VMW_BALLOON_FAILURE -1
124#define VMW_BALLOON_ERROR_CMD_INVALID 1
125#define VMW_BALLOON_ERROR_PPN_INVALID 2
126#define VMW_BALLOON_ERROR_PPN_LOCKED 3
127#define VMW_BALLOON_ERROR_PPN_UNLOCKED 4
128#define VMW_BALLOON_ERROR_PPN_PINNED 5
129#define VMW_BALLOON_ERROR_PPN_NOTNEEDED 6
130#define VMW_BALLOON_ERROR_RESET 7
131#define VMW_BALLOON_ERROR_BUSY 8
132
133#define VMWARE_BALLOON_CMD(cmd, data, result) \
134({ \
135 unsigned long __stat, __dummy1, __dummy2; \
136 __asm__ __volatile__ ("inl (%%dx)" : \
137 "=a"(__stat), \
138 "=c"(__dummy1), \
139 "=d"(__dummy2), \
140 "=b"(result) : \
141 "0"(VMW_BALLOON_HV_MAGIC), \
142 "1"(VMW_BALLOON_CMD_##cmd), \
143 "2"(VMW_BALLOON_HV_PORT), \
144 "3"(data) : \
145 "memory"); \
146 result &= -1UL; \
147 __stat & -1UL; \
148})
149
150#ifdef CONFIG_DEBUG_FS
151struct vmballoon_stats {
152 unsigned int timer;
153
154 /* allocation statustics */
155 unsigned int alloc;
156 unsigned int alloc_fail;
157 unsigned int sleep_alloc;
158 unsigned int sleep_alloc_fail;
159 unsigned int refused_alloc;
160 unsigned int refused_free;
161 unsigned int free;
162
163 /* monitor operations */
164 unsigned int lock;
165 unsigned int lock_fail;
166 unsigned int unlock;
167 unsigned int unlock_fail;
168 unsigned int target;
169 unsigned int target_fail;
170 unsigned int start;
171 unsigned int start_fail;
172 unsigned int guest_type;
173 unsigned int guest_type_fail;
174};
175
176#define STATS_INC(stat) (stat)++
177#else
178#define STATS_INC(stat)
179#endif
180
181struct vmballoon {
182
183 /* list of reserved physical pages */
184 struct list_head pages;
185
186 /* transient list of non-balloonable pages */
187 struct list_head refused_pages;
188 unsigned int n_refused_pages;
189
190 /* balloon size in pages */
191 unsigned int size;
192 unsigned int target;
193
194 /* reset flag */
195 bool reset_required;
196
197 /* adjustment rates (pages per second) */
198 unsigned int rate_alloc;
199 unsigned int rate_free;
200
201 /* slowdown page allocations for next few cycles */
202 unsigned int slow_allocation_cycles;
203
204#ifdef CONFIG_DEBUG_FS
205 /* statistics */
206 struct vmballoon_stats stats;
207
208 /* debugfs file exporting statistics */
209 struct dentry *dbg_entry;
210#endif
211
212 struct sysinfo sysinfo;
213
214 struct delayed_work dwork;
215};
216
217static struct vmballoon balloon;
218static struct workqueue_struct *vmballoon_wq;
219
220/*
221 * Send "start" command to the host, communicating supported version
222 * of the protocol.
223 */
224static bool vmballoon_send_start(struct vmballoon *b)
225{
226 unsigned long status, dummy;
227
228 STATS_INC(b->stats.start);
229
230 status = VMWARE_BALLOON_CMD(START, VMW_BALLOON_PROTOCOL_VERSION, dummy);
231 if (status == VMW_BALLOON_SUCCESS)
232 return true;
233
234 pr_debug("%s - failed, hv returns %ld\n", __func__, status);
235 STATS_INC(b->stats.start_fail);
236 return false;
237}
238
239static bool vmballoon_check_status(struct vmballoon *b, unsigned long status)
240{
241 switch (status) {
242 case VMW_BALLOON_SUCCESS:
243 return true;
244
245 case VMW_BALLOON_ERROR_RESET:
246 b->reset_required = true;
247 /* fall through */
248
249 default:
250 return false;
251 }
252}
253
254/*
255 * Communicate guest type to the host so that it can adjust ballooning
256 * algorithm to the one most appropriate for the guest. This command
257 * is normally issued after sending "start" command and is part of
258 * standard reset sequence.
259 */
260static bool vmballoon_send_guest_id(struct vmballoon *b)
261{
262 unsigned long status, dummy;
263
264 status = VMWARE_BALLOON_CMD(GUEST_ID, VMW_BALLOON_GUEST_ID, dummy);
265
266 STATS_INC(b->stats.guest_type);
267
268 if (vmballoon_check_status(b, status))
269 return true;
270
271 pr_debug("%s - failed, hv returns %ld\n", __func__, status);
272 STATS_INC(b->stats.guest_type_fail);
273 return false;
274}
275
276/*
277 * Retrieve desired balloon size from the host.
278 */
279static bool vmballoon_send_get_target(struct vmballoon *b, u32 *new_target)
280{
281 unsigned long status;
282 unsigned long target;
283 unsigned long limit;
284 u32 limit32;
285
286 /*
287 * si_meminfo() is cheap. Moreover, we want to provide dynamic
288 * max balloon size later. So let us call si_meminfo() every
289 * iteration.
290 */
291 si_meminfo(&b->sysinfo);
292 limit = b->sysinfo.totalram;
293
294 /* Ensure limit fits in 32-bits */
295 limit32 = (u32)limit;
296 if (limit != limit32)
297 return false;
298
299 /* update stats */
300 STATS_INC(b->stats.target);
301
302 status = VMWARE_BALLOON_CMD(GET_TARGET, limit, target);
303 if (vmballoon_check_status(b, status)) {
304 *new_target = target;
305 return true;
306 }
307
308 pr_debug("%s - failed, hv returns %ld\n", __func__, status);
309 STATS_INC(b->stats.target_fail);
310 return false;
311}
312
313/*
314 * Notify the host about allocated page so that host can use it without
315 * fear that guest will need it. Host may reject some pages, we need to
316 * check the return value and maybe submit a different page.
317 */
318static bool vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn)
319{
320 unsigned long status, dummy;
321 u32 pfn32;
322
323 pfn32 = (u32)pfn;
324 if (pfn32 != pfn)
325 return false;
326
327 STATS_INC(b->stats.lock);
328
329 status = VMWARE_BALLOON_CMD(LOCK, pfn, dummy);
330 if (vmballoon_check_status(b, status))
331 return true;
332
333 pr_debug("%s - ppn %lx, hv returns %ld\n", __func__, pfn, status);
334 STATS_INC(b->stats.lock_fail);
335 return false;
336}
337
338/*
339 * Notify the host that guest intends to release given page back into
340 * the pool of available (to the guest) pages.
341 */
342static bool vmballoon_send_unlock_page(struct vmballoon *b, unsigned long pfn)
343{
344 unsigned long status, dummy;
345 u32 pfn32;
346
347 pfn32 = (u32)pfn;
348 if (pfn32 != pfn)
349 return false;
350
351 STATS_INC(b->stats.unlock);
352
353 status = VMWARE_BALLOON_CMD(UNLOCK, pfn, dummy);
354 if (vmballoon_check_status(b, status))
355 return true;
356
357 pr_debug("%s - ppn %lx, hv returns %ld\n", __func__, pfn, status);
358 STATS_INC(b->stats.unlock_fail);
359 return false;
360}
361
362/*
363 * Quickly release all pages allocated for the balloon. This function is
364 * called when host decides to "reset" balloon for one reason or another.
365 * Unlike normal "deflate" we do not (shall not) notify host of the pages
366 * being released.
367 */
368static void vmballoon_pop(struct vmballoon *b)
369{
370 struct page *page, *next;
371 unsigned int count = 0;
372
373 list_for_each_entry_safe(page, next, &b->pages, lru) {
374 list_del(&page->lru);
375 __free_page(page);
376 STATS_INC(b->stats.free);
377 b->size--;
378
379 if (++count >= b->rate_free) {
380 count = 0;
381 cond_resched();
382 }
383 }
384}
385
386/*
387 * Perform standard reset sequence by popping the balloon (in case it
388 * is not empty) and then restarting protocol. This operation normally
389 * happens when host responds with VMW_BALLOON_ERROR_RESET to a command.
390 */
391static void vmballoon_reset(struct vmballoon *b)
392{
393 /* free all pages, skipping monitor unlock */
394 vmballoon_pop(b);
395
396 if (vmballoon_send_start(b)) {
397 b->reset_required = false;
398 if (!vmballoon_send_guest_id(b))
399 pr_err("failed to send guest ID to the host\n");
400 }
401}
402
403/*
404 * Allocate (or reserve) a page for the balloon and notify the host. If host
405 * refuses the page put it on "refuse" list and allocate another one until host
406 * is satisfied. "Refused" pages are released at the end of inflation cycle
407 * (when we allocate b->rate_alloc pages).
408 */
409static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
410{
411 struct page *page;
412 gfp_t flags;
413 bool locked = false;
414
415 do {
416 if (!can_sleep)
417 STATS_INC(b->stats.alloc);
418 else
419 STATS_INC(b->stats.sleep_alloc);
420
421 flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
422 page = alloc_page(flags);
423 if (!page) {
424 if (!can_sleep)
425 STATS_INC(b->stats.alloc_fail);
426 else
427 STATS_INC(b->stats.sleep_alloc_fail);
428 return -ENOMEM;
429 }
430
431 /* inform monitor */
432 locked = vmballoon_send_lock_page(b, page_to_pfn(page));
433 if (!locked) {
434 STATS_INC(b->stats.refused_alloc);
435
436 if (b->reset_required) {
437 __free_page(page);
438 return -EIO;
439 }
440
441 /*
442 * Place page on the list of non-balloonable pages
443 * and retry allocation, unless we already accumulated
444 * too many of them, in which case take a breather.
445 */
446 list_add(&page->lru, &b->refused_pages);
447 if (++b->n_refused_pages >= VMW_BALLOON_MAX_REFUSED)
448 return -EIO;
449 }
450 } while (!locked);
451
452 /* track allocated page */
453 list_add(&page->lru, &b->pages);
454
455 /* update balloon size */
456 b->size++;
457
458 return 0;
459}
460
461/*
462 * Release the page allocated for the balloon. Note that we first notify
463 * the host so it can make sure the page will be available for the guest
464 * to use, if needed.
465 */
466static int vmballoon_release_page(struct vmballoon *b, struct page *page)
467{
468 if (!vmballoon_send_unlock_page(b, page_to_pfn(page)))
469 return -EIO;
470
471 list_del(&page->lru);
472
473 /* deallocate page */
474 __free_page(page);
475 STATS_INC(b->stats.free);
476
477 /* update balloon size */
478 b->size--;
479
480 return 0;
481}
482
483/*
484 * Release pages that were allocated while attempting to inflate the
485 * balloon but were refused by the host for one reason or another.
486 */
487static void vmballoon_release_refused_pages(struct vmballoon *b)
488{
489 struct page *page, *next;
490
491 list_for_each_entry_safe(page, next, &b->refused_pages, lru) {
492 list_del(&page->lru);
493 __free_page(page);
494 STATS_INC(b->stats.refused_free);
495 }
496
497 b->n_refused_pages = 0;
498}
499
500/*
501 * Inflate the balloon towards its target size. Note that we try to limit
502 * the rate of allocation to make sure we are not choking the rest of the
503 * system.
504 */
505static void vmballoon_inflate(struct vmballoon *b)
506{
507 unsigned int goal;
508 unsigned int rate;
509 unsigned int i;
510 unsigned int allocations = 0;
511 int error = 0;
512 bool alloc_can_sleep = false;
513
514 pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
515
516 /*
517 * First try NOSLEEP page allocations to inflate balloon.
518 *
519 * If we do not throttle nosleep allocations, we can drain all
520 * free pages in the guest quickly (if the balloon target is high).
521 * As a side-effect, draining free pages helps to inform (force)
522 * the guest to start swapping if balloon target is not met yet,
523 * which is a desired behavior. However, balloon driver can consume
524 * all available CPU cycles if too many pages are allocated in a
525 * second. Therefore, we throttle nosleep allocations even when
526 * the guest is not under memory pressure. OTOH, if we have already
527 * predicted that the guest is under memory pressure, then we
528 * slowdown page allocations considerably.
529 */
530
531 goal = b->target - b->size;
532 /*
533 * Start with no sleep allocation rate which may be higher
534 * than sleeping allocation rate.
535 */
536 rate = b->slow_allocation_cycles ?
537 b->rate_alloc : VMW_BALLOON_NOSLEEP_ALLOC_MAX;
538
539 pr_debug("%s - goal: %d, no-sleep rate: %d, sleep rate: %d\n",
540 __func__, goal, rate, b->rate_alloc);
541
542 for (i = 0; i < goal; i++) {
543
544 error = vmballoon_reserve_page(b, alloc_can_sleep);
545 if (error) {
546 if (error != -ENOMEM) {
547 /*
548 * Not a page allocation failure, stop this
549 * cycle. Maybe we'll get new target from
550 * the host soon.
551 */
552 break;
553 }
554
555 if (alloc_can_sleep) {
556 /*
557 * CANSLEEP page allocation failed, so guest
558 * is under severe memory pressure. Quickly
559 * decrease allocation rate.
560 */
561 b->rate_alloc = max(b->rate_alloc / 2,
562 VMW_BALLOON_RATE_ALLOC_MIN);
563 break;
564 }
565
566 /*
567 * NOSLEEP page allocation failed, so the guest is
568 * under memory pressure. Let us slow down page
569 * allocations for next few cycles so that the guest
570 * gets out of memory pressure. Also, if we already
571 * allocated b->rate_alloc pages, let's pause,
572 * otherwise switch to sleeping allocations.
573 */
574 b->slow_allocation_cycles = VMW_BALLOON_SLOW_CYCLES;
575
576 if (i >= b->rate_alloc)
577 break;
578
579 alloc_can_sleep = true;
580 /* Lower rate for sleeping allocations. */
581 rate = b->rate_alloc;
582 }
583
584 if (++allocations > VMW_BALLOON_YIELD_THRESHOLD) {
585 cond_resched();
586 allocations = 0;
587 }
588
589 if (i >= rate) {
590 /* We allocated enough pages, let's take a break. */
591 break;
592 }
593 }
594
595 /*
596 * We reached our goal without failures so try increasing
597 * allocation rate.
598 */
599 if (error == 0 && i >= b->rate_alloc) {
600 unsigned int mult = i / b->rate_alloc;
601
602 b->rate_alloc =
603 min(b->rate_alloc + mult * VMW_BALLOON_RATE_ALLOC_INC,
604 VMW_BALLOON_RATE_ALLOC_MAX);
605 }
606
607 vmballoon_release_refused_pages(b);
608}
609
610/*
611 * Decrease the size of the balloon allowing guest to use more memory.
612 */
613static void vmballoon_deflate(struct vmballoon *b)
614{
615 struct page *page, *next;
616 unsigned int i = 0;
617 unsigned int goal;
618 int error;
619
620 pr_debug("%s - size: %d, target %d\n", __func__, b->size, b->target);
621
622 /* limit deallocation rate */
623 goal = min(b->size - b->target, b->rate_free);
624
625 pr_debug("%s - goal: %d, rate: %d\n", __func__, goal, b->rate_free);
626
627 /* free pages to reach target */
628 list_for_each_entry_safe(page, next, &b->pages, lru) {
629 error = vmballoon_release_page(b, page);
630 if (error) {
631 /* quickly decrease rate in case of error */
632 b->rate_free = max(b->rate_free / 2,
633 VMW_BALLOON_RATE_FREE_MIN);
634 return;
635 }
636
637 if (++i >= goal)
638 break;
639 }
640
641 /* slowly increase rate if there were no errors */
642 b->rate_free = min(b->rate_free + VMW_BALLOON_RATE_FREE_INC,
643 VMW_BALLOON_RATE_FREE_MAX);
644}
645
646/*
647 * Balloon work function: reset protocol, if needed, get the new size and
648 * adjust balloon as needed. Repeat in 1 sec.
649 */
650static void vmballoon_work(struct work_struct *work)
651{
652 struct delayed_work *dwork = to_delayed_work(work);
653 struct vmballoon *b = container_of(dwork, struct vmballoon, dwork);
654 unsigned int target;
655
656 STATS_INC(b->stats.timer);
657
658 if (b->reset_required)
659 vmballoon_reset(b);
660
661 if (b->slow_allocation_cycles > 0)
662 b->slow_allocation_cycles--;
663
664 if (vmballoon_send_get_target(b, &target)) {
665 /* update target, adjust size */
666 b->target = target;
667
668 if (b->size < target)
669 vmballoon_inflate(b);
670 else if (b->size > target)
671 vmballoon_deflate(b);
672 }
673
674 queue_delayed_work(vmballoon_wq, dwork, round_jiffies_relative(HZ));
675}
676
677/*
678 * DEBUGFS Interface
679 */
680#ifdef CONFIG_DEBUG_FS
681
682static int vmballoon_debug_show(struct seq_file *f, void *offset)
683{
684 struct vmballoon *b = f->private;
685 struct vmballoon_stats *stats = &b->stats;
686
687 /* format size info */
688 seq_printf(f,
689 "target: %8d pages\n"
690 "current: %8d pages\n",
691 b->target, b->size);
692
693 /* format rate info */
694 seq_printf(f,
695 "rateNoSleepAlloc: %8d pages/sec\n"
696 "rateSleepAlloc: %8d pages/sec\n"
697 "rateFree: %8d pages/sec\n",
698 VMW_BALLOON_NOSLEEP_ALLOC_MAX,
699 b->rate_alloc, b->rate_free);
700
701 seq_printf(f,
702 "\n"
703 "timer: %8u\n"
704 "start: %8u (%4u failed)\n"
705 "guestType: %8u (%4u failed)\n"
706 "lock: %8u (%4u failed)\n"
707 "unlock: %8u (%4u failed)\n"
708 "target: %8u (%4u failed)\n"
709 "primNoSleepAlloc: %8u (%4u failed)\n"
710 "primCanSleepAlloc: %8u (%4u failed)\n"
711 "primFree: %8u\n"
712 "errAlloc: %8u\n"
713 "errFree: %8u\n",
714 stats->timer,
715 stats->start, stats->start_fail,
716 stats->guest_type, stats->guest_type_fail,
717 stats->lock, stats->lock_fail,
718 stats->unlock, stats->unlock_fail,
719 stats->target, stats->target_fail,
720 stats->alloc, stats->alloc_fail,
721 stats->sleep_alloc, stats->sleep_alloc_fail,
722 stats->free,
723 stats->refused_alloc, stats->refused_free);
724
725 return 0;
726}
727
728static int vmballoon_debug_open(struct inode *inode, struct file *file)
729{
730 return single_open(file, vmballoon_debug_show, inode->i_private);
731}
732
733static const struct file_operations vmballoon_debug_fops = {
734 .owner = THIS_MODULE,
735 .open = vmballoon_debug_open,
736 .read = seq_read,
737 .llseek = seq_lseek,
738 .release = single_release,
739};
740
741static int __init vmballoon_debugfs_init(struct vmballoon *b)
742{
743 int error;
744
745 b->dbg_entry = debugfs_create_file("vmmemctl", S_IRUGO, NULL, b,
746 &vmballoon_debug_fops);
747 if (IS_ERR(b->dbg_entry)) {
748 error = PTR_ERR(b->dbg_entry);
749 pr_err("failed to create debugfs entry, error: %d\n", error);
750 return error;
751 }
752
753 return 0;
754}
755
756static void __exit vmballoon_debugfs_exit(struct vmballoon *b)
757{
758 debugfs_remove(b->dbg_entry);
759}
760
761#else
762
763static inline int vmballoon_debugfs_init(struct vmballoon *b)
764{
765 return 0;
766}
767
768static inline void vmballoon_debugfs_exit(struct vmballoon *b)
769{
770}
771
772#endif /* CONFIG_DEBUG_FS */
773
774static int __init vmballoon_init(void)
775{
776 int error;
777
778 /*
779 * Check if we are running on VMware's hypervisor and bail out
780 * if we are not.
781 */
782 if (x86_hyper != &x86_hyper_vmware)
783 return -ENODEV;
784
785 vmballoon_wq = create_freezeable_workqueue("vmmemctl");
786 if (!vmballoon_wq) {
787 pr_err("failed to create workqueue\n");
788 return -ENOMEM;
789 }
790
791 INIT_LIST_HEAD(&balloon.pages);
792 INIT_LIST_HEAD(&balloon.refused_pages);
793
794 /* initialize rates */
795 balloon.rate_alloc = VMW_BALLOON_RATE_ALLOC_MAX;
796 balloon.rate_free = VMW_BALLOON_RATE_FREE_MAX;
797
798 INIT_DELAYED_WORK(&balloon.dwork, vmballoon_work);
799
800 /*
801 * Start balloon.
802 */
803 if (!vmballoon_send_start(&balloon)) {
804 pr_err("failed to send start command to the host\n");
805 error = -EIO;
806 goto fail;
807 }
808
809 if (!vmballoon_send_guest_id(&balloon)) {
810 pr_err("failed to send guest ID to the host\n");
811 error = -EIO;
812 goto fail;
813 }
814
815 error = vmballoon_debugfs_init(&balloon);
816 if (error)
817 goto fail;
818
819 queue_delayed_work(vmballoon_wq, &balloon.dwork, 0);
820
821 return 0;
822
823fail:
824 destroy_workqueue(vmballoon_wq);
825 return error;
826}
827module_init(vmballoon_init);
828
829static void __exit vmballoon_exit(void)
830{
831 cancel_delayed_work_sync(&balloon.dwork);
832 destroy_workqueue(vmballoon_wq);
833
834 vmballoon_debugfs_exit(&balloon);
835
836 /*
837 * Deallocate all reserved memory, and reset connection with monitor.
838 * Reset connection before deallocating memory to avoid potential for
839 * additional spurious resets from guest touching deallocated pages.
840 */
841 vmballoon_send_start(&balloon);
842 vmballoon_pop(&balloon);
843}
844module_exit(vmballoon_exit);