f0ce41f988dbecac8df81ab4fe7ca7f20e890d24
[oweals/openwrt.git] / target / linux / ixp4xx / patches-2.6.25 / 011-rtc_pcf8563_new_style.patch
1 ---
2  drivers/rtc/rtc-pcf8563.c |  109 +++++++++++++---------------------------------
3  1 file changed, 32 insertions(+), 77 deletions(-)
4
5 Index: linux-2.6.25.4/drivers/rtc/rtc-pcf8563.c
6 ===================================================================
7 --- linux-2.6.25.4.orig/drivers/rtc/rtc-pcf8563.c
8 +++ linux-2.6.25.4/drivers/rtc/rtc-pcf8563.c
9 @@ -18,17 +18,7 @@
10  #include <linux/bcd.h>
11  #include <linux/rtc.h>
12  
13 -#define DRV_VERSION "0.4.2"
14 -
15 -/* Addresses to scan: none
16 - * This chip cannot be reliably autodetected. An empty eeprom
17 - * located at 0x51 will pass the validation routine due to
18 - * the way the registers are implemented.
19 - */
20 -static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
21 -
22 -/* Module parameters */
23 -I2C_CLIENT_INSMOD;
24 +#define DRV_VERSION "0.4.3"
25  
26  #define PCF8563_REG_ST1                0x00 /* status */
27  #define PCF8563_REG_ST2                0x01
28 @@ -53,8 +43,10 @@ I2C_CLIENT_INSMOD;
29  #define PCF8563_SC_LV          0x80 /* low voltage */
30  #define PCF8563_MO_C           0x80 /* century */
31  
32 +static struct i2c_driver pcf8563_driver;
33 +
34  struct pcf8563 {
35 -       struct i2c_client client;
36 +       struct rtc_device *rtc;
37         /*
38          * The meaning of MO_C bit varies by the chip type.
39          * From PCF8563 datasheet: this bit is toggled when the years
40 @@ -72,16 +64,13 @@ struct pcf8563 {
41         int c_polarity; /* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */
42  };
43  
44 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind);
45 -static int pcf8563_detach(struct i2c_client *client);
46 -
47  /*
48   * In the routines that deal directly with the pcf8563 hardware, we use
49   * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
50   */
51  static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
52  {
53 -       struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
54 +       struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
55         unsigned char buf[13] = { PCF8563_REG_ST1 };
56  
57         struct i2c_msg msgs[] = {
58 @@ -138,7 +127,7 @@ static int pcf8563_get_datetime(struct i
59  
60  static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
61  {
62 -       struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
63 +       struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
64         int i, err;
65         unsigned char buf[9];
66  
67 @@ -257,100 +246,66 @@ static const struct rtc_class_ops pcf856
68         .set_time       = pcf8563_rtc_set_time,
69  };
70  
71 -static int pcf8563_attach(struct i2c_adapter *adapter)
72 -{
73 -       return i2c_probe(adapter, &addr_data, pcf8563_probe);
74 -}
75 -
76 -static struct i2c_driver pcf8563_driver = {
77 -       .driver         = {
78 -               .name   = "pcf8563",
79 -       },
80 -       .id             = I2C_DRIVERID_PCF8563,
81 -       .attach_adapter = &pcf8563_attach,
82 -       .detach_client  = &pcf8563_detach,
83 -};
84 -
85 -static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
86 +static int pcf8563_probe(struct i2c_client *client)
87  {
88         struct pcf8563 *pcf8563;
89 -       struct i2c_client *client;
90 -       struct rtc_device *rtc;
91  
92         int err = 0;
93  
94 -       dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
95 +       dev_dbg(&client->dev, "%s\n", __FUNCTION__);
96  
97 -       if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
98 -               err = -ENODEV;
99 -               goto exit;
100 -       }
101 +       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
102 +               return -ENODEV;
103  
104 -       if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL))) {
105 -               err = -ENOMEM;
106 -               goto exit;
107 -       }
108 -
109 -       client = &pcf8563->client;
110 -       client->addr = address;
111 -       client->driver = &pcf8563_driver;
112 -       client->adapter = adapter;
113 -
114 -       strlcpy(client->name, pcf8563_driver.driver.name, I2C_NAME_SIZE);
115 +       if (!(pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL)))
116 +               return -ENOMEM;
117  
118         /* Verify the chip is really an PCF8563 */
119 -       if (kind < 0) {
120 -               if (pcf8563_validate_client(client) < 0) {
121 -                       err = -ENODEV;
122 -                       goto exit_kfree;
123 -               }
124 -       }
125 -
126 -       /* Inform the i2c layer */
127 -       if ((err = i2c_attach_client(client)))
128 +       if (pcf8563_validate_client(client) < 0) {
129 +               err = -ENODEV;
130                 goto exit_kfree;
131 +       }
132  
133         dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
134  
135 -       rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
136 +       pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
137                                 &pcf8563_rtc_ops, THIS_MODULE);
138  
139 -       if (IS_ERR(rtc)) {
140 -               err = PTR_ERR(rtc);
141 -               goto exit_detach;
142 +       if (IS_ERR(pcf8563->rtc)) {
143 +               err = PTR_ERR(pcf8563->rtc);
144 +               goto exit_kfree;
145         }
146  
147 -       i2c_set_clientdata(client, rtc);
148 +       i2c_set_clientdata(client, pcf8563);
149  
150         return 0;
151  
152 -exit_detach:
153 -       i2c_detach_client(client);
154 -
155  exit_kfree:
156         kfree(pcf8563);
157  
158 -exit:
159         return err;
160  }
161  
162 -static int pcf8563_detach(struct i2c_client *client)
163 +static int pcf8563_remove(struct i2c_client *client)
164  {
165 -       struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
166 -       int err;
167 -       struct rtc_device *rtc = i2c_get_clientdata(client);
168 +       struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
169  
170 -       if (rtc)
171 -               rtc_device_unregister(rtc);
172 -
173 -       if ((err = i2c_detach_client(client)))
174 -               return err;
175 +       if (pcf8563->rtc)
176 +               rtc_device_unregister(pcf8563->rtc);
177  
178         kfree(pcf8563);
179  
180         return 0;
181  }
182  
183 +static struct i2c_driver pcf8563_driver = {
184 +       .driver         = {
185 +               .name   = "rtc-pcf8563",
186 +       },
187 +       .probe          = pcf8563_probe,
188 +       .remove         = pcf8563_remove,
189 +};
190 +
191  static int __init pcf8563_init(void)
192  {
193         return i2c_add_driver(&pcf8563_driver);