sma1303.c (1f5ffd57c1bcdf02e5a35bf301734476c1bf6612) sma1303.c (2512839dd648ffa2c2a752e1403aaeb928cff71a)
1// SPDX-License-Identifier: GPL-2.0-or-later
2//
3// sma1303.c -- sma1303 ALSA SoC Audio driver
4//
5// Copyright 2023 Iron Device Corporation
6//
7// Auther: Gyuhwa Park <gyuhwa.park@irondevice.com>
8// Kiseok Jo <kiseok.jo@irondevice.com>

--- 984 unchanged lines hidden (view full) ---

993 * params_channels(params);
994
995 dev_dbg(component->dev,
996 "%s : rate = %d : bit size = %d : channel = %d\n",
997 __func__, params_rate(params), params_width(params),
998 params_channels(params));
999
1000 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1// SPDX-License-Identifier: GPL-2.0-or-later
2//
3// sma1303.c -- sma1303 ALSA SoC Audio driver
4//
5// Copyright 2023 Iron Device Corporation
6//
7// Auther: Gyuhwa Park <gyuhwa.park@irondevice.com>
8// Kiseok Jo <kiseok.jo@irondevice.com>

--- 984 unchanged lines hidden (view full) ---

993 * params_channels(params);
994
995 dev_dbg(component->dev,
996 "%s : rate = %d : bit size = %d : channel = %d\n",
997 __func__, params_rate(params), params_width(params),
998 params_channels(params));
999
1000 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1001
1002 if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_MCLK
1003 || sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) {
1004
1001 if (sma1303->sys_clk_id == SMA1303_PLL_CLKIN_BCLK) {
1005 if (sma1303->last_bclk != bclk) {
1006 sma1303_setup_pll(component, bclk);
1007 sma1303->last_bclk = bclk;
1008 }
1009 }
1010
1011 switch (params_rate(params)) {
1012 case 8000:

--- 662 unchanged lines hidden (view full) ---

1675
1676static struct attribute_group sma1303_attr_group = {
1677 .attrs = sma1303_attr,
1678};
1679
1680static int sma1303_i2c_probe(struct i2c_client *client)
1681{
1682 struct sma1303_priv *sma1303;
1002 if (sma1303->last_bclk != bclk) {
1003 sma1303_setup_pll(component, bclk);
1004 sma1303->last_bclk = bclk;
1005 }
1006 }
1007
1008 switch (params_rate(params)) {
1009 case 8000:

--- 662 unchanged lines hidden (view full) ---

1672
1673static struct attribute_group sma1303_attr_group = {
1674 .attrs = sma1303_attr,
1675};
1676
1677static int sma1303_i2c_probe(struct i2c_client *client)
1678{
1679 struct sma1303_priv *sma1303;
1683 struct device_node *np = client->dev.of_node;
1684 int ret, i = 0;
1680 int ret, i = 0;
1685 u32 value = 0;
1686 unsigned int device_info, status, otp_stat;
1687
1688 sma1303 = devm_kzalloc(&client->dev,
1689 sizeof(struct sma1303_priv), GFP_KERNEL);
1690 if (!sma1303)
1691 return -ENOMEM;
1692 sma1303->dev = &client->dev;
1693
1694 sma1303->regmap = devm_regmap_init_i2c(client, &sma_i2c_regmap);
1695 if (IS_ERR(sma1303->regmap)) {
1696 ret = PTR_ERR(sma1303->regmap);
1697 dev_err(&client->dev,
1698 "Failed to allocate register map: %d\n", ret);
1699
1700 return ret;
1701 }
1702
1681 unsigned int device_info, status, otp_stat;
1682
1683 sma1303 = devm_kzalloc(&client->dev,
1684 sizeof(struct sma1303_priv), GFP_KERNEL);
1685 if (!sma1303)
1686 return -ENOMEM;
1687 sma1303->dev = &client->dev;
1688
1689 sma1303->regmap = devm_regmap_init_i2c(client, &sma_i2c_regmap);
1690 if (IS_ERR(sma1303->regmap)) {
1691 ret = PTR_ERR(sma1303->regmap);
1692 dev_err(&client->dev,
1693 "Failed to allocate register map: %d\n", ret);
1694
1695 return ret;
1696 }
1697
1703 if (np) {
1704 if (!of_property_read_u32(np, "sys-clk-id", &value)) {
1705 switch (value) {
1706 case SMA1303_EXTERNAL_CLOCK_19_2:
1707 case SMA1303_EXTERNAL_CLOCK_24_576:
1708 case SMA1303_PLL_CLKIN_MCLK:
1709 dev_dbg(&client->dev, "MCLK is not supported\n");
1710 break;
1711 case SMA1303_PLL_CLKIN_BCLK:
1712 dev_dbg(&client->dev,
1713 "Take an BCLK(SCK) and covert it to an internal PLL for use\n");
1714 break;
1715 default:
1716 dev_err(&client->dev,
1717 "Invalid sys-clk-id: %u\n", value);
1718 return -EINVAL;
1719 }
1720 sma1303->sys_clk_id = value;
1721 } else {
1722 dev_dbg(&client->dev, "Use the internal PLL clock by default\n");
1723 sma1303->sys_clk_id = SMA1303_PLL_CLKIN_BCLK;
1724 }
1725 } else {
1726 dev_err(&client->dev,
1727 "device node initialization error\n");
1728 devm_kfree(&client->dev, sma1303);
1729 return -ENODEV;
1730 }
1731
1732 ret = sma1303_regmap_read(sma1303,
1733 SMA1303_FF_DEVICE_INDEX, &device_info);
1734
1735 if ((ret != 0) || ((device_info & 0xF8) != SMA1303_DEVICE_ID)) {
1736 dev_err(&client->dev, "device initialization error (%d 0x%02X)",
1737 ret, device_info);
1738 }
1739 dev_dbg(&client->dev, "chip version 0x%02X\n", device_info);

--- 38 unchanged lines hidden (view full) ---

1778 sma1303->cur_vol = sma1303->init_vol;
1779 sma1303->last_bclk = 0;
1780 sma1303->last_ocp_val = 0x08;
1781 sma1303->last_over_temp = 0xC0;
1782 sma1303->tsdw_cnt = 0;
1783 sma1303->retry_cnt = SMA1303_I2C_RETRY_COUNT;
1784 sma1303->tdm_slot_rx = 0;
1785 sma1303->tdm_slot_tx = 0;
1698 ret = sma1303_regmap_read(sma1303,
1699 SMA1303_FF_DEVICE_INDEX, &device_info);
1700
1701 if ((ret != 0) || ((device_info & 0xF8) != SMA1303_DEVICE_ID)) {
1702 dev_err(&client->dev, "device initialization error (%d 0x%02X)",
1703 ret, device_info);
1704 }
1705 dev_dbg(&client->dev, "chip version 0x%02X\n", device_info);

--- 38 unchanged lines hidden (view full) ---

1744 sma1303->cur_vol = sma1303->init_vol;
1745 sma1303->last_bclk = 0;
1746 sma1303->last_ocp_val = 0x08;
1747 sma1303->last_over_temp = 0xC0;
1748 sma1303->tsdw_cnt = 0;
1749 sma1303->retry_cnt = SMA1303_I2C_RETRY_COUNT;
1750 sma1303->tdm_slot_rx = 0;
1751 sma1303->tdm_slot_tx = 0;
1752 sma1303->sys_clk_id = SMA1303_PLL_CLKIN_BCLK;
1786
1787 sma1303->dev = &client->dev;
1788 sma1303->kobj = &client->dev.kobj;
1789
1790 INIT_DELAYED_WORK(&sma1303->check_fault_work,
1791 sma1303_check_fault_worker);
1792
1793 i2c_set_clientdata(client, sma1303);

--- 60 unchanged lines hidden ---
1753
1754 sma1303->dev = &client->dev;
1755 sma1303->kobj = &client->dev.kobj;
1756
1757 INIT_DELAYED_WORK(&sma1303->check_fault_work,
1758 sma1303_check_fault_worker);
1759
1760 i2c_set_clientdata(client, sma1303);

--- 60 unchanged lines hidden ---