diff options
-rw-r--r-- | drivers/mfd/wm831x-core.c | 4 | ||||
-rw-r--r-- | drivers/mfd/wm831x-otp.c | 83 | ||||
-rw-r--r-- | include/linux/mfd/wm831x/otp.h | 162 |
3 files changed, 249 insertions, 0 deletions
diff --git a/drivers/mfd/wm831x-core.c b/drivers/mfd/wm831x-core.c index bc40ea315cc0..33eaea2f988e 100644 --- a/drivers/mfd/wm831x-core.c +++ b/drivers/mfd/wm831x-core.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/mfd/wm831x/pdata.h> | 23 | #include <linux/mfd/wm831x/pdata.h> |
24 | #include <linux/mfd/wm831x/irq.h> | 24 | #include <linux/mfd/wm831x/irq.h> |
25 | #include <linux/mfd/wm831x/auxadc.h> | 25 | #include <linux/mfd/wm831x/auxadc.h> |
26 | #include <linux/mfd/wm831x/otp.h> | ||
26 | 27 | ||
27 | enum wm831x_parent { | 28 | enum wm831x_parent { |
28 | WM8310 = 0, | 29 | WM8310 = 0, |
@@ -1340,6 +1341,8 @@ static int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq) | |||
1340 | ret); | 1341 | ret); |
1341 | } | 1342 | } |
1342 | 1343 | ||
1344 | wm831x_otp_init(wm831x); | ||
1345 | |||
1343 | if (pdata && pdata->post_init) { | 1346 | if (pdata && pdata->post_init) { |
1344 | ret = pdata->post_init(wm831x); | 1347 | ret = pdata->post_init(wm831x); |
1345 | if (ret != 0) { | 1348 | if (ret != 0) { |
@@ -1360,6 +1363,7 @@ err: | |||
1360 | 1363 | ||
1361 | static void wm831x_device_exit(struct wm831x *wm831x) | 1364 | static void wm831x_device_exit(struct wm831x *wm831x) |
1362 | { | 1365 | { |
1366 | wm831x_otp_exit(wm831x); | ||
1363 | mfd_remove_devices(wm831x->dev); | 1367 | mfd_remove_devices(wm831x->dev); |
1364 | wm831x_irq_exit(wm831x); | 1368 | wm831x_irq_exit(wm831x); |
1365 | kfree(wm831x); | 1369 | kfree(wm831x); |
diff --git a/drivers/mfd/wm831x-otp.c b/drivers/mfd/wm831x-otp.c new file mode 100644 index 000000000000..f742745ff354 --- /dev/null +++ b/drivers/mfd/wm831x-otp.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * wm831x-otp.c -- OTP for Wolfson WM831x PMICs | ||
3 | * | ||
4 | * Copyright 2009 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.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; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/i2c.h> | ||
18 | #include <linux/bcd.h> | ||
19 | #include <linux/delay.h> | ||
20 | #include <linux/mfd/core.h> | ||
21 | |||
22 | #include <linux/mfd/wm831x/core.h> | ||
23 | #include <linux/mfd/wm831x/otp.h> | ||
24 | |||
25 | /* In bytes */ | ||
26 | #define WM831X_UNIQUE_ID_LEN 16 | ||
27 | |||
28 | /* Read the unique ID from the chip into id */ | ||
29 | static int wm831x_unique_id_read(struct wm831x *wm831x, char *id) | ||
30 | { | ||
31 | int i, val; | ||
32 | |||
33 | for (i = 0; i < WM831X_UNIQUE_ID_LEN / 2; i++) { | ||
34 | val = wm831x_reg_read(wm831x, WM831X_UNIQUE_ID_1 + i); | ||
35 | if (val < 0) | ||
36 | return val; | ||
37 | |||
38 | id[i * 2] = (val >> 8) & 0xff; | ||
39 | id[(i * 2) + 1] = val & 0xff; | ||
40 | } | ||
41 | |||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static ssize_t wm831x_unique_id_show(struct device *dev, | ||
46 | struct device_attribute *attr, char *buf) | ||
47 | { | ||
48 | struct wm831x *wm831x = dev_get_drvdata(dev); | ||
49 | int i, rval; | ||
50 | char id[WM831X_UNIQUE_ID_LEN]; | ||
51 | ssize_t ret = 0; | ||
52 | |||
53 | rval = wm831x_unique_id_read(wm831x, id); | ||
54 | if (rval < 0) | ||
55 | return 0; | ||
56 | |||
57 | for (i = 0; i < WM831X_UNIQUE_ID_LEN; i++) | ||
58 | ret += sprintf(&buf[ret], "%02x", buf[i]); | ||
59 | |||
60 | ret += sprintf(&buf[ret], "\n"); | ||
61 | |||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | static DEVICE_ATTR(unique_id, 0444, wm831x_unique_id_show, NULL); | ||
66 | |||
67 | int wm831x_otp_init(struct wm831x *wm831x) | ||
68 | { | ||
69 | int ret; | ||
70 | |||
71 | ret = device_create_file(wm831x->dev, &dev_attr_unique_id); | ||
72 | if (ret != 0) | ||
73 | dev_err(wm831x->dev, "Unique ID attribute not created: %d\n", | ||
74 | ret); | ||
75 | |||
76 | return ret; | ||
77 | } | ||
78 | |||
79 | void wm831x_otp_exit(struct wm831x *wm831x) | ||
80 | { | ||
81 | device_remove_file(wm831x->dev, &dev_attr_unique_id); | ||
82 | } | ||
83 | |||
diff --git a/include/linux/mfd/wm831x/otp.h b/include/linux/mfd/wm831x/otp.h new file mode 100644 index 000000000000..ce1f81a39bfc --- /dev/null +++ b/include/linux/mfd/wm831x/otp.h | |||
@@ -0,0 +1,162 @@ | |||
1 | /* | ||
2 | * include/linux/mfd/wm831x/otp.h -- OTP interface for WM831x | ||
3 | * | ||
4 | * Copyright 2009 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.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; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #ifndef __MFD_WM831X_OTP_H__ | ||
16 | #define __MFD_WM831X_OTP_H__ | ||
17 | |||
18 | int wm831x_otp_init(struct wm831x *wm831x); | ||
19 | void wm831x_otp_exit(struct wm831x *wm831x); | ||
20 | |||
21 | /* | ||
22 | * R30720 (0x7800) - Unique ID 1 | ||
23 | */ | ||
24 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
25 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
26 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
27 | |||
28 | /* | ||
29 | * R30721 (0x7801) - Unique ID 2 | ||
30 | */ | ||
31 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
32 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
33 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
34 | |||
35 | /* | ||
36 | * R30722 (0x7802) - Unique ID 3 | ||
37 | */ | ||
38 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
39 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
40 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
41 | |||
42 | /* | ||
43 | * R30723 (0x7803) - Unique ID 4 | ||
44 | */ | ||
45 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
46 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
47 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
48 | |||
49 | /* | ||
50 | * R30724 (0x7804) - Unique ID 5 | ||
51 | */ | ||
52 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
53 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
54 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
55 | |||
56 | /* | ||
57 | * R30725 (0x7805) - Unique ID 6 | ||
58 | */ | ||
59 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
60 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
61 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
62 | |||
63 | /* | ||
64 | * R30726 (0x7806) - Unique ID 7 | ||
65 | */ | ||
66 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
67 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
68 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
69 | |||
70 | /* | ||
71 | * R30727 (0x7807) - Unique ID 8 | ||
72 | */ | ||
73 | #define WM831X_UNIQUE_ID_MASK 0xFFFF /* UNIQUE_ID - [15:0] */ | ||
74 | #define WM831X_UNIQUE_ID_SHIFT 0 /* UNIQUE_ID - [15:0] */ | ||
75 | #define WM831X_UNIQUE_ID_WIDTH 16 /* UNIQUE_ID - [15:0] */ | ||
76 | |||
77 | /* | ||
78 | * R30728 (0x7808) - Factory OTP ID | ||
79 | */ | ||
80 | #define WM831X_OTP_FACT_ID_MASK 0xFFFE /* OTP_FACT_ID - [15:1] */ | ||
81 | #define WM831X_OTP_FACT_ID_SHIFT 1 /* OTP_FACT_ID - [15:1] */ | ||
82 | #define WM831X_OTP_FACT_ID_WIDTH 15 /* OTP_FACT_ID - [15:1] */ | ||
83 | #define WM831X_OTP_FACT_FINAL 0x0001 /* OTP_FACT_FINAL */ | ||
84 | #define WM831X_OTP_FACT_FINAL_MASK 0x0001 /* OTP_FACT_FINAL */ | ||
85 | #define WM831X_OTP_FACT_FINAL_SHIFT 0 /* OTP_FACT_FINAL */ | ||
86 | #define WM831X_OTP_FACT_FINAL_WIDTH 1 /* OTP_FACT_FINAL */ | ||
87 | |||
88 | /* | ||
89 | * R30729 (0x7809) - Factory OTP 1 | ||
90 | */ | ||
91 | #define WM831X_DC3_TRIM_MASK 0xF000 /* DC3_TRIM - [15:12] */ | ||
92 | #define WM831X_DC3_TRIM_SHIFT 12 /* DC3_TRIM - [15:12] */ | ||
93 | #define WM831X_DC3_TRIM_WIDTH 4 /* DC3_TRIM - [15:12] */ | ||
94 | #define WM831X_DC2_TRIM_MASK 0x0FC0 /* DC2_TRIM - [11:6] */ | ||
95 | #define WM831X_DC2_TRIM_SHIFT 6 /* DC2_TRIM - [11:6] */ | ||
96 | #define WM831X_DC2_TRIM_WIDTH 6 /* DC2_TRIM - [11:6] */ | ||
97 | #define WM831X_DC1_TRIM_MASK 0x003F /* DC1_TRIM - [5:0] */ | ||
98 | #define WM831X_DC1_TRIM_SHIFT 0 /* DC1_TRIM - [5:0] */ | ||
99 | #define WM831X_DC1_TRIM_WIDTH 6 /* DC1_TRIM - [5:0] */ | ||
100 | |||
101 | /* | ||
102 | * R30730 (0x780A) - Factory OTP 2 | ||
103 | */ | ||
104 | #define WM831X_CHIP_ID_MASK 0xFFFF /* CHIP_ID - [15:0] */ | ||
105 | #define WM831X_CHIP_ID_SHIFT 0 /* CHIP_ID - [15:0] */ | ||
106 | #define WM831X_CHIP_ID_WIDTH 16 /* CHIP_ID - [15:0] */ | ||
107 | |||
108 | /* | ||
109 | * R30731 (0x780B) - Factory OTP 3 | ||
110 | */ | ||
111 | #define WM831X_OSC_TRIM_MASK 0x0780 /* OSC_TRIM - [10:7] */ | ||
112 | #define WM831X_OSC_TRIM_SHIFT 7 /* OSC_TRIM - [10:7] */ | ||
113 | #define WM831X_OSC_TRIM_WIDTH 4 /* OSC_TRIM - [10:7] */ | ||
114 | #define WM831X_BG_TRIM_MASK 0x0078 /* BG_TRIM - [6:3] */ | ||
115 | #define WM831X_BG_TRIM_SHIFT 3 /* BG_TRIM - [6:3] */ | ||
116 | #define WM831X_BG_TRIM_WIDTH 4 /* BG_TRIM - [6:3] */ | ||
117 | #define WM831X_LPBG_TRIM_MASK 0x0007 /* LPBG_TRIM - [2:0] */ | ||
118 | #define WM831X_LPBG_TRIM_SHIFT 0 /* LPBG_TRIM - [2:0] */ | ||
119 | #define WM831X_LPBG_TRIM_WIDTH 3 /* LPBG_TRIM - [2:0] */ | ||
120 | |||
121 | /* | ||
122 | * R30732 (0x780C) - Factory OTP 4 | ||
123 | */ | ||
124 | #define WM831X_CHILD_I2C_ADDR_MASK 0x00FE /* CHILD_I2C_ADDR - [7:1] */ | ||
125 | #define WM831X_CHILD_I2C_ADDR_SHIFT 1 /* CHILD_I2C_ADDR - [7:1] */ | ||
126 | #define WM831X_CHILD_I2C_ADDR_WIDTH 7 /* CHILD_I2C_ADDR - [7:1] */ | ||
127 | #define WM831X_CH_AW 0x0001 /* CH_AW */ | ||
128 | #define WM831X_CH_AW_MASK 0x0001 /* CH_AW */ | ||
129 | #define WM831X_CH_AW_SHIFT 0 /* CH_AW */ | ||
130 | #define WM831X_CH_AW_WIDTH 1 /* CH_AW */ | ||
131 | |||
132 | /* | ||
133 | * R30733 (0x780D) - Factory OTP 5 | ||
134 | */ | ||
135 | #define WM831X_CHARGE_TRIM_MASK 0x003F /* CHARGE_TRIM - [5:0] */ | ||
136 | #define WM831X_CHARGE_TRIM_SHIFT 0 /* CHARGE_TRIM - [5:0] */ | ||
137 | #define WM831X_CHARGE_TRIM_WIDTH 6 /* CHARGE_TRIM - [5:0] */ | ||
138 | |||
139 | /* | ||
140 | * R30736 (0x7810) - Customer OTP ID | ||
141 | */ | ||
142 | #define WM831X_OTP_AUTO_PROG 0x8000 /* OTP_AUTO_PROG */ | ||
143 | #define WM831X_OTP_AUTO_PROG_MASK 0x8000 /* OTP_AUTO_PROG */ | ||
144 | #define WM831X_OTP_AUTO_PROG_SHIFT 15 /* OTP_AUTO_PROG */ | ||
145 | #define WM831X_OTP_AUTO_PROG_WIDTH 1 /* OTP_AUTO_PROG */ | ||
146 | #define WM831X_OTP_CUST_ID_MASK 0x7FFE /* OTP_CUST_ID - [14:1] */ | ||
147 | #define WM831X_OTP_CUST_ID_SHIFT 1 /* OTP_CUST_ID - [14:1] */ | ||
148 | #define WM831X_OTP_CUST_ID_WIDTH 14 /* OTP_CUST_ID - [14:1] */ | ||
149 | #define WM831X_OTP_CUST_FINAL 0x0001 /* OTP_CUST_FINAL */ | ||
150 | #define WM831X_OTP_CUST_FINAL_MASK 0x0001 /* OTP_CUST_FINAL */ | ||
151 | #define WM831X_OTP_CUST_FINAL_SHIFT 0 /* OTP_CUST_FINAL */ | ||
152 | #define WM831X_OTP_CUST_FINAL_WIDTH 1 /* OTP_CUST_FINAL */ | ||
153 | |||
154 | /* | ||
155 | * R30759 (0x7827) - DBE CHECK DATA | ||
156 | */ | ||
157 | #define WM831X_DBE_VALID_DATA_MASK 0xFFFF /* DBE_VALID_DATA - [15:0] */ | ||
158 | #define WM831X_DBE_VALID_DATA_SHIFT 0 /* DBE_VALID_DATA - [15:0] */ | ||
159 | #define WM831X_DBE_VALID_DATA_WIDTH 16 /* DBE_VALID_DATA - [15:0] */ | ||
160 | |||
161 | |||
162 | #endif | ||