cea2e63591199af98e104746422ab0de6dd9bdc8
[openwrt.git] / target / linux / ixp4xx / patches-2.6.25 / 012-rtc_x1205_new_style.patch
1 ---
2 drivers/rtc/rtc-x1205.c | 128 ++++++++++++++++--------------------------------
3 1 file changed, 43 insertions(+), 85 deletions(-)
4
5 Index: linux-2.6.25.1/drivers/rtc/rtc-x1205.c
6 ===================================================================
7 --- linux-2.6.25.1.orig/drivers/rtc/rtc-x1205.c
8 +++ linux-2.6.25.1/drivers/rtc/rtc-x1205.c
9 @@ -22,20 +22,7 @@
10 #include <linux/rtc.h>
11 #include <linux/delay.h>
12
13 -#define DRV_VERSION "1.0.7"
14 -
15 -/* Addresses to scan: none. This chip is located at
16 - * 0x6f and uses a two bytes register addressing.
17 - * Two bytes need to be written to read a single register,
18 - * while most other chips just require one and take the second
19 - * one as the data to be written. To prevent corrupting
20 - * unknown chips, the user must explicitly set the probe parameter.
21 - */
22 -
23 -static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
24 -
25 -/* Insmod parameters */
26 -I2C_CLIENT_INSMOD;
27 +#define DRV_VERSION "1.0.8"
28
29 /* offsets into CCR area */
30
31 @@ -91,19 +78,7 @@ I2C_CLIENT_INSMOD;
32
33 #define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
34
35 -/* Prototypes */
36 -static int x1205_attach(struct i2c_adapter *adapter);
37 -static int x1205_detach(struct i2c_client *client);
38 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
39 -
40 -static struct i2c_driver x1205_driver = {
41 - .driver = {
42 - .name = "x1205",
43 - },
44 - .id = I2C_DRIVERID_X1205,
45 - .attach_adapter = &x1205_attach,
46 - .detach_client = &x1205_detach,
47 -};
48 +static struct i2c_driver x1205_driver;
49
50 /*
51 * In the routines that deal directly with the x1205 hardware, we use
52 @@ -497,58 +472,51 @@ static ssize_t x1205_sysfs_show_dtrim(st
53 }
54 static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
55
56 -static int x1205_attach(struct i2c_adapter *adapter)
57 +static int x1205_sysfs_register(struct device *dev)
58 +{
59 + int err;
60 +
61 + err = device_create_file(dev, &dev_attr_atrim);
62 + if (err)
63 + return err;
64 +
65 + err = device_create_file(dev, &dev_attr_dtrim);
66 + if (err)
67 + device_remove_file(dev, &dev_attr_atrim);
68 +
69 + return err;
70 +}
71 +
72 +static void x1205_sysfs_unregister(struct device *dev)
73 {
74 - return i2c_probe(adapter, &addr_data, x1205_probe);
75 + device_remove_file(dev, &dev_attr_atrim);
76 + device_remove_file(dev, &dev_attr_dtrim);
77 }
78
79 -static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
80 +
81 +static int x1205_probe(struct i2c_client *client)
82 {
83 int err = 0;
84 unsigned char sr;
85 - struct i2c_client *client;
86 struct rtc_device *rtc;
87
88 - dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
89 + dev_dbg(&client->dev, "%s\n", __FUNCTION__);
90
91 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
92 - err = -ENODEV;
93 - goto exit;
94 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
95 + return -ENODEV;
96 }
97
98 - if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
99 - err = -ENOMEM;
100 - goto exit;
101 + if (x1205_validate_client(client) < 0) {
102 + return -ENODEV;
103 }
104
105 - /* I2C client */
106 - client->addr = address;
107 - client->driver = &x1205_driver;
108 - client->adapter = adapter;
109 -
110 - strlcpy(client->name, x1205_driver.driver.name, I2C_NAME_SIZE);
111 -
112 - /* Verify the chip is really an X1205 */
113 - if (kind < 0) {
114 - if (x1205_validate_client(client) < 0) {
115 - err = -ENODEV;
116 - goto exit_kfree;
117 - }
118 - }
119 -
120 - /* Inform the i2c layer */
121 - if ((err = i2c_attach_client(client)))
122 - goto exit_kfree;
123 -
124 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
125
126 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev,
127 &x1205_rtc_ops, THIS_MODULE);
128
129 - if (IS_ERR(rtc)) {
130 - err = PTR_ERR(rtc);
131 - goto exit_detach;
132 - }
133 + if (IS_ERR(rtc))
134 + return PTR_ERR(rtc);
135
136 i2c_set_clientdata(client, rtc);
137
138 @@ -565,45 +533,35 @@ static int x1205_probe(struct i2c_adapte
139 else
140 dev_err(&client->dev, "couldn't read status\n");
141
142 - err = device_create_file(&client->dev, &dev_attr_atrim);
143 - if (err) goto exit_devreg;
144 - err = device_create_file(&client->dev, &dev_attr_dtrim);
145 - if (err) goto exit_atrim;
146 + err = x1205_sysfs_register(&client->dev);
147 + if (err)
148 + goto exit_devreg;
149
150 return 0;
151
152 -exit_atrim:
153 - device_remove_file(&client->dev, &dev_attr_atrim);
154 -
155 exit_devreg:
156 rtc_device_unregister(rtc);
157
158 -exit_detach:
159 - i2c_detach_client(client);
160 -
161 -exit_kfree:
162 - kfree(client);
163 -
164 -exit:
165 return err;
166 }
167
168 -static int x1205_detach(struct i2c_client *client)
169 +static int x1205_remove(struct i2c_client *client)
170 {
171 - int err;
172 struct rtc_device *rtc = i2c_get_clientdata(client);
173
174 - if (rtc)
175 - rtc_device_unregister(rtc);
176 -
177 - if ((err = i2c_detach_client(client)))
178 - return err;
179 -
180 - kfree(client);
181 -
182 + rtc_device_unregister(rtc);
183 + x1205_sysfs_unregister(&client->dev);
184 return 0;
185 }
186
187 +static struct i2c_driver x1205_driver = {
188 + .driver = {
189 + .name = "rtc-x1205",
190 + },
191 + .probe = x1205_probe,
192 + .remove = x1205_remove,
193 +};
194 +
195 static int __init x1205_init(void)
196 {
197 return i2c_add_driver(&x1205_driver);
This page took 0.052146 seconds and 3 git commands to generate.