radeon/audio: consolidate audio_init() functions
[linux-2.6-block.git] / drivers / gpu / drm / radeon / radeon_audio.c
1 /*
2  * Copyright 2014 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Slava Grigorev <slava.grigorev@amd.com>
23  */
24
25 #include <drm/drmP.h>
26 #include "radeon.h"
27
28 void r600_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin,
29                 u8 enable_mask);
30 void dce6_audio_enable(struct radeon_device *rdev, struct r600_audio_pin *pin,
31                 u8 enable_mask);
32
33 static const u32 pin_offsets[7] =
34 {
35         (0x5e00 - 0x5e00),
36         (0x5e18 - 0x5e00),
37         (0x5e30 - 0x5e00),
38         (0x5e48 - 0x5e00),
39         (0x5e60 - 0x5e00),
40         (0x5e78 - 0x5e00),
41         (0x5e90 - 0x5e00),
42 };
43
44 static int radeon_audio_chipset_supported(struct radeon_device *rdev)
45 {
46         return ASIC_IS_DCE2(rdev) && !ASIC_IS_NODCE(rdev);
47 }
48
49 int radeon_audio_init(struct radeon_device *rdev)
50 {
51         int i;
52
53         if (!radeon_audio || !radeon_audio_chipset_supported(rdev))
54                 return 0;
55
56         rdev->audio.enabled = true;
57
58         if (ASIC_IS_DCE83(rdev))                /* KB: 2 streams, 3 endpoints */
59                 rdev->audio.num_pins = 3;
60         else if (ASIC_IS_DCE81(rdev))   /* KV: 4 streams, 7 endpoints */
61                 rdev->audio.num_pins = 7;
62         else if (ASIC_IS_DCE8(rdev))    /* BN/HW: 6 streams, 7 endpoints */
63                 rdev->audio.num_pins = 7;
64         else if (ASIC_IS_DCE64(rdev))   /* OL: 2 streams, 2 endpoints */
65                 rdev->audio.num_pins = 2;
66         else if (ASIC_IS_DCE61(rdev))   /* TN: 4 streams, 6 endpoints */
67                 rdev->audio.num_pins = 6;
68         else if (ASIC_IS_DCE6(rdev))    /* SI: 6 streams, 6 endpoints */
69                 rdev->audio.num_pins = 6;
70         else
71                 rdev->audio.num_pins = 1;
72
73         for (i = 0; i < rdev->audio.num_pins; i++) {
74                 rdev->audio.pin[i].channels = -1;
75                 rdev->audio.pin[i].rate = -1;
76                 rdev->audio.pin[i].bits_per_sample = -1;
77                 rdev->audio.pin[i].status_bits = 0;
78                 rdev->audio.pin[i].category_code = 0;
79                 rdev->audio.pin[i].connected = false;
80                 rdev->audio.pin[i].offset = pin_offsets[i];
81                 rdev->audio.pin[i].id = i;
82                 /* disable audio.  it will be set up later */
83                 if (ASIC_IS_DCE6(rdev))
84                         dce6_audio_enable(rdev, &rdev->audio.pin[i], false);
85                 else
86                         r600_audio_enable(rdev, &rdev->audio.pin[i], false);
87         }
88
89         return 0;
90 }