···11-/*22- * Copyright 2008 Advanced Micro Devices, Inc.33- * Copyright 2008 Red Hat Inc.44- * Copyright 2009 Christian König.55- *66- * Permission is hereby granted, free of charge, to any person obtaining a77- * copy of this software and associated documentation files (the "Software"),88- * to deal in the Software without restriction, including without limitation99- * the rights to use, copy, modify, merge, publish, distribute, sublicense,1010- * and/or sell copies of the Software, and to permit persons to whom the1111- * Software is furnished to do so, subject to the following conditions:1212- *1313- * The above copyright notice and this permission notice shall be included in1414- * all copies or substantial portions of the Software.1515- *1616- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1717- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1818- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1919- * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR2020- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,2121- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2222- * OTHER DEALINGS IN THE SOFTWARE.2323- *2424- * Authors: Christian König2525- */2626-#include <drm/drmP.h>2727-#include "radeon.h"2828-#include "radeon_reg.h"2929-#include "radeon_asic.h"3030-#include "atom.h"3131-3232-/*3333- * check if the chipset is supported3434- */3535-static int r600_audio_chipset_supported(struct radeon_device *rdev)3636-{3737- return ASIC_IS_DCE2(rdev) && !ASIC_IS_NODCE(rdev);3838-}3939-4040-struct r600_audio_pin r600_audio_status(struct radeon_device *rdev)4141-{4242- struct r600_audio_pin status;4343- uint32_t value;4444-4545- value = RREG32(R600_AUDIO_RATE_BPS_CHANNEL);4646-4747- /* number of channels */4848- status.channels = (value & 0x7) + 1;4949-5050- /* bits per sample */5151- switch ((value & 0xF0) >> 4) {5252- case 0x0:5353- status.bits_per_sample = 8;5454- break;5555- case 0x1:5656- status.bits_per_sample = 16;5757- break;5858- case 0x2:5959- status.bits_per_sample = 20;6060- break;6161- case 0x3:6262- status.bits_per_sample = 24;6363- break;6464- case 0x4:6565- status.bits_per_sample = 32;6666- break;6767- default:6868- dev_err(rdev->dev, "Unknown bits per sample 0x%x, using 16\n",6969- (int)value);7070- status.bits_per_sample = 16;7171- }7272-7373- /* current sampling rate in HZ */7474- if (value & 0x4000)7575- status.rate = 44100;7676- else7777- status.rate = 48000;7878- status.rate *= ((value >> 11) & 0x7) + 1;7979- status.rate /= ((value >> 8) & 0x7) + 1;8080-8181- value = RREG32(R600_AUDIO_STATUS_BITS);8282-8383- /* iec 60958 status bits */8484- status.status_bits = value & 0xff;8585-8686- /* iec 60958 category code */8787- status.category_code = (value >> 8) & 0xff;8888-8989- return status;9090-}9191-9292-/*9393- * update all hdmi interfaces with current audio parameters9494- */9595-void r600_audio_update_hdmi(struct work_struct *work)9696-{9797- struct radeon_device *rdev = container_of(work, struct radeon_device,9898- audio_work);9999- struct drm_device *dev = rdev->ddev;100100- struct r600_audio_pin audio_status = r600_audio_status(rdev);101101- struct drm_encoder *encoder;102102- bool changed = false;103103-104104- if (rdev->audio.pin[0].channels != audio_status.channels ||105105- rdev->audio.pin[0].rate != audio_status.rate ||106106- rdev->audio.pin[0].bits_per_sample != audio_status.bits_per_sample ||107107- rdev->audio.pin[0].status_bits != audio_status.status_bits ||108108- rdev->audio.pin[0].category_code != audio_status.category_code) {109109- rdev->audio.pin[0] = audio_status;110110- changed = true;111111- }112112-113113- list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {114114- if (!radeon_encoder_is_digital(encoder))115115- continue;116116- if (changed || r600_hdmi_buffer_status_changed(encoder))117117- r600_hdmi_update_audio_settings(encoder);118118- }119119-}120120-121121-/* enable the audio stream */122122-void r600_audio_enable(struct radeon_device *rdev,123123- struct r600_audio_pin *pin,124124- bool enable)125125-{126126- u32 value = 0;127127-128128- if (!pin)129129- return;130130-131131- if (ASIC_IS_DCE4(rdev)) {132132- if (enable) {133133- value |= 0x81000000; /* Required to enable audio */134134- value |= 0x0e1000f0; /* fglrx sets that too */135135- }136136- WREG32(EVERGREEN_AUDIO_ENABLE, value);137137- } else {138138- WREG32_P(R600_AUDIO_ENABLE,139139- enable ? 0x81000000 : 0x0, ~0x81000000);140140- }141141-}142142-143143-/*144144- * initialize the audio vars145145- */146146-int r600_audio_init(struct radeon_device *rdev)147147-{148148- if (!radeon_audio || !r600_audio_chipset_supported(rdev))149149- return 0;150150-151151- rdev->audio.enabled = true;152152-153153- rdev->audio.num_pins = 1;154154- rdev->audio.pin[0].channels = -1;155155- rdev->audio.pin[0].rate = -1;156156- rdev->audio.pin[0].bits_per_sample = -1;157157- rdev->audio.pin[0].status_bits = 0;158158- rdev->audio.pin[0].category_code = 0;159159- rdev->audio.pin[0].id = 0;160160- /* disable audio. it will be set up later */161161- r600_audio_enable(rdev, &rdev->audio.pin[0], false);162162-163163- return 0;164164-}165165-166166-/*167167- * release the audio timer168168- * TODO: How to do this correctly on SMP systems?169169- */170170-void r600_audio_fini(struct radeon_device *rdev)171171-{172172- if (!rdev->audio.enabled)173173- return;174174-175175- r600_audio_enable(rdev, &rdev->audio.pin[0], false);176176-177177- rdev->audio.enabled = false;178178-}179179-180180-struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev)181181-{182182- /* only one pin on 6xx-NI */183183- return &rdev->audio.pin[0];184184-}
+154
drivers/gpu/drm/radeon/r600_hdmi.c
···727273737474/*7575+ * check if the chipset is supported7676+ */7777+static int r600_audio_chipset_supported(struct radeon_device *rdev)7878+{7979+ return ASIC_IS_DCE2(rdev) && !ASIC_IS_NODCE(rdev);8080+}8181+8282+static struct r600_audio_pin r600_audio_status(struct radeon_device *rdev)8383+{8484+ struct r600_audio_pin status;8585+ uint32_t value;8686+8787+ value = RREG32(R600_AUDIO_RATE_BPS_CHANNEL);8888+8989+ /* number of channels */9090+ status.channels = (value & 0x7) + 1;9191+9292+ /* bits per sample */9393+ switch ((value & 0xF0) >> 4) {9494+ case 0x0:9595+ status.bits_per_sample = 8;9696+ break;9797+ case 0x1:9898+ status.bits_per_sample = 16;9999+ break;100100+ case 0x2:101101+ status.bits_per_sample = 20;102102+ break;103103+ case 0x3:104104+ status.bits_per_sample = 24;105105+ break;106106+ case 0x4:107107+ status.bits_per_sample = 32;108108+ break;109109+ default:110110+ dev_err(rdev->dev, "Unknown bits per sample 0x%x, using 16\n",111111+ (int)value);112112+ status.bits_per_sample = 16;113113+ }114114+115115+ /* current sampling rate in HZ */116116+ if (value & 0x4000)117117+ status.rate = 44100;118118+ else119119+ status.rate = 48000;120120+ status.rate *= ((value >> 11) & 0x7) + 1;121121+ status.rate /= ((value >> 8) & 0x7) + 1;122122+123123+ value = RREG32(R600_AUDIO_STATUS_BITS);124124+125125+ /* iec 60958 status bits */126126+ status.status_bits = value & 0xff;127127+128128+ /* iec 60958 category code */129129+ status.category_code = (value >> 8) & 0xff;130130+131131+ return status;132132+}133133+134134+/*135135+ * update all hdmi interfaces with current audio parameters136136+ */137137+void r600_audio_update_hdmi(struct work_struct *work)138138+{139139+ struct radeon_device *rdev = container_of(work, struct radeon_device,140140+ audio_work);141141+ struct drm_device *dev = rdev->ddev;142142+ struct r600_audio_pin audio_status = r600_audio_status(rdev);143143+ struct drm_encoder *encoder;144144+ bool changed = false;145145+146146+ if (rdev->audio.pin[0].channels != audio_status.channels ||147147+ rdev->audio.pin[0].rate != audio_status.rate ||148148+ rdev->audio.pin[0].bits_per_sample != audio_status.bits_per_sample ||149149+ rdev->audio.pin[0].status_bits != audio_status.status_bits ||150150+ rdev->audio.pin[0].category_code != audio_status.category_code) {151151+ rdev->audio.pin[0] = audio_status;152152+ changed = true;153153+ }154154+155155+ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {156156+ if (!radeon_encoder_is_digital(encoder))157157+ continue;158158+ if (changed || r600_hdmi_buffer_status_changed(encoder))159159+ r600_hdmi_update_audio_settings(encoder);160160+ }161161+}162162+163163+/* enable the audio stream */164164+void r600_audio_enable(struct radeon_device *rdev,165165+ struct r600_audio_pin *pin,166166+ bool enable)167167+{168168+ u32 value = 0;169169+170170+ if (!pin)171171+ return;172172+173173+ if (ASIC_IS_DCE4(rdev)) {174174+ if (enable) {175175+ value |= 0x81000000; /* Required to enable audio */176176+ value |= 0x0e1000f0; /* fglrx sets that too */177177+ }178178+ WREG32(EVERGREEN_AUDIO_ENABLE, value);179179+ } else {180180+ WREG32_P(R600_AUDIO_ENABLE,181181+ enable ? 0x81000000 : 0x0, ~0x81000000);182182+ }183183+}184184+185185+/*186186+ * initialize the audio vars187187+ */188188+int r600_audio_init(struct radeon_device *rdev)189189+{190190+ if (!radeon_audio || !r600_audio_chipset_supported(rdev))191191+ return 0;192192+193193+ rdev->audio.enabled = true;194194+195195+ rdev->audio.num_pins = 1;196196+ rdev->audio.pin[0].channels = -1;197197+ rdev->audio.pin[0].rate = -1;198198+ rdev->audio.pin[0].bits_per_sample = -1;199199+ rdev->audio.pin[0].status_bits = 0;200200+ rdev->audio.pin[0].category_code = 0;201201+ rdev->audio.pin[0].id = 0;202202+ /* disable audio. it will be set up later */203203+ r600_audio_enable(rdev, &rdev->audio.pin[0], false);204204+205205+ return 0;206206+}207207+208208+/*209209+ * release the audio timer210210+ * TODO: How to do this correctly on SMP systems?211211+ */212212+void r600_audio_fini(struct radeon_device *rdev)213213+{214214+ if (!rdev->audio.enabled)215215+ return;216216+217217+ r600_audio_enable(rdev, &rdev->audio.pin[0], false);218218+219219+ rdev->audio.enabled = false;220220+}221221+222222+struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev)223223+{224224+ /* only one pin on 6xx-NI */225225+ return &rdev->audio.pin[0];226226+}227227+228228+/*75229 * calculate CTS and N values if they are not found in the table76230 */77231static void r600_hdmi_calc_cts(uint32_t clock, int *CTS, int *N, int freq)