aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-au1550.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses/i2c-au1550.c')
-rw-r--r--drivers/i2c/busses/i2c-au1550.c177
1 files changed, 110 insertions, 67 deletions
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 2f684166c43d..1953b26da56a 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -30,14 +30,22 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/platform_device.h>
33#include <linux/init.h> 34#include <linux/init.h>
34#include <linux/errno.h> 35#include <linux/errno.h>
35#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/slab.h>
36 38
37#include <asm/mach-au1x00/au1xxx.h> 39#include <asm/mach-au1x00/au1xxx.h>
38#include <asm/mach-au1x00/au1xxx_psc.h> 40#include <asm/mach-au1x00/au1xxx_psc.h>
39 41
40#include "i2c-au1550.h" 42struct i2c_au1550_data {
43 u32 psc_base;
44 int xfer_timeout;
45 int ack_timeout;
46 struct i2c_adapter adap;
47 struct resource *ioarea;
48};
41 49
42static int 50static int
43wait_xfer_done(struct i2c_au1550_data *adap) 51wait_xfer_done(struct i2c_au1550_data *adap)
@@ -105,7 +113,7 @@ wait_master_done(struct i2c_au1550_data *adap)
105} 113}
106 114
107static int 115static int
108do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd) 116do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd, int q)
109{ 117{
110 volatile psc_smb_t *sp; 118 volatile psc_smb_t *sp;
111 u32 stat; 119 u32 stat;
@@ -134,6 +142,10 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd)
134 if (rd) 142 if (rd)
135 addr |= 1; 143 addr |= 1;
136 144
145 /* zero-byte xfers stop immediately */
146 if (q)
147 addr |= PSC_SMBTXRX_STP;
148
137 /* Put byte into fifo, start up master. 149 /* Put byte into fifo, start up master.
138 */ 150 */
139 sp->psc_smbtxrx = addr; 151 sp->psc_smbtxrx = addr;
@@ -142,7 +154,7 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd)
142 au_sync(); 154 au_sync();
143 if (wait_ack(adap)) 155 if (wait_ack(adap))
144 return -EIO; 156 return -EIO;
145 return 0; 157 return (q) ? wait_master_done(adap) : 0;
146} 158}
147 159
148static u32 160static u32
@@ -262,7 +274,8 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
262 274
263 for (i = 0; !err && i < num; i++) { 275 for (i = 0; !err && i < num; i++) {
264 p = &msgs[i]; 276 p = &msgs[i];
265 err = do_address(adap, p->addr, p->flags & I2C_M_RD); 277 err = do_address(adap, p->addr, p->flags & I2C_M_RD,
278 (p->len == 0));
266 if (err || !p->len) 279 if (err || !p->len)
267 continue; 280 continue;
268 if (p->flags & I2C_M_RD) 281 if (p->flags & I2C_M_RD)
@@ -294,18 +307,48 @@ static const struct i2c_algorithm au1550_algo = {
294 * Prior to calling us, the 50MHz clock frequency and routing 307 * Prior to calling us, the 50MHz clock frequency and routing
295 * must have been set up for the PSC indicated by the adapter. 308 * must have been set up for the PSC indicated by the adapter.
296 */ 309 */
297int 310static int __devinit
298i2c_au1550_add_bus(struct i2c_adapter *i2c_adap) 311i2c_au1550_probe(struct platform_device *pdev)
299{ 312{
300 struct i2c_au1550_data *adap = i2c_adap->algo_data; 313 struct i2c_au1550_data *priv;
301 volatile psc_smb_t *sp; 314 volatile psc_smb_t *sp;
302 u32 stat; 315 struct resource *r;
316 u32 stat;
317 int ret;
318
319 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
320 if (!r) {
321 ret = -ENODEV;
322 goto out;
323 }
324
325 priv = kzalloc(sizeof(struct i2c_au1550_data), GFP_KERNEL);
326 if (!priv) {
327 ret = -ENOMEM;
328 goto out;
329 }
330
331 priv->ioarea = request_mem_region(r->start, r->end - r->start + 1,
332 pdev->name);
333 if (!priv->ioarea) {
334 ret = -EBUSY;
335 goto out_mem;
336 }
303 337
304 i2c_adap->algo = &au1550_algo; 338 priv->psc_base = r->start;
339 priv->xfer_timeout = 200;
340 priv->ack_timeout = 200;
341
342 priv->adap.id = I2C_HW_AU1550_PSC;
343 priv->adap.nr = pdev->id;
344 priv->adap.algo = &au1550_algo;
345 priv->adap.algo_data = priv;
346 priv->adap.dev.parent = &pdev->dev;
347 strlcpy(priv->adap.name, "Au1xxx PSC I2C", sizeof(priv->adap.name));
305 348
306 /* Now, set up the PSC for SMBus PIO mode. 349 /* Now, set up the PSC for SMBus PIO mode.
307 */ 350 */
308 sp = (volatile psc_smb_t *)(adap->psc_base); 351 sp = (volatile psc_smb_t *)priv->psc_base;
309 sp->psc_ctrl = PSC_CTRL_DISABLE; 352 sp->psc_ctrl = PSC_CTRL_DISABLE;
310 au_sync(); 353 au_sync();
311 sp->psc_sel = PSC_SEL_PS_SMBUSMODE; 354 sp->psc_sel = PSC_SEL_PS_SMBUSMODE;
@@ -343,87 +386,87 @@ i2c_au1550_add_bus(struct i2c_adapter *i2c_adap)
343 au_sync(); 386 au_sync();
344 } while ((stat & PSC_SMBSTAT_DR) == 0); 387 } while ((stat & PSC_SMBSTAT_DR) == 0);
345 388
346 return i2c_add_adapter(i2c_adap); 389 ret = i2c_add_numbered_adapter(&priv->adap);
347} 390 if (ret == 0) {
391 platform_set_drvdata(pdev, priv);
392 return 0;
393 }
348 394
395 /* disable the PSC */
396 sp->psc_smbcfg = 0;
397 sp->psc_ctrl = PSC_CTRL_DISABLE;
398 au_sync();
349 399
350int 400 release_resource(priv->ioarea);
351i2c_au1550_del_bus(struct i2c_adapter *adap) 401 kfree(priv->ioarea);
402out_mem:
403 kfree(priv);
404out:
405 return ret;
406}
407
408static int __devexit
409i2c_au1550_remove(struct platform_device *pdev)
352{ 410{
353 return i2c_del_adapter(adap); 411 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
412 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
413
414 platform_set_drvdata(pdev, NULL);
415 i2c_del_adapter(&priv->adap);
416 sp->psc_smbcfg = 0;
417 sp->psc_ctrl = PSC_CTRL_DISABLE;
418 au_sync();
419 release_resource(priv->ioarea);
420 kfree(priv->ioarea);
421 kfree(priv);
422 return 0;
354} 423}
355 424
356static int 425static int
357pb1550_reg(struct i2c_client *client) 426i2c_au1550_suspend(struct platform_device *pdev, pm_message_t state)
358{ 427{
428 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
429 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
430
431 sp->psc_ctrl = PSC_CTRL_SUSPEND;
432 au_sync();
359 return 0; 433 return 0;
360} 434}
361 435
362static int 436static int
363pb1550_unreg(struct i2c_client *client) 437i2c_au1550_resume(struct platform_device *pdev)
364{ 438{
439 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
440 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
441
442 sp->psc_ctrl = PSC_CTRL_ENABLE;
443 au_sync();
444 while (!(sp->psc_smbstat & PSC_SMBSTAT_SR))
445 au_sync();
365 return 0; 446 return 0;
366} 447}
367 448
368static struct i2c_au1550_data pb1550_i2c_info = { 449static struct platform_driver au1xpsc_smbus_driver = {
369 SMBUS_PSC_BASE, 200, 200 450 .driver = {
370}; 451 .name = "au1xpsc_smbus",
371 452 .owner = THIS_MODULE,
372static struct i2c_adapter pb1550_board_adapter = { 453 },
373 name: "pb1550 adapter", 454 .probe = i2c_au1550_probe,
374 id: I2C_HW_AU1550_PSC, 455 .remove = __devexit_p(i2c_au1550_remove),
375 algo: NULL, 456 .suspend = i2c_au1550_suspend,
376 algo_data: &pb1550_i2c_info, 457 .resume = i2c_au1550_resume,
377 client_register: pb1550_reg,
378 client_unregister: pb1550_unreg,
379}; 458};
380 459
381/* BIG hack to support the control interface on the Wolfson WM8731
382 * audio codec on the Pb1550 board. We get an address and two data
383 * bytes to write, create an i2c message, and send it across the
384 * i2c transfer function. We do this here because we have access to
385 * the i2c adapter structure.
386 */
387static struct i2c_msg wm_i2c_msg; /* We don't want this stuff on the stack */
388static u8 i2cbuf[2];
389
390int
391pb1550_wm_codec_write(u8 addr, u8 reg, u8 val)
392{
393 wm_i2c_msg.addr = addr;
394 wm_i2c_msg.flags = 0;
395 wm_i2c_msg.buf = i2cbuf;
396 wm_i2c_msg.len = 2;
397 i2cbuf[0] = reg;
398 i2cbuf[1] = val;
399
400 return pb1550_board_adapter.algo->master_xfer(&pb1550_board_adapter, &wm_i2c_msg, 1);
401}
402
403static int __init 460static int __init
404i2c_au1550_init(void) 461i2c_au1550_init(void)
405{ 462{
406 printk(KERN_INFO "Au1550 I2C: "); 463 return platform_driver_register(&au1xpsc_smbus_driver);
407
408 /* This is where we would set up a 50MHz clock source
409 * and routing. On the Pb1550, the SMBus is PSC2, which
410 * uses a shared clock with USB. This has been already
411 * configured by Yamon as a 48MHz clock, close enough
412 * for our work.
413 */
414 if (i2c_au1550_add_bus(&pb1550_board_adapter) < 0) {
415 printk("failed to initialize.\n");
416 return -ENODEV;
417 }
418
419 printk("initialized.\n");
420 return 0;
421} 464}
422 465
423static void __exit 466static void __exit
424i2c_au1550_exit(void) 467i2c_au1550_exit(void)
425{ 468{
426 i2c_au1550_del_bus(&pb1550_board_adapter); 469 platform_driver_unregister(&au1xpsc_smbus_driver);
427} 470}
428 471
429MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC."); 472MODULE_AUTHOR("Dan Malek, Embedded Edge, LLC.");