perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / drivers / media / platform / s5p-cec / exynos_hdmi_cecctrl.c
blob146ae6f25cdbb1eee53837aa1ea28c503163ed28
1 /* drivers/media/platform/s5p-cec/exynos_hdmi_cecctrl.c
3 * Copyright (c) 2009, 2014 Samsung Electronics
4 * http://www.samsung.com/
6 * cec ftn file for Samsung TVOUT driver
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/io.h>
14 #include <linux/device.h>
16 #include "exynos_hdmi_cec.h"
17 #include "regs-cec.h"
19 #define S5P_HDMI_FIN 24000000
20 #define CEC_DIV_RATIO 320000
22 #define CEC_MESSAGE_BROADCAST_MASK 0x0F
23 #define CEC_MESSAGE_BROADCAST 0x0F
24 #define CEC_FILTER_THRESHOLD 0x15
26 void s5p_cec_set_divider(struct s5p_cec_dev *cec)
28 u32 div_ratio, div_val;
29 unsigned int reg;
31 div_ratio = S5P_HDMI_FIN / CEC_DIV_RATIO - 1;
33 if (regmap_read(cec->pmu, EXYNOS_HDMI_PHY_CONTROL, &reg)) {
34 dev_err(cec->dev, "failed to read phy control\n");
35 return;
38 reg = (reg & ~(0x3FF << 16)) | (div_ratio << 16);
40 if (regmap_write(cec->pmu, EXYNOS_HDMI_PHY_CONTROL, reg)) {
41 dev_err(cec->dev, "failed to write phy control\n");
42 return;
45 div_val = CEC_DIV_RATIO * 0.00005 - 1;
47 writeb(0x0, cec->reg + S5P_CEC_DIVISOR_3);
48 writeb(0x0, cec->reg + S5P_CEC_DIVISOR_2);
49 writeb(0x0, cec->reg + S5P_CEC_DIVISOR_1);
50 writeb(div_val, cec->reg + S5P_CEC_DIVISOR_0);
53 void s5p_cec_enable_rx(struct s5p_cec_dev *cec)
55 u8 reg;
57 reg = readb(cec->reg + S5P_CEC_RX_CTRL);
58 reg |= S5P_CEC_RX_CTRL_ENABLE;
59 writeb(reg, cec->reg + S5P_CEC_RX_CTRL);
62 void s5p_cec_mask_rx_interrupts(struct s5p_cec_dev *cec)
64 u8 reg;
66 reg = readb(cec->reg + S5P_CEC_IRQ_MASK);
67 reg |= S5P_CEC_IRQ_RX_DONE;
68 reg |= S5P_CEC_IRQ_RX_ERROR;
69 writeb(reg, cec->reg + S5P_CEC_IRQ_MASK);
72 void s5p_cec_unmask_rx_interrupts(struct s5p_cec_dev *cec)
74 u8 reg;
76 reg = readb(cec->reg + S5P_CEC_IRQ_MASK);
77 reg &= ~S5P_CEC_IRQ_RX_DONE;
78 reg &= ~S5P_CEC_IRQ_RX_ERROR;
79 writeb(reg, cec->reg + S5P_CEC_IRQ_MASK);
82 void s5p_cec_mask_tx_interrupts(struct s5p_cec_dev *cec)
84 u8 reg;
86 reg = readb(cec->reg + S5P_CEC_IRQ_MASK);
87 reg |= S5P_CEC_IRQ_TX_DONE;
88 reg |= S5P_CEC_IRQ_TX_ERROR;
89 writeb(reg, cec->reg + S5P_CEC_IRQ_MASK);
92 void s5p_cec_unmask_tx_interrupts(struct s5p_cec_dev *cec)
94 u8 reg;
96 reg = readb(cec->reg + S5P_CEC_IRQ_MASK);
97 reg &= ~S5P_CEC_IRQ_TX_DONE;
98 reg &= ~S5P_CEC_IRQ_TX_ERROR;
99 writeb(reg, cec->reg + S5P_CEC_IRQ_MASK);
102 void s5p_cec_reset(struct s5p_cec_dev *cec)
104 u8 reg;
106 writeb(S5P_CEC_RX_CTRL_RESET, cec->reg + S5P_CEC_RX_CTRL);
107 writeb(S5P_CEC_TX_CTRL_RESET, cec->reg + S5P_CEC_TX_CTRL);
109 reg = readb(cec->reg + 0xc4);
110 reg &= ~0x1;
111 writeb(reg, cec->reg + 0xc4);
114 void s5p_cec_tx_reset(struct s5p_cec_dev *cec)
116 writeb(S5P_CEC_TX_CTRL_RESET, cec->reg + S5P_CEC_TX_CTRL);
119 void s5p_cec_rx_reset(struct s5p_cec_dev *cec)
121 u8 reg;
123 writeb(S5P_CEC_RX_CTRL_RESET, cec->reg + S5P_CEC_RX_CTRL);
125 reg = readb(cec->reg + 0xc4);
126 reg &= ~0x1;
127 writeb(reg, cec->reg + 0xc4);
130 void s5p_cec_threshold(struct s5p_cec_dev *cec)
132 writeb(CEC_FILTER_THRESHOLD, cec->reg + S5P_CEC_RX_FILTER_TH);
133 writeb(0, cec->reg + S5P_CEC_RX_FILTER_CTRL);
136 void s5p_cec_copy_packet(struct s5p_cec_dev *cec, char *data,
137 size_t count, u8 retries)
139 int i = 0;
140 u8 reg;
142 while (i < count) {
143 writeb(data[i], cec->reg + (S5P_CEC_TX_BUFF0 + (i * 4)));
144 i++;
147 writeb(count, cec->reg + S5P_CEC_TX_BYTES);
148 reg = readb(cec->reg + S5P_CEC_TX_CTRL);
149 reg |= S5P_CEC_TX_CTRL_START;
150 reg &= ~0x70;
151 reg |= retries << 4;
153 if ((data[0] & CEC_MESSAGE_BROADCAST_MASK) == CEC_MESSAGE_BROADCAST) {
154 dev_dbg(cec->dev, "Broadcast");
155 reg |= S5P_CEC_TX_CTRL_BCAST;
156 } else {
157 dev_dbg(cec->dev, "No Broadcast");
158 reg &= ~S5P_CEC_TX_CTRL_BCAST;
161 writeb(reg, cec->reg + S5P_CEC_TX_CTRL);
162 dev_dbg(cec->dev, "cec-tx: cec count (%zu): %*ph", count,
163 (int)count, data);
166 void s5p_cec_set_addr(struct s5p_cec_dev *cec, u32 addr)
168 writeb(addr & 0x0F, cec->reg + S5P_CEC_LOGIC_ADDR);
171 u32 s5p_cec_get_status(struct s5p_cec_dev *cec)
173 u32 status = 0;
175 status = readb(cec->reg + S5P_CEC_STATUS_0) & 0xf;
176 status |= (readb(cec->reg + S5P_CEC_TX_STAT1) & 0xf) << 4;
177 status |= readb(cec->reg + S5P_CEC_STATUS_1) << 8;
178 status |= readb(cec->reg + S5P_CEC_STATUS_2) << 16;
179 status |= readb(cec->reg + S5P_CEC_STATUS_3) << 24;
181 dev_dbg(cec->dev, "status = 0x%x!\n", status);
183 return status;
186 void s5p_clr_pending_tx(struct s5p_cec_dev *cec)
188 writeb(S5P_CEC_IRQ_TX_DONE | S5P_CEC_IRQ_TX_ERROR,
189 cec->reg + S5P_CEC_IRQ_CLEAR);
192 void s5p_clr_pending_rx(struct s5p_cec_dev *cec)
194 writeb(S5P_CEC_IRQ_RX_DONE | S5P_CEC_IRQ_RX_ERROR,
195 cec->reg + S5P_CEC_IRQ_CLEAR);
198 void s5p_cec_get_rx_buf(struct s5p_cec_dev *cec, u32 size, u8 *buffer)
200 u32 i = 0;
201 char debug[40];
203 while (i < size) {
204 buffer[i] = readb(cec->reg + S5P_CEC_RX_BUFF0 + (i * 4));
205 sprintf(debug + i * 2, "%02x ", buffer[i]);
206 i++;
208 dev_dbg(cec->dev, "cec-rx: cec size(%d): %s", size, debug);