diff options
Diffstat (limited to 'drivers/rtc/rtc-m41t80.c')
-rw-r--r-- | drivers/rtc/rtc-m41t80.c | 81 |
1 files changed, 21 insertions, 60 deletions
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index 1cb33cac1237..316bfaa80872 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c | |||
@@ -60,48 +60,21 @@ | |||
60 | 60 | ||
61 | #define DRV_VERSION "0.05" | 61 | #define DRV_VERSION "0.05" |
62 | 62 | ||
63 | struct m41t80_chip_info { | 63 | static const struct i2c_device_id m41t80_id[] = { |
64 | const char *name; | 64 | { "m41t80", 0 }, |
65 | u8 features; | 65 | { "m41t81", M41T80_FEATURE_HT }, |
66 | }; | 66 | { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, |
67 | 67 | { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, | |
68 | static const struct m41t80_chip_info m41t80_chip_info_tbl[] = { | 68 | { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, |
69 | { | 69 | { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, |
70 | .name = "m41t80", | 70 | { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, |
71 | .features = 0, | 71 | { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, |
72 | }, | 72 | { } |
73 | { | ||
74 | .name = "m41t81", | ||
75 | .features = M41T80_FEATURE_HT, | ||
76 | }, | ||
77 | { | ||
78 | .name = "m41t81s", | ||
79 | .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL, | ||
80 | }, | ||
81 | { | ||
82 | .name = "m41t82", | ||
83 | .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL, | ||
84 | }, | ||
85 | { | ||
86 | .name = "m41t83", | ||
87 | .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL, | ||
88 | }, | ||
89 | { | ||
90 | .name = "m41st84", | ||
91 | .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL, | ||
92 | }, | ||
93 | { | ||
94 | .name = "m41st85", | ||
95 | .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL, | ||
96 | }, | ||
97 | { | ||
98 | .name = "m41st87", | ||
99 | .features = M41T80_FEATURE_HT | M41T80_FEATURE_BL, | ||
100 | }, | ||
101 | }; | 73 | }; |
74 | MODULE_DEVICE_TABLE(i2c, m41t80_id); | ||
102 | 75 | ||
103 | struct m41t80_data { | 76 | struct m41t80_data { |
104 | const struct m41t80_chip_info *chip; | 77 | u8 features; |
105 | struct rtc_device *rtc; | 78 | struct rtc_device *rtc; |
106 | }; | 79 | }; |
107 | 80 | ||
@@ -208,7 +181,7 @@ static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq) | |||
208 | struct m41t80_data *clientdata = i2c_get_clientdata(client); | 181 | struct m41t80_data *clientdata = i2c_get_clientdata(client); |
209 | u8 reg; | 182 | u8 reg; |
210 | 183 | ||
211 | if (clientdata->chip->features & M41T80_FEATURE_BL) { | 184 | if (clientdata->features & M41T80_FEATURE_BL) { |
212 | reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS); | 185 | reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS); |
213 | seq_printf(seq, "battery\t\t: %s\n", | 186 | seq_printf(seq, "battery\t\t: %s\n", |
214 | (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok"); | 187 | (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok"); |
@@ -756,12 +729,12 @@ static struct notifier_block wdt_notifier = { | |||
756 | * | 729 | * |
757 | ***************************************************************************** | 730 | ***************************************************************************** |
758 | */ | 731 | */ |
759 | static int m41t80_probe(struct i2c_client *client) | 732 | static int m41t80_probe(struct i2c_client *client, |
733 | const struct i2c_device_id *id) | ||
760 | { | 734 | { |
761 | int i, rc = 0; | 735 | int rc = 0; |
762 | struct rtc_device *rtc = NULL; | 736 | struct rtc_device *rtc = NULL; |
763 | struct rtc_time tm; | 737 | struct rtc_time tm; |
764 | const struct m41t80_chip_info *chip; | ||
765 | struct m41t80_data *clientdata = NULL; | 738 | struct m41t80_data *clientdata = NULL; |
766 | 739 | ||
767 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C | 740 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
@@ -773,19 +746,6 @@ static int m41t80_probe(struct i2c_client *client) | |||
773 | dev_info(&client->dev, | 746 | dev_info(&client->dev, |
774 | "chip found, driver version " DRV_VERSION "\n"); | 747 | "chip found, driver version " DRV_VERSION "\n"); |
775 | 748 | ||
776 | chip = NULL; | ||
777 | for (i = 0; i < ARRAY_SIZE(m41t80_chip_info_tbl); i++) { | ||
778 | if (!strcmp(m41t80_chip_info_tbl[i].name, client->name)) { | ||
779 | chip = &m41t80_chip_info_tbl[i]; | ||
780 | break; | ||
781 | } | ||
782 | } | ||
783 | if (!chip) { | ||
784 | dev_err(&client->dev, "%s is not supported\n", client->name); | ||
785 | rc = -ENODEV; | ||
786 | goto exit; | ||
787 | } | ||
788 | |||
789 | clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL); | 749 | clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL); |
790 | if (!clientdata) { | 750 | if (!clientdata) { |
791 | rc = -ENOMEM; | 751 | rc = -ENOMEM; |
@@ -801,7 +761,7 @@ static int m41t80_probe(struct i2c_client *client) | |||
801 | } | 761 | } |
802 | 762 | ||
803 | clientdata->rtc = rtc; | 763 | clientdata->rtc = rtc; |
804 | clientdata->chip = chip; | 764 | clientdata->features = id->driver_data; |
805 | i2c_set_clientdata(client, clientdata); | 765 | i2c_set_clientdata(client, clientdata); |
806 | 766 | ||
807 | /* Make sure HT (Halt Update) bit is cleared */ | 767 | /* Make sure HT (Halt Update) bit is cleared */ |
@@ -810,7 +770,7 @@ static int m41t80_probe(struct i2c_client *client) | |||
810 | goto ht_err; | 770 | goto ht_err; |
811 | 771 | ||
812 | if (rc & M41T80_ALHOUR_HT) { | 772 | if (rc & M41T80_ALHOUR_HT) { |
813 | if (chip->features & M41T80_FEATURE_HT) { | 773 | if (clientdata->features & M41T80_FEATURE_HT) { |
814 | m41t80_get_datetime(client, &tm); | 774 | m41t80_get_datetime(client, &tm); |
815 | dev_info(&client->dev, "HT bit was set!\n"); | 775 | dev_info(&client->dev, "HT bit was set!\n"); |
816 | dev_info(&client->dev, | 776 | dev_info(&client->dev, |
@@ -842,7 +802,7 @@ static int m41t80_probe(struct i2c_client *client) | |||
842 | goto exit; | 802 | goto exit; |
843 | 803 | ||
844 | #ifdef CONFIG_RTC_DRV_M41T80_WDT | 804 | #ifdef CONFIG_RTC_DRV_M41T80_WDT |
845 | if (chip->features & M41T80_FEATURE_HT) { | 805 | if (clientdata->features & M41T80_FEATURE_HT) { |
846 | rc = misc_register(&wdt_dev); | 806 | rc = misc_register(&wdt_dev); |
847 | if (rc) | 807 | if (rc) |
848 | goto exit; | 808 | goto exit; |
@@ -878,7 +838,7 @@ static int m41t80_remove(struct i2c_client *client) | |||
878 | struct rtc_device *rtc = clientdata->rtc; | 838 | struct rtc_device *rtc = clientdata->rtc; |
879 | 839 | ||
880 | #ifdef CONFIG_RTC_DRV_M41T80_WDT | 840 | #ifdef CONFIG_RTC_DRV_M41T80_WDT |
881 | if (clientdata->chip->features & M41T80_FEATURE_HT) { | 841 | if (clientdata->features & M41T80_FEATURE_HT) { |
882 | misc_deregister(&wdt_dev); | 842 | misc_deregister(&wdt_dev); |
883 | unregister_reboot_notifier(&wdt_notifier); | 843 | unregister_reboot_notifier(&wdt_notifier); |
884 | } | 844 | } |
@@ -896,6 +856,7 @@ static struct i2c_driver m41t80_driver = { | |||
896 | }, | 856 | }, |
897 | .probe = m41t80_probe, | 857 | .probe = m41t80_probe, |
898 | .remove = m41t80_remove, | 858 | .remove = m41t80_remove, |
859 | .id_table = m41t80_id, | ||
899 | }; | 860 | }; |
900 | 861 | ||
901 | static int __init m41t80_rtc_init(void) | 862 | static int __init m41t80_rtc_init(void) |