2 * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood
7 * linux@wolfsonmicro.com
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/init.h>
19 #include <linux/i2c.h>
20 #include <linux/platform_device.h>
21 #include <linux/mfd/wm8350/core.h>
22 #include <linux/slab.h>
24 static int wm8350_i2c_read_device(struct wm8350
*wm8350
, char reg
,
25 int bytes
, void *dest
)
29 ret
= i2c_master_send(wm8350
->i2c_client
, ®
, 1);
32 ret
= i2c_master_recv(wm8350
->i2c_client
, dest
, bytes
);
40 static int wm8350_i2c_write_device(struct wm8350
*wm8350
, char reg
,
43 /* we add 1 byte for device register */
44 u8 msg
[(WM8350_MAX_REGISTER
<< 1) + 1];
47 if (bytes
> ((WM8350_MAX_REGISTER
<< 1) + 1))
51 memcpy(&msg
[1], src
, bytes
);
52 ret
= i2c_master_send(wm8350
->i2c_client
, msg
, bytes
+ 1);
60 static int wm8350_i2c_probe(struct i2c_client
*i2c
,
61 const struct i2c_device_id
*id
)
63 struct wm8350
*wm8350
;
66 wm8350
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm8350
), GFP_KERNEL
);
70 i2c_set_clientdata(i2c
, wm8350
);
71 wm8350
->dev
= &i2c
->dev
;
72 wm8350
->i2c_client
= i2c
;
73 wm8350
->read_dev
= wm8350_i2c_read_device
;
74 wm8350
->write_dev
= wm8350_i2c_write_device
;
76 ret
= wm8350_device_init(wm8350
, i2c
->irq
, i2c
->dev
.platform_data
);
86 static int wm8350_i2c_remove(struct i2c_client
*i2c
)
88 struct wm8350
*wm8350
= i2c_get_clientdata(i2c
);
90 wm8350_device_exit(wm8350
);
95 static const struct i2c_device_id wm8350_i2c_id
[] = {
101 MODULE_DEVICE_TABLE(i2c
, wm8350_i2c_id
);
104 static struct i2c_driver wm8350_i2c_driver
= {
107 .owner
= THIS_MODULE
,
109 .probe
= wm8350_i2c_probe
,
110 .remove
= wm8350_i2c_remove
,
111 .id_table
= wm8350_i2c_id
,
114 static int __init
wm8350_i2c_init(void)
116 return i2c_add_driver(&wm8350_i2c_driver
);
118 /* init early so consumer devices can complete system boot */
119 subsys_initcall(wm8350_i2c_init
);
121 static void __exit
wm8350_i2c_exit(void)
123 i2c_del_driver(&wm8350_i2c_driver
);
125 module_exit(wm8350_i2c_exit
);
127 MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
128 MODULE_LICENSE("GPL");