Port SPI-GPIO driver from 2.6.29-rc4
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.27 / 090-ds1672_new_style.patch
1 From: Alessandro Zummo <alessandro.zummo@towertech.it>
2 Date: Thu, 16 Oct 2008 05:03:10 +0000 (-0700)
3 Subject: rtc-ds1672 new style driver
4 X-Git-Tag: v2.6.28-rc1~429
5 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=1716b0fea36c2be628440c1050182a1a1e9caae7
6
7 rtc-ds1672 new style driver
8
9 New style conversion and reformatting as per indent --linux-style
10
11 Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
12 Cc: David Brownell <david-b@pacbell.net>
13 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
14 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
15 ---
16
17 --- a/drivers/rtc/rtc-ds1672.c
18 +++ b/drivers/rtc/rtc-ds1672.c
19 @@ -9,17 +9,10 @@
20 * published by the Free Software Foundation.
21 */
22
23 -#include <linux/module.h>
24 #include <linux/i2c.h>
25 #include <linux/rtc.h>
26
27 -#define DRV_VERSION "0.3"
28 -
29 -/* Addresses to scan: none. This chip cannot be detected. */
30 -static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
31 -
32 -/* Insmod parameters */
33 -I2C_CLIENT_INSMOD;
34 +#define DRV_VERSION "0.4"
35
36 /* Registers */
37
38 @@ -29,8 +22,7 @@ I2C_CLIENT_INSMOD;
39
40 #define DS1672_REG_CONTROL_EOSC 0x80
41
42 -/* Prototypes */
43 -static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind);
44 +static struct i2c_driver ds1672_driver;
45
46 /*
47 * In the routines that deal directly with the ds1672 hardware, we use
48 @@ -44,8 +36,8 @@ static int ds1672_get_datetime(struct i2
49 unsigned char buf[4];
50
51 struct i2c_msg msgs[] = {
52 - { client->addr, 0, 1, &addr }, /* setup read ptr */
53 - { client->addr, I2C_M_RD, 4, buf }, /* read date */
54 + {client->addr, 0, 1, &addr}, /* setup read ptr */
55 + {client->addr, I2C_M_RD, 4, buf}, /* read date */
56 };
57
58 /* read date registers */
59 @@ -80,7 +72,7 @@ static int ds1672_set_mmss(struct i2c_cl
60 buf[2] = (secs & 0x0000FF00) >> 8;
61 buf[3] = (secs & 0x00FF0000) >> 16;
62 buf[4] = (secs & 0xFF000000) >> 24;
63 - buf[5] = 0; /* set control reg to enable counting */
64 + buf[5] = 0; /* set control reg to enable counting */
65
66 xfer = i2c_master_send(client, buf, 6);
67 if (xfer != 6) {
68 @@ -127,8 +119,8 @@ static int ds1672_get_control(struct i2c
69 unsigned char addr = DS1672_REG_CONTROL;
70
71 struct i2c_msg msgs[] = {
72 - { client->addr, 0, 1, &addr }, /* setup read ptr */
73 - { client->addr, I2C_M_RD, 1, status }, /* read control */
74 + {client->addr, 0, 1, &addr}, /* setup read ptr */
75 + {client->addr, I2C_M_RD, 1, status}, /* read control */
76 };
77
78 /* read control register */
79 @@ -141,7 +133,8 @@ static int ds1672_get_control(struct i2c
80 }
81
82 /* following are the sysfs callback functions */
83 -static ssize_t show_control(struct device *dev, struct device_attribute *attr, char *buf)
84 +static ssize_t show_control(struct device *dev, struct device_attribute *attr,
85 + char *buf)
86 {
87 struct i2c_client *client = to_i2c_client(dev);
88 u8 control;
89 @@ -152,85 +145,46 @@ static ssize_t show_control(struct devic
90 return err;
91
92 return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC)
93 - ? "disabled" : "enabled");
94 + ? "disabled" : "enabled");
95 }
96 +
97 static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
98
99 static const struct rtc_class_ops ds1672_rtc_ops = {
100 - .read_time = ds1672_rtc_read_time,
101 - .set_time = ds1672_rtc_set_time,
102 - .set_mmss = ds1672_rtc_set_mmss,
103 + .read_time = ds1672_rtc_read_time,
104 + .set_time = ds1672_rtc_set_time,
105 + .set_mmss = ds1672_rtc_set_mmss,
106 };
107
108 -static int ds1672_attach(struct i2c_adapter *adapter)
109 -{
110 - return i2c_probe(adapter, &addr_data, ds1672_probe);
111 -}
112 -
113 -static int ds1672_detach(struct i2c_client *client)
114 +static int ds1672_remove(struct i2c_client *client)
115 {
116 - int err;
117 struct rtc_device *rtc = i2c_get_clientdata(client);
118
119 - if (rtc)
120 + if (rtc)
121 rtc_device_unregister(rtc);
122
123 - if ((err = i2c_detach_client(client)))
124 - return err;
125 -
126 - kfree(client);
127 -
128 return 0;
129 }
130
131 -static struct i2c_driver ds1672_driver = {
132 - .driver = {
133 - .name = "ds1672",
134 - },
135 - .id = I2C_DRIVERID_DS1672,
136 - .attach_adapter = &ds1672_attach,
137 - .detach_client = &ds1672_detach,
138 -};
139 -
140 -static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
141 +static int ds1672_probe(struct i2c_client *client,
142 + const struct i2c_device_id *id)
143 {
144 int err = 0;
145 u8 control;
146 - struct i2c_client *client;
147 struct rtc_device *rtc;
148
149 - dev_dbg(&adapter->dev, "%s\n", __func__);
150 -
151 - if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
152 - err = -ENODEV;
153 - goto exit;
154 - }
155 -
156 - if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
157 - err = -ENOMEM;
158 - goto exit;
159 - }
160 + dev_dbg(&client->dev, "%s\n", __func__);
161
162 - /* I2C client */
163 - client->addr = address;
164 - client->driver = &ds1672_driver;
165 - client->adapter = adapter;
166 -
167 - strlcpy(client->name, ds1672_driver.driver.name, I2C_NAME_SIZE);
168 -
169 - /* Inform the i2c layer */
170 - if ((err = i2c_attach_client(client)))
171 - goto exit_kfree;
172 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
173 + return -ENODEV;
174
175 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
176
177 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev,
178 - &ds1672_rtc_ops, THIS_MODULE);
179 + &ds1672_rtc_ops, THIS_MODULE);
180
181 - if (IS_ERR(rtc)) {
182 - err = PTR_ERR(rtc);
183 - goto exit_detach;
184 - }
185 + if (IS_ERR(rtc))
186 + return PTR_ERR(rtc);
187
188 i2c_set_clientdata(client, rtc);
189
190 @@ -241,7 +195,7 @@ static int ds1672_probe(struct i2c_adapt
191
192 if (control & DS1672_REG_CONTROL_EOSC)
193 dev_warn(&client->dev, "Oscillator not enabled. "
194 - "Set time to enable.\n");
195 + "Set time to enable.\n");
196
197 /* Register sysfs hooks */
198 err = device_create_file(&client->dev, &dev_attr_control);
199 @@ -250,19 +204,19 @@ static int ds1672_probe(struct i2c_adapt
200
201 return 0;
202
203 -exit_devreg:
204 + exit_devreg:
205 rtc_device_unregister(rtc);
206 -
207 -exit_detach:
208 - i2c_detach_client(client);
209 -
210 -exit_kfree:
211 - kfree(client);
212 -
213 -exit:
214 return err;
215 }
216
217 +static struct i2c_driver ds1672_driver = {
218 + .driver = {
219 + .name = "rtc-ds1672",
220 + },
221 + .probe = &ds1672_probe,
222 + .remove = &ds1672_remove,
223 +};
224 +
225 static int __init ds1672_init(void)
226 {
227 return i2c_add_driver(&ds1672_driver);
This page took 0.046861 seconds and 5 git commands to generate.