aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/twl-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mfd/twl-core.c')
-rw-r--r--drivers/mfd/twl-core.c153
1 files changed, 69 insertions, 84 deletions
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 806680d1bbb..7c2267e71f8 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -46,9 +46,7 @@
46#include <linux/i2c.h> 46#include <linux/i2c.h>
47#include <linux/i2c/twl.h> 47#include <linux/i2c/twl.h>
48 48
49#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) 49#include "twl-core.h"
50#include <plat/cpu.h>
51#endif
52 50
53/* 51/*
54 * The TWL4030 "Triton 2" is one of a family of a multi-function "Power 52 * The TWL4030 "Triton 2" is one of a family of a multi-function "Power
@@ -116,8 +114,8 @@
116#define twl_has_watchdog() false 114#define twl_has_watchdog() false
117#endif 115#endif
118 116
119#if defined(CONFIG_MFD_TWL4030_AUDIO) || defined(CONFIG_MFD_TWL4030_AUDIO_MODULE) ||\ 117#if defined(CONFIG_MFD_TWL4030_AUDIO) || \
120 defined(CONFIG_TWL6040_CORE) || defined(CONFIG_TWL6040_CORE_MODULE) 118 defined(CONFIG_MFD_TWL4030_AUDIO_MODULE)
121#define twl_has_codec() true 119#define twl_has_codec() true
122#else 120#else
123#define twl_has_codec() false 121#define twl_has_codec() false
@@ -147,12 +145,10 @@
147#define SUB_CHIP_ID1 1 145#define SUB_CHIP_ID1 1
148#define SUB_CHIP_ID2 2 146#define SUB_CHIP_ID2 2
149#define SUB_CHIP_ID3 3 147#define SUB_CHIP_ID3 3
148#define SUB_CHIP_ID_INVAL 0xff
150 149
151#define TWL_MODULE_LAST TWL4030_MODULE_LAST 150#define TWL_MODULE_LAST TWL4030_MODULE_LAST
152 151
153#define TWL4030_NR_IRQS 34 /* core:8, power:8, gpio: 18 */
154#define TWL6030_NR_IRQS 20
155
156/* Base Address defns for twl4030_map[] */ 152/* Base Address defns for twl4030_map[] */
157 153
158/* subchip/slave 0 - USB ID */ 154/* subchip/slave 0 - USB ID */
@@ -314,7 +310,7 @@ static struct twl_mapping twl6030_map[] = {
314 * so they continue to match the order in this table. 310 * so they continue to match the order in this table.
315 */ 311 */
316 { SUB_CHIP_ID1, TWL6030_BASEADD_USB }, 312 { SUB_CHIP_ID1, TWL6030_BASEADD_USB },
317 { SUB_CHIP_ID3, TWL6030_BASEADD_AUDIO }, 313 { SUB_CHIP_ID_INVAL, TWL6030_BASEADD_AUDIO },
318 { SUB_CHIP_ID2, TWL6030_BASEADD_DIEID }, 314 { SUB_CHIP_ID2, TWL6030_BASEADD_DIEID },
319 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 315 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
320 { SUB_CHIP_ID1, TWL6030_BASEADD_PIH }, 316 { SUB_CHIP_ID1, TWL6030_BASEADD_PIH },
@@ -376,6 +372,11 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
376 return -EPERM; 372 return -EPERM;
377 } 373 }
378 sid = twl_map[mod_no].sid; 374 sid = twl_map[mod_no].sid;
375 if (unlikely(sid == SUB_CHIP_ID_INVAL)) {
376 pr_err("%s: module %d is not part of the pmic\n",
377 DRIVER_NAME, mod_no);
378 return -EINVAL;
379 }
379 twl = &twl_modules[sid]; 380 twl = &twl_modules[sid];
380 381
381 mutex_lock(&twl->xfer_lock); 382 mutex_lock(&twl->xfer_lock);
@@ -433,6 +434,11 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
433 return -EPERM; 434 return -EPERM;
434 } 435 }
435 sid = twl_map[mod_no].sid; 436 sid = twl_map[mod_no].sid;
437 if (unlikely(sid == SUB_CHIP_ID_INVAL)) {
438 pr_err("%s: module %d is not part of the pmic\n",
439 DRIVER_NAME, mod_no);
440 return -EINVAL;
441 }
436 twl = &twl_modules[sid]; 442 twl = &twl_modules[sid];
437 443
438 mutex_lock(&twl->xfer_lock); 444 mutex_lock(&twl->xfer_lock);
@@ -663,7 +669,8 @@ add_regulator(int num, struct regulator_init_data *pdata,
663 */ 669 */
664 670
665static int 671static int
666add_children(struct twl4030_platform_data *pdata, unsigned long features) 672add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
673 unsigned long features)
667{ 674{
668 struct device *child; 675 struct device *child;
669 unsigned sub_chip_id; 676 unsigned sub_chip_id;
@@ -671,7 +678,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
671 if (twl_has_gpio() && pdata->gpio) { 678 if (twl_has_gpio() && pdata->gpio) {
672 child = add_child(SUB_CHIP_ID1, "twl4030_gpio", 679 child = add_child(SUB_CHIP_ID1, "twl4030_gpio",
673 pdata->gpio, sizeof(*pdata->gpio), 680 pdata->gpio, sizeof(*pdata->gpio),
674 false, pdata->irq_base + GPIO_INTR_OFFSET, 0); 681 false, irq_base + GPIO_INTR_OFFSET, 0);
675 if (IS_ERR(child)) 682 if (IS_ERR(child))
676 return PTR_ERR(child); 683 return PTR_ERR(child);
677 } 684 }
@@ -679,7 +686,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
679 if (twl_has_keypad() && pdata->keypad) { 686 if (twl_has_keypad() && pdata->keypad) {
680 child = add_child(SUB_CHIP_ID2, "twl4030_keypad", 687 child = add_child(SUB_CHIP_ID2, "twl4030_keypad",
681 pdata->keypad, sizeof(*pdata->keypad), 688 pdata->keypad, sizeof(*pdata->keypad),
682 true, pdata->irq_base + KEYPAD_INTR_OFFSET, 0); 689 true, irq_base + KEYPAD_INTR_OFFSET, 0);
683 if (IS_ERR(child)) 690 if (IS_ERR(child))
684 return PTR_ERR(child); 691 return PTR_ERR(child);
685 } 692 }
@@ -687,7 +694,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
687 if (twl_has_madc() && pdata->madc) { 694 if (twl_has_madc() && pdata->madc) {
688 child = add_child(2, "twl4030_madc", 695 child = add_child(2, "twl4030_madc",
689 pdata->madc, sizeof(*pdata->madc), 696 pdata->madc, sizeof(*pdata->madc),
690 true, pdata->irq_base + MADC_INTR_OFFSET, 0); 697 true, irq_base + MADC_INTR_OFFSET, 0);
691 if (IS_ERR(child)) 698 if (IS_ERR(child))
692 return PTR_ERR(child); 699 return PTR_ERR(child);
693 } 700 }
@@ -703,7 +710,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
703 sub_chip_id = twl_map[TWL_MODULE_RTC].sid; 710 sub_chip_id = twl_map[TWL_MODULE_RTC].sid;
704 child = add_child(sub_chip_id, "twl_rtc", 711 child = add_child(sub_chip_id, "twl_rtc",
705 NULL, 0, 712 NULL, 0,
706 true, pdata->irq_base + RTC_INTR_OFFSET, 0); 713 true, irq_base + RTC_INTR_OFFSET, 0);
707 if (IS_ERR(child)) 714 if (IS_ERR(child))
708 return PTR_ERR(child); 715 return PTR_ERR(child);
709 } 716 }
@@ -756,8 +763,8 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
756 pdata->usb, sizeof(*pdata->usb), 763 pdata->usb, sizeof(*pdata->usb),
757 true, 764 true,
758 /* irq0 = USB_PRES, irq1 = USB */ 765 /* irq0 = USB_PRES, irq1 = USB */
759 pdata->irq_base + USB_PRES_INTR_OFFSET, 766 irq_base + USB_PRES_INTR_OFFSET,
760 pdata->irq_base + USB_INTR_OFFSET); 767 irq_base + USB_INTR_OFFSET);
761 768
762 if (IS_ERR(child)) 769 if (IS_ERR(child))
763 return PTR_ERR(child); 770 return PTR_ERR(child);
@@ -805,8 +812,8 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
805 pdata->usb, sizeof(*pdata->usb), 812 pdata->usb, sizeof(*pdata->usb),
806 true, 813 true,
807 /* irq1 = VBUS_PRES, irq0 = USB ID */ 814 /* irq1 = VBUS_PRES, irq0 = USB ID */
808 pdata->irq_base + USBOTG_INTR_OFFSET, 815 irq_base + USBOTG_INTR_OFFSET,
809 pdata->irq_base + USB_PRES_INTR_OFFSET); 816 irq_base + USB_PRES_INTR_OFFSET);
810 817
811 if (IS_ERR(child)) 818 if (IS_ERR(child))
812 return PTR_ERR(child); 819 return PTR_ERR(child);
@@ -833,7 +840,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
833 840
834 if (twl_has_pwrbutton() && twl_class_is_4030()) { 841 if (twl_has_pwrbutton() && twl_class_is_4030()) {
835 child = add_child(1, "twl4030_pwrbutton", 842 child = add_child(1, "twl4030_pwrbutton",
836 NULL, 0, true, pdata->irq_base + 8 + 0, 0); 843 NULL, 0, true, irq_base + 8 + 0, 0);
837 if (IS_ERR(child)) 844 if (IS_ERR(child))
838 return PTR_ERR(child); 845 return PTR_ERR(child);
839 } 846 }
@@ -847,15 +854,6 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
847 return PTR_ERR(child); 854 return PTR_ERR(child);
848 } 855 }
849 856
850 if (twl_has_codec() && pdata->audio && twl_class_is_6030()) {
851 sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid;
852 child = add_child(sub_chip_id, "twl6040",
853 pdata->audio, sizeof(*pdata->audio),
854 false, 0, 0);
855 if (IS_ERR(child))
856 return PTR_ERR(child);
857 }
858
859 /* twl4030 regulators */ 857 /* twl4030 regulators */
860 if (twl_has_regulator() && twl_class_is_4030()) { 858 if (twl_has_regulator() && twl_class_is_4030()) {
861 child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1, 859 child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1,
@@ -1092,8 +1090,8 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
1092 child = add_child(3, "twl4030_bci", 1090 child = add_child(3, "twl4030_bci",
1093 pdata->bci, sizeof(*pdata->bci), false, 1091 pdata->bci, sizeof(*pdata->bci), false,
1094 /* irq0 = CHG_PRES, irq1 = BCI */ 1092 /* irq0 = CHG_PRES, irq1 = BCI */
1095 pdata->irq_base + BCI_PRES_INTR_OFFSET, 1093 irq_base + BCI_PRES_INTR_OFFSET,
1096 pdata->irq_base + BCI_INTR_OFFSET); 1094 irq_base + BCI_INTR_OFFSET);
1097 if (IS_ERR(child)) 1095 if (IS_ERR(child))
1098 return PTR_ERR(child); 1096 return PTR_ERR(child);
1099 } 1097 }
@@ -1193,26 +1191,24 @@ static void clocks_init(struct device *dev,
1193 1191
1194/*----------------------------------------------------------------------*/ 1192/*----------------------------------------------------------------------*/
1195 1193
1196int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end);
1197int twl4030_exit_irq(void);
1198int twl4030_init_chip_irq(const char *chip);
1199int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end);
1200int twl6030_exit_irq(void);
1201 1194
1202static int twl_remove(struct i2c_client *client) 1195static int twl_remove(struct i2c_client *client)
1203{ 1196{
1204 unsigned i; 1197 unsigned i, num_slaves;
1205 int status; 1198 int status;
1206 1199
1207 if (twl_class_is_4030()) 1200 if (twl_class_is_4030()) {
1208 status = twl4030_exit_irq(); 1201 status = twl4030_exit_irq();
1209 else 1202 num_slaves = TWL_NUM_SLAVES;
1203 } else {
1210 status = twl6030_exit_irq(); 1204 status = twl6030_exit_irq();
1205 num_slaves = TWL_NUM_SLAVES - 1;
1206 }
1211 1207
1212 if (status < 0) 1208 if (status < 0)
1213 return status; 1209 return status;
1214 1210
1215 for (i = 0; i < TWL_NUM_SLAVES; i++) { 1211 for (i = 0; i < num_slaves; i++) {
1216 struct twl_client *twl = &twl_modules[i]; 1212 struct twl_client *twl = &twl_modules[i];
1217 1213
1218 if (twl->client && twl->client != client) 1214 if (twl->client && twl->client != client)
@@ -1223,20 +1219,15 @@ static int twl_remove(struct i2c_client *client)
1223 return 0; 1219 return 0;
1224} 1220}
1225 1221
1226/* NOTE: this driver only handles a single twl4030/tps659x0 chip */ 1222/* NOTE: This driver only handles a single twl4030/tps659x0 chip */
1227static int __devinit 1223static int __devinit
1228twl_probe(struct i2c_client *client, const struct i2c_device_id *id) 1224twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1229{ 1225{
1230 int status;
1231 unsigned i;
1232 struct twl4030_platform_data *pdata = client->dev.platform_data; 1226 struct twl4030_platform_data *pdata = client->dev.platform_data;
1233 struct device_node *node = client->dev.of_node; 1227 struct device_node *node = client->dev.of_node;
1234 u8 temp; 1228 int irq_base = 0;
1235 int ret = 0; 1229 int status;
1236 int nr_irqs = TWL4030_NR_IRQS; 1230 unsigned i, num_slaves;
1237
1238 if ((id->driver_data) & TWL6030_CLASS)
1239 nr_irqs = TWL6030_NR_IRQS;
1240 1231
1241 if (node && !pdata) { 1232 if (node && !pdata) {
1242 /* 1233 /*
@@ -1255,17 +1246,6 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1255 return -EINVAL; 1246 return -EINVAL;
1256 } 1247 }
1257 1248
1258 status = irq_alloc_descs(-1, pdata->irq_base, nr_irqs, 0);
1259 if (IS_ERR_VALUE(status)) {
1260 dev_err(&client->dev, "Fail to allocate IRQ descs\n");
1261 return status;
1262 }
1263
1264 pdata->irq_base = status;
1265 pdata->irq_end = pdata->irq_base + nr_irqs;
1266 irq_domain_add_legacy(node, nr_irqs, pdata->irq_base, 0,
1267 &irq_domain_simple_ops, NULL);
1268
1269 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) { 1249 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
1270 dev_dbg(&client->dev, "can't talk I2C?\n"); 1250 dev_dbg(&client->dev, "can't talk I2C?\n");
1271 return -EIO; 1251 return -EIO;
@@ -1276,13 +1256,23 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1276 return -EBUSY; 1256 return -EBUSY;
1277 } 1257 }
1278 1258
1279 for (i = 0; i < TWL_NUM_SLAVES; i++) { 1259 if ((id->driver_data) & TWL6030_CLASS) {
1280 struct twl_client *twl = &twl_modules[i]; 1260 twl_id = TWL6030_CLASS_ID;
1261 twl_map = &twl6030_map[0];
1262 num_slaves = TWL_NUM_SLAVES - 1;
1263 } else {
1264 twl_id = TWL4030_CLASS_ID;
1265 twl_map = &twl4030_map[0];
1266 num_slaves = TWL_NUM_SLAVES;
1267 }
1268
1269 for (i = 0; i < num_slaves; i++) {
1270 struct twl_client *twl = &twl_modules[i];
1281 1271
1282 twl->address = client->addr + i; 1272 twl->address = client->addr + i;
1283 if (i == 0) 1273 if (i == 0) {
1284 twl->client = client; 1274 twl->client = client;
1285 else { 1275 } else {
1286 twl->client = i2c_new_dummy(client->adapter, 1276 twl->client = i2c_new_dummy(client->adapter,
1287 twl->address); 1277 twl->address);
1288 if (!twl->client) { 1278 if (!twl->client) {
@@ -1294,22 +1284,16 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1294 } 1284 }
1295 mutex_init(&twl->xfer_lock); 1285 mutex_init(&twl->xfer_lock);
1296 } 1286 }
1287
1297 inuse = true; 1288 inuse = true;
1298 if ((id->driver_data) & TWL6030_CLASS) {
1299 twl_id = TWL6030_CLASS_ID;
1300 twl_map = &twl6030_map[0];
1301 } else {
1302 twl_id = TWL4030_CLASS_ID;
1303 twl_map = &twl4030_map[0];
1304 }
1305 1289
1306 /* setup clock framework */ 1290 /* setup clock framework */
1307 clocks_init(&client->dev, pdata->clock); 1291 clocks_init(&client->dev, pdata->clock);
1308 1292
1309 /* read TWL IDCODE Register */ 1293 /* read TWL IDCODE Register */
1310 if (twl_id == TWL4030_CLASS_ID) { 1294 if (twl_id == TWL4030_CLASS_ID) {
1311 ret = twl_read_idcode_register(); 1295 status = twl_read_idcode_register();
1312 WARN(ret < 0, "Error: reading twl_idcode register value\n"); 1296 WARN(status < 0, "Error: reading twl_idcode register value\n");
1313 } 1297 }
1314 1298
1315 /* load power event scripts */ 1299 /* load power event scripts */
@@ -1317,31 +1301,31 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1317 twl4030_power_init(pdata->power); 1301 twl4030_power_init(pdata->power);
1318 1302
1319 /* Maybe init the T2 Interrupt subsystem */ 1303 /* Maybe init the T2 Interrupt subsystem */
1320 if (client->irq 1304 if (client->irq) {
1321 && pdata->irq_base
1322 && pdata->irq_end > pdata->irq_base) {
1323 if (twl_class_is_4030()) { 1305 if (twl_class_is_4030()) {
1324 twl4030_init_chip_irq(id->name); 1306 twl4030_init_chip_irq(id->name);
1325 status = twl4030_init_irq(client->irq, pdata->irq_base, 1307 irq_base = twl4030_init_irq(&client->dev, client->irq);
1326 pdata->irq_end);
1327 } else { 1308 } else {
1328 status = twl6030_init_irq(client->irq, pdata->irq_base, 1309 irq_base = twl6030_init_irq(&client->dev, client->irq);
1329 pdata->irq_end);
1330 } 1310 }
1331 1311
1332 if (status < 0) 1312 if (irq_base < 0) {
1313 status = irq_base;
1333 goto fail; 1314 goto fail;
1315 }
1334 } 1316 }
1335 1317
1336 /* Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface. 1318 /*
1319 * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface.
1337 * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0, 1320 * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0,
1338 * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0. 1321 * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0.
1339 */ 1322 */
1340
1341 if (twl_class_is_4030()) { 1323 if (twl_class_is_4030()) {
1324 u8 temp;
1325
1342 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1); 1326 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1);
1343 temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \ 1327 temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \
1344 I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU); 1328 I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU);
1345 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1); 1329 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
1346 } 1330 }
1347 1331
@@ -1349,11 +1333,12 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1349 if (node) 1333 if (node)
1350 status = of_platform_populate(node, NULL, NULL, &client->dev); 1334 status = of_platform_populate(node, NULL, NULL, &client->dev);
1351 if (status) 1335 if (status)
1352 status = add_children(pdata, id->driver_data); 1336 status = add_children(pdata, irq_base, id->driver_data);
1353 1337
1354fail: 1338fail:
1355 if (status < 0) 1339 if (status < 0)
1356 twl_remove(client); 1340 twl_remove(client);
1341
1357 return status; 1342 return status;
1358} 1343}
1359 1344