aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew F. Davis <afd@ti.com>2016-08-02 17:07:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-08-02 19:35:39 -0400
commit098f9fb0c962eb2fdba5f9d34f4cf7a938237184 (patch)
tree9f0ed4b3613e27b22c200e1f6f64a1089673f87c
parent0b9364b5cf11c6e504f4b77e24b15a0dc8a82df0 (diff)
w1: remove need for ida and use PLATFORM_DEVID_AUTO
PLATFORM_DEVID_AUTO can be used to have the platform core assign a unique ID instead of manually creating one with IDA. Do this in all applicable drivers. Link: http://lkml.kernel.org/r/20160531204313.20979-1-afd@ti.com Signed-off-by: Andrew F. Davis <afd@ti.com> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/w1/slaves/w1_ds2760.c28
-rw-r--r--drivers/w1/slaves/w1_ds2780.c25
-rw-r--r--drivers/w1/slaves/w1_ds2781.c26
3 files changed, 13 insertions, 66 deletions
diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c
index d9079d48d112..59a81cfe64d5 100644
--- a/drivers/w1/slaves/w1_ds2760.c
+++ b/drivers/w1/slaves/w1_ds2760.c
@@ -121,25 +121,14 @@ static const struct attribute_group *w1_ds2760_groups[] = {
121 NULL, 121 NULL,
122}; 122};
123 123
124static DEFINE_IDA(bat_ida);
125
126static int w1_ds2760_add_slave(struct w1_slave *sl) 124static int w1_ds2760_add_slave(struct w1_slave *sl)
127{ 125{
128 int ret; 126 int ret;
129 int id;
130 struct platform_device *pdev; 127 struct platform_device *pdev;
131 128
132 id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); 129 pdev = platform_device_alloc("ds2760-battery", PLATFORM_DEVID_AUTO);
133 if (id < 0) { 130 if (!pdev)
134 ret = id; 131 return -ENOMEM;
135 goto noid;
136 }
137
138 pdev = platform_device_alloc("ds2760-battery", id);
139 if (!pdev) {
140 ret = -ENOMEM;
141 goto pdev_alloc_failed;
142 }
143 pdev->dev.parent = &sl->dev; 132 pdev->dev.parent = &sl->dev;
144 133
145 ret = platform_device_add(pdev); 134 ret = platform_device_add(pdev);
@@ -148,24 +137,19 @@ static int w1_ds2760_add_slave(struct w1_slave *sl)
148 137
149 dev_set_drvdata(&sl->dev, pdev); 138 dev_set_drvdata(&sl->dev, pdev);
150 139
151 goto success; 140 return 0;
152 141
153pdev_add_failed: 142pdev_add_failed:
154 platform_device_put(pdev); 143 platform_device_put(pdev);
155pdev_alloc_failed: 144
156 ida_simple_remove(&bat_ida, id);
157noid:
158success:
159 return ret; 145 return ret;
160} 146}
161 147
162static void w1_ds2760_remove_slave(struct w1_slave *sl) 148static void w1_ds2760_remove_slave(struct w1_slave *sl)
163{ 149{
164 struct platform_device *pdev = dev_get_drvdata(&sl->dev); 150 struct platform_device *pdev = dev_get_drvdata(&sl->dev);
165 int id = pdev->id;
166 151
167 platform_device_unregister(pdev); 152 platform_device_unregister(pdev);
168 ida_simple_remove(&bat_ida, id);
169} 153}
170 154
171static struct w1_family_ops w1_ds2760_fops = { 155static struct w1_family_ops w1_ds2760_fops = {
@@ -182,14 +166,12 @@ static struct w1_family w1_ds2760_family = {
182static int __init w1_ds2760_init(void) 166static int __init w1_ds2760_init(void)
183{ 167{
184 pr_info("1-Wire driver for the DS2760 battery monitor chip - (c) 2004-2005, Szabolcs Gyurko\n"); 168 pr_info("1-Wire driver for the DS2760 battery monitor chip - (c) 2004-2005, Szabolcs Gyurko\n");
185 ida_init(&bat_ida);
186 return w1_register_family(&w1_ds2760_family); 169 return w1_register_family(&w1_ds2760_family);
187} 170}
188 171
189static void __exit w1_ds2760_exit(void) 172static void __exit w1_ds2760_exit(void)
190{ 173{
191 w1_unregister_family(&w1_ds2760_family); 174 w1_unregister_family(&w1_ds2760_family);
192 ida_destroy(&bat_ida);
193} 175}
194 176
195EXPORT_SYMBOL(w1_ds2760_read); 177EXPORT_SYMBOL(w1_ds2760_read);
diff --git a/drivers/w1/slaves/w1_ds2780.c b/drivers/w1/slaves/w1_ds2780.c
index 50e85f7929d4..e63eb86d66f1 100644
--- a/drivers/w1/slaves/w1_ds2780.c
+++ b/drivers/w1/slaves/w1_ds2780.c
@@ -113,25 +113,14 @@ static const struct attribute_group *w1_ds2780_groups[] = {
113 NULL, 113 NULL,
114}; 114};
115 115
116static DEFINE_IDA(bat_ida);
117
118static int w1_ds2780_add_slave(struct w1_slave *sl) 116static int w1_ds2780_add_slave(struct w1_slave *sl)
119{ 117{
120 int ret; 118 int ret;
121 int id;
122 struct platform_device *pdev; 119 struct platform_device *pdev;
123 120
124 id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); 121 pdev = platform_device_alloc("ds2780-battery", PLATFORM_DEVID_AUTO);
125 if (id < 0) { 122 if (!pdev)
126 ret = id; 123 return -ENOMEM;
127 goto noid;
128 }
129
130 pdev = platform_device_alloc("ds2780-battery", id);
131 if (!pdev) {
132 ret = -ENOMEM;
133 goto pdev_alloc_failed;
134 }
135 pdev->dev.parent = &sl->dev; 124 pdev->dev.parent = &sl->dev;
136 125
137 ret = platform_device_add(pdev); 126 ret = platform_device_add(pdev);
@@ -144,19 +133,15 @@ static int w1_ds2780_add_slave(struct w1_slave *sl)
144 133
145pdev_add_failed: 134pdev_add_failed:
146 platform_device_put(pdev); 135 platform_device_put(pdev);
147pdev_alloc_failed: 136
148 ida_simple_remove(&bat_ida, id);
149noid:
150 return ret; 137 return ret;
151} 138}
152 139
153static void w1_ds2780_remove_slave(struct w1_slave *sl) 140static void w1_ds2780_remove_slave(struct w1_slave *sl)
154{ 141{
155 struct platform_device *pdev = dev_get_drvdata(&sl->dev); 142 struct platform_device *pdev = dev_get_drvdata(&sl->dev);
156 int id = pdev->id;
157 143
158 platform_device_unregister(pdev); 144 platform_device_unregister(pdev);
159 ida_simple_remove(&bat_ida, id);
160} 145}
161 146
162static struct w1_family_ops w1_ds2780_fops = { 147static struct w1_family_ops w1_ds2780_fops = {
@@ -172,14 +157,12 @@ static struct w1_family w1_ds2780_family = {
172 157
173static int __init w1_ds2780_init(void) 158static int __init w1_ds2780_init(void)
174{ 159{
175 ida_init(&bat_ida);
176 return w1_register_family(&w1_ds2780_family); 160 return w1_register_family(&w1_ds2780_family);
177} 161}
178 162
179static void __exit w1_ds2780_exit(void) 163static void __exit w1_ds2780_exit(void)
180{ 164{
181 w1_unregister_family(&w1_ds2780_family); 165 w1_unregister_family(&w1_ds2780_family);
182 ida_destroy(&bat_ida);
183} 166}
184 167
185module_init(w1_ds2780_init); 168module_init(w1_ds2780_init);
diff --git a/drivers/w1/slaves/w1_ds2781.c b/drivers/w1/slaves/w1_ds2781.c
index 1eb98fb1688d..99b0f4dc0e31 100644
--- a/drivers/w1/slaves/w1_ds2781.c
+++ b/drivers/w1/slaves/w1_ds2781.c
@@ -17,7 +17,6 @@
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/mutex.h> 19#include <linux/mutex.h>
20#include <linux/idr.h>
21 20
22#include "../w1.h" 21#include "../w1.h"
23#include "../w1_int.h" 22#include "../w1_int.h"
@@ -111,25 +110,14 @@ static const struct attribute_group *w1_ds2781_groups[] = {
111 NULL, 110 NULL,
112}; 111};
113 112
114static DEFINE_IDA(bat_ida);
115
116static int w1_ds2781_add_slave(struct w1_slave *sl) 113static int w1_ds2781_add_slave(struct w1_slave *sl)
117{ 114{
118 int ret; 115 int ret;
119 int id;
120 struct platform_device *pdev; 116 struct platform_device *pdev;
121 117
122 id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL); 118 pdev = platform_device_alloc("ds2781-battery", PLATFORM_DEVID_AUTO);
123 if (id < 0) { 119 if (!pdev)
124 ret = id; 120 return -ENOMEM;
125 goto noid;
126 }
127
128 pdev = platform_device_alloc("ds2781-battery", id);
129 if (!pdev) {
130 ret = -ENOMEM;
131 goto pdev_alloc_failed;
132 }
133 pdev->dev.parent = &sl->dev; 121 pdev->dev.parent = &sl->dev;
134 122
135 ret = platform_device_add(pdev); 123 ret = platform_device_add(pdev);
@@ -142,19 +130,15 @@ static int w1_ds2781_add_slave(struct w1_slave *sl)
142 130
143pdev_add_failed: 131pdev_add_failed:
144 platform_device_put(pdev); 132 platform_device_put(pdev);
145pdev_alloc_failed: 133
146 ida_simple_remove(&bat_ida, id);
147noid:
148 return ret; 134 return ret;
149} 135}
150 136
151static void w1_ds2781_remove_slave(struct w1_slave *sl) 137static void w1_ds2781_remove_slave(struct w1_slave *sl)
152{ 138{
153 struct platform_device *pdev = dev_get_drvdata(&sl->dev); 139 struct platform_device *pdev = dev_get_drvdata(&sl->dev);
154 int id = pdev->id;
155 140
156 platform_device_unregister(pdev); 141 platform_device_unregister(pdev);
157 ida_simple_remove(&bat_ida, id);
158} 142}
159 143
160static struct w1_family_ops w1_ds2781_fops = { 144static struct w1_family_ops w1_ds2781_fops = {
@@ -170,14 +154,12 @@ static struct w1_family w1_ds2781_family = {
170 154
171static int __init w1_ds2781_init(void) 155static int __init w1_ds2781_init(void)
172{ 156{
173 ida_init(&bat_ida);
174 return w1_register_family(&w1_ds2781_family); 157 return w1_register_family(&w1_ds2781_family);
175} 158}
176 159
177static void __exit w1_ds2781_exit(void) 160static void __exit w1_ds2781_exit(void)
178{ 161{
179 w1_unregister_family(&w1_ds2781_family); 162 w1_unregister_family(&w1_ds2781_family);
180 ida_destroy(&bat_ida);
181} 163}
182 164
183module_init(w1_ds2781_init); 165module_init(w1_ds2781_init);