aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/ad525x_dpot-i2c.c10
-rw-r--r--drivers/misc/ad525x_dpot-spi.c97
-rw-r--r--drivers/misc/ad525x_dpot.c24
-rw-r--r--drivers/misc/ad525x_dpot.h8
4 files changed, 53 insertions, 86 deletions
diff --git a/drivers/misc/ad525x_dpot-i2c.c b/drivers/misc/ad525x_dpot-i2c.c
index a39e0555df63..83adab69bfd4 100644
--- a/drivers/misc/ad525x_dpot-i2c.c
+++ b/drivers/misc/ad525x_dpot-i2c.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the Analog Devices digital potentiometers (I2C bus) 2 * Driver for the Analog Devices digital potentiometers (I2C bus)
3 * 3 *
4 * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc. 4 * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
@@ -11,7 +11,6 @@
11 11
12#include "ad525x_dpot.h" 12#include "ad525x_dpot.h"
13 13
14/* ------------------------------------------------------------------------- */
15/* I2C bus functions */ 14/* I2C bus functions */
16static int write_d8(void *client, u8 val) 15static int write_d8(void *client, u8 val)
17{ 16{
@@ -60,18 +59,13 @@ static int __devinit ad_dpot_i2c_probe(struct i2c_client *client,
60 .bops = &bops, 59 .bops = &bops,
61 }; 60 };
62 61
63 struct ad_dpot_id dpot_id = {
64 .name = (char *) &id->name,
65 .devid = id->driver_data,
66 };
67
68 if (!i2c_check_functionality(client->adapter, 62 if (!i2c_check_functionality(client->adapter,
69 I2C_FUNC_SMBUS_WORD_DATA)) { 63 I2C_FUNC_SMBUS_WORD_DATA)) {
70 dev_err(&client->dev, "SMBUS Word Data not Supported\n"); 64 dev_err(&client->dev, "SMBUS Word Data not Supported\n");
71 return -EIO; 65 return -EIO;
72 } 66 }
73 67
74 return ad_dpot_probe(&client->dev, &bdata, &dpot_id); 68 return ad_dpot_probe(&client->dev, &bdata, id->driver_data, id->name);
75} 69}
76 70
77static int __devexit ad_dpot_i2c_remove(struct i2c_client *client) 71static int __devexit ad_dpot_i2c_remove(struct i2c_client *client)
diff --git a/drivers/misc/ad525x_dpot-spi.c b/drivers/misc/ad525x_dpot-spi.c
index 7f9a55afe05d..822749e41fea 100644
--- a/drivers/misc/ad525x_dpot-spi.c
+++ b/drivers/misc/ad525x_dpot-spi.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the Analog Devices digital potentiometers (SPI bus) 2 * Driver for the Analog Devices digital potentiometers (SPI bus)
3 * 3 *
4 * Copyright (C) 2010 Michael Hennerich, Analog Devices Inc. 4 * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
@@ -11,40 +11,6 @@
11 11
12#include "ad525x_dpot.h" 12#include "ad525x_dpot.h"
13 13
14static const struct ad_dpot_id ad_dpot_spi_devlist[] = {
15 {.name = "ad5160", .devid = AD5160_ID},
16 {.name = "ad5161", .devid = AD5161_ID},
17 {.name = "ad5162", .devid = AD5162_ID},
18 {.name = "ad5165", .devid = AD5165_ID},
19 {.name = "ad5200", .devid = AD5200_ID},
20 {.name = "ad5201", .devid = AD5201_ID},
21 {.name = "ad5203", .devid = AD5203_ID},
22 {.name = "ad5204", .devid = AD5204_ID},
23 {.name = "ad5206", .devid = AD5206_ID},
24 {.name = "ad5207", .devid = AD5207_ID},
25 {.name = "ad5231", .devid = AD5231_ID},
26 {.name = "ad5232", .devid = AD5232_ID},
27 {.name = "ad5233", .devid = AD5233_ID},
28 {.name = "ad5235", .devid = AD5235_ID},
29 {.name = "ad5260", .devid = AD5260_ID},
30 {.name = "ad5262", .devid = AD5262_ID},
31 {.name = "ad5263", .devid = AD5263_ID},
32 {.name = "ad5290", .devid = AD5290_ID},
33 {.name = "ad5291", .devid = AD5291_ID},
34 {.name = "ad5292", .devid = AD5292_ID},
35 {.name = "ad5293", .devid = AD5293_ID},
36 {.name = "ad7376", .devid = AD7376_ID},
37 {.name = "ad8400", .devid = AD8400_ID},
38 {.name = "ad8402", .devid = AD8402_ID},
39 {.name = "ad8403", .devid = AD8403_ID},
40 {.name = "adn2850", .devid = ADN2850_ID},
41 {.name = "ad5270", .devid = AD5270_ID},
42 {.name = "ad5271", .devid = AD5271_ID},
43 {}
44};
45
46/* ------------------------------------------------------------------------- */
47
48/* SPI bus functions */ 14/* SPI bus functions */
49static int write8(void *client, u8 val) 15static int write8(void *client, u8 val)
50{ 16{
@@ -109,36 +75,16 @@ static const struct ad_dpot_bus_ops bops = {
109 .write_r8d8 = write16, 75 .write_r8d8 = write16,
110 .write_r8d16 = write24, 76 .write_r8d16 = write24,
111}; 77};
112
113static const struct ad_dpot_id *dpot_match_id(const struct ad_dpot_id *id,
114 char *name)
115{
116 while (id->name && id->name[0]) {
117 if (strcmp(name, id->name) == 0)
118 return id;
119 id++;
120 }
121 return NULL;
122}
123
124static int __devinit ad_dpot_spi_probe(struct spi_device *spi) 78static int __devinit ad_dpot_spi_probe(struct spi_device *spi)
125{ 79{
126 char *name = spi->dev.platform_data;
127 const struct ad_dpot_id *dpot_id;
128
129 struct ad_dpot_bus_data bdata = { 80 struct ad_dpot_bus_data bdata = {
130 .client = spi, 81 .client = spi,
131 .bops = &bops, 82 .bops = &bops,
132 }; 83 };
133 84
134 dpot_id = dpot_match_id(ad_dpot_spi_devlist, name); 85 return ad_dpot_probe(&spi->dev, &bdata,
135 86 spi_get_device_id(spi)->driver_data,
136 if (dpot_id == NULL) { 87 spi_get_device_id(spi)->name);
137 dev_err(&spi->dev, "%s not in supported device list", name);
138 return -ENODEV;
139 }
140
141 return ad_dpot_probe(&spi->dev, &bdata, dpot_id);
142} 88}
143 89
144static int __devexit ad_dpot_spi_remove(struct spi_device *spi) 90static int __devexit ad_dpot_spi_remove(struct spi_device *spi)
@@ -146,14 +92,47 @@ static int __devexit ad_dpot_spi_remove(struct spi_device *spi)
146 return ad_dpot_remove(&spi->dev); 92 return ad_dpot_remove(&spi->dev);
147} 93}
148 94
95static const struct spi_device_id ad_dpot_spi_id[] = {
96 {"ad5160", AD5160_ID},
97 {"ad5161", AD5161_ID},
98 {"ad5162", AD5162_ID},
99 {"ad5165", AD5165_ID},
100 {"ad5200", AD5200_ID},
101 {"ad5201", AD5201_ID},
102 {"ad5203", AD5203_ID},
103 {"ad5204", AD5204_ID},
104 {"ad5206", AD5206_ID},
105 {"ad5207", AD5207_ID},
106 {"ad5231", AD5231_ID},
107 {"ad5232", AD5232_ID},
108 {"ad5233", AD5233_ID},
109 {"ad5235", AD5235_ID},
110 {"ad5260", AD5260_ID},
111 {"ad5262", AD5262_ID},
112 {"ad5263", AD5263_ID},
113 {"ad5290", AD5290_ID},
114 {"ad5291", AD5291_ID},
115 {"ad5292", AD5292_ID},
116 {"ad5293", AD5293_ID},
117 {"ad7376", AD7376_ID},
118 {"ad8400", AD8400_ID},
119 {"ad8402", AD8402_ID},
120 {"ad8403", AD8403_ID},
121 {"adn2850", ADN2850_ID},
122 {"ad5270", AD5270_ID},
123 {"ad5271", AD5271_ID},
124 {}
125};
126MODULE_DEVICE_TABLE(spi, ad_dpot_spi_id);
127
149static struct spi_driver ad_dpot_spi_driver = { 128static struct spi_driver ad_dpot_spi_driver = {
150 .driver = { 129 .driver = {
151 .name = "ad_dpot", 130 .name = "ad_dpot",
152 .bus = &spi_bus_type,
153 .owner = THIS_MODULE, 131 .owner = THIS_MODULE,
154 }, 132 },
155 .probe = ad_dpot_spi_probe, 133 .probe = ad_dpot_spi_probe,
156 .remove = __devexit_p(ad_dpot_spi_remove), 134 .remove = __devexit_p(ad_dpot_spi_remove),
135 .id_table = ad_dpot_spi_id,
157}; 136};
158 137
159static int __init ad_dpot_spi_init(void) 138static int __init ad_dpot_spi_init(void)
diff --git a/drivers/misc/ad525x_dpot.c b/drivers/misc/ad525x_dpot.c
index 7cb911028d09..1d1d42615915 100644
--- a/drivers/misc/ad525x_dpot.c
+++ b/drivers/misc/ad525x_dpot.c
@@ -64,7 +64,7 @@
64 * Author: Chris Verges <chrisv@cyberswitching.com> 64 * Author: Chris Verges <chrisv@cyberswitching.com>
65 * 65 *
66 * derived from ad5252.c 66 * derived from ad5252.c
67 * Copyright (c) 2006 Michael Hennerich <hennerich@blackfin.uclinux.org> 67 * Copyright (c) 2006-2011 Michael Hennerich <hennerich@blackfin.uclinux.org>
68 * 68 *
69 * Licensed under the GPL-2 or later. 69 * Licensed under the GPL-2 or later.
70 */ 70 */
@@ -76,8 +76,6 @@
76#include <linux/delay.h> 76#include <linux/delay.h>
77#include <linux/slab.h> 77#include <linux/slab.h>
78 78
79#define DRIVER_VERSION "0.2"
80
81#include "ad525x_dpot.h" 79#include "ad525x_dpot.h"
82 80
83/* 81/*
@@ -687,8 +685,9 @@ inline void ad_dpot_remove_files(struct device *dev,
687 } 685 }
688} 686}
689 687
690__devinit int ad_dpot_probe(struct device *dev, 688int __devinit ad_dpot_probe(struct device *dev,
691 struct ad_dpot_bus_data *bdata, const struct ad_dpot_id *id) 689 struct ad_dpot_bus_data *bdata, unsigned long devid,
690 const char *name)
692{ 691{
693 692
694 struct dpot_data *data; 693 struct dpot_data *data;
@@ -704,13 +703,13 @@ __devinit int ad_dpot_probe(struct device *dev,
704 mutex_init(&data->update_lock); 703 mutex_init(&data->update_lock);
705 704
706 data->bdata = *bdata; 705 data->bdata = *bdata;
707 data->devid = id->devid; 706 data->devid = devid;
708 707
709 data->max_pos = 1 << DPOT_MAX_POS(data->devid); 708 data->max_pos = 1 << DPOT_MAX_POS(devid);
710 data->rdac_mask = data->max_pos - 1; 709 data->rdac_mask = data->max_pos - 1;
711 data->feat = DPOT_FEAT(data->devid); 710 data->feat = DPOT_FEAT(devid);
712 data->uid = DPOT_UID(data->devid); 711 data->uid = DPOT_UID(devid);
713 data->wipers = DPOT_WIPERS(data->devid); 712 data->wipers = DPOT_WIPERS(devid);
714 713
715 for (i = DPOT_RDAC0; i < MAX_RDACS; i++) 714 for (i = DPOT_RDAC0; i < MAX_RDACS; i++)
716 if (data->wipers & (1 << i)) { 715 if (data->wipers & (1 << i)) {
@@ -731,7 +730,7 @@ __devinit int ad_dpot_probe(struct device *dev,
731 } 730 }
732 731
733 dev_info(dev, "%s %d-Position Digital Potentiometer registered\n", 732 dev_info(dev, "%s %d-Position Digital Potentiometer registered\n",
734 id->name, data->max_pos); 733 name, data->max_pos);
735 734
736 return 0; 735 return 0;
737 736
@@ -745,7 +744,7 @@ exit_free:
745 dev_set_drvdata(dev, NULL); 744 dev_set_drvdata(dev, NULL);
746exit: 745exit:
747 dev_err(dev, "failed to create client for %s ID 0x%lX\n", 746 dev_err(dev, "failed to create client for %s ID 0x%lX\n",
748 id->name, id->devid); 747 name, devid);
749 return err; 748 return err;
750} 749}
751EXPORT_SYMBOL(ad_dpot_probe); 750EXPORT_SYMBOL(ad_dpot_probe);
@@ -770,4 +769,3 @@ MODULE_AUTHOR("Chris Verges <chrisv@cyberswitching.com>, "
770 "Michael Hennerich <hennerich@blackfin.uclinux.org>"); 769 "Michael Hennerich <hennerich@blackfin.uclinux.org>");
771MODULE_DESCRIPTION("Digital potentiometer driver"); 770MODULE_DESCRIPTION("Digital potentiometer driver");
772MODULE_LICENSE("GPL"); 771MODULE_LICENSE("GPL");
773MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/misc/ad525x_dpot.h b/drivers/misc/ad525x_dpot.h
index a662f5987b68..3bea1d5e8774 100644
--- a/drivers/misc/ad525x_dpot.h
+++ b/drivers/misc/ad525x_dpot.h
@@ -208,12 +208,8 @@ struct ad_dpot_bus_data {
208 const struct ad_dpot_bus_ops *bops; 208 const struct ad_dpot_bus_ops *bops;
209}; 209};
210 210
211struct ad_dpot_id { 211int ad_dpot_probe(struct device *dev, struct ad_dpot_bus_data *bdata,
212 char *name; 212 unsigned long devid, const char *name);
213 unsigned long devid;
214};
215
216int ad_dpot_probe(struct device *dev, struct ad_dpot_bus_data *bdata, const struct ad_dpot_id *id);
217int ad_dpot_remove(struct device *dev); 213int ad_dpot_remove(struct device *dev);
218 214
219#endif 215#endif