aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/chips
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/chips')
-rw-r--r--drivers/i2c/chips/Kconfig10
-rw-r--r--drivers/i2c/chips/ds1337.c11
-rw-r--r--drivers/i2c/chips/ds1374.c3
-rw-r--r--drivers/i2c/chips/eeprom.c17
-rw-r--r--drivers/i2c/chips/isp1301_omap.c2
-rw-r--r--drivers/i2c/chips/m41t00.c3
-rw-r--r--drivers/i2c/chips/max6875.c462
-rw-r--r--drivers/i2c/chips/pca9539.c12
-rw-r--r--drivers/i2c/chips/pcf8574.c13
-rw-r--r--drivers/i2c/chips/pcf8591.c13
-rw-r--r--drivers/i2c/chips/rtc8564.c1
11 files changed, 144 insertions, 403 deletions
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 43f70dbfc03f..6bd44a44cd28 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -2,17 +2,12 @@
2# Miscellaneous I2C chip drivers configuration 2# Miscellaneous I2C chip drivers configuration
3# 3#
4 4
5config I2C_SENSOR
6 tristate
7 default n
8
9menu "Miscellaneous I2C Chip support" 5menu "Miscellaneous I2C Chip support"
10 depends on I2C 6 depends on I2C
11 7
12config SENSORS_DS1337 8config SENSORS_DS1337
13 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock" 9 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock"
14 depends on I2C && EXPERIMENTAL 10 depends on I2C && EXPERIMENTAL
15 select I2C_SENSOR
16 help 11 help
17 If you say yes here you get support for Dallas Semiconductor 12 If you say yes here you get support for Dallas Semiconductor
18 DS1337 and DS1339 real-time clock chips. 13 DS1337 and DS1339 real-time clock chips.
@@ -23,7 +18,6 @@ config SENSORS_DS1337
23config SENSORS_DS1374 18config SENSORS_DS1374
24 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock" 19 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock"
25 depends on I2C && EXPERIMENTAL 20 depends on I2C && EXPERIMENTAL
26 select I2C_SENSOR
27 help 21 help
28 If you say yes here you get support for Dallas Semiconductor 22 If you say yes here you get support for Dallas Semiconductor
29 DS1374 real-time clock chips. 23 DS1374 real-time clock chips.
@@ -34,7 +28,6 @@ config SENSORS_DS1374
34config SENSORS_EEPROM 28config SENSORS_EEPROM
35 tristate "EEPROM reader" 29 tristate "EEPROM reader"
36 depends on I2C && EXPERIMENTAL 30 depends on I2C && EXPERIMENTAL
37 select I2C_SENSOR
38 help 31 help
39 If you say yes here you get read-only access to the EEPROM data 32 If you say yes here you get read-only access to the EEPROM data
40 available on modern memory DIMMs and Sony Vaio laptops. Such 33 available on modern memory DIMMs and Sony Vaio laptops. Such
@@ -46,7 +39,6 @@ config SENSORS_EEPROM
46config SENSORS_PCF8574 39config SENSORS_PCF8574
47 tristate "Philips PCF8574 and PCF8574A" 40 tristate "Philips PCF8574 and PCF8574A"
48 depends on I2C && EXPERIMENTAL 41 depends on I2C && EXPERIMENTAL
49 select I2C_SENSOR
50 help 42 help
51 If you say yes here you get support for Philips PCF8574 and 43 If you say yes here you get support for Philips PCF8574 and
52 PCF8574A chips. 44 PCF8574A chips.
@@ -67,7 +59,6 @@ config SENSORS_PCA9539
67config SENSORS_PCF8591 59config SENSORS_PCF8591
68 tristate "Philips PCF8591" 60 tristate "Philips PCF8591"
69 depends on I2C && EXPERIMENTAL 61 depends on I2C && EXPERIMENTAL
70 select I2C_SENSOR
71 help 62 help
72 If you say yes here you get support for Philips PCF8591 chips. 63 If you say yes here you get support for Philips PCF8591 chips.
73 64
@@ -77,7 +68,6 @@ config SENSORS_PCF8591
77config SENSORS_RTC8564 68config SENSORS_RTC8564
78 tristate "Epson 8564 RTC chip" 69 tristate "Epson 8564 RTC chip"
79 depends on I2C && EXPERIMENTAL 70 depends on I2C && EXPERIMENTAL
80 select I2C_SENSOR
81 help 71 help
82 If you say yes here you get support for the Epson 8564 RTC chip. 72 If you say yes here you get support for the Epson 8564 RTC chip.
83 73
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
index 82cf959989fd..9d3175c03395 100644
--- a/drivers/i2c/chips/ds1337.c
+++ b/drivers/i2c/chips/ds1337.c
@@ -17,7 +17,6 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/i2c-sensor.h>
21#include <linux/string.h> 20#include <linux/string.h>
22#include <linux/rtc.h> /* get the user-level API */ 21#include <linux/rtc.h> /* get the user-level API */
23#include <linux/bcd.h> 22#include <linux/bcd.h>
@@ -39,9 +38,8 @@
39 * Functions declaration 38 * Functions declaration
40 */ 39 */
41static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END }; 40static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END };
42static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
43 41
44SENSORS_INSMOD_1(ds1337); 42I2C_CLIENT_INSMOD_1(ds1337);
45 43
46static int ds1337_attach_adapter(struct i2c_adapter *adapter); 44static int ds1337_attach_adapter(struct i2c_adapter *adapter);
47static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind); 45static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind);
@@ -227,7 +225,7 @@ int ds1337_do_command(int bus, int cmd, void *arg)
227 225
228static int ds1337_attach_adapter(struct i2c_adapter *adapter) 226static int ds1337_attach_adapter(struct i2c_adapter *adapter)
229{ 227{
230 return i2c_detect(adapter, &addr_data, ds1337_detect); 228 return i2c_probe(adapter, &addr_data, ds1337_detect);
231} 229}
232 230
233/* 231/*
@@ -354,11 +352,8 @@ static int ds1337_detach_client(struct i2c_client *client)
354 int err; 352 int err;
355 struct ds1337_data *data = i2c_get_clientdata(client); 353 struct ds1337_data *data = i2c_get_clientdata(client);
356 354
357 if ((err = i2c_detach_client(client))) { 355 if ((err = i2c_detach_client(client)))
358 dev_err(&client->dev, "Client deregistration failed, "
359 "client not detached.\n");
360 return err; 356 return err;
361 }
362 357
363 list_del(&data->list); 358 list_del(&data->list);
364 kfree(data); 359 kfree(data);
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
index a445736d8838..0936327a946d 100644
--- a/drivers/i2c/chips/ds1374.c
+++ b/drivers/i2c/chips/ds1374.c
@@ -53,7 +53,6 @@ static struct i2c_client_address_data addr_data = {
53 .normal_i2c = normal_addr, 53 .normal_i2c = normal_addr,
54 .probe = ignore, 54 .probe = ignore,
55 .ignore = ignore, 55 .ignore = ignore,
56 .force = ignore,
57}; 56};
58 57
59static ulong ds1374_read_rtc(void) 58static ulong ds1374_read_rtc(void)
@@ -166,7 +165,7 @@ static void ds1374_set_tlet(ulong arg)
166 "can't confirm time set from rtc chip\n"); 165 "can't confirm time set from rtc chip\n");
167} 166}
168 167
169ulong new_time; 168static ulong new_time;
170 169
171DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time); 170DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time);
172 171
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index a2da31b0dd7b..d58403a47908 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -33,15 +33,13 @@
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/jiffies.h> 34#include <linux/jiffies.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-sensor.h>
37 36
38/* Addresses to scan */ 37/* Addresses to scan */
39static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, 38static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
40 0x55, 0x56, 0x57, I2C_CLIENT_END }; 39 0x55, 0x56, 0x57, I2C_CLIENT_END };
41static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
42 40
43/* Insmod parameters */ 41/* Insmod parameters */
44SENSORS_INSMOD_1(eeprom); 42I2C_CLIENT_INSMOD_1(eeprom);
45 43
46 44
47/* Size of EEPROM in bytes */ 45/* Size of EEPROM in bytes */
@@ -153,21 +151,16 @@ static struct bin_attribute eeprom_attr = {
153 151
154static int eeprom_attach_adapter(struct i2c_adapter *adapter) 152static int eeprom_attach_adapter(struct i2c_adapter *adapter)
155{ 153{
156 return i2c_detect(adapter, &addr_data, eeprom_detect); 154 return i2c_probe(adapter, &addr_data, eeprom_detect);
157} 155}
158 156
159/* This function is called by i2c_detect */ 157/* This function is called by i2c_probe */
160int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) 158int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
161{ 159{
162 struct i2c_client *new_client; 160 struct i2c_client *new_client;
163 struct eeprom_data *data; 161 struct eeprom_data *data;
164 int err = 0; 162 int err = 0;
165 163
166 /* prevent 24RF08 corruption */
167 if (kind < 0)
168 i2c_smbus_xfer(adapter, address, 0, 0, 0,
169 I2C_SMBUS_QUICK, NULL);
170
171 /* There are three ways we can read the EEPROM data: 164 /* There are three ways we can read the EEPROM data:
172 (1) I2C block reads (faster, but unsupported by most adapters) 165 (1) I2C block reads (faster, but unsupported by most adapters)
173 (2) Consecutive byte reads (100% overhead) 166 (2) Consecutive byte reads (100% overhead)
@@ -231,10 +224,8 @@ static int eeprom_detach_client(struct i2c_client *client)
231 int err; 224 int err;
232 225
233 err = i2c_detach_client(client); 226 err = i2c_detach_client(client);
234 if (err) { 227 if (err)
235 dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
236 return err; 228 return err;
237 }
238 229
239 kfree(i2c_get_clientdata(client)); 230 kfree(i2c_get_clientdata(client));
240 231
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 354a26295672..8ee56d4b3891 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -1489,7 +1489,7 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1489 if (the_transceiver) 1489 if (the_transceiver)
1490 return 0; 1490 return 0;
1491 1491
1492 isp = kcalloc(1, sizeof *isp, GFP_KERNEL); 1492 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1493 if (!isp) 1493 if (!isp)
1494 return 0; 1494 return 0;
1495 1495
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 778d7e12859d..3f14528a52a9 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -42,7 +42,6 @@ static struct i2c_client_address_data addr_data = {
42 .normal_i2c = normal_addr, 42 .normal_i2c = normal_addr,
43 .probe = ignore, 43 .probe = ignore,
44 .ignore = ignore, 44 .ignore = ignore,
45 .force = ignore,
46}; 45};
47 46
48ulong 47ulong
@@ -145,7 +144,7 @@ m41t00_set_tlet(ulong arg)
145 return; 144 return;
146} 145}
147 146
148ulong new_time; 147static ulong new_time;
149 148
150DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time); 149DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time);
151 150
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 0230375f72e5..9e1aeb69abf9 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -5,97 +5,60 @@
5 5
6 Based on i2c/chips/eeprom.c 6 Based on i2c/chips/eeprom.c
7 7
8 The MAX6875 has two EEPROM sections: config and user. 8 The MAX6875 has a bank of registers and two banks of EEPROM.
9 At reset, the config EEPROM is read into the registers. 9 Address ranges are defined as follows:
10 * 0x0000 - 0x0046 = configuration registers
11 * 0x8000 - 0x8046 = configuration EEPROM
12 * 0x8100 - 0x82FF = user EEPROM
10 13
11 This driver make 3 binary files available in sysfs: 14 This driver makes the user EEPROM available for read.
12 reg_config - direct access to the registers
13 eeprom_config - acesses configuration eeprom space
14 eeprom_user - free for application use
15 15
16 In our application, we put device serial & model numbers in user eeprom. 16 The registers & config EEPROM should be accessed via i2c-dev.
17 17
18 Notes: 18 The MAX6875 ignores the lowest address bit, so each chip responds to
19 1) The datasheet says that register 0x44 / EEPROM 0x8044 should NOT 19 two addresses - 0x50/0x51 and 0x52/0x53.
20 be overwritten, so the driver explicitly prevents that. 20
21 2) It's a good idea to keep the config (0x45) locked in config EEPROM. 21 Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read
22 You can temporarily enable config writes by changing register 0x45. 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/config.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/sched.h>
35#include <linux/delay.h>
36#include <linux/i2c.h> 33#include <linux/i2c.h>
37#include <linux/i2c-sensor.h> 34#include <asm/semaphore.h>
38 35
39/* Addresses to scan */ 36/* Do not scan - the MAX6875 access method will write to some EEPROM chips */
40/* No address scanned by default, as this could corrupt standard EEPROMS. */
41static unsigned short normal_i2c[] = {I2C_CLIENT_END}; 37static unsigned short normal_i2c[] = {I2C_CLIENT_END};
42static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
43 38
44/* Insmod parameters */ 39/* Insmod parameters */
45SENSORS_INSMOD_1(max6875); 40I2C_CLIENT_INSMOD_1(max6875);
46
47/* this param will prevent 'accidental' writes to the eeprom */
48static int allow_write = 0;
49module_param(allow_write, int, 0);
50MODULE_PARM_DESC(allow_write,
51 "Enable write access:\n"
52 "*0: Read only\n"
53 " 1: Read/Write access");
54 41
55/* The MAX6875 can only read/write 16 bytes at a time */ 42/* The MAX6875 can only read/write 16 bytes at a time */
56#define SLICE_SIZE 16 43#define SLICE_SIZE 16
57#define SLICE_BITS 4 44#define SLICE_BITS 4
58 45
59/* CONFIG EEPROM is at addresses 0x8000 - 0x8045, registers are at 0 - 0x45 */
60#define CONFIG_EEPROM_BASE 0x8000
61#define CONFIG_EEPROM_SIZE 0x0046
62#define CONFIG_EEPROM_SLICES 5
63
64/* USER EEPROM is at addresses 0x8100 - 0x82FF */ 46/* USER EEPROM is at addresses 0x8100 - 0x82FF */
65#define USER_EEPROM_BASE 0x8100 47#define USER_EEPROM_BASE 0x8100
66#define USER_EEPROM_SIZE 0x0200 48#define USER_EEPROM_SIZE 0x0200
67#define USER_EEPROM_SLICES 32 49#define USER_EEPROM_SLICES 32
68 50
69/* MAX6875 commands */ 51/* MAX6875 commands */
70#define MAX6875_CMD_BLOCK_WRITE 0x83 52#define MAX6875_CMD_BLK_READ 0x84
71#define MAX6875_CMD_BLOCK_READ 0x84
72#define MAX6875_CMD_REBOOT 0x88
73
74enum max6875_area_type {
75 max6875_register_config=0,
76 max6875_eeprom_config,
77 max6875_eeprom_user,
78 max6857_max
79};
80
81struct eeprom_block {
82 enum max6875_area_type type;
83 u8 slices;
84 u32 size;
85 u32 valid;
86 u32 base;
87 unsigned long *updated;
88 u8 *data;
89};
90 53
91/* Each client has this additional data */ 54/* Each client has this additional data */
92struct max6875_data { 55struct max6875_data {
93 struct i2c_client client; 56 struct i2c_client client;
94 struct semaphore update_lock; 57 struct semaphore update_lock;
95 struct eeprom_block blocks[max6857_max]; 58
96 /* the above structs point into the arrays below */ 59 u32 valid;
97 u8 data[USER_EEPROM_SIZE + (CONFIG_EEPROM_SIZE*2)]; 60 u8 data[USER_EEPROM_SIZE];
98 unsigned long last_updated[USER_EEPROM_SLICES + (CONFIG_EEPROM_SLICES*2)]; 61 unsigned long last_updated[USER_EEPROM_SLICES];
99}; 62};
100 63
101static int max6875_attach_adapter(struct i2c_adapter *adapter); 64static int max6875_attach_adapter(struct i2c_adapter *adapter);
@@ -111,337 +74,160 @@ static struct i2c_driver max6875_driver = {
111 .detach_client = max6875_detach_client, 74 .detach_client = max6875_detach_client,
112}; 75};
113 76
114static int max6875_update_slice(struct i2c_client *client, 77static void max6875_update_slice(struct i2c_client *client, int slice)
115 struct eeprom_block *blk,
116 int slice)
117{ 78{
118 struct max6875_data *data = i2c_get_clientdata(client); 79 struct max6875_data *data = i2c_get_clientdata(client);
119 int i, j, addr, count; 80 int i, j, addr;
120 u8 rdbuf[SLICE_SIZE]; 81 u8 *buf;
121 int retval = 0;
122 82
123 if (slice >= blk->slices) 83 if (slice >= USER_EEPROM_SLICES)
124 return -1; 84 return;
125 85
126 down(&data->update_lock); 86 down(&data->update_lock);
127 87
128 if (!(blk->valid & (1 << slice)) || 88 buf = &data->data[slice << SLICE_BITS];
129 (jiffies - blk->updated[slice] > 300 * HZ) ||
130 (jiffies < blk->updated[slice])) {
131 dev_dbg(&client->dev, "Starting eeprom update, slice %u, base %u\n",
132 slice, blk->base);
133 89
134 addr = blk->base + (slice << SLICE_BITS); 90 if (!(data->valid & (1 << slice)) ||
135 count = blk->size - (slice << SLICE_BITS); 91 time_after(jiffies, data->last_updated[slice])) {
136 if (count > SLICE_SIZE) {
137 count = SLICE_SIZE;
138 }
139 92
140 /* Preset the read address */ 93 dev_dbg(&client->dev, "Starting update of slice %u\n", slice);
141 if (addr < 0x100) { 94
142 /* select the register */ 95 data->valid &= ~(1 << slice);
143 if (i2c_smbus_write_byte(client, addr & 0xFF)) { 96
144 dev_dbg(&client->dev, "max6875 register select has failed!\n"); 97 addr = USER_EEPROM_BASE + (slice << SLICE_BITS);
145 retval = -1; 98
146 goto exit; 99 /* select the eeprom address */
147 } 100 if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) {
148 } else { 101 dev_err(&client->dev, "address set failed\n");
149 /* select the eeprom */ 102 goto exit_up;
150 if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) {
151 dev_dbg(&client->dev, "max6875 address set has failed!\n");
152 retval = -1;
153 goto exit;
154 }
155 } 103 }
156 104
157 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 105 if (i2c_check_functionality(client->adapter,
158 if (i2c_smbus_read_i2c_block_data(client, MAX6875_CMD_BLOCK_READ, 106 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
159 rdbuf) != SLICE_SIZE) 107 if (i2c_smbus_read_i2c_block_data(client,
160 { 108 MAX6875_CMD_BLK_READ,
161 retval = -1; 109 buf) != SLICE_SIZE) {
162 goto exit; 110 goto exit_up;
163 } 111 }
164
165 memcpy(&blk->data[slice << SLICE_BITS], rdbuf, count);
166 } else { 112 } else {
167 for (i = 0; i < count; i++) { 113 for (i = 0; i < SLICE_SIZE; i++) {
168 j = i2c_smbus_read_byte(client); 114 j = i2c_smbus_read_byte(client);
169 if (j < 0) 115 if (j < 0) {
170 { 116 goto exit_up;
171 retval = -1;
172 goto exit;
173 } 117 }
174 blk->data[(slice << SLICE_BITS) + i] = (u8) j; 118 buf[i] = j;
175 } 119 }
176 } 120 }
177 blk->updated[slice] = jiffies; 121 data->last_updated[slice] = jiffies;
178 blk->valid |= (1 << slice); 122 data->valid |= (1 << slice);
179 } 123 }
180 exit: 124exit_up:
181 up(&data->update_lock); 125 up(&data->update_lock);
182 return retval;
183} 126}
184 127
185static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off, size_t count, 128static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off,
186 enum max6875_area_type area_type) 129 size_t count)
187{ 130{
188 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj)); 131 struct i2c_client *client = kobj_to_i2c_client(kobj);
189 struct max6875_data *data = i2c_get_clientdata(client); 132 struct max6875_data *data = i2c_get_clientdata(client);
190 struct eeprom_block *blk; 133 int slice, max_slice;
191 int slice;
192
193 blk = &data->blocks[area_type];
194 134
195 if (off > blk->size) 135 if (off > USER_EEPROM_SIZE)
196 return 0; 136 return 0;
197 if (off + count > blk->size)
198 count = blk->size - off;
199 137
200 /* Only refresh slices which contain requested bytes */ 138 if (off + count > USER_EEPROM_SIZE)
201 for (slice = (off >> SLICE_BITS); slice <= ((off + count - 1) >> SLICE_BITS); slice++) 139 count = USER_EEPROM_SIZE - off;
202 max6875_update_slice(client, blk, slice);
203 140
204 memcpy(buf, &blk->data[off], count); 141 /* refresh slices which contain requested bytes */
142 max_slice = (off + count - 1) >> SLICE_BITS;
143 for (slice = (off >> SLICE_BITS); slice <= max_slice; slice++)
144 max6875_update_slice(client, slice);
205 145
206 return count; 146 memcpy(buf, &data->data[off], count);
207}
208
209static ssize_t max6875_user_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
210{
211 return max6875_read(kobj, buf, off, count, max6875_eeprom_user);
212}
213
214static ssize_t max6875_config_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
215{
216 return max6875_read(kobj, buf, off, count, max6875_eeprom_config);
217}
218
219static ssize_t max6875_cfgreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
220{
221 return max6875_read(kobj, buf, off, count, max6875_register_config);
222}
223
224
225static ssize_t max6875_write(struct kobject *kobj, char *buf, loff_t off, size_t count,
226 enum max6875_area_type area_type)
227{
228 struct i2c_client *client = to_i2c_client(container_of(kobj, struct device, kobj));
229 struct max6875_data *data = i2c_get_clientdata(client);
230 struct eeprom_block *blk;
231 int slice, addr, retval;
232 ssize_t sent = 0;
233
234 blk = &data->blocks[area_type];
235
236 if (off > blk->size)
237 return 0;
238 if ((off + count) > blk->size)
239 count = blk->size - off;
240
241 if (down_interruptible(&data->update_lock))
242 return -EAGAIN;
243
244 /* writing to a register is done with i2c_smbus_write_byte_data() */
245 if (blk->type == max6875_register_config) {
246 for (sent = 0; sent < count; sent++) {
247 addr = off + sent;
248 if (addr == 0x44)
249 continue;
250
251 retval = i2c_smbus_write_byte_data(client, addr, buf[sent]);
252 }
253 } else {
254 int cmd, val;
255
256 /* We are writing to EEPROM */
257 for (sent = 0; sent < count; sent++) {
258 addr = blk->base + off + sent;
259 cmd = addr >> 8;
260 val = (addr & 0xff) | (buf[sent] << 8); // reversed
261
262 if (addr == 0x8044)
263 continue;
264
265 retval = i2c_smbus_write_word_data(client, cmd, val);
266
267 if (retval) {
268 goto error_exit;
269 }
270 147
271 /* A write takes up to 11 ms */ 148 return count;
272 msleep(11);
273 }
274 }
275
276 /* Invalidate the scratch buffer */
277 for (slice = (off >> SLICE_BITS); slice <= ((off + count - 1) >> SLICE_BITS); slice++)
278 blk->valid &= ~(1 << slice);
279
280 error_exit:
281 up(&data->update_lock);
282
283 return sent;
284}
285
286static ssize_t max6875_user_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
287{
288 return max6875_write(kobj, buf, off, count, max6875_eeprom_user);
289}
290
291static ssize_t max6875_config_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
292{
293 return max6875_write(kobj, buf, off, count, max6875_eeprom_config);
294}
295
296static ssize_t max6875_cfgreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
297{
298 return max6875_write(kobj, buf, off, count, max6875_register_config);
299} 149}
300 150
301static struct bin_attribute user_eeprom_attr = { 151static struct bin_attribute user_eeprom_attr = {
302 .attr = { 152 .attr = {
303 .name = "eeprom_user", 153 .name = "eeprom",
304 .mode = S_IRUGO | S_IWUSR | S_IWGRP, 154 .mode = S_IRUGO,
305 .owner = THIS_MODULE,
306 },
307 .size = USER_EEPROM_SIZE,
308 .read = max6875_user_read,
309 .write = max6875_user_write,
310};
311
312static struct bin_attribute config_eeprom_attr = {
313 .attr = {
314 .name = "eeprom_config",
315 .mode = S_IRUGO | S_IWUSR,
316 .owner = THIS_MODULE,
317 },
318 .size = CONFIG_EEPROM_SIZE,
319 .read = max6875_config_read,
320 .write = max6875_config_write,
321};
322
323static struct bin_attribute config_register_attr = {
324 .attr = {
325 .name = "reg_config",
326 .mode = S_IRUGO | S_IWUSR,
327 .owner = THIS_MODULE, 155 .owner = THIS_MODULE,
328 }, 156 },
329 .size = CONFIG_EEPROM_SIZE, 157 .size = USER_EEPROM_SIZE,
330 .read = max6875_cfgreg_read, 158 .read = max6875_read,
331 .write = max6875_cfgreg_write,
332}; 159};
333 160
334static int max6875_attach_adapter(struct i2c_adapter *adapter) 161static int max6875_attach_adapter(struct i2c_adapter *adapter)
335{ 162{
336 return i2c_detect(adapter, &addr_data, max6875_detect); 163 return i2c_probe(adapter, &addr_data, max6875_detect);
337} 164}
338 165
339/* This function is called by i2c_detect */ 166/* This function is called by i2c_probe */
340static int max6875_detect(struct i2c_adapter *adapter, int address, int kind) 167static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
341{ 168{
342 struct i2c_client *new_client; 169 struct i2c_client *real_client;
170 struct i2c_client *fake_client;
343 struct max6875_data *data; 171 struct max6875_data *data;
344 int err = 0; 172 int err = 0;
345 173
346 /* Prevent 24RF08 corruption (in case of user error) */ 174 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA
347 if (kind < 0) 175 | I2C_FUNC_SMBUS_READ_BYTE))
348 i2c_smbus_xfer(adapter, address, 0, 0, 0, 176 return 0;
349 I2C_SMBUS_QUICK, NULL); 177
350 178 /* Only check even addresses */
351 /* There are three ways we can read the EEPROM data: 179 if (address & 1)
352 (1) I2C block reads (faster, but unsupported by most adapters) 180 return 0;
353 (2) Consecutive byte reads (100% overhead) 181
354 (3) Regular byte data reads (200% overhead) 182 if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL)))
355 The third method is not implemented by this driver because all 183 return -ENOMEM;
356 known adapters support at least the second. */
357 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA |
358 I2C_FUNC_SMBUS_BYTE |
359 I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
360 goto exit;
361
362 /* OK. For now, we presume we have a valid client. We now create the
363 client structure, even though we cannot fill it completely yet.
364 But it allows us to access eeprom_{read,write}_value. */
365 if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL))) {
366 err = -ENOMEM;
367 goto exit;
368 }
369 memset(data, 0, sizeof(struct max6875_data)); 184 memset(data, 0, sizeof(struct max6875_data));
370 185
371 new_client = &data->client; 186 /* A fake client is created on the odd address */
372 i2c_set_clientdata(new_client, data); 187 if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
373 new_client->addr = address; 188 err = -ENOMEM;
374 new_client->adapter = adapter; 189 goto exit_kfree1;
375 new_client->driver = &max6875_driver; 190 }
376 new_client->flags = 0; 191 memset(fake_client, 0, sizeof(struct i2c_client));
377 192
378 /* Setup the user section */ 193 /* Init real i2c_client */
379 data->blocks[max6875_eeprom_user].type = max6875_eeprom_user; 194 real_client = &data->client;
380 data->blocks[max6875_eeprom_user].slices = USER_EEPROM_SLICES; 195 i2c_set_clientdata(real_client, data);
381 data->blocks[max6875_eeprom_user].size = USER_EEPROM_SIZE; 196 real_client->addr = address;
382 data->blocks[max6875_eeprom_user].base = USER_EEPROM_BASE; 197 real_client->adapter = adapter;
383 data->blocks[max6875_eeprom_user].data = data->data; 198 real_client->driver = &max6875_driver;
384 data->blocks[max6875_eeprom_user].updated = data->last_updated; 199 real_client->flags = 0;
385 200 strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
386 /* Setup the config section */
387 data->blocks[max6875_eeprom_config].type = max6875_eeprom_config;
388 data->blocks[max6875_eeprom_config].slices = CONFIG_EEPROM_SLICES;
389 data->blocks[max6875_eeprom_config].size = CONFIG_EEPROM_SIZE;
390 data->blocks[max6875_eeprom_config].base = CONFIG_EEPROM_BASE;
391 data->blocks[max6875_eeprom_config].data = &data->data[USER_EEPROM_SIZE];
392 data->blocks[max6875_eeprom_config].updated = &data->last_updated[USER_EEPROM_SLICES];
393
394 /* Setup the register section */
395 data->blocks[max6875_register_config].type = max6875_register_config;
396 data->blocks[max6875_register_config].slices = CONFIG_EEPROM_SLICES;
397 data->blocks[max6875_register_config].size = CONFIG_EEPROM_SIZE;
398 data->blocks[max6875_register_config].base = 0;
399 data->blocks[max6875_register_config].data = &data->data[USER_EEPROM_SIZE+CONFIG_EEPROM_SIZE];
400 data->blocks[max6875_register_config].updated = &data->last_updated[USER_EEPROM_SLICES+CONFIG_EEPROM_SLICES];
401
402 /* Init the data */
403 memset(data->data, 0xff, sizeof(data->data));
404
405 /* Fill in the remaining client fields */
406 strlcpy(new_client->name, "max6875", I2C_NAME_SIZE);
407 init_MUTEX(&data->update_lock); 201 init_MUTEX(&data->update_lock);
408 202
409 /* Verify that the chip is really what we think it is */ 203 /* Init fake client data */
410 if ((max6875_update_slice(new_client, &data->blocks[max6875_eeprom_config], 4) < 0) || 204 /* set the client data to the i2c_client so that it will get freed */
411 (max6875_update_slice(new_client, &data->blocks[max6875_register_config], 4) < 0)) 205 i2c_set_clientdata(fake_client, fake_client);
412 goto exit_kfree; 206 fake_client->addr = address | 1;
413 207 fake_client->adapter = adapter;
414 /* 0x41,0x42 must be zero and 0x40 must match in eeprom and registers */ 208 fake_client->driver = &max6875_driver;
415 if ((data->blocks[max6875_eeprom_config].data[0x41] != 0) || 209 fake_client->flags = 0;
416 (data->blocks[max6875_eeprom_config].data[0x42] != 0) || 210 strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE);
417 (data->blocks[max6875_register_config].data[0x41] != 0) || 211
418 (data->blocks[max6875_register_config].data[0x42] != 0) || 212 /* Prevent 24RF08 corruption (in case of user error) */
419 (data->blocks[max6875_eeprom_config].data[0x40] != 213 i2c_smbus_write_quick(real_client, 0);
420 data->blocks[max6875_register_config].data[0x40])) 214
421 goto exit_kfree; 215 if ((err = i2c_attach_client(real_client)) != 0)
422 216 goto exit_kfree2;
423 /* Tell the I2C layer a new client has arrived */ 217
424 if ((err = i2c_attach_client(new_client))) 218 if ((err = i2c_attach_client(fake_client)) != 0)
425 goto exit_kfree; 219 goto exit_detach;
426 220
427 /* create the sysfs eeprom files with the correct permissions */ 221 sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
428 if (allow_write == 0) {
429 user_eeprom_attr.attr.mode &= ~S_IWUGO;
430 user_eeprom_attr.write = NULL;
431 config_eeprom_attr.attr.mode &= ~S_IWUGO;
432 config_eeprom_attr.write = NULL;
433 config_register_attr.attr.mode &= ~S_IWUGO;
434 config_register_attr.write = NULL;
435 }
436 sysfs_create_bin_file(&new_client->dev.kobj, &user_eeprom_attr);
437 sysfs_create_bin_file(&new_client->dev.kobj, &config_eeprom_attr);
438 sysfs_create_bin_file(&new_client->dev.kobj, &config_register_attr);
439 222
440 return 0; 223 return 0;
441 224
442exit_kfree: 225exit_detach:
226 i2c_detach_client(real_client);
227exit_kfree2:
228 kfree(fake_client);
229exit_kfree1:
443 kfree(data); 230 kfree(data);
444exit:
445 return err; 231 return err;
446} 232}
447 233
@@ -450,13 +236,9 @@ static int max6875_detach_client(struct i2c_client *client)
450 int err; 236 int err;
451 237
452 err = i2c_detach_client(client); 238 err = i2c_detach_client(client);
453 if (err) { 239 if (err)
454 dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
455 return err; 240 return err;
456 }
457
458 kfree(i2c_get_clientdata(client)); 241 kfree(i2c_get_clientdata(client));
459
460 return 0; 242 return 0;
461} 243}
462 244
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index 9f3ad45daae2..225577fdda4d 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -13,14 +13,12 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/hwmon-sysfs.h> 15#include <linux/hwmon-sysfs.h>
16#include <linux/i2c-sensor.h>
17 16
18/* Addresses to scan */ 17/* Addresses to scan */
19static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END}; 18static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END};
20static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
21 19
22/* Insmod parameters */ 20/* Insmod parameters */
23SENSORS_INSMOD_1(pca9539); 21I2C_CLIENT_INSMOD_1(pca9539);
24 22
25enum pca9539_cmd 23enum pca9539_cmd
26{ 24{
@@ -109,10 +107,10 @@ static struct attribute_group pca9539_defattr_group = {
109 107
110static int pca9539_attach_adapter(struct i2c_adapter *adapter) 108static int pca9539_attach_adapter(struct i2c_adapter *adapter)
111{ 109{
112 return i2c_detect(adapter, &addr_data, pca9539_detect); 110 return i2c_probe(adapter, &addr_data, pca9539_detect);
113} 111}
114 112
115/* This function is called by i2c_detect */ 113/* This function is called by i2c_probe */
116static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind) 114static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
117{ 115{
118 struct i2c_client *new_client; 116 struct i2c_client *new_client;
@@ -164,10 +162,8 @@ static int pca9539_detach_client(struct i2c_client *client)
164{ 162{
165 int err; 163 int err;
166 164
167 if ((err = i2c_detach_client(client))) { 165 if ((err = i2c_detach_client(client)))
168 dev_err(&client->dev, "Client deregistration failed.\n");
169 return err; 166 return err;
170 }
171 167
172 kfree(i2c_get_clientdata(client)); 168 kfree(i2c_get_clientdata(client));
173 return 0; 169 return 0;
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index cfcf64654080..6525743ff9fd 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -39,16 +39,14 @@
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42#include <linux/i2c-sensor.h>
43 42
44/* Addresses to scan */ 43/* Addresses to scan */
45static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 44static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
46 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 45 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
47 I2C_CLIENT_END }; 46 I2C_CLIENT_END };
48static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
49 47
50/* Insmod parameters */ 48/* Insmod parameters */
51SENSORS_INSMOD_2(pcf8574, pcf8574a); 49I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
52 50
53/* Initial values */ 51/* Initial values */
54#define PCF8574_INIT 255 /* All outputs on (input mode) */ 52#define PCF8574_INIT 255 /* All outputs on (input mode) */
@@ -113,10 +111,10 @@ static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
113 111
114static int pcf8574_attach_adapter(struct i2c_adapter *adapter) 112static int pcf8574_attach_adapter(struct i2c_adapter *adapter)
115{ 113{
116 return i2c_detect(adapter, &addr_data, pcf8574_detect); 114 return i2c_probe(adapter, &addr_data, pcf8574_detect);
117} 115}
118 116
119/* This function is called by i2c_detect */ 117/* This function is called by i2c_probe */
120int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) 118int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
121{ 119{
122 struct i2c_client *new_client; 120 struct i2c_client *new_client;
@@ -186,11 +184,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
186{ 184{
187 int err; 185 int err;
188 186
189 if ((err = i2c_detach_client(client))) { 187 if ((err = i2c_detach_client(client)))
190 dev_err(&client->dev,
191 "Client deregistration failed, client not detached.\n");
192 return err; 188 return err;
193 }
194 189
195 kfree(i2c_get_clientdata(client)); 190 kfree(i2c_get_clientdata(client));
196 return 0; 191 return 0;
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index db812ade8564..80f1df9a4500 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -24,15 +24,13 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/i2c-sensor.h>
28 27
29/* Addresses to scan */ 28/* Addresses to scan */
30static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 29static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
31 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 30 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
32static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
33 31
34/* Insmod parameters */ 32/* Insmod parameters */
35SENSORS_INSMOD_1(pcf8591); 33I2C_CLIENT_INSMOD_1(pcf8591);
36 34
37static int input_mode; 35static int input_mode;
38module_param(input_mode, int, 0); 36module_param(input_mode, int, 0);
@@ -164,10 +162,10 @@ static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO,
164 */ 162 */
165static int pcf8591_attach_adapter(struct i2c_adapter *adapter) 163static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
166{ 164{
167 return i2c_detect(adapter, &addr_data, pcf8591_detect); 165 return i2c_probe(adapter, &addr_data, pcf8591_detect);
168} 166}
169 167
170/* This function is called by i2c_detect */ 168/* This function is called by i2c_probe */
171int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) 169int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
172{ 170{
173 struct i2c_client *new_client; 171 struct i2c_client *new_client;
@@ -241,11 +239,8 @@ static int pcf8591_detach_client(struct i2c_client *client)
241{ 239{
242 int err; 240 int err;
243 241
244 if ((err = i2c_detach_client(client))) { 242 if ((err = i2c_detach_client(client)))
245 dev_err(&client->dev,
246 "Client deregistration failed, client not detached.\n");
247 return err; 243 return err;
248 }
249 244
250 kfree(i2c_get_clientdata(client)); 245 kfree(i2c_get_clientdata(client));
251 return 0; 246 return 0;
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
index 588fc2261a91..0b5385c892b1 100644
--- a/drivers/i2c/chips/rtc8564.c
+++ b/drivers/i2c/chips/rtc8564.c
@@ -67,7 +67,6 @@ static struct i2c_client_address_data addr_data = {
67 .normal_i2c = normal_addr, 67 .normal_i2c = normal_addr,
68 .probe = ignore, 68 .probe = ignore,
69 .ignore = ignore, 69 .ignore = ignore,
70 .force = ignore,
71}; 70};
72 71
73static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem); 72static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem);