1818#include <linux/module.h>
1919#include <linux/mutex.h>
2020#include <linux/nvmem-provider.h>
21+ #include <linux/of.h>
2122#include <linux/of_device.h>
2223#include <linux/pm_runtime.h>
2324#include <linux/property.h>
@@ -92,7 +93,7 @@ struct at24_data {
9293 * them for us.
9394 */
9495 u8 bank_addr_shift ;
95- struct regmap * client_regmaps [];
96+ struct regmap * client_regmaps [] __counted_by ( num_addresses ) ;
9697};
9798
9899/*
@@ -191,9 +192,13 @@ AT24_CHIP_DATA(at24_data_24c16, 16384 / 8, 0);
191192AT24_CHIP_DATA (at24_data_24cs16 , 16 ,
192193 AT24_FLAG_SERIAL | AT24_FLAG_READONLY );
193194AT24_CHIP_DATA (at24_data_24c32 , 32768 / 8 , AT24_FLAG_ADDR16 );
195+ /* M24C32-D Additional Write lockable page (M24C32-D order codes) */
196+ AT24_CHIP_DATA (at24_data_24c32d_wlp , 32 , AT24_FLAG_ADDR16 );
194197AT24_CHIP_DATA (at24_data_24cs32 , 16 ,
195198 AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY );
196199AT24_CHIP_DATA (at24_data_24c64 , 65536 / 8 , AT24_FLAG_ADDR16 );
200+ /* M24C64-D Additional Write lockable page (M24C64-D order codes) */
201+ AT24_CHIP_DATA (at24_data_24c64d_wlp , 32 , AT24_FLAG_ADDR16 );
197202AT24_CHIP_DATA (at24_data_24cs64 , 16 ,
198203 AT24_FLAG_ADDR16 | AT24_FLAG_SERIAL | AT24_FLAG_READONLY );
199204AT24_CHIP_DATA (at24_data_24c128 , 131072 / 8 , AT24_FLAG_ADDR16 );
@@ -222,8 +227,10 @@ static const struct i2c_device_id at24_ids[] = {
222227 { "24c16" , (kernel_ulong_t )& at24_data_24c16 },
223228 { "24cs16" , (kernel_ulong_t )& at24_data_24cs16 },
224229 { "24c32" , (kernel_ulong_t )& at24_data_24c32 },
230+ { "24c32d-wl" , (kernel_ulong_t )& at24_data_24c32d_wlp },
225231 { "24cs32" , (kernel_ulong_t )& at24_data_24cs32 },
226232 { "24c64" , (kernel_ulong_t )& at24_data_24c64 },
233+ { "24c64-wl" , (kernel_ulong_t )& at24_data_24c64d_wlp },
227234 { "24cs64" , (kernel_ulong_t )& at24_data_24cs64 },
228235 { "24c128" , (kernel_ulong_t )& at24_data_24c128 },
229236 { "24c256" , (kernel_ulong_t )& at24_data_24c256 },
@@ -236,7 +243,7 @@ static const struct i2c_device_id at24_ids[] = {
236243};
237244MODULE_DEVICE_TABLE (i2c , at24_ids );
238245
239- static const struct of_device_id at24_of_match [] = {
246+ static const struct of_device_id __maybe_unused at24_of_match [] = {
240247 { .compatible = "atmel,24c00" , .data = & at24_data_24c00 },
241248 { .compatible = "atmel,24c01" , .data = & at24_data_24c01 },
242249 { .compatible = "atmel,24cs01" , .data = & at24_data_24cs01 },
@@ -252,8 +259,10 @@ static const struct of_device_id at24_of_match[] = {
252259 { .compatible = "atmel,24c16" , .data = & at24_data_24c16 },
253260 { .compatible = "atmel,24cs16" , .data = & at24_data_24cs16 },
254261 { .compatible = "atmel,24c32" , .data = & at24_data_24c32 },
262+ { .compatible = "atmel,24c32d-wl" , .data = & at24_data_24c32d_wlp },
255263 { .compatible = "atmel,24cs32" , .data = & at24_data_24cs32 },
256264 { .compatible = "atmel,24c64" , .data = & at24_data_24c64 },
265+ { .compatible = "atmel,24c64d-wl" , .data = & at24_data_24c64d_wlp },
257266 { .compatible = "atmel,24cs64" , .data = & at24_data_24cs64 },
258267 { .compatible = "atmel,24c128" , .data = & at24_data_24c128 },
259268 { .compatible = "atmel,24c256" , .data = & at24_data_24c256 },
@@ -431,12 +440,9 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
431440 if (off + count > at24 -> byte_len )
432441 return - EINVAL ;
433442
434- ret = pm_runtime_get_sync (dev );
435- if (ret < 0 ) {
436- pm_runtime_put_noidle (dev );
443+ ret = pm_runtime_resume_and_get (dev );
444+ if (ret )
437445 return ret ;
438- }
439-
440446 /*
441447 * Read data from chip, protecting against concurrent updates
442448 * from this host, but not from other I2C masters.
@@ -478,12 +484,9 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
478484 if (off + count > at24 -> byte_len )
479485 return - EINVAL ;
480486
481- ret = pm_runtime_get_sync (dev );
482- if (ret < 0 ) {
483- pm_runtime_put_noidle (dev );
487+ ret = pm_runtime_resume_and_get (dev );
488+ if (ret )
484489 return ret ;
485- }
486-
487490 /*
488491 * Write data to chip, protecting against concurrent updates
489492 * from this host, but not from other I2C masters.
@@ -509,32 +512,6 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
509512 return 0 ;
510513}
511514
512- static const struct at24_chip_data * at24_get_chip_data (struct device * dev )
513- {
514- struct device_node * of_node = dev -> of_node ;
515- const struct at24_chip_data * cdata ;
516- const struct i2c_device_id * id ;
517-
518- id = i2c_match_id (at24_ids , to_i2c_client (dev ));
519-
520- /*
521- * The I2C core allows OF nodes compatibles to match against the
522- * I2C device ID table as a fallback, so check not only if an OF
523- * node is present but also if it matches an OF device ID entry.
524- */
525- if (of_node && of_match_device (at24_of_match , dev ))
526- cdata = of_device_get_match_data (dev );
527- else if (id )
528- cdata = (void * )id -> driver_data ;
529- else
530- cdata = acpi_device_get_match_data (dev );
531-
532- if (!cdata )
533- return ERR_PTR (- ENODEV );
534-
535- return cdata ;
536- }
537-
538515static int at24_make_dummy_client (struct at24_data * at24 , unsigned int index ,
539516 struct i2c_client * base_client ,
540517 struct regmap_config * regmap_config )
@@ -626,9 +603,9 @@ static int at24_probe(struct i2c_client *client)
626603 i2c_fn_block = i2c_check_functionality (client -> adapter ,
627604 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK );
628605
629- cdata = at24_get_chip_data ( dev );
630- if (IS_ERR ( cdata ) )
631- return PTR_ERR ( cdata ) ;
606+ cdata = i2c_get_match_data ( client );
607+ if (! cdata )
608+ return - ENODEV ;
632609
633610 err = device_property_read_u32 (dev , "pagesize" , & page_size );
634611 if (err )
@@ -861,7 +838,7 @@ static struct i2c_driver at24_driver = {
861838 .driver = {
862839 .name = "at24" ,
863840 .pm = & at24_pm_ops ,
864- .of_match_table = at24_of_match ,
841+ .of_match_table = of_match_ptr ( at24_of_match ) ,
865842 .acpi_match_table = ACPI_PTR (at24_acpi_ids ),
866843 },
867844 .probe_new = at24_probe ,
0 commit comments