Blame view
drivers/mfd/wm831x-i2c.c
2.62 KB
e5b486841 mfd: Factor out W... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* * 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> |
1df5981b8 mfd: Convert WM83... |
21 22 |
#include <linux/err.h> #include <linux/regmap.h> |
e5b486841 mfd: Factor out W... |
23 24 25 |
#include <linux/mfd/wm831x/core.h> #include <linux/mfd/wm831x/pdata.h> |
e5b486841 mfd: Factor out W... |
26 27 28 29 |
static int wm831x_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { struct wm831x *wm831x; |
1df5981b8 mfd: Convert WM83... |
30 |
int ret; |
e5b486841 mfd: Factor out W... |
31 |
|
d48cbb743 mfd: Convert wm83... |
32 |
wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL); |
e5b486841 mfd: Factor out W... |
33 34 35 36 37 |
if (wm831x == NULL) return -ENOMEM; i2c_set_clientdata(i2c, wm831x); wm831x->dev = &i2c->dev; |
1df5981b8 mfd: Convert WM83... |
38 39 40 41 42 43 44 |
wm831x->regmap = regmap_init_i2c(i2c, &wm831x_regmap_config); if (IS_ERR(wm831x->regmap)) { ret = PTR_ERR(wm831x->regmap); dev_err(wm831x->dev, "Failed to allocate register map: %d ", ret); |
1df5981b8 mfd: Convert WM83... |
45 46 |
return ret; } |
e5b486841 mfd: Factor out W... |
47 48 49 50 51 52 53 54 55 56 57 58 |
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; } |
c538ddbe4 mfd: Convert WM83... |
59 |
static int wm831x_i2c_suspend(struct device *dev) |
e5b486841 mfd: Factor out W... |
60 |
{ |
c538ddbe4 mfd: Convert WM83... |
61 |
struct wm831x *wm831x = dev_get_drvdata(dev); |
e5b486841 mfd: Factor out W... |
62 63 64 |
return wm831x_device_suspend(wm831x); } |
523d9cfbb mfd: Support soft... |
65 66 67 68 69 70 |
static void wm831x_i2c_shutdown(struct i2c_client *i2c) { struct wm831x *wm831x = i2c_get_clientdata(i2c); wm831x_device_shutdown(wm831x); } |
e5b486841 mfd: Factor out W... |
71 72 73 74 75 76 77 |
static const struct i2c_device_id wm831x_i2c_id[] = { { "wm8310", WM8310 }, { "wm8311", WM8311 }, { "wm8312", WM8312 }, { "wm8320", WM8320 }, { "wm8321", WM8321 }, { "wm8325", WM8325 }, |
412dc11d3 mfd: Add WM8326 s... |
78 |
{ "wm8326", WM8326 }, |
e5b486841 mfd: Factor out W... |
79 80 81 |
{ } }; MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id); |
c538ddbe4 mfd: Convert WM83... |
82 83 84 |
static const struct dev_pm_ops wm831x_pm_ops = { .suspend = wm831x_i2c_suspend, }; |
e5b486841 mfd: Factor out W... |
85 86 87 |
static struct i2c_driver wm831x_i2c_driver = { .driver = { |
c538ddbe4 mfd: Convert WM83... |
88 89 90 |
.name = "wm831x", .owner = THIS_MODULE, .pm = &wm831x_pm_ops, |
e5b486841 mfd: Factor out W... |
91 92 93 |
}, .probe = wm831x_i2c_probe, .remove = wm831x_i2c_remove, |
523d9cfbb mfd: Support soft... |
94 |
.shutdown = wm831x_i2c_shutdown, |
e5b486841 mfd: Factor out W... |
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
.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 ", 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); |