Blame view
drivers/mfd/as3711.c
6.07 KB
acad189b0
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* * AS3711 PMIC MFC driver * * Copyright (C) 2012 Renesas Electronics Corporation * Author: Guennadi Liakhovetski, <g.liakhovetski@gmx.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the version 2 of the GNU General Public License as * published by the Free Software Foundation */ #include <linux/device.h> #include <linux/err.h> #include <linux/i2c.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/mfd/as3711.h> #include <linux/mfd/core.h> #include <linux/module.h> |
0af6f271d
|
20 |
#include <linux/of.h> |
acad189b0
|
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
#include <linux/regmap.h> #include <linux/slab.h> enum { AS3711_REGULATOR, AS3711_BACKLIGHT, }; /* * Ok to have it static: it is only used during probing and multiple I2C devices * cannot be probed simultaneously. Just make sure to avoid stale data. */ static struct mfd_cell as3711_subdevs[] = { [AS3711_REGULATOR] = {.name = "as3711-regulator",}, [AS3711_BACKLIGHT] = {.name = "as3711-backlight",}, }; static bool as3711_volatile_reg(struct device *dev, unsigned int reg) { switch (reg) { case AS3711_GPIO_SIGNAL_IN: case AS3711_INTERRUPT_STATUS_1: case AS3711_INTERRUPT_STATUS_2: case AS3711_INTERRUPT_STATUS_3: case AS3711_CHARGER_STATUS_1: case AS3711_CHARGER_STATUS_2: case AS3711_REG_STATUS: return true; } return false; } static bool as3711_precious_reg(struct device *dev, unsigned int reg) { switch (reg) { case AS3711_INTERRUPT_STATUS_1: case AS3711_INTERRUPT_STATUS_2: case AS3711_INTERRUPT_STATUS_3: return true; } return false; } static bool as3711_readable_reg(struct device *dev, unsigned int reg) { switch (reg) { case AS3711_SD_1_VOLTAGE: case AS3711_SD_2_VOLTAGE: case AS3711_SD_3_VOLTAGE: case AS3711_SD_4_VOLTAGE: case AS3711_LDO_1_VOLTAGE: case AS3711_LDO_2_VOLTAGE: case AS3711_LDO_3_VOLTAGE: case AS3711_LDO_4_VOLTAGE: case AS3711_LDO_5_VOLTAGE: case AS3711_LDO_6_VOLTAGE: case AS3711_LDO_7_VOLTAGE: case AS3711_LDO_8_VOLTAGE: case AS3711_SD_CONTROL: case AS3711_GPIO_SIGNAL_OUT: case AS3711_GPIO_SIGNAL_IN: case AS3711_SD_CONTROL_1: case AS3711_SD_CONTROL_2: case AS3711_CURR_CONTROL: case AS3711_CURR1_VALUE: case AS3711_CURR2_VALUE: case AS3711_CURR3_VALUE: case AS3711_STEPUP_CONTROL_1: case AS3711_STEPUP_CONTROL_2: case AS3711_STEPUP_CONTROL_4: case AS3711_STEPUP_CONTROL_5: case AS3711_REG_STATUS: case AS3711_INTERRUPT_STATUS_1: case AS3711_INTERRUPT_STATUS_2: case AS3711_INTERRUPT_STATUS_3: case AS3711_CHARGER_STATUS_1: case AS3711_CHARGER_STATUS_2: case AS3711_ASIC_ID_1: case AS3711_ASIC_ID_2: return true; } return false; } static const struct regmap_config as3711_regmap_config = { .reg_bits = 8, .val_bits = 8, .volatile_reg = as3711_volatile_reg, .readable_reg = as3711_readable_reg, .precious_reg = as3711_precious_reg, .max_register = AS3711_MAX_REGS, .num_reg_defaults_raw = AS3711_MAX_REGS, .cache_type = REGCACHE_RBTREE, }; |
64710af3e
|
115 |
#ifdef CONFIG_OF |
445603030
|
116 |
static const struct of_device_id as3711_of_match[] = { |
64710af3e
|
117 118 119 120 121 |
{.compatible = "ams,as3711",}, {} }; MODULE_DEVICE_TABLE(of, as3711_of_match); #endif |
acad189b0
|
122 123 124 125 |
static int as3711_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct as3711 *as3711; |
64710af3e
|
126 |
struct as3711_platform_data *pdata; |
acad189b0
|
127 128 |
unsigned int id1, id2; int ret; |
64710af3e
|
129 |
if (!client->dev.of_node) { |
334a41ce9
|
130 |
pdata = dev_get_platdata(&client->dev); |
64710af3e
|
131 132 133 134 135 136 137 138 139 140 141 142 |
if (!pdata) dev_dbg(&client->dev, "Platform data not found "); } else { pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { dev_err(&client->dev, "Failed to allocate pdata "); return -ENOMEM; } } |
acad189b0
|
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
as3711 = devm_kzalloc(&client->dev, sizeof(struct as3711), GFP_KERNEL); if (!as3711) { dev_err(&client->dev, "Memory allocation failed "); return -ENOMEM; } as3711->dev = &client->dev; i2c_set_clientdata(client, as3711); if (client->irq) dev_notice(&client->dev, "IRQ not supported yet "); as3711->regmap = devm_regmap_init_i2c(client, &as3711_regmap_config); if (IS_ERR(as3711->regmap)) { ret = PTR_ERR(as3711->regmap); dev_err(&client->dev, "regmap initialization failed: %d ", ret); return ret; } ret = regmap_read(as3711->regmap, AS3711_ASIC_ID_1, &id1); if (!ret) ret = regmap_read(as3711->regmap, AS3711_ASIC_ID_2, &id2); if (ret < 0) { dev_err(&client->dev, "regmap_read() failed: %d ", ret); return ret; } if (id1 != 0x8b) return -ENODEV; dev_info(as3711->dev, "AS3711 detected: %x:%x ", id1, id2); /* We can reuse as3711_subdevs[], it will be copied in mfd_add_devices() */ if (pdata) { as3711_subdevs[AS3711_REGULATOR].platform_data = &pdata->regulator; as3711_subdevs[AS3711_REGULATOR].pdata_size = sizeof(pdata->regulator); as3711_subdevs[AS3711_BACKLIGHT].platform_data = &pdata->backlight; as3711_subdevs[AS3711_BACKLIGHT].pdata_size = sizeof(pdata->backlight); } else { as3711_subdevs[AS3711_REGULATOR].platform_data = NULL; as3711_subdevs[AS3711_REGULATOR].pdata_size = 0; as3711_subdevs[AS3711_BACKLIGHT].platform_data = NULL; as3711_subdevs[AS3711_BACKLIGHT].pdata_size = 0; } ret = mfd_add_devices(as3711->dev, -1, as3711_subdevs, ARRAY_SIZE(as3711_subdevs), NULL, 0, NULL); if (ret < 0) dev_err(&client->dev, "add mfd devices failed: %d ", ret); return ret; } static int as3711_i2c_remove(struct i2c_client *client) { struct as3711 *as3711 = i2c_get_clientdata(client); mfd_remove_devices(as3711->dev); return 0; } static const struct i2c_device_id as3711_i2c_id[] = { {.name = "as3711", .driver_data = 0}, {} }; MODULE_DEVICE_TABLE(i2c, as3711_i2c_id); static struct i2c_driver as3711_i2c_driver = { .driver = { .name = "as3711", .owner = THIS_MODULE, |
64710af3e
|
220 221 |
.of_match_table = of_match_ptr(as3711_of_match), }, |
acad189b0
|
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
.probe = as3711_i2c_probe, .remove = as3711_i2c_remove, .id_table = as3711_i2c_id, }; static int __init as3711_i2c_init(void) { return i2c_add_driver(&as3711_i2c_driver); } /* Initialise early */ subsys_initcall(as3711_i2c_init); static void __exit as3711_i2c_exit(void) { i2c_del_driver(&as3711_i2c_driver); } module_exit(as3711_i2c_exit); MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>"); MODULE_DESCRIPTION("AS3711 PMIC driver"); MODULE_LICENSE("GPL v2"); |