16
16
#include <linux/mod_devicetable.h>
17
17
#include <linux/module.h>
18
18
#include <linux/mutex.h>
19
+ #include <linux/nvmem-provider.h>
19
20
20
21
/*
21
22
* DDR4 memory modules use special EEPROMs following the Jedec EE1004
@@ -145,13 +146,17 @@ static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,
145
146
return i2c_smbus_read_i2c_block_data_or_emulated (client , offset , count , buf );
146
147
}
147
148
148
- static ssize_t eeprom_read (struct file * filp , struct kobject * kobj ,
149
- struct bin_attribute * bin_attr ,
150
- char * buf , loff_t off , size_t count )
149
+ static int ee1004_read (void * priv , unsigned int off , void * val , size_t count )
151
150
{
152
- struct i2c_client * client = kobj_to_i2c_client (kobj );
153
- size_t requested = count ;
154
- int ret = 0 ;
151
+ struct i2c_client * client = priv ;
152
+ char * buf = val ;
153
+ int ret ;
154
+
155
+ if (unlikely (!count ))
156
+ return count ;
157
+
158
+ if (off + count > EE1004_EEPROM_SIZE )
159
+ return - EINVAL ;
155
160
156
161
/*
157
162
* Read data from chip, protecting against concurrent access to
@@ -161,28 +166,21 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
161
166
162
167
while (count ) {
163
168
ret = ee1004_eeprom_read (client , buf , off , count );
164
- if (ret < 0 )
165
- goto out ;
169
+ if (ret < 0 ) {
170
+ mutex_unlock (& ee1004_bus_lock );
171
+ return ret ;
172
+ }
166
173
167
174
buf += ret ;
168
175
off += ret ;
169
176
count -= ret ;
170
177
}
171
- out :
178
+
172
179
mutex_unlock (& ee1004_bus_lock );
173
180
174
- return ret < 0 ? ret : requested ;
181
+ return 0 ;
175
182
}
176
183
177
- static BIN_ATTR_RO (eeprom , EE1004_EEPROM_SIZE ) ;
178
-
179
- static struct bin_attribute * ee1004_attrs [] = {
180
- & bin_attr_eeprom ,
181
- NULL
182
- };
183
-
184
- BIN_ATTRIBUTE_GROUPS (ee1004 );
185
-
186
184
static void ee1004_probe_temp_sensor (struct i2c_client * client )
187
185
{
188
186
struct i2c_board_info info = { .type = "jc42" };
@@ -220,7 +218,24 @@ static void ee1004_cleanup_bus_data(void *data)
220
218
221
219
static int ee1004_probe (struct i2c_client * client )
222
220
{
221
+ struct nvmem_config config = {
222
+ .dev = & client -> dev ,
223
+ .name = dev_name (& client -> dev ),
224
+ .id = NVMEM_DEVID_NONE ,
225
+ .owner = THIS_MODULE ,
226
+ .type = NVMEM_TYPE_EEPROM ,
227
+ .read_only = true,
228
+ .root_only = false,
229
+ .reg_read = ee1004_read ,
230
+ .size = EE1004_EEPROM_SIZE ,
231
+ .word_size = 1 ,
232
+ .stride = 1 ,
233
+ .priv = client ,
234
+ .compat = true,
235
+ .base_dev = & client -> dev ,
236
+ };
223
237
struct ee1004_bus_data * bd ;
238
+ struct nvmem_device * ndev ;
224
239
int err , cnr = 0 ;
225
240
226
241
/* Make sure we can operate on this adapter */
@@ -272,6 +287,10 @@ static int ee1004_probe(struct i2c_client *client)
272
287
273
288
mutex_unlock (& ee1004_bus_lock );
274
289
290
+ ndev = devm_nvmem_register (& client -> dev , & config );
291
+ if (IS_ERR (ndev ))
292
+ return PTR_ERR (ndev );
293
+
275
294
dev_info (& client -> dev ,
276
295
"%u byte EE1004-compliant SPD EEPROM, read-only\n" ,
277
296
EE1004_EEPROM_SIZE );
@@ -284,7 +303,6 @@ static int ee1004_probe(struct i2c_client *client)
284
303
static struct i2c_driver ee1004_driver = {
285
304
.driver = {
286
305
.name = "ee1004" ,
287
- .dev_groups = ee1004_groups ,
288
306
},
289
307
.probe = ee1004_probe ,
290
308
.id_table = ee1004_ids ,
0 commit comments