Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 1 | /* |
| 2 | * TI SMSC MFD Driver |
| 3 | * |
| 4 | * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com |
| 5 | * |
| 6 | * Author: Sourav Poddar <sourav.poddar@ti.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; GPL v2. |
| 11 | * |
| 12 | */ |
| 13 | |
Paul Gortmaker | da4d0f2 | 2016-09-12 10:40:52 -0400 | [diff] [blame] | 14 | #include <linux/init.h> |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 15 | #include <linux/slab.h> |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/gpio.h> |
| 18 | #include <linux/workqueue.h> |
| 19 | #include <linux/irq.h> |
| 20 | #include <linux/regmap.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/mfd/core.h> |
| 23 | #include <linux/mfd/smsc.h> |
| 24 | #include <linux/of_platform.h> |
| 25 | |
Krzysztof Kozlowski | 486212f | 2015-01-05 10:01:29 +0100 | [diff] [blame] | 26 | static const struct regmap_config smsc_regmap_config = { |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 27 | .reg_bits = 8, |
| 28 | .val_bits = 8, |
| 29 | .max_register = SMSC_VEN_ID_H, |
| 30 | .cache_type = REGCACHE_RBTREE, |
| 31 | }; |
| 32 | |
| 33 | static int smsc_i2c_probe(struct i2c_client *i2c, |
| 34 | const struct i2c_device_id *id) |
| 35 | { |
| 36 | struct smsc *smsc; |
| 37 | int devid, rev, venid_l, venid_h; |
Markus Elfring | 53b34b8 | 2016-06-26 14:14:54 +0200 | [diff] [blame] | 38 | int ret; |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 39 | |
Markus Elfring | 8349aeb | 2018-03-08 15:05:16 +0100 | [diff] [blame] | 40 | smsc = devm_kzalloc(&i2c->dev, sizeof(*smsc), GFP_KERNEL); |
Markus Elfring | 46c8aa8 | 2018-01-16 08:52:27 +0100 | [diff] [blame] | 41 | if (!smsc) |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 42 | return -ENOMEM; |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 43 | |
| 44 | smsc->regmap = devm_regmap_init_i2c(i2c, &smsc_regmap_config); |
Markus Elfring | 4dc03d0 | 2016-06-26 14:30:46 +0200 | [diff] [blame] | 45 | if (IS_ERR(smsc->regmap)) |
| 46 | return PTR_ERR(smsc->regmap); |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 47 | |
| 48 | i2c_set_clientdata(i2c, smsc); |
| 49 | smsc->dev = &i2c->dev; |
| 50 | |
| 51 | #ifdef CONFIG_OF |
| 52 | of_property_read_u32(i2c->dev.of_node, "clock", &smsc->clk); |
| 53 | #endif |
| 54 | |
| 55 | regmap_read(smsc->regmap, SMSC_DEV_ID, &devid); |
| 56 | regmap_read(smsc->regmap, SMSC_DEV_REV, &rev); |
| 57 | regmap_read(smsc->regmap, SMSC_VEN_ID_L, &venid_l); |
| 58 | regmap_read(smsc->regmap, SMSC_VEN_ID_H, &venid_h); |
| 59 | |
| 60 | dev_info(&i2c->dev, "SMSCxxx devid: %02x rev: %02x venid: %02x\n", |
| 61 | devid, rev, (venid_h << 8) | venid_l); |
| 62 | |
| 63 | ret = regmap_write(smsc->regmap, SMSC_CLK_CTRL, smsc->clk); |
| 64 | if (ret) |
Markus Elfring | 4dc03d0 | 2016-06-26 14:30:46 +0200 | [diff] [blame] | 65 | return ret; |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 66 | |
| 67 | #ifdef CONFIG_OF |
| 68 | if (i2c->dev.of_node) |
Benjamin Gaignard | 6600216 | 2017-05-29 17:46:01 +0200 | [diff] [blame] | 69 | ret = devm_of_platform_populate(&i2c->dev); |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 70 | #endif |
| 71 | |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 72 | return ret; |
| 73 | } |
| 74 | |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 75 | static const struct i2c_device_id smsc_i2c_id[] = { |
| 76 | { "smscece1099", 0}, |
| 77 | {}, |
| 78 | }; |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 79 | |
| 80 | static struct i2c_driver smsc_i2c_driver = { |
| 81 | .driver = { |
| 82 | .name = "smsc", |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 83 | }, |
| 84 | .probe = smsc_i2c_probe, |
Sourav Poddar | 8284328 | 2012-10-01 16:31:22 +0530 | [diff] [blame] | 85 | .id_table = smsc_i2c_id, |
| 86 | }; |
Paul Gortmaker | da4d0f2 | 2016-09-12 10:40:52 -0400 | [diff] [blame] | 87 | builtin_i2c_driver(smsc_i2c_driver); |