aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/hwmon/f75375s.c89
1 files changed, 12 insertions, 77 deletions
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index dc1f30e432ea..1692de369969 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -87,7 +87,6 @@ I2C_CLIENT_INSMOD_2(f75373, f75375);
87 87
88struct f75375_data { 88struct f75375_data {
89 unsigned short addr; 89 unsigned short addr;
90 struct i2c_client *client;
91 struct device *hwmon_dev; 90 struct device *hwmon_dev;
92 91
93 const char *name; 92 const char *name;
@@ -114,21 +113,12 @@ struct f75375_data {
114 s8 temp_max_hyst[2]; 113 s8 temp_max_hyst[2];
115}; 114};
116 115
117static int f75375_attach_adapter(struct i2c_adapter *adapter); 116static int f75375_detect(struct i2c_client *client, int kind,
118static int f75375_detect(struct i2c_adapter *adapter, int address, int kind); 117 struct i2c_board_info *info);
119static int f75375_detach_client(struct i2c_client *client);
120static int f75375_probe(struct i2c_client *client, 118static int f75375_probe(struct i2c_client *client,
121 const struct i2c_device_id *id); 119 const struct i2c_device_id *id);
122static int f75375_remove(struct i2c_client *client); 120static int f75375_remove(struct i2c_client *client);
123 121
124static struct i2c_driver f75375_legacy_driver = {
125 .driver = {
126 .name = "f75375_legacy",
127 },
128 .attach_adapter = f75375_attach_adapter,
129 .detach_client = f75375_detach_client,
130};
131
132static const struct i2c_device_id f75375_id[] = { 122static const struct i2c_device_id f75375_id[] = {
133 { "f75373", f75373 }, 123 { "f75373", f75373 },
134 { "f75375", f75375 }, 124 { "f75375", f75375 },
@@ -137,12 +127,15 @@ static const struct i2c_device_id f75375_id[] = {
137MODULE_DEVICE_TABLE(i2c, f75375_id); 127MODULE_DEVICE_TABLE(i2c, f75375_id);
138 128
139static struct i2c_driver f75375_driver = { 129static struct i2c_driver f75375_driver = {
130 .class = I2C_CLASS_HWMON,
140 .driver = { 131 .driver = {
141 .name = "f75375", 132 .name = "f75375",
142 }, 133 },
143 .probe = f75375_probe, 134 .probe = f75375_probe,
144 .remove = f75375_remove, 135 .remove = f75375_remove,
145 .id_table = f75375_id, 136 .id_table = f75375_id,
137 .detect = f75375_detect,
138 .address_data = &addr_data,
146}; 139};
147 140
148static inline int f75375_read8(struct i2c_client *client, u8 reg) 141static inline int f75375_read8(struct i2c_client *client, u8 reg)
@@ -607,22 +600,6 @@ static const struct attribute_group f75375_group = {
607 .attrs = f75375_attributes, 600 .attrs = f75375_attributes,
608}; 601};
609 602
610static int f75375_detach_client(struct i2c_client *client)
611{
612 int err;
613
614 f75375_remove(client);
615 err = i2c_detach_client(client);
616 if (err) {
617 dev_err(&client->dev,
618 "Client deregistration failed, "
619 "client not detached.\n");
620 return err;
621 }
622 kfree(client);
623 return 0;
624}
625
626static void f75375_init(struct i2c_client *client, struct f75375_data *data, 603static void f75375_init(struct i2c_client *client, struct f75375_data *data,
627 struct f75375s_platform_data *f75375s_pdata) 604 struct f75375s_platform_data *f75375s_pdata)
628{ 605{
@@ -651,7 +628,6 @@ static int f75375_probe(struct i2c_client *client,
651 return -ENOMEM; 628 return -ENOMEM;
652 629
653 i2c_set_clientdata(client, data); 630 i2c_set_clientdata(client, data);
654 data->client = client;
655 mutex_init(&data->update_lock); 631 mutex_init(&data->update_lock);
656 data->kind = id->driver_data; 632 data->kind = id->driver_data;
657 633
@@ -700,29 +676,13 @@ static int f75375_remove(struct i2c_client *client)
700 return 0; 676 return 0;
701} 677}
702 678
703static int f75375_attach_adapter(struct i2c_adapter *adapter) 679/* Return 0 if detection is successful, -ENODEV otherwise */
704{ 680static int f75375_detect(struct i2c_client *client, int kind,
705 if (!(adapter->class & I2C_CLASS_HWMON)) 681 struct i2c_board_info *info)
706 return 0;
707 return i2c_probe(adapter, &addr_data, f75375_detect);
708}
709
710/* This function is called by i2c_probe */
711static int f75375_detect(struct i2c_adapter *adapter, int address, int kind)
712{ 682{
713 struct i2c_client *client; 683 struct i2c_adapter *adapter = client->adapter;
714 u8 version = 0; 684 u8 version = 0;
715 int err = 0;
716 const char *name = ""; 685 const char *name = "";
717 struct i2c_device_id id;
718
719 if (!(client = kzalloc(sizeof(*client), GFP_KERNEL))) {
720 err = -ENOMEM;
721 goto exit;
722 }
723 client->addr = address;
724 client->adapter = adapter;
725 client->driver = &f75375_legacy_driver;
726 686
727 if (kind < 0) { 687 if (kind < 0) {
728 u16 vendid = f75375_read16(client, F75375_REG_VENDOR); 688 u16 vendid = f75375_read16(client, F75375_REG_VENDOR);
@@ -736,7 +696,7 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind)
736 dev_err(&adapter->dev, 696 dev_err(&adapter->dev,
737 "failed,%02X,%02X,%02X\n", 697 "failed,%02X,%02X,%02X\n",
738 chipid, version, vendid); 698 chipid, version, vendid);
739 goto exit_free; 699 return -ENODEV;
740 } 700 }
741 } 701 }
742 702
@@ -746,43 +706,18 @@ static int f75375_detect(struct i2c_adapter *adapter, int address, int kind)
746 name = "f75373"; 706 name = "f75373";
747 } 707 }
748 dev_info(&adapter->dev, "found %s version: %02X\n", name, version); 708 dev_info(&adapter->dev, "found %s version: %02X\n", name, version);
749 strlcpy(client->name, name, I2C_NAME_SIZE); 709 strlcpy(info->type, name, I2C_NAME_SIZE);
750
751 if ((err = i2c_attach_client(client)))
752 goto exit_free;
753
754 strlcpy(id.name, name, I2C_NAME_SIZE);
755 id.driver_data = kind;
756 if ((err = f75375_probe(client, &id)) < 0)
757 goto exit_detach;
758 710
759 return 0; 711 return 0;
760
761exit_detach:
762 i2c_detach_client(client);
763exit_free:
764 kfree(client);
765exit:
766 return err;
767} 712}
768 713
769static int __init sensors_f75375_init(void) 714static int __init sensors_f75375_init(void)
770{ 715{
771 int status; 716 return i2c_add_driver(&f75375_driver);
772 status = i2c_add_driver(&f75375_driver);
773 if (status)
774 return status;
775
776 status = i2c_add_driver(&f75375_legacy_driver);
777 if (status)
778 i2c_del_driver(&f75375_driver);
779
780 return status;
781} 717}
782 718
783static void __exit sensors_f75375_exit(void) 719static void __exit sensors_f75375_exit(void)
784{ 720{
785 i2c_del_driver(&f75375_legacy_driver);
786 i2c_del_driver(&f75375_driver); 721 i2c_del_driver(&f75375_driver);
787} 722}
788 723