Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
Hi Jitao, some things I missed before. Am Montag, den 02.11.2015, 10:09 +0800 schrieb Jitao Shi: [...] > +static int ps8640_regr(struct i2c_client *client, u16 i2c_addr, > +u8 reg, u8 *value) > +{ > + int ret; > + > + client->addr = i2c_addr; I think i2c_new_dummy should be used to create additional clients for the secondary addresses, instead of changing the address of the client with every transfer. > + ret = i2c_master_send(client, , 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); > + return ret; > + } > + > + ret = i2c_master_recv(client, value, 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret); > + return ret; > + } > + > + return 0; > +} [...] > +static int ps8640_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + struct device *dev = >dev; > + struct ps8640 *ps_bridge; > + struct device_node *np = dev->of_node; > + struct device_node *in_ep, *out_ep; > + struct device_node *panel_node = NULL; > + int ret; > + u32 temp_reg; > + > + ps_bridge = devm_kzalloc(dev, sizeof(*ps_bridge), GFP_KERNEL); > + if (!ps_bridge) > + return -ENOMEM; > + > + in_ep = of_graph_get_next_endpoint(np, NULL); > + if (in_ep) { > + out_ep = of_graph_get_next_endpoint(np, in_ep); > + of_node_put(in_ep); > + if (out_ep) { > + panel_node = of_graph_get_remote_port_parent(out_ep); > + of_node_put(out_ep); > + } > + } > + if (panel_node) { > + ps_bridge->panel = of_drm_find_panel(panel_node); > + of_node_put(panel_node); > + if (!ps_bridge->panel) > + return -EPROBE_DEFER; > + } > + > + ps_bridge->client = client; > + > + ps_bridge->pwr_3v3_supply = devm_regulator_get(dev, "vdd33-supply"); Should be "vdd3", regulator_get will add the "-supply" suffix. > + if (IS_ERR(ps_bridge->pwr_3v3_supply)) { > + dev_err(dev, "cannot get ps_bridge->pwr_3v3_supply\n"); > + return PTR_ERR(ps_bridge->pwr_3v3_supply); > + } > + > + ps_bridge->pwr_1v2_supply = devm_regulator_get(dev, "vdd12-supply"); Same here, "vdd12". > + if (IS_ERR(ps_bridge->pwr_1v2_supply)) { > + dev_err(dev, "cannot get ps_bridge->pwr_1v2_supply\n"); > + return PTR_ERR(ps_bridge->pwr_1v2_supply); > + } > + > + ps_bridge->gpio_mode_sel_n = devm_gpiod_get(>dev, "mode-sel", > + GPIOD_OUT_HIGH); > + if (IS_ERR(ps_bridge->gpio_mode_sel_n)) { > + ret = PTR_ERR(ps_bridge->gpio_mode_sel_n); > + DRM_ERROR("cannot get gpio_mode_sel_n %d\n", ret); > + return ret; > + } > + > + ret = gpiod_direction_output(ps_bridge->gpio_mode_sel_n, 1); > + if (ret) { > + DRM_ERROR("cannot configure gpio_mode_sel_n\n"); > + return ret; > + } > + > + ps_bridge->gpio_slp_n = devm_gpiod_get(>dev, "sleep-gpios", > +GPIOD_OUT_HIGH); Should be "sleep", gpiod_get will add the "-gpios" suffix. > + if (IS_ERR(ps_bridge->gpio_slp_n)) { > + ret = PTR_ERR(ps_bridge->gpio_slp_n); > + DRM_ERROR("cannot get gpio_slp_n %d\n", ret); > + return ret; > + } > + > + ret = gpiod_direction_output(ps_bridge->gpio_slp_n, 1); > + if (ret) { > + DRM_ERROR("cannot configure gpio_slp_n\n"); > + return ret; > + } This can be removed, the "devm_gpiod_get(..., GPIOD_OUT_HIGH);" already does the same. > + > + ps_bridge->gpio_rst_n = devm_gpiod_get(>dev, "reset", > +GPIOD_OUT_HIGH); > + if (IS_ERR(ps_bridge->gpio_rst_n)) { > + ret = PTR_ERR(ps_bridge->gpio_rst_n); > + DRM_ERROR("cannot get gpio_rst_n %d\n", ret); > + return ret; > + } > + > + ret = gpiod_direction_output(ps_bridge->gpio_rst_n, 1); > + if (ret) { > + DRM_ERROR("cannot configure gpio_rst_n\n"); > + return ret; > + } Same here, the gpiod_direction_output can be removed. best regards Philipp -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
Hi Jitao, some things I missed before. Am Montag, den 02.11.2015, 10:09 +0800 schrieb Jitao Shi: [...] > +static int ps8640_regr(struct i2c_client *client, u16 i2c_addr, > +u8 reg, u8 *value) > +{ > + int ret; > + > + client->addr = i2c_addr; I think i2c_new_dummy should be used to create additional clients for the secondary addresses, instead of changing the address of the client with every transfer. > + ret = i2c_master_send(client, , 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); > + return ret; > + } > + > + ret = i2c_master_recv(client, value, 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret); > + return ret; > + } > + > + return 0; > +} [...] > +static int ps8640_probe(struct i2c_client *client, > + const struct i2c_device_id *id) > +{ > + struct device *dev = >dev; > + struct ps8640 *ps_bridge; > + struct device_node *np = dev->of_node; > + struct device_node *in_ep, *out_ep; > + struct device_node *panel_node = NULL; > + int ret; > + u32 temp_reg; > + > + ps_bridge = devm_kzalloc(dev, sizeof(*ps_bridge), GFP_KERNEL); > + if (!ps_bridge) > + return -ENOMEM; > + > + in_ep = of_graph_get_next_endpoint(np, NULL); > + if (in_ep) { > + out_ep = of_graph_get_next_endpoint(np, in_ep); > + of_node_put(in_ep); > + if (out_ep) { > + panel_node = of_graph_get_remote_port_parent(out_ep); > + of_node_put(out_ep); > + } > + } > + if (panel_node) { > + ps_bridge->panel = of_drm_find_panel(panel_node); > + of_node_put(panel_node); > + if (!ps_bridge->panel) > + return -EPROBE_DEFER; > + } > + > + ps_bridge->client = client; > + > + ps_bridge->pwr_3v3_supply = devm_regulator_get(dev, "vdd33-supply"); Should be "vdd3", regulator_get will add the "-supply" suffix. > + if (IS_ERR(ps_bridge->pwr_3v3_supply)) { > + dev_err(dev, "cannot get ps_bridge->pwr_3v3_supply\n"); > + return PTR_ERR(ps_bridge->pwr_3v3_supply); > + } > + > + ps_bridge->pwr_1v2_supply = devm_regulator_get(dev, "vdd12-supply"); Same here, "vdd12". > + if (IS_ERR(ps_bridge->pwr_1v2_supply)) { > + dev_err(dev, "cannot get ps_bridge->pwr_1v2_supply\n"); > + return PTR_ERR(ps_bridge->pwr_1v2_supply); > + } > + > + ps_bridge->gpio_mode_sel_n = devm_gpiod_get(>dev, "mode-sel", > + GPIOD_OUT_HIGH); > + if (IS_ERR(ps_bridge->gpio_mode_sel_n)) { > + ret = PTR_ERR(ps_bridge->gpio_mode_sel_n); > + DRM_ERROR("cannot get gpio_mode_sel_n %d\n", ret); > + return ret; > + } > + > + ret = gpiod_direction_output(ps_bridge->gpio_mode_sel_n, 1); > + if (ret) { > + DRM_ERROR("cannot configure gpio_mode_sel_n\n"); > + return ret; > + } > + > + ps_bridge->gpio_slp_n = devm_gpiod_get(>dev, "sleep-gpios", > +GPIOD_OUT_HIGH); Should be "sleep", gpiod_get will add the "-gpios" suffix. > + if (IS_ERR(ps_bridge->gpio_slp_n)) { > + ret = PTR_ERR(ps_bridge->gpio_slp_n); > + DRM_ERROR("cannot get gpio_slp_n %d\n", ret); > + return ret; > + } > + > + ret = gpiod_direction_output(ps_bridge->gpio_slp_n, 1); > + if (ret) { > + DRM_ERROR("cannot configure gpio_slp_n\n"); > + return ret; > + } This can be removed, the "devm_gpiod_get(..., GPIOD_OUT_HIGH);" already does the same. > + > + ps_bridge->gpio_rst_n = devm_gpiod_get(>dev, "reset", > +GPIOD_OUT_HIGH); > + if (IS_ERR(ps_bridge->gpio_rst_n)) { > + ret = PTR_ERR(ps_bridge->gpio_rst_n); > + DRM_ERROR("cannot get gpio_rst_n %d\n", ret); > + return ret; > + } > + > + ret = gpiod_direction_output(ps_bridge->gpio_rst_n, 1); > + if (ret) { > + DRM_ERROR("cannot configure gpio_rst_n\n"); > + return ret; > + } Same here, the gpiod_direction_output can be removed. best regards Philipp -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
Hi Philipp I'll fixed those comments on V3. Thank you very much. Best Regards. On Mon, 2015-11-02 at 12:34 +0100, Philipp Zabel wrote: > Hi Jitao, > > a few comments below. > > Am Montag, den 02.11.2015, 11:54 +0800 schrieb jitao shi: > [...] > > > +static int ps8640_check_valid_id(struct ps8640 *ps_bridge) > > This could be bool and return true/false. > > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + u8 rev_id_low, rev_id_high, chip_id_low, chip_id_high; > > > + int retry_cnt = 0; > > > + > > > + do { > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_H, > > > + _id_high); > > > + if (chip_id_high != 0x30) > > > + DRM_INFO("chip_id_high = 0x%x\n", chip_id_high); > > > + } while ((retry_cnt++ < 2) && (chip_id_high != 0x30)); > > > + > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_L, _id_low); > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_H, _id_high); > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_L, > > > + _id_low); > > > + > > > + if ((rev_id_low == 0x00) && (rev_id_high == 0x0a) && > > > + (chip_id_low == 0x00) && (chip_id_high == 0x30)) > > > + return 1; > > > + > > > + return 0; > > > +} > > > + > > > +static void ps8640_show_mcu_fw_version(struct ps8640 *ps_bridge) > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + u8 major_ver, minor_ver; > > > + > > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x4, _ver); > > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x5, _ver); > > > + > > > + DRM_INFO_ONCE("ps8640 rom fw version %d.%d\n", major_ver, minor_ver); > > > +} > > > + > > > +static int ps8640_bdg_enable(struct ps8640 *ps_bridge) > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + > > > + if (ps8640_check_valid_id(ps_bridge)) { > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x18); > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x1c); > > Can you introduce #defines with descriptive names for those magic > constants and register offsets, and maybe also i2c address offsets? > > > > + > > > + return 0; > > > + } > > > + > > > + return -1; > > Never return -1 to signal a problem. > If there was an error, use a proper error code. > > > > +} > > > + > > > +static void ps8640_prepare(struct ps8640 *ps_bridge) > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + int err, retry_cnt = 0; > > > + u8 set_vdo_done; > > > + > > > + if (ps_bridge->enabled) > > > + return; > > > + > > > + if (drm_panel_prepare(ps_bridge->panel)) { > > > + DRM_ERROR("failed to prepare panel\n"); > > > + return; > > > + } > > > + > > > + err = regulator_enable(ps_bridge->pwr_1v2_supply); > > > + if (err < 0) { > > > + DRM_ERROR("failed to enable pwr_1v2_supply: %d\n", err); > > Missing panel unprepare. > > > > + return; > > > + } > > > + > > > + err = regulator_enable(ps_bridge->pwr_3v3_supply); > > > + if (err < 0) { > > > + DRM_ERROR("failed to enable pwr_3v3_supply: %d\n", err); > > Missing panel unprepare and vdd12 regulator disable. > > > > + return; > > > + } > > > + > > > + gpiod_set_value(ps_bridge->gpio_slp_n, 1); > > > + gpiod_set_value(ps_bridge->gpio_rst_n, 0); > > > + usleep_range(500, 700); > > > + gpiod_set_value(ps_bridge->gpio_rst_n, 1); > > > + > > > + do { > > > + msleep(50); > > > + ps8640_regr(client, ps_bridge->base_reg + 2, PAGE2_GPIO_H, > > > + _vdo_done); > > > + } while ((retry_cnt++ < 70) && ((set_vdo_done & PS_GPIO9) != PS_GPIO9)); > > > + > > > + ps8640_show_mcu_fw_version(ps_bridge); > > > + ps_bridge->enabled = true; > > > +} > > > + > > > +static void ps8640_pre_enable(struct drm_bridge *bridge) > > > +{ > > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > > + > > > + ps8640_prepare(ps_bridge); > > > +} > > > + > > > +static void ps8640_enable(struct drm_bridge *bridge) > > > +{ > > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > > + > > > + ps8640_bdg_enable(ps_bridge); > > > + > > > + if (drm_panel_enable(ps_bridge->panel)) { > > > + DRM_ERROR("failed to enable panel\n"); > > > + return; > > The return is superfluous. > > > > + } > > > +} > > > + > > > +static void ps8640_disable(struct drm_bridge *bridge) > > > +{ > > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > > + > > > + if (!ps_bridge->enabled) > > > + return; > > > + > > > + ps_bridge->enabled = false; > > > + > > > + if (drm_panel_disable(ps_bridge->panel)) { > > > + DRM_ERROR("failed to disable panel\n"); > > > + return; > > Shouldn't we still disable the bridge, even if panel disable fails? > > > > + } > > > + > > > +
Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
Hi Philipp I'll fixed those comments on V3. Thank you very much. Best Regards. On Mon, 2015-11-02 at 12:34 +0100, Philipp Zabel wrote: > Hi Jitao, > > a few comments below. > > Am Montag, den 02.11.2015, 11:54 +0800 schrieb jitao shi: > [...] > > > +static int ps8640_check_valid_id(struct ps8640 *ps_bridge) > > This could be bool and return true/false. > > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + u8 rev_id_low, rev_id_high, chip_id_low, chip_id_high; > > > + int retry_cnt = 0; > > > + > > > + do { > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_H, > > > + _id_high); > > > + if (chip_id_high != 0x30) > > > + DRM_INFO("chip_id_high = 0x%x\n", chip_id_high); > > > + } while ((retry_cnt++ < 2) && (chip_id_high != 0x30)); > > > + > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_L, _id_low); > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_H, _id_high); > > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_L, > > > + _id_low); > > > + > > > + if ((rev_id_low == 0x00) && (rev_id_high == 0x0a) && > > > + (chip_id_low == 0x00) && (chip_id_high == 0x30)) > > > + return 1; > > > + > > > + return 0; > > > +} > > > + > > > +static void ps8640_show_mcu_fw_version(struct ps8640 *ps_bridge) > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + u8 major_ver, minor_ver; > > > + > > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x4, _ver); > > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x5, _ver); > > > + > > > + DRM_INFO_ONCE("ps8640 rom fw version %d.%d\n", major_ver, minor_ver); > > > +} > > > + > > > +static int ps8640_bdg_enable(struct ps8640 *ps_bridge) > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + > > > + if (ps8640_check_valid_id(ps_bridge)) { > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x18); > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x1c); > > Can you introduce #defines with descriptive names for those magic > constants and register offsets, and maybe also i2c address offsets? > > > > + > > > + return 0; > > > + } > > > + > > > + return -1; > > Never return -1 to signal a problem. > If there was an error, use a proper error code. > > > > +} > > > + > > > +static void ps8640_prepare(struct ps8640 *ps_bridge) > > > +{ > > > + struct i2c_client *client = ps_bridge->client; > > > + int err, retry_cnt = 0; > > > + u8 set_vdo_done; > > > + > > > + if (ps_bridge->enabled) > > > + return; > > > + > > > + if (drm_panel_prepare(ps_bridge->panel)) { > > > + DRM_ERROR("failed to prepare panel\n"); > > > + return; > > > + } > > > + > > > + err = regulator_enable(ps_bridge->pwr_1v2_supply); > > > + if (err < 0) { > > > + DRM_ERROR("failed to enable pwr_1v2_supply: %d\n", err); > > Missing panel unprepare. > > > > + return; > > > + } > > > + > > > + err = regulator_enable(ps_bridge->pwr_3v3_supply); > > > + if (err < 0) { > > > + DRM_ERROR("failed to enable pwr_3v3_supply: %d\n", err); > > Missing panel unprepare and vdd12 regulator disable. > > > > + return; > > > + } > > > + > > > + gpiod_set_value(ps_bridge->gpio_slp_n, 1); > > > + gpiod_set_value(ps_bridge->gpio_rst_n, 0); > > > + usleep_range(500, 700); > > > + gpiod_set_value(ps_bridge->gpio_rst_n, 1); > > > + > > > + do { > > > + msleep(50); > > > + ps8640_regr(client, ps_bridge->base_reg + 2, PAGE2_GPIO_H, > > > + _vdo_done); > > > + } while ((retry_cnt++ < 70) && ((set_vdo_done & PS_GPIO9) != PS_GPIO9)); > > > + > > > + ps8640_show_mcu_fw_version(ps_bridge); > > > + ps_bridge->enabled = true; > > > +} > > > + > > > +static void ps8640_pre_enable(struct drm_bridge *bridge) > > > +{ > > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > > + > > > + ps8640_prepare(ps_bridge); > > > +} > > > + > > > +static void ps8640_enable(struct drm_bridge *bridge) > > > +{ > > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > > + > > > + ps8640_bdg_enable(ps_bridge); > > > + > > > + if (drm_panel_enable(ps_bridge->panel)) { > > > + DRM_ERROR("failed to enable panel\n"); > > > + return; > > The return is superfluous. > > > > + } > > > +} > > > + > > > +static void ps8640_disable(struct drm_bridge *bridge) > > > +{ > > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > > + > > > + if (!ps_bridge->enabled) > > > + return; > > > + > > > + ps_bridge->enabled = false; > > > + > > > + if (drm_panel_disable(ps_bridge->panel)) { > > > + DRM_ERROR("failed to disable panel\n"); > > > + return; > > Shouldn't we still disable the bridge, even if panel disable fails? > > > > + } > > > + > > > +
Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
Hi Jitao, a few comments below. Am Montag, den 02.11.2015, 11:54 +0800 schrieb jitao shi: [...] > > +static int ps8640_check_valid_id(struct ps8640 *ps_bridge) This could be bool and return true/false. > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + u8 rev_id_low, rev_id_high, chip_id_low, chip_id_high; > > + int retry_cnt = 0; > > + > > + do { > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_H, > > + _id_high); > > + if (chip_id_high != 0x30) > > + DRM_INFO("chip_id_high = 0x%x\n", chip_id_high); > > + } while ((retry_cnt++ < 2) && (chip_id_high != 0x30)); > > + > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_L, _id_low); > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_H, _id_high); > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_L, > > + _id_low); > > + > > + if ((rev_id_low == 0x00) && (rev_id_high == 0x0a) && > > + (chip_id_low == 0x00) && (chip_id_high == 0x30)) > > + return 1; > > + > > + return 0; > > +} > > + > > +static void ps8640_show_mcu_fw_version(struct ps8640 *ps_bridge) > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + u8 major_ver, minor_ver; > > + > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x4, _ver); > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x5, _ver); > > + > > + DRM_INFO_ONCE("ps8640 rom fw version %d.%d\n", major_ver, minor_ver); > > +} > > + > > +static int ps8640_bdg_enable(struct ps8640 *ps_bridge) > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + > > + if (ps8640_check_valid_id(ps_bridge)) { > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x18); > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x1c); Can you introduce #defines with descriptive names for those magic constants and register offsets, and maybe also i2c address offsets? > > + > > + return 0; > > + } > > + > > + return -1; Never return -1 to signal a problem. If there was an error, use a proper error code. > > +} > > + > > +static void ps8640_prepare(struct ps8640 *ps_bridge) > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + int err, retry_cnt = 0; > > + u8 set_vdo_done; > > + > > + if (ps_bridge->enabled) > > + return; > > + > > + if (drm_panel_prepare(ps_bridge->panel)) { > > + DRM_ERROR("failed to prepare panel\n"); > > + return; > > + } > > + > > + err = regulator_enable(ps_bridge->pwr_1v2_supply); > > + if (err < 0) { > > + DRM_ERROR("failed to enable pwr_1v2_supply: %d\n", err); Missing panel unprepare. > > + return; > > + } > > + > > + err = regulator_enable(ps_bridge->pwr_3v3_supply); > > + if (err < 0) { > > + DRM_ERROR("failed to enable pwr_3v3_supply: %d\n", err); Missing panel unprepare and vdd12 regulator disable. > > + return; > > + } > > + > > + gpiod_set_value(ps_bridge->gpio_slp_n, 1); > > + gpiod_set_value(ps_bridge->gpio_rst_n, 0); > > + usleep_range(500, 700); > > + gpiod_set_value(ps_bridge->gpio_rst_n, 1); > > + > > + do { > > + msleep(50); > > + ps8640_regr(client, ps_bridge->base_reg + 2, PAGE2_GPIO_H, > > + _vdo_done); > > + } while ((retry_cnt++ < 70) && ((set_vdo_done & PS_GPIO9) != PS_GPIO9)); > > + > > + ps8640_show_mcu_fw_version(ps_bridge); > > + ps_bridge->enabled = true; > > +} > > + > > +static void ps8640_pre_enable(struct drm_bridge *bridge) > > +{ > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > + > > + ps8640_prepare(ps_bridge); > > +} > > + > > +static void ps8640_enable(struct drm_bridge *bridge) > > +{ > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > + > > + ps8640_bdg_enable(ps_bridge); > > + > > + if (drm_panel_enable(ps_bridge->panel)) { > > + DRM_ERROR("failed to enable panel\n"); > > + return; The return is superfluous. > > + } > > +} > > + > > +static void ps8640_disable(struct drm_bridge *bridge) > > +{ > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > + > > + if (!ps_bridge->enabled) > > + return; > > + > > + ps_bridge->enabled = false; > > + > > + if (drm_panel_disable(ps_bridge->panel)) { > > + DRM_ERROR("failed to disable panel\n"); > > + return; Shouldn't we still disable the bridge, even if panel disable fails? > > + } > > + > > + regulator_disable(ps_bridge->pwr_1v2_supply); > > + regulator_disable(ps_bridge->pwr_3v3_supply); > > + gpiod_set_value(ps_bridge->gpio_rst_n, 0); > > + gpiod_set_value(ps_bridge->gpio_slp_n, 0); > > +} > > + > > +static void ps8640_post_disable(struct drm_bridge *bridge) > > +{ > > + struct ps8640
Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
Hi Jitao, a few comments below. Am Montag, den 02.11.2015, 11:54 +0800 schrieb jitao shi: [...] > > +static int ps8640_check_valid_id(struct ps8640 *ps_bridge) This could be bool and return true/false. > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + u8 rev_id_low, rev_id_high, chip_id_low, chip_id_high; > > + int retry_cnt = 0; > > + > > + do { > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_H, > > + _id_high); > > + if (chip_id_high != 0x30) > > + DRM_INFO("chip_id_high = 0x%x\n", chip_id_high); > > + } while ((retry_cnt++ < 2) && (chip_id_high != 0x30)); > > + > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_L, _id_low); > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_REV_H, _id_high); > > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_L, > > + _id_low); > > + > > + if ((rev_id_low == 0x00) && (rev_id_high == 0x0a) && > > + (chip_id_low == 0x00) && (chip_id_high == 0x30)) > > + return 1; > > + > > + return 0; > > +} > > + > > +static void ps8640_show_mcu_fw_version(struct ps8640 *ps_bridge) > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + u8 major_ver, minor_ver; > > + > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x4, _ver); > > + ps8640_regr(client, ps_bridge->base_reg + 5, 0x5, _ver); > > + > > + DRM_INFO_ONCE("ps8640 rom fw version %d.%d\n", major_ver, minor_ver); > > +} > > + > > +static int ps8640_bdg_enable(struct ps8640 *ps_bridge) > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + > > + if (ps8640_check_valid_id(ps_bridge)) { > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x18); > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xfe, 0x13); > > + ps8640_regw(client, ps_bridge->base_reg + 3, 0xff, 0x1c); Can you introduce #defines with descriptive names for those magic constants and register offsets, and maybe also i2c address offsets? > > + > > + return 0; > > + } > > + > > + return -1; Never return -1 to signal a problem. If there was an error, use a proper error code. > > +} > > + > > +static void ps8640_prepare(struct ps8640 *ps_bridge) > > +{ > > + struct i2c_client *client = ps_bridge->client; > > + int err, retry_cnt = 0; > > + u8 set_vdo_done; > > + > > + if (ps_bridge->enabled) > > + return; > > + > > + if (drm_panel_prepare(ps_bridge->panel)) { > > + DRM_ERROR("failed to prepare panel\n"); > > + return; > > + } > > + > > + err = regulator_enable(ps_bridge->pwr_1v2_supply); > > + if (err < 0) { > > + DRM_ERROR("failed to enable pwr_1v2_supply: %d\n", err); Missing panel unprepare. > > + return; > > + } > > + > > + err = regulator_enable(ps_bridge->pwr_3v3_supply); > > + if (err < 0) { > > + DRM_ERROR("failed to enable pwr_3v3_supply: %d\n", err); Missing panel unprepare and vdd12 regulator disable. > > + return; > > + } > > + > > + gpiod_set_value(ps_bridge->gpio_slp_n, 1); > > + gpiod_set_value(ps_bridge->gpio_rst_n, 0); > > + usleep_range(500, 700); > > + gpiod_set_value(ps_bridge->gpio_rst_n, 1); > > + > > + do { > > + msleep(50); > > + ps8640_regr(client, ps_bridge->base_reg + 2, PAGE2_GPIO_H, > > + _vdo_done); > > + } while ((retry_cnt++ < 70) && ((set_vdo_done & PS_GPIO9) != PS_GPIO9)); > > + > > + ps8640_show_mcu_fw_version(ps_bridge); > > + ps_bridge->enabled = true; > > +} > > + > > +static void ps8640_pre_enable(struct drm_bridge *bridge) > > +{ > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > + > > + ps8640_prepare(ps_bridge); > > +} > > + > > +static void ps8640_enable(struct drm_bridge *bridge) > > +{ > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > + > > + ps8640_bdg_enable(ps_bridge); > > + > > + if (drm_panel_enable(ps_bridge->panel)) { > > + DRM_ERROR("failed to enable panel\n"); > > + return; The return is superfluous. > > + } > > +} > > + > > +static void ps8640_disable(struct drm_bridge *bridge) > > +{ > > + struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); > > + > > + if (!ps_bridge->enabled) > > + return; > > + > > + ps_bridge->enabled = false; > > + > > + if (drm_panel_disable(ps_bridge->panel)) { > > + DRM_ERROR("failed to disable panel\n"); > > + return; Shouldn't we still disable the bridge, even if panel disable fails? > > + } > > + > > + regulator_disable(ps_bridge->pwr_1v2_supply); > > + regulator_disable(ps_bridge->pwr_3v3_supply); > > + gpiod_set_value(ps_bridge->gpio_rst_n, 0); > > + gpiod_set_value(ps_bridge->gpio_slp_n, 0); > > +} > > + > > +static void ps8640_post_disable(struct drm_bridge *bridge) > > +{ > > + struct ps8640
Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
On Mon, 2015-11-02 at 10:09 +0800, Jitao Shi wrote: > This patch adds drm_bridge driver for parade DSI to eDP bridge chip. > > Signed-off-by: Jitao Shi --- changes since v1: 1. remove edid code 2. remove some wrong comments 3. tune some gpios name, make it easy understand the meaning > --- > drivers/gpu/drm/bridge/Kconfig |9 + > drivers/gpu/drm/bridge/Makefile|1 + > drivers/gpu/drm/bridge/parade-ps8640.c | 479 > > 3 files changed, 489 insertions(+) > create mode 100644 drivers/gpu/drm/bridge/parade-ps8640.c > > diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig > index 2de52a5..8ecaeed 100644 > --- a/drivers/gpu/drm/bridge/Kconfig > +++ b/drivers/gpu/drm/bridge/Kconfig > @@ -29,4 +29,13 @@ config DRM_PARADE_PS8622 > ---help--- > Parade eDP-LVDS bridge chip driver. > > +config DRM_PARADE_PS8640 > + bool "Parade PS8640 MIPI DSI to eDP Converter" > + select DRM_KMS_HELPER > + select DRM_PANEL > + ---help--- > + Choose this option if you have PS8640 for display > + The PS8640 is a high-performance and low-power > + MIPI DSI to eDP converter > + > endmenu > diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile > index e2eef1c..da9e4a4 100644 > --- a/drivers/gpu/drm/bridge/Makefile > +++ b/drivers/gpu/drm/bridge/Makefile > @@ -3,3 +3,4 @@ ccflags-y := -Iinclude/drm > obj-$(CONFIG_DRM_DW_HDMI) += dw_hdmi.o > obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o > obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o > +obj-$(CONFIG_DRM_PARADE_PS8640) += parade-ps8640.o > diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c > b/drivers/gpu/drm/bridge/parade-ps8640.c > new file mode 100644 > index 000..52616ba > --- /dev/null > +++ b/drivers/gpu/drm/bridge/parade-ps8640.c > @@ -0,0 +1,479 @@ > +/* > + * Copyright (c) 2014 MediaTek Inc. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define PAGE2_GPIO_L 0xa6 > +#define PAGE2_GPIO_H 0xa7 > +#define PS_GPIO9 BIT(1) > + > +#define PAGE4_REV_L 0xf0 > +#define PAGE4_REV_H 0xf1 > +#define PAGE4_CHIP_L 0xf2 > +#define PAGE4_CHIP_H 0xf3 > + > +#define bridge_to_ps8640(e) container_of(e, struct ps8640, bridge) > +#define connector_to_ps8640(e) container_of(e, struct ps8640, > connector) > + > +struct ps8640 { > + struct drm_connector connector; > + struct drm_bridge bridge; > + struct i2c_client *client; > + struct ps8640_driver_data *driver_data; > + struct regulator *pwr_1v2_supply; > + struct regulator *pwr_3v3_supply; > + struct drm_panel *panel; > + struct gpio_desc *gpio_rst_n; > + struct gpio_desc *gpio_slp_n; > + struct gpio_desc *gpio_mode_sel_n; > + u16 base_reg; > + bool enabled; > +}; > + > +static int ps8640_regr(struct i2c_client *client, u16 i2c_addr, > +u8 reg, u8 *value) > +{ > + int ret; > + > + client->addr = i2c_addr; > + > + ret = i2c_master_send(client, , 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); > + return ret; > + } > + > + ret = i2c_master_recv(client, value, 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret); > + return ret; > + } > + > + return 0; > +} > + > +static int ps8640_regw(struct i2c_client *client, u16 i2c_addr, > +u8 reg, u8 value) > +{ > + int ret; > + char buf[2]; > + > + client->addr = i2c_addr; > + > + buf[0] = reg; > + buf[1] = value; > + ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); > + if (ret <= 0) { > + DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); > + return ret; > + } > + > + return 0; > +} > + > +static int ps8640_check_valid_id(struct ps8640 *ps_bridge) > +{ > + struct i2c_client *client = ps_bridge->client; > + u8 rev_id_low, rev_id_high, chip_id_low, chip_id_high; > + int retry_cnt = 0; > + > + do { > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_H, > + _id_high); > + if (chip_id_high != 0x30) > + DRM_INFO("chip_id_high = 0x%x\n", chip_id_high); > + } while ((retry_cnt++ < 2) && (chip_id_high !=
Re: [RFC v2 2/2] drm/bridge: Add I2C based driver for ps8640 bridge
On Mon, 2015-11-02 at 10:09 +0800, Jitao Shi wrote: > This patch adds drm_bridge driver for parade DSI to eDP bridge chip. > > Signed-off-by: Jitao Shi--- changes since v1: 1. remove edid code 2. remove some wrong comments 3. tune some gpios name, make it easy understand the meaning > --- > drivers/gpu/drm/bridge/Kconfig |9 + > drivers/gpu/drm/bridge/Makefile|1 + > drivers/gpu/drm/bridge/parade-ps8640.c | 479 > > 3 files changed, 489 insertions(+) > create mode 100644 drivers/gpu/drm/bridge/parade-ps8640.c > > diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig > index 2de52a5..8ecaeed 100644 > --- a/drivers/gpu/drm/bridge/Kconfig > +++ b/drivers/gpu/drm/bridge/Kconfig > @@ -29,4 +29,13 @@ config DRM_PARADE_PS8622 > ---help--- > Parade eDP-LVDS bridge chip driver. > > +config DRM_PARADE_PS8640 > + bool "Parade PS8640 MIPI DSI to eDP Converter" > + select DRM_KMS_HELPER > + select DRM_PANEL > + ---help--- > + Choose this option if you have PS8640 for display > + The PS8640 is a high-performance and low-power > + MIPI DSI to eDP converter > + > endmenu > diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile > index e2eef1c..da9e4a4 100644 > --- a/drivers/gpu/drm/bridge/Makefile > +++ b/drivers/gpu/drm/bridge/Makefile > @@ -3,3 +3,4 @@ ccflags-y := -Iinclude/drm > obj-$(CONFIG_DRM_DW_HDMI) += dw_hdmi.o > obj-$(CONFIG_DRM_NXP_PTN3460) += nxp-ptn3460.o > obj-$(CONFIG_DRM_PARADE_PS8622) += parade-ps8622.o > +obj-$(CONFIG_DRM_PARADE_PS8640) += parade-ps8640.o > diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c > b/drivers/gpu/drm/bridge/parade-ps8640.c > new file mode 100644 > index 000..52616ba > --- /dev/null > +++ b/drivers/gpu/drm/bridge/parade-ps8640.c > @@ -0,0 +1,479 @@ > +/* > + * Copyright (c) 2014 MediaTek Inc. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define PAGE2_GPIO_L 0xa6 > +#define PAGE2_GPIO_H 0xa7 > +#define PS_GPIO9 BIT(1) > + > +#define PAGE4_REV_L 0xf0 > +#define PAGE4_REV_H 0xf1 > +#define PAGE4_CHIP_L 0xf2 > +#define PAGE4_CHIP_H 0xf3 > + > +#define bridge_to_ps8640(e) container_of(e, struct ps8640, bridge) > +#define connector_to_ps8640(e) container_of(e, struct ps8640, > connector) > + > +struct ps8640 { > + struct drm_connector connector; > + struct drm_bridge bridge; > + struct i2c_client *client; > + struct ps8640_driver_data *driver_data; > + struct regulator *pwr_1v2_supply; > + struct regulator *pwr_3v3_supply; > + struct drm_panel *panel; > + struct gpio_desc *gpio_rst_n; > + struct gpio_desc *gpio_slp_n; > + struct gpio_desc *gpio_mode_sel_n; > + u16 base_reg; > + bool enabled; > +}; > + > +static int ps8640_regr(struct i2c_client *client, u16 i2c_addr, > +u8 reg, u8 *value) > +{ > + int ret; > + > + client->addr = i2c_addr; > + > + ret = i2c_master_send(client, , 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); > + return ret; > + } > + > + ret = i2c_master_recv(client, value, 1); > + if (ret <= 0) { > + DRM_ERROR("Failed to recv i2c data, ret=%d\n", ret); > + return ret; > + } > + > + return 0; > +} > + > +static int ps8640_regw(struct i2c_client *client, u16 i2c_addr, > +u8 reg, u8 value) > +{ > + int ret; > + char buf[2]; > + > + client->addr = i2c_addr; > + > + buf[0] = reg; > + buf[1] = value; > + ret = i2c_master_send(client, buf, ARRAY_SIZE(buf)); > + if (ret <= 0) { > + DRM_ERROR("Failed to send i2c command, ret=%d\n", ret); > + return ret; > + } > + > + return 0; > +} > + > +static int ps8640_check_valid_id(struct ps8640 *ps_bridge) > +{ > + struct i2c_client *client = ps_bridge->client; > + u8 rev_id_low, rev_id_high, chip_id_low, chip_id_high; > + int retry_cnt = 0; > + > + do { > + ps8640_regr(client, ps_bridge->base_reg + 4, PAGE4_CHIP_H, > + _id_high); > + if (chip_id_high != 0x30) > + DRM_INFO("chip_id_high = 0x%x\n", chip_id_high); > + } while ((retry_cnt++ < 2)