33 #include <linux/module.h>
37 #include <linux/device.h>
46 #include <linux/i2c.h>
64 #define DRIVER_NAME "twl"
69 #define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
71 #define TWL_NUM_SLAVES 4
73 #define SUB_CHIP_ID0 0
74 #define SUB_CHIP_ID1 1
75 #define SUB_CHIP_ID2 2
76 #define SUB_CHIP_ID3 3
77 #define SUB_CHIP_ID_INVAL 0xff
79 #define TWL_MODULE_LAST TWL4030_MODULE_LAST
84 #define TWL4030_BASEADD_USB 0x0000
87 #define TWL4030_BASEADD_AUDIO_VOICE 0x0000
88 #define TWL4030_BASEADD_GPIO 0x0098
89 #define TWL4030_BASEADD_INTBR 0x0085
90 #define TWL4030_BASEADD_PIH 0x0080
91 #define TWL4030_BASEADD_TEST 0x004C
94 #define TWL4030_BASEADD_INTERRUPTS 0x00B9
95 #define TWL4030_BASEADD_LED 0x00EE
96 #define TWL4030_BASEADD_MADC 0x0000
97 #define TWL4030_BASEADD_MAIN_CHARGE 0x0074
98 #define TWL4030_BASEADD_PRECHARGE 0x00AA
99 #define TWL4030_BASEADD_PWM0 0x00F8
100 #define TWL4030_BASEADD_PWM1 0x00FB
101 #define TWL4030_BASEADD_PWMA 0x00EF
102 #define TWL4030_BASEADD_PWMB 0x00F1
103 #define TWL4030_BASEADD_KEYPAD 0x00D2
105 #define TWL5031_BASEADD_ACCESSORY 0x0074
106 #define TWL5031_BASEADD_INTERRUPTS 0x00B9
110 #define TWL4030_BASEADD_BACKUP 0x0014
111 #define TWL4030_BASEADD_INT 0x002E
112 #define TWL4030_BASEADD_PM_MASTER 0x0036
113 #define TWL4030_BASEADD_PM_RECEIVER 0x005B
114 #define TWL4030_BASEADD_RTC 0x001C
115 #define TWL4030_BASEADD_SECURED_REG 0x0000
121 #define TWL6030_BASEADD_RTC 0x0000
122 #define TWL6030_BASEADD_MEM 0x0017
123 #define TWL6030_BASEADD_PM_MASTER 0x001F
124 #define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030
125 #define TWL6030_BASEADD_PM_MISC 0x00E2
126 #define TWL6030_BASEADD_PM_PUPD 0x00F0
129 #define TWL6030_BASEADD_USB 0x0000
130 #define TWL6030_BASEADD_GPADC_CTRL 0x002E
131 #define TWL6030_BASEADD_AUX 0x0090
132 #define TWL6030_BASEADD_PWM 0x00BA
133 #define TWL6030_BASEADD_GASGAUGE 0x00C0
134 #define TWL6030_BASEADD_PIH 0x00D0
135 #define TWL6030_BASEADD_CHARGER 0x00E0
136 #define TWL6025_BASEADD_CHARGER 0x00DA
139 #define TWL6030_BASEADD_DIEID 0x00C0
142 #define TWL6030_BASEADD_AUDIO 0x0000
143 #define TWL6030_BASEADD_RSV 0x0000
144 #define TWL6030_BASEADD_ZERO 0x0000
147 #define R_CFG_BOOT 0x05
150 #define HFCLK_FREQ_19p2_MHZ (1 << 0)
151 #define HFCLK_FREQ_26_MHZ (2 << 0)
152 #define HFCLK_FREQ_38p4_MHZ (3 << 0)
153 #define HIGH_PERF_SQ (1 << 3)
154 #define CK32K_LOWPWR_EN (1 << 7)
162 static u32 twl_idcode;
164 static unsigned int twl_id;
296 sid = twl_map[mod_no].
sid;
298 pr_err(
"%s: module %d is not part of the pmic\n",
302 twl = &twl_modules[
sid];
311 msg->
len = num_bytes + 1;
315 *value = twl_map[mod_no].
base +
reg;
321 pr_err(
"%s: i2c_write failed to transfer all messages\n",
358 sid = twl_map[mod_no].
sid;
360 pr_err(
"%s: module %d is not part of the pmic\n",
364 twl = &twl_modules[
sid];
372 val = twl_map[mod_no].
base +
reg;
385 pr_err(
"%s: i2c_read failed to transfer all messages\n",
409 u8 temp_buffer[2] = { 0 };
411 temp_buffer[1] =
value;
437 static int twl_read_idcode_register(
void)
444 pr_err(
"TWL4030 Unable to unlock IDCODE registers -%d\n", err);
451 pr_err(
"TWL4030: unable to read IDCODE -%d\n", err);
457 pr_err(
"TWL4030 Unable to relock IDCODE registers -%d\n", err);
496 switch (ctrl & 0x3) {
507 pr_err(
"TWL4030: HFCLK is not configured\n");
517 add_numbered_child(
unsigned chip,
const char *
name,
int num,
518 void *
pdata,
unsigned pdata_len,
519 bool can_wakeup,
int irq0,
int irq1)
537 dev_dbg(&pdev->
dev,
"can't add platform_data\n");
563 return ERR_PTR(status);
568 static inline struct device *add_child(
unsigned chip,
const char *name,
569 void *pdata,
unsigned pdata_len,
570 bool can_wakeup,
int irq0,
int irq1)
572 return add_numbered_child(chip, name, -1, pdata, pdata_len,
573 can_wakeup, irq0, irq1);
579 unsigned num_consumers,
unsigned long features)
581 unsigned sub_chip_id;
609 return add_numbered_child(sub_chip_id,
"twl_reg", num,
610 pdata,
sizeof(*pdata),
false, 0, 0);
615 unsigned long features)
617 return add_regulator_linked(num, pdata,
NULL, 0, features);
628 unsigned long features)
631 unsigned sub_chip_id;
638 return PTR_ERR(child);
646 return PTR_ERR(child);
650 child = add_child(2,
"twl4030_madc",
654 return PTR_ERR(child);
666 child = add_child(sub_chip_id,
"twl_rtc",
670 return PTR_ERR(child);
673 if (
IS_ENABLED(CONFIG_PWM_TWL6030) && twl_class_is_6030()) {
677 return PTR_ERR(child);
681 twl_class_is_4030()) {
691 { .supply =
"bci3v1" },
701 .constraints.valid_ops_mask =
707 &usb_fixed, &usb1v5, 1,
710 return PTR_ERR(child);
713 &usb_fixed, &usb1v8, 1,
716 return PTR_ERR(child);
719 &usb_fixed, usb3v1, 2,
722 return PTR_ERR(child);
726 child = add_child(0,
"twl4030_usb",
727 pdata->
usb,
sizeof(*pdata->
usb),
734 return PTR_ERR(child);
737 if (
IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child) {
740 usb3v1[0].
dev_name = dev_name(child);
744 twl_class_is_6030()) {
755 .constraints.valid_ops_mask =
761 usb3v3.supply =
"ldousb";
764 usb3v3.supply =
"vusb";
767 child = add_regulator_linked(regulator, &usb_fixed,
771 return PTR_ERR(child);
776 child = add_child(0,
"twl6030_usb",
777 pdata->
usb,
sizeof(*pdata->
usb),
784 return PTR_ERR(child);
786 if (
IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child)
787 usb3v3.dev_name = dev_name(child);
788 }
else if (
IS_ENABLED(CONFIG_REGULATOR_TWL4030) &&
789 twl_class_is_6030()) {
790 if (features & TWL6025_SUBCLASS)
795 pdata->
vusb, features);
798 return PTR_ERR(child);
801 if (
IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) {
802 child = add_child(0,
"twl4030_wdt",
NULL, 0,
false, 0, 0);
804 return PTR_ERR(child);
807 if (
IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) {
808 child = add_child(1,
"twl4030_pwrbutton",
809 NULL, 0,
true, irq_base + 8 + 0, 0);
811 return PTR_ERR(child);
815 twl_class_is_4030()) {
817 child = add_child(sub_chip_id,
"twl4030-audio",
821 return PTR_ERR(child);
825 if (
IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_4030()) {
829 return PTR_ERR(child);
834 return PTR_ERR(child);
839 return PTR_ERR(child);
844 return PTR_ERR(child);
849 return PTR_ERR(child);
854 return PTR_ERR(child);
859 pdata->
vaux2, features);
861 return PTR_ERR(child);
866 return PTR_ERR(child);
871 return PTR_ERR(child);
876 return PTR_ERR(child);
881 && twl_class_is_4030()) {
885 return PTR_ERR(child);
890 return PTR_ERR(child);
895 return PTR_ERR(child);
900 return PTR_ERR(child);
905 return PTR_ERR(child);
910 return PTR_ERR(child);
914 if (
IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030() &&
915 !(features & TWL6025_SUBCLASS)) {
919 return PTR_ERR(child);
924 return PTR_ERR(child);
929 return PTR_ERR(child);
934 return PTR_ERR(child);
939 return PTR_ERR(child);
944 return PTR_ERR(child);
949 return PTR_ERR(child);
954 return PTR_ERR(child);
959 return PTR_ERR(child);
964 return PTR_ERR(child);
969 return PTR_ERR(child);
974 return PTR_ERR(child);
979 return PTR_ERR(child);
984 return PTR_ERR(child);
988 if (
IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030()) {
992 return PTR_ERR(child);
996 if (
IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030() &&
997 (features & TWL6025_SUBCLASS)) {
1001 return PTR_ERR(child);
1006 return PTR_ERR(child);
1011 return PTR_ERR(child);
1016 return PTR_ERR(child);
1021 return PTR_ERR(child);
1026 return PTR_ERR(child);
1031 return PTR_ERR(child);
1036 return PTR_ERR(child);
1041 return PTR_ERR(child);
1046 return PTR_ERR(child);
1051 return PTR_ERR(child);
1056 !(features & (TPS_SUBSET |
TWL5031))) {
1057 child = add_child(3,
"twl4030_bci",
1058 pdata->
bci,
sizeof(*pdata->
bci),
false,
1063 return PTR_ERR(child);
1076 static inline int __init protect_pm_master(
void)
1085 static inline int __init unprotect_pm_master(
void)
1099 static void clocks_init(
struct device *
dev,
1110 "using bootloader value (unknown osc rate)\n");
1133 e |= unprotect_pm_master();
1136 e |= protect_pm_master();
1147 unsigned i, num_slaves;
1150 if (twl_class_is_4030()) {
1161 for (i = 0; i < num_slaves; i++) {
1166 twl_modules[
i].client =
NULL;
1181 unsigned i, num_slaves;
1195 if (node && !pdata) {
1210 dev_dbg(&client->
dev,
"no platform data?\n");
1215 platform_set_drvdata(pdev, pdata);
1224 dev_dbg(&client->
dev,
"driver is already in use\n");
1231 twl_map = &twl6030_map[0];
1235 twl_map = &twl4030_map[0];
1239 for (i = 0; i < num_slaves; i++) {
1250 "can't attach client %d\n", i);
1261 clocks_init(&pdev->
dev, pdata->
clock);
1265 status = twl_read_idcode_register();
1266 WARN(status < 0,
"Error: reading twl_idcode register value\n");
1275 if (twl_class_is_4030()) {
1293 if (twl_class_is_4030()) {
1304 status = of_platform_populate(node,
NULL,
NULL, &client->
dev);
1306 status = add_children(pdata, irq_base, id->driver_data);
1323 {
"tps65930", TPS_SUBSET },
1324 {
"tps65920", TPS_SUBSET },
1325 {
"tps65921", TPS_SUBSET },
1336 .id_table = twl_ids,
1338 .remove = twl_remove,
1341 static int __init twl_init(
void)
1343 return i2c_add_driver(&twl_driver);
1347 static void __exit twl_exit(
void)