diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-06-29 09:39:11 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2016-06-27 21:58:03 -0400 |
commit | 699f279d998cf95809babc987abd4a409eada5b2 (patch) | |
tree | 5efc6361d6f6c890a9a314794804e113c57a8e34 | |
parent | 157926c013b39561fd1e3b93f8df96fb0ed17648 (diff) |
hwmon: (jz4740) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to
simplify the code a bit.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/jz4740-hwmon.c | 65 |
1 files changed, 14 insertions, 51 deletions
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c index df9b3447f2a8..0621ee1b3c98 100644 --- a/drivers/hwmon/jz4740-hwmon.c +++ b/drivers/hwmon/jz4740-hwmon.c | |||
@@ -29,23 +29,13 @@ | |||
29 | 29 | ||
30 | struct jz4740_hwmon { | 30 | struct jz4740_hwmon { |
31 | void __iomem *base; | 31 | void __iomem *base; |
32 | |||
33 | int irq; | 32 | int irq; |
34 | |||
35 | const struct mfd_cell *cell; | 33 | const struct mfd_cell *cell; |
36 | struct device *hwmon; | 34 | struct platform_device *pdev; |
37 | |||
38 | struct completion read_completion; | 35 | struct completion read_completion; |
39 | |||
40 | struct mutex lock; | 36 | struct mutex lock; |
41 | }; | 37 | }; |
42 | 38 | ||
43 | static ssize_t jz4740_hwmon_show_name(struct device *dev, | ||
44 | struct device_attribute *dev_attr, char *buf) | ||
45 | { | ||
46 | return sprintf(buf, "jz4740\n"); | ||
47 | } | ||
48 | |||
49 | static irqreturn_t jz4740_hwmon_irq(int irq, void *data) | 39 | static irqreturn_t jz4740_hwmon_irq(int irq, void *data) |
50 | { | 40 | { |
51 | struct jz4740_hwmon *hwmon = data; | 41 | struct jz4740_hwmon *hwmon = data; |
@@ -58,6 +48,7 @@ static ssize_t jz4740_hwmon_read_adcin(struct device *dev, | |||
58 | struct device_attribute *dev_attr, char *buf) | 48 | struct device_attribute *dev_attr, char *buf) |
59 | { | 49 | { |
60 | struct jz4740_hwmon *hwmon = dev_get_drvdata(dev); | 50 | struct jz4740_hwmon *hwmon = dev_get_drvdata(dev); |
51 | struct platform_device *pdev = hwmon->pdev; | ||
61 | struct completion *completion = &hwmon->read_completion; | 52 | struct completion *completion = &hwmon->read_completion; |
62 | long t; | 53 | long t; |
63 | unsigned long val; | 54 | unsigned long val; |
@@ -68,7 +59,7 @@ static ssize_t jz4740_hwmon_read_adcin(struct device *dev, | |||
68 | reinit_completion(completion); | 59 | reinit_completion(completion); |
69 | 60 | ||
70 | enable_irq(hwmon->irq); | 61 | enable_irq(hwmon->irq); |
71 | hwmon->cell->enable(to_platform_device(dev)); | 62 | hwmon->cell->enable(pdev); |
72 | 63 | ||
73 | t = wait_for_completion_interruptible_timeout(completion, HZ); | 64 | t = wait_for_completion_interruptible_timeout(completion, HZ); |
74 | 65 | ||
@@ -80,7 +71,7 @@ static ssize_t jz4740_hwmon_read_adcin(struct device *dev, | |||
80 | ret = t ? t : -ETIMEDOUT; | 71 | ret = t ? t : -ETIMEDOUT; |
81 | } | 72 | } |
82 | 73 | ||
83 | hwmon->cell->disable(to_platform_device(dev)); | 74 | hwmon->cell->disable(pdev); |
84 | disable_irq(hwmon->irq); | 75 | disable_irq(hwmon->irq); |
85 | 76 | ||
86 | mutex_unlock(&hwmon->lock); | 77 | mutex_unlock(&hwmon->lock); |
@@ -88,26 +79,24 @@ static ssize_t jz4740_hwmon_read_adcin(struct device *dev, | |||
88 | return ret; | 79 | return ret; |
89 | } | 80 | } |
90 | 81 | ||
91 | static DEVICE_ATTR(name, S_IRUGO, jz4740_hwmon_show_name, NULL); | ||
92 | static DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL); | 82 | static DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL); |
93 | 83 | ||
94 | static struct attribute *jz4740_hwmon_attributes[] = { | 84 | static struct attribute *jz4740_attrs[] = { |
95 | &dev_attr_name.attr, | ||
96 | &dev_attr_in0_input.attr, | 85 | &dev_attr_in0_input.attr, |
97 | NULL | 86 | NULL |
98 | }; | 87 | }; |
99 | 88 | ||
100 | static const struct attribute_group jz4740_hwmon_attr_group = { | 89 | ATTRIBUTE_GROUPS(jz4740); |
101 | .attrs = jz4740_hwmon_attributes, | ||
102 | }; | ||
103 | 90 | ||
104 | static int jz4740_hwmon_probe(struct platform_device *pdev) | 91 | static int jz4740_hwmon_probe(struct platform_device *pdev) |
105 | { | 92 | { |
106 | int ret; | 93 | int ret; |
94 | struct device *dev = &pdev->dev; | ||
107 | struct jz4740_hwmon *hwmon; | 95 | struct jz4740_hwmon *hwmon; |
96 | struct device *hwmon_dev; | ||
108 | struct resource *mem; | 97 | struct resource *mem; |
109 | 98 | ||
110 | hwmon = devm_kzalloc(&pdev->dev, sizeof(*hwmon), GFP_KERNEL); | 99 | hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); |
111 | if (!hwmon) | 100 | if (!hwmon) |
112 | return -ENOMEM; | 101 | return -ENOMEM; |
113 | 102 | ||
@@ -125,12 +114,11 @@ static int jz4740_hwmon_probe(struct platform_device *pdev) | |||
125 | if (IS_ERR(hwmon->base)) | 114 | if (IS_ERR(hwmon->base)) |
126 | return PTR_ERR(hwmon->base); | 115 | return PTR_ERR(hwmon->base); |
127 | 116 | ||
117 | hwmon->pdev = pdev; | ||
128 | init_completion(&hwmon->read_completion); | 118 | init_completion(&hwmon->read_completion); |
129 | mutex_init(&hwmon->lock); | 119 | mutex_init(&hwmon->lock); |
130 | 120 | ||
131 | platform_set_drvdata(pdev, hwmon); | 121 | ret = devm_request_irq(dev, hwmon->irq, jz4740_hwmon_irq, 0, |
132 | |||
133 | ret = devm_request_irq(&pdev->dev, hwmon->irq, jz4740_hwmon_irq, 0, | ||
134 | pdev->name, hwmon); | 122 | pdev->name, hwmon); |
135 | if (ret) { | 123 | if (ret) { |
136 | dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); | 124 | dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); |
@@ -138,38 +126,13 @@ static int jz4740_hwmon_probe(struct platform_device *pdev) | |||
138 | } | 126 | } |
139 | disable_irq(hwmon->irq); | 127 | disable_irq(hwmon->irq); |
140 | 128 | ||
141 | ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | 129 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, "jz4740", hwmon, |
142 | if (ret) { | 130 | jz4740_groups); |
143 | dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret); | 131 | return PTR_ERR_OR_ZERO(hwmon_dev); |
144 | return ret; | ||
145 | } | ||
146 | |||
147 | hwmon->hwmon = hwmon_device_register(&pdev->dev); | ||
148 | if (IS_ERR(hwmon->hwmon)) { | ||
149 | ret = PTR_ERR(hwmon->hwmon); | ||
150 | goto err_remove_file; | ||
151 | } | ||
152 | |||
153 | return 0; | ||
154 | |||
155 | err_remove_file: | ||
156 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | ||
157 | return ret; | ||
158 | } | ||
159 | |||
160 | static int jz4740_hwmon_remove(struct platform_device *pdev) | ||
161 | { | ||
162 | struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev); | ||
163 | |||
164 | hwmon_device_unregister(hwmon->hwmon); | ||
165 | sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group); | ||
166 | |||
167 | return 0; | ||
168 | } | 132 | } |
169 | 133 | ||
170 | static struct platform_driver jz4740_hwmon_driver = { | 134 | static struct platform_driver jz4740_hwmon_driver = { |
171 | .probe = jz4740_hwmon_probe, | 135 | .probe = jz4740_hwmon_probe, |
172 | .remove = jz4740_hwmon_remove, | ||
173 | .driver = { | 136 | .driver = { |
174 | .name = "jz4740-hwmon", | 137 | .name = "jz4740-hwmon", |
175 | }, | 138 | }, |