Skip to content

Commit f68ae78

Browse files
committed
Merge tag 'at24-updates-for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into i2c/for-mergewindow
at24 updates for v5.17 - add support for a new model: Microchip 24c1025 - reorganize the compatible definitions in the DT binding document - drop the at24_client structure by retrieving the struct device associated with the chip's regmap
2 parents 8ab1ff9 + d08aea2 commit f68ae78

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

Documentation/devicetree/bindings/eeprom/at24.yaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ properties:
8686
pattern: c1024$
8787
- items:
8888
pattern: cs1024$
89+
- items:
90+
pattern: c1025$
91+
- items:
92+
pattern: cs1025$
8993
- items:
9094
pattern: c2048$
9195
- items:
@@ -95,17 +99,20 @@ properties:
9599
# These are special cases that don't conform to the above pattern.
96100
# Each requires a standard at24 model as fallback.
97101
- items:
98-
- const: nxp,se97b
99-
- const: atmel,24c02
102+
- enum:
103+
- rohm,br24g01
104+
- rohm,br24t01
105+
- const: atmel,24c01
100106
- items:
101-
- const: onnn,cat24c04
102-
- const: atmel,24c04
107+
- enum:
108+
- nxp,se97b
109+
- renesas,r1ex24002
110+
- const: atmel,24c02
103111
- items:
104-
- const: onnn,cat24c05
112+
- enum:
113+
- onnn,cat24c04
114+
- onnn,cat24c05
105115
- const: atmel,24c04
106-
- items:
107-
- const: renesas,r1ex24002
108-
- const: atmel,24c02
109116
- items:
110117
- const: renesas,r1ex24016
111118
- const: atmel,24c16
@@ -115,12 +122,6 @@ properties:
115122
- items:
116123
- const: renesas,r1ex24128
117124
- const: atmel,24c128
118-
- items:
119-
- const: rohm,br24g01
120-
- const: atmel,24c01
121-
- items:
122-
- const: rohm,br24t01
123-
- const: atmel,24c01
124125

125126
label:
126127
description: Descriptive name of the EEPROM.

drivers/misc/eeprom/at24.c

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@
6868
* which won't work on pure SMBus systems.
6969
*/
7070

71-
struct at24_client {
72-
struct i2c_client *client;
73-
struct regmap *regmap;
74-
};
75-
7671
struct at24_data {
7772
/*
7873
* Lock protects against activities from other Linux tasks,
@@ -94,9 +89,10 @@ struct at24_data {
9489

9590
/*
9691
* Some chips tie up multiple I2C addresses; dummy devices reserve
97-
* them for us, and we'll use them with SMBus calls.
92+
* them for us.
9893
*/
99-
struct at24_client client[];
94+
u8 bank_addr_shift;
95+
struct regmap *client_regmaps[];
10096
};
10197

10298
/*
@@ -123,6 +119,7 @@ MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
123119
struct at24_chip_data {
124120
u32 byte_len;
125121
u8 flags;
122+
u8 bank_addr_shift;
126123
void (*read_post)(unsigned int off, char *buf, size_t count);
127124
};
128125

@@ -137,6 +134,12 @@ struct at24_chip_data {
137134
.read_post = _read_post, \
138135
}
139136

137+
#define AT24_CHIP_DATA_BS(_name, _len, _flags, _bank_addr_shift) \
138+
static const struct at24_chip_data _name = { \
139+
.byte_len = _len, .flags = _flags, \
140+
.bank_addr_shift = _bank_addr_shift \
141+
}
142+
140143
static void at24_read_post_vaio(unsigned int off, char *buf, size_t count)
141144
{
142145
int i;
@@ -197,6 +200,7 @@ AT24_CHIP_DATA(at24_data_24c128, 131072 / 8, AT24_FLAG_ADDR16);
197200
AT24_CHIP_DATA(at24_data_24c256, 262144 / 8, AT24_FLAG_ADDR16);
198201
AT24_CHIP_DATA(at24_data_24c512, 524288 / 8, AT24_FLAG_ADDR16);
199202
AT24_CHIP_DATA(at24_data_24c1024, 1048576 / 8, AT24_FLAG_ADDR16);
203+
AT24_CHIP_DATA_BS(at24_data_24c1025, 1048576 / 8, AT24_FLAG_ADDR16, 2);
200204
AT24_CHIP_DATA(at24_data_24c2048, 2097152 / 8, AT24_FLAG_ADDR16);
201205
/* identical to 24c08 ? */
202206
AT24_CHIP_DATA(at24_data_INT3499, 8192 / 8, 0);
@@ -225,6 +229,7 @@ static const struct i2c_device_id at24_ids[] = {
225229
{ "24c256", (kernel_ulong_t)&at24_data_24c256 },
226230
{ "24c512", (kernel_ulong_t)&at24_data_24c512 },
227231
{ "24c1024", (kernel_ulong_t)&at24_data_24c1024 },
232+
{ "24c1025", (kernel_ulong_t)&at24_data_24c1025 },
228233
{ "24c2048", (kernel_ulong_t)&at24_data_24c2048 },
229234
{ "at24", 0 },
230235
{ /* END OF LIST */ }
@@ -254,6 +259,7 @@ static const struct of_device_id at24_of_match[] = {
254259
{ .compatible = "atmel,24c256", .data = &at24_data_24c256 },
255260
{ .compatible = "atmel,24c512", .data = &at24_data_24c512 },
256261
{ .compatible = "atmel,24c1024", .data = &at24_data_24c1024 },
262+
{ .compatible = "atmel,24c1025", .data = &at24_data_24c1025 },
257263
{ .compatible = "atmel,24c2048", .data = &at24_data_24c2048 },
258264
{ /* END OF LIST */ },
259265
};
@@ -275,8 +281,8 @@ MODULE_DEVICE_TABLE(acpi, at24_acpi_ids);
275281
* set the byte address; on a multi-master board, another master
276282
* may have changed the chip's "current" address pointer.
277283
*/
278-
static struct at24_client *at24_translate_offset(struct at24_data *at24,
279-
unsigned int *offset)
284+
static struct regmap *at24_translate_offset(struct at24_data *at24,
285+
unsigned int *offset)
280286
{
281287
unsigned int i;
282288

@@ -288,12 +294,12 @@ static struct at24_client *at24_translate_offset(struct at24_data *at24,
288294
*offset &= 0xff;
289295
}
290296

291-
return &at24->client[i];
297+
return at24->client_regmaps[i];
292298
}
293299

294300
static struct device *at24_base_client_dev(struct at24_data *at24)
295301
{
296-
return &at24->client[0].client->dev;
302+
return regmap_get_device(at24->client_regmaps[0]);
297303
}
298304

299305
static size_t at24_adjust_read_count(struct at24_data *at24,
@@ -324,14 +330,10 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
324330
unsigned int offset, size_t count)
325331
{
326332
unsigned long timeout, read_time;
327-
struct at24_client *at24_client;
328-
struct i2c_client *client;
329333
struct regmap *regmap;
330334
int ret;
331335

332-
at24_client = at24_translate_offset(at24, &offset);
333-
regmap = at24_client->regmap;
334-
client = at24_client->client;
336+
regmap = at24_translate_offset(at24, &offset);
335337
count = at24_adjust_read_count(at24, offset, count);
336338

337339
/* adjust offset for mac and serial read ops */
@@ -346,7 +348,7 @@ static ssize_t at24_regmap_read(struct at24_data *at24, char *buf,
346348
read_time = jiffies;
347349

348350
ret = regmap_bulk_read(regmap, offset, buf, count);
349-
dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n",
351+
dev_dbg(regmap_get_device(regmap), "read %zu@%d --> %d (%ld)\n",
350352
count, offset, ret, jiffies);
351353
if (!ret)
352354
return count;
@@ -387,14 +389,10 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
387389
unsigned int offset, size_t count)
388390
{
389391
unsigned long timeout, write_time;
390-
struct at24_client *at24_client;
391-
struct i2c_client *client;
392392
struct regmap *regmap;
393393
int ret;
394394

395-
at24_client = at24_translate_offset(at24, &offset);
396-
regmap = at24_client->regmap;
397-
client = at24_client->client;
395+
regmap = at24_translate_offset(at24, &offset);
398396
count = at24_adjust_write_count(at24, offset, count);
399397
timeout = jiffies + msecs_to_jiffies(at24_write_timeout);
400398

@@ -406,7 +404,7 @@ static ssize_t at24_regmap_write(struct at24_data *at24, const char *buf,
406404
write_time = jiffies;
407405

408406
ret = regmap_bulk_write(regmap, offset, buf, count);
409-
dev_dbg(&client->dev, "write %zu@%d --> %d (%ld)\n",
407+
dev_dbg(regmap_get_device(regmap), "write %zu@%d --> %d (%ld)\n",
410408
count, offset, ret, jiffies);
411409
if (!ret)
412410
return count;
@@ -538,26 +536,24 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
538536
}
539537

540538
static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
539+
struct i2c_client *base_client,
541540
struct regmap_config *regmap_config)
542541
{
543-
struct i2c_client *base_client, *dummy_client;
542+
struct i2c_client *dummy_client;
544543
struct regmap *regmap;
545-
struct device *dev;
546-
547-
base_client = at24->client[0].client;
548-
dev = &base_client->dev;
549544

550-
dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter,
551-
base_client->addr + index);
545+
dummy_client = devm_i2c_new_dummy_device(&base_client->dev,
546+
base_client->adapter,
547+
base_client->addr +
548+
(index << at24->bank_addr_shift));
552549
if (IS_ERR(dummy_client))
553550
return PTR_ERR(dummy_client);
554551

555552
regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
556553
if (IS_ERR(regmap))
557554
return PTR_ERR(regmap);
558555

559-
at24->client[index].client = dummy_client;
560-
at24->client[index].regmap = regmap;
556+
at24->client_regmaps[index] = regmap;
561557

562558
return 0;
563559
}
@@ -680,7 +676,7 @@ static int at24_probe(struct i2c_client *client)
680676
if (IS_ERR(regmap))
681677
return PTR_ERR(regmap);
682678

683-
at24 = devm_kzalloc(dev, struct_size(at24, client, num_addresses),
679+
at24 = devm_kzalloc(dev, struct_size(at24, client_regmaps, num_addresses),
684680
GFP_KERNEL);
685681
if (!at24)
686682
return -ENOMEM;
@@ -690,10 +686,10 @@ static int at24_probe(struct i2c_client *client)
690686
at24->page_size = page_size;
691687
at24->flags = flags;
692688
at24->read_post = cdata->read_post;
689+
at24->bank_addr_shift = cdata->bank_addr_shift;
693690
at24->num_addresses = num_addresses;
694691
at24->offset_adj = at24_get_offset_adj(flags, byte_len);
695-
at24->client[0].client = client;
696-
at24->client[0].regmap = regmap;
692+
at24->client_regmaps[0] = regmap;
697693

698694
at24->vcc_reg = devm_regulator_get(dev, "vcc");
699695
if (IS_ERR(at24->vcc_reg))
@@ -709,7 +705,7 @@ static int at24_probe(struct i2c_client *client)
709705

710706
/* use dummy devices for multiple-address chips */
711707
for (i = 1; i < num_addresses; i++) {
712-
err = at24_make_dummy_client(at24, i, &regmap_config);
708+
err = at24_make_dummy_client(at24, i, client, &regmap_config);
713709
if (err)
714710
return err;
715711
}

0 commit comments

Comments
 (0)