diff options
Diffstat (limited to 'sound/soc/codecs/cs4270.c')
| -rw-r--r-- | sound/soc/codecs/cs4270.c | 103 |
1 files changed, 34 insertions, 69 deletions
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c index 9deb8c74fdfd..0bbd94501d7e 100644 --- a/sound/soc/codecs/cs4270.c +++ b/sound/soc/codecs/cs4270.c | |||
| @@ -490,34 +490,7 @@ static int cs4270_mute(struct snd_soc_dai *dai, int mute) | |||
| 490 | 490 | ||
| 491 | #endif | 491 | #endif |
| 492 | 492 | ||
| 493 | static int cs4270_i2c_probe(struct i2c_adapter *adap, int addr, int kind); | 493 | static int cs4270_i2c_probe(struct i2c_client *, const struct i2c_device_id *); |
| 494 | |||
| 495 | /* | ||
| 496 | * Notify the driver that a new I2C bus has been found. | ||
| 497 | * | ||
| 498 | * This function is called for each I2C bus in the system. The function | ||
| 499 | * then asks the I2C subsystem to probe that bus at the addresses on which | ||
| 500 | * our device (the CS4270) could exist. If a device is found at one of | ||
| 501 | * those addresses, then our probe function (cs4270_i2c_probe) is called. | ||
| 502 | */ | ||
| 503 | static int cs4270_i2c_attach(struct i2c_adapter *adapter) | ||
| 504 | { | ||
| 505 | return i2c_probe(adapter, &addr_data, cs4270_i2c_probe); | ||
| 506 | } | ||
| 507 | |||
| 508 | static int cs4270_i2c_detach(struct i2c_client *client) | ||
| 509 | { | ||
| 510 | struct snd_soc_codec *codec = i2c_get_clientdata(client); | ||
| 511 | |||
| 512 | i2c_detach_client(client); | ||
| 513 | codec->control_data = NULL; | ||
| 514 | |||
| 515 | kfree(codec->reg_cache); | ||
| 516 | codec->reg_cache = NULL; | ||
| 517 | |||
| 518 | kfree(client); | ||
| 519 | return 0; | ||
| 520 | } | ||
| 521 | 494 | ||
| 522 | /* A list of non-DAPM controls that the CS4270 supports */ | 495 | /* A list of non-DAPM controls that the CS4270 supports */ |
| 523 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { | 496 | static const struct snd_kcontrol_new cs4270_snd_controls[] = { |
| @@ -525,14 +498,19 @@ static const struct snd_kcontrol_new cs4270_snd_controls[] = { | |||
| 525 | CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1) | 498 | CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1) |
| 526 | }; | 499 | }; |
| 527 | 500 | ||
| 501 | static const struct i2c_device_id cs4270_id[] = { | ||
| 502 | {"cs4270", 0}, | ||
| 503 | {} | ||
| 504 | }; | ||
| 505 | MODULE_DEVICE_TABLE(i2c, cs4270_id); | ||
| 506 | |||
| 528 | static struct i2c_driver cs4270_i2c_driver = { | 507 | static struct i2c_driver cs4270_i2c_driver = { |
| 529 | .driver = { | 508 | .driver = { |
| 530 | .name = "CS4270 I2C", | 509 | .name = "CS4270 I2C", |
| 531 | .owner = THIS_MODULE, | 510 | .owner = THIS_MODULE, |
| 532 | }, | 511 | }, |
| 533 | .id = I2C_DRIVERID_CS4270, | 512 | .id_table = cs4270_id, |
| 534 | .attach_adapter = cs4270_i2c_attach, | 513 | .probe = cs4270_i2c_probe, |
| 535 | .detach_client = cs4270_i2c_detach, | ||
| 536 | }; | 514 | }; |
| 537 | 515 | ||
| 538 | /* | 516 | /* |
| @@ -561,11 +539,11 @@ static struct snd_soc_device *cs4270_socdev; | |||
| 561 | * Note: snd_soc_new_pcms() must be called before this function can be called, | 539 | * Note: snd_soc_new_pcms() must be called before this function can be called, |
| 562 | * because of snd_ctl_add(). | 540 | * because of snd_ctl_add(). |
| 563 | */ | 541 | */ |
| 564 | static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind) | 542 | static int cs4270_i2c_probe(struct i2c_client *i2c_client, |
| 543 | const struct i2c_device_id *id) | ||
| 565 | { | 544 | { |
| 566 | struct snd_soc_device *socdev = cs4270_socdev; | 545 | struct snd_soc_device *socdev = cs4270_socdev; |
| 567 | struct snd_soc_codec *codec = socdev->codec; | 546 | struct snd_soc_codec *codec = socdev->codec; |
| 568 | struct i2c_client *i2c_client = NULL; | ||
| 569 | int i; | 547 | int i; |
| 570 | int ret = 0; | 548 | int ret = 0; |
| 571 | 549 | ||
| @@ -578,12 +556,6 @@ static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind) | |||
| 578 | 556 | ||
| 579 | /* Note: codec_dai->codec is NULL here */ | 557 | /* Note: codec_dai->codec is NULL here */ |
| 580 | 558 | ||
| 581 | i2c_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | ||
| 582 | if (!i2c_client) { | ||
| 583 | printk(KERN_ERR "cs4270: could not allocate I2C client\n"); | ||
| 584 | return -ENOMEM; | ||
| 585 | } | ||
| 586 | |||
| 587 | codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL); | 559 | codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL); |
| 588 | if (!codec->reg_cache) { | 560 | if (!codec->reg_cache) { |
| 589 | printk(KERN_ERR "cs4270: could not allocate register cache\n"); | 561 | printk(KERN_ERR "cs4270: could not allocate register cache\n"); |
| @@ -591,13 +563,6 @@ static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind) | |||
| 591 | goto error; | 563 | goto error; |
| 592 | } | 564 | } |
| 593 | 565 | ||
| 594 | i2c_set_clientdata(i2c_client, codec); | ||
| 595 | strcpy(i2c_client->name, "CS4270"); | ||
| 596 | |||
| 597 | i2c_client->driver = &cs4270_i2c_driver; | ||
| 598 | i2c_client->adapter = adapter; | ||
| 599 | i2c_client->addr = addr; | ||
| 600 | |||
| 601 | /* Verify that we have a CS4270 */ | 566 | /* Verify that we have a CS4270 */ |
| 602 | 567 | ||
| 603 | ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); | 568 | ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); |
| @@ -612,18 +577,10 @@ static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind) | |||
| 612 | goto error; | 577 | goto error; |
| 613 | } | 578 | } |
| 614 | 579 | ||
| 615 | printk(KERN_INFO "cs4270: found device at I2C address %X\n", addr); | 580 | printk(KERN_INFO "cs4270: found device at I2C address %X\n", |
| 581 | i2c_client->addr); | ||
| 616 | printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF); | 582 | printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF); |
| 617 | 583 | ||
| 618 | /* Tell the I2C layer a new client has arrived */ | ||
| 619 | |||
| 620 | ret = i2c_attach_client(i2c_client); | ||
| 621 | if (ret) { | ||
| 622 | printk(KERN_ERR "cs4270: could not attach codec, " | ||
| 623 | "I2C address %x, error code %i\n", addr, ret); | ||
| 624 | goto error; | ||
| 625 | } | ||
| 626 | |||
| 627 | codec->control_data = i2c_client; | 584 | codec->control_data = i2c_client; |
| 628 | codec->read = cs4270_read_reg_cache; | 585 | codec->read = cs4270_read_reg_cache; |
| 629 | codec->write = cs4270_i2c_write; | 586 | codec->write = cs4270_i2c_write; |
| @@ -648,20 +605,17 @@ static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind) | |||
| 648 | goto error; | 605 | goto error; |
| 649 | } | 606 | } |
| 650 | 607 | ||
| 608 | i2c_set_clientdata(i2c_client, codec); | ||
| 609 | |||
| 651 | return 0; | 610 | return 0; |
| 652 | 611 | ||
| 653 | error: | 612 | error: |
| 654 | if (codec->control_data) { | 613 | codec->control_data = NULL; |
| 655 | i2c_detach_client(i2c_client); | ||
| 656 | codec->control_data = NULL; | ||
| 657 | } | ||
| 658 | 614 | ||
| 659 | kfree(codec->reg_cache); | 615 | kfree(codec->reg_cache); |
| 660 | codec->reg_cache = NULL; | 616 | codec->reg_cache = NULL; |
| 661 | codec->reg_cache_size = 0; | 617 | codec->reg_cache_size = 0; |
| 662 | 618 | ||
| 663 | kfree(i2c_client); | ||
| 664 | |||
| 665 | return ret; | 619 | return ret; |
| 666 | } | 620 | } |
| 667 | 621 | ||
| @@ -727,7 +681,7 @@ static int cs4270_probe(struct platform_device *pdev) | |||
| 727 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); | 681 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 728 | if (ret < 0) { | 682 | if (ret < 0) { |
| 729 | printk(KERN_ERR "cs4270: failed to create PCMs\n"); | 683 | printk(KERN_ERR "cs4270: failed to create PCMs\n"); |
| 730 | return ret; | 684 | goto error_free_codec; |
| 731 | } | 685 | } |
| 732 | 686 | ||
| 733 | #ifdef USE_I2C | 687 | #ifdef USE_I2C |
| @@ -736,8 +690,7 @@ static int cs4270_probe(struct platform_device *pdev) | |||
| 736 | ret = i2c_add_driver(&cs4270_i2c_driver); | 690 | ret = i2c_add_driver(&cs4270_i2c_driver); |
| 737 | if (ret) { | 691 | if (ret) { |
| 738 | printk(KERN_ERR "cs4270: failed to attach driver"); | 692 | printk(KERN_ERR "cs4270: failed to attach driver"); |
| 739 | snd_soc_free_pcms(socdev); | 693 | goto error_free_pcms; |
| 740 | return ret; | ||
| 741 | } | 694 | } |
| 742 | 695 | ||
| 743 | /* Did we find a CS4270 on the I2C bus? */ | 696 | /* Did we find a CS4270 on the I2C bus? */ |
| @@ -759,10 +712,23 @@ static int cs4270_probe(struct platform_device *pdev) | |||
| 759 | ret = snd_soc_register_card(socdev); | 712 | ret = snd_soc_register_card(socdev); |
| 760 | if (ret < 0) { | 713 | if (ret < 0) { |
| 761 | printk(KERN_ERR "cs4270: failed to register card\n"); | 714 | printk(KERN_ERR "cs4270: failed to register card\n"); |
| 762 | snd_soc_free_pcms(socdev); | 715 | goto error_del_driver; |
| 763 | return ret; | ||
| 764 | } | 716 | } |
| 765 | 717 | ||
| 718 | return 0; | ||
| 719 | |||
| 720 | error_del_driver: | ||
| 721 | #ifdef USE_I2C | ||
| 722 | i2c_del_driver(&cs4270_i2c_driver); | ||
| 723 | |||
| 724 | error_free_pcms: | ||
| 725 | #endif | ||
| 726 | snd_soc_free_pcms(socdev); | ||
| 727 | |||
| 728 | error_free_codec: | ||
| 729 | kfree(socdev->codec); | ||
| 730 | socdev->codec = NULL; | ||
| 731 | |||
| 766 | return ret; | 732 | return ret; |
| 767 | } | 733 | } |
| 768 | 734 | ||
| @@ -773,8 +739,7 @@ static int cs4270_remove(struct platform_device *pdev) | |||
| 773 | snd_soc_free_pcms(socdev); | 739 | snd_soc_free_pcms(socdev); |
| 774 | 740 | ||
| 775 | #ifdef USE_I2C | 741 | #ifdef USE_I2C |
| 776 | if (socdev->codec->control_data) | 742 | i2c_del_driver(&cs4270_i2c_driver); |
| 777 | i2c_del_driver(&cs4270_i2c_driver); | ||
| 778 | #endif | 743 | #endif |
| 779 | 744 | ||
| 780 | kfree(socdev->codec); | 745 | kfree(socdev->codec); |
