2 * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
4 * This driver defines and configures the WM8350 for the Freescale i.MX32ADS.
6 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
8 * Author: Liam Girdwood
9 * linux@wolfsonmicro.com
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/init.h>
21 #include <linux/i2c.h>
22 #include <linux/platform_device.h>
23 #include <linux/mfd/wm8350/core.h>
25 static int wm8350_i2c_read_device(struct wm8350
*wm8350
, char reg
,
26 int bytes
, void *dest
)
30 ret
= i2c_master_send(wm8350
->i2c_client
, ®
, 1);
33 return i2c_master_recv(wm8350
->i2c_client
, dest
, bytes
);
36 static int wm8350_i2c_write_device(struct wm8350
*wm8350
, char reg
,
39 /* we add 1 byte for device register */
40 u8 msg
[(WM8350_MAX_REGISTER
<< 1) + 1];
42 if (bytes
> ((WM8350_MAX_REGISTER
<< 1) + 1))
46 memcpy(&msg
[1], src
, bytes
);
47 return i2c_master_send(wm8350
->i2c_client
, msg
, bytes
+ 1);
50 static int wm8350_i2c_probe(struct i2c_client
*i2c
,
51 const struct i2c_device_id
*id
)
53 struct wm8350
*wm8350
;
56 wm8350
= kzalloc(sizeof(struct wm8350
), GFP_KERNEL
);
62 i2c_set_clientdata(i2c
, wm8350
);
63 wm8350
->dev
= &i2c
->dev
;
64 wm8350
->i2c_client
= i2c
;
65 wm8350
->read_dev
= wm8350_i2c_read_device
;
66 wm8350
->write_dev
= wm8350_i2c_write_device
;
68 ret
= wm8350_device_init(wm8350
, i2c
->irq
, i2c
->dev
.platform_data
);
79 static int wm8350_i2c_remove(struct i2c_client
*i2c
)
81 struct wm8350
*wm8350
= i2c_get_clientdata(i2c
);
83 wm8350_device_exit(wm8350
);
89 static const struct i2c_device_id wm8350_i2c_id
[] = {
93 MODULE_DEVICE_TABLE(i2c
, wm8350_i2c_id
);
96 static struct i2c_driver wm8350_i2c_driver
= {
101 .probe
= wm8350_i2c_probe
,
102 .remove
= wm8350_i2c_remove
,
103 .id_table
= wm8350_i2c_id
,
106 static int __init
wm8350_i2c_init(void)
108 return i2c_add_driver(&wm8350_i2c_driver
);
110 /* init early so consumer devices can complete system boot */
111 subsys_initcall(wm8350_i2c_init
);
113 static void __exit
wm8350_i2c_exit(void)
115 i2c_del_driver(&wm8350_i2c_driver
);
117 module_exit(wm8350_i2c_exit
);
119 MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
120 MODULE_LICENSE("GPL");