Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Broadcom BCM590xx PMU |
| 3 | * |
| 4 | * Copyright 2014 Linaro Limited |
| 5 | * Author: Matt Porter <mporter@linaro.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/err.h> |
| 14 | #include <linux/i2c.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/mfd/bcm590xx.h> |
| 17 | #include <linux/mfd/core.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/of_device.h> |
| 22 | #include <linux/regmap.h> |
| 23 | #include <linux/slab.h> |
| 24 | |
| 25 | static const struct mfd_cell bcm590xx_devs[] = { |
| 26 | { |
| 27 | .name = "bcm590xx-vregs", |
| 28 | }, |
| 29 | }; |
| 30 | |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 31 | static const struct regmap_config bcm590xx_regmap_config_pri = { |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 32 | .reg_bits = 8, |
| 33 | .val_bits = 8, |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 34 | .max_register = BCM590XX_MAX_REGISTER_PRI, |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 35 | .cache_type = REGCACHE_RBTREE, |
| 36 | }; |
| 37 | |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 38 | static const struct regmap_config bcm590xx_regmap_config_sec = { |
| 39 | .reg_bits = 8, |
| 40 | .val_bits = 8, |
| 41 | .max_register = BCM590XX_MAX_REGISTER_SEC, |
| 42 | .cache_type = REGCACHE_RBTREE, |
| 43 | }; |
| 44 | |
| 45 | static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri, |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 46 | const struct i2c_device_id *id) |
| 47 | { |
| 48 | struct bcm590xx *bcm590xx; |
| 49 | int ret; |
| 50 | |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 51 | bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL); |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 52 | if (!bcm590xx) |
| 53 | return -ENOMEM; |
| 54 | |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 55 | i2c_set_clientdata(i2c_pri, bcm590xx); |
| 56 | bcm590xx->dev = &i2c_pri->dev; |
| 57 | bcm590xx->i2c_pri = i2c_pri; |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 58 | |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 59 | bcm590xx->regmap_pri = devm_regmap_init_i2c(i2c_pri, |
| 60 | &bcm590xx_regmap_config_pri); |
| 61 | if (IS_ERR(bcm590xx->regmap_pri)) { |
| 62 | ret = PTR_ERR(bcm590xx->regmap_pri); |
| 63 | dev_err(&i2c_pri->dev, "primary regmap init failed: %d\n", ret); |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 64 | return ret; |
| 65 | } |
| 66 | |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 67 | /* Secondary I2C slave address is the base address with A(2) asserted */ |
| 68 | bcm590xx->i2c_sec = i2c_new_dummy(i2c_pri->adapter, |
| 69 | i2c_pri->addr | BIT(2)); |
| 70 | if (IS_ERR_OR_NULL(bcm590xx->i2c_sec)) { |
| 71 | dev_err(&i2c_pri->dev, "failed to add secondary I2C device\n"); |
| 72 | return -ENODEV; |
| 73 | } |
| 74 | i2c_set_clientdata(bcm590xx->i2c_sec, bcm590xx); |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 75 | |
Matt Porter | 9e1e726 | 2014-04-23 19:21:31 -0400 | [diff] [blame] | 76 | bcm590xx->regmap_sec = devm_regmap_init_i2c(bcm590xx->i2c_sec, |
| 77 | &bcm590xx_regmap_config_sec); |
| 78 | if (IS_ERR(bcm590xx->regmap_sec)) { |
| 79 | ret = PTR_ERR(bcm590xx->regmap_sec); |
| 80 | dev_err(&bcm590xx->i2c_sec->dev, |
| 81 | "secondary regmap init failed: %d\n", ret); |
| 82 | goto err; |
| 83 | } |
| 84 | |
| 85 | ret = mfd_add_devices(&i2c_pri->dev, -1, bcm590xx_devs, |
| 86 | ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL); |
| 87 | if (ret < 0) { |
| 88 | dev_err(&i2c_pri->dev, "failed to add sub-devices: %d\n", ret); |
| 89 | goto err; |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | |
| 94 | err: |
| 95 | i2c_unregister_device(bcm590xx->i2c_sec); |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 96 | return ret; |
| 97 | } |
| 98 | |
Axel Lin | 2b29ff7 | 2014-03-31 21:32:37 +0800 | [diff] [blame] | 99 | static int bcm590xx_i2c_remove(struct i2c_client *i2c) |
| 100 | { |
| 101 | mfd_remove_devices(&i2c->dev); |
| 102 | return 0; |
| 103 | } |
| 104 | |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 105 | static const struct of_device_id bcm590xx_of_match[] = { |
| 106 | { .compatible = "brcm,bcm59056" }, |
| 107 | { } |
| 108 | }; |
Axel Lin | 3827c51 | 2014-03-15 09:24:50 +0800 | [diff] [blame] | 109 | MODULE_DEVICE_TABLE(of, bcm590xx_of_match); |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 110 | |
| 111 | static const struct i2c_device_id bcm590xx_i2c_id[] = { |
| 112 | { "bcm59056" }, |
| 113 | { } |
| 114 | }; |
| 115 | MODULE_DEVICE_TABLE(i2c, bcm590xx_i2c_id); |
| 116 | |
| 117 | static struct i2c_driver bcm590xx_i2c_driver = { |
| 118 | .driver = { |
| 119 | .name = "bcm590xx", |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 120 | .of_match_table = of_match_ptr(bcm590xx_of_match), |
| 121 | }, |
| 122 | .probe = bcm590xx_i2c_probe, |
Axel Lin | 2b29ff7 | 2014-03-31 21:32:37 +0800 | [diff] [blame] | 123 | .remove = bcm590xx_i2c_remove, |
Matt Porter | 037b60f | 2014-03-11 19:33:54 -0400 | [diff] [blame] | 124 | .id_table = bcm590xx_i2c_id, |
| 125 | }; |
| 126 | module_i2c_driver(bcm590xx_i2c_driver); |
| 127 | |
| 128 | MODULE_AUTHOR("Matt Porter <mporter@linaro.org>"); |
| 129 | MODULE_DESCRIPTION("BCM590xx multi-function driver"); |
| 130 | MODULE_LICENSE("GPL v2"); |