max14577.c (575343d161d75dc1516f53436b9eb47d04eda938) | max14577.c (eccb80cc22354a12255c2579247a92a30a4c881b) |
---|---|
1/* 2 * max14577.c - mfd core driver for the Maxim 14577 3 * 4 * Copyright (C) 2013 Samsung Electrnoics 5 * Chanwoo Choi <cw00.choi@samsung.com> 6 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 7 unchanged lines hidden (view full) --- 16 * GNU General Public License for more details. 17 * 18 * This driver is based on max8997.c 19 */ 20 21#include <linux/err.h> 22#include <linux/module.h> 23#include <linux/interrupt.h> | 1/* 2 * max14577.c - mfd core driver for the Maxim 14577 3 * 4 * Copyright (C) 2013 Samsung Electrnoics 5 * Chanwoo Choi <cw00.choi@samsung.com> 6 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 7 unchanged lines hidden (view full) --- 16 * GNU General Public License for more details. 17 * 18 * This driver is based on max8997.c 19 */ 20 21#include <linux/err.h> 22#include <linux/module.h> 23#include <linux/interrupt.h> |
24#include <linux/of_device.h> |
|
24#include <linux/mfd/core.h> 25#include <linux/mfd/max14577.h> 26#include <linux/mfd/max14577-private.h> 27 28static struct mfd_cell max14577_devs[] = { 29 { 30 .name = "max14577-muic", 31 .of_compatible = "maxim,max14577-muic", 32 }, 33 { 34 .name = "max14577-regulator", 35 .of_compatible = "maxim,max14577-regulator", 36 }, 37 { .name = "max14577-charger", }, 38}; 39 | 25#include <linux/mfd/core.h> 26#include <linux/mfd/max14577.h> 27#include <linux/mfd/max14577-private.h> 28 29static struct mfd_cell max14577_devs[] = { 30 { 31 .name = "max14577-muic", 32 .of_compatible = "maxim,max14577-muic", 33 }, 34 { 35 .name = "max14577-regulator", 36 .of_compatible = "maxim,max14577-regulator", 37 }, 38 { .name = "max14577-charger", }, 39}; 40 |
41static struct of_device_id max14577_dt_match[] = { 42 { 43 .compatible = "maxim,max14577", 44 .data = (void *)MAXIM_DEVICE_TYPE_MAX14577, 45 }, 46 {}, 47}; 48 |
|
40static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg) 41{ 42 switch (reg) { 43 case MAX14577_REG_INT1 ... MAX14577_REG_STATUS3: 44 return true; 45 default: 46 break; 47 } --- 30 unchanged lines hidden (view full) --- 78 .status_base = MAX14577_REG_INT1, 79 .mask_base = MAX14577_REG_INTMASK1, 80 .mask_invert = 1, 81 .num_regs = 3, 82 .irqs = max14577_irqs, 83 .num_irqs = ARRAY_SIZE(max14577_irqs), 84}; 85 | 49static bool max14577_muic_volatile_reg(struct device *dev, unsigned int reg) 50{ 51 switch (reg) { 52 case MAX14577_REG_INT1 ... MAX14577_REG_STATUS3: 53 return true; 54 default: 55 break; 56 } --- 30 unchanged lines hidden (view full) --- 87 .status_base = MAX14577_REG_INT1, 88 .mask_base = MAX14577_REG_INTMASK1, 89 .mask_invert = 1, 90 .num_regs = 3, 91 .irqs = max14577_irqs, 92 .num_irqs = ARRAY_SIZE(max14577_irqs), 93}; 94 |
95static void max14577_print_dev_type(struct max14577 *max14577) 96{ 97 u8 reg_data, vendor_id, device_id; 98 int ret; 99 100 ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID, 101 ®_data); 102 if (ret) { 103 dev_err(max14577->dev, 104 "Failed to read DEVICEID register: %d\n", ret); 105 return; 106 } 107 108 vendor_id = ((reg_data & DEVID_VENDORID_MASK) >> 109 DEVID_VENDORID_SHIFT); 110 device_id = ((reg_data & DEVID_DEVICEID_MASK) >> 111 DEVID_DEVICEID_SHIFT); 112 113 dev_info(max14577->dev, "Device type: %u (ID: 0x%x, vendor: 0x%x)\n", 114 max14577->dev_type, device_id, vendor_id); 115} 116 |
|
86static int max14577_i2c_probe(struct i2c_client *i2c, 87 const struct i2c_device_id *id) 88{ 89 struct max14577 *max14577; 90 struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev); 91 struct device_node *np = i2c->dev.of_node; | 117static int max14577_i2c_probe(struct i2c_client *i2c, 118 const struct i2c_device_id *id) 119{ 120 struct max14577 *max14577; 121 struct max14577_platform_data *pdata = dev_get_platdata(&i2c->dev); 122 struct device_node *np = i2c->dev.of_node; |
92 u8 reg_data; | |
93 int ret = 0; 94 95 if (np) { 96 pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); 97 if (!pdata) 98 return -ENOMEM; 99 i2c->dev.platform_data = pdata; 100 } --- 16 unchanged lines hidden (view full) --- 117 &max14577_muic_regmap_config); 118 if (IS_ERR(max14577->regmap)) { 119 ret = PTR_ERR(max14577->regmap); 120 dev_err(max14577->dev, "Failed to allocate register map: %d\n", 121 ret); 122 return ret; 123 } 124 | 123 int ret = 0; 124 125 if (np) { 126 pdata = devm_kzalloc(&i2c->dev, sizeof(*pdata), GFP_KERNEL); 127 if (!pdata) 128 return -ENOMEM; 129 i2c->dev.platform_data = pdata; 130 } --- 16 unchanged lines hidden (view full) --- 147 &max14577_muic_regmap_config); 148 if (IS_ERR(max14577->regmap)) { 149 ret = PTR_ERR(max14577->regmap); 150 dev_err(max14577->dev, "Failed to allocate register map: %d\n", 151 ret); 152 return ret; 153 } 154 |
125 ret = max14577_read_reg(max14577->regmap, MAX14577_REG_DEVICEID, 126 ®_data); 127 if (ret) { 128 dev_err(max14577->dev, "Device not found on this channel: %d\n", 129 ret); 130 return ret; | 155 if (np) { 156 const struct of_device_id *of_id; 157 158 of_id = of_match_device(max14577_dt_match, &i2c->dev); 159 if (of_id) 160 max14577->dev_type = (unsigned int)of_id->data; 161 } else { 162 max14577->dev_type = id->driver_data; |
131 } | 163 } |
132 max14577->vendor_id = ((reg_data & DEVID_VENDORID_MASK) >> 133 DEVID_VENDORID_SHIFT); 134 max14577->device_id = ((reg_data & DEVID_DEVICEID_MASK) >> 135 DEVID_DEVICEID_SHIFT); 136 dev_info(max14577->dev, "Device ID: 0x%x, vendor: 0x%x\n", 137 max14577->device_id, max14577->vendor_id); | |
138 | 164 |
165 max14577_print_dev_type(max14577); 166 |
|
139 ret = regmap_add_irq_chip(max14577->regmap, max14577->irq, 140 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0, 141 &max14577_irq_chip, 142 &max14577->irq_data); 143 if (ret != 0) { 144 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n", 145 max14577->irq, ret); 146 return ret; --- 21 unchanged lines hidden (view full) --- 168 169 mfd_remove_devices(max14577->dev); 170 regmap_del_irq_chip(max14577->irq, max14577->irq_data); 171 172 return 0; 173} 174 175static const struct i2c_device_id max14577_i2c_id[] = { | 167 ret = regmap_add_irq_chip(max14577->regmap, max14577->irq, 168 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 0, 169 &max14577_irq_chip, 170 &max14577->irq_data); 171 if (ret != 0) { 172 dev_err(&i2c->dev, "Failed to request IRQ %d: %d\n", 173 max14577->irq, ret); 174 return ret; --- 21 unchanged lines hidden (view full) --- 196 197 mfd_remove_devices(max14577->dev); 198 regmap_del_irq_chip(max14577->irq, max14577->irq_data); 199 200 return 0; 201} 202 203static const struct i2c_device_id max14577_i2c_id[] = { |
176 { "max14577", 0 }, | 204 { "max14577", MAXIM_DEVICE_TYPE_MAX14577, }, |
177 { } 178}; 179MODULE_DEVICE_TABLE(i2c, max14577_i2c_id); 180 181#ifdef CONFIG_PM_SLEEP 182static int max14577_suspend(struct device *dev) 183{ 184 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); --- 26 unchanged lines hidden (view full) --- 211 disable_irq_wake(max14577->irq); 212 enable_irq(max14577->irq); 213 } 214 215 return 0; 216} 217#endif /* CONFIG_PM_SLEEP */ 218 | 205 { } 206}; 207MODULE_DEVICE_TABLE(i2c, max14577_i2c_id); 208 209#ifdef CONFIG_PM_SLEEP 210static int max14577_suspend(struct device *dev) 211{ 212 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); --- 26 unchanged lines hidden (view full) --- 239 disable_irq_wake(max14577->irq); 240 enable_irq(max14577->irq); 241 } 242 243 return 0; 244} 245#endif /* CONFIG_PM_SLEEP */ 246 |
219static struct of_device_id max14577_dt_match[] = { 220 { .compatible = "maxim,max14577", }, 221 {}, 222}; 223 | |
224static SIMPLE_DEV_PM_OPS(max14577_pm, max14577_suspend, max14577_resume); 225 226static struct i2c_driver max14577_i2c_driver = { 227 .driver = { 228 .name = "max14577", 229 .owner = THIS_MODULE, 230 .pm = &max14577_pm, 231 .of_match_table = max14577_dt_match, 232 }, 233 .probe = max14577_i2c_probe, 234 .remove = max14577_i2c_remove, 235 .id_table = max14577_i2c_id, 236}; 237 238static int __init max14577_i2c_init(void) 239{ | 247static SIMPLE_DEV_PM_OPS(max14577_pm, max14577_suspend, max14577_resume); 248 249static struct i2c_driver max14577_i2c_driver = { 250 .driver = { 251 .name = "max14577", 252 .owner = THIS_MODULE, 253 .pm = &max14577_pm, 254 .of_match_table = max14577_dt_match, 255 }, 256 .probe = max14577_i2c_probe, 257 .remove = max14577_i2c_remove, 258 .id_table = max14577_i2c_id, 259}; 260 261static int __init max14577_i2c_init(void) 262{ |
263 BUILD_BUG_ON(ARRAY_SIZE(max14577_i2c_id) != MAXIM_DEVICE_TYPE_NUM); 264 BUILD_BUG_ON(ARRAY_SIZE(max14577_dt_match) != MAXIM_DEVICE_TYPE_NUM); 265 |
|
240 return i2c_add_driver(&max14577_i2c_driver); 241} 242subsys_initcall(max14577_i2c_init); 243 244static void __exit max14577_i2c_exit(void) 245{ 246 i2c_del_driver(&max14577_i2c_driver); 247} 248module_exit(max14577_i2c_exit); 249 250MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 251MODULE_DESCRIPTION("MAXIM 14577 multi-function core driver"); 252MODULE_LICENSE("GPL"); | 266 return i2c_add_driver(&max14577_i2c_driver); 267} 268subsys_initcall(max14577_i2c_init); 269 270static void __exit max14577_i2c_exit(void) 271{ 272 i2c_del_driver(&max14577_i2c_driver); 273} 274module_exit(max14577_i2c_exit); 275 276MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com>"); 277MODULE_DESCRIPTION("MAXIM 14577 multi-function core driver"); 278MODULE_LICENSE("GPL"); |