hc
2024-05-10 ee930fffee469d076998274a2ca55e13dc1efb67
kernel/drivers/misc/eeprom/at24.c
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0+
1
+// SPDX-License-Identifier: GPL-2.0-or-later
22 /*
33 * at24.c - handle most I2C EEPROMs
44 *
....@@ -6,26 +6,39 @@
66 * Copyright (C) 2008 Wolfram Sang, Pengutronix
77 */
88
9
-#define DEBUG
10
-#include <linux/kernel.h>
11
-#include <linux/init.h>
12
-#include <linux/module.h>
13
-#include <linux/of_device.h>
14
-#include <linux/slab.h>
15
-#include <linux/delay.h>
16
-#include <linux/mutex.h>
17
-#include <linux/mod_devicetable.h>
18
-#include <linux/log2.h>
19
-#include <linux/bitops.h>
20
-#include <linux/jiffies.h>
21
-#include <linux/property.h>
229 #include <linux/acpi.h>
10
+#include <linux/bitops.h>
11
+#include <linux/capability.h>
12
+#include <linux/delay.h>
2313 #include <linux/i2c.h>
14
+#include <linux/init.h>
15
+#include <linux/jiffies.h>
16
+#include <linux/kernel.h>
17
+#include <linux/mod_devicetable.h>
18
+#include <linux/module.h>
19
+#include <linux/mutex.h>
2420 #include <linux/nvmem-provider.h>
25
-#include <linux/regmap.h>
26
-#include <linux/platform_data/at24.h>
21
+#include <linux/of_device.h>
2722 #include <linux/pm_runtime.h>
28
-#include <linux/gpio/consumer.h>
23
+#include <linux/property.h>
24
+#include <linux/regmap.h>
25
+#include <linux/regulator/consumer.h>
26
+#include <linux/slab.h>
27
+
28
+/* Address pointer is 16 bit. */
29
+#define AT24_FLAG_ADDR16 BIT(7)
30
+/* sysfs-entry will be read-only. */
31
+#define AT24_FLAG_READONLY BIT(6)
32
+/* sysfs-entry will be world-readable. */
33
+#define AT24_FLAG_IRUGO BIT(5)
34
+/* Take always 8 addresses (24c00). */
35
+#define AT24_FLAG_TAKE8ADDR BIT(4)
36
+/* Factory-programmed serial number. */
37
+#define AT24_FLAG_SERIAL BIT(3)
38
+/* Factory-programmed mac address. */
39
+#define AT24_FLAG_MAC BIT(2)
40
+/* Does not auto-rollover reads to the next slave address. */
41
+#define AT24_FLAG_NO_RDROL BIT(1)
2942
3043 /*
3144 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
....@@ -76,8 +89,8 @@
7689 u8 flags;
7790
7891 struct nvmem_device *nvmem;
79
-
80
- struct gpio_desc *wp_gpio;
92
+ struct regulator *vcc_reg;
93
+ void (*read_post)(unsigned int off, char *buf, size_t count);
8194
8295 /*
8396 * Some chips tie up multiple I2C addresses; dummy devices reserve
....@@ -107,21 +120,44 @@
107120 module_param_named(write_timeout, at24_write_timeout, uint, 0);
108121 MODULE_PARM_DESC(at24_write_timeout, "Time (in ms) to try writes (default 25)");
109122
110
-//Ben
111123 struct at24_data *at24_private=NULL;
124
+
112125 struct at24_chip_data {
113
- /*
114
- * these fields mirror their equivalents in
115
- * struct at24_platform_data
116
- */
117126 u32 byte_len;
118127 u8 flags;
128
+ void (*read_post)(unsigned int off, char *buf, size_t count);
119129 };
120130
121131 #define AT24_CHIP_DATA(_name, _len, _flags) \
122132 static const struct at24_chip_data _name = { \
123133 .byte_len = _len, .flags = _flags, \
124134 }
135
+
136
+#define AT24_CHIP_DATA_CB(_name, _len, _flags, _read_post) \
137
+ static const struct at24_chip_data _name = { \
138
+ .byte_len = _len, .flags = _flags, \
139
+ .read_post = _read_post, \
140
+ }
141
+
142
+static void at24_read_post_vaio(unsigned int off, char *buf, size_t count)
143
+{
144
+ int i;
145
+
146
+ if (capable(CAP_SYS_ADMIN))
147
+ return;
148
+
149
+ /*
150
+ * Hide VAIO private settings to regular users:
151
+ * - BIOS passwords: bytes 0x00 to 0x0f
152
+ * - UUID: bytes 0x10 to 0x1f
153
+ * - Serial number: 0xc0 to 0xdf
154
+ */
155
+ for (i = 0; i < count; i++) {
156
+ if ((off + i <= 0x1f) ||
157
+ (off + i >= 0xc0 && off + i <= 0xdf))
158
+ buf[i] = 0;
159
+ }
160
+}
125161
126162 /* needs 8 addresses as A0-A2 are ignored */
127163 AT24_CHIP_DATA(at24_data_24c00, 128 / 8, AT24_FLAG_TAKE8ADDR);
....@@ -139,6 +175,10 @@
139175 /* spd is a 24c02 in memory DIMMs */
140176 AT24_CHIP_DATA(at24_data_spd, 2048 / 8,
141177 AT24_FLAG_READONLY | AT24_FLAG_IRUGO);
178
+/* 24c02_vaio is a 24c02 on some Sony laptops */
179
+AT24_CHIP_DATA_CB(at24_data_24c02_vaio, 2048 / 8,
180
+ AT24_FLAG_READONLY | AT24_FLAG_IRUGO,
181
+ at24_read_post_vaio);
142182 AT24_CHIP_DATA(at24_data_24c04, 4096 / 8, 0);
143183 AT24_CHIP_DATA(at24_data_24cs04, 16,
144184 AT24_FLAG_SERIAL | AT24_FLAG_READONLY);
....@@ -172,6 +212,7 @@
172212 { "24mac402", (kernel_ulong_t)&at24_data_24mac402 },
173213 { "24mac602", (kernel_ulong_t)&at24_data_24mac602 },
174214 { "spd", (kernel_ulong_t)&at24_data_spd },
215
+ { "24c02-vaio", (kernel_ulong_t)&at24_data_24c02_vaio },
175216 { "24c04", (kernel_ulong_t)&at24_data_24c04 },
176217 { "24cs04", (kernel_ulong_t)&at24_data_24cs04 },
177218 { "24c08", (kernel_ulong_t)&at24_data_24c08 },
....@@ -220,8 +261,9 @@
220261 };
221262 MODULE_DEVICE_TABLE(of, at24_of_match);
222263
223
-static const struct acpi_device_id at24_acpi_ids[] = {
264
+static const struct acpi_device_id __maybe_unused at24_acpi_ids[] = {
224265 { "INT3499", (kernel_ulong_t)&at24_data_INT3499 },
266
+ { "TPF0001", (kernel_ulong_t)&at24_data_24c1024 },
225267 { /* END OF LIST */ }
226268 };
227269 MODULE_DEVICE_TABLE(acpi, at24_acpi_ids);
....@@ -382,7 +424,7 @@
382424 struct at24_data *at24;
383425 struct device *dev;
384426 char *buf = val;
385
- int ret;
427
+ int i, ret;
386428
387429 at24 = priv;
388430 dev = at24_base_client_dev(at24);
....@@ -405,26 +447,27 @@
405447 */
406448 mutex_lock(&at24->lock);
407449
408
- while (count) {
409
- ret = at24_regmap_read(at24, buf, off, count);
450
+ for (i = 0; count; i += ret, count -= ret) {
451
+ ret = at24_regmap_read(at24, buf + i, off + i, count);
410452 if (ret < 0) {
411453 mutex_unlock(&at24->lock);
412454 pm_runtime_put(dev);
413455 return ret;
414456 }
415
- buf += ret;
416
- off += ret;
417
- count -= ret;
418457 }
419458
420459 mutex_unlock(&at24->lock);
421460
422461 pm_runtime_put(dev);
423462
463
+ if (unlikely(at24->read_post))
464
+ at24->read_post(off, buf, i);
465
+
424466 return 0;
425467 }
426468
427
-//add ben
469
+
470
+
428471 static ssize_t at24_read_private(struct at24_data *at24,
429472 char *buf, loff_t off, size_t count)
430473 {
....@@ -564,33 +607,6 @@
564607 }
565608 EXPORT_SYMBOL(at24_mac1_read);
566609
567
-ssize_t at24_mac2_read(unsigned char* mac)
568
-{
569
- char buf[20];
570
- char buf_tmp[12];
571
- ssize_t ret;
572
- if (at24_private == NULL)
573
- {
574
- printk("zcl: at24_mac_read at24_private==null error");
575
- return 0;
576
- }
577
- memset(buf, 0x00, 20);
578
- memset(buf_tmp, 0x00, 12);
579
- ret = at24_read_private(at24_private, buf, 0x20, 6);
580
- if (ret > 0)
581
- {
582
- *mac = buf[0];
583
- *(mac + 1) = buf[1];
584
- *(mac + 2) = buf[2];
585
- *(mac + 3) = buf[3];
586
- *(mac + 4) = buf[4];
587
- *(mac + 5) = buf[5];
588
- }
589
- printk("at24_mac2_read ...............\n");
590
- return ret;
591
-}
592
-EXPORT_SYMBOL(at24_mac2_read);
593
-
594610 static int at24_write(void *priv, unsigned int off, void *val, size_t count)
595611 {
596612 struct at24_data *at24;
....@@ -618,12 +634,10 @@
618634 * from this host, but not from other I2C masters.
619635 */
620636 mutex_lock(&at24->lock);
621
- gpiod_set_value_cansleep(at24->wp_gpio, 0);
622637
623638 while (count) {
624639 ret = at24_regmap_write(at24, buf, off, count);
625640 if (ret < 0) {
626
- gpiod_set_value_cansleep(at24->wp_gpio, 1);
627641 mutex_unlock(&at24->lock);
628642 pm_runtime_put(dev);
629643 return ret;
....@@ -633,7 +647,6 @@
633647 count -= ret;
634648 }
635649
636
- gpiod_set_value_cansleep(at24->wp_gpio, 1);
637650 mutex_unlock(&at24->lock);
638651
639652 pm_runtime_put(dev);
....@@ -641,63 +654,11 @@
641654 return 0;
642655 }
643656
644
-static void at24_properties_to_pdata(struct device *dev,
645
- struct at24_platform_data *chip)
646
-{
647
- int err;
648
- u32 val;
649
-
650
- if (device_property_present(dev, "read-only"))
651
- chip->flags |= AT24_FLAG_READONLY;
652
- if (device_property_present(dev, "no-read-rollover"))
653
- chip->flags |= AT24_FLAG_NO_RDROL;
654
-
655
- err = device_property_read_u32(dev, "address-width", &val);
656
- if (!err) {
657
- switch (val) {
658
- case 8:
659
- if (chip->flags & AT24_FLAG_ADDR16)
660
- dev_warn(dev, "Override address width to be 8, while default is 16\n");
661
- chip->flags &= ~AT24_FLAG_ADDR16;
662
- break;
663
- case 16:
664
- chip->flags |= AT24_FLAG_ADDR16;
665
- break;
666
- default:
667
- dev_warn(dev, "Bad \"address-width\" property: %u\n",
668
- val);
669
- }
670
- }
671
-
672
- err = device_property_read_u32(dev, "size", &val);
673
- if (!err)
674
- chip->byte_len = val;
675
-
676
- err = device_property_read_u32(dev, "pagesize", &val);
677
- if (!err) {
678
- chip->page_size = val;
679
- } else {
680
- /*
681
- * This is slow, but we can't know all eeproms, so we better
682
- * play safe. Specifying custom eeprom-types via platform_data
683
- * is recommended anyhow.
684
- */
685
- chip->page_size = 1;
686
- }
687
-}
688
-
689
-static int at24_get_pdata(struct device *dev, struct at24_platform_data *pdata)
657
+static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
690658 {
691659 struct device_node *of_node = dev->of_node;
692660 const struct at24_chip_data *cdata;
693661 const struct i2c_device_id *id;
694
- struct at24_platform_data *pd;
695
-
696
- pd = dev_get_platdata(dev);
697
- if (pd) {
698
- memcpy(pdata, pd, sizeof(*pdata));
699
- return 0;
700
- }
701662
702663 id = i2c_match_id(at24_ids, to_i2c_client(dev));
703664
....@@ -714,47 +675,29 @@
714675 cdata = acpi_device_get_match_data(dev);
715676
716677 if (!cdata)
717
- return -ENODEV;
678
+ return ERR_PTR(-ENODEV);
718679
719
- pdata->byte_len = cdata->byte_len;
720
- pdata->flags = cdata->flags;
721
- at24_properties_to_pdata(dev, pdata);
722
-
723
- return 0;
724
-}
725
-
726
-static void at24_remove_dummy_clients(struct at24_data *at24)
727
-{
728
- int i;
729
-
730
- for (i = 1; i < at24->num_addresses; i++)
731
- i2c_unregister_device(at24->client[i].client);
680
+ return cdata;
732681 }
733682
734683 static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
735684 struct regmap_config *regmap_config)
736685 {
737686 struct i2c_client *base_client, *dummy_client;
738
- unsigned short int addr;
739687 struct regmap *regmap;
740688 struct device *dev;
741689
742690 base_client = at24->client[0].client;
743691 dev = &base_client->dev;
744
- addr = base_client->addr + index;
745692
746
- dummy_client = i2c_new_dummy(base_client->adapter,
747
- base_client->addr + index);
748
- if (!dummy_client) {
749
- dev_err(dev, "address 0x%02x unavailable\n", addr);
750
- return -EADDRINUSE;
751
- }
693
+ dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter,
694
+ base_client->addr + index);
695
+ if (IS_ERR(dummy_client))
696
+ return PTR_ERR(dummy_client);
752697
753698 regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
754
- if (IS_ERR(regmap)) {
755
- i2c_unregister_device(dummy_client);
699
+ if (IS_ERR(regmap))
756700 return PTR_ERR(regmap);
757
- }
758701
759702 at24->client[index].client = dummy_client;
760703 at24->client[index].regmap = regmap;
....@@ -789,80 +732,120 @@
789732 {
790733 struct regmap_config regmap_config = { };
791734 struct nvmem_config nvmem_config = { };
792
- struct at24_platform_data pdata = { };
735
+ u32 byte_len, page_size, flags, addrw;
736
+ const struct at24_chip_data *cdata;
793737 struct device *dev = &client->dev;
794738 bool i2c_fn_i2c, i2c_fn_block;
795739 unsigned int i, num_addresses;
796740 struct at24_data *at24;
797741 struct regmap *regmap;
798
- size_t at24_size;
799742 bool writable;
800743 u8 test_byte;
801744 int err;
802745
803
- printk("ben %s ...\n", __func__);
804746 i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
805747 i2c_fn_block = i2c_check_functionality(client->adapter,
806748 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK);
807749
808
- err = at24_get_pdata(dev, &pdata);
750
+ cdata = at24_get_chip_data(dev);
751
+ if (IS_ERR(cdata))
752
+ return PTR_ERR(cdata);
753
+
754
+ err = device_property_read_u32(dev, "pagesize", &page_size);
809755 if (err)
810
- return err;
756
+ /*
757
+ * This is slow, but we can't know all eeproms, so we better
758
+ * play safe. Specifying custom eeprom-types via device tree
759
+ * or properties is recommended anyhow.
760
+ */
761
+ page_size = 1;
762
+
763
+ flags = cdata->flags;
764
+ if (device_property_present(dev, "read-only"))
765
+ flags |= AT24_FLAG_READONLY;
766
+ if (device_property_present(dev, "no-read-rollover"))
767
+ flags |= AT24_FLAG_NO_RDROL;
768
+
769
+ err = device_property_read_u32(dev, "address-width", &addrw);
770
+ if (!err) {
771
+ switch (addrw) {
772
+ case 8:
773
+ if (flags & AT24_FLAG_ADDR16)
774
+ dev_warn(dev,
775
+ "Override address width to be 8, while default is 16\n");
776
+ flags &= ~AT24_FLAG_ADDR16;
777
+ break;
778
+ case 16:
779
+ flags |= AT24_FLAG_ADDR16;
780
+ break;
781
+ default:
782
+ dev_warn(dev, "Bad \"address-width\" property: %u\n",
783
+ addrw);
784
+ }
785
+ }
786
+
787
+ err = device_property_read_u32(dev, "size", &byte_len);
788
+ if (err)
789
+ byte_len = cdata->byte_len;
811790
812791 if (!i2c_fn_i2c && !i2c_fn_block)
813
- pdata.page_size = 1;
792
+ page_size = 1;
814793
815
- if (!pdata.page_size) {
794
+ if (!page_size) {
816795 dev_err(dev, "page_size must not be 0!\n");
817796 return -EINVAL;
818797 }
819798
820
- if (!is_power_of_2(pdata.page_size))
799
+ if (!is_power_of_2(page_size))
821800 dev_warn(dev, "page_size looks suspicious (no power of 2)!\n");
822801
823
- if (pdata.flags & AT24_FLAG_TAKE8ADDR)
824
- num_addresses = 8;
825
- else
826
- num_addresses = DIV_ROUND_UP(pdata.byte_len,
827
- (pdata.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
802
+ err = device_property_read_u32(dev, "num-addresses", &num_addresses);
803
+ if (err) {
804
+ if (flags & AT24_FLAG_TAKE8ADDR)
805
+ num_addresses = 8;
806
+ else
807
+ num_addresses = DIV_ROUND_UP(byte_len,
808
+ (flags & AT24_FLAG_ADDR16) ? 65536 : 256);
809
+ }
828810
829
- if ((pdata.flags & AT24_FLAG_SERIAL) && (pdata.flags & AT24_FLAG_MAC)) {
811
+ if ((flags & AT24_FLAG_SERIAL) && (flags & AT24_FLAG_MAC)) {
830812 dev_err(dev,
831813 "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC.");
832814 return -EINVAL;
833815 }
834816
835817 regmap_config.val_bits = 8;
836
- regmap_config.reg_bits = (pdata.flags & AT24_FLAG_ADDR16) ? 16 : 8;
818
+ regmap_config.reg_bits = (flags & AT24_FLAG_ADDR16) ? 16 : 8;
837819 regmap_config.disable_locking = true;
838820
839821 regmap = devm_regmap_init_i2c(client, &regmap_config);
840822 if (IS_ERR(regmap))
841823 return PTR_ERR(regmap);
842824
843
- at24_size = sizeof(*at24) + num_addresses * sizeof(struct at24_client);
844
- at24 = devm_kzalloc(dev, at24_size, GFP_KERNEL);
825
+ at24 = devm_kzalloc(dev, struct_size(at24, client, num_addresses),
826
+ GFP_KERNEL);
845827 if (!at24)
846828 return -ENOMEM;
847829
848830 at24_private = at24;
849831 mutex_init(&at24->lock);
850
- at24->byte_len = pdata.byte_len;
851
- at24->page_size = pdata.page_size;
852
- at24->flags = pdata.flags;
832
+ at24->byte_len = byte_len;
833
+ at24->page_size = page_size;
834
+ at24->flags = flags;
835
+ at24->read_post = cdata->read_post;
853836 at24->num_addresses = num_addresses;
854
- at24->offset_adj = at24_get_offset_adj(pdata.flags, pdata.byte_len);
837
+ at24->offset_adj = at24_get_offset_adj(flags, byte_len);
855838 at24->client[0].client = client;
856839 at24->client[0].regmap = regmap;
857840
858
- at24->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_HIGH);
859
- if (IS_ERR(at24->wp_gpio))
860
- return PTR_ERR(at24->wp_gpio);
841
+ at24->vcc_reg = devm_regulator_get(dev, "vcc");
842
+ if (IS_ERR(at24->vcc_reg))
843
+ return PTR_ERR(at24->vcc_reg);
861844
862
- writable = !(pdata.flags & AT24_FLAG_READONLY);
845
+ writable = !(flags & AT24_FLAG_READONLY);
863846 if (writable) {
864847 at24->write_max = min_t(unsigned int,
865
- pdata.page_size, at24_io_limit);
848
+ page_size, at24_io_limit);
866849 if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX)
867850 at24->write_max = I2C_SMBUS_BLOCK_MAX;
868851 }
....@@ -870,33 +853,32 @@
870853 /* use dummy devices for multiple-address chips */
871854 for (i = 1; i < num_addresses; i++) {
872855 err = at24_make_dummy_client(at24, i, &regmap_config);
873
- if (err) {
874
- at24_remove_dummy_clients(at24);
856
+ if (err)
875857 return err;
876
- }
877858 }
878
-
879
- i2c_set_clientdata(client, at24);
880
-
881
- /* enable runtime pm */
882
- pm_runtime_set_active(dev);
883
- pm_runtime_enable(dev);
884859
885860 /*
886
- * Perform a one-byte test read to verify that the
887
- * chip is functional.
861
+ * We initialize nvmem_config.id to NVMEM_DEVID_AUTO even if the
862
+ * label property is set as some platform can have multiple eeproms
863
+ * with same label and we can not register each of those with same
864
+ * label. Failing to register those eeproms trigger cascade failure
865
+ * on such platform.
888866 */
889
- err = at24_read(at24, 0, &test_byte, 1);
890
- pm_runtime_idle(dev);
891
- if (err) {
892
- err = -ENODEV;
893
- goto err_clients;
867
+ nvmem_config.id = NVMEM_DEVID_AUTO;
868
+
869
+ if (device_property_present(dev, "label")) {
870
+ err = device_property_read_string(dev, "label",
871
+ &nvmem_config.name);
872
+ if (err)
873
+ return err;
874
+ } else {
875
+ nvmem_config.name = dev_name(dev);
894876 }
895877
896
- nvmem_config.name = dev_name(dev);
878
+ nvmem_config.type = NVMEM_TYPE_EEPROM;
897879 nvmem_config.dev = dev;
898880 nvmem_config.read_only = !writable;
899
- nvmem_config.root_only = !(pdata.flags & AT24_FLAG_IRUGO);
881
+ nvmem_config.root_only = !(flags & AT24_FLAG_IRUGO);
900882 nvmem_config.owner = THIS_MODULE;
901883 nvmem_config.compat = true;
902884 nvmem_config.base_dev = dev;
....@@ -905,47 +887,90 @@
905887 nvmem_config.priv = at24;
906888 nvmem_config.stride = 1;
907889 nvmem_config.word_size = 1;
908
- nvmem_config.size = pdata.byte_len;
890
+ nvmem_config.size = byte_len;
891
+
892
+ i2c_set_clientdata(client, at24);
893
+
894
+ err = regulator_enable(at24->vcc_reg);
895
+ if (err) {
896
+ dev_err(dev, "Failed to enable vcc regulator\n");
897
+ return err;
898
+ }
899
+
900
+ /* enable runtime pm */
901
+ pm_runtime_set_active(dev);
902
+ pm_runtime_enable(dev);
909903
910904 at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
911905 if (IS_ERR(at24->nvmem)) {
912
- err = PTR_ERR(at24->nvmem);
913
- goto err_clients;
906
+ pm_runtime_disable(dev);
907
+ if (!pm_runtime_status_suspended(dev))
908
+ regulator_disable(at24->vcc_reg);
909
+ return PTR_ERR(at24->nvmem);
914910 }
915911
916
- dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n",
917
- pdata.byte_len, client->name,
918
- writable ? "writable" : "read-only", at24->write_max);
912
+ /*
913
+ * Perform a one-byte test read to verify that the
914
+ * chip is functional.
915
+ */
916
+ err = at24_read(at24, 0, &test_byte, 1);
917
+ if (err) {
918
+ pm_runtime_disable(dev);
919
+ if (!pm_runtime_status_suspended(dev))
920
+ regulator_disable(at24->vcc_reg);
921
+ return -ENODEV;
922
+ }
919923
920
- /* export data to kernel code */
921
- if (pdata.setup)
922
- pdata.setup(at24->nvmem, pdata.context);
924
+ pm_runtime_idle(dev);
925
+
926
+ if (writable)
927
+ dev_info(dev, "%u byte %s EEPROM, writable, %u bytes/write\n",
928
+ byte_len, client->name, at24->write_max);
929
+ else
930
+ dev_info(dev, "%u byte %s EEPROM, read-only\n",
931
+ byte_len, client->name);
923932
924933 return 0;
925
-
926
-err_clients:
927
- at24_remove_dummy_clients(at24);
928
- pm_runtime_disable(dev);
929
-
930
- return err;
931934 }
932935
933936 static int at24_remove(struct i2c_client *client)
934937 {
935
- struct at24_data *at24;
938
+ struct at24_data *at24 = i2c_get_clientdata(client);
936939
937
- at24 = i2c_get_clientdata(client);
938
-
939
- at24_remove_dummy_clients(at24);
940940 pm_runtime_disable(&client->dev);
941
+ if (!pm_runtime_status_suspended(&client->dev))
942
+ regulator_disable(at24->vcc_reg);
941943 pm_runtime_set_suspended(&client->dev);
942944
943945 return 0;
944946 }
945947
948
+static int __maybe_unused at24_suspend(struct device *dev)
949
+{
950
+ struct i2c_client *client = to_i2c_client(dev);
951
+ struct at24_data *at24 = i2c_get_clientdata(client);
952
+
953
+ return regulator_disable(at24->vcc_reg);
954
+}
955
+
956
+static int __maybe_unused at24_resume(struct device *dev)
957
+{
958
+ struct i2c_client *client = to_i2c_client(dev);
959
+ struct at24_data *at24 = i2c_get_clientdata(client);
960
+
961
+ return regulator_enable(at24->vcc_reg);
962
+}
963
+
964
+static const struct dev_pm_ops at24_pm_ops = {
965
+ SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
966
+ pm_runtime_force_resume)
967
+ SET_RUNTIME_PM_OPS(at24_suspend, at24_resume, NULL)
968
+};
969
+
946970 static struct i2c_driver at24_driver = {
947971 .driver = {
948972 .name = "at24",
973
+ .pm = &at24_pm_ops,
949974 .of_match_table = at24_of_match,
950975 .acpi_match_table = ACPI_PTR(at24_acpi_ids),
951976 },