aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i2c
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@arm.linux.org.uk>2014-02-07 14:17:21 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2014-08-01 12:16:54 -0400
commita8f4d4d63739e4bca459ff40636f1d9e4b7ef5e6 (patch)
tree74e5d31512e939057ad0845a4106bd40e8055d05 /drivers/gpu/drm/i2c
parentde4bf3d51fe38eaf90cb587e4eae1f3f0e056a54 (diff)
drm/i2c: tda998x: allow re-use of tda998x support code
Re-jig the TDA998x code so that we separate the functionality from the drm slave encoder implementation. In several places, this is pretty clearly the correct thing to do, because we can avoid repetitively having to convert from the drm_encoder to the TDA998x private structure, particularly with the driver internal functions. The main motivation behind this change is to allow the code to be re-used with a standard drm_encoder and drm_connector implementation based on the component helpers, rather than the slave_encoder system. The addition of this will be in the following patch. We keep the slave_encoder interface as there are existing users of this; we need to give them time to convert and test. Tested-by: Darren Etheridge <detheridge@ti.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/gpu/drm/i2c')
-rw-r--r--drivers/gpu/drm/i2c/tda998x_drv.c179
1 files changed, 110 insertions, 69 deletions
diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
index 5a738ad0c241..64e120c5299a 100644
--- a/drivers/gpu/drm/i2c/tda998x_drv.c
+++ b/drivers/gpu/drm/i2c/tda998x_drv.c
@@ -730,12 +730,9 @@ tda998x_configure_audio(struct tda998x_priv *priv,
730 730
731/* DRM encoder functions */ 731/* DRM encoder functions */
732 732
733static void 733static void tda998x_encoder_set_config(struct tda998x_priv *priv,
734tda998x_encoder_set_config(struct drm_encoder *encoder, void *params) 734 const struct tda998x_encoder_params *p)
735{ 735{
736 struct tda998x_priv *priv = to_tda998x_priv(encoder);
737 struct tda998x_encoder_params *p = params;
738
739 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(p->swap_a) | 736 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(p->swap_a) |
740 (p->mirr_a ? VIP_CNTRL_0_MIRR_A : 0) | 737 (p->mirr_a ? VIP_CNTRL_0_MIRR_A : 0) |
741 VIP_CNTRL_0_SWAP_B(p->swap_b) | 738 VIP_CNTRL_0_SWAP_B(p->swap_b) |
@@ -752,11 +749,8 @@ tda998x_encoder_set_config(struct drm_encoder *encoder, void *params)
752 priv->params = *p; 749 priv->params = *p;
753} 750}
754 751
755static void 752static void tda998x_encoder_dpms(struct tda998x_priv *priv, int mode)
756tda998x_encoder_dpms(struct drm_encoder *encoder, int mode)
757{ 753{
758 struct tda998x_priv *priv = to_tda998x_priv(encoder);
759
760 /* we only care about on or off: */ 754 /* we only care about on or off: */
761 if (mode != DRM_MODE_DPMS_ON) 755 if (mode != DRM_MODE_DPMS_ON)
762 mode = DRM_MODE_DPMS_OFF; 756 mode = DRM_MODE_DPMS_OFF;
@@ -806,9 +800,8 @@ tda998x_encoder_mode_fixup(struct drm_encoder *encoder,
806 return true; 800 return true;
807} 801}
808 802
809static int 803static int tda998x_encoder_mode_valid(struct tda998x_priv *priv,
810tda998x_encoder_mode_valid(struct drm_encoder *encoder, 804 struct drm_display_mode *mode)
811 struct drm_display_mode *mode)
812{ 805{
813 if (mode->clock > 150000) 806 if (mode->clock > 150000)
814 return MODE_CLOCK_HIGH; 807 return MODE_CLOCK_HIGH;
@@ -820,11 +813,10 @@ tda998x_encoder_mode_valid(struct drm_encoder *encoder,
820} 813}
821 814
822static void 815static void
823tda998x_encoder_mode_set(struct drm_encoder *encoder, 816tda998x_encoder_mode_set(struct tda998x_priv *priv,
824 struct drm_display_mode *mode, 817 struct drm_display_mode *mode,
825 struct drm_display_mode *adjusted_mode) 818 struct drm_display_mode *adjusted_mode)
826{ 819{
827 struct tda998x_priv *priv = to_tda998x_priv(encoder);
828 uint16_t ref_pix, ref_line, n_pix, n_line; 820 uint16_t ref_pix, ref_line, n_pix, n_line;
829 uint16_t hs_pix_s, hs_pix_e; 821 uint16_t hs_pix_s, hs_pix_e;
830 uint16_t vs1_pix_s, vs1_pix_e, vs1_line_s, vs1_line_e; 822 uint16_t vs1_pix_s, vs1_pix_e, vs1_line_s, vs1_line_e;
@@ -1012,20 +1004,16 @@ tda998x_encoder_mode_set(struct drm_encoder *encoder,
1012} 1004}
1013 1005
1014static enum drm_connector_status 1006static enum drm_connector_status
1015tda998x_encoder_detect(struct drm_encoder *encoder, 1007tda998x_encoder_detect(struct tda998x_priv *priv)
1016 struct drm_connector *connector)
1017{ 1008{
1018 struct tda998x_priv *priv = to_tda998x_priv(encoder);
1019 uint8_t val = cec_read(priv, REG_CEC_RXSHPDLEV); 1009 uint8_t val = cec_read(priv, REG_CEC_RXSHPDLEV);
1020 1010
1021 return (val & CEC_RXSHPDLEV_HPD) ? connector_status_connected : 1011 return (val & CEC_RXSHPDLEV_HPD) ? connector_status_connected :
1022 connector_status_disconnected; 1012 connector_status_disconnected;
1023} 1013}
1024 1014
1025static int 1015static int read_edid_block(struct tda998x_priv *priv, uint8_t *buf, int blk)
1026read_edid_block(struct drm_encoder *encoder, uint8_t *buf, int blk)
1027{ 1016{
1028 struct tda998x_priv *priv = to_tda998x_priv(encoder);
1029 uint8_t offset, segptr; 1017 uint8_t offset, segptr;
1030 int ret, i; 1018 int ret, i;
1031 1019
@@ -1079,10 +1067,8 @@ read_edid_block(struct drm_encoder *encoder, uint8_t *buf, int blk)
1079 return 0; 1067 return 0;
1080} 1068}
1081 1069
1082static uint8_t * 1070static uint8_t *do_get_edid(struct tda998x_priv *priv)
1083do_get_edid(struct drm_encoder *encoder)
1084{ 1071{
1085 struct tda998x_priv *priv = to_tda998x_priv(encoder);
1086 int j, valid_extensions = 0; 1072 int j, valid_extensions = 0;
1087 uint8_t *block, *new; 1073 uint8_t *block, *new;
1088 bool print_bad_edid = drm_debug & DRM_UT_KMS; 1074 bool print_bad_edid = drm_debug & DRM_UT_KMS;
@@ -1094,7 +1080,7 @@ do_get_edid(struct drm_encoder *encoder)
1094 reg_clear(priv, REG_TX4, TX4_PD_RAM); 1080 reg_clear(priv, REG_TX4, TX4_PD_RAM);
1095 1081
1096 /* base block fetch */ 1082 /* base block fetch */
1097 if (read_edid_block(encoder, block, 0)) 1083 if (read_edid_block(priv, block, 0))
1098 goto fail; 1084 goto fail;
1099 1085
1100 if (!drm_edid_block_valid(block, 0, print_bad_edid)) 1086 if (!drm_edid_block_valid(block, 0, print_bad_edid))
@@ -1111,7 +1097,7 @@ do_get_edid(struct drm_encoder *encoder)
1111 1097
1112 for (j = 1; j <= block[0x7e]; j++) { 1098 for (j = 1; j <= block[0x7e]; j++) {
1113 uint8_t *ext_block = block + (valid_extensions + 1) * EDID_LENGTH; 1099 uint8_t *ext_block = block + (valid_extensions + 1) * EDID_LENGTH;
1114 if (read_edid_block(encoder, ext_block, j)) 1100 if (read_edid_block(priv, ext_block, j))
1115 goto fail; 1101 goto fail;
1116 1102
1117 if (!drm_edid_block_valid(ext_block, j, print_bad_edid)) 1103 if (!drm_edid_block_valid(ext_block, j, print_bad_edid))
@@ -1144,11 +1130,10 @@ fail:
1144} 1130}
1145 1131
1146static int 1132static int
1147tda998x_encoder_get_modes(struct drm_encoder *encoder, 1133tda998x_encoder_get_modes(struct tda998x_priv *priv,
1148 struct drm_connector *connector) 1134 struct drm_connector *connector)
1149{ 1135{
1150 struct tda998x_priv *priv = to_tda998x_priv(encoder); 1136 struct edid *edid = (struct edid *)do_get_edid(priv);
1151 struct edid *edid = (struct edid *)do_get_edid(encoder);
1152 int n = 0; 1137 int n = 0;
1153 1138
1154 if (edid) { 1139 if (edid) {
@@ -1161,18 +1146,14 @@ tda998x_encoder_get_modes(struct drm_encoder *encoder,
1161 return n; 1146 return n;
1162} 1147}
1163 1148
1164static int 1149static void tda998x_encoder_set_polling(struct tda998x_priv *priv,
1165tda998x_encoder_create_resources(struct drm_encoder *encoder, 1150 struct drm_connector *connector)
1166 struct drm_connector *connector)
1167{ 1151{
1168 struct tda998x_priv *priv = to_tda998x_priv(encoder);
1169
1170 if (priv->hdmi->irq) 1152 if (priv->hdmi->irq)
1171 connector->polled = DRM_CONNECTOR_POLL_HPD; 1153 connector->polled = DRM_CONNECTOR_POLL_HPD;
1172 else 1154 else
1173 connector->polled = DRM_CONNECTOR_POLL_CONNECT | 1155 connector->polled = DRM_CONNECTOR_POLL_CONNECT |
1174 DRM_CONNECTOR_POLL_DISCONNECT; 1156 DRM_CONNECTOR_POLL_DISCONNECT;
1175 return 0;
1176} 1157}
1177 1158
1178static int 1159static int
@@ -1185,11 +1166,8 @@ tda998x_encoder_set_property(struct drm_encoder *encoder,
1185 return 0; 1166 return 0;
1186} 1167}
1187 1168
1188static void 1169static void tda998x_destroy(struct tda998x_priv *priv)
1189tda998x_encoder_destroy(struct drm_encoder *encoder)
1190{ 1170{
1191 struct tda998x_priv *priv = to_tda998x_priv(encoder);
1192
1193 /* disable all IRQs and free the IRQ handler */ 1171 /* disable all IRQs and free the IRQ handler */
1194 cec_write(priv, REG_CEC_RXSHPDINTENA, 0); 1172 cec_write(priv, REG_CEC_RXSHPDINTENA, 0);
1195 reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD); 1173 reg_clear(priv, REG_INT_FLAGS_2, INT_FLAGS_2_EDID_BLK_RD);
@@ -1198,22 +1176,77 @@ tda998x_encoder_destroy(struct drm_encoder *encoder)
1198 1176
1199 if (priv->cec) 1177 if (priv->cec)
1200 i2c_unregister_device(priv->cec); 1178 i2c_unregister_device(priv->cec);
1179}
1180
1181/* Slave encoder support */
1182
1183static void
1184tda998x_encoder_slave_set_config(struct drm_encoder *encoder, void *params)
1185{
1186 tda998x_encoder_set_config(to_tda998x_priv(encoder), params);
1187}
1188
1189static void tda998x_encoder_slave_destroy(struct drm_encoder *encoder)
1190{
1191 struct tda998x_priv *priv = to_tda998x_priv(encoder);
1192
1193 tda998x_destroy(priv);
1201 drm_i2c_encoder_destroy(encoder); 1194 drm_i2c_encoder_destroy(encoder);
1202 kfree(priv); 1195 kfree(priv);
1203} 1196}
1204 1197
1205static struct drm_encoder_slave_funcs tda998x_encoder_funcs = { 1198static void tda998x_encoder_slave_dpms(struct drm_encoder *encoder, int mode)
1206 .set_config = tda998x_encoder_set_config, 1199{
1207 .destroy = tda998x_encoder_destroy, 1200 tda998x_encoder_dpms(to_tda998x_priv(encoder), mode);
1208 .dpms = tda998x_encoder_dpms, 1201}
1202
1203static int tda998x_encoder_slave_mode_valid(struct drm_encoder *encoder,
1204 struct drm_display_mode *mode)
1205{
1206 return tda998x_encoder_mode_valid(to_tda998x_priv(encoder), mode);
1207}
1208
1209static void
1210tda998x_encoder_slave_mode_set(struct drm_encoder *encoder,
1211 struct drm_display_mode *mode,
1212 struct drm_display_mode *adjusted_mode)
1213{
1214 tda998x_encoder_mode_set(to_tda998x_priv(encoder), mode, adjusted_mode);
1215}
1216
1217static enum drm_connector_status
1218tda998x_encoder_slave_detect(struct drm_encoder *encoder,
1219 struct drm_connector *connector)
1220{
1221 return tda998x_encoder_detect(to_tda998x_priv(encoder));
1222}
1223
1224static int tda998x_encoder_slave_get_modes(struct drm_encoder *encoder,
1225 struct drm_connector *connector)
1226{
1227 return tda998x_encoder_get_modes(to_tda998x_priv(encoder), connector);
1228}
1229
1230static int
1231tda998x_encoder_slave_create_resources(struct drm_encoder *encoder,
1232 struct drm_connector *connector)
1233{
1234 tda998x_encoder_set_polling(to_tda998x_priv(encoder), connector);
1235 return 0;
1236}
1237
1238static struct drm_encoder_slave_funcs tda998x_encoder_slave_funcs = {
1239 .set_config = tda998x_encoder_slave_set_config,
1240 .destroy = tda998x_encoder_slave_destroy,
1241 .dpms = tda998x_encoder_slave_dpms,
1209 .save = tda998x_encoder_save, 1242 .save = tda998x_encoder_save,
1210 .restore = tda998x_encoder_restore, 1243 .restore = tda998x_encoder_restore,
1211 .mode_fixup = tda998x_encoder_mode_fixup, 1244 .mode_fixup = tda998x_encoder_mode_fixup,
1212 .mode_valid = tda998x_encoder_mode_valid, 1245 .mode_valid = tda998x_encoder_slave_mode_valid,
1213 .mode_set = tda998x_encoder_mode_set, 1246 .mode_set = tda998x_encoder_slave_mode_set,
1214 .detect = tda998x_encoder_detect, 1247 .detect = tda998x_encoder_slave_detect,
1215 .get_modes = tda998x_encoder_get_modes, 1248 .get_modes = tda998x_encoder_slave_get_modes,
1216 .create_resources = tda998x_encoder_create_resources, 1249 .create_resources = tda998x_encoder_slave_create_resources,
1217 .set_property = tda998x_encoder_set_property, 1250 .set_property = tda998x_encoder_set_property,
1218}; 1251};
1219 1252
@@ -1231,20 +1264,12 @@ tda998x_remove(struct i2c_client *client)
1231 return 0; 1264 return 0;
1232} 1265}
1233 1266
1234static int 1267static int tda998x_create(struct i2c_client *client, struct tda998x_priv *priv)
1235tda998x_encoder_init(struct i2c_client *client,
1236 struct drm_device *dev,
1237 struct drm_encoder_slave *encoder_slave)
1238{ 1268{
1239 struct tda998x_priv *priv;
1240 struct device_node *np = client->dev.of_node; 1269 struct device_node *np = client->dev.of_node;
1241 u32 video; 1270 u32 video;
1242 int rev_lo, rev_hi, ret; 1271 int rev_lo, rev_hi, ret;
1243 1272
1244 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1245 if (!priv)
1246 return -ENOMEM;
1247
1248 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(2) | VIP_CNTRL_0_SWAP_B(3); 1273 priv->vip_cntrl_0 = VIP_CNTRL_0_SWAP_A(2) | VIP_CNTRL_0_SWAP_B(3);
1249 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1); 1274 priv->vip_cntrl_1 = VIP_CNTRL_1_SWAP_C(0) | VIP_CNTRL_1_SWAP_D(1);
1250 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5); 1275 priv->vip_cntrl_2 = VIP_CNTRL_2_SWAP_E(4) | VIP_CNTRL_2_SWAP_F(5);
@@ -1252,17 +1277,11 @@ tda998x_encoder_init(struct i2c_client *client,
1252 priv->current_page = 0xff; 1277 priv->current_page = 0xff;
1253 priv->hdmi = client; 1278 priv->hdmi = client;
1254 priv->cec = i2c_new_dummy(client->adapter, 0x34); 1279 priv->cec = i2c_new_dummy(client->adapter, 0x34);
1255 if (!priv->cec) { 1280 if (!priv->cec)
1256 kfree(priv);
1257 return -ENODEV; 1281 return -ENODEV;
1258 }
1259 1282
1260 priv->encoder = &encoder_slave->base;
1261 priv->dpms = DRM_MODE_DPMS_OFF; 1283 priv->dpms = DRM_MODE_DPMS_OFF;
1262 1284
1263 encoder_slave->slave_priv = priv;
1264 encoder_slave->slave_funcs = &tda998x_encoder_funcs;
1265
1266 /* wake up the device: */ 1285 /* wake up the device: */
1267 cec_write(priv, REG_CEC_ENAMODS, 1286 cec_write(priv, REG_CEC_ENAMODS,
1268 CEC_ENAMODS_EN_RXSENS | CEC_ENAMODS_EN_HDMI); 1287 CEC_ENAMODS_EN_RXSENS | CEC_ENAMODS_EN_HDMI);
@@ -1365,12 +1384,34 @@ fail:
1365 */ 1384 */
1366 if (priv->cec) 1385 if (priv->cec)
1367 i2c_unregister_device(priv->cec); 1386 i2c_unregister_device(priv->cec);
1368 kfree(priv);
1369 encoder_slave->slave_priv = NULL;
1370 encoder_slave->slave_funcs = NULL;
1371 return -ENXIO; 1387 return -ENXIO;
1372} 1388}
1373 1389
1390static int tda998x_encoder_init(struct i2c_client *client,
1391 struct drm_device *dev,
1392 struct drm_encoder_slave *encoder_slave)
1393{
1394 struct tda998x_priv *priv;
1395 int ret;
1396
1397 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1398 if (!priv)
1399 return -ENOMEM;
1400
1401 priv->encoder = &encoder_slave->base;
1402
1403 ret = tda998x_create(client, priv);
1404 if (ret) {
1405 kfree(priv);
1406 return ret;
1407 }
1408
1409 encoder_slave->slave_priv = priv;
1410 encoder_slave->slave_funcs = &tda998x_encoder_slave_funcs;
1411
1412 return 0;
1413}
1414
1374#ifdef CONFIG_OF 1415#ifdef CONFIG_OF
1375static const struct of_device_id tda998x_dt_ids[] = { 1416static const struct of_device_id tda998x_dt_ids[] = {
1376 { .compatible = "nxp,tda998x", }, 1417 { .compatible = "nxp,tda998x", },