| .. | .. | 
|---|
|  | 1 | +// SPDX-License-Identifier: GPL-2.0-or-later | 
|---|
| 1 | 2 | /* | 
|---|
| 2 | 3 | * PMac DBDMA lowlevel functions | 
|---|
| 3 | 4 | * | 
|---|
| 4 | 5 | * Copyright (c) by Takashi Iwai <tiwai@suse.de> | 
|---|
| 5 | 6 | * code based on dmasound.c. | 
|---|
| 6 |  | - * | 
|---|
| 7 |  | - *   This program is free software; you can redistribute it and/or modify | 
|---|
| 8 |  | - *   it under the terms of the GNU General Public License as published by | 
|---|
| 9 |  | - *   the Free Software Foundation; either version 2 of the License, or | 
|---|
| 10 |  | - *   (at your option) any later version. | 
|---|
| 11 |  | - * | 
|---|
| 12 |  | - *   This program is distributed in the hope that it will be useful, | 
|---|
| 13 |  | - *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 14 |  | - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 15 |  | - *   GNU General Public License for more details. | 
|---|
| 16 |  | - * | 
|---|
| 17 |  | - *   You should have received a copy of the GNU General Public License | 
|---|
| 18 |  | - *   along with this program; if not, write to the Free Software | 
|---|
| 19 |  | - *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
|---|
| 20 | 7 | */ | 
|---|
| 21 | 8 |  | 
|---|
| 22 | 9 |  | 
|---|
| .. | .. | 
|---|
| 37 | 24 |  | 
|---|
| 38 | 25 |  | 
|---|
| 39 | 26 | /* fixed frequency table for awacs, screamer, burgundy, DACA (44100 max) */ | 
|---|
| 40 |  | -static int awacs_freqs[8] = { | 
|---|
|  | 27 | +static const int awacs_freqs[8] = { | 
|---|
| 41 | 28 | 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350 | 
|---|
| 42 | 29 | }; | 
|---|
| 43 | 30 | /* fixed frequency table for tumbler */ | 
|---|
| 44 |  | -static int tumbler_freqs[1] = { | 
|---|
|  | 31 | +static const int tumbler_freqs[1] = { | 
|---|
| 45 | 32 | 44100 | 
|---|
| 46 | 33 | }; | 
|---|
| 47 | 34 |  | 
|---|
| .. | .. | 
|---|
| 118 | 105 | { | 
|---|
| 119 | 106 | return (stream == SNDRV_PCM_STREAM_PLAYBACK) ? | 
|---|
| 120 | 107 | SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; | 
|---|
| 121 |  | -} | 
|---|
| 122 |  | - | 
|---|
| 123 |  | -/* | 
|---|
| 124 |  | - * allocate buffers | 
|---|
| 125 |  | - */ | 
|---|
| 126 |  | -static int snd_pmac_pcm_hw_params(struct snd_pcm_substream *subs, | 
|---|
| 127 |  | -				  struct snd_pcm_hw_params *hw_params) | 
|---|
| 128 |  | -{ | 
|---|
| 129 |  | -	return snd_pcm_lib_malloc_pages(subs, params_buffer_bytes(hw_params)); | 
|---|
| 130 |  | -} | 
|---|
| 131 |  | - | 
|---|
| 132 |  | -/* | 
|---|
| 133 |  | - * release buffers | 
|---|
| 134 |  | - */ | 
|---|
| 135 |  | -static int snd_pmac_pcm_hw_free(struct snd_pcm_substream *subs) | 
|---|
| 136 |  | -{ | 
|---|
| 137 |  | -	snd_pcm_lib_free_pages(subs); | 
|---|
| 138 |  | -	return 0; | 
|---|
| 139 | 108 | } | 
|---|
| 140 | 109 |  | 
|---|
| 141 | 110 | /* | 
|---|
| .. | .. | 
|---|
| 257 | 226 | offset += rec->period_size; | 
|---|
| 258 | 227 | } | 
|---|
| 259 | 228 | /* make loop */ | 
|---|
| 260 |  | -	cp->command = cpu_to_le16(DBDMA_NOP + BR_ALWAYS); | 
|---|
|  | 229 | +	cp->command = cpu_to_le16(DBDMA_NOP | BR_ALWAYS); | 
|---|
| 261 | 230 | cp->cmd_dep = cpu_to_le32(rec->cmd.addr); | 
|---|
| 262 | 231 |  | 
|---|
| 263 | 232 | snd_pmac_dma_stop(rec); | 
|---|
| .. | .. | 
|---|
| 684 | 653 | static const struct snd_pcm_ops snd_pmac_playback_ops = { | 
|---|
| 685 | 654 | .open =		snd_pmac_playback_open, | 
|---|
| 686 | 655 | .close =	snd_pmac_playback_close, | 
|---|
| 687 |  | -	.ioctl =	snd_pcm_lib_ioctl, | 
|---|
| 688 |  | -	.hw_params =	snd_pmac_pcm_hw_params, | 
|---|
| 689 |  | -	.hw_free =	snd_pmac_pcm_hw_free, | 
|---|
| 690 | 656 | .prepare =	snd_pmac_playback_prepare, | 
|---|
| 691 | 657 | .trigger =	snd_pmac_playback_trigger, | 
|---|
| 692 | 658 | .pointer =	snd_pmac_playback_pointer, | 
|---|
| .. | .. | 
|---|
| 695 | 661 | static const struct snd_pcm_ops snd_pmac_capture_ops = { | 
|---|
| 696 | 662 | .open =		snd_pmac_capture_open, | 
|---|
| 697 | 663 | .close =	snd_pmac_capture_close, | 
|---|
| 698 |  | -	.ioctl =	snd_pcm_lib_ioctl, | 
|---|
| 699 |  | -	.hw_params =	snd_pmac_pcm_hw_params, | 
|---|
| 700 |  | -	.hw_free =	snd_pmac_pcm_hw_free, | 
|---|
| 701 | 664 | .prepare =	snd_pmac_capture_prepare, | 
|---|
| 702 | 665 | .trigger =	snd_pmac_capture_trigger, | 
|---|
| 703 | 666 | .pointer =	snd_pmac_capture_pointer, | 
|---|
| .. | .. | 
|---|
| 734 | 697 | chip->capture.cur_freqs = chip->freqs_ok; | 
|---|
| 735 | 698 |  | 
|---|
| 736 | 699 | /* preallocate 64k buffer */ | 
|---|
| 737 |  | -	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, | 
|---|
| 738 |  | -					      &chip->pdev->dev, | 
|---|
| 739 |  | -					      64 * 1024, 64 * 1024); | 
|---|
|  | 700 | +	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, | 
|---|
|  | 701 | +				       &chip->pdev->dev, | 
|---|
|  | 702 | +				       64 * 1024, 64 * 1024); | 
|---|
| 740 | 703 |  | 
|---|
| 741 | 704 | return 0; | 
|---|
| 742 | 705 | } | 
|---|
| .. | .. | 
|---|
| 763 | 726 | chip->extra_dma.cmds->xfer_status = cpu_to_le16(0); | 
|---|
| 764 | 727 | chip->extra_dma.cmds->cmd_dep = cpu_to_le32(chip->extra_dma.addr); | 
|---|
| 765 | 728 | chip->extra_dma.cmds->phy_addr = cpu_to_le32(addr); | 
|---|
| 766 |  | -	chip->extra_dma.cmds->command = cpu_to_le16(OUTPUT_MORE + BR_ALWAYS); | 
|---|
|  | 729 | +	chip->extra_dma.cmds->command = cpu_to_le16(OUTPUT_MORE | BR_ALWAYS); | 
|---|
| 767 | 730 | out_le32(&chip->awacs->control, | 
|---|
| 768 | 731 | (in_le32(&chip->awacs->control) & ~0x1f00) | 
|---|
| 769 | 732 | | (speed << 8)); | 
|---|
| .. | .. | 
|---|
| 908 | 871 |  | 
|---|
| 909 | 872 | /* if seems that Keylargo can't byte-swap  */ | 
|---|
| 910 | 873 | for (mio = chip->node->parent; mio; mio = mio->parent) { | 
|---|
| 911 |  | -		if (strcmp(mio->name, "mac-io") == 0) { | 
|---|
|  | 874 | +		if (of_node_name_eq(mio, "mac-io")) { | 
|---|
| 912 | 875 | if (of_device_is_compatible(mio, "Keylargo")) | 
|---|
| 913 | 876 | chip->can_byte_swap = 0; | 
|---|
| 914 | 877 | break; | 
|---|
| .. | .. | 
|---|
| 1141 | 1104 | return 0; | 
|---|
| 1142 | 1105 | } | 
|---|
| 1143 | 1106 |  | 
|---|
| 1144 |  | -static struct snd_kcontrol_new auto_mute_controls[] = { | 
|---|
|  | 1107 | +static const struct snd_kcontrol_new auto_mute_controls[] = { | 
|---|
| 1145 | 1108 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|---|
| 1146 | 1109 | .name = "Auto Mute Switch", | 
|---|
| 1147 | 1110 | .info = snd_pmac_boolean_mono_info, | 
|---|
| .. | .. | 
|---|
| 1180 | 1143 | int i, err; | 
|---|
| 1181 | 1144 | unsigned int irq; | 
|---|
| 1182 | 1145 | unsigned long ctrl_addr, txdma_addr, rxdma_addr; | 
|---|
| 1183 |  | -	static struct snd_device_ops ops = { | 
|---|
|  | 1146 | +	static const struct snd_device_ops ops = { | 
|---|
| 1184 | 1147 | .dev_free =	snd_pmac_dev_free, | 
|---|
| 1185 | 1148 | }; | 
|---|
| 1186 | 1149 |  | 
|---|
| .. | .. | 
|---|
| 1211 | 1174 | np = chip->node; | 
|---|
| 1212 | 1175 | chip->requested = 0; | 
|---|
| 1213 | 1176 | if (chip->is_k2) { | 
|---|
| 1214 |  | -		static char *rnames[] = { | 
|---|
|  | 1177 | +		static const char * const rnames[] = { | 
|---|
| 1215 | 1178 | "Sound Control", "Sound DMA" }; | 
|---|
| 1216 | 1179 | for (i = 0; i < 2; i ++) { | 
|---|
| 1217 | 1180 | if (of_address_to_resource(np->parent, i, | 
|---|
| .. | .. | 
|---|
| 1236 | 1199 | txdma_addr = chip->rsrc[1].start; | 
|---|
| 1237 | 1200 | rxdma_addr = txdma_addr + 0x100; | 
|---|
| 1238 | 1201 | } else { | 
|---|
| 1239 |  | -		static char *rnames[] = { | 
|---|
|  | 1202 | +		static const char * const rnames[] = { | 
|---|
| 1240 | 1203 | "Sound Control", "Sound Tx DMA", "Sound Rx DMA" }; | 
|---|
| 1241 | 1204 | for (i = 0; i < 3; i ++) { | 
|---|
| 1242 | 1205 | if (of_address_to_resource(np, i, | 
|---|
| .. | .. | 
|---|
| 1313 | 1276 | } else if (chip->is_pbook_G3) { | 
|---|
| 1314 | 1277 | struct device_node* mio; | 
|---|
| 1315 | 1278 | for (mio = chip->node->parent; mio; mio = mio->parent) { | 
|---|
| 1316 |  | -			if (strcmp(mio->name, "mac-io") == 0) { | 
|---|
|  | 1279 | +			if (of_node_name_eq(mio, "mac-io")) { | 
|---|
| 1317 | 1280 | struct resource r; | 
|---|
| 1318 | 1281 | if (of_address_to_resource(mio, 0, &r) == 0) | 
|---|
| 1319 | 1282 | chip->macio_base = | 
|---|
| .. | .. | 
|---|
| 1365 | 1328 | snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); | 
|---|
| 1366 | 1329 | if (chip->suspend) | 
|---|
| 1367 | 1330 | chip->suspend(chip); | 
|---|
| 1368 |  | -	snd_pcm_suspend_all(chip->pcm); | 
|---|
| 1369 | 1331 | spin_lock_irqsave(&chip->reg_lock, flags); | 
|---|
| 1370 | 1332 | snd_pmac_beep_stop(chip); | 
|---|
| 1371 | 1333 | spin_unlock_irqrestore(&chip->reg_lock, flags); | 
|---|