11 #include <linux/list.h>
13 #include <linux/slab.h>
15 #include <linux/module.h>
17 #include <linux/device.h>
19 #include <linux/random.h>
30 #define AB3100_EVENTA1 0x21
31 #define AB3100_EVENTA2 0x22
32 #define AB3100_EVENTA3 0x23
35 #define AB3100_DIS 0x00
36 #define AB3100_D0C 0x01
37 #define AB3100_D1C 0x02
38 #define AB3100_D2C 0x03
39 #define AB3100_D3C 0x04
42 #define AB3100_CID 0x20
45 #define AB3100_IMRA1 0x24
46 #define AB3100_IMRA2 0x25
47 #define AB3100_IMRA3 0x26
48 #define AB3100_IMRB1 0x2B
49 #define AB3100_IMRB2 0x2C
50 #define AB3100_IMRB3 0x2D
53 #define AB3100_MCA 0x2E
54 #define AB3100_MCB 0x2F
57 #define AB3100_SUP 0x50
65 static int ab3100_get_chip_id(
struct device *
dev)
72 static int ab3100_set_register_interruptible(
struct ab3100 *
ab3100,
75 u8 regandval[2] = {
reg, regval};
90 "write error (write register): %d\n",
92 }
else if (err != 2) {
94 "write error (write register) "
95 "%d bytes transferred (expected 2)\n",
106 static int set_register_interruptible(
struct device *
dev,
111 return ab3100_set_register_interruptible(ab3100, reg, value);
121 static int ab3100_set_test_register_interruptible(
struct ab3100 *ab3100,
124 u8 regandval[2] = {
reg, regval};
134 "write error (write test register): %d\n",
136 }
else if (err != 2) {
138 "write error (write test register) "
139 "%d bytes transferred (expected 2)\n",
151 static int ab3100_get_register_interruptible(
struct ab3100 *ab3100,
169 "write error (send register address): %d\n",
171 goto get_reg_out_unlock;
172 }
else if (err != 1) {
174 "write error (send register address) "
175 "%d bytes transferred (expected 1)\n",
178 goto get_reg_out_unlock;
187 "write error (read register): %d\n",
189 goto get_reg_out_unlock;
190 }
else if (err != 1) {
192 "write error (read register) "
193 "%d bytes transferred (expected 1)\n",
196 goto get_reg_out_unlock;
207 static int get_register_interruptible(
struct device *
dev,
u8 bank,
u8 reg,
212 return ab3100_get_register_interruptible(ab3100, reg, value);
215 static int ab3100_get_register_page_interruptible(
struct ab3100 *ab3100,
216 u8 first_reg,
u8 *regvals,
u8 numregs)
235 "write error (send first register address): %d\n",
237 goto get_reg_page_out_unlock;
238 }
else if (err != 1) {
240 "write error (send first register address) "
241 "%d bytes transferred (expected 1)\n",
244 goto get_reg_page_out_unlock;
250 "write error (read register page): %d\n",
252 goto get_reg_page_out_unlock;
253 }
else if (err != numregs) {
255 "write error (read register page) "
256 "%d bytes transferred (expected %d)\n",
259 goto get_reg_page_out_unlock;
265 get_reg_page_out_unlock:
270 static int get_register_page_interruptible(
struct device *
dev,
u8 bank,
271 u8 first_reg,
u8 *regvals,
u8 numregs)
275 return ab3100_get_register_page_interruptible(ab3100,
276 first_reg, regvals, numregs);
279 static int ab3100_mask_and_set_register_interruptible(
struct ab3100 *ab3100,
280 u8 reg,
u8 andmask,
u8 ormask)
282 u8 regandval[2] = {
reg, 0};
293 "write error (maskset send address): %d\n",
295 goto get_maskset_unlock;
296 }
else if (err != 1) {
298 "write error (maskset send address) "
299 "%d bytes transferred (expected 1)\n",
302 goto get_maskset_unlock;
308 "write error (maskset read register): %d\n",
310 goto get_maskset_unlock;
311 }
else if (err != 1) {
313 "write error (maskset read register) "
314 "%d bytes transferred (expected 1)\n",
317 goto get_maskset_unlock;
321 regandval[1] &= andmask;
322 regandval[1] |= ormask;
328 "write error (write register): %d\n",
330 goto get_maskset_unlock;
331 }
else if (err != 2) {
333 "write error (write register) "
334 "%d bytes transferred (expected 2)\n",
337 goto get_maskset_unlock;
348 static int mask_and_set_register_interruptible(
struct device *
dev,
u8 bank,
353 return ab3100_mask_and_set_register_interruptible(ab3100,
354 reg, bitmask, (bitmask & bitvalues));
380 static int ab3100_event_registers_startup_state_get(
struct device *dev,
391 .get_chip_id = ab3100_get_chip_id,
392 .set_register = set_register_interruptible,
393 .get_register = get_register_interruptible,
394 .get_register_page = get_register_page_interruptible,
395 .set_register_page =
NULL,
396 .mask_and_set_register = mask_and_set_register_interruptible,
397 .event_registers_startup_state_get =
398 ab3100_event_registers_startup_state_get,
399 .startup_irq_enabled =
NULL,
408 struct ab3100 *ab3100 =
data;
413 err = ab3100_get_register_page_interruptible(ab3100,
AB3100_EVENTA1,
418 fatevent = (event_regs[0] << 16) |
419 (event_regs[1] << 8) |
438 "IRQ Event: 0x%08x\n", fatevent);
444 "error reading event status\n");
448 #ifdef CONFIG_DEBUG_FS
452 static int ab3100_registers_print(
struct seq_file *
s,
void *
p)
454 struct ab3100 *ab3100 = s->
private;
460 for (reg = 0; reg < 0xff; reg++) {
461 ab3100_get_register_interruptible(ab3100, reg, &value);
473 .
open = ab3100_registers_open,
480 struct ab3100_get_set_reg_priv {
481 struct ab3100 *ab3100;
486 const char __user *user_buf,
487 size_t count, loff_t *ppos)
490 struct ab3100 *ab3100 = priv->ab3100;
494 unsigned long user_reg;
499 buf_size =
min(count, (
sizeof(buf)-1));
510 while ((i < buf_size) && (buf[i] ==
' '))
519 while ((i < buf_size) && (buf[i] !=
' '))
532 u8 reg = (
u8) user_reg;
535 ab3100_get_register_interruptible(ab3100, reg, ®value);
538 "debug read AB3100 reg[0x%02x]: 0x%02x\n",
542 unsigned long user_value;
543 u8 reg = (
u8) user_reg;
553 while ((i < buf_size) && (buf[
i] ==
' '))
556 while ((i < buf_size) && (buf[
i] !=
' '))
566 value = (
u8) user_value;
567 ab3100_set_register_interruptible(ab3100, reg, value);
568 ab3100_get_register_interruptible(ab3100, reg, ®value);
571 "debug write reg[0x%02x] with 0x%02x, "
572 "after readback: 0x%02x\n",
573 reg, value, regvalue);
580 .write = ab3100_get_set_reg,
584 static struct dentry *ab3100_dir;
585 static struct dentry *ab3100_reg_file;
586 static struct ab3100_get_set_reg_priv ab3100_get_priv;
587 static struct dentry *ab3100_get_reg_file;
588 static struct ab3100_get_set_reg_priv ab3100_set_priv;
589 static struct dentry *ab3100_set_reg_file;
591 static void ab3100_setup_debugfs(
struct ab3100 *ab3100)
597 goto exit_no_debugfs;
601 &ab3100_registers_fops);
602 if (!ab3100_reg_file) {
604 goto exit_destroy_dir;
607 ab3100_get_priv.ab3100 = ab3100;
608 ab3100_get_priv.mode =
false;
610 S_IWUSR, ab3100_dir, &ab3100_get_priv,
611 &ab3100_get_set_reg_fops);
612 if (!ab3100_get_reg_file) {
614 goto exit_destroy_reg;
617 ab3100_set_priv.ab3100 = ab3100;
618 ab3100_set_priv.mode =
true;
620 S_IWUSR, ab3100_dir, &ab3100_set_priv,
621 &ab3100_get_set_reg_fops);
622 if (!ab3100_set_reg_file) {
624 goto exit_destroy_get_reg;
628 exit_destroy_get_reg:
637 static inline void ab3100_remove_debugfs(
void)
645 static inline void ab3100_setup_debugfs(
struct ab3100 *ab3100)
648 static inline void ab3100_remove_debugfs(
void)
665 ab3100_init_settings[] = {
711 static int __devinit ab3100_setup(
struct ab3100 *ab3100)
716 for (i = 0; i <
ARRAY_SIZE(ab3100_init_settings); i++) {
717 err = ab3100_set_register_interruptible(ab3100,
718 ab3100_init_settings[i].
abreg,
719 ab3100_init_settings[i].
setting);
731 "AB3100 P1E variant detected, "
732 "forcing chip to 32KHz\n");
733 err = ab3100_set_test_register_interruptible(ab3100,
742 static struct mfd_cell ab3100_devs[] = {
744 .name =
"ab3100-dac",
748 .name =
"ab3100-leds",
752 .name =
"ab3100-power",
756 .name =
"ab3100-regulators",
760 .name =
"ab3100-sim",
764 .name =
"ab3100-uart",
768 .name =
"ab3100-rtc",
772 .name =
"ab3100-charger",
776 .name =
"ab3100-boost",
780 .name =
"ab3100-adc",
784 .name =
"ab3100-fuelgauge",
788 .name =
"ab3100-vibrator",
792 .name =
"ab3100-otp",
796 .name =
"ab3100-codec",
863 struct ab3100 *ab3100;
865 client->
dev.platform_data;
871 dev_err(&client->
dev,
"could not allocate AB3100 device\n");
882 i2c_set_clientdata(client, ab3100);
885 err = ab3100_get_register_interruptible(ab3100,
AB3100_CID,
889 "could not communicate with the AB3100 analog "
894 for (i = 0; ids[
i].id != 0x0; i++) {
895 if (ids[i].
id == ab3100->
chip_id) {
904 "AB3000 is not supported\n");
910 if (ids[i].
id == 0x0) {
911 dev_err(&client->
dev,
"unknown analog baseband chip id: 0x%x\n",
913 dev_err(&client->
dev,
"accepting it anyway. Please update "
926 goto exit_no_testreg_client;
929 err = ab3100_setup(ab3100);
934 client->
irq,
NULL, ab3100_irq_handler,
944 for (i = 0; i <
ARRAY_SIZE(ab3100_devs); i++) {
952 ab3100_setup_debugfs(ab3100);
960 exit_no_testreg_client:
967 struct ab3100 *ab3100 = i2c_get_clientdata(client);
971 ab3100_remove_debugfs();
987 .id_table = ab3100_id,
988 .probe = ab3100_probe,
992 static int __init ab3100_i2c_init(
void)
994 return i2c_add_driver(&ab3100_driver);
997 static void __exit ab3100_i2c_exit(
void)