diff options
Diffstat (limited to 'sound/soc/codecs/cs42l51.c')
-rw-r--r-- | sound/soc/codecs/cs42l51.c | 80 |
1 files changed, 22 insertions, 58 deletions
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c index 6c0da2baa154..09488d97de60 100644 --- a/sound/soc/codecs/cs42l51.c +++ b/sound/soc/codecs/cs42l51.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <sound/initval.h> | 29 | #include <sound/initval.h> |
30 | #include <sound/pcm_params.h> | 30 | #include <sound/pcm_params.h> |
31 | #include <sound/pcm.h> | 31 | #include <sound/pcm.h> |
32 | #include <linux/i2c.h> | ||
33 | #include <linux/regmap.h> | 32 | #include <linux/regmap.h> |
34 | 33 | ||
35 | #include "cs42l51.h" | 34 | #include "cs42l51.h" |
@@ -55,7 +54,7 @@ struct cs42l51_private { | |||
55 | static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, | 54 | static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, |
56 | struct snd_ctl_elem_value *ucontrol) | 55 | struct snd_ctl_elem_value *ucontrol) |
57 | { | 56 | { |
58 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | 57 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
59 | unsigned long value = snd_soc_read(codec, CS42L51_PCM_MIXER)&3; | 58 | unsigned long value = snd_soc_read(codec, CS42L51_PCM_MIXER)&3; |
60 | 59 | ||
61 | switch (value) { | 60 | switch (value) { |
@@ -83,7 +82,7 @@ static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol, | |||
83 | static int cs42l51_set_chan_mix(struct snd_kcontrol *kcontrol, | 82 | static int cs42l51_set_chan_mix(struct snd_kcontrol *kcontrol, |
84 | struct snd_ctl_elem_value *ucontrol) | 83 | struct snd_ctl_elem_value *ucontrol) |
85 | { | 84 | { |
86 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); | 85 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
87 | unsigned char val; | 86 | unsigned char val; |
88 | 87 | ||
89 | switch (ucontrol->value.integer.value[0]) { | 88 | switch (ucontrol->value.integer.value[0]) { |
@@ -483,7 +482,7 @@ static struct snd_soc_dai_driver cs42l51_dai = { | |||
483 | .ops = &cs42l51_dai_ops, | 482 | .ops = &cs42l51_dai_ops, |
484 | }; | 483 | }; |
485 | 484 | ||
486 | static int cs42l51_probe(struct snd_soc_codec *codec) | 485 | static int cs42l51_codec_probe(struct snd_soc_codec *codec) |
487 | { | 486 | { |
488 | int ret, reg; | 487 | int ret, reg; |
489 | 488 | ||
@@ -504,7 +503,7 @@ static int cs42l51_probe(struct snd_soc_codec *codec) | |||
504 | } | 503 | } |
505 | 504 | ||
506 | static struct snd_soc_codec_driver soc_codec_device_cs42l51 = { | 505 | static struct snd_soc_codec_driver soc_codec_device_cs42l51 = { |
507 | .probe = cs42l51_probe, | 506 | .probe = cs42l51_codec_probe, |
508 | 507 | ||
509 | .controls = cs42l51_snd_controls, | 508 | .controls = cs42l51_snd_controls, |
510 | .num_controls = ARRAY_SIZE(cs42l51_snd_controls), | 509 | .num_controls = ARRAY_SIZE(cs42l51_snd_controls), |
@@ -514,91 +513,56 @@ static struct snd_soc_codec_driver soc_codec_device_cs42l51 = { | |||
514 | .num_dapm_routes = ARRAY_SIZE(cs42l51_routes), | 513 | .num_dapm_routes = ARRAY_SIZE(cs42l51_routes), |
515 | }; | 514 | }; |
516 | 515 | ||
517 | static const struct regmap_config cs42l51_regmap = { | 516 | const struct regmap_config cs42l51_regmap = { |
518 | .reg_bits = 8, | ||
519 | .val_bits = 8, | ||
520 | |||
521 | .max_register = CS42L51_CHARGE_FREQ, | 517 | .max_register = CS42L51_CHARGE_FREQ, |
522 | .cache_type = REGCACHE_RBTREE, | 518 | .cache_type = REGCACHE_RBTREE, |
523 | }; | 519 | }; |
520 | EXPORT_SYMBOL_GPL(cs42l51_regmap); | ||
524 | 521 | ||
525 | static int cs42l51_i2c_probe(struct i2c_client *i2c_client, | 522 | int cs42l51_probe(struct device *dev, struct regmap *regmap) |
526 | const struct i2c_device_id *id) | ||
527 | { | 523 | { |
528 | struct cs42l51_private *cs42l51; | 524 | struct cs42l51_private *cs42l51; |
529 | struct regmap *regmap; | ||
530 | unsigned int val; | 525 | unsigned int val; |
531 | int ret; | 526 | int ret; |
532 | 527 | ||
533 | regmap = devm_regmap_init_i2c(i2c_client, &cs42l51_regmap); | 528 | if (IS_ERR(regmap)) |
534 | if (IS_ERR(regmap)) { | 529 | return PTR_ERR(regmap); |
535 | ret = PTR_ERR(regmap); | 530 | |
536 | dev_err(&i2c_client->dev, "Failed to create regmap: %d\n", | 531 | cs42l51 = devm_kzalloc(dev, sizeof(struct cs42l51_private), |
537 | ret); | 532 | GFP_KERNEL); |
538 | return ret; | 533 | if (!cs42l51) |
539 | } | 534 | return -ENOMEM; |
535 | |||
536 | dev_set_drvdata(dev, cs42l51); | ||
540 | 537 | ||
541 | /* Verify that we have a CS42L51 */ | 538 | /* Verify that we have a CS42L51 */ |
542 | ret = regmap_read(regmap, CS42L51_CHIP_REV_ID, &val); | 539 | ret = regmap_read(regmap, CS42L51_CHIP_REV_ID, &val); |
543 | if (ret < 0) { | 540 | if (ret < 0) { |
544 | dev_err(&i2c_client->dev, "failed to read I2C\n"); | 541 | dev_err(dev, "failed to read I2C\n"); |
545 | goto error; | 542 | goto error; |
546 | } | 543 | } |
547 | 544 | ||
548 | if ((val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && | 545 | if ((val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_A)) && |
549 | (val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { | 546 | (val != CS42L51_MK_CHIP_REV(CS42L51_CHIP_ID, CS42L51_CHIP_REV_B))) { |
550 | dev_err(&i2c_client->dev, "Invalid chip id: %x\n", val); | 547 | dev_err(dev, "Invalid chip id: %x\n", val); |
551 | ret = -ENODEV; | 548 | ret = -ENODEV; |
552 | goto error; | 549 | goto error; |
553 | } | 550 | } |
551 | dev_info(dev, "Cirrus Logic CS42L51, Revision: %02X\n", | ||
552 | val & CS42L51_CHIP_REV_MASK); | ||
554 | 553 | ||
555 | dev_info(&i2c_client->dev, "found device cs42l51 rev %d\n", | 554 | ret = snd_soc_register_codec(dev, |
556 | val & 7); | ||
557 | |||
558 | cs42l51 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs42l51_private), | ||
559 | GFP_KERNEL); | ||
560 | if (!cs42l51) | ||
561 | return -ENOMEM; | ||
562 | |||
563 | i2c_set_clientdata(i2c_client, cs42l51); | ||
564 | |||
565 | ret = snd_soc_register_codec(&i2c_client->dev, | ||
566 | &soc_codec_device_cs42l51, &cs42l51_dai, 1); | 555 | &soc_codec_device_cs42l51, &cs42l51_dai, 1); |
567 | error: | 556 | error: |
568 | return ret; | 557 | return ret; |
569 | } | 558 | } |
570 | 559 | EXPORT_SYMBOL_GPL(cs42l51_probe); | |
571 | static int cs42l51_i2c_remove(struct i2c_client *client) | ||
572 | { | ||
573 | snd_soc_unregister_codec(&client->dev); | ||
574 | return 0; | ||
575 | } | ||
576 | |||
577 | static const struct i2c_device_id cs42l51_id[] = { | ||
578 | {"cs42l51", 0}, | ||
579 | {} | ||
580 | }; | ||
581 | MODULE_DEVICE_TABLE(i2c, cs42l51_id); | ||
582 | 560 | ||
583 | static const struct of_device_id cs42l51_of_match[] = { | 561 | static const struct of_device_id cs42l51_of_match[] = { |
584 | { .compatible = "cirrus,cs42l51", }, | 562 | { .compatible = "cirrus,cs42l51", }, |
585 | { } | 563 | { } |
586 | }; | 564 | }; |
587 | MODULE_DEVICE_TABLE(of, cs42l51_of_match); | 565 | MODULE_DEVICE_TABLE(of, cs42l51_of_match); |
588 | |||
589 | static struct i2c_driver cs42l51_i2c_driver = { | ||
590 | .driver = { | ||
591 | .name = "cs42l51-codec", | ||
592 | .owner = THIS_MODULE, | ||
593 | .of_match_table = cs42l51_of_match, | ||
594 | }, | ||
595 | .id_table = cs42l51_id, | ||
596 | .probe = cs42l51_i2c_probe, | ||
597 | .remove = cs42l51_i2c_remove, | ||
598 | }; | ||
599 | |||
600 | module_i2c_driver(cs42l51_i2c_driver); | ||
601 | |||
602 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); | 566 | MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); |
603 | MODULE_DESCRIPTION("Cirrus Logic CS42L51 ALSA SoC Codec Driver"); | 567 | MODULE_DESCRIPTION("Cirrus Logic CS42L51 ALSA SoC Codec Driver"); |
604 | MODULE_LICENSE("GPL"); | 568 | MODULE_LICENSE("GPL"); |