- 论坛徽章:
- 0
|
我的设备树gpio相关部分
gpio1:gpio@c00 {
198 device_type = "gpio";
199 compatible = "fsl,mpc8315-gpio","fsl,mpc8349-gpio";
200 reg = <0xc00 0x18>;
201 #gpio-cells = <2>;
202 interrupt-parent = < &ipic >;
203 gpio-controller;
204 };
205
206 gpio2:gpio@d00 {
207 device_type = "gpio";
208 compatible = "fsl,mpc8315-gpio","fsl,mpc8349-gpio";
209 reg = <0xd00 0x18>;
210 #gpio-cells = <2>;
211 interrupt-parent = < &ipic >;
212 gpio-controller;
213 };
214 kt-leds{
215 compatible = "kt-led";
216 led1{
217 label = "led1";
218 gpios = <&gpio2 25 1>;
219 /* gpios = <&gpio1 12 1>; */
220 default-state = "off";
221 };
222 };
驱动的probe
static int __devinit of_kt_led_probe(struct of_device *ofdev,
177 const struct of_device_id *match)
178 {
179 struct device_node *np = ofdev->node, *child;
180 struct kt_led_of_platform_data *pdata;
181 struct kt_led_data *pled;
182 int count = 0, ret;
183
184 /* count GPIOs defined by this device, so we know how much to allocate */
185 for_each_child_of_node(np, child)
186 count++;
187 if (!count)
188 return 0; /* or ENODEV? */
189
190 pdata = kzalloc(sizeof(*pdata) + sizeof(struct kt_led_data) * count,
191 GFP_KERNEL);
192 if (!pdata)
193 return -ENOMEM;
194
195 pdata->num_leds = count;
196 pdata->pdev = &ofdev->dev;
197
198 // alloc led devices number
199 pdata->dev_no = 0;
200 ret = alloc_chrdev_region(&pdata->dev_no, 0, count, DEV_NAME);
201 if (ret)
202 {
203 dev_err(&ofdev->dev, "alloc_chrdev_region failed!\n");
204 kfree(pdata);
205 return ret;
206 }
207 // create the devices class
208 pdata->leddev_class = class_create(THIS_MODULE, DEV_NAME);
209 if (IS_ERR(pdata->leddev_class))
210 {
211 dev_err(pdata->pdev, " class_create failed!\n");
212 unregister_chrdev_region(pdata->dev_no, count);
213 kfree(pdata);
214 return -EEXIST;
215 }
216
217 count = 0;
218 for_each_child_of_node(np, child)
219 {
220 enum of_gpio_flags flags = 0;
221
222 pled = &pdata->led_data[count];
223
224 pled->led_no = count;
225 pled->gpio = of_get_gpio_flags(child, 0, &flags);
执行到225出现错误,进入of_get_gpio_flags函数
int of_get_gpio_flags(struct device_node *np, int index,
enum of_gpio_flags *flags)
{
int ret;
struct device_node *gc;
struct of_gpio_chip *of_gc = NULL;
int size;
const void *gpio_spec;
const u32 *gpio_cells;
ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index,
&gc, &gpio_spec);
if (ret) {
pr_debug("%s: can't parse gpios property\n", __func__);
goto err0;
}
of_gc = gc->data;
if (!of_gc) {
pr_debug("%s: gpio controller %s isn't registered\n",
np->full_name, gc->full_name);
挂在这里了,串口的打印信息
/immr@e0000000/kt-leds/led1: gpio controller /immr@e0000000/gpio@d00 isn't registered
of_kt_leds kt-leds.1: LED create name:led1 no:0 gpio_no:-19 active_low:FALSE
Skipping unavailable LED gpio -19 (led1)
找了两天都没搞定,求大神给建议啊!
|
|