-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 220631 b: refs/heads/master c: e5b4868 h: refs/heads/master i: 220629: ab8fe0a 220627: 41a7bf5 220623: b1ece32 v: v3
- Loading branch information
Mark Brown
authored and
Samuel Ortiz
committed
Oct 28, 2010
1 parent
125422a
commit 1bff609
Showing
7 changed files
with
172 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 00969f23dae70f62d7ce3f7abbbfb6d09ef92739 | ||
refs/heads/master: e5b486841d572c5ac83c798f82f4f67cbbac5320 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* wm831x-i2c.c -- I2C access for Wolfson WM831x PMICs | ||
* | ||
* Copyright 2009,2010 Wolfson Microelectronics PLC. | ||
* | ||
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. | ||
* | ||
*/ | ||
|
||
#include <linux/kernel.h> | ||
#include <linux/module.h> | ||
#include <linux/i2c.h> | ||
#include <linux/delay.h> | ||
#include <linux/mfd/core.h> | ||
#include <linux/slab.h> | ||
|
||
#include <linux/mfd/wm831x/core.h> | ||
#include <linux/mfd/wm831x/pdata.h> | ||
|
||
static int wm831x_i2c_read_device(struct wm831x *wm831x, unsigned short reg, | ||
int bytes, void *dest) | ||
{ | ||
struct i2c_client *i2c = wm831x->control_data; | ||
int ret; | ||
u16 r = cpu_to_be16(reg); | ||
|
||
ret = i2c_master_send(i2c, (unsigned char *)&r, 2); | ||
if (ret < 0) | ||
return ret; | ||
if (ret != 2) | ||
return -EIO; | ||
|
||
ret = i2c_master_recv(i2c, dest, bytes); | ||
if (ret < 0) | ||
return ret; | ||
if (ret != bytes) | ||
return -EIO; | ||
return 0; | ||
} | ||
|
||
/* Currently we allocate the write buffer on the stack; this is OK for | ||
* small writes - if we need to do large writes this will need to be | ||
* revised. | ||
*/ | ||
static int wm831x_i2c_write_device(struct wm831x *wm831x, unsigned short reg, | ||
int bytes, void *src) | ||
{ | ||
struct i2c_client *i2c = wm831x->control_data; | ||
unsigned char msg[bytes + 2]; | ||
int ret; | ||
|
||
reg = cpu_to_be16(reg); | ||
memcpy(&msg[0], ®, 2); | ||
memcpy(&msg[2], src, bytes); | ||
|
||
ret = i2c_master_send(i2c, msg, bytes + 2); | ||
if (ret < 0) | ||
return ret; | ||
if (ret < bytes + 2) | ||
return -EIO; | ||
|
||
return 0; | ||
} | ||
|
||
static int wm831x_i2c_probe(struct i2c_client *i2c, | ||
const struct i2c_device_id *id) | ||
{ | ||
struct wm831x *wm831x; | ||
|
||
wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL); | ||
if (wm831x == NULL) | ||
return -ENOMEM; | ||
|
||
i2c_set_clientdata(i2c, wm831x); | ||
wm831x->dev = &i2c->dev; | ||
wm831x->control_data = i2c; | ||
wm831x->read_dev = wm831x_i2c_read_device; | ||
wm831x->write_dev = wm831x_i2c_write_device; | ||
|
||
return wm831x_device_init(wm831x, id->driver_data, i2c->irq); | ||
} | ||
|
||
static int wm831x_i2c_remove(struct i2c_client *i2c) | ||
{ | ||
struct wm831x *wm831x = i2c_get_clientdata(i2c); | ||
|
||
wm831x_device_exit(wm831x); | ||
|
||
return 0; | ||
} | ||
|
||
static int wm831x_i2c_suspend(struct i2c_client *i2c, pm_message_t mesg) | ||
{ | ||
struct wm831x *wm831x = i2c_get_clientdata(i2c); | ||
|
||
return wm831x_device_suspend(wm831x); | ||
} | ||
|
||
static const struct i2c_device_id wm831x_i2c_id[] = { | ||
{ "wm8310", WM8310 }, | ||
{ "wm8311", WM8311 }, | ||
{ "wm8312", WM8312 }, | ||
{ "wm8320", WM8320 }, | ||
{ "wm8321", WM8321 }, | ||
{ "wm8325", WM8325 }, | ||
{ } | ||
}; | ||
MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id); | ||
|
||
|
||
static struct i2c_driver wm831x_i2c_driver = { | ||
.driver = { | ||
.name = "wm831x", | ||
.owner = THIS_MODULE, | ||
}, | ||
.probe = wm831x_i2c_probe, | ||
.remove = wm831x_i2c_remove, | ||
.suspend = wm831x_i2c_suspend, | ||
.id_table = wm831x_i2c_id, | ||
}; | ||
|
||
static int __init wm831x_i2c_init(void) | ||
{ | ||
int ret; | ||
|
||
ret = i2c_add_driver(&wm831x_i2c_driver); | ||
if (ret != 0) | ||
pr_err("Failed to register wm831x I2C driver: %d\n", ret); | ||
|
||
return ret; | ||
} | ||
subsys_initcall(wm831x_i2c_init); | ||
|
||
static void __exit wm831x_i2c_exit(void) | ||
{ | ||
i2c_del_driver(&wm831x_i2c_driver); | ||
} | ||
module_exit(wm831x_i2c_exit); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters