static int mt6360_init_isnk_properties()

in flash/leds-mt6360.c [617:693]


static int mt6360_init_isnk_properties(struct mt6360_led *led,
				       struct led_init_data *init_data)
{
	struct led_classdev *lcdev;
	struct mt6360_priv *priv = led->priv;
	struct fwnode_handle *child;
	u32 step_uA = MT6360_ISNKRGB_STEPUA, max_uA = MT6360_ISNKRGB_MAXUA;
	u32 val;
	int num_color = 0, ret;

	if (led->led_no == MT6360_VIRTUAL_MULTICOLOR) {
		struct mc_subled *sub_led;

		sub_led = devm_kzalloc(priv->dev,
			sizeof(*sub_led) * MULTICOLOR_NUM_CHANNELS, GFP_KERNEL);
		if (!sub_led)
			return -ENOMEM;

		fwnode_for_each_child_node(init_data->fwnode, child) {
			u32 reg, color;

			ret = fwnode_property_read_u32(child, "reg", &reg);
			if (ret || reg > MT6360_LED_ISNK3 ||
			    priv->leds_active & BIT(reg))
				return -EINVAL;

			ret = fwnode_property_read_u32(child, "color", &color);
			if (ret) {
				dev_err(priv->dev,
					"led %d, no color specified\n",
					led->led_no);
				return ret;
			}

			priv->leds_active |= BIT(reg);
			sub_led[num_color].color_index = color;
			sub_led[num_color].channel = reg;
			num_color++;
		}

		if (num_color < 2) {
			dev_err(priv->dev,
			     "Multicolor must include 2 or more led channel\n");
			return -EINVAL;
		}

		led->mc.num_colors = num_color;
		led->mc.subled_info = sub_led;

		lcdev = &led->mc.led_cdev;
		lcdev->brightness_set_blocking = mt6360_mc_brightness_set;
	} else {
		if (led->led_no == MT6360_LED_ISNKML) {
			step_uA = MT6360_ISNKML_STEPUA;
			max_uA = MT6360_ISNKML_MAXUA;
		}

		lcdev = &led->isnk;
		lcdev->brightness_set_blocking = mt6360_isnk_brightness_set;
	}

	ret = fwnode_property_read_u32(init_data->fwnode, "led-max-microamp",
				       &val);
	if (ret) {
		dev_warn(priv->dev,
		     "Not specified led-max-microamp, config to the minimum\n");
		val = step_uA;
	} else
		val = clamp_align(val, 0, max_uA, step_uA);

	lcdev->max_brightness = val / step_uA;

	fwnode_property_read_string(init_data->fwnode, "linux,default-trigger",
				    &lcdev->default_trigger);

	return 0;
}